got it right this time... also, more general interface to locate_host
authorNathan Bryant <loanshark@uncensored.citadel.org>
Thu, 8 Apr 1999 18:54:13 +0000 (18:54 +0000)
committerNathan Bryant <loanshark@uncensored.citadel.org>
Thu, 8 Apr 1999 18:54:13 +0000 (18:54 +0000)
citadel/ChangeLog
citadel/citserver.c
citadel/locate_host.c
citadel/locate_host.h

index e6f516f0fdf5856f2059242f66be70dc25d48d08..aa23b212a3a12cab374c29d1c9c375f91794fede 100644 (file)
@@ -2,6 +2,7 @@
        * citserver.c: improved is_public_client(), also if a public_client only
          supplies a numeric address, attempt to resolve it
        * locate_host.c: verify that the forward DNS matches the reverse
+       * locate_host.c, locate_host.h: more general interface
 
 Wed Apr  7 21:36:16 EDT 1999 Art Cancro <ajc@uncnsrd.mt-kisco.ny.us>
        * Implemented "access level required to create rooms" (client & server)
index ed45f720b951e79dd9f204c3eff2cb83aae26ab0..5e685dbd97543d984f416e4728d59806f34bebbb 100644 (file)
@@ -259,15 +259,24 @@ void cmd_time(void)
  */
 static int hostnames_match(const char *realname, const char *testname) {
        struct hostent *he;
+       int retval = 0;
 
        if (!strcasecmp(realname, testname))
                return 1;
 
+#ifdef HAVE_NONREENTRANT_NETDB
+       begin_critical_section(S_NETDB);
+#endif
+
        if ((he = gethostbyname(testname)) != NULL)
                if (!strcasecmp(realname, he->h_name))
-                       return 1;
+                       retval = 1;
+
+#ifdef HAVE_NONREENTRANT_NETDB
+       end_critical_section(S_NETDB);
+#endif
 
-       return 0;
+       return retval;
        }
 
 /*
@@ -309,7 +318,6 @@ void cmd_iden(char *argbuf)
        char desc[256];
        char from_host[256];
        struct in_addr addr;
-       struct hostent *he;
 
        if (num_parms(argbuf)<4) {
                cprintf("%d usage error\n",ERROR);
@@ -333,13 +341,12 @@ void cmd_iden(char *argbuf)
 
        if ((strlen(from_host)>0) && 
           (is_public_client(CC->cs_host))) {
-               if (inet_aton(from_host, &addr) &&
-                   (he = gethostbyaddr((char*)&addr, sizeof addr, AF_INET)) !=
-                   NULL)
-                       strncpy(CC->cs_host,he->h_name,24);
-               else
+               if (inet_aton(from_host, &addr))
+                       locate_host(CC->cs_host, &addr);
+               else {
                        strncpy(CC->cs_host,from_host,24);
-               CC->cs_host[24] = 0;
+                       CC->cs_host[24] = 0;
+                       }
                }
        set_wtmpsupp_to_current_room();
 
@@ -699,7 +706,8 @@ void cmd_scdn(char *argbuf)
 void *context_loop(struct CitContext *con)
 {
        char cmdbuf[256];
-       int num_sessions;
+       int num_sessions, len;
+       struct sockaddr_in sin;
 
        /*
         * Wedge our way into the context table.
@@ -727,7 +735,9 @@ void *context_loop(struct CitContext *con)
        strcpy(CC->cs_room, "(no room)");
        strncpy(CC->cs_host, config.c_fqdn, sizeof CC->cs_host);
        CC->cs_host[sizeof CC->cs_host - 1] = 0;
-       locate_host(CC->cs_host);
+       len = sizeof sin;
+       if (!getpeername(CC->client_socket, (struct sockaddr *) &sin, &len))
+               locate_host(CC->cs_host, &sin.sin_addr);
        CC->cs_flags = 0;
        CC->upload_type = UPL_FILE;
        CC->dl_is_net = 0;
index a18d6e99a39c406659b194c81b2458120aa04dac..2860c6a828c647e63b295faaefd4f30a3e71be4c 100644 (file)
 #include "locate_host.h"
 #include "config.h"
 
-void locate_host(char *tbuf)
+void locate_host(char *tbuf, const struct in_addr *addr)
 {
-       struct sockaddr_in cs;
        struct hostent *ch, *ch2;
-       int len;
        char *i;
        int a1, a2, a3, a4;
 
-       len = sizeof(cs);
-       if (getpeername(CC->client_socket, (struct sockaddr *) &cs, &len) < 0) {
-               strcpy(tbuf, config.c_fqdn);
-               return;
-       }
 #ifdef HAVE_NONREENTRANT_NETDB
        begin_critical_section(S_NETDB);
 #endif
 
-       if ((ch = gethostbyaddr((char *) &cs.sin_addr, sizeof(cs.sin_addr),
-                               AF_INET)) == NULL) {
+       if ((ch = gethostbyaddr((char *) addr, sizeof(*addr), AF_INET)) ==
+           NULL) {
              bad_dns:
-               i = (char *) &cs.sin_addr;
+               i = (char *) addr;
                a1 = ((*i++) & 0xff);
                a2 = ((*i++) & 0xff);
                a3 = ((*i++) & 0xff);
@@ -57,8 +50,8 @@ void locate_host(char *tbuf)
 
        /* check address for consistency */
        for (; *ch2->h_addr_list; ch2->h_addr_list++)
-               if (!memcmp(*ch2->h_addr_list, &cs.sin_addr,
-                           sizeof cs.sin_addr)) {
+               if (!memcmp(*ch2->h_addr_list, addr,
+                           sizeof *addr)) {
                        strncpy(tbuf, ch->h_name, 24);
                        goto end;
                }
index 73a88ebd7db0f8c642efab47d41147db1bd2d738..69e343574c09b81587b0334df10adfd26c9e2af3 100644 (file)
@@ -1,2 +1,2 @@
 /* $Id$ */
-void locate_host(char *tbuf);
+void locate_host(char *tbuf, const struct in_addr *addr);