From 4a7a883bee0c7d58b8635888340bf5f07dbdd1bb Mon Sep 17 00:00:00 2001 From: Nathan Bryant Date: Thu, 8 Apr 1999 18:54:13 +0000 Subject: [PATCH] got it right this time... also, more general interface to locate_host --- citadel/ChangeLog | 1 + citadel/citserver.c | 32 +++++++++++++++++++++----------- citadel/locate_host.c | 19 ++++++------------- citadel/locate_host.h | 2 +- 4 files changed, 29 insertions(+), 25 deletions(-) diff --git a/citadel/ChangeLog b/citadel/ChangeLog index e6f516f0f..aa23b212a 100644 --- a/citadel/ChangeLog +++ b/citadel/ChangeLog @@ -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 * Implemented "access level required to create rooms" (client & server) diff --git a/citadel/citserver.c b/citadel/citserver.c index ed45f720b..5e685dbd9 100644 --- a/citadel/citserver.c +++ b/citadel/citserver.c @@ -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; diff --git a/citadel/locate_host.c b/citadel/locate_host.c index a18d6e99a..2860c6a82 100644 --- a/citadel/locate_host.c +++ b/citadel/locate_host.c @@ -22,27 +22,20 @@ #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; } diff --git a/citadel/locate_host.h b/citadel/locate_host.h index 73a88ebd7..69e343574 100644 --- a/citadel/locate_host.h +++ b/citadel/locate_host.h @@ -1,2 +1,2 @@ /* $Id$ */ -void locate_host(char *tbuf); +void locate_host(char *tbuf, const struct in_addr *addr); -- 2.39.2