Return-Path: Delivered-To: new-httpd-archive@hyperreal.org Received: (qmail 4876 invoked by uid 6000); 24 Oct 1997 06:42:04 -0000 Received: (qmail 4841 invoked from network); 24 Oct 1997 06:42:02 -0000 Received: from twinlark.arctic.org (204.62.130.91) by taz.hyperreal.org with SMTP; 24 Oct 1997 06:42:02 -0000 Received: (qmail 26282 invoked by uid 500); 24 Oct 1997 06:42:42 -0000 Date: Thu, 23 Oct 1997 23:42:42 -0700 (PDT) From: Dean Gaudet To: new-httpd@apache.org Subject: pre-patch: struct sockaddr_in error messages Message-ID: Organization: Transmeta Corp. MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: new-httpd-owner@apache.org Precedence: bulk Reply-To: new-httpd@apache.org We've got a few PRs on file asking for client addresses in various error messages. They're quite reasonable requests. I'd hoped we'd get this in way long ago as part of the error log cleanup. This patch adds two extensions to ap_snprintf: %S takes a struct sockaddr_in and prints it a.b.c.d:port %A takes a struct sockaddr_in and prints it a.b.c.d I tweaked a few things to use the extensions as an example. Here are sample log messages: [Thu Oct 23 23:32:18 1997] [error] client 10.1.2.210:3160 denied by server configuration: /home/dgaudet/ap/apachen2/htdocs/server-status [Thu Oct 23 23:32:57 1997] [error] client 127.0.0.1:3362 user asdf not found: /server-status [Thu Oct 23 23:33:15 1997] [error] client 127.0.0.1:3492 user dgaudet: password mismatch: /server-status This is either a feature, or part of the log cleanup. Take yer pick. I don't plan to do much with it either way, except ensure it's part of 2.0. I have to figure out how to make gcc not give printf warnings with the new extensions ... which probably means the syntax will change slightly, I'll have to look up the POSIXly proper way to extend printfs. Dean Index: main/util_snprintf.c =================================================================== RCS file: /export/home/cvs/apachen/src/main/util_snprintf.c,v retrieving revision 1.10 diff -u -r1.10 util_snprintf.c --- util_snprintf.c 1997/10/22 20:29:54 1.10 +++ util_snprintf.c 1997/10/24 06:34:27 @@ -398,6 +398,43 @@ +static char *conv_in_addr(struct in_addr *ia, char *buf_end, int *len) +{ + unsigned addr = ntohl(ia->s_addr); + char *p = buf_end; + bool_int is_negative; + int sub_len; + + p = conv_10((addr & 0x000000FF) , TRUE, &is_negative, p, &sub_len); + *--p = '.'; + p = conv_10((addr & 0x0000FF00) >> 8, TRUE, &is_negative, p, &sub_len); + *--p = '.'; + p = conv_10((addr & 0x00FF0000) >> 16, TRUE, &is_negative, p, &sub_len); + *--p = '.'; + p = conv_10((addr & 0xFF000000) >> 24, TRUE, &is_negative, p, &sub_len); + + *len = buf_end - p; + return (p); +} + + + +static char *conv_sockaddr_in(struct sockaddr_in *si, char *buf_end, int *len) +{ + char *p = buf_end; + bool_int is_negative; + int sub_len; + + p = conv_10(ntohs(si->sin_port), TRUE, &is_negative, p, &sub_len); + *--p = ':'; + p = conv_in_addr(&si->sin_addr, p, &sub_len); + + *len = buf_end - p; + return (p); +} + + + /* * Convert a floating point number to a string formats 'f', 'e' or 'E'. * The result is placed in buf, and len denotes the length of the string @@ -746,6 +783,45 @@ s_len = S_NULL_LEN; } pad_char = ' '; + break; + + + /* print a struct sockaddr_in as a.b.c.d:port */ + case 'S': + { + struct sockaddr_in *si; + + si = va_arg(ap, struct sockaddr_in *); + if (si != NULL) { + s = conv_sockaddr_in(si, &num_buf[NUM_BUF_SIZE], &s_len); + if (adjust_precision && precision < s_len) + s_len = precision; + } + else { + s = S_NULL; + s_len = S_NULL_LEN; + } + pad_char = ' '; + } + break; + + /* print a struct in_addr as a.b.c.d */ + case 'A': + { + struct in_addr *ia; + + ia = va_arg(ap, struct in_addr *); + if (ia != NULL) { + s = conv_in_addr(ia, &num_buf[NUM_BUF_SIZE], &s_len); + if (adjust_precision && precision < s_len) + s_len = precision; + } + else { + s = S_NULL; + s_len = S_NULL_LEN; + } + pad_char = ' '; + } break; Index: modules/standard/mod_access.c =================================================================== RCS file: /export/home/cvs/apachen/src/modules/standard/mod_access.c,v retrieving revision 1.27 diff -u -r1.27 mod_access.c --- mod_access.c 1997/10/22 20:30:11 1.27 +++ mod_access.c 1997/10/24 06:34:28 @@ -361,7 +361,8 @@ if (ret == FORBIDDEN && (satisfies(r) != SATISFY_ANY || !some_auth_required(r))) { aplog_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server, - "Client denied by server configuration: %s", r->filename); + "client %S denied by server configuration: %s", + &r->connection->remote_addr, r->filename); } return ret; Index: modules/standard/mod_auth.c =================================================================== RCS file: /export/home/cvs/apachen/src/modules/standard/mod_auth.c,v retrieving revision 1.29 diff -u -r1.29 mod_auth.c --- mod_auth.c 1997/10/22 20:30:14 1.29 +++ mod_auth.c 1997/10/24 06:34:28 @@ -207,14 +207,16 @@ if (!(sec->auth_authoritative)) return DECLINED; aplog_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server, - "user %s not found: %s", c->user, r->uri); + "client %S user %s not found: %s", + &r->connection->remote_addr, c->user, r->uri); note_basic_auth_failure(r); return AUTH_REQUIRED; } /* anyone know where the prototype for crypt is? */ if (strcmp(real_pw, (char *) crypt(sent_pw, real_pw))) { aplog_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server, - "user %s: password mismatch: %s", c->user, r->uri); + "client %S user %s: password mismatch: %s", + &r->connection->remote_addr, c->user, r->uri); note_basic_auth_failure(r); return AUTH_REQUIRED; } Index: modules/standard/mod_auth_dbm.c =================================================================== RCS file: /export/home/cvs/apachen/src/modules/standard/mod_auth_dbm.c,v retrieving revision 1.31 diff -u -r1.31 mod_auth_dbm.c --- mod_auth_dbm.c 1997/10/22 20:30:16 1.31 +++ mod_auth_dbm.c 1997/10/24 06:34:28 @@ -233,7 +233,8 @@ if (!(sec->auth_dbmauthoritative)) return DECLINED; aplog_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server, - "DBM user %s not found: %s", c->user, r->filename); + "client %S user %s: not found: %s", + &r->connection->remote_addr, c->user, r->uri); note_basic_auth_failure(r); return AUTH_REQUIRED; } @@ -244,7 +245,8 @@ /* anyone know where the prototype for crypt is? */ if (strcmp(real_pw, (char *) crypt(sent_pw, real_pw))) { aplog_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server, - "user %s: password mismatch: %s", c->user, r->uri); + "client %S user %s: password mismatch: %s", + &r->connection->remote_addr, c->user, r->uri); note_basic_auth_failure(r); return AUTH_REQUIRED; } @@ -289,8 +291,9 @@ if (!(sec->auth_dbmauthoritative)) return DECLINED; aplog_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server, - "user %s not in DBM group file %s: %s", - user, sec->auth_dbmgrpfile, r->filename); + "client %S user %s not in DBM group file %s: %s", + &r->connection->remote_addr, + user, sec->auth_dbmgrpfile, r->uri); note_basic_auth_failure(r); return AUTH_REQUIRED; } @@ -305,8 +308,9 @@ } } aplog_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ERR, r->server, - "user %s not in right group: %s", - user, r->filename); + "client %S user %s not in right group: %s", + &r->connection->remote_addr, + user, r->uri); note_basic_auth_failure(r); return AUTH_REQUIRED; }