* Added cs_addr field to struct CitContext -- holds a dotted quad string
authorArt Cancro <ajc@citadel.org>
Thu, 10 Jul 2003 05:51:46 +0000 (05:51 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 10 Jul 2003 05:51:46 +0000 (05:51 +0000)
  of the user's source IP (if applicable).  It's big enough to hold other
  types of address strings in the future (such as IPv6).
* locate_host() populates cs_addr when on a network connection.
* serv_smtp.c now saves the IP address in the proper place in
  the Received: header.
* is_public_client() no longer accepts a hostname.  It just looks at
  CC->cs_host instead.

citadel/ChangeLog
citadel/citserver.c
citadel/citserver.h
citadel/locate_host.c
citadel/locate_host.h
citadel/serv_smtp.c
citadel/server.h

index 43d40da19f06353cecac7d1d204c530a295caf86..12b34c5e290b7aa1f799e53e2d7ead74b09ba1aa 100644 (file)
@@ -1,4 +1,14 @@
  $Log$
+ Revision 607.16  2003/07/10 05:51:46  ajc
+ * Added cs_addr field to struct CitContext -- holds a dotted quad string
+   of the user's source IP (if applicable).  It's big enough to hold other
+   types of address strings in the future (such as IPv6).
+ * locate_host() populates cs_addr when on a network connection.
+ * serv_smtp.c now saves the IP address in the proper place in
+   the Received: header.
+ * is_public_client() no longer accepts a hostname.  It just looks at
+   CC->cs_host instead.
+
  Revision 607.15  2003/06/29 19:54:39  ajc
  * Renamed "struct user" to "struct ctdluser"
  * Renamed "struct room" to "struct ctdlroom"
@@ -4826,4 +4836,3 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
-
index 8ea2441fafb9b1a1f5833518937dcfa3485226f8..69853a1673ceb9e5233605a1e992fd39c4fd85f1 100644 (file)
@@ -404,28 +404,28 @@ static int hostnames_match(const char *realname, const char *testname) {
 }
 
 /*
- * Check a hostname against the public_clients file.  This determines
+ * Check originating host against the public_clients file.  This determines
  * whether the client is allowed to change the hostname for this session
  * (for example, to show the location of the user rather than the location
  * of the client).
  */
-int is_public_client(char *where)
+int is_public_client(void)
 {
        char buf[SIZ];
        FILE *fp;
 
-       lprintf(9, "Checking whether %s is a local client\n", where);
-       if (hostnames_match(where, "localhost")) return(1);
-       if (hostnames_match(where, config.c_fqdn)) return(1);
+       lprintf(9, "Checking whether %s is a local client\n",  CC->cs_host);
+       if (hostnames_match(CC->cs_host, "localhost")) return(1);
+       if (hostnames_match(CC->cs_host, config.c_fqdn)) return(1);
 
-       lprintf(9, "Checking whether %s is a public client\n", where);
+       lprintf(9, "Checking whether %s is a public client\n", CC->cs_host);
        fp = fopen("public_clients", "r");
        if (fp == NULL) return(0);
 
        while (fgets(buf, sizeof buf, fp)!=NULL) {
                while (isspace((buf[strlen(buf)-1]))) 
                        buf[strlen(buf)-1] = 0;
-               if (hostnames_match(where, buf)) {
+               if (hostnames_match(CC->cs_host, buf)) {
                        fclose(fp);
                        return(1);
                }
@@ -471,13 +471,15 @@ void cmd_iden(char *argbuf)
 
        if (strlen(from_host) > 0) {
                if (CC->is_local_socket) do_lookup = 1;
-               else if (is_public_client(CC->cs_host)) do_lookup = 1;
+               else if (is_public_client()) do_lookup = 1;
        }
 
        if (do_lookup) {
                lprintf(9, "Looking up hostname '%s'\n", from_host);
                if ((addr.s_addr = inet_addr(from_host)) != -1) {
-                       locate_host(CC->cs_host, sizeof CC->cs_host, &addr);
+                       locate_host(CC->cs_host, sizeof CC->cs_host,
+                               NULL, 0,
+                               &addr);
                }
                else {
                        safestrncpy(CC->cs_host, from_host, sizeof CC->cs_host);
@@ -848,12 +850,15 @@ void begin_session(struct CitContext *con)
        generate_nonce(con);
        snprintf(con->temp, sizeof con->temp, tmpnam(NULL));
        safestrncpy(con->cs_host, config.c_fqdn, sizeof con->cs_host);
+       safestrncpy(con->cs_addr, "", sizeof con->cs_addr);
        con->cs_host[sizeof con->cs_host - 1] = 0;
        len = sizeof sin;
        if (!CC->is_local_socket) {
                if (!getpeername(con->client_socket,
                   (struct sockaddr *) &sin, &len))
-                       locate_host(con->cs_host, sizeof con->cs_host, &sin.sin_addr);
+                       locate_host(con->cs_host, sizeof con->cs_host,
+                               con->cs_addr, sizeof con->cs_addr,
+                               &sin.sin_addr);
        }
        else {
                strcpy(con->cs_host, "");
index fc8d014959f8f1c4eb9b711e4a59a0438ae63401..45c80754a6a0129e34be9d14d15bf21ad624e927 100644 (file)
@@ -19,7 +19,6 @@ void set_wtmpsupp (char *newtext);
 void set_wtmpsupp_to_current_room(void);
 void cmd_info (void);
 void cmd_time (void);
-int is_public_client (char *where);
 void cmd_iden (char *argbuf);
 void cmd_mesg (char *mname);
 void cmd_emsg (char *mname);
index c95569dcf7cdb7a2d0adf7cfa08d4b32f16c7482..5ef13c8eb6df5f937bf76fef70e03ea0519c484e 100644 (file)
 #include "tools.h"
 #include "domain.h"
 
-void locate_host(char *tbuf, size_t n, const struct in_addr *addr)
+void locate_host(char *tbuf, size_t n,
+               char *abuf, size_t na,
+               const struct in_addr *addr)
 {
        struct hostent *ch;
        const char *i;
        char *j;
        int a1, a2, a3, a4;
+       char address_string[SIZ];
 
        lprintf(9, "locate_host() called\n");
 
@@ -38,15 +41,21 @@ void locate_host(char *tbuf, size_t n, const struct in_addr *addr)
        begin_critical_section(S_NETDB);
 #endif
 
-       if ((ch = gethostbyaddr((const char *) addr, sizeof(*addr), AF_INET)) ==
-           NULL) {
-             bad_dns:
-               i = (const char *) addr;
-               a1 = ((*i++) & 0xff);
-               a2 = ((*i++) & 0xff);
-               a3 = ((*i++) & 0xff);
-               a4 = ((*i++) & 0xff);
-               snprintf(tbuf, n, "%d.%d.%d.%d", a1, a2, a3, a4);
+       i = (const char *) addr;
+       a1 = ((*i++) & 0xff);
+       a2 = ((*i++) & 0xff);
+       a3 = ((*i++) & 0xff);
+       a4 = ((*i++) & 0xff);
+       sprintf(address_string, "%d.%d.%d.%d", a1, a2, a3, a4);
+
+       if (abuf != NULL) {
+               safestrncpy(abuf, address_string, na);
+       }
+
+       if ((ch = gethostbyaddr((const char *) addr,
+          sizeof(*addr), AF_INET)) == NULL) {
+bad_dns:
+               safestrncpy(tbuf, address_string, n);
                goto end;       /* because we might need to end the critical
                                   section */
        }
index 3c271102e83c34fd05aa1acb4ccbae8851f41da1..2f74049b02c8455844fd044c067a6834d2319fdb 100644 (file)
@@ -1,3 +1,5 @@
 /* $Id$ */
-void locate_host(char *tbuf, size_t n, const struct in_addr *addr);
+void locate_host(char *tbuf, size_t n,
+               char *abuf, size_t na,
+               const struct in_addr *addr);
 int rbl_check(char *message_to_spammer);
index 4b2872dcdfc6c7223fb6177cfe12e4149fe0b7c1..28a2ec01534ece1ce522d8b11bad3c088ad037e3 100644 (file)
@@ -493,14 +493,12 @@ void smtp_data(void) {
        datestring(nowstamp, sizeof nowstamp, time(NULL), DATESTRING_RFC822);
        body = mallok(4096);
 
-       /* FIXME
-          it should be Received: from %s (real.name.dom [w.x.y.z])
-        */
        if (body != NULL) snprintf(body, 4096,
-               "Received: from %s (%s)\n"
+               "Received: from %s (%s [%s])\n"
                "       by %s; %s\n",
                        SMTP->helo_node,
                        CC->cs_host,
+                       CC->cs_addr,
                        config.c_fqdn,
                        nowstamp);
        
index 575640ec8cd9bfdc83a95e1bbe63e3d76e941319..e25d5dda3c627561d539247a0d8b1bf29af3f741 100644 (file)
@@ -97,6 +97,7 @@ struct CitContext {
        int cs_clientver;       /* client version number */
        char cs_clientname[32]; /* name of client software */
        char cs_host[64];       /* host logged in from */
+       char cs_addr[64];       /* address logged in from */
 
        /* The Internet type of thing */
        char cs_inet_email[SIZ];/* Return address of outbound Internet mail */