* 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)
*/
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;
}
/*
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);
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();
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.
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;
#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);
/* 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;
}