Error message cleanup.

This commit is contained in:
Robert James Kaes 2001-09-07 04:21:07 +00:00
parent f5b9bdb93d
commit 1a9dc4e7e8
8 changed files with 85 additions and 71 deletions

View File

@ -1,4 +1,4 @@
/* $Id: acl.c,v 1.4 2001-05-27 02:20:54 rjkaes Exp $ /* $Id: acl.c,v 1.5 2001-09-07 04:16:33 rjkaes Exp $
* *
* This system handles Access Control for use of this daemon. A list of * This system handles Access Control for use of this daemon. A list of
* domains, or IP addresses (including IP blocks) are stored in a list * domains, or IP addresses (including IP blocks) are stored in a list
@ -197,7 +197,7 @@ int check_acl(int fd)
if ((test_addr.s_addr & netmask_addr) == (match_addr.s_addr & netmask_addr)) { if ((test_addr.s_addr & netmask_addr) == (match_addr.s_addr & netmask_addr)) {
if (aclptr->acl_access == ACL_DENY) { if (aclptr->acl_access == ACL_DENY) {
log_message(LOG_NOTICE, "Unauthorized access from %s", ip_address); log_message(LOG_NOTICE, "Unauthorized access from [%s].", ip_address);
return 0; return 0;
} else { } else {
return 1; return 1;
@ -215,6 +215,6 @@ int check_acl(int fd)
/* /*
* Deny all connections by default. * Deny all connections by default.
*/ */
log_message(LOG_NOTICE, "Unauthorized connection from %s [%s]", string_address, ip_address); log_message(LOG_NOTICE, "Unauthorized connection from \"%s\" [%s].", string_address, ip_address);
return 0; return 0;
} }

View File

