--- source/lib/util_sock.c.orig 2004-02-06 17:40:30.000000000 -0500 +++ source/lib/util_sock.c 2004-04-27 15:22:15.000000000 -0400 @@ -932,6 +932,65 @@ } /******************************************************************* + Return the DNS name of the local end of a socket. +******************************************************************/ + +char *get_local_name(int fd, BOOL force_lookup) +{ + static pstring name_buf; + pstring tmp_name; + static fstring addr_buf; + struct hostent *hp; + struct in_addr addr; + char *p; + + /* reverse lookups can be *very* expensive, but hopefully name for a + local socket address can be found quickly. Do same checks as + get_peer_name. */ + if (!lp_hostname_lookups() && (force_lookup == False)) { + return get_socket_addr(fd); + } + + p = get_socket_addr(fd); + + /* it might be the same as the last one - save some DNS work */ + if (strcmp(p, addr_buf) == 0) + return name_buf; + + pstrcpy(name_buf,"UNKNOWN"); + if (fd == -1) + return name_buf; + + fstrcpy(addr_buf, p); + + addr = *interpret_addr2(p); + + /* Look up the remote host name. */ + if ((hp = gethostbyaddr((char *)&addr.s_addr, sizeof(addr.s_addr), AF_INET)) == 0) { + DEBUG(1,("Gethostbyaddr failed for %s\n",p)); + pstrcpy(name_buf, p); + } else { + pstrcpy(name_buf,(char *)hp->h_name); + if (!matchname(name_buf, addr)) { + DEBUG(0,("Matchname failed on %s %s\n",name_buf,p)); + pstrcpy(name_buf,"UNKNOWN"); + } + } + + /* can't pass the same source and dest strings in when you + use --enable-developer or the clobber_region() call will + get you */ + + pstrcpy( tmp_name, name_buf ); + alpha_strcpy(name_buf, tmp_name, "_-.", sizeof(name_buf)); + if (strstr(name_buf,"..")) { + pstrcpy(name_buf, "UNKNOWN"); + } + + return name_buf; +} + +/******************************************************************* Return the IP addr of the remote end of a socket as a string. ******************************************************************/ --- source/smbd/server.c.orig 2004-01-16 12:47:53.000000000 -0500 +++ source/smbd/server.c 2004-04-27 15:22:27.000000000 -0400 @@ -399,6 +399,11 @@ /* this is needed so that we get decent entries in smbstatus for port 445 connects */ set_remote_machine_name(get_peer_addr(smbd_server_fd()), False); + + /* this is needed for a decent get_called_name + for port 445 connects. Otherwise, we end up + global_myname() from init_names() */ + set_local_machine_name(get_local_name(smbd_server_fd(), True), False); /* Reset global variables in util.c so that client substitutions will be