@ -1,4 +1,4 @@
/* $Id: buffer.c,v 1.5 2001-05-27 02:23:08 rjkaes Exp $ /* $Id: buffer.c,v 1.6 2001-09-07 04:17:03 rjkaes Exp $
* *
* The buffer used in each connection is a linked list of lines. As the lines * The buffer used in each connection is a linked list of lines. As the lines
* are read in and written out the buffer expands and contracts. Basically, * are read in and written out the buffer expands and contracts. Basically,
@ -199,7 +199,7 @@ ssize_t readbuff(int fd, struct buffer_s *buffptr)
if (bytesin > 0) { if (bytesin > 0) {
if (!(buffer = malloc(bytesin))) { if (!(buffer = malloc(bytesin))) {
log_message(LOG_CRIT, "Could not allocate memory in readbuff() [%s:%d]", __FILE__, __LINE__); log_message(LOG_ERR, "Could not allocate memory in 'readbuff'");
return 0; return 0;
} }
@ -224,7 +224,8 @@ ssize_t readbuff(int fd, struct buffer_s *buffptr)
case EINTR: case EINTR:
return 0; return 0;
default: default:
log_message(LOG_ERR, "readbuff: recv (%s)", strerror(errno)); log_message(LOG_ERR, "recv error (%s) in 'readbuff'.",
strerror(errno));
return -1; return -1;
} }
} }
@ -268,10 +269,14 @@ ssize_t writebuff(int fd, struct buffer_s *buffptr)
return 0; return 0;
case ENOBUFS: case ENOBUFS:
case ENOMEM: case ENOMEM:
log_message(LOG_ERR, "writebuff: send [NOBUFS/NOMEM] %s", strerror(errno)); log_message(LOG_ERR,
"send error [NOBUFS/NOMEM] (%s) in 'writebuff'.",
strerror(errno));
return 0; return 0;
default: default:
log_message(LOG_ERR, "writebuff: send (%s)", strerror(errno)); log_message(LOG_ERR,
"send error (%s) in 'writebuff'.",
strerror(errno));
return -1; return -1;
} }
} }

View File

@ -1,4 +1,4 @@
/* $Id: dnscache.c,v 1.13 2001-09-07 00:40:34 rjkaes Exp $ /* $Id: dnscache.c,v 1.14 2001-09-07 04:17:26 rjkaes Exp $
* *
* This is a caching DNS system. When a host name is needed we look it up here * This is a caching DNS system. When a host name is needed we look it up here
* and see if there is already an answer for it. The domains are placed in a * and see if there is already an answer for it. The domains are placed in a
@ -131,13 +131,13 @@ int dnscache(struct in_addr *addr, char *domain)
return -1; return -1;
} }
memcpy(addr, resolv->h_addr_list[0], (size_t)resolv->h_length); memcpy(addr, resolv->h_addr_list[0], resolv->h_length);
dns_insert(addr, domain); dns_insert(addr, domain);
dns_insertions++; dns_insertions++;
if (dns_insertions > DNS_INSERT_LIMIT) { if (dns_insertions > DNS_INSERT_LIMIT) {
log_message(LOG_NOTICE, "DNS Insertion limit, rebuilding cache."); log_message(LOG_INFO, "DNS Insertion limit reached (%u). Rebuilding cache.", dns_insertions);
ternary_destroy(dns_tree, free); ternary_destroy(dns_tree, free);
dns_tree = ternary_new(); dns_tree = ternary_new();
dns_insertions = 0; dns_insertions = 0;

View File

@ -1,4 +1,4 @@
/* $Id: reqs.c,v 1.19 2001-09-04 18:22:00 rjkaes Exp $ /* $Id: reqs.c,v 1.20 2001-09-07 04:18:04 rjkaes Exp $
* *
* This is where all the work in tinyproxy is actually done. Incoming * This is where all the work in tinyproxy is actually done. Incoming
* connections have a new thread created for them. The thread then * connections have a new thread created for them. The thread then
@ -126,7 +126,7 @@ static int process_method(struct conn_s *connptr)
len = readline(connptr->client_fd, inbuf, LINE_LENGTH); len = readline(connptr->client_fd, inbuf, LINE_LENGTH);
if (len <= 0) { if (len <= 0) {
log_message(LOG_ERR, "client closed before read"); log_message(LOG_ERR, "Client [%s] closed socket before read.", peer_ipaddr);
update_stats(STAT_BADCONN); update_stats(STAT_BADCONN);
return -2; return -2;
} }
@ -139,13 +139,13 @@ static int process_method(struct conn_s *connptr)
log_message(LOG_CONN, "Request: %s", inbuf); log_message(LOG_CONN, "Request: %s", inbuf);
if (regcomp(&preg, HTTPPATTERN, REG_EXTENDED | REG_ICASE) != 0) { if (regcomp(&preg, HTTPPATTERN, REG_EXTENDED | REG_ICASE) != 0) {
log_message(LOG_ERR, "clientreq: regcomp"); log_message(LOG_ERR, "Regular Expression compiling error.");
httperr(connptr, 503, HTTP503ERROR); httperr(connptr, 503, HTTP503ERROR);
update_stats(STAT_BADCONN); update_stats(STAT_BADCONN);
goto EARLY_EXIT; goto EARLY_EXIT;
} }
if (regexec(&preg, inbuf, NMATCH, pmatch, 0) != 0) { if (regexec(&preg, inbuf, NMATCH, pmatch, 0) != 0) {
log_message(LOG_ERR, "clientreq: regexec"); log_message(LOG_ERR, "Regular Expression search error.");
regfree(&preg); regfree(&preg);
httperr(connptr, 503, HTTP503ERROR); httperr(connptr, 503, HTTP503ERROR);
update_stats(STAT_BADCONN); update_stats(STAT_BADCONN);
@ -163,8 +163,8 @@ static int process_method(struct conn_s *connptr)
if (pmatch[METHOD_IND].rm_so == -1 || pmatch[URI_IND].rm_so == -1) { if (pmatch[METHOD_IND].rm_so == -1 || pmatch[URI_IND].rm_so == -1) {
log_message(LOG_ERR, "clientreq: Incomplete line from %s (%s)", log_message(LOG_ERR, "Incomplete request line from [%s].",
peer_ipaddr, inbuf); peer_ipaddr);
httperr(connptr, 400, HTTP400ERROR); httperr(connptr, 400, HTTP400ERROR);
update_stats(STAT_BADCONN); update_stats(STAT_BADCONN);
goto EARLY_EXIT; goto EARLY_EXIT;
@ -173,7 +173,7 @@ static int process_method(struct conn_s *connptr)
len = pmatch[URI_IND].rm_eo - pmatch[URI_IND].rm_so; len = pmatch[URI_IND].rm_eo - pmatch[URI_IND].rm_so;
if (!(buffer = malloc(len + 1))) { if (!(buffer = malloc(len + 1))) {
log_message(LOG_ERR, log_message(LOG_ERR,
"clientreq: Cannot allocate buffer for request from %s", "Could not allocate memory for request from [%s].",
peer_ipaddr); peer_ipaddr);
httperr(connptr, 503, HTTP503ERROR); httperr(connptr, 503, HTTP503ERROR);
update_stats(STAT_BADCONN); update_stats(STAT_BADCONN);
@ -183,7 +183,6 @@ static int process_method(struct conn_s *connptr)
buffer[len] = '\0'; buffer[len] = '\0';
if (!(uri = explode_uri(buffer))) { if (!(uri = explode_uri(buffer))) {
safefree(buffer); safefree(buffer);
log_message(LOG_ERR, "clientreq: Problem with explode_uri");
httperr(connptr, 503, HTTP503ERROR); httperr(connptr, 503, HTTP503ERROR);
update_stats(STAT_BADCONN); update_stats(STAT_BADCONN);
goto EARLY_EXIT; goto EARLY_EXIT;
@ -196,7 +195,9 @@ static int process_method(struct conn_s *connptr)
size_t error_string_len = strlen(uri->scheme) + 64; size_t error_string_len = strlen(uri->scheme) + 64;
error_string = malloc(error_string_len); error_string = malloc(error_string_len);
if (!error_string) { if (!error_string) {
log_message(LOG_CRIT, "Out of Memory!"); log_message(LOG_ERR,
"Could not allocate memory for request from [%s].",
peer_ipaddr);
goto COMMON_EXIT; goto COMMON_EXIT;
} }
snprintf(error_string, error_string_len, snprintf(error_string, error_string_len,
@ -206,7 +207,9 @@ static int process_method(struct conn_s *connptr)
error_string = error_string =
strdup("Invalid scheme (NULL). Only HTTP is allowed."); strdup("Invalid scheme (NULL). Only HTTP is allowed.");
if (!error_string) { if (!error_string) {
log_message(LOG_CRIT, "Out of Memory!"); log_message(LOG_ERR,
"Could not allocate memory for request from [%s].",
peer_ipaddr);
goto COMMON_EXIT; goto COMMON_EXIT;
} }
} }
@ -239,10 +242,12 @@ static int process_method(struct conn_s *connptr)
/* Filter domains out */ /* Filter domains out */
if (config.filter) { if (config.filter) {
if (filter_url(uri->authority)) { if (filter_url(uri->authority)) {
log_message(LOG_ERR, "clientreq: Filtered connection (%s)", log_message(LOG_ERR,
"Proxying refused on filtered domain \"%s\" from [%s].",
uri->authority,
peer_ipaddr); peer_ipaddr);
httperr(connptr, 404, httperr(connptr, 404,
"Unable to connect to filtered host."); "Connection to filtered domain is not allowed.");
update_stats(STAT_DENIED); update_stats(STAT_DENIED);
goto COMMON_EXIT; goto COMMON_EXIT;
} }
@ -253,7 +258,7 @@ static int process_method(struct conn_s *connptr)
request_len = strlen(inbuf) + 1; request_len = strlen(inbuf) + 1;
if (!(request = malloc(request_len))) { if (!(request = malloc(request_len))) {
log_message(LOG_ERR, log_message(LOG_ERR,
"clientreq: cannot allocate buffer for request from %s", "Could not allocate memory for request from [%s].",
peer_ipaddr); peer_ipaddr);
httperr(connptr, 503, HTTP503ERROR); httperr(connptr, 503, HTTP503ERROR);
update_stats(STAT_BADCONN); update_stats(STAT_BADCONN);
@ -544,7 +549,7 @@ static void relay_connection(struct conn_s *connptr)
if (ret == 0) { if (ret == 0) {
tdiff = difftime(time(NULL), last_access); tdiff = difftime(time(NULL), last_access);
if (tdiff > config.idletimeout) { if (tdiff > config.idletimeout) {
log_message(LOG_INFO, "Idle Timeout (after select) %g > %u", tdiff, config.idletimeout); log_message(LOG_INFO, "Idle Timeout (after select) as %g > %u.", tdiff, config.idletimeout);
return; return;
} else { } else {
continue; continue;
@ -642,7 +647,9 @@ void handle_connection(int fd)
connptr = malloc(sizeof(struct conn_s)); connptr = malloc(sizeof(struct conn_s));
if (!connptr) { if (!connptr) {
log_message(LOG_CRIT, "Out of memory!"); log_message(LOG_ERR,
"Could not allocate memory for request from [%s]",
peer_ipaddr);
return; return;
} }
@ -669,7 +676,7 @@ void handle_connection(int fd)
connptr->server_fd = opensock(config.tunnel_name, config.tunnel_port); connptr->server_fd = opensock(config.tunnel_name, config.tunnel_port);
if (connptr->server_fd < 0) { if (connptr->server_fd < 0) {
log_message(LOG_ERR, "Could not connect to tunnel's end, see if we can handle it ourselves."); log_message(LOG_WARNING, "Could not connect to tunnel's end, see if we can handle it ourselves.");
goto internal_proxy; goto internal_proxy;
} }

View File

@ -1,4 +1,4 @@
/* $Id: sock.c,v 1.6 2001-08-29 04:00:22 rjkaes Exp $ /* $Id: sock.c,v 1.7 2001-09-07 04:18:26 rjkaes Exp $
* *
* Sockets are created and destroyed here. When a new connection comes in from * Sockets are created and destroyed here. When a new connection comes in from
* a client, we need to copy the socket and the create a second socket to the * a client, we need to copy the socket and the create a second socket to the
@ -66,19 +66,19 @@ int opensock(char *ip_addr, uint16_t port)
ret = dnscache(&port_info.sin_addr, ip_addr); ret = dnscache(&port_info.sin_addr, ip_addr);
if (ret < 0) { if (ret < 0) {
log_message(LOG_ERR, "opensock: Could not lookup address: %s", ip_addr); log_message(LOG_ERR, "Could not lookup address [%s].", ip_addr);
return -1; return -1;
} }
port_info.sin_port = htons(port); port_info.sin_port = htons(port);
if ((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { if ((sock_fd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
log_message(LOG_ERR, "opensock: socket (%s)", strerror(errno)); log_message(LOG_ERR, "Could not create socket because of '%s'.", strerror(errno));
return -1; return -1;
} }
if (connect(sock_fd, (struct sockaddr*)&port_info, sizeof(port_info)) < 0) { if (connect(sock_fd, (struct sockaddr*)&port_info, sizeof(port_info)) < 0) {
log_message(LOG_ERR, "connecting socket"); log_message(LOG_ERR, "Could not connect socket because of '%s'", strerror(errno));
return -1; return -1;
} }

View File

@ -1,4 +1,4 @@
/* $Id: tinyproxy.c,v 1.13 2001-08-29 04:01:05 rjkaes Exp $ /* $Id: tinyproxy.c,v 1.14 2001-09-07 04:20:26 rjkaes Exp $
* *
* The initialise routine. Basically sets up all the initial stuff (logfile, * The initialise routine. Basically sets up all the initial stuff (logfile,
* listening socket, config options, etc.) and then sits there and loops * listening socket, config options, etc.) and then sits there and loops
@ -65,7 +65,7 @@ void takesig(int sig)
if (config.logf) if (config.logf)
ftruncate(fileno(config.logf), 0); ftruncate(fileno(config.logf), 0);
log_message(LOG_NOTICE, "SIGHUP received, cleaning up..."); log_message(LOG_NOTICE, "SIGHUP received, cleaning up.");
#ifdef FILTER_ENABLE #ifdef FILTER_ENABLE
if (config.filter) { if (config.filter) {
@ -173,7 +173,7 @@ int main(int argc, char **argv)
#ifdef HAVE_SETRLIMIT #ifdef HAVE_SETRLIMIT
struct rlimit core_limit = {0, 0}; struct rlimit core_limit = {0, 0};
if (setrlimit(RLIMIT_CORE, &core_limit) < 0) { if (setrlimit(RLIMIT_CORE, &core_limit) < 0) {
log_message(LOG_CRIT, "tinyproxy: could not set the core limit to zero."); fprintf(stderr, "%s: Could not set the core limit to zero.\n", argv[0]);
exit(EX_SOFTWARE); exit(EX_SOFTWARE);
} }
#endif /* HAVE_SETRLIMIT */ #endif /* HAVE_SETRLIMIT */
@ -196,7 +196,7 @@ int main(int argc, char **argv)
case 'c': case 'c':
conf_file = strdup(optarg); conf_file = strdup(optarg);
if (!conf_file) { if (!conf_file) {
log_message(LOG_EMERG, "tinyproxy: could not allocate memory"); fprintf(stderr, "%s: Could not allocate memory.\n", argv[0]);
exit(EX_SOFTWARE); exit(EX_SOFTWARE);
} }
break; break;
@ -212,7 +212,7 @@ int main(int argc, char **argv)
*/ */
yyin = fopen(conf_file, "r"); yyin = fopen(conf_file, "r");
if (!yyin) { if (!yyin) {
log_message(LOG_ERR, "Could not open %s file", conf_file); fprintf(stderr, "%s: Could not open configuration file \"%s\".\n", argv[0], conf_file);
exit(EX_SOFTWARE); exit(EX_SOFTWARE);
} }
yyparse(); yyparse();
@ -220,13 +220,13 @@ int main(int argc, char **argv)
/* Open the log file if not using syslog */ /* Open the log file if not using syslog */
if (config.syslog == FALSE) { if (config.syslog == FALSE) {
if (!config.logf_name) { if (!config.logf_name) {
fprintf(stderr, "You MUST set a LogFile in the configuration file.\n"); fprintf(stderr, "%s: You MUST set a LogFile in the configuration file.\n", argv[0]);
exit(EX_SOFTWARE); exit(EX_SOFTWARE);
} }
if (!(config.logf = fopen(config.logf_name, "a"))) { if (!(config.logf = fopen(config.logf_name, "a"))) {
fprintf(stderr, fprintf(stderr,
"Unable to open logfile %s for appending!\n", "Could not append to log file \"%s\".\n",
config.logf_name); config.logf_name);
exit(EX_CANTCREAT); exit(EX_CANTCREAT);
} }
@ -243,18 +243,18 @@ int main(int argc, char **argv)
* Set the default values if they were not set in the config file. * Set the default values if they were not set in the config file.
*/ */
if (config.port == 0) { if (config.port == 0) {
fprintf(stderr, "You MUST set a Port in the configuration file\n"); fprintf(stderr, "%s: You MUST set a Port in the configuration file.\n", argv[0]);
exit(EX_SOFTWARE); exit(EX_SOFTWARE);
} }
if (!config.stathost) { if (!config.stathost) {
log_message(LOG_INFO, "Setting stathost to \"%s\"", DEFAULT_STATHOST); log_message(LOG_INFO, "Setting stathost to \"%s\".", DEFAULT_STATHOST);
config.stathost = DEFAULT_STATHOST; config.stathost = DEFAULT_STATHOST;
} }
if (!config.username) { if (!config.username) {
log_message(LOG_WARNING, "You SHOULD set a UserName in the configuration file. Using current user instead."); log_message(LOG_WARNING, "You SHOULD set a UserName in the configuration file. Using current user instead.");
} }
if (config.idletimeout == 0) { if (config.idletimeout == 0) {
log_message(LOG_INFO, "Setting idle timeout to %u seconds", MAX_IDLE_TIME); log_message(LOG_INFO, "Setting idle timeout to %u seconds.", MAX_IDLE_TIME);
config.idletimeout = MAX_IDLE_TIME; config.idletimeout = MAX_IDLE_TIME;
} }
@ -280,7 +280,7 @@ int main(int argc, char **argv)
} }
if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) { if (signal(SIGPIPE, SIG_IGN) == SIG_ERR) {
log_message(LOG_CRIT, "Could not set SIGPIPE\n"); fprintf(stderr, "%s: Could not set the \"SIGPIPE\" signal.\n", argv[0]);
exit(EX_OSERR); exit(EX_OSERR);
} }
@ -293,7 +293,7 @@ int main(int argc, char **argv)
* Start listening on the selected port. * Start listening on the selected port.
*/ */
if (thread_listening_sock(config.port) < 0) { if (thread_listening_sock(config.port) < 0) {
log_message(LOG_CRIT, "Problem creating listening socket"); fprintf(stderr, "%s: Could not create listening socket.\n", argv[0]);
exit(EX_OSERR); exit(EX_OSERR);
} }
@ -304,33 +304,33 @@ int main(int argc, char **argv)
if (config.group && strlen(config.group) > 0) { if (config.group && strlen(config.group) > 0) {
thisgroup = getgrnam(config.group); thisgroup = getgrnam(config.group);
if (!thisgroup) { if (!thisgroup) {
log_message(LOG_ERR, "Unable to find group '%s'!", config.group); fprintf(stderr, "%s: Unable to find group \"%s\".\n", argv[0], config.group);
exit(EX_NOUSER); exit(EX_NOUSER);
} }
if (setgid(thisgroup->gr_gid) < 0) { if (setgid(thisgroup->gr_gid) < 0) {
log_message(LOG_ERR, "Unable to change to group '%s'", config.group); fprintf(stderr, "%s: Unable to change to group \"%s\".\n", argv[0], config.group);
exit(EX_CANTCREAT); exit(EX_CANTCREAT);
} }
log_message(LOG_INFO, "Now running as group %s", config.group); log_message(LOG_INFO, "Now running as group \"%s\".", config.group);
} }
if (config.username && strlen(config.username) > 0) { if (config.username && strlen(config.username) > 0) {
thisuser = getpwnam(config.username); thisuser = getpwnam(config.username);
if (!thisuser) { if (!thisuser) {
log_message(LOG_ERR, "Unable to find user '%s'!", config.username); fprintf(stderr, "%s: Unable to find user \"%s\".", argv[0], config.username);
exit(EX_NOUSER); exit(EX_NOUSER);
} }
if (setuid(thisuser->pw_uid) < 0) { if (setuid(thisuser->pw_uid) < 0) {
log_message(LOG_ERR, "Unable to change to user '%s'", config.username); fprintf(stderr, "%s: Unable to change to user \"%s\".", argv[0], config.username);
exit(EX_CANTCREAT); exit(EX_CANTCREAT);
} }
log_message(LOG_INFO, "Now running as user %s", config.username); log_message(LOG_INFO, "Now running as user \"%s\".", config.username);
} }
} else { } else {
log_message(LOG_WARNING, "Not running as root, so not changing UID/GID."); log_message(LOG_WARNING, "Not running as root, so not changing UID/GID.");
} }
if (thread_pool_create() < 0) { if (thread_pool_create() < 0) {
log_message(LOG_ERR, "Could not create the pool of threads"); fprintf(stderr, "%s: Could not create the pool of threads.", argv[0]);
exit(EX_SOFTWARE); exit(EX_SOFTWARE);
} }
@ -339,11 +339,11 @@ int main(int argc, char **argv)
*/ */
log_message(LOG_INFO, "Setting the various signals."); log_message(LOG_INFO, "Setting the various signals.");
if (signal(SIGTERM, takesig) == SIG_ERR) { if (signal(SIGTERM, takesig) == SIG_ERR) {
log_message(LOG_CRIT, "Could not set SIGTERM\n"); fprintf(stderr, "%s: Could not set the \"SIGTERM\" signal.\n", argv[0]);
exit(EX_OSERR); exit(EX_OSERR);
} }
if (signal(SIGHUP, takesig) == SIG_ERR) { if (signal(SIGHUP, takesig) == SIG_ERR) {
log_message(LOG_CRIT, "Could not set SIGHUP\n"); fprintf(stderr, "%s: Could not set the \"SIGHUP\" signal.\n", argv[0]);
exit(EX_OSERR); exit(EX_OSERR);
} }
@ -363,7 +363,7 @@ int main(int argc, char **argv)
* Remove the PID file. * Remove the PID file.
*/ */
if (unlink(config.pidpath) < 0) { if (unlink(config.pidpath) < 0) {
log_message(LOG_WARNING, "Could not remove PID file %s: %s", log_message(LOG_WARNING, "Could not remove PID file \"%s\": %s.",
config.pidpath, strerror(errno)); config.pidpath, strerror(errno));
} }

View File

@ -1,4 +1,4 @@
/* $Id: uri.c,v 1.4 2001-05-27 02:37:18 rjkaes Exp $ /* $Id: uri.c,v 1.5 2001-09-07 04:20:45 rjkaes Exp $
* *
* This borrows the REGEX from RFC2396 to split a URI string into the five * This borrows the REGEX from RFC2396 to split a URI string into the five
* primary components. The components are: * primary components. The components are:
@ -44,8 +44,10 @@ static int extract_uri(regmatch_t pmatch[], const char *buffer, char **section,
int substring) int substring)
{ {
size_t len = pmatch[substring].rm_eo - pmatch[substring].rm_so; size_t len = pmatch[substring].rm_eo - pmatch[substring].rm_so;
if ((*section = malloc(len + 1)) == NULL) if ((*section = malloc(len + 1)) == NULL) {
log_message(LOG_ERR, "Could not allocate memory for extracting URI.");
return -1; return -1;
}
memset(*section, '\0', len + 1); memset(*section, '\0', len + 1);
memcpy(*section, buffer + pmatch[substring].rm_so, len); memcpy(*section, buffer + pmatch[substring].rm_so, len);
@ -74,12 +76,12 @@ URI *explode_uri(const char *string)
memset(uri, 0, sizeof(URI)); memset(uri, 0, sizeof(URI));
if (regcomp(&preg, URIPATTERN, REG_EXTENDED) != 0) { if (regcomp(&preg, URIPATTERN, REG_EXTENDED) != 0) {
log_message(LOG_ERR, "explode_uri: regcomp"); log_message(LOG_ERR, "Regular Expression compiler error.");
goto ERROR_EXIT; goto ERROR_EXIT;
} }
if (regexec(&preg, string, NMATCH, pmatch, 0) != 0) { if (regexec(&preg, string, NMATCH, pmatch, 0) != 0) {
log_message(LOG_ERR, "explode_uri: regexec"); log_message(LOG_ERR, "Regular Expression search error.");
goto ERROR_EXIT; goto ERROR_EXIT;
} }

View File

@ -1,4 +1,4 @@
/* $Id: utils.c,v 1.8 2001-08-30 16:52:56 rjkaes Exp $ /* $Id: utils.c,v 1.9 2001-09-07 04:21:07 rjkaes Exp $
* *
* Misc. routines which are used by the various functions to handle strings * Misc. routines which are used by the various functions to handle strings
* and memory allocation and pretty much anything else we can think of. Also, * and memory allocation and pretty much anything else we can think of. Also,
@ -62,13 +62,13 @@ int httperr(struct conn_s *connptr, int err, const char *msg)
header_buffer = malloc(HEADER_SIZE); header_buffer = malloc(HEADER_SIZE);
if (!header_buffer) { if (!header_buffer) {
log_message(LOG_CRIT, "Out of memory!"); log_message(LOG_ERR, "Could not allocate memory.");
return -1; return -1;
} }
message_buffer = malloc(MAXBUFFSIZE); message_buffer = malloc(MAXBUFFSIZE);
if (!message_buffer) { if (!message_buffer) {
log_message(LOG_CRIT, "Out of memory!"); log_message(LOG_ERR, "Could not allocate memory.");
safefree(header_buffer); safefree(header_buffer);
return -1; return -1;
} }
@ -82,7 +82,7 @@ int httperr(struct conn_s *connptr, int err, const char *msg)
output_size = strlen(message_buffer) + strlen(header_buffer); output_size = strlen(message_buffer) + strlen(header_buffer);
connptr->output_message = malloc(output_size + 1); connptr->output_message = malloc(output_size + 1);
if (!connptr->output_message) { if (!connptr->output_message) {
log_message(LOG_CRIT, "Out of memory!"); log_message(LOG_ERR, "Could not allocate memory.");
safefree(header_buffer); safefree(header_buffer);
safefree(message_buffer); safefree(message_buffer);
return -1; return -1;
@ -135,7 +135,7 @@ static int create_file_safely(const char *filename)
* existing", exit. * existing", exit.
*/ */
if (errno != ENOENT) { if (errno != ENOENT) {
log_message(LOG_ERR, "Error checking PID file %s: %s", log_message(LOG_ERR, "Error checking PID file %s: %s.",
filename, strerror(errno)); filename, strerror(errno));
return -1; return -1;
} }
@ -146,7 +146,7 @@ static int create_file_safely(const char *filename)
* and open() * and open()
*/ */
if ((fildes = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600)) < 0) { if ((fildes = open(filename, O_RDWR | O_CREAT | O_EXCL, 0600)) < 0) {
log_message(LOG_ERR, "Could not create PID file %s: %s", log_message(LOG_ERR, "Could not create PID file %s: %s.",
filename, strerror(errno)); filename, strerror(errno));
return -1; return -1;
} }
@ -157,7 +157,7 @@ static int create_file_safely(const char *filename)
* Open an existing file. * Open an existing file.
*/ */
if ((fildes = open(filename, O_RDWR)) < 0) { if ((fildes = open(filename, O_RDWR)) < 0) {
log_message(LOG_ERR, "Could not open PID file %s: %s", log_message(LOG_ERR, "Could not open PID file %s: %s.",
filename, strerror(errno)); filename, strerror(errno));
return -1; return -1;
} }
@ -170,7 +170,7 @@ static int create_file_safely(const char *filename)
|| lstatinfo.st_mode != fstatinfo.st_mode || lstatinfo.st_mode != fstatinfo.st_mode
|| lstatinfo.st_ino != fstatinfo.st_ino || lstatinfo.st_ino != fstatinfo.st_ino
|| lstatinfo.st_dev != fstatinfo.st_dev) { || lstatinfo.st_dev != fstatinfo.st_dev) {
log_message(LOG_ERR, "The PID file %s has been changed before it could be opened!", log_message(LOG_ERR, "The PID file %s has been changed before it could be opened.",
filename); filename);
close(fildes); close(fildes);
return -1; return -1;
@ -184,7 +184,7 @@ static int create_file_safely(const char *filename)
* st_mode check would also find this) * st_mode check would also find this)
*/ */
if (fstatinfo.st_nlink > 1 || !S_ISREG(lstatinfo.st_mode)) { if (fstatinfo.st_nlink > 1 || !S_ISREG(lstatinfo.st_mode)) {
log_message(LOG_ERR, "The PID file %s has too many links, or is not a regular file: %s", log_message(LOG_ERR, "The PID file %s has too many links, or is not a regular file: %s.",
filename, strerror(errno)); filename, strerror(errno));
close(fildes); close(fildes);
return -1; return -1;
@ -203,7 +203,7 @@ static int create_file_safely(const char *filename)
#else #else
close(fildes); close(fildes);
if ((fildes = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) { if ((fildes = open(filename, O_RDWR | O_CREAT | O_TRUNC, 0600)) < 0) {
log_message(LOG_ERR, "Could not open PID file %s: %s", log_message(LOG_ERR, "Could not open PID file %s: %s.",
filename, strerror(errno)); filename, strerror(errno));
return -1; return -1;
} }
@ -231,7 +231,7 @@ void pidfile_create(const char *filename)
* Open a stdio file over the low-level one. * Open a stdio file over the low-level one.
*/ */
if ((fd = fdopen(fildes, "w")) == NULL) { if ((fd = fdopen(fildes, "w")) == NULL) {
log_message(LOG_ERR, "fdopen() error on PID file %s: %s", log_message(LOG_ERR, "fdopen() error on PID file %s: %s.",
filename, strerror(errno)); filename, strerror(errno));
close(fildes); close(fildes);
unlink(filename); unlink(filename);