From a2c1623827406667a4f2f058c24f1d971f6627f8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 4 Jun 1996 06:42:03 +0000 Subject: a huge pile of changes :-) The biggest thing is the integration of Lukes new nmbd. Its still largely untested, so we will really need some feedback I've also added auto prototype generation and cleaned up a lot of minor things as a result (This used to be commit 0d8dcfa13c527ec2c8aca39ba49c09e4e694b26c) --- source3/nmbd/nmbd.c | 601 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 601 insertions(+) create mode 100644 source3/nmbd/nmbd.c (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c new file mode 100644 index 0000000000..222ab3f921 --- /dev/null +++ b/source3/nmbd/nmbd.c @@ -0,0 +1,601 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Andrew Tridgell 1994-1995 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + Revision History: + + 14 jan 96: lkcl@pires.co.uk + added multiple workgroup domain master support + +*/ + +#include "includes.h" +#include "loadparm.h" +#include "localnet.h" + +extern int DEBUGLEVEL; + +extern pstring debugf; +pstring servicesf = CONFIGFILE; + +extern pstring scope; + +int ClientNMB = -1; +int ClientDGRAM = -1; + +extern pstring myhostname; +static pstring host_file; +extern pstring myname; + +/* are we running as a daemon ? */ +static BOOL is_daemon = False; + +/* machine comment for host announcements */ +pstring ServerComment=""; + +static BOOL got_bcast = False; +static BOOL got_myip = False; +static BOOL got_nmask = False; + +/* what server type are we currently */ + +time_t StartupTime =0; + +struct in_addr ipzero; + + +/**************************************************************************** +catch a sighup +****************************************************************************/ +static int sig_hup(void) +{ + BlockSignals(True); + + DEBUG(0,("Got SIGHUP (reload not implemented)\n")); + dump_names(); + reload_services(True); + + BlockSignals(False); +#ifndef DONT_REINSTALL_SIG + signal(SIGHUP,SIGNAL_CAST sig_hup); +#endif + return(0); +} + +/**************************************************************************** +catch a sigpipe +****************************************************************************/ +static int sig_pipe(void) +{ + BlockSignals(True); + + DEBUG(0,("Got SIGPIPE\n")); + if (!is_daemon) + exit(1); + BlockSignals(False); + return(0); +} + +#if DUMP_CORE +/******************************************************************* +prepare to dump a core file - carefully! +********************************************************************/ +static BOOL dump_core(void) +{ + char *p; + pstring dname; + strcpy(dname,debugf); + if ((p=strrchr(dname,'/'))) *p=0; + strcat(dname,"/corefiles"); + mkdir(dname,0700); + sys_chown(dname,getuid(),getgid()); + chmod(dname,0700); + if (chdir(dname)) return(False); + umask(~(0700)); + +#ifndef NO_GETRLIMIT +#ifdef RLIMIT_CORE + { + struct rlimit rlp; + getrlimit(RLIMIT_CORE, &rlp); + rlp.rlim_cur = MAX(4*1024*1024,rlp.rlim_cur); + setrlimit(RLIMIT_CORE, &rlp); + getrlimit(RLIMIT_CORE, &rlp); + DEBUG(3,("Core limits now %d %d\n",rlp.rlim_cur,rlp.rlim_max)); + } +#endif +#endif + + + DEBUG(0,("Dumping core in %s\n",dname)); + return(True); +} +#endif + + +/**************************************************************************** +possibly continue after a fault +****************************************************************************/ +static void fault_continue(void) +{ +#if DUMP_CORE + dump_core(); +#endif +} + +/******************************************************************* + expire old names from the namelist and server list + ******************************************************************/ +static void expire_names_and_servers(void) +{ + static time_t lastrun = 0; + time_t t = time(NULL); + + if (!lastrun) lastrun = t; + if (t < lastrun + 5) return; + lastrun = t; + + expire_names(t); + expire_servers(t); +} + +/***************************************************************************** + reload the services file + **************************************************************************/ +BOOL reload_services(BOOL test) +{ + BOOL ret; + extern fstring remote_machine; + + strcpy(remote_machine,"nmbd"); + + if (lp_loaded()) + { + pstring fname; + strcpy(fname,lp_configfile()); + if (file_exist(fname,NULL) && !strcsequal(fname,servicesf)) + { + strcpy(servicesf,fname); + test = False; + } + } + + if (test && !lp_file_list_changed()) + return(True); + + ret = lp_load(servicesf,True); + + /* perhaps the config filename is now set */ + if (!test) { + DEBUG(3,("services not loaded\n")); + reload_services(True); + } + + return(ret); +} + + + +/**************************************************************************** +load a netbios hosts file +****************************************************************************/ +static void load_hosts_file(char *fname) +{ + FILE *f = fopen(fname,"r"); + pstring line; + if (!f) { + DEBUG(2,("Can't open lmhosts file %s\n",fname)); + return; + } + + while (!feof(f)) + { + if (!fgets_slash(line,sizeof(pstring),f)) continue; + + if (*line == '#') continue; + + { + BOOL group=False; + + pstring ip,name,mask,flags,extra; + + char *ptr; + int count = 0; + struct in_addr ipaddr; + struct in_addr ipmask; + enum name_source source = LMHOSTS; + + strcpy(ip,""); + strcpy(name,""); + strcpy(mask,""); + strcpy(flags,""); + strcpy(extra,""); + + ptr = line; + + if (next_token(&ptr,ip ,NULL)) ++count; + if (next_token(&ptr,name ,NULL)) ++count; + if (next_token(&ptr,mask ,NULL)) ++count; + if (next_token(&ptr,flags,NULL)) ++count; + if (next_token(&ptr,extra,NULL)) ++count; + + if (count <= 0) continue; + + if (count > 0 && count < 2) { + DEBUG(0,("Ill formed hosts line [%s]\n",line)); + continue; + } + + /* work out if we need to shuffle the tokens along due to the + optional subnet mask argument */ + + if (strchr(mask, 'G') || strchr(mask, 'S') || strchr(mask, 'M')) { + strcpy(flags, mask ); + /* default action for no subnet mask */ + strcpy(mask, inet_ntoa(Netmask)); + } + + DEBUG(4, ("lmhost entry: %s %s %s %s\n", ip, name, mask, flags)); + + if (strchr(flags,'G') || strchr(flags,'S')) + group = True; + + if (strchr(flags,'M') && !group) { + source = SELF; + strcpy(myname,name); + } + + ipaddr = *interpret_addr2(ip); + ipmask = *interpret_addr2(mask); + + if (group) { + add_domain_entry(ipaddr, ipmask, name, True); + } else { + add_netbios_entry(name,0x20,NB_ACTIVE,0,source,ipaddr); + } + } + } + + fclose(f); +} + + +/**************************************************************************** + The main select loop. + ***************************************************************************/ +static void process(void) +{ + BOOL run_election; + + while (True) + { + run_election = check_elections(); + listen_for_packets(run_election); + + run_packet_queue(); + run_elections(); + + announce_host(); + announce_backup(); + announce_master(); + + expire_names_and_servers(); + expire_netbios_response_entries(time(NULL)-10); + + write_browse_list(); + do_browser_lists(); + check_master_browser(); + } +} + + +/**************************************************************************** + open the socket communication +****************************************************************************/ +static BOOL open_sockets(BOOL isdaemon, int port) +{ + struct hostent *hp; + + /* get host info */ + if ((hp = Get_Hostbyname(myhostname)) == 0) { + DEBUG(0,( "Get_Hostbyname: Unknown host. %s\n",myhostname)); + return False; + } + + if (isdaemon) + ClientNMB = open_socket_in(SOCK_DGRAM, port,0); + else + ClientNMB = 0; + + ClientDGRAM = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3); + + if (ClientNMB == -1) + return(False); + + signal(SIGPIPE, SIGNAL_CAST sig_pipe); + + set_socket_options(ClientNMB,"SO_BROADCAST"); + set_socket_options(ClientDGRAM,"SO_BROADCAST"); + + DEBUG(3,("Sockets opened.\n")); + return True; +} + + +/******************************************************************* + check that a IP, bcast and netmask and consistent. Must be a 1s + broadcast + ******************************************************************/ +static BOOL ip_consistent(struct in_addr ip,struct in_addr bcast, struct in_addr nmask) +{ + unsigned long a_ip,a_bcast,a_nmask; + + a_ip = ntohl(ip.s_addr); + a_bcast = ntohl(bcast.s_addr); + a_nmask = ntohl(nmask.s_addr); + + /* check the netmask is sane */ + if (((a_nmask>>24)&0xFF) != 0xFF) { + DEBUG(0,("Insane netmask %s\n",inet_ntoa(nmask))); + return(False); + } + + /* check the IP and bcast are on the same net */ + if ((a_ip&a_nmask) != (a_bcast&a_nmask)) { + DEBUG(0,("IP and broadcast are on different nets!\n")); + return(False); + } + + /* check the IP and bcast are on the same net */ + if ((a_bcast|a_nmask) != 0xFFFFFFFF) { + DEBUG(0,("Not a ones based broadcast %s\n",inet_ntoa(bcast))); + return(False); + } + + return(True); +} + + +/**************************************************************************** + initialise connect, service and file structs +****************************************************************************/ +static BOOL init_structs() +{ + if (!get_myname(myhostname,got_myip?NULL:&myip)) + return(False); + + /* Read the broadcast address from the interface */ + { + struct in_addr ip0,ip1,ip2; + + ip0 = myip; + + if (!(got_bcast && got_nmask)) + { + get_broadcast(&ip0,&ip1,&ip2); + + if (!got_myip) + myip = ip0; + + if (!got_bcast) + bcast_ip = ip1; + + if (!got_nmask) + Netmask = ip2; + } + + DEBUG(1,("Using IP %s ",inet_ntoa(myip))); + DEBUG(1,("broadcast %s ",inet_ntoa(bcast_ip))); + DEBUG(1,("netmask %s\n",inet_ntoa(Netmask))); + + if (!ip_consistent(myip,bcast_ip,Netmask)) { + DEBUG(0,("WARNING: The IP address, broadcast and Netmask are not consistent\n")); + DEBUG(0,("You are likely to experience problems with this setup!\n")); + } + } + + if (! *myname) { + char *p; + strcpy(myname,myhostname); + p = strchr(myname,'.'); + if (p) *p = 0; + } + + return True; +} + +/**************************************************************************** +usage on the program +****************************************************************************/ +static void usage(char *pname) +{ + DEBUG(0,("Incorrect program usage - is the command line correct?\n")); + + printf("Usage: %s [-n name] [-B bcast address] [-D] [-p port] [-d debuglevel] [-l log basename]\n",pname); + printf("Version %s\n",VERSION); + printf("\t-D become a daemon\n"); + printf("\t-p port listen on the specified port\n"); + printf("\t-d debuglevel set the debuglevel\n"); + printf("\t-l log basename. Basename for log/debug files\n"); + printf("\t-n netbiosname. the netbios name to advertise for this host\n"); + printf("\t-B broadcast address the address to use for broadcasts\n"); + printf("\t-N netmask the netmask to use for subnet determination\n"); + printf("\t-H hosts file load a netbios hosts file\n"); + printf("\t-G group name add a group name to be part of\n"); + printf("\t-I ip-address override the IP address\n"); + printf("\t-C comment sets the machine comment that appears in browse lists\n"); + printf("\n"); +} + + +/**************************************************************************** + main program + **************************************************************************/ + int main(int argc,char *argv[]) +{ + int port = NMB_PORT; + int opt; + extern FILE *dbf; + extern char *optarg; + + *host_file = 0; + + StartupTime = time(NULL); + + TimeInit(); + + strcpy(debugf,NMBLOGFILE); + + setup_logging(argv[0],False); + + charset_initialise(); + + ipzero = *interpret_addr2("0.0.0.0"); + +#ifdef LMHOSTSFILE + strcpy(host_file,LMHOSTSFILE); +#endif + + /* this is for people who can't start the program correctly */ + while (argc > 1 && (*argv[1] != '-')) { + argv++; + argc--; + } + + fault_setup(fault_continue); + + signal(SIGHUP,SIGNAL_CAST sig_hup); + + bcast_ip = ipzero; + myip = ipzero; + + while ((opt = getopt (argc, argv, "s:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:")) != EOF) + { + switch (opt) + { + case 's': + strcpy(servicesf,optarg); + break; + case 'C': + strcpy(ServerComment,optarg); + break; + case 'G': + if (got_bcast && got_nmask) { + add_domain_entry(bcast_ip,Netmask,optarg, True); + } else { + DEBUG(0, ("Warning: option -G %s added before broadcast and netmask.\n", + optarg)); + DEBUG(0, ("Assuming default values: bcast %s netmask %s\n", + inet_ntoa(bcast_ip), inet_ntoa(Netmask))); /* (i hope) */ + } + break; + case 'H': + strcpy(host_file,optarg); + break; + case 'I': + myip = *interpret_addr2(optarg); + got_myip = True; + break; + case 'B': + bcast_ip = *interpret_addr2(optarg); + got_bcast = True; + break; + case 'N': + Netmask = *interpret_addr2(optarg); + got_nmask = True; + break; + case 'n': + strcpy(myname,optarg); + break; + case 'l': + sprintf(debugf,"%s.nmb",optarg); + break; + case 'i': + strcpy(scope,optarg); + strupper(scope); + break; + case 'D': + is_daemon = True; + break; + case 'd': + DEBUGLEVEL = atoi(optarg); + break; + case 'p': + port = atoi(optarg); + break; + case 'h': + usage(argv[0]); + exit(0); + break; + default: + if (!is_a_socket(0)) { + usage(argv[0]); + } + break; + } + } + + DEBUG(1,("%s netbios nameserver version %s started\n",timestring(),VERSION)); + DEBUG(1,("Copyright Andrew Tridgell 1994\n")); + + init_structs(); + + if (!reload_services(False)) + return(-1); + + if (!is_daemon && !is_a_socket(0)) { + DEBUG(0,("standard input is not a socket, assuming -D option\n")); + is_daemon = True; + } + + if (is_daemon) { + DEBUG(2,("%s becoming a daemon\n",timestring())); + become_daemon(); + } + + DEBUG(3,("Opening sockets %d\n", port)); + + if (!open_sockets(is_daemon,port)) return 1; + + if (*host_file) { + load_hosts_file(host_file); + DEBUG(3,("Loaded hosts file\n")); + } + + if (!*ServerComment) + strcpy(ServerComment,"Samba %v"); + string_sub(ServerComment,"%v",VERSION); + string_sub(ServerComment,"%h",myhostname); + + add_my_names(); + add_my_domains(); + + DEBUG(3,("Checked names\n")); + + write_browse_list(); + + DEBUG(3,("Dumped names\n")); + + process(); + close_sockets(); + + if (dbf) + fclose(dbf); + return(0); +} -- cgit From a2641cfe00b7857056fd8fd1e020aae7ea817690 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 4 Jun 1996 15:14:47 +0000 Subject: Did more integration of Lukes code ready for the first release. I've now got WINS registration working, and refresh working. Its looking pretty good so far, but needs lots of testing. (This used to be commit 045014aa57721b9701ca379bcab055b908773184) --- source3/nmbd/nmbd.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 222ab3f921..b6ef717cc0 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -144,15 +144,15 @@ static void fault_continue(void) ******************************************************************/ static void expire_names_and_servers(void) { - static time_t lastrun = 0; - time_t t = time(NULL); - - if (!lastrun) lastrun = t; - if (t < lastrun + 5) return; - lastrun = t; - - expire_names(t); - expire_servers(t); + static time_t lastrun = 0; + time_t t = time(NULL); + + if (!lastrun) lastrun = t; + if (t < lastrun + 5) return; + lastrun = t; + + expire_names(t); + expire_servers(t); } /***************************************************************************** @@ -285,6 +285,7 @@ static void process(void) while (True) { + time_t t = time(NULL); run_election = check_elections(); listen_for_packets(run_election); @@ -296,7 +297,8 @@ static void process(void) announce_master(); expire_names_and_servers(); - expire_netbios_response_entries(time(NULL)-10); + expire_netbios_response_entries(t-10); + refresh_my_names(t); write_browse_list(); do_browser_lists(); -- cgit From e38afbf38210b8cf30c5b13dc5ea96a6dda433f7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 5 Jun 1996 15:16:09 +0000 Subject: - changed some debug levels in clientutil.c - added dir_check_ftype() to clean up the file type checking a bit - added check for libc version >= 5 for setfsuid() for Linux - moved the AM_MASTER() and related macros to nameserv.h - added proper defines for the various netbios announce types - don't call the announce_backup() code, as I'm pretty sure its wrong it sent ANN_GetBackupListReq packets as broadcasts, they are supposed to be used only by clients to the master browser to find a list of available backup servers to remote a netserverenum to, I don't think nmbd should ever send one. - fixed a bug in the browse list writing - minor debug cleanups - put in the code to discard our own broadcasts (it won't work for multi-homed hosts though) - changed ELECTION_VERSION to 1 so we can be beaten by a NT 3.51 server by lowering the os level. - only do sync_browse_lists() if we are the master browser, otherwise we'll cause network overload - don't call tell_become_backup() as it appears to be badly broken, it should only be used when the machine being told has its MAINTAIN_LIST to to auto. Not calling it does no great harm anyway - fix a nasty bug where becomebackup was confused with reset browser! - make setbuffer() not get caught by the auto protototypes (This used to be commit cfbad9b08242962f41595273de08a7293fe432b1) --- source3/nmbd/nmbd.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index b6ef717cc0..a977667c2e 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -293,7 +293,14 @@ static void process(void) run_elections(); announce_host(); + +#if 0 + /* what was this stuff supposed to do? It sent + ANN_GetBackupListReq packets which I think should only be + sent when trying to find out who to browse with */ announce_backup(); +#endif + announce_master(); expire_names_and_servers(); -- cgit From b9ae225b28f4707609e6436dad4be7ebdd7e181f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Jun 1996 11:43:09 +0000 Subject: - added interface.c and removed all the references to myip, bcast_ip and Netmask, instead replacing them with calls to routines in interface.c - got rid of old MAXINT define - added code to ensure we only return one entry for each name in the ipc enum routines - added new_only option to add_netbios_entry() to prevent overwriting of important names - minor time handling fixup (This used to be commit 7ed71b73ae745da099072eee36fc2700d1d91407) --- source3/nmbd/nmbd.c | 112 +++++++++------------------------------------------- 1 file changed, 19 insertions(+), 93 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index a977667c2e..b93ac2d580 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -27,7 +27,6 @@ #include "includes.h" #include "loadparm.h" -#include "localnet.h" extern int DEBUGLEVEL; @@ -49,15 +48,11 @@ static BOOL is_daemon = False; /* machine comment for host announcements */ pstring ServerComment=""; -static BOOL got_bcast = False; -static BOOL got_myip = False; -static BOOL got_nmask = False; - /* what server type are we currently */ time_t StartupTime =0; -struct in_addr ipzero; +extern struct in_addr ipzero; /**************************************************************************** @@ -187,6 +182,8 @@ BOOL reload_services(BOOL test) reload_services(True); } + load_interfaces(); + return(ret); } @@ -248,7 +245,7 @@ static void load_hosts_file(char *fname) if (strchr(mask, 'G') || strchr(mask, 'S') || strchr(mask, 'M')) { strcpy(flags, mask ); /* default action for no subnet mask */ - strcpy(mask, inet_ntoa(Netmask)); + strcpy(mask, ""); } DEBUG(4, ("lmhost entry: %s %s %s %s\n", ip, name, mask, flags)); @@ -262,12 +259,15 @@ static void load_hosts_file(char *fname) } ipaddr = *interpret_addr2(ip); - ipmask = *interpret_addr2(mask); + if (*mask) + ipmask = *interpret_addr2(mask); + else + ipmask = *iface_nmask(ipaddr); if (group) { add_domain_entry(ipaddr, ipmask, name, True); } else { - add_netbios_entry(name,0x20,NB_ACTIVE,0,source,ipaddr); + add_netbios_entry(name,0x20,NB_ACTIVE,0,source,ipaddr,False); } } } @@ -347,78 +347,14 @@ static BOOL open_sockets(BOOL isdaemon, int port) } -/******************************************************************* - check that a IP, bcast and netmask and consistent. Must be a 1s - broadcast - ******************************************************************/ -static BOOL ip_consistent(struct in_addr ip,struct in_addr bcast, struct in_addr nmask) -{ - unsigned long a_ip,a_bcast,a_nmask; - - a_ip = ntohl(ip.s_addr); - a_bcast = ntohl(bcast.s_addr); - a_nmask = ntohl(nmask.s_addr); - - /* check the netmask is sane */ - if (((a_nmask>>24)&0xFF) != 0xFF) { - DEBUG(0,("Insane netmask %s\n",inet_ntoa(nmask))); - return(False); - } - - /* check the IP and bcast are on the same net */ - if ((a_ip&a_nmask) != (a_bcast&a_nmask)) { - DEBUG(0,("IP and broadcast are on different nets!\n")); - return(False); - } - - /* check the IP and bcast are on the same net */ - if ((a_bcast|a_nmask) != 0xFFFFFFFF) { - DEBUG(0,("Not a ones based broadcast %s\n",inet_ntoa(bcast))); - return(False); - } - - return(True); -} - - /**************************************************************************** initialise connect, service and file structs ****************************************************************************/ static BOOL init_structs() { - if (!get_myname(myhostname,got_myip?NULL:&myip)) + if (!get_myname(myhostname,NULL)) return(False); - /* Read the broadcast address from the interface */ - { - struct in_addr ip0,ip1,ip2; - - ip0 = myip; - - if (!(got_bcast && got_nmask)) - { - get_broadcast(&ip0,&ip1,&ip2); - - if (!got_myip) - myip = ip0; - - if (!got_bcast) - bcast_ip = ip1; - - if (!got_nmask) - Netmask = ip2; - } - - DEBUG(1,("Using IP %s ",inet_ntoa(myip))); - DEBUG(1,("broadcast %s ",inet_ntoa(bcast_ip))); - DEBUG(1,("netmask %s\n",inet_ntoa(Netmask))); - - if (!ip_consistent(myip,bcast_ip,Netmask)) { - DEBUG(0,("WARNING: The IP address, broadcast and Netmask are not consistent\n")); - DEBUG(0,("You are likely to experience problems with this setup!\n")); - } - } - if (! *myname) { char *p; strcpy(myname,myhostname); @@ -462,7 +398,9 @@ static void usage(char *pname) int opt; extern FILE *dbf; extern char *optarg; + fstring group; + *group = 0; *host_file = 0; StartupTime = time(NULL); @@ -475,8 +413,6 @@ static void usage(char *pname) charset_initialise(); - ipzero = *interpret_addr2("0.0.0.0"); - #ifdef LMHOSTSFILE strcpy(host_file,LMHOSTSFILE); #endif @@ -491,9 +427,6 @@ static void usage(char *pname) signal(SIGHUP,SIGNAL_CAST sig_hup); - bcast_ip = ipzero; - myip = ipzero; - while ((opt = getopt (argc, argv, "s:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:")) != EOF) { switch (opt) @@ -505,29 +438,19 @@ static void usage(char *pname) strcpy(ServerComment,optarg); break; case 'G': - if (got_bcast && got_nmask) { - add_domain_entry(bcast_ip,Netmask,optarg, True); - } else { - DEBUG(0, ("Warning: option -G %s added before broadcast and netmask.\n", - optarg)); - DEBUG(0, ("Assuming default values: bcast %s netmask %s\n", - inet_ntoa(bcast_ip), inet_ntoa(Netmask))); /* (i hope) */ - } + strcpy(group,optarg); break; case 'H': strcpy(host_file,optarg); break; case 'I': - myip = *interpret_addr2(optarg); - got_myip = True; + iface_set_default(optarg,NULL,NULL); break; case 'B': - bcast_ip = *interpret_addr2(optarg); - got_bcast = True; + iface_set_default(NULL,optarg,NULL); break; case 'N': - Netmask = *interpret_addr2(optarg); - got_nmask = True; + iface_set_default(NULL,NULL,optarg); break; case 'n': strcpy(myname,optarg); @@ -568,6 +491,9 @@ static void usage(char *pname) if (!reload_services(False)) return(-1); + if (*group) + add_domain_entry(*iface_bcast(ipzero),*iface_nmask(ipzero),group, True); + if (!is_daemon && !is_a_socket(0)) { DEBUG(0,("standard input is not a socket, assuming -D option\n")); is_daemon = True; -- cgit From d160d93d8fad563400aa1e1274437df1fbd4ecbf Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 7 Jun 1996 03:34:22 +0000 Subject: - added predict.c, moving the routines from util.c - added iface_count() and iface_n_ip() routines so its easy to loop over the local interface list - made readsize a normal loadparm global - check for null w in add_domain_entry() - set the deathtime to time()-1 for doamin entries with servertype==0 This allows servers that are shutting down to be removed - add the 0x1c name at startup if we are a WINS server. Previously we added it only if we were a master - loop over interfaces in add_my_domains(), so people don't have to have a lmhosts file to get lp_workgroup() on all interfaces - set add to True for find_workgroupstruct() in nmbsync, and check for null return - remove some ugly "errno = EBADF" bits. they just confused things. (This used to be commit 88b191b48836eeb7937f25b37d0bdd4a2276e5a7) --- source3/nmbd/nmbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index b93ac2d580..cd2ebb0521 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -492,7 +492,7 @@ static void usage(char *pname) return(-1); if (*group) - add_domain_entry(*iface_bcast(ipzero),*iface_nmask(ipzero),group, True); + add_my_domains(group); if (!is_daemon && !is_a_socket(0)) { DEBUG(0,("standard input is not a socket, assuming -D option\n")); @@ -519,7 +519,7 @@ static void usage(char *pname) string_sub(ServerComment,"%h",myhostname); add_my_names(); - add_my_domains(); + add_my_domains(lp_workgroup()); DEBUG(3,("Checked names\n")); -- cgit From bfbca5ac7706d03056366b84b679faeab904ecae Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 8 Jun 1996 04:41:51 +0000 Subject: changes from Luke (This used to be commit 5269aa277c635cfda65a27fd1b2e587ac181e1c3) --- source3/nmbd/nmbd.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index cd2ebb0521..8ab9f528ef 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -55,6 +55,28 @@ time_t StartupTime =0; extern struct in_addr ipzero; + /**************************************************************************** +catch a sigterm +****************************************************************************/ +static int sig_term() +{ + BlockSignals(True); + + DEBUG(0,("Got SIGTERM: going down...\n")); + + dump_names(); + reload_services(True); + + /* remove all samba names, with wins server if necessary. */ + remove_my_names(); + + /* XXXX don't care if we never receive a response back... yet */ + /* XXXX other things: if we are a master browser, force an election? */ + + exit(0); +} + + /**************************************************************************** catch a sighup ****************************************************************************/ @@ -267,7 +289,7 @@ static void load_hosts_file(char *fname) if (group) { add_domain_entry(ipaddr, ipmask, name, True); } else { - add_netbios_entry(name,0x20,NB_ACTIVE,0,source,ipaddr,False); + add_netbios_entry(name,0x20,NB_ACTIVE,0,source,ipaddr); } } } @@ -426,8 +448,9 @@ static void usage(char *pname) fault_setup(fault_continue); signal(SIGHUP,SIGNAL_CAST sig_hup); + signal(SIGTERM,SIGNAL_CAST sig_term); - while ((opt = getopt (argc, argv, "s:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:")) != EOF) + while ((opt = getopt(argc, argv, "s:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:")) != EOF) { switch (opt) { -- cgit From 3f6fb647e707d1c919f7942135e3225b78fb5b6c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 8 Jun 1996 05:37:33 +0000 Subject: more changes from Luke (This used to be commit df44f10d7492679dabe3b998e7bacfebbc49ea5e) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 8ab9f528ef..414ad41b63 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -289,7 +289,7 @@ static void load_hosts_file(char *fname) if (group) { add_domain_entry(ipaddr, ipmask, name, True); } else { - add_netbios_entry(name,0x20,NB_ACTIVE,0,source,ipaddr); + add_netbios_entry(name,0x20,NB_ACTIVE,0,source,ipaddr,True); } } } -- cgit From e2eac352b1c6534031ad89a5565d3668833a2bf1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Jun 1996 03:38:08 +0000 Subject: updates from Luke to rename "domains" more accurately to "subnets" (This used to be commit 0a044c25abc363d8b202ff5d148259d624b92ea7) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 414ad41b63..87a545aa1c 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -287,7 +287,7 @@ static void load_hosts_file(char *fname) ipmask = *iface_nmask(ipaddr); if (group) { - add_domain_entry(ipaddr, ipmask, name, True); + add_subnet_entry(ipaddr, ipmask, name, True); } else { add_netbios_entry(name,0x20,NB_ACTIVE,0,source,ipaddr,True); } -- cgit From 7e3b4a1c0df1434eb3d02f93c736ce065f9898d8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Jun 1996 04:38:24 +0000 Subject: got rid of a lot of redundent header files as we now globally generate prototypes automatically using "make proto". This is much less prone to error than the old method of manually adding prototypes (This used to be commit b551dc98f7cc194a5fc2e67a4ebae7fd67a01bbc) --- source3/nmbd/nmbd.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 87a545aa1c..a20c4eb999 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -26,7 +26,6 @@ */ #include "includes.h" -#include "loadparm.h" extern int DEBUGLEVEL; -- cgit From ed2639ebe21dde49af816a96ec6ea1e40f76e768 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Sat, 29 Jun 1996 18:49:20 +0000 Subject: luke's first attempt at using cvs accidentally updated the Makefile updated the name database structure (again!). this time, there is one name database per local interface. there is also a pseudo-interface on ip 255.255.255.255. its purpose is to store WINS name entries. all the local interface name databases store SELF names only. the WINS name database stores non-special browser names. added wins.dat file: records WINS entries in ascii format. this is reloaded when nmbd restarts. added repeating code for response packets. timer is in seconds only at the moment. updated the response queue code to deal with samba registering with a WINS server a bit better (added more cases when a response isn't received). tidied up the response packet processing code and expire_response_queue() code. added cross references between response received and await-response expired code. added over-zealous code that checks all machines that register with samba as a WINS server (every 10 minutes i think): to see whether they are still alive or not (see rfc1001.txt) bug reported by terry@ren.pc.athabascau.ca: DNSFAILed names _stay_ as DNSFAIL, even though the machine may come back up and REGISTER. removed update_from_reg() function. it's not necessary, and it does too much. added code that announces on each local interface samba's ttl as zero and servertype as zero when nmbd is kill -TERMed first attempt at putting the first functionality of samba browsing back in (remote subnets should have samba appear in a workgroup specified through the lmhosts file) lots of other miscellaneous tidying up / chopping about. (This used to be commit 7e8c60cfe54060860e5ce20b1c3b8ec6aa5c54da) --- source3/nmbd/nmbd.c | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index a20c4eb999..1d541ea95f 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -69,6 +69,9 @@ static int sig_term() /* remove all samba names, with wins server if necessary. */ remove_my_names(); + /* announce all server entries as 0 time-to-live, 0 type */ + remove_my_servers(); + /* XXXX don't care if we never receive a response back... yet */ /* XXXX other things: if we are a master browser, force an election? */ @@ -204,6 +207,7 @@ BOOL reload_services(BOOL test) } load_interfaces(); + add_subnet_interfaces(); return(ret); } @@ -286,9 +290,13 @@ static void load_hosts_file(char *fname) ipmask = *iface_nmask(ipaddr); if (group) { - add_subnet_entry(ipaddr, ipmask, name, True); + add_subnet_entry(ipaddr, ipmask, name, True, True); } else { - add_netbios_entry(name,0x20,NB_ACTIVE,0,source,ipaddr,True); + struct subnet_record *d = find_subnet(ipaddr); + if (d) + { + add_netbios_entry(d,name,0x20,NB_ACTIVE,0,source,ipaddr,True,True); + } } } } @@ -316,16 +324,19 @@ static void process(void) announce_host(); #if 0 - /* what was this stuff supposed to do? It sent + /* XXXX what was this stuff supposed to do? It sent ANN_GetBackupListReq packets which I think should only be sent when trying to find out who to browse with */ + announce_backup(); #endif announce_master(); + query_refresh_names(); + expire_names_and_servers(); - expire_netbios_response_entries(t-10); + expire_netbios_response_entries(); refresh_my_names(t); write_browse_list(); @@ -514,7 +525,7 @@ static void usage(char *pname) return(-1); if (*group) - add_my_domains(group); + add_my_subnets(group); if (!is_daemon && !is_a_socket(0)) { DEBUG(0,("standard input is not a socket, assuming -D option\n")); @@ -535,16 +546,22 @@ static void usage(char *pname) DEBUG(3,("Loaded hosts file\n")); } + + if (!*ServerComment) strcpy(ServerComment,"Samba %v"); string_sub(ServerComment,"%v",VERSION); string_sub(ServerComment,"%h",myhostname); add_my_names(); - add_my_domains(lp_workgroup()); + add_my_subnets(lp_workgroup()); DEBUG(3,("Checked names\n")); + load_netbios_names(); + + DEBUG(3,("Loaded names\n")); + write_browse_list(); DEBUG(3,("Dumped names\n")); -- cgit From 7812ff08135318e74f5c286fe4773de8d1423969 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Thu, 4 Jul 1996 19:19:26 +0000 Subject: modified become_master() to a state-based system. becoming a master is now performed in stages: wait for each NetBIOS name to be successfully registered before proceeding to the next stage. tied implicit name registration and release (broadcast method) to the same piece of code as explicit method (via WINS server). created special_browser_name() function that checks __MSBROWSE__ name: this name is ignored by WINS servers apparently. fixed likely incompatibility between refresh_my_names() and add_my_names(). (netbios entries were unlikely to be refreshed). NOTE: none of these changes have been tested. at all. lkcl (This used to be commit 7719fb06524a66ce5e3f30f3152ddb1e200c97f3) --- source3/nmbd/nmbd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 1d541ea95f..187ef8e7b7 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -55,8 +55,8 @@ extern struct in_addr ipzero; /**************************************************************************** -catch a sigterm -****************************************************************************/ + catch a sigterm + ****************************************************************************/ static int sig_term() { BlockSignals(True); @@ -457,7 +457,7 @@ static void usage(char *pname) fault_setup(fault_continue); - signal(SIGHUP,SIGNAL_CAST sig_hup); + signal(SIGHUP ,SIGNAL_CAST sig_hup); signal(SIGTERM,SIGNAL_CAST sig_term); while ((opt = getopt(argc, argv, "s:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:")) != EOF) -- cgit From 9d59ce1d5715f64105643b01aea8b5b9cba8d5a2 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Tue, 9 Jul 1996 18:11:47 +0000 Subject: missed nmbd.c in previous update. did a make proto lkcl (This used to be commit 4ccc84989efc0875dfec95d38be4a8fe746c8795) --- source3/nmbd/nmbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 187ef8e7b7..40cb06aad4 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -63,16 +63,16 @@ static int sig_term() DEBUG(0,("Got SIGTERM: going down...\n")); + /* write out wins.dat file if samba is a WINS server */ dump_names(); - reload_services(True); /* remove all samba names, with wins server if necessary. */ remove_my_names(); /* announce all server entries as 0 time-to-live, 0 type */ + /* XXXX don't care if we never receive a response back... yet */ remove_my_servers(); - /* XXXX don't care if we never receive a response back... yet */ /* XXXX other things: if we are a master browser, force an election? */ exit(0); -- cgit From 25b30c08dce8c04b7b98c02ac1de61d7aa76798f Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Wed, 17 Jul 1996 18:33:36 +0000 Subject: lots of changes to nmbd lkcl (This used to be commit 45d3b2644733333c657c48a69719fec72881f7df) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 40cb06aad4..10b356d9b5 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -323,7 +323,7 @@ static void process(void) announce_host(); -#if 0 +#if 1 /* XXXX what was this stuff supposed to do? It sent ANN_GetBackupListReq packets which I think should only be sent when trying to find out who to browse with */ -- cgit From 3ffb30e8be5bcddca9d0489e1993085a4995c3af Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Thu, 1 Aug 1996 17:49:40 +0000 Subject: local_only NetServerEnum syncs can now be issued. bug spotted in nameservresp.c - arguments to test subnet the response is received on (same_net()) were the wrong way round (ccm@shentel.net) samba was adding WORKGROUP(1e) as a unique not a group name: fixed this bug in reply_name_status() and reply_name_query(): WINS entries weren't being looked up. name status reply adds local SELF entries to WINS SELF entries: some SELF entries are only added locally, while others are only added via WINS. name status needs to have both, combined. a sync will only occur when an ANN_LocalMasterAnnouncement is received, NOT an ANN_HostAnnouncement or an ANN_DomainAnnouncement. when samba is a member of a workgroup, it looks for (using a wins server) and announces to its domain master. NAME_QUERY_ANNOUNCE_HOST - yet another 'state' - has been created to do this: do the name query on the wins server and send the announce host to the answer to this query. jeremy @ vantive wrote the original code to do this, which used the name_query() function. i'm trying to avoid name_query: it times out and generally messes things up, but using queue_netbios_packet() and queue_netbios_pkt_wins() is... not intuitive? lkcl with help from jra (This used to be commit 6e932e4bae8b46e7ff4a55a75484bad78308336a) --- source3/nmbd/nmbd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 10b356d9b5..e2a4bdeb67 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -53,7 +53,6 @@ time_t StartupTime =0; extern struct in_addr ipzero; - /**************************************************************************** catch a sigterm ****************************************************************************/ @@ -90,6 +89,8 @@ static int sig_hup(void) dump_names(); reload_services(True); + set_samba_nb_type(); + BlockSignals(False); #ifndef DONT_REINSTALL_SIG signal(SIGHUP,SIGNAL_CAST sig_hup); @@ -524,6 +525,8 @@ static void usage(char *pname) if (!reload_services(False)) return(-1); + set_samba_nb_type(); + if (*group) add_my_subnets(group); -- cgit From 02b98a8965a60a7c3394835ff01074fc88ffbb89 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Fri, 9 Aug 1996 18:05:34 +0000 Subject: applying login updates from jim@oxfordcc.co.uk, sent in by lewis2@server.uwindsor.ca. rest of this patch to follow. bug in interface.c - uninitialised pointer. nmbd has 0x20 as well as 0x0 NetBIOS name when lmhosts entry is added. lkcl (This used to be commit 2b9475cc5fda4b272f19c4f168d3f00363c8042b) --- source3/nmbd/nmbd.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index e2a4bdeb67..5c3be920f5 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -296,6 +296,7 @@ static void load_hosts_file(char *fname) struct subnet_record *d = find_subnet(ipaddr); if (d) { + add_netbios_entry(d,name,0x00,NB_ACTIVE,0,source,ipaddr,True,True); add_netbios_entry(d,name,0x20,NB_ACTIVE,0,source,ipaddr,True,True); } } -- cgit From 47673b32ed4a907b380b70d5f4f366ba8be301d2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 15 Aug 1996 15:11:34 +0000 Subject: - added FAST_SHARE_MODES code - added some named pipe code from Jim (This used to be commit c94866e9e44ea1eb72da06bc65ef1c032ae8e0c9) --- source3/nmbd/nmbd.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 5c3be920f5..04751f6f56 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -58,7 +58,7 @@ extern struct in_addr ipzero; ****************************************************************************/ static int sig_term() { - BlockSignals(True); + BlockSignals(True,SIGTERM); DEBUG(0,("Got SIGTERM: going down...\n")); @@ -83,7 +83,7 @@ catch a sighup ****************************************************************************/ static int sig_hup(void) { - BlockSignals(True); + BlockSignals(True,SIGHUP); DEBUG(0,("Got SIGHUP (reload not implemented)\n")); dump_names(); @@ -91,7 +91,7 @@ static int sig_hup(void) set_samba_nb_type(); - BlockSignals(False); + BlockSignals(False,SIGHUP); #ifndef DONT_REINSTALL_SIG signal(SIGHUP,SIGNAL_CAST sig_hup); #endif @@ -103,12 +103,12 @@ catch a sigpipe ****************************************************************************/ static int sig_pipe(void) { - BlockSignals(True); + BlockSignals(True,SIGPIPE); DEBUG(0,("Got SIGPIPE\n")); if (!is_daemon) exit(1); - BlockSignals(False); + BlockSignals(False,SIGPIPE); return(0); } -- cgit From f63d4c830aa88d20ababe4c3543bff7becc3a506 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 16 Aug 1996 13:03:26 +0000 Subject: - added the "remote announce" option - made the lp_string() code able to handle any length string - got rid of the obsolete lmhosts code, instead users should use "interfaces" and "remote announce". lmhosts now is just used as a IP to netbios name map - cleanup the inet_address() code (This used to be commit be2b67940302b2e63890cb865fe3948c2206ea91) --- source3/nmbd/nmbd.c | 120 ++++++++++++++++++++++------------------------------ 1 file changed, 51 insertions(+), 69 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 04751f6f56..1ee11edbcf 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -229,80 +229,60 @@ static void load_hosts_file(char *fname) while (!feof(f)) { + pstring ip,name,flags,extra; + struct subnet_record *d; + char *ptr; + int count = 0; + struct in_addr ipaddr; + enum name_source source = LMHOSTS; + if (!fgets_slash(line,sizeof(pstring),f)) continue; if (*line == '#') continue; - { - BOOL group=False; - - pstring ip,name,mask,flags,extra; - - char *ptr; - int count = 0; - struct in_addr ipaddr; - struct in_addr ipmask; - enum name_source source = LMHOSTS; - - strcpy(ip,""); - strcpy(name,""); - strcpy(mask,""); - strcpy(flags,""); - strcpy(extra,""); - - ptr = line; - - if (next_token(&ptr,ip ,NULL)) ++count; - if (next_token(&ptr,name ,NULL)) ++count; - if (next_token(&ptr,mask ,NULL)) ++count; - if (next_token(&ptr,flags,NULL)) ++count; - if (next_token(&ptr,extra,NULL)) ++count; - - if (count <= 0) continue; - - if (count > 0 && count < 2) { - DEBUG(0,("Ill formed hosts line [%s]\n",line)); - continue; - } - - /* work out if we need to shuffle the tokens along due to the - optional subnet mask argument */ - - if (strchr(mask, 'G') || strchr(mask, 'S') || strchr(mask, 'M')) { - strcpy(flags, mask ); - /* default action for no subnet mask */ - strcpy(mask, ""); - } - - DEBUG(4, ("lmhost entry: %s %s %s %s\n", ip, name, mask, flags)); - - if (strchr(flags,'G') || strchr(flags,'S')) - group = True; - - if (strchr(flags,'M') && !group) { - source = SELF; - strcpy(myname,name); - } - - ipaddr = *interpret_addr2(ip); - if (*mask) - ipmask = *interpret_addr2(mask); - else - ipmask = *iface_nmask(ipaddr); - - if (group) { - add_subnet_entry(ipaddr, ipmask, name, True, True); - } else { - struct subnet_record *d = find_subnet(ipaddr); - if (d) - { - add_netbios_entry(d,name,0x00,NB_ACTIVE,0,source,ipaddr,True,True); - add_netbios_entry(d,name,0x20,NB_ACTIVE,0,source,ipaddr,True,True); + strcpy(ip,""); + strcpy(name,""); + strcpy(flags,""); + + ptr = line; + + if (next_token(&ptr,ip ,NULL)) ++count; + if (next_token(&ptr,name ,NULL)) ++count; + if (next_token(&ptr,flags,NULL)) ++count; + if (next_token(&ptr,extra,NULL)) ++count; + + if (count <= 0) continue; + + if (count > 0 && count < 2) { + DEBUG(0,("Ill formed hosts line [%s]\n",line)); + continue; } - } + + if (count >= 4) { + DEBUG(0,("too many columns in %s (obsolete syntax)\n",fname)); + continue; + } + + DEBUG(4, ("lmhost entry: %s %s %s\n", ip, name, flags)); + + if (strchr(flags,'G') || strchr(flags,'S')) { + DEBUG(0,("group flag in %s ignored (obsolete)\n",fname)); + continue; } + + if (strchr(flags,'M')) { + source = SELF; + strcpy(myname,name); + } + + ipaddr = *interpret_addr2(ip); + d = find_subnet(ipaddr); + if (d) { + add_netbios_entry(d,name,0x00,NB_ACTIVE,0,source,ipaddr,True,True); + add_netbios_entry(d,name,0x20,NB_ACTIVE,0,source,ipaddr,True,True); + } } - + fclose(f); } @@ -325,7 +305,7 @@ static void process(void) announce_host(); -#if 1 +#if 0 /* XXXX what was this stuff supposed to do? It sent ANN_GetBackupListReq packets which I think should only be sent when trying to find out who to browse with */ @@ -335,6 +315,8 @@ static void process(void) announce_master(); + announce_remote(); + query_refresh_names(); expire_names_and_servers(); @@ -468,7 +450,7 @@ static void usage(char *pname) { case 's': strcpy(servicesf,optarg); - break; + break; case 'C': strcpy(ServerComment,optarg); break; -- cgit From 28177ca73bdbe3f8fb17a608db3df1a39e0e37a4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 17 Aug 1996 11:37:44 +0000 Subject: - added support for Amiga-unix (based on BSD I think) - changed the order of PROGS and SPROGS in Makefile (SPROGS first) - another 64 bit cleanup (for INADDR_NONE) - added paranoia code in DirCacheAdd() to detect looping - fixed important DirCache flush bug - rewrote the NetServerEnum code after I found it could return servers from multiple workgroups at once, and this could cause browsing havoc. Now a null workgroup query is equivalent to a query for the servers primary workgroup - got rid of my_workgroup() - got rid of "workgroup = *" comment in Makefile. We no longer support a workgroup of *, users must set the workgroup explicitly - the wins.dat file was being stored in a different format to what it was being loaded in - this could cause havoc. fixed. - uppercase our netbios name and the workgroup name at startup - if accept fails in main loop when running as a daemon then continue, don't just exit! - don't use ./ on smbclient in smbtar - better code to detect if a process exists (This used to be commit ec3d53963064b50ff33e8eff47812aac82f164ba) --- source3/nmbd/nmbd.c | 31 ++++++++++++------------------- 1 file changed, 12 insertions(+), 19 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 1ee11edbcf..a4b303923d 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -376,6 +376,7 @@ static BOOL init_structs() strcpy(myname,myhostname); p = strchr(myname,'.'); if (p) *p = 0; + strupper(myname); } return True; @@ -388,19 +389,14 @@ static void usage(char *pname) { DEBUG(0,("Incorrect program usage - is the command line correct?\n")); - printf("Usage: %s [-n name] [-B bcast address] [-D] [-p port] [-d debuglevel] [-l log basename]\n",pname); + printf("Usage: %s [-n name] [-D] [-p port] [-d debuglevel] [-l log basename]\n",pname); printf("Version %s\n",VERSION); printf("\t-D become a daemon\n"); printf("\t-p port listen on the specified port\n"); printf("\t-d debuglevel set the debuglevel\n"); printf("\t-l log basename. Basename for log/debug files\n"); printf("\t-n netbiosname. the netbios name to advertise for this host\n"); - printf("\t-B broadcast address the address to use for broadcasts\n"); - printf("\t-N netmask the netmask to use for subnet determination\n"); printf("\t-H hosts file load a netbios hosts file\n"); - printf("\t-G group name add a group name to be part of\n"); - printf("\t-I ip-address override the IP address\n"); - printf("\t-C comment sets the machine comment that appears in browse lists\n"); printf("\n"); } @@ -416,7 +412,6 @@ static void usage(char *pname) extern char *optarg; fstring group; - *group = 0; *host_file = 0; StartupTime = time(NULL); @@ -451,26 +446,19 @@ static void usage(char *pname) case 's': strcpy(servicesf,optarg); break; + case 'N': + case 'B': + case 'I': case 'C': - strcpy(ServerComment,optarg); - break; case 'G': - strcpy(group,optarg); + DEBUG(0,("Obsolete option '%c' used\n",opt)); break; case 'H': strcpy(host_file,optarg); break; - case 'I': - iface_set_default(optarg,NULL,NULL); - break; - case 'B': - iface_set_default(NULL,optarg,NULL); - break; - case 'N': - iface_set_default(NULL,NULL,optarg); - break; case 'n': strcpy(myname,optarg); + strupper(myname); break; case 'l': sprintf(debugf,"%s.nmb",optarg); @@ -540,6 +528,11 @@ static void usage(char *pname) string_sub(ServerComment,"%h",myhostname); add_my_names(); + + if (strequal(lp_workgroup(),"*")) { + DEBUG(0,("ERROR: a workgroup name of * is no longer supported\n")); + } + add_my_subnets(lp_workgroup()); DEBUG(3,("Checked names\n")); -- cgit From 1aedda6160e0748d82a68bcd64f661ea1b80af9d Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Sat, 17 Aug 1996 15:14:24 +0000 Subject: - fixed wins.dat reloading (it wasn't happening!) - made nb_flags an unsigned 16 bit int in nameserv.h - nmbd was calling add_my_subnets() with an uninitialised parameter group. removed it. lkcl (This used to be commit 3d55e541569e7ab887bddc284bddcafdf86c4d22) --- source3/nmbd/nmbd.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index a4b303923d..82ea9550f3 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -410,7 +410,6 @@ static void usage(char *pname) int opt; extern FILE *dbf; extern char *optarg; - fstring group; *host_file = 0; @@ -498,9 +497,6 @@ static void usage(char *pname) set_samba_nb_type(); - if (*group) - add_my_subnets(group); - if (!is_daemon && !is_a_socket(0)) { DEBUG(0,("standard input is not a socket, assuming -D option\n")); is_daemon = True; -- cgit From 0c33046a0aa0461a5e932dd7b0b6e38ab9708867 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 19 Aug 1996 11:17:29 +0000 Subject: - added "netbios name" option in smb.conf to make controlling the name that samba uses possible - added "socket address" option to allow virtual SMB servers (on systems with IP aliasing line Linux) - disabled FAST_SHARE_MODES by default in Linux as older Linux boxes can't do shared writeable mappings. We really need autoconf ... - added new option types in loadparm so a string type can be specified ot be uppercase only, this is used for the workgroup and netbios name options - auto-create the lock directory if it doesn't exist in shared mem startup - get rid of announce_backup() - change a few comments in nmbd code - rewrote the chaining code completely. Hopefully it will handle any depth chains now. - added LPRng support (This used to be commit e9eac6cd49c352349580ddb13d720cb201aecc48) --- source3/nmbd/nmbd.c | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 82ea9550f3..2621be87ee 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -305,14 +305,6 @@ static void process(void) announce_host(); -#if 0 - /* XXXX what was this stuff supposed to do? It sent - ANN_GetBackupListReq packets which I think should only be - sent when trying to find out who to browse with */ - - announce_backup(); -#endif - announce_master(); announce_remote(); @@ -344,11 +336,11 @@ static BOOL open_sockets(BOOL isdaemon, int port) } if (isdaemon) - ClientNMB = open_socket_in(SOCK_DGRAM, port,0); + ClientNMB = open_socket_in(SOCK_DGRAM, port,0,interpret_addr(lp_socket_address())); else ClientNMB = 0; - ClientDGRAM = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3); + ClientDGRAM = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3,interpret_addr(lp_socket_address())); if (ClientNMB == -1) return(False); @@ -376,8 +368,8 @@ static BOOL init_structs() strcpy(myname,myhostname); p = strchr(myname,'.'); if (p) *p = 0; - strupper(myname); } + strupper(myname); return True; } @@ -490,11 +482,11 @@ static void usage(char *pname) DEBUG(1,("%s netbios nameserver version %s started\n",timestring(),VERSION)); DEBUG(1,("Copyright Andrew Tridgell 1994\n")); - init_structs(); - if (!reload_services(False)) return(-1); + init_structs(); + set_samba_nb_type(); if (!is_daemon && !is_a_socket(0)) { -- cgit From 1073bd65414d1e436e833c2e32bed129c72e1910 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 20 Aug 1996 16:09:41 +0000 Subject: - removed ServerComment and instead set the comment string in nmbd using the "server string" option. This replaces the -C option to nmbd (This used to be commit 9e0fab2ee6c89155e6ba6b2401a25de37cb89333) --- source3/nmbd/nmbd.c | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 2621be87ee..097e4f794a 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -44,9 +44,6 @@ extern pstring myname; /* are we running as a daemon ? */ static BOOL is_daemon = False; -/* machine comment for host announcements */ -pstring ServerComment=""; - /* what server type are we currently */ time_t StartupTime =0; @@ -508,13 +505,6 @@ static void usage(char *pname) DEBUG(3,("Loaded hosts file\n")); } - - - if (!*ServerComment) - strcpy(ServerComment,"Samba %v"); - string_sub(ServerComment,"%v",VERSION); - string_sub(ServerComment,"%h",myhostname); - add_my_names(); if (strequal(lp_workgroup(),"*")) { -- cgit From 9155889092ac9ff476d950a0c1b624ebad3cdad6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 22 Aug 1996 06:32:03 +0000 Subject: - add timeouts to connect() for password server connections. This makes multiple password servers practical. (This used to be commit 5c3e8326cc45d3cbd076475e445ce461a2bf7560) --- source3/nmbd/nmbd.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 097e4f794a..5b3fd19491 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -357,17 +357,22 @@ static BOOL open_sockets(BOOL isdaemon, int port) ****************************************************************************/ static BOOL init_structs() { - if (!get_myname(myhostname,NULL)) - return(False); + extern fstring local_machine; + char *p; if (! *myname) { - char *p; strcpy(myname,myhostname); p = strchr(myname,'.'); if (p) *p = 0; } strupper(myname); + strcpy(local_machine,myname); + trim_string(local_machine," "," "); + p = strchr(local_machine,' '); + if (p) *p = 0; + strlower(local_machine); + return True; } @@ -479,11 +484,15 @@ static void usage(char *pname) DEBUG(1,("%s netbios nameserver version %s started\n",timestring(),VERSION)); DEBUG(1,("Copyright Andrew Tridgell 1994\n")); + get_myname(myhostname,NULL); + if (!reload_services(False)) return(-1); init_structs(); + reload_services(True); + set_samba_nb_type(); if (!is_daemon && !is_a_socket(0)) { -- cgit From 5945be9718b8ea56c8dde99729c0ec0e56080fee Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Fri, 23 Aug 1996 10:17:30 +0000 Subject: - fixed bugs in nmb response packet checking. - added multiple workgroup code - samba can register under different (unique) NetBIOS aliases, one per workgroup it joins. lkcl (This used to be commit f24e341e7e4d8726b98d3a0f83b24f61817fe536) --- source3/nmbd/nmbd.c | 142 ++++++++++++++++++++++++++++------------------------ 1 file changed, 76 insertions(+), 66 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 5b3fd19491..4a3d139fda 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -23,6 +23,10 @@ 14 jan 96: lkcl@pires.co.uk added multiple workgroup domain master support + + 30 July 96: David.Chappell@mail.trincoll.edu + Expanded multiple workgroup domain master browser support. + */ #include "includes.h" @@ -165,10 +169,10 @@ static void expire_names_and_servers(void) time_t t = time(NULL); if (!lastrun) lastrun = t; - if (t < lastrun + 5) return; + if (t < lastrun + 15) return; /* give samba time to check its names */ lastrun = t; - expire_names(t); + check_expire_names(t); /* this checks samba's NetBIOS names */ expire_servers(t); } @@ -187,10 +191,10 @@ BOOL reload_services(BOOL test) pstring fname; strcpy(fname,lp_configfile()); if (file_exist(fname,NULL) && !strcsequal(fname,servicesf)) - { - strcpy(servicesf,fname); - test = False; - } + { + strcpy(servicesf,fname); + test = False; + } } if (test && !lp_file_list_changed()) @@ -251,32 +255,32 @@ static void load_hosts_file(char *fname) if (count <= 0) continue; if (count > 0 && count < 2) { - DEBUG(0,("Ill formed hosts line [%s]\n",line)); - continue; + DEBUG(0,("Ill formed hosts line [%s]\n",line)); + continue; } if (count >= 4) { - DEBUG(0,("too many columns in %s (obsolete syntax)\n",fname)); - continue; + DEBUG(0,("too many columns in %s (obsolete syntax)\n",fname)); + continue; } DEBUG(4, ("lmhost entry: %s %s %s\n", ip, name, flags)); if (strchr(flags,'G') || strchr(flags,'S')) { - DEBUG(0,("group flag in %s ignored (obsolete)\n",fname)); - continue; + DEBUG(0,("group flag in %s ignored (obsolete)\n",fname)); + continue; } if (strchr(flags,'M')) { - source = SELF; - strcpy(myname,name); + source = SELF; + strcpy(myname,name); } ipaddr = *interpret_addr2(ip); d = find_subnet(ipaddr); if (d) { - add_netbios_entry(d,name,0x00,NB_ACTIVE,0,source,ipaddr,True,True); - add_netbios_entry(d,name,0x20,NB_ACTIVE,0,source,ipaddr,True,True); + add_netbios_entry(d,name,0x00,NB_ACTIVE,0,source,ipaddr,True,True); + add_netbios_entry(d,name,0x20,NB_ACTIVE,0,source,ipaddr,True,True); } } @@ -292,8 +296,7 @@ static void process(void) BOOL run_election; while (True) - { - time_t t = time(NULL); + { run_election = check_elections(); listen_for_packets(run_election); @@ -310,12 +313,11 @@ static void process(void) expire_names_and_servers(); expire_netbios_response_entries(); - refresh_my_names(t); write_browse_list(); do_browser_lists(); check_master_browser(); - } + } } @@ -435,50 +437,50 @@ static void usage(char *pname) while ((opt = getopt(argc, argv, "s:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:")) != EOF) { switch (opt) - { - case 's': - strcpy(servicesf,optarg); - break; - case 'N': - case 'B': - case 'I': - case 'C': - case 'G': - DEBUG(0,("Obsolete option '%c' used\n",opt)); - break; - case 'H': - strcpy(host_file,optarg); - break; - case 'n': - strcpy(myname,optarg); - strupper(myname); - break; - case 'l': - sprintf(debugf,"%s.nmb",optarg); - break; - case 'i': - strcpy(scope,optarg); - strupper(scope); - break; - case 'D': - is_daemon = True; - break; - case 'd': - DEBUGLEVEL = atoi(optarg); - break; - case 'p': - port = atoi(optarg); - break; - case 'h': - usage(argv[0]); - exit(0); - break; - default: - if (!is_a_socket(0)) { - usage(argv[0]); - } - break; - } + { + case 's': + strcpy(servicesf,optarg); + break; + case 'N': + case 'B': + case 'I': + case 'C': + case 'G': + DEBUG(0,("Obsolete option '%c' used\n",opt)); + break; + case 'H': + strcpy(host_file,optarg); + break; + case 'n': + strcpy(myname,optarg); + strupper(myname); + break; + case 'l': + sprintf(debugf,"%s.nmb",optarg); + break; + case 'i': + strcpy(scope,optarg); + strupper(scope); + break; + case 'D': + is_daemon = True; + break; + case 'd': + DEBUGLEVEL = atoi(optarg); + break; + case 'p': + port = atoi(optarg); + break; + case 'h': + usage(argv[0]); + exit(0); + break; + default: + if (!is_a_socket(0)) { + usage(argv[0]); + } + break; + } } DEBUG(1,("%s netbios nameserver version %s started\n",timestring(),VERSION)); @@ -487,10 +489,18 @@ static void usage(char *pname) get_myname(myhostname,NULL); if (!reload_services(False)) - return(-1); - + return(-1); + init_structs(); + /* reads the smbbrowse.conf file. this is an alias mapping between + workgroups and samba NetBIOS aliases. samba can therefore be + a member of multiple workgroups, a local master browser of + multiple workgroups, or a domain master browser of multiple + workgroups, via each NetBIOS name alias. the aliases MUST + be unique for this to work. */ + read_smbbrowse_conf(myname); + reload_services(True); set_samba_nb_type(); -- cgit From 9ad5a3fe36ac2b32bcb7a50c608ec586629f2125 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Sat, 24 Aug 1996 01:41:46 +0000 Subject: removed all of lukes recent changes. I need to do a p2 release but can't test the multi group changes. I also found that some of lukes changes wiped out some recent bug fixes. Is your CVS tree ok luke? (This used to be commit 8b7fe224bce64803d55ae279fa61ef3ebbbb0241) --- source3/nmbd/nmbd.c | 142 ++++++++++++++++++++++++---------------------------- 1 file changed, 66 insertions(+), 76 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 4a3d139fda..5b3fd19491 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -23,10 +23,6 @@ 14 jan 96: lkcl@pires.co.uk added multiple workgroup domain master support - - 30 July 96: David.Chappell@mail.trincoll.edu - Expanded multiple workgroup domain master browser support. - */ #include "includes.h" @@ -169,10 +165,10 @@ static void expire_names_and_servers(void) time_t t = time(NULL); if (!lastrun) lastrun = t; - if (t < lastrun + 15) return; /* give samba time to check its names */ + if (t < lastrun + 5) return; lastrun = t; - check_expire_names(t); /* this checks samba's NetBIOS names */ + expire_names(t); expire_servers(t); } @@ -191,10 +187,10 @@ BOOL reload_services(BOOL test) pstring fname; strcpy(fname,lp_configfile()); if (file_exist(fname,NULL) && !strcsequal(fname,servicesf)) - { - strcpy(servicesf,fname); - test = False; - } + { + strcpy(servicesf,fname); + test = False; + } } if (test && !lp_file_list_changed()) @@ -255,32 +251,32 @@ static void load_hosts_file(char *fname) if (count <= 0) continue; if (count > 0 && count < 2) { - DEBUG(0,("Ill formed hosts line [%s]\n",line)); - continue; + DEBUG(0,("Ill formed hosts line [%s]\n",line)); + continue; } if (count >= 4) { - DEBUG(0,("too many columns in %s (obsolete syntax)\n",fname)); - continue; + DEBUG(0,("too many columns in %s (obsolete syntax)\n",fname)); + continue; } DEBUG(4, ("lmhost entry: %s %s %s\n", ip, name, flags)); if (strchr(flags,'G') || strchr(flags,'S')) { - DEBUG(0,("group flag in %s ignored (obsolete)\n",fname)); - continue; + DEBUG(0,("group flag in %s ignored (obsolete)\n",fname)); + continue; } if (strchr(flags,'M')) { - source = SELF; - strcpy(myname,name); + source = SELF; + strcpy(myname,name); } ipaddr = *interpret_addr2(ip); d = find_subnet(ipaddr); if (d) { - add_netbios_entry(d,name,0x00,NB_ACTIVE,0,source,ipaddr,True,True); - add_netbios_entry(d,name,0x20,NB_ACTIVE,0,source,ipaddr,True,True); + add_netbios_entry(d,name,0x00,NB_ACTIVE,0,source,ipaddr,True,True); + add_netbios_entry(d,name,0x20,NB_ACTIVE,0,source,ipaddr,True,True); } } @@ -296,7 +292,8 @@ static void process(void) BOOL run_election; while (True) - { + { + time_t t = time(NULL); run_election = check_elections(); listen_for_packets(run_election); @@ -313,11 +310,12 @@ static void process(void) expire_names_and_servers(); expire_netbios_response_entries(); + refresh_my_names(t); write_browse_list(); do_browser_lists(); check_master_browser(); - } + } } @@ -437,50 +435,50 @@ static void usage(char *pname) while ((opt = getopt(argc, argv, "s:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:")) != EOF) { switch (opt) - { - case 's': - strcpy(servicesf,optarg); - break; - case 'N': - case 'B': - case 'I': - case 'C': - case 'G': - DEBUG(0,("Obsolete option '%c' used\n",opt)); - break; - case 'H': - strcpy(host_file,optarg); - break; - case 'n': - strcpy(myname,optarg); - strupper(myname); - break; - case 'l': - sprintf(debugf,"%s.nmb",optarg); - break; - case 'i': - strcpy(scope,optarg); - strupper(scope); - break; - case 'D': - is_daemon = True; - break; - case 'd': - DEBUGLEVEL = atoi(optarg); - break; - case 'p': - port = atoi(optarg); - break; - case 'h': - usage(argv[0]); - exit(0); - break; - default: - if (!is_a_socket(0)) { - usage(argv[0]); - } - break; - } + { + case 's': + strcpy(servicesf,optarg); + break; + case 'N': + case 'B': + case 'I': + case 'C': + case 'G': + DEBUG(0,("Obsolete option '%c' used\n",opt)); + break; + case 'H': + strcpy(host_file,optarg); + break; + case 'n': + strcpy(myname,optarg); + strupper(myname); + break; + case 'l': + sprintf(debugf,"%s.nmb",optarg); + break; + case 'i': + strcpy(scope,optarg); + strupper(scope); + break; + case 'D': + is_daemon = True; + break; + case 'd': + DEBUGLEVEL = atoi(optarg); + break; + case 'p': + port = atoi(optarg); + break; + case 'h': + usage(argv[0]); + exit(0); + break; + default: + if (!is_a_socket(0)) { + usage(argv[0]); + } + break; + } } DEBUG(1,("%s netbios nameserver version %s started\n",timestring(),VERSION)); @@ -489,18 +487,10 @@ static void usage(char *pname) get_myname(myhostname,NULL); if (!reload_services(False)) - return(-1); - + return(-1); + init_structs(); - /* reads the smbbrowse.conf file. this is an alias mapping between - workgroups and samba NetBIOS aliases. samba can therefore be - a member of multiple workgroups, a local master browser of - multiple workgroups, or a domain master browser of multiple - workgroups, via each NetBIOS name alias. the aliases MUST - be unique for this to work. */ - read_smbbrowse_conf(myname); - reload_services(True); set_samba_nb_type(); -- cgit From 5a2f52b79e28530c454cb488a44588147640f061 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 2 Oct 1996 14:09:22 +0000 Subject: - a huge pile of changes from Luke which implement the browse.conf stuff and also fix a pile of nmbd bugs. Unfortunately I found it very hard to disentangle the new features from the bug fixes so I am putting in the new code. I hope this is the last big pile of changes to the 1.9.16 series! (This used to be commit 20b6203dac4bbb43e4e7bea0b214496d76d679d9) --- source3/nmbd/nmbd.c | 144 ++++++++++++++++++++++++++++------------------------ 1 file changed, 77 insertions(+), 67 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 5b3fd19491..54f4254d51 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -23,6 +23,10 @@ 14 jan 96: lkcl@pires.co.uk added multiple workgroup domain master support + + 30 July 96: David.Chappell@mail.trincoll.edu + Expanded multiple workgroup domain master browser support. + */ #include "includes.h" @@ -165,10 +169,10 @@ static void expire_names_and_servers(void) time_t t = time(NULL); if (!lastrun) lastrun = t; - if (t < lastrun + 5) return; + if (t < lastrun + 15) return; /* give samba time to check its names */ lastrun = t; - expire_names(t); + check_expire_names(t); /* this checks samba's NetBIOS names */ expire_servers(t); } @@ -187,10 +191,10 @@ BOOL reload_services(BOOL test) pstring fname; strcpy(fname,lp_configfile()); if (file_exist(fname,NULL) && !strcsequal(fname,servicesf)) - { - strcpy(servicesf,fname); - test = False; - } + { + strcpy(servicesf,fname); + test = False; + } } if (test && !lp_file_list_changed()) @@ -251,32 +255,32 @@ static void load_hosts_file(char *fname) if (count <= 0) continue; if (count > 0 && count < 2) { - DEBUG(0,("Ill formed hosts line [%s]\n",line)); - continue; + DEBUG(0,("Ill formed hosts line [%s]\n",line)); + continue; } if (count >= 4) { - DEBUG(0,("too many columns in %s (obsolete syntax)\n",fname)); - continue; + DEBUG(0,("too many columns in %s (obsolete syntax)\n",fname)); + continue; } DEBUG(4, ("lmhost entry: %s %s %s\n", ip, name, flags)); if (strchr(flags,'G') || strchr(flags,'S')) { - DEBUG(0,("group flag in %s ignored (obsolete)\n",fname)); - continue; + DEBUG(0,("group flag in %s ignored (obsolete)\n",fname)); + continue; } if (strchr(flags,'M')) { - source = SELF; - strcpy(myname,name); + source = SELF; + strcpy(myname,name); } ipaddr = *interpret_addr2(ip); d = find_subnet(ipaddr); if (d) { - add_netbios_entry(d,name,0x00,NB_ACTIVE,0,source,ipaddr,True,True); - add_netbios_entry(d,name,0x20,NB_ACTIVE,0,source,ipaddr,True,True); + add_netbios_entry(d,name,0x00,NB_ACTIVE,0,source,ipaddr,True,True); + add_netbios_entry(d,name,0x20,NB_ACTIVE,0,source,ipaddr,True,True); } } @@ -292,8 +296,7 @@ static void process(void) BOOL run_election; while (True) - { - time_t t = time(NULL); + { run_election = check_elections(); listen_for_packets(run_election); @@ -310,12 +313,11 @@ static void process(void) expire_names_and_servers(); expire_netbios_response_entries(); - refresh_my_names(t); write_browse_list(); do_browser_lists(); check_master_browser(); - } + } } @@ -435,50 +437,50 @@ static void usage(char *pname) while ((opt = getopt(argc, argv, "s:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:")) != EOF) { switch (opt) - { - case 's': - strcpy(servicesf,optarg); - break; - case 'N': - case 'B': - case 'I': - case 'C': - case 'G': - DEBUG(0,("Obsolete option '%c' used\n",opt)); - break; - case 'H': - strcpy(host_file,optarg); - break; - case 'n': - strcpy(myname,optarg); - strupper(myname); - break; - case 'l': - sprintf(debugf,"%s.nmb",optarg); - break; - case 'i': - strcpy(scope,optarg); - strupper(scope); - break; - case 'D': - is_daemon = True; - break; - case 'd': - DEBUGLEVEL = atoi(optarg); - break; - case 'p': - port = atoi(optarg); - break; - case 'h': - usage(argv[0]); - exit(0); - break; - default: - if (!is_a_socket(0)) { - usage(argv[0]); - } - break; - } + { + case 's': + strcpy(servicesf,optarg); + break; + case 'N': + case 'B': + case 'I': + case 'C': + case 'G': + DEBUG(0,("Obsolete option '%c' used\n",opt)); + break; + case 'H': + strcpy(host_file,optarg); + break; + case 'n': + strcpy(myname,optarg); + strupper(myname); + break; + case 'l': + sprintf(debugf,"%s.nmb",optarg); + break; + case 'i': + strcpy(scope,optarg); + strupper(scope); + break; + case 'D': + is_daemon = True; + break; + case 'd': + DEBUGLEVEL = atoi(optarg); + break; + case 'p': + port = atoi(optarg); + break; + case 'h': + usage(argv[0]); + exit(0); + break; + default: + if (!is_a_socket(0)) { + usage(argv[0]); + } + break; + } } DEBUG(1,("%s netbios nameserver version %s started\n",timestring(),VERSION)); @@ -487,10 +489,18 @@ static void usage(char *pname) get_myname(myhostname,NULL); if (!reload_services(False)) - return(-1); - + return(-1); + init_structs(); + /* reads the smbbrowse.conf file. this is an alias mapping between + workgroups and samba NetBIOS aliases. samba can therefore be + a member of multiple workgroups, a local master browser of + multiple workgroups, or a domain master browser of multiple + workgroups, via each NetBIOS name alias. the aliases MUST + be unique for this to work. */ + read_smbbrowse_conf(myname); + reload_services(True); set_samba_nb_type(); @@ -520,7 +530,7 @@ static void usage(char *pname) DEBUG(0,("ERROR: a workgroup name of * is no longer supported\n")); } - add_my_subnets(lp_workgroup()); + add_workgroups_to_subnets(); DEBUG(3,("Checked names\n")); -- cgit From afd08462ad5ff6b3c4bf621e39c55853a608175e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 2 Oct 1996 15:41:30 +0000 Subject: backout all the changes to nmbd. The 1.9.16 tree is now back to 1.9.16p2 as far as nmbd is concerned apart from a small change that fixes the announce type in two places. (This used to be commit 45e66a69d320024877c8b13f12b21bf895e04410) --- source3/nmbd/nmbd.c | 144 ++++++++++++++++++++++++---------------------------- 1 file changed, 67 insertions(+), 77 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 54f4254d51..5b3fd19491 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -23,10 +23,6 @@ 14 jan 96: lkcl@pires.co.uk added multiple workgroup domain master support - - 30 July 96: David.Chappell@mail.trincoll.edu - Expanded multiple workgroup domain master browser support. - */ #include "includes.h" @@ -169,10 +165,10 @@ static void expire_names_and_servers(void) time_t t = time(NULL); if (!lastrun) lastrun = t; - if (t < lastrun + 15) return; /* give samba time to check its names */ + if (t < lastrun + 5) return; lastrun = t; - check_expire_names(t); /* this checks samba's NetBIOS names */ + expire_names(t); expire_servers(t); } @@ -191,10 +187,10 @@ BOOL reload_services(BOOL test) pstring fname; strcpy(fname,lp_configfile()); if (file_exist(fname,NULL) && !strcsequal(fname,servicesf)) - { - strcpy(servicesf,fname); - test = False; - } + { + strcpy(servicesf,fname); + test = False; + } } if (test && !lp_file_list_changed()) @@ -255,32 +251,32 @@ static void load_hosts_file(char *fname) if (count <= 0) continue; if (count > 0 && count < 2) { - DEBUG(0,("Ill formed hosts line [%s]\n",line)); - continue; + DEBUG(0,("Ill formed hosts line [%s]\n",line)); + continue; } if (count >= 4) { - DEBUG(0,("too many columns in %s (obsolete syntax)\n",fname)); - continue; + DEBUG(0,("too many columns in %s (obsolete syntax)\n",fname)); + continue; } DEBUG(4, ("lmhost entry: %s %s %s\n", ip, name, flags)); if (strchr(flags,'G') || strchr(flags,'S')) { - DEBUG(0,("group flag in %s ignored (obsolete)\n",fname)); - continue; + DEBUG(0,("group flag in %s ignored (obsolete)\n",fname)); + continue; } if (strchr(flags,'M')) { - source = SELF; - strcpy(myname,name); + source = SELF; + strcpy(myname,name); } ipaddr = *interpret_addr2(ip); d = find_subnet(ipaddr); if (d) { - add_netbios_entry(d,name,0x00,NB_ACTIVE,0,source,ipaddr,True,True); - add_netbios_entry(d,name,0x20,NB_ACTIVE,0,source,ipaddr,True,True); + add_netbios_entry(d,name,0x00,NB_ACTIVE,0,source,ipaddr,True,True); + add_netbios_entry(d,name,0x20,NB_ACTIVE,0,source,ipaddr,True,True); } } @@ -296,7 +292,8 @@ static void process(void) BOOL run_election; while (True) - { + { + time_t t = time(NULL); run_election = check_elections(); listen_for_packets(run_election); @@ -313,11 +310,12 @@ static void process(void) expire_names_and_servers(); expire_netbios_response_entries(); + refresh_my_names(t); write_browse_list(); do_browser_lists(); check_master_browser(); - } + } } @@ -437,50 +435,50 @@ static void usage(char *pname) while ((opt = getopt(argc, argv, "s:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:")) != EOF) { switch (opt) - { - case 's': - strcpy(servicesf,optarg); - break; - case 'N': - case 'B': - case 'I': - case 'C': - case 'G': - DEBUG(0,("Obsolete option '%c' used\n",opt)); - break; - case 'H': - strcpy(host_file,optarg); - break; - case 'n': - strcpy(myname,optarg); - strupper(myname); - break; - case 'l': - sprintf(debugf,"%s.nmb",optarg); - break; - case 'i': - strcpy(scope,optarg); - strupper(scope); - break; - case 'D': - is_daemon = True; - break; - case 'd': - DEBUGLEVEL = atoi(optarg); - break; - case 'p': - port = atoi(optarg); - break; - case 'h': - usage(argv[0]); - exit(0); - break; - default: - if (!is_a_socket(0)) { - usage(argv[0]); - } - break; - } + { + case 's': + strcpy(servicesf,optarg); + break; + case 'N': + case 'B': + case 'I': + case 'C': + case 'G': + DEBUG(0,("Obsolete option '%c' used\n",opt)); + break; + case 'H': + strcpy(host_file,optarg); + break; + case 'n': + strcpy(myname,optarg); + strupper(myname); + break; + case 'l': + sprintf(debugf,"%s.nmb",optarg); + break; + case 'i': + strcpy(scope,optarg); + strupper(scope); + break; + case 'D': + is_daemon = True; + break; + case 'd': + DEBUGLEVEL = atoi(optarg); + break; + case 'p': + port = atoi(optarg); + break; + case 'h': + usage(argv[0]); + exit(0); + break; + default: + if (!is_a_socket(0)) { + usage(argv[0]); + } + break; + } } DEBUG(1,("%s netbios nameserver version %s started\n",timestring(),VERSION)); @@ -489,18 +487,10 @@ static void usage(char *pname) get_myname(myhostname,NULL); if (!reload_services(False)) - return(-1); - + return(-1); + init_structs(); - /* reads the smbbrowse.conf file. this is an alias mapping between - workgroups and samba NetBIOS aliases. samba can therefore be - a member of multiple workgroups, a local master browser of - multiple workgroups, or a domain master browser of multiple - workgroups, via each NetBIOS name alias. the aliases MUST - be unique for this to work. */ - read_smbbrowse_conf(myname); - reload_services(True); set_samba_nb_type(); @@ -530,7 +520,7 @@ static void usage(char *pname) DEBUG(0,("ERROR: a workgroup name of * is no longer supported\n")); } - add_workgroups_to_subnets(); + add_my_subnets(lp_workgroup()); DEBUG(3,("Checked names\n")); -- cgit From 8781e4d787763a6b50d7b3819b33ace208ff7784 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 7 Oct 1996 01:56:21 +0000 Subject: - changed the default nmbd loop timout to 10 seconds (2 seconds was much too short) - got rid of many unnecessary calls to time(NULL) in nmbd. They were causing it to chew too much CPU time when idle. Now we pass a time value in from the top level. (This used to be commit 3cd7303dbc2118db7084a6d8872403d825c52323) --- source3/nmbd/nmbd.c | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 5b3fd19491..d8865662c7 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -159,10 +159,9 @@ static void fault_continue(void) /******************************************************************* expire old names from the namelist and server list ******************************************************************/ -static void expire_names_and_servers(void) +static void expire_names_and_servers(time_t t) { static time_t lastrun = 0; - time_t t = time(NULL); if (!lastrun) lastrun = t; if (t < lastrun + 5) return; @@ -298,23 +297,23 @@ static void process(void) listen_for_packets(run_election); run_packet_queue(); - run_elections(); + run_elections(t); - announce_host(); + announce_host(t); - announce_master(); + announce_master(t); - announce_remote(); + announce_remote(t); - query_refresh_names(); + query_refresh_names(t); - expire_names_and_servers(); - expire_netbios_response_entries(); + expire_names_and_servers(t); + expire_netbios_response_entries(t); refresh_my_names(t); - write_browse_list(); - do_browser_lists(); - check_master_browser(); + write_browse_list(t); + do_browser_lists(t); + check_master_browser(t); } } @@ -528,7 +527,7 @@ static void usage(char *pname) DEBUG(3,("Loaded names\n")); - write_browse_list(); + write_browse_list(time(NULL)); DEBUG(3,("Dumped names\n")); -- cgit From 61236274fe27ed0fd563f78853d70a55a16f2cd0 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Tue, 10 Dec 1996 17:55:27 +0000 Subject: Added -f option for lock file. jra@cygnus.com (This used to be commit 0c8df4cef915ff1bead02e5dad8d761a614dfb62) --- source3/nmbd/nmbd.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index d8865662c7..58953bcd9d 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -403,6 +403,7 @@ static void usage(char *pname) int opt; extern FILE *dbf; extern char *optarg; + char pidFile[100] = { 0 }; *host_file = 0; @@ -431,10 +432,13 @@ static void usage(char *pname) signal(SIGHUP ,SIGNAL_CAST sig_hup); signal(SIGTERM,SIGNAL_CAST sig_term); - while ((opt = getopt(argc, argv, "s:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:")) != EOF) + while ((opt = getopt(argc, argv, "s:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:f:")) != EOF) { switch (opt) { + case 'f': + strncpy(pidFile, optarg, sizeof(pidFile)); + break; case 's': strcpy(servicesf,optarg); break; @@ -504,6 +508,32 @@ static void usage(char *pname) become_daemon(); } + if (*pidFile) + { + int fd; + char buf[20]; + + if ((fd = open(pidFile, + O_NONBLOCK | O_CREAT | O_WRONLY | O_TRUNC, 0644)) < 0) + { + DEBUG(0,("ERROR: can't open %s: %s\n", pidFile, strerror(errno))); + exit(1); + } + if (fcntl_lock(fd,F_SETLK,0,1,F_WRLCK)==False) + { + DEBUG(0,("ERROR: nmbd is already running\n")); + exit(1); + } + sprintf(buf, "%u\n", (unsigned int) getpid()); + if (write(fd, buf, strlen(buf)) < 0) + { + DEBUG(0,("ERROR: can't write to %s: %s\n", pidFile, strerror(errno))); + exit(1); + } + /* Leave pid file open & locked for the duration... */ + } + + DEBUG(3,("Opening sockets %d\n", port)); if (!open_sockets(is_daemon,port)) return 1; -- cgit From b581d0324098f12a5bcb1941e698339a84e44a93 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Sun, 9 Mar 1997 14:58:22 +0000 Subject: 1) updated ipc.c NetUserGetInfo - load \\%L\%U instead of \\%L\HOMES because the share must be browseable by a w95 client 2) send_mailslot_reply - unique or group datagram argument added. 3) netlogon.c - rewrote response packet to do the right thing for w95. 4) server.c reply_nt1() - added OEMDomainstring to the end. 5) (deep breath) reworked the nmbd-browsing code a little bit. i discovered two months ago that becoming a primary domain controller (and domain master browser) is done independently of becoming a backup domain controller (logon server) is done independently of becoming a local master browser. therefore, three sets of state-machines (instead of just one) are in place - each of which is responsible for taking samba through the required stages to become: a logon server; a domain master browser; and a local master browser. each of these three things can occur independently on each interface, _including_ the wins pseudo-interface. the only slight caveat is that the wins pseudo-interface, by virtue of _not_ being a broadcast interface, does _not_ register as a local master browser with the wins server, as this doesn't make sense. lkcl (This used to be commit 88c6a00c3c1b430307f512986185b5ed7aea7181) --- source3/nmbd/nmbd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 58953bcd9d..e45facdc2e 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -300,9 +300,7 @@ static void process(void) run_elections(t); announce_host(t); - announce_master(t); - announce_remote(t); query_refresh_names(t); @@ -314,6 +312,7 @@ static void process(void) write_browse_list(t); do_browser_lists(t); check_master_browser(t); + add_domain_names(t); } } -- cgit From 20b5dea237916902437ce3dcdb7c253fd1ad3585 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Wed, 9 Apr 1997 01:19:25 +0000 Subject: Large changes from jra@cygnus.com. Mainly browser updates. access.c: Fixed crash if yp domain unavailable. includes.h: Moved ifdefs for minor platform. interface.c: Changed name of ipgrp to wins_ip to make it clearer. loadparm.c: Changed default of wins support to 'no'. nameannounce.c: Many changes to fix cross subnet browsing. namebrowse.c: Many changes to fix cross subnet browsing. namedbname.c: Many changes to fix cross subnet browsing. namedbresp.c: Many changes to fix cross subnet browsing. namedbsubnet.c: Many changes to fix cross subnet browsing. namedbwork.c: Many changes to fix cross subnet browsing. nameelect.c: Many changes to fix cross subnet browsing. namelogon.c: Many changes to fix cross subnet browsing. namepacket.c: Many changes to fix cross subnet browsing. nameresp.c: Many changes to fix cross subnet browsing. nameserv.c: Many changes to fix cross subnet browsing. nameserv.h: Many changes to fix cross subnet browsing. nameservreply.c: Many changes to fix cross subnet browsing. nameservresp.c: Many changes to fix cross subnet browsing. namework.c: Many changes to fix cross subnet browsing. nmbd.c: Change to search wins subnet. nmbsync.c: Change to check if we are any master before proceeding. proto.h: Added find_subnet_all() and check_work_servertype(). util.c: Moved 'done' settings on name resolution. (This used to be commit a82476eee2c521e5eed092bc367da0a7cef23de1) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index e45facdc2e..eefb4162f7 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -272,7 +272,7 @@ static void load_hosts_file(char *fname) } ipaddr = *interpret_addr2(ip); - d = find_subnet(ipaddr); + d = find_subnet_all(ipaddr); if (d) { add_netbios_entry(d,name,0x00,NB_ACTIVE,0,source,ipaddr,True,True); add_netbios_entry(d,name,0x20,NB_ACTIVE,0,source,ipaddr,True,True); -- cgit From 0f1f0ceb9519368188f695e18e2341ccfd1b2d15 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Thu, 8 May 1997 01:14:17 +0000 Subject: 'The mother of all checkins' :-). Jeremy Allison (jallison@whistle.com) Wed May 7 1997: Update for 1.9.17alpha1 release - 'browsefix release' designed to make browsing across subnets work. byteorder.h: Updated copyright to 1997. charcnv.c: Updated copyright to 1997. charset.c Updated copyright to 1997. charset.h Updated copyright to 1997. client.c Updated copyright to 1997. clientutil.c Updated copyright to 1997. dir.c Updated copyright to 1997. fault.c Updated copyright to 1997. includes.h Updated copyright to 1997. interface.c Updated copyright to 1997. ipc.c Updated copyright to 1997. kanji.c Updated copyright to 1997. kanji.h Updated copyright to 1997. loadparm.c Updated copyright to 1997. locking.c Updated copyright to 1997. mangle.c Updated copyright to 1997. message.c Updated copyright to 1997. nameannounce.c Made use of WINS subnet explicit. Added reset_announce_timer() so announcement can be made immediately when we become a master. Expanded code to do sync with dmb. namebrowse.c Removed redundent checks for AM_MASTER in sync code. Made use of WINS subnet explicit. namedbname.c Made use of WINS subnet explicit. namedbresp.c Made use of WINS subnet explicit. namedbserver.c Made use of WINS subnet explicit. namedbsubnet.c Explicitly add workgroup to WINS subnet when we become a dmb. Made use of WINS subnet explicit. namedbwork.c Made use of WINS subnet explicit. Removed redundent check_work_servertype() function. nameelect.c Explicitly add workgroup to WINS subnet when we become a master browser. Made use of WINS subnet explicit. namelogon.c Updated copyright to 1997. namepacket.c Updated copyright to 1997. namequery.c Updated copyright to 1997. nameresp.c Made use of WINS subnet explicit. Made nmbd fail if configured as master browser and one exists already. nameserv.c Made use of WINS subnet explicit. Remove redundent logon server and domain master code. nameserv.h Add emumerate subnet macros. nameservreply.c Made use of WINS subnet explicit. nameservresp.c Updated copyright to 1997. namework.c Made use of WINS subnet explicit. Updated code to add sync browser entries to add subnet parameter. nmbd.c Added sanity check for misconfigured nmbd. nmblib.c Updated copyright to 1997. nmblookup.c Updated copyright to 1997. nmbsync.c Removed redundent AM_ANY_MASTER check. params.c Updated copyright to 1997. password.c Updated copyright to 1997. pipes.c Updated copyright to 1997. predict.c Updated copyright to 1997. printing.c Updated copyright to 1997. proto.h Changed protos for new nmbd code. quotas.c Updated copyright to 1997. replace.c Updated copyright to 1997. reply.c Updated copyright to 1997. server.c Updated copyright to 1997. shmem.c Updated copyright to 1997. smb.h Updated copyright to 1997. smbencrypt.c Updated copyright to 1997. smbpasswd.c Updated copyright to 1997. smbrun.c Updated copyright to 1997. status.c Updated copyright to 1997. system.c Updated copyright to 1997. testparm.c Updated copyright to 1997. testprns.c Updated copyright to 1997. time.c Updated copyright to 1997. trans2.c Updated copyright to 1997. trans2.h Updated copyright to 1997. uid.c Updated copyright to 1997. username.c Updated copyright to 1997. util.c Updated copyright to 1997. version.h Changed to 1.9.17alpha1. (This used to be commit cf23a155a1315f50d488794a2caf88402bf3e3e6) --- source3/nmbd/nmbd.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index eefb4162f7..550f3198f7 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -2,7 +2,7 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Andrew Tridgell 1994-1995 + Copyright (C) Andrew Tridgell 1994-1997 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -206,6 +206,13 @@ BOOL reload_services(BOOL test) load_interfaces(); add_subnet_interfaces(); + /* Do a sanity check for a misconfigured nmbd */ + if(lp_wins_support() && *lp_wins_server()) { + DEBUG(0,("ERROR: both 'wins support = true' and 'wins server = ' \ +cannot be set in the smb.conf file. nmbd aborting.\n")); + exit(10); + } + return(ret); } @@ -546,6 +553,7 @@ static void usage(char *pname) if (strequal(lp_workgroup(),"*")) { DEBUG(0,("ERROR: a workgroup name of * is no longer supported\n")); + exit(1); } add_my_subnets(lp_workgroup()); -- cgit From aa864415c5183c948fe9ae221023d40265c38013 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Tue, 20 May 1997 00:32:51 +0000 Subject: dir.c: Fixed double slash issue. includes.h: Changed to ifdef FAST_SHARE_MODES. ipc.c: Changed lp_workgroup() to myworkgroup. loadparm.c: Added new shared mem parameters. Added Luke's fix. locking.c: Rewrite to do share modes better (both fast and slow modes). nameannounce.c: Changed lp_workgroup() to myworkgroup. Added Luke's fix. nameconf.c: Changed lp_workgroup() to myworkgroup. namedbname.c: Improved debug. namedbserver.c: Changed lp_workgroup() to myworkgroup. namedbsubnet.c: Added Luke's fix - rewritten somewhat. namedbwork.c: Changed lp_workgroup() to myworkgroup. nameelect.c: Added Luke's fix - rewritten somewhat. nameresp.c: Stoped shadowing global. nameserv.c: Added Luke's fix - Improved debug. nameservreply.c: Improved debug. namework.c: Changed lp_workgroup() to myworkgroup. nmbd.c: Added Luke's fix - Changed lp_workgroup() to myworkgroup. pipes.c: Changed lp_workgroup() to myworkgroup. proto.h: Added Luke's fix, added smb_shm_ proto's. reply.c: Changed lp_workgroup() to myworkgroup. server.c: Rewrite to do share modes better (both fast and slow modes). shmem.c: Rewrite to do share modes better (both fast and slow modes). smb.h: Rewrite to do share modes better (both fast and slow modes). status.c: Rewrite to do share modes better (both fast and slow modes). trans2.c: Fixed double slash issue. util.c: Tidied up, created myworkgroup. Jeremy Allison (jallison@whistle.com). (This used to be commit 2a1711eaaf08bb6776770cd3c96b3010f431a677) --- source3/nmbd/nmbd.c | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 550f3198f7..11f005b785 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -40,6 +40,7 @@ int ClientDGRAM = -1; extern pstring myhostname; static pstring host_file; extern pstring myname; +extern fstring myworkgroup; /* are we running as a daemon ? */ static BOOL is_daemon = False; @@ -67,7 +68,7 @@ static int sig_term() /* announce all server entries as 0 time-to-live, 0 type */ /* XXXX don't care if we never receive a response back... yet */ - remove_my_servers(); + announce_my_servers_removed(); /* XXXX other things: if we are a master browser, force an election? */ @@ -203,9 +204,6 @@ BOOL reload_services(BOOL test) reload_services(True); } - load_interfaces(); - add_subnet_interfaces(); - /* Do a sanity check for a misconfigured nmbd */ if(lp_wins_support() && *lp_wins_server()) { DEBUG(0,("ERROR: both 'wins support = true' and 'wins server = ' \ @@ -502,6 +500,8 @@ static void usage(char *pname) reload_services(True); + strcpy(myworkgroup, lp_workgroup()); + set_samba_nb_type(); if (!is_daemon && !is_a_socket(0)) { @@ -549,15 +549,16 @@ static void usage(char *pname) DEBUG(3,("Loaded hosts file\n")); } + load_interfaces(); + add_my_subnets(myworkgroup); + add_my_names(); - if (strequal(lp_workgroup(),"*")) { + if (strequal(myworkgroup,"*")) { DEBUG(0,("ERROR: a workgroup name of * is no longer supported\n")); exit(1); } - add_my_subnets(lp_workgroup()); - DEBUG(3,("Checked names\n")); load_netbios_names(); -- cgit From 3ab97ebe6db1a5a4a0573c7c8482c94876bbce9a Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Fri, 30 May 1997 20:40:48 +0000 Subject: charcnv.c: Fixed silly bugs detected on IRIX. client.c: Fixed silly bugs detected on IRIX. namedbname.c: Stopped 1d names from being registered in WINS db. namedbsubnet.c: Only register 1e names on broadcast subnet. nameelect.c: Changed add_my_name entries. Forced host announces if we have less than 10 servers listed. Fixed registering 1b domain name issues. namepacket.c: Added error message when dgram discarded. nameserv.c: Added notion of 'direct' names that are not registered on the network. Needed to get around bugs in earlier nmbd handling of DOMAIN(1b) names. nameservreply.c:Tidied up debug message. nameservresp.c: Added response_name_query_domain() code. Deals with re-registering DOMAIN(1b) name. nmbd.c: Fixed silly bugs detected on IRIX. nmblib.c: Added paranoia debugs. proto.h: Updated remove_name_entry(), add_my_name_entry(). server.c: Fixed silly bugs detected on IRIX. trans2.c: Fixed silly bugs detected on IRIX. uid.c: Fixed silly bugs detected on IRIX. version.h: Updated to alpha3. Jeremy (jallison@whistle.com). (This used to be commit f08222bd8b86a061c52d22015f946a4737eb47fd) --- source3/nmbd/nmbd.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 11f005b785..99d65d551a 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -73,6 +73,8 @@ static int sig_term() /* XXXX other things: if we are a master browser, force an election? */ exit(0); + /* Keep compiler happy.. */ + return 0; } -- cgit From d98bea900ee694cdba83149620c65bd7f8765f26 Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Sat, 31 May 1997 01:11:40 +0000 Subject: namepacket.c: Block SIGTERM correctly - we can only take them at defined points. nameserv.c: Fixup name release code - used when we are going down. nameservreply.c: Relaxed check for deleting name - original code never deleted. nmbd.c: Block SIGTERM signals most of the time - see comment on namepacket above. Jeremy (jallison@whistle.com) (This used to be commit 9f4e01224751134c2f7701e2aea87d06a79d77a4) --- source3/nmbd/nmbd.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 99d65d551a..dc3f642cd6 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -571,6 +571,8 @@ static void usage(char *pname) DEBUG(3,("Dumped names\n")); + /* We can only take sigterm signals in the select. */ + BlockSignals(True,SIGTERM); process(); close_sockets(); -- cgit From c6e63aa896a10656f6205828e744b722fc72f8ac Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Wed, 11 Jun 1997 01:03:06 +0000 Subject: Makefile: Added quoata changes for Linux from Thorvald Natvig Makefile.RPM: Added quoata changes for Linux from Thorvald Natvig charset.c: Large changes to add multiple client code pages. charset.h: Changed charset_initialise() proto. client.c: Fixed message sending bug. Changed charset_initialise(). ipc.c: Fixed #ifdef compile problems. loadparm.c: Added "client code page" option. nmbd.c: Changed charset_initialise(). Fixed lmhosts read. nmblookup.c: Changed charset_initialise(). proto.h: Added lp_client_code_page(void). quotas.c: Added quoata changes for Linux from Thorvald Natvig reply.c: Changed debug level. Made SMBecho ignore tid. server.c: Changed charset_initialise(). smb.h: Added DEFAULT_CLIENT_CODE_PAGE as 850. smbpasswd.c: Changed charset_initialise(). status.c: Changed charset_initialise(). testparm.c: Changed charset_initialise(). testprns.c: Changed charset_initialise(). Jeremy Allison (jallison@whistle.com) (This used to be commit 957025bace1bcff34d21a6caeca498e85abccb23) --- source3/nmbd/nmbd.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index dc3f642cd6..75544535af 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -421,7 +421,7 @@ static void usage(char *pname) setup_logging(argv[0],False); - charset_initialise(); + charset_initialise(-1); #ifdef LMHOSTSFILE strcpy(host_file,LMHOSTSFILE); @@ -498,12 +498,19 @@ static void usage(char *pname) if (!reload_services(False)) return(-1); + charset_initialise(lp_client_code_page()); + init_structs(); reload_services(True); strcpy(myworkgroup, lp_workgroup()); + if (strequal(myworkgroup,"*")) { + DEBUG(0,("ERROR: a workgroup name of * is no longer supported\n")); + exit(1); + } + set_samba_nb_type(); if (!is_daemon && !is_a_socket(0)) { @@ -546,27 +553,22 @@ static void usage(char *pname) if (!open_sockets(is_daemon,port)) return 1; - if (*host_file) { - load_hosts_file(host_file); - DEBUG(3,("Loaded hosts file\n")); - } - load_interfaces(); add_my_subnets(myworkgroup); add_my_names(); - if (strequal(myworkgroup,"*")) { - DEBUG(0,("ERROR: a workgroup name of * is no longer supported\n")); - exit(1); - } - DEBUG(3,("Checked names\n")); load_netbios_names(); DEBUG(3,("Loaded names\n")); + if (*host_file) { + load_hosts_file(host_file); + DEBUG(3,("Loaded hosts file\n")); + } + write_browse_list(time(NULL)); DEBUG(3,("Dumped names\n")); -- cgit From 25eae02948b40667495fbb021dd130180180a05e Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Tue, 8 Jul 1997 16:54:44 +0000 Subject: Makefile: Added AIX targets from Ole Holm Nielsen chgpasswd.c: Added Samba/GPL notice (for obvious reasons). clitar.c: Updated Copyright date to include 1997 (for obvious reasons). getsmbpass.c: Updated Copyright date to include 1997 (for obvious reasons). includes.h: Added stropts for solaris. loadparm.c: Changed comment for hide files option. nameconf.c: Updated Copyright date to include 1997 (for obvious reasons). nmbd.c: Updated Copyright date to include 1997 (for obvious reasons). pcap.c: Updated Copyright date to include 1997 (for obvious reasons). proto.h: Re-added accidentaly deleted smb_shm_ calls. quotas.c: Added AIX quota patch from Ole Holm Nielsen server.c: Optimization on calling is_hidden_path. Updated Copyrights. smb.h: Changed DEFAULT_FILES_TO_HIDE from "*/.*" to ".*". smbpass.c: Updated Copyright date to include 1997 (for obvious reasons). ufc.c: Updated Copyright date to include 1997 (for obvious reasons). util.c: Added last component code to is_in_path(). Jeremy (jallison@whistle.com) (This used to be commit 9385ae1005f13c8ed51f1319e3949b5c8571e62d) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 75544535af..bf29829317 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -491,7 +491,7 @@ static void usage(char *pname) } DEBUG(1,("%s netbios nameserver version %s started\n",timestring(),VERSION)); - DEBUG(1,("Copyright Andrew Tridgell 1994\n")); + DEBUG(1,("Copyright Andrew Tridgell 1994-1997\n")); get_myname(myhostname,NULL); -- cgit From 612111c7a1a048d19e24b5e2e4d426247d320d1e Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Fri, 18 Jul 1997 20:21:32 +0000 Subject: charset.c: Split charset_initialise() into 2 - a charset_initialise() and a codepage_initialise(). Fixes problem with initialising dos map twice. charset.h: Changes to support charset changes. client.c: Changes to support charset changes. loadparm.c: follow symlinks parameter from David Clerc nmbd.c: Changes to support charset changes. nmblookup.c:Changes to support charset changes. proto.h: Changes to support charset changes. reply.c: Don't call security=server with no user/no password guest. Fix from Stefaan A Eeckels server.c: follow symlinks code from David Clerc smbpasswd.c:Changes to support charset changes. status.c: Changes to support charset changes. testparm.c: Changes to support charset changes. testprns.c: Changes to support charset changes. uid.c: Fixed log message with no \n. Jeremy (jallison@whistle.com) (This used to be commit 2a28a6e5e461aca7fe6c19cd01d287010056cffb) --- source3/nmbd/nmbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index bf29829317..14611dc2c5 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -421,7 +421,7 @@ static void usage(char *pname) setup_logging(argv[0],False); - charset_initialise(-1); + charset_initialise(); #ifdef LMHOSTSFILE strcpy(host_file,LMHOSTSFILE); @@ -498,7 +498,7 @@ static void usage(char *pname) if (!reload_services(False)) return(-1); - charset_initialise(lp_client_code_page()); + codepage_initialise(lp_client_code_page()); init_structs(); -- cgit From 15ae50ca5203bc4c04567e400ba041a4d1757b2b Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Thu, 24 Jul 1997 17:25:11 +0000 Subject: Makefile: Added UNIXWARE 2.x with shadow passwords from fja@extratech.com client.c: Made prompt appear at debug level 0. Fixed strcasecmp redefinition. Caused client to use set_blocking rather than making fcntl calls itself. dir.c: Removed redundent snum parameters. includes.h: Added SCO fixes. loadparm.c: Made default 'files to hide' a null string. nmbd.c: Removed O_NONBLOCK from pid file open for platforms that dont have it. proto.h: Changed snum to cnum where needed. Changed is_xx_path to is_in_path (now called via MACRO). quotas.c: Swapped setuid/seteuid calls when restoring uid. reply.c: Removed redundent snum parameters. server.c: Changed snum to cnum where needed. Setup new veto_list, hide_list namelists. Added standard_sub changes from Stefaan A Eeckels and Paul Rippin shmem.c: Changed cast for sizeof to be int before negating. smb.h: Added new veto_list, hide_list entries to connections. Added IS_PRINT, IS_HIDDEN_PATH, IS_VETO_PATH macros. trans2.c: Removed redundent snum parameters. util.c: Added standard_sub_basic changes from Stefaan A Eeckels and Paul Rippin Fixed up veto/hidden path processing so the paths are pres-parsed and checked for wildcards (for speed). Jeremy (jallison@whistle.com) (This used to be commit 9afa36f7874cfd527aa6ef1e7965c1d35d46ab1f) --- source3/nmbd/nmbd.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 14611dc2c5..10701c24d4 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -529,7 +529,10 @@ static void usage(char *pname) char buf[20]; if ((fd = open(pidFile, - O_NONBLOCK | O_CREAT | O_WRONLY | O_TRUNC, 0644)) < 0) +#ifdef O_NONBLOCK + O_NONBLOCK | +#endif + O_CREAT | O_WRONLY | O_TRUNC, 0644)) < 0) { DEBUG(0,("ERROR: can't open %s: %s\n", pidFile, strerror(errno))); exit(1); -- cgit From 363b9a2739e9e39d1f69625e6647c6c9047a901a Mon Sep 17 00:00:00 2001 From: Samba Release Account Date: Thu, 31 Jul 1997 18:47:26 +0000 Subject: loadparm.c: Added new netbios aliases parameter (code from Cisco) nameannounce.c: Code to announce aliases as well as our own names. namedbsubnet.c: Code to add the aliases to the server list. nameserv.c: Code to defend our aliases on the namelist. namework.c: Code to check it's one of our aliases. nmbd.c: Code to initialise the aliases. proto.h: Fixup protos. util.c: Code to check it's one of our aliases. All above code based on code for 1.9.16p11 donated by Cisco from Ben Woodard Jeremy (jallison@whistle.com) (This used to be commit a2ce1c0cb1331551ff728dcfe3260fab4cd827e5) --- source3/nmbd/nmbd.c | 68 +++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 64 insertions(+), 4 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 10701c24d4..925f975ffe 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -41,6 +41,7 @@ extern pstring myhostname; static pstring host_file; extern pstring myname; extern fstring myworkgroup; +extern char **my_netbios_names; /* are we running as a daemon ? */ static BOOL is_daemon = False; @@ -363,7 +364,11 @@ static BOOL open_sockets(BOOL isdaemon, int port) static BOOL init_structs() { extern fstring local_machine; - char *p; + char *p, *ptr; + int namecount; + int n; + int nodup; + pstring nbname; if (! *myname) { strcpy(myname,myhostname); @@ -372,12 +377,62 @@ static BOOL init_structs() } strupper(myname); + /* Add any NETBIOS name aliases. Ensure that the first entry + is equal to myname. */ + /* Work out the max number of netbios aliases that we have */ + ptr=lp_netbios_aliases(); + for (namecount=0; next_token(&ptr,nbname,NULL); namecount++) + ; + if (*myname) + namecount++; + + /* Allocate space for the netbios aliases */ + if((my_netbios_names=(char **)malloc(sizeof(char *)*(namecount+1))) == NULL) + { + DEBUG(0,("init_structs: malloc fail.\n")); + return False; + } + + /* Use the myname string first */ + namecount=0; + if (*myname) + my_netbios_names[namecount++] = myname; + + ptr=lp_netbios_aliases(); + while (next_token(&ptr,nbname,NULL)) { + strupper(nbname); + /* Look for duplicates */ + nodup=1; + for(n=0; n Date: Fri, 26 Sep 1997 18:55:29 +0000 Subject: Adding Andrews buffer overflow fixes into the main branch. Jeremy (jallison@whistle.com) (This used to be commit e7eb1f044d3101679dc7a118820ea5efe0cd837c) --- source3/nmbd/nmbd.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 925f975ffe..3f0279908d 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -121,7 +121,7 @@ static BOOL dump_core(void) { char *p; pstring dname; - strcpy(dname,debugf); + pstrcpy(dname,debugf); if ((p=strrchr(dname,'/'))) *p=0; strcat(dname,"/corefiles"); mkdir(dname,0700); @@ -188,10 +188,10 @@ BOOL reload_services(BOOL test) if (lp_loaded()) { pstring fname; - strcpy(fname,lp_configfile()); + pstrcpy(fname,lp_configfile()); if (file_exist(fname,NULL) && !strcsequal(fname,servicesf)) { - strcpy(servicesf,fname); + pstrcpy(servicesf,fname); test = False; } } @@ -276,7 +276,7 @@ static void load_hosts_file(char *fname) if (strchr(flags,'M')) { source = SELF; - strcpy(myname,name); + pstrcpy(myname,name); } ipaddr = *interpret_addr2(ip); @@ -371,7 +371,7 @@ static BOOL init_structs() pstring nbname; if (! *myname) { - strcpy(myname,myhostname); + fstrcpy(myname,myhostname); p = strchr(myname,'.'); if (p) *p = 0; } @@ -422,7 +422,7 @@ static BOOL init_structs() /* Terminate name list */ my_netbios_names[namecount++]=NULL; - strcpy(local_machine,myname); + fstrcpy(local_machine,myname); trim_string(local_machine," "," "); p = strchr(local_machine,' '); if (p) @@ -501,7 +501,7 @@ static void usage(char *pname) strncpy(pidFile, optarg, sizeof(pidFile)); break; case 's': - strcpy(servicesf,optarg); + pstrcpy(servicesf,optarg); break; case 'N': case 'B': @@ -511,17 +511,17 @@ static void usage(char *pname) DEBUG(0,("Obsolete option '%c' used\n",opt)); break; case 'H': - strcpy(host_file,optarg); + pstrcpy(host_file,optarg); break; case 'n': - strcpy(myname,optarg); + pstrcpy(myname,optarg); strupper(myname); break; case 'l': sprintf(debugf,"%s.nmb",optarg); break; case 'i': - strcpy(scope,optarg); + pstrcpy(scope,optarg); strupper(scope); break; case 'D': @@ -564,7 +564,7 @@ static void usage(char *pname) reload_services(True); - strcpy(myworkgroup, lp_workgroup()); + pstrcpy(myworkgroup, lp_workgroup()); if (strequal(myworkgroup,"*")) { DEBUG(0,("ERROR: a workgroup name of * is no longer supported\n")); -- cgit From 4fe23997bf77c31d13daf404bf28d3c16bdcfd7a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 17 Oct 1997 01:46:16 +0000 Subject: added -a "append log" option (This used to be commit 4b7d51ffb8cf23662e0e58a785620a0652da5a7c) --- source3/nmbd/nmbd.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 3f0279908d..c7af54fa13 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -493,7 +493,7 @@ static void usage(char *pname) signal(SIGHUP ,SIGNAL_CAST sig_hup); signal(SIGTERM,SIGNAL_CAST sig_term); - while ((opt = getopt(argc, argv, "s:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:f:")) != EOF) + while ((opt = getopt(argc, argv, "as:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:f:")) != EOF) { switch (opt) { @@ -524,6 +524,12 @@ static void usage(char *pname) pstrcpy(scope,optarg); strupper(scope); break; + case 'a': + { + extern BOOL append_log; + append_log = !append_log; + } + break; case 'D': is_daemon = True; break; -- cgit From c336a2f08183f63031b0a08b2111669bc36a5f30 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 17 Oct 1997 23:08:07 +0000 Subject: .cvsignore: Added make_smbcodepage interface.c: Added is_local_net(). locking.c: Added Fix for zero length share files from Gerald Werner plus a race condition fix for the fix. nameannounce.c: Made function static. namedbresp.c: extern int ClientDGRAM removed - not used. namedbserver.c: extern int ClientDGRAM removed - not used. namedbsubnet.c: Added code to make sockets per subnet. namepacket.c: Added code to read from all sockets & filter. nameresp.c: extern int ClientDGRAM removed - not used. nameserv.c: Indentation tidyup :-). nameserv.h: Added sockets to struct subnet. nameservresp.c: Improved debug message. nmbd.c: Changed to terminte on listen_for_packets exiting. nmbsync.c: extern int ClientDGRAM & ClientNMB removed - not used. proto.h: The usual. util.c: Fixed debug message. Jeremy (jallison@whistle.com) (This used to be commit 6904c2de080b2a9702800e9e4126386ced20569d) --- source3/nmbd/nmbd.c | 29 +++++++++++++++++++---------- 1 file changed, 19 insertions(+), 10 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index c7af54fa13..047284832f 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -34,8 +34,9 @@ pstring servicesf = CONFIGFILE; extern pstring scope; -int ClientNMB = -1; -int ClientDGRAM = -1; +int ClientNMB = -1; +int ClientDGRAM = -1; +int global_nmb_port = -1; extern pstring myhostname; static pstring host_file; @@ -302,7 +303,8 @@ static void process(void) { time_t t = time(NULL); run_election = check_elections(); - listen_for_packets(run_election); + if(listen_for_packets(run_election)) + return; run_packet_queue(); run_elections(t); @@ -338,12 +340,19 @@ static BOOL open_sockets(BOOL isdaemon, int port) return False; } + /* The sockets opened here will be used to receive broadcast + packets *only*. Interface specific sockets are opened in + make_subnet() in namedbsubnet.c. Thus we bind to the + address "0.0.0.0". The parameter 'socket address' is + now deprecated. + */ + if (isdaemon) - ClientNMB = open_socket_in(SOCK_DGRAM, port,0,interpret_addr(lp_socket_address())); + ClientNMB = open_socket_in(SOCK_DGRAM, port,0,0); else ClientNMB = 0; - ClientDGRAM = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3,interpret_addr(lp_socket_address())); + ClientDGRAM = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3,0); if (ClientNMB == -1) return(False); @@ -353,7 +362,7 @@ static BOOL open_sockets(BOOL isdaemon, int port) set_socket_options(ClientNMB,"SO_BROADCAST"); set_socket_options(ClientDGRAM,"SO_BROADCAST"); - DEBUG(3,("Sockets opened.\n")); + DEBUG(3,("open_sockets: Broadcast sockets opened.\n")); return True; } @@ -460,12 +469,12 @@ static void usage(char *pname) **************************************************************************/ int main(int argc,char *argv[]) { - int port = NMB_PORT; int opt; extern FILE *dbf; extern char *optarg; char pidFile[100] = { 0 }; + global_nmb_port = NMB_PORT; *host_file = 0; StartupTime = time(NULL); @@ -537,7 +546,7 @@ static void usage(char *pname) DEBUGLEVEL = atoi(optarg); break; case 'p': - port = atoi(optarg); + global_nmb_port = atoi(optarg); break; case 'h': usage(argv[0]); @@ -618,9 +627,9 @@ static void usage(char *pname) } - DEBUG(3,("Opening sockets %d\n", port)); + DEBUG(3,("Opening sockets %d\n", global_nmb_port)); - if (!open_sockets(is_daemon,port)) return 1; + if (!open_sockets(is_daemon,global_nmb_port)) return 1; load_interfaces(); add_my_subnets(myworkgroup); -- cgit From e5c319186d079eeef55a7ee62fac2a993e932938 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 22 Oct 1997 11:02:00 +0000 Subject: Implemented asynchronous DNS lookups in nmbd. I realised this afternoon just how easy it is to add this, so I thought I'd implement it while the idea was fresh. nmbd forks at startup and uses a pipe to talk to its child. The child does the DNS lookups and the file descriptor of the child is added to the main select loop. While I was doing this I discovered a bug in nmbd that explains why the dns proxy option has been so expensive. The DNS cache entries in the WINS list were never being checked, which means we always did a DNS lookup even if we have done it before and it is in cache. I'm sure this used to work (I tested the DNS cache when I added it) so someone broke it :-( Anyway, the async DNS gets rid of the problem completely. I'll commit just the fix to the DNS cache bug to the 1.9.17 tree. You can disable async DNS by adding -DSYNC_DNS to the compile flags. (This used to be commit 178e27de0791c1ff3268cb456ed5c5efc9ac2a01) --- source3/nmbd/asyncdns.c | 257 ++++++++++++++++++++++++++++++++++++++++++++++++ source3/nmbd/nmbd.c | 13 +-- 2 files changed, 262 insertions(+), 8 deletions(-) create mode 100644 source3/nmbd/asyncdns.c (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c new file mode 100644 index 0000000000..548781edea --- /dev/null +++ b/source3/nmbd/asyncdns.c @@ -0,0 +1,257 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + a async DNS handler + Copyright (C) Andrew Tridgell 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + Revision History: + + 14 jan 96: lkcl@pires.co.uk + added multiple workgroup domain master support + +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; + + +/*************************************************************************** + add a DNS result to the name cache + ****************************************************************************/ +static struct name_record *add_dns_result(struct nmb_name *question, struct in_addr addr) +{ + int name_type = question->name_type; + char *qname = question->name; + + if (!addr.s_addr) { + /* add the fail to WINS cache of names. give it 1 hour in the cache */ + DEBUG(3,("Negative DNS answer for %s\n", qname)); + add_netbios_entry(wins_subnet,qname,name_type,NB_ACTIVE,60*60,DNSFAIL,addr, + True, True); + return NULL; + } + + /* add it to our WINS cache of names. give it 2 hours in the cache */ + DEBUG(3,("DNS gave answer for %s of %s\n", qname, inet_ntoa(addr))); + + return add_netbios_entry(wins_subnet,qname,name_type,NB_ACTIVE,2*60*60,DNS,addr, + True,True); +} + + + +#ifndef SYNC_DNS + +static int fd_in = -1, fd_out = -1; +static int child_pid = -1; +static int in_dns; + +/* this is the structure that is passed between the parent and child */ +struct query_record { + struct nmb_name name; + struct in_addr result; +}; + +/* a queue of pending requests waiting for DNS responses */ +static struct packet_struct *dns_queue; + + + +/*************************************************************************** + return the fd used to gather async dns replies. This is added to the select + loop + ****************************************************************************/ +int asyncdns_fd(void) +{ + return fd_in; +} + +/*************************************************************************** + handle DNS queries arriving from the parent + ****************************************************************************/ +static void asyncdns_process(void) +{ + struct query_record r; + fstring qname; + + DEBUGLEVEL = 0; + + while (1) { + if (read_data(fd_in, (char *)&r, sizeof(r)) != sizeof(r)) + break; + + fstrcpy(qname, r.name.name); + + r.result.s_addr = interpret_addr(qname); + + if (write_data(fd_out, (char *)&r, sizeof(r)) != sizeof(r)) + break; + } + + exit(0); +} + + +/*************************************************************************** + create a child process to handle DNS lookups + ****************************************************************************/ +void start_async_dns(void) +{ + int fd1[2], fd2[2]; + + signal(SIGCLD, SIG_IGN); + + if (pipe(fd1) || pipe(fd2)) { + return; + } + + child_pid = fork(); + + if (child_pid) { + fd_in = fd1[0]; + fd_out = fd2[1]; + close(fd1[1]); + close(fd2[0]); + DEBUG(3,("async DNS initialised\n")); + return; + } + + fd_in = fd2[0]; + fd_out = fd1[1]; + + asyncdns_process(); +} + + +/*************************************************************************** +check if a particular name is already being queried + ****************************************************************************/ +static BOOL query_in_queue(struct query_record *r) +{ + struct packet_struct *p; + for (p = dns_queue; p; p = p->next) { + struct nmb_packet *nmb = &p->packet.nmb; + struct nmb_name *question = &nmb->question.question_name; + + if (name_equal(question, &r->name)) + return True; + } + return False; +} + + +/*************************************************************************** + check the DNS queue + ****************************************************************************/ +void run_dns_queue(void) +{ + struct query_record r; + struct packet_struct *p, *p2; + + if (fd_in == -1) + return; + + if (read_data(fd_in, (char *)&r, sizeof(r)) != sizeof(r)) { + DEBUG(0,("Incomplete DNS answer from child!\n")); + fd_in = -1; + return; + } + + add_dns_result(&r.name, r.result); + + /* loop over the whole dns queue looking for entries that + match the result we just got */ + for (p = dns_queue; p;) { + struct nmb_packet *nmb = &p->packet.nmb; + struct nmb_name *question = &nmb->question.question_name; + + if (name_equal(question, &r.name)) { + DEBUG(3,("DNS calling reply_name_query\n")); + in_dns = 1; + reply_name_query(p); + in_dns = 0; + p->locked = False; + + if (p->prev) + p->prev->next = p->next; + else + dns_queue = p->next; + if (p->next) + p->next->prev = p->prev; + p2 = p->next; + free_packet(p); + p = p2; + } else { + p = p->next; + } + } + +} + +/*************************************************************************** +queue a DNS query + ****************************************************************************/ +BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, + struct name_record **n) +{ + struct query_record r; + + if (in_dns || fd_in == -1) + return False; + + r.name = *question; + + if (!query_in_queue(&r) && + !write_data(fd_out, (char *)&r, sizeof(r))) { + DEBUG(3,("failed to send DNS query to child!\n")); + return False; + } + + p->locked = True; + p->next = dns_queue; + p->prev = NULL; + if (p->next) + p->next->prev = p; + dns_queue = p; + + + DEBUG(3,("added DNS query for %s\n", namestr(question))); + return True; +} + +#else + + +/*************************************************************************** + we use this then we can't do async DNS lookups + ****************************************************************************/ +BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, + struct name_record **n) +{ + int name_type = question->name_type; + char *qname = question->name; + struct in_addr dns_ip; + + DEBUG(3,("DNS search for %s - ", namestr(question))); + + dns_ip.s_addr = interpret_addr(qname); + + *n = add_dns_result(question, dns_ip); + return False; +} +#endif diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 047284832f..5feeb07c90 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -332,14 +332,6 @@ static void process(void) ****************************************************************************/ static BOOL open_sockets(BOOL isdaemon, int port) { - struct hostent *hp; - - /* get host info */ - if ((hp = Get_Hostbyname(myhostname)) == 0) { - DEBUG(0,( "Get_Hostbyname: Unknown host. %s\n",myhostname)); - return False; - } - /* The sockets opened here will be used to receive broadcast packets *only*. Interface specific sockets are opened in make_subnet() in namedbsubnet.c. Thus we bind to the @@ -598,6 +590,10 @@ static void usage(char *pname) become_daemon(); } +#ifndef SYNC_DNS + start_async_dns(); +#endif + if (*pidFile) { int fd; @@ -653,6 +649,7 @@ static void usage(char *pname) /* We can only take sigterm signals in the select. */ BlockSignals(True,SIGTERM); + process(); close_sockets(); -- cgit From abb255cfe674a39c6a42f5083af9c5facdbcca05 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 23 Oct 1997 22:30:57 +0000 Subject: Big change to make nmbd code more readable/understandable. Main change is removal of find_name_search() confusion. This has been replaced with find_name_on_subnet() which makes it explicit what is being searched. Also changed wins_subnet to be wins_client_subnet in preparation for splitting the wins subnet into client and server pieces. This is a big nmbd change and I'd appreciate any bug reports. Specific changes follow : asyncdns.c: Removed wins entry from add_netbios_entry(). This is now explicit in the subnet_record parameter. interface.c: iface_bcast(), iface_nmask(), iface_ip() return the default interface if none can be found. Made this behavior explicit - some code in nmbd incorrectly depended upon this (reply_name_status() for instance). nameannounce.c: find_name_search changes to find_name_on_subnet. namebrowse.c: wins_subnet renamed to wins_client_subnet. namedbname.c: find_name_search removed. find_name_on_subnet added. add_netbios_entry - wins parameter removed. namedbsubnet.c: find_req_subnet removed - not explicit enough. nameelect.c: wins_subnet renamed to wins_client_subnet. namepacket.c: listening() simplified. nameresp.c: wins_subnet renamed to wins_client_subnet. nameserv.c: find_name_search moved to find_name_on_subnet. nameserv.h: FIND_XXX -> changed to FIND_SELF_NAME, FIND_ANY_NAME. nameservreply.c: find_name_search moved to find_name_on_subnet. Debug entries changed. nameservresp.c: wins_subnet renamed to wins_client_subnet. namework.c: wins_subnet renamed to wins_client_subnet. nmbd.c: wins parameter removed from add_netbios_entry. nmbsync: wins_subnet renamed to wins_client_subnet. proto.h: The usual. server.c: remove accepted fd from fd_set. Jeremy (jallison@whistle.com) (This used to be commit 2c97b33fc0b5ef181dbf51a50cb61074935165bf) --- source3/nmbd/asyncdns.c | 32 ++++++++++++++++---------------- source3/nmbd/nmbd.c | 4 ++-- 2 files changed, 18 insertions(+), 18 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 548781edea..94fd65b147 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -35,22 +35,22 @@ extern int DEBUGLEVEL; ****************************************************************************/ static struct name_record *add_dns_result(struct nmb_name *question, struct in_addr addr) { - int name_type = question->name_type; - char *qname = question->name; - - if (!addr.s_addr) { - /* add the fail to WINS cache of names. give it 1 hour in the cache */ - DEBUG(3,("Negative DNS answer for %s\n", qname)); - add_netbios_entry(wins_subnet,qname,name_type,NB_ACTIVE,60*60,DNSFAIL,addr, - True, True); - return NULL; - } - - /* add it to our WINS cache of names. give it 2 hours in the cache */ - DEBUG(3,("DNS gave answer for %s of %s\n", qname, inet_ntoa(addr))); - - return add_netbios_entry(wins_subnet,qname,name_type,NB_ACTIVE,2*60*60,DNS,addr, - True,True); + int name_type = question->name_type; + char *qname = question->name; + + if (!addr.s_addr) { + /* add the fail to WINS cache of names. give it 1 hour in the cache */ + DEBUG(3,("Negative DNS answer for %s\n", qname)); + add_netbios_entry(wins_client_subnet,qname,name_type,NB_ACTIVE,60*60, + DNSFAIL,addr,True); + return NULL; + } + + /* add it to our WINS cache of names. give it 2 hours in the cache */ + DEBUG(3,("DNS gave answer for %s of %s\n", qname, inet_ntoa(addr))); + + return add_netbios_entry(wins_client_subnet,qname,name_type,NB_ACTIVE, + 2*60*60,DNS,addr, True); } diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 5feeb07c90..d53ec8c2e0 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -283,8 +283,8 @@ static void load_hosts_file(char *fname) ipaddr = *interpret_addr2(ip); d = find_subnet_all(ipaddr); if (d) { - add_netbios_entry(d,name,0x00,NB_ACTIVE,0,source,ipaddr,True,True); - add_netbios_entry(d,name,0x20,NB_ACTIVE,0,source,ipaddr,True,True); + add_netbios_entry(d,name,0x00,NB_ACTIVE,0,source,ipaddr,True); + add_netbios_entry(d,name,0x20,NB_ACTIVE,0,source,ipaddr,True); } } -- cgit From 87cada5fd33ea26cccb72454f97781e6e6c3254d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 1 Nov 1997 23:42:28 +0000 Subject: minor async DNS cleanups - start it earlier - set DEBUGLEVEL to -1 to prevent any debug calls in child - exit with _exit() to prevent logfile corruption (This used to be commit 21dd073a2003fa4707c1577a6b07bcef30eb6a50) --- source3/nmbd/asyncdns.c | 5 ++--- source3/nmbd/nmbd.c | 8 ++++---- 2 files changed, 6 insertions(+), 7 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 94fd65b147..4982f7f340 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -89,7 +89,7 @@ static void asyncdns_process(void) struct query_record r; fstring qname; - DEBUGLEVEL = 0; + DEBUGLEVEL = -1; while (1) { if (read_data(fd_in, (char *)&r, sizeof(r)) != sizeof(r)) @@ -103,7 +103,7 @@ static void asyncdns_process(void) break; } - exit(0); + _exit(0); } @@ -127,7 +127,6 @@ void start_async_dns(void) fd_out = fd2[1]; close(fd1[1]); close(fd2[0]); - DEBUG(3,("async DNS initialised\n")); return; } diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index d53ec8c2e0..696889c484 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -561,6 +561,10 @@ static void usage(char *pname) return -1; } +#ifndef SYNC_DNS + start_async_dns(); +#endif + if (!reload_services(False)) return(-1); @@ -590,10 +594,6 @@ static void usage(char *pname) become_daemon(); } -#ifndef SYNC_DNS - start_async_dns(); -#endif - if (*pidFile) { int fd; -- cgit From 4fe3b2ce751806e2add9c021c60c22d22fedbab5 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 2 Nov 1997 01:25:50 +0000 Subject: to avoid any possibility of the pipe getting full and blocking we now only allow one query in the async dns pipe at a time. The others are queued in the parent. (This used to be commit f1004dd52adb29d088f0725e2c940ed44d3a764f) --- source3/nmbd/asyncdns.c | 85 +++++++++++++++++++++++++++++++++---------------- 1 file changed, 58 insertions(+), 27 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 4982f7f340..a451f6b617 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -67,9 +67,11 @@ struct query_record { struct in_addr result; }; -/* a queue of pending requests waiting for DNS responses */ +/* a queue of pending requests waiting to be sent to the DNS child */ static struct packet_struct *dns_queue; +/* the packet currently being processed by the dns child */ +static struct packet_struct *dns_current; /*************************************************************************** @@ -140,20 +142,26 @@ void start_async_dns(void) /*************************************************************************** check if a particular name is already being queried ****************************************************************************/ -static BOOL query_in_queue(struct query_record *r) +static BOOL query_current(struct query_record *r) { - struct packet_struct *p; - for (p = dns_queue; p; p = p->next) { - struct nmb_packet *nmb = &p->packet.nmb; - struct nmb_name *question = &nmb->question.question_name; - - if (name_equal(question, &r->name)) - return True; - } - return False; + return dns_current && + name_equal(&r->name, + &dns_current->packet.nmb.question.question_name); } +/*************************************************************************** + write a query to the child process + ****************************************************************************/ +static BOOL write_child(struct packet_struct *p) +{ + struct query_record r; + + r.name = p->packet.nmb.question.question_name; + + return write_data(fd_out, (char *)&r, sizeof(r)) == sizeof(r); +} + /*************************************************************************** check the DNS queue ****************************************************************************/ @@ -173,6 +181,19 @@ void run_dns_queue(void) add_dns_result(&r.name, r.result); + if (dns_current) { + if (query_current(&r)) { + DEBUG(3,("DNS calling reply_name_query\n")); + in_dns = 1; + reply_name_query(dns_current); + in_dns = 0; + } + + dns_current->locked = False; + free_packet(dns_current); + dns_current = NULL; + } + /* loop over the whole dns queue looking for entries that match the result we just got */ for (p = dns_queue; p;) { @@ -200,6 +221,18 @@ void run_dns_queue(void) } } + if (dns_queue) { + dns_current = dns_queue; + dns_queue = dns_queue->next; + if (dns_queue) dns_queue->prev = NULL; + dns_current->next = NULL; + + if (!write_child(dns_current)) { + DEBUG(3,("failed to send DNS query to child!\n")); + return; + } + } + } /*************************************************************************** @@ -208,27 +241,25 @@ queue a DNS query BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, struct name_record **n) { - struct query_record r; - if (in_dns || fd_in == -1) return False; - r.name = *question; - - if (!query_in_queue(&r) && - !write_data(fd_out, (char *)&r, sizeof(r))) { - DEBUG(3,("failed to send DNS query to child!\n")); - return False; + if (!dns_current) { + if (!write_child(p)) { + DEBUG(3,("failed to send DNS query to child!\n")); + return False; + } + dns_current = p; + p->locked = True; + } else { + p->locked = True; + p->next = dns_queue; + p->prev = NULL; + if (p->next) + p->next->prev = p; + dns_queue = p; } - p->locked = True; - p->next = dns_queue; - p->prev = NULL; - if (p->next) - p->next->prev = p; - dns_queue = p; - - DEBUG(3,("added DNS query for %s\n", namestr(question))); return True; } -- cgit From d186100b661607e8f02274f03334dbd10f6df39d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 2 Nov 1997 01:33:28 +0000 Subject: fix comments (This used to be commit b3fd976b6c5c8342d04d87a7523864b09918d260) --- source3/nmbd/asyncdns.c | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index a451f6b617..3d1b3cc995 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -1,8 +1,7 @@ /* Unix SMB/Netbios implementation. - Version 1.9. a async DNS handler - Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Andrew Tridgell 1997 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,13 +16,7 @@ You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - - Revision History: - - 14 jan 96: lkcl@pires.co.uk - added multiple workgroup domain master support - -*/ + */ #include "includes.h" -- cgit From 5c3f9f4e2c7ab8e2190e2089dccfa01d1fd44f5e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 11 Nov 1997 00:48:42 +0000 Subject: auto-create the locks directory on startup (This used to be commit a0ab8fe54c27d9f25266c5abfd60458827500dfd) --- source3/nmbd/nmbd.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 696889c484..5067a7efc8 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -594,6 +594,10 @@ static void usage(char *pname) become_daemon(); } + if (!directory_exist(lp_lockdir(), NULL)) { + mkdir(lp_lockdir(), 0755); + } + if (*pidFile) { int fd; -- cgit From 4e92c7d1a3b543e48c2b09f8b78352a702c915aa Mon Sep 17 00:00:00 2001 From: John Terpstra Date: Fri, 21 Nov 1997 14:01:23 +0000 Subject: Added in mods for new smb.conf "remote browse sync" option as posted to the samba-1.9.17 tree moments ago. (This used to be commit 2ee25cd117a116d0304960780d6c197f39d25a3d) --- source3/nmbd/nmbd.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 5067a7efc8..1e4a2d9a79 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -312,6 +312,7 @@ static void process(void) announce_host(t); announce_master(t); announce_remote(t); + browse_sync_remote(t); query_refresh_names(t); -- cgit From c4aaa6bc3f7e8bd823f7279c78583384e7617d93 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 2 Dec 1997 19:00:18 +0000 Subject: asyncdns.c: Removed warning when compiling with -DSYNC_DNS. nameelect.c: Tidied up settings of work->ServerType when unbecoming things. nmbd.c: Fixed pidFile warning. server.c: Fixed pidFile warning. Jeremy. (This used to be commit 94d53dcac5d06e48be5cea9d54625da795f62d20) --- source3/nmbd/asyncdns.c | 1 - source3/nmbd/nmbd.c | 4 +++- 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 3d1b3cc995..c87e090754 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -266,7 +266,6 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, struct name_record **n) { - int name_type = question->name_type; char *qname = question->name; struct in_addr dns_ip; diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 1e4a2d9a79..a34e2caf42 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -465,7 +465,9 @@ static void usage(char *pname) int opt; extern FILE *dbf; extern char *optarg; - char pidFile[100] = { 0 }; + char pidFile[100]; + + *pidFile = '\0'; global_nmb_port = NMB_PORT; *host_file = 0; -- cgit From bb97a6adacefe2d01ed94a82c0d02801c7e884b1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 4 Dec 1997 08:10:49 +0000 Subject: allow for zero size reads in asyncdns. These can happen after a signal (This used to be commit 8bac91a6e7a3601b093cb64e9cb3bcc1663fb4d4) --- source3/nmbd/asyncdns.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index c87e090754..f15880080f 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -162,13 +162,16 @@ void run_dns_queue(void) { struct query_record r; struct packet_struct *p, *p2; + int size; if (fd_in == -1) return; - if (read_data(fd_in, (char *)&r, sizeof(r)) != sizeof(r)) { - DEBUG(0,("Incomplete DNS answer from child!\n")); - fd_in = -1; + if ((size=read_data(fd_in, (char *)&r, sizeof(r))) != sizeof(r)) { + if (size) { + DEBUG(0,("Incomplete DNS answer from child!\n")); + fd_in = -1; + } return; } -- cgit From 00fc025b93171750cb44a409f9c179d4beba004b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 4 Dec 1997 10:58:40 +0000 Subject: catch signals in the async dns daemon and allow it to auto-restart if necessary (This used to be commit fa599067f074647a5bad2ffd0fce12ae0a4e43d2) --- source3/nmbd/asyncdns.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index f15880080f..57d0eda9b3 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -128,6 +128,10 @@ void start_async_dns(void) fd_in = fd2[0]; fd_out = fd1[1]; + signal(SIGUSR2, SIG_IGN); + signal(SIGUSR1, SIG_IGN); + signal(SIGHUP, SIG_IGN); + asyncdns_process(); } @@ -167,6 +171,11 @@ void run_dns_queue(void) if (fd_in == -1) return; + if (!process_exists(child_pid)) { + close(fd_in); + start_async_dns(); + } + if ((size=read_data(fd_in, (char *)&r, sizeof(r))) != sizeof(r)) { if (size) { DEBUG(0,("Incomplete DNS answer from child!\n")); -- cgit From 64f0348a3f994334abe64a4d4896109c3c8c9039 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 13 Dec 1997 14:16:07 +0000 Subject: This is it ! The mega-merge of the JRA_NMBD_REWRITE branch back into the main tree. For the cvs logs of all the files starting nmbd_*.c, look in the JRA_NMBD_REWRITE branch. That branch has now been discontinued. Jeremy. (This used to be commit d80b0cb645f81d16734929a0b27a91c6650499bb) --- source3/nmbd/asyncdns.c | 64 +- source3/nmbd/nmbd.c | 811 ++++++++------- source3/nmbd/nmbd_become_dmb.c | 471 +++++++++ source3/nmbd/nmbd_become_lmb.c | 534 ++++++++++ source3/nmbd/nmbd_browserdb.c | 184 ++++ source3/nmbd/nmbd_browsesync.c | 458 +++++++++ source3/nmbd/nmbd_elections.c | 348 +++++++ source3/nmbd/nmbd_incomingdgrams.c | 625 ++++++++++++ source3/nmbd/nmbd_incomingrequests.c | 556 +++++++++++ source3/nmbd/nmbd_lmhosts.c | 168 ++++ source3/nmbd/nmbd_logonnames.c | 166 +++ source3/nmbd/nmbd_mynames.c | 165 +++ source3/nmbd/nmbd_namelistdb.c | 586 +++++++++++ source3/nmbd/nmbd_namequery.c | 234 +++++ source3/nmbd/nmbd_nameregister.c | 390 ++++++++ source3/nmbd/nmbd_namerelease.c | 238 +++++ source3/nmbd/nmbd_nodestatus.c | 99 ++ source3/nmbd/nmbd_packets.c | 1775 +++++++++++++++++++++++++++++++++ source3/nmbd/nmbd_processlogon.c | 250 +++++ source3/nmbd/nmbd_responserecordsdb.c | 238 +++++ source3/nmbd/nmbd_sendannounce.c | 477 +++++++++ source3/nmbd/nmbd_serverlistdb.c | 454 +++++++++ source3/nmbd/nmbd_subnetdb.c | 291 ++++++ source3/nmbd/nmbd_winsproxy.c | 195 ++++ source3/nmbd/nmbd_winsserver.c | 1565 +++++++++++++++++++++++++++++ source3/nmbd/nmbd_workgroupdb.c | 356 +++++++ 26 files changed, 11318 insertions(+), 380 deletions(-) create mode 100644 source3/nmbd/nmbd_become_dmb.c create mode 100644 source3/nmbd/nmbd_become_lmb.c create mode 100644 source3/nmbd/nmbd_browserdb.c create mode 100644 source3/nmbd/nmbd_browsesync.c create mode 100644 source3/nmbd/nmbd_elections.c create mode 100644 source3/nmbd/nmbd_incomingdgrams.c create mode 100644 source3/nmbd/nmbd_incomingrequests.c create mode 100644 source3/nmbd/nmbd_lmhosts.c create mode 100644 source3/nmbd/nmbd_logonnames.c create mode 100644 source3/nmbd/nmbd_mynames.c create mode 100644 source3/nmbd/nmbd_namelistdb.c create mode 100644 source3/nmbd/nmbd_namequery.c create mode 100644 source3/nmbd/nmbd_nameregister.c create mode 100644 source3/nmbd/nmbd_namerelease.c create mode 100644 source3/nmbd/nmbd_nodestatus.c create mode 100644 source3/nmbd/nmbd_packets.c create mode 100644 source3/nmbd/nmbd_processlogon.c create mode 100644 source3/nmbd/nmbd_responserecordsdb.c create mode 100644 source3/nmbd/nmbd_sendannounce.c create mode 100644 source3/nmbd/nmbd_serverlistdb.c create mode 100644 source3/nmbd/nmbd_subnetdb.c create mode 100644 source3/nmbd/nmbd_winsproxy.c create mode 100644 source3/nmbd/nmbd_winsserver.c create mode 100644 source3/nmbd/nmbd_workgroupdb.c (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 57d0eda9b3..1ee9dab065 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -22,28 +22,29 @@ extern int DEBUGLEVEL; - /*************************************************************************** - add a DNS result to the name cache - ****************************************************************************/ + Add a DNS result to the name cache. +****************************************************************************/ + static struct name_record *add_dns_result(struct nmb_name *question, struct in_addr addr) { int name_type = question->name_type; char *qname = question->name; - + + if (!addr.s_addr) { /* add the fail to WINS cache of names. give it 1 hour in the cache */ - DEBUG(3,("Negative DNS answer for %s\n", qname)); - add_netbios_entry(wins_client_subnet,qname,name_type,NB_ACTIVE,60*60, - DNSFAIL,addr,True); + DEBUG(3,("add_dns_result: Negative DNS answer for %s\n", qname)); + add_name_to_subnet(wins_server_subnet,qname,name_type, + NB_ACTIVE, 60*60, DNSFAIL_NAME, 1, &addr); return NULL; } /* add it to our WINS cache of names. give it 2 hours in the cache */ - DEBUG(3,("DNS gave answer for %s of %s\n", qname, inet_ntoa(addr))); + DEBUG(3,("add_dns_result: DNS gave answer for %s of %s\n", qname, inet_ntoa(addr))); - return add_netbios_entry(wins_client_subnet,qname,name_type,NB_ACTIVE, - 2*60*60,DNS,addr, True); + return add_name_to_subnet(wins_server_subnet,qname,name_type, + NB_ACTIVE, 2*60*60, DNS_NAME, 1, &addr); } @@ -101,6 +102,23 @@ static void asyncdns_process(void) _exit(0); } +/**************************************************************************** ** + catch a sigterm + We need a separate term handler here so we don't release any + names that our parent is going to release, or overwrite a + WINS db that our parent is going to write. + **************************************************************************** */ + +static int sig_term() +{ + BlockSignals(True,SIGTERM); + + DEBUG(0,("async dns child. Got SIGTERM: going down...\n")); + + exit(0); + /* Keep compiler happy.. */ + return 0; +} /*************************************************************************** create a child process to handle DNS lookups @@ -131,6 +149,7 @@ void start_async_dns(void) signal(SIGUSR2, SIG_IGN); signal(SIGUSR1, SIG_IGN); signal(SIGHUP, SIG_IGN); + signal( SIGTERM, SIGNAL_CAST sig_term ); asyncdns_process(); } @@ -142,7 +161,7 @@ check if a particular name is already being queried static BOOL query_current(struct query_record *r) { return dns_current && - name_equal(&r->name, + nmb_name_equal(&r->name, &dns_current->packet.nmb.question.question_name); } @@ -166,6 +185,7 @@ void run_dns_queue(void) { struct query_record r; struct packet_struct *p, *p2; + struct name_record *namerec; int size; if (fd_in == -1) @@ -184,13 +204,16 @@ void run_dns_queue(void) return; } - add_dns_result(&r.name, r.result); + namerec = add_dns_result(&r.name, r.result); if (dns_current) { if (query_current(&r)) { - DEBUG(3,("DNS calling reply_name_query\n")); + DEBUG(3,("DNS calling send_wins_name_query_response\n")); in_dns = 1; - reply_name_query(dns_current); + if(namerec == NULL) + send_wins_name_query_response(NAM_ERR, dns_current, NULL); + else + send_wins_name_query_response(0,dns_current,namerec); in_dns = 0; } @@ -205,10 +228,13 @@ void run_dns_queue(void) struct nmb_packet *nmb = &p->packet.nmb; struct nmb_name *question = &nmb->question.question_name; - if (name_equal(question, &r.name)) { - DEBUG(3,("DNS calling reply_name_query\n")); + if (nmb_name_equal(question, &r.name)) { + DEBUG(3,("DNS calling send_wins_name_query_response\n")); in_dns = 1; - reply_name_query(p); + if(namerec == NULL) + send_wins_name_query_response(NAM_ERR, p, NULL); + else + send_wins_name_query_response(0,p,namerec); in_dns = 0; p->locked = False; @@ -286,6 +312,10 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, dns_ip.s_addr = interpret_addr(qname); *n = add_dns_result(question, dns_ip); + if(*n == NULL) + send_wins_name_query_response(NAM_ERR, p, NULL); + else + send_wins_name_query_response(0, p, *n); return False; } #endif diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index a34e2caf42..11cd50cd76 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -34,8 +34,8 @@ pstring servicesf = CONFIGFILE; extern pstring scope; -int ClientNMB = -1; -int ClientDGRAM = -1; +int ClientNMB = -1; +int ClientDGRAM = -1; int global_nmb_port = -1; extern pstring myhostname; @@ -49,47 +49,47 @@ static BOOL is_daemon = False; /* what server type are we currently */ -time_t StartupTime =0; +time_t StartupTime = 0; extern struct in_addr ipzero; - /**************************************************************************** +/**************************************************************************** ** catch a sigterm - ****************************************************************************/ + **************************************************************************** */ static int sig_term() { BlockSignals(True,SIGTERM); DEBUG(0,("Got SIGTERM: going down...\n")); - /* write out wins.dat file if samba is a WINS server */ - dump_names(); + /* Write out wins.dat file if samba is a WINS server */ + wins_write_database(); - /* remove all samba names, with wins server if necessary. */ - remove_my_names(); + /* Remove all SELF registered names. */ + release_my_names(); - /* announce all server entries as 0 time-to-live, 0 type */ - /* XXXX don't care if we never receive a response back... yet */ + /* Announce all server entries as 0 time-to-live, 0 type. */ announce_my_servers_removed(); - /* XXXX other things: if we are a master browser, force an election? */ - exit(0); /* Keep compiler happy.. */ return 0; -} +} /* sig_term */ -/**************************************************************************** -catch a sighup -****************************************************************************/ +/**************************************************************************** ** + catch a sighup + **************************************************************************** */ static int sig_hup(void) { - BlockSignals(True,SIGHUP); + BlockSignals( True, SIGHUP ); + + DEBUG( 0, ( "Got SIGHUP dumping debug info.\n" ) ); + + write_browse_list( 0, True ); - DEBUG(0,("Got SIGHUP (reload not implemented)\n")); - dump_names(); - reload_services(True); + dump_all_namelists(); + reload_services( True ); set_samba_nb_type(); @@ -98,239 +98,294 @@ static int sig_hup(void) signal(SIGHUP,SIGNAL_CAST sig_hup); #endif return(0); -} +} /* sig_hup */ -/**************************************************************************** -catch a sigpipe -****************************************************************************/ +/**************************************************************************** ** + catch a sigpipe + **************************************************************************** */ static int sig_pipe(void) { - BlockSignals(True,SIGPIPE); + BlockSignals( True, SIGPIPE ); - DEBUG(0,("Got SIGPIPE\n")); - if (!is_daemon) + DEBUG( 0, ("Got SIGPIPE\n") ); + if ( !is_daemon ) exit(1); - BlockSignals(False,SIGPIPE); + BlockSignals( False, SIGPIPE ); return(0); -} +} /* sig_pipe */ #if DUMP_CORE -/******************************************************************* -prepare to dump a core file - carefully! -********************************************************************/ +/**************************************************************************** ** + prepare to dump a core file - carefully! + **************************************************************************** */ static BOOL dump_core(void) { char *p; pstring dname; - pstrcpy(dname,debugf); - if ((p=strrchr(dname,'/'))) *p=0; - strcat(dname,"/corefiles"); - mkdir(dname,0700); - sys_chown(dname,getuid(),getgid()); - chmod(dname,0700); - if (chdir(dname)) return(False); - umask(~(0700)); + pstrcpy( dname, debugf ); + if ((p=strrchr(dname,'/'))) + *p=0; + strcat( dname, "/corefiles" ); + mkdir( dname, 0700 ); + sys_chown( dname, getuid(), getgid() ); + chmod( dname, 0700 ); + if ( chdir(dname) ) + return( False ); + umask( ~(0700) ); #ifndef NO_GETRLIMIT #ifdef RLIMIT_CORE { struct rlimit rlp; - getrlimit(RLIMIT_CORE, &rlp); - rlp.rlim_cur = MAX(4*1024*1024,rlp.rlim_cur); - setrlimit(RLIMIT_CORE, &rlp); - getrlimit(RLIMIT_CORE, &rlp); - DEBUG(3,("Core limits now %d %d\n",rlp.rlim_cur,rlp.rlim_max)); + getrlimit( RLIMIT_CORE, &rlp ); + rlp.rlim_cur = MAX( 4*1024*1024, rlp.rlim_cur ); + setrlimit( RLIMIT_CORE, &rlp ); + getrlimit( RLIMIT_CORE, &rlp ); + DEBUG( 3, ( "Core limits now %d %d\n", rlp.rlim_cur, rlp.rlim_max ) ); } #endif #endif - DEBUG(0,("Dumping core in %s\n",dname)); - return(True); -} + DEBUG( 0, ( "Dumping core in %s\n",dname ) ); + return( True ); +} /* dump_core */ #endif -/**************************************************************************** -possibly continue after a fault -****************************************************************************/ +/**************************************************************************** ** + possibly continue after a fault + **************************************************************************** */ static void fault_continue(void) { #if DUMP_CORE dump_core(); #endif -} +} /* fault_continue */ -/******************************************************************* - expire old names from the namelist and server list - ******************************************************************/ +/**************************************************************************** ** + expire old names from the namelist and server list + **************************************************************************** */ static void expire_names_and_servers(time_t t) { static time_t lastrun = 0; - if (!lastrun) lastrun = t; - if (t < lastrun + 5) return; + if ( !lastrun ) + lastrun = t; + if ( t < (lastrun + 5) ) + return; lastrun = t; - + + /* + * Expire any timed out names on all the broadcast + * subnets and those registered with the WINS server. + * (nmbd_namelistdb.c) + */ expire_names(t); - expire_servers(t); -} -/***************************************************************************** + /* + * Go through all the broadcast subnets and for each + * workgroup known on that subnet remove any expired + * server names. If a workgroup has an empty serverlist + * and has itself timed out then remove the workgroup. + * (nmbd_workgroupdb.c) + */ + expire_workgroups_and_servers(t); +} /* expire_names_and_servers */ + +/**************************************************************************** ** reload the services file - **************************************************************************/ + **************************************************************************** */ BOOL reload_services(BOOL test) { BOOL ret; extern fstring remote_machine; - strcpy(remote_machine,"nmbd"); + strcpy( remote_machine, "nmbd" ); - if (lp_loaded()) + if ( lp_loaded() ) + { + pstring fname; + pstrcpy( fname,lp_configfile()); + if (file_exist(fname,NULL) && !strcsequal(fname,servicesf)) { - pstring fname; - pstrcpy(fname,lp_configfile()); - if (file_exist(fname,NULL) && !strcsequal(fname,servicesf)) - { - pstrcpy(servicesf,fname); - test = False; - } + pstrcpy(servicesf,fname); + test = False; } + } - if (test && !lp_file_list_changed()) + if ( test && !lp_file_list_changed() ) return(True); - ret = lp_load(servicesf,True); + ret = lp_load( servicesf, True ); /* perhaps the config filename is now set */ - if (!test) { - DEBUG(3,("services not loaded\n")); - reload_services(True); + if ( !test ) + { + DEBUG( 3, ( "services not loaded\n" ) ); + reload_services( True ); } /* Do a sanity check for a misconfigured nmbd */ - if(lp_wins_support() && *lp_wins_server()) { + if( lp_wins_support() && *lp_wins_server() ) + { DEBUG(0,("ERROR: both 'wins support = true' and 'wins server = ' \ cannot be set in the smb.conf file. nmbd aborting.\n")); exit(10); } return(ret); -} - - - -/**************************************************************************** -load a netbios hosts file -****************************************************************************/ -static void load_hosts_file(char *fname) -{ - FILE *f = fopen(fname,"r"); - pstring line; - if (!f) { - DEBUG(2,("Can't open lmhosts file %s\n",fname)); - return; - } - - while (!feof(f)) - { - pstring ip,name,flags,extra; - struct subnet_record *d; - char *ptr; - int count = 0; - struct in_addr ipaddr; - enum name_source source = LMHOSTS; - - if (!fgets_slash(line,sizeof(pstring),f)) continue; - - if (*line == '#') continue; - - strcpy(ip,""); - strcpy(name,""); - strcpy(flags,""); - - ptr = line; - - if (next_token(&ptr,ip ,NULL)) ++count; - if (next_token(&ptr,name ,NULL)) ++count; - if (next_token(&ptr,flags,NULL)) ++count; - if (next_token(&ptr,extra,NULL)) ++count; - - if (count <= 0) continue; - - if (count > 0 && count < 2) { - DEBUG(0,("Ill formed hosts line [%s]\n",line)); - continue; - } - - if (count >= 4) { - DEBUG(0,("too many columns in %s (obsolete syntax)\n",fname)); - continue; - } - - DEBUG(4, ("lmhost entry: %s %s %s\n", ip, name, flags)); - - if (strchr(flags,'G') || strchr(flags,'S')) { - DEBUG(0,("group flag in %s ignored (obsolete)\n",fname)); - continue; - } - - if (strchr(flags,'M')) { - source = SELF; - pstrcpy(myname,name); - } - - ipaddr = *interpret_addr2(ip); - d = find_subnet_all(ipaddr); - if (d) { - add_netbios_entry(d,name,0x00,NB_ACTIVE,0,source,ipaddr,True); - add_netbios_entry(d,name,0x20,NB_ACTIVE,0,source,ipaddr,True); - } - } - - fclose(f); -} +} /* reload_services */ - -/**************************************************************************** - The main select loop. - ***************************************************************************/ +/**************************************************************************** ** + The main select loop. + **************************************************************************** */ static void process(void) { BOOL run_election; - while (True) - { - time_t t = time(NULL); - run_election = check_elections(); - if(listen_for_packets(run_election)) - return; - - run_packet_queue(); - run_elections(t); - - announce_host(t); - announce_master(t); - announce_remote(t); - browse_sync_remote(t); - - query_refresh_names(t); - - expire_names_and_servers(t); - expire_netbios_response_entries(t); - refresh_my_names(t); - - write_browse_list(t); - do_browser_lists(t); - check_master_browser(t); - add_domain_names(t); - } -} + while( True ) + { + time_t t = time(NULL); + + /* + * Check all broadcast subnets to see if + * we need to run an election on any of them. + * (nmbd_elections.c) + */ + run_election = check_elections(); + + /* + * Read incoming UDP packets. + * (nmbd_packets.c) + */ + if(listen_for_packets(run_election)) + return; + + /* + * Process all incoming packets + * read above. This calls the success and + * failure functions registered when response + * packets arrrive, and also deals with request + * packets from other sources. + * (nmbd_packets.c) + */ + run_packet_queue(); + + /* + * Run any elections - initiate becoming + * a local master browser if we have won. + * (nmbd_elections.c) + */ + run_elections(t); + + /* + * Send out any broadcast announcements + * of our server names. This also announces + * the workgroup name if we are a local + * master browser. + * (nmbd_sendannounce.c) + */ + announce_my_server_names(t); + + /* + * If we are a local master browser, periodically + * announce ourselves to the domain master browser. + * This also deals with syncronising the domain master + * browser server lists with ourselves as a local + * master browser. + * (nmbd_sendannounce.c) + */ + announce_myself_to_domain_master_browser(t); + + /* + * Fullfill any remote announce requests. + * (nmbd_sendannounce.c) + */ + announce_remote(t); + + /* + * Fullfill any remote browse sync announce requests. + * (nmbd_sendannounce.c) + */ + browse_sync_remote(t); + + /* + * Scan the broadcast subnets, and WINS client + * namelists and refresh any that need refreshing. + * (nmbd_mynames.c) + */ + refresh_my_names(t); + + /* + * Scan the subnet namelists and server lists and + * expire thos that have timed out. + * (nmbd.c) + */ + expire_names_and_servers(t); + + /* + * Write out a snapshot of our current browse list into + * the browse.dat file. This is used by smbd to service + * incoming NetServerEnum calls - used to synchronise + * browse lists over subnets. + * (nmbd_serverlistdb.c) + */ + write_browse_list(t, False); + + /* + * If we are a domain master browser, we have a list of + * local master browsers we should synchronise browse + * lists with (these are added by an incoming local + * master browser announcement packet). Expire any of + * these that are no longer current, and pull the server + * lists from each of these known local master browsers. + * (nmbd_browsesync.c) + */ + dmb_expire_and_sync_browser_lists(t); + + /* + * Check that there is a local master browser for our + * workgroup for all our broadcast subnets. If one + * is not found, start an election (which we ourselves + * may or may not participate in, depending on the + * setting of the 'local master' parameter. + * (nmbd_elections.c) + */ + check_master_browser_exists(t); + + /* + * If we are configured as a logon server, attempt to + * register the special NetBIOS names to become such + * (WORKGROUP<1c> name) on all broadcast subnets and + * with the WINS server (if used). If we are configured + * to become a domain master browser, attempt to register + * the special NetBIOS name (WORKGROUP<1b> name) to + * become such. + * (nmbd_become_dmb.c) + */ + add_domain_names(t); + + /* + * If we are a WINS server, do any timer dependent + * processing required. + * (nmbd_winsserver.c) + */ + initiate_wins_processing(t); + + /* + * Go through the repsonse record queue and time out or re-transmit + * and expired entries. + * (nmbd_packets.c) + */ + retransmit_or_expire_response_records(t); + } +} /* process */ -/**************************************************************************** - open the socket communication -****************************************************************************/ +/**************************************************************************** ** + open the socket communication + **************************************************************************** */ static BOOL open_sockets(BOOL isdaemon, int port) { /* The sockets opened here will be used to receive broadcast @@ -340,29 +395,29 @@ static BOOL open_sockets(BOOL isdaemon, int port) now deprecated. */ - if (isdaemon) + if ( isdaemon ) ClientNMB = open_socket_in(SOCK_DGRAM, port,0,0); else ClientNMB = 0; ClientDGRAM = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3,0); - if (ClientNMB == -1) - return(False); + if ( ClientNMB == -1 ) + return( False ); - signal(SIGPIPE, SIGNAL_CAST sig_pipe); + signal( SIGPIPE, SIGNAL_CAST sig_pipe ); - set_socket_options(ClientNMB,"SO_BROADCAST"); - set_socket_options(ClientDGRAM,"SO_BROADCAST"); + set_socket_options( ClientNMB, "SO_BROADCAST" ); + set_socket_options( ClientDGRAM, "SO_BROADCAST" ); - DEBUG(3,("open_sockets: Broadcast sockets opened.\n")); - return True; -} + DEBUG( 3, ( "open_sockets: Broadcast sockets opened.\n" ) ); + return( True ); +} /* open_sockets */ -/**************************************************************************** - initialise connect, service and file structs -****************************************************************************/ +/**************************************************************************** ** + initialise connect, service and file structs + **************************************************************************** */ static BOOL init_structs() { extern fstring local_machine; @@ -372,102 +427,108 @@ static BOOL init_structs() int nodup; pstring nbname; - if (! *myname) { - fstrcpy(myname,myhostname); - p = strchr(myname,'.'); - if (p) *p = 0; + if (! *myname) + { + fstrcpy( myname, myhostname ); + p = strchr( myname, '.' ); + if (p) + *p = 0; } - strupper(myname); + strupper( myname ); /* Add any NETBIOS name aliases. Ensure that the first entry - is equal to myname. */ + is equal to myname. + */ /* Work out the max number of netbios aliases that we have */ - ptr=lp_netbios_aliases(); - for (namecount=0; next_token(&ptr,nbname,NULL); namecount++) + ptr = lp_netbios_aliases(); + for( namecount=0; next_token(&ptr,nbname,NULL); namecount++ ) ; - if (*myname) - namecount++; + if ( *myname ) + namecount++; /* Allocate space for the netbios aliases */ - if((my_netbios_names=(char **)malloc(sizeof(char *)*(namecount+1))) == NULL) + my_netbios_names = (char **)malloc( sizeof(char *) * (namecount+1) ); + if( NULL == my_netbios_names ) { - DEBUG(0,("init_structs: malloc fail.\n")); - return False; + DEBUG( 0, ( "init_structs: malloc fail.\n" ) ); + return( False ); } /* Use the myname string first */ namecount=0; - if (*myname) + if ( *myname ) my_netbios_names[namecount++] = myname; - ptr=lp_netbios_aliases(); - while (next_token(&ptr,nbname,NULL)) { - strupper(nbname); + ptr = lp_netbios_aliases(); + while ( next_token( &ptr, nbname, NULL ) ) + { + strupper( nbname ); /* Look for duplicates */ nodup=1; - for(n=0; n 1 && (*argv[1] != '-')) { + while (argc > 1 && (*argv[1] != '-')) + { argv++; argc--; } - fault_setup(fault_continue); + fault_setup( fault_continue ); - signal(SIGHUP ,SIGNAL_CAST sig_hup); - signal(SIGTERM,SIGNAL_CAST sig_term); + signal( SIGHUP, SIGNAL_CAST sig_hup ); + signal( SIGTERM, SIGNAL_CAST sig_term ); - while ((opt = getopt(argc, argv, "as:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:f:")) != EOF) + while((opt = getopt(argc, argv, "as:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:f:")) != EOF) { switch (opt) - { + { case 'f': strncpy(pidFile, optarg, sizeof(pidFile)); break; - case 's': - pstrcpy(servicesf,optarg); - break; - case 'N': - case 'B': - case 'I': - case 'C': - case 'G': - DEBUG(0,("Obsolete option '%c' used\n",opt)); - break; - case 'H': - pstrcpy(host_file,optarg); - break; - case 'n': - pstrcpy(myname,optarg); - strupper(myname); - break; - case 'l': - sprintf(debugf,"%s.nmb",optarg); - break; - case 'i': - pstrcpy(scope,optarg); - strupper(scope); - break; - case 'a': - { - extern BOOL append_log; - append_log = !append_log; - } - break; - case 'D': - is_daemon = True; - break; - case 'd': - DEBUGLEVEL = atoi(optarg); - break; - case 'p': - global_nmb_port = atoi(optarg); - break; - case 'h': - usage(argv[0]); - exit(0); - break; - default: - if (!is_a_socket(0)) { - usage(argv[0]); - } - break; - } + case 's': + pstrcpy(servicesf,optarg); + break; + case 'N': + case 'B': + case 'I': + case 'C': + case 'G': + DEBUG(0,("Obsolete option '%c' used\n",opt)); + break; + case 'H': + pstrcpy(host_file,optarg); + break; + case 'n': + pstrcpy(myname,optarg); + strupper(myname); + break; + case 'l': + sprintf(debugf,"%s.nmb",optarg); + break; + case 'i': + pstrcpy(scope,optarg); + strupper(scope); + break; + case 'a': + { + extern BOOL append_log; + append_log = !append_log; + } + break; + case 'D': + is_daemon = True; + break; + case 'd': + DEBUGLEVEL = atoi(optarg); + break; + case 'p': + global_nmb_port = atoi(optarg); + break; + case 'h': + usage(argv[0]); + exit(0); + break; + default: + if (!is_a_socket(0)) + { + usage(argv[0]); + } + break; + } } DEBUG(1,("%s netbios nameserver version %s started\n",timestring(),VERSION)); DEBUG(1,("Copyright Andrew Tridgell 1994-1997\n")); - if(!get_myname(myhostname,NULL)) + if( !get_myname( myhostname, NULL) ) { DEBUG(0,("Unable to get my hostname - exiting.\n")); return -1; } -#ifndef SYNC_DNS - start_async_dns(); -#endif - - if (!reload_services(False)) - return(-1); + if ( !reload_services(False) ) + return(-1); codepage_initialise(lp_client_code_page()); if(!init_structs()) return -1; - reload_services(True); + reload_services( True ); - pstrcpy(myworkgroup, lp_workgroup()); + fstrcpy( myworkgroup, lp_workgroup() ); - if (strequal(myworkgroup,"*")) { + if (strequal(myworkgroup,"*")) + { DEBUG(0,("ERROR: a workgroup name of * is no longer supported\n")); exit(1); } set_samba_nb_type(); - if (!is_daemon && !is_a_socket(0)) { + if (!is_daemon && !is_a_socket(0)) + { DEBUG(0,("standard input is not a socket, assuming -D option\n")); is_daemon = True; } - if (is_daemon) { + if (is_daemon) + { DEBUG(2,("%s becoming a daemon\n",timestring())); become_daemon(); } - if (!directory_exist(lp_lockdir(), NULL)) { - mkdir(lp_lockdir(), 0755); + if (!directory_exist(lp_lockdir(), NULL)) + { + mkdir(lp_lockdir(), 0755); } if (*pidFile) - { - int fd; - char buf[20]; + { + int fd; + char buf[20]; - if ((fd = open(pidFile, #ifdef O_NONBLOCK - O_NONBLOCK | + fd = open( pidFile, O_NONBLOCK | O_CREAT | O_WRONLY | O_TRUNC, 0644 ); +#else + fd = open( pidFile, O_CREAT | O_WRONLY | O_TRUNC, 0644 ); #endif - O_CREAT | O_WRONLY | O_TRUNC, 0644)) < 0) - { - DEBUG(0,("ERROR: can't open %s: %s\n", pidFile, strerror(errno))); - exit(1); - } - if (fcntl_lock(fd,F_SETLK,0,1,F_WRLCK)==False) - { - DEBUG(0,("ERROR: nmbd is already running\n")); - exit(1); - } - sprintf(buf, "%u\n", (unsigned int) getpid()); - if (write(fd, buf, strlen(buf)) < 0) - { - DEBUG(0,("ERROR: can't write to %s: %s\n", pidFile, strerror(errno))); - exit(1); - } - /* Leave pid file open & locked for the duration... */ + if ( fd < 0 ) + { + DEBUG(0,("ERROR: can't open %s: %s\n", pidFile, strerror(errno))); + exit(1); } + if (fcntl_lock(fd,F_SETLK,0,1,F_WRLCK)==False) + { + DEBUG(0,("ERROR: nmbd is already running\n")); + exit(1); + } + sprintf(buf, "%u\n", (unsigned int) getpid()); + if (write(fd, buf, strlen(buf)) < 0) + { + DEBUG(0,("ERROR: can't write to %s: %s\n", pidFile, strerror(errno))); + exit(1); + } + /* Leave pid file open & locked for the duration... */ + } - DEBUG(3,("Opening sockets %d\n", global_nmb_port)); + DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); - if (!open_sockets(is_daemon,global_nmb_port)) return 1; + if ( !open_sockets( is_daemon, global_nmb_port ) ) + return 1; + /* Determine all the IP addresses we have. */ load_interfaces(); - add_my_subnets(myworkgroup); - - add_my_names(); - DEBUG(3,("Checked names\n")); - - load_netbios_names(); - - DEBUG(3,("Loaded names\n")); + /* Create an nmbd subnet record for each of the above. */ + if( False == create_subnets() ) + { + DEBUG(0,("ERROR: Failed when creating subnet lists. Exiting.\n")); + exit(1); + } - if (*host_file) { - load_hosts_file(host_file); + /* Load in any static local names. */ + if ( *host_file ) + { + load_lmhosts_file(host_file); DEBUG(3,("Loaded hosts file\n")); } - write_browse_list(time(NULL)); + /* If we are acting as a WINS server, initialise data structures. */ + if( !initialise_wins() ) + { + DEBUG( 0, ( "nmbd: Failed when initialising WINS server.\n" ) ); + exit(1); + } - DEBUG(3,("Dumped names\n")); + /* + * Register nmbd primary workgroup and nmbd names on all + * the broadcast subnets, and on the WINS server (if specified). + * Also initiate the startup of our primary workgroup (start + * elections if we are setup as being able to be a local + * master browser. + */ + + if( False == register_my_workgroup_and_names() ) + { + DEBUG(0,("ERROR: Failed when creating my my workgroup. Exiting.\n")); + exit(1); + } /* We can only take sigterm signals in the select. */ - BlockSignals(True,SIGTERM); + BlockSignals( True, SIGTERM ); process(); close_sockets(); @@ -663,4 +746,6 @@ static void usage(char *pname) if (dbf) fclose(dbf); return(0); -} +} /* main */ + +/* ========================================================================== */ diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c new file mode 100644 index 0000000000..37fceb9bf1 --- /dev/null +++ b/source3/nmbd/nmbd_become_dmb.c @@ -0,0 +1,471 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1994-1997 + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; + +extern pstring scope; +extern pstring myname; +extern fstring myworkgroup; +extern char **my_netbios_names; +extern struct in_addr ipzero; +extern struct in_addr allones_ip; + +extern uint16 samba_nb_type; /* Samba's NetBIOS type. */ + +static void become_domain_master_browser_bcast(char *); + +/******************************************************************* + Unbecome a domain master browser - name release success function. + ******************************************************************/ + +static void unbecome_dmb_success(struct subnet_record *subrec, + struct userdata_struct *userdata, + struct nmb_name *released_name, + struct in_addr released_ip) +{ + struct work_record *work = find_workgroup_on_subnet(subrec, released_name->name); + struct server_record *servrec; + + if(!work) + { + DEBUG(0,("unbecome_dmb_success: Cannot find workgroup %s on subnet %s\n", + released_name->name, subrec->subnet_name)); + return; + } + + if((servrec = find_server_in_workgroup( work, myname)) == NULL) + { + DEBUG(0,("unbecome_dmb_success: Error - cannot find server %s \ +in workgroup %s on subnet %s\n", + myname, released_name->name, subrec->subnet_name)); + return; + } + + /* Set the state in the workgroup structure. */ + work->dom_state = DOMAIN_NONE; + + /* Update our server status. */ + servrec->serv.type &= ~SV_TYPE_DOMAIN_MASTER; + + /* Tell the namelist writer to write out a change. */ + subrec->work_changed = True; + + /* Remove any list of local master browsers we are syncing with. */ + remove_workgroup_lmb_browsers(released_name->name); + + /* Delete the known domain master browser name from the workgroup + struct. */ + bzero((char *)&work->dmb_name, sizeof(work->dmb_name)); + putip((char *)&work->dmb_addr, &ipzero); + + DEBUG(0,("\n ***** Samba server %s has stopped being a domain master browser \ +for workgroup %s on subnet %s *****\n\n", myname, work->work_group, subrec->subnet_name)); + +} + +/******************************************************************* + Unbecome a domain master browser - name release fail function. + ******************************************************************/ + +static void unbecome_dmb_fail(struct subnet_record *subrec, + struct response_record *rrec, + struct nmb_name *released_name) +{ + DEBUG(0,("unbecome_dmb_fail: Failed to unbecome domain master browser for \ +workgroup %s on subnet %s.\n", released_name->name, subrec->subnet_name)); +} + +/******************************************************************* + Unbecome a domain master browser. + ******************************************************************/ + +void unbecome_domain_master(char *workgroup_name) +{ + struct subnet_record *subrec; + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) + { + struct work_record *work = find_workgroup_on_subnet(subrec, workgroup_name); + + if(work && (work->dom_state == DOMAIN_MST)) + { + struct name_record *namerec; + struct nmb_name nmbname; + make_nmb_name(&nmbname,workgroup_name,0x1b,scope); + + /* We can only do this if we are a domain master already. */ + DEBUG(2,("unbecome_domain_master: attempting to stop being a domain \ +master browser for workgroup %s on subnet %s\n", + work->work_group, subrec->subnet_name)); + + /* Find the WORKGROUP<1b> name on the subnet namelist. */ + if((namerec = find_name_on_subnet(subrec, &nmbname, FIND_SELF_NAME))==NULL) + { + DEBUG(0,("unbecome_domain_master: Cannot find name %s on subnet %s.\n", + namestr(&nmbname), subrec->subnet_name)); + continue; + } + release_name(subrec, namerec, + unbecome_dmb_success, + unbecome_dmb_fail, + NULL); + } + } +} + +/**************************************************************************** + Fail to become a Domain Master Browser on a subnet. + ****************************************************************************/ + +static void become_domain_master_fail(struct subnet_record *subrec, + struct response_record *rrec, + struct nmb_name *fail_name) +{ + struct work_record *work = find_workgroup_on_subnet(subrec, fail_name->name); + struct server_record *servrec; + + if(!work) + { + DEBUG(0,("become_domain_master_fail: Error - cannot find \ +workgroup %s on subnet %s\n", fail_name->name, subrec->subnet_name)); + return; + } + + /* Set the state back to DOMAIN_NONE. */ + work->dom_state = DOMAIN_NONE; + + if((servrec = find_server_in_workgroup( work, myname)) == NULL) + { + DEBUG(0,("become_domain_master_fail: Error - cannot find server %s \ +in workgroup %s on subnet %s\n", + myname, work->work_group, subrec->subnet_name)); + return; + } + + /* Update our server status. */ + servrec->serv.type &= ~SV_TYPE_DOMAIN_MASTER; + + /* Tell the namelist writer to write out a change. */ + subrec->work_changed = True; + + DEBUG(0,("become_domain_master_fail: Failed to become a domain master browser for \ +workgroup %s on subnet %s. Couldn't register name %s.\n", + work->work_group, subrec->subnet_name, namestr(fail_name))); +} + +/**************************************************************************** + Become a Domain Master Browser on a subnet. + ****************************************************************************/ + +static void become_domain_master_stage2(struct subnet_record *subrec, + struct userdata_struct *userdata, + struct nmb_name *registered_name, + uint16 nb_flags, + int ttl, struct in_addr registered_ip) +{ + struct work_record *work = find_workgroup_on_subnet( subrec, registered_name->name); + struct server_record *servrec; + + if(!work) + { + DEBUG(0,("become_domain_master_stage2: Error - cannot find \ +workgroup %s on subnet %s\n", registered_name->name, subrec->subnet_name)); + return; + } + + if((servrec = find_server_in_workgroup( work, myname)) == NULL) + { + DEBUG(0,("become_domain_master_stage2: Error - cannot find server %s \ +in workgroup %s on subnet %s\n", + myname, registered_name->name, subrec->subnet_name)); + work->dom_state = DOMAIN_NONE; + return; + } + + /* Set the state in the workgroup structure. */ + work->dom_state = DOMAIN_MST; /* Become domain master. */ + + /* Update our server status. */ + servrec->serv.type |= (SV_TYPE_NT|SV_TYPE_DOMAIN_MASTER); + + /* Tell the namelist writer to write out a change. */ + subrec->work_changed = True; + + DEBUG(0,("\n ***** Samba server %s is now a domain master browser \ +for workgroup %s on subnet %s *****\n\n", myname, work->work_group, subrec->subnet_name)); + + if(subrec == unicast_subnet) + { + struct nmb_name nmbname; + struct in_addr my_first_ip; + + /* Put our name and first IP address into the + workgroup struct as domain master browser. This + will stop us syncing with ourself if we are also + a local master browser. */ + + make_nmb_name(&nmbname, myname, 0x20, scope); + + work->dmb_name = nmbname; + /* Pick the first interface ip address as the domain master browser ip. */ + my_first_ip = *iface_n_ip(0); + + putip((char *)&work->dmb_addr, &my_first_ip); + + /* We successfully registered by unicast with the + WINS server. We now expect to become the domain + master on the local subnets. If this fails, it's + probably a 1.9.16p2 to 1.9.16p11 server's fault. + + This is a configuration issue that should be addressed + by the network administrator - you shouldn't have + several machines configured as a domain master browser + for the same WINS scope (except if they are 1.9.17 or + greater, and you know what you're doing. + + see docs/DOMAIN.txt. + + */ + become_domain_master_browser_bcast(work->work_group); + } +} + +/**************************************************************************** + Start the name registration process when becoming a Domain Master Browser + on a subnet. + ****************************************************************************/ + +static void become_domain_master_stage1(struct subnet_record *subrec, char *wg_name) +{ + struct work_record *work; + + DEBUG(2,("become_domain_master_stage1: Becoming domain master browser for \ +workgroup %s on subnet %s\n", wg_name, subrec->subnet_name)); + + /* First, find the workgroup on the subnet. */ + if((work = find_workgroup_on_subnet( subrec, wg_name )) == NULL) + { + DEBUG(0,("become_domain_master_stage1: Error - unable to find workgroup %s on subnet %s.\n", + wg_name, subrec->subnet_name)); + return; + } + + DEBUG(3,("become_domain_master_stage1: go to first stage: register <1b> name\n")); + work->dom_state = DOMAIN_WAIT; + + /* WORKGROUP<1b> is the domain master browser name. */ + register_name(subrec, work->work_group,0x1b,samba_nb_type, + become_domain_master_stage2, + become_domain_master_fail, NULL); +} + +/**************************************************************************** + Function called when a query for a WORKGROUP<1b> name succeeds. + This is normally a fail condition as it means there is already + a domain master browser for a workgroup and we were trying to + become one. +****************************************************************************/ + +static void become_domain_master_query_success(struct subnet_record *subrec, + struct userdata_struct *userdata, + struct nmb_name *nmbname, struct in_addr ip, + struct res_rec *rrec) +{ + /* If the given ip is not ours, then we can't become a domain + controler as the name is already registered. + */ + + /* BUG note. Samba 1.9.16p11 servers seem to return the broadcast + address or zero ip for this query. Pretend this is ok. */ + + if(ismyip(ip) || ip_equal(allones_ip, ip) || ip_equal(ipzero, ip)) + { + DEBUG(3,("become_domain_master_query_success: Our address (%s) returned \ +in query for name %s (domain master browser name) on subnet %s. \ +Continuing with domain master code.\n", + inet_ntoa(ip), namestr(nmbname), subrec->subnet_name)); + + become_domain_master_stage1(subrec, nmbname->name); + } + else + { + DEBUG(0,("become_domain_master_query_success: There is already a domain \ +master browser at IP %s for workgroup %s registered on subnet %s.\n", + inet_ntoa(ip), nmbname->name, subrec->subnet_name)); + } +} + +/**************************************************************************** + Function called when a query for a WORKGROUP<1b> name fails. + This is normally a success condition as it then allows us to register + our own Domain Master Browser name. + ****************************************************************************/ + +static void become_domain_master_query_fail(struct subnet_record *subrec, + struct response_record *rrec, + struct nmb_name *question_name, int fail_code) +{ + /* If the query was unicast, and the error is not NAM_ERR (name didn't exist), + then this is a failure. Otherwise, not finding the name is what we want. */ + if((subrec == unicast_subnet) && (fail_code != NAM_ERR)) + { + DEBUG(0,("become_domain_master_query_fail: Error %d returned when \ +querying WINS server for name %s.\n", + fail_code, namestr(question_name))); + return; + } + + /* Otherwise - not having the name allows us to register it. */ + become_domain_master_stage1(subrec, question_name->name); +} + +/**************************************************************************** + Attempt to become a domain master browser on all broadcast subnets. + ****************************************************************************/ + +static void become_domain_master_browser_bcast(char *workgroup_name) +{ + struct subnet_record *subrec; + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + { + struct work_record *work = find_workgroup_on_subnet(subrec, workgroup_name); + + if (work && (work->dom_state == DOMAIN_NONE)) + { + struct nmb_name nmbname; + make_nmb_name(&nmbname,workgroup_name,0x1b,scope); + + /* + * Check for our name on the given broadcast subnet first, only initiate + * further processing if we cannot find it. + */ + + if (find_name_on_subnet(subrec, &nmbname, FIND_SELF_NAME) == NULL) + { + DEBUG(0,("become_domain_master_browser_bcast: At time %s attempting to become domain \ +master browser on workgroup %s on subnet %s\n", timestring(), + workgroup_name, subrec->subnet_name)); + + /* Send out a query to establish whether there's a + domain controller on the local subnet. If not, + we can become a domain controller. + */ + + DEBUG(0,("become_domain_master_browser_bcast: querying subnet %s \ +for domain master browser on workgroup %s\n", subrec->subnet_name, workgroup_name)); + + query_name(subrec, nmbname.name, nmbname.name_type, + become_domain_master_query_success, + become_domain_master_query_fail, + NULL); + } + } + } +} + +/**************************************************************************** + Attempt to become a domain master browser by registering with WINS. + ****************************************************************************/ + +static void become_domain_master_browser_wins(char *workgroup_name) +{ + struct work_record *work; + + work = find_workgroup_on_subnet(unicast_subnet, workgroup_name); + + if (work && (work->dom_state == DOMAIN_NONE)) + { + struct nmb_name nmbname; + + make_nmb_name(&nmbname,workgroup_name,0x1b,scope); + + /* + * Check for our name on the unicast subnet first, only initiate + * further processing if we cannot find it. + */ + + if (find_name_on_subnet(unicast_subnet, &nmbname, FIND_SELF_NAME) == NULL) + { + DEBUG(0,("%s become_domain_master_browser_wins: attempting to become domain \ +master browser on workgroup %s, subnet %s.\n", + timestring(), workgroup_name, unicast_subnet->subnet_name)); + + /* Send out a query to establish whether there's a + domain master broswer registered with WINS. If not, + we can become a domain master browser. + */ + + DEBUG(0,("become_domain_master_browser_wins: querying WINS server at IP %s \ +for domain master browser name %s on workgroup %s\n", + inet_ntoa(unicast_subnet->myip), namestr(&nmbname), workgroup_name)); + + query_name(unicast_subnet, nmbname.name, nmbname.name_type, + become_domain_master_query_success, + become_domain_master_query_fail, + NULL); + } + } +} + +/**************************************************************************** + Add the domain logon server and domain master browser names + if we are set up to do so. + **************************************************************************/ + +void add_domain_names(time_t t) +{ + static time_t lastrun = 0; + + if ((lastrun != 0) && (t < lastrun + (CHECK_TIME_ADD_DOM_NAMES * 60))) + return; + + lastrun = t; + + /* Do the "internet group" - <1c> names. */ + if (lp_domain_logons()) + add_logon_names(); + + /* Do the domain master names. */ + if(lp_domain_master()) + { + if(we_are_a_wins_client()) + { + /* We register the WORKGROUP<1b> name with the WINS + server first, and call add_domain_master_bcast() + only if this is successful. + + This results in domain logon services being gracefully provided, + as opposed to the aggressive nature of 1.9.16p2 to 1.9.16p11. + 1.9.16p2 to 1.9.16p11 - due to a bug in namelogon.c, + cannot provide domain master / domain logon services. + */ + become_domain_master_browser_wins(myworkgroup); + } + else + become_domain_master_browser_bcast(myworkgroup); + } +} diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c new file mode 100644 index 0000000000..7f54471a24 --- /dev/null +++ b/source3/nmbd/nmbd_become_lmb.c @@ -0,0 +1,534 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1994-1997 + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; +extern pstring scope; +extern pstring myname; + +extern uint16 samba_nb_type; /* Samba's NetBIOS name type. */ + +/******************************************************************* + Utility function to add a name to the unicast subnet, or add in + our IP address if it already exists. +******************************************************************/ + +static void insert_permanent_name_into_unicast( struct subnet_record *subrec, + struct nmb_name *nmbname, uint16 nb_type ) +{ + struct name_record *namerec; + + if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) == NULL) + { + /* The name needs to be created on the unicast subnet. */ + add_name_to_subnet( unicast_subnet, nmbname->name, nmbname->name_type, + nb_type, PERMANENT_TTL, PERMANENT_NAME, 1, &subrec->myip); + } + else + { + /* The name already exists on the unicast subnet. Add our local + IP for the given broadcast subnet to the name. */ + add_ip_to_name_record( namerec, subrec->myip); + } +} + +/******************************************************************* + Utility function to remove a name from the unicast subnet. +******************************************************************/ + +static void remove_permanent_name_from_unicast( struct subnet_record *subrec, + struct nmb_name *nmbname ) +{ + struct name_record *namerec; + + if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) != NULL) + { + /* Remove this broadcast subnet IP address from the name. */ + remove_ip_from_name_record( namerec, subrec->myip); + if(namerec->num_ips == 0) + remove_name_from_namelist( unicast_subnet, namerec); + } +} + +/******************************************************************* + Utility function always called to set our workgroup and server + state back to potential browser, or none. +******************************************************************/ + +static void reset_workgroup_state( struct subnet_record *subrec, char *workgroup_name ) +{ + struct work_record *work; + struct server_record *servrec; + struct nmb_name nmbname; + + if((work = find_workgroup_on_subnet( subrec, workgroup_name)) == NULL) + { + DEBUG(0,("reset_workgroup_state: Error - cannot find workgroup %s on \ +subnet %s.\n", workgroup_name, subrec->subnet_name )); + return; + } + + if((servrec = find_server_in_workgroup( work, myname)) == NULL) + { + DEBUG(0,("reset_workgroup_state: Error - cannot find server %s \ +in workgroup %s on subnet %s\n", + myname, work->work_group, subrec->subnet_name)); + work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; + return; + } + + /* Update our server status - remove any master flag and replace + it with the potential browser flag. */ + servrec->serv.type &= ~SV_TYPE_MASTER_BROWSER; + servrec->serv.type |= (lp_local_master() ? SV_TYPE_POTENTIAL_BROWSER : 0); + + /* Tell the namelist writer to write out a change. */ + subrec->work_changed = True; + + /* Reset our election flags. */ + work->ElectionCriterion &= ~0x4; + + work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; + + /* Forget who the local master browser was for + this workgroup. */ + + *work->local_master_browser_name = '\0'; + + /* + * Ensure the IP address of this subnet is not registered as one + * of the IP addresses of the WORKGROUP<1d> name on the unicast + * subnet. This undoes what we did below when we became a local + * master browser. + */ + + make_nmb_name(&nmbname, work->work_group, 0x1d, scope); + + remove_permanent_name_from_unicast( subrec, &nmbname); + +} + +/******************************************************************* + Unbecome the local master browser name release success function. +******************************************************************/ + +void unbecome_local_master_success(struct subnet_record *subrec, + struct userdata_struct *userdata, + struct nmb_name *released_name, + struct in_addr released_ip) +{ + DEBUG(3,("unbecome_local_master_success: released name %s.\n", + namestr(released_name))); + + /* Now reset the workgroup and server state. */ + reset_workgroup_state( subrec, released_name->name ); + + DEBUG(0,("\n***** Samba name server %s has stopped being a local master browser for workgroup %s \ +on subnet %s *****\n\n", myname, released_name->name, subrec->subnet_name)); + +} + +/******************************************************************* + Unbecome the local master browser name release fail function. +******************************************************************/ + +void unbecome_local_master_fail(struct subnet_record *subrec, struct response_record *rrec, + struct nmb_name *fail_name) +{ + struct name_record *namerec; + + DEBUG(0,("unbecome_local_master_fail: failed to release name %s. \ +Removing from namelist anyway.\n", namestr(fail_name))); + + /* Do it anyway. */ + namerec = find_name_on_subnet(subrec, fail_name, FIND_SELF_NAME); + if(namerec) + remove_name_from_namelist(subrec, namerec); + + /* Now reset the workgroup and server state. */ + reset_workgroup_state( subrec, fail_name->name ); + + DEBUG(0,("\n***** Samba name server %s has stopped being a local master browser for workgroup %s \ +on subnet %s *****\n\n", myname, fail_name->name, subrec->subnet_name)); + +} + +/******************************************************************* + Utility function to remove the WORKGROUP<1d> name called by both + success and fail of releasing the MSBROWSE name. +******************************************************************/ + +void release_1d_name( struct subnet_record *subrec, char *workgroup_name) +{ + struct nmb_name nmbname; + struct name_record *namerec; + + make_nmb_name(&nmbname, workgroup_name, 0x1d, scope); + if((namerec = find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME))!=NULL) + { + release_name(subrec, namerec, + unbecome_local_master_success, + unbecome_local_master_fail, + NULL); + } +} + +/******************************************************************* + Unbecome the local master browser MSBROWSE name release success function. +******************************************************************/ + +static void release_msbrowse_name_success(struct subnet_record *subrec, + struct userdata_struct *userdata, + struct nmb_name *released_name, + struct in_addr released_ip) +{ + DEBUG(4,("release_msbrowse_name_success: Released name %s on subnet %s\n.", + namestr(released_name), subrec->subnet_name )); + + /* Remove the permanent MSBROWSE name added into the unicast subnet. */ + remove_permanent_name_from_unicast( subrec, released_name); + + release_1d_name( subrec, userdata->data ); +} + +/******************************************************************* + Unbecome the local master browser MSBROWSE name release fail function. +******************************************************************/ + +static void release_msbrowse_name_fail( struct subnet_record *subrec, + struct response_record *rrec, + struct nmb_name *fail_name) +{ + struct userdata_struct *userdata = rrec->userdata; + struct name_record *namerec; + + DEBUG(4,("release_msbrowse_name_fail: Failed to release name %s on subnet %s\n.", + namestr(fail_name), subrec->subnet_name )); + + /* Release the name anyway. */ + namerec = find_name_on_subnet(subrec, fail_name, FIND_SELF_NAME); + if(namerec) + remove_name_from_namelist(subrec, namerec); + + /* Remove the permanent MSBROWSE name added into the unicast subnet. */ + remove_permanent_name_from_unicast( subrec, fail_name); + + release_1d_name( subrec, userdata->data ); +} + +/******************************************************************* + Unbecome the local master browser. +******************************************************************/ + +void unbecome_local_master_browser(struct subnet_record *subrec, struct work_record *work) +{ + struct server_record *servrec; + struct name_record *namerec; + struct nmb_name nmbname; + struct userdata_struct *userdata; + char ud[sizeof(struct userdata_struct) + sizeof(fstring)+1]; + + /* Sanity check. */ + + DEBUG(2,("unbecome_local_master_browser: unbecoming local master for workgroup %s \ +on subnet %s\n",work->work_group, subrec->subnet_name)); + + if((servrec = find_server_in_workgroup( work, myname)) == NULL) + { + DEBUG(0,("unbecome_local_master_browser: Error - cannot find server %s \ +in workgroup %s on subnet %s\n", + myname, work->work_group, subrec->subnet_name)); + work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; + return; + } + + /* Set the state to unbecoming. */ + work->mst_state = MST_UNBECOMING_MASTER; + + /* Setup the userdata for the MSBROWSE name release. */ + /* Setup the userdata_struct - this is copied so we can use + a stack variable for this. */ + userdata = (struct userdata_struct *)ud; + + userdata->copy_fn = NULL; + userdata->free_fn = NULL; + userdata->userdata_len = strlen(work->work_group)+1; + strcpy(userdata->data, work->work_group); + + /* Deregister any browser names we may have. */ + make_nmb_name(&nmbname, MSBROWSE, 0x1, scope); + if((namerec = find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME))!=NULL) + { + release_name(subrec, namerec, + release_msbrowse_name_success, + release_msbrowse_name_fail, + userdata); + } +} + +/**************************************************************************** + Success in registering the WORKGROUP<1d> name. + We are now *really* a local master browser. + ****************************************************************************/ + +static void become_local_master_stage2(struct subnet_record *subrec, + struct userdata_struct *userdata, + struct nmb_name *registered_name, + uint16 nb_flags, + int ttl, struct in_addr registered_ip) +{ + int i = 0; + struct server_record *sl; + struct work_record *work = find_workgroup_on_subnet( subrec, registered_name->name); + struct server_record *servrec; + + if(!work) + { + DEBUG(0,("become_local_master_stage2: Error - cannot find \ +workgroup %s on subnet %s\n", registered_name->name, subrec->subnet_name)); + return; + } + + if((servrec = find_server_in_workgroup( work, myname)) == NULL) + { + DEBUG(0,("become_local_master_stage2: Error - cannot find server %s \ +in workgroup %s on subnet %s\n", + myname, registered_name->name, subrec->subnet_name)); + work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; + return; + } + + DEBUG(3,("become_local_master_stage2: registered as master browser for workgroup %s \ +on subnet %s\n", work->work_group, subrec->subnet_name)); + + work->mst_state = MST_BROWSER; /* registering WORKGROUP(1d) succeeded */ + + /* update our server status */ + servrec->serv.type |= SV_TYPE_MASTER_BROWSER; + servrec->serv.type &= ~SV_TYPE_POTENTIAL_BROWSER; + + /* Tell the namelist writer to write out a change. */ + subrec->work_changed = True; + + /* Add this name to the workgroup as local master browser. */ + StrnCpy(work->local_master_browser_name, myname, + sizeof(work->local_master_browser_name)-1); + + /* Count the number of servers we have on our list. If it's + less than 10 (just a heuristic) request the servers + to announce themselves. + */ + for( sl = work->serverlist; sl != NULL; sl = sl->next) + i++; + + if (i < 10) + { + /* Ask all servers on our local net to announce to us. */ + broadcast_announce_request(subrec, work); + } + + /* + * Now we are a local master on a broadcast subnet, we need to add + * the WORKGROUP<1d> name to the unicast subnet so that we can answer + * unicast requests sent to this name. We can create this name directly on + * the unicast subnet as a WINS server always returns true when registering + * this name, and discards the registration. We use the number of IP + * addresses registered to this name as a reference count, as we + * remove this broadcast subnet IP address from it when we stop becoming a local + * master browser for this broadcast subnet. + */ + + insert_permanent_name_into_unicast( subrec, registered_name, nb_flags); + + /* Reset the announce master browser timer so that we try and tell a domain + master browser as soon as possible that we are a local master browser. */ + reset_announce_timer(); + + DEBUG(0,("\n***** Samba name server %s is now a local master browser for workgroup %s \ +on subnet %s *****\n\n", myname, work->work_group, subrec->subnet_name)); + +} + +/**************************************************************************** + Failed to register the WORKGROUP<1d> name. + ****************************************************************************/ +static void become_local_master_fail2(struct subnet_record *subrec, + struct response_record *rrec, + struct nmb_name *fail_name) +{ + struct work_record *work = find_workgroup_on_subnet( subrec, fail_name->name); + + DEBUG(0,("become_local_master_fail2: failed to register name %s on subnet %s. \ +Failed to become a local master browser.\n", namestr(fail_name), subrec->subnet_name)); + + if(!work) + { + DEBUG(0,("become_local_master_fail2: Error - cannot find \ +workgroup %s on subnet %s\n", fail_name->name, subrec->subnet_name)); + return; + } + + /* Roll back all the way by calling unbecome_local_master_browser(). */ + unbecome_local_master_browser(subrec, work); +} + +/**************************************************************************** + Success in registering the MSBROWSE name. + ****************************************************************************/ + +static void become_local_master_stage1(struct subnet_record *subrec, + struct userdata_struct *userdata, + struct nmb_name *registered_name, + uint16 nb_flags, + int ttl, struct in_addr registered_ip) +{ + char *work_name = userdata->data; + struct work_record *work = find_workgroup_on_subnet( subrec, work_name); + + if(!work) + { + DEBUG(0,("become_local_master_stage1: Error - cannot find \ +workgroup %s on subnet %s\n", work_name, subrec->subnet_name)); + return; + } + + DEBUG(3,("become_local_master_stage1: go to stage 2: register the %s<1d> name.\n", + work->work_group)); + + work->mst_state = MST_MSB; /* Registering MSBROWSE was successful. */ + + /* + * We registered the MSBROWSE name on a broadcast subnet, now need to add + * the MSBROWSE name to the unicast subnet so that we can answer + * unicast requests sent to this name. We create this name directly on + * the unicast subnet. + */ + + insert_permanent_name_into_unicast( subrec, registered_name, nb_flags); + + /* Attempt to register the WORKGROUP<1d> name. */ + register_name(subrec, work->work_group,0x1d,samba_nb_type, + become_local_master_stage2, + become_local_master_fail2, + NULL); +} + +/**************************************************************************** + Failed to register the MSBROWSE name. + ****************************************************************************/ + +static void become_local_master_fail1(struct subnet_record *subrec, + struct response_record *rrec, + struct nmb_name *fail_name) +{ + char *work_name = rrec->userdata->data; + struct work_record *work = find_workgroup_on_subnet(subrec, work_name); + struct server_record *servrec; + + if(!work) + { + DEBUG(0,("become_local_master_fail1: Error - cannot find \ +workgroup %s on subnet %s\n", work_name, subrec->subnet_name)); + return; + } + + if((servrec = find_server_in_workgroup(work, myname)) == NULL) + { + DEBUG(0,("become_local_master_fail1: Error - cannot find server %s \ +in workgroup %s on subnet %s\n", + myname, work->work_group, subrec->subnet_name)); + return; + } + + reset_workgroup_state( subrec, work->work_group ); + + DEBUG(0,("become_local_master_fail1: Failed to become a local master browser for \ +workgroup %s on subnet %s. Couldn't register name %s.\n", + work->work_group, subrec->subnet_name, namestr(fail_name))); +} + +/****************************************************************** + Become the local master browser on a subnet. + This gets called if we win an election on this subnet. + + Stage 1: mst_state was MST_POTENTIAL - go to MST_BACK register ^1^2__MSBROWSE__^2^1. + Stage 2: mst_state was MST_BACKUP - go to MST_MSB and register WORKGROUP<1d>. + Stage 3: mst_state was MST_MSB - go to MST_BROWSER. +******************************************************************/ + +void become_local_master_browser(struct subnet_record *subrec, struct work_record *work) +{ + struct server_record *servrec; + struct userdata_struct *userdata; + char ud[sizeof(struct userdata_struct) + sizeof(fstring)+1]; + + /* Sanity check. */ + if (!lp_local_master()) + { + DEBUG(0,("become_local_master_browser: Samba not configured as a local master browser.\n")); + return; + } + + if(!AM_POTENTIAL_MASTER_BROWSER(work)) + { + DEBUG(2,("become_local_master_browser: Awaiting potential browser state. Current state is %d\n", + work->mst_state )); + return; + } + + if((servrec = find_server_in_workgroup( work, myname)) == NULL) + { + DEBUG(0,("become_local_master_browser: Error - cannot find server %s \ +in workgroup %s on subnet %s\n", + myname, work->work_group, subrec->subnet_name)); + return; + } + + DEBUG(2,("become_local_master_browser: Starting to become a master browser for workgroup \ +%s on subnet %s\n", work->work_group, subrec->subnet_name)); + + DEBUG(3,("become_local_master_browser: first stage - attempt to register ^1^2__MSBROWSE__^2^1\n")); + work->mst_state = MST_BACKUP; /* an election win was successful */ + + work->ElectionCriterion |= 0x5; + + /* Tell the namelist writer to write out a change. */ + subrec->work_changed = True; + + /* Setup the userdata_struct - this is copied so we can use + a stack variable for this. */ + userdata = (struct userdata_struct *)ud; + + userdata->copy_fn = NULL; + userdata->free_fn = NULL; + userdata->userdata_len = strlen(work->work_group)+1; + strcpy(userdata->data, work->work_group); + + /* Register the special browser group name. */ + register_name(subrec, MSBROWSE, 0x01, samba_nb_type|NB_GROUP, + become_local_master_stage1, + become_local_master_fail1, + userdata); +} diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c new file mode 100644 index 0000000000..b2db744370 --- /dev/null +++ b/source3/nmbd/nmbd_browserdb.c @@ -0,0 +1,184 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1994-1997 + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "includes.h" +#include "smb.h" + +extern int DEBUGLEVEL; + +/* This is our local master browser list database. */ +struct browse_cache_record *lmb_browserlist = NULL; + +/*************************************************************************** +Add a browser into the lmb list. +**************************************************************************/ + +static void add_to_lmb_browse_cache(struct browse_cache_record *browc) +{ + struct browse_cache_record *browc2; + + if (lmb_browserlist == NULL) + { + lmb_browserlist = browc; + browc->prev = NULL; + browc->next = NULL; + return; + } + + for (browc2 = lmb_browserlist; browc2->next; browc2 = browc2->next) + ; + + browc2->next = browc; + browc->next = NULL; + browc->prev = browc2; +} + +/******************************************************************* +Remove a lmb browser entry. +******************************************************************/ + +void remove_lmb_browser_entry(struct browse_cache_record *browc) +{ + if (browc->prev) + browc->prev->next = browc->next; + if (browc->next) + browc->next->prev = browc->prev; + + if (lmb_browserlist == browc) + lmb_browserlist = browc->next; + + free((char *)browc); +} + +/**************************************************************************** +Update a browser death time. +****************************************************************************/ + +void update_browser_death_time(struct browse_cache_record *browc) +{ + /* Allow the new lmb to miss an announce period before we remove it. */ + browc->death_time = time(NULL) + (CHECK_TIME_MST_ANNOUNCE + 2)*60; +} + +/**************************************************************************** +Create a browser entry. +****************************************************************************/ + +struct browse_cache_record *create_browser_in_lmb_cache(char *work_name, char *browser_name, + struct in_addr ip) +{ + struct browse_cache_record *browc; + time_t now = time(NULL); + + browc = (struct browse_cache_record *)malloc(sizeof(*browc)); + + if (browc == NULL) + { + DEBUG(0,("create_browser_in_lmb_cache: malloc fail !\n")); + return(NULL); + } + + bzero((char *)browc,sizeof(*browc)); + + /* For a new lmb entry we want to sync with it after one minute. This + will allow it time to send out a local announce and build its + browse list. */ + + browc->sync_time = now + 60; + + /* Allow the new lmb to miss an announce period before we remove it. */ + browc->death_time = now + (CHECK_TIME_MST_ANNOUNCE + 2)*60; + + StrnCpy(browc->lmb_name, browser_name,sizeof(browc->lmb_name)-1); + StrnCpy(browc->work_group,work_name,sizeof(browc->work_group)-1); + strupper(browc->lmb_name); + strupper(browc->work_group); + + browc->ip = ip; + + add_to_lmb_browse_cache(browc); + + DEBUG(3,("create_browser_in_lmb_cache: Added lmb cache entry for workgroup %s name %s IP %s ttl %d\n", + browc->work_group, browc->lmb_name, inet_ntoa(ip), browc->death_time)); + + return(browc); +} + +/**************************************************************************** +Find a browser entry. +****************************************************************************/ + +struct browse_cache_record *find_browser_in_lmb_cache( char *browser_name ) +{ + struct browse_cache_record *browc = NULL; + + for( browc = lmb_browserlist; browc; browc = browc->next) + if(strequal( browser_name, browc->lmb_name)) + break; + + return browc; +} + +/******************************************************************* + Expire timed out browsers in the browserlist. +******************************************************************/ + +void expire_lmb_browsers(time_t t) +{ + struct browse_cache_record *browc; + struct browse_cache_record *nextbrowc; + + for (browc = lmb_browserlist; browc; browc = nextbrowc) + { + nextbrowc = browc->next; + + if (browc->death_time < t) + { + DEBUG(3,("expire_lmb_browsers: Removing timed out lmb entry %s\n",browc->lmb_name)); + remove_lmb_browser_entry(browc); + } + } +} + +/******************************************************************* + Remove browsers from a named workgroup in the browserlist. +******************************************************************/ + +void remove_workgroup_lmb_browsers(char *work_group) +{ + struct browse_cache_record *browc; + struct browse_cache_record *nextbrowc; + + for (browc = lmb_browserlist; browc; browc = nextbrowc) + { + nextbrowc = browc->next; + + if (strequal(work_group, browc->work_group)) + { + DEBUG(3,("remove_workgroup_browsers: Removing lmb entry %s\n",browc->lmb_name)); + remove_lmb_browser_entry(browc); + } + } +} + diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c new file mode 100644 index 0000000000..b899e2e8bc --- /dev/null +++ b/source3/nmbd/nmbd_browsesync.c @@ -0,0 +1,458 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1994-1997 + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "includes.h" +#include "smb.h" + +extern int DEBUGLEVEL; +extern pstring scope; +extern struct in_addr ipzero; +extern pstring myname; + +/* This is our local master browser list database. */ +extern struct browse_cache_record *lmb_browserlist; + +static struct work_record *call_work; +static struct subnet_record *call_subrec; + +/******************************************************************* + This is the NetServerEnum callback. + ******************************************************************/ + +static void callback(char *sname, uint32 stype, char *comment) +{ + struct work_record *work; + + stype &= ~SV_TYPE_LOCAL_LIST_ONLY; + + if (stype & SV_TYPE_DOMAIN_ENUM) + { + /* See if we can find the workgroup on this subnet. */ + if(( work = find_workgroup_on_subnet( call_subrec, sname )) != NULL) + { + /* We already know about this workgroup - update the ttl. */ + update_workgroup_ttl( work, lp_max_ttl() ); + } + else + { + /* Create the workgroup on the subnet. */ + create_workgroup_on_subnet( call_subrec, sname, lp_max_ttl() ); + } + } + else + { + /* Server entry. */ + struct server_record *servrec; + + work = call_work; + + if(( servrec = find_server_in_workgroup( work, sname )) != NULL) + { + /* Check that this is not a locally known server - if so ignore the + entry. */ + if(!(servrec->serv.type & SV_TYPE_LOCAL_LIST_ONLY)) + { + /* We already know about this server - update the ttl. */ + update_server_ttl(servrec, lp_max_ttl() ); + /* Update the type. */ + servrec->serv.type = stype; + } + } + else + { + /* Create the server in the workgroup. */ + create_server_on_workgroup(work, sname,stype,lp_max_ttl(),comment); + } + } +} + +/******************************************************************* + Synchronise browse lists with another browse server. + Log in on the remote server's SMB port to their IPC$ service, + do a NetServerEnum and update our server and workgroup databases. +******************************************************************/ + +static void sync_browse_lists(struct subnet_record *subrec, struct work_record *work, + char *name, int nm_type, struct in_addr ip, BOOL local) +{ + extern fstring local_machine; + static struct cli_state cli; + uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0; + + DEBUG(2,("%s: sync_browse_lists: Sync browse lists with server %s<%02x> at IP %s for workgroup %s\n", + timestring(), name, nm_type, inet_ntoa(ip), work->work_group )); + + /* Check we're not trying to sync with ourselves. This can happen if we are + a domain *and* a local master browser. */ + if(ismyip(ip)) + { + DEBUG(2,("sync_browse_lists: We are both a domain and a local master browser for workgroup %s. \ +Do not sync with ourselves.\n", work->work_group )); + return; + } + + if (!cli_initialise(&cli) || !cli_connect(&cli, name, &ip)) + { + DEBUG(0,("sync_browse_lists: Failed to start browse sync with %s\n", name)); + return; + } + + if (!cli_session_request(&cli, name, nm_type, local_machine)) + { + DEBUG(0,("sync_browse_lists: %s rejected the browse sync session\n",name)); + cli_shutdown(&cli); + return; + } + + if (!cli_negprot(&cli)) + { + DEBUG(0,("sync_browse_lists: %s rejected the negprot\n",name)); + cli_shutdown(&cli); + return; + } + + if (!cli_session_setup(&cli, "", "", 1, "", 0, work->work_group)) + { + DEBUG(0,("sync_browse_lists: %s rejected the browse sync sessionsetup\n", + name)); + cli_shutdown(&cli); + return; + } + + if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) + { + DEBUG(0,("sync_browse_lists: %s refused browse sync IPC$ connect\n", name)); + cli_shutdown(&cli); + return; + } + + call_work = work; + call_subrec = subrec; + + /* Fetch a workgroup list. */ + cli_NetServerEnum(&cli, work->work_group, + local_type|SV_TYPE_DOMAIN_ENUM, + callback); + + /* Now fetch a server list. */ + cli_NetServerEnum(&cli, work->work_group, + local?SV_TYPE_LOCAL_LIST_ONLY:SV_TYPE_ALL, + callback); + + cli_shutdown(&cli); +} + +/**************************************************************************** +As a domain master browser, do a sync with a local master browser. +**************************************************************************/ + +static void sync_with_lmb(struct browse_cache_record *browc) +{ + struct work_record *work; + + if (!(work = find_workgroup_on_subnet(unicast_subnet, browc->work_group))) { + DEBUG(0, ("sync_with_lmb: failed to get a \ +workgroup for a local master browser cache entry workgroup %s, server %s\n", + browc->work_group, browc->lmb_name)); + return; + } + + /* We should only be doing this if we are a domain master browser for + the given workgroup. Ensure this is so. */ + + if(!AM_DOMAIN_MASTER_BROWSER(work)) + { + DEBUG(0,("sync_with_lmb: We are trying to sync with a local master browser %s \ +for workgroup %s and we are not a domain master browser on this workgroup. Error !\n", + browc->lmb_name, browc->work_group)); + return; + } + + DEBUG(2, ("sync_with_lmb: Initiating sync with local master browser %s<0x20> at IP %s for \ +workgroup %s\n", browc->lmb_name, inet_ntoa(browc->ip), browc->work_group)); + + sync_browse_lists(unicast_subnet, work, browc->lmb_name, 0x20, browc->ip, True); + + browc->sync_time += (CHECK_TIME_DMB_TO_LMB_SYNC * 60); +} + +/**************************************************************************** +Sync or expire any local master browsers. +**************************************************************************/ + +void dmb_expire_and_sync_browser_lists(time_t t) +{ + static time_t last_run = 0; + struct browse_cache_record *browc; + + /* Only do this every 20 seconds. */ + if (t - last_run < 20) + return; + + last_run = t; + + expire_lmb_browsers(t); + + for (browc = lmb_browserlist; browc; browc = browc->next) + { + if (browc->sync_time < t) + sync_with_lmb(browc); + } +} + +/**************************************************************************** +As a local master browser, send an announce packet to the domain master browser. +**************************************************************************/ + +static void announce_local_master_browser_to_domain_master_browser( struct work_record *work) +{ + pstring outbuf; + char *p; + + if(ismyip(work->dmb_addr)) + { + DEBUG(2,("announce_local_master_browser_to_domain_master_browser: We are both a domain \ +and a local master browser for workgroup %s. \ +Do not announce to ourselves.\n", work->work_group )); + return; + } + + bzero(outbuf,sizeof(outbuf)); + p = outbuf; + CVAL(p,0) = ANN_MasterAnnouncement; + p++; + + StrnCpy(p,myname,15); + strupper(p); + p = skip_string(p,1); + + DEBUG(4,("announce_local_master_browser_to_domain_master_browser: Sending local master announce \ +to %s for workgroup %s.\n", namestr(&work->dmb_name), work->work_group )); + + send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), + myname, 0x0, work->dmb_name.name, 0x20, work->dmb_addr, FIRST_SUBNET->myip); + +} + +/**************************************************************************** +As a local master browser, do a sync with a domain master browser. +**************************************************************************/ + +static void sync_with_dmb(struct work_record *work) +{ + DEBUG(2, ("sync_with_dmb: Initiating sync with domain master browser %s at IP %s for \ +workgroup %s\n", namestr(&work->dmb_name), inet_ntoa(work->dmb_addr), work->work_group)); + + sync_browse_lists(unicast_subnet, work, work->dmb_name.name, work->dmb_name.name_type, + work->dmb_addr, False); +} + +/**************************************************************************** + Function called when a node status query to a domain master browser IP succeeds. +****************************************************************************/ + +static void domain_master_node_status_success(struct subnet_record *subrec, + struct userdata_struct *userdata, + struct res_rec *answers, + struct in_addr from_ip) +{ + struct work_record *work = find_workgroup_on_subnet( subrec, userdata->data); + + if(work == NULL) + { + DEBUG(0,("domain_master_node_status_success: Unable to find workgroup %s on subnet %s.\n", + userdata->data, subrec->subnet_name)); + return; + } + + DEBUG(3,("domain_master_node_status_success: Success in node status for workgroup %s from ip %s\n", + work->work_group, inet_ntoa(from_ip) )); + + /* Go through the list of names found at answers->rdata and look for + the first SERVER<0x20> name. */ + + if(answers->rdata != NULL) + { + char *p = answers->rdata; + int numnames = CVAL(p, 0); + + p += 1; + + while (numnames--) + { + char qname[17]; + uint16 nb_flags; + int name_type; + + StrnCpy(qname,p,15); + name_type = CVAL(p,15); + nb_flags = get_nb_flags(&p[16]); + trim_string(qname,NULL," "); + + p += 18; + + if(!(nb_flags & NB_GROUP) && (name_type == 0x20)) + { + struct nmb_name nmbname; + + make_nmb_name(&nmbname, qname, name_type, scope); + + /* Copy the dmb name and IP address + into the workgroup struct. */ + + work->dmb_name = nmbname; + putip((char *)&work->dmb_addr, &from_ip); + + /* Do the local master browser announcement to the domain + master browser name and IP. */ + announce_local_master_browser_to_domain_master_browser( work ); + + /* Now synchronise lists with the domain master browser. */ + sync_with_dmb(work); + break; + } + } + } + else + DEBUG(0,("domain_master_node_status_success: Failed to find a SERVER<0x20> \ +name in reply from IP %s.\n", inet_ntoa(from_ip) )); +} + +/**************************************************************************** + Function called when a node status query to a domain master browser IP fails. +****************************************************************************/ + +static void domain_master_node_status_fail(struct subnet_record *subrec, + struct response_record *rrec) +{ + struct userdata_struct *userdata = rrec->userdata; + + DEBUG(0,("domain_master_node_status_fail: Doing a node status request to \ +the domain master browser for workgroup %s at IP %s failed. Cannot sync browser \ +lists.\n", userdata->data, inet_ntoa(rrec->packet->ip) )); + +} + +/**************************************************************************** + Function called when a query for a WORKGROUP<1b> name succeeds. +****************************************************************************/ + +static void find_domain_master_name_query_success(struct subnet_record *subrec, + struct userdata_struct *userdata_in, + struct nmb_name *q_name, struct in_addr answer_ip, struct res_rec *rrec) +{ + /* + * Unfortunately, finding the IP address of the Domain Master Browser, + * as we have here, is not enough. We need to now do a sync to the + * SERVERNAME<0x20> NetBIOS name, as only recent NT servers will + * respond to the SMBSERVER name. To get this name from IP + * address we do a Node status request, and look for the first + * NAME<0x20> in the response, and take that as the server name. + * We also keep a cache of the Domain Master Browser name for this + * workgroup in the Workgroup struct, so that if the same IP addess + * is returned every time, we don't need to do the node status + * request. + */ + + struct work_record *work; + struct nmb_name nmbname; + struct userdata_struct *userdata; + char ud[sizeof(struct userdata_struct) + sizeof(fstring)+1]; + + if (!(work = find_workgroup_on_subnet(subrec, q_name->name))) { + DEBUG(0, ("find_domain_master_name_query_success: failed to find \ +workgroup %s\n", q_name->name )); + return; + } + + /* First check if we already have a dmb for this workgroup. */ + + if(!ip_equal(work->dmb_addr, ipzero) && ip_equal(work->dmb_addr, answer_ip)) + { + /* Do the local master browser announcement to the domain + master browser name and IP. */ + announce_local_master_browser_to_domain_master_browser( work ); + + /* Now synchronise lists with the domain master browser. */ + sync_with_dmb(work); + return; + } + else + putip((char *)&work->dmb_addr, &ipzero); + + /* Now initiate the node status request. */ + bzero((char *)&nmbname, sizeof(nmbname)); + nmbname.name[0] = '*'; + + /* Put the workgroup name into the userdata so we know + what workgroup we're talking to when the reply comes + back. */ + + /* Setup the userdata_struct - this is copied so we can use + a stack variable for this. */ + userdata = (struct userdata_struct *)ud; + + userdata->copy_fn = NULL; + userdata->free_fn = NULL; + userdata->userdata_len = strlen(work->work_group)+1; + strcpy(userdata->data, work->work_group); + + node_status( subrec, &nmbname, answer_ip, + domain_master_node_status_success, + domain_master_node_status_fail, + userdata); +} + +/**************************************************************************** + Function called when a query for a WORKGROUP<1b> name fails. + ****************************************************************************/ +static void find_domain_master_name_query_fail(struct subnet_record *subrec, + struct response_record *rrec, + struct nmb_name *question_name, int fail_code) +{ + DEBUG(0,("find_domain_master_name_query_fail: Unable to find the Domain Master \ +Browser name %s for the workgroup %s. Unable to sync browse lists in this workgroup.\n", + namestr(question_name), question_name->name )); +} + +/**************************************************************************** +As a local master browser for a workgroup find the domain master browser +name, announce ourselves as local master browser to it and then pull the +full domain browse lists from it onto the given subnet. +**************************************************************************/ + +void announce_and_sync_with_domain_master_browser( struct subnet_record *subrec, + struct work_record *work) +{ + struct nmb_name nmbname; + + make_nmb_name(&nmbname,work->work_group,0x1b,scope); + + /* First, query for the WORKGROUP<1b> name from the WINS server. */ + query_name(unicast_subnet, nmbname.name, nmbname.name_type, + find_domain_master_name_query_success, + find_domain_master_name_query_fail, + NULL); + +} diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c new file mode 100644 index 0000000000..5c3c4c7a01 --- /dev/null +++ b/source3/nmbd/nmbd_elections.c @@ -0,0 +1,348 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1994-1997 + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; + +extern pstring myname; +extern fstring myworkgroup; + +/* Election parameters. */ +extern time_t StartupTime; + +/**************************************************************************** + Send an election datagram packet. +**************************************************************************/ +static void send_election_dgram(struct subnet_record *subrec, char *workgroup_name, + uint32 criterion, int timeup,char *server_name) +{ + pstring outbuf; + char *p; + + DEBUG(2,("send_election_dgram: Sending election packet for workgroup %s on subnet %s\n", + workgroup_name, subrec->subnet_name )); + + bzero(outbuf,sizeof(outbuf)); + p = outbuf; + CVAL(p,0) = ANN_Election; /* Election opcode. */ + p++; + + CVAL(p,0) = (criterion == 0 && timeup == 0) ? 0 : ELECTION_VERSION; + SIVAL(p,1,criterion); + SIVAL(p,5,timeup*1000); /* ms - Despite what the spec says. */ + p += 13; + pstrcpy(p,server_name); + strupper(p); + p = skip_string(p,1); + + send_mailslot(False, BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), + server_name, 0, + workgroup_name, 0x1e, + subrec->bcast_ip, subrec->myip); +} + +/******************************************************************* + We found a current master browser on one of our broadcast interfaces. +******************************************************************/ + +static void check_for_master_browser_success(struct subnet_record *subrec, + struct userdata_struct *userdata, + struct nmb_name *answer_name, + struct in_addr answer_ip, struct res_rec *rrec) +{ + DEBUG(3,("check_for_master_browser_success: Local master browser for workgroup %s exists at \ +IP %s (just checking).\n", answer_name->name, inet_ntoa(answer_ip) )); +} + +/******************************************************************* + We failed to find a current master browser on one of our broadcast interfaces. +******************************************************************/ + +static void check_for_master_browser_fail( struct subnet_record *subrec, + struct response_record *rrec, + struct nmb_name *question_name, + int fail_code) +{ + char *workgroup_name = question_name->name; + struct work_record *work = find_workgroup_on_subnet(subrec, workgroup_name); + + if(work == NULL) + { + DEBUG(0,("check_for_master_browser_fail: Unable to find workgroup %s on subnet %s.=\n", + workgroup_name, subrec->subnet_name )); + return; + } + + if (strequal(work->work_group, myworkgroup)) + { + + if (lp_local_master()) + { + /* We have discovered that there is no local master + browser, and we are configured to initiate + an election that we will participate in. + */ + DEBUG(2,("check_for_master_browser_fail: Forcing election on workgroup %s subnet %s\n", + work->work_group, subrec->subnet_name )); + + /* Setting this means we will participate when the + election is run in run_elections(). */ + work->needelection = True; + } + else + { + /* We need to force an election, because we are configured + not to become the local master, but we still need one, + having detected that one doesn't exist. + */ + send_election_dgram(subrec, work->work_group, 0, 0, myname); + } + } +} + +/******************************************************************* + Ensure there is a local master browser for a workgroup on our + broadcast interfaces. +******************************************************************/ + +void check_master_browser_exists(time_t t) +{ + static time_t lastrun=0; + struct subnet_record *subrec; + char *workgroup_name = myworkgroup; + + if (!lastrun) + lastrun = t; + + if (t < (lastrun + (CHECK_TIME_MST_BROWSE * 60))) + return; + + lastrun = t; + + dump_workgroups(); + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + { + struct work_record *work; + + for (work = subrec->workgrouplist; work; work = work->next) + { + if (strequal(work->work_group, workgroup_name) && !AM_LOCAL_MASTER_BROWSER(work)) + { + /* Do a name query for the local master browser on this net. */ + query_name( subrec, work->work_group, 0x1d, + check_for_master_browser_success, + check_for_master_browser_fail, + NULL); + } + } + } +} + +/******************************************************************* + Run an election. +******************************************************************/ + +void run_elections(time_t t) +{ + static time_t lastime = 0; + + struct subnet_record *subrec; + + /* Send election packets once a second - note */ + if (lastime && (t - lastime <= 0)) + return; + + lastime = t; + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + { + struct work_record *work; + + for (work = subrec->workgrouplist; work; work = work->next) + { + if (work->RunningElection) + { + send_election_dgram(subrec, work->work_group, work->ElectionCriterion, + t - StartupTime, myname); + + if (work->ElectionCount++ >= 4) + { + /* Won election (4 packets were sent out uncontested. */ + DEBUG(2,("run_elections: >>> Won election for workgroup %s on subnet %s <<<\n", + work->work_group, subrec->subnet_name )); + + work->RunningElection = False; + + become_local_master_browser(subrec, work); + } + } + } + } +} + +/******************************************************************* + Determine if I win an election. +******************************************************************/ + +static BOOL win_election(struct work_record *work, int version, + uint32 criterion, int timeup, char *server_name) +{ + int mytimeup = time(NULL) - StartupTime; + uint32 mycriterion = work->ElectionCriterion; + + /* If local master is false then never win + in election broadcasts. */ + if(!lp_local_master()) + { + DEBUG(3,("win_election: Losing election as local master == False\n")); + return False; + } + + DEBUG(4,("win_election: election comparison: %x:%x %x:%x %d:%d %s:%s\n", + version, ELECTION_VERSION, + criterion, mycriterion, + timeup, mytimeup, + server_name, myname)); + + if (version > ELECTION_VERSION) + return(False); + if (version < ELECTION_VERSION) + return(True); + + if (criterion > mycriterion) + return(False); + if (criterion < mycriterion) + return(True); + + if (timeup > mytimeup) + return(False); + if (timeup < mytimeup) + return(True); + + if (strcasecmp(myname, server_name) > 0) + return(False); + + return(True); +} + +/******************************************************************* + Process an incoming election datagram packet. +******************************************************************/ + +void process_election(struct subnet_record *subrec, struct packet_struct *p, char *buf) +{ + struct dgram_packet *dgram = &p->packet.dgram; + int version = CVAL(buf,0); + uint32 criterion = IVAL(buf,1); + int timeup = IVAL(buf,5)/1000; + char *server_name = buf+13; + struct work_record *work; + char *workgroup_name = dgram->dest_name.name; + + server_name[15] = 0; + + DEBUG(3,("process_election: Election request from %s at IP %s on subnet %s for workgroup %s.\n", + server_name,inet_ntoa(p->ip), subrec->subnet_name, workgroup_name )); + + DEBUG(5,("process_election: vers=%d criterion=%08x timeup=%d\n", version,criterion,timeup)); + + if(( work = find_workgroup_on_subnet(subrec, workgroup_name)) == NULL) + { + DEBUG(0,("process_election: Cannot find workgroup %s on subnet %s.\n", + workgroup_name, subrec->subnet_name )); + return; + } + + if (!strequal(work->work_group, myworkgroup)) + { + DEBUG(3,("process_election: ignoring election request for workgroup %s on subnet %s as this \ +is not my workgroup.\n", work->work_group, subrec->subnet_name )); + return; + } + + if (win_election(work, version,criterion,timeup,server_name)) + { + /* We take precedence over the requesting server. */ + if (!work->RunningElection) + { + /* We weren't running an election - start running one. */ + + work->needelection = True; + work->ElectionCount=0; + } + + /* Note that if we were running an election for this workgroup on this + subnet already, we just ignore the server we take precedence over. */ + } + else + { + /* We lost. Stop participating. */ + work->needelection = False; + + if (work->RunningElection || AM_LOCAL_MASTER_BROWSER(work)) + { + work->RunningElection = False; + DEBUG(3,("process_election: >>> Lost election for workgroup %s on subnet %s <<<\n", + work->work_group, subrec->subnet_name )); + if (AM_LOCAL_MASTER_BROWSER(work)) + unbecome_local_master_browser(subrec, work); + } + } +} + +/**************************************************************************** + This function looks over all the workgroups known on all the broadcast + subnets and decides if a browser election is to be run on that workgroup. + It returns True if any election packets need to be sent (this will then + be done by run_elections(). +***************************************************************************/ + +BOOL check_elections(void) +{ + struct subnet_record *subrec; + BOOL run_any_election = False; + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + { + struct work_record *work; + for (work = subrec->workgrouplist; work; work = work->next) + { + run_any_election |= work->RunningElection; + + /* Only start an election if we are in the potential browser state. */ + if (work->needelection && !work->RunningElection && AM_POTENTIAL_MASTER_BROWSER(work)) + { + DEBUG(3,("check_elections: >>> Starting election for workgroup %s on subnet %s <<<\n", + work->work_group, subrec->subnet_name )); + + work->ElectionCount = 0; + work->RunningElection = True; + work->needelection = False; + } + } + } + return run_any_election; +} diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c new file mode 100644 index 0000000000..24b4f33838 --- /dev/null +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -0,0 +1,625 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1994-1997 + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; + +extern pstring myname; +extern fstring myworkgroup; + +#if 0 + +/* XXXX note: This function is currently unsuitable for use, as it + does not properly check that a server is in a fit state to become + a backup browser before asking it to be one. + The code is left here to be worked on at a later date. +*/ + +/**************************************************************************** +Tell a server to become a backup browser +**************************************************************************/ + +void tell_become_backup(void) +{ + struct subnet_record *subrec; + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + { + struct work_record *work; + for (work = subrec->workgrouplist; work; work = work->next) + { + struct server_record *servrec; + int num_servers = 0; + int num_backups = 0; + + for (servrec = work->serverlist; servrec; servrec = servrec->next) + { + num_servers++; + + if (is_myname(servrec->serv.name)) + continue; + + if (servrec->serv.type & SV_TYPE_BACKUP_BROWSER) + { + num_backups++; + continue; + } + + if (servrec->serv.type & SV_TYPE_MASTER_BROWSER) + continue; + + if (!(servrec->serv.type & SV_TYPE_POTENTIAL_BROWSER)) + continue; + + DEBUG(3,("num servers: %d num backups: %d\n", + num_servers, num_backups)); + + /* make first server a backup server. thereafter make every + tenth server a backup server */ + if (num_backups != 0 && (num_servers+9) / num_backups > 10) + continue; + + DEBUG(2,("sending become backup to %s %s for %s\n", + servrec->serv.name, inet_ntoa(subrec->bcast_ip), + work->work_group)); + + /* type 11 request from MYNAME(20) to WG(1e) for SERVER */ + do_announce_request(servrec->serv.name, work->work_group, + ANN_BecomeBackup, 0x20, 0x1e, subrec->bcast_ip); + } + } + } +} +#endif + +/******************************************************************* + Process an incoming host announcement packet. +*******************************************************************/ + +void process_host_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf) +{ + struct dgram_packet *dgram = &p->packet.dgram; + int ttl = IVAL(buf,1)/1000; + char *announce_name = buf+5; + uint32 servertype = IVAL(buf,23); + char *comment = buf+31; + struct work_record *work; + struct server_record *servrec; + char *work_name; + char *source_name = dgram->source_name.name; + + comment[43] = 0; + + DEBUG(3,("process_host_announce: from %s<%02x> IP %s to \ +%s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip), + namestr(&dgram->dest_name),announce_name)); + + DEBUG(5,("process_host_announce: ttl=%d server type=%08x comment=%s\n", + ttl, servertype,comment)); + + /* Filter servertype to remove impossible bits. */ + servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM); + + /* A host announcement must be sent to the name WORKGROUP<1d>. */ + if(dgram->dest_name.name_type != 0x1d) + { + DEBUG(2,("process_host_announce: incorrect name type for destination from IP %s \ +(was %02x) should be 0x1d. Allowing packet anyway.\n", + inet_ntoa(p->ip), dgram->dest_name.name_type)); + /* Change it so it was. */ + dgram->dest_name.name_type = 0x1d; + } + + /* For a host announce the workgroup name is the destination name. */ + work_name = dgram->dest_name.name; + + /* + * We are being very agressive here in adding a workgroup + * name on the basis of a host announcing itself as being + * in that workgroup. Maybe we should wait for the workgroup + * announce instead ? JRA. + */ + + if ((work = find_workgroup_on_subnet(subrec, work_name))==NULL) + { + /* We have no record of this workgroup. Add it. */ + if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL) + return; + } + + if((servrec = find_server_in_workgroup( work, announce_name))==NULL) + { + /* If this server is not already in the workgroup, add it. */ + create_server_on_workgroup(work, announce_name, + servertype|SV_TYPE_LOCAL_LIST_ONLY, + ttl, comment); + } + else + { + /* Update the record. */ + servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; + update_server_ttl( servrec, ttl); + StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1); + } + + subrec->work_changed = True; +} + +/******************************************************************* + Process an incoming WORKGROUP announcement packet. +*******************************************************************/ + +void process_workgroup_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf) +{ + struct dgram_packet *dgram = &p->packet.dgram; + int ttl = IVAL(buf,1)/1000; + char *workgroup_announce_name = buf+5; + uint32 servertype = IVAL(buf,23); + char *master_name = buf+31; + struct work_record *work; + char *source_name = dgram->source_name.name; + + master_name[43] = 0; + + DEBUG(3,("process_workgroup_announce: from %s<%02x> IP %s to \ +%s for workgroup %s.\n", source_name, source_name[15], inet_ntoa(p->ip), + namestr(&dgram->dest_name),workgroup_announce_name)); + + DEBUG(5,("process_workgroup_announce: ttl=%d server type=%08x master browser=%s\n", + ttl, servertype, master_name)); + + /* Workgroup announcements must only go to the MSBROWSE name. */ + if (!strequal(dgram->dest_name.name, MSBROWSE) || (dgram->dest_name.name_type != 0x1)) + { + DEBUG(0,("process_workgroup_announce: from IP %s should be to __MSBROWSE__<0x01> not %s\n", + inet_ntoa(p->ip), namestr(&dgram->dest_name))); + return; + } + + if ((work = find_workgroup_on_subnet(subrec, workgroup_announce_name))==NULL) + { + /* We have no record of this workgroup. Add it. */ + if((work = create_workgroup_on_subnet(subrec, workgroup_announce_name, ttl))==NULL) + return; + } + else + { + /* Update the workgroup death_time. */ + update_workgroup_ttl(work, ttl); + } + + if(*work->local_master_browser_name == '\0') + { + /* Set the master browser name. */ + StrnCpy(work->local_master_browser_name, master_name, + sizeof(work->local_master_browser_name)-1); + + } + + subrec->work_changed = True; +} + +/******************************************************************* + Process an incoming local master browser announcement packet. +*******************************************************************/ + +void process_local_master_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf) +{ + struct dgram_packet *dgram = &p->packet.dgram; + int ttl = IVAL(buf,1)/1000; + char *server_name = buf+5; + uint32 servertype = IVAL(buf,23); + char *comment = buf+31; + char *work_name; + struct work_record *work; + struct server_record *servrec; + char *source_name = dgram->source_name.name; + + comment[43] = 0; + + DEBUG(3,("process_local_master_announce: from %s<%02x> IP %s to \ +%s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip), + namestr(&dgram->dest_name),server_name)); + + DEBUG(5,("process_local_master_announce: ttl=%d server type=%08x comment=%s\n", + ttl, servertype, comment)); + + /* A local master announcement must be sent to the name WORKGROUP<1e>. */ + if(dgram->dest_name.name_type != 0x1e) + { + DEBUG(0,("process_local_master_announce: incorrect name type for destination from IP %s \ +(was %02x) should be 0x1e. Ignoring packet.\n", + inet_ntoa(p->ip), dgram->dest_name.name_type)); + return; + } + + /* Filter servertype to remove impossible bits. */ + servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM); + + /* For a local master announce the workgroup name is the destination name. */ + work_name = dgram->dest_name.name; + + if ((work = find_workgroup_on_subnet(subrec, work_name))==NULL) + { + /* We have no record of this workgroup. Add it. */ + if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL) + return; + } + + /* If we think we're the local master browser for this workgroup, + we should never have got this packet. We don't see our own + packets. + */ + if(AM_LOCAL_MASTER_BROWSER(work)) + { + DEBUG(0,("process_local_master_announce: Server %s at IP %s is announcing itself as \ +a local master browser for workgroup %s and we think we are master. Forcing election.\n", + server_name, inet_ntoa(p->ip), work_name)); + + /* Samba nmbd versions 1.9.17 to 1.9.17p4 have a bug in that when + they have become a local master browser once, they will never + stop sending local master announcements. To fix this we send + them a reset browser packet, with level 0x2 on the __SAMBA__ + name that only they should be listening to. */ + + send_browser_reset( 0x2, "__SAMBA__" , 0x20, p->ip); + + /* We should demote ourself and force an election. */ + + unbecome_local_master_browser( subrec, work); + + /* The actual election requests are handled in + nmbd_election.c */ + + work->needelection = True; + return; + } + + /* Find the server record on this workgroup. If it doesn't exist, add it. */ + + if((servrec = find_server_in_workgroup( work, server_name))==NULL) + { + /* If this server is not already in the workgroup, add it. */ + create_server_on_workgroup(work, server_name, + servertype|SV_TYPE_LOCAL_LIST_ONLY, + ttl, comment); + } + else + { + /* Update the record. */ + servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; + update_server_ttl(servrec, ttl); + StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1); + } + + /* Set the master browser name. */ + StrnCpy(work->local_master_browser_name, server_name, + sizeof(work->local_master_browser_name)-1); + + subrec->work_changed = True; +} + +/******************************************************************* + Process a domain master announcement frame. + Domain master browsers receive these from local masters. The Domain + master should then issue a sync with the local master, asking for + that machines local server list. +******************************************************************/ + +void process_master_browser_announce(struct subnet_record *subrec, + struct packet_struct *p,char *buf) +{ + char *local_master_name = buf; + struct work_record *work; + struct browse_cache_record *browrec; + + local_master_name[15] = 0; + + DEBUG(3,("process_master_browser_announce: Local master announce from %s IP %s.\n", + local_master_name, inet_ntoa(p->ip))); + + if (!lp_domain_master()) + { + DEBUG(0,("process_master_browser_announce: Not configured as domain \ +master - ignoring master announce.\n")); + return; + } + + if((work = find_workgroup_on_subnet(subrec, myworkgroup)) == NULL) + { + DEBUG(0,("process_master_browser_announce: Cannot find workgroup %s on subnet %s\n", + myworkgroup, subrec->subnet_name)); + return; + } + + if(!AM_DOMAIN_MASTER_BROWSER(work)) + { + DEBUG(0,("process_master_browser_announce: Local master announce made to us from \ +%s IP %s and we are not a domain master browser.\n", local_master_name, inet_ntoa(p->ip))); + return; + } + + /* Add this host as a local master browser entry on the browse lists. + This causes a sync request to be made to it at a later date. + */ + + if((browrec = find_browser_in_lmb_cache( local_master_name )) == NULL) + { + /* Add it. */ + create_browser_in_lmb_cache( work->work_group, local_master_name, p->ip); + } + else + update_browser_death_time(browrec); +} + +/**************************************************************************** + Send a backup list response. +*****************************************************************************/ + +static void send_backup_list_response(struct subnet_record *subrec, + struct work_record *work, + struct nmb_name *send_to_name, + unsigned char max_number_requested, + uint32 token, struct in_addr sendto_ip) +{ + char outbuf[1024]; + char *p, *countptr, *nameptr; + int count = 0; + int len; + struct server_record *servrec; + + bzero(outbuf,sizeof(outbuf)); + + DEBUG(3,("send_backup_list_response: sending backup list for workgroup %s to %s IP %s\n", + work->work_group, namestr(send_to_name), inet_ntoa(sendto_ip))); + + p = outbuf; + + SCVAL(p,0,ANN_GetBackupListResp); /* Backup list response opcode. */ + p++; + + countptr = p; + p++; + + SIVAL(p,0,token); /* The sender's unique info. */ + p += 4; + + nameptr = p; + + /* We always return at least one name - our own. */ + count = 1; + StrnCpy(p,myname,15); + strupper(p); + p = skip_string(p,1); + + /* Look for backup browsers in this workgroup. */ + for (servrec = work->serverlist; servrec; servrec = servrec->next) + { + len = PTR_DIFF(p, outbuf); + if((sizeof(outbuf) - len) < 16) + break; + + if(count >= max_number_requested) + break; + + if(strnequal(servrec->serv.name, myname,15)) + continue; + + if(!(servrec->serv.type & SV_TYPE_BACKUP_BROWSER)) + continue; + + StrnCpy(p, servrec->serv.name, 15); + strupper(p); + count++; + + DEBUG(5,("send_backup_list_response: Adding server %s number %d\n", + p, count)); + + p = skip_string(p,1); + } + + SCVAL(countptr, 0, count); + + len = PTR_DIFF(p, outbuf); + + DEBUG(4,("send_backup_list_response: sending response to %s<00> IP %s with %d servers.\n", + send_to_name->name, inet_ntoa(sendto_ip), count)); + + send_mailslot(True, BROWSE_MAILSLOT, + outbuf,PTR_DIFF(p,outbuf), + myname, 0, + send_to_name->name,0, + sendto_ip, subrec->myip); +} + +/******************************************************************* + Process a send backup list request packet. + + A client sends a backup list request to ask for a list of servers on + the net that maintain server lists for a domain. A server is then + chosen from this list to send NetServerEnum commands to to list + available servers. + +********************************************************************/ + +void process_get_backup_list_request(struct subnet_record *subrec, + struct packet_struct *p,char *buf) +{ + struct dgram_packet *dgram = &p->packet.dgram; + struct work_record *work; + unsigned char max_number_requested = CVAL(buf,0); + uint32 token = IVAL(buf,1); /* Sender's key index for the workgroup. */ + int name_type = dgram->dest_name.name_type; + char *workgroup_name = dgram->dest_name.name; + + DEBUG(3,("process_get_backup_list_request: request from %s IP %s to %s.\n", + namestr(&dgram->source_name), inet_ntoa(p->ip), + namestr(&dgram->dest_name))); + + /* We have to be a master browser, or a domain master browser + for the requested workgroup. That means it must be our + workgroup. */ + + if(strequal(workgroup_name, myworkgroup) == False) + { + DEBUG(7,("process_get_backup_list_request: Ignoring announce request for workgroup %s.\n", + workgroup_name)); + return; + } + + if((work = find_workgroup_on_subnet(subrec, workgroup_name)) == NULL) + { + DEBUG(0,("process_get_backup_list_request: Cannot find workgroup %s on \ +subnet %s.\n", workgroup_name, subrec->subnet_name)); + return; + } + + if(name_type == 0x1b) + { + /* We must be a domain master browser in order to + process this packet. */ + + if(!AM_DOMAIN_MASTER_BROWSER(work)) + { + DEBUG(0,("process_get_backup_list_request: domain list requested for workgroup %s \ +and I am not a domain master browser.\n", workgroup_name)); + return; + } + } + else if (name_type == 0x1d) + { + /* We must be a local master browser in order to + process this packet. */ + + if(!AM_LOCAL_MASTER_BROWSER(work)) + { + DEBUG(0,("process_get_backup_list_request: domain list requested for workgroup %s \ +and I am not a local master browser.\n", workgroup_name)); + return; + } + } + else + { + DEBUG(0,("process_get_backup_list_request: Invalid name type %x - should be 0x1b or 0x1d.\n", + name_type)); + return; + } + + send_backup_list_response(subrec, work, &dgram->source_name, + max_number_requested, token, p->ip); +} + +/******************************************************************* + Process a reset browser state packet. + + Diagnostic packet: + 0x1 - Stop being a master browser and become a backup browser. + 0x2 - Discard browse lists, stop being a master browser, try again. + 0x4 - Stop being a master browser forever. + +******************************************************************/ + +void process_reset_browser(struct subnet_record *subrec, + struct packet_struct *p,char *buf) +{ + struct dgram_packet *dgram = &p->packet.dgram; + int state = CVAL(buf,0); + struct subnet_record *sr; + + DEBUG(1,("process_reset_browser: received diagnostic browser reset \ +request from %s IP %s state=0x%X\n", + namestr(&dgram->source_name), inet_ntoa(p->ip), state)); + + /* Stop being a local master browser on all our broadcast subnets. */ + if (state & 0x1) + { + for (sr = FIRST_SUBNET; sr; sr = NEXT_SUBNET_EXCLUDING_UNICAST(sr)) + { + struct work_record *work; + for (work = sr->workgrouplist; work; work = work->next) + { + if (AM_LOCAL_MASTER_BROWSER(work)) + { + unbecome_local_master_browser(sr, work); + work->needelection = True; + } + } + } + } + + /* Discard our browse lists. */ + if (state & 0x2) + { + /* + * Calling expire_workgroups_and_servers with a -1 + * time causes all servers not marked with a PERMANENT_TTL + * on the workgroup lists to be discarded, and all + * workgroups with empty server lists to be discarded. + * This means we keep our own server names and workgroup + * as these have a PERMANENT_TTL. + */ + + expire_workgroups_and_servers(-1); + } + + /* Request to stop browsing altogether. */ + if (state & 0x4) + DEBUG(1,("process_reset_browser: ignoring request to stop being a browser.\n")); +} + +/******************************************************************* + Process a announcement request packet. + We don't respond immediately, we just check it's a request for + out workgroup and then set the flag telling the announce code + in nmbd_sendannounce.c:announce_my_server_names that an + announcement is needed soon. + ******************************************************************/ + +void process_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf) +{ + struct dgram_packet *dgram = &p->packet.dgram; + struct work_record *work; + char *workgroup_name = dgram->dest_name.name; + + DEBUG(3,("process_announce_request: Announce request from %s IP %s to %s.\n", + namestr(&dgram->source_name), inet_ntoa(p->ip), + namestr(&dgram->dest_name))); + + /* We only send announcement requests on our workgroup. */ + if(strequal(workgroup_name, myworkgroup) == False) + { + DEBUG(7,("process_announce_request: Ignoring announce request for workgroup %s.\n", + workgroup_name)); + return; + } + + if((work = find_workgroup_on_subnet(subrec, workgroup_name)) == NULL) + { + DEBUG(0,("process_announce_request: Unable to find workgroup %s on subnet !\n", + workgroup_name)); + return; + } + + work->needannounce = True; +} diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c new file mode 100644 index 0000000000..ff4bb07a45 --- /dev/null +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -0,0 +1,556 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1994-1997 + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + This file contains all the code to process NetBIOS requests coming + in on port 137. It does not deal with the code needed to service + WINS server requests, but only broadcast and unicast requests. + +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; + +/**************************************************************************** +Send a name release response. +**************************************************************************/ + +static void send_name_release_response(int rcode, struct packet_struct *p) +{ + struct nmb_packet *nmb = &p->packet.nmb; + char rdata[6]; + + memcpy(&rdata[0], &nmb->additional->rdata[0], 6); + + reply_netbios_packet(p, /* Packet to reply to. */ + rcode, /* Result code. */ + NMB_REL, /* nmbd type code. */ + NMB_NAME_RELEASE_OPCODE, /* opcode. */ + 0, /* ttl. */ + rdata, /* data to send. */ + 6); /* data length. */ +} + +/**************************************************************************** +Process a name release packet on a broadcast subnet. +Ignore it if it's not one of our names. +****************************************************************************/ + +void process_name_release_request(struct subnet_record *subrec, + struct packet_struct *p) +{ + struct nmb_packet *nmb = &p->packet.nmb; + struct in_addr owner_ip; + struct nmb_name *question = &nmb->question.question_name; + BOOL bcast = nmb->header.nm_flags.bcast; + uint16 nb_flags = get_nb_flags(nmb->additional->rdata); + BOOL group = (nb_flags & NB_GROUP) ? True : False; + struct name_record *namerec; + int rcode = 0; + + putip((char *)&owner_ip,&nmb->additional->rdata[2]); + + if(!bcast) + { + /* We should only get broadcast name release packets here. + Anyone trying to release unicast should be going to a WINS + server. If the code gets here, then either we are not a wins + server and they sent it anyway, or we are a WINS server and + the request was malformed. Either way, log an error here. + and send an error reply back. + */ + DEBUG(0,("process_name_release_request: unicast name release request \ +received for name %s from IP %s on subnet %s. Error - should be sent to WINS server\n", + namestr(question), inet_ntoa(owner_ip), subrec->subnet_name)); + + send_name_release_response(FMT_ERR, p); + return; + } + + DEBUG(3,("process_name_release_request: Name release on name %s, \ +subnet %s from owner IP %s\n", + namestr(&nmb->question.question_name), + subrec->subnet_name, inet_ntoa(owner_ip))); + + /* If someone is releasing a broadcast group name, just ignore it. */ + if( group && !ismyip(owner_ip) ) + return; + + namerec = find_name_on_subnet(subrec, &nmb->question.question_name, FIND_ANY_NAME); + + /* We only care about someone trying to release one of our names. */ + if (namerec && ((namerec->source == SELF_NAME) || (namerec->source == PERMANENT_NAME))) + { + rcode = ACT_ERR; + DEBUG(0, ("process_name_release_request: Attempt to release name %s from IP %s \ +on subnet %s being rejected as it is one of our names.\n", + namestr(&nmb->question.question_name), inet_ntoa(owner_ip), subrec->subnet_name)); + } + + if(rcode == 0) + return; + + /* Send a NAME RELEASE RESPONSE (pos/neg) see rfc1002.txt 4.2.10-11 */ + send_name_release_response(rcode, p); +} + +/**************************************************************************** +Send a name registration response. +**************************************************************************/ + +static void send_name_registration_response(int rcode, int ttl, struct packet_struct *p) +{ + struct nmb_packet *nmb = &p->packet.nmb; + char rdata[6]; + + memcpy(&rdata[0], &nmb->additional->rdata[0], 6); + + reply_netbios_packet(p, /* Packet to reply to. */ + rcode, /* Result code. */ + NMB_REG, /* nmbd type code. */ + NMB_NAME_REG_OPCODE, /* opcode. */ + ttl, /* ttl. */ + rdata, /* data to send. */ + 6); /* data length. */ +} + +/**************************************************************************** +Process a name refresh request on a broadcast subnet. +**************************************************************************/ + +void process_name_refresh_request(struct subnet_record *subrec, + struct packet_struct *p) +{ + + struct nmb_packet *nmb = &p->packet.nmb; + struct nmb_name *question = &nmb->question.question_name; + BOOL bcast = nmb->header.nm_flags.bcast; + struct in_addr from_ip; + + putip((char *)&from_ip,&nmb->additional->rdata[2]); + + if(!bcast) + { + /* We should only get broadcast name refresh packets here. + Anyone trying to refresh unicast should be going to a WINS + server. If the code gets here, then either we are not a wins + server and they sent it anyway, or we are a WINS server and + the request was malformed. Either way, log an error here. + and send an error reply back. + */ + DEBUG(0,("process_name_refresh_request: unicast name registration request \ +received for name %s from IP %s on subnet %s. Error - should be sent to WINS server\n", + namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + + send_name_registration_response(FMT_ERR, 0, p); + return; + } + + /* Just log a message. We really don't care about broadcast name + refreshes. */ + + DEBUG(3,("process_name_refresh_request: Name refresh for name %s \ +IP %s on subnet %s\n", namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + +} + +/**************************************************************************** +Process a name registration request on a broadcast subnet. +**************************************************************************/ + +void process_name_registration_request(struct subnet_record *subrec, + struct packet_struct *p) +{ + struct nmb_packet *nmb = &p->packet.nmb; + struct nmb_name *question = &nmb->question.question_name; + BOOL bcast = nmb->header.nm_flags.bcast; + uint16 nb_flags = get_nb_flags(nmb->additional->rdata); + BOOL group = (nb_flags & NB_GROUP) ? True : False; + struct name_record *namerec = NULL; + int ttl = nmb->additional->ttl; + struct in_addr from_ip; + + putip((char *)&from_ip,&nmb->additional->rdata[2]); + + if(!bcast) + { + /* We should only get broadcast name registration packets here. + Anyone trying to register unicast should be going to a WINS + server. If the code gets here, then either we are not a wins + server and they sent it anyway, or we are a WINS server and + the request was malformed. Either way, log an error here. + and send an error reply back. + */ + DEBUG(0,("process_name_registration_request: unicast name registration request \ +received for name %s from IP %s on subnet %s. Error - should be sent to WINS server\n", + namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + + send_name_registration_response(FMT_ERR, 0, p); + return; + } + + DEBUG(3,("process_name_registration_request: Name registration for name %s \ +IP %s on subnet %s\n", namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + + /* See if the name already exists. */ + namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); + + if (!group) + { + /* Unique name. */ + + if ((namerec != NULL) && + ((namerec->source == SELF_NAME) || (namerec->source == PERMANENT_NAME) || + NAME_GROUP(namerec)) + ) + { + /* No-one can register one of Samba's names, nor can they + register a name that's a group name as a unique name */ + + send_name_registration_response(ACT_ERR, 0, p); + return; + } + else if(namerec != NULL) + { + /* Update the namelist record with the new information. */ + namerec->ip[0] = from_ip; + update_name_ttl(namerec, ttl); + + DEBUG(3,("process_name_registration_request: Updated name record %s \ +with IP %s on subnet %s\n",namestr(&namerec->name),inet_ntoa(from_ip), subrec->subnet_name)); + return; + } + } + else + { + /* Group name. */ + + if((namerec != NULL) && !NAME_GROUP(namerec) && + ((namerec->source == SELF_NAME) || (namerec->source == PERMANENT_NAME)) + ) + { + /* Disallow group names when we have a unique name. */ + send_name_registration_response(ACT_ERR, 0, p); + return; + } + } +} + +/**************************************************************************** +This is used to sort names for a name status into a sensible order. +We put our own names first, then in alphabetical order. +**************************************************************************/ + +static int status_compare(char *n1,char *n2) +{ + extern pstring myname; + int l1,l2,l3; + + /* It's a bit tricky because the names are space padded */ + for (l1=0;l1<15 && n1[l1] && n1[l1] != ' ';l1++) ; + for (l2=0;l2<15 && n2[l2] && n2[l2] != ' ';l2++) ; + l3 = strlen(myname); + + if ((l1==l3) && strncmp(n1,myname,l3) == 0 && + (l2!=l3 || strncmp(n2,myname,l3) != 0)) + return -1; + + if ((l2==l3) && strncmp(n2,myname,l3) == 0 && + (l1!=l3 || strncmp(n1,myname,l3) != 0)) + return 1; + + return memcmp(n1,n2,18); +} + + +/**************************************************************************** + Process a node status query + ****************************************************************************/ + +void process_node_status_request(struct subnet_record *subrec, struct packet_struct *p) +{ + struct nmb_packet *nmb = &p->packet.nmb; + char *qname = nmb->question.question_name.name; + int ques_type = nmb->question.question_name.name_type; + char rdata[MAX_DGRAM_SIZE]; + char *countptr, *buf, *bufend, *buf0; + int names_added,i; + struct name_record *namerec; + + DEBUG(3,("process_node_status_request: status request for name %s from IP %s on \ +subnet %s.\n", namestr(&nmb->question.question_name), inet_ntoa(p->ip), + subrec->subnet_name)); + + if((namerec = find_name_on_subnet(subrec, &nmb->question.question_name, + FIND_SELF_NAME)) == 0) + { + DEBUG(1,("process_node_status_request: status request for name %s from IP %s on \ +subnet %s - name not found.\n", namestr(&nmb->question.question_name), + inet_ntoa(p->ip), subrec->subnet_name)); + + return; + } + + /* XXXX hack, we should calculate exactly how many will fit. */ + bufend = &rdata[MAX_DGRAM_SIZE] - 18; + countptr = buf = rdata; + buf += 1; + buf0 = buf; + + names_added = 0; + + namerec = subrec->namelist; + + while (buf < bufend) + { + if ((namerec->source == SELF_NAME) || (namerec->source == PERMANENT_NAME)) + { + int name_type = namerec->name.name_type; + + if (!strequal(namerec->name.name,"*") && + !strequal(namerec->name.name,"__SAMBA__") && + (name_type < 0x1b || name_type >= 0x20 || + ques_type < 0x1b || ques_type >= 0x20 || + strequal(qname, namerec->name.name))) + { + /* Start with the name. */ + bzero(buf,18); + sprintf(buf,"%-15.15s",namerec->name.name); + strupper(buf); + + /* Put the name type and netbios flags in the buffer. */ + buf[15] = name_type; + set_nb_flags(&buf[16],namerec->nb_flags); + buf[16] |= NB_ACTIVE; /* all our names are active */ + + buf += 18; + + names_added++; + } + } + + /* Remove duplicate names. */ + qsort(buf0,names_added,18,QSORT_CAST status_compare); + + for (i=1;inext; + + if (!namerec) + { + /* End of the subnet specific name list. Now + add the names on the unicast subnet . */ + struct subnet_record *uni_subrec = unicast_subnet; + + if (uni_subrec != subrec) + { + subrec = uni_subrec; + namerec = subrec->namelist; + } + } + if (!namerec) + break; + + } + + SCVAL(countptr,0,names_added); + + /* We don't send any stats as they could be used to attack + the protocol. */ + bzero(buf,64); + + buf += 46; + + /* Send a NODE STATUS RESPONSE */ + reply_netbios_packet(p, /* Packet to reply to. */ + 0, /* Result code. */ + NMB_STATUS, /* nmbd type code. */ + NMB_NAME_QUERY_OPCODE, /* opcode. */ + 0, /* ttl. */ + rdata, /* data to send. */ + PTR_DIFF(buf,rdata)); /* data length. */ +} + + +/*************************************************************************** +Process a name query. + +For broadcast name queries: + + - Only reply if the query is for one of YOUR names. + - NEVER send a negative response to a broadcast query. + +****************************************************************************/ + +void process_name_query_request(struct subnet_record *subrec, struct packet_struct *p) +{ + struct nmb_packet *nmb = &p->packet.nmb; + struct nmb_name *question = &nmb->question.question_name; + int name_type = question->name_type; + BOOL bcast = nmb->header.nm_flags.bcast; + int ttl=0; + int rcode = 0; + char *prdata = NULL; + char rdata[6]; + BOOL success = False; + struct name_record *namerec = NULL; + int reply_data_len = 0; + int i; + + DEBUG(3,("process_name_query_request: Name query from %s on subnet %s for name %s\n", + inet_ntoa(p->ip), subrec->subnet_name, namestr(question))); + + /* Look up the name in the cache - if the request is a broadcast request that + came from a subnet we don't know about then search all the broadcast subnets + for a match (as we don't know what interface the request came in on). */ + + if(subrec == remote_broadcast_subnet) + namerec = find_name_for_remote_broadcast_subnet( question, FIND_ANY_NAME); + else + namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); + + + /* Check if it is a name that expired */ + if (namerec && ((namerec->death_time != PERMANENT_TTL) && (namerec->death_time < p->timestamp))) + { + DEBUG(5,("process_name_query_request: expired name %s\n", namestr(&namerec->name))); + namerec = NULL; + } + + if (namerec) + { + + /* + * Always respond to unicast queries. + * Don't respond to broadcast queries unless the query is for + * a name we own, a Primary Domain Controller name, or a WINS_PROXY + * name with type 0 or 0x20. WINS_PROXY names are only ever added + * into the namelist if we were configured as a WINS proxy. + */ + + if (!bcast || + (bcast && ((name_type == 0x1b) || (namerec->source == SELF_NAME) || + (namerec->source == PERMANENT_NAME) || + ((namerec->source == WINS_PROXY_NAME) && ((name_type == 0) || (name_type == 0x20))))) + ) + { + + /* The requested name is a directed query, or it's SELF or PERMANENT or WINS_PROXY, + or it's a Domain Master type. */ + + ttl = (namerec->death_time != PERMANENT_TTL) ? + namerec->death_time - p->timestamp : lp_max_ttl(); + + /* Copy all known ip addresses into the return data. */ + /* Optimise for the common case of one IP address so + we don't need a malloc. */ + + if(namerec->num_ips == 1 ) + prdata = rdata; + else + { + if((prdata = (char *)malloc( namerec->num_ips * 6 )) == NULL) + { + DEBUG(0,("process_name_query_request: malloc fail !\n")); + return; + } + } + + for( i = 0; i < namerec->num_ips; i++) + { + set_nb_flags(&prdata[i*6],namerec->nb_flags); + putip((char *)&prdata[2+(i*6)], &namerec->ip[i]); + } + reply_data_len = namerec->num_ips * 6; + success = True; + } + } + + /* + * If a machine is broadcasting a name lookup request and we have lp_wins_proxy() + * set we should initiate a WINS query here. On success we add the resolved name + * into our namelist with a type of WINS_PROXY_NAME and then reply to the query. + */ + + if(!success && (namerec == NULL) && we_are_a_wins_client() && lp_wins_proxy() && + bcast && (subrec != remote_broadcast_subnet)) + { + make_wins_proxy_name_query_request( subrec, p, question ); + return; + } + + if (!success && bcast) + { + if((prdata != rdata) && (prdata != NULL)) + free(rdata); + return; /* Never reply with a negative response to broadcasts. */ + } + + /* + * Final check. From observation, if a unicast packet is sent + * to a non-WINS server with the recursion desired bit set + * then never send a negative response. + */ + + if(!success && !bcast && nmb->header.nm_flags.recursion_desired) + { + if((prdata != rdata) && (prdata != NULL)) + free(rdata); + return; + } + + if (success) + { + rcode = 0; + DEBUG(3,("OK\n")); + } + else + { + rcode = NAM_ERR; + DEBUG(3,("UNKNOWN\n")); + } + + /* See rfc1002.txt 4.2.13. */ + + reply_netbios_packet(p, /* Packet to reply to. */ + rcode, /* Result code. */ + NMB_QUERY, /* nmbd type code. */ + NMB_NAME_QUERY_OPCODE, /* opcode. */ + ttl, /* ttl. */ + prdata, /* data to send. */ + reply_data_len); /* data length. */ + + if((prdata != rdata) && (prdata != NULL)) + free(prdata); +} diff --git a/source3/nmbd/nmbd_lmhosts.c b/source3/nmbd/nmbd_lmhosts.c new file mode 100644 index 0000000000..2dd1db81cd --- /dev/null +++ b/source3/nmbd/nmbd_lmhosts.c @@ -0,0 +1,168 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + Revision History: + + Handle lmhosts file reading. + +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; + +/**************************************************************************** +Load a lmhosts file. +****************************************************************************/ +void load_lmhosts_file(char *fname) +{ + FILE *fp = fopen(fname,"r"); + pstring line; + if (!fp) { + DEBUG(2,("load_lmhosts_file: Can't open lmhosts file %s. Error was %s\n", + fname, strerror(errno))); + return; + } + + while (!feof(fp)) + { + pstring ip,name,flags,extra; + struct subnet_record *subrec = NULL; + char *ptr; + int count = 0; + struct in_addr ipaddr; + enum name_source source = LMHOSTS_NAME; + int name_type = -1; + + if (!fgets_slash(line,sizeof(pstring),fp)) + continue; + + if (*line == '#') + continue; + + strcpy(ip,""); + strcpy(name,""); + strcpy(flags,""); + + ptr = line; + + if (next_token(&ptr,ip ,NULL)) + ++count; + if (next_token(&ptr,name ,NULL)) + ++count; + if (next_token(&ptr,flags,NULL)) + ++count; + if (next_token(&ptr,extra,NULL)) + ++count; + + if (count <= 0) + continue; + + if (count > 0 && count < 2) + { + DEBUG(0,("load_lmhosts_file: Ill formed hosts line [%s]\n",line)); + continue; + } + + if (count >= 4) + { + DEBUG(0,("load_lmhosts_file: too many columns in lmhosts file %s (obsolete syntax)\n", + fname)); + continue; + } + + DEBUG(4, ("load_lmhosts_file: lmhost entry: %s %s %s\n", ip, name, flags)); + + if (strchr(flags,'G') || strchr(flags,'S')) + { + DEBUG(0,("load_lmhosts_file: group flag in %s ignored (obsolete)\n",fname)); + continue; + } + + ipaddr = *interpret_addr2(ip); + + /* Extra feature. If the name ends in '#XX', where XX is a hex number, + then only add that name type. */ + if((ptr = strchr(name, '#')) != NULL) + { + char *endptr; + + ptr++; + name_type = (int)strtol(ptr, &endptr,0); + + if(!*ptr || (endptr == ptr)) + { + DEBUG(0,("load_lmhosts_file: invalid name %s containing '#'.\n", name)); + continue; + } + + *(--ptr) = '\0'; /* Truncate at the '#' */ + } + + /* We find a relevent subnet to put this entry on, then add it. */ + /* Go through all the broadcast subnets and see if the mask matches. */ + for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + { + if(same_net(ipaddr, subrec->bcast_ip, subrec->mask_ip)) + break; + } + + /* If none match add the name to the remote_broadcast_subnet. */ + if(subrec == NULL) + subrec = remote_broadcast_subnet; + + if(name_type == -1) + { + /* Add the (0) and (0x20) names directly into the namelist for this subnet. */ + add_name_to_subnet(subrec,name,0x00,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr); + add_name_to_subnet(subrec,name,0x20,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr); + } + else + { + /* Add the given name type to the subnet namelist. */ + add_name_to_subnet(subrec,name,name_type,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr); + } + } + + fclose(fp); +} + +/**************************************************************************** + Find a name read from the lmhosts file. We secretly check the names on + the remote_broadcast_subnet as if the name was added to a regular broadcast + subnet it will be found by normal name query processing. +****************************************************************************/ + +BOOL find_name_in_lmhosts(struct nmb_name *nmbname, struct name_record **namerecp) +{ + struct name_record *namerec; + + *namerecp = NULL; + + if((namerec = find_name_on_subnet(remote_broadcast_subnet, nmbname, + FIND_ANY_NAME))==NULL) + return False; + + if(!NAME_IS_ACTIVE(namerec) || (namerec->source != LMHOSTS_NAME)) + return False; + + *namerecp = namerec; + return True; +} diff --git a/source3/nmbd/nmbd_logonnames.c b/source3/nmbd/nmbd_logonnames.c new file mode 100644 index 0000000000..b2431ec0a7 --- /dev/null +++ b/source3/nmbd/nmbd_logonnames.c @@ -0,0 +1,166 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1994-1997 + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; + +extern pstring scope; +extern pstring myname; +extern fstring myworkgroup; +extern char **my_netbios_names; +extern struct in_addr ipzero; +extern struct in_addr allones_ip; + +extern uint16 samba_nb_type; /* Samba's NetBIOS type. */ + +/**************************************************************************** + Fail to become a Logon server on a subnet. + ****************************************************************************/ +static void become_logon_server_fail(struct subnet_record *subrec, + struct response_record *rrec, + struct nmb_name *fail_name) +{ + struct work_record *work = find_workgroup_on_subnet(subrec, fail_name->name); + struct server_record *servrec; + + if(!work) + { + DEBUG(0,("become_logon_server_fail: Error - cannot find \ +workgroup %s on subnet %s\n", fail_name->name, subrec->subnet_name)); + return; + } + + if((servrec = find_server_in_workgroup( work, myname)) == NULL) + { + DEBUG(0,("become_logon_server_fail: Error - cannot find server %s \ +in workgroup %s on subnet %s\n", + myname, fail_name->name, subrec->subnet_name)); + work->log_state = LOGON_NONE; + return; + } + + /* Set the state back to LOGON_NONE. */ + work->log_state = LOGON_NONE; + + servrec->serv.type &= ~SV_TYPE_DOMAIN_CTRL; + + DEBUG(0,("become_logon_server_fail: Failed to become a domain master for \ +workgroup %s on subnet %s. Couldn't register name %s.\n", + work->work_group, subrec->subnet_name, namestr(fail_name))); + +} + +/**************************************************************************** + Become a Logon server on a subnet. + ****************************************************************************/ + +static void become_logon_server_success(struct subnet_record *subrec, + struct userdata_struct *userdata, + struct nmb_name *registered_name, + uint16 nb_flags, + int ttl, struct in_addr registered_ip) +{ + struct work_record *work = find_workgroup_on_subnet( subrec, registered_name->name); + struct server_record *servrec; + + if(!work) + { + DEBUG(0,("become_logon_server_success: Error - cannot find \ +workgroup %s on subnet %s\n", registered_name->name, subrec->subnet_name)); + return; + } + + if((servrec = find_server_in_workgroup( work, myname)) == NULL) + { + DEBUG(0,("become_logon_server_success: Error - cannot find server %s \ +in workgroup %s on subnet %s\n", + myname, registered_name->name, subrec->subnet_name)); + work->log_state = LOGON_NONE; + return; + } + + /* Set the state in the workgroup structure. */ + work->log_state = LOGON_SRV; /* Become domain master. */ + + /* Update our server status. */ + servrec->serv.type |= (SV_TYPE_NT|SV_TYPE_DOMAIN_MEMBER); + /* To allow Win95 policies to load we need to set type domain + controller. + */ + servrec->serv.type |= SV_TYPE_DOMAIN_CTRL; + + /* Tell the namelist writer to write out a change. */ + subrec->work_changed = True; + + DEBUG(0,("become_logon_server_success: Samba is now a logon server\ +for workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name)); +} + +/******************************************************************* + Become a logon server by attempting to register the WORKGROUP<1c> + group name. +******************************************************************/ + +static void become_logon_server(struct subnet_record *subrec, + struct work_record *work) +{ + DEBUG(2,("become_logon_server: Atempting to become logon server for workgroup %s \ +on subnet %s\n", work->work_group,subrec->subnet_name)); + + DEBUG(3,("become_logon_server: go to first stage: register %s<1c> name\n", + work->work_group)); + work->log_state = LOGON_WAIT; + + register_name(subrec, work->work_group,0x1c,samba_nb_type|NB_GROUP, + become_logon_server_success, + become_logon_server_fail, NULL); +} + +/***************************************************************************** + Add the internet group <1c> logon names by unicast and broadcast. + ****************************************************************************/ +void add_logon_names(void) +{ + struct subnet_record *subrec; + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) + { + struct work_record *work = find_workgroup_on_subnet(subrec, myworkgroup); + + if (work && (work->log_state == LOGON_NONE)) + { + struct nmb_name nmbname; + make_nmb_name(&nmbname,myworkgroup,0x1c,scope); + + if (find_name_on_subnet(subrec, &nmbname, FIND_SELF_NAME) == NULL) + { + DEBUG(0,("add_domain_logon_names: At time %s attempting to become \ +logon server for workgroup %s on subnet %s\n", timestring(), myworkgroup, + subrec->subnet_name)); + become_logon_server(subrec, work); + } + } + } +} diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c new file mode 100644 index 0000000000..660b545069 --- /dev/null +++ b/source3/nmbd/nmbd_mynames.c @@ -0,0 +1,165 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1994-1997 + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; + +extern char **my_netbios_names; +extern pstring myname; +extern fstring myworkgroup; + +extern uint16 samba_nb_type; /* Samba's NetBIOS type. */ + +/**************************************************************************** + Fail funtion when registering my netbios names. + **************************************************************************/ + +static void my_name_register_failed(struct subnet_record *subrec, + struct response_record *rrec, struct nmb_name *nmbname) +{ + DEBUG(0,("my_name_register_failed: Failed to register my name %s on subnet %s.\n", + namestr(nmbname), subrec->subnet_name)); +} + +/**************************************************************************** + Add my workgroup and my given names to the subnet lists. + Also add the magic Samba names. + **************************************************************************/ + +BOOL register_my_workgroup_and_names() +{ + struct subnet_record *subrec; + struct work_record *work; + int i; + + for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) + { + /* Create the workgroup on the subnet. */ + if((work = create_workgroup_on_subnet(subrec, myworkgroup, PERMANENT_TTL)) == NULL) + { + DEBUG(0,("register_my_workgroup_and_names: Failed to create my workgroup %s on subnet %s. \ +Exiting.\n", myworkgroup, subrec->subnet_name)); + return False; + } + + /* Each subnet entry, except for the remote_announce_broadcast subnet + and the wins_server_subnet has the magic Samba names. */ + add_samba_names_to_subnet(subrec); + + /* Register all our names including aliases. */ + for (i=0; my_netbios_names[i]; i++) + { + register_name(subrec, my_netbios_names[i],0x20,samba_nb_type, + NULL, + my_name_register_failed, NULL); + register_name(subrec, my_netbios_names[i],0x03,samba_nb_type, + NULL, + my_name_register_failed, NULL); + register_name(subrec, my_netbios_names[i],0x00,samba_nb_type, + NULL, + my_name_register_failed, NULL); + } + + /* Initiate election processing, register the workgroup names etc. */ + initiate_myworkgroup_startup(subrec, work); + } + + /* If we are not a WINS client, we still need to add the magic Samba + names and the netbios names to the unicast subnet directly. This is + to allow unicast node status requests and queries to still work + in a broadcast only environment. */ + + if(we_are_a_wins_client() == False) + { + add_samba_names_to_subnet(unicast_subnet); + + for (i=0; my_netbios_names[i]; i++) + { + add_name_to_subnet(unicast_subnet, my_netbios_names[i],0x20,samba_nb_type, PERMANENT_TTL, + SELF_NAME, 1, &FIRST_SUBNET->myip); + + add_name_to_subnet(unicast_subnet, my_netbios_names[i],0x3,samba_nb_type, PERMANENT_TTL, + SELF_NAME, 1, &FIRST_SUBNET->myip); + + add_name_to_subnet(unicast_subnet, my_netbios_names[i],0x0,samba_nb_type, PERMANENT_TTL, + SELF_NAME, 1, &FIRST_SUBNET->myip); + } + } + + return True; +} + +/**************************************************************************** + Remove all the names we registered. +**************************************************************************/ + +void release_my_names() +{ + struct subnet_record *subrec; + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) + { + struct name_record *namerec, *nextnamerec; + + for (namerec = subrec->namelist; namerec; namerec = nextnamerec) + { + nextnamerec = namerec->next; + if ((namerec->source == SELF_NAME) && !NAME_IS_DEREGISTERING(namerec)) + release_name(subrec, namerec, standard_success_release, + NULL, NULL); + } + } +} + +/******************************************************************* + Refresh our registered names. + ******************************************************************/ + +void refresh_my_names(time_t t) +{ + struct subnet_record *subrec; + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) + { + struct name_record *namerec; + + for (namerec = subrec->namelist; namerec; namerec = namerec->next) + { + /* Each SELF name has an individual time to be refreshed. */ + if ((namerec->source == SELF_NAME) && (namerec->refresh_time < t) && + (namerec->death_time != PERMANENT_TTL)) + { + /* We cheat here and pretend the refresh is going to be + successful & update the refresh times. This stops + multiple refresh calls being done. We actually + deal with refresh failure in the fail_fn. + */ + refresh_name(subrec, namerec, NULL, NULL, NULL); + namerec->death_time += lp_max_ttl(); + namerec->refresh_time += lp_max_ttl(); + } + } + } +} diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c new file mode 100644 index 0000000000..dfd8a80baa --- /dev/null +++ b/source3/nmbd/nmbd_namelistdb.c @@ -0,0 +1,586 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1994-1997 + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; + +extern pstring scope; +extern char **my_netbios_names; + +uint16 samba_nb_type = 0; /* samba's NetBIOS name type */ + + +/**************************************************************************** + Set Samba's NetBIOS name type. + ****************************************************************************/ + +void set_samba_nb_type(void) +{ + if (lp_wins_support() || (*lp_wins_server())) + samba_nb_type = NB_MFLAG; /* samba is a 'hybrid' node type */ + else + samba_nb_type = NB_BFLAG; /* samba is broadcast-only node type */ +} + +/**************************************************************************** + Returns True if the netbios name is ^1^2__MSBROWSE__^2^1. + + Note: This name is registered if as a master browser or backup browser + you are responsible for a workgroup (when you announce a domain by + broadcasting on your local subnet, you announce it as coming from this + name: see announce_host()). + + **************************************************************************/ + +BOOL ms_browser_name(char *name, int type) +{ + return (strequal(name,MSBROWSE) && (type == 0x01)); +} + +/**************************************************************************** + Add a netbios name into a namelist. + **************************************************************************/ + +static void add_name_to_namelist(struct subnet_record *subrec, + struct name_record *namerec) +{ + struct name_record *namerec2; + + if (!subrec->namelist) + { + subrec->namelist = namerec; + namerec->prev = NULL; + namerec->next = NULL; + return; + } + + for (namerec2 = subrec->namelist; namerec2->next; namerec2 = namerec2->next) + ; + + namerec2->next = namerec; + namerec->next = NULL; + namerec->prev = namerec2; + namerec->subnet = subrec; + + subrec->namelist_changed = True; +} + +/**************************************************************************** + Remove a name from the namelist. + **************************************************************************/ + +void remove_name_from_namelist(struct subnet_record *subrec, + struct name_record *namerec) +{ + if (namerec->next) + namerec->next->prev = namerec->prev; + if (namerec->prev) + namerec->prev->next = namerec->next; + + if(namerec == subrec->namelist) + subrec->namelist = namerec->next; + + if(namerec->ip != NULL) + free((char *)namerec->ip); + free((char *)namerec); + + subrec->namelist_changed = True; +} + + +/**************************************************************************** + Find a name in a subnet. + **************************************************************************/ + +struct name_record *find_name_on_subnet(struct subnet_record *subrec, + struct nmb_name *nmbname, BOOL self_only) +{ + struct name_record *namerec = subrec->namelist; + struct name_record *name_ret; + + for (name_ret = namerec; name_ret; name_ret = name_ret->next) + { + if (nmb_name_equal(&name_ret->name, nmbname)) + { + /* Self names only - these include permanent names. */ + if (self_only && (name_ret->source != SELF_NAME) && + (name_ret->source != PERMANENT_NAME) ) + { + continue; + } + DEBUG(9,("find_name_on_subnet: on subnet %s - found name %s source=%d\n", + subrec->subnet_name, namestr(nmbname), name_ret->source)); + return name_ret; + } + } + DEBUG(9,("find_name_on_subnet: on subnet %s - name %s NOT FOUND\n", + subrec->subnet_name, namestr(nmbname))); + return NULL; +} + +/**************************************************************************** + Find a name over all known broadcast subnets. +**************************************************************************/ + +struct name_record *find_name_for_remote_broadcast_subnet( struct nmb_name *nmbname, + BOOL self_only) +{ + struct subnet_record *subrec; + struct name_record *namerec = NULL; + + for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + { + if((namerec = find_name_on_subnet(subrec, nmbname, self_only))!= NULL) + break; + } + + return namerec; +} + +/**************************************************************************** + Update the ttl of an entry in a subnet name list. + ****************************************************************************/ + +void update_name_ttl(struct name_record *namerec, int ttl) +{ + time_t time_now = time(NULL); + + if(namerec->death_time != PERMANENT_TTL) + namerec->death_time = time_now + ttl; + + namerec->refresh_time = time_now + (ttl/2); + + namerec->subnet->namelist_changed = True; +} + +/**************************************************************************** + Add an entry to a subnet name list. + ****************************************************************************/ + +struct name_record *add_name_to_subnet(struct subnet_record *subrec, + char *name, int type, uint16 nb_flags, int ttl, + enum name_source source, int num_ips, struct in_addr *iplist) +{ + struct name_record *namerec; + time_t time_now = time(NULL); + + if((namerec = (struct name_record *)malloc(sizeof(*namerec))) == NULL) + { + DEBUG(0,("add_name_to_subnet: malloc fail.\n")); + return NULL; + } + + bzero((char *)namerec,sizeof(*namerec)); + + namerec->subnet = subrec; + + namerec->num_ips = num_ips; + namerec->ip = (struct in_addr *)malloc(sizeof(struct in_addr) * namerec->num_ips); + if (!namerec->ip) + { + DEBUG(0,("add_name_to_subnet: malloc fail when creating ip_flgs.\n")); + free((char *)namerec); + return NULL; + } + + bzero((char *)namerec->ip, sizeof(struct in_addr) * namerec->num_ips); + + memcpy(&namerec->ip[0], iplist, num_ips * sizeof(struct in_addr)); + + make_nmb_name(&namerec->name,name,type,scope); + + /* Setup the death_time and refresh_time. */ + if(ttl == PERMANENT_TTL) + namerec->death_time = PERMANENT_TTL; + else + namerec->death_time = time_now + ttl; + + namerec->refresh_time = time_now + (ttl/2); + + /* Enter the name as active. */ + namerec->nb_flags = nb_flags | NB_ACTIVE; + + /* If it's our primary name, flag it as so. */ + if(strequal(my_netbios_names[0],name)) + namerec->nb_flags |= NB_PERM; + + namerec->source = source; + + add_name_to_namelist(subrec,namerec); + + DEBUG(3,("add_name_to_subnet: Added netbios name %s with first IP %s ttl=%d nb_flags=%2x to subnet %s\n", + namestr(&namerec->name),inet_ntoa(*iplist),ttl,(unsigned int)nb_flags, + subrec->subnet_name)); + + subrec->namelist_changed = True; + + return(namerec); +} + +/******************************************************************* + Utility function automatically called when a name refresh or register + succeeds. By definition this is a SELF_NAME (or we wouldn't be registering + it). + ******************************************************************/ + +void standard_success_register(struct subnet_record *subrec, + struct userdata_struct *userdata, + struct nmb_name *nmbname, uint16 nb_flags, int ttl, + struct in_addr registered_ip) +{ + struct name_record *namerec = find_name_on_subnet(subrec, nmbname, FIND_SELF_NAME); + + if(namerec == NULL) + add_name_to_subnet(subrec, nmbname->name, nmbname->name_type, + nb_flags, ttl, SELF_NAME, 1, ®istered_ip); + else + update_name_ttl(namerec, ttl); +} + +/******************************************************************* + Utility function automatically called when a name refresh or register + fails. + ******************************************************************/ + +void standard_fail_register(struct subnet_record *subrec, + struct response_record *rrec, struct nmb_name *nmbname) +{ + struct name_record *namerec = find_name_on_subnet(subrec, nmbname, FIND_SELF_NAME); + + DEBUG(0,("standard_fail_register: Failed to register/refresh name %s on subnet %s\n", + namestr(nmbname), subrec->subnet_name)); + + /* Remove the name from the subnet. */ + if(namerec) + remove_name_from_namelist(subrec, namerec); +} + +/******************************************************************* + Utility function to remove an IP address from a name record. + ******************************************************************/ + +static void remove_nth_ip_in_record( struct name_record *namerec, int ind) +{ + if(ind != namerec->num_ips) + memmove( (char *)(&namerec->ip[ind]), (char *)(&namerec->ip[ind+1]), + ( namerec->num_ips - ind - 1) * sizeof(struct in_addr)); + + namerec->num_ips--; + namerec->subnet->namelist_changed = True; +} + +/******************************************************************* + Utility function to check if an IP address exists in a name record. + ******************************************************************/ + +BOOL find_ip_in_name_record(struct name_record *namerec, struct in_addr ip) +{ + int i; + + for(i = 0; i < namerec->num_ips; i++) + if(ip_equal( namerec->ip[i], ip)) + return True; + + return False; +} + +/******************************************************************* + Utility function to add an IP address to a name record. + ******************************************************************/ + +void add_ip_to_name_record(struct name_record *namerec, struct in_addr new_ip) +{ + struct in_addr *new_list; + + /* Don't add one we already have. */ + if(find_ip_in_name_record( namerec, new_ip)) + return; + + if((new_list = (struct in_addr *)malloc( (namerec->num_ips + 1)*sizeof(struct in_addr)) )== NULL) + { + DEBUG(0,("add_ip_to_name_record: Malloc fail !\n")); + return; + } + + memcpy((char *)new_list, (char *)namerec->ip, namerec->num_ips *sizeof(struct in_addr)); + new_list[namerec->num_ips] = new_ip; + + free((char *)namerec->ip); + namerec->ip = new_list; + namerec->num_ips += 1; + + namerec->subnet->namelist_changed = True; +} + +/******************************************************************* + Utility function to remove an IP address from a name record. + ******************************************************************/ + +void remove_ip_from_name_record( struct name_record *namerec, struct in_addr remove_ip) +{ + /* Try and find the requested ip address - remove it. */ + int i; + int orig_num = namerec->num_ips; + + for(i = 0; i < orig_num; i++) + if( ip_equal( remove_ip, namerec->ip[i]) ) + { + remove_nth_ip_in_record( namerec, i); + break; + } +} + +/******************************************************************* + Utility function that release_name callers can plug into as the + success function when a name release is successful. Used to save + duplication of success_function code. + ******************************************************************/ + +void standard_success_release(struct subnet_record *subrec, + struct userdata_struct *userdata, + struct nmb_name *nmbname, struct in_addr released_ip) +{ + struct name_record *namerec = find_name_on_subnet(subrec, nmbname, FIND_ANY_NAME); + + if(namerec == NULL) + { + DEBUG(0,("standard_success_release: Name release for name %s IP %s on subnet %s. Name \ +was not found on subnet.\n", namestr(nmbname), inet_ntoa(released_ip), subrec->subnet_name)); + return; + } + else + { + int orig_num = namerec->num_ips; + + remove_ip_from_name_record( namerec, released_ip); + + if(namerec->num_ips == orig_num) + DEBUG(0,("standard_success_release: Name release for name %s IP %s on subnet %s. This ip \ +is not known for this name.\n", namestr(nmbname), inet_ntoa(released_ip), subrec->subnet_name )); + } + + if (namerec->num_ips == 0) + remove_name_from_namelist(subrec, namerec); +} + +/******************************************************************* + Expires old names in a subnet namelist. + ******************************************************************/ + +void expire_names_on_subnet(struct subnet_record *subrec, time_t t) +{ + struct name_record *namerec; + struct name_record *next_namerec; + + for (namerec = subrec->namelist; namerec; namerec = next_namerec) + { + next_namerec = namerec->next; + if ((namerec->death_time != PERMANENT_TTL) && (namerec->death_time < t)) + { + if (namerec->source == SELF_NAME) + { + DEBUG(3,("expire_names_on_subnet: Subnet %s not expiring SELF name %s\n", + subrec->subnet_name, namestr(&namerec->name))); + namerec->death_time += 300; + namerec->subnet->namelist_changed = True; + continue; + } + DEBUG(3,("expire_names_on_subnet: Subnet %s - removing expired name %s\n", + subrec->subnet_name, namestr(&namerec->name))); + + remove_name_from_namelist(subrec, namerec); + } + } +} + +/******************************************************************* + Expires old names in all subnet namelists. + ******************************************************************/ + +void expire_names(time_t t) +{ + struct subnet_record *subrec; + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) + { + expire_names_on_subnet(subrec, t); + } +} + +/**************************************************************************** + Add the magic samba names, useful for finding samba servers. + These go directly into the name list for a particular subnet, + without going through the normal registration process. + When adding them to the unicast subnet, add them as a list of + all broadcast subnet IP addresses. +**************************************************************************/ + +void add_samba_names_to_subnet(struct subnet_record *subrec) +{ + struct in_addr *iplist = &subrec->myip; + int num_ips = 1; + + /* These names are added permanently (ttl of zero) and will NOT be + refreshed. */ + + if((subrec == unicast_subnet) || (subrec == wins_server_subnet)) + { + struct subnet_record *bcast_subrecs; + int i; + /* Create an IP list containing all our known subnets. */ + + num_ips = iface_count(); + if((iplist = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr) )) == NULL) + { + DEBUG(0,("add_samba_names_to_subnet: Malloc fail !\n")); + return; + } + + for(bcast_subrecs = FIRST_SUBNET, i = 0; bcast_subrecs; + bcast_subrecs = NEXT_SUBNET_EXCLUDING_UNICAST(bcast_subrecs), i++) + iplist[i] = bcast_subrecs->myip; + + } + + add_name_to_subnet(subrec,"*",0x0,samba_nb_type, PERMANENT_TTL, + PERMANENT_NAME, num_ips, iplist); + add_name_to_subnet(subrec,"*",0x20,samba_nb_type,PERMANENT_TTL, + PERMANENT_NAME, num_ips, iplist); + add_name_to_subnet(subrec,"__SAMBA__",0x20,samba_nb_type,PERMANENT_TTL, + PERMANENT_NAME, num_ips, iplist); + add_name_to_subnet(subrec,"__SAMBA__",0x00,samba_nb_type,PERMANENT_TTL, + PERMANENT_NAME, num_ips, iplist); + + if(iplist != &subrec->myip) + free((char *)iplist); +} + +/**************************************************************************** + Dump the contents of the namelists on all the subnets (including unicast) + into a file. Initiated by SIGHUP - used to debug the state of the namelists. +**************************************************************************/ + +static void dump_subnet_namelist( struct subnet_record *subrec, FILE *fp) +{ + struct name_record *namerec; + char *src_type; + struct tm *tm; + int i; + + fprintf(fp, "Subnet %s\n----------------------\n", subrec->subnet_name); + for (namerec = subrec->namelist; namerec; namerec = namerec->next) + { + fprintf(fp,"\tName = %s\t", namestr(&namerec->name)); + switch(namerec->source) + { + case LMHOSTS_NAME: + src_type = "LMHOSTS_NAME"; + break; + case WINS_PROXY_NAME: + src_type = "WINS_PROXY_NAME"; + break; + case REGISTER_NAME: + src_type = "REGISTER_NAME"; + break; + case SELF_NAME: + src_type = "SELF_NAME"; + break; + case DNS_NAME: + src_type = "DNS_NAME"; + break; + case DNSFAIL_NAME: + src_type = "DNSFAIL_NAME"; + break; + case PERMANENT_NAME: + src_type = "PERMANENT_NAME"; + break; + default: + src_type = "unknown!"; + break; + } + fprintf(fp, "Source = %s\nb_flags = %x\t", src_type, namerec->nb_flags); + + if(namerec->death_time != PERMANENT_TTL) + { + tm = LocalTime(&namerec->death_time); + fprintf(fp, "death_time = %s\t", asctime(tm)); + } + else + fprintf(fp, "death_time = PERMANENT\t"); + + if(namerec->refresh_time != PERMANENT_TTL) + { + tm = LocalTime(&namerec->refresh_time); + fprintf(fp, "refresh_time = %s\n", asctime(tm)); + } + else + fprintf(fp, "refresh_time = PERMANENT\n"); + + fprintf(fp, "\t\tnumber of IPS = %d", namerec->num_ips); + for(i = 0; i < namerec->num_ips; i++) + fprintf(fp, "\t%s", inet_ntoa(namerec->ip[i])); + + fprintf(fp, "\n\n"); + } +} + +/**************************************************************************** + Dump the contents of the namelists on all the subnets (including unicast) + into a file. Initiated by SIGHUP - used to debug the state of the namelists. +**************************************************************************/ + +void dump_all_namelists() +{ + fstring fname; + FILE *fp; + struct subnet_record *subrec; + + pstrcpy(fname,lp_lockdir()); + trim_string(fname,NULL,"/"); + strcat(fname,"/"); + strcat(fname,"namelist.debug"); + + fp = fopen(fname,"w"); + + if (!fp) + { + DEBUG(0,("dump_all_namelists: Can't open file %s. Error was %s\n", + fname,strerror(errno))); + return; + } + + for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) + dump_subnet_namelist( subrec, fp); + + if(!we_are_a_wins_client()) + dump_subnet_namelist(unicast_subnet, fp); + + if(remote_broadcast_subnet->namelist != NULL) + dump_subnet_namelist(remote_broadcast_subnet, fp); + + if(wins_server_subnet != NULL) + dump_subnet_namelist( wins_server_subnet, fp); + fclose(fp); +} diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c new file mode 100644 index 0000000000..5d98935fec --- /dev/null +++ b/source3/nmbd/nmbd_namequery.c @@ -0,0 +1,234 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1994-1997 + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; + +extern pstring scope; + +/**************************************************************************** + Deal with a response packet when querying a name. +****************************************************************************/ + +static void query_name_response(struct subnet_record *subrec, + struct response_record *rrec, struct packet_struct *p) +{ + struct nmb_packet *nmb = &p->packet.nmb; + BOOL success = False; + struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name; + struct in_addr answer_ip; + + /* Ensure we don't retry the query but leave the response record cleanup + to the timeout code. We may get more answer responses in which case + we should mark the name in conflict.. */ + rrec->repeat_count = 0; + + if(rrec->num_msgs == 1) + { + /* This is the first response. */ + + if(nmb->header.opcode == NMB_WACK_OPCODE) + { + /* WINS server is telling us to wait. Pretend we didn't get + the response but don't send out any more query requests. */ + + DEBUG(5,("query_name_response: WACK from WINS server %s in querying \ +name %s on subnet %s.\n", inet_ntoa(p->ip), namestr(question_name), subrec->subnet_name)); + + rrec->repeat_count = 0; + /* How long we should wait for. */ + rrec->repeat_time = p->timestamp + nmb->answers->ttl; + rrec->num_msgs--; + return; + } + else if(nmb->header.rcode != 0) + { + success = False; + + DEBUG(5,("query_name_response: On subnet %s - negative response \ +from IP %s for name %s. Error code was %d.\n", subrec->subnet_name, inet_ntoa(p->ip), + namestr(question_name), nmb->header.rcode)); + } + else + { + success = True; + + putip((char *)&answer_ip,&nmb->answers->rdata[2]); + DEBUG(5,("query_name_response: On subnet %s - positive response from IP %s\ +for name %s. IP of that name is %s\n", subrec->subnet_name, inet_ntoa(p->ip), + namestr(question_name), inet_ntoa(answer_ip))); + + /* Interestingly, we could add these names to our namelists, and + change nmbd to a model that checked its own name cache first, + before sending out a query. This is a task for another day, though. + */ + } + } + else if( rrec->num_msgs > 1) + { + DEBUG(0,("query_name_response: Multiple (%d) responses received for a query on \ +subnet %s for name %s. This response was from IP %s\n", + rrec->num_msgs, subrec->subnet_name, namestr(question_name), + inet_ntoa(rrec->packet->ip) )); + + /* We have already called the success or fail function, so we + don't call again here. Leave the response record around in + case we get more responses. */ + + return; + } + + if(success && rrec->success_fn) + (*rrec->success_fn)(subrec, rrec->userdata, question_name, answer_ip, nmb->answers); + else if( rrec->fail_fn) + (*rrec->fail_fn)(subrec, rrec, question_name, nmb->header.rcode); + +} + +/**************************************************************************** + Deal with a timeout when querying a name. +****************************************************************************/ + +static void query_name_timeout_response(struct subnet_record *subrec, + struct response_record *rrec) +{ + struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb; + /* We can only fail here, never succeed. */ + BOOL failed = True; + struct nmb_name *question_name = &sent_nmb->question.question_name; + + if(rrec->num_msgs != 0) + { + /* We got at least one response, and have called the success/fail + function already. */ + + failed = False; + } + + if(failed) + { + DEBUG(5,("query_name_timeout_response: No response to querying name %s on subnet %s.\n", + namestr(question_name), subrec->subnet_name)); + + if(rrec->fail_fn) + (*rrec->fail_fn)(subrec, rrec, question_name, 0); + } + + remove_response_record(subrec, rrec); +} + +/**************************************************************************** + Lookup a name on our local namelists. We check the lmhosts file first. If the + name is not there we look for the name on the given subnet. +****************************************************************************/ + +static BOOL query_local_namelists(struct subnet_record *subrec, struct nmb_name *nmbname, + struct name_record **namerecp) +{ + struct name_record *namerec; + + *namerecp = NULL; + + if(find_name_in_lmhosts(nmbname, namerecp)) + return True; + + if((namerec = find_name_on_subnet(subrec, nmbname, FIND_ANY_NAME))==NULL) + return False; + + if(NAME_IS_ACTIVE(namerec) && ((namerec->source == SELF_NAME) || + (namerec->source == LMHOSTS_NAME)) ) + { + *namerecp = namerec; + return True; + } + return False; +} + +/**************************************************************************** + Try and query for a name. +****************************************************************************/ + +BOOL query_name(struct subnet_record *subrec, char *name, int type, + query_name_success_function success_fn, + query_name_fail_function fail_fn, + struct userdata_struct *userdata) +{ + struct nmb_name nmbname; + struct name_record *namerec; + + make_nmb_name(&nmbname, name, type, scope); + + /* + * We need to check our local namelists first. + * It may be an magic name, lmhosts name or just + * a name we have registered. + */ + + if(query_local_namelists(subrec, &nmbname, &namerec) == True) + { + struct res_rec rrec; + int i; + + bzero((char *)&rrec, sizeof(struct res_rec)); + + /* Fake up the needed res_rec just in case it's used. */ + rrec.rr_name = nmbname; + rrec.rr_type = RR_TYPE_NB; + rrec.rr_class = RR_CLASS_IN; + rrec.ttl = PERMANENT_TTL; + rrec.rdlength = namerec->num_ips * 6; + if(rrec.rdlength > MAX_DGRAM_SIZE) + { + DEBUG(0,("query_name: nmbd internal error - there are %d ip addresses for name %s.\n", + namerec->num_ips, namestr(&nmbname) )); + return False; + } + + for( i = 0; i < namerec->num_ips; i++) + { + set_nb_flags( &rrec.rdata[i*6], namerec->nb_flags ); + putip( &rrec.rdata[(i*6) + 2], (char *)&namerec->ip[i]); + } + + /* Call the success function directly. */ + if(success_fn) + (*success_fn)(subrec, userdata, &nmbname, namerec->ip[0], &rrec); + return False; + } + + if(queue_query_name( subrec, + query_name_response, + query_name_timeout_response, + success_fn, + fail_fn, + userdata, + &nmbname) == NULL) + { + DEBUG(0,("query_name: Failed to send packet trying to query name %s\n", + namestr(&nmbname))); + return True; + } + return False; +} diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c new file mode 100644 index 0000000000..603daaa531 --- /dev/null +++ b/source3/nmbd/nmbd_nameregister.c @@ -0,0 +1,390 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1994-1997 + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; + +extern pstring scope; +extern fstring myworkgroup; + +/**************************************************************************** + Deal with a response packet when registering one of our names. +****************************************************************************/ + +static void register_name_response(struct subnet_record *subrec, + struct response_record *rrec, struct packet_struct *p) +{ + /* + * If we are registering broadcast, then getting a response is an + * error - we do not have the name. If we are registering unicast, + * then we expect to get a response. + */ + + struct nmb_packet *nmb = &p->packet.nmb; + BOOL bcast = nmb->header.nm_flags.bcast; + BOOL success = True; + struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name; + struct nmb_name *answer_name = &nmb->answers->rr_name; + int ttl; + uint16 nb_flags; + struct in_addr registered_ip; + + /* Sanity check. Ensure that the answer name in the incoming packet is the + same as the requested name in the outgoing packet. */ + + if(!nmb_name_equal(question_name, answer_name)) + { + DEBUG(0,("register_name_response: Answer name %s differs from question \ +name %s.\n", namestr(answer_name), namestr(question_name))); + return; + } + + if(bcast) + { + /* + * Special hack to cope with old Samba nmbd's. + * Earlier versions of Samba (up to 1.9.16p11) respond + * to a broadcast name registration of WORKGROUP<1b> when + * they should not. Hence, until these versions are gone, + * we should treat such errors as success for this particular + * case only. jallison@whistle.com. + */ + +#if 1 /* OLD_SAMBA_SERVER_HACK */ + if((nmb->header.rcode == ACT_ERR) && strequal(myworkgroup, answer_name->name) && + (answer_name->name_type == 0x1b)) + { + /* Pretend we did not get this. */ + rrec->num_msgs--; + + DEBUG(5,("register_name_response: Ignoring broadcast response to \ +registration of name %s due to old Samba server bug.\n", namestr(answer_name))); + return; + } +#endif /* OLD_SAMBA_SERVER_HACK */ + + /* Someone else has the name. Log the problem. */ + DEBUG(1,("register_name_response: Failed to register \ +name %s on subnet %s via broadcast. Error code was %d. Reject came from IP %s\n", + namestr(answer_name), + subrec->subnet_name, nmb->header.rcode, inet_ntoa(p->ip))); + success = False; + } + else + { + /* Unicast - check to see if the response allows us to have the name. */ + if(nmb->header.rcode != 0) + { + /* Error code - we didn't get the name. */ + success = False; + + DEBUG(0,("register_name_response: server at IP %s rejected our \ +name registration of %s with error code %d.\n", inet_ntoa(p->ip), + namestr(answer_name), nmb->header.rcode)); + + } + else if(nmb->header.opcode == NMB_WACK_OPCODE) + { + /* WINS server is telling us to wait. Pretend we didn't get + the response but don't send out any more register requests. */ + + DEBUG(5,("register_name_response: WACK from WINS server %s in registering \ +name %s on subnet %s.\n", inet_ntoa(p->ip), namestr(answer_name), subrec->subnet_name)); + + rrec->repeat_count = 0; + /* How long we should wait for. */ + rrec->repeat_time = p->timestamp + nmb->answers->ttl; + rrec->num_msgs--; + return; + } + else + { + success = True; + /* Get the data we need to pass to the success function. */ + nb_flags = get_nb_flags(nmb->answers->rdata); + putip((char*)®istered_ip,&nmb->answers->rdata[2]); + ttl = nmb->answers->ttl; + } + } + + DEBUG(5,("register_name_response: %s in registering name %s on subnet %s.\n", + success ? "success" : "failure", namestr(answer_name), subrec->subnet_name)); + + if(success) + { + /* Enter the registered name into the subnet name database before calling + the success function. */ + standard_success_register(subrec, rrec->userdata, answer_name, nb_flags, ttl, registered_ip); + if( rrec->success_fn) + (*rrec->success_fn)(subrec, rrec->userdata, answer_name, nb_flags, ttl, registered_ip); + } + else + { + if( rrec->fail_fn) + (*rrec->fail_fn)(subrec, rrec, question_name); + /* Remove the name. */ + standard_fail_register( subrec, rrec, question_name); + } + + /* Ensure we don't retry. */ + remove_response_record(subrec, rrec); +} + +/**************************************************************************** + Deal with a timeout when registering one of our names. +****************************************************************************/ + +static void register_name_timeout_response(struct subnet_record *subrec, + struct response_record *rrec) +{ + /* + * If we are registering unicast, then NOT getting a response is an + * error - we do not have the name. If we are registering broadcast, + * then we don't expect to get a response. + */ + + struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb; + BOOL bcast = sent_nmb->header.nm_flags.bcast; + BOOL success = False; + struct nmb_name *question_name = &sent_nmb->question.question_name; + uint16 nb_flags; + int ttl; + struct in_addr registered_ip; + + if(bcast) + { + if(rrec->num_msgs == 0) + { + /* Not receiving a message is success for broadcast registration. */ + success = True; + + /* Pull the success values from the original request packet. */ + nb_flags = get_nb_flags(sent_nmb->additional->rdata); + ttl = sent_nmb->additional->ttl; + putip(®istered_ip,&sent_nmb->additional->rdata[2]); + } + } + else + { + /* Unicast - if no responses then it's an error. */ + if(rrec->num_msgs == 0) + { + DEBUG(2,("register_name_timeout_response: WINS server at address %s is not \ +responding.\n", inet_ntoa(rrec->packet->ip))); + + /* Keep trying to contact the WINS server periodically. This allows + us to work correctly if the WINS server is down temporarily when + we come up. */ + + /* Reset the number of attempts to zero and double the interval between + retries. Max out at 5 minutes. */ + rrec->repeat_count = 3; + rrec->repeat_interval *= 2; + if(rrec->repeat_interval > (5 * 60)) + rrec->repeat_interval = (5 * 60); + rrec->repeat_time = time(NULL) + rrec->repeat_interval; + + DEBUG(5,("register_name_timeout_response: increasing WINS timeout to %d seconds.\n", + rrec->repeat_interval)); + return; /* Don't remove the response record. */ + } + } + + DEBUG(5,("register_name_timeout_response: %s in registering name %s on subnet %s.\n", + success ? "success" : "failure", namestr(question_name), subrec->subnet_name)); + if(success) + { + /* Enter the registered name into the subnet name database before calling + the success function. */ + standard_success_register(subrec, rrec->userdata, question_name, nb_flags, ttl, registered_ip); + if( rrec->success_fn) + (*rrec->success_fn)(subrec, rrec->userdata, question_name, nb_flags, ttl, registered_ip); + } + else + { + if( rrec->fail_fn) + (*rrec->fail_fn)(subrec, rrec, question_name); + /* Remove the name. */ + standard_fail_register( subrec, rrec, question_name); + } + + /* Ensure we don't retry. */ + remove_response_record(subrec, rrec); +} + +/**************************************************************************** + Try and register one of our names on the unicast subnet - multihomed. +****************************************************************************/ + +static BOOL multihomed_register_name( struct nmb_name *nmbname, uint16 nb_flags, + register_name_success_function success_fn, + register_name_fail_function fail_fn, + struct userdata_struct *userdata) +{ + /* + If we are adding a group name, we just send multiple + register name packets to the WINS server (this is an + internet group name. + + If we are adding a unique name, We need first to add + our names to the unicast subnet namelist. This is + because when a WINS server receives a multihomed + registration request, the first thing it does is to + send a name query to the registering machine, to see + if it has put the name in it's local namelist. + We need the name there so the query response code in + nmbd_incomingrequests.c will find it. + + We are adding this name prematurely (we don't really + have it yet), but as this is on the unicast subnet + only we will get away with this (only the WINS server + will ever query names from us on this subnet). + */ + + int num_ips=0; + int i; + struct in_addr *ip_list = NULL; + struct subnet_record *subrec; + + for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) ) + num_ips++; + + if((ip_list = (struct in_addr *)malloc(num_ips * sizeof(struct in_addr)))==NULL) + { + DEBUG(0,("multihomed_register_name: malloc fail !\n")); + return True; + } + + for(subrec = FIRST_SUBNET, i = 0; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec), i++ ) + ip_list[i] = subrec->myip; + + add_name_to_subnet(unicast_subnet, nmbname->name, nmbname->name_type, + nb_flags, lp_max_ttl(), SELF_NAME, num_ips, ip_list); + + free((char *)ip_list); + + /* Now try and register the name, num_ips times. On the last time use + the given success and fail functions. */ + + for( i = 0; i < num_ips; i++) + { + if(queue_register_multihomed_name( unicast_subnet, + register_name_response, + register_name_timeout_response, + (i == num_ips - 1) ? success_fn : NULL, + (i == num_ips - 1) ? fail_fn : NULL, + (i == num_ips - 1) ? userdata : NULL, + nmbname, + nb_flags, + ip_list[i]) == NULL) + { + DEBUG(0,("multihomed_register_name: Failed to send packet trying to \ +register name %s IP %s\n", namestr(nmbname), inet_ntoa(ip_list[i]) )); + return True; + } + } + + return False; +} + +/**************************************************************************** + Try and register one of our names. +****************************************************************************/ + +BOOL register_name(struct subnet_record *subrec, + char *name, int type, uint16 nb_flags, + register_name_success_function success_fn, + register_name_fail_function fail_fn, + struct userdata_struct *userdata) +{ + struct nmb_name nmbname; + + make_nmb_name(&nmbname, name, type, scope); + + /* Always set the NB_ACTIVE flag on the name we are + registering. Doesn't make sense without it. + */ + + nb_flags |= NB_ACTIVE; + + /* If this is the unicast subnet, and we are a multi-homed + host, then register a multi-homed name. */ + + if( (subrec == unicast_subnet) && we_are_multihomed()) + return multihomed_register_name(&nmbname, nb_flags, + success_fn, fail_fn, + userdata); + + if(queue_register_name( subrec, + register_name_response, + register_name_timeout_response, + success_fn, + fail_fn, + userdata, + &nmbname, + nb_flags) == NULL) + { + DEBUG(0,("register_name: Failed to send packet trying to register name %s\n", + namestr(&nmbname))); + return True; + } + return False; +} + +/**************************************************************************** + Try and refresh one of our names. +****************************************************************************/ + +BOOL refresh_name(struct subnet_record *subrec, struct name_record *namerec, + refresh_name_success_function success_fn, + refresh_name_fail_function fail_fn, + struct userdata_struct *userdata) +{ + int i; + + /* + * Go through and refresh the name for all known ip addresses. + * Only call the success/fail function on the last one (it should + * only be done once). + */ + + for( i = 0; i < namerec->num_ips; i++) + { + if(queue_refresh_name( subrec, + register_name_response, + register_name_timeout_response, + (i == (namerec->num_ips - 1)) ? success_fn : NULL, + (i == (namerec->num_ips - 1)) ? fail_fn : NULL, + (i == (namerec->num_ips - 1)) ? userdata : NULL, + namerec, + namerec->ip[i]) == NULL) + { + DEBUG(0,("refresh_name: Failed to send packet trying to refresh name %s\n", + namestr(&namerec->name))); + return True; + } + } + return False; +} diff --git a/source3/nmbd/nmbd_namerelease.c b/source3/nmbd/nmbd_namerelease.c new file mode 100644 index 0000000000..8632dd7655 --- /dev/null +++ b/source3/nmbd/nmbd_namerelease.c @@ -0,0 +1,238 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1994-1997 + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; + +extern pstring scope; + +/**************************************************************************** + Deal with a response packet when releasing one of our names. +****************************************************************************/ + +static void release_name_response(struct subnet_record *subrec, + struct response_record *rrec, struct packet_struct *p) +{ + /* + * If we are releasing broadcast, then getting a response is an + * error. If we are releasing unicast, then we expect to get a response. + */ + + struct nmb_packet *nmb = &p->packet.nmb; + BOOL bcast = nmb->header.nm_flags.bcast; + BOOL success = True; + struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name; + struct nmb_name *answer_name = &nmb->answers->rr_name; + struct in_addr released_ip; + + /* Sanity check. Ensure that the answer name in the incoming packet is the + same as the requested name in the outgoing packet. */ + + if(!nmb_name_equal(question_name, answer_name)) + { + DEBUG(0,("release_name_response: Answer name %s differs from question \ +name %s.\n", namestr(answer_name), namestr(question_name))); + return; + } + + if(bcast) + { + /* Someone sent a response. This shouldn't happen/ */ + DEBUG(1,("release_name_response: A response for releasing name %s was received on a\ +broadcast subnet %s. This should not happen !\n", namestr(answer_name), subrec->subnet_name)); + return; + } + else + { + /* Unicast - check to see if the response allows us to release the name. */ + if(nmb->header.rcode != 0) + { + /* Error code - we were told not to release the name ! What now ! */ + success = False; + + DEBUG(0,("release_name_response: WINS server at IP %s rejected our \ +name release of name %s with error code %d.\n", inet_ntoa(p->ip), + namestr(answer_name), nmb->header.rcode)); + + } + else if(nmb->header.opcode == NMB_WACK_OPCODE) + { + /* WINS server is telling us to wait. Pretend we didn't get + the response but don't send out any more release requests. */ + + DEBUG(5,("release_name_response: WACK from WINS server %s in releasing \ +name %s on subnet %s.\n", inet_ntoa(p->ip), namestr(answer_name), subrec->subnet_name)); + + rrec->repeat_count = 0; + /* How long we should wait for. */ + rrec->repeat_time = p->timestamp + nmb->answers->ttl; + rrec->num_msgs--; + return; + } + } + + DEBUG(5,("release_name_response: %s in releasing name %s on subnet %s.\n", + success ? "success" : "failure", namestr(answer_name), subrec->subnet_name)); + + if(success) + { + putip((char*)&released_ip ,&nmb->answers->rdata[2]); + + if(rrec->success_fn) + (*rrec->success_fn)(subrec, rrec->userdata, answer_name, released_ip); + standard_success_release( subrec, rrec->userdata, answer_name, released_ip); + } + else + { + /* We have no standard_fail_release - maybe we should add one ? */ + if(rrec->fail_fn) + (*rrec->fail_fn)(subrec, rrec, answer_name); + } + + remove_response_record(subrec, rrec); +} + +/**************************************************************************** + Deal with a timeout when releasing one of our names. +****************************************************************************/ + +static void release_name_timeout_response(struct subnet_record *subrec, + struct response_record *rrec) +{ + /* + * If we are releasing unicast, then NOT getting a response is an + * error - we could not release the name. If we are releasing broadcast, + * then we don't expect to get a response. + */ + + struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb; + BOOL bcast = sent_nmb->header.nm_flags.bcast; + BOOL success = False; + struct nmb_name *question_name = &sent_nmb->question.question_name; + struct in_addr released_ip; + + if(bcast) + { + if(rrec->num_msgs == 0) + { + /* Not receiving a message is success for broadcast release. */ + success = True; + + /* Get the ip address we were trying to release. */ + putip((char*)&released_ip ,&sent_nmb->additional->rdata[2]); + } + } + else + { + /* Unicast - if no responses then it's an error. */ + if(rrec->num_msgs == 0) + { + DEBUG(2,("release_name_timeout_response: WINS server at address %s is not \ +responding.\n", inet_ntoa(rrec->packet->ip))); + + /* Keep trying to contact the WINS server periodically. This allows + us to work correctly if the WINS server is down temporarily when + we want to delete the name. */ + + /* Reset the number of attempts to zero and double the interval between + retries. Max out at 5 minutes. */ + rrec->repeat_count = 3; + rrec->repeat_interval *= 2; + if(rrec->repeat_interval > (5 * 60)) + rrec->repeat_interval = (5 * 60); + rrec->repeat_time = time(NULL) + rrec->repeat_interval; + + DEBUG(5,("release_name_timeout_response: increasing WINS timeout to %d seconds.\n", + rrec->repeat_interval)); + return; /* Don't remove the response record. */ + } + } + + DEBUG(5,("release_name_timeout_response: %s in releasing name %s on subnet %s.\n", + success ? "success" : "failure", namestr(question_name), subrec->subnet_name)); + + if(success && rrec->success_fn) + { + if(rrec->success_fn) + (*rrec->success_fn)(subrec, rrec->userdata, question_name, released_ip); + standard_success_release( subrec, rrec->userdata, question_name, released_ip); + } + else + { + /* We have no standard_fail_release - maybe we should add one ? */ + if( rrec->fail_fn) + (*rrec->fail_fn)(subrec, rrec, question_name); + } + + remove_response_record(subrec, rrec); +} + +/**************************************************************************** + Try and release one of our names. +****************************************************************************/ + +BOOL release_name(struct subnet_record *subrec, struct name_record *namerec, + release_name_success_function success_fn, + release_name_fail_function fail_fn, + struct userdata_struct *userdata) +{ + int i; + + /* Ensure it's a SELF name, and in the ACTIVE state. */ + if((namerec->source != SELF_NAME) || !NAME_IS_ACTIVE(namerec)) + { + DEBUG(0,("release_name: Cannot release name %s from subnet %s. Source was %d \n", + namestr(&namerec->name), subrec->subnet_name, namerec->source)); + return True; + } + + /* Set the name into the deregistering state. */ + namerec->nb_flags |= NB_DEREG; + + /* + * Go through and release the name for all known ip addresses. + * Only call the success/fail function on the last one (it should + * only be done once). + */ + + for( i = 0; i < namerec->num_ips; i++) + { + if(queue_release_name( subrec, + release_name_response, + release_name_timeout_response, + (i == (namerec->num_ips - 1)) ? success_fn : NULL, + (i == (namerec->num_ips - 1)) ? fail_fn : NULL, + (i == (namerec->num_ips - 1)) ? userdata : NULL, + &namerec->name, + namerec->nb_flags, + namerec->ip[i]) == NULL) + { + DEBUG(0,("release_name: Failed to send packet trying to release name %s IP %s\n", + namestr(&namerec->name), inet_ntoa(namerec->ip[i]) )); + return True; + } + } + return False; +} diff --git a/source3/nmbd/nmbd_nodestatus.c b/source3/nmbd/nmbd_nodestatus.c new file mode 100644 index 0000000000..267446c69d --- /dev/null +++ b/source3/nmbd/nmbd_nodestatus.c @@ -0,0 +1,99 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1994-1997 + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; + +extern pstring scope; + +/**************************************************************************** + Deal with a successful node status response. +****************************************************************************/ +static void node_status_response(struct subnet_record *subrec, + struct response_record *rrec, struct packet_struct *p) +{ + struct nmb_packet *nmb = &p->packet.nmb; + struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name; + struct nmb_name *answer_name = &nmb->answers->rr_name; + + /* Sanity check. Ensure that the answer name in the incoming packet is the + same as the requested name in the outgoing packet. */ + + if(!nmb_name_equal(question_name, answer_name)) + { + DEBUG(0,("node_status_response: Answer name %s differs from question \ +name %s.\n", namestr(answer_name), namestr(question_name))); + return; + } + + DEBUG(5,("node_status_response: response from name %s on subnet %s.\n", + namestr(answer_name), subrec->subnet_name)); + + /* Just send the whole answer resource record for the success function + to parse. */ + if(rrec->success_fn) + (*rrec->success_fn)(subrec, rrec->userdata, nmb->answers, p->ip); + + /* Ensure we don't retry. */ + remove_response_record(subrec, rrec); +} + +/**************************************************************************** + Deal with a timeout when requesting a node status. +****************************************************************************/ +static void node_status_timeout_response(struct subnet_record *subrec, + struct response_record *rrec) +{ + struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb; + struct nmb_name *question_name = &sent_nmb->question.question_name; + + DEBUG(5,("node_status_timeout_response: failed to get node status from name %s on subnet %s\n", + namestr(question_name), subrec->subnet_name)); + + if( rrec->fail_fn) + (*rrec->fail_fn)(subrec, rrec); + + /* Ensure we don't retry. */ + remove_response_record(subrec, rrec); +} + +/**************************************************************************** + Try and do a node status to a name - given the name & IP address. +****************************************************************************/ + +BOOL node_status(struct subnet_record *subrec, struct nmb_name *nmbname, + struct in_addr send_ip, node_status_success_function success_fn, + node_status_fail_function fail_fn, struct userdata_struct *userdata) +{ + if(queue_node_status( subrec, + node_status_response, node_status_timeout_response, + success_fn, fail_fn, userdata, nmbname, send_ip)==NULL) + { + DEBUG(0,("node_status: Failed to send packet trying to get node status for \ +name %s, IP address %s\n", namestr(nmbname), inet_ntoa(send_ip))); + return True; + } + return False; +} diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c new file mode 100644 index 0000000000..43249cc0a3 --- /dev/null +++ b/source3/nmbd/nmbd_packets.c @@ -0,0 +1,1775 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1994-1997 + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "includes.h" + +extern int ClientNMB; +extern int ClientDGRAM; +extern int global_nmb_port; + +extern int DEBUGLEVEL; + +extern int num_response_packets; + +extern pstring scope; +extern struct in_addr loopback_ip; + +/******************************************************************* + The global packet linked-list. Incoming entries are + added to the end of this list. It is supposed to remain fairly + short so we won't bother with an end pointer. +******************************************************************/ + +static struct packet_struct *packet_queue = NULL; + +/*************************************************************************** +Utility function to find the specific fd to send a packet out on. +**************************************************************************/ + +static int find_subnet_fd_for_address( struct in_addr local_ip ) +{ + struct subnet_record *subrec; + + for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + if(ip_equal(local_ip, subrec->myip)) + return subrec->nmb_sock; + + return ClientNMB; +} + +/*************************************************************************** +Get/Set problematic nb_flags as network byte order 16 bit int. +**************************************************************************/ + +uint16 get_nb_flags(char *buf) +{ + return ((((uint16)*buf)&0xFFFF) & NB_FLGMSK); +} + +void set_nb_flags(char *buf, uint16 nb_flags) +{ + *buf++ = ((nb_flags & NB_FLGMSK) & 0xFF); + *buf = '\0'; +} + +/*************************************************************************** +Dumps out the browse packet data. +**************************************************************************/ + +static void debug_browse_data(char *outbuf, int len) +{ + int i,j; + for (i = 0; i < len; i+= 16) + { + DEBUG(4, ("%3x char ", i)); + + for (j = 0; j < 16; j++) + { + unsigned char x = outbuf[i+j]; + if (x < 32 || x > 127) + x = '.'; + + if (i+j >= len) + break; + DEBUG(4, ("%c", x)); + } + + DEBUG(4, (" hex ", i)); + + for (j = 0; j < 16; j++) + { + if (i+j >= len) + break; + DEBUG(4, (" %02x", (unsigned char)outbuf[i+j])); + } + + DEBUG(4, ("\n")); + } +} + +/*************************************************************************** + Generates the unique transaction identifier +**************************************************************************/ + +static uint16 name_trn_id=0; + +static uint16 generate_name_trn_id(void) +{ + + if (!name_trn_id) + { + name_trn_id = (time(NULL)%(unsigned)0x7FFF) + (getpid()%(unsigned)100); + } + name_trn_id = (name_trn_id+1) % (unsigned)0x7FFF; + return name_trn_id; +} + +/*************************************************************************** + Either loops back or sends out a completed NetBIOS packet. +**************************************************************************/ + +static BOOL send_netbios_packet(struct packet_struct *p) +{ + BOOL loopback_this_packet = False; + + /* Check if we are sending to or from ourselves as a WINS server. */ + if(ismyip(p->ip) && (p->port == global_nmb_port)) + loopback_this_packet = True; + + if(loopback_this_packet) + { + struct packet_struct *lo_packet = NULL; + DEBUG(5,("send_netbios_packet: sending packet to ourselves.\n")); + if((lo_packet = copy_packet(p)) == NULL) + return False; + queue_packet(lo_packet); + } + else if (!send_packet(p)) + { + DEBUG(0,("send_netbios_packet: send_packet() to IP %s port %d failed\n", + inet_ntoa(p->ip),p->port)); + return False; + } + + return True; +} + +/*************************************************************************** + Sets up the common elements of an outgoing NetBIOS packet. +**************************************************************************/ + +static struct packet_struct *create_and_init_netbios_packet(struct nmb_name *nmbname, + BOOL bcast, + struct in_addr to_ip) +{ + struct packet_struct *packet = NULL; + struct nmb_packet *nmb = NULL; + + /* Allocate the packet_struct we will return. */ + if((packet = (struct packet_struct *)malloc(sizeof(*packet))) == NULL) + { + DEBUG(0,("create_and_init_netbios_packet: malloc fail (1) for packet struct.\n")); + return NULL; + } + + bzero((char *)packet,sizeof(*packet)); + + nmb = &packet->packet.nmb; + + nmb->header.name_trn_id = generate_name_trn_id(); + nmb->header.response = False; + nmb->header.nm_flags.recursion_desired = False; + nmb->header.nm_flags.recursion_available = False; + nmb->header.nm_flags.trunc = False; + nmb->header.nm_flags.authoritative = False; + nmb->header.nm_flags.bcast = bcast; + + nmb->header.rcode = 0; + nmb->header.qdcount = 1; + nmb->header.ancount = 0; + nmb->header.nscount = 0; + + nmb->question.question_name = *nmbname; + nmb->question.question_type = QUESTION_TYPE_NB_QUERY; + nmb->question.question_class = QUESTION_CLASS_IN; + + packet->ip = to_ip; + packet->port = NMB_PORT; + packet->fd = ClientNMB; + packet->timestamp = time(NULL); + packet->packet_type = NMB_PACKET; + packet->locked = False; + + return packet; /* Caller must free. */ +} + +/*************************************************************************** + Sets up the common elements of register, refresh or release packet. +**************************************************************************/ + +static BOOL create_and_init_additional_record(struct packet_struct *packet, + uint16 nb_flags, + struct in_addr *register_ip) +{ + struct nmb_packet *nmb = &packet->packet.nmb; + + if((nmb->additional = (struct res_rec *)malloc(sizeof(struct res_rec))) == NULL) + { + DEBUG(0,("initiate_name_register_packet: malloc fail for additional record.\n")); + return False; + } + + bzero((char *)nmb->additional,sizeof(struct res_rec)); + + nmb->additional->rr_name = nmb->question.question_name; + nmb->additional->rr_type = RR_TYPE_NB; + nmb->additional->rr_class = RR_CLASS_IN; + + nmb->additional->ttl = lp_max_ttl(); + + nmb->additional->rdlength = 6; + + set_nb_flags(nmb->additional->rdata,nb_flags); + + /* Set the address for the name we are registering. */ + putip(&nmb->additional->rdata[2], register_ip); + + /* Ensure that we send out the file descriptor to give us the + the specific source address we are registering as our + IP source address. */ + + packet->fd = find_subnet_fd_for_address( *register_ip ); + + return True; +} + +/*************************************************************************** + Sends out a name query. +**************************************************************************/ + +static BOOL initiate_name_query_packet( struct packet_struct *packet) +{ + struct nmb_packet *nmb = NULL; + + nmb = &packet->packet.nmb; + + nmb->header.opcode = NMB_NAME_QUERY_OPCODE; + nmb->header.arcount = 0; + + nmb->header.nm_flags.recursion_desired = True; + + DEBUG(4,("initiate_name_query_packet: sending query for name %s (bcast=%s) to IP %s\n", + namestr(&nmb->question.question_name), + BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip))); + + return send_netbios_packet( packet ); +} + +/*************************************************************************** + Sends out a name register. +**************************************************************************/ + +static BOOL initiate_name_register_packet( struct packet_struct *packet, + uint16 nb_flags, struct in_addr *register_ip) +{ + struct nmb_packet *nmb = &packet->packet.nmb; + + nmb->header.opcode = NMB_NAME_REG_OPCODE; + nmb->header.arcount = 1; + + nmb->header.nm_flags.recursion_desired = True; + + if(create_and_init_additional_record(packet, nb_flags, register_ip) == False) + return False; + + DEBUG(4,("initiate_name_register_packet: sending registration for name %s (bcast=%s) to IP %s\n", + namestr(&nmb->additional->rr_name), + BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip))); + + return send_netbios_packet( packet ); +} + +/*************************************************************************** + Sends out a multihomed name register. +**************************************************************************/ + +static BOOL initiate_multihomed_name_register_packet( struct packet_struct *packet, + uint16 nb_flags, struct in_addr *register_ip) +{ + struct nmb_packet *nmb = &packet->packet.nmb; + char second_ip_buf[25]; + + strcpy(second_ip_buf, inet_ntoa(packet->ip)); + + nmb->header.opcode = NMB_NAME_MULTIHOMED_REG_OPCODE; + nmb->header.arcount = 1; + + nmb->header.nm_flags.recursion_desired = True; + + if(create_and_init_additional_record(packet, nb_flags, register_ip) == False) + return False; + + DEBUG(4,("initiate_multihomed_name_register_packet: sending registration \ +for name %s IP %s (bcast=%s) to IP %s\n", + namestr(&nmb->additional->rr_name), inet_ntoa(*register_ip), + BOOLSTR(nmb->header.nm_flags.bcast), second_ip_buf )); + + return send_netbios_packet( packet ); +} + +/*************************************************************************** + Sends out a name refresh. +**************************************************************************/ + +static BOOL initiate_name_refresh_packet( struct packet_struct *packet, + uint16 nb_flags, struct in_addr *refresh_ip) +{ + struct nmb_packet *nmb = &packet->packet.nmb; + + nmb->header.opcode = NMB_NAME_REFRESH_OPCODE_8; + nmb->header.arcount = 1; + + nmb->header.nm_flags.recursion_desired = False; + + if(create_and_init_additional_record(packet, nb_flags, refresh_ip) == False) + return False; + + DEBUG(4,("initiate_name_refresh_packet: sending refresh for name %s (bcast=%s) to IP %s\n", + namestr(&nmb->additional->rr_name), + BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip))); + + return send_netbios_packet( packet ); +} + +/*************************************************************************** + Sends out a name release. +**************************************************************************/ + +static BOOL initiate_name_release_packet( struct packet_struct *packet, + uint16 nb_flags, struct in_addr *release_ip) +{ + struct nmb_packet *nmb = &packet->packet.nmb; + + nmb->header.opcode = NMB_NAME_RELEASE_OPCODE; + nmb->header.arcount = 1; + + nmb->header.nm_flags.recursion_desired = False; + + if(create_and_init_additional_record(packet, nb_flags, release_ip) == False) + return False; + + DEBUG(4,("initiate_name_release_packet: sending release for name %s (bcast=%s) to IP %s\n", + namestr(&nmb->additional->rr_name), + BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip))); + + return send_netbios_packet( packet ); +} + +/*************************************************************************** + Sends out a node status. +**************************************************************************/ + +static BOOL initiate_node_status_packet( struct packet_struct *packet ) +{ + struct nmb_packet *nmb = &packet->packet.nmb; + + nmb->header.opcode = NMB_NAME_QUERY_OPCODE; + nmb->header.arcount = 0; + + nmb->header.nm_flags.recursion_desired = False; + + nmb->question.question_type = QUESTION_TYPE_NB_STATUS; + + DEBUG(4,("initiate_node_status_packet: sending node status request for name %s to IP %s\n", + namestr(&nmb->question.question_name), + inet_ntoa(packet->ip))); + + return send_netbios_packet( packet ); +} + +/**************************************************************************** + Simplification functions for queuing standard packets. + These should be the only publicly callable functions for sending + out packets. +****************************************************************************/ + +/**************************************************************************** + Assertion - we should never be sending nmbd packets on the remote + broadcast subnet. +****************************************************************************/ + +static BOOL assert_check_subnet(struct subnet_record *subrec) +{ + if( subrec == remote_broadcast_subnet) + { + DEBUG(0,("assert_check_subnet: Attempt to send packet on remote broadcast subnet. \ +This is a bug.\n")); + return True; + } + return False; +} + +/**************************************************************************** + Queue a register name packet to the broadcast address of a subnet. +****************************************************************************/ + +struct response_record *queue_register_name( struct subnet_record *subrec, + response_function resp_fn, + timeout_response_function timeout_fn, + register_name_success_function success_fn, + register_name_fail_function fail_fn, + struct userdata_struct *userdata, + struct nmb_name *nmbname, + uint16 nb_flags) +{ + struct packet_struct *p; + struct response_record *rrec; + BOOL bcast = (subrec == unicast_subnet) ? False : True; + + if(assert_check_subnet(subrec)) + return NULL; + + if(( p = create_and_init_netbios_packet(nmbname, bcast, + subrec->bcast_ip)) == NULL) + return NULL; + + if(initiate_name_register_packet( p, nb_flags, + iface_ip(subrec->bcast_ip)) == False) + { + p->locked = False; + free_packet(p); + return NULL; + } + + if((rrec = make_response_record(subrec, /* subnet record. */ + p, /* packet we sent. */ + resp_fn, /* function to call on response. */ + timeout_fn, /* function to call on timeout. */ + (success_function)success_fn, /* function to call on operation success. */ + (fail_function)fail_fn, /* function to call on operation fail. */ + userdata)) == NULL) + { + p->locked = False; + free_packet(p); + return NULL; + } + + return rrec; +} + +/**************************************************************************** + Queue a multihomed register name packet to the broadcast address of a subnet. +****************************************************************************/ + +struct response_record *queue_register_multihomed_name( struct subnet_record *subrec, + response_function resp_fn, + timeout_response_function timeout_fn, + register_name_success_function success_fn, + register_name_fail_function fail_fn, + struct userdata_struct *userdata, + struct nmb_name *nmbname, + uint16 nb_flags, + struct in_addr register_ip) +{ + struct packet_struct *p; + struct response_record *rrec; + BOOL bcast = False; + BOOL ret; + + /* Sanity check. */ + if(subrec != unicast_subnet) + { + DEBUG(0,("queue_register_multihomed_name: should only be done on \ +unicast subnet. subnet is %s\n.", subrec->subnet_name )); + return NULL; + } + + if(assert_check_subnet(subrec)) + return NULL; + + if(( p = create_and_init_netbios_packet(nmbname, bcast, + subrec->bcast_ip)) == NULL) + return NULL; + + if (nb_flags & NB_GROUP) + ret = initiate_name_register_packet( p, nb_flags, ®ister_ip); + else + ret = initiate_multihomed_name_register_packet( p, nb_flags, ®ister_ip); + + if(ret == False) + { + p->locked = False; + free_packet(p); + return NULL; + } + + if((rrec = make_response_record(subrec, /* subnet record. */ + p, /* packet we sent. */ + resp_fn, /* function to call on response. */ + timeout_fn, /* function to call on timeout. */ + (success_function)success_fn, /* function to call on operation success. */ + (fail_function)fail_fn, /* function to call on operation fail. */ + userdata)) == NULL) + { + p->locked = False; + free_packet(p); + return NULL; + } + + return rrec; +} + +/**************************************************************************** + Queue a release name packet to the broadcast address of a subnet. +****************************************************************************/ + +struct response_record *queue_release_name( struct subnet_record *subrec, + response_function resp_fn, + timeout_response_function timeout_fn, + release_name_success_function success_fn, + release_name_fail_function fail_fn, + struct userdata_struct *userdata, + struct nmb_name *nmbname, + uint16 nb_flags, + struct in_addr release_ip) +{ + BOOL bcast = (subrec == unicast_subnet) ? False : True; + struct packet_struct *p; + struct response_record *rrec; + + if(assert_check_subnet(subrec)) + return NULL; + + if(( p = create_and_init_netbios_packet(nmbname, bcast, + subrec->bcast_ip)) == NULL) + return NULL; + + if(initiate_name_release_packet( p, nb_flags, &release_ip) == False) + { + p->locked = False; + free_packet(p); + return NULL; + } + + if((rrec = make_response_record(subrec, /* subnet record. */ + p, /* packet we sent. */ + resp_fn, /* function to call on response. */ + timeout_fn, /* function to call on timeout. */ + (success_function)success_fn, /* function to call on operation success. */ + (fail_function)fail_fn, /* function to call on operation fail. */ + userdata)) == NULL) + { + p->locked = False; + free_packet(p); + return NULL; + } + + return rrec; +} + +/**************************************************************************** + Queue a refresh name packet to the broadcast address of a subnet. +****************************************************************************/ + +struct response_record *queue_refresh_name( struct subnet_record *subrec, + response_function resp_fn, + timeout_response_function timeout_fn, + refresh_name_success_function success_fn, + refresh_name_fail_function fail_fn, + struct userdata_struct *userdata, + struct name_record *namerec, + struct in_addr refresh_ip) +{ + BOOL bcast = (subrec == unicast_subnet) ? False : True; + struct packet_struct *p; + struct response_record *rrec; + + if(assert_check_subnet(subrec)) + return NULL; + + if(( p = create_and_init_netbios_packet(&namerec->name, bcast, + subrec->bcast_ip)) == NULL) + return NULL; + + if(initiate_name_refresh_packet( p, namerec->nb_flags, &refresh_ip) == False) + { + p->locked = False; + free_packet(p); + return NULL; + } + + if((rrec = make_response_record(subrec, /* subnet record. */ + p, /* packet we sent. */ + resp_fn, /* function to call on response. */ + timeout_fn, /* function to call on timeout. */ + (success_function)success_fn, /* function to call on operation success. */ + (fail_function)fail_fn, /* function to call on operation fail. */ + userdata)) == NULL) + { + p->locked = False; + free_packet(p); + return NULL; + } + + return rrec; +} + +/**************************************************************************** + Queue a query name packet to the broadcast address of a subnet. +****************************************************************************/ + +struct response_record *queue_query_name( struct subnet_record *subrec, + response_function resp_fn, + timeout_response_function timeout_fn, + query_name_success_function success_fn, + query_name_fail_function fail_fn, + struct userdata_struct *userdata, + struct nmb_name *nmbname) +{ + struct packet_struct *p; + struct response_record *rrec; + BOOL bcast = True; + + if ((subrec == unicast_subnet) || (subrec == wins_server_subnet)) + bcast = False; + + if(assert_check_subnet(subrec)) + return NULL; + + if(( p = create_and_init_netbios_packet(nmbname, bcast, + subrec->bcast_ip)) == NULL) + return NULL; + + if(initiate_name_query_packet( p ) == False) + { + p->locked = False; + free_packet(p); + return NULL; + } + + if((rrec = make_response_record(subrec, /* subnet record. */ + p, /* packet we sent. */ + resp_fn, /* function to call on response. */ + timeout_fn, /* function to call on timeout. */ + (success_function)success_fn, /* function to call on operation success. */ + (fail_function)fail_fn, /* function to call on operation fail. */ + userdata)) == NULL) + { + p->locked = False; + free_packet(p); + return NULL; + } + + return rrec; +} + +/**************************************************************************** + Queue a node status packet to a given name and address. +****************************************************************************/ + +struct response_record *queue_node_status( struct subnet_record *subrec, + response_function resp_fn, + timeout_response_function timeout_fn, + node_status_success_function success_fn, + node_status_fail_function fail_fn, + struct userdata_struct *userdata, + struct nmb_name *nmbname, + struct in_addr send_ip) +{ + struct packet_struct *p; + struct response_record *rrec; + BOOL bcast = False; + + /* Sanity check. */ + if(subrec != unicast_subnet) + { + DEBUG(0,("queue_register_multihomed_name: should only be done on \ +unicast subnet. subnet is %s\n.", subrec->subnet_name )); + return NULL; + } + + if(assert_check_subnet(subrec)) + return NULL; + + if(( p = create_and_init_netbios_packet(nmbname, bcast, + send_ip)) == NULL) + return NULL; + + if(initiate_node_status_packet(p) == False) + { + p->locked = False; + free_packet(p); + return NULL; + } + + if((rrec = make_response_record(subrec, /* subnet record. */ + p, /* packet we sent. */ + resp_fn, /* function to call on response. */ + timeout_fn, /* function to call on timeout. */ + (success_function)success_fn, /* function to call on operation success. */ + (fail_function)fail_fn, /* function to call on operation fail. */ + userdata)) == NULL) + { + p->locked = False; + free_packet(p); + return NULL; + } + + return rrec; +} + +/**************************************************************************** + Reply to a netbios name packet. see rfc1002.txt +****************************************************************************/ + +void reply_netbios_packet(struct packet_struct *orig_packet, + int rcode, enum netbios_reply_type_code rcv_code, int opcode, + int ttl, char *data,int len) +{ + struct packet_struct packet; + struct nmb_packet *nmb = NULL; + struct res_rec answers; + struct nmb_packet *orig_nmb = &orig_packet->packet.nmb; + BOOL loopback_this_packet = False; + char *packet_type = "unknown"; + + /* Check if we are sending to or from ourselves. */ + if(ismyip(orig_packet->ip) && (orig_packet->port == global_nmb_port)) + loopback_this_packet = True; + + nmb = &packet.packet.nmb; + + /* Do a partial copy of the packet. We clear the locked flag and + the resource record pointers. */ + packet = *orig_packet; /* Full structure copy. */ + packet.locked = False; + nmb->answers = NULL; + nmb->nsrecs = NULL; + nmb->additional = NULL; + + switch (rcv_code) + { + case NMB_STATUS: + { + packet_type = "nmb_status"; + nmb->header.nm_flags.recursion_desired = False; + nmb->header.nm_flags.recursion_available = False; + break; + } + case NMB_QUERY: + { + packet_type = "nmb_query"; + nmb->header.nm_flags.recursion_desired = True; + nmb->header.nm_flags.recursion_available = True; + break; + } + case NMB_REG: + case NMB_REG_REFRESH: + { + packet_type = "nmb_reg"; + nmb->header.nm_flags.recursion_desired = True; + nmb->header.nm_flags.recursion_available = True; + break; + } + case NMB_REL: + { + packet_type = "nmb_rel"; + nmb->header.nm_flags.recursion_desired = False; + nmb->header.nm_flags.recursion_available = False; + break; + } + case NMB_WAIT_ACK: + { + packet_type = "nmb_wack"; + nmb->header.nm_flags.recursion_desired = False; + nmb->header.nm_flags.recursion_available = False; + break; + } + case WINS_REG: + { + packet_type = "wins_reg"; + nmb->header.nm_flags.recursion_desired = True; + nmb->header.nm_flags.recursion_available = True; + break; + } + case WINS_QUERY: + { + packet_type = "wins_query"; + nmb->header.nm_flags.recursion_desired = True; + nmb->header.nm_flags.recursion_available = True; + break; + } + + default: + { + DEBUG(0,("reply_netbios_packet: Unknown packet type: %s %s to ip %s\n", + packet_type, namestr(&orig_nmb->question.question_name), + inet_ntoa(packet.ip))); + + return; + } + } + + DEBUG(4,("reply_netbios_packet: sending a reply of packet type: %s %s to ip %s \ +for id %hu\n", + packet_type, namestr(&orig_nmb->question.question_name), + inet_ntoa(packet.ip), orig_nmb->header.name_trn_id)); + + nmb->header.name_trn_id = orig_nmb->header.name_trn_id; + nmb->header.opcode = opcode; + nmb->header.response = True; + nmb->header.nm_flags.bcast = False; + nmb->header.nm_flags.trunc = False; + nmb->header.nm_flags.authoritative = True; + + nmb->header.rcode = rcode; + nmb->header.qdcount = 0; + nmb->header.ancount = 1; + nmb->header.nscount = 0; + nmb->header.arcount = 0; + + bzero((char*)&nmb->question,sizeof(nmb->question)); + + nmb->answers = &answers; + bzero((char*)nmb->answers,sizeof(*nmb->answers)); + + nmb->answers->rr_name = orig_nmb->question.question_name; + nmb->answers->rr_type = orig_nmb->question.question_type; + nmb->answers->rr_class = orig_nmb->question.question_class; + nmb->answers->ttl = ttl; + + if (data && len) + { + nmb->answers->rdlength = len; + memcpy(nmb->answers->rdata, data, len); + } + + packet.packet_type = NMB_PACKET; + /* Ensure we send out on the same fd that the original + packet came in on to give the correct source IP address. */ + packet.fd = orig_packet->fd; + packet.timestamp = time(NULL); + + debug_nmb_packet(&packet); + + if(loopback_this_packet) + { + struct packet_struct *lo_packet; + DEBUG(5,("reply_netbios_packet: sending packet to ourselves.\n")); + if((lo_packet = copy_packet(&packet)) == NULL) + return; + queue_packet(lo_packet); + } + else if (!send_packet(&packet)) + { + DEBUG(0,("reply_netbios_packet: send_packet to IP %s port %d failed\n", + inet_ntoa(packet.ip),packet.port)); + } +} + +/******************************************************************* + Queue a packet into a packet queue +******************************************************************/ + +void queue_packet(struct packet_struct *packet) +{ + struct packet_struct *p; + + if (!packet_queue) + { + packet->prev = NULL; + packet->next = NULL; + packet_queue = packet; + return; + } + + /* find the bottom */ + for (p=packet_queue;p->next;p=p->next) + ; + + p->next = packet; + packet->next = NULL; + packet->prev = p; +} + +/**************************************************************************** + Try and find a matching subnet record for a datagram port 138 packet. +****************************************************************************/ + +static struct subnet_record *find_subnet_for_dgram_browse_packet(struct packet_struct *p) +{ + struct subnet_record *subrec; + + /* Go through all the broadcast subnets and see if the mask matches. */ + for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + { + if(same_net(p->ip, subrec->bcast_ip, subrec->mask_ip)) + return subrec; + } + + /* If the subnet record is the remote announce broadcast subnet, + hack it here to be the first subnet. This is really gross and + is needed due to people turning on port 137/138 broadcast + forwarding on their routers. May fire and brimstone rain + down upon them... + */ + + return FIRST_SUBNET; +} + +/**************************************************************************** +Dispatch a browse frame from port 138 to the correct processing function. +****************************************************************************/ + +void process_browse_packet(struct packet_struct *p, char *buf,int len) +{ + struct dgram_packet *dgram = &p->packet.dgram; + int command = CVAL(buf,0); + struct subnet_record *subrec = find_subnet_for_dgram_browse_packet(p); + + /* Drop the packet if it's a different NetBIOS scope, or + the source is from one of our names. */ + + if (!strequal(dgram->dest_name.scope,scope )) + { + DEBUG(7,("process_browse_packet: Discarding datagram from IP %s. Scope (%s) \ +mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, scope)); + return; + } + + if (is_myname(dgram->source_name.name)) + { + DEBUG(0,("process_browse_packet: Discarding datagram from IP %s. Source name \ +%s is one of our names !\n", inet_ntoa(p->ip), namestr(&dgram->source_name))); + return; + } + + switch (command) + { + case ANN_HostAnnouncement: + { + debug_browse_data(buf, len); + process_host_announce(subrec, p, buf+1); + break; + } + case ANN_DomainAnnouncement: + { + debug_browse_data(buf, len); + process_workgroup_announce(subrec, p, buf+1); + break; + } + case ANN_LocalMasterAnnouncement: + { + debug_browse_data(buf, len); + process_local_master_announce(subrec, p, buf+1); + break; + } + case ANN_AnnouncementRequest: + { + process_announce_request(subrec, p, buf+1); + break; + } + case ANN_Election: + { + process_election(subrec, p, buf+1); + break; + } + case ANN_GetBackupListReq: + { + debug_browse_data(buf, len); + + /* This is one occasion where we change a subnet that is + given to us. If the packet was sent to WORKGROUP<1b> instead + of WORKGROUP<1d> then it was unicast to us a domain master + browser. Change subrec to unicast. + */ + if(dgram->dest_name.name_type == 0x1b) + subrec = unicast_subnet; + + process_get_backup_list_request(subrec, p, buf+1); + break; + } + case ANN_GetBackupListResp: + { + debug_browse_data(buf, len); + /* We never send ANN_GetBackupListReq so we + should never get these. */ + DEBUG(0,("process_browse_packet: Discarding GetBackupListResponse \ +packet from %s IP %s\n", namestr(&dgram->source_name), inet_ntoa(p->ip))); + break; + } + case ANN_ResetBrowserState: + { + process_reset_browser(subrec, p, buf+1); + break; + } + case ANN_MasterAnnouncement: + { + /* Master browser datagrams must be processed + on the unicast subnet. */ + subrec = unicast_subnet; + + process_master_browser_announce(subrec, p, buf+1); + break; + } + default: + { + DEBUG(0,("process_browse_packet: On subnet %s ignoring browse packet \ +command code %d from %s IP %s to %s\n", + subrec->subnet_name, command, namestr(&dgram->source_name), + inet_ntoa(p->ip), namestr(&dgram->dest_name))); + } + } +} + +/**************************************************************************** + Determine if a packet is for us on port 138. Note that to have any chance of + being efficient we need to drop as many packets as possible at this + stage as subsequent processing is expensive. +****************************************************************************/ + +static BOOL listening(struct packet_struct *p,struct nmb_name *nbname) +{ + struct subnet_record *subrec = NULL; + + for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + { + if(same_net(p->ip, subrec->bcast_ip, subrec->mask_ip)) + break; + } + + if(subrec == NULL) + subrec = unicast_subnet; + + return (find_name_on_subnet(subrec, nbname, FIND_SELF_NAME) != NULL); +} + +/**************************************************************************** + Process udp 138 datagrams +****************************************************************************/ + +static void process_dgram(struct packet_struct *p) +{ + char *buf; + char *buf2; + int len; + struct dgram_packet *dgram = &p->packet.dgram; + + /* If we aren't listening to the destination name then ignore the packet */ + if (!listening(p,&dgram->dest_name)) + { + DEBUG(5,("process_dgram: ignoring dgram packet sent to name %s from %s\n", + namestr(&dgram->dest_name), inet_ntoa(p->ip))); + return; + } + + if (dgram->header.msg_type != 0x10 && + dgram->header.msg_type != 0x11 && + dgram->header.msg_type != 0x12) + { + /* Don't process error packets etc yet */ + DEBUG(5,("process_dgram: ignoring dgram packet sent to name %s from IP %s as it is \ + an error packet of type %x\n", + namestr(&dgram->dest_name), inet_ntoa(p->ip), dgram->header.msg_type)); + return; + } + + buf = &dgram->data[0]; + buf -= 4; /* XXXX for the pseudo tcp length - + someday I need to get rid of this */ + + if (CVAL(buf,smb_com) != SMBtrans) + return; + + len = SVAL(buf,smb_vwv11); + buf2 = smb_base(buf) + SVAL(buf,smb_vwv12); + + DEBUG(4,("process_dgram: datagram from %s to %s IP %s for %s of type %d len=%d\n", + namestr(&dgram->source_name),namestr(&dgram->dest_name), + inet_ntoa(p->ip), smb_buf(buf),CVAL(buf2,0),len)); + + + if (len <= 0) + return; + + /* Datagram packet received for the browser mailslot */ + if (strequal(smb_buf(buf),BROWSE_MAILSLOT)) + { + process_browse_packet(p,buf2,len); + return; + } + + /* Datagram packet received for the domain logon mailslot */ + if (strequal(smb_buf(buf),NET_LOGON_MAILSLOT)) + { + process_logon_packet(p,buf2,len,NET_LOGON_MAILSLOT); + return; + } + + /* Datagram packet received for the NT domain logon mailslot */ + if (strequal(smb_buf(buf),NT_LOGON_MAILSLOT)) + { + process_logon_packet(p,buf2,len,NT_LOGON_MAILSLOT); + return; + } +} + +/**************************************************************************** + Validate a response nmb packet. +****************************************************************************/ + +BOOL validate_nmb_response_packet( struct nmb_packet *nmb ) +{ + BOOL ignore = False; + + switch (nmb->header.opcode) + { + case NMB_NAME_REG_OPCODE: + case NMB_NAME_REFRESH_OPCODE_8: /* ambiguity in rfc1002 about which is correct. */ + case NMB_NAME_REFRESH_OPCODE_9: /* WinNT uses 8 by default. */ + if (nmb->header.ancount == 0) + { + DEBUG(0,("validate_nmb_response_packet: Bad REG/REFRESH Packet. ")); + ignore = True; + } + break; + + case NMB_NAME_QUERY_OPCODE: + if ((nmb->header.ancount != 0) && (nmb->header.ancount != 1)) + { + DEBUG(0,("validate_nmb_response_packet: Bad QUERY Packet. ")); + ignore = True; + } + break; + case NMB_NAME_RELEASE_OPCODE: + if (nmb->header.ancount == 0) + { + DEBUG(0,("validate_nmb_response_packet: Bad RELEASE Packet. ")); + ignore = True; + } + break; + case NMB_WACK_OPCODE: + /* Check WACK response here. */ + if (nmb->header.ancount != 1) + { + DEBUG(0,("validate_nmb_response_packet: Bad WACK Packet. ")); + ignore = True; + } + break; + default: + DEBUG(0,("validate_nmb_response_packet: Ignoring packet with unknown opcode %d.\n", + nmb->header.opcode)); + return True; + } + + if(ignore) + DEBUG(0,("Ignoring response packet with opcode %d.\n", nmb->header.opcode)); + + return ignore; +} + +/**************************************************************************** + Validate a request nmb packet. +****************************************************************************/ + +BOOL validate_nmb_packet( struct nmb_packet *nmb ) +{ + BOOL ignore = False; + + switch (nmb->header.opcode) + { + case NMB_NAME_REG_OPCODE: + case NMB_NAME_REFRESH_OPCODE_8: /* ambiguity in rfc1002 about which is correct. */ + case NMB_NAME_REFRESH_OPCODE_9: /* WinNT uses 8 by default. */ + case NMB_NAME_MULTIHOMED_REG_OPCODE: + if (nmb->header.qdcount==0 || nmb->header.arcount==0) + { + DEBUG(0,("validate_nmb_packet: Bad REG/REFRESH Packet. ")); + ignore = True; + } + break; + + case NMB_NAME_QUERY_OPCODE: + if ((nmb->header.qdcount == 0) || + ((nmb->question.question_type != QUESTION_TYPE_NB_QUERY) && + (nmb->question.question_type != QUESTION_TYPE_NB_STATUS))) + { + DEBUG(0,("validate_nmb_packet: Bad QUERY Packet. ")); + ignore = True; + } + break; + + case NMB_NAME_RELEASE_OPCODE: + if (nmb->header.qdcount==0 || nmb->header.arcount==0) + { + DEBUG(0,("validate_nmb_packet: Bad RELEASE Packet. ")); + ignore = True; + } + break; + default: + DEBUG(0,("validate_nmb_packet: Ignoring packet with unknown opcode %d.\n", + nmb->header.opcode)); + return True; + } + + if(ignore) + DEBUG(0,("validate_nmb_packet: Ignoring request packet with opcode %d.\n", nmb->header.opcode)); + + return ignore; +} + +/**************************************************************************** + Find a subnet (and potentially a response record) for a packet. +****************************************************************************/ + +static struct subnet_record *find_subnet_for_nmb_packet( struct packet_struct *p, + struct response_record **pprrec) +{ + struct nmb_packet *nmb = &p->packet.nmb; + struct response_record *rrec = NULL; + struct subnet_record *subrec = NULL; + + if(pprrec != NULL) + *pprrec = NULL; + + if(nmb->header.response) + { + /* It's a response packet. Find a record for it or it's an error. */ + + rrec = find_response_record( &subrec, nmb->header.name_trn_id); + if(rrec == NULL) + { + DEBUG(0,("find_subnet_for_nmb_packet: response record not found for response id %hu\n", + nmb->header.name_trn_id)); + return NULL; + } + + if(subrec == NULL) + { + DEBUG(0,("find_subnet_for_nmb_packet: subnet record not found for response id %hu\n", + nmb->header.name_trn_id)); + return NULL; + } + + if(pprrec != NULL) + *pprrec = rrec; + return subrec; + } + + /* Try and see what subnet this packet belongs to. */ + + /* WINS server ? */ + if(packet_is_for_wins_server(p)) + return wins_server_subnet; + + /* If it wasn't a broadcast packet then send to the UNICAST subnet. */ + if(nmb->header.nm_flags.bcast == False) + return unicast_subnet; + + /* Go through all the broadcast subnets and see if the mask matches. */ + for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + { + if(same_net(p->ip, subrec->bcast_ip, subrec->mask_ip)) + return subrec; + } + + /* If none match it must have been a directed broadcast - assign + the remote_broadcast_subnet. */ + return remote_broadcast_subnet; +} + +/**************************************************************************** + Process a nmb request packet - validate the packet and route it. +****************************************************************************/ + +static void process_nmb_request(struct packet_struct *p) +{ + struct nmb_packet *nmb = &p->packet.nmb; + struct subnet_record *subrec = NULL; + + debug_nmb_packet(p); + + /* Ensure we have a good packet. */ + if(validate_nmb_packet(nmb)) + return; + + /* Allocate a subnet to this packet - if we cannot - fail. */ + if((subrec = find_subnet_for_nmb_packet(p, NULL))==NULL) + return; + + switch (nmb->header.opcode) + { + case NMB_NAME_REG_OPCODE: + if(subrec == wins_server_subnet) + wins_process_name_registration_request(subrec, p); + else + process_name_registration_request(subrec, p); + break; + + case NMB_NAME_REFRESH_OPCODE_8: /* ambiguity in rfc1002 about which is correct. */ + case NMB_NAME_REFRESH_OPCODE_9: + if(subrec == wins_server_subnet) + wins_process_name_refresh_request(subrec, p); + else + process_name_refresh_request(subrec, p); + break; + + case NMB_NAME_MULTIHOMED_REG_OPCODE: + if(subrec == wins_server_subnet) + wins_process_multihomed_name_registration_request(subrec, p); + else + { + DEBUG(0,("process_nmb_request: Multihomed registration request must be \ +directed at a WINS server.\n")); + } + break; + + case NMB_NAME_QUERY_OPCODE: + switch (nmb->question.question_type) + { + case QUESTION_TYPE_NB_QUERY: + { + if(subrec == wins_server_subnet) + wins_process_name_query_request(subrec, p); + else + process_name_query_request(subrec, p); + break; + } + case QUESTION_TYPE_NB_STATUS: + { + if(subrec == wins_server_subnet) + { + DEBUG(0,("process_nmb_request: NB_STATUS request directed at WINS server is \ +not allowed.\n")); + break; + } + else + process_node_status_request(subrec, p); + break; + } + } + break; + + case NMB_NAME_RELEASE_OPCODE: + if(subrec == wins_server_subnet) + wins_process_name_release_request(subrec, p); + else + process_name_release_request(subrec, p); + break; + } +} + +/**************************************************************************** + Process a nmb response packet - validate the packet and route it. + to either the WINS server or a normal response. +****************************************************************************/ + +static void process_nmb_response(struct packet_struct *p) +{ + struct nmb_packet *nmb = &p->packet.nmb; + struct subnet_record *subrec = NULL; + struct response_record *rrec = NULL; + + debug_nmb_packet(p); + + if(validate_nmb_response_packet(nmb)) + return; + + if((subrec = find_subnet_for_nmb_packet(p, &rrec))==NULL) + return; + + if(rrec == NULL) + { + DEBUG(0,("process_nmb_response: response packet received but no response record \ +found for id = %hu. Ignoring packet.\n", nmb->header.name_trn_id)); + return; + } + + /* Increment the number of responses received for this record. */ + rrec->num_msgs++; + /* Ensure we don't re-send the request. */ + rrec->repeat_count = 0; + + /* Call the response received function for this packet. */ + (*rrec->resp_fn)(subrec, rrec, p); +} + + +/******************************************************************* + Run elements off the packet queue till its empty +******************************************************************/ + +void run_packet_queue() +{ + struct packet_struct *p; + + while ((p = packet_queue)) + { + packet_queue = p->next; + if (packet_queue) + packet_queue->prev = NULL; + p->next = p->prev = NULL; + + switch (p->packet_type) + { + case NMB_PACKET: + if(p->packet.nmb.header.response) + process_nmb_response(p); + else + process_nmb_request(p); + break; + + case DGRAM_PACKET: + process_dgram(p); + break; + } + free_packet(p); + } +} + +/******************************************************************* + Retransmit or timeout elements from all the outgoing subnet response + record queues. +******************************************************************/ + +void retransmit_or_expire_response_records(time_t t) +{ + struct subnet_record *subrec; + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) + { + struct response_record *rrec, *nextrrec; + + for (rrec = subrec->responselist; rrec; rrec = nextrrec) + { + nextrrec = rrec->next; + + if (rrec->repeat_time <= t) + { + if (rrec->repeat_count > 0) + { + /* Resend while we have a non-zero repeat_count. */ + if(!send_packet(rrec->packet)) + { + DEBUG(0,("retransmit_or_expire_response_records: Failed to resend packet id %hu \ +to IP %s on subnet %s\n", rrec->response_id, inet_ntoa(rrec->packet->ip), + subrec->subnet_name)); + } + rrec->repeat_time += rrec->repeat_interval; + rrec->repeat_count--; + } + else + { + DEBUG(4,("retransmit_or_expire_response_records: timeout for packet id %hu to IP %s \ +on subnet %s\n", rrec->response_id, inet_ntoa(rrec->packet->ip), + subrec->subnet_name)); + + /* Call the timeout function. This will deal with removing the + timed out packet. */ + if(rrec->timeout_fn) + (*rrec->timeout_fn)(subrec, rrec); + else + { + /* We must remove the record ourself if there is + no timeout function. */ + remove_response_record(subrec, rrec); + } + } /* rrec->repeat_count > 0 */ + } /* rrec->repeat_time <= t */ + } /* end for rrec */ + } /* end for subnet */ +} + +/**************************************************************************** + Create an fd_set containing all the sockets in the subnet structures, + plus the broadcast sockets. +***************************************************************************/ + +static BOOL create_listen_fdset(fd_set **ppset, int **psock_array, int *listen_number) +{ + int *sock_array = NULL; + struct subnet_record *subrec = NULL; + int count = 0; + int num = 0; + fd_set *pset = (fd_set *)malloc(sizeof(fd_set)); + + if(pset == NULL) + { + DEBUG(0,("create_listen_fdset: malloc fail !\n")); + return True; + } + + /* Check that we can add all the fd's we need. */ + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + count++; + + if((count*2) + 2 > FD_SETSIZE) + { + DEBUG(0,("create_listen_fdset: Too many file descriptors needed (%d). We can \ +only use %d.\n", (count*2) + 2, FD_SETSIZE)); + return True; + } + + if((sock_array = (int *)malloc(((count*2) + 2)*sizeof(int))) == NULL) + { + DEBUG(0,("create_listen_fdset: malloc fail for socket array.\n")); + return True; + } + + FD_ZERO(pset); + + /* Add in the broadcast socket on 137. */ + FD_SET(ClientNMB,pset); + sock_array[num++] = ClientNMB; + + /* Add in the 137 sockets on all the interfaces. */ + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + { + FD_SET(subrec->nmb_sock,pset); + sock_array[num++] = subrec->nmb_sock; + } + + /* Add in the broadcast socket on 138. */ + FD_SET(ClientDGRAM,pset); + sock_array[num++] = ClientDGRAM; + + /* Add in the 138 sockets on all the interfaces. */ + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + { + FD_SET(subrec->dgram_sock,pset); + sock_array[num++] = subrec->dgram_sock; + } + + *listen_number = (count*2) + 2; + *ppset = pset; + *psock_array = sock_array; + + return False; +} + +/**************************************************************************** + Listens for NMB or DGRAM packets, and queues them. +***************************************************************************/ + +BOOL listen_for_packets(BOOL run_election) +{ + static fd_set *listen_set = NULL; + static int listen_number = 0; + static int *sock_array = NULL; + + fd_set fds; + int selrtn; + struct timeval timeout; +#ifndef SYNC_DNS + int dns_fd; +#endif + + if(listen_set == NULL) + { + if(create_listen_fdset(&listen_set, &sock_array, &listen_number)) + { + DEBUG(0,("listen_for_packets: Fatal error. unable to create listen set. Exiting.\n")); + return True; + } + } + + memcpy((char *)&fds, (char *)listen_set, sizeof(fd_set)); + +#ifndef SYNC_DNS + dns_fd = asyncdns_fd(); + if (dns_fd != -1) { + FD_SET(dns_fd, &fds); + } +#endif + + + /* + * During elections and when expecting a netbios response packet we + * need to send election packets at tighter intervals. + * Ideally it needs to be the interval (in ms) between time now and + * the time we are expecting the next netbios packet. + */ + + timeout.tv_sec = (run_election||num_response_packets) ? 1 : NMBD_SELECT_LOOP; + timeout.tv_usec = 0; + + /* We can only take term signals when we are in the select. */ + BlockSignals(False, SIGTERM); + selrtn = sys_select(&fds,&timeout); + BlockSignals(True, SIGTERM); + + if(selrtn > 0) + { + int i; + +#ifndef SYNC_DNS + if (dns_fd != -1 && FD_ISSET(dns_fd,&fds)) { + run_dns_queue(); + } +#endif + + for(i = 0; i < listen_number; i++) + { + if(i < (listen_number/2)) + { + /* Processing a 137 socket. */ + if (FD_ISSET(sock_array[i],&fds)) + { + struct packet_struct *packet = read_packet(sock_array[i], NMB_PACKET); + if (packet) + { + /* + * If we got a packet on the broadcast socket and interfaces + * only is set then check it came from one of our local nets. + */ + if(lp_bind_interfaces_only() && (sock_array[i] == ClientNMB) && + (!is_local_net(packet->ip))) + { + DEBUG(7,("discarding nmb packet sent to broadcast socket from %s:%d\n", + inet_ntoa(packet->ip),packet->port)); + free_packet(packet); + } + else if ((ip_equal(loopback_ip, packet->ip) || + ismyip(packet->ip)) && packet->port == global_nmb_port) + { + DEBUG(7,("discarding own packet from %s:%d\n", + inet_ntoa(packet->ip),packet->port)); + free_packet(packet); + } + else + { + /* Save the file descriptor this packet came in on. */ + packet->fd = sock_array[i]; + queue_packet(packet); + } + } + } + } + else + { + /* Processing a 138 socket. */ + + if (FD_ISSET(sock_array[i],&fds)) + { + struct packet_struct *packet = read_packet(sock_array[i], DGRAM_PACKET); + if (packet) + { + /* + * If we got a packet on the broadcast socket and interfaces + * only is set then check it came from one of our local nets. + */ + if(lp_bind_interfaces_only() && (sock_array[i] == ClientDGRAM) && + (!is_local_net(packet->ip))) + { + DEBUG(7,("discarding dgram packet sent to broadcast socket from %s:%d\n", + inet_ntoa(packet->ip),packet->port)); + free_packet(packet); + } + else if ((ip_equal(loopback_ip, packet->ip) || + ismyip(packet->ip)) && packet->port == DGRAM_PORT) + { + DEBUG(7,("discarding own packet from %s:%d\n", + inet_ntoa(packet->ip),packet->port)); + free_packet(packet); + } + else + { + /* Save the file descriptor this packet came in on. */ + packet->fd = sock_array[i]; + queue_packet(packet); + } + } + } + } /* end processing 138 socket. */ + } /* end for */ + } /* end if selret > 0 */ + return False; +} + +/**************************************************************************** + Construct and send a netbios DGRAM. + Note that this currently sends all packets to port 138. +**************************************************************************/ + +BOOL send_mailslot(BOOL unique, char *mailslot,char *buf,int len, + char *srcname, int src_type, + char *dstname, int dest_type, + struct in_addr dest_ip,struct in_addr src_ip) +{ + BOOL loopback_this_packet = False; + struct packet_struct p; + struct dgram_packet *dgram = &p.packet.dgram; + char *ptr,*p2; + char tmp[4]; + + bzero((char *)&p,sizeof(p)); + + if(ismyip(dest_ip)) + loopback_this_packet = True; + + generate_name_trn_id(); + + /* DIRECT GROUP or UNIQUE datagram. */ + dgram->header.msg_type = unique ? 0x10 : 0x11; + dgram->header.flags.node_type = M_NODE; + dgram->header.flags.first = True; + dgram->header.flags.more = False; + dgram->header.dgm_id = name_trn_id; + dgram->header.source_ip = src_ip; + dgram->header.source_port = DGRAM_PORT; + dgram->header.dgm_length = 0; /* Let build_dgram() handle this. */ + dgram->header.packet_offset = 0; + + make_nmb_name(&dgram->source_name,srcname,0,scope); + make_nmb_name(&dgram->dest_name,dstname,dest_type,scope); + + ptr = &dgram->data[0]; + + /* Setup the smb part. */ + ptr -= 4; /* XXX Ugliness because of handling of tcp SMB length. */ + memcpy(tmp,ptr,4); + set_message(ptr,17,17 + len,True); + memcpy(ptr,tmp,4); + + CVAL(ptr,smb_com) = SMBtrans; + SSVAL(ptr,smb_vwv1,len); + SSVAL(ptr,smb_vwv11,len); + SSVAL(ptr,smb_vwv12,70 + strlen(mailslot)); + SSVAL(ptr,smb_vwv13,3); + SSVAL(ptr,smb_vwv14,1); + SSVAL(ptr,smb_vwv15,1); + SSVAL(ptr,smb_vwv16,2); + p2 = smb_buf(ptr); + strcpy(p2,mailslot); + p2 = skip_string(p2,1); + + memcpy(p2,buf,len); + p2 += len; + + dgram->datasize = PTR_DIFF(p2,ptr+4); /* +4 for tcp length. */ + + p.ip = dest_ip; + p.port = DGRAM_PORT; + p.fd = ClientDGRAM; + p.timestamp = time(NULL); + p.packet_type = DGRAM_PACKET; + + DEBUG(4,("send_mailslot: Sending to mailslot %s from %s IP %s ", mailslot, + namestr(&dgram->source_name), inet_ntoa(src_ip))); + DEBUG(4,("to %s IP %s\n", namestr(&dgram->dest_name), inet_ntoa(dest_ip))); + + debug_browse_data(buf, len); + + if(loopback_this_packet) + { + struct packet_struct *lo_packet = NULL; + DEBUG(5,("send_mailslot: sending packet to ourselves.\n")); + if((lo_packet = copy_packet(&p)) == NULL) + return False; + queue_packet(lo_packet); + return True; + } + else + return(send_packet(&p)); +} diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c new file mode 100644 index 0000000000..ae917564fe --- /dev/null +++ b/source3/nmbd/nmbd_processlogon.c @@ -0,0 +1,250 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1994-1997 + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + Revision History: + +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; + +extern pstring myname; +extern fstring myworkgroup; + +/**************************************************************************** +Process a domain logon packet +**************************************************************************/ + +void process_logon_packet(struct packet_struct *p,char *buf,int len, + char *mailslot) +{ + struct dgram_packet *dgram = &p->packet.dgram; + pstring my_name; + fstring reply_name; + BOOL add_slashes = False; + pstring outbuf; + int code,reply_code; + char unknown_byte = 0; + uint16 request_count = 0; + uint16 token = 0; + + uint32 ntversion; + uint16 lmnttoken; + uint16 lm20token; + uint32 allowableaccount; /* Control bits, i.e. 0x80 == workstation trust a/c. */ + uint32 domainsidsize; + uint16 requestcount; + char *domainsid; + char *getdc; + char *uniuser; /* Unicode user name. */ + pstring ascuser; + char *unicomp; /* Unicode computer name. */ + struct smb_passwd *smb_pass; /* To check if machine account exists */ + + if (!lp_domain_logons()) + { + DEBUG(3,("process_logon_packet: Logon packet received from IP %S and domain \ +logons are not enabled.\n", inet_ntoa(p->ip) )); + return; + } + + strcpy(my_name, myname); + strupper(my_name); + + code = SVAL(buf,0); + DEBUG(1,("process_logon_packet: Logon from %s: code = %x\n", inet_ntoa(p->ip), code)); + + switch (code) + { + case 0: + { + char *q = buf + 2; + char *machine = q; + char *user = skip_string(machine,1); + + getdc = skip_string(user,1); + q = skip_string(getdc,1); + unknown_byte = CVAL(q,0); + request_count = SVAL(q,1); + token = SVAL(q,3); + + reply_code = 0x6; + strcpy(reply_name,my_name); + add_slashes = True; + + DEBUG(3,("process_logon_packet: Domain login request from %s at IP %s user=%s token=%x\n", + machine,inet_ntoa(p->ip),user,token)); + + q = outbuf; + SSVAL(q, 0, 6); q += 2; + + strcpy(reply_name, "\\\\"); + strcat(reply_name, my_name); + strcpy(q, reply_name); q = skip_string(q, 1); /* PDC name */ + + SSVAL(q, 0, token); q += 2; + + dump_data(4, outbuf, PTR_DIFF(q, outbuf)); + + send_mailslot(True, getdc, + outbuf,PTR_DIFF(q,outbuf), + dgram->dest_name.name, + dgram->dest_name.name_type, + dgram->source_name.name, + dgram->source_name.name_type, + p->ip, *iface_ip(p->ip)); + break; + } + + case QUERYFORPDC: + { + char *q = buf + 2; + char *machine = q; + + getdc = skip_string(machine,1); + unicomp = skip_string(getdc,1); + + q = align2(unicomp, buf); + + q = skip_unicode_string(q, 1); + + ntversion = IVAL(q, 0); q += 4; + lmnttoken = SVAL(q, 0); q += 2; + lm20token = SVAL(q, 0); q += 2; + + /* Construct reply. */ + + q = outbuf; + SSVAL(q, 0, QUERYFORPDC_R); q += 2; + + strcpy(reply_name,my_name); + strcpy(q, reply_name); q = skip_string(q, 1); /* PDC name */ + + if (strcmp(mailslot, NT_LOGON_MAILSLOT)==0) { + q = align2(q, buf); + + PutUniCode(q, my_name); /* PDC name */ + q = skip_unicode_string(q, 1); + PutUniCode(q, myworkgroup); /* Domain name*/ + q = skip_unicode_string(q, 1); + + SIVAL(q, 0, ntversion); q += 4; + SSVAL(q, 0, lmnttoken); q += 2; + SSVAL(q, 0, lm20token); q += 2; + } + + DEBUG(3,("process_logon_packet: GETDC request from %s at IP %s, \ +reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", + machine,inet_ntoa(p->ip), reply_name, lp_workgroup(), + QUERYFORPDC_R, (uint32)ntversion, (uint32)lmnttoken, + (uint32)lm20token )); + + dump_data(4, outbuf, PTR_DIFF(q, outbuf)); + + send_mailslot(True, getdc, + outbuf,PTR_DIFF(q,outbuf), + dgram->dest_name.name, + dgram->dest_name.name_type, + dgram->source_name.name, + dgram->source_name.name_type, + p->ip, *iface_ip(p->ip)); + return; + } + + case SAMLOGON: + { + char *q = buf + 2; + + requestcount = SVAL(q, 0); q += 2; + unicomp = q; + uniuser = skip_unicode_string(unicomp,1); + getdc = skip_unicode_string(uniuser,1); + q = skip_string(getdc,1); + allowableaccount = IVAL(q, 0); q += 4; + domainsidsize = IVAL(q, 0); q += 4; + domainsid = q; + q += domainsidsize + 3; + ntversion = IVAL(q, 0); q += 4; + lmnttoken = SVAL(q, 0); q += 2; + lm20token = SVAL(q, 0); q += 2; + + DEBUG(3,("process_logon_packet: SAMLOGON sidsize %d ntv %d\n", domainsidsize, ntversion)); + + /* + * If MACHINE$ is in our password database then respond, else ignore. + * Let's ignore the SID. + */ + + strcpy(ascuser, unistr(uniuser)); + DEBUG(3,("process_logon_packet: SAMLOGON user %s\n", ascuser)); + + strcpy(reply_name,"\\\\"); /* Here it wants \\LOGONSERVER. */ + strcpy(reply_name+2,my_name); + + smb_pass = get_smbpwd_entry(ascuser, 0); + + if(!smb_pass) + { + DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, not in password file\n", + unistr(unicomp),inet_ntoa(p->ip), ascuser)); + return; + } + else + { + DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n", + unistr(unicomp),inet_ntoa(p->ip), ascuser, reply_name, myworkgroup, + SAMLOGON_R ,lmnttoken)); + } + + /* Construct reply. */ + + q = outbuf; + SSVAL(q, 0, SAMLOGON_R); q += 2; + + PutUniCode(q, reply_name); q = skip_unicode_string(q, 1); + unistrcpy(q, uniuser); q = skip_unicode_string(q, 1); /* User name (workstation trust account) */ + PutUniCode(q, lp_workgroup()); q = skip_unicode_string(q, 1); /* Domain name. */ + + SIVAL(q, 0, ntversion); q += 4; + SSVAL(q, 0, lmnttoken); q += 2; + SSVAL(q, 0, lm20token); q += 2; + + dump_data(4, outbuf, PTR_DIFF(q, outbuf)); + + send_mailslot(True, getdc, + outbuf,PTR_DIFF(q,outbuf), + dgram->dest_name.name, + dgram->dest_name.name_type, + dgram->source_name.name, + dgram->source_name.name_type, + p->ip, *iface_ip(p->ip)); + break; + } + + default: + { + DEBUG(3,("process_logon_packet: Unknown domain request %d\n",code)); + return; + } + } +} diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c new file mode 100644 index 0000000000..bc0c0745f5 --- /dev/null +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -0,0 +1,238 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios library routines + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1994-1997 + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "includes.h" + +extern int ClientNMB; + +extern int DEBUGLEVEL; + +extern pstring scope; +extern pstring myname; +extern struct in_addr ipzero; + +int num_response_packets = 0; + +/*************************************************************************** + Add an expected response record into the list + **************************************************************************/ + +void add_response_record(struct subnet_record *subrec, + struct response_record *rrec) +{ + struct response_record *rrec2; + + num_response_packets++; /* count of total number of packets still around */ + + DEBUG(4,("add_response_record: adding response record id:%hu to subnet %s. num_records:%d\n", + rrec->response_id, subrec->subnet_name, num_response_packets)); + + if (!subrec->responselist) + { + subrec->responselist = rrec; + rrec->prev = NULL; + rrec->next = NULL; + return; + } + + for (rrec2 = subrec->responselist; rrec2->next; rrec2 = rrec2->next) + ; + + rrec2->next = rrec; + rrec->next = NULL; + rrec->prev = rrec2; +} + +/*************************************************************************** + Remove an expected response record from the list + **************************************************************************/ + +void remove_response_record(struct subnet_record *subrec, + struct response_record *rrec) +{ + if (rrec->prev) + rrec->prev->next = rrec->next; + if (rrec->next) + rrec->next->prev = rrec->prev; + + if (subrec->responselist == rrec) + subrec->responselist = rrec->next; + + if(rrec->userdata) + { + if(rrec->userdata->free_fn) + (*rrec->userdata->free_fn)(rrec->userdata); + else + free((char *)rrec->userdata); + } + + /* Ensure we can delete. */ + rrec->packet->locked = False; + free_packet(rrec->packet); + + free((char *)rrec); + + num_response_packets--; /* count of total number of packets still around */ +} + +/**************************************************************************** + Create a response record for an outgoing packet. + **************************************************************************/ + +struct response_record *make_response_record( struct subnet_record *subrec, + struct packet_struct *p, + response_function resp_fn, + timeout_response_function timeout_fn, + success_function success_fn, + fail_function fail_fn, + struct userdata_struct *userdata) +{ + struct response_record *rrec; + struct nmb_packet *nmb = &p->packet.nmb; + + if (!(rrec = (struct response_record *)malloc(sizeof(*rrec)))) + { + DEBUG(0,("make_response_queue_record: malloc fail for response_record.\n")); + return NULL; + } + + bzero((char *)rrec, sizeof(*rrec)); + + rrec->response_id = nmb->header.name_trn_id; + + rrec->resp_fn = resp_fn; + rrec->timeout_fn = timeout_fn; + rrec->success_fn = success_fn; + rrec->fail_fn = fail_fn; + + rrec->packet = p; + + if(userdata) + { + /* Intelligent userdata. */ + if(userdata->copy_fn) + { + if((rrec->userdata = (*userdata->copy_fn)(userdata)) == NULL) + { + DEBUG(0,("make_response_queue_record: copy fail for userdata.\n")); + free(rrec); + return NULL; + } + } + else + { + /* Primitive userdata, do a memcpy. */ + if((rrec->userdata = (struct userdata_struct *) + malloc(sizeof(struct userdata_struct)+userdata->userdata_len)) == NULL) + { + DEBUG(0,("make_response_queue_record: malloc fail for userdata.\n")); + free(rrec); + return NULL; + } + rrec->userdata->copy_fn = userdata->copy_fn; + rrec->userdata->free_fn = userdata->free_fn; + rrec->userdata->userdata_len = userdata->userdata_len; + memcpy(rrec->userdata->data, userdata->data, userdata->userdata_len); + } + } + else + rrec->userdata = NULL; + + rrec->num_msgs = 0; + + if(!nmb->header.nm_flags.bcast) + rrec->repeat_interval = 5; /* 5 seconds for unicast packets. */ + else + rrec->repeat_interval = 1; /* XXXX should be in ms */ + rrec->repeat_count = 3; /* 3 retries */ + rrec->repeat_time = time(NULL) + rrec->repeat_interval; /* initial retry time */ + + /* Lock the packet so we won't lose it while it's on the list. */ + p->locked = True; + + add_response_record(subrec, rrec); + + return rrec; +} + +/**************************************************************************** + Find a response in a subnet's name query response list. + **************************************************************************/ + +static struct response_record *find_response_record_on_subnet( + struct subnet_record *subrec, uint16 id) +{ + struct response_record *rrec = NULL; + + for (rrec = subrec->responselist; rrec; rrec = rrec->next) + { + if (rrec->response_id == id) + { + DEBUG(4, ("find_response_record: found response record id = %hu on subnet %s\n", + id, subrec->subnet_name)); + break; + } + } + return rrec; +} + +/**************************************************************************** + Find a response in any subnet's name query response list. + **************************************************************************/ + +struct response_record *find_response_record(struct subnet_record **ppsubrec, + uint16 id) +{ + struct response_record *rrec = NULL; + + for ((*ppsubrec) = FIRST_SUBNET; (*ppsubrec); + (*ppsubrec) = NEXT_SUBNET_INCLUDING_UNICAST(*ppsubrec)) + { + if((rrec = find_response_record_on_subnet(*ppsubrec, id)) != NULL) + return rrec; + } + + /* There should never be response records on the remote_broadcast subnet. + Sanity check to ensure this is so. */ + if(remote_broadcast_subnet->responselist != NULL) + { + DEBUG(0,("find_response_record: response record found on subnet %s. This should \ +never happen !\n", remote_broadcast_subnet->subnet_name)); + } + + /* Now check the WINS server subnet if it exists. */ + if(wins_server_subnet != NULL) + { + *ppsubrec = wins_server_subnet; + if((rrec = find_response_record_on_subnet(*ppsubrec, id))!= NULL) + return rrec; + } + + DEBUG(0,("find_response_record: repsonse packet id %hu received with no \ +matching record.\n", id)); + + *ppsubrec = NULL; + + return NULL; +} diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c new file mode 100644 index 0000000000..e4b288aea5 --- /dev/null +++ b/source3/nmbd/nmbd_sendannounce.c @@ -0,0 +1,477 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1994-1997 + Copyright (C) Jeremy Allison 1994-1997 + + SMB Version handling + Copyright (C) John H Terpstra 1995-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; +extern pstring myname; +extern fstring myworkgroup; +extern char **my_netbios_names; +extern int updatecount; + +/**************************************************************************** + Send a browser reset packet. +**************************************************************************/ + +void send_browser_reset(int reset_type, char *to_name, int to_type, struct in_addr to_ip) +{ + pstring outbuf; + char *p; + + DEBUG(3,("send_browser_reset: sending reset request type %d to %s<%02x> IP %s.\n", + reset_type, to_name, to_type, inet_ntoa(to_ip) )); + + bzero(outbuf,sizeof(outbuf)); + p = outbuf; + CVAL(p,0) = ANN_ResetBrowserState; + p++; + CVAL(p,0) = reset_type; + p++; + + send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), + myname, 0x0, to_name, to_type, to_ip, FIRST_SUBNET->myip); +} + +/**************************************************************************** + Broadcast a packet to the local net requesting that all servers in this + workgroup announce themselves to us. + **************************************************************************/ + +void broadcast_announce_request(struct subnet_record *subrec, struct work_record *work) +{ + pstring outbuf; + char *p; + + work->needannounce = True; + + DEBUG(3,("broadcast_announce_request: sending announce request for workgroup %s \ +to subnet %s\n", work->work_group, subrec->subnet_name)); + + bzero(outbuf,sizeof(outbuf)); + p = outbuf; + CVAL(p,0) = ANN_AnnouncementRequest; + p++; + + CVAL(p,0) = work->token; /* (local) Unique workgroup token id. */ + p++; + StrnCpy(p,myname,15); + strupper(p); + p = skip_string(p,1); + + send_mailslot(False, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), + myname, 0x0, work->work_group,0x1e, subrec->bcast_ip, subrec->myip); +} + +/**************************************************************************** + Broadcast an announcement. + **************************************************************************/ + +static void send_announcement(struct subnet_record *subrec, int announce_type, + char *from_name, char *to_name, int to_type, struct in_addr to_ip, + time_t announce_interval, + char *server_name, int server_type, char *server_comment) +{ + pstring outbuf; + char *p; + + bzero(outbuf,sizeof(outbuf)); + p = outbuf+1; + + CVAL(outbuf,0) = announce_type; + + /* Announcement parameters. */ + CVAL(p,0) = updatecount; + SIVAL(p,1,announce_interval*1000); /* Milliseconds - despite the spec. */ + + StrnCpy(p+5,server_name,15); + strupper(p+5); + + CVAL(p,21) = lp_major_announce_version(); /* Major version. */ + CVAL(p,22) = lp_minor_announce_version(); /* Minor version. */ + + SIVAL(p,23,server_type & ~SV_TYPE_LOCAL_LIST_ONLY); + /* Browse version: got from NT/AS 4.00 - Value defined in smb.h (JHT). */ + SSVAL(p,27,BROWSER_ELECTION_VERSION); + SSVAL(p,29,BROWSER_CONSTANT); /* Browse signature. */ + + pstrcpy(p+31,server_comment); + p += 31; + p = skip_string(p,1); + + send_mailslot(False,BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), + from_name, 0x0, to_name, to_type, to_ip, subrec->myip); +} + +/**************************************************************************** + We are a local master browser. Announce this to WORKGROUP<1e>. +****************************************************************************/ + +static void send_local_master_announcement(struct subnet_record *subrec, struct work_record *work, + struct server_record *servrec) +{ + /* Ensure we don't have the prohibited bit set. */ + uint32 type = servrec->serv.type & ~SV_TYPE_LOCAL_LIST_ONLY; + + DEBUG(3,("send_local_master_announcement: type %x for name %s on subnet %s for workgroup %s\n", + type, myname, subrec->subnet_name, work->work_group)); + + send_announcement(subrec, ANN_LocalMasterAnnouncement, + myname, /* From nbt name. */ + work->work_group, 0x1e, /* To nbt name. */ + subrec->bcast_ip, /* To ip. */ + work->announce_interval, /* Time until next announce. */ + myname, /* Name to announce. */ + type, /* Type field. */ + servrec->serv.comment); +} + +/**************************************************************************** + Announce the workgroup WORKGROUP to MSBROWSE<01>. +****************************************************************************/ + +static void send_workgroup_announcement(struct subnet_record *subrec, struct work_record *work) +{ + DEBUG(3,("send_workgroup_announcement: on subnet %s for workgroup %s\n", + subrec->subnet_name, work->work_group)); + + send_announcement(subrec, ANN_DomainAnnouncement, + myname, /* From nbt name. */ + MSBROWSE, 0x1, /* To nbt name. */ + subrec->bcast_ip, /* To ip. */ + work->announce_interval, /* Time until next announce. */ + work->work_group, /* Name to announce. */ + SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT, /* workgroup announce flags. */ + myname); /* From name as comment. */ +} + +/**************************************************************************** + Announce the given host to WORKGROUP<1d>. +****************************************************************************/ + +static void send_host_announcement(struct subnet_record *subrec, struct work_record *work, + struct server_record *servrec) +{ + /* Ensure we don't have the prohibited bits set. */ + uint32 type = servrec->serv.type & ~SV_TYPE_LOCAL_LIST_ONLY; + + DEBUG(3,("send_host_announcement: type %x for host %s on subnet %s for workgroup %s\n", + type, servrec->serv.name, subrec->subnet_name, work->work_group)); + + send_announcement(subrec, ANN_HostAnnouncement, + servrec->serv.name, /* From nbt name. */ + work->work_group, 0x1d, /* To nbt name. */ + subrec->bcast_ip, /* To ip. */ + work->announce_interval, /* Time until next announce. */ + servrec->serv.name, /* Name to announce. */ + type, /* Type field. */ + servrec->serv.comment); +} + +/**************************************************************************** + Announce a server record. + ****************************************************************************/ + +static void announce_server(struct subnet_record *subrec, struct work_record *work, + struct server_record *servrec) +{ + /* Only do domain announcements if we are a master and it's + our primary name we're being asked to announce. */ + + if (AM_LOCAL_MASTER_BROWSER(work) && strequal(myname,servrec->serv.name)) + { + send_local_master_announcement(subrec, work, servrec); + send_workgroup_announcement(subrec, work); + } + else + { + send_host_announcement(subrec, work, servrec); + } +} + +/**************************************************************************** + Go through all my registered names on all broadcast subnets and announce + them if the timeout requires it. + **************************************************************************/ + +void announce_my_server_names(time_t t) +{ + struct subnet_record *subrec; + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + { + struct work_record *work = find_workgroup_on_subnet(subrec, myworkgroup); + + if(work) + { + struct server_record *servrec; + + if (work->needannounce) + { + /* Drop back to a max 3 minute announce. This is to prevent a + single lost packet from breaking things for too long. */ + + work->announce_interval = MIN(work->announce_interval, + CHECK_TIME_MIN_HOST_ANNCE*60); + work->lastannounce_time = t - (work->announce_interval+1); + work->needannounce = False; + } + + /* Announce every minute at first then progress to every 12 mins */ + if ((t - work->lastannounce_time) < work->announce_interval) + continue; + + if (work->announce_interval < (CHECK_TIME_MAX_HOST_ANNCE * 60)) + work->announce_interval += 60; + + work->lastannounce_time = t; + + for (servrec = work->serverlist; servrec; servrec = servrec->next) + { + if (is_myname(servrec->serv.name)) + announce_server(subrec, work, servrec); + } + } /* if work */ + } /* for subrec */ +} + +/* Announce timer. Moved into global static so it can be reset + when a machine becomes a local master browser. */ +static time_t announce_timer_last=0; + +/**************************************************************************** + Reset the announce_timer so that a local master browser announce will be done + immediately. + ****************************************************************************/ + +void reset_announce_timer() +{ + announce_timer_last = time(NULL) - (CHECK_TIME_MST_ANNOUNCE * 60); +} + +/**************************************************************************** + Announce myself as a local master browser to a domain master browser. + **************************************************************************/ + +void announce_myself_to_domain_master_browser(time_t t) +{ + struct subnet_record *subrec; + struct work_record *work; + + if(!we_are_a_wins_client()) + { + DEBUG(10,("announce_myself_to_domain_master_browser: no unicast subnet, ignoring.\n")); + return; + } + + if (!announce_timer_last) + announce_timer_last = t; + + if ((t-announce_timer_last) < (CHECK_TIME_MST_ANNOUNCE * 60)) + { + DEBUG(10,("announce_myself_to_domain_master_browser: t (%d) - last(%d) < %d\n", + t, announce_timer_last, CHECK_TIME_MST_ANNOUNCE * 60 )); + return; + } + + announce_timer_last = t; + + /* Look over all our broadcast subnets to see if any of them + has the state set as local master browser. */ + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + { + for (work = subrec->workgrouplist; work; work = work->next) + { + if (AM_LOCAL_MASTER_BROWSER(work)) + { + DEBUG(4,( "announce_myself_to_domain_master_browser: I am a local master browser for \ +workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name)); + + /* Look in nmbd_browsersync.c for the rest of this code. */ + announce_and_sync_with_domain_master_browser(subrec, work); + } + } + } +} + +/**************************************************************************** +Announce all samba's server entries as 'gone'. +This must *only* be called on shutdown. +****************************************************************************/ + +void announce_my_servers_removed(void) +{ + struct subnet_record *subrec; + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + { + struct work_record *work; + for (work = subrec->workgrouplist; work; work = work->next) + { + struct server_record *servrec; + + work->announce_interval = 0; + for (servrec = work->serverlist; servrec; servrec = servrec->next) + { + if (!is_myname(servrec->serv.name)) + continue; + servrec->serv.type = 0; + if(AM_LOCAL_MASTER_BROWSER(work)) + send_local_master_announcement(subrec, work, servrec); + send_host_announcement(subrec, work, servrec); + } + } + } +} + +/**************************************************************************** + Do all the "remote" announcements. These are used to put ourselves + on a remote browse list. They are done blind, no checking is done to + see if there is actually a local master browser at the other end. + **************************************************************************/ + +void announce_remote(time_t t) +{ + char *s,*ptr; + static time_t last_time = 0; + pstring s2; + struct in_addr addr; + char *comment; + int stype = lp_default_server_announce(); + + if (last_time && (t < (last_time + REMOTE_ANNOUNCE_INTERVAL))) + return; + + last_time = t; + + s = lp_remote_announce(); + if (!*s) + return; + + comment = lp_serverstring(); + + for (ptr=s; next_token(&ptr,s2,NULL); ) + { + /* The entries are of the form a.b.c.d/WORKGROUP with + WORKGROUP being optional */ + char *wgroup; + int i; + + wgroup = strchr(s2,'/'); + if (wgroup) + *wgroup++ = 0; + if (!wgroup || !*wgroup) + wgroup = myworkgroup; + + addr = *interpret_addr2(s2); + + /* Announce all our names including aliases */ + /* Give the ip address as the address of our first + broadcast subnet. */ + + for(i=0; my_netbios_names[i]; i++) + { + char *name = my_netbios_names[i]; + + DEBUG(5,("announce_remote: Doing remote announce for server %s to IP %s.\n", + name, inet_ntoa(addr) )); + + send_announcement(FIRST_SUBNET, ANN_HostAnnouncement, + name, /* From nbt name. */ + wgroup, 0x1e, /* To nbt name. */ + addr, /* To ip. */ + REMOTE_ANNOUNCE_INTERVAL, /* Time until next announce. */ + name, /* Name to announce. */ + stype, /* Type field. */ + comment); + } + } +} + +/**************************************************************************** + Implement the 'remote browse sync' feature Andrew added. + These are used to put our browse lists into remote browse lists. + **************************************************************************/ + +void browse_sync_remote(time_t t) +{ + char *s,*ptr; + static time_t last_time = 0; + pstring s2; + struct in_addr addr; + struct work_record *work; + pstring outbuf; + char *p; + + if (last_time && (t < (last_time + REMOTE_ANNOUNCE_INTERVAL))) + return; + + last_time = t; + + s = lp_remote_browse_sync(); + if (!*s) + return; + + /* + * We only do this if we are the local master browser + * for our workgroup on the firsst subnet. + */ + + if((work = find_workgroup_on_subnet(FIRST_SUBNET, myworkgroup)) == NULL) + { + DEBUG(0,("browse_sync_remote: Cannot find workgroup %s on subnet %s\n", + myworkgroup, FIRST_SUBNET->subnet_name )); + return; + } + + if(!AM_LOCAL_MASTER_BROWSER(work)) + { + DEBUG(5,("browse_sync_remote: We can only do this if we are a local master browser \ +for workgroup %s on subnet %s.\n", myworkgroup, FIRST_SUBNET->subnet_name )); + return; + } + + bzero(outbuf,sizeof(outbuf)); + p = outbuf; + CVAL(p,0) = ANN_MasterAnnouncement; + p++; + + StrnCpy(p,myname,15); + strupper(p); + p = skip_string(p,1); + + for (ptr=s; next_token(&ptr,s2,NULL); ) + { + /* The entries are of the form a.b.c.d */ + addr = *interpret_addr2(s2); + + DEBUG(5,("announce_remote: Doing remote browse sync announce for server %s to IP %s.\n", + myname, inet_ntoa(addr) )); + + send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), + myname, 0x0, "*", 0x0, addr, FIRST_SUBNET->myip); + } +} diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c new file mode 100644 index 0000000000..1281fe2ee3 --- /dev/null +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -0,0 +1,454 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1994-1997 + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "includes.h" +#include "smb.h" + +extern int ClientNMB; + +extern int DEBUGLEVEL; + +extern pstring myname; +extern fstring myworkgroup; +extern char **my_netbios_names; + +int updatecount = 0; + +/******************************************************************* + Remove all the servers in a work group. + ******************************************************************/ + +void remove_all_servers(struct work_record *work) +{ + struct server_record *servrec; + struct server_record *nexts; + + for (servrec = work->serverlist; servrec; servrec = nexts) + { + DEBUG(7,("remove_all_servers: Removing server %s\n",servrec->serv.name)); + nexts = servrec->next; + + if (servrec->prev) + servrec->prev->next = servrec->next; + if (servrec->next) + servrec->next->prev = servrec->prev; + + if (work->serverlist == servrec) + work->serverlist = servrec->next; + + free((char *)servrec); + + } + + work->subnet->work_changed = True; +} + +/*************************************************************************** + Add a server into the a workgroup serverlist. + **************************************************************************/ + +static void add_server_to_workgroup(struct work_record *work, + struct server_record *servrec) +{ + struct server_record *servrec2; + + if (!work->serverlist) + { + work->serverlist = servrec; + servrec->prev = NULL; + servrec->next = NULL; + return; + } + + for (servrec2 = work->serverlist; servrec2->next; servrec2 = servrec2->next) + ; + + servrec2->next = servrec; + servrec->next = NULL; + servrec->prev = servrec2; + work->subnet->work_changed = True; +} + +/**************************************************************************** + Find a server in a server list. + **************************************************************************/ + +struct server_record *find_server_in_workgroup(struct work_record *work, char *name) +{ + struct server_record *ret; + + for (ret = work->serverlist; ret; ret = ret->next) + { + if (strequal(ret->serv.name,name)) + return ret; + } + return NULL; +} + + +/**************************************************************************** + Remove a server entry from this workgroup. + ****************************************************************************/ + +static void remove_server_from_workgroup(struct work_record *work, struct server_record *servrec) +{ + if (servrec->prev) + servrec->prev->next = servrec->next; + if (servrec->next) + servrec->next->prev = servrec->prev; + + if (work->serverlist == servrec) + work->serverlist = servrec->next; + + free((char *)servrec); + work->subnet->work_changed = True; +} + +/**************************************************************************** + Create a server entry on this workgroup. + ****************************************************************************/ + +struct server_record *create_server_on_workgroup(struct work_record *work, + char *name,int servertype, + int ttl,char *comment) +{ + struct server_record *servrec; + + if (name[0] == '*') + { + DEBUG(7,("create_server_on_workgroup: not adding name starting with '*' (%s)\n", + name)); + return (NULL); + } + + if((servrec = find_server_in_workgroup(work, name)) != NULL) + { + DEBUG(0,("create_server_on_workgroup: Server %s already exists on \ +workgroup %s. This is a bug.\n", name, work->work_group)); + return NULL; + } + + if((servrec = (struct server_record *)malloc(sizeof(*servrec))) == NULL) + { + DEBUG(0,("create_server_entry_on_workgroup: malloc fail !\n")); + return NULL; + } + + bzero((char *)servrec,sizeof(*servrec)); + + servrec->subnet = work->subnet; + + StrnCpy(servrec->serv.name,name,sizeof(servrec->serv.name)-1); + StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1); + strupper(servrec->serv.name); + servrec->serv.type = servertype; + + update_server_ttl(servrec, ttl); + + add_server_to_workgroup(work, servrec); + + DEBUG(3,("create_server_on_workgroup: Created server entry %s of type %x (%s) on \ +workgroup %s.\n", name,servertype,comment, work->work_group)); + + work->subnet->work_changed = True; + + return(servrec); +} + +/******************************************************************* + Update the ttl field of a server record. +*******************************************************************/ + +void update_server_ttl(struct server_record *servrec, int ttl) +{ + if(ttl > lp_max_ttl()) + ttl = lp_max_ttl(); + + if(is_myname(servrec->serv.name)) + servrec->death_time = PERMANENT_TTL; + else + servrec->death_time = (ttl != PERMANENT_TTL) ? time(NULL)+(ttl*3) : PERMANENT_TTL; + + servrec->subnet->work_changed = True; +} + +/******************************************************************* + Expire old servers in the serverlist. A time of -1 indicates + everybody dies except those with a death_time of PERMANENT_TTL (which is 0). + This should only be called from expire_workgroups_and_servers(). + ******************************************************************/ + +void expire_servers(struct work_record *work, time_t t) +{ + struct server_record *servrec; + struct server_record *nexts; + + for (servrec = work->serverlist; servrec; servrec = nexts) + { + nexts = servrec->next; + + if ((servrec->death_time != PERMANENT_TTL) && ((t == -1) || (servrec->death_time < t))) + { + DEBUG(3,("expire_old_servers: Removing timed out server %s\n",servrec->serv.name)); + remove_server_from_workgroup(work, servrec); + work->subnet->work_changed = True; + } + } +} + +/******************************************************************* + Decide if we should write out a server record for this server. + We return zero if we should not. Check if we've already written + out this server record from an earlier subnet. +******************************************************************/ + +static uint32 write_this_server_name( struct subnet_record *subrec, + struct work_record *work, + struct server_record *servrec) +{ + struct subnet_record *ssub; + struct work_record *iwork; + struct server_record *sserv; + + /* Go through all the subnets we have already seen. */ + for (ssub = FIRST_SUBNET; ssub != subrec; ssub = NEXT_SUBNET_INCLUDING_UNICAST(ssub)) + { + for(iwork = ssub->workgrouplist; iwork; iwork = iwork->next) + { + if((sserv = find_server_in_workgroup( iwork, servrec->serv.name)) != NULL) + { + /* + * We have already written out this server record, don't + * do it again. This gives precedence to servers we have seen + * on the broadcast subnets over servers that may have been + * added via a sync on the unicast_subet. + * + * The correct way to do this is to have a serverlist file + * per subnet - this means changes to smbd as well. I may + * add this at a later date (JRA). + */ + + return 0; + } + } + } + + return servrec->serv.type; +} + +/******************************************************************* + Decide if we should write out a workgroup record for this workgroup. + We return zero if we should not. Don't write out myworkgroup (we've + already done it) and also don't write out a second workgroup record + on the unicast subnet that we've already written out on one of the + broadcast subnets. +******************************************************************/ + +static uint32 write_this_workgroup_name( struct subnet_record *subrec, + struct work_record *work) +{ + struct subnet_record *ssub; + + if(strequal(myworkgroup, work->work_group)) + return 0; + + /* This is a workgroup we have seen on a broadcast subnet. All + these have the same type. */ + + if(subrec != unicast_subnet) + return (SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT|SV_TYPE_LOCAL_LIST_ONLY); + + for(ssub = FIRST_SUBNET; ssub; ssub = NEXT_SUBNET_EXCLUDING_UNICAST(ssub)) + { + /* This is the unicast subnet so check if we've already written out + this subnet when we passed over the broadcast subnets. */ + + if(find_workgroup_on_subnet( ssub, work->work_group) != NULL) + return 0; + } + + /* All workgroups on the unicast subnet (except our own, which we + have already written out) cannot be local. */ + + return (SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT); +} + +/******************************************************************* + Write out the browse.dat file. + ******************************************************************/ + +void write_browse_list(time_t t, BOOL force_write) +{ + struct subnet_record *subrec; + struct work_record *work; + struct server_record *servrec; + pstring fname,fnamenew; + uint32 stype; + fstring tmp; + int i; + FILE *fp; + BOOL list_changed = force_write; + static time_t lasttime = 0; + + if (!lasttime) + lasttime = t; + if (t - lasttime < 5) + return; + + for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) + { + if(subrec->work_changed) + { + list_changed = True; + break; + } + } + + if(!list_changed) + return; + + lasttime = t; + updatecount++; + + dump_workgroups(); + + pstrcpy(fname,lp_lockdir()); + trim_string(fname,NULL,"/"); + strcat(fname,"/"); + strcat(fname,SERVER_LIST); + pstrcpy(fnamenew,fname); + strcat(fnamenew,"."); + + fp = fopen(fnamenew,"w"); + + if (!fp) + { + DEBUG(0,("write_browse_list: Can't open file %s. Error was %s\n", + fnamenew,strerror(errno))); + return; + } + + /* + * Write out a record for our workgroup. Use the record from the first + * subnet. + */ + + if((work = find_workgroup_on_subnet(FIRST_SUBNET, myworkgroup)) == NULL) + { + DEBUG(0,("write_browse_list: Fatal error - cannot find my workgroup %s\n", + myworkgroup)); + fclose(fp); + return; + } + + sprintf(tmp, "\"%s\"", work->work_group); + fprintf(fp, "%-25s ", tmp); + fprintf(fp, "%08x ", SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT|SV_TYPE_LOCAL_LIST_ONLY); + sprintf(tmp, "\"%s\" ", *work->local_master_browser_name ? work->local_master_browser_name : "Unknown"); + fprintf(fp, "%-30s", tmp); + fprintf(fp, "\"%s\"\n", work->work_group); + + /* + * We need to do something special for our own names. + * This is due to the fact that we may be a local master browser on + * one of our broadcast subnets, and a domain master on the unicast + * subnet. We iterate over the subnets and only write out the name + * once. + */ + + for (i=0; my_netbios_names[i]; i++) + { + stype = 0; + for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) + { + if((work = find_workgroup_on_subnet( subrec, myworkgroup )) == NULL) + continue; + if((servrec = find_server_in_workgroup( work, my_netbios_names[i])) == NULL) + continue; + + stype |= servrec->serv.type; + } + + /* Output server details, plus what workgroup they're in. */ + sprintf(tmp, "\"%s\"", my_netbios_names[i]); + fprintf(fp, "%-25s ", tmp); + fprintf(fp, "%08x ", stype); + sprintf(tmp, "\"%s\" ", lp_serverstring()); + fprintf(fp, "%-30s", tmp); + fprintf(fp, "\"%s\"\n", myworkgroup); + } + + for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) + { + subrec->work_changed = False; + + for (work = subrec->workgrouplist; work ; work = work->next) + { + /* Write out a workgroup record for a workgroup. */ + uint32 wg_type = write_this_workgroup_name( subrec, work); + + if(wg_type) + { + sprintf(tmp, "\"%s\"", work->work_group); + fprintf(fp, "%-25s ", tmp); + + fprintf(fp, "%08x ", wg_type); + sprintf(tmp, "\"%s\" ", *work->local_master_browser_name ? + work->local_master_browser_name : "Unknown" ); + fprintf(fp, "%-30s", tmp); + fprintf(fp, "\"%s\"\n", work->work_group); + } + + /* Now write out any server records a workgroup may have. */ + + for (servrec = work->serverlist; servrec ; servrec = servrec->next) + { + uint32 serv_type; + + /* We have already written our names here. */ + if(is_myname(servrec->serv.name)) + continue; + + serv_type = write_this_server_name(subrec, work, servrec); + + if(serv_type) + { + /* Output server details, plus what workgroup they're in. */ + sprintf(tmp, "\"%s\"", servrec->serv.name); + fprintf(fp, "%-25s ", tmp); + fprintf(fp, "%08x ", serv_type); + sprintf(tmp, "\"%s\" ", servrec->serv.comment); + fprintf(fp, "%-30s", tmp); + fprintf(fp, "\"%s\"\n", work->work_group); + } + } + } + } + + fclose(fp); + unlink(fname); + chmod(fnamenew,0644); + rename(fnamenew,fname); + DEBUG(3,("write_browse_list: Wrote browse list into file %s\n",fname)); +} diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c new file mode 100644 index 0000000000..93aecc21f2 --- /dev/null +++ b/source3/nmbd/nmbd_subnetdb.c @@ -0,0 +1,291 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1994-1997 + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + + Revision History: + +*/ + +#include "includes.h" +#include "smb.h" + +extern int ClientNMB; +extern int ClientDGRAM; +extern int global_nmb_port; + +extern int DEBUGLEVEL; + +extern pstring myname; +extern fstring myworkgroup; +extern char **my_netbios_names; +extern struct in_addr ipzero; + +/* This is the broadcast subnets database. */ +struct subnet_record *subnetlist = NULL; + +/* Extra subnets - keep these separate so enumeration code doesn't + run onto it by mistake. */ + +struct subnet_record *unicast_subnet = NULL; +struct subnet_record *remote_broadcast_subnet = NULL; +struct subnet_record *wins_server_subnet = NULL; + +extern uint16 samba_nb_type; /* Samba's NetBIOS name type. */ + +/**************************************************************************** + Add a subnet into the list. + **************************************************************************/ + +static void add_subnet(struct subnet_record *subrec) +{ + struct subnet_record *subrec2; + + if (!subnetlist) + { + subnetlist = subrec; + subrec->prev = NULL; + subrec->next = NULL; + return; + } + + for (subrec2 = subnetlist; subrec2->next; subrec2 = subrec2->next) + ; + + subrec2->next = subrec; + subrec->next = NULL; + subrec->prev = subrec2; +} + +/**************************************************************************** + Create a subnet entry. + ****************************************************************************/ + +static struct subnet_record *make_subnet(char *name, enum subnet_type type, + struct in_addr myip, struct in_addr bcast_ip, + struct in_addr mask_ip) +{ + struct subnet_record *subrec = NULL; + int nmb_sock, dgram_sock; + + /* Check if we are creating a non broadcast subnet - if so don't create + sockets. + */ + + if(type != NORMAL_SUBNET) + { + nmb_sock = -1; + dgram_sock = -1; + } + else + { + /* + * Attempt to open the sockets on port 137/138 for this interface + * and bind them. + * Fail the subnet creation if this fails. + */ + + if((nmb_sock = open_socket_in(SOCK_DGRAM, global_nmb_port,0, myip.s_addr)) == -1) + { + DEBUG(0,("make_subnet: Failed to open nmb socket on interface %s \ +for port %d. Error was %s\n", inet_ntoa(myip), global_nmb_port, strerror(errno))); + return NULL; + } + + if((dgram_sock = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3, myip.s_addr)) == -1) + { + DEBUG(0,("make_subnet: Failed to open dgram socket on interface %s \ +for port %d. Error was %s\n", inet_ntoa(myip), DGRAM_PORT, strerror(errno))); + return NULL; + } + + /* Make sure we can broadcast from these sockets. */ + set_socket_options(nmb_sock,"SO_BROADCAST"); + set_socket_options(dgram_sock,"SO_BROADCAST"); + + } + + subrec = (struct subnet_record *)malloc(sizeof(*subrec)); + + if (!subrec) + { + DEBUG(0,("make_subnet: malloc fail !\n")); + close(nmb_sock); + close(dgram_sock); + return(NULL); + } + + bzero((char *)subrec,sizeof(*subrec)); + + if((subrec->subnet_name = strdup(name)) == NULL) + { + DEBUG(0,("make_subnet: malloc fail for subnet name !\n")); + close(nmb_sock); + close(dgram_sock); + free((char *)subrec); + return(NULL); + } + + DEBUG(2, ("making subnet name:%s ", name )); + DEBUG(2, ("Broadcast address:%s ", inet_ntoa(bcast_ip))); + DEBUG(2, ("Subnet mask:%s\n", inet_ntoa(mask_ip))); + + subrec->namelist_changed = False; + subrec->work_changed = False; + + subrec->bcast_ip = bcast_ip; + subrec->mask_ip = mask_ip; + subrec->myip = myip; + subrec->type = type; + subrec->nmb_sock = nmb_sock; + subrec->dgram_sock = dgram_sock; + + return subrec; +} + +/**************************************************************************** + Create subnet entries. +**************************************************************************/ + +BOOL create_subnets() +{ + int num_interfaces = iface_count(); + int i; + struct in_addr unicast_ip; + + if(num_interfaces == 0) + { + DEBUG(0,("create_subnets: No local interfaces !\n")); + return False; + } + + /* + * Create subnets from all the local interfaces and thread them onto + * the linked list. + */ + + for (i = 0 ; i < num_interfaces; i++) + { + struct subnet_record *subrec; + struct interface *iface = get_interface(i); + + if((subrec = make_subnet(inet_ntoa(iface->ip), NORMAL_SUBNET, + iface->ip, iface->bcast,iface->nmask)) == NULL) + return False; + add_subnet(subrec); + } + + /* + * If we have been configured to use a WINS server, then try and + * get the ip address of it here. If we are the WINS server then + * set the unicast subnet address to be the first of our own real + * addresses. + */ + + if(*lp_wins_server()) + { + struct in_addr real_wins_ip; + real_wins_ip = *interpret_addr2(lp_wins_server()); + + if (!zero_ip(real_wins_ip)) + { + unicast_ip = real_wins_ip; + } + else + { + /* The smb.conf's wins server parameter MUST be a host_name + or an ip_address. */ + DEBUG(0,("invalid smb.conf parameter 'wins server'\n")); + return False; + } + } + else if(lp_we_are_a_wins_server()) + { + /* Pick the first interface ip address as the WINS server ip. */ + unicast_ip = *iface_n_ip(0); + } + else + { + /* We should not be using a WINS server at all. Set the + ip address of the subnet to be zero. */ + unicast_ip = ipzero; + } + + /* + * Create the unicast and remote broadcast subnets. + * Don't put these onto the linked list. + * The ip address of the unicast subnet is set to be + * the WINS server address, if it exists, or ipzero if not. + */ + + unicast_subnet = make_subnet( "UNICAST_SUBNET", UNICAST_SUBNET, + unicast_ip, unicast_ip, unicast_ip); + + remote_broadcast_subnet = make_subnet( "REMOTE_BROADCAST_SUBNET", + REMOTE_BROADCAST_SUBNET, + ipzero, ipzero, ipzero); + + if((unicast_subnet == NULL) || (remote_broadcast_subnet == NULL)) + return False; + + /* + * If we are WINS server, create the WINS_SERVER_SUBNET - don't put on + * the linked list. + */ + + if (lp_we_are_a_wins_server()) + { + if((wins_server_subnet = make_subnet("WINS_SERVER_SUBNET", + WINS_SERVER_SUBNET, + ipzero, ipzero, ipzero)) == NULL) + return False; + } + + return True; +} + +/******************************************************************* +Function to tell us if we can use the unicast subnet. +******************************************************************/ + +BOOL we_are_a_wins_client() +{ + static int cache_we_are_a_wins_client = -1; + + if(cache_we_are_a_wins_client == -1) + cache_we_are_a_wins_client = (ip_equal(ipzero, unicast_subnet->myip) ? + False : True); + + return cache_we_are_a_wins_client; +} + +/******************************************************************* +Access function used by NEXT_SUBNET_INCLUDING_UNICAST +******************************************************************/ + +struct subnet_record *get_next_subnet_maybe_unicast(struct subnet_record *subrec) +{ + if(subrec == unicast_subnet) + return NULL; + else if((subrec->next == NULL) && we_are_a_wins_client()) + return unicast_subnet; + else + return subrec->next; +} diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c new file mode 100644 index 0000000000..ed8653b8bf --- /dev/null +++ b/source3/nmbd/nmbd_winsproxy.c @@ -0,0 +1,195 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "includes.h" + +extern int DEBUGLEVEL; + +/**************************************************************************** +Function called when the name lookup succeeded. +****************************************************************************/ + +static void wins_proxy_name_query_request_success( struct subnet_record *subrec, + struct userdata_struct *userdata, + struct nmb_name *nmbname, struct in_addr ip, struct res_rec *rrec) +{ + struct packet_struct *original_packet; + struct subnet_record *orig_broadcast_subnet; + uint16 nb_flags; + int num_ips; + int i; + int ttl; + struct in_addr *iplist; + + /* Extract the original packet and the original broadcast subnet from + the userdata. */ + + memcpy( (char *)&orig_broadcast_subnet, userdata->data, sizeof(struct subnet_record *) ); + memcpy( (char *)&original_packet, &userdata->data[sizeof(struct subnet_record *)], + sizeof(struct packet_struct *) ); + + nb_flags = get_nb_flags( rrec->rdata ); + + num_ips = rrec->rdlength / 6; + if(num_ips == 0) + { + DEBUG(0,("wins_proxy_name_query_request_success: Invalid number of IP records (0) \ +returned for name %s.\n", namestr(nmbname) )); + return; + } + + if(num_ips == 1) + iplist = &ip; + else + { + if((iplist = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr) )) == NULL) + { + DEBUG(0,("wins_proxy_name_query_request_success: malloc fail !\n")); + return; + } + + for(i = 0; i < num_ips; i++) + putip( (char *)&iplist[i], (char *)&rrec->rdata[ (i*6) + 2]); + } + + /* Add the queried name to the original subnet as a WINS_PROXY_NAME. */ + + if(rrec == PERMANENT_TTL) + ttl = lp_max_ttl(); + + add_name_to_subnet( orig_broadcast_subnet, nmbname->name, nmbname->name_type, + nb_flags, ttl, WINS_PROXY_NAME, num_ips, iplist); + + if(iplist != &ip) + free((char *)iplist); + + /* Finally reply to the original name query. */ + reply_netbios_packet(original_packet, /* Packet to reply to. */ + 0, /* Result code. */ + NMB_QUERY, /* nmbd type code. */ + NMB_NAME_QUERY_OPCODE, /* opcode. */ + ttl, /* ttl. */ + rrec->rdata, /* data to send. */ + rrec->rdlength); /* data length. */ +} + +/**************************************************************************** +Function called when the name lookup failed. +****************************************************************************/ + +static void wins_proxy_name_query_request_fail(struct subnet_record *subrec, + struct response_record *rrec, + struct nmb_name *question_name, int fail_code) +{ + DEBUG(4,("wins_proxy_name_query_request_fail: WINS server returned error code %d for lookup \ +of name %s.\n", fail_code, namestr(question_name) )); +} + +/**************************************************************************** +Function to make a deep copy of the userdata we will need when the WINS +proxy query returns. +****************************************************************************/ + +static struct userdata_struct *wins_proxy_userdata_copy_fn(struct userdata_struct *userdata) +{ + struct packet_struct *p, *copy_of_p; + struct userdata_struct *new_userdata = + (struct userdata_struct *)malloc( userdata->userdata_len ); + + if(new_userdata == NULL) + return NULL; + + new_userdata->copy_fn = userdata->copy_fn; + new_userdata->free_fn = userdata->free_fn; + new_userdata->userdata_len = userdata->userdata_len; + + /* Copy the subnet_record pointer. */ + memcpy( new_userdata->data, userdata->data, sizeof(struct subnet_record *) ); + + /* Extract the pointer to the packet struct */ + memcpy((char *)&p, &userdata->data[sizeof(struct subnet_record *)], + sizeof(struct packet_struct *) ); + + /* Do a deep copy of the packet. */ + if((copy_of_p = copy_packet(p)) == NULL) + { + free((char *)new_userdata); + return NULL; + } + + /* Lock the copy. */ + copy_of_p->locked = True; + + memcpy( &new_userdata->data[sizeof(struct subnet_record *)], (char *)©_of_p, + sizeof(struct packet_struct *) ); + + return new_userdata; +} + +/**************************************************************************** +Function to free the deep copy of the userdata we used when the WINS +proxy query returned. +****************************************************************************/ + +static void wins_proxy_userdata_free_fn(struct userdata_struct *userdata) +{ + struct packet_struct *p; + + /* Extract the pointer to the packet struct */ + memcpy((char *)&p, &userdata->data[sizeof(struct subnet_record *)], + sizeof(struct packet_struct *)); + + /* Unlock the packet. */ + p->locked = False; + + free_packet(p); + free((char *)userdata); +} + +/**************************************************************************** + Make a WINS query on behalf of a broadcast client name query request. +****************************************************************************/ + +void make_wins_proxy_name_query_request( struct subnet_record *subrec, + struct packet_struct *incoming_packet, + struct nmb_name *question_name) +{ + char ud[sizeof(struct userdata_struct) + sizeof(struct subrec *) + + sizeof(struct packet_struct *)]; + struct userdata_struct *userdata = (struct userdata_struct *)ud; + + bzero(ud, sizeof(ud)); + + userdata->copy_fn = wins_proxy_userdata_copy_fn; + userdata->free_fn = wins_proxy_userdata_free_fn; + userdata->userdata_len = sizeof(ud); + memcpy( userdata->data, (char *)&subrec, sizeof(struct subnet_record *)); + memcpy( &userdata->data[sizeof(struct subnet_record *)], (char *)&incoming_packet, + sizeof(struct packet_struct *)); + + /* Now use the unicast subnet to query the name with the WINS server. */ + query_name( unicast_subnet, question_name->name, question_name->name_type, + wins_proxy_name_query_request_success, + wins_proxy_name_query_request_fail, + userdata); +} diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c new file mode 100644 index 0000000000..ba7b62e5ab --- /dev/null +++ b/source3/nmbd/nmbd_winsserver.c @@ -0,0 +1,1565 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "includes.h" + +#define WINS_LIST "wins.dat" + +extern int DEBUGLEVEL; +extern struct in_addr ipzero; + +/**************************************************************************** +Determine if this packet should be allocated to the WINS server. +*****************************************************************************/ + +BOOL packet_is_for_wins_server(struct packet_struct *packet) +{ + struct nmb_packet *nmb = &packet->packet.nmb; + + /* Only unicast packets go to a WINS server. */ + if((wins_server_subnet == NULL) || (nmb->header.nm_flags.bcast == True)) + { + DEBUG(10, ("packet_is_for_wins_server: failing WINS test #1.\n")); + return False; + } + + /* Check for node status requests. */ + if (nmb->question.question_type != QUESTION_TYPE_NB_QUERY) + return False; + + switch(nmb->header.opcode) + { + /* + * A WINS server issues WACKS, not receives them. + */ + case NMB_WACK_OPCODE: + DEBUG(10, ("packet_is_for_wins_server: failing WINS test #2 (WACK).\n")); + return False; + /* + * A WINS server only processes registration and + * release requests, not responses. + */ + case NMB_NAME_REG_OPCODE: + case NMB_NAME_MULTIHOMED_REG_OPCODE: + case NMB_NAME_REFRESH_OPCODE_8: /* ambiguity in rfc1002 about which is correct. */ + case NMB_NAME_REFRESH_OPCODE_9: /* WinNT uses 8 by default. */ + if(nmb->header.response) + { + DEBUG(10, ("packet_is_for_wins_server: failing WINS test #3 (response = 1).\n")); + return False; + } + break; + + case NMB_NAME_RELEASE_OPCODE: + if(nmb->header.response) + { + DEBUG(10, ("packet_is_for_wins_server: failing WINS test #4 (response = 1).\n")); + return False; + } + break; + + /* + * Only process unicast name queries with rd = 1. + */ + case NMB_NAME_QUERY_OPCODE: + if(!nmb->header.response && !nmb->header.nm_flags.recursion_desired) + { + DEBUG(10, ("packet_is_for_wins_server: failing WINS test #5 (response = 1).\n")); + return False; + } + break; + } + + return True; +} + +/**************************************************************************** +Utility function to decide what ttl to give a register/refresh request. +*****************************************************************************/ + +static int get_ttl_from_packet(struct nmb_packet *nmb) +{ + int ttl = nmb->additional->ttl; + + if(ttl < lp_min_wins_ttl() ) + ttl = lp_min_wins_ttl(); + + if(ttl > lp_max_wins_ttl() ) + ttl = lp_max_wins_ttl(); + + return ttl; +} + +/**************************************************************************** +Load or create the WINS database. +*****************************************************************************/ + +BOOL initialise_wins(void) +{ + fstring fname; + time_t time_now = time(NULL); + FILE *fp; + pstring line; + + if(!lp_we_are_a_wins_server()) + return True; + + add_samba_names_to_subnet(wins_server_subnet); + +#ifndef SYNC_DNS + /* Setup the async dns. */ + start_async_dns(); +#endif + + fstrcpy(fname,lp_lockdir()); + trim_string(fname,NULL,"/"); + strcat(fname,"/"); + strcat(fname,WINS_LIST); + + if((fp = fopen(fname,"r")) == NULL) + { + DEBUG(2,("initialise_wins: Can't open wins database file %s. Error was %s\n", + fname, strerror(errno) )); + return True; + } + + while (!feof(fp)) + { + pstring name_str, ip_str, ttl_str, nb_flags_str; + unsigned int num_ips; + pstring name; + struct in_addr *ip_list; + int type = 0; + uint16 nb_flags; + time_t ttl; + enum name_source source; + char *ptr; + char *p; + BOOL got_token; + BOOL was_ip; + int i; + + /* Read a line from the wins.dat file. Strips whitespace + from the beginning and end of the line. + */ + if (!fgets_slash(line,sizeof(pstring),fp)) + continue; + + if (*line == '#') + continue; + + ptr = line; + + /* + * Now we handle multiple IP addresses per name we need + * to iterate over the line twice. The first time to + * determine how many IP addresses there are, the second + * time to actually parse them into the ip_list array. + */ + + if (!next_token(&ptr,name_str,NULL)) + { + DEBUG(0,("initialise_wins: Failed to parse name when parsing line %s\n", line )); + continue; + } + + if (!next_token(&ptr,ttl_str,NULL)) + { + DEBUG(0,("initialise_wins: Failed to parse time to live when parsing line %s\n", line )); + continue; + } + + /* + * Determine the number of IP addresses per line. + */ + num_ips = 0; + do + { + got_token = next_token(&ptr,ip_str,NULL); + was_ip = False; + + if(got_token && strchr(ip_str, '.')) + { + num_ips++; + was_ip = True; + } + } while( got_token && was_ip); + + if(num_ips == 0) + { + DEBUG(0,("initialise_wins: Missing IP address when parsing line %s\n", line )); + continue; + } + + if(!got_token) + { + DEBUG(0,("initialise_wins: Missing nb_flags when parsing line %s\n", line )); + continue; + } + + /* Allocate the space for the ip_list. */ + if((ip_list = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr))) == NULL) + { + DEBUG(0,("initialise_wins: Malloc fail !\n")); + return False; + } + + /* Reset and re-parse the line. */ + ptr = line; + next_token(&ptr,name_str,NULL); + next_token(&ptr,ttl_str,NULL); + for(i = 0; i < num_ips; i++) + { + next_token(&ptr, ip_str, NULL); + ip_list[i] = *interpret_addr2(ip_str); + if (ip_equal(ip_list[i], ipzero)) + source = SELF_NAME; + } + next_token(&ptr,nb_flags_str,NULL); + + /* + * Deal with SELF or REGISTER name encoding. Default is REGISTER + * for compatibility with old nmbds. + */ + + if(nb_flags_str[strlen(nb_flags_str)-1] == 'S') + { + DEBUG(5,("initialise_wins: Ignoring SELF name %s\n", line)); + free((char *)ip_list); + continue; + } + + if(nb_flags_str[strlen(nb_flags_str)-1] == 'R') + nb_flags_str[strlen(nb_flags_str)-1] = '\0'; + + /* Netbios name. # divides the name from the type (hex): netbios#xx */ + pstrcpy(name,name_str); + + if((p = strchr(name,'#')) != NULL) + { + *p = 0; + sscanf(p+1,"%x",&type); + } + + /* Decode the netbios flags (hex) and the time-to-live (in seconds). */ + sscanf(nb_flags_str,"%hx",&nb_flags); + sscanf(ttl_str,"%ld",&ttl); + + /* add all entries that have 60 seconds or more to live */ + if ((ttl - 60) > time_now || ttl == PERMANENT_TTL) + { + struct name_record *namerec; + + if(ttl != PERMANENT_TTL) + ttl -= time_now; + + DEBUG(4, ("initialise_wins: add name: %s#%02x ttl = %ld first IP %s flags = %2hx\n", + name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); + + namerec = add_name_to_subnet(wins_server_subnet, name, type, nb_flags, + ttl, REGISTER_NAME, num_ips, ip_list); + + } + else + { + DEBUG(4, ("initialise_wins: not adding name (ttl problem) %s#%02x ttl = %ld first IP %s flags = %2hx\n", + name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); + } + + free((char *)ip_list); + } + + fclose(fp); + return True; +} + +/**************************************************************************** +Send a WINS WACK (Wait ACKnowledgement) response. +**************************************************************************/ + +static void send_wins_wack_response(int ttl, struct packet_struct *p) +{ + struct nmb_packet *nmb = &p->packet.nmb; + unsigned char rdata[2]; + + rdata[0] = rdata[1] = 0; + + /* Taken from nmblib.c - we need to send back almost + identical bytes from the requesting packet header. */ + + rdata[0] = (nmb->header.opcode & 0xF) << 3; + if (nmb->header.nm_flags.authoritative && + nmb->header.response) rdata[0] |= 0x4; + if (nmb->header.nm_flags.trunc) rdata[0] |= 0x2; + if (nmb->header.nm_flags.recursion_desired) rdata[0] |= 0x1; + if (nmb->header.nm_flags.recursion_available && + nmb->header.response) rdata[1] |= 0x80; + if (nmb->header.nm_flags.bcast) rdata[1] |= 0x10; + + reply_netbios_packet(p, /* Packet to reply to. */ + 0, /* Result code. */ + NMB_WAIT_ACK, /* nmbd type code. */ + NMB_WACK_OPCODE, /* opcode. */ + ttl, /* ttl. */ + (char *)rdata, /* data to send. */ + 2); /* data length. */ +} + +/**************************************************************************** +Send a WINS name registration response. +**************************************************************************/ + +static void send_wins_name_registration_response(int rcode, int ttl, struct packet_struct *p) +{ + struct nmb_packet *nmb = &p->packet.nmb; + char rdata[6]; + + memcpy(&rdata[0], &nmb->additional->rdata[0], 6); + + reply_netbios_packet(p, /* Packet to reply to. */ + rcode, /* Result code. */ + WINS_REG, /* nmbd type code. */ + NMB_NAME_REG_OPCODE, /* opcode. */ + ttl, /* ttl. */ + rdata, /* data to send. */ + 6); /* data length. */ +} + +/*********************************************************************** + Deal with a name refresh request to a WINS server. +************************************************************************/ + +void wins_process_name_refresh_request(struct subnet_record *subrec, + struct packet_struct *p) +{ + struct nmb_packet *nmb = &p->packet.nmb; + struct nmb_name *question = &nmb->question.question_name; + BOOL bcast = nmb->header.nm_flags.bcast; + uint16 nb_flags = get_nb_flags(nmb->additional->rdata); + BOOL group = (nb_flags & NB_GROUP) ? True : False; + struct name_record *namerec = NULL; + int ttl = get_ttl_from_packet(nmb); + struct in_addr from_ip; + + putip((char *)&from_ip,&nmb->additional->rdata[2]); + + if(bcast) + { + /* + * We should only get unicast name refresh packets here. + * Anyone trying to refresh broadcast should not be going to a WINS + * server. Log an error here. + */ + + DEBUG(0,("wins_process_name_refresh_request: broadcast name refresh request \ +received for name %s from IP %s on subnet %s. Error - should not be sent to WINS server\n", + namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + return; + } + + DEBUG(3,("wins_process_name_refresh_request: Name refresh for name %s \ +IP %s\n", namestr(question), inet_ntoa(from_ip) )); + + /* + * See if the name already exists. + */ + + namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); + + /* + * If this is a refresh request and the name doesn't exist then + * fail it. + */ + + if(namerec == NULL) + { + DEBUG(3,("wins_process_name_refresh_request: Name refresh for name %s and \ +the name does not exist.\n", namestr(question) )); + send_wins_name_registration_response(NAM_ERR, 0, p); + return; + } + + /* + * Check that the group bits for the refreshing name and the + * name in our database match. + */ + + if((namerec != NULL) && ((group && !NAME_GROUP(namerec)) || (!group && NAME_GROUP(namerec))) ) + { + DEBUG(3,("wins_process_name_refresh_request: Name %s group bit = %s \ +does not match group bit in WINS for this name.\n", namestr(question), group ? "True" : "False" )); + send_wins_name_registration_response(RFS_ERR, 0, p); + return; + } + + /* + * For a unique name check that the person refreshing the name is one of the registered IP + * addresses. If not - fail the refresh. Do the same for group names with a type of 0x1c. + * Just return success for unique 0x1d refreshes. For normal group names update the ttl + * and return success. + */ + + if((!group || (group && (question->name_type == 0x1c))) && find_ip_in_name_record(namerec, from_ip )) + { + /* + * Update the ttl. + */ + update_name_ttl(namerec, ttl); + send_wins_name_registration_response(0, ttl, p); + return; + } + else if(group) + { + /* + * Normal groups are all registered with an IP address of 255.255.255.255 + * so we can't search for the IP address. + */ + update_name_ttl(namerec, ttl); + send_wins_name_registration_response(0, ttl, p); + return; + } + else if(!group && (question->name_type == 0x1d)) + { + /* + * Special name type - just pretend the refresh succeeded. + */ + send_wins_name_registration_response(0, ttl, p); + return; + } + else + { + /* + * Fail the refresh. + */ + + DEBUG(3,("wins_process_name_refresh_request: Name refresh for name %s with IP %s and \ +is IP is not known to the name.\n", namestr(question), inet_ntoa(from_ip) )); + send_wins_name_registration_response(RFS_ERR, 0, p); + return; + } +} + +/*********************************************************************** + Deal with a name registration request query success to a client that + owned the name. + + We have a locked pointer to the original packet stashed away in the + userdata pointer. The success here is actually a failure as it means + the client we queried wants to keep the name, so we must return + a registration failure to the original requestor. +************************************************************************/ + +static void wins_register_query_success(struct subnet_record *subrec, + struct userdata_struct *userdata, + struct nmb_name *question_name, + struct in_addr ip, + struct res_rec *answers) +{ + struct packet_struct *orig_reg_packet; + + memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *)); + + DEBUG(3,("wins_register_query_success: Original client at IP %s still wants the \ +name %s. Rejecting registration request.\n", inet_ntoa(ip), namestr(question_name) )); + + send_wins_name_registration_response(RFS_ERR, 0, orig_reg_packet); + + orig_reg_packet->locked = False; + free_packet(orig_reg_packet); +} + +/*********************************************************************** + Deal with a name registration request query failure to a client that + owned the name. + + We have a locked pointer to the original packet stashed away in the + userdata pointer. The failure here is actually a success as it means + the client we queried didn't want to keep the name, so we can remove + the old name record and then successfully add the new name. +************************************************************************/ + +static void wins_register_query_fail(struct subnet_record *subrec, + struct response_record *rrec, + struct nmb_name *question_name, + int rcode) +{ + struct userdata_struct *userdata = rrec->userdata; + struct packet_struct *orig_reg_packet; + struct nmb_packet *nmb; + struct name_record *namerec = NULL; + uint16 nb_flags; + BOOL group; + + memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *)); + + nmb = &orig_reg_packet->packet.nmb; + + nb_flags = get_nb_flags(nmb->additional->rdata); + group = (nb_flags & NB_GROUP) ? True : False; + + /* + * We want to just add the name, as we now know the original owner + * didn't want it. But we can't just do that as an arbitary + * amount of time may have taken place between the name query + * request and this timeout/error response. So we check that + * the name still exists and is in the same state - if so + * we remove it and call wins_process_name_registration_request() + * as we know it will do the right thing now. + */ + + namerec = find_name_on_subnet(subrec, question_name, FIND_ANY_NAME); + + if((namerec != NULL) && (namerec->source == REGISTER_NAME) && + ip_equal(rrec->packet->ip, *namerec->ip) ) + { + remove_name_from_namelist( subrec, namerec); + namerec = NULL; + } + + if(namerec == NULL) + wins_process_name_registration_request(subrec, orig_reg_packet); + else + DEBUG(2,("wins_register_query_fail: The state of the WINS database changed between \ +querying for name %s in order to replace it and this reply.\n", namestr(question_name) )); + + orig_reg_packet->locked = False; + free_packet(orig_reg_packet); +} + +/*********************************************************************** + Deal with a name registration request to a WINS server. + + Use the following pseudocode : + + registering_group + | + | + +--------name exists + | | + | | + | +--- existing name is group + | | | + | | | + | | +--- add name (return). + | | + | | + | +--- exiting name is unique + | | + | | + | +--- query existing owner (return). + | + | + +--------name doesn't exist + | + | + +--- add name (return). + + registering_unique + | + | + +--------name exists + | | + | | + | +--- existing name is group + | | | + | | | + | | +--- fail add (return). + | | + | | + | +--- exiting name is unique + | | + | | + | +--- query existing owner (return). + | + | + +--------name doesn't exist + | + | + +--- add name (return). + + As can be seen from the above, the two cases may be collapsed onto each + other with the exception of the case where the name already exists and + is a group name. This case we handle with an if statement. + +************************************************************************/ + +void wins_process_name_registration_request(struct subnet_record *subrec, + struct packet_struct *p) +{ + struct nmb_packet *nmb = &p->packet.nmb; + struct nmb_name *question = &nmb->question.question_name; + BOOL bcast = nmb->header.nm_flags.bcast; + uint16 nb_flags = get_nb_flags(nmb->additional->rdata); + int ttl = get_ttl_from_packet(nmb); + struct name_record *namerec = NULL; + struct in_addr from_ip; + BOOL registering_group_name = (nb_flags & NB_GROUP) ? True : False;; + + putip((char *)&from_ip,&nmb->additional->rdata[2]); + + if(bcast) + { + /* + * We should only get unicast name registration packets here. + * Anyone trying to register broadcast should not be going to a WINS + * server. Log an error here. + */ + + DEBUG(0,("wins_process_name_registration_request: broadcast name registration request \ +received for name %s from IP %s on subnet %s. Error - should not be sent to WINS server\n", + namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + return; + } + + DEBUG(3,("wins_process_name_registration_request: %s name registration for name %s \ +IP %s\n", registering_group_name ? "Group" : "Unique", namestr(question), inet_ntoa(from_ip) )); + + /* + * See if the name already exists. + */ + + namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); + + /* + * Deal with the case where the name found was a dns entry. + * Remove it as we now have a NetBIOS client registering the + * name. + */ + + if((namerec != NULL) && ((namerec->source == DNS_NAME) || (namerec->source == DNSFAIL_NAME))) + { + DEBUG(5,("wins_process_name_registration_request: Name (%s) in WINS was a dns lookup \ +- removing it.\n", namestr(question) )); + remove_name_from_namelist( subrec, namerec); + namerec = NULL; + } + + /* + * Reject if the name exists and is not a REGISTER_NAME. + * (ie. Don't allow any static names to be overwritten. + */ + + if((namerec != NULL) && (namerec->source != REGISTER_NAME)) + { + DEBUG(3,("wins_process_name_registration_request: Attempt to register name %s. Name \ +already exists in WINS with source type %d.\n", namestr(question), namerec->source )); + send_wins_name_registration_response(RFS_ERR, 0, p); + return; + } + + /* + * Special policy decisions based on MS documentation. + * 1). All group names (except names ending in 0x1c) are added as 255.255.255.255. + * 2). All unique names ending in 0x1d are ignored, although a positive response is sent. + */ + + /* + * A group name is always added as the local broadcast address, except + * for group names ending in 0x1c. + * Group names with type 0x1c are registered with individual IP addresses. + */ + + if(registering_group_name && (question->name_type != 0x1c)) + from_ip = *interpret_addr2("255.255.255.255"); + + /* + * Ignore all attempts to register a unique 0x1d name, although return success. + */ + + if(!registering_group_name && (question->name_type == 0x1d)) + { + DEBUG(3,("wins_process_name_registration_request: Ignoring request \ +to register name %s from IP %s.", namestr(question), inet_ntoa(p->ip) )); + send_wins_name_registration_response(0, ttl, p); + return; + } + + /* + * Next two cases are the 'if statement' mentioned above. + */ + + if((namerec != NULL) && NAME_GROUP(namerec)) + { + if(registering_group_name) + { + /* + * If we are adding a group name, the name exists and is also a group entry just add this + * IP address to it and update the ttl. + */ + + DEBUG(3,("wins_process_name_registration_request: Adding IP %s to group name %s.\n", + inet_ntoa(from_ip), namestr(question) )); + /* + * Check the ip address is not already in the group. + */ + if(!find_ip_in_name_record(namerec, from_ip)) + add_ip_to_name_record(namerec, from_ip); + update_name_ttl(namerec, ttl); + send_wins_name_registration_response(0, ttl, p); + return; + } + else + { + /* + * If we are adding a unique name, the name exists in the WINS db + * and is a group name then reject the registration. + */ + + DEBUG(3,("wins_process_name_registration_request: Attempt to register name %s. Name \ +already exists in WINS as a GROUP name.\n", namestr(question) )); + send_wins_name_registration_response(RFS_ERR, 0, p); + return; + } + } + + /* + * From here on down we know that if the name exists in the WINS db it is + * a unique name, not a group name. + */ + + /* + * If the name exists and is one of our names then check the + * registering IP address. If it's not one of ours then automatically + * reject without doing the query - we know we will reject it. + */ + + if((namerec != NULL) && (is_myname(namerec->name.name)) ) + { + if(!ismyip(from_ip)) + { + DEBUG(3,("wins_process_name_registration_request: Attempt to register name %s. Name \ +is one of our (WINS server) names. Denying registration.\n", namestr(question) )); + send_wins_name_registration_response(RFS_ERR, 0, p); + return; + } + else + { + /* + * It's one of our names and one of our IP's - update the ttl. + */ + update_name_ttl(namerec, ttl); + send_wins_name_registration_response(0, ttl, p); + return; + } + } + + /* + * If the name exists and it is a unique registration and the registering IP + * is the same as the the (single) already registered IP then just update the ttl. + */ + + if(!registering_group_name && (namerec != NULL) && (namerec->num_ips == 1) && + ip_equal(namerec->ip[0], from_ip)) + { + update_name_ttl(namerec, ttl); + send_wins_name_registration_response(0, ttl, p); + return; + } + + /* + * Finally if the name exists do a query to the registering machine + * to see if they still claim to have the name. + */ + + if(namerec != NULL) + { + char ud[sizeof(struct userdata_struct) + sizeof(struct packet_struct *)]; + struct userdata_struct *userdata = (struct userdata_struct *)&ud; + + /* + * First send a WACK to the registering machine. + */ + + send_wins_wack_response(60, p); + + /* + * When the reply comes back we need the original packet. + * Lock this so it won't be freed and then put it into + * the userdata structure. + */ + + p->locked = True; + + userdata = (struct userdata_struct *)ud; + + userdata->copy_fn = NULL; + userdata->free_fn = NULL; + userdata->userdata_len = sizeof(struct packet_struct *); + memcpy(userdata->data, (char *)&p, sizeof(struct packet_struct *) ); + + /* + * As query_name uses the subnet broadcast address as the destination + * of the packet we temporarily change the subnet broadcast address to + * be the first IP address of the name owner and send the packet. This + * is a *horrible* hack but the alternative is to add the destination + * address parameter to all query_name() calls. I hate this code :-). + */ + + subrec->bcast_ip = *namerec->ip; + + query_name( subrec, question->name, question->name_type, + wins_register_query_success, + wins_register_query_fail, + userdata); + subrec->bcast_ip = ipzero; + return; + } + + /* + * Name did not exist - add it. + */ + + add_name_to_subnet(subrec, question->name, question->name_type, + nb_flags, ttl, REGISTER_NAME, 1, &from_ip); + + send_wins_name_registration_response(0, ttl, p); +} + +/*********************************************************************** + Deal with a mutihomed name query success to the machine that + requested the multihomed name registration. + + We have a locked pointer to the original packet stashed away in the + userdata pointer. +************************************************************************/ + +static void wins_multihomed_register_query_success(struct subnet_record *subrec, + struct userdata_struct *userdata, + struct nmb_name *question_name, + struct in_addr ip, + struct res_rec *answers) +{ + struct packet_struct *orig_reg_packet; + struct nmb_packet *nmb; + struct name_record *namerec = NULL; + struct in_addr from_ip; + int ttl; + + memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *)); + + nmb = &orig_reg_packet->packet.nmb; + + putip((char *)&from_ip,&nmb->additional->rdata[2]); + ttl = get_ttl_from_packet(nmb); + + /* + * We want to just add the new IP, as we now know the requesting + * machine claims to own it. But we can't just do that as an arbitary + * amount of time may have taken place between the name query + * request and this response. So we check that + * the name still exists and is in the same state - if so + * we just add the extra IP and update the ttl. + */ + + namerec = find_name_on_subnet(subrec, question_name, FIND_ANY_NAME); + + if( (namerec == NULL) || (namerec->source != REGISTER_NAME) ) + { + DEBUG(3,("wins_multihomed_register_query_success: name %s is not in the correct state to add \ +a subsequent IP addess.\n", namestr(question_name) )); + send_wins_name_registration_response(RFS_ERR, 0, orig_reg_packet); + return; + } + + if(!find_ip_in_name_record(namerec, from_ip)) + add_ip_to_name_record(namerec, from_ip); + update_name_ttl(namerec, ttl); + send_wins_name_registration_response(0, ttl, orig_reg_packet); + +} + +/*********************************************************************** + Deal with a name registration request query failure to a client that + owned the name. + + We have a locked pointer to the original packet stashed away in the + userdata pointer. +************************************************************************/ + +static void wins_multihomed_register_query_fail(struct subnet_record *subrec, + struct response_record *rrec, + struct nmb_name *question_name, + int rcode) +{ + struct userdata_struct *userdata = rrec->userdata; + struct packet_struct *orig_reg_packet; + + memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *)); + + DEBUG(3,("wins_multihomed_register_query_fail: Registering machine at IP %s failed to answer \ +query successfully for name %s.\n", inet_ntoa(orig_reg_packet->ip), namestr(question_name) )); + send_wins_name_registration_response(RFS_ERR, 0, orig_reg_packet); + return; +} + +/*********************************************************************** + Deal with a multihomed name registration request to a WINS server. + These cannot be group name registrations. +***********************************************************************/ + +void wins_process_multihomed_name_registration_request( struct subnet_record *subrec, + struct packet_struct *p) +{ + struct nmb_packet *nmb = &p->packet.nmb; + struct nmb_name *question = &nmb->question.question_name; + BOOL bcast = nmb->header.nm_flags.bcast; + uint16 nb_flags = get_nb_flags(nmb->additional->rdata); + int ttl = get_ttl_from_packet(nmb); + struct name_record *namerec = NULL; + struct in_addr from_ip; + BOOL group = (nb_flags & NB_GROUP) ? True : False;; + + putip((char *)&from_ip,&nmb->additional->rdata[2]); + + if(bcast) + { + /* + * We should only get unicast name registration packets here. + * Anyone trying to register broadcast should not be going to a WINS + * server. Log an error here. + */ + + DEBUG(0,("wins_process_multihomed_name_registration_request: broadcast name registration request \ +received for name %s from IP %s on subnet %s. Error - should not be sent to WINS server\n", + namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + return; + } + + /* + * Only unique names should be registered multihomed. + */ + + if(group) + { + DEBUG(0,("wins_process_multihomed_name_registration_request: group name registration request \ +received for name %s from IP %s on subnet %s. Errror - group names should not be multihomed.\n", + namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + return; + } + + DEBUG(3,("wins_process_multihomed_name_registration_request: name registration for name %s \ +IP %s\n", namestr(question), inet_ntoa(from_ip) )); + + /* + * Deal with policy regarding 0x1d names. + */ + + if(question->name_type == 0x1d) + { + DEBUG(3,("wins_process_multihomed_name_registration_request: Ignoring request \ +to register name %s from IP %s.", namestr(question), inet_ntoa(p->ip) )); + send_wins_name_registration_response(0, ttl, p); + return; + } + + /* + * See if the name already exists. + */ + + namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); + + /* + * Deal with the case where the name found was a dns entry. + * Remove it as we now have a NetBIOS client registering the + * name. + */ + + if((namerec != NULL) && ((namerec->source == DNS_NAME) || (namerec->source == DNSFAIL_NAME))) + { + DEBUG(5,("wins_process_multihomed_name_registration_request: Name (%s) in WINS was a dns lookup \ +- removing it.\n", namestr(question) )); + remove_name_from_namelist( subrec, namerec); + namerec = NULL; + } + + /* + * Reject if the name exists and is not a REGISTER_NAME. + * (ie. Don't allow any static names to be overwritten. + */ + + if((namerec != NULL) && (namerec->source != REGISTER_NAME)) + { + DEBUG(3,("wins_process_multihomed_name_registration_request: Attempt to register name %s. Name \ +already exists in WINS with source type %d.\n", namestr(question), namerec->source )); + send_wins_name_registration_response(RFS_ERR, 0, p); + return; + } + + /* + * Reject if the name exists and is a GROUP name. + */ + + if((namerec != NULL) && NAME_GROUP(namerec)) + { + DEBUG(3,("wins_process_multihomed_name_registration_request: Attempt to register name %s. Name \ +already exists in WINS as a GROUP name.\n", namestr(question) )); + send_wins_name_registration_response(RFS_ERR, 0, p); + return; + } + + /* + * From here on down we know that if the name exists in the WINS db it is + * a unique name, not a group name. + */ + + /* + * If the name exists and is one of our names then check the + * registering IP address. If it's not one of ours then automatically + * reject without doing the query - we know we will reject it. + */ + + if((namerec != NULL) && (is_myname(namerec->name.name)) ) + { + if(!ismyip(from_ip)) + { + DEBUG(3,("wins_process_multihomed_name_registration_request: Attempt to register name %s. Name \ +is one of our (WINS server) names. Denying registration.\n", namestr(question) )); + send_wins_name_registration_response(RFS_ERR, 0, p); + return; + } + else + { + /* + * It's one of our names and one of our IP's. Ensure the IP is in the record and + * update the ttl. + */ + if(!find_ip_in_name_record(namerec, from_ip)) + add_ip_to_name_record(namerec, from_ip); + update_name_ttl(namerec, ttl); + send_wins_name_registration_response(0, ttl, p); + return; + } + } + + /* + * If the name exists do a query to the owner + * to see if they still want the name. + */ + + if(namerec != NULL) + { + char ud[sizeof(struct userdata_struct) + sizeof(struct packet_struct *)]; + struct userdata_struct *userdata = (struct userdata_struct *)&ud; + + /* + * First send a WACK to the registering machine. + */ + + send_wins_wack_response(60, p); + + /* + * When the reply comes back we need the original packet. + * Lock this so it won't be freed and then put it into + * the userdata structure. + */ + + p->locked = True; + + userdata = (struct userdata_struct *)ud; + + userdata->copy_fn = NULL; + userdata->free_fn = NULL; + userdata->userdata_len = sizeof(struct packet_struct *); + memcpy(userdata->data, (char *)&p, sizeof(struct packet_struct *) ); + + /* + * As query_name uses the subnet broadcast address as the destination + * of the packet we temporarily change the subnet broadcast address to + * be the IP address of the requesting machine and send the packet. This + * is a *horrible* hack but the alternative is to add the destination + * address parameter to all query_name() calls. I hate this code :-). + */ + + subrec->bcast_ip = p->ip; + query_name( subrec, question->name, question->name_type, + wins_multihomed_register_query_success, + wins_multihomed_register_query_fail, + userdata); + subrec->bcast_ip = ipzero; + return; + } + + /* + * Name did not exist - add it. + */ + + add_name_to_subnet(subrec, question->name, question->name_type, + nb_flags, ttl, REGISTER_NAME, 1, &from_ip); + + send_wins_name_registration_response(0, ttl, p); +} + +/*********************************************************************** + Deal with the special name query for *<1b>. +***********************************************************************/ + +static void process_wins_dmb_query_request(struct subnet_record *subrec, + struct packet_struct *p) +{ + struct name_record *namerec = NULL; + char *prdata; + int num_ips; + + /* + * Go through all the names in the WINS db looking for those + * ending in <1b>. Use this to calculate the number of IP + * addresses we need to return. + */ + + num_ips = 0; + for(namerec = subrec->namelist; namerec; namerec = namerec->next) + { + if(namerec->name.name_type == 0x1b) + num_ips += namerec->num_ips; + } + + if(num_ips == 0) + { + /* + * There are no 0x1b names registered. Return name query fail. + */ + send_wins_name_query_response(NAM_ERR, p, NULL); + return; + } + + if((prdata = (char *)malloc( num_ips * 6 )) == NULL) + { + DEBUG(0,("process_wins_dmb_query_request: Malloc fail !.\n")); + return; + } + + /* + * Go through all the names again in the WINS db looking for those + * ending in <1b>. Add their IP addresses into the list we will + * return. + */ + + num_ips = 0; + for(namerec = subrec->namelist; namerec; namerec = namerec->next) + { + if(namerec->name.name_type == 0x1b) + { + int i; + for(i = 0; i < namerec->num_ips; i++) + { + set_nb_flags(&prdata[num_ips * 6],namerec->nb_flags); + putip((char *)&prdata[(num_ips * 6) + 2], &namerec->ip[i]); + num_ips++; + } + } + } + + /* + * Send back the reply containing the IP list. + */ + + reply_netbios_packet(p, /* Packet to reply to. */ + 0, /* Result code. */ + WINS_QUERY, /* nmbd type code. */ + NMB_NAME_QUERY_OPCODE, /* opcode. */ + lp_min_wins_ttl(), /* ttl. */ + prdata, /* data to send. */ + num_ips*6); /* data length. */ + + free(prdata); +} + +/**************************************************************************** +Send a WINS name query response. +**************************************************************************/ + +void send_wins_name_query_response(int rcode, struct packet_struct *p, + struct name_record *namerec) +{ + char rdata[6]; + char *prdata = rdata; + int reply_data_len = 0; + int ttl = 0; + int i = 0; + int j; + + bzero(rdata,6); + + if(rcode == 0) + { + int same_net_index; + + ttl = (namerec->death_time != PERMANENT_TTL) ? + namerec->death_time - p->timestamp : lp_max_wins_ttl(); + + /* Copy all known ip addresses into the return data. */ + /* Optimise for the common case of one IP address so + we don't need a malloc. */ + + if(namerec->num_ips == 1 ) + prdata = rdata; + else + { + if((prdata = (char *)malloc( namerec->num_ips * 6 )) == NULL) + { + DEBUG(0,("send_wins_name_query_response: malloc fail !\n")); + return; + } + + /* + * Look over the known IP addresses and see if one of them + * is on the same (local) net as the requesting IP address. If so then + * put that IP address into the packet as the first IP. + * We can only do this for local nets as they're the only + * ones we know the netmask for. + */ + + same_net_index = -1; + i = 0; + + if(is_local_net(p->ip)) + { + struct in_addr *n_mask = iface_nmask(p->ip); + + for( j = 0; j < namerec->num_ips; j++) + { + if(same_net( namerec->ip[j], p->ip, *n_mask)) + { + set_nb_flags(&prdata[0],namerec->nb_flags); + putip((char *)&prdata[2], &namerec->ip[j]); + same_net_index = j; + i = 1; + } + } + } + } + + for(; i < namerec->num_ips; i++) + { + if(i == same_net_index) + continue; + set_nb_flags(&prdata[i*6],namerec->nb_flags); + putip((char *)&prdata[2+(i*6)], &namerec->ip[i]); + } + reply_data_len = namerec->num_ips * 6; + + } + + reply_netbios_packet(p, /* Packet to reply to. */ + rcode, /* Result code. */ + WINS_QUERY, /* nmbd type code. */ + NMB_NAME_QUERY_OPCODE, /* opcode. */ + ttl, /* ttl. */ + prdata, /* data to send. */ + reply_data_len); /* data length. */ + + if((prdata != rdata) && (prdata != NULL)) + free(prdata); +} + +/*********************************************************************** + Deal with a name query. +***********************************************************************/ + +void wins_process_name_query_request(struct subnet_record *subrec, + struct packet_struct *p) +{ + struct nmb_packet *nmb = &p->packet.nmb; + struct nmb_name *question = &nmb->question.question_name; + struct name_record *namerec = NULL; + + DEBUG(3,("wins_process_name_query: name query for name %s from IP %s\n", + namestr(question), inet_ntoa(p->ip) )); + + /* + * Special name code. If the queried name is *<1b> then search + * the entire WINS database and return a list of all the IP addresses + * registered to any <1b> name. This is to allow domain master browsers + * to discover other domains that may not have a presence on their subnet. + */ + + if(strequal( question->name, "*") && (question->name_type == 0x1b)) + { + process_wins_dmb_query_request( subrec, p); + return; + } + + namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); + + if(namerec != NULL) + { + /* + * If it's a DNSFAIL_NAME then reply name not found. + */ + + if(namerec->source == DNSFAIL_NAME) + { + DEBUG(3,("wins_process_name_query: name query for name %s returning DNS fail.\n", + namestr(question) )); + send_wins_name_query_response(NAM_ERR, p, namerec); + return; + } + + /* + * If the name has expired then reply name not found. + */ + + if((namerec->death_time != PERMANENT_TTL) && (namerec->death_time < p->timestamp)) + { + DEBUG(3,("wins_process_name_query: name query for name %s - name expired. Returning fail.\n", + namestr(question) )); + send_wins_name_query_response(NAM_ERR, p, namerec); + return; + } + + DEBUG(3,("wins_process_name_query: name query for name %s returning first IP %s.\n", + namestr(question), inet_ntoa(namerec->ip[0]) )); + + send_wins_name_query_response(0, p, namerec); + return; + } + + /* + * Name not found in WINS - try a dns query if it's a 0x20 name. + */ + + if(lp_dns_proxy() && (question->name_type == 0x20)) + { + + DEBUG(3,("wins_process_name_query: name query for name %s not found - doing dns lookup.\n", + namestr(question) )); + + queue_dns_query(p, question, &namerec); + return; + } + + /* + * Name not found - return error. + */ + + send_wins_name_query_response(NAM_ERR, p, NULL); +} + +/**************************************************************************** +Send a WINS name release response. +**************************************************************************/ + +static void send_wins_name_release_response(int rcode, struct packet_struct *p) +{ + struct nmb_packet *nmb = &p->packet.nmb; + char rdata[6]; + + memcpy(&rdata[0], &nmb->additional->rdata[0], 6); + + reply_netbios_packet(p, /* Packet to reply to. */ + rcode, /* Result code. */ + NMB_REL, /* nmbd type code. */ + NMB_NAME_RELEASE_OPCODE, /* opcode. */ + 0, /* ttl. */ + rdata, /* data to send. */ + 6); /* data length. */ +} + +/*********************************************************************** + Deal with a name release. +***********************************************************************/ + +void wins_process_name_release_request(struct subnet_record *subrec, + struct packet_struct *p) +{ + struct nmb_packet *nmb = &p->packet.nmb; + struct nmb_name *question = &nmb->question.question_name; + BOOL bcast = nmb->header.nm_flags.bcast; + uint16 nb_flags = get_nb_flags(nmb->additional->rdata); + struct name_record *namerec = NULL; + struct in_addr from_ip; + BOOL releasing_group_name = (nb_flags & NB_GROUP) ? True : False;; + + putip((char *)&from_ip,&nmb->additional->rdata[2]); + + if(bcast) + { + /* + * We should only get unicast name registration packets here. + * Anyone trying to register broadcast should not be going to a WINS + * server. Log an error here. + */ + + DEBUG(0,("wins_process_name_release_request: broadcast name registration request \ +received for name %s from IP %s on subnet %s. Error - should not be sent to WINS server\n", + namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + return; + } + + DEBUG(3,("wins_process_name_release_request: %s name release for name %s \ +IP %s\n", releasing_group_name ? "Group" : "Unique", namestr(question), inet_ntoa(from_ip) )); + + /* + * Deal with policy regarding 0x1d names. + */ + + if(!releasing_group_name && (question->name_type == 0x1d)) + { + DEBUG(3,("wins_process_name_release_request: Ignoring request \ +to release name %s from IP %s.", namestr(question), inet_ntoa(p->ip) )); + send_wins_name_release_response(0, p); + return; + } + + /* + * See if the name already exists. + */ + + namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); + + if((namerec == NULL) || ((namerec != NULL) && (namerec->source != REGISTER_NAME)) ) + { + send_wins_name_release_response(NAM_ERR, p); + return; + } + + /* + * Check that the sending machine has permission to release this name. + * If it's a group name not ending in 0x1c then just say yes and let + * the group time out. + */ + + if(releasing_group_name && (question->name_type != 0x1c)) + { + send_wins_name_release_response(0, p); + return; + } + + /* + * Check that the releasing node is on the list of IP addresses + * for this name. Disallow the release if not. + */ + + if(!find_ip_in_name_record(namerec, from_ip)) + { + DEBUG(3,("wins_process_name_release_request: Refusing request to \ +release name %s as IP %s is not one of the known IP's for this name.\n", + namestr(question), inet_ntoa(from_ip) )); + send_wins_name_release_response(NAM_ERR, p); + return; + } + + /* + * Release the name and then remove the IP from the known list. + */ + + send_wins_name_release_response(0, p); + remove_ip_from_name_record(namerec, from_ip); + + /* + * Remove the name entirely if no IP addresses left. + */ + if (namerec->num_ips == 0) + remove_name_from_namelist(subrec, namerec); + +} + +/******************************************************************* + WINS time dependent processing. +******************************************************************/ + +void initiate_wins_processing(time_t t) +{ + static time_t lasttime = 0; + + if (!lasttime) + lasttime = t; + if (t - lasttime < 5) + return; + + if(!lp_we_are_a_wins_server()) + return; + + expire_names_on_subnet(wins_server_subnet, t); + + if(wins_server_subnet->namelist_changed) + wins_write_database(); + + wins_server_subnet->namelist_changed = False; +} + +/******************************************************************* + Write out the current WINS database. +******************************************************************/ + +void wins_write_database(void) +{ + struct name_record *namerec; + fstring fname, fnamenew; + + FILE *fp; + + if(!lp_we_are_a_wins_server()) + return; + + fstrcpy(fname,lp_lockdir()); + trim_string(fname,NULL,"/"); + strcat(fname,"/"); + strcat(fname,WINS_LIST); + fstrcpy(fnamenew,fname); + strcat(fnamenew,"."); + + if((fp = fopen(fnamenew,"w")) == NULL) + { + DEBUG(0,("wins_write_database: Can't open %s. Error was %s\n", fnamenew, strerror(errno))); + return; + } + + DEBUG(4,("wins_write_database: Dump of WINS name list.\n")); + + for (namerec = wins_server_subnet->namelist; namerec; namerec = namerec->next) + { + int i; + struct tm *tm; + + DEBUG(4,("%-19s ", namestr(&namerec->name) )); + + if(namerec->death_time != PERMANENT_TTL) + { + tm = LocalTime(&namerec->death_time); + DEBUG(4,("TTL = %s", asctime(tm) )); + } + else + DEBUG(4,("TTL = PERMANENT\t")); + + for (i = 0; i < namerec->num_ips; i++) + DEBUG(4,("%15s ", inet_ntoa(namerec->ip[i]) )); + DEBUG(4,("%2x\n", namerec->nb_flags )); + + if (namerec->source == REGISTER_NAME) + { + fprintf(fp, "%s#%02x %ld ", + namerec->name.name,namerec->name.name_type, /* Ignore scope. */ + namerec->death_time); + + for (i = 0; i < namerec->num_ips; i++) + fprintf(fp, "%s ", inet_ntoa(namerec->ip[i])); + fprintf(fp, "%2xR\n", namerec->nb_flags); + } + } + + fclose(fp); + unlink(fname); + chmod(fnamenew,0644); + rename(fnamenew,fname); +} diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c new file mode 100644 index 0000000000..828e29a024 --- /dev/null +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -0,0 +1,356 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Luke Kenneth Casson Leighton 1994-1997 + Copyright (C) Jeremy Allison 1994-1997 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +#include "includes.h" +#include "smb.h" + +extern int ClientNMB; + +extern int DEBUGLEVEL; + +extern pstring myname; +extern fstring myworkgroup; +extern char **my_netbios_names; +extern uint16 samba_nb_type; +extern struct in_addr ipzero; + +int workgroup_count = 0; /* unique index key: one for each workgroup */ + +/**************************************************************************** + Add a workgroup into the list. + **************************************************************************/ + +static void add_workgroup(struct subnet_record *subrec, struct work_record *work) +{ + struct work_record *w2; + + work->subnet = subrec; + + if (!subrec->workgrouplist) + { + subrec->workgrouplist = work; + work->prev = NULL; + work->next = NULL; + return; + } + + for (w2 = subrec->workgrouplist; w2->next; w2 = w2->next) + ; + + w2->next = work; + work->next = NULL; + work->prev = w2; + + subrec->work_changed = True; +} + +/**************************************************************************** + Create an empty workgroup. + **************************************************************************/ + +static struct work_record *create_workgroup(char *name, int ttl) +{ + struct work_record *work; + struct subnet_record *subrec; + int t = -1; + + if((work = (struct work_record *)malloc(sizeof(*work))) == NULL) + { + DEBUG(0,("create_workgroup: malloc fail !\n")); + return NULL; + } + bzero((char *)work, sizeof(*work)); + + StrnCpy(work->work_group,name,sizeof(work->work_group)-1); + work->serverlist = NULL; + + work->RunningElection = False; + work->ElectionCount = 0; + work->announce_interval = 0; + work->needelection = False; + work->needannounce = True; + work->lastannounce_time = time(NULL); + work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; + work->dom_state = DOMAIN_NONE; + work->log_state = LOGON_NONE; + + work->death_time = (ttl != PERMANENT_TTL) ? time(NULL)+(ttl*3) : PERMANENT_TTL; + + /* Make sure all token representations of workgroups are unique. */ + + for (subrec = FIRST_SUBNET; subrec && (t == -1); + subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) + { + struct work_record *w; + for (w = subrec->workgrouplist; w && t == -1; w = w->next) + { + if (strequal(w->work_group, work->work_group)) + t = w->token; + } + } + + if (t == -1) + work->token = ++workgroup_count; + else + work->token = t; + + /* No known local master browser as yet. */ + *work->local_master_browser_name = '\0'; + + /* No known domain master browser as yet. */ + *work->dmb_name.name = '\0'; + putip((char *)&work->dmb_addr, &ipzero); + + /* WfWg uses 01040b01 */ + /* Win95 uses 01041501 */ + /* NTAS uses ???????? */ + work->ElectionCriterion = (MAINTAIN_LIST)|(ELECTION_VERSION<<8); + work->ElectionCriterion |= (lp_os_level() << 24); + if (lp_domain_master()) + work->ElectionCriterion |= 0x80; + + return work; +} + +/******************************************************************* + Remove a workgroup. + ******************************************************************/ + +static struct work_record *remove_workgroup_from_subnet(struct subnet_record *subrec, + struct work_record *work) +{ + struct work_record *ret_work = NULL; + + DEBUG(3,("remove_workgroup: Removing workgroup %s\n", work->work_group)); + + ret_work = work->next; + + remove_all_servers(work); + + if (!work->serverlist) + { + if (work->prev) + work->prev->next = work->next; + if (work->next) + work->next->prev = work->prev; + + if (subrec->workgrouplist == work) + subrec->workgrouplist = work->next; + + free((char *)work); + } + + subrec->work_changed = True; + + return ret_work; +} + + +/**************************************************************************** + Find a workgroup in the workgroup list of a subnet. + **************************************************************************/ + +struct work_record *find_workgroup_on_subnet(struct subnet_record *subrec, + fstring name) +{ + struct work_record *ret; + + DEBUG(4, ("find_workgroup_on_subnet: workgroup search for %s on subnet %s: ", + name, subrec->subnet_name)); + + for (ret = subrec->workgrouplist; ret; ret = ret->next) + { + if (!strcmp(ret->work_group,name)) + { + DEBUG(4, ("found\n")); + return(ret); + } + } + DEBUG(4, ("not found\n")); + return NULL; +} + +/**************************************************************************** + Create a workgroup in the workgroup list of the subnet. + **************************************************************************/ + +struct work_record *create_workgroup_on_subnet(struct subnet_record *subrec, + fstring name, int ttl) +{ + struct work_record *work = NULL; + + DEBUG(4,("create_workgroup_on_subnet: creating group %s on subnet %s\n", + name, subrec->subnet_name)); + + if ((work = create_workgroup(name, ttl))) + { + add_workgroup(subrec, work); + + subrec->work_changed = True; + + return(work); + } + + return NULL; +} + +/**************************************************************************** + Update a workgroup ttl. + **************************************************************************/ + +void update_workgroup_ttl(struct work_record *work, int ttl) +{ + if(work->death_time != PERMANENT_TTL) + work->death_time = time(NULL)+(ttl*3); + work->subnet->work_changed = True; +} + +/**************************************************************************** + Fail function called if we cannot register the WORKGROUP<0> and + WORKGROUP<1e> names on the net. +**************************************************************************/ + +static void fail_register(struct subnet_record *subrec, struct response_record *rrec, + struct nmb_name *nmbname) +{ + DEBUG(0,("fail_register: Failed to register name %s on subnet %s.\n", + namestr(nmbname), subrec->subnet_name)); +} + +/**************************************************************************** + If the workgroup is our primary workgroup, add the required names to it. +**************************************************************************/ + +void initiate_myworkgroup_startup(struct subnet_record *subrec, struct work_record *work) +{ + int i; + + if(!strequal(myworkgroup, work->work_group)) + return; + + /* If this is a broadcast subnet then start elections on it + if we are so configured. */ + + if ((subrec != unicast_subnet) && (subrec != remote_broadcast_subnet) && + (subrec != wins_server_subnet) && lp_preferred_master() && + lp_local_master()) + { + DEBUG(3, ("initiate_myworkgroup_startup: preferred master startup for \ +workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name)); + work->needelection = True; + work->ElectionCriterion |= (1<<3); + } + + /* Register the WORKGROUP<0> and WORKGROUP<1e> names on the network. */ + + register_name(subrec,myworkgroup,0x0,samba_nb_type|NB_GROUP, + NULL, + fail_register,NULL); + + register_name(subrec,myworkgroup,0x1e,samba_nb_type|NB_GROUP, + NULL, + fail_register,NULL); + + for( i = 0; my_netbios_names[i]; i++) + { + char *name = my_netbios_names[i]; + int stype = lp_default_server_announce() | (lp_local_master() ? + SV_TYPE_POTENTIAL_BROWSER : 0 ); + + if(!strequal(myname, name)) + stype &= ~(SV_TYPE_MASTER_BROWSER|SV_TYPE_POTENTIAL_BROWSER| + SV_TYPE_DOMAIN_MASTER|SV_TYPE_DOMAIN_MEMBER); + + create_server_on_workgroup(work,name,stype|SV_TYPE_LOCAL_LIST_ONLY, + PERMANENT_TTL, lp_serverstring()); + DEBUG(3,("initiate_myworkgroup_startup: Added server name entry %s \ +on subnet %s\n", name, subrec->subnet_name)); + } +} + +/**************************************************************************** + Dump a copy of the workgroup database into the log file. + **************************************************************************/ + +void dump_workgroups(void) +{ + struct subnet_record *subrec; + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) + { + if (subrec->workgrouplist) + { + struct work_record *work; + + DEBUG(4,("dump_workgroups: dump workgroup on subnet %15s: ", subrec->subnet_name)); + DEBUG(4,(" netmask=%15s:\n", inet_ntoa(subrec->mask_ip))); + + for (work = subrec->workgrouplist; work; work = work->next) + { + DEBUG(4,("\t%s(%d) current master browser = %s\n", work->work_group, + work->token, + *work->local_master_browser_name ? work->local_master_browser_name : "UNKNOWN" )); + if (work->serverlist) + { + struct server_record *servrec; + for (servrec = work->serverlist; servrec; servrec = servrec->next) + { + DEBUG(4,("\t\t%s %8x (%s)\n", + servrec->serv.name, servrec->serv.type, servrec->serv.comment)); + } + } + } + } + } +} + +/**************************************************************************** + Expire any dead servers on all workgroups. If the workgroup has expired + remove it. + **************************************************************************/ + +void expire_workgroups_and_servers(time_t t) +{ + struct subnet_record *subrec; + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) + { + struct work_record *work; + struct work_record *nextwork; + + for (work = subrec->workgrouplist; work; work = nextwork) + { + nextwork = work->next; + expire_servers(work, t); + + if ((work->serverlist == NULL) && (work->death_time != PERMANENT_TTL) && + ((t == -1) || (work->death_time < t))) + { + DEBUG(3,("expire_workgroups_and_servers: Removing timed out workgroup %s\n", + work->work_group)); + remove_workgroup_from_subnet(subrec, work); + } + } + } +} -- cgit From 111245cd734a8a4a51a8e33c1cc2faed32f46d5e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 14 Dec 1997 17:49:41 +0000 Subject: allow name_type 0x20 as well as name_type 0x0 in dns proxying (This used to be commit be8a40487c128947cead19a43cf2f983e9543305) --- source3/nmbd/nmbd_winsserver.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index ba7b62e5ab..bd8febd65d 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1338,7 +1338,8 @@ void wins_process_name_query_request(struct subnet_record *subrec, * Name not found in WINS - try a dns query if it's a 0x20 name. */ - if(lp_dns_proxy() && (question->name_type == 0x20)) + if(lp_dns_proxy() && + ((question->name_type == 0x20) || question->name_type == 0)) { DEBUG(3,("wins_process_name_query: name query for name %s not found - doing dns lookup.\n", -- cgit From 5d4345b66de2bbf9d60e78682d820adb30b52a79 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 16 Dec 1997 07:30:25 +0000 Subject: nmbd_incomingdgrams.c: Fix bug with Syntax 5.1 servers reported by SGI where they do host announcements to LOCAL_MASTER_BROWSER_NAME<00> rather than WORKGROUP<1d>. nmbd_incomingrequests.c: Deal with WINS_PROXY_NAME issues - don't reply with that name if it's the same broadcast net. nmbd_serverlistdb.c: Stopped writing "Unknown" for local master browsers we don't know. nmbd_winsproxy.c: Deal with WINS_PROXY_NAME issues - don't reply with that name if it's the same broadcast net. Jeremy. (This used to be commit 5adfff94c9020bd57f84ccbc8fba5b1d8d1615af) --- source3/nmbd/nmbd_incomingdgrams.c | 11 +++++++++++ source3/nmbd/nmbd_incomingrequests.c | 36 +++++++++++++++++++++++++++++++++++- source3/nmbd/nmbd_serverlistdb.c | 5 ++--- source3/nmbd/nmbd_winsproxy.c | 25 ++++++++++++++++++++++++- 4 files changed, 72 insertions(+), 5 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 24b4f33838..d43b1369e6 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -134,6 +134,17 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p /* For a host announce the workgroup name is the destination name. */ work_name = dgram->dest_name.name; + /* + * Syntax servers version 5.1 send HostAnnounce packets to + * *THE WRONG NAME*. They send to LOCAL_MASTER_BROWSER_NAME<00> + * instead of WORKGROUP<1d> name. So to fix this we check if + * the workgroup name is our own name, and if so change it + * to be our primary workgroup name. + */ + + if(strequal(work_name, myname)) + work_name = myworkgroup; + /* * We are being very agressive here in adding a workgroup * name on the basis of a host announcing itself as being diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index ff4bb07a45..73abdf0050 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -213,7 +213,19 @@ IP %s on subnet %s\n", namestr(question), inet_ntoa(from_ip), subrec->subnet_nam /* See if the name already exists. */ namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); - + + /* + * If the name being registered exists and is a WINS_PROXY_NAME + * then delete the WINS proxy name entry so we don't reply erroneously + * later to queries. + */ + + if((namerec != NULL) && (namerec->source == WINS_PROXY_NAME)) + { + remove_name_from_namelist( subrec, namerec ); + namerec = NULL; + } + if (!group) { /* Unique name. */ @@ -469,6 +481,28 @@ void process_name_query_request(struct subnet_record *subrec, struct packet_stru /* The requested name is a directed query, or it's SELF or PERMANENT or WINS_PROXY, or it's a Domain Master type. */ + /* + * If this is a WINS_PROXY_NAME, then ceck that none of the IP + * addresses we are returning is on the same broadcast subnet + * as the requesting packet. If it is then don't reply as the + * actual machine will be replying also and we don't want two + * replies to a broadcast query. + */ + + if(namerec->source == WINS_PROXY_NAME) + { + for( i = 0; i < namerec->num_ips; i++) + { + if(same_net( namerec->ip[i], subrec->myip, subrec->mask_ip )) + { + DEBUG(5,("process_name_query_request: name %s is a WINS proxy name and is also \ +on the same subnet (%s) as the requestor. Not replying.\n", + namestr(&namerec->name), subrec->subnet_name )); + return; + } + } + } + ttl = (namerec->death_time != PERMANENT_TTL) ? namerec->death_time - p->timestamp : lp_max_ttl(); diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index 1281fe2ee3..b3dca36c84 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -365,7 +365,7 @@ void write_browse_list(time_t t, BOOL force_write) sprintf(tmp, "\"%s\"", work->work_group); fprintf(fp, "%-25s ", tmp); fprintf(fp, "%08x ", SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT|SV_TYPE_LOCAL_LIST_ONLY); - sprintf(tmp, "\"%s\" ", *work->local_master_browser_name ? work->local_master_browser_name : "Unknown"); + sprintf(tmp, "\"%s\" ", work->local_master_browser_name); fprintf(fp, "%-30s", tmp); fprintf(fp, "\"%s\"\n", work->work_group); @@ -414,8 +414,7 @@ void write_browse_list(time_t t, BOOL force_write) fprintf(fp, "%-25s ", tmp); fprintf(fp, "%08x ", wg_type); - sprintf(tmp, "\"%s\" ", *work->local_master_browser_name ? - work->local_master_browser_name : "Unknown" ); + sprintf(tmp, "\"%s\" ", work->local_master_browser_name); fprintf(fp, "%-30s", tmp); fprintf(fp, "\"%s\"\n", work->work_group); } diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index ed8653b8bf..4f2326795d 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -35,6 +35,7 @@ static void wins_proxy_name_query_request_success( struct subnet_record *subrec, { struct packet_struct *original_packet; struct subnet_record *orig_broadcast_subnet; + struct name_record *namerec; uint16 nb_flags; int num_ips; int i; @@ -77,12 +78,34 @@ returned for name %s.\n", namestr(nmbname) )); if(rrec == PERMANENT_TTL) ttl = lp_max_ttl(); - add_name_to_subnet( orig_broadcast_subnet, nmbname->name, nmbname->name_type, + namerec = add_name_to_subnet( orig_broadcast_subnet, nmbname->name, nmbname->name_type, nb_flags, ttl, WINS_PROXY_NAME, num_ips, iplist); if(iplist != &ip) free((char *)iplist); + /* + * Check that none of the IP addresses we are returning is on the + * same broadcast subnet as the original requesting packet. If it + * is then don't reply (although we still need to add the name + * to the cache) as the actual machine will be replying also + * and we don't want two replies to a broadcast query. + */ + + if(namerec && original_packet->packet.nmb.header.nm_flags.bcast) + { + for( i = 0; i < namerec->num_ips; i++) + { + if(same_net( namerec->ip[i], orig_broadcast_subnet->myip, orig_broadcast_subnet->mask_ip )) + { + DEBUG(5,("wins_proxy_name_query_request_success: name %s is a WINS proxy name and is also \ +on the same subnet (%s) as the requestor. Not replying.\n", + namestr(&namerec->name), orig_broadcast_subnet->subnet_name )); + return; + } + } + } + /* Finally reply to the original name query. */ reply_netbios_packet(original_packet, /* Packet to reply to. */ 0, /* Result code. */ -- cgit From 16bf14adf1b78f7ec4d3d267d500258fdf399627 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 16 Dec 1997 09:20:34 +0000 Subject: Added Lanman announce patch from Jacco de Leeuw . Also added code to stop old Samba servers that announce the workgroup name as master browser name when they are a local master browser. Jeremy. (This used to be commit 3605da055737e2cc0fbfffe7772721943a5be8bd) --- source3/nmbd/nmbd.c | 10 +++ source3/nmbd/nmbd_become_lmb.c | 29 ++++++- source3/nmbd/nmbd_incomingdgrams.c | 151 ++++++++++++++++++++++++++++++++++--- source3/nmbd/nmbd_packets.c | 56 ++++++++++++++ source3/nmbd/nmbd_processlogon.c | 2 +- source3/nmbd/nmbd_sendannounce.c | 106 ++++++++++++++++++++++++++ 6 files changed, 341 insertions(+), 13 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 11cd50cd76..86f01d8e79 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -47,6 +47,9 @@ extern char **my_netbios_names; /* are we running as a daemon ? */ static BOOL is_daemon = False; +/* have we found LanMan clients yet? */ +BOOL found_lm_clients = False; + /* what server type are we currently */ time_t StartupTime = 0; @@ -288,6 +291,13 @@ static void process(void) */ announce_my_server_names(t); + /* + * Send out any LanMan broadcast announcements + * of our server names. + * (nmbd_sendannounce.c) + */ + announce_my_lm_server_names(t); + /* * If we are a local master browser, periodically * announce ourselves to the domain master browser. diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index 7f54471a24..6496a2f9e5 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -115,7 +115,7 @@ in workgroup %s on subnet %s\n", /* Forget who the local master browser was for this workgroup. */ - *work->local_master_browser_name = '\0'; + set_workgroup_local_master_browser_name( work, ""); /* * Ensure the IP address of this subnet is not registered as one @@ -333,8 +333,7 @@ on subnet %s\n", work->work_group, subrec->subnet_name)); subrec->work_changed = True; /* Add this name to the workgroup as local master browser. */ - StrnCpy(work->local_master_browser_name, myname, - sizeof(work->local_master_browser_name)-1); + set_workgroup_local_master_browser_name( work, myname); /* Count the number of servers we have on our list. If it's less than 10 (just a heuristic) request the servers @@ -532,3 +531,27 @@ in workgroup %s on subnet %s\n", become_local_master_fail1, userdata); } + +/*************************************************************** + Utility function to set the local master browser name. Does + some sanity checking as old versions of Samba seem to sometimes + say that the master browser name for a workgroup is the same + as the workgroup name. +****************************************************************/ + +void set_workgroup_local_master_browser_name( struct work_record *work, char *newname) +{ + DEBUG(5,("set_workgroup_local_master_browser_name: setting local master name to '%s' \ +for workgroup %s.\n", newname, work->work_group )); + + if(strequal( work->work_group, newname)) + { + DEBUG(5, ("set_workgroup_local_master_browser_name: Refusing to set \ +local_master_browser_name for workgroup %s to workgroup name.\n", + work->work_group )); + return; + } + + StrnCpy(work->local_master_browser_name, newname, + sizeof(work->local_master_browser_name)-1); +} diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index d43b1369e6..452516b64e 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -28,6 +28,7 @@ extern int DEBUGLEVEL; extern pstring myname; extern fstring myworkgroup; +extern BOOL found_lm_clients; #if 0 @@ -223,9 +224,7 @@ void process_workgroup_announce(struct subnet_record *subrec, struct packet_stru if(*work->local_master_browser_name == '\0') { /* Set the master browser name. */ - StrnCpy(work->local_master_browser_name, master_name, - sizeof(work->local_master_browser_name)-1); - + set_workgroup_local_master_browser_name( work, master_name ); } subrec->work_changed = True; @@ -324,9 +323,7 @@ a local master browser for workgroup %s and we think we are master. Forcing elec StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1); } - /* Set the master browser name. */ - StrnCpy(work->local_master_browser_name, server_name, - sizeof(work->local_master_browser_name)-1); + set_workgroup_local_master_browser_name( work, server_name ); subrec->work_changed = True; } @@ -384,6 +381,105 @@ master - ignoring master announce.\n")); update_browser_death_time(browrec); } +/******************************************************************* + Process an incoming LanMan host announcement packet. +*******************************************************************/ + +void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf) +{ + struct dgram_packet *dgram = &p->packet.dgram; + uint32 servertype = IVAL(buf,1); + int osmajor=CVAL(buf,5); /* major version of node software */ + int osminor=CVAL(buf,6); /* minor version of node software */ + int ttl = SVAL(buf,7); + char *announce_name = buf+9; + struct work_record *work; + struct server_record *servrec; + char *work_name; + char *source_name = dgram->source_name.name; + pstring comment; + char *s = buf+9; + + s = skip_string(s,1); + StrnCpy(comment, s, 43); + + DEBUG(3,("process_lm_host_announce: LM Announcement from %s<%02x> IP %s to \ +%s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip), + namestr(&dgram->dest_name),announce_name)); + + DEBUG(5,("process_lm_host_announce: os=(%d,%d) ttl=%d server type=%08x comment=%s\n", + osmajor, osminor, ttl, servertype,comment)); + + if ((osmajor < 36) || (osmajor > 38) || (osminor !=0)) + { + DEBUG(5,("process_lm_host_announce: LM Announcement packet does not " \ + "originate from OS/2 Warp client. Ignoring packet.\n")); + /* Could have been from a Windows machine (with its LM Announce enabled), + or a Samba server. Then don't disrupt the current browse list. */ + return; + } + + /* Filter servertype to remove impossible bits. */ + servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM); + + /* A LanMan host announcement must be sent to the name WORKGROUP<00>. */ + if(dgram->dest_name.name_type != 0x00) + { + DEBUG(2,("process_lm_host_announce: incorrect name type for destination from IP %s \ +(was %02x) should be 0x00. Allowing packet anyway.\n", + inet_ntoa(p->ip), dgram->dest_name.name_type)); + /* Change it so it was. */ + dgram->dest_name.name_type = 0x00; + } + + /* For a LanMan host announce the workgroup name is the destination name. */ + work_name = dgram->dest_name.name; + + /* + * Syntax servers version 5.1 send HostAnnounce packets to + * *THE WRONG NAME*. They send to LOCAL_MASTER_BROWSER_NAME<00> + * instead of WORKGROUP<1d> name. So to fix this we check if + * the workgroup name is our own name, and if so change it + * to be our primary workgroup name. This code is probably + * not needed in the LanMan announce code, but it won't hurt. + */ + + if(strequal(work_name, myname)) + work_name = myworkgroup; + + /* + * We are being very agressive here in adding a workgroup + * name on the basis of a host announcing itself as being + * in that workgroup. Maybe we should wait for the workgroup + * announce instead ? JRA. + */ + + if ((work = find_workgroup_on_subnet(subrec, work_name))==NULL) + { + /* We have no record of this workgroup. Add it. */ + if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL) + return; + } + + if((servrec = find_server_in_workgroup( work, announce_name))==NULL) + { + /* If this server is not already in the workgroup, add it. */ + create_server_on_workgroup(work, announce_name, + servertype|SV_TYPE_LOCAL_LIST_ONLY, + ttl, comment); + } + else + { + /* Update the record. */ + servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; + update_server_ttl( servrec, ttl); + StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1); + } + + subrec->work_changed = True; + found_lm_clients = True; +} + /**************************************************************************** Send a backup list response. *****************************************************************************/ @@ -600,12 +696,12 @@ request from %s IP %s state=0x%X\n", } /******************************************************************* - Process a announcement request packet. + Process an announcement request packet. We don't respond immediately, we just check it's a request for - out workgroup and then set the flag telling the announce code + our workgroup and then set the flag telling the announce code in nmbd_sendannounce.c:announce_my_server_names that an announcement is needed soon. - ******************************************************************/ +******************************************************************/ void process_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf) { @@ -634,3 +730,40 @@ void process_announce_request(struct subnet_record *subrec, struct packet_struct work->needannounce = True; } + +/******************************************************************* + Process a LanMan announcement request packet. + We don't respond immediately, we just check it's a request for + our workgroup and then set the flag telling that we have found + a LanMan client (DOS or OS/2) and that we will have to start + sending LanMan announcements (unless specifically disabled + through the "lm_announce" parameter in smb.conf) +******************************************************************/ + +void process_lm_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf) +{ + struct dgram_packet *dgram = &p->packet.dgram; + struct work_record *work; + char *workgroup_name = dgram->dest_name.name; + + DEBUG(3,("process_lm_announce_request: Announce request from %s IP %s to %s.\n", + namestr(&dgram->source_name), inet_ntoa(p->ip), + namestr(&dgram->dest_name))); + + /* We only send announcement requests on our workgroup. */ + if(strequal(workgroup_name, myworkgroup) == False) + { + DEBUG(7,("process_lm_announce_request: Ignoring announce request for workgroup %s.\n", + workgroup_name)); + return; + } + + if((work = find_workgroup_on_subnet(subrec, workgroup_name)) == NULL) + { + DEBUG(0,("process_announce_request: Unable to find workgroup %s on subnet !\n", + workgroup_name)); + return; + } + + found_lm_clients = True; +} diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 43249cc0a3..4fb0543967 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1023,6 +1023,56 @@ command code %d from %s IP %s to %s\n", } } +/**************************************************************************** + Dispatch a LanMan browse frame from port 138 to the correct processing function. +****************************************************************************/ + +void process_lanman_packet(struct packet_struct *p, char *buf,int len) +{ + struct dgram_packet *dgram = &p->packet.dgram; + int command = SVAL(buf,0); + struct subnet_record *subrec = find_subnet_for_dgram_browse_packet(p); + + /* Drop the packet if it's a different NetBIOS scope, or + the source is from one of our names. */ + + if (!strequal(dgram->dest_name.scope,scope )) + { + DEBUG(7,("process_lanman_packet: Discarding datagram from IP %s. Scope (%s) \ +mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, scope)); + return; + } + + if (is_myname(dgram->source_name.name)) + { + DEBUG(0,("process_lanman_packet: Discarding datagram from IP %s. Source name \ +%s is one of our names !\n", inet_ntoa(p->ip), namestr(&dgram->source_name))); + return; + } + + switch (command) + { + case ANN_HostAnnouncement: + { + debug_browse_data(buf, len); + process_lm_host_announce(subrec, p, buf+1); + break; + } + case ANN_AnnouncementRequest: + { + process_lm_announce_request(subrec, p, buf+1); + break; + } + default: + { + DEBUG(0,("process_lanman_packet: On subnet %s ignoring browse packet \ +command code %d from %s IP %s to %s\n", + subrec->subnet_name, command, namestr(&dgram->source_name), + inet_ntoa(p->ip), namestr(&dgram->dest_name))); + } + } +} + /**************************************************************************** Determine if a packet is for us on port 138. Note that to have any chance of being efficient we need to drop as many packets as possible at this @@ -1100,6 +1150,12 @@ static void process_dgram(struct packet_struct *p) return; } + /* Datagram packet received for the LAN Manager mailslot */ + if (strequal(smb_buf(buf),LANMAN_MAILSLOT)) { + process_lanman_packet(p,buf2,len); + return; + } + /* Datagram packet received for the domain logon mailslot */ if (strequal(smb_buf(buf),NET_LOGON_MAILSLOT)) { diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index ae917564fe..cd2fbfd0a5 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -63,7 +63,7 @@ void process_logon_packet(struct packet_struct *p,char *buf,int len, if (!lp_domain_logons()) { - DEBUG(3,("process_logon_packet: Logon packet received from IP %S and domain \ + DEBUG(3,("process_logon_packet: Logon packet received from IP %s and domain \ logons are not enabled.\n", inet_ntoa(p->ip) )); return; } diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index e4b288aea5..aac3dad366 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -32,6 +32,7 @@ extern pstring myname; extern fstring myworkgroup; extern char **my_netbios_names; extern int updatecount; +extern BOOL found_lm_clients; /**************************************************************************** Send a browser reset packet. @@ -126,6 +127,37 @@ static void send_announcement(struct subnet_record *subrec, int announce_type, from_name, 0x0, to_name, to_type, to_ip, subrec->myip); } +/**************************************************************************** + Broadcast a LanMan announcement. +**************************************************************************/ + +static void send_lm_announcement(struct subnet_record *subrec, int announce_type, + char *from_name, char *to_name, int to_type, struct in_addr to_ip, + time_t announce_interval, + char *server_name, int server_type, char *server_comment) +{ + pstring outbuf; + char *p=outbuf; + + bzero(outbuf,sizeof(outbuf)); + + SSVAL(p,0,announce_type); + SIVAL(p,2,server_type & ~SV_TYPE_LOCAL_LIST_ONLY); + CVAL(p,6) = lp_major_announce_version(); /* Major version. */ + CVAL(p,7) = lp_minor_announce_version(); /* Minor version. */ + SSVAL(p,8,announce_interval); /* In seconds - according to spec. */ + + p += 10; + StrnCpy(p,server_name,15); + strupper(p); + p = skip_string(p,1); + pstrcpy(p,server_comment); + p = skip_string(p,1); + + send_mailslot(False,LANMAN_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), + from_name, 0x0, to_name, to_type, to_ip, subrec->myip); +} + /**************************************************************************** We are a local master browser. Announce this to WORKGROUP<1e>. ****************************************************************************/ @@ -191,6 +223,29 @@ static void send_host_announcement(struct subnet_record *subrec, struct work_rec servrec->serv.comment); } +/**************************************************************************** + Announce the given LanMan host +****************************************************************************/ + +static void send_lm_host_announcement(struct subnet_record *subrec, struct work_record *work, + struct server_record *servrec, int lm_interval) +{ + /* Ensure we don't have the prohibited bits set. */ + uint32 type = servrec->serv.type & ~SV_TYPE_LOCAL_LIST_ONLY; + + DEBUG(3,("send_lm_host_announcement: type %x for host %s on subnet %s for workgroup %s, ttl: %d\n", + type, servrec->serv.name, subrec->subnet_name, work->work_group, lm_interval)); + + send_lm_announcement(subrec, ANN_HostAnnouncement, + servrec->serv.name, /* From nbt name. */ + work->work_group, 0x00, /* To nbt name. */ + subrec->bcast_ip, /* To ip. */ + lm_interval, /* Time until next announce. */ + servrec->serv.name, /* Name to announce. */ + type, /* Type field. */ + servrec->serv.comment); +} + /**************************************************************************** Announce a server record. ****************************************************************************/ @@ -258,6 +313,56 @@ void announce_my_server_names(time_t t) } /* for subrec */ } +/**************************************************************************** + Go through all my registered names on all broadcast subnets and announce + them as a LanMan server if the timeout requires it. +**************************************************************************/ + +void announce_my_lm_server_names(time_t t) +{ + struct subnet_record *subrec; + static time_t last_lm_announce_time=0; + int announce_interval = lp_lm_interval(); + int lm_announce = lp_lm_announce(); + + if ((announce_interval <= 0) || (lm_announce <= 0)) + { + /* user absolutely does not want LM announcements to be sent. */ + return; + } + + if ((lm_announce >= 2) && (!found_lm_clients)) + { + /* has been set to 2 (Auto) but no LM clients detected (yet). */ + return; + } + + /* Otherwise: must have been set to 1 (Yes), or LM clients *have* + been detected. */ + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + { + struct work_record *work = find_workgroup_on_subnet(subrec, myworkgroup); + + if(work) + { + struct server_record *servrec; + + if (last_lm_announce_time && ((t - last_lm_announce_time) < announce_interval )) + continue; + + last_lm_announce_time = t; + + for (servrec = work->serverlist; servrec; servrec = servrec->next) + { + if (is_myname(servrec->serv.name)) + /* skipping equivalent of announce_server() */ + send_lm_host_announcement(subrec, work, servrec, announce_interval); + } + } /* if work */ + } /* for subrec */ +} + /* Announce timer. Moved into global static so it can be reset when a machine becomes a local master browser. */ static time_t announce_timer_last=0; @@ -342,6 +447,7 @@ void announce_my_servers_removed(void) if(AM_LOCAL_MASTER_BROWSER(work)) send_local_master_announcement(subrec, work, servrec); send_host_announcement(subrec, work, servrec); + send_lm_host_announcement(subrec, work, servrec, 0); } } } -- cgit From e9ef2a5a5e9bbec686429f00366b6d72cba83d03 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 16 Dec 1997 12:21:39 +0000 Subject: WHATSNEW.txt - updated for 1.9.18alpha13. docs/smb.conf.5: Removed unused NTDOMAIN params. Added new params. source/loadparm.c: Put #ifdef NTDOMAIN around unused params. source/nmbd_become_lmb.c: Removed check for workgroup name in lmb name. Jeremy. (This used to be commit 5136c5ec119968b39e2cf9d7f3e6836d9286a51f) --- source3/nmbd/nmbd_become_lmb.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index 6496a2f9e5..6dcd61d76c 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -544,6 +544,11 @@ void set_workgroup_local_master_browser_name( struct work_record *work, char *ne DEBUG(5,("set_workgroup_local_master_browser_name: setting local master name to '%s' \ for workgroup %s.\n", newname, work->work_group )); +#if 0 + /* + * Apparently some sites use the workgroup name as the local + * master browser name. Arrrrggghhhhh ! (JRA). + */ if(strequal( work->work_group, newname)) { DEBUG(5, ("set_workgroup_local_master_browser_name: Refusing to set \ @@ -551,6 +556,7 @@ local_master_browser_name for workgroup %s to workgroup name.\n", work->work_group )); return; } +#endif StrnCpy(work->local_master_browser_name, newname, sizeof(work->local_master_browser_name)-1); -- cgit From b80b6ea3b43a880bb392b8ef8caaff0f11bb80ef Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Dec 1997 11:05:00 +0000 Subject: kanji.h: Fixed problems with re-definitions of strchr and others on AIX. nmbd_nameregister.c: Applied fix found by "Eloy A. Paris" (don't re-use lists after you have freed them :-). Jeremy. (This used to be commit bcfcc39a2752de0fb35b419d005bb1a86fd15fea) --- source3/nmbd/nmbd_nameregister.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index 603daaa531..cdaef1a767 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -283,8 +283,6 @@ static BOOL multihomed_register_name( struct nmb_name *nmbname, uint16 nb_flags, add_name_to_subnet(unicast_subnet, nmbname->name, nmbname->name_type, nb_flags, lp_max_ttl(), SELF_NAME, num_ips, ip_list); - free((char *)ip_list); - /* Now try and register the name, num_ips times. On the last time use the given success and fail functions. */ @@ -302,10 +300,14 @@ static BOOL multihomed_register_name( struct nmb_name *nmbname, uint16 nb_flags, { DEBUG(0,("multihomed_register_name: Failed to send packet trying to \ register name %s IP %s\n", namestr(nmbname), inet_ntoa(ip_list[i]) )); + + free((char *)ip_list); return True; } } + free((char *)ip_list); + return False; } -- cgit From 74c807fcc5a02a5a5b0ea06ddf2bc65e85938716 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 23 Dec 1997 06:38:36 +0000 Subject: architecture.doc: Re-added since I lost it (sorry Dan :-). nmbd.c nmbd_responserecordsdb.c: Spelling mistake fixes. Jeremy. (This used to be commit f5dfc8913bcce71f14b59c5ed8415b0f54b58e6c) --- source3/nmbd/nmbd.c | 2 +- source3/nmbd/nmbd_responserecordsdb.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 86f01d8e79..de83c0f67e 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -384,7 +384,7 @@ static void process(void) initiate_wins_processing(t); /* - * Go through the repsonse record queue and time out or re-transmit + * Go through the response record queue and time out or re-transmit * and expired entries. * (nmbd_packets.c) */ diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index bc0c0745f5..031853271b 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -229,7 +229,7 @@ never happen !\n", remote_broadcast_subnet->subnet_name)); return rrec; } - DEBUG(0,("find_response_record: repsonse packet id %hu received with no \ + DEBUG(0,("find_response_record: response packet id %hu received with no \ matching record.\n", id)); *ppsubrec = NULL; -- cgit From 0c0777400fd4a2e0586761514345153c9ee218ed Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 24 Dec 1997 07:10:04 +0000 Subject: Finally added the code Andrew wanted that will allow a Samba domain master browser to use the *<1b> feature of the Samba WINS server to get a full workgroup list. nmbd.c: Added timed call to collect_all_workgroup_names_from_wins_server(). nmbd_browsesync.c: Meat of the code to implement collect_all_workgroup_names_from_wins_server(). nmbd_incomingdgrams.c: Fixed comment typo. Jeremy. (This used to be commit 1a3ab3e84a415a6d0d9b4cafb3f0f6e8cbe3fa69) --- source3/nmbd/nmbd.c | 8 ++ source3/nmbd/nmbd_browsesync.c | 202 +++++++++++++++++++++++++++++++++++++ source3/nmbd/nmbd_incomingdgrams.c | 2 +- 3 files changed, 211 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index de83c0f67e..da98fbfde3 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -383,6 +383,14 @@ static void process(void) */ initiate_wins_processing(t); + /* + * If we are a domain master browser, attempt to contact the + * WINS server to get a list of all known WORKGROUPS/DOMAINS. + * This will only work to a Samba WINS server. + * (nmbd_browsesync.c) + */ + collect_all_workgroup_names_from_wins_server(t); + /* * Go through the response record queue and time out or re-transmit * and expired entries. diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index b899e2e8bc..cc81807de4 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -29,6 +29,7 @@ extern int DEBUGLEVEL; extern pstring scope; extern struct in_addr ipzero; extern pstring myname; +extern fstring myworkgroup; /* This is our local master browser list database. */ extern struct browse_cache_record *lmb_browserlist; @@ -447,6 +448,13 @@ void announce_and_sync_with_domain_master_browser( struct subnet_record *subrec, { struct nmb_name nmbname; + /* Only do this if we are using a WINS server. */ + if(we_are_a_wins_client() == False) + { + DEBUG(10,("announce_and_sync_with_domain_master_browser: Ignoring as we are not a WINS client.\n")); + return; + } + make_nmb_name(&nmbname,work->work_group,0x1b,scope); /* First, query for the WORKGROUP<1b> name from the WINS server. */ @@ -456,3 +464,197 @@ void announce_and_sync_with_domain_master_browser( struct subnet_record *subrec, NULL); } + +/**************************************************************************** + Function called when a node status query to a domain master browser IP succeeds. + This function is only called on query to a Samba 1.9.18 or above WINS server. + + Note that adding the workgroup name is enough for this workgroup to be + browsable by clients, as clients query the WINS server or broadcast + nets for the WORKGROUP<1b> name when they want to browse a workgroup + they are not in. We do not need to do a sync with this Domain Master + Browser in order for our browse clients to see machines in this workgroup. + JRA. +****************************************************************************/ + +static void get_domain_master_name_node_status_success(struct subnet_record *subrec, + struct userdata_struct *userdata, + struct res_rec *answers, + struct in_addr from_ip) +{ + struct work_record *work; + + DEBUG(3,("get_domain_master_name_node_status_success: Success in node status from ip %s\n", + inet_ntoa(from_ip) )); + + /* + * Go through the list of names found at answers->rdata and look for + * the first WORKGROUP<0x1b> name. + */ + + if(answers->rdata != NULL) + { + char *p = answers->rdata; + int numnames = CVAL(p, 0); + + p += 1; + + while (numnames--) + { + char qname[17]; + uint16 nb_flags; + int name_type; + + StrnCpy(qname,p,15); + name_type = CVAL(p,15); + nb_flags = get_nb_flags(&p[16]); + trim_string(qname,NULL," "); + + p += 18; + + if(!(nb_flags & NB_GROUP) && (name_type == 0x1b)) + { + + DEBUG(5,("get_domain_master_name_node_status_success: IP %s is a domain \ +master browser for workgroup %s. Adding this name.\n", inet_ntoa(from_ip), qname )); + + /* + * If we don't already know about this workgroup, add it + * to the workgroup list on the unicast_subnet. + */ + if((work = find_workgroup_on_subnet( subrec, qname)) == NULL) + { + /* + * Add it - with an hour in the cache. + */ + if((work = create_workgroup_on_subnet(subrec, qname, 60*60))==NULL) + return; + } + break; + } + } + } + else + DEBUG(0,("get_domain_master_name_node_status_success: Failed to find a WORKGROUP<0x1b> \ +name in reply from IP %s.\n", inet_ntoa(from_ip) )); +} + +/**************************************************************************** + Function called when a node status query to a domain master browser IP fails. +****************************************************************************/ + +static void get_domain_master_name_node_status_fail(struct subnet_record *subrec, + struct response_record *rrec) +{ + DEBUG(0,("get_domain_master_name_node_status_fail: Doing a node status request to \ +the domain master browser at IP %s failed. Cannot get workgroup name.\n", + inet_ntoa(rrec->packet->ip) )); + +} +/**************************************************************************** + Function called when a query for *<1b> name succeeds. +****************************************************************************/ + +static void find_all_domain_master_names_query_success(struct subnet_record *subrec, + struct userdata_struct *userdata_in, + struct nmb_name *q_name, struct in_addr answer_ip, struct res_rec *rrec) +{ + /* + * We now have a list of all the domain master browsers for all workgroups + * that have registered with the WINS server. Now do a node status request + * to each one and look for the first 1b name in the reply. This will be + * the workgroup name that we will add to the unicast subnet as a 'non-local' + * workgroup. + */ + + struct nmb_name nmbname; + struct in_addr send_ip; + int i; + + DEBUG(5,("find_all_domain_master_names_query_succes: Got answer from WINS server of %d \ +IP addresses for Domain Master Browsers.\n", rrec->rdlength / 6 )); + + for(i = 0; i < rrec->rdlength / 6; i++) + { + /* Initiate the node status requests. */ + bzero((char *)&nmbname, sizeof(nmbname)); + nmbname.name[0] = '*'; + + putip((char *)&send_ip, (char *)&rrec->rdata[(i*6) + 2]); + + /* + * Don't send node status requests to ourself. + */ + + if(ismyip( send_ip )) + { + DEBUG(5,("find_all_domain_master_names_query_succes: Not sending node status \ +to our own IP %s.\n", inet_ntoa(send_ip) )); + continue; + } + + DEBUG(5,("find_all_domain_master_names_query_succes: sending node status request to \ +IP %s.\n", inet_ntoa(send_ip) )); + + node_status( subrec, &nmbname, send_ip, + get_domain_master_name_node_status_success, + get_domain_master_name_node_status_fail, + NULL); + } +} + +/**************************************************************************** + Function called when a query for *<1b> name fails. + ****************************************************************************/ +static void find_all_domain_master_names_query_fail(struct subnet_record *subrec, + struct response_record *rrec, + struct nmb_name *question_name, int fail_code) +{ + DEBUG(10,("find_domain_master_name_query_fail: WINS server did not reply to a query \ +for name %s. This means it is probably not a Samba 1.9.18 or above WINS server.\n", + namestr(question_name) )); +} + +/**************************************************************************** + If we are a domain master browser on the unicast subnet, do a query to the + WINS server for the *<1b> name. This will only work to a Samba WINS server, + so ignore it if we fail. If we succeed, contact each of the IP addresses in + turn and do a node status request to them. If this succeeds then look for a + <1b> name in the reply - this is the workgroup name. Add this to the unicast + subnet. This is expensive, so we only do this every 15 minutes. +**************************************************************************/ + +void collect_all_workgroup_names_from_wins_server(time_t t) +{ + static time_t lastrun = 0; + struct work_record *work; + struct nmb_name nmbname; + + /* Only do this if we are using a WINS server. */ + if(we_are_a_wins_client() == False) + return; + + /* Check to see if we are a domain master browser on the unicast subnet. */ + if((work = find_workgroup_on_subnet( unicast_subnet, myworkgroup)) == NULL) + { + DEBUG(0,("collect_all_workgroup_names_from_wins_server: Cannot find my workgroup %s on subnet %s.\n", + myworkgroup, unicast_subnet->subnet_name )); + return; + } + + if(!AM_DOMAIN_MASTER_BROWSER(work)) + return; + + if ((lastrun != 0) && (t < lastrun + (15 * 60))) + return; + + lastrun = t; + + make_nmb_name(&nmbname,"*",0x1b,scope); + + /* First, query for the *<1b> name from the WINS server. */ + query_name(unicast_subnet, nmbname.name, nmbname.name_type, + find_all_domain_master_names_query_success, + find_all_domain_master_names_query_fail, + NULL); +} diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 452516b64e..7133d5ebfb 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -737,7 +737,7 @@ void process_announce_request(struct subnet_record *subrec, struct packet_struct our workgroup and then set the flag telling that we have found a LanMan client (DOS or OS/2) and that we will have to start sending LanMan announcements (unless specifically disabled - through the "lm_announce" parameter in smb.conf) + through the "lm announce" parameter in smb.conf) ******************************************************************/ void process_lm_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf) -- cgit From 5cdb60bd93fcf97fa9ee1c42642237eb7d4c2083 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 24 Dec 1997 08:49:44 +0000 Subject: nmbd_elections.c: Added new parameter to dump_workgroups call. nmbd_incomingdgrams.c: Deal with announcements with servertype == 0 - these are announcements that a machine is shutting down and must be treated differently. nmbd_serverlistdb.c: Exposed remove_server_from_workgroup as external. Added code to dump out workgroups on signal correctly. nmbd_workgroupdb.c: Added new parameter to dump_workgroups call. Jeremy. (This used to be commit f7591109b968c66012af5e9fe818bba8e6f1cf23) --- source3/nmbd/nmbd_elections.c | 2 +- source3/nmbd/nmbd_incomingdgrams.c | 139 ++++++++++++++++++++++++++----------- source3/nmbd/nmbd_serverlistdb.c | 18 +++-- source3/nmbd/nmbd_workgroupdb.c | 13 ++-- 4 files changed, 116 insertions(+), 56 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 5c3c4c7a01..8081de8382 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -141,7 +141,7 @@ void check_master_browser_exists(time_t t) lastrun = t; - dump_workgroups(); + dump_workgroups(False); for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 7133d5ebfb..2396c847a3 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -153,28 +153,45 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p * announce instead ? JRA. */ - if ((work = find_workgroup_on_subnet(subrec, work_name))==NULL) + work = find_workgroup_on_subnet(subrec, work_name); + + if(servertype != 0) { - /* We have no record of this workgroup. Add it. */ - if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL) - return; - } + if (work ==NULL ) + { + /* We have no record of this workgroup. Add it. */ + if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL) + return; + } - if((servrec = find_server_in_workgroup( work, announce_name))==NULL) - { - /* If this server is not already in the workgroup, add it. */ - create_server_on_workgroup(work, announce_name, - servertype|SV_TYPE_LOCAL_LIST_ONLY, - ttl, comment); + if((servrec = find_server_in_workgroup( work, announce_name))==NULL) + { + /* If this server is not already in the workgroup, add it. */ + create_server_on_workgroup(work, announce_name, + servertype|SV_TYPE_LOCAL_LIST_ONLY, + ttl, comment); + } + else + { + /* Update the record. */ + servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; + update_server_ttl( servrec, ttl); + StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1); + } } else { - /* Update the record. */ - servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; - update_server_ttl( servrec, ttl); - StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1); + /* + * This server is announcing it is going down. Remove it from the + * workgroup. + */ + if(!is_myname(announce_name) && (work != NULL) && + ((servrec = find_server_in_workgroup( work, announce_name))!=NULL) + ) + { + remove_server_from_workgroup( work, servrec); + } } - subrec->work_changed = True; } @@ -272,6 +289,10 @@ void process_local_master_announce(struct subnet_record *subrec, struct packet_s if ((work = find_workgroup_on_subnet(subrec, work_name))==NULL) { + /* Don't bother adding if it's a local master release announce. */ + if(servertype == 0) + return; + /* We have no record of this workgroup. Add it. */ if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL) return; @@ -308,23 +329,39 @@ a local master browser for workgroup %s and we think we are master. Forcing elec /* Find the server record on this workgroup. If it doesn't exist, add it. */ - if((servrec = find_server_in_workgroup( work, server_name))==NULL) + if(servertype != 0) { - /* If this server is not already in the workgroup, add it. */ - create_server_on_workgroup(work, server_name, - servertype|SV_TYPE_LOCAL_LIST_ONLY, - ttl, comment); + if((servrec = find_server_in_workgroup( work, server_name))==NULL) + { + /* If this server is not already in the workgroup, add it. */ + create_server_on_workgroup(work, server_name, + servertype|SV_TYPE_LOCAL_LIST_ONLY, + ttl, comment); + } + else + { + /* Update the record. */ + servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; + update_server_ttl(servrec, ttl); + StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1); + } + + set_workgroup_local_master_browser_name( work, server_name ); } else { - /* Update the record. */ - servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; - update_server_ttl(servrec, ttl); - StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1); + /* + * This server is announcing it is going down. Remove it from the + * workgroup. + */ + if(!is_myname(server_name) && (work != NULL) && + ((servrec = find_server_in_workgroup( work, server_name))!=NULL) + ) + { + remove_server_from_workgroup( work, servrec); + } } - set_workgroup_local_master_browser_name( work, server_name ); - subrec->work_changed = True; } @@ -454,26 +491,44 @@ void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct * announce instead ? JRA. */ - if ((work = find_workgroup_on_subnet(subrec, work_name))==NULL) - { - /* We have no record of this workgroup. Add it. */ - if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL) - return; - } + work = find_workgroup_on_subnet(subrec, work_name); - if((servrec = find_server_in_workgroup( work, announce_name))==NULL) + if(servertype != 0) { - /* If this server is not already in the workgroup, add it. */ - create_server_on_workgroup(work, announce_name, - servertype|SV_TYPE_LOCAL_LIST_ONLY, - ttl, comment); + if (work == NULL) + { + /* We have no record of this workgroup. Add it. */ + if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL) + return; + } + + if((servrec = find_server_in_workgroup( work, announce_name))==NULL) + { + /* If this server is not already in the workgroup, add it. */ + create_server_on_workgroup(work, announce_name, + servertype|SV_TYPE_LOCAL_LIST_ONLY, + ttl, comment); + } + else + { + /* Update the record. */ + servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; + update_server_ttl( servrec, ttl); + StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1); + } } else { - /* Update the record. */ - servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; - update_server_ttl( servrec, ttl); - StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1); + /* + * This server is announcing it is going down. Remove it from the + * workgroup. + */ + if(!is_myname(announce_name) && (work != NULL) && + ((servrec = find_server_in_workgroup( work, announce_name))!=NULL) + ) + { + remove_server_from_workgroup( work, servrec); + } } subrec->work_changed = True; diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index b3dca36c84..6a6998f81d 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -111,7 +111,7 @@ struct server_record *find_server_in_workgroup(struct work_record *work, char *n Remove a server entry from this workgroup. ****************************************************************************/ -static void remove_server_from_workgroup(struct work_record *work, struct server_record *servrec) +void remove_server_from_workgroup(struct work_record *work, struct server_record *servrec) { if (servrec->prev) servrec->prev->next = servrec->next; @@ -311,11 +311,17 @@ void write_browse_list(time_t t, BOOL force_write) BOOL list_changed = force_write; static time_t lasttime = 0; - if (!lasttime) - lasttime = t; - if (t - lasttime < 5) - return; + /* Always dump if we're being told to by a signal. */ + if(force_write == False) + { + if (!lasttime) + lasttime = t; + if (t - lasttime < 5) + return; + } + dump_workgroups(force_write); + for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { if(subrec->work_changed) @@ -331,8 +337,6 @@ void write_browse_list(time_t t, BOOL force_write) lasttime = t; updatecount++; - dump_workgroups(); - pstrcpy(fname,lp_lockdir()); trim_string(fname,NULL,"/"); strcat(fname,"/"); diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 828e29a024..1b97b92721 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -293,22 +293,23 @@ on subnet %s\n", name, subrec->subnet_name)); Dump a copy of the workgroup database into the log file. **************************************************************************/ -void dump_workgroups(void) +void dump_workgroups(BOOL force_write) { struct subnet_record *subrec; - + int debuglevel = force_write ? 0 : 4; + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { if (subrec->workgrouplist) { struct work_record *work; - DEBUG(4,("dump_workgroups: dump workgroup on subnet %15s: ", subrec->subnet_name)); - DEBUG(4,(" netmask=%15s:\n", inet_ntoa(subrec->mask_ip))); + DEBUG(debuglevel,("dump_workgroups: dump workgroup on subnet %15s: ", subrec->subnet_name)); + DEBUG(debuglevel,(" netmask=%15s:\n", inet_ntoa(subrec->mask_ip))); for (work = subrec->workgrouplist; work; work = work->next) { - DEBUG(4,("\t%s(%d) current master browser = %s\n", work->work_group, + DEBUG(debuglevel,("\t%s(%d) current master browser = %s\n", work->work_group, work->token, *work->local_master_browser_name ? work->local_master_browser_name : "UNKNOWN" )); if (work->serverlist) @@ -316,7 +317,7 @@ void dump_workgroups(void) struct server_record *servrec; for (servrec = work->serverlist; servrec; servrec = servrec->next) { - DEBUG(4,("\t\t%s %8x (%s)\n", + DEBUG(debuglevel,("\t\t%s %8x (%s)\n", servrec->serv.name, servrec->serv.type, servrec->serv.comment)); } } -- cgit From aef2c5d69956c72f8b0bd2285283e8879ed8603d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 24 Dec 1997 09:30:56 +0000 Subject: Added SIGUSR1/SIGUSR2 handling. Sending nmbd/smbd a SIGUSR1 will raise the debug level by one (capped at 10) sending a SIGUSR2 will lower it (lower limit at zero). Jeremy. (This used to be commit 6a3cb6f4b46129e4d799a24d34cdb9460ed8910f) --- source3/nmbd/nmbd.c | 21 +++++++++++++++++++-- source3/nmbd/nmbd_packets.c | 19 ++++++++++++++++++- 2 files changed, 37 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index da98fbfde3..744942ba46 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -75,11 +75,11 @@ static int sig_term() announce_my_servers_removed(); exit(0); + /* Keep compiler happy.. */ return 0; } /* sig_term */ - /**************************************************************************** ** catch a sighup **************************************************************************** */ @@ -577,6 +577,17 @@ int main(int argc,char *argv[]) signal( SIGHUP, SIGNAL_CAST sig_hup ); signal( SIGTERM, SIGNAL_CAST sig_term ); + /* Setup the signals that allow the debug log level + to by dynamically changed. */ + +#if defined(SIGUSR1) + signal( SIGUSR1, SIGNAL_CAST sig_usr1 ); +#endif /* SIGUSR1 */ + +#if defined(SIGUSR2) + signal( SIGUSR2, SIGNAL_CAST sig_usr2 ); +#endif /* SIGUSR2 */ + while((opt = getopt(argc, argv, "as:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:f:")) != EOF) { switch (opt) @@ -755,8 +766,14 @@ int main(int argc,char *argv[]) exit(1); } - /* We can only take sigterm signals in the select. */ + /* We can only take signals in the select. */ BlockSignals( True, SIGTERM ); +#if defined(SIGUSR1) + BlockSignals( True, SIGUSR1); +#endif /* SIGUSR1 */ +#if defined(SIGUSR2) + BlockSignals( True, SIGUSR2); +#endif /* SIGUSR2 */ process(); close_sockets(); diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 4fb0543967..03bd3889fa 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1650,10 +1650,27 @@ BOOL listen_for_packets(BOOL run_election) timeout.tv_sec = (run_election||num_response_packets) ? 1 : NMBD_SELECT_LOOP; timeout.tv_usec = 0; - /* We can only take term signals when we are in the select. */ + /* Prepare for the select - allow certain signals. */ + BlockSignals(False, SIGTERM); +#if defined(SIGUSR1) + BlockSignals(False, SIGUSR1); +#endif /* SIGUSR1 */ +#if defined(SIGUSR2) + BlockSignals(False, SIGUSR2); +#endif /* SIGUSR2 */ + selrtn = sys_select(&fds,&timeout); + + /* We can only take signals when we are in the select - block them again here. */ + BlockSignals(True, SIGTERM); +#if defined(SIGUSR1) + BlockSignals(True, SIGUSR1); +#endif /* SIGUSR1 */ +#if defined(SIGUSR2) + BlockSignals(True, SIGUSR2); +#endif /* SIGUSR2 */ if(selrtn > 0) { -- cgit From 7f49012b1d9f7f0bd00488fd2d2d3853f8403b60 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Wed, 24 Dec 1997 15:42:14 +0000 Subject: This is actually Jeremy, working as Herb :-). Fixed bug where, when server is shut down it would always do a lm announce broadcast of shutdown. This could cause other nmbd's to think that they have seen an lm announce broadcast and start doing it themselves. Changed to only send lm announce shutdown if admin configured it or one was seen on the subnet. Jeremy. (This used to be commit 64c8111574ff9fa00d5b43b146ae4d6f6bdf0565) --- source3/nmbd/nmbd_sendannounce.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index aac3dad366..e859ff6bb7 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -430,7 +430,10 @@ This must *only* be called on shutdown. void announce_my_servers_removed(void) { + int announce_interval = lp_lm_interval(); + int lm_announce = lp_lm_announce(); struct subnet_record *subrec; + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { struct work_record *work; @@ -447,6 +450,25 @@ void announce_my_servers_removed(void) if(AM_LOCAL_MASTER_BROWSER(work)) send_local_master_announcement(subrec, work, servrec); send_host_announcement(subrec, work, servrec); + + + if ((announce_interval <= 0) || (lm_announce <= 0)) + { + /* user absolutely does not want LM announcements to be sent. */ + continue; + } + + if ((lm_announce >= 2) && (!found_lm_clients)) + { + /* has been set to 2 (Auto) but no LM clients detected (yet). */ + continue; + } + + /* + * lm announce was set or we have seen lm announcements, so do + * a lm announcement of host removed. + */ + send_lm_host_announcement(subrec, work, servrec, 0); } } -- cgit From 65a21bcbddd768a5aa41fc684150d9c5ceb9d5d9 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 26 Dec 1997 09:57:40 +0000 Subject: use _exit to exit a child (This used to be commit 992b1cbc143be910d9b8e65afdc82c43d33650a5) --- source3/nmbd/asyncdns.c | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 1ee9dab065..e0d262f72c 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -111,11 +111,7 @@ static void asyncdns_process(void) static int sig_term() { - BlockSignals(True,SIGTERM); - - DEBUG(0,("async dns child. Got SIGTERM: going down...\n")); - - exit(0); + _exit(0); /* Keep compiler happy.. */ return 0; } @@ -149,7 +145,7 @@ void start_async_dns(void) signal(SIGUSR2, SIG_IGN); signal(SIGUSR1, SIG_IGN); signal(SIGHUP, SIG_IGN); - signal( SIGTERM, SIGNAL_CAST sig_term ); + signal(SIGTERM, SIGNAL_CAST sig_term ); asyncdns_process(); } -- cgit From ed2ed5671bf868234d540cf9e0b887a19d25cc10 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 26 Dec 1997 10:01:57 +0000 Subject: fixed a couple of illegal uses of scanf() in the nmbd wins code. They caused a core dump under IRIX when compiled with -64. In general you cannot assume things about variable sizes. In particular sizeof(time_t) may not equal sizeof(long) and sizeof(uint16) may not equal sizeof(short). There are probably other bugs like this. We'll need to check all format statements for use of %ld, %hx etc. In general these should not be used unless you have an explicit cast to the appropriate type. (This used to be commit 6ea907e78672558d470e9a819982940a9228e2fa) --- source3/nmbd/nmbd_winsserver.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index bd8febd65d..7bb3081e10 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -150,8 +150,8 @@ BOOL initialise_wins(void) pstring name; struct in_addr *ip_list; int type = 0; - uint16 nb_flags; - time_t ttl; + int nb_flags; + int ttl; enum name_source source; char *ptr; char *p; @@ -262,8 +262,8 @@ BOOL initialise_wins(void) } /* Decode the netbios flags (hex) and the time-to-live (in seconds). */ - sscanf(nb_flags_str,"%hx",&nb_flags); - sscanf(ttl_str,"%ld",&ttl); + sscanf(nb_flags_str,"%x",&nb_flags); + sscanf(ttl_str,"%d",&ttl); /* add all entries that have 60 seconds or more to live */ if ((ttl - 60) > time_now || ttl == PERMANENT_TTL) @@ -273,7 +273,7 @@ BOOL initialise_wins(void) if(ttl != PERMANENT_TTL) ttl -= time_now; - DEBUG(4, ("initialise_wins: add name: %s#%02x ttl = %ld first IP %s flags = %2hx\n", + DEBUG(4, ("initialise_wins: add name: %s#%02x ttl = %d first IP %s flags = %2x\n", name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); namerec = add_name_to_subnet(wins_server_subnet, name, type, nb_flags, @@ -282,7 +282,7 @@ BOOL initialise_wins(void) } else { - DEBUG(4, ("initialise_wins: not adding name (ttl problem) %s#%02x ttl = %ld first IP %s flags = %2hx\n", + DEBUG(4, ("initialise_wins: not adding name (ttl problem) %s#%02x ttl = %ld first IP %s flags = %2x\n", name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); } -- cgit From b26a147f04d5454c70ef76df126101d19b35ee8a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 26 Dec 1997 10:07:05 +0000 Subject: fixed another couple of minor type errors (they could cause incorrect output but not a core dump) (This used to be commit 4dc66214a0cdf16e48cca961914fae37b3762330) --- source3/nmbd/nmbd_winsserver.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 7bb3081e10..725e6e3747 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -282,7 +282,7 @@ BOOL initialise_wins(void) } else { - DEBUG(4, ("initialise_wins: not adding name (ttl problem) %s#%02x ttl = %ld first IP %s flags = %2x\n", + DEBUG(4, ("initialise_wins: not adding name (ttl problem) %s#%02x ttl = %d first IP %s flags = %2x\n", name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); } @@ -1549,9 +1549,9 @@ void wins_write_database(void) if (namerec->source == REGISTER_NAME) { - fprintf(fp, "%s#%02x %ld ", - namerec->name.name,namerec->name.name_type, /* Ignore scope. */ - namerec->death_time); + fprintf(fp, "%s#%02x %d ", + namerec->name.name,namerec->name.name_type, /* Ignore scope. */ + (int)namerec->death_time); for (i = 0; i < namerec->num_ips; i++) fprintf(fp, "%s ", inet_ntoa(namerec->ip[i])); -- cgit From d018d7b42a7ae68a5a76c3874d285e9399fdce81 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Sat, 3 Jan 1998 03:35:13 +0000 Subject: added timestrings to become and unbecome domain/local master browser messages. (This used to be commit 5e7e3d18b51e1eb949bc793d3106a17d8e65a1af) --- source3/nmbd/nmbd_become_dmb.c | 13 +++++++------ source3/nmbd/nmbd_become_lmb.c | 12 ++++++------ 2 files changed, 13 insertions(+), 12 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index 37fceb9bf1..d8788b7314 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -81,8 +81,8 @@ in workgroup %s on subnet %s\n", bzero((char *)&work->dmb_name, sizeof(work->dmb_name)); putip((char *)&work->dmb_addr, &ipzero); - DEBUG(0,("\n ***** Samba server %s has stopped being a domain master browser \ -for workgroup %s on subnet %s *****\n\n", myname, work->work_group, subrec->subnet_name)); + DEBUG(0,("\n%s ***** Samba server %s has stopped being a domain master browser \ +for workgroup %s on subnet %s *****\n\n", timestring(), myname, work->work_group, subrec->subnet_name)); } @@ -214,8 +214,9 @@ in workgroup %s on subnet %s\n", /* Tell the namelist writer to write out a change. */ subrec->work_changed = True; - DEBUG(0,("\n ***** Samba server %s is now a domain master browser \ -for workgroup %s on subnet %s *****\n\n", myname, work->work_group, subrec->subnet_name)); + DEBUG(0,("\n%s ***** Samba server %s is now a domain master browser for \ +workgroup %s on subnet %s *****\n\n", timestring(),myname, work->work_group, +subrec->subnet_name)); if(subrec == unicast_subnet) { @@ -312,9 +313,9 @@ Continuing with domain master code.\n", } else { - DEBUG(0,("become_domain_master_query_success: There is already a domain \ + DEBUG(0,("%s become_domain_master_query_success: There is already a domain \ master browser at IP %s for workgroup %s registered on subnet %s.\n", - inet_ntoa(ip), nmbname->name, subrec->subnet_name)); + timestring(), inet_ntoa(ip), nmbname->name, subrec->subnet_name)); } } diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index 6dcd61d76c..2d9f2cce55 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -145,8 +145,8 @@ void unbecome_local_master_success(struct subnet_record *subrec, /* Now reset the workgroup and server state. */ reset_workgroup_state( subrec, released_name->name ); - DEBUG(0,("\n***** Samba name server %s has stopped being a local master browser for workgroup %s \ -on subnet %s *****\n\n", myname, released_name->name, subrec->subnet_name)); + DEBUG(0,("\n%s ***** Samba name server %s has stopped being a local master browser for workgroup %s \ +on subnet %s *****\n\n", timestring(), myname, released_name->name, subrec->subnet_name)); } @@ -170,8 +170,8 @@ Removing from namelist anyway.\n", namestr(fail_name))); /* Now reset the workgroup and server state. */ reset_workgroup_state( subrec, fail_name->name ); - DEBUG(0,("\n***** Samba name server %s has stopped being a local master browser for workgroup %s \ -on subnet %s *****\n\n", myname, fail_name->name, subrec->subnet_name)); + DEBUG(0,("\n%s ***** Samba name server %s has stopped being a local master browser for workgroup %s \ +on subnet %s *****\n\n", timestring(), myname, fail_name->name, subrec->subnet_name)); } @@ -365,8 +365,8 @@ on subnet %s\n", work->work_group, subrec->subnet_name)); master browser as soon as possible that we are a local master browser. */ reset_announce_timer(); - DEBUG(0,("\n***** Samba name server %s is now a local master browser for workgroup %s \ -on subnet %s *****\n\n", myname, work->work_group, subrec->subnet_name)); + DEBUG(0,("\n%s ***** Samba name server %s is now a local master browser for workgroup %s \ +on subnet %s *****\n\n", timestring(), myname, work->work_group, subrec->subnet_name)); } -- cgit From c23ed625b22bfc765ba95cb7b8addf55625fea44 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 7 Jan 1998 06:21:56 +0000 Subject: includes.h: Added FreeBSD 3.x fixes. Added HPUX10.x fixes. interface.c: Added netmask fix. nmbd_nameregister.c: Fixed unitialised variable warnings. nmbd_winsproxy.c: Fixed unitialised variable warnings. nmbd_winsserver.c: Fixed DEC warnings. print_svid.c: Fixed DEC warnings. printing.c: Added LPRng fixes. Jeremy. (This used to be commit 28aff043c4a3693a0c20e87c7ce11eb4bf285b78) --- source3/nmbd/nmbd_nameregister.c | 8 ++++---- source3/nmbd/nmbd_winsproxy.c | 2 +- source3/nmbd/nmbd_winsserver.c | 7 +++---- 3 files changed, 8 insertions(+), 9 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index cdaef1a767..3223159ace 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -47,8 +47,8 @@ static void register_name_response(struct subnet_record *subrec, BOOL success = True; struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name; struct nmb_name *answer_name = &nmb->answers->rr_name; - int ttl; - uint16 nb_flags; + int ttl = 0; + uint16 nb_flags = 0; struct in_addr registered_ip; /* Sanity check. Ensure that the answer name in the incoming packet is the @@ -169,8 +169,8 @@ static void register_name_timeout_response(struct subnet_record *subrec, BOOL bcast = sent_nmb->header.nm_flags.bcast; BOOL success = False; struct nmb_name *question_name = &sent_nmb->question.question_name; - uint16 nb_flags; - int ttl; + uint16 nb_flags = 0; + int ttl = 0; struct in_addr registered_ip; if(bcast) diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index 4f2326795d..36b9e7843c 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -39,7 +39,7 @@ static void wins_proxy_name_query_request_success( struct subnet_record *subrec, uint16 nb_flags; int num_ips; int i; - int ttl; + int ttl = 3600; /* By default one hour in the cache. */ struct in_addr *iplist; /* Extract the original packet and the original broadcast subnet from diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 725e6e3747..4a631a79b7 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -784,7 +784,7 @@ is one of our (WINS server) names. Denying registration.\n", namestr(question) ) if(namerec != NULL) { char ud[sizeof(struct userdata_struct) + sizeof(struct packet_struct *)]; - struct userdata_struct *userdata = (struct userdata_struct *)&ud; + struct userdata_struct *userdata = (struct userdata_struct *)ud; /* * First send a WACK to the registering machine. @@ -1059,7 +1059,7 @@ is one of our (WINS server) names. Denying registration.\n", namestr(question) ) if(namerec != NULL) { char ud[sizeof(struct userdata_struct) + sizeof(struct packet_struct *)]; - struct userdata_struct *userdata = (struct userdata_struct *)&ud; + struct userdata_struct *userdata = (struct userdata_struct *)ud; /* * First send a WACK to the registering machine. @@ -1202,7 +1202,7 @@ void send_wins_name_query_response(int rcode, struct packet_struct *p, if(rcode == 0) { - int same_net_index; + int same_net_index = -1; ttl = (namerec->death_time != PERMANENT_TTL) ? namerec->death_time - p->timestamp : lp_max_wins_ttl(); @@ -1229,7 +1229,6 @@ void send_wins_name_query_response(int rcode, struct packet_struct *p, * ones we know the netmask for. */ - same_net_index = -1; i = 0; if(is_local_net(p->ip)) -- cgit From 0d1933fefc3685cc2d5e48e05a323f5ef81be555 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 9 Jan 1998 05:33:27 +0000 Subject: docs/Support.txt: Removed consultant. source/Makefile: Added Volker's comment. source/nmbd_become_lmb.c: source/nmbd_browsesync.c: source/nmbd_incomingdgrams.c: Fixed userdata alignment problems. source/mem_man/mem_man.c: source/mem_man/mem_man.h: added smb_ prefix to stop namespace collisions. Jeremy. (This used to be commit 4c8af3bc9f43b2427609cbeecb7940b1753a9a1c) --- source3/nmbd/nmbd_become_lmb.c | 23 +++++++++++++++-------- source3/nmbd/nmbd_browsesync.c | 9 +++++++-- source3/nmbd/nmbd_incomingdgrams.c | 4 ++-- 3 files changed, 24 insertions(+), 12 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index 2d9f2cce55..7bfd558003 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -248,7 +248,6 @@ void unbecome_local_master_browser(struct subnet_record *subrec, struct work_rec struct name_record *namerec; struct nmb_name nmbname; struct userdata_struct *userdata; - char ud[sizeof(struct userdata_struct) + sizeof(fstring)+1]; /* Sanity check. */ @@ -268,9 +267,11 @@ in workgroup %s on subnet %s\n", work->mst_state = MST_UNBECOMING_MASTER; /* Setup the userdata for the MSBROWSE name release. */ - /* Setup the userdata_struct - this is copied so we can use - a stack variable for this. */ - userdata = (struct userdata_struct *)ud; + if((userdata = (struct userdata_struct *)malloc( sizeof(struct userdata_struct) + sizeof(fstring)+1)) == NULL) + { + DEBUG(0,("unbecome_local_master_browser: malloc fail.\n")); + return; + } userdata->copy_fn = NULL; userdata->free_fn = NULL; @@ -286,6 +287,8 @@ in workgroup %s on subnet %s\n", release_msbrowse_name_fail, userdata); } + + free((char *)userdata); } /**************************************************************************** @@ -481,7 +484,6 @@ void become_local_master_browser(struct subnet_record *subrec, struct work_recor { struct server_record *servrec; struct userdata_struct *userdata; - char ud[sizeof(struct userdata_struct) + sizeof(fstring)+1]; /* Sanity check. */ if (!lp_local_master()) @@ -516,9 +518,12 @@ in workgroup %s on subnet %s\n", /* Tell the namelist writer to write out a change. */ subrec->work_changed = True; - /* Setup the userdata_struct - this is copied so we can use - a stack variable for this. */ - userdata = (struct userdata_struct *)ud; + /* Setup the userdata_struct. */ + if((userdata = (struct userdata_struct *)malloc(sizeof(struct userdata_struct) + sizeof(fstring)+1)) == NULL) + { + DEBUG(0,("become_local_master_browser: malloc fail.\n")); + return; + } userdata->copy_fn = NULL; userdata->free_fn = NULL; @@ -530,6 +535,8 @@ in workgroup %s on subnet %s\n", become_local_master_stage1, become_local_master_fail1, userdata); + + free((char *)userdata); } /*************************************************************** diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index cc81807de4..e4231e6017 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -379,7 +379,6 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec, struct work_record *work; struct nmb_name nmbname; struct userdata_struct *userdata; - char ud[sizeof(struct userdata_struct) + sizeof(fstring)+1]; if (!(work = find_workgroup_on_subnet(subrec, q_name->name))) { DEBUG(0, ("find_domain_master_name_query_success: failed to find \ @@ -412,7 +411,11 @@ workgroup %s\n", q_name->name )); /* Setup the userdata_struct - this is copied so we can use a stack variable for this. */ - userdata = (struct userdata_struct *)ud; + if((userdata = (struct userdata_struct *)malloc(sizeof(struct userdata_struct) + sizeof(fstring)+1)) == NULL) + { + DEBUG(0, ("find_domain_master_name_query_success: malloc fail.\n")); + return; + } userdata->copy_fn = NULL; userdata->free_fn = NULL; @@ -423,6 +426,8 @@ workgroup %s\n", q_name->name )); domain_master_node_status_success, domain_master_node_status_fail, userdata); + + free((char *)userdata); } /**************************************************************************** diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 2396c847a3..b1de27f181 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -547,7 +547,7 @@ static void send_backup_list_response(struct subnet_record *subrec, { char outbuf[1024]; char *p, *countptr, *nameptr; - int count = 0; + unsigned int count = 0; int len; struct server_record *servrec; @@ -582,7 +582,7 @@ static void send_backup_list_response(struct subnet_record *subrec, if((sizeof(outbuf) - len) < 16) break; - if(count >= max_number_requested) + if(count >= (unsigned int)max_number_requested) break; if(strnequal(servrec->serv.name, myname,15)) -- cgit From c247cc7187380564228c12187f6e37e666762d08 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 20 Jan 1998 04:58:41 +0000 Subject: Fixed bug found by Bernhard Laeser where we are announcing to the wrong DMB name. Jeremy. (This used to be commit 6b3d4620c128fe1f77f579a451eac7f41a83064f) --- source3/nmbd/nmbd_browsesync.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index e4231e6017..3ee85a4758 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -252,7 +252,7 @@ Do not announce to ourselves.\n", work->work_group )); to %s for workgroup %s.\n", namestr(&work->dmb_name), work->work_group )); send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), - myname, 0x0, work->dmb_name.name, 0x20, work->dmb_addr, FIRST_SUBNET->myip); + myname, 0x0, work->dmb_name.name, 0x0, work->dmb_addr, FIRST_SUBNET->myip); } -- cgit From 2d1ff641f09e06c8ddf62814b12a3f2fa3851244 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 21 Jan 1998 12:15:07 +0000 Subject: Fixed send_mailslot code where src_type was always being set to zero. Fix found by Bernhard Laeser . Jeremy. (This used to be commit 303b5a79c83246e1895f9478e187610addfd2862) --- source3/nmbd/nmbd_packets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 03bd3889fa..a40b4d426d 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1794,7 +1794,7 @@ BOOL send_mailslot(BOOL unique, char *mailslot,char *buf,int len, dgram->header.dgm_length = 0; /* Let build_dgram() handle this. */ dgram->header.packet_offset = 0; - make_nmb_name(&dgram->source_name,srcname,0,scope); + make_nmb_name(&dgram->source_name,srcname,src_type,scope); make_nmb_name(&dgram->dest_name,dstname,dest_type,scope); ptr = &dgram->data[0]; -- cgit From 55f400bd84f26027f5ec9b7fa06b22895de7557c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 22 Jan 1998 13:27:43 +0000 Subject: This is *not* a big change (although it looks like one). This is merely updating the Copyright statements from 1997 to 1998. It's a once a year thing :-). NO OTHER CHANGES WERE MADE. Jeremy. (This used to be commit b9c16977231efb274e08856f7f3f4408dad6d96c) --- source3/nmbd/asyncdns.c | 2 +- source3/nmbd/nmbd.c | 2 +- source3/nmbd/nmbd_become_dmb.c | 6 +++--- source3/nmbd/nmbd_become_lmb.c | 6 +++--- source3/nmbd/nmbd_browserdb.c | 6 +++--- source3/nmbd/nmbd_browsesync.c | 6 +++--- source3/nmbd/nmbd_elections.c | 6 +++--- source3/nmbd/nmbd_incomingdgrams.c | 6 +++--- source3/nmbd/nmbd_incomingrequests.c | 6 +++--- source3/nmbd/nmbd_lmhosts.c | 2 +- source3/nmbd/nmbd_logonnames.c | 6 +++--- source3/nmbd/nmbd_mynames.c | 6 +++--- source3/nmbd/nmbd_namelistdb.c | 6 +++--- source3/nmbd/nmbd_namequery.c | 6 +++--- source3/nmbd/nmbd_nameregister.c | 6 +++--- source3/nmbd/nmbd_namerelease.c | 6 +++--- source3/nmbd/nmbd_nodestatus.c | 6 +++--- source3/nmbd/nmbd_packets.c | 6 +++--- source3/nmbd/nmbd_processlogon.c | 6 +++--- source3/nmbd/nmbd_responserecordsdb.c | 6 +++--- source3/nmbd/nmbd_sendannounce.c | 8 ++++---- source3/nmbd/nmbd_serverlistdb.c | 6 +++--- source3/nmbd/nmbd_subnetdb.c | 6 +++--- source3/nmbd/nmbd_winsproxy.c | 2 +- source3/nmbd/nmbd_winsserver.c | 2 +- source3/nmbd/nmbd_workgroupdb.c | 6 +++--- 26 files changed, 69 insertions(+), 69 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index e0d262f72c..ee3fdfcd17 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -1,7 +1,7 @@ /* Unix SMB/Netbios implementation. a async DNS handler - Copyright (C) Andrew Tridgell 1997 + Copyright (C) Andrew Tridgell 1997-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 744942ba46..4497e0b15d 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -2,7 +2,7 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Andrew Tridgell 1994-1997 + Copyright (C) Andrew Tridgell 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index d8788b7314..52065758bc 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -2,9 +2,9 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Andrew Tridgell 1994-1997 - Copyright (C) Luke Kenneth Casson Leighton 1994-1997 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Luke Kenneth Casson Leighton 1994-1998 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index 7bfd558003..2420b2ec4b 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -2,9 +2,9 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Andrew Tridgell 1994-1997 - Copyright (C) Luke Kenneth Casson Leighton 1994-1997 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Luke Kenneth Casson Leighton 1994-1998 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c index b2db744370..ee3e4e4bde 100644 --- a/source3/nmbd/nmbd_browserdb.c +++ b/source3/nmbd/nmbd_browserdb.c @@ -2,9 +2,9 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Andrew Tridgell 1994-1997 - Copyright (C) Luke Kenneth Casson Leighton 1994-1997 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Luke Kenneth Casson Leighton 1994-1998 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 3ee85a4758..94bdecb8fc 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -2,9 +2,9 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Andrew Tridgell 1994-1997 - Copyright (C) Luke Kenneth Casson Leighton 1994-1997 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Luke Kenneth Casson Leighton 1994-1998 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 8081de8382..fa1e5986a8 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -2,9 +2,9 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Andrew Tridgell 1994-1997 - Copyright (C) Luke Kenneth Casson Leighton 1994-1997 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Luke Kenneth Casson Leighton 1994-1998 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index b1de27f181..46d988e89a 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -2,9 +2,9 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Andrew Tridgell 1994-1997 - Copyright (C) Luke Kenneth Casson Leighton 1994-1997 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Luke Kenneth Casson Leighton 1994-1998 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index 73abdf0050..57517c3734 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -2,9 +2,9 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Andrew Tridgell 1994-1997 - Copyright (C) Luke Kenneth Casson Leighton 1994-1997 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Luke Kenneth Casson Leighton 1994-1998 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_lmhosts.c b/source3/nmbd/nmbd_lmhosts.c index 2dd1db81cd..722c3681f5 100644 --- a/source3/nmbd/nmbd_lmhosts.c +++ b/source3/nmbd/nmbd_lmhosts.c @@ -2,7 +2,7 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_logonnames.c b/source3/nmbd/nmbd_logonnames.c index b2431ec0a7..4128213f97 100644 --- a/source3/nmbd/nmbd_logonnames.c +++ b/source3/nmbd/nmbd_logonnames.c @@ -2,9 +2,9 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Andrew Tridgell 1994-1997 - Copyright (C) Luke Kenneth Casson Leighton 1994-1997 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Luke Kenneth Casson Leighton 1994-1998 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index 660b545069..035d1e6d3f 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -2,9 +2,9 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Andrew Tridgell 1994-1997 - Copyright (C) Luke Kenneth Casson Leighton 1994-1997 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Luke Kenneth Casson Leighton 1994-1998 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index dfd8a80baa..2237fc504d 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -2,9 +2,9 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Andrew Tridgell 1994-1997 - Copyright (C) Luke Kenneth Casson Leighton 1994-1997 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Luke Kenneth Casson Leighton 1994-1998 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index 5d98935fec..bbd831cac8 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -2,9 +2,9 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Andrew Tridgell 1994-1997 - Copyright (C) Luke Kenneth Casson Leighton 1994-1997 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Luke Kenneth Casson Leighton 1994-1998 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index 3223159ace..a3e4208cdc 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -2,9 +2,9 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Andrew Tridgell 1994-1997 - Copyright (C) Luke Kenneth Casson Leighton 1994-1997 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Luke Kenneth Casson Leighton 1994-1998 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_namerelease.c b/source3/nmbd/nmbd_namerelease.c index 8632dd7655..b2f9b47878 100644 --- a/source3/nmbd/nmbd_namerelease.c +++ b/source3/nmbd/nmbd_namerelease.c @@ -2,9 +2,9 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Andrew Tridgell 1994-1997 - Copyright (C) Luke Kenneth Casson Leighton 1994-1997 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Luke Kenneth Casson Leighton 1994-1998 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_nodestatus.c b/source3/nmbd/nmbd_nodestatus.c index 267446c69d..196c0f0ba7 100644 --- a/source3/nmbd/nmbd_nodestatus.c +++ b/source3/nmbd/nmbd_nodestatus.c @@ -2,9 +2,9 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Andrew Tridgell 1994-1997 - Copyright (C) Luke Kenneth Casson Leighton 1994-1997 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Luke Kenneth Casson Leighton 1994-1998 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index a40b4d426d..9dad5ddaa9 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -2,9 +2,9 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Andrew Tridgell 1994-1997 - Copyright (C) Luke Kenneth Casson Leighton 1994-1997 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Luke Kenneth Casson Leighton 1994-1998 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index cd2fbfd0a5..64f66038e0 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -2,9 +2,9 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Andrew Tridgell 1994-1997 - Copyright (C) Luke Kenneth Casson Leighton 1994-1997 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Luke Kenneth Casson Leighton 1994-1998 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index 031853271b..a075284a4a 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -2,9 +2,9 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios library routines - Copyright (C) Andrew Tridgell 1994-1997 - Copyright (C) Luke Kenneth Casson Leighton 1994-1997 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Luke Kenneth Casson Leighton 1994-1998 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index e859ff6bb7..62e5f02d8c 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -2,12 +2,12 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Andrew Tridgell 1994-1997 - Copyright (C) Luke Kenneth Casson Leighton 1994-1997 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Luke Kenneth Casson Leighton 1994-1998 + Copyright (C) Jeremy Allison 1994-1998 SMB Version handling - Copyright (C) John H Terpstra 1995-1997 + Copyright (C) John H Terpstra 1995-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index 6a6998f81d..e94cb1da6e 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -2,9 +2,9 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Andrew Tridgell 1994-1997 - Copyright (C) Luke Kenneth Casson Leighton 1994-1997 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Luke Kenneth Casson Leighton 1994-1998 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 93aecc21f2..5e18fe9cc0 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -2,9 +2,9 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Andrew Tridgell 1994-1997 - Copyright (C) Luke Kenneth Casson Leighton 1994-1997 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Luke Kenneth Casson Leighton 1994-1998 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index 36b9e7843c..ded37ebf30 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -3,7 +3,7 @@ Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 4a631a79b7..eb120e0918 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -3,7 +3,7 @@ Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 1b97b92721..b834525747 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -2,9 +2,9 @@ Unix SMB/Netbios implementation. Version 1.9. NBT netbios routines and daemon - version 2 - Copyright (C) Andrew Tridgell 1994-1997 - Copyright (C) Luke Kenneth Casson Leighton 1994-1997 - Copyright (C) Jeremy Allison 1994-1997 + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Luke Kenneth Casson Leighton 1994-1998 + Copyright (C) Jeremy Allison 1994-1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -- cgit From 66c668a6d308662dd02ea359551fb6d3867d12ca Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 23 Jan 1998 05:22:19 +0000 Subject: nmbd.c, server.c: Added #ifndef MEM_MAN around code that sets the SIGUSR1 and SIGUSR2 signals. This allows the MEM_MAN code to be compiled in and the memory debug feature to be used with SIGUSR1. Jeremy. (This used to be commit 43ef7e3cb5bb971ff6ddf8230b08995e55b7c6e1) --- source3/nmbd/nmbd.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 4497e0b15d..b6e4244cd0 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -580,6 +580,9 @@ int main(int argc,char *argv[]) /* Setup the signals that allow the debug log level to by dynamically changed. */ + /* If we are using the malloc debug code we can't use + SIGUSR1 and SIGUSR2 to do debug level changes. */ +#ifndef MEM_MAN #if defined(SIGUSR1) signal( SIGUSR1, SIGNAL_CAST sig_usr1 ); #endif /* SIGUSR1 */ @@ -587,6 +590,7 @@ int main(int argc,char *argv[]) #if defined(SIGUSR2) signal( SIGUSR2, SIGNAL_CAST sig_usr2 ); #endif /* SIGUSR2 */ +#endif /* MEM_MAN */ while((opt = getopt(argc, argv, "as:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:f:")) != EOF) { -- cgit From 89652787c3894c7a79345a2ea67a4de741a0f760 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 29 Jan 1998 08:25:46 +0000 Subject: Makefile: Fix for OSF1 typo. asyncdns.c: Fixes that went into 1.9.18p2 - allow unclocking of sigterm. chgpasswd.c: char -> unsigned char fixes. includes.h: AIX fix to get prototype for inet_ntoa. local.h: Tune size of shared memory based on MAX_OPEN_FILES. nmbd_mynames.c: Fix for nmbd repeated refresh bug. nmbd_responserecordsdb.c: Fix for nmbd repeated refresh bug. nmbd_winsserver.c: Fix for multi-homed registration optimisation. smb.h: Moved default shared memory size to local.h Jeremy. (This used to be commit fa5466805685d461564054d7d9947948fc56ae93) --- source3/nmbd/asyncdns.c | 12 ++++++++++++ source3/nmbd/nmbd_mynames.c | 3 ++- source3/nmbd/nmbd_responserecordsdb.c | 25 +++++++++++++++++++++++++ source3/nmbd/nmbd_winsserver.c | 14 +++++++++++++- 4 files changed, 52 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index ee3fdfcd17..3b71369d67 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -187,6 +187,9 @@ void run_dns_queue(void) if (fd_in == -1) return; + /* Allow SIGTERM to kill us. */ + BlockSignals(False, SIGTERM); + if (!process_exists(child_pid)) { close(fd_in); start_async_dns(); @@ -197,9 +200,12 @@ void run_dns_queue(void) DEBUG(0,("Incomplete DNS answer from child!\n")); fd_in = -1; } + BlockSignals(True, SIGTERM); return; } + BlockSignals(True, SIGTERM); + namerec = add_dns_result(&r.name, r.result); if (dns_current) { @@ -305,8 +311,14 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, DEBUG(3,("DNS search for %s - ", namestr(question))); + /* Unblock TERM signal so we can be killed in DNS lookup. */ + BlockSignals(False, SIGTERM); + dns_ip.s_addr = interpret_addr(qname); + /* Re-block TERM signal. */ + BlockSignals(True, SIGTERM); + *n = add_dns_result(question, dns_ip); if(*n == NULL) send_wins_name_query_response(NAM_ERR, p, NULL); diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index 035d1e6d3f..9441449bed 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -156,7 +156,8 @@ void refresh_my_names(time_t t) multiple refresh calls being done. We actually deal with refresh failure in the fail_fn. */ - refresh_name(subrec, namerec, NULL, NULL, NULL); + if(!is_refresh_already_queued( subrec, namerec)) + refresh_name(subrec, namerec, NULL, NULL, NULL); namerec->death_time += lp_max_ttl(); namerec->refresh_time += lp_max_ttl(); } diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index a075284a4a..ceace36a61 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -236,3 +236,28 @@ matching record.\n", id)); return NULL; } + +/**************************************************************************** + Check if a refresh is queued for a particular name on a particular subnet. + **************************************************************************/ + +BOOL is_refresh_already_queued(struct subnet_record *subrec, struct name_record *namerec) +{ + struct response_record *rrec = NULL; + + for (rrec = subrec->responselist; rrec; rrec = rrec->next) + { + struct packet_struct *p = rrec->packet; + struct nmb_packet *nmb = &p->packet.nmb; + + if((nmb->header.opcode == NMB_NAME_REFRESH_OPCODE_8) || + (nmb->header.opcode == NMB_NAME_REFRESH_OPCODE_9)) + { + /* Yes it's a queued refresh - check if the name is correct. */ + if(nmb_name_equal(&nmb->question.question_name, &namerec->name)) + return True; + } + } + + return False; +} diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index eb120e0918..134b758c29 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1051,6 +1051,18 @@ is one of our (WINS server) names. Denying registration.\n", namestr(question) ) } } + /* + * If the name exists check if the IP address is already registered + * to that name. If so then update the ttl and reply success. + */ + + if((namerec != NULL) && find_ip_in_name_record(namerec, from_ip)) + { + update_name_ttl(namerec, ttl); + send_wins_name_registration_response(0, ttl, p); + return; + } + /* * If the name exists do a query to the owner * to see if they still want the name. @@ -1548,7 +1560,7 @@ void wins_write_database(void) if (namerec->source == REGISTER_NAME) { - fprintf(fp, "%s#%02x %d ", + fprintf(fp, "\"%s#%02x\" %d ", namerec->name.name,namerec->name.name_type, /* Ignore scope. */ (int)namerec->death_time); -- cgit From c04291ae995b65935ef9581bfd95eebaf4354c1d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 12 Feb 1998 14:57:55 +0000 Subject: make the initial logfile names consistent. This should mean that smbd starts with log.smb and nmbd starts with log.nmb. It also gets rid of the "log." when using the log.%m construct as %m expands to smb before a client connects. (This used to be commit b7712a0a6d0afeef6239d5af61cba677eebb247b) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index b6e4244cd0..d42580bcbd 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -204,7 +204,7 @@ BOOL reload_services(BOOL test) BOOL ret; extern fstring remote_machine; - strcpy( remote_machine, "nmbd" ); + strcpy( remote_machine, "nmb" ); if ( lp_loaded() ) { -- cgit From c16d4aec00230983973be3b827d1209f5db65d9c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 20 Feb 1998 19:48:01 +0000 Subject: nmbd_packets.c: nmbd_subnetdb.c: Patch from Andrey Alekseyev to fix the fact that retransmit_or_expire_response_records() wasn't looking at the WINS subnet. server.c: Patch from jkf@soton.ac.uk to add %p (NIS server path) substitution. smbpass.c: Fix to stop parsing failing on non-valid lines. trans2.c: Fix for volume serial number code. util.c: Patch from jkf@soton.ac.uk to add %p (NIS server path) substitution. Fix for warnings under RH5. gcc 2.8. Jeremy. (This used to be commit e58ab3bbe6e939ba678ad5482e58e0191c8dcbcb) --- source3/nmbd/nmbd_packets.c | 8 ++++++-- source3/nmbd/nmbd_subnetdb.c | 24 ++++++++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 9dad5ddaa9..cd99343e70 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1486,14 +1486,18 @@ void run_packet_queue() /******************************************************************* Retransmit or timeout elements from all the outgoing subnet response - record queues. + record queues. NOTE that this code must also check the WINS server + subnet for response records to timeout as the WINS server code + can send requests to check if a client still owns a name. + (Patch from Andrey Alekseyev ). ******************************************************************/ void retransmit_or_expire_response_records(time_t t) { struct subnet_record *subrec; - for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) + for (subrec = FIRST_SUBNET; subrec; + subrec = get_next_subnet_maybe_unicast_or_wins_server(subrec)) { struct response_record *rrec, *nextrrec; diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 5e18fe9cc0..07692cc82c 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -289,3 +289,27 @@ struct subnet_record *get_next_subnet_maybe_unicast(struct subnet_record *subrec else return subrec->next; } + +/******************************************************************* + Access function used by retransmit_or_expire_response_records() in + nmbd_packets.c. Patch from Andrey Alekseyev + Needed when we need to enumerate all the broadcast, unicast and + WINS subnets. +******************************************************************/ + +struct subnet_record *get_next_subnet_maybe_unicast_or_wins_server(struct subnet_record *subrec) +{ + if(subrec == unicast_subnet) + if(wins_server_subnet) + return wins_server_subnet; + else + return NULL; + + if(wins_server_subnet && subrec == wins_server_subnet) + return NULL; + + if((subrec->next == NULL) && we_are_a_wins_client()) + return unicast_subnet; + else + return subrec->next; +} -- cgit From 834ef5624421dfdb4665012ea43aa37d092efe40 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 24 Feb 1998 17:59:34 +0000 Subject: nmbd_incomingdgrams.c: Fix for typo. nmbd_sendannounce.c: Remote announcement was announcing to the wrong name ! nmblookup.c: Fix for substitutions not seeing hostname. testparm.c: Fix for substitutions not seeing hostname. wsmbstatus.c: Fix for substitutions not seeing hostname. util.c: Change read_udp_socket to use sockaddr_in rather than dubiously messing around with an opaque data type (sockaddr). Jeremy. (This used to be commit 776ccf5c0641b5aa300236c2612b5f2761d1179f) --- source3/nmbd/nmbd_incomingdgrams.c | 4 ++-- source3/nmbd/nmbd_sendannounce.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 46d988e89a..80057ef12c 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -449,8 +449,8 @@ void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct if ((osmajor < 36) || (osmajor > 38) || (osminor !=0)) { - DEBUG(5,("process_lm_host_announce: LM Announcement packet does not " \ - "originate from OS/2 Warp client. Ignoring packet.\n")); + DEBUG(5,("process_lm_host_announce: LM Announcement packet does not \ +originate from OS/2 Warp client. Ignoring packet.\n")); /* Could have been from a Windows machine (with its LM Announce enabled), or a Samba server. Then don't disrupt the current browse list. */ return; diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index 62e5f02d8c..e39e251496 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -529,7 +529,7 @@ void announce_remote(time_t t) send_announcement(FIRST_SUBNET, ANN_HostAnnouncement, name, /* From nbt name. */ - wgroup, 0x1e, /* To nbt name. */ + wgroup, 0x1d, /* To nbt name. */ addr, /* To ip. */ REMOTE_ANNOUNCE_INTERVAL, /* Time until next announce. */ name, /* Name to announce. */ -- cgit From cadfca4cf58003518e9afef55b9a36c33f044b3c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 24 Feb 1998 18:46:47 +0000 Subject: Fixed bug where second response message was being printed with the wrong IP address. This confused a lot of people (including me :-). Jeremy. (This used to be commit 0f4080d3f076db58917d13787a282e96ba59a053) --- source3/nmbd/nmbd_namequery.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index bbd831cac8..51f18edd05 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -91,7 +91,7 @@ for name %s. IP of that name is %s\n", subrec->subnet_name, inet_ntoa(p->ip), DEBUG(0,("query_name_response: Multiple (%d) responses received for a query on \ subnet %s for name %s. This response was from IP %s\n", rrec->num_msgs, subrec->subnet_name, namestr(question_name), - inet_ntoa(rrec->packet->ip) )); + inet_ntoa(p->ip) )); /* We have already called the success or fail function, so we don't call again here. Leave the response record around in -- cgit From 4680e65bb5a6da5131135a155573e1d2592ed1b0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 24 Feb 1998 20:05:39 +0000 Subject: Fixed bug reported by Janne.Harju@nmp.nokia.com. When used in broadcast only mode nmbd was not reporting WORKGROUP<0> and WORKGROUP<1e> names to a unicast node status query (although it was registering these names on the network). Also tidied up code in nmbd_mynames.c so that all known IP addresses are registered in the unicast subnet in this case rather than just the first, as was previously done. Jeremy. (This used to be commit eb71c5edcbb983ed4a1b0f57139bd66b671c67fa) --- source3/nmbd/nmbd_become_lmb.c | 2 +- source3/nmbd/nmbd_mynames.c | 40 ++++++++++++++++++++++++++++++++++------ 2 files changed, 35 insertions(+), 7 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index 2420b2ec4b..b58244104d 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -35,7 +35,7 @@ extern uint16 samba_nb_type; /* Samba's NetBIOS name type. */ our IP address if it already exists. ******************************************************************/ -static void insert_permanent_name_into_unicast( struct subnet_record *subrec, +void insert_permanent_name_into_unicast( struct subnet_record *subrec, struct nmb_name *nmbname, uint16 nb_type ) { struct name_record *namerec; diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index 9441449bed..30804ab807 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -29,6 +29,7 @@ extern int DEBUGLEVEL; extern char **my_netbios_names; extern pstring myname; extern fstring myworkgroup; +extern pstring scope; extern uint16 samba_nb_type; /* Samba's NetBIOS type. */ @@ -97,14 +98,41 @@ Exiting.\n", myworkgroup, subrec->subnet_name)); for (i=0; my_netbios_names[i]; i++) { - add_name_to_subnet(unicast_subnet, my_netbios_names[i],0x20,samba_nb_type, PERMANENT_TTL, - SELF_NAME, 1, &FIRST_SUBNET->myip); + for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + { + /* + * Ensure all the IP addresses are added if we are multihomed. + */ + struct nmb_name nmbname; + + make_nmb_name(&nmbname, my_netbios_names[i],0x20, scope); + insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type); + + make_nmb_name(&nmbname, my_netbios_names[i],0x3, scope); + insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type); + + make_nmb_name(&nmbname, my_netbios_names[i],0x0, scope); + insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type); + } + } + + /* + * Add the WORKGROUP<0> and WORKGROUP<1e> group names to the unicast subnet + * also for the same reasons. + */ + + for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + { + /* + * Ensure all the IP addresses are added if we are multihomed. + */ + struct nmb_name nmbname; - add_name_to_subnet(unicast_subnet, my_netbios_names[i],0x3,samba_nb_type, PERMANENT_TTL, - SELF_NAME, 1, &FIRST_SUBNET->myip); + make_nmb_name(&nmbname, myworkgroup, 0x0, scope); + insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP); - add_name_to_subnet(unicast_subnet, my_netbios_names[i],0x0,samba_nb_type, PERMANENT_TTL, - SELF_NAME, 1, &FIRST_SUBNET->myip); + make_nmb_name(&nmbname, myworkgroup, 0x1e, scope); + insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP); } } -- cgit From 64095b2486e3aca286103e28e400da3e40b14556 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 26 Feb 1998 19:26:18 +0000 Subject: Code to work around a bug in FTP OnNet software NBT implementation. They do a broadcast name release for WORKGROUP<0> and WORKGROUP<1e> names and *don't set the group bit*. Jeremy. (This used to be commit 1feb54e1ba27ab8aba2df4ebef4df010ca980f12) --- source3/nmbd/nmbd_incomingrequests.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index 57517c3734..ae163c6014 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -29,6 +29,7 @@ #include "includes.h" extern int DEBUGLEVEL; +extern fstring myworkgroup; /**************************************************************************** Send a name release response. @@ -95,6 +96,21 @@ subnet %s from owner IP %s\n", if( group && !ismyip(owner_ip) ) return; + /* + * Code to work around a bug in FTP OnNet software NBT implementation. + * They do a broadcast name release for WORKGROUP<0> and WORKGROUP<1e> + * names and *don't set the group bit* !!!!! + */ + + if( !group && !ismyip(owner_ip) && strequal(question->name, myworkgroup) && + ((question->name_type == 0x0) || (question->name_type == 0x1e))) + { + DEBUG(6,("process_name_release_request: FTP OnNet bug workaround. Ignoring \ +group release name %s from IP %s on subnet %s with no group bit set.\n", + namestr(question), inet_ntoa(owner_ip), subrec->subnet_name )); + return; + } + namerec = find_name_on_subnet(subrec, &nmb->question.question_name, FIND_ANY_NAME); /* We only care about someone trying to release one of our names. */ -- cgit From 45dab9f06594777e96be5f4556e6bb386f68f309 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 26 Feb 1998 22:58:21 +0000 Subject: Makefile, password.c, includes.h: Added KRB4 patches from Johan Hedin nmbd_packets.c: Patch for aliased interfaces from Daniel Haun . Jeremy. (This used to be commit 60f6302b1972e49159bf6e1a838e691268e4399c) --- source3/nmbd/nmbd_packets.c | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index cd99343e70..f14c62c4eb 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -58,6 +58,21 @@ static int find_subnet_fd_for_address( struct in_addr local_ip ) return ClientNMB; } +/*************************************************************************** +Utility function to find the specific fd to send a mailslot packet out on. +**************************************************************************/ + +static int find_subnet_mailslot_fd_for_address( struct in_addr local_ip ) +{ + struct subnet_record *subrec; + + for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + if(ip_equal(local_ip, subrec->myip)) + return subrec->dgram_sock; + + return ClientDGRAM; +} + /*************************************************************************** Get/Set problematic nb_flags as network byte order 16 bit int. **************************************************************************/ @@ -1828,7 +1843,7 @@ BOOL send_mailslot(BOOL unique, char *mailslot,char *buf,int len, p.ip = dest_ip; p.port = DGRAM_PORT; - p.fd = ClientDGRAM; + p.fd = find_subnet_mailslot_fd_for_address( src_ip ); p.timestamp = time(NULL); p.packet_type = DGRAM_PACKET; -- cgit From b7fb6c6b38784d25c9c85e9b27b08e30111dbd0c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 3 Mar 1998 20:19:14 +0000 Subject: Change the multibyte character set support so that Kanji support is one case of multibyte character support, rather than being a specific case in single byte character support. This allows us to add Big5 Chinese support (code page 950) and Korean Hangul support (code page 949) at very little cost. Also allows us to easily add future multibyte code pages. Makefile: Added codepages 949, 950 as we now support more multibyte codepages. asyncdns.c: Fixed problem with child being re-spawned when parent killed. charcnv.c charset.c client.c clitar.c kanji.c kanji.h smb.h util.c loadparm.c: Generic multibyte codepage support (adding Big5 Chinese and Korean Hangul). nmbd.c: Fixed problem with child being re-spawned when parent killed. mangle.c: Modified str_checksum so that first 15 characters have more effect on outcome. This helps with short name mangling as most 'long' names are still shorter than 15 chars (bug was foobar_mng and foobar_sum would hash to the same value, with the modified code they hash differently. Jeremy. (This used to be commit 299016338cfb47f0c585875ef9b468121fcee97d) --- source3/nmbd/asyncdns.c | 22 +++++++++++++++++++++- source3/nmbd/nmbd.c | 3 +++ 2 files changed, 24 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 3b71369d67..3fb16a08e9 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -103,7 +103,8 @@ static void asyncdns_process(void) } /**************************************************************************** ** - catch a sigterm + catch a sigterm (in the child process - the parent has a different handler + see nmbd.c for details). We need a separate term handler here so we don't release any names that our parent is going to release, or overwrite a WINS db that our parent is going to write. @@ -116,6 +117,17 @@ static int sig_term() return 0; } +/*************************************************************************** + Called by the parent process when it receives a SIGTERM - also kills the + child so we don't get child async dns processes lying around, causing trouble. + ****************************************************************************/ + +void kill_async_dns_child() +{ + if(child_pid != 0 && child_pid != -1) + kill(child_pid, SIGTERM); +} + /*************************************************************************** create a child process to handle DNS lookups ****************************************************************************/ @@ -326,4 +338,12 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, send_wins_name_query_response(0, p, *n); return False; } + +/*************************************************************************** + With sync dns there is no child to kill on SIGTERM. + ****************************************************************************/ +void kill_async_dns_child() +{ + return; +} #endif diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index d42580bcbd..1a12e0eec0 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -74,6 +74,9 @@ static int sig_term() /* Announce all server entries as 0 time-to-live, 0 type. */ announce_my_servers_removed(); + /* If there was an async dns child - kill it. */ + kill_async_dns_child(); + exit(0); /* Keep compiler happy.. */ -- cgit From fdeea341ed1bae670382e45eb731db1b5838ad21 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 11 Mar 1998 21:11:04 +0000 Subject: "For I have laboured mightily on Luke's code, and hath broken all I saw" - the book of Jeremy, chapter 1 :-). So here is the mega-merge of the NTDOM branch server code. It doesn't include the new client side pieces, we'll look at that later. This should give the same functionality, server wise, as the NTDOM branch does, only merged into the main branch. Any fixes to domain controler functionality should be added to the main branch, not the NTDOM branch. This code compiles without warnings on gcc2.8, but will need further testing before we are sure all the working functionality of the NTDOM server branch has been correctly carried over. I hereby declare the server side of the NTDOM branch dead (and all who sail in her :-). Jeremy. (This used to be commit 118ba4d77a33248e762a2cf843fb7cbc906ee6e7) --- source3/nmbd/nmbd_processlogon.c | 10 ++++++++-- source3/nmbd/nmbd_subnetdb.c | 2 ++ source3/nmbd/nmbd_winsserver.c | 7 ++++--- 3 files changed, 14 insertions(+), 5 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 64f66038e0..f881b867c0 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -195,7 +195,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", * Let's ignore the SID. */ - strcpy(ascuser, unistr(uniuser)); + pstrcpy(ascuser, unistr(uniuser)); DEBUG(3,("process_logon_packet: SAMLOGON user %s\n", ascuser)); strcpy(reply_name,"\\\\"); /* Here it wants \\LOGONSERVER. */ @@ -203,12 +203,18 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", smb_pass = get_smbpwd_entry(ascuser, 0); - if(!smb_pass) + if(!smb_pass ) { DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, not in password file\n", unistr(unicomp),inet_ntoa(p->ip), ascuser)); return; } + else if(smb_pass->acct_ctrl & ACB_DISABLED) + { + DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, accound disabled.\n", + unistr(unicomp),inet_ntoa(p->ip), ascuser)); + return; + } else { DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n", diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 07692cc82c..e10ddc2c6a 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -300,10 +300,12 @@ struct subnet_record *get_next_subnet_maybe_unicast(struct subnet_record *subrec struct subnet_record *get_next_subnet_maybe_unicast_or_wins_server(struct subnet_record *subrec) { if(subrec == unicast_subnet) + { if(wins_server_subnet) return wins_server_subnet; else return NULL; + } if(wins_server_subnet && subrec == wins_server_subnet) return NULL; diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 134b758c29..afc8741366 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1260,12 +1260,13 @@ void send_wins_name_query_response(int rcode, struct packet_struct *p, } } - for(; i < namerec->num_ips; i++) + for(j = 0; j < namerec->num_ips; j++) { - if(i == same_net_index) + if(j == same_net_index) continue; set_nb_flags(&prdata[i*6],namerec->nb_flags); - putip((char *)&prdata[2+(i*6)], &namerec->ip[i]); + putip((char *)&prdata[2+(i*6)], &namerec->ip[j]); + i++; } reply_data_len = namerec->num_ips * 6; -- cgit From b85346942e7d785af718b68d61b208cb457a2b27 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 14 Mar 1998 08:27:41 +0000 Subject: another makeover of loadparm to support new stuff in swat and testparm. In particular I added: - ability to optionally save default values of all parameters when calling lp_load(). This can then be used to save only non-default parameters in lp_dump(). This makes the saved smb.conf (and viewed parameters in testparm) much shorter - ability to not load ipc share in lp_load() - separators in parm_table[] so parameters can be grouped logically. - flag to mark parameters that are local but which should be also viewed as global as far as parameters editing is concerned (This used to be commit f9af35da26e58fb0b644b5f0169f1c212230047a) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 1a12e0eec0..f199a21ea8 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -223,7 +223,7 @@ BOOL reload_services(BOOL test) if ( test && !lp_file_list_changed() ) return(True); - ret = lp_load( servicesf, True ); + ret = lp_load( servicesf, True , False, False); /* perhaps the config filename is now set */ if ( !test ) -- cgit From c063e9ec3e90508e846dd51e22a643c74c02f7c1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 14 Mar 1998 12:57:58 +0000 Subject: added the ability to start/stop the server from SWAT. I needed to modify the way the pidfile is handled in nmbd and smbd to do this. Jeremy, you may wish to look at what I've done as it probably breaks the Whistle use of pidfiles. In particular I've removed the -f option and instead smbd and nmbd always create a pidfile in the lock directory. (This used to be commit 20bb22d61b986d2036c681fc33db60f2b2b3c1c7) --- source3/nmbd/nmbd.c | 39 +++------------------------------------ 1 file changed, 3 insertions(+), 36 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index f199a21ea8..e757aa46c4 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -549,7 +549,6 @@ int main(int argc,char *argv[]) int opt; extern FILE *dbf; extern char *optarg; - char pidFile[100] = { 0 }; global_nmb_port = NMB_PORT; *host_file = 0; @@ -599,9 +598,6 @@ int main(int argc,char *argv[]) { switch (opt) { - case 'f': - strncpy(pidFile, optarg, sizeof(pidFile)); - break; case 's': pstrcpy(servicesf,optarg); break; @@ -695,40 +691,11 @@ int main(int argc,char *argv[]) become_daemon(); } - if (!directory_exist(lp_lockdir(), NULL)) - { - mkdir(lp_lockdir(), 0755); - } - - if (*pidFile) - { - int fd; - char buf[20]; - -#ifdef O_NONBLOCK - fd = open( pidFile, O_NONBLOCK | O_CREAT | O_WRONLY | O_TRUNC, 0644 ); -#else - fd = open( pidFile, O_CREAT | O_WRONLY | O_TRUNC, 0644 ); -#endif - if ( fd < 0 ) - { - DEBUG(0,("ERROR: can't open %s: %s\n", pidFile, strerror(errno))); - exit(1); - } - if (fcntl_lock(fd,F_SETLK,0,1,F_WRLCK)==False) - { - DEBUG(0,("ERROR: nmbd is already running\n")); - exit(1); - } - sprintf(buf, "%u\n", (unsigned int) getpid()); - if (write(fd, buf, strlen(buf)) < 0) - { - DEBUG(0,("ERROR: can't write to %s: %s\n", pidFile, strerror(errno))); - exit(1); - } - /* Leave pid file open & locked for the duration... */ + if (!directory_exist(lp_lockdir(), NULL)) { + mkdir(lp_lockdir(), 0755); } + pidfile_create("nmbd"); DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); -- cgit From c54af0f8b20e3f93c59da6a817920e1de6c4a870 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 16 Mar 1998 20:59:47 +0000 Subject: Adding the same change as was added to 1.9.18 branch to add the "name resolve order" parameter. source/Makefile: Re-ordered link for name resolve order code. source/clientgen.c: source/clientutil.c: Added calls to resolve_name(). source/includes.h: Added HPUX zombie fix. source/loadparm.c: Added new name resolve order parameter. source/namequery.c: Re-wrote to include parsing of lmhosts file, new resolve_name() function requested by John. source/nmbd.c: Tell resolve_name not to do WINS lookups if we are the WINS server. source/nmbd_lmhosts.c: Call lmhosts parsing functions in namequery.c source/password.c: Call resolve_name() to lookup security=server name. source/reply.c: source/time.c: source/trans2.c: "fake directory create times" fix from Jim Hague - hague@research.canon.com.au. source/util.c: Removed isalnum() test in Get_Hostname() that seems to cause problems on many systems. Jeremy. (This used to be commit 7f118970da7c43eaddcf92dc056d3e849f1e7d5c) --- source3/nmbd/nmbd.c | 3 ++ source3/nmbd/nmbd_lmhosts.c | 81 ++++----------------------------------------- 2 files changed, 10 insertions(+), 74 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index e757aa46c4..837f98e8bb 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -44,6 +44,8 @@ extern pstring myname; extern fstring myworkgroup; extern char **my_netbios_names; +extern BOOL global_in_nmbd; + /* are we running as a daemon ? */ static BOOL is_daemon = False; @@ -552,6 +554,7 @@ int main(int argc,char *argv[]) global_nmb_port = NMB_PORT; *host_file = 0; + global_in_nmbd = True; StartupTime = time(NULL); diff --git a/source3/nmbd/nmbd_lmhosts.c b/source3/nmbd/nmbd_lmhosts.c index 722c3681f5..206c2367b1 100644 --- a/source3/nmbd/nmbd_lmhosts.c +++ b/source3/nmbd/nmbd_lmhosts.c @@ -33,88 +33,21 @@ Load a lmhosts file. ****************************************************************************/ void load_lmhosts_file(char *fname) { - FILE *fp = fopen(fname,"r"); - pstring line; + pstring name; + int name_type; + struct in_addr ipaddr; + FILE *fp = startlmhosts( fname ); + if (!fp) { DEBUG(2,("load_lmhosts_file: Can't open lmhosts file %s. Error was %s\n", fname, strerror(errno))); return; } - while (!feof(fp)) + while (getlmhostsent(fp, name, &name_type, &ipaddr) ) { - pstring ip,name,flags,extra; struct subnet_record *subrec = NULL; - char *ptr; - int count = 0; - struct in_addr ipaddr; enum name_source source = LMHOSTS_NAME; - int name_type = -1; - - if (!fgets_slash(line,sizeof(pstring),fp)) - continue; - - if (*line == '#') - continue; - - strcpy(ip,""); - strcpy(name,""); - strcpy(flags,""); - - ptr = line; - - if (next_token(&ptr,ip ,NULL)) - ++count; - if (next_token(&ptr,name ,NULL)) - ++count; - if (next_token(&ptr,flags,NULL)) - ++count; - if (next_token(&ptr,extra,NULL)) - ++count; - - if (count <= 0) - continue; - - if (count > 0 && count < 2) - { - DEBUG(0,("load_lmhosts_file: Ill formed hosts line [%s]\n",line)); - continue; - } - - if (count >= 4) - { - DEBUG(0,("load_lmhosts_file: too many columns in lmhosts file %s (obsolete syntax)\n", - fname)); - continue; - } - - DEBUG(4, ("load_lmhosts_file: lmhost entry: %s %s %s\n", ip, name, flags)); - - if (strchr(flags,'G') || strchr(flags,'S')) - { - DEBUG(0,("load_lmhosts_file: group flag in %s ignored (obsolete)\n",fname)); - continue; - } - - ipaddr = *interpret_addr2(ip); - - /* Extra feature. If the name ends in '#XX', where XX is a hex number, - then only add that name type. */ - if((ptr = strchr(name, '#')) != NULL) - { - char *endptr; - - ptr++; - name_type = (int)strtol(ptr, &endptr,0); - - if(!*ptr || (endptr == ptr)) - { - DEBUG(0,("load_lmhosts_file: invalid name %s containing '#'.\n", name)); - continue; - } - - *(--ptr) = '\0'; /* Truncate at the '#' */ - } /* We find a relevent subnet to put this entry on, then add it. */ /* Go through all the broadcast subnets and see if the mask matches. */ @@ -141,7 +74,7 @@ void load_lmhosts_file(char *fname) } } - fclose(fp); + endlmhosts(fp); } /**************************************************************************** -- cgit From fd6dacbcdbbc2fbcb1e8f487cd58eefb4c24b982 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 2 Apr 1998 19:12:11 +0000 Subject: We were missing a case switch in announcement processing - we were loggin a become backup request with debug log level of 0 - thus producing lots of annoying error messages. Now handle this explicitly. Jeremy. (This used to be commit 0f4914b870b0dfa876ac47d29f3a1b3736a3d698) --- source3/nmbd/nmbd_packets.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index f14c62c4eb..cafed5f79a 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -982,11 +982,13 @@ mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, scop } case ANN_AnnouncementRequest: { + debug_browse_data(buf, len); process_announce_request(subrec, p, buf+1); break; } case ANN_Election: { + debug_browse_data(buf, len); process_election(subrec, p, buf+1); break; } @@ -1016,6 +1018,7 @@ packet from %s IP %s\n", namestr(&dgram->source_name), inet_ntoa(p->ip))); } case ANN_ResetBrowserState: { + debug_browse_data(buf, len); process_reset_browser(subrec, p, buf+1); break; } @@ -1025,11 +1028,25 @@ packet from %s IP %s\n", namestr(&dgram->source_name), inet_ntoa(p->ip))); on the unicast subnet. */ subrec = unicast_subnet; + debug_browse_data(buf, len); process_master_browser_announce(subrec, p, buf+1); break; } + case ANN_BecomeBackup: + { + /* + * We don't currently implement this. Log it just in case. + */ + debug_browse_data(buf, len); + DEBUG(10,("process_browse_packet: On subnet %s ignoring browse packet \ +command ANN_BecomeBackup from %s IP %s to %s\n", + subrec->subnet_name, namestr(&dgram->source_name), + inet_ntoa(p->ip), namestr(&dgram->dest_name))); + break; + } default: { + debug_browse_data(buf, len); DEBUG(0,("process_browse_packet: On subnet %s ignoring browse packet \ command code %d from %s IP %s to %s\n", subrec->subnet_name, command, namestr(&dgram->source_name), -- cgit From cac6a060af598bf94e6414b06e7365ec51ca360e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 13 Apr 1998 19:24:06 +0000 Subject: Changes to allow Samba to be compiled with -Wstrict-prototypes with gcc. (Not a big change although it looks like it :-). Jeremy. (This used to be commit cd2613c57261456485fe4eeecfda209ada70de8e) --- source3/nmbd/asyncdns.c | 6 +++--- source3/nmbd/nmbd.c | 6 +++--- source3/nmbd/nmbd_mynames.c | 4 ++-- source3/nmbd/nmbd_namelistdb.c | 2 +- source3/nmbd/nmbd_packets.c | 2 +- source3/nmbd/nmbd_sendannounce.c | 2 +- source3/nmbd/nmbd_subnetdb.c | 4 ++-- 7 files changed, 13 insertions(+), 13 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 3fb16a08e9..6019819793 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -110,7 +110,7 @@ static void asyncdns_process(void) WINS db that our parent is going to write. **************************************************************************** */ -static int sig_term() +static int sig_term(void) { _exit(0); /* Keep compiler happy.. */ @@ -122,7 +122,7 @@ static int sig_term() child so we don't get child async dns processes lying around, causing trouble. ****************************************************************************/ -void kill_async_dns_child() +void kill_async_dns_child(void) { if(child_pid != 0 && child_pid != -1) kill(child_pid, SIGTERM); @@ -342,7 +342,7 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, /*************************************************************************** With sync dns there is no child to kill on SIGTERM. ****************************************************************************/ -void kill_async_dns_child() +void kill_async_dns_child(void) { return; } diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 837f98e8bb..8373997e64 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -61,7 +61,7 @@ extern struct in_addr ipzero; /**************************************************************************** ** catch a sigterm **************************************************************************** */ -static int sig_term() +static int sig_term(void) { BlockSignals(True,SIGTERM); @@ -441,7 +441,7 @@ static BOOL open_sockets(BOOL isdaemon, int port) /**************************************************************************** ** initialise connect, service and file structs **************************************************************************** */ -static BOOL init_structs() +static BOOL init_structs(void) { extern fstring local_machine; char *p, *ptr; @@ -577,7 +577,7 @@ int main(int argc,char *argv[]) argc--; } - fault_setup( fault_continue ); + fault_setup((void (*)(void *))fault_continue ); signal( SIGHUP, SIGNAL_CAST sig_hup ); signal( SIGTERM, SIGNAL_CAST sig_term ); diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index 30804ab807..cf21fafd87 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -49,7 +49,7 @@ static void my_name_register_failed(struct subnet_record *subrec, Also add the magic Samba names. **************************************************************************/ -BOOL register_my_workgroup_and_names() +BOOL register_my_workgroup_and_names(void) { struct subnet_record *subrec; struct work_record *work; @@ -143,7 +143,7 @@ Exiting.\n", myworkgroup, subrec->subnet_name)); Remove all the names we registered. **************************************************************************/ -void release_my_names() +void release_my_names(void) { struct subnet_record *subrec; diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 2237fc504d..b37cac10dc 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -551,7 +551,7 @@ static void dump_subnet_namelist( struct subnet_record *subrec, FILE *fp) into a file. Initiated by SIGHUP - used to debug the state of the namelists. **************************************************************************/ -void dump_all_namelists() +void dump_all_namelists(void) { fstring fname; FILE *fp; diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index cafed5f79a..19c61a877a 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1488,7 +1488,7 @@ found for id = %hu. Ignoring packet.\n", nmb->header.name_trn_id)); Run elements off the packet queue till its empty ******************************************************************/ -void run_packet_queue() +void run_packet_queue(void) { struct packet_struct *p; diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index e39e251496..48072650c2 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -372,7 +372,7 @@ static time_t announce_timer_last=0; immediately. ****************************************************************************/ -void reset_announce_timer() +void reset_announce_timer(void) { announce_timer_last = time(NULL) - (CHECK_TIME_MST_ANNOUNCE * 60); } diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index e10ddc2c6a..d8e8dd4ab9 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -164,7 +164,7 @@ for port %d. Error was %s\n", inet_ntoa(myip), DGRAM_PORT, strerror(errno))); Create subnet entries. **************************************************************************/ -BOOL create_subnets() +BOOL create_subnets(void) { int num_interfaces = iface_count(); int i; @@ -265,7 +265,7 @@ BOOL create_subnets() Function to tell us if we can use the unicast subnet. ******************************************************************/ -BOOL we_are_a_wins_client() +BOOL we_are_a_wins_client(void) { static int cache_we_are_a_wins_client = -1; -- cgit From 2a53d6f7077de596265a3e73e79827392054142c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 14 Apr 1998 00:41:59 +0000 Subject: Modified interfaces to getting smb password entries from get_smbpwd_entry (now an internal function to smbpass.c) to a more UNIX-like : getsmbpwnam() - get entry by name. getsmbpwuid() - get entry by uid. Changed the type returned by the smbpasswd enumeration functions to be a void * so that people don't come to depend on it being a FILE *. These abstractions should make it much easier to replace the smbpasswd file with a better backend in future. Other files changed are to match the above changes. Jeremy. (This used to be commit 1161cfb7f2b0d5a6d3e2b524a14a6f325ce70efb) --- source3/nmbd/nmbd_processlogon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index f881b867c0..bc9fcb5921 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -201,7 +201,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", strcpy(reply_name,"\\\\"); /* Here it wants \\LOGONSERVER. */ strcpy(reply_name+2,my_name); - smb_pass = get_smbpwd_entry(ascuser, 0); + smb_pass = getsmbpwnam(ascuser); if(!smb_pass ) { -- cgit From 041a292c439189206f1c35de94893dd51a1fda33 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 15 Apr 1998 20:00:41 +0000 Subject: ipc.c: Fix for printer queue spinning with Win95. nmbd.c: Fix for always overwriting log despite append setting. smb.h: Addition of last time password changed entry to account info. smbpass.c: Changes to support last time changed field in smbpasswd file. smbpasswd.c: Changes to support last time changed field in smbpasswd file. util.c: Fix for always overwriting log despite append setting. Jeremy. (This used to be commit eb4fe9ecdf539209efab07dc992447ea7370cf93) --- source3/nmbd/nmbd.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 8373997e64..5de1d3291d 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -653,6 +653,8 @@ int main(int argc,char *argv[]) } } + reopen_logs(); + DEBUG(1,("%s netbios nameserver version %s started\n",timestring(),VERSION)); DEBUG(1,("Copyright Andrew Tridgell 1994-1997\n")); -- cgit From ec6fde99ab739ff2c410e5459bba06b06d18b5dc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 20 Apr 1998 20:32:50 +0000 Subject: Fixed bug that John found in WINS server code. When nmbd as a WINS server is sending out a name_query after a WACK, it needs to send a packet with recursion_desired = 0 (yes Luke, you were right all along :-). If it doesn't then if it's talking to itself then the query packet ends up back in the WINS server instead of in the client side code. Makefile: Changed proto generation to stop including NMBDOBJ twice. nmbd_namequery.c nmbd_packets.c nmbd_winsserver.c: Added extra query_name_from_wins_server() code. Jeremy. (This used to be commit c5ca05c29546053a771f4ea3ef850efb3be970ea) --- source3/nmbd/nmbd_namequery.c | 29 +++++++++++++++++++ source3/nmbd/nmbd_packets.c | 64 ++++++++++++++++++++++++++++++++++++++++++ source3/nmbd/nmbd_winsserver.c | 15 ++++------ 3 files changed, 99 insertions(+), 9 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index 51f18edd05..1794efe890 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -232,3 +232,32 @@ BOOL query_name(struct subnet_record *subrec, char *name, int type, } return False; } + +/**************************************************************************** + Try and query for a name from nmbd acting as a WINS server. +****************************************************************************/ + +BOOL query_name_from_wins_server(struct in_addr ip_to, + char *name, int type, + query_name_success_function success_fn, + query_name_fail_function fail_fn, + struct userdata_struct *userdata) +{ + struct nmb_name nmbname; + + make_nmb_name(&nmbname, name, type, scope); + + if(queue_query_name_from_wins_server( ip_to, + query_name_response, + query_name_timeout_response, + success_fn, + fail_fn, + userdata, + &nmbname) == NULL) + { + DEBUG(0,("query_name_from_wins_server: Failed to send packet trying to query name %s\n", + namestr(&nmbname))); + return True; + } + return False; +} diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 19c61a877a..54f4f3a2cb 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -281,6 +281,28 @@ static BOOL initiate_name_query_packet( struct packet_struct *packet) return send_netbios_packet( packet ); } +/*************************************************************************** + Sends out a name query - from a WINS server. +**************************************************************************/ + +static BOOL initiate_name_query_packet_from_wins_server( struct packet_struct *packet) +{ + struct nmb_packet *nmb = NULL; + + nmb = &packet->packet.nmb; + + nmb->header.opcode = NMB_NAME_QUERY_OPCODE; + nmb->header.arcount = 0; + + nmb->header.nm_flags.recursion_desired = False; + + DEBUG(4,("initiate_name_query_packet_from_wins_server: sending query for name %s (bcast=%s) to IP %s\n", + namestr(&nmb->question.question_name), + BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip))); + + return send_netbios_packet( packet ); +} + /*************************************************************************** Sends out a name register. **************************************************************************/ @@ -679,6 +701,48 @@ struct response_record *queue_query_name( struct subnet_record *subrec, return rrec; } +/**************************************************************************** + Queue a query name packet to a given address from the WINS subnet. +****************************************************************************/ + +struct response_record *queue_query_name_from_wins_server( struct in_addr to_ip, + response_function resp_fn, + timeout_response_function timeout_fn, + query_name_success_function success_fn, + query_name_fail_function fail_fn, + struct userdata_struct *userdata, + struct nmb_name *nmbname) +{ + struct packet_struct *p; + struct response_record *rrec; + BOOL bcast = False; + + if(( p = create_and_init_netbios_packet(nmbname, bcast, to_ip)) == NULL) + return NULL; + + if(initiate_name_query_packet_from_wins_server( p ) == False) + { + p->locked = False; + free_packet(p); + return NULL; + } + + if((rrec = make_response_record(wins_server_subnet, /* subnet record. */ + p, /* packet we sent. */ + resp_fn, /* function to call on response. */ + timeout_fn, /* function to call on timeout. */ + (success_function)success_fn, /* function to call on operation success. */ + (fail_function)fail_fn, /* function to call on operation fail. */ + userdata)) == NULL) + { + p->locked = False; + free_packet(p); + return NULL; + } + + return rrec; +} + /**************************************************************************** Queue a node status packet to a given name and address. ****************************************************************************/ diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index afc8741366..d089686917 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -808,20 +808,17 @@ is one of our (WINS server) names. Denying registration.\n", namestr(question) ) memcpy(userdata->data, (char *)&p, sizeof(struct packet_struct *) ); /* - * As query_name uses the subnet broadcast address as the destination - * of the packet we temporarily change the subnet broadcast address to - * be the first IP address of the name owner and send the packet. This - * is a *horrible* hack but the alternative is to add the destination - * address parameter to all query_name() calls. I hate this code :-). + * Use the new call to send a query directly to an IP address. + * This sends the query directly to the IP address, and ensures + * the recursion desired flag is not set (you were right Luke :-). + * This function should *only* be called from the WINS server + * code. JRA. */ - subrec->bcast_ip = *namerec->ip; - - query_name( subrec, question->name, question->name_type, + query_name_from_wins_server( *namerec->ip, question->name, question->name_type, wins_register_query_success, wins_register_query_fail, userdata); - subrec->bcast_ip = ipzero; return; } -- cgit From e7ac86607c80912e55ac7179b100cea22749c16f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 25 Apr 1998 01:12:08 +0000 Subject: This looks like a big change but really isn't. It is changing the global variables "myname" and "myworkgroup" to "global_myname" and "global_myworkgroup" respectively. This is to make it very explicit when we are messing with a global (don't ask - it makes the domain client code much clearer :-). Jeremy. (This used to be commit 866406bfe399cf757c8275093dacd5ce4843afa0) --- source3/nmbd/nmbd.c | 32 ++++++++++++++-------------- source3/nmbd/nmbd_become_dmb.c | 26 +++++++++++------------ source3/nmbd/nmbd_become_lmb.c | 30 +++++++++++++------------- source3/nmbd/nmbd_browsesync.c | 12 +++++------ source3/nmbd/nmbd_elections.c | 18 ++++++++-------- source3/nmbd/nmbd_incomingdgrams.c | 28 ++++++++++++------------ source3/nmbd/nmbd_incomingrequests.c | 16 +++++++------- source3/nmbd/nmbd_logonnames.c | 18 ++++++++-------- source3/nmbd/nmbd_mynames.c | 11 +++++----- source3/nmbd/nmbd_nameregister.c | 4 ++-- source3/nmbd/nmbd_processlogon.c | 10 ++++----- source3/nmbd/nmbd_responserecordsdb.c | 1 - source3/nmbd/nmbd_sendannounce.c | 40 +++++++++++++++++------------------ source3/nmbd/nmbd_serverlistdb.c | 15 ++++++------- source3/nmbd/nmbd_subnetdb.c | 1 - source3/nmbd/nmbd_workgroupdb.c | 12 +++++------ 16 files changed, 135 insertions(+), 139 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 5de1d3291d..512504b02d 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -40,8 +40,8 @@ int global_nmb_port = -1; extern pstring myhostname; static pstring host_file; -extern pstring myname; -extern fstring myworkgroup; +extern pstring global_myname; +extern fstring global_myworkgroup; extern char **my_netbios_names; extern BOOL global_in_nmbd; @@ -450,23 +450,23 @@ static BOOL init_structs(void) int nodup; pstring nbname; - if (! *myname) + if (! *global_myname) { - fstrcpy( myname, myhostname ); - p = strchr( myname, '.' ); + fstrcpy( global_myname, myhostname ); + p = strchr( global_myname, '.' ); if (p) *p = 0; } - strupper( myname ); + strupper( global_myname ); /* Add any NETBIOS name aliases. Ensure that the first entry - is equal to myname. + is equal to global_myname. */ /* Work out the max number of netbios aliases that we have */ ptr = lp_netbios_aliases(); for( namecount=0; next_token(&ptr,nbname,NULL); namecount++ ) ; - if ( *myname ) + if ( *global_myname ) namecount++; /* Allocate space for the netbios aliases */ @@ -477,10 +477,10 @@ static BOOL init_structs(void) return( False ); } - /* Use the myname string first */ + /* Use the global_myname string first */ namecount=0; - if ( *myname ) - my_netbios_names[namecount++] = myname; + if ( *global_myname ) + my_netbios_names[namecount++] = global_myname; ptr = lp_netbios_aliases(); while ( next_token( &ptr, nbname, NULL ) ) @@ -508,7 +508,7 @@ static BOOL init_structs(void) /* Terminate name list */ my_netbios_names[namecount++] = NULL; - fstrcpy( local_machine, myname ); + fstrcpy( local_machine, global_myname ); trim_string( local_machine, " ", " " ); p = strchr( local_machine, ' ' ); if (p) @@ -615,8 +615,8 @@ int main(int argc,char *argv[]) pstrcpy(host_file,optarg); break; case 'n': - pstrcpy(myname,optarg); - strupper(myname); + pstrcpy(global_myname,optarg); + strupper(global_myname); break; case 'l': sprintf(debugf,"%s.nmb",optarg); @@ -674,9 +674,9 @@ int main(int argc,char *argv[]) reload_services( True ); - fstrcpy( myworkgroup, lp_workgroup() ); + fstrcpy( global_myworkgroup, lp_workgroup() ); - if (strequal(myworkgroup,"*")) + if (strequal(global_myworkgroup,"*")) { DEBUG(0,("ERROR: a workgroup name of * is no longer supported\n")); exit(1); diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index 52065758bc..d01bf18310 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -27,8 +27,8 @@ extern int DEBUGLEVEL; extern pstring scope; -extern pstring myname; -extern fstring myworkgroup; +extern pstring global_myname; +extern fstring global_myworkgroup; extern char **my_netbios_names; extern struct in_addr ipzero; extern struct in_addr allones_ip; @@ -56,11 +56,11 @@ static void unbecome_dmb_success(struct subnet_record *subrec, return; } - if((servrec = find_server_in_workgroup( work, myname)) == NULL) + if((servrec = find_server_in_workgroup( work, global_myname)) == NULL) { DEBUG(0,("unbecome_dmb_success: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - myname, released_name->name, subrec->subnet_name)); + global_myname, released_name->name, subrec->subnet_name)); return; } @@ -82,7 +82,7 @@ in workgroup %s on subnet %s\n", putip((char *)&work->dmb_addr, &ipzero); DEBUG(0,("\n%s ***** Samba server %s has stopped being a domain master browser \ -for workgroup %s on subnet %s *****\n\n", timestring(), myname, work->work_group, subrec->subnet_name)); +for workgroup %s on subnet %s *****\n\n", timestring(), global_myname, work->work_group, subrec->subnet_name)); } @@ -157,11 +157,11 @@ workgroup %s on subnet %s\n", fail_name->name, subrec->subnet_name)); /* Set the state back to DOMAIN_NONE. */ work->dom_state = DOMAIN_NONE; - if((servrec = find_server_in_workgroup( work, myname)) == NULL) + if((servrec = find_server_in_workgroup( work, global_myname)) == NULL) { DEBUG(0,("become_domain_master_fail: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - myname, work->work_group, subrec->subnet_name)); + global_myname, work->work_group, subrec->subnet_name)); return; } @@ -196,11 +196,11 @@ workgroup %s on subnet %s\n", registered_name->name, subrec->subnet_name)); return; } - if((servrec = find_server_in_workgroup( work, myname)) == NULL) + if((servrec = find_server_in_workgroup( work, global_myname)) == NULL) { DEBUG(0,("become_domain_master_stage2: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - myname, registered_name->name, subrec->subnet_name)); + global_myname, registered_name->name, subrec->subnet_name)); work->dom_state = DOMAIN_NONE; return; } @@ -215,7 +215,7 @@ in workgroup %s on subnet %s\n", subrec->work_changed = True; DEBUG(0,("\n%s ***** Samba server %s is now a domain master browser for \ -workgroup %s on subnet %s *****\n\n", timestring(),myname, work->work_group, +workgroup %s on subnet %s *****\n\n", timestring(),global_myname, work->work_group, subrec->subnet_name)); if(subrec == unicast_subnet) @@ -228,7 +228,7 @@ subrec->subnet_name)); will stop us syncing with ourself if we are also a local master browser. */ - make_nmb_name(&nmbname, myname, 0x20, scope); + make_nmb_name(&nmbname, global_myname, 0x20, scope); work->dmb_name = nmbname; /* Pick the first interface ip address as the domain master browser ip. */ @@ -464,9 +464,9 @@ void add_domain_names(time_t t) 1.9.16p2 to 1.9.16p11 - due to a bug in namelogon.c, cannot provide domain master / domain logon services. */ - become_domain_master_browser_wins(myworkgroup); + become_domain_master_browser_wins(global_myworkgroup); } else - become_domain_master_browser_bcast(myworkgroup); + become_domain_master_browser_bcast(global_myworkgroup); } } diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index b58244104d..c602789fb8 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -26,7 +26,7 @@ extern int DEBUGLEVEL; extern pstring scope; -extern pstring myname; +extern pstring global_myname; extern uint16 samba_nb_type; /* Samba's NetBIOS name type. */ @@ -90,11 +90,11 @@ subnet %s.\n", workgroup_name, subrec->subnet_name )); return; } - if((servrec = find_server_in_workgroup( work, myname)) == NULL) + if((servrec = find_server_in_workgroup( work, global_myname)) == NULL) { DEBUG(0,("reset_workgroup_state: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - myname, work->work_group, subrec->subnet_name)); + global_myname, work->work_group, subrec->subnet_name)); work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; return; } @@ -146,7 +146,7 @@ void unbecome_local_master_success(struct subnet_record *subrec, reset_workgroup_state( subrec, released_name->name ); DEBUG(0,("\n%s ***** Samba name server %s has stopped being a local master browser for workgroup %s \ -on subnet %s *****\n\n", timestring(), myname, released_name->name, subrec->subnet_name)); +on subnet %s *****\n\n", timestring(), global_myname, released_name->name, subrec->subnet_name)); } @@ -171,7 +171,7 @@ Removing from namelist anyway.\n", namestr(fail_name))); reset_workgroup_state( subrec, fail_name->name ); DEBUG(0,("\n%s ***** Samba name server %s has stopped being a local master browser for workgroup %s \ -on subnet %s *****\n\n", timestring(), myname, fail_name->name, subrec->subnet_name)); +on subnet %s *****\n\n", timestring(), global_myname, fail_name->name, subrec->subnet_name)); } @@ -254,11 +254,11 @@ void unbecome_local_master_browser(struct subnet_record *subrec, struct work_rec DEBUG(2,("unbecome_local_master_browser: unbecoming local master for workgroup %s \ on subnet %s\n",work->work_group, subrec->subnet_name)); - if((servrec = find_server_in_workgroup( work, myname)) == NULL) + if((servrec = find_server_in_workgroup( work, global_myname)) == NULL) { DEBUG(0,("unbecome_local_master_browser: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - myname, work->work_group, subrec->subnet_name)); + global_myname, work->work_group, subrec->subnet_name)); work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; return; } @@ -314,11 +314,11 @@ workgroup %s on subnet %s\n", registered_name->name, subrec->subnet_name)); return; } - if((servrec = find_server_in_workgroup( work, myname)) == NULL) + if((servrec = find_server_in_workgroup( work, global_myname)) == NULL) { DEBUG(0,("become_local_master_stage2: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - myname, registered_name->name, subrec->subnet_name)); + global_myname, registered_name->name, subrec->subnet_name)); work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; return; } @@ -336,7 +336,7 @@ on subnet %s\n", work->work_group, subrec->subnet_name)); subrec->work_changed = True; /* Add this name to the workgroup as local master browser. */ - set_workgroup_local_master_browser_name( work, myname); + set_workgroup_local_master_browser_name( work, global_myname); /* Count the number of servers we have on our list. If it's less than 10 (just a heuristic) request the servers @@ -369,7 +369,7 @@ on subnet %s\n", work->work_group, subrec->subnet_name)); reset_announce_timer(); DEBUG(0,("\n%s ***** Samba name server %s is now a local master browser for workgroup %s \ -on subnet %s *****\n\n", timestring(), myname, work->work_group, subrec->subnet_name)); +on subnet %s *****\n\n", timestring(), global_myname, work->work_group, subrec->subnet_name)); } @@ -456,11 +456,11 @@ workgroup %s on subnet %s\n", work_name, subrec->subnet_name)); return; } - if((servrec = find_server_in_workgroup(work, myname)) == NULL) + if((servrec = find_server_in_workgroup(work, global_myname)) == NULL) { DEBUG(0,("become_local_master_fail1: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - myname, work->work_group, subrec->subnet_name)); + global_myname, work->work_group, subrec->subnet_name)); return; } @@ -499,11 +499,11 @@ void become_local_master_browser(struct subnet_record *subrec, struct work_recor return; } - if((servrec = find_server_in_workgroup( work, myname)) == NULL) + if((servrec = find_server_in_workgroup( work, global_myname)) == NULL) { DEBUG(0,("become_local_master_browser: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - myname, work->work_group, subrec->subnet_name)); + global_myname, work->work_group, subrec->subnet_name)); return; } diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 94bdecb8fc..c78fdfc514 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -28,8 +28,8 @@ extern int DEBUGLEVEL; extern pstring scope; extern struct in_addr ipzero; -extern pstring myname; -extern fstring myworkgroup; +extern pstring global_myname; +extern fstring global_myworkgroup; /* This is our local master browser list database. */ extern struct browse_cache_record *lmb_browserlist; @@ -244,7 +244,7 @@ Do not announce to ourselves.\n", work->work_group )); CVAL(p,0) = ANN_MasterAnnouncement; p++; - StrnCpy(p,myname,15); + StrnCpy(p,global_myname,15); strupper(p); p = skip_string(p,1); @@ -252,7 +252,7 @@ Do not announce to ourselves.\n", work->work_group )); to %s for workgroup %s.\n", namestr(&work->dmb_name), work->work_group )); send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), - myname, 0x0, work->dmb_name.name, 0x0, work->dmb_addr, FIRST_SUBNET->myip); + global_myname, 0x0, work->dmb_name.name, 0x0, work->dmb_addr, FIRST_SUBNET->myip); } @@ -640,10 +640,10 @@ void collect_all_workgroup_names_from_wins_server(time_t t) return; /* Check to see if we are a domain master browser on the unicast subnet. */ - if((work = find_workgroup_on_subnet( unicast_subnet, myworkgroup)) == NULL) + if((work = find_workgroup_on_subnet( unicast_subnet, global_myworkgroup)) == NULL) { DEBUG(0,("collect_all_workgroup_names_from_wins_server: Cannot find my workgroup %s on subnet %s.\n", - myworkgroup, unicast_subnet->subnet_name )); + global_myworkgroup, unicast_subnet->subnet_name )); return; } diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index fa1e5986a8..569b653129 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -26,8 +26,8 @@ extern int DEBUGLEVEL; -extern pstring myname; -extern fstring myworkgroup; +extern pstring global_myname; +extern fstring global_myworkgroup; /* Election parameters. */ extern time_t StartupTime; @@ -95,7 +95,7 @@ static void check_for_master_browser_fail( struct subnet_record *subrec, return; } - if (strequal(work->work_group, myworkgroup)) + if (strequal(work->work_group, global_myworkgroup)) { if (lp_local_master()) @@ -117,7 +117,7 @@ static void check_for_master_browser_fail( struct subnet_record *subrec, not to become the local master, but we still need one, having detected that one doesn't exist. */ - send_election_dgram(subrec, work->work_group, 0, 0, myname); + send_election_dgram(subrec, work->work_group, 0, 0, global_myname); } } } @@ -131,7 +131,7 @@ void check_master_browser_exists(time_t t) { static time_t lastrun=0; struct subnet_record *subrec; - char *workgroup_name = myworkgroup; + char *workgroup_name = global_myworkgroup; if (!lastrun) lastrun = t; @@ -186,7 +186,7 @@ void run_elections(time_t t) if (work->RunningElection) { send_election_dgram(subrec, work->work_group, work->ElectionCriterion, - t - StartupTime, myname); + t - StartupTime, global_myname); if (work->ElectionCount++ >= 4) { @@ -225,7 +225,7 @@ static BOOL win_election(struct work_record *work, int version, version, ELECTION_VERSION, criterion, mycriterion, timeup, mytimeup, - server_name, myname)); + server_name, global_myname)); if (version > ELECTION_VERSION) return(False); @@ -242,7 +242,7 @@ static BOOL win_election(struct work_record *work, int version, if (timeup < mytimeup) return(True); - if (strcasecmp(myname, server_name) > 0) + if (strcasecmp(global_myname, server_name) > 0) return(False); return(True); @@ -276,7 +276,7 @@ void process_election(struct subnet_record *subrec, struct packet_struct *p, cha return; } - if (!strequal(work->work_group, myworkgroup)) + if (!strequal(work->work_group, global_myworkgroup)) { DEBUG(3,("process_election: ignoring election request for workgroup %s on subnet %s as this \ is not my workgroup.\n", work->work_group, subrec->subnet_name )); diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 80057ef12c..62dc444e0c 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -26,8 +26,8 @@ extern int DEBUGLEVEL; -extern pstring myname; -extern fstring myworkgroup; +extern pstring global_myname; +extern fstring global_myworkgroup; extern BOOL found_lm_clients; #if 0 @@ -143,8 +143,8 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p * to be our primary workgroup name. */ - if(strequal(work_name, myname)) - work_name = myworkgroup; + if(strequal(work_name, global_myname)) + work_name = global_myworkgroup; /* * We are being very agressive here in adding a workgroup @@ -391,10 +391,10 @@ master - ignoring master announce.\n")); return; } - if((work = find_workgroup_on_subnet(subrec, myworkgroup)) == NULL) + if((work = find_workgroup_on_subnet(subrec, global_myworkgroup)) == NULL) { DEBUG(0,("process_master_browser_announce: Cannot find workgroup %s on subnet %s\n", - myworkgroup, subrec->subnet_name)); + global_myworkgroup, subrec->subnet_name)); return; } @@ -481,8 +481,8 @@ originate from OS/2 Warp client. Ignoring packet.\n")); * not needed in the LanMan announce code, but it won't hurt. */ - if(strequal(work_name, myname)) - work_name = myworkgroup; + if(strequal(work_name, global_myname)) + work_name = global_myworkgroup; /* * We are being very agressive here in adding a workgroup @@ -571,7 +571,7 @@ static void send_backup_list_response(struct subnet_record *subrec, /* We always return at least one name - our own. */ count = 1; - StrnCpy(p,myname,15); + StrnCpy(p,global_myname,15); strupper(p); p = skip_string(p,1); @@ -585,7 +585,7 @@ static void send_backup_list_response(struct subnet_record *subrec, if(count >= (unsigned int)max_number_requested) break; - if(strnequal(servrec->serv.name, myname,15)) + if(strnequal(servrec->serv.name, global_myname,15)) continue; if(!(servrec->serv.type & SV_TYPE_BACKUP_BROWSER)) @@ -610,7 +610,7 @@ static void send_backup_list_response(struct subnet_record *subrec, send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), - myname, 0, + global_myname, 0, send_to_name->name,0, sendto_ip, subrec->myip); } @@ -643,7 +643,7 @@ void process_get_backup_list_request(struct subnet_record *subrec, for the requested workgroup. That means it must be our workgroup. */ - if(strequal(workgroup_name, myworkgroup) == False) + if(strequal(workgroup_name, global_myworkgroup) == False) { DEBUG(7,("process_get_backup_list_request: Ignoring announce request for workgroup %s.\n", workgroup_name)); @@ -769,7 +769,7 @@ void process_announce_request(struct subnet_record *subrec, struct packet_struct namestr(&dgram->dest_name))); /* We only send announcement requests on our workgroup. */ - if(strequal(workgroup_name, myworkgroup) == False) + if(strequal(workgroup_name, global_myworkgroup) == False) { DEBUG(7,("process_announce_request: Ignoring announce request for workgroup %s.\n", workgroup_name)); @@ -806,7 +806,7 @@ void process_lm_announce_request(struct subnet_record *subrec, struct packet_str namestr(&dgram->dest_name))); /* We only send announcement requests on our workgroup. */ - if(strequal(workgroup_name, myworkgroup) == False) + if(strequal(workgroup_name, global_myworkgroup) == False) { DEBUG(7,("process_lm_announce_request: Ignoring announce request for workgroup %s.\n", workgroup_name)); diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index ae163c6014..e1c56f591f 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -29,7 +29,7 @@ #include "includes.h" extern int DEBUGLEVEL; -extern fstring myworkgroup; +extern fstring global_myworkgroup; /**************************************************************************** Send a name release response. @@ -102,7 +102,7 @@ subnet %s from owner IP %s\n", * names and *don't set the group bit* !!!!! */ - if( !group && !ismyip(owner_ip) && strequal(question->name, myworkgroup) && + if( !group && !ismyip(owner_ip) && strequal(question->name, global_myworkgroup) && ((question->name_type == 0x0) || (question->name_type == 0x1e))) { DEBUG(6,("process_name_release_request: FTP OnNet bug workaround. Ignoring \ @@ -290,20 +290,20 @@ We put our own names first, then in alphabetical order. static int status_compare(char *n1,char *n2) { - extern pstring myname; + extern pstring global_myname; int l1,l2,l3; /* It's a bit tricky because the names are space padded */ for (l1=0;l1<15 && n1[l1] && n1[l1] != ' ';l1++) ; for (l2=0;l2<15 && n2[l2] && n2[l2] != ' ';l2++) ; - l3 = strlen(myname); + l3 = strlen(global_myname); - if ((l1==l3) && strncmp(n1,myname,l3) == 0 && - (l2!=l3 || strncmp(n2,myname,l3) != 0)) + if ((l1==l3) && strncmp(n1,global_myname,l3) == 0 && + (l2!=l3 || strncmp(n2,global_myname,l3) != 0)) return -1; - if ((l2==l3) && strncmp(n2,myname,l3) == 0 && - (l1!=l3 || strncmp(n1,myname,l3) != 0)) + if ((l2==l3) && strncmp(n2,global_myname,l3) == 0 && + (l1!=l3 || strncmp(n1,global_myname,l3) != 0)) return 1; return memcmp(n1,n2,18); diff --git a/source3/nmbd/nmbd_logonnames.c b/source3/nmbd/nmbd_logonnames.c index 4128213f97..c5e2e6ca4f 100644 --- a/source3/nmbd/nmbd_logonnames.c +++ b/source3/nmbd/nmbd_logonnames.c @@ -27,8 +27,8 @@ extern int DEBUGLEVEL; extern pstring scope; -extern pstring myname; -extern fstring myworkgroup; +extern pstring global_myname; +extern fstring global_myworkgroup; extern char **my_netbios_names; extern struct in_addr ipzero; extern struct in_addr allones_ip; @@ -52,11 +52,11 @@ workgroup %s on subnet %s\n", fail_name->name, subrec->subnet_name)); return; } - if((servrec = find_server_in_workgroup( work, myname)) == NULL) + if((servrec = find_server_in_workgroup( work, global_myname)) == NULL) { DEBUG(0,("become_logon_server_fail: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - myname, fail_name->name, subrec->subnet_name)); + global_myname, fail_name->name, subrec->subnet_name)); work->log_state = LOGON_NONE; return; } @@ -92,11 +92,11 @@ workgroup %s on subnet %s\n", registered_name->name, subrec->subnet_name)); return; } - if((servrec = find_server_in_workgroup( work, myname)) == NULL) + if((servrec = find_server_in_workgroup( work, global_myname)) == NULL) { DEBUG(0,("become_logon_server_success: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - myname, registered_name->name, subrec->subnet_name)); + global_myname, registered_name->name, subrec->subnet_name)); work->log_state = LOGON_NONE; return; } @@ -147,17 +147,17 @@ void add_logon_names(void) for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { - struct work_record *work = find_workgroup_on_subnet(subrec, myworkgroup); + struct work_record *work = find_workgroup_on_subnet(subrec, global_myworkgroup); if (work && (work->log_state == LOGON_NONE)) { struct nmb_name nmbname; - make_nmb_name(&nmbname,myworkgroup,0x1c,scope); + make_nmb_name(&nmbname,global_myworkgroup,0x1c,scope); if (find_name_on_subnet(subrec, &nmbname, FIND_SELF_NAME) == NULL) { DEBUG(0,("add_domain_logon_names: At time %s attempting to become \ -logon server for workgroup %s on subnet %s\n", timestring(), myworkgroup, +logon server for workgroup %s on subnet %s\n", timestring(), global_myworkgroup, subrec->subnet_name)); become_logon_server(subrec, work); } diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index cf21fafd87..92ea3ea154 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -27,8 +27,7 @@ extern int DEBUGLEVEL; extern char **my_netbios_names; -extern pstring myname; -extern fstring myworkgroup; +extern fstring global_myworkgroup; extern pstring scope; extern uint16 samba_nb_type; /* Samba's NetBIOS type. */ @@ -58,10 +57,10 @@ BOOL register_my_workgroup_and_names(void) for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { /* Create the workgroup on the subnet. */ - if((work = create_workgroup_on_subnet(subrec, myworkgroup, PERMANENT_TTL)) == NULL) + if((work = create_workgroup_on_subnet(subrec, global_myworkgroup, PERMANENT_TTL)) == NULL) { DEBUG(0,("register_my_workgroup_and_names: Failed to create my workgroup %s on subnet %s. \ -Exiting.\n", myworkgroup, subrec->subnet_name)); +Exiting.\n", global_myworkgroup, subrec->subnet_name)); return False; } @@ -128,10 +127,10 @@ Exiting.\n", myworkgroup, subrec->subnet_name)); */ struct nmb_name nmbname; - make_nmb_name(&nmbname, myworkgroup, 0x0, scope); + make_nmb_name(&nmbname, global_myworkgroup, 0x0, scope); insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP); - make_nmb_name(&nmbname, myworkgroup, 0x1e, scope); + make_nmb_name(&nmbname, global_myworkgroup, 0x1e, scope); insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP); } } diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index a3e4208cdc..8eae5e0f1c 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -27,7 +27,7 @@ extern int DEBUGLEVEL; extern pstring scope; -extern fstring myworkgroup; +extern fstring global_myworkgroup; /**************************************************************************** Deal with a response packet when registering one of our names. @@ -73,7 +73,7 @@ name %s.\n", namestr(answer_name), namestr(question_name))); */ #if 1 /* OLD_SAMBA_SERVER_HACK */ - if((nmb->header.rcode == ACT_ERR) && strequal(myworkgroup, answer_name->name) && + if((nmb->header.rcode == ACT_ERR) && strequal(global_myworkgroup, answer_name->name) && (answer_name->name_type == 0x1b)) { /* Pretend we did not get this. */ diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index bc9fcb5921..f647687db8 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -28,8 +28,8 @@ extern int DEBUGLEVEL; -extern pstring myname; -extern fstring myworkgroup; +extern pstring global_myname; +extern fstring global_myworkgroup; /**************************************************************************** Process a domain logon packet @@ -68,7 +68,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); return; } - strcpy(my_name, myname); + strcpy(my_name, global_myname); strupper(my_name); code = SVAL(buf,0); @@ -145,7 +145,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); PutUniCode(q, my_name); /* PDC name */ q = skip_unicode_string(q, 1); - PutUniCode(q, myworkgroup); /* Domain name*/ + PutUniCode(q, global_myworkgroup); /* Domain name*/ q = skip_unicode_string(q, 1); SIVAL(q, 0, ntversion); q += 4; @@ -218,7 +218,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", else { DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n", - unistr(unicomp),inet_ntoa(p->ip), ascuser, reply_name, myworkgroup, + unistr(unicomp),inet_ntoa(p->ip), ascuser, reply_name, global_myworkgroup, SAMLOGON_R ,lmnttoken)); } diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index ceace36a61..6dae0d43e9 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -29,7 +29,6 @@ extern int ClientNMB; extern int DEBUGLEVEL; extern pstring scope; -extern pstring myname; extern struct in_addr ipzero; int num_response_packets = 0; diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index 48072650c2..3936b7e92e 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -28,8 +28,8 @@ #include "includes.h" extern int DEBUGLEVEL; -extern pstring myname; -extern fstring myworkgroup; +extern pstring global_myname; +extern fstring global_myworkgroup; extern char **my_netbios_names; extern int updatecount; extern BOOL found_lm_clients; @@ -54,7 +54,7 @@ void send_browser_reset(int reset_type, char *to_name, int to_type, struct in_ad p++; send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), - myname, 0x0, to_name, to_type, to_ip, FIRST_SUBNET->myip); + global_myname, 0x0, to_name, to_type, to_ip, FIRST_SUBNET->myip); } /**************************************************************************** @@ -79,12 +79,12 @@ to subnet %s\n", work->work_group, subrec->subnet_name)); CVAL(p,0) = work->token; /* (local) Unique workgroup token id. */ p++; - StrnCpy(p,myname,15); + StrnCpy(p,global_myname,15); strupper(p); p = skip_string(p,1); send_mailslot(False, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), - myname, 0x0, work->work_group,0x1e, subrec->bcast_ip, subrec->myip); + global_myname, 0x0, work->work_group,0x1e, subrec->bcast_ip, subrec->myip); } /**************************************************************************** @@ -169,14 +169,14 @@ static void send_local_master_announcement(struct subnet_record *subrec, struct uint32 type = servrec->serv.type & ~SV_TYPE_LOCAL_LIST_ONLY; DEBUG(3,("send_local_master_announcement: type %x for name %s on subnet %s for workgroup %s\n", - type, myname, subrec->subnet_name, work->work_group)); + type, global_myname, subrec->subnet_name, work->work_group)); send_announcement(subrec, ANN_LocalMasterAnnouncement, - myname, /* From nbt name. */ + global_myname, /* From nbt name. */ work->work_group, 0x1e, /* To nbt name. */ subrec->bcast_ip, /* To ip. */ work->announce_interval, /* Time until next announce. */ - myname, /* Name to announce. */ + global_myname, /* Name to announce. */ type, /* Type field. */ servrec->serv.comment); } @@ -191,13 +191,13 @@ static void send_workgroup_announcement(struct subnet_record *subrec, struct wor subrec->subnet_name, work->work_group)); send_announcement(subrec, ANN_DomainAnnouncement, - myname, /* From nbt name. */ + global_myname, /* From nbt name. */ MSBROWSE, 0x1, /* To nbt name. */ subrec->bcast_ip, /* To ip. */ work->announce_interval, /* Time until next announce. */ work->work_group, /* Name to announce. */ SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT, /* workgroup announce flags. */ - myname); /* From name as comment. */ + global_myname); /* From name as comment. */ } /**************************************************************************** @@ -256,7 +256,7 @@ static void announce_server(struct subnet_record *subrec, struct work_record *wo /* Only do domain announcements if we are a master and it's our primary name we're being asked to announce. */ - if (AM_LOCAL_MASTER_BROWSER(work) && strequal(myname,servrec->serv.name)) + if (AM_LOCAL_MASTER_BROWSER(work) && strequal(global_myname,servrec->serv.name)) { send_local_master_announcement(subrec, work, servrec); send_workgroup_announcement(subrec, work); @@ -278,7 +278,7 @@ void announce_my_server_names(time_t t) for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { - struct work_record *work = find_workgroup_on_subnet(subrec, myworkgroup); + struct work_record *work = find_workgroup_on_subnet(subrec, global_myworkgroup); if(work) { @@ -342,7 +342,7 @@ void announce_my_lm_server_names(time_t t) for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { - struct work_record *work = find_workgroup_on_subnet(subrec, myworkgroup); + struct work_record *work = find_workgroup_on_subnet(subrec, global_myworkgroup); if(work) { @@ -512,7 +512,7 @@ void announce_remote(time_t t) if (wgroup) *wgroup++ = 0; if (!wgroup || !*wgroup) - wgroup = myworkgroup; + wgroup = global_myworkgroup; addr = *interpret_addr2(s2); @@ -568,17 +568,17 @@ void browse_sync_remote(time_t t) * for our workgroup on the firsst subnet. */ - if((work = find_workgroup_on_subnet(FIRST_SUBNET, myworkgroup)) == NULL) + if((work = find_workgroup_on_subnet(FIRST_SUBNET, global_myworkgroup)) == NULL) { DEBUG(0,("browse_sync_remote: Cannot find workgroup %s on subnet %s\n", - myworkgroup, FIRST_SUBNET->subnet_name )); + global_myworkgroup, FIRST_SUBNET->subnet_name )); return; } if(!AM_LOCAL_MASTER_BROWSER(work)) { DEBUG(5,("browse_sync_remote: We can only do this if we are a local master browser \ -for workgroup %s on subnet %s.\n", myworkgroup, FIRST_SUBNET->subnet_name )); +for workgroup %s on subnet %s.\n", global_myworkgroup, FIRST_SUBNET->subnet_name )); return; } @@ -587,7 +587,7 @@ for workgroup %s on subnet %s.\n", myworkgroup, FIRST_SUBNET->subnet_name )); CVAL(p,0) = ANN_MasterAnnouncement; p++; - StrnCpy(p,myname,15); + StrnCpy(p,global_myname,15); strupper(p); p = skip_string(p,1); @@ -597,9 +597,9 @@ for workgroup %s on subnet %s.\n", myworkgroup, FIRST_SUBNET->subnet_name )); addr = *interpret_addr2(s2); DEBUG(5,("announce_remote: Doing remote browse sync announce for server %s to IP %s.\n", - myname, inet_ntoa(addr) )); + global_myname, inet_ntoa(addr) )); send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), - myname, 0x0, "*", 0x0, addr, FIRST_SUBNET->myip); + global_myname, 0x0, "*", 0x0, addr, FIRST_SUBNET->myip); } } diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index e94cb1da6e..ea1948cece 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -29,8 +29,7 @@ extern int ClientNMB; extern int DEBUGLEVEL; -extern pstring myname; -extern fstring myworkgroup; +extern fstring global_myworkgroup; extern char **my_netbios_names; int updatecount = 0; @@ -259,7 +258,7 @@ static uint32 write_this_server_name( struct subnet_record *subrec, /******************************************************************* Decide if we should write out a workgroup record for this workgroup. - We return zero if we should not. Don't write out myworkgroup (we've + We return zero if we should not. Don't write out global_myworkgroup (we've already done it) and also don't write out a second workgroup record on the unicast subnet that we've already written out on one of the broadcast subnets. @@ -270,7 +269,7 @@ static uint32 write_this_workgroup_name( struct subnet_record *subrec, { struct subnet_record *ssub; - if(strequal(myworkgroup, work->work_group)) + if(strequal(global_myworkgroup, work->work_group)) return 0; /* This is a workgroup we have seen on a broadcast subnet. All @@ -358,10 +357,10 @@ void write_browse_list(time_t t, BOOL force_write) * subnet. */ - if((work = find_workgroup_on_subnet(FIRST_SUBNET, myworkgroup)) == NULL) + if((work = find_workgroup_on_subnet(FIRST_SUBNET, global_myworkgroup)) == NULL) { DEBUG(0,("write_browse_list: Fatal error - cannot find my workgroup %s\n", - myworkgroup)); + global_myworkgroup)); fclose(fp); return; } @@ -386,7 +385,7 @@ void write_browse_list(time_t t, BOOL force_write) stype = 0; for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { - if((work = find_workgroup_on_subnet( subrec, myworkgroup )) == NULL) + if((work = find_workgroup_on_subnet( subrec, global_myworkgroup )) == NULL) continue; if((servrec = find_server_in_workgroup( work, my_netbios_names[i])) == NULL) continue; @@ -400,7 +399,7 @@ void write_browse_list(time_t t, BOOL force_write) fprintf(fp, "%08x ", stype); sprintf(tmp, "\"%s\" ", lp_serverstring()); fprintf(fp, "%-30s", tmp); - fprintf(fp, "\"%s\"\n", myworkgroup); + fprintf(fp, "\"%s\"\n", global_myworkgroup); } for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index d8e8dd4ab9..34287bbe69 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -33,7 +33,6 @@ extern int global_nmb_port; extern int DEBUGLEVEL; -extern pstring myname; extern fstring myworkgroup; extern char **my_netbios_names; extern struct in_addr ipzero; diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index b834525747..0b392680df 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -29,8 +29,8 @@ extern int ClientNMB; extern int DEBUGLEVEL; -extern pstring myname; -extern fstring myworkgroup; +extern pstring global_myname; +extern fstring global_myworkgroup; extern char **my_netbios_names; extern uint16 samba_nb_type; extern struct in_addr ipzero; @@ -246,7 +246,7 @@ void initiate_myworkgroup_startup(struct subnet_record *subrec, struct work_reco { int i; - if(!strequal(myworkgroup, work->work_group)) + if(!strequal(global_myworkgroup, work->work_group)) return; /* If this is a broadcast subnet then start elections on it @@ -264,11 +264,11 @@ workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name)); /* Register the WORKGROUP<0> and WORKGROUP<1e> names on the network. */ - register_name(subrec,myworkgroup,0x0,samba_nb_type|NB_GROUP, + register_name(subrec,global_myworkgroup,0x0,samba_nb_type|NB_GROUP, NULL, fail_register,NULL); - register_name(subrec,myworkgroup,0x1e,samba_nb_type|NB_GROUP, + register_name(subrec,global_myworkgroup,0x1e,samba_nb_type|NB_GROUP, NULL, fail_register,NULL); @@ -278,7 +278,7 @@ workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name)); int stype = lp_default_server_announce() | (lp_local_master() ? SV_TYPE_POTENTIAL_BROWSER : 0 ); - if(!strequal(myname, name)) + if(!strequal(global_myname, name)) stype &= ~(SV_TYPE_MASTER_BROWSER|SV_TYPE_POTENTIAL_BROWSER| SV_TYPE_DOMAIN_MASTER|SV_TYPE_DOMAIN_MEMBER); -- cgit From 19f76f391b97b405879fd8574e711a6d59e4e60c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 5 May 1998 19:24:32 +0000 Subject: genrand.c: SGI compile warning fix. ipc.c: Fix for duplicate printer names being long. loadparm.c: Set bNetWkstaUserLogon to false by default - new code in password.c protects us. nmbd_logonnames.c: nmbd_namequery.c: nmbd_namerelease.c: Debug messages fix. password.c: SGI compile warning fix, fix for tcon() with bNetWkstaUserLogon call. reply.c: SGI compile warning fix. server.c Debug messages fix. smbpass.c: Fix for incorrect pointer. Jeremy. (This used to be commit 567d3f838988cafab4770fce1cf68b73085e6c71) --- source3/nmbd/nmbd_logonnames.c | 2 +- source3/nmbd/nmbd_namequery.c | 2 +- source3/nmbd/nmbd_namerelease.c | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_logonnames.c b/source3/nmbd/nmbd_logonnames.c index c5e2e6ca4f..dbbb8defaf 100644 --- a/source3/nmbd/nmbd_logonnames.c +++ b/source3/nmbd/nmbd_logonnames.c @@ -114,7 +114,7 @@ in workgroup %s on subnet %s\n", /* Tell the namelist writer to write out a change. */ subrec->work_changed = True; - DEBUG(0,("become_logon_server_success: Samba is now a logon server\ + DEBUG(0,("become_logon_server_success: Samba is now a logon server \ for workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name)); } diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index 1794efe890..509b3b3107 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -76,7 +76,7 @@ from IP %s for name %s. Error code was %d.\n", subrec->subnet_name, inet_ntoa(p- success = True; putip((char *)&answer_ip,&nmb->answers->rdata[2]); - DEBUG(5,("query_name_response: On subnet %s - positive response from IP %s\ + DEBUG(5,("query_name_response: On subnet %s - positive response from IP %s \ for name %s. IP of that name is %s\n", subrec->subnet_name, inet_ntoa(p->ip), namestr(question_name), inet_ntoa(answer_ip))); diff --git a/source3/nmbd/nmbd_namerelease.c b/source3/nmbd/nmbd_namerelease.c index b2f9b47878..f72de8c20e 100644 --- a/source3/nmbd/nmbd_namerelease.c +++ b/source3/nmbd/nmbd_namerelease.c @@ -60,7 +60,7 @@ name %s.\n", namestr(answer_name), namestr(question_name))); if(bcast) { /* Someone sent a response. This shouldn't happen/ */ - DEBUG(1,("release_name_response: A response for releasing name %s was received on a\ + DEBUG(1,("release_name_response: A response for releasing name %s was received on a \ broadcast subnet %s. This should not happen !\n", namestr(answer_name), subrec->subnet_name)); return; } -- cgit From d8d9f7723337c267a8740750fe19a6387cfbb1f6 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Thu, 7 May 1998 18:19:05 +0000 Subject: created "passdb.c" which is an interface point to (at present) either smbpasswd or ldap passwd, at compile-time (-DUSE_LDAP). _none_ of the functions in ldap.c or smbpass.c should be called directly: only those in passdb.c should be used. -DUSE_LDAP is unlikely to compile at the moment. (This used to be commit 57b01ad4ffb14ebd600d4e66602b54ed987f6106) --- source3/nmbd/nmbd_processlogon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index f647687db8..50b6052c67 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -201,7 +201,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", strcpy(reply_name,"\\\\"); /* Here it wants \\LOGONSERVER. */ strcpy(reply_name+2,my_name); - smb_pass = getsmbpwnam(ascuser); + smb_pass = getsampwnam(ascuser); if(!smb_pass ) { -- cgit From 3dfc0c847240ac7e12c39f4ed9c31a888949ade1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 11 May 1998 06:38:36 +0000 Subject: changed to use slprintf() instead of sprintf() just about everywhere. I've implemented slprintf() as a bounds checked sprintf() using mprotect() and a non-writeable page. This should prevent any sprintf based security holes. (This used to be commit ee09e9dadb69aaba5a751dd20ccc6d587d841bd6) --- source3/nmbd/nmbd.c | 2 +- source3/nmbd/nmbd_serverlistdb.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 512504b02d..f9519bea18 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -619,7 +619,7 @@ int main(int argc,char *argv[]) strupper(global_myname); break; case 'l': - sprintf(debugf,"%s.nmb",optarg); + slprintf(debugf,sizeof(debugf)-1, "%s.nmb",optarg); break; case 'i': pstrcpy(scope,optarg); diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index ea1948cece..64ca49cdbc 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -365,10 +365,10 @@ void write_browse_list(time_t t, BOOL force_write) return; } - sprintf(tmp, "\"%s\"", work->work_group); + slprintf(tmp,sizeof(tmp)-1, "\"%s\"", work->work_group); fprintf(fp, "%-25s ", tmp); fprintf(fp, "%08x ", SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT|SV_TYPE_LOCAL_LIST_ONLY); - sprintf(tmp, "\"%s\" ", work->local_master_browser_name); + slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", work->local_master_browser_name); fprintf(fp, "%-30s", tmp); fprintf(fp, "\"%s\"\n", work->work_group); @@ -394,10 +394,10 @@ void write_browse_list(time_t t, BOOL force_write) } /* Output server details, plus what workgroup they're in. */ - sprintf(tmp, "\"%s\"", my_netbios_names[i]); + slprintf(tmp, sizeof(tmp)-1, "\"%s\"", my_netbios_names[i]); fprintf(fp, "%-25s ", tmp); fprintf(fp, "%08x ", stype); - sprintf(tmp, "\"%s\" ", lp_serverstring()); + slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", lp_serverstring()); fprintf(fp, "%-30s", tmp); fprintf(fp, "\"%s\"\n", global_myworkgroup); } @@ -413,11 +413,11 @@ void write_browse_list(time_t t, BOOL force_write) if(wg_type) { - sprintf(tmp, "\"%s\"", work->work_group); + slprintf(tmp, sizeof(tmp)-1, "\"%s\"", work->work_group); fprintf(fp, "%-25s ", tmp); fprintf(fp, "%08x ", wg_type); - sprintf(tmp, "\"%s\" ", work->local_master_browser_name); + slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", work->local_master_browser_name); fprintf(fp, "%-30s", tmp); fprintf(fp, "\"%s\"\n", work->work_group); } @@ -437,10 +437,10 @@ void write_browse_list(time_t t, BOOL force_write) if(serv_type) { /* Output server details, plus what workgroup they're in. */ - sprintf(tmp, "\"%s\"", servrec->serv.name); + slprintf(tmp, sizeof(tmp)-1, "\"%s\"", servrec->serv.name); fprintf(fp, "%-25s ", tmp); fprintf(fp, "%08x ", serv_type); - sprintf(tmp, "\"%s\" ", servrec->serv.comment); + slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", servrec->serv.comment); fprintf(fp, "%-30s", tmp); fprintf(fp, "\"%s\"\n", work->work_group); } -- cgit From f888868f46a5418bac9ab528497136c152895305 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 12 May 1998 00:55:32 +0000 Subject: This is a security audit change of the main source. It removed all ocurrences of the following functions : sprintf strcpy strcat The replacements are slprintf, safe_strcpy and safe_strcat. It should not be possible to use code in Samba that uses sprintf, strcpy or strcat, only the safe_equivalents. Once Andrew has fixed the slprintf implementation then this code will be moved back to the 1.9.18 code stream. Jeremy. (This used to be commit 2d774454005f0b54e5684cf618da7060594dfcbb) --- source3/nmbd/nmbd.c | 8 ++++---- source3/nmbd/nmbd_become_lmb.c | 4 ++-- source3/nmbd/nmbd_browsesync.c | 2 +- source3/nmbd/nmbd_incomingrequests.c | 2 +- source3/nmbd/nmbd_namelistdb.c | 6 +++--- source3/nmbd/nmbd_packets.c | 6 +++--- source3/nmbd/nmbd_processlogon.c | 18 +++++++++--------- source3/nmbd/nmbd_serverlistdb.c | 6 +++--- source3/nmbd/nmbd_winsserver.c | 18 +++++++++--------- 9 files changed, 35 insertions(+), 35 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index f9519bea18..39f5087497 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -133,7 +133,7 @@ static BOOL dump_core(void) pstrcpy( dname, debugf ); if ((p=strrchr(dname,'/'))) *p=0; - strcat( dname, "/corefiles" ); + pstrcat( dname, "/corefiles" ); mkdir( dname, 0700 ); sys_chown( dname, getuid(), getgid() ); chmod( dname, 0700 ); @@ -209,7 +209,7 @@ BOOL reload_services(BOOL test) BOOL ret; extern fstring remote_machine; - strcpy( remote_machine, "nmb" ); + fstrcpy( remote_machine, "nmb" ); if ( lp_loaded() ) { @@ -560,14 +560,14 @@ int main(int argc,char *argv[]) TimeInit(); - strcpy( debugf, NMBLOGFILE ); + pstrcpy( debugf, NMBLOGFILE ); setup_logging( argv[0], False ); charset_initialise(); #ifdef LMHOSTSFILE - strcpy( host_file, LMHOSTSFILE ); + pstrcpy( host_file, LMHOSTSFILE ); #endif /* this is for people who can't start the program correctly */ diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index c602789fb8..ffa3b38cba 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -276,7 +276,7 @@ in workgroup %s on subnet %s\n", userdata->copy_fn = NULL; userdata->free_fn = NULL; userdata->userdata_len = strlen(work->work_group)+1; - strcpy(userdata->data, work->work_group); + pstrcpy(userdata->data, work->work_group); /* Deregister any browser names we may have. */ make_nmb_name(&nmbname, MSBROWSE, 0x1, scope); @@ -528,7 +528,7 @@ in workgroup %s on subnet %s\n", userdata->copy_fn = NULL; userdata->free_fn = NULL; userdata->userdata_len = strlen(work->work_group)+1; - strcpy(userdata->data, work->work_group); + pstrcpy(userdata->data, work->work_group); /* Register the special browser group name. */ register_name(subrec, MSBROWSE, 0x01, samba_nb_type|NB_GROUP, diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index c78fdfc514..c1f6aa5a6c 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -420,7 +420,7 @@ workgroup %s\n", q_name->name )); userdata->copy_fn = NULL; userdata->free_fn = NULL; userdata->userdata_len = strlen(work->work_group)+1; - strcpy(userdata->data, work->work_group); + pstrcpy(userdata->data, work->work_group); node_status( subrec, &nmbname, answer_ip, domain_master_node_status_success, diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index e1c56f591f..02b511a363 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -362,7 +362,7 @@ subnet %s - name not found.\n", namestr(&nmb->question.question_name), { /* Start with the name. */ bzero(buf,18); - sprintf(buf,"%-15.15s",namerec->name.name); + slprintf(buf, 17, "%-15.15s",namerec->name.name); strupper(buf); /* Put the name type and netbios flags in the buffer. */ diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index b37cac10dc..07d026e051 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -553,14 +553,14 @@ static void dump_subnet_namelist( struct subnet_record *subrec, FILE *fp) void dump_all_namelists(void) { - fstring fname; + pstring fname; FILE *fp; struct subnet_record *subrec; pstrcpy(fname,lp_lockdir()); trim_string(fname,NULL,"/"); - strcat(fname,"/"); - strcat(fname,"namelist.debug"); + pstrcat(fname,"/"); + pstrcat(fname,"namelist.debug"); fp = fopen(fname,"w"); diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 54f4f3a2cb..b62f0aff62 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -335,9 +335,9 @@ static BOOL initiate_multihomed_name_register_packet( struct packet_struct *pack uint16 nb_flags, struct in_addr *register_ip) { struct nmb_packet *nmb = &packet->packet.nmb; - char second_ip_buf[25]; + fstring second_ip_buf; - strcpy(second_ip_buf, inet_ntoa(packet->ip)); + fstrcpy(second_ip_buf, inet_ntoa(packet->ip)); nmb->header.opcode = NMB_NAME_MULTIHOMED_REG_OPCODE; nmb->header.arcount = 1; @@ -1914,7 +1914,7 @@ BOOL send_mailslot(BOOL unique, char *mailslot,char *buf,int len, SSVAL(ptr,smb_vwv15,1); SSVAL(ptr,smb_vwv16,2); p2 = smb_buf(ptr); - strcpy(p2,mailslot); + pstrcpy(p2,mailslot); p2 = skip_string(p2,1); memcpy(p2,buf,len); diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 50b6052c67..631b8ff01f 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -68,7 +68,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); return; } - strcpy(my_name, global_myname); + pstrcpy(my_name, global_myname); strupper(my_name); code = SVAL(buf,0); @@ -89,7 +89,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); token = SVAL(q,3); reply_code = 0x6; - strcpy(reply_name,my_name); + fstrcpy(reply_name,my_name); add_slashes = True; DEBUG(3,("process_logon_packet: Domain login request from %s at IP %s user=%s token=%x\n", @@ -98,9 +98,9 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); q = outbuf; SSVAL(q, 0, 6); q += 2; - strcpy(reply_name, "\\\\"); - strcat(reply_name, my_name); - strcpy(q, reply_name); q = skip_string(q, 1); /* PDC name */ + fstrcpy(reply_name, "\\\\"); + fstrcat(reply_name, my_name); + fstrcpy(q, reply_name); q = skip_string(q, 1); /* PDC name */ SSVAL(q, 0, token); q += 2; @@ -137,8 +137,8 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); q = outbuf; SSVAL(q, 0, QUERYFORPDC_R); q += 2; - strcpy(reply_name,my_name); - strcpy(q, reply_name); q = skip_string(q, 1); /* PDC name */ + fstrcpy(reply_name,my_name); + fstrcpy(q, reply_name); q = skip_string(q, 1); /* PDC name */ if (strcmp(mailslot, NT_LOGON_MAILSLOT)==0) { q = align2(q, buf); @@ -198,8 +198,8 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", pstrcpy(ascuser, unistr(uniuser)); DEBUG(3,("process_logon_packet: SAMLOGON user %s\n", ascuser)); - strcpy(reply_name,"\\\\"); /* Here it wants \\LOGONSERVER. */ - strcpy(reply_name+2,my_name); + fstrcpy(reply_name,"\\\\"); /* Here it wants \\LOGONSERVER. */ + fstrcpy(reply_name+2,my_name); smb_pass = getsampwnam(ascuser); diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index 64ca49cdbc..6ff6ad5c5d 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -338,10 +338,10 @@ void write_browse_list(time_t t, BOOL force_write) pstrcpy(fname,lp_lockdir()); trim_string(fname,NULL,"/"); - strcat(fname,"/"); - strcat(fname,SERVER_LIST); + pstrcat(fname,"/"); + pstrcat(fname,SERVER_LIST); pstrcpy(fnamenew,fname); - strcat(fnamenew,"."); + pstrcat(fnamenew,"."); fp = fopen(fnamenew,"w"); diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index d089686917..acab815926 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -116,7 +116,7 @@ Load or create the WINS database. BOOL initialise_wins(void) { - fstring fname; + pstring fname; time_t time_now = time(NULL); FILE *fp; pstring line; @@ -131,10 +131,10 @@ BOOL initialise_wins(void) start_async_dns(); #endif - fstrcpy(fname,lp_lockdir()); + pstrcpy(fname,lp_lockdir()); trim_string(fname,NULL,"/"); - strcat(fname,"/"); - strcat(fname,WINS_LIST); + pstrcat(fname,"/"); + pstrcat(fname,WINS_LIST); if((fp = fopen(fname,"r")) == NULL) { @@ -1515,7 +1515,7 @@ void initiate_wins_processing(time_t t) void wins_write_database(void) { struct name_record *namerec; - fstring fname, fnamenew; + pstring fname, fnamenew; FILE *fp; @@ -1524,10 +1524,10 @@ void wins_write_database(void) fstrcpy(fname,lp_lockdir()); trim_string(fname,NULL,"/"); - strcat(fname,"/"); - strcat(fname,WINS_LIST); - fstrcpy(fnamenew,fname); - strcat(fnamenew,"."); + pstrcat(fname,"/"); + pstrcat(fname,WINS_LIST); + pstrcpy(fnamenew,fname); + pstrcat(fnamenew,"."); if((fp = fopen(fnamenew,"w")) == NULL) { -- cgit From ee9a61841ac10d32d869a3893bc690c66f2bb1bb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 12 May 1998 22:11:24 +0000 Subject: includes.h: SunOS doesn't have strcasecmp, solaris versions prior to 2.6 don't have vsnprintf. locking_slow.c: slight tidy. make_smbcodepage.c: Use safe_strcpy instead of pstrcpy. nmbd_winsserver.c: Use pstrcpy instead of fstrcpy. smbmount.c: Fixed reported bug. util.c: Removed old fstrcpy/fstrcat functions. Jeremy. (This used to be commit f257d2e4bafd3944cca737699913a8d868279ca6) --- source3/nmbd/nmbd_winsserver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index acab815926..e1f0fbae8f 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1522,7 +1522,7 @@ void wins_write_database(void) if(!lp_we_are_a_wins_server()) return; - fstrcpy(fname,lp_lockdir()); + pstrcpy(fname,lp_lockdir()); trim_string(fname,NULL,"/"); pstrcat(fname,"/"); pstrcat(fname,WINS_LIST); -- cgit From ffab54750f0eec202895670dd9293ee4aa3eb475 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 18 May 1998 21:30:57 +0000 Subject: chgpasswd.c: Changed back to getsmb... from getsam... ldap.c: Stoped dummy_function being prototyped. loadparm.c: Fixed slprintf sizes. nisppass.c: Fixed safe_strcpy sizes. nmbd_processlogon.c: Changed back to getsmb... from getsam... nttrans.c: Just a dump of new code. passdb.c: Moved stuff around a lot - stopped any lookups by rid. This needs to be indirected through a function table (soon). password.c: Changed back to getsmb... from getsam... reply.c: Changed back to getsmb... from getsam... slprintf.c: Fixed prototype problems. smb.h: Fixed prototype problems. smbpass.c: Changed to getsmbfile.... smbpasswd.c: Changed back to getsmb... from getsam... lib/rpc/server/srv_netlog.c: Changed back to getsmb... from getsam... lib/rpc/server/srv_samr.c: Fixed rid lookup - use uid or gid lookup. lib/rpc/server/srv_util.c: Changed back to getsmb... from getsam... Jeremy. (This used to be commit 7d332b2493d2089d09521250fc9b72d8953307c0) --- source3/nmbd/nmbd_processlogon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 631b8ff01f..2ad4a831ca 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -201,7 +201,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", fstrcpy(reply_name,"\\\\"); /* Here it wants \\LOGONSERVER. */ fstrcpy(reply_name+2,my_name); - smb_pass = getsampwnam(ascuser); + smb_pass = getsmbpwnam(ascuser); if(!smb_pass ) { -- cgit From d9e4b23674e4084b2fd88a5b2e3b0ffea752568a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 19 May 1998 04:45:40 +0000 Subject: Forgot to add the initialize_password_db() call to nmbd also. Jeremy. (This used to be commit 2f9f0a88e8220575edb43a9945d0b60829efa840) --- source3/nmbd/nmbd.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 39f5087497..1bb7ed55e4 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -566,6 +566,9 @@ int main(int argc,char *argv[]) charset_initialise(); + if(!initialize_password_db()) + exit(1); + #ifdef LMHOSTSFILE pstrcpy( host_file, LMHOSTSFILE ); #endif -- cgit From f3e26636452de78e1acb68de3823fe031aee4b3e Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Mon, 8 Jun 1998 03:44:13 +0000 Subject: Cosmetic. Added a cast to (void) to a call to add_name_to_subnet() since the return value was being ignored anyway. SGI's lint said: function returns value which is sometimes ignored add_name_to_subnet Chris -)----- (This used to be commit ae706bff10cc77f06b8069e637ec9768d6a46966) --- source3/nmbd/asyncdns.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 6019819793..3d2d5303de 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -35,16 +35,16 @@ static struct name_record *add_dns_result(struct nmb_name *question, struct in_a if (!addr.s_addr) { /* add the fail to WINS cache of names. give it 1 hour in the cache */ DEBUG(3,("add_dns_result: Negative DNS answer for %s\n", qname)); - add_name_to_subnet(wins_server_subnet,qname,name_type, - NB_ACTIVE, 60*60, DNSFAIL_NAME, 1, &addr); - return NULL; + (void)add_name_to_subnet( wins_server_subnet, qname, name_type, + NB_ACTIVE, 60*60, DNSFAIL_NAME, 1, &addr ); + return( NULL ); } /* add it to our WINS cache of names. give it 2 hours in the cache */ DEBUG(3,("add_dns_result: DNS gave answer for %s of %s\n", qname, inet_ntoa(addr))); - return add_name_to_subnet(wins_server_subnet,qname,name_type, - NB_ACTIVE, 2*60*60, DNS_NAME, 1, &addr); + return( add_name_to_subnet( wins_server_subnet, qname, name_type, + NB_ACTIVE, 2*60*60, DNS_NAME, 1, &addr ) ); } -- cgit From 072504985973be17f64a23aaaa99a8d3ef5b2ea6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 8 Jun 1998 19:09:47 +0000 Subject: Added code to add the Samba names onto the remote_broadcast subnet, as NT 4.x does directed broadcast node status requests for the *<0x0> name. Jeremy. (This used to be commit 8c6fe8870a72271a6acd1633efc362c59e283e19) --- source3/nmbd/nmbd_mynames.c | 13 +++++++++---- source3/nmbd/nmbd_namelistdb.c | 3 ++- 2 files changed, 11 insertions(+), 5 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index 92ea3ea154..2bb8f775d0 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -64,8 +64,7 @@ Exiting.\n", global_myworkgroup, subrec->subnet_name)); return False; } - /* Each subnet entry, except for the remote_announce_broadcast subnet - and the wins_server_subnet has the magic Samba names. */ + /* Each subnet entry, except for the wins_server_subnet has the magic Samba names. */ add_samba_names_to_subnet(subrec); /* Register all our names including aliases. */ @@ -135,6 +134,12 @@ Exiting.\n", global_myworkgroup, subrec->subnet_name)); } } + /* + * We need to add the Samba names to the remote broadcast subnet, + * as NT 4.x does directed broadcast requests to the *<0x0> name. + */ + add_samba_names_to_subnet(remote_broadcast_subnet); + return True; } @@ -185,8 +190,8 @@ void refresh_my_names(time_t t) */ if(!is_refresh_already_queued( subrec, namerec)) refresh_name(subrec, namerec, NULL, NULL, NULL); - namerec->death_time += lp_max_ttl(); - namerec->refresh_time += lp_max_ttl(); + namerec->death_time += lp_max_ttl(); + namerec->refresh_time += lp_max_ttl(); } } } diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 07d026e051..897505ca2b 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -445,7 +445,8 @@ void add_samba_names_to_subnet(struct subnet_record *subrec) /* These names are added permanently (ttl of zero) and will NOT be refreshed. */ - if((subrec == unicast_subnet) || (subrec == wins_server_subnet)) + if((subrec == unicast_subnet) || (subrec == wins_server_subnet) || + (subrec == remote_broadcast_subnet) ) { struct subnet_record *bcast_subrecs; int i; -- cgit From 96bc4042779570e6239b2626888ea0ca9be17391 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Tue, 9 Jun 1998 01:56:18 +0000 Subject: This is a first step toward moving long namelists into a database. I split the name_record structure into pieces. The goal is that the key (the name) be separate from the data associated with the key. Databases such as gdbm store information in [key,content] pairs. There is no functional change in with this update. It's just a step in the direction that Jeremy and I have been discussing. Chris -)----- (This used to be commit e420a4bd7d368a0e910893400fb7b46ab8694a08) --- source3/nmbd/nmbd_become_lmb.c | 2 +- source3/nmbd/nmbd_incomingrequests.c | 76 +++++++----- source3/nmbd/nmbd_lmhosts.c | 2 +- source3/nmbd/nmbd_mynames.c | 16 +-- source3/nmbd/nmbd_namelistdb.c | 231 ++++++++++++++++++++--------------- source3/nmbd/nmbd_namequery.c | 20 +-- source3/nmbd/nmbd_nameregister.c | 10 +- source3/nmbd/nmbd_namerelease.c | 20 +-- source3/nmbd/nmbd_packets.c | 2 +- source3/nmbd/nmbd_winsproxy.c | 14 ++- source3/nmbd/nmbd_winsserver.c | 121 ++++++++++-------- 11 files changed, 292 insertions(+), 222 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index ffa3b38cba..b97da7d8b4 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -67,7 +67,7 @@ static void remove_permanent_name_from_unicast( struct subnet_record *subrec, { /* Remove this broadcast subnet IP address from the name. */ remove_ip_from_name_record( namerec, subrec->myip); - if(namerec->num_ips == 0) + if(namerec->data.num_ips == 0) remove_name_from_namelist( unicast_subnet, namerec); } } diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index 02b511a363..d05036b3ee 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -114,7 +114,9 @@ group release name %s from IP %s on subnet %s with no group bit set.\n", namerec = find_name_on_subnet(subrec, &nmb->question.question_name, FIND_ANY_NAME); /* We only care about someone trying to release one of our names. */ - if (namerec && ((namerec->source == SELF_NAME) || (namerec->source == PERMANENT_NAME))) + if( namerec + && ( (namerec->data.source == SELF_NAME) + || (namerec->data.source == PERMANENT_NAME) ) ) { rcode = ACT_ERR; DEBUG(0, ("process_name_release_request: Attempt to release name %s from IP %s \ @@ -236,7 +238,7 @@ IP %s on subnet %s\n", namestr(question), inet_ntoa(from_ip), subrec->subnet_nam * later to queries. */ - if((namerec != NULL) && (namerec->source == WINS_PROXY_NAME)) + if((namerec != NULL) && (namerec->data.source == WINS_PROXY_NAME)) { remove_name_from_namelist( subrec, namerec ); namerec = NULL; @@ -246,10 +248,10 @@ IP %s on subnet %s\n", namestr(question), inet_ntoa(from_ip), subrec->subnet_nam { /* Unique name. */ - if ((namerec != NULL) && - ((namerec->source == SELF_NAME) || (namerec->source == PERMANENT_NAME) || - NAME_GROUP(namerec)) - ) + if( (namerec != NULL) + && ( (namerec->data.source == SELF_NAME) + || (namerec->data.source == PERMANENT_NAME) + || NAME_GROUP(namerec) ) ) { /* No-one can register one of Samba's names, nor can they register a name that's a group name as a unique name */ @@ -260,7 +262,7 @@ IP %s on subnet %s\n", namestr(question), inet_ntoa(from_ip), subrec->subnet_nam else if(namerec != NULL) { /* Update the namelist record with the new information. */ - namerec->ip[0] = from_ip; + namerec->data.ip[0] = from_ip; update_name_ttl(namerec, ttl); DEBUG(3,("process_name_registration_request: Updated name record %s \ @@ -272,9 +274,10 @@ with IP %s on subnet %s\n",namestr(&namerec->name),inet_ntoa(from_ip), subrec->s { /* Group name. */ - if((namerec != NULL) && !NAME_GROUP(namerec) && - ((namerec->source == SELF_NAME) || (namerec->source == PERMANENT_NAME)) - ) + if( (namerec != NULL) + && !NAME_GROUP(namerec) + && ( (namerec->data.source == SELF_NAME) + || (namerec->data.source == PERMANENT_NAME) ) ) { /* Disallow group names when we have a unique name. */ send_name_registration_response(ACT_ERR, 0, p); @@ -350,7 +353,8 @@ subnet %s - name not found.\n", namestr(&nmb->question.question_name), while (buf < bufend) { - if ((namerec->source == SELF_NAME) || (namerec->source == PERMANENT_NAME)) + if( (namerec->data.source == SELF_NAME) + || (namerec->data.source == PERMANENT_NAME) ) { int name_type = namerec->name.name_type; @@ -367,19 +371,19 @@ subnet %s - name not found.\n", namestr(&nmb->question.question_name), /* Put the name type and netbios flags in the buffer. */ buf[15] = name_type; - set_nb_flags(&buf[16],namerec->nb_flags); + set_nb_flags( &buf[16],namerec->data.nb_flags ); buf[16] |= NB_ACTIVE; /* all our names are active */ buf += 18; - + names_added++; } } /* Remove duplicate names. */ - qsort(buf0,names_added,18,QSORT_CAST status_compare); + qsort( buf0, names_added, 18, QSORT_CAST status_compare ); - for (i=1;ideath_time != PERMANENT_TTL) && (namerec->death_time < p->timestamp))) + if( namerec + && ( (namerec->data.death_time != PERMANENT_TTL) + && (namerec->data.death_time < p->timestamp) ) ) { DEBUG(5,("process_name_query_request: expired name %s\n", namestr(&namerec->name))); namerec = NULL; @@ -487,11 +493,17 @@ void process_name_query_request(struct subnet_record *subrec, struct packet_stru * into the namelist if we were configured as a WINS proxy. */ - if (!bcast || - (bcast && ((name_type == 0x1b) || (namerec->source == SELF_NAME) || - (namerec->source == PERMANENT_NAME) || - ((namerec->source == WINS_PROXY_NAME) && ((name_type == 0) || (name_type == 0x20))))) - ) + if( !bcast + || ( bcast + && ( (name_type == 0x1b) + || (namerec->data.source == SELF_NAME) + || (namerec->data.source == PERMANENT_NAME) + || ( (namerec->data.source == WINS_PROXY_NAME) + && ( (name_type == 0) || (name_type == 0x20) ) + ) + ) + ) + ) { /* The requested name is a directed query, or it's SELF or PERMANENT or WINS_PROXY, @@ -505,11 +517,11 @@ void process_name_query_request(struct subnet_record *subrec, struct packet_stru * replies to a broadcast query. */ - if(namerec->source == WINS_PROXY_NAME) + if( namerec->data.source == WINS_PROXY_NAME ) { - for( i = 0; i < namerec->num_ips; i++) + for( i = 0; i < namerec->data.num_ips; i++) { - if(same_net( namerec->ip[i], subrec->myip, subrec->mask_ip )) + if(same_net( namerec->data.ip[i], subrec->myip, subrec->mask_ip )) { DEBUG(5,("process_name_query_request: name %s is a WINS proxy name and is also \ on the same subnet (%s) as the requestor. Not replying.\n", @@ -519,30 +531,30 @@ on the same subnet (%s) as the requestor. Not replying.\n", } } - ttl = (namerec->death_time != PERMANENT_TTL) ? - namerec->death_time - p->timestamp : lp_max_ttl(); + ttl = (namerec->data.death_time != PERMANENT_TTL) ? + namerec->data.death_time - p->timestamp : lp_max_ttl(); /* Copy all known ip addresses into the return data. */ /* Optimise for the common case of one IP address so we don't need a malloc. */ - if(namerec->num_ips == 1 ) + if( namerec->data.num_ips == 1 ) prdata = rdata; else { - if((prdata = (char *)malloc( namerec->num_ips * 6 )) == NULL) + if((prdata = (char *)malloc( namerec->data.num_ips * 6 )) == NULL) { DEBUG(0,("process_name_query_request: malloc fail !\n")); return; } } - for( i = 0; i < namerec->num_ips; i++) + for( i = 0; i < namerec->data.num_ips; i++ ) { - set_nb_flags(&prdata[i*6],namerec->nb_flags); - putip((char *)&prdata[2+(i*6)], &namerec->ip[i]); + set_nb_flags(&prdata[i*6],namerec->data.nb_flags); + putip((char *)&prdata[2+(i*6)], &namerec->data.ip[i]); } - reply_data_len = namerec->num_ips * 6; + reply_data_len = namerec->data.num_ips * 6; success = True; } } diff --git a/source3/nmbd/nmbd_lmhosts.c b/source3/nmbd/nmbd_lmhosts.c index 206c2367b1..f4d520b1cf 100644 --- a/source3/nmbd/nmbd_lmhosts.c +++ b/source3/nmbd/nmbd_lmhosts.c @@ -93,7 +93,7 @@ BOOL find_name_in_lmhosts(struct nmb_name *nmbname, struct name_record **namerec FIND_ANY_NAME))==NULL) return False; - if(!NAME_IS_ACTIVE(namerec) || (namerec->source != LMHOSTS_NAME)) + if(!NAME_IS_ACTIVE(namerec) || (namerec->data.source != LMHOSTS_NAME)) return False; *namerecp = namerec; diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index 2bb8f775d0..f0330c00b7 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -158,7 +158,8 @@ void release_my_names(void) for (namerec = subrec->namelist; namerec; namerec = nextnamerec) { nextnamerec = namerec->next; - if ((namerec->source == SELF_NAME) && !NAME_IS_DEREGISTERING(namerec)) + if( (namerec->data.source == SELF_NAME) + && !NAME_IS_DEREGISTERING(namerec) ) release_name(subrec, namerec, standard_success_release, NULL, NULL); } @@ -180,18 +181,19 @@ void refresh_my_names(time_t t) for (namerec = subrec->namelist; namerec; namerec = namerec->next) { /* Each SELF name has an individual time to be refreshed. */ - if ((namerec->source == SELF_NAME) && (namerec->refresh_time < t) && - (namerec->death_time != PERMANENT_TTL)) + if( (namerec->data.source == SELF_NAME) + && (namerec->data.refresh_time < t) + && ( namerec->data.death_time != PERMANENT_TTL) ) { /* We cheat here and pretend the refresh is going to be successful & update the refresh times. This stops multiple refresh calls being done. We actually deal with refresh failure in the fail_fn. */ - if(!is_refresh_already_queued( subrec, namerec)) - refresh_name(subrec, namerec, NULL, NULL, NULL); - namerec->death_time += lp_max_ttl(); - namerec->refresh_time += lp_max_ttl(); + if( !is_refresh_already_queued( subrec, namerec) ) + refresh_name( subrec, namerec, NULL, NULL, NULL ); + namerec->data.death_time += lp_max_ttl(); + namerec->data.refresh_time += lp_max_ttl(); } } } diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 897505ca2b..6375dad4a2 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -38,7 +38,7 @@ uint16 samba_nb_type = 0; /* samba's NetBIOS name type */ void set_samba_nb_type(void) { - if (lp_wins_support() || (*lp_wins_server())) + if( lp_wins_support() || (*lp_wins_server()) ) samba_nb_type = NB_MFLAG; /* samba is a 'hybrid' node type */ else samba_nb_type = NB_BFLAG; /* samba is broadcast-only node type */ @@ -54,9 +54,9 @@ void set_samba_nb_type(void) **************************************************************************/ -BOOL ms_browser_name(char *name, int type) +BOOL ms_browser_name( char *name, int type ) { - return (strequal(name,MSBROWSE) && (type == 0x01)); + return( strequal( name, MSBROWSE ) && (type == 0x01) ); } /**************************************************************************** @@ -76,7 +76,7 @@ static void add_name_to_namelist(struct subnet_record *subrec, return; } - for (namerec2 = subrec->namelist; namerec2->next; namerec2 = namerec2->next) + for( namerec2 = subrec->namelist; namerec2->next; namerec2 = namerec2->next ) ; namerec2->next = namerec; @@ -91,8 +91,8 @@ static void add_name_to_namelist(struct subnet_record *subrec, Remove a name from the namelist. **************************************************************************/ -void remove_name_from_namelist(struct subnet_record *subrec, - struct name_record *namerec) +void remove_name_from_namelist( struct subnet_record *subrec, + struct name_record *namerec ) { if (namerec->next) namerec->next->prev = namerec->prev; @@ -102,8 +102,8 @@ void remove_name_from_namelist(struct subnet_record *subrec, if(namerec == subrec->namelist) subrec->namelist = namerec->next; - if(namerec->ip != NULL) - free((char *)namerec->ip); + if(namerec->data.ip != NULL) + free((char *)namerec->data.ip); free((char *)namerec); subrec->namelist_changed = True; @@ -125,13 +125,13 @@ struct name_record *find_name_on_subnet(struct subnet_record *subrec, if (nmb_name_equal(&name_ret->name, nmbname)) { /* Self names only - these include permanent names. */ - if (self_only && (name_ret->source != SELF_NAME) && - (name_ret->source != PERMANENT_NAME) ) + if (self_only && (name_ret->data.source != SELF_NAME) && + (name_ret->data.source != PERMANENT_NAME) ) { continue; } DEBUG(9,("find_name_on_subnet: on subnet %s - found name %s source=%d\n", - subrec->subnet_name, namestr(nmbname), name_ret->source)); + subrec->subnet_name, namestr(nmbname), name_ret->data.source)); return name_ret; } } @@ -144,15 +144,18 @@ struct name_record *find_name_on_subnet(struct subnet_record *subrec, Find a name over all known broadcast subnets. **************************************************************************/ -struct name_record *find_name_for_remote_broadcast_subnet( struct nmb_name *nmbname, - BOOL self_only) +struct name_record + *find_name_for_remote_broadcast_subnet( struct nmb_name *nmbname, + BOOL self_only ) { struct subnet_record *subrec; struct name_record *namerec = NULL; - for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + for( subrec = FIRST_SUBNET; + subrec; + subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) ) { - if((namerec = find_name_on_subnet(subrec, nmbname, self_only))!= NULL) + if( NULL != (namerec = find_name_on_subnet(subrec, nmbname, self_only)) ) break; } @@ -163,14 +166,14 @@ struct name_record *find_name_for_remote_broadcast_subnet( struct nmb_name *nmbn Update the ttl of an entry in a subnet name list. ****************************************************************************/ -void update_name_ttl(struct name_record *namerec, int ttl) +void update_name_ttl( struct name_record *namerec, int ttl ) { time_t time_now = time(NULL); - if(namerec->death_time != PERMANENT_TTL) - namerec->death_time = time_now + ttl; + if(namerec->data.death_time != PERMANENT_TTL) + namerec->data.death_time = time_now + ttl; - namerec->refresh_time = time_now + (ttl/2); + namerec->data.refresh_time = time_now + (ttl/2); namerec->subnet->namelist_changed = True; } @@ -196,43 +199,49 @@ struct name_record *add_name_to_subnet(struct subnet_record *subrec, namerec->subnet = subrec; - namerec->num_ips = num_ips; - namerec->ip = (struct in_addr *)malloc(sizeof(struct in_addr) * namerec->num_ips); - if (!namerec->ip) + namerec->data.num_ips = num_ips; + namerec->data.ip = (struct in_addr *)malloc( sizeof(struct in_addr) + * namerec->data.num_ips ); + if (!namerec->data.ip) { DEBUG(0,("add_name_to_subnet: malloc fail when creating ip_flgs.\n")); free((char *)namerec); return NULL; } - bzero((char *)namerec->ip, sizeof(struct in_addr) * namerec->num_ips); + bzero( (char *)namerec->data.ip, + sizeof(struct in_addr) * namerec->data.num_ips ); - memcpy(&namerec->ip[0], iplist, num_ips * sizeof(struct in_addr)); + memcpy( &namerec->data.ip[0], iplist, num_ips * sizeof(struct in_addr) ); - make_nmb_name(&namerec->name,name,type,scope); + make_nmb_name( &namerec->name, name, type, scope ); /* Setup the death_time and refresh_time. */ if(ttl == PERMANENT_TTL) - namerec->death_time = PERMANENT_TTL; + namerec->data.death_time = PERMANENT_TTL; else - namerec->death_time = time_now + ttl; + namerec->data.death_time = time_now + ttl; - namerec->refresh_time = time_now + (ttl/2); + namerec->data.refresh_time = time_now + (ttl/2); /* Enter the name as active. */ - namerec->nb_flags = nb_flags | NB_ACTIVE; + namerec->data.nb_flags = nb_flags | NB_ACTIVE; /* If it's our primary name, flag it as so. */ if(strequal(my_netbios_names[0],name)) - namerec->nb_flags |= NB_PERM; + namerec->data.nb_flags |= NB_PERM; - namerec->source = source; + namerec->data.source = source; add_name_to_namelist(subrec,namerec); - DEBUG(3,("add_name_to_subnet: Added netbios name %s with first IP %s ttl=%d nb_flags=%2x to subnet %s\n", - namestr(&namerec->name),inet_ntoa(*iplist),ttl,(unsigned int)nb_flags, - subrec->subnet_name)); + DEBUG( 3, ( "add_name_to_subnet: Added netbios name %s with first IP %s \ +ttl=%d nb_flags=%2x to subnet %s\n", + namestr(&namerec->name), + inet_ntoa(*iplist), + ttl, + (unsigned int)nb_flags, + subrec->subnet_name) ); subrec->namelist_changed = True; @@ -250,13 +259,14 @@ void standard_success_register(struct subnet_record *subrec, struct nmb_name *nmbname, uint16 nb_flags, int ttl, struct in_addr registered_ip) { - struct name_record *namerec = find_name_on_subnet(subrec, nmbname, FIND_SELF_NAME); + struct name_record *namerec; - if(namerec == NULL) - add_name_to_subnet(subrec, nmbname->name, nmbname->name_type, - nb_flags, ttl, SELF_NAME, 1, ®istered_ip); + namerec = find_name_on_subnet( subrec, nmbname, FIND_SELF_NAME ); + if( NULL == namerec ) + add_name_to_subnet( subrec, nmbname->name, nmbname->name_type, + nb_flags, ttl, SELF_NAME, 1, ®istered_ip ); else - update_name_ttl(namerec, ttl); + update_name_ttl( namerec, ttl ); } /******************************************************************* @@ -264,16 +274,20 @@ void standard_success_register(struct subnet_record *subrec, fails. ******************************************************************/ -void standard_fail_register(struct subnet_record *subrec, - struct response_record *rrec, struct nmb_name *nmbname) +void standard_fail_register( struct subnet_record *subrec, + struct response_record *rrec, + struct nmb_name *nmbname ) { - struct name_record *namerec = find_name_on_subnet(subrec, nmbname, FIND_SELF_NAME); + struct name_record *namerec; - DEBUG(0,("standard_fail_register: Failed to register/refresh name %s on subnet %s\n", - namestr(nmbname), subrec->subnet_name)); + namerec = find_name_on_subnet( subrec, nmbname, FIND_SELF_NAME ); + + DEBUG( 0, ( "standard_fail_register: Failed to register/refresh name %s \ +on subnet %s\n", + namestr(nmbname), subrec->subnet_name) ); /* Remove the name from the subnet. */ - if(namerec) + if( namerec ) remove_name_from_namelist(subrec, namerec); } @@ -283,11 +297,12 @@ void standard_fail_register(struct subnet_record *subrec, static void remove_nth_ip_in_record( struct name_record *namerec, int ind) { - if(ind != namerec->num_ips) - memmove( (char *)(&namerec->ip[ind]), (char *)(&namerec->ip[ind+1]), - ( namerec->num_ips - ind - 1) * sizeof(struct in_addr)); + if( ind != namerec->data.num_ips ) + memmove( (char *)(&namerec->data.ip[ind]), + (char *)(&namerec->data.ip[ind+1]), + ( namerec->data.num_ips - ind - 1) * sizeof(struct in_addr) ); - namerec->num_ips--; + namerec->data.num_ips--; namerec->subnet->namelist_changed = True; } @@ -295,12 +310,12 @@ static void remove_nth_ip_in_record( struct name_record *namerec, int ind) Utility function to check if an IP address exists in a name record. ******************************************************************/ -BOOL find_ip_in_name_record(struct name_record *namerec, struct in_addr ip) +BOOL find_ip_in_name_record( struct name_record *namerec, struct in_addr ip ) { int i; - for(i = 0; i < namerec->num_ips; i++) - if(ip_equal( namerec->ip[i], ip)) + for(i = 0; i < namerec->data.num_ips; i++) + if(ip_equal( namerec->data.ip[i], ip)) return True; return False; @@ -318,18 +333,22 @@ void add_ip_to_name_record(struct name_record *namerec, struct in_addr new_ip) if(find_ip_in_name_record( namerec, new_ip)) return; - if((new_list = (struct in_addr *)malloc( (namerec->num_ips + 1)*sizeof(struct in_addr)) )== NULL) + new_list = (struct in_addr *)malloc( (namerec->data.num_ips + 1) + * sizeof(struct in_addr) ); + if( NULL == new_list ) { DEBUG(0,("add_ip_to_name_record: Malloc fail !\n")); return; } - memcpy((char *)new_list, (char *)namerec->ip, namerec->num_ips *sizeof(struct in_addr)); - new_list[namerec->num_ips] = new_ip; + memcpy( (char *)new_list, + (char *)namerec->data.ip, + namerec->data.num_ips * sizeof(struct in_addr) ); + new_list[namerec->data.num_ips] = new_ip; - free((char *)namerec->ip); - namerec->ip = new_list; - namerec->num_ips += 1; + free((char *)namerec->data.ip); + namerec->data.ip = new_list; + namerec->data.num_ips += 1; namerec->subnet->namelist_changed = True; } @@ -338,14 +357,15 @@ void add_ip_to_name_record(struct name_record *namerec, struct in_addr new_ip) Utility function to remove an IP address from a name record. ******************************************************************/ -void remove_ip_from_name_record( struct name_record *namerec, struct in_addr remove_ip) +void remove_ip_from_name_record( struct name_record *namerec, + struct in_addr remove_ip ) { /* Try and find the requested ip address - remove it. */ int i; - int orig_num = namerec->num_ips; + int orig_num = namerec->data.num_ips; for(i = 0; i < orig_num; i++) - if( ip_equal( remove_ip, namerec->ip[i]) ) + if( ip_equal( remove_ip, namerec->data.ip[i]) ) { remove_nth_ip_in_record( namerec, i); break; @@ -358,31 +378,40 @@ void remove_ip_from_name_record( struct name_record *namerec, struct in_addr rem duplication of success_function code. ******************************************************************/ -void standard_success_release(struct subnet_record *subrec, - struct userdata_struct *userdata, - struct nmb_name *nmbname, struct in_addr released_ip) +void standard_success_release( struct subnet_record *subrec, + struct userdata_struct *userdata, + struct nmb_name *nmbname, + struct in_addr released_ip ) { - struct name_record *namerec = find_name_on_subnet(subrec, nmbname, FIND_ANY_NAME); + struct name_record *namerec; + + namerec = find_name_on_subnet( subrec, nmbname, FIND_ANY_NAME ); - if(namerec == NULL) + if( namerec == NULL ) { - DEBUG(0,("standard_success_release: Name release for name %s IP %s on subnet %s. Name \ -was not found on subnet.\n", namestr(nmbname), inet_ntoa(released_ip), subrec->subnet_name)); + DEBUG( 0, ( "standard_success_release: Name release for name %s IP %s \ +on subnet %s. Name was not found on subnet.\n", + namestr(nmbname), + inet_ntoa(released_ip), + subrec->subnet_name) ); return; } else { - int orig_num = namerec->num_ips; + int orig_num = namerec->data.num_ips; - remove_ip_from_name_record( namerec, released_ip); + remove_ip_from_name_record( namerec, released_ip ); - if(namerec->num_ips == orig_num) - DEBUG(0,("standard_success_release: Name release for name %s IP %s on subnet %s. This ip \ -is not known for this name.\n", namestr(nmbname), inet_ntoa(released_ip), subrec->subnet_name )); + if( namerec->data.num_ips == orig_num ) + DEBUG( 0, ( "standard_success_release: Name release for name %s IP %s \ +on subnet %s. This ip is not known for this name.\n", + namestr(nmbname), + inet_ntoa(released_ip), + subrec->subnet_name ) ); } - if (namerec->num_ips == 0) - remove_name_from_namelist(subrec, namerec); + if( namerec->data.num_ips == 0 ) + remove_name_from_namelist( subrec, namerec ); } /******************************************************************* @@ -397,17 +426,19 @@ void expire_names_on_subnet(struct subnet_record *subrec, time_t t) for (namerec = subrec->namelist; namerec; namerec = next_namerec) { next_namerec = namerec->next; - if ((namerec->death_time != PERMANENT_TTL) && (namerec->death_time < t)) + if( (namerec->data.death_time != PERMANENT_TTL) + && (namerec->data.death_time < t) ) { - if (namerec->source == SELF_NAME) + if (namerec->data.source == SELF_NAME) { - DEBUG(3,("expire_names_on_subnet: Subnet %s not expiring SELF name %s\n", - subrec->subnet_name, namestr(&namerec->name))); - namerec->death_time += 300; + DEBUG( 3, ( "expire_names_on_subnet: Subnet %s not expiring SELF \ +name %s\n", + subrec->subnet_name, namestr(&namerec->name) ) ); + namerec->data.death_time += 300; namerec->subnet->namelist_changed = True; continue; } - DEBUG(3,("expire_names_on_subnet: Subnet %s - removing expired name %s\n", + DEBUG(3,("expire_names_on_subnet: Subnet %s - removing expired name %s\n", subrec->subnet_name, namestr(&namerec->name))); remove_name_from_namelist(subrec, namerec); @@ -423,9 +454,11 @@ void expire_names(time_t t) { struct subnet_record *subrec; - for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) + for( subrec = FIRST_SUBNET; + subrec; + subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec) ) { - expire_names_on_subnet(subrec, t); + expire_names_on_subnet( subrec, t ); } } @@ -437,7 +470,7 @@ void expire_names(time_t t) all broadcast subnet IP addresses. **************************************************************************/ -void add_samba_names_to_subnet(struct subnet_record *subrec) +void add_samba_names_to_subnet( struct subnet_record *subrec ) { struct in_addr *iplist = &subrec->myip; int num_ips = 1; @@ -453,14 +486,16 @@ void add_samba_names_to_subnet(struct subnet_record *subrec) /* Create an IP list containing all our known subnets. */ num_ips = iface_count(); - if((iplist = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr) )) == NULL) + iplist = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr) ); + if( NULL == iplist ) { DEBUG(0,("add_samba_names_to_subnet: Malloc fail !\n")); return; } - for(bcast_subrecs = FIRST_SUBNET, i = 0; bcast_subrecs; - bcast_subrecs = NEXT_SUBNET_EXCLUDING_UNICAST(bcast_subrecs), i++) + for( bcast_subrecs = FIRST_SUBNET, i = 0; + bcast_subrecs; + bcast_subrecs = NEXT_SUBNET_EXCLUDING_UNICAST(bcast_subrecs), i++ ) iplist[i] = bcast_subrecs->myip; } @@ -494,7 +529,7 @@ static void dump_subnet_namelist( struct subnet_record *subrec, FILE *fp) for (namerec = subrec->namelist; namerec; namerec = namerec->next) { fprintf(fp,"\tName = %s\t", namestr(&namerec->name)); - switch(namerec->source) + switch(namerec->data.source) { case LMHOSTS_NAME: src_type = "LMHOSTS_NAME"; @@ -521,27 +556,27 @@ static void dump_subnet_namelist( struct subnet_record *subrec, FILE *fp) src_type = "unknown!"; break; } - fprintf(fp, "Source = %s\nb_flags = %x\t", src_type, namerec->nb_flags); + fprintf(fp,"Source = %s\nb_flags = %x\t", src_type, namerec->data.nb_flags); - if(namerec->death_time != PERMANENT_TTL) + if(namerec->data.death_time != PERMANENT_TTL) { - tm = LocalTime(&namerec->death_time); + tm = LocalTime(&namerec->data.death_time); fprintf(fp, "death_time = %s\t", asctime(tm)); } else fprintf(fp, "death_time = PERMANENT\t"); - if(namerec->refresh_time != PERMANENT_TTL) + if(namerec->data.refresh_time != PERMANENT_TTL) { - tm = LocalTime(&namerec->refresh_time); + tm = LocalTime(&namerec->data.refresh_time); fprintf(fp, "refresh_time = %s\n", asctime(tm)); } else fprintf(fp, "refresh_time = PERMANENT\n"); - fprintf(fp, "\t\tnumber of IPS = %d", namerec->num_ips); - for(i = 0; i < namerec->num_ips; i++) - fprintf(fp, "\t%s", inet_ntoa(namerec->ip[i])); + fprintf(fp, "\t\tnumber of IPS = %d", namerec->data.num_ips); + for(i = 0; i < namerec->data.num_ips; i++) + fprintf(fp, "\t%s", inet_ntoa(namerec->data.ip[i])); fprintf(fp, "\n\n"); } @@ -572,7 +607,9 @@ void dump_all_namelists(void) return; } - for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) + for( subrec = FIRST_SUBNET; + subrec; + subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec) ) dump_subnet_namelist( subrec, fp); if(!we_are_a_wins_client()) diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index 509b3b3107..7c2b0d4d76 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -37,7 +37,8 @@ static void query_name_response(struct subnet_record *subrec, { struct nmb_packet *nmb = &p->packet.nmb; BOOL success = False; - struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name; + struct nmb_name *question_name = + &rrec->packet->packet.nmb.question.question_name; struct in_addr answer_ip; /* Ensure we don't retry the query but leave the response record cleanup @@ -157,8 +158,9 @@ static BOOL query_local_namelists(struct subnet_record *subrec, struct nmb_name if((namerec = find_name_on_subnet(subrec, nmbname, FIND_ANY_NAME))==NULL) return False; - if(NAME_IS_ACTIVE(namerec) && ((namerec->source == SELF_NAME) || - (namerec->source == LMHOSTS_NAME)) ) + if( NAME_IS_ACTIVE(namerec) + && ( (namerec->data.source == SELF_NAME) + || (namerec->data.source == LMHOSTS_NAME) ) ) { *namerecp = namerec; return True; @@ -198,23 +200,23 @@ BOOL query_name(struct subnet_record *subrec, char *name, int type, rrec.rr_type = RR_TYPE_NB; rrec.rr_class = RR_CLASS_IN; rrec.ttl = PERMANENT_TTL; - rrec.rdlength = namerec->num_ips * 6; + rrec.rdlength = namerec->data.num_ips * 6; if(rrec.rdlength > MAX_DGRAM_SIZE) { DEBUG(0,("query_name: nmbd internal error - there are %d ip addresses for name %s.\n", - namerec->num_ips, namestr(&nmbname) )); + namerec->data.num_ips, namestr(&nmbname) )); return False; } - for( i = 0; i < namerec->num_ips; i++) + for( i = 0; i < namerec->data.num_ips; i++) { - set_nb_flags( &rrec.rdata[i*6], namerec->nb_flags ); - putip( &rrec.rdata[(i*6) + 2], (char *)&namerec->ip[i]); + set_nb_flags( &rrec.rdata[i*6], namerec->data.nb_flags ); + putip( &rrec.rdata[(i*6) + 2], (char *)&namerec->data.ip[i]); } /* Call the success function directly. */ if(success_fn) - (*success_fn)(subrec, userdata, &nmbname, namerec->ip[0], &rrec); + (*success_fn)(subrec, userdata, &nmbname, namerec->data.ip[0], &rrec); return False; } diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index 8eae5e0f1c..a4b8d4d65a 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -372,16 +372,16 @@ BOOL refresh_name(struct subnet_record *subrec, struct name_record *namerec, * only be done once). */ - for( i = 0; i < namerec->num_ips; i++) + for( i = 0; i < namerec->data.num_ips; i++) { if(queue_refresh_name( subrec, register_name_response, register_name_timeout_response, - (i == (namerec->num_ips - 1)) ? success_fn : NULL, - (i == (namerec->num_ips - 1)) ? fail_fn : NULL, - (i == (namerec->num_ips - 1)) ? userdata : NULL, + (i == (namerec->data.num_ips - 1)) ? success_fn : NULL, + (i == (namerec->data.num_ips - 1)) ? fail_fn : NULL, + (i == (namerec->data.num_ips - 1)) ? userdata : NULL, namerec, - namerec->ip[i]) == NULL) + namerec->data.ip[i]) == NULL) { DEBUG(0,("refresh_name: Failed to send packet trying to refresh name %s\n", namestr(&namerec->name))); diff --git a/source3/nmbd/nmbd_namerelease.c b/source3/nmbd/nmbd_namerelease.c index f72de8c20e..b58bab3a1d 100644 --- a/source3/nmbd/nmbd_namerelease.c +++ b/source3/nmbd/nmbd_namerelease.c @@ -201,15 +201,15 @@ BOOL release_name(struct subnet_record *subrec, struct name_record *namerec, int i; /* Ensure it's a SELF name, and in the ACTIVE state. */ - if((namerec->source != SELF_NAME) || !NAME_IS_ACTIVE(namerec)) + if((namerec->data.source != SELF_NAME) || !NAME_IS_ACTIVE(namerec)) { DEBUG(0,("release_name: Cannot release name %s from subnet %s. Source was %d \n", - namestr(&namerec->name), subrec->subnet_name, namerec->source)); + namestr(&namerec->name), subrec->subnet_name, namerec->data.source)); return True; } /* Set the name into the deregistering state. */ - namerec->nb_flags |= NB_DEREG; + namerec->data.nb_flags |= NB_DEREG; /* * Go through and release the name for all known ip addresses. @@ -217,20 +217,20 @@ BOOL release_name(struct subnet_record *subrec, struct name_record *namerec, * only be done once). */ - for( i = 0; i < namerec->num_ips; i++) + for( i = 0; i < namerec->data.num_ips; i++) { if(queue_release_name( subrec, release_name_response, release_name_timeout_response, - (i == (namerec->num_ips - 1)) ? success_fn : NULL, - (i == (namerec->num_ips - 1)) ? fail_fn : NULL, - (i == (namerec->num_ips - 1)) ? userdata : NULL, + (i == (namerec->data.num_ips - 1)) ? success_fn : NULL, + (i == (namerec->data.num_ips - 1)) ? fail_fn : NULL, + (i == (namerec->data.num_ips - 1)) ? userdata : NULL, &namerec->name, - namerec->nb_flags, - namerec->ip[i]) == NULL) + namerec->data.nb_flags, + namerec->data.ip[i]) == NULL) { DEBUG(0,("release_name: Failed to send packet trying to release name %s IP %s\n", - namestr(&namerec->name), inet_ntoa(namerec->ip[i]) )); + namestr(&namerec->name), inet_ntoa(namerec->data.ip[i]) )); return True; } } diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index b62f0aff62..e07391fb48 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -629,7 +629,7 @@ struct response_record *queue_refresh_name( struct subnet_record *subrec, subrec->bcast_ip)) == NULL) return NULL; - if(initiate_name_refresh_packet( p, namerec->nb_flags, &refresh_ip) == False) + if( !initiate_name_refresh_packet( p, namerec->data.nb_flags, &refresh_ip ) ) { p->locked = False; free_packet(p); diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index ded37ebf30..97caef7f82 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -94,13 +94,17 @@ returned for name %s.\n", namestr(nmbname) )); if(namerec && original_packet->packet.nmb.header.nm_flags.bcast) { - for( i = 0; i < namerec->num_ips; i++) + for( i = 0; i < namerec->data.num_ips; i++) { - if(same_net( namerec->ip[i], orig_broadcast_subnet->myip, orig_broadcast_subnet->mask_ip )) + if( same_net( namerec->data.ip[i], + orig_broadcast_subnet->myip, + orig_broadcast_subnet->mask_ip ) ) { - DEBUG(5,("wins_proxy_name_query_request_success: name %s is a WINS proxy name and is also \ -on the same subnet (%s) as the requestor. Not replying.\n", - namestr(&namerec->name), orig_broadcast_subnet->subnet_name )); + DEBUG( 5, ( "wins_proxy_name_query_request_success: name %s is a WINS \ +proxy name and is also on the same subnet (%s) as the requestor. \ +Not replying.\n", + namestr(&namerec->name), + orig_broadcast_subnet->subnet_name ) ); return; } } diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index e1f0fbae8f..89e602606b 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -529,8 +529,9 @@ static void wins_register_query_fail(struct subnet_record *subrec, namerec = find_name_on_subnet(subrec, question_name, FIND_ANY_NAME); - if((namerec != NULL) && (namerec->source == REGISTER_NAME) && - ip_equal(rrec->packet->ip, *namerec->ip) ) + if( (namerec != NULL) + && (namerec->data.source == REGISTER_NAME) + && ip_equal(rrec->packet->ip, *namerec->data.ip) ) { remove_name_from_namelist( subrec, namerec); namerec = NULL; @@ -646,11 +647,13 @@ IP %s\n", registering_group_name ? "Group" : "Unique", namestr(question), inet_n * name. */ - if((namerec != NULL) && ((namerec->source == DNS_NAME) || (namerec->source == DNSFAIL_NAME))) + if( (namerec != NULL) + && ( (namerec->data.source == DNS_NAME) + || (namerec->data.source == DNSFAIL_NAME) ) ) { - DEBUG(5,("wins_process_name_registration_request: Name (%s) in WINS was a dns lookup \ -- removing it.\n", namestr(question) )); - remove_name_from_namelist( subrec, namerec); + DEBUG(5,("wins_process_name_registration_request: Name (%s) in WINS was \ +a dns lookup - removing it.\n", namestr(question) )); + remove_name_from_namelist( subrec, namerec ); namerec = NULL; } @@ -659,10 +662,11 @@ IP %s\n", registering_group_name ? "Group" : "Unique", namestr(question), inet_n * (ie. Don't allow any static names to be overwritten. */ - if((namerec != NULL) && (namerec->source != REGISTER_NAME)) + if((namerec != NULL) && (namerec->data.source != REGISTER_NAME)) { - DEBUG(3,("wins_process_name_registration_request: Attempt to register name %s. Name \ -already exists in WINS with source type %d.\n", namestr(question), namerec->source )); + DEBUG( 3, ( "wins_process_name_registration_request: Attempt \ +to register name %s. Name already exists in WINS with source type %d.\n", + namestr(question), namerec->data.source )); send_wins_name_registration_response(RFS_ERR, 0, p); return; } @@ -768,11 +772,13 @@ is one of our (WINS server) names. Denying registration.\n", namestr(question) ) * is the same as the the (single) already registered IP then just update the ttl. */ - if(!registering_group_name && (namerec != NULL) && (namerec->num_ips == 1) && - ip_equal(namerec->ip[0], from_ip)) + if( !registering_group_name + && (namerec != NULL) + && (namerec->data.num_ips == 1) + && ip_equal( namerec->data.ip[0], from_ip ) ) { - update_name_ttl(namerec, ttl); - send_wins_name_registration_response(0, ttl, p); + update_name_ttl( namerec, ttl ); + send_wins_name_registration_response( 0, ttl, p ); return; } @@ -781,7 +787,7 @@ is one of our (WINS server) names. Denying registration.\n", namestr(question) ) * to see if they still claim to have the name. */ - if(namerec != NULL) + if( namerec != NULL ) { char ud[sizeof(struct userdata_struct) + sizeof(struct packet_struct *)]; struct userdata_struct *userdata = (struct userdata_struct *)ud; @@ -815,10 +821,12 @@ is one of our (WINS server) names. Denying registration.\n", namestr(question) ) * code. JRA. */ - query_name_from_wins_server( *namerec->ip, question->name, question->name_type, - wins_register_query_success, - wins_register_query_fail, - userdata); + query_name_from_wins_server( *namerec->data.ip, + question->name, + question->name_type, + wins_register_query_success, + wins_register_query_fail, + userdata ); return; } @@ -870,7 +878,7 @@ static void wins_multihomed_register_query_success(struct subnet_record *subrec, namerec = find_name_on_subnet(subrec, question_name, FIND_ANY_NAME); - if( (namerec == NULL) || (namerec->source != REGISTER_NAME) ) + if( (namerec == NULL) || (namerec->data.source != REGISTER_NAME) ) { DEBUG(3,("wins_multihomed_register_query_success: name %s is not in the correct state to add \ a subsequent IP addess.\n", namestr(question_name) )); @@ -981,7 +989,9 @@ to register name %s from IP %s.", namestr(question), inet_ntoa(p->ip) )); * name. */ - if((namerec != NULL) && ((namerec->source == DNS_NAME) || (namerec->source == DNSFAIL_NAME))) + if( (namerec != NULL) + && ( (namerec->data.source == DNS_NAME) + || (namerec->data.source == DNSFAIL_NAME) ) ) { DEBUG(5,("wins_process_multihomed_name_registration_request: Name (%s) in WINS was a dns lookup \ - removing it.\n", namestr(question) )); @@ -994,10 +1004,11 @@ to register name %s from IP %s.", namestr(question), inet_ntoa(p->ip) )); * (ie. Don't allow any static names to be overwritten. */ - if((namerec != NULL) && (namerec->source != REGISTER_NAME)) + if( (namerec != NULL) && (namerec->data.source != REGISTER_NAME) ) { - DEBUG(3,("wins_process_multihomed_name_registration_request: Attempt to register name %s. Name \ -already exists in WINS with source type %d.\n", namestr(question), namerec->source )); + DEBUG( 3, ( "wins_process_multihomed_name_registration_request: Attempt \ +to register name %s. Name already exists in WINS with source type %d.\n", + namestr(question), namerec->data.source )); send_wins_name_registration_response(RFS_ERR, 0, p); return; } @@ -1139,7 +1150,7 @@ static void process_wins_dmb_query_request(struct subnet_record *subrec, for(namerec = subrec->namelist; namerec; namerec = namerec->next) { if(namerec->name.name_type == 0x1b) - num_ips += namerec->num_ips; + num_ips += namerec->data.num_ips; } if(num_ips == 0) @@ -1169,10 +1180,10 @@ static void process_wins_dmb_query_request(struct subnet_record *subrec, if(namerec->name.name_type == 0x1b) { int i; - for(i = 0; i < namerec->num_ips; i++) + for(i = 0; i < namerec->data.num_ips; i++) { - set_nb_flags(&prdata[num_ips * 6],namerec->nb_flags); - putip((char *)&prdata[(num_ips * 6) + 2], &namerec->ip[i]); + set_nb_flags(&prdata[num_ips * 6],namerec->data.nb_flags); + putip((char *)&prdata[(num_ips * 6) + 2], &namerec->data.ip[i]); num_ips++; } } @@ -1213,18 +1224,18 @@ void send_wins_name_query_response(int rcode, struct packet_struct *p, { int same_net_index = -1; - ttl = (namerec->death_time != PERMANENT_TTL) ? - namerec->death_time - p->timestamp : lp_max_wins_ttl(); + ttl = (namerec->data.death_time != PERMANENT_TTL) ? + namerec->data.death_time - p->timestamp : lp_max_wins_ttl(); /* Copy all known ip addresses into the return data. */ /* Optimise for the common case of one IP address so we don't need a malloc. */ - if(namerec->num_ips == 1 ) + if( namerec->data.num_ips == 1 ) prdata = rdata; else { - if((prdata = (char *)malloc( namerec->num_ips * 6 )) == NULL) + if((prdata = (char *)malloc( namerec->data.num_ips * 6 )) == NULL) { DEBUG(0,("send_wins_name_query_response: malloc fail !\n")); return; @@ -1244,12 +1255,12 @@ void send_wins_name_query_response(int rcode, struct packet_struct *p, { struct in_addr *n_mask = iface_nmask(p->ip); - for( j = 0; j < namerec->num_ips; j++) + for( j = 0; j < namerec->data.num_ips; j++) { - if(same_net( namerec->ip[j], p->ip, *n_mask)) + if(same_net( namerec->data.ip[j], p->ip, *n_mask)) { - set_nb_flags(&prdata[0],namerec->nb_flags); - putip((char *)&prdata[2], &namerec->ip[j]); + set_nb_flags(&prdata[0],namerec->data.nb_flags); + putip((char *)&prdata[2], &namerec->data.ip[j]); same_net_index = j; i = 1; } @@ -1257,15 +1268,15 @@ void send_wins_name_query_response(int rcode, struct packet_struct *p, } } - for(j = 0; j < namerec->num_ips; j++) + for(j = 0; j < namerec->data.num_ips; j++) { if(j == same_net_index) continue; - set_nb_flags(&prdata[i*6],namerec->nb_flags); - putip((char *)&prdata[2+(i*6)], &namerec->ip[j]); + set_nb_flags(&prdata[i*6],namerec->data.nb_flags); + putip((char *)&prdata[2+(i*6)], &namerec->data.ip[j]); i++; } - reply_data_len = namerec->num_ips * 6; + reply_data_len = namerec->data.num_ips * 6; } @@ -1316,7 +1327,7 @@ void wins_process_name_query_request(struct subnet_record *subrec, * If it's a DNSFAIL_NAME then reply name not found. */ - if(namerec->source == DNSFAIL_NAME) + if( namerec->data.source == DNSFAIL_NAME ) { DEBUG(3,("wins_process_name_query: name query for name %s returning DNS fail.\n", namestr(question) )); @@ -1328,7 +1339,8 @@ void wins_process_name_query_request(struct subnet_record *subrec, * If the name has expired then reply name not found. */ - if((namerec->death_time != PERMANENT_TTL) && (namerec->death_time < p->timestamp)) + if( (namerec->data.death_time != PERMANENT_TTL) + && (namerec->data.death_time < p->timestamp) ) { DEBUG(3,("wins_process_name_query: name query for name %s - name expired. Returning fail.\n", namestr(question) )); @@ -1337,7 +1349,7 @@ void wins_process_name_query_request(struct subnet_record *subrec, } DEBUG(3,("wins_process_name_query: name query for name %s returning first IP %s.\n", - namestr(question), inet_ntoa(namerec->ip[0]) )); + namestr(question), inet_ntoa(namerec->data.ip[0]) )); send_wins_name_query_response(0, p, namerec); return; @@ -1437,7 +1449,8 @@ to release name %s from IP %s.", namestr(question), inet_ntoa(p->ip) )); namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); - if((namerec == NULL) || ((namerec != NULL) && (namerec->source != REGISTER_NAME)) ) + if( (namerec == NULL) + || ((namerec != NULL) && (namerec->data.source != REGISTER_NAME)) ) { send_wins_name_release_response(NAM_ERR, p); return; @@ -1479,7 +1492,7 @@ release name %s as IP %s is not one of the known IP's for this name.\n", /* * Remove the name entirely if no IP addresses left. */ - if (namerec->num_ips == 0) + if (namerec->data.num_ips == 0) remove_name_from_namelist(subrec, namerec); } @@ -1544,27 +1557,27 @@ void wins_write_database(void) DEBUG(4,("%-19s ", namestr(&namerec->name) )); - if(namerec->death_time != PERMANENT_TTL) + if( namerec->data.death_time != PERMANENT_TTL ) { - tm = LocalTime(&namerec->death_time); + tm = LocalTime(&namerec->data.death_time); DEBUG(4,("TTL = %s", asctime(tm) )); } else DEBUG(4,("TTL = PERMANENT\t")); - for (i = 0; i < namerec->num_ips; i++) - DEBUG(4,("%15s ", inet_ntoa(namerec->ip[i]) )); - DEBUG(4,("%2x\n", namerec->nb_flags )); + for (i = 0; i < namerec->data.num_ips; i++) + DEBUG(4,("%15s ", inet_ntoa(namerec->data.ip[i]) )); + DEBUG(4,("%2x\n", namerec->data.nb_flags )); - if (namerec->source == REGISTER_NAME) + if( namerec->data.source == REGISTER_NAME ) { fprintf(fp, "\"%s#%02x\" %d ", namerec->name.name,namerec->name.name_type, /* Ignore scope. */ - (int)namerec->death_time); + (int)namerec->data.death_time); - for (i = 0; i < namerec->num_ips; i++) - fprintf(fp, "%s ", inet_ntoa(namerec->ip[i])); - fprintf(fp, "%2xR\n", namerec->nb_flags); + for (i = 0; i < namerec->data.num_ips; i++) + fprintf( fp, "%s ", inet_ntoa( namerec->data.ip[i] ) ); + fprintf( fp, "%2xR\n", namerec->data.nb_flags ); } } -- cgit From 75e909f27db1e1ff69897e477a2c4704faf9a2fb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 9 Jun 1998 02:17:06 +0000 Subject: Fixed compile problem after make proto. Chris's reformating of the (rather long named function) find_name_for_remote_broadcast_subnet (moving the function name onto a line on it's own) caused the proto awk script to miss it. Jeremy. (This used to be commit 17c758687f0ec6040633bc1815a52627b7e15f02) --- source3/nmbd/nmbd_namelistdb.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 6375dad4a2..f9a348eeea 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -144,9 +144,8 @@ struct name_record *find_name_on_subnet(struct subnet_record *subrec, Find a name over all known broadcast subnets. **************************************************************************/ -struct name_record - *find_name_for_remote_broadcast_subnet( struct nmb_name *nmbname, - BOOL self_only ) +struct name_record *find_name_for_remote_broadcast_subnet( struct nmb_name *nmbname, + BOOL self_only ) { struct subnet_record *subrec; struct name_record *namerec = NULL; -- cgit From d4366df039dfd730fe24c95b9ef7d59306f35309 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Wed, 10 Jun 1998 19:51:58 +0000 Subject: I've replaced the linked list used to manage the subnet namelists with a splay tree. For short lists, this will have no noticable effect. As lists (eg. the WINS database) grow longer, the speed improvements should be quite dramatic. This change is an incremental step toward replacing the in-memory namelists with a back-end database. This change is going into the 1.9.19pre-alpha code because...well...it's pre-alpha. Please let me know if there are any problems. (Oh, as a side-effect, the wins.dat will be in sorted order. :) Chris -)----- (This used to be commit 7806c453df02a89f67e7c5c8b91f24aa2274e756) --- source3/nmbd/nmbd_incomingrequests.c | 6 +- source3/nmbd/nmbd_mynames.c | 14 +- source3/nmbd/nmbd_namelistdb.c | 357 +++++++++++++++++++---------------- source3/nmbd/nmbd_subnetdb.c | 18 +- source3/nmbd/nmbd_winsserver.c | 15 +- 5 files changed, 229 insertions(+), 181 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index d05036b3ee..790d19d609 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -349,7 +349,7 @@ subnet %s - name not found.\n", namestr(&nmb->question.question_name), names_added = 0; - namerec = subrec->namelist; + namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); while (buf < bufend) { @@ -397,7 +397,7 @@ subnet %s - name not found.\n", namestr(&nmb->question.question_name), buf = buf0 + 18*names_added; - namerec = namerec->next; + namerec = (struct name_record *)ubi_trNext( namerec ); if (!namerec) { @@ -408,7 +408,7 @@ subnet %s - name not found.\n", namestr(&nmb->question.question_name), if (uni_subrec != subrec) { subrec = uni_subrec; - namerec = subrec->namelist; + namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); } } if (!namerec) diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index f0330c00b7..ba42274165 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -155,13 +155,15 @@ void release_my_names(void) { struct name_record *namerec, *nextnamerec; - for (namerec = subrec->namelist; namerec; namerec = nextnamerec) + for (namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); + namerec; + namerec = nextnamerec) { - nextnamerec = namerec->next; + nextnamerec = (struct name_record *)ubi_trNext( namerec ); if( (namerec->data.source == SELF_NAME) && !NAME_IS_DEREGISTERING(namerec) ) - release_name(subrec, namerec, standard_success_release, - NULL, NULL); + release_name( subrec, namerec, standard_success_release, + NULL, NULL); } } } @@ -178,7 +180,9 @@ void refresh_my_names(time_t t) { struct name_record *namerec; - for (namerec = subrec->namelist; namerec; namerec = namerec->next) + for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); + namerec; + namerec = (struct name_record *)ubi_trNext( namerec ) ) { /* Each SELF name has an individual time to be refreshed. */ if( (namerec->data.source == SELF_NAME) diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index f9a348eeea..4454cdfed0 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -32,215 +32,233 @@ extern char **my_netbios_names; uint16 samba_nb_type = 0; /* samba's NetBIOS name type */ -/**************************************************************************** - Set Samba's NetBIOS name type. - ****************************************************************************/ - +/* ************************************************************************** ** + * Set Samba's NetBIOS name type. + * ************************************************************************** ** + */ void set_samba_nb_type(void) -{ + { if( lp_wins_support() || (*lp_wins_server()) ) - samba_nb_type = NB_MFLAG; /* samba is a 'hybrid' node type */ + samba_nb_type = NB_MFLAG; /* samba is a 'hybrid' node type. */ else - samba_nb_type = NB_BFLAG; /* samba is broadcast-only node type */ -} - -/**************************************************************************** - Returns True if the netbios name is ^1^2__MSBROWSE__^2^1. - - Note: This name is registered if as a master browser or backup browser - you are responsible for a workgroup (when you announce a domain by - broadcasting on your local subnet, you announce it as coming from this - name: see announce_host()). - - **************************************************************************/ - + samba_nb_type = NB_BFLAG; /* samba is broadcast-only node type. */ + } /* set_samba_nb_type */ + +/* ************************************************************************** ** + * Returns True if the netbios name is ^1^2__MSBROWSE__^2^1. + * + * Note: This name is registered if as a master browser or backup browser + * you are responsible for a workgroup (when you announce a domain by + * broadcasting on your local subnet, you announce it as coming from this + * name: see announce_host()). + * + * ************************************************************************** ** + */ BOOL ms_browser_name( char *name, int type ) -{ + { return( strequal( name, MSBROWSE ) && (type == 0x01) ); -} - -/**************************************************************************** - Add a netbios name into a namelist. - **************************************************************************/ - -static void add_name_to_namelist(struct subnet_record *subrec, - struct name_record *namerec) -{ - struct name_record *namerec2; + } /* ms_browser_name */ - if (!subrec->namelist) +/* ************************************************************************** ** + * Convert a NetBIOS name to upper case. + * ************************************************************************** ** + */ +static void upcase_name( struct nmb_name *target, struct nmb_name *source ) { - subrec->namelist = namerec; - namerec->prev = NULL; - namerec->next = NULL; - return; - } - - for( namerec2 = subrec->namelist; namerec2->next; namerec2 = namerec2->next ) - ; - - namerec2->next = namerec; - namerec->next = NULL; - namerec->prev = namerec2; - namerec->subnet = subrec; + int i; - subrec->namelist_changed = True; -} + if( NULL != source ) + (void)memcpy( target, source, sizeof( struct nmb_name ) ); + + strupper( target->name ); + strupper( target->scope ); + + /* fudge... We're using a byte-by-byte compare, so we must be sure that + * unused space doesn't have garbage in it. + */ + for( i = strlen( target->name ); i < sizeof( target->name ); i++ ) + target->name[i] = '\0'; + for( i = strlen( target->scope ); i < sizeof( target->scope ); i++ ) + target->scope[i] = '\0'; + } /* upcase_name */ + +/* ************************************************************************** ** + * Add a new or overwrite an existing namelist entry. + * ************************************************************************** ** + */ +void update_name_in_namelist( struct subnet_record *subrec, + struct name_record *namerec ) + { + struct name_record *oldrec = NULL; -/**************************************************************************** - Remove a name from the namelist. - **************************************************************************/ + (void)ubi_trInsert( subrec->namelist, namerec, &(namerec->name), &oldrec ); + if( oldrec ) + { + if( oldrec->data.ip ) + free( oldrec->data.ip ); + free( oldrec ); + } + } /* update_name_in_namelist */ +/* ************************************************************************** ** + * Remove a name from the namelist. + * ************************************************************************** ** + */ void remove_name_from_namelist( struct subnet_record *subrec, - struct name_record *namerec ) -{ - if (namerec->next) - namerec->next->prev = namerec->prev; - if (namerec->prev) - namerec->prev->next = namerec->next; - - if(namerec == subrec->namelist) - subrec->namelist = namerec->next; + struct name_record *namerec ) + { + (void)ubi_trRemove( subrec->namelist, namerec ); if(namerec->data.ip != NULL) free((char *)namerec->data.ip); free((char *)namerec); subrec->namelist_changed = True; -} - - -/**************************************************************************** - Find a name in a subnet. - **************************************************************************/ - -struct name_record *find_name_on_subnet(struct subnet_record *subrec, - struct nmb_name *nmbname, BOOL self_only) -{ - struct name_record *namerec = subrec->namelist; - struct name_record *name_ret; - - for (name_ret = namerec; name_ret; name_ret = name_ret->next) + } /* remove_name_from_namelist */ + +/* ************************************************************************** ** + * Find a name in a subnet. + * ************************************************************************** ** + */ +struct name_record *find_name_on_subnet( struct subnet_record *subrec, + struct nmb_name *nmbname, + BOOL self_only ) { - if (nmb_name_equal(&name_ret->name, nmbname)) + struct nmb_name uc_name[1]; + struct name_record *name_ret; + + upcase_name( uc_name, nmbname ); + name_ret = (struct name_record *)ubi_trFind( subrec->namelist, uc_name ); + if( name_ret ) { - /* Self names only - these include permanent names. */ - if (self_only && (name_ret->data.source != SELF_NAME) && - (name_ret->data.source != PERMANENT_NAME) ) + /* Self names only - these include permanent names. */ + if( self_only + && (name_ret->data.source != SELF_NAME) + && (name_ret->data.source != PERMANENT_NAME) ) { - continue; + DEBUG( 9, + ( "find_name_on_subnet: on subnet %s - self name %s NOT FOUND\n", + subrec->subnet_name, namestr(nmbname) ) ); + return( NULL ); } - DEBUG(9,("find_name_on_subnet: on subnet %s - found name %s source=%d\n", - subrec->subnet_name, namestr(nmbname), name_ret->data.source)); - return name_ret; + DEBUG( 9, ("find_name_on_subnet: on subnet %s - found name %s source=%d\n", + subrec->subnet_name, namestr(nmbname), name_ret->data.source) ); + return( name_ret ); } - } - DEBUG(9,("find_name_on_subnet: on subnet %s - name %s NOT FOUND\n", - subrec->subnet_name, namestr(nmbname))); - return NULL; -} - -/**************************************************************************** - Find a name over all known broadcast subnets. -**************************************************************************/ - -struct name_record *find_name_for_remote_broadcast_subnet( struct nmb_name *nmbname, - BOOL self_only ) -{ + DEBUG( 9, + ( "find_name_on_subnet: on subnet %s - name %s NOT FOUND\n", + subrec->subnet_name, namestr(nmbname) ) ); + return( NULL ); + } /* find_name_on_subnet */ + +/* ************************************************************************** ** + * Find a name over all known broadcast subnets. + * ************************************************************************** ** + */ +struct name_record *find_name_for_remote_broadcast_subnet( + struct nmb_name *nmbname, + BOOL self_only ) + { struct subnet_record *subrec; - struct name_record *namerec = NULL; + struct name_record *namerec = NULL; for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) ) - { + { if( NULL != (namerec = find_name_on_subnet(subrec, nmbname, self_only)) ) break; - } + } - return namerec; -} + return( namerec ); + } /* find_name_for_remote_broadcast_subnet */ -/**************************************************************************** - Update the ttl of an entry in a subnet name list. - ****************************************************************************/ - +/* ************************************************************************** ** + * Update the ttl of an entry in a subnet name list. + * ************************************************************************** ** + */ void update_name_ttl( struct name_record *namerec, int ttl ) { time_t time_now = time(NULL); - if(namerec->data.death_time != PERMANENT_TTL) + if( namerec->data.death_time != PERMANENT_TTL ) namerec->data.death_time = time_now + ttl; namerec->data.refresh_time = time_now + (ttl/2); namerec->subnet->namelist_changed = True; -} - -/**************************************************************************** - Add an entry to a subnet name list. - ****************************************************************************/ - -struct name_record *add_name_to_subnet(struct subnet_record *subrec, - char *name, int type, uint16 nb_flags, int ttl, - enum name_source source, int num_ips, struct in_addr *iplist) +} /* update_name_ttl */ + +/* ************************************************************************** ** + * Add an entry to a subnet name list. + * ************************************************************************** ** + */ +struct name_record *add_name_to_subnet( struct subnet_record *subrec, + char *name, + int type, + uint16 nb_flags, + int ttl, + enum name_source source, + int num_ips, + struct in_addr *iplist) { struct name_record *namerec; time_t time_now = time(NULL); - if((namerec = (struct name_record *)malloc(sizeof(*namerec))) == NULL) + namerec = (struct name_record *)malloc( sizeof(*namerec) ); + if( NULL == namerec ) { - DEBUG(0,("add_name_to_subnet: malloc fail.\n")); - return NULL; + DEBUG( 0, ( "add_name_to_subnet: malloc fail.\n" ) ); + return( NULL ); } - bzero((char *)namerec,sizeof(*namerec)); - - namerec->subnet = subrec; - - namerec->data.num_ips = num_ips; + bzero( (char *)namerec, sizeof(*namerec) ); namerec->data.ip = (struct in_addr *)malloc( sizeof(struct in_addr) - * namerec->data.num_ips ); - if (!namerec->data.ip) + * num_ips ); + if( NULL == namerec->data.ip ) { - DEBUG(0,("add_name_to_subnet: malloc fail when creating ip_flgs.\n")); - free((char *)namerec); + DEBUG( 0, ( "add_name_to_subnet: malloc fail when creating ip_flgs.\n" ) ); + free( (char *)namerec ); return NULL; } - bzero( (char *)namerec->data.ip, - sizeof(struct in_addr) * namerec->data.num_ips ); - - memcpy( &namerec->data.ip[0], iplist, num_ips * sizeof(struct in_addr) ); + namerec->subnet = subrec; make_nmb_name( &namerec->name, name, type, scope ); - - /* Setup the death_time and refresh_time. */ - if(ttl == PERMANENT_TTL) - namerec->data.death_time = PERMANENT_TTL; - else - namerec->data.death_time = time_now + ttl; - - namerec->data.refresh_time = time_now + (ttl/2); + upcase_name( &namerec->name, NULL ); /* Enter the name as active. */ namerec->data.nb_flags = nb_flags | NB_ACTIVE; /* If it's our primary name, flag it as so. */ - if(strequal(my_netbios_names[0],name)) + if( strequal( my_netbios_names[0], name ) ) namerec->data.nb_flags |= NB_PERM; + /* Copy the IPs. */ + namerec->data.num_ips = num_ips; + memcpy( (namerec->data.ip), iplist, num_ips * sizeof(struct in_addr) ); + + /* Data source. */ namerec->data.source = source; - - add_name_to_namelist(subrec,namerec); + + /* Setup the death_time and refresh_time. */ + if( ttl == PERMANENT_TTL ) + namerec->data.death_time = PERMANENT_TTL; + else + namerec->data.death_time = time_now + ttl; + + namerec->data.refresh_time = time_now + (ttl/2); + + /* Now add the record to the name list. */ + update_name_in_namelist( subrec, namerec ); DEBUG( 3, ( "add_name_to_subnet: Added netbios name %s with first IP %s \ ttl=%d nb_flags=%2x to subnet %s\n", - namestr(&namerec->name), - inet_ntoa(*iplist), + namestr( &namerec->name ), + inet_ntoa( *iplist ), ttl, (unsigned int)nb_flags, - subrec->subnet_name) ); + subrec->subnet_name ) ); subrec->namelist_changed = True; @@ -324,12 +342,12 @@ BOOL find_ip_in_name_record( struct name_record *namerec, struct in_addr ip ) Utility function to add an IP address to a name record. ******************************************************************/ -void add_ip_to_name_record(struct name_record *namerec, struct in_addr new_ip) +void add_ip_to_name_record( struct name_record *namerec, struct in_addr new_ip ) { struct in_addr *new_list; /* Don't add one we already have. */ - if(find_ip_in_name_record( namerec, new_ip)) + if( find_ip_in_name_record( namerec, new_ip ) ) return; new_list = (struct in_addr *)malloc( (namerec->data.num_ips + 1) @@ -422,13 +440,15 @@ void expire_names_on_subnet(struct subnet_record *subrec, time_t t) struct name_record *namerec; struct name_record *next_namerec; - for (namerec = subrec->namelist; namerec; namerec = next_namerec) + for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); + namerec; + namerec = next_namerec ) { - next_namerec = namerec->next; + next_namerec = (struct name_record *)ubi_trNext( namerec ); if( (namerec->data.death_time != PERMANENT_TTL) && (namerec->data.death_time < t) ) { - if (namerec->data.source == SELF_NAME) + if( namerec->data.source == SELF_NAME ) { DEBUG( 3, ( "expire_names_on_subnet: Subnet %s not expiring SELF \ name %s\n", @@ -440,7 +460,7 @@ name %s\n", DEBUG(3,("expire_names_on_subnet: Subnet %s - removing expired name %s\n", subrec->subnet_name, namestr(&namerec->name))); - remove_name_from_namelist(subrec, namerec); + remove_name_from_namelist( subrec, namerec ); } } } @@ -477,8 +497,9 @@ void add_samba_names_to_subnet( struct subnet_record *subrec ) /* These names are added permanently (ttl of zero) and will NOT be refreshed. */ - if((subrec == unicast_subnet) || (subrec == wins_server_subnet) || - (subrec == remote_broadcast_subnet) ) + if( (subrec == unicast_subnet) + || (subrec == wins_server_subnet) + || (subrec == remote_broadcast_subnet) ) { struct subnet_record *bcast_subrecs; int i; @@ -499,14 +520,14 @@ void add_samba_names_to_subnet( struct subnet_record *subrec ) } - add_name_to_subnet(subrec,"*",0x0,samba_nb_type, PERMANENT_TTL, - PERMANENT_NAME, num_ips, iplist); - add_name_to_subnet(subrec,"*",0x20,samba_nb_type,PERMANENT_TTL, - PERMANENT_NAME, num_ips, iplist); - add_name_to_subnet(subrec,"__SAMBA__",0x20,samba_nb_type,PERMANENT_TTL, - PERMANENT_NAME, num_ips, iplist); - add_name_to_subnet(subrec,"__SAMBA__",0x00,samba_nb_type,PERMANENT_TTL, - PERMANENT_NAME, num_ips, iplist); + (void)add_name_to_subnet(subrec,"*",0x0,samba_nb_type, PERMANENT_TTL, + PERMANENT_NAME, num_ips, iplist); + (void)add_name_to_subnet(subrec,"*",0x20,samba_nb_type,PERMANENT_TTL, + PERMANENT_NAME, num_ips, iplist); + (void)add_name_to_subnet(subrec,"__SAMBA__",0x20,samba_nb_type,PERMANENT_TTL, + PERMANENT_NAME, num_ips, iplist); + (void)add_name_to_subnet(subrec,"__SAMBA__",0x00,samba_nb_type,PERMANENT_TTL, + PERMANENT_NAME, num_ips, iplist); if(iplist != &subrec->myip) free((char *)iplist); @@ -525,7 +546,9 @@ static void dump_subnet_namelist( struct subnet_record *subrec, FILE *fp) int i; fprintf(fp, "Subnet %s\n----------------------\n", subrec->subnet_name); - for (namerec = subrec->namelist; namerec; namerec = namerec->next) + for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); + namerec; + namerec = (struct name_record *)ubi_trNext( namerec ) ) { fprintf(fp,"\tName = %s\t", namestr(&namerec->name)); switch(namerec->data.source) @@ -609,15 +632,15 @@ void dump_all_namelists(void) for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec) ) - dump_subnet_namelist( subrec, fp); + dump_subnet_namelist( subrec, fp ); - if(!we_are_a_wins_client()) - dump_subnet_namelist(unicast_subnet, fp); + if( !we_are_a_wins_client() ) + dump_subnet_namelist( unicast_subnet, fp ); - if(remote_broadcast_subnet->namelist != NULL) - dump_subnet_namelist(remote_broadcast_subnet, fp); + if( remote_broadcast_subnet->namelist != NULL ) + dump_subnet_namelist( remote_broadcast_subnet, fp ); - if(wins_server_subnet != NULL) - dump_subnet_namelist( wins_server_subnet, fp); - fclose(fp); + if( wins_server_subnet != NULL ) + dump_subnet_namelist( wins_server_subnet, fp ); + fclose( fp ); } diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 34287bbe69..2b29d1b45b 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -73,6 +73,17 @@ static void add_subnet(struct subnet_record *subrec) subrec->prev = subrec2; } +/* CRH!!! */ +/* ************************************************************************** ** * This will go away when we move to a "real" database back-end. + * ************************************************************************** ** */ +int namelist_entry_compare( ubi_trItemPtr Item, ubi_trNodePtr Node ) + { + struct name_record *NR = (struct name_record *)Node; + + return( memcmp( Item, &(NR->name), sizeof(struct nmb_name) ) ); + } /* namelist_entry_compare */ +/* CRH!!! */ + /**************************************************************************** Create a subnet entry. ****************************************************************************/ @@ -131,8 +142,11 @@ for port %d. Error was %s\n", inet_ntoa(myip), DGRAM_PORT, strerror(errno))); return(NULL); } - bzero((char *)subrec,sizeof(*subrec)); - + bzero( (char *)subrec, sizeof(*subrec) ); + (void)ubi_trInitTree( subrec->namelist, + namelist_entry_compare, + ubi_trOVERWRITE ); + if((subrec->subnet_name = strdup(name)) == NULL) { DEBUG(0,("make_subnet: malloc fail for subnet name !\n")); diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 89e602606b..304e9f4dba 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1147,9 +1147,11 @@ static void process_wins_dmb_query_request(struct subnet_record *subrec, */ num_ips = 0; - for(namerec = subrec->namelist; namerec; namerec = namerec->next) + for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); + namerec; + namerec = (struct name_record *)ubi_trNext( namerec ) ) { - if(namerec->name.name_type == 0x1b) + if( namerec->name.name_type == 0x1b ) num_ips += namerec->data.num_ips; } @@ -1175,7 +1177,9 @@ static void process_wins_dmb_query_request(struct subnet_record *subrec, */ num_ips = 0; - for(namerec = subrec->namelist; namerec; namerec = namerec->next) + for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); + namerec; + namerec = (struct name_record *)ubi_trNext( namerec ) ) { if(namerec->name.name_type == 0x1b) { @@ -1550,7 +1554,10 @@ void wins_write_database(void) DEBUG(4,("wins_write_database: Dump of WINS name list.\n")); - for (namerec = wins_server_subnet->namelist; namerec; namerec = namerec->next) + for( namerec + = (struct name_record *)ubi_trFirst( wins_server_subnet->namelist ); + namerec; + namerec = (struct name_record *)ubi_trNext( namerec ) ) { int i; struct tm *tm; -- cgit From 7fda0a49cb665ba75c9071c1dc39fe93f103a9b5 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Tue, 23 Jun 1998 08:15:05 +0000 Subject: The function add_name_to_subnet(), in file nmbd_namelistdb.c, returns a pointer to the newly constructed name list entry. In most cases, this return value is ignored. The two exceptions are in asyncdns.c and nmbd_winsproxy.c. Most of the calls which ignored the return value were not cast to void, so I added the cast. This helped me sort out which calls really did use the return value. I also discovered one case, in nmbd_winsserver.c, in which the return value was being stored to a variable which, in turn, was not used. Chris -)----- (This used to be commit 384122d165ed6d5d211a29e5a63a63bf5cd82c75) --- source3/nmbd/nmbd_become_lmb.c | 5 +++-- source3/nmbd/nmbd_lmhosts.c | 6 +++--- source3/nmbd/nmbd_namelistdb.c | 4 ++-- source3/nmbd/nmbd_nameregister.c | 9 ++++++--- source3/nmbd/nmbd_winsproxy.c | 5 +++-- source3/nmbd/nmbd_winsserver.c | 16 +++++++--------- 6 files changed, 24 insertions(+), 21 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index b97da7d8b4..7329de6f69 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -43,8 +43,9 @@ void insert_permanent_name_into_unicast( struct subnet_record *subrec, if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) == NULL) { /* The name needs to be created on the unicast subnet. */ - add_name_to_subnet( unicast_subnet, nmbname->name, nmbname->name_type, - nb_type, PERMANENT_TTL, PERMANENT_NAME, 1, &subrec->myip); + (void)add_name_to_subnet( unicast_subnet, nmbname->name, + nmbname->name_type, nb_type, + PERMANENT_TTL, PERMANENT_NAME, 1, &subrec->myip); } else { diff --git a/source3/nmbd/nmbd_lmhosts.c b/source3/nmbd/nmbd_lmhosts.c index f4d520b1cf..158988813b 100644 --- a/source3/nmbd/nmbd_lmhosts.c +++ b/source3/nmbd/nmbd_lmhosts.c @@ -64,13 +64,13 @@ void load_lmhosts_file(char *fname) if(name_type == -1) { /* Add the (0) and (0x20) names directly into the namelist for this subnet. */ - add_name_to_subnet(subrec,name,0x00,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr); - add_name_to_subnet(subrec,name,0x20,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr); + (void)add_name_to_subnet(subrec,name,0x00,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr); + (void)add_name_to_subnet(subrec,name,0x20,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr); } else { /* Add the given name type to the subnet namelist. */ - add_name_to_subnet(subrec,name,name_type,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr); + (void)add_name_to_subnet(subrec,name,name_type,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr); } } diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 4454cdfed0..d2c9ea2e71 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -280,8 +280,8 @@ void standard_success_register(struct subnet_record *subrec, namerec = find_name_on_subnet( subrec, nmbname, FIND_SELF_NAME ); if( NULL == namerec ) - add_name_to_subnet( subrec, nmbname->name, nmbname->name_type, - nb_flags, ttl, SELF_NAME, 1, ®istered_ip ); + (void)add_name_to_subnet( subrec, nmbname->name, nmbname->name_type, + nb_flags, ttl, SELF_NAME, 1, ®istered_ip ); else update_name_ttl( namerec, ttl ); } diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index a4b8d4d65a..270a3ef6a5 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -277,11 +277,14 @@ static BOOL multihomed_register_name( struct nmb_name *nmbname, uint16 nb_flags, return True; } - for(subrec = FIRST_SUBNET, i = 0; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec), i++ ) + for( subrec = FIRST_SUBNET, i = 0; + subrec; + subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec), i++ ) ip_list[i] = subrec->myip; - add_name_to_subnet(unicast_subnet, nmbname->name, nmbname->name_type, - nb_flags, lp_max_ttl(), SELF_NAME, num_ips, ip_list); + (void)add_name_to_subnet( unicast_subnet, nmbname->name, nmbname->name_type, + nb_flags, lp_max_ttl(), SELF_NAME, + num_ips, ip_list); /* Now try and register the name, num_ips times. On the last time use the given success and fail functions. */ diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index 97caef7f82..5635124bcd 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -78,8 +78,9 @@ returned for name %s.\n", namestr(nmbname) )); if(rrec == PERMANENT_TTL) ttl = lp_max_ttl(); - namerec = add_name_to_subnet( orig_broadcast_subnet, nmbname->name, nmbname->name_type, - nb_flags, ttl, WINS_PROXY_NAME, num_ips, iplist); + namerec = add_name_to_subnet( orig_broadcast_subnet, nmbname->name, + nmbname->name_type, nb_flags, ttl, + WINS_PROXY_NAME, num_ips, iplist ); if(iplist != &ip) free((char *)iplist); diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 304e9f4dba..e8dd78f1ab 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -268,16 +268,14 @@ BOOL initialise_wins(void) /* add all entries that have 60 seconds or more to live */ if ((ttl - 60) > time_now || ttl == PERMANENT_TTL) { - struct name_record *namerec; - if(ttl != PERMANENT_TTL) ttl -= time_now; - DEBUG(4, ("initialise_wins: add name: %s#%02x ttl = %d first IP %s flags = %2x\n", + DEBUG( 4, ("initialise_wins: add name: %s#%02x ttl = %d first IP %s flags = %2x\n", name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); - namerec = add_name_to_subnet(wins_server_subnet, name, type, nb_flags, - ttl, REGISTER_NAME, num_ips, ip_list); + (void)add_name_to_subnet( wins_server_subnet, name, type, nb_flags, + ttl, REGISTER_NAME, num_ips, ip_list ); } else @@ -834,8 +832,8 @@ is one of our (WINS server) names. Denying registration.\n", namestr(question) ) * Name did not exist - add it. */ - add_name_to_subnet(subrec, question->name, question->name_type, - nb_flags, ttl, REGISTER_NAME, 1, &from_ip); + (void)add_name_to_subnet( subrec, question->name, question->name_type, + nb_flags, ttl, REGISTER_NAME, 1, &from_ip ); send_wins_name_registration_response(0, ttl, p); } @@ -1123,8 +1121,8 @@ is one of our (WINS server) names. Denying registration.\n", namestr(question) ) * Name did not exist - add it. */ - add_name_to_subnet(subrec, question->name, question->name_type, - nb_flags, ttl, REGISTER_NAME, 1, &from_ip); + (void)add_name_to_subnet( subrec, question->name, question->name_type, + nb_flags, ttl, REGISTER_NAME, 1, &from_ip ); send_wins_name_registration_response(0, ttl, p); } -- cgit From bc39cff279ef3df174c1d1408f90e88666e64237 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 25 Jun 1998 23:51:28 +0000 Subject: clitar.c: Fixed gcc warning with comment in /* */ code. nmbd_winsserver.c: Remember to free packet in multi-homed register code. Use correct query_name_from_wins_server call instead of query_name call in multihomed code. Jeremy. (This used to be commit 6e995802fecb4474003db55a69c9e1663737aade) --- source3/nmbd/nmbd_winsserver.c | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index e8dd78f1ab..f663362706 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -881,6 +881,10 @@ static void wins_multihomed_register_query_success(struct subnet_record *subrec, DEBUG(3,("wins_multihomed_register_query_success: name %s is not in the correct state to add \ a subsequent IP addess.\n", namestr(question_name) )); send_wins_name_registration_response(RFS_ERR, 0, orig_reg_packet); + + orig_reg_packet->locked = False; + free_packet(orig_reg_packet); + return; } @@ -889,6 +893,8 @@ a subsequent IP addess.\n", namestr(question_name) )); update_name_ttl(namerec, ttl); send_wins_name_registration_response(0, ttl, orig_reg_packet); + orig_reg_packet->locked = False; + free_packet(orig_reg_packet); } /*********************************************************************** @@ -912,6 +918,9 @@ static void wins_multihomed_register_query_fail(struct subnet_record *subrec, DEBUG(3,("wins_multihomed_register_query_fail: Registering machine at IP %s failed to answer \ query successfully for name %s.\n", inet_ntoa(orig_reg_packet->ip), namestr(question_name) )); send_wins_name_registration_response(RFS_ERR, 0, orig_reg_packet); + + orig_reg_packet->locked = False; + free_packet(orig_reg_packet); return; } @@ -1100,20 +1109,21 @@ is one of our (WINS server) names. Denying registration.\n", namestr(question) ) userdata->userdata_len = sizeof(struct packet_struct *); memcpy(userdata->data, (char *)&p, sizeof(struct packet_struct *) ); - /* - * As query_name uses the subnet broadcast address as the destination - * of the packet we temporarily change the subnet broadcast address to - * be the IP address of the requesting machine and send the packet. This - * is a *horrible* hack but the alternative is to add the destination - * address parameter to all query_name() calls. I hate this code :-). + /* + * Use the new call to send a query directly to an IP address. + * This sends the query directly to the IP address, and ensures + * the recursion desired flag is not set (you were right Luke :-). + * This function should *only* be called from the WINS server + * code. JRA. */ - subrec->bcast_ip = p->ip; - query_name( subrec, question->name, question->name_type, - wins_multihomed_register_query_success, - wins_multihomed_register_query_fail, - userdata); - subrec->bcast_ip = ipzero; + query_name_from_wins_server( p->ip, + question->name, + question->name_type, + wins_multihomed_register_query_success, + wins_multihomed_register_query_fail, + userdata ); + return; } -- cgit From d8b0a8bab2334e9214975e3ac35c1556c4030fd9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 27 Jun 1998 00:27:44 +0000 Subject: nisppass.c: Fixed incorrect parameter usage. nmbd_become_lmb.c: Add 'force_new_election' parameter to some functions. This allows the start of the election to be done *after* the demotion from local master browser is done. Also changed code so release of 1d name is done immediately to allow other local master to gain it. nmbd_elections.c: Ensured no elections are run until we have registered the WORKGROUP<1e> name that we must listen on to participate in elections. nmbd_incomingdgrams.c: Use force_new_election code. nmbd_namelistdb.c: Make update_name_in_namelist static. nmbd_subnetdb.c: Fix bug in comparison function. We cannot use memcmp as structure packing may make this fail. nmbd_packets.c: Ensure that we only send one release packet when sending a broadcast packet. nmbd_workgroupdb.c: Ensure we put the correct value in the ElectionCriterion field. nmblib.c: Ensure make_nmb_name zero's the struct nmb_name. Jeremy. (This used to be commit 1fcb094ba04f01be1261ac92198c25b21b0d5ad5) --- source3/nmbd/nmbd_become_lmb.c | 83 ++++++++++++++++++++++++-------------- source3/nmbd/nmbd_elections.c | 43 +++++++++++++++++--- source3/nmbd/nmbd_incomingdgrams.c | 9 +---- source3/nmbd/nmbd_namelistdb.c | 2 +- source3/nmbd/nmbd_packets.c | 11 +++++ source3/nmbd/nmbd_subnetdb.c | 17 +++++++- source3/nmbd/nmbd_workgroupdb.c | 2 +- 7 files changed, 122 insertions(+), 45 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index 7329de6f69..f66723eb17 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -78,7 +78,8 @@ static void remove_permanent_name_from_unicast( struct subnet_record *subrec, state back to potential browser, or none. ******************************************************************/ -static void reset_workgroup_state( struct subnet_record *subrec, char *workgroup_name ) +static void reset_workgroup_state( struct subnet_record *subrec, char *workgroup_name, + BOOL force_new_election ) { struct work_record *work; struct server_record *servrec; @@ -129,6 +130,8 @@ in workgroup %s on subnet %s\n", remove_permanent_name_from_unicast( subrec, &nmbname); + if(force_new_election) + work->needelection = True; } /******************************************************************* @@ -140,11 +143,15 @@ void unbecome_local_master_success(struct subnet_record *subrec, struct nmb_name *released_name, struct in_addr released_ip) { + BOOL force_new_election = False; + + memcpy((char *)&force_new_election, userdata->data, sizeof(BOOL)); + DEBUG(3,("unbecome_local_master_success: released name %s.\n", namestr(released_name))); /* Now reset the workgroup and server state. */ - reset_workgroup_state( subrec, released_name->name ); + reset_workgroup_state( subrec, released_name->name, force_new_election ); DEBUG(0,("\n%s ***** Samba name server %s has stopped being a local master browser for workgroup %s \ on subnet %s *****\n\n", timestring(), global_myname, released_name->name, subrec->subnet_name)); @@ -159,6 +166,10 @@ void unbecome_local_master_fail(struct subnet_record *subrec, struct response_re struct nmb_name *fail_name) { struct name_record *namerec; + struct userdata_struct *userdata = rrec->userdata; + BOOL force_new_election = False; + + memcpy((char *)&force_new_election, userdata->data, sizeof(BOOL)); DEBUG(0,("unbecome_local_master_fail: failed to release name %s. \ Removing from namelist anyway.\n", namestr(fail_name))); @@ -169,19 +180,18 @@ Removing from namelist anyway.\n", namestr(fail_name))); remove_name_from_namelist(subrec, namerec); /* Now reset the workgroup and server state. */ - reset_workgroup_state( subrec, fail_name->name ); + reset_workgroup_state( subrec, fail_name->name, force_new_election ); DEBUG(0,("\n%s ***** Samba name server %s has stopped being a local master browser for workgroup %s \ on subnet %s *****\n\n", timestring(), global_myname, fail_name->name, subrec->subnet_name)); - } /******************************************************************* - Utility function to remove the WORKGROUP<1d> name called by both - success and fail of releasing the MSBROWSE name. + Utility function to remove the WORKGROUP<1d> name. ******************************************************************/ -void release_1d_name( struct subnet_record *subrec, char *workgroup_name) +static void release_1d_name( struct subnet_record *subrec, char *workgroup_name, + BOOL force_new_election) { struct nmb_name nmbname; struct name_record *namerec; @@ -189,10 +199,26 @@ void release_1d_name( struct subnet_record *subrec, char *workgroup_name) make_nmb_name(&nmbname, workgroup_name, 0x1d, scope); if((namerec = find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME))!=NULL) { + struct userdata_struct *userdata; + + if((userdata = (struct userdata_struct *)malloc( + sizeof(struct userdata_struct) + sizeof(BOOL))) == NULL) + { + DEBUG(0,("release_1d_name: malloc fail.\n")); + return; + } + + userdata->copy_fn = NULL; + userdata->free_fn = NULL; + userdata->userdata_len = sizeof(BOOL); + memcpy((char *)userdata->data, &force_new_election, sizeof(BOOL)); + release_name(subrec, namerec, unbecome_local_master_success, unbecome_local_master_fail, - NULL); + userdata); + + free((char *)userdata); } } @@ -210,8 +236,6 @@ static void release_msbrowse_name_success(struct subnet_record *subrec, /* Remove the permanent MSBROWSE name added into the unicast subnet. */ remove_permanent_name_from_unicast( subrec, released_name); - - release_1d_name( subrec, userdata->data ); } /******************************************************************* @@ -222,7 +246,6 @@ static void release_msbrowse_name_fail( struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *fail_name) { - struct userdata_struct *userdata = rrec->userdata; struct name_record *namerec; DEBUG(4,("release_msbrowse_name_fail: Failed to release name %s on subnet %s\n.", @@ -235,20 +258,19 @@ static void release_msbrowse_name_fail( struct subnet_record *subrec, /* Remove the permanent MSBROWSE name added into the unicast subnet. */ remove_permanent_name_from_unicast( subrec, fail_name); - - release_1d_name( subrec, userdata->data ); } /******************************************************************* - Unbecome the local master browser. + Unbecome the local master browser. If force_new_election is true, restart + the election process after we've unbecome the local master. ******************************************************************/ -void unbecome_local_master_browser(struct subnet_record *subrec, struct work_record *work) +void unbecome_local_master_browser(struct subnet_record *subrec, struct work_record *work, + BOOL force_new_election) { struct server_record *servrec; struct name_record *namerec; struct nmb_name nmbname; - struct userdata_struct *userdata; /* Sanity check. */ @@ -267,17 +289,12 @@ in workgroup %s on subnet %s\n", /* Set the state to unbecoming. */ work->mst_state = MST_UNBECOMING_MASTER; - /* Setup the userdata for the MSBROWSE name release. */ - if((userdata = (struct userdata_struct *)malloc( sizeof(struct userdata_struct) + sizeof(fstring)+1)) == NULL) - { - DEBUG(0,("unbecome_local_master_browser: malloc fail.\n")); - return; - } + /* + * Release the WORKGROUP<1d> name asap to allow another machine to + * claim it. + */ - userdata->copy_fn = NULL; - userdata->free_fn = NULL; - userdata->userdata_len = strlen(work->work_group)+1; - pstrcpy(userdata->data, work->work_group); + release_1d_name( subrec, work->work_group, force_new_election); /* Deregister any browser names we may have. */ make_nmb_name(&nmbname, MSBROWSE, 0x1, scope); @@ -286,10 +303,16 @@ in workgroup %s on subnet %s\n", release_name(subrec, namerec, release_msbrowse_name_success, release_msbrowse_name_fail, - userdata); + NULL); } - free((char *)userdata); + /* + * Ensure we have sent and processed these release packets + * before returning - we don't want to process any election + * packets before dealing with the 1d release. + */ + + retransmit_or_expire_response_records(time(NULL)); } /**************************************************************************** @@ -394,7 +417,7 @@ workgroup %s on subnet %s\n", fail_name->name, subrec->subnet_name)); } /* Roll back all the way by calling unbecome_local_master_browser(). */ - unbecome_local_master_browser(subrec, work); + unbecome_local_master_browser(subrec, work, False); } /**************************************************************************** @@ -465,7 +488,7 @@ in workgroup %s on subnet %s\n", return; } - reset_workgroup_state( subrec, work->work_group ); + reset_workgroup_state( subrec, work->work_group, False ); DEBUG(0,("become_local_master_fail1: Failed to become a local master browser for \ workgroup %s on subnet %s. Couldn't register name %s.\n", diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 569b653129..4be5b73508 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -26,6 +26,8 @@ extern int DEBUGLEVEL; +extern pstring scope; + extern pstring global_myname; extern fstring global_myworkgroup; @@ -58,7 +60,7 @@ static void send_election_dgram(struct subnet_record *subrec, char *workgroup_na p = skip_string(p,1); send_mailslot(False, BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), - server_name, 0, + global_myname, 0, workgroup_name, 0x1e, subrec->bcast_ip, subrec->myip); } @@ -117,7 +119,7 @@ static void check_for_master_browser_fail( struct subnet_record *subrec, not to become the local master, but we still need one, having detected that one doesn't exist. */ - send_election_dgram(subrec, work->work_group, 0, 0, global_myname); + send_election_dgram(subrec, work->work_group, 0, 0, ""); } } } @@ -171,8 +173,8 @@ void run_elections(time_t t) struct subnet_record *subrec; - /* Send election packets once a second - note */ - if (lastime && (t - lastime <= 0)) + /* Send election packets once every 2 seconds - note */ + if (lastime && (t - lastime < 2)) return; lastime = t; @@ -185,6 +187,20 @@ void run_elections(time_t t) { if (work->RunningElection) { + /* + * We can only run an election for a workgroup if we have + * registered the WORKGROUP<1e> name, as that's the name + * we must listen to. + */ + struct nmb_name nmbname; + + make_nmb_name(&nmbname, work->work_group, 0x1e, scope); + if(find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME)==NULL) { + DEBUG(8,("run_elections: Cannot send election packet yet as name %s not \ +yet registered on subnet %s\n", namestr(&nmbname), subrec->subnet_name )); + continue; + } + send_election_dgram(subrec, work->work_group, work->ElectionCriterion, t - StartupTime, global_myname); @@ -308,7 +324,7 @@ is not my workgroup.\n", work->work_group, subrec->subnet_name )); DEBUG(3,("process_election: >>> Lost election for workgroup %s on subnet %s <<<\n", work->work_group, subrec->subnet_name )); if (AM_LOCAL_MASTER_BROWSER(work)) - unbecome_local_master_browser(subrec, work); + unbecome_local_master_browser(subrec, work, False); } } } @@ -335,12 +351,29 @@ BOOL check_elections(void) /* Only start an election if we are in the potential browser state. */ if (work->needelection && !work->RunningElection && AM_POTENTIAL_MASTER_BROWSER(work)) { + /* + * We can only run an election for a workgroup if we have + * registered the WORKGROUP<1e> name, as that's the name + * we must listen to. + */ + struct nmb_name nmbname; + + make_nmb_name(&nmbname, work->work_group, 0x1e, scope); + if(find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME)==NULL) { + DEBUG(8,("check_elections: Cannot send election packet yet as name %s not \ +yet registered on subnet %s\n", namestr(&nmbname), subrec->subnet_name )); + continue; + } + DEBUG(3,("check_elections: >>> Starting election for workgroup %s on subnet %s <<<\n", work->work_group, subrec->subnet_name )); work->ElectionCount = 0; work->RunningElection = True; work->needelection = False; + + /* Send a force election packet to begin. */ + send_election_dgram(subrec, work->work_group, 0, 0, ""); } } } diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 62dc444e0c..daa321b3ae 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -318,12 +318,10 @@ a local master browser for workgroup %s and we think we are master. Forcing elec /* We should demote ourself and force an election. */ - unbecome_local_master_browser( subrec, work); + unbecome_local_master_browser( subrec, work, True); /* The actual election requests are handled in nmbd_election.c */ - - work->needelection = True; return; } @@ -722,10 +720,7 @@ request from %s IP %s state=0x%X\n", for (work = sr->workgrouplist; work; work = work->next) { if (AM_LOCAL_MASTER_BROWSER(work)) - { - unbecome_local_master_browser(sr, work); - work->needelection = True; - } + unbecome_local_master_browser(sr, work, True); } } } diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index d2c9ea2e71..b7f185deeb 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -86,7 +86,7 @@ static void upcase_name( struct nmb_name *target, struct nmb_name *source ) * Add a new or overwrite an existing namelist entry. * ************************************************************************** ** */ -void update_name_in_namelist( struct subnet_record *subrec, +static void update_name_in_namelist( struct subnet_record *subrec, struct name_record *namerec ) { struct name_record *oldrec = NULL; diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index e07391fb48..23db845348 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -602,6 +602,17 @@ struct response_record *queue_release_name( struct subnet_record *subrec, return NULL; } + /* + * For a broadcast release packet, only send once. + * This will cause us to remove the name asap. JRA. + */ + + if(bcast) + { + rrec->repeat_count = 0; + rrec->repeat_time = 0; + } + return rrec; } diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 2b29d1b45b..40ae1db1b3 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -75,12 +75,27 @@ static void add_subnet(struct subnet_record *subrec) /* CRH!!! */ /* ************************************************************************** ** * This will go away when we move to a "real" database back-end. + Note that we cannot use memcmp here as we have no control + over how the struct nmb_name structures are packed in memory. JRA. * ************************************************************************** ** */ int namelist_entry_compare( ubi_trItemPtr Item, ubi_trNodePtr Node ) { struct name_record *NR = (struct name_record *)Node; + struct nmb_name *nmbname = (struct nmb_name *)Item; + int ret; - return( memcmp( Item, &(NR->name), sizeof(struct nmb_name) ) ); + if(nmb_name_equal( &NR->name, nmbname)) + return 0; + + ret = strcmp( nmbname->name, NR->name.name); + if(ret) + return ret; + + ret = strcmp( nmbname->scope, NR->name.scope); + if(ret) + return ret; + + return nmbname->name_type - NR->name.name_type; } /* namelist_entry_compare */ /* CRH!!! */ diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 0b392680df..818875c820 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -125,7 +125,7 @@ static struct work_record *create_workgroup(char *name, int ttl) /* WfWg uses 01040b01 */ /* Win95 uses 01041501 */ /* NTAS uses ???????? */ - work->ElectionCriterion = (MAINTAIN_LIST)|(ELECTION_VERSION<<8); + work->ElectionCriterion = (MAINTAIN_LIST)|(BROWSER_ELECTION_VERSION<<8); work->ElectionCriterion |= (lp_os_level() << 24); if (lp_domain_master()) work->ElectionCriterion |= 0x80; -- cgit From fdb124c1cd0e91fa2a5f1c993a1df12fb866cca9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 27 Jun 1998 01:07:30 +0000 Subject: Added code to do elections when told to do so. Jeremy. (This used to be commit a38d903d2016202d470f1405e593be3c20404d72) --- source3/nmbd/nmbd_elections.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 4be5b73508..ceef961d5e 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -348,8 +348,15 @@ BOOL check_elections(void) { run_any_election |= work->RunningElection; - /* Only start an election if we are in the potential browser state. */ - if (work->needelection && !work->RunningElection && AM_POTENTIAL_MASTER_BROWSER(work)) + /* + * Start an election if we have any chance of winning. + * Note this is a change to the previous code, that would + * only run an election if nmbd was in the potential browser + * state. We need to run elections in any state if we're told + * to. JRA. + */ + + if (work->needelection && !work->RunningElection && lp_local_master()) { /* * We can only run an election for a workgroup if we have -- cgit From 06e42fa8659483495055eb3aab1982ebf3d0efa3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 29 Jun 1998 22:50:49 +0000 Subject: nmbd_elections.c: Removed force elections code to bring into line with 1.9.18. nmbd_namelistdb.c: Added comment for Chris. nmbd_subnetdb.c: Went back to Chris's comparison code as with the make_nmb_name change it all works now. lib/rpc/server/srv_netlog.c: Ensure we return 'account disabled' for disabled accounts, rather than crashing. Jeremy. (This used to be commit 4ab3d1682789319965a55edb37212b7671a743bb) --- source3/nmbd/nmbd_elections.c | 3 --- source3/nmbd/nmbd_namelistdb.c | 4 +++- source3/nmbd/nmbd_subnetdb.c | 19 +++++++++++++++++++ 3 files changed, 22 insertions(+), 4 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index ceef961d5e..5c85191ec2 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -378,9 +378,6 @@ yet registered on subnet %s\n", namestr(&nmbname), subrec->subnet_name )); work->ElectionCount = 0; work->RunningElection = True; work->needelection = False; - - /* Send a force election packet to begin. */ - send_election_dgram(subrec, work->work_group, 0, 0, ""); } } } diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index b7f185deeb..29d822550c 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -288,7 +288,9 @@ void standard_success_register(struct subnet_record *subrec, /******************************************************************* Utility function automatically called when a name refresh or register - fails. + fails. Note that this is only ever called on a broadcast subnet with + one IP address per name. This is why it can just delete the name + without enumerating the IP adresses. JRA. ******************************************************************/ void standard_fail_register( struct subnet_record *subrec, diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 40ae1db1b3..36a3ee9a27 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -74,6 +74,7 @@ static void add_subnet(struct subnet_record *subrec) } /* CRH!!! */ +#if 0 /* ************************************************************************** ** * This will go away when we move to a "real" database back-end. Note that we cannot use memcmp here as we have no control over how the struct nmb_name structures are packed in memory. JRA. @@ -97,6 +98,24 @@ int namelist_entry_compare( ubi_trItemPtr Item, ubi_trNodePtr Node ) return nmbname->name_type - NR->name.name_type; } /* namelist_entry_compare */ +#else +/* ************************************************************************** ** + * This will go away when we move to a "real" database back-end. + * ************************************************************************** ** + */ +int namelist_entry_compare( ubi_trItemPtr Item, ubi_trNodePtr Node ) + { + struct name_record *NR = (struct name_record *)Node; + + struct nmb_name *Iname = (struct nmb_name *)Item; + DEBUG(10, ("namelist_entry_compare: %d == memcmp( \"%s\", \"%s\", %d )\n", + memcmp( Item, &(NR->name), sizeof(struct nmb_name) ), + namestr(Iname), namestr(&NR->name), sizeof(struct nmb_name)) ); + + return( memcmp( Item, &(NR->name), sizeof(struct nmb_name) ) ); + } /* namelist_entry_compare */ + +#endif /* CRH!!! */ /**************************************************************************** -- cgit From 3daefed54e221b397f1eff43d2a83a61c4500fb1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 2 Jul 1998 18:49:08 +0000 Subject: chgpasswd.c: Fix from Peter Debus for Digital UNIX password change core dump bug. nmbd_subnetdb.c: Make namelist_entry_compare() static. nttrans.c: More NT SMB stuff. Jeremy. (This used to be commit 1925a29c6b355b8358ee99e5b876b6376aa7d628) --- source3/nmbd/nmbd_subnetdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 36a3ee9a27..20d924910d 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -79,7 +79,7 @@ static void add_subnet(struct subnet_record *subrec) Note that we cannot use memcmp here as we have no control over how the struct nmb_name structures are packed in memory. JRA. * ************************************************************************** ** */ -int namelist_entry_compare( ubi_trItemPtr Item, ubi_trNodePtr Node ) +static int namelist_entry_compare( ubi_trItemPtr Item, ubi_trNodePtr Node ) { struct name_record *NR = (struct name_record *)Node; struct nmb_name *nmbname = (struct nmb_name *)Item; @@ -103,7 +103,7 @@ int namelist_entry_compare( ubi_trItemPtr Item, ubi_trNodePtr Node ) * This will go away when we move to a "real" database back-end. * ************************************************************************** ** */ -int namelist_entry_compare( ubi_trItemPtr Item, ubi_trNodePtr Node ) +static int namelist_entry_compare( ubi_trItemPtr Item, ubi_trNodePtr Node ) { struct name_record *NR = (struct name_record *)Node; -- cgit From 59d07445b61e26321e3a1770c13756ac5948aabb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 14 Jul 1998 21:23:59 +0000 Subject: loadparm.c: With apologies to Charlton Heston and Pierre Boule. "You damn fools, you finally did it". Changed default security mode to be security=user. Yes this is a big (although small in code) change. It's something we've been discussing for a while, to finally wean people off the legacy security=share mode which is *never* what you want. Jeremy. nmbd_incomingrequests.c: Bug fix for nmbd core dumps caused by overrun. Found by . nttrans.c: More NT smb stuff. reply.c: Unlink will overwrite an existing file. Well you learn something new about POSIX every day. :-). server.c: Tidyup unreadable code. smbpasswd.c: Code to allow -U remote_username to allow ordinary users to change remote passwords if their NT username is different from their UNIX username. Patch from . Jeremy. (This used to be commit 4eccb47cfb3c8907a6558b6ea9a02b0184458e34) --- source3/nmbd/nmbd_incomingrequests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index 790d19d609..3c9438ace3 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -420,7 +420,7 @@ subnet %s - name not found.\n", namestr(&nmb->question.question_name), /* We don't send any stats as they could be used to attack the protocol. */ - bzero(buf,64); + bzero(buf,46); buf += 46; -- cgit From e6608b5279dcb258fa97d7719e854b72de84b9b9 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Fri, 24 Jul 1998 19:03:11 +0000 Subject: Converted the browser database to a ubi_dLinkList. This should reduce code size, etc. Also did a bit of work to add comments. Chris -)----- (This used to be commit d8b0a2104c05df957f0eb49c21388ec5a4858d98) --- source3/nmbd/nmbd_browserdb.c | 281 +++++++++++++++++++++++------------------ source3/nmbd/nmbd_browsesync.c | 4 +- 2 files changed, 161 insertions(+), 124 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c index ee3e4e4bde..293a129d42 100644 --- a/source3/nmbd/nmbd_browserdb.c +++ b/source3/nmbd/nmbd_browserdb.c @@ -5,6 +5,7 @@ Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 Copyright (C) Jeremy Allison 1994-1998 + Copyright (C) Christopher R. Hertel 1998 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -21,164 +22,198 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +/* -------------------------------------------------------------------------- ** + * Modified July 1998 by CRH. + * I converted this module to use the canned doubly-linked lists. I also + * added comments above the functions where possible. + */ #include "includes.h" -#include "smb.h" extern int DEBUGLEVEL; -/* This is our local master browser list database. */ -struct browse_cache_record *lmb_browserlist = NULL; - -/*************************************************************************** -Add a browser into the lmb list. -**************************************************************************/ - -static void add_to_lmb_browse_cache(struct browse_cache_record *browc) -{ - struct browse_cache_record *browc2; - - if (lmb_browserlist == NULL) +/* -------------------------------------------------------------------------- ** + * Variables... + * + * lmb_browserlist - This is our local master browser list. + */ + +ubi_dlNewList( lmb_browserlist ); + + +/* -------------------------------------------------------------------------- ** + * Functions... + */ + +/* ************************************************************************** ** + * Remove and free a browser list entry. + * + * Input: browc - A pointer to the entry to be removed from the list and + * freed. + * Output: none. + * + * ************************************************************************** ** + */ +static void remove_lmb_browser_entry( struct browse_cache_record *browc ) + { + free( (char *)ubi_dlRemThis( lmb_browserlist, browc ) ); + } /* remove_lmb_browser_entry */ + +/* ************************************************************************** ** + * Update a browser death time. + * + * Input: browc - Pointer to the entry to be updated. + * Output: none. + * + * ************************************************************************** ** + */ +void update_browser_death_time( struct browse_cache_record *browc ) { - lmb_browserlist = browc; - browc->prev = NULL; - browc->next = NULL; - return; - } - - for (browc2 = lmb_browserlist; browc2->next; browc2 = browc2->next) - ; - - browc2->next = browc; - browc->next = NULL; - browc->prev = browc2; -} - -/******************************************************************* -Remove a lmb browser entry. -******************************************************************/ - -void remove_lmb_browser_entry(struct browse_cache_record *browc) -{ - if (browc->prev) - browc->prev->next = browc->next; - if (browc->next) - browc->next->prev = browc->prev; - - if (lmb_browserlist == browc) - lmb_browserlist = browc->next; - - free((char *)browc); -} - -/**************************************************************************** -Update a browser death time. -****************************************************************************/ - -void update_browser_death_time(struct browse_cache_record *browc) -{ /* Allow the new lmb to miss an announce period before we remove it. */ - browc->death_time = time(NULL) + (CHECK_TIME_MST_ANNOUNCE + 2)*60; -} - -/**************************************************************************** -Create a browser entry. -****************************************************************************/ - -struct browse_cache_record *create_browser_in_lmb_cache(char *work_name, char *browser_name, - struct in_addr ip) -{ + browc->death_time = time(NULL) + ( (CHECK_TIME_MST_ANNOUNCE + 2) * 60 ); + } /* update_browser_death_time */ + +/* ************************************************************************** ** + * Create a browser entry and add it to the local master browser list. + * + * Input: work_name + * browser_name + * ip + * + * Output: Pointer to the new entry, or NULL if malloc() failed. + * + * ************************************************************************** ** + */ +struct browse_cache_record *create_browser_in_lmb_cache( char *work_name, + char *browser_name, + struct in_addr ip ) + { struct browse_cache_record *browc; - time_t now = time(NULL); + time_t now = time( NULL ); - browc = (struct browse_cache_record *)malloc(sizeof(*browc)); - - if (browc == NULL) - { - DEBUG(0,("create_browser_in_lmb_cache: malloc fail !\n")); - return(NULL); - } + browc = (struct browse_cache_record *)malloc( sizeof( *browc ) ); - bzero((char *)browc,sizeof(*browc)); + if( NULL == browc ) + { + DEBUG( 0, ("create_browser_in_lmb_cache: malloc fail !\n") ); + return( NULL ); + } + + bzero( (char *)browc, sizeof( *browc ) ); /* For a new lmb entry we want to sync with it after one minute. This will allow it time to send out a local announce and build its - browse list. */ - + browse list. + */ browc->sync_time = now + 60; /* Allow the new lmb to miss an announce period before we remove it. */ - browc->death_time = now + (CHECK_TIME_MST_ANNOUNCE + 2)*60; + browc->death_time = now + ( (CHECK_TIME_MST_ANNOUNCE + 2) * 60 ); - StrnCpy(browc->lmb_name, browser_name,sizeof(browc->lmb_name)-1); - StrnCpy(browc->work_group,work_name,sizeof(browc->work_group)-1); - strupper(browc->lmb_name); - strupper(browc->work_group); + StrnCpy( browc->lmb_name, browser_name, sizeof(browc->lmb_name)-1 ); + StrnCpy( browc->work_group, work_name, sizeof(browc->work_group)-1 ); + strupper( browc->lmb_name ); + strupper( browc->work_group ); browc->ip = ip; - add_to_lmb_browse_cache(browc); - - DEBUG(3,("create_browser_in_lmb_cache: Added lmb cache entry for workgroup %s name %s IP %s ttl %d\n", - browc->work_group, browc->lmb_name, inet_ntoa(ip), browc->death_time)); - - return(browc); -} - -/**************************************************************************** -Find a browser entry. -****************************************************************************/ + (void)ubi_dlAddTail( lmb_browserlist, browc ); + if( DEBUGLVL( 3 ) ) + { + Debug1( "nmbd_browserdb:create_browser_in_lmb_cache()\n" ); + Debug1( " Added lmb cache entry for workgroup %s ", browc->work_group ); + Debug1( "name %s IP %s ", browc->lmb_name, inet_ntoa(ip) ); + Debug1( "ttl %d\n", browc->death_time ); + } + + return( browc ); + } /* create_browser_in_lmb_cache */ + +/* ************************************************************************** ** + * Find a browser entry in the local master browser list. + * + * Input: browser_name - The name for which to search. + * + * Output: A pointer to the matching entry, or NULL if no match was found. + * + * ************************************************************************** ** + */ struct browse_cache_record *find_browser_in_lmb_cache( char *browser_name ) -{ - struct browse_cache_record *browc = NULL; + { + struct browse_cache_record *browc; - for( browc = lmb_browserlist; browc; browc = browc->next) - if(strequal( browser_name, browc->lmb_name)) + for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist ); + browc; + browc = (struct browse_cache_record *)ubi_dlNext( browc ) ) + if( strequal( browser_name, browc->lmb_name ) ) break; - return browc; -} - -/******************************************************************* - Expire timed out browsers in the browserlist. -******************************************************************/ - -void expire_lmb_browsers(time_t t) -{ + return( browc ); + } /* find_browser_in_lmb_cache */ + +/* ************************************************************************** ** + * Expire timed out browsers in the browserlist. + * + * Input: t - Expiration time. Entries with death times less than this + * value will be removed from the list. + * Output: none. + * + * ************************************************************************** ** + */ +void expire_lmb_browsers( time_t t ) + { struct browse_cache_record *browc; struct browse_cache_record *nextbrowc; - for (browc = lmb_browserlist; browc; browc = nextbrowc) - { - nextbrowc = browc->next; - - if (browc->death_time < t) + for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist ); + browc; + browc = nextbrowc ) { - DEBUG(3,("expire_lmb_browsers: Removing timed out lmb entry %s\n",browc->lmb_name)); - remove_lmb_browser_entry(browc); + nextbrowc = (struct browse_cache_record *)ubi_dlNext( browc ); + + if( browc->death_time < t ) + { + if( DEBUGLVL( 3 ) ) + { + Debug1( "nmbd_browserdb:expire_lmb_browsers()\n" ); + Debug1( " Removing timed out lmb entry %s\n", browc->lmb_name ); + } + remove_lmb_browser_entry( browc ); + } } - } -} - -/******************************************************************* - Remove browsers from a named workgroup in the browserlist. -******************************************************************/ - -void remove_workgroup_lmb_browsers(char *work_group) + } /* expire_lmb_browsers */ + +/* ************************************************************************** ** + * Remove browsers from a named workgroup in the browserlist. + * + * Input: work_group - The name of the work group which is to be removed + * from the browse list. + * Output: none. + * + * ************************************************************************** ** + */ +void remove_workgroup_lmb_browsers( char *work_group ) { struct browse_cache_record *browc; struct browse_cache_record *nextbrowc; - for (browc = lmb_browserlist; browc; browc = nextbrowc) - { - nextbrowc = browc->next; - - if (strequal(work_group, browc->work_group)) + for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist ); + browc; + browc = nextbrowc ) { - DEBUG(3,("remove_workgroup_browsers: Removing lmb entry %s\n",browc->lmb_name)); + nextbrowc = (struct browse_cache_record *)ubi_dlNext( browc ); + + if( strequal( work_group, browc->work_group ) ) + { + if( DEBUGLVL( 3 ) ) + { + Debug1( "nmbd_browserdb:remove_workgroup_browsers()\n" ); + Debug1( "Removing lmb entry %s\n", browc->lmb_name ); + } remove_lmb_browser_entry(browc); + } } - } -} + } /* remove_workgroup_lmb_browsers */ +/* ========================================================================== */ diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index c1f6aa5a6c..dd4a82d7f6 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -215,7 +215,9 @@ void dmb_expire_and_sync_browser_lists(time_t t) expire_lmb_browsers(t); - for (browc = lmb_browserlist; browc; browc = browc->next) + for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist ); + browc; + browc = (struct browse_cache_record *)ubi_dlNext( browc ) ) { if (browc->sync_time < t) sync_with_lmb(browc); -- cgit From 85474e07804f815a74de399654f28a80722449ab Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Sat, 25 Jul 1998 15:45:42 +0000 Subject: Cleaned up some testing code and made it more "permanent" looking. The NetBIOS name lists attached to the subnet records are now managed by the splay tree code. I am still working on the WINS database as a separate issue. Code is written, it's just a matter of incorporating it. CRH (This used to be commit 5ba96ddde4a4b2da2cc09190f5c6f0e633852f12) --- source3/nmbd/nmbd_subnetdb.c | 70 ++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 38 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 20d924910d..942175c9f8 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -73,51 +73,35 @@ static void add_subnet(struct subnet_record *subrec) subrec->prev = subrec2; } -/* CRH!!! */ -#if 0 -/* ************************************************************************** ** * This will go away when we move to a "real" database back-end. - Note that we cannot use memcmp here as we have no control - over how the struct nmb_name structures are packed in memory. JRA. - * ************************************************************************** ** */ -static int namelist_entry_compare( ubi_trItemPtr Item, ubi_trNodePtr Node ) - { - struct name_record *NR = (struct name_record *)Node; - struct nmb_name *nmbname = (struct nmb_name *)Item; - int ret; - - if(nmb_name_equal( &NR->name, nmbname)) - return 0; - - ret = strcmp( nmbname->name, NR->name.name); - if(ret) - return ret; - - ret = strcmp( nmbname->scope, NR->name.scope); - if(ret) - return ret; - - return nmbname->name_type - NR->name.name_type; - } /* namelist_entry_compare */ -#else /* ************************************************************************** ** - * This will go away when we move to a "real" database back-end. + * Comparison routine for ordering the splay-tree based namelists assoicated + * with each subnet record. + * + * Input: Item - Pointer to the comparison key. + * Node - Pointer to a node the splay tree. + * + * Output: The return value will be <0 , ==0, or >0 depending upon the + * ordinal relationship of the two keys. + * * ************************************************************************** ** */ static int namelist_entry_compare( ubi_trItemPtr Item, ubi_trNodePtr Node ) { struct name_record *NR = (struct name_record *)Node; - struct nmb_name *Iname = (struct nmb_name *)Item; - DEBUG(10, ("namelist_entry_compare: %d == memcmp( \"%s\", \"%s\", %d )\n", - memcmp( Item, &(NR->name), sizeof(struct nmb_name) ), - namestr(Iname), namestr(&NR->name), sizeof(struct nmb_name)) ); + if( DEBUGLVL( 10 ) ) + { + struct nmb_name *Iname = (struct nmb_name *)Item; + + Debug1( "nmbd_subnetdb:namelist_entry_compare()\n" ); + Debug1( "%d == memcmp( \"%s\", \"%s\", %d )\n", + memcmp( Item, &(NR->name), sizeof(struct nmb_name) ), + namestr(Iname), namestr(&NR->name), sizeof(struct nmb_name) ); + } return( memcmp( Item, &(NR->name), sizeof(struct nmb_name) ) ); } /* namelist_entry_compare */ -#endif -/* CRH!!! */ - /**************************************************************************** Create a subnet entry. ****************************************************************************/ @@ -148,15 +132,25 @@ static struct subnet_record *make_subnet(char *name, enum subnet_type type, if((nmb_sock = open_socket_in(SOCK_DGRAM, global_nmb_port,0, myip.s_addr)) == -1) { - DEBUG(0,("make_subnet: Failed to open nmb socket on interface %s \ -for port %d. Error was %s\n", inet_ntoa(myip), global_nmb_port, strerror(errno))); + if( DEBUGLVL( 0 ) ) + { + Debug1( "nmbd_subnetdb:make_subnet()\n" ); + Debug1( " Failed to open nmb socket on interface %s ", inet_ntoa(myip) ); + Debug1( "for port %d. ", global_nmb_port ); + Debug1( "Error was %s\n", strerror(errno) ); + } return NULL; } if((dgram_sock = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3, myip.s_addr)) == -1) { - DEBUG(0,("make_subnet: Failed to open dgram socket on interface %s \ -for port %d. Error was %s\n", inet_ntoa(myip), DGRAM_PORT, strerror(errno))); + if( DEBUGLVL( 0 ) ) + { + Debug1( "nmbd_subnetdb:make_subnet()\n" ); + Debug1( " Failed to open dgram socket on interface %s ", inet_ntoa(myip) ); + Debug1( "for port %d. ", DGRAM_PORT ); + Debug1( "Error was %s\n", strerror(errno) ); + } return NULL; } -- cgit From 1aa138922e5c0e4925ff5cbfcdb4e7cad367b31b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 27 Jul 1998 18:50:45 +0000 Subject: chgpasswd.c: Fixed up debug calls to stop crashes if ptsname failed. local.h: Kept FSTYPE_STRING as Samba for now. nmbd_browsesync.c: Added bugfix from Matt Chapman mattyc@cyberdude.com - lmb_browserlist is now a struct ubi_dlList not a struct browse_cache_record *. server.c: smb.h: uid.c: password.c: Removed attrs code - it is not used anywhere. Jeremy (This used to be commit ef1af7fe6d5c58ae57b8e4efff0729e1a315da43) --- source3/nmbd/nmbd_browsesync.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index dd4a82d7f6..fd55fe161d 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -32,7 +32,7 @@ extern pstring global_myname; extern fstring global_myworkgroup; /* This is our local master browser list database. */ -extern struct browse_cache_record *lmb_browserlist; +extern struct ubi_dlList lmb_browserlist[]; static struct work_record *call_work; static struct subnet_record *call_subrec; -- cgit From 64578c0589a3a741f81fb55c16eeb882128da00b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 29 Jul 1998 03:08:05 +0000 Subject: merge from the autoconf2 branch to the main branch (This used to be commit 3bda7ac417107a7b01d91805ca71c4330657ed21) --- source3/nmbd/asyncdns.c | 10 +++++----- source3/nmbd/nmbd.c | 16 +++++++--------- 2 files changed, 12 insertions(+), 14 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 3d2d5303de..89be2b0ce0 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -135,7 +135,7 @@ void start_async_dns(void) { int fd1[2], fd2[2]; - signal(SIGCLD, SIG_IGN); + CatchChild(); if (pipe(fd1) || pipe(fd2)) { return; @@ -154,10 +154,10 @@ void start_async_dns(void) fd_in = fd2[0]; fd_out = fd1[1]; - signal(SIGUSR2, SIG_IGN); - signal(SIGUSR1, SIG_IGN); - signal(SIGHUP, SIG_IGN); - signal(SIGTERM, SIGNAL_CAST sig_term ); + CatchSignal(SIGUSR2, SIG_IGN); + CatchSignal(SIGUSR1, SIG_IGN); + CatchSignal(SIGHUP, SIG_IGN); + CatchSignal(SIGTERM, SIGNAL_CAST sig_term ); asyncdns_process(); } diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 1bb7ed55e4..3fa749b883 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -102,9 +102,7 @@ static int sig_hup(void) set_samba_nb_type(); BlockSignals(False,SIGHUP); -#ifndef DONT_REINSTALL_SIG - signal(SIGHUP,SIGNAL_CAST sig_hup); -#endif + return(0); } /* sig_hup */ @@ -141,7 +139,7 @@ static BOOL dump_core(void) return( False ); umask( ~(0700) ); -#ifndef NO_GETRLIMIT +#ifdef HAVE_GETRLIMIT #ifdef RLIMIT_CORE { struct rlimit rlp; @@ -428,7 +426,7 @@ static BOOL open_sockets(BOOL isdaemon, int port) if ( ClientNMB == -1 ) return( False ); - signal( SIGPIPE, SIGNAL_CAST sig_pipe ); + CatchSignal( SIGPIPE, SIGNAL_CAST sig_pipe ); set_socket_options( ClientNMB, "SO_BROADCAST" ); set_socket_options( ClientDGRAM, "SO_BROADCAST" ); @@ -582,8 +580,8 @@ int main(int argc,char *argv[]) fault_setup((void (*)(void *))fault_continue ); - signal( SIGHUP, SIGNAL_CAST sig_hup ); - signal( SIGTERM, SIGNAL_CAST sig_term ); + CatchSignal( SIGHUP, SIGNAL_CAST sig_hup ); + CatchSignal( SIGTERM, SIGNAL_CAST sig_term ); /* Setup the signals that allow the debug log level to by dynamically changed. */ @@ -592,11 +590,11 @@ int main(int argc,char *argv[]) SIGUSR1 and SIGUSR2 to do debug level changes. */ #ifndef MEM_MAN #if defined(SIGUSR1) - signal( SIGUSR1, SIGNAL_CAST sig_usr1 ); + CatchSignal( SIGUSR1, SIGNAL_CAST sig_usr1 ); #endif /* SIGUSR1 */ #if defined(SIGUSR2) - signal( SIGUSR2, SIGNAL_CAST sig_usr2 ); + CatchSignal( SIGUSR2, SIGNAL_CAST sig_usr2 ); #endif /* SIGUSR2 */ #endif /* MEM_MAN */ -- cgit From 28900ea26ff1c8d41328bba30206db7fe91e2184 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Fri, 31 Jul 1998 22:39:15 +0000 Subject: As per a Andrew's message, I went through and removed the timestring() timestamps from several DEBUG messages. The timestamps are redundant now that DEBUG() provides them automatically. There are still a few more files to do, but I've got to get home for dinner. Chris -)----- (This used to be commit 60286ccecaa6028d687e6406755016455e3b3a26) --- source3/nmbd/nmbd.c | 8 +++--- source3/nmbd/nmbd_become_dmb.c | 59 ++++++++++++++++++++++++++++++------------ 2 files changed, 46 insertions(+), 21 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 3fa749b883..af12911e7e 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -656,12 +656,12 @@ int main(int argc,char *argv[]) reopen_logs(); - DEBUG(1,("%s netbios nameserver version %s started\n",timestring(),VERSION)); - DEBUG(1,("Copyright Andrew Tridgell 1994-1997\n")); + DEBUG( 1, ( "Netbios nameserver version %s started.\n", VERSION ) ); + DEBUGADD( 1, ( "Copyright Andrew Tridgell 1994-1997\n" ) ); if( !get_myname( myhostname, NULL) ) { - DEBUG(0,("Unable to get my hostname - exiting.\n")); + DEBUG( 0, ( "Unable to get my hostname - exiting.\n" ) ); return -1; } @@ -693,7 +693,7 @@ int main(int argc,char *argv[]) if (is_daemon) { - DEBUG(2,("%s becoming a daemon\n",timestring())); + DEBUG( 2, ( "Becoming a daemon.\n" ) ); become_daemon(); } diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index d01bf18310..01f1126b21 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -81,8 +81,13 @@ in workgroup %s on subnet %s\n", bzero((char *)&work->dmb_name, sizeof(work->dmb_name)); putip((char *)&work->dmb_addr, &ipzero); - DEBUG(0,("\n%s ***** Samba server %s has stopped being a domain master browser \ -for workgroup %s on subnet %s *****\n\n", timestring(), global_myname, work->work_group, subrec->subnet_name)); + if( DEBUGLVL( 0 ) ) + { + dbgtext( "*****\n\nSamba server %s ", global_myname ); + dbgtext( "has stopped being a domain master browser " ); + dbgtext( "for workgroup %s ", work->work_group ); + dbgtext( "on subnet %s.\n\n*****\n", subrec->subnet_name ); + } } @@ -94,8 +99,12 @@ static void unbecome_dmb_fail(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *released_name) { - DEBUG(0,("unbecome_dmb_fail: Failed to unbecome domain master browser for \ -workgroup %s on subnet %s.\n", released_name->name, subrec->subnet_name)); + if( DEBUGLVL( 0 ) ) + { + dbgtext( "unbecome_dmb_fail: Failed to unbecome domain master browser " ); + dbgtext( "for workgroup %s ", released_name->name ); + dbgtext( "on subnet %s.\n", subrec->subnet_name ); + } } /******************************************************************* @@ -214,11 +223,15 @@ in workgroup %s on subnet %s\n", /* Tell the namelist writer to write out a change. */ subrec->work_changed = True; - DEBUG(0,("\n%s ***** Samba server %s is now a domain master browser for \ -workgroup %s on subnet %s *****\n\n", timestring(),global_myname, work->work_group, -subrec->subnet_name)); + if( DEBUGLVL( 0 ) ) + { + dbgtext( "*****\n\nSamba server %s ", global_myname ); + dbgtext( "is now a domain master browser for " ); + dbgtext( "workgroup %s ", work->work_group ); + dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name ); + } - if(subrec == unicast_subnet) + if( subrec == unicast_subnet ) { struct nmb_name nmbname; struct in_addr my_first_ip; @@ -313,9 +326,13 @@ Continuing with domain master code.\n", } else { - DEBUG(0,("%s become_domain_master_query_success: There is already a domain \ -master browser at IP %s for workgroup %s registered on subnet %s.\n", - timestring(), inet_ntoa(ip), nmbname->name, subrec->subnet_name)); + if( DEBUGLVL( 0 ) ) + { + dbgtext( "become_domain_master_query_success:\n" ); + dbgtext( "There is already a domain master browser at " ); + dbgtext( "IP %s for workgroup %s ", inet_ntoa(ip), nmbname->name ); + dbgtext( "registered on subnet %s.\n", subrec->subnet_name ); + } } } @@ -367,9 +384,13 @@ static void become_domain_master_browser_bcast(char *workgroup_name) if (find_name_on_subnet(subrec, &nmbname, FIND_SELF_NAME) == NULL) { - DEBUG(0,("become_domain_master_browser_bcast: At time %s attempting to become domain \ -master browser on workgroup %s on subnet %s\n", timestring(), - workgroup_name, subrec->subnet_name)); + if( DEBUGLVL( 0 ) ) + { + dbgtext( "become_domain_master_browser_bcast:\n" ); + dbgtext( "Attempting to become domain master browser on " ); + dbgtext( "workgroup %s on subnet %s\n", + workgroup_name, subrec->subnet_name ); + } /* Send out a query to establish whether there's a domain controller on the local subnet. If not, @@ -411,9 +432,13 @@ static void become_domain_master_browser_wins(char *workgroup_name) if (find_name_on_subnet(unicast_subnet, &nmbname, FIND_SELF_NAME) == NULL) { - DEBUG(0,("%s become_domain_master_browser_wins: attempting to become domain \ -master browser on workgroup %s, subnet %s.\n", - timestring(), workgroup_name, unicast_subnet->subnet_name)); + if( DEBUGLVL( 0 ) ) + { + dbgtext( "become_domain_master_browser_wins:\n" ); + dbgtext( "Attempting to become domain master browser " ); + dbgtext( "on workgroup %s, subnet %s.\n", + workgroup_name, unicast_subnet->subnet_name ); + } /* Send out a query to establish whether there's a domain master broswer registered with WINS. If not, -- cgit From f1abfacd4d230075e5c4029271f2f3952ac2c68a Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Mon, 3 Aug 1998 18:13:13 +0000 Subject: I finished removing timestring() calls from DEBUG() messages. Also went through and changed some DEBUG() calls to DEBUGADD() to combine output under a single timestamp. There were too many timestamps. Note that Jeremy has told me that he's working on adding a config parameter to turn timestamps off. Cool. Chris -)----- (This used to be commit 247dbc9a24987035a47f1ba4fa143b1e2c050e92) --- source3/nmbd/nmbd_become_lmb.c | 30 ++++++++++++++++++++++++------ source3/nmbd/nmbd_browsesync.c | 9 +++++++-- source3/nmbd/nmbd_logonnames.c | 10 +++++++--- source3/nmbd/nmbd_packets.c | 12 +++++++----- source3/nmbd/nmbd_workgroupdb.c | 4 ++-- 5 files changed, 47 insertions(+), 18 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index f66723eb17..2d007ecd75 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -153,8 +153,14 @@ void unbecome_local_master_success(struct subnet_record *subrec, /* Now reset the workgroup and server state. */ reset_workgroup_state( subrec, released_name->name, force_new_election ); - DEBUG(0,("\n%s ***** Samba name server %s has stopped being a local master browser for workgroup %s \ -on subnet %s *****\n\n", timestring(), global_myname, released_name->name, subrec->subnet_name)); + if( DEBUGLVL( 0 ) ) + { + dbgtext( "*****\n\n" ); + dbgtext( "Samba name server %s ", global_myname ); + dbgtext( "has stopped being a local master browser " ); + dbgtext( "for workgroup %s ", released_name->name ); + dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name ); + } } @@ -182,8 +188,14 @@ Removing from namelist anyway.\n", namestr(fail_name))); /* Now reset the workgroup and server state. */ reset_workgroup_state( subrec, fail_name->name, force_new_election ); - DEBUG(0,("\n%s ***** Samba name server %s has stopped being a local master browser for workgroup %s \ -on subnet %s *****\n\n", timestring(), global_myname, fail_name->name, subrec->subnet_name)); + if( DEBUGLVL( 0 ) ) + { + dbgtext( "*****\n\n" ); + dbgtext( "Samba name server %s ", global_myname ); + dbgtext( "has stopped being a local master browser " ); + dbgtext( "for workgroup %s ", fail_name->name ); + dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name ); + } } /******************************************************************* @@ -392,8 +404,14 @@ on subnet %s\n", work->work_group, subrec->subnet_name)); master browser as soon as possible that we are a local master browser. */ reset_announce_timer(); - DEBUG(0,("\n%s ***** Samba name server %s is now a local master browser for workgroup %s \ -on subnet %s *****\n\n", timestring(), global_myname, work->work_group, subrec->subnet_name)); + if( DEBUGLVL( 0 ) ) + { + dbgtext( "*****\n\n" ); + dbgtext( "Samba name server %s ", global_myname ); + dbgtext( "is now a local master browser " ); + dbgtext( "for workgroup %s ", work->work_group ); + dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name ); + } } diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index fd55fe161d..dcf2ea3c48 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -101,8 +101,13 @@ static void sync_browse_lists(struct subnet_record *subrec, struct work_record * static struct cli_state cli; uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0; - DEBUG(2,("%s: sync_browse_lists: Sync browse lists with server %s<%02x> at IP %s for workgroup %s\n", - timestring(), name, nm_type, inet_ntoa(ip), work->work_group )); + if( DEBUGLVL( 2 ) ) + { + dbgtext( "sync_browse_lists():\n" ); + dbgtext( "Sync browse lists with server %s<%02x> ", name, nm_type ); + dbgtext( "at IP %s ", inet_ntoa( ip ) ); + dbgtext( "for workgroup %s\n", work->work_group ); + } /* Check we're not trying to sync with ourselves. This can happen if we are a domain *and* a local master browser. */ diff --git a/source3/nmbd/nmbd_logonnames.c b/source3/nmbd/nmbd_logonnames.c index dbbb8defaf..4486fb2840 100644 --- a/source3/nmbd/nmbd_logonnames.c +++ b/source3/nmbd/nmbd_logonnames.c @@ -156,9 +156,13 @@ void add_logon_names(void) if (find_name_on_subnet(subrec, &nmbname, FIND_SELF_NAME) == NULL) { - DEBUG(0,("add_domain_logon_names: At time %s attempting to become \ -logon server for workgroup %s on subnet %s\n", timestring(), global_myworkgroup, - subrec->subnet_name)); + if( DEBUGLVL( 0 ) ) + { + dbgtext( "add_domain_logon_names:\n" ); + dbgtext( "Attempting to become logon server " ); + dbgtext( "for workgroup %s ", global_myworkgroup ); + dbgtext( "on subnet %s\n", subrec->subnet_name ); + } become_logon_server(subrec, work); } } diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 23db845348..1f216e3111 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -95,9 +95,11 @@ Dumps out the browse packet data. static void debug_browse_data(char *outbuf, int len) { int i,j; + + DEBUG( 4, ( "debug_browse_data():\n" ) ); for (i = 0; i < len; i+= 16) { - DEBUG(4, ("%3x char ", i)); + DEBUGADD( 4, ( "%3x char ", i ) ); for (j = 0; j < 16; j++) { @@ -107,19 +109,19 @@ static void debug_browse_data(char *outbuf, int len) if (i+j >= len) break; - DEBUG(4, ("%c", x)); + DEBUGADD( 4, ( "%c", x ) ); } - DEBUG(4, (" hex ", i)); + DEBUGADD( 4, ( " hex ", i ) ); for (j = 0; j < 16; j++) { if (i+j >= len) break; - DEBUG(4, (" %02x", (unsigned char)outbuf[i+j])); + DEBUGADD( 4, ( " %02x", (unsigned char)outbuf[i+j] ) ); } - DEBUG(4, ("\n")); + DEBUGADD( 4, ("\n") ); } } diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 818875c820..51b2519d83 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -183,11 +183,11 @@ struct work_record *find_workgroup_on_subnet(struct subnet_record *subrec, { if (!strcmp(ret->work_group,name)) { - DEBUG(4, ("found\n")); + DEBUGADD(4, ("found.\n")); return(ret); } } - DEBUG(4, ("not found\n")); + DEBUGADD(4, ("not found.\n")); return NULL; } -- cgit From 103857e8e33c724805baf5283335dc4e3901f007 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Mon, 3 Aug 1998 18:33:49 +0000 Subject: One more minor change to the format of a DEBUG message. I broke up a very long output line in become_domain_master_query_success(). Chris -)----- (This used to be commit 9b5d431661c55056c31bedf9ef3900f27e1c5292) --- source3/nmbd/nmbd_become_dmb.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index 01f1126b21..fe02f18f06 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -317,10 +317,15 @@ static void become_domain_master_query_success(struct subnet_record *subrec, if(ismyip(ip) || ip_equal(allones_ip, ip) || ip_equal(ipzero, ip)) { - DEBUG(3,("become_domain_master_query_success: Our address (%s) returned \ -in query for name %s (domain master browser name) on subnet %s. \ -Continuing with domain master code.\n", - inet_ntoa(ip), namestr(nmbname), subrec->subnet_name)); + if( DEBUGLVL( 3 ) ) + { + dbgtext( "become_domain_master_query_success():\n" ); + dbgtext( "Our address (%s) ", inet_ntoa(ip) ); + dbgtext( "returned in query for name %s ", namestr(nmbname) ); + dbgtext( "(domain master browser name) " ); + dbgtext( "on subnet %s.\n", subrec->subnet_name ); + dbgtext( "Continuing with domain master code.\n" ); + } become_domain_master_stage1(subrec, nmbname->name); } -- cgit From 31c09de03c656b7309888dbbc5240c31ed81537e Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Mon, 3 Aug 1998 22:10:53 +0000 Subject: More formatting changes. Mostly converted some DEBUG() calls to DEBUGADD() so that we wouldn't get too many timestamps. Chris -)----- (This used to be commit 3e7e5fad378cf144927d9f2ffc82f80e150d44ab) --- source3/nmbd/nmbd.c | 2 +- source3/nmbd/nmbd_winsserver.c | 10 +++++----- source3/nmbd/nmbd_workgroupdb.c | 24 ++++++++++++++++-------- 3 files changed, 22 insertions(+), 14 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index af12911e7e..567f7bbca7 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -515,7 +515,7 @@ static BOOL init_structs(void) DEBUG( 5, ("Netbios name list:-\n") ); for( n=0; my_netbios_names[n]; n++ ) - DEBUG( 5, ( "my_netbios_names[%d]=\"%s\"\n", n, my_netbios_names[n] ) ); + DEBUGADD( 5, ( "my_netbios_names[%d]=\"%s\"\n", n, my_netbios_names[n] ) ); return( True ); } /* init_structs */ diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index f663362706..dfa52a65f8 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1570,19 +1570,19 @@ void wins_write_database(void) int i; struct tm *tm; - DEBUG(4,("%-19s ", namestr(&namerec->name) )); + DEBUGADD(4,("%-19s ", namestr(&namerec->name) )); if( namerec->data.death_time != PERMANENT_TTL ) { tm = LocalTime(&namerec->data.death_time); - DEBUG(4,("TTL = %s", asctime(tm) )); + DEBUGADD(4,("TTL = %s", asctime(tm) )); } else - DEBUG(4,("TTL = PERMANENT\t")); + DEBUGADD(4,("TTL = PERMANENT\t")); for (i = 0; i < namerec->data.num_ips; i++) - DEBUG(4,("%15s ", inet_ntoa(namerec->data.ip[i]) )); - DEBUG(4,("%2x\n", namerec->data.nb_flags )); + DEBUGADD(4,("%15s ", inet_ntoa(namerec->data.ip[i]) )); + DEBUGADD(4,("%2x\n", namerec->data.nb_flags )); if( namerec->data.source == REGISTER_NAME ) { diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 51b2519d83..0b0b724854 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -303,22 +303,30 @@ void dump_workgroups(BOOL force_write) if (subrec->workgrouplist) { struct work_record *work; - - DEBUG(debuglevel,("dump_workgroups: dump workgroup on subnet %15s: ", subrec->subnet_name)); - DEBUG(debuglevel,(" netmask=%15s:\n", inet_ntoa(subrec->mask_ip))); + + if( DEBUGLVL( debuglevel ) ) + { + dbgtext( "dump_workgroups()\n " ); + dbgtext( "dump workgroup on subnet %15s: ", subrec->subnet_name ); + dbgtext( "netmask=%15s:\n", inet_ntoa(subrec->mask_ip) ); + } for (work = subrec->workgrouplist; work; work = work->next) { - DEBUG(debuglevel,("\t%s(%d) current master browser = %s\n", work->work_group, - work->token, - *work->local_master_browser_name ? work->local_master_browser_name : "UNKNOWN" )); + DEBUGADD( debuglevel, ( "\t%s(%d) current master browser = %s\n", + work->work_group, + work->token, + *work->local_master_browser_name + ? work->local_master_browser_name : "UNKNOWN" ) ); if (work->serverlist) { struct server_record *servrec; for (servrec = work->serverlist; servrec; servrec = servrec->next) { - DEBUG(debuglevel,("\t\t%s %8x (%s)\n", - servrec->serv.name, servrec->serv.type, servrec->serv.comment)); + DEBUGADD( debuglevel, ( "\t\t%s %8x (%s)\n", + servrec->serv.name, + servrec->serv.type, + servrec->serv.comment ) ); } } } -- cgit From 27ff18a184556f1e157de7c2789f39e3e70a40fc Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 9 Aug 1998 11:24:15 +0000 Subject: these dummy files are needed for autoconf processing (This used to be commit be762dc3de6c1ef768790522dfe93007a61ce5d7) --- source3/nmbd/dummy.in | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 source3/nmbd/dummy.in (limited to 'source3/nmbd') diff --git a/source3/nmbd/dummy.in b/source3/nmbd/dummy.in new file mode 100644 index 0000000000..e69de29bb2 -- cgit From 87bcd5502c105921b48f9654d1c4f6d14ed9e9f6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 9 Aug 1998 11:25:49 +0000 Subject: added ignore rules for the dummy files (This used to be commit 687f76a17d6d3ebd33b4d9a848deef56f3c1f56a) --- source3/nmbd/.cvsignore | 1 + 1 file changed, 1 insertion(+) create mode 100644 source3/nmbd/.cvsignore (limited to 'source3/nmbd') diff --git a/source3/nmbd/.cvsignore b/source3/nmbd/.cvsignore new file mode 100644 index 0000000000..421376db9e --- /dev/null +++ b/source3/nmbd/.cvsignore @@ -0,0 +1 @@ +dummy -- cgit From ea8631d249dc41b9c3abbe8bfaf8c64a313b0478 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Tue, 11 Aug 1998 21:25:55 +0000 Subject: Quick fix for a small problem. If you run 'nmbd -?' you'd get the usage message *but the daemon would start anyway*. I've added a call to exit() in the default: case of the option processing loop. Chris -)----- (This used to be commit c69727bd29c0bf1cded0db84602e791304691e2e) --- source3/nmbd/nmbd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 567f7bbca7..9df30adc8c 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -646,9 +646,10 @@ int main(int argc,char *argv[]) exit(0); break; default: - if (!is_a_socket(0)) + if( !is_a_socket(0) ) { usage(argv[0]); + exit(0); } break; } -- cgit From b9623ab59e813131b1ed3f51616a46e719d59c21 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 14 Aug 1998 17:38:29 +0000 Subject: this is the bug change to using connection_struct* instead of cnum. Connections[] is now a local array in server.c I might have broken something with this change. In particular the oplock code is suspect and some .dll files aren't being oplocked when I expected them to be. I'll look at it after I've got some sleep. (This used to be commit c7ee025ead4a85b6fa44a832047b878451845fb6) --- source3/nmbd/nmbd.c | 3 ++- source3/nmbd/nmbd_browserdb.c | 2 +- source3/nmbd/nmbd_nameregister.c | 2 +- source3/nmbd/nmbd_namerelease.c | 2 +- source3/nmbd/nmbd_packets.c | 2 +- source3/nmbd/nmbd_sendannounce.c | 3 ++- 6 files changed, 8 insertions(+), 6 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 9df30adc8c..24f4951612 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -153,7 +153,8 @@ static BOOL dump_core(void) #endif - DEBUG( 0, ( "Dumping core in %s\n",dname ) ); + DEBUG(0,("Dumping core in %s\n",dname)); + abort(); return( True ); } /* dump_core */ #endif diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c index 293a129d42..8e32dbd570 100644 --- a/source3/nmbd/nmbd_browserdb.c +++ b/source3/nmbd/nmbd_browserdb.c @@ -124,7 +124,7 @@ struct browse_cache_record *create_browser_in_lmb_cache( char *work_name, Debug1( "nmbd_browserdb:create_browser_in_lmb_cache()\n" ); Debug1( " Added lmb cache entry for workgroup %s ", browc->work_group ); Debug1( "name %s IP %s ", browc->lmb_name, inet_ntoa(ip) ); - Debug1( "ttl %d\n", browc->death_time ); + Debug1( "ttl %d\n", (int)browc->death_time ); } return( browc ); diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index 270a3ef6a5..05b549d30f 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -207,7 +207,7 @@ responding.\n", inet_ntoa(rrec->packet->ip))); rrec->repeat_time = time(NULL) + rrec->repeat_interval; DEBUG(5,("register_name_timeout_response: increasing WINS timeout to %d seconds.\n", - rrec->repeat_interval)); + (int)rrec->repeat_interval)); return; /* Don't remove the response record. */ } } diff --git a/source3/nmbd/nmbd_namerelease.c b/source3/nmbd/nmbd_namerelease.c index b58bab3a1d..558ab6ab16 100644 --- a/source3/nmbd/nmbd_namerelease.c +++ b/source3/nmbd/nmbd_namerelease.c @@ -165,7 +165,7 @@ responding.\n", inet_ntoa(rrec->packet->ip))); rrec->repeat_time = time(NULL) + rrec->repeat_interval; DEBUG(5,("release_name_timeout_response: increasing WINS timeout to %d seconds.\n", - rrec->repeat_interval)); + (int)rrec->repeat_interval)); return; /* Don't remove the response record. */ } } diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 1f216e3111..d557414a27 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -112,7 +112,7 @@ static void debug_browse_data(char *outbuf, int len) DEBUGADD( 4, ( "%c", x ) ); } - DEBUGADD( 4, ( " hex ", i ) ); + DEBUGADD( 4, ( " hex ") ); for (j = 0; j < 16; j++) { diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index 3936b7e92e..6c9f67ab21 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -398,7 +398,8 @@ void announce_myself_to_domain_master_browser(time_t t) if ((t-announce_timer_last) < (CHECK_TIME_MST_ANNOUNCE * 60)) { DEBUG(10,("announce_myself_to_domain_master_browser: t (%d) - last(%d) < %d\n", - t, announce_timer_last, CHECK_TIME_MST_ANNOUNCE * 60 )); + (int)t, (int)announce_timer_last, + CHECK_TIME_MST_ANNOUNCE * 60 )); return; } -- cgit From e13aeea928dd89373cfaf3916c96f853c1227884 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 15 Aug 1998 01:19:26 +0000 Subject: configure: Changes for extra headers. configure.in: Source for header changes. client/clitar.c: Fixed isXXX macros & debugs for gcc pedantic compile. include/config.h.in: Added MEMSET, BZERO, MEMORY, RPCSVC_YPCLNT, STRINGS headers. include/includes.h: Headers for the above. include/smb.h: Made SIGNAL_CAST POSIX by default void (*)(int). lib/access.c: Fixed isXXX macros & debugs for gcc pedantic compile. lib/charset.c: Fixed isXXX macros & debugs for gcc pedantic compile. lib/debug.c: Fixed signal functs. lib/kanji.c: Fixed isXXX macros & debugs for gcc pedantic compile. lib/smbrun.c: Fixed isXXX macros & debugs for gcc pedantic compile. lib/util.c: Fixed isXXX macros & debugs for gcc pedantic compile. libsmb/namequery.c: Fixed isXXX macros & debugs for gcc pedantic compile. locking/shmem.c: Fixed isXXX macros & debugs for gcc pedantic compile. locking/shmem_sysv.c: Fixed error messages in sysV stuff. nmbd/asyncdns.c: Fixed signal functs. nmbd/nmbd.c: Fixed isXXX macros & debugs for gcc pedantic compile. passdb/passdb.c: Fixed isXXX macros & debugs for gcc pedantic compile. passdb/smbpassfile.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/chgpasswd.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/ipc.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/nttrans.c: Fixed fsp code path. smbd/password.c: fixed HAVE_YP_GET_DEFAULT_DOMAIN problem. smbd/printing.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/reply.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/server.c: Fixed isXXX macros & debugs for gcc pedantic compile. smbd/trans2.c: Fixed core dump bug. smbd/uid.c: Fixed isXXX macros & debugs for gcc pedantic compile. Jeremy. (This used to be commit 1b9cbcd02e575dc0a95fa589f720df30a4acc46b) --- source3/nmbd/asyncdns.c | 4 +--- source3/nmbd/nmbd.c | 12 ++++-------- 2 files changed, 5 insertions(+), 11 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 89be2b0ce0..9926045d82 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -110,11 +110,9 @@ static void asyncdns_process(void) WINS db that our parent is going to write. **************************************************************************** */ -static int sig_term(void) +static void sig_term(int sig) { _exit(0); - /* Keep compiler happy.. */ - return 0; } /*************************************************************************** diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 24f4951612..9eae3b0e98 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -61,7 +61,7 @@ extern struct in_addr ipzero; /**************************************************************************** ** catch a sigterm **************************************************************************** */ -static int sig_term(void) +static void sig_term(int sig) { BlockSignals(True,SIGTERM); @@ -81,14 +81,12 @@ static int sig_term(void) exit(0); - /* Keep compiler happy.. */ - return 0; } /* sig_term */ /**************************************************************************** ** catch a sighup **************************************************************************** */ -static int sig_hup(void) +static void sig_hup(int sig) { BlockSignals( True, SIGHUP ); @@ -103,13 +101,12 @@ static int sig_hup(void) BlockSignals(False,SIGHUP); - return(0); } /* sig_hup */ /**************************************************************************** ** catch a sigpipe **************************************************************************** */ -static int sig_pipe(void) +static void sig_pipe(int sig) { BlockSignals( True, SIGPIPE ); @@ -117,7 +114,6 @@ static int sig_pipe(void) if ( !is_daemon ) exit(1); BlockSignals( False, SIGPIPE ); - return(0); } /* sig_pipe */ #if DUMP_CORE @@ -147,7 +143,7 @@ static BOOL dump_core(void) rlp.rlim_cur = MAX( 4*1024*1024, rlp.rlim_cur ); setrlimit( RLIMIT_CORE, &rlp ); getrlimit( RLIMIT_CORE, &rlp ); - DEBUG( 3, ( "Core limits now %d %d\n", rlp.rlim_cur, rlp.rlim_max ) ); + DEBUG( 3, ( "Core limits now %d %d\n", (int)rlp.rlim_cur, (int)rlp.rlim_max ) ); } #endif #endif -- cgit From 7fe3a42857792a70bdd729fefa2311b77ae86e7e Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Fri, 21 Aug 1998 17:21:55 +0000 Subject: nmbd and smbd had different behavior with respect to log files. nmbd would default to overwrite and smbd would default to append. Also, the -a option (actually a toggle, such that "-a -a" would set the default) was documented as append mode for nmbd, and *overwrite mode* for smbd. nmbd now defaults to append mode, to match smbd. The -a option now always means append, and I've added the -o option to both, meaning overwrite. Note that the change to nmbd's default behavior may confuse some people. I've not seen anything about 2.0.0 changes in the WHATSNEW.txt file. Where would I document a change like this? Chris -)----- (This used to be commit b1d374fb14b1fb92a84260f1dcc59a39a4b99a3d) --- source3/nmbd/nmbd.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 9eae3b0e98..9b872f8ffe 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -534,6 +534,8 @@ static void usage(char *pname) printf( "\t-n netbiosname. " ); printf( "the netbios name to advertise for this host\n"); printf( "\t-H hosts file load a netbios hosts file\n" ); + printf( "\t-a append to log file (default)\n" ); + printf( "\t-o overwrite log file, don't append\n" ); printf( "\n"); } /* usage */ @@ -546,6 +548,9 @@ int main(int argc,char *argv[]) int opt; extern FILE *dbf; extern char *optarg; + extern BOOL append_log; + + append_log = True; /* Default, override with '-o' option. */ global_nmb_port = NMB_PORT; *host_file = 0; @@ -595,7 +600,8 @@ int main(int argc,char *argv[]) #endif /* SIGUSR2 */ #endif /* MEM_MAN */ - while((opt = getopt(argc, argv, "as:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:f:")) != EOF) + while( EOF != + (opt = getopt( argc, argv, "aos:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:f:" )) ) { switch (opt) { @@ -624,10 +630,10 @@ int main(int argc,char *argv[]) strupper(scope); break; case 'a': - { - extern BOOL append_log; - append_log = !append_log; - } + append_log = True; + break; + case 'o': + append_log = False; break; case 'D': is_daemon = True; -- cgit From c077bce5c0f760dc918b0442346502ec96a92c1b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 28 Aug 1998 14:35:24 +0000 Subject: nmbd would core dump if a large number of netbios aliases is set. The problem was a buffer overflow in process_node_status_request(). this really points out a general problem is allocating MAX_DGRAM_SIZE packets on the stack in nmbd. There must be a better way. (This used to be commit 7db45f169c33e0f3a67ba2260049226992de8bdf) --- source3/nmbd/nmbd_incomingrequests.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index 3c9438ace3..a3afbe827a 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -341,8 +341,9 @@ subnet %s - name not found.\n", namestr(&nmb->question.question_name), return; } - /* XXXX hack, we should calculate exactly how many will fit. */ - bufend = &rdata[MAX_DGRAM_SIZE] - 18; + /* this is not an exact calculation. the 46 is for the stats buffer + and the 60 is to leave room for the header etc */ + bufend = &rdata[MAX_DGRAM_SIZE] - (18 + 46 + 60); countptr = buf = rdata; buf += 1; buf0 = buf; -- cgit From 38142a1ebbe860778e26eaff68585726061c05e2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 28 Aug 1998 21:46:29 +0000 Subject: This checking fixes the statcache bug that stopped NetBench from running correctly. Added new parameter "stat cache size" - set to 50 by default. I now declare the statcache code officially "open" for business :-). It gets a hit rate of 97% with a NetBench run and seems to make using a case insensitive run as efficient as a case sensitive run. Also tidied up our sys_select usage - added a maxfd parameter and also added an implementation of select in terms of poll(), for systems where poll() is much faster. This is disabled by default. Jeremy. (This used to be commit 779b924ec1f6c81ff578d22295b20fece698d1fc) --- source3/nmbd/nmbd_packets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index d557414a27..65d98c9a59 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1773,7 +1773,7 @@ BOOL listen_for_packets(BOOL run_election) BlockSignals(False, SIGUSR2); #endif /* SIGUSR2 */ - selrtn = sys_select(&fds,&timeout); + selrtn = sys_select(256,&fds,&timeout); /* We can only take signals when we are in the select - block them again here. */ -- cgit From 7731692b74ff0cb58a6262b2f436fdddacbe7d08 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 29 Aug 1998 03:10:39 +0000 Subject: don't exit on a SIGPIPE (This used to be commit f18b4e95bffb25fa016dd6e7f9a128a9fc69466f) --- source3/nmbd/nmbd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 9b872f8ffe..3bb2584eaf 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -111,8 +111,7 @@ static void sig_pipe(int sig) BlockSignals( True, SIGPIPE ); DEBUG( 0, ("Got SIGPIPE\n") ); - if ( !is_daemon ) - exit(1); + BlockSignals( False, SIGPIPE ); } /* sig_pipe */ -- cgit From 1778debff146423e3543d40c2fe8413a34888a27 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 30 Aug 1998 04:27:26 +0000 Subject: added some defensive programming to nmbd. This mostly means zeroing areas of memory before freeing them. While doing this I also found a couple of real bugs. In two places we were freeing some memory that came from the stack, which leads to a certain core dump on many sytems. (This used to be commit c5e5c25c854e54f59291057ba47c4701b5910ebe) --- source3/nmbd/nmbd_become_lmb.c | 11 ++++++----- source3/nmbd/nmbd_browsesync.c | 5 +++-- source3/nmbd/nmbd_incomingrequests.c | 4 ++-- source3/nmbd/nmbd_namelistdb.c | 4 ++++ source3/nmbd/nmbd_responserecordsdb.c | 13 +++++++++---- source3/nmbd/nmbd_serverlistdb.c | 2 ++ source3/nmbd/nmbd_subnetdb.c | 1 + source3/nmbd/nmbd_winsproxy.c | 1 + source3/nmbd/nmbd_workgroupdb.c | 1 + 9 files changed, 29 insertions(+), 13 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index 2d007ecd75..3fe6f596fa 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -212,9 +212,9 @@ static void release_1d_name( struct subnet_record *subrec, char *workgroup_name, if((namerec = find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME))!=NULL) { struct userdata_struct *userdata; + int size = sizeof(struct userdata_struct) + sizeof(BOOL); - if((userdata = (struct userdata_struct *)malloc( - sizeof(struct userdata_struct) + sizeof(BOOL))) == NULL) + if((userdata = (struct userdata_struct *)malloc(size)) == NULL) { DEBUG(0,("release_1d_name: malloc fail.\n")); return; @@ -230,7 +230,7 @@ static void release_1d_name( struct subnet_record *subrec, char *workgroup_name, unbecome_local_master_fail, userdata); - free((char *)userdata); + zero_free(userdata, size); } } @@ -526,6 +526,7 @@ void become_local_master_browser(struct subnet_record *subrec, struct work_recor { struct server_record *servrec; struct userdata_struct *userdata; + int size = sizeof(struct userdata_struct) + sizeof(fstring) + 1; /* Sanity check. */ if (!lp_local_master()) @@ -561,7 +562,7 @@ in workgroup %s on subnet %s\n", subrec->work_changed = True; /* Setup the userdata_struct. */ - if((userdata = (struct userdata_struct *)malloc(sizeof(struct userdata_struct) + sizeof(fstring)+1)) == NULL) + if((userdata = (struct userdata_struct *)malloc(size)) == NULL) { DEBUG(0,("become_local_master_browser: malloc fail.\n")); return; @@ -578,7 +579,7 @@ in workgroup %s on subnet %s\n", become_local_master_fail1, userdata); - free((char *)userdata); + zero_free(userdata, size); } /*************************************************************** diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index dcf2ea3c48..bc0cf43f7c 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -386,6 +386,7 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec, struct work_record *work; struct nmb_name nmbname; struct userdata_struct *userdata; + int size = sizeof(struct userdata_struct) + sizeof(fstring)+1; if (!(work = find_workgroup_on_subnet(subrec, q_name->name))) { DEBUG(0, ("find_domain_master_name_query_success: failed to find \ @@ -418,7 +419,7 @@ workgroup %s\n", q_name->name )); /* Setup the userdata_struct - this is copied so we can use a stack variable for this. */ - if((userdata = (struct userdata_struct *)malloc(sizeof(struct userdata_struct) + sizeof(fstring)+1)) == NULL) + if((userdata = (struct userdata_struct *)malloc(size)) == NULL) { DEBUG(0, ("find_domain_master_name_query_success: malloc fail.\n")); return; @@ -434,7 +435,7 @@ workgroup %s\n", q_name->name )); domain_master_node_status_fail, userdata); - free((char *)userdata); + zero_free(userdata, size); } /**************************************************************************** diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index a3afbe827a..c2b8be212f 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -576,7 +576,7 @@ on the same subnet (%s) as the requestor. Not replying.\n", if (!success && bcast) { if((prdata != rdata) && (prdata != NULL)) - free(rdata); + free(prdata); return; /* Never reply with a negative response to broadcasts. */ } @@ -589,7 +589,7 @@ on the same subnet (%s) as the requestor. Not replying.\n", if(!success && !bcast && nmb->header.nm_flags.recursion_desired) { if((prdata != rdata) && (prdata != NULL)) - free(rdata); + free(prdata); return; } diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 29d822550c..de5835a115 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -111,6 +111,8 @@ void remove_name_from_namelist( struct subnet_record *subrec, if(namerec->data.ip != NULL) free((char *)namerec->data.ip); + + ZERO_STRUCTP(namerec); free((char *)namerec); subrec->namelist_changed = True; @@ -218,6 +220,8 @@ struct name_record *add_name_to_subnet( struct subnet_record *subrec, if( NULL == namerec->data.ip ) { DEBUG( 0, ( "add_name_to_subnet: malloc fail when creating ip_flgs.\n" ) ); + + ZERO_STRUCTP(namerec); free( (char *)namerec ); return NULL; } diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index 6dae0d43e9..21defa970c 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -80,16 +80,19 @@ void remove_response_record(struct subnet_record *subrec, if(rrec->userdata) { - if(rrec->userdata->free_fn) - (*rrec->userdata->free_fn)(rrec->userdata); - else - free((char *)rrec->userdata); + if(rrec->userdata->free_fn) { + (*rrec->userdata->free_fn)(rrec->userdata); + } else { + ZERO_STRUCTP(rrec->userdata); + free((char *)rrec->userdata); + } } /* Ensure we can delete. */ rrec->packet->locked = False; free_packet(rrec->packet); + ZERO_STRUCTP(rrec); free((char *)rrec); num_response_packets--; /* count of total number of packets still around */ @@ -135,6 +138,7 @@ struct response_record *make_response_record( struct subnet_record *subrec, if((rrec->userdata = (*userdata->copy_fn)(userdata)) == NULL) { DEBUG(0,("make_response_queue_record: copy fail for userdata.\n")); + ZERO_STRUCTP(rrec); free(rrec); return NULL; } @@ -146,6 +150,7 @@ struct response_record *make_response_record( struct subnet_record *subrec, malloc(sizeof(struct userdata_struct)+userdata->userdata_len)) == NULL) { DEBUG(0,("make_response_queue_record: malloc fail for userdata.\n")); + ZERO_STRUCTP(rrec); free(rrec); return NULL; } diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index 6ff6ad5c5d..a4dab6f419 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -56,6 +56,7 @@ void remove_all_servers(struct work_record *work) if (work->serverlist == servrec) work->serverlist = servrec->next; + ZERO_STRUCTP(servrec); free((char *)servrec); } @@ -120,6 +121,7 @@ void remove_server_from_workgroup(struct work_record *work, struct server_record if (work->serverlist == servrec) work->serverlist = servrec->next; + ZERO_STRUCTP(servrec); free((char *)servrec); work->subnet->work_changed = True; } diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 942175c9f8..edc930c205 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -180,6 +180,7 @@ static struct subnet_record *make_subnet(char *name, enum subnet_type type, DEBUG(0,("make_subnet: malloc fail for subnet name !\n")); close(nmb_sock); close(dgram_sock); + ZERO_STRUCTP(subrec); free((char *)subrec); return(NULL); } diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index 5635124bcd..2084d3915a 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -191,6 +191,7 @@ static void wins_proxy_userdata_free_fn(struct userdata_struct *userdata) p->locked = False; free_packet(p); + ZERO_STRUCTP(userdata); free((char *)userdata); } diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 0b0b724854..ac25127e82 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -158,6 +158,7 @@ static struct work_record *remove_workgroup_from_subnet(struct subnet_record *su if (subrec->workgrouplist == work) subrec->workgrouplist = work->next; + ZERO_STRUCTP(work); free((char *)work); } -- cgit From 5a44ce9caaa9e3b19ee387b698ac255ec2cb5785 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 30 Aug 1998 05:43:59 +0000 Subject: changed the format of the wins.dat file slightly. It now has a line like this: VERSION 1 251152 the first number is a version #define in nmbd_winsserver.c and will be used if we ever have to change the format again. The second number is a hash of the current interfaces setting. It is used to detect the case where nmbd is restarted on a machine after the IP of the machine has changed (or the interfaces list has changed in any way). When that happens we need to discard the old wins.dat cache or you end up with chaos. This has bitten quite a few people, they find that when they move a machine it continues using the old IP for some things for the next week until the wins entries time out! I've checked, and the old nmbd can handle the new format, although it does spit out a spurious error message about the VERSION line. So users can safely run 2.0alpha then switch back to 1.9.18 without problems. (This used to be commit c4a8cdc60a5b01894ab2456e77b6d89d4c16a088) --- source3/nmbd/nmbd_winsserver.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index dfa52a65f8..11e0aaecd6 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -24,6 +24,7 @@ #include "includes.h" #define WINS_LIST "wins.dat" +#define WINS_VERSION 1 extern int DEBUGLEVEL; extern struct in_addr ipzero; @@ -158,6 +159,8 @@ BOOL initialise_wins(void) BOOL got_token; BOOL was_ip; int i; + unsigned hash; + int version; /* Read a line from the wins.dat file. Strips whitespace from the beginning and end of the line. @@ -168,6 +171,17 @@ BOOL initialise_wins(void) if (*line == '#') continue; + if (strncmp(line,"VERSION ", 8) == 0) { + if (sscanf(line,"VERSION %d %u", &version, &hash) != 2 || + version != WINS_VERSION || + hash != iface_hash()) { + DEBUG(0,("Discarding invalid wins.dat file [%s]\n",line)); + fclose(fp); + return True; + } + continue; + } + ptr = line; /* @@ -1561,6 +1575,8 @@ void wins_write_database(void) } DEBUG(4,("wins_write_database: Dump of WINS name list.\n")); + + fprintf(fp,"VERSION %d %u\n", WINS_VERSION, iface_hash()); for( namerec = (struct name_record *)ubi_trFirst( wins_server_subnet->namelist ); -- cgit From 3debe642bd299e1aed8578df342f4bfecf5d8b3b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 30 Aug 1998 06:49:14 +0000 Subject: include our netbios names list and our workgroup in the wins.dat hash (This used to be commit f555a76df696a0625acc16fa365dc048e0c2447d) --- source3/nmbd/nmbd_winsserver.c | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 11e0aaecd6..e7c6d69cd6 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -29,6 +29,26 @@ extern int DEBUGLEVEL; extern struct in_addr ipzero; + + +/**************************************************************************** +hash our interfaces and netbios names settings +*****************************************************************************/ +static unsigned wins_hash(void) +{ + int i; + unsigned ret = iface_hash(); + extern char **my_netbios_names; + + for (i=0;my_netbios_names[i];i++) + ret ^= str_checksum(my_netbios_names[i]); + + ret ^= str_checksum(lp_workgroup()); + + return ret; +} + + /**************************************************************************** Determine if this packet should be allocated to the WINS server. *****************************************************************************/ @@ -174,7 +194,7 @@ BOOL initialise_wins(void) if (strncmp(line,"VERSION ", 8) == 0) { if (sscanf(line,"VERSION %d %u", &version, &hash) != 2 || version != WINS_VERSION || - hash != iface_hash()) { + hash != wins_hash()) { DEBUG(0,("Discarding invalid wins.dat file [%s]\n",line)); fclose(fp); return True; @@ -1576,7 +1596,7 @@ void wins_write_database(void) DEBUG(4,("wins_write_database: Dump of WINS name list.\n")); - fprintf(fp,"VERSION %d %u\n", WINS_VERSION, iface_hash()); + fprintf(fp,"VERSION %d %u\n", WINS_VERSION, wins_hash()); for( namerec = (struct name_record *)ubi_trFirst( wins_server_subnet->namelist ); -- cgit From 179e8c66f121e01b5e69ad8b1c39f8a1a1e45814 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 30 Aug 1998 08:45:23 +0000 Subject: changed the way that name query records are sorted in replies. They are now sorted by the number of common leading bits in the IP address with the address of the querying host. (This used to be commit 4460a1bc6aa7666d1c71d32ba73855d6ed32320a) --- source3/nmbd/nmbd_incomingrequests.c | 3 +++ source3/nmbd/nmbd_winsserver.c | 42 ++++++------------------------------ 2 files changed, 9 insertions(+), 36 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index c2b8be212f..97d223b291 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -555,6 +555,9 @@ on the same subnet (%s) as the requestor. Not replying.\n", set_nb_flags(&prdata[i*6],namerec->data.nb_flags); putip((char *)&prdata[2+(i*6)], &namerec->data.ip[i]); } + + sort_query_replies(prdata, i, p->ip); + reply_data_len = namerec->data.num_ips * 6; success = True; } diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index e7c6d69cd6..d891124d06 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1261,15 +1261,12 @@ void send_wins_name_query_response(int rcode, struct packet_struct *p, char *prdata = rdata; int reply_data_len = 0; int ttl = 0; - int i = 0; - int j; + int i; bzero(rdata,6); if(rcode == 0) { - int same_net_index = -1; - ttl = (namerec->data.death_time != PERMANENT_TTL) ? namerec->data.death_time - p->timestamp : lp_max_wins_ttl(); @@ -1286,44 +1283,17 @@ void send_wins_name_query_response(int rcode, struct packet_struct *p, DEBUG(0,("send_wins_name_query_response: malloc fail !\n")); return; } - - /* - * Look over the known IP addresses and see if one of them - * is on the same (local) net as the requesting IP address. If so then - * put that IP address into the packet as the first IP. - * We can only do this for local nets as they're the only - * ones we know the netmask for. - */ - - i = 0; - - if(is_local_net(p->ip)) - { - struct in_addr *n_mask = iface_nmask(p->ip); - - for( j = 0; j < namerec->data.num_ips; j++) - { - if(same_net( namerec->data.ip[j], p->ip, *n_mask)) - { - set_nb_flags(&prdata[0],namerec->data.nb_flags); - putip((char *)&prdata[2], &namerec->data.ip[j]); - same_net_index = j; - i = 1; - } - } - } } - for(j = 0; j < namerec->data.num_ips; j++) + for(i = 0; i < namerec->data.num_ips; i++) { - if(j == same_net_index) - continue; set_nb_flags(&prdata[i*6],namerec->data.nb_flags); - putip((char *)&prdata[2+(i*6)], &namerec->data.ip[j]); - i++; + putip((char *)&prdata[2+(i*6)], &namerec->data.ip[i]); } - reply_data_len = namerec->data.num_ips * 6; + sort_query_replies(prdata, i, p->ip); + + reply_data_len = namerec->data.num_ips * 6; } reply_netbios_packet(p, /* Packet to reply to. */ -- cgit From f04d5b6b11235cc9ade0d65063dd60ad2184ee96 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 30 Aug 1998 09:50:45 +0000 Subject: we we have successfully done a query on *<1b> from a wins server and then obtained a node status response we need to remember the server name of the master browser so that other browse clients asking us for a workgroup list will get a entry for the master of that workgroup. (This used to be commit 601f995ffbfa0ee477ea628d92b9660d6bdd8cbc) --- source3/nmbd/nmbd_browsesync.c | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index bc0cf43f7c..ac2cb5b71e 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -496,6 +496,9 @@ static void get_domain_master_name_node_status_success(struct subnet_record *sub struct in_addr from_ip) { struct work_record *work; + fstring server_name; + + server_name[0] = 0; DEBUG(3,("get_domain_master_name_node_status_success: Success in node status from ip %s\n", inet_ntoa(from_ip) )); @@ -525,11 +528,19 @@ static void get_domain_master_name_node_status_success(struct subnet_record *sub p += 18; + if(!(nb_flags & NB_GROUP) && (name_type == 0x00) && + server_name[0] == 0) { + /* this is almost certainly the server netbios name */ + fstrcpy(server_name, qname); + continue; + } + if(!(nb_flags & NB_GROUP) && (name_type == 0x1b)) { - DEBUG(5,("get_domain_master_name_node_status_success: IP %s is a domain \ -master browser for workgroup %s. Adding this name.\n", inet_ntoa(from_ip), qname )); + DEBUG(5,("get_domain_master_name_node_status_success: %s(%s) is a domain \ +master browser for workgroup %s. Adding this name.\n", + server_name, inet_ntoa(from_ip), qname )); /* * If we don't already know about this workgroup, add it @@ -537,11 +548,18 @@ master browser for workgroup %s. Adding this name.\n", inet_ntoa(from_ip), qname */ if((work = find_workgroup_on_subnet( subrec, qname)) == NULL) { - /* - * Add it - with an hour in the cache. - */ - if((work = create_workgroup_on_subnet(subrec, qname, 60*60))==NULL) - return; + struct nmb_name nmbname; + /* + * Add it - with an hour in the cache. + */ + if(!(work= create_workgroup_on_subnet(subrec, qname, 60*60))) + return; + + /* remember who the master is */ + fstrcpy(work->local_master_browser_name, server_name); + make_nmb_name(&nmbname, server_name, 0x20, scope); + work->dmb_name = nmbname; + work->dmb_addr = from_ip; } break; } -- cgit From 998db177ba25d0fb1fc12b1528025bf975b7c6ad Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 30 Aug 1998 15:58:17 +0000 Subject: finished the asynchronous browse synchronisation code. It even seems to work (not a lot of testing yet though). Now we just need to deal with people worried about having more than two nmbd processes sometimes. (the async processes are created on demand for browse sync, so you'll only see more than 2 occasionally) (This used to be commit a350a54680e4170e2adf571b010ea508e7291780) --- source3/nmbd/nmbd.c | 10 ++ source3/nmbd/nmbd_browsesync.c | 186 +++++++-------------------- source3/nmbd/nmbd_synclists.c | 282 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 337 insertions(+), 141 deletions(-) create mode 100644 source3/nmbd/nmbd_synclists.c (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 3bb2584eaf..9210ce4dcf 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -396,6 +396,16 @@ static void process(void) * (nmbd_packets.c) */ retransmit_or_expire_response_records(t); + + /* + * check to see if any remote browse sync child processes have completed + */ + sync_check_completion(); + + /* + * regularly sync with any other DMBs we know about + */ + sync_all_dmbs(t); } } /* process */ diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index ac2cb5b71e..a4faca5515 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -34,145 +34,9 @@ extern fstring global_myworkgroup; /* This is our local master browser list database. */ extern struct ubi_dlList lmb_browserlist[]; -static struct work_record *call_work; -static struct subnet_record *call_subrec; - -/******************************************************************* - This is the NetServerEnum callback. - ******************************************************************/ - -static void callback(char *sname, uint32 stype, char *comment) -{ - struct work_record *work; - - stype &= ~SV_TYPE_LOCAL_LIST_ONLY; - - if (stype & SV_TYPE_DOMAIN_ENUM) - { - /* See if we can find the workgroup on this subnet. */ - if(( work = find_workgroup_on_subnet( call_subrec, sname )) != NULL) - { - /* We already know about this workgroup - update the ttl. */ - update_workgroup_ttl( work, lp_max_ttl() ); - } - else - { - /* Create the workgroup on the subnet. */ - create_workgroup_on_subnet( call_subrec, sname, lp_max_ttl() ); - } - } - else - { - /* Server entry. */ - struct server_record *servrec; - - work = call_work; - - if(( servrec = find_server_in_workgroup( work, sname )) != NULL) - { - /* Check that this is not a locally known server - if so ignore the - entry. */ - if(!(servrec->serv.type & SV_TYPE_LOCAL_LIST_ONLY)) - { - /* We already know about this server - update the ttl. */ - update_server_ttl(servrec, lp_max_ttl() ); - /* Update the type. */ - servrec->serv.type = stype; - } - } - else - { - /* Create the server in the workgroup. */ - create_server_on_workgroup(work, sname,stype,lp_max_ttl(),comment); - } - } -} - -/******************************************************************* - Synchronise browse lists with another browse server. - Log in on the remote server's SMB port to their IPC$ service, - do a NetServerEnum and update our server and workgroup databases. -******************************************************************/ - -static void sync_browse_lists(struct subnet_record *subrec, struct work_record *work, - char *name, int nm_type, struct in_addr ip, BOOL local) -{ - extern fstring local_machine; - static struct cli_state cli; - uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0; - - if( DEBUGLVL( 2 ) ) - { - dbgtext( "sync_browse_lists():\n" ); - dbgtext( "Sync browse lists with server %s<%02x> ", name, nm_type ); - dbgtext( "at IP %s ", inet_ntoa( ip ) ); - dbgtext( "for workgroup %s\n", work->work_group ); - } - - /* Check we're not trying to sync with ourselves. This can happen if we are - a domain *and* a local master browser. */ - if(ismyip(ip)) - { - DEBUG(2,("sync_browse_lists: We are both a domain and a local master browser for workgroup %s. \ -Do not sync with ourselves.\n", work->work_group )); - return; - } - - if (!cli_initialise(&cli) || !cli_connect(&cli, name, &ip)) - { - DEBUG(0,("sync_browse_lists: Failed to start browse sync with %s\n", name)); - return; - } - - if (!cli_session_request(&cli, name, nm_type, local_machine)) - { - DEBUG(0,("sync_browse_lists: %s rejected the browse sync session\n",name)); - cli_shutdown(&cli); - return; - } - - if (!cli_negprot(&cli)) - { - DEBUG(0,("sync_browse_lists: %s rejected the negprot\n",name)); - cli_shutdown(&cli); - return; - } - - if (!cli_session_setup(&cli, "", "", 1, "", 0, work->work_group)) - { - DEBUG(0,("sync_browse_lists: %s rejected the browse sync sessionsetup\n", - name)); - cli_shutdown(&cli); - return; - } - - if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) - { - DEBUG(0,("sync_browse_lists: %s refused browse sync IPC$ connect\n", name)); - cli_shutdown(&cli); - return; - } - - call_work = work; - call_subrec = subrec; - - /* Fetch a workgroup list. */ - cli_NetServerEnum(&cli, work->work_group, - local_type|SV_TYPE_DOMAIN_ENUM, - callback); - - /* Now fetch a server list. */ - cli_NetServerEnum(&cli, work->work_group, - local?SV_TYPE_LOCAL_LIST_ONLY:SV_TYPE_ALL, - callback); - - cli_shutdown(&cli); -} - /**************************************************************************** As a domain master browser, do a sync with a local master browser. **************************************************************************/ - static void sync_with_lmb(struct browse_cache_record *browc) { struct work_record *work; @@ -198,7 +62,7 @@ for workgroup %s and we are not a domain master browser on this workgroup. Error DEBUG(2, ("sync_with_lmb: Initiating sync with local master browser %s<0x20> at IP %s for \ workgroup %s\n", browc->lmb_name, inet_ntoa(browc->ip), browc->work_group)); - sync_browse_lists(unicast_subnet, work, browc->lmb_name, 0x20, browc->ip, True); + sync_browse_lists(work, browc->lmb_name, 0x20, browc->ip, True, True); browc->sync_time += (CHECK_TIME_DMB_TO_LMB_SYNC * 60); } @@ -206,7 +70,6 @@ workgroup %s\n", browc->lmb_name, inet_ntoa(browc->ip), browc->work_group)); /**************************************************************************** Sync or expire any local master browsers. **************************************************************************/ - void dmb_expire_and_sync_browser_lists(time_t t) { static time_t last_run = 0; @@ -272,8 +135,8 @@ static void sync_with_dmb(struct work_record *work) DEBUG(2, ("sync_with_dmb: Initiating sync with domain master browser %s at IP %s for \ workgroup %s\n", namestr(&work->dmb_name), inet_ntoa(work->dmb_addr), work->work_group)); - sync_browse_lists(unicast_subnet, work, work->dmb_name.name, work->dmb_name.name_type, - work->dmb_addr, False); + sync_browse_lists(work, work->dmb_name.name, work->dmb_name.name_type, + work->dmb_addr, False, True); } /**************************************************************************** @@ -654,7 +517,6 @@ for name %s. This means it is probably not a Samba 1.9.18 or above WINS server.\ <1b> name in the reply - this is the workgroup name. Add this to the unicast subnet. This is expensive, so we only do this every 15 minutes. **************************************************************************/ - void collect_all_workgroup_names_from_wins_server(time_t t) { static time_t lastrun = 0; @@ -689,3 +551,45 @@ void collect_all_workgroup_names_from_wins_server(time_t t) find_all_domain_master_names_query_fail, NULL); } + + +/**************************************************************************** + If we are a domain master browser on the unicast subnet, do a regular sync + with all other DMBs that we know of on that subnet +**************************************************************************/ +void sync_all_dmbs(time_t t) +{ + static time_t lastrun = 0; + struct work_record *work; + + /* Only do this if we are using a WINS server. */ + if(we_are_a_wins_client() == False) + return; + + /* Check to see if we are a domain master browser on the + unicast subnet. */ + work = find_workgroup_on_subnet(unicast_subnet, global_myworkgroup); + if (!work) return; + + if (!AM_DOMAIN_MASTER_BROWSER(work)) + return; + + if ((lastrun != 0) && (t < lastrun + (15 * 60))) + return; + + + for (work=unicast_subnet->workgrouplist; work; work = work->next) { + if (strcmp(global_myworkgroup, work->work_group) && + !ip_equal(work->dmb_addr, ipzero)) { + lastrun = t; + + DEBUG(3,("initiating DMB<->DMB sync with %s(%s)\n", + work->dmb_name.name, + inet_ntoa(work->dmb_addr))); + sync_browse_lists(work, + work->dmb_name.name, + work->dmb_name.name_type, + work->dmb_addr, False, False); + } + } +} diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c new file mode 100644 index 0000000000..b62d9b7569 --- /dev/null +++ b/source3/nmbd/nmbd_synclists.c @@ -0,0 +1,282 @@ +/* + Unix SMB/Netbios implementation. + Version 1.9. + NBT netbios routines and daemon - version 2 + Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Luke Kenneth Casson Leighton 1994-1998 + Copyright (C) Jeremy Allison 1994-1998 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + +/* this file handles asynchronous browse synchronisation requests. The + requests are done by forking and putting the result in a file in the + locks directory. We do it this way because we don't want nmbd to be + blocked waiting for some server to respond on a TCP connection. This + also allows us to have more than 1 sync going at once (tridge) */ + +#include "includes.h" +#include "smb.h" + +extern int DEBUGLEVEL; + +struct sync_record { + struct sync_record *next, *prev; + fstring workgroup; + fstring server; + pstring fname; + struct in_addr ip; + int pid; +}; + +/* a linked list of current sync connections */ +static struct sync_record *syncs; + +static FILE *fp; + +/******************************************************************* + This is the NetServerEnum callback. + ******************************************************************/ +static void callback(char *sname, uint32 stype, char *comment) +{ + fprintf(fp,"\"%s\" %08X \"%s\"\n", sname, stype, comment); +} + + +/******************************************************************* + Synchronise browse lists with another browse server. + Log in on the remote server's SMB port to their IPC$ service, + do a NetServerEnum and record the results in fname +******************************************************************/ +static void sync_child(char *name, int nm_type, + char *workgroup, + struct in_addr ip, BOOL local, BOOL servers, + char *fname) +{ + extern fstring local_machine; + static struct cli_state cli; + uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0; + + if (!cli_initialise(&cli) || !cli_connect(&cli, name, &ip)) { + fclose(fp); + return; + } + + if (!cli_session_request(&cli, name, nm_type, local_machine)) { + cli_shutdown(&cli); + fclose(fp); + return; + } + + if (!cli_negprot(&cli)) { + cli_shutdown(&cli); + return; + } + + if (!cli_session_setup(&cli, "", "", 1, "", 0, workgroup)) { + cli_shutdown(&cli); + return; + } + + if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) { + cli_shutdown(&cli); + return; + } + + /* Fetch a workgroup list. */ + cli_NetServerEnum(&cli, workgroup, + local_type|SV_TYPE_DOMAIN_ENUM, + callback); + + /* Now fetch a server list. */ + if (servers) { + cli_NetServerEnum(&cli, workgroup, + local?SV_TYPE_LOCAL_LIST_ONLY:SV_TYPE_ALL, + callback); + } + + cli_shutdown(&cli); +} + + +/******************************************************************* + initialise a browse sync with another browse server. Log in on the + remote server's SMB port to their IPC$ service, do a NetServerEnum + and record the results +******************************************************************/ +void sync_browse_lists(struct work_record *work, + char *name, int nm_type, + struct in_addr ip, BOOL local, BOOL servers) +{ + struct sync_record *s; + static int counter; + + /* Check we're not trying to sync with ourselves. This can + happen if we are a domain *and* a local master browser. */ + if (ismyip(ip)) { + return; + } + + s = (struct sync_record *)malloc(sizeof(*s)); + if (!s) return; + + ZERO_STRUCTP(s); + + fstrcpy(s->workgroup, work->work_group); + fstrcpy(s->server, name); + s->ip = ip; + + slprintf(s->fname, sizeof(pstring)-1, + "%s/sync.%d", lp_lockdir(), counter++); + string_sub(s->fname,"//", "/"); + + DLIST_ADD(syncs, s); + + /* the parent forks and returns, leaving the child to do the + actual sync */ + CatchChild(); + if ((s->pid = fork())) return; + + DEBUG(2,("Initiating browse sync for %s to %s(%s)\n", + work->work_group, name, inet_ntoa(ip))); + + fp = fopen(s->fname,"w"); + if (!fp) _exit(1); + + sync_child(name, nm_type, work->work_group, ip, local, servers, + s->fname); + + fclose(fp); + _exit(0); +} + +/********************************************************************** +handle one line from a completed sync file + **********************************************************************/ +static void complete_one(struct sync_record *s, + char *sname, uint32 stype, char *comment) +{ + struct work_record *work; + struct server_record *servrec; + + stype &= ~SV_TYPE_LOCAL_LIST_ONLY; + + if (stype & SV_TYPE_DOMAIN_ENUM) { + /* See if we can find the workgroup on this subnet. */ + if((work=find_workgroup_on_subnet(unicast_subnet, sname))) { + /* We already know about this workgroup - + update the ttl. */ + update_workgroup_ttl(work,lp_max_ttl()); + } else { + /* Create the workgroup on the subnet. */ + work = create_workgroup_on_subnet(unicast_subnet, + sname, lp_max_ttl()); + if (work) { + /* remember who the master is */ + fstrcpy(work->local_master_browser_name, + comment); + } + } + return; + } + + work = find_workgroup_on_subnet(unicast_subnet, s->workgroup); + if (!work) { + DEBUG(3,("workgroup %s doesn't exist on unicast subnet?\n", + s->workgroup)); + return; + } + + if ((servrec = find_server_in_workgroup( work, sname))) { + /* Check that this is not a locally known + server - if so ignore the entry. */ + if(!(servrec->serv.type & SV_TYPE_LOCAL_LIST_ONLY)) { + /* We already know about this server - update + the ttl. */ + update_server_ttl(servrec, lp_max_ttl()); + /* Update the type. */ + servrec->serv.type = stype; + } + return; + } + + /* Create the server in the workgroup. */ + create_server_on_workgroup(work, sname,stype, lp_max_ttl(), comment); +} + + +/********************************************************************** +read the completed sync info + **********************************************************************/ +static void complete_sync(struct sync_record *s) +{ + FILE *f; + fstring server, type_str; + unsigned type; + pstring comment; + pstring line; + char *ptr; + int count=0; + + f = fopen(s->fname,"r"); + + while (!feof(f)) { + + if (!fgets_slash(line,sizeof(pstring),f)) continue; + + ptr = line; + + DEBUG(9,("sync line [%s]\n", line)); + + if (!next_token(&ptr,server,NULL) || + !next_token(&ptr,type_str,NULL) || + !next_token(&ptr,comment,NULL)) { + continue; + } + + sscanf(type_str, "%X", &type); + + complete_one(s, server, type, comment); + + count++; + } + + fclose(f); + + unlink(s->fname); + + DEBUG(2,("sync with %s(%s) for workgroup %s completed (%d records)\n", + s->server, inet_ntoa(s->ip), s->workgroup, count)); +} + +/********************************************************************** +check for completion of any of the child processes + **********************************************************************/ +void sync_check_completion(void) +{ + struct sync_record *s, *next; + + for (s=syncs;s;s=next) { + next = s->next; + if (!process_exists(s->pid)) { + /* it has completed - grab the info */ + complete_sync(s); + DLIST_REMOVE(syncs, s); + ZERO_STRUCTP(s); + free(s); + } + } +} -- cgit From 98b0fafc6132e12bc9b7e39784cb2e221a8a5125 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 30 Aug 1998 16:33:48 +0000 Subject: a couple of debug lines (This used to be commit 03d343ddf5ef672afb3cf1fa65f86eb2c0a48772) --- source3/nmbd/asyncdns.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 9926045d82..8f28f515ea 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -136,6 +136,7 @@ void start_async_dns(void) CatchChild(); if (pipe(fd1) || pipe(fd2)) { + DEBUG(0,("can't create asyncdns pipes\n")); return; } @@ -146,6 +147,7 @@ void start_async_dns(void) fd_out = fd2[1]; close(fd1[1]); close(fd2[0]); + DEBUG(0,("started asyncdns process %d\n", child_pid)); return; } -- cgit From ab4577f141b0c08a543d998a36892bbafae4e902 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 30 Aug 1998 17:04:24 +0000 Subject: added a dest_port parameter to send_mailslot() so we send replies to the correct port in environments like ip masq. (This used to be commit 7d455ee637b6ff70c95845f89d71573ca07b83f3) --- source3/nmbd/nmbd_browsesync.c | 3 ++- source3/nmbd/nmbd_elections.c | 2 +- source3/nmbd/nmbd_incomingdgrams.c | 14 +++++++------- source3/nmbd/nmbd_packets.c | 7 +++---- source3/nmbd/nmbd_processlogon.c | 6 +++--- source3/nmbd/nmbd_sendannounce.c | 14 +++++++++----- 6 files changed, 25 insertions(+), 21 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index a4faca5515..8136568c6a 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -122,7 +122,8 @@ Do not announce to ourselves.\n", work->work_group )); to %s for workgroup %s.\n", namestr(&work->dmb_name), work->work_group )); send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), - global_myname, 0x0, work->dmb_name.name, 0x0, work->dmb_addr, FIRST_SUBNET->myip); + global_myname, 0x0, work->dmb_name.name, 0x0, + work->dmb_addr, FIRST_SUBNET->myip, DGRAM_PORT); } diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 5c85191ec2..cd310639e9 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -62,7 +62,7 @@ static void send_election_dgram(struct subnet_record *subrec, char *workgroup_na send_mailslot(False, BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), global_myname, 0, workgroup_name, 0x1e, - subrec->bcast_ip, subrec->myip); + subrec->bcast_ip, subrec->myip, DGRAM_PORT); } /******************************************************************* diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index daa321b3ae..36242d9ac2 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -536,12 +536,12 @@ originate from OS/2 Warp client. Ignoring packet.\n")); /**************************************************************************** Send a backup list response. *****************************************************************************/ - static void send_backup_list_response(struct subnet_record *subrec, - struct work_record *work, - struct nmb_name *send_to_name, - unsigned char max_number_requested, - uint32 token, struct in_addr sendto_ip) + struct work_record *work, + struct nmb_name *send_to_name, + unsigned char max_number_requested, + uint32 token, struct in_addr sendto_ip, + int port) { char outbuf[1024]; char *p, *countptr, *nameptr; @@ -610,7 +610,7 @@ static void send_backup_list_response(struct subnet_record *subrec, outbuf,PTR_DIFF(p,outbuf), global_myname, 0, send_to_name->name,0, - sendto_ip, subrec->myip); + sendto_ip, subrec->myip, port); } /******************************************************************* @@ -687,7 +687,7 @@ and I am not a local master browser.\n", workgroup_name)); } send_backup_list_response(subrec, work, &dgram->source_name, - max_number_requested, token, p->ip); + max_number_requested, token, p->ip, p->port); } /******************************************************************* diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 65d98c9a59..816695833a 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1875,13 +1875,12 @@ BOOL listen_for_packets(BOOL run_election) /**************************************************************************** Construct and send a netbios DGRAM. - Note that this currently sends all packets to port 138. **************************************************************************/ - BOOL send_mailslot(BOOL unique, char *mailslot,char *buf,int len, char *srcname, int src_type, char *dstname, int dest_type, - struct in_addr dest_ip,struct in_addr src_ip) + struct in_addr dest_ip,struct in_addr src_ip, + int dest_port) { BOOL loopback_this_packet = False; struct packet_struct p; @@ -1936,7 +1935,7 @@ BOOL send_mailslot(BOOL unique, char *mailslot,char *buf,int len, dgram->datasize = PTR_DIFF(p2,ptr+4); /* +4 for tcp length. */ p.ip = dest_ip; - p.port = DGRAM_PORT; + p.port = dest_port; p.fd = find_subnet_mailslot_fd_for_address( src_ip ); p.timestamp = time(NULL); p.packet_type = DGRAM_PACKET; diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 2ad4a831ca..29dc68fb80 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -112,7 +112,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); dgram->dest_name.name_type, dgram->source_name.name, dgram->source_name.name_type, - p->ip, *iface_ip(p->ip)); + p->ip, *iface_ip(p->ip), p->port); break; } @@ -167,7 +167,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", dgram->dest_name.name_type, dgram->source_name.name, dgram->source_name.name_type, - p->ip, *iface_ip(p->ip)); + p->ip, *iface_ip(p->ip), p->port); return; } @@ -243,7 +243,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", dgram->dest_name.name_type, dgram->source_name.name, dgram->source_name.name_type, - p->ip, *iface_ip(p->ip)); + p->ip, *iface_ip(p->ip), p->port); break; } diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index 6c9f67ab21..d43d2878e3 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -54,7 +54,8 @@ void send_browser_reset(int reset_type, char *to_name, int to_type, struct in_ad p++; send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), - global_myname, 0x0, to_name, to_type, to_ip, FIRST_SUBNET->myip); + global_myname, 0x0, to_name, to_type, to_ip, + FIRST_SUBNET->myip, DGRAM_PORT); } /**************************************************************************** @@ -84,7 +85,8 @@ to subnet %s\n", work->work_group, subrec->subnet_name)); p = skip_string(p,1); send_mailslot(False, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), - global_myname, 0x0, work->work_group,0x1e, subrec->bcast_ip, subrec->myip); + global_myname, 0x0, work->work_group,0x1e, subrec->bcast_ip, + subrec->myip, DGRAM_PORT); } /**************************************************************************** @@ -124,7 +126,8 @@ static void send_announcement(struct subnet_record *subrec, int announce_type, p = skip_string(p,1); send_mailslot(False,BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), - from_name, 0x0, to_name, to_type, to_ip, subrec->myip); + from_name, 0x0, to_name, to_type, to_ip, subrec->myip, + DGRAM_PORT); } /**************************************************************************** @@ -155,7 +158,8 @@ static void send_lm_announcement(struct subnet_record *subrec, int announce_type p = skip_string(p,1); send_mailslot(False,LANMAN_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), - from_name, 0x0, to_name, to_type, to_ip, subrec->myip); + from_name, 0x0, to_name, to_type, to_ip, subrec->myip, + DGRAM_PORT); } /**************************************************************************** @@ -601,6 +605,6 @@ for workgroup %s on subnet %s.\n", global_myworkgroup, FIRST_SUBNET->subnet_name global_myname, inet_ntoa(addr) )); send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), - global_myname, 0x0, "*", 0x0, addr, FIRST_SUBNET->myip); + global_myname, 0x0, "*", 0x0, addr, FIRST_SUBNET->myip, DGRAM_PORT); } } -- cgit From 61b5fd6f32e9ccb612df1354a3e3b3bed5f2b808 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 31 Aug 1998 03:11:42 +0000 Subject: bounds check next_token() to prevent possible buffer overflows (This used to be commit 3eade55dc7c842bdc50205c330802d211fae54d3) --- source3/nmbd/nmbd.c | 4 ++-- source3/nmbd/nmbd_sendannounce.c | 4 ++-- source3/nmbd/nmbd_synclists.c | 10 +++++----- source3/nmbd/nmbd_winsserver.c | 14 +++++++------- 4 files changed, 16 insertions(+), 16 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 9210ce4dcf..feb9c2420e 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -468,7 +468,7 @@ static BOOL init_structs(void) */ /* Work out the max number of netbios aliases that we have */ ptr = lp_netbios_aliases(); - for( namecount=0; next_token(&ptr,nbname,NULL); namecount++ ) + for( namecount=0; next_token(&ptr,nbname,NULL, sizeof(nbname)); namecount++ ) ; if ( *global_myname ) namecount++; @@ -487,7 +487,7 @@ static BOOL init_structs(void) my_netbios_names[namecount++] = global_myname; ptr = lp_netbios_aliases(); - while ( next_token( &ptr, nbname, NULL ) ) + while ( next_token( &ptr, nbname, NULL, sizeof(nbname) ) ) { strupper( nbname ); /* Look for duplicates */ diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index d43d2878e3..38c8deafe7 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -506,7 +506,7 @@ void announce_remote(time_t t) comment = lp_serverstring(); - for (ptr=s; next_token(&ptr,s2,NULL); ) + for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) { /* The entries are of the form a.b.c.d/WORKGROUP with WORKGROUP being optional */ @@ -596,7 +596,7 @@ for workgroup %s on subnet %s.\n", global_myworkgroup, FIRST_SUBNET->subnet_name strupper(p); p = skip_string(p,1); - for (ptr=s; next_token(&ptr,s2,NULL); ) + for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) { /* The entries are of the form a.b.c.d */ addr = *interpret_addr2(s2); diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index b62d9b7569..432b6dcbe2 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -150,6 +150,8 @@ void sync_browse_lists(struct work_record *work, CatchChild(); if ((s->pid = fork())) return; + BlockSignals( False, SIGTERM ); + DEBUG(2,("Initiating browse sync for %s to %s(%s)\n", work->work_group, name, inet_ntoa(ip))); @@ -239,11 +241,9 @@ static void complete_sync(struct sync_record *s) ptr = line; - DEBUG(9,("sync line [%s]\n", line)); - - if (!next_token(&ptr,server,NULL) || - !next_token(&ptr,type_str,NULL) || - !next_token(&ptr,comment,NULL)) { + if (!next_token(&ptr,server,NULL,sizeof(server)) || + !next_token(&ptr,type_str,NULL, sizeof(type_str)) || + !next_token(&ptr,comment,NULL, sizeof(comment))) { continue; } diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index d891124d06..2fcc95e1d6 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -211,13 +211,13 @@ BOOL initialise_wins(void) * time to actually parse them into the ip_list array. */ - if (!next_token(&ptr,name_str,NULL)) + if (!next_token(&ptr,name_str,NULL,sizeof(name_str))) { DEBUG(0,("initialise_wins: Failed to parse name when parsing line %s\n", line )); continue; } - if (!next_token(&ptr,ttl_str,NULL)) + if (!next_token(&ptr,ttl_str,NULL,sizeof(ttl_str))) { DEBUG(0,("initialise_wins: Failed to parse time to live when parsing line %s\n", line )); continue; @@ -229,7 +229,7 @@ BOOL initialise_wins(void) num_ips = 0; do { - got_token = next_token(&ptr,ip_str,NULL); + got_token = next_token(&ptr,ip_str,NULL,sizeof(ip_str)); was_ip = False; if(got_token && strchr(ip_str, '.')) @@ -260,16 +260,16 @@ BOOL initialise_wins(void) /* Reset and re-parse the line. */ ptr = line; - next_token(&ptr,name_str,NULL); - next_token(&ptr,ttl_str,NULL); + next_token(&ptr,name_str,NULL,sizeof(name_str)); + next_token(&ptr,ttl_str,NULL,sizeof(ttl_str)); for(i = 0; i < num_ips; i++) { - next_token(&ptr, ip_str, NULL); + next_token(&ptr, ip_str, NULL, sizeof(ip_str)); ip_list[i] = *interpret_addr2(ip_str); if (ip_equal(ip_list[i], ipzero)) source = SELF_NAME; } - next_token(&ptr,nb_flags_str,NULL); + next_token(&ptr,nb_flags_str,NULL, sizeof(nb_flags_str)); /* * Deal with SELF or REGISTER name encoding. Default is REGISTER -- cgit From 055e3c88e6d88bd7dee5ae9c87dc04433124f660 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 31 Aug 1998 04:19:31 +0000 Subject: set a maximum name refresh time of 20 minutes. The previous code was strictly correct, but not very practical. self names were only refreshed every 3 days. I hit a situation where the Samba WINS server was restarted after deleting wins.dat and didn't notice some remote subnets (also running Samba). I realised that the complete database wouldn't have been rebuilt for 3 days, which is way too long. In order to recover from WINS restarts we need a much shorter maximum refresh time. (This used to be commit 1d23dd0912e81ff72695bd043e8e2aee32da18a8) --- source3/nmbd/nmbd_mynames.c | 2 +- source3/nmbd/nmbd_namelistdb.c | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index ba42274165..4a4e102786 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -197,7 +197,7 @@ void refresh_my_names(time_t t) if( !is_refresh_already_queued( subrec, namerec) ) refresh_name( subrec, namerec, NULL, NULL, NULL ); namerec->data.death_time += lp_max_ttl(); - namerec->data.refresh_time += lp_max_ttl(); + namerec->data.refresh_time += MIN(lp_max_ttl(), MAX_REFRESH_TIME); } } } diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index de5835a115..498cbcfdcf 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -186,7 +186,7 @@ void update_name_ttl( struct name_record *namerec, int ttl ) if( namerec->data.death_time != PERMANENT_TTL ) namerec->data.death_time = time_now + ttl; - namerec->data.refresh_time = time_now + (ttl/2); + namerec->data.refresh_time = time_now + MIN((ttl/2), MAX_REFRESH_TIME); namerec->subnet->namelist_changed = True; } /* update_name_ttl */ @@ -251,7 +251,7 @@ struct name_record *add_name_to_subnet( struct subnet_record *subrec, else namerec->data.death_time = time_now + ttl; - namerec->data.refresh_time = time_now + (ttl/2); + namerec->data.refresh_time = time_now + MIN((ttl/2), MAX_REFRESH_TIME); /* Now add the record to the name list. */ update_name_in_namelist( subrec, namerec ); -- cgit From f8ad53aa037b362b37592ca04b160cb81ccdecc8 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 31 Aug 1998 06:59:23 +0000 Subject: I realised that my DMB<->DMB sync code has the property that the amount of network traffic grows as the square of the number of workgroups. It probably wouldn't have caused problems but to be safe I changed the code to use random() to decrease the probability of a DMB<->DMB sync in proportion to the number of known workgroups. This keeps the nice browse connectivity while making the traffic rise only linearly with the number of workgroups. (This used to be commit 685f4ef2e1f83ab39e91229cf53a61eecb6181eb) --- source3/nmbd/nmbd.c | 2 ++ source3/nmbd/nmbd_browsesync.c | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index feb9c2420e..72cc9408d5 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -567,6 +567,8 @@ int main(int argc,char *argv[]) StartupTime = time(NULL); + srandom(time(NULL) ^ getpid()); + TimeInit(); pstrcpy( debugf, NMBLOGFILE ); diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 8136568c6a..b1fb4e631f 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -556,12 +556,17 @@ void collect_all_workgroup_names_from_wins_server(time_t t) /**************************************************************************** If we are a domain master browser on the unicast subnet, do a regular sync - with all other DMBs that we know of on that subnet + with all other DMBs that we know of on that subnet. + +To prevent exponential network traffic with large numbers of workgroups +we use a randomised system where sync probability is inversely proportional +to the number of known workgroups **************************************************************************/ void sync_all_dmbs(time_t t) { static time_t lastrun = 0; struct work_record *work; + int count=0; /* Only do this if we are using a WINS server. */ if(we_are_a_wins_client() == False) @@ -575,13 +580,24 @@ void sync_all_dmbs(time_t t) if (!AM_DOMAIN_MASTER_BROWSER(work)) return; - if ((lastrun != 0) && (t < lastrun + (15 * 60))) + if ((lastrun != 0) && (t < lastrun + (5 * 60))) return; + /* count how many syncs we might need to do */ + for (work=unicast_subnet->workgrouplist; work; work = work->next) { + if (strcmp(global_myworkgroup, work->work_group) && + !ip_equal(work->dmb_addr, ipzero)) { + count++; + } + } + /* sync with a probability of 1/count */ for (work=unicast_subnet->workgrouplist; work; work = work->next) { if (strcmp(global_myworkgroup, work->work_group) && !ip_equal(work->dmb_addr, ipzero)) { + + if (((unsigned)random()) % count != 0) continue; + lastrun = t; DEBUG(3,("initiating DMB<->DMB sync with %s(%s)\n", -- cgit From 5e20600e54a275d39e79f4547cb55c5946c14117 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 31 Aug 1998 07:23:11 +0000 Subject: minor fixes to the DMB<->DMB sync code. We now get the dmb name from the local_master name on the unicast subnet if it is unknown. (This used to be commit 222b6d90e09288091028f5e0435f1d4a74153f66) --- source3/nmbd/nmbd_browsesync.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index b1fb4e631f..5969395ef7 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -585,21 +585,26 @@ void sync_all_dmbs(time_t t) /* count how many syncs we might need to do */ for (work=unicast_subnet->workgrouplist; work; work = work->next) { - if (strcmp(global_myworkgroup, work->work_group) && - !ip_equal(work->dmb_addr, ipzero)) { + if (strcmp(global_myworkgroup, work->work_group)) { count++; } } /* sync with a probability of 1/count */ for (work=unicast_subnet->workgrouplist; work; work = work->next) { - if (strcmp(global_myworkgroup, work->work_group) && - !ip_equal(work->dmb_addr, ipzero)) { - + if (strcmp(global_myworkgroup, work->work_group)) { if (((unsigned)random()) % count != 0) continue; lastrun = t; + if (!work->dmb_name.name[0]) { + /* we don't know the DMB - assume it is + the same as the unicast local master */ + make_nmb_name(&work->dmb_name, + work->local_master_browser_name, + 0x20, scope); + } + DEBUG(3,("initiating DMB<->DMB sync with %s(%s)\n", work->dmb_name.name, inet_ntoa(work->dmb_addr))); -- cgit From a2450e6fb3a2b53bdfc128b851f0d44d245e9eeb Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 31 Aug 1998 09:38:50 +0000 Subject: I looked at the refresh issue a bit more and discovered that Samba also doesn't switch to a registration if a refresh fails, instead the name is removed! This makes it even more imortant that a Samba WINS server accepts refresh requests as registration requests if the name is not registered. I've gone ahead and implemented this. (This used to be commit 07f825fc9491bb5adac047854e67c63f7757143b) --- source3/nmbd/nmbd_winsserver.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 2fcc95e1d6..48d27f7bae 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -420,14 +420,15 @@ IP %s\n", namestr(question), inet_ntoa(from_ip) )); /* * If this is a refresh request and the name doesn't exist then - * fail it. + * treat it like a registration request. This allows us to recover + * from errors (tridge) */ if(namerec == NULL) { DEBUG(3,("wins_process_name_refresh_request: Name refresh for name %s and \ -the name does not exist.\n", namestr(question) )); - send_wins_name_registration_response(NAM_ERR, 0, p); +the name does not exist. Treating as registration.\n", namestr(question) )); + wins_process_name_registration_request(subrec,p); return; } -- cgit From 148691b1c5e8e93b02762757345a54c82e6fdadc Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 2 Sep 1998 05:00:47 +0000 Subject: we are never interested in SIGPIPE so just ignore (block) it always. Don't even install a handler. (This used to be commit 72c383f4b7bcce5374632dc972df16ab0e2542b9) --- source3/nmbd/nmbd.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 72cc9408d5..ef3713c134 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -103,17 +103,6 @@ static void sig_hup(int sig) } /* sig_hup */ -/**************************************************************************** ** - catch a sigpipe - **************************************************************************** */ -static void sig_pipe(int sig) -{ - BlockSignals( True, SIGPIPE ); - - DEBUG( 0, ("Got SIGPIPE\n") ); - - BlockSignals( False, SIGPIPE ); -} /* sig_pipe */ #if DUMP_CORE /**************************************************************************** ** @@ -432,7 +421,8 @@ static BOOL open_sockets(BOOL isdaemon, int port) if ( ClientNMB == -1 ) return( False ); - CatchSignal( SIGPIPE, SIGNAL_CAST sig_pipe ); + /* we are never interested in SIGPIPE */ + BlockSignals(True,SIGPIPE); set_socket_options( ClientNMB, "SO_BROADCAST" ); set_socket_options( ClientDGRAM, "SO_BROADCAST" ); -- cgit From e9ea36e4d2270bd7d32da12ef6d6e2299641582d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 5 Sep 1998 05:07:05 +0000 Subject: tridge the destroyer returns! prompted by the interpret_security() dead code that Jean-Francois pointed out I added a make target "finddead" that finds potentially dead (ie. unused) code. It spat out 304 function names ... I went through these are deleted many of them, making others static (finddead also reports functions that are used only in the local file). in doing this I have almost certainly deleted some useful code. I may have even prevented compilation with some compile options. I apologise. I decided it was better to get rid of this code now and add back the one or two functions that are needed than to keep all this baggage. So, if I have done a bit too much "destroying" then let me know. Keep the swearing to a minimum :) One bit I didn't do is the ubibt code. Chris, can you look at that? Heaps of unused functions there. Can they be made static? (This used to be commit 2204475c87f3024ea8fd1fbd7385b2def617a46f) --- source3/nmbd/nmbd_become_dmb.c | 108 ---------------------------------- source3/nmbd/nmbd_become_lmb.c | 4 +- source3/nmbd/nmbd_browserdb.c | 34 ----------- source3/nmbd/nmbd_namelistdb.c | 15 ----- source3/nmbd/nmbd_packets.c | 15 +++-- source3/nmbd/nmbd_responserecordsdb.c | 2 +- 6 files changed, 10 insertions(+), 168 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index fe02f18f06..cfaec3378d 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -37,114 +37,6 @@ extern uint16 samba_nb_type; /* Samba's NetBIOS type. */ static void become_domain_master_browser_bcast(char *); -/******************************************************************* - Unbecome a domain master browser - name release success function. - ******************************************************************/ - -static void unbecome_dmb_success(struct subnet_record *subrec, - struct userdata_struct *userdata, - struct nmb_name *released_name, - struct in_addr released_ip) -{ - struct work_record *work = find_workgroup_on_subnet(subrec, released_name->name); - struct server_record *servrec; - - if(!work) - { - DEBUG(0,("unbecome_dmb_success: Cannot find workgroup %s on subnet %s\n", - released_name->name, subrec->subnet_name)); - return; - } - - if((servrec = find_server_in_workgroup( work, global_myname)) == NULL) - { - DEBUG(0,("unbecome_dmb_success: Error - cannot find server %s \ -in workgroup %s on subnet %s\n", - global_myname, released_name->name, subrec->subnet_name)); - return; - } - - /* Set the state in the workgroup structure. */ - work->dom_state = DOMAIN_NONE; - - /* Update our server status. */ - servrec->serv.type &= ~SV_TYPE_DOMAIN_MASTER; - - /* Tell the namelist writer to write out a change. */ - subrec->work_changed = True; - - /* Remove any list of local master browsers we are syncing with. */ - remove_workgroup_lmb_browsers(released_name->name); - - /* Delete the known domain master browser name from the workgroup - struct. */ - bzero((char *)&work->dmb_name, sizeof(work->dmb_name)); - putip((char *)&work->dmb_addr, &ipzero); - - if( DEBUGLVL( 0 ) ) - { - dbgtext( "*****\n\nSamba server %s ", global_myname ); - dbgtext( "has stopped being a domain master browser " ); - dbgtext( "for workgroup %s ", work->work_group ); - dbgtext( "on subnet %s.\n\n*****\n", subrec->subnet_name ); - } - -} - -/******************************************************************* - Unbecome a domain master browser - name release fail function. - ******************************************************************/ - -static void unbecome_dmb_fail(struct subnet_record *subrec, - struct response_record *rrec, - struct nmb_name *released_name) -{ - if( DEBUGLVL( 0 ) ) - { - dbgtext( "unbecome_dmb_fail: Failed to unbecome domain master browser " ); - dbgtext( "for workgroup %s ", released_name->name ); - dbgtext( "on subnet %s.\n", subrec->subnet_name ); - } -} - -/******************************************************************* - Unbecome a domain master browser. - ******************************************************************/ - -void unbecome_domain_master(char *workgroup_name) -{ - struct subnet_record *subrec; - - for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) - { - struct work_record *work = find_workgroup_on_subnet(subrec, workgroup_name); - - if(work && (work->dom_state == DOMAIN_MST)) - { - struct name_record *namerec; - struct nmb_name nmbname; - make_nmb_name(&nmbname,workgroup_name,0x1b,scope); - - /* We can only do this if we are a domain master already. */ - DEBUG(2,("unbecome_domain_master: attempting to stop being a domain \ -master browser for workgroup %s on subnet %s\n", - work->work_group, subrec->subnet_name)); - - /* Find the WORKGROUP<1b> name on the subnet namelist. */ - if((namerec = find_name_on_subnet(subrec, &nmbname, FIND_SELF_NAME))==NULL) - { - DEBUG(0,("unbecome_domain_master: Cannot find name %s on subnet %s.\n", - namestr(&nmbname), subrec->subnet_name)); - continue; - } - release_name(subrec, namerec, - unbecome_dmb_success, - unbecome_dmb_fail, - NULL); - } - } -} - /**************************************************************************** Fail to become a Domain Master Browser on a subnet. ****************************************************************************/ diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index 3fe6f596fa..1e4f070271 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -138,7 +138,7 @@ in workgroup %s on subnet %s\n", Unbecome the local master browser name release success function. ******************************************************************/ -void unbecome_local_master_success(struct subnet_record *subrec, +static void unbecome_local_master_success(struct subnet_record *subrec, struct userdata_struct *userdata, struct nmb_name *released_name, struct in_addr released_ip) @@ -168,7 +168,7 @@ void unbecome_local_master_success(struct subnet_record *subrec, Unbecome the local master browser name release fail function. ******************************************************************/ -void unbecome_local_master_fail(struct subnet_record *subrec, struct response_record *rrec, +static void unbecome_local_master_fail(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *fail_name) { struct name_record *namerec; diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c index 8e32dbd570..12ce00df4f 100644 --- a/source3/nmbd/nmbd_browserdb.c +++ b/source3/nmbd/nmbd_browserdb.c @@ -183,37 +183,3 @@ void expire_lmb_browsers( time_t t ) } } } /* expire_lmb_browsers */ - -/* ************************************************************************** ** - * Remove browsers from a named workgroup in the browserlist. - * - * Input: work_group - The name of the work group which is to be removed - * from the browse list. - * Output: none. - * - * ************************************************************************** ** - */ -void remove_workgroup_lmb_browsers( char *work_group ) -{ - struct browse_cache_record *browc; - struct browse_cache_record *nextbrowc; - - for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist ); - browc; - browc = nextbrowc ) - { - nextbrowc = (struct browse_cache_record *)ubi_dlNext( browc ); - - if( strequal( work_group, browc->work_group ) ) - { - if( DEBUGLVL( 3 ) ) - { - Debug1( "nmbd_browserdb:remove_workgroup_browsers()\n" ); - Debug1( "Removing lmb entry %s\n", browc->lmb_name ); - } - remove_lmb_browser_entry(browc); - } - } - } /* remove_workgroup_lmb_browsers */ - -/* ========================================================================== */ diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 498cbcfdcf..f9b2e3da9a 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -44,21 +44,6 @@ void set_samba_nb_type(void) samba_nb_type = NB_BFLAG; /* samba is broadcast-only node type. */ } /* set_samba_nb_type */ -/* ************************************************************************** ** - * Returns True if the netbios name is ^1^2__MSBROWSE__^2^1. - * - * Note: This name is registered if as a master browser or backup browser - * you are responsible for a workgroup (when you announce a domain by - * broadcasting on your local subnet, you announce it as coming from this - * name: see announce_host()). - * - * ************************************************************************** ** - */ -BOOL ms_browser_name( char *name, int type ) - { - return( strequal( name, MSBROWSE ) && (type == 0x01) ); - } /* ms_browser_name */ - /* ************************************************************************** ** * Convert a NetBIOS name to upper case. * ************************************************************************** ** diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 816695833a..10ce2da0c1 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -35,6 +35,8 @@ extern int num_response_packets; extern pstring scope; extern struct in_addr loopback_ip; +static void queue_packet(struct packet_struct *packet); + /******************************************************************* The global packet linked-list. Incoming entries are added to the end of this list. It is supposed to remain fairly @@ -963,8 +965,7 @@ for id %hu\n", /******************************************************************* Queue a packet into a packet queue ******************************************************************/ - -void queue_packet(struct packet_struct *packet) +static void queue_packet(struct packet_struct *packet) { struct packet_struct *p; @@ -1013,8 +1014,7 @@ static struct subnet_record *find_subnet_for_dgram_browse_packet(struct packet_s /**************************************************************************** Dispatch a browse frame from port 138 to the correct processing function. ****************************************************************************/ - -void process_browse_packet(struct packet_struct *p, char *buf,int len) +static void process_browse_packet(struct packet_struct *p, char *buf,int len) { struct dgram_packet *dgram = &p->packet.dgram; int command = CVAL(buf,0); @@ -1135,8 +1135,7 @@ command code %d from %s IP %s to %s\n", /**************************************************************************** Dispatch a LanMan browse frame from port 138 to the correct processing function. ****************************************************************************/ - -void process_lanman_packet(struct packet_struct *p, char *buf,int len) +static void process_lanman_packet(struct packet_struct *p, char *buf,int len) { struct dgram_packet *dgram = &p->packet.dgram; int command = SVAL(buf,0); @@ -1284,7 +1283,7 @@ static void process_dgram(struct packet_struct *p) Validate a response nmb packet. ****************************************************************************/ -BOOL validate_nmb_response_packet( struct nmb_packet *nmb ) +static BOOL validate_nmb_response_packet( struct nmb_packet *nmb ) { BOOL ignore = False; @@ -1338,7 +1337,7 @@ BOOL validate_nmb_response_packet( struct nmb_packet *nmb ) Validate a request nmb packet. ****************************************************************************/ -BOOL validate_nmb_packet( struct nmb_packet *nmb ) +static BOOL validate_nmb_packet( struct nmb_packet *nmb ) { BOOL ignore = False; diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index 21defa970c..3edca69981 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -37,7 +37,7 @@ int num_response_packets = 0; Add an expected response record into the list **************************************************************************/ -void add_response_record(struct subnet_record *subrec, +static void add_response_record(struct subnet_record *subrec, struct response_record *rrec) { struct response_record *rrec2; -- cgit From 5de3c136808d891ca25009beefc194dc825a5a16 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Wed, 9 Sep 1998 16:37:54 +0000 Subject: Copyright notices written to debug logs are now through 1998. Chris -)----- (This used to be commit ac13c29d46f564fc340b652b4b71dfa92e4b5b16) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index ef3713c134..482e136ba4 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -662,7 +662,7 @@ int main(int argc,char *argv[]) reopen_logs(); DEBUG( 1, ( "Netbios nameserver version %s started.\n", VERSION ) ); - DEBUGADD( 1, ( "Copyright Andrew Tridgell 1994-1997\n" ) ); + DEBUGADD( 1, ( "Copyright Andrew Tridgell 1994-1998\n" ) ); if( !get_myname( myhostname, NULL) ) { -- cgit From 42edee90bfd597474cebdb932bff113dff4a57bf Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 10 Sep 1998 04:00:09 +0000 Subject: fixed a bug in the wins database writer that caused the database to be written continuously rather than once every 5 seconds (at most). also changed it to 20 seconds :) (This used to be commit 1b07de7079e81da9c0b930bdc30ae0451b57d53a) --- source3/nmbd/nmbd_winsserver.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 48d27f7bae..1502dd8155 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1524,9 +1524,11 @@ void initiate_wins_processing(time_t t) if (!lasttime) lasttime = t; - if (t - lasttime < 5) + if (t - lasttime < 20) return; + lasttime = t; + if(!lp_we_are_a_wins_server()) return; @@ -1541,17 +1543,23 @@ void initiate_wins_processing(time_t t) /******************************************************************* Write out the current WINS database. ******************************************************************/ - void wins_write_database(void) { struct name_record *namerec; pstring fname, fnamenew; - + static int child_pid; + FILE *fp; if(!lp_we_are_a_wins_server()) return; + /* we will do the writing in a child process to ensure that the parent + doesn't block while this is done */ + if ((child_pid=fork())) { + return; + } + pstrcpy(fname,lp_lockdir()); trim_string(fname,NULL,"/"); pstrcat(fname,"/"); -- cgit From e959f2e2322cfac811946d418406267629a2c12b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 17 Sep 1998 06:36:08 +0000 Subject: fixed a potential problem with wins_write_database() child processes. In sig_term() we were calling wins_write_database(0) which would fork a child. This child might then get killed by the same process killing off the parent. That process would then fork another child etc. The solution is to pass a "background" flag to wins_write_database(0) and only fork if this is set. (This used to be commit 1e1a512e3ff59f962fb3de382f671618bed60839) --- source3/nmbd/nmbd.c | 2 +- source3/nmbd/nmbd_serverlistdb.c | 3 ++- source3/nmbd/nmbd_winsserver.c | 21 ++++++++++----------- 3 files changed, 13 insertions(+), 13 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 482e136ba4..d7383fb736 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -68,7 +68,7 @@ static void sig_term(int sig) DEBUG(0,("Got SIGTERM: going down...\n")); /* Write out wins.dat file if samba is a WINS server */ - wins_write_database(); + wins_write_database(False); /* Remove all SELF registered names. */ release_my_names(); diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index a4dab6f419..458fbd0085 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -321,6 +321,8 @@ void write_browse_list(time_t t, BOOL force_write) return; } + lasttime = t; + dump_workgroups(force_write); for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) @@ -335,7 +337,6 @@ void write_browse_list(time_t t, BOOL force_write) if(!list_changed) return; - lasttime = t; updatecount++; pstrcpy(fname,lp_lockdir()); diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 1502dd8155..3c831ee1ea 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1535,7 +1535,7 @@ void initiate_wins_processing(time_t t) expire_names_on_subnet(wins_server_subnet, t); if(wins_server_subnet->namelist_changed) - wins_write_database(); + wins_write_database(True); wins_server_subnet->namelist_changed = False; } @@ -1543,7 +1543,7 @@ void initiate_wins_processing(time_t t) /******************************************************************* Write out the current WINS database. ******************************************************************/ -void wins_write_database(void) +void wins_write_database(BOOL background) { struct name_record *namerec; pstring fname, fnamenew; @@ -1556,16 +1556,15 @@ void wins_write_database(void) /* we will do the writing in a child process to ensure that the parent doesn't block while this is done */ - if ((child_pid=fork())) { - return; + if (background) { + CatchChild(); + if ((child_pid=fork())) { + return; + } } - pstrcpy(fname,lp_lockdir()); - trim_string(fname,NULL,"/"); - pstrcat(fname,"/"); - pstrcat(fname,WINS_LIST); - pstrcpy(fnamenew,fname); - pstrcat(fnamenew,"."); + slprintf(fname,sizeof(fname),"%s/%s.%d", lp_lockdir(), WINS_LIST, getpid()); + string_sub(s->fname,"//", "/"); if((fp = fopen(fnamenew,"w")) == NULL) { @@ -1612,7 +1611,7 @@ void wins_write_database(void) } fclose(fp); - unlink(fname); chmod(fnamenew,0644); + unlink(fname); rename(fnamenew,fname); } -- cgit From 1eef953aca34f76b464f06372e927b08d33b2022 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 17 Sep 1998 08:23:00 +0000 Subject: fixed a typo in my last commit (This used to be commit 31b4048362c63ab19e9ef35453c3763eec8b8f2b) --- source3/nmbd/nmbd_winsserver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 3c831ee1ea..c81e0a913e 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1564,7 +1564,7 @@ void wins_write_database(BOOL background) } slprintf(fname,sizeof(fname),"%s/%s.%d", lp_lockdir(), WINS_LIST, getpid()); - string_sub(s->fname,"//", "/"); + string_sub(fname,"//", "/"); if((fp = fopen(fnamenew,"w")) == NULL) { -- cgit From d66a657f90b1c8410f2d49be87539954a39a0469 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 17 Sep 1998 08:27:46 +0000 Subject: fixed the nmbd fork bomb. It was a silly mistake, as expected. wins_write_database() didn't exit after doing its stuff, so when it returned you had two copies of nmbd :) (This used to be commit 5e6488d4830016ea720a644c1b1ae25b336d3b8b) --- source3/nmbd/nmbd_winsserver.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index c81e0a913e..64f3142972 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1614,4 +1614,7 @@ void wins_write_database(BOOL background) chmod(fnamenew,0644); unlink(fname); rename(fnamenew,fname); + if (background) { + _exit(0); + } } -- cgit From c8e6aa6dc169f717b9d05b32fc666c0656fd54b3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 17 Sep 1998 08:35:07 +0000 Subject: fixed another potential fork bomb where the wins file becomes non-writeable for some reason. (This used to be commit 9edd43dcd6cc040416f11e00320c53682558fd8a) --- source3/nmbd/nmbd_synclists.c | 2 ++ source3/nmbd/nmbd_winsserver.c | 3 +++ 2 files changed, 5 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 432b6dcbe2..dee64d501b 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -234,6 +234,8 @@ static void complete_sync(struct sync_record *s) int count=0; f = fopen(s->fname,"r"); + + if (!f) return; while (!feof(f)) { diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 64f3142972..72386bd55b 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1569,6 +1569,9 @@ void wins_write_database(BOOL background) if((fp = fopen(fnamenew,"w")) == NULL) { DEBUG(0,("wins_write_database: Can't open %s. Error was %s\n", fnamenew, strerror(errno))); + if (background) { + _exit(0); + } return; } -- cgit From ac9b687cc2496409e1c8d86393812faf94ec7550 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 17 Sep 1998 19:16:12 +0000 Subject: configure configure.in: Added tests for fseek64 and ftell64. config.h.in: Added fseek64 and ftell64. includes.h: Added definition of SMB_BIG_INTEGER. smb.h: Changed (*getsmbpwpos) and (*setsmbpwpos) to use SMB_BIG_INTEGER. access.c: Tidyup of dbug statement. system.c: Added sys_fseek and sys_ftell. Changed mode calls to use mode_t. asyncdns.c: Tidyup of comment. loadparm.c: Tidyup of set_default_server_announce_type() function definition. ldap.c: Changed (*getsmbpwpos) and (*setsmbpwpos) to use SMB_BIG_INTEGER. nispass.c: Changed (*getsmbpwpos) and (*setsmbpwpos) to use SMB_BIG_INTEGER. smbpass.c: Changed (*getsmbpwpos) and (*setsmbpwpos) to use SMB_BIG_INTEGER. smbpassfile.c: Use sys_fseek(). chgpasswd.c: Tidyup of debug statement. dosmode.c: Changed mode calls to use mode_t. ipc.c: Removal of dead code. nttrans.c: Changed mode calls to use mode_t. open.c: Changed mode calls to use mode_t. pipes.c: Removal of dead code. reply.c: Removal of dead code. trans2.c: Removal of dead code. Changed mode calls to use mode_t. Jeremy. (This used to be commit c381d32e3dc23fe887408016cae821aceb30da2c) --- source3/nmbd/asyncdns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 8f28f515ea..3054ad7353 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -313,7 +313,7 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, /*************************************************************************** - we use this then we can't do async DNS lookups + we use this when we can't do async DNS lookups ****************************************************************************/ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, struct name_record **n) -- cgit From 1e17cbd2a3db061c8638ee8566ded53d14878bca Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 Sep 1998 00:12:15 +0000 Subject: nmbd/nmbd_winsserver.c: Fixed printf style warning. script/mkproto.awk: Added SMB_BIG_UINT. Jeremy. (This used to be commit c22c40f0caa7d6a9e8120e6415fa728db708db3e) --- source3/nmbd/nmbd_winsserver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 72386bd55b..1ce9160dea 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1563,7 +1563,7 @@ void wins_write_database(BOOL background) } } - slprintf(fname,sizeof(fname),"%s/%s.%d", lp_lockdir(), WINS_LIST, getpid()); + slprintf(fname,sizeof(fname),"%s/%s.%d", lp_lockdir(), WINS_LIST, (unsigned int)getpid()); string_sub(fname,"//", "/"); if((fp = fopen(fnamenew,"w")) == NULL) -- cgit From 2e6f6bc7f811dadab9fdd393981b37dfdbcd1fbc Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 18 Sep 1998 13:52:30 +0000 Subject: oops ... I got the filenames wrong in my cleanup of the wins database save, so it started saving weird filenames (from an unitialised fstring). chaos reigns! (This used to be commit 20a550d61e322cc9a0acfdf8fb974dafe0cd9603) --- source3/nmbd/nmbd_winsserver.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 1ce9160dea..cba3c1b308 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1563,8 +1563,9 @@ void wins_write_database(BOOL background) } } - slprintf(fname,sizeof(fname),"%s/%s.%d", lp_lockdir(), WINS_LIST, (unsigned int)getpid()); + slprintf(fname,sizeof(fname),"%s/%s", lp_lockdir(), WINS_LIST); string_sub(fname,"//", "/"); + slprintf(fnamenew,sizeof(fnamenew),"%s.%u", fname, (unsigned int)getpid()); if((fp = fopen(fnamenew,"w")) == NULL) { -- cgit From e649750cb4d2d2577f0577b1d7a87ae4daf8fb6f Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Mon, 21 Sep 1998 09:07:08 +0000 Subject: major autoconf clean-up fix problems in builds with srcdir!=builddir (This used to be commit 1ffc3b807a3f80644c974b454ff5e6f68e89b546) --- source3/nmbd/dummy.in | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/dummy.in b/source3/nmbd/dummy.in index e69de29bb2..8b13789179 100644 --- a/source3/nmbd/dummy.in +++ b/source3/nmbd/dummy.in @@ -0,0 +1 @@ + -- cgit From ac39ce3eba28eed97942e915f7b4cd77cdfd9e2d Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Mon, 21 Sep 1998 11:34:44 +0000 Subject: replace getpass() with getsmbpass() if getsmbpass.c compiles (This used to be commit 9a5bdf5c1bef689fe0d6879949df869efbc34783) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index d7383fb736..ba72724d2b 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -542,7 +542,7 @@ static void usage(char *pname) /**************************************************************************** ** main program **************************************************************************** */ -int main(int argc,char *argv[]) + int main(int argc,char *argv[]) { int opt; extern FILE *dbf; -- cgit From 66d5d73a5d75e88a77970f7b27687b8354ab2e80 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Fri, 25 Sep 1998 21:01:52 +0000 Subject: added rpcclient program (This used to be commit aa38f39d67fade4dfd7badb7a9b39c833a1dd1ca) --- source3/nmbd/nmbd_synclists.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index dee64d501b..b6f54dccec 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -32,6 +32,7 @@ #include "smb.h" extern int DEBUGLEVEL; +extern pstring scope; struct sync_record { struct sync_record *next, *prev; @@ -69,13 +70,18 @@ static void sync_child(char *name, int nm_type, extern fstring local_machine; static struct cli_state cli; uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0; + struct nmb_name called, calling; if (!cli_initialise(&cli) || !cli_connect(&cli, name, &ip)) { fclose(fp); return; } - if (!cli_session_request(&cli, name, nm_type, local_machine)) { + make_nmb_name(&calling, local_machine, 0x0 , scope); + make_nmb_name(&called , name , nm_type, scope); + + if (!cli_session_request(&cli, &calling, &called)) + { cli_shutdown(&cli); fclose(fp); return; -- cgit From 5f7ee360567a6b4e1a6f43ff01da057d2998fef8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 25 Sep 1998 23:40:49 +0000 Subject: Makefile.in: Fixed bug with continuation line causing proto to fail. Added $(PROGS) $(SPROGS) as targets for make clean. acconfig.h: Added HAVE_IRIX_SPECIFIC_CAPABILITIES. configure.in: Added sys/capability.h header check. Added function checks for srandom random srand rand. Added HAVE_IRIX_SPECIFIC_CAPABILITIES test. includes.h: Added #include . ntdomain.h: Moved struct acct_info into here from smb.h smb.h: Added KERNEL_OPLOCK_CAPABILITY define. Moved enum action_type into rpcclient.h Moved struct cli_state into client.h Moved struct nt_client_info, struct tar_client_info, struct client_info into rpcclient.h lib/genrand.c: Changed to use sys_random() & friends. lib/smbrun.c: Lose capabilities after fork. lib/system.c: Added set_process_capability(), set_inherited_process_capability() sys_random(), sys_srandom(). lib/util.c: Added Ander's EFBIG lock check to fcntl_lock for 64 bit access to an 32 bit mounted NFS filesystem. nmbd/nmbd.c: Changed to use sys_random() & friends. nmbd/nmbd_browsesync.c: Changed to use sys_random() & friends. passdb/ldap.c: Missed one pdb_encode_acct_ctrl call. passdb/passdb.c: Changed to Ander's code for ' ' characters. passdb/smbpass.c: Added Ander's code to reset ACB_PWNOTREQ. script/mkproto.awk: Added 'long' to prototypes. smbd/chgpasswd.c: Lose capabilities after fork. smbd/open.c: Do the mmap *after* the kernel oplock. smbd/oplock.c: Removed stub code from kernel oplock path. Added set_process_capability(), set_inherited_process_capability() calls. smbd/reply.c: Initialize count = 0, offset = 0. smbd/server.c: Added set_process_capability(), set_inherited_process_capability() calls. tests/summary.c: Ensure we have RANDOM or RAND. utils/smbpasswd.c: Added Ander's code to reset ACB_PWNOTREQ. utils/torture.c: Changed to use sys_random() & friends. Jeremy. (This used to be commit e8be306f23963ac00b1a383ebe0cc1421529fb02) --- source3/nmbd/nmbd.c | 2 +- source3/nmbd/nmbd_browsesync.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index ba72724d2b..bdafdd44fc 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -557,7 +557,7 @@ static void usage(char *pname) StartupTime = time(NULL); - srandom(time(NULL) ^ getpid()); + sys_srandom(time(NULL) ^ getpid()); TimeInit(); diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 5969395ef7..da514076e6 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -593,7 +593,7 @@ void sync_all_dmbs(time_t t) /* sync with a probability of 1/count */ for (work=unicast_subnet->workgrouplist; work; work = work->next) { if (strcmp(global_myworkgroup, work->work_group)) { - if (((unsigned)random()) % count != 0) continue; + if (((unsigned)sys_random()) % count != 0) continue; lastrun = t; -- cgit From cf971f88ac188eec353a7fb021744b8076cc4eb7 Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Mon, 28 Sep 1998 00:14:36 +0000 Subject: automated generation of .dummy files for each subdirectory; dummy.in files are no longer needed, and new directories will be taken care of automatically, at configure (or config.status --recheck) time (This used to be commit 237a8e5fe62d757c04b8207cbbee4df1470cfe4e) --- source3/nmbd/dummy.in | 1 - 1 file changed, 1 deletion(-) delete mode 100644 source3/nmbd/dummy.in (limited to 'source3/nmbd') diff --git a/source3/nmbd/dummy.in b/source3/nmbd/dummy.in deleted file mode 100644 index 8b13789179..0000000000 --- a/source3/nmbd/dummy.in +++ /dev/null @@ -1 +0,0 @@ - -- cgit From cf3a9741dc7427efb97eff09a3c197a906ce6767 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 28 Sep 1998 21:43:48 +0000 Subject: Changes to test in configure if capabilities are enabled on a system. Changes to get Samba to compile cleanly with the IRIX compiler with the options : -fullwarn -woff 1209,1174 (the -woff options are to turn off warnings about unused function parameters and controlling loop expressions being constants). Split prototype generation as we hit a limit in IRIX nawk. Removed "." code in smbd/filename.c (yet again :-). Jeremy. (This used to be commit e0567433bd72aec17bf5a54cc292701095d25f09) --- source3/nmbd/nmbd_become_lmb.c | 9 +++------ source3/nmbd/nmbd_incomingdgrams.c | 7 ++----- source3/nmbd/nmbd_packets.c | 2 +- source3/nmbd/nmbd_processlogon.c | 15 +-------------- source3/nmbd/nmbd_serverlistdb.c | 3 +-- source3/nmbd/nmbd_winsserver.c | 14 +------------- 6 files changed, 9 insertions(+), 41 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index 1e4f070271..80609cf504 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -280,7 +280,6 @@ static void release_msbrowse_name_fail( struct subnet_record *subrec, void unbecome_local_master_browser(struct subnet_record *subrec, struct work_record *work, BOOL force_new_election) { - struct server_record *servrec; struct name_record *namerec; struct nmb_name nmbname; @@ -289,7 +288,7 @@ void unbecome_local_master_browser(struct subnet_record *subrec, struct work_rec DEBUG(2,("unbecome_local_master_browser: unbecoming local master for workgroup %s \ on subnet %s\n",work->work_group, subrec->subnet_name)); - if((servrec = find_server_in_workgroup( work, global_myname)) == NULL) + if(find_server_in_workgroup( work, global_myname) == NULL) { DEBUG(0,("unbecome_local_master_browser: Error - cannot find server %s \ in workgroup %s on subnet %s\n", @@ -489,7 +488,6 @@ static void become_local_master_fail1(struct subnet_record *subrec, { char *work_name = rrec->userdata->data; struct work_record *work = find_workgroup_on_subnet(subrec, work_name); - struct server_record *servrec; if(!work) { @@ -498,7 +496,7 @@ workgroup %s on subnet %s\n", work_name, subrec->subnet_name)); return; } - if((servrec = find_server_in_workgroup(work, global_myname)) == NULL) + if(find_server_in_workgroup(work, global_myname) == NULL) { DEBUG(0,("become_local_master_fail1: Error - cannot find server %s \ in workgroup %s on subnet %s\n", @@ -524,7 +522,6 @@ workgroup %s on subnet %s. Couldn't register name %s.\n", void become_local_master_browser(struct subnet_record *subrec, struct work_record *work) { - struct server_record *servrec; struct userdata_struct *userdata; int size = sizeof(struct userdata_struct) + sizeof(fstring) + 1; @@ -542,7 +539,7 @@ void become_local_master_browser(struct subnet_record *subrec, struct work_recor return; } - if((servrec = find_server_in_workgroup( work, global_myname)) == NULL) + if(find_server_in_workgroup( work, global_myname) == NULL) { DEBUG(0,("become_local_master_browser: Error - cannot find server %s \ in workgroup %s on subnet %s\n", diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 36242d9ac2..e6c4ab2771 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -544,7 +544,7 @@ static void send_backup_list_response(struct subnet_record *subrec, int port) { char outbuf[1024]; - char *p, *countptr, *nameptr; + char *p, *countptr; unsigned int count = 0; int len; struct server_record *servrec; @@ -565,8 +565,6 @@ static void send_backup_list_response(struct subnet_record *subrec, SIVAL(p,0,token); /* The sender's unique info. */ p += 4; - nameptr = p; - /* We always return at least one name - our own. */ count = 1; StrnCpy(p,global_myname,15); @@ -793,7 +791,6 @@ void process_announce_request(struct subnet_record *subrec, struct packet_struct void process_lm_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf) { struct dgram_packet *dgram = &p->packet.dgram; - struct work_record *work; char *workgroup_name = dgram->dest_name.name; DEBUG(3,("process_lm_announce_request: Announce request from %s IP %s to %s.\n", @@ -808,7 +805,7 @@ void process_lm_announce_request(struct subnet_record *subrec, struct packet_str return; } - if((work = find_workgroup_on_subnet(subrec, workgroup_name)) == NULL) + if(find_workgroup_on_subnet(subrec, workgroup_name) == NULL) { DEBUG(0,("process_announce_request: Unable to find workgroup %s on subnet !\n", workgroup_name)); diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 10ce2da0c1..a515ea548e 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -138,7 +138,7 @@ static uint16 generate_name_trn_id(void) if (!name_trn_id) { - name_trn_id = (time(NULL)%(unsigned)0x7FFF) + (getpid()%(unsigned)100); + name_trn_id = ((unsigned)time(NULL)%(unsigned)0x7FFF) + ((unsigned)getpid()%(unsigned)100); } name_trn_id = (name_trn_id+1) % (unsigned)0x7FFF; return name_trn_id; diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 29dc68fb80..68a0ff4000 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -41,20 +41,14 @@ void process_logon_packet(struct packet_struct *p,char *buf,int len, struct dgram_packet *dgram = &p->packet.dgram; pstring my_name; fstring reply_name; - BOOL add_slashes = False; pstring outbuf; - int code,reply_code; - char unknown_byte = 0; - uint16 request_count = 0; + int code; uint16 token = 0; uint32 ntversion; uint16 lmnttoken; uint16 lm20token; - uint32 allowableaccount; /* Control bits, i.e. 0x80 == workstation trust a/c. */ uint32 domainsidsize; - uint16 requestcount; - char *domainsid; char *getdc; char *uniuser; /* Unicode user name. */ pstring ascuser; @@ -84,13 +78,9 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); getdc = skip_string(user,1); q = skip_string(getdc,1); - unknown_byte = CVAL(q,0); - request_count = SVAL(q,1); token = SVAL(q,3); - reply_code = 0x6; fstrcpy(reply_name,my_name); - add_slashes = True; DEBUG(3,("process_logon_packet: Domain login request from %s at IP %s user=%s token=%x\n", machine,inet_ntoa(p->ip),user,token)); @@ -175,14 +165,11 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", { char *q = buf + 2; - requestcount = SVAL(q, 0); q += 2; unicomp = q; uniuser = skip_unicode_string(unicomp,1); getdc = skip_unicode_string(uniuser,1); q = skip_string(getdc,1); - allowableaccount = IVAL(q, 0); q += 4; domainsidsize = IVAL(q, 0); q += 4; - domainsid = q; q += domainsidsize + 3; ntversion = IVAL(q, 0); q += 4; lmnttoken = SVAL(q, 0); q += 2; diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index 458fbd0085..cf7295ee11 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -230,14 +230,13 @@ static uint32 write_this_server_name( struct subnet_record *subrec, { struct subnet_record *ssub; struct work_record *iwork; - struct server_record *sserv; /* Go through all the subnets we have already seen. */ for (ssub = FIRST_SUBNET; ssub != subrec; ssub = NEXT_SUBNET_INCLUDING_UNICAST(ssub)) { for(iwork = ssub->workgrouplist; iwork; iwork = iwork->next) { - if((sserv = find_server_in_workgroup( iwork, servrec->serv.name)) != NULL) + if(find_server_in_workgroup( iwork, servrec->serv.name) != NULL) { /* * We have already written out this server record, don't diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index cba3c1b308..80825579c4 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -173,7 +173,6 @@ BOOL initialise_wins(void) int type = 0; int nb_flags; int ttl; - enum name_source source; char *ptr; char *p; BOOL got_token; @@ -266,8 +265,6 @@ BOOL initialise_wins(void) { next_token(&ptr, ip_str, NULL, sizeof(ip_str)); ip_list[i] = *interpret_addr2(ip_str); - if (ip_equal(ip_list[i], ipzero)) - source = SELF_NAME; } next_token(&ptr,nb_flags_str,NULL, sizeof(nb_flags_str)); @@ -538,18 +535,10 @@ static void wins_register_query_fail(struct subnet_record *subrec, { struct userdata_struct *userdata = rrec->userdata; struct packet_struct *orig_reg_packet; - struct nmb_packet *nmb; struct name_record *namerec = NULL; - uint16 nb_flags; - BOOL group; memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *)); - nmb = &orig_reg_packet->packet.nmb; - - nb_flags = get_nb_flags(nmb->additional->rdata); - group = (nb_flags & NB_GROUP) ? True : False; - /* * We want to just add the name, as we now know the original owner * didn't want it. But we can't just do that as an arbitary @@ -1547,7 +1536,6 @@ void wins_write_database(BOOL background) { struct name_record *namerec; pstring fname, fnamenew; - static int child_pid; FILE *fp; @@ -1558,7 +1546,7 @@ void wins_write_database(BOOL background) doesn't block while this is done */ if (background) { CatchChild(); - if ((child_pid=fork())) { + if (fork()) { return; } } -- cgit From a2d7f765e8500f23c126c7b7cb6bb346adc11641 Mon Sep 17 00:00:00 2001 From: Alexandre Oliva Date: Tue, 29 Sep 1998 04:52:17 +0000 Subject: get away with dummy and .dummy files (This used to be commit 90a8a02484a0897b053fd6531b7fec5d23098b6f) --- source3/nmbd/.cvsignore | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/.cvsignore b/source3/nmbd/.cvsignore index 421376db9e..e69de29bb2 100644 --- a/source3/nmbd/.cvsignore +++ b/source3/nmbd/.cvsignore @@ -1 +0,0 @@ -dummy -- cgit From da0c1ef08e007092f107d8f65fe63e5cf76c9ed7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 29 Sep 1998 17:16:15 +0000 Subject: Fixed bug introduced by me in dead code elimination. Bug was caused by multiple C statements on a line. IMHO this is a *BUG* and will be treated as such.... Fixed all such multiple statements in this file. Jeremy. (This used to be commit ea3ab46f12565ac6ccbb8c69825acedd3640ec12) --- source3/nmbd/nmbd_processlogon.c | 66 ++++++++++++++++++++++++++-------------- 1 file changed, 44 insertions(+), 22 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 68a0ff4000..ae2e824727 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -86,13 +86,15 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); machine,inet_ntoa(p->ip),user,token)); q = outbuf; - SSVAL(q, 0, 6); q += 2; + SSVAL(q, 0, 6); + q += 2; fstrcpy(reply_name, "\\\\"); fstrcat(reply_name, my_name); fstrcpy(q, reply_name); q = skip_string(q, 1); /* PDC name */ - SSVAL(q, 0, token); q += 2; + SSVAL(q, 0, token); + q += 2; dump_data(4, outbuf, PTR_DIFF(q, outbuf)); @@ -118,17 +120,22 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); q = skip_unicode_string(q, 1); - ntversion = IVAL(q, 0); q += 4; - lmnttoken = SVAL(q, 0); q += 2; - lm20token = SVAL(q, 0); q += 2; + ntversion = IVAL(q, 0); + q += 4; + lmnttoken = SVAL(q, 0); + q += 2; + lm20token = SVAL(q, 0); + q += 2; /* Construct reply. */ q = outbuf; - SSVAL(q, 0, QUERYFORPDC_R); q += 2; + SSVAL(q, 0, QUERYFORPDC_R); + q += 2; fstrcpy(reply_name,my_name); - fstrcpy(q, reply_name); q = skip_string(q, 1); /* PDC name */ + fstrcpy(q, reply_name); + q = skip_string(q, 1); /* PDC name */ if (strcmp(mailslot, NT_LOGON_MAILSLOT)==0) { q = align2(q, buf); @@ -138,9 +145,12 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); PutUniCode(q, global_myworkgroup); /* Domain name*/ q = skip_unicode_string(q, 1); - SIVAL(q, 0, ntversion); q += 4; - SSVAL(q, 0, lmnttoken); q += 2; - SSVAL(q, 0, lm20token); q += 2; + SIVAL(q, 0, ntversion); + q += 4; + SSVAL(q, 0, lmnttoken); + q += 2; + SSVAL(q, 0, lm20token); + q += 2; } DEBUG(3,("process_logon_packet: GETDC request from %s at IP %s, \ @@ -169,11 +179,16 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", uniuser = skip_unicode_string(unicomp,1); getdc = skip_unicode_string(uniuser,1); q = skip_string(getdc,1); - domainsidsize = IVAL(q, 0); q += 4; + q += 4; + domainsidsize = IVAL(q, 0); + q += 4; q += domainsidsize + 3; - ntversion = IVAL(q, 0); q += 4; - lmnttoken = SVAL(q, 0); q += 2; - lm20token = SVAL(q, 0); q += 2; + ntversion = IVAL(q, 0); + q += 4; + lmnttoken = SVAL(q, 0); + q += 2; + lm20token = SVAL(q, 0); + q += 2; DEBUG(3,("process_logon_packet: SAMLOGON sidsize %d ntv %d\n", domainsidsize, ntversion)); @@ -212,15 +227,22 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", /* Construct reply. */ q = outbuf; - SSVAL(q, 0, SAMLOGON_R); q += 2; - - PutUniCode(q, reply_name); q = skip_unicode_string(q, 1); - unistrcpy(q, uniuser); q = skip_unicode_string(q, 1); /* User name (workstation trust account) */ - PutUniCode(q, lp_workgroup()); q = skip_unicode_string(q, 1); /* Domain name. */ + SSVAL(q, 0, SAMLOGON_R); + q += 2; - SIVAL(q, 0, ntversion); q += 4; - SSVAL(q, 0, lmnttoken); q += 2; - SSVAL(q, 0, lm20token); q += 2; + PutUniCode(q, reply_name); + q = skip_unicode_string(q, 1); + unistrcpy(q, uniuser); + q = skip_unicode_string(q, 1); /* User name (workstation trust account) */ + PutUniCode(q, lp_workgroup()); + q = skip_unicode_string(q, 1); /* Domain name. */ + + SIVAL(q, 0, ntversion); + q += 4; + SSVAL(q, 0, lmnttoken); + q += 2; + SSVAL(q, 0, lm20token); + q += 2; dump_data(4, outbuf, PTR_DIFF(q, outbuf)); -- cgit From 0ccf4104a1b502eff799566ea0bd9e8b00b30b19 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 29 Sep 1998 17:17:48 +0000 Subject: Missed one removed multi-statement line. Grrr. Jeremy. (This used to be commit 7958787d9beffcd0f025c7a85469844d2e520ce5) --- source3/nmbd/nmbd_processlogon.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index ae2e824727..89b7e0e647 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -175,6 +175,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", { char *q = buf + 2; + q += 2; unicomp = q; uniuser = skip_unicode_string(unicomp,1); getdc = skip_unicode_string(uniuser,1); -- cgit From f36d5c8bbfe4cfcbabb45d7004ed463f90c34f65 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 5 Oct 1998 03:53:25 +0000 Subject: get type of callback right (This used to be commit 327eba774e5bb17a91f80617bd7359afe0c83f48) --- source3/nmbd/nmbd_synclists.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index b6f54dccec..8dee5ca4f2 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -51,7 +51,7 @@ static FILE *fp; /******************************************************************* This is the NetServerEnum callback. ******************************************************************/ -static void callback(char *sname, uint32 stype, char *comment) +static void callback(const char *sname, uint32 stype, const char *comment) { fprintf(fp,"\"%s\" %08X \"%s\"\n", sname, stype, comment); } -- cgit From 9307940876a6c226969e9169d55c0408cd7ab032 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 21 Oct 1998 01:35:01 +0000 Subject: fixing smbd encrypted rpcs (data lens, alloc hints, sequence nums argh). put unicode strings after SAMLOGON query regardless of whether it's an NT mailslot or a non-NT mailslot, after having observed this behaviour out of NT machines. (This used to be commit c101113ec20ed0ba633e78e4ee45596cdccaf1b5) --- source3/nmbd/nmbd_processlogon.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 89b7e0e647..5495697c8f 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -55,6 +55,8 @@ void process_logon_packet(struct packet_struct *p,char *buf,int len, char *unicomp; /* Unicode computer name. */ struct smb_passwd *smb_pass; /* To check if machine account exists */ + memset(outbuf, 0, sizeof(outbuf)); + if (!lp_domain_logons()) { DEBUG(3,("process_logon_packet: Logon packet received from IP %s and domain \ @@ -137,7 +139,9 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); fstrcpy(q, reply_name); q = skip_string(q, 1); /* PDC name */ +#if 0 if (strcmp(mailslot, NT_LOGON_MAILSLOT)==0) { +#endif q = align2(q, buf); PutUniCode(q, my_name); /* PDC name */ @@ -151,7 +155,9 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); q += 2; SSVAL(q, 0, lm20token); q += 2; +#if 0 } +#endif DEBUG(3,("process_logon_packet: GETDC request from %s at IP %s, \ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", -- cgit From 88a0a8c088adc0a8750865f78573ba1c59813101 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Wed, 21 Oct 1998 17:26:54 +0000 Subject: Changed the debug calls to use the newer debug macros. This allowed me to break up some very long lines in both the code and the output. The change is mostly cosmetic, but should improve log file readability. (This used to be commit fc4e0148ebf8ea45e4410224218c0c987965d36c) --- source3/nmbd/nmbd_browsesync.c | 210 +++++++++++++++++++++++++++++------------ 1 file changed, 151 insertions(+), 59 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index da514076e6..4d8b76daa7 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -41,11 +41,16 @@ static void sync_with_lmb(struct browse_cache_record *browc) { struct work_record *work; - if (!(work = find_workgroup_on_subnet(unicast_subnet, browc->work_group))) { - DEBUG(0, ("sync_with_lmb: failed to get a \ -workgroup for a local master browser cache entry workgroup %s, server %s\n", - browc->work_group, browc->lmb_name)); - return; + if( !(work = find_workgroup_on_subnet(unicast_subnet, browc->work_group)) ) + { + if( DEBUGLVL( 0 ) ) + { + dbgtext( "sync_with_lmb:\n" ); + dbgtext( "Failed to get a workgroup for a local master browser " ); + dbgtext( "cache entry workgroup " ); + dbgtext( "%s, server %s\n", browc->work_group, browc->lmb_name ); + } + return; } /* We should only be doing this if we are a domain master browser for @@ -53,14 +58,24 @@ workgroup for a local master browser cache entry workgroup %s, server %s\n", if(!AM_DOMAIN_MASTER_BROWSER(work)) { - DEBUG(0,("sync_with_lmb: We are trying to sync with a local master browser %s \ -for workgroup %s and we are not a domain master browser on this workgroup. Error !\n", - browc->lmb_name, browc->work_group)); + if( DEBUGLVL( 0 ) ) + { + dbgtext( "sync_with_lmb:\n" ); + dbgtext( "We are trying to sync with a local master browser " ); + dbgtext( "%s for workgroup %s\n", browc->lmb_name, browc->work_group ); + dbgtext( "and we are not a domain master browser on this workgroup.\n" ); + dbgtext( "Error!\n" ); + } return; } - DEBUG(2, ("sync_with_lmb: Initiating sync with local master browser %s<0x20> at IP %s for \ -workgroup %s\n", browc->lmb_name, inet_ntoa(browc->ip), browc->work_group)); + if( DEBUGLVL( 2 ) ) + { + dbgtext( "sync_with_lmb:\n" ); + dbgtext( "Initiating sync with local master browser " ); + dbgtext( "%s<0x20> at IP %s ", browc->lmb_name, inet_ntoa(browc->ip) ); + dbgtext( "for workgroup %s\n", browc->work_group ); + } sync_browse_lists(work, browc->lmb_name, 0x20, browc->ip, True, True); @@ -103,9 +118,13 @@ static void announce_local_master_browser_to_domain_master_browser( struct work_ if(ismyip(work->dmb_addr)) { - DEBUG(2,("announce_local_master_browser_to_domain_master_browser: We are both a domain \ -and a local master browser for workgroup %s. \ -Do not announce to ourselves.\n", work->work_group )); + if( DEBUGLVL( 2 ) ) + { + dbgtext( "announce_local_master_browser_to_domain_master_browser:\n" ); + dbgtext( "We are both a domain and a local master browser for " ); + dbgtext( "workgroup %s. ", work->work_group ); + dbgtext( "Do not announce to ourselves.\n" ); + } return; } @@ -118,8 +137,13 @@ Do not announce to ourselves.\n", work->work_group )); strupper(p); p = skip_string(p,1); - DEBUG(4,("announce_local_master_browser_to_domain_master_browser: Sending local master announce \ -to %s for workgroup %s.\n", namestr(&work->dmb_name), work->work_group )); + if( DEBUGLVL( 4 ) ) + { + dbgtext( "announce_local_master_browser_to_domain_master_browser:\n" ); + dbgtext( "Sending local master announce to " ); + dbgtext( "%s for workgroup %s.\n", namestr(&work->dmb_name), + work->work_group ); + } send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), global_myname, 0x0, work->dmb_name.name, 0x0, @@ -133,8 +157,14 @@ As a local master browser, do a sync with a domain master browser. static void sync_with_dmb(struct work_record *work) { - DEBUG(2, ("sync_with_dmb: Initiating sync with domain master browser %s at IP %s for \ -workgroup %s\n", namestr(&work->dmb_name), inet_ntoa(work->dmb_addr), work->work_group)); + if( DEBUGLVL( 2 ) ) + { + dbgtext( "sync_with_dmb:\n" ); + dbgtext( "Initiating sync with domain master browser " ); + dbgtext( "%s ", namestr(&work->dmb_name) ); + dbgtext( "at IP %s ", inet_ntoa(work->dmb_addr) ); + dbgtext( "for workgroup %s\n", work->work_group ); + } sync_browse_lists(work, work->dmb_name.name, work->dmb_name.name_type, work->dmb_addr, False, True); @@ -151,15 +181,23 @@ static void domain_master_node_status_success(struct subnet_record *subrec, { struct work_record *work = find_workgroup_on_subnet( subrec, userdata->data); - if(work == NULL) + if( work == NULL ) { - DEBUG(0,("domain_master_node_status_success: Unable to find workgroup %s on subnet %s.\n", - userdata->data, subrec->subnet_name)); + if( DEBUGLVL( 0 ) ) + { + dbgtext( "domain_master_node_status_success:\n" ); + dbgtext( "Unable to find workgroup " ); + dbgtext( "%s on subnet %s.\n", userdata->data, subrec->subnet_name ); + } return; } - DEBUG(3,("domain_master_node_status_success: Success in node status for workgroup %s from ip %s\n", - work->work_group, inet_ntoa(from_ip) )); + if( DEBUGLVL( 3 ) ) + { + dbgtext( "domain_master_node_status_success:\n" ); + dbgtext( "Success in node status for workgroup " ); + dbgtext( "%s from ip %s\n", work->work_group, inet_ntoa(from_ip) ); + } /* Go through the list of names found at answers->rdata and look for the first SERVER<0x20> name. */ @@ -207,8 +245,12 @@ static void domain_master_node_status_success(struct subnet_record *subrec, } } else - DEBUG(0,("domain_master_node_status_success: Failed to find a SERVER<0x20> \ -name in reply from IP %s.\n", inet_ntoa(from_ip) )); + if( DEBUGLVL( 0 ) ) + { + dbgtext( "domain_master_node_status_success:\n" ); + dbgtext( "Failed to find a SERVER<0x20> name in reply from IP " ); + dbgtext( "%s.\n", inet_ntoa(from_ip) ); + } } /**************************************************************************** @@ -220,10 +262,14 @@ static void domain_master_node_status_fail(struct subnet_record *subrec, { struct userdata_struct *userdata = rrec->userdata; - DEBUG(0,("domain_master_node_status_fail: Doing a node status request to \ -the domain master browser for workgroup %s at IP %s failed. Cannot sync browser \ -lists.\n", userdata->data, inet_ntoa(rrec->packet->ip) )); - + if( DEBUGLVL( 0 ) ) + { + dbgtext( "domain_master_node_status_fail:\n" ); + dbgtext( "Doing a node status request to the domain master browser\n" ); + dbgtext( "for workgroup %s ", userdata->data ); + dbgtext( "at IP %s failed.\n", inet_ntoa(rrec->packet->ip) ); + dbgtext( "Cannot sync browser lists.\n" ); + } } /**************************************************************************** @@ -252,9 +298,13 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec, struct userdata_struct *userdata; int size = sizeof(struct userdata_struct) + sizeof(fstring)+1; - if (!(work = find_workgroup_on_subnet(subrec, q_name->name))) { - DEBUG(0, ("find_domain_master_name_query_success: failed to find \ -workgroup %s\n", q_name->name )); + if( !(work = find_workgroup_on_subnet(subrec, q_name->name)) ) + { + if( DEBUGLVL( 0 ) ) + { + dbgtext( "find_domain_master_name_query_success:\n" ); + dbgtext( "Failed to find workgroup %s\n", q_name->name ); + } return; } @@ -309,9 +359,14 @@ static void find_domain_master_name_query_fail(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *question_name, int fail_code) { - DEBUG(0,("find_domain_master_name_query_fail: Unable to find the Domain Master \ -Browser name %s for the workgroup %s. Unable to sync browse lists in this workgroup.\n", - namestr(question_name), question_name->name )); + if( DEBUGLVL( 0 ) ) + { + dbgtext( "find_domain_master_name_query_fail:\n" ); + dbgtext( "Unable to find the Domain Master Browser name " ); + dbgtext( "%s for the workgroup %s.\n", + namestr(question_name), question_name->name ); + dbgtext( "Unable to sync browse lists in this workgroup.\n" ); + } } /**************************************************************************** @@ -328,7 +383,11 @@ void announce_and_sync_with_domain_master_browser( struct subnet_record *subrec, /* Only do this if we are using a WINS server. */ if(we_are_a_wins_client() == False) { - DEBUG(10,("announce_and_sync_with_domain_master_browser: Ignoring as we are not a WINS client.\n")); + if( DEBUGLVL( 10 ) ) + { + dbgtext( "announce_and_sync_with_domain_master_browser:\n" ); + dbgtext( "Ignoring, as we are not a WINS client.\n" ); + } return; } @@ -364,8 +423,11 @@ static void get_domain_master_name_node_status_success(struct subnet_record *sub server_name[0] = 0; - DEBUG(3,("get_domain_master_name_node_status_success: Success in node status from ip %s\n", - inet_ntoa(from_ip) )); + if( DEBUGLVL( 3 ) ) + { + dbgtext( "get_domain_master_name_node_status_success:\n" ); + dbgtext( "Success in node status from ip %s\n", inet_ntoa(from_ip) ); + } /* * Go through the list of names found at answers->rdata and look for @@ -401,10 +463,13 @@ static void get_domain_master_name_node_status_success(struct subnet_record *sub if(!(nb_flags & NB_GROUP) && (name_type == 0x1b)) { - - DEBUG(5,("get_domain_master_name_node_status_success: %s(%s) is a domain \ -master browser for workgroup %s. Adding this name.\n", - server_name, inet_ntoa(from_ip), qname )); + if( DEBUGLVL( 5 ) ) + { + dbgtext( "get_domain_master_name_node_status_success:\n" ); + dbgtext( "%s(%s) ", server_name, inet_ntoa(from_ip) ); + dbgtext( "is a domain master browser for workgroup " ); + dbgtext( "%s. Adding this name.\n", qname ); + } /* * If we don't already know about this workgroup, add it @@ -430,8 +495,12 @@ master browser for workgroup %s. Adding this name.\n", } } else - DEBUG(0,("get_domain_master_name_node_status_success: Failed to find a WORKGROUP<0x1b> \ -name in reply from IP %s.\n", inet_ntoa(from_ip) )); + if( DEBUGLVL( 0 ) ) + { + dbgtext( "get_domain_master_name_node_status_success:\n" ); + dbgtext( "Failed to find a WORKGROUP<0x1b> name in reply from IP " ); + dbgtext( "%s.\n", inet_ntoa(from_ip) ); + } } /**************************************************************************** @@ -441,11 +510,15 @@ name in reply from IP %s.\n", inet_ntoa(from_ip) )); static void get_domain_master_name_node_status_fail(struct subnet_record *subrec, struct response_record *rrec) { - DEBUG(0,("get_domain_master_name_node_status_fail: Doing a node status request to \ -the domain master browser at IP %s failed. Cannot get workgroup name.\n", - inet_ntoa(rrec->packet->ip) )); - + if( DEBUGLVL( 0 ) ) + { + dbgtext( "get_domain_master_name_node_status_fail:\n" ); + dbgtext( "Doing a node status request to the domain master browser " ); + dbgtext( "at IP %s failed.\n", inet_ntoa(rrec->packet->ip) ); + dbgtext( "Cannot get workgroup name.\n" ); + } } + /**************************************************************************** Function called when a query for *<1b> name succeeds. ****************************************************************************/ @@ -466,8 +539,12 @@ static void find_all_domain_master_names_query_success(struct subnet_record *sub struct in_addr send_ip; int i; - DEBUG(5,("find_all_domain_master_names_query_succes: Got answer from WINS server of %d \ -IP addresses for Domain Master Browsers.\n", rrec->rdlength / 6 )); + if( DEBUGLVL( 5 ) ) + { + dbgtext( "find_all_domain_master_names_query_succes:\n" ); + dbgtext( "Got answer from WINS server of %d ", (rrec->rdlength / 6) ); + dbgtext( "IP addresses for Domain Master Browsers.\n" ); + } for(i = 0; i < rrec->rdlength / 6; i++) { @@ -483,13 +560,20 @@ IP addresses for Domain Master Browsers.\n", rrec->rdlength / 6 )); if(ismyip( send_ip )) { - DEBUG(5,("find_all_domain_master_names_query_succes: Not sending node status \ -to our own IP %s.\n", inet_ntoa(send_ip) )); + if( DEBUGLVL( 5 ) ) + { + dbgtext( "find_all_domain_master_names_query_succes:\n" ); + dbgtext( "Not sending node status to our own IP " ); + dbgtext( "%s.\n", inet_ntoa(send_ip) ); + } continue; } - DEBUG(5,("find_all_domain_master_names_query_succes: sending node status request to \ -IP %s.\n", inet_ntoa(send_ip) )); + if( DEBUGLVL( 5 ) ) + { + dbgtext( "find_all_domain_master_names_query_success:\n" ); + dbgtext( "Sending node status request to IP %s.\n", inet_ntoa(send_ip) ); + } node_status( subrec, &nmbname, send_ip, get_domain_master_name_node_status_success, @@ -505,9 +589,13 @@ static void find_all_domain_master_names_query_fail(struct subnet_record *subrec struct response_record *rrec, struct nmb_name *question_name, int fail_code) { - DEBUG(10,("find_domain_master_name_query_fail: WINS server did not reply to a query \ -for name %s. This means it is probably not a Samba 1.9.18 or above WINS server.\n", - namestr(question_name) )); + if( DEBUGLVL( 10 ) ) + { + dbgtext( "find_domain_master_name_query_fail:\n" ); + dbgtext( "WINS server did not reply to a query for name " ); + dbgtext( "%s.\nThis means it ", namestr(question_name) ); + dbgtext( "is probably not a Samba 1.9.18 or above WINS server.\n" ); + } } /**************************************************************************** @@ -531,8 +619,12 @@ void collect_all_workgroup_names_from_wins_server(time_t t) /* Check to see if we are a domain master browser on the unicast subnet. */ if((work = find_workgroup_on_subnet( unicast_subnet, global_myworkgroup)) == NULL) { - DEBUG(0,("collect_all_workgroup_names_from_wins_server: Cannot find my workgroup %s on subnet %s.\n", - global_myworkgroup, unicast_subnet->subnet_name )); + if( DEBUGLVL( 0 ) ) + { + dbgtext( "collect_all_workgroup_names_from_wins_server:\n" ); + dbgtext( "Cannot find my workgroup %s ", global_myworkgroup ); + dbgtext( "on subnet %s.\n", unicast_subnet->subnet_name ); + } return; } @@ -605,7 +697,7 @@ void sync_all_dmbs(time_t t) 0x20, scope); } - DEBUG(3,("initiating DMB<->DMB sync with %s(%s)\n", + DEBUG(3,("Initiating DMB<->DMB sync with %s(%s)\n", work->dmb_name.name, inet_ntoa(work->dmb_addr))); sync_browse_lists(work, -- cgit From 2356f467d129305246b4ba08e61a854f832a76ca Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Thu, 22 Oct 1998 00:30:41 +0000 Subject: Another cosmetic change. When dumping the wins.dat, this module will also write the database contents to the log file (don't do this if you have a large wins.dat!). The output was in a sort of tabular format, except that the asctime() function was used and it always terminates its output with a newline. I did a bit of fussing, removed the '\n' character, and did my best to line up the other columns. If the output format of asctime() is different on different systems, then the columns won't line up, but the output will still look better than it did before. Chris -)----- (This used to be commit 57295113feefcde77b429c661878444cd078b21f) --- source3/nmbd/nmbd_winsserver.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 80825579c4..5dc350152f 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1580,11 +1580,17 @@ void wins_write_database(BOOL background) if( namerec->data.death_time != PERMANENT_TTL ) { + char *ts, *nl; + tm = LocalTime(&namerec->data.death_time); - DEBUGADD(4,("TTL = %s", asctime(tm) )); + ts = asctime(tm); + nl = strrchr( ts, '\n' ); + if( NULL != nl ) + *nl = '\0'; + DEBUGADD(4,("TTL = %s ", ts )); } else - DEBUGADD(4,("TTL = PERMANENT\t")); + DEBUGADD(4,("TTL = PERMANENT ")); for (i = 0; i < namerec->data.num_ips; i++) DEBUGADD(4,("%15s ", inet_ntoa(namerec->data.ip[i]) )); -- cgit From 034a12fdcb6f707b382d9da481bc012a3c49da76 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Thu, 22 Oct 1998 18:07:39 +0000 Subject: Minor change. The debug_browse_data() function does a hex dump of a browser packet. The last line is often not a full 16 bytes, which would miss-align the hex output. I've added the padding needed to align the hex output. Chris -)----- (This used to be commit 9f9b30abab118f0a2e007beddd79de38a2d5ea29) --- source3/nmbd/nmbd_packets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index a515ea548e..b0ef96f694 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -114,7 +114,7 @@ static void debug_browse_data(char *outbuf, int len) DEBUGADD( 4, ( "%c", x ) ); } - DEBUGADD( 4, ( " hex ") ); + DEBUGADD( 4, ( "%*s hex ", 16-j, "" ) ); for (j = 0; j < 16; j++) { -- cgit From 6f6125364866d29edc90c58ce4b30a74b253fe37 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Thu, 22 Oct 1998 22:51:45 +0000 Subject: Okay, this is really silly but removing one space from one debug statement meant that one hex dump would fit within 80 characters in lynx after HTML conversion. (This used to be commit c391f076f29cff917fd51d58598e1ad11048e824) --- source3/nmbd/nmbd_packets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index b0ef96f694..d7049a270f 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -114,7 +114,7 @@ static void debug_browse_data(char *outbuf, int len) DEBUGADD( 4, ( "%c", x ) ); } - DEBUGADD( 4, ( "%*s hex ", 16-j, "" ) ); + DEBUGADD( 4, ( "%*s hex", 16-j, "" ) ); for (j = 0; j < 16; j++) { -- cgit From 04f2858fd7f2123f12bfdb4ba695dc56ef7df0c7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 31 Oct 1998 07:38:50 +0000 Subject: took out Lukes change as it breaks domain logons for Win95 clients (ie. it breaks Sues machine). Luke, your comment was: put unicode strings after SAMLOGON query regardless of whether it's an NT mailslot or a non-NT mailslot, after having observed this behaviour out of NT machines. perhaps you could post the relevant tcpdump or netmon capture so we can see what is going on? I suspect that what you saw isn't exactly what the win95 boxes are generating. Maybe you saw a GETDCxxx instead of a GETDC000 ? Maybe we need a switch based on the GETDC request type? We won't know unless we see sniffs. (This used to be commit a2bacc08955ba61aac4b45b63a54b279e5776261) --- source3/nmbd/nmbd_processlogon.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 5495697c8f..3f519ecfc9 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -139,9 +139,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); fstrcpy(q, reply_name); q = skip_string(q, 1); /* PDC name */ -#if 0 if (strcmp(mailslot, NT_LOGON_MAILSLOT)==0) { -#endif q = align2(q, buf); PutUniCode(q, my_name); /* PDC name */ @@ -155,9 +153,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); q += 2; SSVAL(q, 0, lm20token); q += 2; -#if 0 } -#endif DEBUG(3,("process_logon_packet: GETDC request from %s at IP %s, \ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", -- cgit From 502e2ec3cf3dc1e0d64771f52b7bc7ff54050526 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Mon, 2 Nov 1998 16:20:25 +0000 Subject: removed comment line at end of file (This used to be commit 5e2fc8b7ccf4a9c8b0a2acf4bd752531ac6fa775) --- source3/nmbd/nmbd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index bdafdd44fc..92c43f410e 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -567,7 +567,10 @@ static void usage(char *pname) charset_initialise(); - if(!initialize_password_db()) + if(!initialise_group_db()) + exit(1); + + if(!initialise_password_db()) exit(1); #ifdef LMHOSTSFILE @@ -768,4 +771,3 @@ static void usage(char *pname) return(0); } /* main */ -/* ========================================================================== */ -- cgit From c082539152eefb90a752277b3917403f613c3a3a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 2 Nov 1998 18:12:28 +0000 Subject: client/client.c: Patch to tidy up file size output. nmbd/nmbd.c: Someone (a "yank" no doubt :-) Changed instances of "initialise" to "initialize". Someone get that man an *English* dictionary.... :-) :-). Jeremy. (This used to be commit 6279be7f96802bb132e5e18dd8c6912652296e70) --- source3/nmbd/nmbd.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 92c43f410e..d7ce42dae2 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -567,10 +567,7 @@ static void usage(char *pname) charset_initialise(); - if(!initialise_group_db()) - exit(1); - - if(!initialise_password_db()) + if(!initialize_password_db()) exit(1); #ifdef LMHOSTSFILE -- cgit From 24ca89bfb03fb82e975eff94070275ee403cd0f9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 14 Nov 1998 01:04:13 +0000 Subject: Removed acconfig.h configure configure.in include/config.h.in: Made smbwrapper not made by default. nmbd*: Changed all calls to namestr() to nmbd_namestr() to fix broken FreeBSD include file problem...sigh. Jeremy. (This used to be commit 9ee8f39aed8772a05c203161b4ae6b7d90d67481) --- source3/nmbd/asyncdns.c | 4 +-- source3/nmbd/nmbd_become_dmb.c | 8 ++--- source3/nmbd/nmbd_become_lmb.c | 12 +++---- source3/nmbd/nmbd_browsesync.c | 8 ++--- source3/nmbd/nmbd_elections.c | 4 +-- source3/nmbd/nmbd_incomingdgrams.c | 26 +++++++------- source3/nmbd/nmbd_incomingrequests.c | 28 +++++++-------- source3/nmbd/nmbd_logonnames.c | 2 +- source3/nmbd/nmbd_mynames.c | 2 +- source3/nmbd/nmbd_namelistdb.c | 20 +++++------ source3/nmbd/nmbd_namequery.c | 16 ++++----- source3/nmbd/nmbd_nameregister.c | 20 +++++------ source3/nmbd/nmbd_namerelease.c | 16 ++++----- source3/nmbd/nmbd_nodestatus.c | 8 ++--- source3/nmbd/nmbd_packets.c | 46 ++++++++++++------------ source3/nmbd/nmbd_subnetdb.c | 2 +- source3/nmbd/nmbd_winsproxy.c | 6 ++-- source3/nmbd/nmbd_winsserver.c | 70 ++++++++++++++++++------------------ source3/nmbd/nmbd_workgroupdb.c | 2 +- 19 files changed, 150 insertions(+), 150 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 3054ad7353..67e55ebd50 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -305,7 +305,7 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, dns_queue = p; } - DEBUG(3,("added DNS query for %s\n", namestr(question))); + DEBUG(3,("added DNS query for %s\n", nmb_namestr(question))); return True; } @@ -321,7 +321,7 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, char *qname = question->name; struct in_addr dns_ip; - DEBUG(3,("DNS search for %s - ", namestr(question))); + DEBUG(3,("DNS search for %s - ", nmb_namestr(question))); /* Unblock TERM signal so we can be killed in DNS lookup. */ BlockSignals(False, SIGTERM); diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index cfaec3378d..cbef1db4b7 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -74,7 +74,7 @@ in workgroup %s on subnet %s\n", DEBUG(0,("become_domain_master_fail: Failed to become a domain master browser for \ workgroup %s on subnet %s. Couldn't register name %s.\n", - work->work_group, subrec->subnet_name, namestr(fail_name))); + work->work_group, subrec->subnet_name, nmb_namestr(fail_name))); } /**************************************************************************** @@ -213,7 +213,7 @@ static void become_domain_master_query_success(struct subnet_record *subrec, { dbgtext( "become_domain_master_query_success():\n" ); dbgtext( "Our address (%s) ", inet_ntoa(ip) ); - dbgtext( "returned in query for name %s ", namestr(nmbname) ); + dbgtext( "returned in query for name %s ", nmb_namestr(nmbname) ); dbgtext( "(domain master browser name) " ); dbgtext( "on subnet %s.\n", subrec->subnet_name ); dbgtext( "Continuing with domain master code.\n" ); @@ -249,7 +249,7 @@ static void become_domain_master_query_fail(struct subnet_record *subrec, { DEBUG(0,("become_domain_master_query_fail: Error %d returned when \ querying WINS server for name %s.\n", - fail_code, namestr(question_name))); + fail_code, nmb_namestr(question_name))); return; } @@ -344,7 +344,7 @@ static void become_domain_master_browser_wins(char *workgroup_name) DEBUG(0,("become_domain_master_browser_wins: querying WINS server at IP %s \ for domain master browser name %s on workgroup %s\n", - inet_ntoa(unicast_subnet->myip), namestr(&nmbname), workgroup_name)); + inet_ntoa(unicast_subnet->myip), nmb_namestr(&nmbname), workgroup_name)); query_name(unicast_subnet, nmbname.name, nmbname.name_type, become_domain_master_query_success, diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index 80609cf504..f3fa69132e 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -148,7 +148,7 @@ static void unbecome_local_master_success(struct subnet_record *subrec, memcpy((char *)&force_new_election, userdata->data, sizeof(BOOL)); DEBUG(3,("unbecome_local_master_success: released name %s.\n", - namestr(released_name))); + nmb_namestr(released_name))); /* Now reset the workgroup and server state. */ reset_workgroup_state( subrec, released_name->name, force_new_election ); @@ -178,7 +178,7 @@ static void unbecome_local_master_fail(struct subnet_record *subrec, struct resp memcpy((char *)&force_new_election, userdata->data, sizeof(BOOL)); DEBUG(0,("unbecome_local_master_fail: failed to release name %s. \ -Removing from namelist anyway.\n", namestr(fail_name))); +Removing from namelist anyway.\n", nmb_namestr(fail_name))); /* Do it anyway. */ namerec = find_name_on_subnet(subrec, fail_name, FIND_SELF_NAME); @@ -244,7 +244,7 @@ static void release_msbrowse_name_success(struct subnet_record *subrec, struct in_addr released_ip) { DEBUG(4,("release_msbrowse_name_success: Released name %s on subnet %s\n.", - namestr(released_name), subrec->subnet_name )); + nmb_namestr(released_name), subrec->subnet_name )); /* Remove the permanent MSBROWSE name added into the unicast subnet. */ remove_permanent_name_from_unicast( subrec, released_name); @@ -261,7 +261,7 @@ static void release_msbrowse_name_fail( struct subnet_record *subrec, struct name_record *namerec; DEBUG(4,("release_msbrowse_name_fail: Failed to release name %s on subnet %s\n.", - namestr(fail_name), subrec->subnet_name )); + nmb_namestr(fail_name), subrec->subnet_name )); /* Release the name anyway. */ namerec = find_name_on_subnet(subrec, fail_name, FIND_SELF_NAME); @@ -424,7 +424,7 @@ static void become_local_master_fail2(struct subnet_record *subrec, struct work_record *work = find_workgroup_on_subnet( subrec, fail_name->name); DEBUG(0,("become_local_master_fail2: failed to register name %s on subnet %s. \ -Failed to become a local master browser.\n", namestr(fail_name), subrec->subnet_name)); +Failed to become a local master browser.\n", nmb_namestr(fail_name), subrec->subnet_name)); if(!work) { @@ -508,7 +508,7 @@ in workgroup %s on subnet %s\n", DEBUG(0,("become_local_master_fail1: Failed to become a local master browser for \ workgroup %s on subnet %s. Couldn't register name %s.\n", - work->work_group, subrec->subnet_name, namestr(fail_name))); + work->work_group, subrec->subnet_name, nmb_namestr(fail_name))); } /****************************************************************** diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 4d8b76daa7..eafcc79c0a 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -141,7 +141,7 @@ static void announce_local_master_browser_to_domain_master_browser( struct work_ { dbgtext( "announce_local_master_browser_to_domain_master_browser:\n" ); dbgtext( "Sending local master announce to " ); - dbgtext( "%s for workgroup %s.\n", namestr(&work->dmb_name), + dbgtext( "%s for workgroup %s.\n", nmb_namestr(&work->dmb_name), work->work_group ); } @@ -161,7 +161,7 @@ static void sync_with_dmb(struct work_record *work) { dbgtext( "sync_with_dmb:\n" ); dbgtext( "Initiating sync with domain master browser " ); - dbgtext( "%s ", namestr(&work->dmb_name) ); + dbgtext( "%s ", nmb_namestr(&work->dmb_name) ); dbgtext( "at IP %s ", inet_ntoa(work->dmb_addr) ); dbgtext( "for workgroup %s\n", work->work_group ); } @@ -364,7 +364,7 @@ static void find_domain_master_name_query_fail(struct subnet_record *subrec, dbgtext( "find_domain_master_name_query_fail:\n" ); dbgtext( "Unable to find the Domain Master Browser name " ); dbgtext( "%s for the workgroup %s.\n", - namestr(question_name), question_name->name ); + nmb_namestr(question_name), question_name->name ); dbgtext( "Unable to sync browse lists in this workgroup.\n" ); } } @@ -593,7 +593,7 @@ static void find_all_domain_master_names_query_fail(struct subnet_record *subrec { dbgtext( "find_domain_master_name_query_fail:\n" ); dbgtext( "WINS server did not reply to a query for name " ); - dbgtext( "%s.\nThis means it ", namestr(question_name) ); + dbgtext( "%s.\nThis means it ", nmb_namestr(question_name) ); dbgtext( "is probably not a Samba 1.9.18 or above WINS server.\n" ); } } diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index cd310639e9..915528b31a 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -197,7 +197,7 @@ void run_elections(time_t t) make_nmb_name(&nmbname, work->work_group, 0x1e, scope); if(find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME)==NULL) { DEBUG(8,("run_elections: Cannot send election packet yet as name %s not \ -yet registered on subnet %s\n", namestr(&nmbname), subrec->subnet_name )); +yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name )); continue; } @@ -368,7 +368,7 @@ BOOL check_elections(void) make_nmb_name(&nmbname, work->work_group, 0x1e, scope); if(find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME)==NULL) { DEBUG(8,("check_elections: Cannot send election packet yet as name %s not \ -yet registered on subnet %s\n", namestr(&nmbname), subrec->subnet_name )); +yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name )); continue; } diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index e6c4ab2771..41aaebd9b1 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -114,7 +114,7 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p DEBUG(3,("process_host_announce: from %s<%02x> IP %s to \ %s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip), - namestr(&dgram->dest_name),announce_name)); + nmb_namestr(&dgram->dest_name),announce_name)); DEBUG(5,("process_host_announce: ttl=%d server type=%08x comment=%s\n", ttl, servertype,comment)); @@ -213,7 +213,7 @@ void process_workgroup_announce(struct subnet_record *subrec, struct packet_stru DEBUG(3,("process_workgroup_announce: from %s<%02x> IP %s to \ %s for workgroup %s.\n", source_name, source_name[15], inet_ntoa(p->ip), - namestr(&dgram->dest_name),workgroup_announce_name)); + nmb_namestr(&dgram->dest_name),workgroup_announce_name)); DEBUG(5,("process_workgroup_announce: ttl=%d server type=%08x master browser=%s\n", ttl, servertype, master_name)); @@ -222,7 +222,7 @@ void process_workgroup_announce(struct subnet_record *subrec, struct packet_stru if (!strequal(dgram->dest_name.name, MSBROWSE) || (dgram->dest_name.name_type != 0x1)) { DEBUG(0,("process_workgroup_announce: from IP %s should be to __MSBROWSE__<0x01> not %s\n", - inet_ntoa(p->ip), namestr(&dgram->dest_name))); + inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name))); return; } @@ -267,7 +267,7 @@ void process_local_master_announce(struct subnet_record *subrec, struct packet_s DEBUG(3,("process_local_master_announce: from %s<%02x> IP %s to \ %s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip), - namestr(&dgram->dest_name),server_name)); + nmb_namestr(&dgram->dest_name),server_name)); DEBUG(5,("process_local_master_announce: ttl=%d server type=%08x comment=%s\n", ttl, servertype, comment)); @@ -440,7 +440,7 @@ void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct DEBUG(3,("process_lm_host_announce: LM Announcement from %s<%02x> IP %s to \ %s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip), - namestr(&dgram->dest_name),announce_name)); + nmb_namestr(&dgram->dest_name),announce_name)); DEBUG(5,("process_lm_host_announce: os=(%d,%d) ttl=%d server type=%08x comment=%s\n", osmajor, osminor, ttl, servertype,comment)); @@ -552,7 +552,7 @@ static void send_backup_list_response(struct subnet_record *subrec, bzero(outbuf,sizeof(outbuf)); DEBUG(3,("send_backup_list_response: sending backup list for workgroup %s to %s IP %s\n", - work->work_group, namestr(send_to_name), inet_ntoa(sendto_ip))); + work->work_group, nmb_namestr(send_to_name), inet_ntoa(sendto_ip))); p = outbuf; @@ -632,8 +632,8 @@ void process_get_backup_list_request(struct subnet_record *subrec, char *workgroup_name = dgram->dest_name.name; DEBUG(3,("process_get_backup_list_request: request from %s IP %s to %s.\n", - namestr(&dgram->source_name), inet_ntoa(p->ip), - namestr(&dgram->dest_name))); + nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), + nmb_namestr(&dgram->dest_name))); /* We have to be a master browser, or a domain master browser for the requested workgroup. That means it must be our @@ -707,7 +707,7 @@ void process_reset_browser(struct subnet_record *subrec, DEBUG(1,("process_reset_browser: received diagnostic browser reset \ request from %s IP %s state=0x%X\n", - namestr(&dgram->source_name), inet_ntoa(p->ip), state)); + nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), state)); /* Stop being a local master browser on all our broadcast subnets. */ if (state & 0x1) @@ -758,8 +758,8 @@ void process_announce_request(struct subnet_record *subrec, struct packet_struct char *workgroup_name = dgram->dest_name.name; DEBUG(3,("process_announce_request: Announce request from %s IP %s to %s.\n", - namestr(&dgram->source_name), inet_ntoa(p->ip), - namestr(&dgram->dest_name))); + nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), + nmb_namestr(&dgram->dest_name))); /* We only send announcement requests on our workgroup. */ if(strequal(workgroup_name, global_myworkgroup) == False) @@ -794,8 +794,8 @@ void process_lm_announce_request(struct subnet_record *subrec, struct packet_str char *workgroup_name = dgram->dest_name.name; DEBUG(3,("process_lm_announce_request: Announce request from %s IP %s to %s.\n", - namestr(&dgram->source_name), inet_ntoa(p->ip), - namestr(&dgram->dest_name))); + nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), + nmb_namestr(&dgram->dest_name))); /* We only send announcement requests on our workgroup. */ if(strequal(workgroup_name, global_myworkgroup) == False) diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index 97d223b291..dd5a23e0b0 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -81,7 +81,7 @@ void process_name_release_request(struct subnet_record *subrec, */ DEBUG(0,("process_name_release_request: unicast name release request \ received for name %s from IP %s on subnet %s. Error - should be sent to WINS server\n", - namestr(question), inet_ntoa(owner_ip), subrec->subnet_name)); + nmb_namestr(question), inet_ntoa(owner_ip), subrec->subnet_name)); send_name_release_response(FMT_ERR, p); return; @@ -89,7 +89,7 @@ received for name %s from IP %s on subnet %s. Error - should be sent to WINS ser DEBUG(3,("process_name_release_request: Name release on name %s, \ subnet %s from owner IP %s\n", - namestr(&nmb->question.question_name), + nmb_namestr(&nmb->question.question_name), subrec->subnet_name, inet_ntoa(owner_ip))); /* If someone is releasing a broadcast group name, just ignore it. */ @@ -107,7 +107,7 @@ subnet %s from owner IP %s\n", { DEBUG(6,("process_name_release_request: FTP OnNet bug workaround. Ignoring \ group release name %s from IP %s on subnet %s with no group bit set.\n", - namestr(question), inet_ntoa(owner_ip), subrec->subnet_name )); + nmb_namestr(question), inet_ntoa(owner_ip), subrec->subnet_name )); return; } @@ -121,7 +121,7 @@ group release name %s from IP %s on subnet %s with no group bit set.\n", rcode = ACT_ERR; DEBUG(0, ("process_name_release_request: Attempt to release name %s from IP %s \ on subnet %s being rejected as it is one of our names.\n", - namestr(&nmb->question.question_name), inet_ntoa(owner_ip), subrec->subnet_name)); + nmb_namestr(&nmb->question.question_name), inet_ntoa(owner_ip), subrec->subnet_name)); } if(rcode == 0) @@ -177,7 +177,7 @@ void process_name_refresh_request(struct subnet_record *subrec, */ DEBUG(0,("process_name_refresh_request: unicast name registration request \ received for name %s from IP %s on subnet %s. Error - should be sent to WINS server\n", - namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); send_name_registration_response(FMT_ERR, 0, p); return; @@ -187,7 +187,7 @@ received for name %s from IP %s on subnet %s. Error - should be sent to WINS ser refreshes. */ DEBUG(3,("process_name_refresh_request: Name refresh for name %s \ -IP %s on subnet %s\n", namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); +IP %s on subnet %s\n", nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); } @@ -220,14 +220,14 @@ void process_name_registration_request(struct subnet_record *subrec, */ DEBUG(0,("process_name_registration_request: unicast name registration request \ received for name %s from IP %s on subnet %s. Error - should be sent to WINS server\n", - namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); send_name_registration_response(FMT_ERR, 0, p); return; } DEBUG(3,("process_name_registration_request: Name registration for name %s \ -IP %s on subnet %s\n", namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); +IP %s on subnet %s\n", nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); /* See if the name already exists. */ namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); @@ -266,7 +266,7 @@ IP %s on subnet %s\n", namestr(question), inet_ntoa(from_ip), subrec->subnet_nam update_name_ttl(namerec, ttl); DEBUG(3,("process_name_registration_request: Updated name record %s \ -with IP %s on subnet %s\n",namestr(&namerec->name),inet_ntoa(from_ip), subrec->subnet_name)); +with IP %s on subnet %s\n",nmb_namestr(&namerec->name),inet_ntoa(from_ip), subrec->subnet_name)); return; } } @@ -328,14 +328,14 @@ void process_node_status_request(struct subnet_record *subrec, struct packet_str struct name_record *namerec; DEBUG(3,("process_node_status_request: status request for name %s from IP %s on \ -subnet %s.\n", namestr(&nmb->question.question_name), inet_ntoa(p->ip), +subnet %s.\n", nmb_namestr(&nmb->question.question_name), inet_ntoa(p->ip), subrec->subnet_name)); if((namerec = find_name_on_subnet(subrec, &nmb->question.question_name, FIND_SELF_NAME)) == 0) { DEBUG(1,("process_node_status_request: status request for name %s from IP %s on \ -subnet %s - name not found.\n", namestr(&nmb->question.question_name), +subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name), inet_ntoa(p->ip), subrec->subnet_name)); return; @@ -462,7 +462,7 @@ void process_name_query_request(struct subnet_record *subrec, struct packet_stru int i; DEBUG(3,("process_name_query_request: Name query from %s on subnet %s for name %s\n", - inet_ntoa(p->ip), subrec->subnet_name, namestr(question))); + inet_ntoa(p->ip), subrec->subnet_name, nmb_namestr(question))); /* Look up the name in the cache - if the request is a broadcast request that came from a subnet we don't know about then search all the broadcast subnets @@ -479,7 +479,7 @@ void process_name_query_request(struct subnet_record *subrec, struct packet_stru && ( (namerec->data.death_time != PERMANENT_TTL) && (namerec->data.death_time < p->timestamp) ) ) { - DEBUG(5,("process_name_query_request: expired name %s\n", namestr(&namerec->name))); + DEBUG(5,("process_name_query_request: expired name %s\n", nmb_namestr(&namerec->name))); namerec = NULL; } @@ -526,7 +526,7 @@ void process_name_query_request(struct subnet_record *subrec, struct packet_stru { DEBUG(5,("process_name_query_request: name %s is a WINS proxy name and is also \ on the same subnet (%s) as the requestor. Not replying.\n", - namestr(&namerec->name), subrec->subnet_name )); + nmb_namestr(&namerec->name), subrec->subnet_name )); return; } } diff --git a/source3/nmbd/nmbd_logonnames.c b/source3/nmbd/nmbd_logonnames.c index 4486fb2840..471a64377d 100644 --- a/source3/nmbd/nmbd_logonnames.c +++ b/source3/nmbd/nmbd_logonnames.c @@ -68,7 +68,7 @@ in workgroup %s on subnet %s\n", DEBUG(0,("become_logon_server_fail: Failed to become a domain master for \ workgroup %s on subnet %s. Couldn't register name %s.\n", - work->work_group, subrec->subnet_name, namestr(fail_name))); + work->work_group, subrec->subnet_name, nmb_namestr(fail_name))); } diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index 4a4e102786..64cb8ea9e9 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -40,7 +40,7 @@ static void my_name_register_failed(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *nmbname) { DEBUG(0,("my_name_register_failed: Failed to register my name %s on subnet %s.\n", - namestr(nmbname), subrec->subnet_name)); + nmb_namestr(nmbname), subrec->subnet_name)); } /**************************************************************************** diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index f9b2e3da9a..1493c87f8a 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -125,16 +125,16 @@ struct name_record *find_name_on_subnet( struct subnet_record *subrec, { DEBUG( 9, ( "find_name_on_subnet: on subnet %s - self name %s NOT FOUND\n", - subrec->subnet_name, namestr(nmbname) ) ); + subrec->subnet_name, nmb_namestr(nmbname) ) ); return( NULL ); } DEBUG( 9, ("find_name_on_subnet: on subnet %s - found name %s source=%d\n", - subrec->subnet_name, namestr(nmbname), name_ret->data.source) ); + subrec->subnet_name, nmb_namestr(nmbname), name_ret->data.source) ); return( name_ret ); } DEBUG( 9, ( "find_name_on_subnet: on subnet %s - name %s NOT FOUND\n", - subrec->subnet_name, namestr(nmbname) ) ); + subrec->subnet_name, nmb_namestr(nmbname) ) ); return( NULL ); } /* find_name_on_subnet */ @@ -243,7 +243,7 @@ struct name_record *add_name_to_subnet( struct subnet_record *subrec, DEBUG( 3, ( "add_name_to_subnet: Added netbios name %s with first IP %s \ ttl=%d nb_flags=%2x to subnet %s\n", - namestr( &namerec->name ), + nmb_namestr( &namerec->name ), inet_ntoa( *iplist ), ttl, (unsigned int)nb_flags, @@ -292,7 +292,7 @@ void standard_fail_register( struct subnet_record *subrec, DEBUG( 0, ( "standard_fail_register: Failed to register/refresh name %s \ on subnet %s\n", - namestr(nmbname), subrec->subnet_name) ); + nmb_namestr(nmbname), subrec->subnet_name) ); /* Remove the name from the subnet. */ if( namerec ) @@ -399,7 +399,7 @@ void standard_success_release( struct subnet_record *subrec, { DEBUG( 0, ( "standard_success_release: Name release for name %s IP %s \ on subnet %s. Name was not found on subnet.\n", - namestr(nmbname), + nmb_namestr(nmbname), inet_ntoa(released_ip), subrec->subnet_name) ); return; @@ -413,7 +413,7 @@ on subnet %s. Name was not found on subnet.\n", if( namerec->data.num_ips == orig_num ) DEBUG( 0, ( "standard_success_release: Name release for name %s IP %s \ on subnet %s. This ip is not known for this name.\n", - namestr(nmbname), + nmb_namestr(nmbname), inet_ntoa(released_ip), subrec->subnet_name ) ); } @@ -443,13 +443,13 @@ void expire_names_on_subnet(struct subnet_record *subrec, time_t t) { DEBUG( 3, ( "expire_names_on_subnet: Subnet %s not expiring SELF \ name %s\n", - subrec->subnet_name, namestr(&namerec->name) ) ); + subrec->subnet_name, nmb_namestr(&namerec->name) ) ); namerec->data.death_time += 300; namerec->subnet->namelist_changed = True; continue; } DEBUG(3,("expire_names_on_subnet: Subnet %s - removing expired name %s\n", - subrec->subnet_name, namestr(&namerec->name))); + subrec->subnet_name, nmb_namestr(&namerec->name))); remove_name_from_namelist( subrec, namerec ); } @@ -541,7 +541,7 @@ static void dump_subnet_namelist( struct subnet_record *subrec, FILE *fp) namerec; namerec = (struct name_record *)ubi_trNext( namerec ) ) { - fprintf(fp,"\tName = %s\t", namestr(&namerec->name)); + fprintf(fp,"\tName = %s\t", nmb_namestr(&namerec->name)); switch(namerec->data.source) { case LMHOSTS_NAME: diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index 7c2b0d4d76..fae045882f 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -56,7 +56,7 @@ static void query_name_response(struct subnet_record *subrec, the response but don't send out any more query requests. */ DEBUG(5,("query_name_response: WACK from WINS server %s in querying \ -name %s on subnet %s.\n", inet_ntoa(p->ip), namestr(question_name), subrec->subnet_name)); +name %s on subnet %s.\n", inet_ntoa(p->ip), nmb_namestr(question_name), subrec->subnet_name)); rrec->repeat_count = 0; /* How long we should wait for. */ @@ -70,7 +70,7 @@ name %s on subnet %s.\n", inet_ntoa(p->ip), namestr(question_name), subrec->subn DEBUG(5,("query_name_response: On subnet %s - negative response \ from IP %s for name %s. Error code was %d.\n", subrec->subnet_name, inet_ntoa(p->ip), - namestr(question_name), nmb->header.rcode)); + nmb_namestr(question_name), nmb->header.rcode)); } else { @@ -79,7 +79,7 @@ from IP %s for name %s. Error code was %d.\n", subrec->subnet_name, inet_ntoa(p- putip((char *)&answer_ip,&nmb->answers->rdata[2]); DEBUG(5,("query_name_response: On subnet %s - positive response from IP %s \ for name %s. IP of that name is %s\n", subrec->subnet_name, inet_ntoa(p->ip), - namestr(question_name), inet_ntoa(answer_ip))); + nmb_namestr(question_name), inet_ntoa(answer_ip))); /* Interestingly, we could add these names to our namelists, and change nmbd to a model that checked its own name cache first, @@ -91,7 +91,7 @@ for name %s. IP of that name is %s\n", subrec->subnet_name, inet_ntoa(p->ip), { DEBUG(0,("query_name_response: Multiple (%d) responses received for a query on \ subnet %s for name %s. This response was from IP %s\n", - rrec->num_msgs, subrec->subnet_name, namestr(question_name), + rrec->num_msgs, subrec->subnet_name, nmb_namestr(question_name), inet_ntoa(p->ip) )); /* We have already called the success or fail function, so we @@ -131,7 +131,7 @@ static void query_name_timeout_response(struct subnet_record *subrec, if(failed) { DEBUG(5,("query_name_timeout_response: No response to querying name %s on subnet %s.\n", - namestr(question_name), subrec->subnet_name)); + nmb_namestr(question_name), subrec->subnet_name)); if(rrec->fail_fn) (*rrec->fail_fn)(subrec, rrec, question_name, 0); @@ -204,7 +204,7 @@ BOOL query_name(struct subnet_record *subrec, char *name, int type, if(rrec.rdlength > MAX_DGRAM_SIZE) { DEBUG(0,("query_name: nmbd internal error - there are %d ip addresses for name %s.\n", - namerec->data.num_ips, namestr(&nmbname) )); + namerec->data.num_ips, nmb_namestr(&nmbname) )); return False; } @@ -229,7 +229,7 @@ BOOL query_name(struct subnet_record *subrec, char *name, int type, &nmbname) == NULL) { DEBUG(0,("query_name: Failed to send packet trying to query name %s\n", - namestr(&nmbname))); + nmb_namestr(&nmbname))); return True; } return False; @@ -258,7 +258,7 @@ BOOL query_name_from_wins_server(struct in_addr ip_to, &nmbname) == NULL) { DEBUG(0,("query_name_from_wins_server: Failed to send packet trying to query name %s\n", - namestr(&nmbname))); + nmb_namestr(&nmbname))); return True; } return False; diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index 05b549d30f..069e262987 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -57,7 +57,7 @@ static void register_name_response(struct subnet_record *subrec, if(!nmb_name_equal(question_name, answer_name)) { DEBUG(0,("register_name_response: Answer name %s differs from question \ -name %s.\n", namestr(answer_name), namestr(question_name))); +name %s.\n", nmb_namestr(answer_name), nmb_namestr(question_name))); return; } @@ -80,7 +80,7 @@ name %s.\n", namestr(answer_name), namestr(question_name))); rrec->num_msgs--; DEBUG(5,("register_name_response: Ignoring broadcast response to \ -registration of name %s due to old Samba server bug.\n", namestr(answer_name))); +registration of name %s due to old Samba server bug.\n", nmb_namestr(answer_name))); return; } #endif /* OLD_SAMBA_SERVER_HACK */ @@ -88,7 +88,7 @@ registration of name %s due to old Samba server bug.\n", namestr(answer_name))); /* Someone else has the name. Log the problem. */ DEBUG(1,("register_name_response: Failed to register \ name %s on subnet %s via broadcast. Error code was %d. Reject came from IP %s\n", - namestr(answer_name), + nmb_namestr(answer_name), subrec->subnet_name, nmb->header.rcode, inet_ntoa(p->ip))); success = False; } @@ -102,7 +102,7 @@ name %s on subnet %s via broadcast. Error code was %d. Reject came from IP %s\n" DEBUG(0,("register_name_response: server at IP %s rejected our \ name registration of %s with error code %d.\n", inet_ntoa(p->ip), - namestr(answer_name), nmb->header.rcode)); + nmb_namestr(answer_name), nmb->header.rcode)); } else if(nmb->header.opcode == NMB_WACK_OPCODE) @@ -111,7 +111,7 @@ name registration of %s with error code %d.\n", inet_ntoa(p->ip), the response but don't send out any more register requests. */ DEBUG(5,("register_name_response: WACK from WINS server %s in registering \ -name %s on subnet %s.\n", inet_ntoa(p->ip), namestr(answer_name), subrec->subnet_name)); +name %s on subnet %s.\n", inet_ntoa(p->ip), nmb_namestr(answer_name), subrec->subnet_name)); rrec->repeat_count = 0; /* How long we should wait for. */ @@ -130,7 +130,7 @@ name %s on subnet %s.\n", inet_ntoa(p->ip), namestr(answer_name), subrec->subnet } DEBUG(5,("register_name_response: %s in registering name %s on subnet %s.\n", - success ? "success" : "failure", namestr(answer_name), subrec->subnet_name)); + success ? "success" : "failure", nmb_namestr(answer_name), subrec->subnet_name)); if(success) { @@ -213,7 +213,7 @@ responding.\n", inet_ntoa(rrec->packet->ip))); } DEBUG(5,("register_name_timeout_response: %s in registering name %s on subnet %s.\n", - success ? "success" : "failure", namestr(question_name), subrec->subnet_name)); + success ? "success" : "failure", nmb_namestr(question_name), subrec->subnet_name)); if(success) { /* Enter the registered name into the subnet name database before calling @@ -302,7 +302,7 @@ static BOOL multihomed_register_name( struct nmb_name *nmbname, uint16 nb_flags, ip_list[i]) == NULL) { DEBUG(0,("multihomed_register_name: Failed to send packet trying to \ -register name %s IP %s\n", namestr(nmbname), inet_ntoa(ip_list[i]) )); +register name %s IP %s\n", nmb_namestr(nmbname), inet_ntoa(ip_list[i]) )); free((char *)ip_list); return True; @@ -352,7 +352,7 @@ BOOL register_name(struct subnet_record *subrec, nb_flags) == NULL) { DEBUG(0,("register_name: Failed to send packet trying to register name %s\n", - namestr(&nmbname))); + nmb_namestr(&nmbname))); return True; } return False; @@ -387,7 +387,7 @@ BOOL refresh_name(struct subnet_record *subrec, struct name_record *namerec, namerec->data.ip[i]) == NULL) { DEBUG(0,("refresh_name: Failed to send packet trying to refresh name %s\n", - namestr(&namerec->name))); + nmb_namestr(&namerec->name))); return True; } } diff --git a/source3/nmbd/nmbd_namerelease.c b/source3/nmbd/nmbd_namerelease.c index 558ab6ab16..1cdc78e6a0 100644 --- a/source3/nmbd/nmbd_namerelease.c +++ b/source3/nmbd/nmbd_namerelease.c @@ -53,7 +53,7 @@ static void release_name_response(struct subnet_record *subrec, if(!nmb_name_equal(question_name, answer_name)) { DEBUG(0,("release_name_response: Answer name %s differs from question \ -name %s.\n", namestr(answer_name), namestr(question_name))); +name %s.\n", nmb_namestr(answer_name), nmb_namestr(question_name))); return; } @@ -61,7 +61,7 @@ name %s.\n", namestr(answer_name), namestr(question_name))); { /* Someone sent a response. This shouldn't happen/ */ DEBUG(1,("release_name_response: A response for releasing name %s was received on a \ -broadcast subnet %s. This should not happen !\n", namestr(answer_name), subrec->subnet_name)); +broadcast subnet %s. This should not happen !\n", nmb_namestr(answer_name), subrec->subnet_name)); return; } else @@ -74,7 +74,7 @@ broadcast subnet %s. This should not happen !\n", namestr(answer_name), subrec-> DEBUG(0,("release_name_response: WINS server at IP %s rejected our \ name release of name %s with error code %d.\n", inet_ntoa(p->ip), - namestr(answer_name), nmb->header.rcode)); + nmb_namestr(answer_name), nmb->header.rcode)); } else if(nmb->header.opcode == NMB_WACK_OPCODE) @@ -83,7 +83,7 @@ name release of name %s with error code %d.\n", inet_ntoa(p->ip), the response but don't send out any more release requests. */ DEBUG(5,("release_name_response: WACK from WINS server %s in releasing \ -name %s on subnet %s.\n", inet_ntoa(p->ip), namestr(answer_name), subrec->subnet_name)); +name %s on subnet %s.\n", inet_ntoa(p->ip), nmb_namestr(answer_name), subrec->subnet_name)); rrec->repeat_count = 0; /* How long we should wait for. */ @@ -94,7 +94,7 @@ name %s on subnet %s.\n", inet_ntoa(p->ip), namestr(answer_name), subrec->subnet } DEBUG(5,("release_name_response: %s in releasing name %s on subnet %s.\n", - success ? "success" : "failure", namestr(answer_name), subrec->subnet_name)); + success ? "success" : "failure", nmb_namestr(answer_name), subrec->subnet_name)); if(success) { @@ -171,7 +171,7 @@ responding.\n", inet_ntoa(rrec->packet->ip))); } DEBUG(5,("release_name_timeout_response: %s in releasing name %s on subnet %s.\n", - success ? "success" : "failure", namestr(question_name), subrec->subnet_name)); + success ? "success" : "failure", nmb_namestr(question_name), subrec->subnet_name)); if(success && rrec->success_fn) { @@ -204,7 +204,7 @@ BOOL release_name(struct subnet_record *subrec, struct name_record *namerec, if((namerec->data.source != SELF_NAME) || !NAME_IS_ACTIVE(namerec)) { DEBUG(0,("release_name: Cannot release name %s from subnet %s. Source was %d \n", - namestr(&namerec->name), subrec->subnet_name, namerec->data.source)); + nmb_namestr(&namerec->name), subrec->subnet_name, namerec->data.source)); return True; } @@ -230,7 +230,7 @@ BOOL release_name(struct subnet_record *subrec, struct name_record *namerec, namerec->data.ip[i]) == NULL) { DEBUG(0,("release_name: Failed to send packet trying to release name %s IP %s\n", - namestr(&namerec->name), inet_ntoa(namerec->data.ip[i]) )); + nmb_namestr(&namerec->name), inet_ntoa(namerec->data.ip[i]) )); return True; } } diff --git a/source3/nmbd/nmbd_nodestatus.c b/source3/nmbd/nmbd_nodestatus.c index 196c0f0ba7..d8af09b398 100644 --- a/source3/nmbd/nmbd_nodestatus.c +++ b/source3/nmbd/nmbd_nodestatus.c @@ -44,12 +44,12 @@ static void node_status_response(struct subnet_record *subrec, if(!nmb_name_equal(question_name, answer_name)) { DEBUG(0,("node_status_response: Answer name %s differs from question \ -name %s.\n", namestr(answer_name), namestr(question_name))); +name %s.\n", nmb_namestr(answer_name), nmb_namestr(question_name))); return; } DEBUG(5,("node_status_response: response from name %s on subnet %s.\n", - namestr(answer_name), subrec->subnet_name)); + nmb_namestr(answer_name), subrec->subnet_name)); /* Just send the whole answer resource record for the success function to parse. */ @@ -70,7 +70,7 @@ static void node_status_timeout_response(struct subnet_record *subrec, struct nmb_name *question_name = &sent_nmb->question.question_name; DEBUG(5,("node_status_timeout_response: failed to get node status from name %s on subnet %s\n", - namestr(question_name), subrec->subnet_name)); + nmb_namestr(question_name), subrec->subnet_name)); if( rrec->fail_fn) (*rrec->fail_fn)(subrec, rrec); @@ -92,7 +92,7 @@ BOOL node_status(struct subnet_record *subrec, struct nmb_name *nmbname, success_fn, fail_fn, userdata, nmbname, send_ip)==NULL) { DEBUG(0,("node_status: Failed to send packet trying to get node status for \ -name %s, IP address %s\n", namestr(nmbname), inet_ntoa(send_ip))); +name %s, IP address %s\n", nmb_namestr(nmbname), inet_ntoa(send_ip))); return True; } return False; diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index d7049a270f..ce785b40a4 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -279,7 +279,7 @@ static BOOL initiate_name_query_packet( struct packet_struct *packet) nmb->header.nm_flags.recursion_desired = True; DEBUG(4,("initiate_name_query_packet: sending query for name %s (bcast=%s) to IP %s\n", - namestr(&nmb->question.question_name), + nmb_namestr(&nmb->question.question_name), BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip))); return send_netbios_packet( packet ); @@ -301,7 +301,7 @@ static BOOL initiate_name_query_packet_from_wins_server( struct packet_struct *p nmb->header.nm_flags.recursion_desired = False; DEBUG(4,("initiate_name_query_packet_from_wins_server: sending query for name %s (bcast=%s) to IP %s\n", - namestr(&nmb->question.question_name), + nmb_namestr(&nmb->question.question_name), BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip))); return send_netbios_packet( packet ); @@ -325,7 +325,7 @@ static BOOL initiate_name_register_packet( struct packet_struct *packet, return False; DEBUG(4,("initiate_name_register_packet: sending registration for name %s (bcast=%s) to IP %s\n", - namestr(&nmb->additional->rr_name), + nmb_namestr(&nmb->additional->rr_name), BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip))); return send_netbios_packet( packet ); @@ -353,7 +353,7 @@ static BOOL initiate_multihomed_name_register_packet( struct packet_struct *pack DEBUG(4,("initiate_multihomed_name_register_packet: sending registration \ for name %s IP %s (bcast=%s) to IP %s\n", - namestr(&nmb->additional->rr_name), inet_ntoa(*register_ip), + nmb_namestr(&nmb->additional->rr_name), inet_ntoa(*register_ip), BOOLSTR(nmb->header.nm_flags.bcast), second_ip_buf )); return send_netbios_packet( packet ); @@ -377,7 +377,7 @@ static BOOL initiate_name_refresh_packet( struct packet_struct *packet, return False; DEBUG(4,("initiate_name_refresh_packet: sending refresh for name %s (bcast=%s) to IP %s\n", - namestr(&nmb->additional->rr_name), + nmb_namestr(&nmb->additional->rr_name), BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip))); return send_netbios_packet( packet ); @@ -401,7 +401,7 @@ static BOOL initiate_name_release_packet( struct packet_struct *packet, return False; DEBUG(4,("initiate_name_release_packet: sending release for name %s (bcast=%s) to IP %s\n", - namestr(&nmb->additional->rr_name), + nmb_namestr(&nmb->additional->rr_name), BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip))); return send_netbios_packet( packet ); @@ -423,7 +423,7 @@ static BOOL initiate_node_status_packet( struct packet_struct *packet ) nmb->question.question_type = QUESTION_TYPE_NB_STATUS; DEBUG(4,("initiate_node_status_packet: sending node status request for name %s to IP %s\n", - namestr(&nmb->question.question_name), + nmb_namestr(&nmb->question.question_name), inet_ntoa(packet->ip))); return send_netbios_packet( packet ); @@ -898,7 +898,7 @@ void reply_netbios_packet(struct packet_struct *orig_packet, default: { DEBUG(0,("reply_netbios_packet: Unknown packet type: %s %s to ip %s\n", - packet_type, namestr(&orig_nmb->question.question_name), + packet_type, nmb_namestr(&orig_nmb->question.question_name), inet_ntoa(packet.ip))); return; @@ -907,7 +907,7 @@ void reply_netbios_packet(struct packet_struct *orig_packet, DEBUG(4,("reply_netbios_packet: sending a reply of packet type: %s %s to ip %s \ for id %hu\n", - packet_type, namestr(&orig_nmb->question.question_name), + packet_type, nmb_namestr(&orig_nmb->question.question_name), inet_ntoa(packet.ip), orig_nmb->header.name_trn_id)); nmb->header.name_trn_id = orig_nmb->header.name_trn_id; @@ -1033,7 +1033,7 @@ mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, scop if (is_myname(dgram->source_name.name)) { DEBUG(0,("process_browse_packet: Discarding datagram from IP %s. Source name \ -%s is one of our names !\n", inet_ntoa(p->ip), namestr(&dgram->source_name))); +%s is one of our names !\n", inet_ntoa(p->ip), nmb_namestr(&dgram->source_name))); return; } @@ -1090,7 +1090,7 @@ mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, scop /* We never send ANN_GetBackupListReq so we should never get these. */ DEBUG(0,("process_browse_packet: Discarding GetBackupListResponse \ -packet from %s IP %s\n", namestr(&dgram->source_name), inet_ntoa(p->ip))); +packet from %s IP %s\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip))); break; } case ANN_ResetBrowserState: @@ -1117,8 +1117,8 @@ packet from %s IP %s\n", namestr(&dgram->source_name), inet_ntoa(p->ip))); debug_browse_data(buf, len); DEBUG(10,("process_browse_packet: On subnet %s ignoring browse packet \ command ANN_BecomeBackup from %s IP %s to %s\n", - subrec->subnet_name, namestr(&dgram->source_name), - inet_ntoa(p->ip), namestr(&dgram->dest_name))); + subrec->subnet_name, nmb_namestr(&dgram->source_name), + inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name))); break; } default: @@ -1126,8 +1126,8 @@ command ANN_BecomeBackup from %s IP %s to %s\n", debug_browse_data(buf, len); DEBUG(0,("process_browse_packet: On subnet %s ignoring browse packet \ command code %d from %s IP %s to %s\n", - subrec->subnet_name, command, namestr(&dgram->source_name), - inet_ntoa(p->ip), namestr(&dgram->dest_name))); + subrec->subnet_name, command, nmb_namestr(&dgram->source_name), + inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name))); } } } @@ -1154,7 +1154,7 @@ mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, scop if (is_myname(dgram->source_name.name)) { DEBUG(0,("process_lanman_packet: Discarding datagram from IP %s. Source name \ -%s is one of our names !\n", inet_ntoa(p->ip), namestr(&dgram->source_name))); +%s is one of our names !\n", inet_ntoa(p->ip), nmb_namestr(&dgram->source_name))); return; } @@ -1175,8 +1175,8 @@ mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, scop { DEBUG(0,("process_lanman_packet: On subnet %s ignoring browse packet \ command code %d from %s IP %s to %s\n", - subrec->subnet_name, command, namestr(&dgram->source_name), - inet_ntoa(p->ip), namestr(&dgram->dest_name))); + subrec->subnet_name, command, nmb_namestr(&dgram->source_name), + inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name))); } } } @@ -1218,7 +1218,7 @@ static void process_dgram(struct packet_struct *p) if (!listening(p,&dgram->dest_name)) { DEBUG(5,("process_dgram: ignoring dgram packet sent to name %s from %s\n", - namestr(&dgram->dest_name), inet_ntoa(p->ip))); + nmb_namestr(&dgram->dest_name), inet_ntoa(p->ip))); return; } @@ -1229,7 +1229,7 @@ static void process_dgram(struct packet_struct *p) /* Don't process error packets etc yet */ DEBUG(5,("process_dgram: ignoring dgram packet sent to name %s from IP %s as it is \ an error packet of type %x\n", - namestr(&dgram->dest_name), inet_ntoa(p->ip), dgram->header.msg_type)); + nmb_namestr(&dgram->dest_name), inet_ntoa(p->ip), dgram->header.msg_type)); return; } @@ -1244,7 +1244,7 @@ static void process_dgram(struct packet_struct *p) buf2 = smb_base(buf) + SVAL(buf,smb_vwv12); DEBUG(4,("process_dgram: datagram from %s to %s IP %s for %s of type %d len=%d\n", - namestr(&dgram->source_name),namestr(&dgram->dest_name), + nmb_namestr(&dgram->source_name),nmb_namestr(&dgram->dest_name), inet_ntoa(p->ip), smb_buf(buf),CVAL(buf2,0),len)); @@ -1940,8 +1940,8 @@ BOOL send_mailslot(BOOL unique, char *mailslot,char *buf,int len, p.packet_type = DGRAM_PACKET; DEBUG(4,("send_mailslot: Sending to mailslot %s from %s IP %s ", mailslot, - namestr(&dgram->source_name), inet_ntoa(src_ip))); - DEBUG(4,("to %s IP %s\n", namestr(&dgram->dest_name), inet_ntoa(dest_ip))); + nmb_namestr(&dgram->source_name), inet_ntoa(src_ip))); + DEBUG(4,("to %s IP %s\n", nmb_namestr(&dgram->dest_name), inet_ntoa(dest_ip))); debug_browse_data(buf, len); diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index edc930c205..527efa9dd8 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -96,7 +96,7 @@ static int namelist_entry_compare( ubi_trItemPtr Item, ubi_trNodePtr Node ) Debug1( "nmbd_subnetdb:namelist_entry_compare()\n" ); Debug1( "%d == memcmp( \"%s\", \"%s\", %d )\n", memcmp( Item, &(NR->name), sizeof(struct nmb_name) ), - namestr(Iname), namestr(&NR->name), sizeof(struct nmb_name) ); + nmb_namestr(Iname), nmb_namestr(&NR->name), sizeof(struct nmb_name) ); } return( memcmp( Item, &(NR->name), sizeof(struct nmb_name) ) ); diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index 2084d3915a..43beb9acd8 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -55,7 +55,7 @@ static void wins_proxy_name_query_request_success( struct subnet_record *subrec, if(num_ips == 0) { DEBUG(0,("wins_proxy_name_query_request_success: Invalid number of IP records (0) \ -returned for name %s.\n", namestr(nmbname) )); +returned for name %s.\n", nmb_namestr(nmbname) )); return; } @@ -104,7 +104,7 @@ returned for name %s.\n", namestr(nmbname) )); DEBUG( 5, ( "wins_proxy_name_query_request_success: name %s is a WINS \ proxy name and is also on the same subnet (%s) as the requestor. \ Not replying.\n", - namestr(&namerec->name), + nmb_namestr(&namerec->name), orig_broadcast_subnet->subnet_name ) ); return; } @@ -130,7 +130,7 @@ static void wins_proxy_name_query_request_fail(struct subnet_record *subrec, struct nmb_name *question_name, int fail_code) { DEBUG(4,("wins_proxy_name_query_request_fail: WINS server returned error code %d for lookup \ -of name %s.\n", fail_code, namestr(question_name) )); +of name %s.\n", fail_code, nmb_namestr(question_name) )); } /**************************************************************************** diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 5dc350152f..0906715af4 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -402,12 +402,12 @@ void wins_process_name_refresh_request(struct subnet_record *subrec, DEBUG(0,("wins_process_name_refresh_request: broadcast name refresh request \ received for name %s from IP %s on subnet %s. Error - should not be sent to WINS server\n", - namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); return; } DEBUG(3,("wins_process_name_refresh_request: Name refresh for name %s \ -IP %s\n", namestr(question), inet_ntoa(from_ip) )); +IP %s\n", nmb_namestr(question), inet_ntoa(from_ip) )); /* * See if the name already exists. @@ -424,7 +424,7 @@ IP %s\n", namestr(question), inet_ntoa(from_ip) )); if(namerec == NULL) { DEBUG(3,("wins_process_name_refresh_request: Name refresh for name %s and \ -the name does not exist. Treating as registration.\n", namestr(question) )); +the name does not exist. Treating as registration.\n", nmb_namestr(question) )); wins_process_name_registration_request(subrec,p); return; } @@ -437,7 +437,7 @@ the name does not exist. Treating as registration.\n", namestr(question) )); if((namerec != NULL) && ((group && !NAME_GROUP(namerec)) || (!group && NAME_GROUP(namerec))) ) { DEBUG(3,("wins_process_name_refresh_request: Name %s group bit = %s \ -does not match group bit in WINS for this name.\n", namestr(question), group ? "True" : "False" )); +does not match group bit in WINS for this name.\n", nmb_namestr(question), group ? "True" : "False" )); send_wins_name_registration_response(RFS_ERR, 0, p); return; } @@ -483,7 +483,7 @@ does not match group bit in WINS for this name.\n", namestr(question), group ? " */ DEBUG(3,("wins_process_name_refresh_request: Name refresh for name %s with IP %s and \ -is IP is not known to the name.\n", namestr(question), inet_ntoa(from_ip) )); +is IP is not known to the name.\n", nmb_namestr(question), inet_ntoa(from_ip) )); send_wins_name_registration_response(RFS_ERR, 0, p); return; } @@ -510,7 +510,7 @@ static void wins_register_query_success(struct subnet_record *subrec, memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *)); DEBUG(3,("wins_register_query_success: Original client at IP %s still wants the \ -name %s. Rejecting registration request.\n", inet_ntoa(ip), namestr(question_name) )); +name %s. Rejecting registration request.\n", inet_ntoa(ip), nmb_namestr(question_name) )); send_wins_name_registration_response(RFS_ERR, 0, orig_reg_packet); @@ -563,7 +563,7 @@ static void wins_register_query_fail(struct subnet_record *subrec, wins_process_name_registration_request(subrec, orig_reg_packet); else DEBUG(2,("wins_register_query_fail: The state of the WINS database changed between \ -querying for name %s in order to replace it and this reply.\n", namestr(question_name) )); +querying for name %s in order to replace it and this reply.\n", nmb_namestr(question_name) )); orig_reg_packet->locked = False; free_packet(orig_reg_packet); @@ -650,12 +650,12 @@ void wins_process_name_registration_request(struct subnet_record *subrec, DEBUG(0,("wins_process_name_registration_request: broadcast name registration request \ received for name %s from IP %s on subnet %s. Error - should not be sent to WINS server\n", - namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); return; } DEBUG(3,("wins_process_name_registration_request: %s name registration for name %s \ -IP %s\n", registering_group_name ? "Group" : "Unique", namestr(question), inet_ntoa(from_ip) )); +IP %s\n", registering_group_name ? "Group" : "Unique", nmb_namestr(question), inet_ntoa(from_ip) )); /* * See if the name already exists. @@ -674,7 +674,7 @@ IP %s\n", registering_group_name ? "Group" : "Unique", namestr(question), inet_n || (namerec->data.source == DNSFAIL_NAME) ) ) { DEBUG(5,("wins_process_name_registration_request: Name (%s) in WINS was \ -a dns lookup - removing it.\n", namestr(question) )); +a dns lookup - removing it.\n", nmb_namestr(question) )); remove_name_from_namelist( subrec, namerec ); namerec = NULL; } @@ -688,7 +688,7 @@ a dns lookup - removing it.\n", namestr(question) )); { DEBUG( 3, ( "wins_process_name_registration_request: Attempt \ to register name %s. Name already exists in WINS with source type %d.\n", - namestr(question), namerec->data.source )); + nmb_namestr(question), namerec->data.source )); send_wins_name_registration_response(RFS_ERR, 0, p); return; } @@ -715,7 +715,7 @@ to register name %s. Name already exists in WINS with source type %d.\n", if(!registering_group_name && (question->name_type == 0x1d)) { DEBUG(3,("wins_process_name_registration_request: Ignoring request \ -to register name %s from IP %s.", namestr(question), inet_ntoa(p->ip) )); +to register name %s from IP %s.", nmb_namestr(question), inet_ntoa(p->ip) )); send_wins_name_registration_response(0, ttl, p); return; } @@ -734,7 +734,7 @@ to register name %s from IP %s.", namestr(question), inet_ntoa(p->ip) )); */ DEBUG(3,("wins_process_name_registration_request: Adding IP %s to group name %s.\n", - inet_ntoa(from_ip), namestr(question) )); + inet_ntoa(from_ip), nmb_namestr(question) )); /* * Check the ip address is not already in the group. */ @@ -752,7 +752,7 @@ to register name %s from IP %s.", namestr(question), inet_ntoa(p->ip) )); */ DEBUG(3,("wins_process_name_registration_request: Attempt to register name %s. Name \ -already exists in WINS as a GROUP name.\n", namestr(question) )); +already exists in WINS as a GROUP name.\n", nmb_namestr(question) )); send_wins_name_registration_response(RFS_ERR, 0, p); return; } @@ -774,7 +774,7 @@ already exists in WINS as a GROUP name.\n", namestr(question) )); if(!ismyip(from_ip)) { DEBUG(3,("wins_process_name_registration_request: Attempt to register name %s. Name \ -is one of our (WINS server) names. Denying registration.\n", namestr(question) )); +is one of our (WINS server) names. Denying registration.\n", nmb_namestr(question) )); send_wins_name_registration_response(RFS_ERR, 0, p); return; } @@ -903,7 +903,7 @@ static void wins_multihomed_register_query_success(struct subnet_record *subrec, if( (namerec == NULL) || (namerec->data.source != REGISTER_NAME) ) { DEBUG(3,("wins_multihomed_register_query_success: name %s is not in the correct state to add \ -a subsequent IP addess.\n", namestr(question_name) )); +a subsequent IP addess.\n", nmb_namestr(question_name) )); send_wins_name_registration_response(RFS_ERR, 0, orig_reg_packet); orig_reg_packet->locked = False; @@ -940,7 +940,7 @@ static void wins_multihomed_register_query_fail(struct subnet_record *subrec, memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *)); DEBUG(3,("wins_multihomed_register_query_fail: Registering machine at IP %s failed to answer \ -query successfully for name %s.\n", inet_ntoa(orig_reg_packet->ip), namestr(question_name) )); +query successfully for name %s.\n", inet_ntoa(orig_reg_packet->ip), nmb_namestr(question_name) )); send_wins_name_registration_response(RFS_ERR, 0, orig_reg_packet); orig_reg_packet->locked = False; @@ -977,7 +977,7 @@ void wins_process_multihomed_name_registration_request( struct subnet_record *su DEBUG(0,("wins_process_multihomed_name_registration_request: broadcast name registration request \ received for name %s from IP %s on subnet %s. Error - should not be sent to WINS server\n", - namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); return; } @@ -989,12 +989,12 @@ received for name %s from IP %s on subnet %s. Error - should not be sent to WINS { DEBUG(0,("wins_process_multihomed_name_registration_request: group name registration request \ received for name %s from IP %s on subnet %s. Errror - group names should not be multihomed.\n", - namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); return; } DEBUG(3,("wins_process_multihomed_name_registration_request: name registration for name %s \ -IP %s\n", namestr(question), inet_ntoa(from_ip) )); +IP %s\n", nmb_namestr(question), inet_ntoa(from_ip) )); /* * Deal with policy regarding 0x1d names. @@ -1003,7 +1003,7 @@ IP %s\n", namestr(question), inet_ntoa(from_ip) )); if(question->name_type == 0x1d) { DEBUG(3,("wins_process_multihomed_name_registration_request: Ignoring request \ -to register name %s from IP %s.", namestr(question), inet_ntoa(p->ip) )); +to register name %s from IP %s.", nmb_namestr(question), inet_ntoa(p->ip) )); send_wins_name_registration_response(0, ttl, p); return; } @@ -1025,7 +1025,7 @@ to register name %s from IP %s.", namestr(question), inet_ntoa(p->ip) )); || (namerec->data.source == DNSFAIL_NAME) ) ) { DEBUG(5,("wins_process_multihomed_name_registration_request: Name (%s) in WINS was a dns lookup \ -- removing it.\n", namestr(question) )); +- removing it.\n", nmb_namestr(question) )); remove_name_from_namelist( subrec, namerec); namerec = NULL; } @@ -1039,7 +1039,7 @@ to register name %s from IP %s.", namestr(question), inet_ntoa(p->ip) )); { DEBUG( 3, ( "wins_process_multihomed_name_registration_request: Attempt \ to register name %s. Name already exists in WINS with source type %d.\n", - namestr(question), namerec->data.source )); + nmb_namestr(question), namerec->data.source )); send_wins_name_registration_response(RFS_ERR, 0, p); return; } @@ -1051,7 +1051,7 @@ to register name %s. Name already exists in WINS with source type %d.\n", if((namerec != NULL) && NAME_GROUP(namerec)) { DEBUG(3,("wins_process_multihomed_name_registration_request: Attempt to register name %s. Name \ -already exists in WINS as a GROUP name.\n", namestr(question) )); +already exists in WINS as a GROUP name.\n", nmb_namestr(question) )); send_wins_name_registration_response(RFS_ERR, 0, p); return; } @@ -1072,7 +1072,7 @@ already exists in WINS as a GROUP name.\n", namestr(question) )); if(!ismyip(from_ip)) { DEBUG(3,("wins_process_multihomed_name_registration_request: Attempt to register name %s. Name \ -is one of our (WINS server) names. Denying registration.\n", namestr(question) )); +is one of our (WINS server) names. Denying registration.\n", nmb_namestr(question) )); send_wins_name_registration_response(RFS_ERR, 0, p); return; } @@ -1310,7 +1310,7 @@ void wins_process_name_query_request(struct subnet_record *subrec, struct name_record *namerec = NULL; DEBUG(3,("wins_process_name_query: name query for name %s from IP %s\n", - namestr(question), inet_ntoa(p->ip) )); + nmb_namestr(question), inet_ntoa(p->ip) )); /* * Special name code. If the queried name is *<1b> then search @@ -1336,7 +1336,7 @@ void wins_process_name_query_request(struct subnet_record *subrec, if( namerec->data.source == DNSFAIL_NAME ) { DEBUG(3,("wins_process_name_query: name query for name %s returning DNS fail.\n", - namestr(question) )); + nmb_namestr(question) )); send_wins_name_query_response(NAM_ERR, p, namerec); return; } @@ -1349,13 +1349,13 @@ void wins_process_name_query_request(struct subnet_record *subrec, && (namerec->data.death_time < p->timestamp) ) { DEBUG(3,("wins_process_name_query: name query for name %s - name expired. Returning fail.\n", - namestr(question) )); + nmb_namestr(question) )); send_wins_name_query_response(NAM_ERR, p, namerec); return; } DEBUG(3,("wins_process_name_query: name query for name %s returning first IP %s.\n", - namestr(question), inet_ntoa(namerec->data.ip[0]) )); + nmb_namestr(question), inet_ntoa(namerec->data.ip[0]) )); send_wins_name_query_response(0, p, namerec); return; @@ -1370,7 +1370,7 @@ void wins_process_name_query_request(struct subnet_record *subrec, { DEBUG(3,("wins_process_name_query: name query for name %s not found - doing dns lookup.\n", - namestr(question) )); + nmb_namestr(question) )); queue_dns_query(p, question, &namerec); return; @@ -1430,12 +1430,12 @@ void wins_process_name_release_request(struct subnet_record *subrec, DEBUG(0,("wins_process_name_release_request: broadcast name registration request \ received for name %s from IP %s on subnet %s. Error - should not be sent to WINS server\n", - namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); return; } DEBUG(3,("wins_process_name_release_request: %s name release for name %s \ -IP %s\n", releasing_group_name ? "Group" : "Unique", namestr(question), inet_ntoa(from_ip) )); +IP %s\n", releasing_group_name ? "Group" : "Unique", nmb_namestr(question), inet_ntoa(from_ip) )); /* * Deal with policy regarding 0x1d names. @@ -1444,7 +1444,7 @@ IP %s\n", releasing_group_name ? "Group" : "Unique", namestr(question), inet_nto if(!releasing_group_name && (question->name_type == 0x1d)) { DEBUG(3,("wins_process_name_release_request: Ignoring request \ -to release name %s from IP %s.", namestr(question), inet_ntoa(p->ip) )); +to release name %s from IP %s.", nmb_namestr(question), inet_ntoa(p->ip) )); send_wins_name_release_response(0, p); return; } @@ -1483,7 +1483,7 @@ to release name %s from IP %s.", namestr(question), inet_ntoa(p->ip) )); { DEBUG(3,("wins_process_name_release_request: Refusing request to \ release name %s as IP %s is not one of the known IP's for this name.\n", - namestr(question), inet_ntoa(from_ip) )); + nmb_namestr(question), inet_ntoa(from_ip) )); send_wins_name_release_response(NAM_ERR, p); return; } @@ -1576,7 +1576,7 @@ void wins_write_database(BOOL background) int i; struct tm *tm; - DEBUGADD(4,("%-19s ", namestr(&namerec->name) )); + DEBUGADD(4,("%-19s ", nmb_namestr(&namerec->name) )); if( namerec->data.death_time != PERMANENT_TTL ) { diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index ac25127e82..2546b848a8 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -236,7 +236,7 @@ static void fail_register(struct subnet_record *subrec, struct response_record * struct nmb_name *nmbname) { DEBUG(0,("fail_register: Failed to register name %s on subnet %s.\n", - namestr(nmbname), subrec->subnet_name)); + nmb_namestr(nmbname), subrec->subnet_name)); } /**************************************************************************** -- cgit From 74d539f5573a3ed3ff1b96c54752a389da4c3e14 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Tue, 17 Nov 1998 16:19:04 +0000 Subject: - group database API. oops and oh dear, the threat has been carried out: the pre-alpha "domain group" etc parameters have disappeared. - interactive debug detection - re-added mem_man (andrew's memory management, detects memory corruption) - american spellings of "initialise" replaced with english spelling of "initialise". - started on "lookup_name()" and "lookup_sid()" functions. proper ones. - moved lots of functions around. created some modules of commonly used code. e.g the password file locking code, which is used in groupfile.c and aliasfile.c and smbpass.c - moved RID_TYPE_MASK up another bit. this is really unfortunate, but there is no other "fast" way to identify users from groups from aliases. i do not believe that this code saves us anything (the multipliers) and puts us at a disadvantage (reduces the useable rid space). the designers of NT aren't silly: if they can get away with a user- interface-speed LsaLookupNames / LsaLookupSids, then so can we. i spoke with isaac at the cifs conference, the only time for example that they do a security context check is on file create. certainly not on individual file reads / writes, which would drastically hit their performance and ours, too. - renamed myworkgroup to global_sam_name, amongst other things, when used in the rpc code. there is also a global_member_name, as we are always responsible for a SAM database, the scope of which is limited by the role of the machine (e.g if a member of a workgroup, your SAM is for _local_ logins only, and its name is the name of your server. you even still have a SID. see LsaQueryInfoPolicy, levels 3 and 5). - updated functionality of groupname.c to be able to cope with names like DOMAIN\group and SERVER\alias. used this code to be able to do aliases as well as groups. this code may actually be better off being used in username mapping, too. - created a connect to serverlist function in clientgen.c and used it in password.c - initialisation in server.c depends on the role of the server. well, it does now. - rpctorture. smbtorture. EXERCISE EXTREME CAUTION. (This used to be commit 0d21e1e6090b933f396c764af535ca3388a562db) --- source3/nmbd/nmbd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index d7ce42dae2..2c9dd13274 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -567,7 +567,7 @@ static void usage(char *pname) charset_initialise(); - if(!initialize_password_db()) + if(!initialise_password_db()) exit(1); #ifdef LMHOSTSFILE @@ -593,11 +593,11 @@ static void usage(char *pname) SIGUSR1 and SIGUSR2 to do debug level changes. */ #ifndef MEM_MAN #if defined(SIGUSR1) - CatchSignal( SIGUSR1, SIGNAL_CAST sig_usr1 ); + CatchSignal( SIGUSR1, SIGNAL_CAST sig_usr1 ); #endif /* SIGUSR1 */ #if defined(SIGUSR2) - CatchSignal( SIGUSR2, SIGNAL_CAST sig_usr2 ); + CatchSignal( SIGUSR2, SIGNAL_CAST sig_usr2 ); #endif /* SIGUSR2 */ #endif /* MEM_MAN */ -- cgit From 768761820e8d7481c586c4e0ab4ac7cb36d18c4b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 17 Nov 1998 20:50:07 +0000 Subject: Added the same open()/fopen()/creat()/mmap() -> sys_XXX calls. Tidied up some of the mess (no other word for it). Still doesn't compile cleanly. There are calls with incorrect parameters that don't seem to be doing the right thing. This code still needs surgery :-(. Jeremy. (This used to be commit 18ff93a9abbf68ee8c59c0af3e57c63e4a015dac) --- source3/nmbd/nmbd_namelistdb.c | 2 +- source3/nmbd/nmbd_serverlistdb.c | 2 +- source3/nmbd/nmbd_synclists.c | 4 ++-- source3/nmbd/nmbd_winsserver.c | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 1493c87f8a..8d6d139867 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -611,7 +611,7 @@ void dump_all_namelists(void) pstrcat(fname,"/"); pstrcat(fname,"namelist.debug"); - fp = fopen(fname,"w"); + fp = sys_fopen(fname,"w"); if (!fp) { diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index cf7295ee11..d30e8da64c 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -345,7 +345,7 @@ void write_browse_list(time_t t, BOOL force_write) pstrcpy(fnamenew,fname); pstrcat(fnamenew,"."); - fp = fopen(fnamenew,"w"); + fp = sys_fopen(fnamenew,"w"); if (!fp) { diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 8dee5ca4f2..dae25b6eca 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -161,7 +161,7 @@ void sync_browse_lists(struct work_record *work, DEBUG(2,("Initiating browse sync for %s to %s(%s)\n", work->work_group, name, inet_ntoa(ip))); - fp = fopen(s->fname,"w"); + fp = sys_fopen(s->fname,"w"); if (!fp) _exit(1); sync_child(name, nm_type, work->work_group, ip, local, servers, @@ -239,7 +239,7 @@ static void complete_sync(struct sync_record *s) char *ptr; int count=0; - f = fopen(s->fname,"r"); + f = sys_fopen(s->fname,"r"); if (!f) return; diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 0906715af4..35ca5af62c 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -157,7 +157,7 @@ BOOL initialise_wins(void) pstrcat(fname,"/"); pstrcat(fname,WINS_LIST); - if((fp = fopen(fname,"r")) == NULL) + if((fp = sys_fopen(fname,"r")) == NULL) { DEBUG(2,("initialise_wins: Can't open wins database file %s. Error was %s\n", fname, strerror(errno) )); @@ -1555,7 +1555,7 @@ void wins_write_database(BOOL background) string_sub(fname,"//", "/"); slprintf(fnamenew,sizeof(fnamenew),"%s.%u", fname, (unsigned int)getpid()); - if((fp = fopen(fnamenew,"w")) == NULL) + if((fp = sys_fopen(fnamenew,"w")) == NULL) { DEBUG(0,("wins_write_database: Can't open %s. Error was %s\n", fnamenew, strerror(errno))); if (background) { -- cgit From 30038de4623bc827ee8019c569faf00583d1fe58 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Sun, 29 Nov 1998 20:03:33 +0000 Subject: weekend work. user / group database API. - split sam_passwd and smb_passwd into separate higher-order function tables - renamed struct smb_passwd's "smb_user" to "unix_user". added "nt_user" plus user_rid, and added a "wrap" function in both sam_passwd and smb_passwd password databases to fill in the blank entries that are not obtained from whatever password database API instance is being used. NOTE: whenever a struct smb_passwd or struct sam_passwd is used, it MUST be initialised with pwdb_sam_init() or pwd_smb_init(), see chgpasswd.c for the only example outside of the password database APIs i could find. - added query_useraliases code to rpcclient. - dealt with some nasty interdependencies involving non-smbd programs and the password database API. this is still not satisfactorily resolved completelely, but it's the best i can do for now. - #ifdef'd out some password database options so that people don't mistakenly set them unless they recompile to _use_ those options. lots of debugging done, it's still not finished. the unix/NT uid/gid and user-rid/group-rid issues are better, but not perfect. the "BUILTIN" domain is still missing: users cannot be added to "BUILTIN" groups yet, as we only have an "alias" db API and a "group" db API but not "builtin-alias" db API... (This used to be commit 5d5d7e4de7d1514ab87b07ede629de8aa00519a1) --- source3/nmbd/nmbd.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 2c9dd13274..bfcf0ad239 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -1,7 +1,7 @@ /* - Unix SMB/Netbios implementation. + Unix SMB/NetBIOS implementation. Version 1.9. - NBT netbios routines and daemon - version 2 + NBT NetBIOS routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 This program is free software; you can redistribute it and/or modify @@ -509,7 +509,7 @@ static BOOL init_structs(void) *p = 0; strlower( local_machine ); - DEBUG( 5, ("Netbios name list:-\n") ); + DEBUG( 5, ("NetBIOS name list:-\n") ); for( n=0; my_netbios_names[n]; n++ ) DEBUGADD( 5, ( "my_netbios_names[%d]=\"%s\"\n", n, my_netbios_names[n] ) ); @@ -567,9 +567,6 @@ static void usage(char *pname) charset_initialise(); - if(!initialise_password_db()) - exit(1); - #ifdef LMHOSTSFILE pstrcpy( host_file, LMHOSTSFILE ); #endif @@ -661,7 +658,7 @@ static void usage(char *pname) reopen_logs(); - DEBUG( 1, ( "Netbios nameserver version %s started.\n", VERSION ) ); + DEBUG( 1, ( "NetBIOS nameserver version %s started.\n", VERSION ) ); DEBUGADD( 1, ( "Copyright Andrew Tridgell 1994-1998\n" ) ); if( !get_myname( myhostname, NULL) ) @@ -680,13 +677,17 @@ static void usage(char *pname) reload_services( True ); - fstrcpy( global_myworkgroup, lp_workgroup() ); - - if (strequal(global_myworkgroup,"*")) - { - DEBUG(0,("ERROR: a workgroup name of * is no longer supported\n")); - exit(1); - } + if (!pwdb_initialise()) + { + exit(1); + } + + if (!get_member_domain_sid()) + { + DEBUG(0,("ERROR: Samba cannot obtain PDC SID from PDC(s) %s.\n", + lp_passwordserver())); + exit(1); + } set_samba_nb_type(); -- cgit From 04e382fb166a64de193dc3c7b21187d8382eaeea Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Tue, 1 Dec 1998 19:10:44 +0000 Subject: rpc_samr.h parse_samr.c srv_samr.c : samr_query_aliasmembers (cool!) util_pwdb.c sids.c nmbd.c server.c smbpasswd.c swat.c : pwdb_initialise(BOOL is_server) now creates / reads DOMAIN_NAME.SID if is_server is True, and does LsaQueryInfoPolicy(levels 3 and 5) to obtain member and pdc sids. (This used to be commit 3e1eb4f26b67e484b05e1dde94fd4e4dae982631) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index bfcf0ad239..46c24aee7d 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -677,7 +677,7 @@ static void usage(char *pname) reload_services( True ); - if (!pwdb_initialise()) + if (!pwdb_initialise(True)) { exit(1); } -- cgit From 8d08fb732349e50d287aa864fbf57ecc51b55562 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Thu, 3 Dec 1998 17:38:20 +0000 Subject: jean-f spotted race condition on generation of sam sid, from starting nmbd and smbd. nmbd is now client: smbd is solely responsible for creating sam_name.SID (This used to be commit 50fa4822df679b4d54b5a868179594ec087e811f) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 46c24aee7d..a81f9e4bfe 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -677,7 +677,7 @@ static void usage(char *pname) reload_services( True ); - if (!pwdb_initialise(True)) + if (!pwdb_initialise(False)) { exit(1); } -- cgit From cfba976fc234a4b9f1712d42dca405b25b314401 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 9 Dec 1998 06:35:37 +0000 Subject: removed the SID stuff from the head branch as well. This allows the removal of PASSDB_OBJ, RPC_CLIENT_OBJ and RPC_PARSE_OBJ from nmbd in the head branch. so nmbd just went on a diet :) (This used to be commit be697c9ef00f1b6366228dcdd3983d68158dd94f) --- source3/nmbd/nmbd.c | 12 ------------ source3/nmbd/nmbd_processlogon.c | 28 +++++----------------------- 2 files changed, 5 insertions(+), 35 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index a81f9e4bfe..d44fe5507c 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -677,18 +677,6 @@ static void usage(char *pname) reload_services( True ); - if (!pwdb_initialise(False)) - { - exit(1); - } - - if (!get_member_domain_sid()) - { - DEBUG(0,("ERROR: Samba cannot obtain PDC SID from PDC(s) %s.\n", - lp_passwordserver())); - exit(1); - } - set_samba_nb_type(); if (!is_daemon && !is_a_socket(0)) diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 3f519ecfc9..4281068341 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -44,7 +44,6 @@ void process_logon_packet(struct packet_struct *p,char *buf,int len, pstring outbuf; int code; uint16 token = 0; - uint32 ntversion; uint16 lmnttoken; uint16 lm20token; @@ -53,7 +52,6 @@ void process_logon_packet(struct packet_struct *p,char *buf,int len, char *uniuser; /* Unicode user name. */ pstring ascuser; char *unicomp; /* Unicode computer name. */ - struct smb_passwd *smb_pass; /* To check if machine account exists */ memset(outbuf, 0, sizeof(outbuf)); @@ -196,7 +194,8 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", DEBUG(3,("process_logon_packet: SAMLOGON sidsize %d ntv %d\n", domainsidsize, ntversion)); /* - * If MACHINE$ is in our password database then respond, else ignore. + * we respond regadless of whether the machine is in our password + * database. If it isn't then we let smbd send an appropriate error. * Let's ignore the SID. */ @@ -206,26 +205,9 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", fstrcpy(reply_name,"\\\\"); /* Here it wants \\LOGONSERVER. */ fstrcpy(reply_name+2,my_name); - smb_pass = getsmbpwnam(ascuser); - - if(!smb_pass ) - { - DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, not in password file\n", - unistr(unicomp),inet_ntoa(p->ip), ascuser)); - return; - } - else if(smb_pass->acct_ctrl & ACB_DISABLED) - { - DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, accound disabled.\n", - unistr(unicomp),inet_ntoa(p->ip), ascuser)); - return; - } - else - { - DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n", - unistr(unicomp),inet_ntoa(p->ip), ascuser, reply_name, global_myworkgroup, - SAMLOGON_R ,lmnttoken)); - } + DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n", + unistr(unicomp),inet_ntoa(p->ip), ascuser, reply_name, global_myworkgroup, + SAMLOGON_R ,lmnttoken)); /* Construct reply. */ -- cgit From 1f989cda944f21b3ba829e1008f1189d2d3671a8 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 9 Dec 1998 16:23:57 +0000 Subject: need to initialise global_myworkgroup (This used to be commit 501617307f3b9bbad76406d00b1bc82f5cb479a6) --- source3/nmbd/nmbd.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index d44fe5507c..c266043c2c 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -677,6 +677,11 @@ static void usage(char *pname) reload_services( True ); + if (!pwdb_init_myworkgroup()) + { + exit(1); + } + set_samba_nb_type(); if (!is_daemon && !is_a_socket(0)) -- cgit From 58a0cbc0c842187d68872fe021b2ce68a13a12eb Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 9 Dec 1998 16:30:37 +0000 Subject: oops, util_pwdb.c appears to be included in PASSDB_OBJ not LIB_OBJ. (This used to be commit ca10eb44909e66a07dc7f88b0a740390f9ec3922) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index c266043c2c..1471254b4e 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -677,7 +677,7 @@ static void usage(char *pname) reload_services( True ); - if (!pwdb_init_myworkgroup()) + if (!init_myworkgroup()) { exit(1); } -- cgit From 3e7039349fa79cc16cd3a2ece79b63b0fffbb616 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 17 Dec 1998 21:41:28 +0000 Subject: Fix bug with nmbd running wild due to recursion in retransmit_or_expire_response_records(). Jeremy. (This used to be commit d5f05b4faef50e7cfc0ed05a87d92e14102106c6) --- source3/nmbd/nmbd_packets.c | 33 ++++++++++++++++++++++++--------- source3/nmbd/nmbd_responserecordsdb.c | 3 +++ 2 files changed, 27 insertions(+), 9 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index ce785b40a4..7f27753352 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1633,16 +1633,31 @@ to IP %s on subnet %s\n", rrec->response_id, inet_ntoa(rrec->packet->ip), on subnet %s\n", rrec->response_id, inet_ntoa(rrec->packet->ip), subrec->subnet_name)); - /* Call the timeout function. This will deal with removing the - timed out packet. */ - if(rrec->timeout_fn) - (*rrec->timeout_fn)(subrec, rrec); - else + /* + * Check the flag in this record to prevent recursion if we end + * up in this function again via the timeout function call. + */ + + if(!rrec->in_expiration_processing) { - /* We must remove the record ourself if there is - no timeout function. */ - remove_response_record(subrec, rrec); - } + + /* + * Set the recursion protection flag in this record. + */ + + rrec->in_expiration_processing = True; + + /* Call the timeout function. This will deal with removing the + timed out packet. */ + if(rrec->timeout_fn) + (*rrec->timeout_fn)(subrec, rrec); + else + { + /* We must remove the record ourself if there is + no timeout function. */ + remove_response_record(subrec, rrec); + } + } /* !rrec->in_expitation_processing */ } /* rrec->repeat_count > 0 */ } /* rrec->repeat_time <= t */ } /* end for rrec */ diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index 3edca69981..0c698760bb 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -172,6 +172,9 @@ struct response_record *make_response_record( struct subnet_record *subrec, rrec->repeat_count = 3; /* 3 retries */ rrec->repeat_time = time(NULL) + rrec->repeat_interval; /* initial retry time */ + /* This packet is not being processed. */ + rrec->in_expiration_processing = False; + /* Lock the packet so we won't lose it while it's on the list. */ p->locked = True; -- cgit From fd96929ec1fa27e0affd4c4e9ba307c4ee30b978 Mon Sep 17 00:00:00 2001 From: Matthew Chapman Date: Fri, 12 Feb 1999 00:16:09 +0000 Subject: UNICODE cleanup (see lib/util_unistr.c). No more ugly static library buffers and all functions take a destination string length (especially unistrcpy was rather dangerous; we were only saved by the fact that datagrams are limited in size). (This used to be commit a1d39af1ce1d451b811dbd7c2ba391214851b87e) --- source3/nmbd/nmbd_processlogon.c | 41 ++++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 4281068341..67678db069 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -50,7 +50,6 @@ void process_logon_packet(struct packet_struct *p,char *buf,int len, uint32 domainsidsize; char *getdc; char *uniuser; /* Unicode user name. */ - pstring ascuser; char *unicomp; /* Unicode computer name. */ memset(outbuf, 0, sizeof(outbuf)); @@ -118,7 +117,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); q = align2(unicomp, buf); - q = skip_unicode_string(q, 1); + q = skip_unibuf(q, buf+len-q); ntversion = IVAL(q, 0); q += 4; @@ -140,10 +139,9 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); if (strcmp(mailslot, NT_LOGON_MAILSLOT)==0) { q = align2(q, buf); - PutUniCode(q, my_name); /* PDC name */ - q = skip_unicode_string(q, 1); - PutUniCode(q, global_myworkgroup); /* Domain name*/ - q = skip_unicode_string(q, 1); + /* PDC and domain name */ + q = ascii_to_unibuf(q, my_name, outbuf+sizeof(outbuf)-q); + q = ascii_to_unibuf(q, global_myworkgroup, outbuf+sizeof(outbuf)-q); SIVAL(q, 0, ntversion); q += 4; @@ -177,8 +175,8 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += 2; unicomp = q; - uniuser = skip_unicode_string(unicomp,1); - getdc = skip_unicode_string(uniuser,1); + uniuser = skip_unibuf(unicomp, buf+len-q); + getdc = skip_unibuf(uniuser, buf+len-q); q = skip_string(getdc,1); q += 4; domainsidsize = IVAL(q, 0); @@ -199,15 +197,20 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", * Let's ignore the SID. */ - pstrcpy(ascuser, unistr(uniuser)); - DEBUG(3,("process_logon_packet: SAMLOGON user %s\n", ascuser)); - fstrcpy(reply_name,"\\\\"); /* Here it wants \\LOGONSERVER. */ fstrcpy(reply_name+2,my_name); - DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n", - unistr(unicomp),inet_ntoa(p->ip), ascuser, reply_name, global_myworkgroup, - SAMLOGON_R ,lmnttoken)); + if (DEBUGLVL(3)) { + fstring ascuser; + fstring asccomp; + + unibuf_to_ascii(ascuser, uniuser, sizeof(ascuser)); + unibuf_to_ascii(asccomp, unicomp, sizeof(asccomp)); + + DEBUGADD(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n", + asccomp,inet_ntoa(p->ip), ascuser, reply_name, + global_myworkgroup, SAMLOGON_R, lmnttoken)); + } /* Construct reply. */ @@ -215,12 +218,10 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", SSVAL(q, 0, SAMLOGON_R); q += 2; - PutUniCode(q, reply_name); - q = skip_unicode_string(q, 1); - unistrcpy(q, uniuser); - q = skip_unicode_string(q, 1); /* User name (workstation trust account) */ - PutUniCode(q, lp_workgroup()); - q = skip_unicode_string(q, 1); /* Domain name. */ + /* Logon server, trust account, domain */ + q = ascii_to_unibuf(q, reply_name, outbuf+sizeof(outbuf)-q); + q = uni_strncpy(q, uniuser, outbuf+sizeof(outbuf)-q); + q = ascii_to_unibuf(q, lp_workgroup(), outbuf+sizeof(outbuf)-q); SIVAL(q, 0, ntversion); q += 4; -- cgit From 2737f26ad64ee32d6ef7365dcce0a3eb881f99db Mon Sep 17 00:00:00 2001 From: Matthew Chapman Date: Mon, 15 Feb 1999 05:33:30 +0000 Subject: Always null-terminate strings. Also some string length and sizeof(pointer) corrections. (This used to be commit ce24191939b82985d09eabe945199f38b0fea486) --- source3/nmbd/nmbd_processlogon.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 67678db069..98ce8a680a 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -140,8 +140,8 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); q = align2(q, buf); /* PDC and domain name */ - q = ascii_to_unibuf(q, my_name, outbuf+sizeof(outbuf)-q); - q = ascii_to_unibuf(q, global_myworkgroup, outbuf+sizeof(outbuf)-q); + q = ascii_to_unibuf(q, my_name, outbuf+sizeof(outbuf)-q-2); + q = ascii_to_unibuf(q, global_myworkgroup, outbuf+sizeof(outbuf)-q-2); SIVAL(q, 0, ntversion); q += 4; @@ -204,8 +204,8 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", fstring ascuser; fstring asccomp; - unibuf_to_ascii(ascuser, uniuser, sizeof(ascuser)); - unibuf_to_ascii(asccomp, unicomp, sizeof(asccomp)); + unibuf_to_ascii(ascuser, uniuser, sizeof(ascuser)-1); + unibuf_to_ascii(asccomp, unicomp, sizeof(asccomp)-1); DEBUGADD(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n", asccomp,inet_ntoa(p->ip), ascuser, reply_name, @@ -219,9 +219,9 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += 2; /* Logon server, trust account, domain */ - q = ascii_to_unibuf(q, reply_name, outbuf+sizeof(outbuf)-q); - q = uni_strncpy(q, uniuser, outbuf+sizeof(outbuf)-q); - q = ascii_to_unibuf(q, lp_workgroup(), outbuf+sizeof(outbuf)-q); + q = ascii_to_unibuf(q, reply_name, outbuf+sizeof(outbuf)-q-2); + q = uni_strncpy(q, uniuser, outbuf+sizeof(outbuf)-q-2); + q = ascii_to_unibuf(q, lp_workgroup(), outbuf+sizeof(outbuf)-q-2); SIVAL(q, 0, ntversion); q += 4; -- cgit From aecbc5b5d37690f145c42ed834a58565c12db6d3 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Tue, 9 Mar 1999 01:20:08 +0000 Subject: oh dear, it's this one again. removed check for MAILSLOT\NTLOGON because it's wrong. i've seen a packet from nt client on MAILSLOT\NETLOGON with appended undocumented unicode tacked on the end and the response contained undocumented unicode tacked on the end. (This used to be commit 74c7d626cd85189c902489d220c3eca30a4b1bb1) --- source3/nmbd/nmbd_processlogon.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 98ce8a680a..5b8e01f5d0 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -136,20 +136,18 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); fstrcpy(q, reply_name); q = skip_string(q, 1); /* PDC name */ - if (strcmp(mailslot, NT_LOGON_MAILSLOT)==0) { - q = align2(q, buf); - - /* PDC and domain name */ - q = ascii_to_unibuf(q, my_name, outbuf+sizeof(outbuf)-q-2); - q = ascii_to_unibuf(q, global_myworkgroup, outbuf+sizeof(outbuf)-q-2); - - SIVAL(q, 0, ntversion); - q += 4; - SSVAL(q, 0, lmnttoken); - q += 2; - SSVAL(q, 0, lm20token); - q += 2; - } + q = align2(q, buf); + + /* PDC and domain name */ + q = ascii_to_unibuf(q, my_name, outbuf+sizeof(outbuf)-q-2); + q = ascii_to_unibuf(q, global_myworkgroup, outbuf+sizeof(outbuf)-q-2); + + SIVAL(q, 0, ntversion); + q += 4; + SSVAL(q, 0, lmnttoken); + q += 2; + SSVAL(q, 0, lm20token); + q += 2; DEBUG(3,("process_logon_packet: GETDC request from %s at IP %s, \ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", -- cgit From a3c6e96a22bfaaa5a2993e85327555266476013d Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Tue, 9 Mar 1999 01:21:57 +0000 Subject: mods to allow inter-domain trust accounts to be added to SAM database using smbpasswd command. (This used to be commit 62d499f83256c6e8b3308dc4bd8e9f5df873b14b) --- source3/nmbd/nmbd_packets.c | 55 ++++----------------------------------------- 1 file changed, 4 insertions(+), 51 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 7f27753352..a9803b363f 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -90,43 +90,6 @@ void set_nb_flags(char *buf, uint16 nb_flags) *buf = '\0'; } -/*************************************************************************** -Dumps out the browse packet data. -**************************************************************************/ - -static void debug_browse_data(char *outbuf, int len) -{ - int i,j; - - DEBUG( 4, ( "debug_browse_data():\n" ) ); - for (i = 0; i < len; i+= 16) - { - DEBUGADD( 4, ( "%3x char ", i ) ); - - for (j = 0; j < 16; j++) - { - unsigned char x = outbuf[i+j]; - if (x < 32 || x > 127) - x = '.'; - - if (i+j >= len) - break; - DEBUGADD( 4, ( "%c", x ) ); - } - - DEBUGADD( 4, ( "%*s hex", 16-j, "" ) ); - - for (j = 0; j < 16; j++) - { - if (i+j >= len) - break; - DEBUGADD( 4, ( " %02x", (unsigned char)outbuf[i+j] ) ); - } - - DEBUGADD( 4, ("\n") ); - } -} - /*************************************************************************** Generates the unique transaction identifier **************************************************************************/ @@ -1041,37 +1004,31 @@ mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, scop { case ANN_HostAnnouncement: { - debug_browse_data(buf, len); process_host_announce(subrec, p, buf+1); break; } case ANN_DomainAnnouncement: { - debug_browse_data(buf, len); process_workgroup_announce(subrec, p, buf+1); break; } case ANN_LocalMasterAnnouncement: { - debug_browse_data(buf, len); process_local_master_announce(subrec, p, buf+1); break; } case ANN_AnnouncementRequest: { - debug_browse_data(buf, len); process_announce_request(subrec, p, buf+1); break; } case ANN_Election: { - debug_browse_data(buf, len); process_election(subrec, p, buf+1); break; } case ANN_GetBackupListReq: { - debug_browse_data(buf, len); /* This is one occasion where we change a subnet that is given to us. If the packet was sent to WORKGROUP<1b> instead @@ -1086,7 +1043,6 @@ mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, scop } case ANN_GetBackupListResp: { - debug_browse_data(buf, len); /* We never send ANN_GetBackupListReq so we should never get these. */ DEBUG(0,("process_browse_packet: Discarding GetBackupListResponse \ @@ -1095,7 +1051,6 @@ packet from %s IP %s\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip))); } case ANN_ResetBrowserState: { - debug_browse_data(buf, len); process_reset_browser(subrec, p, buf+1); break; } @@ -1105,7 +1060,6 @@ packet from %s IP %s\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip))); on the unicast subnet. */ subrec = unicast_subnet; - debug_browse_data(buf, len); process_master_browser_announce(subrec, p, buf+1); break; } @@ -1114,7 +1068,6 @@ packet from %s IP %s\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip))); /* * We don't currently implement this. Log it just in case. */ - debug_browse_data(buf, len); DEBUG(10,("process_browse_packet: On subnet %s ignoring browse packet \ command ANN_BecomeBackup from %s IP %s to %s\n", subrec->subnet_name, nmb_namestr(&dgram->source_name), @@ -1123,7 +1076,6 @@ command ANN_BecomeBackup from %s IP %s to %s\n", } default: { - debug_browse_data(buf, len); DEBUG(0,("process_browse_packet: On subnet %s ignoring browse packet \ command code %d from %s IP %s to %s\n", subrec->subnet_name, command, nmb_namestr(&dgram->source_name), @@ -1162,7 +1114,7 @@ mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, scop { case ANN_HostAnnouncement: { - debug_browse_data(buf, len); + dump_data(4, buf, len); process_lm_host_announce(subrec, p, buf+1); break; } @@ -1247,10 +1199,11 @@ static void process_dgram(struct packet_struct *p) nmb_namestr(&dgram->source_name),nmb_namestr(&dgram->dest_name), inet_ntoa(p->ip), smb_buf(buf),CVAL(buf2,0),len)); - if (len <= 0) return; + dump_data(100, buf2, len); + /* Datagram packet received for the browser mailslot */ if (strequal(smb_buf(buf),BROWSE_MAILSLOT)) { @@ -1958,7 +1911,7 @@ BOOL send_mailslot(BOOL unique, char *mailslot,char *buf,int len, nmb_namestr(&dgram->source_name), inet_ntoa(src_ip))); DEBUG(4,("to %s IP %s\n", nmb_namestr(&dgram->dest_name), inet_ntoa(dest_ip))); - debug_browse_data(buf, len); + dump_data(4, buf, len); if(loopback_this_packet) { -- cgit From 60bfe3819eb92da021218987467b2ff101b094dd Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Tue, 9 Mar 1999 02:03:39 +0000 Subject: alignment issue in UDP SAMLOGON response. (This used to be commit de290627f06915d420d37d2a3ac2f736c4cf8d74) --- source3/nmbd/nmbd_processlogon.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 5b8e01f5d0..710bbe0de7 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -179,7 +179,9 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += 4; domainsidsize = IVAL(q, 0); q += 4; - q += domainsidsize + 3; + q += domainsidsize + 2; + q = align2(q, buf); + ntversion = IVAL(q, 0); q += 4; lmnttoken = SVAL(q, 0); @@ -187,7 +189,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", lm20token = SVAL(q, 0); q += 2; - DEBUG(3,("process_logon_packet: SAMLOGON sidsize %d ntv %d\n", domainsidsize, ntversion)); + DEBUG(3,("process_logon_packet: SAMLOGON sidsize %d ntv %x\n", domainsidsize, ntversion)); /* * we respond regadless of whether the machine is in our password @@ -198,7 +200,8 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", fstrcpy(reply_name,"\\\\"); /* Here it wants \\LOGONSERVER. */ fstrcpy(reply_name+2,my_name); - if (DEBUGLVL(3)) { + if (DEBUGLVL(3)) + { fstring ascuser; fstring asccomp; -- cgit From 7f913623be602be833eb8668e60734e2758cb9a1 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 17 Mar 1999 19:48:29 +0000 Subject: alignment issue for UDP SAMLOGON response. (This used to be commit 9d01e9d86a8d22a283a8377a12bb175398547d78) --- source3/nmbd/nmbd_processlogon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 710bbe0de7..fb5dec29f9 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -179,8 +179,8 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += 4; domainsidsize = IVAL(q, 0); q += 4; - q += domainsidsize + 2; - q = align2(q, buf); + q += domainsidsize; + q = align4(q, buf); ntversion = IVAL(q, 0); q += 4; -- cgit From 5a6db490ea56d6492f268b8c5fbc2bc017ba87b6 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 17 Mar 1999 21:35:10 +0000 Subject: SAMLOGON query - alignment issue is beginning to get to me. (This used to be commit baf55934dc5118f8c423fe05c0e4b8d7c018fa14) --- source3/nmbd/nmbd_processlogon.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index fb5dec29f9..6b56aed5b2 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -180,7 +180,9 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", domainsidsize = IVAL(q, 0); q += 4; q += domainsidsize; + q = align4(q, buf); + q += 2; ntversion = IVAL(q, 0); q += 4; -- cgit From 9c2520e6cdf8951f6f6645af91915fac67b49d19 Mon Sep 17 00:00:00 2001 From: Matthew Chapman Date: Sun, 11 Apr 1999 10:23:19 +0000 Subject: Trying to improve DC location & browsing performance for the average user who doesn't know what an LMB or DMB is. * check_master_browser_exists now performs the check the first time around, so if there is indeed no master browser then Samba takes up the job much faster. * Upped default OS level to 32. There is no reason why some stupid little Windows box should become LMB instead of a Samba *server*. * "domain master" now defaults to "auto". Currently this attempts to become DMB iff Samba is the PDC (ala Windows NT). "preferred master" also defaults to "auto", which enables preferred master iff Samba is DMB. * lp_server_role now just returns the predetermined role, rather than working it out each time, since the server role is becoming very heavily used (esp for the BDC code). (This used to be commit 4a23a358b5ad8873acb7db11f27b87d2a016bec1) --- source3/nmbd/nmbd_elections.c | 3 --- source3/nmbd/nmbd_workgroupdb.c | 3 +-- 2 files changed, 1 insertion(+), 5 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 915528b31a..8f876eab0c 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -135,9 +135,6 @@ void check_master_browser_exists(time_t t) struct subnet_record *subrec; char *workgroup_name = global_myworkgroup; - if (!lastrun) - lastrun = t; - if (t < (lastrun + (CHECK_TIME_MST_BROWSE * 60))) return; diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 2546b848a8..0f66b140a8 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -254,8 +254,7 @@ void initiate_myworkgroup_startup(struct subnet_record *subrec, struct work_reco if we are so configured. */ if ((subrec != unicast_subnet) && (subrec != remote_broadcast_subnet) && - (subrec != wins_server_subnet) && lp_preferred_master() && - lp_local_master()) + (subrec != wins_server_subnet) && lp_preferred_master()) { DEBUG(3, ("initiate_myworkgroup_startup: preferred master startup for \ workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name)); -- cgit From 8592314480287edbf98daeab4a979ddec3196b55 Mon Sep 17 00:00:00 2001 From: Matthew Chapman Date: Sun, 8 Aug 1999 04:51:13 +0000 Subject: Fix for Win95 not being able to find PDC (for User/Server Manager, and password change requests), from Michael Stockman . GETDC on \MAILSLOT\NET\NETLOGON necessarily returns less information than the NTLOGON version. (This used to be commit 8a603a8793cb067cd06edc3d73d0b35c427ed5ed) --- source3/nmbd/nmbd_processlogon.c | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 6b56aed5b2..0fc44a40c9 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -136,18 +136,21 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); fstrcpy(q, reply_name); q = skip_string(q, 1); /* PDC name */ - q = align2(q, buf); - /* PDC and domain name */ - q = ascii_to_unibuf(q, my_name, outbuf+sizeof(outbuf)-q-2); - q = ascii_to_unibuf(q, global_myworkgroup, outbuf+sizeof(outbuf)-q-2); - - SIVAL(q, 0, ntversion); - q += 4; - SSVAL(q, 0, lmnttoken); - q += 2; - SSVAL(q, 0, lm20token); - q += 2; + if (strcmp(mailslot, NT_LOGON_MAILSLOT)==0) + { + q = align2(q, buf); + + q = ascii_to_unibuf(q, my_name, outbuf+sizeof(outbuf)-q-2); + q = ascii_to_unibuf(q, global_myworkgroup, outbuf+sizeof(outbuf)-q-2); + + SIVAL(q, 0, ntversion); + q += 4; + SSVAL(q, 0, lmnttoken); + q += 2; + SSVAL(q, 0, lm20token); + q += 2; + } DEBUG(3,("process_logon_packet: GETDC request from %s at IP %s, \ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", -- cgit From b231d2fafaff8dc67ef2dbaec778f716524d4f6a Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Mon, 15 Nov 1999 22:11:10 +0000 Subject: - added DCE/RPC "fault" PDU support. - disabled (AGAIN) the GETDC "if (MAILSLOT\NTLOGON)" code that will get NT5rc2 to work but WILL break win95 (AGAIN). this needs _not_ to be re-enabled but to be replaced with a better mechanism. - added SMBwrite support (note: SMBwriteX already existed) as NT5rc2 is sending DCE/RPC over SMBwrite not SMBwriteX. (This used to be commit 25c70e3c984c4fed19763ed405741e83fe14f87e) --- source3/nmbd/nmbd_processlogon.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 0fc44a40c9..6ddf47fc5f 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -137,7 +137,9 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); q = skip_string(q, 1); /* PDC name */ /* PDC and domain name */ +#if 0 if (strcmp(mailslot, NT_LOGON_MAILSLOT)==0) +#endif { q = align2(q, buf); @@ -179,13 +181,16 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", uniuser = skip_unibuf(unicomp, buf+len-q); getdc = skip_unibuf(uniuser, buf+len-q); q = skip_string(getdc,1); - q += 4; + q += 4; /* skip Account Control Bits */ domainsidsize = IVAL(q, 0); q += 4; - q += domainsidsize; - q = align4(q, buf); - q += 2; + if (domainsidsize != 0) + { + q += domainsidsize; + q += 2; + q = align4(q, buf); + } ntversion = IVAL(q, 0); q += 4; @@ -205,6 +210,10 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", fstrcpy(reply_name,"\\\\"); /* Here it wants \\LOGONSERVER. */ fstrcpy(reply_name+2,my_name); + ntversion = 0x01; + lmnttoken = 0xffff; + lm20token = 0xffff; + if (DEBUGLVL(3)) { fstring ascuser; @@ -221,7 +230,14 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", /* Construct reply. */ q = outbuf; - SSVAL(q, 0, SAMLOGON_R); + if (uniuser[0] == 0) + { + SSVAL(q, 0, SAMLOGON_UNK_R); /* user unknown */ + } + else + { + SSVAL(q, 0, SAMLOGON_R); + } q += 2; /* Logon server, trust account, domain */ -- cgit From ccc8585567804d6a7e6f684a97d58871e2fd9f8a Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Thu, 18 Nov 1999 00:26:11 +0000 Subject: added regqueryval command (experimental) to get reg_io_q_info() and reg_io_r_info() working properly. previously they weren't well understood (well, they were the first of the registry functions i did, back in december 97, ok??? :-) set ntversion to 0x1 in SAMQUERY, so that we reply same as NT4 srv. (This used to be commit 98ddeaf442cb30972cb281bf0489a6e5f7eb2883) --- source3/nmbd/nmbd_processlogon.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 6ddf47fc5f..0c9450b7a2 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -146,6 +146,8 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); q = ascii_to_unibuf(q, my_name, outbuf+sizeof(outbuf)-q-2); q = ascii_to_unibuf(q, global_myworkgroup, outbuf+sizeof(outbuf)-q-2); + ntversion = 0x01; + SIVAL(q, 0, ntversion); q += 4; SSVAL(q, 0, lmnttoken); -- cgit From da517a3ff4c133a1475e8e63054201551d132436 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Thu, 18 Nov 1999 23:15:45 +0000 Subject: responses to UDP samquery go back to SERVER<00> not DOMAIN<1c>, the request name. modified createuser rpcclient command to examine name being added. if it ends in a $, assume that a workstation trust account is being added. (This used to be commit 4aea261cb0e5f34255ff83271eb5cadb0eb78bc9) --- source3/nmbd/nmbd_packets.c | 2 +- source3/nmbd/nmbd_processlogon.c | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index a9803b363f..f10d9a2bc5 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1864,7 +1864,7 @@ BOOL send_mailslot(BOOL unique, char *mailslot,char *buf,int len, /* DIRECT GROUP or UNIQUE datagram. */ dgram->header.msg_type = unique ? 0x10 : 0x11; - dgram->header.flags.node_type = M_NODE; + dgram->header.flags.node_type = M_NODE | 0x40; dgram->header.flags.first = True; dgram->header.flags.more = False; dgram->header.dgm_id = name_trn_id; diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 0c9450b7a2..a515c2706d 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -166,10 +166,10 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", send_mailslot(True, getdc, outbuf,PTR_DIFF(q,outbuf), - dgram->dest_name.name, - dgram->dest_name.name_type, - dgram->source_name.name, - dgram->source_name.name_type, + my_name, + 0x0, + dgram->source_name.name, + dgram->source_name.name_type, p->ip, *iface_ip(p->ip), p->port); return; } @@ -258,10 +258,10 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", send_mailslot(True, getdc, outbuf,PTR_DIFF(q,outbuf), - dgram->dest_name.name, - dgram->dest_name.name_type, - dgram->source_name.name, - dgram->source_name.name_type, + my_name, + 0x0, + dgram->source_name.name, + dgram->source_name.name_type, p->ip, *iface_ip(p->ip), p->port); break; } -- cgit From 161c11e4bcd408064493c063b228aab589fd2a19 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Fri, 19 Nov 1999 01:01:07 +0000 Subject: - bug in nmbd registering DOMAIN_NAME<1c> to WINS server; recursion desired flag MUST be set in any NBT UDP packets sent to a WINS server, else they will go to the WINS client side of the NT NetBIOS kernel instead, and will get trashed. - added \PIPE\browser server-side code. (This used to be commit 8e406c1fa296c3f97b1cd7ddde7b5aeb9232b26e) --- source3/nmbd/nmbd_namelistdb.c | 2 ++ source3/nmbd/nmbd_packets.c | 25 +++++++++++++++++-------- 2 files changed, 19 insertions(+), 8 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 8d6d139867..0bc5fd875a 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -42,6 +42,8 @@ void set_samba_nb_type(void) samba_nb_type = NB_MFLAG; /* samba is a 'hybrid' node type. */ else samba_nb_type = NB_BFLAG; /* samba is broadcast-only node type. */ + + DEBUG(10,("set_samba_nb_type: %x\n", samba_nb_type)); } /* set_samba_nb_type */ /* ************************************************************************** ** diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index f10d9a2bc5..c39699f822 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -143,6 +143,7 @@ static BOOL send_netbios_packet(struct packet_struct *p) static struct packet_struct *create_and_init_netbios_packet(struct nmb_name *nmbname, BOOL bcast, + BOOL rec_des, struct in_addr to_ip) { struct packet_struct *packet = NULL; @@ -161,7 +162,7 @@ static struct packet_struct *create_and_init_netbios_packet(struct nmb_name *nmb nmb->header.name_trn_id = generate_name_trn_id(); nmb->header.response = False; - nmb->header.nm_flags.recursion_desired = False; + nmb->header.nm_flags.recursion_desired = rec_des; nmb->header.nm_flags.recursion_available = False; nmb->header.nm_flags.trunc = False; nmb->header.nm_flags.authoritative = False; @@ -430,11 +431,12 @@ struct response_record *queue_register_name( struct subnet_record *subrec, struct packet_struct *p; struct response_record *rrec; BOOL bcast = (subrec == unicast_subnet) ? False : True; + BOOL rec_des = (subrec == wins_server_subnet) ? True : False; if(assert_check_subnet(subrec)) return NULL; - if(( p = create_and_init_netbios_packet(nmbname, bcast, + if(( p = create_and_init_netbios_packet(nmbname, bcast, rec_des, subrec->bcast_ip)) == NULL) return NULL; @@ -479,6 +481,7 @@ struct response_record *queue_register_multihomed_name( struct subnet_record *su struct packet_struct *p; struct response_record *rrec; BOOL bcast = False; + BOOL rec_des = (subrec == wins_server_subnet) ? True : False; BOOL ret; /* Sanity check. */ @@ -492,7 +495,7 @@ unicast subnet. subnet is %s\n.", subrec->subnet_name )); if(assert_check_subnet(subrec)) return NULL; - if(( p = create_and_init_netbios_packet(nmbname, bcast, + if(( p = create_and_init_netbios_packet(nmbname, bcast, rec_des, subrec->bcast_ip)) == NULL) return NULL; @@ -539,13 +542,14 @@ struct response_record *queue_release_name( struct subnet_record *subrec, struct in_addr release_ip) { BOOL bcast = (subrec == unicast_subnet) ? False : True; + BOOL rec_des = (subrec == wins_server_subnet) ? True : False; struct packet_struct *p; struct response_record *rrec; if(assert_check_subnet(subrec)) return NULL; - if(( p = create_and_init_netbios_packet(nmbname, bcast, + if(( p = create_and_init_netbios_packet(nmbname, bcast, rec_des, subrec->bcast_ip)) == NULL) return NULL; @@ -597,13 +601,14 @@ struct response_record *queue_refresh_name( struct subnet_record *subrec, struct in_addr refresh_ip) { BOOL bcast = (subrec == unicast_subnet) ? False : True; + BOOL rec_des = (subrec == wins_server_subnet) ? True : False; struct packet_struct *p; struct response_record *rrec; if(assert_check_subnet(subrec)) return NULL; - if(( p = create_and_init_netbios_packet(&namerec->name, bcast, + if(( p = create_and_init_netbios_packet(&namerec->name, bcast,rec_des, subrec->bcast_ip)) == NULL) return NULL; @@ -645,6 +650,7 @@ struct response_record *queue_query_name( struct subnet_record *subrec, struct packet_struct *p; struct response_record *rrec; BOOL bcast = True; + BOOL rec_des = (subrec == wins_server_subnet) ? True : False; if ((subrec == unicast_subnet) || (subrec == wins_server_subnet)) bcast = False; @@ -652,7 +658,7 @@ struct response_record *queue_query_name( struct subnet_record *subrec, if(assert_check_subnet(subrec)) return NULL; - if(( p = create_and_init_netbios_packet(nmbname, bcast, + if(( p = create_and_init_netbios_packet(nmbname, bcast,rec_des, subrec->bcast_ip)) == NULL) return NULL; @@ -694,8 +700,10 @@ struct response_record *queue_query_name_from_wins_server( struct in_addr to_ip, struct packet_struct *p; struct response_record *rrec; BOOL bcast = False; + BOOL rec_des = True; - if(( p = create_and_init_netbios_packet(nmbname, bcast, to_ip)) == NULL) + if(( p = create_and_init_netbios_packet(nmbname, bcast, rec_des, + to_ip)) == NULL) return NULL; if(initiate_name_query_packet_from_wins_server( p ) == False) @@ -737,6 +745,7 @@ struct response_record *queue_node_status( struct subnet_record *subrec, struct packet_struct *p; struct response_record *rrec; BOOL bcast = False; + BOOL rec_des = (subrec == wins_server_subnet) ? True : False; /* Sanity check. */ if(subrec != unicast_subnet) @@ -749,7 +758,7 @@ unicast subnet. subnet is %s\n.", subrec->subnet_name )); if(assert_check_subnet(subrec)) return NULL; - if(( p = create_and_init_netbios_packet(nmbname, bcast, + if(( p = create_and_init_netbios_packet(nmbname, bcast,rec_des, send_ip)) == NULL) return NULL; -- cgit From 6ddfc68e0496dc41f8c9a022a0b04a2066b43c9d Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 1 Dec 1999 02:15:14 +0000 Subject: sys_select added one more argument (read, write selectors). (This used to be commit e4d92ff9dfc51735e6932748f66a7c20b2c1cb6a) --- source3/nmbd/nmbd_packets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index c39699f822..66c774a6e9 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1749,7 +1749,7 @@ BOOL listen_for_packets(BOOL run_election) BlockSignals(False, SIGUSR2); #endif /* SIGUSR2 */ - selrtn = sys_select(256,&fds,&timeout); + selrtn = sys_select(256,&fds,NULL, &timeout); /* We can only take signals when we are in the select - block them again here. */ -- cgit From a76fee73337aca00973ca744f3c41906a72e5855 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 1 Dec 1999 22:06:53 +0000 Subject: more cli_session_setup() calls. what the heck are these doing??? they should all be replaced with cli_establish_connection(). created cli_use_wait_keyboard() which waits on multiple cli_states and swallows session keepalives. (This used to be commit fcc39b3f4f2f8d04d3fab09db048b4f3dc1e97d5) --- source3/nmbd/nmbd_synclists.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index dae25b6eca..aab1e4349c 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -92,7 +92,7 @@ static void sync_child(char *name, int nm_type, return; } - if (!cli_session_setup(&cli, "", "", 1, "", 0, workgroup)) { + if (!cli_session_setup(&cli, local_machine, "", "", 1, "", 0, workgroup)) { cli_shutdown(&cli); return; } -- cgit From 3db52feb1f3b2c07ce0b06ad4a7099fa6efe3fc7 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 13 Dec 1999 13:27:58 +0000 Subject: first pass at updating head branch to be to be the same as the SAMBA_2_0 branch (This used to be commit 453a822a76780063dff23526c35408866d0c0154) --- source3/nmbd/asyncdns.c | 4 +- source3/nmbd/nmbd.c | 163 ++++++++++++++++++++++++++-------- source3/nmbd/nmbd_become_dmb.c | 10 +++ source3/nmbd/nmbd_browserdb.c | 2 +- source3/nmbd/nmbd_browsesync.c | 8 +- source3/nmbd/nmbd_elections.c | 5 +- source3/nmbd/nmbd_incomingdgrams.c | 34 +++++-- source3/nmbd/nmbd_incomingrequests.c | 7 +- source3/nmbd/nmbd_mynames.c | 78 ++++++++++------ source3/nmbd/nmbd_namelistdb.c | 4 +- source3/nmbd/nmbd_namequery.c | 2 +- source3/nmbd/nmbd_nameregister.c | 7 ++ source3/nmbd/nmbd_packets.c | 119 +++++++++++++++++-------- source3/nmbd/nmbd_processlogon.c | 91 +++++++------------ source3/nmbd/nmbd_responserecordsdb.c | 2 +- source3/nmbd/nmbd_sendannounce.c | 12 +-- source3/nmbd/nmbd_serverlistdb.c | 5 +- source3/nmbd/nmbd_subnetdb.c | 74 +++++++++------ source3/nmbd/nmbd_synclists.c | 8 +- source3/nmbd/nmbd_winsproxy.c | 2 +- source3/nmbd/nmbd_winsserver.c | 77 +++++++++++++--- source3/nmbd/nmbd_workgroupdb.c | 31 ++----- 22 files changed, 484 insertions(+), 261 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 67e55ebd50..99e697b470 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -52,7 +52,7 @@ static struct name_record *add_dns_result(struct nmb_name *question, struct in_a #ifndef SYNC_DNS static int fd_in = -1, fd_out = -1; -static int child_pid = -1; +static pid_t child_pid = -1; static int in_dns; /* this is the structure that is passed between the parent and child */ @@ -147,7 +147,7 @@ void start_async_dns(void) fd_out = fd2[1]; close(fd1[1]); close(fd2[0]); - DEBUG(0,("started asyncdns process %d\n", child_pid)); + DEBUG(0,("started asyncdns process %d\n", (int)child_pid)); return; } diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 1471254b4e..533c06351f 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -1,7 +1,7 @@ /* - Unix SMB/NetBIOS implementation. + Unix SMB/Netbios implementation. Version 1.9. - NBT NetBIOS routines and daemon - version 2 + NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 This program is free software; you can redistribute it and/or modify @@ -38,7 +38,6 @@ int ClientNMB = -1; int ClientDGRAM = -1; int global_nmb_port = -1; -extern pstring myhostname; static pstring host_file; extern pstring global_myname; extern fstring global_myworkgroup; @@ -86,6 +85,8 @@ static void sig_term(int sig) /**************************************************************************** ** catch a sighup **************************************************************************** */ +static VOLATILE SIG_ATOMIC_T reload_after_sighup = False; + static void sig_hup(int sig) { BlockSignals( True, SIGHUP ); @@ -95,9 +96,8 @@ static void sig_hup(int sig) write_browse_list( 0, True ); dump_all_namelists(); - reload_services( True ); - set_samba_nb_type(); + reload_after_sighup = True; BlockSignals(False,SIGHUP); @@ -184,6 +184,67 @@ static void expire_names_and_servers(time_t t) expire_workgroups_and_servers(t); } /* expire_names_and_servers */ + +/************************************************************************** ** +reload the list of network interfaces + ************************************************************************** */ +static void reload_interfaces(time_t t) +{ + static time_t lastt; + int n; + struct subnet_record *subrec; + extern BOOL rescan_listen_set; + + if (t && ((t - lastt) < NMBD_INTERFACES_RELOAD)) return; + lastt = t; + + if (!interfaces_changed()) return; + + /* the list of probed interfaces has changed, we may need to add/remove + some subnets */ + load_interfaces(); + + /* find any interfaces that need adding */ + for (n=iface_count() - 1; n >= 0; n--) { + struct interface *iface = get_interface(n); + for (subrec=subnetlist; subrec; subrec=subrec->next) { + if (ip_equal(iface->ip, subrec->myip) && + ip_equal(iface->nmask, subrec->mask_ip)) break; + } + if (!subrec) { + /* it wasn't found! add it */ + DEBUG(2,("Found new interface %s\n", + inet_ntoa(iface->ip))); + subrec = make_normal_subnet(iface); + if (subrec) register_my_workgroup_one_subnet(subrec); + } + } + + /* find any interfaces that need deleting */ + for (subrec=subnetlist; subrec; subrec=subrec->next) { + for (n=iface_count() - 1; n >= 0; n--) { + struct interface *iface = get_interface(n); + if (ip_equal(iface->ip, subrec->myip) && + ip_equal(iface->nmask, subrec->mask_ip)) break; + } + if (n == -1) { + /* oops, an interface has disapeared. This is + tricky, we don't dare actually free the + interface as it could be being used, so + instead we just wear the memory leak and + remove it from the list of interfaces without + freeing it */ + DEBUG(2,("Deleting dead interface %s\n", + inet_ntoa(subrec->myip))); + close_subnet(subrec); + } + } + + rescan_listen_set = True; +} + + + /**************************************************************************** ** reload the services file **************************************************************************** */ @@ -395,6 +456,20 @@ static void process(void) * regularly sync with any other DMBs we know about */ sync_all_dmbs(t); + + /* + * Reload the services file if we got a sighup. + */ + + if(reload_after_sighup) { + reload_services( True ); + reopen_logs(); + reload_interfaces(0); + reload_after_sighup = False; + } + + /* check for new network interfaces */ + reload_interfaces(t); } } /* process */ @@ -412,11 +487,11 @@ static BOOL open_sockets(BOOL isdaemon, int port) */ if ( isdaemon ) - ClientNMB = open_socket_in(SOCK_DGRAM, port,0,0); + ClientNMB = open_socket_in(SOCK_DGRAM, port,0,0,True); else ClientNMB = 0; - ClientDGRAM = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3,0); + ClientDGRAM = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3,0,True); if ( ClientNMB == -1 ) return( False ); @@ -446,7 +521,7 @@ static BOOL init_structs(void) if (! *global_myname) { - fstrcpy( global_myname, myhostname ); + fstrcpy( global_myname, myhostname() ); p = strchr( global_myname, '.' ); if (p) *p = 0; @@ -509,7 +584,7 @@ static BOOL init_structs(void) *p = 0; strlower( local_machine ); - DEBUG( 5, ("NetBIOS name list:-\n") ); + DEBUG( 5, ("Netbios name list:-\n") ); for( n=0; my_netbios_names[n]; n++ ) DEBUGADD( 5, ( "my_netbios_names[%d]=\"%s\"\n", n, my_netbios_names[n] ) ); @@ -521,20 +596,21 @@ static BOOL init_structs(void) **************************************************************************** */ static void usage(char *pname) { - DEBUG(0,("Incorrect program usage - is the command line correct?\n")); - - printf( "Usage: %s [-n name] [-D] [-p port] [-d debuglevel] ", pname ); - printf( "[-l log basename]\n" ); - printf( "Version %s\n", VERSION ); - printf( "\t-D become a daemon\n" ); - printf( "\t-p port listen on the specified port\n" ); - printf( "\t-d debuglevel set the debuglevel\n" ); + + printf( "Usage: %s [-DaohV] [-H lmhosts file] [-d debuglevel] [-l log basename]\n", pname ); + printf( " [-n name] [-p port] [-s configuration file] [-i scope]\n" ); + printf( "\t-D Become a daemon\n" ); + printf( "\t-a Append to log file (default)\n" ); + printf( "\t-o Overwrite log file, don't append\n" ); + printf( "\t-h Print usage\n" ); + printf( "\t-V Print version\n" ); + printf( "\t-H hosts file Load a netbios hosts file\n" ); + printf( "\t-d debuglevel Set the debuglevel\n" ); printf( "\t-l log basename. Basename for log/debug files\n" ); - printf( "\t-n netbiosname. " ); - printf( "the netbios name to advertise for this host\n"); - printf( "\t-H hosts file load a netbios hosts file\n" ); - printf( "\t-a append to log file (default)\n" ); - printf( "\t-o overwrite log file, don't append\n" ); + printf( "\t-n netbiosname. Primary netbios name\n" ); + printf( "\t-p port Listen on the specified port\n" ); + printf( "\t-s configuration file Configuration file name\n" ); + printf( "\t-i scope NetBIOS scope\n" ); printf( "\n"); } /* usage */ @@ -583,6 +659,11 @@ static void usage(char *pname) CatchSignal( SIGHUP, SIGNAL_CAST sig_hup ); CatchSignal( SIGTERM, SIGNAL_CAST sig_term ); +#if defined(SIGFPE) + /* we are never interested in SIGFPE */ + BlockSignals(True,SIGFPE); +#endif + /* Setup the signals that allow the debug log level to by dynamically changed. */ @@ -590,16 +671,16 @@ static void usage(char *pname) SIGUSR1 and SIGUSR2 to do debug level changes. */ #ifndef MEM_MAN #if defined(SIGUSR1) - CatchSignal( SIGUSR1, SIGNAL_CAST sig_usr1 ); + CatchSignal( SIGUSR1, SIGNAL_CAST sig_usr1 ); #endif /* SIGUSR1 */ #if defined(SIGUSR2) - CatchSignal( SIGUSR2, SIGNAL_CAST sig_usr2 ); + CatchSignal( SIGUSR2, SIGNAL_CAST sig_usr2 ); #endif /* SIGUSR2 */ #endif /* MEM_MAN */ while( EOF != - (opt = getopt( argc, argv, "aos:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:f:" )) ) + (opt = getopt( argc, argv, "Vaos:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:f:" )) ) { switch (opt) { @@ -646,9 +727,14 @@ static void usage(char *pname) usage(argv[0]); exit(0); break; + case 'V': + printf( "Version %s\n", VERSION ); + exit(0); + break; default: if( !is_a_socket(0) ) { + DEBUG(0,("Incorrect program usage - is the command line correct?\n")); usage(argv[0]); exit(0); } @@ -658,15 +744,9 @@ static void usage(char *pname) reopen_logs(); - DEBUG( 1, ( "NetBIOS nameserver version %s started.\n", VERSION ) ); + DEBUG( 1, ( "Netbios nameserver version %s started.\n", VERSION ) ); DEBUGADD( 1, ( "Copyright Andrew Tridgell 1994-1998\n" ) ); - if( !get_myname( myhostname, NULL) ) - { - DEBUG( 0, ( "Unable to get my hostname - exiting.\n" ) ); - return -1; - } - if ( !reload_services(False) ) return(-1); @@ -677,10 +757,13 @@ static void usage(char *pname) reload_services( True ); - if (!init_myworkgroup()) - { - exit(1); - } + fstrcpy( global_myworkgroup, lp_workgroup() ); + + if (strequal(global_myworkgroup,"*")) + { + DEBUG(0,("ERROR: a workgroup name of * is no longer supported\n")); + exit(1); + } set_samba_nb_type(); @@ -696,6 +779,14 @@ static void usage(char *pname) become_daemon(); } +#ifndef SYNC_DNS + /* Setup the async dns. We do it here so it doesn't have all the other + stuff initialised and thus chewing memory and sockets */ + if(lp_we_are_a_wins_server()) { + start_async_dns(); + } +#endif + if (!directory_exist(lp_lockdir(), NULL)) { mkdir(lp_lockdir(), 0755); } diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index cbef1db4b7..ae809607dc 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -157,6 +157,16 @@ in workgroup %s on subnet %s\n", */ become_domain_master_browser_bcast(work->work_group); } + else + { + /* + * Now we are a domain master on a broadcast subnet, we need to add + * the WORKGROUP<1b> name to the unicast subnet so that we can answer + * unicast requests sent to this name. This bug wasn't found for a while + * as it is strange to have a DMB without using WINS. JRA. + */ + insert_permanent_name_into_unicast(subrec, registered_name, nb_flags); + } } /**************************************************************************** diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c index 12ce00df4f..10d22431e9 100644 --- a/source3/nmbd/nmbd_browserdb.c +++ b/source3/nmbd/nmbd_browserdb.c @@ -99,7 +99,7 @@ struct browse_cache_record *create_browser_in_lmb_cache( char *work_name, return( NULL ); } - bzero( (char *)browc, sizeof( *browc ) ); + memset( (char *)browc, '\0', sizeof( *browc ) ); /* For a new lmb entry we want to sync with it after one minute. This will allow it time to send out a local announce and build its diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index eafcc79c0a..b177fb524e 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -32,7 +32,7 @@ extern pstring global_myname; extern fstring global_myworkgroup; /* This is our local master browser list database. */ -extern struct ubi_dlList lmb_browserlist[]; +extern ubi_dlList lmb_browserlist[]; /**************************************************************************** As a domain master browser, do a sync with a local master browser. @@ -128,7 +128,7 @@ static void announce_local_master_browser_to_domain_master_browser( struct work_ return; } - bzero(outbuf,sizeof(outbuf)); + memset(outbuf,'\0',sizeof(outbuf)); p = outbuf; CVAL(p,0) = ANN_MasterAnnouncement; p++; @@ -324,7 +324,7 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec, putip((char *)&work->dmb_addr, &ipzero); /* Now initiate the node status request. */ - bzero((char *)&nmbname, sizeof(nmbname)); + memset((char *)&nmbname, '\0',sizeof(nmbname)); nmbname.name[0] = '*'; /* Put the workgroup name into the userdata so we know @@ -549,7 +549,7 @@ static void find_all_domain_master_names_query_success(struct subnet_record *sub for(i = 0; i < rrec->rdlength / 6; i++) { /* Initiate the node status requests. */ - bzero((char *)&nmbname, sizeof(nmbname)); + memset((char *)&nmbname, '\0', sizeof(nmbname)); nmbname.name[0] = '*'; putip((char *)&send_ip, (char *)&rrec->rdata[(i*6) + 2]); diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 8f876eab0c..8e1605dbba 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -46,7 +46,7 @@ static void send_election_dgram(struct subnet_record *subrec, char *workgroup_na DEBUG(2,("send_election_dgram: Sending election packet for workgroup %s on subnet %s\n", workgroup_name, subrec->subnet_name )); - bzero(outbuf,sizeof(outbuf)); + memset(outbuf,'\0',sizeof(outbuf)); p = outbuf; CVAL(p,0) = ANN_Election; /* Election opcode. */ p++; @@ -135,6 +135,9 @@ void check_master_browser_exists(time_t t) struct subnet_record *subrec; char *workgroup_name = global_myworkgroup; + if (!lastrun) + lastrun = t; + if (t < (lastrun + (CHECK_TIME_MST_BROWSE * 60))) return; diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 41aaebd9b1..b8be579779 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -546,10 +546,11 @@ static void send_backup_list_response(struct subnet_record *subrec, char outbuf[1024]; char *p, *countptr; unsigned int count = 0; - int len; +#if 0 struct server_record *servrec; +#endif - bzero(outbuf,sizeof(outbuf)); + memset(outbuf,'\0',sizeof(outbuf)); DEBUG(3,("send_backup_list_response: sending backup list for workgroup %s to %s IP %s\n", work->work_group, nmb_namestr(send_to_name), inet_ntoa(sendto_ip))); @@ -572,9 +573,20 @@ static void send_backup_list_response(struct subnet_record *subrec, p = skip_string(p,1); /* Look for backup browsers in this workgroup. */ + +#if 0 + /* we don't currently send become_backup requests so we should never + send any other servers names out as backups for our + workgroup. That's why this is commented out (tridge) */ + + /* + * NB. Note that the struct work_record here is not neccessarily + * attached to the subnet *subrec. + */ + for (servrec = work->serverlist; servrec; servrec = servrec->next) { - len = PTR_DIFF(p, outbuf); + int len = PTR_DIFF(p, outbuf); if((sizeof(outbuf) - len) < 16) break; @@ -596,11 +608,10 @@ static void send_backup_list_response(struct subnet_record *subrec, p = skip_string(p,1); } +#endif SCVAL(countptr, 0, count); - len = PTR_DIFF(p, outbuf); - DEBUG(4,("send_backup_list_response: sending response to %s<00> IP %s with %d servers.\n", send_to_name->name, inet_ntoa(sendto_ip), count)); @@ -630,6 +641,7 @@ void process_get_backup_list_request(struct subnet_record *subrec, uint32 token = IVAL(buf,1); /* Sender's key index for the workgroup. */ int name_type = dgram->dest_name.name_type; char *workgroup_name = dgram->dest_name.name; + struct subnet_record *search_subrec = subrec; DEBUG(3,("process_get_backup_list_request: request from %s IP %s to %s.\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), @@ -646,13 +658,19 @@ void process_get_backup_list_request(struct subnet_record *subrec, return; } - if((work = find_workgroup_on_subnet(subrec, workgroup_name)) == NULL) + if((work = find_workgroup_on_subnet(search_subrec, workgroup_name)) == NULL) { DEBUG(0,("process_get_backup_list_request: Cannot find workgroup %s on \ -subnet %s.\n", workgroup_name, subrec->subnet_name)); +subnet %s.\n", workgroup_name, search_subrec->subnet_name)); return; } + /* + * If the packet was sent to WORKGROUP<1b> instead + * of WORKGROUP<1d> then it was unicast to us a domain master + * browser. Change search subrec to unicast. + */ + if(name_type == 0x1b) { /* We must be a domain master browser in order to @@ -664,6 +682,8 @@ subnet %s.\n", workgroup_name, subrec->subnet_name)); and I am not a domain master browser.\n", workgroup_name)); return; } + + search_subrec = unicast_subnet; } else if (name_type == 0x1d) { diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index dd5a23e0b0..7c46204445 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -176,8 +176,9 @@ void process_name_refresh_request(struct subnet_record *subrec, and send an error reply back. */ DEBUG(0,("process_name_refresh_request: unicast name registration request \ -received for name %s from IP %s on subnet %s. Error - should be sent to WINS server\n", +received for name %s from IP %s on subnet %s.\n", nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + DEBUG(0,("Error - should be sent to WINS server\n")); send_name_registration_response(FMT_ERR, 0, p); return; @@ -366,7 +367,7 @@ subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name), strequal(qname, namerec->name.name))) { /* Start with the name. */ - bzero(buf,18); + memset(buf,'\0',18); slprintf(buf, 17, "%-15.15s",namerec->name.name); strupper(buf); @@ -421,7 +422,7 @@ subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name), /* We don't send any stats as they could be used to attack the protocol. */ - bzero(buf,46); + memset(buf,'\0',46); buf += 46; diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index 64cb8ea9e9..c36df21e7b 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -43,6 +43,47 @@ static void my_name_register_failed(struct subnet_record *subrec, nmb_namestr(nmbname), subrec->subnet_name)); } + +/**************************************************************************** + Add my workgroup and my given names to one subnet + Also add the magic Samba names. + **************************************************************************/ +void register_my_workgroup_one_subnet(struct subnet_record *subrec) +{ + int i; + + struct work_record *work; + + /* Create the workgroup on the subnet. */ + if((work = create_workgroup_on_subnet(subrec, global_myworkgroup, + PERMANENT_TTL)) == NULL) { + DEBUG(0,("register_my_workgroup_and_names: Failed to create my workgroup %s on subnet %s. \ +Exiting.\n", global_myworkgroup, subrec->subnet_name)); + return; + } + + /* Each subnet entry, except for the wins_server_subnet has + the magic Samba names. */ + add_samba_names_to_subnet(subrec); + + /* Register all our names including aliases. */ + for (i=0; my_netbios_names[i]; i++) { + register_name(subrec, my_netbios_names[i],0x20,samba_nb_type, + NULL, + my_name_register_failed, NULL); + register_name(subrec, my_netbios_names[i],0x03,samba_nb_type, + NULL, + my_name_register_failed, NULL); + register_name(subrec, my_netbios_names[i],0x00,samba_nb_type, + NULL, + my_name_register_failed, NULL); + } + + /* Initiate election processing, register the workgroup names etc. */ + initiate_myworkgroup_startup(subrec, work); +} + + /**************************************************************************** Add my workgroup and my given names to the subnet lists. Also add the magic Samba names. @@ -51,38 +92,13 @@ static void my_name_register_failed(struct subnet_record *subrec, BOOL register_my_workgroup_and_names(void) { struct subnet_record *subrec; - struct work_record *work; int i; - for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) + for(subrec = FIRST_SUBNET; + subrec; + subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { - /* Create the workgroup on the subnet. */ - if((work = create_workgroup_on_subnet(subrec, global_myworkgroup, PERMANENT_TTL)) == NULL) - { - DEBUG(0,("register_my_workgroup_and_names: Failed to create my workgroup %s on subnet %s. \ -Exiting.\n", global_myworkgroup, subrec->subnet_name)); - return False; - } - - /* Each subnet entry, except for the wins_server_subnet has the magic Samba names. */ - add_samba_names_to_subnet(subrec); - - /* Register all our names including aliases. */ - for (i=0; my_netbios_names[i]; i++) - { - register_name(subrec, my_netbios_names[i],0x20,samba_nb_type, - NULL, - my_name_register_failed, NULL); - register_name(subrec, my_netbios_names[i],0x03,samba_nb_type, - NULL, - my_name_register_failed, NULL); - register_name(subrec, my_netbios_names[i],0x00,samba_nb_type, - NULL, - my_name_register_failed, NULL); - } - - /* Initiate election processing, register the workgroup names etc. */ - initiate_myworkgroup_startup(subrec, work); + register_my_workgroup_one_subnet(subrec); } /* If we are not a WINS client, we still need to add the magic Samba @@ -180,6 +196,10 @@ void refresh_my_names(time_t t) { struct name_record *namerec; + /* B nodes don't send out name refresh requests, see RFC 1001, 15.5.1 */ + if (subrec != unicast_subnet) + continue; + for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); namerec; namerec = (struct name_record *)ubi_trNext( namerec ) ) diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 0bc5fd875a..dbb8be1f2d 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -42,8 +42,6 @@ void set_samba_nb_type(void) samba_nb_type = NB_MFLAG; /* samba is a 'hybrid' node type. */ else samba_nb_type = NB_BFLAG; /* samba is broadcast-only node type. */ - - DEBUG(10,("set_samba_nb_type: %x\n", samba_nb_type)); } /* set_samba_nb_type */ /* ************************************************************************** ** @@ -201,7 +199,7 @@ struct name_record *add_name_to_subnet( struct subnet_record *subrec, return( NULL ); } - bzero( (char *)namerec, sizeof(*namerec) ); + memset( (char *)namerec, '\0', sizeof(*namerec) ); namerec->data.ip = (struct in_addr *)malloc( sizeof(struct in_addr) * num_ips ); if( NULL == namerec->data.ip ) diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index fae045882f..8c41554842 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -193,7 +193,7 @@ BOOL query_name(struct subnet_record *subrec, char *name, int type, struct res_rec rrec; int i; - bzero((char *)&rrec, sizeof(struct res_rec)); + memset((char *)&rrec, '\0', sizeof(struct res_rec)); /* Fake up the needed res_rec just in case it's used. */ rrec.rr_name = nmbname; diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index 069e262987..1e819cc88f 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -54,6 +54,13 @@ static void register_name_response(struct subnet_record *subrec, /* Sanity check. Ensure that the answer name in the incoming packet is the same as the requested name in the outgoing packet. */ + if(!question_name || !answer_name) + { + DEBUG(0,("register_name_response: malformed response (%s is NULL).\n", + question_name ? "question_name" : "answer_name" )); + return; + } + if(!nmb_name_equal(question_name, answer_name)) { DEBUG(0,("register_name_response: Answer name %s differs from question \ diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 66c774a6e9..0a7696a466 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -37,6 +37,9 @@ extern struct in_addr loopback_ip; static void queue_packet(struct packet_struct *packet); +BOOL rescan_listen_set = False; + + /******************************************************************* The global packet linked-list. Incoming entries are added to the end of this list. It is supposed to remain fairly @@ -90,6 +93,43 @@ void set_nb_flags(char *buf, uint16 nb_flags) *buf = '\0'; } +/*************************************************************************** +Dumps out the browse packet data. +**************************************************************************/ + +static void debug_browse_data(char *outbuf, int len) +{ + int i,j; + + DEBUG( 4, ( "debug_browse_data():\n" ) ); + for (i = 0; i < len; i+= 16) + { + DEBUGADD( 4, ( "%3x char ", i ) ); + + for (j = 0; j < 16; j++) + { + unsigned char x = outbuf[i+j]; + if (x < 32 || x > 127) + x = '.'; + + if (i+j >= len) + break; + DEBUGADD( 4, ( "%c", x ) ); + } + + DEBUGADD( 4, ( "%*s hex", 16-j, "" ) ); + + for (j = 0; j < 16; j++) + { + if (i+j >= len) + break; + DEBUGADD( 4, ( " %02x", (unsigned char)outbuf[i+j] ) ); + } + + DEBUGADD( 4, ("\n") ); + } +} + /*************************************************************************** Generates the unique transaction identifier **************************************************************************/ @@ -143,7 +183,6 @@ static BOOL send_netbios_packet(struct packet_struct *p) static struct packet_struct *create_and_init_netbios_packet(struct nmb_name *nmbname, BOOL bcast, - BOOL rec_des, struct in_addr to_ip) { struct packet_struct *packet = NULL; @@ -156,13 +195,13 @@ static struct packet_struct *create_and_init_netbios_packet(struct nmb_name *nmb return NULL; } - bzero((char *)packet,sizeof(*packet)); + memset((char *)packet,'\0',sizeof(*packet)); nmb = &packet->packet.nmb; nmb->header.name_trn_id = generate_name_trn_id(); nmb->header.response = False; - nmb->header.nm_flags.recursion_desired = rec_des; + nmb->header.nm_flags.recursion_desired = False; nmb->header.nm_flags.recursion_available = False; nmb->header.nm_flags.trunc = False; nmb->header.nm_flags.authoritative = False; @@ -203,13 +242,17 @@ static BOOL create_and_init_additional_record(struct packet_struct *packet, return False; } - bzero((char *)nmb->additional,sizeof(struct res_rec)); + memset((char *)nmb->additional,'\0',sizeof(struct res_rec)); nmb->additional->rr_name = nmb->question.question_name; nmb->additional->rr_type = RR_TYPE_NB; nmb->additional->rr_class = RR_CLASS_IN; - nmb->additional->ttl = lp_max_ttl(); + /* See RFC 1002, sections 5.1.1.1, 5.1.1.2 and 5.1.1.3 */ + if (nmb->header.nm_flags.bcast) + nmb->additional->ttl = PERMANENT_TTL; + else + nmb->additional->ttl = lp_max_ttl(); nmb->additional->rdlength = 6; @@ -431,12 +474,11 @@ struct response_record *queue_register_name( struct subnet_record *subrec, struct packet_struct *p; struct response_record *rrec; BOOL bcast = (subrec == unicast_subnet) ? False : True; - BOOL rec_des = (subrec == wins_server_subnet) ? True : False; if(assert_check_subnet(subrec)) return NULL; - if(( p = create_and_init_netbios_packet(nmbname, bcast, rec_des, + if(( p = create_and_init_netbios_packet(nmbname, bcast, subrec->bcast_ip)) == NULL) return NULL; @@ -481,7 +523,6 @@ struct response_record *queue_register_multihomed_name( struct subnet_record *su struct packet_struct *p; struct response_record *rrec; BOOL bcast = False; - BOOL rec_des = (subrec == wins_server_subnet) ? True : False; BOOL ret; /* Sanity check. */ @@ -495,7 +536,7 @@ unicast subnet. subnet is %s\n.", subrec->subnet_name )); if(assert_check_subnet(subrec)) return NULL; - if(( p = create_and_init_netbios_packet(nmbname, bcast, rec_des, + if(( p = create_and_init_netbios_packet(nmbname, bcast, subrec->bcast_ip)) == NULL) return NULL; @@ -542,14 +583,13 @@ struct response_record *queue_release_name( struct subnet_record *subrec, struct in_addr release_ip) { BOOL bcast = (subrec == unicast_subnet) ? False : True; - BOOL rec_des = (subrec == wins_server_subnet) ? True : False; struct packet_struct *p; struct response_record *rrec; if(assert_check_subnet(subrec)) return NULL; - if(( p = create_and_init_netbios_packet(nmbname, bcast, rec_des, + if(( p = create_and_init_netbios_packet(nmbname, bcast, subrec->bcast_ip)) == NULL) return NULL; @@ -601,14 +641,13 @@ struct response_record *queue_refresh_name( struct subnet_record *subrec, struct in_addr refresh_ip) { BOOL bcast = (subrec == unicast_subnet) ? False : True; - BOOL rec_des = (subrec == wins_server_subnet) ? True : False; struct packet_struct *p; struct response_record *rrec; if(assert_check_subnet(subrec)) return NULL; - if(( p = create_and_init_netbios_packet(&namerec->name, bcast,rec_des, + if(( p = create_and_init_netbios_packet(&namerec->name, bcast, subrec->bcast_ip)) == NULL) return NULL; @@ -650,7 +689,6 @@ struct response_record *queue_query_name( struct subnet_record *subrec, struct packet_struct *p; struct response_record *rrec; BOOL bcast = True; - BOOL rec_des = (subrec == wins_server_subnet) ? True : False; if ((subrec == unicast_subnet) || (subrec == wins_server_subnet)) bcast = False; @@ -658,7 +696,7 @@ struct response_record *queue_query_name( struct subnet_record *subrec, if(assert_check_subnet(subrec)) return NULL; - if(( p = create_and_init_netbios_packet(nmbname, bcast,rec_des, + if(( p = create_and_init_netbios_packet(nmbname, bcast, subrec->bcast_ip)) == NULL) return NULL; @@ -700,10 +738,8 @@ struct response_record *queue_query_name_from_wins_server( struct in_addr to_ip, struct packet_struct *p; struct response_record *rrec; BOOL bcast = False; - BOOL rec_des = True; - if(( p = create_and_init_netbios_packet(nmbname, bcast, rec_des, - to_ip)) == NULL) + if(( p = create_and_init_netbios_packet(nmbname, bcast, to_ip)) == NULL) return NULL; if(initiate_name_query_packet_from_wins_server( p ) == False) @@ -745,7 +781,6 @@ struct response_record *queue_node_status( struct subnet_record *subrec, struct packet_struct *p; struct response_record *rrec; BOOL bcast = False; - BOOL rec_des = (subrec == wins_server_subnet) ? True : False; /* Sanity check. */ if(subrec != unicast_subnet) @@ -758,7 +793,7 @@ unicast subnet. subnet is %s\n.", subrec->subnet_name )); if(assert_check_subnet(subrec)) return NULL; - if(( p = create_and_init_netbios_packet(nmbname, bcast,rec_des, + if(( p = create_and_init_netbios_packet(nmbname, bcast, send_ip)) == NULL) return NULL; @@ -895,10 +930,10 @@ for id %hu\n", nmb->header.nscount = 0; nmb->header.arcount = 0; - bzero((char*)&nmb->question,sizeof(nmb->question)); + memset((char*)&nmb->question,'\0',sizeof(nmb->question)); nmb->answers = &answers; - bzero((char*)nmb->answers,sizeof(*nmb->answers)); + memset((char*)nmb->answers,'\0',sizeof(*nmb->answers)); nmb->answers->rr_name = orig_nmb->question.question_name; nmb->answers->rr_type = orig_nmb->question.question_type; @@ -1013,45 +1048,43 @@ mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, scop { case ANN_HostAnnouncement: { + debug_browse_data(buf, len); process_host_announce(subrec, p, buf+1); break; } case ANN_DomainAnnouncement: { + debug_browse_data(buf, len); process_workgroup_announce(subrec, p, buf+1); break; } case ANN_LocalMasterAnnouncement: { + debug_browse_data(buf, len); process_local_master_announce(subrec, p, buf+1); break; } case ANN_AnnouncementRequest: { + debug_browse_data(buf, len); process_announce_request(subrec, p, buf+1); break; } case ANN_Election: { + debug_browse_data(buf, len); process_election(subrec, p, buf+1); break; } case ANN_GetBackupListReq: { - - /* This is one occasion where we change a subnet that is - given to us. If the packet was sent to WORKGROUP<1b> instead - of WORKGROUP<1d> then it was unicast to us a domain master - browser. Change subrec to unicast. - */ - if(dgram->dest_name.name_type == 0x1b) - subrec = unicast_subnet; - + debug_browse_data(buf, len); process_get_backup_list_request(subrec, p, buf+1); break; } case ANN_GetBackupListResp: { + debug_browse_data(buf, len); /* We never send ANN_GetBackupListReq so we should never get these. */ DEBUG(0,("process_browse_packet: Discarding GetBackupListResponse \ @@ -1060,6 +1093,7 @@ packet from %s IP %s\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip))); } case ANN_ResetBrowserState: { + debug_browse_data(buf, len); process_reset_browser(subrec, p, buf+1); break; } @@ -1069,6 +1103,7 @@ packet from %s IP %s\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip))); on the unicast subnet. */ subrec = unicast_subnet; + debug_browse_data(buf, len); process_master_browser_announce(subrec, p, buf+1); break; } @@ -1077,6 +1112,7 @@ packet from %s IP %s\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip))); /* * We don't currently implement this. Log it just in case. */ + debug_browse_data(buf, len); DEBUG(10,("process_browse_packet: On subnet %s ignoring browse packet \ command ANN_BecomeBackup from %s IP %s to %s\n", subrec->subnet_name, nmb_namestr(&dgram->source_name), @@ -1085,6 +1121,7 @@ command ANN_BecomeBackup from %s IP %s to %s\n", } default: { + debug_browse_data(buf, len); DEBUG(0,("process_browse_packet: On subnet %s ignoring browse packet \ command code %d from %s IP %s to %s\n", subrec->subnet_name, command, nmb_namestr(&dgram->source_name), @@ -1123,7 +1160,7 @@ mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, scop { case ANN_HostAnnouncement: { - dump_data(4, buf, len); + debug_browse_data(buf, len); process_lm_host_announce(subrec, p, buf+1); break; } @@ -1208,11 +1245,10 @@ static void process_dgram(struct packet_struct *p) nmb_namestr(&dgram->source_name),nmb_namestr(&dgram->dest_name), inet_ntoa(p->ip), smb_buf(buf),CVAL(buf2,0),len)); + if (len <= 0) return; - dump_data(100, buf2, len); - /* Datagram packet received for the browser mailslot */ if (strequal(smb_buf(buf),BROWSE_MAILSLOT)) { @@ -1687,6 +1723,10 @@ only use %d.\n", (count*2) + 2, FD_SETSIZE)); } *listen_number = (count*2) + 2; + + if (*ppset) free(*ppset); + if (*psock_array) free(*psock_array); + *ppset = pset; *psock_array = sock_array; @@ -1710,13 +1750,14 @@ BOOL listen_for_packets(BOOL run_election) int dns_fd; #endif - if(listen_set == NULL) + if(listen_set == NULL || rescan_listen_set) { if(create_listen_fdset(&listen_set, &sock_array, &listen_number)) { DEBUG(0,("listen_for_packets: Fatal error. unable to create listen set. Exiting.\n")); return True; } + rescan_listen_set = False; } memcpy((char *)&fds, (char *)listen_set, sizeof(fd_set)); @@ -1749,7 +1790,7 @@ BOOL listen_for_packets(BOOL run_election) BlockSignals(False, SIGUSR2); #endif /* SIGUSR2 */ - selrtn = sys_select(256,&fds,NULL, &timeout); + selrtn = sys_select(FD_SETSIZE,&fds,&timeout); /* We can only take signals when we are in the select - block them again here. */ @@ -1864,7 +1905,7 @@ BOOL send_mailslot(BOOL unique, char *mailslot,char *buf,int len, char *ptr,*p2; char tmp[4]; - bzero((char *)&p,sizeof(p)); + memset((char *)&p,'\0',sizeof(p)); if(ismyip(dest_ip)) loopback_this_packet = True; @@ -1873,7 +1914,7 @@ BOOL send_mailslot(BOOL unique, char *mailslot,char *buf,int len, /* DIRECT GROUP or UNIQUE datagram. */ dgram->header.msg_type = unique ? 0x10 : 0x11; - dgram->header.flags.node_type = M_NODE | 0x40; + dgram->header.flags.node_type = M_NODE; dgram->header.flags.first = True; dgram->header.flags.more = False; dgram->header.dgm_id = name_trn_id; @@ -1920,7 +1961,7 @@ BOOL send_mailslot(BOOL unique, char *mailslot,char *buf,int len, nmb_namestr(&dgram->source_name), inet_ntoa(src_ip))); DEBUG(4,("to %s IP %s\n", nmb_namestr(&dgram->dest_name), inet_ntoa(dest_ip))); - dump_data(4, buf, len); + debug_browse_data(buf, len); if(loopback_this_packet) { diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index a515c2706d..279ab1c764 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -50,6 +50,7 @@ void process_logon_packet(struct packet_struct *p,char *buf,int len, uint32 domainsidsize; char *getdc; char *uniuser; /* Unicode user name. */ + pstring ascuser; char *unicomp; /* Unicode computer name. */ memset(outbuf, 0, sizeof(outbuf)); @@ -117,7 +118,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); q = align2(unicomp, buf); - q = skip_unibuf(q, buf+len-q); + q = skip_unicode_string(q, 1); ntversion = IVAL(q, 0); q += 4; @@ -134,19 +135,17 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); fstrcpy(reply_name,my_name); fstrcpy(q, reply_name); + q = skip_string(q, 1); /* PDC name */ - /* PDC and domain name */ -#if 0 - if (strcmp(mailslot, NT_LOGON_MAILSLOT)==0) -#endif - { + if (strcmp(mailslot, NT_LOGON_MAILSLOT)==0) { q = align2(q, buf); - q = ascii_to_unibuf(q, my_name, outbuf+sizeof(outbuf)-q-2); - q = ascii_to_unibuf(q, global_myworkgroup, outbuf+sizeof(outbuf)-q-2); + dos_PutUniCode(q, my_name, sizeof(pstring)); /* PDC name */ + q = skip_unicode_string(q, 1); - ntversion = 0x01; + dos_PutUniCode(q, global_myworkgroup,sizeof(pstring)); /* Domain name*/ + q = skip_unicode_string(q, 1); SIVAL(q, 0, ntversion); q += 4; @@ -166,10 +165,10 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", send_mailslot(True, getdc, outbuf,PTR_DIFF(q,outbuf), - my_name, - 0x0, - dgram->source_name.name, - dgram->source_name.name_type, + dgram->dest_name.name, + dgram->dest_name.name_type, + dgram->source_name.name, + dgram->source_name.name_type, p->ip, *iface_ip(p->ip), p->port); return; } @@ -180,20 +179,13 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += 2; unicomp = q; - uniuser = skip_unibuf(unicomp, buf+len-q); - getdc = skip_unibuf(uniuser, buf+len-q); + uniuser = skip_unicode_string(unicomp,1); + getdc = skip_unicode_string(uniuser,1); q = skip_string(getdc,1); - q += 4; /* skip Account Control Bits */ + q += 4; domainsidsize = IVAL(q, 0); q += 4; - - if (domainsidsize != 0) - { - q += domainsidsize; - q += 2; - q = align4(q, buf); - } - + q += domainsidsize + 3; ntversion = IVAL(q, 0); q += 4; lmnttoken = SVAL(q, 0); @@ -201,7 +193,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", lm20token = SVAL(q, 0); q += 2; - DEBUG(3,("process_logon_packet: SAMLOGON sidsize %d ntv %x\n", domainsidsize, ntversion)); + DEBUG(3,("process_logon_packet: SAMLOGON sidsize %d ntv %d\n", domainsidsize, ntversion)); /* * we respond regadless of whether the machine is in our password @@ -209,43 +201,28 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", * Let's ignore the SID. */ + pstrcpy(ascuser, dos_unistr(uniuser)); + DEBUG(3,("process_logon_packet: SAMLOGON user %s\n", ascuser)); + fstrcpy(reply_name,"\\\\"); /* Here it wants \\LOGONSERVER. */ fstrcpy(reply_name+2,my_name); - ntversion = 0x01; - lmnttoken = 0xffff; - lm20token = 0xffff; - - if (DEBUGLVL(3)) - { - fstring ascuser; - fstring asccomp; - - unibuf_to_ascii(ascuser, uniuser, sizeof(ascuser)-1); - unibuf_to_ascii(asccomp, unicomp, sizeof(asccomp)-1); - - DEBUGADD(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n", - asccomp,inet_ntoa(p->ip), ascuser, reply_name, - global_myworkgroup, SAMLOGON_R, lmnttoken)); - } + DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n", + dos_unistr(unicomp),inet_ntoa(p->ip), ascuser, reply_name, global_myworkgroup, + SAMLOGON_R ,lmnttoken)); /* Construct reply. */ q = outbuf; - if (uniuser[0] == 0) - { - SSVAL(q, 0, SAMLOGON_UNK_R); /* user unknown */ - } - else - { - SSVAL(q, 0, SAMLOGON_R); - } + SSVAL(q, 0, SAMLOGON_R); q += 2; - /* Logon server, trust account, domain */ - q = ascii_to_unibuf(q, reply_name, outbuf+sizeof(outbuf)-q-2); - q = uni_strncpy(q, uniuser, outbuf+sizeof(outbuf)-q-2); - q = ascii_to_unibuf(q, lp_workgroup(), outbuf+sizeof(outbuf)-q-2); + dos_PutUniCode(q, reply_name,sizeof(pstring)); + q = skip_unicode_string(q, 1); + unistrcpy(q, uniuser); + q = skip_unicode_string(q, 1); /* User name (workstation trust account) */ + dos_PutUniCode(q, lp_workgroup(),sizeof(pstring)); + q = skip_unicode_string(q, 1); /* Domain name. */ SIVAL(q, 0, ntversion); q += 4; @@ -258,10 +235,10 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", send_mailslot(True, getdc, outbuf,PTR_DIFF(q,outbuf), - my_name, - 0x0, - dgram->source_name.name, - dgram->source_name.name_type, + dgram->dest_name.name, + dgram->dest_name.name_type, + dgram->source_name.name, + dgram->source_name.name_type, p->ip, *iface_ip(p->ip), p->port); break; } diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index 0c698760bb..fe29464773 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -119,7 +119,7 @@ struct response_record *make_response_record( struct subnet_record *subrec, return NULL; } - bzero((char *)rrec, sizeof(*rrec)); + memset((char *)rrec, '\0', sizeof(*rrec)); rrec->response_id = nmb->header.name_trn_id; diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index 38c8deafe7..87115a1eb0 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -46,7 +46,7 @@ void send_browser_reset(int reset_type, char *to_name, int to_type, struct in_ad DEBUG(3,("send_browser_reset: sending reset request type %d to %s<%02x> IP %s.\n", reset_type, to_name, to_type, inet_ntoa(to_ip) )); - bzero(outbuf,sizeof(outbuf)); + memset(outbuf,'\0',sizeof(outbuf)); p = outbuf; CVAL(p,0) = ANN_ResetBrowserState; p++; @@ -73,7 +73,7 @@ void broadcast_announce_request(struct subnet_record *subrec, struct work_record DEBUG(3,("broadcast_announce_request: sending announce request for workgroup %s \ to subnet %s\n", work->work_group, subrec->subnet_name)); - bzero(outbuf,sizeof(outbuf)); + memset(outbuf,'\0',sizeof(outbuf)); p = outbuf; CVAL(p,0) = ANN_AnnouncementRequest; p++; @@ -101,7 +101,7 @@ static void send_announcement(struct subnet_record *subrec, int announce_type, pstring outbuf; char *p; - bzero(outbuf,sizeof(outbuf)); + memset(outbuf,'\0',sizeof(outbuf)); p = outbuf+1; CVAL(outbuf,0) = announce_type; @@ -142,7 +142,7 @@ static void send_lm_announcement(struct subnet_record *subrec, int announce_type pstring outbuf; char *p=outbuf; - bzero(outbuf,sizeof(outbuf)); + memset(outbuf,'\0',sizeof(outbuf)); SSVAL(p,0,announce_type); SIVAL(p,2,server_type & ~SV_TYPE_LOCAL_LIST_ONLY); @@ -504,7 +504,7 @@ void announce_remote(time_t t) if (!*s) return; - comment = lp_serverstring(); + comment = string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH); for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) { @@ -587,7 +587,7 @@ for workgroup %s on subnet %s.\n", global_myworkgroup, FIRST_SUBNET->subnet_name return; } - bzero(outbuf,sizeof(outbuf)); + memset(outbuf,'\0',sizeof(outbuf)); p = outbuf; CVAL(p,0) = ANN_MasterAnnouncement; p++; diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index d30e8da64c..41009bc68f 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -156,7 +156,7 @@ workgroup %s. This is a bug.\n", name, work->work_group)); return NULL; } - bzero((char *)servrec,sizeof(*servrec)); + memset((char *)servrec,'\0',sizeof(*servrec)); servrec->subnet = work->subnet; @@ -399,7 +399,8 @@ void write_browse_list(time_t t, BOOL force_write) slprintf(tmp, sizeof(tmp)-1, "\"%s\"", my_netbios_names[i]); fprintf(fp, "%-25s ", tmp); fprintf(fp, "%08x ", stype); - slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", lp_serverstring()); + slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", + string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH)); fprintf(fp, "%-30s", tmp); fprintf(fp, "\"%s\"\n", global_myworkgroup); } diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 527efa9dd8..37b50f8525 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -55,22 +55,7 @@ extern uint16 samba_nb_type; /* Samba's NetBIOS name type. */ static void add_subnet(struct subnet_record *subrec) { - struct subnet_record *subrec2; - - if (!subnetlist) - { - subnetlist = subrec; - subrec->prev = NULL; - subrec->next = NULL; - return; - } - - for (subrec2 = subnetlist; subrec2->next; subrec2 = subrec2->next) - ; - - subrec2->next = subrec; - subrec->next = NULL; - subrec->prev = subrec2; + DLIST_ADD(subnetlist, subrec); } /* ************************************************************************** ** @@ -96,19 +81,41 @@ static int namelist_entry_compare( ubi_trItemPtr Item, ubi_trNodePtr Node ) Debug1( "nmbd_subnetdb:namelist_entry_compare()\n" ); Debug1( "%d == memcmp( \"%s\", \"%s\", %d )\n", memcmp( Item, &(NR->name), sizeof(struct nmb_name) ), - nmb_namestr(Iname), nmb_namestr(&NR->name), sizeof(struct nmb_name) ); + nmb_namestr(Iname), nmb_namestr(&NR->name), (int)sizeof(struct nmb_name) ); } return( memcmp( Item, &(NR->name), sizeof(struct nmb_name) ) ); } /* namelist_entry_compare */ + +/**************************************************************************** +stop listening on a subnet +we don't free the record as we don't have proper reference counting for it +yet and it may be in use by a response record + ****************************************************************************/ +void close_subnet(struct subnet_record *subrec) +{ + DLIST_REMOVE(subnetlist, subrec); + + if (subrec->dgram_sock != -1) { + close(subrec->dgram_sock); + subrec->dgram_sock = -1; + } + if (subrec->nmb_sock != -1) { + close(subrec->nmb_sock); + subrec->nmb_sock = -1; + } +} + + + /**************************************************************************** Create a subnet entry. ****************************************************************************/ static struct subnet_record *make_subnet(char *name, enum subnet_type type, - struct in_addr myip, struct in_addr bcast_ip, - struct in_addr mask_ip) + struct in_addr myip, struct in_addr bcast_ip, + struct in_addr mask_ip) { struct subnet_record *subrec = NULL; int nmb_sock, dgram_sock; @@ -130,7 +137,7 @@ static struct subnet_record *make_subnet(char *name, enum subnet_type type, * Fail the subnet creation if this fails. */ - if((nmb_sock = open_socket_in(SOCK_DGRAM, global_nmb_port,0, myip.s_addr)) == -1) + if((nmb_sock = open_socket_in(SOCK_DGRAM, global_nmb_port,0, myip.s_addr,True)) == -1) { if( DEBUGLVL( 0 ) ) { @@ -142,7 +149,7 @@ static struct subnet_record *make_subnet(char *name, enum subnet_type type, return NULL; } - if((dgram_sock = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3, myip.s_addr)) == -1) + if((dgram_sock = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3, myip.s_addr,True)) == -1) { if( DEBUGLVL( 0 ) ) { @@ -170,7 +177,7 @@ static struct subnet_record *make_subnet(char *name, enum subnet_type type, return(NULL); } - bzero( (char *)subrec, sizeof(*subrec) ); + memset( (char *)subrec, '\0', sizeof(*subrec) ); (void)ubi_trInitTree( subrec->namelist, namelist_entry_compare, ubi_trOVERWRITE ); @@ -202,6 +209,23 @@ static struct subnet_record *make_subnet(char *name, enum subnet_type type, return subrec; } + +/**************************************************************************** + Create a normal subnet +**************************************************************************/ +struct subnet_record *make_normal_subnet(struct interface *iface) +{ + struct subnet_record *subrec; + + subrec = make_subnet(inet_ntoa(iface->ip), NORMAL_SUBNET, + iface->ip, iface->bcast, iface->nmask); + if (subrec) { + add_subnet(subrec); + } + return subrec; +} + + /**************************************************************************** Create subnet entries. **************************************************************************/ @@ -225,13 +249,9 @@ BOOL create_subnets(void) for (i = 0 ; i < num_interfaces; i++) { - struct subnet_record *subrec; struct interface *iface = get_interface(i); - if((subrec = make_subnet(inet_ntoa(iface->ip), NORMAL_SUBNET, - iface->ip, iface->bcast,iface->nmask)) == NULL) - return False; - add_subnet(subrec); + if (!make_normal_subnet(iface)) return False; } /* diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index aab1e4349c..fb51be4d8f 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -40,7 +40,7 @@ struct sync_record { fstring server; pstring fname; struct in_addr ip; - int pid; + pid_t pid; }; /* a linked list of current sync connections */ @@ -92,7 +92,7 @@ static void sync_child(char *name, int nm_type, return; } - if (!cli_session_setup(&cli, local_machine, "", "", 1, "", 0, workgroup)) { + if (!cli_session_setup(&cli, "", "", 1, "", 0, workgroup)) { cli_shutdown(&cli); return; } @@ -103,7 +103,7 @@ static void sync_child(char *name, int nm_type, } /* Fetch a workgroup list. */ - cli_NetServerEnum(&cli, workgroup, + cli_NetServerEnum(&cli, cli.server_domain?cli.server_domain:workgroup, local_type|SV_TYPE_DOMAIN_ENUM, callback); @@ -147,7 +147,7 @@ void sync_browse_lists(struct work_record *work, slprintf(s->fname, sizeof(pstring)-1, "%s/sync.%d", lp_lockdir(), counter++); - string_sub(s->fname,"//", "/"); + all_string_sub(s->fname,"//", "/", 0); DLIST_ADD(syncs, s); diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index 43beb9acd8..1398ebd299 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -207,7 +207,7 @@ void make_wins_proxy_name_query_request( struct subnet_record *subrec, sizeof(struct packet_struct *)]; struct userdata_struct *userdata = (struct userdata_struct *)ud; - bzero(ud, sizeof(ud)); + memset(ud, '\0', sizeof(ud)); userdata->copy_fn = wins_proxy_userdata_copy_fn; userdata->free_fn = wins_proxy_userdata_free_fn; diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 35ca5af62c..45e9335167 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -30,6 +30,41 @@ extern int DEBUGLEVEL; extern struct in_addr ipzero; +/**************************************************************************** +possibly call the WINS hook external program when a WINS change is made +*****************************************************************************/ +static void wins_hook(char *operation, struct name_record *namerec, int ttl) +{ + pstring command; + char *cmd = lp_wins_hook(); + char *p; + int i; + + if (!cmd || !*cmd) return; + + for (p=namerec->name.name; *p; p++) { + if (!(isalnum((int)*p) || strchr("._-",*p))) { + DEBUG(3,("not calling wins hook for invalid name %s\n", nmb_namestr(&namerec->name))); + return; + } + } + + p = command; + p += slprintf(p, sizeof(command), "%s %s %s %02x %d", + cmd, + operation, + namerec->name.name, + namerec->name.name_type, + ttl); + + for (i=0;idata.num_ips;i++) { + p += slprintf(p, sizeof(command) - (p-command), " %s", inet_ntoa(namerec->data.ip[i])); + } + + DEBUG(3,("calling wins hook for %s\n", nmb_namestr(&namerec->name))); + smbrun(command, NULL, False); +} + /**************************************************************************** hash our interfaces and netbios names settings @@ -147,11 +182,6 @@ BOOL initialise_wins(void) add_samba_names_to_subnet(wins_server_subnet); -#ifndef SYNC_DNS - /* Setup the async dns. */ - start_async_dns(); -#endif - pstrcpy(fname,lp_lockdir()); trim_string(fname,NULL,"/"); pstrcat(fname,"/"); @@ -456,6 +486,7 @@ does not match group bit in WINS for this name.\n", nmb_namestr(question), group */ update_name_ttl(namerec, ttl); send_wins_name_registration_response(0, ttl, p); + wins_hook("refresh", namerec, ttl); return; } else if(group) @@ -636,7 +667,7 @@ void wins_process_name_registration_request(struct subnet_record *subrec, int ttl = get_ttl_from_packet(nmb); struct name_record *namerec = NULL; struct in_addr from_ip; - BOOL registering_group_name = (nb_flags & NB_GROUP) ? True : False;; + BOOL registering_group_name = (nb_flags & NB_GROUP) ? True : False; putip((char *)&from_ip,&nmb->additional->rdata[2]); @@ -715,7 +746,7 @@ to register name %s. Name already exists in WINS with source type %d.\n", if(!registering_group_name && (question->name_type == 0x1d)) { DEBUG(3,("wins_process_name_registration_request: Ignoring request \ -to register name %s from IP %s.", nmb_namestr(question), inet_ntoa(p->ip) )); +to register name %s from IP %s.\n", nmb_namestr(question), inet_ntoa(p->ip) )); send_wins_name_registration_response(0, ttl, p); return; } @@ -785,6 +816,7 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio */ update_name_ttl(namerec, ttl); send_wins_name_registration_response(0, ttl, p); + wins_hook("refresh", namerec, ttl); return; } } @@ -801,6 +833,7 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio { update_name_ttl( namerec, ttl ); send_wins_name_registration_response( 0, ttl, p ); + wins_hook("refresh", namerec, ttl); return; } @@ -858,6 +891,9 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio (void)add_name_to_subnet( subrec, question->name, question->name_type, nb_flags, ttl, REGISTER_NAME, 1, &from_ip ); + if ((namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME))) { + wins_hook("add", namerec, ttl); + } send_wins_name_registration_response(0, ttl, p); } @@ -916,6 +952,7 @@ a subsequent IP addess.\n", nmb_namestr(question_name) )); add_ip_to_name_record(namerec, from_ip); update_name_ttl(namerec, ttl); send_wins_name_registration_response(0, ttl, orig_reg_packet); + wins_hook("add", namerec, ttl); orig_reg_packet->locked = False; free_packet(orig_reg_packet); @@ -1082,11 +1119,16 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio * It's one of our names and one of our IP's. Ensure the IP is in the record and * update the ttl. */ - if(!find_ip_in_name_record(namerec, from_ip)) - add_ip_to_name_record(namerec, from_ip); - update_name_ttl(namerec, ttl); - send_wins_name_registration_response(0, ttl, p); - return; + if(!find_ip_in_name_record(namerec, from_ip)) { + add_ip_to_name_record(namerec, from_ip); + wins_hook("add", namerec, ttl); + } else { + wins_hook("refresh", namerec, ttl); + } + + update_name_ttl(namerec, ttl); + send_wins_name_registration_response(0, ttl, p); + return; } } @@ -1099,6 +1141,7 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio { update_name_ttl(namerec, ttl); send_wins_name_registration_response(0, ttl, p); + wins_hook("refresh", namerec, ttl); return; } @@ -1158,6 +1201,10 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio (void)add_name_to_subnet( subrec, question->name, question->name_type, nb_flags, ttl, REGISTER_NAME, 1, &from_ip ); + if ((namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME))) { + wins_hook("add", namerec, ttl); + } + send_wins_name_registration_response(0, ttl, p); } @@ -1253,7 +1300,7 @@ void send_wins_name_query_response(int rcode, struct packet_struct *p, int ttl = 0; int i; - bzero(rdata,6); + memset(rdata,'\0',6); if(rcode == 0) { @@ -1495,6 +1542,8 @@ release name %s as IP %s is not one of the known IP's for this name.\n", send_wins_name_release_response(0, p); remove_ip_from_name_record(namerec, from_ip); + wins_hook("delete", namerec, 0); + /* * Remove the name entirely if no IP addresses left. */ @@ -1552,7 +1601,7 @@ void wins_write_database(BOOL background) } slprintf(fname,sizeof(fname),"%s/%s", lp_lockdir(), WINS_LIST); - string_sub(fname,"//", "/"); + all_string_sub(fname,"//", "/", 0); slprintf(fnamenew,sizeof(fnamenew),"%s.%u", fname, (unsigned int)getpid()); if((fp = sys_fopen(fnamenew,"w")) == NULL) diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 0f66b140a8..5514e78dc1 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -43,26 +43,9 @@ int workgroup_count = 0; /* unique index key: one for each workgroup */ static void add_workgroup(struct subnet_record *subrec, struct work_record *work) { - struct work_record *w2; - - work->subnet = subrec; - - if (!subrec->workgrouplist) - { - subrec->workgrouplist = work; - work->prev = NULL; - work->next = NULL; - return; - } - - for (w2 = subrec->workgrouplist; w2->next; w2 = w2->next) - ; - - w2->next = work; - work->next = NULL; - work->prev = w2; - - subrec->work_changed = True; + work->subnet = subrec; + DLIST_ADD(subrec->workgrouplist, work); + subrec->work_changed = True; } /**************************************************************************** @@ -80,7 +63,7 @@ static struct work_record *create_workgroup(char *name, int ttl) DEBUG(0,("create_workgroup: malloc fail !\n")); return NULL; } - bzero((char *)work, sizeof(*work)); + memset((char *)work, '\0', sizeof(*work)); StrnCpy(work->work_group,name,sizeof(work->work_group)-1); work->serverlist = NULL; @@ -254,7 +237,8 @@ void initiate_myworkgroup_startup(struct subnet_record *subrec, struct work_reco if we are so configured. */ if ((subrec != unicast_subnet) && (subrec != remote_broadcast_subnet) && - (subrec != wins_server_subnet) && lp_preferred_master()) + (subrec != wins_server_subnet) && lp_preferred_master() && + lp_local_master()) { DEBUG(3, ("initiate_myworkgroup_startup: preferred master startup for \ workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name)); @@ -283,7 +267,8 @@ workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name)); SV_TYPE_DOMAIN_MASTER|SV_TYPE_DOMAIN_MEMBER); create_server_on_workgroup(work,name,stype|SV_TYPE_LOCAL_LIST_ONLY, - PERMANENT_TTL, lp_serverstring()); + PERMANENT_TTL, + string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH)); DEBUG(3,("initiate_myworkgroup_startup: Added server name entry %s \ on subnet %s\n", name, subrec->subnet_name)); } -- cgit From 9a781a8c6de9513ba5f4cafef41379fae96807c1 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 2 Jan 2000 23:00:27 +0000 Subject: - added tdb_flags option to tdb_open() - added TDB_CLEAR_IF_FIRST flag to clear the database if this is the first attached process. Useful for non-persistent databases like our locking area (this will also make upgrades to new database layouts easier) - use lock_path() in a couple of places - leave connections database open while smbd running - cleaned up some tdb code a little, using macros for constants (This used to be commit 00e9da3ca577527db392aced62f02c69cfee8f4f) --- source3/nmbd/nmbd_namelistdb.c | 10 ++-------- source3/nmbd/nmbd_winsserver.c | 10 ++-------- 2 files changed, 4 insertions(+), 16 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index dbb8be1f2d..e2433f42d3 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -602,21 +602,15 @@ static void dump_subnet_namelist( struct subnet_record *subrec, FILE *fp) void dump_all_namelists(void) { - pstring fname; FILE *fp; struct subnet_record *subrec; - pstrcpy(fname,lp_lockdir()); - trim_string(fname,NULL,"/"); - pstrcat(fname,"/"); - pstrcat(fname,"namelist.debug"); - - fp = sys_fopen(fname,"w"); + fp = sys_fopen(lock_path("namelist.debug"),"w"); if (!fp) { DEBUG(0,("dump_all_namelists: Can't open file %s. Error was %s\n", - fname,strerror(errno))); + "namelist.debug",strerror(errno))); return; } diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 45e9335167..d1a100aaea 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -172,7 +172,6 @@ Load or create the WINS database. BOOL initialise_wins(void) { - pstring fname; time_t time_now = time(NULL); FILE *fp; pstring line; @@ -182,15 +181,10 @@ BOOL initialise_wins(void) add_samba_names_to_subnet(wins_server_subnet); - pstrcpy(fname,lp_lockdir()); - trim_string(fname,NULL,"/"); - pstrcat(fname,"/"); - pstrcat(fname,WINS_LIST); - - if((fp = sys_fopen(fname,"r")) == NULL) + if((fp = sys_fopen(lock_path(WINS_LIST),"r")) == NULL) { DEBUG(2,("initialise_wins: Can't open wins database file %s. Error was %s\n", - fname, strerror(errno) )); + WINS_LIST, strerror(errno) )); return True; } -- cgit From 574788039f53fada4769731ea3fafe9710417b71 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 3 Jan 2000 03:17:16 +0000 Subject: added the unexpected packet database (unexpected.tdb) this means "nmblookup -S" now always works, even with broken servers the database stores all unexpected replies and these can be accessed by any client. while doing this I cleaned up a couple of functions, and put in place a better trn_id generator. in most places the code got quite a bit simpler due to the addition of simple helper functions. I haven't yet put the code in to take advantage of this for pdc replies - that will be next. Jeremys pdc finding code will then work :) (This used to be commit 280e6359d36c9bc8dcded302f15c3a1db8e3feeb) --- source3/nmbd/nmbd.c | 5 +++++ source3/nmbd/nmbd_packets.c | 3 ++- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 533c06351f..3ba8acc5e0 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -457,6 +457,11 @@ static void process(void) */ sync_all_dmbs(t); + /* + * clear the unexpected packet queue + */ + clear_unexpected(t); + /* * Reload the services file if we got a sighup. */ diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 0a7696a466..77bdb29816 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1402,8 +1402,9 @@ static struct subnet_record *find_subnet_for_nmb_packet( struct packet_struct *p rrec = find_response_record( &subrec, nmb->header.name_trn_id); if(rrec == NULL) { - DEBUG(0,("find_subnet_for_nmb_packet: response record not found for response id %hu\n", + DEBUG(3,("find_subnet_for_nmb_packet: response record not found for response id %hu\n", nmb->header.name_trn_id)); + unexpected_packet(p); return NULL; } -- cgit From d705b62141d092a5a9ca4e905bab2d1f1a1c3e9e Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 3 Jan 2000 03:31:41 +0000 Subject: got rid of mem_man yamd is much better, and doesn't require any source code changes if you haven't seen yamd then take a look at http://www3.hmc.edu/~neldredge/yamd/ its excellent! (This used to be commit 25b13f8b79d648188036f027f45bc78ec117cc88) --- source3/nmbd/nmbd.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 3ba8acc5e0..751aede394 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -674,7 +674,6 @@ static void usage(char *pname) /* If we are using the malloc debug code we can't use SIGUSR1 and SIGUSR2 to do debug level changes. */ -#ifndef MEM_MAN #if defined(SIGUSR1) CatchSignal( SIGUSR1, SIGNAL_CAST sig_usr1 ); #endif /* SIGUSR1 */ @@ -682,7 +681,6 @@ static void usage(char *pname) #if defined(SIGUSR2) CatchSignal( SIGUSR2, SIGNAL_CAST sig_usr2 ); #endif /* SIGUSR2 */ -#endif /* MEM_MAN */ while( EOF != (opt = getopt( argc, argv, "Vaos:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:f:" )) ) -- cgit From 632b4f806eae15e319b8f62caef5d25634cf720c Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 3 Jan 2000 06:30:50 +0000 Subject: added suppport for unexpected udp/138 packets I also fixed up the lookup_pdc_name() code so that it now works, even with a NT server that insists on replying to udp/138. The method I used to match packets was to use the mailslot string as a datagram ID. The true dgm_id doesn't work as NT doesn't set it correctly. uggh. PS: Jeremy, I had to change your code quite a bit, are you sure this worked with a Samba PDC?? The code looked broken, it got the offsets wrong in the SMB portion of the packet and filled in the IP incorrectly. (This used to be commit 32f66f4ea63038cb4b3785bdf1762abdde076f5d) --- source3/nmbd/nmbd_packets.c | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 77bdb29816..3bf009f2c2 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1204,7 +1204,6 @@ static BOOL listening(struct packet_struct *p,struct nmb_name *nbname) /**************************************************************************** Process udp 138 datagrams ****************************************************************************/ - static void process_dgram(struct packet_struct *p) { char *buf; @@ -1215,20 +1214,22 @@ static void process_dgram(struct packet_struct *p) /* If we aren't listening to the destination name then ignore the packet */ if (!listening(p,&dgram->dest_name)) { - DEBUG(5,("process_dgram: ignoring dgram packet sent to name %s from %s\n", - nmb_namestr(&dgram->dest_name), inet_ntoa(p->ip))); - return; + unexpected_packet(p); + DEBUG(5,("process_dgram: ignoring dgram packet sent to name %s from %s\n", + nmb_namestr(&dgram->dest_name), inet_ntoa(p->ip))); + return; } if (dgram->header.msg_type != 0x10 && dgram->header.msg_type != 0x11 && dgram->header.msg_type != 0x12) { - /* Don't process error packets etc yet */ - DEBUG(5,("process_dgram: ignoring dgram packet sent to name %s from IP %s as it is \ - an error packet of type %x\n", - nmb_namestr(&dgram->dest_name), inet_ntoa(p->ip), dgram->header.msg_type)); - return; + unexpected_packet(p); + /* Don't process error packets etc yet */ + DEBUG(5,("process_dgram: ignoring dgram packet sent to name %s from IP %s as it is \ +an error packet of type %x\n", + nmb_namestr(&dgram->dest_name), inet_ntoa(p->ip), dgram->header.msg_type)); + return; } buf = &dgram->data[0]; @@ -1275,6 +1276,8 @@ static void process_dgram(struct packet_struct *p) process_logon_packet(p,buf2,len,NT_LOGON_MAILSLOT); return; } + + unexpected_packet(p); } /**************************************************************************** -- cgit From 5e9f5591873fc5c5b5c8dbb0e29a080b8afe9966 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 5 Jan 2000 06:36:36 +0000 Subject: implemented talloc() as described on samba-technical. This fixes the lp_string() bug properly. we still need to add lp_talloc_free() calls in all the main event loops, I've only put it in smbd and nmbd thus far. (This used to be commit aa7f81552540f5dca2c146f5edd805611d5b390f) --- source3/nmbd/nmbd.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 751aede394..5bb3d7fc00 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -475,6 +475,9 @@ static void process(void) /* check for new network interfaces */ reload_interfaces(t); + + /* free up temp memory */ + lp_talloc_free(); } } /* process */ -- cgit From 171da4d78736730557a94b44af9f2d62081b80ba Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Fri, 7 Jan 2000 06:55:36 +0000 Subject: this looks like a big commit, but it isn't really :) This fixes our netbios scope handling. We now have a 'netbios scope' option in smb.conf and the scope option is removed from make_nmb_name() this was prompted by a bug in our PDC finding code where it didn't append the scope to the query of the '*' name. (This used to be commit b563be824b8c3141c49558eced7829b48d4ab26f) --- source3/nmbd/nmbd.c | 11 ++--------- source3/nmbd/nmbd_become_dmb.c | 7 +++---- source3/nmbd/nmbd_become_lmb.c | 7 +++---- source3/nmbd/nmbd_browsesync.c | 17 +++++++---------- source3/nmbd/nmbd_elections.c | 6 ++---- source3/nmbd/nmbd_logonnames.c | 3 +-- source3/nmbd/nmbd_mynames.c | 11 +++++------ source3/nmbd/nmbd_namelistdb.c | 5 ++--- source3/nmbd/nmbd_namequery.c | 6 ++---- source3/nmbd/nmbd_nameregister.c | 3 +-- source3/nmbd/nmbd_namerelease.c | 2 -- source3/nmbd/nmbd_nodestatus.c | 2 -- source3/nmbd/nmbd_packets.c | 15 ++++++++------- source3/nmbd/nmbd_responserecordsdb.c | 1 - source3/nmbd/nmbd_synclists.c | 5 ++--- 15 files changed, 38 insertions(+), 63 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 5bb3d7fc00..cf472d579d 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -32,8 +32,6 @@ extern int DEBUGLEVEL; extern pstring debugf; pstring servicesf = CONFIGFILE; -extern pstring scope; - int ClientNMB = -1; int ClientDGRAM = -1; int global_nmb_port = -1; @@ -606,7 +604,7 @@ static void usage(char *pname) { printf( "Usage: %s [-DaohV] [-H lmhosts file] [-d debuglevel] [-l log basename]\n", pname ); - printf( " [-n name] [-p port] [-s configuration file] [-i scope]\n" ); + printf( " [-n name] [-p port] [-s configuration file]\n" ); printf( "\t-D Become a daemon\n" ); printf( "\t-a Append to log file (default)\n" ); printf( "\t-o Overwrite log file, don't append\n" ); @@ -618,7 +616,6 @@ static void usage(char *pname) printf( "\t-n netbiosname. Primary netbios name\n" ); printf( "\t-p port Listen on the specified port\n" ); printf( "\t-s configuration file Configuration file name\n" ); - printf( "\t-i scope NetBIOS scope\n" ); printf( "\n"); } /* usage */ @@ -686,7 +683,7 @@ static void usage(char *pname) #endif /* SIGUSR2 */ while( EOF != - (opt = getopt( argc, argv, "Vaos:T:I:C:bAi:B:N:Rn:l:d:Dp:hSH:G:f:" )) ) + (opt = getopt( argc, argv, "Vaos:T:I:C:bAB:N:Rn:l:d:Dp:hSH:G:f:" )) ) { switch (opt) { @@ -710,10 +707,6 @@ static void usage(char *pname) case 'l': slprintf(debugf,sizeof(debugf)-1, "%s.nmb",optarg); break; - case 'i': - pstrcpy(scope,optarg); - strupper(scope); - break; case 'a': append_log = True; break; diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index ae809607dc..76d92c2f3e 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -26,7 +26,6 @@ extern int DEBUGLEVEL; -extern pstring scope; extern pstring global_myname; extern fstring global_myworkgroup; extern char **my_netbios_names; @@ -133,7 +132,7 @@ in workgroup %s on subnet %s\n", will stop us syncing with ourself if we are also a local master browser. */ - make_nmb_name(&nmbname, global_myname, 0x20, scope); + make_nmb_name(&nmbname, global_myname, 0x20); work->dmb_name = nmbname; /* Pick the first interface ip address as the domain master browser ip. */ @@ -282,7 +281,7 @@ static void become_domain_master_browser_bcast(char *workgroup_name) if (work && (work->dom_state == DOMAIN_NONE)) { struct nmb_name nmbname; - make_nmb_name(&nmbname,workgroup_name,0x1b,scope); + make_nmb_name(&nmbname,workgroup_name,0x1b); /* * Check for our name on the given broadcast subnet first, only initiate @@ -330,7 +329,7 @@ static void become_domain_master_browser_wins(char *workgroup_name) { struct nmb_name nmbname; - make_nmb_name(&nmbname,workgroup_name,0x1b,scope); + make_nmb_name(&nmbname,workgroup_name,0x1b); /* * Check for our name on the unicast subnet first, only initiate diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index f3fa69132e..31c67ae7f3 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -25,7 +25,6 @@ #include "includes.h" extern int DEBUGLEVEL; -extern pstring scope; extern pstring global_myname; extern uint16 samba_nb_type; /* Samba's NetBIOS name type. */ @@ -126,7 +125,7 @@ in workgroup %s on subnet %s\n", * master browser. */ - make_nmb_name(&nmbname, work->work_group, 0x1d, scope); + make_nmb_name(&nmbname, work->work_group, 0x1d); remove_permanent_name_from_unicast( subrec, &nmbname); @@ -208,7 +207,7 @@ static void release_1d_name( struct subnet_record *subrec, char *workgroup_name, struct nmb_name nmbname; struct name_record *namerec; - make_nmb_name(&nmbname, workgroup_name, 0x1d, scope); + make_nmb_name(&nmbname, workgroup_name, 0x1d); if((namerec = find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME))!=NULL) { struct userdata_struct *userdata; @@ -308,7 +307,7 @@ in workgroup %s on subnet %s\n", release_1d_name( subrec, work->work_group, force_new_election); /* Deregister any browser names we may have. */ - make_nmb_name(&nmbname, MSBROWSE, 0x1, scope); + make_nmb_name(&nmbname, MSBROWSE, 0x1); if((namerec = find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME))!=NULL) { release_name(subrec, namerec, diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index b177fb524e..23ca0a398f 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -26,7 +26,6 @@ #include "smb.h" extern int DEBUGLEVEL; -extern pstring scope; extern struct in_addr ipzero; extern pstring global_myname; extern fstring global_myworkgroup; @@ -226,7 +225,7 @@ static void domain_master_node_status_success(struct subnet_record *subrec, { struct nmb_name nmbname; - make_nmb_name(&nmbname, qname, name_type, scope); + make_nmb_name(&nmbname, qname, name_type); /* Copy the dmb name and IP address into the workgroup struct. */ @@ -324,8 +323,7 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec, putip((char *)&work->dmb_addr, &ipzero); /* Now initiate the node status request. */ - memset((char *)&nmbname, '\0',sizeof(nmbname)); - nmbname.name[0] = '*'; + make_nmb_name(&nmbname,"*",0x0); /* Put the workgroup name into the userdata so we know what workgroup we're talking to when the reply comes @@ -391,7 +389,7 @@ void announce_and_sync_with_domain_master_browser( struct subnet_record *subrec, return; } - make_nmb_name(&nmbname,work->work_group,0x1b,scope); + make_nmb_name(&nmbname,work->work_group,0x1b); /* First, query for the WORKGROUP<1b> name from the WINS server. */ query_name(unicast_subnet, nmbname.name, nmbname.name_type, @@ -486,7 +484,7 @@ static void get_domain_master_name_node_status_success(struct subnet_record *sub /* remember who the master is */ fstrcpy(work->local_master_browser_name, server_name); - make_nmb_name(&nmbname, server_name, 0x20, scope); + make_nmb_name(&nmbname, server_name, 0x20); work->dmb_name = nmbname; work->dmb_addr = from_ip; } @@ -549,8 +547,7 @@ static void find_all_domain_master_names_query_success(struct subnet_record *sub for(i = 0; i < rrec->rdlength / 6; i++) { /* Initiate the node status requests. */ - memset((char *)&nmbname, '\0', sizeof(nmbname)); - nmbname.name[0] = '*'; + make_nmb_name(&nmbname, "*", 0); putip((char *)&send_ip, (char *)&rrec->rdata[(i*6) + 2]); @@ -636,7 +633,7 @@ void collect_all_workgroup_names_from_wins_server(time_t t) lastrun = t; - make_nmb_name(&nmbname,"*",0x1b,scope); + make_nmb_name(&nmbname,"*",0x1b); /* First, query for the *<1b> name from the WINS server. */ query_name(unicast_subnet, nmbname.name, nmbname.name_type, @@ -694,7 +691,7 @@ void sync_all_dmbs(time_t t) the same as the unicast local master */ make_nmb_name(&work->dmb_name, work->local_master_browser_name, - 0x20, scope); + 0x20); } DEBUG(3,("Initiating DMB<->DMB sync with %s(%s)\n", diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 8e1605dbba..be38b572f6 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -26,8 +26,6 @@ extern int DEBUGLEVEL; -extern pstring scope; - extern pstring global_myname; extern fstring global_myworkgroup; @@ -194,7 +192,7 @@ void run_elections(time_t t) */ struct nmb_name nmbname; - make_nmb_name(&nmbname, work->work_group, 0x1e, scope); + make_nmb_name(&nmbname, work->work_group, 0x1e); if(find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME)==NULL) { DEBUG(8,("run_elections: Cannot send election packet yet as name %s not \ yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name )); @@ -365,7 +363,7 @@ BOOL check_elections(void) */ struct nmb_name nmbname; - make_nmb_name(&nmbname, work->work_group, 0x1e, scope); + make_nmb_name(&nmbname, work->work_group, 0x1e); if(find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME)==NULL) { DEBUG(8,("check_elections: Cannot send election packet yet as name %s not \ yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name )); diff --git a/source3/nmbd/nmbd_logonnames.c b/source3/nmbd/nmbd_logonnames.c index 471a64377d..c63de56a34 100644 --- a/source3/nmbd/nmbd_logonnames.c +++ b/source3/nmbd/nmbd_logonnames.c @@ -26,7 +26,6 @@ extern int DEBUGLEVEL; -extern pstring scope; extern pstring global_myname; extern fstring global_myworkgroup; extern char **my_netbios_names; @@ -152,7 +151,7 @@ void add_logon_names(void) if (work && (work->log_state == LOGON_NONE)) { struct nmb_name nmbname; - make_nmb_name(&nmbname,global_myworkgroup,0x1c,scope); + make_nmb_name(&nmbname,global_myworkgroup,0x1c); if (find_name_on_subnet(subrec, &nmbname, FIND_SELF_NAME) == NULL) { diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index c36df21e7b..7ea8ffc946 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -28,7 +28,6 @@ extern int DEBUGLEVEL; extern char **my_netbios_names; extern fstring global_myworkgroup; -extern pstring scope; extern uint16 samba_nb_type; /* Samba's NetBIOS type. */ @@ -119,13 +118,13 @@ BOOL register_my_workgroup_and_names(void) */ struct nmb_name nmbname; - make_nmb_name(&nmbname, my_netbios_names[i],0x20, scope); + make_nmb_name(&nmbname, my_netbios_names[i],0x20); insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type); - make_nmb_name(&nmbname, my_netbios_names[i],0x3, scope); + make_nmb_name(&nmbname, my_netbios_names[i],0x3); insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type); - make_nmb_name(&nmbname, my_netbios_names[i],0x0, scope); + make_nmb_name(&nmbname, my_netbios_names[i],0x0); insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type); } } @@ -142,10 +141,10 @@ BOOL register_my_workgroup_and_names(void) */ struct nmb_name nmbname; - make_nmb_name(&nmbname, global_myworkgroup, 0x0, scope); + make_nmb_name(&nmbname, global_myworkgroup, 0x0); insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP); - make_nmb_name(&nmbname, global_myworkgroup, 0x1e, scope); + make_nmb_name(&nmbname, global_myworkgroup, 0x1e); insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP); } } diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index e2433f42d3..15328af33e 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -26,7 +26,6 @@ extern int DEBUGLEVEL; -extern pstring scope; extern char **my_netbios_names; uint16 samba_nb_type = 0; /* samba's NetBIOS name type */ @@ -213,8 +212,8 @@ struct name_record *add_name_to_subnet( struct subnet_record *subrec, namerec->subnet = subrec; - make_nmb_name( &namerec->name, name, type, scope ); - upcase_name( &namerec->name, NULL ); + make_nmb_name(&namerec->name, name, type); + upcase_name(&namerec->name, NULL ); /* Enter the name as active. */ namerec->data.nb_flags = nb_flags | NB_ACTIVE; diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index 8c41554842..57baa4cb2f 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -26,8 +26,6 @@ extern int DEBUGLEVEL; -extern pstring scope; - /**************************************************************************** Deal with a response packet when querying a name. ****************************************************************************/ @@ -180,7 +178,7 @@ BOOL query_name(struct subnet_record *subrec, char *name, int type, struct nmb_name nmbname; struct name_record *namerec; - make_nmb_name(&nmbname, name, type, scope); + make_nmb_name(&nmbname, name, type); /* * We need to check our local namelists first. @@ -247,7 +245,7 @@ BOOL query_name_from_wins_server(struct in_addr ip_to, { struct nmb_name nmbname; - make_nmb_name(&nmbname, name, type, scope); + make_nmb_name(&nmbname, name, type); if(queue_query_name_from_wins_server( ip_to, query_name_response, diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index 1e819cc88f..8805728737 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -26,7 +26,6 @@ extern int DEBUGLEVEL; -extern pstring scope; extern fstring global_myworkgroup; /**************************************************************************** @@ -333,7 +332,7 @@ BOOL register_name(struct subnet_record *subrec, { struct nmb_name nmbname; - make_nmb_name(&nmbname, name, type, scope); + make_nmb_name(&nmbname, name, type); /* Always set the NB_ACTIVE flag on the name we are registering. Doesn't make sense without it. diff --git a/source3/nmbd/nmbd_namerelease.c b/source3/nmbd/nmbd_namerelease.c index 1cdc78e6a0..2e3b4e8c6a 100644 --- a/source3/nmbd/nmbd_namerelease.c +++ b/source3/nmbd/nmbd_namerelease.c @@ -26,8 +26,6 @@ extern int DEBUGLEVEL; -extern pstring scope; - /**************************************************************************** Deal with a response packet when releasing one of our names. ****************************************************************************/ diff --git a/source3/nmbd/nmbd_nodestatus.c b/source3/nmbd/nmbd_nodestatus.c index d8af09b398..d78f8a5547 100644 --- a/source3/nmbd/nmbd_nodestatus.c +++ b/source3/nmbd/nmbd_nodestatus.c @@ -26,8 +26,6 @@ extern int DEBUGLEVEL; -extern pstring scope; - /**************************************************************************** Deal with a successful node status response. ****************************************************************************/ diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 3bf009f2c2..428758ada3 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -32,7 +32,6 @@ extern int DEBUGLEVEL; extern int num_response_packets; -extern pstring scope; extern struct in_addr loopback_ip; static void queue_packet(struct packet_struct *packet); @@ -1026,14 +1025,15 @@ static void process_browse_packet(struct packet_struct *p, char *buf,int len) struct dgram_packet *dgram = &p->packet.dgram; int command = CVAL(buf,0); struct subnet_record *subrec = find_subnet_for_dgram_browse_packet(p); + extern pstring global_scope; /* Drop the packet if it's a different NetBIOS scope, or the source is from one of our names. */ - if (!strequal(dgram->dest_name.scope,scope )) + if (!strequal(dgram->dest_name.scope, global_scope)) { DEBUG(7,("process_browse_packet: Discarding datagram from IP %s. Scope (%s) \ -mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, scope)); +mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, global_scope)); return; } @@ -1138,14 +1138,15 @@ static void process_lanman_packet(struct packet_struct *p, char *buf,int len) struct dgram_packet *dgram = &p->packet.dgram; int command = SVAL(buf,0); struct subnet_record *subrec = find_subnet_for_dgram_browse_packet(p); + extern pstring global_scope; /* Drop the packet if it's a different NetBIOS scope, or the source is from one of our names. */ - if (!strequal(dgram->dest_name.scope,scope )) + if (!strequal(dgram->dest_name.scope, global_scope)) { DEBUG(7,("process_lanman_packet: Discarding datagram from IP %s. Scope (%s) \ -mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, scope)); +mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, global_scope)); return; } @@ -1927,8 +1928,8 @@ BOOL send_mailslot(BOOL unique, char *mailslot,char *buf,int len, dgram->header.dgm_length = 0; /* Let build_dgram() handle this. */ dgram->header.packet_offset = 0; - make_nmb_name(&dgram->source_name,srcname,src_type,scope); - make_nmb_name(&dgram->dest_name,dstname,dest_type,scope); + make_nmb_name(&dgram->source_name,srcname,src_type); + make_nmb_name(&dgram->dest_name,dstname,dest_type); ptr = &dgram->data[0]; diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index fe29464773..1b6e1ca16d 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -28,7 +28,6 @@ extern int ClientNMB; extern int DEBUGLEVEL; -extern pstring scope; extern struct in_addr ipzero; int num_response_packets = 0; diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index fb51be4d8f..7bf1790377 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -32,7 +32,6 @@ #include "smb.h" extern int DEBUGLEVEL; -extern pstring scope; struct sync_record { struct sync_record *next, *prev; @@ -77,8 +76,8 @@ static void sync_child(char *name, int nm_type, return; } - make_nmb_name(&calling, local_machine, 0x0 , scope); - make_nmb_name(&called , name , nm_type, scope); + make_nmb_name(&calling, local_machine, 0x0); + make_nmb_name(&called , name , nm_type); if (!cli_session_request(&cli, &calling, &called)) { -- cgit From 40122f6e32627f2afaad0e66eb2f5f6eaa56a4e0 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 28 Jan 2000 23:47:31 +0000 Subject: Modified auto alignment of ud[] struct on stack to be declared as an array of pointers. This should cause alignment on a correct boundary.. Spotted by Darren Reed . Jeremy. (This used to be commit 91f4d0675333d7c5d7bb5ff077faaf83e1fd9bfe) --- source3/nmbd/nmbd_winsproxy.c | 4 ++-- source3/nmbd/nmbd_winsserver.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index 1398ebd299..24ba192cdb 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -203,8 +203,8 @@ void make_wins_proxy_name_query_request( struct subnet_record *subrec, struct packet_struct *incoming_packet, struct nmb_name *question_name) { - char ud[sizeof(struct userdata_struct) + sizeof(struct subrec *) + - sizeof(struct packet_struct *)]; + long *ud[(sizeof(struct userdata_struct) + sizeof(struct subrec *) + + sizeof(struct packet_struct *))/sizeof(long *) + 1]; struct userdata_struct *userdata = (struct userdata_struct *)ud; memset(ud, '\0', sizeof(ud)); diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index d1a100aaea..e978718106 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -838,7 +838,7 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio if( namerec != NULL ) { - char ud[sizeof(struct userdata_struct) + sizeof(struct packet_struct *)]; + long *ud[(sizeof(struct userdata_struct) + sizeof(struct packet_struct *))/sizeof(long *) + 1]; struct userdata_struct *userdata = (struct userdata_struct *)ud; /* @@ -1146,7 +1146,7 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio if(namerec != NULL) { - char ud[sizeof(struct userdata_struct) + sizeof(struct packet_struct *)]; + long *ud[(sizeof(struct userdata_struct) + sizeof(struct packet_struct *))/sizeof(long *) + 1]; struct userdata_struct *userdata = (struct userdata_struct *)ud; /* -- cgit From f7324464b1adcac67e620a75f2fd51ef8e615173 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Tue, 22 Feb 2000 21:00:01 +0000 Subject: richard got the short request for GETDC right (hooray!) win9x _and_ nt now work. (This used to be commit 27ef1789267c7af70071ac9b1d216b4dd745578a) --- source3/nmbd/nmbd_processlogon.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 279ab1c764..e13dff8302 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -44,10 +44,11 @@ void process_logon_packet(struct packet_struct *p,char *buf,int len, pstring outbuf; int code; uint16 token = 0; - uint32 ntversion; - uint16 lmnttoken; - uint16 lm20token; + uint32 ntversion = 0; + uint16 lmnttoken = 0; + uint16 lm20token = 0; uint32 domainsidsize; + BOOL short_request = 0; char *getdc; char *uniuser; /* Unicode user name. */ pstring ascuser; @@ -120,12 +121,21 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); q = skip_unicode_string(q, 1); - ntversion = IVAL(q, 0); - q += 4; - lmnttoken = SVAL(q, 0); - q += 2; - lm20token = SVAL(q, 0); - q += 2; + if ((buf - q) >= len) { /* Check for a short request */ + + short_request = 1; + + } + else { /* A full length request */ + + ntversion = IVAL(q, 0); + q += 4; + lmnttoken = SVAL(q, 0); + q += 2; + lm20token = SVAL(q, 0); + q += 2; + + } /* Construct reply. */ @@ -135,10 +145,11 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); fstrcpy(reply_name,my_name); fstrcpy(q, reply_name); - q = skip_string(q, 1); /* PDC name */ - if (strcmp(mailslot, NT_LOGON_MAILSLOT)==0) { + /* PDC and domain name */ + if (!short_request) /* Make a full reply */ + { q = align2(q, buf); dos_PutUniCode(q, my_name, sizeof(pstring)); /* PDC name */ @@ -155,6 +166,8 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); q += 2; } + /* RJS, 21-Feb-2000, we send a short reply if the request was short */ + DEBUG(3,("process_logon_packet: GETDC request from %s at IP %s, \ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", machine,inet_ntoa(p->ip), reply_name, lp_workgroup(), -- cgit From 9db96b7646aa36aa5b4ff309419235fe20bef78a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 23 Feb 2000 02:02:33 +0000 Subject: lib/system.c: Fixed gcc warnings. nmbd/nmbd_processlogon.c: Use "True" and "False" instead of 1 and 0. Others - preparing for multiple pdu write code. Jeremy. (This used to be commit 9f879ec396230deba34fbe5e82d8a65f92137c54) --- source3/nmbd/nmbd_processlogon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index e13dff8302..d3b7f92fc7 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -48,7 +48,7 @@ void process_logon_packet(struct packet_struct *p,char *buf,int len, uint16 lmnttoken = 0; uint16 lm20token = 0; uint32 domainsidsize; - BOOL short_request = 0; + BOOL short_request = False; char *getdc; char *uniuser; /* Unicode user name. */ pstring ascuser; @@ -123,7 +123,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); if ((buf - q) >= len) { /* Check for a short request */ - short_request = 1; + short_request = True; } else { /* A full length request */ -- cgit From b18791b860e7d1f21f06e8b6b843ffbf1c1d101b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 26 Mar 2000 23:13:12 +0000 Subject: merge from tng ... reload services can be static (This used to be commit b13a903720a6ef789ee7d688c05be2e77584580e) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index cf472d579d..60e7b13b2c 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -246,7 +246,7 @@ static void reload_interfaces(time_t t) /**************************************************************************** ** reload the services file **************************************************************************** */ -BOOL reload_services(BOOL test) +static BOOL reload_services(BOOL test) { BOOL ret; extern fstring remote_machine; -- cgit From 4e7af2b3b580b2b580ca65bc96266d1a9b627f9d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 26 Mar 2000 23:16:07 +0000 Subject: when doing a "secure nbns" wack response and check with owner for a multihomed registration we were sending the packet to the wrong host! We sent it to the person trying to register rather than to the person who currently holds the name. That means we were not secure and we could allow two people to register the same name. Jeremy, you may wish to merge this change into 2.0.X (This used to be commit 94ca1d1250d12918311a402cc689050ba1d06e24) --- source3/nmbd/nmbd_winsserver.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index e978718106..2b99a8ce53 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1176,9 +1176,12 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio * the recursion desired flag is not set (you were right Luke :-). * This function should *only* be called from the WINS server * code. JRA. + * + * Note that this packet is sent to the current owner of the name, + * not the person who sent the packet */ - query_name_from_wins_server( p->ip, + query_name_from_wins_server( namerec->data.ip[0], question->name, question->name_type, wins_multihomed_register_query_success, -- cgit From 3a290ce80c6d6fc117127e46b2741bba2abff34d Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Mon, 27 Mar 2000 00:52:33 +0000 Subject: rename static reload_services function to reload_nmbd_services because it clashes with other reload_services definitions. (This used to be commit affaf9c5411e533a77621574d356e886eea93465) --- source3/nmbd/nmbd.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 60e7b13b2c..a7cf7560b3 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -246,7 +246,7 @@ static void reload_interfaces(time_t t) /**************************************************************************** ** reload the services file **************************************************************************** */ -static BOOL reload_services(BOOL test) +static BOOL reload_nmbd_services(BOOL test) { BOOL ret; extern fstring remote_machine; @@ -273,7 +273,7 @@ static BOOL reload_services(BOOL test) if ( !test ) { DEBUG( 3, ( "services not loaded\n" ) ); - reload_services( True ); + reload_nmbd_services( True ); } /* Do a sanity check for a misconfigured nmbd */ @@ -285,7 +285,7 @@ cannot be set in the smb.conf file. nmbd aborting.\n")); } return(ret); -} /* reload_services */ +} /* reload_nmbd_services */ /**************************************************************************** ** The main select loop. @@ -465,7 +465,7 @@ static void process(void) */ if(reload_after_sighup) { - reload_services( True ); + reload_nmbd_services( True ); reopen_logs(); reload_interfaces(0); reload_after_sighup = False; @@ -746,7 +746,7 @@ static void usage(char *pname) DEBUG( 1, ( "Netbios nameserver version %s started.\n", VERSION ) ); DEBUGADD( 1, ( "Copyright Andrew Tridgell 1994-1998\n" ) ); - if ( !reload_services(False) ) + if ( !reload_nmbd_services(False) ) return(-1); codepage_initialise(lp_client_code_page()); @@ -754,7 +754,7 @@ static void usage(char *pname) if(!init_structs()) return -1; - reload_services( True ); + reload_nmbd_services( True ); fstrcpy( global_myworkgroup, lp_workgroup() ); -- cgit From 61302f54bdf327e6879297166d175ee8144fad25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 27 Mar 2000 08:34:26 +0000 Subject: fixed the hanlding of recursion desired when sending packets from nmbd. It does NOT follow the rule that packets to the wins server have rec_des set (I know that we have postulated this in the past). Please don't screw with this unless you do careful testing from WinXX clients. Luke and I spent a couple of hours today getting this right (it was wrong in both TNG and HEAD) (This used to be commit 9eda2e27b74d95975e481d92930ef87de7006919) --- source3/nmbd/nmbd_packets.c | 45 ++++++++++++++++++++++----------------------- 1 file changed, 22 insertions(+), 23 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 428758ada3..627bbea019 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -178,10 +178,15 @@ static BOOL send_netbios_packet(struct packet_struct *p) /*************************************************************************** Sets up the common elements of an outgoing NetBIOS packet. + + Note: do not attempt to rationalise whether rec_des should be set or not + in a particular situation. Just follow rfc_1002 or look at examples from WinXX. + It does NOT follow the rule that requests to the wins server always have + rec_des true. See for example name releases and refreshes **************************************************************************/ static struct packet_struct *create_and_init_netbios_packet(struct nmb_name *nmbname, - BOOL bcast, + BOOL bcast, BOOL rec_des, struct in_addr to_ip) { struct packet_struct *packet = NULL; @@ -200,7 +205,7 @@ static struct packet_struct *create_and_init_netbios_packet(struct nmb_name *nmb nmb->header.name_trn_id = generate_name_trn_id(); nmb->header.response = False; - nmb->header.nm_flags.recursion_desired = False; + nmb->header.nm_flags.recursion_desired = rec_des; nmb->header.nm_flags.recursion_available = False; nmb->header.nm_flags.trunc = False; nmb->header.nm_flags.authoritative = False; @@ -472,13 +477,14 @@ struct response_record *queue_register_name( struct subnet_record *subrec, { struct packet_struct *p; struct response_record *rrec; - BOOL bcast = (subrec == unicast_subnet) ? False : True; if(assert_check_subnet(subrec)) return NULL; - if(( p = create_and_init_netbios_packet(nmbname, bcast, - subrec->bcast_ip)) == NULL) + /* note that all name registration requests have RD set (rfc1002 - + section 4.2.2 */ + if ((p = create_and_init_netbios_packet(nmbname, (subrec != unicast_subnet), True, + subrec->bcast_ip)) == NULL) return NULL; if(initiate_name_register_packet( p, nb_flags, @@ -521,7 +527,6 @@ struct response_record *queue_register_multihomed_name( struct subnet_record *su { struct packet_struct *p; struct response_record *rrec; - BOOL bcast = False; BOOL ret; /* Sanity check. */ @@ -535,8 +540,8 @@ unicast subnet. subnet is %s\n.", subrec->subnet_name )); if(assert_check_subnet(subrec)) return NULL; - if(( p = create_and_init_netbios_packet(nmbname, bcast, - subrec->bcast_ip)) == NULL) + if(( p = create_and_init_netbios_packet(nmbname, False, True, + subrec->bcast_ip)) == NULL) return NULL; if (nb_flags & NB_GROUP) @@ -581,14 +586,13 @@ struct response_record *queue_release_name( struct subnet_record *subrec, uint16 nb_flags, struct in_addr release_ip) { - BOOL bcast = (subrec == unicast_subnet) ? False : True; struct packet_struct *p; struct response_record *rrec; if(assert_check_subnet(subrec)) return NULL; - if(( p = create_and_init_netbios_packet(nmbname, bcast, + if(( p = create_and_init_netbios_packet(nmbname, (subrec != unicast_subnet), False, subrec->bcast_ip)) == NULL) return NULL; @@ -639,14 +643,13 @@ struct response_record *queue_refresh_name( struct subnet_record *subrec, struct name_record *namerec, struct in_addr refresh_ip) { - BOOL bcast = (subrec == unicast_subnet) ? False : True; struct packet_struct *p; struct response_record *rrec; if(assert_check_subnet(subrec)) return NULL; - if(( p = create_and_init_netbios_packet(&namerec->name, bcast, + if(( p = create_and_init_netbios_packet(&namerec->name, (subrec != unicast_subnet), False, subrec->bcast_ip)) == NULL) return NULL; @@ -687,16 +690,14 @@ struct response_record *queue_query_name( struct subnet_record *subrec, { struct packet_struct *p; struct response_record *rrec; - BOOL bcast = True; - if ((subrec == unicast_subnet) || (subrec == wins_server_subnet)) - bcast = False; - if(assert_check_subnet(subrec)) return NULL; - if(( p = create_and_init_netbios_packet(nmbname, bcast, - subrec->bcast_ip)) == NULL) + if(( p = create_and_init_netbios_packet(nmbname, + (subrec != unicast_subnet), + (subrec == unicast_subnet), + subrec->bcast_ip)) == NULL) return NULL; if(initiate_name_query_packet( p ) == False) @@ -736,9 +737,8 @@ struct response_record *queue_query_name_from_wins_server( struct in_addr to_ip, { struct packet_struct *p; struct response_record *rrec; - BOOL bcast = False; - if(( p = create_and_init_netbios_packet(nmbname, bcast, to_ip)) == NULL) + if ((p = create_and_init_netbios_packet(nmbname, False, False, to_ip)) == NULL) return NULL; if(initiate_name_query_packet_from_wins_server( p ) == False) @@ -779,7 +779,6 @@ struct response_record *queue_node_status( struct subnet_record *subrec, { struct packet_struct *p; struct response_record *rrec; - BOOL bcast = False; /* Sanity check. */ if(subrec != unicast_subnet) @@ -792,8 +791,8 @@ unicast subnet. subnet is %s\n.", subrec->subnet_name )); if(assert_check_subnet(subrec)) return NULL; - if(( p = create_and_init_netbios_packet(nmbname, bcast, - send_ip)) == NULL) + if(( p = create_and_init_netbios_packet(nmbname, False, False, + send_ip)) == NULL) return NULL; if(initiate_node_status_packet(p) == False) -- cgit From 6570b48d73d4d6597cf8f17040cb57e8b16394dd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 27 Mar 2000 12:19:58 +0000 Subject: the final part of the nmbd merge between head and tng - this gets the GETDC stuff sorted out (This used to be commit f6b56ae93e47a54317f2711533ec8208d5cbc8a9) --- source3/nmbd/nmbd_packets.c | 9 +++--- source3/nmbd/nmbd_processlogon.c | 59 +++++++++++++++++++++++----------------- 2 files changed, 38 insertions(+), 30 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 627bbea019..a7c94f1544 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -592,7 +592,7 @@ struct response_record *queue_release_name( struct subnet_record *subrec, if(assert_check_subnet(subrec)) return NULL; - if(( p = create_and_init_netbios_packet(nmbname, (subrec != unicast_subnet), False, + if ((p = create_and_init_netbios_packet(nmbname, (subrec != unicast_subnet), False, subrec->bcast_ip)) == NULL) return NULL; @@ -621,10 +621,9 @@ struct response_record *queue_release_name( struct subnet_record *subrec, * This will cause us to remove the name asap. JRA. */ - if(bcast) - { - rrec->repeat_count = 0; - rrec->repeat_time = 0; + if (subrec != unicast_subnet) { + rrec->repeat_count = 0; + rrec->repeat_time = 0; } return rrec; diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index d3b7f92fc7..bc4c6ea127 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -117,28 +117,35 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); getdc = skip_string(machine,1); unicomp = skip_string(getdc,1); - q = align2(unicomp, buf); - - q = skip_unicode_string(q, 1); - - if ((buf - q) >= len) { /* Check for a short request */ - - short_request = True; - - } - else { /* A full length request */ - - ntversion = IVAL(q, 0); - q += 4; - lmnttoken = SVAL(q, 0); - q += 2; - lm20token = SVAL(q, 0); - q += 2; - + /* at this point we can work out if this is a W9X or NT style + request. Experiments show that the difference is wether the + packet ends here. For a W9X request we now end with a pair of + bytes (usually 0xFE 0xFF) whereas with NT we have two further + strings - the following is a simple way of detecting this */ + if (len - PTR_DIFF(unicomp, buf) > 3) { + short_request = True; + } else { + /* A full length (NT style) request */ + q = skip_unicode_string(unicomp, 1); + + if (len - PTR_DIFF(q, buf) > 8) { + /* with NT5 clients we can sometimes + get additional data - a length specificed string + containing the domain name, then 16 bytes of + data (no idea what it is) */ + int dom_len = CVAL(q, 0); + q++; + if (dom_len != 0) { + q += dom_len + 1; + } + q += 16; + } + ntversion = IVAL(q, 0); + lmnttoken = SVAL(q, 4); + lm20token = SVAL(q, 6); } /* Construct reply. */ - q = outbuf; SSVAL(q, 0, QUERYFORPDC_R); q += 2; @@ -159,11 +166,9 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); q = skip_unicode_string(q, 1); SIVAL(q, 0, ntversion); - q += 4; - SSVAL(q, 0, lmnttoken); - q += 2; - SSVAL(q, 0, lm20token); - q += 2; + SSVAL(q, 4, lmnttoken); + SSVAL(q, 6, lm20token); + q += 8; } /* RJS, 21-Feb-2000, we send a short reply if the request was short */ @@ -227,7 +232,11 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", /* Construct reply. */ q = outbuf; - SSVAL(q, 0, SAMLOGON_R); + if (SVAL(uniuser, 0) == 0) { + SSVAL(q, 0, SAMLOGON_UNK_R); /* user unknown */ + } else { + SSVAL(q, 0, SAMLOGON_R); + } q += 2; dos_PutUniCode(q, reply_name,sizeof(pstring)); -- cgit From 18bc76a0c6830358a137b4198e17b1b7ce92b9bf Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 27 Mar 2000 12:38:45 +0000 Subject: changed the definition of dos_PutUniCode the previous definition could result is us overflowing a buffer. The null termination was always added yet the size returned did not include the null termination. the new function takes a BOOL null_terminate, and always returns the total number of bytes consumed by the string. (This used to be commit 426c90433396a95033eefcc4af97603abc934221) --- source3/nmbd/nmbd_processlogon.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index bc4c6ea127..0886654de9 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -159,11 +159,8 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); { q = align2(q, buf); - dos_PutUniCode(q, my_name, sizeof(pstring)); /* PDC name */ - q = skip_unicode_string(q, 1); - - dos_PutUniCode(q, global_myworkgroup,sizeof(pstring)); /* Domain name*/ - q = skip_unicode_string(q, 1); + q += dos_PutUniCode(q, my_name, sizeof(pstring), True); /* PDC name */ + q += dos_PutUniCode(q, global_myworkgroup,sizeof(pstring), True); /* Domain name*/ SIVAL(q, 0, ntversion); SSVAL(q, 4, lmnttoken); @@ -239,12 +236,10 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", } q += 2; - dos_PutUniCode(q, reply_name,sizeof(pstring)); - q = skip_unicode_string(q, 1); + q += dos_PutUniCode(q, reply_name,sizeof(pstring), True); unistrcpy(q, uniuser); q = skip_unicode_string(q, 1); /* User name (workstation trust account) */ - dos_PutUniCode(q, lp_workgroup(),sizeof(pstring)); - q = skip_unicode_string(q, 1); /* Domain name. */ + q += dos_PutUniCode(q, lp_workgroup(),sizeof(pstring), True); SIVAL(q, 0, ntversion); q += 4; -- cgit From 1bb5664127992119b9f95d6269f2ae9fa534633b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 28 Mar 2000 03:03:34 +0000 Subject: damn, the test was the wrong way around for short_resuest (This used to be commit 1ac46c40118fce9443141ce19506d124a873b73d) --- source3/nmbd/nmbd_processlogon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 0886654de9..a0e747648c 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -122,7 +122,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); packet ends here. For a W9X request we now end with a pair of bytes (usually 0xFE 0xFF) whereas with NT we have two further strings - the following is a simple way of detecting this */ - if (len - PTR_DIFF(unicomp, buf) > 3) { + if (len - PTR_DIFF(unicomp, buf) <= 3) { short_request = True; } else { /* A full length (NT style) request */ -- cgit From 99665730764d825924b961cb4e39dbff2ed550b3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 29 Mar 2000 21:30:52 +0000 Subject: Cause nmbd to ignore loopback interface when constructing its interface list. This is done by default when interfaces are probed, but if someone explicitly adds 127.0.0.1 to the interfaces line for smbd, then nmbd would start to try and register names on it. This was not good :-(. Jeremy. (This used to be commit cc3ad825214686ad03dd4176d0c55290d1de6221) --- source3/nmbd/nmbd.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index a7cf7560b3..57d025c660 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -192,6 +192,7 @@ static void reload_interfaces(time_t t) int n; struct subnet_record *subrec; extern BOOL rescan_listen_set; + extern struct in_addr loopback_ip; if (t && ((t - lastt) < NMBD_INTERFACES_RELOAD)) return; lastt = t; @@ -205,10 +206,23 @@ static void reload_interfaces(time_t t) /* find any interfaces that need adding */ for (n=iface_count() - 1; n >= 0; n--) { struct interface *iface = get_interface(n); + + /* + * We don't want to add a loopback interface, in case + * someone has added 127.0.0.1 for smbd, nmbd needs to + * ignore it here. JRA. + */ + + if (ip_equal(iface->ip, loopback_ip)) { + DEBUG(2,("reload_interfaces: Ignoring loopback interface %s\n", inet_ntoa(iface->ip))); + continue; + } + for (subrec=subnetlist; subrec; subrec=subrec->next) { if (ip_equal(iface->ip, subrec->myip) && ip_equal(iface->nmask, subrec->mask_ip)) break; } + if (!subrec) { /* it wasn't found! add it */ DEBUG(2,("Found new interface %s\n", -- cgit From a49d86ccc19e24e97ea46b674de5528b7013b0d7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 3 Apr 2000 17:12:25 +0000 Subject: Additional fix for nmbd and 127.0.0.1 interface. Jeremy. (This used to be commit 715fa7ea8cf00d72c868bed420c28a29011f53a1) --- source3/nmbd/nmbd_subnetdb.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 37b50f8525..330be4057f 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -235,6 +235,7 @@ BOOL create_subnets(void) int num_interfaces = iface_count(); int i; struct in_addr unicast_ip; + extern struct in_addr loopback_ip; if(num_interfaces == 0) { @@ -251,6 +252,17 @@ BOOL create_subnets(void) { struct interface *iface = get_interface(i); + /* + * We don't want to add a loopback interface, in case + * someone has added 127.0.0.1 for smbd, nmbd needs to + * ignore it here. JRA. + */ + + if (ip_equal(iface->ip, loopback_ip)) { + DEBUG(2,("create_subnets: Ignoring loopback interface.\n" )); + continue; + } + if (!make_normal_subnet(iface)) return False; } -- cgit From 2fa922611bf7160e2c1ce80c11b50006448bf98d Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 11 Apr 2000 13:55:53 +0000 Subject: finally got sick of the "extern int Client" code and the stupid assumption that we have one socket everywhere while doing so I discovered a few bugs! 1) the clientgen session retarget code if used from smbd or nmbd would cause a crash as it called close_sockets() which closed our main socket! fixed by removing close_sockets() completely - it is unnecessary 2) the caching in client_addr() and client_name() was bogus - it could easily get fooled and give the wrong result. fixed. 3) the retarget could could recurse, allowing an easy denial of service attack on nmbd. fixed. (This used to be commit 5937ab14d222696e40a3fc6f0e6a536f2d7305d3) --- source3/nmbd/nmbd.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 57d025c660..c7ebe48822 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -859,7 +859,6 @@ static void usage(char *pname) #endif /* SIGUSR2 */ process(); - close_sockets(); if (dbf) fclose(dbf); -- cgit From 55fa1630e4e2c298e19387ee18b425b86fd02656 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 11 Apr 2000 14:11:14 +0000 Subject: some updates to the process logon code to reflect lukes latest research plus some cleanups (This used to be commit 1682faa1b0e95fc5acdf9b10da80a6515f8772cd) --- source3/nmbd/nmbd_processlogon.c | 58 ++++++++++++++++++++++++++-------------- 1 file changed, 38 insertions(+), 20 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index a0e747648c..60dc816ee1 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -115,18 +115,21 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); char *machine = q; getdc = skip_string(machine,1); - unicomp = skip_string(getdc,1); + q = skip_string(getdc,1); + q = align2(q, buf); /* at this point we can work out if this is a W9X or NT style request. Experiments show that the difference is wether the packet ends here. For a W9X request we now end with a pair of bytes (usually 0xFE 0xFF) whereas with NT we have two further strings - the following is a simple way of detecting this */ - if (len - PTR_DIFF(unicomp, buf) <= 3) { + if (len - PTR_DIFF(q, buf) <= 3) { short_request = True; } else { + unicomp = q; + /* A full length (NT style) request */ - q = skip_unicode_string(unicomp, 1); + q = skip_unibuf(unicomp, PTR_DIFF(buf + len, unicomp)); if (len - PTR_DIFF(q, buf) > 8) { /* with NT5 clients we can sometimes @@ -162,9 +165,9 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); q += dos_PutUniCode(q, my_name, sizeof(pstring), True); /* PDC name */ q += dos_PutUniCode(q, global_myworkgroup,sizeof(pstring), True); /* Domain name*/ - SIVAL(q, 0, ntversion); - SSVAL(q, 4, lmnttoken); - SSVAL(q, 6, lm20token); + SIVAL(q, 0, 1); /* our nt version */ + SSVAL(q, 4, 0xffff); /* our lmnttoken */ + SSVAL(q, 6, 0xffff); /* our lm20token */ q += 8; } @@ -194,19 +197,35 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += 2; unicomp = q; - uniuser = skip_unicode_string(unicomp,1); - getdc = skip_unicode_string(uniuser,1); + uniuser = skip_unibuf(unicomp, PTR_DIFF(buf+len, unicomp)); + getdc = skip_unibuf(uniuser,PTR_DIFF(buf+len, uniuser)); q = skip_string(getdc,1); q += 4; domainsidsize = IVAL(q, 0); q += 4; q += domainsidsize + 3; + + if (domainsidsize != 0) { + q += domainsidsize; + q = align4(q, buf); + } + if (len - PTR_DIFF(q, buf) > 8) { + /* with NT5 clients we can sometimes + get additional data - a length specificed string + containing the domain name, then 16 bytes of + data (no idea what it is) */ + int dom_len = CVAL(q, 0); + q++; + if (dom_len != 0) { + q += dom_len + 1; + } + q += 16; + } + ntversion = IVAL(q, 0); - q += 4; - lmnttoken = SVAL(q, 0); - q += 2; - lm20token = SVAL(q, 0); - q += 2; + lmnttoken = SVAL(q, 4); + lm20token = SVAL(q, 6); + q += 8; DEBUG(3,("process_logon_packet: SAMLOGON sidsize %d ntv %d\n", domainsidsize, ntversion)); @@ -238,15 +257,14 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += dos_PutUniCode(q, reply_name,sizeof(pstring), True); unistrcpy(q, uniuser); - q = skip_unicode_string(q, 1); /* User name (workstation trust account) */ + q = skip_unibuf(q, PTR_DIFF(buf+len, q)); /* User name (workstation trust account) */ q += dos_PutUniCode(q, lp_workgroup(),sizeof(pstring), True); - SIVAL(q, 0, ntversion); - q += 4; - SSVAL(q, 0, lmnttoken); - q += 2; - SSVAL(q, 0, lm20token); - q += 2; + /* tell the client what version we are */ + SIVAL(q, 0, 1); /* our ntversion */ + SSVAL(q, 4, 0xffff); /* our lmnttoken */ + SSVAL(q, 6, 0xffff); /* our lm20token */ + q += 8; dump_data(4, outbuf, PTR_DIFF(q, outbuf)); -- cgit From 420099f96f2d448c71da29053187223f2d90ef68 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 11 Apr 2000 14:25:04 +0000 Subject: add a comment (This used to be commit 0da440c8fe365fd53c313e9dc62dda7e40916d62) --- source3/nmbd/nmbd_processlogon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 60dc816ee1..76a9aea952 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -200,7 +200,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", uniuser = skip_unibuf(unicomp, PTR_DIFF(buf+len, unicomp)); getdc = skip_unibuf(uniuser,PTR_DIFF(buf+len, uniuser)); q = skip_string(getdc,1); - q += 4; + q += 4; /* Account Control Bits - indicating username type */ domainsidsize = IVAL(q, 0); q += 4; q += domainsidsize + 3; -- cgit From f6be38cae223f1ad3f4ecc5b81d14c44d92f58ba Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Apr 2000 19:44:54 +0000 Subject: include/byteorder.h: ALIGN4/ALIGN2 macros. include/includes.h: Added SMB_BIG_UINT_BITS. lib/util.c: Removed align2/align4 - use macros. libsmb/namequery.c: Use ALIGN2. locking/locking.c: Replace do_lock, do_unlock, args with SMB_BIG_UINT, not SMB_OFF_T. Needed to move to hiding POSIX locks at a lower layer. nmbd/nmbd_processlogon.c: Use ALIGN2/ALIGN4 macros. smbd/blocking.c: Replace do_lock, do_unlock, args with SMB_BIG_UINT, not SMB_OFF_T. smbd/reply.c: Replace do_lock, do_unlock, args with SMB_BIG_UINT, not SMB_OFF_T. Jeremy. (This used to be commit 491eea8a20bf80d426625479326211dc975857a6) --- source3/nmbd/nmbd_processlogon.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 76a9aea952..47467f132d 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -116,7 +116,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); getdc = skip_string(machine,1); q = skip_string(getdc,1); - q = align2(q, buf); + q = ALIGN2(q, buf); /* at this point we can work out if this is a W9X or NT style request. Experiments show that the difference is wether the @@ -160,7 +160,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); /* PDC and domain name */ if (!short_request) /* Make a full reply */ { - q = align2(q, buf); + q = ALIGN2(q, buf); q += dos_PutUniCode(q, my_name, sizeof(pstring), True); /* PDC name */ q += dos_PutUniCode(q, global_myworkgroup,sizeof(pstring), True); /* Domain name*/ @@ -207,7 +207,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", if (domainsidsize != 0) { q += domainsidsize; - q = align4(q, buf); + q = ALIGN4(q, buf); } if (len - PTR_DIFF(q, buf) > 8) { /* with NT5 clients we can sometimes -- cgit From f5da7470c3f4d1fc86dee19e85d189595344bad2 Mon Sep 17 00:00:00 2001 From: Luke Leighton Date: Wed, 12 Apr 2000 05:56:16 +0000 Subject: logic for domainsidsize is if size is zero, there's no sid, so don't advance over it and 4-byte align. this _used_ to be "regardless of domainsidsize, advance by domainsidsize+3" which is wrong. (This used to be commit 5086e6425f3630d8f5ca1e25a333eb97fdf86e93) --- source3/nmbd/nmbd_processlogon.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 47467f132d..3c0df6995e 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -203,7 +203,6 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += 4; /* Account Control Bits - indicating username type */ domainsidsize = IVAL(q, 0); q += 4; - q += domainsidsize + 3; if (domainsidsize != 0) { q += domainsidsize; -- cgit From 7b1c5392f789ff933e8ab61c9b65b400b7c33ffe Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 18 Apr 2000 03:34:27 +0000 Subject: updates from the TNG branch (This used to be commit 36fb5bc72fc6c0de719205ea34f497bfa0c4082f) --- source3/nmbd/nmbd_processlogon.c | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 3c0df6995e..9784afe9e2 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -101,8 +101,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); send_mailslot(True, getdc, outbuf,PTR_DIFF(q,outbuf), - dgram->dest_name.name, - dgram->dest_name.name_type, + global_myname, 0x0, dgram->source_name.name, dgram->source_name.name_type, p->ip, *iface_ip(p->ip), p->port); @@ -175,7 +174,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); DEBUG(3,("process_logon_packet: GETDC request from %s at IP %s, \ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", - machine,inet_ntoa(p->ip), reply_name, lp_workgroup(), + machine,inet_ntoa(p->ip), reply_name, global_myworkgroup, QUERYFORPDC_R, (uint32)ntversion, (uint32)lmnttoken, (uint32)lm20token )); @@ -183,8 +182,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", send_mailslot(True, getdc, outbuf,PTR_DIFF(q,outbuf), - dgram->dest_name.name, - dgram->dest_name.name_type, + global_myname, 0x0, dgram->source_name.name, dgram->source_name.name_type, p->ip, *iface_ip(p->ip), p->port); @@ -255,9 +253,8 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += 2; q += dos_PutUniCode(q, reply_name,sizeof(pstring), True); - unistrcpy(q, uniuser); - q = skip_unibuf(q, PTR_DIFF(buf+len, q)); /* User name (workstation trust account) */ - q += dos_PutUniCode(q, lp_workgroup(),sizeof(pstring), True); + q += dos_PutUniCode(q, ascuser, sizeof(pstring), True); + q += dos_PutUniCode(q, global_myworkgroup,sizeof(pstring), True); /* tell the client what version we are */ SIVAL(q, 0, 1); /* our ntversion */ @@ -269,8 +266,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", send_mailslot(True, getdc, outbuf,PTR_DIFF(q,outbuf), - dgram->dest_name.name, - dgram->dest_name.name_type, + global_myname, 0x0, dgram->source_name.name, dgram->source_name.name_type, p->ip, *iface_ip(p->ip), p->port); -- cgit From 6259f51dd9918eccc9697f3763d918f7c9b82b50 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 22 Apr 2000 00:33:16 +0000 Subject: This is a *big* checkin that may break some things, but implements the new open mechanism Andrew & I discussed. config.sub: configure: Included the QNX patch. include/vfs.h: smbd/vfs-wrap.c: smbd/vfs.c: Added ftruncate vfs call (needed). Note that we will also need locking calls in the vfs (to be added). lib/util_unistr.c: nmbd/nmbd_processlogon.c: Fix for NT domain logons causing nmbd to core dump. Also fix for sidsize DOS bug. locking/locking.c: Check value of ret before using it for memdup. printing/printing.c: Convert print_fsp_open to return an allocated fsp. rpc_server/srv_lsa.c: Fix for NT domain logons. I have removed all use of lp_share_modes() from the code (although I left the parameter in the table for backwards compatibility). It no longer makes sense for this to exist. smbd/close.c: Removed lp_share_modes(). smbd/fileio.c: Fixed parameters to unlock_share_entry call in panic code. smbd/files.c: Correctly set the unix_ERR_code to ERRnofids on fsp allocation fail. smbd/nttrans.c: smbd/reply.c: smbd/trans2.c: Changed all occurrences of open_file_shared/open_directory/ open_file_stat to return an fsp from the call. smbd/open.c: Changed all occurrences of open_file_shared/open_directory/ open_file_stat to return an fsp from the call. In addition I have fixed a long standing race condition in the deny mode processing w.r.t. two smbd's creating a file. Andrew, please note that your original idea of using open with O_EXCL in this case would not work (I went over the races very carefully) and so we must re-check deny modes *after* the open() call returns. This is because there is a race between the open with O_EXCL and the lock of the share mode entry. Imagine the case where the first smbd does the open with O_EXCL and a deny mode of DENY_ALL, but is pre-empted before it locks the share modes and creates the deny mode entry for DENY_ALL. A second smbd could then come in with O_RDONLY and a deny mode of DENY_NONE and the two opens would be allowed. The *only* way to fix this race is to lock the share modes after the open and then do the deny mode checks *after* this lock in the case where the file did not originally exist. This code will need extensive testing but seems to initially work. Jeremy. (This used to be commit ab0ecc39d688f16b9692fe90b991f0b89287070a) --- source3/nmbd/nmbd_processlogon.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 9784afe9e2..bb4b7547a6 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -67,7 +67,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); strupper(my_name); code = SVAL(buf,0); - DEBUG(1,("process_logon_packet: Logon from %s: code = %x\n", inet_ntoa(p->ip), code)); + DEBUG(1,("process_logon_packet: Logon from %s: code = 0x%x\n", inet_ntoa(p->ip), code)); switch (code) { @@ -202,10 +202,15 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", domainsidsize = IVAL(q, 0); q += 4; - if (domainsidsize != 0) { + DEBUG(3,("process_logon_packet: SAMLOGON sidsize %d, len = %d\n", domainsidsize, len)); + + if (domainsidsize < (len - PTR_DIFF(q, buf)) && (domainsidsize != 0)) { q += domainsidsize; q = ALIGN4(q, buf); } + + DEBUG(3,("process_logon_packet: len = %d PTR_DIFF(q, buf) = %d\n", len, PTR_DIFF(q, buf) )); + if (len - PTR_DIFF(q, buf) > 8) { /* with NT5 clients we can sometimes get additional data - a length specificed string @@ -213,7 +218,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", data (no idea what it is) */ int dom_len = CVAL(q, 0); q++; - if (dom_len != 0) { + if (dom_len < (len - PTR_DIFF(q, buf)) && (dom_len != 0)) { q += dom_len + 1; } q += 16; -- cgit From f0442220fa57c77c6691f3301bc0d80635d0b23f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 24 Apr 2000 11:30:45 +0000 Subject: fixed a parameter bug found by insure (This used to be commit a559a8066fb162c4da0a5046c49a105eabf131d9) --- source3/nmbd/nmbd_workgroupdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 5514e78dc1..485253680b 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -156,7 +156,7 @@ static struct work_record *remove_workgroup_from_subnet(struct subnet_record *su **************************************************************************/ struct work_record *find_workgroup_on_subnet(struct subnet_record *subrec, - fstring name) + const char *name) { struct work_record *ret; -- cgit From 84f65e6be63307373949bc4490fcd40b34794903 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 25 Apr 2000 00:45:42 +0000 Subject: don't qsort a list less than 2 entries (This used to be commit 6faa3c23ae6d8aab52f8d6689e04bde9b3029804) --- source3/nmbd/nmbd_incomingrequests.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index 7c46204445..c59c045bad 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -383,7 +383,9 @@ subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name), } /* Remove duplicate names. */ - qsort( buf0, names_added, 18, QSORT_CAST status_compare ); + if (names_added > 1) { + qsort( buf0, names_added, 18, QSORT_CAST status_compare ); + } for( i=1; i < names_added ; i++ ) { -- cgit From 693ffb8466ada58ecc59fde754ba79fc6f51528d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 2 May 2000 02:23:41 +0000 Subject: Added sys_fork() and sys_getpid() functions to stop the overhead of doing a system call every time we want to just get our pid. Jeremy. (This used to be commit 148628b616b5c29ba6340d65fc3ddbcabba6e67a) --- source3/nmbd/asyncdns.c | 2 +- source3/nmbd/nmbd.c | 2 +- source3/nmbd/nmbd_packets.c | 2 +- source3/nmbd/nmbd_synclists.c | 2 +- source3/nmbd/nmbd_winsserver.c | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 99e697b470..1fe04a39e3 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -140,7 +140,7 @@ void start_async_dns(void) return; } - child_pid = fork(); + child_pid = sys_fork(); if (child_pid) { fd_in = fd1[0]; diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index c7ebe48822..b59a626fff 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -652,7 +652,7 @@ static void usage(char *pname) StartupTime = time(NULL); - sys_srandom(time(NULL) ^ getpid()); + sys_srandom(time(NULL) ^ sys_getpid()); TimeInit(); diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index a7c94f1544..ee2ba2e240 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -140,7 +140,7 @@ static uint16 generate_name_trn_id(void) if (!name_trn_id) { - name_trn_id = ((unsigned)time(NULL)%(unsigned)0x7FFF) + ((unsigned)getpid()%(unsigned)100); + name_trn_id = ((unsigned)time(NULL)%(unsigned)0x7FFF) + ((unsigned)sys_getpid()%(unsigned)100); } name_trn_id = (name_trn_id+1) % (unsigned)0x7FFF; return name_trn_id; diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 7bf1790377..b69a9959c2 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -153,7 +153,7 @@ void sync_browse_lists(struct work_record *work, /* the parent forks and returns, leaving the child to do the actual sync */ CatchChild(); - if ((s->pid = fork())) return; + if ((s->pid = sys_fork())) return; BlockSignals( False, SIGTERM ); diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 2b99a8ce53..33b33040cb 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1592,14 +1592,14 @@ void wins_write_database(BOOL background) doesn't block while this is done */ if (background) { CatchChild(); - if (fork()) { + if (sys_fork()) { return; } } slprintf(fname,sizeof(fname),"%s/%s", lp_lockdir(), WINS_LIST); all_string_sub(fname,"//", "/", 0); - slprintf(fnamenew,sizeof(fnamenew),"%s.%u", fname, (unsigned int)getpid()); + slprintf(fnamenew,sizeof(fnamenew),"%s.%u", fname, (unsigned int)sys_getpid()); if((fp = sys_fopen(fnamenew,"w")) == NULL) { -- cgit From a7a4f4f67c230fbc47a5e140c059e6cfc45cd1b4 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 2 May 2000 23:56:24 +0000 Subject: Fixed wild pointer diff found by insure. Jeremy. (This used to be commit 158d9cada8c12725981d495faf8ed9f5d4306e23) --- source3/nmbd/nmbd_processlogon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index bb4b7547a6..0da25a313d 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -159,7 +159,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); /* PDC and domain name */ if (!short_request) /* Make a full reply */ { - q = ALIGN2(q, buf); + q = ALIGN2(q, outbuf); q += dos_PutUniCode(q, my_name, sizeof(pstring), True); /* PDC name */ q += dos_PutUniCode(q, global_myworkgroup,sizeof(pstring), True); /* Domain name*/ -- cgit From ddc9b8b40642c90fe7c34b088eae4f8075f4033a Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 10 May 2000 09:49:55 +0000 Subject: more merging it is now at the stage that winbindd can compile in the head branch, but not link (This used to be commit d178c00aae77710ae6ff20a7f54a30e3bd8232bb) --- source3/nmbd/nmbd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index b59a626fff..af78af756e 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -656,8 +656,7 @@ static void usage(char *pname) TimeInit(); - pstrcpy( debugf, NMBLOGFILE ); - + slprintf(debugf, sizeof(debugf), "%s/log.nmbd", LOGFILEBASE); setup_logging( argv[0], False ); charset_initialise(); -- cgit From 8843a6379d7c1cf59f0f3673cbc567b09994b7d2 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sun, 11 Jun 2000 05:57:58 +0000 Subject: Linux kernel oplocks now seem to work, but need a _lot_ of testing I had to modify sys_select() to not loop on EINTR. I added a wrapper called sys_select_intr() which gives the old behaviour. (This used to be commit b28cc4163bc2faaa80c5782fc02c8f03c410cdeb) --- source3/nmbd/nmbd_packets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index ee2ba2e240..05b75e984e 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1793,7 +1793,7 @@ BOOL listen_for_packets(BOOL run_election) BlockSignals(False, SIGUSR2); #endif /* SIGUSR2 */ - selrtn = sys_select(FD_SETSIZE,&fds,&timeout); + selrtn = sys_select_intr(FD_SETSIZE,&fds,&timeout); /* We can only take signals when we are in the select - block them again here. */ -- cgit From b35f21fb3a19417e2aab82a573ff121a086b224c Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Wed, 19 Jul 2000 01:21:30 +0000 Subject: First cut toward adding WINS server failover. *Note: failover doesn't actually work yet!* It's just that the code I'm adding provides all of the pieces necessary. I do have one big question. Something that I'll have to ask Jeremy, I'm thinkin'. In nmbd/nmbd_subnetdb.c the IP of the WINS server is used to set up the Unicast subnet. ...so what happens if the WINS server changes? My guess is either: a) nothing. b) I'd have to change the unicast subnet entry whenever the WINS server changes. Urq. BTW, the lp_wins_server() function no longer returns the WINS server name or IP. It returns the list of WINS servers entered in smb.conf. To get the currently 'live' WINS server, use the wins_srv() function. Fun, eh? Chris -)----- (This used to be commit cc08bdc74f4cd111fdc582ee7babef47ed8a950d) --- source3/nmbd/nmbd_subnetdb.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 330be4057f..57f937148e 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -271,12 +271,16 @@ BOOL create_subnets(void) * get the ip address of it here. If we are the WINS server then * set the unicast subnet address to be the first of our own real * addresses. + * + * NOTE: I'm not sure of the implications of WINS server failover + * on this bit of code. Because of failover, the WINS + * server address can change. */ if(*lp_wins_server()) { struct in_addr real_wins_ip; - real_wins_ip = *interpret_addr2(lp_wins_server()); + real_wins_ip = *interpret_addr2( wins_srv() ); if (!zero_ip(real_wins_ip)) { -- cgit From 3c9e410c340d53897a3f97243d8286812704f6c0 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Wed, 19 Jul 2000 05:32:43 +0000 Subject: Instead of handing back a string (which might be a DNS name or an IP string), the wins_srv module now hands back a struct in_addr when it's called. It caches the IP address once it has been looked up. The IP is cleared (and must be looked up again) if the 'wins server' parameter is reread, or if the node is marked 'dead'. A dead node will not be re-tried for 10 minutes (per a #define in wins_srv.c). As it was, the code was reading the WINS server name or IP directly from lp_wins_server. That's okay, except that if the value was expressed as a name, then a DNS lookup would be done every time the client wanted to talk to the server. I still need to work out the implications of failover regarding the 'unicast subnet' list. Chris -)----- (This used to be commit 73aa188320fd3bf10b5dfc057323f40aff2c13bd) --- source3/nmbd/nmbd_subnetdb.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 57f937148e..3bad3f9568 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -274,13 +274,13 @@ BOOL create_subnets(void) * * NOTE: I'm not sure of the implications of WINS server failover * on this bit of code. Because of failover, the WINS - * server address can change. + * server address can change. crh */ if(*lp_wins_server()) { struct in_addr real_wins_ip; - real_wins_ip = *interpret_addr2( wins_srv() ); + real_wins_ip = wins_srv_ip(); if (!zero_ip(real_wins_ip)) { @@ -288,9 +288,10 @@ BOOL create_subnets(void) } else { - /* The smb.conf's wins server parameter MUST be a host_name - or an ip_address. */ - DEBUG(0,("invalid smb.conf parameter 'wins server'\n")); + /* wins_srv_ip() can return a zero IP if all servers are + * either down or incorrectly entered in smb.conf. crh + */ + DEBUG(0,("No 'live' WINS servers found. Check 'wins server' parameter.\n")); return False; } } @@ -330,9 +331,9 @@ BOOL create_subnets(void) if (lp_we_are_a_wins_server()) { - if((wins_server_subnet = make_subnet("WINS_SERVER_SUBNET", - WINS_SERVER_SUBNET, - ipzero, ipzero, ipzero)) == NULL) + if( (wins_server_subnet = make_subnet( "WINS_SERVER_SUBNET", + WINS_SERVER_SUBNET, + ipzero, ipzero, ipzero )) == NULL ) return False; } -- cgit From 6e150a7ca507869df7b639e1a80ba101b1d5771a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 30 Aug 2000 17:34:35 +0000 Subject: Fix for bind interfaces only sometimes picking the wrong IP address for a name query. From Steve Langasek . Jeremy. (This used to be commit 9890740121ae7bd7a0196bbf946c6f8c82aa7f6e) --- source3/nmbd/nmbd_packets.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 05b75e984e..cf00dc9083 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -699,8 +699,30 @@ struct response_record *queue_query_name( struct subnet_record *subrec, subrec->bcast_ip)) == NULL) return NULL; - if(initiate_name_query_packet( p ) == False) - { + if(lp_bind_interfaces_only()) { + int i; + + DEBUG(10,("queue_query_name: bind_interfaces_only is set, looking for suitable source IP\n")); + for(i = 0; i < iface_count(); i++) { + struct in_addr *ifip = iface_n_ip(i); + + if(ifip == NULL) { + DEBUG(0,("queue_query_name: interface %d has NULL IP address !\n", i)); + continue; + } + + if (ip_equal(*ifip,loopback_ip)) { + DEBUG(5,("queue_query_name: ignoring loopback interface (%d)\n", i)); + continue; + } + + DEBUG(10,("queue_query_name: using source IP %s\n",inet_ntoa(*ifip))); + p->fd = find_subnet_fd_for_address( *ifip ); + break; + } + } + + if(initiate_name_query_packet( p ) == False) { p->locked = False; free_packet(p); return NULL; -- cgit From 3689e4ffc10fceb4c39814ef58fe31697e7dd976 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 11 Sep 2000 07:02:43 +0000 Subject: the first cut of the internal messaging system. The motivation for this system is to replace the UDP message for oplocks, but this commit only does the "set debug level" message. (This used to be commit 2a34ee95f3929cff131db6c5a2b4820194c05b2d) --- source3/nmbd/nmbd.c | 19 ------------------- source3/nmbd/nmbd_packets.c | 12 ------------ 2 files changed, 31 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index af78af756e..cd47296774 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -682,19 +682,6 @@ static void usage(char *pname) BlockSignals(True,SIGFPE); #endif - /* Setup the signals that allow the debug log level - to by dynamically changed. */ - - /* If we are using the malloc debug code we can't use - SIGUSR1 and SIGUSR2 to do debug level changes. */ -#if defined(SIGUSR1) - CatchSignal( SIGUSR1, SIGNAL_CAST sig_usr1 ); -#endif /* SIGUSR1 */ - -#if defined(SIGUSR2) - CatchSignal( SIGUSR2, SIGNAL_CAST sig_usr2 ); -#endif /* SIGUSR2 */ - while( EOF != (opt = getopt( argc, argv, "Vaos:T:I:C:bAB:N:Rn:l:d:Dp:hSH:G:f:" )) ) { @@ -850,12 +837,6 @@ static void usage(char *pname) /* We can only take signals in the select. */ BlockSignals( True, SIGTERM ); -#if defined(SIGUSR1) - BlockSignals( True, SIGUSR1); -#endif /* SIGUSR1 */ -#if defined(SIGUSR2) - BlockSignals( True, SIGUSR2); -#endif /* SIGUSR2 */ process(); diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index cf00dc9083..605233f40d 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1808,24 +1808,12 @@ BOOL listen_for_packets(BOOL run_election) /* Prepare for the select - allow certain signals. */ BlockSignals(False, SIGTERM); -#if defined(SIGUSR1) - BlockSignals(False, SIGUSR1); -#endif /* SIGUSR1 */ -#if defined(SIGUSR2) - BlockSignals(False, SIGUSR2); -#endif /* SIGUSR2 */ selrtn = sys_select_intr(FD_SETSIZE,&fds,&timeout); /* We can only take signals when we are in the select - block them again here. */ BlockSignals(True, SIGTERM); -#if defined(SIGUSR1) - BlockSignals(True, SIGUSR1); -#endif /* SIGUSR1 */ -#if defined(SIGUSR2) - BlockSignals(True, SIGUSR2); -#endif /* SIGUSR2 */ if(selrtn > 0) { -- cgit From 0b2e454703fc59b9c019fb8bded92cbc78432567 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 11 Sep 2000 07:33:44 +0000 Subject: debug messages now work for nmbd (This used to be commit 6a503f95b10f6661b089f30f2b5ffebead32685c) --- source3/nmbd/nmbd.c | 4 ++ source3/nmbd/nmbd_packets.c | 157 +++++++++++++++++++++----------------------- 2 files changed, 79 insertions(+), 82 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index cd47296774..2da879fc94 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -490,6 +490,9 @@ static void process(void) /* free up temp memory */ lp_talloc_free(); + + /* check for internal messages */ + message_init(); } } /* process */ @@ -791,6 +794,7 @@ static void usage(char *pname) } pidfile_create("nmbd"); + message_init(); DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 605233f40d..d1f77fe2d2 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1758,8 +1758,17 @@ only use %d.\n", (count*2) + 2, FD_SETSIZE)); return False; } +/**************************************************************************** +do any signal triggered processing +***************************************************************************/ +static void nmbd_async_processing(void) +{ + message_dispatch(); +} + /**************************************************************************** Listens for NMB or DGRAM packets, and queues them. + return True if the socket is dead ***************************************************************************/ BOOL listen_for_packets(BOOL run_election) @@ -1767,6 +1776,7 @@ BOOL listen_for_packets(BOOL run_election) static fd_set *listen_set = NULL; static int listen_number = 0; static int *sock_array = NULL; + int i; fd_set fds; int selrtn; @@ -1809,97 +1819,80 @@ BOOL listen_for_packets(BOOL run_election) BlockSignals(False, SIGTERM); - selrtn = sys_select_intr(FD_SETSIZE,&fds,&timeout); + selrtn = sys_select(FD_SETSIZE,&fds,&timeout); /* We can only take signals when we are in the select - block them again here. */ BlockSignals(True, SIGTERM); - if(selrtn > 0) - { - int i; + if(selrtn == -1) { + if (errno == EINTR) { + nmbd_async_processing(); + } + return False; + } #ifndef SYNC_DNS - if (dns_fd != -1 && FD_ISSET(dns_fd,&fds)) { - run_dns_queue(); - } + if (dns_fd != -1 && FD_ISSET(dns_fd,&fds)) { + run_dns_queue(); + } #endif - for(i = 0; i < listen_number; i++) - { - if(i < (listen_number/2)) - { - /* Processing a 137 socket. */ - if (FD_ISSET(sock_array[i],&fds)) - { - struct packet_struct *packet = read_packet(sock_array[i], NMB_PACKET); - if (packet) - { - /* - * If we got a packet on the broadcast socket and interfaces - * only is set then check it came from one of our local nets. - */ - if(lp_bind_interfaces_only() && (sock_array[i] == ClientNMB) && - (!is_local_net(packet->ip))) - { - DEBUG(7,("discarding nmb packet sent to broadcast socket from %s:%d\n", - inet_ntoa(packet->ip),packet->port)); - free_packet(packet); - } - else if ((ip_equal(loopback_ip, packet->ip) || - ismyip(packet->ip)) && packet->port == global_nmb_port) - { - DEBUG(7,("discarding own packet from %s:%d\n", - inet_ntoa(packet->ip),packet->port)); - free_packet(packet); - } - else - { - /* Save the file descriptor this packet came in on. */ - packet->fd = sock_array[i]; - queue_packet(packet); - } - } - } - } - else - { - /* Processing a 138 socket. */ - - if (FD_ISSET(sock_array[i],&fds)) - { - struct packet_struct *packet = read_packet(sock_array[i], DGRAM_PACKET); - if (packet) - { - /* - * If we got a packet on the broadcast socket and interfaces - * only is set then check it came from one of our local nets. - */ - if(lp_bind_interfaces_only() && (sock_array[i] == ClientDGRAM) && - (!is_local_net(packet->ip))) - { - DEBUG(7,("discarding dgram packet sent to broadcast socket from %s:%d\n", - inet_ntoa(packet->ip),packet->port)); - free_packet(packet); - } - else if ((ip_equal(loopback_ip, packet->ip) || - ismyip(packet->ip)) && packet->port == DGRAM_PORT) - { - DEBUG(7,("discarding own packet from %s:%d\n", - inet_ntoa(packet->ip),packet->port)); - free_packet(packet); - } - else - { - /* Save the file descriptor this packet came in on. */ - packet->fd = sock_array[i]; - queue_packet(packet); - } - } - } - } /* end processing 138 socket. */ - } /* end for */ - } /* end if selret > 0 */ + for(i = 0; i < listen_number; i++) { + if (i < (listen_number/2)) { + /* Processing a 137 socket. */ + if (FD_ISSET(sock_array[i],&fds)) { + struct packet_struct *packet = read_packet(sock_array[i], NMB_PACKET); + if (packet) { + /* + * If we got a packet on the broadcast socket and interfaces + * only is set then check it came from one of our local nets. + */ + if(lp_bind_interfaces_only() && (sock_array[i] == ClientNMB) && + (!is_local_net(packet->ip))) { + DEBUG(7,("discarding nmb packet sent to broadcast socket from %s:%d\n", + inet_ntoa(packet->ip),packet->port)); + free_packet(packet); + } else if ((ip_equal(loopback_ip, packet->ip) || + ismyip(packet->ip)) && packet->port == global_nmb_port) { + DEBUG(7,("discarding own packet from %s:%d\n", + inet_ntoa(packet->ip),packet->port)); + free_packet(packet); + } else { + /* Save the file descriptor this packet came in on. */ + packet->fd = sock_array[i]; + queue_packet(packet); + } + } + } + } else { + /* Processing a 138 socket. */ + if (FD_ISSET(sock_array[i],&fds)) { + struct packet_struct *packet = read_packet(sock_array[i], DGRAM_PACKET); + if (packet) { + /* + * If we got a packet on the broadcast socket and interfaces + * only is set then check it came from one of our local nets. + */ + if(lp_bind_interfaces_only() && (sock_array[i] == ClientDGRAM) && + (!is_local_net(packet->ip))) { + DEBUG(7,("discarding dgram packet sent to broadcast socket from %s:%d\n", + inet_ntoa(packet->ip),packet->port)); + free_packet(packet); + } else if ((ip_equal(loopback_ip, packet->ip) || + ismyip(packet->ip)) && packet->port == DGRAM_PORT) { + DEBUG(7,("discarding own packet from %s:%d\n", + inet_ntoa(packet->ip),packet->port)); + free_packet(packet); + } else { + /* Save the file descriptor this packet came in on. */ + packet->fd = sock_array[i]; + queue_packet(packet); + } + } + } + } /* end processing 138 socket. */ + } /* end for */ return False; } -- cgit From f0ce4f7ae3b58f45b70598e3a44539e3e12291ce Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 12 Sep 2000 06:13:25 +0000 Subject: - changed the msg_type to be an int instead of an enum so that it is easier to add new message types to messages.h without breaking old binaries - added a MSG_FORCE_ELECTION message to force nmbd to hold an election (This used to be commit f1c49ca7ce56bc39259041a71479e84ebf53eeca) --- source3/nmbd/nmbd.c | 7 ++++--- source3/nmbd/nmbd_elections.c | 21 +++++++++++++++++++++ source3/nmbd/nmbd_packets.c | 11 ----------- 3 files changed, 25 insertions(+), 14 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 2da879fc94..914f288001 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -312,6 +312,9 @@ static void process(void) { time_t t = time(NULL); + /* check for internal messages */ + message_dispatch(); + /* * Check all broadcast subnets to see if * we need to run an election on any of them. @@ -490,9 +493,6 @@ static void process(void) /* free up temp memory */ lp_talloc_free(); - - /* check for internal messages */ - message_init(); } } /* process */ @@ -795,6 +795,7 @@ static void usage(char *pname) pidfile_create("nmbd"); message_init(); + message_register(MSG_FORCE_ELECTION, nmbd_message_election); DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index be38b572f6..522e268ae7 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -381,3 +381,24 @@ yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name )); } return run_any_election; } + + + +/**************************************************************************** +process a internal Samba message forcing an election +***************************************************************************/ +void nmbd_message_election(int msg_type, pid_t src, void *buf, size_t len) +{ + struct subnet_record *subrec; + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { + struct work_record *work; + for (work = subrec->workgrouplist; work; work = work->next) { + if (strequal(work->work_group, global_myworkgroup)) { + work->needelection = True; + work->ElectionCount=0; + work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; + } + } + } +} diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index d1f77fe2d2..50193d5339 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1758,14 +1758,6 @@ only use %d.\n", (count*2) + 2, FD_SETSIZE)); return False; } -/**************************************************************************** -do any signal triggered processing -***************************************************************************/ -static void nmbd_async_processing(void) -{ - message_dispatch(); -} - /**************************************************************************** Listens for NMB or DGRAM packets, and queues them. return True if the socket is dead @@ -1826,9 +1818,6 @@ BOOL listen_for_packets(BOOL run_election) BlockSignals(True, SIGTERM); if(selrtn == -1) { - if (errno == EINTR) { - nmbd_async_processing(); - } return False; } -- cgit From 8582d426467e715a912ef06c13bdbbdeb9000739 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 7 Oct 2000 01:15:07 +0000 Subject: Ensure browse.dat is written and read in UNIX character set format. Jeremy. (This used to be commit 279d0ec656b03f9266e38b013f16b69e7571c0d5) --- source3/nmbd/nmbd_synclists.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index b69a9959c2..7d10250325 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -49,13 +49,13 @@ static FILE *fp; /******************************************************************* This is the NetServerEnum callback. + Note sname and comment are in UNIX codepage format. ******************************************************************/ static void callback(const char *sname, uint32 stype, const char *comment) { fprintf(fp,"\"%s\" %08X \"%s\"\n", sname, stype, comment); } - /******************************************************************* Synchronise browse lists with another browse server. Log in on the remote server's SMB port to their IPC$ service, @@ -67,6 +67,7 @@ static void sync_child(char *name, int nm_type, char *fname) { extern fstring local_machine; + fstring unix_workgroup; static struct cli_state cli; uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0; struct nmb_name called, calling; @@ -101,14 +102,20 @@ static void sync_child(char *name, int nm_type, return; } + /* All the cli_XX functions take UNIX character set. */ + fstrcpy(unix_workgroup, cli.server_domain?cli.server_domain:workgroup); + dos_to_unix(unix_workgroup, True); + /* Fetch a workgroup list. */ - cli_NetServerEnum(&cli, cli.server_domain?cli.server_domain:workgroup, + cli_NetServerEnum(&cli, unix_workgroup, local_type|SV_TYPE_DOMAIN_ENUM, callback); /* Now fetch a server list. */ if (servers) { - cli_NetServerEnum(&cli, workgroup, + fstrcpy(unix_workgroup, workgroup); + dos_to_unix(unix_workgroup, True); + cli_NetServerEnum(&cli, unix_workgroup, local?SV_TYPE_LOCAL_LIST_ONLY:SV_TYPE_ALL, callback); } @@ -248,6 +255,9 @@ static void complete_sync(struct sync_record *s) ptr = line; + /* The line is written in UNIX character set. Convert to DOS codepage. */ + unix_to_dos(line,True); + if (!next_token(&ptr,server,NULL,sizeof(server)) || !next_token(&ptr,type_str,NULL, sizeof(type_str)) || !next_token(&ptr,comment,NULL, sizeof(comment))) { -- cgit From c56301b1d117c27213fe2dc4faf72a1bec19d092 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 12 Oct 2000 21:19:49 +0000 Subject: Ignore SIGUSR2. Terminate nmbd if we have no interfaces. Jeremy. (This used to be commit 580e2e044cfd1d011d9f28f0f49ef60ca6ba8d32) --- source3/nmbd/nmbd.c | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 914f288001..5b9a00aad0 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -186,7 +186,7 @@ static void expire_names_and_servers(time_t t) /************************************************************************** ** reload the list of network interfaces ************************************************************************** */ -static void reload_interfaces(time_t t) +static BOOL reload_interfaces(time_t t) { static time_t lastt; int n; @@ -194,10 +194,10 @@ static void reload_interfaces(time_t t) extern BOOL rescan_listen_set; extern struct in_addr loopback_ip; - if (t && ((t - lastt) < NMBD_INTERFACES_RELOAD)) return; + if (t && ((t - lastt) < NMBD_INTERFACES_RELOAD)) return False; lastt = t; - if (!interfaces_changed()) return; + if (!interfaces_changed()) return False; /* the list of probed interfaces has changed, we may need to add/remove some subnets */ @@ -253,6 +253,13 @@ static void reload_interfaces(time_t t) } rescan_listen_set = True; + + /* We need to shutdown if there are no subnets... */ + if (FIRST_SUBNET == NULL) { + DEBUG(0,("reload_interfaces: No subnets to listen to. Shutting down...\n")); + return True; + } + return False; } @@ -484,12 +491,14 @@ static void process(void) if(reload_after_sighup) { reload_nmbd_services( True ); reopen_logs(); - reload_interfaces(0); + if(reload_interfaces(0)) + return; reload_after_sighup = False; } /* check for new network interfaces */ - reload_interfaces(t); + if(reload_interfaces(t)) + return; /* free up temp memory */ lp_talloc_free(); @@ -685,6 +694,11 @@ static void usage(char *pname) BlockSignals(True,SIGFPE); #endif + /* We no longer use USR2... */ +#if defined(SIGUSR2) + BlockSignals(True, SIGUSR2); +#endif + while( EOF != (opt = getopt( argc, argv, "Vaos:T:I:C:bAB:N:Rn:l:d:Dp:hSH:G:f:" )) ) { -- cgit From 901c3224deb650826f418313e2c7e76602403788 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 17 Nov 2000 00:33:06 +0000 Subject: John Reillys fix for de-registering broadcast names (NT doesn't do this). Jeremy. (This used to be commit 245907f2affb530237809b81b8748f7f0a1e4502) --- source3/nmbd/nmbd_mynames.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index 7ea8ffc946..432a4736a4 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -164,9 +164,13 @@ BOOL register_my_workgroup_and_names(void) void release_my_names(void) { +#if 0 /*JRR: do WINS server only, otherwise clients ignore us when we come back up*/ struct subnet_record *subrec; for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) +#else + struct subnet_record *subrec = unicast_subnet; +#endif { struct name_record *namerec, *nextnamerec; -- cgit From 39f0f1120faef0d8d2bf37ea14c7113f08975147 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Tue, 2 Jan 2001 14:00:27 +0000 Subject: Comment out unused generate_name_trn_id ... (This used to be commit fb5798e1d9eb518f85e30680883c0460141b245d) --- source3/nmbd/nmbd_packets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 50193d5339..c16777ff41 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1905,7 +1905,7 @@ BOOL send_mailslot(BOOL unique, char *mailslot,char *buf,int len, if(ismyip(dest_ip)) loopback_this_packet = True; - generate_name_trn_id(); + /* generate_name_trn_id(); */ /* Not used, so gone, RJS */ /* DIRECT GROUP or UNIQUE datagram. */ dgram->header.msg_type = unique ? 0x10 : 0x11; -- cgit From 842589582bd8a1f631665d1410096f4571371643 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Tue, 2 Jan 2001 14:24:46 +0000 Subject: Make the use of generate_name_trn_id conform to the usage elsewhere ... (This used to be commit 46a3a56ecf411eb885aee2892e12d3846ce32ad6) --- source3/nmbd/nmbd_packets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index c16777ff41..8bd9d2761f 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1912,7 +1912,7 @@ BOOL send_mailslot(BOOL unique, char *mailslot,char *buf,int len, dgram->header.flags.node_type = M_NODE; dgram->header.flags.first = True; dgram->header.flags.more = False; - dgram->header.dgm_id = name_trn_id; + dgram->header.dgm_id = generate_name_trn_id(); dgram->header.source_ip = src_ip; dgram->header.source_port = DGRAM_PORT; dgram->header.dgm_length = 0; /* Let build_dgram() handle this. */ -- cgit From 79ad1926d06dd1241c11b3788daff27dbd1000b1 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Wed, 3 Jan 2001 01:25:05 +0000 Subject: We only want to mark mailslot packets as loopback packets if they are to the DGRAM_PORT, since we want to actually send those to other ports. They might be for the client library running on the Samba server! (This used to be commit 05e2dd5e85d4aca1ccb9f6991e1415f85cbbdc1a) --- source3/nmbd/nmbd_packets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 8bd9d2761f..8b10298561 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1902,7 +1902,7 @@ BOOL send_mailslot(BOOL unique, char *mailslot,char *buf,int len, memset((char *)&p,'\0',sizeof(p)); - if(ismyip(dest_ip)) + if(ismyip(dest_ip) && (dest_port == DGRAM_PORT)) /* Only if to DGRAM_PORT */ loopback_this_packet = True; /* generate_name_trn_id(); */ /* Not used, so gone, RJS */ -- cgit From 92ebc81734a8a4165f88eeba9c05a05ea2917584 Mon Sep 17 00:00:00 2001 From: Richard Sharpe Date: Thu, 4 Jan 2001 11:35:55 +0000 Subject: I need a callback arg for cli_NetServerEnum and cli_RNetShareEnum, so I had to modifiy any routine that calls it to pass NULL and so forth. Should have no impact. It compiles OK. (This used to be commit 7f862e387f935a2125481338eee850afcb8d82ba) --- source3/nmbd/nmbd_synclists.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 7d10250325..bc731a9ceb 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -51,7 +51,8 @@ static FILE *fp; This is the NetServerEnum callback. Note sname and comment are in UNIX codepage format. ******************************************************************/ -static void callback(const char *sname, uint32 stype, const char *comment) +static void callback(const char *sname, uint32 stype, + const char *comment, void *state) { fprintf(fp,"\"%s\" %08X \"%s\"\n", sname, stype, comment); } @@ -108,8 +109,8 @@ static void sync_child(char *name, int nm_type, /* Fetch a workgroup list. */ cli_NetServerEnum(&cli, unix_workgroup, - local_type|SV_TYPE_DOMAIN_ENUM, - callback); + local_type|SV_TYPE_DOMAIN_ENUM, + callback, NULL); /* Now fetch a server list. */ if (servers) { @@ -117,7 +118,7 @@ static void sync_child(char *name, int nm_type, dos_to_unix(unix_workgroup, True); cli_NetServerEnum(&cli, unix_workgroup, local?SV_TYPE_LOCAL_LIST_ONLY:SV_TYPE_ALL, - callback); + callback, NULL); } cli_shutdown(&cli); -- cgit From fcfaebda7fb35989e62bc317287896c410c7833b Mon Sep 17 00:00:00 2001 From: David O'Neill Date: Thu, 25 Jan 2001 16:36:42 +0000 Subject: Changes from APPLIANCE_HEAD: source/smbd/server.c source/nmbd/nmbd.c - Fixed a very subtle bug with signals. Seems that POSIX requires that the signal mask be inhereted. So, if you happen to kick off smbd/nmbd from code that has the mask set on SIGUSR1, you lose messages. (This used to be commit b4c98196fc65e8b3bce928296e854987622eae78) --- source3/nmbd/nmbd.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 5b9a00aad0..f772788341 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -686,6 +686,12 @@ static void usage(char *pname) fault_setup((void (*)(void *))fault_continue ); + /* POSIX demands that signals are inherited. If the invoking process has + * these signals masked, we will have problems, as we won't recieve them. */ + BlockSignals(False, SIGHUP); + BlockSignals(False, SIGUSR1); + BlockSignals(False, SIGTERM); + CatchSignal( SIGHUP, SIGNAL_CAST sig_hup ); CatchSignal( SIGTERM, SIGNAL_CAST sig_term ); -- cgit From a82df9c67367e0828afcc65b0635187c73e2813a Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Thu, 15 Feb 2001 19:50:34 +0000 Subject: samba/source/nmbd/nmbd.c change remote_machine name to nmbd instead of nmb so we write to same log file that was originally created as log.nmbd samba/source/smbd/server.c change remote_machine name to smbd instead of smb so we write to same log file that was originally created as log.smbd samba/source/lib/interface.c allow binding to all interface IP addresses even if on same subnet. This allows you to specify which IP's you want in interfaces line and use bind interfaces only (This used to be commit 01dfd59712f3730498784d7632da8fe0113d55b6) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index f772788341..32d66d39fd 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -272,7 +272,7 @@ static BOOL reload_nmbd_services(BOOL test) BOOL ret; extern fstring remote_machine; - fstrcpy( remote_machine, "nmb" ); + fstrcpy( remote_machine, "nmbd" ); if ( lp_loaded() ) { -- cgit From 6c99c38cbf8726090648e081a690039c6eb59f62 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 8 Mar 2001 22:29:39 +0000 Subject: Fixed double fclose() call (I love insure :-). Jeremy. (This used to be commit 0a84839dc046c17375daea4ed18ef118887ef421) --- source3/nmbd/nmbd_synclists.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index bc731a9ceb..23cbc01b88 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -74,7 +74,6 @@ static void sync_child(char *name, int nm_type, struct nmb_name called, calling; if (!cli_initialise(&cli) || !cli_connect(&cli, name, &ip)) { - fclose(fp); return; } @@ -84,7 +83,6 @@ static void sync_child(char *name, int nm_type, if (!cli_session_request(&cli, &calling, &called)) { cli_shutdown(&cli); - fclose(fp); return; } -- cgit From 4ab6182a0ffdbe92a01dd6533e0862aa8d0f6d83 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 15 Mar 2001 00:49:13 +0000 Subject: AS/U on a sparc now joins and authenticates against a Samba PDC ! Jeremy. (This used to be commit 28a0bc5f5710aa732db662caa38f9da2138b5db2) --- source3/nmbd/nmbd_processlogon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 0da25a313d..5e554ceae2 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -102,7 +102,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); send_mailslot(True, getdc, outbuf,PTR_DIFF(q,outbuf), global_myname, 0x0, - dgram->source_name.name, + machine, dgram->source_name.name_type, p->ip, *iface_ip(p->ip), p->port); break; -- cgit From 0f2b15707ad0e41b786f0078f334b7782d63b8af Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 21 Mar 2001 04:12:36 +0000 Subject: added option "enhanced browsing" this allows users to disable the cross-subnet browse extensions that I added to Samba a couple of years ago. This may be useful for getting rid of empty workgroups. (This used to be commit 978980050e599d3830d0474bc9a8003bfe227719) --- source3/nmbd/nmbd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 32d66d39fd..5e8e7e1ec6 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -460,7 +460,9 @@ static void process(void) * This will only work to a Samba WINS server. * (nmbd_browsesync.c) */ - collect_all_workgroup_names_from_wins_server(t); + if (lp_enhanced_browsing()) { + collect_all_workgroup_names_from_wins_server(t); + } /* * Go through the response record queue and time out or re-transmit @@ -477,7 +479,9 @@ static void process(void) /* * regularly sync with any other DMBs we know about */ - sync_all_dmbs(t); + if (lp_enhanced_browsing()) { + sync_all_dmbs(t); + } /* * clear the unexpected packet queue -- cgit From 370664344a138ada6779dab23fa31bc4e0794e1a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 23 Mar 2001 19:01:27 +0000 Subject: Fix insure-found parameter size missmatch. Jeremy. (This used to be commit 2f658691e47406f38bec2fc20951f82043fbf894) --- source3/nmbd/nmbd_workgroupdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 485253680b..01477c8113 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -52,7 +52,7 @@ static void add_workgroup(struct subnet_record *subrec, struct work_record *work Create an empty workgroup. **************************************************************************/ -static struct work_record *create_workgroup(char *name, int ttl) +static struct work_record *create_workgroup(const char *name, int ttl) { struct work_record *work; struct subnet_record *subrec; @@ -180,7 +180,7 @@ struct work_record *find_workgroup_on_subnet(struct subnet_record *subrec, **************************************************************************/ struct work_record *create_workgroup_on_subnet(struct subnet_record *subrec, - fstring name, int ttl) + const char *name, int ttl) { struct work_record *work = NULL; -- cgit From f9a15ce1a69f905e94db7650f0a4805720cd9c88 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 8 Apr 2001 20:22:39 +0000 Subject: Got "medieval on our ass" about adding the -1 to slprintf. Jeremy. (This used to be commit 94747b4639ed9b19f7d0fb896e43aa392a84989a) --- source3/nmbd/nmbd.c | 2 +- source3/nmbd/nmbd_winsserver.c | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 5e8e7e1ec6..e176abbe6f 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -672,7 +672,7 @@ static void usage(char *pname) TimeInit(); - slprintf(debugf, sizeof(debugf), "%s/log.nmbd", LOGFILEBASE); + slprintf(debugf, sizeof(debugf)-1, "%s/log.nmbd", LOGFILEBASE); setup_logging( argv[0], False ); charset_initialise(); diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 33b33040cb..454b2170aa 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -50,7 +50,7 @@ static void wins_hook(char *operation, struct name_record *namerec, int ttl) } p = command; - p += slprintf(p, sizeof(command), "%s %s %s %02x %d", + p += slprintf(p, sizeof(command)-1, "%s %s %s %02x %d", cmd, operation, namerec->name.name, @@ -58,7 +58,7 @@ static void wins_hook(char *operation, struct name_record *namerec, int ttl) ttl); for (i=0;idata.num_ips;i++) { - p += slprintf(p, sizeof(command) - (p-command), " %s", inet_ntoa(namerec->data.ip[i])); + p += slprintf(p, sizeof(command) - (p-command) -1, " %s", inet_ntoa(namerec->data.ip[i])); } DEBUG(3,("calling wins hook for %s\n", nmb_namestr(&namerec->name))); @@ -1597,9 +1597,9 @@ void wins_write_database(BOOL background) } } - slprintf(fname,sizeof(fname),"%s/%s", lp_lockdir(), WINS_LIST); + slprintf(fname,sizeof(fname)-1,"%s/%s", lp_lockdir(), WINS_LIST); all_string_sub(fname,"//", "/", 0); - slprintf(fnamenew,sizeof(fnamenew),"%s.%u", fname, (unsigned int)sys_getpid()); + slprintf(fnamenew,sizeof(fnamenew)-1,"%s.%u", fname, (unsigned int)sys_getpid()); if((fp = sys_fopen(fnamenew,"w")) == NULL) { -- cgit From 50e78a9ac8cf0949c2471fafde844c674f97d73d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 13 Apr 2001 00:37:00 +0000 Subject: As Andrew suggested, make smbrun return a fd for a deleted file which can then be read. Jeremy. (This used to be commit e7d59d6de89a5fdd201e4b5c6072dab08b1519db) --- source3/nmbd/nmbd_winsserver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 454b2170aa..7836f0570c 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -62,7 +62,7 @@ static void wins_hook(char *operation, struct name_record *namerec, int ttl) } DEBUG(3,("calling wins hook for %s\n", nmb_namestr(&namerec->name))); - smbrun(command, NULL, False); + smbrun(command, NULL, NULL); } -- cgit From 2ef68c7e92d4661664f0410509f7cb551e74a198 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 13 Apr 2001 19:12:06 +0000 Subject: Merge of Andrew's changes in 2.2. Jeremy. (This used to be commit fc76681812b1469208ad6c8847afdfc68bc6db49) --- source3/nmbd/nmbd_winsserver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 7836f0570c..296102fd99 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -62,7 +62,7 @@ static void wins_hook(char *operation, struct name_record *namerec, int ttl) } DEBUG(3,("calling wins hook for %s\n", nmb_namestr(&namerec->name))); - smbrun(command, NULL, NULL); + smbrun(command, NULL); } -- cgit From 38227191ed2228ac6a07f826a68ace253cbd11dc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 24 Apr 2001 18:01:40 +0000 Subject: Patch for nmbd core dump in printing debug packets. No length check. Jeremy. (This used to be commit eacb96396d57d6b622b750d64b3686e6fbeaf68c) --- source3/nmbd/nmbd_packets.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 8b10298561..142268b0b0 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -107,12 +107,14 @@ static void debug_browse_data(char *outbuf, int len) for (j = 0; j < 16; j++) { - unsigned char x = outbuf[i+j]; + unsigned char x; + if (i+j >= len) + break; + + x = outbuf[i+j]; if (x < 32 || x > 127) x = '.'; - if (i+j >= len) - break; DEBUGADD( 4, ( "%c", x ) ); } -- cgit From a7e07d149d76a4d62aba6801ac648c0c72999ea9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 24 Apr 2001 23:51:57 +0000 Subject: Fix bad length in dgram. Jeremy. (This used to be commit 8bd27845f0d8b19409ba79c028ce54732d7276e1) --- source3/nmbd/nmbd_packets.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 142268b0b0..3fa382b96f 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1273,6 +1273,13 @@ an error packet of type %x\n", if (len <= 0) return; + if (buf2 + len > buf + sizeof(dgram->data)) { + DEBUG(2,("process_dgram: datagram from %s to %s IP %s for %s of type %d len=%d too long.\n", + nmb_namestr(&dgram->source_name),nmb_namestr(&dgram->dest_name), + inet_ntoa(p->ip), smb_buf(buf),CVAL(buf2,0),len)); + len = (buf + sizeof(dgram->data)) - buf; + } + /* Datagram packet received for the browser mailslot */ if (strequal(smb_buf(buf),BROWSE_MAILSLOT)) { -- cgit From 30c02f987186963ed768c843ff2fc411d0cc7166 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 25 Apr 2001 01:07:33 +0000 Subject: More paranioa fixes against nmbd lengths. Jeremy. (This used to be commit 53f35a71c6fc46814eca914573506622d7db4e08) --- source3/nmbd/nmbd_packets.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 3fa382b96f..dcdf1a9df1 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1265,21 +1265,21 @@ an error packet of type %x\n", len = SVAL(buf,smb_vwv11); buf2 = smb_base(buf) + SVAL(buf,smb_vwv12); - DEBUG(4,("process_dgram: datagram from %s to %s IP %s for %s of type %d len=%d\n", - nmb_namestr(&dgram->source_name),nmb_namestr(&dgram->dest_name), - inet_ntoa(p->ip), smb_buf(buf),CVAL(buf2,0),len)); - - if (len <= 0) return; if (buf2 + len > buf + sizeof(dgram->data)) { - DEBUG(2,("process_dgram: datagram from %s to %s IP %s for %s of type %d len=%d too long.\n", + DEBUG(2,("process_dgram: datagram from %s to %s IP %s for %s %d len=%d too long.\n", nmb_namestr(&dgram->source_name),nmb_namestr(&dgram->dest_name), - inet_ntoa(p->ip), smb_buf(buf),CVAL(buf2,0),len)); + inet_ntoa(p->ip), smb_buf(buf),len)); len = (buf + sizeof(dgram->data)) - buf; } + DEBUG(4,("process_dgram: datagram from %s to %s IP %s for %s of type %d len=%d\n", + nmb_namestr(&dgram->source_name),nmb_namestr(&dgram->dest_name), + inet_ntoa(p->ip), smb_buf(buf),CVAL(buf2,0),len)); + + /* Datagram packet received for the browser mailslot */ if (strequal(smb_buf(buf),BROWSE_MAILSLOT)) { -- cgit From 7d72ec3eda198b0fdbedd7ca227898e02a5319ad Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 27 Apr 2001 22:19:25 +0000 Subject: Mismatched format and args. Jeremy. (This used to be commit d57feb2c85f973ad22098054b8d6d049869e2a69) --- source3/nmbd/nmbd_packets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index dcdf1a9df1..00059c1775 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1269,7 +1269,7 @@ an error packet of type %x\n", return; if (buf2 + len > buf + sizeof(dgram->data)) { - DEBUG(2,("process_dgram: datagram from %s to %s IP %s for %s %d len=%d too long.\n", + DEBUG(2,("process_dgram: datagram from %s to %s IP %s for %s len=%d too long.\n", nmb_namestr(&dgram->source_name),nmb_namestr(&dgram->dest_name), inet_ntoa(p->ip), smb_buf(buf),len)); len = (buf + sizeof(dgram->data)) - buf; -- cgit From b95a294a0879e800e816281a80d0074224cd8cd4 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 25 Jun 2001 02:53:13 +0000 Subject: fixed usage of socklen_t and also tidied up SIG_ATOMIC_T, using a typedef instead of a define (This used to be commit e2ecff419fdc0a0dc7551b33b377dc11061ef2a3) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index e176abbe6f..2fab8f6bc7 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -83,7 +83,7 @@ static void sig_term(int sig) /**************************************************************************** ** catch a sighup **************************************************************************** */ -static VOLATILE SIG_ATOMIC_T reload_after_sighup = False; +static VOLATILE sig_atomic_t reload_after_sighup = False; static void sig_hup(int sig) { -- cgit From 9e7896144ae1f7cc4539d875e6c2a94f8b54a2bb Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Thu, 28 Jun 2001 20:49:47 +0000 Subject: Added info to some of the debug messages to get a better handle on a problem people are reporting regarding multiple responses to queries on <1D> names. There should only ever be one LMB but some users are seeing multiple replies to queries for the LMB name. This is probably due to nodes on the LAN that have NetBIOS over NetBEUI and/or IPX enabled. Previously, the debug message did not include the IP address associated with the name. It *did* include the source address of the packet, but in the examples I've seen all of these were the same, eg: [2000/06/22 11:58:25, 0] nmbd/nmbd_namequery.c:query_name_response(93) query_name_response: Multiple (2) responses received for a query on subnet 129.130.10.136 for name NT.CIS.KSU.EDU<1d>. This response was from IP 129.130.10.24 [2000/06/22 11:58:25, 0] nmbd/nmbd_namequery.c:query_name_response(93) query_name_response: Multiple (3) responses received for a query on subnet 129.130.10.136 for name NT.CIS.KSU.EDU<1d>. This response was from IP 129.130.10.24 [2000/06/22 11:58:25, 0] nmbd/nmbd_namequery.c:query_name_response(93) query_name_response: Multiple (4) responses received for a query on subnet 129.130.10.136 for name NT.CIS.KSU.EDU<1d>. This response was from IP 129.130.10.24 [2000/06/22 11:58:25, 0] nmbd/nmbd_namequery.c:query_name_response(93) query_name_response: Multiple (5) responses received for a query on subnet 129.130.10.136 for name NT.CIS.KSU.EDU<1d>. This response was from IP 129.130.10.24 Note that all of the above are reported as having come from 129.130.10.24. This should never happen. If 129.130.10.24 is a WINS server it should send a Negative Name Query Response for a <1D> name query (wierd but true). So, are all of the above coming from different systems, all of which think are the LMB? Are they all coming from one system that is, for some strange reason, replying five times to the same query? Anyway, I needed more info so I've changed the debug messages. Chris -)----- (This used to be commit 8f2f09af0a0a80cacef933ed500884e2c0b3f2fb) --- source3/nmbd/nmbd_namequery.c | 80 ++++++++++++++++++++++++++++++------------- 1 file changed, 56 insertions(+), 24 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index 57baa4cb2f..61435c14f5 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -30,8 +30,9 @@ extern int DEBUGLEVEL; Deal with a response packet when querying a name. ****************************************************************************/ -static void query_name_response(struct subnet_record *subrec, - struct response_record *rrec, struct packet_struct *p) +static void query_name_response( struct subnet_record *subrec, + struct response_record *rrec, + struct packet_struct *p) { struct nmb_packet *nmb = &p->packet.nmb; BOOL success = False; @@ -52,9 +53,14 @@ static void query_name_response(struct subnet_record *subrec, { /* WINS server is telling us to wait. Pretend we didn't get the response but don't send out any more query requests. */ - - DEBUG(5,("query_name_response: WACK from WINS server %s in querying \ -name %s on subnet %s.\n", inet_ntoa(p->ip), nmb_namestr(question_name), subrec->subnet_name)); + + if( DEBUGLVL( 5 ) ) + { + dbgtext( "query_name_response: " ); + dbgtext( "WACK from WINS server %s ", inet_ntoa(p->ip) ); + dbgtext( "in querying name %s ", nmb_namestr(question_name) ); + dbgtext( "on subnet %s.\n", subrec->subnet_name ); + } rrec->repeat_count = 0; /* How long we should wait for. */ @@ -66,18 +72,26 @@ name %s on subnet %s.\n", inet_ntoa(p->ip), nmb_namestr(question_name), subrec-> { success = False; - DEBUG(5,("query_name_response: On subnet %s - negative response \ -from IP %s for name %s. Error code was %d.\n", subrec->subnet_name, inet_ntoa(p->ip), - nmb_namestr(question_name), nmb->header.rcode)); + if( DEBUGLVL( 5 ) ) + { + dbgtext( "query_name_response: On subnet %s ", subrec->subnet_name ); + dbgtext( "- negative response from IP %s ", inet_ntoa(p->ip) ); + dbgtext( "for name %s. ", nmb_namestr(question_name) ); + dbgtext( "Error code was %d.\n", nmb->header.rcode ); + } } else { success = True; putip((char *)&answer_ip,&nmb->answers->rdata[2]); - DEBUG(5,("query_name_response: On subnet %s - positive response from IP %s \ -for name %s. IP of that name is %s\n", subrec->subnet_name, inet_ntoa(p->ip), - nmb_namestr(question_name), inet_ntoa(answer_ip))); + if( DEBUGLVL( 5 ) ) + { + dbgtext( "query_name_response: On subnet %s ", subrec->subnet_name ); + dbgtext( "- positive response from IP %s ", inet_ntoa(p->ip) ); + dbgtext( "for name %s. ", nmb_namestr(question_name) ); + dbgtext( "IP of that name is %s\n", inet_ntoa(answer_ip) ); + } /* Interestingly, we could add these names to our namelists, and change nmbd to a model that checked its own name cache first, @@ -87,10 +101,15 @@ for name %s. IP of that name is %s\n", subrec->subnet_name, inet_ntoa(p->ip), } else if( rrec->num_msgs > 1) { - DEBUG(0,("query_name_response: Multiple (%d) responses received for a query on \ -subnet %s for name %s. This response was from IP %s\n", - rrec->num_msgs, subrec->subnet_name, nmb_namestr(question_name), - inet_ntoa(p->ip) )); + if( DEBUGLVL( 0 ) ) + { + dbgtext( "query_name_response: " ); + dbgtext( "Multiple (%d) responses ", rrec->num_msgs ); + dbgtext( "received for a query on subnet %s ", subrec->subnet_name ); + dbgtext( "for name %s.\nThis response ", nmb_namestr(question_name) ); + dbgtext( "was from IP %s, reporting", inet_ntoa(p->ip) ); + dbgtext( "an IP address of %s.\n", inet_ntoa(answer_ip) ); + } /* We have already called the success or fail function, so we don't call again here. Leave the response record around in @@ -128,9 +147,12 @@ static void query_name_timeout_response(struct subnet_record *subrec, if(failed) { - DEBUG(5,("query_name_timeout_response: No response to querying name %s on subnet %s.\n", - nmb_namestr(question_name), subrec->subnet_name)); - + if( DEBUGLVL( 5 ) ) + { + dbgtext( "query_name_timeout_response: No response to " ); + dbgtext( "query for name %s ", nmb_namestr(question_name) ); + dbgtext( "on subnet %s.\n", subrec->subnet_name ); + } if(rrec->fail_fn) (*rrec->fail_fn)(subrec, rrec, question_name, 0); } @@ -201,8 +223,12 @@ BOOL query_name(struct subnet_record *subrec, char *name, int type, rrec.rdlength = namerec->data.num_ips * 6; if(rrec.rdlength > MAX_DGRAM_SIZE) { - DEBUG(0,("query_name: nmbd internal error - there are %d ip addresses for name %s.\n", - namerec->data.num_ips, nmb_namestr(&nmbname) )); + if( DEBUGLVL( 0 ) ) + { + dbgtext( "query_name: nmbd internal error - " ); + dbgtext( "there are %d ip addresses ", namerec->data.num_ips ); + dbgtext( "for name %s.\n", nmb_namestr(&nmbname) ); + } return False; } @@ -226,8 +252,11 @@ BOOL query_name(struct subnet_record *subrec, char *name, int type, userdata, &nmbname) == NULL) { - DEBUG(0,("query_name: Failed to send packet trying to query name %s\n", - nmb_namestr(&nmbname))); + if( DEBUGLVL( 0 ) ) + { + dbgtext( "query_name: Failed to send packet " ); + dbgtext( "trying to query name %s\n", nmb_namestr(&nmbname) ); + } return True; } return False; @@ -255,8 +284,11 @@ BOOL query_name_from_wins_server(struct in_addr ip_to, userdata, &nmbname) == NULL) { - DEBUG(0,("query_name_from_wins_server: Failed to send packet trying to query name %s\n", - nmb_namestr(&nmbname))); + if( DEBUGLVL( 0 ) ) + { + dbgtext( "query_name_from_wins_server: Failed to send packet " ); + dbgtext( "trying to query name %s\n", nmb_namestr(&nmbname) ); + } return True; } return False; -- cgit From ef6c9d7425be907230eb533fbbe2e6ac150a0bbd Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 1 Jul 2001 23:24:08 +0000 Subject: "netbios aliases" and "interfaces" options change from P_STRING to P_LIST (This used to be commit db36ed1d80fcbee16d0a0b5f226e56961f3bf1ec) --- source3/nmbd/nmbd.c | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 2fab8f6bc7..2969c332d5 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -549,11 +549,11 @@ static BOOL open_sockets(BOOL isdaemon, int port) static BOOL init_structs(void) { extern fstring local_machine; - char *p, *ptr; + char *p, **ptr; int namecount; int n; int nodup; - pstring nbname; + char *nbname; if (! *global_myname) { @@ -569,7 +569,7 @@ static BOOL init_structs(void) */ /* Work out the max number of netbios aliases that we have */ ptr = lp_netbios_aliases(); - for( namecount=0; next_token(&ptr,nbname,NULL, sizeof(nbname)); namecount++ ) + for( namecount=0; *ptr; namecount++,ptr++ ) ; if ( *global_myname ) namecount++; @@ -588,8 +588,14 @@ static BOOL init_structs(void) my_netbios_names[namecount++] = global_myname; ptr = lp_netbios_aliases(); - while ( next_token( &ptr, nbname, NULL, sizeof(nbname) ) ) + while ( *ptr ) { + nbname = strdup(*ptr); + if (nbname == NULL) + { + DEBUG(0,("init_structs: malloc fail when allocating names.\n")); + return False; + } strupper( nbname ); /* Look for duplicates */ nodup=1; @@ -599,17 +605,13 @@ static BOOL init_structs(void) nodup=0; } if (nodup) - my_netbios_names[namecount++] = strdup( nbname ); + my_netbios_names[namecount++] = nbname; + else + free(nbname); + + ptr++; } - /* Check the strdups succeeded. */ - for( n = 0; n < namecount; n++ ) - if( NULL == my_netbios_names[n] ) - { - DEBUG(0,("init_structs: malloc fail when allocating names.\n")); - return False; - } - /* Terminate name list */ my_netbios_names[namecount++] = NULL; -- cgit From 89ee12d37399ac77f3532f9dfee5e52b7359f552 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 3 Jul 2001 00:23:38 +0000 Subject: - sorry, forgot to test a pointer (This used to be commit 1aef52245229741bc24c3e8147fa86eaa20fe9b2) --- source3/nmbd/nmbd.c | 47 ++++++++++++++++++++++++++--------------------- 1 file changed, 26 insertions(+), 21 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 2969c332d5..8a6bf383d1 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -569,8 +569,10 @@ static BOOL init_structs(void) */ /* Work out the max number of netbios aliases that we have */ ptr = lp_netbios_aliases(); - for( namecount=0; *ptr; namecount++,ptr++ ) - ; + namecount = 0; + if (ptr) + for( ; *ptr; namecount++,ptr++ ) + ; if ( *global_myname ) namecount++; @@ -588,28 +590,31 @@ static BOOL init_structs(void) my_netbios_names[namecount++] = global_myname; ptr = lp_netbios_aliases(); - while ( *ptr ) + if (ptr) { - nbname = strdup(*ptr); - if (nbname == NULL) + while ( *ptr ) { - DEBUG(0,("init_structs: malloc fail when allocating names.\n")); - return False; + nbname = strdup(*ptr); + if (nbname == NULL) + { + DEBUG(0,("init_structs: malloc fail when allocating names.\n")); + return False; + } + strupper( nbname ); + /* Look for duplicates */ + nodup=1; + for( n=0; n Date: Wed, 4 Jul 2001 07:15:53 +0000 Subject: The big character set handling changeover! This commit gets rid of all our old codepage handling and replaces it with iconv. All internal strings in Samba are now in "unix" charset, which may be multi-byte. See internals.doc and my posting to samba-technical for a more complete explanation. (This used to be commit debb471267960e56005a741817ebd227ecfc512a) --- source3/nmbd/nmbd.c | 4 ---- source3/nmbd/nmbd_processlogon.c | 8 ++++---- source3/nmbd/nmbd_sendannounce.c | 17 +++++++---------- source3/nmbd/nmbd_synclists.c | 5 ----- 4 files changed, 11 insertions(+), 23 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 8a6bf383d1..ca9d04d768 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -682,8 +682,6 @@ static void usage(char *pname) slprintf(debugf, sizeof(debugf)-1, "%s/log.nmbd", LOGFILEBASE); setup_logging( argv[0], False ); - charset_initialise(); - #ifdef LMHOSTSFILE pstrcpy( host_file, LMHOSTSFILE ); #endif @@ -783,8 +781,6 @@ static void usage(char *pname) if ( !reload_nmbd_services(False) ) return(-1); - codepage_initialise(lp_client_code_page()); - if(!init_structs()) return -1; diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 5e554ceae2..3e4591c0cf 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -163,7 +163,6 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); q += dos_PutUniCode(q, my_name, sizeof(pstring), True); /* PDC name */ q += dos_PutUniCode(q, global_myworkgroup,sizeof(pstring), True); /* Domain name*/ - SIVAL(q, 0, 1); /* our nt version */ SSVAL(q, 4, 0xffff); /* our lmnttoken */ SSVAL(q, 6, 0xffff); /* our lm20token */ @@ -192,6 +191,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", case SAMLOGON: { char *q = buf + 2; + fstring asccomp; q += 2; unicomp = q; @@ -236,15 +236,15 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", * database. If it isn't then we let smbd send an appropriate error. * Let's ignore the SID. */ - - pstrcpy(ascuser, dos_unistr(uniuser)); + pull_ucs2_pstring(ascuser, uniuser); + pull_ucs2_fstring(asccomp, unicomp); DEBUG(3,("process_logon_packet: SAMLOGON user %s\n", ascuser)); fstrcpy(reply_name,"\\\\"); /* Here it wants \\LOGONSERVER. */ fstrcpy(reply_name+2,my_name); DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n", - dos_unistr(unicomp),inet_ntoa(p->ip), ascuser, reply_name, global_myworkgroup, + asccomp,inet_ntoa(p->ip), ascuser, reply_name, global_myworkgroup, SAMLOGON_R ,lmnttoken)); /* Construct reply. */ diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index 87115a1eb0..eb5839253b 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -80,9 +80,7 @@ to subnet %s\n", work->work_group, subrec->subnet_name)); CVAL(p,0) = work->token; /* (local) Unique workgroup token id. */ p++; - StrnCpy(p,global_myname,15); - strupper(p); - p = skip_string(p,1); + p += push_string(NULL, p+1, global_myname, 15, STR_ASCII|STR_UPPER|STR_TERMINATE); send_mailslot(False, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), global_myname, 0x0, work->work_group,0x1e, subrec->bcast_ip, @@ -110,8 +108,7 @@ static void send_announcement(struct subnet_record *subrec, int announce_type, CVAL(p,0) = updatecount; SIVAL(p,1,announce_interval*1000); /* Milliseconds - despite the spec. */ - StrnCpy(p+5,server_name,15); - strupper(p+5); + push_string(NULL, p+5, server_name, 15, STR_ASCII|STR_UPPER|STR_TERMINATE); CVAL(p,21) = lp_major_announce_version(); /* Major version. */ CVAL(p,22) = lp_minor_announce_version(); /* Minor version. */ @@ -121,9 +118,7 @@ static void send_announcement(struct subnet_record *subrec, int announce_type, SSVAL(p,27,BROWSER_ELECTION_VERSION); SSVAL(p,29,BROWSER_CONSTANT); /* Browse signature. */ - pstrcpy(p+31,server_comment); - p += 31; - p = skip_string(p,1); + p += 31 + push_string(NULL, p+31, server_comment, -1, STR_ASCII|STR_TERMINATE); send_mailslot(False,BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), from_name, 0x0, to_name, to_type, to_ip, subrec->myip, @@ -151,11 +146,13 @@ static void send_lm_announcement(struct subnet_record *subrec, int announce_type SSVAL(p,8,announce_interval); /* In seconds - according to spec. */ p += 10; - StrnCpy(p,server_name,15); + /*StrnCpy(p,server_name,15); strupper(p); p = skip_string(p,1); pstrcpy(p,server_comment); - p = skip_string(p,1); + p = skip_string(p,1);*/ + p += push_string(NULL, p, server_name, 15, STR_ASCII|STR_UPPER|STR_TERMINATE); + p += push_string(NULL, p, server_comment, sizeof(pstring)-15, STR_ASCII|STR_UPPER|STR_TERMINATE); send_mailslot(False,LANMAN_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), from_name, 0x0, to_name, to_type, to_ip, subrec->myip, diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 23cbc01b88..29462685b0 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -103,7 +103,6 @@ static void sync_child(char *name, int nm_type, /* All the cli_XX functions take UNIX character set. */ fstrcpy(unix_workgroup, cli.server_domain?cli.server_domain:workgroup); - dos_to_unix(unix_workgroup, True); /* Fetch a workgroup list. */ cli_NetServerEnum(&cli, unix_workgroup, @@ -113,7 +112,6 @@ static void sync_child(char *name, int nm_type, /* Now fetch a server list. */ if (servers) { fstrcpy(unix_workgroup, workgroup); - dos_to_unix(unix_workgroup, True); cli_NetServerEnum(&cli, unix_workgroup, local?SV_TYPE_LOCAL_LIST_ONLY:SV_TYPE_ALL, callback, NULL); @@ -254,9 +252,6 @@ static void complete_sync(struct sync_record *s) ptr = line; - /* The line is written in UNIX character set. Convert to DOS codepage. */ - unix_to_dos(line,True); - if (!next_token(&ptr,server,NULL,sizeof(server)) || !next_token(&ptr,type_str,NULL, sizeof(type_str)) || !next_token(&ptr,comment,NULL, sizeof(comment))) { -- cgit From 527e824293ee934ca5da0ef5424efe5ab7757248 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 4 Jul 2001 07:36:09 +0000 Subject: strchr and strrchr are macros when compiling with optimisation in gcc, so we can't redefine them. damn. (This used to be commit c41fc06376d1a2b83690612304e85010b5e5f3cf) --- source3/nmbd/nmbd.c | 6 +++--- source3/nmbd/nmbd_sendannounce.c | 2 +- source3/nmbd/nmbd_winsserver.c | 8 ++++---- 3 files changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index ca9d04d768..8b771bc452 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -111,7 +111,7 @@ static BOOL dump_core(void) char *p; pstring dname; pstrcpy( dname, debugf ); - if ((p=strrchr(dname,'/'))) + if ((p=strrchr_m(dname,'/'))) *p=0; pstrcat( dname, "/corefiles" ); mkdir( dname, 0700 ); @@ -558,7 +558,7 @@ static BOOL init_structs(void) if (! *global_myname) { fstrcpy( global_myname, myhostname() ); - p = strchr( global_myname, '.' ); + p = strchr_m( global_myname, '.' ); if (p) *p = 0; } @@ -622,7 +622,7 @@ static BOOL init_structs(void) fstrcpy( local_machine, global_myname ); trim_string( local_machine, " ", " " ); - p = strchr( local_machine, ' ' ); + p = strchr_m( local_machine, ' ' ); if (p) *p = 0; strlower( local_machine ); diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index eb5839253b..32a6d339de 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -510,7 +510,7 @@ void announce_remote(time_t t) char *wgroup; int i; - wgroup = strchr(s2,'/'); + wgroup = strchr_m(s2,'/'); if (wgroup) *wgroup++ = 0; if (!wgroup || !*wgroup) diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 296102fd99..0ba1aef057 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -43,7 +43,7 @@ static void wins_hook(char *operation, struct name_record *namerec, int ttl) if (!cmd || !*cmd) return; for (p=namerec->name.name; *p; p++) { - if (!(isalnum((int)*p) || strchr("._-",*p))) { + if (!(isalnum((int)*p) || strchr_m("._-",*p))) { DEBUG(3,("not calling wins hook for invalid name %s\n", nmb_namestr(&namerec->name))); return; } @@ -255,7 +255,7 @@ BOOL initialise_wins(void) got_token = next_token(&ptr,ip_str,NULL,sizeof(ip_str)); was_ip = False; - if(got_token && strchr(ip_str, '.')) + if(got_token && strchr_m(ip_str, '.')) { num_ips++; was_ip = True; @@ -310,7 +310,7 @@ BOOL initialise_wins(void) /* Netbios name. # divides the name from the type (hex): netbios#xx */ pstrcpy(name,name_str); - if((p = strchr(name,'#')) != NULL) + if((p = strchr_m(name,'#')) != NULL) { *p = 0; sscanf(p+1,"%x",&type); @@ -1630,7 +1630,7 @@ void wins_write_database(BOOL background) tm = LocalTime(&namerec->data.death_time); ts = asctime(tm); - nl = strrchr( ts, '\n' ); + nl = strrchr_m( ts, '\n' ); if( NULL != nl ) *nl = '\0'; DEBUGADD(4,("TTL = %s ", ts )); -- cgit From 973a78c2db1e15fc0a88b15d8857a8d7cf46a140 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Tue, 10 Jul 2001 16:10:04 +0000 Subject: Fix from John Malmberg. When I added the additional information to the debug block that reports multiple query responses I did not notice that the local answer_ip variable was only selectively set. Chris -)----- (This used to be commit 22ea0770d87b2faece2e5dfc098ccf27f4da155f) --- source3/nmbd/nmbd_namequery.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index 61435c14f5..67421103dd 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -40,6 +40,8 @@ static void query_name_response( struct subnet_record *subrec, &rrec->packet->packet.nmb.question.question_name; struct in_addr answer_ip; + answer_ip.S_un.S_addr = 0; /* Fix from JEM...should always initialize. */ + /* Ensure we don't retry the query but leave the response record cleanup to the timeout code. We may get more answer responses in which case we should mark the name in conflict.. */ @@ -103,6 +105,7 @@ static void query_name_response( struct subnet_record *subrec, { if( DEBUGLVL( 0 ) ) { + putip( (char *)&answer_ip, &nmb->answers->rdata[2] ); dbgtext( "query_name_response: " ); dbgtext( "Multiple (%d) responses ", rrec->num_msgs ); dbgtext( "received for a query on subnet %s ", subrec->subnet_name ); -- cgit From f8f1d9d5c3998dd9252bf13fb8b7968d08e2e062 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 10 Jul 2001 17:14:52 +0000 Subject: Fix tree breakage, the last change was entirly non-portable, and we already have this nice variable to do exactly this... (This used to be commit cad6f53433a9345c06ae94c5ef63434e72a2daea) --- source3/nmbd/nmbd_namequery.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index 67421103dd..662d3895dd 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -26,6 +26,8 @@ extern int DEBUGLEVEL; +extern struct in_addr ipzero; + /**************************************************************************** Deal with a response packet when querying a name. ****************************************************************************/ @@ -40,7 +42,7 @@ static void query_name_response( struct subnet_record *subrec, &rrec->packet->packet.nmb.question.question_name; struct in_addr answer_ip; - answer_ip.S_un.S_addr = 0; /* Fix from JEM...should always initialize. */ + answer_ip = ipzero; /* Fix from JEM...should always initialize. */ /* Ensure we don't retry the query but leave the response record cleanup to the timeout code. We may get more answer responses in which case -- cgit From bb8c1be67c09136768ed3166f4e14d3bdd4afdcc Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Tue, 10 Jul 2001 18:05:29 +0000 Subject: Andrew B and I were commiting the same fix at the same time in different trees. This change simply brings HEAD and 2.2 in line with one another. Otherwise the code would be differnt but the meaning would be the same, which is awkward. Chris 'fifty-seven commits per line changed' Hertel -)----- (This used to be commit bbf14e2d4e054e2af4f9cbbb05b86f6ac41084c6) --- source3/nmbd/nmbd_namequery.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index 662d3895dd..66af796b6f 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -25,7 +25,6 @@ #include "includes.h" extern int DEBUGLEVEL; - extern struct in_addr ipzero; /**************************************************************************** @@ -40,9 +39,7 @@ static void query_name_response( struct subnet_record *subrec, BOOL success = False; struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name; - struct in_addr answer_ip; - - answer_ip = ipzero; /* Fix from JEM...should always initialize. */ + struct in_addr answer_ip = ipzero; /* Ensure we don't retry the query but leave the response record cleanup to the timeout code. We may get more answer responses in which case -- cgit From c6b51500af5d4f09b4e08d57a7e930a0817e080b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 17 Jul 2001 20:42:59 +0000 Subject: Fixes from Jens-Uwe.Walther@force.de to make the -l option behave consistently. Jeremy. (This used to be commit f591ca9f25c54d3cdd0b76df472411e44c95ea47) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 8b771bc452..7795958ed0 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -737,7 +737,7 @@ static void usage(char *pname) strupper(global_myname); break; case 'l': - slprintf(debugf,sizeof(debugf)-1, "%s.nmb",optarg); + slprintf(debugf, sizeof(debugf)-1, "%s/log.nmbd", optarg); break; case 'a': append_log = True; -- cgit From 6597e1bd26125dbe16ad7250604bbd369705e921 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 30 Jul 2001 17:52:26 +0000 Subject: Fixes for varargs problems with std c. Fix from Rick Lake for QNX. Jeremy. (This used to be commit c13b77eb35fe51403a51e1a146cedc643e550de7) --- source3/nmbd/nmbd_namequery.c | 8 ++++---- source3/nmbd/nmbd_nameregister.c | 8 ++++---- source3/nmbd/nmbd_namerelease.c | 8 ++++---- source3/nmbd/nmbd_nodestatus.c | 2 +- 4 files changed, 13 insertions(+), 13 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index 66af796b6f..b497526475 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -121,9 +121,9 @@ static void query_name_response( struct subnet_record *subrec, } if(success && rrec->success_fn) - (*rrec->success_fn)(subrec, rrec->userdata, question_name, answer_ip, nmb->answers); + (*(query_name_success_function)rrec->success_fn)(subrec, rrec->userdata, question_name, answer_ip, nmb->answers); else if( rrec->fail_fn) - (*rrec->fail_fn)(subrec, rrec, question_name, nmb->header.rcode); + (*(query_name_fail_function)rrec->fail_fn)(subrec, rrec, question_name, nmb->header.rcode); } @@ -156,7 +156,7 @@ static void query_name_timeout_response(struct subnet_record *subrec, dbgtext( "on subnet %s.\n", subrec->subnet_name ); } if(rrec->fail_fn) - (*rrec->fail_fn)(subrec, rrec, question_name, 0); + (*(query_name_fail_function)rrec->fail_fn)(subrec, rrec, question_name, 0); } remove_response_record(subrec, rrec); @@ -242,7 +242,7 @@ BOOL query_name(struct subnet_record *subrec, char *name, int type, /* Call the success function directly. */ if(success_fn) - (*success_fn)(subrec, userdata, &nmbname, namerec->data.ip[0], &rrec); + (*(query_name_success_function)success_fn)(subrec, userdata, &nmbname, namerec->data.ip[0], &rrec); return False; } diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index 8805728737..6d4d66cbef 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -144,12 +144,12 @@ name %s on subnet %s.\n", inet_ntoa(p->ip), nmb_namestr(answer_name), subrec->su the success function. */ standard_success_register(subrec, rrec->userdata, answer_name, nb_flags, ttl, registered_ip); if( rrec->success_fn) - (*rrec->success_fn)(subrec, rrec->userdata, answer_name, nb_flags, ttl, registered_ip); + (*(register_name_success_function)rrec->success_fn)(subrec, rrec->userdata, answer_name, nb_flags, ttl, registered_ip); } else { if( rrec->fail_fn) - (*rrec->fail_fn)(subrec, rrec, question_name); + (*(register_name_fail_function)rrec->fail_fn)(subrec, rrec, question_name); /* Remove the name. */ standard_fail_register( subrec, rrec, question_name); } @@ -226,12 +226,12 @@ responding.\n", inet_ntoa(rrec->packet->ip))); the success function. */ standard_success_register(subrec, rrec->userdata, question_name, nb_flags, ttl, registered_ip); if( rrec->success_fn) - (*rrec->success_fn)(subrec, rrec->userdata, question_name, nb_flags, ttl, registered_ip); + (*(register_name_success_function)rrec->success_fn)(subrec, rrec->userdata, question_name, nb_flags, ttl, registered_ip); } else { if( rrec->fail_fn) - (*rrec->fail_fn)(subrec, rrec, question_name); + (*(register_name_fail_function)rrec->fail_fn)(subrec, rrec, question_name); /* Remove the name. */ standard_fail_register( subrec, rrec, question_name); } diff --git a/source3/nmbd/nmbd_namerelease.c b/source3/nmbd/nmbd_namerelease.c index 2e3b4e8c6a..0f693c63d0 100644 --- a/source3/nmbd/nmbd_namerelease.c +++ b/source3/nmbd/nmbd_namerelease.c @@ -99,14 +99,14 @@ name %s on subnet %s.\n", inet_ntoa(p->ip), nmb_namestr(answer_name), subrec->su putip((char*)&released_ip ,&nmb->answers->rdata[2]); if(rrec->success_fn) - (*rrec->success_fn)(subrec, rrec->userdata, answer_name, released_ip); + (*(release_name_success_function)rrec->success_fn)(subrec, rrec->userdata, answer_name, released_ip); standard_success_release( subrec, rrec->userdata, answer_name, released_ip); } else { /* We have no standard_fail_release - maybe we should add one ? */ if(rrec->fail_fn) - (*rrec->fail_fn)(subrec, rrec, answer_name); + (*(release_name_fail_function)rrec->fail_fn)(subrec, rrec, answer_name); } remove_response_record(subrec, rrec); @@ -174,14 +174,14 @@ responding.\n", inet_ntoa(rrec->packet->ip))); if(success && rrec->success_fn) { if(rrec->success_fn) - (*rrec->success_fn)(subrec, rrec->userdata, question_name, released_ip); + (*(release_name_success_function)rrec->success_fn)(subrec, rrec->userdata, question_name, released_ip); standard_success_release( subrec, rrec->userdata, question_name, released_ip); } else { /* We have no standard_fail_release - maybe we should add one ? */ if( rrec->fail_fn) - (*rrec->fail_fn)(subrec, rrec, question_name); + (*(release_name_fail_function)rrec->fail_fn)(subrec, rrec, question_name); } remove_response_record(subrec, rrec); diff --git a/source3/nmbd/nmbd_nodestatus.c b/source3/nmbd/nmbd_nodestatus.c index d78f8a5547..d28ea1cff4 100644 --- a/source3/nmbd/nmbd_nodestatus.c +++ b/source3/nmbd/nmbd_nodestatus.c @@ -52,7 +52,7 @@ name %s.\n", nmb_namestr(answer_name), nmb_namestr(question_name))); /* Just send the whole answer resource record for the success function to parse. */ if(rrec->success_fn) - (*rrec->success_fn)(subrec, rrec->userdata, nmb->answers, p->ip); + (*(node_status_success_function)rrec->success_fn)(subrec, rrec->userdata, nmb->answers, p->ip); /* Ensure we don't retry. */ remove_response_record(subrec, rrec); -- cgit From 2236c671a0ecf303492a644adae002a6cf009bf2 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 24 Aug 2001 19:21:40 +0000 Subject: Only register the #1b name if we are ROLE_DOMAIN_PDC rather than lp_domain_master() (This used to be commit b8fe147430fbceff5da8853e5240d251f2671d0e) --- source3/nmbd/nmbd_become_dmb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index 76d92c2f3e..089aa8f16a 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -382,7 +382,7 @@ void add_domain_names(time_t t) add_logon_names(); /* Do the domain master names. */ - if(lp_domain_master()) + if(lp_server_role() == ROLE_DOMAIN_PDC) { if(we_are_a_wins_client()) { -- cgit From c1f0d99013e0c29d76d51b81ec2396d055471a82 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 24 Aug 2001 19:28:08 +0000 Subject: Process the SAM/UAS change notification message. (This used to be commit efcbcfaa48d36063c974c20692ee2c38d09d2216) --- source3/nmbd/nmbd_processlogon.c | 73 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 73 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 3e4591c0cf..6d38b53070 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -31,6 +31,20 @@ extern int DEBUGLEVEL; extern pstring global_myname; extern fstring global_myworkgroup; +struct sam_database_info { + uint32 index; + uint32 serial_lo, serial_hi; + uint32 date_lo, date_hi; +}; + +/**************************************************************************** +Handle a sam/uas change notification +**************************************************************************/ +static void handle_sam_uas_change(int db_count, + struct sam_database_info *db_info) +{ +} + /**************************************************************************** Process a domain logon packet **************************************************************************/ @@ -278,6 +292,65 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", break; } + /* Announce change to UAS or SAM */ + + case SAM_UAS_CHANGE: { + struct sam_database_info *db_info; + char *q = buf + 2; + int i, db_count; + + /* Header */ + + q += 4; /* Low serial number */ + q += 4; /* Date/time */ + q += 4; /* Pulse */ + q += 4; /* Random */ + + /* Domain info */ + + q = skip_string(q, 1); /* PDC name */ + q = skip_string(q, 1); /* Domain name */ + q = skip_unibuf(q, PTR_DIFF(buf + len, q)); /* Unicode PDC name */ + q = skip_unibuf(q, PTR_DIFF(buf + len, q)); /* Unicode domain name */ + + /* Database info */ + + db_count = IVAL(q, 0); q += 2; + + db_info = (struct sam_database_info *) + malloc(sizeof(struct sam_database_info) * db_count); + + if (db_info == NULL) { + DEBUG(3, ("out of memory allocating info for %d databases\n", + db_count)); + return; + } + + for (i = 0; i < db_count; i++) { + db_info[i].index = IVAL(q, 0); + db_info[i].serial_lo = IVAL(q, 4); + db_info[i].serial_hi = IVAL(q, 8); + db_info[i].date_lo = IVAL(q, 12); + db_info[i].date_hi = IVAL(q, 16); + q += 20; + } + + /* Domain SID */ + + q += IVAL(q, 0) + 4; /* 4 byte length plus data */ + + q += 2; /* Alignment? */ + + /* Misc other info */ + + q += 4; /* NT version (0x1) */ + q += 2; /* LMNT token (0xff) */ + q += 2; /* LM20 token (0xff) */ + + handle_sam_uas_change(db_count, db_info); + free(db_info); + } + default: { DEBUG(3,("process_logon_packet: Unknown domain request %d\n",code)); -- cgit From 7fed75b4cbeb4110c27525d6e4824c9bf73ceb56 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Sun, 26 Aug 2001 06:24:03 +0000 Subject: Instead of checking lp_wins_server() to see if a WINS server was specified, nmbd now calls wins_srv_count(). This returns the number of WINS servers specified in the 'wins server' parameter. The return value will be zero if 'wins server' is not specified. Quick change to make room for WINS failover. (This used to be commit 0777ebc04b838b6b9036a5d0a6e0565bb0a65d9f) --- source3/nmbd/nmbd.c | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 7795958ed0..87c539371b 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -298,12 +298,15 @@ static BOOL reload_nmbd_services(BOOL test) } /* Do a sanity check for a misconfigured nmbd */ - if( lp_wins_support() && *lp_wins_server() ) - { - DEBUG(0,("ERROR: both 'wins support = true' and 'wins server = ' \ -cannot be set in the smb.conf file. nmbd aborting.\n")); + if( lp_wins_support() && wins_srv_count() ) + { + if( DEBUGLVL(0) ) + { + dbgtext( "ERROR: 'wins support = true' and 'wins server = '\n" ); + dbgtext( "are conflicting settings. nmbd aborting.\n" ); + } exit(10); - } + } return(ret); } /* reload_nmbd_services */ -- cgit From 7c09aa553da2f0b855e96396c13d854968537c30 Mon Sep 17 00:00:00 2001 From: "Christopher R. Hertel" Date: Sun, 26 Aug 2001 06:43:39 +0000 Subject: Same as nmbd.c. These now test wins_srv_count() instead of lp_wins_server to determine whether the 'wins server' parameter is set. (This used to be commit 5b975d3a9cea39e9992a9b556b8a6d9d3ec14807) --- source3/nmbd/nmbd_namelistdb.c | 2 +- source3/nmbd/nmbd_subnetdb.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 15328af33e..efac14c8c6 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -37,7 +37,7 @@ uint16 samba_nb_type = 0; /* samba's NetBIOS name type */ */ void set_samba_nb_type(void) { - if( lp_wins_support() || (*lp_wins_server()) ) + if( lp_wins_support() || wins_srv_count() ) samba_nb_type = NB_MFLAG; /* samba is a 'hybrid' node type. */ else samba_nb_type = NB_BFLAG; /* samba is broadcast-only node type. */ diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 3bad3f9568..e77a47801d 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -277,7 +277,7 @@ BOOL create_subnets(void) * server address can change. crh */ - if(*lp_wins_server()) + if( wins_srv_count() ) { struct in_addr real_wins_ip; real_wins_ip = wins_srv_ip(); -- cgit From 259d59084da6d9abada23da5dbd4e0bf25ffa548 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 28 Aug 2001 06:08:31 +0000 Subject: Send a MSG_SMB_SAM_REPL when a UAS/SAM change netlogon message is received. (This used to be commit b7cf14bf84a19da8a5b8fe9895ce78f138b5379c) --- source3/nmbd/nmbd_processlogon.c | 42 ++++++++++++++++++++++++++++++++-------- 1 file changed, 34 insertions(+), 8 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 6d38b53070..3d117b1615 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -38,11 +38,28 @@ struct sam_database_info { }; /**************************************************************************** -Handle a sam/uas change notification +Send a message to smbd to do a sam delta sync **************************************************************************/ -static void handle_sam_uas_change(int db_count, - struct sam_database_info *db_info) +static void send_repl_message(uint32 low_serial) { + TDB_CONTEXT *tdb; + + tdb = tdb_open_log(lock_path("connections.tdb"), 0, + USE_TDB_MMAP_FLAG, O_RDONLY, 0); + + if (!tdb) { + DEBUG(3, ("send_repl_message(): failed to open connections " + "database\n")); + return; + } + + DEBUG(3, ("sending replication message, serial = 0x%04x\n", + low_serial)); + + message_send_all(tdb, MSG_SMB_SAM_REPL, &low_serial, + sizeof(low_serial), False); + + tdb_close(tdb); } /**************************************************************************** @@ -292,16 +309,19 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", break; } - /* Announce change to UAS or SAM */ + /* Announce change to UAS or SAM. Send by the domain controller when a + replication event is required. */ case SAM_UAS_CHANGE: { struct sam_database_info *db_info; char *q = buf + 2; int i, db_count; + uint32 low_serial; /* Header */ - q += 4; /* Low serial number */ + low_serial = IVAL(q, 0); q += 4; /* Low serial number */ + q += 4; /* Date/time */ q += 4; /* Pulse */ q += 4; /* Random */ @@ -315,7 +335,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", /* Database info */ - db_count = IVAL(q, 0); q += 2; + db_count = SVAL(q, 0); q += 2; db_info = (struct sam_database_info *) malloc(sizeof(struct sam_database_info) * db_count); @@ -347,8 +367,14 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += 2; /* LMNT token (0xff) */ q += 2; /* LM20 token (0xff) */ - handle_sam_uas_change(db_count, db_info); - free(db_info); + free(db_info); /* Not sure whether we need to do anything + useful with these */ + + /* Send message to smbd */ + + send_repl_message(low_serial); + + break; } default: -- cgit From 75287280717bc1f1411d2084d3295fffb1ccb391 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Wed, 5 Sep 2001 18:43:55 +0000 Subject: merge profile data changes from 2.2 (This used to be commit c105859304e93297fa29f346e9cbd1af0c95048b) --- source3/nmbd/nmbd_elections.c | 9 +++-- source3/nmbd/nmbd_incomingdgrams.c | 69 ++++++++++++++++++++++++++------------ source3/nmbd/nmbd_synclists.c | 13 +++++-- 3 files changed, 65 insertions(+), 26 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 522e268ae7..0fc3ab9a89 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -177,6 +177,7 @@ void run_elections(time_t t) lastime = t; + START_PROFILE(run_elections); for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { struct work_record *work; @@ -215,6 +216,7 @@ yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name )); } } } + END_PROFILE(run_elections); } /******************************************************************* @@ -276,6 +278,7 @@ void process_election(struct subnet_record *subrec, struct packet_struct *p, cha struct work_record *work; char *workgroup_name = dgram->dest_name.name; + START_PROFILE(election); server_name[15] = 0; DEBUG(3,("process_election: Election request from %s at IP %s on subnet %s for workgroup %s.\n", @@ -287,14 +290,14 @@ void process_election(struct subnet_record *subrec, struct packet_struct *p, cha { DEBUG(0,("process_election: Cannot find workgroup %s on subnet %s.\n", workgroup_name, subrec->subnet_name )); - return; + goto done; } if (!strequal(work->work_group, global_myworkgroup)) { DEBUG(3,("process_election: ignoring election request for workgroup %s on subnet %s as this \ is not my workgroup.\n", work->work_group, subrec->subnet_name )); - return; + goto done; } if (win_election(work, version,criterion,timeup,server_name)) @@ -325,6 +328,8 @@ is not my workgroup.\n", work->work_group, subrec->subnet_name )); unbecome_local_master_browser(subrec, work, False); } } +done: + END_PROFILE(election); } /**************************************************************************** diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index b8be579779..5ee051e98b 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -110,6 +110,7 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p char *work_name; char *source_name = dgram->source_name.name; + START_PROFILE(host_announce); comment[43] = 0; DEBUG(3,("process_host_announce: from %s<%02x> IP %s to \ @@ -161,7 +162,7 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p { /* We have no record of this workgroup. Add it. */ if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL) - return; + goto done; } if((servrec = find_server_in_workgroup( work, announce_name))==NULL) @@ -193,6 +194,8 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p } } subrec->work_changed = True; +done: + END_PROFILE(host_announce); } /******************************************************************* @@ -209,6 +212,7 @@ void process_workgroup_announce(struct subnet_record *subrec, struct packet_stru struct work_record *work; char *source_name = dgram->source_name.name; + START_PROFILE(workgroup_announce); master_name[43] = 0; DEBUG(3,("process_workgroup_announce: from %s<%02x> IP %s to \ @@ -223,14 +227,14 @@ void process_workgroup_announce(struct subnet_record *subrec, struct packet_stru { DEBUG(0,("process_workgroup_announce: from IP %s should be to __MSBROWSE__<0x01> not %s\n", inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name))); - return; + goto done; } if ((work = find_workgroup_on_subnet(subrec, workgroup_announce_name))==NULL) { /* We have no record of this workgroup. Add it. */ if((work = create_workgroup_on_subnet(subrec, workgroup_announce_name, ttl))==NULL) - return; + goto done; } else { @@ -245,6 +249,8 @@ void process_workgroup_announce(struct subnet_record *subrec, struct packet_stru } subrec->work_changed = True; +done: + END_PROFILE(workgroup_announce); } /******************************************************************* @@ -263,6 +269,7 @@ void process_local_master_announce(struct subnet_record *subrec, struct packet_s struct server_record *servrec; char *source_name = dgram->source_name.name; + START_PROFILE(local_master_announce); comment[43] = 0; DEBUG(3,("process_local_master_announce: from %s<%02x> IP %s to \ @@ -278,7 +285,7 @@ void process_local_master_announce(struct subnet_record *subrec, struct packet_s DEBUG(0,("process_local_master_announce: incorrect name type for destination from IP %s \ (was %02x) should be 0x1e. Ignoring packet.\n", inet_ntoa(p->ip), dgram->dest_name.name_type)); - return; + goto done; } /* Filter servertype to remove impossible bits. */ @@ -291,11 +298,11 @@ void process_local_master_announce(struct subnet_record *subrec, struct packet_s { /* Don't bother adding if it's a local master release announce. */ if(servertype == 0) - return; + goto done; /* We have no record of this workgroup. Add it. */ if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL) - return; + goto done; } /* If we think we're the local master browser for this workgroup, @@ -322,7 +329,7 @@ a local master browser for workgroup %s and we think we are master. Forcing elec /* The actual election requests are handled in nmbd_election.c */ - return; + goto done; } /* Find the server record on this workgroup. If it doesn't exist, add it. */ @@ -361,6 +368,8 @@ a local master browser for workgroup %s and we think we are master. Forcing elec } subrec->work_changed = True; +done: + END_PROFILE(local_master_announce); } /******************************************************************* @@ -377,6 +386,7 @@ void process_master_browser_announce(struct subnet_record *subrec, struct work_record *work; struct browse_cache_record *browrec; + START_PROFILE(master_browser_announce); local_master_name[15] = 0; DEBUG(3,("process_master_browser_announce: Local master announce from %s IP %s.\n", @@ -386,21 +396,21 @@ void process_master_browser_announce(struct subnet_record *subrec, { DEBUG(0,("process_master_browser_announce: Not configured as domain \ master - ignoring master announce.\n")); - return; + goto done; } if((work = find_workgroup_on_subnet(subrec, global_myworkgroup)) == NULL) { DEBUG(0,("process_master_browser_announce: Cannot find workgroup %s on subnet %s\n", global_myworkgroup, subrec->subnet_name)); - return; + goto done; } if(!AM_DOMAIN_MASTER_BROWSER(work)) { DEBUG(0,("process_master_browser_announce: Local master announce made to us from \ %s IP %s and we are not a domain master browser.\n", local_master_name, inet_ntoa(p->ip))); - return; + goto done; } /* Add this host as a local master browser entry on the browse lists. @@ -414,6 +424,8 @@ master - ignoring master announce.\n")); } else update_browser_death_time(browrec); +done: + END_PROFILE(master_browser_announce); } /******************************************************************* @@ -435,6 +447,7 @@ void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct pstring comment; char *s = buf+9; + START_PROFILE(lm_host_announce); s = skip_string(s,1); StrnCpy(comment, s, 43); @@ -451,7 +464,7 @@ void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct originate from OS/2 Warp client. Ignoring packet.\n")); /* Could have been from a Windows machine (with its LM Announce enabled), or a Samba server. Then don't disrupt the current browse list. */ - return; + goto done; } /* Filter servertype to remove impossible bits. */ @@ -497,7 +510,7 @@ originate from OS/2 Warp client. Ignoring packet.\n")); { /* We have no record of this workgroup. Add it. */ if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL) - return; + goto done; } if((servrec = find_server_in_workgroup( work, announce_name))==NULL) @@ -531,6 +544,8 @@ originate from OS/2 Warp client. Ignoring packet.\n")); subrec->work_changed = True; found_lm_clients = True; +done: + END_PROFILE(lm_host_announce); } /**************************************************************************** @@ -643,6 +658,7 @@ void process_get_backup_list_request(struct subnet_record *subrec, char *workgroup_name = dgram->dest_name.name; struct subnet_record *search_subrec = subrec; + START_PROFILE(get_backup_list); DEBUG(3,("process_get_backup_list_request: request from %s IP %s to %s.\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name))); @@ -655,14 +671,14 @@ void process_get_backup_list_request(struct subnet_record *subrec, { DEBUG(7,("process_get_backup_list_request: Ignoring announce request for workgroup %s.\n", workgroup_name)); - return; + goto done; } if((work = find_workgroup_on_subnet(search_subrec, workgroup_name)) == NULL) { DEBUG(0,("process_get_backup_list_request: Cannot find workgroup %s on \ subnet %s.\n", workgroup_name, search_subrec->subnet_name)); - return; + goto done; } /* @@ -680,7 +696,7 @@ subnet %s.\n", workgroup_name, search_subrec->subnet_name)); { DEBUG(0,("process_get_backup_list_request: domain list requested for workgroup %s \ and I am not a domain master browser.\n", workgroup_name)); - return; + goto done; } search_subrec = unicast_subnet; @@ -694,18 +710,20 @@ and I am not a domain master browser.\n", workgroup_name)); { DEBUG(0,("process_get_backup_list_request: domain list requested for workgroup %s \ and I am not a local master browser.\n", workgroup_name)); - return; + goto done; } } else { DEBUG(0,("process_get_backup_list_request: Invalid name type %x - should be 0x1b or 0x1d.\n", name_type)); - return; + goto done; } send_backup_list_response(subrec, work, &dgram->source_name, max_number_requested, token, p->ip, p->port); +done: + END_PROFILE(get_backup_list); } /******************************************************************* @@ -725,6 +743,7 @@ void process_reset_browser(struct subnet_record *subrec, int state = CVAL(buf,0); struct subnet_record *sr; + START_PROFILE(reset_browser); DEBUG(1,("process_reset_browser: received diagnostic browser reset \ request from %s IP %s state=0x%X\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), state)); @@ -761,6 +780,8 @@ request from %s IP %s state=0x%X\n", /* Request to stop browsing altogether. */ if (state & 0x4) DEBUG(1,("process_reset_browser: ignoring request to stop being a browser.\n")); +done: + END_PROFILE(reset_browser); } /******************************************************************* @@ -777,6 +798,7 @@ void process_announce_request(struct subnet_record *subrec, struct packet_struct struct work_record *work; char *workgroup_name = dgram->dest_name.name; + START_PROFILE(announce_request); DEBUG(3,("process_announce_request: Announce request from %s IP %s to %s.\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name))); @@ -786,17 +808,19 @@ void process_announce_request(struct subnet_record *subrec, struct packet_struct { DEBUG(7,("process_announce_request: Ignoring announce request for workgroup %s.\n", workgroup_name)); - return; + goto done; } if((work = find_workgroup_on_subnet(subrec, workgroup_name)) == NULL) { DEBUG(0,("process_announce_request: Unable to find workgroup %s on subnet !\n", workgroup_name)); - return; + goto done; } work->needannounce = True; +done: + END_PROFILE(lm_host_announce); } /******************************************************************* @@ -813,6 +837,7 @@ void process_lm_announce_request(struct subnet_record *subrec, struct packet_str struct dgram_packet *dgram = &p->packet.dgram; char *workgroup_name = dgram->dest_name.name; + START_PROFILE(lm_announce_request); DEBUG(3,("process_lm_announce_request: Announce request from %s IP %s to %s.\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name))); @@ -822,15 +847,17 @@ void process_lm_announce_request(struct subnet_record *subrec, struct packet_str { DEBUG(7,("process_lm_announce_request: Ignoring announce request for workgroup %s.\n", workgroup_name)); - return; + goto done; } if(find_workgroup_on_subnet(subrec, workgroup_name) == NULL) { DEBUG(0,("process_announce_request: Unable to find workgroup %s on subnet !\n", workgroup_name)); - return; + goto done; } found_lm_clients = True; +done: + END_PROFILE(lm_host_announce); } diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 29462685b0..dea68d4c27 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -133,14 +133,17 @@ void sync_browse_lists(struct work_record *work, struct sync_record *s; static int counter; + START_PROFILE(sync_browse_lists); /* Check we're not trying to sync with ourselves. This can happen if we are a domain *and* a local master browser. */ if (ismyip(ip)) { +done: + END_PROFILE(sync_browse_lists); return; } s = (struct sync_record *)malloc(sizeof(*s)); - if (!s) return; + if (!s) goto done; ZERO_STRUCTP(s); @@ -155,7 +158,7 @@ void sync_browse_lists(struct work_record *work, DLIST_ADD(syncs, s); /* the parent forks and returns, leaving the child to do the - actual sync */ + actual sync and call END_PROFILE*/ CatchChild(); if ((s->pid = sys_fork())) return; @@ -165,12 +168,16 @@ void sync_browse_lists(struct work_record *work, work->work_group, name, inet_ntoa(ip))); fp = sys_fopen(s->fname,"w"); - if (!fp) _exit(1); + if (!fp) { + END_PROFILE(sync_browse_lists); + _exit(1); + } sync_child(name, nm_type, work->work_group, ip, local, servers, s->fname); fclose(fp); + END_PROFILE(sync_browse_lists); _exit(0); } -- cgit From 9a9ac2739bbdc993ecdfa78298bdd9c059328378 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 6 Sep 2001 22:08:19 +0000 Subject: got rid of USE_TDB_MMAP_FLAG as its not needed any more (This used to be commit c26e0d3f27a05ecc8bd2390f9aab7f9451524e47) --- source3/nmbd/nmbd_incomingdgrams.c | 2 +- source3/nmbd/nmbd_processlogon.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 5ee051e98b..eaafd63f1a 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -780,7 +780,7 @@ request from %s IP %s state=0x%X\n", /* Request to stop browsing altogether. */ if (state & 0x4) DEBUG(1,("process_reset_browser: ignoring request to stop being a browser.\n")); -done: + END_PROFILE(reset_browser); } diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 3d117b1615..4f98a23584 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -45,7 +45,7 @@ static void send_repl_message(uint32 low_serial) TDB_CONTEXT *tdb; tdb = tdb_open_log(lock_path("connections.tdb"), 0, - USE_TDB_MMAP_FLAG, O_RDONLY, 0); + TDB_DEFAULT, O_RDONLY, 0); if (!tdb) { DEBUG(3, ("send_repl_message(): failed to open connections " -- cgit From b30e75692d68233448b3ad3d7ddd4b4ac423d3ab Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Sep 2001 11:08:57 +0000 Subject: replaced stdio in many parts of samba with a XFILE. XFILE is a cut-down replacemnt of stdio that doesn't suffer from the 8-bit filedescriptor limit that we hit with nasty consequences on some systems I would eventually prefer us to have a configure test to see if we need to replace stdio, but for now this code needs to be tested widely so I'm enabling it by default. (This used to be commit 1af8bf34f1caa3e7ec312d8109c07d32a945a448) --- source3/nmbd/nmbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 87c539371b..141d055281 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -666,7 +666,7 @@ static void usage(char *pname) int main(int argc,char *argv[]) { int opt; - extern FILE *dbf; + extern XFILE *dbf; extern char *optarg; extern BOOL append_log; @@ -876,7 +876,7 @@ static void usage(char *pname) process(); if (dbf) - fclose(dbf); + x_fclose(dbf); return(0); } /* main */ -- cgit From b12a4dd9b655485420d5c67dd143d8f49ac28a40 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Sep 2001 12:14:18 +0000 Subject: declare dbf in one spot (This used to be commit f41c3bb80f1e498a9d27f6e236b0ff3a742764c9) --- source3/nmbd/nmbd.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 141d055281..d8d0aa4626 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -666,7 +666,6 @@ static void usage(char *pname) int main(int argc,char *argv[]) { int opt; - extern XFILE *dbf; extern char *optarg; extern BOOL append_log; -- cgit From 79139fe8d882c39620b0d52ef081f639d1294917 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Sep 2001 12:46:42 +0000 Subject: convert more code to use XFILE (This used to be commit fe6679dffba9a92bb35933ad52172c9be0e9ef90) --- source3/nmbd/nmbd_lmhosts.c | 2 +- source3/nmbd/nmbd_synclists.c | 8 ++++---- source3/nmbd/nmbd_winsserver.c | 10 +++++----- 3 files changed, 10 insertions(+), 10 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_lmhosts.c b/source3/nmbd/nmbd_lmhosts.c index 158988813b..04ab280784 100644 --- a/source3/nmbd/nmbd_lmhosts.c +++ b/source3/nmbd/nmbd_lmhosts.c @@ -36,7 +36,7 @@ void load_lmhosts_file(char *fname) pstring name; int name_type; struct in_addr ipaddr; - FILE *fp = startlmhosts( fname ); + XFILE *fp = startlmhosts( fname ); if (!fp) { DEBUG(2,("load_lmhosts_file: Can't open lmhosts file %s. Error was %s\n", diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index dea68d4c27..51c9257f5a 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -241,7 +241,7 @@ read the completed sync info **********************************************************************/ static void complete_sync(struct sync_record *s) { - FILE *f; + XFILE *f; fstring server, type_str; unsigned type; pstring comment; @@ -249,11 +249,11 @@ static void complete_sync(struct sync_record *s) char *ptr; int count=0; - f = sys_fopen(s->fname,"r"); + f = x_fopen(s->fname,O_RDONLY, 0); if (!f) return; - while (!feof(f)) { + while (!x_feof(f)) { if (!fgets_slash(line,sizeof(pstring),f)) continue; @@ -272,7 +272,7 @@ static void complete_sync(struct sync_record *s) count++; } - fclose(f); + x_fclose(f); unlink(s->fname); diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 0ba1aef057..03d475133e 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -173,7 +173,7 @@ Load or create the WINS database. BOOL initialise_wins(void) { time_t time_now = time(NULL); - FILE *fp; + XFILE *fp; pstring line; if(!lp_we_are_a_wins_server()) @@ -181,14 +181,14 @@ BOOL initialise_wins(void) add_samba_names_to_subnet(wins_server_subnet); - if((fp = sys_fopen(lock_path(WINS_LIST),"r")) == NULL) + if((fp = x_fopen(lock_path(WINS_LIST),O_RDONLY, 0)) == NULL) { DEBUG(2,("initialise_wins: Can't open wins database file %s. Error was %s\n", WINS_LIST, strerror(errno) )); return True; } - while (!feof(fp)) + while (!x_feof(fp)) { pstring name_str, ip_str, ttl_str, nb_flags_str; unsigned int num_ips; @@ -219,7 +219,7 @@ BOOL initialise_wins(void) version != WINS_VERSION || hash != wins_hash()) { DEBUG(0,("Discarding invalid wins.dat file [%s]\n",line)); - fclose(fp); + x_fclose(fp); return True; } continue; @@ -342,7 +342,7 @@ BOOL initialise_wins(void) free((char *)ip_list); } - fclose(fp); + x_fclose(fp); return True; } -- cgit From 4d65bc094941f1214efdf03c9d363715aa35a656 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 10 Sep 2001 13:09:54 +0000 Subject: convert more code to use XFILE (This used to be commit fd24265c06f6d2b636c1863941a33029dd9f3828) --- source3/nmbd/nmbd_namelistdb.c | 28 ++++++++++++++-------------- source3/nmbd/nmbd_serverlistdb.c | 40 ++++++++++++++++++++-------------------- source3/nmbd/nmbd_synclists.c | 8 ++++---- source3/nmbd/nmbd_winsserver.c | 15 +++++++-------- 4 files changed, 45 insertions(+), 46 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index efac14c8c6..281197df65 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -528,19 +528,19 @@ void add_samba_names_to_subnet( struct subnet_record *subrec ) into a file. Initiated by SIGHUP - used to debug the state of the namelists. **************************************************************************/ -static void dump_subnet_namelist( struct subnet_record *subrec, FILE *fp) +static void dump_subnet_namelist( struct subnet_record *subrec, XFILE *fp) { struct name_record *namerec; char *src_type; struct tm *tm; int i; - fprintf(fp, "Subnet %s\n----------------------\n", subrec->subnet_name); + x_fprintf(fp, "Subnet %s\n----------------------\n", subrec->subnet_name); for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); namerec; namerec = (struct name_record *)ubi_trNext( namerec ) ) { - fprintf(fp,"\tName = %s\t", nmb_namestr(&namerec->name)); + x_fprintf(fp,"\tName = %s\t", nmb_namestr(&namerec->name)); switch(namerec->data.source) { case LMHOSTS_NAME: @@ -568,29 +568,29 @@ static void dump_subnet_namelist( struct subnet_record *subrec, FILE *fp) src_type = "unknown!"; break; } - fprintf(fp,"Source = %s\nb_flags = %x\t", src_type, namerec->data.nb_flags); + x_fprintf(fp,"Source = %s\nb_flags = %x\t", src_type, namerec->data.nb_flags); if(namerec->data.death_time != PERMANENT_TTL) { tm = LocalTime(&namerec->data.death_time); - fprintf(fp, "death_time = %s\t", asctime(tm)); + x_fprintf(fp, "death_time = %s\t", asctime(tm)); } else - fprintf(fp, "death_time = PERMANENT\t"); + x_fprintf(fp, "death_time = PERMANENT\t"); if(namerec->data.refresh_time != PERMANENT_TTL) { tm = LocalTime(&namerec->data.refresh_time); - fprintf(fp, "refresh_time = %s\n", asctime(tm)); + x_fprintf(fp, "refresh_time = %s\n", asctime(tm)); } else - fprintf(fp, "refresh_time = PERMANENT\n"); + x_fprintf(fp, "refresh_time = PERMANENT\n"); - fprintf(fp, "\t\tnumber of IPS = %d", namerec->data.num_ips); + x_fprintf(fp, "\t\tnumber of IPS = %d", namerec->data.num_ips); for(i = 0; i < namerec->data.num_ips; i++) - fprintf(fp, "\t%s", inet_ntoa(namerec->data.ip[i])); + x_fprintf(fp, "\t%s", inet_ntoa(namerec->data.ip[i])); - fprintf(fp, "\n\n"); + x_fprintf(fp, "\n\n"); } } @@ -601,10 +601,10 @@ static void dump_subnet_namelist( struct subnet_record *subrec, FILE *fp) void dump_all_namelists(void) { - FILE *fp; + XFILE *fp; struct subnet_record *subrec; - fp = sys_fopen(lock_path("namelist.debug"),"w"); + fp = x_fopen(lock_path("namelist.debug"),O_WRONLY|O_CREAT|O_TRUNC, 0644); if (!fp) { @@ -626,5 +626,5 @@ void dump_all_namelists(void) if( wins_server_subnet != NULL ) dump_subnet_namelist( wins_server_subnet, fp ); - fclose( fp ); + x_fclose( fp ); } diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index 41009bc68f..711ddb2490 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -307,7 +307,7 @@ void write_browse_list(time_t t, BOOL force_write) uint32 stype; fstring tmp; int i; - FILE *fp; + XFILE *fp; BOOL list_changed = force_write; static time_t lasttime = 0; @@ -345,7 +345,7 @@ void write_browse_list(time_t t, BOOL force_write) pstrcpy(fnamenew,fname); pstrcat(fnamenew,"."); - fp = sys_fopen(fnamenew,"w"); + fp = x_fopen(fnamenew,O_WRONLY|O_CREAT|O_TRUNC, 0644); if (!fp) { @@ -363,16 +363,16 @@ void write_browse_list(time_t t, BOOL force_write) { DEBUG(0,("write_browse_list: Fatal error - cannot find my workgroup %s\n", global_myworkgroup)); - fclose(fp); + x_fclose(fp); return; } slprintf(tmp,sizeof(tmp)-1, "\"%s\"", work->work_group); - fprintf(fp, "%-25s ", tmp); - fprintf(fp, "%08x ", SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT|SV_TYPE_LOCAL_LIST_ONLY); + x_fprintf(fp, "%-25s ", tmp); + x_fprintf(fp, "%08x ", SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT|SV_TYPE_LOCAL_LIST_ONLY); slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", work->local_master_browser_name); - fprintf(fp, "%-30s", tmp); - fprintf(fp, "\"%s\"\n", work->work_group); + x_fprintf(fp, "%-30s", tmp); + x_fprintf(fp, "\"%s\"\n", work->work_group); /* * We need to do something special for our own names. @@ -397,12 +397,12 @@ void write_browse_list(time_t t, BOOL force_write) /* Output server details, plus what workgroup they're in. */ slprintf(tmp, sizeof(tmp)-1, "\"%s\"", my_netbios_names[i]); - fprintf(fp, "%-25s ", tmp); - fprintf(fp, "%08x ", stype); + x_fprintf(fp, "%-25s ", tmp); + x_fprintf(fp, "%08x ", stype); slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH)); - fprintf(fp, "%-30s", tmp); - fprintf(fp, "\"%s\"\n", global_myworkgroup); + x_fprintf(fp, "%-30s", tmp); + x_fprintf(fp, "\"%s\"\n", global_myworkgroup); } for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) @@ -417,12 +417,12 @@ void write_browse_list(time_t t, BOOL force_write) if(wg_type) { slprintf(tmp, sizeof(tmp)-1, "\"%s\"", work->work_group); - fprintf(fp, "%-25s ", tmp); + x_fprintf(fp, "%-25s ", tmp); - fprintf(fp, "%08x ", wg_type); + x_fprintf(fp, "%08x ", wg_type); slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", work->local_master_browser_name); - fprintf(fp, "%-30s", tmp); - fprintf(fp, "\"%s\"\n", work->work_group); + x_fprintf(fp, "%-30s", tmp); + x_fprintf(fp, "\"%s\"\n", work->work_group); } /* Now write out any server records a workgroup may have. */ @@ -441,17 +441,17 @@ void write_browse_list(time_t t, BOOL force_write) { /* Output server details, plus what workgroup they're in. */ slprintf(tmp, sizeof(tmp)-1, "\"%s\"", servrec->serv.name); - fprintf(fp, "%-25s ", tmp); - fprintf(fp, "%08x ", serv_type); + x_fprintf(fp, "%-25s ", tmp); + x_fprintf(fp, "%08x ", serv_type); slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", servrec->serv.comment); - fprintf(fp, "%-30s", tmp); - fprintf(fp, "\"%s\"\n", work->work_group); + x_fprintf(fp, "%-30s", tmp); + x_fprintf(fp, "\"%s\"\n", work->work_group); } } } } - fclose(fp); + x_fclose(fp); unlink(fname); chmod(fnamenew,0644); rename(fnamenew,fname); diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 51c9257f5a..e3ea67f135 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -45,7 +45,7 @@ struct sync_record { /* a linked list of current sync connections */ static struct sync_record *syncs; -static FILE *fp; +static XFILE *fp; /******************************************************************* This is the NetServerEnum callback. @@ -54,7 +54,7 @@ static FILE *fp; static void callback(const char *sname, uint32 stype, const char *comment, void *state) { - fprintf(fp,"\"%s\" %08X \"%s\"\n", sname, stype, comment); + x_fprintf(fp,"\"%s\" %08X \"%s\"\n", sname, stype, comment); } /******************************************************************* @@ -167,7 +167,7 @@ done: DEBUG(2,("Initiating browse sync for %s to %s(%s)\n", work->work_group, name, inet_ntoa(ip))); - fp = sys_fopen(s->fname,"w"); + fp = x_fopen(s->fname,O_WRONLY|O_CREAT|O_TRUNC, 0644); if (!fp) { END_PROFILE(sync_browse_lists); _exit(1); @@ -176,7 +176,7 @@ done: sync_child(name, nm_type, work->work_group, ip, local, servers, s->fname); - fclose(fp); + x_fclose(fp); END_PROFILE(sync_browse_lists); _exit(0); } diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 03d475133e..10eaf91e8a 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1582,8 +1582,7 @@ void wins_write_database(BOOL background) { struct name_record *namerec; pstring fname, fnamenew; - - FILE *fp; + XFILE *fp; if(!lp_we_are_a_wins_server()) return; @@ -1601,7 +1600,7 @@ void wins_write_database(BOOL background) all_string_sub(fname,"//", "/", 0); slprintf(fnamenew,sizeof(fnamenew)-1,"%s.%u", fname, (unsigned int)sys_getpid()); - if((fp = sys_fopen(fnamenew,"w")) == NULL) + if((fp = x_fopen(fnamenew,O_WRONLY|O_CREAT|O_TRUNC, 0644)) == NULL) { DEBUG(0,("wins_write_database: Can't open %s. Error was %s\n", fnamenew, strerror(errno))); if (background) { @@ -1612,7 +1611,7 @@ void wins_write_database(BOOL background) DEBUG(4,("wins_write_database: Dump of WINS name list.\n")); - fprintf(fp,"VERSION %d %u\n", WINS_VERSION, wins_hash()); + x_fprintf(fp,"VERSION %d %u\n", WINS_VERSION, wins_hash()); for( namerec = (struct name_record *)ubi_trFirst( wins_server_subnet->namelist ); @@ -1644,17 +1643,17 @@ void wins_write_database(BOOL background) if( namerec->data.source == REGISTER_NAME ) { - fprintf(fp, "\"%s#%02x\" %d ", + x_fprintf(fp, "\"%s#%02x\" %d ", namerec->name.name,namerec->name.name_type, /* Ignore scope. */ (int)namerec->data.death_time); for (i = 0; i < namerec->data.num_ips; i++) - fprintf( fp, "%s ", inet_ntoa( namerec->data.ip[i] ) ); - fprintf( fp, "%2xR\n", namerec->data.nb_flags ); + x_fprintf( fp, "%s ", inet_ntoa( namerec->data.ip[i] ) ); + x_fprintf( fp, "%2xR\n", namerec->data.nb_flags ); } } - fclose(fp); + x_fclose(fp); chmod(fnamenew,0644); unlink(fname); rename(fnamenew,fname); -- cgit From 1f312492ecf8b3215bddf5c2f2d9fb2cbe2bf098 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Mon, 17 Sep 2001 04:35:51 +0000 Subject: move to SAFE_FREE() (This used to be commit 1446a1562b1c618c023b056f476e26da7ee3d532) --- source3/nmbd/nmbd.c | 2 +- source3/nmbd/nmbd_browserdb.c | 2 +- source3/nmbd/nmbd_incomingrequests.c | 12 ++++++------ source3/nmbd/nmbd_namelistdb.c | 16 +++++++--------- source3/nmbd/nmbd_nameregister.c | 4 ++-- source3/nmbd/nmbd_packets.c | 4 ++-- source3/nmbd/nmbd_processlogon.c | 2 +- source3/nmbd/nmbd_responserecordsdb.c | 8 ++++---- source3/nmbd/nmbd_serverlistdb.c | 4 ++-- source3/nmbd/nmbd_subnetdb.c | 2 +- source3/nmbd/nmbd_synclists.c | 2 +- source3/nmbd/nmbd_winsproxy.c | 6 +++--- source3/nmbd/nmbd_winsserver.c | 10 +++++----- source3/nmbd/nmbd_workgroupdb.c | 2 +- 14 files changed, 37 insertions(+), 39 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index d8d0aa4626..6fead637eb 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -614,7 +614,7 @@ static BOOL init_structs(void) if (nodup) my_netbios_names[namecount++] = nbname; else - free(nbname); + SAFE_FREE(nbname); ptr++; } diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c index 10d22431e9..9523152840 100644 --- a/source3/nmbd/nmbd_browserdb.c +++ b/source3/nmbd/nmbd_browserdb.c @@ -56,7 +56,7 @@ ubi_dlNewList( lmb_browserlist ); */ static void remove_lmb_browser_entry( struct browse_cache_record *browc ) { - free( (char *)ubi_dlRemThis( lmb_browserlist, browc ) ); + safe_free( ubi_dlRemThis( lmb_browserlist, browc ) ); } /* remove_lmb_browser_entry */ /* ************************************************************************** ** diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index c59c045bad..b390755be5 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -581,8 +581,8 @@ on the same subnet (%s) as the requestor. Not replying.\n", if (!success && bcast) { - if((prdata != rdata) && (prdata != NULL)) - free(prdata); + if(prdata != rdata) + SAFE_FREE(prdata); return; /* Never reply with a negative response to broadcasts. */ } @@ -594,8 +594,8 @@ on the same subnet (%s) as the requestor. Not replying.\n", if(!success && !bcast && nmb->header.nm_flags.recursion_desired) { - if((prdata != rdata) && (prdata != NULL)) - free(prdata); + if(prdata != rdata) + SAFE_FREE(prdata); return; } @@ -620,6 +620,6 @@ on the same subnet (%s) as the requestor. Not replying.\n", prdata, /* data to send. */ reply_data_len); /* data length. */ - if((prdata != rdata) && (prdata != NULL)) - free(prdata); + if(prdata != rdata) + SAFE_FREE(prdata); } diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 281197df65..fe2c0c0f21 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -78,9 +78,8 @@ static void update_name_in_namelist( struct subnet_record *subrec, (void)ubi_trInsert( subrec->namelist, namerec, &(namerec->name), &oldrec ); if( oldrec ) { - if( oldrec->data.ip ) - free( oldrec->data.ip ); - free( oldrec ); + SAFE_FREE( oldrec->data.ip ); + SAFE_FREE( oldrec ); } } /* update_name_in_namelist */ @@ -93,11 +92,10 @@ void remove_name_from_namelist( struct subnet_record *subrec, { (void)ubi_trRemove( subrec->namelist, namerec ); - if(namerec->data.ip != NULL) - free((char *)namerec->data.ip); + SAFE_FREE(namerec->data.ip); ZERO_STRUCTP(namerec); - free((char *)namerec); + SAFE_FREE(namerec); subrec->namelist_changed = True; } /* remove_name_from_namelist */ @@ -206,7 +204,7 @@ struct name_record *add_name_to_subnet( struct subnet_record *subrec, DEBUG( 0, ( "add_name_to_subnet: malloc fail when creating ip_flgs.\n" ) ); ZERO_STRUCTP(namerec); - free( (char *)namerec ); + SAFE_FREE(namerec); return NULL; } @@ -353,7 +351,7 @@ void add_ip_to_name_record( struct name_record *namerec, struct in_addr new_ip ) namerec->data.num_ips * sizeof(struct in_addr) ); new_list[namerec->data.num_ips] = new_ip; - free((char *)namerec->data.ip); + SAFE_FREE(namerec->data.ip); namerec->data.ip = new_list; namerec->data.num_ips += 1; @@ -520,7 +518,7 @@ void add_samba_names_to_subnet( struct subnet_record *subrec ) PERMANENT_NAME, num_ips, iplist); if(iplist != &subrec->myip) - free((char *)iplist); + SAFE_FREE(iplist); } /**************************************************************************** diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index 6d4d66cbef..6b7bb6a73a 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -310,12 +310,12 @@ static BOOL multihomed_register_name( struct nmb_name *nmbname, uint16 nb_flags, DEBUG(0,("multihomed_register_name: Failed to send packet trying to \ register name %s IP %s\n", nmb_namestr(nmbname), inet_ntoa(ip_list[i]) )); - free((char *)ip_list); + SAFE_FREE(ip_list); return True; } } - free((char *)ip_list); + SAFE_FREE(ip_list); return False; } diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 00059c1775..ab4b2c5e89 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1758,8 +1758,8 @@ only use %d.\n", (count*2) + 2, FD_SETSIZE)); *listen_number = (count*2) + 2; - if (*ppset) free(*ppset); - if (*psock_array) free(*psock_array); + SAFE_FREE(*ppset); + SAFE_FREE(*psock_array); *ppset = pset; *psock_array = sock_array; diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 4f98a23584..9923d352dc 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -367,7 +367,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += 2; /* LMNT token (0xff) */ q += 2; /* LM20 token (0xff) */ - free(db_info); /* Not sure whether we need to do anything + SAFE_FREE(db_info); /* Not sure whether we need to do anything useful with these */ /* Send message to smbd */ diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index 1b6e1ca16d..b4376d6405 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -83,7 +83,7 @@ void remove_response_record(struct subnet_record *subrec, (*rrec->userdata->free_fn)(rrec->userdata); } else { ZERO_STRUCTP(rrec->userdata); - free((char *)rrec->userdata); + SAFE_FREE(rrec->userdata); } } @@ -92,7 +92,7 @@ void remove_response_record(struct subnet_record *subrec, free_packet(rrec->packet); ZERO_STRUCTP(rrec); - free((char *)rrec); + SAFE_FREE(rrec); num_response_packets--; /* count of total number of packets still around */ } @@ -138,7 +138,7 @@ struct response_record *make_response_record( struct subnet_record *subrec, { DEBUG(0,("make_response_queue_record: copy fail for userdata.\n")); ZERO_STRUCTP(rrec); - free(rrec); + SAFE_FREE(rrec); return NULL; } } @@ -150,7 +150,7 @@ struct response_record *make_response_record( struct subnet_record *subrec, { DEBUG(0,("make_response_queue_record: malloc fail for userdata.\n")); ZERO_STRUCTP(rrec); - free(rrec); + SAFE_FREE(rrec); return NULL; } rrec->userdata->copy_fn = userdata->copy_fn; diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index 711ddb2490..cbc48d2313 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -57,7 +57,7 @@ void remove_all_servers(struct work_record *work) work->serverlist = servrec->next; ZERO_STRUCTP(servrec); - free((char *)servrec); + SAFE_FREE(servrec); } @@ -122,7 +122,7 @@ void remove_server_from_workgroup(struct work_record *work, struct server_record work->serverlist = servrec->next; ZERO_STRUCTP(servrec); - free((char *)servrec); + SAFE_FREE(servrec); work->subnet->work_changed = True; } diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index e77a47801d..996952451d 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -188,7 +188,7 @@ static struct subnet_record *make_subnet(char *name, enum subnet_type type, close(nmb_sock); close(dgram_sock); ZERO_STRUCTP(subrec); - free((char *)subrec); + SAFE_FREE(subrec); return(NULL); } diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index e3ea67f135..7ba39f0cd4 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -294,7 +294,7 @@ void sync_check_completion(void) complete_sync(s); DLIST_REMOVE(syncs, s); ZERO_STRUCTP(s); - free(s); + SAFE_FREE(s); } } } diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index 24ba192cdb..d3118e82e1 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -83,7 +83,7 @@ returned for name %s.\n", nmb_namestr(nmbname) )); WINS_PROXY_NAME, num_ips, iplist ); if(iplist != &ip) - free((char *)iplist); + SAFE_FREE(iplist); /* * Check that none of the IP addresses we are returning is on the @@ -161,7 +161,7 @@ static struct userdata_struct *wins_proxy_userdata_copy_fn(struct userdata_struc /* Do a deep copy of the packet. */ if((copy_of_p = copy_packet(p)) == NULL) { - free((char *)new_userdata); + SAFE_FREE(new_userdata); return NULL; } @@ -192,7 +192,7 @@ static void wins_proxy_userdata_free_fn(struct userdata_struct *userdata) free_packet(p); ZERO_STRUCTP(userdata); - free((char *)userdata); + SAFE_FREE(userdata); } /**************************************************************************** diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 10eaf91e8a..621a23b9e2 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -300,7 +300,7 @@ BOOL initialise_wins(void) if(nb_flags_str[strlen(nb_flags_str)-1] == 'S') { DEBUG(5,("initialise_wins: Ignoring SELF name %s\n", line)); - free((char *)ip_list); + SAFE_FREE(ip_list); continue; } @@ -339,7 +339,7 @@ BOOL initialise_wins(void) name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); } - free((char *)ip_list); + SAFE_FREE(ip_list); } x_fclose(fp); @@ -1281,7 +1281,7 @@ static void process_wins_dmb_query_request(struct subnet_record *subrec, prdata, /* data to send. */ num_ips*6); /* data length. */ - free(prdata); + SAFE_FREE(prdata); } /**************************************************************************** @@ -1338,8 +1338,8 @@ void send_wins_name_query_response(int rcode, struct packet_struct *p, prdata, /* data to send. */ reply_data_len); /* data length. */ - if((prdata != rdata) && (prdata != NULL)) - free(prdata); + if(prdata != rdata) + SAFE_FREE(prdata); } /*********************************************************************** diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 01477c8113..6bb156b41f 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -142,7 +142,7 @@ static struct work_record *remove_workgroup_from_subnet(struct subnet_record *su subrec->workgrouplist = work->next; ZERO_STRUCTP(work); - free((char *)work); + SAFE_FREE(work); } subrec->work_changed = True; -- cgit From 29d3318437f3137d61e955d5ee5d8f70c115e3d2 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 26 Sep 2001 16:47:02 +0000 Subject: From 2.2. Volker (This used to be commit 50ea73426f58070859bbbe769c8353a11ff33dc9) --- source3/nmbd/nmbd_processlogon.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 9923d352dc..e8d580adbb 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -144,6 +144,12 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); char *q = buf + 2; char *machine = q; + if (!lp_domain_master()) + { + /* We're not Primary Domain Controller -- ignore this */ + goto done; + } + getdc = skip_string(machine,1); q = skip_string(getdc,1); q = ALIGN2(q, buf); -- cgit From f7fb26f6750d0daf188ec25dded1cfa0f95d6a54 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 27 Sep 2001 16:28:50 +0000 Subject: How often did I read the CVS commit message "Always compile before commit" :-(( Volker (This used to be commit 69a3277fc5be35536168ba195968b8b76f0b5954) --- source3/nmbd/nmbd_processlogon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index e8d580adbb..811f963bad 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -147,7 +147,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); if (!lp_domain_master()) { /* We're not Primary Domain Controller -- ignore this */ - goto done; + return; } getdc = skip_string(machine,1); -- cgit From dc1fc3ee8ec2199bc73bb5d7ec711c6800f61d65 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 2 Oct 2001 04:29:50 +0000 Subject: Removed 'extern int DEBUGLEVEL' as it is now in the smb.h header. (This used to be commit 2d0922b0eabfdc0aaf1d0797482fef47ed7fde8e) --- source3/nmbd/asyncdns.c | 2 -- source3/nmbd/nmbd.c | 3 --- source3/nmbd/nmbd_become_dmb.c | 2 -- source3/nmbd/nmbd_become_lmb.c | 1 - source3/nmbd/nmbd_browserdb.c | 2 -- source3/nmbd/nmbd_browsesync.c | 1 - source3/nmbd/nmbd_elections.c | 2 -- source3/nmbd/nmbd_incomingdgrams.c | 2 -- source3/nmbd/nmbd_incomingrequests.c | 1 - source3/nmbd/nmbd_lmhosts.c | 2 -- source3/nmbd/nmbd_logonnames.c | 2 -- source3/nmbd/nmbd_mynames.c | 2 -- source3/nmbd/nmbd_namelistdb.c | 2 -- source3/nmbd/nmbd_namequery.c | 1 - source3/nmbd/nmbd_nameregister.c | 2 -- source3/nmbd/nmbd_namerelease.c | 2 -- source3/nmbd/nmbd_nodestatus.c | 2 -- source3/nmbd/nmbd_packets.c | 2 -- source3/nmbd/nmbd_processlogon.c | 2 -- source3/nmbd/nmbd_responserecordsdb.c | 2 -- source3/nmbd/nmbd_sendannounce.c | 1 - source3/nmbd/nmbd_serverlistdb.c | 2 -- source3/nmbd/nmbd_subnetdb.c | 2 -- source3/nmbd/nmbd_synclists.c | 2 -- source3/nmbd/nmbd_winsproxy.c | 2 -- source3/nmbd/nmbd_winsserver.c | 2 -- source3/nmbd/nmbd_workgroupdb.c | 2 -- 27 files changed, 50 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 1fe04a39e3..5ae2eb202d 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -20,8 +20,6 @@ #include "includes.h" -extern int DEBUGLEVEL; - /*************************************************************************** Add a DNS result to the name cache. ****************************************************************************/ diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 6fead637eb..3c93f306b8 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -27,8 +27,6 @@ #include "includes.h" -extern int DEBUGLEVEL; - extern pstring debugf; pstring servicesf = CONFIGFILE; @@ -878,4 +876,3 @@ static void usage(char *pname) x_fclose(dbf); return(0); } /* main */ - diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index 089aa8f16a..8a9fbaedd5 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -24,8 +24,6 @@ #include "includes.h" -extern int DEBUGLEVEL; - extern pstring global_myname; extern fstring global_myworkgroup; extern char **my_netbios_names; diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index 31c67ae7f3..52955d9bfc 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -24,7 +24,6 @@ #include "includes.h" -extern int DEBUGLEVEL; extern pstring global_myname; extern uint16 samba_nb_type; /* Samba's NetBIOS name type. */ diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c index 9523152840..cbf871a700 100644 --- a/source3/nmbd/nmbd_browserdb.c +++ b/source3/nmbd/nmbd_browserdb.c @@ -30,8 +30,6 @@ #include "includes.h" -extern int DEBUGLEVEL; - /* -------------------------------------------------------------------------- ** * Variables... * diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 23ca0a398f..6a8edd0eaf 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -25,7 +25,6 @@ #include "includes.h" #include "smb.h" -extern int DEBUGLEVEL; extern struct in_addr ipzero; extern pstring global_myname; extern fstring global_myworkgroup; diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 0fc3ab9a89..6db595269f 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -24,8 +24,6 @@ #include "includes.h" -extern int DEBUGLEVEL; - extern pstring global_myname; extern fstring global_myworkgroup; diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index eaafd63f1a..d10e6ec0b0 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -24,8 +24,6 @@ #include "includes.h" -extern int DEBUGLEVEL; - extern pstring global_myname; extern fstring global_myworkgroup; extern BOOL found_lm_clients; diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index b390755be5..81e6bb9629 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -28,7 +28,6 @@ #include "includes.h" -extern int DEBUGLEVEL; extern fstring global_myworkgroup; /**************************************************************************** diff --git a/source3/nmbd/nmbd_lmhosts.c b/source3/nmbd/nmbd_lmhosts.c index 04ab280784..4d819b41e9 100644 --- a/source3/nmbd/nmbd_lmhosts.c +++ b/source3/nmbd/nmbd_lmhosts.c @@ -26,8 +26,6 @@ #include "includes.h" -extern int DEBUGLEVEL; - /**************************************************************************** Load a lmhosts file. ****************************************************************************/ diff --git a/source3/nmbd/nmbd_logonnames.c b/source3/nmbd/nmbd_logonnames.c index c63de56a34..4f48b21b7f 100644 --- a/source3/nmbd/nmbd_logonnames.c +++ b/source3/nmbd/nmbd_logonnames.c @@ -24,8 +24,6 @@ #include "includes.h" -extern int DEBUGLEVEL; - extern pstring global_myname; extern fstring global_myworkgroup; extern char **my_netbios_names; diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index 432a4736a4..47655c804b 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -24,8 +24,6 @@ #include "includes.h" -extern int DEBUGLEVEL; - extern char **my_netbios_names; extern fstring global_myworkgroup; diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index fe2c0c0f21..aa9589e45a 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -24,8 +24,6 @@ #include "includes.h" -extern int DEBUGLEVEL; - extern char **my_netbios_names; uint16 samba_nb_type = 0; /* samba's NetBIOS name type */ diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index b497526475..1f0895ee37 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -24,7 +24,6 @@ #include "includes.h" -extern int DEBUGLEVEL; extern struct in_addr ipzero; /**************************************************************************** diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index 6b7bb6a73a..24463e1f9b 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -24,8 +24,6 @@ #include "includes.h" -extern int DEBUGLEVEL; - extern fstring global_myworkgroup; /**************************************************************************** diff --git a/source3/nmbd/nmbd_namerelease.c b/source3/nmbd/nmbd_namerelease.c index 0f693c63d0..30a9d16561 100644 --- a/source3/nmbd/nmbd_namerelease.c +++ b/source3/nmbd/nmbd_namerelease.c @@ -24,8 +24,6 @@ #include "includes.h" -extern int DEBUGLEVEL; - /**************************************************************************** Deal with a response packet when releasing one of our names. ****************************************************************************/ diff --git a/source3/nmbd/nmbd_nodestatus.c b/source3/nmbd/nmbd_nodestatus.c index d28ea1cff4..eeb532d410 100644 --- a/source3/nmbd/nmbd_nodestatus.c +++ b/source3/nmbd/nmbd_nodestatus.c @@ -24,8 +24,6 @@ #include "includes.h" -extern int DEBUGLEVEL; - /**************************************************************************** Deal with a successful node status response. ****************************************************************************/ diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index ab4b2c5e89..ace4ddfa25 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -28,8 +28,6 @@ extern int ClientNMB; extern int ClientDGRAM; extern int global_nmb_port; -extern int DEBUGLEVEL; - extern int num_response_packets; extern struct in_addr loopback_ip; diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 811f963bad..bcd1e1a1ff 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -26,8 +26,6 @@ #include "includes.h" -extern int DEBUGLEVEL; - extern pstring global_myname; extern fstring global_myworkgroup; diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index b4376d6405..b24c85a9d8 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -26,8 +26,6 @@ extern int ClientNMB; -extern int DEBUGLEVEL; - extern struct in_addr ipzero; int num_response_packets = 0; diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index 32a6d339de..1f56dea882 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -27,7 +27,6 @@ #include "includes.h" -extern int DEBUGLEVEL; extern pstring global_myname; extern fstring global_myworkgroup; extern char **my_netbios_names; diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index cbc48d2313..183ea34320 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -27,8 +27,6 @@ extern int ClientNMB; -extern int DEBUGLEVEL; - extern fstring global_myworkgroup; extern char **my_netbios_names; diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 996952451d..ebb6bfa9c6 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -31,8 +31,6 @@ extern int ClientNMB; extern int ClientDGRAM; extern int global_nmb_port; -extern int DEBUGLEVEL; - extern fstring myworkgroup; extern char **my_netbios_names; extern struct in_addr ipzero; diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 7ba39f0cd4..f6d1165e57 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -31,8 +31,6 @@ #include "includes.h" #include "smb.h" -extern int DEBUGLEVEL; - struct sync_record { struct sync_record *next, *prev; fstring workgroup; diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index d3118e82e1..8410228958 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -23,8 +23,6 @@ #include "includes.h" -extern int DEBUGLEVEL; - /**************************************************************************** Function called when the name lookup succeeded. ****************************************************************************/ diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 621a23b9e2..ea025e66f3 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -26,10 +26,8 @@ #define WINS_LIST "wins.dat" #define WINS_VERSION 1 -extern int DEBUGLEVEL; extern struct in_addr ipzero; - /**************************************************************************** possibly call the WINS hook external program when a WINS change is made *****************************************************************************/ diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 6bb156b41f..3b7a64b8e5 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -27,8 +27,6 @@ extern int ClientNMB; -extern int DEBUGLEVEL; - extern pstring global_myname; extern fstring global_myworkgroup; extern char **my_netbios_names; -- cgit From f5a5acec33160e9eedad079afe04597f796658d3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 8 Oct 2001 19:39:07 +0000 Subject: Fixed WINS re-registration bug. Don't ask..... :-(. It was in my code :-). Jeremy. (This used to be commit 129c640810bdf9ce2942e682d3d6fcca01a13488) --- source3/nmbd/nmbd_mynames.c | 4 ++-- source3/nmbd/nmbd_nameregister.c | 1 + 2 files changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index 47655c804b..7f9a3441a8 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -217,8 +217,8 @@ void refresh_my_names(time_t t) */ if( !is_refresh_already_queued( subrec, namerec) ) refresh_name( subrec, namerec, NULL, NULL, NULL ); - namerec->data.death_time += lp_max_ttl(); - namerec->data.refresh_time += MIN(lp_max_ttl(), MAX_REFRESH_TIME); + namerec->data.death_time = t + lp_max_ttl(); + namerec->data.refresh_time = t + MIN(lp_max_ttl(), MAX_REFRESH_TIME); } } } diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index 24463e1f9b..c3361cec60 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -209,6 +209,7 @@ responding.\n", inet_ntoa(rrec->packet->ip))); if(rrec->repeat_interval > (5 * 60)) rrec->repeat_interval = (5 * 60); rrec->repeat_time = time(NULL) + rrec->repeat_interval; + rrec->in_expiration_processing = False; DEBUG(5,("register_name_timeout_response: increasing WINS timeout to %d seconds.\n", (int)rrec->repeat_interval)); -- cgit From f741f656737f4ec46cd318e986b6bf412ed309d2 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 19 Nov 2001 02:49:53 +0000 Subject: Store some path names in global variables initialized to configure default, rather than in preprocessor macros. (This used to be commit 79ec88f0da40faebe1e587f1b3e87b5f2b184f58) --- source3/nmbd/nmbd.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 3c93f306b8..de673b6462 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -1,6 +1,5 @@ /* Unix SMB/Netbios implementation. - Version 1.9. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 @@ -28,7 +27,6 @@ #include "includes.h" extern pstring debugf; -pstring servicesf = CONFIGFILE; int ClientNMB = -1; int ClientDGRAM = -1; @@ -276,9 +274,9 @@ static BOOL reload_nmbd_services(BOOL test) { pstring fname; pstrcpy( fname,lp_configfile()); - if (file_exist(fname,NULL) && !strcsequal(fname,servicesf)) + if (file_exist(fname,NULL) && !strcsequal(fname,dyn_CONFIGFILE)) { - pstrcpy(servicesf,fname); + pstrcpy(dyn_CONFIGFILE,fname); test = False; } } @@ -286,7 +284,7 @@ static BOOL reload_nmbd_services(BOOL test) if ( test && !lp_file_list_changed() ) return(True); - ret = lp_load( servicesf, True , False, False); + ret = lp_load( dyn_CONFIGFILE, True , False, False); /* perhaps the config filename is now set */ if ( !test ) @@ -679,7 +677,7 @@ static void usage(char *pname) TimeInit(); - slprintf(debugf, sizeof(debugf)-1, "%s/log.nmbd", LOGFILEBASE); + slprintf(debugf, sizeof(debugf)-1, "%s/log.nmbd", dyn_LOGFILEBASE); setup_logging( argv[0], False ); #ifdef LMHOSTSFILE @@ -720,7 +718,7 @@ static void usage(char *pname) switch (opt) { case 's': - pstrcpy(servicesf,optarg); + pstrcpy(dyn_CONFIGFILE, optarg); break; case 'N': case 'B': -- cgit From 8654a161c8722a0059b15af12cdb81b27d49e71a Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Mon, 19 Nov 2001 03:12:10 +0000 Subject: LMHOSTSFILE is now dynamically configured too. (This used to be commit a779710fff5fddcbf65a8ddc8e9169b586b85481) --- source3/nmbd/nmbd.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index de673b6462..595a65a0cd 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -32,7 +32,6 @@ int ClientNMB = -1; int ClientDGRAM = -1; int global_nmb_port = -1; -static pstring host_file; extern pstring global_myname; extern fstring global_myworkgroup; extern char **my_netbios_names; @@ -668,7 +667,6 @@ static void usage(char *pname) append_log = True; /* Default, override with '-o' option. */ global_nmb_port = NMB_PORT; - *host_file = 0; global_in_nmbd = True; StartupTime = time(NULL); @@ -680,10 +678,6 @@ static void usage(char *pname) slprintf(debugf, sizeof(debugf)-1, "%s/log.nmbd", dyn_LOGFILEBASE); setup_logging( argv[0], False ); -#ifdef LMHOSTSFILE - pstrcpy( host_file, LMHOSTSFILE ); -#endif - /* this is for people who can't start the program correctly */ while (argc > 1 && (*argv[1] != '-')) { @@ -728,7 +722,7 @@ static void usage(char *pname) DEBUG(0,("Obsolete option '%c' used\n",opt)); break; case 'H': - pstrcpy(host_file,optarg); + pstrcpy(dyn_LMHOSTSFILE, optarg); break; case 'n': pstrcpy(global_myname,optarg); @@ -838,11 +832,8 @@ static void usage(char *pname) } /* Load in any static local names. */ - if ( *host_file ) - { - load_lmhosts_file(host_file); - DEBUG(3,("Loaded hosts file\n")); - } + load_lmhosts_file(dyn_LMHOSTSFILE); + DEBUG(3,("Loaded hosts file %s\n", dyn_LMHOSTSFILE)); /* If we are acting as a WINS server, initialise data structures. */ if( !initialise_wins() ) -- cgit From 79b34d1b11e685d068b9c0ac9a0ec06eaa263d82 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Fri, 23 Nov 2001 00:52:29 +0000 Subject: Removed TimeInit() call from every client program (except for one place in smbd/process.c where the timezone is reinitialised. Was replaced with check for a static is_initialised boolean. (This used to be commit 8fc772c9e5770cd3a8857670214dcff033ebae32) --- source3/nmbd/nmbd.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 595a65a0cd..314eead565 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -673,8 +673,6 @@ static void usage(char *pname) sys_srandom(time(NULL) ^ sys_getpid()); - TimeInit(); - slprintf(debugf, sizeof(debugf)-1, "%s/log.nmbd", dyn_LOGFILEBASE); setup_logging( argv[0], False ); -- cgit From 585d0efbc6428e5876d354fee49c241c1bad809d Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 26 Nov 2001 03:11:44 +0000 Subject: Got medieval on another pointless extern. Removed extern struct ipzero and replaced with two functions: void zero_ip(struct in_adder *ip); BOOL is_zero_ip(struct in_addr ip); (This used to be commit 778f5f77a66cda76348a7c6f64cd63afe2bfe077) --- source3/nmbd/nmbd.c | 2 -- source3/nmbd/nmbd_become_dmb.c | 3 +-- source3/nmbd/nmbd_browsesync.c | 5 ++--- source3/nmbd/nmbd_logonnames.c | 1 - source3/nmbd/nmbd_namequery.c | 6 +++--- source3/nmbd/nmbd_responserecordsdb.c | 2 -- source3/nmbd/nmbd_subnetdb.c | 11 ++++++----- source3/nmbd/nmbd_winsserver.c | 2 -- source3/nmbd/nmbd_workgroupdb.c | 3 +-- 9 files changed, 13 insertions(+), 22 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 314eead565..1b6547f6c3 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -48,8 +48,6 @@ BOOL found_lm_clients = False; time_t StartupTime = 0; -extern struct in_addr ipzero; - /**************************************************************************** ** catch a sigterm **************************************************************************** */ diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index 8a9fbaedd5..d62607a643 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -27,7 +27,6 @@ extern pstring global_myname; extern fstring global_myworkgroup; extern char **my_netbios_names; -extern struct in_addr ipzero; extern struct in_addr allones_ip; extern uint16 samba_nb_type; /* Samba's NetBIOS type. */ @@ -214,7 +213,7 @@ static void become_domain_master_query_success(struct subnet_record *subrec, /* BUG note. Samba 1.9.16p11 servers seem to return the broadcast address or zero ip for this query. Pretend this is ok. */ - if(ismyip(ip) || ip_equal(allones_ip, ip) || ip_equal(ipzero, ip)) + if(ismyip(ip) || ip_equal(allones_ip, ip) || is_zero_ip(ip)) { if( DEBUGLVL( 3 ) ) { diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 6a8edd0eaf..35bd29334e 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -25,7 +25,6 @@ #include "includes.h" #include "smb.h" -extern struct in_addr ipzero; extern pstring global_myname; extern fstring global_myworkgroup; @@ -308,7 +307,7 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec, /* First check if we already have a dmb for this workgroup. */ - if(!ip_equal(work->dmb_addr, ipzero) && ip_equal(work->dmb_addr, answer_ip)) + if(!is_zero_ip(work->dmb_addr) && ip_equal(work->dmb_addr, answer_ip)) { /* Do the local master browser announcement to the domain master browser name and IP. */ @@ -319,7 +318,7 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec, return; } else - putip((char *)&work->dmb_addr, &ipzero); + zero_ip(&work->dmb_addr); /* Now initiate the node status request. */ make_nmb_name(&nmbname,"*",0x0); diff --git a/source3/nmbd/nmbd_logonnames.c b/source3/nmbd/nmbd_logonnames.c index 4f48b21b7f..52340f1f31 100644 --- a/source3/nmbd/nmbd_logonnames.c +++ b/source3/nmbd/nmbd_logonnames.c @@ -27,7 +27,6 @@ extern pstring global_myname; extern fstring global_myworkgroup; extern char **my_netbios_names; -extern struct in_addr ipzero; extern struct in_addr allones_ip; extern uint16 samba_nb_type; /* Samba's NetBIOS type. */ diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index 1f0895ee37..9d2a7a4895 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -24,8 +24,6 @@ #include "includes.h" -extern struct in_addr ipzero; - /**************************************************************************** Deal with a response packet when querying a name. ****************************************************************************/ @@ -38,7 +36,9 @@ static void query_name_response( struct subnet_record *subrec, BOOL success = False; struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name; - struct in_addr answer_ip = ipzero; + struct in_addr answer_ip; + + zero_ip(&answer_ip); /* Ensure we don't retry the query but leave the response record cleanup to the timeout code. We may get more answer responses in which case diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index b24c85a9d8..63601ff26c 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -26,8 +26,6 @@ extern int ClientNMB; -extern struct in_addr ipzero; - int num_response_packets = 0; /*************************************************************************** diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index ebb6bfa9c6..3b450f6712 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -33,7 +33,6 @@ extern int global_nmb_port; extern fstring myworkgroup; extern char **my_netbios_names; -extern struct in_addr ipzero; /* This is the broadcast subnets database. */ struct subnet_record *subnetlist = NULL; @@ -232,7 +231,7 @@ BOOL create_subnets(void) { int num_interfaces = iface_count(); int i; - struct in_addr unicast_ip; + struct in_addr unicast_ip, ipzero; extern struct in_addr loopback_ip; if(num_interfaces == 0) @@ -280,7 +279,7 @@ BOOL create_subnets(void) struct in_addr real_wins_ip; real_wins_ip = wins_srv_ip(); - if (!zero_ip(real_wins_ip)) + if (!is_zero_ip(real_wins_ip)) { unicast_ip = real_wins_ip; } @@ -302,7 +301,7 @@ BOOL create_subnets(void) { /* We should not be using a WINS server at all. Set the ip address of the subnet to be zero. */ - unicast_ip = ipzero; + zero_ip(&unicast_ip); } /* @@ -315,6 +314,8 @@ BOOL create_subnets(void) unicast_subnet = make_subnet( "UNICAST_SUBNET", UNICAST_SUBNET, unicast_ip, unicast_ip, unicast_ip); + zero_ip(&ipzero); + remote_broadcast_subnet = make_subnet( "REMOTE_BROADCAST_SUBNET", REMOTE_BROADCAST_SUBNET, ipzero, ipzero, ipzero); @@ -347,7 +348,7 @@ BOOL we_are_a_wins_client(void) static int cache_we_are_a_wins_client = -1; if(cache_we_are_a_wins_client == -1) - cache_we_are_a_wins_client = (ip_equal(ipzero, unicast_subnet->myip) ? + cache_we_are_a_wins_client = (is_zero_ip(unicast_subnet->myip) ? False : True); return cache_we_are_a_wins_client; diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index ea025e66f3..ecb5f2da55 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -26,8 +26,6 @@ #define WINS_LIST "wins.dat" #define WINS_VERSION 1 -extern struct in_addr ipzero; - /**************************************************************************** possibly call the WINS hook external program when a WINS change is made *****************************************************************************/ diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 3b7a64b8e5..4551eaf46b 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -31,7 +31,6 @@ extern pstring global_myname; extern fstring global_myworkgroup; extern char **my_netbios_names; extern uint16 samba_nb_type; -extern struct in_addr ipzero; int workgroup_count = 0; /* unique index key: one for each workgroup */ @@ -101,7 +100,7 @@ static struct work_record *create_workgroup(const char *name, int ttl) /* No known domain master browser as yet. */ *work->dmb_name.name = '\0'; - putip((char *)&work->dmb_addr, &ipzero); + zero_ip(&work->dmb_addr); /* WfWg uses 01040b01 */ /* Win95 uses 01041501 */ -- cgit From a3e74d16d097d9a5393abfc7ae09a9c56d369bb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 27 Nov 2001 03:40:06 +0000 Subject: added -i option to nmbd, giving interactive mode (like winbindd) (This used to be commit 1a30efdc2c7e5b385197bbfbcebac6a7305929b8) --- source3/nmbd/nmbd.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 1b6547f6c3..963e265330 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -661,6 +661,7 @@ static void usage(char *pname) int opt; extern char *optarg; extern BOOL append_log; + BOOL opt_interactive = False; append_log = True; /* Default, override with '-o' option. */ @@ -672,7 +673,6 @@ static void usage(char *pname) sys_srandom(time(NULL) ^ sys_getpid()); slprintf(debugf, sizeof(debugf)-1, "%s/log.nmbd", dyn_LOGFILEBASE); - setup_logging( argv[0], False ); /* this is for people who can't start the program correctly */ while (argc > 1 && (*argv[1] != '-')) @@ -703,7 +703,7 @@ static void usage(char *pname) #endif while( EOF != - (opt = getopt( argc, argv, "Vaos:T:I:C:bAB:N:Rn:l:d:Dp:hSH:G:f:" )) ) + (opt = getopt( argc, argv, "Vaos:T:I:C:bAB:N:Rn:l:d:Dp:hSH:G:f:i" )) ) { switch (opt) { @@ -717,6 +717,9 @@ static void usage(char *pname) case 'G': DEBUG(0,("Obsolete option '%c' used\n",opt)); break; + case 'i': + opt_interactive = True; + break; case 'H': pstrcpy(dyn_LMHOSTSFILE, optarg); break; @@ -761,6 +764,8 @@ static void usage(char *pname) } } + setup_logging( argv[0], opt_interactive ); + reopen_logs(); DEBUG( 1, ( "Netbios nameserver version %s started.\n", VERSION ) ); @@ -790,7 +795,7 @@ static void usage(char *pname) is_daemon = True; } - if (is_daemon) + if (is_daemon && !opt_interactive) { DEBUG( 2, ( "Becoming a daemon.\n" ) ); become_daemon(); -- cgit From 9ed10f83d76eba1c4d4ac19842314f24db1c7a65 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 20 Dec 2001 22:27:05 +0000 Subject: Removed global debugf. Replaced with lp_set_logfile(name). Fixed winbindd to finally stop leaving log. file droppings :-). Jeremy. (This used to be commit 0bea6cf79a44f79fa3a4f2c8381e898e79c66509) --- source3/nmbd/nmbd.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 963e265330..80d712036d 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -26,8 +26,6 @@ #include "includes.h" -extern pstring debugf; - int ClientNMB = -1; int ClientDGRAM = -1; int global_nmb_port = -1; @@ -103,7 +101,7 @@ static BOOL dump_core(void) { char *p; pstring dname; - pstrcpy( dname, debugf ); + pstrcpy( dname, lp_logfile() ); if ((p=strrchr_m(dname,'/'))) *p=0; pstrcat( dname, "/corefiles" ); @@ -662,6 +660,7 @@ static void usage(char *pname) extern char *optarg; extern BOOL append_log; BOOL opt_interactive = False; + pstring logfile; append_log = True; /* Default, override with '-o' option. */ @@ -672,7 +671,8 @@ static void usage(char *pname) sys_srandom(time(NULL) ^ sys_getpid()); - slprintf(debugf, sizeof(debugf)-1, "%s/log.nmbd", dyn_LOGFILEBASE); + slprintf(logfile, sizeof(logfile)-1, "%s/log.nmbd", dyn_LOGFILEBASE); + lp_set_logfile(logfile); /* this is for people who can't start the program correctly */ while (argc > 1 && (*argv[1] != '-')) @@ -728,7 +728,8 @@ static void usage(char *pname) strupper(global_myname); break; case 'l': - slprintf(debugf, sizeof(debugf)-1, "%s/log.nmbd", optarg); + slprintf(logfile, sizeof(logfile)-1, "%s/log.nmbd", optarg); + lp_set_logfile(logfile); break; case 'a': append_log = True; -- cgit From bf65820af242786bd66d814fc3e9d89920a49f8e Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Fri, 21 Dec 2001 00:37:49 +0000 Subject: Add an output parameter to message_send_all that says how many messages were sent, so you know how many replies to expect. Const and doc religion. (This used to be commit 22e510ea0d69356be4fd2fa5ad9e9f4e84f62337) --- source3/nmbd/nmbd_processlogon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index bcd1e1a1ff..b348250f86 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -55,7 +55,7 @@ static void send_repl_message(uint32 low_serial) low_serial)); message_send_all(tdb, MSG_SMB_SAM_REPL, &low_serial, - sizeof(low_serial), False); + sizeof(low_serial), False, NULL); tdb_close(tdb); } -- cgit From 0d6a1c09982f7497a4ea80f9c4db3bb249ccfa67 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 29 Dec 2001 21:13:53 +0000 Subject: Fixup -i interactive modes. Jeremy. (This used to be commit 9343b613d3778b0330bc4d610d3befd363797360) --- source3/nmbd/nmbd.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 80d712036d..29b6c0347a 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -634,10 +634,11 @@ static BOOL init_structs(void) static void usage(char *pname) { - printf( "Usage: %s [-DaohV] [-H lmhosts file] [-d debuglevel] [-l log basename]\n", pname ); + printf( "Usage: %s [-DaiohV] [-H lmhosts file] [-d debuglevel] [-l log basename]\n", pname ); printf( " [-n name] [-p port] [-s configuration file]\n" ); - printf( "\t-D Become a daemon\n" ); + printf( "\t-D Become a daemon (default)\n" ); printf( "\t-a Append to log file (default)\n" ); + printf( "\t-i Run interactive (not a daemon)\n" ); printf( "\t-o Overwrite log file, don't append\n" ); printf( "\t-h Print usage\n" ); printf( "\t-V Print version\n" ); @@ -717,9 +718,9 @@ static void usage(char *pname) case 'G': DEBUG(0,("Obsolete option '%c' used\n",opt)); break; - case 'i': - opt_interactive = True; - break; + case 'i': + opt_interactive = True; + break; case 'H': pstrcpy(dyn_LMHOSTSFILE, optarg); break; -- cgit From bb81e23e176ec7dfe0111b5aa2946a51239ef3b9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 30 Dec 2001 01:46:38 +0000 Subject: When running interactive we want to set our own process group for signal management. Jeremy. (This used to be commit fffae94dd5699f44c0b1c8081587deafd89b3fc0) --- source3/nmbd/nmbd.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 29b6c0347a..b2ff81675a 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -803,6 +803,15 @@ static void usage(char *pname) become_daemon(); } +#if HAVE_SETPGID + /* + * If we're interactive we want to set our own process group for + * signal management. + */ + if (opt_interactive) + setpgid( (pid_t)0, (pid_t)0 ); +#endif + #ifndef SYNC_DNS /* Setup the async dns. We do it here so it doesn't have all the other stuff initialised and thus chewing memory and sockets */ -- cgit From d6823366b881612234ab0655adb11c594f864c4a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 11 Jan 2002 19:10:25 +0000 Subject: Same fix as went into 2.2 (I'm waiting for jerry to finish some code). Jeremy. (This used to be commit 01ff6ce4963e1daff019f2b936cef218e1c93f67) --- source3/nmbd/nmbd_browsesync.c | 2 +- source3/nmbd/nmbd_elections.c | 4 ++-- source3/nmbd/nmbd_packets.c | 2 +- source3/nmbd/nmbd_sendannounce.c | 22 +++++++++++----------- 4 files changed, 15 insertions(+), 15 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 35bd29334e..40e04e7ecb 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -127,7 +127,7 @@ static void announce_local_master_browser_to_domain_master_browser( struct work_ memset(outbuf,'\0',sizeof(outbuf)); p = outbuf; - CVAL(p,0) = ANN_MasterAnnouncement; + SCVAL(p,0,ANN_MasterAnnouncement); p++; StrnCpy(p,global_myname,15); diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 6db595269f..ae22518495 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -44,10 +44,10 @@ static void send_election_dgram(struct subnet_record *subrec, char *workgroup_na memset(outbuf,'\0',sizeof(outbuf)); p = outbuf; - CVAL(p,0) = ANN_Election; /* Election opcode. */ + SCVAL(p,0,ANN_Election); /* Election opcode. */ p++; - CVAL(p,0) = (criterion == 0 && timeup == 0) ? 0 : ELECTION_VERSION; + SCVAL(p,0,((criterion == 0 && timeup == 0) ? 0 : ELECTION_VERSION)); SIVAL(p,1,criterion); SIVAL(p,5,timeup*1000); /* ms - Despite what the spec says. */ p += 13; diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index ace4ddfa25..a81da0ca9b 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1936,7 +1936,7 @@ BOOL send_mailslot(BOOL unique, char *mailslot,char *buf,int len, set_message(ptr,17,17 + len,True); memcpy(ptr,tmp,4); - CVAL(ptr,smb_com) = SMBtrans; + SCVAL(ptr,smb_com,SMBtrans); SSVAL(ptr,smb_vwv1,len); SSVAL(ptr,smb_vwv11,len); SSVAL(ptr,smb_vwv12,70 + strlen(mailslot)); diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index 1f56dea882..ee3b3d110f 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -47,9 +47,9 @@ void send_browser_reset(int reset_type, char *to_name, int to_type, struct in_ad memset(outbuf,'\0',sizeof(outbuf)); p = outbuf; - CVAL(p,0) = ANN_ResetBrowserState; + SCVAL(p,0,ANN_ResetBrowserState); p++; - CVAL(p,0) = reset_type; + SCVAL(p,0,reset_type); p++; send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), @@ -74,10 +74,10 @@ to subnet %s\n", work->work_group, subrec->subnet_name)); memset(outbuf,'\0',sizeof(outbuf)); p = outbuf; - CVAL(p,0) = ANN_AnnouncementRequest; + SCVAL(p,0,ANN_AnnouncementRequest); p++; - CVAL(p,0) = work->token; /* (local) Unique workgroup token id. */ + SCVAL(p,0,work->token); /* (local) Unique workgroup token id. */ p++; p += push_string(NULL, p+1, global_myname, 15, STR_ASCII|STR_UPPER|STR_TERMINATE); @@ -101,16 +101,16 @@ static void send_announcement(struct subnet_record *subrec, int announce_type, memset(outbuf,'\0',sizeof(outbuf)); p = outbuf+1; - CVAL(outbuf,0) = announce_type; + SCVAL(outbuf,0,announce_type); /* Announcement parameters. */ - CVAL(p,0) = updatecount; + SCVAL(p,0,updatecount); SIVAL(p,1,announce_interval*1000); /* Milliseconds - despite the spec. */ push_string(NULL, p+5, server_name, 15, STR_ASCII|STR_UPPER|STR_TERMINATE); - CVAL(p,21) = lp_major_announce_version(); /* Major version. */ - CVAL(p,22) = lp_minor_announce_version(); /* Minor version. */ + SCVAL(p,21,lp_major_announce_version()); /* Major version. */ + SCVAL(p,22,lp_minor_announce_version()); /* Minor version. */ SIVAL(p,23,server_type & ~SV_TYPE_LOCAL_LIST_ONLY); /* Browse version: got from NT/AS 4.00 - Value defined in smb.h (JHT). */ @@ -140,8 +140,8 @@ static void send_lm_announcement(struct subnet_record *subrec, int announce_type SSVAL(p,0,announce_type); SIVAL(p,2,server_type & ~SV_TYPE_LOCAL_LIST_ONLY); - CVAL(p,6) = lp_major_announce_version(); /* Major version. */ - CVAL(p,7) = lp_minor_announce_version(); /* Minor version. */ + SCVAL(p,6,lp_major_announce_version()); /* Major version. */ + SCVAL(p,7,lp_minor_announce_version()); /* Minor version. */ SSVAL(p,8,announce_interval); /* In seconds - according to spec. */ p += 10; @@ -585,7 +585,7 @@ for workgroup %s on subnet %s.\n", global_myworkgroup, FIRST_SUBNET->subnet_name memset(outbuf,'\0',sizeof(outbuf)); p = outbuf; - CVAL(p,0) = ANN_MasterAnnouncement; + SCVAL(p,0,ANN_MasterAnnouncement); p++; StrnCpy(p,global_myname,15); -- cgit From 24bdb14564c7b18bb6f93dc9ec53526bfda2c194 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 16 Jan 2002 19:23:05 +0000 Subject: Fix name register bug with non-existent wins server. Jeremy. (This used to be commit 4e41780c21d9a6c056104f952e720a79c830c65e) --- source3/nmbd/nmbd_mynames.c | 61 +++++++++++++++++++++------------------------ 1 file changed, 29 insertions(+), 32 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index 7f9a3441a8..b1b3f48b62 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -98,53 +98,50 @@ BOOL register_my_workgroup_and_names(void) register_my_workgroup_one_subnet(subrec); } - /* If we are not a WINS client, we still need to add the magic Samba + /* We still need to add the magic Samba names and the netbios names to the unicast subnet directly. This is to allow unicast node status requests and queries to still work in a broadcast only environment. */ - if(we_are_a_wins_client() == False) - { - add_samba_names_to_subnet(unicast_subnet); + add_samba_names_to_subnet(unicast_subnet); - for (i=0; my_netbios_names[i]; i++) + for (i=0; my_netbios_names[i]; i++) + { + for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { - for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - { - /* - * Ensure all the IP addresses are added if we are multihomed. - */ - struct nmb_name nmbname; + /* + * Ensure all the IP addresses are added if we are multihomed. + */ + struct nmb_name nmbname; - make_nmb_name(&nmbname, my_netbios_names[i],0x20); - insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type); + make_nmb_name(&nmbname, my_netbios_names[i],0x20); + insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type); - make_nmb_name(&nmbname, my_netbios_names[i],0x3); - insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type); + make_nmb_name(&nmbname, my_netbios_names[i],0x3); + insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type); - make_nmb_name(&nmbname, my_netbios_names[i],0x0); - insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type); - } + make_nmb_name(&nmbname, my_netbios_names[i],0x0); + insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type); } + } + /* + * Add the WORKGROUP<0> and WORKGROUP<1e> group names to the unicast subnet + * also for the same reasons. + */ + + for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + { /* - * Add the WORKGROUP<0> and WORKGROUP<1e> group names to the unicast subnet - * also for the same reasons. + * Ensure all the IP addresses are added if we are multihomed. */ + struct nmb_name nmbname; - for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - { - /* - * Ensure all the IP addresses are added if we are multihomed. - */ - struct nmb_name nmbname; + make_nmb_name(&nmbname, global_myworkgroup, 0x0); + insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP); - make_nmb_name(&nmbname, global_myworkgroup, 0x0); - insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP); - - make_nmb_name(&nmbname, global_myworkgroup, 0x1e); - insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP); - } + make_nmb_name(&nmbname, global_myworkgroup, 0x1e); + insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP); } /* -- cgit From 9d05373a767cef2e841640f192e74da37fbb099f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 Jan 2002 02:30:37 +0000 Subject: Tidyup & code refactoring from Martin.Sheppard@csiro.au. Jeremy. (This used to be commit 85da18e46e607aa593b7c55f2c7eddd1c3769673) --- source3/nmbd/nmbd_serverlistdb.c | 49 +++++++++++++++++++--------------------- 1 file changed, 23 insertions(+), 26 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index 183ea34320..e2992107fb 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -296,6 +296,19 @@ static uint32 write_this_workgroup_name( struct subnet_record *subrec, Write out the browse.dat file. ******************************************************************/ +void write_browse_list_entry(XFILE *fp, fstring name, uint32 rec_type, + fstring local_master_browser_name, fstring description) +{ + fstring tmp; + + slprintf(tmp,sizeof(tmp)-1, "\"%s\"", name); + x_fprintf(fp, "%-25s ", tmp); + x_fprintf(fp, "%08x ", rec_type); + slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", local_master_browser_name); + x_fprintf(fp, "%-30s", tmp); + x_fprintf(fp, "\"%s\"\n", description); +} + void write_browse_list(time_t t, BOOL force_write) { struct subnet_record *subrec; @@ -365,12 +378,9 @@ void write_browse_list(time_t t, BOOL force_write) return; } - slprintf(tmp,sizeof(tmp)-1, "\"%s\"", work->work_group); - x_fprintf(fp, "%-25s ", tmp); - x_fprintf(fp, "%08x ", SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT|SV_TYPE_LOCAL_LIST_ONLY); - slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", work->local_master_browser_name); - x_fprintf(fp, "%-30s", tmp); - x_fprintf(fp, "\"%s\"\n", work->work_group); + write_browse_list_entry(fp, work->work_group, + SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT|SV_TYPE_LOCAL_LIST_ONLY, + work->local_master_browser_name, work->work_group); /* * We need to do something special for our own names. @@ -394,13 +404,8 @@ void write_browse_list(time_t t, BOOL force_write) } /* Output server details, plus what workgroup they're in. */ - slprintf(tmp, sizeof(tmp)-1, "\"%s\"", my_netbios_names[i]); - x_fprintf(fp, "%-25s ", tmp); - x_fprintf(fp, "%08x ", stype); - slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", - string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH)); - x_fprintf(fp, "%-30s", tmp); - x_fprintf(fp, "\"%s\"\n", global_myworkgroup); + write_browse_list_entry(fp, my_netbios_names[i], stype, + string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH), global_myworkgroup); } for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) @@ -414,13 +419,9 @@ void write_browse_list(time_t t, BOOL force_write) if(wg_type) { - slprintf(tmp, sizeof(tmp)-1, "\"%s\"", work->work_group); - x_fprintf(fp, "%-25s ", tmp); - - x_fprintf(fp, "%08x ", wg_type); - slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", work->local_master_browser_name); - x_fprintf(fp, "%-30s", tmp); - x_fprintf(fp, "\"%s\"\n", work->work_group); + write_browse_list_entry(fp, work->work_group, wg_type, + work->local_master_browser_name, + work->work_group); } /* Now write out any server records a workgroup may have. */ @@ -438,12 +439,8 @@ void write_browse_list(time_t t, BOOL force_write) if(serv_type) { /* Output server details, plus what workgroup they're in. */ - slprintf(tmp, sizeof(tmp)-1, "\"%s\"", servrec->serv.name); - x_fprintf(fp, "%-25s ", tmp); - x_fprintf(fp, "%08x ", serv_type); - slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", servrec->serv.comment); - x_fprintf(fp, "%-30s", tmp); - x_fprintf(fp, "\"%s\"\n", work->work_group); + write_browse_list_entry(fp, servrec->serv.name, serv_type, + servrec->serv.comment, work->work_group); } } } -- cgit From efdb29d0e0f7737dcf21045bc560a1b9378886b4 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 18 Jan 2002 03:26:53 +0000 Subject: Ensure (C) message is output on startup. Jeremy. (This used to be commit 7d05175494227bf30d098e04ec91c4f0a7b7184c) --- source3/nmbd/nmbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index b2ff81675a..57dacc7a05 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -770,8 +770,8 @@ static void usage(char *pname) reopen_logs(); - DEBUG( 1, ( "Netbios nameserver version %s started.\n", VERSION ) ); - DEBUGADD( 1, ( "Copyright Andrew Tridgell 1994-1998\n" ) ); + DEBUG( 0, ( "Netbios nameserver version %s started.\n", VERSION ) ); + DEBUGADD( 0, ( "Copyright Andrew Tridgell and the Samba Team 1994-2002\n" ) ); if ( !reload_nmbd_services(False) ) return(-1); -- cgit From a2cff140cfa21697c896c1faf636bd36b4d0c86b Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Fri, 25 Jan 2002 17:03:36 +0000 Subject: remove unused variable J.F. (This used to be commit ca7665c6b3618d3160bbd8e55ab56a8783cf8934) --- source3/nmbd/nmbd_serverlistdb.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index e2992107fb..fd1d8e51ba 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -316,7 +316,6 @@ void write_browse_list(time_t t, BOOL force_write) struct server_record *servrec; pstring fname,fnamenew; uint32 stype; - fstring tmp; int i; XFILE *fp; BOOL list_changed = force_write; -- cgit From 558e4cf0b87f393c2b0a52192c5051c258f281e0 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Fri, 25 Jan 2002 22:50:15 +0000 Subject: rewrote nmbd's wins backend to use a tdb instead of a flat text file. Changed the way the wins record are handled in memory. Now they are living much longer with the different states: active, released and tombstone. Also added a version ID, some wins flags and the wins owner ip address to the namrec->data struct, and a function to process messages sent by the wins replication daemon. the initiate_wins_processing() function is not correct, I'll fix it later. J.F. (This used to be commit b902e087d06c32797af19021a7f56895d86d7364) --- source3/nmbd/nmbd.c | 1 + source3/nmbd/nmbd_namelistdb.c | 1 + source3/nmbd/nmbd_winsserver.c | 892 +++++++++++++++++++++++++++++------------ 3 files changed, 627 insertions(+), 267 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 57dacc7a05..a7abdc5da0 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -827,6 +827,7 @@ static void usage(char *pname) pidfile_create("nmbd"); message_init(); message_register(MSG_FORCE_ELECTION, nmbd_message_election); + message_register(MSG_WINS_NEW_ENTRY, nmbd_wins_new_entry); DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index aa9589e45a..fba56ef49f 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -213,6 +213,7 @@ struct name_record *add_name_to_subnet( struct subnet_record *subrec, /* Enter the name as active. */ namerec->data.nb_flags = nb_flags | NB_ACTIVE; + namerec->data.wins_flags = WINS_ACTIVE; /* If it's our primary name, flag it as so. */ if( strequal( my_netbios_names[0], name ) ) diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index ecb5f2da55..d732da62cf 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -23,9 +23,81 @@ #include "includes.h" -#define WINS_LIST "wins.dat" +#define WINS_LIST "wins.tdb" #define WINS_VERSION 1 +/**************************************************************************** +change the wins owner address in the record. +*****************************************************************************/ +static void update_wins_owner(struct name_record *namerec, struct in_addr wins_ip) +{ + if (namerec==NULL) + return; + namerec->data.wins_ip=wins_ip; +} + +/**************************************************************************** +create the wins flags based on the nb flags and the input value. +*****************************************************************************/ +static void update_wins_flag(struct name_record *namerec, int flags) +{ + if (namerec==NULL) + return; + + namerec->data.wins_flags=0x0; + + /* if it's a group, it can be a normal or a special one */ + if (namerec->data.nb_flags & NB_GROUP) { + if (namerec->name.name_type==0x1C) + namerec->data.wins_flags|=WINS_SGROUP; + else + if (namerec->data.num_ips>1) + namerec->data.wins_flags|=WINS_SGROUP; + else + namerec->data.wins_flags|=WINS_NGROUP; + } else { + /* can be unique or multi-homed */ + if (namerec->data.num_ips>1) + namerec->data.wins_flags|=WINS_MHOMED; + else + namerec->data.wins_flags|=WINS_UNIQUE; + } + + /* the node type are the same bits */ + namerec->data.wins_flags|=namerec->data.nb_flags&NB_NODETYPEMASK; + + /* the static bit is elsewhere */ + if (namerec->data.death_time == PERMANENT_TTL) + namerec->data.wins_flags|=WINS_STATIC; + + /* and add the given bits */ + namerec->data.wins_flags|=flags; + + DEBUG(8,("update_wins_flag: nbflags: 0x%x, ttl: 0x%d, flags: 0x%x, winsflags: 0x%x\n", + namerec->data.nb_flags, (int)namerec->data.death_time, flags, namerec->data.wins_flags)); + +} + +/**************************************************************************** +return the general ID value and increase it if requested +*****************************************************************************/ +static void get_global_id_and_update(SMB_BIG_UINT *current_id, BOOL update) +{ + /* + * it's kept as a static here, to prevent people from messing + * with the value directly + */ + + static SMB_BIG_UINT general_id = 1; + + DEBUG(5,("get_global_id_and_update: updating version ID: %d\n", (int)general_id)); + + *current_id = general_id; + + if (update) + general_id++; +} + /**************************************************************************** possibly call the WINS hook external program when a WINS change is made *****************************************************************************/ @@ -168,178 +240,115 @@ Load or create the WINS database. BOOL initialise_wins(void) { - time_t time_now = time(NULL); - XFILE *fp; - pstring line; + time_t time_now = time(NULL); + TDB_CONTEXT *tdb; + TDB_DATA kbuf, dbuf, newkey; + struct name_record *namerec = NULL; + struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); - if(!lp_we_are_a_wins_server()) - return True; + DEBUG(2,("initialise_wins: started\n")); - add_samba_names_to_subnet(wins_server_subnet); + if(!lp_we_are_a_wins_server()) + return True; - if((fp = x_fopen(lock_path(WINS_LIST),O_RDONLY, 0)) == NULL) - { - DEBUG(2,("initialise_wins: Can't open wins database file %s. Error was %s\n", - WINS_LIST, strerror(errno) )); - return True; - } - - while (!x_feof(fp)) - { - pstring name_str, ip_str, ttl_str, nb_flags_str; - unsigned int num_ips; - pstring name; - struct in_addr *ip_list; - int type = 0; - int nb_flags; - int ttl; - char *ptr; - char *p; - BOOL got_token; - BOOL was_ip; - int i; - unsigned hash; - int version; - - /* Read a line from the wins.dat file. Strips whitespace - from the beginning and end of the line. - */ - if (!fgets_slash(line,sizeof(pstring),fp)) - continue; - - if (*line == '#') - continue; - - if (strncmp(line,"VERSION ", 8) == 0) { - if (sscanf(line,"VERSION %d %u", &version, &hash) != 2 || - version != WINS_VERSION || - hash != wins_hash()) { - DEBUG(0,("Discarding invalid wins.dat file [%s]\n",line)); - x_fclose(fp); - return True; - } - continue; - } - - ptr = line; + add_samba_names_to_subnet(wins_server_subnet); - /* - * Now we handle multiple IP addresses per name we need - * to iterate over the line twice. The first time to - * determine how many IP addresses there are, the second - * time to actually parse them into the ip_list array. - */ - - if (!next_token(&ptr,name_str,NULL,sizeof(name_str))) - { - DEBUG(0,("initialise_wins: Failed to parse name when parsing line %s\n", line )); - continue; - } + tdb = tdb_open_log(lock_path(WINS_LIST), 0, TDB_DEFAULT, O_RDONLY, 0600); + if (!tdb) { + DEBUG(2,("initialise_wins: Can't open wins database file %s. Error was %s\n", WINS_LIST, strerror(errno) )); + return True; + } - if (!next_token(&ptr,ttl_str,NULL,sizeof(ttl_str))) - { - DEBUG(0,("initialise_wins: Failed to parse time to live when parsing line %s\n", line )); - continue; - } + if (tdb_fetch_int(tdb, INFO_VERSION) != WINS_VERSION) { + DEBUG(0,("Discarding invalid wins.dat file\n")); + tdb_close(tdb); + return True; + } - /* - * Determine the number of IP addresses per line. - */ - num_ips = 0; - do - { - got_token = next_token(&ptr,ip_str,NULL,sizeof(ip_str)); - was_ip = False; + for (kbuf = tdb_firstkey(tdb); + kbuf.dptr; + newkey = tdb_nextkey(tdb, kbuf), safe_free(kbuf.dptr), kbuf=newkey) { + + pstring name_type, name, ip_str; + char *p; + int type = 0; + int nb_flags; + int ttl; + unsigned int num_ips; + int high, low; + struct in_addr wins_ip; + struct in_addr *ip_list; + int wins_flags; + int len,i; + + if (strncmp(kbuf.dptr, ENTRY_PREFIX, strlen(ENTRY_PREFIX)) != 0) + continue; + + dbuf = tdb_fetch(tdb, kbuf); + if (!dbuf.dptr) continue; + + fstrcpy(name_type, kbuf.dptr+strlen(ENTRY_PREFIX)); + + pstrcpy(name, name_type); + + if((p = strchr(name,'#')) != NULL) { + *p = 0; + sscanf(p+1,"%x",&type); + } - if(got_token && strchr_m(ip_str, '.')) - { - num_ips++; - was_ip = True; - } - } while( got_token && was_ip); + len = tdb_unpack(dbuf.dptr, dbuf.dsize, "dddfddd", + &nb_flags, &high, &low, + ip_str, &ttl, &num_ips, &wins_flags); - if(num_ips == 0) - { - DEBUG(0,("initialise_wins: Missing IP address when parsing line %s\n", line )); - continue; - } + wins_ip=*interpret_addr2(ip_str); - if(!got_token) - { - DEBUG(0,("initialise_wins: Missing nb_flags when parsing line %s\n", line )); - continue; - } + /* Don't reload replica records */ + if (!ip_equal(wins_ip, our_fake_ip)) + continue; - /* Allocate the space for the ip_list. */ - if((ip_list = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr))) == NULL) - { - DEBUG(0,("initialise_wins: Malloc fail !\n")); - return False; - } - - /* Reset and re-parse the line. */ - ptr = line; - next_token(&ptr,name_str,NULL,sizeof(name_str)); - next_token(&ptr,ttl_str,NULL,sizeof(ttl_str)); - for(i = 0; i < num_ips; i++) - { - next_token(&ptr, ip_str, NULL, sizeof(ip_str)); - ip_list[i] = *interpret_addr2(ip_str); - } - next_token(&ptr,nb_flags_str,NULL, sizeof(nb_flags_str)); + /* Don't reload released or tombstoned records */ + if ((wins_flags&WINS_STATE_MASK) != WINS_ACTIVE) + continue; - /* - * Deal with SELF or REGISTER name encoding. Default is REGISTER - * for compatibility with old nmbds. - */ + /* Allocate the space for the ip_list. */ + if((ip_list = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr))) == NULL) { + DEBUG(0,("initialise_wins: Malloc fail !\n")); + return False; + } - if(nb_flags_str[strlen(nb_flags_str)-1] == 'S') - { - DEBUG(5,("initialise_wins: Ignoring SELF name %s\n", line)); - SAFE_FREE(ip_list); - continue; - } - - if(nb_flags_str[strlen(nb_flags_str)-1] == 'R') - nb_flags_str[strlen(nb_flags_str)-1] = '\0'; - - /* Netbios name. # divides the name from the type (hex): netbios#xx */ - pstrcpy(name,name_str); - - if((p = strchr_m(name,'#')) != NULL) - { - *p = 0; - sscanf(p+1,"%x",&type); - } - - /* Decode the netbios flags (hex) and the time-to-live (in seconds). */ - sscanf(nb_flags_str,"%x",&nb_flags); - sscanf(ttl_str,"%d",&ttl); + for (i = 0; i < num_ips; i++) { + len += tdb_unpack(dbuf.dptr+len, dbuf.dsize-len, "f", ip_str); + ip_list[i] = *interpret_addr2(ip_str); + } - /* add all entries that have 60 seconds or more to live */ - if ((ttl - 60) > time_now || ttl == PERMANENT_TTL) - { - if(ttl != PERMANENT_TTL) - ttl -= time_now; + /* add all entries that have 60 seconds or more to live */ + if ((ttl - 60) > time_now || ttl == PERMANENT_TTL) { + if(ttl != PERMANENT_TTL) + ttl -= time_now; - DEBUG( 4, ("initialise_wins: add name: %s#%02x ttl = %d first IP %s flags = %2x\n", - name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); - - (void)add_name_to_subnet( wins_server_subnet, name, type, nb_flags, - ttl, REGISTER_NAME, num_ips, ip_list ); - - } - else - { - DEBUG(4, ("initialise_wins: not adding name (ttl problem) %s#%02x ttl = %d first IP %s flags = %2x\n", - name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); - } + DEBUG( 4, ("initialise_wins: add name: %s#%02x ttl = %d first IP %s flags = %2x\n", + name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); + + namerec=add_name_to_subnet( wins_server_subnet, name, type, nb_flags, + ttl, REGISTER_NAME, num_ips, ip_list); + if (namerec!=NULL) { + update_wins_owner(namerec, wins_ip); + update_wins_flag(namerec, wins_flags); + /* we don't reload the ID, on startup we restart at 1 */ + get_global_id_and_update(&namerec->data.id, True); + } + + } else { + DEBUG(4, ("initialise_wins: not adding name (ttl problem) %s#%02x ttl = %d first IP %s flags = %2x\n", + name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); + } - SAFE_FREE(ip_list); - } + SAFE_FREE(ip_list); + } - x_fclose(fp); - return True; + tdb_close(tdb); + DEBUG(2,("initialise_wins: done\n")); + return True; } /**************************************************************************** @@ -409,6 +418,7 @@ void wins_process_name_refresh_request(struct subnet_record *subrec, struct name_record *namerec = NULL; int ttl = get_ttl_from_packet(nmb); struct in_addr from_ip; + struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); putip((char *)&from_ip,&nmb->additional->rdata[2]); @@ -449,6 +459,21 @@ the name does not exist. Treating as registration.\n", nmb_namestr(question) )); return; } + /* + * if the name is present but not active, + * simply remove it and treat the request + * as a registration + */ + if (namerec != NULL && !WINS_STATE_ACTIVE(namerec)) + { + DEBUG(5,("wins_process_name_refresh_request: Name (%s) in WINS was \ +not active - removing it.\n", nmb_namestr(question) )); + remove_name_from_namelist( subrec, namerec ); + namerec = NULL; + wins_process_name_registration_request(subrec,p); + return; + } + /* * Check that the group bits for the refreshing name and the * name in our database match. @@ -475,6 +500,16 @@ does not match group bit in WINS for this name.\n", nmb_namestr(question), group * Update the ttl. */ update_name_ttl(namerec, ttl); + + /* + * if the record is a replica: + * we take ownership and update the version ID. + */ + if (!ip_equal(namerec->data.wins_ip, our_fake_ip)) { + update_wins_owner(namerec, our_fake_ip); + get_global_id_and_update(&namerec->data.id, True); + } + send_wins_name_registration_response(0, ttl, p); wins_hook("refresh", namerec, ttl); return; @@ -658,6 +693,7 @@ void wins_process_name_registration_request(struct subnet_record *subrec, struct name_record *namerec = NULL; struct in_addr from_ip; BOOL registering_group_name = (nb_flags & NB_GROUP) ? True : False; + struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); putip((char *)&from_ip,&nmb->additional->rdata[2]); @@ -684,6 +720,18 @@ IP %s\n", registering_group_name ? "Group" : "Unique", nmb_namestr(question), in namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); + /* + * if the record exists but NOT in active state, + * consider it dead. + */ + if ( (namerec != NULL) && !WINS_STATE_ACTIVE(namerec)) + { + DEBUG(5,("wins_process_name_registration_request: Name (%s) in WINS was \ +not active - removing it.\n", nmb_namestr(question) )); + remove_name_from_namelist( subrec, namerec ); + namerec = NULL; + } + /* * Deal with the case where the name found was a dns entry. * Remove it as we now have a NetBIOS client registering the @@ -759,8 +807,22 @@ to register name %s from IP %s.\n", nmb_namestr(question), inet_ntoa(p->ip) )); /* * Check the ip address is not already in the group. */ - if(!find_ip_in_name_record(namerec, from_ip)) + if(!find_ip_in_name_record(namerec, from_ip)) { add_ip_to_name_record(namerec, from_ip); + /* we need to update the record for replication */ + get_global_id_and_update(&namerec->data.id, True); + + /* + * if the record is a replica, we must change + * the wins owner to us to make the replication updates + * it on the other wins servers. + * And when the partner will receive this record, + * it will update its own record. + */ + + update_wins_owner(namerec, our_fake_ip); + + } update_name_ttl(namerec, ttl); send_wins_name_registration_response(0, ttl, p); return; @@ -770,6 +832,8 @@ to register name %s from IP %s.\n", nmb_namestr(question), inet_ntoa(p->ip) )); /* * If we are adding a unique name, the name exists in the WINS db * and is a group name then reject the registration. + * + * explanation: groups have a higher priority than unique names. */ DEBUG(3,("wins_process_name_registration_request: Attempt to register name %s. Name \ @@ -813,13 +877,18 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio /* * If the name exists and it is a unique registration and the registering IP - * is the same as the the (single) already registered IP then just update the ttl. + * is the same as the (single) already registered IP then just update the ttl. + * + * But not if the record is an active replica. IF it's a replica, it means it can be + * the same client which has moved and not yet expired. So we don't update + * the ttl in this case and go beyond to do a WACK and query the old client */ if( !registering_group_name && (namerec != NULL) && (namerec->data.num_ips == 1) - && ip_equal( namerec->data.ip[0], from_ip ) ) + && ip_equal( namerec->data.ip[0], from_ip ) + && ip_equal(namerec->data.wins_ip, our_fake_ip) ) { update_name_ttl( namerec, ttl ); send_wins_name_registration_response( 0, ttl, p ); @@ -880,9 +949,12 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio */ (void)add_name_to_subnet( subrec, question->name, question->name_type, - nb_flags, ttl, REGISTER_NAME, 1, &from_ip ); + nb_flags, ttl, REGISTER_NAME, 1, &from_ip); if ((namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME))) { - wins_hook("add", namerec, ttl); + get_global_id_and_update(&namerec->data.id, True); + update_wins_owner(namerec, our_fake_ip); + update_wins_flag(namerec, WINS_ACTIVE); + wins_hook("add", namerec, ttl); } send_wins_name_registration_response(0, ttl, p); @@ -907,6 +979,7 @@ static void wins_multihomed_register_query_success(struct subnet_record *subrec, struct name_record *namerec = NULL; struct in_addr from_ip; int ttl; + struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *)); @@ -926,7 +999,7 @@ static void wins_multihomed_register_query_success(struct subnet_record *subrec, namerec = find_name_on_subnet(subrec, question_name, FIND_ANY_NAME); - if( (namerec == NULL) || (namerec->data.source != REGISTER_NAME) ) + if( (namerec == NULL) || (namerec->data.source != REGISTER_NAME) || !WINS_STATE_ACTIVE(namerec) ) { DEBUG(3,("wins_multihomed_register_query_success: name %s is not in the correct state to add \ a subsequent IP addess.\n", nmb_namestr(question_name) )); @@ -940,6 +1013,10 @@ a subsequent IP addess.\n", nmb_namestr(question_name) )); if(!find_ip_in_name_record(namerec, from_ip)) add_ip_to_name_record(namerec, from_ip); + + get_global_id_and_update(&namerec->data.id, True); + update_wins_owner(namerec, our_fake_ip); + update_wins_flag(namerec, WINS_ACTIVE); update_name_ttl(namerec, ttl); send_wins_name_registration_response(0, ttl, orig_reg_packet); wins_hook("add", namerec, ttl); @@ -990,7 +1067,8 @@ void wins_process_multihomed_name_registration_request( struct subnet_record *su int ttl = get_ttl_from_packet(nmb); struct name_record *namerec = NULL; struct in_addr from_ip; - BOOL group = (nb_flags & NB_GROUP) ? True : False;; + BOOL group = (nb_flags & NB_GROUP) ? True : False; + struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); putip((char *)&from_ip,&nmb->additional->rdata[2]); @@ -1072,10 +1150,10 @@ to register name %s. Name already exists in WINS with source type %d.\n", } /* - * Reject if the name exists and is a GROUP name. + * Reject if the name exists and is a GROUP name and is active. */ - if((namerec != NULL) && NAME_GROUP(namerec)) + if((namerec != NULL) && NAME_GROUP(namerec) && WINS_STATE_ACTIVE(namerec)) { DEBUG(3,("wins_process_multihomed_name_registration_request: Attempt to register name %s. Name \ already exists in WINS as a GROUP name.\n", nmb_namestr(question) )); @@ -1107,9 +1185,13 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio { /* * It's one of our names and one of our IP's. Ensure the IP is in the record and - * update the ttl. + * update the ttl. Update the version ID to force replication. */ if(!find_ip_in_name_record(namerec, from_ip)) { + get_global_id_and_update(&namerec->data.id, True); + update_wins_owner(namerec, our_fake_ip); + update_wins_flag(namerec, WINS_ACTIVE); + add_ip_to_name_record(namerec, from_ip); wins_hook("add", namerec, ttl); } else { @@ -1123,13 +1205,23 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio } /* - * If the name exists check if the IP address is already registered + * If the name exists and is active, check if the IP address is already registered * to that name. If so then update the ttl and reply success. */ - if((namerec != NULL) && find_ip_in_name_record(namerec, from_ip)) + if((namerec != NULL) && find_ip_in_name_record(namerec, from_ip) && WINS_STATE_ACTIVE(namerec)) { update_name_ttl(namerec, ttl); + /* + * If it's a replica, we need to become the wins owner + * to force the replication + */ + if (!ip_equal(namerec->data.wins_ip, our_fake_ip)) { + get_global_id_and_update(&namerec->data.id, True); + update_wins_owner(namerec, our_fake_ip); + update_wins_flag(namerec, WINS_ACTIVE); + } + send_wins_name_registration_response(0, ttl, p); wins_hook("refresh", namerec, ttl); return; @@ -1192,9 +1284,12 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio */ (void)add_name_to_subnet( subrec, question->name, question->name_type, - nb_flags, ttl, REGISTER_NAME, 1, &from_ip ); + nb_flags, ttl, REGISTER_NAME, 1, &from_ip); if ((namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME))) { + get_global_id_and_update(&namerec->data.id, True); + update_wins_owner(namerec, our_fake_ip); + update_wins_flag(namerec, WINS_ACTIVE); wins_hook("add", namerec, ttl); } @@ -1213,7 +1308,7 @@ static void process_wins_dmb_query_request(struct subnet_record *subrec, int num_ips; /* - * Go through all the names in the WINS db looking for those + * Go through all the ACTIVE names in the WINS db looking for those * ending in <1b>. Use this to calculate the number of IP * addresses we need to return. */ @@ -1223,7 +1318,7 @@ static void process_wins_dmb_query_request(struct subnet_record *subrec, namerec; namerec = (struct name_record *)ubi_trNext( namerec ) ) { - if( namerec->name.name_type == 0x1b ) + if(WINS_STATE_ACTIVE(namerec) && namerec->name.name_type == 0x1b ) num_ips += namerec->data.num_ips; } @@ -1253,7 +1348,7 @@ static void process_wins_dmb_query_request(struct subnet_record *subrec, namerec; namerec = (struct name_record *)ubi_trNext( namerec ) ) { - if(namerec->name.name_type == 0x1b) + if(WINS_STATE_ACTIVE(namerec) && namerec->name.name_type == 0x1b) { int i; for(i = 0; i < namerec->data.num_ips; i++) @@ -1369,6 +1464,17 @@ void wins_process_name_query_request(struct subnet_record *subrec, if(namerec != NULL) { + /* + * If the name is not anymore in active state then reply not found. + * it's fair even if we keep it in the cache for days. + */ + if (!WINS_STATE_ACTIVE(namerec)) + { + DEBUG(3,("wins_process_name_query: name query for name %s - name expired. Returning fail.\n", + nmb_namestr(question) )); + send_wins_name_query_response(NAM_ERR, p, namerec); + return; + } /* * If it's a DNSFAIL_NAME then reply name not found. */ @@ -1528,21 +1634,29 @@ release name %s as IP %s is not one of the known IP's for this name.\n", return; } + /* + * Check if the record is active. IF it's already released + * or tombstoned, refuse the release. + */ + if (!WINS_STATE_ACTIVE(namerec)) { + DEBUG(3,("wins_process_name_release_request: Refusing request to \ +release name %s as this record is not anymore active.\n", + nmb_namestr(question) )); + send_wins_name_release_response(NAM_ERR, p); + return; + } + /* - * Release the name and then remove the IP from the known list. + * Send a release response. + * Flag the name as released and update the ttl */ send_wins_name_release_response(0, p); - remove_ip_from_name_record(namerec, from_ip); + + namerec->data.wins_flags |= WINS_RELEASED; + update_name_ttl(namerec, EXTINCTION_INTERVAL); wins_hook("delete", namerec, 0); - - /* - * Remove the name entirely if no IP addresses left. - */ - if (namerec->data.num_ips == 0) - remove_name_from_namelist(subrec, namerec); - } /******************************************************************* @@ -1551,24 +1665,84 @@ release name %s as IP %s is not one of the known IP's for this name.\n", void initiate_wins_processing(time_t t) { - static time_t lasttime = 0; - - if (!lasttime) - lasttime = t; - if (t - lasttime < 20) - return; + static time_t lasttime = 0; + struct name_record *namerec; + struct name_record *next_namerec; + struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); + + if (!lasttime) + lasttime = t; + if (t - lasttime < 20) + return; + + lasttime = t; + + if(!lp_we_are_a_wins_server()) + return; + + for( namerec = (struct name_record *)ubi_trFirst( wins_server_subnet->namelist ); + namerec; + namerec = next_namerec ) { + next_namerec = (struct name_record *)ubi_trNext( namerec ); + + if( (namerec->data.death_time != PERMANENT_TTL) + && (namerec->data.death_time < t) ) { + + if( namerec->data.source == SELF_NAME ) { + DEBUG( 3, ( "expire_names_on_subnet: Subnet %s not expiring SELF name %s\n", + wins_server_subnet->subnet_name, nmb_namestr(&namerec->name) ) ); + namerec->data.death_time += 300; + namerec->subnet->namelist_changed = True; + continue; + } + + /* handle records, samba is the wins owner */ + if (ip_equal(namerec->data.wins_ip, our_fake_ip)) { + switch (namerec->data.wins_flags | WINS_STATE_MASK) { + case WINS_ACTIVE: + namerec->data.wins_flags&=~WINS_STATE_MASK; + namerec->data.wins_flags|=WINS_RELEASED; + namerec->data.death_time = t + EXTINCTION_INTERVAL; + DEBUG(3,("initiate_wins_processing: expiring %s\n", nmb_namestr(&namerec->name))); + break; + case WINS_RELEASED: + namerec->data.wins_flags&=~WINS_STATE_MASK; + namerec->data.wins_flags|=WINS_TOMBSTONED; + namerec->data.death_time = t + EXTINCTION_TIMEOUT; + get_global_id_and_update(&namerec->data.id, True); + DEBUG(3,("initiate_wins_processing: tombstoning %s\n", nmb_namestr(&namerec->name))); + break; + case WINS_TOMBSTONED: + DEBUG(3,("initiate_wins_processing: deleting %s\n", nmb_namestr(&namerec->name))); + remove_name_from_namelist( wins_server_subnet, namerec ); + break; + } + } else { + switch (namerec->data.wins_flags | WINS_STATE_MASK) { + case WINS_ACTIVE: + /* that's not as MS says it should be */ + namerec->data.wins_flags&=~WINS_STATE_MASK; + namerec->data.wins_flags|=WINS_TOMBSTONED; + namerec->data.death_time = t + EXTINCTION_TIMEOUT; + DEBUG(3,("initiate_wins_processing: tombstoning %s\n", nmb_namestr(&namerec->name))); + case WINS_TOMBSTONED: + DEBUG(3,("initiate_wins_processing: deleting %s\n", nmb_namestr(&namerec->name))); + remove_name_from_namelist( wins_server_subnet, namerec ); + break; + case WINS_RELEASED: + DEBUG(0,("initiate_wins_processing: %s is in released state and\ +we are not the wins owner !\n", nmb_namestr(&namerec->name))); + break; + } + } - lasttime = t; - - if(!lp_we_are_a_wins_server()) - return; - - expire_names_on_subnet(wins_server_subnet, t); + } + } - if(wins_server_subnet->namelist_changed) - wins_write_database(True); + if(wins_server_subnet->namelist_changed) + wins_write_database(True); - wins_server_subnet->namelist_changed = False; + wins_server_subnet->namelist_changed = False; } /******************************************************************* @@ -1576,84 +1750,268 @@ void initiate_wins_processing(time_t t) ******************************************************************/ void wins_write_database(BOOL background) { - struct name_record *namerec; - pstring fname, fnamenew; - XFILE *fp; - - if(!lp_we_are_a_wins_server()) - return; + struct name_record *namerec; + pstring fname, fnamenew; + TDB_CONTEXT *tdb; + TDB_DATA kbuf, dbuf; + pstring key, buf; + int len; + int num_record=0; + SMB_BIG_UINT id; + + if(!lp_we_are_a_wins_server()) + return; + + /* we will do the writing in a child process to ensure that the parent + doesn't block while this is done */ + if (background) { + CatchChild(); + if (sys_fork()) { + return; + } + } - /* we will do the writing in a child process to ensure that the parent - doesn't block while this is done */ - if (background) { - CatchChild(); - if (sys_fork()) { - return; - } - } + slprintf(fname,sizeof(fname)-1,"%s/%s", lp_lockdir(), WINS_LIST); + all_string_sub(fname,"//", "/", 0); + slprintf(fnamenew,sizeof(fnamenew)-1,"%s.%u", fname, (unsigned int)sys_getpid()); - slprintf(fname,sizeof(fname)-1,"%s/%s", lp_lockdir(), WINS_LIST); - all_string_sub(fname,"//", "/", 0); - slprintf(fnamenew,sizeof(fnamenew)-1,"%s.%u", fname, (unsigned int)sys_getpid()); + tdb = tdb_open_log(fnamenew, 0, TDB_DEFAULT, O_RDWR|O_CREAT|O_TRUNC, 0644); + if (!tdb) { + DEBUG(0,("wins_write_database: Can't open %s. Error was %s\n", fnamenew, strerror(errno))); + if (background) + _exit(0); + return; + } - if((fp = x_fopen(fnamenew,O_WRONLY|O_CREAT|O_TRUNC, 0644)) == NULL) - { - DEBUG(0,("wins_write_database: Can't open %s. Error was %s\n", fnamenew, strerror(errno))); - if (background) { - _exit(0); - } - return; - } + DEBUG(3,("wins_write_database: Dump of WINS name list.\n")); - DEBUG(4,("wins_write_database: Dump of WINS name list.\n")); + tdb_store_int(tdb, INFO_VERSION, WINS_VERSION); - x_fprintf(fp,"VERSION %d %u\n", WINS_VERSION, wins_hash()); - - for( namerec - = (struct name_record *)ubi_trFirst( wins_server_subnet->namelist ); - namerec; - namerec = (struct name_record *)ubi_trNext( namerec ) ) - { - int i; - struct tm *tm; + for (namerec = (struct name_record *)ubi_trFirst( wins_server_subnet->namelist ); + namerec; + namerec = (struct name_record *)ubi_trNext( namerec ) ) { - DEBUGADD(4,("%-19s ", nmb_namestr(&namerec->name) )); + int i; + struct tm *tm; - if( namerec->data.death_time != PERMANENT_TTL ) - { - char *ts, *nl; - - tm = LocalTime(&namerec->data.death_time); - ts = asctime(tm); - nl = strrchr_m( ts, '\n' ); - if( NULL != nl ) - *nl = '\0'; - DEBUGADD(4,("TTL = %s ", ts )); - } - else - DEBUGADD(4,("TTL = PERMANENT ")); + DEBUGADD(3,("%-19s ", nmb_namestr(&namerec->name) )); - for (i = 0; i < namerec->data.num_ips; i++) - DEBUGADD(4,("%15s ", inet_ntoa(namerec->data.ip[i]) )); - DEBUGADD(4,("%2x\n", namerec->data.nb_flags )); + if( namerec->data.death_time != PERMANENT_TTL ) { + char *ts, *nl; - if( namerec->data.source == REGISTER_NAME ) - { - x_fprintf(fp, "\"%s#%02x\" %d ", - namerec->name.name,namerec->name.name_type, /* Ignore scope. */ - (int)namerec->data.death_time); + tm = LocalTime(&namerec->data.death_time); + ts = asctime(tm); + nl = strrchr_m( ts, '\n' ); + if( NULL != nl ) + *nl = '\0'; - for (i = 0; i < namerec->data.num_ips; i++) - x_fprintf( fp, "%s ", inet_ntoa( namerec->data.ip[i] ) ); - x_fprintf( fp, "%2xR\n", namerec->data.nb_flags ); - } - } - - x_fclose(fp); - chmod(fnamenew,0644); - unlink(fname); - rename(fnamenew,fname); - if (background) { - _exit(0); - } + DEBUGADD(3,("TTL = %s ", ts )); + } else + DEBUGADD(3,("TTL = PERMANENT ")); + + for (i = 0; i < namerec->data.num_ips; i++) + DEBUGADD(0,("%15s ", inet_ntoa(namerec->data.ip[i]) )); + + DEBUGADD(3,("0x%2x 0x%2x %15s\n", namerec->data.nb_flags, namerec->data.wins_flags, inet_ntoa(namerec->data.wins_ip))); + + if( namerec->data.source == REGISTER_NAME ) { + + /* store the type in the key to make the name unique */ + slprintf(key, sizeof(key), "%s%s#%02x", ENTRY_PREFIX, namerec->name.name, namerec->name.name_type); + + len = tdb_pack(buf, sizeof(buf), "dddfddd", + (int)namerec->data.nb_flags, + (int)(namerec->data.id>>32), + (int)(namerec->data.id&0xffffffff), + inet_ntoa(namerec->data.wins_ip), + (int)namerec->data.death_time, + namerec->data.num_ips, + namerec->data.wins_flags); + + for (i = 0; i < namerec->data.num_ips; i++) + len += tdb_pack(buf+len, sizeof(buf)-len, "f", inet_ntoa(namerec->data.ip[i])); + + kbuf.dsize = strlen(key)+1; + kbuf.dptr = key; + dbuf.dsize = len; + dbuf.dptr = buf; + if (tdb_store(tdb, kbuf, dbuf, TDB_INSERT) != 0) return; + + num_record++; + } + } + + /* store the number of records */ + tdb_store_int(tdb, INFO_COUNT, num_record); + + /* get and store the last used ID */ + get_global_id_and_update(&id, False); + tdb_store_int(tdb, INFO_ID_HIGH, id>>32); + tdb_store_int(tdb, INFO_ID_LOW, id&0xffffffff); + + tdb_close(tdb); + + chmod(fnamenew,0644); + unlink(fname); + rename(fnamenew,fname); + + if (background) + _exit(0); +} + +/**************************************************************************** +process a internal Samba message receiving a wins record +***************************************************************************/ +void nmbd_wins_new_entry(int msg_type, pid_t src, void *buf, size_t len) +{ + WINS_RECORD *record; + struct name_record *namerec = NULL; + struct name_record *new_namerec = NULL; + struct nmb_name question; + BOOL overwrite=False; + struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); + int i; + + if (buf==NULL) + return; + + record=(WINS_RECORD *)buf; + + ZERO_STRUCT(question); + memcpy(question.name, record->name, 16); + question.name_type=record->type; + + namerec = find_name_on_subnet(wins_server_subnet, &question, FIND_ANY_NAME); + + /* record doesn't exist, add it */ + if (namerec == NULL) { + DEBUG(3,("nmbd_wins_new_entry: adding new replicated record: %s<%02x> for wins server: %s\n", + record->name, record->type, inet_ntoa(record->wins_ip))); + + new_namerec=add_name_to_subnet( wins_server_subnet, record->name, record->type, record->nb_flags, + EXTINCTION_INTERVAL, REGISTER_NAME, record->num_ips, record->ip); + if (new_namerec!=NULL) { + update_wins_owner(new_namerec, record->wins_ip); + update_wins_flag(new_namerec, record->wins_flags); + new_namerec->data.id=record->id; + + wins_server_subnet->namelist_changed = True; + } + } + + /* check if we have a conflict */ + if (namerec != NULL) { + /* both records are UNIQUE */ + if (namerec->data.wins_flags&WINS_UNIQUE && record->wins_flags&WINS_UNIQUE) { + + /* the database record is a replica */ + if (!ip_equal(namerec->data.wins_ip, our_fake_ip)) { + if (namerec->data.wins_flags&WINS_ACTIVE && record->wins_flags&WINS_TOMBSTONED) { + if (ip_equal(namerec->data.wins_ip, record->wins_ip)) + overwrite=True; + } else + overwrite=True; + } else { + /* we are the wins owner of the database record */ + /* the 2 records have the same IP address */ + if (ip_equal(namerec->data.ip[0], record->ip[0])) { + if (namerec->data.wins_flags&WINS_ACTIVE && record->wins_flags&WINS_TOMBSTONED) + get_global_id_and_update(&namerec->data.id, True); + else + overwrite=True; + + } else { + /* the 2 records have different IP address */ + if (namerec->data.wins_flags&WINS_ACTIVE) { + if (record->wins_flags&WINS_TOMBSTONED) + get_global_id_and_update(&namerec->data.id, True); + if (record->wins_flags&WINS_ACTIVE) + /* send conflict challenge to the replica node */ + ; + } else + overwrite=True; + } + + } + } + + /* the replica is a standard group */ + if (record->wins_flags&WINS_NGROUP || record->wins_flags&WINS_SGROUP) { + /* if the database record is unique and active force a name release */ + if (namerec->data.wins_flags&WINS_UNIQUE) + /* send a release name to the unique node */ + ; + overwrite=True; + + } + + /* the replica is a special group */ + if (record->wins_flags&WINS_SGROUP && namerec->data.wins_flags&WINS_SGROUP) { + if (namerec->data.wins_flags&WINS_ACTIVE) { + for (i=0; inum_ips; i++) + if(!find_ip_in_name_record(namerec, record->ip[i])) + add_ip_to_name_record(namerec, record->ip[i]); + } + else + overwrite=True; + } + + /* the replica is a multihomed host */ + + /* I'm giving up on multi homed. Too much complex to understand */ + + if (record->wins_flags&WINS_MHOMED) { + if (! namerec->data.wins_flags&WINS_ACTIVE) { + if ( !namerec->data.wins_flags&WINS_RELEASED && !namerec->data.wins_flags&WINS_NGROUP) + overwrite=True; + } + else { + if (ip_equal(record->wins_ip, namerec->data.wins_ip)) + overwrite=True; + + if (ip_equal(namerec->data.wins_ip, our_fake_ip)) + if (namerec->data.wins_flags&WINS_UNIQUE) + get_global_id_and_update(&namerec->data.id, True); + + } + + if (record->wins_flags&WINS_ACTIVE && namerec->data.wins_flags&WINS_ACTIVE) + if (namerec->data.wins_flags&WINS_UNIQUE || + namerec->data.wins_flags&WINS_MHOMED) + if (ip_equal(record->wins_ip, namerec->data.wins_ip)) + overwrite=True; + + } + + if (overwrite == False) + DEBUG(3, ("nmbd_wins_new_entry: conflict in adding record: %s<%02x> from wins server: %s\n", + record->name, record->type, inet_ntoa(record->wins_ip))); + else { + DEBUG(3, ("nmbd_wins_new_entry: replacing record: %s<%02x> from wins server: %s\n", + record->name, record->type, inet_ntoa(record->wins_ip))); + + /* remove the old record and add a new one */ + remove_name_from_namelist( wins_server_subnet, namerec ); + new_namerec=add_name_to_subnet( wins_server_subnet, record->name, record->type, record->nb_flags, + EXTINCTION_INTERVAL, REGISTER_NAME, record->num_ips, record->ip); + if (new_namerec!=NULL) { + update_wins_owner(new_namerec, record->wins_ip); + update_wins_flag(new_namerec, record->wins_flags); + new_namerec->data.id=record->id; + + wins_server_subnet->namelist_changed = True; + } + + wins_server_subnet->namelist_changed = True; + } + + } } + + + + + + + + -- cgit From cd68afe31256ad60748b34f7318a180cfc2127cc Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Wed, 30 Jan 2002 06:08:46 +0000 Subject: Removed version number from file header. Changed "SMB/Netbios" to "SMB/CIFS" in file header. (This used to be commit 6a58c9bd06d0d7502a24bf5ce5a2faf0a146edfa) --- source3/nmbd/asyncdns.c | 2 +- source3/nmbd/nmbd.c | 2 +- source3/nmbd/nmbd_become_dmb.c | 3 +-- source3/nmbd/nmbd_become_lmb.c | 3 +-- source3/nmbd/nmbd_browserdb.c | 3 +-- source3/nmbd/nmbd_browsesync.c | 3 +-- source3/nmbd/nmbd_elections.c | 3 +-- source3/nmbd/nmbd_incomingdgrams.c | 3 +-- source3/nmbd/nmbd_incomingrequests.c | 3 +-- source3/nmbd/nmbd_lmhosts.c | 3 +-- source3/nmbd/nmbd_logonnames.c | 3 +-- source3/nmbd/nmbd_mynames.c | 3 +-- source3/nmbd/nmbd_namelistdb.c | 3 +-- source3/nmbd/nmbd_namequery.c | 3 +-- source3/nmbd/nmbd_nameregister.c | 3 +-- source3/nmbd/nmbd_namerelease.c | 3 +-- source3/nmbd/nmbd_nodestatus.c | 3 +-- source3/nmbd/nmbd_packets.c | 3 +-- source3/nmbd/nmbd_processlogon.c | 3 +-- source3/nmbd/nmbd_responserecordsdb.c | 3 +-- source3/nmbd/nmbd_sendannounce.c | 3 +-- source3/nmbd/nmbd_serverlistdb.c | 3 +-- source3/nmbd/nmbd_subnetdb.c | 3 +-- source3/nmbd/nmbd_synclists.c | 3 +-- source3/nmbd/nmbd_winsproxy.c | 3 +-- source3/nmbd/nmbd_winsserver.c | 3 +-- source3/nmbd/nmbd_workgroupdb.c | 3 +-- 27 files changed, 27 insertions(+), 52 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 5ae2eb202d..c5ff718836 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -1,5 +1,5 @@ /* - Unix SMB/Netbios implementation. + Unix SMB/CIFS implementation. a async DNS handler Copyright (C) Andrew Tridgell 1997-1998 diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index a7abdc5da0..9ed8dd92b6 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -1,5 +1,5 @@ /* - Unix SMB/Netbios implementation. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index d62607a643..7f4a7a2144 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index 52955d9bfc..3e0884567e 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c index cbf871a700..a4ef98e265 100644 --- a/source3/nmbd/nmbd_browserdb.c +++ b/source3/nmbd/nmbd_browserdb.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 40e04e7ecb..5dcc8cce19 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index ae22518495..acff7a72e8 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index d10e6ec0b0..261200b4c5 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index 81e6bb9629..3f2b921074 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 diff --git a/source3/nmbd/nmbd_lmhosts.c b/source3/nmbd/nmbd_lmhosts.c index 4d819b41e9..3c067d8ed4 100644 --- a/source3/nmbd/nmbd_lmhosts.c +++ b/source3/nmbd/nmbd_lmhosts.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Jeremy Allison 1994-1998 diff --git a/source3/nmbd/nmbd_logonnames.c b/source3/nmbd/nmbd_logonnames.c index 52340f1f31..1406515d6b 100644 --- a/source3/nmbd/nmbd_logonnames.c +++ b/source3/nmbd/nmbd_logonnames.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index b1b3f48b62..a3311fec47 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index fba56ef49f..68b44d618f 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index 9d2a7a4895..aeb9984180 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index c3361cec60..cbc72fe2a9 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 diff --git a/source3/nmbd/nmbd_namerelease.c b/source3/nmbd/nmbd_namerelease.c index 30a9d16561..fd35181f33 100644 --- a/source3/nmbd/nmbd_namerelease.c +++ b/source3/nmbd/nmbd_namerelease.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 diff --git a/source3/nmbd/nmbd_nodestatus.c b/source3/nmbd/nmbd_nodestatus.c index eeb532d410..993e4d9d17 100644 --- a/source3/nmbd/nmbd_nodestatus.c +++ b/source3/nmbd/nmbd_nodestatus.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index a81da0ca9b..6e5487ae44 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index b348250f86..23e4f935ca 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index 63601ff26c..a2da5ddf4a 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios library routines Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index ee3b3d110f..d4a7070042 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index fd1d8e51ba..a315d80afe 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 3b450f6712..6c6e7adbb8 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index f6d1165e57..bf03d4d1cf 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index 8410228958..2e65ebb612 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Jeremy Allison 1994-1998 diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index d732da62cf..d274f6d3d3 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Jeremy Allison 1994-1998 diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 4551eaf46b..d1cfc24a31 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -1,6 +1,5 @@ /* - Unix SMB/Netbios implementation. - Version 1.9. + Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 -- cgit From 69adbb0ce3bb9d5bd569c13aaa3ac8f390c1586a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 31 Jan 2002 23:26:12 +0000 Subject: Fix from Michael Steffens to make signal processing work correctly in winbindd. This is a really good patch that gives full select semantics to the Samba modified select. Jeremy. (This used to be commit 3af16ade173cac24c1ac5eff4a36b439f16ac036) --- source3/nmbd/nmbd_packets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 6e5487ae44..a11b30b1dc 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1817,7 +1817,7 @@ BOOL listen_for_packets(BOOL run_election) BlockSignals(False, SIGTERM); - selrtn = sys_select(FD_SETSIZE,&fds,&timeout); + selrtn = sys_select(FD_SETSIZE,&fds,NULL,NULL,&timeout); /* We can only take signals when we are in the select - block them again here. */ -- cgit From a93740935fb93f55b98847ff41a4bf7e9b5d1320 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 1 Mar 2002 02:57:52 +0000 Subject: Cause nmbd to take signal processing in-band, rather than in signal handlers. THIS NEEDS TESTING ! Jeremy. (This used to be commit 166d2a6144f929baecd83bdd855f6ada06cb51a6) --- source3/nmbd/nmbd.c | 707 +++++++++++++++++++++++++++------------------------- 1 file changed, 368 insertions(+), 339 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 9ed8dd92b6..62e3f1757b 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -2,6 +2,7 @@ Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 + Copyright (C) Jeremy Allison 1997-2002 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -17,11 +18,6 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - Revision History: - - 14 jan 96: lkcl@pires.co.uk - added multiple workgroup domain master support - */ #include "includes.h" @@ -47,136 +43,140 @@ BOOL found_lm_clients = False; time_t StartupTime = 0; /**************************************************************************** ** - catch a sigterm + Handle a SIGTERM in band. **************************************************************************** */ -static void sig_term(int sig) + +static void terminate(void) { - BlockSignals(True,SIGTERM); - - DEBUG(0,("Got SIGTERM: going down...\n")); + DEBUG(0,("Got SIGTERM: going down...\n")); - /* Write out wins.dat file if samba is a WINS server */ - wins_write_database(False); + /* Write out wins.dat file if samba is a WINS server */ + wins_write_database(False); - /* Remove all SELF registered names. */ - release_my_names(); + /* Remove all SELF registered names. */ + release_my_names(); - /* Announce all server entries as 0 time-to-live, 0 type. */ - announce_my_servers_removed(); - - /* If there was an async dns child - kill it. */ - kill_async_dns_child(); + /* Announce all server entries as 0 time-to-live, 0 type. */ + announce_my_servers_removed(); - exit(0); + /* If there was an async dns child - kill it. */ + kill_async_dns_child(); -} /* sig_term */ + exit(0); +} /**************************************************************************** ** - catch a sighup + Catch a SIGTERM signal. **************************************************************************** */ -static VOLATILE sig_atomic_t reload_after_sighup = False; - -static void sig_hup(int sig) -{ - BlockSignals( True, SIGHUP ); - - DEBUG( 0, ( "Got SIGHUP dumping debug info.\n" ) ); - write_browse_list( 0, True ); +static VOLATILE sig_atomic_t got_sig_term; - dump_all_namelists(); - - reload_after_sighup = True; +static void sig_term(int sig) +{ + got_sig_term = 1; + sys_select_signal(); +} - BlockSignals(False,SIGHUP); +/**************************************************************************** ** + Catch a SIGHUP signal. + **************************************************************************** */ -} /* sig_hup */ +static VOLATILE sig_atomic_t reload_after_sighup; +static void sig_hup(int sig) +{ + reload_after_sighup = 1; + sys_select_signal(); +} #if DUMP_CORE /**************************************************************************** ** - prepare to dump a core file - carefully! + Prepare to dump a core file - carefully! **************************************************************************** */ + static BOOL dump_core(void) { - char *p; - pstring dname; - pstrcpy( dname, lp_logfile() ); - if ((p=strrchr_m(dname,'/'))) - *p=0; - pstrcat( dname, "/corefiles" ); - mkdir( dname, 0700 ); - sys_chown( dname, getuid(), getgid() ); - chmod( dname, 0700 ); - if ( chdir(dname) ) - return( False ); - umask( ~(0700) ); + char *p; + pstring dname; + pstrcpy( dname, lp_logfile() ); + if ((p=strrchr_m(dname,'/'))) + *p=0; + pstrcat( dname, "/corefiles" ); + mkdir( dname, 0700 ); + sys_chown( dname, getuid(), getgid() ); + chmod( dname, 0700 ); + if ( chdir(dname) ) + return( False ); + umask( ~(0700) ); #ifdef HAVE_GETRLIMIT #ifdef RLIMIT_CORE - { - struct rlimit rlp; - getrlimit( RLIMIT_CORE, &rlp ); - rlp.rlim_cur = MAX( 4*1024*1024, rlp.rlim_cur ); - setrlimit( RLIMIT_CORE, &rlp ); - getrlimit( RLIMIT_CORE, &rlp ); - DEBUG( 3, ( "Core limits now %d %d\n", (int)rlp.rlim_cur, (int)rlp.rlim_max ) ); - } + { + struct rlimit rlp; + getrlimit( RLIMIT_CORE, &rlp ); + rlp.rlim_cur = MAX( 4*1024*1024, rlp.rlim_cur ); + setrlimit( RLIMIT_CORE, &rlp ); + getrlimit( RLIMIT_CORE, &rlp ); + DEBUG( 3, ( "Core limits now %d %d\n", (int)rlp.rlim_cur, (int)rlp.rlim_max ) ); + } #endif #endif - DEBUG(0,("Dumping core in %s\n",dname)); - abort(); - return( True ); -} /* dump_core */ + DEBUG(0,("Dumping core in %s\n",dname)); + abort(); + return( True ); +} #endif - /**************************************************************************** ** - possibly continue after a fault + Possibly continue after a fault. **************************************************************************** */ + static void fault_continue(void) { #if DUMP_CORE - dump_core(); + dump_core(); #endif -} /* fault_continue */ +} /**************************************************************************** ** - expire old names from the namelist and server list + Expire old names from the namelist and server list. **************************************************************************** */ + static void expire_names_and_servers(time_t t) { - static time_t lastrun = 0; + static time_t lastrun = 0; - if ( !lastrun ) - lastrun = t; - if ( t < (lastrun + 5) ) - return; - lastrun = t; + if ( !lastrun ) + lastrun = t; + if ( t < (lastrun + 5) ) + return; + lastrun = t; - /* - * Expire any timed out names on all the broadcast - * subnets and those registered with the WINS server. - * (nmbd_namelistdb.c) - */ - expire_names(t); + /* + * Expire any timed out names on all the broadcast + * subnets and those registered with the WINS server. + * (nmbd_namelistdb.c) + */ - /* - * Go through all the broadcast subnets and for each - * workgroup known on that subnet remove any expired - * server names. If a workgroup has an empty serverlist - * and has itself timed out then remove the workgroup. - * (nmbd_workgroupdb.c) - */ - expire_workgroups_and_servers(t); -} /* expire_names_and_servers */ + expire_names(t); + /* + * Go through all the broadcast subnets and for each + * workgroup known on that subnet remove any expired + * server names. If a workgroup has an empty serverlist + * and has itself timed out then remove the workgroup. + * (nmbd_workgroupdb.c) + */ + + expire_workgroups_and_servers(t); +} /************************************************************************** ** -reload the list of network interfaces + Reload the list of network interfaces. ************************************************************************** */ + static BOOL reload_interfaces(time_t t) { static time_t lastt; @@ -253,293 +253,321 @@ static BOOL reload_interfaces(time_t t) return False; } - - /**************************************************************************** ** - reload the services file + Reload the services file. **************************************************************************** */ + static BOOL reload_nmbd_services(BOOL test) { - BOOL ret; - extern fstring remote_machine; + BOOL ret; + extern fstring remote_machine; - fstrcpy( remote_machine, "nmbd" ); + fstrcpy( remote_machine, "nmbd" ); - if ( lp_loaded() ) - { - pstring fname; - pstrcpy( fname,lp_configfile()); - if (file_exist(fname,NULL) && !strcsequal(fname,dyn_CONFIGFILE)) - { - pstrcpy(dyn_CONFIGFILE,fname); - test = False; - } - } + if ( lp_loaded() ) { + pstring fname; + pstrcpy( fname,lp_configfile()); + if (file_exist(fname,NULL) && !strcsequal(fname,dyn_CONFIGFILE)) { + pstrcpy(dyn_CONFIGFILE,fname); + test = False; + } + } - if ( test && !lp_file_list_changed() ) - return(True); + if ( test && !lp_file_list_changed() ) + return(True); - ret = lp_load( dyn_CONFIGFILE, True , False, False); + ret = lp_load( dyn_CONFIGFILE, True , False, False); - /* perhaps the config filename is now set */ - if ( !test ) - { - DEBUG( 3, ( "services not loaded\n" ) ); - reload_nmbd_services( True ); - } + /* perhaps the config filename is now set */ + if ( !test ) { + DEBUG( 3, ( "services not loaded\n" ) ); + reload_nmbd_services( True ); + } - /* Do a sanity check for a misconfigured nmbd */ - if( lp_wins_support() && wins_srv_count() ) - { - if( DEBUGLVL(0) ) - { - dbgtext( "ERROR: 'wins support = true' and 'wins server = '\n" ); - dbgtext( "are conflicting settings. nmbd aborting.\n" ); - } - exit(10); - } + /* Do a sanity check for a misconfigured nmbd */ + if( lp_wins_support() && wins_srv_count() ) { + if( DEBUGLVL(0) ) { + dbgtext( "ERROR: 'wins support = true' and 'wins server = '\n" ); + dbgtext( "are conflicting settings. nmbd aborting.\n" ); + } + exit(10); + } - return(ret); -} /* reload_nmbd_services */ + return(ret); +} /**************************************************************************** ** The main select loop. **************************************************************************** */ + static void process(void) { - BOOL run_election; + BOOL run_election; - while( True ) - { - time_t t = time(NULL); - - /* check for internal messages */ - message_dispatch(); - - /* - * Check all broadcast subnets to see if - * we need to run an election on any of them. - * (nmbd_elections.c) - */ - run_election = check_elections(); - - /* - * Read incoming UDP packets. - * (nmbd_packets.c) - */ - if(listen_for_packets(run_election)) - return; - - /* - * Process all incoming packets - * read above. This calls the success and - * failure functions registered when response - * packets arrrive, and also deals with request - * packets from other sources. - * (nmbd_packets.c) - */ - run_packet_queue(); - - /* - * Run any elections - initiate becoming - * a local master browser if we have won. - * (nmbd_elections.c) - */ - run_elections(t); - - /* - * Send out any broadcast announcements - * of our server names. This also announces - * the workgroup name if we are a local - * master browser. - * (nmbd_sendannounce.c) - */ - announce_my_server_names(t); - - /* - * Send out any LanMan broadcast announcements - * of our server names. - * (nmbd_sendannounce.c) - */ - announce_my_lm_server_names(t); - - /* - * If we are a local master browser, periodically - * announce ourselves to the domain master browser. - * This also deals with syncronising the domain master - * browser server lists with ourselves as a local - * master browser. - * (nmbd_sendannounce.c) - */ - announce_myself_to_domain_master_browser(t); - - /* - * Fullfill any remote announce requests. - * (nmbd_sendannounce.c) - */ - announce_remote(t); - - /* - * Fullfill any remote browse sync announce requests. - * (nmbd_sendannounce.c) - */ - browse_sync_remote(t); - - /* - * Scan the broadcast subnets, and WINS client - * namelists and refresh any that need refreshing. - * (nmbd_mynames.c) - */ - refresh_my_names(t); - - /* - * Scan the subnet namelists and server lists and - * expire thos that have timed out. - * (nmbd.c) - */ - expire_names_and_servers(t); - - /* - * Write out a snapshot of our current browse list into - * the browse.dat file. This is used by smbd to service - * incoming NetServerEnum calls - used to synchronise - * browse lists over subnets. - * (nmbd_serverlistdb.c) - */ - write_browse_list(t, False); - - /* - * If we are a domain master browser, we have a list of - * local master browsers we should synchronise browse - * lists with (these are added by an incoming local - * master browser announcement packet). Expire any of - * these that are no longer current, and pull the server - * lists from each of these known local master browsers. - * (nmbd_browsesync.c) - */ - dmb_expire_and_sync_browser_lists(t); - - /* - * Check that there is a local master browser for our - * workgroup for all our broadcast subnets. If one - * is not found, start an election (which we ourselves - * may or may not participate in, depending on the - * setting of the 'local master' parameter. - * (nmbd_elections.c) - */ - check_master_browser_exists(t); - - /* - * If we are configured as a logon server, attempt to - * register the special NetBIOS names to become such - * (WORKGROUP<1c> name) on all broadcast subnets and - * with the WINS server (if used). If we are configured - * to become a domain master browser, attempt to register - * the special NetBIOS name (WORKGROUP<1b> name) to - * become such. - * (nmbd_become_dmb.c) - */ - add_domain_names(t); - - /* - * If we are a WINS server, do any timer dependent - * processing required. - * (nmbd_winsserver.c) - */ - initiate_wins_processing(t); - - /* - * If we are a domain master browser, attempt to contact the - * WINS server to get a list of all known WORKGROUPS/DOMAINS. - * This will only work to a Samba WINS server. - * (nmbd_browsesync.c) - */ - if (lp_enhanced_browsing()) { - collect_all_workgroup_names_from_wins_server(t); - } + while( True ) { + time_t t = time(NULL); - /* - * Go through the response record queue and time out or re-transmit - * and expired entries. - * (nmbd_packets.c) - */ - retransmit_or_expire_response_records(t); - - /* - * check to see if any remote browse sync child processes have completed - */ - sync_check_completion(); - - /* - * regularly sync with any other DMBs we know about - */ - if (lp_enhanced_browsing()) { - sync_all_dmbs(t); - } + /* Check for internal messages */ + + message_dispatch(); + + /* + * Check all broadcast subnets to see if + * we need to run an election on any of them. + * (nmbd_elections.c) + */ - /* - * clear the unexpected packet queue - */ - clear_unexpected(t); + run_election = check_elections(); - /* - * Reload the services file if we got a sighup. - */ + /* + * Read incoming UDP packets. + * (nmbd_packets.c) + */ - if(reload_after_sighup) { - reload_nmbd_services( True ); - reopen_logs(); - if(reload_interfaces(0)) + if(listen_for_packets(run_election)) return; - reload_after_sighup = False; - } - /* check for new network interfaces */ - if(reload_interfaces(t)) - return; + /* + * Handle termination inband. + */ - /* free up temp memory */ - lp_talloc_free(); - } -} /* process */ + if (got_sig_term) { + got_sig_term = 0; + terminate(); + } + + /* + * Process all incoming packets + * read above. This calls the success and + * failure functions registered when response + * packets arrrive, and also deals with request + * packets from other sources. + * (nmbd_packets.c) + */ + + run_packet_queue(); + + /* + * Run any elections - initiate becoming + * a local master browser if we have won. + * (nmbd_elections.c) + */ + + run_elections(t); + + /* + * Send out any broadcast announcements + * of our server names. This also announces + * the workgroup name if we are a local + * master browser. + * (nmbd_sendannounce.c) + */ + + announce_my_server_names(t); + /* + * Send out any LanMan broadcast announcements + * of our server names. + * (nmbd_sendannounce.c) + */ + + announce_my_lm_server_names(t); + + /* + * If we are a local master browser, periodically + * announce ourselves to the domain master browser. + * This also deals with syncronising the domain master + * browser server lists with ourselves as a local + * master browser. + * (nmbd_sendannounce.c) + */ + + announce_myself_to_domain_master_browser(t); + + /* + * Fullfill any remote announce requests. + * (nmbd_sendannounce.c) + */ + + announce_remote(t); + + /* + * Fullfill any remote browse sync announce requests. + * (nmbd_sendannounce.c) + */ + + browse_sync_remote(t); + + /* + * Scan the broadcast subnets, and WINS client + * namelists and refresh any that need refreshing. + * (nmbd_mynames.c) + */ + + refresh_my_names(t); + + /* + * Scan the subnet namelists and server lists and + * expire thos that have timed out. + * (nmbd.c) + */ + + expire_names_and_servers(t); + + /* + * Write out a snapshot of our current browse list into + * the browse.dat file. This is used by smbd to service + * incoming NetServerEnum calls - used to synchronise + * browse lists over subnets. + * (nmbd_serverlistdb.c) + */ + + write_browse_list(t, False); + + /* + * If we are a domain master browser, we have a list of + * local master browsers we should synchronise browse + * lists with (these are added by an incoming local + * master browser announcement packet). Expire any of + * these that are no longer current, and pull the server + * lists from each of these known local master browsers. + * (nmbd_browsesync.c) + */ + + dmb_expire_and_sync_browser_lists(t); + + /* + * Check that there is a local master browser for our + * workgroup for all our broadcast subnets. If one + * is not found, start an election (which we ourselves + * may or may not participate in, depending on the + * setting of the 'local master' parameter. + * (nmbd_elections.c) + */ + + check_master_browser_exists(t); + + /* + * If we are configured as a logon server, attempt to + * register the special NetBIOS names to become such + * (WORKGROUP<1c> name) on all broadcast subnets and + * with the WINS server (if used). If we are configured + * to become a domain master browser, attempt to register + * the special NetBIOS name (WORKGROUP<1b> name) to + * become such. + * (nmbd_become_dmb.c) + */ + + add_domain_names(t); + + /* + * If we are a WINS server, do any timer dependent + * processing required. + * (nmbd_winsserver.c) + */ + + initiate_wins_processing(t); + + /* + * If we are a domain master browser, attempt to contact the + * WINS server to get a list of all known WORKGROUPS/DOMAINS. + * This will only work to a Samba WINS server. + * (nmbd_browsesync.c) + */ + + if (lp_enhanced_browsing()) + collect_all_workgroup_names_from_wins_server(t); + + /* + * Go through the response record queue and time out or re-transmit + * and expired entries. + * (nmbd_packets.c) + */ + + retransmit_or_expire_response_records(t); + + /* + * check to see if any remote browse sync child processes have completed + */ + + sync_check_completion(); + + /* + * regularly sync with any other DMBs we know about + */ + + if (lp_enhanced_browsing()) + sync_all_dmbs(t); + + /* + * clear the unexpected packet queue + */ + + clear_unexpected(t); + + /* + * Reload the services file if we got a sighup. + */ + + if(reload_after_sighup) { + DEBUG( 0, ( "Got SIGHUP dumping debug info.\n" ) ); + write_browse_list( 0, True ); + dump_all_namelists(); + reload_nmbd_services( True ); + reopen_logs(); + if(reload_interfaces(0)) + return; + reload_after_sighup = 0; + } + + /* check for new network interfaces */ + + if(reload_interfaces(t)) + return; + + /* free up temp memory */ + lp_talloc_free(); + } +} /**************************************************************************** ** - open the socket communication + Open the socket communication. **************************************************************************** */ + static BOOL open_sockets(BOOL isdaemon, int port) { - /* The sockets opened here will be used to receive broadcast - packets *only*. Interface specific sockets are opened in - make_subnet() in namedbsubnet.c. Thus we bind to the - address "0.0.0.0". The parameter 'socket address' is - now deprecated. - */ - - if ( isdaemon ) - ClientNMB = open_socket_in(SOCK_DGRAM, port,0,0,True); - else - ClientNMB = 0; + /* + * The sockets opened here will be used to receive broadcast + * packets *only*. Interface specific sockets are opened in + * make_subnet() in namedbsubnet.c. Thus we bind to the + * address "0.0.0.0". The parameter 'socket address' is + * now deprecated. + */ + + if ( isdaemon ) + ClientNMB = open_socket_in(SOCK_DGRAM, port,0,0,True); + else + ClientNMB = 0; - ClientDGRAM = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3,0,True); + ClientDGRAM = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3,0,True); - if ( ClientNMB == -1 ) - return( False ); + if ( ClientNMB == -1 ) + return( False ); - /* we are never interested in SIGPIPE */ - BlockSignals(True,SIGPIPE); + /* we are never interested in SIGPIPE */ + BlockSignals(True,SIGPIPE); - set_socket_options( ClientNMB, "SO_BROADCAST" ); - set_socket_options( ClientDGRAM, "SO_BROADCAST" ); - - DEBUG( 3, ( "open_sockets: Broadcast sockets opened.\n" ) ); - return( True ); -} /* open_sockets */ + set_socket_options( ClientNMB, "SO_BROADCAST" ); + set_socket_options( ClientDGRAM, "SO_BROADCAST" ); + DEBUG( 3, ( "open_sockets: Broadcast sockets opened.\n" ) ); + return( True ); +} /**************************************************************************** ** - initialise connect, service and file structs + Initialise connect, service and file structs. **************************************************************************** */ + static BOOL init_structs(void) { extern fstring local_machine; @@ -626,11 +654,12 @@ static BOOL init_structs(void) DEBUGADD( 5, ( "my_netbios_names[%d]=\"%s\"\n", n, my_netbios_names[n] ) ); return( True ); -} /* init_structs */ +} /**************************************************************************** ** - usage on the program + Usage on the program. **************************************************************************** */ + static void usage(char *pname) { @@ -649,7 +678,7 @@ static void usage(char *pname) printf( "\t-p port Listen on the specified port\n" ); printf( "\t-s configuration file Configuration file name\n" ); printf( "\n"); -} /* usage */ +} /**************************************************************************** ** @@ -877,4 +906,4 @@ static void usage(char *pname) if (dbf) x_fclose(dbf); return(0); -} /* main */ +} -- cgit From db4dd16d8d61883f8b011ae3ea948578ddba8beb Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 5 Mar 2002 00:46:41 +0000 Subject: Removed unused static function. (This used to be commit 472acd89b2bf5ec2a471957aaff42e560053f60e) --- source3/nmbd/nmbd_winsserver.c | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index d274f6d3d3..75f93eafde 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -133,24 +133,6 @@ static void wins_hook(char *operation, struct name_record *namerec, int ttl) } -/**************************************************************************** -hash our interfaces and netbios names settings -*****************************************************************************/ -static unsigned wins_hash(void) -{ - int i; - unsigned ret = iface_hash(); - extern char **my_netbios_names; - - for (i=0;my_netbios_names[i];i++) - ret ^= str_checksum(my_netbios_names[i]); - - ret ^= str_checksum(lp_workgroup()); - - return ret; -} - - /**************************************************************************** Determine if this packet should be allocated to the WINS server. *****************************************************************************/ -- cgit From 75722fa183d1678bc7360bc79f9ac8cf17cd62e3 Mon Sep 17 00:00:00 2001 From: Martin Pool Date: Wed, 20 Mar 2002 06:57:03 +0000 Subject: Add assertions that kill() is never accidentally passed a non-positive pid. This follows a bug in rsync where it would accidentally kill(-1), removing all the user's processes. I can't see any way this would directly happen in Samba, but having the assertions seems beneficial. http://cvs.samba.org/cgi-bin/cvsweb/rsync/util.c.diff?r1=1.108&r2=1.109&f=h (This used to be commit 098905bea29c7d5b886809d431294ddf2fc1e152) --- source3/nmbd/asyncdns.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index c5ff718836..6c2f8de3b1 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -120,8 +120,9 @@ static void sig_term(int sig) void kill_async_dns_child(void) { - if(child_pid != 0 && child_pid != -1) - kill(child_pid, SIGTERM); + if (child_pid > 0) { + kill(child_pid, SIGTERM); + } } /*************************************************************************** -- cgit From 67d21b5a4ba35244c4362130ce7c501c89839429 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 21 Mar 2002 23:39:17 +0000 Subject: Make winbindd_idmap tdb endian independent. This is very important for sharing between machines with rsync. Finally removed tdb_store_int/tdb_fetch_int. Now only tdb_store_int32/tdb_fetch_int32 which are endian independent are allowed. Jeremy. (This used to be commit 1c4a00dcc13f4a7c5876a5cf63ca730190d1132e) --- source3/nmbd/nmbd_winsserver.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 75f93eafde..3332e99e9d 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -240,7 +240,7 @@ BOOL initialise_wins(void) return True; } - if (tdb_fetch_int(tdb, INFO_VERSION) != WINS_VERSION) { + if (tdb_fetch_int32(tdb, INFO_VERSION) != WINS_VERSION) { DEBUG(0,("Discarding invalid wins.dat file\n")); tdb_close(tdb); return True; @@ -1766,7 +1766,7 @@ void wins_write_database(BOOL background) DEBUG(3,("wins_write_database: Dump of WINS name list.\n")); - tdb_store_int(tdb, INFO_VERSION, WINS_VERSION); + tdb_store_int32(tdb, INFO_VERSION, WINS_VERSION); for (namerec = (struct name_record *)ubi_trFirst( wins_server_subnet->namelist ); namerec; @@ -1823,12 +1823,12 @@ void wins_write_database(BOOL background) } /* store the number of records */ - tdb_store_int(tdb, INFO_COUNT, num_record); + tdb_store_int32(tdb, INFO_COUNT, num_record); /* get and store the last used ID */ get_global_id_and_update(&id, False); - tdb_store_int(tdb, INFO_ID_HIGH, id>>32); - tdb_store_int(tdb, INFO_ID_LOW, id&0xffffffff); + tdb_store_int32(tdb, INFO_ID_HIGH, id>>32); + tdb_store_int32(tdb, INFO_ID_LOW, id&0xffffffff); tdb_close(tdb); -- cgit From 63cbe1be9a37929bf00fc52615c43502d0035563 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 29 Mar 2002 00:57:35 +0000 Subject: Fix to stop PERMANENT_NAMES being added when nmbd starts up and WINS server is down. Keep adding refreshible names instead. Jeremy. (This used to be commit f25fcd99fa0d0ec2095d9db42145d236c14748e0) --- source3/nmbd/nmbd_mynames.c | 39 ++++++++++++++++++++++++++++++++++----- 1 file changed, 34 insertions(+), 5 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index a3311fec47..aac188db2b 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -79,6 +79,35 @@ Exiting.\n", global_myworkgroup, subrec->subnet_name)); initiate_myworkgroup_startup(subrec, work); } +/******************************************************************* + Utility function to add a name to the unicast subnet, or add in + our IP address if it already exists. +******************************************************************/ + +static void insert_refresh_name_into_unicast( struct subnet_record *subrec, + struct nmb_name *nmbname, uint16 nb_type ) +{ + struct name_record *namerec; + + if (!we_are_a_wins_client()) { + insert_permanent_name_into_unicast(subrec, nmbname, nb_type); + return; + } + + if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) == NULL) + { + /* The name needs to be created on the unicast subnet. */ + (void)add_name_to_subnet( unicast_subnet, nmbname->name, + nmbname->name_type, nb_type, + MIN(lp_max_ttl(), MAX_REFRESH_TIME), SELF_NAME, 1, &subrec->myip); + } + else + { + /* The name already exists on the unicast subnet. Add our local + IP for the given broadcast subnet to the name. */ + add_ip_to_name_record( namerec, subrec->myip); + } +} /**************************************************************************** Add my workgroup and my given names to the subnet lists. @@ -114,13 +143,13 @@ BOOL register_my_workgroup_and_names(void) struct nmb_name nmbname; make_nmb_name(&nmbname, my_netbios_names[i],0x20); - insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type); + insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type); make_nmb_name(&nmbname, my_netbios_names[i],0x3); - insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type); + insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type); make_nmb_name(&nmbname, my_netbios_names[i],0x0); - insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type); + insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type); } } @@ -137,10 +166,10 @@ BOOL register_my_workgroup_and_names(void) struct nmb_name nmbname; make_nmb_name(&nmbname, global_myworkgroup, 0x0); - insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP); + insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP); make_nmb_name(&nmbname, global_myworkgroup, 0x1e); - insert_permanent_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP); + insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP); } /* -- cgit From 3e0c6ded6538899cbdf1f4c30669d411e07ac957 Mon Sep 17 00:00:00 2001 From: Jean-François Micouleau Date: Fri, 29 Mar 2002 13:58:32 +0000 Subject: nmbd handle shutdown message. J.F. (This used to be commit c33459f7018a2522158b20261ab8c100fdde9034) --- source3/nmbd/nmbd.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 62e3f1757b..051991f46d 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -65,6 +65,15 @@ static void terminate(void) exit(0); } +/**************************************************************************** ** + Handle a SHUTDOWN message from smbcontrol. + **************************************************************************** */ + +static void nmbd_terminate(int msg_type, pid_t src, void *buf, size_t len) +{ + terminate(); +} + /**************************************************************************** ** Catch a SIGTERM signal. **************************************************************************** */ @@ -857,6 +866,7 @@ static void usage(char *pname) message_init(); message_register(MSG_FORCE_ELECTION, nmbd_message_election); message_register(MSG_WINS_NEW_ENTRY, nmbd_wins_new_entry); + message_register(MSG_SHUTDOWN, nmbd_terminate); DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); -- cgit From e90b65284812aaa5ff9e9935ce9bbad7791cbbcd Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 15 Jul 2002 10:35:28 +0000 Subject: updated the 3.0 branch from the head branch - ready for alpha18 (This used to be commit 03ac082dcb375b6f3ca3d810a6a6367542bc23ce) --- source3/nmbd/nmbd.c | 19 +- source3/nmbd/nmbd_incomingrequests.c | 316 +++++++------- source3/nmbd/nmbd_mynames.c | 93 ++-- source3/nmbd/nmbd_namelistdb.c | 2 +- source3/nmbd/nmbd_namequery.c | 2 +- source3/nmbd/nmbd_nameregister.c | 789 ++++++++++++++++++++-------------- source3/nmbd/nmbd_namerelease.c | 361 ++++++++-------- source3/nmbd/nmbd_packets.c | 334 +++++++------- source3/nmbd/nmbd_responserecordsdb.c | 12 +- source3/nmbd/nmbd_subnetdb.c | 71 +-- source3/nmbd/nmbd_winsserver.c | 12 +- 11 files changed, 1036 insertions(+), 975 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 051991f46d..d30efb550c 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -53,8 +53,8 @@ static void terminate(void) /* Write out wins.dat file if samba is a WINS server */ wins_write_database(False); - /* Remove all SELF registered names. */ - release_my_names(); + /* Remove all SELF registered names from WINS */ + release_wins_names(); /* Announce all server entries as 0 time-to-live, 0 type. */ announce_my_servers_removed(); @@ -78,7 +78,7 @@ static void nmbd_terminate(int msg_type, pid_t src, void *buf, size_t len) Catch a SIGTERM signal. **************************************************************************** */ -static VOLATILE sig_atomic_t got_sig_term; +static SIG_ATOMIC_T got_sig_term; static void sig_term(int sig) { @@ -90,7 +90,7 @@ static void sig_term(int sig) Catch a SIGHUP signal. **************************************************************************** */ -static VOLATILE sig_atomic_t reload_after_sighup; +static SIG_ATOMIC_T reload_after_sighup; static void sig_hup(int sig) { @@ -293,15 +293,6 @@ static BOOL reload_nmbd_services(BOOL test) reload_nmbd_services( True ); } - /* Do a sanity check for a misconfigured nmbd */ - if( lp_wins_support() && wins_srv_count() ) { - if( DEBUGLVL(0) ) { - dbgtext( "ERROR: 'wins support = true' and 'wins server = '\n" ); - dbgtext( "are conflicting settings. nmbd aborting.\n" ); - } - exit(10); - } - return(ret); } @@ -853,7 +844,7 @@ static void usage(char *pname) #ifndef SYNC_DNS /* Setup the async dns. We do it here so it doesn't have all the other stuff initialised and thus chewing memory and sockets */ - if(lp_we_are_a_wins_server()) { + if(lp_we_are_a_wins_server() && lp_dns_proxy()) { start_async_dns(); } #endif diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index 3f2b921074..834f237a2c 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -449,175 +449,151 @@ For broadcast name queries: void process_name_query_request(struct subnet_record *subrec, struct packet_struct *p) { - struct nmb_packet *nmb = &p->packet.nmb; - struct nmb_name *question = &nmb->question.question_name; - int name_type = question->name_type; - BOOL bcast = nmb->header.nm_flags.bcast; - int ttl=0; - int rcode = 0; - char *prdata = NULL; - char rdata[6]; - BOOL success = False; - struct name_record *namerec = NULL; - int reply_data_len = 0; - int i; - - DEBUG(3,("process_name_query_request: Name query from %s on subnet %s for name %s\n", - inet_ntoa(p->ip), subrec->subnet_name, nmb_namestr(question))); + struct nmb_packet *nmb = &p->packet.nmb; + struct nmb_name *question = &nmb->question.question_name; + int name_type = question->name_type; + BOOL bcast = nmb->header.nm_flags.bcast; + int ttl=0; + int rcode = 0; + char *prdata = NULL; + char rdata[6]; + BOOL success = False; + struct name_record *namerec = NULL; + int reply_data_len = 0; + int i; + + DEBUG(3,("process_name_query_request: Name query from %s on subnet %s for name %s\n", + inet_ntoa(p->ip), subrec->subnet_name, nmb_namestr(question))); - /* Look up the name in the cache - if the request is a broadcast request that - came from a subnet we don't know about then search all the broadcast subnets - for a match (as we don't know what interface the request came in on). */ - - if(subrec == remote_broadcast_subnet) - namerec = find_name_for_remote_broadcast_subnet( question, FIND_ANY_NAME); - else - namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); - - - /* Check if it is a name that expired */ - if( namerec - && ( (namerec->data.death_time != PERMANENT_TTL) - && (namerec->data.death_time < p->timestamp) ) ) - { - DEBUG(5,("process_name_query_request: expired name %s\n", nmb_namestr(&namerec->name))); - namerec = NULL; - } - - if (namerec) - { - - /* - * Always respond to unicast queries. - * Don't respond to broadcast queries unless the query is for - * a name we own, a Primary Domain Controller name, or a WINS_PROXY - * name with type 0 or 0x20. WINS_PROXY names are only ever added - * into the namelist if we were configured as a WINS proxy. - */ - - if( !bcast - || ( bcast - && ( (name_type == 0x1b) - || (namerec->data.source == SELF_NAME) - || (namerec->data.source == PERMANENT_NAME) - || ( (namerec->data.source == WINS_PROXY_NAME) - && ( (name_type == 0) || (name_type == 0x20) ) - ) - ) - ) - ) - { - - /* The requested name is a directed query, or it's SELF or PERMANENT or WINS_PROXY, - or it's a Domain Master type. */ - - /* - * If this is a WINS_PROXY_NAME, then ceck that none of the IP - * addresses we are returning is on the same broadcast subnet - * as the requesting packet. If it is then don't reply as the - * actual machine will be replying also and we don't want two - * replies to a broadcast query. - */ - - if( namerec->data.source == WINS_PROXY_NAME ) - { - for( i = 0; i < namerec->data.num_ips; i++) - { - if(same_net( namerec->data.ip[i], subrec->myip, subrec->mask_ip )) - { - DEBUG(5,("process_name_query_request: name %s is a WINS proxy name and is also \ -on the same subnet (%s) as the requestor. Not replying.\n", - nmb_namestr(&namerec->name), subrec->subnet_name )); - return; - } - } - } - - ttl = (namerec->data.death_time != PERMANENT_TTL) ? - namerec->data.death_time - p->timestamp : lp_max_ttl(); - - /* Copy all known ip addresses into the return data. */ - /* Optimise for the common case of one IP address so - we don't need a malloc. */ - - if( namerec->data.num_ips == 1 ) - prdata = rdata; - else - { - if((prdata = (char *)malloc( namerec->data.num_ips * 6 )) == NULL) - { - DEBUG(0,("process_name_query_request: malloc fail !\n")); - return; - } - } - - for( i = 0; i < namerec->data.num_ips; i++ ) - { - set_nb_flags(&prdata[i*6],namerec->data.nb_flags); - putip((char *)&prdata[2+(i*6)], &namerec->data.ip[i]); - } - - sort_query_replies(prdata, i, p->ip); - - reply_data_len = namerec->data.num_ips * 6; - success = True; - } - } - - /* - * If a machine is broadcasting a name lookup request and we have lp_wins_proxy() - * set we should initiate a WINS query here. On success we add the resolved name - * into our namelist with a type of WINS_PROXY_NAME and then reply to the query. - */ - - if(!success && (namerec == NULL) && we_are_a_wins_client() && lp_wins_proxy() && - bcast && (subrec != remote_broadcast_subnet)) - { - make_wins_proxy_name_query_request( subrec, p, question ); - return; - } - - if (!success && bcast) - { - if(prdata != rdata) - SAFE_FREE(prdata); - return; /* Never reply with a negative response to broadcasts. */ - } - - /* - * Final check. From observation, if a unicast packet is sent - * to a non-WINS server with the recursion desired bit set - * then never send a negative response. - */ - - if(!success && !bcast && nmb->header.nm_flags.recursion_desired) - { - if(prdata != rdata) - SAFE_FREE(prdata); - return; - } - - if (success) - { - rcode = 0; - DEBUG(3,("OK\n")); - } - else - { - rcode = NAM_ERR; - DEBUG(3,("UNKNOWN\n")); - } - - /* See rfc1002.txt 4.2.13. */ - - reply_netbios_packet(p, /* Packet to reply to. */ - rcode, /* Result code. */ - NMB_QUERY, /* nmbd type code. */ - NMB_NAME_QUERY_OPCODE, /* opcode. */ - ttl, /* ttl. */ - prdata, /* data to send. */ - reply_data_len); /* data length. */ - - if(prdata != rdata) - SAFE_FREE(prdata); + /* Look up the name in the cache - if the request is a broadcast request that + came from a subnet we don't know about then search all the broadcast subnets + for a match (as we don't know what interface the request came in on). */ + + if(subrec == remote_broadcast_subnet) + namerec = find_name_for_remote_broadcast_subnet( question, FIND_ANY_NAME); + else + namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); + + /* Check if it is a name that expired */ + if (namerec && + ((namerec->data.death_time != PERMANENT_TTL) && + (namerec->data.death_time < p->timestamp))) { + DEBUG(5,("process_name_query_request: expired name %s\n", nmb_namestr(&namerec->name))); + namerec = NULL; + } + + if (namerec) { + /* + * Always respond to unicast queries. + * Don't respond to broadcast queries unless the query is for + * a name we own, a Primary Domain Controller name, or a WINS_PROXY + * name with type 0 or 0x20. WINS_PROXY names are only ever added + * into the namelist if we were configured as a WINS proxy. + */ + + if (!bcast || + (bcast && ((name_type == 0x1b) || + (namerec->data.source == SELF_NAME) || + (namerec->data.source == PERMANENT_NAME) || + ((namerec->data.source == WINS_PROXY_NAME) && + ((name_type == 0) || (name_type == 0x20)))))) { + /* The requested name is a directed query, or it's SELF or PERMANENT or WINS_PROXY, + or it's a Domain Master type. */ + + /* + * If this is a WINS_PROXY_NAME, then ceck that none of the IP + * addresses we are returning is on the same broadcast subnet + * as the requesting packet. If it is then don't reply as the + * actual machine will be replying also and we don't want two + * replies to a broadcast query. + */ + + if (namerec->data.source == WINS_PROXY_NAME) { + for( i = 0; i < namerec->data.num_ips; i++) { + if (same_net(namerec->data.ip[i], subrec->myip, subrec->mask_ip)) { + DEBUG(5,("process_name_query_request: name %s is a WINS proxy name and is also on the same subnet (%s) as the requestor. Not replying.\n", + nmb_namestr(&namerec->name), subrec->subnet_name )); + return; + } + } + } + + ttl = (namerec->data.death_time != PERMANENT_TTL) ? + namerec->data.death_time - p->timestamp : lp_max_ttl(); + + /* Copy all known ip addresses into the return data. */ + /* Optimise for the common case of one IP address so + we don't need a malloc. */ + + if (namerec->data.num_ips == 1) { + prdata = rdata; + } else { + if ((prdata = (char *)malloc( namerec->data.num_ips * 6 )) == NULL) { + DEBUG(0,("process_name_query_request: malloc fail !\n")); + return; + } + } + + for (i = 0; i < namerec->data.num_ips; i++) { + set_nb_flags(&prdata[i*6],namerec->data.nb_flags); + putip((char *)&prdata[2+(i*6)], &namerec->data.ip[i]); + } + + sort_query_replies(prdata, i, p->ip); + + reply_data_len = namerec->data.num_ips * 6; + success = True; + } + } + + /* + * If a machine is broadcasting a name lookup request and we have lp_wins_proxy() + * set we should initiate a WINS query here. On success we add the resolved name + * into our namelist with a type of WINS_PROXY_NAME and then reply to the query. + */ + + if(!success && (namerec == NULL) && we_are_a_wins_client() && lp_wins_proxy() && + bcast && (subrec != remote_broadcast_subnet)) { + make_wins_proxy_name_query_request( subrec, p, question ); + return; + } + + if (!success && bcast) { + if(prdata != rdata) + SAFE_FREE(prdata); + return; /* Never reply with a negative response to broadcasts. */ + } + + /* + * Final check. From observation, if a unicast packet is sent + * to a non-WINS server with the recursion desired bit set + * then never send a negative response. + */ + + if(!success && !bcast && nmb->header.nm_flags.recursion_desired) { + if(prdata != rdata) + SAFE_FREE(prdata); + return; + } + + if (success) { + rcode = 0; + DEBUG(3,("OK\n")); + } else { + rcode = NAM_ERR; + DEBUG(3,("UNKNOWN\n")); + } + + /* See rfc1002.txt 4.2.13. */ + + reply_netbios_packet(p, /* Packet to reply to. */ + rcode, /* Result code. */ + NMB_QUERY, /* nmbd type code. */ + NMB_NAME_QUERY_OPCODE, /* opcode. */ + ttl, /* ttl. */ + prdata, /* data to send. */ + reply_data_len); /* data length. */ + + if(prdata != rdata) + SAFE_FREE(prdata); } diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index aac188db2b..345245c57d 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -184,67 +184,48 @@ BOOL register_my_workgroup_and_names(void) /**************************************************************************** Remove all the names we registered. **************************************************************************/ - -void release_my_names(void) +void release_wins_names(void) { -#if 0 /*JRR: do WINS server only, otherwise clients ignore us when we come back up*/ - struct subnet_record *subrec; - - for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) -#else - struct subnet_record *subrec = unicast_subnet; -#endif - { - struct name_record *namerec, *nextnamerec; - - for (namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); - namerec; - namerec = nextnamerec) - { - nextnamerec = (struct name_record *)ubi_trNext( namerec ); - if( (namerec->data.source == SELF_NAME) - && !NAME_IS_DEREGISTERING(namerec) ) - release_name( subrec, namerec, standard_success_release, - NULL, NULL); - } - } + struct subnet_record *subrec = unicast_subnet; + struct name_record *namerec, *nextnamerec; + + for (namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); + namerec; + namerec = nextnamerec) { + nextnamerec = (struct name_record *)ubi_trNext( namerec ); + if( (namerec->data.source == SELF_NAME) + && !NAME_IS_DEREGISTERING(namerec) ) + release_name( subrec, namerec, standard_success_release, + NULL, NULL); + } } /******************************************************************* - Refresh our registered names. + Refresh our registered names with WINS ******************************************************************/ - void refresh_my_names(time_t t) { - struct subnet_record *subrec; - - for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) - { - struct name_record *namerec; - - /* B nodes don't send out name refresh requests, see RFC 1001, 15.5.1 */ - if (subrec != unicast_subnet) - continue; - - for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); - namerec; - namerec = (struct name_record *)ubi_trNext( namerec ) ) - { - /* Each SELF name has an individual time to be refreshed. */ - if( (namerec->data.source == SELF_NAME) - && (namerec->data.refresh_time < t) - && ( namerec->data.death_time != PERMANENT_TTL) ) - { - /* We cheat here and pretend the refresh is going to be - successful & update the refresh times. This stops - multiple refresh calls being done. We actually - deal with refresh failure in the fail_fn. - */ - if( !is_refresh_already_queued( subrec, namerec) ) - refresh_name( subrec, namerec, NULL, NULL, NULL ); - namerec->data.death_time = t + lp_max_ttl(); - namerec->data.refresh_time = t + MIN(lp_max_ttl(), MAX_REFRESH_TIME); - } - } - } + struct name_record *namerec; + + if (wins_srv_count() < 1) return; + + for (namerec = (struct name_record *)ubi_trFirst(unicast_subnet->namelist); + namerec; + namerec = (struct name_record *)ubi_trNext(namerec)) { + /* Each SELF name has an individual time to be refreshed. */ + if ((namerec->data.source == SELF_NAME) && + (namerec->data.refresh_time < t) && + (namerec->data.death_time != PERMANENT_TTL)) { + /* We cheat here and pretend the refresh is going to be + successful & update the refresh times. This stops + multiple refresh calls being done. We actually + deal with refresh failure in the fail_fn. + */ + if (!is_refresh_already_queued(unicast_subnet, namerec)) { + wins_refresh_name(namerec); + } + namerec->data.death_time = t + lp_max_ttl(); + namerec->data.refresh_time = t + MIN(lp_max_ttl(), MAX_REFRESH_TIME); + } + } } diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 68b44d618f..bca79ef0c8 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -35,7 +35,7 @@ uint16 samba_nb_type = 0; /* samba's NetBIOS name type */ void set_samba_nb_type(void) { if( lp_wins_support() || wins_srv_count() ) - samba_nb_type = NB_MFLAG; /* samba is a 'hybrid' node type. */ + samba_nb_type = NB_HFLAG; /* samba is a 'hybrid' node type. */ else samba_nb_type = NB_BFLAG; /* samba is broadcast-only node type. */ } /* set_samba_nb_type */ diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index aeb9984180..7a820a7148 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -107,7 +107,7 @@ static void query_name_response( struct subnet_record *subrec, dbgtext( "Multiple (%d) responses ", rrec->num_msgs ); dbgtext( "received for a query on subnet %s ", subrec->subnet_name ); dbgtext( "for name %s.\nThis response ", nmb_namestr(question_name) ); - dbgtext( "was from IP %s, reporting", inet_ntoa(p->ip) ); + dbgtext( "was from IP %s, reporting ", inet_ntoa(p->ip) ); dbgtext( "an IP address of %s.\n", inet_ntoa(answer_ip) ); } diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index cbc72fe2a9..4ac5473d4a 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -25,6 +25,10 @@ extern fstring global_myworkgroup; +/* forward declarations */ +static void wins_next_registration(struct response_record *rrec); + + /**************************************************************************** Deal with a response packet when registering one of our names. ****************************************************************************/ @@ -32,368 +36,489 @@ extern fstring global_myworkgroup; static void register_name_response(struct subnet_record *subrec, struct response_record *rrec, struct packet_struct *p) { - /* - * If we are registering broadcast, then getting a response is an - * error - we do not have the name. If we are registering unicast, - * then we expect to get a response. - */ - - struct nmb_packet *nmb = &p->packet.nmb; - BOOL bcast = nmb->header.nm_flags.bcast; - BOOL success = True; - struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name; - struct nmb_name *answer_name = &nmb->answers->rr_name; - int ttl = 0; - uint16 nb_flags = 0; - struct in_addr registered_ip; - - /* Sanity check. Ensure that the answer name in the incoming packet is the - same as the requested name in the outgoing packet. */ - - if(!question_name || !answer_name) - { - DEBUG(0,("register_name_response: malformed response (%s is NULL).\n", - question_name ? "question_name" : "answer_name" )); - return; - } - - if(!nmb_name_equal(question_name, answer_name)) - { - DEBUG(0,("register_name_response: Answer name %s differs from question \ -name %s.\n", nmb_namestr(answer_name), nmb_namestr(question_name))); - return; - } - - if(bcast) - { - /* - * Special hack to cope with old Samba nmbd's. - * Earlier versions of Samba (up to 1.9.16p11) respond - * to a broadcast name registration of WORKGROUP<1b> when - * they should not. Hence, until these versions are gone, - * we should treat such errors as success for this particular - * case only. jallison@whistle.com. - */ - + /* + * If we are registering broadcast, then getting a response is an + * error - we do not have the name. If we are registering unicast, + * then we expect to get a response. + */ + + struct nmb_packet *nmb = &p->packet.nmb; + BOOL bcast = nmb->header.nm_flags.bcast; + BOOL success = True; + struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name; + struct nmb_name *answer_name = &nmb->answers->rr_name; + struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb; + int ttl = 0; + uint16 nb_flags = 0; + struct in_addr register_ip; + fstring reg_name; + + putip(®ister_ip,&sent_nmb->additional->rdata[2]); + fstrcpy(reg_name, inet_ntoa(register_ip)); + + if (subrec == unicast_subnet) { + /* we know that this wins server is definately alive - for the moment! */ + wins_srv_alive(rrec->packet->ip, register_ip); + } + + /* Sanity check. Ensure that the answer name in the incoming packet is the + same as the requested name in the outgoing packet. */ + + if(!question_name || !answer_name) { + DEBUG(0,("register_name_response: malformed response (%s is NULL).\n", + question_name ? "question_name" : "answer_name" )); + return; + } + + if(!nmb_name_equal(question_name, answer_name)) { + DEBUG(0,("register_name_response: Answer name %s differs from question name %s.\n", + nmb_namestr(answer_name), nmb_namestr(question_name))); + return; + } + + if(bcast) { + /* + * Special hack to cope with old Samba nmbd's. + * Earlier versions of Samba (up to 1.9.16p11) respond + * to a broadcast name registration of WORKGROUP<1b> when + * they should not. Hence, until these versions are gone, + * we should treat such errors as success for this particular + * case only. jallison@whistle.com. + */ + #if 1 /* OLD_SAMBA_SERVER_HACK */ - if((nmb->header.rcode == ACT_ERR) && strequal(global_myworkgroup, answer_name->name) && - (answer_name->name_type == 0x1b)) - { - /* Pretend we did not get this. */ - rrec->num_msgs--; - - DEBUG(5,("register_name_response: Ignoring broadcast response to \ -registration of name %s due to old Samba server bug.\n", nmb_namestr(answer_name))); - return; - } + if((nmb->header.rcode == ACT_ERR) && strequal(global_myworkgroup, answer_name->name) && + (answer_name->name_type == 0x1b)) { + /* Pretend we did not get this. */ + rrec->num_msgs--; + + DEBUG(5,("register_name_response: Ignoring broadcast response to registration of name %s due to old Samba server bug.\n", + nmb_namestr(answer_name))); + return; + } #endif /* OLD_SAMBA_SERVER_HACK */ - /* Someone else has the name. Log the problem. */ - DEBUG(1,("register_name_response: Failed to register \ -name %s on subnet %s via broadcast. Error code was %d. Reject came from IP %s\n", - nmb_namestr(answer_name), - subrec->subnet_name, nmb->header.rcode, inet_ntoa(p->ip))); - success = False; - } - else - { - /* Unicast - check to see if the response allows us to have the name. */ - if(nmb->header.rcode != 0) - { - /* Error code - we didn't get the name. */ - success = False; - - DEBUG(0,("register_name_response: server at IP %s rejected our \ -name registration of %s with error code %d.\n", inet_ntoa(p->ip), - nmb_namestr(answer_name), nmb->header.rcode)); - - } - else if(nmb->header.opcode == NMB_WACK_OPCODE) - { - /* WINS server is telling us to wait. Pretend we didn't get - the response but don't send out any more register requests. */ - - DEBUG(5,("register_name_response: WACK from WINS server %s in registering \ -name %s on subnet %s.\n", inet_ntoa(p->ip), nmb_namestr(answer_name), subrec->subnet_name)); - - rrec->repeat_count = 0; - /* How long we should wait for. */ - rrec->repeat_time = p->timestamp + nmb->answers->ttl; - rrec->num_msgs--; - return; - } - else - { - success = True; - /* Get the data we need to pass to the success function. */ - nb_flags = get_nb_flags(nmb->answers->rdata); - putip((char*)®istered_ip,&nmb->answers->rdata[2]); - ttl = nmb->answers->ttl; - } - } - - DEBUG(5,("register_name_response: %s in registering name %s on subnet %s.\n", - success ? "success" : "failure", nmb_namestr(answer_name), subrec->subnet_name)); - - if(success) - { - /* Enter the registered name into the subnet name database before calling - the success function. */ - standard_success_register(subrec, rrec->userdata, answer_name, nb_flags, ttl, registered_ip); - if( rrec->success_fn) - (*(register_name_success_function)rrec->success_fn)(subrec, rrec->userdata, answer_name, nb_flags, ttl, registered_ip); - } - else - { - if( rrec->fail_fn) - (*(register_name_fail_function)rrec->fail_fn)(subrec, rrec, question_name); - /* Remove the name. */ - standard_fail_register( subrec, rrec, question_name); - } - - /* Ensure we don't retry. */ - remove_response_record(subrec, rrec); + /* Someone else has the name. Log the problem. */ + DEBUG(1,("register_name_response: Failed to register name %s IP %s on subnet %s via broadcast. Error code was %d. Reject came from IP %s\n", + nmb_namestr(answer_name), + reg_name, + subrec->subnet_name, nmb->header.rcode, inet_ntoa(p->ip))); + success = False; + } else { + /* Unicast - check to see if the response allows us to have the name. */ + if(nmb->header.rcode != 0) { + /* Error code - we didn't get the name. */ + success = False; + + DEBUG(0,("register_name_response: %sserver at IP %s rejected our name registration of %s IP %s with error code %d.\n", + subrec==unicast_subnet?"WINS ":"", + inet_ntoa(p->ip), + nmb_namestr(answer_name), + reg_name, + nmb->header.rcode)); + } else if (nmb->header.opcode == NMB_WACK_OPCODE) { + /* WINS server is telling us to wait. Pretend we didn't get + the response but don't send out any more register requests. */ + + DEBUG(5,("register_name_response: WACK from WINS server %s in registering name %s IP %s\n", + inet_ntoa(p->ip), nmb_namestr(answer_name), reg_name)); + + rrec->repeat_count = 0; + /* How long we should wait for. */ + rrec->repeat_time = p->timestamp + nmb->answers->ttl; + rrec->num_msgs--; + return; + } else { + success = True; + /* Get the data we need to pass to the success function. */ + nb_flags = get_nb_flags(nmb->answers->rdata); + ttl = nmb->answers->ttl; + + /* send off a registration for the next IP, if any */ + wins_next_registration(rrec); + } + } + + DEBUG(5,("register_name_response: %s in registering %sname %s IP %s with %s.\n", + success ? "success" : "failure", + subrec==unicast_subnet?"WINS ":"", + nmb_namestr(answer_name), + reg_name, + inet_ntoa(rrec->packet->ip))); + + if(success) { + /* Enter the registered name into the subnet name database before calling + the success function. */ + standard_success_register(subrec, rrec->userdata, answer_name, nb_flags, ttl, register_ip); + if( rrec->success_fn) + (*(register_name_success_function)rrec->success_fn)(subrec, rrec->userdata, answer_name, nb_flags, ttl, register_ip); + } else { + if( rrec->fail_fn) + (*(register_name_fail_function)rrec->fail_fn)(subrec, rrec, question_name); + /* Remove the name. */ + standard_fail_register( subrec, rrec, question_name); + } + + /* Ensure we don't retry. */ + remove_response_record(subrec, rrec); } + +/**************************************************************************** + Deal with a timeout of a WINS registration request +****************************************************************************/ +static void wins_registration_timeout(struct subnet_record *subrec, + struct response_record *rrec) +{ + struct userdata_struct *userdata = rrec->userdata; + struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb; + struct nmb_name *nmbname = &sent_nmb->question.question_name; + struct in_addr register_ip; + fstring src_addr; + + putip(®ister_ip,&sent_nmb->additional->rdata[2]); + + fstrcpy(src_addr, inet_ntoa(register_ip)); + + DEBUG(2,("wins_registration_timeout: WINS server %s timed out registering IP %s\n", + inet_ntoa(rrec->packet->ip), src_addr)); + + /* mark it temporarily dead for this source address */ + wins_srv_died(rrec->packet->ip, register_ip); + + /* if we have some userdata then use that to work out what + wins server to try next */ + if (userdata) { + const char *tag = (const char *)userdata->data; + + /* try the next wins server in our failover list for + this tag */ + rrec->packet->ip = wins_srv_ip_tag(tag, register_ip); + } + + /* if we have run out of wins servers for this tag then they + must all have timed out. We treat this as *success*, not + failure, and go into our standard name refresh mode. This + copes with all the wins servers being down */ + if (wins_srv_is_dead(rrec->packet->ip, register_ip)) { + uint16 nb_flags = get_nb_flags(sent_nmb->additional->rdata); + int ttl = sent_nmb->additional->ttl; + + standard_success_register(subrec, userdata, nmbname, nb_flags, ttl, register_ip); + if(rrec->success_fn) { + (*(register_name_success_function)rrec->success_fn)(subrec, + rrec->userdata, + nmbname, + nb_flags, + ttl, + register_ip); + } + + /* send off a registration for the next IP, if any */ + wins_next_registration(rrec); + + /* don't need to send this packet any more */ + remove_response_record(subrec, rrec); + return; + } + + /* we will be moving to the next WINS server for this group, + send it immediately */ + rrec->repeat_count = 2; + rrec->repeat_time = time(NULL) + 1; + rrec->in_expiration_processing = False; + + DEBUG(6,("Retrying register of name %s IP %s with WINS server %s\n", + nmb_namestr(nmbname), src_addr, inet_ntoa(rrec->packet->ip))); + + /* notice that we don't remove the response record. This keeps + us trying to register with each of our failover wins servers */ +} + + /**************************************************************************** Deal with a timeout when registering one of our names. ****************************************************************************/ static void register_name_timeout_response(struct subnet_record *subrec, - struct response_record *rrec) + struct response_record *rrec) { - /* - * If we are registering unicast, then NOT getting a response is an - * error - we do not have the name. If we are registering broadcast, - * then we don't expect to get a response. - */ - - struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb; - BOOL bcast = sent_nmb->header.nm_flags.bcast; - BOOL success = False; - struct nmb_name *question_name = &sent_nmb->question.question_name; - uint16 nb_flags = 0; - int ttl = 0; - struct in_addr registered_ip; - - if(bcast) - { - if(rrec->num_msgs == 0) - { - /* Not receiving a message is success for broadcast registration. */ - success = True; - - /* Pull the success values from the original request packet. */ - nb_flags = get_nb_flags(sent_nmb->additional->rdata); - ttl = sent_nmb->additional->ttl; - putip(®istered_ip,&sent_nmb->additional->rdata[2]); - } - } - else - { - /* Unicast - if no responses then it's an error. */ - if(rrec->num_msgs == 0) - { - DEBUG(2,("register_name_timeout_response: WINS server at address %s is not \ -responding.\n", inet_ntoa(rrec->packet->ip))); - - /* Keep trying to contact the WINS server periodically. This allows - us to work correctly if the WINS server is down temporarily when - we come up. */ - - /* Reset the number of attempts to zero and double the interval between - retries. Max out at 5 minutes. */ - rrec->repeat_count = 3; - rrec->repeat_interval *= 2; - if(rrec->repeat_interval > (5 * 60)) - rrec->repeat_interval = (5 * 60); - rrec->repeat_time = time(NULL) + rrec->repeat_interval; - rrec->in_expiration_processing = False; - - DEBUG(5,("register_name_timeout_response: increasing WINS timeout to %d seconds.\n", - (int)rrec->repeat_interval)); - return; /* Don't remove the response record. */ - } - } - - DEBUG(5,("register_name_timeout_response: %s in registering name %s on subnet %s.\n", - success ? "success" : "failure", nmb_namestr(question_name), subrec->subnet_name)); - if(success) - { - /* Enter the registered name into the subnet name database before calling - the success function. */ - standard_success_register(subrec, rrec->userdata, question_name, nb_flags, ttl, registered_ip); - if( rrec->success_fn) - (*(register_name_success_function)rrec->success_fn)(subrec, rrec->userdata, question_name, nb_flags, ttl, registered_ip); - } - else - { - if( rrec->fail_fn) - (*(register_name_fail_function)rrec->fail_fn)(subrec, rrec, question_name); - /* Remove the name. */ - standard_fail_register( subrec, rrec, question_name); - } - - /* Ensure we don't retry. */ - remove_response_record(subrec, rrec); + /* + * If we are registering unicast, then NOT getting a response is an + * error - we do not have the name. If we are registering broadcast, + * then we don't expect to get a response. + */ + + struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb; + BOOL bcast = sent_nmb->header.nm_flags.bcast; + BOOL success = False; + struct nmb_name *question_name = &sent_nmb->question.question_name; + uint16 nb_flags = 0; + int ttl = 0; + struct in_addr registered_ip; + + if (bcast) { + if(rrec->num_msgs == 0) { + /* Not receiving a message is success for broadcast registration. */ + success = True; + + /* Pull the success values from the original request packet. */ + nb_flags = get_nb_flags(sent_nmb->additional->rdata); + ttl = sent_nmb->additional->ttl; + putip(®istered_ip,&sent_nmb->additional->rdata[2]); + } + } else { + /* wins timeouts are special */ + wins_registration_timeout(subrec, rrec); + return; + } + + DEBUG(5,("register_name_timeout_response: %s in registering name %s on subnet %s.\n", + success ? "success" : "failure", nmb_namestr(question_name), subrec->subnet_name)); + if(success) { + /* Enter the registered name into the subnet name database before calling + the success function. */ + standard_success_register(subrec, rrec->userdata, question_name, nb_flags, ttl, registered_ip); + if( rrec->success_fn) + (*(register_name_success_function)rrec->success_fn)(subrec, rrec->userdata, question_name, nb_flags, ttl, registered_ip); + } else { + if( rrec->fail_fn) + (*(register_name_fail_function)rrec->fail_fn)(subrec, rrec, question_name); + /* Remove the name. */ + standard_fail_register( subrec, rrec, question_name); + } + + /* Ensure we don't retry. */ + remove_response_record(subrec, rrec); } + /**************************************************************************** - Try and register one of our names on the unicast subnet - multihomed. +initiate one multi-homed name registration packet +****************************************************************************/ +static void multihomed_register_one(struct nmb_name *nmbname, + uint16 nb_flags, + register_name_success_function success_fn, + register_name_fail_function fail_fn, + struct in_addr ip, + const char *tag) +{ + struct userdata_struct *userdata; + struct in_addr wins_ip = wins_srv_ip_tag(tag, ip); + fstring ip_str; + + userdata = (struct userdata_struct *)malloc(sizeof(*userdata) + strlen(tag) + 1); + if (!userdata) { + DEBUG(0,("Failed to allocate userdata structure!\n")); + return; + } + ZERO_STRUCTP(userdata); + userdata->userdata_len = strlen(tag) + 1; + strlcpy(userdata->data, tag, userdata->userdata_len); + + fstrcpy(ip_str, inet_ntoa(ip)); + + DEBUG(6,("Registering name %s IP %s with WINS server %s using tag '%s'\n", + nmb_namestr(nmbname), ip_str, inet_ntoa(wins_ip), tag)); + + if (queue_register_multihomed_name(unicast_subnet, + register_name_response, + register_name_timeout_response, + success_fn, + fail_fn, + userdata, + nmbname, + nb_flags, + ip, + wins_ip) == NULL) { + DEBUG(0,("multihomed_register_one: Failed to send packet trying to register name %s IP %s\n", + nmb_namestr(nmbname), inet_ntoa(ip))); + } + + free(userdata); +} + + +/**************************************************************************** +we have finished the registration of one IP and need to see if we have +any more IPs left to register with this group of wins server for this name ****************************************************************************/ +static void wins_next_registration(struct response_record *rrec) +{ + struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb; + struct nmb_name *nmbname = &sent_nmb->question.question_name; + uint16 nb_flags = get_nb_flags(sent_nmb->additional->rdata); + struct userdata_struct *userdata = rrec->userdata; + const char *tag; + struct in_addr last_ip; + struct subnet_record *subrec; + + putip(&last_ip,&sent_nmb->additional->rdata[2]); + + if (!userdata) { + /* it wasn't multi-homed */ + return; + } + + tag = (const char *)userdata->data; + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { + if (ip_equal(last_ip, subrec->myip)) { + subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec); + break; + } + } + + if (!subrec) { + /* no more to do! */ + return; + } + + switch (sent_nmb->header.opcode) { + case NMB_NAME_MULTIHOMED_REG_OPCODE: + multihomed_register_one(nmbname, nb_flags, NULL, NULL, subrec->myip, tag); + break; + case NMB_NAME_REFRESH_OPCODE_8: + queue_wins_refresh(nmbname, + register_name_response, + register_name_timeout_response, + nb_flags, subrec->myip, tag); + break; + } +} -static BOOL multihomed_register_name( struct nmb_name *nmbname, uint16 nb_flags, - register_name_success_function success_fn, - register_name_fail_function fail_fn, - struct userdata_struct *userdata) +/**************************************************************************** + Try and register one of our names on the unicast subnet - multihomed. +****************************************************************************/ +static void multihomed_register_name(struct nmb_name *nmbname, uint16 nb_flags, + register_name_success_function success_fn, + register_name_fail_function fail_fn) { - /* - If we are adding a group name, we just send multiple - register name packets to the WINS server (this is an - internet group name. - - If we are adding a unique name, We need first to add - our names to the unicast subnet namelist. This is - because when a WINS server receives a multihomed - registration request, the first thing it does is to - send a name query to the registering machine, to see - if it has put the name in it's local namelist. - We need the name there so the query response code in - nmbd_incomingrequests.c will find it. - - We are adding this name prematurely (we don't really - have it yet), but as this is on the unicast subnet - only we will get away with this (only the WINS server - will ever query names from us on this subnet). - */ - - int num_ips=0; - int i; - struct in_addr *ip_list = NULL; - struct subnet_record *subrec; - - for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) ) - num_ips++; - - if((ip_list = (struct in_addr *)malloc(num_ips * sizeof(struct in_addr)))==NULL) - { - DEBUG(0,("multihomed_register_name: malloc fail !\n")); - return True; - } - - for( subrec = FIRST_SUBNET, i = 0; - subrec; - subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec), i++ ) - ip_list[i] = subrec->myip; - - (void)add_name_to_subnet( unicast_subnet, nmbname->name, nmbname->name_type, - nb_flags, lp_max_ttl(), SELF_NAME, - num_ips, ip_list); - - /* Now try and register the name, num_ips times. On the last time use - the given success and fail functions. */ - - for( i = 0; i < num_ips; i++) - { - if(queue_register_multihomed_name( unicast_subnet, - register_name_response, - register_name_timeout_response, - (i == num_ips - 1) ? success_fn : NULL, - (i == num_ips - 1) ? fail_fn : NULL, - (i == num_ips - 1) ? userdata : NULL, - nmbname, - nb_flags, - ip_list[i]) == NULL) - { - DEBUG(0,("multihomed_register_name: Failed to send packet trying to \ -register name %s IP %s\n", nmb_namestr(nmbname), inet_ntoa(ip_list[i]) )); - - SAFE_FREE(ip_list); - return True; - } - } - - SAFE_FREE(ip_list); - - return False; + /* + If we are adding a group name, we just send multiple + register name packets to the WINS server (this is an + internet group name. + + If we are adding a unique name, We need first to add + our names to the unicast subnet namelist. This is + because when a WINS server receives a multihomed + registration request, the first thing it does is to + send a name query to the registering machine, to see + if it has put the name in it's local namelist. + We need the name there so the query response code in + nmbd_incomingrequests.c will find it. + + We are adding this name prematurely (we don't really + have it yet), but as this is on the unicast subnet + only we will get away with this (only the WINS server + will ever query names from us on this subnet). + */ + int num_ips=0; + int i, t; + struct subnet_record *subrec; + char **wins_tags; + struct in_addr *ip_list; + + for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) ) + num_ips++; + + if((ip_list = (struct in_addr *)malloc(num_ips * sizeof(struct in_addr)))==NULL) { + DEBUG(0,("multihomed_register_name: malloc fail !\n")); + return; + } + + for (subrec = FIRST_SUBNET, i = 0; + subrec; + subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec), i++ ) { + ip_list[i] = subrec->myip; + } + + add_name_to_subnet(unicast_subnet, nmbname->name, nmbname->name_type, + nb_flags, lp_max_ttl(), SELF_NAME, + num_ips, ip_list); + + /* get the list of wins tags - we try to register for each of them */ + wins_tags = wins_srv_tags(); + + /* Now try and register the name for each wins tag. Note that + at this point we only register our first IP with each wins + group. We will register the rest from + wins_next_registration() when we get the reply for this + one. That follows the way W2K does things (tridge) + */ + for (t=0; wins_tags && wins_tags[t]; t++) { + multihomed_register_one(nmbname, nb_flags, + success_fn, fail_fn, + ip_list[0], + wins_tags[t]); + } + + wins_srv_tags_free(wins_tags); + + SAFE_FREE(ip_list); } + /**************************************************************************** Try and register one of our names. ****************************************************************************/ - -BOOL register_name(struct subnet_record *subrec, +void register_name(struct subnet_record *subrec, char *name, int type, uint16 nb_flags, register_name_success_function success_fn, register_name_fail_function fail_fn, struct userdata_struct *userdata) { - struct nmb_name nmbname; - - make_nmb_name(&nmbname, name, type); - - /* Always set the NB_ACTIVE flag on the name we are - registering. Doesn't make sense without it. - */ - - nb_flags |= NB_ACTIVE; - - /* If this is the unicast subnet, and we are a multi-homed - host, then register a multi-homed name. */ - - if( (subrec == unicast_subnet) && we_are_multihomed()) - return multihomed_register_name(&nmbname, nb_flags, - success_fn, fail_fn, - userdata); - - if(queue_register_name( subrec, - register_name_response, - register_name_timeout_response, - success_fn, - fail_fn, - userdata, - &nmbname, - nb_flags) == NULL) - { - DEBUG(0,("register_name: Failed to send packet trying to register name %s\n", - nmb_namestr(&nmbname))); - return True; - } - return False; + struct nmb_name nmbname; + + make_nmb_name(&nmbname, name, type); + + /* Always set the NB_ACTIVE flag on the name we are + registering. Doesn't make sense without it. + */ + + nb_flags |= NB_ACTIVE; + + if (subrec == unicast_subnet) { + /* we now always do multi-homed registration if we are + registering to a WINS server. This copes much + better with complex WINS setups */ + multihomed_register_name(&nmbname, nb_flags, + success_fn, fail_fn); + return; + } + + if (queue_register_name(subrec, + register_name_response, + register_name_timeout_response, + success_fn, + fail_fn, + userdata, + &nmbname, + nb_flags) == NULL) { + DEBUG(0,("register_name: Failed to send packet trying to register name %s\n", + nmb_namestr(&nmbname))); + } } + /**************************************************************************** - Try and refresh one of our names. + Try and refresh one of our names. This is *only* called for WINS refresh ****************************************************************************/ - -BOOL refresh_name(struct subnet_record *subrec, struct name_record *namerec, - refresh_name_success_function success_fn, - refresh_name_fail_function fail_fn, - struct userdata_struct *userdata) +void wins_refresh_name(struct name_record *namerec) { - int i; - - /* - * Go through and refresh the name for all known ip addresses. - * Only call the success/fail function on the last one (it should - * only be done once). - */ - - for( i = 0; i < namerec->data.num_ips; i++) - { - if(queue_refresh_name( subrec, - register_name_response, - register_name_timeout_response, - (i == (namerec->data.num_ips - 1)) ? success_fn : NULL, - (i == (namerec->data.num_ips - 1)) ? fail_fn : NULL, - (i == (namerec->data.num_ips - 1)) ? userdata : NULL, - namerec, - namerec->data.ip[i]) == NULL) - { - DEBUG(0,("refresh_name: Failed to send packet trying to refresh name %s\n", - nmb_namestr(&namerec->name))); - return True; - } - } - return False; + int t; + char **wins_tags; + + /* get the list of wins tags - we try to refresh for each of them */ + wins_tags = wins_srv_tags(); + + for (t=0; wins_tags && wins_tags[t]; t++) { + queue_wins_refresh(&namerec->name, + register_name_response, + register_name_timeout_response, + namerec->data.nb_flags, + namerec->data.ip[0], wins_tags[t]); + } + + wins_srv_tags_free(wins_tags); } diff --git a/source3/nmbd/nmbd_namerelease.c b/source3/nmbd/nmbd_namerelease.c index fd35181f33..0611ca9323 100644 --- a/source3/nmbd/nmbd_namerelease.c +++ b/source3/nmbd/nmbd_namerelease.c @@ -28,85 +28,72 @@ ****************************************************************************/ static void release_name_response(struct subnet_record *subrec, - struct response_record *rrec, struct packet_struct *p) + struct response_record *rrec, struct packet_struct *p) { - /* - * If we are releasing broadcast, then getting a response is an - * error. If we are releasing unicast, then we expect to get a response. - */ - - struct nmb_packet *nmb = &p->packet.nmb; - BOOL bcast = nmb->header.nm_flags.bcast; - BOOL success = True; - struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name; - struct nmb_name *answer_name = &nmb->answers->rr_name; - struct in_addr released_ip; - - /* Sanity check. Ensure that the answer name in the incoming packet is the - same as the requested name in the outgoing packet. */ - - if(!nmb_name_equal(question_name, answer_name)) - { - DEBUG(0,("release_name_response: Answer name %s differs from question \ -name %s.\n", nmb_namestr(answer_name), nmb_namestr(question_name))); - return; - } - - if(bcast) - { - /* Someone sent a response. This shouldn't happen/ */ - DEBUG(1,("release_name_response: A response for releasing name %s was received on a \ -broadcast subnet %s. This should not happen !\n", nmb_namestr(answer_name), subrec->subnet_name)); - return; - } - else - { - /* Unicast - check to see if the response allows us to release the name. */ - if(nmb->header.rcode != 0) - { - /* Error code - we were told not to release the name ! What now ! */ - success = False; - - DEBUG(0,("release_name_response: WINS server at IP %s rejected our \ -name release of name %s with error code %d.\n", inet_ntoa(p->ip), - nmb_namestr(answer_name), nmb->header.rcode)); - - } - else if(nmb->header.opcode == NMB_WACK_OPCODE) - { - /* WINS server is telling us to wait. Pretend we didn't get - the response but don't send out any more release requests. */ - - DEBUG(5,("release_name_response: WACK from WINS server %s in releasing \ -name %s on subnet %s.\n", inet_ntoa(p->ip), nmb_namestr(answer_name), subrec->subnet_name)); - - rrec->repeat_count = 0; - /* How long we should wait for. */ - rrec->repeat_time = p->timestamp + nmb->answers->ttl; - rrec->num_msgs--; - return; - } - } - - DEBUG(5,("release_name_response: %s in releasing name %s on subnet %s.\n", - success ? "success" : "failure", nmb_namestr(answer_name), subrec->subnet_name)); - - if(success) - { - putip((char*)&released_ip ,&nmb->answers->rdata[2]); - - if(rrec->success_fn) - (*(release_name_success_function)rrec->success_fn)(subrec, rrec->userdata, answer_name, released_ip); - standard_success_release( subrec, rrec->userdata, answer_name, released_ip); - } - else - { - /* We have no standard_fail_release - maybe we should add one ? */ - if(rrec->fail_fn) - (*(release_name_fail_function)rrec->fail_fn)(subrec, rrec, answer_name); - } - - remove_response_record(subrec, rrec); + /* + * If we are releasing broadcast, then getting a response is an + * error. If we are releasing unicast, then we expect to get a response. + */ + struct nmb_packet *nmb = &p->packet.nmb; + BOOL bcast = nmb->header.nm_flags.bcast; + BOOL success = True; + struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name; + struct nmb_name *answer_name = &nmb->answers->rr_name; + struct in_addr released_ip; + + /* Sanity check. Ensure that the answer name in the incoming packet is the + same as the requested name in the outgoing packet. */ + if (!nmb_name_equal(question_name, answer_name)) { + DEBUG(0,("release_name_response: Answer name %s differs from question name %s.\n", + nmb_namestr(answer_name), nmb_namestr(question_name))); + return; + } + + if (bcast) { + /* Someone sent a response to a bcast release? ignore it. */ + return; + } + + /* Unicast - check to see if the response allows us to release the name. */ + if (nmb->header.rcode != 0) { + /* Error code - we were told not to release the name ! What now ! */ + success = False; + + DEBUG(0,("release_name_response: WINS server at IP %s rejected our \ +name release of name %s with error code %d.\n", + inet_ntoa(p->ip), + nmb_namestr(answer_name), nmb->header.rcode)); + } else if (nmb->header.opcode == NMB_WACK_OPCODE) { + /* WINS server is telling us to wait. Pretend we didn't get + the response but don't send out any more release requests. */ + + DEBUG(5,("release_name_response: WACK from WINS server %s in releasing \ +name %s on subnet %s.\n", + inet_ntoa(p->ip), nmb_namestr(answer_name), subrec->subnet_name)); + + rrec->repeat_count = 0; + /* How long we should wait for. */ + rrec->repeat_time = p->timestamp + nmb->answers->ttl; + rrec->num_msgs--; + return; + } + + DEBUG(5,("release_name_response: %s in releasing name %s on subnet %s.\n", + success ? "success" : "failure", nmb_namestr(answer_name), subrec->subnet_name)); + if (success) { + putip((char*)&released_ip ,&nmb->answers->rdata[2]); + + if(rrec->success_fn) + (*(release_name_success_function)rrec->success_fn)(subrec, rrec->userdata, answer_name, released_ip); + standard_success_release( subrec, rrec->userdata, answer_name, released_ip); + } else { + /* We have no standard_fail_release - maybe we should add one ? */ + if (rrec->fail_fn) { + (*(release_name_fail_function)rrec->fail_fn)(subrec, rrec, answer_name); + } + } + + remove_response_record(subrec, rrec); } /**************************************************************************** @@ -114,120 +101,122 @@ name %s on subnet %s.\n", inet_ntoa(p->ip), nmb_namestr(answer_name), subrec->su ****************************************************************************/ static void release_name_timeout_response(struct subnet_record *subrec, - struct response_record *rrec) + struct response_record *rrec) { - /* - * If we are releasing unicast, then NOT getting a response is an - * error - we could not release the name. If we are releasing broadcast, - * then we don't expect to get a response. - */ - - struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb; - BOOL bcast = sent_nmb->header.nm_flags.bcast; - BOOL success = False; - struct nmb_name *question_name = &sent_nmb->question.question_name; - struct in_addr released_ip; - - if(bcast) - { - if(rrec->num_msgs == 0) - { - /* Not receiving a message is success for broadcast release. */ - success = True; - - /* Get the ip address we were trying to release. */ - putip((char*)&released_ip ,&sent_nmb->additional->rdata[2]); - } - } - else - { - /* Unicast - if no responses then it's an error. */ - if(rrec->num_msgs == 0) - { - DEBUG(2,("release_name_timeout_response: WINS server at address %s is not \ -responding.\n", inet_ntoa(rrec->packet->ip))); - - /* Keep trying to contact the WINS server periodically. This allows - us to work correctly if the WINS server is down temporarily when - we want to delete the name. */ - - /* Reset the number of attempts to zero and double the interval between - retries. Max out at 5 minutes. */ - rrec->repeat_count = 3; - rrec->repeat_interval *= 2; - if(rrec->repeat_interval > (5 * 60)) - rrec->repeat_interval = (5 * 60); - rrec->repeat_time = time(NULL) + rrec->repeat_interval; - - DEBUG(5,("release_name_timeout_response: increasing WINS timeout to %d seconds.\n", - (int)rrec->repeat_interval)); - return; /* Don't remove the response record. */ - } - } - - DEBUG(5,("release_name_timeout_response: %s in releasing name %s on subnet %s.\n", - success ? "success" : "failure", nmb_namestr(question_name), subrec->subnet_name)); - - if(success && rrec->success_fn) - { - if(rrec->success_fn) - (*(release_name_success_function)rrec->success_fn)(subrec, rrec->userdata, question_name, released_ip); - standard_success_release( subrec, rrec->userdata, question_name, released_ip); - } - else - { - /* We have no standard_fail_release - maybe we should add one ? */ - if( rrec->fail_fn) - (*(release_name_fail_function)rrec->fail_fn)(subrec, rrec, question_name); - } - - remove_response_record(subrec, rrec); + /* a release is *always* considered to be successful when it + times out. This doesn't cause problems as if a WINS server + doesn't respond and someone else wants the name then the + normal WACK/name query from the WINS server will cope */ + struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb; + BOOL bcast = sent_nmb->header.nm_flags.bcast; + struct nmb_name *question_name = &sent_nmb->question.question_name; + struct in_addr released_ip; + + /* Get the ip address we were trying to release. */ + putip((char*)&released_ip ,&sent_nmb->additional->rdata[2]); + + if (!bcast) { + /* mark the WINS server temporarily dead */ + wins_srv_died(rrec->packet->ip, released_ip); + } + + DEBUG(5,("release_name_timeout_response: success in releasing name %s on subnet %s.\n", + nmb_namestr(question_name), subrec->subnet_name)); + + if (rrec->success_fn) { + (*(release_name_success_function)rrec->success_fn)(subrec, rrec->userdata, question_name, released_ip); + } + + standard_success_release( subrec, rrec->userdata, question_name, released_ip); + remove_response_record(subrec, rrec); } + +/* + when releasing a name with WINS we need to send the release to each of + the WINS groups +*/ +static void wins_release_name(struct name_record *namerec, + release_name_success_function success_fn, + release_name_fail_function fail_fn, + struct userdata_struct *userdata) +{ + int t, i; + char **wins_tags; + + /* get the list of wins tags - we try to release for each of them */ + wins_tags = wins_srv_tags(); + + for (t=0;wins_tags && wins_tags[t]; t++) { + for (i = 0; i < namerec->data.num_ips; i++) { + struct in_addr wins_ip = wins_srv_ip_tag(wins_tags[t], namerec->data.ip[i]); + + BOOL last_one = ((i==namerec->data.num_ips - 1) && !wins_tags[t+1]); + if (queue_release_name(unicast_subnet, + release_name_response, + release_name_timeout_response, + last_one?success_fn : NULL, + last_one? fail_fn : NULL, + last_one? userdata : NULL, + &namerec->name, + namerec->data.nb_flags, + namerec->data.ip[i], + wins_ip) == NULL) { + DEBUG(0,("release_name: Failed to send packet trying to release name %s IP %s\n", + nmb_namestr(&namerec->name), inet_ntoa(namerec->data.ip[i]) )); + } + } + } + + wins_srv_tags_free(wins_tags); +} + + /**************************************************************************** Try and release one of our names. ****************************************************************************/ -BOOL release_name(struct subnet_record *subrec, struct name_record *namerec, - release_name_success_function success_fn, - release_name_fail_function fail_fn, - struct userdata_struct *userdata) +void release_name(struct subnet_record *subrec, struct name_record *namerec, + release_name_success_function success_fn, + release_name_fail_function fail_fn, + struct userdata_struct *userdata) { - int i; - - /* Ensure it's a SELF name, and in the ACTIVE state. */ - if((namerec->data.source != SELF_NAME) || !NAME_IS_ACTIVE(namerec)) - { - DEBUG(0,("release_name: Cannot release name %s from subnet %s. Source was %d \n", - nmb_namestr(&namerec->name), subrec->subnet_name, namerec->data.source)); - return True; - } - - /* Set the name into the deregistering state. */ - namerec->data.nb_flags |= NB_DEREG; - - /* - * Go through and release the name for all known ip addresses. - * Only call the success/fail function on the last one (it should - * only be done once). - */ - - for( i = 0; i < namerec->data.num_ips; i++) - { - if(queue_release_name( subrec, - release_name_response, - release_name_timeout_response, - (i == (namerec->data.num_ips - 1)) ? success_fn : NULL, - (i == (namerec->data.num_ips - 1)) ? fail_fn : NULL, - (i == (namerec->data.num_ips - 1)) ? userdata : NULL, - &namerec->name, - namerec->data.nb_flags, - namerec->data.ip[i]) == NULL) - { - DEBUG(0,("release_name: Failed to send packet trying to release name %s IP %s\n", - nmb_namestr(&namerec->name), inet_ntoa(namerec->data.ip[i]) )); - return True; - } - } - return False; + int i; + + /* Ensure it's a SELF name, and in the ACTIVE state. */ + if ((namerec->data.source != SELF_NAME) || !NAME_IS_ACTIVE(namerec)) { + DEBUG(0,("release_name: Cannot release name %s from subnet %s. Source was %d \n", + nmb_namestr(&namerec->name), subrec->subnet_name, namerec->data.source)); + return; + } + + /* Set the name into the deregistering state. */ + namerec->data.nb_flags |= NB_DEREG; + + /* wins releases are a bit different */ + if (subrec == unicast_subnet) { + wins_release_name(namerec, success_fn, fail_fn, userdata); + return; + } + + /* + * Go through and release the name for all known ip addresses. + * Only call the success/fail function on the last one (it should + * only be done once). + */ + for (i = 0; i < namerec->data.num_ips; i++) { + if (queue_release_name(subrec, + release_name_response, + release_name_timeout_response, + (i == (namerec->data.num_ips - 1)) ? success_fn : NULL, + (i == (namerec->data.num_ips - 1)) ? fail_fn : NULL, + (i == (namerec->data.num_ips - 1)) ? userdata : NULL, + &namerec->name, + namerec->data.nb_flags, + namerec->data.ip[i], + subrec->bcast_ip) == NULL) { + DEBUG(0,("release_name: Failed to send packet trying to release name %s IP %s\n", + nmb_namestr(&namerec->name), inet_ntoa(namerec->data.ip[i]) )); + } + } } diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index a11b30b1dc..a20ebf16fd 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -237,40 +237,44 @@ static BOOL create_and_init_additional_record(struct packet_struct *packet, uint16 nb_flags, struct in_addr *register_ip) { - struct nmb_packet *nmb = &packet->packet.nmb; - - if((nmb->additional = (struct res_rec *)malloc(sizeof(struct res_rec))) == NULL) - { - DEBUG(0,("initiate_name_register_packet: malloc fail for additional record.\n")); - return False; - } - - memset((char *)nmb->additional,'\0',sizeof(struct res_rec)); - - nmb->additional->rr_name = nmb->question.question_name; - nmb->additional->rr_type = RR_TYPE_NB; - nmb->additional->rr_class = RR_CLASS_IN; - - /* See RFC 1002, sections 5.1.1.1, 5.1.1.2 and 5.1.1.3 */ - if (nmb->header.nm_flags.bcast) - nmb->additional->ttl = PERMANENT_TTL; - else - nmb->additional->ttl = lp_max_ttl(); - - nmb->additional->rdlength = 6; - - set_nb_flags(nmb->additional->rdata,nb_flags); - - /* Set the address for the name we are registering. */ - putip(&nmb->additional->rdata[2], register_ip); - - /* Ensure that we send out the file descriptor to give us the - the specific source address we are registering as our - IP source address. */ - - packet->fd = find_subnet_fd_for_address( *register_ip ); - - return True; + struct nmb_packet *nmb = &packet->packet.nmb; + + if((nmb->additional = (struct res_rec *)malloc(sizeof(struct res_rec))) == NULL) { + DEBUG(0,("initiate_name_register_packet: malloc fail for additional record.\n")); + return False; + } + + memset((char *)nmb->additional,'\0',sizeof(struct res_rec)); + + nmb->additional->rr_name = nmb->question.question_name; + nmb->additional->rr_type = RR_TYPE_NB; + nmb->additional->rr_class = RR_CLASS_IN; + + /* See RFC 1002, sections 5.1.1.1, 5.1.1.2 and 5.1.1.3 */ + if (nmb->header.nm_flags.bcast) + nmb->additional->ttl = PERMANENT_TTL; + else + nmb->additional->ttl = lp_max_ttl(); + + nmb->additional->rdlength = 6; + + set_nb_flags(nmb->additional->rdata,nb_flags); + + /* Set the address for the name we are registering. */ + putip(&nmb->additional->rdata[2], register_ip); + + /* + it turns out that Jeremys code was correct, we are supposed + to send registrations from the IP we are registering. The + trick is what to do on timeouts! When we send on a + non-routable IP then the reply will timeout, and we should + treat this as success, not failure. That means we go into + our standard refresh cycle for that name which copes nicely + with disconnected networks. + */ + packet->fd = find_subnet_fd_for_address(*register_ip); + + return True; } /*************************************************************************** @@ -345,28 +349,28 @@ static BOOL initiate_name_register_packet( struct packet_struct *packet, Sends out a multihomed name register. **************************************************************************/ -static BOOL initiate_multihomed_name_register_packet( struct packet_struct *packet, - uint16 nb_flags, struct in_addr *register_ip) +static BOOL initiate_multihomed_name_register_packet(struct packet_struct *packet, + uint16 nb_flags, struct in_addr *register_ip) { - struct nmb_packet *nmb = &packet->packet.nmb; - fstring second_ip_buf; - - fstrcpy(second_ip_buf, inet_ntoa(packet->ip)); + struct nmb_packet *nmb = &packet->packet.nmb; + fstring second_ip_buf; - nmb->header.opcode = NMB_NAME_MULTIHOMED_REG_OPCODE; - nmb->header.arcount = 1; - - nmb->header.nm_flags.recursion_desired = True; + fstrcpy(second_ip_buf, inet_ntoa(packet->ip)); - if(create_and_init_additional_record(packet, nb_flags, register_ip) == False) - return False; + nmb->header.opcode = NMB_NAME_MULTIHOMED_REG_OPCODE; + nmb->header.arcount = 1; - DEBUG(4,("initiate_multihomed_name_register_packet: sending registration \ + nmb->header.nm_flags.recursion_desired = True; + + if(create_and_init_additional_record(packet, nb_flags, register_ip) == False) + return False; + + DEBUG(4,("initiate_multihomed_name_register_packet: sending registration \ for name %s IP %s (bcast=%s) to IP %s\n", - nmb_namestr(&nmb->additional->rr_name), inet_ntoa(*register_ip), - BOOLSTR(nmb->header.nm_flags.bcast), second_ip_buf )); + nmb_namestr(&nmb->additional->rr_name), inet_ntoa(*register_ip), + BOOLSTR(nmb->header.nm_flags.bcast), second_ip_buf )); - return send_netbios_packet( packet ); + return send_netbios_packet( packet ); } /*************************************************************************** @@ -510,65 +514,123 @@ struct response_record *queue_register_name( struct subnet_record *subrec, return rrec; } + /**************************************************************************** - Queue a multihomed register name packet to the broadcast address of a subnet. + Queue a refresh name packet to the broadcast address of a subnet. +****************************************************************************/ +void queue_wins_refresh(struct nmb_name *nmbname, + response_function resp_fn, + timeout_response_function timeout_fn, + uint16 nb_flags, + struct in_addr refresh_ip, + const char *tag) +{ + struct packet_struct *p; + struct response_record *rrec; + struct in_addr wins_ip; + struct userdata_struct *userdata; + fstring ip_str; + + wins_ip = wins_srv_ip_tag(tag, refresh_ip); + + if ((p = create_and_init_netbios_packet(nmbname, False, False, wins_ip)) == NULL) { + return; + } + + if (!initiate_name_refresh_packet(p, nb_flags, &refresh_ip)) { + p->locked = False; + free_packet(p); + return; + } + + fstrcpy(ip_str, inet_ntoa(refresh_ip)); + + DEBUG(6,("Refreshing name %s IP %s with WINS server %s using tag '%s'\n", + nmb_namestr(nmbname), ip_str, inet_ntoa(wins_ip), tag)); + + userdata = (struct userdata_struct *)malloc(sizeof(*userdata) + strlen(tag) + 1); + if (!userdata) { + DEBUG(0,("Failed to allocate userdata structure!\n")); + return; + } + ZERO_STRUCTP(userdata); + userdata->userdata_len = strlen(tag) + 1; + strlcpy(userdata->data, tag, userdata->userdata_len); + + if ((rrec = make_response_record(unicast_subnet, + p, + resp_fn, timeout_fn, + NULL, + NULL, + userdata)) == NULL) { + p->locked = False; + free_packet(p); + return; + } + + free(userdata); + + /* we don't want to repeat refresh packets */ + rrec->repeat_count = 0; +} + + +/**************************************************************************** + Queue a multihomed register name packet to a given WINS server IP ****************************************************************************/ struct response_record *queue_register_multihomed_name( struct subnet_record *subrec, - response_function resp_fn, - timeout_response_function timeout_fn, - register_name_success_function success_fn, - register_name_fail_function fail_fn, - struct userdata_struct *userdata, - struct nmb_name *nmbname, - uint16 nb_flags, - struct in_addr register_ip) + response_function resp_fn, + timeout_response_function timeout_fn, + register_name_success_function success_fn, + register_name_fail_function fail_fn, + struct userdata_struct *userdata, + struct nmb_name *nmbname, + uint16 nb_flags, + struct in_addr register_ip, + struct in_addr wins_ip) { - struct packet_struct *p; - struct response_record *rrec; - BOOL ret; - - /* Sanity check. */ - if(subrec != unicast_subnet) - { - DEBUG(0,("queue_register_multihomed_name: should only be done on \ + struct packet_struct *p; + struct response_record *rrec; + BOOL ret; + + /* Sanity check. */ + if(subrec != unicast_subnet) { + DEBUG(0,("queue_register_multihomed_name: should only be done on \ unicast subnet. subnet is %s\n.", subrec->subnet_name )); - return NULL; - } + return NULL; + } - if(assert_check_subnet(subrec)) - return NULL; + if(assert_check_subnet(subrec)) + return NULL; - if(( p = create_and_init_netbios_packet(nmbname, False, True, - subrec->bcast_ip)) == NULL) - return NULL; - - if (nb_flags & NB_GROUP) - ret = initiate_name_register_packet( p, nb_flags, ®ister_ip); - else - ret = initiate_multihomed_name_register_packet( p, nb_flags, ®ister_ip); - - if(ret == False) - { - p->locked = False; - free_packet(p); - return NULL; - } - - if((rrec = make_response_record(subrec, /* subnet record. */ - p, /* packet we sent. */ - resp_fn, /* function to call on response. */ - timeout_fn, /* function to call on timeout. */ - (success_function)success_fn, /* function to call on operation success. */ - (fail_function)fail_fn, /* function to call on operation fail. */ - userdata)) == NULL) - { - p->locked = False; - free_packet(p); - return NULL; - } + if ((p = create_and_init_netbios_packet(nmbname, False, True, wins_ip)) == NULL) + return NULL; + + if (nb_flags & NB_GROUP) + ret = initiate_name_register_packet( p, nb_flags, ®ister_ip); + else + ret = initiate_multihomed_name_register_packet(p, nb_flags, ®ister_ip); + + if (ret == False) { + p->locked = False; + free_packet(p); + return NULL; + } - return rrec; + if ((rrec = make_response_record(subrec, /* subnet record. */ + p, /* packet we sent. */ + resp_fn, /* function to call on response. */ + timeout_fn, /* function to call on timeout. */ + (success_function)success_fn, /* function to call on operation success. */ + (fail_function)fail_fn, /* function to call on operation fail. */ + userdata)) == NULL) { + p->locked = False; + free_packet(p); + return NULL; + } + + return rrec; } /**************************************************************************** @@ -576,14 +638,15 @@ unicast subnet. subnet is %s\n.", subrec->subnet_name )); ****************************************************************************/ struct response_record *queue_release_name( struct subnet_record *subrec, - response_function resp_fn, - timeout_response_function timeout_fn, - release_name_success_function success_fn, - release_name_fail_function fail_fn, - struct userdata_struct *userdata, - struct nmb_name *nmbname, - uint16 nb_flags, - struct in_addr release_ip) + response_function resp_fn, + timeout_response_function timeout_fn, + release_name_success_function success_fn, + release_name_fail_function fail_fn, + struct userdata_struct *userdata, + struct nmb_name *nmbname, + uint16 nb_flags, + struct in_addr release_ip, + struct in_addr dest_ip) { struct packet_struct *p; struct response_record *rrec; @@ -592,7 +655,7 @@ struct response_record *queue_release_name( struct subnet_record *subrec, return NULL; if ((p = create_and_init_netbios_packet(nmbname, (subrec != unicast_subnet), False, - subrec->bcast_ip)) == NULL) + dest_ip)) == NULL) return NULL; if(initiate_name_release_packet( p, nb_flags, &release_ip) == False) @@ -628,52 +691,6 @@ struct response_record *queue_release_name( struct subnet_record *subrec, return rrec; } -/**************************************************************************** - Queue a refresh name packet to the broadcast address of a subnet. -****************************************************************************/ - -struct response_record *queue_refresh_name( struct subnet_record *subrec, - response_function resp_fn, - timeout_response_function timeout_fn, - refresh_name_success_function success_fn, - refresh_name_fail_function fail_fn, - struct userdata_struct *userdata, - struct name_record *namerec, - struct in_addr refresh_ip) -{ - struct packet_struct *p; - struct response_record *rrec; - - if(assert_check_subnet(subrec)) - return NULL; - - if(( p = create_and_init_netbios_packet(&namerec->name, (subrec != unicast_subnet), False, - subrec->bcast_ip)) == NULL) - return NULL; - - if( !initiate_name_refresh_packet( p, namerec->data.nb_flags, &refresh_ip ) ) - { - p->locked = False; - free_packet(p); - return NULL; - } - - if((rrec = make_response_record(subrec, /* subnet record. */ - p, /* packet we sent. */ - resp_fn, /* function to call on response. */ - timeout_fn, /* function to call on timeout. */ - (success_function)success_fn, /* function to call on operation success. */ - (fail_function)fail_fn, /* function to call on operation fail. */ - userdata)) == NULL) - { - p->locked = False; - free_packet(p); - return NULL; - } - - return rrec; -} - /**************************************************************************** Queue a query name packet to the broadcast address of a subnet. ****************************************************************************/ @@ -1849,8 +1866,9 @@ BOOL listen_for_packets(BOOL run_election) inet_ntoa(packet->ip),packet->port)); free_packet(packet); } else if ((ip_equal(loopback_ip, packet->ip) || - ismyip(packet->ip)) && packet->port == global_nmb_port) { - DEBUG(7,("discarding own packet from %s:%d\n", + ismyip(packet->ip)) && packet->port == global_nmb_port && + packet->packet.nmb.header.nm_flags.bcast) { + DEBUG(7,("discarding own bcast packet from %s:%d\n", inet_ntoa(packet->ip),packet->port)); free_packet(packet); } else { @@ -1876,7 +1894,7 @@ BOOL listen_for_packets(BOOL run_election) free_packet(packet); } else if ((ip_equal(loopback_ip, packet->ip) || ismyip(packet->ip)) && packet->port == DGRAM_PORT) { - DEBUG(7,("discarding own packet from %s:%d\n", + DEBUG(7,("discarding own dgram packet from %s:%d\n", inet_ntoa(packet->ip),packet->port)); free_packet(packet); } else { diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index a2da5ddf4a..7e8c8025ae 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -97,12 +97,12 @@ void remove_response_record(struct subnet_record *subrec, **************************************************************************/ struct response_record *make_response_record( struct subnet_record *subrec, - struct packet_struct *p, - response_function resp_fn, - timeout_response_function timeout_fn, - success_function success_fn, - fail_function fail_fn, - struct userdata_struct *userdata) + struct packet_struct *p, + response_function resp_fn, + timeout_response_function timeout_fn, + success_function success_fn, + fail_function fail_fn, + struct userdata_struct *userdata) { struct response_record *rrec; struct nmb_packet *nmb = &p->packet.nmb; diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 6c6e7adbb8..e68fc1589c 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -233,12 +233,17 @@ BOOL create_subnets(void) struct in_addr unicast_ip, ipzero; extern struct in_addr loopback_ip; - if(num_interfaces == 0) - { - DEBUG(0,("create_subnets: No local interfaces !\n")); - return False; + if(num_interfaces == 0) { + DEBUG(0,("create_subnets: No local interfaces !\n")); + DEBUG(0,("create_subnets: Waiting for an interface to appear ...\n")); + while (iface_count() == 0) { + sleep(5); + load_interfaces(); + } } + num_interfaces = iface_count(); + /* * Create subnets from all the local interfaces and thread them onto * the linked list. @@ -262,45 +267,14 @@ BOOL create_subnets(void) if (!make_normal_subnet(iface)) return False; } - /* - * If we have been configured to use a WINS server, then try and - * get the ip address of it here. If we are the WINS server then - * set the unicast subnet address to be the first of our own real - * addresses. - * - * NOTE: I'm not sure of the implications of WINS server failover - * on this bit of code. Because of failover, the WINS - * server address can change. crh - */ - - if( wins_srv_count() ) - { - struct in_addr real_wins_ip; - real_wins_ip = wins_srv_ip(); - - if (!is_zero_ip(real_wins_ip)) - { - unicast_ip = real_wins_ip; - } - else - { - /* wins_srv_ip() can return a zero IP if all servers are - * either down or incorrectly entered in smb.conf. crh - */ - DEBUG(0,("No 'live' WINS servers found. Check 'wins server' parameter.\n")); - return False; - } - } - else if(lp_we_are_a_wins_server()) - { - /* Pick the first interface ip address as the WINS server ip. */ - unicast_ip = *iface_n_ip(0); - } - else - { - /* We should not be using a WINS server at all. Set the - ip address of the subnet to be zero. */ - zero_ip(&unicast_ip); + if (lp_we_are_a_wins_server()) { + /* Pick the first interface ip address as the WINS server ip. */ + unicast_ip = *iface_n_ip(0); + } else { + /* note that we do not set the wins server IP here. We just + set it at zero and let the wins registration code cope + with getting the IPs right for each packet */ + zero_ip(&unicast_ip); } /* @@ -341,16 +315,13 @@ BOOL create_subnets(void) /******************************************************************* Function to tell us if we can use the unicast subnet. ******************************************************************/ - BOOL we_are_a_wins_client(void) { - static int cache_we_are_a_wins_client = -1; - - if(cache_we_are_a_wins_client == -1) - cache_we_are_a_wins_client = (is_zero_ip(unicast_subnet->myip) ? - False : True); + if (wins_srv_count() > 0) { + return True; + } - return cache_we_are_a_wins_client; + return False; } /******************************************************************* diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 3332e99e9d..13554a9430 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -983,7 +983,7 @@ static void wins_multihomed_register_query_success(struct subnet_record *subrec, if( (namerec == NULL) || (namerec->data.source != REGISTER_NAME) || !WINS_STATE_ACTIVE(namerec) ) { DEBUG(3,("wins_multihomed_register_query_success: name %s is not in the correct state to add \ -a subsequent IP addess.\n", nmb_namestr(question_name) )); +a subsequent IP address.\n", nmb_namestr(question_name) )); send_wins_name_registration_response(RFS_ERR, 0, orig_reg_packet); orig_reg_packet->locked = False; @@ -1100,6 +1100,16 @@ to register name %s from IP %s.", nmb_namestr(question), inet_ntoa(p->ip) )); namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); + /* + * if the record exists but NOT in active state, + * consider it dead. + */ + if ((namerec != NULL) && !WINS_STATE_ACTIVE(namerec)) { + DEBUG(5,("wins_process_multihomed_name_registration_request: Name (%s) in WINS was not active - removing it.\n", nmb_namestr(question))); + remove_name_from_namelist(subrec, namerec); + namerec = NULL; + } + /* * Deal with the case where the name found was a dns entry. * Remove it as we now have a NetBIOS client registering the -- cgit From b2edf254eda92f775e7d3d9b6793b4d77f9000b6 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 17 Aug 2002 17:00:51 +0000 Subject: sync 3.0 branch with head (This used to be commit 3928578b52cfc949be5e0ef444fce1558d75f290) --- source3/nmbd/asyncdns.c | 1 + source3/nmbd/nmbd.c | 11 ++-- source3/nmbd/nmbd_become_dmb.c | 2 +- source3/nmbd/nmbd_mynames.c | 2 +- source3/nmbd/nmbd_nameregister.c | 22 ++++---- source3/nmbd/nmbd_packets.c | 25 +++++++-- source3/nmbd/nmbd_processlogon.c | 113 +++++++++++++++++++++++++++++++++++---- 7 files changed, 146 insertions(+), 30 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 6c2f8de3b1..c86ee69a09 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -122,6 +122,7 @@ void kill_async_dns_child(void) { if (child_pid > 0) { kill(child_pid, SIGTERM); + child_pid = -1; } } diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index d30efb550c..05ea4997d5 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -269,9 +269,8 @@ static BOOL reload_interfaces(time_t t) static BOOL reload_nmbd_services(BOOL test) { BOOL ret; - extern fstring remote_machine; - fstrcpy( remote_machine, "nmbd" ); + set_remote_machine_name("nmbd"); if ( lp_loaded() ) { pstring fname; @@ -861,8 +860,10 @@ static void usage(char *pname) DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); - if ( !open_sockets( is_daemon, global_nmb_port ) ) + if ( !open_sockets( is_daemon, global_nmb_port ) ) { + kill_async_dns_child(); return 1; + } /* Determine all the IP addresses we have. */ load_interfaces(); @@ -871,6 +872,7 @@ static void usage(char *pname) if( False == create_subnets() ) { DEBUG(0,("ERROR: Failed when creating subnet lists. Exiting.\n")); + kill_async_dns_child(); exit(1); } @@ -882,6 +884,7 @@ static void usage(char *pname) if( !initialise_wins() ) { DEBUG( 0, ( "nmbd: Failed when initialising WINS server.\n" ) ); + kill_async_dns_child(); exit(1); } @@ -896,6 +899,7 @@ static void usage(char *pname) if( False == register_my_workgroup_and_names() ) { DEBUG(0,("ERROR: Failed when creating my my workgroup. Exiting.\n")); + kill_async_dns_child(); exit(1); } @@ -906,5 +910,6 @@ static void usage(char *pname) if (dbf) x_fclose(dbf); + kill_async_dns_child(); return(0); } diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index 7f4a7a2144..ccc1f7e8ad 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -347,7 +347,7 @@ static void become_domain_master_browser_wins(char *workgroup_name) we can become a domain master browser. */ - DEBUG(0,("become_domain_master_browser_wins: querying WINS server at IP %s \ + DEBUG(0,("become_domain_master_browser_wins: querying WINS server from IP %s \ for domain master browser name %s on workgroup %s\n", inet_ntoa(unicast_subnet->myip), nmb_namestr(&nmbname), workgroup_name)); diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index 345245c57d..ba7d509a77 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -225,7 +225,7 @@ void refresh_my_names(time_t t) wins_refresh_name(namerec); } namerec->data.death_time = t + lp_max_ttl(); - namerec->data.refresh_time = t + MIN(lp_max_ttl(), MAX_REFRESH_TIME); + namerec->data.refresh_time = t + MIN(lp_max_ttl()/2, MAX_REFRESH_TIME); } } } diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index 4ac5473d4a..b6d3c20d99 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -106,17 +106,7 @@ static void register_name_response(struct subnet_record *subrec, success = False; } else { /* Unicast - check to see if the response allows us to have the name. */ - if(nmb->header.rcode != 0) { - /* Error code - we didn't get the name. */ - success = False; - - DEBUG(0,("register_name_response: %sserver at IP %s rejected our name registration of %s IP %s with error code %d.\n", - subrec==unicast_subnet?"WINS ":"", - inet_ntoa(p->ip), - nmb_namestr(answer_name), - reg_name, - nmb->header.rcode)); - } else if (nmb->header.opcode == NMB_WACK_OPCODE) { + if (nmb->header.opcode == NMB_WACK_OPCODE) { /* WINS server is telling us to wait. Pretend we didn't get the response but don't send out any more register requests. */ @@ -128,6 +118,16 @@ static void register_name_response(struct subnet_record *subrec, rrec->repeat_time = p->timestamp + nmb->answers->ttl; rrec->num_msgs--; return; + } else if (nmb->header.rcode != 0) { + /* Error code - we didn't get the name. */ + success = False; + + DEBUG(0,("register_name_response: %sserver at IP %s rejected our name registration of %s IP %s with error code %d.\n", + subrec==unicast_subnet?"WINS ":"", + inet_ntoa(p->ip), + nmb_namestr(answer_name), + reg_name, + nmb->header.rcode)); } else { success = True; /* Get the data we need to pass to the success function. */ diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index a20ebf16fd..d252b98ed6 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -705,14 +705,33 @@ struct response_record *queue_query_name( struct subnet_record *subrec, { struct packet_struct *p; struct response_record *rrec; + struct in_addr to_ip; if(assert_check_subnet(subrec)) return NULL; + to_ip = subrec->bcast_ip; + + /* queries to the WINS server turn up here as queries to IP 0.0.0.0 + These need to be handled a bit differently */ + if (subrec->type == UNICAST_SUBNET && is_zero_ip(to_ip)) { + /* what we really need to do is loop over each of our wins + * servers and wins server tags here, but that just doesn't + * fit our architecture at the moment (userdata may already + * be used when we get here). For now we just query the first + * active wins server on the first tag. */ + char **tags = wins_srv_tags(); + if (!tags) { + return NULL; + } + to_ip = wins_srv_ip_tag(tags[0], to_ip); + wins_srv_tags_free(tags); + } + if(( p = create_and_init_netbios_packet(nmbname, (subrec != unicast_subnet), (subrec == unicast_subnet), - subrec->bcast_ip)) == NULL) + to_ip)) == NULL) return NULL; if(lp_bind_interfaces_only()) { @@ -1670,7 +1689,7 @@ void retransmit_or_expire_response_records(time_t t) to IP %s on subnet %s\n", rrec->response_id, inet_ntoa(rrec->packet->ip), subrec->subnet_name)); } - rrec->repeat_time += rrec->repeat_interval; + rrec->repeat_time = t + rrec->repeat_interval; rrec->repeat_count--; } else @@ -1950,7 +1969,7 @@ BOOL send_mailslot(BOOL unique, char *mailslot,char *buf,int len, /* Setup the smb part. */ ptr -= 4; /* XXX Ugliness because of handling of tcp SMB length. */ memcpy(tmp,ptr,4); - set_message(ptr,17,17 + len,True); + set_message(ptr,17,23 + len,True); memcpy(ptr,tmp,4); SCVAL(ptr,smb_com,SMBtrans); diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 23e4f935ca..d6605d08f5 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -4,6 +4,8 @@ Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 Copyright (C) Jeremy Allison 1994-1998 + Copyright (C) Jim McDonough 2002 + Copyright (C) Anthony Liguori 2002 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -284,19 +286,108 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", /* Construct reply. */ q = outbuf; - if (SVAL(uniuser, 0) == 0) { - SSVAL(q, 0, SAMLOGON_UNK_R); /* user unknown */ - } else { - SSVAL(q, 0, SAMLOGON_R); - } - q += 2; - - q += dos_PutUniCode(q, reply_name,sizeof(pstring), True); - q += dos_PutUniCode(q, ascuser, sizeof(pstring), True); - q += dos_PutUniCode(q, global_myworkgroup,sizeof(pstring), True); + /* we want the simple version unless we are an ADS PDC..which means */ + /* never, at least for now */ + if ((ntversion < 11) || (SEC_ADS != lp_security()) || (ROLE_DOMAIN_PDC != lp_server_role())) { + if (SVAL(uniuser, 0) == 0) { + SSVAL(q, 0, SAMLOGON_UNK_R); /* user unknown */ + } else { + SSVAL(q, 0, SAMLOGON_R); + } + + q += 2; + + q += dos_PutUniCode(q, reply_name,sizeof(pstring), True); + q += dos_PutUniCode(q, ascuser, sizeof(pstring), True); + q += dos_PutUniCode(q, global_myworkgroup,sizeof(pstring), True); + } +#ifdef HAVE_ADS + else { + GUID domain_guid; + pstring domain; + char *component, *dc, *q1; + uint8 size; + + safe_strcpy(domain, lp_realm(), sizeof(domain)); + + if (SVAL(uniuser, 0) == 0) { + SSVAL(q, 0, SAMLOGON_AD_UNK_R); /* user unknown */ + } else { + SSVAL(q, 0, SAMLOGON_AD_R); + } + q += 2; + + SSVAL(q, 0, 0); + q += 2; + SIVAL(q, 0, ADS_PDC|ADS_GC|ADS_LDAP|ADS_DS| + ADS_KDC|ADS_TIMESERV|ADS_CLOSEST|ADS_WRITABLE); + q += 4; + + /* Push Domain GUID */ + if (False == secrets_fetch_domain_guid(domain, &domain_guid)) { + DEBUG(2, ("Could not fetch DomainGUID for %s\n", domain)); + return; + } + memcpy(q, &domain_guid, sizeof(domain_guid)); + q += sizeof(domain_guid); + + /* Push domain components */ + dc = domain; + q1 = q; + while ((component = strsep(&dc, "."))) { + size = push_ascii(&q[1], component, -1, 0); + SCVAL(q, 0, size); + q += (size + 1); + } + SCVAL(q, 0, 0); q++; + SSVAL(q, 0, 0x18c0); /* not sure what this is for, but */ + q += 2; /* it must follow the domain name. */ + + /* Push dns host name */ + size = push_ascii(&q[1], global_myname, -1, 0); + SCVAL(q, 0, size); + q += (size + 1); + SSVAL(q, 0, 0x18c0); /* not sure what this is for, but */ + q += 2; /* it must follow the domain name. */ + + /* Push NETBIOS of domain */ + size = push_ascii(&q[1], domain, -1, STR_UPPER); + SCVAL(q, 0, size); + q += (size + 1); + SCVAL(q, 0, 0); q++; /* is this a null terminator or empty field */ + /* null terminator would not be needed because size is included */ + + /* Push NETBIOS of hostname */ + size = push_ascii(&q[1], my_name, -1, 0); + SCVAL(q, 0, size); + q += (size + 1); + SCVAL(q, 0, 0); q++; /* null terminator or empty field? */ + + /* Push user account */ + size = push_ascii(&q[1], ascuser, -1, 0); + SCVAL(q, 0, size); + q += (size + 1); + + /* Push 'Default-First-Site-Name' */ + size = push_ascii(&q[1], "Default-First-Site-Name", -1, 0); + SCVAL(q, 0, size); + q += (size + 1); + + SSVAL(q, 0, 0xc000); /* unknown */ + SCVAL(q, 2, PTR_DIFF(q,q1)); + SCVAL(q, 3, 0x10); /* unknown */ + q += 4; + + SIVAL(q, 0, 0x00000002); q += 4; /* unknown */ + SIVAL(q, 0, (iface_ip(p->ip))->s_addr); q += 4; + SIVAL(q, 0, 0x00000000); q += 4; /* unknown */ + SIVAL(q, 0, 0x00000000); q += 4; /* unknown */ + } +#endif /* tell the client what version we are */ - SIVAL(q, 0, 1); /* our ntversion */ + SIVAL(q, 0, ((ntversion < 11) || (SEC_ADS != lp_security())) ? 1 : 13); + /* our ntversion */ SSVAL(q, 4, 0xffff); /* our lmnttoken */ SSVAL(q, 6, 0xffff); /* our lm20token */ q += 8; -- cgit From a834a73e341059be154426390304a42e4a011f72 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 25 Sep 2002 15:19:00 +0000 Subject: sync'ing up for 3.0alpha20 release (This used to be commit 65e7b5273bb58802bf0c389b77f7fcae0a1f6139) --- source3/nmbd/nmbd_processlogon.c | 3 ++- source3/nmbd/nmbd_synclists.c | 6 +++++- 2 files changed, 7 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index d6605d08f5..b65cebe203 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -334,7 +334,8 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", /* Push domain components */ dc = domain; q1 = q; - while ((component = strsep(&dc, "."))) { + while ((component = strtok(dc, "."))) { + dc = NULL; size = push_ascii(&q[1], component, -1, 0); SCVAL(q, 0, size); q += (size + 1); diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index bf03d4d1cf..24adf4e69f 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -70,7 +70,11 @@ static void sync_child(char *name, int nm_type, uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0; struct nmb_name called, calling; - if (!cli_initialise(&cli) || !cli_connect(&cli, name, &ip)) { + /* W2K DMB's return empty browse lists on port 445. Use 139. + * Patch from Andy Levine andyl@epicrealm.com. + */ + + if (!cli_initialise(&cli) || !cli_set_port(&cli, 139) || !cli_connect(&cli, name, &ip)) { return; } -- cgit From a287517c7e94ce581c2a1d5f8034b3f6967abf87 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 3 Oct 2002 17:30:57 +0000 Subject: Merging tridge's wins fixes. Tridge - we're supposed to be keeping 3.0 up to date :-). Jeremy. (This used to be commit 5959f35db6b4b23c591799dad7587e6616e5a998) --- source3/nmbd/nmbd_winsserver.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 13554a9430..ee47cff049 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1952,8 +1952,8 @@ void nmbd_wins_new_entry(int msg_type, pid_t src, void *buf, size_t len) /* I'm giving up on multi homed. Too much complex to understand */ if (record->wins_flags&WINS_MHOMED) { - if (! namerec->data.wins_flags&WINS_ACTIVE) { - if ( !namerec->data.wins_flags&WINS_RELEASED && !namerec->data.wins_flags&WINS_NGROUP) + if (! (namerec->data.wins_flags&WINS_ACTIVE)) { + if ( !(namerec->data.wins_flags&WINS_RELEASED) && !(namerec->data.wins_flags&WINS_NGROUP)) overwrite=True; } else { -- cgit From 641dd258adb2a3d265b89b2726d93fac3942e36a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 8 Oct 2002 18:26:12 +0000 Subject: Ensure we register the 1c name on the unicast subnet. Jeremy. (This used to be commit e1ea20d2d14b9671503eeeccddc7683cc94371c0) --- source3/nmbd/nmbd_logonnames.c | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_logonnames.c b/source3/nmbd/nmbd_logonnames.c index 1406515d6b..28e0e8a02b 100644 --- a/source3/nmbd/nmbd_logonnames.c +++ b/source3/nmbd/nmbd_logonnames.c @@ -109,6 +109,16 @@ in workgroup %s on subnet %s\n", /* Tell the namelist writer to write out a change. */ subrec->work_changed = True; + /* + * Add the WORKGROUP<1C> name to the UNICAST subnet with the IP address + * for this subnet so we will respond to queries on this name. + */ + { + struct nmb_name nmbname; + make_nmb_name(&nmbname,global_myworkgroup,0x1c); + insert_permanent_name_into_unicast(subrec, &nmbname, 0x1c); + } + DEBUG(0,("become_logon_server_success: Samba is now a logon server \ for workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name)); } -- cgit From dc5297f413c40f04e1fdae719e29d949e3301091 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 9 Nov 2002 16:57:45 +0000 Subject: Sync with HEAD (This used to be commit 1a25dc776ddc36de9a214e023becff1ceb10290c) --- source3/nmbd/nmbd.c | 130 ++++++++++++---------------------------------------- 1 file changed, 29 insertions(+), 101 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 05ea4997d5..9f4a934fae 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -3,6 +3,7 @@ NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Jeremy Allison 1997-2002 + Copyright (C) Jelmer Vernooij 2002 (Conversion to popt) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -655,41 +656,32 @@ static BOOL init_structs(void) return( True ); } -/**************************************************************************** ** - Usage on the program. - **************************************************************************** */ - -static void usage(char *pname) -{ - - printf( "Usage: %s [-DaiohV] [-H lmhosts file] [-d debuglevel] [-l log basename]\n", pname ); - printf( " [-n name] [-p port] [-s configuration file]\n" ); - printf( "\t-D Become a daemon (default)\n" ); - printf( "\t-a Append to log file (default)\n" ); - printf( "\t-i Run interactive (not a daemon)\n" ); - printf( "\t-o Overwrite log file, don't append\n" ); - printf( "\t-h Print usage\n" ); - printf( "\t-V Print version\n" ); - printf( "\t-H hosts file Load a netbios hosts file\n" ); - printf( "\t-d debuglevel Set the debuglevel\n" ); - printf( "\t-l log basename. Basename for log/debug files\n" ); - printf( "\t-n netbiosname. Primary netbios name\n" ); - printf( "\t-p port Listen on the specified port\n" ); - printf( "\t-s configuration file Configuration file name\n" ); - printf( "\n"); -} - - /**************************************************************************** ** main program **************************************************************************** */ - int main(int argc,char *argv[]) + int main(int argc, const char *argv[]) { - int opt; - extern char *optarg; - extern BOOL append_log; - BOOL opt_interactive = False; - pstring logfile; + extern BOOL append_log; + static BOOL opt_interactive = False; + poptContext pc; + struct poptOption long_options[] = { + POPT_AUTOHELP + {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon(default)" }, + {"log-append", 'a', POPT_ARG_VAL, &append_log, True, "Append to log file" }, + {"interactive", 'i', POPT_ARG_VAL, &opt_interactive, True, "Run interactive (not a daemon)" }, + {"log-overwrite", 'o', POPT_ARG_VAL, &append_log, False, "Overwrite log file, don't append" }, + {"hosts", 'H', POPT_ARG_STRING, dyn_LMHOSTSFILE, 'H', "Load a netbios hosts file"}, + {"port", 'p', POPT_ARG_INT, &global_nmb_port, NMB_PORT, "Listen on the specified port" }, + {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug }, + {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile }, + {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_socket_options }, + {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version }, + {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_netbios_name }, + {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_log_base }, + { NULL } + }; + int opt; + pstring logfile; append_log = True; /* Default, override with '-o' option. */ @@ -703,13 +695,6 @@ static void usage(char *pname) slprintf(logfile, sizeof(logfile)-1, "%s/log.nmbd", dyn_LOGFILEBASE); lp_set_logfile(logfile); - /* this is for people who can't start the program correctly */ - while (argc > 1 && (*argv[1] != '-')) - { - argv++; - argc--; - } - fault_setup((void (*)(void *))fault_continue ); /* POSIX demands that signals are inherited. If the invoking process has @@ -730,70 +715,13 @@ static void usage(char *pname) #if defined(SIGUSR2) BlockSignals(True, SIGUSR2); #endif + pc = poptGetContext("nmbd", argc, argv, long_options, 0); + + while((opt = poptGetNextOpt(pc)) != -1) + { } - while( EOF != - (opt = getopt( argc, argv, "Vaos:T:I:C:bAB:N:Rn:l:d:Dp:hSH:G:f:i" )) ) - { - switch (opt) - { - case 's': - pstrcpy(dyn_CONFIGFILE, optarg); - break; - case 'N': - case 'B': - case 'I': - case 'C': - case 'G': - DEBUG(0,("Obsolete option '%c' used\n",opt)); - break; - case 'i': - opt_interactive = True; - break; - case 'H': - pstrcpy(dyn_LMHOSTSFILE, optarg); - break; - case 'n': - pstrcpy(global_myname,optarg); - strupper(global_myname); - break; - case 'l': - slprintf(logfile, sizeof(logfile)-1, "%s/log.nmbd", optarg); - lp_set_logfile(logfile); - break; - case 'a': - append_log = True; - break; - case 'o': - append_log = False; - break; - case 'D': - is_daemon = True; - break; - case 'd': - DEBUGLEVEL = atoi(optarg); - break; - case 'p': - global_nmb_port = atoi(optarg); - break; - case 'h': - usage(argv[0]); - exit(0); - break; - case 'V': - printf( "Version %s\n", VERSION ); - exit(0); - break; - default: - if( !is_a_socket(0) ) - { - DEBUG(0,("Incorrect program usage - is the command line correct?\n")); - usage(argv[0]); - exit(0); - } - break; - } - } - + poptFreeContext(pc); + setup_logging( argv[0], opt_interactive ); reopen_logs(); -- cgit From f09109c7bc32966bb464df0712583b30602d6ad0 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 9 Nov 2002 17:08:58 +0000 Subject: Last sync with HEAD (This used to be commit 1175b62337f5c29954cd5e8dfdc2327c9c80748c) --- source3/nmbd/nmbd.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 9f4a934fae..50730d40f3 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -661,15 +661,12 @@ static BOOL init_structs(void) **************************************************************************** */ int main(int argc, const char *argv[]) { - extern BOOL append_log; static BOOL opt_interactive = False; poptContext pc; struct poptOption long_options[] = { POPT_AUTOHELP {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon(default)" }, - {"log-append", 'a', POPT_ARG_VAL, &append_log, True, "Append to log file" }, {"interactive", 'i', POPT_ARG_VAL, &opt_interactive, True, "Run interactive (not a daemon)" }, - {"log-overwrite", 'o', POPT_ARG_VAL, &append_log, False, "Overwrite log file, don't append" }, {"hosts", 'H', POPT_ARG_STRING, dyn_LMHOSTSFILE, 'H', "Load a netbios hosts file"}, {"port", 'p', POPT_ARG_INT, &global_nmb_port, NMB_PORT, "Listen on the specified port" }, {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug }, @@ -683,8 +680,6 @@ static BOOL init_structs(void) int opt; pstring logfile; - append_log = True; /* Default, override with '-o' option. */ - global_nmb_port = NMB_PORT; global_in_nmbd = True; -- cgit From 2f194322d419350f35a48dff750066894d68eccf Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 12 Nov 2002 23:20:50 +0000 Subject: Removed global_myworkgroup, global_myname, global_myscope. Added liberal dashes of const. This is a rather large check-in, some things may break. It does compile though :-). Jeremy. (This used to be commit f755711df8f74f9b8e8c1a2b0d07d02a931eeb89) --- source3/nmbd/nmbd.c | 102 +---------------------------------- source3/nmbd/nmbd_become_dmb.c | 25 ++++----- source3/nmbd/nmbd_become_lmb.c | 32 ++++++----- source3/nmbd/nmbd_browsesync.c | 17 +++--- source3/nmbd/nmbd_elections.c | 23 ++++---- source3/nmbd/nmbd_incomingdgrams.c | 30 +++++------ source3/nmbd/nmbd_incomingrequests.c | 15 +++--- source3/nmbd/nmbd_logonnames.c | 19 +++---- source3/nmbd/nmbd_mynames.c | 27 +++++----- source3/nmbd/nmbd_namelistdb.c | 4 +- source3/nmbd/nmbd_nameregister.c | 6 +-- source3/nmbd/nmbd_packets.c | 14 +++-- source3/nmbd/nmbd_processlogon.c | 22 ++++---- source3/nmbd/nmbd_sendannounce.c | 66 ++++++++++++----------- source3/nmbd/nmbd_serverlistdb.c | 31 +++++------ source3/nmbd/nmbd_subnetdb.c | 3 -- source3/nmbd/nmbd_synclists.c | 2 +- source3/nmbd/nmbd_workgroupdb.c | 15 +++--- 18 files changed, 158 insertions(+), 295 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 50730d40f3..5987d70a45 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -27,10 +27,6 @@ int ClientNMB = -1; int ClientDGRAM = -1; int global_nmb_port = -1; -extern pstring global_myname; -extern fstring global_myworkgroup; -extern char **my_netbios_names; - extern BOOL global_in_nmbd; /* are we running as a daemon ? */ @@ -564,98 +560,6 @@ static BOOL open_sockets(BOOL isdaemon, int port) return( True ); } -/**************************************************************************** ** - Initialise connect, service and file structs. - **************************************************************************** */ - -static BOOL init_structs(void) -{ - extern fstring local_machine; - char *p, **ptr; - int namecount; - int n; - int nodup; - char *nbname; - - if (! *global_myname) - { - fstrcpy( global_myname, myhostname() ); - p = strchr_m( global_myname, '.' ); - if (p) - *p = 0; - } - strupper( global_myname ); - - /* Add any NETBIOS name aliases. Ensure that the first entry - is equal to global_myname. - */ - /* Work out the max number of netbios aliases that we have */ - ptr = lp_netbios_aliases(); - namecount = 0; - if (ptr) - for( ; *ptr; namecount++,ptr++ ) - ; - if ( *global_myname ) - namecount++; - - /* Allocate space for the netbios aliases */ - my_netbios_names = (char **)malloc( sizeof(char *) * (namecount+1) ); - if( NULL == my_netbios_names ) - { - DEBUG( 0, ( "init_structs: malloc fail.\n" ) ); - return( False ); - } - - /* Use the global_myname string first */ - namecount=0; - if ( *global_myname ) - my_netbios_names[namecount++] = global_myname; - - ptr = lp_netbios_aliases(); - if (ptr) - { - while ( *ptr ) - { - nbname = strdup(*ptr); - if (nbname == NULL) - { - DEBUG(0,("init_structs: malloc fail when allocating names.\n")); - return False; - } - strupper( nbname ); - /* Look for duplicates */ - nodup=1; - for( n=0; nname, subrec->subnet_name)); /* Set the state back to DOMAIN_NONE. */ work->dom_state = DOMAIN_NONE; - if((servrec = find_server_in_workgroup( work, global_myname)) == NULL) + if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) { DEBUG(0,("become_domain_master_fail: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - global_myname, work->work_group, subrec->subnet_name)); + global_myname(), work->work_group, subrec->subnet_name)); return; } @@ -92,11 +89,11 @@ workgroup %s on subnet %s\n", registered_name->name, subrec->subnet_name)); return; } - if((servrec = find_server_in_workgroup( work, global_myname)) == NULL) + if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) { DEBUG(0,("become_domain_master_stage2: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - global_myname, registered_name->name, subrec->subnet_name)); + global_myname(), registered_name->name, subrec->subnet_name)); work->dom_state = DOMAIN_NONE; return; } @@ -112,7 +109,7 @@ in workgroup %s on subnet %s\n", if( DEBUGLVL( 0 ) ) { - dbgtext( "*****\n\nSamba server %s ", global_myname ); + dbgtext( "*****\n\nSamba server %s ", global_myname() ); dbgtext( "is now a domain master browser for " ); dbgtext( "workgroup %s ", work->work_group ); dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name ); @@ -128,7 +125,7 @@ in workgroup %s on subnet %s\n", will stop us syncing with ourself if we are also a local master browser. */ - make_nmb_name(&nmbname, global_myname, 0x20); + make_nmb_name(&nmbname, global_myname(), 0x20); work->dmb_name = nmbname; /* Pick the first interface ip address as the domain master browser ip. */ @@ -266,7 +263,7 @@ querying WINS server for name %s.\n", Attempt to become a domain master browser on all broadcast subnets. ****************************************************************************/ -static void become_domain_master_browser_bcast(char *workgroup_name) +static void become_domain_master_browser_bcast(const char *workgroup_name) { struct subnet_record *subrec; @@ -315,7 +312,7 @@ for domain master browser on workgroup %s\n", subrec->subnet_name, workgroup_nam Attempt to become a domain master browser by registering with WINS. ****************************************************************************/ -static void become_domain_master_browser_wins(char *workgroup_name) +static void become_domain_master_browser_wins(const char *workgroup_name) { struct work_record *work; @@ -391,9 +388,9 @@ void add_domain_names(time_t t) 1.9.16p2 to 1.9.16p11 - due to a bug in namelogon.c, cannot provide domain master / domain logon services. */ - become_domain_master_browser_wins(global_myworkgroup); + become_domain_master_browser_wins(lp_workgroup()); } else - become_domain_master_browser_bcast(global_myworkgroup); + become_domain_master_browser_bcast(lp_workgroup()); } } diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index 3e0884567e..7b8ba14bb5 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -23,8 +23,6 @@ #include "includes.h" -extern pstring global_myname; - extern uint16 samba_nb_type; /* Samba's NetBIOS name type. */ /******************************************************************* @@ -89,11 +87,11 @@ subnet %s.\n", workgroup_name, subrec->subnet_name )); return; } - if((servrec = find_server_in_workgroup( work, global_myname)) == NULL) + if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) { DEBUG(0,("reset_workgroup_state: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - global_myname, work->work_group, subrec->subnet_name)); + global_myname(), work->work_group, subrec->subnet_name)); work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; return; } @@ -153,7 +151,7 @@ static void unbecome_local_master_success(struct subnet_record *subrec, if( DEBUGLVL( 0 ) ) { dbgtext( "*****\n\n" ); - dbgtext( "Samba name server %s ", global_myname ); + dbgtext( "Samba name server %s ", global_myname() ); dbgtext( "has stopped being a local master browser " ); dbgtext( "for workgroup %s ", released_name->name ); dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name ); @@ -188,7 +186,7 @@ Removing from namelist anyway.\n", nmb_namestr(fail_name))); if( DEBUGLVL( 0 ) ) { dbgtext( "*****\n\n" ); - dbgtext( "Samba name server %s ", global_myname ); + dbgtext( "Samba name server %s ", global_myname() ); dbgtext( "has stopped being a local master browser " ); dbgtext( "for workgroup %s ", fail_name->name ); dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name ); @@ -285,11 +283,11 @@ void unbecome_local_master_browser(struct subnet_record *subrec, struct work_rec DEBUG(2,("unbecome_local_master_browser: unbecoming local master for workgroup %s \ on subnet %s\n",work->work_group, subrec->subnet_name)); - if(find_server_in_workgroup( work, global_myname) == NULL) + if(find_server_in_workgroup( work, global_myname()) == NULL) { DEBUG(0,("unbecome_local_master_browser: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - global_myname, work->work_group, subrec->subnet_name)); + global_myname(), work->work_group, subrec->subnet_name)); work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; return; } @@ -346,11 +344,11 @@ workgroup %s on subnet %s\n", registered_name->name, subrec->subnet_name)); return; } - if((servrec = find_server_in_workgroup( work, global_myname)) == NULL) + if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) { DEBUG(0,("become_local_master_stage2: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - global_myname, registered_name->name, subrec->subnet_name)); + global_myname(), registered_name->name, subrec->subnet_name)); work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; return; } @@ -368,7 +366,7 @@ on subnet %s\n", work->work_group, subrec->subnet_name)); subrec->work_changed = True; /* Add this name to the workgroup as local master browser. */ - set_workgroup_local_master_browser_name( work, global_myname); + set_workgroup_local_master_browser_name( work, global_myname()); /* Count the number of servers we have on our list. If it's less than 10 (just a heuristic) request the servers @@ -403,7 +401,7 @@ on subnet %s\n", work->work_group, subrec->subnet_name)); if( DEBUGLVL( 0 ) ) { dbgtext( "*****\n\n" ); - dbgtext( "Samba name server %s ", global_myname ); + dbgtext( "Samba name server %s ", global_myname() ); dbgtext( "is now a local master browser " ); dbgtext( "for workgroup %s ", work->work_group ); dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name ); @@ -493,11 +491,11 @@ workgroup %s on subnet %s\n", work_name, subrec->subnet_name)); return; } - if(find_server_in_workgroup(work, global_myname) == NULL) + if(find_server_in_workgroup(work, global_myname()) == NULL) { DEBUG(0,("become_local_master_fail1: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - global_myname, work->work_group, subrec->subnet_name)); + global_myname(), work->work_group, subrec->subnet_name)); return; } @@ -536,11 +534,11 @@ void become_local_master_browser(struct subnet_record *subrec, struct work_recor return; } - if(find_server_in_workgroup( work, global_myname) == NULL) + if(find_server_in_workgroup( work, global_myname()) == NULL) { DEBUG(0,("become_local_master_browser: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - global_myname, work->work_group, subrec->subnet_name)); + global_myname(), work->work_group, subrec->subnet_name)); return; } @@ -583,7 +581,7 @@ in workgroup %s on subnet %s\n", as the workgroup name. ****************************************************************/ -void set_workgroup_local_master_browser_name( struct work_record *work, char *newname) +void set_workgroup_local_master_browser_name( struct work_record *work, const char *newname) { DEBUG(5,("set_workgroup_local_master_browser_name: setting local master name to '%s' \ for workgroup %s.\n", newname, work->work_group )); diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 5dcc8cce19..3a20f07b05 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -24,9 +24,6 @@ #include "includes.h" #include "smb.h" -extern pstring global_myname; -extern fstring global_myworkgroup; - /* This is our local master browser list database. */ extern ubi_dlList lmb_browserlist[]; @@ -129,7 +126,7 @@ static void announce_local_master_browser_to_domain_master_browser( struct work_ SCVAL(p,0,ANN_MasterAnnouncement); p++; - StrnCpy(p,global_myname,15); + StrnCpy(p,global_myname(),15); strupper(p); p = skip_string(p,1); @@ -142,7 +139,7 @@ static void announce_local_master_browser_to_domain_master_browser( struct work_ } send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), - global_myname, 0x0, work->dmb_name.name, 0x0, + global_myname(), 0x0, work->dmb_name.name, 0x0, work->dmb_addr, FIRST_SUBNET->myip, DGRAM_PORT); } @@ -611,12 +608,12 @@ void collect_all_workgroup_names_from_wins_server(time_t t) return; /* Check to see if we are a domain master browser on the unicast subnet. */ - if((work = find_workgroup_on_subnet( unicast_subnet, global_myworkgroup)) == NULL) + if((work = find_workgroup_on_subnet( unicast_subnet, lp_workgroup())) == NULL) { if( DEBUGLVL( 0 ) ) { dbgtext( "collect_all_workgroup_names_from_wins_server:\n" ); - dbgtext( "Cannot find my workgroup %s ", global_myworkgroup ); + dbgtext( "Cannot find my workgroup %s ", lp_workgroup() ); dbgtext( "on subnet %s.\n", unicast_subnet->subnet_name ); } return; @@ -660,7 +657,7 @@ void sync_all_dmbs(time_t t) /* Check to see if we are a domain master browser on the unicast subnet. */ - work = find_workgroup_on_subnet(unicast_subnet, global_myworkgroup); + work = find_workgroup_on_subnet(unicast_subnet, lp_workgroup()); if (!work) return; if (!AM_DOMAIN_MASTER_BROWSER(work)) @@ -671,14 +668,14 @@ void sync_all_dmbs(time_t t) /* count how many syncs we might need to do */ for (work=unicast_subnet->workgrouplist; work; work = work->next) { - if (strcmp(global_myworkgroup, work->work_group)) { + if (strcmp(lp_workgroup(), work->work_group)) { count++; } } /* sync with a probability of 1/count */ for (work=unicast_subnet->workgrouplist; work; work = work->next) { - if (strcmp(global_myworkgroup, work->work_group)) { + if (strcmp(lp_workgroup(), work->work_group)) { if (((unsigned)sys_random()) % count != 0) continue; lastrun = t; diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index acff7a72e8..976abbed25 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -23,17 +23,14 @@ #include "includes.h" -extern pstring global_myname; -extern fstring global_myworkgroup; - /* Election parameters. */ extern time_t StartupTime; /**************************************************************************** Send an election datagram packet. **************************************************************************/ -static void send_election_dgram(struct subnet_record *subrec, char *workgroup_name, - uint32 criterion, int timeup,char *server_name) +static void send_election_dgram(struct subnet_record *subrec, const char *workgroup_name, + uint32 criterion, int timeup,const char *server_name) { pstring outbuf; char *p; @@ -55,7 +52,7 @@ static void send_election_dgram(struct subnet_record *subrec, char *workgroup_na p = skip_string(p,1); send_mailslot(False, BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), - global_myname, 0, + global_myname(), 0, workgroup_name, 0x1e, subrec->bcast_ip, subrec->myip, DGRAM_PORT); } @@ -92,7 +89,7 @@ static void check_for_master_browser_fail( struct subnet_record *subrec, return; } - if (strequal(work->work_group, global_myworkgroup)) + if (strequal(work->work_group, lp_workgroup())) { if (lp_local_master()) @@ -128,7 +125,7 @@ void check_master_browser_exists(time_t t) { static time_t lastrun=0; struct subnet_record *subrec; - char *workgroup_name = global_myworkgroup; + const char *workgroup_name = lp_workgroup(); if (!lastrun) lastrun = t; @@ -198,7 +195,7 @@ yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name )); } send_election_dgram(subrec, work->work_group, work->ElectionCriterion, - t - StartupTime, global_myname); + t - StartupTime, global_myname()); if (work->ElectionCount++ >= 4) { @@ -238,7 +235,7 @@ static BOOL win_election(struct work_record *work, int version, version, ELECTION_VERSION, criterion, mycriterion, timeup, mytimeup, - server_name, global_myname)); + server_name, global_myname())); if (version > ELECTION_VERSION) return(False); @@ -255,7 +252,7 @@ static BOOL win_election(struct work_record *work, int version, if (timeup < mytimeup) return(True); - if (strcasecmp(global_myname, server_name) > 0) + if (strcasecmp(global_myname(), server_name) > 0) return(False); return(True); @@ -290,7 +287,7 @@ void process_election(struct subnet_record *subrec, struct packet_struct *p, cha goto done; } - if (!strequal(work->work_group, global_myworkgroup)) + if (!strequal(work->work_group, lp_workgroup())) { DEBUG(3,("process_election: ignoring election request for workgroup %s on subnet %s as this \ is not my workgroup.\n", work->work_group, subrec->subnet_name )); @@ -396,7 +393,7 @@ void nmbd_message_election(int msg_type, pid_t src, void *buf, size_t len) for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { struct work_record *work; for (work = subrec->workgrouplist; work; work = work->next) { - if (strequal(work->work_group, global_myworkgroup)) { + if (strequal(work->work_group, lp_workgroup())) { work->needelection = True; work->ElectionCount=0; work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 261200b4c5..cd6954fc62 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -23,8 +23,6 @@ #include "includes.h" -extern pstring global_myname; -extern fstring global_myworkgroup; extern BOOL found_lm_clients; #if 0 @@ -104,7 +102,7 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p char *comment = buf+31; struct work_record *work; struct server_record *servrec; - char *work_name; + const char *work_name; char *source_name = dgram->source_name.name; START_PROFILE(host_announce); @@ -141,8 +139,8 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p * to be our primary workgroup name. */ - if(strequal(work_name, global_myname)) - work_name = global_myworkgroup; + if(strequal(work_name, global_myname())) + work_name = lp_workgroup(); /* * We are being very agressive here in adding a workgroup @@ -396,10 +394,10 @@ master - ignoring master announce.\n")); goto done; } - if((work = find_workgroup_on_subnet(subrec, global_myworkgroup)) == NULL) + if((work = find_workgroup_on_subnet(subrec, lp_workgroup())) == NULL) { DEBUG(0,("process_master_browser_announce: Cannot find workgroup %s on subnet %s\n", - global_myworkgroup, subrec->subnet_name)); + lp_workgroup(), subrec->subnet_name)); goto done; } @@ -439,7 +437,7 @@ void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct char *announce_name = buf+9; struct work_record *work; struct server_record *servrec; - char *work_name; + const char *work_name; char *source_name = dgram->source_name.name; pstring comment; char *s = buf+9; @@ -489,8 +487,8 @@ originate from OS/2 Warp client. Ignoring packet.\n")); * not needed in the LanMan announce code, but it won't hurt. */ - if(strequal(work_name, global_myname)) - work_name = global_myworkgroup; + if(strequal(work_name, global_myname())) + work_name = lp_workgroup(); /* * We are being very agressive here in adding a workgroup @@ -580,7 +578,7 @@ static void send_backup_list_response(struct subnet_record *subrec, /* We always return at least one name - our own. */ count = 1; - StrnCpy(p,global_myname,15); + StrnCpy(p,global_myname(),15); strupper(p); p = skip_string(p,1); @@ -605,7 +603,7 @@ static void send_backup_list_response(struct subnet_record *subrec, if(count >= (unsigned int)max_number_requested) break; - if(strnequal(servrec->serv.name, global_myname,15)) + if(strnequal(servrec->serv.name, global_myname(),15)) continue; if(!(servrec->serv.type & SV_TYPE_BACKUP_BROWSER)) @@ -629,7 +627,7 @@ static void send_backup_list_response(struct subnet_record *subrec, send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), - global_myname, 0, + global_myname(), 0, send_to_name->name,0, sendto_ip, subrec->myip, port); } @@ -664,7 +662,7 @@ void process_get_backup_list_request(struct subnet_record *subrec, for the requested workgroup. That means it must be our workgroup. */ - if(strequal(workgroup_name, global_myworkgroup) == False) + if(strequal(workgroup_name, lp_workgroup()) == False) { DEBUG(7,("process_get_backup_list_request: Ignoring announce request for workgroup %s.\n", workgroup_name)); @@ -801,7 +799,7 @@ void process_announce_request(struct subnet_record *subrec, struct packet_struct nmb_namestr(&dgram->dest_name))); /* We only send announcement requests on our workgroup. */ - if(strequal(workgroup_name, global_myworkgroup) == False) + if(strequal(workgroup_name, lp_workgroup()) == False) { DEBUG(7,("process_announce_request: Ignoring announce request for workgroup %s.\n", workgroup_name)); @@ -840,7 +838,7 @@ void process_lm_announce_request(struct subnet_record *subrec, struct packet_str nmb_namestr(&dgram->dest_name))); /* We only send announcement requests on our workgroup. */ - if(strequal(workgroup_name, global_myworkgroup) == False) + if(strequal(workgroup_name, lp_workgroup()) == False) { DEBUG(7,("process_lm_announce_request: Ignoring announce request for workgroup %s.\n", workgroup_name)); diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index 834f237a2c..a8168566f1 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -27,8 +27,6 @@ #include "includes.h" -extern fstring global_myworkgroup; - /**************************************************************************** Send a name release response. **************************************************************************/ @@ -100,7 +98,7 @@ subnet %s from owner IP %s\n", * names and *don't set the group bit* !!!!! */ - if( !group && !ismyip(owner_ip) && strequal(question->name, global_myworkgroup) && + if( !group && !ismyip(owner_ip) && strequal(question->name, lp_workgroup()) && ((question->name_type == 0x0) || (question->name_type == 0x1e))) { DEBUG(6,("process_name_release_request: FTP OnNet bug workaround. Ignoring \ @@ -292,20 +290,19 @@ We put our own names first, then in alphabetical order. static int status_compare(char *n1,char *n2) { - extern pstring global_myname; int l1,l2,l3; /* It's a bit tricky because the names are space padded */ for (l1=0;l1<15 && n1[l1] && n1[l1] != ' ';l1++) ; for (l2=0;l2<15 && n2[l2] && n2[l2] != ' ';l2++) ; - l3 = strlen(global_myname); + l3 = strlen(global_myname()); - if ((l1==l3) && strncmp(n1,global_myname,l3) == 0 && - (l2!=l3 || strncmp(n2,global_myname,l3) != 0)) + if ((l1==l3) && strncmp(n1,global_myname(),l3) == 0 && + (l2!=l3 || strncmp(n2,global_myname(),l3) != 0)) return -1; - if ((l2==l3) && strncmp(n2,global_myname,l3) == 0 && - (l1!=l3 || strncmp(n1,global_myname,l3) != 0)) + if ((l2==l3) && strncmp(n2,global_myname(),l3) == 0 && + (l1!=l3 || strncmp(n1,global_myname(),l3) != 0)) return 1; return memcmp(n1,n2,18); diff --git a/source3/nmbd/nmbd_logonnames.c b/source3/nmbd/nmbd_logonnames.c index 28e0e8a02b..b73586aa45 100644 --- a/source3/nmbd/nmbd_logonnames.c +++ b/source3/nmbd/nmbd_logonnames.c @@ -23,9 +23,6 @@ #include "includes.h" -extern pstring global_myname; -extern fstring global_myworkgroup; -extern char **my_netbios_names; extern struct in_addr allones_ip; extern uint16 samba_nb_type; /* Samba's NetBIOS type. */ @@ -47,11 +44,11 @@ workgroup %s on subnet %s\n", fail_name->name, subrec->subnet_name)); return; } - if((servrec = find_server_in_workgroup( work, global_myname)) == NULL) + if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) { DEBUG(0,("become_logon_server_fail: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - global_myname, fail_name->name, subrec->subnet_name)); + global_myname(), fail_name->name, subrec->subnet_name)); work->log_state = LOGON_NONE; return; } @@ -87,11 +84,11 @@ workgroup %s on subnet %s\n", registered_name->name, subrec->subnet_name)); return; } - if((servrec = find_server_in_workgroup( work, global_myname)) == NULL) + if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) { DEBUG(0,("become_logon_server_success: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - global_myname, registered_name->name, subrec->subnet_name)); + global_myname(), registered_name->name, subrec->subnet_name)); work->log_state = LOGON_NONE; return; } @@ -115,7 +112,7 @@ in workgroup %s on subnet %s\n", */ { struct nmb_name nmbname; - make_nmb_name(&nmbname,global_myworkgroup,0x1c); + make_nmb_name(&nmbname,lp_workgroup(),0x1c); insert_permanent_name_into_unicast(subrec, &nmbname, 0x1c); } @@ -152,12 +149,12 @@ void add_logon_names(void) for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { - struct work_record *work = find_workgroup_on_subnet(subrec, global_myworkgroup); + struct work_record *work = find_workgroup_on_subnet(subrec, lp_workgroup()); if (work && (work->log_state == LOGON_NONE)) { struct nmb_name nmbname; - make_nmb_name(&nmbname,global_myworkgroup,0x1c); + make_nmb_name(&nmbname,lp_workgroup(),0x1c); if (find_name_on_subnet(subrec, &nmbname, FIND_SELF_NAME) == NULL) { @@ -165,7 +162,7 @@ void add_logon_names(void) { dbgtext( "add_domain_logon_names:\n" ); dbgtext( "Attempting to become logon server " ); - dbgtext( "for workgroup %s ", global_myworkgroup ); + dbgtext( "for workgroup %s ", lp_workgroup() ); dbgtext( "on subnet %s\n", subrec->subnet_name ); } become_logon_server(subrec, work); diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index ba7d509a77..dd66821839 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -23,9 +23,6 @@ #include "includes.h" -extern char **my_netbios_names; -extern fstring global_myworkgroup; - extern uint16 samba_nb_type; /* Samba's NetBIOS type. */ /**************************************************************************** @@ -51,10 +48,10 @@ void register_my_workgroup_one_subnet(struct subnet_record *subrec) struct work_record *work; /* Create the workgroup on the subnet. */ - if((work = create_workgroup_on_subnet(subrec, global_myworkgroup, + if((work = create_workgroup_on_subnet(subrec, lp_workgroup(), PERMANENT_TTL)) == NULL) { DEBUG(0,("register_my_workgroup_and_names: Failed to create my workgroup %s on subnet %s. \ -Exiting.\n", global_myworkgroup, subrec->subnet_name)); +Exiting.\n", lp_workgroup(), subrec->subnet_name)); return; } @@ -63,14 +60,14 @@ Exiting.\n", global_myworkgroup, subrec->subnet_name)); add_samba_names_to_subnet(subrec); /* Register all our names including aliases. */ - for (i=0; my_netbios_names[i]; i++) { - register_name(subrec, my_netbios_names[i],0x20,samba_nb_type, + for (i=0; my_netbios_names(i); i++) { + register_name(subrec, my_netbios_names(i),0x20,samba_nb_type, NULL, my_name_register_failed, NULL); - register_name(subrec, my_netbios_names[i],0x03,samba_nb_type, + register_name(subrec, my_netbios_names(i),0x03,samba_nb_type, NULL, my_name_register_failed, NULL); - register_name(subrec, my_netbios_names[i],0x00,samba_nb_type, + register_name(subrec, my_netbios_names(i),0x00,samba_nb_type, NULL, my_name_register_failed, NULL); } @@ -133,7 +130,7 @@ BOOL register_my_workgroup_and_names(void) add_samba_names_to_subnet(unicast_subnet); - for (i=0; my_netbios_names[i]; i++) + for (i=0; my_netbios_names(i); i++) { for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { @@ -142,13 +139,13 @@ BOOL register_my_workgroup_and_names(void) */ struct nmb_name nmbname; - make_nmb_name(&nmbname, my_netbios_names[i],0x20); + make_nmb_name(&nmbname, my_netbios_names(i),0x20); insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type); - make_nmb_name(&nmbname, my_netbios_names[i],0x3); + make_nmb_name(&nmbname, my_netbios_names(i),0x3); insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type); - make_nmb_name(&nmbname, my_netbios_names[i],0x0); + make_nmb_name(&nmbname, my_netbios_names(i),0x0); insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type); } } @@ -165,10 +162,10 @@ BOOL register_my_workgroup_and_names(void) */ struct nmb_name nmbname; - make_nmb_name(&nmbname, global_myworkgroup, 0x0); + make_nmb_name(&nmbname, lp_workgroup(), 0x0); insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP); - make_nmb_name(&nmbname, global_myworkgroup, 0x1e); + make_nmb_name(&nmbname, lp_workgroup(), 0x1e); insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP); } diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index bca79ef0c8..7ff2d4171e 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -23,8 +23,6 @@ #include "includes.h" -extern char **my_netbios_names; - uint16 samba_nb_type = 0; /* samba's NetBIOS name type */ @@ -215,7 +213,7 @@ struct name_record *add_name_to_subnet( struct subnet_record *subrec, namerec->data.wins_flags = WINS_ACTIVE; /* If it's our primary name, flag it as so. */ - if( strequal( my_netbios_names[0], name ) ) + if( strequal( my_netbios_names(0), name ) ) namerec->data.nb_flags |= NB_PERM; /* Copy the IPs. */ diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index b6d3c20d99..7bf2584053 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -23,8 +23,6 @@ #include "includes.h" -extern fstring global_myworkgroup; - /* forward declarations */ static void wins_next_registration(struct response_record *rrec); @@ -87,7 +85,7 @@ static void register_name_response(struct subnet_record *subrec, */ #if 1 /* OLD_SAMBA_SERVER_HACK */ - if((nmb->header.rcode == ACT_ERR) && strequal(global_myworkgroup, answer_name->name) && + if((nmb->header.rcode == ACT_ERR) && strequal(lp_workgroup(), answer_name->name) && (answer_name->name_type == 0x1b)) { /* Pretend we did not get this. */ rrec->num_msgs--; @@ -463,7 +461,7 @@ static void multihomed_register_name(struct nmb_name *nmbname, uint16 nb_flags, Try and register one of our names. ****************************************************************************/ void register_name(struct subnet_record *subrec, - char *name, int type, uint16 nb_flags, + const char *name, int type, uint16 nb_flags, register_name_success_function success_fn, register_name_fail_function fail_fn, struct userdata_struct *userdata) diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index d252b98ed6..894f6bb7d6 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1080,15 +1080,14 @@ static void process_browse_packet(struct packet_struct *p, char *buf,int len) struct dgram_packet *dgram = &p->packet.dgram; int command = CVAL(buf,0); struct subnet_record *subrec = find_subnet_for_dgram_browse_packet(p); - extern pstring global_scope; /* Drop the packet if it's a different NetBIOS scope, or the source is from one of our names. */ - if (!strequal(dgram->dest_name.scope, global_scope)) + if (!strequal(dgram->dest_name.scope, global_scope())) { DEBUG(7,("process_browse_packet: Discarding datagram from IP %s. Scope (%s) \ -mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, global_scope)); +mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, global_scope())); return; } @@ -1193,15 +1192,14 @@ static void process_lanman_packet(struct packet_struct *p, char *buf,int len) struct dgram_packet *dgram = &p->packet.dgram; int command = SVAL(buf,0); struct subnet_record *subrec = find_subnet_for_dgram_browse_packet(p); - extern pstring global_scope; /* Drop the packet if it's a different NetBIOS scope, or the source is from one of our names. */ - if (!strequal(dgram->dest_name.scope, global_scope)) + if (!strequal(dgram->dest_name.scope, global_scope())) { DEBUG(7,("process_lanman_packet: Discarding datagram from IP %s. Scope (%s) \ -mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, global_scope)); +mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, global_scope())); return; } @@ -1932,8 +1930,8 @@ BOOL listen_for_packets(BOOL run_election) Construct and send a netbios DGRAM. **************************************************************************/ BOOL send_mailslot(BOOL unique, char *mailslot,char *buf,int len, - char *srcname, int src_type, - char *dstname, int dest_type, + const char *srcname, int src_type, + const char *dstname, int dest_type, struct in_addr dest_ip,struct in_addr src_ip, int dest_port) { diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index b65cebe203..6f2517f39f 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -27,9 +27,6 @@ #include "includes.h" -extern pstring global_myname; -extern fstring global_myworkgroup; - struct sam_database_info { uint32 index; uint32 serial_lo, serial_hi; @@ -93,8 +90,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); return; } - pstrcpy(my_name, global_myname); - strupper(my_name); + pstrcpy(my_name, global_myname()); code = SVAL(buf,0); DEBUG(1,("process_logon_packet: Logon from %s: code = 0x%x\n", inet_ntoa(p->ip), code)); @@ -131,7 +127,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); send_mailslot(True, getdc, outbuf,PTR_DIFF(q,outbuf), - global_myname, 0x0, + global_myname(), 0x0, machine, dgram->source_name.name_type, p->ip, *iface_ip(p->ip), p->port); @@ -198,7 +194,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); q = ALIGN2(q, outbuf); q += dos_PutUniCode(q, my_name, sizeof(pstring), True); /* PDC name */ - q += dos_PutUniCode(q, global_myworkgroup,sizeof(pstring), True); /* Domain name*/ + q += dos_PutUniCode(q, lp_workgroup(),sizeof(pstring), True); /* Domain name*/ SIVAL(q, 0, 1); /* our nt version */ SSVAL(q, 4, 0xffff); /* our lmnttoken */ SSVAL(q, 6, 0xffff); /* our lm20token */ @@ -209,7 +205,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); DEBUG(3,("process_logon_packet: GETDC request from %s at IP %s, \ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", - machine,inet_ntoa(p->ip), reply_name, global_myworkgroup, + machine,inet_ntoa(p->ip), reply_name, lp_workgroup(), QUERYFORPDC_R, (uint32)ntversion, (uint32)lmnttoken, (uint32)lm20token )); @@ -217,7 +213,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", send_mailslot(True, getdc, outbuf,PTR_DIFF(q,outbuf), - global_myname, 0x0, + global_myname(), 0x0, dgram->source_name.name, dgram->source_name.name_type, p->ip, *iface_ip(p->ip), p->port); @@ -280,7 +276,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", fstrcpy(reply_name+2,my_name); DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n", - asccomp,inet_ntoa(p->ip), ascuser, reply_name, global_myworkgroup, + asccomp,inet_ntoa(p->ip), ascuser, reply_name, lp_workgroup(), SAMLOGON_R ,lmnttoken)); /* Construct reply. */ @@ -299,7 +295,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += dos_PutUniCode(q, reply_name,sizeof(pstring), True); q += dos_PutUniCode(q, ascuser, sizeof(pstring), True); - q += dos_PutUniCode(q, global_myworkgroup,sizeof(pstring), True); + q += dos_PutUniCode(q, lp_workgroup(),sizeof(pstring), True); } #ifdef HAVE_ADS else { @@ -345,7 +341,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += 2; /* it must follow the domain name. */ /* Push dns host name */ - size = push_ascii(&q[1], global_myname, -1, 0); + size = push_ascii(&q[1], global_myname(), -1, 0); SCVAL(q, 0, size); q += (size + 1); SSVAL(q, 0, 0x18c0); /* not sure what this is for, but */ @@ -397,7 +393,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", send_mailslot(True, getdc, outbuf,PTR_DIFF(q,outbuf), - global_myname, 0x0, + global_myname(), 0x0, dgram->source_name.name, dgram->source_name.name_type, p->ip, *iface_ip(p->ip), p->port); diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index d4a7070042..de05ee973c 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -26,9 +26,6 @@ #include "includes.h" -extern pstring global_myname; -extern fstring global_myworkgroup; -extern char **my_netbios_names; extern int updatecount; extern BOOL found_lm_clients; @@ -52,7 +49,7 @@ void send_browser_reset(int reset_type, char *to_name, int to_type, struct in_ad p++; send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), - global_myname, 0x0, to_name, to_type, to_ip, + global_myname(), 0x0, to_name, to_type, to_ip, FIRST_SUBNET->myip, DGRAM_PORT); } @@ -78,10 +75,10 @@ to subnet %s\n", work->work_group, subrec->subnet_name)); SCVAL(p,0,work->token); /* (local) Unique workgroup token id. */ p++; - p += push_string(NULL, p+1, global_myname, 15, STR_ASCII|STR_UPPER|STR_TERMINATE); + p += push_string(NULL, p+1, global_myname(), 15, STR_ASCII|STR_UPPER|STR_TERMINATE); send_mailslot(False, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), - global_myname, 0x0, work->work_group,0x1e, subrec->bcast_ip, + global_myname(), 0x0, work->work_group,0x1e, subrec->bcast_ip, subrec->myip, DGRAM_PORT); } @@ -90,9 +87,9 @@ to subnet %s\n", work->work_group, subrec->subnet_name)); **************************************************************************/ static void send_announcement(struct subnet_record *subrec, int announce_type, - char *from_name, char *to_name, int to_type, struct in_addr to_ip, + const char *from_name, const char *to_name, int to_type, struct in_addr to_ip, time_t announce_interval, - char *server_name, int server_type, char *server_comment) + const char *server_name, int server_type, const char *server_comment) { pstring outbuf; char *p; @@ -168,14 +165,14 @@ static void send_local_master_announcement(struct subnet_record *subrec, struct uint32 type = servrec->serv.type & ~SV_TYPE_LOCAL_LIST_ONLY; DEBUG(3,("send_local_master_announcement: type %x for name %s on subnet %s for workgroup %s\n", - type, global_myname, subrec->subnet_name, work->work_group)); + type, global_myname(), subrec->subnet_name, work->work_group)); send_announcement(subrec, ANN_LocalMasterAnnouncement, - global_myname, /* From nbt name. */ + global_myname(), /* From nbt name. */ work->work_group, 0x1e, /* To nbt name. */ subrec->bcast_ip, /* To ip. */ work->announce_interval, /* Time until next announce. */ - global_myname, /* Name to announce. */ + global_myname(), /* Name to announce. */ type, /* Type field. */ servrec->serv.comment); } @@ -190,13 +187,13 @@ static void send_workgroup_announcement(struct subnet_record *subrec, struct wor subrec->subnet_name, work->work_group)); send_announcement(subrec, ANN_DomainAnnouncement, - global_myname, /* From nbt name. */ + global_myname(), /* From nbt name. */ MSBROWSE, 0x1, /* To nbt name. */ subrec->bcast_ip, /* To ip. */ work->announce_interval, /* Time until next announce. */ work->work_group, /* Name to announce. */ SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT, /* workgroup announce flags. */ - global_myname); /* From name as comment. */ + global_myname()); /* From name as comment. */ } /**************************************************************************** @@ -255,7 +252,7 @@ static void announce_server(struct subnet_record *subrec, struct work_record *wo /* Only do domain announcements if we are a master and it's our primary name we're being asked to announce. */ - if (AM_LOCAL_MASTER_BROWSER(work) && strequal(global_myname,servrec->serv.name)) + if (AM_LOCAL_MASTER_BROWSER(work) && strequal(global_myname(),servrec->serv.name)) { send_local_master_announcement(subrec, work, servrec); send_workgroup_announcement(subrec, work); @@ -277,7 +274,7 @@ void announce_my_server_names(time_t t) for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { - struct work_record *work = find_workgroup_on_subnet(subrec, global_myworkgroup); + struct work_record *work = find_workgroup_on_subnet(subrec, lp_workgroup()); if(work) { @@ -341,7 +338,7 @@ void announce_my_lm_server_names(time_t t) for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { - struct work_record *work = find_workgroup_on_subnet(subrec, global_myworkgroup); + struct work_record *work = find_workgroup_on_subnet(subrec, lp_workgroup()); if(work) { @@ -483,7 +480,8 @@ void announce_my_servers_removed(void) void announce_remote(time_t t) { - char *s,*ptr; + char *s; + const char *ptr; static time_t last_time = 0; pstring s2; struct in_addr addr; @@ -505,14 +503,17 @@ void announce_remote(time_t t) { /* The entries are of the form a.b.c.d/WORKGROUP with WORKGROUP being optional */ - char *wgroup; + const char *wgroup; + char *pwgroup; int i; - wgroup = strchr_m(s2,'/'); - if (wgroup) - *wgroup++ = 0; - if (!wgroup || !*wgroup) - wgroup = global_myworkgroup; + pwgroup = strchr_m(s2,'/'); + if (pwgroup) + *pwgroup++ = 0; + if (!pwgroup || !*pwgroup) + wgroup = lp_workgroup(); + else + wgroup = pwgroup; addr = *interpret_addr2(s2); @@ -520,9 +521,9 @@ void announce_remote(time_t t) /* Give the ip address as the address of our first broadcast subnet. */ - for(i=0; my_netbios_names[i]; i++) + for(i=0; my_netbios_names(i); i++) { - char *name = my_netbios_names[i]; + const char *name = my_netbios_names(i); DEBUG(5,("announce_remote: Doing remote announce for server %s to IP %s.\n", name, inet_ntoa(addr) )); @@ -546,7 +547,8 @@ void announce_remote(time_t t) void browse_sync_remote(time_t t) { - char *s,*ptr; + char *s; + const char *ptr; static time_t last_time = 0; pstring s2; struct in_addr addr; @@ -568,17 +570,17 @@ void browse_sync_remote(time_t t) * for our workgroup on the firsst subnet. */ - if((work = find_workgroup_on_subnet(FIRST_SUBNET, global_myworkgroup)) == NULL) + if((work = find_workgroup_on_subnet(FIRST_SUBNET, lp_workgroup())) == NULL) { DEBUG(0,("browse_sync_remote: Cannot find workgroup %s on subnet %s\n", - global_myworkgroup, FIRST_SUBNET->subnet_name )); + lp_workgroup(), FIRST_SUBNET->subnet_name )); return; } if(!AM_LOCAL_MASTER_BROWSER(work)) { DEBUG(5,("browse_sync_remote: We can only do this if we are a local master browser \ -for workgroup %s on subnet %s.\n", global_myworkgroup, FIRST_SUBNET->subnet_name )); +for workgroup %s on subnet %s.\n", lp_workgroup(), FIRST_SUBNET->subnet_name )); return; } @@ -587,7 +589,7 @@ for workgroup %s on subnet %s.\n", global_myworkgroup, FIRST_SUBNET->subnet_name SCVAL(p,0,ANN_MasterAnnouncement); p++; - StrnCpy(p,global_myname,15); + StrnCpy(p,global_myname(),15); strupper(p); p = skip_string(p,1); @@ -597,9 +599,9 @@ for workgroup %s on subnet %s.\n", global_myworkgroup, FIRST_SUBNET->subnet_name addr = *interpret_addr2(s2); DEBUG(5,("announce_remote: Doing remote browse sync announce for server %s to IP %s.\n", - global_myname, inet_ntoa(addr) )); + global_myname(), inet_ntoa(addr) )); send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), - global_myname, 0x0, "*", 0x0, addr, FIRST_SUBNET->myip, DGRAM_PORT); + global_myname(), 0x0, "*", 0x0, addr, FIRST_SUBNET->myip, DGRAM_PORT); } } diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index a315d80afe..2fee239b2d 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -26,9 +26,6 @@ extern int ClientNMB; -extern fstring global_myworkgroup; -extern char **my_netbios_names; - int updatecount = 0; /******************************************************************* @@ -91,7 +88,7 @@ static void add_server_to_workgroup(struct work_record *work, Find a server in a server list. **************************************************************************/ -struct server_record *find_server_in_workgroup(struct work_record *work, char *name) +struct server_record *find_server_in_workgroup(struct work_record *work, const char *name) { struct server_record *ret; @@ -128,8 +125,8 @@ void remove_server_from_workgroup(struct work_record *work, struct server_record ****************************************************************************/ struct server_record *create_server_on_workgroup(struct work_record *work, - char *name,int servertype, - int ttl,char *comment) + const char *name,int servertype, + int ttl, const char *comment) { struct server_record *servrec; @@ -256,7 +253,7 @@ static uint32 write_this_server_name( struct subnet_record *subrec, /******************************************************************* Decide if we should write out a workgroup record for this workgroup. - We return zero if we should not. Don't write out global_myworkgroup (we've + We return zero if we should not. Don't write out lp_workgroup() (we've already done it) and also don't write out a second workgroup record on the unicast subnet that we've already written out on one of the broadcast subnets. @@ -267,7 +264,7 @@ static uint32 write_this_workgroup_name( struct subnet_record *subrec, { struct subnet_record *ssub; - if(strequal(global_myworkgroup, work->work_group)) + if(strequal(lp_workgroup(), work->work_group)) return 0; /* This is a workgroup we have seen on a broadcast subnet. All @@ -295,8 +292,8 @@ static uint32 write_this_workgroup_name( struct subnet_record *subrec, Write out the browse.dat file. ******************************************************************/ -void write_browse_list_entry(XFILE *fp, fstring name, uint32 rec_type, - fstring local_master_browser_name, fstring description) +void write_browse_list_entry(XFILE *fp, const char *name, uint32 rec_type, + const char *local_master_browser_name, const char *description) { fstring tmp; @@ -368,10 +365,10 @@ void write_browse_list(time_t t, BOOL force_write) * subnet. */ - if((work = find_workgroup_on_subnet(FIRST_SUBNET, global_myworkgroup)) == NULL) + if((work = find_workgroup_on_subnet(FIRST_SUBNET, lp_workgroup())) == NULL) { DEBUG(0,("write_browse_list: Fatal error - cannot find my workgroup %s\n", - global_myworkgroup)); + lp_workgroup())); x_fclose(fp); return; } @@ -388,22 +385,22 @@ void write_browse_list(time_t t, BOOL force_write) * once. */ - for (i=0; my_netbios_names[i]; i++) + for (i=0; my_netbios_names(i); i++) { stype = 0; for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { - if((work = find_workgroup_on_subnet( subrec, global_myworkgroup )) == NULL) + if((work = find_workgroup_on_subnet( subrec, lp_workgroup() )) == NULL) continue; - if((servrec = find_server_in_workgroup( work, my_netbios_names[i])) == NULL) + if((servrec = find_server_in_workgroup( work, my_netbios_names(i))) == NULL) continue; stype |= servrec->serv.type; } /* Output server details, plus what workgroup they're in. */ - write_browse_list_entry(fp, my_netbios_names[i], stype, - string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH), global_myworkgroup); + write_browse_list_entry(fp, my_netbios_names(i), stype, + string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH), lp_workgroup()); } for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index e68fc1589c..3ca33c4e53 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -30,9 +30,6 @@ extern int ClientNMB; extern int ClientDGRAM; extern int global_nmb_port; -extern fstring myworkgroup; -extern char **my_netbios_names; - /* This is the broadcast subnets database. */ struct subnet_record *subnetlist = NULL; diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 24adf4e69f..30c7d579f1 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -247,7 +247,7 @@ static void complete_sync(struct sync_record *s) unsigned type; pstring comment; pstring line; - char *ptr; + const char *ptr; int count=0; f = x_fopen(s->fname,O_RDONLY, 0); diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index d1cfc24a31..f2dc80dfe5 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -26,9 +26,6 @@ extern int ClientNMB; -extern pstring global_myname; -extern fstring global_myworkgroup; -extern char **my_netbios_names; extern uint16 samba_nb_type; int workgroup_count = 0; /* unique index key: one for each workgroup */ @@ -226,7 +223,7 @@ void initiate_myworkgroup_startup(struct subnet_record *subrec, struct work_reco { int i; - if(!strequal(global_myworkgroup, work->work_group)) + if(!strequal(lp_workgroup(), work->work_group)) return; /* If this is a broadcast subnet then start elections on it @@ -244,21 +241,21 @@ workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name)); /* Register the WORKGROUP<0> and WORKGROUP<1e> names on the network. */ - register_name(subrec,global_myworkgroup,0x0,samba_nb_type|NB_GROUP, + register_name(subrec,lp_workgroup(),0x0,samba_nb_type|NB_GROUP, NULL, fail_register,NULL); - register_name(subrec,global_myworkgroup,0x1e,samba_nb_type|NB_GROUP, + register_name(subrec,lp_workgroup(),0x1e,samba_nb_type|NB_GROUP, NULL, fail_register,NULL); - for( i = 0; my_netbios_names[i]; i++) + for( i = 0; my_netbios_names(i); i++) { - char *name = my_netbios_names[i]; + const char *name = my_netbios_names(i); int stype = lp_default_server_announce() | (lp_local_master() ? SV_TYPE_POTENTIAL_BROWSER : 0 ); - if(!strequal(global_myname, name)) + if(!strequal(global_myname(), name)) stype &= ~(SV_TYPE_MASTER_BROWSER|SV_TYPE_POTENTIAL_BROWSER| SV_TYPE_DOMAIN_MASTER|SV_TYPE_DOMAIN_MEMBER); -- cgit From 392e2b2a0aab5e0e86d831b462b174abe8d089cb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 15 Nov 2002 18:55:18 +0000 Subject: Fix from "Stefan (metze) Metzmacher" for nmbd 1c group release. Jeremy. (This used to be commit 7d9552e9c58e533f451a720c9c9c54b8abf3a454) --- source3/nmbd/nmbd_winsserver.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index ee47cff049..d67d25bb88 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1637,6 +1637,22 @@ release name %s as this record is not anymore active.\n", return; } + /* + * Check if the record is a 0x1c group + * and has more then one ip + * remove only this address. + */ + + if(releasing_group_name && + (question->name_type == 0x1c) && + (namerec->data.num_ips > 1)) { + remove_ip_from_name_record(namerec, from_ip); + DEBUG(3,("wins_process_name_release_request: Remove IP %s from NAME: %s\n", + inet_ntoa(from_ip),nmb_namestr(question))); + send_wins_name_release_response(0, p); + return; + } + /* * Send a release response. * Flag the name as released and update the ttl -- cgit From de474974ea25df7738dd175126e3f1de0df47ea6 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 23 Nov 2002 02:52:36 +0000 Subject: Lots of fixes for error paths where tdb_fetch() data need freeing. Found via a post from Arcady Chernyak . Jeremy. (This used to be commit 5d5762d1787db4392d2dff16024097c638b2d494) --- source3/nmbd/nmbd_winsserver.c | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index d67d25bb88..87391b35df 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -266,7 +266,8 @@ BOOL initialise_wins(void) continue; dbuf = tdb_fetch(tdb, kbuf); - if (!dbuf.dptr) continue; + if (!dbuf.dptr) + continue; fstrcpy(name_type, kbuf.dptr+strlen(ENTRY_PREFIX)); @@ -284,15 +285,20 @@ BOOL initialise_wins(void) wins_ip=*interpret_addr2(ip_str); /* Don't reload replica records */ - if (!ip_equal(wins_ip, our_fake_ip)) + if (!ip_equal(wins_ip, our_fake_ip)) { + SAFE_FREE(dbuf.dptr); continue; + } /* Don't reload released or tombstoned records */ - if ((wins_flags&WINS_STATE_MASK) != WINS_ACTIVE) + if ((wins_flags&WINS_STATE_MASK) != WINS_ACTIVE) { + SAFE_FREE(dbuf.dptr); continue; + } /* Allocate the space for the ip_list. */ if((ip_list = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr))) == NULL) { + SAFE_FREE(dbuf.dptr); DEBUG(0,("initialise_wins: Malloc fail !\n")); return False; } @@ -324,6 +330,7 @@ BOOL initialise_wins(void) name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); } + SAFE_FREE(dbuf.dptr); SAFE_FREE(ip_list); } -- cgit From 9ce440e25de2db3e6170574c548fd0335d0b1190 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Tue, 3 Dec 2002 19:38:27 +0000 Subject: Stop using hacks for dns host/domain names. (This used to be commit e707e2cc7c7483f6bcfbbaf8d3d99614a05a9ecf) --- source3/nmbd/nmbd_processlogon.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 6f2517f39f..48fc8eabbf 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -301,10 +301,12 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", else { GUID domain_guid; pstring domain; + pstring hostname; char *component, *dc, *q1; uint8 size; - safe_strcpy(domain, lp_realm(), sizeof(domain)); + get_mydomname(domain); + get_myname(hostname); if (SVAL(uniuser, 0) == 0) { SSVAL(q, 0, SAMLOGON_AD_UNK_R); /* user unknown */ @@ -341,14 +343,14 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += 2; /* it must follow the domain name. */ /* Push dns host name */ - size = push_ascii(&q[1], global_myname(), -1, 0); + size = push_ascii(&q[1], hostname, -1, 0); SCVAL(q, 0, size); q += (size + 1); SSVAL(q, 0, 0x18c0); /* not sure what this is for, but */ q += 2; /* it must follow the domain name. */ /* Push NETBIOS of domain */ - size = push_ascii(&q[1], domain, -1, STR_UPPER); + size = push_ascii(&q[1], lp_workgroup(), -1, STR_UPPER); SCVAL(q, 0, size); q += (size + 1); SCVAL(q, 0, 0); q++; /* is this a null terminator or empty field */ -- cgit From 9327793ff5367268802ae5aa9833959ed3fd6ce7 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 12 Dec 2002 02:56:15 +0000 Subject: Merge of #include removals. (This used to be commit bdb6e76ab5031365c50f7bbcd5e52c4f7a039024) --- source3/nmbd/nmbd_browsesync.c | 1 - source3/nmbd/nmbd_serverlistdb.c | 1 - source3/nmbd/nmbd_subnetdb.c | 1 - source3/nmbd/nmbd_synclists.c | 1 - source3/nmbd/nmbd_workgroupdb.c | 1 - 5 files changed, 5 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 3a20f07b05..daa5142b25 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -22,7 +22,6 @@ */ #include "includes.h" -#include "smb.h" /* This is our local master browser list database. */ extern ubi_dlList lmb_browserlist[]; diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index 2fee239b2d..ee0c021d5d 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -22,7 +22,6 @@ */ #include "includes.h" -#include "smb.h" extern int ClientNMB; diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 3ca33c4e53..7875cd06b4 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -24,7 +24,6 @@ */ #include "includes.h" -#include "smb.h" extern int ClientNMB; extern int ClientDGRAM; diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 30c7d579f1..b9952fb446 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -28,7 +28,6 @@ also allows us to have more than 1 sync going at once (tridge) */ #include "includes.h" -#include "smb.h" struct sync_record { struct sync_record *next, *prev; diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index f2dc80dfe5..b8ea60dec0 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -22,7 +22,6 @@ */ #include "includes.h" -#include "smb.h" extern int ClientNMB; -- cgit From 6d6ee3b227dd71bf72e0b375571573115ddfa61a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 19 Dec 2002 22:14:40 +0000 Subject: Protect nmbd against malformed reply packets. Some reports on the lists showing these. Jeremy. (This used to be commit 4bc49cc943504d1a9a73894f6810bc755ee6e324) --- source3/nmbd/nmbd_namequery.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index 7a820a7148..8995e9ac52 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -81,6 +81,14 @@ static void query_name_response( struct subnet_record *subrec, } else { + if (!nmb->answers) + { + dbgtext( "query_name_response: On subnet %s ", subrec->subnet_name ); + dbgtext( "IP %s ", inet_ntoa(p->ip) ); + dbgtext( "returned a success response with no answer\n" ); + return; + } + success = True; putip((char *)&answer_ip,&nmb->answers->rdata[2]); @@ -102,7 +110,8 @@ static void query_name_response( struct subnet_record *subrec, { if( DEBUGLVL( 0 ) ) { - putip( (char *)&answer_ip, &nmb->answers->rdata[2] ); + if (nmb->answers) + putip( (char *)&answer_ip, &nmb->answers->rdata[2] ); dbgtext( "query_name_response: " ); dbgtext( "Multiple (%d) responses ", rrec->num_msgs ); dbgtext( "received for a query on subnet %s ", subrec->subnet_name ); -- cgit From ef8bd7c4f7ae8192ea05db070962ecf0ff3615f3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 20 Dec 2002 20:21:31 +0000 Subject: Forward port the change to talloc_init() to make all talloc contexts named. Ensure we can query them. Jeremy. (This used to be commit 09a218a9f6fb0bd922940467bf8500eb4f1bcf84) --- source3/nmbd/nmbd.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 5987d70a45..988127e431 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -95,6 +95,25 @@ static void sig_hup(int sig) sys_select_signal(); } +/******************************************************************* + Print out all talloc memory info. +********************************************************************/ + +void return_all_talloc_info(int msg_type, pid_t src_pid, void *buf, size_t len) +{ + TALLOC_CTX *ctx = talloc_init("info context"); + char *info = NULL; + + if (!ctx) + return; + + info = talloc_describe_all(ctx); + if (info) + DEBUG(10,(info)); + message_send_pid(src_pid, MSG_TALLOC_USAGE, info, info ? strlen(info) + 1 : 0, True); + talloc_destroy(ctx); +} + #if DUMP_CORE /**************************************************************************** ** Prepare to dump a core file - carefully! @@ -682,6 +701,7 @@ static BOOL open_sockets(BOOL isdaemon, int port) message_register(MSG_FORCE_ELECTION, nmbd_message_election); message_register(MSG_WINS_NEW_ENTRY, nmbd_wins_new_entry); message_register(MSG_SHUTDOWN, nmbd_terminate); + message_register(MSG_REQ_TALLOC_USAGE, return_all_talloc_info); DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); -- cgit From 634c54310c92c48dd4eceec602e230a021bdcfc5 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Fri, 3 Jan 2003 08:28:12 +0000 Subject: Merge from HEAD - make Samba compile with -Wwrite-strings without additional warnings. (Adds a lot of const). Andrew Bartlett (This used to be commit 3a7458f9472432ef12c43008414925fd1ce8ea0c) --- source3/nmbd/nmbd_namelistdb.c | 4 ++-- source3/nmbd/nmbd_packets.c | 4 ++-- source3/nmbd/nmbd_processlogon.c | 4 ++-- source3/nmbd/nmbd_sendannounce.c | 2 +- source3/nmbd/nmbd_subnetdb.c | 2 +- source3/nmbd/nmbd_winsserver.c | 2 +- 6 files changed, 9 insertions(+), 9 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 7ff2d4171e..932d926a91 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -173,7 +173,7 @@ void update_name_ttl( struct name_record *namerec, int ttl ) * ************************************************************************** ** */ struct name_record *add_name_to_subnet( struct subnet_record *subrec, - char *name, + const char *name, int type, uint16 nb_flags, int ttl, @@ -525,7 +525,7 @@ void add_samba_names_to_subnet( struct subnet_record *subrec ) static void dump_subnet_namelist( struct subnet_record *subrec, XFILE *fp) { struct name_record *namerec; - char *src_type; + const char *src_type; struct tm *tm; int i; diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 894f6bb7d6..d83cd10d0c 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -887,7 +887,7 @@ void reply_netbios_packet(struct packet_struct *orig_packet, struct res_rec answers; struct nmb_packet *orig_nmb = &orig_packet->packet.nmb; BOOL loopback_this_packet = False; - char *packet_type = "unknown"; + const char *packet_type = "unknown"; /* Check if we are sending to or from ourselves. */ if(ismyip(orig_packet->ip) && (orig_packet->port == global_nmb_port)) @@ -1929,7 +1929,7 @@ BOOL listen_for_packets(BOOL run_election) /**************************************************************************** Construct and send a netbios DGRAM. **************************************************************************/ -BOOL send_mailslot(BOOL unique, char *mailslot,char *buf,int len, +BOOL send_mailslot(BOOL unique, const char *mailslot,char *buf,int len, const char *srcname, int src_type, const char *dstname, int dest_type, struct in_addr dest_ip,struct in_addr src_ip, diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 48fc8eabbf..39724921a4 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -62,8 +62,8 @@ static void send_repl_message(uint32 low_serial) Process a domain logon packet **************************************************************************/ -void process_logon_packet(struct packet_struct *p,char *buf,int len, - char *mailslot) +void process_logon_packet(struct packet_struct *p, char *buf,int len, + const char *mailslot) { struct dgram_packet *dgram = &p->packet.dgram; pstring my_name; diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index de05ee973c..40d07aae16 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -33,7 +33,7 @@ extern BOOL found_lm_clients; Send a browser reset packet. **************************************************************************/ -void send_browser_reset(int reset_type, char *to_name, int to_type, struct in_addr to_ip) +void send_browser_reset(int reset_type, const char *to_name, int to_type, struct in_addr to_ip) { pstring outbuf; char *p; diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 7875cd06b4..6296826425 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -105,7 +105,7 @@ void close_subnet(struct subnet_record *subrec) Create a subnet entry. ****************************************************************************/ -static struct subnet_record *make_subnet(char *name, enum subnet_type type, +static struct subnet_record *make_subnet(const char *name, enum subnet_type type, struct in_addr myip, struct in_addr bcast_ip, struct in_addr mask_ip) { diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 87391b35df..e43dd3f467 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -100,7 +100,7 @@ static void get_global_id_and_update(SMB_BIG_UINT *current_id, BOOL update) /**************************************************************************** possibly call the WINS hook external program when a WINS change is made *****************************************************************************/ -static void wins_hook(char *operation, struct name_record *namerec, int ttl) +static void wins_hook(const char *operation, struct name_record *namerec, int ttl) { pstring command; char *cmd = lp_wins_hook(); -- cgit From f5d5df9644abc08ae1b16a0826eb8cf5c3de54d1 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 3 Jan 2003 17:39:30 +0000 Subject: patch to include support for daemontools from Michael Handler (This used to be commit a8db1b611d83bfd8dcf60f1e6d8fcbf57c798528) --- source3/nmbd/nmbd.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 988127e431..2b7d8033a2 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -32,6 +32,12 @@ extern BOOL global_in_nmbd; /* are we running as a daemon ? */ static BOOL is_daemon = False; +/* fork or run in foreground ? */ +static BOOL Fork = True; + +/* log to standard output ? */ +static BOOL log_stdout = False; + /* have we found LanMan clients yet? */ BOOL found_lm_clients = False; @@ -590,6 +596,8 @@ static BOOL open_sockets(BOOL isdaemon, int port) POPT_AUTOHELP {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon(default)" }, {"interactive", 'i', POPT_ARG_VAL, &opt_interactive, True, "Run interactive (not a daemon)" }, + {"foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools & etc)" }, + {"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" }, {"hosts", 'H', POPT_ARG_STRING, dyn_LMHOSTSFILE, 'H', "Load a netbios hosts file"}, {"port", 'p', POPT_ARG_INT, &global_nmb_port, NMB_PORT, "Listen on the specified port" }, {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug }, @@ -639,8 +647,18 @@ static BOOL open_sockets(BOOL isdaemon, int port) { } poptFreeContext(pc); - - setup_logging( argv[0], opt_interactive ); + + if ( opt_interactive ) { + Fork = False; + log_stdout = True; + } + + if ( log_stdout && Fork ) { + DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n")); + exit(1); + } + + setup_logging( argv[0], log_stdout ); reopen_logs(); @@ -672,7 +690,7 @@ static BOOL open_sockets(BOOL isdaemon, int port) if (is_daemon && !opt_interactive) { DEBUG( 2, ( "Becoming a daemon.\n" ) ); - become_daemon(); + become_daemon(Fork); } #if HAVE_SETPGID -- cgit From 27b7e51a3cc619f879655a3230611457ac43b9e7 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 14 Jan 2003 08:53:59 +0000 Subject: Merge from HEAD: - fstring/pstring mixups - the detection code that found them (disabled) - a bit of whitespace - a static Andrew Bartlett (This used to be commit 9b70fa868e7d9481f584c83fc4046174e1dedfd9) --- source3/nmbd/nmbd_winsserver.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index e43dd3f467..4ef476f814 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -250,7 +250,8 @@ BOOL initialise_wins(void) kbuf.dptr; newkey = tdb_nextkey(tdb, kbuf), safe_free(kbuf.dptr), kbuf=newkey) { - pstring name_type, name, ip_str; + fstring name_type; + pstring name, ip_str; char *p; int type = 0; int nb_flags; -- cgit From 99cdb462083381c88689a4e698ca48b6ed4cf5ac Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 15 Jan 2003 18:57:41 +0000 Subject: *lots of small merges form HEAD *sync up configure.in *don't build torture tools in make all *make sure to remove torture tools as part of make clean (This used to be commit 0fb724b3216eeeb97e61ff12755ca3a31bcad6ef) --- source3/nmbd/nmbd_become_lmb.c | 2 +- source3/nmbd/nmbd_browsesync.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index 7b8ba14bb5..bac5589566 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -563,7 +563,7 @@ in workgroup %s on subnet %s\n", userdata->copy_fn = NULL; userdata->free_fn = NULL; userdata->userdata_len = strlen(work->work_group)+1; - pstrcpy(userdata->data, work->work_group); + fstrcpy(userdata->data, work->work_group); /* Register the special browser group name. */ register_name(subrec, MSBROWSE, 0x01, samba_nb_type|NB_GROUP, diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index daa5142b25..f27f42297f 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -333,7 +333,7 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec, userdata->copy_fn = NULL; userdata->free_fn = NULL; userdata->userdata_len = strlen(work->work_group)+1; - pstrcpy(userdata->data, work->work_group); + fstrcpy(userdata->data, work->work_group); node_status( subrec, &nmbname, answer_ip, domain_master_node_status_success, -- cgit From 1cba0a757970ffd8b81d61c88965010968ab3eff Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 28 Jan 2003 12:07:02 +0000 Subject: Merge from HEAD: - NTLMSSP over SPENGO (sesssion-setup-and-x) cleanup and code refactor. - also consequential changes to the NTLMSSP and SPNEGO parsing functions - and the client code that uses the same functions - Add ntlm_auth, a NTLMSSP authentication interface for use by applications like Squid and Apache. - also consquential changes to use common code for base64 encode/decode. - Winbind changes to support ntlm_auth (I don't want this program to need to read smb.conf, instead getting all it's details over the pipe). - nmbd changes for fstrcat() instead of fstrcpy(). Andrew Bartlett (This used to be commit fbb46da79cf322570a7e3318100c304bbf33409e) --- source3/nmbd/nmbd_processlogon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 39724921a4..a702fc3015 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -272,8 +272,8 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", pull_ucs2_fstring(asccomp, unicomp); DEBUG(3,("process_logon_packet: SAMLOGON user %s\n", ascuser)); - fstrcpy(reply_name,"\\\\"); /* Here it wants \\LOGONSERVER. */ - fstrcpy(reply_name+2,my_name); + fstrcpy(reply_name, "\\\\"); /* Here it wants \\LOGONSERVER. */ + fstrcat(reply_name, my_name); DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n", asccomp,inet_ntoa(p->ip), ascuser, reply_name, lp_workgroup(), -- cgit From c44e39065c342eaf9efb7a91499791f157433a18 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 10 Mar 2003 15:04:29 +0000 Subject: check a pointer before dereferencing it; not sure why userdata == NULL though (This used to be commit 944752024ba6ab762b12c29ee867e37401dac12b) --- source3/nmbd/nmbd_browsesync.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index f27f42297f..c363ed0d34 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -258,7 +258,7 @@ static void domain_master_node_status_fail(struct subnet_record *subrec, { dbgtext( "domain_master_node_status_fail:\n" ); dbgtext( "Doing a node status request to the domain master browser\n" ); - dbgtext( "for workgroup %s ", userdata->data ); + dbgtext( "for workgroup %s ", userdata ? userdata->data : "NULL" ); dbgtext( "at IP %s failed.\n", inet_ntoa(rrec->packet->ip) ); dbgtext( "Cannot sync browser lists.\n" ); } -- cgit From cdc6fc8acb24645ccd0f2862741c9ea9e1c02829 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 18 Mar 2003 09:52:55 +0000 Subject: Add an extra parameter to our 'set_remote_machine_name' and 'set_local_machine_name' so that the client can't change it from under us. (.NET RC2 and WinXP install calls the machine 'machinename' during NTLMSSP on the domain join). Andrew Bartlett (This used to be commit 4c7163e7c2cc09bd95faa05156ee480957a7a4d8) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 2b7d8033a2..fc08645f1d 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -292,7 +292,7 @@ static BOOL reload_nmbd_services(BOOL test) { BOOL ret; - set_remote_machine_name("nmbd"); + set_remote_machine_name("nmbd", False); if ( lp_loaded() ) { pstring fname; -- cgit From 50e9b88dff56e70ad03eb104cb151fe21112b984 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Tue, 18 Mar 2003 11:56:56 +0000 Subject: NMBD string parinoia and memcpy() parinoia fixes from HEAD. Andrew Bartlett (This used to be commit fb29caddd987f94989f852584b912eeee45b50da) --- source3/nmbd/nmbd_become_lmb.c | 6 +++--- source3/nmbd/nmbd_browsesync.c | 4 ++-- source3/nmbd/nmbd_packets.c | 15 ++++++++++----- 3 files changed, 15 insertions(+), 10 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index bac5589566..6f8e7efb1a 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -207,7 +207,7 @@ static void release_1d_name( struct subnet_record *subrec, char *workgroup_name, if((namerec = find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME))!=NULL) { struct userdata_struct *userdata; - int size = sizeof(struct userdata_struct) + sizeof(BOOL); + size_t size = sizeof(struct userdata_struct) + sizeof(BOOL); if((userdata = (struct userdata_struct *)malloc(size)) == NULL) { @@ -518,7 +518,7 @@ workgroup %s on subnet %s. Couldn't register name %s.\n", void become_local_master_browser(struct subnet_record *subrec, struct work_record *work) { struct userdata_struct *userdata; - int size = sizeof(struct userdata_struct) + sizeof(fstring) + 1; + size_t size = sizeof(struct userdata_struct) + sizeof(fstring) + 1; /* Sanity check. */ if (!lp_local_master()) @@ -563,7 +563,7 @@ in workgroup %s on subnet %s\n", userdata->copy_fn = NULL; userdata->free_fn = NULL; userdata->userdata_len = strlen(work->work_group)+1; - fstrcpy(userdata->data, work->work_group); + overmalloc_safe_strcpy(userdata->data, work->work_group, size - sizeof(*userdata) - 1); /* Register the special browser group name. */ register_name(subrec, MSBROWSE, 0x01, samba_nb_type|NB_GROUP, diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index c363ed0d34..b9082ee1c3 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -288,7 +288,7 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec, struct work_record *work; struct nmb_name nmbname; struct userdata_struct *userdata; - int size = sizeof(struct userdata_struct) + sizeof(fstring)+1; + size_t size = sizeof(struct userdata_struct) + sizeof(fstring)+1; if( !(work = find_workgroup_on_subnet(subrec, q_name->name)) ) { @@ -333,7 +333,7 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec, userdata->copy_fn = NULL; userdata->free_fn = NULL; userdata->userdata_len = strlen(work->work_group)+1; - fstrcpy(userdata->data, work->work_group); + overmalloc_safe_strcpy(userdata->data, work->work_group, size - sizeof(*userdata) - 1); node_status( subrec, &nmbname, answer_ip, domain_master_node_status_success, diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index d83cd10d0c..6c3446d6c8 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1929,7 +1929,7 @@ BOOL listen_for_packets(BOOL run_election) /**************************************************************************** Construct and send a netbios DGRAM. **************************************************************************/ -BOOL send_mailslot(BOOL unique, const char *mailslot,char *buf,int len, +BOOL send_mailslot(BOOL unique, const char *mailslot,char *buf, size_t len, const char *srcname, int src_type, const char *dstname, int dest_type, struct in_addr dest_ip,struct in_addr src_ip, @@ -1979,11 +1979,16 @@ BOOL send_mailslot(BOOL unique, const char *mailslot,char *buf,int len, SSVAL(ptr,smb_vwv15,1); SSVAL(ptr,smb_vwv16,2); p2 = smb_buf(ptr); - pstrcpy(p2,mailslot); + safe_strcpy_base(p2, mailslot, dgram->data, sizeof(dgram->data)); p2 = skip_string(p2,1); - - memcpy(p2,buf,len); - p2 += len; + + if (((p2+len) > dgram->data+sizeof(dgram->data)) || ((p2+len) < p2)) { + DEBUG(0, ("send_mailslot: Cannot write beyond end of packet\n")); + return False; + } else { + memcpy(p2,buf,len); + p2 += len; + } dgram->datasize = PTR_DIFF(p2,ptr+4); /* +4 for tcp length. */ -- cgit From cbded5d6f889542f803932b280e0de826238fce7 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Wed, 19 Mar 2003 19:33:08 +0000 Subject: replace pstrcpy (This used to be commit c5876f9f07bfff4e03f3a70136515c9daab20afd) --- source3/nmbd/nmbd_elections.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 976abbed25..f09c37eedc 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -47,7 +47,7 @@ static void send_election_dgram(struct subnet_record *subrec, const char *workgr SIVAL(p,1,criterion); SIVAL(p,5,timeup*1000); /* ms - Despite what the spec says. */ p += 13; - pstrcpy(p,server_name); + safe_strcpy(p, server_name, sizeof(outbuf) - 1 - (p-outbuf)); strupper(p); p = skip_string(p,1); -- cgit From efadbacb9abde371dfb3f19c9f9f69539ec1dc34 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Thu, 20 Mar 2003 14:49:47 +0000 Subject: use pstrcpy_base() (This used to be commit 2e3710f67293b01084026549246d494103b2d536) --- source3/nmbd/nmbd_elections.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index f09c37eedc..339a27d207 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -47,7 +47,7 @@ static void send_election_dgram(struct subnet_record *subrec, const char *workgr SIVAL(p,1,criterion); SIVAL(p,5,timeup*1000); /* ms - Despite what the spec says. */ p += 13; - safe_strcpy(p, server_name, sizeof(outbuf) - 1 - (p-outbuf)); + pstrcpy_base(p, server_name, outbuf); strupper(p); p = skip_string(p,1); -- cgit From 744aa7208537374c33f7a0129c20c5c665d3d933 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sun, 30 Mar 2003 23:03:11 +0000 Subject: update copyright notice since it we are now almost 4 months into 2003 (This used to be commit 0751d2f117b4274dd19388d856de75d9fc739865) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index fc08645f1d..5685db7452 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -663,7 +663,7 @@ static BOOL open_sockets(BOOL isdaemon, int port) reopen_logs(); DEBUG( 0, ( "Netbios nameserver version %s started.\n", VERSION ) ); - DEBUGADD( 0, ( "Copyright Andrew Tridgell and the Samba Team 1994-2002\n" ) ); + DEBUGADD( 0, ( "Copyright Andrew Tridgell and the Samba Team 1994-2003\n" ) ); if ( !reload_nmbd_services(False) ) return(-1); -- cgit From 63cbbe26923b8f6bbed11428a3a218a88d17ffe7 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 14 Apr 2003 03:30:20 +0000 Subject: Merge Jelmer's popt updates from HEAD. (This used to be commit 98e84b3e83d2a365c818ea64f9418edb29d690f2) --- source3/nmbd/nmbd.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 5685db7452..013ef9ddb7 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -3,7 +3,7 @@ NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Jeremy Allison 1997-2002 - Copyright (C) Jelmer Vernooij 2002 (Conversion to popt) + Copyright (C) Jelmer Vernooij 2002,2003 (Conversion to popt) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -600,15 +600,9 @@ static BOOL open_sockets(BOOL isdaemon, int port) {"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" }, {"hosts", 'H', POPT_ARG_STRING, dyn_LMHOSTSFILE, 'H', "Load a netbios hosts file"}, {"port", 'p', POPT_ARG_INT, &global_nmb_port, NMB_PORT, "Listen on the specified port" }, - {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_debug }, - {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_configfile }, - {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_socket_options }, - {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_version }, - {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_netbios_name }, - {NULL, 0, POPT_ARG_INCLUDE_TABLE, popt_common_log_base }, + POPT_COMMON_SAMBA { NULL } }; - int opt; pstring logfile; global_nmb_port = NMB_PORT; @@ -624,7 +618,7 @@ static BOOL open_sockets(BOOL isdaemon, int port) fault_setup((void (*)(void *))fault_continue ); /* POSIX demands that signals are inherited. If the invoking process has - * these signals masked, we will have problems, as we won't recieve them. */ + * these signals masked, we will have problems, as we won't receive them. */ BlockSignals(False, SIGHUP); BlockSignals(False, SIGUSR1); BlockSignals(False, SIGTERM); @@ -643,9 +637,6 @@ static BOOL open_sockets(BOOL isdaemon, int port) #endif pc = poptGetContext("nmbd", argc, argv, long_options, 0); - while((opt = poptGetNextOpt(pc)) != -1) - { } - poptFreeContext(pc); if ( opt_interactive ) { -- cgit From 7d01a9b71c87f5715ded803b2c059a4797e9b690 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 14 Apr 2003 04:01:41 +0000 Subject: Merge: - debugging tdb messages now initialised and handled in lib/messages.c (This used to be commit da216706a420b31beaac91553a4eb90181de814a) --- source3/nmbd/nmbd.c | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 013ef9ddb7..f87ab97798 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -101,25 +101,6 @@ static void sig_hup(int sig) sys_select_signal(); } -/******************************************************************* - Print out all talloc memory info. -********************************************************************/ - -void return_all_talloc_info(int msg_type, pid_t src_pid, void *buf, size_t len) -{ - TALLOC_CTX *ctx = talloc_init("info context"); - char *info = NULL; - - if (!ctx) - return; - - info = talloc_describe_all(ctx); - if (info) - DEBUG(10,(info)); - message_send_pid(src_pid, MSG_TALLOC_USAGE, info, info ? strlen(info) + 1 : 0, True); - talloc_destroy(ctx); -} - #if DUMP_CORE /**************************************************************************** ** Prepare to dump a core file - carefully! @@ -710,7 +691,6 @@ static BOOL open_sockets(BOOL isdaemon, int port) message_register(MSG_FORCE_ELECTION, nmbd_message_election); message_register(MSG_WINS_NEW_ENTRY, nmbd_wins_new_entry); message_register(MSG_SHUTDOWN, nmbd_terminate); - message_register(MSG_REQ_TALLOC_USAGE, return_all_talloc_info); DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); -- cgit From 7176f75036a63c712f16e446267b29a9878d0b1b Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 16 Apr 2003 14:25:56 +0000 Subject: fixed the popt option handling in nmbd, so that -i now works (This used to be commit 2bb93421e665cdc0c4a2d8a539f76856e4d32249) --- source3/nmbd/nmbd.c | 71 ++++++++++++++++++++++++++++------------------------- 1 file changed, 37 insertions(+), 34 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index f87ab97798..8e7759d90b 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -30,13 +30,13 @@ int global_nmb_port = -1; extern BOOL global_in_nmbd; /* are we running as a daemon ? */ -static BOOL is_daemon = False; +static BOOL is_daemon; /* fork or run in foreground ? */ static BOOL Fork = True; /* log to standard output ? */ -static BOOL log_stdout = False; +static BOOL log_stdout; /* have we found LanMan clients yet? */ BOOL found_lm_clients = False; @@ -571,8 +571,10 @@ static BOOL open_sockets(BOOL isdaemon, int port) **************************************************************************** */ int main(int argc, const char *argv[]) { - static BOOL opt_interactive = False; + pstring logfile; + static BOOL opt_interactive; poptContext pc; + int opt; struct poptOption long_options[] = { POPT_AUTOHELP {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon(default)" }, @@ -584,46 +586,47 @@ static BOOL open_sockets(BOOL isdaemon, int port) POPT_COMMON_SAMBA { NULL } }; - pstring logfile; - - global_nmb_port = NMB_PORT; - global_in_nmbd = True; - - StartupTime = time(NULL); - - sys_srandom(time(NULL) ^ sys_getpid()); - slprintf(logfile, sizeof(logfile)-1, "%s/log.nmbd", dyn_LOGFILEBASE); - lp_set_logfile(logfile); + global_nmb_port = NMB_PORT; - fault_setup((void (*)(void *))fault_continue ); - - /* POSIX demands that signals are inherited. If the invoking process has - * these signals masked, we will have problems, as we won't receive them. */ - BlockSignals(False, SIGHUP); - BlockSignals(False, SIGUSR1); - BlockSignals(False, SIGTERM); - - CatchSignal( SIGHUP, SIGNAL_CAST sig_hup ); - CatchSignal( SIGTERM, SIGNAL_CAST sig_term ); + pc = poptGetContext("nmbd", argc, argv, long_options, 0); + while ((opt = poptGetNextOpt(pc)) != -1) ; + poptFreeContext(pc); + global_in_nmbd = True; + + StartupTime = time(NULL); + + sys_srandom(time(NULL) ^ sys_getpid()); + + slprintf(logfile, sizeof(logfile)-1, "%s/log.nmbd", dyn_LOGFILEBASE); + lp_set_logfile(logfile); + + fault_setup((void (*)(void *))fault_continue ); + + /* POSIX demands that signals are inherited. If the invoking process has + * these signals masked, we will have problems, as we won't receive them. */ + BlockSignals(False, SIGHUP); + BlockSignals(False, SIGUSR1); + BlockSignals(False, SIGTERM); + + CatchSignal( SIGHUP, SIGNAL_CAST sig_hup ); + CatchSignal( SIGTERM, SIGNAL_CAST sig_term ); + #if defined(SIGFPE) - /* we are never interested in SIGFPE */ - BlockSignals(True,SIGFPE); + /* we are never interested in SIGFPE */ + BlockSignals(True,SIGFPE); #endif - /* We no longer use USR2... */ + /* We no longer use USR2... */ #if defined(SIGUSR2) - BlockSignals(True, SIGUSR2); + BlockSignals(True, SIGUSR2); #endif - pc = poptGetContext("nmbd", argc, argv, long_options, 0); - - poptFreeContext(pc); - if ( opt_interactive ) { - Fork = False; - log_stdout = True; - } + if ( opt_interactive ) { + Fork = False; + log_stdout = True; + } if ( log_stdout && Fork ) { DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n")); -- cgit From 2a3a9f0bf43c3bf99a71f7296bb5ff6199893fea Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 23 Apr 2003 13:27:35 +0000 Subject: Merge the 'safe' parts of my StrnCpy patch - many of the users really wanted a pstrcpy/fstrcpy or at most a safe_strcpy(). These have the advantage of being compiler-verifiable. Get these out of the way, along with a rewrite of 'get_short_archi' in the spoolss client and server. (This pushes around const string pointers, rather than copied strings). Andrew Bartlett (This used to be commit 32fb801ddc035e8971e9911ed4b6e51892e9d1cc) --- source3/nmbd/nmbd_become_lmb.c | 3 +-- source3/nmbd/nmbd_browserdb.c | 4 ++-- source3/nmbd/nmbd_browsesync.c | 8 ++++++-- source3/nmbd/nmbd_incomingdgrams.c | 14 +++++++++----- source3/nmbd/nmbd_sendannounce.c | 8 ++++++-- source3/nmbd/nmbd_serverlistdb.c | 4 ++-- source3/nmbd/nmbd_workgroupdb.c | 2 +- 7 files changed, 27 insertions(+), 16 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index 6f8e7efb1a..d390bf72e9 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -600,6 +600,5 @@ local_master_browser_name for workgroup %s to workgroup name.\n", } #endif - StrnCpy(work->local_master_browser_name, newname, - sizeof(work->local_master_browser_name)-1); + fstrcpy(work->local_master_browser_name, newname); } diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c index a4ef98e265..d7c852605e 100644 --- a/source3/nmbd/nmbd_browserdb.c +++ b/source3/nmbd/nmbd_browserdb.c @@ -107,8 +107,8 @@ struct browse_cache_record *create_browser_in_lmb_cache( char *work_name, /* Allow the new lmb to miss an announce period before we remove it. */ browc->death_time = now + ( (CHECK_TIME_MST_ANNOUNCE + 2) * 60 ); - StrnCpy( browc->lmb_name, browser_name, sizeof(browc->lmb_name)-1 ); - StrnCpy( browc->work_group, work_name, sizeof(browc->work_group)-1 ); + pstrcpy( browc->lmb_name, browser_name); + pstrcpy( browc->work_group, work_name); strupper( browc->lmb_name ); strupper( browc->work_group ); diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index b9082ee1c3..ca8d269cb0 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -106,6 +106,7 @@ As a local master browser, send an announce packet to the domain master browser. static void announce_local_master_browser_to_domain_master_browser( struct work_record *work) { pstring outbuf; + fstring myname; char *p; if(ismyip(work->dmb_addr)) @@ -125,8 +126,11 @@ static void announce_local_master_browser_to_domain_master_browser( struct work_ SCVAL(p,0,ANN_MasterAnnouncement); p++; - StrnCpy(p,global_myname(),15); - strupper(p); + fstrcpy(myname, global_myname()); + strupper(myname); + myname[15]='\0'; + push_pstring_base(p, myname, outbuf); + p = skip_string(p,1); if( DEBUGLVL( 4 ) ) diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index cd6954fc62..16fecbccd9 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -172,7 +172,7 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p /* Update the record. */ servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; update_server_ttl( servrec, ttl); - StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1); + fstrcpy(servrec->serv.comment,comment); } } else @@ -343,7 +343,7 @@ a local master browser for workgroup %s and we think we are master. Forcing elec /* Update the record. */ servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; update_server_ttl(servrec, ttl); - StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1); + fstrcpy(servrec->serv.comment,comment); } set_workgroup_local_master_browser_name( work, server_name ); @@ -520,7 +520,7 @@ originate from OS/2 Warp client. Ignoring packet.\n")); /* Update the record. */ servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; update_server_ttl( servrec, ttl); - StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1); + fstrcpy(servrec->serv.comment,comment); } } else @@ -559,6 +559,7 @@ static void send_backup_list_response(struct subnet_record *subrec, #if 0 struct server_record *servrec; #endif + fstring myname; memset(outbuf,'\0',sizeof(outbuf)); @@ -578,8 +579,11 @@ static void send_backup_list_response(struct subnet_record *subrec, /* We always return at least one name - our own. */ count = 1; - StrnCpy(p,global_myname(),15); - strupper(p); + fstrcpy(myname, global_myname()); + strupper(myname); + myname[15]='\0'; + push_pstring_base(p, myname, outbuf); + p = skip_string(p,1); /* Look for backup browsers in this workgroup. */ diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index 40d07aae16..8501acf9ba 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -555,6 +555,7 @@ void browse_sync_remote(time_t t) struct work_record *work; pstring outbuf; char *p; + fstring myname; if (last_time && (t < (last_time + REMOTE_ANNOUNCE_INTERVAL))) return; @@ -589,8 +590,11 @@ for workgroup %s on subnet %s.\n", lp_workgroup(), FIRST_SUBNET->subnet_name )); SCVAL(p,0,ANN_MasterAnnouncement); p++; - StrnCpy(p,global_myname(),15); - strupper(p); + fstrcpy(myname, global_myname()); + strupper(myname); + myname[15]='\0'; + push_pstring_base(p, myname, outbuf); + p = skip_string(p,1); for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index ee0c021d5d..e99599e16f 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -153,8 +153,8 @@ workgroup %s. This is a bug.\n", name, work->work_group)); servrec->subnet = work->subnet; - StrnCpy(servrec->serv.name,name,sizeof(servrec->serv.name)-1); - StrnCpy(servrec->serv.comment,comment,sizeof(servrec->serv.comment)-1); + fstrcpy(servrec->serv.name,name); + fstrcpy(servrec->serv.comment,comment); strupper(servrec->serv.name); servrec->serv.type = servertype; diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index b8ea60dec0..2357fd637b 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -57,7 +57,7 @@ static struct work_record *create_workgroup(const char *name, int ttl) } memset((char *)work, '\0', sizeof(*work)); - StrnCpy(work->work_group,name,sizeof(work->work_group)-1); + fstrcpy(work->work_group,name); work->serverlist = NULL; work->RunningElection = False; -- cgit From 10dc904bb417c86474b06f8f56ee87211389fbca Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Fri, 25 Apr 2003 12:42:32 +0000 Subject: As nobody really objected to this patch, I opted to create facts :-) This uses 'socket address' as the source address for nmbd. This way we can again synchronize with the DMB if we have 'bind interfaces only' to a virtual interface. I'd love to see this in 2.2.9, but that is up to jerry or jra. Volker (This used to be commit fe637c690b671ddb5ccbf506825a9ede6abf6668) --- source3/nmbd/nmbd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 8e7759d90b..d9300f4668 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -547,7 +547,9 @@ static BOOL open_sockets(BOOL isdaemon, int port) */ if ( isdaemon ) - ClientNMB = open_socket_in(SOCK_DGRAM, port,0,0,True); + ClientNMB = open_socket_in(SOCK_DGRAM, port, + interpret_addr(lp_socket_address()), + 0,True); else ClientNMB = 0; -- cgit From 8be1c3a0e4faa7453663e64729b65757fad6efeb Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 28 Apr 2003 12:27:18 +0000 Subject: Fix a confusing error message Volker (This used to be commit 69df898afb45e2e577a10649f66f5352887044a2) --- source3/nmbd/nmbd_winsserver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 4ef476f814..47ce8119f3 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -241,7 +241,7 @@ BOOL initialise_wins(void) } if (tdb_fetch_int32(tdb, INFO_VERSION) != WINS_VERSION) { - DEBUG(0,("Discarding invalid wins.dat file\n")); + DEBUG(0,("Discarding invalid wins.tdb file\n")); tdb_close(tdb); return True; } -- cgit From 6b4330235f5aca9d3db9544738e6d1a6d3daac23 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 7 May 2003 01:00:36 +0000 Subject: We used to use the name "*",0x0 here, but some Windows servers don't answer that name. However we *know* they have the name workgroup#1b (as we just looked it up). So do the node status request on this name instead. Found at LBL labs. Jeremy. (This used to be commit 41e3abe8b80026812ea7dd7ad535e8e41e26daa4) --- source3/nmbd/nmbd_browsesync.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index ca8d269cb0..381f65e0c8 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -320,7 +320,15 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec, zero_ip(&work->dmb_addr); /* Now initiate the node status request. */ - make_nmb_name(&nmbname,"*",0x0); + + /* We used to use the name "*",0x0 here, but some Windows + * servers don't answer that name. However we *know* they + * have the name workgroup#1b (as we just looked it up). + * So do the node status request on this name instead. + * Found at LBL labs. JRA. + */ + + make_nmb_name(&nmbname,work->work_group,0x1b); /* Put the workgroup name into the userdata so we know what workgroup we're talking to when the reply comes -- cgit From 53f0ebc82b27347264c0ebc972487c6f62eb8933 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 8 May 2003 07:33:39 +0000 Subject: This puts back wins.dat into nmbd for easy editing. It leaves most of the other infrastructure with name owners etc in place. If anybody is really going to tackle winsrepld, it will probably not be hard to put the additional info back. Volker (This used to be commit eb82daa84a5339f28ebf431ee1044b7e1e4a4300) --- source3/nmbd/nmbd_winsserver.c | 416 ++++++++++++++++++++++------------------- 1 file changed, 222 insertions(+), 194 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 47ce8119f3..eafff03b76 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -22,7 +22,7 @@ #include "includes.h" -#define WINS_LIST "wins.tdb" +#define WINS_LIST "wins.dat" #define WINS_VERSION 1 /**************************************************************************** @@ -221,123 +221,177 @@ Load or create the WINS database. BOOL initialise_wins(void) { - time_t time_now = time(NULL); - TDB_CONTEXT *tdb; - TDB_DATA kbuf, dbuf, newkey; - struct name_record *namerec = NULL; - struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); + time_t time_now = time(NULL); + XFILE *fp; + pstring line; - DEBUG(2,("initialise_wins: started\n")); + if(!lp_we_are_a_wins_server()) + return True; - if(!lp_we_are_a_wins_server()) - return True; + add_samba_names_to_subnet(wins_server_subnet); - add_samba_names_to_subnet(wins_server_subnet); + if((fp = x_fopen(lock_path(WINS_LIST),O_RDONLY,0)) == NULL) + { + DEBUG(2,("initialise_wins: Can't open wins database file %s. Error was %s\n", + WINS_LIST, strerror(errno) )); + return True; + } - tdb = tdb_open_log(lock_path(WINS_LIST), 0, TDB_DEFAULT, O_RDONLY, 0600); - if (!tdb) { - DEBUG(2,("initialise_wins: Can't open wins database file %s. Error was %s\n", WINS_LIST, strerror(errno) )); - return True; - } + while (!x_feof(fp)) + { + pstring name_str, ip_str, ttl_str, nb_flags_str; + unsigned int num_ips; + pstring name; + struct in_addr *ip_list; + int type = 0; + int nb_flags; + int ttl; + const char *ptr; + char *p; + BOOL got_token; + BOOL was_ip; + int i; + unsigned hash; + int version; + + /* Read a line from the wins.dat file. Strips whitespace + from the beginning and end of the line. + */ + if (!fgets_slash(line,sizeof(pstring),fp)) + continue; + + if (*line == '#') + continue; + + if (strncmp(line,"VERSION ", 8) == 0) { + if (sscanf(line,"VERSION %d %u", &version, &hash) != 2 || + version != WINS_VERSION) { + DEBUG(0,("Discarding invalid wins.dat file [%s]\n",line)); + x_fclose(fp); + return True; + } + continue; + } - if (tdb_fetch_int32(tdb, INFO_VERSION) != WINS_VERSION) { - DEBUG(0,("Discarding invalid wins.tdb file\n")); - tdb_close(tdb); - return True; - } + ptr = line; - for (kbuf = tdb_firstkey(tdb); - kbuf.dptr; - newkey = tdb_nextkey(tdb, kbuf), safe_free(kbuf.dptr), kbuf=newkey) { - - fstring name_type; - pstring name, ip_str; - char *p; - int type = 0; - int nb_flags; - int ttl; - unsigned int num_ips; - int high, low; - struct in_addr wins_ip; - struct in_addr *ip_list; - int wins_flags; - int len,i; - - if (strncmp(kbuf.dptr, ENTRY_PREFIX, strlen(ENTRY_PREFIX)) != 0) - continue; - - dbuf = tdb_fetch(tdb, kbuf); - if (!dbuf.dptr) - continue; + /* + * Now we handle multiple IP addresses per name we need + * to iterate over the line twice. The first time to + * determine how many IP addresses there are, the second + * time to actually parse them into the ip_list array. + */ - fstrcpy(name_type, kbuf.dptr+strlen(ENTRY_PREFIX)); + if (!next_token(&ptr,name_str,NULL,sizeof(name_str))) + { + DEBUG(0,("initialise_wins: Failed to parse name when parsing line %s\n", line )); + continue; + } - pstrcpy(name, name_type); + if (!next_token(&ptr,ttl_str,NULL,sizeof(ttl_str))) + { + DEBUG(0,("initialise_wins: Failed to parse time to live when parsing line %s\n", line )); + continue; + } - if((p = strchr(name,'#')) != NULL) { - *p = 0; - sscanf(p+1,"%x",&type); - } + /* + * Determine the number of IP addresses per line. + */ + num_ips = 0; + do + { + got_token = next_token(&ptr,ip_str,NULL,sizeof(ip_str)); + was_ip = False; - len = tdb_unpack(dbuf.dptr, dbuf.dsize, "dddfddd", - &nb_flags, &high, &low, - ip_str, &ttl, &num_ips, &wins_flags); + if(got_token && strchr(ip_str, '.')) + { + num_ips++; + was_ip = True; + } + } while( got_token && was_ip); - wins_ip=*interpret_addr2(ip_str); + if(num_ips == 0) + { + DEBUG(0,("initialise_wins: Missing IP address when parsing line %s\n", line )); + continue; + } - /* Don't reload replica records */ - if (!ip_equal(wins_ip, our_fake_ip)) { - SAFE_FREE(dbuf.dptr); - continue; - } + if(!got_token) + { + DEBUG(0,("initialise_wins: Missing nb_flags when parsing line %s\n", line )); + continue; + } - /* Don't reload released or tombstoned records */ - if ((wins_flags&WINS_STATE_MASK) != WINS_ACTIVE) { - SAFE_FREE(dbuf.dptr); - continue; - } + /* Allocate the space for the ip_list. */ + if((ip_list = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr))) == NULL) + { + DEBUG(0,("initialise_wins: Malloc fail !\n")); + return False; + } + + /* Reset and re-parse the line. */ + ptr = line; + next_token(&ptr,name_str,NULL,sizeof(name_str)); + next_token(&ptr,ttl_str,NULL,sizeof(ttl_str)); + for(i = 0; i < num_ips; i++) + { + next_token(&ptr, ip_str, NULL, sizeof(ip_str)); + ip_list[i] = *interpret_addr2(ip_str); + } + next_token(&ptr,nb_flags_str,NULL, sizeof(nb_flags_str)); - /* Allocate the space for the ip_list. */ - if((ip_list = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr))) == NULL) { - SAFE_FREE(dbuf.dptr); - DEBUG(0,("initialise_wins: Malloc fail !\n")); - return False; - } + /* + * Deal with SELF or REGISTER name encoding. Default is REGISTER + * for compatibility with old nmbds. + */ - for (i = 0; i < num_ips; i++) { - len += tdb_unpack(dbuf.dptr+len, dbuf.dsize-len, "f", ip_str); - ip_list[i] = *interpret_addr2(ip_str); - } + if(nb_flags_str[strlen(nb_flags_str)-1] == 'S') + { + DEBUG(5,("initialise_wins: Ignoring SELF name %s\n", line)); + SAFE_FREE(ip_list); + continue; + } + + if(nb_flags_str[strlen(nb_flags_str)-1] == 'R') + nb_flags_str[strlen(nb_flags_str)-1] = '\0'; + + /* Netbios name. # divides the name from the type (hex): netbios#xx */ + pstrcpy(name,name_str); + + if((p = strchr(name,'#')) != NULL) + { + *p = 0; + sscanf(p+1,"%x",&type); + } + + /* Decode the netbios flags (hex) and the time-to-live (in seconds). */ + sscanf(nb_flags_str,"%x",&nb_flags); + sscanf(ttl_str,"%d",&ttl); - /* add all entries that have 60 seconds or more to live */ - if ((ttl - 60) > time_now || ttl == PERMANENT_TTL) { - if(ttl != PERMANENT_TTL) - ttl -= time_now; + /* add all entries that have 60 seconds or more to live */ + if ((ttl - 60) > time_now || ttl == PERMANENT_TTL) + { + if(ttl != PERMANENT_TTL) + ttl -= time_now; - DEBUG( 4, ("initialise_wins: add name: %s#%02x ttl = %d first IP %s flags = %2x\n", - name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); - - namerec=add_name_to_subnet( wins_server_subnet, name, type, nb_flags, - ttl, REGISTER_NAME, num_ips, ip_list); - if (namerec!=NULL) { - update_wins_owner(namerec, wins_ip); - update_wins_flag(namerec, wins_flags); - /* we don't reload the ID, on startup we restart at 1 */ - get_global_id_and_update(&namerec->data.id, True); - } + DEBUG( 4, ("initialise_wins: add name: %s#%02x ttl = %d first IP %s flags = %2x\n", + name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); - } else { - DEBUG(4, ("initialise_wins: not adding name (ttl problem) %s#%02x ttl = %d first IP %s flags = %2x\n", - name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); - } + (void)add_name_to_subnet( wins_server_subnet, name, type, nb_flags, + ttl, REGISTER_NAME, num_ips, ip_list ); - SAFE_FREE(dbuf.dptr); - SAFE_FREE(ip_list); - } + } + else + { + DEBUG(4, ("initialise_wins: not adding name (ttl problem) %s#%02x ttl = %d first IP %s flags = %2x\n", + name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); + } + + SAFE_FREE(ip_list); + } - tdb_close(tdb); - DEBUG(2,("initialise_wins: done\n")); - return True; + x_fclose(fp); + return True; } /**************************************************************************** @@ -1765,113 +1819,87 @@ we are not the wins owner !\n", nmb_namestr(&namerec->name))); ******************************************************************/ void wins_write_database(BOOL background) { - struct name_record *namerec; - pstring fname, fnamenew; - TDB_CONTEXT *tdb; - TDB_DATA kbuf, dbuf; - pstring key, buf; - int len; - int num_record=0; - SMB_BIG_UINT id; - - if(!lp_we_are_a_wins_server()) - return; - - /* we will do the writing in a child process to ensure that the parent - doesn't block while this is done */ - if (background) { - CatchChild(); - if (sys_fork()) { - return; - } - } - - slprintf(fname,sizeof(fname)-1,"%s/%s", lp_lockdir(), WINS_LIST); - all_string_sub(fname,"//", "/", 0); - slprintf(fnamenew,sizeof(fnamenew)-1,"%s.%u", fname, (unsigned int)sys_getpid()); - - tdb = tdb_open_log(fnamenew, 0, TDB_DEFAULT, O_RDWR|O_CREAT|O_TRUNC, 0644); - if (!tdb) { - DEBUG(0,("wins_write_database: Can't open %s. Error was %s\n", fnamenew, strerror(errno))); - if (background) - _exit(0); - return; - } - - DEBUG(3,("wins_write_database: Dump of WINS name list.\n")); - - tdb_store_int32(tdb, INFO_VERSION, WINS_VERSION); - - for (namerec = (struct name_record *)ubi_trFirst( wins_server_subnet->namelist ); - namerec; - namerec = (struct name_record *)ubi_trNext( namerec ) ) { - - int i; - struct tm *tm; - - DEBUGADD(3,("%-19s ", nmb_namestr(&namerec->name) )); + struct name_record *namerec; + pstring fname, fnamenew; - if( namerec->data.death_time != PERMANENT_TTL ) { - char *ts, *nl; - - tm = LocalTime(&namerec->data.death_time); - ts = asctime(tm); - nl = strrchr_m( ts, '\n' ); - if( NULL != nl ) - *nl = '\0'; + XFILE *fp; + + if(!lp_we_are_a_wins_server()) + return; - DEBUGADD(3,("TTL = %s ", ts )); - } else - DEBUGADD(3,("TTL = PERMANENT ")); + /* we will do the writing in a child process to ensure that the parent + doesn't block while this is done */ + if (background) { + CatchChild(); + if (sys_fork()) { + return; + } + } - for (i = 0; i < namerec->data.num_ips; i++) - DEBUGADD(0,("%15s ", inet_ntoa(namerec->data.ip[i]) )); + slprintf(fname,sizeof(fname)-1,"%s/%s", lp_lockdir(), WINS_LIST); + all_string_sub(fname,"//", "/", 0); + slprintf(fnamenew,sizeof(fnamenew)-1,"%s.%u", fname, (unsigned int)sys_getpid()); - DEBUGADD(3,("0x%2x 0x%2x %15s\n", namerec->data.nb_flags, namerec->data.wins_flags, inet_ntoa(namerec->data.wins_ip))); + if((fp = x_fopen(fnamenew,O_WRONLY|O_CREAT,0644)) == NULL) + { + DEBUG(0,("wins_write_database: Can't open %s. Error was %s\n", fnamenew, strerror(errno))); + if (background) { + _exit(0); + } + return; + } - if( namerec->data.source == REGISTER_NAME ) { - - /* store the type in the key to make the name unique */ - slprintf(key, sizeof(key), "%s%s#%02x", ENTRY_PREFIX, namerec->name.name, namerec->name.name_type); - - len = tdb_pack(buf, sizeof(buf), "dddfddd", - (int)namerec->data.nb_flags, - (int)(namerec->data.id>>32), - (int)(namerec->data.id&0xffffffff), - inet_ntoa(namerec->data.wins_ip), - (int)namerec->data.death_time, - namerec->data.num_ips, - namerec->data.wins_flags); - - for (i = 0; i < namerec->data.num_ips; i++) - len += tdb_pack(buf+len, sizeof(buf)-len, "f", inet_ntoa(namerec->data.ip[i])); - - kbuf.dsize = strlen(key)+1; - kbuf.dptr = key; - dbuf.dsize = len; - dbuf.dptr = buf; - if (tdb_store(tdb, kbuf, dbuf, TDB_INSERT) != 0) return; + DEBUG(4,("wins_write_database: Dump of WINS name list.\n")); - num_record++; - } - } + x_fprintf(fp,"VERSION %d %u\n", WINS_VERSION, 0); + + for( namerec + = (struct name_record *)ubi_trFirst( wins_server_subnet->namelist ); + namerec; + namerec = (struct name_record *)ubi_trNext( namerec ) ) + { + int i; + struct tm *tm; - /* store the number of records */ - tdb_store_int32(tdb, INFO_COUNT, num_record); + DEBUGADD(4,("%-19s ", nmb_namestr(&namerec->name) )); - /* get and store the last used ID */ - get_global_id_and_update(&id, False); - tdb_store_int32(tdb, INFO_ID_HIGH, id>>32); - tdb_store_int32(tdb, INFO_ID_LOW, id&0xffffffff); + if( namerec->data.death_time != PERMANENT_TTL ) + { + char *ts, *nl; + + tm = LocalTime(&namerec->data.death_time); + ts = asctime(tm); + nl = strrchr( ts, '\n' ); + if( NULL != nl ) + *nl = '\0'; + DEBUGADD(4,("TTL = %s ", ts )); + } + else + DEBUGADD(4,("TTL = PERMANENT ")); - tdb_close(tdb); + for (i = 0; i < namerec->data.num_ips; i++) + DEBUGADD(4,("%15s ", inet_ntoa(namerec->data.ip[i]) )); + DEBUGADD(4,("%2x\n", namerec->data.nb_flags )); - chmod(fnamenew,0644); - unlink(fname); - rename(fnamenew,fname); + if( namerec->data.source == REGISTER_NAME ) + { + x_fprintf(fp, "\"%s#%02x\" %d ", + namerec->name.name,namerec->name.name_type, /* Ignore scope. */ + (int)namerec->data.death_time); - if (background) - _exit(0); + for (i = 0; i < namerec->data.num_ips; i++) + x_fprintf( fp, "%s ", inet_ntoa( namerec->data.ip[i] ) ); + x_fprintf( fp, "%2xR\n", namerec->data.nb_flags ); + } + } + + x_fclose(fp); + chmod(fnamenew,0644); + unlink(fname); + rename(fnamenew,fname); + if (background) { + _exit(0); + } } /**************************************************************************** -- cgit From 417d0e9afc321612a55928d5aa7ec6ead8dfcc0c Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 8 May 2003 21:19:58 +0000 Subject: fix bug #47; revert registration of workgroup<1b> to 2.2 behavior (This used to be commit 016f6b4e19c2b8e4f5e1d010cc428ca194650140) --- source3/nmbd/nmbd_become_dmb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index 6b92f4c3c0..2e76e51f45 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -375,7 +375,7 @@ void add_domain_names(time_t t) add_logon_names(); /* Do the domain master names. */ - if(lp_server_role() == ROLE_DOMAIN_PDC) + if(lp_domain_master()) { if(we_are_a_wins_client()) { -- cgit From c507ebe56741d773bf6e7ad547863a2da1aee687 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 10 May 2003 10:53:48 +0000 Subject: Patch from metze and me that adds dummy smb_register_*() functions so that is now possible to, for example, load a module which contains an auth method into a binary without the auth/ subsystem built in. (This used to be commit 74d9ecfe2dd7364643d32acb62ade957bd71cd0d) --- source3/nmbd/nmbd.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index d9300f4668..411a406a92 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -23,6 +23,8 @@ #include "includes.h" +#include "module_dummy.h" + int ClientNMB = -1; int ClientDGRAM = -1; int global_nmb_port = -1; -- cgit From 0914e541f5480834c1b0ddc98b5f71f7f7abf9cb Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 10 May 2003 11:49:51 +0000 Subject: Reverse previous patch from Stefan and me after comments by Andrew Bartlett (This used to be commit d817eaf0ecca2d878ab1ffcf7a747a02d71c811e) --- source3/nmbd/nmbd.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 411a406a92..d9300f4668 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -23,8 +23,6 @@ #include "includes.h" -#include "module_dummy.h" - int ClientNMB = -1; int ClientDGRAM = -1; int global_nmb_port = -1; -- cgit From 40c53cae2bd6f104bdd1ffe53a1cb58891824eac Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Tue, 20 May 2003 13:49:53 +0000 Subject: Fix bug #98: DNS compression is required for proper building of the netlogon for ads packet. repeated DNS components will not be properly encoded otherwise. (This used to be commit 1e85a9ed8da2e48b0ef586599742ed515bd91ecd) --- source3/nmbd/nmbd_processlogon.c | 67 +++++++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 25 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index a702fc3015..42edcc871f 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -304,19 +304,19 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", pstring hostname; char *component, *dc, *q1; uint8 size; + char *q_orig = q; + int str_offset; get_mydomname(domain); get_myname(hostname); if (SVAL(uniuser, 0) == 0) { - SSVAL(q, 0, SAMLOGON_AD_UNK_R); /* user unknown */ + SIVAL(q, 0, SAMLOGON_AD_UNK_R); /* user unknown */ } else { - SSVAL(q, 0, SAMLOGON_AD_R); + SIVAL(q, 0, SAMLOGON_AD_R); } - q += 2; + q += 4; - SSVAL(q, 0, 0); - q += 2; SIVAL(q, 0, ADS_PDC|ADS_GC|ADS_LDAP|ADS_DS| ADS_KDC|ADS_TIMESERV|ADS_CLOSEST|ADS_WRITABLE); q += 4; @@ -329,7 +329,8 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", memcpy(q, &domain_guid, sizeof(domain_guid)); q += sizeof(domain_guid); - /* Push domain components */ + /* Forest */ + str_offset = q - q_orig; dc = domain; q1 = q; while ((component = strtok(dc, "."))) { @@ -338,44 +339,60 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", SCVAL(q, 0, size); q += (size + 1); } + + /* Unk0 */ SCVAL(q, 0, 0); q++; - SSVAL(q, 0, 0x18c0); /* not sure what this is for, but */ - q += 2; /* it must follow the domain name. */ - /* Push dns host name */ + /* Domain */ + SCVAL(q, 0, 0xc0 | ((str_offset >> 8) & 0x3F)); + SCVAL(q, 1, str_offset & 0xFF); + q += 2; + + /* Hostname */ size = push_ascii(&q[1], hostname, -1, 0); SCVAL(q, 0, size); q += (size + 1); - SSVAL(q, 0, 0x18c0); /* not sure what this is for, but */ - q += 2; /* it must follow the domain name. */ + SCVAL(q, 0, 0xc0 | ((str_offset >> 8) & 0x3F)); + SCVAL(q, 1, str_offset & 0xFF); + q += 2; - /* Push NETBIOS of domain */ + /* NETBIOS of domain */ size = push_ascii(&q[1], lp_workgroup(), -1, STR_UPPER); SCVAL(q, 0, size); q += (size + 1); - SCVAL(q, 0, 0); q++; /* is this a null terminator or empty field */ - /* null terminator would not be needed because size is included */ - /* Push NETBIOS of hostname */ + /* Unk1 */ + SCVAL(q, 0, 0); q++; + + /* NETBIOS of hostname */ size = push_ascii(&q[1], my_name, -1, 0); SCVAL(q, 0, size); q += (size + 1); - SCVAL(q, 0, 0); q++; /* null terminator or empty field? */ - /* Push user account */ - size = push_ascii(&q[1], ascuser, -1, 0); - SCVAL(q, 0, size); - q += (size + 1); + /* Unk2 */ + SCVAL(q, 0, 0); q++; + + /* User name */ + if (SVAL(uniuser, 0) != 0) { + size = push_ascii(&q[1], ascuser, -1, 0); + SCVAL(q, 0, size); + q += (size + 1); + } - /* Push 'Default-First-Site-Name' */ + q_orig = q; + /* Site name */ size = push_ascii(&q[1], "Default-First-Site-Name", -1, 0); SCVAL(q, 0, size); q += (size + 1); - SSVAL(q, 0, 0xc000); /* unknown */ - SCVAL(q, 2, PTR_DIFF(q,q1)); - SCVAL(q, 3, 0x10); /* unknown */ - q += 4; + /* Site name (2) */ + str_offset = q - q_orig; + SCVAL(q, 0, 0xc0 | ((str_offset >> 8) & 0x3F)); + SCVAL(q, 1, str_offset & 0xFF); + q += 2; + + SCVAL(q, 0, PTR_DIFF(q,q1)); + SCVAL(q, 1, 0x10); /* unknown */ SIVAL(q, 0, 0x00000002); q += 4; /* unknown */ SIVAL(q, 0, (iface_ip(p->ip))->s_addr); q += 4; -- cgit From ce72beb2b558d86fb49063c6b1fa00e07952ce56 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 3 Jul 2003 19:11:31 +0000 Subject: Removed strupper/strlower macros that automatically map to strupper_m/strlower_m. I really want people to think about when they're using multibyte strings. Jeremy. (This used to be commit ff222716a08af65d26ad842ce4c2841cc6540959) --- source3/nmbd/nmbd_browserdb.c | 139 +++++++++++++++++------------------ source3/nmbd/nmbd_browsesync.c | 2 +- source3/nmbd/nmbd_elections.c | 2 +- source3/nmbd/nmbd_incomingdgrams.c | 4 +- source3/nmbd/nmbd_incomingrequests.c | 2 +- source3/nmbd/nmbd_namelistdb.c | 4 +- source3/nmbd/nmbd_sendannounce.c | 4 +- source3/nmbd/nmbd_serverlistdb.c | 2 +- 8 files changed, 76 insertions(+), 83 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c index d7c852605e..4a302ddfd4 100644 --- a/source3/nmbd/nmbd_browserdb.c +++ b/source3/nmbd/nmbd_browserdb.c @@ -37,7 +37,6 @@ ubi_dlNewList( lmb_browserlist ); - /* -------------------------------------------------------------------------- ** * Functions... */ @@ -52,9 +51,9 @@ ubi_dlNewList( lmb_browserlist ); * ************************************************************************** ** */ static void remove_lmb_browser_entry( struct browse_cache_record *browc ) - { - safe_free( ubi_dlRemThis( lmb_browserlist, browc ) ); - } /* remove_lmb_browser_entry */ +{ + safe_free( ubi_dlRemThis( lmb_browserlist, browc ) ); +} /* ************************************************************************** ** * Update a browser death time. @@ -65,10 +64,10 @@ static void remove_lmb_browser_entry( struct browse_cache_record *browc ) * ************************************************************************** ** */ void update_browser_death_time( struct browse_cache_record *browc ) - { - /* Allow the new lmb to miss an announce period before we remove it. */ - browc->death_time = time(NULL) + ( (CHECK_TIME_MST_ANNOUNCE + 2) * 60 ); - } /* update_browser_death_time */ +{ + /* Allow the new lmb to miss an announce period before we remove it. */ + browc->death_time = time(NULL) + ( (CHECK_TIME_MST_ANNOUNCE + 2) * 60 ); +} /* ************************************************************************** ** * Create a browser entry and add it to the local master browser list. @@ -84,48 +83,47 @@ void update_browser_death_time( struct browse_cache_record *browc ) struct browse_cache_record *create_browser_in_lmb_cache( char *work_name, char *browser_name, struct in_addr ip ) - { - struct browse_cache_record *browc; - time_t now = time( NULL ); +{ + struct browse_cache_record *browc; + time_t now = time( NULL ); - browc = (struct browse_cache_record *)malloc( sizeof( *browc ) ); + browc = (struct browse_cache_record *)malloc( sizeof( *browc ) ); - if( NULL == browc ) - { - DEBUG( 0, ("create_browser_in_lmb_cache: malloc fail !\n") ); - return( NULL ); - } + if( NULL == browc ) { + DEBUG( 0, ("create_browser_in_lmb_cache: malloc fail !\n") ); + return( NULL ); + } - memset( (char *)browc, '\0', sizeof( *browc ) ); + memset( (char *)browc, '\0', sizeof( *browc ) ); - /* For a new lmb entry we want to sync with it after one minute. This - will allow it time to send out a local announce and build its - browse list. - */ - browc->sync_time = now + 60; - - /* Allow the new lmb to miss an announce period before we remove it. */ - browc->death_time = now + ( (CHECK_TIME_MST_ANNOUNCE + 2) * 60 ); - - pstrcpy( browc->lmb_name, browser_name); - pstrcpy( browc->work_group, work_name); - strupper( browc->lmb_name ); - strupper( browc->work_group ); + /* For a new lmb entry we want to sync with it after one minute. This + will allow it time to send out a local announce and build its + browse list. + */ + + browc->sync_time = now + 60; + + /* Allow the new lmb to miss an announce period before we remove it. */ + browc->death_time = now + ( (CHECK_TIME_MST_ANNOUNCE + 2) * 60 ); + + pstrcpy( browc->lmb_name, browser_name); + pstrcpy( browc->work_group, work_name); + strupper_m( browc->lmb_name ); + strupper_m( browc->work_group ); - browc->ip = ip; + browc->ip = ip; - (void)ubi_dlAddTail( lmb_browserlist, browc ); - - if( DEBUGLVL( 3 ) ) - { - Debug1( "nmbd_browserdb:create_browser_in_lmb_cache()\n" ); - Debug1( " Added lmb cache entry for workgroup %s ", browc->work_group ); - Debug1( "name %s IP %s ", browc->lmb_name, inet_ntoa(ip) ); - Debug1( "ttl %d\n", (int)browc->death_time ); - } + (void)ubi_dlAddTail( lmb_browserlist, browc ); + + if( DEBUGLVL( 3 ) ) { + Debug1( "nmbd_browserdb:create_browser_in_lmb_cache()\n" ); + Debug1( " Added lmb cache entry for workgroup %s ", browc->work_group ); + Debug1( "name %s IP %s ", browc->lmb_name, inet_ntoa(ip) ); + Debug1( "ttl %d\n", (int)browc->death_time ); + } - return( browc ); - } /* create_browser_in_lmb_cache */ + return( browc ); +} /* ************************************************************************** ** * Find a browser entry in the local master browser list. @@ -137,17 +135,16 @@ struct browse_cache_record *create_browser_in_lmb_cache( char *work_name, * ************************************************************************** ** */ struct browse_cache_record *find_browser_in_lmb_cache( char *browser_name ) - { - struct browse_cache_record *browc; +{ + struct browse_cache_record *browc; - for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist ); - browc; - browc = (struct browse_cache_record *)ubi_dlNext( browc ) ) - if( strequal( browser_name, browc->lmb_name ) ) - break; + for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist ); + browc; browc = (struct browse_cache_record *)ubi_dlNext( browc ) ) + if( strequal( browser_name, browc->lmb_name ) ) + break; - return( browc ); - } /* find_browser_in_lmb_cache */ + return( browc ); +} /* ************************************************************************** ** * Expire timed out browsers in the browserlist. @@ -159,24 +156,20 @@ struct browse_cache_record *find_browser_in_lmb_cache( char *browser_name ) * ************************************************************************** ** */ void expire_lmb_browsers( time_t t ) - { - struct browse_cache_record *browc; - struct browse_cache_record *nextbrowc; - - for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist ); - browc; - browc = nextbrowc ) - { - nextbrowc = (struct browse_cache_record *)ubi_dlNext( browc ); - - if( browc->death_time < t ) - { - if( DEBUGLVL( 3 ) ) - { - Debug1( "nmbd_browserdb:expire_lmb_browsers()\n" ); - Debug1( " Removing timed out lmb entry %s\n", browc->lmb_name ); - } - remove_lmb_browser_entry( browc ); - } - } - } /* expire_lmb_browsers */ +{ + struct browse_cache_record *browc; + struct browse_cache_record *nextbrowc; + + for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist ); + browc; browc = nextbrowc ) { + nextbrowc = (struct browse_cache_record *)ubi_dlNext( browc ); + + if( browc->death_time < t ) { + if( DEBUGLVL( 3 ) ) { + Debug1( "nmbd_browserdb:expire_lmb_browsers()\n" ); + Debug1( " Removing timed out lmb entry %s\n", browc->lmb_name ); + } + remove_lmb_browser_entry( browc ); + } + } +} diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 381f65e0c8..26d4735744 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -127,7 +127,7 @@ static void announce_local_master_browser_to_domain_master_browser( struct work_ p++; fstrcpy(myname, global_myname()); - strupper(myname); + strupper_m(myname); myname[15]='\0'; push_pstring_base(p, myname, outbuf); diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 339a27d207..b948eb9d04 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -48,7 +48,7 @@ static void send_election_dgram(struct subnet_record *subrec, const char *workgr SIVAL(p,5,timeup*1000); /* ms - Despite what the spec says. */ p += 13; pstrcpy_base(p, server_name, outbuf); - strupper(p); + strupper_m(p); p = skip_string(p,1); send_mailslot(False, BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 16fecbccd9..80465ada0d 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -580,7 +580,7 @@ static void send_backup_list_response(struct subnet_record *subrec, /* We always return at least one name - our own. */ count = 1; fstrcpy(myname, global_myname()); - strupper(myname); + strupper_m(myname); myname[15]='\0'; push_pstring_base(p, myname, outbuf); @@ -614,7 +614,7 @@ static void send_backup_list_response(struct subnet_record *subrec, continue; StrnCpy(p, servrec->serv.name, 15); - strupper(p); + strupper_m(p); count++; DEBUG(5,("send_backup_list_response: Adding server %s number %d\n", diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index a8168566f1..a3faf5e104 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -364,7 +364,7 @@ subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name), /* Start with the name. */ memset(buf,'\0',18); slprintf(buf, 17, "%-15.15s",namerec->name.name); - strupper(buf); + strupper_m(buf); /* Put the name type and netbios flags in the buffer. */ buf[15] = name_type; diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 932d926a91..3f6d2f3b64 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -49,8 +49,8 @@ static void upcase_name( struct nmb_name *target, struct nmb_name *source ) if( NULL != source ) (void)memcpy( target, source, sizeof( struct nmb_name ) ); - strupper( target->name ); - strupper( target->scope ); + strupper_m( target->name ); + strupper_m( target->scope ); /* fudge... We're using a byte-by-byte compare, so we must be sure that * unused space doesn't have garbage in it. diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index 8501acf9ba..353717ee62 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -142,7 +142,7 @@ static void send_lm_announcement(struct subnet_record *subrec, int announce_type p += 10; /*StrnCpy(p,server_name,15); - strupper(p); + strupper_m(p); p = skip_string(p,1); pstrcpy(p,server_comment); p = skip_string(p,1);*/ @@ -591,7 +591,7 @@ for workgroup %s on subnet %s.\n", lp_workgroup(), FIRST_SUBNET->subnet_name )); p++; fstrcpy(myname, global_myname()); - strupper(myname); + strupper_m(myname); myname[15]='\0'; push_pstring_base(p, myname, outbuf); diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index e99599e16f..2484a7f830 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -155,7 +155,7 @@ workgroup %s. This is a bug.\n", name, work->work_group)); fstrcpy(servrec->serv.name,name); fstrcpy(servrec->serv.comment,comment); - strupper(servrec->serv.name); + strupper_m(servrec->serv.name); servrec->serv.type = servertype; update_server_ttl(servrec, ttl); -- cgit From 8c4be2bbc9d1b42ae1b26a3a2519dd2c911dee45 Mon Sep 17 00:00:00 2001 From: Alexander Bokovoy Date: Tue, 15 Jul 2003 17:21:21 +0000 Subject: Add support for MSG_SMB_CONF_UPDATED and MSG_SHUTDOWN to all daemons (smbd, nmbd, winbindd). Reviewed by jerry and tridge. (This used to be commit 02c5e2fc6f0721ebd82a9e6a2b34190607de55fe) --- source3/nmbd/nmbd.c | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index d9300f4668..2801e54551 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -298,6 +298,28 @@ static BOOL reload_nmbd_services(BOOL test) return(ret); } +/**************************************************************************** ** + * React on 'smbcontrol nmbd reload-config' in the same way as to SIGHUP + * We use buf here to return BOOL result to process() when reload_interfaces() + * detects that there are no subnets. + **************************************************************************** */ +static void msg_reload_nmbd_services(int msg_type, pid_t src, void *buf, size_t len) +{ + write_browse_list( 0, True ); + dump_all_namelists(); + reload_nmbd_services( True ); + reopen_logs(); + + if(buf) { + /* We were called from process() */ + /* If reload_interfaces() returned True */ + /* we need to shutdown if there are no subnets... */ + /* pass this info back to process() */ + *((BOOL*)buf) = reload_interfaces(0); + } +} + + /**************************************************************************** ** The main select loop. **************************************************************************** */ @@ -305,6 +327,7 @@ static BOOL reload_nmbd_services(BOOL test) static void process(void) { BOOL run_election; + BOOL no_subnets; while( True ) { time_t t = time(NULL); @@ -513,11 +536,8 @@ static void process(void) if(reload_after_sighup) { DEBUG( 0, ( "Got SIGHUP dumping debug info.\n" ) ); - write_browse_list( 0, True ); - dump_all_namelists(); - reload_nmbd_services( True ); - reopen_logs(); - if(reload_interfaces(0)) + msg_reload_nmbd_services(MSG_SMB_CONF_UPDATED, (pid_t) 0, (void*) &no_subnets, 0); + if(no_subnets) return; reload_after_sighup = 0; } @@ -696,6 +716,7 @@ static BOOL open_sockets(BOOL isdaemon, int port) message_register(MSG_FORCE_ELECTION, nmbd_message_election); message_register(MSG_WINS_NEW_ENTRY, nmbd_wins_new_entry); message_register(MSG_SHUTDOWN, nmbd_terminate); + message_register(MSG_SMB_CONF_UPDATED, msg_reload_nmbd_services); DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); -- cgit From f210ee9b99b3b6ac0234680f1af83fd783ef9af4 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Fri, 1 Aug 2003 14:47:39 +0000 Subject: Fix copyright statements for various pieces of Anthony Liguori's work. (This used to be commit 15d2bc47854df75f8b2644ccbc887d0357d9cd27) --- source3/nmbd/nmbd_processlogon.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 42edcc871f..7d6cd1ceab 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -5,7 +5,6 @@ Copyright (C) Luke Kenneth Casson Leighton 1994-1998 Copyright (C) Jeremy Allison 1994-1998 Copyright (C) Jim McDonough 2002 - Copyright (C) Anthony Liguori 2002 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -- cgit From 8c64504f7c58b05769ec1014242c15a2eb93ca84 Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Fri, 1 Aug 2003 15:30:44 +0000 Subject: Update my copyrights according to my agreement with IBM (This used to be commit a2bd8f0bfa12f2a1e33c96bc9dabcc0e2171700d) --- source3/nmbd/nmbd_processlogon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 7d6cd1ceab..bc3540af70 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -4,7 +4,7 @@ Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 Copyright (C) Jeremy Allison 1994-1998 - Copyright (C) Jim McDonough 2002 + Copyright (C) Jim McDonough 2002 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by -- cgit From 8bfe26b62db2e671b143d93a5428f8fb64a9df05 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 20 Aug 2003 17:13:38 +0000 Subject: metze's autogenerate patch for version.h (This used to be commit ae452e51b02672a56adf18aa7a7e365eeaba9272) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 2801e54551..fd648a4a27 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -659,7 +659,7 @@ static BOOL open_sockets(BOOL isdaemon, int port) reopen_logs(); - DEBUG( 0, ( "Netbios nameserver version %s started.\n", VERSION ) ); + DEBUG( 0, ( "Netbios nameserver version %s started.\n", SAMBA_VERSION_STRING) ); DEBUGADD( 0, ( "Copyright Andrew Tridgell and the Samba Team 1994-2003\n" ) ); if ( !reload_nmbd_services(False) ) -- cgit From 647a048ad085c74ebbddb1957b690f3cb9ced178 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 22 Aug 2003 00:26:37 +0000 Subject: Ensure nmb_namestr() converts back from CH_DOS to CH_UNIX. Jeremy. (This used to be commit eb792727437c74417f5ef7614b300ab84f06fdaf) --- source3/nmbd/nmbd_winsserver.c | 8 -------- 1 file changed, 8 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index eafff03b76..cd39dc5e21 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -2050,11 +2050,3 @@ void nmbd_wins_new_entry(int msg_type, pid_t src, void *buf, size_t len) } } - - - - - - - - -- cgit From 5dfeda00028c1d22428736a85140dec6f46ff94c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 22 Aug 2003 21:41:50 +0000 Subject: Use correct size (17 not 16) when doing a push_ascii(). Ensure that wins hook is called with unix charset. Jeremy. (This used to be commit ecb80573870103de7b3f332fb53bf6b952f25ee7) --- source3/nmbd/nmbd_winsserver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index cd39dc5e21..784c909c81 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -120,7 +120,7 @@ static void wins_hook(const char *operation, struct name_record *namerec, int tt p += slprintf(p, sizeof(command)-1, "%s %s %s %02x %d", cmd, operation, - namerec->name.name, + nmb_namestr(&namerec->name), namerec->name.name_type, ttl); -- cgit From dac11b890b3e81f8849340e582b7f397a612baba Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 23 Aug 2003 01:59:14 +0000 Subject: Half-way though the big conversion of all nmbd access to wire elements being converted to pull/push_ascii. This will not work right at the moment for non English codepages, but compiles - I will finish the work over the weekend. Then nmbd should be completely codepage correct. Jeremy. (This used to be commit 236d6adadf32397b28028ea82ae2ec027366f7c8) --- source3/nmbd/nmbd.c | 205 ++++--- source3/nmbd/nmbd_become_dmb.c | 522 +++++++++-------- source3/nmbd/nmbd_become_lmb.c | 688 +++++++++++------------ source3/nmbd/nmbd_browserdb.c | 6 +- source3/nmbd/nmbd_browsesync.c | 841 +++++++++++++--------------- source3/nmbd/nmbd_elections.c | 527 +++++++++-------- source3/nmbd/nmbd_incomingdgrams.c | 1087 ++++++++++++++++++------------------ source3/nmbd/nmbd_namequery.c | 4 +- 8 files changed, 1895 insertions(+), 1985 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index fd648a4a27..c33011a417 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -303,6 +303,7 @@ static BOOL reload_nmbd_services(BOOL test) * We use buf here to return BOOL result to process() when reload_interfaces() * detects that there are no subnets. **************************************************************************** */ + static void msg_reload_nmbd_services(int msg_type, pid_t src, void *buf, size_t len) { write_browse_list( 0, True ); @@ -650,126 +651,120 @@ static BOOL open_sockets(BOOL isdaemon, int port) log_stdout = True; } - if ( log_stdout && Fork ) { - DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n")); - exit(1); - } + if ( log_stdout && Fork ) { + DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n")); + exit(1); + } - setup_logging( argv[0], log_stdout ); + setup_logging( argv[0], log_stdout ); - reopen_logs(); + reopen_logs(); - DEBUG( 0, ( "Netbios nameserver version %s started.\n", SAMBA_VERSION_STRING) ); - DEBUGADD( 0, ( "Copyright Andrew Tridgell and the Samba Team 1994-2003\n" ) ); + DEBUG( 0, ( "Netbios nameserver version %s started.\n", SAMBA_VERSION_STRING) ); + DEBUGADD( 0, ( "Copyright Andrew Tridgell and the Samba Team 1994-2003\n" ) ); - if ( !reload_nmbd_services(False) ) - return(-1); + if ( !reload_nmbd_services(False) ) + return(-1); - if(!init_names()) - return -1; + if(!init_names()) + return -1; - reload_nmbd_services( True ); + reload_nmbd_services( True ); - if (strequal(lp_workgroup(),"*")) - { - DEBUG(0,("ERROR: a workgroup name of * is no longer supported\n")); - exit(1); - } + if (strequal(lp_workgroup(),"*")) { + DEBUG(0,("ERROR: a workgroup name of * is no longer supported\n")); + exit(1); + } - set_samba_nb_type(); + set_samba_nb_type(); - if (!is_daemon && !is_a_socket(0)) - { - DEBUG(0,("standard input is not a socket, assuming -D option\n")); - is_daemon = True; - } + if (!is_daemon && !is_a_socket(0)) { + DEBUG(0,("standard input is not a socket, assuming -D option\n")); + is_daemon = True; + } - if (is_daemon && !opt_interactive) - { - DEBUG( 2, ( "Becoming a daemon.\n" ) ); - become_daemon(Fork); - } + if (is_daemon && !opt_interactive) { + DEBUG( 2, ( "Becoming a daemon.\n" ) ); + become_daemon(Fork); + } #if HAVE_SETPGID - /* - * If we're interactive we want to set our own process group for - * signal management. - */ - if (opt_interactive) - setpgid( (pid_t)0, (pid_t)0 ); + /* + * If we're interactive we want to set our own process group for + * signal management. + */ + if (opt_interactive) + setpgid( (pid_t)0, (pid_t)0 ); #endif #ifndef SYNC_DNS - /* Setup the async dns. We do it here so it doesn't have all the other - stuff initialised and thus chewing memory and sockets */ - if(lp_we_are_a_wins_server() && lp_dns_proxy()) { - start_async_dns(); - } + /* Setup the async dns. We do it here so it doesn't have all the other + stuff initialised and thus chewing memory and sockets */ + if(lp_we_are_a_wins_server() && lp_dns_proxy()) { + start_async_dns(); + } #endif - if (!directory_exist(lp_lockdir(), NULL)) { - mkdir(lp_lockdir(), 0755); - } - - pidfile_create("nmbd"); - message_init(); - message_register(MSG_FORCE_ELECTION, nmbd_message_election); - message_register(MSG_WINS_NEW_ENTRY, nmbd_wins_new_entry); - message_register(MSG_SHUTDOWN, nmbd_terminate); - message_register(MSG_SMB_CONF_UPDATED, msg_reload_nmbd_services); - - DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); - - if ( !open_sockets( is_daemon, global_nmb_port ) ) { - kill_async_dns_child(); - return 1; - } - - /* Determine all the IP addresses we have. */ - load_interfaces(); - - /* Create an nmbd subnet record for each of the above. */ - if( False == create_subnets() ) - { - DEBUG(0,("ERROR: Failed when creating subnet lists. Exiting.\n")); - kill_async_dns_child(); - exit(1); - } - - /* Load in any static local names. */ - load_lmhosts_file(dyn_LMHOSTSFILE); - DEBUG(3,("Loaded hosts file %s\n", dyn_LMHOSTSFILE)); - - /* If we are acting as a WINS server, initialise data structures. */ - if( !initialise_wins() ) - { - DEBUG( 0, ( "nmbd: Failed when initialising WINS server.\n" ) ); - kill_async_dns_child(); - exit(1); - } - - /* - * Register nmbd primary workgroup and nmbd names on all - * the broadcast subnets, and on the WINS server (if specified). - * Also initiate the startup of our primary workgroup (start - * elections if we are setup as being able to be a local - * master browser. - */ - - if( False == register_my_workgroup_and_names() ) - { - DEBUG(0,("ERROR: Failed when creating my my workgroup. Exiting.\n")); - kill_async_dns_child(); - exit(1); - } - - /* We can only take signals in the select. */ - BlockSignals( True, SIGTERM ); - - process(); - - if (dbf) - x_fclose(dbf); - kill_async_dns_child(); - return(0); + if (!directory_exist(lp_lockdir(), NULL)) { + mkdir(lp_lockdir(), 0755); + } + + pidfile_create("nmbd"); + message_init(); + message_register(MSG_FORCE_ELECTION, nmbd_message_election); + message_register(MSG_WINS_NEW_ENTRY, nmbd_wins_new_entry); + message_register(MSG_SHUTDOWN, nmbd_terminate); + message_register(MSG_SMB_CONF_UPDATED, msg_reload_nmbd_services); + + DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); + + if ( !open_sockets( is_daemon, global_nmb_port ) ) { + kill_async_dns_child(); + return 1; + } + + /* Determine all the IP addresses we have. */ + load_interfaces(); + + /* Create an nmbd subnet record for each of the above. */ + if( False == create_subnets() ) { + DEBUG(0,("ERROR: Failed when creating subnet lists. Exiting.\n")); + kill_async_dns_child(); + exit(1); + } + + /* Load in any static local names. */ + load_lmhosts_file(dyn_LMHOSTSFILE); + DEBUG(3,("Loaded hosts file %s\n", dyn_LMHOSTSFILE)); + + /* If we are acting as a WINS server, initialise data structures. */ + if( !initialise_wins() ) { + DEBUG( 0, ( "nmbd: Failed when initialising WINS server.\n" ) ); + kill_async_dns_child(); + exit(1); + } + + /* + * Register nmbd primary workgroup and nmbd names on all + * the broadcast subnets, and on the WINS server (if specified). + * Also initiate the startup of our primary workgroup (start + * elections if we are setup as being able to be a local + * master browser. + */ + + if( False == register_my_workgroup_and_names() ) { + DEBUG(0,("ERROR: Failed when creating my my workgroup. Exiting.\n")); + kill_async_dns_child(); + exit(1); + } + + /* We can only take signals in the select. */ + BlockSignals( True, SIGTERM ); + + process(); + + if (dbf) + x_fclose(dbf); + kill_async_dns_child(); + return(0); } diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index 2e76e51f45..46d37fbb81 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -3,7 +3,7 @@ NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 - Copyright (C) Jeremy Allison 1994-1998 + Copyright (C) Jeremy Allison 1994-2003 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -37,36 +37,37 @@ static void become_domain_master_fail(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *fail_name) { - struct work_record *work = find_workgroup_on_subnet(subrec, fail_name->name); - struct server_record *servrec; - - if(!work) - { - DEBUG(0,("become_domain_master_fail: Error - cannot find \ -workgroup %s on subnet %s\n", fail_name->name, subrec->subnet_name)); - return; - } - - /* Set the state back to DOMAIN_NONE. */ - work->dom_state = DOMAIN_NONE; - - if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) - { - DEBUG(0,("become_domain_master_fail: Error - cannot find server %s \ + nstring failname; + struct work_record *work; + struct server_record *servrec; + + pull_ascii_nstring(failname, fail_name->name); + work = find_workgroup_on_subnet(subrec, failname); + if(!work) { + DEBUG(0,("become_domain_master_fail: Error - cannot find \ +workgroup %s on subnet %s\n", failname, subrec->subnet_name)); + return; + } + + /* Set the state back to DOMAIN_NONE. */ + work->dom_state = DOMAIN_NONE; + + if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) { + DEBUG(0,("become_domain_master_fail: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - global_myname(), work->work_group, subrec->subnet_name)); - return; - } + global_myname(), work->work_group, subrec->subnet_name)); + return; + } - /* Update our server status. */ - servrec->serv.type &= ~SV_TYPE_DOMAIN_MASTER; + /* Update our server status. */ + servrec->serv.type &= ~SV_TYPE_DOMAIN_MASTER; - /* Tell the namelist writer to write out a change. */ - subrec->work_changed = True; + /* Tell the namelist writer to write out a change. */ + subrec->work_changed = True; - DEBUG(0,("become_domain_master_fail: Failed to become a domain master browser for \ + DEBUG(0,("become_domain_master_fail: Failed to become a domain master browser for \ workgroup %s on subnet %s. Couldn't register name %s.\n", - work->work_group, subrec->subnet_name, nmb_namestr(fail_name))); + work->work_group, subrec->subnet_name, nmb_namestr(fail_name))); } /**************************************************************************** @@ -79,115 +80,112 @@ static void become_domain_master_stage2(struct subnet_record *subrec, uint16 nb_flags, int ttl, struct in_addr registered_ip) { - struct work_record *work = find_workgroup_on_subnet( subrec, registered_name->name); - struct server_record *servrec; - - if(!work) - { - DEBUG(0,("become_domain_master_stage2: Error - cannot find \ -workgroup %s on subnet %s\n", registered_name->name, subrec->subnet_name)); - return; - } - - if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) - { - DEBUG(0,("become_domain_master_stage2: Error - cannot find server %s \ + nstring regname; + struct work_record *work; + struct server_record *servrec; + + pull_ascii_nstring(regname, registered_name->name); + work = find_workgroup_on_subnet( subrec, regname); + + if(!work) { + DEBUG(0,("become_domain_master_stage2: Error - cannot find \ +workgroup %s on subnet %s\n", regname, subrec->subnet_name)); + return; + } + + if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) { + DEBUG(0,("become_domain_master_stage2: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - global_myname(), registered_name->name, subrec->subnet_name)); - work->dom_state = DOMAIN_NONE; - return; - } - - /* Set the state in the workgroup structure. */ - work->dom_state = DOMAIN_MST; /* Become domain master. */ - - /* Update our server status. */ - servrec->serv.type |= (SV_TYPE_NT|SV_TYPE_DOMAIN_MASTER); - - /* Tell the namelist writer to write out a change. */ - subrec->work_changed = True; - - if( DEBUGLVL( 0 ) ) - { - dbgtext( "*****\n\nSamba server %s ", global_myname() ); - dbgtext( "is now a domain master browser for " ); - dbgtext( "workgroup %s ", work->work_group ); - dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name ); - } - - if( subrec == unicast_subnet ) - { - struct nmb_name nmbname; - struct in_addr my_first_ip; - - /* Put our name and first IP address into the - workgroup struct as domain master browser. This - will stop us syncing with ourself if we are also - a local master browser. */ - - make_nmb_name(&nmbname, global_myname(), 0x20); - - work->dmb_name = nmbname; - /* Pick the first interface ip address as the domain master browser ip. */ - my_first_ip = *iface_n_ip(0); - - putip((char *)&work->dmb_addr, &my_first_ip); - - /* We successfully registered by unicast with the - WINS server. We now expect to become the domain - master on the local subnets. If this fails, it's - probably a 1.9.16p2 to 1.9.16p11 server's fault. - - This is a configuration issue that should be addressed - by the network administrator - you shouldn't have - several machines configured as a domain master browser - for the same WINS scope (except if they are 1.9.17 or - greater, and you know what you're doing. - - see docs/DOMAIN.txt. - - */ - become_domain_master_browser_bcast(work->work_group); - } - else - { - /* - * Now we are a domain master on a broadcast subnet, we need to add - * the WORKGROUP<1b> name to the unicast subnet so that we can answer - * unicast requests sent to this name. This bug wasn't found for a while - * as it is strange to have a DMB without using WINS. JRA. - */ - insert_permanent_name_into_unicast(subrec, registered_name, nb_flags); - } + global_myname(), regname, subrec->subnet_name)); + work->dom_state = DOMAIN_NONE; + return; + } + + /* Set the state in the workgroup structure. */ + work->dom_state = DOMAIN_MST; /* Become domain master. */ + + /* Update our server status. */ + servrec->serv.type |= (SV_TYPE_NT|SV_TYPE_DOMAIN_MASTER); + + /* Tell the namelist writer to write out a change. */ + subrec->work_changed = True; + + if( DEBUGLVL( 0 ) ) { + dbgtext( "*****\n\nSamba server %s ", global_myname() ); + dbgtext( "is now a domain master browser for " ); + dbgtext( "workgroup %s ", work->work_group ); + dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name ); + } + + if( subrec == unicast_subnet ) { + struct nmb_name nmbname; + struct in_addr my_first_ip; + + /* Put our name and first IP address into the + workgroup struct as domain master browser. This + will stop us syncing with ourself if we are also + a local master browser. */ + + make_nmb_name(&nmbname, global_myname(), 0x20); + + work->dmb_name = nmbname; + /* Pick the first interface ip address as the domain master browser ip. */ + my_first_ip = *iface_n_ip(0); + + putip((char *)&work->dmb_addr, &my_first_ip); + + /* We successfully registered by unicast with the + WINS server. We now expect to become the domain + master on the local subnets. If this fails, it's + probably a 1.9.16p2 to 1.9.16p11 server's fault. + + This is a configuration issue that should be addressed + by the network administrator - you shouldn't have + several machines configured as a domain master browser + for the same WINS scope (except if they are 1.9.17 or + greater, and you know what you're doing. + + see docs/DOMAIN.txt. + + */ + become_domain_master_browser_bcast(work->work_group); + } else { + /* + * Now we are a domain master on a broadcast subnet, we need to add + * the WORKGROUP<1b> name to the unicast subnet so that we can answer + * unicast requests sent to this name. This bug wasn't found for a while + * as it is strange to have a DMB without using WINS. JRA. + */ + insert_permanent_name_into_unicast(subrec, registered_name, nb_flags); + } } /**************************************************************************** Start the name registration process when becoming a Domain Master Browser on a subnet. - ****************************************************************************/ +****************************************************************************/ -static void become_domain_master_stage1(struct subnet_record *subrec, char *wg_name) +static void become_domain_master_stage1(struct subnet_record *subrec, const char *wg_name) { - struct work_record *work; + struct work_record *work; - DEBUG(2,("become_domain_master_stage1: Becoming domain master browser for \ + DEBUG(2,("become_domain_master_stage1: Becoming domain master browser for \ workgroup %s on subnet %s\n", wg_name, subrec->subnet_name)); - /* First, find the workgroup on the subnet. */ - if((work = find_workgroup_on_subnet( subrec, wg_name )) == NULL) - { - DEBUG(0,("become_domain_master_stage1: Error - unable to find workgroup %s on subnet %s.\n", - wg_name, subrec->subnet_name)); - return; - } - - DEBUG(3,("become_domain_master_stage1: go to first stage: register <1b> name\n")); - work->dom_state = DOMAIN_WAIT; - - /* WORKGROUP<1b> is the domain master browser name. */ - register_name(subrec, work->work_group,0x1b,samba_nb_type, - become_domain_master_stage2, - become_domain_master_fail, NULL); + /* First, find the workgroup on the subnet. */ + if((work = find_workgroup_on_subnet( subrec, wg_name )) == NULL) { + DEBUG(0,("become_domain_master_stage1: Error - unable to find workgroup %s on subnet %s.\n", + wg_name, subrec->subnet_name)); + return; + } + + DEBUG(3,("become_domain_master_stage1: go to first stage: register <1b> name\n")); + work->dom_state = DOMAIN_WAIT; + + /* WORKGROUP<1b> is the domain master browser name. */ + register_name(subrec, work->work_group,0x1b,samba_nb_type, + become_domain_master_stage2, + become_domain_master_fail, NULL); } /**************************************************************************** @@ -202,37 +200,35 @@ static void become_domain_master_query_success(struct subnet_record *subrec, struct nmb_name *nmbname, struct in_addr ip, struct res_rec *rrec) { - /* If the given ip is not ours, then we can't become a domain - controler as the name is already registered. - */ - - /* BUG note. Samba 1.9.16p11 servers seem to return the broadcast - address or zero ip for this query. Pretend this is ok. */ - - if(ismyip(ip) || ip_equal(allones_ip, ip) || is_zero_ip(ip)) - { - if( DEBUGLVL( 3 ) ) - { - dbgtext( "become_domain_master_query_success():\n" ); - dbgtext( "Our address (%s) ", inet_ntoa(ip) ); - dbgtext( "returned in query for name %s ", nmb_namestr(nmbname) ); - dbgtext( "(domain master browser name) " ); - dbgtext( "on subnet %s.\n", subrec->subnet_name ); - dbgtext( "Continuing with domain master code.\n" ); - } - - become_domain_master_stage1(subrec, nmbname->name); - } - else - { - if( DEBUGLVL( 0 ) ) - { - dbgtext( "become_domain_master_query_success:\n" ); - dbgtext( "There is already a domain master browser at " ); - dbgtext( "IP %s for workgroup %s ", inet_ntoa(ip), nmbname->name ); - dbgtext( "registered on subnet %s.\n", subrec->subnet_name ); - } - } + nstring name; + pull_ascii_nstring(name, nmbname->name); + + /* If the given ip is not ours, then we can't become a domain + controler as the name is already registered. + */ + + /* BUG note. Samba 1.9.16p11 servers seem to return the broadcast + address or zero ip for this query. Pretend this is ok. */ + + if(ismyip(ip) || ip_equal(allones_ip, ip) || is_zero_ip(ip)) { + if( DEBUGLVL( 3 ) ) { + dbgtext( "become_domain_master_query_success():\n" ); + dbgtext( "Our address (%s) ", inet_ntoa(ip) ); + dbgtext( "returned in query for name %s ", nmb_namestr(nmbname) ); + dbgtext( "(domain master browser name) " ); + dbgtext( "on subnet %s.\n", subrec->subnet_name ); + dbgtext( "Continuing with domain master code.\n" ); + } + + become_domain_master_stage1(subrec, name); + } else { + if( DEBUGLVL( 0 ) ) { + dbgtext( "become_domain_master_query_success:\n" ); + dbgtext( "There is already a domain master browser at " ); + dbgtext( "IP %s for workgroup %s ", inet_ntoa(ip), name ); + dbgtext( "registered on subnet %s.\n", subrec->subnet_name ); + } + } } /**************************************************************************** @@ -245,18 +241,21 @@ static void become_domain_master_query_fail(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *question_name, int fail_code) { - /* If the query was unicast, and the error is not NAM_ERR (name didn't exist), - then this is a failure. Otherwise, not finding the name is what we want. */ - if((subrec == unicast_subnet) && (fail_code != NAM_ERR)) - { - DEBUG(0,("become_domain_master_query_fail: Error %d returned when \ + nstring name; + + /* If the query was unicast, and the error is not NAM_ERR (name didn't exist), + then this is a failure. Otherwise, not finding the name is what we want. */ + + if((subrec == unicast_subnet) && (fail_code != NAM_ERR)) { + DEBUG(0,("become_domain_master_query_fail: Error %d returned when \ querying WINS server for name %s.\n", - fail_code, nmb_namestr(question_name))); - return; - } + fail_code, nmb_namestr(question_name))); + return; + } - /* Otherwise - not having the name allows us to register it. */ - become_domain_master_stage1(subrec, question_name->name); + /* Otherwise - not having the name allows us to register it. */ + pull_ascii_nstring(name, question_name->name); + become_domain_master_stage1(subrec, name); } /**************************************************************************** @@ -265,47 +264,43 @@ querying WINS server for name %s.\n", static void become_domain_master_browser_bcast(const char *workgroup_name) { - struct subnet_record *subrec; - - for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - { - struct work_record *work = find_workgroup_on_subnet(subrec, workgroup_name); - - if (work && (work->dom_state == DOMAIN_NONE)) - { - struct nmb_name nmbname; - make_nmb_name(&nmbname,workgroup_name,0x1b); - - /* - * Check for our name on the given broadcast subnet first, only initiate - * further processing if we cannot find it. - */ - - if (find_name_on_subnet(subrec, &nmbname, FIND_SELF_NAME) == NULL) - { - if( DEBUGLVL( 0 ) ) - { - dbgtext( "become_domain_master_browser_bcast:\n" ); - dbgtext( "Attempting to become domain master browser on " ); - dbgtext( "workgroup %s on subnet %s\n", - workgroup_name, subrec->subnet_name ); - } - - /* Send out a query to establish whether there's a - domain controller on the local subnet. If not, - we can become a domain controller. - */ - - DEBUG(0,("become_domain_master_browser_bcast: querying subnet %s \ + struct subnet_record *subrec; + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { + struct work_record *work = find_workgroup_on_subnet(subrec, workgroup_name); + + if (work && (work->dom_state == DOMAIN_NONE)) { + struct nmb_name nmbname; + make_nmb_name(&nmbname,workgroup_name,0x1b); + + /* + * Check for our name on the given broadcast subnet first, only initiate + * further processing if we cannot find it. + */ + + if (find_name_on_subnet(subrec, &nmbname, FIND_SELF_NAME) == NULL) { + if( DEBUGLVL( 0 ) ) { + dbgtext( "become_domain_master_browser_bcast:\n" ); + dbgtext( "Attempting to become domain master browser on " ); + dbgtext( "workgroup %s on subnet %s\n", + workgroup_name, subrec->subnet_name ); + } + + /* Send out a query to establish whether there's a + domain controller on the local subnet. If not, + we can become a domain controller. + */ + + DEBUG(0,("become_domain_master_browser_bcast: querying subnet %s \ for domain master browser on workgroup %s\n", subrec->subnet_name, workgroup_name)); - query_name(subrec, nmbname.name, nmbname.name_type, - become_domain_master_query_success, - become_domain_master_query_fail, - NULL); - } - } - } + query_name(subrec, workgroup_name, nmbname.name_type, + become_domain_master_query_success, + become_domain_master_query_fail, + NULL); + } + } + } } /**************************************************************************** @@ -314,46 +309,43 @@ for domain master browser on workgroup %s\n", subrec->subnet_name, workgroup_nam static void become_domain_master_browser_wins(const char *workgroup_name) { - struct work_record *work; + struct work_record *work; - work = find_workgroup_on_subnet(unicast_subnet, workgroup_name); + work = find_workgroup_on_subnet(unicast_subnet, workgroup_name); - if (work && (work->dom_state == DOMAIN_NONE)) - { - struct nmb_name nmbname; + if (work && (work->dom_state == DOMAIN_NONE)) { + struct nmb_name nmbname; - make_nmb_name(&nmbname,workgroup_name,0x1b); + make_nmb_name(&nmbname,workgroup_name,0x1b); - /* - * Check for our name on the unicast subnet first, only initiate - * further processing if we cannot find it. - */ + /* + * Check for our name on the unicast subnet first, only initiate + * further processing if we cannot find it. + */ - if (find_name_on_subnet(unicast_subnet, &nmbname, FIND_SELF_NAME) == NULL) - { - if( DEBUGLVL( 0 ) ) - { - dbgtext( "become_domain_master_browser_wins:\n" ); - dbgtext( "Attempting to become domain master browser " ); - dbgtext( "on workgroup %s, subnet %s.\n", - workgroup_name, unicast_subnet->subnet_name ); - } + if (find_name_on_subnet(unicast_subnet, &nmbname, FIND_SELF_NAME) == NULL) { + if( DEBUGLVL( 0 ) ) { + dbgtext( "become_domain_master_browser_wins:\n" ); + dbgtext( "Attempting to become domain master browser " ); + dbgtext( "on workgroup %s, subnet %s.\n", + workgroup_name, unicast_subnet->subnet_name ); + } - /* Send out a query to establish whether there's a - domain master broswer registered with WINS. If not, - we can become a domain master browser. - */ + /* Send out a query to establish whether there's a + domain master broswer registered with WINS. If not, + we can become a domain master browser. + */ - DEBUG(0,("become_domain_master_browser_wins: querying WINS server from IP %s \ + DEBUG(0,("become_domain_master_browser_wins: querying WINS server from IP %s \ for domain master browser name %s on workgroup %s\n", - inet_ntoa(unicast_subnet->myip), nmb_namestr(&nmbname), workgroup_name)); - - query_name(unicast_subnet, nmbname.name, nmbname.name_type, - become_domain_master_query_success, - become_domain_master_query_fail, - NULL); - } - } + inet_ntoa(unicast_subnet->myip), nmb_namestr(&nmbname), workgroup_name)); + + query_name(unicast_subnet, workgroup_name, nmbname.name_type, + become_domain_master_query_success, + become_domain_master_query_fail, + NULL); + } + } } /**************************************************************************** @@ -363,34 +355,32 @@ for domain master browser name %s on workgroup %s\n", void add_domain_names(time_t t) { - static time_t lastrun = 0; - - if ((lastrun != 0) && (t < lastrun + (CHECK_TIME_ADD_DOM_NAMES * 60))) - return; - - lastrun = t; - - /* Do the "internet group" - <1c> names. */ - if (lp_domain_logons()) - add_logon_names(); - - /* Do the domain master names. */ - if(lp_domain_master()) - { - if(we_are_a_wins_client()) - { - /* We register the WORKGROUP<1b> name with the WINS - server first, and call add_domain_master_bcast() - only if this is successful. - - This results in domain logon services being gracefully provided, - as opposed to the aggressive nature of 1.9.16p2 to 1.9.16p11. - 1.9.16p2 to 1.9.16p11 - due to a bug in namelogon.c, - cannot provide domain master / domain logon services. - */ - become_domain_master_browser_wins(lp_workgroup()); - } - else - become_domain_master_browser_bcast(lp_workgroup()); - } + static time_t lastrun = 0; + + if ((lastrun != 0) && (t < lastrun + (CHECK_TIME_ADD_DOM_NAMES * 60))) + return; + + lastrun = t; + + /* Do the "internet group" - <1c> names. */ + if (lp_domain_logons()) + add_logon_names(); + + /* Do the domain master names. */ + if(lp_domain_master()) { + if(we_are_a_wins_client()) { + /* We register the WORKGROUP<1b> name with the WINS + server first, and call add_domain_master_bcast() + only if this is successful. + + This results in domain logon services being gracefully provided, + as opposed to the aggressive nature of 1.9.16p2 to 1.9.16p11. + 1.9.16p2 to 1.9.16p11 - due to a bug in namelogon.c, + cannot provide domain master / domain logon services. + */ + become_domain_master_browser_wins(lp_workgroup()); + } else { + become_domain_master_browser_bcast(lp_workgroup()); + } + } } diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index d390bf72e9..a6ae1ce42e 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -3,7 +3,7 @@ NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 - Copyright (C) Jeremy Allison 1994-1998 + Copyright (C) Jeremy Allison 1994-2003 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -33,21 +33,20 @@ extern uint16 samba_nb_type; /* Samba's NetBIOS name type. */ void insert_permanent_name_into_unicast( struct subnet_record *subrec, struct nmb_name *nmbname, uint16 nb_type ) { - struct name_record *namerec; - - if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) == NULL) - { - /* The name needs to be created on the unicast subnet. */ - (void)add_name_to_subnet( unicast_subnet, nmbname->name, - nmbname->name_type, nb_type, - PERMANENT_TTL, PERMANENT_NAME, 1, &subrec->myip); - } - else - { - /* The name already exists on the unicast subnet. Add our local - IP for the given broadcast subnet to the name. */ - add_ip_to_name_record( namerec, subrec->myip); - } + nstring name; + struct name_record *namerec; + + if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) == NULL) { + pull_ascii_nstring(name, nmbname->name); + /* The name needs to be created on the unicast subnet. */ + (void)add_name_to_subnet( unicast_subnet, name, + nmbname->name_type, nb_type, + PERMANENT_TTL, PERMANENT_NAME, 1, &subrec->myip); + } else { + /* The name already exists on the unicast subnet. Add our local + IP for the given broadcast subnet to the name. */ + add_ip_to_name_record( namerec, subrec->myip); + } } /******************************************************************* @@ -57,15 +56,14 @@ void insert_permanent_name_into_unicast( struct subnet_record *subrec, static void remove_permanent_name_from_unicast( struct subnet_record *subrec, struct nmb_name *nmbname ) { - struct name_record *namerec; - - if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) != NULL) - { - /* Remove this broadcast subnet IP address from the name. */ - remove_ip_from_name_record( namerec, subrec->myip); - if(namerec->data.num_ips == 0) - remove_name_from_namelist( unicast_subnet, namerec); - } + struct name_record *namerec; + + if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) != NULL) { + /* Remove this broadcast subnet IP address from the name. */ + remove_ip_from_name_record( namerec, subrec->myip); + if(namerec->data.num_ips == 0) + remove_name_from_namelist( unicast_subnet, namerec); + } } /******************************************************************* @@ -73,60 +71,58 @@ static void remove_permanent_name_from_unicast( struct subnet_record *subrec, state back to potential browser, or none. ******************************************************************/ -static void reset_workgroup_state( struct subnet_record *subrec, char *workgroup_name, +static void reset_workgroup_state( struct subnet_record *subrec, const char *workgroup_name, BOOL force_new_election ) { - struct work_record *work; - struct server_record *servrec; - struct nmb_name nmbname; + struct work_record *work; + struct server_record *servrec; + struct nmb_name nmbname; - if((work = find_workgroup_on_subnet( subrec, workgroup_name)) == NULL) - { - DEBUG(0,("reset_workgroup_state: Error - cannot find workgroup %s on \ + if((work = find_workgroup_on_subnet( subrec, workgroup_name)) == NULL) { + DEBUG(0,("reset_workgroup_state: Error - cannot find workgroup %s on \ subnet %s.\n", workgroup_name, subrec->subnet_name )); - return; - } + return; + } - if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) - { - DEBUG(0,("reset_workgroup_state: Error - cannot find server %s \ + if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) { + DEBUG(0,("reset_workgroup_state: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - global_myname(), work->work_group, subrec->subnet_name)); - work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; - return; - } + global_myname(), work->work_group, subrec->subnet_name)); + work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; + return; + } - /* Update our server status - remove any master flag and replace - it with the potential browser flag. */ - servrec->serv.type &= ~SV_TYPE_MASTER_BROWSER; - servrec->serv.type |= (lp_local_master() ? SV_TYPE_POTENTIAL_BROWSER : 0); + /* Update our server status - remove any master flag and replace + it with the potential browser flag. */ + servrec->serv.type &= ~SV_TYPE_MASTER_BROWSER; + servrec->serv.type |= (lp_local_master() ? SV_TYPE_POTENTIAL_BROWSER : 0); - /* Tell the namelist writer to write out a change. */ - subrec->work_changed = True; + /* Tell the namelist writer to write out a change. */ + subrec->work_changed = True; - /* Reset our election flags. */ - work->ElectionCriterion &= ~0x4; + /* Reset our election flags. */ + work->ElectionCriterion &= ~0x4; - work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; + work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; - /* Forget who the local master browser was for - this workgroup. */ + /* Forget who the local master browser was for + this workgroup. */ - set_workgroup_local_master_browser_name( work, ""); + set_workgroup_local_master_browser_name( work, ""); - /* - * Ensure the IP address of this subnet is not registered as one - * of the IP addresses of the WORKGROUP<1d> name on the unicast - * subnet. This undoes what we did below when we became a local - * master browser. - */ + /* + * Ensure the IP address of this subnet is not registered as one + * of the IP addresses of the WORKGROUP<1d> name on the unicast + * subnet. This undoes what we did below when we became a local + * master browser. + */ - make_nmb_name(&nmbname, work->work_group, 0x1d); + make_nmb_name(&nmbname, work->work_group, 0x1d); - remove_permanent_name_from_unicast( subrec, &nmbname); + remove_permanent_name_from_unicast( subrec, &nmbname); - if(force_new_election) - work->needelection = True; + if(force_new_election) + work->needelection = True; } /******************************************************************* @@ -138,24 +134,25 @@ static void unbecome_local_master_success(struct subnet_record *subrec, struct nmb_name *released_name, struct in_addr released_ip) { - BOOL force_new_election = False; + BOOL force_new_election = False; + nstring relname; - memcpy((char *)&force_new_election, userdata->data, sizeof(BOOL)); + memcpy((char *)&force_new_election, userdata->data, sizeof(BOOL)); - DEBUG(3,("unbecome_local_master_success: released name %s.\n", - nmb_namestr(released_name))); + DEBUG(3,("unbecome_local_master_success: released name %s.\n", + nmb_namestr(released_name))); - /* Now reset the workgroup and server state. */ - reset_workgroup_state( subrec, released_name->name, force_new_election ); + /* Now reset the workgroup and server state. */ + pull_ascii_nstring(relname, released_name->name); + reset_workgroup_state( subrec, relname, force_new_election ); - if( DEBUGLVL( 0 ) ) - { - dbgtext( "*****\n\n" ); - dbgtext( "Samba name server %s ", global_myname() ); - dbgtext( "has stopped being a local master browser " ); - dbgtext( "for workgroup %s ", released_name->name ); - dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name ); - } + if( DEBUGLVL( 0 ) ) { + dbgtext( "*****\n\n" ); + dbgtext( "Samba name server %s ", global_myname() ); + dbgtext( "has stopped being a local master browser " ); + dbgtext( "for workgroup %s ", relname ); + dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name ); + } } @@ -166,67 +163,66 @@ static void unbecome_local_master_success(struct subnet_record *subrec, static void unbecome_local_master_fail(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *fail_name) { - struct name_record *namerec; - struct userdata_struct *userdata = rrec->userdata; - BOOL force_new_election = False; + struct name_record *namerec; + struct userdata_struct *userdata = rrec->userdata; + BOOL force_new_election = False; + nstring failname; - memcpy((char *)&force_new_election, userdata->data, sizeof(BOOL)); + memcpy((char *)&force_new_election, userdata->data, sizeof(BOOL)); - DEBUG(0,("unbecome_local_master_fail: failed to release name %s. \ + DEBUG(0,("unbecome_local_master_fail: failed to release name %s. \ Removing from namelist anyway.\n", nmb_namestr(fail_name))); - /* Do it anyway. */ - namerec = find_name_on_subnet(subrec, fail_name, FIND_SELF_NAME); - if(namerec) - remove_name_from_namelist(subrec, namerec); - - /* Now reset the workgroup and server state. */ - reset_workgroup_state( subrec, fail_name->name, force_new_election ); - - if( DEBUGLVL( 0 ) ) - { - dbgtext( "*****\n\n" ); - dbgtext( "Samba name server %s ", global_myname() ); - dbgtext( "has stopped being a local master browser " ); - dbgtext( "for workgroup %s ", fail_name->name ); - dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name ); - } + /* Do it anyway. */ + namerec = find_name_on_subnet(subrec, fail_name, FIND_SELF_NAME); + if(namerec) + remove_name_from_namelist(subrec, namerec); + + /* Now reset the workgroup and server state. */ + pull_ascii_nstring(failname, fail_name->name); + reset_workgroup_state( subrec, failname, force_new_election ); + + if( DEBUGLVL( 0 ) ) { + dbgtext( "*****\n\n" ); + dbgtext( "Samba name server %s ", global_myname() ); + dbgtext( "has stopped being a local master browser " ); + dbgtext( "for workgroup %s ", failname ); + dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name ); + } } /******************************************************************* Utility function to remove the WORKGROUP<1d> name. ******************************************************************/ -static void release_1d_name( struct subnet_record *subrec, char *workgroup_name, +static void release_1d_name( struct subnet_record *subrec, const char *workgroup_name, BOOL force_new_election) { - struct nmb_name nmbname; - struct name_record *namerec; - - make_nmb_name(&nmbname, workgroup_name, 0x1d); - if((namerec = find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME))!=NULL) - { - struct userdata_struct *userdata; - size_t size = sizeof(struct userdata_struct) + sizeof(BOOL); - - if((userdata = (struct userdata_struct *)malloc(size)) == NULL) - { - DEBUG(0,("release_1d_name: malloc fail.\n")); - return; - } - - userdata->copy_fn = NULL; - userdata->free_fn = NULL; - userdata->userdata_len = sizeof(BOOL); - memcpy((char *)userdata->data, &force_new_election, sizeof(BOOL)); - - release_name(subrec, namerec, - unbecome_local_master_success, - unbecome_local_master_fail, - userdata); - - zero_free(userdata, size); - } + struct nmb_name nmbname; + struct name_record *namerec; + + make_nmb_name(&nmbname, workgroup_name, 0x1d); + if((namerec = find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME))!=NULL) { + struct userdata_struct *userdata; + size_t size = sizeof(struct userdata_struct) + sizeof(BOOL); + + if((userdata = (struct userdata_struct *)malloc(size)) == NULL) { + DEBUG(0,("release_1d_name: malloc fail.\n")); + return; + } + + userdata->copy_fn = NULL; + userdata->free_fn = NULL; + userdata->userdata_len = sizeof(BOOL); + memcpy((char *)userdata->data, &force_new_election, sizeof(BOOL)); + + release_name(subrec, namerec, + unbecome_local_master_success, + unbecome_local_master_fail, + userdata); + + zero_free(userdata, size); + } } /******************************************************************* @@ -238,11 +234,11 @@ static void release_msbrowse_name_success(struct subnet_record *subrec, struct nmb_name *released_name, struct in_addr released_ip) { - DEBUG(4,("release_msbrowse_name_success: Released name %s on subnet %s\n.", - nmb_namestr(released_name), subrec->subnet_name )); + DEBUG(4,("release_msbrowse_name_success: Released name %s on subnet %s\n.", + nmb_namestr(released_name), subrec->subnet_name )); - /* Remove the permanent MSBROWSE name added into the unicast subnet. */ - remove_permanent_name_from_unicast( subrec, released_name); + /* Remove the permanent MSBROWSE name added into the unicast subnet. */ + remove_permanent_name_from_unicast( subrec, released_name); } /******************************************************************* @@ -253,18 +249,18 @@ static void release_msbrowse_name_fail( struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *fail_name) { - struct name_record *namerec; + struct name_record *namerec; - DEBUG(4,("release_msbrowse_name_fail: Failed to release name %s on subnet %s\n.", - nmb_namestr(fail_name), subrec->subnet_name )); + DEBUG(4,("release_msbrowse_name_fail: Failed to release name %s on subnet %s\n.", + nmb_namestr(fail_name), subrec->subnet_name )); - /* Release the name anyway. */ - namerec = find_name_on_subnet(subrec, fail_name, FIND_SELF_NAME); - if(namerec) - remove_name_from_namelist(subrec, namerec); + /* Release the name anyway. */ + namerec = find_name_on_subnet(subrec, fail_name, FIND_SELF_NAME); + if(namerec) + remove_name_from_namelist(subrec, namerec); - /* Remove the permanent MSBROWSE name added into the unicast subnet. */ - remove_permanent_name_from_unicast( subrec, fail_name); + /* Remove the permanent MSBROWSE name added into the unicast subnet. */ + remove_permanent_name_from_unicast( subrec, fail_name); } /******************************************************************* @@ -275,50 +271,48 @@ static void release_msbrowse_name_fail( struct subnet_record *subrec, void unbecome_local_master_browser(struct subnet_record *subrec, struct work_record *work, BOOL force_new_election) { - struct name_record *namerec; - struct nmb_name nmbname; + struct name_record *namerec; + struct nmb_name nmbname; /* Sanity check. */ - DEBUG(2,("unbecome_local_master_browser: unbecoming local master for workgroup %s \ + DEBUG(2,("unbecome_local_master_browser: unbecoming local master for workgroup %s \ on subnet %s\n",work->work_group, subrec->subnet_name)); - if(find_server_in_workgroup( work, global_myname()) == NULL) - { - DEBUG(0,("unbecome_local_master_browser: Error - cannot find server %s \ + if(find_server_in_workgroup( work, global_myname()) == NULL) { + DEBUG(0,("unbecome_local_master_browser: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - global_myname(), work->work_group, subrec->subnet_name)); - work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; - return; - } + global_myname(), work->work_group, subrec->subnet_name)); + work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; + return; + } - /* Set the state to unbecoming. */ - work->mst_state = MST_UNBECOMING_MASTER; - - /* - * Release the WORKGROUP<1d> name asap to allow another machine to - * claim it. - */ - - release_1d_name( subrec, work->work_group, force_new_election); - - /* Deregister any browser names we may have. */ - make_nmb_name(&nmbname, MSBROWSE, 0x1); - if((namerec = find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME))!=NULL) - { - release_name(subrec, namerec, - release_msbrowse_name_success, - release_msbrowse_name_fail, - NULL); - } - - /* - * Ensure we have sent and processed these release packets - * before returning - we don't want to process any election - * packets before dealing with the 1d release. - */ - - retransmit_or_expire_response_records(time(NULL)); + /* Set the state to unbecoming. */ + work->mst_state = MST_UNBECOMING_MASTER; + + /* + * Release the WORKGROUP<1d> name asap to allow another machine to + * claim it. + */ + + release_1d_name( subrec, work->work_group, force_new_election); + + /* Deregister any browser names we may have. */ + make_nmb_name(&nmbname, MSBROWSE, 0x1); + if((namerec = find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME))!=NULL) { + release_name(subrec, namerec, + release_msbrowse_name_success, + release_msbrowse_name_fail, + NULL); + } + + /* + * Ensure we have sent and processed these release packets + * before returning - we don't want to process any election + * packets before dealing with the 1d release. + */ + + retransmit_or_expire_response_records(time(NULL)); } /**************************************************************************** @@ -332,104 +326,107 @@ static void become_local_master_stage2(struct subnet_record *subrec, uint16 nb_flags, int ttl, struct in_addr registered_ip) { - int i = 0; - struct server_record *sl; - struct work_record *work = find_workgroup_on_subnet( subrec, registered_name->name); - struct server_record *servrec; - - if(!work) - { - DEBUG(0,("become_local_master_stage2: Error - cannot find \ -workgroup %s on subnet %s\n", registered_name->name, subrec->subnet_name)); - return; - } - - if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) - { - DEBUG(0,("become_local_master_stage2: Error - cannot find server %s \ + int i = 0; + struct server_record *sl; + struct work_record *work; + struct server_record *servrec; + nstring regname; + + pull_ascii_nstring(regname, registered_name->name); + work = find_workgroup_on_subnet( subrec, regname); + + if(!work) { + DEBUG(0,("become_local_master_stage2: Error - cannot find \ +workgroup %s on subnet %s\n", regname, subrec->subnet_name)); + return; + } + + if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) { + DEBUG(0,("become_local_master_stage2: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - global_myname(), registered_name->name, subrec->subnet_name)); - work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; - return; - } + global_myname(), regname, subrec->subnet_name)); + work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; + return; + } - DEBUG(3,("become_local_master_stage2: registered as master browser for workgroup %s \ + DEBUG(3,("become_local_master_stage2: registered as master browser for workgroup %s \ on subnet %s\n", work->work_group, subrec->subnet_name)); - work->mst_state = MST_BROWSER; /* registering WORKGROUP(1d) succeeded */ - - /* update our server status */ - servrec->serv.type |= SV_TYPE_MASTER_BROWSER; - servrec->serv.type &= ~SV_TYPE_POTENTIAL_BROWSER; - - /* Tell the namelist writer to write out a change. */ - subrec->work_changed = True; - - /* Add this name to the workgroup as local master browser. */ - set_workgroup_local_master_browser_name( work, global_myname()); - - /* Count the number of servers we have on our list. If it's - less than 10 (just a heuristic) request the servers - to announce themselves. - */ - for( sl = work->serverlist; sl != NULL; sl = sl->next) - i++; - - if (i < 10) - { - /* Ask all servers on our local net to announce to us. */ - broadcast_announce_request(subrec, work); - } - - /* - * Now we are a local master on a broadcast subnet, we need to add - * the WORKGROUP<1d> name to the unicast subnet so that we can answer - * unicast requests sent to this name. We can create this name directly on - * the unicast subnet as a WINS server always returns true when registering - * this name, and discards the registration. We use the number of IP - * addresses registered to this name as a reference count, as we - * remove this broadcast subnet IP address from it when we stop becoming a local - * master browser for this broadcast subnet. - */ - - insert_permanent_name_into_unicast( subrec, registered_name, nb_flags); - - /* Reset the announce master browser timer so that we try and tell a domain - master browser as soon as possible that we are a local master browser. */ - reset_announce_timer(); - - if( DEBUGLVL( 0 ) ) - { - dbgtext( "*****\n\n" ); - dbgtext( "Samba name server %s ", global_myname() ); - dbgtext( "is now a local master browser " ); - dbgtext( "for workgroup %s ", work->work_group ); - dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name ); - } - + work->mst_state = MST_BROWSER; /* registering WORKGROUP(1d) succeeded */ + + /* update our server status */ + servrec->serv.type |= SV_TYPE_MASTER_BROWSER; + servrec->serv.type &= ~SV_TYPE_POTENTIAL_BROWSER; + + /* Tell the namelist writer to write out a change. */ + subrec->work_changed = True; + + /* Add this name to the workgroup as local master browser. */ + set_workgroup_local_master_browser_name( work, global_myname()); + + /* Count the number of servers we have on our list. If it's + less than 10 (just a heuristic) request the servers + to announce themselves. + */ + for( sl = work->serverlist; sl != NULL; sl = sl->next) + i++; + + if (i < 10) { + /* Ask all servers on our local net to announce to us. */ + broadcast_announce_request(subrec, work); + } + + /* + * Now we are a local master on a broadcast subnet, we need to add + * the WORKGROUP<1d> name to the unicast subnet so that we can answer + * unicast requests sent to this name. We can create this name directly on + * the unicast subnet as a WINS server always returns true when registering + * this name, and discards the registration. We use the number of IP + * addresses registered to this name as a reference count, as we + * remove this broadcast subnet IP address from it when we stop becoming a local + * master browser for this broadcast subnet. + */ + + insert_permanent_name_into_unicast( subrec, registered_name, nb_flags); + + /* Reset the announce master browser timer so that we try and tell a domain + master browser as soon as possible that we are a local master browser. */ + reset_announce_timer(); + + if( DEBUGLVL( 0 ) ) { + dbgtext( "*****\n\n" ); + dbgtext( "Samba name server %s ", global_myname() ); + dbgtext( "is now a local master browser " ); + dbgtext( "for workgroup %s ", work->work_group ); + dbgtext( "on subnet %s\n\n*****\n", subrec->subnet_name ); + } } /**************************************************************************** Failed to register the WORKGROUP<1d> name. ****************************************************************************/ + static void become_local_master_fail2(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *fail_name) { - struct work_record *work = find_workgroup_on_subnet( subrec, fail_name->name); + nstring failname; + struct work_record *work; - DEBUG(0,("become_local_master_fail2: failed to register name %s on subnet %s. \ + DEBUG(0,("become_local_master_fail2: failed to register name %s on subnet %s. \ Failed to become a local master browser.\n", nmb_namestr(fail_name), subrec->subnet_name)); - if(!work) - { - DEBUG(0,("become_local_master_fail2: Error - cannot find \ -workgroup %s on subnet %s\n", fail_name->name, subrec->subnet_name)); - return; - } + pull_ascii_nstring(failname, fail_name->name); + work = find_workgroup_on_subnet( subrec, failname); - /* Roll back all the way by calling unbecome_local_master_browser(). */ - unbecome_local_master_browser(subrec, work, False); + if(!work) { + DEBUG(0,("become_local_master_fail2: Error - cannot find \ +workgroup %s on subnet %s\n", failname, subrec->subnet_name)); + return; + } + + /* Roll back all the way by calling unbecome_local_master_browser(). */ + unbecome_local_master_browser(subrec, work, False); } /**************************************************************************** @@ -442,35 +439,34 @@ static void become_local_master_stage1(struct subnet_record *subrec, uint16 nb_flags, int ttl, struct in_addr registered_ip) { - char *work_name = userdata->data; - struct work_record *work = find_workgroup_on_subnet( subrec, work_name); - - if(!work) - { - DEBUG(0,("become_local_master_stage1: Error - cannot find \ -workgroup %s on subnet %s\n", work_name, subrec->subnet_name)); - return; - } - - DEBUG(3,("become_local_master_stage1: go to stage 2: register the %s<1d> name.\n", - work->work_group)); - - work->mst_state = MST_MSB; /* Registering MSBROWSE was successful. */ - - /* - * We registered the MSBROWSE name on a broadcast subnet, now need to add - * the MSBROWSE name to the unicast subnet so that we can answer - * unicast requests sent to this name. We create this name directly on - * the unicast subnet. - */ - - insert_permanent_name_into_unicast( subrec, registered_name, nb_flags); - - /* Attempt to register the WORKGROUP<1d> name. */ - register_name(subrec, work->work_group,0x1d,samba_nb_type, - become_local_master_stage2, - become_local_master_fail2, - NULL); + char *work_name = userdata->data; + struct work_record *work = find_workgroup_on_subnet( subrec, work_name); + + if(!work) { + DEBUG(0,("become_local_master_stage1: Error - cannot find \ + %s on subnet %s\n", work_name, subrec->subnet_name)); + return; + } + + DEBUG(3,("become_local_master_stage1: go to stage 2: register the %s<1d> name.\n", + work->work_group)); + + work->mst_state = MST_MSB; /* Registering MSBROWSE was successful. */ + + /* + * We registered the MSBROWSE name on a broadcast subnet, now need to add + * the MSBROWSE name to the unicast subnet so that we can answer + * unicast requests sent to this name. We create this name directly on + * the unicast subnet. + */ + + insert_permanent_name_into_unicast( subrec, registered_name, nb_flags); + + /* Attempt to register the WORKGROUP<1d> name. */ + register_name(subrec, work->work_group,0x1d,samba_nb_type, + become_local_master_stage2, + become_local_master_fail2, + NULL); } /**************************************************************************** @@ -481,29 +477,27 @@ static void become_local_master_fail1(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *fail_name) { - char *work_name = rrec->userdata->data; - struct work_record *work = find_workgroup_on_subnet(subrec, work_name); + char *work_name = rrec->userdata->data; + struct work_record *work = find_workgroup_on_subnet(subrec, work_name); - if(!work) - { - DEBUG(0,("become_local_master_fail1: Error - cannot find \ + if(!work) { + DEBUG(0,("become_local_master_fail1: Error - cannot find \ workgroup %s on subnet %s\n", work_name, subrec->subnet_name)); - return; - } + return; + } - if(find_server_in_workgroup(work, global_myname()) == NULL) - { - DEBUG(0,("become_local_master_fail1: Error - cannot find server %s \ + if(find_server_in_workgroup(work, global_myname()) == NULL) { + DEBUG(0,("become_local_master_fail1: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - global_myname(), work->work_group, subrec->subnet_name)); - return; - } + global_myname(), work->work_group, subrec->subnet_name)); + return; + } - reset_workgroup_state( subrec, work->work_group, False ); + reset_workgroup_state( subrec, work->work_group, False ); - DEBUG(0,("become_local_master_fail1: Failed to become a local master browser for \ + DEBUG(0,("become_local_master_fail1: Failed to become a local master browser for \ workgroup %s on subnet %s. Couldn't register name %s.\n", - work->work_group, subrec->subnet_name, nmb_namestr(fail_name))); + work->work_group, subrec->subnet_name, nmb_namestr(fail_name))); } /****************************************************************** @@ -517,61 +511,57 @@ workgroup %s on subnet %s. Couldn't register name %s.\n", void become_local_master_browser(struct subnet_record *subrec, struct work_record *work) { - struct userdata_struct *userdata; - size_t size = sizeof(struct userdata_struct) + sizeof(fstring) + 1; - - /* Sanity check. */ - if (!lp_local_master()) - { - DEBUG(0,("become_local_master_browser: Samba not configured as a local master browser.\n")); - return; - } - - if(!AM_POTENTIAL_MASTER_BROWSER(work)) - { - DEBUG(2,("become_local_master_browser: Awaiting potential browser state. Current state is %d\n", - work->mst_state )); - return; - } - - if(find_server_in_workgroup( work, global_myname()) == NULL) - { - DEBUG(0,("become_local_master_browser: Error - cannot find server %s \ + struct userdata_struct *userdata; + size_t size = sizeof(struct userdata_struct) + sizeof(fstring) + 1; + + /* Sanity check. */ + if (!lp_local_master()) { + DEBUG(0,("become_local_master_browser: Samba not configured as a local master browser.\n")); + return; + } + + if(!AM_POTENTIAL_MASTER_BROWSER(work)) { + DEBUG(2,("become_local_master_browser: Awaiting potential browser state. Current state is %d\n", + work->mst_state )); + return; + } + + if(find_server_in_workgroup( work, global_myname()) == NULL) { + DEBUG(0,("become_local_master_browser: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - global_myname(), work->work_group, subrec->subnet_name)); - return; - } + global_myname(), work->work_group, subrec->subnet_name)); + return; + } - DEBUG(2,("become_local_master_browser: Starting to become a master browser for workgroup \ + DEBUG(2,("become_local_master_browser: Starting to become a master browser for workgroup \ %s on subnet %s\n", work->work_group, subrec->subnet_name)); - DEBUG(3,("become_local_master_browser: first stage - attempt to register ^1^2__MSBROWSE__^2^1\n")); - work->mst_state = MST_BACKUP; /* an election win was successful */ + DEBUG(3,("become_local_master_browser: first stage - attempt to register ^1^2__MSBROWSE__^2^1\n")); + work->mst_state = MST_BACKUP; /* an election win was successful */ - work->ElectionCriterion |= 0x5; + work->ElectionCriterion |= 0x5; - /* Tell the namelist writer to write out a change. */ - subrec->work_changed = True; + /* Tell the namelist writer to write out a change. */ + subrec->work_changed = True; - /* Setup the userdata_struct. */ - if((userdata = (struct userdata_struct *)malloc(size)) == NULL) - { - DEBUG(0,("become_local_master_browser: malloc fail.\n")); - return; - } + /* Setup the userdata_struct. */ + if((userdata = (struct userdata_struct *)malloc(size)) == NULL) { + DEBUG(0,("become_local_master_browser: malloc fail.\n")); + return; + } - userdata->copy_fn = NULL; - userdata->free_fn = NULL; - userdata->userdata_len = strlen(work->work_group)+1; - overmalloc_safe_strcpy(userdata->data, work->work_group, size - sizeof(*userdata) - 1); + userdata->copy_fn = NULL; + userdata->free_fn = NULL; + userdata->userdata_len = strlen(work->work_group)+1; + overmalloc_safe_strcpy(userdata->data, work->work_group, size - sizeof(*userdata) - 1); - /* Register the special browser group name. */ - register_name(subrec, MSBROWSE, 0x01, samba_nb_type|NB_GROUP, - become_local_master_stage1, - become_local_master_fail1, - userdata); + /* Register the special browser group name. */ + register_name(subrec, MSBROWSE, 0x01, samba_nb_type|NB_GROUP, + become_local_master_stage1, + become_local_master_fail1, + userdata); - zero_free(userdata, size); + zero_free(userdata, size); } /*************************************************************** @@ -583,7 +573,7 @@ in workgroup %s on subnet %s\n", void set_workgroup_local_master_browser_name( struct work_record *work, const char *newname) { - DEBUG(5,("set_workgroup_local_master_browser_name: setting local master name to '%s' \ + DEBUG(5,("set_workgroup_local_master_browser_name: setting local master name to '%s' \ for workgroup %s.\n", newname, work->work_group )); #if 0 @@ -600,5 +590,5 @@ local_master_browser_name for workgroup %s to workgroup name.\n", } #endif - fstrcpy(work->local_master_browser_name, newname); + fstrcpy(work->local_master_browser_name, newname); } diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c index 4a302ddfd4..83dfba66e9 100644 --- a/source3/nmbd/nmbd_browserdb.c +++ b/source3/nmbd/nmbd_browserdb.c @@ -80,8 +80,8 @@ void update_browser_death_time( struct browse_cache_record *browc ) * * ************************************************************************** ** */ -struct browse_cache_record *create_browser_in_lmb_cache( char *work_name, - char *browser_name, +struct browse_cache_record *create_browser_in_lmb_cache( const char *work_name, + const char *browser_name, struct in_addr ip ) { struct browse_cache_record *browc; @@ -134,7 +134,7 @@ struct browse_cache_record *create_browser_in_lmb_cache( char *work_name, * * ************************************************************************** ** */ -struct browse_cache_record *find_browser_in_lmb_cache( char *browser_name ) +struct browse_cache_record *find_browser_in_lmb_cache( const char *browser_name ) { struct browse_cache_record *browc; diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 26d4735744..95e542354f 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -3,7 +3,7 @@ NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 - Copyright (C) Jeremy Allison 1994-1998 + Copyright (C) Jeremy Allison 1994-2003 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,74 +29,70 @@ extern ubi_dlList lmb_browserlist[]; /**************************************************************************** As a domain master browser, do a sync with a local master browser. **************************************************************************/ + static void sync_with_lmb(struct browse_cache_record *browc) { - struct work_record *work; - - if( !(work = find_workgroup_on_subnet(unicast_subnet, browc->work_group)) ) - { - if( DEBUGLVL( 0 ) ) - { - dbgtext( "sync_with_lmb:\n" ); - dbgtext( "Failed to get a workgroup for a local master browser " ); - dbgtext( "cache entry workgroup " ); - dbgtext( "%s, server %s\n", browc->work_group, browc->lmb_name ); - } - return; - } + struct work_record *work; - /* We should only be doing this if we are a domain master browser for - the given workgroup. Ensure this is so. */ - - if(!AM_DOMAIN_MASTER_BROWSER(work)) - { - if( DEBUGLVL( 0 ) ) - { - dbgtext( "sync_with_lmb:\n" ); - dbgtext( "We are trying to sync with a local master browser " ); - dbgtext( "%s for workgroup %s\n", browc->lmb_name, browc->work_group ); - dbgtext( "and we are not a domain master browser on this workgroup.\n" ); - dbgtext( "Error!\n" ); - } - return; - } + if( !(work = find_workgroup_on_subnet(unicast_subnet, browc->work_group)) ) { + if( DEBUGLVL( 0 ) ) { + dbgtext( "sync_with_lmb:\n" ); + dbgtext( "Failed to get a workgroup for a local master browser " ); + dbgtext( "cache entry workgroup " ); + dbgtext( "%s, server %s\n", browc->work_group, browc->lmb_name ); + } + return; + } - if( DEBUGLVL( 2 ) ) - { - dbgtext( "sync_with_lmb:\n" ); - dbgtext( "Initiating sync with local master browser " ); - dbgtext( "%s<0x20> at IP %s ", browc->lmb_name, inet_ntoa(browc->ip) ); - dbgtext( "for workgroup %s\n", browc->work_group ); - } + /* We should only be doing this if we are a domain master browser for + the given workgroup. Ensure this is so. */ - sync_browse_lists(work, browc->lmb_name, 0x20, browc->ip, True, True); + if(!AM_DOMAIN_MASTER_BROWSER(work)) { + if( DEBUGLVL( 0 ) ) { + dbgtext( "sync_with_lmb:\n" ); + dbgtext( "We are trying to sync with a local master browser " ); + dbgtext( "%s for workgroup %s\n", browc->lmb_name, browc->work_group ); + dbgtext( "and we are not a domain master browser on this workgroup.\n" ); + dbgtext( "Error!\n" ); + } + return; + } + + if( DEBUGLVL( 2 ) ) { + dbgtext( "sync_with_lmb:\n" ); + dbgtext( "Initiating sync with local master browser " ); + dbgtext( "%s<0x20> at IP %s ", browc->lmb_name, inet_ntoa(browc->ip) ); + dbgtext( "for workgroup %s\n", browc->work_group ); + } + + sync_browse_lists(work, browc->lmb_name, 0x20, browc->ip, True, True); - browc->sync_time += (CHECK_TIME_DMB_TO_LMB_SYNC * 60); + browc->sync_time += (CHECK_TIME_DMB_TO_LMB_SYNC * 60); } /**************************************************************************** Sync or expire any local master browsers. **************************************************************************/ + void dmb_expire_and_sync_browser_lists(time_t t) { - static time_t last_run = 0; - struct browse_cache_record *browc; + static time_t last_run = 0; + struct browse_cache_record *browc; - /* Only do this every 20 seconds. */ - if (t - last_run < 20) - return; + /* Only do this every 20 seconds. */ + if (t - last_run < 20) + return; - last_run = t; + last_run = t; - expire_lmb_browsers(t); + expire_lmb_browsers(t); - for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist ); - browc; - browc = (struct browse_cache_record *)ubi_dlNext( browc ) ) - { - if (browc->sync_time < t) - sync_with_lmb(browc); - } + for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist ); + browc; + browc = (struct browse_cache_record *)ubi_dlNext( browc ) ) { + if (browc->sync_time < t) + sync_with_lmb(browc); + } } /**************************************************************************** @@ -105,46 +101,43 @@ As a local master browser, send an announce packet to the domain master browser. static void announce_local_master_browser_to_domain_master_browser( struct work_record *work) { - pstring outbuf; - fstring myname; - char *p; - - if(ismyip(work->dmb_addr)) - { - if( DEBUGLVL( 2 ) ) - { - dbgtext( "announce_local_master_browser_to_domain_master_browser:\n" ); - dbgtext( "We are both a domain and a local master browser for " ); - dbgtext( "workgroup %s. ", work->work_group ); - dbgtext( "Do not announce to ourselves.\n" ); - } - return; - } + pstring outbuf; + fstring myname; + char *p; + + if(ismyip(work->dmb_addr)) { + if( DEBUGLVL( 2 ) ) { + dbgtext( "announce_local_master_browser_to_domain_master_browser:\n" ); + dbgtext( "We are both a domain and a local master browser for " ); + dbgtext( "workgroup %s. ", work->work_group ); + dbgtext( "Do not announce to ourselves.\n" ); + } + return; + } - memset(outbuf,'\0',sizeof(outbuf)); - p = outbuf; - SCVAL(p,0,ANN_MasterAnnouncement); - p++; + memset(outbuf,'\0',sizeof(outbuf)); + p = outbuf; + SCVAL(p,0,ANN_MasterAnnouncement); + p++; - fstrcpy(myname, global_myname()); - strupper_m(myname); - myname[15]='\0'; - push_pstring_base(p, myname, outbuf); + fstrcpy(myname, global_myname()); + strupper_m(myname); + myname[15]='\0'; + /* The call below does CH_UNIX -> CH_DOS conversion. JRA */ + push_pstring_base(p, myname, outbuf); - p = skip_string(p,1); + p = skip_string(p,1); - if( DEBUGLVL( 4 ) ) - { - dbgtext( "announce_local_master_browser_to_domain_master_browser:\n" ); - dbgtext( "Sending local master announce to " ); - dbgtext( "%s for workgroup %s.\n", nmb_namestr(&work->dmb_name), - work->work_group ); - } + if( DEBUGLVL( 4 ) ) { + dbgtext( "announce_local_master_browser_to_domain_master_browser:\n" ); + dbgtext( "Sending local master announce to " ); + dbgtext( "%s for workgroup %s.\n", nmb_namestr(&work->dmb_name), + work->work_group ); + } - send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), + send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), global_myname(), 0x0, work->dmb_name.name, 0x0, work->dmb_addr, FIRST_SUBNET->myip, DGRAM_PORT); - } /**************************************************************************** @@ -153,17 +146,19 @@ As a local master browser, do a sync with a domain master browser. static void sync_with_dmb(struct work_record *work) { - if( DEBUGLVL( 2 ) ) - { - dbgtext( "sync_with_dmb:\n" ); - dbgtext( "Initiating sync with domain master browser " ); - dbgtext( "%s ", nmb_namestr(&work->dmb_name) ); - dbgtext( "at IP %s ", inet_ntoa(work->dmb_addr) ); - dbgtext( "for workgroup %s\n", work->work_group ); - } + nstring dmb_name; + + if( DEBUGLVL( 2 ) ) { + dbgtext( "sync_with_dmb:\n" ); + dbgtext( "Initiating sync with domain master browser " ); + dbgtext( "%s ", nmb_namestr(&work->dmb_name) ); + dbgtext( "at IP %s ", inet_ntoa(work->dmb_addr) ); + dbgtext( "for workgroup %s\n", work->work_group ); + } - sync_browse_lists(work, work->dmb_name.name, work->dmb_name.name_type, - work->dmb_addr, False, True); + pull_ascii_nstring(dmb_name, work->dmb_name.name); + sync_browse_lists(work, dmb_name, work->dmb_name.name_type, + work->dmb_addr, False, True); } /**************************************************************************** @@ -175,78 +170,69 @@ static void domain_master_node_status_success(struct subnet_record *subrec, struct res_rec *answers, struct in_addr from_ip) { - struct work_record *work = find_workgroup_on_subnet( subrec, userdata->data); - - if( work == NULL ) - { - if( DEBUGLVL( 0 ) ) - { - dbgtext( "domain_master_node_status_success:\n" ); - dbgtext( "Unable to find workgroup " ); - dbgtext( "%s on subnet %s.\n", userdata->data, subrec->subnet_name ); - } - return; - } + struct work_record *work = find_workgroup_on_subnet( subrec, userdata->data); - if( DEBUGLVL( 3 ) ) - { - dbgtext( "domain_master_node_status_success:\n" ); - dbgtext( "Success in node status for workgroup " ); - dbgtext( "%s from ip %s\n", work->work_group, inet_ntoa(from_ip) ); - } + if( work == NULL ) { + if( DEBUGLVL( 0 ) ) { + dbgtext( "domain_master_node_status_success:\n" ); + dbgtext( "Unable to find workgroup " ); + dbgtext( "%s on subnet %s.\n", userdata->data, subrec->subnet_name ); + } + return; + } + + if( DEBUGLVL( 3 ) ) { + dbgtext( "domain_master_node_status_success:\n" ); + dbgtext( "Success in node status for workgroup " ); + dbgtext( "%s from ip %s\n", work->work_group, inet_ntoa(from_ip) ); + } /* Go through the list of names found at answers->rdata and look for the first SERVER<0x20> name. */ - if(answers->rdata != NULL) - { - char *p = answers->rdata; - int numnames = CVAL(p, 0); + if(answers->rdata != NULL) { + char *p = answers->rdata; + int numnames = CVAL(p, 0); - p += 1; + p += 1; - while (numnames--) - { - char qname[17]; - uint16 nb_flags; - int name_type; + while (numnames--) { + nstring qname; + uint16 nb_flags; + int name_type; - StrnCpy(qname,p,15); - name_type = CVAL(p,15); - nb_flags = get_nb_flags(&p[16]); - trim_string(qname,NULL," "); + pull_ascii_nstring(qname, p); + name_type = CVAL(p,15); + nb_flags = get_nb_flags(&p[16]); + trim_string(qname,NULL," "); - p += 18; + p += 18; - if(!(nb_flags & NB_GROUP) && (name_type == 0x20)) - { - struct nmb_name nmbname; + if(!(nb_flags & NB_GROUP) && (name_type == 0x20)) { + struct nmb_name nmbname; - make_nmb_name(&nmbname, qname, name_type); + make_nmb_name(&nmbname, qname, name_type); - /* Copy the dmb name and IP address - into the workgroup struct. */ + /* Copy the dmb name and IP address + into the workgroup struct. */ - work->dmb_name = nmbname; - putip((char *)&work->dmb_addr, &from_ip); + work->dmb_name = nmbname; + putip((char *)&work->dmb_addr, &from_ip); - /* Do the local master browser announcement to the domain - master browser name and IP. */ - announce_local_master_browser_to_domain_master_browser( work ); + /* Do the local master browser announcement to the domain + master browser name and IP. */ + announce_local_master_browser_to_domain_master_browser( work ); - /* Now synchronise lists with the domain master browser. */ - sync_with_dmb(work); - break; - } - } - } - else - if( DEBUGLVL( 0 ) ) - { - dbgtext( "domain_master_node_status_success:\n" ); - dbgtext( "Failed to find a SERVER<0x20> name in reply from IP " ); - dbgtext( "%s.\n", inet_ntoa(from_ip) ); - } + /* Now synchronise lists with the domain master browser. */ + sync_with_dmb(work); + break; + } + } + } else if( DEBUGLVL( 0 ) ) { + dbgtext( "domain_master_node_status_success:\n" ); + dbgtext( "Failed to find a SERVER<0x20> name in reply from IP " ); + dbgtext( "%s.\n", inet_ntoa(from_ip) ); + } } /**************************************************************************** @@ -256,16 +242,15 @@ static void domain_master_node_status_success(struct subnet_record *subrec, static void domain_master_node_status_fail(struct subnet_record *subrec, struct response_record *rrec) { - struct userdata_struct *userdata = rrec->userdata; - - if( DEBUGLVL( 0 ) ) - { - dbgtext( "domain_master_node_status_fail:\n" ); - dbgtext( "Doing a node status request to the domain master browser\n" ); - dbgtext( "for workgroup %s ", userdata ? userdata->data : "NULL" ); - dbgtext( "at IP %s failed.\n", inet_ntoa(rrec->packet->ip) ); - dbgtext( "Cannot sync browser lists.\n" ); - } + struct userdata_struct *userdata = rrec->userdata; + + if( DEBUGLVL( 0 ) ) { + dbgtext( "domain_master_node_status_fail:\n" ); + dbgtext( "Doing a node status request to the domain master browser\n" ); + dbgtext( "for workgroup %s ", userdata ? userdata->data : "NULL" ); + dbgtext( "at IP %s failed.\n", inet_ntoa(rrec->packet->ip) ); + dbgtext( "Cannot sync browser lists.\n" ); + } } /**************************************************************************** @@ -276,100 +261,99 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec, struct userdata_struct *userdata_in, struct nmb_name *q_name, struct in_addr answer_ip, struct res_rec *rrec) { - /* - * Unfortunately, finding the IP address of the Domain Master Browser, - * as we have here, is not enough. We need to now do a sync to the - * SERVERNAME<0x20> NetBIOS name, as only recent NT servers will - * respond to the SMBSERVER name. To get this name from IP - * address we do a Node status request, and look for the first - * NAME<0x20> in the response, and take that as the server name. - * We also keep a cache of the Domain Master Browser name for this - * workgroup in the Workgroup struct, so that if the same IP addess - * is returned every time, we don't need to do the node status - * request. - */ - - struct work_record *work; - struct nmb_name nmbname; - struct userdata_struct *userdata; - size_t size = sizeof(struct userdata_struct) + sizeof(fstring)+1; - - if( !(work = find_workgroup_on_subnet(subrec, q_name->name)) ) - { - if( DEBUGLVL( 0 ) ) - { - dbgtext( "find_domain_master_name_query_success:\n" ); - dbgtext( "Failed to find workgroup %s\n", q_name->name ); - } - return; + /* + * Unfortunately, finding the IP address of the Domain Master Browser, + * as we have here, is not enough. We need to now do a sync to the + * SERVERNAME<0x20> NetBIOS name, as only recent NT servers will + * respond to the SMBSERVER name. To get this name from IP + * address we do a Node status request, and look for the first + * NAME<0x20> in the response, and take that as the server name. + * We also keep a cache of the Domain Master Browser name for this + * workgroup in the Workgroup struct, so that if the same IP addess + * is returned every time, we don't need to do the node status + * request. + */ + + struct work_record *work; + struct nmb_name nmbname; + struct userdata_struct *userdata; + size_t size = sizeof(struct userdata_struct) + sizeof(fstring)+1; + nstring qname; + + pull_ascii_nstring(qname, q_name->name); + if( !(work = find_workgroup_on_subnet(subrec, qname)) ) { + if( DEBUGLVL( 0 ) ) { + dbgtext( "find_domain_master_name_query_success:\n" ); + dbgtext( "Failed to find workgroup %s\n", qname); + } + return; } /* First check if we already have a dmb for this workgroup. */ - if(!is_zero_ip(work->dmb_addr) && ip_equal(work->dmb_addr, answer_ip)) - { - /* Do the local master browser announcement to the domain - master browser name and IP. */ - announce_local_master_browser_to_domain_master_browser( work ); + if(!is_zero_ip(work->dmb_addr) && ip_equal(work->dmb_addr, answer_ip)) { + /* Do the local master browser announcement to the domain + master browser name and IP. */ + announce_local_master_browser_to_domain_master_browser( work ); - /* Now synchronise lists with the domain master browser. */ - sync_with_dmb(work); - return; - } - else - zero_ip(&work->dmb_addr); - - /* Now initiate the node status request. */ - - /* We used to use the name "*",0x0 here, but some Windows - * servers don't answer that name. However we *know* they - * have the name workgroup#1b (as we just looked it up). - * So do the node status request on this name instead. - * Found at LBL labs. JRA. - */ - - make_nmb_name(&nmbname,work->work_group,0x1b); - - /* Put the workgroup name into the userdata so we know - what workgroup we're talking to when the reply comes - back. */ - - /* Setup the userdata_struct - this is copied so we can use - a stack variable for this. */ - if((userdata = (struct userdata_struct *)malloc(size)) == NULL) - { - DEBUG(0, ("find_domain_master_name_query_success: malloc fail.\n")); - return; - } + /* Now synchronise lists with the domain master browser. */ + sync_with_dmb(work); + return; + } else { + zero_ip(&work->dmb_addr); + } - userdata->copy_fn = NULL; - userdata->free_fn = NULL; - userdata->userdata_len = strlen(work->work_group)+1; - overmalloc_safe_strcpy(userdata->data, work->work_group, size - sizeof(*userdata) - 1); + /* Now initiate the node status request. */ - node_status( subrec, &nmbname, answer_ip, - domain_master_node_status_success, - domain_master_node_status_fail, - userdata); + /* We used to use the name "*",0x0 here, but some Windows + * servers don't answer that name. However we *know* they + * have the name workgroup#1b (as we just looked it up). + * So do the node status request on this name instead. + * Found at LBL labs. JRA. + */ - zero_free(userdata, size); + make_nmb_name(&nmbname,work->work_group,0x1b); + + /* Put the workgroup name into the userdata so we know + what workgroup we're talking to when the reply comes + back. */ + + /* Setup the userdata_struct - this is copied so we can use + a stack variable for this. */ + + if((userdata = (struct userdata_struct *)malloc(size)) == NULL) { + DEBUG(0, ("find_domain_master_name_query_success: malloc fail.\n")); + return; + } + + userdata->copy_fn = NULL; + userdata->free_fn = NULL; + userdata->userdata_len = strlen(work->work_group)+1; + overmalloc_safe_strcpy(userdata->data, work->work_group, size - sizeof(*userdata) - 1); + + node_status( subrec, &nmbname, answer_ip, + domain_master_node_status_success, + domain_master_node_status_fail, + userdata); + + zero_free(userdata, size); } /**************************************************************************** Function called when a query for a WORKGROUP<1b> name fails. ****************************************************************************/ + static void find_domain_master_name_query_fail(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *question_name, int fail_code) { - if( DEBUGLVL( 0 ) ) - { - dbgtext( "find_domain_master_name_query_fail:\n" ); - dbgtext( "Unable to find the Domain Master Browser name " ); - dbgtext( "%s for the workgroup %s.\n", - nmb_namestr(question_name), question_name->name ); - dbgtext( "Unable to sync browse lists in this workgroup.\n" ); - } + if( DEBUGLVL( 0 ) ) { + dbgtext( "find_domain_master_name_query_fail:\n" ); + dbgtext( "Unable to find the Domain Master Browser name " ); + dbgtext( "%s for the workgroup %s.\n", + nmb_namestr(question_name), question_name->name ); + dbgtext( "Unable to sync browse lists in this workgroup.\n" ); + } } /**************************************************************************** @@ -381,27 +365,20 @@ full domain browse lists from it onto the given subnet. void announce_and_sync_with_domain_master_browser( struct subnet_record *subrec, struct work_record *work) { - struct nmb_name nmbname; - - /* Only do this if we are using a WINS server. */ - if(we_are_a_wins_client() == False) - { - if( DEBUGLVL( 10 ) ) - { - dbgtext( "announce_and_sync_with_domain_master_browser:\n" ); - dbgtext( "Ignoring, as we are not a WINS client.\n" ); - } - return; - } - - make_nmb_name(&nmbname,work->work_group,0x1b); + /* Only do this if we are using a WINS server. */ + if(we_are_a_wins_client() == False) { + if( DEBUGLVL( 10 ) ) { + dbgtext( "announce_and_sync_with_domain_master_browser:\n" ); + dbgtext( "Ignoring, as we are not a WINS client.\n" ); + } + return; + } - /* First, query for the WORKGROUP<1b> name from the WINS server. */ - query_name(unicast_subnet, nmbname.name, nmbname.name_type, + /* First, query for the WORKGROUP<1b> name from the WINS server. */ + query_name(unicast_subnet, work->work_group, 0x1b, find_domain_master_name_query_success, find_domain_master_name_query_fail, NULL); - } /**************************************************************************** @@ -421,89 +398,81 @@ static void get_domain_master_name_node_status_success(struct subnet_record *sub struct res_rec *answers, struct in_addr from_ip) { - struct work_record *work; - fstring server_name; + struct work_record *work; + fstring server_name; - server_name[0] = 0; + server_name[0] = 0; - if( DEBUGLVL( 3 ) ) - { - dbgtext( "get_domain_master_name_node_status_success:\n" ); - dbgtext( "Success in node status from ip %s\n", inet_ntoa(from_ip) ); - } + if( DEBUGLVL( 3 ) ) { + dbgtext( "get_domain_master_name_node_status_success:\n" ); + dbgtext( "Success in node status from ip %s\n", inet_ntoa(from_ip) ); + } - /* - * Go through the list of names found at answers->rdata and look for - * the first WORKGROUP<0x1b> name. - */ - - if(answers->rdata != NULL) - { - char *p = answers->rdata; - int numnames = CVAL(p, 0); - - p += 1; - - while (numnames--) - { - char qname[17]; - uint16 nb_flags; - int name_type; - - StrnCpy(qname,p,15); - name_type = CVAL(p,15); - nb_flags = get_nb_flags(&p[16]); - trim_string(qname,NULL," "); - - p += 18; - - if(!(nb_flags & NB_GROUP) && (name_type == 0x00) && - server_name[0] == 0) { - /* this is almost certainly the server netbios name */ - fstrcpy(server_name, qname); - continue; - } - - if(!(nb_flags & NB_GROUP) && (name_type == 0x1b)) - { - if( DEBUGLVL( 5 ) ) - { - dbgtext( "get_domain_master_name_node_status_success:\n" ); - dbgtext( "%s(%s) ", server_name, inet_ntoa(from_ip) ); - dbgtext( "is a domain master browser for workgroup " ); - dbgtext( "%s. Adding this name.\n", qname ); - } - - /* - * If we don't already know about this workgroup, add it - * to the workgroup list on the unicast_subnet. - */ - if((work = find_workgroup_on_subnet( subrec, qname)) == NULL) - { - struct nmb_name nmbname; - /* - * Add it - with an hour in the cache. - */ - if(!(work= create_workgroup_on_subnet(subrec, qname, 60*60))) - return; - - /* remember who the master is */ - fstrcpy(work->local_master_browser_name, server_name); - make_nmb_name(&nmbname, server_name, 0x20); - work->dmb_name = nmbname; - work->dmb_addr = from_ip; - } - break; - } - } - } - else - if( DEBUGLVL( 0 ) ) - { - dbgtext( "get_domain_master_name_node_status_success:\n" ); - dbgtext( "Failed to find a WORKGROUP<0x1b> name in reply from IP " ); - dbgtext( "%s.\n", inet_ntoa(from_ip) ); - } + /* + * Go through the list of names found at answers->rdata and look for + * the first WORKGROUP<0x1b> name. + */ + + if(answers->rdata != NULL) { + char *p = answers->rdata; + int numnames = CVAL(p, 0); + + p += 1; + + while (numnames--) { + nstring qname; + uint16 nb_flags; + int name_type; + + pull_ascii_nstring(qname, p); + name_type = CVAL(p,15); + nb_flags = get_nb_flags(&p[16]); + trim_string(qname,NULL," "); + + p += 18; + + if(!(nb_flags & NB_GROUP) && (name_type == 0x00) && + server_name[0] == 0) { + /* this is almost certainly the server netbios name */ + fstrcpy(server_name, qname); + continue; + } + + if(!(nb_flags & NB_GROUP) && (name_type == 0x1b)) { + if( DEBUGLVL( 5 ) ) { + dbgtext( "get_domain_master_name_node_status_success:\n" ); + dbgtext( "%s(%s) ", server_name, inet_ntoa(from_ip) ); + dbgtext( "is a domain master browser for workgroup " ); + dbgtext( "%s. Adding this name.\n", qname ); + } + + /* + * If we don't already know about this workgroup, add it + * to the workgroup list on the unicast_subnet. + */ + + if((work = find_workgroup_on_subnet( subrec, qname)) == NULL) { + struct nmb_name nmbname; + /* + * Add it - with an hour in the cache. + */ + if(!(work= create_workgroup_on_subnet(subrec, qname, 60*60))) + return; + + /* remember who the master is */ + fstrcpy(work->local_master_browser_name, server_name); + make_nmb_name(&nmbname, server_name, 0x20); + work->dmb_name = nmbname; + work->dmb_addr = from_ip; + } + break; + } + } + } else if( DEBUGLVL( 0 ) ) { + dbgtext( "get_domain_master_name_node_status_success:\n" ); + dbgtext( "Failed to find a WORKGROUP<0x1b> name in reply from IP " ); + dbgtext( "%s.\n", inet_ntoa(from_ip) ); + } } /**************************************************************************** @@ -513,13 +482,12 @@ static void get_domain_master_name_node_status_success(struct subnet_record *sub static void get_domain_master_name_node_status_fail(struct subnet_record *subrec, struct response_record *rrec) { - if( DEBUGLVL( 0 ) ) - { - dbgtext( "get_domain_master_name_node_status_fail:\n" ); - dbgtext( "Doing a node status request to the domain master browser " ); - dbgtext( "at IP %s failed.\n", inet_ntoa(rrec->packet->ip) ); - dbgtext( "Cannot get workgroup name.\n" ); - } + if( DEBUGLVL( 0 ) ) { + dbgtext( "get_domain_master_name_node_status_fail:\n" ); + dbgtext( "Doing a node status request to the domain master browser " ); + dbgtext( "at IP %s failed.\n", inet_ntoa(rrec->packet->ip) ); + dbgtext( "Cannot get workgroup name.\n" ); + } } /**************************************************************************** @@ -530,58 +498,53 @@ static void find_all_domain_master_names_query_success(struct subnet_record *sub struct userdata_struct *userdata_in, struct nmb_name *q_name, struct in_addr answer_ip, struct res_rec *rrec) { - /* - * We now have a list of all the domain master browsers for all workgroups - * that have registered with the WINS server. Now do a node status request - * to each one and look for the first 1b name in the reply. This will be - * the workgroup name that we will add to the unicast subnet as a 'non-local' - * workgroup. - */ - - struct nmb_name nmbname; - struct in_addr send_ip; - int i; - - if( DEBUGLVL( 5 ) ) - { - dbgtext( "find_all_domain_master_names_query_succes:\n" ); - dbgtext( "Got answer from WINS server of %d ", (rrec->rdlength / 6) ); - dbgtext( "IP addresses for Domain Master Browsers.\n" ); - } + /* + * We now have a list of all the domain master browsers for all workgroups + * that have registered with the WINS server. Now do a node status request + * to each one and look for the first 1b name in the reply. This will be + * the workgroup name that we will add to the unicast subnet as a 'non-local' + * workgroup. + */ + + struct nmb_name nmbname; + struct in_addr send_ip; + int i; + + if( DEBUGLVL( 5 ) ) { + dbgtext( "find_all_domain_master_names_query_succes:\n" ); + dbgtext( "Got answer from WINS server of %d ", (rrec->rdlength / 6) ); + dbgtext( "IP addresses for Domain Master Browsers.\n" ); + } - for(i = 0; i < rrec->rdlength / 6; i++) - { - /* Initiate the node status requests. */ - make_nmb_name(&nmbname, "*", 0); - - putip((char *)&send_ip, (char *)&rrec->rdata[(i*6) + 2]); - - /* - * Don't send node status requests to ourself. - */ - - if(ismyip( send_ip )) - { - if( DEBUGLVL( 5 ) ) - { - dbgtext( "find_all_domain_master_names_query_succes:\n" ); - dbgtext( "Not sending node status to our own IP " ); - dbgtext( "%s.\n", inet_ntoa(send_ip) ); - } - continue; - } - - if( DEBUGLVL( 5 ) ) - { - dbgtext( "find_all_domain_master_names_query_success:\n" ); - dbgtext( "Sending node status request to IP %s.\n", inet_ntoa(send_ip) ); - } - - node_status( subrec, &nmbname, send_ip, - get_domain_master_name_node_status_success, - get_domain_master_name_node_status_fail, - NULL); - } + for(i = 0; i < rrec->rdlength / 6; i++) { + /* Initiate the node status requests. */ + make_nmb_name(&nmbname, "*", 0); + + putip((char *)&send_ip, (char *)&rrec->rdata[(i*6) + 2]); + + /* + * Don't send node status requests to ourself. + */ + + if(ismyip( send_ip )) { + if( DEBUGLVL( 5 ) ) { + dbgtext( "find_all_domain_master_names_query_succes:\n" ); + dbgtext( "Not sending node status to our own IP " ); + dbgtext( "%s.\n", inet_ntoa(send_ip) ); + } + continue; + } + + if( DEBUGLVL( 5 ) ) { + dbgtext( "find_all_domain_master_names_query_success:\n" ); + dbgtext( "Sending node status request to IP %s.\n", inet_ntoa(send_ip) ); + } + + node_status( subrec, &nmbname, send_ip, + get_domain_master_name_node_status_success, + get_domain_master_name_node_status_fail, + NULL); + } } /**************************************************************************** @@ -591,13 +554,12 @@ static void find_all_domain_master_names_query_fail(struct subnet_record *subrec struct response_record *rrec, struct nmb_name *question_name, int fail_code) { - if( DEBUGLVL( 10 ) ) - { - dbgtext( "find_domain_master_name_query_fail:\n" ); - dbgtext( "WINS server did not reply to a query for name " ); - dbgtext( "%s.\nThis means it ", nmb_namestr(question_name) ); - dbgtext( "is probably not a Samba 1.9.18 or above WINS server.\n" ); - } + if( DEBUGLVL( 10 ) ) { + dbgtext( "find_domain_master_name_query_fail:\n" ); + dbgtext( "WINS server did not reply to a query for name " ); + dbgtext( "%s.\nThis means it ", nmb_namestr(question_name) ); + dbgtext( "is probably not a Samba 1.9.18 or above WINS server.\n" ); + } } /**************************************************************************** @@ -608,43 +570,39 @@ static void find_all_domain_master_names_query_fail(struct subnet_record *subrec <1b> name in the reply - this is the workgroup name. Add this to the unicast subnet. This is expensive, so we only do this every 15 minutes. **************************************************************************/ + void collect_all_workgroup_names_from_wins_server(time_t t) { - static time_t lastrun = 0; - struct work_record *work; - struct nmb_name nmbname; - - /* Only do this if we are using a WINS server. */ - if(we_are_a_wins_client() == False) - return; - - /* Check to see if we are a domain master browser on the unicast subnet. */ - if((work = find_workgroup_on_subnet( unicast_subnet, lp_workgroup())) == NULL) - { - if( DEBUGLVL( 0 ) ) - { - dbgtext( "collect_all_workgroup_names_from_wins_server:\n" ); - dbgtext( "Cannot find my workgroup %s ", lp_workgroup() ); - dbgtext( "on subnet %s.\n", unicast_subnet->subnet_name ); - } - return; - } + static time_t lastrun = 0; + struct work_record *work; - if(!AM_DOMAIN_MASTER_BROWSER(work)) - return; + /* Only do this if we are using a WINS server. */ + if(we_are_a_wins_client() == False) + return; - if ((lastrun != 0) && (t < lastrun + (15 * 60))) - return; - - lastrun = t; + /* Check to see if we are a domain master browser on the unicast subnet. */ + if((work = find_workgroup_on_subnet( unicast_subnet, lp_workgroup())) == NULL) { + if( DEBUGLVL( 0 ) ) { + dbgtext( "collect_all_workgroup_names_from_wins_server:\n" ); + dbgtext( "Cannot find my workgroup %s ", lp_workgroup() ); + dbgtext( "on subnet %s.\n", unicast_subnet->subnet_name ); + } + return; + } + + if(!AM_DOMAIN_MASTER_BROWSER(work)) + return; - make_nmb_name(&nmbname,"*",0x1b); + if ((lastrun != 0) && (t < lastrun + (15 * 60))) + return; + + lastrun = t; - /* First, query for the *<1b> name from the WINS server. */ - query_name(unicast_subnet, nmbname.name, nmbname.name_type, - find_all_domain_master_names_query_success, - find_all_domain_master_names_query_fail, - NULL); + /* First, query for the *<1b> name from the WINS server. */ + query_name(unicast_subnet, "*", 0x1b, + find_all_domain_master_names_query_success, + find_all_domain_master_names_query_fail, + NULL); } @@ -656,6 +614,7 @@ To prevent exponential network traffic with large numbers of workgroups we use a randomised system where sync probability is inversely proportional to the number of known workgroups **************************************************************************/ + void sync_all_dmbs(time_t t) { static time_t lastrun = 0; @@ -669,7 +628,8 @@ void sync_all_dmbs(time_t t) /* Check to see if we are a domain master browser on the unicast subnet. */ work = find_workgroup_on_subnet(unicast_subnet, lp_workgroup()); - if (!work) return; + if (!work) + return; if (!AM_DOMAIN_MASTER_BROWSER(work)) return; @@ -687,7 +647,10 @@ void sync_all_dmbs(time_t t) /* sync with a probability of 1/count */ for (work=unicast_subnet->workgrouplist; work; work = work->next) { if (strcmp(lp_workgroup(), work->work_group)) { - if (((unsigned)sys_random()) % count != 0) continue; + nstring dmb_name; + + if (((unsigned)sys_random()) % count != 0) + continue; lastrun = t; @@ -699,13 +662,15 @@ void sync_all_dmbs(time_t t) 0x20); } + pull_ascii_nstring(dmb_name, work->dmb_name.name); + DEBUG(3,("Initiating DMB<->DMB sync with %s(%s)\n", - work->dmb_name.name, - inet_ntoa(work->dmb_addr))); + dmb_name, inet_ntoa(work->dmb_addr))); + sync_browse_lists(work, - work->dmb_name.name, + dmb_name, work->dmb_name.name_type, work->dmb_addr, False, False); } } -} +} diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index b948eb9d04..09ab9ee783 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -3,7 +3,7 @@ NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 - Copyright (C) Jeremy Allison 1994-1998 + Copyright (C) Jeremy Allison 1994-2003 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,32 +29,35 @@ extern time_t StartupTime; /**************************************************************************** Send an election datagram packet. **************************************************************************/ + static void send_election_dgram(struct subnet_record *subrec, const char *workgroup_name, uint32 criterion, int timeup,const char *server_name) { - pstring outbuf; - char *p; - - DEBUG(2,("send_election_dgram: Sending election packet for workgroup %s on subnet %s\n", - workgroup_name, subrec->subnet_name )); - - memset(outbuf,'\0',sizeof(outbuf)); - p = outbuf; - SCVAL(p,0,ANN_Election); /* Election opcode. */ - p++; - - SCVAL(p,0,((criterion == 0 && timeup == 0) ? 0 : ELECTION_VERSION)); - SIVAL(p,1,criterion); - SIVAL(p,5,timeup*1000); /* ms - Despite what the spec says. */ - p += 13; - pstrcpy_base(p, server_name, outbuf); - strupper_m(p); - p = skip_string(p,1); + pstring outbuf; + fstring srv_name; + char *p; + + DEBUG(2,("send_election_dgram: Sending election packet for workgroup %s on subnet %s\n", + workgroup_name, subrec->subnet_name )); + + memset(outbuf,'\0',sizeof(outbuf)); + p = outbuf; + SCVAL(p,0,ANN_Election); /* Election opcode. */ + p++; + + SCVAL(p,0,((criterion == 0 && timeup == 0) ? 0 : ELECTION_VERSION)); + SIVAL(p,1,criterion); + SIVAL(p,5,timeup*1000); /* ms - Despite what the spec says. */ + p += 13; + fstrcpy(srv_name, server_name); + strupper_m(srv_name); + pstrcpy_base(p, srv_name, outbuf); + p = skip_string(p,1); - send_mailslot(False, BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), - global_myname(), 0, - workgroup_name, 0x1e, - subrec->bcast_ip, subrec->myip, DGRAM_PORT); + send_mailslot(False, BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), + global_myname(), 0, + workgroup_name, 0x1e, + subrec->bcast_ip, subrec->myip, DGRAM_PORT); } /******************************************************************* @@ -66,8 +69,10 @@ static void check_for_master_browser_success(struct subnet_record *subrec, struct nmb_name *answer_name, struct in_addr answer_ip, struct res_rec *rrec) { - DEBUG(3,("check_for_master_browser_success: Local master browser for workgroup %s exists at \ -IP %s (just checking).\n", answer_name->name, inet_ntoa(answer_ip) )); + nstring aname; + pull_ascii_nstring(aname, answer_name->name); + DEBUG(3,("check_for_master_browser_success: Local master browser for workgroup %s exists at \ +IP %s (just checking).\n", aname, inet_ntoa(answer_ip) )); } /******************************************************************* @@ -79,41 +84,39 @@ static void check_for_master_browser_fail( struct subnet_record *subrec, struct nmb_name *question_name, int fail_code) { - char *workgroup_name = question_name->name; - struct work_record *work = find_workgroup_on_subnet(subrec, workgroup_name); - - if(work == NULL) - { - DEBUG(0,("check_for_master_browser_fail: Unable to find workgroup %s on subnet %s.=\n", - workgroup_name, subrec->subnet_name )); - return; - } - - if (strequal(work->work_group, lp_workgroup())) - { - - if (lp_local_master()) - { - /* We have discovered that there is no local master - browser, and we are configured to initiate - an election that we will participate in. - */ - DEBUG(2,("check_for_master_browser_fail: Forcing election on workgroup %s subnet %s\n", - work->work_group, subrec->subnet_name )); - - /* Setting this means we will participate when the - election is run in run_elections(). */ - work->needelection = True; - } - else - { - /* We need to force an election, because we are configured - not to become the local master, but we still need one, - having detected that one doesn't exist. - */ - send_election_dgram(subrec, work->work_group, 0, 0, ""); - } - } + nstring workgroup_name; + struct work_record *work; + + pull_ascii_nstring(workgroup_name,question_name->name); + + work = find_workgroup_on_subnet(subrec, workgroup_name); + if(work == NULL) { + DEBUG(0,("check_for_master_browser_fail: Unable to find workgroup %s on subnet %s.=\n", + workgroup_name, subrec->subnet_name )); + return; + } + + if (strequal(work->work_group, lp_workgroup())) { + + if (lp_local_master()) { + /* We have discovered that there is no local master + browser, and we are configured to initiate + an election that we will participate in. + */ + DEBUG(2,("check_for_master_browser_fail: Forcing election on workgroup %s subnet %s\n", + work->work_group, subrec->subnet_name )); + + /* Setting this means we will participate when the + election is run in run_elections(). */ + work->needelection = True; + } else { + /* We need to force an election, because we are configured + not to become the local master, but we still need one, + having detected that one doesn't exist. + */ + send_election_dgram(subrec, work->work_group, 0, 0, ""); + } + } } /******************************************************************* @@ -123,36 +126,33 @@ static void check_for_master_browser_fail( struct subnet_record *subrec, void check_master_browser_exists(time_t t) { - static time_t lastrun=0; - struct subnet_record *subrec; - const char *workgroup_name = lp_workgroup(); - - if (!lastrun) - lastrun = t; - - if (t < (lastrun + (CHECK_TIME_MST_BROWSE * 60))) - return; - - lastrun = t; - - dump_workgroups(False); - - for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - { - struct work_record *work; - - for (work = subrec->workgrouplist; work; work = work->next) - { - if (strequal(work->work_group, workgroup_name) && !AM_LOCAL_MASTER_BROWSER(work)) - { - /* Do a name query for the local master browser on this net. */ - query_name( subrec, work->work_group, 0x1d, - check_for_master_browser_success, - check_for_master_browser_fail, - NULL); - } - } - } + static time_t lastrun=0; + struct subnet_record *subrec; + const char *workgroup_name = lp_workgroup(); + + if (!lastrun) + lastrun = t; + + if (t < (lastrun + (CHECK_TIME_MST_BROWSE * 60))) + return; + + lastrun = t; + + dump_workgroups(False); + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { + struct work_record *work; + + for (work = subrec->workgrouplist; work; work = work->next) { + if (strequal(work->work_group, workgroup_name) && !AM_LOCAL_MASTER_BROWSER(work)) { + /* Do a name query for the local master browser on this net. */ + query_name( subrec, work->work_group, 0x1d, + check_for_master_browser_success, + check_for_master_browser_fail, + NULL); + } + } + } } /******************************************************************* @@ -161,56 +161,52 @@ void check_master_browser_exists(time_t t) void run_elections(time_t t) { - static time_t lastime = 0; + static time_t lastime = 0; - struct subnet_record *subrec; + struct subnet_record *subrec; - /* Send election packets once every 2 seconds - note */ - if (lastime && (t - lastime < 2)) - return; + /* Send election packets once every 2 seconds - note */ + if (lastime && (t - lastime < 2)) + return; - lastime = t; + lastime = t; - START_PROFILE(run_elections); - for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - { - struct work_record *work; - - for (work = subrec->workgrouplist; work; work = work->next) - { - if (work->RunningElection) - { - /* - * We can only run an election for a workgroup if we have - * registered the WORKGROUP<1e> name, as that's the name - * we must listen to. - */ - struct nmb_name nmbname; - - make_nmb_name(&nmbname, work->work_group, 0x1e); - if(find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME)==NULL) { - DEBUG(8,("run_elections: Cannot send election packet yet as name %s not \ + START_PROFILE(run_elections); + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { + struct work_record *work; + + for (work = subrec->workgrouplist; work; work = work->next) { + if (work->RunningElection) { + /* + * We can only run an election for a workgroup if we have + * registered the WORKGROUP<1e> name, as that's the name + * we must listen to. + */ + struct nmb_name nmbname; + + make_nmb_name(&nmbname, work->work_group, 0x1e); + if(find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME)==NULL) { + DEBUG(8,("run_elections: Cannot send election packet yet as name %s not \ yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name )); - continue; - } + continue; + } - send_election_dgram(subrec, work->work_group, work->ElectionCriterion, - t - StartupTime, global_myname()); + send_election_dgram(subrec, work->work_group, work->ElectionCriterion, + t - StartupTime, global_myname()); - if (work->ElectionCount++ >= 4) - { - /* Won election (4 packets were sent out uncontested. */ - DEBUG(2,("run_elections: >>> Won election for workgroup %s on subnet %s <<<\n", - work->work_group, subrec->subnet_name )); - - work->RunningElection = False; - - become_local_master_browser(subrec, work); - } - } - } - } - END_PROFILE(run_elections); + if (work->ElectionCount++ >= 4) { + /* Won election (4 packets were sent out uncontested. */ + DEBUG(2,("run_elections: >>> Won election for workgroup %s on subnet %s <<<\n", + work->work_group, subrec->subnet_name )); + + work->RunningElection = False; + + become_local_master_browser(subrec, work); + } + } + } + } + END_PROFILE(run_elections); } /******************************************************************* @@ -218,44 +214,42 @@ yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name )); ******************************************************************/ static BOOL win_election(struct work_record *work, int version, - uint32 criterion, int timeup, char *server_name) + uint32 criterion, int timeup, const char *server_name) { - int mytimeup = time(NULL) - StartupTime; - uint32 mycriterion = work->ElectionCriterion; - - /* If local master is false then never win - in election broadcasts. */ - if(!lp_local_master()) - { - DEBUG(3,("win_election: Losing election as local master == False\n")); - return False; - } + int mytimeup = time(NULL) - StartupTime; + uint32 mycriterion = work->ElectionCriterion; + + /* If local master is false then never win in election broadcasts. */ + if(!lp_local_master()) { + DEBUG(3,("win_election: Losing election as local master == False\n")); + return False; + } - DEBUG(4,("win_election: election comparison: %x:%x %x:%x %d:%d %s:%s\n", - version, ELECTION_VERSION, - criterion, mycriterion, - timeup, mytimeup, - server_name, global_myname())); - - if (version > ELECTION_VERSION) - return(False); - if (version < ELECTION_VERSION) - return(True); + DEBUG(4,("win_election: election comparison: %x:%x %x:%x %d:%d %s:%s\n", + version, ELECTION_VERSION, + criterion, mycriterion, + timeup, mytimeup, + server_name, global_myname())); + + if (version > ELECTION_VERSION) + return(False); + if (version < ELECTION_VERSION) + return(True); - if (criterion > mycriterion) - return(False); - if (criterion < mycriterion) - return(True); - - if (timeup > mytimeup) - return(False); - if (timeup < mytimeup) - return(True); - - if (strcasecmp(global_myname(), server_name) > 0) - return(False); + if (criterion > mycriterion) + return(False); + if (criterion < mycriterion) + return(True); + + if (timeup > mytimeup) + return(False); + if (timeup < mytimeup) + return(True); + + if (strcasecmp(global_myname(), server_name) > 0) + return(False); - return(True); + return(True); } /******************************************************************* @@ -264,66 +258,63 @@ static BOOL win_election(struct work_record *work, int version, void process_election(struct subnet_record *subrec, struct packet_struct *p, char *buf) { - struct dgram_packet *dgram = &p->packet.dgram; - int version = CVAL(buf,0); - uint32 criterion = IVAL(buf,1); - int timeup = IVAL(buf,5)/1000; - char *server_name = buf+13; - struct work_record *work; - char *workgroup_name = dgram->dest_name.name; - - START_PROFILE(election); - server_name[15] = 0; - - DEBUG(3,("process_election: Election request from %s at IP %s on subnet %s for workgroup %s.\n", - server_name,inet_ntoa(p->ip), subrec->subnet_name, workgroup_name )); - - DEBUG(5,("process_election: vers=%d criterion=%08x timeup=%d\n", version,criterion,timeup)); - - if(( work = find_workgroup_on_subnet(subrec, workgroup_name)) == NULL) - { - DEBUG(0,("process_election: Cannot find workgroup %s on subnet %s.\n", - workgroup_name, subrec->subnet_name )); - goto done; - } - - if (!strequal(work->work_group, lp_workgroup())) - { - DEBUG(3,("process_election: ignoring election request for workgroup %s on subnet %s as this \ + struct dgram_packet *dgram = &p->packet.dgram; + int version = CVAL(buf,0); + uint32 criterion = IVAL(buf,1); + int timeup = IVAL(buf,5)/1000; + nstring server_name; + struct work_record *work; + nstring workgroup_name; + + pull_ascii_nstring(server_name, buf+13); + pull_ascii_nstring(workgroup_name, dgram->dest_name.name); + + START_PROFILE(election); + server_name[15] = 0; + + DEBUG(3,("process_election: Election request from %s at IP %s on subnet %s for workgroup %s.\n", + server_name,inet_ntoa(p->ip), subrec->subnet_name, workgroup_name )); + + DEBUG(5,("process_election: vers=%d criterion=%08x timeup=%d\n", version,criterion,timeup)); + + if(( work = find_workgroup_on_subnet(subrec, workgroup_name)) == NULL) { + DEBUG(0,("process_election: Cannot find workgroup %s on subnet %s.\n", + workgroup_name, subrec->subnet_name )); + goto done; + } + + if (!strequal(work->work_group, lp_workgroup())) { + DEBUG(3,("process_election: ignoring election request for workgroup %s on subnet %s as this \ is not my workgroup.\n", work->work_group, subrec->subnet_name )); - goto done; - } - - if (win_election(work, version,criterion,timeup,server_name)) - { - /* We take precedence over the requesting server. */ - if (!work->RunningElection) - { - /* We weren't running an election - start running one. */ - - work->needelection = True; - work->ElectionCount=0; - } - - /* Note that if we were running an election for this workgroup on this - subnet already, we just ignore the server we take precedence over. */ - } - else - { - /* We lost. Stop participating. */ - work->needelection = False; - - if (work->RunningElection || AM_LOCAL_MASTER_BROWSER(work)) - { - work->RunningElection = False; - DEBUG(3,("process_election: >>> Lost election for workgroup %s on subnet %s <<<\n", - work->work_group, subrec->subnet_name )); - if (AM_LOCAL_MASTER_BROWSER(work)) - unbecome_local_master_browser(subrec, work, False); - } - } + goto done; + } + + if (win_election(work, version,criterion,timeup,server_name)) { + /* We take precedence over the requesting server. */ + if (!work->RunningElection) { + /* We weren't running an election - start running one. */ + + work->needelection = True; + work->ElectionCount=0; + } + + /* Note that if we were running an election for this workgroup on this + subnet already, we just ignore the server we take precedence over. */ + } else { + /* We lost. Stop participating. */ + work->needelection = False; + + if (work->RunningElection || AM_LOCAL_MASTER_BROWSER(work)) { + work->RunningElection = False; + DEBUG(3,("process_election: >>> Lost election for workgroup %s on subnet %s <<<\n", + work->work_group, subrec->subnet_name )); + if (AM_LOCAL_MASTER_BROWSER(work)) + unbecome_local_master_browser(subrec, work, False); + } + } done: - END_PROFILE(election); + + END_PROFILE(election); } /**************************************************************************** @@ -335,57 +326,53 @@ done: BOOL check_elections(void) { - struct subnet_record *subrec; - BOOL run_any_election = False; - - for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - { - struct work_record *work; - for (work = subrec->workgrouplist; work; work = work->next) - { - run_any_election |= work->RunningElection; - - /* - * Start an election if we have any chance of winning. - * Note this is a change to the previous code, that would - * only run an election if nmbd was in the potential browser - * state. We need to run elections in any state if we're told - * to. JRA. - */ - - if (work->needelection && !work->RunningElection && lp_local_master()) - { - /* - * We can only run an election for a workgroup if we have - * registered the WORKGROUP<1e> name, as that's the name - * we must listen to. - */ - struct nmb_name nmbname; - - make_nmb_name(&nmbname, work->work_group, 0x1e); - if(find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME)==NULL) { - DEBUG(8,("check_elections: Cannot send election packet yet as name %s not \ + struct subnet_record *subrec; + BOOL run_any_election = False; + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { + struct work_record *work; + for (work = subrec->workgrouplist; work; work = work->next) { + run_any_election |= work->RunningElection; + + /* + * Start an election if we have any chance of winning. + * Note this is a change to the previous code, that would + * only run an election if nmbd was in the potential browser + * state. We need to run elections in any state if we're told + * to. JRA. + */ + + if (work->needelection && !work->RunningElection && lp_local_master()) { + /* + * We can only run an election for a workgroup if we have + * registered the WORKGROUP<1e> name, as that's the name + * we must listen to. + */ + struct nmb_name nmbname; + + make_nmb_name(&nmbname, work->work_group, 0x1e); + if(find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME)==NULL) { + DEBUG(8,("check_elections: Cannot send election packet yet as name %s not \ yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name )); - continue; - } - - DEBUG(3,("check_elections: >>> Starting election for workgroup %s on subnet %s <<<\n", - work->work_group, subrec->subnet_name )); - - work->ElectionCount = 0; - work->RunningElection = True; - work->needelection = False; - } - } - } - return run_any_election; -} + continue; + } + DEBUG(3,("check_elections: >>> Starting election for workgroup %s on subnet %s <<<\n", + work->work_group, subrec->subnet_name )); + work->ElectionCount = 0; + work->RunningElection = True; + work->needelection = False; + } + } + } + return run_any_election; +} /**************************************************************************** -process a internal Samba message forcing an election + Process a internal Samba message forcing an election. ***************************************************************************/ + void nmbd_message_election(int msg_type, pid_t src, void *buf, size_t len) { struct subnet_record *subrec; diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 80465ada0d..49fad8e867 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -95,102 +95,99 @@ void tell_become_backup(void) void process_host_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf) { - struct dgram_packet *dgram = &p->packet.dgram; - int ttl = IVAL(buf,1)/1000; - char *announce_name = buf+5; - uint32 servertype = IVAL(buf,23); - char *comment = buf+31; - struct work_record *work; - struct server_record *servrec; - const char *work_name; - char *source_name = dgram->source_name.name; - - START_PROFILE(host_announce); - comment[43] = 0; + struct dgram_packet *dgram = &p->packet.dgram; + int ttl = IVAL(buf,1)/1000; + nstring announce_name; + uint32 servertype = IVAL(buf,23); + fstring comment; + struct work_record *work; + struct server_record *servrec; + nstring work_name; + nstring source_name; + + START_PROFILE(host_announce); + + pull_ascii_fstring(comment, buf+31); + comment[12] = 0; - DEBUG(3,("process_host_announce: from %s<%02x> IP %s to \ + pull_ascii_nstring(announce_name, buf+5); + pull_ascii_nstring(source_name, dgram->source_name.name); + + DEBUG(3,("process_host_announce: from %s<%02x> IP %s to \ %s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip), - nmb_namestr(&dgram->dest_name),announce_name)); + nmb_namestr(&dgram->dest_name),announce_name)); - DEBUG(5,("process_host_announce: ttl=%d server type=%08x comment=%s\n", - ttl, servertype,comment)); + DEBUG(5,("process_host_announce: ttl=%d server type=%08x comment=%s\n", + ttl, servertype,comment)); - /* Filter servertype to remove impossible bits. */ - servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM); + /* Filter servertype to remove impossible bits. */ + servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM); - /* A host announcement must be sent to the name WORKGROUP<1d>. */ - if(dgram->dest_name.name_type != 0x1d) - { - DEBUG(2,("process_host_announce: incorrect name type for destination from IP %s \ + /* A host announcement must be sent to the name WORKGROUP<1d>. */ + if(dgram->dest_name.name_type != 0x1d) { + DEBUG(2,("process_host_announce: incorrect name type for destination from IP %s \ (was %02x) should be 0x1d. Allowing packet anyway.\n", - inet_ntoa(p->ip), dgram->dest_name.name_type)); - /* Change it so it was. */ - dgram->dest_name.name_type = 0x1d; - } - - /* For a host announce the workgroup name is the destination name. */ - work_name = dgram->dest_name.name; - - /* - * Syntax servers version 5.1 send HostAnnounce packets to - * *THE WRONG NAME*. They send to LOCAL_MASTER_BROWSER_NAME<00> - * instead of WORKGROUP<1d> name. So to fix this we check if - * the workgroup name is our own name, and if so change it - * to be our primary workgroup name. - */ - - if(strequal(work_name, global_myname())) - work_name = lp_workgroup(); - - /* - * We are being very agressive here in adding a workgroup - * name on the basis of a host announcing itself as being - * in that workgroup. Maybe we should wait for the workgroup - * announce instead ? JRA. - */ - - work = find_workgroup_on_subnet(subrec, work_name); - - if(servertype != 0) - { - if (work ==NULL ) - { - /* We have no record of this workgroup. Add it. */ - if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL) - goto done; - } + inet_ntoa(p->ip), dgram->dest_name.name_type)); + /* Change it so it was. */ + dgram->dest_name.name_type = 0x1d; + } + + /* For a host announce the workgroup name is the destination name. */ + pull_ascii_nstring(work_name, dgram->dest_name.name); + + /* + * Syntax servers version 5.1 send HostAnnounce packets to + * *THE WRONG NAME*. They send to LOCAL_MASTER_BROWSER_NAME<00> + * instead of WORKGROUP<1d> name. So to fix this we check if + * the workgroup name is our own name, and if so change it + * to be our primary workgroup name. + */ + + if(strequal(work_name, global_myname())) + nstrcpy(work_name,lp_workgroup()); + + /* + * We are being very agressive here in adding a workgroup + * name on the basis of a host announcing itself as being + * in that workgroup. Maybe we should wait for the workgroup + * announce instead ? JRA. + */ + + work = find_workgroup_on_subnet(subrec, work_name); + + if(servertype != 0) { + if (work ==NULL ) { + /* We have no record of this workgroup. Add it. */ + if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL) + goto done; + } - if((servrec = find_server_in_workgroup( work, announce_name))==NULL) - { - /* If this server is not already in the workgroup, add it. */ - create_server_on_workgroup(work, announce_name, - servertype|SV_TYPE_LOCAL_LIST_ONLY, - ttl, comment); - } - else - { - /* Update the record. */ - servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; - update_server_ttl( servrec, ttl); - fstrcpy(servrec->serv.comment,comment); - } - } - else - { - /* - * This server is announcing it is going down. Remove it from the - * workgroup. - */ - if(!is_myname(announce_name) && (work != NULL) && - ((servrec = find_server_in_workgroup( work, announce_name))!=NULL) - ) - { - remove_server_from_workgroup( work, servrec); - } - } - subrec->work_changed = True; + if((servrec = find_server_in_workgroup( work, announce_name))==NULL) { + /* If this server is not already in the workgroup, add it. */ + create_server_on_workgroup(work, announce_name, + servertype|SV_TYPE_LOCAL_LIST_ONLY, + ttl, comment); + } else { + /* Update the record. */ + servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; + update_server_ttl( servrec, ttl); + fstrcpy(servrec->serv.comment,comment); + } + } else { + /* + * This server is announcing it is going down. Remove it from the + * workgroup. + */ + if(!is_myname(announce_name) && (work != NULL) && + ((servrec = find_server_in_workgroup( work, announce_name))!=NULL)) { + remove_server_from_workgroup( work, servrec); + } + } + + subrec->work_changed = True; done: - END_PROFILE(host_announce); + + END_PROFILE(host_announce); } /******************************************************************* @@ -199,53 +196,56 @@ done: void process_workgroup_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf) { - struct dgram_packet *dgram = &p->packet.dgram; - int ttl = IVAL(buf,1)/1000; - char *workgroup_announce_name = buf+5; - uint32 servertype = IVAL(buf,23); - char *master_name = buf+31; - struct work_record *work; - char *source_name = dgram->source_name.name; - - START_PROFILE(workgroup_announce); - master_name[43] = 0; - - DEBUG(3,("process_workgroup_announce: from %s<%02x> IP %s to \ + struct dgram_packet *dgram = &p->packet.dgram; + int ttl = IVAL(buf,1)/1000; + nstring workgroup_announce_name; + nstring master_name; + uint32 servertype = IVAL(buf,23); + struct work_record *work; + nstring source_name; + nstring dest_name; + + START_PROFILE(workgroup_announce); + + pull_ascii_nstring(workgroup_announce_name,buf+5); + pull_ascii_nstring(master_name,buf+31); + master_name[12] = 0; + pull_ascii_nstring(source_name,dgram->source_name.name); + pull_ascii_nstring(dest_name,dgram->dest_name.name); + + DEBUG(3,("process_workgroup_announce: from %s<%02x> IP %s to \ %s for workgroup %s.\n", source_name, source_name[15], inet_ntoa(p->ip), - nmb_namestr(&dgram->dest_name),workgroup_announce_name)); - - DEBUG(5,("process_workgroup_announce: ttl=%d server type=%08x master browser=%s\n", - ttl, servertype, master_name)); - - /* Workgroup announcements must only go to the MSBROWSE name. */ - if (!strequal(dgram->dest_name.name, MSBROWSE) || (dgram->dest_name.name_type != 0x1)) - { - DEBUG(0,("process_workgroup_announce: from IP %s should be to __MSBROWSE__<0x01> not %s\n", - inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name))); - goto done; - } + nmb_namestr(&dgram->dest_name),workgroup_announce_name)); + + DEBUG(5,("process_workgroup_announce: ttl=%d server type=%08x master browser=%s\n", + ttl, servertype, master_name)); + + /* Workgroup announcements must only go to the MSBROWSE name. */ + if (!strequal(dest_name, MSBROWSE) || (dgram->dest_name.name_type != 0x1)) { + DEBUG(0,("process_workgroup_announce: from IP %s should be to __MSBROWSE__<0x01> not %s\n", + inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name))); + goto done; + } + + if ((work = find_workgroup_on_subnet(subrec, workgroup_announce_name))==NULL) { + /* We have no record of this workgroup. Add it. */ + if((work = create_workgroup_on_subnet(subrec, workgroup_announce_name, ttl))==NULL) + goto done; + } else { + /* Update the workgroup death_time. */ + update_workgroup_ttl(work, ttl); + } + + if(*work->local_master_browser_name == '\0') { + /* Set the master browser name. */ + set_workgroup_local_master_browser_name( work, master_name ); + } + + subrec->work_changed = True; - if ((work = find_workgroup_on_subnet(subrec, workgroup_announce_name))==NULL) - { - /* We have no record of this workgroup. Add it. */ - if((work = create_workgroup_on_subnet(subrec, workgroup_announce_name, ttl))==NULL) - goto done; - } - else - { - /* Update the workgroup death_time. */ - update_workgroup_ttl(work, ttl); - } - - if(*work->local_master_browser_name == '\0') - { - /* Set the master browser name. */ - set_workgroup_local_master_browser_name( work, master_name ); - } - - subrec->work_changed = True; done: - END_PROFILE(workgroup_announce); + + END_PROFILE(workgroup_announce); } /******************************************************************* @@ -254,117 +254,110 @@ done: void process_local_master_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf) { - struct dgram_packet *dgram = &p->packet.dgram; - int ttl = IVAL(buf,1)/1000; - char *server_name = buf+5; - uint32 servertype = IVAL(buf,23); - char *comment = buf+31; - char *work_name; - struct work_record *work; - struct server_record *servrec; - char *source_name = dgram->source_name.name; - - START_PROFILE(local_master_announce); - comment[43] = 0; - - DEBUG(3,("process_local_master_announce: from %s<%02x> IP %s to \ + struct dgram_packet *dgram = &p->packet.dgram; + int ttl = IVAL(buf,1)/1000; + nstring server_name; + uint32 servertype = IVAL(buf,23); + fstring comment; + nstring work_name; + struct work_record *work; + struct server_record *servrec; + nstring source_name; + + START_PROFILE(local_master_announce); + + pull_ascii_nstring(server_name,buf+5); + pull_ascii_fstring(comment, buf+31); + comment[12] = 0; + pull_ascii_nstring(source_name, dgram->source_name.name); + pull_ascii_nstring(work_name, dgram->dest_name.name); + + DEBUG(3,("process_local_master_announce: from %s<%02x> IP %s to \ %s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip), - nmb_namestr(&dgram->dest_name),server_name)); + nmb_namestr(&dgram->dest_name),server_name)); - DEBUG(5,("process_local_master_announce: ttl=%d server type=%08x comment=%s\n", - ttl, servertype, comment)); + DEBUG(5,("process_local_master_announce: ttl=%d server type=%08x comment=%s\n", + ttl, servertype, comment)); - /* A local master announcement must be sent to the name WORKGROUP<1e>. */ - if(dgram->dest_name.name_type != 0x1e) - { - DEBUG(0,("process_local_master_announce: incorrect name type for destination from IP %s \ + /* A local master announcement must be sent to the name WORKGROUP<1e>. */ + if(dgram->dest_name.name_type != 0x1e) { + DEBUG(0,("process_local_master_announce: incorrect name type for destination from IP %s \ (was %02x) should be 0x1e. Ignoring packet.\n", - inet_ntoa(p->ip), dgram->dest_name.name_type)); - goto done; - } - - /* Filter servertype to remove impossible bits. */ - servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM); - - /* For a local master announce the workgroup name is the destination name. */ - work_name = dgram->dest_name.name; - - if ((work = find_workgroup_on_subnet(subrec, work_name))==NULL) - { - /* Don't bother adding if it's a local master release announce. */ - if(servertype == 0) - goto done; - - /* We have no record of this workgroup. Add it. */ - if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL) - goto done; - } - - /* If we think we're the local master browser for this workgroup, - we should never have got this packet. We don't see our own - packets. - */ - if(AM_LOCAL_MASTER_BROWSER(work)) - { - DEBUG(0,("process_local_master_announce: Server %s at IP %s is announcing itself as \ + inet_ntoa(p->ip), dgram->dest_name.name_type)); + goto done; + } + + /* Filter servertype to remove impossible bits. */ + servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM); + + /* For a local master announce the workgroup name is the destination name. */ + + if ((work = find_workgroup_on_subnet(subrec, work_name))==NULL) { + /* Don't bother adding if it's a local master release announce. */ + if(servertype == 0) + goto done; + + /* We have no record of this workgroup. Add it. */ + if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL) + goto done; + } + + /* If we think we're the local master browser for this workgroup, + we should never have got this packet. We don't see our own + packets. + */ + if(AM_LOCAL_MASTER_BROWSER(work)) { + DEBUG(0,("process_local_master_announce: Server %s at IP %s is announcing itself as \ a local master browser for workgroup %s and we think we are master. Forcing election.\n", - server_name, inet_ntoa(p->ip), work_name)); + server_name, inet_ntoa(p->ip), work_name)); - /* Samba nmbd versions 1.9.17 to 1.9.17p4 have a bug in that when - they have become a local master browser once, they will never - stop sending local master announcements. To fix this we send - them a reset browser packet, with level 0x2 on the __SAMBA__ - name that only they should be listening to. */ + /* Samba nmbd versions 1.9.17 to 1.9.17p4 have a bug in that when + they have become a local master browser once, they will never + stop sending local master announcements. To fix this we send + them a reset browser packet, with level 0x2 on the __SAMBA__ + name that only they should be listening to. */ - send_browser_reset( 0x2, "__SAMBA__" , 0x20, p->ip); - - /* We should demote ourself and force an election. */ - - unbecome_local_master_browser( subrec, work, True); - - /* The actual election requests are handled in - nmbd_election.c */ - goto done; - } - - /* Find the server record on this workgroup. If it doesn't exist, add it. */ - - if(servertype != 0) - { - if((servrec = find_server_in_workgroup( work, server_name))==NULL) - { - /* If this server is not already in the workgroup, add it. */ - create_server_on_workgroup(work, server_name, - servertype|SV_TYPE_LOCAL_LIST_ONLY, - ttl, comment); - } - else - { - /* Update the record. */ - servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; - update_server_ttl(servrec, ttl); - fstrcpy(servrec->serv.comment,comment); - } - - set_workgroup_local_master_browser_name( work, server_name ); - } - else - { - /* - * This server is announcing it is going down. Remove it from the - * workgroup. - */ - if(!is_myname(server_name) && (work != NULL) && - ((servrec = find_server_in_workgroup( work, server_name))!=NULL) - ) - { - remove_server_from_workgroup( work, servrec); - } - } - - subrec->work_changed = True; + send_browser_reset( 0x2, "__SAMBA__" , 0x20, p->ip); + + /* We should demote ourself and force an election. */ + + unbecome_local_master_browser( subrec, work, True); + + /* The actual election requests are handled in nmbd_election.c */ + goto done; + } + + /* Find the server record on this workgroup. If it doesn't exist, add it. */ + + if(servertype != 0) { + if((servrec = find_server_in_workgroup( work, server_name))==NULL) { + /* If this server is not already in the workgroup, add it. */ + create_server_on_workgroup(work, server_name, + servertype|SV_TYPE_LOCAL_LIST_ONLY, + ttl, comment); + } else { + /* Update the record. */ + servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; + update_server_ttl(servrec, ttl); + fstrcpy(servrec->serv.comment,comment); + } + + set_workgroup_local_master_browser_name( work, server_name ); + } else { + /* + * This server is announcing it is going down. Remove it from the + * workgroup. + */ + if(!is_myname(server_name) && (work != NULL) && + ((servrec = find_server_in_workgroup( work, server_name))!=NULL)) { + remove_server_from_workgroup( work, servrec); + } + } + + subrec->work_changed = True; done: - END_PROFILE(local_master_announce); + + END_PROFILE(local_master_announce); } /******************************************************************* @@ -377,50 +370,49 @@ done: void process_master_browser_announce(struct subnet_record *subrec, struct packet_struct *p,char *buf) { - char *local_master_name = buf; - struct work_record *work; - struct browse_cache_record *browrec; + nstring local_master_name; + struct work_record *work; + struct browse_cache_record *browrec; - START_PROFILE(master_browser_announce); - local_master_name[15] = 0; + START_PROFILE(master_browser_announce); + + pull_ascii_nstring(local_master_name,buf); - DEBUG(3,("process_master_browser_announce: Local master announce from %s IP %s.\n", - local_master_name, inet_ntoa(p->ip))); + DEBUG(3,("process_master_browser_announce: Local master announce from %s IP %s.\n", + local_master_name, inet_ntoa(p->ip))); - if (!lp_domain_master()) - { - DEBUG(0,("process_master_browser_announce: Not configured as domain \ + if (!lp_domain_master()) { + DEBUG(0,("process_master_browser_announce: Not configured as domain \ master - ignoring master announce.\n")); - goto done; - } + goto done; + } - if((work = find_workgroup_on_subnet(subrec, lp_workgroup())) == NULL) - { - DEBUG(0,("process_master_browser_announce: Cannot find workgroup %s on subnet %s\n", - lp_workgroup(), subrec->subnet_name)); - goto done; - } - - if(!AM_DOMAIN_MASTER_BROWSER(work)) - { - DEBUG(0,("process_master_browser_announce: Local master announce made to us from \ + if((work = find_workgroup_on_subnet(subrec, lp_workgroup())) == NULL) { + DEBUG(0,("process_master_browser_announce: Cannot find workgroup %s on subnet %s\n", + lp_workgroup(), subrec->subnet_name)); + goto done; + } + + if(!AM_DOMAIN_MASTER_BROWSER(work)) { + DEBUG(0,("process_master_browser_announce: Local master announce made to us from \ %s IP %s and we are not a domain master browser.\n", local_master_name, inet_ntoa(p->ip))); - goto done; - } + goto done; + } - /* Add this host as a local master browser entry on the browse lists. - This causes a sync request to be made to it at a later date. - */ + /* Add this host as a local master browser entry on the browse lists. + This causes a sync request to be made to it at a later date. + */ + + if((browrec = find_browser_in_lmb_cache( local_master_name )) == NULL) { + /* Add it. */ + create_browser_in_lmb_cache( work->work_group, local_master_name, p->ip); + } else { + update_browser_death_time(browrec); + } - if((browrec = find_browser_in_lmb_cache( local_master_name )) == NULL) - { - /* Add it. */ - create_browser_in_lmb_cache( work->work_group, local_master_name, p->ip); - } - else - update_browser_death_time(browrec); done: - END_PROFILE(master_browser_announce); + + END_PROFILE(master_browser_announce); } /******************************************************************* @@ -429,123 +421,117 @@ done: void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf) { - struct dgram_packet *dgram = &p->packet.dgram; - uint32 servertype = IVAL(buf,1); - int osmajor=CVAL(buf,5); /* major version of node software */ - int osminor=CVAL(buf,6); /* minor version of node software */ - int ttl = SVAL(buf,7); - char *announce_name = buf+9; - struct work_record *work; - struct server_record *servrec; - const char *work_name; - char *source_name = dgram->source_name.name; - pstring comment; - char *s = buf+9; - - START_PROFILE(lm_host_announce); - s = skip_string(s,1); - StrnCpy(comment, s, 43); - - DEBUG(3,("process_lm_host_announce: LM Announcement from %s<%02x> IP %s to \ -%s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip), - nmb_namestr(&dgram->dest_name),announce_name)); - - DEBUG(5,("process_lm_host_announce: os=(%d,%d) ttl=%d server type=%08x comment=%s\n", - osmajor, osminor, ttl, servertype,comment)); - - if ((osmajor < 36) || (osmajor > 38) || (osminor !=0)) - { - DEBUG(5,("process_lm_host_announce: LM Announcement packet does not \ + struct dgram_packet *dgram = &p->packet.dgram; + uint32 servertype = IVAL(buf,1); + int osmajor=CVAL(buf,5); /* major version of node software */ + int osminor=CVAL(buf,6); /* minor version of node software */ + int ttl = SVAL(buf,7); + nstring announce_name; + struct work_record *work; + struct server_record *servrec; + nstring work_name; + nstring source_name; + fstring comment; + char *s = buf+9; + + START_PROFILE(lm_host_announce); + s = skip_string(s,1); + pull_ascii(comment, s, sizeof(fstring), 43, STR_TERMINATE); + + pull_ascii_nstring(announce_name,buf+9); + pull_ascii_nstring(source_name,dgram->source_name.name); + /* For a LanMan host announce the workgroup name is the destination name. */ + pull_ascii_nstring(work_name,dgram->dest_name.name); + + DEBUG(3,("process_lm_host_announce: LM Announcement from %s IP %s to \ +%s for server %s.\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), + nmb_namestr(&dgram->dest_name),announce_name)); + + DEBUG(5,("process_lm_host_announce: os=(%d,%d) ttl=%d server type=%08x comment=%s\n", + osmajor, osminor, ttl, servertype,comment)); + + if ((osmajor < 36) || (osmajor > 38) || (osminor !=0)) { + DEBUG(5,("process_lm_host_announce: LM Announcement packet does not \ originate from OS/2 Warp client. Ignoring packet.\n")); - /* Could have been from a Windows machine (with its LM Announce enabled), - or a Samba server. Then don't disrupt the current browse list. */ - goto done; - } + /* Could have been from a Windows machine (with its LM Announce enabled), + or a Samba server. Then don't disrupt the current browse list. */ + goto done; + } - /* Filter servertype to remove impossible bits. */ - servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM); + /* Filter servertype to remove impossible bits. */ + servertype &= ~(SV_TYPE_LOCAL_LIST_ONLY|SV_TYPE_DOMAIN_ENUM); - /* A LanMan host announcement must be sent to the name WORKGROUP<00>. */ - if(dgram->dest_name.name_type != 0x00) - { - DEBUG(2,("process_lm_host_announce: incorrect name type for destination from IP %s \ + /* A LanMan host announcement must be sent to the name WORKGROUP<00>. */ + if(dgram->dest_name.name_type != 0x00) { + DEBUG(2,("process_lm_host_announce: incorrect name type for destination from IP %s \ (was %02x) should be 0x00. Allowing packet anyway.\n", - inet_ntoa(p->ip), dgram->dest_name.name_type)); - /* Change it so it was. */ - dgram->dest_name.name_type = 0x00; - } - - /* For a LanMan host announce the workgroup name is the destination name. */ - work_name = dgram->dest_name.name; - - /* - * Syntax servers version 5.1 send HostAnnounce packets to - * *THE WRONG NAME*. They send to LOCAL_MASTER_BROWSER_NAME<00> - * instead of WORKGROUP<1d> name. So to fix this we check if - * the workgroup name is our own name, and if so change it - * to be our primary workgroup name. This code is probably - * not needed in the LanMan announce code, but it won't hurt. - */ - - if(strequal(work_name, global_myname())) - work_name = lp_workgroup(); - - /* - * We are being very agressive here in adding a workgroup - * name on the basis of a host announcing itself as being - * in that workgroup. Maybe we should wait for the workgroup - * announce instead ? JRA. - */ + inet_ntoa(p->ip), dgram->dest_name.name_type)); + /* Change it so it was. */ + dgram->dest_name.name_type = 0x00; + } + + /* + * Syntax servers version 5.1 send HostAnnounce packets to + * *THE WRONG NAME*. They send to LOCAL_MASTER_BROWSER_NAME<00> + * instead of WORKGROUP<1d> name. So to fix this we check if + * the workgroup name is our own name, and if so change it + * to be our primary workgroup name. This code is probably + * not needed in the LanMan announce code, but it won't hurt. + */ + + if(strequal(work_name, global_myname())) + nstrcpy(work_name,lp_workgroup()); + + /* + * We are being very agressive here in adding a workgroup + * name on the basis of a host announcing itself as being + * in that workgroup. Maybe we should wait for the workgroup + * announce instead ? JRA. + */ + + work = find_workgroup_on_subnet(subrec, work_name); + + if(servertype != 0) { + if (work == NULL) { + /* We have no record of this workgroup. Add it. */ + if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL) + goto done; + } + + if((servrec = find_server_in_workgroup( work, announce_name))==NULL) { + /* If this server is not already in the workgroup, add it. */ + create_server_on_workgroup(work, announce_name, + servertype|SV_TYPE_LOCAL_LIST_ONLY, + ttl, comment); + } else { + /* Update the record. */ + servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; + update_server_ttl( servrec, ttl); + fstrcpy(servrec->serv.comment,comment); + } + } else { + /* + * This server is announcing it is going down. Remove it from the + * workgroup. + */ + if(!is_myname(announce_name) && (work != NULL) && + ((servrec = find_server_in_workgroup( work, announce_name))!=NULL)) { + remove_server_from_workgroup( work, servrec); + } + } + + subrec->work_changed = True; + found_lm_clients = True; - work = find_workgroup_on_subnet(subrec, work_name); - - if(servertype != 0) - { - if (work == NULL) - { - /* We have no record of this workgroup. Add it. */ - if((work = create_workgroup_on_subnet(subrec, work_name, ttl))==NULL) - goto done; - } - - if((servrec = find_server_in_workgroup( work, announce_name))==NULL) - { - /* If this server is not already in the workgroup, add it. */ - create_server_on_workgroup(work, announce_name, - servertype|SV_TYPE_LOCAL_LIST_ONLY, - ttl, comment); - } - else - { - /* Update the record. */ - servrec->serv.type = servertype|SV_TYPE_LOCAL_LIST_ONLY; - update_server_ttl( servrec, ttl); - fstrcpy(servrec->serv.comment,comment); - } - } - else - { - /* - * This server is announcing it is going down. Remove it from the - * workgroup. - */ - if(!is_myname(announce_name) && (work != NULL) && - ((servrec = find_server_in_workgroup( work, announce_name))!=NULL) - ) - { - remove_server_from_workgroup( work, servrec); - } - } - - subrec->work_changed = True; - found_lm_clients = True; done: - END_PROFILE(lm_host_announce); + + END_PROFILE(lm_host_announce); } /**************************************************************************** Send a backup list response. *****************************************************************************/ + static void send_backup_list_response(struct subnet_record *subrec, struct work_record *work, struct nmb_name *send_to_name, @@ -553,40 +539,41 @@ static void send_backup_list_response(struct subnet_record *subrec, uint32 token, struct in_addr sendto_ip, int port) { - char outbuf[1024]; - char *p, *countptr; - unsigned int count = 0; + char outbuf[1024]; + char *p, *countptr; + unsigned int count = 0; + nstring send_to_namestr; #if 0 struct server_record *servrec; #endif - fstring myname; + fstring myname; - memset(outbuf,'\0',sizeof(outbuf)); + memset(outbuf,'\0',sizeof(outbuf)); - DEBUG(3,("send_backup_list_response: sending backup list for workgroup %s to %s IP %s\n", - work->work_group, nmb_namestr(send_to_name), inet_ntoa(sendto_ip))); + DEBUG(3,("send_backup_list_response: sending backup list for workgroup %s to %s IP %s\n", + work->work_group, nmb_namestr(send_to_name), inet_ntoa(sendto_ip))); - p = outbuf; + p = outbuf; - SCVAL(p,0,ANN_GetBackupListResp); /* Backup list response opcode. */ - p++; + SCVAL(p,0,ANN_GetBackupListResp); /* Backup list response opcode. */ + p++; - countptr = p; - p++; + countptr = p; + p++; - SIVAL(p,0,token); /* The sender's unique info. */ - p += 4; + SIVAL(p,0,token); /* The sender's unique info. */ + p += 4; - /* We always return at least one name - our own. */ - count = 1; - fstrcpy(myname, global_myname()); - strupper_m(myname); - myname[15]='\0'; - push_pstring_base(p, myname, outbuf); + /* We always return at least one name - our own. */ + count = 1; + fstrcpy(myname, global_myname()); + strupper_m(myname); + myname[15]='\0'; + push_pstring_base(p, myname, outbuf); - p = skip_string(p,1); + p = skip_string(p,1); - /* Look for backup browsers in this workgroup. */ + /* Look for backup browsers in this workgroup. */ #if 0 /* we don't currently send become_backup requests so we should never @@ -624,16 +611,18 @@ static void send_backup_list_response(struct subnet_record *subrec, } #endif - SCVAL(countptr, 0, count); + SCVAL(countptr, 0, count); + + pull_ascii_nstring(send_to_namestr, send_to_name->name); - DEBUG(4,("send_backup_list_response: sending response to %s<00> IP %s with %d servers.\n", - send_to_name->name, inet_ntoa(sendto_ip), count)); + DEBUG(4,("send_backup_list_response: sending response to %s<00> IP %s with %d servers.\n", + send_to_namestr, inet_ntoa(sendto_ip), count)); - send_mailslot(True, BROWSE_MAILSLOT, - outbuf,PTR_DIFF(p,outbuf), - global_myname(), 0, - send_to_name->name,0, - sendto_ip, subrec->myip, port); + send_mailslot(True, BROWSE_MAILSLOT, + outbuf,PTR_DIFF(p,outbuf), + global_myname(), 0, + send_to_namestr,0, + sendto_ip, subrec->myip, port); } /******************************************************************* @@ -649,80 +638,74 @@ static void send_backup_list_response(struct subnet_record *subrec, void process_get_backup_list_request(struct subnet_record *subrec, struct packet_struct *p,char *buf) { - struct dgram_packet *dgram = &p->packet.dgram; - struct work_record *work; - unsigned char max_number_requested = CVAL(buf,0); - uint32 token = IVAL(buf,1); /* Sender's key index for the workgroup. */ - int name_type = dgram->dest_name.name_type; - char *workgroup_name = dgram->dest_name.name; - struct subnet_record *search_subrec = subrec; - - START_PROFILE(get_backup_list); - DEBUG(3,("process_get_backup_list_request: request from %s IP %s to %s.\n", - nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), - nmb_namestr(&dgram->dest_name))); + struct dgram_packet *dgram = &p->packet.dgram; + struct work_record *work; + unsigned char max_number_requested = CVAL(buf,0); + uint32 token = IVAL(buf,1); /* Sender's key index for the workgroup. */ + int name_type = dgram->dest_name.name_type; + nstring workgroup_name; + struct subnet_record *search_subrec = subrec; + + START_PROFILE(get_backup_list); + pull_ascii_nstring(workgroup_name, dgram->dest_name.name); + + DEBUG(3,("process_get_backup_list_request: request from %s IP %s to %s.\n", + nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), + nmb_namestr(&dgram->dest_name))); - /* We have to be a master browser, or a domain master browser - for the requested workgroup. That means it must be our - workgroup. */ - - if(strequal(workgroup_name, lp_workgroup()) == False) - { - DEBUG(7,("process_get_backup_list_request: Ignoring announce request for workgroup %s.\n", - workgroup_name)); - goto done; - } - - if((work = find_workgroup_on_subnet(search_subrec, workgroup_name)) == NULL) - { - DEBUG(0,("process_get_backup_list_request: Cannot find workgroup %s on \ + /* We have to be a master browser, or a domain master browser + for the requested workgroup. That means it must be our + workgroup. */ + + if(strequal(workgroup_name, lp_workgroup()) == False) { + DEBUG(7,("process_get_backup_list_request: Ignoring announce request for workgroup %s.\n", + workgroup_name)); + goto done; + } + + if((work = find_workgroup_on_subnet(search_subrec, workgroup_name)) == NULL) { + DEBUG(0,("process_get_backup_list_request: Cannot find workgroup %s on \ subnet %s.\n", workgroup_name, search_subrec->subnet_name)); - goto done; - } + goto done; + } - /* - * If the packet was sent to WORKGROUP<1b> instead - * of WORKGROUP<1d> then it was unicast to us a domain master - * browser. Change search subrec to unicast. - */ + /* + * If the packet was sent to WORKGROUP<1b> instead + * of WORKGROUP<1d> then it was unicast to us a domain master + * browser. Change search subrec to unicast. + */ - if(name_type == 0x1b) - { - /* We must be a domain master browser in order to - process this packet. */ + if(name_type == 0x1b) { + /* We must be a domain master browser in order to + process this packet. */ - if(!AM_DOMAIN_MASTER_BROWSER(work)) - { - DEBUG(0,("process_get_backup_list_request: domain list requested for workgroup %s \ + if(!AM_DOMAIN_MASTER_BROWSER(work)) { + DEBUG(0,("process_get_backup_list_request: domain list requested for workgroup %s \ and I am not a domain master browser.\n", workgroup_name)); - goto done; - } + goto done; + } - search_subrec = unicast_subnet; - } - else if (name_type == 0x1d) - { - /* We must be a local master browser in order to - process this packet. */ + search_subrec = unicast_subnet; + } else if (name_type == 0x1d) { + /* We must be a local master browser in order to process this packet. */ - if(!AM_LOCAL_MASTER_BROWSER(work)) - { - DEBUG(0,("process_get_backup_list_request: domain list requested for workgroup %s \ + if(!AM_LOCAL_MASTER_BROWSER(work)) { + DEBUG(0,("process_get_backup_list_request: domain list requested for workgroup %s \ and I am not a local master browser.\n", workgroup_name)); - goto done; - } - } - else - { - DEBUG(0,("process_get_backup_list_request: Invalid name type %x - should be 0x1b or 0x1d.\n", - name_type)); - goto done; - } + goto done; + } + } else { + DEBUG(0,("process_get_backup_list_request: Invalid name type %x - should be 0x1b or 0x1d.\n", + name_type)); + goto done; + } + + send_backup_list_response(subrec, work, &dgram->source_name, + max_number_requested, token, p->ip, p->port); - send_backup_list_response(subrec, work, &dgram->source_name, - max_number_requested, token, p->ip, p->port); done: - END_PROFILE(get_backup_list); + + END_PROFILE(get_backup_list); } /******************************************************************* @@ -738,49 +721,46 @@ done: void process_reset_browser(struct subnet_record *subrec, struct packet_struct *p,char *buf) { - struct dgram_packet *dgram = &p->packet.dgram; - int state = CVAL(buf,0); - struct subnet_record *sr; + struct dgram_packet *dgram = &p->packet.dgram; + int state = CVAL(buf,0); + struct subnet_record *sr; - START_PROFILE(reset_browser); - DEBUG(1,("process_reset_browser: received diagnostic browser reset \ -request from %s IP %s state=0x%X\n", - nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), state)); + START_PROFILE(reset_browser); - /* Stop being a local master browser on all our broadcast subnets. */ - if (state & 0x1) - { - for (sr = FIRST_SUBNET; sr; sr = NEXT_SUBNET_EXCLUDING_UNICAST(sr)) - { - struct work_record *work; - for (work = sr->workgrouplist; work; work = work->next) - { - if (AM_LOCAL_MASTER_BROWSER(work)) - unbecome_local_master_browser(sr, work, True); - } - } - } + DEBUG(1,("process_reset_browser: received diagnostic browser reset \ +request from %s IP %s state=0x%X\n", + nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), state)); + + /* Stop being a local master browser on all our broadcast subnets. */ + if (state & 0x1) { + for (sr = FIRST_SUBNET; sr; sr = NEXT_SUBNET_EXCLUDING_UNICAST(sr)) { + struct work_record *work; + for (work = sr->workgrouplist; work; work = work->next) { + if (AM_LOCAL_MASTER_BROWSER(work)) + unbecome_local_master_browser(sr, work, True); + } + } + } - /* Discard our browse lists. */ - if (state & 0x2) - { - /* - * Calling expire_workgroups_and_servers with a -1 - * time causes all servers not marked with a PERMANENT_TTL - * on the workgroup lists to be discarded, and all - * workgroups with empty server lists to be discarded. - * This means we keep our own server names and workgroup - * as these have a PERMANENT_TTL. - */ - - expire_workgroups_and_servers(-1); - } + /* Discard our browse lists. */ + if (state & 0x2) { + /* + * Calling expire_workgroups_and_servers with a -1 + * time causes all servers not marked with a PERMANENT_TTL + * on the workgroup lists to be discarded, and all + * workgroups with empty server lists to be discarded. + * This means we keep our own server names and workgroup + * as these have a PERMANENT_TTL. + */ + + expire_workgroups_and_servers(-1); + } - /* Request to stop browsing altogether. */ - if (state & 0x4) - DEBUG(1,("process_reset_browser: ignoring request to stop being a browser.\n")); + /* Request to stop browsing altogether. */ + if (state & 0x4) + DEBUG(1,("process_reset_browser: ignoring request to stop being a browser.\n")); - END_PROFILE(reset_browser); + END_PROFILE(reset_browser); } /******************************************************************* @@ -793,33 +773,34 @@ request from %s IP %s state=0x%X\n", void process_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf) { - struct dgram_packet *dgram = &p->packet.dgram; - struct work_record *work; - char *workgroup_name = dgram->dest_name.name; + struct dgram_packet *dgram = &p->packet.dgram; + struct work_record *work; + nstring workgroup_name; - START_PROFILE(announce_request); - DEBUG(3,("process_announce_request: Announce request from %s IP %s to %s.\n", - nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), - nmb_namestr(&dgram->dest_name))); - - /* We only send announcement requests on our workgroup. */ - if(strequal(workgroup_name, lp_workgroup()) == False) - { - DEBUG(7,("process_announce_request: Ignoring announce request for workgroup %s.\n", - workgroup_name)); - goto done; - } - - if((work = find_workgroup_on_subnet(subrec, workgroup_name)) == NULL) - { - DEBUG(0,("process_announce_request: Unable to find workgroup %s on subnet !\n", - workgroup_name)); - goto done; - } + START_PROFILE(announce_request); - work->needannounce = True; + pull_ascii_nstring(workgroup_name, dgram->dest_name.name); + DEBUG(3,("process_announce_request: Announce request from %s IP %s to %s.\n", + nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), + nmb_namestr(&dgram->dest_name))); + + /* We only send announcement requests on our workgroup. */ + if(strequal(workgroup_name, lp_workgroup()) == False) { + DEBUG(7,("process_announce_request: Ignoring announce request for workgroup %s.\n", + workgroup_name)); + goto done; + } + + if((work = find_workgroup_on_subnet(subrec, workgroup_name)) == NULL) { + DEBUG(0,("process_announce_request: Unable to find workgroup %s on subnet !\n", + workgroup_name)); + goto done; + } + + work->needannounce = True; done: - END_PROFILE(lm_host_announce); + + END_PROFILE(lm_host_announce); } /******************************************************************* @@ -833,30 +814,32 @@ done: void process_lm_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf) { - struct dgram_packet *dgram = &p->packet.dgram; - char *workgroup_name = dgram->dest_name.name; + struct dgram_packet *dgram = &p->packet.dgram; + nstring workgroup_name; - START_PROFILE(lm_announce_request); - DEBUG(3,("process_lm_announce_request: Announce request from %s IP %s to %s.\n", - nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), - nmb_namestr(&dgram->dest_name))); + START_PROFILE(lm_announce_request); - /* We only send announcement requests on our workgroup. */ - if(strequal(workgroup_name, lp_workgroup()) == False) - { - DEBUG(7,("process_lm_announce_request: Ignoring announce request for workgroup %s.\n", - workgroup_name)); - goto done; - } + pull_ascii_nstring(workgroup_name, dgram->dest_name.name); + DEBUG(3,("process_lm_announce_request: Announce request from %s IP %s to %s.\n", + nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), + nmb_namestr(&dgram->dest_name))); - if(find_workgroup_on_subnet(subrec, workgroup_name) == NULL) - { - DEBUG(0,("process_announce_request: Unable to find workgroup %s on subnet !\n", - workgroup_name)); - goto done; - } + /* We only send announcement requests on our workgroup. */ + if(strequal(workgroup_name, lp_workgroup()) == False) { + DEBUG(7,("process_lm_announce_request: Ignoring announce request for workgroup %s.\n", + workgroup_name)); + goto done; + } + + if(find_workgroup_on_subnet(subrec, workgroup_name) == NULL) { + DEBUG(0,("process_announce_request: Unable to find workgroup %s on subnet !\n", + workgroup_name)); + goto done; + } + + found_lm_clients = True; - found_lm_clients = True; done: - END_PROFILE(lm_host_announce); + + END_PROFILE(lm_host_announce); } diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index 8995e9ac52..2a200713b9 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -201,7 +201,7 @@ static BOOL query_local_namelists(struct subnet_record *subrec, struct nmb_name Try and query for a name. ****************************************************************************/ -BOOL query_name(struct subnet_record *subrec, char *name, int type, +BOOL query_name(struct subnet_record *subrec, const char *name, int type, query_name_success_function success_fn, query_name_fail_function fail_fn, struct userdata_struct *userdata) @@ -276,7 +276,7 @@ BOOL query_name(struct subnet_record *subrec, char *name, int type, ****************************************************************************/ BOOL query_name_from_wins_server(struct in_addr ip_to, - char *name, int type, + const char *name, int type, query_name_success_function success_fn, query_name_fail_function fail_fn, struct userdata_struct *userdata) -- cgit From 9fdc1363bec6ae9a0a0f9a37130b98a92ebe8ce2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 27 Aug 2003 01:25:01 +0000 Subject: Fix the character set handling properly in nmbd. Also fix bug where iconv wasn't re-initialised on reading of "charset" parameters. This caused workgroup name to be set incorrectly if it contained an extended character. Jeremy. (This used to be commit 84ae44678a6c59c999bc1023fdd9b7ad87f4ec18) --- source3/nmbd/asyncdns.c | 73 +- source3/nmbd/nmbd.c | 3 +- source3/nmbd/nmbd_elections.c | 1 + source3/nmbd/nmbd_incomingrequests.c | 606 ++++---- source3/nmbd/nmbd_lmhosts.c | 91 +- source3/nmbd/nmbd_logonnames.c | 195 +-- source3/nmbd/nmbd_mynames.c | 184 ++- source3/nmbd/nmbd_namelistdb.c | 800 +++++----- source3/nmbd/nmbd_namequery.c | 410 +++-- source3/nmbd/nmbd_nameregister.c | 28 +- source3/nmbd/nmbd_nodestatus.c | 68 +- source3/nmbd/nmbd_packets.c | 2499 +++++++++++++++---------------- source3/nmbd/nmbd_processlogon.c | 813 +++++----- source3/nmbd/nmbd_responserecordsdb.c | 318 ++-- source3/nmbd/nmbd_sendannounce.c | 765 +++++----- source3/nmbd/nmbd_serverlistdb.c | 520 +++---- source3/nmbd/nmbd_subnetdb.c | 395 +++-- source3/nmbd/nmbd_synclists.c | 29 +- source3/nmbd/nmbd_winsproxy.c | 260 ++-- source3/nmbd/nmbd_winsserver.c | 2649 ++++++++++++++++----------------- source3/nmbd/nmbd_workgroupdb.c | 357 ++--- 21 files changed, 5325 insertions(+), 5739 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index c86ee69a09..6d5d487b11 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -26,26 +26,25 @@ static struct name_record *add_dns_result(struct nmb_name *question, struct in_addr addr) { - int name_type = question->name_type; - char *qname = question->name; - + int name_type = question->name_type; + nstring qname; + + pull_ascii_nstring(qname, question->name); - if (!addr.s_addr) { - /* add the fail to WINS cache of names. give it 1 hour in the cache */ - DEBUG(3,("add_dns_result: Negative DNS answer for %s\n", qname)); - (void)add_name_to_subnet( wins_server_subnet, qname, name_type, - NB_ACTIVE, 60*60, DNSFAIL_NAME, 1, &addr ); - return( NULL ); - } - - /* add it to our WINS cache of names. give it 2 hours in the cache */ - DEBUG(3,("add_dns_result: DNS gave answer for %s of %s\n", qname, inet_ntoa(addr))); - - return( add_name_to_subnet( wins_server_subnet, qname, name_type, - NB_ACTIVE, 2*60*60, DNS_NAME, 1, &addr ) ); -} + if (!addr.s_addr) { + /* add the fail to WINS cache of names. give it 1 hour in the cache */ + DEBUG(3,("add_dns_result: Negative DNS answer for %s\n", qname)); + (void)add_name_to_subnet( wins_server_subnet, qname, name_type, + NB_ACTIVE, 60*60, DNSFAIL_NAME, 1, &addr ); + return( NULL ); + } + /* add it to our WINS cache of names. give it 2 hours in the cache */ + DEBUG(3,("add_dns_result: DNS gave answer for %s of %s\n", qname, inet_ntoa(addr))); + return( add_name_to_subnet( wins_server_subnet, qname, name_type, + NB_ACTIVE, 2*60*60, DNS_NAME, 1, &addr ) ); +} #ifndef SYNC_DNS @@ -70,6 +69,7 @@ static struct packet_struct *dns_current; return the fd used to gather async dns replies. This is added to the select loop ****************************************************************************/ + int asyncdns_fd(void) { return fd_in; @@ -110,7 +110,7 @@ static void asyncdns_process(void) static void sig_term(int sig) { - _exit(0); + _exit(0); } /*************************************************************************** @@ -224,10 +224,10 @@ void run_dns_queue(void) if (query_current(&r)) { DEBUG(3,("DNS calling send_wins_name_query_response\n")); in_dns = 1; - if(namerec == NULL) - send_wins_name_query_response(NAM_ERR, dns_current, NULL); - else - send_wins_name_query_response(0,dns_current,namerec); + if(namerec == NULL) + send_wins_name_query_response(NAM_ERR, dns_current, NULL); + else + send_wins_name_query_response(0,dns_current,namerec); in_dns = 0; } @@ -245,10 +245,10 @@ void run_dns_queue(void) if (nmb_name_equal(question, &r.name)) { DEBUG(3,("DNS calling send_wins_name_query_response\n")); in_dns = 1; - if(namerec == NULL) - send_wins_name_query_response(NAM_ERR, p, NULL); - else - send_wins_name_query_response(0,p,namerec); + if(namerec == NULL) + send_wins_name_query_response(NAM_ERR, p, NULL); + else + send_wins_name_query_response(0,p,namerec); in_dns = 0; p->locked = False; @@ -269,7 +269,8 @@ void run_dns_queue(void) if (dns_queue) { dns_current = dns_queue; dns_queue = dns_queue->next; - if (dns_queue) dns_queue->prev = NULL; + if (dns_queue) + dns_queue->prev = NULL; dns_current->next = NULL; if (!write_child(dns_current)) { @@ -277,12 +278,12 @@ void run_dns_queue(void) return; } } - } /*************************************************************************** queue a DNS query ****************************************************************************/ + BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, struct name_record **n) { @@ -315,11 +316,14 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, /*************************************************************************** we use this when we can't do async DNS lookups ****************************************************************************/ + BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, struct name_record **n) { - char *qname = question->name; struct in_addr dns_ip; + nstring qname; + + pull_ascii_nstring(qname, question->name); DEBUG(3,("DNS search for %s - ", nmb_namestr(question))); @@ -332,18 +336,19 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, BlockSignals(True, SIGTERM); *n = add_dns_result(question, dns_ip); - if(*n == NULL) - send_wins_name_query_response(NAM_ERR, p, NULL); - else - send_wins_name_query_response(0, p, *n); + if(*n == NULL) + send_wins_name_query_response(NAM_ERR, p, NULL); + else + send_wins_name_query_response(0, p, *n); return False; } /*************************************************************************** With sync dns there is no child to kill on SIGTERM. ****************************************************************************/ + void kill_async_dns_child(void) { - return; + return; } #endif diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index c33011a417..25ba07c8a7 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -231,7 +231,8 @@ static BOOL reload_interfaces(time_t t) DEBUG(2,("Found new interface %s\n", inet_ntoa(iface->ip))); subrec = make_normal_subnet(iface); - if (subrec) register_my_workgroup_one_subnet(subrec); + if (subrec) + register_my_workgroup_one_subnet(subrec); } } diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 09ab9ee783..d4d6da081a 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -51,6 +51,7 @@ static void send_election_dgram(struct subnet_record *subrec, const char *workgr p += 13; fstrcpy(srv_name, server_name); strupper_m(srv_name); + /* The following call does UNIX -> DOS charset conversion. */ pstrcpy_base(p, srv_name, outbuf); p = skip_string(p,1); diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index a3faf5e104..dd999fbdf7 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -3,7 +3,7 @@ NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 - Copyright (C) Jeremy Allison 1994-1998 + Copyright (C) Jeremy Allison 1994-2003 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -33,18 +33,18 @@ Send a name release response. static void send_name_release_response(int rcode, struct packet_struct *p) { - struct nmb_packet *nmb = &p->packet.nmb; - char rdata[6]; + struct nmb_packet *nmb = &p->packet.nmb; + char rdata[6]; - memcpy(&rdata[0], &nmb->additional->rdata[0], 6); + memcpy(&rdata[0], &nmb->additional->rdata[0], 6); - reply_netbios_packet(p, /* Packet to reply to. */ - rcode, /* Result code. */ - NMB_REL, /* nmbd type code. */ - NMB_NAME_RELEASE_OPCODE, /* opcode. */ - 0, /* ttl. */ - rdata, /* data to send. */ - 6); /* data length. */ + reply_netbios_packet(p, /* Packet to reply to. */ + rcode, /* Result code. */ + NMB_REL, /* nmbd type code. */ + NMB_NAME_RELEASE_OPCODE, /* opcode. */ + 0, /* ttl. */ + rdata, /* data to send. */ + 6); /* data length. */ } /**************************************************************************** @@ -55,76 +55,74 @@ Ignore it if it's not one of our names. void process_name_release_request(struct subnet_record *subrec, struct packet_struct *p) { - struct nmb_packet *nmb = &p->packet.nmb; - struct in_addr owner_ip; - struct nmb_name *question = &nmb->question.question_name; - BOOL bcast = nmb->header.nm_flags.bcast; - uint16 nb_flags = get_nb_flags(nmb->additional->rdata); - BOOL group = (nb_flags & NB_GROUP) ? True : False; - struct name_record *namerec; - int rcode = 0; + struct nmb_packet *nmb = &p->packet.nmb; + struct in_addr owner_ip; + struct nmb_name *question = &nmb->question.question_name; + nstring qname; + BOOL bcast = nmb->header.nm_flags.bcast; + uint16 nb_flags = get_nb_flags(nmb->additional->rdata); + BOOL group = (nb_flags & NB_GROUP) ? True : False; + struct name_record *namerec; + int rcode = 0; - putip((char *)&owner_ip,&nmb->additional->rdata[2]); + putip((char *)&owner_ip,&nmb->additional->rdata[2]); - if(!bcast) - { - /* We should only get broadcast name release packets here. - Anyone trying to release unicast should be going to a WINS - server. If the code gets here, then either we are not a wins - server and they sent it anyway, or we are a WINS server and - the request was malformed. Either way, log an error here. - and send an error reply back. - */ - DEBUG(0,("process_name_release_request: unicast name release request \ + if(!bcast) { + /* We should only get broadcast name release packets here. + Anyone trying to release unicast should be going to a WINS + server. If the code gets here, then either we are not a wins + server and they sent it anyway, or we are a WINS server and + the request was malformed. Either way, log an error here. + and send an error reply back. + */ + DEBUG(0,("process_name_release_request: unicast name release request \ received for name %s from IP %s on subnet %s. Error - should be sent to WINS server\n", - nmb_namestr(question), inet_ntoa(owner_ip), subrec->subnet_name)); + nmb_namestr(question), inet_ntoa(owner_ip), subrec->subnet_name)); - send_name_release_response(FMT_ERR, p); - return; - } + send_name_release_response(FMT_ERR, p); + return; + } - DEBUG(3,("process_name_release_request: Name release on name %s, \ + DEBUG(3,("process_name_release_request: Name release on name %s, \ subnet %s from owner IP %s\n", - nmb_namestr(&nmb->question.question_name), - subrec->subnet_name, inet_ntoa(owner_ip))); + nmb_namestr(&nmb->question.question_name), + subrec->subnet_name, inet_ntoa(owner_ip))); - /* If someone is releasing a broadcast group name, just ignore it. */ - if( group && !ismyip(owner_ip) ) - return; - - /* - * Code to work around a bug in FTP OnNet software NBT implementation. - * They do a broadcast name release for WORKGROUP<0> and WORKGROUP<1e> - * names and *don't set the group bit* !!!!! - */ - - if( !group && !ismyip(owner_ip) && strequal(question->name, lp_workgroup()) && - ((question->name_type == 0x0) || (question->name_type == 0x1e))) - { - DEBUG(6,("process_name_release_request: FTP OnNet bug workaround. Ignoring \ + /* If someone is releasing a broadcast group name, just ignore it. */ + if( group && !ismyip(owner_ip) ) + return; + + /* + * Code to work around a bug in FTP OnNet software NBT implementation. + * They do a broadcast name release for WORKGROUP<0> and WORKGROUP<1e> + * names and *don't set the group bit* !!!!! + */ + + pull_ascii_nstring(qname, question->name); + if( !group && !ismyip(owner_ip) && strequal(qname, lp_workgroup()) && + ((question->name_type == 0x0) || (question->name_type == 0x1e))) { + DEBUG(6,("process_name_release_request: FTP OnNet bug workaround. Ignoring \ group release name %s from IP %s on subnet %s with no group bit set.\n", - nmb_namestr(question), inet_ntoa(owner_ip), subrec->subnet_name )); - return; - } - - namerec = find_name_on_subnet(subrec, &nmb->question.question_name, FIND_ANY_NAME); - - /* We only care about someone trying to release one of our names. */ - if( namerec - && ( (namerec->data.source == SELF_NAME) - || (namerec->data.source == PERMANENT_NAME) ) ) - { - rcode = ACT_ERR; - DEBUG(0, ("process_name_release_request: Attempt to release name %s from IP %s \ + nmb_namestr(question), inet_ntoa(owner_ip), subrec->subnet_name )); + return; + } + + namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); + + /* We only care about someone trying to release one of our names. */ + if( namerec && ( (namerec->data.source == SELF_NAME) + || (namerec->data.source == PERMANENT_NAME) ) ) { + rcode = ACT_ERR; + DEBUG(0, ("process_name_release_request: Attempt to release name %s from IP %s \ on subnet %s being rejected as it is one of our names.\n", - nmb_namestr(&nmb->question.question_name), inet_ntoa(owner_ip), subrec->subnet_name)); - } + nmb_namestr(&nmb->question.question_name), inet_ntoa(owner_ip), subrec->subnet_name)); + } - if(rcode == 0) - return; + if(rcode == 0) + return; - /* Send a NAME RELEASE RESPONSE (pos/neg) see rfc1002.txt 4.2.10-11 */ - send_name_release_response(rcode, p); + /* Send a NAME RELEASE RESPONSE (pos/neg) see rfc1002.txt 4.2.10-11 */ + send_name_release_response(rcode, p); } /**************************************************************************** @@ -133,18 +131,18 @@ Send a name registration response. static void send_name_registration_response(int rcode, int ttl, struct packet_struct *p) { - struct nmb_packet *nmb = &p->packet.nmb; - char rdata[6]; + struct nmb_packet *nmb = &p->packet.nmb; + char rdata[6]; - memcpy(&rdata[0], &nmb->additional->rdata[0], 6); + memcpy(&rdata[0], &nmb->additional->rdata[0], 6); - reply_netbios_packet(p, /* Packet to reply to. */ - rcode, /* Result code. */ - NMB_REG, /* nmbd type code. */ - NMB_NAME_REG_OPCODE, /* opcode. */ - ttl, /* ttl. */ - rdata, /* data to send. */ - 6); /* data length. */ + reply_netbios_packet(p, /* Packet to reply to. */ + rcode, /* Result code. */ + NMB_REG, /* nmbd type code. */ + NMB_NAME_REG_OPCODE, /* opcode. */ + ttl, /* ttl. */ + rdata, /* data to send. */ + 6); /* data length. */ } /**************************************************************************** @@ -154,38 +152,34 @@ Process a name refresh request on a broadcast subnet. void process_name_refresh_request(struct subnet_record *subrec, struct packet_struct *p) { - - struct nmb_packet *nmb = &p->packet.nmb; - struct nmb_name *question = &nmb->question.question_name; - BOOL bcast = nmb->header.nm_flags.bcast; - struct in_addr from_ip; + struct nmb_packet *nmb = &p->packet.nmb; + struct nmb_name *question = &nmb->question.question_name; + BOOL bcast = nmb->header.nm_flags.bcast; + struct in_addr from_ip; - putip((char *)&from_ip,&nmb->additional->rdata[2]); - - if(!bcast) - { - /* We should only get broadcast name refresh packets here. - Anyone trying to refresh unicast should be going to a WINS - server. If the code gets here, then either we are not a wins - server and they sent it anyway, or we are a WINS server and - the request was malformed. Either way, log an error here. - and send an error reply back. - */ - DEBUG(0,("process_name_refresh_request: unicast name registration request \ + putip((char *)&from_ip,&nmb->additional->rdata[2]); + + if(!bcast) { + /* We should only get broadcast name refresh packets here. + Anyone trying to refresh unicast should be going to a WINS + server. If the code gets here, then either we are not a wins + server and they sent it anyway, or we are a WINS server and + the request was malformed. Either way, log an error here. + and send an error reply back. + */ + DEBUG(0,("process_name_refresh_request: unicast name registration request \ received for name %s from IP %s on subnet %s.\n", - nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); - DEBUG(0,("Error - should be sent to WINS server\n")); + nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + DEBUG(0,("Error - should be sent to WINS server\n")); - send_name_registration_response(FMT_ERR, 0, p); - return; - } + send_name_registration_response(FMT_ERR, 0, p); + return; + } - /* Just log a message. We really don't care about broadcast name - refreshes. */ + /* Just log a message. We really don't care about broadcast name refreshes. */ - DEBUG(3,("process_name_refresh_request: Name refresh for name %s \ + DEBUG(3,("process_name_refresh_request: Name refresh for name %s \ IP %s on subnet %s\n", nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); - } /**************************************************************************** @@ -195,92 +189,83 @@ Process a name registration request on a broadcast subnet. void process_name_registration_request(struct subnet_record *subrec, struct packet_struct *p) { - struct nmb_packet *nmb = &p->packet.nmb; - struct nmb_name *question = &nmb->question.question_name; - BOOL bcast = nmb->header.nm_flags.bcast; - uint16 nb_flags = get_nb_flags(nmb->additional->rdata); - BOOL group = (nb_flags & NB_GROUP) ? True : False; - struct name_record *namerec = NULL; - int ttl = nmb->additional->ttl; - struct in_addr from_ip; + struct nmb_packet *nmb = &p->packet.nmb; + struct nmb_name *question = &nmb->question.question_name; + BOOL bcast = nmb->header.nm_flags.bcast; + uint16 nb_flags = get_nb_flags(nmb->additional->rdata); + BOOL group = (nb_flags & NB_GROUP) ? True : False; + struct name_record *namerec = NULL; + int ttl = nmb->additional->ttl; + struct in_addr from_ip; - putip((char *)&from_ip,&nmb->additional->rdata[2]); + putip((char *)&from_ip,&nmb->additional->rdata[2]); - if(!bcast) - { - /* We should only get broadcast name registration packets here. - Anyone trying to register unicast should be going to a WINS - server. If the code gets here, then either we are not a wins - server and they sent it anyway, or we are a WINS server and - the request was malformed. Either way, log an error here. - and send an error reply back. - */ - DEBUG(0,("process_name_registration_request: unicast name registration request \ + if(!bcast) { + /* We should only get broadcast name registration packets here. + Anyone trying to register unicast should be going to a WINS + server. If the code gets here, then either we are not a wins + server and they sent it anyway, or we are a WINS server and + the request was malformed. Either way, log an error here. + and send an error reply back. + */ + DEBUG(0,("process_name_registration_request: unicast name registration request \ received for name %s from IP %s on subnet %s. Error - should be sent to WINS server\n", - nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); - send_name_registration_response(FMT_ERR, 0, p); - return; - } + send_name_registration_response(FMT_ERR, 0, p); + return; + } - DEBUG(3,("process_name_registration_request: Name registration for name %s \ + DEBUG(3,("process_name_registration_request: Name registration for name %s \ IP %s on subnet %s\n", nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); - /* See if the name already exists. */ - namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); + /* See if the name already exists. */ + namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); - /* - * If the name being registered exists and is a WINS_PROXY_NAME - * then delete the WINS proxy name entry so we don't reply erroneously - * later to queries. - */ - - if((namerec != NULL) && (namerec->data.source == WINS_PROXY_NAME)) - { - remove_name_from_namelist( subrec, namerec ); - namerec = NULL; - } - - if (!group) - { - /* Unique name. */ - - if( (namerec != NULL) - && ( (namerec->data.source == SELF_NAME) - || (namerec->data.source == PERMANENT_NAME) - || NAME_GROUP(namerec) ) ) - { - /* No-one can register one of Samba's names, nor can they - register a name that's a group name as a unique name */ - - send_name_registration_response(ACT_ERR, 0, p); - return; - } - else if(namerec != NULL) - { - /* Update the namelist record with the new information. */ - namerec->data.ip[0] = from_ip; - update_name_ttl(namerec, ttl); - - DEBUG(3,("process_name_registration_request: Updated name record %s \ + /* + * If the name being registered exists and is a WINS_PROXY_NAME + * then delete the WINS proxy name entry so we don't reply erroneously + * later to queries. + */ + + if((namerec != NULL) && (namerec->data.source == WINS_PROXY_NAME)) { + remove_name_from_namelist( subrec, namerec ); + namerec = NULL; + } + + if (!group) { + /* Unique name. */ + + if( (namerec != NULL) + && ( (namerec->data.source == SELF_NAME) + || (namerec->data.source == PERMANENT_NAME) + || NAME_GROUP(namerec) ) ) { + /* No-one can register one of Samba's names, nor can they + register a name that's a group name as a unique name */ + + send_name_registration_response(ACT_ERR, 0, p); + return; + } else if(namerec != NULL) { + /* Update the namelist record with the new information. */ + namerec->data.ip[0] = from_ip; + update_name_ttl(namerec, ttl); + + DEBUG(3,("process_name_registration_request: Updated name record %s \ with IP %s on subnet %s\n",nmb_namestr(&namerec->name),inet_ntoa(from_ip), subrec->subnet_name)); - return; - } - } - else - { - /* Group name. */ - - if( (namerec != NULL) - && !NAME_GROUP(namerec) - && ( (namerec->data.source == SELF_NAME) - || (namerec->data.source == PERMANENT_NAME) ) ) - { - /* Disallow group names when we have a unique name. */ - send_name_registration_response(ACT_ERR, 0, p); - return; - } - } + return; + } + } else { + /* Group name. */ + + if( (namerec != NULL) + && !NAME_GROUP(namerec) + && ( (namerec->data.source == SELF_NAME) + || (namerec->data.source == PERMANENT_NAME) ) ) { + /* Disallow group names when we have a unique name. */ + send_name_registration_response(ACT_ERR, 0, p); + return; + } + } } /**************************************************************************** @@ -290,147 +275,150 @@ We put our own names first, then in alphabetical order. static int status_compare(char *n1,char *n2) { - int l1,l2,l3; - - /* It's a bit tricky because the names are space padded */ - for (l1=0;l1<15 && n1[l1] && n1[l1] != ' ';l1++) ; - for (l2=0;l2<15 && n2[l2] && n2[l2] != ' ';l2++) ; - l3 = strlen(global_myname()); - - if ((l1==l3) && strncmp(n1,global_myname(),l3) == 0 && - (l2!=l3 || strncmp(n2,global_myname(),l3) != 0)) - return -1; - - if ((l2==l3) && strncmp(n2,global_myname(),l3) == 0 && - (l1!=l3 || strncmp(n1,global_myname(),l3) != 0)) - return 1; - - return memcmp(n1,n2,18); + nstring name1, name2; + int l1,l2,l3; + + pull_ascii_nstring(name1, n1); + pull_ascii_nstring(name2, n2); + n1 = name1; + n2 = name2; + + /* It's a bit tricky because the names are space padded */ + for (l1=0;l1<15 && n1[l1] && n1[l1] != ' ';l1++) + ; + for (l2=0;l2<15 && n2[l2] && n2[l2] != ' ';l2++) + ; + l3 = strlen(global_myname()); + + if ((l1==l3) && strncmp(n1,global_myname(),l3) == 0 && + (l2!=l3 || strncmp(n2,global_myname(),l3) != 0)) + return -1; + + if ((l2==l3) && strncmp(n2,global_myname(),l3) == 0 && + (l1!=l3 || strncmp(n1,global_myname(),l3) != 0)) + return 1; + + return memcmp(n1,n2,sizeof(nstring)); } - /**************************************************************************** Process a node status query ****************************************************************************/ void process_node_status_request(struct subnet_record *subrec, struct packet_struct *p) { - struct nmb_packet *nmb = &p->packet.nmb; - char *qname = nmb->question.question_name.name; - int ques_type = nmb->question.question_name.name_type; - char rdata[MAX_DGRAM_SIZE]; - char *countptr, *buf, *bufend, *buf0; - int names_added,i; - struct name_record *namerec; - - DEBUG(3,("process_node_status_request: status request for name %s from IP %s on \ -subnet %s.\n", nmb_namestr(&nmb->question.question_name), inet_ntoa(p->ip), - subrec->subnet_name)); - - if((namerec = find_name_on_subnet(subrec, &nmb->question.question_name, - FIND_SELF_NAME)) == 0) - { - DEBUG(1,("process_node_status_request: status request for name %s from IP %s on \ + struct nmb_packet *nmb = &p->packet.nmb; + nstring qname; + int ques_type = nmb->question.question_name.name_type; + char rdata[MAX_DGRAM_SIZE]; + char *countptr, *buf, *bufend, *buf0; + int names_added,i; + struct name_record *namerec; + + pull_ascii_nstring(qname, nmb->question.question_name.name); + + DEBUG(3,("process_node_status_request: status request for name %s from IP %s on \ +subnet %s.\n", nmb_namestr(&nmb->question.question_name), inet_ntoa(p->ip), subrec->subnet_name)); + + if((namerec = find_name_on_subnet(subrec, &nmb->question.question_name, FIND_SELF_NAME)) == 0) { + DEBUG(1,("process_node_status_request: status request for name %s from IP %s on \ subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name), - inet_ntoa(p->ip), subrec->subnet_name)); + inet_ntoa(p->ip), subrec->subnet_name)); - return; - } + return; + } - /* this is not an exact calculation. the 46 is for the stats buffer - and the 60 is to leave room for the header etc */ - bufend = &rdata[MAX_DGRAM_SIZE] - (18 + 46 + 60); - countptr = buf = rdata; - buf += 1; - buf0 = buf; - - names_added = 0; - - namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); - - while (buf < bufend) - { - if( (namerec->data.source == SELF_NAME) - || (namerec->data.source == PERMANENT_NAME) ) - { - int name_type = namerec->name.name_type; - - if (!strequal(namerec->name.name,"*") && - !strequal(namerec->name.name,"__SAMBA__") && - (name_type < 0x1b || name_type >= 0x20 || - ques_type < 0x1b || ques_type >= 0x20 || - strequal(qname, namerec->name.name))) - { - /* Start with the name. */ - memset(buf,'\0',18); - slprintf(buf, 17, "%-15.15s",namerec->name.name); - strupper_m(buf); - - /* Put the name type and netbios flags in the buffer. */ - buf[15] = name_type; - set_nb_flags( &buf[16],namerec->data.nb_flags ); - buf[16] |= NB_ACTIVE; /* all our names are active */ - - buf += 18; - - names_added++; - } - } - - /* Remove duplicate names. */ - if (names_added > 1) { - qsort( buf0, names_added, 18, QSORT_CAST status_compare ); - } - - for( i=1; i < names_added ; i++ ) - { - if (memcmp(buf0 + 18*i,buf0 + 18*(i-1),16) == 0) - { - names_added--; - if (names_added == i) - break; - memmove(buf0 + 18*i,buf0 + 18*(i+1),18*(names_added-i)); - i--; - } - } - - buf = buf0 + 18*names_added; - - namerec = (struct name_record *)ubi_trNext( namerec ); - - if (!namerec) - { - /* End of the subnet specific name list. Now - add the names on the unicast subnet . */ - struct subnet_record *uni_subrec = unicast_subnet; - - if (uni_subrec != subrec) - { - subrec = uni_subrec; - namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); - } - } - if (!namerec) - break; - - } + /* this is not an exact calculation. the 46 is for the stats buffer + and the 60 is to leave room for the header etc */ + bufend = &rdata[MAX_DGRAM_SIZE] - (18 + 46 + 60); + countptr = buf = rdata; + buf += 1; + buf0 = buf; + + names_added = 0; + + namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); + + while (buf < bufend) { + if( (namerec->data.source == SELF_NAME) || (namerec->data.source == PERMANENT_NAME) ) { + int name_type = namerec->name.name_type; + nstring name; + + pull_ascii_nstring(name, namerec->name.name); + strupper_m(name); + if (!strequal(name,"*") && + !strequal(name,"__SAMBA__") && + (name_type < 0x1b || name_type >= 0x20 || + ques_type < 0x1b || ques_type >= 0x20 || + strequal(qname, name))) { + /* Start with the name. */ + nstring tmp_name; + memset(tmp_name,'\0',sizeof(tmp_name)); + snprintf(tmp_name, sizeof(tmp_name), "%-15.15s",name); + push_ascii_nstring(buf, tmp_name); + + /* Put the name type and netbios flags in the buffer. */ + + buf[15] = name_type; + set_nb_flags( &buf[16],namerec->data.nb_flags ); + buf[16] |= NB_ACTIVE; /* all our names are active */ + + buf += 18; + + names_added++; + } + } + + /* Remove duplicate names. */ + if (names_added > 1) { + qsort( buf0, names_added, 18, QSORT_CAST status_compare ); + } + + for( i=1; i < names_added ; i++ ) { + if (memcmp(buf0 + 18*i,buf0 + 18*(i-1),16) == 0) { + names_added--; + if (names_added == i) + break; + memmove(buf0 + 18*i,buf0 + 18*(i+1),18*(names_added-i)); + i--; + } + } + + buf = buf0 + 18*names_added; + + namerec = (struct name_record *)ubi_trNext( namerec ); + + if (!namerec) { + /* End of the subnet specific name list. Now + add the names on the unicast subnet . */ + struct subnet_record *uni_subrec = unicast_subnet; + + if (uni_subrec != subrec) { + subrec = uni_subrec; + namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); + } + } + if (!namerec) + break; + + } - SCVAL(countptr,0,names_added); + SCVAL(countptr,0,names_added); - /* We don't send any stats as they could be used to attack - the protocol. */ - memset(buf,'\0',46); + /* We don't send any stats as they could be used to attack + the protocol. */ + memset(buf,'\0',46); - buf += 46; + buf += 46; - /* Send a NODE STATUS RESPONSE */ - reply_netbios_packet(p, /* Packet to reply to. */ - 0, /* Result code. */ - NMB_STATUS, /* nmbd type code. */ - NMB_NAME_QUERY_OPCODE, /* opcode. */ - 0, /* ttl. */ - rdata, /* data to send. */ - PTR_DIFF(buf,rdata)); /* data length. */ + /* Send a NODE STATUS RESPONSE */ + reply_netbios_packet(p, /* Packet to reply to. */ + 0, /* Result code. */ + NMB_STATUS, /* nmbd type code. */ + NMB_NAME_QUERY_OPCODE, /* opcode. */ + 0, /* ttl. */ + rdata, /* data to send. */ + PTR_DIFF(buf,rdata)); /* data length. */ } diff --git a/source3/nmbd/nmbd_lmhosts.c b/source3/nmbd/nmbd_lmhosts.c index 3c067d8ed4..b14e13f3a4 100644 --- a/source3/nmbd/nmbd_lmhosts.c +++ b/source3/nmbd/nmbd_lmhosts.c @@ -28,50 +28,46 @@ /**************************************************************************** Load a lmhosts file. ****************************************************************************/ + void load_lmhosts_file(char *fname) { - pstring name; - int name_type; - struct in_addr ipaddr; - XFILE *fp = startlmhosts( fname ); - - if (!fp) { - DEBUG(2,("load_lmhosts_file: Can't open lmhosts file %s. Error was %s\n", - fname, strerror(errno))); - return; - } + pstring name; + int name_type; + struct in_addr ipaddr; + XFILE *fp = startlmhosts( fname ); + + if (!fp) { + DEBUG(2,("load_lmhosts_file: Can't open lmhosts file %s. Error was %s\n", + fname, strerror(errno))); + return; + } - while (getlmhostsent(fp, name, &name_type, &ipaddr) ) - { - struct subnet_record *subrec = NULL; - enum name_source source = LMHOSTS_NAME; - - /* We find a relevent subnet to put this entry on, then add it. */ - /* Go through all the broadcast subnets and see if the mask matches. */ - for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - { - if(same_net(ipaddr, subrec->bcast_ip, subrec->mask_ip)) - break; - } + while (getlmhostsent(fp, name, &name_type, &ipaddr) ) { + struct subnet_record *subrec = NULL; + enum name_source source = LMHOSTS_NAME; + + /* We find a relevent subnet to put this entry on, then add it. */ + /* Go through all the broadcast subnets and see if the mask matches. */ + for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { + if(same_net(ipaddr, subrec->bcast_ip, subrec->mask_ip)) + break; + } - /* If none match add the name to the remote_broadcast_subnet. */ - if(subrec == NULL) - subrec = remote_broadcast_subnet; - - if(name_type == -1) - { - /* Add the (0) and (0x20) names directly into the namelist for this subnet. */ - (void)add_name_to_subnet(subrec,name,0x00,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr); - (void)add_name_to_subnet(subrec,name,0x20,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr); - } - else - { - /* Add the given name type to the subnet namelist. */ - (void)add_name_to_subnet(subrec,name,name_type,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr); - } - } + /* If none match add the name to the remote_broadcast_subnet. */ + if(subrec == NULL) + subrec = remote_broadcast_subnet; + + if(name_type == -1) { + /* Add the (0) and (0x20) names directly into the namelist for this subnet. */ + (void)add_name_to_subnet(subrec,name,0x00,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr); + (void)add_name_to_subnet(subrec,name,0x20,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr); + } else { + /* Add the given name type to the subnet namelist. */ + (void)add_name_to_subnet(subrec,name,name_type,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr); + } + } - endlmhosts(fp); + endlmhosts(fp); } /**************************************************************************** @@ -82,17 +78,16 @@ void load_lmhosts_file(char *fname) BOOL find_name_in_lmhosts(struct nmb_name *nmbname, struct name_record **namerecp) { - struct name_record *namerec; + struct name_record *namerec; - *namerecp = NULL; + *namerecp = NULL; - if((namerec = find_name_on_subnet(remote_broadcast_subnet, nmbname, - FIND_ANY_NAME))==NULL) - return False; + if((namerec = find_name_on_subnet(remote_broadcast_subnet, nmbname, FIND_ANY_NAME))==NULL) + return False; - if(!NAME_IS_ACTIVE(namerec) || (namerec->data.source != LMHOSTS_NAME)) - return False; + if(!NAME_IS_ACTIVE(namerec) || (namerec->data.source != LMHOSTS_NAME)) + return False; - *namerecp = namerec; - return True; + *namerecp = namerec; + return True; } diff --git a/source3/nmbd/nmbd_logonnames.c b/source3/nmbd/nmbd_logonnames.c index b73586aa45..f79fc56f7b 100644 --- a/source3/nmbd/nmbd_logonnames.c +++ b/source3/nmbd/nmbd_logonnames.c @@ -3,7 +3,7 @@ NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 - Copyright (C) Jeremy Allison 1994-1998 + Copyright (C) Jeremy Allison 1994-2003 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -29,38 +29,40 @@ extern uint16 samba_nb_type; /* Samba's NetBIOS type. */ /**************************************************************************** Fail to become a Logon server on a subnet. - ****************************************************************************/ +****************************************************************************/ + static void become_logon_server_fail(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *fail_name) { - struct work_record *work = find_workgroup_on_subnet(subrec, fail_name->name); - struct server_record *servrec; - - if(!work) - { - DEBUG(0,("become_logon_server_fail: Error - cannot find \ -workgroup %s on subnet %s\n", fail_name->name, subrec->subnet_name)); - return; - } - - if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) - { - DEBUG(0,("become_logon_server_fail: Error - cannot find server %s \ + nstring failname; + struct work_record *work; + struct server_record *servrec; + + pull_ascii_nstring(failname, fail_name->name); + work = find_workgroup_on_subnet(subrec, failname); + if(!work) { + DEBUG(0,("become_logon_server_fail: Error - cannot find \ +workgroup %s on subnet %s\n", failname, subrec->subnet_name)); + return; + } + + if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) { + DEBUG(0,("become_logon_server_fail: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - global_myname(), fail_name->name, subrec->subnet_name)); - work->log_state = LOGON_NONE; - return; - } + global_myname(), failname, subrec->subnet_name)); + work->log_state = LOGON_NONE; + return; + } - /* Set the state back to LOGON_NONE. */ - work->log_state = LOGON_NONE; + /* Set the state back to LOGON_NONE. */ + work->log_state = LOGON_NONE; - servrec->serv.type &= ~SV_TYPE_DOMAIN_CTRL; + servrec->serv.type &= ~SV_TYPE_DOMAIN_CTRL; - DEBUG(0,("become_logon_server_fail: Failed to become a domain master for \ + DEBUG(0,("become_logon_server_fail: Failed to become a domain master for \ workgroup %s on subnet %s. Couldn't register name %s.\n", - work->work_group, subrec->subnet_name, nmb_namestr(fail_name))); + work->work_group, subrec->subnet_name, nmb_namestr(fail_name))); } @@ -74,49 +76,51 @@ static void become_logon_server_success(struct subnet_record *subrec, uint16 nb_flags, int ttl, struct in_addr registered_ip) { - struct work_record *work = find_workgroup_on_subnet( subrec, registered_name->name); - struct server_record *servrec; - - if(!work) - { - DEBUG(0,("become_logon_server_success: Error - cannot find \ -workgroup %s on subnet %s\n", registered_name->name, subrec->subnet_name)); - return; - } - - if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) - { - DEBUG(0,("become_logon_server_success: Error - cannot find server %s \ + nstring reg_name; + struct work_record *work; + struct server_record *servrec; + + pull_ascii_nstring(reg_name, registered_name->name); + work = find_workgroup_on_subnet( subrec, reg_name); + if(!work) { + DEBUG(0,("become_logon_server_success: Error - cannot find \ +workgroup %s on subnet %s\n", reg_name, subrec->subnet_name)); + return; + } + + if((servrec = find_server_in_workgroup( work, global_myname())) == NULL) { + DEBUG(0,("become_logon_server_success: Error - cannot find server %s \ in workgroup %s on subnet %s\n", - global_myname(), registered_name->name, subrec->subnet_name)); - work->log_state = LOGON_NONE; - return; - } - - /* Set the state in the workgroup structure. */ - work->log_state = LOGON_SRV; /* Become domain master. */ - - /* Update our server status. */ - servrec->serv.type |= (SV_TYPE_NT|SV_TYPE_DOMAIN_MEMBER); - /* To allow Win95 policies to load we need to set type domain - controller. - */ - servrec->serv.type |= SV_TYPE_DOMAIN_CTRL; - - /* Tell the namelist writer to write out a change. */ - subrec->work_changed = True; - - /* - * Add the WORKGROUP<1C> name to the UNICAST subnet with the IP address - * for this subnet so we will respond to queries on this name. - */ - { - struct nmb_name nmbname; - make_nmb_name(&nmbname,lp_workgroup(),0x1c); - insert_permanent_name_into_unicast(subrec, &nmbname, 0x1c); - } - - DEBUG(0,("become_logon_server_success: Samba is now a logon server \ + global_myname(), reg_name, subrec->subnet_name)); + work->log_state = LOGON_NONE; + return; + } + + /* Set the state in the workgroup structure. */ + work->log_state = LOGON_SRV; /* Become domain master. */ + + /* Update our server status. */ + servrec->serv.type |= (SV_TYPE_NT|SV_TYPE_DOMAIN_MEMBER); + /* To allow Win95 policies to load we need to set type domain + controller. + */ + servrec->serv.type |= SV_TYPE_DOMAIN_CTRL; + + /* Tell the namelist writer to write out a change. */ + subrec->work_changed = True; + + /* + * Add the WORKGROUP<1C> name to the UNICAST subnet with the IP address + * for this subnet so we will respond to queries on this name. + */ + + { + struct nmb_name nmbname; + make_nmb_name(&nmbname,lp_workgroup(),0x1c); + insert_permanent_name_into_unicast(subrec, &nmbname, 0x1c); + } + + DEBUG(0,("become_logon_server_success: Samba is now a logon server \ for workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name)); } @@ -128,45 +132,42 @@ for workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name)); static void become_logon_server(struct subnet_record *subrec, struct work_record *work) { - DEBUG(2,("become_logon_server: Atempting to become logon server for workgroup %s \ + DEBUG(2,("become_logon_server: Atempting to become logon server for workgroup %s \ on subnet %s\n", work->work_group,subrec->subnet_name)); - DEBUG(3,("become_logon_server: go to first stage: register %s<1c> name\n", - work->work_group)); - work->log_state = LOGON_WAIT; + DEBUG(3,("become_logon_server: go to first stage: register %s<1c> name\n", + work->work_group)); + work->log_state = LOGON_WAIT; - register_name(subrec, work->work_group,0x1c,samba_nb_type|NB_GROUP, - become_logon_server_success, - become_logon_server_fail, NULL); + register_name(subrec, work->work_group,0x1c,samba_nb_type|NB_GROUP, + become_logon_server_success, + become_logon_server_fail, NULL); } /***************************************************************************** Add the internet group <1c> logon names by unicast and broadcast. ****************************************************************************/ + void add_logon_names(void) { - struct subnet_record *subrec; - - for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) - { - struct work_record *work = find_workgroup_on_subnet(subrec, lp_workgroup()); - - if (work && (work->log_state == LOGON_NONE)) - { - struct nmb_name nmbname; - make_nmb_name(&nmbname,lp_workgroup(),0x1c); - - if (find_name_on_subnet(subrec, &nmbname, FIND_SELF_NAME) == NULL) - { - if( DEBUGLVL( 0 ) ) - { - dbgtext( "add_domain_logon_names:\n" ); - dbgtext( "Attempting to become logon server " ); - dbgtext( "for workgroup %s ", lp_workgroup() ); - dbgtext( "on subnet %s\n", subrec->subnet_name ); - } - become_logon_server(subrec, work); - } - } - } + struct subnet_record *subrec; + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { + struct work_record *work = find_workgroup_on_subnet(subrec, lp_workgroup()); + + if (work && (work->log_state == LOGON_NONE)) { + struct nmb_name nmbname; + make_nmb_name(&nmbname,lp_workgroup(),0x1c); + + if (find_name_on_subnet(subrec, &nmbname, FIND_SELF_NAME) == NULL) { + if( DEBUGLVL( 0 ) ) { + dbgtext( "add_domain_logon_names:\n" ); + dbgtext( "Attempting to become logon server " ); + dbgtext( "for workgroup %s ", lp_workgroup() ); + dbgtext( "on subnet %s\n", subrec->subnet_name ); + } + become_logon_server(subrec, work); + } + } + } } diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index dd66821839..f02fbe1640 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -3,7 +3,7 @@ NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 - Copyright (C) Jeremy Allison 1994-1998 + Copyright (C) Jeremy Allison 1994-2003 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -27,20 +27,21 @@ extern uint16 samba_nb_type; /* Samba's NetBIOS type. */ /**************************************************************************** Fail funtion when registering my netbios names. - **************************************************************************/ +**************************************************************************/ static void my_name_register_failed(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *nmbname) { - DEBUG(0,("my_name_register_failed: Failed to register my name %s on subnet %s.\n", - nmb_namestr(nmbname), subrec->subnet_name)); + DEBUG(0,("my_name_register_failed: Failed to register my name %s on subnet %s.\n", + nmb_namestr(nmbname), subrec->subnet_name)); } /**************************************************************************** Add my workgroup and my given names to one subnet Also add the magic Samba names. - **************************************************************************/ +**************************************************************************/ + void register_my_workgroup_one_subnet(struct subnet_record *subrec) { int i; @@ -84,111 +85,104 @@ Exiting.\n", lp_workgroup(), subrec->subnet_name)); static void insert_refresh_name_into_unicast( struct subnet_record *subrec, struct nmb_name *nmbname, uint16 nb_type ) { - struct name_record *namerec; - - if (!we_are_a_wins_client()) { - insert_permanent_name_into_unicast(subrec, nmbname, nb_type); - return; - } - - if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) == NULL) - { - /* The name needs to be created on the unicast subnet. */ - (void)add_name_to_subnet( unicast_subnet, nmbname->name, - nmbname->name_type, nb_type, - MIN(lp_max_ttl(), MAX_REFRESH_TIME), SELF_NAME, 1, &subrec->myip); - } - else - { - /* The name already exists on the unicast subnet. Add our local - IP for the given broadcast subnet to the name. */ - add_ip_to_name_record( namerec, subrec->myip); - } + struct name_record *namerec; + + if (!we_are_a_wins_client()) { + insert_permanent_name_into_unicast(subrec, nmbname, nb_type); + return; + } + + if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) == NULL) { + nstring name; + pull_ascii_nstring(name, nmbname->name); + /* The name needs to be created on the unicast subnet. */ + (void)add_name_to_subnet( unicast_subnet, name, + nmbname->name_type, nb_type, + MIN(lp_max_ttl(), MAX_REFRESH_TIME), SELF_NAME, 1, &subrec->myip); + } else { + /* The name already exists on the unicast subnet. Add our local + IP for the given broadcast subnet to the name. */ + add_ip_to_name_record( namerec, subrec->myip); + } } /**************************************************************************** Add my workgroup and my given names to the subnet lists. Also add the magic Samba names. - **************************************************************************/ +**************************************************************************/ BOOL register_my_workgroup_and_names(void) { - struct subnet_record *subrec; - int i; - - for(subrec = FIRST_SUBNET; - subrec; - subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) - { - register_my_workgroup_one_subnet(subrec); - } - - /* We still need to add the magic Samba - names and the netbios names to the unicast subnet directly. This is - to allow unicast node status requests and queries to still work - in a broadcast only environment. */ - - add_samba_names_to_subnet(unicast_subnet); - - for (i=0; my_netbios_names(i); i++) - { - for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - { - /* - * Ensure all the IP addresses are added if we are multihomed. - */ - struct nmb_name nmbname; - - make_nmb_name(&nmbname, my_netbios_names(i),0x20); - insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type); - - make_nmb_name(&nmbname, my_netbios_names(i),0x3); - insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type); - - make_nmb_name(&nmbname, my_netbios_names(i),0x0); - insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type); - } - } - - /* - * Add the WORKGROUP<0> and WORKGROUP<1e> group names to the unicast subnet - * also for the same reasons. - */ - - for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - { - /* - * Ensure all the IP addresses are added if we are multihomed. - */ - struct nmb_name nmbname; - - make_nmb_name(&nmbname, lp_workgroup(), 0x0); - insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP); - - make_nmb_name(&nmbname, lp_workgroup(), 0x1e); - insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP); - } - - /* - * We need to add the Samba names to the remote broadcast subnet, - * as NT 4.x does directed broadcast requests to the *<0x0> name. - */ - add_samba_names_to_subnet(remote_broadcast_subnet); - - return True; + struct subnet_record *subrec; + int i; + + for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { + register_my_workgroup_one_subnet(subrec); + } + + /* We still need to add the magic Samba + names and the netbios names to the unicast subnet directly. This is + to allow unicast node status requests and queries to still work + in a broadcast only environment. */ + + add_samba_names_to_subnet(unicast_subnet); + + for (i=0; my_netbios_names(i); i++) { + for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { + /* + * Ensure all the IP addresses are added if we are multihomed. + */ + struct nmb_name nmbname; + + make_nmb_name(&nmbname, my_netbios_names(i),0x20); + insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type); + + make_nmb_name(&nmbname, my_netbios_names(i),0x3); + insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type); + + make_nmb_name(&nmbname, my_netbios_names(i),0x0); + insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type); + } + } + + /* + * Add the WORKGROUP<0> and WORKGROUP<1e> group names to the unicast subnet + * also for the same reasons. + */ + + for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { + /* + * Ensure all the IP addresses are added if we are multihomed. + */ + struct nmb_name nmbname; + + make_nmb_name(&nmbname, lp_workgroup(), 0x0); + insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP); + + make_nmb_name(&nmbname, lp_workgroup(), 0x1e); + insert_refresh_name_into_unicast(subrec, &nmbname, samba_nb_type|NB_GROUP); + } + + /* + * We need to add the Samba names to the remote broadcast subnet, + * as NT 4.x does directed broadcast requests to the *<0x0> name. + */ + + add_samba_names_to_subnet(remote_broadcast_subnet); + + return True; } /**************************************************************************** Remove all the names we registered. **************************************************************************/ + void release_wins_names(void) { struct subnet_record *subrec = unicast_subnet; struct name_record *namerec, *nextnamerec; - for (namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); - namerec; - namerec = nextnamerec) { + for (namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); namerec; namerec = nextnamerec) { nextnamerec = (struct name_record *)ubi_trNext( namerec ); if( (namerec->data.source == SELF_NAME) && !NAME_IS_DEREGISTERING(namerec) ) @@ -199,12 +193,14 @@ void release_wins_names(void) /******************************************************************* Refresh our registered names with WINS - ******************************************************************/ +******************************************************************/ + void refresh_my_names(time_t t) { struct name_record *namerec; - if (wins_srv_count() < 1) return; + if (wins_srv_count() < 1) + return; for (namerec = (struct name_record *)ubi_trFirst(unicast_subnet->namelist); namerec; diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 3f6d2f3b64..d1c9afd608 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -3,7 +3,7 @@ NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 - Copyright (C) Jeremy Allison 1994-1998 + Copyright (C) Jeremy Allison 1994-2003 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,152 +26,149 @@ uint16 samba_nb_type = 0; /* samba's NetBIOS name type */ -/* ************************************************************************** ** - * Set Samba's NetBIOS name type. - * ************************************************************************** ** - */ +/************************************************************************** + Set Samba's NetBIOS name type. +***************************************************************************/ + void set_samba_nb_type(void) - { - if( lp_wins_support() || wins_srv_count() ) - samba_nb_type = NB_HFLAG; /* samba is a 'hybrid' node type. */ - else - samba_nb_type = NB_BFLAG; /* samba is broadcast-only node type. */ - } /* set_samba_nb_type */ - -/* ************************************************************************** ** - * Convert a NetBIOS name to upper case. - * ************************************************************************** ** - */ +{ + if( lp_wins_support() || wins_srv_count() ) + samba_nb_type = NB_HFLAG; /* samba is a 'hybrid' node type. */ + else + samba_nb_type = NB_BFLAG; /* samba is broadcast-only node type. */ +} + +/*************************************************************************** + Convert a NetBIOS name to upper case. +***************************************************************************/ + static void upcase_name( struct nmb_name *target, struct nmb_name *source ) - { - int i; - - if( NULL != source ) - (void)memcpy( target, source, sizeof( struct nmb_name ) ); - - strupper_m( target->name ); - strupper_m( target->scope ); - - /* fudge... We're using a byte-by-byte compare, so we must be sure that - * unused space doesn't have garbage in it. - */ - for( i = strlen( target->name ); i < sizeof( target->name ); i++ ) - target->name[i] = '\0'; - for( i = strlen( target->scope ); i < sizeof( target->scope ); i++ ) - target->scope[i] = '\0'; - } /* upcase_name */ - -/* ************************************************************************** ** - * Add a new or overwrite an existing namelist entry. - * ************************************************************************** ** - */ +{ + int i; + nstring targ; + fstring scope; + + if( NULL != source ) + memcpy( target, source, sizeof( struct nmb_name ) ); + + pull_ascii_nstring(targ, target->name); + strupper_m( targ ); + push_ascii_nstring( target->name, targ); + + pull_ascii(scope, target->scope, 64, -1, STR_TERMINATE); + strupper_m( scope ); + push_ascii(target->scope, scope, 64, STR_TERMINATE); + + /* fudge... We're using a byte-by-byte compare, so we must be sure that + * unused space doesn't have garbage in it. + */ + + for( i = strlen( target->name ); i < sizeof( target->name ); i++ ) + target->name[i] = '\0'; + for( i = strlen( target->scope ); i < sizeof( target->scope ); i++ ) + target->scope[i] = '\0'; +} + +/************************************************************************** + Add a new or overwrite an existing namelist entry. +***************************************************************************/ + static void update_name_in_namelist( struct subnet_record *subrec, struct name_record *namerec ) - { - struct name_record *oldrec = NULL; - - (void)ubi_trInsert( subrec->namelist, namerec, &(namerec->name), &oldrec ); - if( oldrec ) - { - SAFE_FREE( oldrec->data.ip ); - SAFE_FREE( oldrec ); - } - } /* update_name_in_namelist */ - -/* ************************************************************************** ** - * Remove a name from the namelist. - * ************************************************************************** ** - */ -void remove_name_from_namelist( struct subnet_record *subrec, - struct name_record *namerec ) - { - (void)ubi_trRemove( subrec->namelist, namerec ); +{ + struct name_record *oldrec = NULL; - SAFE_FREE(namerec->data.ip); + ubi_trInsert( subrec->namelist, namerec, &(namerec->name), &oldrec ); + if( oldrec ) { + SAFE_FREE( oldrec->data.ip ); + SAFE_FREE( oldrec ); + } +} - ZERO_STRUCTP(namerec); - SAFE_FREE(namerec); +/************************************************************************** + Remove a name from the namelist. +***************************************************************************/ + +void remove_name_from_namelist( struct subnet_record *subrec, + struct name_record *namerec ) +{ + ubi_trRemove( subrec->namelist, namerec ); + SAFE_FREE(namerec->data.ip); + ZERO_STRUCTP(namerec); + SAFE_FREE(namerec); + subrec->namelist_changed = True; +} - subrec->namelist_changed = True; - } /* remove_name_from_namelist */ +/************************************************************************** + Find a name in a subnet. +**************************************************************************/ -/* ************************************************************************** ** - * Find a name in a subnet. - * ************************************************************************** ** - */ struct name_record *find_name_on_subnet( struct subnet_record *subrec, struct nmb_name *nmbname, BOOL self_only ) - { - struct nmb_name uc_name[1]; - struct name_record *name_ret; - - upcase_name( uc_name, nmbname ); - name_ret = (struct name_record *)ubi_trFind( subrec->namelist, uc_name ); - if( name_ret ) - { - /* Self names only - these include permanent names. */ - if( self_only - && (name_ret->data.source != SELF_NAME) - && (name_ret->data.source != PERMANENT_NAME) ) - { - DEBUG( 9, - ( "find_name_on_subnet: on subnet %s - self name %s NOT FOUND\n", - subrec->subnet_name, nmb_namestr(nmbname) ) ); - return( NULL ); - } - DEBUG( 9, ("find_name_on_subnet: on subnet %s - found name %s source=%d\n", - subrec->subnet_name, nmb_namestr(nmbname), name_ret->data.source) ); - return( name_ret ); - } - DEBUG( 9, - ( "find_name_on_subnet: on subnet %s - name %s NOT FOUND\n", - subrec->subnet_name, nmb_namestr(nmbname) ) ); - return( NULL ); - } /* find_name_on_subnet */ - -/* ************************************************************************** ** - * Find a name over all known broadcast subnets. - * ************************************************************************** ** - */ +{ + struct nmb_name uc_name[1]; + struct name_record *name_ret; + + upcase_name( uc_name, nmbname ); + name_ret = (struct name_record *)ubi_trFind( subrec->namelist, uc_name ); + if( name_ret ) { + /* Self names only - these include permanent names. */ + if( self_only && (name_ret->data.source != SELF_NAME) && (name_ret->data.source != PERMANENT_NAME) ) { + DEBUG( 9, ( "find_name_on_subnet: on subnet %s - self name %s NOT FOUND\n", + subrec->subnet_name, nmb_namestr(nmbname) ) ); + return( NULL ); + } + + DEBUG( 9, ("find_name_on_subnet: on subnet %s - found name %s source=%d\n", + subrec->subnet_name, nmb_namestr(nmbname), name_ret->data.source) ); + return( name_ret ); + } + + DEBUG( 9, ( "find_name_on_subnet: on subnet %s - name %s NOT FOUND\n", + subrec->subnet_name, nmb_namestr(nmbname) ) ); + return( NULL ); +} + +/************************************************************************** + Find a name over all known broadcast subnets. +************************************************************************/ + struct name_record *find_name_for_remote_broadcast_subnet( struct nmb_name *nmbname, BOOL self_only ) - { - struct subnet_record *subrec; - struct name_record *namerec = NULL; - - for( subrec = FIRST_SUBNET; - subrec; - subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) ) - { - if( NULL != (namerec = find_name_on_subnet(subrec, nmbname, self_only)) ) - break; - } - - return( namerec ); - } /* find_name_for_remote_broadcast_subnet */ +{ + struct subnet_record *subrec; + struct name_record *namerec = NULL; + + for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) ) { + if( NULL != (namerec = find_name_on_subnet(subrec, nmbname, self_only)) ) + break; + } + + return( namerec ); +} -/* ************************************************************************** ** - * Update the ttl of an entry in a subnet name list. - * ************************************************************************** ** - */ +/************************************************************************** + Update the ttl of an entry in a subnet name list. +***************************************************************************/ + void update_name_ttl( struct name_record *namerec, int ttl ) { - time_t time_now = time(NULL); + time_t time_now = time(NULL); - if( namerec->data.death_time != PERMANENT_TTL ) - namerec->data.death_time = time_now + ttl; + if( namerec->data.death_time != PERMANENT_TTL ) + namerec->data.death_time = time_now + ttl; - namerec->data.refresh_time = time_now + MIN((ttl/2), MAX_REFRESH_TIME); + namerec->data.refresh_time = time_now + MIN((ttl/2), MAX_REFRESH_TIME); + + namerec->subnet->namelist_changed = True; +} - namerec->subnet->namelist_changed = True; -} /* update_name_ttl */ +/************************************************************************** + Add an entry to a subnet name list. +***********************************************************************/ -/* ************************************************************************** ** - * Add an entry to a subnet name list. - * ************************************************************************** ** - */ struct name_record *add_name_to_subnet( struct subnet_record *subrec, const char *name, int type, @@ -181,70 +178,66 @@ struct name_record *add_name_to_subnet( struct subnet_record *subrec, int num_ips, struct in_addr *iplist) { - struct name_record *namerec; - time_t time_now = time(NULL); + struct name_record *namerec; + time_t time_now = time(NULL); - namerec = (struct name_record *)malloc( sizeof(*namerec) ); - if( NULL == namerec ) - { - DEBUG( 0, ( "add_name_to_subnet: malloc fail.\n" ) ); - return( NULL ); - } + namerec = (struct name_record *)malloc( sizeof(*namerec) ); + if( NULL == namerec ) { + DEBUG( 0, ( "add_name_to_subnet: malloc fail.\n" ) ); + return( NULL ); + } - memset( (char *)namerec, '\0', sizeof(*namerec) ); - namerec->data.ip = (struct in_addr *)malloc( sizeof(struct in_addr) - * num_ips ); - if( NULL == namerec->data.ip ) - { - DEBUG( 0, ( "add_name_to_subnet: malloc fail when creating ip_flgs.\n" ) ); + memset( (char *)namerec, '\0', sizeof(*namerec) ); + namerec->data.ip = (struct in_addr *)malloc( sizeof(struct in_addr) * num_ips ); + if( NULL == namerec->data.ip ) { + DEBUG( 0, ( "add_name_to_subnet: malloc fail when creating ip_flgs.\n" ) ); + ZERO_STRUCTP(namerec); + SAFE_FREE(namerec); + return NULL; + } - ZERO_STRUCTP(namerec); - SAFE_FREE(namerec); - return NULL; - } + namerec->subnet = subrec; - namerec->subnet = subrec; + make_nmb_name(&namerec->name, name, type); + upcase_name(&namerec->name, NULL ); - make_nmb_name(&namerec->name, name, type); - upcase_name(&namerec->name, NULL ); + /* Enter the name as active. */ + namerec->data.nb_flags = nb_flags | NB_ACTIVE; + namerec->data.wins_flags = WINS_ACTIVE; - /* Enter the name as active. */ - namerec->data.nb_flags = nb_flags | NB_ACTIVE; - namerec->data.wins_flags = WINS_ACTIVE; + /* If it's our primary name, flag it as so. */ + if( strequal( my_netbios_names(0), name ) ) + namerec->data.nb_flags |= NB_PERM; - /* If it's our primary name, flag it as so. */ - if( strequal( my_netbios_names(0), name ) ) - namerec->data.nb_flags |= NB_PERM; + /* Copy the IPs. */ + namerec->data.num_ips = num_ips; + memcpy( (namerec->data.ip), iplist, num_ips * sizeof(struct in_addr) ); - /* Copy the IPs. */ - namerec->data.num_ips = num_ips; - memcpy( (namerec->data.ip), iplist, num_ips * sizeof(struct in_addr) ); + /* Data source. */ + namerec->data.source = source; - /* Data source. */ - namerec->data.source = source; + /* Setup the death_time and refresh_time. */ + if( ttl == PERMANENT_TTL ) + namerec->data.death_time = PERMANENT_TTL; + else + namerec->data.death_time = time_now + ttl; - /* Setup the death_time and refresh_time. */ - if( ttl == PERMANENT_TTL ) - namerec->data.death_time = PERMANENT_TTL; - else - namerec->data.death_time = time_now + ttl; + namerec->data.refresh_time = time_now + MIN((ttl/2), MAX_REFRESH_TIME); - namerec->data.refresh_time = time_now + MIN((ttl/2), MAX_REFRESH_TIME); + /* Now add the record to the name list. */ + update_name_in_namelist( subrec, namerec ); - /* Now add the record to the name list. */ - update_name_in_namelist( subrec, namerec ); - - DEBUG( 3, ( "add_name_to_subnet: Added netbios name %s with first IP %s \ + DEBUG( 3, ( "add_name_to_subnet: Added netbios name %s with first IP %s \ ttl=%d nb_flags=%2x to subnet %s\n", - nmb_namestr( &namerec->name ), - inet_ntoa( *iplist ), - ttl, - (unsigned int)nb_flags, - subrec->subnet_name ) ); + nmb_namestr( &namerec->name ), + inet_ntoa( *iplist ), + ttl, + (unsigned int)nb_flags, + subrec->subnet_name ) ); - subrec->namelist_changed = True; + subrec->namelist_changed = True; - return(namerec); + return(namerec); } /******************************************************************* @@ -258,14 +251,17 @@ void standard_success_register(struct subnet_record *subrec, struct nmb_name *nmbname, uint16 nb_flags, int ttl, struct in_addr registered_ip) { - struct name_record *namerec; - - namerec = find_name_on_subnet( subrec, nmbname, FIND_SELF_NAME ); - if( NULL == namerec ) - (void)add_name_to_subnet( subrec, nmbname->name, nmbname->name_type, - nb_flags, ttl, SELF_NAME, 1, ®istered_ip ); - else - update_name_ttl( namerec, ttl ); + struct name_record *namerec; + + namerec = find_name_on_subnet( subrec, nmbname, FIND_SELF_NAME ); + if( NULL == namerec ) { + nstring name; + pull_ascii_nstring(name, nmbname->name); + add_name_to_subnet( subrec, name, nmbname->name_type, + nb_flags, ttl, SELF_NAME, 1, ®istered_ip ); + } else { + update_name_ttl( namerec, ttl ); + } } /******************************************************************* @@ -279,17 +275,16 @@ void standard_fail_register( struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *nmbname ) { - struct name_record *namerec; + struct name_record *namerec; - namerec = find_name_on_subnet( subrec, nmbname, FIND_SELF_NAME ); + namerec = find_name_on_subnet( subrec, nmbname, FIND_SELF_NAME ); - DEBUG( 0, ( "standard_fail_register: Failed to register/refresh name %s \ -on subnet %s\n", - nmb_namestr(nmbname), subrec->subnet_name) ); + DEBUG( 0, ( "standard_fail_register: Failed to register/refresh name %s \ +on subnet %s\n", nmb_namestr(nmbname), subrec->subnet_name) ); - /* Remove the name from the subnet. */ - if( namerec ) - remove_name_from_namelist(subrec, namerec); + /* Remove the name from the subnet. */ + if( namerec ) + remove_name_from_namelist(subrec, namerec); } /******************************************************************* @@ -298,13 +293,13 @@ on subnet %s\n", static void remove_nth_ip_in_record( struct name_record *namerec, int ind) { - if( ind != namerec->data.num_ips ) - memmove( (char *)(&namerec->data.ip[ind]), - (char *)(&namerec->data.ip[ind+1]), - ( namerec->data.num_ips - ind - 1) * sizeof(struct in_addr) ); + if( ind != namerec->data.num_ips ) + memmove( (char *)(&namerec->data.ip[ind]), + (char *)(&namerec->data.ip[ind+1]), + ( namerec->data.num_ips - ind - 1) * sizeof(struct in_addr) ); - namerec->data.num_ips--; - namerec->subnet->namelist_changed = True; + namerec->data.num_ips--; + namerec->subnet->namelist_changed = True; } /******************************************************************* @@ -313,13 +308,13 @@ static void remove_nth_ip_in_record( struct name_record *namerec, int ind) BOOL find_ip_in_name_record( struct name_record *namerec, struct in_addr ip ) { - int i; + int i; - for(i = 0; i < namerec->data.num_ips; i++) - if(ip_equal( namerec->data.ip[i], ip)) - return True; + for(i = 0; i < namerec->data.num_ips; i++) + if(ip_equal( namerec->data.ip[i], ip)) + return True; - return False; + return False; } /******************************************************************* @@ -328,30 +323,26 @@ BOOL find_ip_in_name_record( struct name_record *namerec, struct in_addr ip ) void add_ip_to_name_record( struct name_record *namerec, struct in_addr new_ip ) { - struct in_addr *new_list; + struct in_addr *new_list; - /* Don't add one we already have. */ - if( find_ip_in_name_record( namerec, new_ip ) ) - return; + /* Don't add one we already have. */ + if( find_ip_in_name_record( namerec, new_ip ) ) + return; - new_list = (struct in_addr *)malloc( (namerec->data.num_ips + 1) - * sizeof(struct in_addr) ); - if( NULL == new_list ) - { - DEBUG(0,("add_ip_to_name_record: Malloc fail !\n")); - return; - } - - memcpy( (char *)new_list, - (char *)namerec->data.ip, - namerec->data.num_ips * sizeof(struct in_addr) ); - new_list[namerec->data.num_ips] = new_ip; - - SAFE_FREE(namerec->data.ip); - namerec->data.ip = new_list; - namerec->data.num_ips += 1; - - namerec->subnet->namelist_changed = True; + new_list = (struct in_addr *)malloc( (namerec->data.num_ips + 1) * sizeof(struct in_addr) ); + if( NULL == new_list ) { + DEBUG(0,("add_ip_to_name_record: Malloc fail !\n")); + return; + } + + memcpy( (char *)new_list, (char *)namerec->data.ip, namerec->data.num_ips * sizeof(struct in_addr) ); + new_list[namerec->data.num_ips] = new_ip; + + SAFE_FREE(namerec->data.ip); + namerec->data.ip = new_list; + namerec->data.num_ips += 1; + + namerec->subnet->namelist_changed = True; } /******************************************************************* @@ -361,16 +352,16 @@ void add_ip_to_name_record( struct name_record *namerec, struct in_addr new_ip ) void remove_ip_from_name_record( struct name_record *namerec, struct in_addr remove_ip ) { - /* Try and find the requested ip address - remove it. */ - int i; - int orig_num = namerec->data.num_ips; - - for(i = 0; i < orig_num; i++) - if( ip_equal( remove_ip, namerec->data.ip[i]) ) - { - remove_nth_ip_in_record( namerec, i); - break; - } + /* Try and find the requested ip address - remove it. */ + int i; + int orig_num = namerec->data.num_ips; + + for(i = 0; i < orig_num; i++) { + if( ip_equal( remove_ip, namerec->data.ip[i]) ) { + remove_nth_ip_in_record( namerec, i); + break; + } + } } /******************************************************************* @@ -384,85 +375,67 @@ void standard_success_release( struct subnet_record *subrec, struct nmb_name *nmbname, struct in_addr released_ip ) { - struct name_record *namerec; - - namerec = find_name_on_subnet( subrec, nmbname, FIND_ANY_NAME ); - - if( namerec == NULL ) - { - DEBUG( 0, ( "standard_success_release: Name release for name %s IP %s \ -on subnet %s. Name was not found on subnet.\n", - nmb_namestr(nmbname), - inet_ntoa(released_ip), - subrec->subnet_name) ); - return; - } - else - { - int orig_num = namerec->data.num_ips; - - remove_ip_from_name_record( namerec, released_ip ); - - if( namerec->data.num_ips == orig_num ) - DEBUG( 0, ( "standard_success_release: Name release for name %s IP %s \ -on subnet %s. This ip is not known for this name.\n", - nmb_namestr(nmbname), - inet_ntoa(released_ip), - subrec->subnet_name ) ); - } - - if( namerec->data.num_ips == 0 ) - remove_name_from_namelist( subrec, namerec ); + struct name_record *namerec; + + namerec = find_name_on_subnet( subrec, nmbname, FIND_ANY_NAME ); + if( namerec == NULL ) { + DEBUG( 0, ( "standard_success_release: Name release for name %s IP %s \ +on subnet %s. Name was not found on subnet.\n", nmb_namestr(nmbname), inet_ntoa(released_ip), + subrec->subnet_name) ); + return; + } else { + int orig_num = namerec->data.num_ips; + + remove_ip_from_name_record( namerec, released_ip ); + + if( namerec->data.num_ips == orig_num ) + DEBUG( 0, ( "standard_success_release: Name release for name %s IP %s \ +on subnet %s. This ip is not known for this name.\n", nmb_namestr(nmbname), inet_ntoa(released_ip), subrec->subnet_name ) ); + } + + if( namerec->data.num_ips == 0 ) + remove_name_from_namelist( subrec, namerec ); } /******************************************************************* Expires old names in a subnet namelist. - ******************************************************************/ +******************************************************************/ void expire_names_on_subnet(struct subnet_record *subrec, time_t t) { - struct name_record *namerec; - struct name_record *next_namerec; - - for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); - namerec; - namerec = next_namerec ) - { - next_namerec = (struct name_record *)ubi_trNext( namerec ); - if( (namerec->data.death_time != PERMANENT_TTL) - && (namerec->data.death_time < t) ) - { - if( namerec->data.source == SELF_NAME ) - { - DEBUG( 3, ( "expire_names_on_subnet: Subnet %s not expiring SELF \ -name %s\n", - subrec->subnet_name, nmb_namestr(&namerec->name) ) ); - namerec->data.death_time += 300; - namerec->subnet->namelist_changed = True; - continue; - } - DEBUG(3,("expire_names_on_subnet: Subnet %s - removing expired name %s\n", - subrec->subnet_name, nmb_namestr(&namerec->name))); + struct name_record *namerec; + struct name_record *next_namerec; + + for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); namerec; namerec = next_namerec ) { + next_namerec = (struct name_record *)ubi_trNext( namerec ); + if( (namerec->data.death_time != PERMANENT_TTL) && (namerec->data.death_time < t) ) { + if( namerec->data.source == SELF_NAME ) { + DEBUG( 3, ( "expire_names_on_subnet: Subnet %s not expiring SELF \ +name %s\n", subrec->subnet_name, nmb_namestr(&namerec->name) ) ); + namerec->data.death_time += 300; + namerec->subnet->namelist_changed = True; + continue; + } + + DEBUG(3,("expire_names_on_subnet: Subnet %s - removing expired name %s\n", + subrec->subnet_name, nmb_namestr(&namerec->name))); - remove_name_from_namelist( subrec, namerec ); - } - } + remove_name_from_namelist( subrec, namerec ); + } + } } /******************************************************************* Expires old names in all subnet namelists. - ******************************************************************/ +******************************************************************/ void expire_names(time_t t) { - struct subnet_record *subrec; - - for( subrec = FIRST_SUBNET; - subrec; - subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec) ) - { - expire_names_on_subnet( subrec, t ); - } + struct subnet_record *subrec; + + for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec) ) { + expire_names_on_subnet( subrec, t ); + } } /**************************************************************************** @@ -475,46 +448,39 @@ void expire_names(time_t t) void add_samba_names_to_subnet( struct subnet_record *subrec ) { - struct in_addr *iplist = &subrec->myip; - int num_ips = 1; - - /* These names are added permanently (ttl of zero) and will NOT be - refreshed. */ - - if( (subrec == unicast_subnet) - || (subrec == wins_server_subnet) - || (subrec == remote_broadcast_subnet) ) - { - struct subnet_record *bcast_subrecs; - int i; - /* Create an IP list containing all our known subnets. */ - - num_ips = iface_count(); - iplist = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr) ); - if( NULL == iplist ) - { - DEBUG(0,("add_samba_names_to_subnet: Malloc fail !\n")); - return; - } - - for( bcast_subrecs = FIRST_SUBNET, i = 0; - bcast_subrecs; - bcast_subrecs = NEXT_SUBNET_EXCLUDING_UNICAST(bcast_subrecs), i++ ) - iplist[i] = bcast_subrecs->myip; - - } - - (void)add_name_to_subnet(subrec,"*",0x0,samba_nb_type, PERMANENT_TTL, - PERMANENT_NAME, num_ips, iplist); - (void)add_name_to_subnet(subrec,"*",0x20,samba_nb_type,PERMANENT_TTL, - PERMANENT_NAME, num_ips, iplist); - (void)add_name_to_subnet(subrec,"__SAMBA__",0x20,samba_nb_type,PERMANENT_TTL, - PERMANENT_NAME, num_ips, iplist); - (void)add_name_to_subnet(subrec,"__SAMBA__",0x00,samba_nb_type,PERMANENT_TTL, - PERMANENT_NAME, num_ips, iplist); - - if(iplist != &subrec->myip) - SAFE_FREE(iplist); + struct in_addr *iplist = &subrec->myip; + int num_ips = 1; + + /* These names are added permanently (ttl of zero) and will NOT be refreshed. */ + + if( (subrec == unicast_subnet) || (subrec == wins_server_subnet) || (subrec == remote_broadcast_subnet) ) { + struct subnet_record *bcast_subrecs; + int i; + + /* Create an IP list containing all our known subnets. */ + + num_ips = iface_count(); + iplist = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr) ); + if( NULL == iplist ) { + DEBUG(0,("add_samba_names_to_subnet: Malloc fail !\n")); + return; + } + + for( bcast_subrecs = FIRST_SUBNET, i = 0; bcast_subrecs; bcast_subrecs = NEXT_SUBNET_EXCLUDING_UNICAST(bcast_subrecs), i++ ) + iplist[i] = bcast_subrecs->myip; + } + + add_name_to_subnet(subrec,"*",0x0,samba_nb_type, PERMANENT_TTL, + PERMANENT_NAME, num_ips, iplist); + add_name_to_subnet(subrec,"*",0x20,samba_nb_type,PERMANENT_TTL, + PERMANENT_NAME, num_ips, iplist); + add_name_to_subnet(subrec,"__SAMBA__",0x20,samba_nb_type,PERMANENT_TTL, + PERMANENT_NAME, num_ips, iplist); + add_name_to_subnet(subrec,"__SAMBA__",0x00,samba_nb_type,PERMANENT_TTL, + PERMANENT_NAME, num_ips, iplist); + + if(iplist != &subrec->myip) + SAFE_FREE(iplist); } /**************************************************************************** @@ -524,68 +490,65 @@ void add_samba_names_to_subnet( struct subnet_record *subrec ) static void dump_subnet_namelist( struct subnet_record *subrec, XFILE *fp) { - struct name_record *namerec; - const char *src_type; - struct tm *tm; - int i; - - x_fprintf(fp, "Subnet %s\n----------------------\n", subrec->subnet_name); - for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); - namerec; - namerec = (struct name_record *)ubi_trNext( namerec ) ) - { - x_fprintf(fp,"\tName = %s\t", nmb_namestr(&namerec->name)); - switch(namerec->data.source) - { - case LMHOSTS_NAME: - src_type = "LMHOSTS_NAME"; - break; - case WINS_PROXY_NAME: - src_type = "WINS_PROXY_NAME"; - break; - case REGISTER_NAME: - src_type = "REGISTER_NAME"; - break; - case SELF_NAME: - src_type = "SELF_NAME"; - break; - case DNS_NAME: - src_type = "DNS_NAME"; - break; - case DNSFAIL_NAME: - src_type = "DNSFAIL_NAME"; - break; - case PERMANENT_NAME: - src_type = "PERMANENT_NAME"; - break; - default: - src_type = "unknown!"; - break; - } - x_fprintf(fp,"Source = %s\nb_flags = %x\t", src_type, namerec->data.nb_flags); - - if(namerec->data.death_time != PERMANENT_TTL) - { - tm = LocalTime(&namerec->data.death_time); - x_fprintf(fp, "death_time = %s\t", asctime(tm)); - } - else - x_fprintf(fp, "death_time = PERMANENT\t"); - - if(namerec->data.refresh_time != PERMANENT_TTL) - { - tm = LocalTime(&namerec->data.refresh_time); - x_fprintf(fp, "refresh_time = %s\n", asctime(tm)); - } - else - x_fprintf(fp, "refresh_time = PERMANENT\n"); - - x_fprintf(fp, "\t\tnumber of IPS = %d", namerec->data.num_ips); - for(i = 0; i < namerec->data.num_ips; i++) - x_fprintf(fp, "\t%s", inet_ntoa(namerec->data.ip[i])); - - x_fprintf(fp, "\n\n"); - } + struct name_record *namerec; + const char *src_type; + struct tm *tm; + int i; + + x_fprintf(fp, "Subnet %s\n----------------------\n", subrec->subnet_name); + for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); namerec; + namerec = (struct name_record *)ubi_trNext( namerec ) ) { + + x_fprintf(fp,"\tName = %s\t", nmb_namestr(&namerec->name)); + switch(namerec->data.source) { + case LMHOSTS_NAME: + src_type = "LMHOSTS_NAME"; + break; + case WINS_PROXY_NAME: + src_type = "WINS_PROXY_NAME"; + break; + case REGISTER_NAME: + src_type = "REGISTER_NAME"; + break; + case SELF_NAME: + src_type = "SELF_NAME"; + break; + case DNS_NAME: + src_type = "DNS_NAME"; + break; + case DNSFAIL_NAME: + src_type = "DNSFAIL_NAME"; + break; + case PERMANENT_NAME: + src_type = "PERMANENT_NAME"; + break; + default: + src_type = "unknown!"; + break; + } + + x_fprintf(fp,"Source = %s\nb_flags = %x\t", src_type, namerec->data.nb_flags); + + if(namerec->data.death_time != PERMANENT_TTL) { + tm = LocalTime(&namerec->data.death_time); + x_fprintf(fp, "death_time = %s\t", asctime(tm)); + } else { + x_fprintf(fp, "death_time = PERMANENT\t"); + } + + if(namerec->data.refresh_time != PERMANENT_TTL) { + tm = LocalTime(&namerec->data.refresh_time); + x_fprintf(fp, "refresh_time = %s\n", asctime(tm)); + } else { + x_fprintf(fp, "refresh_time = PERMANENT\n"); + } + + x_fprintf(fp, "\t\tnumber of IPS = %d", namerec->data.num_ips); + for(i = 0; i < namerec->data.num_ips; i++) + x_fprintf(fp, "\t%s", inet_ntoa(namerec->data.ip[i])); + + x_fprintf(fp, "\n\n"); + } } /**************************************************************************** @@ -595,30 +558,27 @@ static void dump_subnet_namelist( struct subnet_record *subrec, XFILE *fp) void dump_all_namelists(void) { - XFILE *fp; - struct subnet_record *subrec; + XFILE *fp; + struct subnet_record *subrec; - fp = x_fopen(lock_path("namelist.debug"),O_WRONLY|O_CREAT|O_TRUNC, 0644); + fp = x_fopen(lock_path("namelist.debug"),O_WRONLY|O_CREAT|O_TRUNC, 0644); - if (!fp) - { - DEBUG(0,("dump_all_namelists: Can't open file %s. Error was %s\n", - "namelist.debug",strerror(errno))); - return; - } + if (!fp) { + DEBUG(0,("dump_all_namelists: Can't open file %s. Error was %s\n", + "namelist.debug",strerror(errno))); + return; + } - for( subrec = FIRST_SUBNET; - subrec; - subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec) ) - dump_subnet_namelist( subrec, fp ); + for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec) ) + dump_subnet_namelist( subrec, fp ); - if( !we_are_a_wins_client() ) - dump_subnet_namelist( unicast_subnet, fp ); + if( !we_are_a_wins_client() ) + dump_subnet_namelist( unicast_subnet, fp ); - if( remote_broadcast_subnet->namelist != NULL ) - dump_subnet_namelist( remote_broadcast_subnet, fp ); + if( remote_broadcast_subnet->namelist != NULL ) + dump_subnet_namelist( remote_broadcast_subnet, fp ); - if( wins_server_subnet != NULL ) - dump_subnet_namelist( wins_server_subnet, fp ); - x_fclose( fp ); + if( wins_server_subnet != NULL ) + dump_subnet_namelist( wins_server_subnet, fp ); + x_fclose( fp ); } diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index 2a200713b9..1b07852f11 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -3,7 +3,7 @@ NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 - Copyright (C) Jeremy Allison 1994-1998 + Copyright (C) Jeremy Allison 1994-2003 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -31,106 +31,95 @@ static void query_name_response( struct subnet_record *subrec, struct response_record *rrec, struct packet_struct *p) { - struct nmb_packet *nmb = &p->packet.nmb; - BOOL success = False; - struct nmb_name *question_name = - &rrec->packet->packet.nmb.question.question_name; - struct in_addr answer_ip; - - zero_ip(&answer_ip); - - /* Ensure we don't retry the query but leave the response record cleanup - to the timeout code. We may get more answer responses in which case - we should mark the name in conflict.. */ - rrec->repeat_count = 0; - - if(rrec->num_msgs == 1) - { - /* This is the first response. */ - - if(nmb->header.opcode == NMB_WACK_OPCODE) - { - /* WINS server is telling us to wait. Pretend we didn't get - the response but don't send out any more query requests. */ - - if( DEBUGLVL( 5 ) ) - { - dbgtext( "query_name_response: " ); - dbgtext( "WACK from WINS server %s ", inet_ntoa(p->ip) ); - dbgtext( "in querying name %s ", nmb_namestr(question_name) ); - dbgtext( "on subnet %s.\n", subrec->subnet_name ); - } + struct nmb_packet *nmb = &p->packet.nmb; + BOOL success = False; + struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name; + struct in_addr answer_ip; + + zero_ip(&answer_ip); + + /* Ensure we don't retry the query but leave the response record cleanup + to the timeout code. We may get more answer responses in which case + we should mark the name in conflict.. */ + rrec->repeat_count = 0; + + if(rrec->num_msgs == 1) { + /* This is the first response. */ + + if(nmb->header.opcode == NMB_WACK_OPCODE) { + /* WINS server is telling us to wait. Pretend we didn't get + the response but don't send out any more query requests. */ + + if( DEBUGLVL( 5 ) ) { + dbgtext( "query_name_response: " ); + dbgtext( "WACK from WINS server %s ", inet_ntoa(p->ip) ); + dbgtext( "in querying name %s ", nmb_namestr(question_name) ); + dbgtext( "on subnet %s.\n", subrec->subnet_name ); + } - rrec->repeat_count = 0; - /* How long we should wait for. */ - rrec->repeat_time = p->timestamp + nmb->answers->ttl; - rrec->num_msgs--; - return; - } - else if(nmb->header.rcode != 0) - { - success = False; - - if( DEBUGLVL( 5 ) ) - { - dbgtext( "query_name_response: On subnet %s ", subrec->subnet_name ); - dbgtext( "- negative response from IP %s ", inet_ntoa(p->ip) ); - dbgtext( "for name %s. ", nmb_namestr(question_name) ); - dbgtext( "Error code was %d.\n", nmb->header.rcode ); - } - } - else - { - if (!nmb->answers) - { - dbgtext( "query_name_response: On subnet %s ", subrec->subnet_name ); - dbgtext( "IP %s ", inet_ntoa(p->ip) ); - dbgtext( "returned a success response with no answer\n" ); - return; - } - - success = True; - - putip((char *)&answer_ip,&nmb->answers->rdata[2]); - if( DEBUGLVL( 5 ) ) - { - dbgtext( "query_name_response: On subnet %s ", subrec->subnet_name ); - dbgtext( "- positive response from IP %s ", inet_ntoa(p->ip) ); - dbgtext( "for name %s. ", nmb_namestr(question_name) ); - dbgtext( "IP of that name is %s\n", inet_ntoa(answer_ip) ); - } - - /* Interestingly, we could add these names to our namelists, and - change nmbd to a model that checked its own name cache first, - before sending out a query. This is a task for another day, though. - */ - } - } - else if( rrec->num_msgs > 1) - { - if( DEBUGLVL( 0 ) ) - { - if (nmb->answers) - putip( (char *)&answer_ip, &nmb->answers->rdata[2] ); - dbgtext( "query_name_response: " ); - dbgtext( "Multiple (%d) responses ", rrec->num_msgs ); - dbgtext( "received for a query on subnet %s ", subrec->subnet_name ); - dbgtext( "for name %s.\nThis response ", nmb_namestr(question_name) ); - dbgtext( "was from IP %s, reporting ", inet_ntoa(p->ip) ); - dbgtext( "an IP address of %s.\n", inet_ntoa(answer_ip) ); - } - - /* We have already called the success or fail function, so we - don't call again here. Leave the response record around in - case we get more responses. */ - - return; - } + rrec->repeat_count = 0; + /* How long we should wait for. */ + rrec->repeat_time = p->timestamp + nmb->answers->ttl; + rrec->num_msgs--; + return; + } else if(nmb->header.rcode != 0) { + + success = False; + + if( DEBUGLVL( 5 ) ) { + dbgtext( "query_name_response: On subnet %s ", subrec->subnet_name ); + dbgtext( "- negative response from IP %s ", inet_ntoa(p->ip) ); + dbgtext( "for name %s. ", nmb_namestr(question_name) ); + dbgtext( "Error code was %d.\n", nmb->header.rcode ); + } + } else { + if (!nmb->answers) { + dbgtext( "query_name_response: On subnet %s ", subrec->subnet_name ); + dbgtext( "IP %s ", inet_ntoa(p->ip) ); + dbgtext( "returned a success response with no answer\n" ); + return; + } + + success = True; + + putip((char *)&answer_ip,&nmb->answers->rdata[2]); + + if( DEBUGLVL( 5 ) ) { + dbgtext( "query_name_response: On subnet %s ", subrec->subnet_name ); + dbgtext( "- positive response from IP %s ", inet_ntoa(p->ip) ); + dbgtext( "for name %s. ", nmb_namestr(question_name) ); + dbgtext( "IP of that name is %s\n", inet_ntoa(answer_ip) ); + } + + /* Interestingly, we could add these names to our namelists, and + change nmbd to a model that checked its own name cache first, + before sending out a query. This is a task for another day, though. + */ + } + } else if( rrec->num_msgs > 1) { + + if( DEBUGLVL( 0 ) ) { + if (nmb->answers) + putip( (char *)&answer_ip, &nmb->answers->rdata[2] ); + dbgtext( "query_name_response: " ); + dbgtext( "Multiple (%d) responses ", rrec->num_msgs ); + dbgtext( "received for a query on subnet %s ", subrec->subnet_name ); + dbgtext( "for name %s.\nThis response ", nmb_namestr(question_name) ); + dbgtext( "was from IP %s, reporting ", inet_ntoa(p->ip) ); + dbgtext( "an IP address of %s.\n", inet_ntoa(answer_ip) ); + } + + /* We have already called the success or fail function, so we + don't call again here. Leave the response record around in + case we get more responses. */ + + return; + } - if(success && rrec->success_fn) - (*(query_name_success_function)rrec->success_fn)(subrec, rrec->userdata, question_name, answer_ip, nmb->answers); - else if( rrec->fail_fn) - (*(query_name_fail_function)rrec->fail_fn)(subrec, rrec, question_name, nmb->header.rcode); + if(success && rrec->success_fn) + (*(query_name_success_function)rrec->success_fn)(subrec, rrec->userdata, question_name, answer_ip, nmb->answers); + else if( rrec->fail_fn) + (*(query_name_fail_function)rrec->fail_fn)(subrec, rrec, question_name, nmb->header.rcode); } @@ -141,32 +130,30 @@ static void query_name_response( struct subnet_record *subrec, static void query_name_timeout_response(struct subnet_record *subrec, struct response_record *rrec) { - struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb; - /* We can only fail here, never succeed. */ - BOOL failed = True; - struct nmb_name *question_name = &sent_nmb->question.question_name; - - if(rrec->num_msgs != 0) - { - /* We got at least one response, and have called the success/fail - function already. */ - - failed = False; - } - - if(failed) - { - if( DEBUGLVL( 5 ) ) - { - dbgtext( "query_name_timeout_response: No response to " ); - dbgtext( "query for name %s ", nmb_namestr(question_name) ); - dbgtext( "on subnet %s.\n", subrec->subnet_name ); - } - if(rrec->fail_fn) - (*(query_name_fail_function)rrec->fail_fn)(subrec, rrec, question_name, 0); - } - - remove_response_record(subrec, rrec); + struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb; + /* We can only fail here, never succeed. */ + BOOL failed = True; + struct nmb_name *question_name = &sent_nmb->question.question_name; + + if(rrec->num_msgs != 0) { + /* We got at least one response, and have called the success/fail + function already. */ + + failed = False; + } + + if(failed) { + if( DEBUGLVL( 5 ) ) { + dbgtext( "query_name_timeout_response: No response to " ); + dbgtext( "query for name %s ", nmb_namestr(question_name) ); + dbgtext( "on subnet %s.\n", subrec->subnet_name ); + } + + if(rrec->fail_fn) + (*(query_name_fail_function)rrec->fail_fn)(subrec, rrec, question_name, 0); + } + + remove_response_record(subrec, rrec); } /**************************************************************************** @@ -177,24 +164,21 @@ static void query_name_timeout_response(struct subnet_record *subrec, static BOOL query_local_namelists(struct subnet_record *subrec, struct nmb_name *nmbname, struct name_record **namerecp) { - struct name_record *namerec; + struct name_record *namerec; - *namerecp = NULL; + *namerecp = NULL; - if(find_name_in_lmhosts(nmbname, namerecp)) - return True; + if(find_name_in_lmhosts(nmbname, namerecp)) + return True; - if((namerec = find_name_on_subnet(subrec, nmbname, FIND_ANY_NAME))==NULL) - return False; - - if( NAME_IS_ACTIVE(namerec) - && ( (namerec->data.source == SELF_NAME) - || (namerec->data.source == LMHOSTS_NAME) ) ) - { - *namerecp = namerec; - return True; - } - return False; + if((namerec = find_name_on_subnet(subrec, nmbname, FIND_ANY_NAME))==NULL) + return False; + + if( NAME_IS_ACTIVE(namerec) && ( (namerec->data.source == SELF_NAME) || (namerec->data.source == LMHOSTS_NAME) ) ) { + *namerecp = namerec; + return True; + } + return False; } /**************************************************************************** @@ -206,69 +190,57 @@ BOOL query_name(struct subnet_record *subrec, const char *name, int type, query_name_fail_function fail_fn, struct userdata_struct *userdata) { - struct nmb_name nmbname; - struct name_record *namerec; - - make_nmb_name(&nmbname, name, type); - - /* - * We need to check our local namelists first. - * It may be an magic name, lmhosts name or just - * a name we have registered. - */ - - if(query_local_namelists(subrec, &nmbname, &namerec) == True) - { - struct res_rec rrec; - int i; - - memset((char *)&rrec, '\0', sizeof(struct res_rec)); - - /* Fake up the needed res_rec just in case it's used. */ - rrec.rr_name = nmbname; - rrec.rr_type = RR_TYPE_NB; - rrec.rr_class = RR_CLASS_IN; - rrec.ttl = PERMANENT_TTL; - rrec.rdlength = namerec->data.num_ips * 6; - if(rrec.rdlength > MAX_DGRAM_SIZE) - { - if( DEBUGLVL( 0 ) ) - { - dbgtext( "query_name: nmbd internal error - " ); - dbgtext( "there are %d ip addresses ", namerec->data.num_ips ); - dbgtext( "for name %s.\n", nmb_namestr(&nmbname) ); - } - return False; - } - - for( i = 0; i < namerec->data.num_ips; i++) - { - set_nb_flags( &rrec.rdata[i*6], namerec->data.nb_flags ); - putip( &rrec.rdata[(i*6) + 2], (char *)&namerec->data.ip[i]); - } - - /* Call the success function directly. */ - if(success_fn) - (*(query_name_success_function)success_fn)(subrec, userdata, &nmbname, namerec->data.ip[0], &rrec); - return False; - } - - if(queue_query_name( subrec, - query_name_response, - query_name_timeout_response, - success_fn, - fail_fn, - userdata, - &nmbname) == NULL) - { - if( DEBUGLVL( 0 ) ) - { - dbgtext( "query_name: Failed to send packet " ); - dbgtext( "trying to query name %s\n", nmb_namestr(&nmbname) ); - } - return True; - } - return False; + struct nmb_name nmbname; + struct name_record *namerec; + + make_nmb_name(&nmbname, name, type); + + /* + * We need to check our local namelists first. + * It may be an magic name, lmhosts name or just + * a name we have registered. + */ + + if(query_local_namelists(subrec, &nmbname, &namerec) == True) { + struct res_rec rrec; + int i; + + memset((char *)&rrec, '\0', sizeof(struct res_rec)); + + /* Fake up the needed res_rec just in case it's used. */ + rrec.rr_name = nmbname; + rrec.rr_type = RR_TYPE_NB; + rrec.rr_class = RR_CLASS_IN; + rrec.ttl = PERMANENT_TTL; + rrec.rdlength = namerec->data.num_ips * 6; + if(rrec.rdlength > MAX_DGRAM_SIZE) { + if( DEBUGLVL( 0 ) ) { + dbgtext( "query_name: nmbd internal error - " ); + dbgtext( "there are %d ip addresses ", namerec->data.num_ips ); + dbgtext( "for name %s.\n", nmb_namestr(&nmbname) ); + } + return False; + } + + for( i = 0; i < namerec->data.num_ips; i++) { + set_nb_flags( &rrec.rdata[i*6], namerec->data.nb_flags ); + putip( &rrec.rdata[(i*6) + 2], (char *)&namerec->data.ip[i]); + } + + /* Call the success function directly. */ + if(success_fn) + (*(query_name_success_function)success_fn)(subrec, userdata, &nmbname, namerec->data.ip[0], &rrec); + return False; + } + + if(queue_query_name( subrec, query_name_response, query_name_timeout_response, success_fn, fail_fn, userdata, &nmbname) == NULL) { + if( DEBUGLVL( 0 ) ) { + dbgtext( "query_name: Failed to send packet " ); + dbgtext( "trying to query name %s\n", nmb_namestr(&nmbname) ); + } + return True; + } + return False; } /**************************************************************************** @@ -281,24 +253,16 @@ BOOL query_name_from_wins_server(struct in_addr ip_to, query_name_fail_function fail_fn, struct userdata_struct *userdata) { - struct nmb_name nmbname; - - make_nmb_name(&nmbname, name, type); - - if(queue_query_name_from_wins_server( ip_to, - query_name_response, - query_name_timeout_response, - success_fn, - fail_fn, - userdata, - &nmbname) == NULL) - { - if( DEBUGLVL( 0 ) ) - { - dbgtext( "query_name_from_wins_server: Failed to send packet " ); - dbgtext( "trying to query name %s\n", nmb_namestr(&nmbname) ); - } - return True; - } - return False; + struct nmb_name nmbname; + + make_nmb_name(&nmbname, name, type); + + if(queue_query_name_from_wins_server( ip_to, query_name_response, query_name_timeout_response, success_fn, fail_fn, userdata, &nmbname) == NULL) { + if( DEBUGLVL( 0 ) ) { + dbgtext( "query_name_from_wins_server: Failed to send packet " ); + dbgtext( "trying to query name %s\n", nmb_namestr(&nmbname) ); + } + return True; + } + return False; } diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index 7bf2584053..5c9deeb4db 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -3,7 +3,7 @@ NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 - Copyright (C) Jeremy Allison 1994-1998 + Copyright (C) Jeremy Allison 1994-2003 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -85,7 +85,9 @@ static void register_name_response(struct subnet_record *subrec, */ #if 1 /* OLD_SAMBA_SERVER_HACK */ - if((nmb->header.rcode == ACT_ERR) && strequal(lp_workgroup(), answer_name->name) && + nstring ans_name; + pull_ascii_nstring(ans_name, answer_name->name); + if((nmb->header.rcode == ACT_ERR) && strequal(lp_workgroup(), ans_name) && (answer_name->name_type == 0x1b)) { /* Pretend we did not get this. */ rrec->num_msgs--; @@ -161,10 +163,10 @@ static void register_name_response(struct subnet_record *subrec, remove_response_record(subrec, rrec); } - /**************************************************************************** Deal with a timeout of a WINS registration request ****************************************************************************/ + static void wins_registration_timeout(struct subnet_record *subrec, struct response_record *rrec) { @@ -233,7 +235,6 @@ static void wins_registration_timeout(struct subnet_record *subrec, us trying to register with each of our failover wins servers */ } - /**************************************************************************** Deal with a timeout when registering one of our names. ****************************************************************************/ @@ -290,10 +291,10 @@ static void register_name_timeout_response(struct subnet_record *subrec, remove_response_record(subrec, rrec); } - /**************************************************************************** -initiate one multi-homed name registration packet + Initiate one multi-homed name registration packet. ****************************************************************************/ + static void multihomed_register_one(struct nmb_name *nmbname, uint16 nb_flags, register_name_success_function success_fn, @@ -336,11 +337,11 @@ static void multihomed_register_one(struct nmb_name *nmbname, free(userdata); } - /**************************************************************************** -we have finished the registration of one IP and need to see if we have -any more IPs left to register with this group of wins server for this name + We have finished the registration of one IP and need to see if we have + any more IPs left to register with this group of wins server for this name. ****************************************************************************/ + static void wins_next_registration(struct response_record *rrec) { struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb; @@ -388,6 +389,7 @@ static void wins_next_registration(struct response_record *rrec) /**************************************************************************** Try and register one of our names on the unicast subnet - multihomed. ****************************************************************************/ + static void multihomed_register_name(struct nmb_name *nmbname, uint16 nb_flags, register_name_success_function success_fn, register_name_fail_function fail_fn) @@ -416,6 +418,7 @@ static void multihomed_register_name(struct nmb_name *nmbname, uint16 nb_flags, struct subnet_record *subrec; char **wins_tags; struct in_addr *ip_list; + nstring name; for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) ) num_ips++; @@ -431,7 +434,8 @@ static void multihomed_register_name(struct nmb_name *nmbname, uint16 nb_flags, ip_list[i] = subrec->myip; } - add_name_to_subnet(unicast_subnet, nmbname->name, nmbname->name_type, + pull_ascii_nstring(name, nmbname->name); + add_name_to_subnet(unicast_subnet, name, nmbname->name_type, nb_flags, lp_max_ttl(), SELF_NAME, num_ips, ip_list); @@ -456,10 +460,10 @@ static void multihomed_register_name(struct nmb_name *nmbname, uint16 nb_flags, SAFE_FREE(ip_list); } - /**************************************************************************** Try and register one of our names. ****************************************************************************/ + void register_name(struct subnet_record *subrec, const char *name, int type, uint16 nb_flags, register_name_success_function success_fn, @@ -498,10 +502,10 @@ void register_name(struct subnet_record *subrec, } } - /**************************************************************************** Try and refresh one of our names. This is *only* called for WINS refresh ****************************************************************************/ + void wins_refresh_name(struct name_record *namerec) { int t; diff --git a/source3/nmbd/nmbd_nodestatus.c b/source3/nmbd/nmbd_nodestatus.c index 993e4d9d17..0ea5d6a818 100644 --- a/source3/nmbd/nmbd_nodestatus.c +++ b/source3/nmbd/nmbd_nodestatus.c @@ -3,7 +3,7 @@ NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 - Copyright (C) Jeremy Allison 1994-1998 + Copyright (C) Jeremy Allison 1994-2003 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,52 +26,52 @@ /**************************************************************************** Deal with a successful node status response. ****************************************************************************/ + static void node_status_response(struct subnet_record *subrec, struct response_record *rrec, struct packet_struct *p) { - struct nmb_packet *nmb = &p->packet.nmb; - struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name; - struct nmb_name *answer_name = &nmb->answers->rr_name; + struct nmb_packet *nmb = &p->packet.nmb; + struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name; + struct nmb_name *answer_name = &nmb->answers->rr_name; - /* Sanity check. Ensure that the answer name in the incoming packet is the - same as the requested name in the outgoing packet. */ + /* Sanity check. Ensure that the answer name in the incoming packet is the + same as the requested name in the outgoing packet. */ - if(!nmb_name_equal(question_name, answer_name)) - { - DEBUG(0,("node_status_response: Answer name %s differs from question \ + if(!nmb_name_equal(question_name, answer_name)) { + DEBUG(0,("node_status_response: Answer name %s differs from question \ name %s.\n", nmb_namestr(answer_name), nmb_namestr(question_name))); - return; - } + return; + } - DEBUG(5,("node_status_response: response from name %s on subnet %s.\n", - nmb_namestr(answer_name), subrec->subnet_name)); + DEBUG(5,("node_status_response: response from name %s on subnet %s.\n", + nmb_namestr(answer_name), subrec->subnet_name)); - /* Just send the whole answer resource record for the success function - to parse. */ - if(rrec->success_fn) - (*(node_status_success_function)rrec->success_fn)(subrec, rrec->userdata, nmb->answers, p->ip); + /* Just send the whole answer resource record for the success function to parse. */ + if(rrec->success_fn) + (*(node_status_success_function)rrec->success_fn)(subrec, rrec->userdata, nmb->answers, p->ip); - /* Ensure we don't retry. */ - remove_response_record(subrec, rrec); + /* Ensure we don't retry. */ + remove_response_record(subrec, rrec); } /**************************************************************************** Deal with a timeout when requesting a node status. ****************************************************************************/ + static void node_status_timeout_response(struct subnet_record *subrec, struct response_record *rrec) { - struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb; - struct nmb_name *question_name = &sent_nmb->question.question_name; + struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb; + struct nmb_name *question_name = &sent_nmb->question.question_name; - DEBUG(5,("node_status_timeout_response: failed to get node status from name %s on subnet %s\n", - nmb_namestr(question_name), subrec->subnet_name)); + DEBUG(5,("node_status_timeout_response: failed to get node status from name %s on subnet %s\n", + nmb_namestr(question_name), subrec->subnet_name)); - if( rrec->fail_fn) - (*rrec->fail_fn)(subrec, rrec); + if( rrec->fail_fn) + (*rrec->fail_fn)(subrec, rrec); - /* Ensure we don't retry. */ - remove_response_record(subrec, rrec); + /* Ensure we don't retry. */ + remove_response_record(subrec, rrec); } /**************************************************************************** @@ -82,13 +82,11 @@ BOOL node_status(struct subnet_record *subrec, struct nmb_name *nmbname, struct in_addr send_ip, node_status_success_function success_fn, node_status_fail_function fail_fn, struct userdata_struct *userdata) { - if(queue_node_status( subrec, - node_status_response, node_status_timeout_response, - success_fn, fail_fn, userdata, nmbname, send_ip)==NULL) - { - DEBUG(0,("node_status: Failed to send packet trying to get node status for \ + if(queue_node_status( subrec, node_status_response, node_status_timeout_response, + success_fn, fail_fn, userdata, nmbname, send_ip)==NULL) { + DEBUG(0,("node_status: Failed to send packet trying to get node status for \ name %s, IP address %s\n", nmb_namestr(nmbname), inet_ntoa(send_ip))); - return True; - } - return False; + return True; + } + return False; } diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 6c3446d6c8..72eb1b5019 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -3,7 +3,7 @@ NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 - Copyright (C) Jeremy Allison 1994-1998 + Copyright (C) Jeremy Allison 1994-2003 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -50,13 +50,13 @@ Utility function to find the specific fd to send a packet out on. static int find_subnet_fd_for_address( struct in_addr local_ip ) { - struct subnet_record *subrec; + struct subnet_record *subrec; - for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - if(ip_equal(local_ip, subrec->myip)) - return subrec->nmb_sock; + for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + if(ip_equal(local_ip, subrec->myip)) + return subrec->nmb_sock; - return ClientNMB; + return ClientNMB; } /*************************************************************************** @@ -65,13 +65,13 @@ Utility function to find the specific fd to send a mailslot packet out on. static int find_subnet_mailslot_fd_for_address( struct in_addr local_ip ) { - struct subnet_record *subrec; + struct subnet_record *subrec; - for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - if(ip_equal(local_ip, subrec->myip)) - return subrec->dgram_sock; + for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + if(ip_equal(local_ip, subrec->myip)) + return subrec->dgram_sock; - return ClientDGRAM; + return ClientDGRAM; } /*************************************************************************** @@ -80,13 +80,13 @@ Get/Set problematic nb_flags as network byte order 16 bit int. uint16 get_nb_flags(char *buf) { - return ((((uint16)*buf)&0xFFFF) & NB_FLGMSK); + return ((((uint16)*buf)&0xFFFF) & NB_FLGMSK); } void set_nb_flags(char *buf, uint16 nb_flags) { - *buf++ = ((nb_flags & NB_FLGMSK) & 0xFF); - *buf = '\0'; + *buf++ = ((nb_flags & NB_FLGMSK) & 0xFF); + *buf = '\0'; } /*************************************************************************** @@ -95,37 +95,34 @@ Dumps out the browse packet data. static void debug_browse_data(char *outbuf, int len) { - int i,j; - - DEBUG( 4, ( "debug_browse_data():\n" ) ); - for (i = 0; i < len; i+= 16) - { - DEBUGADD( 4, ( "%3x char ", i ) ); - - for (j = 0; j < 16; j++) - { - unsigned char x; - if (i+j >= len) - break; - - x = outbuf[i+j]; - if (x < 32 || x > 127) - x = '.'; + int i,j; + + DEBUG( 4, ( "debug_browse_data():\n" ) ); + for (i = 0; i < len; i+= 16) { + DEBUGADD( 4, ( "%3x char ", i ) ); + + for (j = 0; j < 16; j++) { + unsigned char x; + if (i+j >= len) + break; + + x = outbuf[i+j]; + if (x < 32 || x > 127) + x = '.'; - DEBUGADD( 4, ( "%c", x ) ); - } + DEBUGADD( 4, ( "%c", x ) ); + } - DEBUGADD( 4, ( "%*s hex", 16-j, "" ) ); + DEBUGADD( 4, ( "%*s hex", 16-j, "" ) ); - for (j = 0; j < 16; j++) - { - if (i+j >= len) - break; - DEBUGADD( 4, ( " %02x", (unsigned char)outbuf[i+j] ) ); - } + for (j = 0; j < 16; j++) { + if (i+j >= len) + break; + DEBUGADD( 4, ( " %02x", (unsigned char)outbuf[i+j] ) ); + } - DEBUGADD( 4, ("\n") ); - } + DEBUGADD( 4, ("\n") ); + } } /*************************************************************************** @@ -136,13 +133,11 @@ static uint16 name_trn_id=0; static uint16 generate_name_trn_id(void) { - - if (!name_trn_id) - { - name_trn_id = ((unsigned)time(NULL)%(unsigned)0x7FFF) + ((unsigned)sys_getpid()%(unsigned)100); - } - name_trn_id = (name_trn_id+1) % (unsigned)0x7FFF; - return name_trn_id; + if (!name_trn_id) { + name_trn_id = ((unsigned)time(NULL)%(unsigned)0x7FFF) + ((unsigned)sys_getpid()%(unsigned)100); + } + name_trn_id = (name_trn_id+1) % (unsigned)0x7FFF; + return name_trn_id; } /*************************************************************************** @@ -151,28 +146,25 @@ static uint16 generate_name_trn_id(void) static BOOL send_netbios_packet(struct packet_struct *p) { - BOOL loopback_this_packet = False; - - /* Check if we are sending to or from ourselves as a WINS server. */ - if(ismyip(p->ip) && (p->port == global_nmb_port)) - loopback_this_packet = True; - - if(loopback_this_packet) - { - struct packet_struct *lo_packet = NULL; - DEBUG(5,("send_netbios_packet: sending packet to ourselves.\n")); - if((lo_packet = copy_packet(p)) == NULL) - return False; - queue_packet(lo_packet); - } - else if (!send_packet(p)) - { - DEBUG(0,("send_netbios_packet: send_packet() to IP %s port %d failed\n", - inet_ntoa(p->ip),p->port)); - return False; - } + BOOL loopback_this_packet = False; + + /* Check if we are sending to or from ourselves as a WINS server. */ + if(ismyip(p->ip) && (p->port == global_nmb_port)) + loopback_this_packet = True; + + if(loopback_this_packet) { + struct packet_struct *lo_packet = NULL; + DEBUG(5,("send_netbios_packet: sending packet to ourselves.\n")); + if((lo_packet = copy_packet(p)) == NULL) + return False; + queue_packet(lo_packet); + } else if (!send_packet(p)) { + DEBUG(0,("send_netbios_packet: send_packet() to IP %s port %d failed\n", + inet_ntoa(p->ip),p->port)); + return False; + } - return True; + return True; } /*************************************************************************** @@ -188,45 +180,44 @@ static struct packet_struct *create_and_init_netbios_packet(struct nmb_name *nmb BOOL bcast, BOOL rec_des, struct in_addr to_ip) { - struct packet_struct *packet = NULL; - struct nmb_packet *nmb = NULL; - - /* Allocate the packet_struct we will return. */ - if((packet = (struct packet_struct *)malloc(sizeof(*packet))) == NULL) - { - DEBUG(0,("create_and_init_netbios_packet: malloc fail (1) for packet struct.\n")); - return NULL; - } + struct packet_struct *packet = NULL; + struct nmb_packet *nmb = NULL; + + /* Allocate the packet_struct we will return. */ + if((packet = (struct packet_struct *)malloc(sizeof(*packet))) == NULL) { + DEBUG(0,("create_and_init_netbios_packet: malloc fail (1) for packet struct.\n")); + return NULL; + } - memset((char *)packet,'\0',sizeof(*packet)); + memset((char *)packet,'\0',sizeof(*packet)); - nmb = &packet->packet.nmb; + nmb = &packet->packet.nmb; - nmb->header.name_trn_id = generate_name_trn_id(); - nmb->header.response = False; - nmb->header.nm_flags.recursion_desired = rec_des; - nmb->header.nm_flags.recursion_available = False; - nmb->header.nm_flags.trunc = False; - nmb->header.nm_flags.authoritative = False; - nmb->header.nm_flags.bcast = bcast; + nmb->header.name_trn_id = generate_name_trn_id(); + nmb->header.response = False; + nmb->header.nm_flags.recursion_desired = rec_des; + nmb->header.nm_flags.recursion_available = False; + nmb->header.nm_flags.trunc = False; + nmb->header.nm_flags.authoritative = False; + nmb->header.nm_flags.bcast = bcast; - nmb->header.rcode = 0; - nmb->header.qdcount = 1; - nmb->header.ancount = 0; - nmb->header.nscount = 0; - - nmb->question.question_name = *nmbname; - nmb->question.question_type = QUESTION_TYPE_NB_QUERY; - nmb->question.question_class = QUESTION_CLASS_IN; - - packet->ip = to_ip; - packet->port = NMB_PORT; - packet->fd = ClientNMB; - packet->timestamp = time(NULL); - packet->packet_type = NMB_PACKET; - packet->locked = False; + nmb->header.rcode = 0; + nmb->header.qdcount = 1; + nmb->header.ancount = 0; + nmb->header.nscount = 0; + + nmb->question.question_name = *nmbname; + nmb->question.question_type = QUESTION_TYPE_NB_QUERY; + nmb->question.question_class = QUESTION_CLASS_IN; + + packet->ip = to_ip; + packet->port = NMB_PORT; + packet->fd = ClientNMB; + packet->timestamp = time(NULL); + packet->packet_type = NMB_PACKET; + packet->locked = False; - return packet; /* Caller must free. */ + return packet; /* Caller must free. */ } /*************************************************************************** @@ -283,20 +274,20 @@ static BOOL create_and_init_additional_record(struct packet_struct *packet, static BOOL initiate_name_query_packet( struct packet_struct *packet) { - struct nmb_packet *nmb = NULL; + struct nmb_packet *nmb = NULL; - nmb = &packet->packet.nmb; + nmb = &packet->packet.nmb; - nmb->header.opcode = NMB_NAME_QUERY_OPCODE; - nmb->header.arcount = 0; + nmb->header.opcode = NMB_NAME_QUERY_OPCODE; + nmb->header.arcount = 0; - nmb->header.nm_flags.recursion_desired = True; + nmb->header.nm_flags.recursion_desired = True; - DEBUG(4,("initiate_name_query_packet: sending query for name %s (bcast=%s) to IP %s\n", - nmb_namestr(&nmb->question.question_name), - BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip))); + DEBUG(4,("initiate_name_query_packet: sending query for name %s (bcast=%s) to IP %s\n", + nmb_namestr(&nmb->question.question_name), + BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip))); - return send_netbios_packet( packet ); + return send_netbios_packet( packet ); } /*************************************************************************** @@ -305,20 +296,20 @@ static BOOL initiate_name_query_packet( struct packet_struct *packet) static BOOL initiate_name_query_packet_from_wins_server( struct packet_struct *packet) { - struct nmb_packet *nmb = NULL; + struct nmb_packet *nmb = NULL; - nmb = &packet->packet.nmb; + nmb = &packet->packet.nmb; - nmb->header.opcode = NMB_NAME_QUERY_OPCODE; - nmb->header.arcount = 0; + nmb->header.opcode = NMB_NAME_QUERY_OPCODE; + nmb->header.arcount = 0; - nmb->header.nm_flags.recursion_desired = False; + nmb->header.nm_flags.recursion_desired = False; - DEBUG(4,("initiate_name_query_packet_from_wins_server: sending query for name %s (bcast=%s) to IP %s\n", - nmb_namestr(&nmb->question.question_name), - BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip))); + DEBUG(4,("initiate_name_query_packet_from_wins_server: sending query for name %s (bcast=%s) to IP %s\n", + nmb_namestr(&nmb->question.question_name), + BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip))); - return send_netbios_packet( packet ); + return send_netbios_packet( packet ); } /*************************************************************************** @@ -328,21 +319,21 @@ static BOOL initiate_name_query_packet_from_wins_server( struct packet_struct *p static BOOL initiate_name_register_packet( struct packet_struct *packet, uint16 nb_flags, struct in_addr *register_ip) { - struct nmb_packet *nmb = &packet->packet.nmb; + struct nmb_packet *nmb = &packet->packet.nmb; - nmb->header.opcode = NMB_NAME_REG_OPCODE; - nmb->header.arcount = 1; + nmb->header.opcode = NMB_NAME_REG_OPCODE; + nmb->header.arcount = 1; - nmb->header.nm_flags.recursion_desired = True; + nmb->header.nm_flags.recursion_desired = True; - if(create_and_init_additional_record(packet, nb_flags, register_ip) == False) - return False; + if(create_and_init_additional_record(packet, nb_flags, register_ip) == False) + return False; - DEBUG(4,("initiate_name_register_packet: sending registration for name %s (bcast=%s) to IP %s\n", - nmb_namestr(&nmb->additional->rr_name), - BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip))); + DEBUG(4,("initiate_name_register_packet: sending registration for name %s (bcast=%s) to IP %s\n", + nmb_namestr(&nmb->additional->rr_name), + BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip))); - return send_netbios_packet( packet ); + return send_netbios_packet( packet ); } /*************************************************************************** @@ -380,21 +371,21 @@ for name %s IP %s (bcast=%s) to IP %s\n", static BOOL initiate_name_refresh_packet( struct packet_struct *packet, uint16 nb_flags, struct in_addr *refresh_ip) { - struct nmb_packet *nmb = &packet->packet.nmb; + struct nmb_packet *nmb = &packet->packet.nmb; - nmb->header.opcode = NMB_NAME_REFRESH_OPCODE_8; - nmb->header.arcount = 1; + nmb->header.opcode = NMB_NAME_REFRESH_OPCODE_8; + nmb->header.arcount = 1; - nmb->header.nm_flags.recursion_desired = False; + nmb->header.nm_flags.recursion_desired = False; - if(create_and_init_additional_record(packet, nb_flags, refresh_ip) == False) - return False; + if(create_and_init_additional_record(packet, nb_flags, refresh_ip) == False) + return False; - DEBUG(4,("initiate_name_refresh_packet: sending refresh for name %s (bcast=%s) to IP %s\n", - nmb_namestr(&nmb->additional->rr_name), - BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip))); + DEBUG(4,("initiate_name_refresh_packet: sending refresh for name %s (bcast=%s) to IP %s\n", + nmb_namestr(&nmb->additional->rr_name), + BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip))); - return send_netbios_packet( packet ); + return send_netbios_packet( packet ); } /*************************************************************************** @@ -404,21 +395,21 @@ static BOOL initiate_name_refresh_packet( struct packet_struct *packet, static BOOL initiate_name_release_packet( struct packet_struct *packet, uint16 nb_flags, struct in_addr *release_ip) { - struct nmb_packet *nmb = &packet->packet.nmb; + struct nmb_packet *nmb = &packet->packet.nmb; - nmb->header.opcode = NMB_NAME_RELEASE_OPCODE; - nmb->header.arcount = 1; + nmb->header.opcode = NMB_NAME_RELEASE_OPCODE; + nmb->header.arcount = 1; - nmb->header.nm_flags.recursion_desired = False; + nmb->header.nm_flags.recursion_desired = False; - if(create_and_init_additional_record(packet, nb_flags, release_ip) == False) - return False; + if(create_and_init_additional_record(packet, nb_flags, release_ip) == False) + return False; - DEBUG(4,("initiate_name_release_packet: sending release for name %s (bcast=%s) to IP %s\n", - nmb_namestr(&nmb->additional->rr_name), - BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip))); + DEBUG(4,("initiate_name_release_packet: sending release for name %s (bcast=%s) to IP %s\n", + nmb_namestr(&nmb->additional->rr_name), + BOOLSTR(nmb->header.nm_flags.bcast), inet_ntoa(packet->ip))); - return send_netbios_packet( packet ); + return send_netbios_packet( packet ); } /*************************************************************************** @@ -427,20 +418,20 @@ static BOOL initiate_name_release_packet( struct packet_struct *packet, static BOOL initiate_node_status_packet( struct packet_struct *packet ) { - struct nmb_packet *nmb = &packet->packet.nmb; + struct nmb_packet *nmb = &packet->packet.nmb; - nmb->header.opcode = NMB_NAME_QUERY_OPCODE; - nmb->header.arcount = 0; + nmb->header.opcode = NMB_NAME_QUERY_OPCODE; + nmb->header.arcount = 0; - nmb->header.nm_flags.recursion_desired = False; + nmb->header.nm_flags.recursion_desired = False; - nmb->question.question_type = QUESTION_TYPE_NB_STATUS; + nmb->question.question_type = QUESTION_TYPE_NB_STATUS; - DEBUG(4,("initiate_node_status_packet: sending node status request for name %s to IP %s\n", - nmb_namestr(&nmb->question.question_name), - inet_ntoa(packet->ip))); + DEBUG(4,("initiate_node_status_packet: sending node status request for name %s to IP %s\n", + nmb_namestr(&nmb->question.question_name), + inet_ntoa(packet->ip))); - return send_netbios_packet( packet ); + return send_netbios_packet( packet ); } /**************************************************************************** @@ -456,13 +447,12 @@ static BOOL initiate_node_status_packet( struct packet_struct *packet ) static BOOL assert_check_subnet(struct subnet_record *subrec) { - if( subrec == remote_broadcast_subnet) - { - DEBUG(0,("assert_check_subnet: Attempt to send packet on remote broadcast subnet. \ + if( subrec == remote_broadcast_subnet) { + DEBUG(0,("assert_check_subnet: Attempt to send packet on remote broadcast subnet. \ This is a bug.\n")); - return True; - } - return False; + return True; + } + return False; } /**************************************************************************** @@ -478,46 +468,42 @@ struct response_record *queue_register_name( struct subnet_record *subrec, struct nmb_name *nmbname, uint16 nb_flags) { - struct packet_struct *p; - struct response_record *rrec; - - if(assert_check_subnet(subrec)) - return NULL; - - /* note that all name registration requests have RD set (rfc1002 - - section 4.2.2 */ - if ((p = create_and_init_netbios_packet(nmbname, (subrec != unicast_subnet), True, - subrec->bcast_ip)) == NULL) - return NULL; - - if(initiate_name_register_packet( p, nb_flags, - iface_ip(subrec->bcast_ip)) == False) - { - p->locked = False; - free_packet(p); - return NULL; - } - - if((rrec = make_response_record(subrec, /* subnet record. */ - p, /* packet we sent. */ - resp_fn, /* function to call on response. */ - timeout_fn, /* function to call on timeout. */ - (success_function)success_fn, /* function to call on operation success. */ - (fail_function)fail_fn, /* function to call on operation fail. */ - userdata)) == NULL) - { - p->locked = False; - free_packet(p); - return NULL; - } - - return rrec; -} + struct packet_struct *p; + struct response_record *rrec; + + if(assert_check_subnet(subrec)) + return NULL; + + /* note that all name registration requests have RD set (rfc1002 - section 4.2.2 */ + if ((p = create_and_init_netbios_packet(nmbname, (subrec != unicast_subnet), True, + subrec->bcast_ip)) == NULL) + return NULL; + + if(initiate_name_register_packet( p, nb_flags, iface_ip(subrec->bcast_ip)) == False) { + p->locked = False; + free_packet(p); + return NULL; + } + + if((rrec = make_response_record(subrec, /* subnet record. */ + p, /* packet we sent. */ + resp_fn, /* function to call on response. */ + timeout_fn, /* function to call on timeout. */ + (success_function)success_fn, /* function to call on operation success. */ + (fail_function)fail_fn, /* function to call on operation fail. */ + userdata)) == NULL) { + p->locked = False; + free_packet(p); + return NULL; + } + return rrec; +} /**************************************************************************** Queue a refresh name packet to the broadcast address of a subnet. ****************************************************************************/ + void queue_wins_refresh(struct nmb_name *nmbname, response_function resp_fn, timeout_response_function timeout_fn, @@ -648,47 +634,44 @@ struct response_record *queue_release_name( struct subnet_record *subrec, struct in_addr release_ip, struct in_addr dest_ip) { - struct packet_struct *p; - struct response_record *rrec; - - if(assert_check_subnet(subrec)) - return NULL; - - if ((p = create_and_init_netbios_packet(nmbname, (subrec != unicast_subnet), False, - dest_ip)) == NULL) - return NULL; - - if(initiate_name_release_packet( p, nb_flags, &release_ip) == False) - { - p->locked = False; - free_packet(p); - return NULL; - } - - if((rrec = make_response_record(subrec, /* subnet record. */ - p, /* packet we sent. */ - resp_fn, /* function to call on response. */ - timeout_fn, /* function to call on timeout. */ - (success_function)success_fn, /* function to call on operation success. */ - (fail_function)fail_fn, /* function to call on operation fail. */ - userdata)) == NULL) - { - p->locked = False; - free_packet(p); - return NULL; - } - - /* - * For a broadcast release packet, only send once. - * This will cause us to remove the name asap. JRA. - */ - - if (subrec != unicast_subnet) { - rrec->repeat_count = 0; - rrec->repeat_time = 0; - } - - return rrec; + struct packet_struct *p; + struct response_record *rrec; + + if(assert_check_subnet(subrec)) + return NULL; + + if ((p = create_and_init_netbios_packet(nmbname, (subrec != unicast_subnet), False, dest_ip)) == NULL) + return NULL; + + if(initiate_name_release_packet( p, nb_flags, &release_ip) == False) { + p->locked = False; + free_packet(p); + return NULL; + } + + if((rrec = make_response_record(subrec, /* subnet record. */ + p, /* packet we sent. */ + resp_fn, /* function to call on response. */ + timeout_fn, /* function to call on timeout. */ + (success_function)success_fn, /* function to call on operation success. */ + (fail_function)fail_fn, /* function to call on operation fail. */ + userdata)) == NULL) { + p->locked = False; + free_packet(p); + return NULL; + } + + /* + * For a broadcast release packet, only send once. + * This will cause us to remove the name asap. JRA. + */ + + if (subrec != unicast_subnet) { + rrec->repeat_count = 0; + rrec->repeat_time = 0; + } + + return rrec; } /**************************************************************************** @@ -703,80 +686,80 @@ struct response_record *queue_query_name( struct subnet_record *subrec, struct userdata_struct *userdata, struct nmb_name *nmbname) { - struct packet_struct *p; - struct response_record *rrec; - struct in_addr to_ip; + struct packet_struct *p; + struct response_record *rrec; + struct in_addr to_ip; - if(assert_check_subnet(subrec)) - return NULL; + if(assert_check_subnet(subrec)) + return NULL; - to_ip = subrec->bcast_ip; + to_ip = subrec->bcast_ip; - /* queries to the WINS server turn up here as queries to IP 0.0.0.0 - These need to be handled a bit differently */ - if (subrec->type == UNICAST_SUBNET && is_zero_ip(to_ip)) { - /* what we really need to do is loop over each of our wins - * servers and wins server tags here, but that just doesn't - * fit our architecture at the moment (userdata may already - * be used when we get here). For now we just query the first - * active wins server on the first tag. */ - char **tags = wins_srv_tags(); - if (!tags) { - return NULL; - } - to_ip = wins_srv_ip_tag(tags[0], to_ip); - wins_srv_tags_free(tags); - } - - if(( p = create_and_init_netbios_packet(nmbname, - (subrec != unicast_subnet), - (subrec == unicast_subnet), - to_ip)) == NULL) - return NULL; - - if(lp_bind_interfaces_only()) { - int i; - - DEBUG(10,("queue_query_name: bind_interfaces_only is set, looking for suitable source IP\n")); - for(i = 0; i < iface_count(); i++) { - struct in_addr *ifip = iface_n_ip(i); - - if(ifip == NULL) { - DEBUG(0,("queue_query_name: interface %d has NULL IP address !\n", i)); - continue; - } - - if (ip_equal(*ifip,loopback_ip)) { - DEBUG(5,("queue_query_name: ignoring loopback interface (%d)\n", i)); - continue; - } - - DEBUG(10,("queue_query_name: using source IP %s\n",inet_ntoa(*ifip))); - p->fd = find_subnet_fd_for_address( *ifip ); - break; - } - } - - if(initiate_name_query_packet( p ) == False) { - p->locked = False; - free_packet(p); - return NULL; - } - - if((rrec = make_response_record(subrec, /* subnet record. */ - p, /* packet we sent. */ - resp_fn, /* function to call on response. */ - timeout_fn, /* function to call on timeout. */ - (success_function)success_fn, /* function to call on operation success. */ - (fail_function)fail_fn, /* function to call on operation fail. */ - userdata)) == NULL) - { - p->locked = False; - free_packet(p); - return NULL; - } - - return rrec; + /* queries to the WINS server turn up here as queries to IP 0.0.0.0 + These need to be handled a bit differently */ + if (subrec->type == UNICAST_SUBNET && is_zero_ip(to_ip)) { + /* What we really need to do is loop over each of our wins + * servers and wins server tags here, but that just doesn't + * fit our architecture at the moment (userdata may already + * be used when we get here). For now we just query the first + * active wins server on the first tag. + */ + char **tags = wins_srv_tags(); + if (!tags) { + return NULL; + } + to_ip = wins_srv_ip_tag(tags[0], to_ip); + wins_srv_tags_free(tags); + } + + if(( p = create_and_init_netbios_packet(nmbname, + (subrec != unicast_subnet), + (subrec == unicast_subnet), + to_ip)) == NULL) + return NULL; + + if(lp_bind_interfaces_only()) { + int i; + + DEBUG(10,("queue_query_name: bind_interfaces_only is set, looking for suitable source IP\n")); + for(i = 0; i < iface_count(); i++) { + struct in_addr *ifip = iface_n_ip(i); + + if(ifip == NULL) { + DEBUG(0,("queue_query_name: interface %d has NULL IP address !\n", i)); + continue; + } + + if (ip_equal(*ifip,loopback_ip)) { + DEBUG(5,("queue_query_name: ignoring loopback interface (%d)\n", i)); + continue; + } + + DEBUG(10,("queue_query_name: using source IP %s\n",inet_ntoa(*ifip))); + p->fd = find_subnet_fd_for_address( *ifip ); + break; + } + } + + if(initiate_name_query_packet( p ) == False) { + p->locked = False; + free_packet(p); + return NULL; + } + + if((rrec = make_response_record(subrec, /* subnet record. */ + p, /* packet we sent. */ + resp_fn, /* function to call on response. */ + timeout_fn, /* function to call on timeout. */ + (success_function)success_fn, /* function to call on operation success. */ + (fail_function)fail_fn, /* function to call on operation fail. */ + userdata)) == NULL) { + p->locked = False; + free_packet(p); + return NULL; + } + + return rrec; } /**************************************************************************** @@ -791,33 +774,31 @@ struct response_record *queue_query_name_from_wins_server( struct in_addr to_ip, struct userdata_struct *userdata, struct nmb_name *nmbname) { - struct packet_struct *p; - struct response_record *rrec; - - if ((p = create_and_init_netbios_packet(nmbname, False, False, to_ip)) == NULL) - return NULL; - - if(initiate_name_query_packet_from_wins_server( p ) == False) - { - p->locked = False; - free_packet(p); - return NULL; - } - - if((rrec = make_response_record(wins_server_subnet, /* subnet record. */ - p, /* packet we sent. */ - resp_fn, /* function to call on response. */ - timeout_fn, /* function to call on timeout. */ - (success_function)success_fn, /* function to call on operation success. */ - (fail_function)fail_fn, /* function to call on operation fail. */ - userdata)) == NULL) - { - p->locked = False; - free_packet(p); - return NULL; - } - - return rrec; + struct packet_struct *p; + struct response_record *rrec; + + if ((p = create_and_init_netbios_packet(nmbname, False, False, to_ip)) == NULL) + return NULL; + + if(initiate_name_query_packet_from_wins_server( p ) == False) { + p->locked = False; + free_packet(p); + return NULL; + } + + if((rrec = make_response_record(wins_server_subnet, /* subnet record. */ + p, /* packet we sent. */ + resp_fn, /* function to call on response. */ + timeout_fn, /* function to call on timeout. */ + (success_function)success_fn, /* function to call on operation success. */ + (fail_function)fail_fn, /* function to call on operation fail. */ + userdata)) == NULL) { + p->locked = False; + free_packet(p); + return NULL; + } + + return rrec; } /**************************************************************************** @@ -833,45 +814,41 @@ struct response_record *queue_node_status( struct subnet_record *subrec, struct nmb_name *nmbname, struct in_addr send_ip) { - struct packet_struct *p; - struct response_record *rrec; + struct packet_struct *p; + struct response_record *rrec; - /* Sanity check. */ - if(subrec != unicast_subnet) - { - DEBUG(0,("queue_register_multihomed_name: should only be done on \ + /* Sanity check. */ + if(subrec != unicast_subnet) { + DEBUG(0,("queue_register_multihomed_name: should only be done on \ unicast subnet. subnet is %s\n.", subrec->subnet_name )); - return NULL; - } - - if(assert_check_subnet(subrec)) - return NULL; - - if(( p = create_and_init_netbios_packet(nmbname, False, False, - send_ip)) == NULL) - return NULL; - - if(initiate_node_status_packet(p) == False) - { - p->locked = False; - free_packet(p); - return NULL; - } - - if((rrec = make_response_record(subrec, /* subnet record. */ - p, /* packet we sent. */ - resp_fn, /* function to call on response. */ - timeout_fn, /* function to call on timeout. */ - (success_function)success_fn, /* function to call on operation success. */ - (fail_function)fail_fn, /* function to call on operation fail. */ - userdata)) == NULL) - { - p->locked = False; - free_packet(p); - return NULL; - } - - return rrec; + return NULL; + } + + if(assert_check_subnet(subrec)) + return NULL; + + if(( p = create_and_init_netbios_packet(nmbname, False, False, send_ip)) == NULL) + return NULL; + + if(initiate_node_status_packet(p) == False) { + p->locked = False; + free_packet(p); + return NULL; + } + + if((rrec = make_response_record(subrec, /* subnet record. */ + p, /* packet we sent. */ + resp_fn, /* function to call on response. */ + timeout_fn, /* function to call on timeout. */ + (success_function)success_fn, /* function to call on operation success. */ + (fail_function)fail_fn, /* function to call on operation fail. */ + userdata)) == NULL) { + p->locked = False; + free_packet(p); + return NULL; + } + + return rrec; } /**************************************************************************** @@ -882,169 +859,145 @@ void reply_netbios_packet(struct packet_struct *orig_packet, int rcode, enum netbios_reply_type_code rcv_code, int opcode, int ttl, char *data,int len) { - struct packet_struct packet; - struct nmb_packet *nmb = NULL; - struct res_rec answers; - struct nmb_packet *orig_nmb = &orig_packet->packet.nmb; - BOOL loopback_this_packet = False; - const char *packet_type = "unknown"; + struct packet_struct packet; + struct nmb_packet *nmb = NULL; + struct res_rec answers; + struct nmb_packet *orig_nmb = &orig_packet->packet.nmb; + BOOL loopback_this_packet = False; + const char *packet_type = "unknown"; - /* Check if we are sending to or from ourselves. */ - if(ismyip(orig_packet->ip) && (orig_packet->port == global_nmb_port)) - loopback_this_packet = True; + /* Check if we are sending to or from ourselves. */ + if(ismyip(orig_packet->ip) && (orig_packet->port == global_nmb_port)) + loopback_this_packet = True; - nmb = &packet.packet.nmb; - - /* Do a partial copy of the packet. We clear the locked flag and - the resource record pointers. */ - packet = *orig_packet; /* Full structure copy. */ - packet.locked = False; - nmb->answers = NULL; - nmb->nsrecs = NULL; - nmb->additional = NULL; - - switch (rcv_code) - { - case NMB_STATUS: - { - packet_type = "nmb_status"; - nmb->header.nm_flags.recursion_desired = False; - nmb->header.nm_flags.recursion_available = False; - break; - } - case NMB_QUERY: - { - packet_type = "nmb_query"; - nmb->header.nm_flags.recursion_desired = True; - nmb->header.nm_flags.recursion_available = True; - break; - } - case NMB_REG: - case NMB_REG_REFRESH: - { - packet_type = "nmb_reg"; - nmb->header.nm_flags.recursion_desired = True; - nmb->header.nm_flags.recursion_available = True; - break; - } - case NMB_REL: - { - packet_type = "nmb_rel"; - nmb->header.nm_flags.recursion_desired = False; - nmb->header.nm_flags.recursion_available = False; - break; - } - case NMB_WAIT_ACK: - { - packet_type = "nmb_wack"; - nmb->header.nm_flags.recursion_desired = False; - nmb->header.nm_flags.recursion_available = False; - break; - } - case WINS_REG: - { - packet_type = "wins_reg"; - nmb->header.nm_flags.recursion_desired = True; - nmb->header.nm_flags.recursion_available = True; - break; - } - case WINS_QUERY: - { - packet_type = "wins_query"; - nmb->header.nm_flags.recursion_desired = True; - nmb->header.nm_flags.recursion_available = True; - break; - } - - default: - { - DEBUG(0,("reply_netbios_packet: Unknown packet type: %s %s to ip %s\n", - packet_type, nmb_namestr(&orig_nmb->question.question_name), - inet_ntoa(packet.ip))); - - return; - } - } - - DEBUG(4,("reply_netbios_packet: sending a reply of packet type: %s %s to ip %s \ -for id %hu\n", - packet_type, nmb_namestr(&orig_nmb->question.question_name), - inet_ntoa(packet.ip), orig_nmb->header.name_trn_id)); - - nmb->header.name_trn_id = orig_nmb->header.name_trn_id; - nmb->header.opcode = opcode; - nmb->header.response = True; - nmb->header.nm_flags.bcast = False; - nmb->header.nm_flags.trunc = False; - nmb->header.nm_flags.authoritative = True; + nmb = &packet.packet.nmb; + + /* Do a partial copy of the packet. We clear the locked flag and + the resource record pointers. */ + packet = *orig_packet; /* Full structure copy. */ + packet.locked = False; + nmb->answers = NULL; + nmb->nsrecs = NULL; + nmb->additional = NULL; + + switch (rcv_code) { + case NMB_STATUS: + packet_type = "nmb_status"; + nmb->header.nm_flags.recursion_desired = False; + nmb->header.nm_flags.recursion_available = False; + break; + case NMB_QUERY: + packet_type = "nmb_query"; + nmb->header.nm_flags.recursion_desired = True; + nmb->header.nm_flags.recursion_available = True; + break; + case NMB_REG: + case NMB_REG_REFRESH: + packet_type = "nmb_reg"; + nmb->header.nm_flags.recursion_desired = True; + nmb->header.nm_flags.recursion_available = True; + break; + case NMB_REL: + packet_type = "nmb_rel"; + nmb->header.nm_flags.recursion_desired = False; + nmb->header.nm_flags.recursion_available = False; + break; + case NMB_WAIT_ACK: + packet_type = "nmb_wack"; + nmb->header.nm_flags.recursion_desired = False; + nmb->header.nm_flags.recursion_available = False; + break; + case WINS_REG: + packet_type = "wins_reg"; + nmb->header.nm_flags.recursion_desired = True; + nmb->header.nm_flags.recursion_available = True; + break; + case WINS_QUERY: + packet_type = "wins_query"; + nmb->header.nm_flags.recursion_desired = True; + nmb->header.nm_flags.recursion_available = True; + break; + default: + DEBUG(0,("reply_netbios_packet: Unknown packet type: %s %s to ip %s\n", + packet_type, nmb_namestr(&orig_nmb->question.question_name), + inet_ntoa(packet.ip))); + return; + } + + DEBUG(4,("reply_netbios_packet: sending a reply of packet type: %s %s to ip %s \ +for id %hu\n", packet_type, nmb_namestr(&orig_nmb->question.question_name), + inet_ntoa(packet.ip), orig_nmb->header.name_trn_id)); + + nmb->header.name_trn_id = orig_nmb->header.name_trn_id; + nmb->header.opcode = opcode; + nmb->header.response = True; + nmb->header.nm_flags.bcast = False; + nmb->header.nm_flags.trunc = False; + nmb->header.nm_flags.authoritative = True; - nmb->header.rcode = rcode; - nmb->header.qdcount = 0; - nmb->header.ancount = 1; - nmb->header.nscount = 0; - nmb->header.arcount = 0; + nmb->header.rcode = rcode; + nmb->header.qdcount = 0; + nmb->header.ancount = 1; + nmb->header.nscount = 0; + nmb->header.arcount = 0; - memset((char*)&nmb->question,'\0',sizeof(nmb->question)); + memset((char*)&nmb->question,'\0',sizeof(nmb->question)); - nmb->answers = &answers; - memset((char*)nmb->answers,'\0',sizeof(*nmb->answers)); + nmb->answers = &answers; + memset((char*)nmb->answers,'\0',sizeof(*nmb->answers)); - nmb->answers->rr_name = orig_nmb->question.question_name; - nmb->answers->rr_type = orig_nmb->question.question_type; - nmb->answers->rr_class = orig_nmb->question.question_class; - nmb->answers->ttl = ttl; + nmb->answers->rr_name = orig_nmb->question.question_name; + nmb->answers->rr_type = orig_nmb->question.question_type; + nmb->answers->rr_class = orig_nmb->question.question_class; + nmb->answers->ttl = ttl; - if (data && len) - { - nmb->answers->rdlength = len; - memcpy(nmb->answers->rdata, data, len); - } + if (data && len) { + nmb->answers->rdlength = len; + memcpy(nmb->answers->rdata, data, len); + } - packet.packet_type = NMB_PACKET; - /* Ensure we send out on the same fd that the original - packet came in on to give the correct source IP address. */ - packet.fd = orig_packet->fd; - packet.timestamp = time(NULL); + packet.packet_type = NMB_PACKET; + /* Ensure we send out on the same fd that the original + packet came in on to give the correct source IP address. */ + packet.fd = orig_packet->fd; + packet.timestamp = time(NULL); - debug_nmb_packet(&packet); + debug_nmb_packet(&packet); - if(loopback_this_packet) - { - struct packet_struct *lo_packet; - DEBUG(5,("reply_netbios_packet: sending packet to ourselves.\n")); - if((lo_packet = copy_packet(&packet)) == NULL) - return; - queue_packet(lo_packet); - } - else if (!send_packet(&packet)) - { - DEBUG(0,("reply_netbios_packet: send_packet to IP %s port %d failed\n", - inet_ntoa(packet.ip),packet.port)); - } + if(loopback_this_packet) { + struct packet_struct *lo_packet; + DEBUG(5,("reply_netbios_packet: sending packet to ourselves.\n")); + if((lo_packet = copy_packet(&packet)) == NULL) + return; + queue_packet(lo_packet); + } else if (!send_packet(&packet)) { + DEBUG(0,("reply_netbios_packet: send_packet to IP %s port %d failed\n", + inet_ntoa(packet.ip),packet.port)); + } } /******************************************************************* Queue a packet into a packet queue ******************************************************************/ + static void queue_packet(struct packet_struct *packet) { - struct packet_struct *p; - - if (!packet_queue) - { - packet->prev = NULL; - packet->next = NULL; - packet_queue = packet; - return; - } + struct packet_struct *p; + + if (!packet_queue) { + packet->prev = NULL; + packet->next = NULL; + packet_queue = packet; + return; + } - /* find the bottom */ - for (p=packet_queue;p->next;p=p->next) - ; + /* find the bottom */ + for (p=packet_queue;p->next;p=p->next) + ; - p->next = packet; - packet->next = NULL; - packet->prev = p; + p->next = packet; + packet->next = NULL; + packet->prev = p; } /**************************************************************************** @@ -1053,184 +1006,153 @@ static void queue_packet(struct packet_struct *packet) static struct subnet_record *find_subnet_for_dgram_browse_packet(struct packet_struct *p) { - struct subnet_record *subrec; - - /* Go through all the broadcast subnets and see if the mask matches. */ - for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - { - if(same_net(p->ip, subrec->bcast_ip, subrec->mask_ip)) - return subrec; - } - - /* If the subnet record is the remote announce broadcast subnet, - hack it here to be the first subnet. This is really gross and - is needed due to people turning on port 137/138 broadcast - forwarding on their routers. May fire and brimstone rain - down upon them... - */ - - return FIRST_SUBNET; + struct subnet_record *subrec; + + /* Go through all the broadcast subnets and see if the mask matches. */ + for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { + if(same_net(p->ip, subrec->bcast_ip, subrec->mask_ip)) + return subrec; + } + + /* If the subnet record is the remote announce broadcast subnet, + hack it here to be the first subnet. This is really gross and + is needed due to people turning on port 137/138 broadcast + forwarding on their routers. May fire and brimstone rain + down upon them... + */ + + return FIRST_SUBNET; } /**************************************************************************** Dispatch a browse frame from port 138 to the correct processing function. ****************************************************************************/ + static void process_browse_packet(struct packet_struct *p, char *buf,int len) { - struct dgram_packet *dgram = &p->packet.dgram; - int command = CVAL(buf,0); - struct subnet_record *subrec = find_subnet_for_dgram_browse_packet(p); - - /* Drop the packet if it's a different NetBIOS scope, or - the source is from one of our names. */ - - if (!strequal(dgram->dest_name.scope, global_scope())) - { - DEBUG(7,("process_browse_packet: Discarding datagram from IP %s. Scope (%s) \ -mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, global_scope())); - return; - } - - if (is_myname(dgram->source_name.name)) - { - DEBUG(0,("process_browse_packet: Discarding datagram from IP %s. Source name \ + struct dgram_packet *dgram = &p->packet.dgram; + int command = CVAL(buf,0); + struct subnet_record *subrec = find_subnet_for_dgram_browse_packet(p); + char scope[64]; + nstring src_name; + + /* Drop the packet if it's a different NetBIOS scope, or the source is from one of our names. */ + pull_ascii(scope, dgram->dest_name.scope, 64, 64, STR_TERMINATE); + if (!strequal(scope, global_scope())) { + DEBUG(7,("process_browse_packet: Discarding datagram from IP %s. Scope (%s) \ +mismatch with our scope (%s).\n", inet_ntoa(p->ip), scope, global_scope())); + return; + } + + pull_ascii_nstring(src_name, dgram->source_name.name); + if (is_myname(src_name)) { + DEBUG(0,("process_browse_packet: Discarding datagram from IP %s. Source name \ %s is one of our names !\n", inet_ntoa(p->ip), nmb_namestr(&dgram->source_name))); - return; - } - - switch (command) - { - case ANN_HostAnnouncement: - { - debug_browse_data(buf, len); - process_host_announce(subrec, p, buf+1); - break; - } - case ANN_DomainAnnouncement: - { - debug_browse_data(buf, len); - process_workgroup_announce(subrec, p, buf+1); - break; - } - case ANN_LocalMasterAnnouncement: - { - debug_browse_data(buf, len); - process_local_master_announce(subrec, p, buf+1); - break; - } - case ANN_AnnouncementRequest: - { - debug_browse_data(buf, len); - process_announce_request(subrec, p, buf+1); - break; - } - case ANN_Election: - { - debug_browse_data(buf, len); - process_election(subrec, p, buf+1); - break; - } - case ANN_GetBackupListReq: - { - debug_browse_data(buf, len); - process_get_backup_list_request(subrec, p, buf+1); - break; - } - case ANN_GetBackupListResp: - { - debug_browse_data(buf, len); - /* We never send ANN_GetBackupListReq so we - should never get these. */ - DEBUG(0,("process_browse_packet: Discarding GetBackupListResponse \ + return; + } + + switch (command) { + case ANN_HostAnnouncement: + debug_browse_data(buf, len); + process_host_announce(subrec, p, buf+1); + break; + case ANN_DomainAnnouncement: + debug_browse_data(buf, len); + process_workgroup_announce(subrec, p, buf+1); + break; + case ANN_LocalMasterAnnouncement: + debug_browse_data(buf, len); + process_local_master_announce(subrec, p, buf+1); + break; + case ANN_AnnouncementRequest: + debug_browse_data(buf, len); + process_announce_request(subrec, p, buf+1); + break; + case ANN_Election: + debug_browse_data(buf, len); + process_election(subrec, p, buf+1); + break; + case ANN_GetBackupListReq: + debug_browse_data(buf, len); + process_get_backup_list_request(subrec, p, buf+1); + break; + case ANN_GetBackupListResp: + debug_browse_data(buf, len); + /* We never send ANN_GetBackupListReq so we should never get these. */ + DEBUG(0,("process_browse_packet: Discarding GetBackupListResponse \ packet from %s IP %s\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip))); - break; - } - case ANN_ResetBrowserState: - { - debug_browse_data(buf, len); - process_reset_browser(subrec, p, buf+1); - break; - } - case ANN_MasterAnnouncement: - { - /* Master browser datagrams must be processed - on the unicast subnet. */ - subrec = unicast_subnet; - - debug_browse_data(buf, len); - process_master_browser_announce(subrec, p, buf+1); - break; - } - case ANN_BecomeBackup: - { - /* - * We don't currently implement this. Log it just in case. - */ - debug_browse_data(buf, len); - DEBUG(10,("process_browse_packet: On subnet %s ignoring browse packet \ -command ANN_BecomeBackup from %s IP %s to %s\n", - subrec->subnet_name, nmb_namestr(&dgram->source_name), - inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name))); - break; - } - default: - { - debug_browse_data(buf, len); - DEBUG(0,("process_browse_packet: On subnet %s ignoring browse packet \ -command code %d from %s IP %s to %s\n", - subrec->subnet_name, command, nmb_namestr(&dgram->source_name), - inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name))); - } - } + break; + case ANN_ResetBrowserState: + debug_browse_data(buf, len); + process_reset_browser(subrec, p, buf+1); + break; + case ANN_MasterAnnouncement: + /* Master browser datagrams must be processed on the unicast subnet. */ + subrec = unicast_subnet; + + debug_browse_data(buf, len); + process_master_browser_announce(subrec, p, buf+1); + break; + case ANN_BecomeBackup: + /* + * We don't currently implement this. Log it just in case. + */ + debug_browse_data(buf, len); + DEBUG(10,("process_browse_packet: On subnet %s ignoring browse packet \ +command ANN_BecomeBackup from %s IP %s to %s\n", subrec->subnet_name, nmb_namestr(&dgram->source_name), + inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name))); + break; + default: + debug_browse_data(buf, len); + DEBUG(0,("process_browse_packet: On subnet %s ignoring browse packet \ +command code %d from %s IP %s to %s\n", subrec->subnet_name, command, nmb_namestr(&dgram->source_name), + inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name))); + break; + } } /**************************************************************************** Dispatch a LanMan browse frame from port 138 to the correct processing function. ****************************************************************************/ + static void process_lanman_packet(struct packet_struct *p, char *buf,int len) { - struct dgram_packet *dgram = &p->packet.dgram; - int command = SVAL(buf,0); - struct subnet_record *subrec = find_subnet_for_dgram_browse_packet(p); - - /* Drop the packet if it's a different NetBIOS scope, or - the source is from one of our names. */ - - if (!strequal(dgram->dest_name.scope, global_scope())) - { - DEBUG(7,("process_lanman_packet: Discarding datagram from IP %s. Scope (%s) \ -mismatch with our scope (%s).\n", inet_ntoa(p->ip), dgram->dest_name.scope, global_scope())); - return; - } - - if (is_myname(dgram->source_name.name)) - { - DEBUG(0,("process_lanman_packet: Discarding datagram from IP %s. Source name \ + struct dgram_packet *dgram = &p->packet.dgram; + int command = SVAL(buf,0); + struct subnet_record *subrec = find_subnet_for_dgram_browse_packet(p); + char scope[64]; + nstring src_name; + + /* Drop the packet if it's a different NetBIOS scope, or the source is from one of our names. */ + + pull_ascii(scope, dgram->dest_name.scope, 64, 64, STR_TERMINATE); + if (!strequal(scope, global_scope())) { + DEBUG(7,("process_lanman_packet: Discarding datagram from IP %s. Scope (%s) \ +mismatch with our scope (%s).\n", inet_ntoa(p->ip), scope, global_scope())); + return; + } + + pull_ascii_nstring(src_name, dgram->source_name.name); + if (is_myname(src_name)) { + DEBUG(0,("process_lanman_packet: Discarding datagram from IP %s. Source name \ %s is one of our names !\n", inet_ntoa(p->ip), nmb_namestr(&dgram->source_name))); - return; - } - - switch (command) - { - case ANN_HostAnnouncement: - { - debug_browse_data(buf, len); - process_lm_host_announce(subrec, p, buf+1); - break; - } - case ANN_AnnouncementRequest: - { - process_lm_announce_request(subrec, p, buf+1); - break; - } - default: - { - DEBUG(0,("process_lanman_packet: On subnet %s ignoring browse packet \ -command code %d from %s IP %s to %s\n", - subrec->subnet_name, command, nmb_namestr(&dgram->source_name), - inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name))); - } - } + return; + } + + switch (command) { + case ANN_HostAnnouncement: + debug_browse_data(buf, len); + process_lm_host_announce(subrec, p, buf+1); + break; + case ANN_AnnouncementRequest: + process_lm_announce_request(subrec, p, buf+1); + break; + default: + DEBUG(0,("process_lanman_packet: On subnet %s ignoring browse packet \ +command code %d from %s IP %s to %s\n", subrec->subnet_name, command, nmb_namestr(&dgram->source_name), + inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name))); + break; + } } /**************************************************************************** @@ -1241,104 +1163,94 @@ command code %d from %s IP %s to %s\n", static BOOL listening(struct packet_struct *p,struct nmb_name *nbname) { - struct subnet_record *subrec = NULL; + struct subnet_record *subrec = NULL; - for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - { - if(same_net(p->ip, subrec->bcast_ip, subrec->mask_ip)) - break; - } + for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { + if(same_net(p->ip, subrec->bcast_ip, subrec->mask_ip)) + break; + } - if(subrec == NULL) - subrec = unicast_subnet; + if(subrec == NULL) + subrec = unicast_subnet; - return (find_name_on_subnet(subrec, nbname, FIND_SELF_NAME) != NULL); + return (find_name_on_subnet(subrec, nbname, FIND_SELF_NAME) != NULL); } /**************************************************************************** Process udp 138 datagrams ****************************************************************************/ + static void process_dgram(struct packet_struct *p) { - char *buf; - char *buf2; - int len; - struct dgram_packet *dgram = &p->packet.dgram; - - /* If we aren't listening to the destination name then ignore the packet */ - if (!listening(p,&dgram->dest_name)) - { - unexpected_packet(p); - DEBUG(5,("process_dgram: ignoring dgram packet sent to name %s from %s\n", - nmb_namestr(&dgram->dest_name), inet_ntoa(p->ip))); - return; - } - - if (dgram->header.msg_type != 0x10 && - dgram->header.msg_type != 0x11 && - dgram->header.msg_type != 0x12) - { - unexpected_packet(p); - /* Don't process error packets etc yet */ - DEBUG(5,("process_dgram: ignoring dgram packet sent to name %s from IP %s as it is \ -an error packet of type %x\n", - nmb_namestr(&dgram->dest_name), inet_ntoa(p->ip), dgram->header.msg_type)); - return; - } - - buf = &dgram->data[0]; - buf -= 4; /* XXXX for the pseudo tcp length - - someday I need to get rid of this */ - - if (CVAL(buf,smb_com) != SMBtrans) - return; - - len = SVAL(buf,smb_vwv11); - buf2 = smb_base(buf) + SVAL(buf,smb_vwv12); - - if (len <= 0) - return; - - if (buf2 + len > buf + sizeof(dgram->data)) { - DEBUG(2,("process_dgram: datagram from %s to %s IP %s for %s len=%d too long.\n", + char *buf; + char *buf2; + int len; + struct dgram_packet *dgram = &p->packet.dgram; + + /* If we aren't listening to the destination name then ignore the packet */ + if (!listening(p,&dgram->dest_name)) { + unexpected_packet(p); + DEBUG(5,("process_dgram: ignoring dgram packet sent to name %s from %s\n", + nmb_namestr(&dgram->dest_name), inet_ntoa(p->ip))); + return; + } + + if (dgram->header.msg_type != 0x10 && dgram->header.msg_type != 0x11 && dgram->header.msg_type != 0x12) { + unexpected_packet(p); + /* Don't process error packets etc yet */ + DEBUG(5,("process_dgram: ignoring dgram packet sent to name %s from IP %s as it is \ +an error packet of type %x\n", nmb_namestr(&dgram->dest_name), inet_ntoa(p->ip), dgram->header.msg_type)); + return; + } + + buf = &dgram->data[0]; + buf -= 4; /* XXXX for the pseudo tcp length - someday I need to get rid of this */ + + if (CVAL(buf,smb_com) != SMBtrans) + return; + + len = SVAL(buf,smb_vwv11); + buf2 = smb_base(buf) + SVAL(buf,smb_vwv12); + + if (len <= 0) + return; + + if (buf2 + len > buf + sizeof(dgram->data)) { + DEBUG(2,("process_dgram: datagram from %s to %s IP %s for %s len=%d too long.\n", + nmb_namestr(&dgram->source_name),nmb_namestr(&dgram->dest_name), + inet_ntoa(p->ip), smb_buf(buf),len)); + len = (buf + sizeof(dgram->data)) - buf; + } + + DEBUG(4,("process_dgram: datagram from %s to %s IP %s for %s of type %d len=%d\n", nmb_namestr(&dgram->source_name),nmb_namestr(&dgram->dest_name), - inet_ntoa(p->ip), smb_buf(buf),len)); - len = (buf + sizeof(dgram->data)) - buf; - } + inet_ntoa(p->ip), smb_buf(buf),CVAL(buf2,0),len)); - DEBUG(4,("process_dgram: datagram from %s to %s IP %s for %s of type %d len=%d\n", - nmb_namestr(&dgram->source_name),nmb_namestr(&dgram->dest_name), - inet_ntoa(p->ip), smb_buf(buf),CVAL(buf2,0),len)); + /* Datagram packet received for the browser mailslot */ + if (strequal(smb_buf(buf),BROWSE_MAILSLOT)) { + process_browse_packet(p,buf2,len); + return; + } - - /* Datagram packet received for the browser mailslot */ - if (strequal(smb_buf(buf),BROWSE_MAILSLOT)) - { - process_browse_packet(p,buf2,len); - return; - } - - /* Datagram packet received for the LAN Manager mailslot */ - if (strequal(smb_buf(buf),LANMAN_MAILSLOT)) { - process_lanman_packet(p,buf2,len); - return; - } - - /* Datagram packet received for the domain logon mailslot */ - if (strequal(smb_buf(buf),NET_LOGON_MAILSLOT)) - { - process_logon_packet(p,buf2,len,NET_LOGON_MAILSLOT); - return; - } - - /* Datagram packet received for the NT domain logon mailslot */ - if (strequal(smb_buf(buf),NT_LOGON_MAILSLOT)) - { - process_logon_packet(p,buf2,len,NT_LOGON_MAILSLOT); - return; - } - - unexpected_packet(p); + /* Datagram packet received for the LAN Manager mailslot */ + if (strequal(smb_buf(buf),LANMAN_MAILSLOT)) { + process_lanman_packet(p,buf2,len); + return; + } + + /* Datagram packet received for the domain logon mailslot */ + if (strequal(smb_buf(buf),NET_LOGON_MAILSLOT)) { + process_logon_packet(p,buf2,len,NET_LOGON_MAILSLOT); + return; + } + + /* Datagram packet received for the NT domain logon mailslot */ + if (strequal(smb_buf(buf),NT_LOGON_MAILSLOT)) { + process_logon_packet(p,buf2,len,NT_LOGON_MAILSLOT); + return; + } + + unexpected_packet(p); } /**************************************************************************** @@ -1347,52 +1259,49 @@ an error packet of type %x\n", static BOOL validate_nmb_response_packet( struct nmb_packet *nmb ) { - BOOL ignore = False; - - switch (nmb->header.opcode) - { - case NMB_NAME_REG_OPCODE: - case NMB_NAME_REFRESH_OPCODE_8: /* ambiguity in rfc1002 about which is correct. */ - case NMB_NAME_REFRESH_OPCODE_9: /* WinNT uses 8 by default. */ - if (nmb->header.ancount == 0) - { - DEBUG(0,("validate_nmb_response_packet: Bad REG/REFRESH Packet. ")); - ignore = True; - } - break; - - case NMB_NAME_QUERY_OPCODE: - if ((nmb->header.ancount != 0) && (nmb->header.ancount != 1)) - { - DEBUG(0,("validate_nmb_response_packet: Bad QUERY Packet. ")); - ignore = True; - } - break; - case NMB_NAME_RELEASE_OPCODE: - if (nmb->header.ancount == 0) - { - DEBUG(0,("validate_nmb_response_packet: Bad RELEASE Packet. ")); - ignore = True; - } - break; - case NMB_WACK_OPCODE: - /* Check WACK response here. */ - if (nmb->header.ancount != 1) - { - DEBUG(0,("validate_nmb_response_packet: Bad WACK Packet. ")); - ignore = True; - } - break; - default: - DEBUG(0,("validate_nmb_response_packet: Ignoring packet with unknown opcode %d.\n", - nmb->header.opcode)); - return True; - } - - if(ignore) - DEBUG(0,("Ignoring response packet with opcode %d.\n", nmb->header.opcode)); - - return ignore; + BOOL ignore = False; + + switch (nmb->header.opcode) { + case NMB_NAME_REG_OPCODE: + case NMB_NAME_REFRESH_OPCODE_8: /* ambiguity in rfc1002 about which is correct. */ + case NMB_NAME_REFRESH_OPCODE_9: /* WinNT uses 8 by default. */ + if (nmb->header.ancount == 0) { + DEBUG(0,("validate_nmb_response_packet: Bad REG/REFRESH Packet. ")); + ignore = True; + } + break; + + case NMB_NAME_QUERY_OPCODE: + if ((nmb->header.ancount != 0) && (nmb->header.ancount != 1)) { + DEBUG(0,("validate_nmb_response_packet: Bad QUERY Packet. ")); + ignore = True; + } + break; + + case NMB_NAME_RELEASE_OPCODE: + if (nmb->header.ancount == 0) { + DEBUG(0,("validate_nmb_response_packet: Bad RELEASE Packet. ")); + ignore = True; + } + break; + + case NMB_WACK_OPCODE: + /* Check WACK response here. */ + if (nmb->header.ancount != 1) { + DEBUG(0,("validate_nmb_response_packet: Bad WACK Packet. ")); + ignore = True; + } + break; + default: + DEBUG(0,("validate_nmb_response_packet: Ignoring packet with unknown opcode %d.\n", + nmb->header.opcode)); + return True; + } + + if(ignore) + DEBUG(0,("Ignoring response packet with opcode %d.\n", nmb->header.opcode)); + + return ignore; } /**************************************************************************** @@ -1401,48 +1310,43 @@ static BOOL validate_nmb_response_packet( struct nmb_packet *nmb ) static BOOL validate_nmb_packet( struct nmb_packet *nmb ) { - BOOL ignore = False; - - switch (nmb->header.opcode) - { - case NMB_NAME_REG_OPCODE: - case NMB_NAME_REFRESH_OPCODE_8: /* ambiguity in rfc1002 about which is correct. */ - case NMB_NAME_REFRESH_OPCODE_9: /* WinNT uses 8 by default. */ - case NMB_NAME_MULTIHOMED_REG_OPCODE: - if (nmb->header.qdcount==0 || nmb->header.arcount==0) - { - DEBUG(0,("validate_nmb_packet: Bad REG/REFRESH Packet. ")); - ignore = True; - } - break; - - case NMB_NAME_QUERY_OPCODE: - if ((nmb->header.qdcount == 0) || - ((nmb->question.question_type != QUESTION_TYPE_NB_QUERY) && - (nmb->question.question_type != QUESTION_TYPE_NB_STATUS))) - { - DEBUG(0,("validate_nmb_packet: Bad QUERY Packet. ")); - ignore = True; - } - break; - - case NMB_NAME_RELEASE_OPCODE: - if (nmb->header.qdcount==0 || nmb->header.arcount==0) - { - DEBUG(0,("validate_nmb_packet: Bad RELEASE Packet. ")); - ignore = True; - } - break; - default: - DEBUG(0,("validate_nmb_packet: Ignoring packet with unknown opcode %d.\n", - nmb->header.opcode)); - return True; - } - - if(ignore) - DEBUG(0,("validate_nmb_packet: Ignoring request packet with opcode %d.\n", nmb->header.opcode)); - - return ignore; + BOOL ignore = False; + + switch (nmb->header.opcode) { + case NMB_NAME_REG_OPCODE: + case NMB_NAME_REFRESH_OPCODE_8: /* ambiguity in rfc1002 about which is correct. */ + case NMB_NAME_REFRESH_OPCODE_9: /* WinNT uses 8 by default. */ + case NMB_NAME_MULTIHOMED_REG_OPCODE: + if (nmb->header.qdcount==0 || nmb->header.arcount==0) { + DEBUG(0,("validate_nmb_packet: Bad REG/REFRESH Packet. ")); + ignore = True; + } + break; + + case NMB_NAME_QUERY_OPCODE: + if ((nmb->header.qdcount == 0) || ((nmb->question.question_type != QUESTION_TYPE_NB_QUERY) && + (nmb->question.question_type != QUESTION_TYPE_NB_STATUS))) { + DEBUG(0,("validate_nmb_packet: Bad QUERY Packet. ")); + ignore = True; + } + break; + + case NMB_NAME_RELEASE_OPCODE: + if (nmb->header.qdcount==0 || nmb->header.arcount==0) { + DEBUG(0,("validate_nmb_packet: Bad RELEASE Packet. ")); + ignore = True; + } + break; + default: + DEBUG(0,("validate_nmb_packet: Ignoring packet with unknown opcode %d.\n", + nmb->header.opcode)); + return True; + } + + if(ignore) + DEBUG(0,("validate_nmb_packet: Ignoring request packet with opcode %d.\n", nmb->header.opcode)); + + return ignore; } /**************************************************************************** @@ -1452,58 +1356,53 @@ static BOOL validate_nmb_packet( struct nmb_packet *nmb ) static struct subnet_record *find_subnet_for_nmb_packet( struct packet_struct *p, struct response_record **pprrec) { - struct nmb_packet *nmb = &p->packet.nmb; - struct response_record *rrec = NULL; - struct subnet_record *subrec = NULL; - - if(pprrec != NULL) - *pprrec = NULL; - - if(nmb->header.response) - { - /* It's a response packet. Find a record for it or it's an error. */ - - rrec = find_response_record( &subrec, nmb->header.name_trn_id); - if(rrec == NULL) - { - DEBUG(3,("find_subnet_for_nmb_packet: response record not found for response id %hu\n", - nmb->header.name_trn_id)); - unexpected_packet(p); - return NULL; - } - - if(subrec == NULL) - { - DEBUG(0,("find_subnet_for_nmb_packet: subnet record not found for response id %hu\n", - nmb->header.name_trn_id)); - return NULL; - } - - if(pprrec != NULL) - *pprrec = rrec; - return subrec; - } - - /* Try and see what subnet this packet belongs to. */ - - /* WINS server ? */ - if(packet_is_for_wins_server(p)) - return wins_server_subnet; - - /* If it wasn't a broadcast packet then send to the UNICAST subnet. */ - if(nmb->header.nm_flags.bcast == False) - return unicast_subnet; - - /* Go through all the broadcast subnets and see if the mask matches. */ - for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - { - if(same_net(p->ip, subrec->bcast_ip, subrec->mask_ip)) - return subrec; - } - - /* If none match it must have been a directed broadcast - assign - the remote_broadcast_subnet. */ - return remote_broadcast_subnet; + struct nmb_packet *nmb = &p->packet.nmb; + struct response_record *rrec = NULL; + struct subnet_record *subrec = NULL; + + if(pprrec != NULL) + *pprrec = NULL; + + if(nmb->header.response) { + /* It's a response packet. Find a record for it or it's an error. */ + + rrec = find_response_record( &subrec, nmb->header.name_trn_id); + if(rrec == NULL) { + DEBUG(3,("find_subnet_for_nmb_packet: response record not found for response id %hu\n", + nmb->header.name_trn_id)); + unexpected_packet(p); + return NULL; + } + + if(subrec == NULL) { + DEBUG(0,("find_subnet_for_nmb_packet: subnet record not found for response id %hu\n", + nmb->header.name_trn_id)); + return NULL; + } + + if(pprrec != NULL) + *pprrec = rrec; + return subrec; + } + + /* Try and see what subnet this packet belongs to. */ + + /* WINS server ? */ + if(packet_is_for_wins_server(p)) + return wins_server_subnet; + + /* If it wasn't a broadcast packet then send to the UNICAST subnet. */ + if(nmb->header.nm_flags.bcast == False) + return unicast_subnet; + + /* Go through all the broadcast subnets and see if the mask matches. */ + for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { + if(same_net(p->ip, subrec->bcast_ip, subrec->mask_ip)) + return subrec; + } + + /* If none match it must have been a directed broadcast - assign the remote_broadcast_subnet. */ + return remote_broadcast_subnet; } /**************************************************************************** @@ -1512,79 +1411,71 @@ static struct subnet_record *find_subnet_for_nmb_packet( struct packet_struct *p static void process_nmb_request(struct packet_struct *p) { - struct nmb_packet *nmb = &p->packet.nmb; - struct subnet_record *subrec = NULL; - - debug_nmb_packet(p); - - /* Ensure we have a good packet. */ - if(validate_nmb_packet(nmb)) - return; - - /* Allocate a subnet to this packet - if we cannot - fail. */ - if((subrec = find_subnet_for_nmb_packet(p, NULL))==NULL) - return; - - switch (nmb->header.opcode) - { - case NMB_NAME_REG_OPCODE: - if(subrec == wins_server_subnet) - wins_process_name_registration_request(subrec, p); - else - process_name_registration_request(subrec, p); - break; - - case NMB_NAME_REFRESH_OPCODE_8: /* ambiguity in rfc1002 about which is correct. */ - case NMB_NAME_REFRESH_OPCODE_9: - if(subrec == wins_server_subnet) - wins_process_name_refresh_request(subrec, p); - else - process_name_refresh_request(subrec, p); - break; - - case NMB_NAME_MULTIHOMED_REG_OPCODE: - if(subrec == wins_server_subnet) - wins_process_multihomed_name_registration_request(subrec, p); - else - { - DEBUG(0,("process_nmb_request: Multihomed registration request must be \ + struct nmb_packet *nmb = &p->packet.nmb; + struct subnet_record *subrec = NULL; + + debug_nmb_packet(p); + + /* Ensure we have a good packet. */ + if(validate_nmb_packet(nmb)) + return; + + /* Allocate a subnet to this packet - if we cannot - fail. */ + if((subrec = find_subnet_for_nmb_packet(p, NULL))==NULL) + return; + + switch (nmb->header.opcode) { + case NMB_NAME_REG_OPCODE: + if(subrec == wins_server_subnet) + wins_process_name_registration_request(subrec, p); + else + process_name_registration_request(subrec, p); + break; + + case NMB_NAME_REFRESH_OPCODE_8: /* ambiguity in rfc1002 about which is correct. */ + case NMB_NAME_REFRESH_OPCODE_9: + if(subrec == wins_server_subnet) + wins_process_name_refresh_request(subrec, p); + else + process_name_refresh_request(subrec, p); + break; + + case NMB_NAME_MULTIHOMED_REG_OPCODE: + if(subrec == wins_server_subnet) { + wins_process_multihomed_name_registration_request(subrec, p); + } else { + DEBUG(0,("process_nmb_request: Multihomed registration request must be \ directed at a WINS server.\n")); - } - break; - - case NMB_NAME_QUERY_OPCODE: - switch (nmb->question.question_type) - { - case QUESTION_TYPE_NB_QUERY: - { - if(subrec == wins_server_subnet) - wins_process_name_query_request(subrec, p); - else - process_name_query_request(subrec, p); - break; - } - case QUESTION_TYPE_NB_STATUS: - { - if(subrec == wins_server_subnet) - { - DEBUG(0,("process_nmb_request: NB_STATUS request directed at WINS server is \ + } + break; + + case NMB_NAME_QUERY_OPCODE: + switch (nmb->question.question_type) { + case QUESTION_TYPE_NB_QUERY: + if(subrec == wins_server_subnet) + wins_process_name_query_request(subrec, p); + else + process_name_query_request(subrec, p); + break; + case QUESTION_TYPE_NB_STATUS: + if(subrec == wins_server_subnet) { + DEBUG(0,("process_nmb_request: NB_STATUS request directed at WINS server is \ not allowed.\n")); - break; - } - else - process_node_status_request(subrec, p); - break; - } - } - break; + break; + } else { + process_node_status_request(subrec, p); + } + break; + } + break; - case NMB_NAME_RELEASE_OPCODE: - if(subrec == wins_server_subnet) - wins_process_name_release_request(subrec, p); - else - process_name_release_request(subrec, p); - break; - } + case NMB_NAME_RELEASE_OPCODE: + if(subrec == wins_server_subnet) + wins_process_name_release_request(subrec, p); + else + process_name_release_request(subrec, p); + break; + } } /**************************************************************************** @@ -1594,65 +1485,61 @@ not allowed.\n")); static void process_nmb_response(struct packet_struct *p) { - struct nmb_packet *nmb = &p->packet.nmb; - struct subnet_record *subrec = NULL; - struct response_record *rrec = NULL; + struct nmb_packet *nmb = &p->packet.nmb; + struct subnet_record *subrec = NULL; + struct response_record *rrec = NULL; - debug_nmb_packet(p); + debug_nmb_packet(p); - if(validate_nmb_response_packet(nmb)) - return; + if(validate_nmb_response_packet(nmb)) + return; - if((subrec = find_subnet_for_nmb_packet(p, &rrec))==NULL) - return; + if((subrec = find_subnet_for_nmb_packet(p, &rrec))==NULL) + return; - if(rrec == NULL) - { - DEBUG(0,("process_nmb_response: response packet received but no response record \ + if(rrec == NULL) { + DEBUG(0,("process_nmb_response: response packet received but no response record \ found for id = %hu. Ignoring packet.\n", nmb->header.name_trn_id)); - return; - } + return; + } - /* Increment the number of responses received for this record. */ - rrec->num_msgs++; - /* Ensure we don't re-send the request. */ - rrec->repeat_count = 0; + /* Increment the number of responses received for this record. */ + rrec->num_msgs++; + /* Ensure we don't re-send the request. */ + rrec->repeat_count = 0; - /* Call the response received function for this packet. */ - (*rrec->resp_fn)(subrec, rrec, p); + /* Call the response received function for this packet. */ + (*rrec->resp_fn)(subrec, rrec, p); } - /******************************************************************* Run elements off the packet queue till its empty ******************************************************************/ void run_packet_queue(void) { - struct packet_struct *p; - - while ((p = packet_queue)) - { - packet_queue = p->next; - if (packet_queue) - packet_queue->prev = NULL; - p->next = p->prev = NULL; - - switch (p->packet_type) - { - case NMB_PACKET: - if(p->packet.nmb.header.response) - process_nmb_response(p); - else - process_nmb_request(p); - break; - - case DGRAM_PACKET: - process_dgram(p); - break; - } - free_packet(p); - } + struct packet_struct *p; + + while ((p = packet_queue)) { + packet_queue = p->next; + if (packet_queue) + packet_queue->prev = NULL; + p->next = p->prev = NULL; + + switch (p->packet_type) { + case NMB_PACKET: + if(p->packet.nmb.header.response) + process_nmb_response(p); + else + process_nmb_request(p); + break; + + case DGRAM_PACKET: + process_dgram(p); + break; + } + free_packet(p); + } } /******************************************************************* @@ -1665,66 +1552,54 @@ void run_packet_queue(void) void retransmit_or_expire_response_records(time_t t) { - struct subnet_record *subrec; + struct subnet_record *subrec; - for (subrec = FIRST_SUBNET; subrec; - subrec = get_next_subnet_maybe_unicast_or_wins_server(subrec)) - { - struct response_record *rrec, *nextrrec; + for (subrec = FIRST_SUBNET; subrec; subrec = get_next_subnet_maybe_unicast_or_wins_server(subrec)) { + struct response_record *rrec, *nextrrec; - for (rrec = subrec->responselist; rrec; rrec = nextrrec) - { - nextrrec = rrec->next; + for (rrec = subrec->responselist; rrec; rrec = nextrrec) { + nextrrec = rrec->next; - if (rrec->repeat_time <= t) - { - if (rrec->repeat_count > 0) - { - /* Resend while we have a non-zero repeat_count. */ - if(!send_packet(rrec->packet)) - { - DEBUG(0,("retransmit_or_expire_response_records: Failed to resend packet id %hu \ -to IP %s on subnet %s\n", rrec->response_id, inet_ntoa(rrec->packet->ip), - subrec->subnet_name)); - } - rrec->repeat_time = t + rrec->repeat_interval; - rrec->repeat_count--; - } - else - { - DEBUG(4,("retransmit_or_expire_response_records: timeout for packet id %hu to IP %s \ -on subnet %s\n", rrec->response_id, inet_ntoa(rrec->packet->ip), - subrec->subnet_name)); - - /* - * Check the flag in this record to prevent recursion if we end - * up in this function again via the timeout function call. - */ - - if(!rrec->in_expiration_processing) - { - - /* - * Set the recursion protection flag in this record. - */ - - rrec->in_expiration_processing = True; - - /* Call the timeout function. This will deal with removing the - timed out packet. */ - if(rrec->timeout_fn) - (*rrec->timeout_fn)(subrec, rrec); - else - { - /* We must remove the record ourself if there is - no timeout function. */ - remove_response_record(subrec, rrec); - } - } /* !rrec->in_expitation_processing */ - } /* rrec->repeat_count > 0 */ - } /* rrec->repeat_time <= t */ - } /* end for rrec */ - } /* end for subnet */ + if (rrec->repeat_time <= t) { + if (rrec->repeat_count > 0) { + /* Resend while we have a non-zero repeat_count. */ + if(!send_packet(rrec->packet)) { + DEBUG(0,("retransmit_or_expire_response_records: Failed to resend packet id %hu \ +to IP %s on subnet %s\n", rrec->response_id, inet_ntoa(rrec->packet->ip), subrec->subnet_name)); + } + rrec->repeat_time = t + rrec->repeat_interval; + rrec->repeat_count--; + } else { + DEBUG(4,("retransmit_or_expire_response_records: timeout for packet id %hu to IP %s \ +on subnet %s\n", rrec->response_id, inet_ntoa(rrec->packet->ip), subrec->subnet_name)); + + /* + * Check the flag in this record to prevent recursion if we end + * up in this function again via the timeout function call. + */ + + if(!rrec->in_expiration_processing) { + + /* + * Set the recursion protection flag in this record. + */ + + rrec->in_expiration_processing = True; + + /* Call the timeout function. This will deal with removing the + timed out packet. */ + if(rrec->timeout_fn) { + (*rrec->timeout_fn)(subrec, rrec); + } else { + /* We must remove the record ourself if there is + no timeout function. */ + remove_response_record(subrec, rrec); + } + } /* !rrec->in_expitation_processing */ + } /* rrec->repeat_count > 0 */ + } /* rrec->repeat_time <= t */ + } /* end for rrec */ + } /* end for subnet */ } /**************************************************************************** @@ -1734,68 +1609,63 @@ on subnet %s\n", rrec->response_id, inet_ntoa(rrec->packet->ip), static BOOL create_listen_fdset(fd_set **ppset, int **psock_array, int *listen_number) { - int *sock_array = NULL; - struct subnet_record *subrec = NULL; - int count = 0; - int num = 0; - fd_set *pset = (fd_set *)malloc(sizeof(fd_set)); - - if(pset == NULL) - { - DEBUG(0,("create_listen_fdset: malloc fail !\n")); - return True; - } - - /* Check that we can add all the fd's we need. */ - for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - count++; - - if((count*2) + 2 > FD_SETSIZE) - { - DEBUG(0,("create_listen_fdset: Too many file descriptors needed (%d). We can \ + int *sock_array = NULL; + struct subnet_record *subrec = NULL; + int count = 0; + int num = 0; + fd_set *pset = (fd_set *)malloc(sizeof(fd_set)); + + if(pset == NULL) { + DEBUG(0,("create_listen_fdset: malloc fail !\n")); + return True; + } + + /* Check that we can add all the fd's we need. */ + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) + count++; + + if((count*2) + 2 > FD_SETSIZE) { + DEBUG(0,("create_listen_fdset: Too many file descriptors needed (%d). We can \ only use %d.\n", (count*2) + 2, FD_SETSIZE)); - return True; - } - - if((sock_array = (int *)malloc(((count*2) + 2)*sizeof(int))) == NULL) - { - DEBUG(0,("create_listen_fdset: malloc fail for socket array.\n")); - return True; - } - - FD_ZERO(pset); - - /* Add in the broadcast socket on 137. */ - FD_SET(ClientNMB,pset); - sock_array[num++] = ClientNMB; - - /* Add in the 137 sockets on all the interfaces. */ - for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - { - FD_SET(subrec->nmb_sock,pset); - sock_array[num++] = subrec->nmb_sock; - } - - /* Add in the broadcast socket on 138. */ - FD_SET(ClientDGRAM,pset); - sock_array[num++] = ClientDGRAM; - - /* Add in the 138 sockets on all the interfaces. */ - for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - { - FD_SET(subrec->dgram_sock,pset); - sock_array[num++] = subrec->dgram_sock; - } - - *listen_number = (count*2) + 2; - - SAFE_FREE(*ppset); - SAFE_FREE(*psock_array); - - *ppset = pset; - *psock_array = sock_array; + return True; + } + + if((sock_array = (int *)malloc(((count*2) + 2)*sizeof(int))) == NULL) { + DEBUG(0,("create_listen_fdset: malloc fail for socket array.\n")); + return True; + } + + FD_ZERO(pset); + + /* Add in the broadcast socket on 137. */ + FD_SET(ClientNMB,pset); + sock_array[num++] = ClientNMB; + + /* Add in the 137 sockets on all the interfaces. */ + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { + FD_SET(subrec->nmb_sock,pset); + sock_array[num++] = subrec->nmb_sock; + } + + /* Add in the broadcast socket on 138. */ + FD_SET(ClientDGRAM,pset); + sock_array[num++] = ClientDGRAM; + + /* Add in the 138 sockets on all the interfaces. */ + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { + FD_SET(subrec->dgram_sock,pset); + sock_array[num++] = subrec->dgram_sock; + } + + *listen_number = (count*2) + 2; + + SAFE_FREE(*ppset); + SAFE_FREE(*psock_array); + + *ppset = pset; + *psock_array = sock_array; - return False; + return False; } /**************************************************************************** @@ -1805,214 +1675,211 @@ only use %d.\n", (count*2) + 2, FD_SETSIZE)); BOOL listen_for_packets(BOOL run_election) { - static fd_set *listen_set = NULL; - static int listen_number = 0; - static int *sock_array = NULL; - int i; - - fd_set fds; - int selrtn; - struct timeval timeout; + static fd_set *listen_set = NULL; + static int listen_number = 0; + static int *sock_array = NULL; + int i; + + fd_set fds; + int selrtn; + struct timeval timeout; #ifndef SYNC_DNS - int dns_fd; + int dns_fd; #endif - if(listen_set == NULL || rescan_listen_set) - { - if(create_listen_fdset(&listen_set, &sock_array, &listen_number)) - { - DEBUG(0,("listen_for_packets: Fatal error. unable to create listen set. Exiting.\n")); - return True; - } - rescan_listen_set = False; - } + if(listen_set == NULL || rescan_listen_set) { + if(create_listen_fdset(&listen_set, &sock_array, &listen_number)) { + DEBUG(0,("listen_for_packets: Fatal error. unable to create listen set. Exiting.\n")); + return True; + } + rescan_listen_set = False; + } - memcpy((char *)&fds, (char *)listen_set, sizeof(fd_set)); + memcpy((char *)&fds, (char *)listen_set, sizeof(fd_set)); #ifndef SYNC_DNS - dns_fd = asyncdns_fd(); - if (dns_fd != -1) { - FD_SET(dns_fd, &fds); - } + dns_fd = asyncdns_fd(); + if (dns_fd != -1) { + FD_SET(dns_fd, &fds); + } #endif + /* + * During elections and when expecting a netbios response packet we + * need to send election packets at tighter intervals. + * Ideally it needs to be the interval (in ms) between time now and + * the time we are expecting the next netbios packet. + */ - /* - * During elections and when expecting a netbios response packet we - * need to send election packets at tighter intervals. - * Ideally it needs to be the interval (in ms) between time now and - * the time we are expecting the next netbios packet. - */ - - timeout.tv_sec = (run_election||num_response_packets) ? 1 : NMBD_SELECT_LOOP; - timeout.tv_usec = 0; + timeout.tv_sec = (run_election||num_response_packets) ? 1 : NMBD_SELECT_LOOP; + timeout.tv_usec = 0; - /* Prepare for the select - allow certain signals. */ + /* Prepare for the select - allow certain signals. */ - BlockSignals(False, SIGTERM); + BlockSignals(False, SIGTERM); - selrtn = sys_select(FD_SETSIZE,&fds,NULL,NULL,&timeout); + selrtn = sys_select(FD_SETSIZE,&fds,NULL,NULL,&timeout); - /* We can only take signals when we are in the select - block them again here. */ + /* We can only take signals when we are in the select - block them again here. */ - BlockSignals(True, SIGTERM); + BlockSignals(True, SIGTERM); - if(selrtn == -1) { - return False; - } + if(selrtn == -1) { + return False; + } #ifndef SYNC_DNS - if (dns_fd != -1 && FD_ISSET(dns_fd,&fds)) { - run_dns_queue(); - } + if (dns_fd != -1 && FD_ISSET(dns_fd,&fds)) { + run_dns_queue(); + } #endif - for(i = 0; i < listen_number; i++) { - if (i < (listen_number/2)) { - /* Processing a 137 socket. */ - if (FD_ISSET(sock_array[i],&fds)) { - struct packet_struct *packet = read_packet(sock_array[i], NMB_PACKET); - if (packet) { - /* - * If we got a packet on the broadcast socket and interfaces - * only is set then check it came from one of our local nets. - */ - if(lp_bind_interfaces_only() && (sock_array[i] == ClientNMB) && - (!is_local_net(packet->ip))) { - DEBUG(7,("discarding nmb packet sent to broadcast socket from %s:%d\n", - inet_ntoa(packet->ip),packet->port)); - free_packet(packet); - } else if ((ip_equal(loopback_ip, packet->ip) || - ismyip(packet->ip)) && packet->port == global_nmb_port && - packet->packet.nmb.header.nm_flags.bcast) { - DEBUG(7,("discarding own bcast packet from %s:%d\n", - inet_ntoa(packet->ip),packet->port)); - free_packet(packet); - } else { - /* Save the file descriptor this packet came in on. */ - packet->fd = sock_array[i]; - queue_packet(packet); - } - } - } - } else { - /* Processing a 138 socket. */ - if (FD_ISSET(sock_array[i],&fds)) { - struct packet_struct *packet = read_packet(sock_array[i], DGRAM_PACKET); - if (packet) { - /* - * If we got a packet on the broadcast socket and interfaces - * only is set then check it came from one of our local nets. - */ - if(lp_bind_interfaces_only() && (sock_array[i] == ClientDGRAM) && - (!is_local_net(packet->ip))) { - DEBUG(7,("discarding dgram packet sent to broadcast socket from %s:%d\n", - inet_ntoa(packet->ip),packet->port)); - free_packet(packet); - } else if ((ip_equal(loopback_ip, packet->ip) || - ismyip(packet->ip)) && packet->port == DGRAM_PORT) { - DEBUG(7,("discarding own dgram packet from %s:%d\n", - inet_ntoa(packet->ip),packet->port)); - free_packet(packet); - } else { - /* Save the file descriptor this packet came in on. */ - packet->fd = sock_array[i]; - queue_packet(packet); - } - } - } - } /* end processing 138 socket. */ - } /* end for */ - return False; + for(i = 0; i < listen_number; i++) { + if (i < (listen_number/2)) { + /* Processing a 137 socket. */ + if (FD_ISSET(sock_array[i],&fds)) { + struct packet_struct *packet = read_packet(sock_array[i], NMB_PACKET); + if (packet) { + /* + * If we got a packet on the broadcast socket and interfaces + * only is set then check it came from one of our local nets. + */ + if(lp_bind_interfaces_only() && (sock_array[i] == ClientNMB) && + (!is_local_net(packet->ip))) { + DEBUG(7,("discarding nmb packet sent to broadcast socket from %s:%d\n", + inet_ntoa(packet->ip),packet->port)); + free_packet(packet); + } else if ((ip_equal(loopback_ip, packet->ip) || + ismyip(packet->ip)) && packet->port == global_nmb_port && + packet->packet.nmb.header.nm_flags.bcast) { + DEBUG(7,("discarding own bcast packet from %s:%d\n", + inet_ntoa(packet->ip),packet->port)); + free_packet(packet); + } else { + /* Save the file descriptor this packet came in on. */ + packet->fd = sock_array[i]; + queue_packet(packet); + } + } + } + } else { + /* Processing a 138 socket. */ + if (FD_ISSET(sock_array[i],&fds)) { + struct packet_struct *packet = read_packet(sock_array[i], DGRAM_PACKET); + if (packet) { + /* + * If we got a packet on the broadcast socket and interfaces + * only is set then check it came from one of our local nets. + */ + if(lp_bind_interfaces_only() && (sock_array[i] == ClientDGRAM) && + (!is_local_net(packet->ip))) { + DEBUG(7,("discarding dgram packet sent to broadcast socket from %s:%d\n", + inet_ntoa(packet->ip),packet->port)); + free_packet(packet); + } else if ((ip_equal(loopback_ip, packet->ip) || + ismyip(packet->ip)) && packet->port == DGRAM_PORT) { + DEBUG(7,("discarding own dgram packet from %s:%d\n", + inet_ntoa(packet->ip),packet->port)); + free_packet(packet); + } else { + /* Save the file descriptor this packet came in on. */ + packet->fd = sock_array[i]; + queue_packet(packet); + } + } + } + } /* end processing 138 socket. */ + } /* end for */ + return False; } /**************************************************************************** Construct and send a netbios DGRAM. **************************************************************************/ + BOOL send_mailslot(BOOL unique, const char *mailslot,char *buf, size_t len, const char *srcname, int src_type, const char *dstname, int dest_type, struct in_addr dest_ip,struct in_addr src_ip, int dest_port) { - BOOL loopback_this_packet = False; - struct packet_struct p; - struct dgram_packet *dgram = &p.packet.dgram; - char *ptr,*p2; - char tmp[4]; - - memset((char *)&p,'\0',sizeof(p)); - - if(ismyip(dest_ip) && (dest_port == DGRAM_PORT)) /* Only if to DGRAM_PORT */ - loopback_this_packet = True; - - /* generate_name_trn_id(); */ /* Not used, so gone, RJS */ - - /* DIRECT GROUP or UNIQUE datagram. */ - dgram->header.msg_type = unique ? 0x10 : 0x11; - dgram->header.flags.node_type = M_NODE; - dgram->header.flags.first = True; - dgram->header.flags.more = False; - dgram->header.dgm_id = generate_name_trn_id(); - dgram->header.source_ip = src_ip; - dgram->header.source_port = DGRAM_PORT; - dgram->header.dgm_length = 0; /* Let build_dgram() handle this. */ - dgram->header.packet_offset = 0; + BOOL loopback_this_packet = False; + struct packet_struct p; + struct dgram_packet *dgram = &p.packet.dgram; + char *ptr,*p2; + char tmp[4]; + + memset((char *)&p,'\0',sizeof(p)); + + if(ismyip(dest_ip) && (dest_port == DGRAM_PORT)) /* Only if to DGRAM_PORT */ + loopback_this_packet = True; + + /* generate_name_trn_id(); */ /* Not used, so gone, RJS */ + + /* DIRECT GROUP or UNIQUE datagram. */ + dgram->header.msg_type = unique ? 0x10 : 0x11; + dgram->header.flags.node_type = M_NODE; + dgram->header.flags.first = True; + dgram->header.flags.more = False; + dgram->header.dgm_id = generate_name_trn_id(); + dgram->header.source_ip = src_ip; + dgram->header.source_port = DGRAM_PORT; + dgram->header.dgm_length = 0; /* Let build_dgram() handle this. */ + dgram->header.packet_offset = 0; - make_nmb_name(&dgram->source_name,srcname,src_type); - make_nmb_name(&dgram->dest_name,dstname,dest_type); - - ptr = &dgram->data[0]; - - /* Setup the smb part. */ - ptr -= 4; /* XXX Ugliness because of handling of tcp SMB length. */ - memcpy(tmp,ptr,4); - set_message(ptr,17,23 + len,True); - memcpy(ptr,tmp,4); - - SCVAL(ptr,smb_com,SMBtrans); - SSVAL(ptr,smb_vwv1,len); - SSVAL(ptr,smb_vwv11,len); - SSVAL(ptr,smb_vwv12,70 + strlen(mailslot)); - SSVAL(ptr,smb_vwv13,3); - SSVAL(ptr,smb_vwv14,1); - SSVAL(ptr,smb_vwv15,1); - SSVAL(ptr,smb_vwv16,2); - p2 = smb_buf(ptr); - safe_strcpy_base(p2, mailslot, dgram->data, sizeof(dgram->data)); - p2 = skip_string(p2,1); + make_nmb_name(&dgram->source_name,srcname,src_type); + make_nmb_name(&dgram->dest_name,dstname,dest_type); + + ptr = &dgram->data[0]; + + /* Setup the smb part. */ + ptr -= 4; /* XXX Ugliness because of handling of tcp SMB length. */ + memcpy(tmp,ptr,4); + set_message(ptr,17,23 + len,True); + memcpy(ptr,tmp,4); + + SCVAL(ptr,smb_com,SMBtrans); + SSVAL(ptr,smb_vwv1,len); + SSVAL(ptr,smb_vwv11,len); + SSVAL(ptr,smb_vwv12,70 + strlen(mailslot)); + SSVAL(ptr,smb_vwv13,3); + SSVAL(ptr,smb_vwv14,1); + SSVAL(ptr,smb_vwv15,1); + SSVAL(ptr,smb_vwv16,2); + p2 = smb_buf(ptr); + safe_strcpy_base(p2, mailslot, dgram->data, sizeof(dgram->data)); + p2 = skip_string(p2,1); - if (((p2+len) > dgram->data+sizeof(dgram->data)) || ((p2+len) < p2)) { - DEBUG(0, ("send_mailslot: Cannot write beyond end of packet\n")); - return False; - } else { - memcpy(p2,buf,len); - p2 += len; - } - - dgram->datasize = PTR_DIFF(p2,ptr+4); /* +4 for tcp length. */ - - p.ip = dest_ip; - p.port = dest_port; - p.fd = find_subnet_mailslot_fd_for_address( src_ip ); - p.timestamp = time(NULL); - p.packet_type = DGRAM_PACKET; - - DEBUG(4,("send_mailslot: Sending to mailslot %s from %s IP %s ", mailslot, - nmb_namestr(&dgram->source_name), inet_ntoa(src_ip))); - DEBUG(4,("to %s IP %s\n", nmb_namestr(&dgram->dest_name), inet_ntoa(dest_ip))); - - debug_browse_data(buf, len); - - if(loopback_this_packet) - { - struct packet_struct *lo_packet = NULL; - DEBUG(5,("send_mailslot: sending packet to ourselves.\n")); - if((lo_packet = copy_packet(&p)) == NULL) - return False; - queue_packet(lo_packet); - return True; - } - else - return(send_packet(&p)); + if (((p2+len) > dgram->data+sizeof(dgram->data)) || ((p2+len) < p2)) { + DEBUG(0, ("send_mailslot: Cannot write beyond end of packet\n")); + return False; + } else { + memcpy(p2,buf,len); + p2 += len; + } + + dgram->datasize = PTR_DIFF(p2,ptr+4); /* +4 for tcp length. */ + + p.ip = dest_ip; + p.port = dest_port; + p.fd = find_subnet_mailslot_fd_for_address( src_ip ); + p.timestamp = time(NULL); + p.packet_type = DGRAM_PACKET; + + DEBUG(4,("send_mailslot: Sending to mailslot %s from %s IP %s ", mailslot, + nmb_namestr(&dgram->source_name), inet_ntoa(src_ip))); + DEBUG(4,("to %s IP %s\n", nmb_namestr(&dgram->dest_name), inet_ntoa(dest_ip))); + + debug_browse_data(buf, len); + + if(loopback_this_packet) { + struct packet_struct *lo_packet = NULL; + DEBUG(5,("send_mailslot: sending packet to ourselves.\n")); + if((lo_packet = copy_packet(&p)) == NULL) + return False; + queue_packet(lo_packet); + return True; + } else { + return(send_packet(&p)); + } } diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index bc3540af70..2a6a6b66d1 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -3,7 +3,7 @@ NBT netbios routines and daemon - version 2 Copyright (C) Andrew Tridgell 1994-1998 Copyright (C) Luke Kenneth Casson Leighton 1994-1998 - Copyright (C) Jeremy Allison 1994-1998 + Copyright (C) Jeremy Allison 1994-2003 Copyright (C) Jim McDonough 2002 This program is free software; you can redistribute it and/or modify @@ -35,6 +35,7 @@ struct sam_database_info { /**************************************************************************** Send a message to smbd to do a sam delta sync **************************************************************************/ + static void send_repl_message(uint32 low_serial) { TDB_CONTEXT *tdb; @@ -64,432 +65,452 @@ Process a domain logon packet void process_logon_packet(struct packet_struct *p, char *buf,int len, const char *mailslot) { - struct dgram_packet *dgram = &p->packet.dgram; - pstring my_name; - fstring reply_name; - pstring outbuf; - int code; - uint16 token = 0; - uint32 ntversion = 0; - uint16 lmnttoken = 0; - uint16 lm20token = 0; - uint32 domainsidsize; - BOOL short_request = False; - char *getdc; - char *uniuser; /* Unicode user name. */ - pstring ascuser; - char *unicomp; /* Unicode computer name. */ - - memset(outbuf, 0, sizeof(outbuf)); - - if (!lp_domain_logons()) - { - DEBUG(3,("process_logon_packet: Logon packet received from IP %s and domain \ + struct dgram_packet *dgram = &p->packet.dgram; + pstring my_name; + fstring reply_name; + pstring outbuf; + int code; + uint16 token = 0; + uint32 ntversion = 0; + uint16 lmnttoken = 0; + uint16 lm20token = 0; + uint32 domainsidsize; + BOOL short_request = False; + char *getdc; + char *uniuser; /* Unicode user name. */ + pstring ascuser; + char *unicomp; /* Unicode computer name. */ + + memset(outbuf, 0, sizeof(outbuf)); + + if (!lp_domain_logons()) { + DEBUG(3,("process_logon_packet: Logon packet received from IP %s and domain \ logons are not enabled.\n", inet_ntoa(p->ip) )); - return; - } - - pstrcpy(my_name, global_myname()); - - code = SVAL(buf,0); - DEBUG(1,("process_logon_packet: Logon from %s: code = 0x%x\n", inet_ntoa(p->ip), code)); - - switch (code) - { - case 0: - { - char *q = buf + 2; - char *machine = q; - char *user = skip_string(machine,1); - - getdc = skip_string(user,1); - q = skip_string(getdc,1); - token = SVAL(q,3); - - fstrcpy(reply_name,my_name); - - DEBUG(3,("process_logon_packet: Domain login request from %s at IP %s user=%s token=%x\n", - machine,inet_ntoa(p->ip),user,token)); - - q = outbuf; - SSVAL(q, 0, 6); - q += 2; - - fstrcpy(reply_name, "\\\\"); - fstrcat(reply_name, my_name); - fstrcpy(q, reply_name); q = skip_string(q, 1); /* PDC name */ - - SSVAL(q, 0, token); - q += 2; - - dump_data(4, outbuf, PTR_DIFF(q, outbuf)); - - send_mailslot(True, getdc, - outbuf,PTR_DIFF(q,outbuf), - global_myname(), 0x0, - machine, - dgram->source_name.name_type, - p->ip, *iface_ip(p->ip), p->port); - break; - } - - case QUERYFORPDC: - { - char *q = buf + 2; - char *machine = q; - - if (!lp_domain_master()) - { - /* We're not Primary Domain Controller -- ignore this */ - return; - } - - getdc = skip_string(machine,1); - q = skip_string(getdc,1); - q = ALIGN2(q, buf); - - /* at this point we can work out if this is a W9X or NT style - request. Experiments show that the difference is wether the - packet ends here. For a W9X request we now end with a pair of - bytes (usually 0xFE 0xFF) whereas with NT we have two further - strings - the following is a simple way of detecting this */ - if (len - PTR_DIFF(q, buf) <= 3) { - short_request = True; - } else { - unicomp = q; - - /* A full length (NT style) request */ - q = skip_unibuf(unicomp, PTR_DIFF(buf + len, unicomp)); - - if (len - PTR_DIFF(q, buf) > 8) { + return; + } + + pstrcpy(my_name, global_myname()); + + code = SVAL(buf,0); + DEBUG(1,("process_logon_packet: Logon from %s: code = 0x%x\n", inet_ntoa(p->ip), code)); + + switch (code) { + case 0: + { + fstring mach_str, user_str, getdc_str; + char *q = buf + 2; + char *machine = q; + char *user = skip_string(machine,1); + + getdc = skip_string(user,1); + q = skip_string(getdc,1); + token = SVAL(q,3); + + fstrcpy(reply_name,my_name); + + pull_ascii_fstring(mach_str, machine); + pull_ascii_fstring(user_str, user); + pull_ascii_fstring(getdc_str, getdc); + + DEBUG(3,("process_logon_packet: Domain login request from %s at IP %s user=%s token=%x\n", + mach_str,inet_ntoa(p->ip),user_str,token)); + + q = outbuf; + SSVAL(q, 0, 6); + q += 2; + + fstrcpy(reply_name, "\\\\"); + fstrcat(reply_name, my_name); + push_ascii_fstring(q, reply_name); + q = skip_string(q, 1); /* PDC name */ + + SSVAL(q, 0, token); + q += 2; + + dump_data(4, outbuf, PTR_DIFF(q, outbuf)); + + send_mailslot(True, getdc_str, + outbuf,PTR_DIFF(q,outbuf), + global_myname(), 0x0, + mach_str, + dgram->source_name.name_type, + p->ip, *iface_ip(p->ip), p->port); + break; + } + + case QUERYFORPDC: + { + fstring mach_str, getdc_str; + nstring source_name; + char *q = buf + 2; + char *machine = q; + + if (!lp_domain_master()) { + /* We're not Primary Domain Controller -- ignore this */ + return; + } + + getdc = skip_string(machine,1); + q = skip_string(getdc,1); + q = ALIGN2(q, buf); + + /* At this point we can work out if this is a W9X or NT style + request. Experiments show that the difference is wether the + packet ends here. For a W9X request we now end with a pair of + bytes (usually 0xFE 0xFF) whereas with NT we have two further + strings - the following is a simple way of detecting this */ + + if (len - PTR_DIFF(q, buf) <= 3) { + short_request = True; + } else { + unicomp = q; + + /* A full length (NT style) request */ + q = skip_unibuf(unicomp, PTR_DIFF(buf + len, unicomp)); + + if (len - PTR_DIFF(q, buf) > 8) { + /* with NT5 clients we can sometimes + get additional data - a length specificed string + containing the domain name, then 16 bytes of + data (no idea what it is) */ + int dom_len = CVAL(q, 0); + q++; + if (dom_len != 0) { + q += dom_len + 1; + } + q += 16; + } + ntversion = IVAL(q, 0); + lmnttoken = SVAL(q, 4); + lm20token = SVAL(q, 6); + } + + /* Construct reply. */ + q = outbuf; + SSVAL(q, 0, QUERYFORPDC_R); + q += 2; + + fstrcpy(reply_name,my_name); + push_ascii_fstring(q, reply_name); + q = skip_string(q, 1); /* PDC name */ + + /* PDC and domain name */ + if (!short_request) { + /* Make a full reply */ + q = ALIGN2(q, outbuf); + + q += dos_PutUniCode(q, my_name, sizeof(pstring), True); /* PDC name */ + q += dos_PutUniCode(q, lp_workgroup(),sizeof(pstring), True); /* Domain name*/ + SIVAL(q, 0, 1); /* our nt version */ + SSVAL(q, 4, 0xffff); /* our lmnttoken */ + SSVAL(q, 6, 0xffff); /* our lm20token */ + q += 8; + } + + /* RJS, 21-Feb-2000, we send a short reply if the request was short */ + + pull_ascii_fstring(mach_str, machine); + + DEBUG(3,("process_logon_packet: GETDC request from %s at IP %s, \ +reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", + mach_str,inet_ntoa(p->ip), reply_name, lp_workgroup(), + QUERYFORPDC_R, (uint32)ntversion, (uint32)lmnttoken, + (uint32)lm20token )); + + dump_data(4, outbuf, PTR_DIFF(q, outbuf)); + + pull_ascii_fstring(getdc_str, getdc); + pull_ascii_nstring(source_name, dgram->source_name.name); + + send_mailslot(True, getdc_str, + outbuf,PTR_DIFF(q,outbuf), + global_myname(), 0x0, + source_name, + dgram->source_name.name_type, + p->ip, *iface_ip(p->ip), p->port); + return; + } + + case SAMLOGON: + + { + fstring getdc_str; + nstring source_name; + char *q = buf + 2; + fstring asccomp; + + q += 2; + unicomp = q; + uniuser = skip_unibuf(unicomp, PTR_DIFF(buf+len, unicomp)); + getdc = skip_unibuf(uniuser,PTR_DIFF(buf+len, uniuser)); + q = skip_string(getdc,1); + q += 4; /* Account Control Bits - indicating username type */ + domainsidsize = IVAL(q, 0); + q += 4; + + DEBUG(3,("process_logon_packet: SAMLOGON sidsize %d, len = %d\n", domainsidsize, len)); + + if (domainsidsize < (len - PTR_DIFF(q, buf)) && (domainsidsize != 0)) { + q += domainsidsize; + q = ALIGN4(q, buf); + } + + DEBUG(3,("process_logon_packet: len = %d PTR_DIFF(q, buf) = %d\n", len, PTR_DIFF(q, buf) )); + + if (len - PTR_DIFF(q, buf) > 8) { /* with NT5 clients we can sometimes - get additional data - a length specificed string - containing the domain name, then 16 bytes of - data (no idea what it is) */ + get additional data - a length specificed string + containing the domain name, then 16 bytes of + data (no idea what it is) */ int dom_len = CVAL(q, 0); q++; - if (dom_len != 0) { + if (dom_len < (len - PTR_DIFF(q, buf)) && (dom_len != 0)) { q += dom_len + 1; } q += 16; - } - ntversion = IVAL(q, 0); - lmnttoken = SVAL(q, 4); - lm20token = SVAL(q, 6); - } - - /* Construct reply. */ - q = outbuf; - SSVAL(q, 0, QUERYFORPDC_R); - q += 2; - - fstrcpy(reply_name,my_name); - fstrcpy(q, reply_name); - q = skip_string(q, 1); /* PDC name */ - - /* PDC and domain name */ - if (!short_request) /* Make a full reply */ - { - q = ALIGN2(q, outbuf); - - q += dos_PutUniCode(q, my_name, sizeof(pstring), True); /* PDC name */ - q += dos_PutUniCode(q, lp_workgroup(),sizeof(pstring), True); /* Domain name*/ - SIVAL(q, 0, 1); /* our nt version */ - SSVAL(q, 4, 0xffff); /* our lmnttoken */ - SSVAL(q, 6, 0xffff); /* our lm20token */ - q += 8; - } - - /* RJS, 21-Feb-2000, we send a short reply if the request was short */ - - DEBUG(3,("process_logon_packet: GETDC request from %s at IP %s, \ -reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", - machine,inet_ntoa(p->ip), reply_name, lp_workgroup(), - QUERYFORPDC_R, (uint32)ntversion, (uint32)lmnttoken, - (uint32)lm20token )); - - dump_data(4, outbuf, PTR_DIFF(q, outbuf)); - - send_mailslot(True, getdc, - outbuf,PTR_DIFF(q,outbuf), - global_myname(), 0x0, - dgram->source_name.name, - dgram->source_name.name_type, - p->ip, *iface_ip(p->ip), p->port); - return; - } - - case SAMLOGON: - { - char *q = buf + 2; - fstring asccomp; - - q += 2; - unicomp = q; - uniuser = skip_unibuf(unicomp, PTR_DIFF(buf+len, unicomp)); - getdc = skip_unibuf(uniuser,PTR_DIFF(buf+len, uniuser)); - q = skip_string(getdc,1); - q += 4; /* Account Control Bits - indicating username type */ - domainsidsize = IVAL(q, 0); - q += 4; - - DEBUG(3,("process_logon_packet: SAMLOGON sidsize %d, len = %d\n", domainsidsize, len)); - - if (domainsidsize < (len - PTR_DIFF(q, buf)) && (domainsidsize != 0)) { - q += domainsidsize; - q = ALIGN4(q, buf); - } - - DEBUG(3,("process_logon_packet: len = %d PTR_DIFF(q, buf) = %d\n", len, PTR_DIFF(q, buf) )); - - if (len - PTR_DIFF(q, buf) > 8) { - /* with NT5 clients we can sometimes - get additional data - a length specificed string - containing the domain name, then 16 bytes of - data (no idea what it is) */ - int dom_len = CVAL(q, 0); - q++; - if (dom_len < (len - PTR_DIFF(q, buf)) && (dom_len != 0)) { - q += dom_len + 1; - } - q += 16; - } - - ntversion = IVAL(q, 0); - lmnttoken = SVAL(q, 4); - lm20token = SVAL(q, 6); - q += 8; - - DEBUG(3,("process_logon_packet: SAMLOGON sidsize %d ntv %d\n", domainsidsize, ntversion)); - - /* - * we respond regadless of whether the machine is in our password - * database. If it isn't then we let smbd send an appropriate error. - * Let's ignore the SID. - */ - pull_ucs2_pstring(ascuser, uniuser); - pull_ucs2_fstring(asccomp, unicomp); - DEBUG(3,("process_logon_packet: SAMLOGON user %s\n", ascuser)); - - fstrcpy(reply_name, "\\\\"); /* Here it wants \\LOGONSERVER. */ - fstrcat(reply_name, my_name); - - DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n", - asccomp,inet_ntoa(p->ip), ascuser, reply_name, lp_workgroup(), - SAMLOGON_R ,lmnttoken)); - - /* Construct reply. */ - - q = outbuf; - /* we want the simple version unless we are an ADS PDC..which means */ - /* never, at least for now */ - if ((ntversion < 11) || (SEC_ADS != lp_security()) || (ROLE_DOMAIN_PDC != lp_server_role())) { - if (SVAL(uniuser, 0) == 0) { - SSVAL(q, 0, SAMLOGON_UNK_R); /* user unknown */ - } else { - SSVAL(q, 0, SAMLOGON_R); - } + } + + ntversion = IVAL(q, 0); + lmnttoken = SVAL(q, 4); + lm20token = SVAL(q, 6); + q += 8; + + DEBUG(3,("process_logon_packet: SAMLOGON sidsize %d ntv %d\n", domainsidsize, ntversion)); + + /* + * we respond regadless of whether the machine is in our password + * database. If it isn't then we let smbd send an appropriate error. + * Let's ignore the SID. + */ + pull_ucs2_pstring(ascuser, uniuser); + pull_ucs2_fstring(asccomp, unicomp); + DEBUG(3,("process_logon_packet: SAMLOGON user %s\n", ascuser)); + + fstrcpy(reply_name, "\\\\"); /* Here it wants \\LOGONSERVER. */ + fstrcat(reply_name, my_name); + + DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n", + asccomp,inet_ntoa(p->ip), ascuser, reply_name, lp_workgroup(), + SAMLOGON_R ,lmnttoken)); + + /* Construct reply. */ + + q = outbuf; + /* we want the simple version unless we are an ADS PDC..which means */ + /* never, at least for now */ + if ((ntversion < 11) || (SEC_ADS != lp_security()) || (ROLE_DOMAIN_PDC != lp_server_role())) { + if (SVAL(uniuser, 0) == 0) { + SSVAL(q, 0, SAMLOGON_UNK_R); /* user unknown */ + } else { + SSVAL(q, 0, SAMLOGON_R); + } - q += 2; + q += 2; - q += dos_PutUniCode(q, reply_name,sizeof(pstring), True); - q += dos_PutUniCode(q, ascuser, sizeof(pstring), True); - q += dos_PutUniCode(q, lp_workgroup(),sizeof(pstring), True); - } + q += dos_PutUniCode(q, reply_name,sizeof(pstring), True); + q += dos_PutUniCode(q, ascuser, sizeof(pstring), True); + q += dos_PutUniCode(q, lp_workgroup(),sizeof(pstring), True); + } #ifdef HAVE_ADS - else { - GUID domain_guid; - pstring domain; - pstring hostname; - char *component, *dc, *q1; - uint8 size; - char *q_orig = q; - int str_offset; - - get_mydomname(domain); - get_myname(hostname); + else { + GUID domain_guid; + pstring domain; + pstring hostname; + char *component, *dc, *q1; + uint8 size; + char *q_orig = q; + int str_offset; + + get_mydomname(domain); + get_myname(hostname); - if (SVAL(uniuser, 0) == 0) { - SIVAL(q, 0, SAMLOGON_AD_UNK_R); /* user unknown */ - } else { - SIVAL(q, 0, SAMLOGON_AD_R); - } - q += 4; + if (SVAL(uniuser, 0) == 0) { + SIVAL(q, 0, SAMLOGON_AD_UNK_R); /* user unknown */ + } else { + SIVAL(q, 0, SAMLOGON_AD_R); + } + q += 4; - SIVAL(q, 0, ADS_PDC|ADS_GC|ADS_LDAP|ADS_DS| - ADS_KDC|ADS_TIMESERV|ADS_CLOSEST|ADS_WRITABLE); - q += 4; + SIVAL(q, 0, ADS_PDC|ADS_GC|ADS_LDAP|ADS_DS| + ADS_KDC|ADS_TIMESERV|ADS_CLOSEST|ADS_WRITABLE); + q += 4; - /* Push Domain GUID */ - if (False == secrets_fetch_domain_guid(domain, &domain_guid)) { - DEBUG(2, ("Could not fetch DomainGUID for %s\n", domain)); - return; - } - memcpy(q, &domain_guid, sizeof(domain_guid)); - q += sizeof(domain_guid); - - /* Forest */ - str_offset = q - q_orig; - dc = domain; - q1 = q; - while ((component = strtok(dc, "."))) { - dc = NULL; - size = push_ascii(&q[1], component, -1, 0); - SCVAL(q, 0, size); - q += (size + 1); - } + /* Push Domain GUID */ + if (False == secrets_fetch_domain_guid(domain, &domain_guid)) { + DEBUG(2, ("Could not fetch DomainGUID for %s\n", domain)); + return; + } + memcpy(q, &domain_guid, sizeof(domain_guid)); + q += sizeof(domain_guid); + + /* Forest */ + str_offset = q - q_orig; + dc = domain; + q1 = q; + while ((component = strtok(dc, "."))) { + dc = NULL; + size = push_ascii(&q[1], component, -1, 0); + SCVAL(q, 0, size); + q += (size + 1); + } - /* Unk0 */ - SCVAL(q, 0, 0); q++; - - /* Domain */ - SCVAL(q, 0, 0xc0 | ((str_offset >> 8) & 0x3F)); - SCVAL(q, 1, str_offset & 0xFF); - q += 2; - - /* Hostname */ - size = push_ascii(&q[1], hostname, -1, 0); - SCVAL(q, 0, size); - q += (size + 1); - SCVAL(q, 0, 0xc0 | ((str_offset >> 8) & 0x3F)); - SCVAL(q, 1, str_offset & 0xFF); - q += 2; - - /* NETBIOS of domain */ - size = push_ascii(&q[1], lp_workgroup(), -1, STR_UPPER); - SCVAL(q, 0, size); - q += (size + 1); - - /* Unk1 */ - SCVAL(q, 0, 0); q++; - - /* NETBIOS of hostname */ - size = push_ascii(&q[1], my_name, -1, 0); - SCVAL(q, 0, size); - q += (size + 1); - - /* Unk2 */ - SCVAL(q, 0, 0); q++; - - /* User name */ - if (SVAL(uniuser, 0) != 0) { - size = push_ascii(&q[1], ascuser, -1, 0); - SCVAL(q, 0, size); - q += (size + 1); - } + /* Unk0 */ + SCVAL(q, 0, 0); + q++; - q_orig = q; - /* Site name */ - size = push_ascii(&q[1], "Default-First-Site-Name", -1, 0); - SCVAL(q, 0, size); - q += (size + 1); - - /* Site name (2) */ - str_offset = q - q_orig; - SCVAL(q, 0, 0xc0 | ((str_offset >> 8) & 0x3F)); - SCVAL(q, 1, str_offset & 0xFF); - q += 2; - - SCVAL(q, 0, PTR_DIFF(q,q1)); - SCVAL(q, 1, 0x10); /* unknown */ - - SIVAL(q, 0, 0x00000002); q += 4; /* unknown */ - SIVAL(q, 0, (iface_ip(p->ip))->s_addr); q += 4; - SIVAL(q, 0, 0x00000000); q += 4; /* unknown */ - SIVAL(q, 0, 0x00000000); q += 4; /* unknown */ - } + /* Domain */ + SCVAL(q, 0, 0xc0 | ((str_offset >> 8) & 0x3F)); + SCVAL(q, 1, str_offset & 0xFF); + q += 2; + + /* Hostname */ + size = push_ascii(&q[1], hostname, -1, 0); + SCVAL(q, 0, size); + q += (size + 1); + SCVAL(q, 0, 0xc0 | ((str_offset >> 8) & 0x3F)); + SCVAL(q, 1, str_offset & 0xFF); + q += 2; + + /* NETBIOS of domain */ + size = push_ascii(&q[1], lp_workgroup(), -1, STR_UPPER); + SCVAL(q, 0, size); + q += (size + 1); + + /* Unk1 */ + SCVAL(q, 0, 0); + q++; + + /* NETBIOS of hostname */ + size = push_ascii(&q[1], my_name, -1, 0); + SCVAL(q, 0, size); + q += (size + 1); + + /* Unk2 */ + SCVAL(q, 0, 0); + q++; + + /* User name */ + if (SVAL(uniuser, 0) != 0) { + size = push_ascii(&q[1], ascuser, -1, 0); + SCVAL(q, 0, size); + q += (size + 1); + } + + q_orig = q; + /* Site name */ + size = push_ascii(&q[1], "Default-First-Site-Name", -1, 0); + SCVAL(q, 0, size); + q += (size + 1); + + /* Site name (2) */ + str_offset = q - q_orig; + SCVAL(q, 0, 0xc0 | ((str_offset >> 8) & 0x3F)); + SCVAL(q, 1, str_offset & 0xFF); + q += 2; + + SCVAL(q, 0, PTR_DIFF(q,q1)); + SCVAL(q, 1, 0x10); /* unknown */ + + SIVAL(q, 0, 0x00000002); + q += 4; /* unknown */ + SIVAL(q, 0, (iface_ip(p->ip))->s_addr); + q += 4; + SIVAL(q, 0, 0x00000000); + q += 4; /* unknown */ + SIVAL(q, 0, 0x00000000); + q += 4; /* unknown */ + } #endif - /* tell the client what version we are */ - SIVAL(q, 0, ((ntversion < 11) || (SEC_ADS != lp_security())) ? 1 : 13); - /* our ntversion */ - SSVAL(q, 4, 0xffff); /* our lmnttoken */ - SSVAL(q, 6, 0xffff); /* our lm20token */ - q += 8; - - dump_data(4, outbuf, PTR_DIFF(q, outbuf)); - - send_mailslot(True, getdc, - outbuf,PTR_DIFF(q,outbuf), - global_myname(), 0x0, - dgram->source_name.name, - dgram->source_name.name_type, - p->ip, *iface_ip(p->ip), p->port); - break; - } - - /* Announce change to UAS or SAM. Send by the domain controller when a - replication event is required. */ - - case SAM_UAS_CHANGE: { - struct sam_database_info *db_info; - char *q = buf + 2; - int i, db_count; - uint32 low_serial; + /* tell the client what version we are */ + SIVAL(q, 0, ((ntversion < 11) || (SEC_ADS != lp_security())) ? 1 : 13); + /* our ntversion */ + SSVAL(q, 4, 0xffff); /* our lmnttoken */ + SSVAL(q, 6, 0xffff); /* our lm20token */ + q += 8; + + dump_data(4, outbuf, PTR_DIFF(q, outbuf)); + + pull_ascii_fstring(getdc_str, getdc); + pull_ascii_nstring(source_name, dgram->source_name.name); + + send_mailslot(True, getdc, + outbuf,PTR_DIFF(q,outbuf), + global_myname(), 0x0, + dgram->source_name.name, + dgram->source_name.name_type, + p->ip, *iface_ip(p->ip), p->port); + break; + } + + /* Announce change to UAS or SAM. Send by the domain controller when a + replication event is required. */ + + case SAM_UAS_CHANGE: + { + struct sam_database_info *db_info; + char *q = buf + 2; + int i, db_count; + uint32 low_serial; - /* Header */ + /* Header */ - low_serial = IVAL(q, 0); q += 4; /* Low serial number */ + low_serial = IVAL(q, 0); q += 4; /* Low serial number */ - q += 4; /* Date/time */ - q += 4; /* Pulse */ - q += 4; /* Random */ + q += 4; /* Date/time */ + q += 4; /* Pulse */ + q += 4; /* Random */ - /* Domain info */ + /* Domain info */ - q = skip_string(q, 1); /* PDC name */ - q = skip_string(q, 1); /* Domain name */ - q = skip_unibuf(q, PTR_DIFF(buf + len, q)); /* Unicode PDC name */ - q = skip_unibuf(q, PTR_DIFF(buf + len, q)); /* Unicode domain name */ + q = skip_string(q, 1); /* PDC name */ + q = skip_string(q, 1); /* Domain name */ + q = skip_unibuf(q, PTR_DIFF(buf + len, q)); /* Unicode PDC name */ + q = skip_unibuf(q, PTR_DIFF(buf + len, q)); /* Unicode domain name */ - /* Database info */ + /* Database info */ - db_count = SVAL(q, 0); q += 2; + db_count = SVAL(q, 0); q += 2; - db_info = (struct sam_database_info *) - malloc(sizeof(struct sam_database_info) * db_count); - - if (db_info == NULL) { - DEBUG(3, ("out of memory allocating info for %d databases\n", - db_count)); - return; - } + db_info = (struct sam_database_info *) + malloc(sizeof(struct sam_database_info) * db_count); + + if (db_info == NULL) { + DEBUG(3, ("out of memory allocating info for %d databases\n", db_count)); + return; + } - for (i = 0; i < db_count; i++) { - db_info[i].index = IVAL(q, 0); - db_info[i].serial_lo = IVAL(q, 4); - db_info[i].serial_hi = IVAL(q, 8); - db_info[i].date_lo = IVAL(q, 12); - db_info[i].date_hi = IVAL(q, 16); - q += 20; - } - - /* Domain SID */ - - q += IVAL(q, 0) + 4; /* 4 byte length plus data */ + for (i = 0; i < db_count; i++) { + db_info[i].index = IVAL(q, 0); + db_info[i].serial_lo = IVAL(q, 4); + db_info[i].serial_hi = IVAL(q, 8); + db_info[i].date_lo = IVAL(q, 12); + db_info[i].date_hi = IVAL(q, 16); + q += 20; + } + + /* Domain SID */ + + q += IVAL(q, 0) + 4; /* 4 byte length plus data */ - q += 2; /* Alignment? */ - - /* Misc other info */ + q += 2; /* Alignment? */ - q += 4; /* NT version (0x1) */ - q += 2; /* LMNT token (0xff) */ - q += 2; /* LM20 token (0xff) */ + /* Misc other info */ - SAFE_FREE(db_info); /* Not sure whether we need to do anything - useful with these */ + q += 4; /* NT version (0x1) */ + q += 2; /* LMNT token (0xff) */ + q += 2; /* LM20 token (0xff) */ - /* Send message to smbd */ + SAFE_FREE(db_info); /* Not sure whether we need to do anything useful with these */ - send_repl_message(low_serial); + /* Send message to smbd */ - break; - } + send_repl_message(low_serial); + break; + } - default: - { - DEBUG(3,("process_logon_packet: Unknown domain request %d\n",code)); - return; - } - } + default: + DEBUG(3,("process_logon_packet: Unknown domain request %d\n",code)); + return; + } } diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index 7e8c8025ae..30c0c12950 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -34,27 +34,26 @@ int num_response_packets = 0; static void add_response_record(struct subnet_record *subrec, struct response_record *rrec) { - struct response_record *rrec2; + struct response_record *rrec2; - num_response_packets++; /* count of total number of packets still around */ + num_response_packets++; /* count of total number of packets still around */ - DEBUG(4,("add_response_record: adding response record id:%hu to subnet %s. num_records:%d\n", - rrec->response_id, subrec->subnet_name, num_response_packets)); + DEBUG(4,("add_response_record: adding response record id:%hu to subnet %s. num_records:%d\n", + rrec->response_id, subrec->subnet_name, num_response_packets)); - if (!subrec->responselist) - { - subrec->responselist = rrec; - rrec->prev = NULL; - rrec->next = NULL; - return; - } + if (!subrec->responselist) { + subrec->responselist = rrec; + rrec->prev = NULL; + rrec->next = NULL; + return; + } - for (rrec2 = subrec->responselist; rrec2->next; rrec2 = rrec2->next) - ; + for (rrec2 = subrec->responselist; rrec2->next; rrec2 = rrec2->next) + ; - rrec2->next = rrec; - rrec->next = NULL; - rrec->prev = rrec2; + rrec2->next = rrec; + rrec->next = NULL; + rrec->prev = rrec2; } /*************************************************************************** @@ -64,32 +63,31 @@ static void add_response_record(struct subnet_record *subrec, void remove_response_record(struct subnet_record *subrec, struct response_record *rrec) { - if (rrec->prev) - rrec->prev->next = rrec->next; - if (rrec->next) - rrec->next->prev = rrec->prev; - - if (subrec->responselist == rrec) - subrec->responselist = rrec->next; - - if(rrec->userdata) - { - if(rrec->userdata->free_fn) { - (*rrec->userdata->free_fn)(rrec->userdata); - } else { - ZERO_STRUCTP(rrec->userdata); - SAFE_FREE(rrec->userdata); - } - } - - /* Ensure we can delete. */ - rrec->packet->locked = False; - free_packet(rrec->packet); - - ZERO_STRUCTP(rrec); - SAFE_FREE(rrec); - - num_response_packets--; /* count of total number of packets still around */ + if (rrec->prev) + rrec->prev->next = rrec->next; + if (rrec->next) + rrec->next->prev = rrec->prev; + + if (subrec->responselist == rrec) + subrec->responselist = rrec->next; + + if(rrec->userdata) { + if(rrec->userdata->free_fn) { + (*rrec->userdata->free_fn)(rrec->userdata); + } else { + ZERO_STRUCTP(rrec->userdata); + SAFE_FREE(rrec->userdata); + } + } + + /* Ensure we can delete. */ + rrec->packet->locked = False; + free_packet(rrec->packet); + + ZERO_STRUCTP(rrec); + SAFE_FREE(rrec); + + num_response_packets--; /* count of total number of packets still around */ } /**************************************************************************** @@ -104,77 +102,70 @@ struct response_record *make_response_record( struct subnet_record *subrec, fail_function fail_fn, struct userdata_struct *userdata) { - struct response_record *rrec; - struct nmb_packet *nmb = &p->packet.nmb; - - if (!(rrec = (struct response_record *)malloc(sizeof(*rrec)))) - { - DEBUG(0,("make_response_queue_record: malloc fail for response_record.\n")); - return NULL; - } - - memset((char *)rrec, '\0', sizeof(*rrec)); - - rrec->response_id = nmb->header.name_trn_id; - - rrec->resp_fn = resp_fn; - rrec->timeout_fn = timeout_fn; - rrec->success_fn = success_fn; - rrec->fail_fn = fail_fn; - - rrec->packet = p; - - if(userdata) - { - /* Intelligent userdata. */ - if(userdata->copy_fn) - { - if((rrec->userdata = (*userdata->copy_fn)(userdata)) == NULL) - { - DEBUG(0,("make_response_queue_record: copy fail for userdata.\n")); - ZERO_STRUCTP(rrec); - SAFE_FREE(rrec); - return NULL; - } - } - else - { - /* Primitive userdata, do a memcpy. */ - if((rrec->userdata = (struct userdata_struct *) - malloc(sizeof(struct userdata_struct)+userdata->userdata_len)) == NULL) - { - DEBUG(0,("make_response_queue_record: malloc fail for userdata.\n")); - ZERO_STRUCTP(rrec); - SAFE_FREE(rrec); - return NULL; - } - rrec->userdata->copy_fn = userdata->copy_fn; - rrec->userdata->free_fn = userdata->free_fn; - rrec->userdata->userdata_len = userdata->userdata_len; - memcpy(rrec->userdata->data, userdata->data, userdata->userdata_len); - } - } - else - rrec->userdata = NULL; - - rrec->num_msgs = 0; - - if(!nmb->header.nm_flags.bcast) - rrec->repeat_interval = 5; /* 5 seconds for unicast packets. */ - else - rrec->repeat_interval = 1; /* XXXX should be in ms */ - rrec->repeat_count = 3; /* 3 retries */ - rrec->repeat_time = time(NULL) + rrec->repeat_interval; /* initial retry time */ - - /* This packet is not being processed. */ - rrec->in_expiration_processing = False; - - /* Lock the packet so we won't lose it while it's on the list. */ - p->locked = True; - - add_response_record(subrec, rrec); - - return rrec; + struct response_record *rrec; + struct nmb_packet *nmb = &p->packet.nmb; + + if (!(rrec = (struct response_record *)malloc(sizeof(*rrec)))) { + DEBUG(0,("make_response_queue_record: malloc fail for response_record.\n")); + return NULL; + } + + memset((char *)rrec, '\0', sizeof(*rrec)); + + rrec->response_id = nmb->header.name_trn_id; + + rrec->resp_fn = resp_fn; + rrec->timeout_fn = timeout_fn; + rrec->success_fn = success_fn; + rrec->fail_fn = fail_fn; + + rrec->packet = p; + + if(userdata) { + /* Intelligent userdata. */ + if(userdata->copy_fn) { + if((rrec->userdata = (*userdata->copy_fn)(userdata)) == NULL) { + DEBUG(0,("make_response_queue_record: copy fail for userdata.\n")); + ZERO_STRUCTP(rrec); + SAFE_FREE(rrec); + return NULL; + } + } else { + /* Primitive userdata, do a memcpy. */ + if((rrec->userdata = (struct userdata_struct *) + malloc(sizeof(struct userdata_struct)+userdata->userdata_len)) == NULL) { + DEBUG(0,("make_response_queue_record: malloc fail for userdata.\n")); + ZERO_STRUCTP(rrec); + SAFE_FREE(rrec); + return NULL; + } + rrec->userdata->copy_fn = userdata->copy_fn; + rrec->userdata->free_fn = userdata->free_fn; + rrec->userdata->userdata_len = userdata->userdata_len; + memcpy(rrec->userdata->data, userdata->data, userdata->userdata_len); + } + } else { + rrec->userdata = NULL; + } + + rrec->num_msgs = 0; + + if(!nmb->header.nm_flags.bcast) + rrec->repeat_interval = 5; /* 5 seconds for unicast packets. */ + else + rrec->repeat_interval = 1; /* XXXX should be in ms */ + rrec->repeat_count = 3; /* 3 retries */ + rrec->repeat_time = time(NULL) + rrec->repeat_interval; /* initial retry time */ + + /* This packet is not being processed. */ + rrec->in_expiration_processing = False; + + /* Lock the packet so we won't lose it while it's on the list. */ + p->locked = True; + + add_response_record(subrec, rrec); + + return rrec; } /**************************************************************************** @@ -184,18 +175,16 @@ struct response_record *make_response_record( struct subnet_record *subrec, static struct response_record *find_response_record_on_subnet( struct subnet_record *subrec, uint16 id) { - struct response_record *rrec = NULL; - - for (rrec = subrec->responselist; rrec; rrec = rrec->next) - { - if (rrec->response_id == id) - { - DEBUG(4, ("find_response_record: found response record id = %hu on subnet %s\n", - id, subrec->subnet_name)); - break; - } - } - return rrec; + struct response_record *rrec = NULL; + + for (rrec = subrec->responselist; rrec; rrec = rrec->next) { + if (rrec->response_id == id) { + DEBUG(4, ("find_response_record: found response record id = %hu on subnet %s\n", + id, subrec->subnet_name)); + break; + } + } + return rrec; } /**************************************************************************** @@ -205,37 +194,34 @@ static struct response_record *find_response_record_on_subnet( struct response_record *find_response_record(struct subnet_record **ppsubrec, uint16 id) { - struct response_record *rrec = NULL; - - for ((*ppsubrec) = FIRST_SUBNET; (*ppsubrec); - (*ppsubrec) = NEXT_SUBNET_INCLUDING_UNICAST(*ppsubrec)) - { - if((rrec = find_response_record_on_subnet(*ppsubrec, id)) != NULL) - return rrec; - } - - /* There should never be response records on the remote_broadcast subnet. - Sanity check to ensure this is so. */ - if(remote_broadcast_subnet->responselist != NULL) - { - DEBUG(0,("find_response_record: response record found on subnet %s. This should \ + struct response_record *rrec = NULL; + + for ((*ppsubrec) = FIRST_SUBNET; (*ppsubrec); + (*ppsubrec) = NEXT_SUBNET_INCLUDING_UNICAST(*ppsubrec)) { + if((rrec = find_response_record_on_subnet(*ppsubrec, id)) != NULL) + return rrec; + } + + /* There should never be response records on the remote_broadcast subnet. + Sanity check to ensure this is so. */ + if(remote_broadcast_subnet->responselist != NULL) { + DEBUG(0,("find_response_record: response record found on subnet %s. This should \ never happen !\n", remote_broadcast_subnet->subnet_name)); - } + } - /* Now check the WINS server subnet if it exists. */ - if(wins_server_subnet != NULL) - { - *ppsubrec = wins_server_subnet; - if((rrec = find_response_record_on_subnet(*ppsubrec, id))!= NULL) - return rrec; - } + /* Now check the WINS server subnet if it exists. */ + if(wins_server_subnet != NULL) { + *ppsubrec = wins_server_subnet; + if((rrec = find_response_record_on_subnet(*ppsubrec, id))!= NULL) + return rrec; + } - DEBUG(0,("find_response_record: response packet id %hu received with no \ + DEBUG(0,("find_response_record: response packet id %hu received with no \ matching record.\n", id)); - *ppsubrec = NULL; + *ppsubrec = NULL; - return NULL; + return NULL; } /**************************************************************************** @@ -244,21 +230,19 @@ matching record.\n", id)); BOOL is_refresh_already_queued(struct subnet_record *subrec, struct name_record *namerec) { - struct response_record *rrec = NULL; + struct response_record *rrec = NULL; - for (rrec = subrec->responselist; rrec; rrec = rrec->next) - { - struct packet_struct *p = rrec->packet; - struct nmb_packet *nmb = &p->packet.nmb; - - if((nmb->header.opcode == NMB_NAME_REFRESH_OPCODE_8) || - (nmb->header.opcode == NMB_NAME_REFRESH_OPCODE_9)) - { - /* Yes it's a queued refresh - check if the name is correct. */ - if(nmb_name_equal(&nmb->question.question_name, &namerec->name)) - return True; - } - } - - return False; -} + for (rrec = subrec->responselist; rrec; rrec = rrec->next) { + struct packet_struct *p = rrec->packet; + struct nmb_packet *nmb = &p->packet.nmb; + + if((nmb->header.opcode == NMB_NAME_REFRESH_OPCODE_8) || + (nmb->header.opcode == NMB_NAME_REFRESH_OPCODE_9)) { + /* Yes it's a queued refresh - check if the name is correct. */ + if(nmb_name_equal(&nmb->question.question_name, &namerec->name)) + return True; + } + } + + return False; +} diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index 353717ee62..87908e352c 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -35,21 +35,21 @@ extern BOOL found_lm_clients; void send_browser_reset(int reset_type, const char *to_name, int to_type, struct in_addr to_ip) { - pstring outbuf; - char *p; + pstring outbuf; + char *p; - DEBUG(3,("send_browser_reset: sending reset request type %d to %s<%02x> IP %s.\n", - reset_type, to_name, to_type, inet_ntoa(to_ip) )); + DEBUG(3,("send_browser_reset: sending reset request type %d to %s<%02x> IP %s.\n", + reset_type, to_name, to_type, inet_ntoa(to_ip) )); - memset(outbuf,'\0',sizeof(outbuf)); - p = outbuf; - SCVAL(p,0,ANN_ResetBrowserState); - p++; - SCVAL(p,0,reset_type); - p++; + memset(outbuf,'\0',sizeof(outbuf)); + p = outbuf; + SCVAL(p,0,ANN_ResetBrowserState); + p++; + SCVAL(p,0,reset_type); + p++; - send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), - global_myname(), 0x0, to_name, to_type, to_ip, + send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), + global_myname(), 0x0, to_name, to_type, to_ip, FIRST_SUBNET->myip, DGRAM_PORT); } @@ -60,25 +60,25 @@ void send_browser_reset(int reset_type, const char *to_name, int to_type, struct void broadcast_announce_request(struct subnet_record *subrec, struct work_record *work) { - pstring outbuf; - char *p; + pstring outbuf; + char *p; - work->needannounce = True; + work->needannounce = True; - DEBUG(3,("broadcast_announce_request: sending announce request for workgroup %s \ + DEBUG(3,("broadcast_announce_request: sending announce request for workgroup %s \ to subnet %s\n", work->work_group, subrec->subnet_name)); - memset(outbuf,'\0',sizeof(outbuf)); - p = outbuf; - SCVAL(p,0,ANN_AnnouncementRequest); - p++; + memset(outbuf,'\0',sizeof(outbuf)); + p = outbuf; + SCVAL(p,0,ANN_AnnouncementRequest); + p++; - SCVAL(p,0,work->token); /* (local) Unique workgroup token id. */ - p++; - p += push_string(NULL, p+1, global_myname(), 15, STR_ASCII|STR_UPPER|STR_TERMINATE); + SCVAL(p,0,work->token); /* (local) Unique workgroup token id. */ + p++; + p += push_string(NULL, p+1, global_myname(), 15, STR_ASCII|STR_UPPER|STR_TERMINATE); - send_mailslot(False, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), - global_myname(), 0x0, work->work_group,0x1e, subrec->bcast_ip, + send_mailslot(False, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), + global_myname(), 0x0, work->work_group,0x1e, subrec->bcast_ip, subrec->myip, DGRAM_PORT); } @@ -91,33 +91,33 @@ static void send_announcement(struct subnet_record *subrec, int announce_type, time_t announce_interval, const char *server_name, int server_type, const char *server_comment) { - pstring outbuf; - char *p; + pstring outbuf; + char *p; - memset(outbuf,'\0',sizeof(outbuf)); - p = outbuf+1; + memset(outbuf,'\0',sizeof(outbuf)); + p = outbuf+1; - SCVAL(outbuf,0,announce_type); + SCVAL(outbuf,0,announce_type); - /* Announcement parameters. */ - SCVAL(p,0,updatecount); - SIVAL(p,1,announce_interval*1000); /* Milliseconds - despite the spec. */ + /* Announcement parameters. */ + SCVAL(p,0,updatecount); + SIVAL(p,1,announce_interval*1000); /* Milliseconds - despite the spec. */ - push_string(NULL, p+5, server_name, 15, STR_ASCII|STR_UPPER|STR_TERMINATE); + push_string(NULL, p+5, server_name, 15, STR_ASCII|STR_UPPER|STR_TERMINATE); - SCVAL(p,21,lp_major_announce_version()); /* Major version. */ - SCVAL(p,22,lp_minor_announce_version()); /* Minor version. */ + SCVAL(p,21,lp_major_announce_version()); /* Major version. */ + SCVAL(p,22,lp_minor_announce_version()); /* Minor version. */ - SIVAL(p,23,server_type & ~SV_TYPE_LOCAL_LIST_ONLY); - /* Browse version: got from NT/AS 4.00 - Value defined in smb.h (JHT). */ - SSVAL(p,27,BROWSER_ELECTION_VERSION); - SSVAL(p,29,BROWSER_CONSTANT); /* Browse signature. */ + SIVAL(p,23,server_type & ~SV_TYPE_LOCAL_LIST_ONLY); + /* Browse version: got from NT/AS 4.00 - Value defined in smb.h (JHT). */ + SSVAL(p,27,BROWSER_ELECTION_VERSION); + SSVAL(p,29,BROWSER_CONSTANT); /* Browse signature. */ - p += 31 + push_string(NULL, p+31, server_comment, -1, STR_ASCII|STR_TERMINATE); + p += 31 + push_string(NULL, p+31, server_comment, -1, STR_ASCII|STR_TERMINATE); - send_mailslot(False,BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), - from_name, 0x0, to_name, to_type, to_ip, subrec->myip, - DGRAM_PORT); + send_mailslot(False,BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), + from_name, 0x0, to_name, to_type, to_ip, subrec->myip, + DGRAM_PORT); } /**************************************************************************** @@ -129,28 +129,23 @@ static void send_lm_announcement(struct subnet_record *subrec, int announce_type time_t announce_interval, char *server_name, int server_type, char *server_comment) { - pstring outbuf; - char *p=outbuf; - - memset(outbuf,'\0',sizeof(outbuf)); - - SSVAL(p,0,announce_type); - SIVAL(p,2,server_type & ~SV_TYPE_LOCAL_LIST_ONLY); - SCVAL(p,6,lp_major_announce_version()); /* Major version. */ - SCVAL(p,7,lp_minor_announce_version()); /* Minor version. */ - SSVAL(p,8,announce_interval); /* In seconds - according to spec. */ - - p += 10; - /*StrnCpy(p,server_name,15); - strupper_m(p); - p = skip_string(p,1); - pstrcpy(p,server_comment); - p = skip_string(p,1);*/ - p += push_string(NULL, p, server_name, 15, STR_ASCII|STR_UPPER|STR_TERMINATE); - p += push_string(NULL, p, server_comment, sizeof(pstring)-15, STR_ASCII|STR_UPPER|STR_TERMINATE); - - send_mailslot(False,LANMAN_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), - from_name, 0x0, to_name, to_type, to_ip, subrec->myip, + pstring outbuf; + char *p=outbuf; + + memset(outbuf,'\0',sizeof(outbuf)); + + SSVAL(p,0,announce_type); + SIVAL(p,2,server_type & ~SV_TYPE_LOCAL_LIST_ONLY); + SCVAL(p,6,lp_major_announce_version()); /* Major version. */ + SCVAL(p,7,lp_minor_announce_version()); /* Minor version. */ + SSVAL(p,8,announce_interval); /* In seconds - according to spec. */ + + p += 10; + p += push_string(NULL, p, server_name, 15, STR_ASCII|STR_UPPER|STR_TERMINATE); + p += push_string(NULL, p, server_comment, sizeof(pstring)-15, STR_ASCII|STR_UPPER|STR_TERMINATE); + + send_mailslot(False,LANMAN_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), + from_name, 0x0, to_name, to_type, to_ip, subrec->myip, DGRAM_PORT); } @@ -161,20 +156,20 @@ static void send_lm_announcement(struct subnet_record *subrec, int announce_type static void send_local_master_announcement(struct subnet_record *subrec, struct work_record *work, struct server_record *servrec) { - /* Ensure we don't have the prohibited bit set. */ - uint32 type = servrec->serv.type & ~SV_TYPE_LOCAL_LIST_ONLY; - - DEBUG(3,("send_local_master_announcement: type %x for name %s on subnet %s for workgroup %s\n", - type, global_myname(), subrec->subnet_name, work->work_group)); - - send_announcement(subrec, ANN_LocalMasterAnnouncement, - global_myname(), /* From nbt name. */ - work->work_group, 0x1e, /* To nbt name. */ - subrec->bcast_ip, /* To ip. */ - work->announce_interval, /* Time until next announce. */ - global_myname(), /* Name to announce. */ - type, /* Type field. */ - servrec->serv.comment); + /* Ensure we don't have the prohibited bit set. */ + uint32 type = servrec->serv.type & ~SV_TYPE_LOCAL_LIST_ONLY; + + DEBUG(3,("send_local_master_announcement: type %x for name %s on subnet %s for workgroup %s\n", + type, global_myname(), subrec->subnet_name, work->work_group)); + + send_announcement(subrec, ANN_LocalMasterAnnouncement, + global_myname(), /* From nbt name. */ + work->work_group, 0x1e, /* To nbt name. */ + subrec->bcast_ip, /* To ip. */ + work->announce_interval, /* Time until next announce. */ + global_myname(), /* Name to announce. */ + type, /* Type field. */ + servrec->serv.comment); } /**************************************************************************** @@ -183,17 +178,17 @@ static void send_local_master_announcement(struct subnet_record *subrec, struct static void send_workgroup_announcement(struct subnet_record *subrec, struct work_record *work) { - DEBUG(3,("send_workgroup_announcement: on subnet %s for workgroup %s\n", - subrec->subnet_name, work->work_group)); - - send_announcement(subrec, ANN_DomainAnnouncement, - global_myname(), /* From nbt name. */ - MSBROWSE, 0x1, /* To nbt name. */ - subrec->bcast_ip, /* To ip. */ - work->announce_interval, /* Time until next announce. */ - work->work_group, /* Name to announce. */ - SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT, /* workgroup announce flags. */ - global_myname()); /* From name as comment. */ + DEBUG(3,("send_workgroup_announcement: on subnet %s for workgroup %s\n", + subrec->subnet_name, work->work_group)); + + send_announcement(subrec, ANN_DomainAnnouncement, + global_myname(), /* From nbt name. */ + MSBROWSE, 0x1, /* To nbt name. */ + subrec->bcast_ip, /* To ip. */ + work->announce_interval, /* Time until next announce. */ + work->work_group, /* Name to announce. */ + SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT, /* workgroup announce flags. */ + global_myname()); /* From name as comment. */ } /**************************************************************************** @@ -203,20 +198,20 @@ static void send_workgroup_announcement(struct subnet_record *subrec, struct wor static void send_host_announcement(struct subnet_record *subrec, struct work_record *work, struct server_record *servrec) { - /* Ensure we don't have the prohibited bits set. */ - uint32 type = servrec->serv.type & ~SV_TYPE_LOCAL_LIST_ONLY; - - DEBUG(3,("send_host_announcement: type %x for host %s on subnet %s for workgroup %s\n", - type, servrec->serv.name, subrec->subnet_name, work->work_group)); - - send_announcement(subrec, ANN_HostAnnouncement, - servrec->serv.name, /* From nbt name. */ - work->work_group, 0x1d, /* To nbt name. */ - subrec->bcast_ip, /* To ip. */ - work->announce_interval, /* Time until next announce. */ - servrec->serv.name, /* Name to announce. */ - type, /* Type field. */ - servrec->serv.comment); + /* Ensure we don't have the prohibited bits set. */ + uint32 type = servrec->serv.type & ~SV_TYPE_LOCAL_LIST_ONLY; + + DEBUG(3,("send_host_announcement: type %x for host %s on subnet %s for workgroup %s\n", + type, servrec->serv.name, subrec->subnet_name, work->work_group)); + + send_announcement(subrec, ANN_HostAnnouncement, + servrec->serv.name, /* From nbt name. */ + work->work_group, 0x1d, /* To nbt name. */ + subrec->bcast_ip, /* To ip. */ + work->announce_interval, /* Time until next announce. */ + servrec->serv.name, /* Name to announce. */ + type, /* Type field. */ + servrec->serv.comment); } /**************************************************************************** @@ -226,20 +221,20 @@ static void send_host_announcement(struct subnet_record *subrec, struct work_rec static void send_lm_host_announcement(struct subnet_record *subrec, struct work_record *work, struct server_record *servrec, int lm_interval) { - /* Ensure we don't have the prohibited bits set. */ - uint32 type = servrec->serv.type & ~SV_TYPE_LOCAL_LIST_ONLY; - - DEBUG(3,("send_lm_host_announcement: type %x for host %s on subnet %s for workgroup %s, ttl: %d\n", - type, servrec->serv.name, subrec->subnet_name, work->work_group, lm_interval)); - - send_lm_announcement(subrec, ANN_HostAnnouncement, - servrec->serv.name, /* From nbt name. */ - work->work_group, 0x00, /* To nbt name. */ - subrec->bcast_ip, /* To ip. */ - lm_interval, /* Time until next announce. */ - servrec->serv.name, /* Name to announce. */ - type, /* Type field. */ - servrec->serv.comment); + /* Ensure we don't have the prohibited bits set. */ + uint32 type = servrec->serv.type & ~SV_TYPE_LOCAL_LIST_ONLY; + + DEBUG(3,("send_lm_host_announcement: type %x for host %s on subnet %s for workgroup %s, ttl: %d\n", + type, servrec->serv.name, subrec->subnet_name, work->work_group, lm_interval)); + + send_lm_announcement(subrec, ANN_HostAnnouncement, + servrec->serv.name, /* From nbt name. */ + work->work_group, 0x00, /* To nbt name. */ + subrec->bcast_ip, /* To ip. */ + lm_interval, /* Time until next announce. */ + servrec->serv.name, /* Name to announce (fstring not netbios name struct). */ + type, /* Type field. */ + servrec->serv.comment); } /**************************************************************************** @@ -249,18 +244,15 @@ static void send_lm_host_announcement(struct subnet_record *subrec, struct work_ static void announce_server(struct subnet_record *subrec, struct work_record *work, struct server_record *servrec) { - /* Only do domain announcements if we are a master and it's - our primary name we're being asked to announce. */ - - if (AM_LOCAL_MASTER_BROWSER(work) && strequal(global_myname(),servrec->serv.name)) - { - send_local_master_announcement(subrec, work, servrec); - send_workgroup_announcement(subrec, work); - } - else - { - send_host_announcement(subrec, work, servrec); - } + /* Only do domain announcements if we are a master and it's + our primary name we're being asked to announce. */ + + if (AM_LOCAL_MASTER_BROWSER(work) && strequal(global_myname(),servrec->serv.name)) { + send_local_master_announcement(subrec, work, servrec); + send_workgroup_announcement(subrec, work); + } else { + send_host_announcement(subrec, work, servrec); + } } /**************************************************************************** @@ -270,43 +262,39 @@ static void announce_server(struct subnet_record *subrec, struct work_record *wo void announce_my_server_names(time_t t) { - struct subnet_record *subrec; - - for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - { - struct work_record *work = find_workgroup_on_subnet(subrec, lp_workgroup()); - - if(work) - { - struct server_record *servrec; - - if (work->needannounce) - { - /* Drop back to a max 3 minute announce. This is to prevent a - single lost packet from breaking things for too long. */ - - work->announce_interval = MIN(work->announce_interval, - CHECK_TIME_MIN_HOST_ANNCE*60); - work->lastannounce_time = t - (work->announce_interval+1); - work->needannounce = False; - } - - /* Announce every minute at first then progress to every 12 mins */ - if ((t - work->lastannounce_time) < work->announce_interval) - continue; - - if (work->announce_interval < (CHECK_TIME_MAX_HOST_ANNCE * 60)) - work->announce_interval += 60; - - work->lastannounce_time = t; - - for (servrec = work->serverlist; servrec; servrec = servrec->next) - { - if (is_myname(servrec->serv.name)) - announce_server(subrec, work, servrec); - } - } /* if work */ - } /* for subrec */ + struct subnet_record *subrec; + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { + struct work_record *work = find_workgroup_on_subnet(subrec, lp_workgroup()); + + if(work) { + struct server_record *servrec; + + if (work->needannounce) { + /* Drop back to a max 3 minute announce. This is to prevent a + single lost packet from breaking things for too long. */ + + work->announce_interval = MIN(work->announce_interval, + CHECK_TIME_MIN_HOST_ANNCE*60); + work->lastannounce_time = t - (work->announce_interval+1); + work->needannounce = False; + } + + /* Announce every minute at first then progress to every 12 mins */ + if ((t - work->lastannounce_time) < work->announce_interval) + continue; + + if (work->announce_interval < (CHECK_TIME_MAX_HOST_ANNCE * 60)) + work->announce_interval += 60; + + work->lastannounce_time = t; + + for (servrec = work->serverlist; servrec; servrec = servrec->next) { + if (is_myname(servrec->serv.name)) + announce_server(subrec, work, servrec); + } + } /* if work */ + } /* for subrec */ } /**************************************************************************** @@ -316,47 +304,42 @@ void announce_my_server_names(time_t t) void announce_my_lm_server_names(time_t t) { - struct subnet_record *subrec; - static time_t last_lm_announce_time=0; - int announce_interval = lp_lm_interval(); - int lm_announce = lp_lm_announce(); - - if ((announce_interval <= 0) || (lm_announce <= 0)) - { - /* user absolutely does not want LM announcements to be sent. */ - return; - } - - if ((lm_announce >= 2) && (!found_lm_clients)) - { - /* has been set to 2 (Auto) but no LM clients detected (yet). */ - return; - } - - /* Otherwise: must have been set to 1 (Yes), or LM clients *have* - been detected. */ - - for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - { - struct work_record *work = find_workgroup_on_subnet(subrec, lp_workgroup()); - - if(work) - { - struct server_record *servrec; - - if (last_lm_announce_time && ((t - last_lm_announce_time) < announce_interval )) - continue; - - last_lm_announce_time = t; - - for (servrec = work->serverlist; servrec; servrec = servrec->next) - { - if (is_myname(servrec->serv.name)) - /* skipping equivalent of announce_server() */ - send_lm_host_announcement(subrec, work, servrec, announce_interval); - } - } /* if work */ - } /* for subrec */ + struct subnet_record *subrec; + static time_t last_lm_announce_time=0; + int announce_interval = lp_lm_interval(); + int lm_announce = lp_lm_announce(); + + if ((announce_interval <= 0) || (lm_announce <= 0)) { + /* user absolutely does not want LM announcements to be sent. */ + return; + } + + if ((lm_announce >= 2) && (!found_lm_clients)) { + /* has been set to 2 (Auto) but no LM clients detected (yet). */ + return; + } + + /* Otherwise: must have been set to 1 (Yes), or LM clients *have* + been detected. */ + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { + struct work_record *work = find_workgroup_on_subnet(subrec, lp_workgroup()); + + if(work) { + struct server_record *servrec; + + if (last_lm_announce_time && ((t - last_lm_announce_time) < announce_interval )) + continue; + + last_lm_announce_time = t; + + for (servrec = work->serverlist; servrec; servrec = servrec->next) { + if (is_myname(servrec->serv.name)) + /* skipping equivalent of announce_server() */ + send_lm_host_announcement(subrec, work, servrec, announce_interval); + } + } /* if work */ + } /* for subrec */ } /* Announce timer. Moved into global static so it can be reset @@ -370,7 +353,7 @@ static time_t announce_timer_last=0; void reset_announce_timer(void) { - announce_timer_last = time(NULL) - (CHECK_TIME_MST_ANNOUNCE * 60); + announce_timer_last = time(NULL) - (CHECK_TIME_MST_ANNOUNCE * 60); } /**************************************************************************** @@ -379,45 +362,40 @@ void reset_announce_timer(void) void announce_myself_to_domain_master_browser(time_t t) { - struct subnet_record *subrec; - struct work_record *work; - - if(!we_are_a_wins_client()) - { - DEBUG(10,("announce_myself_to_domain_master_browser: no unicast subnet, ignoring.\n")); - return; - } - - if (!announce_timer_last) - announce_timer_last = t; - - if ((t-announce_timer_last) < (CHECK_TIME_MST_ANNOUNCE * 60)) - { - DEBUG(10,("announce_myself_to_domain_master_browser: t (%d) - last(%d) < %d\n", - (int)t, (int)announce_timer_last, - CHECK_TIME_MST_ANNOUNCE * 60 )); - return; - } - - announce_timer_last = t; - - /* Look over all our broadcast subnets to see if any of them - has the state set as local master browser. */ - - for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - { - for (work = subrec->workgrouplist; work; work = work->next) - { - if (AM_LOCAL_MASTER_BROWSER(work)) - { - DEBUG(4,( "announce_myself_to_domain_master_browser: I am a local master browser for \ + struct subnet_record *subrec; + struct work_record *work; + + if(!we_are_a_wins_client()) { + DEBUG(10,("announce_myself_to_domain_master_browser: no unicast subnet, ignoring.\n")); + return; + } + + if (!announce_timer_last) + announce_timer_last = t; + + if ((t-announce_timer_last) < (CHECK_TIME_MST_ANNOUNCE * 60)) { + DEBUG(10,("announce_myself_to_domain_master_browser: t (%d) - last(%d) < %d\n", + (int)t, (int)announce_timer_last, + CHECK_TIME_MST_ANNOUNCE * 60 )); + return; + } + + announce_timer_last = t; + + /* Look over all our broadcast subnets to see if any of them + has the state set as local master browser. */ + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { + for (work = subrec->workgrouplist; work; work = work->next) { + if (AM_LOCAL_MASTER_BROWSER(work)) { + DEBUG(4,( "announce_myself_to_domain_master_browser: I am a local master browser for \ workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name)); - /* Look in nmbd_browsersync.c for the rest of this code. */ - announce_and_sync_with_domain_master_browser(subrec, work); - } - } - } + /* Look in nmbd_browsersync.c for the rest of this code. */ + announce_and_sync_with_domain_master_browser(subrec, work); + } + } + } } /**************************************************************************** @@ -427,49 +405,43 @@ This must *only* be called on shutdown. void announce_my_servers_removed(void) { - int announce_interval = lp_lm_interval(); - int lm_announce = lp_lm_announce(); - struct subnet_record *subrec; - - for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - { - struct work_record *work; - for (work = subrec->workgrouplist; work; work = work->next) - { - struct server_record *servrec; - - work->announce_interval = 0; - for (servrec = work->serverlist; servrec; servrec = servrec->next) - { - if (!is_myname(servrec->serv.name)) - continue; - servrec->serv.type = 0; - if(AM_LOCAL_MASTER_BROWSER(work)) - send_local_master_announcement(subrec, work, servrec); - send_host_announcement(subrec, work, servrec); - - - if ((announce_interval <= 0) || (lm_announce <= 0)) - { - /* user absolutely does not want LM announcements to be sent. */ - continue; - } - - if ((lm_announce >= 2) && (!found_lm_clients)) - { - /* has been set to 2 (Auto) but no LM clients detected (yet). */ - continue; - } - - /* - * lm announce was set or we have seen lm announcements, so do - * a lm announcement of host removed. - */ - - send_lm_host_announcement(subrec, work, servrec, 0); - } - } - } + int announce_interval = lp_lm_interval(); + int lm_announce = lp_lm_announce(); + struct subnet_record *subrec; + + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { + struct work_record *work; + for (work = subrec->workgrouplist; work; work = work->next) { + struct server_record *servrec; + + work->announce_interval = 0; + for (servrec = work->serverlist; servrec; servrec = servrec->next) { + if (!is_myname(servrec->serv.name)) + continue; + servrec->serv.type = 0; + if(AM_LOCAL_MASTER_BROWSER(work)) + send_local_master_announcement(subrec, work, servrec); + send_host_announcement(subrec, work, servrec); + + if ((announce_interval <= 0) || (lm_announce <= 0)) { + /* user absolutely does not want LM announcements to be sent. */ + continue; + } + + if ((lm_announce >= 2) && (!found_lm_clients)) { + /* has been set to 2 (Auto) but no LM clients detected (yet). */ + continue; + } + + /* + * lm announce was set or we have seen lm announcements, so do + * a lm announcement of host removed. + */ + + send_lm_host_announcement(subrec, work, servrec, 0); + } + } + } } /**************************************************************************** @@ -480,132 +452,127 @@ void announce_my_servers_removed(void) void announce_remote(time_t t) { - char *s; - const char *ptr; - static time_t last_time = 0; - pstring s2; - struct in_addr addr; - char *comment; - int stype = lp_default_server_announce(); - - if (last_time && (t < (last_time + REMOTE_ANNOUNCE_INTERVAL))) - return; - - last_time = t; - - s = lp_remote_announce(); - if (!*s) - return; - - comment = string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH); - - for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) - { - /* The entries are of the form a.b.c.d/WORKGROUP with - WORKGROUP being optional */ - const char *wgroup; - char *pwgroup; - int i; - - pwgroup = strchr_m(s2,'/'); - if (pwgroup) - *pwgroup++ = 0; - if (!pwgroup || !*pwgroup) - wgroup = lp_workgroup(); - else - wgroup = pwgroup; - - addr = *interpret_addr2(s2); + char *s; + const char *ptr; + static time_t last_time = 0; + pstring s2; + struct in_addr addr; + char *comment; + int stype = lp_default_server_announce(); + + if (last_time && (t < (last_time + REMOTE_ANNOUNCE_INTERVAL))) + return; + + last_time = t; + + s = lp_remote_announce(); + if (!*s) + return; + + comment = string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH); + + for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) { + /* The entries are of the form a.b.c.d/WORKGROUP with + WORKGROUP being optional */ + const char *wgroup; + char *pwgroup; + int i; + + pwgroup = strchr_m(s2,'/'); + if (pwgroup) + *pwgroup++ = 0; + if (!pwgroup || !*pwgroup) + wgroup = lp_workgroup(); + else + wgroup = pwgroup; + + addr = *interpret_addr2(s2); - /* Announce all our names including aliases */ - /* Give the ip address as the address of our first - broadcast subnet. */ - - for(i=0; my_netbios_names(i); i++) - { - const char *name = my_netbios_names(i); - - DEBUG(5,("announce_remote: Doing remote announce for server %s to IP %s.\n", - name, inet_ntoa(addr) )); - - send_announcement(FIRST_SUBNET, ANN_HostAnnouncement, - name, /* From nbt name. */ - wgroup, 0x1d, /* To nbt name. */ - addr, /* To ip. */ - REMOTE_ANNOUNCE_INTERVAL, /* Time until next announce. */ - name, /* Name to announce. */ - stype, /* Type field. */ - comment); - } - } + /* Announce all our names including aliases */ + /* Give the ip address as the address of our first + broadcast subnet. */ + + for(i=0; my_netbios_names(i); i++) { + const char *name = my_netbios_names(i); + + DEBUG(5,("announce_remote: Doing remote announce for server %s to IP %s.\n", + name, inet_ntoa(addr) )); + + send_announcement(FIRST_SUBNET, ANN_HostAnnouncement, + name, /* From nbt name. */ + wgroup, 0x1d, /* To nbt name. */ + addr, /* To ip. */ + REMOTE_ANNOUNCE_INTERVAL, /* Time until next announce. */ + name, /* Name to announce. */ + stype, /* Type field. */ + comment); + } + } } /**************************************************************************** Implement the 'remote browse sync' feature Andrew added. These are used to put our browse lists into remote browse lists. - **************************************************************************/ +**************************************************************************/ void browse_sync_remote(time_t t) { - char *s; - const char *ptr; - static time_t last_time = 0; - pstring s2; - struct in_addr addr; - struct work_record *work; - pstring outbuf; - char *p; - fstring myname; + char *s; + const char *ptr; + static time_t last_time = 0; + pstring s2; + struct in_addr addr; + struct work_record *work; + pstring outbuf; + char *p; + fstring myname; - if (last_time && (t < (last_time + REMOTE_ANNOUNCE_INTERVAL))) - return; + if (last_time && (t < (last_time + REMOTE_ANNOUNCE_INTERVAL))) + return; - last_time = t; - - s = lp_remote_browse_sync(); - if (!*s) - return; - - /* - * We only do this if we are the local master browser - * for our workgroup on the firsst subnet. - */ - - if((work = find_workgroup_on_subnet(FIRST_SUBNET, lp_workgroup())) == NULL) - { - DEBUG(0,("browse_sync_remote: Cannot find workgroup %s on subnet %s\n", - lp_workgroup(), FIRST_SUBNET->subnet_name )); - return; - } + last_time = t; + + s = lp_remote_browse_sync(); + if (!*s) + return; + + /* + * We only do this if we are the local master browser + * for our workgroup on the firsst subnet. + */ + + if((work = find_workgroup_on_subnet(FIRST_SUBNET, lp_workgroup())) == NULL) { + DEBUG(0,("browse_sync_remote: Cannot find workgroup %s on subnet %s\n", + lp_workgroup(), FIRST_SUBNET->subnet_name )); + return; + } - if(!AM_LOCAL_MASTER_BROWSER(work)) - { - DEBUG(5,("browse_sync_remote: We can only do this if we are a local master browser \ + if(!AM_LOCAL_MASTER_BROWSER(work)) { + DEBUG(5,("browse_sync_remote: We can only do this if we are a local master browser \ for workgroup %s on subnet %s.\n", lp_workgroup(), FIRST_SUBNET->subnet_name )); - return; - } + return; + } - memset(outbuf,'\0',sizeof(outbuf)); - p = outbuf; - SCVAL(p,0,ANN_MasterAnnouncement); - p++; + memset(outbuf,'\0',sizeof(outbuf)); + p = outbuf; + SCVAL(p,0,ANN_MasterAnnouncement); + p++; - fstrcpy(myname, global_myname()); - strupper_m(myname); - myname[15]='\0'; - push_pstring_base(p, myname, outbuf); + fstrcpy(myname, global_myname()); + strupper_m(myname); + myname[15]='\0'; + push_pstring_base(p, myname, outbuf); - p = skip_string(p,1); + p = skip_string(p,1); - for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) - { - /* The entries are of the form a.b.c.d */ - addr = *interpret_addr2(s2); + for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) { + /* The entries are of the form a.b.c.d */ + addr = *interpret_addr2(s2); - DEBUG(5,("announce_remote: Doing remote browse sync announce for server %s to IP %s.\n", - global_myname(), inet_ntoa(addr) )); + DEBUG(5,("announce_remote: Doing remote browse sync announce for server %s to IP %s.\n", + global_myname(), inet_ntoa(addr) )); - send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), - global_myname(), 0x0, "*", 0x0, addr, FIRST_SUBNET->myip, DGRAM_PORT); - } + send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), + global_myname(), 0x0, "*", 0x0, addr, FIRST_SUBNET->myip, DGRAM_PORT); + } } diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index 2484a7f830..b4c6e2902d 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -33,28 +33,26 @@ int updatecount = 0; void remove_all_servers(struct work_record *work) { - struct server_record *servrec; - struct server_record *nexts; + struct server_record *servrec; + struct server_record *nexts; - for (servrec = work->serverlist; servrec; servrec = nexts) - { - DEBUG(7,("remove_all_servers: Removing server %s\n",servrec->serv.name)); - nexts = servrec->next; + for (servrec = work->serverlist; servrec; servrec = nexts) { + DEBUG(7,("remove_all_servers: Removing server %s\n",servrec->serv.name)); + nexts = servrec->next; - if (servrec->prev) - servrec->prev->next = servrec->next; - if (servrec->next) - servrec->next->prev = servrec->prev; + if (servrec->prev) + servrec->prev->next = servrec->next; + if (servrec->next) + servrec->next->prev = servrec->prev; - if (work->serverlist == servrec) - work->serverlist = servrec->next; + if (work->serverlist == servrec) + work->serverlist = servrec->next; - ZERO_STRUCTP(servrec); - SAFE_FREE(servrec); + ZERO_STRUCTP(servrec); + SAFE_FREE(servrec); + } - } - - work->subnet->work_changed = True; + work->subnet->work_changed = True; } /*************************************************************************** @@ -64,23 +62,22 @@ void remove_all_servers(struct work_record *work) static void add_server_to_workgroup(struct work_record *work, struct server_record *servrec) { - struct server_record *servrec2; - - if (!work->serverlist) - { - work->serverlist = servrec; - servrec->prev = NULL; - servrec->next = NULL; - return; - } - - for (servrec2 = work->serverlist; servrec2->next; servrec2 = servrec2->next) - ; - - servrec2->next = servrec; - servrec->next = NULL; - servrec->prev = servrec2; - work->subnet->work_changed = True; + struct server_record *servrec2; + + if (!work->serverlist) { + work->serverlist = servrec; + servrec->prev = NULL; + servrec->next = NULL; + return; + } + + for (servrec2 = work->serverlist; servrec2->next; servrec2 = servrec2->next) + ; + + servrec2->next = servrec; + servrec->next = NULL; + servrec->prev = servrec2; + work->subnet->work_changed = True; } /**************************************************************************** @@ -89,14 +86,13 @@ static void add_server_to_workgroup(struct work_record *work, struct server_record *find_server_in_workgroup(struct work_record *work, const char *name) { - struct server_record *ret; + struct server_record *ret; - for (ret = work->serverlist; ret; ret = ret->next) - { - if (strequal(ret->serv.name,name)) - return ret; - } - return NULL; + for (ret = work->serverlist; ret; ret = ret->next) { + if (strequal(ret->serv.name,name)) + return ret; + } + return NULL; } @@ -106,17 +102,17 @@ struct server_record *find_server_in_workgroup(struct work_record *work, const c void remove_server_from_workgroup(struct work_record *work, struct server_record *servrec) { - if (servrec->prev) - servrec->prev->next = servrec->next; - if (servrec->next) - servrec->next->prev = servrec->prev; + if (servrec->prev) + servrec->prev->next = servrec->next; + if (servrec->next) + servrec->next->prev = servrec->prev; - if (work->serverlist == servrec) - work->serverlist = servrec->next; + if (work->serverlist == servrec) + work->serverlist = servrec->next; - ZERO_STRUCTP(servrec); - SAFE_FREE(servrec); - work->subnet->work_changed = True; + ZERO_STRUCTP(servrec); + SAFE_FREE(servrec); + work->subnet->work_changed = True; } /**************************************************************************** @@ -127,47 +123,44 @@ struct server_record *create_server_on_workgroup(struct work_record *work, const char *name,int servertype, int ttl, const char *comment) { - struct server_record *servrec; + struct server_record *servrec; - if (name[0] == '*') - { - DEBUG(7,("create_server_on_workgroup: not adding name starting with '*' (%s)\n", - name)); - return (NULL); - } + if (name[0] == '*') { + DEBUG(7,("create_server_on_workgroup: not adding name starting with '*' (%s)\n", + name)); + return (NULL); + } - if((servrec = find_server_in_workgroup(work, name)) != NULL) - { - DEBUG(0,("create_server_on_workgroup: Server %s already exists on \ + if((servrec = find_server_in_workgroup(work, name)) != NULL) { + DEBUG(0,("create_server_on_workgroup: Server %s already exists on \ workgroup %s. This is a bug.\n", name, work->work_group)); - return NULL; - } + return NULL; + } - if((servrec = (struct server_record *)malloc(sizeof(*servrec))) == NULL) - { - DEBUG(0,("create_server_entry_on_workgroup: malloc fail !\n")); - return NULL; - } + if((servrec = (struct server_record *)malloc(sizeof(*servrec))) == NULL) { + DEBUG(0,("create_server_entry_on_workgroup: malloc fail !\n")); + return NULL; + } - memset((char *)servrec,'\0',sizeof(*servrec)); + memset((char *)servrec,'\0',sizeof(*servrec)); - servrec->subnet = work->subnet; + servrec->subnet = work->subnet; - fstrcpy(servrec->serv.name,name); - fstrcpy(servrec->serv.comment,comment); - strupper_m(servrec->serv.name); - servrec->serv.type = servertype; + fstrcpy(servrec->serv.name,name); + fstrcpy(servrec->serv.comment,comment); + strupper_m(servrec->serv.name); + servrec->serv.type = servertype; - update_server_ttl(servrec, ttl); + update_server_ttl(servrec, ttl); - add_server_to_workgroup(work, servrec); + add_server_to_workgroup(work, servrec); - DEBUG(3,("create_server_on_workgroup: Created server entry %s of type %x (%s) on \ + DEBUG(3,("create_server_on_workgroup: Created server entry %s of type %x (%s) on \ workgroup %s.\n", name,servertype,comment, work->work_group)); - work->subnet->work_changed = True; + work->subnet->work_changed = True; - return(servrec); + return(servrec); } /******************************************************************* @@ -176,15 +169,15 @@ workgroup %s.\n", name,servertype,comment, work->work_group)); void update_server_ttl(struct server_record *servrec, int ttl) { - if(ttl > lp_max_ttl()) - ttl = lp_max_ttl(); + if(ttl > lp_max_ttl()) + ttl = lp_max_ttl(); - if(is_myname(servrec->serv.name)) - servrec->death_time = PERMANENT_TTL; - else - servrec->death_time = (ttl != PERMANENT_TTL) ? time(NULL)+(ttl*3) : PERMANENT_TTL; + if(is_myname(servrec->serv.name)) + servrec->death_time = PERMANENT_TTL; + else + servrec->death_time = (ttl != PERMANENT_TTL) ? time(NULL)+(ttl*3) : PERMANENT_TTL; - servrec->subnet->work_changed = True; + servrec->subnet->work_changed = True; } /******************************************************************* @@ -195,20 +188,18 @@ void update_server_ttl(struct server_record *servrec, int ttl) void expire_servers(struct work_record *work, time_t t) { - struct server_record *servrec; - struct server_record *nexts; + struct server_record *servrec; + struct server_record *nexts; - for (servrec = work->serverlist; servrec; servrec = nexts) - { - nexts = servrec->next; - - if ((servrec->death_time != PERMANENT_TTL) && ((t == -1) || (servrec->death_time < t))) - { - DEBUG(3,("expire_old_servers: Removing timed out server %s\n",servrec->serv.name)); - remove_server_from_workgroup(work, servrec); - work->subnet->work_changed = True; - } - } + for (servrec = work->serverlist; servrec; servrec = nexts) { + nexts = servrec->next; + + if ((servrec->death_time != PERMANENT_TTL) && ((t == -1) || (servrec->death_time < t))) { + DEBUG(3,("expire_old_servers: Removing timed out server %s\n",servrec->serv.name)); + remove_server_from_workgroup(work, servrec); + work->subnet->work_changed = True; + } + } } /******************************************************************* @@ -221,33 +212,30 @@ static uint32 write_this_server_name( struct subnet_record *subrec, struct work_record *work, struct server_record *servrec) { - struct subnet_record *ssub; - struct work_record *iwork; - - /* Go through all the subnets we have already seen. */ - for (ssub = FIRST_SUBNET; ssub != subrec; ssub = NEXT_SUBNET_INCLUDING_UNICAST(ssub)) - { - for(iwork = ssub->workgrouplist; iwork; iwork = iwork->next) - { - if(find_server_in_workgroup( iwork, servrec->serv.name) != NULL) - { - /* - * We have already written out this server record, don't - * do it again. This gives precedence to servers we have seen - * on the broadcast subnets over servers that may have been - * added via a sync on the unicast_subet. - * - * The correct way to do this is to have a serverlist file - * per subnet - this means changes to smbd as well. I may - * add this at a later date (JRA). - */ - - return 0; - } - } - } - - return servrec->serv.type; + struct subnet_record *ssub; + struct work_record *iwork; + + /* Go through all the subnets we have already seen. */ + for (ssub = FIRST_SUBNET; ssub != subrec; ssub = NEXT_SUBNET_INCLUDING_UNICAST(ssub)) { + for(iwork = ssub->workgrouplist; iwork; iwork = iwork->next) { + if(find_server_in_workgroup( iwork, servrec->serv.name) != NULL) { + /* + * We have already written out this server record, don't + * do it again. This gives precedence to servers we have seen + * on the broadcast subnets over servers that may have been + * added via a sync on the unicast_subet. + * + * The correct way to do this is to have a serverlist file + * per subnet - this means changes to smbd as well. I may + * add this at a later date (JRA). + */ + + return 0; + } + } + } + + return servrec->serv.type; } /******************************************************************* @@ -261,30 +249,29 @@ static uint32 write_this_server_name( struct subnet_record *subrec, static uint32 write_this_workgroup_name( struct subnet_record *subrec, struct work_record *work) { - struct subnet_record *ssub; + struct subnet_record *ssub; - if(strequal(lp_workgroup(), work->work_group)) - return 0; + if(strequal(lp_workgroup(), work->work_group)) + return 0; - /* This is a workgroup we have seen on a broadcast subnet. All - these have the same type. */ + /* This is a workgroup we have seen on a broadcast subnet. All + these have the same type. */ - if(subrec != unicast_subnet) - return (SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT|SV_TYPE_LOCAL_LIST_ONLY); + if(subrec != unicast_subnet) + return (SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT|SV_TYPE_LOCAL_LIST_ONLY); - for(ssub = FIRST_SUBNET; ssub; ssub = NEXT_SUBNET_EXCLUDING_UNICAST(ssub)) - { - /* This is the unicast subnet so check if we've already written out - this subnet when we passed over the broadcast subnets. */ + for(ssub = FIRST_SUBNET; ssub; ssub = NEXT_SUBNET_EXCLUDING_UNICAST(ssub)) { + /* This is the unicast subnet so check if we've already written out + this subnet when we passed over the broadcast subnets. */ - if(find_workgroup_on_subnet( ssub, work->work_group) != NULL) - return 0; - } + if(find_workgroup_on_subnet( ssub, work->work_group) != NULL) + return 0; + } - /* All workgroups on the unicast subnet (except our own, which we - have already written out) cannot be local. */ + /* All workgroups on the unicast subnet (except our own, which we + have already written out) cannot be local. */ - return (SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT); + return (SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT); } /******************************************************************* @@ -306,143 +293,130 @@ void write_browse_list_entry(XFILE *fp, const char *name, uint32 rec_type, void write_browse_list(time_t t, BOOL force_write) { - struct subnet_record *subrec; - struct work_record *work; - struct server_record *servrec; - pstring fname,fnamenew; - uint32 stype; - int i; - XFILE *fp; - BOOL list_changed = force_write; - static time_t lasttime = 0; + struct subnet_record *subrec; + struct work_record *work; + struct server_record *servrec; + pstring fname,fnamenew; + uint32 stype; + int i; + XFILE *fp; + BOOL list_changed = force_write; + static time_t lasttime = 0; - /* Always dump if we're being told to by a signal. */ - if(force_write == False) - { - if (!lasttime) - lasttime = t; - if (t - lasttime < 5) - return; - } - - lasttime = t; - - dump_workgroups(force_write); + /* Always dump if we're being told to by a signal. */ + if(force_write == False) { + if (!lasttime) + lasttime = t; + if (t - lasttime < 5) + return; + } + + lasttime = t; + + dump_workgroups(force_write); - for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) - { - if(subrec->work_changed) - { - list_changed = True; - break; - } - } - - if(!list_changed) - return; - - updatecount++; + for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { + if(subrec->work_changed) { + list_changed = True; + break; + } + } + + if(!list_changed) + return; + + updatecount++; - pstrcpy(fname,lp_lockdir()); - trim_string(fname,NULL,"/"); - pstrcat(fname,"/"); - pstrcat(fname,SERVER_LIST); - pstrcpy(fnamenew,fname); - pstrcat(fnamenew,"."); + pstrcpy(fname,lp_lockdir()); + trim_string(fname,NULL,"/"); + pstrcat(fname,"/"); + pstrcat(fname,SERVER_LIST); + pstrcpy(fnamenew,fname); + pstrcat(fnamenew,"."); - fp = x_fopen(fnamenew,O_WRONLY|O_CREAT|O_TRUNC, 0644); + fp = x_fopen(fnamenew,O_WRONLY|O_CREAT|O_TRUNC, 0644); - if (!fp) - { - DEBUG(0,("write_browse_list: Can't open file %s. Error was %s\n", - fnamenew,strerror(errno))); - return; - } + if (!fp) { + DEBUG(0,("write_browse_list: Can't open file %s. Error was %s\n", + fnamenew,strerror(errno))); + return; + } - /* - * Write out a record for our workgroup. Use the record from the first - * subnet. - */ - - if((work = find_workgroup_on_subnet(FIRST_SUBNET, lp_workgroup())) == NULL) - { - DEBUG(0,("write_browse_list: Fatal error - cannot find my workgroup %s\n", - lp_workgroup())); - x_fclose(fp); - return; - } - - write_browse_list_entry(fp, work->work_group, - SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT|SV_TYPE_LOCAL_LIST_ONLY, - work->local_master_browser_name, work->work_group); - - /* - * We need to do something special for our own names. - * This is due to the fact that we may be a local master browser on - * one of our broadcast subnets, and a domain master on the unicast - * subnet. We iterate over the subnets and only write out the name - * once. - */ - - for (i=0; my_netbios_names(i); i++) - { - stype = 0; - for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) - { - if((work = find_workgroup_on_subnet( subrec, lp_workgroup() )) == NULL) - continue; - if((servrec = find_server_in_workgroup( work, my_netbios_names(i))) == NULL) - continue; - - stype |= servrec->serv.type; - } - - /* Output server details, plus what workgroup they're in. */ - write_browse_list_entry(fp, my_netbios_names(i), stype, - string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH), lp_workgroup()); - } + /* + * Write out a record for our workgroup. Use the record from the first + * subnet. + */ + + if((work = find_workgroup_on_subnet(FIRST_SUBNET, lp_workgroup())) == NULL) { + DEBUG(0,("write_browse_list: Fatal error - cannot find my workgroup %s\n", + lp_workgroup())); + x_fclose(fp); + return; + } + + write_browse_list_entry(fp, work->work_group, + SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT|SV_TYPE_LOCAL_LIST_ONLY, + work->local_master_browser_name, work->work_group); + + /* + * We need to do something special for our own names. + * This is due to the fact that we may be a local master browser on + * one of our broadcast subnets, and a domain master on the unicast + * subnet. We iterate over the subnets and only write out the name + * once. + */ + + for (i=0; my_netbios_names(i); i++) { + stype = 0; + for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { + if((work = find_workgroup_on_subnet( subrec, lp_workgroup() )) == NULL) + continue; + if((servrec = find_server_in_workgroup( work, my_netbios_names(i))) == NULL) + continue; + + stype |= servrec->serv.type; + } + + /* Output server details, plus what workgroup they're in. */ + write_browse_list_entry(fp, my_netbios_names(i), stype, + string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH), lp_workgroup()); + } - for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) - { - subrec->work_changed = False; - - for (work = subrec->workgrouplist; work ; work = work->next) - { - /* Write out a workgroup record for a workgroup. */ - uint32 wg_type = write_this_workgroup_name( subrec, work); - - if(wg_type) - { - write_browse_list_entry(fp, work->work_group, wg_type, - work->local_master_browser_name, - work->work_group); - } - - /* Now write out any server records a workgroup may have. */ - - for (servrec = work->serverlist; servrec ; servrec = servrec->next) - { - uint32 serv_type; - - /* We have already written our names here. */ - if(is_myname(servrec->serv.name)) - continue; - - serv_type = write_this_server_name(subrec, work, servrec); - - if(serv_type) - { - /* Output server details, plus what workgroup they're in. */ - write_browse_list_entry(fp, servrec->serv.name, serv_type, - servrec->serv.comment, work->work_group); - } - } - } - } + for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { + subrec->work_changed = False; + + for (work = subrec->workgrouplist; work ; work = work->next) { + /* Write out a workgroup record for a workgroup. */ + uint32 wg_type = write_this_workgroup_name( subrec, work); + + if(wg_type) { + write_browse_list_entry(fp, work->work_group, wg_type, + work->local_master_browser_name, + work->work_group); + } + + /* Now write out any server records a workgroup may have. */ + + for (servrec = work->serverlist; servrec ; servrec = servrec->next) { + uint32 serv_type; + + /* We have already written our names here. */ + if(is_myname(servrec->serv.name)) + continue; + + serv_type = write_this_server_name(subrec, work, servrec); + if(serv_type) { + /* Output server details, plus what workgroup they're in. */ + write_browse_list_entry(fp, servrec->serv.name, serv_type, + servrec->serv.comment, work->work_group); + } + } + } + } - x_fclose(fp); - unlink(fname); - chmod(fnamenew,0644); - rename(fnamenew,fname); - DEBUG(3,("write_browse_list: Wrote browse list into file %s\n",fname)); + x_fclose(fp); + unlink(fname); + chmod(fnamenew,0644); + rename(fnamenew,fname); + DEBUG(3,("write_browse_list: Wrote browse list into file %s\n",fname)); } diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 6296826425..02a91f2760 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -63,28 +63,27 @@ static void add_subnet(struct subnet_record *subrec) * ************************************************************************** ** */ static int namelist_entry_compare( ubi_trItemPtr Item, ubi_trNodePtr Node ) - { - struct name_record *NR = (struct name_record *)Node; - - if( DEBUGLVL( 10 ) ) - { - struct nmb_name *Iname = (struct nmb_name *)Item; +{ + struct name_record *NR = (struct name_record *)Node; - Debug1( "nmbd_subnetdb:namelist_entry_compare()\n" ); - Debug1( "%d == memcmp( \"%s\", \"%s\", %d )\n", - memcmp( Item, &(NR->name), sizeof(struct nmb_name) ), - nmb_namestr(Iname), nmb_namestr(&NR->name), (int)sizeof(struct nmb_name) ); - } + if( DEBUGLVL( 10 ) ) { + struct nmb_name *Iname = (struct nmb_name *)Item; - return( memcmp( Item, &(NR->name), sizeof(struct nmb_name) ) ); - } /* namelist_entry_compare */ + Debug1( "nmbd_subnetdb:namelist_entry_compare()\n" ); + Debug1( "%d == memcmp( \"%s\", \"%s\", %d )\n", + memcmp( Item, &(NR->name), sizeof(struct nmb_name) ), + nmb_namestr(Iname), nmb_namestr(&NR->name), (int)sizeof(struct nmb_name) ); + } + return( memcmp( Item, &(NR->name), sizeof(struct nmb_name) ) ); +} /**************************************************************************** stop listening on a subnet we don't free the record as we don't have proper reference counting for it yet and it may be in use by a response record ****************************************************************************/ + void close_subnet(struct subnet_record *subrec) { DLIST_REMOVE(subnetlist, subrec); @@ -99,8 +98,6 @@ void close_subnet(struct subnet_record *subrec) } } - - /**************************************************************************** Create a subnet entry. ****************************************************************************/ @@ -109,102 +106,90 @@ static struct subnet_record *make_subnet(const char *name, enum subnet_type type struct in_addr myip, struct in_addr bcast_ip, struct in_addr mask_ip) { - struct subnet_record *subrec = NULL; - int nmb_sock, dgram_sock; - - /* Check if we are creating a non broadcast subnet - if so don't create - sockets. - */ - - if(type != NORMAL_SUBNET) - { - nmb_sock = -1; - dgram_sock = -1; - } - else - { - /* - * Attempt to open the sockets on port 137/138 for this interface - * and bind them. - * Fail the subnet creation if this fails. - */ - - if((nmb_sock = open_socket_in(SOCK_DGRAM, global_nmb_port,0, myip.s_addr,True)) == -1) - { - if( DEBUGLVL( 0 ) ) - { - Debug1( "nmbd_subnetdb:make_subnet()\n" ); - Debug1( " Failed to open nmb socket on interface %s ", inet_ntoa(myip) ); - Debug1( "for port %d. ", global_nmb_port ); - Debug1( "Error was %s\n", strerror(errno) ); - } - return NULL; - } - - if((dgram_sock = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3, myip.s_addr,True)) == -1) - { - if( DEBUGLVL( 0 ) ) - { - Debug1( "nmbd_subnetdb:make_subnet()\n" ); - Debug1( " Failed to open dgram socket on interface %s ", inet_ntoa(myip) ); - Debug1( "for port %d. ", DGRAM_PORT ); - Debug1( "Error was %s\n", strerror(errno) ); - } - return NULL; - } - - /* Make sure we can broadcast from these sockets. */ - set_socket_options(nmb_sock,"SO_BROADCAST"); - set_socket_options(dgram_sock,"SO_BROADCAST"); - - } - - subrec = (struct subnet_record *)malloc(sizeof(*subrec)); - - if (!subrec) - { - DEBUG(0,("make_subnet: malloc fail !\n")); - close(nmb_sock); - close(dgram_sock); - return(NULL); - } + struct subnet_record *subrec = NULL; + int nmb_sock, dgram_sock; + + /* Check if we are creating a non broadcast subnet - if so don't create + sockets. */ + + if(type != NORMAL_SUBNET) { + nmb_sock = -1; + dgram_sock = -1; + } else { + /* + * Attempt to open the sockets on port 137/138 for this interface + * and bind them. + * Fail the subnet creation if this fails. + */ + + if((nmb_sock = open_socket_in(SOCK_DGRAM, global_nmb_port,0, myip.s_addr,True)) == -1) { + if( DEBUGLVL( 0 ) ) { + Debug1( "nmbd_subnetdb:make_subnet()\n" ); + Debug1( " Failed to open nmb socket on interface %s ", inet_ntoa(myip) ); + Debug1( "for port %d. ", global_nmb_port ); + Debug1( "Error was %s\n", strerror(errno) ); + } + return NULL; + } + + if((dgram_sock = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3, myip.s_addr,True)) == -1) { + if( DEBUGLVL( 0 ) ) { + Debug1( "nmbd_subnetdb:make_subnet()\n" ); + Debug1( " Failed to open dgram socket on interface %s ", inet_ntoa(myip) ); + Debug1( "for port %d. ", DGRAM_PORT ); + Debug1( "Error was %s\n", strerror(errno) ); + } + return NULL; + } + + /* Make sure we can broadcast from these sockets. */ + set_socket_options(nmb_sock,"SO_BROADCAST"); + set_socket_options(dgram_sock,"SO_BROADCAST"); + } + + subrec = (struct subnet_record *)malloc(sizeof(*subrec)); + if (!subrec) { + DEBUG(0,("make_subnet: malloc fail !\n")); + close(nmb_sock); + close(dgram_sock); + return(NULL); + } - memset( (char *)subrec, '\0', sizeof(*subrec) ); - (void)ubi_trInitTree( subrec->namelist, - namelist_entry_compare, - ubi_trOVERWRITE ); - - if((subrec->subnet_name = strdup(name)) == NULL) - { - DEBUG(0,("make_subnet: malloc fail for subnet name !\n")); - close(nmb_sock); - close(dgram_sock); - ZERO_STRUCTP(subrec); - SAFE_FREE(subrec); - return(NULL); - } - - DEBUG(2, ("making subnet name:%s ", name )); - DEBUG(2, ("Broadcast address:%s ", inet_ntoa(bcast_ip))); - DEBUG(2, ("Subnet mask:%s\n", inet_ntoa(mask_ip))); + memset( (char *)subrec, '\0', sizeof(*subrec) ); + (void)ubi_trInitTree( subrec->namelist, + namelist_entry_compare, + ubi_trOVERWRITE ); + + if((subrec->subnet_name = strdup(name)) == NULL) { + DEBUG(0,("make_subnet: malloc fail for subnet name !\n")); + close(nmb_sock); + close(dgram_sock); + ZERO_STRUCTP(subrec); + SAFE_FREE(subrec); + return(NULL); + } + + DEBUG(2, ("making subnet name:%s ", name )); + DEBUG(2, ("Broadcast address:%s ", inet_ntoa(bcast_ip))); + DEBUG(2, ("Subnet mask:%s\n", inet_ntoa(mask_ip))); - subrec->namelist_changed = False; - subrec->work_changed = False; + subrec->namelist_changed = False; + subrec->work_changed = False; - subrec->bcast_ip = bcast_ip; - subrec->mask_ip = mask_ip; - subrec->myip = myip; - subrec->type = type; - subrec->nmb_sock = nmb_sock; - subrec->dgram_sock = dgram_sock; + subrec->bcast_ip = bcast_ip; + subrec->mask_ip = mask_ip; + subrec->myip = myip; + subrec->type = type; + subrec->nmb_sock = nmb_sock; + subrec->dgram_sock = dgram_sock; - return subrec; + return subrec; } - /**************************************************************************** Create a normal subnet **************************************************************************/ + struct subnet_record *make_normal_subnet(struct interface *iface) { struct subnet_record *subrec; @@ -217,100 +202,99 @@ struct subnet_record *make_normal_subnet(struct interface *iface) return subrec; } - /**************************************************************************** Create subnet entries. **************************************************************************/ BOOL create_subnets(void) { - int num_interfaces = iface_count(); - int i; - struct in_addr unicast_ip, ipzero; - extern struct in_addr loopback_ip; - - if(num_interfaces == 0) { - DEBUG(0,("create_subnets: No local interfaces !\n")); - DEBUG(0,("create_subnets: Waiting for an interface to appear ...\n")); - while (iface_count() == 0) { - sleep(5); - load_interfaces(); - } - } - - num_interfaces = iface_count(); - - /* - * Create subnets from all the local interfaces and thread them onto - * the linked list. - */ - - for (i = 0 ; i < num_interfaces; i++) - { - struct interface *iface = get_interface(i); - - /* - * We don't want to add a loopback interface, in case - * someone has added 127.0.0.1 for smbd, nmbd needs to - * ignore it here. JRA. - */ - - if (ip_equal(iface->ip, loopback_ip)) { - DEBUG(2,("create_subnets: Ignoring loopback interface.\n" )); - continue; - } - - if (!make_normal_subnet(iface)) return False; - } - - if (lp_we_are_a_wins_server()) { - /* Pick the first interface ip address as the WINS server ip. */ - unicast_ip = *iface_n_ip(0); - } else { - /* note that we do not set the wins server IP here. We just - set it at zero and let the wins registration code cope - with getting the IPs right for each packet */ - zero_ip(&unicast_ip); - } - - /* - * Create the unicast and remote broadcast subnets. - * Don't put these onto the linked list. - * The ip address of the unicast subnet is set to be - * the WINS server address, if it exists, or ipzero if not. - */ - - unicast_subnet = make_subnet( "UNICAST_SUBNET", UNICAST_SUBNET, - unicast_ip, unicast_ip, unicast_ip); - - zero_ip(&ipzero); - - remote_broadcast_subnet = make_subnet( "REMOTE_BROADCAST_SUBNET", - REMOTE_BROADCAST_SUBNET, - ipzero, ipzero, ipzero); - - if((unicast_subnet == NULL) || (remote_broadcast_subnet == NULL)) - return False; - - /* - * If we are WINS server, create the WINS_SERVER_SUBNET - don't put on - * the linked list. - */ - - if (lp_we_are_a_wins_server()) - { - if( (wins_server_subnet = make_subnet( "WINS_SERVER_SUBNET", - WINS_SERVER_SUBNET, - ipzero, ipzero, ipzero )) == NULL ) - return False; - } - - return True; + int num_interfaces = iface_count(); + int i; + struct in_addr unicast_ip, ipzero; + extern struct in_addr loopback_ip; + + if(num_interfaces == 0) { + DEBUG(0,("create_subnets: No local interfaces !\n")); + DEBUG(0,("create_subnets: Waiting for an interface to appear ...\n")); + while (iface_count() == 0) { + sleep(5); + load_interfaces(); + } + } + + num_interfaces = iface_count(); + + /* + * Create subnets from all the local interfaces and thread them onto + * the linked list. + */ + + for (i = 0 ; i < num_interfaces; i++) { + struct interface *iface = get_interface(i); + + /* + * We don't want to add a loopback interface, in case + * someone has added 127.0.0.1 for smbd, nmbd needs to + * ignore it here. JRA. + */ + + if (ip_equal(iface->ip, loopback_ip)) { + DEBUG(2,("create_subnets: Ignoring loopback interface.\n" )); + continue; + } + + if (!make_normal_subnet(iface)) + return False; + } + + if (lp_we_are_a_wins_server()) { + /* Pick the first interface ip address as the WINS server ip. */ + unicast_ip = *iface_n_ip(0); + } else { + /* note that we do not set the wins server IP here. We just + set it at zero and let the wins registration code cope + with getting the IPs right for each packet */ + zero_ip(&unicast_ip); + } + + /* + * Create the unicast and remote broadcast subnets. + * Don't put these onto the linked list. + * The ip address of the unicast subnet is set to be + * the WINS server address, if it exists, or ipzero if not. + */ + + unicast_subnet = make_subnet( "UNICAST_SUBNET", UNICAST_SUBNET, + unicast_ip, unicast_ip, unicast_ip); + + zero_ip(&ipzero); + + remote_broadcast_subnet = make_subnet( "REMOTE_BROADCAST_SUBNET", + REMOTE_BROADCAST_SUBNET, + ipzero, ipzero, ipzero); + + if((unicast_subnet == NULL) || (remote_broadcast_subnet == NULL)) + return False; + + /* + * If we are WINS server, create the WINS_SERVER_SUBNET - don't put on + * the linked list. + */ + + if (lp_we_are_a_wins_server()) { + if( (wins_server_subnet = make_subnet( "WINS_SERVER_SUBNET", + WINS_SERVER_SUBNET, + ipzero, ipzero, ipzero )) == NULL ) + return False; + } + + return True; } /******************************************************************* Function to tell us if we can use the unicast subnet. ******************************************************************/ + BOOL we_are_a_wins_client(void) { if (wins_srv_count() > 0) { @@ -326,12 +310,12 @@ Access function used by NEXT_SUBNET_INCLUDING_UNICAST struct subnet_record *get_next_subnet_maybe_unicast(struct subnet_record *subrec) { - if(subrec == unicast_subnet) - return NULL; - else if((subrec->next == NULL) && we_are_a_wins_client()) - return unicast_subnet; - else - return subrec->next; + if(subrec == unicast_subnet) + return NULL; + else if((subrec->next == NULL) && we_are_a_wins_client()) + return unicast_subnet; + else + return subrec->next; } /******************************************************************* @@ -343,19 +327,18 @@ struct subnet_record *get_next_subnet_maybe_unicast(struct subnet_record *subrec struct subnet_record *get_next_subnet_maybe_unicast_or_wins_server(struct subnet_record *subrec) { - if(subrec == unicast_subnet) - { - if(wins_server_subnet) - return wins_server_subnet; - else - return NULL; - } - - if(wins_server_subnet && subrec == wins_server_subnet) - return NULL; - - if((subrec->next == NULL) && we_are_a_wins_client()) - return unicast_subnet; - else - return subrec->next; + if(subrec == unicast_subnet) { + if(wins_server_subnet) + return wins_server_subnet; + else + return NULL; + } + + if(wins_server_subnet && subrec == wins_server_subnet) + return NULL; + + if((subrec->next == NULL) && we_are_a_wins_client()) + return unicast_subnet; + else + return subrec->next; } diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index b9952fb446..337c2f9468 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -47,6 +47,7 @@ static XFILE *fp; This is the NetServerEnum callback. Note sname and comment are in UNIX codepage format. ******************************************************************/ + static void callback(const char *sname, uint32 stype, const char *comment, void *state) { @@ -58,6 +59,7 @@ static void callback(const char *sname, uint32 stype, Log in on the remote server's SMB port to their IPC$ service, do a NetServerEnum and record the results in fname ******************************************************************/ + static void sync_child(char *name, int nm_type, char *workgroup, struct in_addr ip, BOOL local, BOOL servers, @@ -78,10 +80,9 @@ static void sync_child(char *name, int nm_type, } make_nmb_name(&calling, local_machine, 0x0); - make_nmb_name(&called , name , nm_type); + make_nmb_name(&called , name, nm_type); - if (!cli_session_request(&cli, &calling, &called)) - { + if (!cli_session_request(&cli, &calling, &called)) { cli_shutdown(&cli); return; } @@ -120,12 +121,12 @@ static void sync_child(char *name, int nm_type, cli_shutdown(&cli); } - /******************************************************************* initialise a browse sync with another browse server. Log in on the remote server's SMB port to their IPC$ service, do a NetServerEnum and record the results ******************************************************************/ + void sync_browse_lists(struct work_record *work, char *name, int nm_type, struct in_addr ip, BOOL local, BOOL servers) @@ -182,8 +183,9 @@ done: } /********************************************************************** -handle one line from a completed sync file + Handle one line from a completed sync file. **********************************************************************/ + static void complete_one(struct sync_record *s, char *sname, uint32 stype, char *comment) { @@ -235,10 +237,10 @@ static void complete_one(struct sync_record *s, create_server_on_workgroup(work, sname,stype, lp_max_ttl(), comment); } - /********************************************************************** -read the completed sync info - **********************************************************************/ + Read the completed sync info. +**********************************************************************/ + static void complete_sync(struct sync_record *s) { XFILE *f; @@ -251,11 +253,13 @@ static void complete_sync(struct sync_record *s) f = x_fopen(s->fname,O_RDONLY, 0); - if (!f) return; + if (!f) + return; while (!x_feof(f)) { - if (!fgets_slash(line,sizeof(pstring),f)) continue; + if (!fgets_slash(line,sizeof(pstring),f)) + continue; ptr = line; @@ -281,8 +285,9 @@ static void complete_sync(struct sync_record *s) } /********************************************************************** -check for completion of any of the child processes - **********************************************************************/ + Check for completion of any of the child processes. +**********************************************************************/ + void sync_check_completion(void) { struct sync_record *s, *next; diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index 2e65ebb612..bace112752 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -30,92 +30,85 @@ static void wins_proxy_name_query_request_success( struct subnet_record *subrec, struct userdata_struct *userdata, struct nmb_name *nmbname, struct in_addr ip, struct res_rec *rrec) { - struct packet_struct *original_packet; - struct subnet_record *orig_broadcast_subnet; - struct name_record *namerec; - uint16 nb_flags; - int num_ips; - int i; - int ttl = 3600; /* By default one hour in the cache. */ - struct in_addr *iplist; - - /* Extract the original packet and the original broadcast subnet from - the userdata. */ - - memcpy( (char *)&orig_broadcast_subnet, userdata->data, sizeof(struct subnet_record *) ); - memcpy( (char *)&original_packet, &userdata->data[sizeof(struct subnet_record *)], - sizeof(struct packet_struct *) ); - - nb_flags = get_nb_flags( rrec->rdata ); - - num_ips = rrec->rdlength / 6; - if(num_ips == 0) - { - DEBUG(0,("wins_proxy_name_query_request_success: Invalid number of IP records (0) \ + nstring name; + struct packet_struct *original_packet; + struct subnet_record *orig_broadcast_subnet; + struct name_record *namerec; + uint16 nb_flags; + int num_ips; + int i; + int ttl = 3600; /* By default one hour in the cache. */ + struct in_addr *iplist; + + /* Extract the original packet and the original broadcast subnet from + the userdata. */ + + memcpy( (char *)&orig_broadcast_subnet, userdata->data, sizeof(struct subnet_record *) ); + memcpy( (char *)&original_packet, &userdata->data[sizeof(struct subnet_record *)], + sizeof(struct packet_struct *) ); + + nb_flags = get_nb_flags( rrec->rdata ); + + num_ips = rrec->rdlength / 6; + if(num_ips == 0) { + DEBUG(0,("wins_proxy_name_query_request_success: Invalid number of IP records (0) \ returned for name %s.\n", nmb_namestr(nmbname) )); - return; - } - - if(num_ips == 1) - iplist = &ip; - else - { - if((iplist = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr) )) == NULL) - { - DEBUG(0,("wins_proxy_name_query_request_success: malloc fail !\n")); - return; - } - - for(i = 0; i < num_ips; i++) - putip( (char *)&iplist[i], (char *)&rrec->rdata[ (i*6) + 2]); - } - - /* Add the queried name to the original subnet as a WINS_PROXY_NAME. */ - - if(rrec == PERMANENT_TTL) - ttl = lp_max_ttl(); - - namerec = add_name_to_subnet( orig_broadcast_subnet, nmbname->name, - nmbname->name_type, nb_flags, ttl, - WINS_PROXY_NAME, num_ips, iplist ); - - if(iplist != &ip) - SAFE_FREE(iplist); - - /* - * Check that none of the IP addresses we are returning is on the - * same broadcast subnet as the original requesting packet. If it - * is then don't reply (although we still need to add the name - * to the cache) as the actual machine will be replying also - * and we don't want two replies to a broadcast query. - */ - - if(namerec && original_packet->packet.nmb.header.nm_flags.bcast) - { - for( i = 0; i < namerec->data.num_ips; i++) - { - if( same_net( namerec->data.ip[i], - orig_broadcast_subnet->myip, - orig_broadcast_subnet->mask_ip ) ) - { - DEBUG( 5, ( "wins_proxy_name_query_request_success: name %s is a WINS \ + return; + } + + if(num_ips == 1) { + iplist = &ip; + } else { + if((iplist = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr) )) == NULL) { + DEBUG(0,("wins_proxy_name_query_request_success: malloc fail !\n")); + return; + } + + for(i = 0; i < num_ips; i++) + putip( (char *)&iplist[i], (char *)&rrec->rdata[ (i*6) + 2]); + } + + /* Add the queried name to the original subnet as a WINS_PROXY_NAME. */ + + if(rrec == PERMANENT_TTL) + ttl = lp_max_ttl(); + + pull_ascii_nstring(name, nmbname->name); + namerec = add_name_to_subnet( orig_broadcast_subnet, name, + nmbname->name_type, nb_flags, ttl, + WINS_PROXY_NAME, num_ips, iplist ); + + if(iplist != &ip) + SAFE_FREE(iplist); + + /* + * Check that none of the IP addresses we are returning is on the + * same broadcast subnet as the original requesting packet. If it + * is then don't reply (although we still need to add the name + * to the cache) as the actual machine will be replying also + * and we don't want two replies to a broadcast query. + */ + + if(namerec && original_packet->packet.nmb.header.nm_flags.bcast) { + for( i = 0; i < namerec->data.num_ips; i++) { + if( same_net( namerec->data.ip[i], orig_broadcast_subnet->myip, + orig_broadcast_subnet->mask_ip ) ) { + DEBUG( 5, ( "wins_proxy_name_query_request_success: name %s is a WINS \ proxy name and is also on the same subnet (%s) as the requestor. \ -Not replying.\n", - nmb_namestr(&namerec->name), - orig_broadcast_subnet->subnet_name ) ); - return; - } - } - } - - /* Finally reply to the original name query. */ - reply_netbios_packet(original_packet, /* Packet to reply to. */ - 0, /* Result code. */ - NMB_QUERY, /* nmbd type code. */ - NMB_NAME_QUERY_OPCODE, /* opcode. */ - ttl, /* ttl. */ - rrec->rdata, /* data to send. */ - rrec->rdlength); /* data length. */ +Not replying.\n", nmb_namestr(&namerec->name), orig_broadcast_subnet->subnet_name ) ); + return; + } + } + } + + /* Finally reply to the original name query. */ + reply_netbios_packet(original_packet, /* Packet to reply to. */ + 0, /* Result code. */ + NMB_QUERY, /* nmbd type code. */ + NMB_NAME_QUERY_OPCODE, /* opcode. */ + ttl, /* ttl. */ + rrec->rdata, /* data to send. */ + rrec->rdlength); /* data length. */ } /**************************************************************************** @@ -126,7 +119,7 @@ static void wins_proxy_name_query_request_fail(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *question_name, int fail_code) { - DEBUG(4,("wins_proxy_name_query_request_fail: WINS server returned error code %d for lookup \ + DEBUG(4,("wins_proxy_name_query_request_fail: WINS server returned error code %d for lookup \ of name %s.\n", fail_code, nmb_namestr(question_name) )); } @@ -137,38 +130,35 @@ proxy query returns. static struct userdata_struct *wins_proxy_userdata_copy_fn(struct userdata_struct *userdata) { - struct packet_struct *p, *copy_of_p; - struct userdata_struct *new_userdata = - (struct userdata_struct *)malloc( userdata->userdata_len ); + struct packet_struct *p, *copy_of_p; + struct userdata_struct *new_userdata = (struct userdata_struct *)malloc( userdata->userdata_len ); - if(new_userdata == NULL) - return NULL; + if(new_userdata == NULL) + return NULL; - new_userdata->copy_fn = userdata->copy_fn; - new_userdata->free_fn = userdata->free_fn; - new_userdata->userdata_len = userdata->userdata_len; + new_userdata->copy_fn = userdata->copy_fn; + new_userdata->free_fn = userdata->free_fn; + new_userdata->userdata_len = userdata->userdata_len; - /* Copy the subnet_record pointer. */ - memcpy( new_userdata->data, userdata->data, sizeof(struct subnet_record *) ); + /* Copy the subnet_record pointer. */ + memcpy( new_userdata->data, userdata->data, sizeof(struct subnet_record *) ); - /* Extract the pointer to the packet struct */ - memcpy((char *)&p, &userdata->data[sizeof(struct subnet_record *)], - sizeof(struct packet_struct *) ); + /* Extract the pointer to the packet struct */ + memcpy((char *)&p, &userdata->data[sizeof(struct subnet_record *)], sizeof(struct packet_struct *) ); - /* Do a deep copy of the packet. */ - if((copy_of_p = copy_packet(p)) == NULL) - { - SAFE_FREE(new_userdata); - return NULL; - } + /* Do a deep copy of the packet. */ + if((copy_of_p = copy_packet(p)) == NULL) { + SAFE_FREE(new_userdata); + return NULL; + } - /* Lock the copy. */ - copy_of_p->locked = True; + /* Lock the copy. */ + copy_of_p->locked = True; - memcpy( &new_userdata->data[sizeof(struct subnet_record *)], (char *)©_of_p, - sizeof(struct packet_struct *) ); + memcpy( &new_userdata->data[sizeof(struct subnet_record *)], (char *)©_of_p, + sizeof(struct packet_struct *) ); - return new_userdata; + return new_userdata; } /**************************************************************************** @@ -178,18 +168,18 @@ proxy query returned. static void wins_proxy_userdata_free_fn(struct userdata_struct *userdata) { - struct packet_struct *p; + struct packet_struct *p; - /* Extract the pointer to the packet struct */ - memcpy((char *)&p, &userdata->data[sizeof(struct subnet_record *)], - sizeof(struct packet_struct *)); + /* Extract the pointer to the packet struct */ + memcpy((char *)&p, &userdata->data[sizeof(struct subnet_record *)], + sizeof(struct packet_struct *)); - /* Unlock the packet. */ - p->locked = False; + /* Unlock the packet. */ + p->locked = False; - free_packet(p); - ZERO_STRUCTP(userdata); - SAFE_FREE(userdata); + free_packet(p); + ZERO_STRUCTP(userdata); + SAFE_FREE(userdata); } /**************************************************************************** @@ -200,22 +190,24 @@ void make_wins_proxy_name_query_request( struct subnet_record *subrec, struct packet_struct *incoming_packet, struct nmb_name *question_name) { - long *ud[(sizeof(struct userdata_struct) + sizeof(struct subrec *) + - sizeof(struct packet_struct *))/sizeof(long *) + 1]; - struct userdata_struct *userdata = (struct userdata_struct *)ud; + long *ud[(sizeof(struct userdata_struct) + sizeof(struct subrec *) + + sizeof(struct packet_struct *))/sizeof(long *) + 1]; + struct userdata_struct *userdata = (struct userdata_struct *)ud; + nstring qname; - memset(ud, '\0', sizeof(ud)); + memset(ud, '\0', sizeof(ud)); - userdata->copy_fn = wins_proxy_userdata_copy_fn; - userdata->free_fn = wins_proxy_userdata_free_fn; - userdata->userdata_len = sizeof(ud); - memcpy( userdata->data, (char *)&subrec, sizeof(struct subnet_record *)); - memcpy( &userdata->data[sizeof(struct subnet_record *)], (char *)&incoming_packet, - sizeof(struct packet_struct *)); - - /* Now use the unicast subnet to query the name with the WINS server. */ - query_name( unicast_subnet, question_name->name, question_name->name_type, - wins_proxy_name_query_request_success, - wins_proxy_name_query_request_fail, - userdata); + userdata->copy_fn = wins_proxy_userdata_copy_fn; + userdata->free_fn = wins_proxy_userdata_free_fn; + userdata->userdata_len = sizeof(ud); + memcpy( userdata->data, (char *)&subrec, sizeof(struct subnet_record *)); + memcpy( &userdata->data[sizeof(struct subnet_record *)], (char *)&incoming_packet, + sizeof(struct packet_struct *)); + + /* Now use the unicast subnet to query the name with the WINS server. */ + pull_ascii_nstring(qname, question_name->name); + query_name( unicast_subnet, qname, question_name->name_type, + wins_proxy_name_query_request_success, + wins_proxy_name_query_request_fail, + userdata); } diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 784c909c81..1abff5d5e2 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -2,7 +2,7 @@ Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 - Copyright (C) Jeremy Allison 1994-1998 + Copyright (C) Jeremy Allison 1994-2003 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -26,8 +26,9 @@ #define WINS_VERSION 1 /**************************************************************************** -change the wins owner address in the record. + Change the wins owner address in the record. *****************************************************************************/ + static void update_wins_owner(struct name_record *namerec, struct in_addr wins_ip) { if (namerec==NULL) @@ -36,8 +37,9 @@ static void update_wins_owner(struct name_record *namerec, struct in_addr wins_i } /**************************************************************************** -create the wins flags based on the nb flags and the input value. + Create the wins flags based on the nb flags and the input value. *****************************************************************************/ + static void update_wins_flag(struct name_record *namerec, int flags) { if (namerec==NULL) @@ -74,12 +76,12 @@ static void update_wins_flag(struct name_record *namerec, int flags) DEBUG(8,("update_wins_flag: nbflags: 0x%x, ttl: 0x%d, flags: 0x%x, winsflags: 0x%x\n", namerec->data.nb_flags, (int)namerec->data.death_time, flags, namerec->data.wins_flags)); - } /**************************************************************************** -return the general ID value and increase it if requested + Return the general ID value and increase it if requested. *****************************************************************************/ + static void get_global_id_and_update(SMB_BIG_UINT *current_id, BOOL update) { /* @@ -98,8 +100,9 @@ static void get_global_id_and_update(SMB_BIG_UINT *current_id, BOOL update) } /**************************************************************************** -possibly call the WINS hook external program when a WINS change is made + Possibly call the WINS hook external program when a WINS change is made. *****************************************************************************/ + static void wins_hook(const char *operation, struct name_record *namerec, int ttl) { pstring command; @@ -139,63 +142,58 @@ Determine if this packet should be allocated to the WINS server. BOOL packet_is_for_wins_server(struct packet_struct *packet) { - struct nmb_packet *nmb = &packet->packet.nmb; - - /* Only unicast packets go to a WINS server. */ - if((wins_server_subnet == NULL) || (nmb->header.nm_flags.bcast == True)) - { - DEBUG(10, ("packet_is_for_wins_server: failing WINS test #1.\n")); - return False; - } - - /* Check for node status requests. */ - if (nmb->question.question_type != QUESTION_TYPE_NB_QUERY) - return False; - - switch(nmb->header.opcode) - { - /* - * A WINS server issues WACKS, not receives them. - */ - case NMB_WACK_OPCODE: - DEBUG(10, ("packet_is_for_wins_server: failing WINS test #2 (WACK).\n")); - return False; - /* - * A WINS server only processes registration and - * release requests, not responses. - */ - case NMB_NAME_REG_OPCODE: - case NMB_NAME_MULTIHOMED_REG_OPCODE: - case NMB_NAME_REFRESH_OPCODE_8: /* ambiguity in rfc1002 about which is correct. */ - case NMB_NAME_REFRESH_OPCODE_9: /* WinNT uses 8 by default. */ - if(nmb->header.response) - { - DEBUG(10, ("packet_is_for_wins_server: failing WINS test #3 (response = 1).\n")); - return False; - } - break; - - case NMB_NAME_RELEASE_OPCODE: - if(nmb->header.response) - { - DEBUG(10, ("packet_is_for_wins_server: failing WINS test #4 (response = 1).\n")); - return False; - } - break; - - /* - * Only process unicast name queries with rd = 1. - */ - case NMB_NAME_QUERY_OPCODE: - if(!nmb->header.response && !nmb->header.nm_flags.recursion_desired) - { - DEBUG(10, ("packet_is_for_wins_server: failing WINS test #5 (response = 1).\n")); - return False; - } - break; - } - - return True; + struct nmb_packet *nmb = &packet->packet.nmb; + + /* Only unicast packets go to a WINS server. */ + if((wins_server_subnet == NULL) || (nmb->header.nm_flags.bcast == True)) { + DEBUG(10, ("packet_is_for_wins_server: failing WINS test #1.\n")); + return False; + } + + /* Check for node status requests. */ + if (nmb->question.question_type != QUESTION_TYPE_NB_QUERY) + return False; + + switch(nmb->header.opcode) { + /* + * A WINS server issues WACKS, not receives them. + */ + case NMB_WACK_OPCODE: + DEBUG(10, ("packet_is_for_wins_server: failing WINS test #2 (WACK).\n")); + return False; + /* + * A WINS server only processes registration and + * release requests, not responses. + */ + case NMB_NAME_REG_OPCODE: + case NMB_NAME_MULTIHOMED_REG_OPCODE: + case NMB_NAME_REFRESH_OPCODE_8: /* ambiguity in rfc1002 about which is correct. */ + case NMB_NAME_REFRESH_OPCODE_9: /* WinNT uses 8 by default. */ + if(nmb->header.response) { + DEBUG(10, ("packet_is_for_wins_server: failing WINS test #3 (response = 1).\n")); + return False; + } + break; + + case NMB_NAME_RELEASE_OPCODE: + if(nmb->header.response) { + DEBUG(10, ("packet_is_for_wins_server: failing WINS test #4 (response = 1).\n")); + return False; + } + break; + + /* + * Only process unicast name queries with rd = 1. + */ + case NMB_NAME_QUERY_OPCODE: + if(!nmb->header.response && !nmb->header.nm_flags.recursion_desired) { + DEBUG(10, ("packet_is_for_wins_server: failing WINS test #5 (response = 1).\n")); + return False; + } + break; + } + + return True; } /**************************************************************************** @@ -204,15 +202,15 @@ Utility function to decide what ttl to give a register/refresh request. static int get_ttl_from_packet(struct nmb_packet *nmb) { - int ttl = nmb->additional->ttl; + int ttl = nmb->additional->ttl; - if(ttl < lp_min_wins_ttl() ) - ttl = lp_min_wins_ttl(); + if(ttl < lp_min_wins_ttl() ) + ttl = lp_min_wins_ttl(); - if(ttl > lp_max_wins_ttl() ) - ttl = lp_max_wins_ttl(); + if(ttl > lp_max_wins_ttl() ) + ttl = lp_max_wins_ttl(); - return ttl; + return ttl; } /**************************************************************************** @@ -221,177 +219,160 @@ Load or create the WINS database. BOOL initialise_wins(void) { - time_t time_now = time(NULL); - XFILE *fp; - pstring line; - - if(!lp_we_are_a_wins_server()) - return True; - - add_samba_names_to_subnet(wins_server_subnet); - - if((fp = x_fopen(lock_path(WINS_LIST),O_RDONLY,0)) == NULL) - { - DEBUG(2,("initialise_wins: Can't open wins database file %s. Error was %s\n", - WINS_LIST, strerror(errno) )); - return True; - } - - while (!x_feof(fp)) - { - pstring name_str, ip_str, ttl_str, nb_flags_str; - unsigned int num_ips; - pstring name; - struct in_addr *ip_list; - int type = 0; - int nb_flags; - int ttl; - const char *ptr; - char *p; - BOOL got_token; - BOOL was_ip; - int i; - unsigned hash; - int version; - - /* Read a line from the wins.dat file. Strips whitespace - from the beginning and end of the line. - */ - if (!fgets_slash(line,sizeof(pstring),fp)) - continue; + time_t time_now = time(NULL); + XFILE *fp; + pstring line; + + if(!lp_we_are_a_wins_server()) + return True; + + add_samba_names_to_subnet(wins_server_subnet); + + if((fp = x_fopen(lock_path(WINS_LIST),O_RDONLY,0)) == NULL) { + DEBUG(2,("initialise_wins: Can't open wins database file %s. Error was %s\n", + WINS_LIST, strerror(errno) )); + return True; + } + + while (!x_feof(fp)) { + pstring name_str, ip_str, ttl_str, nb_flags_str; + unsigned int num_ips; + pstring name; + struct in_addr *ip_list; + int type = 0; + int nb_flags; + int ttl; + const char *ptr; + char *p; + BOOL got_token; + BOOL was_ip; + int i; + unsigned int hash; + int version; + + /* Read a line from the wins.dat file. Strips whitespace + from the beginning and end of the line. */ + if (!fgets_slash(line,sizeof(pstring),fp)) + continue; - if (*line == '#') - continue; - - if (strncmp(line,"VERSION ", 8) == 0) { - if (sscanf(line,"VERSION %d %u", &version, &hash) != 2 || - version != WINS_VERSION) { - DEBUG(0,("Discarding invalid wins.dat file [%s]\n",line)); - x_fclose(fp); - return True; - } - continue; - } - - ptr = line; - - /* - * Now we handle multiple IP addresses per name we need - * to iterate over the line twice. The first time to - * determine how many IP addresses there are, the second - * time to actually parse them into the ip_list array. - */ - - if (!next_token(&ptr,name_str,NULL,sizeof(name_str))) - { - DEBUG(0,("initialise_wins: Failed to parse name when parsing line %s\n", line )); - continue; - } - - if (!next_token(&ptr,ttl_str,NULL,sizeof(ttl_str))) - { - DEBUG(0,("initialise_wins: Failed to parse time to live when parsing line %s\n", line )); - continue; - } - - /* - * Determine the number of IP addresses per line. - */ - num_ips = 0; - do - { - got_token = next_token(&ptr,ip_str,NULL,sizeof(ip_str)); - was_ip = False; - - if(got_token && strchr(ip_str, '.')) - { - num_ips++; - was_ip = True; - } - } while( got_token && was_ip); - - if(num_ips == 0) - { - DEBUG(0,("initialise_wins: Missing IP address when parsing line %s\n", line )); - continue; - } - - if(!got_token) - { - DEBUG(0,("initialise_wins: Missing nb_flags when parsing line %s\n", line )); - continue; - } - - /* Allocate the space for the ip_list. */ - if((ip_list = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr))) == NULL) - { - DEBUG(0,("initialise_wins: Malloc fail !\n")); - return False; - } + if (*line == '#') + continue; + + if (strncmp(line,"VERSION ", 8) == 0) { + if (sscanf(line,"VERSION %d %u", &version, &hash) != 2 || + version != WINS_VERSION) { + DEBUG(0,("Discarding invalid wins.dat file [%s]\n",line)); + x_fclose(fp); + return True; + } + continue; + } + + ptr = line; + + /* + * Now we handle multiple IP addresses per name we need + * to iterate over the line twice. The first time to + * determine how many IP addresses there are, the second + * time to actually parse them into the ip_list array. + */ + + if (!next_token(&ptr,name_str,NULL,sizeof(name_str))) { + DEBUG(0,("initialise_wins: Failed to parse name when parsing line %s\n", line )); + continue; + } + + if (!next_token(&ptr,ttl_str,NULL,sizeof(ttl_str))) { + DEBUG(0,("initialise_wins: Failed to parse time to live when parsing line %s\n", line )); + continue; + } + + /* + * Determine the number of IP addresses per line. + */ + num_ips = 0; + do { + got_token = next_token(&ptr,ip_str,NULL,sizeof(ip_str)); + was_ip = False; + + if(got_token && strchr(ip_str, '.')) { + num_ips++; + was_ip = True; + } + } while( got_token && was_ip); + + if(num_ips == 0) { + DEBUG(0,("initialise_wins: Missing IP address when parsing line %s\n", line )); + continue; + } + + if(!got_token) { + DEBUG(0,("initialise_wins: Missing nb_flags when parsing line %s\n", line )); + continue; + } + + /* Allocate the space for the ip_list. */ + if((ip_list = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr))) == NULL) { + DEBUG(0,("initialise_wins: Malloc fail !\n")); + return False; + } - /* Reset and re-parse the line. */ - ptr = line; - next_token(&ptr,name_str,NULL,sizeof(name_str)); - next_token(&ptr,ttl_str,NULL,sizeof(ttl_str)); - for(i = 0; i < num_ips; i++) - { - next_token(&ptr, ip_str, NULL, sizeof(ip_str)); - ip_list[i] = *interpret_addr2(ip_str); - } - next_token(&ptr,nb_flags_str,NULL, sizeof(nb_flags_str)); - - /* - * Deal with SELF or REGISTER name encoding. Default is REGISTER - * for compatibility with old nmbds. - */ - - if(nb_flags_str[strlen(nb_flags_str)-1] == 'S') - { - DEBUG(5,("initialise_wins: Ignoring SELF name %s\n", line)); - SAFE_FREE(ip_list); - continue; - } + /* Reset and re-parse the line. */ + ptr = line; + next_token(&ptr,name_str,NULL,sizeof(name_str)); + next_token(&ptr,ttl_str,NULL,sizeof(ttl_str)); + for(i = 0; i < num_ips; i++) { + next_token(&ptr, ip_str, NULL, sizeof(ip_str)); + ip_list[i] = *interpret_addr2(ip_str); + } + next_token(&ptr,nb_flags_str,NULL, sizeof(nb_flags_str)); + + /* + * Deal with SELF or REGISTER name encoding. Default is REGISTER + * for compatibility with old nmbds. + */ + + if(nb_flags_str[strlen(nb_flags_str)-1] == 'S') { + DEBUG(5,("initialise_wins: Ignoring SELF name %s\n", line)); + SAFE_FREE(ip_list); + continue; + } - if(nb_flags_str[strlen(nb_flags_str)-1] == 'R') - nb_flags_str[strlen(nb_flags_str)-1] = '\0'; + if(nb_flags_str[strlen(nb_flags_str)-1] == 'R') + nb_flags_str[strlen(nb_flags_str)-1] = '\0'; - /* Netbios name. # divides the name from the type (hex): netbios#xx */ - pstrcpy(name,name_str); + /* Netbios name. # divides the name from the type (hex): netbios#xx */ + pstrcpy(name,name_str); - if((p = strchr(name,'#')) != NULL) - { - *p = 0; - sscanf(p+1,"%x",&type); - } + if((p = strchr(name,'#')) != NULL) { + *p = 0; + sscanf(p+1,"%x",&type); + } - /* Decode the netbios flags (hex) and the time-to-live (in seconds). */ - sscanf(nb_flags_str,"%x",&nb_flags); - sscanf(ttl_str,"%d",&ttl); - - /* add all entries that have 60 seconds or more to live */ - if ((ttl - 60) > time_now || ttl == PERMANENT_TTL) - { - if(ttl != PERMANENT_TTL) - ttl -= time_now; + /* Decode the netbios flags (hex) and the time-to-live (in seconds). */ + sscanf(nb_flags_str,"%x",&nb_flags); + sscanf(ttl_str,"%d",&ttl); + + /* add all entries that have 60 seconds or more to live */ + if ((ttl - 60) > time_now || ttl == PERMANENT_TTL) { + if(ttl != PERMANENT_TTL) + ttl -= time_now; - DEBUG( 4, ("initialise_wins: add name: %s#%02x ttl = %d first IP %s flags = %2x\n", - name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); - - (void)add_name_to_subnet( wins_server_subnet, name, type, nb_flags, - ttl, REGISTER_NAME, num_ips, ip_list ); - - } - else - { - DEBUG(4, ("initialise_wins: not adding name (ttl problem) %s#%02x ttl = %d first IP %s flags = %2x\n", - name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); - } + DEBUG( 4, ("initialise_wins: add name: %s#%02x ttl = %d first IP %s flags = %2x\n", + name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); + + (void)add_name_to_subnet( wins_server_subnet, name, type, nb_flags, + ttl, REGISTER_NAME, num_ips, ip_list ); + } else { + DEBUG(4, ("initialise_wins: not adding name (ttl problem) %s#%02x ttl = %d first IP %s flags = %2x\n", + name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); + } - SAFE_FREE(ip_list); - } + SAFE_FREE(ip_list); + } - x_fclose(fp); - return True; + x_fclose(fp); + return True; } /**************************************************************************** @@ -400,30 +381,33 @@ Send a WINS WACK (Wait ACKnowledgement) response. static void send_wins_wack_response(int ttl, struct packet_struct *p) { - struct nmb_packet *nmb = &p->packet.nmb; - unsigned char rdata[2]; - - rdata[0] = rdata[1] = 0; - - /* Taken from nmblib.c - we need to send back almost - identical bytes from the requesting packet header. */ - - rdata[0] = (nmb->header.opcode & 0xF) << 3; - if (nmb->header.nm_flags.authoritative && - nmb->header.response) rdata[0] |= 0x4; - if (nmb->header.nm_flags.trunc) rdata[0] |= 0x2; - if (nmb->header.nm_flags.recursion_desired) rdata[0] |= 0x1; - if (nmb->header.nm_flags.recursion_available && - nmb->header.response) rdata[1] |= 0x80; - if (nmb->header.nm_flags.bcast) rdata[1] |= 0x10; - - reply_netbios_packet(p, /* Packet to reply to. */ - 0, /* Result code. */ - NMB_WAIT_ACK, /* nmbd type code. */ - NMB_WACK_OPCODE, /* opcode. */ - ttl, /* ttl. */ - (char *)rdata, /* data to send. */ - 2); /* data length. */ + struct nmb_packet *nmb = &p->packet.nmb; + unsigned char rdata[2]; + + rdata[0] = rdata[1] = 0; + + /* Taken from nmblib.c - we need to send back almost + identical bytes from the requesting packet header. */ + + rdata[0] = (nmb->header.opcode & 0xF) << 3; + if (nmb->header.nm_flags.authoritative && nmb->header.response) + rdata[0] |= 0x4; + if (nmb->header.nm_flags.trunc) + rdata[0] |= 0x2; + if (nmb->header.nm_flags.recursion_desired) + rdata[0] |= 0x1; + if (nmb->header.nm_flags.recursion_available && nmb->header.response) + rdata[1] |= 0x80; + if (nmb->header.nm_flags.bcast) + rdata[1] |= 0x10; + + reply_netbios_packet(p, /* Packet to reply to. */ + 0, /* Result code. */ + NMB_WAIT_ACK, /* nmbd type code. */ + NMB_WACK_OPCODE, /* opcode. */ + ttl, /* ttl. */ + (char *)rdata, /* data to send. */ + 2); /* data length. */ } /**************************************************************************** @@ -432,18 +416,18 @@ Send a WINS name registration response. static void send_wins_name_registration_response(int rcode, int ttl, struct packet_struct *p) { - struct nmb_packet *nmb = &p->packet.nmb; - char rdata[6]; - - memcpy(&rdata[0], &nmb->additional->rdata[0], 6); - - reply_netbios_packet(p, /* Packet to reply to. */ - rcode, /* Result code. */ - WINS_REG, /* nmbd type code. */ - NMB_NAME_REG_OPCODE, /* opcode. */ - ttl, /* ttl. */ - rdata, /* data to send. */ - 6); /* data length. */ + struct nmb_packet *nmb = &p->packet.nmb; + char rdata[6]; + + memcpy(&rdata[0], &nmb->additional->rdata[0], 6); + + reply_netbios_packet(p, /* Packet to reply to. */ + rcode, /* Result code. */ + WINS_REG, /* nmbd type code. */ + NMB_NAME_REG_OPCODE, /* opcode. */ + ttl, /* ttl. */ + rdata, /* data to send. */ + 6); /* data length. */ } /*********************************************************************** @@ -453,139 +437,128 @@ static void send_wins_name_registration_response(int rcode, int ttl, struct pack void wins_process_name_refresh_request(struct subnet_record *subrec, struct packet_struct *p) { - struct nmb_packet *nmb = &p->packet.nmb; - struct nmb_name *question = &nmb->question.question_name; - BOOL bcast = nmb->header.nm_flags.bcast; - uint16 nb_flags = get_nb_flags(nmb->additional->rdata); - BOOL group = (nb_flags & NB_GROUP) ? True : False; - struct name_record *namerec = NULL; - int ttl = get_ttl_from_packet(nmb); - struct in_addr from_ip; - struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); - - putip((char *)&from_ip,&nmb->additional->rdata[2]); - - if(bcast) - { - /* - * We should only get unicast name refresh packets here. - * Anyone trying to refresh broadcast should not be going to a WINS - * server. Log an error here. - */ - - DEBUG(0,("wins_process_name_refresh_request: broadcast name refresh request \ + struct nmb_packet *nmb = &p->packet.nmb; + struct nmb_name *question = &nmb->question.question_name; + BOOL bcast = nmb->header.nm_flags.bcast; + uint16 nb_flags = get_nb_flags(nmb->additional->rdata); + BOOL group = (nb_flags & NB_GROUP) ? True : False; + struct name_record *namerec = NULL; + int ttl = get_ttl_from_packet(nmb); + struct in_addr from_ip; + struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); + + putip((char *)&from_ip,&nmb->additional->rdata[2]); + + if(bcast) { + /* + * We should only get unicast name refresh packets here. + * Anyone trying to refresh broadcast should not be going to a WINS + * server. Log an error here. + */ + + DEBUG(0,("wins_process_name_refresh_request: broadcast name refresh request \ received for name %s from IP %s on subnet %s. Error - should not be sent to WINS server\n", - nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); - return; - } + nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + return; + } - DEBUG(3,("wins_process_name_refresh_request: Name refresh for name %s \ + DEBUG(3,("wins_process_name_refresh_request: Name refresh for name %s \ IP %s\n", nmb_namestr(question), inet_ntoa(from_ip) )); - /* - * See if the name already exists. - */ + /* + * See if the name already exists. + */ - namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); + namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); - /* - * If this is a refresh request and the name doesn't exist then - * treat it like a registration request. This allows us to recover - * from errors (tridge) - */ + /* + * If this is a refresh request and the name doesn't exist then + * treat it like a registration request. This allows us to recover + * from errors (tridge) + */ - if(namerec == NULL) - { - DEBUG(3,("wins_process_name_refresh_request: Name refresh for name %s and \ + if(namerec == NULL) { + DEBUG(3,("wins_process_name_refresh_request: Name refresh for name %s and \ the name does not exist. Treating as registration.\n", nmb_namestr(question) )); - wins_process_name_registration_request(subrec,p); - return; - } - - /* - * if the name is present but not active, - * simply remove it and treat the request - * as a registration - */ - if (namerec != NULL && !WINS_STATE_ACTIVE(namerec)) - { - DEBUG(5,("wins_process_name_refresh_request: Name (%s) in WINS was \ + wins_process_name_registration_request(subrec,p); + return; + } + + /* + * if the name is present but not active, + * simply remove it and treat the request + * as a registration + */ + if (namerec != NULL && !WINS_STATE_ACTIVE(namerec)) { + DEBUG(5,("wins_process_name_refresh_request: Name (%s) in WINS was \ not active - removing it.\n", nmb_namestr(question) )); - remove_name_from_namelist( subrec, namerec ); - namerec = NULL; - wins_process_name_registration_request(subrec,p); - return; - } - - /* - * Check that the group bits for the refreshing name and the - * name in our database match. - */ - - if((namerec != NULL) && ((group && !NAME_GROUP(namerec)) || (!group && NAME_GROUP(namerec))) ) - { - DEBUG(3,("wins_process_name_refresh_request: Name %s group bit = %s \ + remove_name_from_namelist( subrec, namerec ); + namerec = NULL; + wins_process_name_registration_request(subrec,p); + return; + } + + /* + * Check that the group bits for the refreshing name and the + * name in our database match. + */ + + if((namerec != NULL) && ((group && !NAME_GROUP(namerec)) || (!group && NAME_GROUP(namerec))) ) { + DEBUG(3,("wins_process_name_refresh_request: Name %s group bit = %s \ does not match group bit in WINS for this name.\n", nmb_namestr(question), group ? "True" : "False" )); - send_wins_name_registration_response(RFS_ERR, 0, p); - return; - } - - /* - * For a unique name check that the person refreshing the name is one of the registered IP - * addresses. If not - fail the refresh. Do the same for group names with a type of 0x1c. - * Just return success for unique 0x1d refreshes. For normal group names update the ttl - * and return success. - */ - - if((!group || (group && (question->name_type == 0x1c))) && find_ip_in_name_record(namerec, from_ip )) - { - /* - * Update the ttl. - */ - update_name_ttl(namerec, ttl); - - /* - * if the record is a replica: - * we take ownership and update the version ID. - */ - if (!ip_equal(namerec->data.wins_ip, our_fake_ip)) { - update_wins_owner(namerec, our_fake_ip); - get_global_id_and_update(&namerec->data.id, True); - } - - send_wins_name_registration_response(0, ttl, p); - wins_hook("refresh", namerec, ttl); - return; - } - else if(group) - { - /* - * Normal groups are all registered with an IP address of 255.255.255.255 - * so we can't search for the IP address. - */ - update_name_ttl(namerec, ttl); - send_wins_name_registration_response(0, ttl, p); - return; - } - else if(!group && (question->name_type == 0x1d)) - { - /* - * Special name type - just pretend the refresh succeeded. - */ - send_wins_name_registration_response(0, ttl, p); - return; - } - else - { - /* - * Fail the refresh. - */ - - DEBUG(3,("wins_process_name_refresh_request: Name refresh for name %s with IP %s and \ + send_wins_name_registration_response(RFS_ERR, 0, p); + return; + } + + /* + * For a unique name check that the person refreshing the name is one of the registered IP + * addresses. If not - fail the refresh. Do the same for group names with a type of 0x1c. + * Just return success for unique 0x1d refreshes. For normal group names update the ttl + * and return success. + */ + + if((!group || (group && (question->name_type == 0x1c))) && find_ip_in_name_record(namerec, from_ip )) { + /* + * Update the ttl. + */ + update_name_ttl(namerec, ttl); + + /* + * if the record is a replica: + * we take ownership and update the version ID. + */ + if (!ip_equal(namerec->data.wins_ip, our_fake_ip)) { + update_wins_owner(namerec, our_fake_ip); + get_global_id_and_update(&namerec->data.id, True); + } + + send_wins_name_registration_response(0, ttl, p); + wins_hook("refresh", namerec, ttl); + return; + } else if(group) { + /* + * Normal groups are all registered with an IP address of 255.255.255.255 + * so we can't search for the IP address. + */ + update_name_ttl(namerec, ttl); + send_wins_name_registration_response(0, ttl, p); + return; + } else if(!group && (question->name_type == 0x1d)) { + /* + * Special name type - just pretend the refresh succeeded. + */ + send_wins_name_registration_response(0, ttl, p); + return; + } else { + /* + * Fail the refresh. + */ + + DEBUG(3,("wins_process_name_refresh_request: Name refresh for name %s with IP %s and \ is IP is not known to the name.\n", nmb_namestr(question), inet_ntoa(from_ip) )); - send_wins_name_registration_response(RFS_ERR, 0, p); - return; - } + send_wins_name_registration_response(RFS_ERR, 0, p); + return; + } } /*********************************************************************** @@ -604,17 +577,17 @@ static void wins_register_query_success(struct subnet_record *subrec, struct in_addr ip, struct res_rec *answers) { - struct packet_struct *orig_reg_packet; + struct packet_struct *orig_reg_packet; - memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *)); + memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *)); - DEBUG(3,("wins_register_query_success: Original client at IP %s still wants the \ + DEBUG(3,("wins_register_query_success: Original client at IP %s still wants the \ name %s. Rejecting registration request.\n", inet_ntoa(ip), nmb_namestr(question_name) )); - send_wins_name_registration_response(RFS_ERR, 0, orig_reg_packet); + send_wins_name_registration_response(RFS_ERR, 0, orig_reg_packet); - orig_reg_packet->locked = False; - free_packet(orig_reg_packet); + orig_reg_packet->locked = False; + free_packet(orig_reg_packet); } /*********************************************************************** @@ -632,40 +605,37 @@ static void wins_register_query_fail(struct subnet_record *subrec, struct nmb_name *question_name, int rcode) { - struct userdata_struct *userdata = rrec->userdata; - struct packet_struct *orig_reg_packet; - struct name_record *namerec = NULL; - - memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *)); - - /* - * We want to just add the name, as we now know the original owner - * didn't want it. But we can't just do that as an arbitary - * amount of time may have taken place between the name query - * request and this timeout/error response. So we check that - * the name still exists and is in the same state - if so - * we remove it and call wins_process_name_registration_request() - * as we know it will do the right thing now. - */ - - namerec = find_name_on_subnet(subrec, question_name, FIND_ANY_NAME); - - if( (namerec != NULL) - && (namerec->data.source == REGISTER_NAME) - && ip_equal(rrec->packet->ip, *namerec->data.ip) ) - { - remove_name_from_namelist( subrec, namerec); - namerec = NULL; - } - - if(namerec == NULL) - wins_process_name_registration_request(subrec, orig_reg_packet); - else - DEBUG(2,("wins_register_query_fail: The state of the WINS database changed between \ + struct userdata_struct *userdata = rrec->userdata; + struct packet_struct *orig_reg_packet; + struct name_record *namerec = NULL; + + memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *)); + + /* + * We want to just add the name, as we now know the original owner + * didn't want it. But we can't just do that as an arbitary + * amount of time may have taken place between the name query + * request and this timeout/error response. So we check that + * the name still exists and is in the same state - if so + * we remove it and call wins_process_name_registration_request() + * as we know it will do the right thing now. + */ + + namerec = find_name_on_subnet(subrec, question_name, FIND_ANY_NAME); + + if( (namerec != NULL) && (namerec->data.source == REGISTER_NAME) && ip_equal(rrec->packet->ip, *namerec->data.ip) ) { + remove_name_from_namelist( subrec, namerec); + namerec = NULL; + } + + if(namerec == NULL) + wins_process_name_registration_request(subrec, orig_reg_packet); + else + DEBUG(2,("wins_register_query_fail: The state of the WINS database changed between \ querying for name %s in order to replace it and this reply.\n", nmb_namestr(question_name) )); - orig_reg_packet->locked = False; - free_packet(orig_reg_packet); + orig_reg_packet->locked = False; + free_packet(orig_reg_packet); } /*********************************************************************** @@ -728,279 +698,269 @@ querying for name %s in order to replace it and this reply.\n", nmb_namestr(ques void wins_process_name_registration_request(struct subnet_record *subrec, struct packet_struct *p) { - struct nmb_packet *nmb = &p->packet.nmb; - struct nmb_name *question = &nmb->question.question_name; - BOOL bcast = nmb->header.nm_flags.bcast; - uint16 nb_flags = get_nb_flags(nmb->additional->rdata); - int ttl = get_ttl_from_packet(nmb); - struct name_record *namerec = NULL; - struct in_addr from_ip; - BOOL registering_group_name = (nb_flags & NB_GROUP) ? True : False; - struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); - - putip((char *)&from_ip,&nmb->additional->rdata[2]); - - if(bcast) - { - /* - * We should only get unicast name registration packets here. - * Anyone trying to register broadcast should not be going to a WINS - * server. Log an error here. - */ - - DEBUG(0,("wins_process_name_registration_request: broadcast name registration request \ + nstring name; + struct nmb_packet *nmb = &p->packet.nmb; + struct nmb_name *question = &nmb->question.question_name; + BOOL bcast = nmb->header.nm_flags.bcast; + uint16 nb_flags = get_nb_flags(nmb->additional->rdata); + int ttl = get_ttl_from_packet(nmb); + struct name_record *namerec = NULL; + struct in_addr from_ip; + BOOL registering_group_name = (nb_flags & NB_GROUP) ? True : False; + struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); + + putip((char *)&from_ip,&nmb->additional->rdata[2]); + + if(bcast) { + /* + * We should only get unicast name registration packets here. + * Anyone trying to register broadcast should not be going to a WINS + * server. Log an error here. + */ + + DEBUG(0,("wins_process_name_registration_request: broadcast name registration request \ received for name %s from IP %s on subnet %s. Error - should not be sent to WINS server\n", - nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); - return; - } + nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + return; + } - DEBUG(3,("wins_process_name_registration_request: %s name registration for name %s \ + DEBUG(3,("wins_process_name_registration_request: %s name registration for name %s \ IP %s\n", registering_group_name ? "Group" : "Unique", nmb_namestr(question), inet_ntoa(from_ip) )); - /* - * See if the name already exists. - */ + /* + * See if the name already exists. + */ - namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); + namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); - /* - * if the record exists but NOT in active state, - * consider it dead. - */ - if ( (namerec != NULL) && !WINS_STATE_ACTIVE(namerec)) - { - DEBUG(5,("wins_process_name_registration_request: Name (%s) in WINS was \ + /* + * if the record exists but NOT in active state, + * consider it dead. + */ + if ( (namerec != NULL) && !WINS_STATE_ACTIVE(namerec)) { + DEBUG(5,("wins_process_name_registration_request: Name (%s) in WINS was \ not active - removing it.\n", nmb_namestr(question) )); - remove_name_from_namelist( subrec, namerec ); - namerec = NULL; - } - - /* - * Deal with the case where the name found was a dns entry. - * Remove it as we now have a NetBIOS client registering the - * name. - */ - - if( (namerec != NULL) - && ( (namerec->data.source == DNS_NAME) - || (namerec->data.source == DNSFAIL_NAME) ) ) - { - DEBUG(5,("wins_process_name_registration_request: Name (%s) in WINS was \ + remove_name_from_namelist( subrec, namerec ); + namerec = NULL; + } + + /* + * Deal with the case where the name found was a dns entry. + * Remove it as we now have a NetBIOS client registering the + * name. + */ + + if( (namerec != NULL) && ( (namerec->data.source == DNS_NAME) || (namerec->data.source == DNSFAIL_NAME) ) ) { + DEBUG(5,("wins_process_name_registration_request: Name (%s) in WINS was \ a dns lookup - removing it.\n", nmb_namestr(question) )); - remove_name_from_namelist( subrec, namerec ); - namerec = NULL; - } - - /* - * Reject if the name exists and is not a REGISTER_NAME. - * (ie. Don't allow any static names to be overwritten. - */ - - if((namerec != NULL) && (namerec->data.source != REGISTER_NAME)) - { - DEBUG( 3, ( "wins_process_name_registration_request: Attempt \ + remove_name_from_namelist( subrec, namerec ); + namerec = NULL; + } + + /* + * Reject if the name exists and is not a REGISTER_NAME. + * (ie. Don't allow any static names to be overwritten. + */ + + if((namerec != NULL) && (namerec->data.source != REGISTER_NAME)) { + DEBUG( 3, ( "wins_process_name_registration_request: Attempt \ to register name %s. Name already exists in WINS with source type %d.\n", - nmb_namestr(question), namerec->data.source )); - send_wins_name_registration_response(RFS_ERR, 0, p); - return; - } - - /* - * Special policy decisions based on MS documentation. - * 1). All group names (except names ending in 0x1c) are added as 255.255.255.255. - * 2). All unique names ending in 0x1d are ignored, although a positive response is sent. - */ - - /* - * A group name is always added as the local broadcast address, except - * for group names ending in 0x1c. - * Group names with type 0x1c are registered with individual IP addresses. - */ - - if(registering_group_name && (question->name_type != 0x1c)) - from_ip = *interpret_addr2("255.255.255.255"); - - /* - * Ignore all attempts to register a unique 0x1d name, although return success. - */ - - if(!registering_group_name && (question->name_type == 0x1d)) - { - DEBUG(3,("wins_process_name_registration_request: Ignoring request \ + nmb_namestr(question), namerec->data.source )); + send_wins_name_registration_response(RFS_ERR, 0, p); + return; + } + + /* + * Special policy decisions based on MS documentation. + * 1). All group names (except names ending in 0x1c) are added as 255.255.255.255. + * 2). All unique names ending in 0x1d are ignored, although a positive response is sent. + */ + + /* + * A group name is always added as the local broadcast address, except + * for group names ending in 0x1c. + * Group names with type 0x1c are registered with individual IP addresses. + */ + + if(registering_group_name && (question->name_type != 0x1c)) + from_ip = *interpret_addr2("255.255.255.255"); + + /* + * Ignore all attempts to register a unique 0x1d name, although return success. + */ + + if(!registering_group_name && (question->name_type == 0x1d)) { + DEBUG(3,("wins_process_name_registration_request: Ignoring request \ to register name %s from IP %s.\n", nmb_namestr(question), inet_ntoa(p->ip) )); - send_wins_name_registration_response(0, ttl, p); - return; - } - - /* - * Next two cases are the 'if statement' mentioned above. - */ - - if((namerec != NULL) && NAME_GROUP(namerec)) - { - if(registering_group_name) - { - /* - * If we are adding a group name, the name exists and is also a group entry just add this - * IP address to it and update the ttl. - */ - - DEBUG(3,("wins_process_name_registration_request: Adding IP %s to group name %s.\n", - inet_ntoa(from_ip), nmb_namestr(question) )); - /* - * Check the ip address is not already in the group. - */ - if(!find_ip_in_name_record(namerec, from_ip)) { - add_ip_to_name_record(namerec, from_ip); - /* we need to update the record for replication */ - get_global_id_and_update(&namerec->data.id, True); + send_wins_name_registration_response(0, ttl, p); + return; + } /* - * if the record is a replica, we must change - * the wins owner to us to make the replication updates - * it on the other wins servers. - * And when the partner will receive this record, - * it will update its own record. + * Next two cases are the 'if statement' mentioned above. */ - update_wins_owner(namerec, our_fake_ip); + if((namerec != NULL) && NAME_GROUP(namerec)) { + if(registering_group_name) { + /* + * If we are adding a group name, the name exists and is also a group entry just add this + * IP address to it and update the ttl. + */ + + DEBUG(3,("wins_process_name_registration_request: Adding IP %s to group name %s.\n", + inet_ntoa(from_ip), nmb_namestr(question) )); + + /* + * Check the ip address is not already in the group. + */ + + if(!find_ip_in_name_record(namerec, from_ip)) { + add_ip_to_name_record(namerec, from_ip); + /* we need to update the record for replication */ + get_global_id_and_update(&namerec->data.id, True); + + /* + * if the record is a replica, we must change + * the wins owner to us to make the replication updates + * it on the other wins servers. + * And when the partner will receive this record, + * it will update its own record. + */ + + update_wins_owner(namerec, our_fake_ip); + } + update_name_ttl(namerec, ttl); + send_wins_name_registration_response(0, ttl, p); + return; + } else { - } - update_name_ttl(namerec, ttl); - send_wins_name_registration_response(0, ttl, p); - return; - } - else - { - /* - * If we are adding a unique name, the name exists in the WINS db - * and is a group name then reject the registration. - * - * explanation: groups have a higher priority than unique names. - */ - - DEBUG(3,("wins_process_name_registration_request: Attempt to register name %s. Name \ + /* + * If we are adding a unique name, the name exists in the WINS db + * and is a group name then reject the registration. + * + * explanation: groups have a higher priority than unique names. + */ + + DEBUG(3,("wins_process_name_registration_request: Attempt to register name %s. Name \ already exists in WINS as a GROUP name.\n", nmb_namestr(question) )); - send_wins_name_registration_response(RFS_ERR, 0, p); - return; - } - } - - /* - * From here on down we know that if the name exists in the WINS db it is - * a unique name, not a group name. - */ - - /* - * If the name exists and is one of our names then check the - * registering IP address. If it's not one of ours then automatically - * reject without doing the query - we know we will reject it. - */ - - if((namerec != NULL) && (is_myname(namerec->name.name)) ) - { - if(!ismyip(from_ip)) - { - DEBUG(3,("wins_process_name_registration_request: Attempt to register name %s. Name \ + send_wins_name_registration_response(RFS_ERR, 0, p); + return; + } + } + + /* + * From here on down we know that if the name exists in the WINS db it is + * a unique name, not a group name. + */ + + /* + * If the name exists and is one of our names then check the + * registering IP address. If it's not one of ours then automatically + * reject without doing the query - we know we will reject it. + */ + + pull_ascii_nstring(name, namerec->name.name); + if((namerec != NULL) && (is_myname(name)) ) { + if(!ismyip(from_ip)) { + DEBUG(3,("wins_process_name_registration_request: Attempt to register name %s. Name \ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(question) )); - send_wins_name_registration_response(RFS_ERR, 0, p); - return; - } - else - { - /* - * It's one of our names and one of our IP's - update the ttl. - */ - update_name_ttl(namerec, ttl); - send_wins_name_registration_response(0, ttl, p); - wins_hook("refresh", namerec, ttl); - return; - } - } - - /* - * If the name exists and it is a unique registration and the registering IP - * is the same as the (single) already registered IP then just update the ttl. - * - * But not if the record is an active replica. IF it's a replica, it means it can be - * the same client which has moved and not yet expired. So we don't update - * the ttl in this case and go beyond to do a WACK and query the old client - */ - - if( !registering_group_name - && (namerec != NULL) - && (namerec->data.num_ips == 1) - && ip_equal( namerec->data.ip[0], from_ip ) - && ip_equal(namerec->data.wins_ip, our_fake_ip) ) - { - update_name_ttl( namerec, ttl ); - send_wins_name_registration_response( 0, ttl, p ); - wins_hook("refresh", namerec, ttl); - return; - } - - /* - * Finally if the name exists do a query to the registering machine - * to see if they still claim to have the name. - */ - - if( namerec != NULL ) - { - long *ud[(sizeof(struct userdata_struct) + sizeof(struct packet_struct *))/sizeof(long *) + 1]; - struct userdata_struct *userdata = (struct userdata_struct *)ud; - - /* - * First send a WACK to the registering machine. - */ - - send_wins_wack_response(60, p); - - /* - * When the reply comes back we need the original packet. - * Lock this so it won't be freed and then put it into - * the userdata structure. - */ - - p->locked = True; - - userdata = (struct userdata_struct *)ud; - - userdata->copy_fn = NULL; - userdata->free_fn = NULL; - userdata->userdata_len = sizeof(struct packet_struct *); - memcpy(userdata->data, (char *)&p, sizeof(struct packet_struct *) ); - - /* - * Use the new call to send a query directly to an IP address. - * This sends the query directly to the IP address, and ensures - * the recursion desired flag is not set (you were right Luke :-). - * This function should *only* be called from the WINS server - * code. JRA. - */ - - query_name_from_wins_server( *namerec->data.ip, - question->name, - question->name_type, - wins_register_query_success, - wins_register_query_fail, - userdata ); - return; - } - - /* - * Name did not exist - add it. - */ - - (void)add_name_to_subnet( subrec, question->name, question->name_type, - nb_flags, ttl, REGISTER_NAME, 1, &from_ip); - if ((namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME))) { - get_global_id_and_update(&namerec->data.id, True); - update_wins_owner(namerec, our_fake_ip); - update_wins_flag(namerec, WINS_ACTIVE); - wins_hook("add", namerec, ttl); - } + send_wins_name_registration_response(RFS_ERR, 0, p); + return; + } else { + /* + * It's one of our names and one of our IP's - update the ttl. + */ + update_name_ttl(namerec, ttl); + send_wins_name_registration_response(0, ttl, p); + wins_hook("refresh", namerec, ttl); + return; + } + } - send_wins_name_registration_response(0, ttl, p); + /* + * If the name exists and it is a unique registration and the registering IP + * is the same as the (single) already registered IP then just update the ttl. + * + * But not if the record is an active replica. IF it's a replica, it means it can be + * the same client which has moved and not yet expired. So we don't update + * the ttl in this case and go beyond to do a WACK and query the old client + */ + + if( !registering_group_name + && (namerec != NULL) + && (namerec->data.num_ips == 1) + && ip_equal( namerec->data.ip[0], from_ip ) + && ip_equal(namerec->data.wins_ip, our_fake_ip) ) { + update_name_ttl( namerec, ttl ); + send_wins_name_registration_response( 0, ttl, p ); + wins_hook("refresh", namerec, ttl); + return; + } + + /* + * Finally if the name exists do a query to the registering machine + * to see if they still claim to have the name. + */ + + if( namerec != NULL ) { + long *ud[(sizeof(struct userdata_struct) + sizeof(struct packet_struct *))/sizeof(long *) + 1]; + struct userdata_struct *userdata = (struct userdata_struct *)ud; + + /* + * First send a WACK to the registering machine. + */ + + send_wins_wack_response(60, p); + + /* + * When the reply comes back we need the original packet. + * Lock this so it won't be freed and then put it into + * the userdata structure. + */ + + p->locked = True; + + userdata = (struct userdata_struct *)ud; + + userdata->copy_fn = NULL; + userdata->free_fn = NULL; + userdata->userdata_len = sizeof(struct packet_struct *); + memcpy(userdata->data, (char *)&p, sizeof(struct packet_struct *) ); + + /* + * Use the new call to send a query directly to an IP address. + * This sends the query directly to the IP address, and ensures + * the recursion desired flag is not set (you were right Luke :-). + * This function should *only* be called from the WINS server + * code. JRA. + */ + + pull_ascii_nstring(name, question->name); + query_name_from_wins_server( *namerec->data.ip, + name, + question->name_type, + wins_register_query_success, + wins_register_query_fail, + userdata ); + return; + } + + /* + * Name did not exist - add it. + */ + + pull_ascii_nstring(name, question->name); + add_name_to_subnet( subrec, name, question->name_type, + nb_flags, ttl, REGISTER_NAME, 1, &from_ip); + + if ((namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME))) { + get_global_id_and_update(&namerec->data.id, True); + update_wins_owner(namerec, our_fake_ip); + update_wins_flag(namerec, WINS_ACTIVE); + wins_hook("add", namerec, ttl); + } + + send_wins_name_registration_response(0, ttl, p); } /*********************************************************************** @@ -1017,55 +977,54 @@ static void wins_multihomed_register_query_success(struct subnet_record *subrec, struct in_addr ip, struct res_rec *answers) { - struct packet_struct *orig_reg_packet; - struct nmb_packet *nmb; - struct name_record *namerec = NULL; - struct in_addr from_ip; - int ttl; - struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); - - memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *)); - - nmb = &orig_reg_packet->packet.nmb; - - putip((char *)&from_ip,&nmb->additional->rdata[2]); - ttl = get_ttl_from_packet(nmb); - - /* - * We want to just add the new IP, as we now know the requesting - * machine claims to own it. But we can't just do that as an arbitary - * amount of time may have taken place between the name query - * request and this response. So we check that - * the name still exists and is in the same state - if so - * we just add the extra IP and update the ttl. - */ - - namerec = find_name_on_subnet(subrec, question_name, FIND_ANY_NAME); - - if( (namerec == NULL) || (namerec->data.source != REGISTER_NAME) || !WINS_STATE_ACTIVE(namerec) ) - { - DEBUG(3,("wins_multihomed_register_query_success: name %s is not in the correct state to add \ + struct packet_struct *orig_reg_packet; + struct nmb_packet *nmb; + struct name_record *namerec = NULL; + struct in_addr from_ip; + int ttl; + struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); + + memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *)); + + nmb = &orig_reg_packet->packet.nmb; + + putip((char *)&from_ip,&nmb->additional->rdata[2]); + ttl = get_ttl_from_packet(nmb); + + /* + * We want to just add the new IP, as we now know the requesting + * machine claims to own it. But we can't just do that as an arbitary + * amount of time may have taken place between the name query + * request and this response. So we check that + * the name still exists and is in the same state - if so + * we just add the extra IP and update the ttl. + */ + + namerec = find_name_on_subnet(subrec, question_name, FIND_ANY_NAME); + + if( (namerec == NULL) || (namerec->data.source != REGISTER_NAME) || !WINS_STATE_ACTIVE(namerec) ) { + DEBUG(3,("wins_multihomed_register_query_success: name %s is not in the correct state to add \ a subsequent IP address.\n", nmb_namestr(question_name) )); - send_wins_name_registration_response(RFS_ERR, 0, orig_reg_packet); + send_wins_name_registration_response(RFS_ERR, 0, orig_reg_packet); - orig_reg_packet->locked = False; - free_packet(orig_reg_packet); + orig_reg_packet->locked = False; + free_packet(orig_reg_packet); - return; - } + return; + } - if(!find_ip_in_name_record(namerec, from_ip)) - add_ip_to_name_record(namerec, from_ip); + if(!find_ip_in_name_record(namerec, from_ip)) + add_ip_to_name_record(namerec, from_ip); - get_global_id_and_update(&namerec->data.id, True); - update_wins_owner(namerec, our_fake_ip); - update_wins_flag(namerec, WINS_ACTIVE); - update_name_ttl(namerec, ttl); - send_wins_name_registration_response(0, ttl, orig_reg_packet); - wins_hook("add", namerec, ttl); + get_global_id_and_update(&namerec->data.id, True); + update_wins_owner(namerec, our_fake_ip); + update_wins_flag(namerec, WINS_ACTIVE); + update_name_ttl(namerec, ttl); + send_wins_name_registration_response(0, ttl, orig_reg_packet); + wins_hook("add", namerec, ttl); - orig_reg_packet->locked = False; - free_packet(orig_reg_packet); + orig_reg_packet->locked = False; + free_packet(orig_reg_packet); } /*********************************************************************** @@ -1081,18 +1040,18 @@ static void wins_multihomed_register_query_fail(struct subnet_record *subrec, struct nmb_name *question_name, int rcode) { - struct userdata_struct *userdata = rrec->userdata; - struct packet_struct *orig_reg_packet; + struct userdata_struct *userdata = rrec->userdata; + struct packet_struct *orig_reg_packet; - memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *)); + memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *)); - DEBUG(3,("wins_multihomed_register_query_fail: Registering machine at IP %s failed to answer \ + DEBUG(3,("wins_multihomed_register_query_fail: Registering machine at IP %s failed to answer \ query successfully for name %s.\n", inet_ntoa(orig_reg_packet->ip), nmb_namestr(question_name) )); - send_wins_name_registration_response(RFS_ERR, 0, orig_reg_packet); + send_wins_name_registration_response(RFS_ERR, 0, orig_reg_packet); - orig_reg_packet->locked = False; - free_packet(orig_reg_packet); - return; + orig_reg_packet->locked = False; + free_packet(orig_reg_packet); + return; } /*********************************************************************** @@ -1103,250 +1062,241 @@ query successfully for name %s.\n", inet_ntoa(orig_reg_packet->ip), nmb_namestr( void wins_process_multihomed_name_registration_request( struct subnet_record *subrec, struct packet_struct *p) { - struct nmb_packet *nmb = &p->packet.nmb; - struct nmb_name *question = &nmb->question.question_name; - BOOL bcast = nmb->header.nm_flags.bcast; - uint16 nb_flags = get_nb_flags(nmb->additional->rdata); - int ttl = get_ttl_from_packet(nmb); - struct name_record *namerec = NULL; - struct in_addr from_ip; - BOOL group = (nb_flags & NB_GROUP) ? True : False; - struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); - - putip((char *)&from_ip,&nmb->additional->rdata[2]); - - if(bcast) - { - /* - * We should only get unicast name registration packets here. - * Anyone trying to register broadcast should not be going to a WINS - * server. Log an error here. - */ - - DEBUG(0,("wins_process_multihomed_name_registration_request: broadcast name registration request \ + struct nmb_packet *nmb = &p->packet.nmb; + struct nmb_name *question = &nmb->question.question_name; + BOOL bcast = nmb->header.nm_flags.bcast; + uint16 nb_flags = get_nb_flags(nmb->additional->rdata); + int ttl = get_ttl_from_packet(nmb); + struct name_record *namerec = NULL; + struct in_addr from_ip; + BOOL group = (nb_flags & NB_GROUP) ? True : False; + struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); + nstring qname; + + putip((char *)&from_ip,&nmb->additional->rdata[2]); + + if(bcast) { + /* + * We should only get unicast name registration packets here. + * Anyone trying to register broadcast should not be going to a WINS + * server. Log an error here. + */ + + DEBUG(0,("wins_process_multihomed_name_registration_request: broadcast name registration request \ received for name %s from IP %s on subnet %s. Error - should not be sent to WINS server\n", - nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); - return; - } + nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + return; + } - /* - * Only unique names should be registered multihomed. - */ + /* + * Only unique names should be registered multihomed. + */ - if(group) - { - DEBUG(0,("wins_process_multihomed_name_registration_request: group name registration request \ + if(group) { + DEBUG(0,("wins_process_multihomed_name_registration_request: group name registration request \ received for name %s from IP %s on subnet %s. Errror - group names should not be multihomed.\n", - nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); - return; - } + nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + return; + } - DEBUG(3,("wins_process_multihomed_name_registration_request: name registration for name %s \ + DEBUG(3,("wins_process_multihomed_name_registration_request: name registration for name %s \ IP %s\n", nmb_namestr(question), inet_ntoa(from_ip) )); - /* - * Deal with policy regarding 0x1d names. - */ + /* + * Deal with policy regarding 0x1d names. + */ - if(question->name_type == 0x1d) - { - DEBUG(3,("wins_process_multihomed_name_registration_request: Ignoring request \ + if(question->name_type == 0x1d) { + DEBUG(3,("wins_process_multihomed_name_registration_request: Ignoring request \ to register name %s from IP %s.", nmb_namestr(question), inet_ntoa(p->ip) )); - send_wins_name_registration_response(0, ttl, p); - return; - } - - /* - * See if the name already exists. - */ - - namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); - - /* - * if the record exists but NOT in active state, - * consider it dead. - */ - if ((namerec != NULL) && !WINS_STATE_ACTIVE(namerec)) { - DEBUG(5,("wins_process_multihomed_name_registration_request: Name (%s) in WINS was not active - removing it.\n", nmb_namestr(question))); - remove_name_from_namelist(subrec, namerec); - namerec = NULL; - } + send_wins_name_registration_response(0, ttl, p); + return; + } + + /* + * See if the name already exists. + */ + + namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); + + /* + * if the record exists but NOT in active state, + * consider it dead. + */ + + if ((namerec != NULL) && !WINS_STATE_ACTIVE(namerec)) { + DEBUG(5,("wins_process_multihomed_name_registration_request: Name (%s) in WINS was not active - removing it.\n", nmb_namestr(question))); + remove_name_from_namelist(subrec, namerec); + namerec = NULL; + } - /* - * Deal with the case where the name found was a dns entry. - * Remove it as we now have a NetBIOS client registering the - * name. - */ - - if( (namerec != NULL) - && ( (namerec->data.source == DNS_NAME) - || (namerec->data.source == DNSFAIL_NAME) ) ) - { - DEBUG(5,("wins_process_multihomed_name_registration_request: Name (%s) in WINS was a dns lookup \ + /* + * Deal with the case where the name found was a dns entry. + * Remove it as we now have a NetBIOS client registering the + * name. + */ + + if( (namerec != NULL) && ( (namerec->data.source == DNS_NAME) || (namerec->data.source == DNSFAIL_NAME) ) ) { + DEBUG(5,("wins_process_multihomed_name_registration_request: Name (%s) in WINS was a dns lookup \ - removing it.\n", nmb_namestr(question) )); - remove_name_from_namelist( subrec, namerec); - namerec = NULL; - } - - /* - * Reject if the name exists and is not a REGISTER_NAME. - * (ie. Don't allow any static names to be overwritten. - */ - - if( (namerec != NULL) && (namerec->data.source != REGISTER_NAME) ) - { - DEBUG( 3, ( "wins_process_multihomed_name_registration_request: Attempt \ + remove_name_from_namelist( subrec, namerec); + namerec = NULL; + } + + /* + * Reject if the name exists and is not a REGISTER_NAME. + * (ie. Don't allow any static names to be overwritten. + */ + + if( (namerec != NULL) && (namerec->data.source != REGISTER_NAME) ) { + DEBUG( 3, ( "wins_process_multihomed_name_registration_request: Attempt \ to register name %s. Name already exists in WINS with source type %d.\n", - nmb_namestr(question), namerec->data.source )); - send_wins_name_registration_response(RFS_ERR, 0, p); - return; - } - - /* - * Reject if the name exists and is a GROUP name and is active. - */ - - if((namerec != NULL) && NAME_GROUP(namerec) && WINS_STATE_ACTIVE(namerec)) - { - DEBUG(3,("wins_process_multihomed_name_registration_request: Attempt to register name %s. Name \ + nmb_namestr(question), namerec->data.source )); + send_wins_name_registration_response(RFS_ERR, 0, p); + return; + } + + /* + * Reject if the name exists and is a GROUP name and is active. + */ + + if((namerec != NULL) && NAME_GROUP(namerec) && WINS_STATE_ACTIVE(namerec)) { + DEBUG(3,("wins_process_multihomed_name_registration_request: Attempt to register name %s. Name \ already exists in WINS as a GROUP name.\n", nmb_namestr(question) )); - send_wins_name_registration_response(RFS_ERR, 0, p); - return; - } - - /* - * From here on down we know that if the name exists in the WINS db it is - * a unique name, not a group name. - */ - - /* - * If the name exists and is one of our names then check the - * registering IP address. If it's not one of ours then automatically - * reject without doing the query - we know we will reject it. - */ - - if((namerec != NULL) && (is_myname(namerec->name.name)) ) - { - if(!ismyip(from_ip)) - { - DEBUG(3,("wins_process_multihomed_name_registration_request: Attempt to register name %s. Name \ + send_wins_name_registration_response(RFS_ERR, 0, p); + return; + } + + /* + * From here on down we know that if the name exists in the WINS db it is + * a unique name, not a group name. + */ + + /* + * If the name exists and is one of our names then check the + * registering IP address. If it's not one of ours then automatically + * reject without doing the query - we know we will reject it. + */ + + if((namerec != NULL) && (is_myname(namerec->name.name)) ) { + if(!ismyip(from_ip)) { + DEBUG(3,("wins_process_multihomed_name_registration_request: Attempt to register name %s. Name \ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(question) )); - send_wins_name_registration_response(RFS_ERR, 0, p); - return; - } - else - { - /* - * It's one of our names and one of our IP's. Ensure the IP is in the record and - * update the ttl. Update the version ID to force replication. - */ - if(!find_ip_in_name_record(namerec, from_ip)) { - get_global_id_and_update(&namerec->data.id, True); - update_wins_owner(namerec, our_fake_ip); - update_wins_flag(namerec, WINS_ACTIVE); - - add_ip_to_name_record(namerec, from_ip); - wins_hook("add", namerec, ttl); - } else { - wins_hook("refresh", namerec, ttl); - } - - update_name_ttl(namerec, ttl); - send_wins_name_registration_response(0, ttl, p); - return; - } - } - - /* - * If the name exists and is active, check if the IP address is already registered - * to that name. If so then update the ttl and reply success. - */ - - if((namerec != NULL) && find_ip_in_name_record(namerec, from_ip) && WINS_STATE_ACTIVE(namerec)) - { - update_name_ttl(namerec, ttl); - /* - * If it's a replica, we need to become the wins owner - * to force the replication - */ - if (!ip_equal(namerec->data.wins_ip, our_fake_ip)) { - get_global_id_and_update(&namerec->data.id, True); - update_wins_owner(namerec, our_fake_ip); - update_wins_flag(namerec, WINS_ACTIVE); - } + send_wins_name_registration_response(RFS_ERR, 0, p); + return; + } else { + /* + * It's one of our names and one of our IP's. Ensure the IP is in the record and + * update the ttl. Update the version ID to force replication. + */ + if(!find_ip_in_name_record(namerec, from_ip)) { + get_global_id_and_update(&namerec->data.id, True); + update_wins_owner(namerec, our_fake_ip); + update_wins_flag(namerec, WINS_ACTIVE); + + add_ip_to_name_record(namerec, from_ip); + wins_hook("add", namerec, ttl); + } else { + wins_hook("refresh", namerec, ttl); + } + + update_name_ttl(namerec, ttl); + send_wins_name_registration_response(0, ttl, p); + return; + } + } + + /* + * If the name exists and is active, check if the IP address is already registered + * to that name. If so then update the ttl and reply success. + */ + + if((namerec != NULL) && find_ip_in_name_record(namerec, from_ip) && WINS_STATE_ACTIVE(namerec)) { + update_name_ttl(namerec, ttl); + + /* + * If it's a replica, we need to become the wins owner + * to force the replication + */ + if (!ip_equal(namerec->data.wins_ip, our_fake_ip)) { + get_global_id_and_update(&namerec->data.id, True); + update_wins_owner(namerec, our_fake_ip); + update_wins_flag(namerec, WINS_ACTIVE); + } - send_wins_name_registration_response(0, ttl, p); - wins_hook("refresh", namerec, ttl); - return; - } - - /* - * If the name exists do a query to the owner - * to see if they still want the name. - */ - - if(namerec != NULL) - { - long *ud[(sizeof(struct userdata_struct) + sizeof(struct packet_struct *))/sizeof(long *) + 1]; - struct userdata_struct *userdata = (struct userdata_struct *)ud; - - /* - * First send a WACK to the registering machine. - */ - - send_wins_wack_response(60, p); - - /* - * When the reply comes back we need the original packet. - * Lock this so it won't be freed and then put it into - * the userdata structure. - */ - - p->locked = True; - - userdata = (struct userdata_struct *)ud; - - userdata->copy_fn = NULL; - userdata->free_fn = NULL; - userdata->userdata_len = sizeof(struct packet_struct *); - memcpy(userdata->data, (char *)&p, sizeof(struct packet_struct *) ); - - /* - * Use the new call to send a query directly to an IP address. - * This sends the query directly to the IP address, and ensures - * the recursion desired flag is not set (you were right Luke :-). - * This function should *only* be called from the WINS server - * code. JRA. - * - * Note that this packet is sent to the current owner of the name, - * not the person who sent the packet - */ - - query_name_from_wins_server( namerec->data.ip[0], - question->name, - question->name_type, - wins_multihomed_register_query_success, - wins_multihomed_register_query_fail, - userdata ); - - return; - } - - /* - * Name did not exist - add it. - */ - - (void)add_name_to_subnet( subrec, question->name, question->name_type, - nb_flags, ttl, REGISTER_NAME, 1, &from_ip); - - if ((namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME))) { - get_global_id_and_update(&namerec->data.id, True); - update_wins_owner(namerec, our_fake_ip); - update_wins_flag(namerec, WINS_ACTIVE); - wins_hook("add", namerec, ttl); - } - - send_wins_name_registration_response(0, ttl, p); + send_wins_name_registration_response(0, ttl, p); + wins_hook("refresh", namerec, ttl); + return; + } + + /* + * If the name exists do a query to the owner + * to see if they still want the name. + */ + + if(namerec != NULL) { + long *ud[(sizeof(struct userdata_struct) + sizeof(struct packet_struct *))/sizeof(long *) + 1]; + struct userdata_struct *userdata = (struct userdata_struct *)ud; + + /* + * First send a WACK to the registering machine. + */ + + send_wins_wack_response(60, p); + + /* + * When the reply comes back we need the original packet. + * Lock this so it won't be freed and then put it into + * the userdata structure. + */ + + p->locked = True; + + userdata = (struct userdata_struct *)ud; + + userdata->copy_fn = NULL; + userdata->free_fn = NULL; + userdata->userdata_len = sizeof(struct packet_struct *); + memcpy(userdata->data, (char *)&p, sizeof(struct packet_struct *) ); + + /* + * Use the new call to send a query directly to an IP address. + * This sends the query directly to the IP address, and ensures + * the recursion desired flag is not set (you were right Luke :-). + * This function should *only* be called from the WINS server + * code. JRA. + * + * Note that this packet is sent to the current owner of the name, + * not the person who sent the packet + */ + + pull_ascii_nstring( qname, question->name); + query_name_from_wins_server( namerec->data.ip[0], + qname, + question->name_type, + wins_multihomed_register_query_success, + wins_multihomed_register_query_fail, + userdata ); + + return; + } + + /* + * Name did not exist - add it. + */ + + pull_ascii_nstring( qname, question->name); + add_name_to_subnet( subrec, qname, question->name_type, + nb_flags, ttl, REGISTER_NAME, 1, &from_ip); + + if ((namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME))) { + get_global_id_and_update(&namerec->data.id, True); + update_wins_owner(namerec, our_fake_ip); + update_wins_flag(namerec, WINS_ACTIVE); + wins_hook("add", namerec, ttl); + } + + send_wins_name_registration_response(0, ttl, p); } /*********************************************************************** @@ -1356,76 +1306,68 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio static void process_wins_dmb_query_request(struct subnet_record *subrec, struct packet_struct *p) { - struct name_record *namerec = NULL; - char *prdata; - int num_ips; - - /* - * Go through all the ACTIVE names in the WINS db looking for those - * ending in <1b>. Use this to calculate the number of IP - * addresses we need to return. - */ - - num_ips = 0; - for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); - namerec; - namerec = (struct name_record *)ubi_trNext( namerec ) ) - { - if(WINS_STATE_ACTIVE(namerec) && namerec->name.name_type == 0x1b ) - num_ips += namerec->data.num_ips; - } - - if(num_ips == 0) - { - /* - * There are no 0x1b names registered. Return name query fail. - */ - send_wins_name_query_response(NAM_ERR, p, NULL); - return; - } - - if((prdata = (char *)malloc( num_ips * 6 )) == NULL) - { - DEBUG(0,("process_wins_dmb_query_request: Malloc fail !.\n")); - return; - } - - /* - * Go through all the names again in the WINS db looking for those - * ending in <1b>. Add their IP addresses into the list we will - * return. - */ - - num_ips = 0; - for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); - namerec; - namerec = (struct name_record *)ubi_trNext( namerec ) ) - { - if(WINS_STATE_ACTIVE(namerec) && namerec->name.name_type == 0x1b) - { - int i; - for(i = 0; i < namerec->data.num_ips; i++) - { - set_nb_flags(&prdata[num_ips * 6],namerec->data.nb_flags); - putip((char *)&prdata[(num_ips * 6) + 2], &namerec->data.ip[i]); - num_ips++; - } - } - } - - /* - * Send back the reply containing the IP list. - */ - - reply_netbios_packet(p, /* Packet to reply to. */ - 0, /* Result code. */ - WINS_QUERY, /* nmbd type code. */ - NMB_NAME_QUERY_OPCODE, /* opcode. */ - lp_min_wins_ttl(), /* ttl. */ - prdata, /* data to send. */ - num_ips*6); /* data length. */ - - SAFE_FREE(prdata); + struct name_record *namerec = NULL; + char *prdata; + int num_ips; + + /* + * Go through all the ACTIVE names in the WINS db looking for those + * ending in <1b>. Use this to calculate the number of IP + * addresses we need to return. + */ + + num_ips = 0; + for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); + namerec; namerec = (struct name_record *)ubi_trNext( namerec ) ) { + if(WINS_STATE_ACTIVE(namerec) && namerec->name.name_type == 0x1b ) + num_ips += namerec->data.num_ips; + } + + if(num_ips == 0) { + /* + * There are no 0x1b names registered. Return name query fail. + */ + send_wins_name_query_response(NAM_ERR, p, NULL); + return; + } + + if((prdata = (char *)malloc( num_ips * 6 )) == NULL) { + DEBUG(0,("process_wins_dmb_query_request: Malloc fail !.\n")); + return; + } + + /* + * Go through all the names again in the WINS db looking for those + * ending in <1b>. Add their IP addresses into the list we will + * return. + */ + + num_ips = 0; + for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); + namerec; namerec = (struct name_record *)ubi_trNext( namerec ) ) { + if(WINS_STATE_ACTIVE(namerec) && namerec->name.name_type == 0x1b) { + int i; + for(i = 0; i < namerec->data.num_ips; i++) { + set_nb_flags(&prdata[num_ips * 6],namerec->data.nb_flags); + putip((char *)&prdata[(num_ips * 6) + 2], &namerec->data.ip[i]); + num_ips++; + } + } + } + + /* + * Send back the reply containing the IP list. + */ + + reply_netbios_packet(p, /* Packet to reply to. */ + 0, /* Result code. */ + WINS_QUERY, /* nmbd type code. */ + NMB_NAME_QUERY_OPCODE, /* opcode. */ + lp_min_wins_ttl(), /* ttl. */ + prdata, /* data to send. */ + num_ips*6); /* data length. */ + + SAFE_FREE(prdata); } /**************************************************************************** @@ -1435,55 +1377,48 @@ Send a WINS name query response. void send_wins_name_query_response(int rcode, struct packet_struct *p, struct name_record *namerec) { - char rdata[6]; - char *prdata = rdata; - int reply_data_len = 0; - int ttl = 0; - int i; - - memset(rdata,'\0',6); - - if(rcode == 0) - { - ttl = (namerec->data.death_time != PERMANENT_TTL) ? - namerec->data.death_time - p->timestamp : lp_max_wins_ttl(); - - /* Copy all known ip addresses into the return data. */ - /* Optimise for the common case of one IP address so - we don't need a malloc. */ - - if( namerec->data.num_ips == 1 ) - prdata = rdata; - else - { - if((prdata = (char *)malloc( namerec->data.num_ips * 6 )) == NULL) - { - DEBUG(0,("send_wins_name_query_response: malloc fail !\n")); - return; - } - } - - for(i = 0; i < namerec->data.num_ips; i++) - { - set_nb_flags(&prdata[i*6],namerec->data.nb_flags); - putip((char *)&prdata[2+(i*6)], &namerec->data.ip[i]); - } - - sort_query_replies(prdata, i, p->ip); - - reply_data_len = namerec->data.num_ips * 6; - } - - reply_netbios_packet(p, /* Packet to reply to. */ - rcode, /* Result code. */ - WINS_QUERY, /* nmbd type code. */ - NMB_NAME_QUERY_OPCODE, /* opcode. */ - ttl, /* ttl. */ - prdata, /* data to send. */ - reply_data_len); /* data length. */ - - if(prdata != rdata) - SAFE_FREE(prdata); + char rdata[6]; + char *prdata = rdata; + int reply_data_len = 0; + int ttl = 0; + int i; + + memset(rdata,'\0',6); + + if(rcode == 0) { + ttl = (namerec->data.death_time != PERMANENT_TTL) ? namerec->data.death_time - p->timestamp : lp_max_wins_ttl(); + + /* Copy all known ip addresses into the return data. */ + /* Optimise for the common case of one IP address so we don't need a malloc. */ + + if( namerec->data.num_ips == 1 ) { + prdata = rdata; + } else { + if((prdata = (char *)malloc( namerec->data.num_ips * 6 )) == NULL) { + DEBUG(0,("send_wins_name_query_response: malloc fail !\n")); + return; + } + } + + for(i = 0; i < namerec->data.num_ips; i++) { + set_nb_flags(&prdata[i*6],namerec->data.nb_flags); + putip((char *)&prdata[2+(i*6)], &namerec->data.ip[i]); + } + + sort_query_replies(prdata, i, p->ip); + reply_data_len = namerec->data.num_ips * 6; + } + + reply_netbios_packet(p, /* Packet to reply to. */ + rcode, /* Result code. */ + WINS_QUERY, /* nmbd type code. */ + NMB_NAME_QUERY_OPCODE, /* opcode. */ + ttl, /* ttl. */ + prdata, /* data to send. */ + reply_data_len); /* data length. */ + + if(prdata != rdata) + SAFE_FREE(prdata); } /*********************************************************************** @@ -1493,93 +1428,87 @@ void send_wins_name_query_response(int rcode, struct packet_struct *p, void wins_process_name_query_request(struct subnet_record *subrec, struct packet_struct *p) { - struct nmb_packet *nmb = &p->packet.nmb; - struct nmb_name *question = &nmb->question.question_name; - struct name_record *namerec = NULL; - - DEBUG(3,("wins_process_name_query: name query for name %s from IP %s\n", - nmb_namestr(question), inet_ntoa(p->ip) )); - - /* - * Special name code. If the queried name is *<1b> then search - * the entire WINS database and return a list of all the IP addresses - * registered to any <1b> name. This is to allow domain master browsers - * to discover other domains that may not have a presence on their subnet. - */ - - if(strequal( question->name, "*") && (question->name_type == 0x1b)) - { - process_wins_dmb_query_request( subrec, p); - return; - } - - namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); - - if(namerec != NULL) - { - /* - * If the name is not anymore in active state then reply not found. - * it's fair even if we keep it in the cache for days. - */ - if (!WINS_STATE_ACTIVE(namerec)) - { - DEBUG(3,("wins_process_name_query: name query for name %s - name expired. Returning fail.\n", - nmb_namestr(question) )); - send_wins_name_query_response(NAM_ERR, p, namerec); - return; - } - /* - * If it's a DNSFAIL_NAME then reply name not found. - */ - - if( namerec->data.source == DNSFAIL_NAME ) - { - DEBUG(3,("wins_process_name_query: name query for name %s returning DNS fail.\n", - nmb_namestr(question) )); - send_wins_name_query_response(NAM_ERR, p, namerec); - return; - } - - /* - * If the name has expired then reply name not found. - */ - - if( (namerec->data.death_time != PERMANENT_TTL) - && (namerec->data.death_time < p->timestamp) ) - { - DEBUG(3,("wins_process_name_query: name query for name %s - name expired. Returning fail.\n", - nmb_namestr(question) )); - send_wins_name_query_response(NAM_ERR, p, namerec); - return; - } - - DEBUG(3,("wins_process_name_query: name query for name %s returning first IP %s.\n", - nmb_namestr(question), inet_ntoa(namerec->data.ip[0]) )); - - send_wins_name_query_response(0, p, namerec); - return; - } - - /* - * Name not found in WINS - try a dns query if it's a 0x20 name. - */ - - if(lp_dns_proxy() && - ((question->name_type == 0x20) || question->name_type == 0)) - { - - DEBUG(3,("wins_process_name_query: name query for name %s not found - doing dns lookup.\n", - nmb_namestr(question) )); - - queue_dns_query(p, question, &namerec); - return; - } - - /* - * Name not found - return error. - */ - - send_wins_name_query_response(NAM_ERR, p, NULL); + struct nmb_packet *nmb = &p->packet.nmb; + struct nmb_name *question = &nmb->question.question_name; + struct name_record *namerec = NULL; + nstring qname; + + DEBUG(3,("wins_process_name_query: name query for name %s from IP %s\n", + nmb_namestr(question), inet_ntoa(p->ip) )); + + /* + * Special name code. If the queried name is *<1b> then search + * the entire WINS database and return a list of all the IP addresses + * registered to any <1b> name. This is to allow domain master browsers + * to discover other domains that may not have a presence on their subnet. + */ + + pull_ascii_nstring(qname, question->name); + if(strequal( qname, "*") && (question->name_type == 0x1b)) { + process_wins_dmb_query_request( subrec, p); + return; + } + + namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); + + if(namerec != NULL) { + /* + * If the name is not anymore in active state then reply not found. + * it's fair even if we keep it in the cache for days. + */ + if (!WINS_STATE_ACTIVE(namerec)) { + DEBUG(3,("wins_process_name_query: name query for name %s - name expired. Returning fail.\n", + nmb_namestr(question) )); + send_wins_name_query_response(NAM_ERR, p, namerec); + return; + } + + /* + * If it's a DNSFAIL_NAME then reply name not found. + */ + + if( namerec->data.source == DNSFAIL_NAME ) { + DEBUG(3,("wins_process_name_query: name query for name %s returning DNS fail.\n", + nmb_namestr(question) )); + send_wins_name_query_response(NAM_ERR, p, namerec); + return; + } + + /* + * If the name has expired then reply name not found. + */ + + if( (namerec->data.death_time != PERMANENT_TTL) && (namerec->data.death_time < p->timestamp) ) { + DEBUG(3,("wins_process_name_query: name query for name %s - name expired. Returning fail.\n", + nmb_namestr(question) )); + send_wins_name_query_response(NAM_ERR, p, namerec); + return; + } + + DEBUG(3,("wins_process_name_query: name query for name %s returning first IP %s.\n", + nmb_namestr(question), inet_ntoa(namerec->data.ip[0]) )); + + send_wins_name_query_response(0, p, namerec); + return; + } + + /* + * Name not found in WINS - try a dns query if it's a 0x20 name. + */ + + if(lp_dns_proxy() && ((question->name_type == 0x20) || question->name_type == 0)) { + DEBUG(3,("wins_process_name_query: name query for name %s not found - doing dns lookup.\n", + nmb_namestr(question) )); + + queue_dns_query(p, question, &namerec); + return; + } + + /* + * Name not found - return error. + */ + + send_wins_name_query_response(NAM_ERR, p, NULL); } /**************************************************************************** @@ -1588,18 +1517,18 @@ Send a WINS name release response. static void send_wins_name_release_response(int rcode, struct packet_struct *p) { - struct nmb_packet *nmb = &p->packet.nmb; - char rdata[6]; - - memcpy(&rdata[0], &nmb->additional->rdata[0], 6); - - reply_netbios_packet(p, /* Packet to reply to. */ - rcode, /* Result code. */ - NMB_REL, /* nmbd type code. */ - NMB_NAME_RELEASE_OPCODE, /* opcode. */ - 0, /* ttl. */ - rdata, /* data to send. */ - 6); /* data length. */ + struct nmb_packet *nmb = &p->packet.nmb; + char rdata[6]; + + memcpy(&rdata[0], &nmb->additional->rdata[0], 6); + + reply_netbios_packet(p, /* Packet to reply to. */ + rcode, /* Result code. */ + NMB_REL, /* nmbd type code. */ + NMB_NAME_RELEASE_OPCODE, /* opcode. */ + 0, /* ttl. */ + rdata, /* data to send. */ + 6); /* data length. */ } /*********************************************************************** @@ -1609,123 +1538,115 @@ static void send_wins_name_release_response(int rcode, struct packet_struct *p) void wins_process_name_release_request(struct subnet_record *subrec, struct packet_struct *p) { - struct nmb_packet *nmb = &p->packet.nmb; - struct nmb_name *question = &nmb->question.question_name; - BOOL bcast = nmb->header.nm_flags.bcast; - uint16 nb_flags = get_nb_flags(nmb->additional->rdata); - struct name_record *namerec = NULL; - struct in_addr from_ip; - BOOL releasing_group_name = (nb_flags & NB_GROUP) ? True : False;; - - putip((char *)&from_ip,&nmb->additional->rdata[2]); - - if(bcast) - { - /* - * We should only get unicast name registration packets here. - * Anyone trying to register broadcast should not be going to a WINS - * server. Log an error here. - */ - - DEBUG(0,("wins_process_name_release_request: broadcast name registration request \ + struct nmb_packet *nmb = &p->packet.nmb; + struct nmb_name *question = &nmb->question.question_name; + BOOL bcast = nmb->header.nm_flags.bcast; + uint16 nb_flags = get_nb_flags(nmb->additional->rdata); + struct name_record *namerec = NULL; + struct in_addr from_ip; + BOOL releasing_group_name = (nb_flags & NB_GROUP) ? True : False;; + + putip((char *)&from_ip,&nmb->additional->rdata[2]); + + if(bcast) { + /* + * We should only get unicast name registration packets here. + * Anyone trying to register broadcast should not be going to a WINS + * server. Log an error here. + */ + + DEBUG(0,("wins_process_name_release_request: broadcast name registration request \ received for name %s from IP %s on subnet %s. Error - should not be sent to WINS server\n", - nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); - return; - } + nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + return; + } - DEBUG(3,("wins_process_name_release_request: %s name release for name %s \ + DEBUG(3,("wins_process_name_release_request: %s name release for name %s \ IP %s\n", releasing_group_name ? "Group" : "Unique", nmb_namestr(question), inet_ntoa(from_ip) )); - /* - * Deal with policy regarding 0x1d names. - */ + /* + * Deal with policy regarding 0x1d names. + */ - if(!releasing_group_name && (question->name_type == 0x1d)) - { - DEBUG(3,("wins_process_name_release_request: Ignoring request \ + if(!releasing_group_name && (question->name_type == 0x1d)) { + DEBUG(3,("wins_process_name_release_request: Ignoring request \ to release name %s from IP %s.", nmb_namestr(question), inet_ntoa(p->ip) )); - send_wins_name_release_response(0, p); - return; - } + send_wins_name_release_response(0, p); + return; + } - /* - * See if the name already exists. - */ + /* + * See if the name already exists. + */ - namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); - - if( (namerec == NULL) - || ((namerec != NULL) && (namerec->data.source != REGISTER_NAME)) ) - { - send_wins_name_release_response(NAM_ERR, p); - return; - } - - /* - * Check that the sending machine has permission to release this name. - * If it's a group name not ending in 0x1c then just say yes and let - * the group time out. - */ - - if(releasing_group_name && (question->name_type != 0x1c)) - { - send_wins_name_release_response(0, p); - return; - } - - /* - * Check that the releasing node is on the list of IP addresses - * for this name. Disallow the release if not. - */ - - if(!find_ip_in_name_record(namerec, from_ip)) - { - DEBUG(3,("wins_process_name_release_request: Refusing request to \ + namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); + + if( (namerec == NULL) || ((namerec != NULL) && (namerec->data.source != REGISTER_NAME)) ) { + send_wins_name_release_response(NAM_ERR, p); + return; + } + + /* + * Check that the sending machine has permission to release this name. + * If it's a group name not ending in 0x1c then just say yes and let + * the group time out. + */ + + if(releasing_group_name && (question->name_type != 0x1c)) { + send_wins_name_release_response(0, p); + return; + } + + /* + * Check that the releasing node is on the list of IP addresses + * for this name. Disallow the release if not. + */ + + if(!find_ip_in_name_record(namerec, from_ip)) { + DEBUG(3,("wins_process_name_release_request: Refusing request to \ release name %s as IP %s is not one of the known IP's for this name.\n", - nmb_namestr(question), inet_ntoa(from_ip) )); - send_wins_name_release_response(NAM_ERR, p); - return; - } - - /* - * Check if the record is active. IF it's already released - * or tombstoned, refuse the release. - */ - if (!WINS_STATE_ACTIVE(namerec)) { - DEBUG(3,("wins_process_name_release_request: Refusing request to \ -release name %s as this record is not anymore active.\n", - nmb_namestr(question) )); - send_wins_name_release_response(NAM_ERR, p); - return; - } - - /* - * Check if the record is a 0x1c group - * and has more then one ip - * remove only this address. - */ - - if(releasing_group_name && - (question->name_type == 0x1c) && - (namerec->data.num_ips > 1)) { - remove_ip_from_name_record(namerec, from_ip); - DEBUG(3,("wins_process_name_release_request: Remove IP %s from NAME: %s\n", - inet_ntoa(from_ip),nmb_namestr(question))); - send_wins_name_release_response(0, p); - return; - } + nmb_namestr(question), inet_ntoa(from_ip) )); + send_wins_name_release_response(NAM_ERR, p); + return; + } + + /* + * Check if the record is active. IF it's already released + * or tombstoned, refuse the release. + */ + + if (!WINS_STATE_ACTIVE(namerec)) { + DEBUG(3,("wins_process_name_release_request: Refusing request to \ +release name %s as this record is not active anymore.\n", nmb_namestr(question) )); + send_wins_name_release_response(NAM_ERR, p); + return; + } + + /* + * Check if the record is a 0x1c group + * and has more then one ip + * remove only this address. + */ + + if(releasing_group_name && (question->name_type == 0x1c) && (namerec->data.num_ips > 1)) { + remove_ip_from_name_record(namerec, from_ip); + DEBUG(3,("wins_process_name_release_request: Remove IP %s from NAME: %s\n", + inet_ntoa(from_ip),nmb_namestr(question))); + send_wins_name_release_response(0, p); + return; + } - /* - * Send a release response. - * Flag the name as released and update the ttl - */ + /* + * Send a release response. + * Flag the name as released and update the ttl + */ - send_wins_name_release_response(0, p); + send_wins_name_release_response(0, p); - namerec->data.wins_flags |= WINS_RELEASED; - update_name_ttl(namerec, EXTINCTION_INTERVAL); + namerec->data.wins_flags |= WINS_RELEASED; + update_name_ttl(namerec, EXTINCTION_INTERVAL); - wins_hook("delete", namerec, 0); + wins_hook("delete", namerec, 0); } /******************************************************************* @@ -1817,94 +1738,89 @@ we are not the wins owner !\n", nmb_namestr(&namerec->name))); /******************************************************************* Write out the current WINS database. ******************************************************************/ + void wins_write_database(BOOL background) { - struct name_record *namerec; - pstring fname, fnamenew; + struct name_record *namerec; + pstring fname, fnamenew; - XFILE *fp; + XFILE *fp; - if(!lp_we_are_a_wins_server()) - return; - - /* we will do the writing in a child process to ensure that the parent - doesn't block while this is done */ - if (background) { - CatchChild(); - if (sys_fork()) { - return; - } - } - - slprintf(fname,sizeof(fname)-1,"%s/%s", lp_lockdir(), WINS_LIST); - all_string_sub(fname,"//", "/", 0); - slprintf(fnamenew,sizeof(fnamenew)-1,"%s.%u", fname, (unsigned int)sys_getpid()); - - if((fp = x_fopen(fnamenew,O_WRONLY|O_CREAT,0644)) == NULL) - { - DEBUG(0,("wins_write_database: Can't open %s. Error was %s\n", fnamenew, strerror(errno))); - if (background) { - _exit(0); - } - return; - } - - DEBUG(4,("wins_write_database: Dump of WINS name list.\n")); - - x_fprintf(fp,"VERSION %d %u\n", WINS_VERSION, 0); + if(!lp_we_are_a_wins_server()) + return; + + /* We will do the writing in a child process to ensure that the parent doesn't block while this is done */ + if (background) { + CatchChild(); + if (sys_fork()) { + return; + } + } + + slprintf(fname,sizeof(fname)-1,"%s/%s", lp_lockdir(), WINS_LIST); + all_string_sub(fname,"//", "/", 0); + slprintf(fnamenew,sizeof(fnamenew)-1,"%s.%u", fname, (unsigned int)sys_getpid()); + + if((fp = x_fopen(fnamenew,O_WRONLY|O_CREAT,0644)) == NULL) { + DEBUG(0,("wins_write_database: Can't open %s. Error was %s\n", fnamenew, strerror(errno))); + if (background) { + _exit(0); + } + return; + } + + DEBUG(4,("wins_write_database: Dump of WINS name list.\n")); + + x_fprintf(fp,"VERSION %d %u\n", WINS_VERSION, 0); - for( namerec - = (struct name_record *)ubi_trFirst( wins_server_subnet->namelist ); - namerec; - namerec = (struct name_record *)ubi_trNext( namerec ) ) - { - int i; - struct tm *tm; - - DEBUGADD(4,("%-19s ", nmb_namestr(&namerec->name) )); - - if( namerec->data.death_time != PERMANENT_TTL ) - { - char *ts, *nl; - - tm = LocalTime(&namerec->data.death_time); - ts = asctime(tm); - nl = strrchr( ts, '\n' ); - if( NULL != nl ) - *nl = '\0'; - DEBUGADD(4,("TTL = %s ", ts )); - } - else - DEBUGADD(4,("TTL = PERMANENT ")); - - for (i = 0; i < namerec->data.num_ips; i++) - DEBUGADD(4,("%15s ", inet_ntoa(namerec->data.ip[i]) )); - DEBUGADD(4,("%2x\n", namerec->data.nb_flags )); - - if( namerec->data.source == REGISTER_NAME ) - { - x_fprintf(fp, "\"%s#%02x\" %d ", - namerec->name.name,namerec->name.name_type, /* Ignore scope. */ - (int)namerec->data.death_time); - - for (i = 0; i < namerec->data.num_ips; i++) - x_fprintf( fp, "%s ", inet_ntoa( namerec->data.ip[i] ) ); - x_fprintf( fp, "%2xR\n", namerec->data.nb_flags ); - } - } + for( namerec = (struct name_record *)ubi_trFirst( wins_server_subnet->namelist ); namerec; namerec = (struct name_record *)ubi_trNext( namerec ) ) { + int i; + struct tm *tm; + + DEBUGADD(4,("%-19s ", nmb_namestr(&namerec->name) )); + + if( namerec->data.death_time != PERMANENT_TTL ) { + char *ts, *nl; + + tm = LocalTime(&namerec->data.death_time); + ts = asctime(tm); + nl = strrchr( ts, '\n' ); + if( NULL != nl ) + *nl = '\0'; + DEBUGADD(4,("TTL = %s ", ts )); + } else { + DEBUGADD(4,("TTL = PERMANENT ")); + } + + for (i = 0; i < namerec->data.num_ips; i++) + DEBUGADD(4,("%15s ", inet_ntoa(namerec->data.ip[i]) )); + DEBUGADD(4,("%2x\n", namerec->data.nb_flags )); + + if( namerec->data.source == REGISTER_NAME ) { + nstring name; + pull_ascii_nstring(name, namerec->name.name); + x_fprintf(fp, "\"%s#%02x\" %d ", name,namerec->name.name_type, /* Ignore scope. */ + (int)namerec->data.death_time); + + for (i = 0; i < namerec->data.num_ips; i++) + x_fprintf( fp, "%s ", inet_ntoa( namerec->data.ip[i] ) ); + x_fprintf( fp, "%2xR\n", namerec->data.nb_flags ); + } + } - x_fclose(fp); - chmod(fnamenew,0644); - unlink(fname); - rename(fnamenew,fname); - if (background) { - _exit(0); - } + x_fclose(fp); + chmod(fnamenew,0644); + unlink(fname); + rename(fnamenew,fname); + if (background) { + _exit(0); + } } /**************************************************************************** -process a internal Samba message receiving a wins record + Process a internal Samba message receiving a wins record. ***************************************************************************/ + void nmbd_wins_new_entry(int msg_type, pid_t src, void *buf, size_t len) { WINS_RECORD *record; @@ -1918,11 +1834,10 @@ void nmbd_wins_new_entry(int msg_type, pid_t src, void *buf, size_t len) if (buf==NULL) return; + /* Record should use UNIX codepage. Ensure this is so in the wrepld code. JRA. */ record=(WINS_RECORD *)buf; - ZERO_STRUCT(question); - memcpy(question.name, record->name, 16); - question.name_type=record->type; + make_nmb_name(&question, record->name, record->type); namerec = find_name_on_subnet(wins_server_subnet, &question, FIND_ANY_NAME); @@ -1994,9 +1909,9 @@ void nmbd_wins_new_entry(int msg_type, pid_t src, void *buf, size_t len) for (i=0; inum_ips; i++) if(!find_ip_in_name_record(namerec, record->ip[i])) add_ip_to_name_record(namerec, record->ip[i]); - } - else + } else { overwrite=True; + } } /* the replica is a multihomed host */ diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 2357fd637b..08d6fb2c62 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -31,7 +31,7 @@ int workgroup_count = 0; /* unique index key: one for each workgroup */ /**************************************************************************** Add a workgroup into the list. - **************************************************************************/ +**************************************************************************/ static void add_workgroup(struct subnet_record *subrec, struct work_record *work) { @@ -42,164 +42,153 @@ static void add_workgroup(struct subnet_record *subrec, struct work_record *work /**************************************************************************** Create an empty workgroup. - **************************************************************************/ +**************************************************************************/ static struct work_record *create_workgroup(const char *name, int ttl) { - struct work_record *work; - struct subnet_record *subrec; - int t = -1; + struct work_record *work; + struct subnet_record *subrec; + int t = -1; - if((work = (struct work_record *)malloc(sizeof(*work))) == NULL) - { - DEBUG(0,("create_workgroup: malloc fail !\n")); - return NULL; - } - memset((char *)work, '\0', sizeof(*work)); + if((work = (struct work_record *)malloc(sizeof(*work))) == NULL) { + DEBUG(0,("create_workgroup: malloc fail !\n")); + return NULL; + } + memset((char *)work, '\0', sizeof(*work)); - fstrcpy(work->work_group,name); - work->serverlist = NULL; + fstrcpy(work->work_group,name); + work->serverlist = NULL; - work->RunningElection = False; - work->ElectionCount = 0; - work->announce_interval = 0; - work->needelection = False; - work->needannounce = True; - work->lastannounce_time = time(NULL); - work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; - work->dom_state = DOMAIN_NONE; - work->log_state = LOGON_NONE; + work->RunningElection = False; + work->ElectionCount = 0; + work->announce_interval = 0; + work->needelection = False; + work->needannounce = True; + work->lastannounce_time = time(NULL); + work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; + work->dom_state = DOMAIN_NONE; + work->log_state = LOGON_NONE; - work->death_time = (ttl != PERMANENT_TTL) ? time(NULL)+(ttl*3) : PERMANENT_TTL; + work->death_time = (ttl != PERMANENT_TTL) ? time(NULL)+(ttl*3) : PERMANENT_TTL; - /* Make sure all token representations of workgroups are unique. */ + /* Make sure all token representations of workgroups are unique. */ - for (subrec = FIRST_SUBNET; subrec && (t == -1); - subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) - { - struct work_record *w; - for (w = subrec->workgrouplist; w && t == -1; w = w->next) - { - if (strequal(w->work_group, work->work_group)) - t = w->token; - } - } + for (subrec = FIRST_SUBNET; subrec && (t == -1); subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { + struct work_record *w; + for (w = subrec->workgrouplist; w && t == -1; w = w->next) { + if (strequal(w->work_group, work->work_group)) + t = w->token; + } + } - if (t == -1) - work->token = ++workgroup_count; - else - work->token = t; + if (t == -1) + work->token = ++workgroup_count; + else + work->token = t; - /* No known local master browser as yet. */ - *work->local_master_browser_name = '\0'; - - /* No known domain master browser as yet. */ - *work->dmb_name.name = '\0'; - zero_ip(&work->dmb_addr); - - /* WfWg uses 01040b01 */ - /* Win95 uses 01041501 */ - /* NTAS uses ???????? */ - work->ElectionCriterion = (MAINTAIN_LIST)|(BROWSER_ELECTION_VERSION<<8); - work->ElectionCriterion |= (lp_os_level() << 24); - if (lp_domain_master()) - work->ElectionCriterion |= 0x80; + /* No known local master browser as yet. */ + *work->local_master_browser_name = '\0'; + + /* No known domain master browser as yet. */ + *work->dmb_name.name = '\0'; + zero_ip(&work->dmb_addr); + + /* WfWg uses 01040b01 */ + /* Win95 uses 01041501 */ + /* NTAS uses ???????? */ + work->ElectionCriterion = (MAINTAIN_LIST)|(BROWSER_ELECTION_VERSION<<8); + work->ElectionCriterion |= (lp_os_level() << 24); + if (lp_domain_master()) + work->ElectionCriterion |= 0x80; - return work; + return work; } /******************************************************************* Remove a workgroup. - ******************************************************************/ +******************************************************************/ static struct work_record *remove_workgroup_from_subnet(struct subnet_record *subrec, struct work_record *work) { - struct work_record *ret_work = NULL; + struct work_record *ret_work = NULL; - DEBUG(3,("remove_workgroup: Removing workgroup %s\n", work->work_group)); + DEBUG(3,("remove_workgroup: Removing workgroup %s\n", work->work_group)); - ret_work = work->next; + ret_work = work->next; - remove_all_servers(work); + remove_all_servers(work); - if (!work->serverlist) - { - if (work->prev) - work->prev->next = work->next; - if (work->next) - work->next->prev = work->prev; + if (!work->serverlist) { + if (work->prev) + work->prev->next = work->next; + if (work->next) + work->next->prev = work->prev; - if (subrec->workgrouplist == work) - subrec->workgrouplist = work->next; + if (subrec->workgrouplist == work) + subrec->workgrouplist = work->next; - ZERO_STRUCTP(work); - SAFE_FREE(work); - } + ZERO_STRUCTP(work); + SAFE_FREE(work); + } - subrec->work_changed = True; + subrec->work_changed = True; - return ret_work; + return ret_work; } - /**************************************************************************** Find a workgroup in the workgroup list of a subnet. - **************************************************************************/ +**************************************************************************/ struct work_record *find_workgroup_on_subnet(struct subnet_record *subrec, const char *name) { - struct work_record *ret; + struct work_record *ret; - DEBUG(4, ("find_workgroup_on_subnet: workgroup search for %s on subnet %s: ", - name, subrec->subnet_name)); + DEBUG(4, ("find_workgroup_on_subnet: workgroup search for %s on subnet %s: ", + name, subrec->subnet_name)); - for (ret = subrec->workgrouplist; ret; ret = ret->next) - { - if (!strcmp(ret->work_group,name)) - { - DEBUGADD(4, ("found.\n")); - return(ret); - } - } - DEBUGADD(4, ("not found.\n")); - return NULL; + for (ret = subrec->workgrouplist; ret; ret = ret->next) { + if (strequal(ret->work_group,name)) { + DEBUGADD(4, ("found.\n")); + return(ret); + } + } + DEBUGADD(4, ("not found.\n")); + return NULL; } /**************************************************************************** Create a workgroup in the workgroup list of the subnet. - **************************************************************************/ +**************************************************************************/ struct work_record *create_workgroup_on_subnet(struct subnet_record *subrec, const char *name, int ttl) { - struct work_record *work = NULL; + struct work_record *work = NULL; - DEBUG(4,("create_workgroup_on_subnet: creating group %s on subnet %s\n", - name, subrec->subnet_name)); + DEBUG(4,("create_workgroup_on_subnet: creating group %s on subnet %s\n", + name, subrec->subnet_name)); - if ((work = create_workgroup(name, ttl))) - { - add_workgroup(subrec, work); - - subrec->work_changed = True; + if ((work = create_workgroup(name, ttl))) { + add_workgroup(subrec, work); + subrec->work_changed = True; + return(work); + } - return(work); - } - - return NULL; + return NULL; } /**************************************************************************** Update a workgroup ttl. - **************************************************************************/ +**************************************************************************/ void update_workgroup_ttl(struct work_record *work, int ttl) { - if(work->death_time != PERMANENT_TTL) - work->death_time = time(NULL)+(ttl*3); - work->subnet->work_changed = True; + if(work->death_time != PERMANENT_TTL) + work->death_time = time(NULL)+(ttl*3); + work->subnet->work_changed = True; } /**************************************************************************** @@ -210,8 +199,8 @@ void update_workgroup_ttl(struct work_record *work, int ttl) static void fail_register(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *nmbname) { - DEBUG(0,("fail_register: Failed to register name %s on subnet %s.\n", - nmb_namestr(nmbname), subrec->subnet_name)); + DEBUG(0,("fail_register: Failed to register name %s on subnet %s.\n", + nmb_namestr(nmbname), subrec->subnet_name)); } /**************************************************************************** @@ -220,50 +209,38 @@ static void fail_register(struct subnet_record *subrec, struct response_record * void initiate_myworkgroup_startup(struct subnet_record *subrec, struct work_record *work) { - int i; + int i; - if(!strequal(lp_workgroup(), work->work_group)) - return; + if(!strequal(lp_workgroup(), work->work_group)) + return; - /* If this is a broadcast subnet then start elections on it - if we are so configured. */ + /* If this is a broadcast subnet then start elections on it if we are so configured. */ - if ((subrec != unicast_subnet) && (subrec != remote_broadcast_subnet) && - (subrec != wins_server_subnet) && lp_preferred_master() && - lp_local_master()) - { - DEBUG(3, ("initiate_myworkgroup_startup: preferred master startup for \ + if ((subrec != unicast_subnet) && (subrec != remote_broadcast_subnet) && + (subrec != wins_server_subnet) && lp_preferred_master() && lp_local_master()) { + DEBUG(3, ("initiate_myworkgroup_startup: preferred master startup for \ workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name)); - work->needelection = True; - work->ElectionCriterion |= (1<<3); - } + work->needelection = True; + work->ElectionCriterion |= (1<<3); + } - /* Register the WORKGROUP<0> and WORKGROUP<1e> names on the network. */ + /* Register the WORKGROUP<0> and WORKGROUP<1e> names on the network. */ - register_name(subrec,lp_workgroup(),0x0,samba_nb_type|NB_GROUP, - NULL, - fail_register,NULL); - - register_name(subrec,lp_workgroup(),0x1e,samba_nb_type|NB_GROUP, - NULL, - fail_register,NULL); - - for( i = 0; my_netbios_names(i); i++) - { - const char *name = my_netbios_names(i); - int stype = lp_default_server_announce() | (lp_local_master() ? - SV_TYPE_POTENTIAL_BROWSER : 0 ); + register_name(subrec,lp_workgroup(),0x0,samba_nb_type|NB_GROUP, NULL, fail_register,NULL); + register_name(subrec,lp_workgroup(),0x1e,samba_nb_type|NB_GROUP, NULL, fail_register,NULL); + + for( i = 0; my_netbios_names(i); i++) { + const char *name = my_netbios_names(i); + int stype = lp_default_server_announce() | (lp_local_master() ? SV_TYPE_POTENTIAL_BROWSER : 0 ); - if(!strequal(global_myname(), name)) - stype &= ~(SV_TYPE_MASTER_BROWSER|SV_TYPE_POTENTIAL_BROWSER| - SV_TYPE_DOMAIN_MASTER|SV_TYPE_DOMAIN_MEMBER); + if(!strequal(global_myname(), name)) + stype &= ~(SV_TYPE_MASTER_BROWSER|SV_TYPE_POTENTIAL_BROWSER|SV_TYPE_DOMAIN_MASTER|SV_TYPE_DOMAIN_MEMBER); - create_server_on_workgroup(work,name,stype|SV_TYPE_LOCAL_LIST_ONLY, - PERMANENT_TTL, - string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH)); - DEBUG(3,("initiate_myworkgroup_startup: Added server name entry %s \ + create_server_on_workgroup(work,name,stype|SV_TYPE_LOCAL_LIST_ONLY, PERMANENT_TTL, + string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH)); + DEBUG(3,("initiate_myworkgroup_startup: Added server name entry %s \ on subnet %s\n", name, subrec->subnet_name)); - } + } } /**************************************************************************** @@ -272,43 +249,34 @@ on subnet %s\n", name, subrec->subnet_name)); void dump_workgroups(BOOL force_write) { - struct subnet_record *subrec; - int debuglevel = force_write ? 0 : 4; + struct subnet_record *subrec; + int debuglevel = force_write ? 0 : 4; - for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) - { - if (subrec->workgrouplist) - { - struct work_record *work; - - if( DEBUGLVL( debuglevel ) ) - { - dbgtext( "dump_workgroups()\n " ); - dbgtext( "dump workgroup on subnet %15s: ", subrec->subnet_name ); - dbgtext( "netmask=%15s:\n", inet_ntoa(subrec->mask_ip) ); - } - - for (work = subrec->workgrouplist; work; work = work->next) - { - DEBUGADD( debuglevel, ( "\t%s(%d) current master browser = %s\n", - work->work_group, - work->token, - *work->local_master_browser_name - ? work->local_master_browser_name : "UNKNOWN" ) ); - if (work->serverlist) - { - struct server_record *servrec; - for (servrec = work->serverlist; servrec; servrec = servrec->next) - { - DEBUGADD( debuglevel, ( "\t\t%s %8x (%s)\n", - servrec->serv.name, - servrec->serv.type, - servrec->serv.comment ) ); - } - } - } - } - } + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { + if (subrec->workgrouplist) { + struct work_record *work; + + if( DEBUGLVL( debuglevel ) ) { + dbgtext( "dump_workgroups()\n " ); + dbgtext( "dump workgroup on subnet %15s: ", subrec->subnet_name ); + dbgtext( "netmask=%15s:\n", inet_ntoa(subrec->mask_ip) ); + } + + for (work = subrec->workgrouplist; work; work = work->next) { + DEBUGADD( debuglevel, ( "\t%s(%d) current master browser = %s\n", work->work_group, + work->token, *work->local_master_browser_name ? work->local_master_browser_name : "UNKNOWN" ) ); + if (work->serverlist) { + struct server_record *servrec; + for (servrec = work->serverlist; servrec; servrec = servrec->next) { + DEBUGADD( debuglevel, ( "\t\t%s %8x (%s)\n", + servrec->serv.name, + servrec->serv.type, + servrec->serv.comment ) ); + } + } + } + } + } } /**************************************************************************** @@ -318,25 +286,22 @@ void dump_workgroups(BOOL force_write) void expire_workgroups_and_servers(time_t t) { - struct subnet_record *subrec; + struct subnet_record *subrec; - for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) - { - struct work_record *work; - struct work_record *nextwork; - - for (work = subrec->workgrouplist; work; work = nextwork) - { - nextwork = work->next; - expire_servers(work, t); - - if ((work->serverlist == NULL) && (work->death_time != PERMANENT_TTL) && - ((t == -1) || (work->death_time < t))) - { - DEBUG(3,("expire_workgroups_and_servers: Removing timed out workgroup %s\n", - work->work_group)); - remove_workgroup_from_subnet(subrec, work); - } - } - } + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { + struct work_record *work; + struct work_record *nextwork; + + for (work = subrec->workgrouplist; work; work = nextwork) { + nextwork = work->next; + expire_servers(work, t); + + if ((work->serverlist == NULL) && (work->death_time != PERMANENT_TTL) && + ((t == -1) || (work->death_time < t))) { + DEBUG(3,("expire_workgroups_and_servers: Removing timed out workgroup %s\n", + work->work_group)); + remove_workgroup_from_subnet(subrec, work); + } + } + } } -- cgit From 4561b811df8b858fd7fbedeb534aa715d66a9005 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 27 Aug 2003 15:07:46 +0000 Subject: fix segfault on empty wins server name registration reply (This used to be commit 743560284cebd686be1094ce1d657e6d06c291b0) --- source3/nmbd/nmbd_winsserver.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 1abff5d5e2..484588c662 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -859,8 +859,10 @@ already exists in WINS as a GROUP name.\n", nmb_namestr(question) )); * reject without doing the query - we know we will reject it. */ - pull_ascii_nstring(name, namerec->name.name); - if((namerec != NULL) && (is_myname(name)) ) { + if ( namerec != NULL ) + pull_ascii_nstring(name, namerec->name.name); + + if( is_myname(name) ) { if(!ismyip(from_ip)) { DEBUG(3,("wins_process_name_registration_request: Attempt to register name %s. Name \ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(question) )); -- cgit From 8dc1a4f30066f7cc25ab6b775b24f32ba275d78e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 27 Aug 2003 18:00:09 +0000 Subject: Ensure we use correct length nstrings for workgroup and browser names. Jeremy. (This used to be commit be534c8adf6c3cb8921ce49dbb79991c632d501e) --- source3/nmbd/nmbd_become_lmb.c | 2 +- source3/nmbd/nmbd_browserdb.c | 4 ++-- source3/nmbd/nmbd_browsesync.c | 6 +++--- source3/nmbd/nmbd_elections.c | 8 ++++---- source3/nmbd/nmbd_serverlistdb.c | 2 +- source3/nmbd/nmbd_synclists.c | 11 +++++------ source3/nmbd/nmbd_workgroupdb.c | 8 ++++---- 7 files changed, 20 insertions(+), 21 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index a6ae1ce42e..2370c7ba36 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -590,5 +590,5 @@ local_master_browser_name for workgroup %s to workgroup name.\n", } #endif - fstrcpy(work->local_master_browser_name, newname); + nstrcpy(work->local_master_browser_name, newname); } diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c index 83dfba66e9..443edf599d 100644 --- a/source3/nmbd/nmbd_browserdb.c +++ b/source3/nmbd/nmbd_browserdb.c @@ -106,8 +106,8 @@ struct browse_cache_record *create_browser_in_lmb_cache( const char *work_name, /* Allow the new lmb to miss an announce period before we remove it. */ browc->death_time = now + ( (CHECK_TIME_MST_ANNOUNCE + 2) * 60 ); - pstrcpy( browc->lmb_name, browser_name); - pstrcpy( browc->work_group, work_name); + nstrcpy( browc->lmb_name, browser_name); + nstrcpy( browc->work_group, work_name); strupper_m( browc->lmb_name ); strupper_m( browc->work_group ); diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 95e542354f..96e8fd1b81 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -460,7 +460,7 @@ static void get_domain_master_name_node_status_success(struct subnet_record *sub return; /* remember who the master is */ - fstrcpy(work->local_master_browser_name, server_name); + nstrcpy(work->local_master_browser_name, server_name); make_nmb_name(&nmbname, server_name, 0x20); work->dmb_name = nmbname; work->dmb_addr = from_ip; @@ -639,14 +639,14 @@ void sync_all_dmbs(time_t t) /* count how many syncs we might need to do */ for (work=unicast_subnet->workgrouplist; work; work = work->next) { - if (strcmp(lp_workgroup(), work->work_group)) { + if (strncmp(lp_workgroup(), work->work_group, sizeof(nstring))) { count++; } } /* sync with a probability of 1/count */ for (work=unicast_subnet->workgrouplist; work; work = work->next) { - if (strcmp(lp_workgroup(), work->work_group)) { + if (strncmp(lp_workgroup(), work->work_group, sizeof(nstring))) { nstring dmb_name; if (((unsigned)sys_random()) % count != 0) diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index d4d6da081a..e341f6f7fb 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -97,7 +97,7 @@ static void check_for_master_browser_fail( struct subnet_record *subrec, return; } - if (strequal(work->work_group, lp_workgroup())) { + if (strnequal(work->work_group, lp_workgroup(), sizeof(nstring))) { if (lp_local_master()) { /* We have discovered that there is no local master @@ -145,7 +145,7 @@ void check_master_browser_exists(time_t t) struct work_record *work; for (work = subrec->workgrouplist; work; work = work->next) { - if (strequal(work->work_group, workgroup_name) && !AM_LOCAL_MASTER_BROWSER(work)) { + if (strnequal(work->work_group, workgroup_name, sizeof(nstring)) && !AM_LOCAL_MASTER_BROWSER(work)) { /* Do a name query for the local master browser on this net. */ query_name( subrec, work->work_group, 0x1d, check_for_master_browser_success, @@ -284,7 +284,7 @@ void process_election(struct subnet_record *subrec, struct packet_struct *p, cha goto done; } - if (!strequal(work->work_group, lp_workgroup())) { + if (!strnequal(work->work_group, lp_workgroup(), sizeof(nstring))) { DEBUG(3,("process_election: ignoring election request for workgroup %s on subnet %s as this \ is not my workgroup.\n", work->work_group, subrec->subnet_name )); goto done; @@ -381,7 +381,7 @@ void nmbd_message_election(int msg_type, pid_t src, void *buf, size_t len) for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { struct work_record *work; for (work = subrec->workgrouplist; work; work = work->next) { - if (strequal(work->work_group, lp_workgroup())) { + if (strnequal(work->work_group, lp_workgroup(), sizeof(nstring))) { work->needelection = True; work->ElectionCount=0; work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index b4c6e2902d..ecde45cfb9 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -251,7 +251,7 @@ static uint32 write_this_workgroup_name( struct subnet_record *subrec, { struct subnet_record *ssub; - if(strequal(lp_workgroup(), work->work_group)) + if(strnequal(lp_workgroup(), work->work_group, sizeof(nstring))) return 0; /* This is a workgroup we have seen on a broadcast subnet. All diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 337c2f9468..6a0576a5a4 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -31,8 +31,8 @@ struct sync_record { struct sync_record *next, *prev; - fstring workgroup; - fstring server; + nstring workgroup; + nstring server; pstring fname; struct in_addr ip; pid_t pid; @@ -148,8 +148,8 @@ done: ZERO_STRUCTP(s); - fstrcpy(s->workgroup, work->work_group); - fstrcpy(s->server, name); + nstrcpy(s->workgroup, work->work_group); + nstrcpy(s->server, name); s->ip = ip; slprintf(s->fname, sizeof(pstring)-1, @@ -206,8 +206,7 @@ static void complete_one(struct sync_record *s, sname, lp_max_ttl()); if (work) { /* remember who the master is */ - fstrcpy(work->local_master_browser_name, - comment); + nstrcpy(work->local_master_browser_name, comment); } } return; diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 08d6fb2c62..c957b517cf 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -56,7 +56,7 @@ static struct work_record *create_workgroup(const char *name, int ttl) } memset((char *)work, '\0', sizeof(*work)); - fstrcpy(work->work_group,name); + nstrcpy(work->work_group,name); work->serverlist = NULL; work->RunningElection = False; @@ -76,7 +76,7 @@ static struct work_record *create_workgroup(const char *name, int ttl) for (subrec = FIRST_SUBNET; subrec && (t == -1); subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { struct work_record *w; for (w = subrec->workgrouplist; w && t == -1; w = w->next) { - if (strequal(w->work_group, work->work_group)) + if (strnequal(w->work_group, work->work_group, sizeof(nstring))) t = w->token; } } @@ -150,7 +150,7 @@ struct work_record *find_workgroup_on_subnet(struct subnet_record *subrec, name, subrec->subnet_name)); for (ret = subrec->workgrouplist; ret; ret = ret->next) { - if (strequal(ret->work_group,name)) { + if (strnequal(ret->work_group,name,sizeof(nstring))) { DEBUGADD(4, ("found.\n")); return(ret); } @@ -211,7 +211,7 @@ void initiate_myworkgroup_startup(struct subnet_record *subrec, struct work_reco { int i; - if(!strequal(lp_workgroup(), work->work_group)) + if(!strnequal(lp_workgroup(), work->work_group,sizeof(nstring))) return; /* If this is a broadcast subnet then start elections on it if we are so configured. */ -- cgit From 6872f392f1a8cd667aecc8df0b15da66f58c9407 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 28 Aug 2003 18:12:59 +0000 Subject: Fixed off-by-one bugs in workgroup name comparisons. Complain when a workgroup name is >15 characters. Jeremy. (This used to be commit 35a0b3c035d50474eda97b015676885722737a95) --- source3/nmbd/nmbd_elections.c | 8 ++++---- source3/nmbd/nmbd_serverlistdb.c | 2 +- source3/nmbd/nmbd_workgroupdb.c | 15 +++++++++++---- 3 files changed, 16 insertions(+), 9 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index e341f6f7fb..fabc0eddca 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -97,7 +97,7 @@ static void check_for_master_browser_fail( struct subnet_record *subrec, return; } - if (strnequal(work->work_group, lp_workgroup(), sizeof(nstring))) { + if (strnequal(work->work_group, lp_workgroup(), sizeof(nstring)-1)) { if (lp_local_master()) { /* We have discovered that there is no local master @@ -145,7 +145,7 @@ void check_master_browser_exists(time_t t) struct work_record *work; for (work = subrec->workgrouplist; work; work = work->next) { - if (strnequal(work->work_group, workgroup_name, sizeof(nstring)) && !AM_LOCAL_MASTER_BROWSER(work)) { + if (strnequal(work->work_group, workgroup_name, sizeof(nstring)-1) && !AM_LOCAL_MASTER_BROWSER(work)) { /* Do a name query for the local master browser on this net. */ query_name( subrec, work->work_group, 0x1d, check_for_master_browser_success, @@ -284,7 +284,7 @@ void process_election(struct subnet_record *subrec, struct packet_struct *p, cha goto done; } - if (!strnequal(work->work_group, lp_workgroup(), sizeof(nstring))) { + if (!strnequal(work->work_group, lp_workgroup(), sizeof(nstring)-1)) { DEBUG(3,("process_election: ignoring election request for workgroup %s on subnet %s as this \ is not my workgroup.\n", work->work_group, subrec->subnet_name )); goto done; @@ -381,7 +381,7 @@ void nmbd_message_election(int msg_type, pid_t src, void *buf, size_t len) for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { struct work_record *work; for (work = subrec->workgrouplist; work; work = work->next) { - if (strnequal(work->work_group, lp_workgroup(), sizeof(nstring))) { + if (strnequal(work->work_group, lp_workgroup(), sizeof(nstring)-1)) { work->needelection = True; work->ElectionCount=0; work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index ecde45cfb9..a5008f803b 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -251,7 +251,7 @@ static uint32 write_this_workgroup_name( struct subnet_record *subrec, { struct subnet_record *ssub; - if(strnequal(lp_workgroup(), work->work_group, sizeof(nstring))) + if(strnequal(lp_workgroup(), work->work_group, sizeof(nstring)-1)) return 0; /* This is a workgroup we have seen on a broadcast subnet. All diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index c957b517cf..b9fab4b278 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -56,7 +56,14 @@ static struct work_record *create_workgroup(const char *name, int ttl) } memset((char *)work, '\0', sizeof(*work)); - nstrcpy(work->work_group,name); + if (strlen(name)+1 > sizeof(nstring)) { + memcpy(work->work_group,name,sizeof(nstring)-1); + work->work_group[sizeof(nstring)-1] = '\0'; + DEBUG(0,("create_workgroup: workgroup name %s is too long. Truncating to %s\n", + name, work->work_group )); + } else { + nstrcpy(work->work_group,name); + } work->serverlist = NULL; work->RunningElection = False; @@ -76,7 +83,7 @@ static struct work_record *create_workgroup(const char *name, int ttl) for (subrec = FIRST_SUBNET; subrec && (t == -1); subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { struct work_record *w; for (w = subrec->workgrouplist; w && t == -1; w = w->next) { - if (strnequal(w->work_group, work->work_group, sizeof(nstring))) + if (strnequal(w->work_group, work->work_group, sizeof(nstring)-1)) t = w->token; } } @@ -150,7 +157,7 @@ struct work_record *find_workgroup_on_subnet(struct subnet_record *subrec, name, subrec->subnet_name)); for (ret = subrec->workgrouplist; ret; ret = ret->next) { - if (strnequal(ret->work_group,name,sizeof(nstring))) { + if (strnequal(ret->work_group,name,sizeof(nstring)-1)) { DEBUGADD(4, ("found.\n")); return(ret); } @@ -211,7 +218,7 @@ void initiate_myworkgroup_startup(struct subnet_record *subrec, struct work_reco { int i; - if(!strnequal(lp_workgroup(), work->work_group,sizeof(nstring))) + if(!strnequal(lp_workgroup(), work->work_group,sizeof(nstring)-1)) return; /* If this is a broadcast subnet then start elections on it if we are so configured. */ -- cgit From 569c2827fa64d2ab81959b13e552ab675174fa00 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 28 Aug 2003 18:23:05 +0000 Subject: Add length warning on register name. Jeremy. (This used to be commit 68d02ebbcd9bc4cf7c84763d03c903b1f2e55fb8) --- source3/nmbd/nmbd_nameregister.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index 5c9deeb4db..0397f56512 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -471,8 +471,18 @@ void register_name(struct subnet_record *subrec, struct userdata_struct *userdata) { struct nmb_name nmbname; - - make_nmb_name(&nmbname, name, type); + nstring nname; + + if (strlen(name)+1 > sizeof(nstring)) { + memcpy(nname, name,sizeof(nstring)-1); + nname[sizeof(nstring)-1] = '\0'; + DEBUG(0,("register_name: NetBIOS name %s is too long. Truncating to %s\n", + name, nname)); + } else { + nstrcpy(nname,name); + } + + make_nmb_name(&nmbname, nname, type); /* Always set the NB_ACTIVE flag on the name we are registering. Doesn't make sense without it. -- cgit From 9b276fc77fc30638263be4593967da72f6f93c75 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 1 Sep 2003 18:28:09 +0000 Subject: Fix comment strings to 43 bytes as per spec. Jeremy. (This used to be commit f1ec43fae400455d20931ab2d3ecd8f9a6609050) --- source3/nmbd/nmbd_incomingdgrams.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 49fad8e867..f646e39716 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -108,7 +108,7 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p START_PROFILE(host_announce); pull_ascii_fstring(comment, buf+31); - comment[12] = 0; + comment[42] = 0; pull_ascii_nstring(announce_name, buf+5); pull_ascii_nstring(source_name, dgram->source_name.name); @@ -209,7 +209,6 @@ void process_workgroup_announce(struct subnet_record *subrec, struct packet_stru pull_ascii_nstring(workgroup_announce_name,buf+5); pull_ascii_nstring(master_name,buf+31); - master_name[12] = 0; pull_ascii_nstring(source_name,dgram->source_name.name); pull_ascii_nstring(dest_name,dgram->dest_name.name); @@ -268,7 +267,7 @@ void process_local_master_announce(struct subnet_record *subrec, struct packet_s pull_ascii_nstring(server_name,buf+5); pull_ascii_fstring(comment, buf+31); - comment[12] = 0; + comment[42] = 0; pull_ascii_nstring(source_name, dgram->source_name.name); pull_ascii_nstring(work_name, dgram->dest_name.name); -- cgit From 94f59f54921174fc156fade575ca114d331b1bd8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 5 Sep 2003 19:59:55 +0000 Subject: More tuning from cachegrind. Change most trim_string() calls to trim_char(0, as that's what they do. Fix string_replace() to fast-path ascii. Jeremy. (This used to be commit f35e9a8b909d3c74be47083ccc4a4e91a14938db) --- source3/nmbd/nmbd_browsesync.c | 4 ++-- source3/nmbd/nmbd_serverlistdb.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 96e8fd1b81..6cde88651f 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -204,7 +204,7 @@ static void domain_master_node_status_success(struct subnet_record *subrec, pull_ascii_nstring(qname, p); name_type = CVAL(p,15); nb_flags = get_nb_flags(&p[16]); - trim_string(qname,NULL," "); + trim_char(qname,'\0',' '); p += 18; @@ -427,7 +427,7 @@ static void get_domain_master_name_node_status_success(struct subnet_record *sub pull_ascii_nstring(qname, p); name_type = CVAL(p,15); nb_flags = get_nb_flags(&p[16]); - trim_string(qname,NULL," "); + trim_char(qname,'\0',' '); p += 18; diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index a5008f803b..cdb1089a54 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -328,7 +328,7 @@ void write_browse_list(time_t t, BOOL force_write) updatecount++; pstrcpy(fname,lp_lockdir()); - trim_string(fname,NULL,"/"); + trim_char(fname,'\0' ,'/'); pstrcat(fname,"/"); pstrcat(fname,SERVER_LIST); pstrcpy(fnamenew,fname); -- cgit From 1148875a1586ee232f40422ba776af71594c70fb Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 29 Sep 2003 04:41:45 +0000 Subject: Fix broken wins hook functionality. A i18n fixe caused the name type to be appended to the netbios name between angle brackets. This interfered the 'sh -c' used to implement smbrun(). Closes bug #528. (This used to be commit 92b37b3ef097e84adace1295af42853c07ddbec2) --- source3/nmbd/nmbd_winsserver.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 484588c662..804a5aad57 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -107,7 +107,7 @@ static void wins_hook(const char *operation, struct name_record *namerec, int tt { pstring command; char *cmd = lp_wins_hook(); - char *p; + char *p, *namestr; int i; if (!cmd || !*cmd) return; @@ -119,11 +119,17 @@ static void wins_hook(const char *operation, struct name_record *namerec, int tt } } + /* Use the name without the nametype (and scope) appended */ + + namestr = nmb_namestr(&namerec->name); + p = strchr(namestr, '<'); + *p = 0; + p = command; p += slprintf(p, sizeof(command)-1, "%s %s %s %02x %d", cmd, operation, - nmb_namestr(&namerec->name), + namestr, namerec->name.name_type, ttl); -- cgit From ecd8cc4ef29327f205e76093fd744a837421fee6 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Mon, 29 Sep 2003 04:57:20 +0000 Subject: Apply some NULL pointer paranoia to previous wins hook fix. (This used to be commit 0281c5b764971c5300b99b82d89c812ded5a1335) --- source3/nmbd/nmbd_winsserver.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 804a5aad57..3694072420 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -122,8 +122,8 @@ static void wins_hook(const char *operation, struct name_record *namerec, int tt /* Use the name without the nametype (and scope) appended */ namestr = nmb_namestr(&namerec->name); - p = strchr(namestr, '<'); - *p = 0; + if ((p = strchr(namestr, '<'))) + *p = 0; p = command; p += slprintf(p, sizeof(command)-1, "%s %s %s %02x %d", -- cgit From bb0598faf58679a7ad26a1caab8eadb154a07ae2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 22 Oct 2003 23:38:20 +0000 Subject: Put strcasecmp/strncasecmp on the banned list (except for needed calls in iconv.c and nsswitch/). Using them means you're not thinking about multibyte at all and I really want to discourage that. Jeremy. (This used to be commit d7e35dfb9283d560d0ed2ab231f36ed92767dace) --- source3/nmbd/nmbd_elections.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index fabc0eddca..19b00f1f4d 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -247,7 +247,7 @@ static BOOL win_election(struct work_record *work, int version, if (timeup < mytimeup) return(True); - if (strcasecmp(global_myname(), server_name) > 0) + if (StrCaseCmp(global_myname(), server_name) > 0) return(False); return(True); -- cgit From 231124ced9237cdbc3732a722c8f373ee760927b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 29 Oct 2003 21:28:00 +0000 Subject: Fixes to check for wraps which could cause coredumps. Jeremy. (This used to be commit ad06edd1bb58cc5e2c38a364b1af96a933b770af) --- source3/nmbd/nmbd_processlogon.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 2a6a6b66d1..816b351464 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -491,6 +491,8 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", /* Domain SID */ +#if 0 + /* We must range check this. */ q += IVAL(q, 0) + 4; /* 4 byte length plus data */ q += 2; /* Alignment? */ @@ -500,6 +502,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += 4; /* NT version (0x1) */ q += 2; /* LMNT token (0xff) */ q += 2; /* LM20 token (0xff) */ +#endif SAFE_FREE(db_info); /* Not sure whether we need to do anything useful with these */ -- cgit From 13fe54264e360ef798d7afa0509259d0562bfc0e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 1 Nov 2003 17:41:16 +0000 Subject: This binds the nmbd sending socket to the 'socket address'. Hmmm. This is correct in 2.2. Obviously I did not test my 3.0 checkin at that time. Now it hit me at a customer's site... Volker (This used to be commit a0e741aa684c756943969bdb4be20a02e588d27c) --- source3/nmbd/nmbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 25ba07c8a7..36aa2e2485 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -570,8 +570,8 @@ static BOOL open_sockets(BOOL isdaemon, int port) if ( isdaemon ) ClientNMB = open_socket_in(SOCK_DGRAM, port, - interpret_addr(lp_socket_address()), - 0,True); + 0, interpret_addr(lp_socket_address()), + True); else ClientNMB = 0; -- cgit From 536f72913e6102ac06196f919cc0cc2060532f37 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 5 Nov 2003 00:12:49 +0000 Subject: Fix for bug #771. Fix packet length for browse list reply. Jeremy. (This used to be commit d085c94dacffbe8199e83315340e4f60d1f0b9a5) --- source3/nmbd/nmbd_packets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 72eb1b5019..c318689fd1 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1835,7 +1835,7 @@ BOOL send_mailslot(BOOL unique, const char *mailslot,char *buf, size_t len, /* Setup the smb part. */ ptr -= 4; /* XXX Ugliness because of handling of tcp SMB length. */ memcpy(tmp,ptr,4); - set_message(ptr,17,23 + len,True); + set_message(ptr,17,strlen(mailslot) + 1 + len,True); memcpy(ptr,tmp,4); SCVAL(ptr,smb_com,SMBtrans); -- cgit From 9f154119e8788e9c3525b0a61c64326abd35bdf6 Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Thu, 6 Nov 2003 22:11:08 +0000 Subject: Final round of printf warnings fixes for the moment. (This used to be commit 0519a7022b4979c0e8ddd4907f4b858a59299c06) --- source3/nmbd/nmbd_processlogon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 816b351464..3b02197805 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -255,7 +255,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q = ALIGN4(q, buf); } - DEBUG(3,("process_logon_packet: len = %d PTR_DIFF(q, buf) = %d\n", len, PTR_DIFF(q, buf) )); + DEBUG(3,("process_logon_packet: len = %d PTR_DIFF(q, buf) = %ld\n", len, (unsigned long)PTR_DIFF(q, buf) )); if (len - PTR_DIFF(q, buf) > 8) { /* with NT5 clients we can sometimes -- cgit From 86450924a0ed5ea721eb8555c5192978e875bbbe Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sun, 11 Jan 2004 13:23:50 +0000 Subject: update copyright to -2004 metze (This used to be commit 12d6bc3bd0684646e990c2fc6485fe1a92ac98fb) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 36aa2e2485..880de7f91b 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -662,7 +662,7 @@ static BOOL open_sockets(BOOL isdaemon, int port) reopen_logs(); DEBUG( 0, ( "Netbios nameserver version %s started.\n", SAMBA_VERSION_STRING) ); - DEBUGADD( 0, ( "Copyright Andrew Tridgell and the Samba Team 1994-2003\n" ) ); + DEBUGADD( 0, ( "Copyright Andrew Tridgell and the Samba Team 1994-2004\n" ) ); if ( !reload_nmbd_services(False) ) return(-1); -- cgit From eade7ab7698dd86ceefe2ce70bcdd447ca48a1bb Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Sat, 24 Jan 2004 10:46:55 +0000 Subject: A Samba DC is nothing special these days - so every domain controller location packet from the client is not a DEBUG(1) event anymore... (Yes, we printed this for each of these UDP packets...) Andrew Bartlett (This used to be commit 4ca0ab7506f15112d996bf68278e54e535c4cab4) --- source3/nmbd/nmbd_processlogon.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 3b02197805..7819649b83 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -84,7 +84,7 @@ void process_logon_packet(struct packet_struct *p, char *buf,int len, memset(outbuf, 0, sizeof(outbuf)); if (!lp_domain_logons()) { - DEBUG(3,("process_logon_packet: Logon packet received from IP %s and domain \ + DEBUG(5,("process_logon_packet: Logon packet received from IP %s and domain \ logons are not enabled.\n", inet_ntoa(p->ip) )); return; } @@ -92,7 +92,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); pstrcpy(my_name, global_myname()); code = SVAL(buf,0); - DEBUG(1,("process_logon_packet: Logon from %s: code = 0x%x\n", inet_ntoa(p->ip), code)); + DEBUG(4,("process_logon_packet: Logon from %s: code = 0x%x\n", inet_ntoa(p->ip), code)); switch (code) { case 0: @@ -112,7 +112,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); pull_ascii_fstring(user_str, user); pull_ascii_fstring(getdc_str, getdc); - DEBUG(3,("process_logon_packet: Domain login request from %s at IP %s user=%s token=%x\n", + DEBUG(5,("process_logon_packet: Domain login request from %s at IP %s user=%s token=%x\n", mach_str,inet_ntoa(p->ip),user_str,token)); q = outbuf; @@ -211,7 +211,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); pull_ascii_fstring(mach_str, machine); - DEBUG(3,("process_logon_packet: GETDC request from %s at IP %s, \ + DEBUG(5,("process_logon_packet: GETDC request from %s at IP %s, \ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", mach_str,inet_ntoa(p->ip), reply_name, lp_workgroup(), QUERYFORPDC_R, (uint32)ntversion, (uint32)lmnttoken, @@ -248,14 +248,14 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", domainsidsize = IVAL(q, 0); q += 4; - DEBUG(3,("process_logon_packet: SAMLOGON sidsize %d, len = %d\n", domainsidsize, len)); + DEBUG(5,("process_logon_packet: SAMLOGON sidsize %d, len = %d\n", domainsidsize, len)); if (domainsidsize < (len - PTR_DIFF(q, buf)) && (domainsidsize != 0)) { q += domainsidsize; q = ALIGN4(q, buf); } - DEBUG(3,("process_logon_packet: len = %d PTR_DIFF(q, buf) = %ld\n", len, (unsigned long)PTR_DIFF(q, buf) )); + DEBUG(5,("process_logon_packet: len = %d PTR_DIFF(q, buf) = %ld\n", len, (unsigned long)PTR_DIFF(q, buf) )); if (len - PTR_DIFF(q, buf) > 8) { /* with NT5 clients we can sometimes @@ -284,12 +284,12 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", */ pull_ucs2_pstring(ascuser, uniuser); pull_ucs2_fstring(asccomp, unicomp); - DEBUG(3,("process_logon_packet: SAMLOGON user %s\n", ascuser)); + DEBUG(5,("process_logon_packet: SAMLOGON user %s\n", ascuser)); fstrcpy(reply_name, "\\\\"); /* Here it wants \\LOGONSERVER. */ fstrcat(reply_name, my_name); - DEBUG(3,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n", + DEBUG(5,("process_logon_packet: SAMLOGON request from %s(%s) for %s, returning logon svr %s domain %s code %x token=%x\n", asccomp,inet_ntoa(p->ip), ascuser, reply_name, lp_workgroup(), SAMLOGON_R ,lmnttoken)); -- cgit From 2f2e5b01919fe4daf60f97430959ebc98e31ce92 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 30 Jan 2004 18:38:48 +0000 Subject: Fix up name canonicalization (needed for krb5 keytab support later). Remove source_env handler (no longer used in any codepath). Jeremy. (This used to be commit 3a3e33603084048e647af86a9badaaf49433c789) --- source3/nmbd/nmbd_processlogon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 7819649b83..7350d8237f 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -321,7 +321,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", char *q_orig = q; int str_offset; - get_mydomname(domain); + get_mydnsdomname(domain); get_myname(hostname); if (SVAL(uniuser, 0) == 0) { -- cgit From 6b9dbbcd249360fb9acd61d6900baccf621c9cce Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 13 Mar 2004 02:16:21 +0000 Subject: Modified fix for bugid #784. Based on a patch from moriyama@miraclelinux.com (MORIYAMA Masayuki). Don't use nstrings to hold workgroup and netbios names. The problem with them is that MB netbios and workgroup names in unix charset (particularly utf8) may be up to 3x bigger than the name when represented in dos charset (ie. cp932). So go back to using fstrings for these but translate into nstrings (ie. 16 byte length values) for transport on the wire. Jeremy. (This used to be commit b4ea493599ab414f7828b83f40a5a8b43479ff64) --- source3/nmbd/asyncdns.c | 4 +- source3/nmbd/nmbd_become_dmb.c | 16 ++++---- source3/nmbd/nmbd_become_lmb.c | 22 +++++------ source3/nmbd/nmbd_browserdb.c | 4 +- source3/nmbd/nmbd_browsesync.c | 22 +++++------ source3/nmbd/nmbd_elections.c | 16 ++++---- source3/nmbd/nmbd_incomingdgrams.c | 76 ++++++++++++++++++------------------ source3/nmbd/nmbd_incomingrequests.c | 31 ++++++++------- source3/nmbd/nmbd_logonnames.c | 8 ++-- source3/nmbd/nmbd_mynames.c | 4 +- source3/nmbd/nmbd_namelistdb.c | 8 ++-- source3/nmbd/nmbd_nameregister.c | 23 +++++------ source3/nmbd/nmbd_packets.c | 8 ++-- source3/nmbd/nmbd_processlogon.c | 6 +-- source3/nmbd/nmbd_synclists.c | 10 ++--- source3/nmbd/nmbd_winsproxy.c | 8 ++-- source3/nmbd/nmbd_winsserver.c | 22 +++++------ source3/nmbd/nmbd_workgroupdb.c | 23 ++++++----- 18 files changed, 160 insertions(+), 151 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 6d5d487b11..dafbff7af2 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -27,9 +27,9 @@ static struct name_record *add_dns_result(struct nmb_name *question, struct in_addr addr) { int name_type = question->name_type; - nstring qname; + fstring qname; - pull_ascii_nstring(qname, question->name); + pull_ascii_nstring(qname, sizeof(qname), question->name); if (!addr.s_addr) { /* add the fail to WINS cache of names. give it 1 hour in the cache */ diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index 46d37fbb81..c9b0a22580 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -37,11 +37,11 @@ static void become_domain_master_fail(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *fail_name) { - nstring failname; + fstring failname; struct work_record *work; struct server_record *servrec; - pull_ascii_nstring(failname, fail_name->name); + pull_ascii_nstring(failname, sizeof(failname), fail_name->name); work = find_workgroup_on_subnet(subrec, failname); if(!work) { DEBUG(0,("become_domain_master_fail: Error - cannot find \ @@ -80,11 +80,11 @@ static void become_domain_master_stage2(struct subnet_record *subrec, uint16 nb_flags, int ttl, struct in_addr registered_ip) { - nstring regname; + fstring regname; struct work_record *work; struct server_record *servrec; - pull_ascii_nstring(regname, registered_name->name); + pull_ascii_nstring(regname, sizeof(regname), registered_name->name); work = find_workgroup_on_subnet( subrec, regname); if(!work) { @@ -200,8 +200,8 @@ static void become_domain_master_query_success(struct subnet_record *subrec, struct nmb_name *nmbname, struct in_addr ip, struct res_rec *rrec) { - nstring name; - pull_ascii_nstring(name, nmbname->name); + fstring name; + pull_ascii_nstring(name, sizeof(name), nmbname->name); /* If the given ip is not ours, then we can't become a domain controler as the name is already registered. @@ -241,7 +241,7 @@ static void become_domain_master_query_fail(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *question_name, int fail_code) { - nstring name; + fstring name; /* If the query was unicast, and the error is not NAM_ERR (name didn't exist), then this is a failure. Otherwise, not finding the name is what we want. */ @@ -254,7 +254,7 @@ querying WINS server for name %s.\n", } /* Otherwise - not having the name allows us to register it. */ - pull_ascii_nstring(name, question_name->name); + pull_ascii_nstring(name, sizeof(name), question_name->name); become_domain_master_stage1(subrec, name); } diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index 2370c7ba36..8d66320f3e 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -33,11 +33,11 @@ extern uint16 samba_nb_type; /* Samba's NetBIOS name type. */ void insert_permanent_name_into_unicast( struct subnet_record *subrec, struct nmb_name *nmbname, uint16 nb_type ) { - nstring name; + fstring name; struct name_record *namerec; if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) == NULL) { - pull_ascii_nstring(name, nmbname->name); + pull_ascii_nstring(name, sizeof(name), nmbname->name); /* The name needs to be created on the unicast subnet. */ (void)add_name_to_subnet( unicast_subnet, name, nmbname->name_type, nb_type, @@ -135,7 +135,7 @@ static void unbecome_local_master_success(struct subnet_record *subrec, struct in_addr released_ip) { BOOL force_new_election = False; - nstring relname; + fstring relname; memcpy((char *)&force_new_election, userdata->data, sizeof(BOOL)); @@ -143,7 +143,7 @@ static void unbecome_local_master_success(struct subnet_record *subrec, nmb_namestr(released_name))); /* Now reset the workgroup and server state. */ - pull_ascii_nstring(relname, released_name->name); + pull_ascii_nstring(relname, sizeof(relname), released_name->name); reset_workgroup_state( subrec, relname, force_new_election ); if( DEBUGLVL( 0 ) ) { @@ -166,7 +166,7 @@ static void unbecome_local_master_fail(struct subnet_record *subrec, struct resp struct name_record *namerec; struct userdata_struct *userdata = rrec->userdata; BOOL force_new_election = False; - nstring failname; + fstring failname; memcpy((char *)&force_new_election, userdata->data, sizeof(BOOL)); @@ -179,7 +179,7 @@ Removing from namelist anyway.\n", nmb_namestr(fail_name))); remove_name_from_namelist(subrec, namerec); /* Now reset the workgroup and server state. */ - pull_ascii_nstring(failname, fail_name->name); + pull_ascii_nstring(failname, sizeof(failname), fail_name->name); reset_workgroup_state( subrec, failname, force_new_election ); if( DEBUGLVL( 0 ) ) { @@ -330,9 +330,9 @@ static void become_local_master_stage2(struct subnet_record *subrec, struct server_record *sl; struct work_record *work; struct server_record *servrec; - nstring regname; + fstring regname; - pull_ascii_nstring(regname, registered_name->name); + pull_ascii_nstring(regname, sizeof(regname), registered_name->name); work = find_workgroup_on_subnet( subrec, regname); if(!work) { @@ -410,13 +410,13 @@ static void become_local_master_fail2(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *fail_name) { - nstring failname; + fstring failname; struct work_record *work; DEBUG(0,("become_local_master_fail2: failed to register name %s on subnet %s. \ Failed to become a local master browser.\n", nmb_namestr(fail_name), subrec->subnet_name)); - pull_ascii_nstring(failname, fail_name->name); + pull_ascii_nstring(failname, sizeof(failname), fail_name->name); work = find_workgroup_on_subnet( subrec, failname); if(!work) { @@ -590,5 +590,5 @@ local_master_browser_name for workgroup %s to workgroup name.\n", } #endif - nstrcpy(work->local_master_browser_name, newname); + fstrcpy(work->local_master_browser_name, newname); } diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c index 443edf599d..d781259156 100644 --- a/source3/nmbd/nmbd_browserdb.c +++ b/source3/nmbd/nmbd_browserdb.c @@ -106,8 +106,8 @@ struct browse_cache_record *create_browser_in_lmb_cache( const char *work_name, /* Allow the new lmb to miss an announce period before we remove it. */ browc->death_time = now + ( (CHECK_TIME_MST_ANNOUNCE + 2) * 60 ); - nstrcpy( browc->lmb_name, browser_name); - nstrcpy( browc->work_group, work_name); + fstrcpy( browc->lmb_name, browser_name); + fstrcpy( browc->work_group, work_name); strupper_m( browc->lmb_name ); strupper_m( browc->work_group ); diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 6cde88651f..454c349767 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -146,7 +146,7 @@ As a local master browser, do a sync with a domain master browser. static void sync_with_dmb(struct work_record *work) { - nstring dmb_name; + fstring dmb_name; if( DEBUGLVL( 2 ) ) { dbgtext( "sync_with_dmb:\n" ); @@ -156,7 +156,7 @@ static void sync_with_dmb(struct work_record *work) dbgtext( "for workgroup %s\n", work->work_group ); } - pull_ascii_nstring(dmb_name, work->dmb_name.name); + pull_ascii_nstring(dmb_name, sizeof(fstring), work->dmb_name.name); sync_browse_lists(work, dmb_name, work->dmb_name.name_type, work->dmb_addr, False, True); } @@ -197,11 +197,11 @@ static void domain_master_node_status_success(struct subnet_record *subrec, p += 1; while (numnames--) { - nstring qname; + fstring qname; uint16 nb_flags; int name_type; - pull_ascii_nstring(qname, p); + pull_ascii_nstring(qname, sizeof(qname), p); name_type = CVAL(p,15); nb_flags = get_nb_flags(&p[16]); trim_char(qname,'\0',' '); @@ -278,9 +278,9 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec, struct nmb_name nmbname; struct userdata_struct *userdata; size_t size = sizeof(struct userdata_struct) + sizeof(fstring)+1; - nstring qname; + fstring qname; - pull_ascii_nstring(qname, q_name->name); + pull_ascii_nstring(qname, sizeof(qname), q_name->name); if( !(work = find_workgroup_on_subnet(subrec, qname)) ) { if( DEBUGLVL( 0 ) ) { dbgtext( "find_domain_master_name_query_success:\n" ); @@ -420,11 +420,11 @@ static void get_domain_master_name_node_status_success(struct subnet_record *sub p += 1; while (numnames--) { - nstring qname; + fstring qname; uint16 nb_flags; int name_type; - pull_ascii_nstring(qname, p); + pull_ascii_nstring(qname, sizeof(qname), p); name_type = CVAL(p,15); nb_flags = get_nb_flags(&p[16]); trim_char(qname,'\0',' '); @@ -460,7 +460,7 @@ static void get_domain_master_name_node_status_success(struct subnet_record *sub return; /* remember who the master is */ - nstrcpy(work->local_master_browser_name, server_name); + fstrcpy(work->local_master_browser_name, server_name); make_nmb_name(&nmbname, server_name, 0x20); work->dmb_name = nmbname; work->dmb_addr = from_ip; @@ -647,7 +647,7 @@ void sync_all_dmbs(time_t t) /* sync with a probability of 1/count */ for (work=unicast_subnet->workgrouplist; work; work = work->next) { if (strncmp(lp_workgroup(), work->work_group, sizeof(nstring))) { - nstring dmb_name; + fstring dmb_name; if (((unsigned)sys_random()) % count != 0) continue; @@ -662,7 +662,7 @@ void sync_all_dmbs(time_t t) 0x20); } - pull_ascii_nstring(dmb_name, work->dmb_name.name); + pull_ascii_nstring(dmb_name, sizeof(dmb_name), work->dmb_name.name); DEBUG(3,("Initiating DMB<->DMB sync with %s(%s)\n", dmb_name, inet_ntoa(work->dmb_addr))); diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 19b00f1f4d..882c26ce80 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -70,8 +70,8 @@ static void check_for_master_browser_success(struct subnet_record *subrec, struct nmb_name *answer_name, struct in_addr answer_ip, struct res_rec *rrec) { - nstring aname; - pull_ascii_nstring(aname, answer_name->name); + fstring aname; + pull_ascii_nstring(aname, sizeof(aname), answer_name->name); DEBUG(3,("check_for_master_browser_success: Local master browser for workgroup %s exists at \ IP %s (just checking).\n", aname, inet_ntoa(answer_ip) )); } @@ -85,10 +85,10 @@ static void check_for_master_browser_fail( struct subnet_record *subrec, struct nmb_name *question_name, int fail_code) { - nstring workgroup_name; + fstring workgroup_name; struct work_record *work; - pull_ascii_nstring(workgroup_name,question_name->name); + pull_ascii_nstring(workgroup_name,sizeof(workgroup_name),question_name->name); work = find_workgroup_on_subnet(subrec, workgroup_name); if(work == NULL) { @@ -263,12 +263,12 @@ void process_election(struct subnet_record *subrec, struct packet_struct *p, cha int version = CVAL(buf,0); uint32 criterion = IVAL(buf,1); int timeup = IVAL(buf,5)/1000; - nstring server_name; + fstring server_name; struct work_record *work; - nstring workgroup_name; + fstring workgroup_name; - pull_ascii_nstring(server_name, buf+13); - pull_ascii_nstring(workgroup_name, dgram->dest_name.name); + pull_ascii_nstring(server_name, sizeof(server_name), buf+13); + pull_ascii_nstring(workgroup_name, sizeof(workgroup_name), dgram->dest_name.name); START_PROFILE(election); server_name[15] = 0; diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index f646e39716..1450610e19 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -97,21 +97,21 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p { struct dgram_packet *dgram = &p->packet.dgram; int ttl = IVAL(buf,1)/1000; - nstring announce_name; + fstring announce_name; uint32 servertype = IVAL(buf,23); fstring comment; struct work_record *work; struct server_record *servrec; - nstring work_name; - nstring source_name; + fstring work_name; + fstring source_name; START_PROFILE(host_announce); pull_ascii_fstring(comment, buf+31); comment[42] = 0; - pull_ascii_nstring(announce_name, buf+5); - pull_ascii_nstring(source_name, dgram->source_name.name); + pull_ascii_nstring(announce_name, sizeof(announce_name), buf+5); + pull_ascii_nstring(source_name, sizeof(source_name), dgram->source_name.name); DEBUG(3,("process_host_announce: from %s<%02x> IP %s to \ %s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip), @@ -133,7 +133,7 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p } /* For a host announce the workgroup name is the destination name. */ - pull_ascii_nstring(work_name, dgram->dest_name.name); + pull_ascii_nstring(work_name, sizeof(work_name), dgram->dest_name.name); /* * Syntax servers version 5.1 send HostAnnounce packets to @@ -144,7 +144,7 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p */ if(strequal(work_name, global_myname())) - nstrcpy(work_name,lp_workgroup()); + fstrcpy(work_name,lp_workgroup()); /* * We are being very agressive here in adding a workgroup @@ -198,19 +198,19 @@ void process_workgroup_announce(struct subnet_record *subrec, struct packet_stru { struct dgram_packet *dgram = &p->packet.dgram; int ttl = IVAL(buf,1)/1000; - nstring workgroup_announce_name; - nstring master_name; + fstring workgroup_announce_name; + fstring master_name; uint32 servertype = IVAL(buf,23); struct work_record *work; - nstring source_name; - nstring dest_name; + fstring source_name; + fstring dest_name; START_PROFILE(workgroup_announce); - pull_ascii_nstring(workgroup_announce_name,buf+5); - pull_ascii_nstring(master_name,buf+31); - pull_ascii_nstring(source_name,dgram->source_name.name); - pull_ascii_nstring(dest_name,dgram->dest_name.name); + pull_ascii_nstring(workgroup_announce_name,sizeof(workgroup_announce_name),buf+5); + pull_ascii_nstring(master_name,sizeof(master_name),buf+31); + pull_ascii_nstring(source_name,sizeof(source_name),dgram->source_name.name); + pull_ascii_nstring(dest_name,sizeof(dest_name),dgram->dest_name.name); DEBUG(3,("process_workgroup_announce: from %s<%02x> IP %s to \ %s for workgroup %s.\n", source_name, source_name[15], inet_ntoa(p->ip), @@ -255,21 +255,21 @@ void process_local_master_announce(struct subnet_record *subrec, struct packet_s { struct dgram_packet *dgram = &p->packet.dgram; int ttl = IVAL(buf,1)/1000; - nstring server_name; + fstring server_name; uint32 servertype = IVAL(buf,23); fstring comment; - nstring work_name; + fstring work_name; struct work_record *work; struct server_record *servrec; - nstring source_name; + fstring source_name; START_PROFILE(local_master_announce); - pull_ascii_nstring(server_name,buf+5); + pull_ascii_nstring(server_name,sizeof(server_name),buf+5); pull_ascii_fstring(comment, buf+31); comment[42] = 0; - pull_ascii_nstring(source_name, dgram->source_name.name); - pull_ascii_nstring(work_name, dgram->dest_name.name); + pull_ascii_nstring(source_name, sizeof(source_name), dgram->source_name.name); + pull_ascii_nstring(work_name, sizeof(work_name), dgram->dest_name.name); DEBUG(3,("process_local_master_announce: from %s<%02x> IP %s to \ %s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip), @@ -369,13 +369,13 @@ done: void process_master_browser_announce(struct subnet_record *subrec, struct packet_struct *p,char *buf) { - nstring local_master_name; + fstring local_master_name; struct work_record *work; struct browse_cache_record *browrec; START_PROFILE(master_browser_announce); - pull_ascii_nstring(local_master_name,buf); + pull_ascii_nstring(local_master_name,sizeof(local_master_name),buf); DEBUG(3,("process_master_browser_announce: Local master announce from %s IP %s.\n", local_master_name, inet_ntoa(p->ip))); @@ -425,11 +425,11 @@ void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct int osmajor=CVAL(buf,5); /* major version of node software */ int osminor=CVAL(buf,6); /* minor version of node software */ int ttl = SVAL(buf,7); - nstring announce_name; + fstring announce_name; struct work_record *work; struct server_record *servrec; - nstring work_name; - nstring source_name; + fstring work_name; + fstring source_name; fstring comment; char *s = buf+9; @@ -437,10 +437,10 @@ void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct s = skip_string(s,1); pull_ascii(comment, s, sizeof(fstring), 43, STR_TERMINATE); - pull_ascii_nstring(announce_name,buf+9); - pull_ascii_nstring(source_name,dgram->source_name.name); + pull_ascii_nstring(announce_name,sizeof(announce_name),buf+9); + pull_ascii_nstring(source_name,sizeof(source_name),dgram->source_name.name); /* For a LanMan host announce the workgroup name is the destination name. */ - pull_ascii_nstring(work_name,dgram->dest_name.name); + pull_ascii_nstring(work_name,sizeof(work_name),dgram->dest_name.name); DEBUG(3,("process_lm_host_announce: LM Announcement from %s IP %s to \ %s for server %s.\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), @@ -479,7 +479,7 @@ originate from OS/2 Warp client. Ignoring packet.\n")); */ if(strequal(work_name, global_myname())) - nstrcpy(work_name,lp_workgroup()); + fstrcpy(work_name,lp_workgroup()); /* * We are being very agressive here in adding a workgroup @@ -541,7 +541,7 @@ static void send_backup_list_response(struct subnet_record *subrec, char outbuf[1024]; char *p, *countptr; unsigned int count = 0; - nstring send_to_namestr; + fstring send_to_namestr; #if 0 struct server_record *servrec; #endif @@ -612,7 +612,7 @@ static void send_backup_list_response(struct subnet_record *subrec, SCVAL(countptr, 0, count); - pull_ascii_nstring(send_to_namestr, send_to_name->name); + pull_ascii_nstring(send_to_namestr, sizeof(send_to_namestr), send_to_name->name); DEBUG(4,("send_backup_list_response: sending response to %s<00> IP %s with %d servers.\n", send_to_namestr, inet_ntoa(sendto_ip), count)); @@ -642,11 +642,11 @@ void process_get_backup_list_request(struct subnet_record *subrec, unsigned char max_number_requested = CVAL(buf,0); uint32 token = IVAL(buf,1); /* Sender's key index for the workgroup. */ int name_type = dgram->dest_name.name_type; - nstring workgroup_name; + fstring workgroup_name; struct subnet_record *search_subrec = subrec; START_PROFILE(get_backup_list); - pull_ascii_nstring(workgroup_name, dgram->dest_name.name); + pull_ascii_nstring(workgroup_name, sizeof(workgroup_name), dgram->dest_name.name); DEBUG(3,("process_get_backup_list_request: request from %s IP %s to %s.\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), @@ -774,11 +774,11 @@ void process_announce_request(struct subnet_record *subrec, struct packet_struct { struct dgram_packet *dgram = &p->packet.dgram; struct work_record *work; - nstring workgroup_name; + fstring workgroup_name; START_PROFILE(announce_request); - pull_ascii_nstring(workgroup_name, dgram->dest_name.name); + pull_ascii_nstring(workgroup_name, sizeof(workgroup_name), dgram->dest_name.name); DEBUG(3,("process_announce_request: Announce request from %s IP %s to %s.\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name))); @@ -814,11 +814,11 @@ done: void process_lm_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf) { struct dgram_packet *dgram = &p->packet.dgram; - nstring workgroup_name; + fstring workgroup_name; START_PROFILE(lm_announce_request); - pull_ascii_nstring(workgroup_name, dgram->dest_name.name); + pull_ascii_nstring(workgroup_name, sizeof(workgroup_name), dgram->dest_name.name); DEBUG(3,("process_lm_announce_request: Announce request from %s IP %s to %s.\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name))); diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index dd999fbdf7..d43cefc0df 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -58,7 +58,7 @@ void process_name_release_request(struct subnet_record *subrec, struct nmb_packet *nmb = &p->packet.nmb; struct in_addr owner_ip; struct nmb_name *question = &nmb->question.question_name; - nstring qname; + fstring qname; BOOL bcast = nmb->header.nm_flags.bcast; uint16 nb_flags = get_nb_flags(nmb->additional->rdata); BOOL group = (nb_flags & NB_GROUP) ? True : False; @@ -98,7 +98,7 @@ subnet %s from owner IP %s\n", * names and *don't set the group bit* !!!!! */ - pull_ascii_nstring(qname, question->name); + pull_ascii_nstring(qname, sizeof(qname), question->name); if( !group && !ismyip(owner_ip) && strequal(qname, lp_workgroup()) && ((question->name_type == 0x0) || (question->name_type == 0x1e))) { DEBUG(6,("process_name_release_request: FTP OnNet bug workaround. Ignoring \ @@ -275,11 +275,13 @@ We put our own names first, then in alphabetical order. static int status_compare(char *n1,char *n2) { - nstring name1, name2; + fstring name1, name2; int l1,l2,l3; - pull_ascii_nstring(name1, n1); - pull_ascii_nstring(name2, n2); + memset(name1, '\0', sizeof(name1)); + memset(name2, '\0', sizeof(name2)); + pull_ascii_nstring(name1, sizeof(name1), n1); + pull_ascii_nstring(name2, sizeof(name2), n2); n1 = name1; n2 = name2; @@ -298,7 +300,7 @@ static int status_compare(char *n1,char *n2) (l1!=l3 || strncmp(n1,global_myname(),l3) != 0)) return 1; - return memcmp(n1,n2,sizeof(nstring)); + return memcmp(n1,n2,sizeof(fstring)); } /**************************************************************************** @@ -308,14 +310,14 @@ static int status_compare(char *n1,char *n2) void process_node_status_request(struct subnet_record *subrec, struct packet_struct *p) { struct nmb_packet *nmb = &p->packet.nmb; - nstring qname; + fstring qname; int ques_type = nmb->question.question_name.name_type; char rdata[MAX_DGRAM_SIZE]; char *countptr, *buf, *bufend, *buf0; int names_added,i; struct name_record *namerec; - pull_ascii_nstring(qname, nmb->question.question_name.name); + pull_ascii_nstring(qname, sizeof(qname), nmb->question.question_name.name); DEBUG(3,("process_node_status_request: status request for name %s from IP %s on \ subnet %s.\n", nmb_namestr(&nmb->question.question_name), inet_ntoa(p->ip), subrec->subnet_name)); @@ -342,9 +344,9 @@ subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name), while (buf < bufend) { if( (namerec->data.source == SELF_NAME) || (namerec->data.source == PERMANENT_NAME) ) { int name_type = namerec->name.name_type; - nstring name; + fstring name; - pull_ascii_nstring(name, namerec->name.name); + pull_ascii_nstring(name, sizeof(name), namerec->name.name); strupper_m(name); if (!strequal(name,"*") && !strequal(name,"__SAMBA__") && @@ -352,10 +354,11 @@ subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name), ques_type < 0x1b || ques_type >= 0x20 || strequal(qname, name))) { /* Start with the name. */ - nstring tmp_name; - memset(tmp_name,'\0',sizeof(tmp_name)); - snprintf(tmp_name, sizeof(tmp_name), "%-15.15s",name); - push_ascii_nstring(buf, tmp_name); + size_t len; + push_ascii_nstring(buf, name); + len = strlen(buf); + memset(buf + len, ' ', MAX_NETBIOSNAME_LEN - len - 1); + buf[MAX_NETBIOSNAME_LEN - 1] = '\0'; /* Put the name type and netbios flags in the buffer. */ diff --git a/source3/nmbd/nmbd_logonnames.c b/source3/nmbd/nmbd_logonnames.c index f79fc56f7b..b6e841139f 100644 --- a/source3/nmbd/nmbd_logonnames.c +++ b/source3/nmbd/nmbd_logonnames.c @@ -35,11 +35,11 @@ static void become_logon_server_fail(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *fail_name) { - nstring failname; + fstring failname; struct work_record *work; struct server_record *servrec; - pull_ascii_nstring(failname, fail_name->name); + pull_ascii_nstring(failname, sizeof(failname), fail_name->name); work = find_workgroup_on_subnet(subrec, failname); if(!work) { DEBUG(0,("become_logon_server_fail: Error - cannot find \ @@ -76,11 +76,11 @@ static void become_logon_server_success(struct subnet_record *subrec, uint16 nb_flags, int ttl, struct in_addr registered_ip) { - nstring reg_name; + fstring reg_name; struct work_record *work; struct server_record *servrec; - pull_ascii_nstring(reg_name, registered_name->name); + pull_ascii_nstring(reg_name, sizeof(reg_name), registered_name->name); work = find_workgroup_on_subnet( subrec, reg_name); if(!work) { DEBUG(0,("become_logon_server_success: Error - cannot find \ diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index f02fbe1640..83a8361ed9 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -93,8 +93,8 @@ static void insert_refresh_name_into_unicast( struct subnet_record *subrec, } if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) == NULL) { - nstring name; - pull_ascii_nstring(name, nmbname->name); + fstring name; + pull_ascii_nstring(name, sizeof(name), nmbname->name); /* The name needs to be created on the unicast subnet. */ (void)add_name_to_subnet( unicast_subnet, name, nmbname->name_type, nb_type, diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index d1c9afd608..9f89abdbb2 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -45,13 +45,13 @@ void set_samba_nb_type(void) static void upcase_name( struct nmb_name *target, struct nmb_name *source ) { int i; - nstring targ; + fstring targ; fstring scope; if( NULL != source ) memcpy( target, source, sizeof( struct nmb_name ) ); - pull_ascii_nstring(targ, target->name); + pull_ascii_nstring(targ, sizeof(targ), target->name); strupper_m( targ ); push_ascii_nstring( target->name, targ); @@ -255,8 +255,8 @@ void standard_success_register(struct subnet_record *subrec, namerec = find_name_on_subnet( subrec, nmbname, FIND_SELF_NAME ); if( NULL == namerec ) { - nstring name; - pull_ascii_nstring(name, nmbname->name); + fstring name; + pull_ascii_nstring(name, sizeof(name), nmbname->name); add_name_to_subnet( subrec, name, nmbname->name_type, nb_flags, ttl, SELF_NAME, 1, ®istered_ip ); } else { diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index 0397f56512..4fbdd143e1 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -85,8 +85,8 @@ static void register_name_response(struct subnet_record *subrec, */ #if 1 /* OLD_SAMBA_SERVER_HACK */ - nstring ans_name; - pull_ascii_nstring(ans_name, answer_name->name); + fstring ans_name; + pull_ascii_nstring(ans_name, sizeof(ans_name), answer_name->name); if((nmb->header.rcode == ACT_ERR) && strequal(lp_workgroup(), ans_name) && (answer_name->name_type == 0x1b)) { /* Pretend we did not get this. */ @@ -418,7 +418,7 @@ static void multihomed_register_name(struct nmb_name *nmbname, uint16 nb_flags, struct subnet_record *subrec; char **wins_tags; struct in_addr *ip_list; - nstring name; + fstring name; for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) ) num_ips++; @@ -434,7 +434,7 @@ static void multihomed_register_name(struct nmb_name *nmbname, uint16 nb_flags, ip_list[i] = subrec->myip; } - pull_ascii_nstring(name, nmbname->name); + pull_ascii_nstring(name, sizeof(name), nmbname->name); add_name_to_subnet(unicast_subnet, name, nmbname->name_type, nb_flags, lp_max_ttl(), SELF_NAME, num_ips, ip_list); @@ -473,17 +473,18 @@ void register_name(struct subnet_record *subrec, struct nmb_name nmbname; nstring nname; - if (strlen(name)+1 > sizeof(nstring)) { - memcpy(nname, name,sizeof(nstring)-1); - nname[sizeof(nstring)-1] = '\0'; + errno = 0; + push_ascii_nstring(nname, name); + if (errno == E2BIG) { + fstring tname; + pull_ascii_nstring(tname, sizeof(tname), nname); DEBUG(0,("register_name: NetBIOS name %s is too long. Truncating to %s\n", - name, nname)); + name, tname)); + make_nmb_name(&nmbname, tname, type); } else { - nstrcpy(nname,name); + make_nmb_name(&nmbname, name, type); } - make_nmb_name(&nmbname, nname, type); - /* Always set the NB_ACTIVE flag on the name we are registering. Doesn't make sense without it. */ diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index c318689fd1..b5cbaab00b 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1034,7 +1034,7 @@ static void process_browse_packet(struct packet_struct *p, char *buf,int len) int command = CVAL(buf,0); struct subnet_record *subrec = find_subnet_for_dgram_browse_packet(p); char scope[64]; - nstring src_name; + fstring src_name; /* Drop the packet if it's a different NetBIOS scope, or the source is from one of our names. */ pull_ascii(scope, dgram->dest_name.scope, 64, 64, STR_TERMINATE); @@ -1044,7 +1044,7 @@ mismatch with our scope (%s).\n", inet_ntoa(p->ip), scope, global_scope())); return; } - pull_ascii_nstring(src_name, dgram->source_name.name); + pull_ascii_nstring(src_name, sizeof(src_name), dgram->source_name.name); if (is_myname(src_name)) { DEBUG(0,("process_browse_packet: Discarding datagram from IP %s. Source name \ %s is one of our names !\n", inet_ntoa(p->ip), nmb_namestr(&dgram->source_name))); @@ -1121,7 +1121,7 @@ static void process_lanman_packet(struct packet_struct *p, char *buf,int len) int command = SVAL(buf,0); struct subnet_record *subrec = find_subnet_for_dgram_browse_packet(p); char scope[64]; - nstring src_name; + fstring src_name; /* Drop the packet if it's a different NetBIOS scope, or the source is from one of our names. */ @@ -1132,7 +1132,7 @@ mismatch with our scope (%s).\n", inet_ntoa(p->ip), scope, global_scope())); return; } - pull_ascii_nstring(src_name, dgram->source_name.name); + pull_ascii_nstring(src_name, sizeof(src_name), dgram->source_name.name); if (is_myname(src_name)) { DEBUG(0,("process_lanman_packet: Discarding datagram from IP %s. Source name \ %s is one of our names !\n", inet_ntoa(p->ip), nmb_namestr(&dgram->source_name))); diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 7350d8237f..617a7be6cb 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -141,7 +141,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); case QUERYFORPDC: { fstring mach_str, getdc_str; - nstring source_name; + fstring source_name; char *q = buf + 2; char *machine = q; @@ -220,7 +220,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", dump_data(4, outbuf, PTR_DIFF(q, outbuf)); pull_ascii_fstring(getdc_str, getdc); - pull_ascii_nstring(source_name, dgram->source_name.name); + pull_ascii_nstring(source_name, sizeof(source_name), dgram->source_name.name); send_mailslot(True, getdc_str, outbuf,PTR_DIFF(q,outbuf), @@ -432,7 +432,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", dump_data(4, outbuf, PTR_DIFF(q, outbuf)); pull_ascii_fstring(getdc_str, getdc); - pull_ascii_nstring(source_name, dgram->source_name.name); + pull_ascii_nstring(source_name, sizeof(source_name), dgram->source_name.name); send_mailslot(True, getdc, outbuf,PTR_DIFF(q,outbuf), diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 6a0576a5a4..424af1e2e3 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -31,8 +31,8 @@ struct sync_record { struct sync_record *next, *prev; - nstring workgroup; - nstring server; + fstring workgroup; + fstring server; pstring fname; struct in_addr ip; pid_t pid; @@ -148,8 +148,8 @@ done: ZERO_STRUCTP(s); - nstrcpy(s->workgroup, work->work_group); - nstrcpy(s->server, name); + fstrcpy(s->workgroup, work->work_group); + fstrcpy(s->server, name); s->ip = ip; slprintf(s->fname, sizeof(pstring)-1, @@ -206,7 +206,7 @@ static void complete_one(struct sync_record *s, sname, lp_max_ttl()); if (work) { /* remember who the master is */ - nstrcpy(work->local_master_browser_name, comment); + fstrcpy(work->local_master_browser_name, comment); } } return; diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index bace112752..d91818698e 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -30,7 +30,7 @@ static void wins_proxy_name_query_request_success( struct subnet_record *subrec, struct userdata_struct *userdata, struct nmb_name *nmbname, struct in_addr ip, struct res_rec *rrec) { - nstring name; + fstring name; struct packet_struct *original_packet; struct subnet_record *orig_broadcast_subnet; struct name_record *namerec; @@ -73,7 +73,7 @@ returned for name %s.\n", nmb_namestr(nmbname) )); if(rrec == PERMANENT_TTL) ttl = lp_max_ttl(); - pull_ascii_nstring(name, nmbname->name); + pull_ascii_nstring(name, sizeof(name), nmbname->name); namerec = add_name_to_subnet( orig_broadcast_subnet, name, nmbname->name_type, nb_flags, ttl, WINS_PROXY_NAME, num_ips, iplist ); @@ -193,7 +193,7 @@ void make_wins_proxy_name_query_request( struct subnet_record *subrec, long *ud[(sizeof(struct userdata_struct) + sizeof(struct subrec *) + sizeof(struct packet_struct *))/sizeof(long *) + 1]; struct userdata_struct *userdata = (struct userdata_struct *)ud; - nstring qname; + fstring qname; memset(ud, '\0', sizeof(ud)); @@ -205,7 +205,7 @@ void make_wins_proxy_name_query_request( struct subnet_record *subrec, sizeof(struct packet_struct *)); /* Now use the unicast subnet to query the name with the WINS server. */ - pull_ascii_nstring(qname, question_name->name); + pull_ascii_nstring(qname, sizeof(qname), question_name->name); query_name( unicast_subnet, qname, question_name->name_type, wins_proxy_name_query_request_success, wins_proxy_name_query_request_fail, diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 3694072420..7279014194 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -704,7 +704,7 @@ querying for name %s in order to replace it and this reply.\n", nmb_namestr(ques void wins_process_name_registration_request(struct subnet_record *subrec, struct packet_struct *p) { - nstring name; + fstring name; struct nmb_packet *nmb = &p->packet.nmb; struct nmb_name *question = &nmb->question.question_name; BOOL bcast = nmb->header.nm_flags.bcast; @@ -866,7 +866,7 @@ already exists in WINS as a GROUP name.\n", nmb_namestr(question) )); */ if ( namerec != NULL ) - pull_ascii_nstring(name, namerec->name.name); + pull_ascii_nstring(name, sizeof(name), namerec->name.name); if( is_myname(name) ) { if(!ismyip(from_ip)) { @@ -943,7 +943,7 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio * code. JRA. */ - pull_ascii_nstring(name, question->name); + pull_ascii_nstring(name, sizeof(name), question->name); query_name_from_wins_server( *namerec->data.ip, name, question->name_type, @@ -957,7 +957,7 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio * Name did not exist - add it. */ - pull_ascii_nstring(name, question->name); + pull_ascii_nstring(name, sizeof(name), question->name); add_name_to_subnet( subrec, name, question->name_type, nb_flags, ttl, REGISTER_NAME, 1, &from_ip); @@ -1079,7 +1079,7 @@ void wins_process_multihomed_name_registration_request( struct subnet_record *su struct in_addr from_ip; BOOL group = (nb_flags & NB_GROUP) ? True : False; struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); - nstring qname; + fstring qname; putip((char *)&from_ip,&nmb->additional->rdata[2]); @@ -1278,7 +1278,7 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio * not the person who sent the packet */ - pull_ascii_nstring( qname, question->name); + pull_ascii_nstring( qname, sizeof(qname), question->name); query_name_from_wins_server( namerec->data.ip[0], qname, question->name_type, @@ -1293,7 +1293,7 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio * Name did not exist - add it. */ - pull_ascii_nstring( qname, question->name); + pull_ascii_nstring( qname, sizeof(qname), question->name); add_name_to_subnet( subrec, qname, question->name_type, nb_flags, ttl, REGISTER_NAME, 1, &from_ip); @@ -1439,7 +1439,7 @@ void wins_process_name_query_request(struct subnet_record *subrec, struct nmb_packet *nmb = &p->packet.nmb; struct nmb_name *question = &nmb->question.question_name; struct name_record *namerec = NULL; - nstring qname; + fstring qname; DEBUG(3,("wins_process_name_query: name query for name %s from IP %s\n", nmb_namestr(question), inet_ntoa(p->ip) )); @@ -1451,7 +1451,7 @@ void wins_process_name_query_request(struct subnet_record *subrec, * to discover other domains that may not have a presence on their subnet. */ - pull_ascii_nstring(qname, question->name); + pull_ascii_nstring(qname, sizeof(qname), question->name); if(strequal( qname, "*") && (question->name_type == 0x1b)) { process_wins_dmb_query_request( subrec, p); return; @@ -1805,8 +1805,8 @@ void wins_write_database(BOOL background) DEBUGADD(4,("%2x\n", namerec->data.nb_flags )); if( namerec->data.source == REGISTER_NAME ) { - nstring name; - pull_ascii_nstring(name, namerec->name.name); + fstring name; + pull_ascii_nstring(name, sizeof(name), namerec->name.name); x_fprintf(fp, "\"%s#%02x\" %d ", name,namerec->name.name_type, /* Ignore scope. */ (int)namerec->data.death_time); diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index b9fab4b278..bd2737ef97 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -48,6 +48,8 @@ static struct work_record *create_workgroup(const char *name, int ttl) { struct work_record *work; struct subnet_record *subrec; + nstring nname; + int t = -1; if((work = (struct work_record *)malloc(sizeof(*work))) == NULL) { @@ -55,15 +57,18 @@ static struct work_record *create_workgroup(const char *name, int ttl) return NULL; } memset((char *)work, '\0', sizeof(*work)); - - if (strlen(name)+1 > sizeof(nstring)) { - memcpy(work->work_group,name,sizeof(nstring)-1); - work->work_group[sizeof(nstring)-1] = '\0'; - DEBUG(0,("create_workgroup: workgroup name %s is too long. Truncating to %s\n", - name, work->work_group )); - } else { - nstrcpy(work->work_group,name); - } + + errno = 0; + push_ascii_nstring(nname, name); + if (errno == E2BIG) { + fstring tname; + pull_ascii_nstring(tname, sizeof(tname), nname); + fstrcpy(work->work_group,tname); + DEBUG(0,("create_workgroup: workgroup name %s is too long. Truncating to %s\n", + name, tname)); + } else { + fstrcpy(work->work_group,name); + } work->serverlist = NULL; work->RunningElection = False; -- cgit From a0034d3586dadfddc18e4a3096564bf158d43e4e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 13 Mar 2004 02:47:21 +0000 Subject: Ensure we don't truncate strcmps to nstring anymore... Jeremy. (This used to be commit d7cf64b1e4e501bcd01ddc8279babc65d894a4b3) --- source3/nmbd/nmbd_browsesync.c | 4 ++-- source3/nmbd/nmbd_elections.c | 8 ++++---- source3/nmbd/nmbd_serverlistdb.c | 2 +- source3/nmbd/nmbd_workgroupdb.c | 6 +++--- 4 files changed, 10 insertions(+), 10 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 454c349767..f16d8603c9 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -639,14 +639,14 @@ void sync_all_dmbs(time_t t) /* count how many syncs we might need to do */ for (work=unicast_subnet->workgrouplist; work; work = work->next) { - if (strncmp(lp_workgroup(), work->work_group, sizeof(nstring))) { + if (strcmp(lp_workgroup(), work->work_group)) { count++; } } /* sync with a probability of 1/count */ for (work=unicast_subnet->workgrouplist; work; work = work->next) { - if (strncmp(lp_workgroup(), work->work_group, sizeof(nstring))) { + if (strcmp(lp_workgroup(), work->work_group)) { fstring dmb_name; if (((unsigned)sys_random()) % count != 0) diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 882c26ce80..24026d7cd9 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -97,7 +97,7 @@ static void check_for_master_browser_fail( struct subnet_record *subrec, return; } - if (strnequal(work->work_group, lp_workgroup(), sizeof(nstring)-1)) { + if (strequal(work->work_group, lp_workgroup())) { if (lp_local_master()) { /* We have discovered that there is no local master @@ -145,7 +145,7 @@ void check_master_browser_exists(time_t t) struct work_record *work; for (work = subrec->workgrouplist; work; work = work->next) { - if (strnequal(work->work_group, workgroup_name, sizeof(nstring)-1) && !AM_LOCAL_MASTER_BROWSER(work)) { + if (strequal(work->work_group, workgroup_name) && !AM_LOCAL_MASTER_BROWSER(work)) { /* Do a name query for the local master browser on this net. */ query_name( subrec, work->work_group, 0x1d, check_for_master_browser_success, @@ -284,7 +284,7 @@ void process_election(struct subnet_record *subrec, struct packet_struct *p, cha goto done; } - if (!strnequal(work->work_group, lp_workgroup(), sizeof(nstring)-1)) { + if (!strequal(work->work_group, lp_workgroup())) { DEBUG(3,("process_election: ignoring election request for workgroup %s on subnet %s as this \ is not my workgroup.\n", work->work_group, subrec->subnet_name )); goto done; @@ -381,7 +381,7 @@ void nmbd_message_election(int msg_type, pid_t src, void *buf, size_t len) for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { struct work_record *work; for (work = subrec->workgrouplist; work; work = work->next) { - if (strnequal(work->work_group, lp_workgroup(), sizeof(nstring)-1)) { + if (strequal(work->work_group, lp_workgroup())) { work->needelection = True; work->ElectionCount=0; work->mst_state = lp_local_master() ? MST_POTENTIAL : MST_NONE; diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index cdb1089a54..e6fad8319d 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -251,7 +251,7 @@ static uint32 write_this_workgroup_name( struct subnet_record *subrec, { struct subnet_record *ssub; - if(strnequal(lp_workgroup(), work->work_group, sizeof(nstring)-1)) + if(strequal(lp_workgroup(), work->work_group)) return 0; /* This is a workgroup we have seen on a broadcast subnet. All diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index bd2737ef97..3efef49c04 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -88,7 +88,7 @@ static struct work_record *create_workgroup(const char *name, int ttl) for (subrec = FIRST_SUBNET; subrec && (t == -1); subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { struct work_record *w; for (w = subrec->workgrouplist; w && t == -1; w = w->next) { - if (strnequal(w->work_group, work->work_group, sizeof(nstring)-1)) + if (strequal(w->work_group, work->work_group)) t = w->token; } } @@ -162,7 +162,7 @@ struct work_record *find_workgroup_on_subnet(struct subnet_record *subrec, name, subrec->subnet_name)); for (ret = subrec->workgrouplist; ret; ret = ret->next) { - if (strnequal(ret->work_group,name,sizeof(nstring)-1)) { + if (strequal(ret->work_group,name)) { DEBUGADD(4, ("found.\n")); return(ret); } @@ -223,7 +223,7 @@ void initiate_myworkgroup_startup(struct subnet_record *subrec, struct work_reco { int i; - if(!strnequal(lp_workgroup(), work->work_group,sizeof(nstring)-1)) + if(!strequal(lp_workgroup(), work->work_group)) return; /* If this is a broadcast subnet then start elections on it if we are so configured. */ -- cgit From ce0c99312c7da78679357610730ba5b60f4319b9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 15 Mar 2004 21:45:45 +0000 Subject: Use "unix netbios name" type unstring - 64 bytes long to manipulate netbios names in nmbd. Allows conversion from dos codepage mb strings (ie. SJIS) to expand to utf8 size on read. Jeremy. (This used to be commit 834d816caf9cd6318da00febde50d9233469dac2) --- source3/nmbd/asyncdns.c | 9 ++++---- source3/nmbd/nmbd_become_dmb.c | 8 +++---- source3/nmbd/nmbd_become_lmb.c | 12 +++++----- source3/nmbd/nmbd_browserdb.c | 4 ++-- source3/nmbd/nmbd_browsesync.c | 22 +++++++++--------- source3/nmbd/nmbd_elections.c | 12 +++++----- source3/nmbd/nmbd_incomingdgrams.c | 44 ++++++++++++++++++------------------ source3/nmbd/nmbd_incomingrequests.c | 10 ++++---- source3/nmbd/nmbd_logonnames.c | 4 ++-- source3/nmbd/nmbd_mynames.c | 2 +- source3/nmbd/nmbd_namelistdb.c | 4 ++-- source3/nmbd/nmbd_nameregister.c | 6 ++--- source3/nmbd/nmbd_packets.c | 4 ++-- source3/nmbd/nmbd_processlogon.c | 4 ++-- source3/nmbd/nmbd_sendannounce.c | 4 ++-- source3/nmbd/nmbd_synclists.c | 12 +++++----- source3/nmbd/nmbd_winsproxy.c | 4 ++-- source3/nmbd/nmbd_winsserver.c | 8 +++---- source3/nmbd/nmbd_workgroupdb.c | 6 ++--- 19 files changed, 89 insertions(+), 90 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index dafbff7af2..653cb97fbb 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -27,7 +27,7 @@ static struct name_record *add_dns_result(struct nmb_name *question, struct in_addr addr) { int name_type = question->name_type; - fstring qname; + unstring qname; pull_ascii_nstring(qname, sizeof(qname), question->name); @@ -81,7 +81,7 @@ int asyncdns_fd(void) static void asyncdns_process(void) { struct query_record r; - fstring qname; + unstring qname; DEBUGLEVEL = -1; @@ -89,8 +89,7 @@ static void asyncdns_process(void) if (read_data(fd_in, (char *)&r, sizeof(r)) != sizeof(r)) break; - fstrcpy(qname, r.name.name); - + pull_ascii_nstring( qname, sizeof(qname), r.name.name); r.result.s_addr = interpret_addr(qname); if (write_data(fd_out, (char *)&r, sizeof(r)) != sizeof(r)) @@ -321,7 +320,7 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, struct name_record **n) { struct in_addr dns_ip; - nstring qname; + unstring qname; pull_ascii_nstring(qname, question->name); diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index c9b0a22580..fb1fb33a81 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -37,7 +37,7 @@ static void become_domain_master_fail(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *fail_name) { - fstring failname; + unstring failname; struct work_record *work; struct server_record *servrec; @@ -80,7 +80,7 @@ static void become_domain_master_stage2(struct subnet_record *subrec, uint16 nb_flags, int ttl, struct in_addr registered_ip) { - fstring regname; + unstring regname; struct work_record *work; struct server_record *servrec; @@ -200,7 +200,7 @@ static void become_domain_master_query_success(struct subnet_record *subrec, struct nmb_name *nmbname, struct in_addr ip, struct res_rec *rrec) { - fstring name; + unstring name; pull_ascii_nstring(name, sizeof(name), nmbname->name); /* If the given ip is not ours, then we can't become a domain @@ -241,7 +241,7 @@ static void become_domain_master_query_fail(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *question_name, int fail_code) { - fstring name; + unstring name; /* If the query was unicast, and the error is not NAM_ERR (name didn't exist), then this is a failure. Otherwise, not finding the name is what we want. */ diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index 8d66320f3e..c536deb6f4 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -33,7 +33,7 @@ extern uint16 samba_nb_type; /* Samba's NetBIOS name type. */ void insert_permanent_name_into_unicast( struct subnet_record *subrec, struct nmb_name *nmbname, uint16 nb_type ) { - fstring name; + unstring name; struct name_record *namerec; if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) == NULL) { @@ -135,7 +135,7 @@ static void unbecome_local_master_success(struct subnet_record *subrec, struct in_addr released_ip) { BOOL force_new_election = False; - fstring relname; + unstring relname; memcpy((char *)&force_new_election, userdata->data, sizeof(BOOL)); @@ -166,7 +166,7 @@ static void unbecome_local_master_fail(struct subnet_record *subrec, struct resp struct name_record *namerec; struct userdata_struct *userdata = rrec->userdata; BOOL force_new_election = False; - fstring failname; + unstring failname; memcpy((char *)&force_new_election, userdata->data, sizeof(BOOL)); @@ -330,7 +330,7 @@ static void become_local_master_stage2(struct subnet_record *subrec, struct server_record *sl; struct work_record *work; struct server_record *servrec; - fstring regname; + unstring regname; pull_ascii_nstring(regname, sizeof(regname), registered_name->name); work = find_workgroup_on_subnet( subrec, regname); @@ -410,7 +410,7 @@ static void become_local_master_fail2(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *fail_name) { - fstring failname; + unstring failname; struct work_record *work; DEBUG(0,("become_local_master_fail2: failed to register name %s on subnet %s. \ @@ -590,5 +590,5 @@ local_master_browser_name for workgroup %s to workgroup name.\n", } #endif - fstrcpy(work->local_master_browser_name, newname); + unstrcpy(work->local_master_browser_name, newname); } diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c index d781259156..c92513fae8 100644 --- a/source3/nmbd/nmbd_browserdb.c +++ b/source3/nmbd/nmbd_browserdb.c @@ -106,8 +106,8 @@ struct browse_cache_record *create_browser_in_lmb_cache( const char *work_name, /* Allow the new lmb to miss an announce period before we remove it. */ browc->death_time = now + ( (CHECK_TIME_MST_ANNOUNCE + 2) * 60 ); - fstrcpy( browc->lmb_name, browser_name); - fstrcpy( browc->work_group, work_name); + unstrcpy( browc->lmb_name, browser_name); + unstrcpy( browc->work_group, work_name); strupper_m( browc->lmb_name ); strupper_m( browc->work_group ); diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index f16d8603c9..15827e21ba 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -102,7 +102,7 @@ As a local master browser, send an announce packet to the domain master browser. static void announce_local_master_browser_to_domain_master_browser( struct work_record *work) { pstring outbuf; - fstring myname; + unstring myname; char *p; if(ismyip(work->dmb_addr)) { @@ -120,7 +120,7 @@ static void announce_local_master_browser_to_domain_master_browser( struct work_ SCVAL(p,0,ANN_MasterAnnouncement); p++; - fstrcpy(myname, global_myname()); + unstrcpy(myname, global_myname()); strupper_m(myname); myname[15]='\0'; /* The call below does CH_UNIX -> CH_DOS conversion. JRA */ @@ -146,7 +146,7 @@ As a local master browser, do a sync with a domain master browser. static void sync_with_dmb(struct work_record *work) { - fstring dmb_name; + unstring dmb_name; if( DEBUGLVL( 2 ) ) { dbgtext( "sync_with_dmb:\n" ); @@ -156,7 +156,7 @@ static void sync_with_dmb(struct work_record *work) dbgtext( "for workgroup %s\n", work->work_group ); } - pull_ascii_nstring(dmb_name, sizeof(fstring), work->dmb_name.name); + pull_ascii_nstring(dmb_name, sizeof(dmb_name), work->dmb_name.name); sync_browse_lists(work, dmb_name, work->dmb_name.name_type, work->dmb_addr, False, True); } @@ -197,7 +197,7 @@ static void domain_master_node_status_success(struct subnet_record *subrec, p += 1; while (numnames--) { - fstring qname; + unstring qname; uint16 nb_flags; int name_type; @@ -278,7 +278,7 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec, struct nmb_name nmbname; struct userdata_struct *userdata; size_t size = sizeof(struct userdata_struct) + sizeof(fstring)+1; - fstring qname; + unstring qname; pull_ascii_nstring(qname, sizeof(qname), q_name->name); if( !(work = find_workgroup_on_subnet(subrec, qname)) ) { @@ -399,7 +399,7 @@ static void get_domain_master_name_node_status_success(struct subnet_record *sub struct in_addr from_ip) { struct work_record *work; - fstring server_name; + unstring server_name; server_name[0] = 0; @@ -420,7 +420,7 @@ static void get_domain_master_name_node_status_success(struct subnet_record *sub p += 1; while (numnames--) { - fstring qname; + unstring qname; uint16 nb_flags; int name_type; @@ -434,7 +434,7 @@ static void get_domain_master_name_node_status_success(struct subnet_record *sub if(!(nb_flags & NB_GROUP) && (name_type == 0x00) && server_name[0] == 0) { /* this is almost certainly the server netbios name */ - fstrcpy(server_name, qname); + unstrcpy(server_name, qname); continue; } @@ -460,7 +460,7 @@ static void get_domain_master_name_node_status_success(struct subnet_record *sub return; /* remember who the master is */ - fstrcpy(work->local_master_browser_name, server_name); + unstrcpy(work->local_master_browser_name, server_name); make_nmb_name(&nmbname, server_name, 0x20); work->dmb_name = nmbname; work->dmb_addr = from_ip; @@ -647,7 +647,7 @@ void sync_all_dmbs(time_t t) /* sync with a probability of 1/count */ for (work=unicast_subnet->workgrouplist; work; work = work->next) { if (strcmp(lp_workgroup(), work->work_group)) { - fstring dmb_name; + unstring dmb_name; if (((unsigned)sys_random()) % count != 0) continue; diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 24026d7cd9..470cf4277b 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -34,7 +34,7 @@ static void send_election_dgram(struct subnet_record *subrec, const char *workgr uint32 criterion, int timeup,const char *server_name) { pstring outbuf; - fstring srv_name; + unstring srv_name; char *p; DEBUG(2,("send_election_dgram: Sending election packet for workgroup %s on subnet %s\n", @@ -49,7 +49,7 @@ static void send_election_dgram(struct subnet_record *subrec, const char *workgr SIVAL(p,1,criterion); SIVAL(p,5,timeup*1000); /* ms - Despite what the spec says. */ p += 13; - fstrcpy(srv_name, server_name); + unstrcpy(srv_name, server_name); strupper_m(srv_name); /* The following call does UNIX -> DOS charset conversion. */ pstrcpy_base(p, srv_name, outbuf); @@ -70,7 +70,7 @@ static void check_for_master_browser_success(struct subnet_record *subrec, struct nmb_name *answer_name, struct in_addr answer_ip, struct res_rec *rrec) { - fstring aname; + unstring aname; pull_ascii_nstring(aname, sizeof(aname), answer_name->name); DEBUG(3,("check_for_master_browser_success: Local master browser for workgroup %s exists at \ IP %s (just checking).\n", aname, inet_ntoa(answer_ip) )); @@ -85,7 +85,7 @@ static void check_for_master_browser_fail( struct subnet_record *subrec, struct nmb_name *question_name, int fail_code) { - fstring workgroup_name; + unstring workgroup_name; struct work_record *work; pull_ascii_nstring(workgroup_name,sizeof(workgroup_name),question_name->name); @@ -263,9 +263,9 @@ void process_election(struct subnet_record *subrec, struct packet_struct *p, cha int version = CVAL(buf,0); uint32 criterion = IVAL(buf,1); int timeup = IVAL(buf,5)/1000; - fstring server_name; + unstring server_name; struct work_record *work; - fstring workgroup_name; + unstring workgroup_name; pull_ascii_nstring(server_name, sizeof(server_name), buf+13); pull_ascii_nstring(workgroup_name, sizeof(workgroup_name), dgram->dest_name.name); diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 1450610e19..53b1947157 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -97,13 +97,13 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p { struct dgram_packet *dgram = &p->packet.dgram; int ttl = IVAL(buf,1)/1000; - fstring announce_name; + unstring announce_name; uint32 servertype = IVAL(buf,23); fstring comment; struct work_record *work; struct server_record *servrec; - fstring work_name; - fstring source_name; + unstring work_name; + unstring source_name; START_PROFILE(host_announce); @@ -144,7 +144,7 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p */ if(strequal(work_name, global_myname())) - fstrcpy(work_name,lp_workgroup()); + unstrcpy(work_name,lp_workgroup()); /* * We are being very agressive here in adding a workgroup @@ -198,12 +198,12 @@ void process_workgroup_announce(struct subnet_record *subrec, struct packet_stru { struct dgram_packet *dgram = &p->packet.dgram; int ttl = IVAL(buf,1)/1000; - fstring workgroup_announce_name; - fstring master_name; + unstring workgroup_announce_name; + unstring master_name; uint32 servertype = IVAL(buf,23); struct work_record *work; - fstring source_name; - fstring dest_name; + unstring source_name; + unstring dest_name; START_PROFILE(workgroup_announce); @@ -255,13 +255,13 @@ void process_local_master_announce(struct subnet_record *subrec, struct packet_s { struct dgram_packet *dgram = &p->packet.dgram; int ttl = IVAL(buf,1)/1000; - fstring server_name; + unstring server_name; uint32 servertype = IVAL(buf,23); fstring comment; - fstring work_name; + unstring work_name; struct work_record *work; struct server_record *servrec; - fstring source_name; + unstring source_name; START_PROFILE(local_master_announce); @@ -369,7 +369,7 @@ done: void process_master_browser_announce(struct subnet_record *subrec, struct packet_struct *p,char *buf) { - fstring local_master_name; + unstring local_master_name; struct work_record *work; struct browse_cache_record *browrec; @@ -425,11 +425,11 @@ void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct int osmajor=CVAL(buf,5); /* major version of node software */ int osminor=CVAL(buf,6); /* minor version of node software */ int ttl = SVAL(buf,7); - fstring announce_name; + unstring announce_name; struct work_record *work; struct server_record *servrec; - fstring work_name; - fstring source_name; + unstring work_name; + unstring source_name; fstring comment; char *s = buf+9; @@ -479,7 +479,7 @@ originate from OS/2 Warp client. Ignoring packet.\n")); */ if(strequal(work_name, global_myname())) - fstrcpy(work_name,lp_workgroup()); + unstrcpy(work_name,lp_workgroup()); /* * We are being very agressive here in adding a workgroup @@ -541,11 +541,11 @@ static void send_backup_list_response(struct subnet_record *subrec, char outbuf[1024]; char *p, *countptr; unsigned int count = 0; - fstring send_to_namestr; + unstring send_to_namestr; #if 0 struct server_record *servrec; #endif - fstring myname; + unstring myname; memset(outbuf,'\0',sizeof(outbuf)); @@ -565,7 +565,7 @@ static void send_backup_list_response(struct subnet_record *subrec, /* We always return at least one name - our own. */ count = 1; - fstrcpy(myname, global_myname()); + unstrcpy(myname, global_myname()); strupper_m(myname); myname[15]='\0'; push_pstring_base(p, myname, outbuf); @@ -642,7 +642,7 @@ void process_get_backup_list_request(struct subnet_record *subrec, unsigned char max_number_requested = CVAL(buf,0); uint32 token = IVAL(buf,1); /* Sender's key index for the workgroup. */ int name_type = dgram->dest_name.name_type; - fstring workgroup_name; + unstring workgroup_name; struct subnet_record *search_subrec = subrec; START_PROFILE(get_backup_list); @@ -774,7 +774,7 @@ void process_announce_request(struct subnet_record *subrec, struct packet_struct { struct dgram_packet *dgram = &p->packet.dgram; struct work_record *work; - fstring workgroup_name; + unstring workgroup_name; START_PROFILE(announce_request); @@ -814,7 +814,7 @@ done: void process_lm_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf) { struct dgram_packet *dgram = &p->packet.dgram; - fstring workgroup_name; + unstring workgroup_name; START_PROFILE(lm_announce_request); diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index d43cefc0df..9214594096 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -58,7 +58,7 @@ void process_name_release_request(struct subnet_record *subrec, struct nmb_packet *nmb = &p->packet.nmb; struct in_addr owner_ip; struct nmb_name *question = &nmb->question.question_name; - fstring qname; + unstring qname; BOOL bcast = nmb->header.nm_flags.bcast; uint16 nb_flags = get_nb_flags(nmb->additional->rdata); BOOL group = (nb_flags & NB_GROUP) ? True : False; @@ -275,7 +275,7 @@ We put our own names first, then in alphabetical order. static int status_compare(char *n1,char *n2) { - fstring name1, name2; + unstring name1, name2; int l1,l2,l3; memset(name1, '\0', sizeof(name1)); @@ -300,7 +300,7 @@ static int status_compare(char *n1,char *n2) (l1!=l3 || strncmp(n1,global_myname(),l3) != 0)) return 1; - return memcmp(n1,n2,sizeof(fstring)); + return memcmp(n1,n2,sizeof(name1)); } /**************************************************************************** @@ -310,7 +310,7 @@ static int status_compare(char *n1,char *n2) void process_node_status_request(struct subnet_record *subrec, struct packet_struct *p) { struct nmb_packet *nmb = &p->packet.nmb; - fstring qname; + unstring qname; int ques_type = nmb->question.question_name.name_type; char rdata[MAX_DGRAM_SIZE]; char *countptr, *buf, *bufend, *buf0; @@ -344,7 +344,7 @@ subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name), while (buf < bufend) { if( (namerec->data.source == SELF_NAME) || (namerec->data.source == PERMANENT_NAME) ) { int name_type = namerec->name.name_type; - fstring name; + unstring name; pull_ascii_nstring(name, sizeof(name), namerec->name.name); strupper_m(name); diff --git a/source3/nmbd/nmbd_logonnames.c b/source3/nmbd/nmbd_logonnames.c index b6e841139f..e426430591 100644 --- a/source3/nmbd/nmbd_logonnames.c +++ b/source3/nmbd/nmbd_logonnames.c @@ -35,7 +35,7 @@ static void become_logon_server_fail(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *fail_name) { - fstring failname; + unstring failname; struct work_record *work; struct server_record *servrec; @@ -76,7 +76,7 @@ static void become_logon_server_success(struct subnet_record *subrec, uint16 nb_flags, int ttl, struct in_addr registered_ip) { - fstring reg_name; + unstring reg_name; struct work_record *work; struct server_record *servrec; diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index 83a8361ed9..07247d5495 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -93,7 +93,7 @@ static void insert_refresh_name_into_unicast( struct subnet_record *subrec, } if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) == NULL) { - fstring name; + unstring name; pull_ascii_nstring(name, sizeof(name), nmbname->name); /* The name needs to be created on the unicast subnet. */ (void)add_name_to_subnet( unicast_subnet, name, diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 9f89abdbb2..bb14ff7641 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -45,7 +45,7 @@ void set_samba_nb_type(void) static void upcase_name( struct nmb_name *target, struct nmb_name *source ) { int i; - fstring targ; + unstring targ; fstring scope; if( NULL != source ) @@ -255,7 +255,7 @@ void standard_success_register(struct subnet_record *subrec, namerec = find_name_on_subnet( subrec, nmbname, FIND_SELF_NAME ); if( NULL == namerec ) { - fstring name; + unstring name; pull_ascii_nstring(name, sizeof(name), nmbname->name); add_name_to_subnet( subrec, name, nmbname->name_type, nb_flags, ttl, SELF_NAME, 1, ®istered_ip ); diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index 4fbdd143e1..4e11881f06 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -85,7 +85,7 @@ static void register_name_response(struct subnet_record *subrec, */ #if 1 /* OLD_SAMBA_SERVER_HACK */ - fstring ans_name; + unstring ans_name; pull_ascii_nstring(ans_name, sizeof(ans_name), answer_name->name); if((nmb->header.rcode == ACT_ERR) && strequal(lp_workgroup(), ans_name) && (answer_name->name_type == 0x1b)) { @@ -418,7 +418,7 @@ static void multihomed_register_name(struct nmb_name *nmbname, uint16 nb_flags, struct subnet_record *subrec; char **wins_tags; struct in_addr *ip_list; - fstring name; + unstring name; for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) ) num_ips++; @@ -476,7 +476,7 @@ void register_name(struct subnet_record *subrec, errno = 0; push_ascii_nstring(nname, name); if (errno == E2BIG) { - fstring tname; + unstring tname; pull_ascii_nstring(tname, sizeof(tname), nname); DEBUG(0,("register_name: NetBIOS name %s is too long. Truncating to %s\n", name, tname)); diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index b5cbaab00b..d8b50a1b2e 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1034,7 +1034,7 @@ static void process_browse_packet(struct packet_struct *p, char *buf,int len) int command = CVAL(buf,0); struct subnet_record *subrec = find_subnet_for_dgram_browse_packet(p); char scope[64]; - fstring src_name; + unstring src_name; /* Drop the packet if it's a different NetBIOS scope, or the source is from one of our names. */ pull_ascii(scope, dgram->dest_name.scope, 64, 64, STR_TERMINATE); @@ -1121,7 +1121,7 @@ static void process_lanman_packet(struct packet_struct *p, char *buf,int len) int command = SVAL(buf,0); struct subnet_record *subrec = find_subnet_for_dgram_browse_packet(p); char scope[64]; - fstring src_name; + unstring src_name; /* Drop the packet if it's a different NetBIOS scope, or the source is from one of our names. */ diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 617a7be6cb..1d1fe75d9c 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -235,7 +235,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", { fstring getdc_str; - nstring source_name; + fstring source_name; char *q = buf + 2; fstring asccomp; @@ -437,7 +437,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", send_mailslot(True, getdc, outbuf,PTR_DIFF(q,outbuf), global_myname(), 0x0, - dgram->source_name.name, + source_name, dgram->source_name.name_type, p->ip, *iface_ip(p->ip), p->port); break; diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index 87908e352c..6e50d2f2ff 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -525,7 +525,7 @@ void browse_sync_remote(time_t t) struct work_record *work; pstring outbuf; char *p; - fstring myname; + unstring myname; if (last_time && (t < (last_time + REMOTE_ANNOUNCE_INTERVAL))) return; @@ -558,7 +558,7 @@ for workgroup %s on subnet %s.\n", lp_workgroup(), FIRST_SUBNET->subnet_name )); SCVAL(p,0,ANN_MasterAnnouncement); p++; - fstrcpy(myname, global_myname()); + unstrcpy(myname, global_myname()); strupper_m(myname); myname[15]='\0'; push_pstring_base(p, myname, outbuf); diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 424af1e2e3..86f1f760fd 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -31,8 +31,8 @@ struct sync_record { struct sync_record *next, *prev; - fstring workgroup; - fstring server; + unstring workgroup; + unstring server; pstring fname; struct in_addr ip; pid_t pid; @@ -148,8 +148,8 @@ done: ZERO_STRUCTP(s); - fstrcpy(s->workgroup, work->work_group); - fstrcpy(s->server, name); + unstrcpy(s->workgroup, work->work_group); + unstrcpy(s->server, name); s->ip = ip; slprintf(s->fname, sizeof(pstring)-1, @@ -206,7 +206,7 @@ static void complete_one(struct sync_record *s, sname, lp_max_ttl()); if (work) { /* remember who the master is */ - fstrcpy(work->local_master_browser_name, comment); + unstrcpy(work->local_master_browser_name, comment); } } return; @@ -243,7 +243,7 @@ static void complete_one(struct sync_record *s, static void complete_sync(struct sync_record *s) { XFILE *f; - fstring server, type_str; + unstring server, type_str; unsigned type; pstring comment; pstring line; diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index d91818698e..cce168adb2 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -30,7 +30,7 @@ static void wins_proxy_name_query_request_success( struct subnet_record *subrec, struct userdata_struct *userdata, struct nmb_name *nmbname, struct in_addr ip, struct res_rec *rrec) { - fstring name; + unstring name; struct packet_struct *original_packet; struct subnet_record *orig_broadcast_subnet; struct name_record *namerec; @@ -193,7 +193,7 @@ void make_wins_proxy_name_query_request( struct subnet_record *subrec, long *ud[(sizeof(struct userdata_struct) + sizeof(struct subrec *) + sizeof(struct packet_struct *))/sizeof(long *) + 1]; struct userdata_struct *userdata = (struct userdata_struct *)ud; - fstring qname; + unstring qname; memset(ud, '\0', sizeof(ud)); diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 7279014194..8a63840239 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -704,7 +704,7 @@ querying for name %s in order to replace it and this reply.\n", nmb_namestr(ques void wins_process_name_registration_request(struct subnet_record *subrec, struct packet_struct *p) { - fstring name; + unstring name; struct nmb_packet *nmb = &p->packet.nmb; struct nmb_name *question = &nmb->question.question_name; BOOL bcast = nmb->header.nm_flags.bcast; @@ -1079,7 +1079,7 @@ void wins_process_multihomed_name_registration_request( struct subnet_record *su struct in_addr from_ip; BOOL group = (nb_flags & NB_GROUP) ? True : False; struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); - fstring qname; + unstring qname; putip((char *)&from_ip,&nmb->additional->rdata[2]); @@ -1439,7 +1439,7 @@ void wins_process_name_query_request(struct subnet_record *subrec, struct nmb_packet *nmb = &p->packet.nmb; struct nmb_name *question = &nmb->question.question_name; struct name_record *namerec = NULL; - fstring qname; + unstring qname; DEBUG(3,("wins_process_name_query: name query for name %s from IP %s\n", nmb_namestr(question), inet_ntoa(p->ip) )); @@ -1805,7 +1805,7 @@ void wins_write_database(BOOL background) DEBUGADD(4,("%2x\n", namerec->data.nb_flags )); if( namerec->data.source == REGISTER_NAME ) { - fstring name; + unstring name; pull_ascii_nstring(name, sizeof(name), namerec->name.name); x_fprintf(fp, "\"%s#%02x\" %d ", name,namerec->name.name_type, /* Ignore scope. */ (int)namerec->data.death_time); diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 3efef49c04..8880cb58bb 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -61,13 +61,13 @@ static struct work_record *create_workgroup(const char *name, int ttl) errno = 0; push_ascii_nstring(nname, name); if (errno == E2BIG) { - fstring tname; + unstring tname; pull_ascii_nstring(tname, sizeof(tname), nname); - fstrcpy(work->work_group,tname); + unstrcpy(work->work_group,tname); DEBUG(0,("create_workgroup: workgroup name %s is too long. Truncating to %s\n", name, tname)); } else { - fstrcpy(work->work_group,name); + unstrcpy(work->work_group,name); } work->serverlist = NULL; -- cgit From 96c5a010bb42b268b441f776ac44cad84d5f2261 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 16 Mar 2004 00:10:30 +0000 Subject: Avoid mb conversion overflow when sending an announcement. Jeremy. (This used to be commit 188e1daaffb3b21abc250ebb37d9a671ba51d054) --- source3/nmbd/nmbd_sendannounce.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index 6e50d2f2ff..a74dd99196 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -92,6 +92,7 @@ static void send_announcement(struct subnet_record *subrec, int announce_type, const char *server_name, int server_type, const char *server_comment) { pstring outbuf; + unstring upper_server_name; char *p; memset(outbuf,'\0',sizeof(outbuf)); @@ -103,7 +104,9 @@ static void send_announcement(struct subnet_record *subrec, int announce_type, SCVAL(p,0,updatecount); SIVAL(p,1,announce_interval*1000); /* Milliseconds - despite the spec. */ - push_string(NULL, p+5, server_name, 15, STR_ASCII|STR_UPPER|STR_TERMINATE); + safe_strcpy(upper_server_name, server_name, sizeof(upper_server_name)-1); + strupper_m(upper_server_name); + push_string(NULL, p+5, upper_server_name, 16, STR_ASCII|STR_TERMINATE); SCVAL(p,21,lp_major_announce_version()); /* Major version. */ SCVAL(p,22,lp_minor_announce_version()); /* Minor version. */ -- cgit From 931df5850e326ad0639fe317e0ca82e6d820a68e Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 5 Apr 2004 12:19:50 +0000 Subject: r39: * importing .cvsignore files * updateing WHATSNEW with vl's change (This used to be commit a7e2730ec4389e0c249886a8bfe1ee14c5abac41) --- source3/nmbd/.cvsignore | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 source3/nmbd/.cvsignore (limited to 'source3/nmbd') diff --git a/source3/nmbd/.cvsignore b/source3/nmbd/.cvsignore deleted file mode 100644 index e69de29bb2..0000000000 -- cgit From 8ad3d8c9b065f3a2040beff801bdc9dceac868a8 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 13 Apr 2004 14:39:48 +0000 Subject: r196: merging struct uuid from trunk (This used to be commit 911a28361b9d8dd50597627f245ebfb57c6294fb) --- source3/nmbd/nmbd_processlogon.c | 9 ++-- source3/nmbd/nmbd_winsserver.c | 114 ++++++++++++++++++++++++++------------- 2 files changed, 83 insertions(+), 40 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 1d1fe75d9c..da93224043 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -313,7 +313,8 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", } #ifdef HAVE_ADS else { - GUID domain_guid; + struct uuid domain_guid; + UUID_FLAT flat_guid; pstring domain; pstring hostname; char *component, *dc, *q1; @@ -340,8 +341,10 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", DEBUG(2, ("Could not fetch DomainGUID for %s\n", domain)); return; } - memcpy(q, &domain_guid, sizeof(domain_guid)); - q += sizeof(domain_guid); + + smb_uuid_pack(domain_guid, &flat_guid); + memcpy(q, &flat_guid.info, UUID_FLAT_SIZE); + q += UUID_FLAT_SIZE; /* Forest */ str_offset = q - q_orig; diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 8a63840239..582338d710 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -440,8 +440,8 @@ static void send_wins_name_registration_response(int rcode, int ttl, struct pack Deal with a name refresh request to a WINS server. ************************************************************************/ -void wins_process_name_refresh_request(struct subnet_record *subrec, - struct packet_struct *p) +void wins_process_name_refresh_request( struct subnet_record *subrec, + struct packet_struct *p ) { struct nmb_packet *nmb = &p->packet.nmb; struct nmb_name *question = &nmb->question.question_name; @@ -453,28 +453,36 @@ void wins_process_name_refresh_request(struct subnet_record *subrec, struct in_addr from_ip; struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); - putip((char *)&from_ip,&nmb->additional->rdata[2]); + putip( (char *)&from_ip, &nmb->additional->rdata[2] ); if(bcast) { /* * We should only get unicast name refresh packets here. - * Anyone trying to refresh broadcast should not be going to a WINS - * server. Log an error here. + * Anyone trying to refresh broadcast should not be going + * to a WINS server. Log an error here. */ - - DEBUG(0,("wins_process_name_refresh_request: broadcast name refresh request \ -received for name %s from IP %s on subnet %s. Error - should not be sent to WINS server\n", - nmb_namestr(question), inet_ntoa(from_ip), subrec->subnet_name)); + if( DEBUGLVL( 0 ) ) { + dbgtext( "wins_process_name_refresh_request: " ); + dbgtext( "Broadcast name refresh request received " ); + dbgtext( "for name %s ", nmb_namestr(question) ); + dbgtext( "from IP %s ", inet_ntoa(from_ip) ); + dbgtext( "on subnet %s. ", subrec->subnet_name ); + dbgtext( "Error - Broadcasts should not be sent " ); + dbgtext( "to a WINS server\n" ); + } return; } - DEBUG(3,("wins_process_name_refresh_request: Name refresh for name %s \ -IP %s\n", nmb_namestr(question), inet_ntoa(from_ip) )); + if( DEBUGLVL( 3 ) ) { + dbgtext( "wins_process_name_refresh_request: " ); + dbgtext( "Name refresh for name %s IP %s\n", + nmb_namestr(question), inet_ntoa(from_ip) ); + } /* * See if the name already exists. + * If not, handle it as a name registration and return. */ - namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME); /* @@ -482,48 +490,62 @@ IP %s\n", nmb_namestr(question), inet_ntoa(from_ip) )); * treat it like a registration request. This allows us to recover * from errors (tridge) */ - if(namerec == NULL) { - DEBUG(3,("wins_process_name_refresh_request: Name refresh for name %s and \ -the name does not exist. Treating as registration.\n", nmb_namestr(question) )); + if( DEBUGLVL( 3 ) ) { + dbgtext( "wins_process_name_refresh_request: " ); + dbgtext( "Name refresh for name %s ", + nmb_namestr( question ) ); + dbgtext( "and the name does not exist. Treating " ); + dbgtext( "as registration.\n" ); + } wins_process_name_registration_request(subrec,p); return; } /* - * if the name is present but not active, - * simply remove it and treat the request - * as a registration + * if the name is present but not active, simply remove it + * and treat the refresh request as a registration & return. */ if (namerec != NULL && !WINS_STATE_ACTIVE(namerec)) { - DEBUG(5,("wins_process_name_refresh_request: Name (%s) in WINS was \ -not active - removing it.\n", nmb_namestr(question) )); + if( DEBUGLVL( 5 ) ) { + dbgtext( "wins_process_name_refresh_request: " ); + dbgtext( "Name (%s) in WINS ", nmb_namestr(question) ); + dbgtext( "was not active - removing it.\n" ); + } remove_name_from_namelist( subrec, namerec ); namerec = NULL; - wins_process_name_registration_request(subrec,p); + wins_process_name_registration_request( subrec, p ); return; } /* * Check that the group bits for the refreshing name and the - * name in our database match. + * name in our database match. If not, refuse the refresh. + * [crh: Why RFS_ERR instead of ACT_ERR? Is this what MS does?] */ - - if((namerec != NULL) && ((group && !NAME_GROUP(namerec)) || (!group && NAME_GROUP(namerec))) ) { - DEBUG(3,("wins_process_name_refresh_request: Name %s group bit = %s \ -does not match group bit in WINS for this name.\n", nmb_namestr(question), group ? "True" : "False" )); + if( (namerec != NULL) && + ( (group && !NAME_GROUP(namerec)) + || (!group && NAME_GROUP(namerec)) ) ) { + if( DEBUGLVL( 3 ) ) { + dbgtext( "wins_process_name_refresh_request: " ); + dbgtext( "Name %s ", nmb_namestr(question) ); + dbgtext( "group bit = %s does not match ", + group ? "True" : "False" ); + dbgtext( "group bit in WINS for this name.\n" ); + } send_wins_name_registration_response(RFS_ERR, 0, p); return; } /* - * For a unique name check that the person refreshing the name is one of the registered IP - * addresses. If not - fail the refresh. Do the same for group names with a type of 0x1c. - * Just return success for unique 0x1d refreshes. For normal group names update the ttl - * and return success. + * For a unique name check that the person refreshing the name is + * one of the registered IP addresses. If not - fail the refresh. + * Do the same for group names with a type of 0x1c. + * Just return success for unique 0x1d refreshes. For normal group + * names update the ttl and return success. */ - - if((!group || (group && (question->name_type == 0x1c))) && find_ip_in_name_record(namerec, from_ip )) { + if( (!group || (group && (question->name_type == 0x1c))) + && find_ip_in_name_record(namerec, from_ip) ) { /* * Update the ttl. */ @@ -541,10 +563,25 @@ does not match group bit in WINS for this name.\n", nmb_namestr(question), group send_wins_name_registration_response(0, ttl, p); wins_hook("refresh", namerec, ttl); return; + } else if((group && (question->name_type == 0x1c))) { + /* + * Added by crh for bug #1079. + * Fix from Bert Driehuis + */ + if( DEBUGLVL( 3 ) ) { + dbgtext( "wins_process_name_refresh_request: " ); + dbgtext( "Name refresh for name %s, ", + nmb_namestr(question) ); + dbgtext( "but IP address %s ", inet_ntoa(from_ip) ); + dbgtext( "is not yet associated with " ); + dbgtext( "that name. Treating as registration.\n" ); + } + wins_process_name_registration_request(subrec,p); + return; } else if(group) { /* - * Normal groups are all registered with an IP address of 255.255.255.255 - * so we can't search for the IP address. + * Normal groups are all registered with an IP address of + * 255.255.255.255 so we can't search for the IP address. */ update_name_ttl(namerec, ttl); send_wins_name_registration_response(0, ttl, p); @@ -559,9 +596,12 @@ does not match group bit in WINS for this name.\n", nmb_namestr(question), group /* * Fail the refresh. */ - - DEBUG(3,("wins_process_name_refresh_request: Name refresh for name %s with IP %s and \ -is IP is not known to the name.\n", nmb_namestr(question), inet_ntoa(from_ip) )); + if( DEBUGLVL( 3 ) ) { + dbgtext( "wins_process_name_refresh_request: " ); + dbgtext( "Name refresh for name %s with IP %s ", + nmb_namestr(question), inet_ntoa(from_ip) ); + dbgtext( "and is IP is not known to the name.\n" ); + } send_wins_name_registration_response(RFS_ERR, 0, p); return; } -- cgit From 16452d54f77b17409f3cb40a286ef84e8e6d79a2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 27 May 2004 22:57:50 +0000 Subject: r928: Ensure we're calling send_mailslot() with a UNIX charset target name. Jeremy. (This used to be commit 409eef2be78a74b8ae69e4f1f58514006f0ae090) --- source3/nmbd/nmbd_browsesync.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 15827e21ba..56ffdc2670 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -103,6 +103,7 @@ static void announce_local_master_browser_to_domain_master_browser( struct work_ { pstring outbuf; unstring myname; + unstring dmb_name; char *p; if(ismyip(work->dmb_addr)) { @@ -135,8 +136,10 @@ static void announce_local_master_browser_to_domain_master_browser( struct work_ work->work_group ); } + /* Target name for send_mailslot must be in UNIX charset. */ + pull_ascii_nstring(dmb_name, sizeof(dmb_name), work->dmb_name.name); send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), - global_myname(), 0x0, work->dmb_name.name, 0x0, + global_myname(), 0x0, dmb_name, 0x0, work->dmb_addr, FIRST_SUBNET->myip, DGRAM_PORT); } -- cgit From e8a1292d91e4442fc98f080cae79201575353995 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 29 Jun 2004 00:51:31 +0000 Subject: r1290: Ensure we remove DNS and DNSFAIL records immediately on timeout. Fix for #607. Jeremy. (This used to be commit e6ff6d95d21ff071d0fb7266987c75fd15f6652f) --- source3/nmbd/nmbd_winsserver.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 582338d710..8ebdfadbf7 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1727,11 +1727,16 @@ void initiate_wins_processing(time_t t) && (namerec->data.death_time < t) ) { if( namerec->data.source == SELF_NAME ) { - DEBUG( 3, ( "expire_names_on_subnet: Subnet %s not expiring SELF name %s\n", + DEBUG( 3, ( "initiate_wins_processing: Subnet %s not expiring SELF name %s\n", wins_server_subnet->subnet_name, nmb_namestr(&namerec->name) ) ); namerec->data.death_time += 300; namerec->subnet->namelist_changed = True; continue; + } else if (namerec->data.source == DNS_NAME || namerec->data.source == DNSFAIL_NAME) { + DEBUG(3,("initiate_wins_processing: deleting timed out DNS name %s\n", + nmb_namestr(&namerec->name))); + remove_name_from_namelist( wins_server_subnet, namerec ); + break; } /* handle records, samba is the wins owner */ -- cgit From 7310ba1b18a8971d432be0cee59b25c1d16383b9 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 29 Jun 2004 17:32:44 +0000 Subject: r1299: Don't "break" - "continue" ! Otherwise we only expire the first name ! Doh ! Jeremy. (This used to be commit 451d289f6971a74757b72577cc587bef06585540) --- source3/nmbd/nmbd_winsserver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 8ebdfadbf7..0e0289d9a3 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1736,7 +1736,7 @@ void initiate_wins_processing(time_t t) DEBUG(3,("initiate_wins_processing: deleting timed out DNS name %s\n", nmb_namestr(&namerec->name))); remove_name_from_namelist( wins_server_subnet, namerec ); - break; + continue; } /* handle records, samba is the wins owner */ -- cgit From 571cc4811bc373a5b4aeda9e5635aff1ff650e06 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 4 Sep 2004 01:57:16 +0000 Subject: r2224: Make nmbd more robust against bad netbios packets. Jeremy. (This used to be commit dd9b17abd6b32c090840c1a0b797fd774711cb3a) --- source3/nmbd/nmbd_packets.c | 44 ++++++++++++++--- source3/nmbd/nmbd_processlogon.c | 104 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 141 insertions(+), 7 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index d8b50a1b2e..96de4911dc 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1203,6 +1203,16 @@ an error packet of type %x\n", nmb_namestr(&dgram->dest_name), inet_ntoa(p->ip), return; } + /* Ensure we have a large enough packet before looking inside. */ + if (dgram->datasize < (smb_vwv12 - 2)) { + /* That's the offset minus the 4 byte length + 2 bytes of offset. */ + DEBUG(0,("process_dgram: ignoring too short dgram packet (%u) sent to name %s from IP %s\n", + (unsigned int)dgram->datasize, + nmb_namestr(&dgram->dest_name), + inet_ntoa(p->ip) )); + return; + } + buf = &dgram->data[0]; buf -= 4; /* XXXX for the pseudo tcp length - someday I need to get rid of this */ @@ -1212,14 +1222,36 @@ an error packet of type %x\n", nmb_namestr(&dgram->dest_name), inet_ntoa(p->ip), len = SVAL(buf,smb_vwv11); buf2 = smb_base(buf) + SVAL(buf,smb_vwv12); - if (len <= 0) + if (len <= 0 || len > dgram->datasize) { + DEBUG(0,("process_dgram: ignoring malformed1 (datasize = %d, len = %d) datagram \ +packet sent to name %s from IP %s\n", + dgram->datasize, + len, + nmb_namestr(&dgram->dest_name), + inet_ntoa(p->ip) )); + return; + } + + if (buf2 < dgram->data || (buf2 >= dgram->data + dgram->datasize)) { + DEBUG(0,("process_dgram: ignoring malformed2 (datasize = %d, len=%d, off=%d) datagram \ +packet sent to name %s from IP %s\n", + dgram->datasize, + len, + PTR_DIFF(buf2, dgram->data), + nmb_namestr(&dgram->dest_name), + inet_ntoa(p->ip) )); return; + } - if (buf2 + len > buf + sizeof(dgram->data)) { - DEBUG(2,("process_dgram: datagram from %s to %s IP %s for %s len=%d too long.\n", - nmb_namestr(&dgram->source_name),nmb_namestr(&dgram->dest_name), - inet_ntoa(p->ip), smb_buf(buf),len)); - len = (buf + sizeof(dgram->data)) - buf; + if ((buf2 + len < dgram->data) || (buf2 + len > dgram->data + dgram->datasize)) { + DEBUG(0,("process_dgram: ignoring malformed3 (datasize = %d, len=%d, off=%d) datagram \ +packet sent to name %s from IP %s\n", + dgram->datasize, + len, + PTR_DIFF(buf2, dgram->data), + nmb_namestr(&dgram->dest_name), + inet_ntoa(p->ip) )); + return; } DEBUG(4,("process_dgram: datagram from %s to %s IP %s for %s of type %d len=%d\n", diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index da93224043..fa2a8c1cef 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -102,8 +102,22 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); char *machine = q; char *user = skip_string(machine,1); + if (PTR_DIFF(user, buf) >= len) { + DEBUG(0,("process_logon_packet: bad packet\n")); + return; + } getdc = skip_string(user,1); + + if (PTR_DIFF(getdc, buf) >= len) { + DEBUG(0,("process_logon_packet: bad packet\n")); + return; + } q = skip_string(getdc,1); + + if (PTR_DIFF(q + 5, buf) >= len) { + DEBUG(0,("process_logon_packet: bad packet\n")); + return; + } token = SVAL(q,3); fstrcpy(reply_name,my_name); @@ -151,7 +165,17 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); } getdc = skip_string(machine,1); + + if (PTR_DIFF(getdc, buf) >= len) { + DEBUG(0,("process_logon_packet: bad packet\n")); + return; + } q = skip_string(getdc,1); + + if (PTR_DIFF(q, buf) >= len) { + DEBUG(0,("process_logon_packet: bad packet\n")); + return; + } q = ALIGN2(q, buf); /* At this point we can work out if this is a W9X or NT style @@ -165,9 +189,19 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); } else { unicomp = q; + if (PTR_DIFF(q, buf) >= len) { + DEBUG(0,("process_logon_packet: bad packet\n")); + return; + } + /* A full length (NT style) request */ q = skip_unibuf(unicomp, PTR_DIFF(buf + len, unicomp)); + if (PTR_DIFF(q, buf) >= len) { + DEBUG(0,("process_logon_packet: bad packet\n")); + return; + } + if (len - PTR_DIFF(q, buf) > 8) { /* with NT5 clients we can sometimes get additional data - a length specificed string @@ -180,6 +214,12 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); } q += 16; } + + if (PTR_DIFF(q + 8, buf) >= len) { + DEBUG(0,("process_logon_packet: bad packet\n")); + return; + } + ntversion = IVAL(q, 0); lmnttoken = SVAL(q, 4); lm20token = SVAL(q, 6); @@ -240,10 +280,34 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", fstring asccomp; q += 2; + + if (PTR_DIFF(q, buf) >= len) { + DEBUG(0,("process_logon_packet: bad packet\n")); + return; + } + unicomp = q; uniuser = skip_unibuf(unicomp, PTR_DIFF(buf+len, unicomp)); + + if (PTR_DIFF(uniuser, buf) >= len) { + DEBUG(0,("process_logon_packet: bad packet\n")); + return; + } + getdc = skip_unibuf(uniuser,PTR_DIFF(buf+len, uniuser)); + + if (PTR_DIFF(getdc, buf) >= len) { + DEBUG(0,("process_logon_packet: bad packet\n")); + return; + } + q = skip_string(getdc,1); + + if (PTR_DIFF(q + 8, buf) >= len) { + DEBUG(0,("process_logon_packet: bad packet\n")); + return; + } + q += 4; /* Account Control Bits - indicating username type */ domainsidsize = IVAL(q, 0); q += 4; @@ -270,6 +334,11 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += 16; } + if (PTR_DIFF(q + 8, buf) >= len) { + DEBUG(0,("process_logon_packet: bad packet\n")); + return; + } + ntversion = IVAL(q, 0); lmnttoken = SVAL(q, 4); lm20token = SVAL(q, 6); @@ -458,6 +527,11 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", /* Header */ + if (PTR_DIFF(q + 16, buf) >= len) { + DEBUG(0,("process_logon_packet: bad packet\n")); + return; + } + low_serial = IVAL(q, 0); q += 4; /* Low serial number */ q += 4; /* Date/time */ @@ -467,14 +541,42 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", /* Domain info */ q = skip_string(q, 1); /* PDC name */ + + if (PTR_DIFF(q, buf) >= len) { + DEBUG(0,("process_logon_packet: bad packet\n")); + return; + } + q = skip_string(q, 1); /* Domain name */ + + if (PTR_DIFF(q, buf) >= len) { + DEBUG(0,("process_logon_packet: bad packet\n")); + return; + } + q = skip_unibuf(q, PTR_DIFF(buf + len, q)); /* Unicode PDC name */ + + if (PTR_DIFF(q, buf) >= len) { + DEBUG(0,("process_logon_packet: bad packet\n")); + return; + } + q = skip_unibuf(q, PTR_DIFF(buf + len, q)); /* Unicode domain name */ /* Database info */ + if (PTR_DIFF(q + 2, buf) >= len) { + DEBUG(0,("process_logon_packet: bad packet\n")); + return; + } + db_count = SVAL(q, 0); q += 2; - + + if (PTR_DIFF(q + (db_count*20), buf) >= len) { + DEBUG(0,("process_logon_packet: bad packet\n")); + return; + } + db_info = (struct sam_database_info *) malloc(sizeof(struct sam_database_info) * db_count); -- cgit From 1ee9f9ad81d6619f581b87ef9e631d18ee4452b9 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 9 Sep 2004 01:46:20 +0000 Subject: r2261: fix getdc mailslot checks; testing with Windows 98se, WinME, WinNT 4.0/200x/XP (This used to be commit 8ad147508ac653698ebacf9fd19fc5eb5863db28) --- source3/nmbd/nmbd_processlogon.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index fa2a8c1cef..ae4011eb8f 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -114,7 +114,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); } q = skip_string(getdc,1); - if (PTR_DIFF(q + 5, buf) >= len) { + if (PTR_DIFF(q + 5, buf) > len) { DEBUG(0,("process_logon_packet: bad packet\n")); return; } @@ -215,7 +215,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); q += 16; } - if (PTR_DIFF(q + 8, buf) >= len) { + if (PTR_DIFF(q + 8, buf) > len) { DEBUG(0,("process_logon_packet: bad packet\n")); return; } @@ -334,7 +334,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += 16; } - if (PTR_DIFF(q + 8, buf) >= len) { + if (PTR_DIFF(q + 8, buf) > len) { DEBUG(0,("process_logon_packet: bad packet\n")); return; } -- cgit From e2fb31ebc009b80617549cb0192bdce80020e740 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 16 Sep 2004 00:25:04 +0000 Subject: r2363: Fix to make find_workgroup use the same truncation as create_workgroup (refactor to a common function). Patch from Paul Szabo - psz@maths.usyd.edu.au. Jeremy. (This used to be commit b2b6d6e890813b0d222ac75efb95434ba8c70e46) --- source3/nmbd/nmbd_workgroupdb.c | 43 +++++++++++++++++++++++++++-------------- 1 file changed, 28 insertions(+), 15 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 8880cb58bb..8f3ae36b65 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -40,6 +40,27 @@ static void add_workgroup(struct subnet_record *subrec, struct work_record *work subrec->work_changed = True; } +/**************************************************************************** + Copy name to unstring. Used by create_workgroup() and find_workgroup_on_subnet(). +**************************************************************************/ + +static void name_to_unstring(unstring unname, const char *name) +{ + nstring nname; + + errno = 0; + push_ascii_nstring(nname, name); + if (errno == E2BIG) { + unstring tname; + pull_ascii_nstring(tname, sizeof(tname), nname); + unstrcpy(unname, tname); + DEBUG(0,("name_to_nstring: workgroup name %s is too long. Truncating to %s\n", + name, tname)); + } else { + unstrcpy(unname, name); + } +} + /**************************************************************************** Create an empty workgroup. **************************************************************************/ @@ -48,8 +69,6 @@ static struct work_record *create_workgroup(const char *name, int ttl) { struct work_record *work; struct subnet_record *subrec; - nstring nname; - int t = -1; if((work = (struct work_record *)malloc(sizeof(*work))) == NULL) { @@ -58,17 +77,8 @@ static struct work_record *create_workgroup(const char *name, int ttl) } memset((char *)work, '\0', sizeof(*work)); - errno = 0; - push_ascii_nstring(nname, name); - if (errno == E2BIG) { - unstring tname; - pull_ascii_nstring(tname, sizeof(tname), nname); - unstrcpy(work->work_group,tname); - DEBUG(0,("create_workgroup: workgroup name %s is too long. Truncating to %s\n", - name, tname)); - } else { - unstrcpy(work->work_group,name); - } + name_to_unstring(work->work_group, name); + work->serverlist = NULL; work->RunningElection = False; @@ -157,12 +167,15 @@ struct work_record *find_workgroup_on_subnet(struct subnet_record *subrec, const char *name) { struct work_record *ret; - + unstring un_name; + DEBUG(4, ("find_workgroup_on_subnet: workgroup search for %s on subnet %s: ", name, subrec->subnet_name)); + name_to_unstring(un_name, name); + for (ret = subrec->workgrouplist; ret; ret = ret->next) { - if (strequal(ret->work_group,name)) { + if (strequal(ret->work_group,un_name)) { DEBUGADD(4, ("found.\n")); return(ret); } -- cgit From 3b015a4cc7c0cd6b3662bc89a97df9769e57e7e6 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 21 Sep 2004 09:07:42 +0000 Subject: r2470: Fix bug 1797: winbind and nmbd ignored "-l" option. Thanks to Igor Zhbanov bsg@uniyar.ac.ru. Volker (This used to be commit 8a28475a0b7659cb0cdefe57edf801d9958c3755) --- source3/nmbd/nmbd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 880de7f91b..f8006a22a9 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -29,6 +29,8 @@ int global_nmb_port = -1; extern BOOL global_in_nmbd; +extern BOOL override_logfile; + /* are we running as a daemon ? */ static BOOL is_daemon; @@ -623,8 +625,10 @@ static BOOL open_sockets(BOOL isdaemon, int port) sys_srandom(time(NULL) ^ sys_getpid()); - slprintf(logfile, sizeof(logfile)-1, "%s/log.nmbd", dyn_LOGFILEBASE); - lp_set_logfile(logfile); + if (!override_logfile) { + slprintf(logfile, sizeof(logfile)-1, "%s/log.nmbd", dyn_LOGFILEBASE); + lp_set_logfile(logfile); + } fault_setup((void (*)(void *))fault_continue ); -- cgit From 4a505a2860c08c8223b44507e212a4ce5e433bea Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Nov 2004 22:11:20 +0000 Subject: r3864: Fix from Lars Müller for bug #2050. Make nmbd use maxfd+1 in select also. Jeremy. (This used to be commit e3ca22b80dc1c22f0e5c829d11724c79e317641f) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source3/nmbd/nmbd_packets.c | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 96de4911dc..9dd2d05e14 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1634,12 +1634,22 @@ on subnet %s\n", rrec->response_id, inet_ntoa(rrec->packet->ip), subrec->subnet_ } /* end for subnet */ } +/**************************************************************************** + Check and if required set the highest fd. +***************************************************************************/ + +void check_set_maxfd( int *maxfd, int fd) +{ + if ( *maxfd < fd ) + *maxfd = fd; +} + /**************************************************************************** Create an fd_set containing all the sockets in the subnet structures, plus the broadcast sockets. ***************************************************************************/ -static BOOL create_listen_fdset(fd_set **ppset, int **psock_array, int *listen_number) +static BOOL create_listen_fdset(fd_set **ppset, int **psock_array, int *listen_number, int *maxfd) { int *sock_array = NULL; struct subnet_record *subrec = NULL; @@ -1672,21 +1682,25 @@ only use %d.\n", (count*2) + 2, FD_SETSIZE)); /* Add in the broadcast socket on 137. */ FD_SET(ClientNMB,pset); sock_array[num++] = ClientNMB; + check_set_maxfd( maxfd, ClientNMB); /* Add in the 137 sockets on all the interfaces. */ for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { FD_SET(subrec->nmb_sock,pset); sock_array[num++] = subrec->nmb_sock; + check_set_maxfd( maxfd, subrec->nmb_sock); } /* Add in the broadcast socket on 138. */ FD_SET(ClientDGRAM,pset); sock_array[num++] = ClientDGRAM; + check_set_maxfd( maxfd, ClientDGRAM); /* Add in the 138 sockets on all the interfaces. */ for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { FD_SET(subrec->dgram_sock,pset); sock_array[num++] = subrec->dgram_sock; + check_set_maxfd( maxfd, subrec->dgram_sock); } *listen_number = (count*2) + 2; @@ -1711,6 +1725,7 @@ BOOL listen_for_packets(BOOL run_election) static int listen_number = 0; static int *sock_array = NULL; int i; + int maxfd = 0; fd_set fds; int selrtn; @@ -1720,7 +1735,7 @@ BOOL listen_for_packets(BOOL run_election) #endif if(listen_set == NULL || rescan_listen_set) { - if(create_listen_fdset(&listen_set, &sock_array, &listen_number)) { + if(create_listen_fdset(&listen_set, &sock_array, &listen_number, &maxfd)) { DEBUG(0,("listen_for_packets: Fatal error. unable to create listen set. Exiting.\n")); return True; } @@ -1733,6 +1748,7 @@ BOOL listen_for_packets(BOOL run_election) dns_fd = asyncdns_fd(); if (dns_fd != -1) { FD_SET(dns_fd, &fds); + check_set_maxfd( &maxfd, dns_fd); } #endif @@ -1750,7 +1766,7 @@ BOOL listen_for_packets(BOOL run_election) BlockSignals(False, SIGTERM); - selrtn = sys_select(FD_SETSIZE,&fds,NULL,NULL,&timeout); + selrtn = sys_select(maxfd+1,&fds,NULL,NULL,&timeout); /* We can only take signals when we are in the select - block them again here. */ -- cgit From a68172ce7cc6c3c9cb02c1b07add9ad1c9c50bbe Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 19 Nov 2004 19:32:31 +0000 Subject: r3877: Final (I hope :-) fix for #2050 from Lars Müller for select maxfd's. Jeremy. (This used to be commit 65fc39fc388244923d1e36076b5a4116aa434be5) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source3/nmbd/nmbd_packets.c | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 9dd2d05e14..a81b28ec74 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1634,16 +1634,6 @@ on subnet %s\n", rrec->response_id, inet_ntoa(rrec->packet->ip), subrec->subnet_ } /* end for subnet */ } -/**************************************************************************** - Check and if required set the highest fd. -***************************************************************************/ - -void check_set_maxfd( int *maxfd, int fd) -{ - if ( *maxfd < fd ) - *maxfd = fd; -} - /**************************************************************************** Create an fd_set containing all the sockets in the subnet structures, plus the broadcast sockets. @@ -1682,25 +1672,25 @@ only use %d.\n", (count*2) + 2, FD_SETSIZE)); /* Add in the broadcast socket on 137. */ FD_SET(ClientNMB,pset); sock_array[num++] = ClientNMB; - check_set_maxfd( maxfd, ClientNMB); + *maxfd = MAX( *maxfd, ClientNMB); /* Add in the 137 sockets on all the interfaces. */ for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { FD_SET(subrec->nmb_sock,pset); sock_array[num++] = subrec->nmb_sock; - check_set_maxfd( maxfd, subrec->nmb_sock); + *maxfd = MAX( *maxfd, subrec->nmb_sock); } /* Add in the broadcast socket on 138. */ FD_SET(ClientDGRAM,pset); sock_array[num++] = ClientDGRAM; - check_set_maxfd( maxfd, ClientDGRAM); + *maxfd = MAX( *maxfd, ClientDGRAM); /* Add in the 138 sockets on all the interfaces. */ for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { FD_SET(subrec->dgram_sock,pset); sock_array[num++] = subrec->dgram_sock; - check_set_maxfd( maxfd, subrec->dgram_sock); + *maxfd = MAX( *maxfd, subrec->dgram_sock); } *listen_number = (count*2) + 2; @@ -1725,7 +1715,7 @@ BOOL listen_for_packets(BOOL run_election) static int listen_number = 0; static int *sock_array = NULL; int i; - int maxfd = 0; + static int maxfd = 0; fd_set fds; int selrtn; @@ -1748,7 +1738,7 @@ BOOL listen_for_packets(BOOL run_election) dns_fd = asyncdns_fd(); if (dns_fd != -1) { FD_SET(dns_fd, &fds); - check_set_maxfd( &maxfd, dns_fd); + maxfd = MAX( maxfd, dns_fd); } #endif -- cgit From acf9d61421faa6c0055d57fdee7db300dc5431aa Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 7 Dec 2004 18:25:53 +0000 Subject: r4088: Get medieval on our ass about malloc.... :-). Take control of all our allocation functions so we can funnel through some well known functions. Should help greatly with malloc checking. HEAD patch to follow. Jeremy. (This used to be commit 620f2e608f70ba92f032720c031283d295c5c06a) --- source3/nmbd/nmbd_become_lmb.c | 4 ++-- source3/nmbd/nmbd_browserdb.c | 2 +- source3/nmbd/nmbd_browsesync.c | 2 +- source3/nmbd/nmbd_incomingrequests.c | 2 +- source3/nmbd/nmbd_namelistdb.c | 8 ++++---- source3/nmbd/nmbd_nameregister.c | 4 ++-- source3/nmbd/nmbd_packets.c | 10 +++++----- source3/nmbd/nmbd_processlogon.c | 3 +-- source3/nmbd/nmbd_responserecordsdb.c | 4 ++-- source3/nmbd/nmbd_serverlistdb.c | 2 +- source3/nmbd/nmbd_subnetdb.c | 4 ++-- source3/nmbd/nmbd_synclists.c | 2 +- source3/nmbd/nmbd_winsproxy.c | 4 ++-- source3/nmbd/nmbd_winsserver.c | 6 +++--- source3/nmbd/nmbd_workgroupdb.c | 2 +- 15 files changed, 29 insertions(+), 30 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index c536deb6f4..b928a8a7c5 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -206,7 +206,7 @@ static void release_1d_name( struct subnet_record *subrec, const char *workgroup struct userdata_struct *userdata; size_t size = sizeof(struct userdata_struct) + sizeof(BOOL); - if((userdata = (struct userdata_struct *)malloc(size)) == NULL) { + if((userdata = (struct userdata_struct *)SMB_MALLOC(size)) == NULL) { DEBUG(0,("release_1d_name: malloc fail.\n")); return; } @@ -545,7 +545,7 @@ in workgroup %s on subnet %s\n", subrec->work_changed = True; /* Setup the userdata_struct. */ - if((userdata = (struct userdata_struct *)malloc(size)) == NULL) { + if((userdata = (struct userdata_struct *)SMB_MALLOC(size)) == NULL) { DEBUG(0,("become_local_master_browser: malloc fail.\n")); return; } diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c index c92513fae8..e8797a99d5 100644 --- a/source3/nmbd/nmbd_browserdb.c +++ b/source3/nmbd/nmbd_browserdb.c @@ -87,7 +87,7 @@ struct browse_cache_record *create_browser_in_lmb_cache( const char *work_name, struct browse_cache_record *browc; time_t now = time( NULL ); - browc = (struct browse_cache_record *)malloc( sizeof( *browc ) ); + browc = SMB_MALLOC_P(struct browse_cache_record); if( NULL == browc ) { DEBUG( 0, ("create_browser_in_lmb_cache: malloc fail !\n") ); diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 56ffdc2670..03234bb98f 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -324,7 +324,7 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec, /* Setup the userdata_struct - this is copied so we can use a stack variable for this. */ - if((userdata = (struct userdata_struct *)malloc(size)) == NULL) { + if((userdata = (struct userdata_struct *)SMB_MALLOC(size)) == NULL) { DEBUG(0, ("find_domain_master_name_query_success: malloc fail.\n")); return; } diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index 9214594096..7fac8c2573 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -516,7 +516,7 @@ void process_name_query_request(struct subnet_record *subrec, struct packet_stru if (namerec->data.num_ips == 1) { prdata = rdata; } else { - if ((prdata = (char *)malloc( namerec->data.num_ips * 6 )) == NULL) { + if ((prdata = (char *)SMB_MALLOC( namerec->data.num_ips * 6 )) == NULL) { DEBUG(0,("process_name_query_request: malloc fail !\n")); return; } diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index bb14ff7641..bdb308a2ea 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -181,14 +181,14 @@ struct name_record *add_name_to_subnet( struct subnet_record *subrec, struct name_record *namerec; time_t time_now = time(NULL); - namerec = (struct name_record *)malloc( sizeof(*namerec) ); + namerec = SMB_MALLOC_P(struct name_record); if( NULL == namerec ) { DEBUG( 0, ( "add_name_to_subnet: malloc fail.\n" ) ); return( NULL ); } memset( (char *)namerec, '\0', sizeof(*namerec) ); - namerec->data.ip = (struct in_addr *)malloc( sizeof(struct in_addr) * num_ips ); + namerec->data.ip = SMB_MALLOC_ARRAY( struct in_addr, num_ips ); if( NULL == namerec->data.ip ) { DEBUG( 0, ( "add_name_to_subnet: malloc fail when creating ip_flgs.\n" ) ); ZERO_STRUCTP(namerec); @@ -329,7 +329,7 @@ void add_ip_to_name_record( struct name_record *namerec, struct in_addr new_ip ) if( find_ip_in_name_record( namerec, new_ip ) ) return; - new_list = (struct in_addr *)malloc( (namerec->data.num_ips + 1) * sizeof(struct in_addr) ); + new_list = SMB_MALLOC_ARRAY( struct in_addr, namerec->data.num_ips + 1); if( NULL == new_list ) { DEBUG(0,("add_ip_to_name_record: Malloc fail !\n")); return; @@ -460,7 +460,7 @@ void add_samba_names_to_subnet( struct subnet_record *subrec ) /* Create an IP list containing all our known subnets. */ num_ips = iface_count(); - iplist = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr) ); + iplist = SMB_MALLOC_ARRAY( struct in_addr, num_ips); if( NULL == iplist ) { DEBUG(0,("add_samba_names_to_subnet: Malloc fail !\n")); return; diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index 4e11881f06..8f2a889254 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -306,7 +306,7 @@ static void multihomed_register_one(struct nmb_name *nmbname, struct in_addr wins_ip = wins_srv_ip_tag(tag, ip); fstring ip_str; - userdata = (struct userdata_struct *)malloc(sizeof(*userdata) + strlen(tag) + 1); + userdata = (struct userdata_struct *)SMB_MALLOC(sizeof(*userdata) + strlen(tag) + 1); if (!userdata) { DEBUG(0,("Failed to allocate userdata structure!\n")); return; @@ -423,7 +423,7 @@ static void multihomed_register_name(struct nmb_name *nmbname, uint16 nb_flags, for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) ) num_ips++; - if((ip_list = (struct in_addr *)malloc(num_ips * sizeof(struct in_addr)))==NULL) { + if((ip_list = SMB_MALLOC_ARRAY(struct in_addr, num_ips))==NULL) { DEBUG(0,("multihomed_register_name: malloc fail !\n")); return; } diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index a81b28ec74..8a111eb957 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -184,7 +184,7 @@ static struct packet_struct *create_and_init_netbios_packet(struct nmb_name *nmb struct nmb_packet *nmb = NULL; /* Allocate the packet_struct we will return. */ - if((packet = (struct packet_struct *)malloc(sizeof(*packet))) == NULL) { + if((packet = SMB_MALLOC_P(struct packet_struct)) == NULL) { DEBUG(0,("create_and_init_netbios_packet: malloc fail (1) for packet struct.\n")); return NULL; } @@ -230,7 +230,7 @@ static BOOL create_and_init_additional_record(struct packet_struct *packet, { struct nmb_packet *nmb = &packet->packet.nmb; - if((nmb->additional = (struct res_rec *)malloc(sizeof(struct res_rec))) == NULL) { + if((nmb->additional = SMB_MALLOC_P(struct res_rec)) == NULL) { DEBUG(0,("initiate_name_register_packet: malloc fail for additional record.\n")); return False; } @@ -534,7 +534,7 @@ void queue_wins_refresh(struct nmb_name *nmbname, DEBUG(6,("Refreshing name %s IP %s with WINS server %s using tag '%s'\n", nmb_namestr(nmbname), ip_str, inet_ntoa(wins_ip), tag)); - userdata = (struct userdata_struct *)malloc(sizeof(*userdata) + strlen(tag) + 1); + userdata = (struct userdata_struct *)SMB_MALLOC(sizeof(*userdata) + strlen(tag) + 1); if (!userdata) { DEBUG(0,("Failed to allocate userdata structure!\n")); return; @@ -1645,7 +1645,7 @@ static BOOL create_listen_fdset(fd_set **ppset, int **psock_array, int *listen_n struct subnet_record *subrec = NULL; int count = 0; int num = 0; - fd_set *pset = (fd_set *)malloc(sizeof(fd_set)); + fd_set *pset = SMB_MALLOC_P(fd_set); if(pset == NULL) { DEBUG(0,("create_listen_fdset: malloc fail !\n")); @@ -1662,7 +1662,7 @@ only use %d.\n", (count*2) + 2, FD_SETSIZE)); return True; } - if((sock_array = (int *)malloc(((count*2) + 2)*sizeof(int))) == NULL) { + if((sock_array = SMB_MALLOC_ARRAY(int, (count*2) + 2)) == NULL) { DEBUG(0,("create_listen_fdset: malloc fail for socket array.\n")); return True; } diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index ae4011eb8f..5c0fc2c521 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -577,8 +577,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", return; } - db_info = (struct sam_database_info *) - malloc(sizeof(struct sam_database_info) * db_count); + db_info = SMB_MALLOC_ARRAY(struct sam_database_info, db_count); if (db_info == NULL) { DEBUG(3, ("out of memory allocating info for %d databases\n", db_count)); diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index 30c0c12950..a5903ef462 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -105,7 +105,7 @@ struct response_record *make_response_record( struct subnet_record *subrec, struct response_record *rrec; struct nmb_packet *nmb = &p->packet.nmb; - if (!(rrec = (struct response_record *)malloc(sizeof(*rrec)))) { + if (!(rrec = SMB_MALLOC_P(struct response_record))) { DEBUG(0,("make_response_queue_record: malloc fail for response_record.\n")); return NULL; } @@ -133,7 +133,7 @@ struct response_record *make_response_record( struct subnet_record *subrec, } else { /* Primitive userdata, do a memcpy. */ if((rrec->userdata = (struct userdata_struct *) - malloc(sizeof(struct userdata_struct)+userdata->userdata_len)) == NULL) { + SMB_MALLOC(sizeof(struct userdata_struct)+userdata->userdata_len)) == NULL) { DEBUG(0,("make_response_queue_record: malloc fail for userdata.\n")); ZERO_STRUCTP(rrec); SAFE_FREE(rrec); diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index e6fad8319d..52d00e1585 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -137,7 +137,7 @@ workgroup %s. This is a bug.\n", name, work->work_group)); return NULL; } - if((servrec = (struct server_record *)malloc(sizeof(*servrec))) == NULL) { + if((servrec = SMB_MALLOC_P(struct server_record)) == NULL) { DEBUG(0,("create_server_entry_on_workgroup: malloc fail !\n")); return NULL; } diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 02a91f2760..ecfd92719b 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -147,7 +147,7 @@ static struct subnet_record *make_subnet(const char *name, enum subnet_type type set_socket_options(dgram_sock,"SO_BROADCAST"); } - subrec = (struct subnet_record *)malloc(sizeof(*subrec)); + subrec = SMB_MALLOC_P(struct subnet_record); if (!subrec) { DEBUG(0,("make_subnet: malloc fail !\n")); close(nmb_sock); @@ -160,7 +160,7 @@ static struct subnet_record *make_subnet(const char *name, enum subnet_type type namelist_entry_compare, ubi_trOVERWRITE ); - if((subrec->subnet_name = strdup(name)) == NULL) { + if((subrec->subnet_name = SMB_STRDUP(name)) == NULL) { DEBUG(0,("make_subnet: malloc fail for subnet name !\n")); close(nmb_sock); close(dgram_sock); diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 86f1f760fd..c6bcb3e574 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -143,7 +143,7 @@ done: return; } - s = (struct sync_record *)malloc(sizeof(*s)); + s = SMB_MALLOC_P(struct sync_record); if (!s) goto done; ZERO_STRUCTP(s); diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index cce168adb2..b01ffcffc1 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -59,7 +59,7 @@ returned for name %s.\n", nmb_namestr(nmbname) )); if(num_ips == 1) { iplist = &ip; } else { - if((iplist = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr) )) == NULL) { + if((iplist = SMB_MALLOC_ARRAY( struct in_addr, num_ips )) == NULL) { DEBUG(0,("wins_proxy_name_query_request_success: malloc fail !\n")); return; } @@ -131,7 +131,7 @@ proxy query returns. static struct userdata_struct *wins_proxy_userdata_copy_fn(struct userdata_struct *userdata) { struct packet_struct *p, *copy_of_p; - struct userdata_struct *new_userdata = (struct userdata_struct *)malloc( userdata->userdata_len ); + struct userdata_struct *new_userdata = (struct userdata_struct *)SMB_MALLOC( userdata->userdata_len ); if(new_userdata == NULL) return NULL; diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 0e0289d9a3..86f5b9c426 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -318,7 +318,7 @@ BOOL initialise_wins(void) } /* Allocate the space for the ip_list. */ - if((ip_list = (struct in_addr *)malloc( num_ips * sizeof(struct in_addr))) == NULL) { + if((ip_list = SMB_MALLOC_ARRAY( struct in_addr, num_ips)) == NULL) { DEBUG(0,("initialise_wins: Malloc fail !\n")); return False; } @@ -1379,7 +1379,7 @@ static void process_wins_dmb_query_request(struct subnet_record *subrec, return; } - if((prdata = (char *)malloc( num_ips * 6 )) == NULL) { + if((prdata = (char *)SMB_MALLOC( num_ips * 6 )) == NULL) { DEBUG(0,("process_wins_dmb_query_request: Malloc fail !.\n")); return; } @@ -1442,7 +1442,7 @@ void send_wins_name_query_response(int rcode, struct packet_struct *p, if( namerec->data.num_ips == 1 ) { prdata = rdata; } else { - if((prdata = (char *)malloc( namerec->data.num_ips * 6 )) == NULL) { + if((prdata = (char *)SMB_MALLOC( namerec->data.num_ips * 6 )) == NULL) { DEBUG(0,("send_wins_name_query_response: malloc fail !\n")); return; } diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 8f3ae36b65..917116dd07 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -71,7 +71,7 @@ static struct work_record *create_workgroup(const char *name, int ttl) struct subnet_record *subrec; int t = -1; - if((work = (struct work_record *)malloc(sizeof(*work))) == NULL) { + if((work = SMB_MALLOC_P(struct work_record)) == NULL) { DEBUG(0,("create_workgroup: malloc fail !\n")); return NULL; } -- cgit From 22923f7d2d20afb758f48a371160473a2a900750 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 29 Jan 2005 02:03:46 +0000 Subject: r5076: Ensure that WINS negative name query responses and WACK packets use the correct RR type of 0xA instead of reflecting back what the query RR type was (0x20). See rfc1002 sections 4.2.14 and 4.2.16. Jeremy. (This used to be commit ab8c9240044f1ef3d5c6ac4850c8ec615c2e32fd) --- source3/nmbd/nmbd_packets.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 8a111eb957..70ea087426 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -864,6 +864,7 @@ void reply_netbios_packet(struct packet_struct *orig_packet, struct res_rec answers; struct nmb_packet *orig_nmb = &orig_packet->packet.nmb; BOOL loopback_this_packet = False; + BOOL use_null_rr_type = False; const char *packet_type = "unknown"; /* Check if we are sending to or from ourselves. */ @@ -906,6 +907,7 @@ void reply_netbios_packet(struct packet_struct *orig_packet, packet_type = "nmb_wack"; nmb->header.nm_flags.recursion_desired = False; nmb->header.nm_flags.recursion_available = False; + use_null_rr_type = True; break; case WINS_REG: packet_type = "wins_reg"; @@ -916,6 +918,9 @@ void reply_netbios_packet(struct packet_struct *orig_packet, packet_type = "wins_query"; nmb->header.nm_flags.recursion_desired = True; nmb->header.nm_flags.recursion_available = True; + if (rcode) { + use_null_rr_type = True; + } break; default: DEBUG(0,("reply_netbios_packet: Unknown packet type: %s %s to ip %s\n", @@ -947,7 +952,11 @@ for id %hu\n", packet_type, nmb_namestr(&orig_nmb->question.question_name), memset((char*)nmb->answers,'\0',sizeof(*nmb->answers)); nmb->answers->rr_name = orig_nmb->question.question_name; - nmb->answers->rr_type = orig_nmb->question.question_type; + if (use_null_rr_type) { + nmb->answers->rr_type = RR_TYPE_NULL; + } else { + nmb->answers->rr_type = orig_nmb->question.question_type; + } nmb->answers->rr_class = orig_nmb->question.question_class; nmb->answers->ttl = ttl; -- cgit From e03b7d30d59637739b7b7621a4675a87e51b8c74 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 29 Jan 2005 02:18:01 +0000 Subject: r5077: Use correct type for rr record on negative name query reply. Jeremy. (This used to be commit 86c5548d272c0804c0188ae744ae1bb17eb817f6) --- source3/nmbd/nmbd_packets.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 70ea087426..f6d267c8f1 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -891,6 +891,9 @@ void reply_netbios_packet(struct packet_struct *orig_packet, packet_type = "nmb_query"; nmb->header.nm_flags.recursion_desired = True; nmb->header.nm_flags.recursion_available = True; + if (rcode) { + use_null_rr_type = True; + } break; case NMB_REG: case NMB_REG_REFRESH: -- cgit From 7171515a01ac37a8c9cbed6bf70c3927cf38cdba Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 29 Jan 2005 02:49:01 +0000 Subject: r5082: Don't blindly copy question rr_type and class, set correctly as required by rfc1002. Jeremy. (This used to be commit 422fb43dda13e0840245ae272b7621640b8ad220) --- source3/nmbd/nmbd_packets.c | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index f6d267c8f1..4baf2d3d6c 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -864,7 +864,7 @@ void reply_netbios_packet(struct packet_struct *orig_packet, struct res_rec answers; struct nmb_packet *orig_nmb = &orig_packet->packet.nmb; BOOL loopback_this_packet = False; - BOOL use_null_rr_type = False; + int rr_type = RR_TYPE_NB; const char *packet_type = "unknown"; /* Check if we are sending to or from ourselves. */ @@ -886,13 +886,14 @@ void reply_netbios_packet(struct packet_struct *orig_packet, packet_type = "nmb_status"; nmb->header.nm_flags.recursion_desired = False; nmb->header.nm_flags.recursion_available = False; + rr_type = RR_TYPE_NBSTAT; break; case NMB_QUERY: packet_type = "nmb_query"; nmb->header.nm_flags.recursion_desired = True; nmb->header.nm_flags.recursion_available = True; if (rcode) { - use_null_rr_type = True; + rr_type = RR_TYPE_NULL; } break; case NMB_REG: @@ -910,7 +911,7 @@ void reply_netbios_packet(struct packet_struct *orig_packet, packet_type = "nmb_wack"; nmb->header.nm_flags.recursion_desired = False; nmb->header.nm_flags.recursion_available = False; - use_null_rr_type = True; + rr_type = RR_TYPE_NULL; break; case WINS_REG: packet_type = "wins_reg"; @@ -922,7 +923,7 @@ void reply_netbios_packet(struct packet_struct *orig_packet, nmb->header.nm_flags.recursion_desired = True; nmb->header.nm_flags.recursion_available = True; if (rcode) { - use_null_rr_type = True; + rr_type = RR_TYPE_NULL; } break; default: @@ -955,12 +956,8 @@ for id %hu\n", packet_type, nmb_namestr(&orig_nmb->question.question_name), memset((char*)nmb->answers,'\0',sizeof(*nmb->answers)); nmb->answers->rr_name = orig_nmb->question.question_name; - if (use_null_rr_type) { - nmb->answers->rr_type = RR_TYPE_NULL; - } else { - nmb->answers->rr_type = orig_nmb->question.question_type; - } - nmb->answers->rr_class = orig_nmb->question.question_class; + nmb->answers->rr_type = rr_type; + nmb->answers->rr_class = RR_CLASS_IN; nmb->answers->ttl = ttl; if (data && len) { -- cgit From a6c895de85b8f1d2368515b58b7d02541954a190 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 9 Mar 2005 22:20:40 +0000 Subject: r5717: BUG 2215: horrible code in nmbd_winsproxy.c; gcc folks at redhat claim its in violation of the C spec. It's so horrible I believe them (This used to be commit fa7eb5693314efb14d42a739f8006ddf8d41e9d5) --- source3/nmbd/nmbd_winsproxy.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index b01ffcffc1..7531972461 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -190,12 +190,15 @@ void make_wins_proxy_name_query_request( struct subnet_record *subrec, struct packet_struct *incoming_packet, struct nmb_name *question_name) { - long *ud[(sizeof(struct userdata_struct) + sizeof(struct subrec *) + - sizeof(struct packet_struct *))/sizeof(long *) + 1]; - struct userdata_struct *userdata = (struct userdata_struct *)ud; + union { + struct userdata_struct ud; + char c[sizeof(struct userdata_struct) + sizeof(struct subrec *) + + sizeof(struct packet_struct *)+sizeof(long*)]; + } ud; + struct userdata_struct *userdata = &ud.ud; unstring qname; - memset(ud, '\0', sizeof(ud)); + memset(&ud, '\0', sizeof(ud)); userdata->copy_fn = wins_proxy_userdata_copy_fn; userdata->free_fn = wins_proxy_userdata_free_fn; -- cgit From 978ca8486031e43754a3c23757f361bf3a85f335 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Wed, 6 Apr 2005 16:28:04 +0000 Subject: r6225: get rid of warnings from my compiler about nested externs (This used to be commit efea76ac71412f8622cd233912309e91b9ea52da) --- source3/nmbd/nmbd.c | 4 ++-- source3/nmbd/nmbd_subnetdb.c | 2 +- source3/nmbd/nmbd_synclists.c | 3 ++- 3 files changed, 5 insertions(+), 4 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index f8006a22a9..532b578f3c 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -27,6 +27,8 @@ int ClientNMB = -1; int ClientDGRAM = -1; int global_nmb_port = -1; +extern BOOL rescan_listen_set; +extern struct in_addr loopback_ip; extern BOOL global_in_nmbd; extern BOOL override_logfile; @@ -196,8 +198,6 @@ static BOOL reload_interfaces(time_t t) static time_t lastt; int n; struct subnet_record *subrec; - extern BOOL rescan_listen_set; - extern struct in_addr loopback_ip; if (t && ((t - lastt) < NMBD_INTERFACES_RELOAD)) return False; lastt = t; diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index ecfd92719b..b53a6d7328 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -25,6 +25,7 @@ #include "includes.h" +extern struct in_addr loopback_ip; extern int ClientNMB; extern int ClientDGRAM; extern int global_nmb_port; @@ -211,7 +212,6 @@ BOOL create_subnets(void) int num_interfaces = iface_count(); int i; struct in_addr unicast_ip, ipzero; - extern struct in_addr loopback_ip; if(num_interfaces == 0) { DEBUG(0,("create_subnets: No local interfaces !\n")); diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index c6bcb3e574..33690133bf 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -29,6 +29,8 @@ #include "includes.h" +extern fstring local_machine; + struct sync_record { struct sync_record *next, *prev; unstring workgroup; @@ -65,7 +67,6 @@ static void sync_child(char *name, int nm_type, struct in_addr ip, BOOL local, BOOL servers, char *fname) { - extern fstring local_machine; fstring unix_workgroup; static struct cli_state cli; uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0; -- cgit From fed660877c16562265327c6093ea645cf4176b5c Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 8 Jun 2005 22:10:34 +0000 Subject: r7415: * big change -- volker's new async winbindd from trunk (This used to be commit a0ac9a8ffd4af31a0ebc423b4acbb2f043d865b8) --- source3/nmbd/nmbd.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 532b578f3c..af93bf5197 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -323,6 +323,56 @@ static void msg_reload_nmbd_services(int msg_type, pid_t src, void *buf, size_t } } +static void msg_nmbd_send_packet(int msg_type, pid_t src, + void *buf, size_t len) +{ + struct packet_struct *p = (struct packet_struct *)buf; + struct subnet_record *subrec; + struct in_addr *local_ip; + + DEBUG(10, ("Received send_packet from %d\n", src)); + + if (len != sizeof(struct packet_struct)) { + DEBUG(2, ("Discarding invalid packet length from %d\n", src)); + return; + } + + if ((p->packet_type != NMB_PACKET) && + (p->packet_type != DGRAM_PACKET)) { + DEBUG(2, ("Discarding invalid packet type from %d: %d\n", + src, p->packet_type)); + return; + } + + local_ip = iface_ip(p->ip); + + if (local_ip == NULL) { + DEBUG(2, ("Could not find ip for packet from %d\n", src)); + return; + } + + subrec = FIRST_SUBNET; + + p->fd = (p->packet_type == NMB_PACKET) ? + subrec->nmb_sock : subrec->dgram_sock; + + for (subrec = FIRST_SUBNET; subrec != NULL; + subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { + if (ip_equal(*local_ip, subrec->myip)) { + p->fd = (p->packet_type == NMB_PACKET) ? + subrec->nmb_sock : subrec->dgram_sock; + break; + } + } + + if (p->packet_type == DGRAM_PACKET) { + p->port = 138; + p->packet.dgram.header.source_ip.s_addr = local_ip->s_addr; + p->packet.dgram.header.source_port = 138; + } + + send_packet(p); +} /**************************************************************************** ** The main select loop. @@ -720,6 +770,7 @@ static BOOL open_sockets(BOOL isdaemon, int port) message_register(MSG_WINS_NEW_ENTRY, nmbd_wins_new_entry); message_register(MSG_SHUTDOWN, nmbd_terminate); message_register(MSG_SMB_CONF_UPDATED, msg_reload_nmbd_services); + message_register(MSG_SEND_PACKET, msg_nmbd_send_packet); DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); -- cgit From 129b461673ecd0ad4d16c0c99585dd5c067172df Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Thu, 9 Jun 2005 15:20:11 +0000 Subject: r7440: * merge registry server changes from trunk (so far) for more printmig.exe work * merge the sys_select_signal(char c) change from trunk in order to keeo the winbind code in sync (This used to be commit a112c5570a7f8ddddde1af0fa665f40a6067e8cf) --- source3/nmbd/nmbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index af93bf5197..97e22943b1 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -90,7 +90,7 @@ static SIG_ATOMIC_T got_sig_term; static void sig_term(int sig) { got_sig_term = 1; - sys_select_signal(); + sys_select_signal(SIGTERM); } /**************************************************************************** ** @@ -102,7 +102,7 @@ static SIG_ATOMIC_T reload_after_sighup; static void sig_hup(int sig) { reload_after_sighup = 1; - sys_select_signal(); + sys_select_signal(SIGHUP); } #if DUMP_CORE -- cgit From 311cf22a2e028d560000da0645abd3625d1cbd3d Mon Sep 17 00:00:00 2001 From: Tim Potter Date: Tue, 2 Aug 2005 20:44:30 +0000 Subject: r8946: Some casts to fix warnings when time_t is an unsigned type. Fixes bugzilla #1888 and #1894. (This used to be commit dcc74371388d280d8ee5130a04e1594ae88d19b3) --- source3/nmbd/nmbd_workgroupdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 917116dd07..335d522031 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -322,7 +322,7 @@ void expire_workgroups_and_servers(time_t t) expire_servers(work, t); if ((work->serverlist == NULL) && (work->death_time != PERMANENT_TTL) && - ((t == -1) || (work->death_time < t))) { + ((t == (time_t)-1) || (work->death_time < t))) { DEBUG(3,("expire_workgroups_and_servers: Removing timed out workgroup %s\n", work->work_group)); remove_workgroup_from_subnet(subrec, work); -- cgit From 2f626e7b5ad2d921490723e32863bd423e8272cd Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Tue, 30 Aug 2005 11:41:45 +0000 Subject: r9790: remove 'set but not used' variables (reported by Jason Mader) (This used to be commit 9c78f3b0d6c36854e082a89cb1ee5b80fcc9fe35) --- source3/nmbd/nmbd.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 97e22943b1..bc58dd3a28 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -650,7 +650,6 @@ static BOOL open_sockets(BOOL isdaemon, int port) pstring logfile; static BOOL opt_interactive; poptContext pc; - int opt; struct poptOption long_options[] = { POPT_AUTOHELP {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon(default)" }, @@ -666,7 +665,7 @@ static BOOL open_sockets(BOOL isdaemon, int port) global_nmb_port = NMB_PORT; pc = poptGetContext("nmbd", argc, argv, long_options, 0); - while ((opt = poptGetNextOpt(pc)) != -1) ; + while (poptGetNextOpt(pc) != -1) {}; poptFreeContext(pc); global_in_nmbd = True; -- cgit From 54abd2aa66069e6baf7769c496f46d9dba18db39 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 30 Sep 2005 17:13:37 +0000 Subject: r10656: BIG merge from trunk. Features not copied over * \PIPE\unixinfo * winbindd's {group,alias}membership new functions * winbindd's lookupsids() functionality * swat (trunk changes to be reverted as per discussion with Deryck) (This used to be commit 939c3cb5d78e3a2236209b296aa8aba8bdce32d3) --- source3/nmbd/asyncdns.c | 2 +- source3/nmbd/nmbd.c | 21 +++++++++++++-------- source3/nmbd/nmbd_elections.c | 3 ++- source3/nmbd/nmbd_packets.c | 4 ++-- source3/nmbd/nmbd_synclists.c | 2 +- source3/nmbd/nmbd_winsserver.c | 3 ++- 6 files changed, 21 insertions(+), 14 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 653cb97fbb..4db54ea198 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -201,7 +201,7 @@ void run_dns_queue(void) /* Allow SIGTERM to kill us. */ BlockSignals(False, SIGTERM); - if (!process_exists(child_pid)) { + if (!process_exists_by_pid(child_pid)) { close(fd_in); start_async_dns(); } diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index bc58dd3a28..fcaba03b3d 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -76,7 +76,8 @@ static void terminate(void) Handle a SHUTDOWN message from smbcontrol. **************************************************************************** */ -static void nmbd_terminate(int msg_type, pid_t src, void *buf, size_t len) +static void nmbd_terminate(int msg_type, struct process_id src, + void *buf, size_t len) { terminate(); } @@ -307,7 +308,8 @@ static BOOL reload_nmbd_services(BOOL test) * detects that there are no subnets. **************************************************************************** */ -static void msg_reload_nmbd_services(int msg_type, pid_t src, void *buf, size_t len) +static void msg_reload_nmbd_services(int msg_type, struct process_id src, + void *buf, size_t len) { write_browse_list( 0, True ); dump_all_namelists(); @@ -323,31 +325,33 @@ static void msg_reload_nmbd_services(int msg_type, pid_t src, void *buf, size_t } } -static void msg_nmbd_send_packet(int msg_type, pid_t src, +static void msg_nmbd_send_packet(int msg_type, struct process_id src, void *buf, size_t len) { struct packet_struct *p = (struct packet_struct *)buf; struct subnet_record *subrec; struct in_addr *local_ip; - DEBUG(10, ("Received send_packet from %d\n", src)); + DEBUG(10, ("Received send_packet from %d\n", procid_to_pid(&src))); if (len != sizeof(struct packet_struct)) { - DEBUG(2, ("Discarding invalid packet length from %d\n", src)); + DEBUG(2, ("Discarding invalid packet length from %d\n", + procid_to_pid(&src))); return; } if ((p->packet_type != NMB_PACKET) && (p->packet_type != DGRAM_PACKET)) { DEBUG(2, ("Discarding invalid packet type from %d: %d\n", - src, p->packet_type)); + procid_to_pid(&src), p->packet_type)); return; } local_ip = iface_ip(p->ip); if (local_ip == NULL) { - DEBUG(2, ("Could not find ip for packet from %d\n", src)); + DEBUG(2, ("Could not find ip for packet from %d\n", + procid_to_pid(&src))); return; } @@ -590,7 +594,8 @@ static void process(void) if(reload_after_sighup) { DEBUG( 0, ( "Got SIGHUP dumping debug info.\n" ) ); - msg_reload_nmbd_services(MSG_SMB_CONF_UPDATED, (pid_t) 0, (void*) &no_subnets, 0); + msg_reload_nmbd_services(MSG_SMB_CONF_UPDATED, + pid_to_procid(0), (void*) &no_subnets, 0); if(no_subnets) return; reload_after_sighup = 0; diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 470cf4277b..6e8e8429be 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -374,7 +374,8 @@ yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name )); Process a internal Samba message forcing an election. ***************************************************************************/ -void nmbd_message_election(int msg_type, pid_t src, void *buf, size_t len) +void nmbd_message_election(int msg_type, struct process_id src, + void *buf, size_t len) { struct subnet_record *subrec; diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 4baf2d3d6c..c25473c4fb 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1246,7 +1246,7 @@ packet sent to name %s from IP %s\n", packet sent to name %s from IP %s\n", dgram->datasize, len, - PTR_DIFF(buf2, dgram->data), + (int)PTR_DIFF(buf2, dgram->data), nmb_namestr(&dgram->dest_name), inet_ntoa(p->ip) )); return; @@ -1257,7 +1257,7 @@ packet sent to name %s from IP %s\n", packet sent to name %s from IP %s\n", dgram->datasize, len, - PTR_DIFF(buf2, dgram->data), + (int)PTR_DIFF(buf2, dgram->data), nmb_namestr(&dgram->dest_name), inet_ntoa(p->ip) )); return; diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 33690133bf..28ad92ed10 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -294,7 +294,7 @@ void sync_check_completion(void) for (s=syncs;s;s=next) { next = s->next; - if (!process_exists(s->pid)) { + if (!process_exists_by_pid(s->pid)) { /* it has completed - grab the info */ complete_sync(s); DLIST_REMOVE(syncs, s); diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 86f5b9c426..d76cb8f032 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1874,7 +1874,8 @@ void wins_write_database(BOOL background) Process a internal Samba message receiving a wins record. ***************************************************************************/ -void nmbd_wins_new_entry(int msg_type, pid_t src, void *buf, size_t len) +void nmbd_wins_new_entry(int msg_type, struct process_id src, + void *buf, size_t len) { WINS_RECORD *record; struct name_record *namerec = NULL; -- cgit From 8ec32e008a2309e04d954bd7c6740740735628db Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Fri, 7 Oct 2005 15:43:32 +0000 Subject: r10822: updating copyright info (This used to be commit ef3845366bc883e735b2008243b7c05a403f42ca) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index fcaba03b3d..086878e221 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -720,7 +720,7 @@ static BOOL open_sockets(BOOL isdaemon, int port) reopen_logs(); DEBUG( 0, ( "Netbios nameserver version %s started.\n", SAMBA_VERSION_STRING) ); - DEBUGADD( 0, ( "Copyright Andrew Tridgell and the Samba Team 1994-2004\n" ) ); + DEBUGADD( 0, ( "%s\n", COPYRIGHT_STARTUP_MESSAGE ) ); if ( !reload_nmbd_services(False) ) return(-1); -- cgit From 6d5757395a0e54245543794d0d6d6d6a32cd857a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 5 Nov 2005 04:21:55 +0000 Subject: r11511: A classic "friday night check-in" :-). This moves much of the Samba4 timezone handling code back into Samba3. Gets rid of "kludge-gmt" and removes the effectiveness of the parameter "time offset" (I can add this back in very easily if needed) - it's no longer being looked at. I'm hoping this will fix the problems people have been having with DST transitions. I'll start comprehensive testing tomorrow, but for now all modifications are done. Splits time get/set functions into srv_XXX and cli_XXX as they need to look at different timezone offsets. Get rid of much of the "efficiency" cruft that was added to Samba back in the day when the C library timezone handling functions were slow. Jeremy. (This used to be commit 414303bc0272f207046b471a0364fa296b67c1f8) --- source3/nmbd/nmbd.c | 2 ++ source3/nmbd/nmbd_namelistdb.c | 4 ++-- source3/nmbd/nmbd_winsserver.c | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 086878e221..282857ef98 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -776,6 +776,8 @@ static BOOL open_sockets(BOOL isdaemon, int port) message_register(MSG_SMB_CONF_UPDATED, msg_reload_nmbd_services); message_register(MSG_SEND_PACKET, msg_nmbd_send_packet); + TimeInit(); + DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); if ( !open_sockets( is_daemon, global_nmb_port ) ) { diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index bdb308a2ea..344d3c7ca1 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -530,14 +530,14 @@ static void dump_subnet_namelist( struct subnet_record *subrec, XFILE *fp) x_fprintf(fp,"Source = %s\nb_flags = %x\t", src_type, namerec->data.nb_flags); if(namerec->data.death_time != PERMANENT_TTL) { - tm = LocalTime(&namerec->data.death_time); + tm = localtime(&namerec->data.death_time); x_fprintf(fp, "death_time = %s\t", asctime(tm)); } else { x_fprintf(fp, "death_time = PERMANENT\t"); } if(namerec->data.refresh_time != PERMANENT_TTL) { - tm = LocalTime(&namerec->data.refresh_time); + tm = localtime(&namerec->data.refresh_time); x_fprintf(fp, "refresh_time = %s\n", asctime(tm)); } else { x_fprintf(fp, "refresh_time = PERMANENT\n"); diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index d76cb8f032..8a1f82c8b1 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1835,7 +1835,7 @@ void wins_write_database(BOOL background) if( namerec->data.death_time != PERMANENT_TTL ) { char *ts, *nl; - tm = LocalTime(&namerec->data.death_time); + tm = localtime(&namerec->data.death_time); ts = asctime(tm); nl = strrchr( ts, '\n' ); if( NULL != nl ) -- cgit From c3d673e5712b254ea6e3eef10041f3a30b70a983 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 7 Nov 2005 23:28:42 +0000 Subject: r11566: From metze. Use "interpret_addr(lp_socket_address())" for port 138. Jeremy. (This used to be commit d398a1aeb48422a89cee59d5760a87bbb2d50b03) --- source3/nmbd/nmbd.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 282857ef98..01fdb8e74c 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -632,7 +632,9 @@ static BOOL open_sockets(BOOL isdaemon, int port) else ClientNMB = 0; - ClientDGRAM = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3,0,True); + ClientDGRAM = open_socket_in(SOCK_DGRAM, DGRAM_PORT, + 3, interpret_addr(lp_socket_address()), + True); if ( ClientNMB == -1 ) return( False ); -- cgit From d1f91f7c723733113b4e9792042101c80dfc064c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Dec 2005 06:46:46 +0000 Subject: r12043: It's amazing the warnings you find when compiling on a 64-bit box with gcc4 and -O6... Fix a bunch of C99 dereferencing type-punned pointer will break strict-aliasing rules errors. Also added prs_int32 (not uint32...) as it's needed in one place. Find places where prs_uint32 was being used to marshall/unmarshall a time_t (a big no no on 64-bits). More warning fixes to come. Thanks to Volker for nudging me to compile like this. Jeremy. (This used to be commit c65b752604f8f58abc4e7ae8514dc2c7f086271c) --- source3/nmbd/nmbd_namelistdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 344d3c7ca1..88d5ea52f5 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -78,7 +78,7 @@ static void update_name_in_namelist( struct subnet_record *subrec, { struct name_record *oldrec = NULL; - ubi_trInsert( subrec->namelist, namerec, &(namerec->name), &oldrec ); + ubi_trInsert( subrec->namelist, namerec, &namerec->name, &oldrec ); if( oldrec ) { SAFE_FREE( oldrec->data.ip ); SAFE_FREE( oldrec ); -- cgit From 83b987befdbba857131102700d237728784b6f69 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 6 Dec 2005 23:06:38 +0000 Subject: r12107: Move to a tdb-based wins database. At the moment we still use it as though it were an in-memory db and dump out to a flat file every 2 mins, but that can now change. Jeremy. (This used to be commit a342681792724c1ae8561ba8d352c4ee6e2a5332) --- source3/nmbd/asyncdns.c | 26 +- source3/nmbd/nmbd.c | 5 +- source3/nmbd/nmbd_browserdb.c | 22 +- source3/nmbd/nmbd_browsesync.c | 6 +- source3/nmbd/nmbd_incomingrequests.c | 6 +- source3/nmbd/nmbd_mynames.c | 8 +- source3/nmbd/nmbd_namelistdb.c | 327 ++++++++------ source3/nmbd/nmbd_subnetdb.c | 33 +- source3/nmbd/nmbd_winsproxy.c | 22 +- source3/nmbd/nmbd_winsserver.c | 801 +++++++++++++++++++++++++++-------- 10 files changed, 882 insertions(+), 374 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 4db54ea198..c0626d1161 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -34,16 +34,18 @@ static struct name_record *add_dns_result(struct nmb_name *question, struct in_a if (!addr.s_addr) { /* add the fail to WINS cache of names. give it 1 hour in the cache */ DEBUG(3,("add_dns_result: Negative DNS answer for %s\n", qname)); - (void)add_name_to_subnet( wins_server_subnet, qname, name_type, + add_name_to_subnet( wins_server_subnet, qname, name_type, NB_ACTIVE, 60*60, DNSFAIL_NAME, 1, &addr ); - return( NULL ); + return NULL; } /* add it to our WINS cache of names. give it 2 hours in the cache */ DEBUG(3,("add_dns_result: DNS gave answer for %s of %s\n", qname, inet_ntoa(addr))); - return( add_name_to_subnet( wins_server_subnet, qname, name_type, - NB_ACTIVE, 2*60*60, DNS_NAME, 1, &addr ) ); + add_name_to_subnet( wins_server_subnet, qname, name_type, + NB_ACTIVE, 2*60*60, DNS_NAME, 1, &addr); + + return find_name_on_subnet(wins_server_subnet, question, FIND_ANY_NAME); } #ifndef SYNC_DNS @@ -283,8 +285,7 @@ void run_dns_queue(void) queue a DNS query ****************************************************************************/ -BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, - struct name_record **n) +BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question) { if (in_dns || fd_in == -1) return False; @@ -316,9 +317,9 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, we use this when we can't do async DNS lookups ****************************************************************************/ -BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, - struct name_record **n) +BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question) { + struct name_record *namerec = NULL; struct in_addr dns_ip; unstring qname; @@ -334,11 +335,12 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question, /* Re-block TERM signal. */ BlockSignals(True, SIGTERM); - *n = add_dns_result(question, dns_ip); - if(*n == NULL) + namerec = add_dns_result(question, dns_ip); + if(namerec == NULL) { send_wins_name_query_response(NAM_ERR, p, NULL); - else - send_wins_name_query_response(0, p, *n); + } else { + send_wins_name_query_response(0, p, namerec); + } return False; } diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 01fdb8e74c..78411d3417 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -58,7 +58,7 @@ static void terminate(void) DEBUG(0,("Got SIGTERM: going down...\n")); /* Write out wins.dat file if samba is a WINS server */ - wins_write_database(False); + wins_write_database(0,False); /* Remove all SELF registered names from WINS */ release_wins_names(); @@ -773,7 +773,10 @@ static BOOL open_sockets(BOOL isdaemon, int port) pidfile_create("nmbd"); message_init(); message_register(MSG_FORCE_ELECTION, nmbd_message_election); +#if 0 + /* Until winsrepl is done. */ message_register(MSG_WINS_NEW_ENTRY, nmbd_wins_new_entry); +#endif message_register(MSG_SHUTDOWN, nmbd_terminate); message_register(MSG_SMB_CONF_UPDATED, msg_reload_nmbd_services); message_register(MSG_SEND_PACKET, msg_nmbd_send_packet); diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c index e8797a99d5..e27e483702 100644 --- a/source3/nmbd/nmbd_browserdb.c +++ b/source3/nmbd/nmbd_browserdb.c @@ -35,7 +35,7 @@ * lmb_browserlist - This is our local master browser list. */ -ubi_dlNewList( lmb_browserlist ); +struct browse_cache_record *lmb_browserlist; /* -------------------------------------------------------------------------- ** * Functions... @@ -52,7 +52,8 @@ ubi_dlNewList( lmb_browserlist ); */ static void remove_lmb_browser_entry( struct browse_cache_record *browc ) { - safe_free( ubi_dlRemThis( lmb_browserlist, browc ) ); + DLIST_REMOVE(lmb_browserlist, browc); + SAFE_FREE(browc); } /* ************************************************************************** ** @@ -85,6 +86,7 @@ struct browse_cache_record *create_browser_in_lmb_cache( const char *work_name, struct in_addr ip ) { struct browse_cache_record *browc; + struct browse_cache_record *tmp_browc; time_t now = time( NULL ); browc = SMB_MALLOC_P(struct browse_cache_record); @@ -113,7 +115,7 @@ struct browse_cache_record *create_browser_in_lmb_cache( const char *work_name, browc->ip = ip; - (void)ubi_dlAddTail( lmb_browserlist, browc ); + DLIST_ADD_END(lmb_browserlist, browc, tmp_browc); if( DEBUGLVL( 3 ) ) { Debug1( "nmbd_browserdb:create_browser_in_lmb_cache()\n" ); @@ -138,12 +140,13 @@ struct browse_cache_record *find_browser_in_lmb_cache( const char *browser_name { struct browse_cache_record *browc; - for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist ); - browc; browc = (struct browse_cache_record *)ubi_dlNext( browc ) ) - if( strequal( browser_name, browc->lmb_name ) ) + for( browc = lmb_browserlist; browc; browc = browc->next ) { + if( strequal( browser_name, browc->lmb_name ) ) { break; + } + } - return( browc ); + return browc; } /* ************************************************************************** ** @@ -160,9 +163,8 @@ void expire_lmb_browsers( time_t t ) struct browse_cache_record *browc; struct browse_cache_record *nextbrowc; - for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist ); - browc; browc = nextbrowc ) { - nextbrowc = (struct browse_cache_record *)ubi_dlNext( browc ); + for( browc = lmb_browserlist; browc; browc = nextbrowc) { + nextbrowc = browc->next; if( browc->death_time < t ) { if( DEBUGLVL( 3 ) ) { diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 03234bb98f..9535a3115a 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -24,7 +24,7 @@ #include "includes.h" /* This is our local master browser list database. */ -extern ubi_dlList lmb_browserlist[]; +extern struct browse_cache_record *lmb_browserlist; /**************************************************************************** As a domain master browser, do a sync with a local master browser. @@ -87,9 +87,7 @@ void dmb_expire_and_sync_browser_lists(time_t t) expire_lmb_browsers(t); - for( browc = (struct browse_cache_record *)ubi_dlFirst( lmb_browserlist ); - browc; - browc = (struct browse_cache_record *)ubi_dlNext( browc ) ) { + for( browc = lmb_browserlist; browc; browc = browc->next ) { if (browc->sync_time < t) sync_with_lmb(browc); } diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index 7fac8c2573..eaef7097b4 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -339,7 +339,7 @@ subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name), names_added = 0; - namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); + namerec = subrec->namelist; while (buf < bufend) { if( (namerec->data.source == SELF_NAME) || (namerec->data.source == PERMANENT_NAME) ) { @@ -389,7 +389,7 @@ subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name), buf = buf0 + 18*names_added; - namerec = (struct name_record *)ubi_trNext( namerec ); + namerec = namerec->next; if (!namerec) { /* End of the subnet specific name list. Now @@ -398,7 +398,7 @@ subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name), if (uni_subrec != subrec) { subrec = uni_subrec; - namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); + namerec = subrec->namelist; } } if (!namerec) diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index 07247d5495..f34d98172c 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -182,8 +182,8 @@ void release_wins_names(void) struct subnet_record *subrec = unicast_subnet; struct name_record *namerec, *nextnamerec; - for (namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); namerec; namerec = nextnamerec) { - nextnamerec = (struct name_record *)ubi_trNext( namerec ); + for (namerec = subrec->namelist; namerec; namerec = nextnamerec) { + nextnamerec = namerec->next; if( (namerec->data.source == SELF_NAME) && !NAME_IS_DEREGISTERING(namerec) ) release_name( subrec, namerec, standard_success_release, @@ -202,9 +202,7 @@ void refresh_my_names(time_t t) if (wins_srv_count() < 1) return; - for (namerec = (struct name_record *)ubi_trFirst(unicast_subnet->namelist); - namerec; - namerec = (struct name_record *)ubi_trNext(namerec)) { + for (namerec = unicast_subnet->namelist; namerec; namerec = namerec->next) { /* Each SELF name has an individual time to be refreshed. */ if ((namerec->data.source == SELF_NAME) && (namerec->data.refresh_time < t) && diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 88d5ea52f5..894b877613 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -32,24 +32,26 @@ uint16 samba_nb_type = 0; /* samba's NetBIOS name type */ void set_samba_nb_type(void) { - if( lp_wins_support() || wins_srv_count() ) + if( lp_wins_support() || wins_srv_count() ) { samba_nb_type = NB_HFLAG; /* samba is a 'hybrid' node type. */ - else + } else { samba_nb_type = NB_BFLAG; /* samba is broadcast-only node type. */ + } } /*************************************************************************** Convert a NetBIOS name to upper case. ***************************************************************************/ -static void upcase_name( struct nmb_name *target, struct nmb_name *source ) +static void upcase_name( struct nmb_name *target, const struct nmb_name *source ) { int i; unstring targ; fstring scope; - if( NULL != source ) + if( NULL != source ) { memcpy( target, source, sizeof( struct nmb_name ) ); + } pull_ascii_nstring(targ, sizeof(targ), target->name); strupper_m( targ ); @@ -63,25 +65,11 @@ static void upcase_name( struct nmb_name *target, struct nmb_name *source ) * unused space doesn't have garbage in it. */ - for( i = strlen( target->name ); i < sizeof( target->name ); i++ ) + for( i = strlen( target->name ); i < sizeof( target->name ); i++ ) { target->name[i] = '\0'; - for( i = strlen( target->scope ); i < sizeof( target->scope ); i++ ) + } + for( i = strlen( target->scope ); i < sizeof( target->scope ); i++ ) { target->scope[i] = '\0'; -} - -/************************************************************************** - Add a new or overwrite an existing namelist entry. -***************************************************************************/ - -static void update_name_in_namelist( struct subnet_record *subrec, - struct name_record *namerec ) -{ - struct name_record *oldrec = NULL; - - ubi_trInsert( subrec->namelist, namerec, &namerec->name, &oldrec ); - if( oldrec ) { - SAFE_FREE( oldrec->data.ip ); - SAFE_FREE( oldrec ); } } @@ -89,64 +77,81 @@ static void update_name_in_namelist( struct subnet_record *subrec, Remove a name from the namelist. ***************************************************************************/ -void remove_name_from_namelist( struct subnet_record *subrec, - struct name_record *namerec ) +void remove_name_from_namelist(struct subnet_record *subrec, + struct name_record *namerec ) { - ubi_trRemove( subrec->namelist, namerec ); + if (subrec == wins_server_subnet) { + remove_name_from_wins_namelist(namerec); + } else { + subrec->namelist_changed = True; + } + DLIST_REMOVE(subrec->namelist, namerec); SAFE_FREE(namerec->data.ip); ZERO_STRUCTP(namerec); SAFE_FREE(namerec); - subrec->namelist_changed = True; } /************************************************************************** Find a name in a subnet. **************************************************************************/ -struct name_record *find_name_on_subnet( struct subnet_record *subrec, - struct nmb_name *nmbname, - BOOL self_only ) +struct name_record *find_name_on_subnet(struct subnet_record *subrec, + const struct nmb_name *nmbname, + BOOL self_only) { - struct nmb_name uc_name[1]; + struct nmb_name uc_name; struct name_record *name_ret; - upcase_name( uc_name, nmbname ); - name_ret = (struct name_record *)ubi_trFind( subrec->namelist, uc_name ); + upcase_name( &uc_name, nmbname ); + + if (subrec == wins_server_subnet) { + return find_name_on_wins_subnet(&uc_name, self_only); + } + + for( name_ret = subrec->namelist; name_ret; name_ret = name_ret->next) { + if (memcmp(&uc_name, &name_ret->name, sizeof(struct nmb_name)) == 0) { + break; + } + } + if( name_ret ) { /* Self names only - these include permanent names. */ if( self_only && (name_ret->data.source != SELF_NAME) && (name_ret->data.source != PERMANENT_NAME) ) { DEBUG( 9, ( "find_name_on_subnet: on subnet %s - self name %s NOT FOUND\n", subrec->subnet_name, nmb_namestr(nmbname) ) ); - return( NULL ); + return False; } DEBUG( 9, ("find_name_on_subnet: on subnet %s - found name %s source=%d\n", subrec->subnet_name, nmb_namestr(nmbname), name_ret->data.source) ); - return( name_ret ); + + return name_ret; } DEBUG( 9, ( "find_name_on_subnet: on subnet %s - name %s NOT FOUND\n", subrec->subnet_name, nmb_namestr(nmbname) ) ); - return( NULL ); + + return NULL; } /************************************************************************** Find a name over all known broadcast subnets. ************************************************************************/ -struct name_record *find_name_for_remote_broadcast_subnet( - struct nmb_name *nmbname, - BOOL self_only ) +struct name_record *find_name_for_remote_broadcast_subnet(struct nmb_name *nmbname, + BOOL self_only) { struct subnet_record *subrec; - struct name_record *namerec = NULL; + struct name_record *namerec; for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) ) { - if( NULL != (namerec = find_name_on_subnet(subrec, nmbname, self_only)) ) - break; + namerec = find_name_on_subnet(subrec, nmbname, self_only); + if (namerec) { + return namerec; + } } - return( namerec ); + return NULL; } /************************************************************************** @@ -157,34 +162,40 @@ void update_name_ttl( struct name_record *namerec, int ttl ) { time_t time_now = time(NULL); - if( namerec->data.death_time != PERMANENT_TTL ) + if( namerec->data.death_time != PERMANENT_TTL) { namerec->data.death_time = time_now + ttl; + } namerec->data.refresh_time = time_now + MIN((ttl/2), MAX_REFRESH_TIME); - namerec->subnet->namelist_changed = True; + if (namerec->subnet == wins_server_subnet) { + wins_store_changed_namerec(namerec); + } else { + namerec->subnet->namelist_changed = True; + } } /************************************************************************** Add an entry to a subnet name list. ***********************************************************************/ -struct name_record *add_name_to_subnet( struct subnet_record *subrec, - const char *name, - int type, - uint16 nb_flags, - int ttl, - enum name_source source, - int num_ips, - struct in_addr *iplist) +BOOL add_name_to_subnet( struct subnet_record *subrec, + const char *name, + int type, + uint16 nb_flags, + int ttl, + enum name_source source, + int num_ips, + struct in_addr *iplist) { + BOOL ret = False; struct name_record *namerec; time_t time_now = time(NULL); namerec = SMB_MALLOC_P(struct name_record); if( NULL == namerec ) { DEBUG( 0, ( "add_name_to_subnet: malloc fail.\n" ) ); - return( NULL ); + return False; } memset( (char *)namerec, '\0', sizeof(*namerec) ); @@ -193,7 +204,7 @@ struct name_record *add_name_to_subnet( struct subnet_record *subrec, DEBUG( 0, ( "add_name_to_subnet: malloc fail when creating ip_flgs.\n" ) ); ZERO_STRUCTP(namerec); SAFE_FREE(namerec); - return NULL; + return False; } namerec->subnet = subrec; @@ -206,8 +217,9 @@ struct name_record *add_name_to_subnet( struct subnet_record *subrec, namerec->data.wins_flags = WINS_ACTIVE; /* If it's our primary name, flag it as so. */ - if( strequal( my_netbios_names(0), name ) ) + if (strequal( my_netbios_names(0), name )) { namerec->data.nb_flags |= NB_PERM; + } /* Copy the IPs. */ namerec->data.num_ips = num_ips; @@ -217,16 +229,14 @@ struct name_record *add_name_to_subnet( struct subnet_record *subrec, namerec->data.source = source; /* Setup the death_time and refresh_time. */ - if( ttl == PERMANENT_TTL ) + if (ttl == PERMANENT_TTL) { namerec->data.death_time = PERMANENT_TTL; - else + } else { namerec->data.death_time = time_now + ttl; + } namerec->data.refresh_time = time_now + MIN((ttl/2), MAX_REFRESH_TIME); - /* Now add the record to the name list. */ - update_name_in_namelist( subrec, namerec ); - DEBUG( 3, ( "add_name_to_subnet: Added netbios name %s with first IP %s \ ttl=%d nb_flags=%2x to subnet %s\n", nmb_namestr( &namerec->name ), @@ -235,9 +245,20 @@ ttl=%d nb_flags=%2x to subnet %s\n", (unsigned int)nb_flags, subrec->subnet_name ) ); - subrec->namelist_changed = True; + /* Now add the record to the name list. */ + + if (subrec == wins_server_subnet) { + ret = add_name_to_wins_subnet(namerec); + /* Free namerec - it's stored in the tdb. */ + SAFE_FREE(namerec->data.ip); + SAFE_FREE(namerec); + } else { + DLIST_ADD(subrec->namelist, namerec); + subrec->namelist_changed = True; + ret = True; + } - return(namerec); + return ret; } /******************************************************************* @@ -253,8 +274,8 @@ void standard_success_register(struct subnet_record *subrec, { struct name_record *namerec; - namerec = find_name_on_subnet( subrec, nmbname, FIND_SELF_NAME ); - if( NULL == namerec ) { + namerec = find_name_on_subnet( subrec, nmbname, FIND_SELF_NAME); + if (namerec == NULL) { unstring name; pull_ascii_nstring(name, sizeof(name), nmbname->name); add_name_to_subnet( subrec, name, nmbname->name_type, @@ -277,14 +298,15 @@ void standard_fail_register( struct subnet_record *subrec, { struct name_record *namerec; - namerec = find_name_on_subnet( subrec, nmbname, FIND_SELF_NAME ); + namerec = find_name_on_subnet( subrec, nmbname, FIND_SELF_NAME); DEBUG( 0, ( "standard_fail_register: Failed to register/refresh name %s \ on subnet %s\n", nmb_namestr(nmbname), subrec->subnet_name) ); /* Remove the name from the subnet. */ - if( namerec ) + if( namerec ) { remove_name_from_namelist(subrec, namerec); + } } /******************************************************************* @@ -293,13 +315,18 @@ on subnet %s\n", nmb_namestr(nmbname), subrec->subnet_name) ); static void remove_nth_ip_in_record( struct name_record *namerec, int ind) { - if( ind != namerec->data.num_ips ) + if( ind != namerec->data.num_ips ) { memmove( (char *)(&namerec->data.ip[ind]), (char *)(&namerec->data.ip[ind+1]), ( namerec->data.num_ips - ind - 1) * sizeof(struct in_addr) ); + } namerec->data.num_ips--; - namerec->subnet->namelist_changed = True; + if (namerec->subnet == wins_server_subnet) { + wins_store_changed_namerec(namerec); + } else { + namerec->subnet->namelist_changed = True; + } } /******************************************************************* @@ -310,9 +337,11 @@ BOOL find_ip_in_name_record( struct name_record *namerec, struct in_addr ip ) { int i; - for(i = 0; i < namerec->data.num_ips; i++) - if(ip_equal( namerec->data.ip[i], ip)) + for(i = 0; i < namerec->data.num_ips; i++) { + if(ip_equal( namerec->data.ip[i], ip)) { return True; + } + } return False; } @@ -326,8 +355,9 @@ void add_ip_to_name_record( struct name_record *namerec, struct in_addr new_ip ) struct in_addr *new_list; /* Don't add one we already have. */ - if( find_ip_in_name_record( namerec, new_ip ) ) + if( find_ip_in_name_record( namerec, new_ip )) { return; + } new_list = SMB_MALLOC_ARRAY( struct in_addr, namerec->data.num_ips + 1); if( NULL == new_list ) { @@ -342,7 +372,11 @@ void add_ip_to_name_record( struct name_record *namerec, struct in_addr new_ip ) namerec->data.ip = new_list; namerec->data.num_ips += 1; - namerec->subnet->namelist_changed = True; + if (namerec->subnet == wins_server_subnet) { + wins_store_changed_namerec(namerec); + } else { + namerec->subnet->namelist_changed = True; + } } /******************************************************************* @@ -388,26 +422,29 @@ on subnet %s. Name was not found on subnet.\n", nmb_namestr(nmbname), inet_ntoa( remove_ip_from_name_record( namerec, released_ip ); - if( namerec->data.num_ips == orig_num ) + if( namerec->data.num_ips == orig_num ) { DEBUG( 0, ( "standard_success_release: Name release for name %s IP %s \ on subnet %s. This ip is not known for this name.\n", nmb_namestr(nmbname), inet_ntoa(released_ip), subrec->subnet_name ) ); + } } - if( namerec->data.num_ips == 0 ) + if( namerec->data.num_ips == 0 ) { remove_name_from_namelist( subrec, namerec ); + } } /******************************************************************* - Expires old names in a subnet namelist. + Expires old names in a subnet namelist. + NB. Does not touch the wins_subnet - no wins specific processing here. ******************************************************************/ -void expire_names_on_subnet(struct subnet_record *subrec, time_t t) +static void expire_names_on_subnet(struct subnet_record *subrec, time_t t) { struct name_record *namerec; struct name_record *next_namerec; - for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); namerec; namerec = next_namerec ) { - next_namerec = (struct name_record *)ubi_trNext( namerec ); + for( namerec = subrec->namelist; namerec; namerec = next_namerec ) { + next_namerec = namerec->next; if( (namerec->data.death_time != PERMANENT_TTL) && (namerec->data.death_time < t) ) { if( namerec->data.source == SELF_NAME ) { DEBUG( 3, ( "expire_names_on_subnet: Subnet %s not expiring SELF \ @@ -420,13 +457,14 @@ name %s\n", subrec->subnet_name, nmb_namestr(&namerec->name) ) ); DEBUG(3,("expire_names_on_subnet: Subnet %s - removing expired name %s\n", subrec->subnet_name, nmb_namestr(&namerec->name))); - remove_name_from_namelist( subrec, namerec ); + remove_name_from_namelist(subrec, namerec ); } } } /******************************************************************* - Expires old names in all subnet namelists. + Expires old names in all subnet namelists. + NB. Does not touch the wins_subnet. ******************************************************************/ void expire_names(time_t t) @@ -479,75 +517,85 @@ void add_samba_names_to_subnet( struct subnet_record *subrec ) add_name_to_subnet(subrec,"__SAMBA__",0x00,samba_nb_type,PERMANENT_TTL, PERMANENT_NAME, num_ips, iplist); - if(iplist != &subrec->myip) + if(iplist != &subrec->myip) { SAFE_FREE(iplist); + } } /**************************************************************************** - Dump the contents of the namelists on all the subnets (including unicast) - into a file. Initiated by SIGHUP - used to debug the state of the namelists. + Dump a name_record struct. **************************************************************************/ -static void dump_subnet_namelist( struct subnet_record *subrec, XFILE *fp) +void dump_name_record( struct name_record *namerec, XFILE *fp) { - struct name_record *namerec; const char *src_type; struct tm *tm; int i; - x_fprintf(fp, "Subnet %s\n----------------------\n", subrec->subnet_name); - for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); namerec; - namerec = (struct name_record *)ubi_trNext( namerec ) ) { - - x_fprintf(fp,"\tName = %s\t", nmb_namestr(&namerec->name)); - switch(namerec->data.source) { - case LMHOSTS_NAME: - src_type = "LMHOSTS_NAME"; - break; - case WINS_PROXY_NAME: - src_type = "WINS_PROXY_NAME"; - break; - case REGISTER_NAME: - src_type = "REGISTER_NAME"; - break; - case SELF_NAME: - src_type = "SELF_NAME"; - break; - case DNS_NAME: - src_type = "DNS_NAME"; - break; - case DNSFAIL_NAME: - src_type = "DNSFAIL_NAME"; - break; - case PERMANENT_NAME: - src_type = "PERMANENT_NAME"; - break; - default: - src_type = "unknown!"; - break; - } + x_fprintf(fp,"\tName = %s\t", nmb_namestr(&namerec->name)); + switch(namerec->data.source) { + case LMHOSTS_NAME: + src_type = "LMHOSTS_NAME"; + break; + case WINS_PROXY_NAME: + src_type = "WINS_PROXY_NAME"; + break; + case REGISTER_NAME: + src_type = "REGISTER_NAME"; + break; + case SELF_NAME: + src_type = "SELF_NAME"; + break; + case DNS_NAME: + src_type = "DNS_NAME"; + break; + case DNSFAIL_NAME: + src_type = "DNSFAIL_NAME"; + break; + case PERMANENT_NAME: + src_type = "PERMANENT_NAME"; + break; + default: + src_type = "unknown!"; + break; + } - x_fprintf(fp,"Source = %s\nb_flags = %x\t", src_type, namerec->data.nb_flags); + x_fprintf(fp,"Source = %s\nb_flags = %x\t", src_type, namerec->data.nb_flags); - if(namerec->data.death_time != PERMANENT_TTL) { - tm = localtime(&namerec->data.death_time); - x_fprintf(fp, "death_time = %s\t", asctime(tm)); - } else { - x_fprintf(fp, "death_time = PERMANENT\t"); - } + if(namerec->data.death_time != PERMANENT_TTL) { + tm = localtime(&namerec->data.death_time); + x_fprintf(fp, "death_time = %s\t", asctime(tm)); + } else { + x_fprintf(fp, "death_time = PERMANENT\t"); + } - if(namerec->data.refresh_time != PERMANENT_TTL) { - tm = localtime(&namerec->data.refresh_time); - x_fprintf(fp, "refresh_time = %s\n", asctime(tm)); - } else { - x_fprintf(fp, "refresh_time = PERMANENT\n"); - } + if(namerec->data.refresh_time != PERMANENT_TTL) { + tm = localtime(&namerec->data.refresh_time); + x_fprintf(fp, "refresh_time = %s\n", asctime(tm)); + } else { + x_fprintf(fp, "refresh_time = PERMANENT\n"); + } - x_fprintf(fp, "\t\tnumber of IPS = %d", namerec->data.num_ips); - for(i = 0; i < namerec->data.num_ips; i++) - x_fprintf(fp, "\t%s", inet_ntoa(namerec->data.ip[i])); + x_fprintf(fp, "\t\tnumber of IPS = %d", namerec->data.num_ips); + for(i = 0; i < namerec->data.num_ips; i++) { + x_fprintf(fp, "\t%s", inet_ntoa(namerec->data.ip[i])); + } + + x_fprintf(fp, "\n\n"); + +} + +/**************************************************************************** + Dump the contents of the namelists on all the subnets (including unicast) + into a file. Initiated by SIGHUP - used to debug the state of the namelists. +**************************************************************************/ - x_fprintf(fp, "\n\n"); +static void dump_subnet_namelist( struct subnet_record *subrec, XFILE *fp) +{ + struct name_record *namerec; + x_fprintf(fp, "Subnet %s\n----------------------\n", subrec->subnet_name); + for( namerec = subrec->namelist; namerec; namerec = namerec->next) { + dump_name_record(namerec, fp); } } @@ -569,16 +617,21 @@ void dump_all_namelists(void) return; } - for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec) ) + for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { dump_subnet_namelist( subrec, fp ); + } - if( !we_are_a_wins_client() ) + if (!we_are_a_wins_client()) { dump_subnet_namelist( unicast_subnet, fp ); + } - if( remote_broadcast_subnet->namelist != NULL ) + if (remote_broadcast_subnet->namelist != NULL) { dump_subnet_namelist( remote_broadcast_subnet, fp ); + } + + if (wins_server_subnet != NULL) { + dump_wins_subnet_namelist(fp ); + } - if( wins_server_subnet != NULL ) - dump_subnet_namelist( wins_server_subnet, fp ); x_fclose( fp ); } diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index b53a6d7328..b2e1178beb 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -51,34 +51,6 @@ static void add_subnet(struct subnet_record *subrec) DLIST_ADD(subnetlist, subrec); } -/* ************************************************************************** ** - * Comparison routine for ordering the splay-tree based namelists assoicated - * with each subnet record. - * - * Input: Item - Pointer to the comparison key. - * Node - Pointer to a node the splay tree. - * - * Output: The return value will be <0 , ==0, or >0 depending upon the - * ordinal relationship of the two keys. - * - * ************************************************************************** ** - */ -static int namelist_entry_compare( ubi_trItemPtr Item, ubi_trNodePtr Node ) -{ - struct name_record *NR = (struct name_record *)Node; - - if( DEBUGLVL( 10 ) ) { - struct nmb_name *Iname = (struct nmb_name *)Item; - - Debug1( "nmbd_subnetdb:namelist_entry_compare()\n" ); - Debug1( "%d == memcmp( \"%s\", \"%s\", %d )\n", - memcmp( Item, &(NR->name), sizeof(struct nmb_name) ), - nmb_namestr(Iname), nmb_namestr(&NR->name), (int)sizeof(struct nmb_name) ); - } - - return( memcmp( Item, &(NR->name), sizeof(struct nmb_name) ) ); -} - /**************************************************************************** stop listening on a subnet we don't free the record as we don't have proper reference counting for it @@ -156,10 +128,7 @@ static struct subnet_record *make_subnet(const char *name, enum subnet_type type return(NULL); } - memset( (char *)subrec, '\0', sizeof(*subrec) ); - (void)ubi_trInitTree( subrec->namelist, - namelist_entry_compare, - ubi_trOVERWRITE ); + ZERO_STRUCTP(subrec); if((subrec->subnet_name = SMB_STRDUP(name)) == NULL) { DEBUG(0,("make_subnet: malloc fail for subnet name !\n")); diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index 7531972461..d6dc6261c8 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -33,7 +33,7 @@ static void wins_proxy_name_query_request_success( struct subnet_record *subrec, unstring name; struct packet_struct *original_packet; struct subnet_record *orig_broadcast_subnet; - struct name_record *namerec; + struct name_record *namerec = NULL; uint16 nb_flags; int num_ips; int i; @@ -64,22 +64,34 @@ returned for name %s.\n", nmb_namestr(nmbname) )); return; } - for(i = 0; i < num_ips; i++) + for(i = 0; i < num_ips; i++) { putip( (char *)&iplist[i], (char *)&rrec->rdata[ (i*6) + 2]); + } } /* Add the queried name to the original subnet as a WINS_PROXY_NAME. */ - if(rrec == PERMANENT_TTL) + if(rrec == PERMANENT_TTL) { ttl = lp_max_ttl(); + } pull_ascii_nstring(name, sizeof(name), nmbname->name); - namerec = add_name_to_subnet( orig_broadcast_subnet, name, + add_name_to_subnet( orig_broadcast_subnet, name, nmbname->name_type, nb_flags, ttl, WINS_PROXY_NAME, num_ips, iplist ); - if(iplist != &ip) + namerec = find_name_on_subnet(orig_broadcast_subnet, nmbname, FIND_ANY_NAME); + if (!namerec) { + DEBUG(0,("wins_proxy_name_query_request_success: failed to add " + "name %s to subnet %s !\n", + name, + orig_broadcast_subnet->subnet_name )); + return; + } + + if(iplist != &ip) { SAFE_FREE(iplist); + } /* * Check that none of the IP addresses we are returning is on the diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 8a1f82c8b1..5c234bf8dc 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -2,7 +2,7 @@ Unix SMB/CIFS implementation. NBT netbios routines and daemon - version 2 - Copyright (C) Jeremy Allison 1994-2003 + Copyright (C) Jeremy Allison 1994-2005 This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -18,12 +18,312 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + Converted to store WINS data in a tdb. Dec 2005. JRA. */ #include "includes.h" #define WINS_LIST "wins.dat" #define WINS_VERSION 1 +#define WINSDB_VERSION 1 + +/**************************************************************************** + We don't store the NetBIOS scope in the wins.tdb. We key off the (utf8) netbios + name (65 bytes with the last byte being the name type). +*****************************************************************************/ + +TDB_CONTEXT *wins_tdb; + +/**************************************************************************** + Convert a wins.tdb record to a struct name_record. Add in our global_scope(). +*****************************************************************************/ + +static struct name_record *wins_record_to_name_record(TDB_DATA key, TDB_DATA data) +{ + struct name_record *namerec = NULL; + uint16 nb_flags; + unsigned char nr_src; + uint32 death_time, refresh_time; + uint32 id_low, id_high; + uint32 saddr; + uint32 wins_flags; + uint32 num_ips; + size_t len; + int i; + + if (data.dptr == NULL || data.dsize == 0) { + return NULL; + } + + /* Min size is "wbddddddd" + 1 ip address (4). */ + if (data.dsize < 2 + 1 + (7*4) + 4) { + return NULL; + } + + len = tdb_unpack(data.dptr, data.dsize, + "wbddddddd", + &nb_flags, + &nr_src, + &death_time, + &refresh_time, + &id_low, + &id_high, + &saddr, + &wins_flags, + &num_ips ); + + namerec = SMB_MALLOC_P(struct name_record); + if (!namerec) { + return NULL; + } + + namerec->data.ip = SMB_MALLOC_ARRAY(struct in_addr, num_ips); + if (!namerec->data.ip) { + SAFE_FREE(namerec); + return NULL; + } + + namerec->subnet = wins_server_subnet; + push_ascii_nstring(namerec->name.name, key.dptr); + namerec->name.name_type = key.dptr[sizeof(unstring)]; + /* Add the scope. */ + push_ascii(namerec->name.scope, global_scope(), 64, STR_TERMINATE); + + /* We're using a byte-by-byte compare, so we must be sure that + * unused space doesn't have garbage in it. + */ + + for( i = strlen( namerec->name.name ); i < sizeof( namerec->name.name ); i++ ) { + namerec->name.name[i] = '\0'; + } + for( i = strlen( namerec->name.scope ); i < sizeof( namerec->name.scope ); i++ ) { + namerec->name.scope[i] = '\0'; + } + + namerec->data.nb_flags = nb_flags; + namerec->data.source = (enum name_source)nr_src; + namerec->data.death_time = (time_t)death_time; + namerec->data.refresh_time = (time_t)refresh_time; + namerec->data.id = id_low; +#if defined(HAVE_LONGLONG) + namerec->data.id |= ((SMB_BIG_UINT)id_high << 32); +#endif + namerec->data.wins_ip.s_addr = saddr; + namerec->data.wins_flags = wins_flags, + namerec->data.num_ips = num_ips; + + for (i = 0; i < num_ips; i++) { + namerec->data.ip[i].s_addr = IVAL(data.dptr, len + (i*4)); + } + + return namerec; +} + +/**************************************************************************** + Convert a struct name_record to a wins.tdb record. Ignore the scope. +*****************************************************************************/ + +static TDB_DATA name_record_to_wins_record(const struct name_record *namerec) +{ + TDB_DATA data; + size_t len = 0; + int i; + uint32 id_low = (namerec->data.id & 0xFFFFFFFF); +#if defined(HAVE_LONGLONG) + uint32 id_high = (namerec->data.id >> 32) & 0xFFFFFFFF; +#else + uint32 id_high = 0; +#endif + + ZERO_STRUCT(data); + + len = (2 + 1 + (7*4)); /* "wbddddddd" */ + len += (namerec->data.num_ips * 4); + + data.dptr = SMB_MALLOC(len); + if (!data.dptr) { + return data; + } + data.dsize = len; + + len = tdb_pack(data.dptr, data.dsize, "wbddddddd", + namerec->data.nb_flags, + (unsigned char)namerec->data.source, + (uint32)namerec->data.death_time, + (uint32)namerec->data.refresh_time, + id_low, + id_high, + (uint32)namerec->data.wins_ip.s_addr, + (uint32)namerec->data.wins_flags, + (uint32)namerec->data.num_ips ); + + for (i = 0; i < namerec->data.num_ips; i++) { + SIVAL(data.dptr, len + (i*4), namerec->data.ip[i].s_addr); + } + + return data; +} + +/**************************************************************************** + Create key. Key is UNIX codepage namestring (usually utf8 64 byte len) with 1 byte type. +*****************************************************************************/ + +static TDB_DATA name_to_key(const struct nmb_name *nmbname) +{ + static char keydata[sizeof(unstring) + 1]; + TDB_DATA key; + + memset(keydata, '\0', sizeof(keydata)); + + pull_ascii_nstring(keydata, sizeof(unstring), nmbname->name); + strupper_m(keydata); + keydata[sizeof(unstring)] = nmbname->name_type; + key.dptr = keydata; + key.dsize = sizeof(keydata); + + return key; +} + +/**************************************************************************** + Lookup a given name in the wins.tdb and create a temporary malloc'ed data struct + on the linked list. We will free this later in XXXX(). +*****************************************************************************/ + +struct name_record *find_name_on_wins_subnet(const struct nmb_name *nmbname, BOOL self_only) +{ + TDB_DATA data, key; + struct name_record *nr = NULL; + struct name_record *namerec = NULL; + + if (!wins_tdb) { + return NULL; + } + + key = name_to_key(nmbname); + data = tdb_fetch(wins_tdb, key); + + if (data.dsize == 0) { + return NULL; + } + + namerec = wins_record_to_name_record(key, data); + if (!namerec) { + return NULL; + } + + /* Search for this name record on the list. Replace it if found. */ + + for( nr = wins_server_subnet->namelist; nr; nr = nr->next) { + if (memcmp(nmbname->name, nr->name.name, 16) == 0) { + /* Delete it. */ + DLIST_REMOVE(wins_server_subnet->namelist, nr); + SAFE_FREE(nr->data.ip); + SAFE_FREE(nr); + break; + } + } + + DLIST_ADD(wins_server_subnet->namelist, namerec); + return namerec; +} + +/**************************************************************************** + Overwrite or add a given name in the wins.tdb. +*****************************************************************************/ + +static BOOL store_or_replace_wins_namerec(const struct name_record *namerec, int tdb_flag) +{ + TDB_DATA key, data; + int ret; + + if (!wins_tdb) { + return False; + } + + key = name_to_key(&namerec->name); + data = name_record_to_wins_record(namerec); + + if (data.dptr == NULL) { + return False; + } + + ret = tdb_store(wins_tdb, key, data, tdb_flag); + + SAFE_FREE(data.dptr); + return (ret == 0) ? True : False; +} + +/**************************************************************************** + Overwrite a given name in the wins.tdb. +*****************************************************************************/ + +BOOL wins_store_changed_namerec(const struct name_record *namerec) +{ + return store_or_replace_wins_namerec(namerec, TDB_REPLACE); +} + +/**************************************************************************** + Primary interface into creating and overwriting records in the wins.tdb. +*****************************************************************************/ + +BOOL add_name_to_wins_subnet(const struct name_record *namerec) +{ + return store_or_replace_wins_namerec(namerec, TDB_INSERT); +} + +/**************************************************************************** + Delete a given name in the tdb and remove the temporary malloc'ed data struct + on the linked list. +*****************************************************************************/ + +BOOL remove_name_from_wins_namelist(struct name_record *namerec) +{ + TDB_DATA key; + int ret; + + if (!wins_tdb) { + return False; + } + + key = name_to_key(&namerec->name); + ret = tdb_delete(wins_tdb, key); + + DLIST_REMOVE(wins_server_subnet->namelist, namerec); + SAFE_FREE(namerec->data.ip); + ZERO_STRUCTP(namerec); + SAFE_FREE(namerec); + return (ret == 0) ? True : False; +} + +/**************************************************************************** + Dump out the complete namelist. +*****************************************************************************/ + +static int traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) +{ + struct name_record *namerec = NULL; + XFILE *fp = (XFILE *)state; + + if (kbuf.dsize != sizeof(unstring) + 1) { + return 0; + } + + namerec = wins_record_to_name_record(kbuf, dbuf); + if (!namerec) { + return 0; + } + + dump_name_record(namerec, fp); + + SAFE_FREE(namerec->data.ip); + SAFE_FREE(namerec); + return 0; +} + +void dump_wins_subnet_namelist(XFILE *fp) +{ + tdb_traverse(wins_tdb, traverse_fn, (void *)fp); +} /**************************************************************************** Change the wins owner address in the record. @@ -31,8 +331,6 @@ static void update_wins_owner(struct name_record *namerec, struct in_addr wins_ip) { - if (namerec==NULL) - return; namerec->data.wins_ip=wins_ip; } @@ -42,34 +340,35 @@ static void update_wins_owner(struct name_record *namerec, struct in_addr wins_i static void update_wins_flag(struct name_record *namerec, int flags) { - if (namerec==NULL) - return; - namerec->data.wins_flags=0x0; /* if it's a group, it can be a normal or a special one */ if (namerec->data.nb_flags & NB_GROUP) { - if (namerec->name.name_type==0x1C) + if (namerec->name.name_type==0x1C) { namerec->data.wins_flags|=WINS_SGROUP; - else - if (namerec->data.num_ips>1) + } else { + if (namerec->data.num_ips>1) { namerec->data.wins_flags|=WINS_SGROUP; - else + } else { namerec->data.wins_flags|=WINS_NGROUP; + } + } } else { /* can be unique or multi-homed */ - if (namerec->data.num_ips>1) + if (namerec->data.num_ips>1) { namerec->data.wins_flags|=WINS_MHOMED; - else + } else { namerec->data.wins_flags|=WINS_UNIQUE; + } } /* the node type are the same bits */ namerec->data.wins_flags|=namerec->data.nb_flags&NB_NODETYPEMASK; /* the static bit is elsewhere */ - if (namerec->data.death_time == PERMANENT_TTL) + if (namerec->data.death_time == PERMANENT_TTL) { namerec->data.wins_flags|=WINS_STATIC; + } /* and add the given bits */ namerec->data.wins_flags|=flags; @@ -95,12 +394,14 @@ static void get_global_id_and_update(SMB_BIG_UINT *current_id, BOOL update) *current_id = general_id; - if (update) + if (update) { general_id++; + } } /**************************************************************************** Possibly call the WINS hook external program when a WINS change is made. + Also stores the changed record back in the wins_tdb. *****************************************************************************/ static void wins_hook(const char *operation, struct name_record *namerec, int ttl) @@ -110,7 +411,11 @@ static void wins_hook(const char *operation, struct name_record *namerec, int tt char *p, *namestr; int i; - if (!cmd || !*cmd) return; + wins_store_changed_namerec(namerec); + + if (!cmd || !*cmd) { + return; + } for (p=namerec->name.name; *p; p++) { if (!(isalnum((int)*p) || strchr_m("._-",*p))) { @@ -122,8 +427,9 @@ static void wins_hook(const char *operation, struct name_record *namerec, int tt /* Use the name without the nametype (and scope) appended */ namestr = nmb_namestr(&namerec->name); - if ((p = strchr(namestr, '<'))) + if ((p = strchr(namestr, '<'))) { *p = 0; + } p = command; p += slprintf(p, sizeof(command)-1, "%s %s %s %02x %d", @@ -141,7 +447,6 @@ static void wins_hook(const char *operation, struct name_record *namerec, int tt smbrun(command, NULL); } - /**************************************************************************** Determine if this packet should be allocated to the WINS server. *****************************************************************************/ @@ -157,8 +462,9 @@ BOOL packet_is_for_wins_server(struct packet_struct *packet) } /* Check for node status requests. */ - if (nmb->question.question_type != QUESTION_TYPE_NB_QUERY) + if (nmb->question.question_type != QUESTION_TYPE_NB_QUERY) { return False; + } switch(nmb->header.opcode) { /* @@ -210,11 +516,13 @@ static int get_ttl_from_packet(struct nmb_packet *nmb) { int ttl = nmb->additional->ttl; - if(ttl < lp_min_wins_ttl() ) + if (ttl < lp_min_wins_ttl()) { ttl = lp_min_wins_ttl(); + } - if(ttl > lp_max_wins_ttl() ) + if (ttl > lp_max_wins_ttl()) { ttl = lp_max_wins_ttl(); + } return ttl; } @@ -229,8 +537,19 @@ BOOL initialise_wins(void) XFILE *fp; pstring line; - if(!lp_we_are_a_wins_server()) + if(!lp_we_are_a_wins_server()) { return True; + } + + /* Open the wins.tdb. */ + wins_tdb = tdb_open_log(lock_path("wins.tdb"), 0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST, O_CREAT|O_RDWR, 0600); + if (!wins_tdb) { + DEBUG(0,("initialise_wins: failed to open wins.tdb. Error was %s\n", + strerror(errno) )); + return False; + } + + tdb_store_int32(wins_tdb, "WINSDB_VERSION", WINSDB_VERSION); add_samba_names_to_subnet(wins_server_subnet); @@ -344,8 +663,9 @@ BOOL initialise_wins(void) continue; } - if(nb_flags_str[strlen(nb_flags_str)-1] == 'R') + if(nb_flags_str[strlen(nb_flags_str)-1] == 'R') { nb_flags_str[strlen(nb_flags_str)-1] = '\0'; + } /* Netbios name. # divides the name from the type (hex): netbios#xx */ pstrcpy(name,name_str); @@ -361,8 +681,9 @@ BOOL initialise_wins(void) /* add all entries that have 60 seconds or more to live */ if ((ttl - 60) > time_now || ttl == PERMANENT_TTL) { - if(ttl != PERMANENT_TTL) + if(ttl != PERMANENT_TTL) { ttl -= time_now; + } DEBUG( 4, ("initialise_wins: add name: %s#%02x ttl = %d first IP %s flags = %2x\n", name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); @@ -370,7 +691,8 @@ BOOL initialise_wins(void) (void)add_name_to_subnet( wins_server_subnet, name, type, nb_flags, ttl, REGISTER_NAME, num_ips, ip_list ); } else { - DEBUG(4, ("initialise_wins: not adding name (ttl problem) %s#%02x ttl = %d first IP %s flags = %2x\n", + DEBUG(4, ("initialise_wins: not adding name (ttl problem) " + "%s#%02x ttl = %d first IP %s flags = %2x\n", name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); } @@ -396,16 +718,21 @@ static void send_wins_wack_response(int ttl, struct packet_struct *p) identical bytes from the requesting packet header. */ rdata[0] = (nmb->header.opcode & 0xF) << 3; - if (nmb->header.nm_flags.authoritative && nmb->header.response) + if (nmb->header.nm_flags.authoritative && nmb->header.response) { rdata[0] |= 0x4; - if (nmb->header.nm_flags.trunc) + } + if (nmb->header.nm_flags.trunc) { rdata[0] |= 0x2; - if (nmb->header.nm_flags.recursion_desired) + } + if (nmb->header.nm_flags.recursion_desired) { rdata[0] |= 0x1; - if (nmb->header.nm_flags.recursion_available && nmb->header.response) + } + if (nmb->header.nm_flags.recursion_available && nmb->header.response) { rdata[1] |= 0x80; - if (nmb->header.nm_flags.bcast) + } + if (nmb->header.nm_flags.bcast) { rdata[1] |= 0x10; + } reply_netbios_packet(p, /* Packet to reply to. */ 0, /* Result code. */ @@ -545,7 +872,7 @@ void wins_process_name_refresh_request( struct subnet_record *subrec, * names update the ttl and return success. */ if( (!group || (group && (question->name_type == 0x1c))) - && find_ip_in_name_record(namerec, from_ip) ) { + && find_ip_in_name_record(namerec, from_ip) ) { /* * Update the ttl. */ @@ -584,6 +911,7 @@ void wins_process_name_refresh_request( struct subnet_record *subrec, * 255.255.255.255 so we can't search for the IP address. */ update_name_ttl(namerec, ttl); + wins_hook("refresh", namerec, ttl); send_wins_name_registration_response(0, ttl, p); return; } else if(!group && (question->name_type == 0x1d)) { @@ -669,16 +997,19 @@ static void wins_register_query_fail(struct subnet_record *subrec, namerec = find_name_on_subnet(subrec, question_name, FIND_ANY_NAME); - if( (namerec != NULL) && (namerec->data.source == REGISTER_NAME) && ip_equal(rrec->packet->ip, *namerec->data.ip) ) { + if ((namerec != NULL) && (namerec->data.source == REGISTER_NAME) && + ip_equal(rrec->packet->ip, *namerec->data.ip)) { remove_name_from_namelist( subrec, namerec); namerec = NULL; } - if(namerec == NULL) + if(namerec == NULL) { wins_process_name_registration_request(subrec, orig_reg_packet); - else - DEBUG(2,("wins_register_query_fail: The state of the WINS database changed between \ -querying for name %s in order to replace it and this reply.\n", nmb_namestr(question_name) )); + } else { + DEBUG(2,("wins_register_query_fail: The state of the WINS database changed between " + "querying for name %s in order to replace it and this reply.\n", + nmb_namestr(question_name) )); + } orig_reg_packet->locked = False; free_packet(orig_reg_packet); @@ -828,8 +1159,9 @@ to register name %s. Name already exists in WINS with source type %d.\n", * Group names with type 0x1c are registered with individual IP addresses. */ - if(registering_group_name && (question->name_type != 0x1c)) + if(registering_group_name && (question->name_type != 0x1c)) { from_ip = *interpret_addr2("255.255.255.255"); + } /* * Ignore all attempts to register a unique 0x1d name, although return success. @@ -876,6 +1208,7 @@ to register name %s from IP %s.\n", nmb_namestr(question), inet_ntoa(p->ip) )); update_wins_owner(namerec, our_fake_ip); } update_name_ttl(namerec, ttl); + wins_hook("refresh", namerec, ttl); send_wins_name_registration_response(0, ttl, p); return; } else { @@ -905,8 +1238,11 @@ already exists in WINS as a GROUP name.\n", nmb_namestr(question) )); * reject without doing the query - we know we will reject it. */ - if ( namerec != NULL ) + if ( namerec != NULL ) { pull_ascii_nstring(name, sizeof(name), namerec->name.name); + } else { + name[0] = '\0'; + } if( is_myname(name) ) { if(!ismyip(from_ip)) { @@ -919,8 +1255,8 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio * It's one of our names and one of our IP's - update the ttl. */ update_name_ttl(namerec, ttl); - send_wins_name_registration_response(0, ttl, p); wins_hook("refresh", namerec, ttl); + send_wins_name_registration_response(0, ttl, p); return; } } @@ -940,8 +1276,8 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio && ip_equal( namerec->data.ip[0], from_ip ) && ip_equal(namerec->data.wins_ip, our_fake_ip) ) { update_name_ttl( namerec, ttl ); - send_wins_name_registration_response( 0, ttl, p ); wins_hook("refresh", namerec, ttl); + send_wins_name_registration_response( 0, ttl, p ); return; } @@ -1061,15 +1397,16 @@ a subsequent IP address.\n", nmb_namestr(question_name) )); return; } - if(!find_ip_in_name_record(namerec, from_ip)) + if(!find_ip_in_name_record(namerec, from_ip)) { add_ip_to_name_record(namerec, from_ip); + } get_global_id_and_update(&namerec->data.id, True); update_wins_owner(namerec, our_fake_ip); update_wins_flag(namerec, WINS_ACTIVE); update_name_ttl(namerec, ttl); - send_wins_name_registration_response(0, ttl, orig_reg_packet); wins_hook("add", namerec, ttl); + send_wins_name_registration_response(0, ttl, orig_reg_packet); orig_reg_packet->locked = False; free_packet(orig_reg_packet); @@ -1237,18 +1574,17 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio * It's one of our names and one of our IP's. Ensure the IP is in the record and * update the ttl. Update the version ID to force replication. */ + update_name_ttl(namerec, ttl); + if(!find_ip_in_name_record(namerec, from_ip)) { get_global_id_and_update(&namerec->data.id, True); update_wins_owner(namerec, our_fake_ip); update_wins_flag(namerec, WINS_ACTIVE); add_ip_to_name_record(namerec, from_ip); - wins_hook("add", namerec, ttl); - } else { - wins_hook("refresh", namerec, ttl); } - update_name_ttl(namerec, ttl); + wins_hook("refresh", namerec, ttl); send_wins_name_registration_response(0, ttl, p); return; } @@ -1272,8 +1608,8 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio update_wins_flag(namerec, WINS_ACTIVE); } - send_wins_name_registration_response(0, ttl, p); wins_hook("refresh", namerec, ttl); + send_wins_name_registration_response(0, ttl, p); return; } @@ -1347,6 +1683,37 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio send_wins_name_registration_response(0, ttl, p); } +/*********************************************************************** + Fetch all *<1b> names from the WINS db and store on the namelist. +***********************************************************************/ + +static int fetch_1b_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) +{ + struct name_record *namerec = NULL; + + if (kbuf.dsize != sizeof(unstring) + 1) { + return 0; + } + + /* Filter out all non-1b names. */ + if (kbuf.dptr[sizeof(unstring)] != 0x1b) { + return 0; + } + + namerec = wins_record_to_name_record(kbuf, dbuf); + if (!namerec) { + return 0; + } + + DLIST_ADD(wins_server_subnet->namelist, namerec); + return 0; +} + +void fetch_all_active_wins_1b_names(void) +{ + tdb_traverse(wins_tdb, fetch_1b_traverse_fn, NULL); +} + /*********************************************************************** Deal with the special name query for *<1b>. ***********************************************************************/ @@ -1365,10 +1732,13 @@ static void process_wins_dmb_query_request(struct subnet_record *subrec, */ num_ips = 0; - for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); - namerec; namerec = (struct name_record *)ubi_trNext( namerec ) ) { - if(WINS_STATE_ACTIVE(namerec) && namerec->name.name_type == 0x1b ) + + fetch_all_active_wins_1b_names(); + + for( namerec = subrec->namelist; namerec; namerec = namerec->next ) { + if( WINS_STATE_ACTIVE(namerec) && namerec->name.name_type == 0x1b) { num_ips += namerec->data.num_ips; + } } if(num_ips == 0) { @@ -1391,9 +1761,8 @@ static void process_wins_dmb_query_request(struct subnet_record *subrec, */ num_ips = 0; - for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); - namerec; namerec = (struct name_record *)ubi_trNext( namerec ) ) { - if(WINS_STATE_ACTIVE(namerec) && namerec->name.name_type == 0x1b) { + for( namerec = subrec->namelist; namerec; namerec = namerec->next ) { + if( WINS_STATE_ACTIVE(namerec) && namerec->name.name_type == 0x1b) { int i; for(i = 0; i < namerec->data.num_ips; i++) { set_nb_flags(&prdata[num_ips * 6],namerec->data.nb_flags); @@ -1465,8 +1834,9 @@ void send_wins_name_query_response(int rcode, struct packet_struct *p, prdata, /* data to send. */ reply_data_len); /* data length. */ - if(prdata != rdata) + if(prdata != rdata) { SAFE_FREE(prdata); + } } /*********************************************************************** @@ -1548,7 +1918,7 @@ void wins_process_name_query_request(struct subnet_record *subrec, DEBUG(3,("wins_process_name_query: name query for name %s not found - doing dns lookup.\n", nmb_namestr(question) )); - queue_dns_query(p, question, &namerec); + queue_dns_query(p, question); return; } @@ -1680,6 +2050,7 @@ release name %s as this record is not active anymore.\n", nmb_namestr(question) remove_ip_from_name_record(namerec, from_ip); DEBUG(3,("wins_process_name_release_request: Remove IP %s from NAME: %s\n", inet_ntoa(from_ip),nmb_namestr(question))); + wins_hook("delete", namerec, 0); send_wins_name_release_response(0, p); return; } @@ -1689,118 +2060,235 @@ release name %s as this record is not active anymore.\n", nmb_namestr(question) * Flag the name as released and update the ttl */ - send_wins_name_release_response(0, p); - namerec->data.wins_flags |= WINS_RELEASED; update_name_ttl(namerec, EXTINCTION_INTERVAL); wins_hook("delete", namerec, 0); + send_wins_name_release_response(0, p); } /******************************************************************* WINS time dependent processing. ******************************************************************/ +static int wins_processing_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) +{ + time_t t = *(time_t *)state; + BOOL store_record = False; + struct name_record *namerec = NULL; + struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); + + if (kbuf.dsize != sizeof(unstring) + 1) { + return 0; + } + + namerec = wins_record_to_name_record(kbuf, dbuf); + if (!namerec) { + return 0; + } + + if( (namerec->data.death_time != PERMANENT_TTL) && (namerec->data.death_time < t) ) { + if( namerec->data.source == SELF_NAME ) { + DEBUG( 3, ( "wins_processing_traverse_fn: Subnet %s not expiring SELF name %s\n", + wins_server_subnet->subnet_name, nmb_namestr(&namerec->name) ) ); + namerec->data.death_time += 300; + store_record = True; + goto done; + } else if (namerec->data.source == DNS_NAME || namerec->data.source == DNSFAIL_NAME) { + DEBUG(3,("wins_processing_traverse_fn: deleting timed out DNS name %s\n", + nmb_namestr(&namerec->name))); + remove_name_from_wins_namelist(namerec ); + goto done; + } + + /* handle records, samba is the wins owner */ + if (ip_equal(namerec->data.wins_ip, our_fake_ip)) { + switch (namerec->data.wins_flags | WINS_STATE_MASK) { + case WINS_ACTIVE: + namerec->data.wins_flags&=~WINS_STATE_MASK; + namerec->data.wins_flags|=WINS_RELEASED; + namerec->data.death_time = t + EXTINCTION_INTERVAL; + DEBUG(3,("wins_processing_traverse_fn: expiring %s\n", + nmb_namestr(&namerec->name))); + store_record = True; + goto done; + case WINS_RELEASED: + namerec->data.wins_flags&=~WINS_STATE_MASK; + namerec->data.wins_flags|=WINS_TOMBSTONED; + namerec->data.death_time = t + EXTINCTION_TIMEOUT; + get_global_id_and_update(&namerec->data.id, True); + DEBUG(3,("wins_processing_traverse_fn: tombstoning %s\n", + nmb_namestr(&namerec->name))); + store_record = True; + goto done; + case WINS_TOMBSTONED: + DEBUG(3,("wins_processing_traverse_fn: deleting %s\n", + nmb_namestr(&namerec->name))); + remove_name_from_wins_namelist(namerec ); + goto done; + } + } else { + switch (namerec->data.wins_flags | WINS_STATE_MASK) { + case WINS_ACTIVE: + /* that's not as MS says it should be */ + namerec->data.wins_flags&=~WINS_STATE_MASK; + namerec->data.wins_flags|=WINS_TOMBSTONED; + namerec->data.death_time = t + EXTINCTION_TIMEOUT; + DEBUG(3,("wins_processing_traverse_fn: tombstoning %s\n", + nmb_namestr(&namerec->name))); + store_record = True; + goto done; + case WINS_TOMBSTONED: + DEBUG(3,("wins_processing_traverse_fn: deleting %s\n", + nmb_namestr(&namerec->name))); + remove_name_from_wins_namelist(namerec ); + goto done; + case WINS_RELEASED: + DEBUG(0,("wins_processing_traverse_fn: %s is in released state and\ +we are not the wins owner !\n", nmb_namestr(&namerec->name))); + goto done; + } + } + } + + done: + + if (store_record) { + wins_store_changed_namerec(namerec); + } + + SAFE_FREE(namerec->data.ip); + SAFE_FREE(namerec); + + return 0; +} + +/******************************************************************* + Time dependent wins processing. +******************************************************************/ + void initiate_wins_processing(time_t t) { static time_t lasttime = 0; - struct name_record *namerec; - struct name_record *next_namerec; - struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); + struct name_record *nr = NULL; + struct name_record *nrnext = NULL; - if (!lasttime) + if (!lasttime) { lasttime = t; - if (t - lasttime < 20) + } + if (t - lasttime < 20) { return; + } + + if(!lp_we_are_a_wins_server()) { + lasttime = t; + return; + } + + tdb_traverse(wins_tdb, wins_processing_traverse_fn, &t); + + + /* Delete all temporary name records on the wins subnet linked list. */ + for( nr = wins_server_subnet->namelist; nr; nr = nrnext) { + nrnext = nr->next; + DLIST_REMOVE(wins_server_subnet->namelist, nr); + SAFE_FREE(nr->data.ip); + SAFE_FREE(nr); + } + + wins_write_database(t, True); lasttime = t; +} - if(!lp_we_are_a_wins_server()) - return; +/******************************************************************* + Write out one record. +******************************************************************/ - for( namerec = (struct name_record *)ubi_trFirst( wins_server_subnet->namelist ); - namerec; - namerec = next_namerec ) { - next_namerec = (struct name_record *)ubi_trNext( namerec ); - - if( (namerec->data.death_time != PERMANENT_TTL) - && (namerec->data.death_time < t) ) { - - if( namerec->data.source == SELF_NAME ) { - DEBUG( 3, ( "initiate_wins_processing: Subnet %s not expiring SELF name %s\n", - wins_server_subnet->subnet_name, nmb_namestr(&namerec->name) ) ); - namerec->data.death_time += 300; - namerec->subnet->namelist_changed = True; - continue; - } else if (namerec->data.source == DNS_NAME || namerec->data.source == DNSFAIL_NAME) { - DEBUG(3,("initiate_wins_processing: deleting timed out DNS name %s\n", - nmb_namestr(&namerec->name))); - remove_name_from_namelist( wins_server_subnet, namerec ); - continue; - } +void wins_write_name_record(struct name_record *namerec, XFILE *fp) +{ + int i; + struct tm *tm; - /* handle records, samba is the wins owner */ - if (ip_equal(namerec->data.wins_ip, our_fake_ip)) { - switch (namerec->data.wins_flags | WINS_STATE_MASK) { - case WINS_ACTIVE: - namerec->data.wins_flags&=~WINS_STATE_MASK; - namerec->data.wins_flags|=WINS_RELEASED; - namerec->data.death_time = t + EXTINCTION_INTERVAL; - DEBUG(3,("initiate_wins_processing: expiring %s\n", nmb_namestr(&namerec->name))); - break; - case WINS_RELEASED: - namerec->data.wins_flags&=~WINS_STATE_MASK; - namerec->data.wins_flags|=WINS_TOMBSTONED; - namerec->data.death_time = t + EXTINCTION_TIMEOUT; - get_global_id_and_update(&namerec->data.id, True); - DEBUG(3,("initiate_wins_processing: tombstoning %s\n", nmb_namestr(&namerec->name))); - break; - case WINS_TOMBSTONED: - DEBUG(3,("initiate_wins_processing: deleting %s\n", nmb_namestr(&namerec->name))); - remove_name_from_namelist( wins_server_subnet, namerec ); - break; - } - } else { - switch (namerec->data.wins_flags | WINS_STATE_MASK) { - case WINS_ACTIVE: - /* that's not as MS says it should be */ - namerec->data.wins_flags&=~WINS_STATE_MASK; - namerec->data.wins_flags|=WINS_TOMBSTONED; - namerec->data.death_time = t + EXTINCTION_TIMEOUT; - DEBUG(3,("initiate_wins_processing: tombstoning %s\n", nmb_namestr(&namerec->name))); - case WINS_TOMBSTONED: - DEBUG(3,("initiate_wins_processing: deleting %s\n", nmb_namestr(&namerec->name))); - remove_name_from_namelist( wins_server_subnet, namerec ); - break; - case WINS_RELEASED: - DEBUG(0,("initiate_wins_processing: %s is in released state and\ -we are not the wins owner !\n", nmb_namestr(&namerec->name))); - break; - } - } + DEBUGADD(4,("%-19s ", nmb_namestr(&namerec->name) )); + + if( namerec->data.death_time != PERMANENT_TTL ) { + char *ts, *nl; + tm = localtime(&namerec->data.death_time); + ts = asctime(tm); + nl = strrchr( ts, '\n' ); + if( NULL != nl ) { + *nl = '\0'; } + DEBUGADD(4,("TTL = %s ", ts )); + } else { + DEBUGADD(4,("TTL = PERMANENT ")); + } + + for (i = 0; i < namerec->data.num_ips; i++) { + DEBUGADD(4,("%15s ", inet_ntoa(namerec->data.ip[i]) )); } + DEBUGADD(4,("%2x\n", namerec->data.nb_flags )); - if(wins_server_subnet->namelist_changed) - wins_write_database(True); + if( namerec->data.source == REGISTER_NAME ) { + unstring name; + pull_ascii_nstring(name, sizeof(name), namerec->name.name); + x_fprintf(fp, "\"%s#%02x\" %d ", name,namerec->name.name_type, /* Ignore scope. */ + (int)namerec->data.death_time); - wins_server_subnet->namelist_changed = False; + for (i = 0; i < namerec->data.num_ips; i++) + x_fprintf( fp, "%s ", inet_ntoa( namerec->data.ip[i] ) ); + x_fprintf( fp, "%2xR\n", namerec->data.nb_flags ); + } } /******************************************************************* Write out the current WINS database. ******************************************************************/ -void wins_write_database(BOOL background) +static int wins_writedb_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) +{ + struct name_record *namerec = NULL; + XFILE *fp = (XFILE *)state; + + if (kbuf.dsize != sizeof(unstring) + 1) { + return 0; + } + + namerec = wins_record_to_name_record(kbuf, dbuf); + if (!namerec) { + return 0; + } + + wins_write_name_record(namerec, fp); + + SAFE_FREE(namerec->data.ip); + SAFE_FREE(namerec); + return 0; +} + + +void wins_write_database(time_t t, BOOL background) { - struct name_record *namerec; + static time_t last_write_time = 0; pstring fname, fnamenew; XFILE *fp; - if(!lp_we_are_a_wins_server()) + if (background) { + if (!last_write_time) { + last_write_time = t; + } + if (t - last_write_time < 120) { + return; + } + + } + + if(!lp_we_are_a_wins_server()) { return; + } /* We will do the writing in a child process to ensure that the parent doesn't block while this is done */ if (background) { @@ -1808,6 +2296,11 @@ void wins_write_database(BOOL background) if (sys_fork()) { return; } + if (tdb_reopen(wins_tdb)) { + DEBUG(0,("wins_write_database: tdb_reopen failed. Error was %s\n", + strerror(errno))); + return; + } } slprintf(fname,sizeof(fname)-1,"%s/%s", lp_lockdir(), WINS_LIST); @@ -1826,41 +2319,8 @@ void wins_write_database(BOOL background) x_fprintf(fp,"VERSION %d %u\n", WINS_VERSION, 0); - for( namerec = (struct name_record *)ubi_trFirst( wins_server_subnet->namelist ); namerec; namerec = (struct name_record *)ubi_trNext( namerec ) ) { - int i; - struct tm *tm; - - DEBUGADD(4,("%-19s ", nmb_namestr(&namerec->name) )); - - if( namerec->data.death_time != PERMANENT_TTL ) { - char *ts, *nl; - - tm = localtime(&namerec->data.death_time); - ts = asctime(tm); - nl = strrchr( ts, '\n' ); - if( NULL != nl ) - *nl = '\0'; - DEBUGADD(4,("TTL = %s ", ts )); - } else { - DEBUGADD(4,("TTL = PERMANENT ")); - } + tdb_traverse(wins_tdb, wins_writedb_traverse_fn, fp); - for (i = 0; i < namerec->data.num_ips; i++) - DEBUGADD(4,("%15s ", inet_ntoa(namerec->data.ip[i]) )); - DEBUGADD(4,("%2x\n", namerec->data.nb_flags )); - - if( namerec->data.source == REGISTER_NAME ) { - unstring name; - pull_ascii_nstring(name, sizeof(name), namerec->name.name); - x_fprintf(fp, "\"%s#%02x\" %d ", name,namerec->name.name_type, /* Ignore scope. */ - (int)namerec->data.death_time); - - for (i = 0; i < namerec->data.num_ips; i++) - x_fprintf( fp, "%s ", inet_ntoa( namerec->data.ip[i] ) ); - x_fprintf( fp, "%2xR\n", namerec->data.nb_flags ); - } - } - x_fclose(fp); chmod(fnamenew,0644); unlink(fname); @@ -1870,6 +2330,8 @@ void wins_write_database(BOOL background) } } +#if 0 + Until winsrepl is done. /**************************************************************************** Process a internal Samba message receiving a wins record. ***************************************************************************/ @@ -1885,8 +2347,9 @@ void nmbd_wins_new_entry(int msg_type, struct process_id src, struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); int i; - if (buf==NULL) + if (buf==NULL) { return; + } /* Record should use UNIX codepage. Ensure this is so in the wrepld code. JRA. */ record=(WINS_RECORD *)buf; @@ -1900,8 +2363,15 @@ void nmbd_wins_new_entry(int msg_type, struct process_id src, DEBUG(3,("nmbd_wins_new_entry: adding new replicated record: %s<%02x> for wins server: %s\n", record->name, record->type, inet_ntoa(record->wins_ip))); - new_namerec=add_name_to_subnet( wins_server_subnet, record->name, record->type, record->nb_flags, - EXTINCTION_INTERVAL, REGISTER_NAME, record->num_ips, record->ip); + new_namerec=add_name_to_subnet( wins_server_subnet, + record->name, + record->type, + record->nb_flags, + EXTINCTION_INTERVAL, + REGISTER_NAME, + record->num_ips, + record->ip); + if (new_namerec!=NULL) { update_wins_owner(new_namerec, record->wins_ip); update_wins_flag(new_namerec, record->wins_flags); @@ -2019,3 +2489,4 @@ void nmbd_wins_new_entry(int msg_type, struct process_id src, } } +#endif -- cgit From 4d3152e1454ce62f3d1f864ccbf2a58234dab09d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 13 Dec 2005 19:37:05 +0000 Subject: r12214: Fix compile if SYNC_DNS is set. Jeremy. (This used to be commit 7c545e1e77c3e235b21eb11d5ced91c603da491d) --- source3/nmbd/asyncdns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index c0626d1161..c8caa3fee2 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -323,7 +323,7 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question) struct in_addr dns_ip; unstring qname; - pull_ascii_nstring(qname, question->name); + pull_ascii_nstring(qname, sizeof(qname), question->name); DEBUG(3,("DNS search for %s - ", nmb_namestr(question))); -- cgit From 496b67888202093ad464d05f14eb5633583b2631 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 29 Dec 2005 13:10:33 +0000 Subject: r12564: Ensure load_case_tables is always done first. Jeremy. (This used to be commit addb5095292d6b201cc85f6acab5ec8e6f8f4404) --- source3/nmbd/nmbd.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 78411d3417..68004bad59 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -669,6 +669,8 @@ static BOOL open_sockets(BOOL isdaemon, int port) { NULL } }; + load_case_tables(); + global_nmb_port = NMB_PORT; pc = poptGetContext("nmbd", argc, argv, long_options, 0); -- cgit From 4c7b4cd33aff214879b450e532a091941558727d Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Sun, 15 Jan 2006 12:30:36 +0000 Subject: r12946: fix a segfault in nmbd when 'wins support = yes' caused by double free (This used to be commit c11372f4ec49634e2ae2e6b9ddf4d2b72976f9c5) --- source3/nmbd/nmbd_namelistdb.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 894b877613..baaf5dbd54 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -82,9 +82,11 @@ void remove_name_from_namelist(struct subnet_record *subrec, { if (subrec == wins_server_subnet) { remove_name_from_wins_namelist(namerec); - } else { - subrec->namelist_changed = True; - } + return; + } + + subrec->namelist_changed = True; + DLIST_REMOVE(subrec->namelist, namerec); SAFE_FREE(namerec->data.ip); ZERO_STRUCTP(namerec); -- cgit From f7519540090b2f47259f72d81b267b3e7a1a8950 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 16 Jan 2006 18:03:56 +0000 Subject: r12967: BUG 1061: don't corrupt the file name when reading an lmhosts file (-H) in nmbd. Patch from Andrew Esh (This used to be commit 14160c496112e06e4ea0d0a5aa5bad2b58e90601) --- source3/nmbd/nmbd.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 68004bad59..ea7e9a5288 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -657,13 +657,14 @@ static BOOL open_sockets(BOOL isdaemon, int port) pstring logfile; static BOOL opt_interactive; poptContext pc; + static char *p_lmhosts = dyn_LMHOSTSFILE; struct poptOption long_options[] = { POPT_AUTOHELP {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon(default)" }, {"interactive", 'i', POPT_ARG_VAL, &opt_interactive, True, "Run interactive (not a daemon)" }, {"foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools & etc)" }, {"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" }, - {"hosts", 'H', POPT_ARG_STRING, dyn_LMHOSTSFILE, 'H', "Load a netbios hosts file"}, + {"hosts", 'H', POPT_ARG_STRING, &p_lmhosts, 'H', "Load a netbios hosts file"}, {"port", 'p', POPT_ARG_INT, &global_nmb_port, NMB_PORT, "Listen on the specified port" }, POPT_COMMON_SAMBA { NULL } @@ -803,8 +804,8 @@ static BOOL open_sockets(BOOL isdaemon, int port) } /* Load in any static local names. */ - load_lmhosts_file(dyn_LMHOSTSFILE); - DEBUG(3,("Loaded hosts file %s\n", dyn_LMHOSTSFILE)); + load_lmhosts_file(p_lmhosts); + DEBUG(3,("Loaded hosts file %s\n", p_lmhosts)); /* If we are acting as a WINS server, initialise data structures. */ if( !initialise_wins() ) { -- cgit From e95e6044b06fa225b016f20ab53ee4082a8f5ae0 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 23 Jan 2006 14:02:17 +0000 Subject: r13081: correct fix for the segv in nmbd caused by a double free on namerec. (This used to be commit c908dbc4b260bac72cbc6d25f4728359a6ec8259) --- source3/nmbd/nmbd_namelistdb.c | 11 +++++------ source3/nmbd/nmbd_winsserver.c | 5 +++-- 2 files changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index baaf5dbd54..60023a7ed5 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -80,14 +80,13 @@ static void upcase_name( struct nmb_name *target, const struct nmb_name *source void remove_name_from_namelist(struct subnet_record *subrec, struct name_record *namerec ) { - if (subrec == wins_server_subnet) { + if (subrec == wins_server_subnet) remove_name_from_wins_namelist(namerec); - return; - } - - subrec->namelist_changed = True; + else { + subrec->namelist_changed = True; + DLIST_REMOVE(subrec->namelist, namerec); + } - DLIST_REMOVE(subrec->namelist, namerec); SAFE_FREE(namerec->data.ip); ZERO_STRUCTP(namerec); SAFE_FREE(namerec); diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 5c234bf8dc..9983efe5eb 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -290,8 +290,9 @@ BOOL remove_name_from_wins_namelist(struct name_record *namerec) DLIST_REMOVE(wins_server_subnet->namelist, namerec); SAFE_FREE(namerec->data.ip); - ZERO_STRUCTP(namerec); - SAFE_FREE(namerec); + + /* namerec must be freed by the caller */ + return (ret == 0) ? True : False; } -- cgit From 9c15bd311db76885b27f30ba92d885833f668550 Mon Sep 17 00:00:00 2001 From: Derrell Lipman Date: Sat, 28 Jan 2006 22:53:04 +0000 Subject: r13212: r12414@cabra: derrell | 2006-01-28 17:52:17 -0500 lp_load() could not be called multiple times to modify parameter settings based on reading from multiple configuration settings. Each time, it initialized all of the settings back to their defaults before reading the specified configuration file. This patch adds a parameter to lp_load() specifying whether the settings should be initialized. It does, however, still force the settings to be initialized the first time, even if the request was to not initialize them. (Not doing so could wreak havoc due to uninitialized values.) (This used to be commit f2a24de769d1b2266e576597c57a8e3b1e2a2b51) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index ea7e9a5288..f69cc32ff6 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -291,7 +291,7 @@ static BOOL reload_nmbd_services(BOOL test) if ( test && !lp_file_list_changed() ) return(True); - ret = lp_load( dyn_CONFIGFILE, True , False, False); + ret = lp_load( dyn_CONFIGFILE, True , False, False, True); /* perhaps the config filename is now set */ if ( !test ) { -- cgit From fbe02a6021f339c14b278d1ac706702dcedd8aff Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Wed, 15 Feb 2006 18:22:00 +0000 Subject: r13510: plug memory leak in WINS server code. (This used to be commit 381c327a65489bf8b0fd4935662ca1df6f9e1183) --- source3/nmbd/nmbd_winsserver.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 9983efe5eb..ddc9edfb06 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -207,6 +207,11 @@ struct name_record *find_name_on_wins_subnet(const struct nmb_name *nmbname, BOO } namerec = wins_record_to_name_record(key, data); + + /* done with the this */ + + SAFE_FREE( data.dptr ); + if (!namerec) { return NULL; } -- cgit From fb5362c069b5b6548478b2217a0519c56d856705 Mon Sep 17 00:00:00 2001 From: Gerald Carter Date: Mon, 20 Feb 2006 17:59:58 +0000 Subject: r13571: Replace all calls to talloc_free() with thye TALLOC_FREE() macro which sets the freed pointer to NULL. (This used to be commit b65be8874a2efe5a4b167448960a4fcf6bd995e2) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index f69cc32ff6..38183159a2 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -607,7 +607,7 @@ static void process(void) return; /* free up temp memory */ - lp_talloc_free(); + lp_TALLOC_FREE(); } } -- cgit From 0a516662abf927f96a66abb65034edab639b2682 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 6 Mar 2006 17:01:51 +0000 Subject: r13873: I think this is the longstanding wins server crash bug, not part of the changes I made but something that's been there a while.... Coverity bugid #41. Jeremy. (This used to be commit 2f6cf810eae124820a073258ffe62aace7a92d9c) --- source3/nmbd/nmbd_winsserver.c | 33 ++++++++++++++++----------------- 1 file changed, 16 insertions(+), 17 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index ddc9edfb06..f6f9d743b5 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1246,25 +1246,24 @@ already exists in WINS as a GROUP name.\n", nmb_namestr(question) )); if ( namerec != NULL ) { pull_ascii_nstring(name, sizeof(name), namerec->name.name); - } else { - name[0] = '\0'; - } - - if( is_myname(name) ) { - if(!ismyip(from_ip)) { - DEBUG(3,("wins_process_name_registration_request: Attempt to register name %s. Name \ + if( is_myname(name) ) { + if(!ismyip(from_ip)) { + DEBUG(3,("wins_process_name_registration_request: Attempt to register name %s. Name \ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(question) )); - send_wins_name_registration_response(RFS_ERR, 0, p); - return; - } else { - /* - * It's one of our names and one of our IP's - update the ttl. - */ - update_name_ttl(namerec, ttl); - wins_hook("refresh", namerec, ttl); - send_wins_name_registration_response(0, ttl, p); - return; + send_wins_name_registration_response(RFS_ERR, 0, p); + return; + } else { + /* + * It's one of our names and one of our IP's - update the ttl. + */ + update_name_ttl(namerec, ttl); + wins_hook("refresh", namerec, ttl); + send_wins_name_registration_response(0, ttl, p); + return; + } } + } else { + name[0] = '\0'; } /* -- cgit From fa94300f5fd3b115cebe1604d8c002e6b669b472 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 6 Mar 2006 17:47:21 +0000 Subject: r13875: Fix coverity bug #148. Deref of rrec before NULL check. Jeremy. (This used to be commit 0f1dffb2f2ce5ace1b3216f578ab115c976624c7) --- source3/nmbd/nmbd_winsproxy.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index d6dc6261c8..a31eb1e2a6 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -49,7 +49,12 @@ static void wins_proxy_name_query_request_success( struct subnet_record *subrec, nb_flags = get_nb_flags( rrec->rdata ); - num_ips = rrec->rdlength / 6; + if (rrec) { + num_ips = rrec->rdlength / 6; + } else { + num_ips = 0; + } + if(num_ips == 0) { DEBUG(0,("wins_proxy_name_query_request_success: Invalid number of IP records (0) \ returned for name %s.\n", nmb_namestr(nmbname) )); @@ -71,7 +76,7 @@ returned for name %s.\n", nmb_namestr(nmbname) )); /* Add the queried name to the original subnet as a WINS_PROXY_NAME. */ - if(rrec == PERMANENT_TTL) { + if(rrec && (rrec == PERMANENT_TTL)) { ttl = lp_max_ttl(); } -- cgit From cc6b2d086adab2e08e0e021079f734fbd1ace3cc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 6 Mar 2006 19:23:54 +0000 Subject: r13880: Fix coverity bug CID #97, mem leak on error path. Jeremy. (This used to be commit 0dc37dd2d85d59e7287cebcb7019194cf6754074) --- source3/nmbd/nmbd_winsproxy.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index a31eb1e2a6..a66290da6c 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -85,6 +85,10 @@ returned for name %s.\n", nmb_namestr(nmbname) )); nmbname->name_type, nb_flags, ttl, WINS_PROXY_NAME, num_ips, iplist ); + if(iplist != &ip) { + SAFE_FREE(iplist); + } + namerec = find_name_on_subnet(orig_broadcast_subnet, nmbname, FIND_ANY_NAME); if (!namerec) { DEBUG(0,("wins_proxy_name_query_request_success: failed to add " @@ -94,10 +98,6 @@ returned for name %s.\n", nmb_namestr(nmbname) )); return; } - if(iplist != &ip) { - SAFE_FREE(iplist); - } - /* * Check that none of the IP addresses we are returning is on the * same broadcast subnet as the original requesting packet. If it -- cgit From 9bb215fe68c2b6e1bbc90748ad28d3ba9491e4ac Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 6 Mar 2006 19:27:16 +0000 Subject: r13882: Fix coverity CID bug #96. Missing free on error exit path. Jeremy. (This used to be commit 95ef857c89a330ef4012ba3c10d2bbbbab112b34) --- source3/nmbd/nmbd_winsserver.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index f6f9d743b5..198d90f35a 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -645,6 +645,7 @@ BOOL initialise_wins(void) /* Allocate the space for the ip_list. */ if((ip_list = SMB_MALLOC_ARRAY( struct in_addr, num_ips)) == NULL) { DEBUG(0,("initialise_wins: Malloc fail !\n")); + x_fclose(fp); return False; } -- cgit From 4c0bf8d75dcaca833da2bc8b284d4ddf1d698f64 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 6 Mar 2006 19:30:34 +0000 Subject: r13884: Fix coverity CID #95. Resource leak on error path. Jeremy. (This used to be commit f4bf550b5757024b41062784b185b52a1a0e11f4) --- source3/nmbd/nmbd_packets.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index c25473c4fb..0f84b4f771 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -536,6 +536,8 @@ void queue_wins_refresh(struct nmb_name *nmbname, userdata = (struct userdata_struct *)SMB_MALLOC(sizeof(*userdata) + strlen(tag) + 1); if (!userdata) { + p->locked = False; + free_packet(p); DEBUG(0,("Failed to allocate userdata structure!\n")); return; } -- cgit From 4d79117c6d6507fb183298882d82bfba1f857753 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 6 Mar 2006 19:34:25 +0000 Subject: r13887: Fix coverity bug CID #94. mem leak on error codepath. Jeremy. (This used to be commit dd47e0ef1175a57ec2e9b797ac942cb79f4a5d05) --- source3/nmbd/nmbd_packets.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 0f84b4f771..89362392fe 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1670,11 +1670,13 @@ static BOOL create_listen_fdset(fd_set **ppset, int **psock_array, int *listen_n if((count*2) + 2 > FD_SETSIZE) { DEBUG(0,("create_listen_fdset: Too many file descriptors needed (%d). We can \ only use %d.\n", (count*2) + 2, FD_SETSIZE)); + SAFE_FREE(pset); return True; } if((sock_array = SMB_MALLOC_ARRAY(int, (count*2) + 2)) == NULL) { DEBUG(0,("create_listen_fdset: malloc fail for socket array.\n")); + SAFE_FREE(pset); return True; } -- cgit From 6d9c2b872f1552b7e1127f0b52f197e599fd9552 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 6 Mar 2006 20:05:20 +0000 Subject: r13892: Doh ! My bugfix had a bug :-). Spotted by Willi Mann , if rrec can be null make sure we *never* deref it. Jeremy. (This used to be commit d6d7a5ac62b6ee08e365c5982302b1d8dc69a78f) --- source3/nmbd/nmbd_winsproxy.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index a66290da6c..4f08b2fc5b 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -47,11 +47,11 @@ static void wins_proxy_name_query_request_success( struct subnet_record *subrec, memcpy( (char *)&original_packet, &userdata->data[sizeof(struct subnet_record *)], sizeof(struct packet_struct *) ); - nb_flags = get_nb_flags( rrec->rdata ); - if (rrec) { + nb_flags = get_nb_flags( rrec->rdata ); num_ips = rrec->rdlength / 6; } else { + nb_flags = 0; num_ips = 0; } -- cgit From 6b35642037e17766a25b158c0c0a5f01405ec9e8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 8 Mar 2006 01:43:23 +0000 Subject: r14007: Coverity bug CID #197. Don't compare against 0, we mean the ttl instead. Jeremy. (This used to be commit ccb2a52e29de7e2847ccd93aa99236f63202a4af) --- source3/nmbd/nmbd_winsproxy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index 4f08b2fc5b..7a28eba77d 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -76,7 +76,7 @@ returned for name %s.\n", nmb_namestr(nmbname) )); /* Add the queried name to the original subnet as a WINS_PROXY_NAME. */ - if(rrec && (rrec == PERMANENT_TTL)) { + if(rrec->ttl == PERMANENT_TTL) { ttl = lp_max_ttl(); } -- cgit From 250c02554ec3dd52f33e33406fdd605f5d932d5f Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 21 Mar 2006 13:16:50 +0000 Subject: r14618: add --no-process-group to all server programms to make the following possible: timelimit 20000 bin/nmbd -F -S --no-process-group timelimit 20000 bin/smbd -F -S --no-process-group this is needed to 'make test' working without losing child processes metze (This used to be commit c3a9f30e2a12cc852c9fa3a7d161f5c6ee0694ce) --- source3/nmbd/nmbd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 38183159a2..f58c389fc9 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -658,11 +658,13 @@ static BOOL open_sockets(BOOL isdaemon, int port) static BOOL opt_interactive; poptContext pc; static char *p_lmhosts = dyn_LMHOSTSFILE; + static BOOL no_process_group = False; struct poptOption long_options[] = { POPT_AUTOHELP {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon(default)" }, {"interactive", 'i', POPT_ARG_VAL, &opt_interactive, True, "Run interactive (not a daemon)" }, {"foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools & etc)" }, + {"no-process-group", 0, POPT_ARG_VAL, &no_process_group, True, "Don't create a new process group" }, {"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" }, {"hosts", 'H', POPT_ARG_STRING, &p_lmhosts, 'H', "Load a netbios hosts file"}, {"port", 'p', POPT_ARG_INT, &global_nmb_port, NMB_PORT, "Listen on the specified port" }, @@ -749,7 +751,7 @@ static BOOL open_sockets(BOOL isdaemon, int port) if (is_daemon && !opt_interactive) { DEBUG( 2, ( "Becoming a daemon.\n" ) ); - become_daemon(Fork); + become_daemon(Fork, no_process_group); } #if HAVE_SETPGID @@ -757,7 +759,7 @@ static BOOL open_sockets(BOOL isdaemon, int port) * If we're interactive we want to set our own process group for * signal management. */ - if (opt_interactive) + if (opt_interactive && !no_process_group) setpgid( (pid_t)0, (pid_t)0 ); #endif -- cgit From 4fa555980070d78b39711ef21d77628d26055bc2 Mon Sep 17 00:00:00 2001 From: James Peach Date: Tue, 4 Apr 2006 00:27:50 +0000 Subject: r14898: This change is an attempt to improve the quality of the information that is produced when a process exits abnormally. First, we coalesce the core dumping code so that we greatly improve our odds of being able to produce a core file, even in the case of a memory fault. I've removed duplicates of dump_core() and split it in two to reduce the amount of work needed to actually do the dump. Second, we refactor the exit_server code path to always log an explanation and a stack trace. My goal is to always produce enough log information for us to be able to explain any server exit, though there is a risk that this could produce too much log information on a flaky network. Finally, smbcontrol has gained a smbd fault injection operation to test the changes above. This is only enabled for developer builds. (This used to be commit 56bc02d64498eb3faf89f0c5452b9299daea8e95) --- source3/nmbd/nmbd.c | 41 +---------------------------------------- 1 file changed, 1 insertion(+), 40 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index f58c389fc9..fca17d1ff7 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -106,46 +106,6 @@ static void sig_hup(int sig) sys_select_signal(SIGHUP); } -#if DUMP_CORE -/**************************************************************************** ** - Prepare to dump a core file - carefully! - **************************************************************************** */ - -static BOOL dump_core(void) -{ - char *p; - pstring dname; - pstrcpy( dname, lp_logfile() ); - if ((p=strrchr_m(dname,'/'))) - *p=0; - pstrcat( dname, "/corefiles" ); - mkdir( dname, 0700 ); - sys_chown( dname, getuid(), getgid() ); - chmod( dname, 0700 ); - if ( chdir(dname) ) - return( False ); - umask( ~(0700) ); - -#ifdef HAVE_GETRLIMIT -#ifdef RLIMIT_CORE - { - struct rlimit rlp; - getrlimit( RLIMIT_CORE, &rlp ); - rlp.rlim_cur = MAX( 4*1024*1024, rlp.rlim_cur ); - setrlimit( RLIMIT_CORE, &rlp ); - getrlimit( RLIMIT_CORE, &rlp ); - DEBUG( 3, ( "Core limits now %d %d\n", (int)rlp.rlim_cur, (int)rlp.rlim_max ) ); - } -#endif -#endif - - - DEBUG(0,("Dumping core in %s\n",dname)); - abort(); - return( True ); -} -#endif - /**************************************************************************** ** Possibly continue after a fault. **************************************************************************** */ @@ -692,6 +652,7 @@ static BOOL open_sockets(BOOL isdaemon, int port) } fault_setup((void (*)(void *))fault_continue ); + dump_core_setup("nmbd"); /* POSIX demands that signals are inherited. If the invoking process has * these signals masked, we will have problems, as we won't receive them. */ -- cgit From 0f985dcb1978afd4b383116f01b3acf65c39ecd7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sun, 9 Apr 2006 19:39:38 +0000 Subject: r15012: Fix bug #2715. Fix suggested by ISHIKAWA Tomonori No need to null terminate early, pull_ascii_fstring will do this. Jeremy. (This used to be commit b1bbe568313001f4b4e49382742e4b819c0a2b03) --- source3/nmbd/nmbd_incomingdgrams.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 53b1947157..09eb7bfa86 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -108,7 +108,6 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p START_PROFILE(host_announce); pull_ascii_fstring(comment, buf+31); - comment[42] = 0; pull_ascii_nstring(announce_name, sizeof(announce_name), buf+5); pull_ascii_nstring(source_name, sizeof(source_name), dgram->source_name.name); @@ -267,7 +266,6 @@ void process_local_master_announce(struct subnet_record *subrec, struct packet_s pull_ascii_nstring(server_name,sizeof(server_name),buf+5); pull_ascii_fstring(comment, buf+31); - comment[42] = 0; pull_ascii_nstring(source_name, sizeof(source_name), dgram->source_name.name); pull_ascii_nstring(work_name, sizeof(work_name), dgram->dest_name.name); -- cgit From 4d55a81958a67d5da3227d7af79a5c630f678424 Mon Sep 17 00:00:00 2001 From: James Peach Date: Fri, 5 May 2006 07:15:45 +0000 Subject: r15450: Change profiling data macros to use stack variables rather than globals. This catches mismatched start/end calls and removes the need for special nested profiling calls. (This used to be commit ee750498812190edd3ec52ca3c750258f3b8a97a) --- source3/nmbd/nmbd_incomingdgrams.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 09eb7bfa86..880700c72c 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -797,7 +797,7 @@ void process_announce_request(struct subnet_record *subrec, struct packet_struct work->needannounce = True; done: - END_PROFILE(lm_host_announce); + END_PROFILE(announce_request); } /******************************************************************* @@ -838,5 +838,5 @@ void process_lm_announce_request(struct subnet_record *subrec, struct packet_str done: - END_PROFILE(lm_host_announce); + END_PROFILE(lm_announce_request); } -- cgit From ce5f1afc75d0ece2ebc06eb06ec404c2a8467480 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 7 May 2006 09:21:39 +0000 Subject: r15483: Fix 'declaration after code' warnings. Volker (This used to be commit 7729799be9984a02a2a309289067b7500696e657) --- source3/nmbd/nmbd_elections.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 6e8e8429be..50e1372936 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -166,13 +166,16 @@ void run_elections(time_t t) struct subnet_record *subrec; + START_PROFILE(run_elections); + /* Send election packets once every 2 seconds - note */ - if (lastime && (t - lastime < 2)) + if (lastime && (t - lastime < 2)) { + END_PROFILE(run_elections); return; + } lastime = t; - START_PROFILE(run_elections); for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { struct work_record *work; @@ -267,10 +270,11 @@ void process_election(struct subnet_record *subrec, struct packet_struct *p, cha struct work_record *work; unstring workgroup_name; + START_PROFILE(election); + pull_ascii_nstring(server_name, sizeof(server_name), buf+13); pull_ascii_nstring(workgroup_name, sizeof(workgroup_name), dgram->dest_name.name); - START_PROFILE(election); server_name[15] = 0; DEBUG(3,("process_election: Election request from %s at IP %s on subnet %s for workgroup %s.\n", -- cgit From 0648638fef56a65f9389c8a98f66c57663e8c401 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 May 2006 19:49:44 +0000 Subject: r15700: Make nmbd udp sockets non-blocking to prevent problem with select returning true but no data being available. Fix for bug #3779. Jeremy. (This used to be commit e5787cf75b2e7d50f551f34f28d280c27b0aa134) --- source3/nmbd/nmbd.c | 4 ++++ source3/nmbd/nmbd_responserecordsdb.c | 2 -- source3/nmbd/nmbd_serverlistdb.c | 2 -- source3/nmbd/nmbd_subnetdb.c | 6 ++++-- source3/nmbd/nmbd_workgroupdb.c | 2 -- 5 files changed, 8 insertions(+), 8 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index fca17d1ff7..9c8f99df25 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -605,6 +605,10 @@ static BOOL open_sockets(BOOL isdaemon, int port) set_socket_options( ClientNMB, "SO_BROADCAST" ); set_socket_options( ClientDGRAM, "SO_BROADCAST" ); + /* Ensure we're non-blocking. */ + set_blocking( ClientNMB, False); + set_blocking( ClientDGRAM, False); + DEBUG( 3, ( "open_sockets: Broadcast sockets opened.\n" ) ); return( True ); } diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index a5903ef462..6f22fd906d 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -23,8 +23,6 @@ #include "includes.h" -extern int ClientNMB; - int num_response_packets = 0; /*************************************************************************** diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index 52d00e1585..cc762ae8d2 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -23,8 +23,6 @@ #include "includes.h" -extern int ClientNMB; - int updatecount = 0; /******************************************************************* diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index b2e1178beb..c3640028d2 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -26,8 +26,6 @@ #include "includes.h" extern struct in_addr loopback_ip; -extern int ClientNMB; -extern int ClientDGRAM; extern int global_nmb_port; /* This is the broadcast subnets database. */ @@ -118,6 +116,10 @@ static struct subnet_record *make_subnet(const char *name, enum subnet_type type /* Make sure we can broadcast from these sockets. */ set_socket_options(nmb_sock,"SO_BROADCAST"); set_socket_options(dgram_sock,"SO_BROADCAST"); + + /* Set them non-blocking. */ + set_blocking(nmb_sock, False); + set_blocking(dgram_sock, False); } subrec = SMB_MALLOC_P(struct subnet_record); diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 335d522031..ca665bdf4f 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -23,8 +23,6 @@ #include "includes.h" -extern int ClientNMB; - extern uint16 samba_nb_type; int workgroup_count = 0; /* unique index key: one for each workgroup */ -- cgit From 863aa313c161d206aba8ca3659607a141b8ea83b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Jun 2006 00:36:00 +0000 Subject: r16019: This should not be a level zero message - it's harmless and can happen though misconfiguration. Jeremy. (This used to be commit 4b9cf399a691ba4a7392caca558d0e98b4d19104) --- source3/nmbd/nmbd_responserecordsdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index 6f22fd906d..367c1f4427 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -214,7 +214,7 @@ never happen !\n", remote_broadcast_subnet->subnet_name)); return rrec; } - DEBUG(0,("find_response_record: response packet id %hu received with no \ + DEBUG(3,("find_response_record: response packet id %hu received with no \ matching record.\n", id)); *ppsubrec = NULL; -- cgit From a5da0a72e1f1e026690df4b149a63754f29e6c28 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 14 Jun 2006 00:37:52 +0000 Subject: r16213: Fix Klocwork #852. iface_n_ip can potentially return NULL. Ensure we don't deref. Jeremy. (This used to be commit c2f0ea2ff2f6ad925cee9c85110c6ad828ffb7a9) --- source3/nmbd/nmbd_become_dmb.c | 10 +++++++++- source3/nmbd/nmbd_subnetdb.c | 8 +++++++- 2 files changed, 16 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index fb1fb33a81..523ec6cabf 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -120,6 +120,7 @@ in workgroup %s on subnet %s\n", if( subrec == unicast_subnet ) { struct nmb_name nmbname; struct in_addr my_first_ip; + struct in_addr *nip; /* Put our name and first IP address into the workgroup struct as domain master browser. This @@ -130,7 +131,14 @@ in workgroup %s on subnet %s\n", work->dmb_name = nmbname; /* Pick the first interface ip address as the domain master browser ip. */ - my_first_ip = *iface_n_ip(0); + nip = iface_n_ip(0); + + if (!nip) { + DEBUG(0,("become_domain_master_stage2: Error. iface_n_ip returned NULL\n")); + return; + } + + my_first_ip = *nip; putip((char *)&work->dmb_addr, &my_first_ip); diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index c3640028d2..5a93d8bec0 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -220,7 +220,13 @@ BOOL create_subnets(void) if (lp_we_are_a_wins_server()) { /* Pick the first interface ip address as the WINS server ip. */ - unicast_ip = *iface_n_ip(0); + struct in_addr *nip = iface_n_ip(0); + + if (!nip) { + return False; + } + + unicast_ip = *nip; } else { /* note that we do not set the wins server IP here. We just set it at zero and let the wins registration code cope -- cgit From a1e0a0e9286fbe90ca04cda9df38e72d8d18b0c1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 14 Jun 2006 21:36:49 +0000 Subject: r16230: Fix Klocwork #861 and others. localtime and asctime can return NULL. Ensure we check all returns correctly. Jeremy. (This used to be commit 6c61dc8ed6d84f310ef391fb7700e93ef42c4afc) --- source3/nmbd/nmbd_namelistdb.c | 20 ++++++++++++++++++-- source3/nmbd/nmbd_winsserver.c | 6 ++++++ 2 files changed, 24 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 60023a7ed5..fb32ce1aad 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -564,15 +564,31 @@ void dump_name_record( struct name_record *namerec, XFILE *fp) x_fprintf(fp,"Source = %s\nb_flags = %x\t", src_type, namerec->data.nb_flags); if(namerec->data.death_time != PERMANENT_TTL) { + const char *asct; tm = localtime(&namerec->data.death_time); - x_fprintf(fp, "death_time = %s\t", asctime(tm)); + if (!tm) { + return; + } + asct = asctime(tm); + if (!asct) { + return; + } + x_fprintf(fp, "death_time = %s\t", asct); } else { x_fprintf(fp, "death_time = PERMANENT\t"); } if(namerec->data.refresh_time != PERMANENT_TTL) { + const char *asct; tm = localtime(&namerec->data.refresh_time); - x_fprintf(fp, "refresh_time = %s\n", asctime(tm)); + if (!tm) { + return; + } + asct = asctime(tm); + if (!asct) { + return; + } + x_fprintf(fp, "refresh_time = %s\n", asct); } else { x_fprintf(fp, "refresh_time = PERMANENT\n"); } diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 198d90f35a..29d5c41de8 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -2222,7 +2222,13 @@ void wins_write_name_record(struct name_record *namerec, XFILE *fp) char *ts, *nl; tm = localtime(&namerec->data.death_time); + if (!tm) { + return; + } ts = asctime(tm); + if (!ts) { + return; + } nl = strrchr( ts, '\n' ); if( NULL != nl ) { *nl = '\0'; -- cgit From 44333763612a79d64f109f94b47c5c26bd01e625 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 16 Jun 2006 22:44:28 +0000 Subject: r16313: Not a problem - but ensure Klocwork is quiet (#872). Jeremy. (This used to be commit 22a345deed6caa5750e2bb233a20422ad7b90d94) --- source3/nmbd/nmbd_subnetdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 5a93d8bec0..3b9be2c2ce 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -57,8 +57,6 @@ yet and it may be in use by a response record void close_subnet(struct subnet_record *subrec) { - DLIST_REMOVE(subnetlist, subrec); - if (subrec->dgram_sock != -1) { close(subrec->dgram_sock); subrec->dgram_sock = -1; @@ -67,6 +65,8 @@ void close_subnet(struct subnet_record *subrec) close(subrec->nmb_sock); subrec->nmb_sock = -1; } + + DLIST_REMOVE(subnetlist, subrec); } /**************************************************************************** -- cgit From 9a7adde8a37a5593e8fbb2bdfd5003c837d568ed Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 28 Jun 2006 00:01:28 +0000 Subject: r16576: Fix Klocwork #2015. Possible null deref. Jeremy. (This used to be commit 9cbfaf62a3c4bb7d2e594e412449506ab0af4063) --- source3/nmbd/nmbd.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 9c8f99df25..26495d25c1 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -173,6 +173,11 @@ static BOOL reload_interfaces(time_t t) for (n=iface_count() - 1; n >= 0; n--) { struct interface *iface = get_interface(n); + if (!iface) { + DEBUG(2,("reload_interfaces: failed to get interface %d\n", n)); + continue; + } + /* * We don't want to add a loopback interface, in case * someone has added 127.0.0.1 for smbd, nmbd needs to -- cgit From d70803ebe3472cc1930e5732b320d14a47c54d28 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 28 Jun 2006 00:05:53 +0000 Subject: r16579: Fix Klocwork #2016. Possible null deref. Jeremy. (This used to be commit f6d5bae4a105eee1b1d5b1aaa70a675705345d9e) --- source3/nmbd/nmbd_serverlistdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index cc762ae8d2..ea27f9d4e5 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -214,7 +214,7 @@ static uint32 write_this_server_name( struct subnet_record *subrec, struct work_record *iwork; /* Go through all the subnets we have already seen. */ - for (ssub = FIRST_SUBNET; ssub != subrec; ssub = NEXT_SUBNET_INCLUDING_UNICAST(ssub)) { + for (ssub = FIRST_SUBNET; ssub && (ssub != subrec); ssub = NEXT_SUBNET_INCLUDING_UNICAST(ssub)) { for(iwork = ssub->workgrouplist; iwork; iwork = iwork->next) { if(find_server_in_workgroup( iwork, servrec->serv.name) != NULL) { /* -- cgit From 5a1a08d4286b85252233517373cad75a355b05a7 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 28 Jun 2006 00:07:53 +0000 Subject: r16581: Fix Klocwork #2017. Possible null deref. Jeremy. (This used to be commit 6967fd4cefa84a7b7b5e14467bfa8152907d55c9) --- source3/nmbd/nmbd_subnetdb.c | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 3b9be2c2ce..04df3e9a4f 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -203,6 +203,11 @@ BOOL create_subnets(void) for (i = 0 ; i < num_interfaces; i++) { struct interface *iface = get_interface(i); + if (!iface) { + DEBUG(2,("create_subnets: can't get interface %d.\n", i )); + continue; + } + /* * We don't want to add a loopback interface, in case * someone has added 127.0.0.1 for smbd, nmbd needs to -- cgit From 79eaa709a05d765673ea0766b1d23a0c60d76b4c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 28 Jun 2006 20:39:07 +0000 Subject: r16642: Fix show-stopper bug #3876. Double-free in wins server code. Jerry please merge for 3.0.23. Jeremy. (This used to be commit d354b430ff0473764db8ea492a68d10946dadc23) --- source3/nmbd/nmbd_winsserver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 29d5c41de8..86f7fd5850 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -76,6 +76,7 @@ static struct name_record *wins_record_to_name_record(TDB_DATA key, TDB_DATA dat if (!namerec) { return NULL; } + ZERO_STRUCTP(namerec); namerec->data.ip = SMB_MALLOC_ARRAY(struct in_addr, num_ips); if (!namerec->data.ip) { @@ -294,7 +295,6 @@ BOOL remove_name_from_wins_namelist(struct name_record *namerec) ret = tdb_delete(wins_tdb, key); DLIST_REMOVE(wins_server_subnet->namelist, namerec); - SAFE_FREE(namerec->data.ip); /* namerec must be freed by the caller */ -- cgit From d88926f6b4c11ba60200d7a7574b14fd04ab8a8f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 29 Jun 2006 00:48:44 +0000 Subject: r16665: Fix a couple of bugs I discovered now I've looked closer at the wins server code. Firstly, it needs to do the searches on the SELF_NAMES correctly, secondly it needs to flush the in-memory cache out before returning the 1b names - else it might get duplicates returned if many 1b queries are done in quick succession. Jerry, I hate to say this but you might want to consider this for 3.0.23.... Jeremy. (This used to be commit b36b9befbbc4ac318168b7788d3722710ecbf10f) --- source3/nmbd/nmbd_namelistdb.c | 2 +- source3/nmbd/nmbd_winsserver.c | 42 ++++++++++++++++++++++++++++++++---------- 2 files changed, 33 insertions(+), 11 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index fb32ce1aad..d71eb5479a 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -120,7 +120,7 @@ struct name_record *find_name_on_subnet(struct subnet_record *subrec, if( self_only && (name_ret->data.source != SELF_NAME) && (name_ret->data.source != PERMANENT_NAME) ) { DEBUG( 9, ( "find_name_on_subnet: on subnet %s - self name %s NOT FOUND\n", subrec->subnet_name, nmb_namestr(nmbname) ) ); - return False; + return NULL; } DEBUG( 9, ("find_name_on_subnet: on subnet %s - found name %s source=%d\n", diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 86f7fd5850..75841414bc 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -34,6 +34,24 @@ TDB_CONTEXT *wins_tdb; +/**************************************************************************** + Delete all the temporary name records on the in-memory linked list. +*****************************************************************************/ + +static void wins_delete_all_tmp_in_memory_records(void) +{ + struct name_record *nr = NULL; + struct name_record *nrnext = NULL; + + /* Delete all temporary name records on the wins subnet linked list. */ + for( nr = wins_server_subnet->namelist; nr; nr = nrnext) { + nrnext = nr->next; + DLIST_REMOVE(wins_server_subnet->namelist, nr); + SAFE_FREE(nr->data.ip); + SAFE_FREE(nr); + } +} + /**************************************************************************** Convert a wins.tdb record to a struct name_record. Add in our global_scope(). *****************************************************************************/ @@ -217,6 +235,14 @@ struct name_record *find_name_on_wins_subnet(const struct nmb_name *nmbname, BOO return NULL; } + /* Self names only - these include permanent names. */ + if( self_only && (namerec->data.source != SELF_NAME) && (namerec->data.source != PERMANENT_NAME) ) { + DEBUG( 9, ( "find_name_on_wins_subnet: self name %s NOT FOUND\n", nmb_namestr(nmbname) ) ); + SAFE_FREE(namerec->data.ip); + SAFE_FREE(namerec); + return NULL; + } + /* Search for this name record on the list. Replace it if found. */ for( nr = wins_server_subnet->namelist; nr; nr = nr->next) { @@ -1739,6 +1765,11 @@ static void process_wins_dmb_query_request(struct subnet_record *subrec, num_ips = 0; + /* First, clear the in memory list - we're going to re-populate + it with the tdb_traversal in fetch_all_active_wins_1b_names. */ + + wins_delete_all_tmp_in_memory_records(); + fetch_all_active_wins_1b_names(); for( namerec = subrec->namelist; namerec; namerec = namerec->next ) { @@ -2176,8 +2207,6 @@ we are not the wins owner !\n", nmb_namestr(&namerec->name))); void initiate_wins_processing(time_t t) { static time_t lasttime = 0; - struct name_record *nr = NULL; - struct name_record *nrnext = NULL; if (!lasttime) { lasttime = t; @@ -2193,14 +2222,7 @@ void initiate_wins_processing(time_t t) tdb_traverse(wins_tdb, wins_processing_traverse_fn, &t); - - /* Delete all temporary name records on the wins subnet linked list. */ - for( nr = wins_server_subnet->namelist; nr; nr = nrnext) { - nrnext = nr->next; - DLIST_REMOVE(wins_server_subnet->namelist, nr); - SAFE_FREE(nr->data.ip); - SAFE_FREE(nr); - } + wins_delete_all_tmp_in_memory_records(); wins_write_database(t, True); -- cgit From fbdcf2663b56007a438ac4f0d8d82436b1bfe688 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 11 Jul 2006 18:01:26 +0000 Subject: r16945: Sync trunk -> 3.0 for 3.0.24 code. Still need to do the upper layer directories but this is what everyone is waiting for.... Jeremy. (This used to be commit 9dafb7f48ca3e7af956b0a7d1720c2546fc4cfb8) --- source3/nmbd/nmbd_synclists.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 28ad92ed10..0e67c3f69c 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -68,7 +68,7 @@ static void sync_child(char *name, int nm_type, char *fname) { fstring unix_workgroup; - static struct cli_state cli; + struct cli_state *cli; uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0; struct nmb_name called, calling; @@ -76,50 +76,55 @@ static void sync_child(char *name, int nm_type, * Patch from Andy Levine andyl@epicrealm.com. */ - if (!cli_initialise(&cli) || !cli_set_port(&cli, 139) || !cli_connect(&cli, name, &ip)) { + cli = cli_initialise(); + if (!cli) { + return; + } + + if (!cli_set_port(cli, 139) || !cli_connect(cli, name, &ip)) { return; } make_nmb_name(&calling, local_machine, 0x0); make_nmb_name(&called , name, nm_type); - if (!cli_session_request(&cli, &calling, &called)) { - cli_shutdown(&cli); + if (!cli_session_request(cli, &calling, &called)) { + cli_shutdown(cli); return; } - if (!cli_negprot(&cli)) { - cli_shutdown(&cli); + if (!cli_negprot(cli)) { + cli_shutdown(cli); return; } - if (!cli_session_setup(&cli, "", "", 1, "", 0, workgroup)) { - cli_shutdown(&cli); + if (!cli_session_setup(cli, "", "", 1, "", 0, workgroup)) { + cli_shutdown(cli); return; } - if (!cli_send_tconX(&cli, "IPC$", "IPC", "", 1)) { - cli_shutdown(&cli); + if (!cli_send_tconX(cli, "IPC$", "IPC", "", 1)) { + cli_shutdown(cli); return; } /* All the cli_XX functions take UNIX character set. */ - fstrcpy(unix_workgroup, cli.server_domain?cli.server_domain:workgroup); + fstrcpy(unix_workgroup, cli->server_domain ? cli->server_domain : workgroup); /* Fetch a workgroup list. */ - cli_NetServerEnum(&cli, unix_workgroup, + cli_NetServerEnum(cli, unix_workgroup, local_type|SV_TYPE_DOMAIN_ENUM, callback, NULL); /* Now fetch a server list. */ if (servers) { fstrcpy(unix_workgroup, workgroup); - cli_NetServerEnum(&cli, unix_workgroup, + cli_NetServerEnum(cli, unix_workgroup, local?SV_TYPE_LOCAL_LIST_ONLY:SV_TYPE_ALL, callback, NULL); } - cli_shutdown(&cli); + cli_shutdown(cli); } /******************************************************************* -- cgit From b29915d6113264bdce243005d29a1af9a8b69bde Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 16 Aug 2006 17:14:16 +0000 Subject: r17571: Change the return code of cli_session_setup from BOOL to NTSTATUS Volker (This used to be commit 94817a8ef53589011bc4ead4e17807a101acf5c9) --- source3/nmbd/nmbd_synclists.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 0e67c3f69c..7fe39676c6 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -98,7 +98,8 @@ static void sync_child(char *name, int nm_type, return; } - if (!cli_session_setup(cli, "", "", 1, "", 0, workgroup)) { + if (!NT_STATUS_IS_OK(cli_session_setup(cli, "", "", 1, "", 0, + workgroup))) { cli_shutdown(cli); return; } -- cgit From f852fdbe06ec9f19424d6870cba9b1872a0d5d7a Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sun, 20 Aug 2006 17:55:06 +0000 Subject: r17626: Some C++ Warnings (This used to be commit 09e7c010f03ac3c621f7a7fad44685d278c1481a) --- source3/nmbd/nmbd_winsserver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 75841414bc..320415503b 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -159,7 +159,7 @@ static TDB_DATA name_record_to_wins_record(const struct name_record *namerec) len = (2 + 1 + (7*4)); /* "wbddddddd" */ len += (namerec->data.num_ips * 4); - data.dptr = SMB_MALLOC(len); + data.dptr = (char *)SMB_MALLOC(len); if (!data.dptr) { return data; } -- cgit From e7a49f2b25be3d893a516d6cc3c205b58ff0c20c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 21 Aug 2006 20:03:32 +0000 Subject: r17668: Fix the miscalculations in pushing announces. Fixes problems Kukks reported. Jeremy. (This used to be commit 426d722029b245e239f0ee39b6be249c59e1918c) --- source3/nmbd/nmbd_sendannounce.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index a74dd99196..7fcedc557e 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -35,7 +35,7 @@ extern BOOL found_lm_clients; void send_browser_reset(int reset_type, const char *to_name, int to_type, struct in_addr to_ip) { - pstring outbuf; + char outbuf[PSTRING_LEN]; char *p; DEBUG(3,("send_browser_reset: sending reset request type %d to %s<%02x> IP %s.\n", @@ -60,7 +60,7 @@ void send_browser_reset(int reset_type, const char *to_name, int to_type, struct void broadcast_announce_request(struct subnet_record *subrec, struct work_record *work) { - pstring outbuf; + char outbuf[PSTRING_LEN]; char *p; work->needannounce = True; @@ -91,7 +91,7 @@ static void send_announcement(struct subnet_record *subrec, int announce_type, time_t announce_interval, const char *server_name, int server_type, const char *server_comment) { - pstring outbuf; + char outbuf[PSTRING_LEN]; unstring upper_server_name; char *p; @@ -116,7 +116,7 @@ static void send_announcement(struct subnet_record *subrec, int announce_type, SSVAL(p,27,BROWSER_ELECTION_VERSION); SSVAL(p,29,BROWSER_CONSTANT); /* Browse signature. */ - p += 31 + push_string(NULL, p+31, server_comment, -1, STR_ASCII|STR_TERMINATE); + p += 31 + push_string(NULL, p+31, server_comment, sizeof(outbuf) - (p + 31 - outbuf), STR_ASCII|STR_TERMINATE); send_mailslot(False,BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), from_name, 0x0, to_name, to_type, to_ip, subrec->myip, @@ -132,7 +132,7 @@ static void send_lm_announcement(struct subnet_record *subrec, int announce_type time_t announce_interval, char *server_name, int server_type, char *server_comment) { - pstring outbuf; + char outbuf[PSTRING_LEN]; char *p=outbuf; memset(outbuf,'\0',sizeof(outbuf)); @@ -145,7 +145,7 @@ static void send_lm_announcement(struct subnet_record *subrec, int announce_type p += 10; p += push_string(NULL, p, server_name, 15, STR_ASCII|STR_UPPER|STR_TERMINATE); - p += push_string(NULL, p, server_comment, sizeof(pstring)-15, STR_ASCII|STR_UPPER|STR_TERMINATE); + p += push_string(NULL, p, server_comment, sizeof(outbuf)- (p - outbuf), STR_ASCII|STR_UPPER|STR_TERMINATE); send_mailslot(False,LANMAN_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), from_name, 0x0, to_name, to_type, to_ip, subrec->myip, -- cgit From 22c7238825112813444012289c898086b2414bd4 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 24 Aug 2006 20:42:31 +0000 Subject: r17807: Fix a file descriptor leak pointed out by John Malmberg. Thanks! Volker (This used to be commit fac007ccbec75f5ee9ff2769d8add4d27e62167d) --- source3/nmbd/asyncdns.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index c8caa3fee2..0c7a1e50b7 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -205,6 +205,7 @@ void run_dns_queue(void) if (!process_exists_by_pid(child_pid)) { close(fd_in); + close(fd_out); start_async_dns(); } -- cgit From 6f9ce7def71ac7156be1583a6a0d610414330c98 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 28 Aug 2006 02:13:50 +0000 Subject: r17864: Fix possible null deref if client doesn't give us an answer record. Found by the Stanford checker. Jeremy. (This used to be commit 1ec77c50118de808f710b17f878b1e80d4e351d5) --- source3/nmbd/nmbd_namequery.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index 1b07852f11..2c1cd13034 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -59,7 +59,15 @@ static void query_name_response( struct subnet_record *subrec, rrec->repeat_count = 0; /* How long we should wait for. */ - rrec->repeat_time = p->timestamp + nmb->answers->ttl; + if (nmb->answers) { + rrec->repeat_time = p->timestamp + nmb->answers->ttl; + } else { + /* No answer - this is probably a corrupt + packet.... */ + DEBUG(0,("query_name_response: missing answer record in " + "NMB_WACK_OPCODE response.\n")); + rrec->repeat_time = p->timestamp + 10; + } rrec->num_msgs--; return; } else if(nmb->header.rcode != 0) { -- cgit From 258a465e20e007a30043220367d17ecfc87b4f90 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Mon, 18 Sep 2006 07:52:16 +0000 Subject: r18605: sync dlinklist.h with samba4, that means DLIST_ADD_END() and DLIST_DEMOTE() now take the type of the tmp pointer not the tmp pointer itself anymore. metze (This used to be commit 2f58645b7094e81dff3734f11aa183ea2ab53d2d) --- source3/nmbd/nmbd_browserdb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c index e27e483702..b75028be0d 100644 --- a/source3/nmbd/nmbd_browserdb.c +++ b/source3/nmbd/nmbd_browserdb.c @@ -86,7 +86,6 @@ struct browse_cache_record *create_browser_in_lmb_cache( const char *work_name, struct in_addr ip ) { struct browse_cache_record *browc; - struct browse_cache_record *tmp_browc; time_t now = time( NULL ); browc = SMB_MALLOC_P(struct browse_cache_record); @@ -115,7 +114,7 @@ struct browse_cache_record *create_browser_in_lmb_cache( const char *work_name, browc->ip = ip; - DLIST_ADD_END(lmb_browserlist, browc, tmp_browc); + DLIST_ADD_END(lmb_browserlist, browc, struct browse_cache_record *); if( DEBUGLVL( 3 ) ) { Debug1( "nmbd_browserdb:create_browser_in_lmb_cache()\n" ); -- cgit From b4498846618eacde0d38e88c0f1882eff9f56b5c Mon Sep 17 00:00:00 2001 From: Jim McDonough Date: Tue, 19 Sep 2006 00:39:21 +0000 Subject: r18660: Fix build, one uuid->GUID was missed. (This used to be commit f8ea2069d444a6630b61828999605a3ed011db02) --- source3/nmbd/nmbd_processlogon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 5c0fc2c521..4a8d1db51d 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -382,7 +382,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", } #ifdef HAVE_ADS else { - struct uuid domain_guid; + struct GUID domain_guid; UUID_FLAT flat_guid; pstring domain; pstring hostname; -- cgit From 9a0273634860386ecdd6b4c606f30f2620ae3dc0 Mon Sep 17 00:00:00 2001 From: James Peach Date: Tue, 7 Nov 2006 17:18:00 +0000 Subject: r19626: Coalesce usage of DUMP_CORE. Fix formatting on chdir error message in core dump path. (This used to be commit 9a51fba71c5fa7082c331e1a78a98638d9aa06cf) --- source3/nmbd/nmbd.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 26495d25c1..4a05fde28c 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -112,9 +112,7 @@ static void sig_hup(int sig) static void fault_continue(void) { -#if DUMP_CORE dump_core(); -#endif } /**************************************************************************** ** -- cgit From caf8c6a76be051559ffcfe97084edca43e0a3cee Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 30 Jan 2007 22:22:06 +0000 Subject: r21064: The core of this patch is void message_register(int msg_type, void (*fn)(int msg_type, struct process_id pid, - void *buf, size_t len)) + void *buf, size_t len, + void *private_data), + void *private_data) { struct dispatch_fns *dfn; So this adds a (so far unused) private pointer that is passed from message_register to the message handler. A prerequisite to implement a tiny samba4-API compatible wrapper around our messaging system. That itself is necessary for the Samba4 notify system. Yes, I know, I could import the whole Samba4 messaging system, but I want to do it step by step and I think getting notify in is more important in this step. Volker (This used to be commit c8ae60ed65dcce9660ee39c75488f2838cf9a28b) --- source3/nmbd/nmbd.c | 18 +++++++++--------- source3/nmbd/nmbd_elections.c | 2 +- source3/nmbd/nmbd_winsserver.c | 2 +- 3 files changed, 11 insertions(+), 11 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 4a05fde28c..46f209872b 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -77,7 +77,7 @@ static void terminate(void) **************************************************************************** */ static void nmbd_terminate(int msg_type, struct process_id src, - void *buf, size_t len) + void *buf, size_t len, void *private_data) { terminate(); } @@ -272,7 +272,7 @@ static BOOL reload_nmbd_services(BOOL test) **************************************************************************** */ static void msg_reload_nmbd_services(int msg_type, struct process_id src, - void *buf, size_t len) + void *buf, size_t len, void *private_data) { write_browse_list( 0, True ); dump_all_namelists(); @@ -289,7 +289,7 @@ static void msg_reload_nmbd_services(int msg_type, struct process_id src, } static void msg_nmbd_send_packet(int msg_type, struct process_id src, - void *buf, size_t len) + void *buf, size_t len, void *private_data) { struct packet_struct *p = (struct packet_struct *)buf; struct subnet_record *subrec; @@ -558,7 +558,7 @@ static void process(void) if(reload_after_sighup) { DEBUG( 0, ( "Got SIGHUP dumping debug info.\n" ) ); msg_reload_nmbd_services(MSG_SMB_CONF_UPDATED, - pid_to_procid(0), (void*) &no_subnets, 0); + pid_to_procid(0), (void*) &no_subnets, 0, NULL); if(no_subnets) return; reload_after_sighup = 0; @@ -745,14 +745,14 @@ static BOOL open_sockets(BOOL isdaemon, int port) pidfile_create("nmbd"); message_init(); - message_register(MSG_FORCE_ELECTION, nmbd_message_election); + message_register(MSG_FORCE_ELECTION, nmbd_message_election, NULL); #if 0 /* Until winsrepl is done. */ - message_register(MSG_WINS_NEW_ENTRY, nmbd_wins_new_entry); + message_register(MSG_WINS_NEW_ENTRY, nmbd_wins_new_entry, NULL); #endif - message_register(MSG_SHUTDOWN, nmbd_terminate); - message_register(MSG_SMB_CONF_UPDATED, msg_reload_nmbd_services); - message_register(MSG_SEND_PACKET, msg_nmbd_send_packet); + message_register(MSG_SHUTDOWN, nmbd_terminate, NULL); + message_register(MSG_SMB_CONF_UPDATED, msg_reload_nmbd_services, NULL); + message_register(MSG_SEND_PACKET, msg_nmbd_send_packet, NULL); TimeInit(); diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 50e1372936..3aadd70b83 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -379,7 +379,7 @@ yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name )); ***************************************************************************/ void nmbd_message_election(int msg_type, struct process_id src, - void *buf, size_t len) + void *buf, size_t len, void *private_data) { struct subnet_record *subrec; diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 320415503b..6ea102c391 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -2371,7 +2371,7 @@ void wins_write_database(time_t t, BOOL background) ***************************************************************************/ void nmbd_wins_new_entry(int msg_type, struct process_id src, - void *buf, size_t len) + void *buf, size_t len, void *private_data) { WINS_RECORD *record; struct name_record *namerec = NULL; -- cgit From 56ba44766854ed7cda265bdaf85913f2a1008282 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 28 Mar 2007 13:34:59 +0000 Subject: r22001: change prototype of dump_data(), so that it takes unsigned char * now, which matches what samba4 has. also fix all the callers to prevent compiler warnings metze (This used to be commit fa322f0cc9c26a9537ba3f0a7d4e4a25941317e7) --- source3/nmbd/nmbd_processlogon.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 4a8d1db51d..232f430b66 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -141,7 +141,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); SSVAL(q, 0, token); q += 2; - dump_data(4, outbuf, PTR_DIFF(q, outbuf)); + dump_data(4, (uint8 *)outbuf, PTR_DIFF(q, outbuf)); send_mailslot(True, getdc_str, outbuf,PTR_DIFF(q,outbuf), @@ -257,7 +257,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", QUERYFORPDC_R, (uint32)ntversion, (uint32)lmnttoken, (uint32)lm20token )); - dump_data(4, outbuf, PTR_DIFF(q, outbuf)); + dump_data(4, (uint8 *)outbuf, PTR_DIFF(q, outbuf)); pull_ascii_fstring(getdc_str, getdc); pull_ascii_nstring(source_name, sizeof(source_name), dgram->source_name.name); @@ -501,7 +501,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", SSVAL(q, 6, 0xffff); /* our lm20token */ q += 8; - dump_data(4, outbuf, PTR_DIFF(q, outbuf)); + dump_data(4, (uint8 *)outbuf, PTR_DIFF(q, outbuf)); pull_ascii_fstring(getdc_str, getdc); pull_ascii_nstring(source_name, sizeof(source_name), dgram->source_name.name); -- cgit From bc2b6436d0f5f3e9ffdfaeb7f1b32996a83d5478 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Thu, 29 Mar 2007 09:35:51 +0000 Subject: r22009: change TDB_DATA from char * to unsigned char * and fix all compiler warnings in the users metze (This used to be commit 3a28443079c141a6ce8182c65b56ca210e34f37f) --- source3/nmbd/nmbd_winsserver.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 6ea102c391..9c2fe72702 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -103,7 +103,7 @@ static struct name_record *wins_record_to_name_record(TDB_DATA key, TDB_DATA dat } namerec->subnet = wins_server_subnet; - push_ascii_nstring(namerec->name.name, key.dptr); + push_ascii_nstring(namerec->name.name, (const char *)key.dptr); namerec->name.name_type = key.dptr[sizeof(unstring)]; /* Add the scope. */ push_ascii(namerec->name.scope, global_scope(), 64, STR_TERMINATE); @@ -159,7 +159,7 @@ static TDB_DATA name_record_to_wins_record(const struct name_record *namerec) len = (2 + 1 + (7*4)); /* "wbddddddd" */ len += (namerec->data.num_ips * 4); - data.dptr = (char *)SMB_MALLOC(len); + data.dptr = (uint8 *)SMB_MALLOC(len); if (!data.dptr) { return data; } @@ -197,7 +197,7 @@ static TDB_DATA name_to_key(const struct nmb_name *nmbname) pull_ascii_nstring(keydata, sizeof(unstring), nmbname->name); strupper_m(keydata); keydata[sizeof(unstring)] = nmbname->name_type; - key.dptr = keydata; + key.dptr = (uint8 *)keydata; key.dsize = sizeof(keydata); return key; -- cgit From 261c004d7bf85de945a1a3956c1d8f15075bc224 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 30 Mar 2007 22:25:08 +0000 Subject: r22014: Make us pass RANDOMIPC test again :-(. This is an ugly check-in, but I've no option. Jeremy. (This used to be commit c3a565081d70b209a4f9e6e8f1859bf7194a5f74) --- source3/nmbd/nmbd_browsesync.c | 2 +- source3/nmbd/nmbd_elections.c | 2 +- source3/nmbd/nmbd_incomingdgrams.c | 18 ++++++++++++------ source3/nmbd/nmbd_packets.c | 6 +++--- source3/nmbd/nmbd_processlogon.c | 38 +++++++++++++++++++------------------- source3/nmbd/nmbd_sendannounce.c | 2 +- 6 files changed, 37 insertions(+), 31 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 9535a3115a..ddb223de9f 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -125,7 +125,7 @@ static void announce_local_master_browser_to_domain_master_browser( struct work_ /* The call below does CH_UNIX -> CH_DOS conversion. JRA */ push_pstring_base(p, myname, outbuf); - p = skip_string(p,1); + p = skip_string(outbuf,sizeof(outbuf),p,1); if( DEBUGLVL( 4 ) ) { dbgtext( "announce_local_master_browser_to_domain_master_browser:\n" ); diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 3aadd70b83..fbdb6c4524 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -53,7 +53,7 @@ static void send_election_dgram(struct subnet_record *subrec, const char *workgr strupper_m(srv_name); /* The following call does UNIX -> DOS charset conversion. */ pstrcpy_base(p, srv_name, outbuf); - p = skip_string(p,1); + p = skip_string(outbuf,sizeof(outbuf),p,1); send_mailslot(False, BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), global_myname(), 0, diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 880700c72c..616b5df9db 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -416,7 +416,7 @@ done: Process an incoming LanMan host announcement packet. *******************************************************************/ -void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf) +void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct *p, char *buf, int len) { struct dgram_packet *dgram = &p->packet.dgram; uint32 servertype = IVAL(buf,1); @@ -429,10 +429,16 @@ void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct unstring work_name; unstring source_name; fstring comment; - char *s = buf+9; + char *s = get_safe_offset(buf,len,buf,9); + if (!s) { + return; + } START_PROFILE(lm_host_announce); - s = skip_string(s,1); + s = skip_string(buf,len,s,1); + if (!s) { + return; + } pull_ascii(comment, s, sizeof(fstring), 43, STR_TERMINATE); pull_ascii_nstring(announce_name,sizeof(announce_name),buf+9); @@ -568,7 +574,7 @@ static void send_backup_list_response(struct subnet_record *subrec, myname[15]='\0'; push_pstring_base(p, myname, outbuf); - p = skip_string(p,1); + p = skip_string(outbuf,sizeof(outbuf),p,1); /* Look for backup browsers in this workgroup. */ @@ -604,7 +610,7 @@ static void send_backup_list_response(struct subnet_record *subrec, DEBUG(5,("send_backup_list_response: Adding server %s number %d\n", p, count)); - p = skip_string(p,1); + p = skip_string(outbuf,sizeof(outbuf),p,1); } #endif @@ -809,7 +815,7 @@ done: through the "lm announce" parameter in smb.conf) ******************************************************************/ -void process_lm_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf) +void process_lm_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf, int len) { struct dgram_packet *dgram = &p->packet.dgram; unstring workgroup_name; diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 89362392fe..5ec6be1307 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1153,10 +1153,10 @@ mismatch with our scope (%s).\n", inet_ntoa(p->ip), scope, global_scope())); switch (command) { case ANN_HostAnnouncement: debug_browse_data(buf, len); - process_lm_host_announce(subrec, p, buf+1); + process_lm_host_announce(subrec, p, buf+1, len > 1 ? len-1 : 0); break; case ANN_AnnouncementRequest: - process_lm_announce_request(subrec, p, buf+1); + process_lm_announce_request(subrec, p, buf+1, len > 1 ? len-1 : 0); break; default: DEBUG(0,("process_lanman_packet: On subnet %s ignoring browse packet \ @@ -1899,7 +1899,7 @@ BOOL send_mailslot(BOOL unique, const char *mailslot,char *buf, size_t len, SSVAL(ptr,smb_vwv16,2); p2 = smb_buf(ptr); safe_strcpy_base(p2, mailslot, dgram->data, sizeof(dgram->data)); - p2 = skip_string(p2,1); + p2 = skip_string(ptr,MAX_DGRAM_SIZE,p2,1); if (((p2+len) > dgram->data+sizeof(dgram->data)) || ((p2+len) < p2)) { DEBUG(0, ("send_mailslot: Cannot write beyond end of packet\n")); diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 232f430b66..6b10d61267 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -91,7 +91,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); pstrcpy(my_name, global_myname()); - code = SVAL(buf,0); + code = get_safe_offset(buf,len,buf,2) ? SVAL(buf,0) : -1; DEBUG(4,("process_logon_packet: Logon from %s: code = 0x%x\n", inet_ntoa(p->ip), code)); switch (code) { @@ -100,21 +100,21 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); fstring mach_str, user_str, getdc_str; char *q = buf + 2; char *machine = q; - char *user = skip_string(machine,1); + char *user = skip_string(buf,len,machine,1); - if (PTR_DIFF(user, buf) >= len) { + if (!user || PTR_DIFF(user, buf) >= len) { DEBUG(0,("process_logon_packet: bad packet\n")); return; } - getdc = skip_string(user,1); + getdc = skip_string(buf,len,user,1); - if (PTR_DIFF(getdc, buf) >= len) { + if (!getdc || PTR_DIFF(getdc, buf) >= len) { DEBUG(0,("process_logon_packet: bad packet\n")); return; } - q = skip_string(getdc,1); + q = skip_string(buf,len,getdc,1); - if (PTR_DIFF(q + 5, buf) > len) { + if (!q || PTR_DIFF(q + 5, buf) > len) { DEBUG(0,("process_logon_packet: bad packet\n")); return; } @@ -136,7 +136,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); fstrcpy(reply_name, "\\\\"); fstrcat(reply_name, my_name); push_ascii_fstring(q, reply_name); - q = skip_string(q, 1); /* PDC name */ + q = skip_string(outbuf,sizeof(outbuf),q, 1); /* PDC name */ SSVAL(q, 0, token); q += 2; @@ -164,15 +164,15 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); return; } - getdc = skip_string(machine,1); + getdc = skip_string(buf,len,machine,1); - if (PTR_DIFF(getdc, buf) >= len) { + if (!getdc || PTR_DIFF(getdc, buf) >= len) { DEBUG(0,("process_logon_packet: bad packet\n")); return; } - q = skip_string(getdc,1); + q = skip_string(buf,len,getdc,1); - if (PTR_DIFF(q, buf) >= len) { + if (!q || PTR_DIFF(q, buf) >= len) { DEBUG(0,("process_logon_packet: bad packet\n")); return; } @@ -232,7 +232,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); fstrcpy(reply_name,my_name); push_ascii_fstring(q, reply_name); - q = skip_string(q, 1); /* PDC name */ + q = skip_string(outbuf,sizeof(outbuf),q, 1); /* PDC name */ /* PDC and domain name */ if (!short_request) { @@ -301,9 +301,9 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", return; } - q = skip_string(getdc,1); + q = skip_string(buf,len,getdc,1); - if (PTR_DIFF(q + 8, buf) >= len) { + if (!q || PTR_DIFF(q + 8, buf) >= len) { DEBUG(0,("process_logon_packet: bad packet\n")); return; } @@ -540,16 +540,16 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", /* Domain info */ - q = skip_string(q, 1); /* PDC name */ + q = skip_string(buf,len,q, 1); /* PDC name */ - if (PTR_DIFF(q, buf) >= len) { + if (!q || PTR_DIFF(q, buf) >= len) { DEBUG(0,("process_logon_packet: bad packet\n")); return; } - q = skip_string(q, 1); /* Domain name */ + q = skip_string(buf,len,q, 1); /* Domain name */ - if (PTR_DIFF(q, buf) >= len) { + if (!q || PTR_DIFF(q, buf) >= len) { DEBUG(0,("process_logon_packet: bad packet\n")); return; } diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index 7fcedc557e..0cd481649d 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -566,7 +566,7 @@ for workgroup %s on subnet %s.\n", lp_workgroup(), FIRST_SUBNET->subnet_name )); myname[15]='\0'; push_pstring_base(p, myname, outbuf); - p = skip_string(p,1); + p = skip_string(outbuf,sizeof(outbuf),p,1); for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) { /* The entries are of the form a.b.c.d */ -- cgit From 01efa3d40392be1f17398f8b713f45f410e265e7 Mon Sep 17 00:00:00 2001 From: Herb Lewis Date: Sat, 31 Mar 2007 03:11:02 +0000 Subject: r22018: fix compile error (This used to be commit a4c1c770a227390f745c9db07efe468bdcd31339) --- source3/nmbd/nmbd_incomingdgrams.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 616b5df9db..ef23f3a20d 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -431,13 +431,13 @@ void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct fstring comment; char *s = get_safe_offset(buf,len,buf,9); + START_PROFILE(lm_host_announce); if (!s) { - return; + goto done; } - START_PROFILE(lm_host_announce); s = skip_string(buf,len,s,1); if (!s) { - return; + goto done; } pull_ascii(comment, s, sizeof(fstring), 43, STR_TERMINATE); -- cgit From e5358d6c55cc0aae64447d32611bea4c249f0788 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 2 Apr 2007 19:04:57 +0000 Subject: r22042: Try and clean up my own mess using the API Volker suggested. I now use : BOOL is_offset_safe(const char *buf_base, size_t buf_len, char *ptr, size_t off) char *get_safe_ptr(const char *buf_base, size_t buf_len, char *ptr, size_t off) char *get_safe_str_ptr(const char *buf_base, size_t buf_len, char *ptr, size_t off) int get_safe_SVAL(const char *buf_base, size_t buf_len, char *ptr, size_t off, int failval) int get_safe_IVAL(const char *buf_base, size_t buf_len, char *ptr, size_t off, int failval) Volker, please criticize and comment. Thanks, Jeremy. (This used to be commit d47af7c9263f519e7307859b6a696d854c5dfca3) --- source3/nmbd/nmbd_incomingdgrams.c | 2 +- source3/nmbd/nmbd_processlogon.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index ef23f3a20d..ec8aa370ce 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -429,7 +429,7 @@ void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct unstring work_name; unstring source_name; fstring comment; - char *s = get_safe_offset(buf,len,buf,9); + char *s = get_safe_str_ptr(buf,len,buf,9); START_PROFILE(lm_host_announce); if (!s) { diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 6b10d61267..b23e6b996e 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -91,7 +91,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); pstrcpy(my_name, global_myname()); - code = get_safe_offset(buf,len,buf,2) ? SVAL(buf,0) : -1; + code = get_safe_SVAL(buf,len,buf,0,-1); DEBUG(4,("process_logon_packet: Logon from %s: code = 0x%x\n", inet_ntoa(p->ip), code)); switch (code) { -- cgit From 0a2cc569a1803f459f7db77d03e6e90ae30aa35d Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 2 Apr 2007 20:10:21 +0000 Subject: r22045: As Volker noticed, skip_string's last argument is redundent. Remove it. Jeremy. (This used to be commit 140881cfbb59ce4a699b5900efe02bf315be7bd5) --- source3/nmbd/nmbd_browsesync.c | 2 +- source3/nmbd/nmbd_elections.c | 2 +- source3/nmbd/nmbd_incomingdgrams.c | 6 +++--- source3/nmbd/nmbd_packets.c | 2 +- source3/nmbd/nmbd_processlogon.c | 20 ++++++++++---------- source3/nmbd/nmbd_sendannounce.c | 2 +- 6 files changed, 17 insertions(+), 17 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index ddb223de9f..54d02aac35 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -125,7 +125,7 @@ static void announce_local_master_browser_to_domain_master_browser( struct work_ /* The call below does CH_UNIX -> CH_DOS conversion. JRA */ push_pstring_base(p, myname, outbuf); - p = skip_string(outbuf,sizeof(outbuf),p,1); + p = skip_string(outbuf,sizeof(outbuf),p); if( DEBUGLVL( 4 ) ) { dbgtext( "announce_local_master_browser_to_domain_master_browser:\n" ); diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index fbdb6c4524..eb6f1b6e0a 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -53,7 +53,7 @@ static void send_election_dgram(struct subnet_record *subrec, const char *workgr strupper_m(srv_name); /* The following call does UNIX -> DOS charset conversion. */ pstrcpy_base(p, srv_name, outbuf); - p = skip_string(outbuf,sizeof(outbuf),p,1); + p = skip_string(outbuf,sizeof(outbuf),p); send_mailslot(False, BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), global_myname(), 0, diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index ec8aa370ce..4f3b3d3a7b 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -435,7 +435,7 @@ void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct if (!s) { goto done; } - s = skip_string(buf,len,s,1); + s = skip_string(buf,len,s); if (!s) { goto done; } @@ -574,7 +574,7 @@ static void send_backup_list_response(struct subnet_record *subrec, myname[15]='\0'; push_pstring_base(p, myname, outbuf); - p = skip_string(outbuf,sizeof(outbuf),p,1); + p = skip_string(outbuf,sizeof(outbuf),p); /* Look for backup browsers in this workgroup. */ @@ -610,7 +610,7 @@ static void send_backup_list_response(struct subnet_record *subrec, DEBUG(5,("send_backup_list_response: Adding server %s number %d\n", p, count)); - p = skip_string(outbuf,sizeof(outbuf),p,1); + p = skip_string(outbuf,sizeof(outbuf),p); } #endif diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 5ec6be1307..87a38b9d2a 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1899,7 +1899,7 @@ BOOL send_mailslot(BOOL unique, const char *mailslot,char *buf, size_t len, SSVAL(ptr,smb_vwv16,2); p2 = smb_buf(ptr); safe_strcpy_base(p2, mailslot, dgram->data, sizeof(dgram->data)); - p2 = skip_string(ptr,MAX_DGRAM_SIZE,p2,1); + p2 = skip_string(ptr,MAX_DGRAM_SIZE,p2); if (((p2+len) > dgram->data+sizeof(dgram->data)) || ((p2+len) < p2)) { DEBUG(0, ("send_mailslot: Cannot write beyond end of packet\n")); diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index b23e6b996e..ee7d732ae4 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -100,19 +100,19 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); fstring mach_str, user_str, getdc_str; char *q = buf + 2; char *machine = q; - char *user = skip_string(buf,len,machine,1); + char *user = skip_string(buf,len,machine); if (!user || PTR_DIFF(user, buf) >= len) { DEBUG(0,("process_logon_packet: bad packet\n")); return; } - getdc = skip_string(buf,len,user,1); + getdc = skip_string(buf,len,user); if (!getdc || PTR_DIFF(getdc, buf) >= len) { DEBUG(0,("process_logon_packet: bad packet\n")); return; } - q = skip_string(buf,len,getdc,1); + q = skip_string(buf,len,getdc); if (!q || PTR_DIFF(q + 5, buf) > len) { DEBUG(0,("process_logon_packet: bad packet\n")); @@ -136,7 +136,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); fstrcpy(reply_name, "\\\\"); fstrcat(reply_name, my_name); push_ascii_fstring(q, reply_name); - q = skip_string(outbuf,sizeof(outbuf),q, 1); /* PDC name */ + q = skip_string(outbuf,sizeof(outbuf),q); /* PDC name */ SSVAL(q, 0, token); q += 2; @@ -164,13 +164,13 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); return; } - getdc = skip_string(buf,len,machine,1); + getdc = skip_string(buf,len,machine); if (!getdc || PTR_DIFF(getdc, buf) >= len) { DEBUG(0,("process_logon_packet: bad packet\n")); return; } - q = skip_string(buf,len,getdc,1); + q = skip_string(buf,len,getdc); if (!q || PTR_DIFF(q, buf) >= len) { DEBUG(0,("process_logon_packet: bad packet\n")); @@ -232,7 +232,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); fstrcpy(reply_name,my_name); push_ascii_fstring(q, reply_name); - q = skip_string(outbuf,sizeof(outbuf),q, 1); /* PDC name */ + q = skip_string(outbuf,sizeof(outbuf),q); /* PDC name */ /* PDC and domain name */ if (!short_request) { @@ -301,7 +301,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", return; } - q = skip_string(buf,len,getdc,1); + q = skip_string(buf,len,getdc); if (!q || PTR_DIFF(q + 8, buf) >= len) { DEBUG(0,("process_logon_packet: bad packet\n")); @@ -540,14 +540,14 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", /* Domain info */ - q = skip_string(buf,len,q, 1); /* PDC name */ + q = skip_string(buf,len,q); /* PDC name */ if (!q || PTR_DIFF(q, buf) >= len) { DEBUG(0,("process_logon_packet: bad packet\n")); return; } - q = skip_string(buf,len,q, 1); /* Domain name */ + q = skip_string(buf,len,q); /* Domain name */ if (!q || PTR_DIFF(q, buf) >= len) { DEBUG(0,("process_logon_packet: bad packet\n")); diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index 0cd481649d..e2dc130463 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -566,7 +566,7 @@ for workgroup %s on subnet %s.\n", lp_workgroup(), FIRST_SUBNET->subnet_name )); myname[15]='\0'; push_pstring_base(p, myname, outbuf); - p = skip_string(outbuf,sizeof(outbuf),p,1); + p = skip_string(outbuf,sizeof(outbuf),p); for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) { /* The entries are of the form a.b.c.d */ -- cgit From d1ec6909727698f94c3c0228797a1d070dc17fa1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 10 Apr 2007 20:35:30 +0000 Subject: r22157: Fix bug #3634 - stop nmbd segfaulting with bad interface line. Jeremy. (This used to be commit c3e2207cb40386c565b23fcabc8c7384b10216de) --- source3/nmbd/nmbd_subnetdb.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 04df3e9a4f..4b04751235 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -223,6 +223,13 @@ BOOL create_subnets(void) return False; } + /* We must have at least one subnet. */ + if (subnetlist == NULL) { + DEBUG(0,("create_subnets: unable to create any subnet from " + "given interfaces. nmbd is terminating\n")); + return False; + } + if (lp_we_are_a_wins_server()) { /* Pick the first interface ip address as the WINS server ip. */ struct in_addr *nip = iface_n_ip(0); -- cgit From 0829e1ad1c3646efecf50729f493b9ee72ef0517 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 19 Apr 2007 22:40:32 +0000 Subject: r22391: Looks bigger than it is. Make "inbuf" available to all callers of smb_setlen (via set_message() calls). This will allow the server to reflect back the correct encryption context. Jeremy. (This used to be commit 2d80a96120a5fe2fe726f00746d36d85044c4bdb) --- source3/nmbd/nmbd_packets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 87a38b9d2a..d34beb7ff6 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1886,7 +1886,7 @@ BOOL send_mailslot(BOOL unique, const char *mailslot,char *buf, size_t len, /* Setup the smb part. */ ptr -= 4; /* XXX Ugliness because of handling of tcp SMB length. */ memcpy(tmp,ptr,4); - set_message(ptr,17,strlen(mailslot) + 1 + len,True); + set_message(NULL,ptr,17,strlen(mailslot) + 1 + len,True); memcpy(ptr,tmp,4); SCVAL(ptr,smb_com,SMBtrans); -- cgit From 8a22b1f0ea81f06616a2dc41a138c5126359f009 Mon Sep 17 00:00:00 2001 From: James Peach Date: Fri, 20 Apr 2007 18:34:33 +0000 Subject: r22417: Refactor the various daemon run-mode options to make the semantics of the various flags explicit. (This used to be commit 19c929c6330a50f278ac322ac5fcb83d03734ea2) --- source3/nmbd/nmbd.c | 61 +++++++++++++++++++++++---------------------- source3/nmbd/nmbd_lmhosts.c | 2 +- 2 files changed, 32 insertions(+), 31 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 46f209872b..3a18e66774 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -33,15 +33,6 @@ extern BOOL global_in_nmbd; extern BOOL override_logfile; -/* are we running as a daemon ? */ -static BOOL is_daemon; - -/* fork or run in foreground ? */ -static BOOL Fork = True; - -/* log to standard output ? */ -static BOOL log_stdout; - /* have we found LanMan clients yet? */ BOOL found_lm_clients = False; @@ -578,7 +569,7 @@ static void process(void) Open the socket communication. **************************************************************************** */ -static BOOL open_sockets(BOOL isdaemon, int port) +static BOOL open_sockets(enum smb_server_mode server_mode, int port) { /* * The sockets opened here will be used to receive broadcast @@ -588,12 +579,13 @@ static BOOL open_sockets(BOOL isdaemon, int port) * now deprecated. */ - if ( isdaemon ) + if ( server_mode == SERVER_MODE_INETD ) { + ClientNMB = 0; + } else { ClientNMB = open_socket_in(SOCK_DGRAM, port, 0, interpret_addr(lp_socket_address()), True); - else - ClientNMB = 0; + } ClientDGRAM = open_socket_in(SOCK_DGRAM, DGRAM_PORT, 3, interpret_addr(lp_socket_address()), @@ -622,15 +614,20 @@ static BOOL open_sockets(BOOL isdaemon, int port) int main(int argc, const char *argv[]) { pstring logfile; - static BOOL opt_interactive; poptContext pc; - static char *p_lmhosts = dyn_LMHOSTSFILE; - static BOOL no_process_group = False; + const char *p_lmhosts = dyn_LMHOSTSFILE; + BOOL no_process_group = False; + BOOL log_stdout = False; + enum smb_server_mode server_mode = SERVER_MODE_DAEMON; + struct poptOption long_options[] = { POPT_AUTOHELP - {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon(default)" }, - {"interactive", 'i', POPT_ARG_VAL, &opt_interactive, True, "Run interactive (not a daemon)" }, - {"foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools & etc)" }, + {"daemon", 'D', POPT_ARG_VAL, &server_mode, SERVER_MODE_DAEMON, + "Become a daemon(default)" }, + {"interactive", 'i', POPT_ARG_VAL, &server_mode, + SERVER_MODE_INTERACTIVE, "Run interactive (not a daemon)" }, + {"foreground", 'F', POPT_ARG_VAL, &server_mode, + SERVER_MODE_FOREGROUND, "Run daemon in foreground (for daemontools & etc)" }, {"no-process-group", 0, POPT_ARG_VAL, &no_process_group, True, "Don't create a new process group" }, {"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" }, {"hosts", 'H', POPT_ARG_STRING, &p_lmhosts, 'H', "Load a netbios hosts file"}, @@ -680,12 +677,11 @@ static BOOL open_sockets(BOOL isdaemon, int port) BlockSignals(True, SIGUSR2); #endif - if ( opt_interactive ) { - Fork = False; + if (server_mode == SERVER_MODE_INTERACTIVE) { log_stdout = True; } - if ( log_stdout && Fork ) { + if (log_stdout && server_mode == SERVER_MODE_DAEMON) { DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n")); exit(1); } @@ -712,14 +708,19 @@ static BOOL open_sockets(BOOL isdaemon, int port) set_samba_nb_type(); - if (!is_daemon && !is_a_socket(0)) { - DEBUG(0,("standard input is not a socket, assuming -D option\n")); - is_daemon = True; + if (is_a_socket(0)) { + if (server_mode == SERVER_MODE_DAEMON) { + DEBUG(0,("standard input is a socket, " + "assuming -F option\n")); + } + server_mode = SERVER_MODE_INETD; } - - if (is_daemon && !opt_interactive) { + + if (server_mode == SERVER_MODE_DAEMON) { DEBUG( 2, ( "Becoming a daemon.\n" ) ); - become_daemon(Fork, no_process_group); + become_daemon(True, no_process_group); + } else if (server_mode == SERVER_MODE_FOREGROUND) { + become_daemon(False, no_process_group); } #if HAVE_SETPGID @@ -727,7 +728,7 @@ static BOOL open_sockets(BOOL isdaemon, int port) * If we're interactive we want to set our own process group for * signal management. */ - if (opt_interactive && !no_process_group) + if (server_mode == SERVER_MODE_INTERACTIVE && !no_process_group) setpgid( (pid_t)0, (pid_t)0 ); #endif @@ -758,7 +759,7 @@ static BOOL open_sockets(BOOL isdaemon, int port) DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); - if ( !open_sockets( is_daemon, global_nmb_port ) ) { + if ( !open_sockets( server_mode, global_nmb_port ) ) { kill_async_dns_child(); return 1; } diff --git a/source3/nmbd/nmbd_lmhosts.c b/source3/nmbd/nmbd_lmhosts.c index b14e13f3a4..be3ddfe637 100644 --- a/source3/nmbd/nmbd_lmhosts.c +++ b/source3/nmbd/nmbd_lmhosts.c @@ -29,7 +29,7 @@ Load a lmhosts file. ****************************************************************************/ -void load_lmhosts_file(char *fname) +void load_lmhosts_file(const char *fname) { pstring name; int name_type; -- cgit From e6383f47629368d9dd4e803f17566a24e9d7359e Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 7 May 2007 09:35:35 +0000 Subject: r22736: Start to merge the low-hanging fruit from the now 7000-line cluster patch. This changes "struct process_id" to "struct server_id", keeping both is just too much hassle. No functional change (I hope ;-)) Volker (This used to be commit 0ad4b1226c9d91b72136310d3bbb640d2c5d67b8) --- source3/nmbd/nmbd.c | 6 +++--- source3/nmbd/nmbd_elections.c | 2 +- source3/nmbd/nmbd_winsserver.c | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 3a18e66774..6e0de362b9 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -67,7 +67,7 @@ static void terminate(void) Handle a SHUTDOWN message from smbcontrol. **************************************************************************** */ -static void nmbd_terminate(int msg_type, struct process_id src, +static void nmbd_terminate(int msg_type, struct server_id src, void *buf, size_t len, void *private_data) { terminate(); @@ -262,7 +262,7 @@ static BOOL reload_nmbd_services(BOOL test) * detects that there are no subnets. **************************************************************************** */ -static void msg_reload_nmbd_services(int msg_type, struct process_id src, +static void msg_reload_nmbd_services(int msg_type, struct server_id src, void *buf, size_t len, void *private_data) { write_browse_list( 0, True ); @@ -279,7 +279,7 @@ static void msg_reload_nmbd_services(int msg_type, struct process_id src, } } -static void msg_nmbd_send_packet(int msg_type, struct process_id src, +static void msg_nmbd_send_packet(int msg_type, struct server_id src, void *buf, size_t len, void *private_data) { struct packet_struct *p = (struct packet_struct *)buf; diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index eb6f1b6e0a..a053d0803b 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -378,7 +378,7 @@ yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name )); Process a internal Samba message forcing an election. ***************************************************************************/ -void nmbd_message_election(int msg_type, struct process_id src, +void nmbd_message_election(int msg_type, struct server_id src, void *buf, size_t len, void *private_data) { struct subnet_record *subrec; diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 9c2fe72702..fc9b95491c 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -2370,7 +2370,7 @@ void wins_write_database(time_t t, BOOL background) Process a internal Samba message receiving a wins record. ***************************************************************************/ -void nmbd_wins_new_entry(int msg_type, struct process_id src, +void nmbd_wins_new_entry(int msg_type, struct server_id src, void *buf, size_t len, void *private_data) { WINS_RECORD *record; -- cgit From 4aa44f7475e03dcc596f6a13fffffda7268074a1 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 8 May 2007 13:44:36 +0000 Subject: r22761: This introduces lib/conn_tdb.c with two main functions: connections_traverse and connections_forall. This centralizes all the routines that did individual tdb_open("connections.tdb") and direct tdb_traverse. Volker (This used to be commit e43e94cda1ad8876b3cb5d1129080b57fa6ec214) --- source3/nmbd/nmbd_processlogon.c | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index ee7d732ae4..15be7f59c0 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -38,24 +38,10 @@ Send a message to smbd to do a sam delta sync static void send_repl_message(uint32 low_serial) { - TDB_CONTEXT *tdb; - - tdb = tdb_open_log(lock_path("connections.tdb"), 0, - TDB_DEFAULT, O_RDONLY, 0); - - if (!tdb) { - DEBUG(3, ("send_repl_message(): failed to open connections " - "database\n")); - return; - } - DEBUG(3, ("sending replication message, serial = 0x%04x\n", low_serial)); - - message_send_all(tdb, MSG_SMB_SAM_REPL, &low_serial, + message_send_all(MSG_SMB_SAM_REPL, &low_serial, sizeof(low_serial), False, NULL); - - tdb_close(tdb); } /**************************************************************************** -- cgit From ab7a9d2bbe95ac2194db7eb358e3bf1ba4aa8890 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 15 May 2007 13:44:11 +0000 Subject: r22902: Add an event_context and a messaging_context to nmbd. Not used yet. (This used to be commit 6d210fb8a13e93fe5b7bc160a343f74878dea727) --- source3/nmbd/nmbd.c | 27 ++++++++++++++++++++++++++- source3/nmbd/nmbd_packets.c | 33 ++++++++++++++++++++++++++------- 2 files changed, 52 insertions(+), 8 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 6e0de362b9..f328673a55 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -40,6 +40,27 @@ BOOL found_lm_clients = False; time_t StartupTime = 0; +struct event_context *nmbd_event_context(void) +{ + static struct event_context *ctx; + + if (!ctx && !(ctx = event_context_init(NULL))) { + smb_panic("Could not init nmbd event context\n"); + } + return ctx; +} + +struct messaging_context *nmbd_messaging_context(void) +{ + static struct messaging_context *ctx; + + if (!ctx && !(ctx = messaging_init(NULL, server_id_self(), + nmbd_event_context()))) { + smb_panic("Could not init nmbd messaging context\n"); + } + return ctx; +} + /**************************************************************************** ** Handle a SIGTERM in band. **************************************************************************** */ @@ -732,6 +753,11 @@ static BOOL open_sockets(enum smb_server_mode server_mode, int port) setpgid( (pid_t)0, (pid_t)0 ); #endif + message_init(); + if (nmbd_messaging_context() == NULL) { + return 1; + } + #ifndef SYNC_DNS /* Setup the async dns. We do it here so it doesn't have all the other stuff initialised and thus chewing memory and sockets */ @@ -745,7 +771,6 @@ static BOOL open_sockets(enum smb_server_mode server_mode, int port) } pidfile_create("nmbd"); - message_init(); message_register(MSG_FORCE_ELECTION, nmbd_message_election, NULL); #if 0 /* Until winsrepl is done. */ diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index d34beb7ff6..2fbf2f4146 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1730,7 +1730,8 @@ BOOL listen_for_packets(BOOL run_election) int i; static int maxfd = 0; - fd_set fds; + fd_set r_fds; + fd_set w_fds; int selrtn; struct timeval timeout; #ifndef SYNC_DNS @@ -1745,12 +1746,13 @@ BOOL listen_for_packets(BOOL run_election) rescan_listen_set = False; } - memcpy((char *)&fds, (char *)listen_set, sizeof(fd_set)); + memcpy((char *)&r_fds, (char *)listen_set, sizeof(fd_set)); + FD_ZERO(&w_fds); #ifndef SYNC_DNS dns_fd = asyncdns_fd(); if (dns_fd != -1) { - FD_SET(dns_fd, &fds); + FD_SET(dns_fd, &r_fds); maxfd = MAX( maxfd, dns_fd); } #endif @@ -1765,11 +1767,24 @@ BOOL listen_for_packets(BOOL run_election) timeout.tv_sec = (run_election||num_response_packets) ? 1 : NMBD_SELECT_LOOP; timeout.tv_usec = 0; + { + struct timeval now = timeval_current(); + event_add_to_select_args(nmbd_event_context(), &now, + &r_fds, &w_fds, &timeout, &maxfd); + } + + if (timeval_is_zero(&timeout)) { + /* Process a timed event now... */ + if (run_events(nmbd_event_context(), 0, NULL, NULL)) { + return False; + } + } + /* Prepare for the select - allow certain signals. */ BlockSignals(False, SIGTERM); - selrtn = sys_select(maxfd+1,&fds,NULL,NULL,&timeout); + selrtn = sys_select(maxfd+1,&r_fds,&w_fds,NULL,&timeout); /* We can only take signals when we are in the select - block them again here. */ @@ -1779,8 +1794,12 @@ BOOL listen_for_packets(BOOL run_election) return False; } + if (run_events(nmbd_event_context(), selrtn, &r_fds, &w_fds)) { + return False; + } + #ifndef SYNC_DNS - if (dns_fd != -1 && FD_ISSET(dns_fd,&fds)) { + if (dns_fd != -1 && FD_ISSET(dns_fd,&r_fds)) { run_dns_queue(); } #endif @@ -1788,7 +1807,7 @@ BOOL listen_for_packets(BOOL run_election) for(i = 0; i < listen_number; i++) { if (i < (listen_number/2)) { /* Processing a 137 socket. */ - if (FD_ISSET(sock_array[i],&fds)) { + if (FD_ISSET(sock_array[i],&r_fds)) { struct packet_struct *packet = read_packet(sock_array[i], NMB_PACKET); if (packet) { /* @@ -1815,7 +1834,7 @@ BOOL listen_for_packets(BOOL run_election) } } else { /* Processing a 138 socket. */ - if (FD_ISSET(sock_array[i],&fds)) { + if (FD_ISSET(sock_array[i],&r_fds)) { struct packet_struct *packet = read_packet(sock_array[i], DGRAM_PACKET); if (packet) { /* -- cgit From 84758bd1f8633d3efe30e293887596db6bfd5e5b Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 15 May 2007 15:14:32 +0000 Subject: r22908: All callers of message_init now also call messaging_init. Unify those. (This used to be commit 330946ad2307ca34f0a8d068a0193fcb8a0d6036) --- source3/nmbd/nmbd.c | 1 - 1 file changed, 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index f328673a55..ba05316d71 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -753,7 +753,6 @@ static BOOL open_sockets(enum smb_server_mode server_mode, int port) setpgid( (pid_t)0, (pid_t)0 ); #endif - message_init(); if (nmbd_messaging_context() == NULL) { return 1; } -- cgit From 8c3f8e5697f29f1a9829298e0561ff7305b62082 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Tue, 15 May 2007 15:49:55 +0000 Subject: r22911: Pass a messaging_context to message_send_all (This used to be commit cc92ce665dcfe9054d09429219883b18a4cab090) --- source3/nmbd/nmbd_processlogon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 15be7f59c0..0d869f1586 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -40,8 +40,8 @@ static void send_repl_message(uint32 low_serial) { DEBUG(3, ("sending replication message, serial = 0x%04x\n", low_serial)); - message_send_all(MSG_SMB_SAM_REPL, &low_serial, - sizeof(low_serial), False, NULL); + message_send_all(nmbd_messaging_context(), MSG_SMB_SAM_REPL, + &low_serial, sizeof(low_serial), False, NULL); } /**************************************************************************** -- cgit From 4d5f58c2b945e7a2263ba42749f73c7ba72ab3c7 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 19 May 2007 21:53:28 +0000 Subject: r23015: Make message_(de)register static to messages.c (This used to be commit a8082a3c7c3d1e68c27fc3bf42f3d44402cc6f9f) --- source3/nmbd/nmbd.c | 52 ++++++++++++++++++++++++++++-------------- source3/nmbd/nmbd_elections.c | 7 ++++-- source3/nmbd/nmbd_winsserver.c | 7 ++++-- 3 files changed, 45 insertions(+), 21 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index ba05316d71..405aed3428 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -88,8 +88,11 @@ static void terminate(void) Handle a SHUTDOWN message from smbcontrol. **************************************************************************** */ -static void nmbd_terminate(int msg_type, struct server_id src, - void *buf, size_t len, void *private_data) +static void nmbd_terminate(struct messaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id server_id, + DATA_BLOB *data) { terminate(); } @@ -283,33 +286,39 @@ static BOOL reload_nmbd_services(BOOL test) * detects that there are no subnets. **************************************************************************** */ -static void msg_reload_nmbd_services(int msg_type, struct server_id src, - void *buf, size_t len, void *private_data) +static void msg_reload_nmbd_services(struct messaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id server_id, + DATA_BLOB *data) { write_browse_list( 0, True ); dump_all_namelists(); reload_nmbd_services( True ); reopen_logs(); - if(buf) { + if (data->data) { /* We were called from process() */ /* If reload_interfaces() returned True */ /* we need to shutdown if there are no subnets... */ /* pass this info back to process() */ - *((BOOL*)buf) = reload_interfaces(0); + *((BOOL*)data->data) = reload_interfaces(0); } } -static void msg_nmbd_send_packet(int msg_type, struct server_id src, - void *buf, size_t len, void *private_data) +static void msg_nmbd_send_packet(struct messaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id src, + DATA_BLOB *data) { - struct packet_struct *p = (struct packet_struct *)buf; + struct packet_struct *p = (struct packet_struct *)data->data; struct subnet_record *subrec; struct in_addr *local_ip; DEBUG(10, ("Received send_packet from %d\n", procid_to_pid(&src))); - if (len != sizeof(struct packet_struct)) { + if (data->length != sizeof(struct packet_struct)) { DEBUG(2, ("Discarding invalid packet length from %d\n", procid_to_pid(&src))); return; @@ -568,9 +577,13 @@ static void process(void) */ if(reload_after_sighup) { + DATA_BLOB blob = data_blob_const(&no_subnets, + sizeof(no_subnets)); DEBUG( 0, ( "Got SIGHUP dumping debug info.\n" ) ); - msg_reload_nmbd_services(MSG_SMB_CONF_UPDATED, - pid_to_procid(0), (void*) &no_subnets, 0, NULL); + msg_reload_nmbd_services(nmbd_messaging_context(), + NULL, MSG_SMB_CONF_UPDATED, + procid_self(), &blob); + if(no_subnets) return; reload_after_sighup = 0; @@ -770,14 +783,19 @@ static BOOL open_sockets(enum smb_server_mode server_mode, int port) } pidfile_create("nmbd"); - message_register(MSG_FORCE_ELECTION, nmbd_message_election, NULL); + messaging_register(nmbd_messaging_context(), NULL, + MSG_FORCE_ELECTION, nmbd_message_election); #if 0 /* Until winsrepl is done. */ - message_register(MSG_WINS_NEW_ENTRY, nmbd_wins_new_entry, NULL); + messaging_register(nmbd_messaging_context(), NULL, + MSG_WINS_NEW_ENTRY, nmbd_wins_new_entry); #endif - message_register(MSG_SHUTDOWN, nmbd_terminate, NULL); - message_register(MSG_SMB_CONF_UPDATED, msg_reload_nmbd_services, NULL); - message_register(MSG_SEND_PACKET, msg_nmbd_send_packet, NULL); + messaging_register(nmbd_messaging_context(), NULL, + MSG_SHUTDOWN, nmbd_terminate); + messaging_register(nmbd_messaging_context(), NULL, + MSG_SMB_CONF_UPDATED, msg_reload_nmbd_services); + messaging_register(nmbd_messaging_context(), NULL, + MSG_SEND_PACKET, msg_nmbd_send_packet); TimeInit(); diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index a053d0803b..bd4308674c 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -378,8 +378,11 @@ yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name )); Process a internal Samba message forcing an election. ***************************************************************************/ -void nmbd_message_election(int msg_type, struct server_id src, - void *buf, size_t len, void *private_data) +void nmbd_message_election(struct messaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id server_id, + DATA_BLOB *data) { struct subnet_record *subrec; diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index fc9b95491c..0f27351d2d 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -2370,8 +2370,11 @@ void wins_write_database(time_t t, BOOL background) Process a internal Samba message receiving a wins record. ***************************************************************************/ -void nmbd_wins_new_entry(int msg_type, struct server_id src, - void *buf, size_t len, void *private_data) +void nmbd_wins_new_entry(struct messaging_context *msg, + void *private_data, + uint32_t msg_type, + struct server_id server_id, + DATA_BLOB *data) { WINS_RECORD *record; struct name_record *namerec = NULL; -- cgit From ac3f08ddbe0b484375624db0e35999a8584b57f4 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Mon, 21 May 2007 22:17:13 +0000 Subject: r23055: Rewrite messages.c to use auto-generated marshalling in the tdb. I'm doing this because for the clustering the marshalling is needed in more than one place, so I wanted a decent routine to marshall a message_rec struct which was not there before. Tridge, this seems about the same speed as it used to be before, the librpc/ndr overhead in my tests was under the noise. Volker (This used to be commit eaefd00563173dfabb7716c5695ac0a2f7139bb6) --- source3/nmbd/nmbd.c | 2 +- source3/nmbd/nmbd_processlogon.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 405aed3428..8c94ad842b 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -376,7 +376,7 @@ static void process(void) /* Check for internal messages */ - message_dispatch(); + message_dispatch(nmbd_messaging_context()); /* * Check all broadcast subnets to see if diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 0d869f1586..287f3e8897 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -41,7 +41,7 @@ static void send_repl_message(uint32 low_serial) DEBUG(3, ("sending replication message, serial = 0x%04x\n", low_serial)); message_send_all(nmbd_messaging_context(), MSG_SMB_SAM_REPL, - &low_serial, sizeof(low_serial), False, NULL); + &low_serial, sizeof(low_serial), NULL); } /**************************************************************************** -- cgit From 0ff54fb41db4841fa72ac74361e9dd602a47418f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 5 Jun 2007 01:59:37 +0000 Subject: r23349: Fix from Steve Langasek to allow SIGTERM to cause nmbd to exit on awaiting an interface to come up. Debian bug #168079 Jeremy. (This used to be commit 9ee310f3d68426da552f084ebcffef6b8ebbf612) --- source3/nmbd/nmbd_subnetdb.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 4b04751235..398119cc82 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -185,12 +185,28 @@ BOOL create_subnets(void) struct in_addr unicast_ip, ipzero; if(num_interfaces == 0) { + void (*saved_handler)(int); + DEBUG(0,("create_subnets: No local interfaces !\n")); DEBUG(0,("create_subnets: Waiting for an interface to appear ...\n")); + + /* + * Whilst we're waiting for an interface, allow SIGTERM to + * cause us to exit. + */ + + saved_handler = CatchSignal( SIGTERM, SIGNAL_CAST SIG_DFL ); + while (iface_count() == 0) { sleep(5); load_interfaces(); } + + /* + * We got an interface, restore our normal term handler. + */ + + CatchSignal( SIGTERM, SIGNAL_CAST saved_handler ); } num_interfaces = iface_count(); -- cgit From 9ae6e51616cb37f4de0e45645fda8315278149be Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 12 Jun 2007 01:45:40 +0000 Subject: r23425: Volker noticed this obvious fix for the wins server code :-). Thanks Volker ! Jeremy. (This used to be commit e3f33a2a503ada232aa1165e2321822584a026bd) --- source3/nmbd/nmbd_winsserver.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 0f27351d2d..4338aeac93 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -2140,7 +2140,7 @@ static int wins_processing_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA /* handle records, samba is the wins owner */ if (ip_equal(namerec->data.wins_ip, our_fake_ip)) { - switch (namerec->data.wins_flags | WINS_STATE_MASK) { + switch (namerec->data.wins_flags & WINS_STATE_MASK) { case WINS_ACTIVE: namerec->data.wins_flags&=~WINS_STATE_MASK; namerec->data.wins_flags|=WINS_RELEASED; @@ -2165,7 +2165,7 @@ static int wins_processing_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA goto done; } } else { - switch (namerec->data.wins_flags | WINS_STATE_MASK) { + switch (namerec->data.wins_flags & WINS_STATE_MASK) { case WINS_ACTIVE: /* that's not as MS says it should be */ namerec->data.wins_flags&=~WINS_STATE_MASK; -- cgit From b1ce226af8b61ad7e3c37860a59c6715012e738b Mon Sep 17 00:00:00 2001 From: James Peach Date: Fri, 15 Jun 2007 21:58:49 +0000 Subject: r23510: Tidy calls to smb_panic by removing trailing newlines. Print the failed expression in SMB_ASSERT. (This used to be commit 171dc060e2a576d724eed1ca65636bdafffd7713) --- source3/nmbd/nmbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 8c94ad842b..d367dc70fb 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -45,7 +45,7 @@ struct event_context *nmbd_event_context(void) static struct event_context *ctx; if (!ctx && !(ctx = event_context_init(NULL))) { - smb_panic("Could not init nmbd event context\n"); + smb_panic("Could not init nmbd event context"); } return ctx; } @@ -56,7 +56,7 @@ struct messaging_context *nmbd_messaging_context(void) if (!ctx && !(ctx = messaging_init(NULL, server_id_self(), nmbd_event_context()))) { - smb_panic("Could not init nmbd messaging context\n"); + smb_panic("Could not init nmbd messaging context"); } return ctx; } -- cgit From ce02d0dfcbeeeec316578322257d998589090c6f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 20 Jun 2007 17:38:42 +0000 Subject: r23554: Fix bug #4711 by makeing cli_connect return an NTSTATUS. Long overdue fix.... Jeremy. (This used to be commit 073fdc5a58139796dbaa7ea9833dca5308f11282) --- source3/nmbd/nmbd_synclists.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 7fe39676c6..fa1a41a5af 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -71,6 +71,7 @@ static void sync_child(char *name, int nm_type, struct cli_state *cli; uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0; struct nmb_name called, calling; + NTSTATUS status; /* W2K DMB's return empty browse lists on port 445. Use 139. * Patch from Andy Levine andyl@epicrealm.com. @@ -81,7 +82,12 @@ static void sync_child(char *name, int nm_type, return; } - if (!cli_set_port(cli, 139) || !cli_connect(cli, name, &ip)) { + if (!cli_set_port(cli, 139)) { + return; + } + + status = cli_connect(cli, name, &ip); + if (!NT_STATUS_IS_OK(status)) { return; } -- cgit From 1deb049a020cb2e804fc74e9b06f5c04f73005e8 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 20 Jun 2007 23:24:18 +0000 Subject: r23556: Fix for error path from Atsushi Nakabayashi . Jeremy. (This used to be commit 3f70c1b10589965ee95ef7497ff6fb7c39475569) --- source3/nmbd/nmbd_winsserver.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 4338aeac93..bbaca83e21 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -2333,6 +2333,7 @@ void wins_write_database(time_t t, BOOL background) if (tdb_reopen(wins_tdb)) { DEBUG(0,("wins_write_database: tdb_reopen failed. Error was %s\n", strerror(errno))); + _exit(0); return; } } -- cgit From d824b98f80ba186030cbb70b3a1e5daf80469ecd Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 9 Jul 2007 19:25:36 +0000 Subject: r23779: Change from v2 or later to v3 or later. Jeremy. (This used to be commit 407e6e695b8366369b7c76af1ff76869b45347b3) --- source3/nmbd/asyncdns.c | 2 +- source3/nmbd/nmbd.c | 2 +- source3/nmbd/nmbd_become_dmb.c | 2 +- source3/nmbd/nmbd_become_lmb.c | 2 +- source3/nmbd/nmbd_browserdb.c | 2 +- source3/nmbd/nmbd_browsesync.c | 2 +- source3/nmbd/nmbd_elections.c | 2 +- source3/nmbd/nmbd_incomingdgrams.c | 2 +- source3/nmbd/nmbd_incomingrequests.c | 2 +- source3/nmbd/nmbd_lmhosts.c | 2 +- source3/nmbd/nmbd_logonnames.c | 2 +- source3/nmbd/nmbd_mynames.c | 2 +- source3/nmbd/nmbd_namelistdb.c | 2 +- source3/nmbd/nmbd_namequery.c | 2 +- source3/nmbd/nmbd_nameregister.c | 2 +- source3/nmbd/nmbd_namerelease.c | 2 +- source3/nmbd/nmbd_nodestatus.c | 2 +- source3/nmbd/nmbd_packets.c | 2 +- source3/nmbd/nmbd_processlogon.c | 2 +- source3/nmbd/nmbd_responserecordsdb.c | 2 +- source3/nmbd/nmbd_sendannounce.c | 2 +- source3/nmbd/nmbd_serverlistdb.c | 2 +- source3/nmbd/nmbd_subnetdb.c | 2 +- source3/nmbd/nmbd_synclists.c | 2 +- source3/nmbd/nmbd_winsproxy.c | 2 +- source3/nmbd/nmbd_winsserver.c | 2 +- source3/nmbd/nmbd_workgroupdb.c | 2 +- 27 files changed, 27 insertions(+), 27 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 0c7a1e50b7..25bbcabe5c 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -5,7 +5,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index d367dc70fb..e62f4250de 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index 523ec6cabf..08765038fa 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index b928a8a7c5..34c6271e9f 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c index b75028be0d..3b8ad8b3a7 100644 --- a/source3/nmbd/nmbd_browserdb.c +++ b/source3/nmbd/nmbd_browserdb.c @@ -8,7 +8,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 54d02aac35..b261907b92 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index bd4308674c..8d6a65b704 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 4f3b3d3a7b..7438156733 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index eaef7097b4..0367122601 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_lmhosts.c b/source3/nmbd/nmbd_lmhosts.c index be3ddfe637..ff2edc7e05 100644 --- a/source3/nmbd/nmbd_lmhosts.c +++ b/source3/nmbd/nmbd_lmhosts.c @@ -5,7 +5,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_logonnames.c b/source3/nmbd/nmbd_logonnames.c index e426430591..22fc951ff3 100644 --- a/source3/nmbd/nmbd_logonnames.c +++ b/source3/nmbd/nmbd_logonnames.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index f34d98172c..2e93eb5ef3 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index d71eb5479a..736c9fd325 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index 2c1cd13034..68ff68b337 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index 8f2a889254..fedf2ae9e4 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_namerelease.c b/source3/nmbd/nmbd_namerelease.c index 0611ca9323..aa53ee124b 100644 --- a/source3/nmbd/nmbd_namerelease.c +++ b/source3/nmbd/nmbd_namerelease.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_nodestatus.c b/source3/nmbd/nmbd_nodestatus.c index 0ea5d6a818..1228341416 100644 --- a/source3/nmbd/nmbd_nodestatus.c +++ b/source3/nmbd/nmbd_nodestatus.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 2fbf2f4146..9aead6d99c 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 287f3e8897..c05d61be10 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -8,7 +8,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index 367c1f4427..8d02fc4fc5 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index e2dc130463..47126530be 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -10,7 +10,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index ea27f9d4e5..5d7d340d4d 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 398119cc82..555e9585ce 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index fa1a41a5af..3238ac2460 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index 7a28eba77d..314e71d707 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -6,7 +6,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index bbaca83e21..66eeb24065 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -6,7 +6,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index ca665bdf4f..24467ef443 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, -- cgit From df2465298b2ca9cca92fadf69536dc77ade9fdb3 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:47:40 +0000 Subject: r23783: Processing the UAS change message was causing problems on ppc64 Linux systems. Rather than trying to fix this, it's much better just to remove the code, as it serves no purpose at all (the message that is generated is ignored by smbd). This sort of parsing should really be done by PIDL generated code. (This used to be commit 22e8404cef4961f7468a9f24e23024c827233b84) --- source3/nmbd/nmbd_processlogon.c | 110 +-------------------------------------- 1 file changed, 2 insertions(+), 108 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index c05d61be10..65c9e53cda 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -32,18 +32,6 @@ struct sam_database_info { uint32 date_lo, date_hi; }; -/**************************************************************************** -Send a message to smbd to do a sam delta sync -**************************************************************************/ - -static void send_repl_message(uint32 low_serial) -{ - DEBUG(3, ("sending replication message, serial = 0x%04x\n", - low_serial)); - message_send_all(nmbd_messaging_context(), MSG_SMB_SAM_REPL, - &low_serial, sizeof(low_serial), NULL); -} - /**************************************************************************** Process a domain logon packet **************************************************************************/ @@ -505,102 +493,8 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", replication event is required. */ case SAM_UAS_CHANGE: - { - struct sam_database_info *db_info; - char *q = buf + 2; - int i, db_count; - uint32 low_serial; - - /* Header */ - - if (PTR_DIFF(q + 16, buf) >= len) { - DEBUG(0,("process_logon_packet: bad packet\n")); - return; - } - - low_serial = IVAL(q, 0); q += 4; /* Low serial number */ - - q += 4; /* Date/time */ - q += 4; /* Pulse */ - q += 4; /* Random */ - - /* Domain info */ - - q = skip_string(buf,len,q); /* PDC name */ - - if (!q || PTR_DIFF(q, buf) >= len) { - DEBUG(0,("process_logon_packet: bad packet\n")); - return; - } - - q = skip_string(buf,len,q); /* Domain name */ - - if (!q || PTR_DIFF(q, buf) >= len) { - DEBUG(0,("process_logon_packet: bad packet\n")); - return; - } - - q = skip_unibuf(q, PTR_DIFF(buf + len, q)); /* Unicode PDC name */ - - if (PTR_DIFF(q, buf) >= len) { - DEBUG(0,("process_logon_packet: bad packet\n")); - return; - } - - q = skip_unibuf(q, PTR_DIFF(buf + len, q)); /* Unicode domain name */ - - /* Database info */ - - if (PTR_DIFF(q + 2, buf) >= len) { - DEBUG(0,("process_logon_packet: bad packet\n")); - return; - } - - db_count = SVAL(q, 0); q += 2; - - if (PTR_DIFF(q + (db_count*20), buf) >= len) { - DEBUG(0,("process_logon_packet: bad packet\n")); - return; - } - - db_info = SMB_MALLOC_ARRAY(struct sam_database_info, db_count); - - if (db_info == NULL) { - DEBUG(3, ("out of memory allocating info for %d databases\n", db_count)); - return; - } - - for (i = 0; i < db_count; i++) { - db_info[i].index = IVAL(q, 0); - db_info[i].serial_lo = IVAL(q, 4); - db_info[i].serial_hi = IVAL(q, 8); - db_info[i].date_lo = IVAL(q, 12); - db_info[i].date_hi = IVAL(q, 16); - q += 20; - } - - /* Domain SID */ - -#if 0 - /* We must range check this. */ - q += IVAL(q, 0) + 4; /* 4 byte length plus data */ - - q += 2; /* Alignment? */ - - /* Misc other info */ - - q += 4; /* NT version (0x1) */ - q += 2; /* LMNT token (0xff) */ - q += 2; /* LM20 token (0xff) */ -#endif - - SAFE_FREE(db_info); /* Not sure whether we need to do anything useful with these */ - - /* Send message to smbd */ - - send_repl_message(low_serial); - break; - } + DEBUG(5, ("Got SAM_UAS_CHANGE\n")); + break; default: DEBUG(3,("process_logon_packet: Unknown domain request %d\n",code)); -- cgit From 5e54558c6dea67b56bbfaba5698f3a434d3dffb6 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 00:52:41 +0000 Subject: r23784: use the GPLv3 boilerplate as recommended by the FSF and the license text (This used to be commit b0132e94fc5fef936aa766fb99a306b3628e9f07) --- source3/nmbd/asyncdns.c | 3 +-- source3/nmbd/nmbd.c | 3 +-- source3/nmbd/nmbd_become_dmb.c | 3 +-- source3/nmbd/nmbd_become_lmb.c | 3 +-- source3/nmbd/nmbd_browserdb.c | 3 +-- source3/nmbd/nmbd_browsesync.c | 3 +-- source3/nmbd/nmbd_elections.c | 3 +-- source3/nmbd/nmbd_incomingdgrams.c | 3 +-- source3/nmbd/nmbd_incomingrequests.c | 3 +-- source3/nmbd/nmbd_lmhosts.c | 3 +-- source3/nmbd/nmbd_logonnames.c | 3 +-- source3/nmbd/nmbd_mynames.c | 3 +-- source3/nmbd/nmbd_namelistdb.c | 3 +-- source3/nmbd/nmbd_namequery.c | 3 +-- source3/nmbd/nmbd_nameregister.c | 3 +-- source3/nmbd/nmbd_namerelease.c | 3 +-- source3/nmbd/nmbd_nodestatus.c | 3 +-- source3/nmbd/nmbd_packets.c | 3 +-- source3/nmbd/nmbd_processlogon.c | 3 +-- source3/nmbd/nmbd_responserecordsdb.c | 3 +-- source3/nmbd/nmbd_sendannounce.c | 3 +-- source3/nmbd/nmbd_serverlistdb.c | 3 +-- source3/nmbd/nmbd_subnetdb.c | 3 +-- source3/nmbd/nmbd_synclists.c | 3 +-- source3/nmbd/nmbd_winsproxy.c | 3 +-- source3/nmbd/nmbd_winsserver.c | 3 +-- source3/nmbd/nmbd_workgroupdb.c | 3 +-- 27 files changed, 27 insertions(+), 54 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 25bbcabe5c..f572aefc78 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index e62f4250de..b14e5a0b61 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index 08765038fa..a0250f205a 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index 34c6271e9f..ac65917d23 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c index 3b8ad8b3a7..a279364978 100644 --- a/source3/nmbd/nmbd_browserdb.c +++ b/source3/nmbd/nmbd_browserdb.c @@ -17,8 +17,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ /* -------------------------------------------------------------------------- ** diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index b261907b92..2e12f72b33 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 8d6a65b704..ef06ef0547 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 7438156733..ba533f4b0c 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index 0367122601..956d0ab1e9 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . This file contains all the code to process NetBIOS requests coming in on port 137. It does not deal with the code needed to service diff --git a/source3/nmbd/nmbd_lmhosts.c b/source3/nmbd/nmbd_lmhosts.c index ff2edc7e05..4785df6cba 100644 --- a/source3/nmbd/nmbd_lmhosts.c +++ b/source3/nmbd/nmbd_lmhosts.c @@ -14,8 +14,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . Revision History: diff --git a/source3/nmbd/nmbd_logonnames.c b/source3/nmbd/nmbd_logonnames.c index 22fc951ff3..71b69ebd87 100644 --- a/source3/nmbd/nmbd_logonnames.c +++ b/source3/nmbd/nmbd_logonnames.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index 2e93eb5ef3..5ebd42ce87 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 736c9fd325..75259a3672 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index 68ff68b337..4dcae87220 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index fedf2ae9e4..d781e0d89f 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ diff --git a/source3/nmbd/nmbd_namerelease.c b/source3/nmbd/nmbd_namerelease.c index aa53ee124b..cf19a3295e 100644 --- a/source3/nmbd/nmbd_namerelease.c +++ b/source3/nmbd/nmbd_namerelease.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ diff --git a/source3/nmbd/nmbd_nodestatus.c b/source3/nmbd/nmbd_nodestatus.c index 1228341416..8d51f13006 100644 --- a/source3/nmbd/nmbd_nodestatus.c +++ b/source3/nmbd/nmbd_nodestatus.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 9aead6d99c..baf243cda1 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 65c9e53cda..e837939fa3 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -17,8 +17,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . Revision History: diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index 8d02fc4fc5..640a1861ef 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index 47126530be..661b68f331 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -19,8 +19,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index 5d7d340d4d..9bd80b7270 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 555e9585ce..a2b5a97a18 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . Revision History: diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 3238ac2460..60d1d3fd8d 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index 314e71d707..2c57c4649a 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -15,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 66eeb24065..cd07549b30 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -15,8 +15,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . Converted to store WINS data in a tdb. Dec 2005. JRA. */ diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 24467ef443..60194e9915 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ -- cgit From 4ce5c3636714e80f740c141587c1e7a9ca3b67bb Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 24 Jul 2007 10:24:27 +0000 Subject: r24027: merge from http://people.samba.org/bzr/metze/samba/3_2-ctdb-metze/: add in any cluster addresses. We need to response to these, but not listen on them. This allows us to run nmbd on every node in the cluster, and have all of them register with a WINS server correctly metze (This used to be commit 98c57562c4dcf04b72a1e4ad5d9f5cf48e7d0b28) --- source3/nmbd/nmbd_mynames.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index 5ebd42ce87..8fa5439ee3 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -114,6 +114,7 @@ BOOL register_my_workgroup_and_names(void) { struct subnet_record *subrec; int i; + const char **cluster_addresses = NULL; for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { register_my_workgroup_one_subnet(subrec); @@ -144,6 +145,35 @@ BOOL register_my_workgroup_and_names(void) } } + /* + * add in any cluster addresses. We need to response to these, + * but not listen on them. This allows us to run nmbd on every + * node in the cluster, and have all of them register with a + * WINS server correctly + */ + if (lp_clustering()) { + cluster_addresses = lp_cluster_addresses(); + } + if (cluster_addresses) { + int a, n; + unsigned name_types[] = {0x20, 0x3, 0x0}; + + for (i=0; my_netbios_names(i); i++) { + for(subrec = FIRST_SUBNET; subrec; subrec = subrec->next) { + for (n=0;n and WORKGROUP<1e> group names to the unicast subnet * also for the same reasons. -- cgit From 2e498b48bbfb127b33d2e84ba87c7d9456c42558 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 21 Aug 2007 14:22:16 +0000 Subject: r24599: patch from Karolin Seeger : smbd, nmbd and winbindd can be started with invalid options currently. The first patch attached would be a possible solution. It contains an exit if an invalid option has been used. The main problem is, that existing setups with wrong options or missing arguments in start scripts will break (which is the right behaviour from my point of view). metze (This used to be commit 8532e3182ab44d4ac84823e9798293f156192aaf) --- source3/nmbd/nmbd.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index b14e5a0b61..4f1dd93cae 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -652,6 +652,7 @@ static BOOL open_sockets(enum smb_server_mode server_mode, int port) BOOL no_process_group = False; BOOL log_stdout = False; enum smb_server_mode server_mode = SERVER_MODE_DAEMON; + int opt; struct poptOption long_options[] = { POPT_AUTOHELP @@ -674,7 +675,14 @@ static BOOL open_sockets(enum smb_server_mode server_mode, int port) global_nmb_port = NMB_PORT; pc = poptGetContext("nmbd", argc, argv, long_options, 0); - while (poptGetNextOpt(pc) != -1) {}; + while ((opt = poptGetNextOpt(pc)) != -1) { + switch (opt) { + default: + d_fprintf(stderr, "\nInvalid option %s: %s\n", + poptBadOption(pc, 0), poptStrerror(opt)); + exit(1); + } + }; poptFreeContext(pc); global_in_nmbd = True; -- cgit From 8dd00920ef8f9e6dce9bfb80c45ae46c2a562abd Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Wed, 22 Aug 2007 12:06:27 +0000 Subject: r24621: - deferr calling build_options();exit(0); - use poptPrintUsage() to give the user more info metze (This used to be commit a95d9d1ef99d6a2f77a289f8d2011cae482821b1) --- source3/nmbd/nmbd.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 4f1dd93cae..9c8c764763 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -678,8 +678,9 @@ static BOOL open_sockets(enum smb_server_mode server_mode, int port) while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { default: - d_fprintf(stderr, "\nInvalid option %s: %s\n", + d_fprintf(stderr, "\nInvalid option %s: %s\n\n", poptBadOption(pc, 0), poptStrerror(opt)); + poptPrintUsage(pc, stderr, 0); exit(1); } }; -- cgit From 929e1d99209e20a9c2c95c8bdfc8eaa37b2c2291 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 30 Aug 2007 19:48:31 +0000 Subject: r24809: Consolidate the use of temporary talloc contexts. This adds the two functions talloc_stackframe() and talloc_tos(). * When a new talloc stackframe is allocated with talloc_stackframe(), then * the TALLOC_CTX returned with talloc_tos() is reset to that new * frame. Whenever that stack frame is TALLOC_FREE()'ed, then the reverse * happens: The previous talloc_tos() is restored. * * This API is designed to be robust in the sense that if someone forgets to * TALLOC_FREE() a stackframe, then the next outer one correctly cleans up and * resets the talloc_tos(). The original motivation for this patch was to get rid of the sid_string_static & friends buffers. Explicitly passing talloc context everywhere clutters code too much for my taste, so an implicit talloc_tos() is introduced here. Many of these static buffers are replaced by a single static pointer. The intended use would thus be that low-level functions can rather freely push stuff to talloc_tos, the upper layers clean up by freeing the stackframe. The more of these stackframes are used and correctly freed the more exact the memory cleanup happens. This patch removes the main_loop_talloc_ctx, tmp_talloc_ctx and lp_talloc_ctx (did I forget any?) So, never do a tmp_ctx = talloc_init("foo"); anymore, instead, use tmp_ctx = talloc_stackframe() :-) Volker (This used to be commit 6585ea2cb7f417e14540495b9c7380fe9c8c717b) --- source3/nmbd/nmbd.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 9c8c764763..b9d78a8ba9 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -372,6 +372,7 @@ static void process(void) while( True ) { time_t t = time(NULL); + TALLOC_CTX *frame = talloc_stackframe(); /* Check for internal messages */ @@ -390,8 +391,10 @@ static void process(void) * (nmbd_packets.c) */ - if(listen_for_packets(run_election)) + if(listen_for_packets(run_election)) { + TALLOC_FREE(frame); return; + } /* * Handle termination inband. @@ -583,18 +586,22 @@ static void process(void) NULL, MSG_SMB_CONF_UPDATED, procid_self(), &blob); - if(no_subnets) + if(no_subnets) { + TALLOC_FREE(frame); return; + } reload_after_sighup = 0; } /* check for new network interfaces */ - if(reload_interfaces(t)) + if(reload_interfaces(t)) { + TALLOC_FREE(frame); return; + } /* free up temp memory */ - lp_TALLOC_FREE(); + TALLOC_FREE(frame); } } -- cgit From 923f14ff37cc1ea70631cb9037685246d941cfae Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 8 Sep 2007 05:12:17 +0000 Subject: r25021: Fix coverity #435. Use of -1. Jeremy. (This used to be commit f789186086b55a81c52e05d1f8c97c33b69131bd) --- source3/nmbd/nmbd_subnetdb.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index a2b5a97a18..690ca5b621 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -124,8 +124,12 @@ static struct subnet_record *make_subnet(const char *name, enum subnet_type type subrec = SMB_MALLOC_P(struct subnet_record); if (!subrec) { DEBUG(0,("make_subnet: malloc fail !\n")); - close(nmb_sock); - close(dgram_sock); + if (nmb_sock != -1) { + close(nmb_sock); + } + if (dgram_sock != -1) { + close(dgram_sock); + } return(NULL); } @@ -133,8 +137,12 @@ static struct subnet_record *make_subnet(const char *name, enum subnet_type type if((subrec->subnet_name = SMB_STRDUP(name)) == NULL) { DEBUG(0,("make_subnet: malloc fail for subnet name !\n")); - close(nmb_sock); - close(dgram_sock); + if (nmb_sock != -1) { + close(nmb_sock); + } + if (dgram_sock != -1) { + close(dgram_sock); + } ZERO_STRUCTP(subrec); SAFE_FREE(subrec); return(NULL); -- cgit From eacd3140573d1122a3785823e4003bfc6352c431 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 13 Sep 2007 22:08:59 +0000 Subject: r25138: More pstring elimination. Add a TALLOC_CTX parameter to unix_convert(). Jeremy. (This used to be commit 39c211a702e91c34c1a5a689e1b0c4530ea8a1ac) --- source3/nmbd/nmbd_processlogon.c | 99 +++++++++++++++++++++++++++++++++------- 1 file changed, 82 insertions(+), 17 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index e837939fa3..1ba45ce8df 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -68,7 +68,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); DEBUG(4,("process_logon_packet: Logon from %s: code = 0x%x\n", inet_ntoa(p->ip), code)); switch (code) { - case 0: + case 0: { fstring mach_str, user_str, getdc_str; char *q = buf + 2; @@ -108,7 +108,9 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); fstrcpy(reply_name, "\\\\"); fstrcat(reply_name, my_name); - push_ascii_fstring(q, reply_name); + push_ascii(q,reply_name, + sizeof(outbuf)-PTR_DIFF(q, outbuf), + STR_TERMINATE); q = skip_string(outbuf,sizeof(outbuf),q); /* PDC name */ SSVAL(q, 0, token); @@ -116,7 +118,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); dump_data(4, (uint8 *)outbuf, PTR_DIFF(q, outbuf)); - send_mailslot(True, getdc_str, + send_mailslot(True, getdc_str, outbuf,PTR_DIFF(q,outbuf), global_myname(), 0x0, mach_str, @@ -132,7 +134,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); char *q = buf + 2; char *machine = q; - if (!lp_domain_master()) { + if (!lp_domain_master()) { /* We're not Primary Domain Controller -- ignore this */ return; } @@ -204,7 +206,9 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); q += 2; fstrcpy(reply_name,my_name); - push_ascii_fstring(q, reply_name); + push_ascii(q, reply_name, + sizeof(outbuf)-PTR_DIFF(q, outbuf), + STR_TERMINATE); q = skip_string(outbuf,sizeof(outbuf),q); /* PDC name */ /* PDC and domain name */ @@ -212,8 +216,15 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); /* Make a full reply */ q = ALIGN2(q, outbuf); - q += dos_PutUniCode(q, my_name, sizeof(pstring), True); /* PDC name */ - q += dos_PutUniCode(q, lp_workgroup(),sizeof(pstring), True); /* Domain name*/ + q += dos_PutUniCode(q, my_name, + sizeof(pstring) - PTR_DIFF(q, outbuf), + True); /* PDC name */ + q += dos_PutUniCode(q, lp_workgroup(), + sizeof(pstring) - (q-outbuf), + True); /* Domain name*/ + if (sizeof(pstring) - PTR_DIFF(q, outbuf) < 8) { + return; + } SIVAL(q, 0, 1); /* our nt version */ SSVAL(q, 4, 0xffff); /* our lmnttoken */ SSVAL(q, 6, 0xffff); /* our lm20token */ @@ -349,9 +360,15 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += 2; - q += dos_PutUniCode(q, reply_name,sizeof(pstring), True); - q += dos_PutUniCode(q, ascuser, sizeof(pstring), True); - q += dos_PutUniCode(q, lp_workgroup(),sizeof(pstring), True); + q += dos_PutUniCode(q, reply_name, + sizeof(pstring) - PTR_DIFF(q, outbuf), + True); + q += dos_PutUniCode(q, ascuser, + sizeof(pstring) - PTR_DIFF(q, outbuf), + True); + q += dos_PutUniCode(q, lp_workgroup(), + sizeof(pstring) - PTR_DIFF(q, outbuf), + True); } #ifdef HAVE_ADS else { @@ -366,7 +383,10 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", get_mydnsdomname(domain); get_myname(hostname); - + + if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 8) { + return; + } if (SVAL(uniuser, 0) == 0) { SIVAL(q, 0, SAMLOGON_AD_UNK_R); /* user unknown */ } else { @@ -379,6 +399,9 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += 4; /* Push Domain GUID */ + if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < UUID_FLAT_SIZE) { + return; + } if (False == secrets_fetch_domain_guid(domain, &domain_guid)) { DEBUG(2, ("Could not fetch DomainGUID for %s\n", domain)); return; @@ -394,12 +417,20 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q1 = q; while ((component = strtok(dc, "."))) { dc = NULL; - size = push_ascii(&q[1], component, -1, 0); + if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 1) { + return; + } + size = push_ascii(&q[1], component, + sizeof(outbuf) - PTR_DIFF(q+1, outbuf), + 0); SCVAL(q, 0, size); q += (size + 1); } /* Unk0 */ + if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 4) { + return; + } SCVAL(q, 0, 0); q++; @@ -409,44 +440,74 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += 2; /* Hostname */ - size = push_ascii(&q[1], hostname, -1, 0); + size = push_ascii(&q[1], hostname, + sizeof(outbuf) - PTR_DIFF(q+1, outbuf), + 0); SCVAL(q, 0, size); q += (size + 1); + + if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 3) { + return; + } + SCVAL(q, 0, 0xc0 | ((str_offset >> 8) & 0x3F)); SCVAL(q, 1, str_offset & 0xFF); q += 2; /* NETBIOS of domain */ - size = push_ascii(&q[1], lp_workgroup(), -1, STR_UPPER); + size = push_ascii(&q[1], lp_workgroup(), + sizeof(outbuf) - PTR_DIFF(q+1, outbuf), + STR_UPPER); SCVAL(q, 0, size); q += (size + 1); /* Unk1 */ + if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 2) { + return; + } + SCVAL(q, 0, 0); q++; /* NETBIOS of hostname */ - size = push_ascii(&q[1], my_name, -1, 0); + size = push_ascii(&q[1], my_name, + sizeof(outbuf) - PTR_DIFF(q+1, outbuf), + 0); SCVAL(q, 0, size); q += (size + 1); /* Unk2 */ + if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 4) { + return; + } + SCVAL(q, 0, 0); q++; /* User name */ if (SVAL(uniuser, 0) != 0) { - size = push_ascii(&q[1], ascuser, -1, 0); + size = push_ascii(&q[1], ascuser, + sizeof(outbuf) - PTR_DIFF(q+1, outbuf), + 0); SCVAL(q, 0, size); q += (size + 1); } q_orig = q; /* Site name */ - size = push_ascii(&q[1], "Default-First-Site-Name", -1, 0); + if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 1) { + return; + } + size = push_ascii(&q[1], "Default-First-Site-Name", + sizeof(outbuf) - PTR_DIFF(q+1, outbuf), + 0); SCVAL(q, 0, size); q += (size + 1); + if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 18) { + return; + } + /* Site name (2) */ str_offset = q - q_orig; SCVAL(q, 0, 0xc0 | ((str_offset >> 8) & 0x3F)); @@ -467,6 +528,10 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", } #endif + if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 8) { + return; + } + /* tell the client what version we are */ SIVAL(q, 0, ((ntversion < 11) || (SEC_ADS != lp_security())) ? 1 : 13); /* our ntversion */ -- cgit From 3aaca8028e09db58381076f199a43680f81f04ac Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 14 Sep 2007 22:03:41 +0000 Subject: r25170: Remove pstring limits from ms_fnmatch and module load. Jeremy. (This used to be commit 764574ee05ea4f13cdd30c0a0668ffeb81756989) --- source3/nmbd/nmbd_processlogon.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 1ba45ce8df..8a183c4d24 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -220,7 +220,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); sizeof(pstring) - PTR_DIFF(q, outbuf), True); /* PDC name */ q += dos_PutUniCode(q, lp_workgroup(), - sizeof(pstring) - (q-outbuf), + sizeof(pstring) - PTR_DIFF(q, outbuf), True); /* Domain name*/ if (sizeof(pstring) - PTR_DIFF(q, outbuf) < 8) { return; @@ -525,7 +525,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += 4; /* unknown */ SIVAL(q, 0, 0x00000000); q += 4; /* unknown */ - } + } #endif if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 8) { @@ -535,7 +535,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", /* tell the client what version we are */ SIVAL(q, 0, ((ntversion < 11) || (SEC_ADS != lp_security())) ? 1 : 13); /* our ntversion */ - SSVAL(q, 4, 0xffff); /* our lmnttoken */ + SSVAL(q, 4, 0xffff); /* our lmnttoken */ SSVAL(q, 6, 0xffff); /* our lm20token */ q += 8; @@ -549,7 +549,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", global_myname(), 0x0, source_name, dgram->source_name.name_type, - p->ip, *iface_ip(p->ip), p->port); + p->ip, *iface_ip(p->ip), p->port); break; } -- cgit From 934b92f5d0e4950f7b4c7531eecf3df59a4d0ed3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 19 Sep 2007 17:52:06 +0000 Subject: r25238: Make the error returns from the string functions always consistent. Return -1 on error, and ensure we check for this. In cases where the dest is already specified and we've been asked to terminate with a null, ensure we always do so even on error. Jeremy. (This used to be commit abedd967869ade9a43c3a8e1b889c60d4aca81cf) --- source3/nmbd/nmbd_processlogon.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 8a183c4d24..abac2ac776 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -53,6 +53,7 @@ void process_logon_packet(struct packet_struct *p, char *buf,int len, char *uniuser; /* Unicode user name. */ pstring ascuser; char *unicomp; /* Unicode computer name. */ + size_t size; memset(outbuf, 0, sizeof(outbuf)); @@ -108,9 +109,12 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); fstrcpy(reply_name, "\\\\"); fstrcat(reply_name, my_name); - push_ascii(q,reply_name, + size = push_ascii(q,reply_name, sizeof(outbuf)-PTR_DIFF(q, outbuf), STR_TERMINATE); + if (size == (size_t)-1) { + return; + } q = skip_string(outbuf,sizeof(outbuf),q); /* PDC name */ SSVAL(q, 0, token); @@ -206,9 +210,12 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); q += 2; fstrcpy(reply_name,my_name); - push_ascii(q, reply_name, + size = push_ascii(q, reply_name, sizeof(outbuf)-PTR_DIFF(q, outbuf), STR_TERMINATE); + if (size == (size_t)-1) { + return; + } q = skip_string(outbuf,sizeof(outbuf),q); /* PDC name */ /* PDC and domain name */ @@ -377,7 +384,6 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", pstring domain; pstring hostname; char *component, *dc, *q1; - uint8 size; char *q_orig = q; int str_offset; @@ -423,6 +429,9 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", size = push_ascii(&q[1], component, sizeof(outbuf) - PTR_DIFF(q+1, outbuf), 0); + if (size == (size_t)-1 || size > 0xff) { + return; + } SCVAL(q, 0, size); q += (size + 1); } @@ -443,6 +452,9 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", size = push_ascii(&q[1], hostname, sizeof(outbuf) - PTR_DIFF(q+1, outbuf), 0); + if (size == (size_t)-1 || size > 0xff) { + return; + } SCVAL(q, 0, size); q += (size + 1); @@ -458,6 +470,9 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", size = push_ascii(&q[1], lp_workgroup(), sizeof(outbuf) - PTR_DIFF(q+1, outbuf), STR_UPPER); + if (size == (size_t)-1 || size > 0xff) { + return; + } SCVAL(q, 0, size); q += (size + 1); @@ -473,6 +488,9 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", size = push_ascii(&q[1], my_name, sizeof(outbuf) - PTR_DIFF(q+1, outbuf), 0); + if (size == (size_t)-1 || size > 0xff) { + return; + } SCVAL(q, 0, size); q += (size + 1); @@ -489,6 +507,9 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", size = push_ascii(&q[1], ascuser, sizeof(outbuf) - PTR_DIFF(q+1, outbuf), 0); + if (size == (size_t)-1 || size > 0xff) { + return; + } SCVAL(q, 0, size); q += (size + 1); } @@ -501,6 +522,9 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", size = push_ascii(&q[1], "Default-First-Site-Name", sizeof(outbuf) - PTR_DIFF(q+1, outbuf), 0); + if (size == (size_t)-1 || size > 0xff) { + return; + } SCVAL(q, 0, size); q += (size + 1); -- cgit From 0d87820380416955a132d565a479b4234f78c113 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 3 Oct 2007 20:43:55 +0000 Subject: r25492: Start adding IPv6 compatible code to lib/util_sock.c and deal with the ripple effects this causes. utmp has to change etc. Remove some global varables and store address/port in the unexpected db. Jeremy. (This used to be commit 18c6a2211d9e25233d01715b3f78977edcd6d869) --- source3/nmbd/nmbd_packets.c | 54 ++++++++++++++++++++++----------------------- 1 file changed, 27 insertions(+), 27 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index baf243cda1..bf01075d14 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -766,7 +766,7 @@ struct response_record *queue_query_name( struct subnet_record *subrec, /**************************************************************************** Queue a query name packet to a given address from the WINS subnet. ****************************************************************************/ - + struct response_record *queue_query_name_from_wins_server( struct in_addr to_ip, response_function resp_fn, timeout_response_function timeout_fn, @@ -805,7 +805,7 @@ struct response_record *queue_query_name_from_wins_server( struct in_addr to_ip, /**************************************************************************** Queue a node status packet to a given name and address. ****************************************************************************/ - + struct response_record *queue_node_status( struct subnet_record *subrec, response_function resp_fn, timeout_response_function timeout_fn, @@ -835,7 +835,7 @@ unicast subnet. subnet is %s\n.", subrec->subnet_name )); p->locked = False; free_packet(p); return NULL; - } + } if((rrec = make_response_record(subrec, /* subnet record. */ p, /* packet we sent. */ @@ -867,11 +867,11 @@ void reply_netbios_packet(struct packet_struct *orig_packet, BOOL loopback_this_packet = False; int rr_type = RR_TYPE_NB; const char *packet_type = "unknown"; - + /* Check if we are sending to or from ourselves. */ if(ismyip(orig_packet->ip) && (orig_packet->port == global_nmb_port)) loopback_this_packet = True; - + nmb = &packet.packet.nmb; /* Do a partial copy of the packet. We clear the locked flag and @@ -944,28 +944,28 @@ for id %hu\n", packet_type, nmb_namestr(&orig_nmb->question.question_name), nmb->header.nm_flags.bcast = False; nmb->header.nm_flags.trunc = False; nmb->header.nm_flags.authoritative = True; - + nmb->header.rcode = rcode; nmb->header.qdcount = 0; nmb->header.ancount = 1; nmb->header.nscount = 0; nmb->header.arcount = 0; - + memset((char*)&nmb->question,'\0',sizeof(nmb->question)); - + nmb->answers = &answers; memset((char*)nmb->answers,'\0',sizeof(*nmb->answers)); - + nmb->answers->rr_name = orig_nmb->question.question_name; nmb->answers->rr_type = rr_type; nmb->answers->rr_class = RR_CLASS_IN; nmb->answers->ttl = ttl; - + if (data && len) { nmb->answers->rdlength = len; memcpy(nmb->answers->rdata, data, len); } - + packet.packet_type = NMB_PACKET; /* Ensure we send out on the same fd that the original packet came in on to give the correct source IP address. */ @@ -973,7 +973,7 @@ for id %hu\n", packet_type, nmb_namestr(&orig_nmb->question.question_name), packet.timestamp = time(NULL); debug_nmb_packet(&packet); - + if(loopback_this_packet) { struct packet_struct *lo_packet; DEBUG(5,("reply_netbios_packet: sending packet to ourselves.\n")); @@ -1000,9 +1000,9 @@ static void queue_packet(struct packet_struct *packet) packet_queue = packet; return; } - + /* find the bottom */ - for (p=packet_queue;p->next;p=p->next) + for (p=packet_queue;p->next;p=p->next) ; p->next = packet; @@ -1104,7 +1104,7 @@ packet from %s IP %s\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip))); process_master_browser_announce(subrec, p, buf+1); break; case ANN_BecomeBackup: - /* + /* * We don't currently implement this. Log it just in case. */ debug_browse_data(buf, len); @@ -1118,7 +1118,7 @@ command ANN_BecomeBackup from %s IP %s to %s\n", subrec->subnet_name, nmb_namest command code %d from %s IP %s to %s\n", subrec->subnet_name, command, nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name))); break; - } + } } /**************************************************************************** @@ -1345,7 +1345,7 @@ static BOOL validate_nmb_response_packet( struct nmb_packet *nmb ) return ignore; } - + /**************************************************************************** Validate a request nmb packet. ****************************************************************************/ @@ -1510,7 +1510,7 @@ not allowed.\n")); break; } break; - + case NMB_NAME_RELEASE_OPCODE: if(subrec == wins_server_subnet) wins_process_name_release_request(subrec, p); @@ -1549,7 +1549,7 @@ found for id = %hu. Ignoring packet.\n", nmb->header.name_trn_id)); rrec->num_msgs++; /* Ensure we don't re-send the request. */ rrec->repeat_count = 0; - + /* Call the response received function for this packet. */ (*rrec->resp_fn)(subrec, rrec, p); } @@ -1582,7 +1582,7 @@ void run_packet_queue(void) } free_packet(p); } -} +} /******************************************************************* Retransmit or timeout elements from all the outgoing subnet response @@ -1601,7 +1601,7 @@ void retransmit_or_expire_response_records(time_t t) for (rrec = subrec->responselist; rrec; rrec = nextrrec) { nextrrec = rrec->next; - + if (rrec->repeat_time <= t) { if (rrec->repeat_count > 0) { /* Resend while we have a non-zero repeat_count. */ @@ -1712,7 +1712,7 @@ only use %d.\n", (count*2) + 2, FD_SETSIZE)); *ppset = pset; *psock_array = sock_array; - + return False; } @@ -1756,7 +1756,7 @@ BOOL listen_for_packets(BOOL run_election) } #endif - /* + /* * During elections and when expecting a netbios response packet we * need to send election packets at tighter intervals. * Ideally it needs to be the interval (in ms) between time now and @@ -1778,7 +1778,7 @@ BOOL listen_for_packets(BOOL run_election) return False; } } - + /* Prepare for the select - allow certain signals. */ BlockSignals(False, SIGTERM); @@ -1886,7 +1886,7 @@ BOOL send_mailslot(BOOL unique, const char *mailslot,char *buf, size_t len, /* generate_name_trn_id(); */ /* Not used, so gone, RJS */ /* DIRECT GROUP or UNIQUE datagram. */ - dgram->header.msg_type = unique ? 0x10 : 0x11; + dgram->header.msg_type = unique ? 0x10 : 0x11; dgram->header.flags.node_type = M_NODE; dgram->header.flags.first = True; dgram->header.flags.more = False; @@ -1895,7 +1895,7 @@ BOOL send_mailslot(BOOL unique, const char *mailslot,char *buf, size_t len, dgram->header.source_port = DGRAM_PORT; dgram->header.dgm_length = 0; /* Let build_dgram() handle this. */ dgram->header.packet_offset = 0; - + make_nmb_name(&dgram->source_name,srcname,src_type); make_nmb_name(&dgram->dest_name,dstname,dest_type); @@ -1918,7 +1918,7 @@ BOOL send_mailslot(BOOL unique, const char *mailslot,char *buf, size_t len, p2 = smb_buf(ptr); safe_strcpy_base(p2, mailslot, dgram->data, sizeof(dgram->data)); p2 = skip_string(ptr,MAX_DGRAM_SIZE,p2); - + if (((p2+len) > dgram->data+sizeof(dgram->data)) || ((p2+len) < p2)) { DEBUG(0, ("send_mailslot: Cannot write beyond end of packet\n")); return False; -- cgit From e5a951325a6cac8567af3a66de6d2df577508ae4 Mon Sep 17 00:00:00 2001 From: "Gerald (Jerry) Carter" Date: Wed, 10 Oct 2007 15:34:30 -0500 Subject: [GLUE] Rsync SAMBA_3_2_0 SVN r25598 in order to create the v3-2-test branch. (This used to be commit 5c6c8e1fe93f340005110a7833946191659d88ab) --- source3/nmbd/nmbd.c | 61 ++++++++++++++++++++++----------------------- source3/nmbd/nmbd_packets.c | 2 +- 2 files changed, 31 insertions(+), 32 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index b9d78a8ba9..dc03506194 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -32,6 +32,15 @@ extern BOOL global_in_nmbd; extern BOOL override_logfile; +/* are we running as a daemon ? */ +static BOOL is_daemon; + +/* fork or run in foreground ? */ +static BOOL Fork = True; + +/* log to standard output ? */ +static BOOL log_stdout; + /* have we found LanMan clients yet? */ BOOL found_lm_clients = False; @@ -609,7 +618,7 @@ static void process(void) Open the socket communication. **************************************************************************** */ -static BOOL open_sockets(enum smb_server_mode server_mode, int port) +static BOOL open_sockets(BOOL isdaemon, int port) { /* * The sockets opened here will be used to receive broadcast @@ -619,13 +628,12 @@ static BOOL open_sockets(enum smb_server_mode server_mode, int port) * now deprecated. */ - if ( server_mode == SERVER_MODE_INETD ) { - ClientNMB = 0; - } else { + if ( isdaemon ) ClientNMB = open_socket_in(SOCK_DGRAM, port, 0, interpret_addr(lp_socket_address()), True); - } + else + ClientNMB = 0; ClientDGRAM = open_socket_in(SOCK_DGRAM, DGRAM_PORT, 3, interpret_addr(lp_socket_address()), @@ -654,21 +662,16 @@ static BOOL open_sockets(enum smb_server_mode server_mode, int port) int main(int argc, const char *argv[]) { pstring logfile; + static BOOL opt_interactive; poptContext pc; - const char *p_lmhosts = dyn_LMHOSTSFILE; - BOOL no_process_group = False; - BOOL log_stdout = False; - enum smb_server_mode server_mode = SERVER_MODE_DAEMON; + static char *p_lmhosts = dyn_LMHOSTSFILE; + static BOOL no_process_group = False; int opt; - struct poptOption long_options[] = { POPT_AUTOHELP - {"daemon", 'D', POPT_ARG_VAL, &server_mode, SERVER_MODE_DAEMON, - "Become a daemon(default)" }, - {"interactive", 'i', POPT_ARG_VAL, &server_mode, - SERVER_MODE_INTERACTIVE, "Run interactive (not a daemon)" }, - {"foreground", 'F', POPT_ARG_VAL, &server_mode, - SERVER_MODE_FOREGROUND, "Run daemon in foreground (for daemontools & etc)" }, + {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon(default)" }, + {"interactive", 'i', POPT_ARG_VAL, &opt_interactive, True, "Run interactive (not a daemon)" }, + {"foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools & etc)" }, {"no-process-group", 0, POPT_ARG_VAL, &no_process_group, True, "Don't create a new process group" }, {"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" }, {"hosts", 'H', POPT_ARG_STRING, &p_lmhosts, 'H', "Load a netbios hosts file"}, @@ -726,11 +729,12 @@ static BOOL open_sockets(enum smb_server_mode server_mode, int port) BlockSignals(True, SIGUSR2); #endif - if (server_mode == SERVER_MODE_INTERACTIVE) { + if ( opt_interactive ) { + Fork = False; log_stdout = True; } - if (log_stdout && server_mode == SERVER_MODE_DAEMON) { + if ( log_stdout && Fork ) { DEBUG(0,("ERROR: Can't log to stdout (-S) unless daemon is in foreground (-F) or interactive (-i)\n")); exit(1); } @@ -757,19 +761,14 @@ static BOOL open_sockets(enum smb_server_mode server_mode, int port) set_samba_nb_type(); - if (is_a_socket(0)) { - if (server_mode == SERVER_MODE_DAEMON) { - DEBUG(0,("standard input is a socket, " - "assuming -F option\n")); - } - server_mode = SERVER_MODE_INETD; + if (!is_daemon && !is_a_socket(0)) { + DEBUG(0,("standard input is not a socket, assuming -D option\n")); + is_daemon = True; } - - if (server_mode == SERVER_MODE_DAEMON) { + + if (is_daemon && !opt_interactive) { DEBUG( 2, ( "Becoming a daemon.\n" ) ); - become_daemon(True, no_process_group); - } else if (server_mode == SERVER_MODE_FOREGROUND) { - become_daemon(False, no_process_group); + become_daemon(Fork, no_process_group); } #if HAVE_SETPGID @@ -777,7 +776,7 @@ static BOOL open_sockets(enum smb_server_mode server_mode, int port) * If we're interactive we want to set our own process group for * signal management. */ - if (server_mode == SERVER_MODE_INTERACTIVE && !no_process_group) + if (opt_interactive && !no_process_group) setpgid( (pid_t)0, (pid_t)0 ); #endif @@ -816,7 +815,7 @@ static BOOL open_sockets(enum smb_server_mode server_mode, int port) DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); - if ( !open_sockets( server_mode, global_nmb_port ) ) { + if ( !open_sockets( is_daemon, global_nmb_port ) ) { kill_async_dns_child(); return 1; } diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index bf01075d14..875e13fdc8 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1904,7 +1904,7 @@ BOOL send_mailslot(BOOL unique, const char *mailslot,char *buf, size_t len, /* Setup the smb part. */ ptr -= 4; /* XXX Ugliness because of handling of tcp SMB length. */ memcpy(tmp,ptr,4); - set_message(NULL,ptr,17,strlen(mailslot) + 1 + len,True); + set_message(ptr,17,strlen(mailslot) + 1 + len,True); memcpy(ptr,tmp,4); SCVAL(ptr,smb_com,SMBtrans); -- cgit From 8e54530b52fd256137740107e9fdf000f00a7a30 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 10 Oct 2007 18:25:16 -0700 Subject: Add start of IPv6 implementation. Currently most of this is avoiding IPv6 in winbindd, but moves most of the socket functions that were wrongly in lib/util.c into lib/util_sock.c and provides generic IPv4/6 independent versions of most things. Still lots of work to do, but now I can see how I'll fix the access check code. Nasty part that remains is the name resolution code which is used to returning arrays of in_addr structs. Jeremy. (This used to be commit 3f6bd0e1ec5cc6670f3d08f76fc2cd94c9cd1a08) --- source3/nmbd/nmbd.c | 55 ++++++++++++++++++++++++++++-------- source3/nmbd/nmbd_become_dmb.c | 20 +++++++------ source3/nmbd/nmbd_browsesync.c | 8 +++--- source3/nmbd/nmbd_incomingrequests.c | 6 ++-- source3/nmbd/nmbd_lmhosts.c | 2 +- source3/nmbd/nmbd_logonnames.c | 2 -- source3/nmbd/nmbd_namequery.c | 2 +- source3/nmbd/nmbd_packets.c | 54 ++++++++++++++++++++--------------- source3/nmbd/nmbd_processlogon.c | 21 +++++++++++--- source3/nmbd/nmbd_subnetdb.c | 50 +++++++++++++++++++++----------- source3/nmbd/nmbd_synclists.c | 2 +- source3/nmbd/nmbd_winsproxy.c | 2 +- source3/nmbd/nmbd_winsserver.c | 4 +-- source3/nmbd/nmbd_workgroupdb.c | 2 +- 14 files changed, 149 insertions(+), 81 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index dc03506194..f0de0b8485 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -27,7 +27,6 @@ int ClientDGRAM = -1; int global_nmb_port = -1; extern BOOL rescan_listen_set; -extern struct in_addr loopback_ip; extern BOOL global_in_nmbd; extern BOOL override_logfile; @@ -192,33 +191,49 @@ static BOOL reload_interfaces(time_t t) /* find any interfaces that need adding */ for (n=iface_count() - 1; n >= 0; n--) { - struct interface *iface = get_interface(n); + char str[INET6_ADDRSTRLEN]; + const struct interface *iface = get_interface(n); + struct in_addr ip, nmask; if (!iface) { DEBUG(2,("reload_interfaces: failed to get interface %d\n", n)); continue; } + /* Ensure we're only dealing with IPv4 here. */ + if (iface->ip.ss_family != AF_INET) { + DEBUG(2,("reload_interfaces: " + "ignoring non IPv4 interface.\n")); + continue; + } + + ip = ((struct sockaddr_in *)&iface->ip)->sin_addr; + nmask = ((struct sockaddr_in *)&iface->netmask)->sin_addr; + /* * We don't want to add a loopback interface, in case * someone has added 127.0.0.1 for smbd, nmbd needs to * ignore it here. JRA. */ - if (ip_equal(iface->ip, loopback_ip)) { - DEBUG(2,("reload_interfaces: Ignoring loopback interface %s\n", inet_ntoa(iface->ip))); + if (is_loopback_addr(&iface->ip)) { + DEBUG(2,("reload_interfaces: Ignoring loopback " + "interface %s\n", + print_sockaddr(str, sizeof(str), + &iface->ip, sizeof(iface->ip)) )); continue; } for (subrec=subnetlist; subrec; subrec=subrec->next) { - if (ip_equal(iface->ip, subrec->myip) && - ip_equal(iface->nmask, subrec->mask_ip)) break; + if (ip_equal(ip, subrec->myip) && + ip_equal(nmask, subrec->mask_ip)) break; } if (!subrec) { /* it wasn't found! add it */ DEBUG(2,("Found new interface %s\n", - inet_ntoa(iface->ip))); + print_sockaddr(str, sizeof(str), + &iface->ip, sizeof(iface->ip)) )); subrec = make_normal_subnet(iface); if (subrec) register_my_workgroup_one_subnet(subrec); @@ -229,8 +244,20 @@ static BOOL reload_interfaces(time_t t) for (subrec=subnetlist; subrec; subrec=subrec->next) { for (n=iface_count() - 1; n >= 0; n--) { struct interface *iface = get_interface(n); - if (ip_equal(iface->ip, subrec->myip) && - ip_equal(iface->nmask, subrec->mask_ip)) break; + struct in_addr ip, nmask; + if (!iface) { + continue; + } + /* Ensure we're only dealing with IPv4 here. */ + if (iface->ip.ss_family != AF_INET) { + DEBUG(2,("reload_interfaces: " + "ignoring non IPv4 interface.\n")); + continue; + } + ip = ((struct sockaddr_in *)&iface->ip)->sin_addr; + nmask = ((struct sockaddr_in *)&iface->netmask)->sin_addr; + if (ip_equal(ip, subrec->myip) && + ip_equal(nmask, subrec->mask_ip)) break; } if (n == -1) { /* oops, an interface has disapeared. This is @@ -322,7 +349,9 @@ static void msg_nmbd_send_packet(struct messaging_context *msg, { struct packet_struct *p = (struct packet_struct *)data->data; struct subnet_record *subrec; - struct in_addr *local_ip; + struct sockaddr_storage ss; + const struct sockaddr_storage *pss; + const struct in_addr *local_ip; DEBUG(10, ("Received send_packet from %d\n", procid_to_pid(&src))); @@ -339,14 +368,16 @@ static void msg_nmbd_send_packet(struct messaging_context *msg, return; } - local_ip = iface_ip(p->ip); + in_addr_to_sockaddr_storage(&ss, p->ip); + pss = iface_ip(&ss); - if (local_ip == NULL) { + if (pss == NULL) { DEBUG(2, ("Could not find ip for packet from %d\n", procid_to_pid(&src))); return; } + local_ip = &((const struct sockaddr_in *)pss)->sin_addr; subrec = FIRST_SUBNET; p->fd = (p->packet_type == NMB_PACKET) ? diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index a0250f205a..fb87927436 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -22,8 +22,6 @@ #include "includes.h" -extern struct in_addr allones_ip; - extern uint16 samba_nb_type; /* Samba's NetBIOS type. */ static void become_domain_master_browser_bcast(const char *); @@ -119,7 +117,7 @@ in workgroup %s on subnet %s\n", if( subrec == unicast_subnet ) { struct nmb_name nmbname; struct in_addr my_first_ip; - struct in_addr *nip; + const struct in_addr *nip; /* Put our name and first IP address into the workgroup struct as domain master browser. This @@ -129,14 +127,14 @@ in workgroup %s on subnet %s\n", make_nmb_name(&nmbname, global_myname(), 0x20); work->dmb_name = nmbname; - /* Pick the first interface ip address as the domain master browser ip. */ - nip = iface_n_ip(0); + /* Pick the first interface IPv4 address as the domain master browser ip. */ + nip = first_ipv4_iface(); if (!nip) { - DEBUG(0,("become_domain_master_stage2: Error. iface_n_ip returned NULL\n")); + DEBUG(0,("become_domain_master_stage2: " + "Error. get_interface returned NULL\n")); return; } - my_first_ip = *nip; putip((char *)&work->dmb_addr, &my_first_ip); @@ -204,10 +202,12 @@ workgroup %s on subnet %s\n", wg_name, subrec->subnet_name)); static void become_domain_master_query_success(struct subnet_record *subrec, struct userdata_struct *userdata, - struct nmb_name *nmbname, struct in_addr ip, + struct nmb_name *nmbname, struct in_addr ip, struct res_rec *rrec) { unstring name; + struct in_addr allones_ip; + pull_ascii_nstring(name, sizeof(name), nmbname->name); /* If the given ip is not ours, then we can't become a domain @@ -217,7 +217,9 @@ static void become_domain_master_query_success(struct subnet_record *subrec, /* BUG note. Samba 1.9.16p11 servers seem to return the broadcast address or zero ip for this query. Pretend this is ok. */ - if(ismyip(ip) || ip_equal(allones_ip, ip) || is_zero_ip(ip)) { + allones_ip.s_addr = htonl(INADDR_BROADCAST); + + if(ismyip_v4(ip) || ip_equal(allones_ip, ip) || is_zero_ip_v4(ip)) { if( DEBUGLVL( 3 ) ) { dbgtext( "become_domain_master_query_success():\n" ); dbgtext( "Our address (%s) ", inet_ntoa(ip) ); diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 2e12f72b33..e141b3e288 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -103,7 +103,7 @@ static void announce_local_master_browser_to_domain_master_browser( struct work_ unstring dmb_name; char *p; - if(ismyip(work->dmb_addr)) { + if(ismyip_v4(work->dmb_addr)) { if( DEBUGLVL( 2 ) ) { dbgtext( "announce_local_master_browser_to_domain_master_browser:\n" ); dbgtext( "We are both a domain and a local master browser for " ); @@ -291,7 +291,7 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec, /* First check if we already have a dmb for this workgroup. */ - if(!is_zero_ip(work->dmb_addr) && ip_equal(work->dmb_addr, answer_ip)) { + if(!is_zero_ip_v4(work->dmb_addr) && ip_equal(work->dmb_addr, answer_ip)) { /* Do the local master browser announcement to the domain master browser name and IP. */ announce_local_master_browser_to_domain_master_browser( work ); @@ -300,7 +300,7 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec, sync_with_dmb(work); return; } else { - zero_ip(&work->dmb_addr); + zero_ip_v4(&work->dmb_addr); } /* Now initiate the node status request. */ @@ -526,7 +526,7 @@ static void find_all_domain_master_names_query_success(struct subnet_record *sub * Don't send node status requests to ourself. */ - if(ismyip( send_ip )) { + if(ismyip_v4( send_ip )) { if( DEBUGLVL( 5 ) ) { dbgtext( "find_all_domain_master_names_query_succes:\n" ); dbgtext( "Not sending node status to our own IP " ); diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index 956d0ab1e9..292a580ef9 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -88,7 +88,7 @@ subnet %s from owner IP %s\n", subrec->subnet_name, inet_ntoa(owner_ip))); /* If someone is releasing a broadcast group name, just ignore it. */ - if( group && !ismyip(owner_ip) ) + if( group && !ismyip_v4(owner_ip) ) return; /* @@ -98,7 +98,7 @@ subnet %s from owner IP %s\n", */ pull_ascii_nstring(qname, sizeof(qname), question->name); - if( !group && !ismyip(owner_ip) && strequal(qname, lp_workgroup()) && + if( !group && !ismyip_v4(owner_ip) && strequal(qname, lp_workgroup()) && ((question->name_type == 0x0) || (question->name_type == 0x1e))) { DEBUG(6,("process_name_release_request: FTP OnNet bug workaround. Ignoring \ group release name %s from IP %s on subnet %s with no group bit set.\n", @@ -497,7 +497,7 @@ void process_name_query_request(struct subnet_record *subrec, struct packet_stru if (namerec->data.source == WINS_PROXY_NAME) { for( i = 0; i < namerec->data.num_ips; i++) { - if (same_net(namerec->data.ip[i], subrec->myip, subrec->mask_ip)) { + if (same_net_v4(namerec->data.ip[i], subrec->myip, subrec->mask_ip)) { DEBUG(5,("process_name_query_request: name %s is a WINS proxy name and is also on the same subnet (%s) as the requestor. Not replying.\n", nmb_namestr(&namerec->name), subrec->subnet_name )); return; diff --git a/source3/nmbd/nmbd_lmhosts.c b/source3/nmbd/nmbd_lmhosts.c index 4785df6cba..eba7329418 100644 --- a/source3/nmbd/nmbd_lmhosts.c +++ b/source3/nmbd/nmbd_lmhosts.c @@ -48,7 +48,7 @@ void load_lmhosts_file(const char *fname) /* We find a relevent subnet to put this entry on, then add it. */ /* Go through all the broadcast subnets and see if the mask matches. */ for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { - if(same_net(ipaddr, subrec->bcast_ip, subrec->mask_ip)) + if(same_net_v4(ipaddr, subrec->bcast_ip, subrec->mask_ip)) break; } diff --git a/source3/nmbd/nmbd_logonnames.c b/source3/nmbd/nmbd_logonnames.c index 71b69ebd87..f0350af3b8 100644 --- a/source3/nmbd/nmbd_logonnames.c +++ b/source3/nmbd/nmbd_logonnames.c @@ -22,8 +22,6 @@ #include "includes.h" -extern struct in_addr allones_ip; - extern uint16 samba_nb_type; /* Samba's NetBIOS type. */ /**************************************************************************** diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index 4dcae87220..ea170d3aaa 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -35,7 +35,7 @@ static void query_name_response( struct subnet_record *subrec, struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name; struct in_addr answer_ip; - zero_ip(&answer_ip); + zero_ip_v4(&answer_ip); /* Ensure we don't retry the query but leave the response record cleanup to the timeout code. We may get more answer responses in which case diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 875e13fdc8..cb13febe46 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -28,8 +28,6 @@ extern int global_nmb_port; extern int num_response_packets; -extern struct in_addr loopback_ip; - static void queue_packet(struct packet_struct *packet); BOOL rescan_listen_set = False; @@ -148,7 +146,7 @@ static BOOL send_netbios_packet(struct packet_struct *p) BOOL loopback_this_packet = False; /* Check if we are sending to or from ourselves as a WINS server. */ - if(ismyip(p->ip) && (p->port == global_nmb_port)) + if(ismyip_v4(p->ip) && (p->port == global_nmb_port)) loopback_this_packet = True; if(loopback_this_packet) { @@ -225,12 +223,12 @@ static struct packet_struct *create_and_init_netbios_packet(struct nmb_name *nmb static BOOL create_and_init_additional_record(struct packet_struct *packet, uint16 nb_flags, - struct in_addr *register_ip) + const struct in_addr *register_ip) { struct nmb_packet *nmb = &packet->packet.nmb; if((nmb->additional = SMB_MALLOC_P(struct res_rec)) == NULL) { - DEBUG(0,("initiate_name_register_packet: malloc fail for additional record.\n")); + DEBUG(0,("create_and_init_additional_record: malloc fail for additional record.\n")); return False; } @@ -316,7 +314,7 @@ static BOOL initiate_name_query_packet_from_wins_server( struct packet_struct *p **************************************************************************/ static BOOL initiate_name_register_packet( struct packet_struct *packet, - uint16 nb_flags, struct in_addr *register_ip) + uint16 nb_flags, const struct in_addr *register_ip) { struct nmb_packet *nmb = &packet->packet.nmb; @@ -469,7 +467,8 @@ struct response_record *queue_register_name( struct subnet_record *subrec, { struct packet_struct *p; struct response_record *rrec; - + struct sockaddr_storage ss; + const struct sockaddr_storage *pss = NULL; if(assert_check_subnet(subrec)) return NULL; @@ -478,7 +477,16 @@ struct response_record *queue_register_name( struct subnet_record *subrec, subrec->bcast_ip)) == NULL) return NULL; - if(initiate_name_register_packet( p, nb_flags, iface_ip(subrec->bcast_ip)) == False) { + in_addr_to_sockaddr_storage(&ss, subrec->bcast_ip); + pss = iface_ip(&ss); + if (!pss || pss->ss_family != AF_INET) { + p->locked = False; + free_packet(p); + return NULL; + } + + if(initiate_name_register_packet(p, nb_flags, + &((const struct sockaddr_in *)pss)->sin_addr) == False) { p->locked = False; free_packet(p); return NULL; @@ -698,7 +706,7 @@ struct response_record *queue_query_name( struct subnet_record *subrec, /* queries to the WINS server turn up here as queries to IP 0.0.0.0 These need to be handled a bit differently */ - if (subrec->type == UNICAST_SUBNET && is_zero_ip(to_ip)) { + if (subrec->type == UNICAST_SUBNET && is_zero_ip_v4(to_ip)) { /* What we really need to do is loop over each of our wins * servers and wins server tags here, but that just doesn't * fit our architecture at the moment (userdata may already @@ -724,14 +732,14 @@ struct response_record *queue_query_name( struct subnet_record *subrec, DEBUG(10,("queue_query_name: bind_interfaces_only is set, looking for suitable source IP\n")); for(i = 0; i < iface_count(); i++) { - struct in_addr *ifip = iface_n_ip(i); + const struct in_addr *ifip = iface_n_ip_v4(i); - if(ifip == NULL) { + if (ifip == NULL) { DEBUG(0,("queue_query_name: interface %d has NULL IP address !\n", i)); continue; } - if (ip_equal(*ifip,loopback_ip)) { + if (is_loopback_ip_v4(*ifip)) { DEBUG(5,("queue_query_name: ignoring loopback interface (%d)\n", i)); continue; } @@ -869,7 +877,7 @@ void reply_netbios_packet(struct packet_struct *orig_packet, const char *packet_type = "unknown"; /* Check if we are sending to or from ourselves. */ - if(ismyip(orig_packet->ip) && (orig_packet->port == global_nmb_port)) + if(ismyip_v4(orig_packet->ip) && (orig_packet->port == global_nmb_port)) loopback_this_packet = True; nmb = &packet.packet.nmb; @@ -1020,7 +1028,7 @@ static struct subnet_record *find_subnet_for_dgram_browse_packet(struct packet_s /* Go through all the broadcast subnets and see if the mask matches. */ for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { - if(same_net(p->ip, subrec->bcast_ip, subrec->mask_ip)) + if(same_net_v4(p->ip, subrec->bcast_ip, subrec->mask_ip)) return subrec; } @@ -1176,7 +1184,7 @@ static BOOL listening(struct packet_struct *p,struct nmb_name *nbname) struct subnet_record *subrec = NULL; for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { - if(same_net(p->ip, subrec->bcast_ip, subrec->mask_ip)) + if(same_net_v4(p->ip, subrec->bcast_ip, subrec->mask_ip)) break; } @@ -1439,7 +1447,7 @@ static struct subnet_record *find_subnet_for_nmb_packet( struct packet_struct *p /* Go through all the broadcast subnets and see if the mask matches. */ for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { - if(same_net(p->ip, subrec->bcast_ip, subrec->mask_ip)) + if(same_net_v4(p->ip, subrec->bcast_ip, subrec->mask_ip)) return subrec; } @@ -1814,12 +1822,12 @@ BOOL listen_for_packets(BOOL run_election) * only is set then check it came from one of our local nets. */ if(lp_bind_interfaces_only() && (sock_array[i] == ClientNMB) && - (!is_local_net(packet->ip))) { + (!is_local_net_v4(packet->ip))) { DEBUG(7,("discarding nmb packet sent to broadcast socket from %s:%d\n", inet_ntoa(packet->ip),packet->port)); free_packet(packet); - } else if ((ip_equal(loopback_ip, packet->ip) || - ismyip(packet->ip)) && packet->port == global_nmb_port && + } else if ((is_loopback_ip_v4(packet->ip) || + ismyip_v4(packet->ip)) && packet->port == global_nmb_port && packet->packet.nmb.header.nm_flags.bcast) { DEBUG(7,("discarding own bcast packet from %s:%d\n", inet_ntoa(packet->ip),packet->port)); @@ -1841,12 +1849,12 @@ BOOL listen_for_packets(BOOL run_election) * only is set then check it came from one of our local nets. */ if(lp_bind_interfaces_only() && (sock_array[i] == ClientDGRAM) && - (!is_local_net(packet->ip))) { + (!is_local_net_v4(packet->ip))) { DEBUG(7,("discarding dgram packet sent to broadcast socket from %s:%d\n", inet_ntoa(packet->ip),packet->port)); free_packet(packet); - } else if ((ip_equal(loopback_ip, packet->ip) || - ismyip(packet->ip)) && packet->port == DGRAM_PORT) { + } else if ((is_loopback_ip_v4(packet->ip) || + ismyip_v4(packet->ip)) && packet->port == DGRAM_PORT) { DEBUG(7,("discarding own dgram packet from %s:%d\n", inet_ntoa(packet->ip),packet->port)); free_packet(packet); @@ -1880,7 +1888,7 @@ BOOL send_mailslot(BOOL unique, const char *mailslot,char *buf, size_t len, memset((char *)&p,'\0',sizeof(p)); - if(ismyip(dest_ip) && (dest_port == DGRAM_PORT)) /* Only if to DGRAM_PORT */ + if(ismyip_v4(dest_ip) && (dest_port == DGRAM_PORT)) /* Only if to DGRAM_PORT */ loopback_this_packet = True; /* generate_name_trn_id(); */ /* Not used, so gone, RJS */ diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index abac2ac776..4b5fe28d4e 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -54,6 +54,19 @@ void process_logon_packet(struct packet_struct *p, char *buf,int len, pstring ascuser; char *unicomp; /* Unicode computer name. */ size_t size; + struct sockaddr_storage ss; + const struct sockaddr_storage *pss; + struct in_addr ip; + + in_addr_to_sockaddr_storage(&ss, p->ip); + pss = iface_ip(&ss); + if (!pss) { + DEBUG(5,("process_logon_packet:can't find outgoing interface " + "for packet from IP %s\n", + inet_ntoa(p->ip) )); + return; + } + ip = ((struct sockaddr_in *)pss)->sin_addr; memset(outbuf, 0, sizeof(outbuf)); @@ -127,7 +140,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); global_myname(), 0x0, mach_str, dgram->source_name.name_type, - p->ip, *iface_ip(p->ip), p->port); + p->ip, ip, p->port); break; } @@ -258,7 +271,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", global_myname(), 0x0, source_name, dgram->source_name.name_type, - p->ip, *iface_ip(p->ip), p->port); + p->ip, ip, p->port); return; } @@ -543,7 +556,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", SIVAL(q, 0, 0x00000002); q += 4; /* unknown */ - SIVAL(q, 0, (iface_ip(p->ip))->s_addr); + SIVAL(q, 0, ntohl(ip.s_addr)); q += 4; SIVAL(q, 0, 0x00000000); q += 4; /* unknown */ @@ -573,7 +586,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", global_myname(), 0x0, source_name, dgram->source_name.name_type, - p->ip, *iface_ip(p->ip), p->port); + p->ip, ip, p->port); break; } diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 690ca5b621..7fd241cf62 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -24,7 +24,6 @@ #include "includes.h" -extern struct in_addr loopback_ip; extern int global_nmb_port; /* This is the broadcast subnets database. */ @@ -169,12 +168,16 @@ static struct subnet_record *make_subnet(const char *name, enum subnet_type type Create a normal subnet **************************************************************************/ -struct subnet_record *make_normal_subnet(struct interface *iface) +struct subnet_record *make_normal_subnet(const struct interface *iface) { + struct subnet_record *subrec; + const struct in_addr *pip = &((const struct sockaddr_in *)&iface->ip)->sin_addr; + const struct in_addr *pbcast = &((const struct sockaddr_in *)&iface->bcast)->sin_addr; + const struct in_addr *pnmask = &((const struct sockaddr_in *)&iface->netmask)->sin_addr; - subrec = make_subnet(inet_ntoa(iface->ip), NORMAL_SUBNET, - iface->ip, iface->bcast, iface->nmask); + subrec = make_subnet(inet_ntoa(*pip), NORMAL_SUBNET, + *pip, *pbcast, *pnmask); if (subrec) { add_subnet(subrec); } @@ -186,8 +189,9 @@ struct subnet_record *make_normal_subnet(struct interface *iface) **************************************************************************/ BOOL create_subnets(void) -{ - int num_interfaces = iface_count(); +{ + /* We only count IPv4 interfaces whilst we're waiting. */ + int num_interfaces = iface_count_v4(); int i; struct in_addr unicast_ip, ipzero; @@ -197,47 +201,59 @@ BOOL create_subnets(void) DEBUG(0,("create_subnets: No local interfaces !\n")); DEBUG(0,("create_subnets: Waiting for an interface to appear ...\n")); - /* + /* * Whilst we're waiting for an interface, allow SIGTERM to * cause us to exit. */ saved_handler = CatchSignal( SIGTERM, SIGNAL_CAST SIG_DFL ); - while (iface_count() == 0) { + /* We only count IPv4 interfaces here. */ + while (iface_count_v4() == 0) { sleep(5); load_interfaces(); } - /* + /* * We got an interface, restore our normal term handler. */ CatchSignal( SIGTERM, SIGNAL_CAST saved_handler ); } + /* + * Here we count v4 and v6 - we know there's at least one + * IPv4 interface and we filter on it below. + */ num_interfaces = iface_count(); - /* + /* * Create subnets from all the local interfaces and thread them onto - * the linked list. + * the linked list. */ for (i = 0 ; i < num_interfaces; i++) { - struct interface *iface = get_interface(i); + const struct interface *iface = get_interface(i); if (!iface) { DEBUG(2,("create_subnets: can't get interface %d.\n", i )); continue; } + /* Ensure we're only dealing with IPv4 here. */ + if (iface->ip.ss_family != AF_INET) { + DEBUG(2,("create_subnets: " + "ignoring non IPv4 interface.\n")); + continue; + } + /* * We don't want to add a loopback interface, in case * someone has added 127.0.0.1 for smbd, nmbd needs to * ignore it here. JRA. */ - if (ip_equal(iface->ip, loopback_ip)) { + if (is_loopback_addr(&iface->ip)) { DEBUG(2,("create_subnets: Ignoring loopback interface.\n" )); continue; } @@ -254,8 +270,8 @@ BOOL create_subnets(void) } if (lp_we_are_a_wins_server()) { - /* Pick the first interface ip address as the WINS server ip. */ - struct in_addr *nip = iface_n_ip(0); + /* Pick the first interface IPv4 address as the WINS server ip. */ + const struct in_addr *nip = first_ipv4_iface(); if (!nip) { return False; @@ -266,7 +282,7 @@ BOOL create_subnets(void) /* note that we do not set the wins server IP here. We just set it at zero and let the wins registration code cope with getting the IPs right for each packet */ - zero_ip(&unicast_ip); + zero_ip_v4(&unicast_ip); } /* @@ -279,7 +295,7 @@ BOOL create_subnets(void) unicast_subnet = make_subnet( "UNICAST_SUBNET", UNICAST_SUBNET, unicast_ip, unicast_ip, unicast_ip); - zero_ip(&ipzero); + zero_ip_v4(&ipzero); remote_broadcast_subnet = make_subnet( "REMOTE_BROADCAST_SUBNET", REMOTE_BROADCAST_SUBNET, diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 60d1d3fd8d..6b716bdf35 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -149,7 +149,7 @@ void sync_browse_lists(struct work_record *work, START_PROFILE(sync_browse_lists); /* Check we're not trying to sync with ourselves. This can happen if we are a domain *and* a local master browser. */ - if (ismyip(ip)) { + if (ismyip_v4(ip)) { done: END_PROFILE(sync_browse_lists); return; diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index 2c57c4649a..ff80c15fff 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -107,7 +107,7 @@ returned for name %s.\n", nmb_namestr(nmbname) )); if(namerec && original_packet->packet.nmb.header.nm_flags.bcast) { for( i = 0; i < namerec->data.num_ips; i++) { - if( same_net( namerec->data.ip[i], orig_broadcast_subnet->myip, + if( same_net_v4( namerec->data.ip[i], orig_broadcast_subnet->myip, orig_broadcast_subnet->mask_ip ) ) { DEBUG( 5, ( "wins_proxy_name_query_request_success: name %s is a WINS \ proxy name and is also on the same subnet (%s) as the requestor. \ diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index cd07549b30..66c060f652 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -1273,7 +1273,7 @@ already exists in WINS as a GROUP name.\n", nmb_namestr(question) )); if ( namerec != NULL ) { pull_ascii_nstring(name, sizeof(name), namerec->name.name); if( is_myname(name) ) { - if(!ismyip(from_ip)) { + if(!ismyip_v4(from_ip)) { DEBUG(3,("wins_process_name_registration_request: Attempt to register name %s. Name \ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(question) )); send_wins_name_registration_response(RFS_ERR, 0, p); @@ -1595,7 +1595,7 @@ already exists in WINS as a GROUP name.\n", nmb_namestr(question) )); */ if((namerec != NULL) && (is_myname(namerec->name.name)) ) { - if(!ismyip(from_ip)) { + if(!ismyip_v4(from_ip)) { DEBUG(3,("wins_process_multihomed_name_registration_request: Attempt to register name %s. Name \ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(question) )); send_wins_name_registration_response(RFS_ERR, 0, p); diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 60194e9915..82c3a31669 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -110,7 +110,7 @@ static struct work_record *create_workgroup(const char *name, int ttl) /* No known domain master browser as yet. */ *work->dmb_name.name = '\0'; - zero_ip(&work->dmb_addr); + zero_ip_v4(&work->dmb_addr); /* WfWg uses 01040b01 */ /* Win95 uses 01041501 */ -- cgit From 30191d1a5704ad2b158386b511558972d539ce47 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 18 Oct 2007 17:40:25 -0700 Subject: RIP BOOL. Convert BOOL -> bool. I found a few interesting bugs in various places whilst doing this (places that assumed BOOL == int). I also need to fix the Samba4 pidl generation (next checkin). Jeremy. (This used to be commit f35a266b3cbb3e5fa6a86be60f34fe340a3ca71f) --- source3/nmbd/asyncdns.c | 8 +++--- source3/nmbd/nmbd.c | 34 ++++++++++++------------- source3/nmbd/nmbd_become_lmb.c | 20 +++++++-------- source3/nmbd/nmbd_elections.c | 6 ++--- source3/nmbd/nmbd_incomingdgrams.c | 2 +- source3/nmbd/nmbd_incomingrequests.c | 14 +++++----- source3/nmbd/nmbd_lmhosts.c | 2 +- source3/nmbd/nmbd_mynames.c | 2 +- source3/nmbd/nmbd_namelistdb.c | 10 ++++---- source3/nmbd/nmbd_namequery.c | 10 ++++---- source3/nmbd/nmbd_nameregister.c | 8 +++--- source3/nmbd/nmbd_namerelease.c | 8 +++--- source3/nmbd/nmbd_nodestatus.c | 2 +- source3/nmbd/nmbd_packets.c | 48 +++++++++++++++++------------------ source3/nmbd/nmbd_processlogon.c | 2 +- source3/nmbd/nmbd_responserecordsdb.c | 2 +- source3/nmbd/nmbd_sendannounce.c | 2 +- source3/nmbd/nmbd_serverlistdb.c | 4 +-- source3/nmbd/nmbd_subnetdb.c | 4 +-- source3/nmbd/nmbd_synclists.c | 4 +-- source3/nmbd/nmbd_winsserver.c | 42 +++++++++++++++--------------- source3/nmbd/nmbd_workgroupdb.c | 2 +- 22 files changed, 118 insertions(+), 118 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index f572aefc78..b9c9ffb1c6 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -166,7 +166,7 @@ void start_async_dns(void) /*************************************************************************** check if a particular name is already being queried ****************************************************************************/ -static BOOL query_current(struct query_record *r) +static bool query_current(struct query_record *r) { return dns_current && nmb_name_equal(&r->name, @@ -177,7 +177,7 @@ static BOOL query_current(struct query_record *r) /*************************************************************************** write a query to the child process ****************************************************************************/ -static BOOL write_child(struct packet_struct *p) +static bool write_child(struct packet_struct *p) { struct query_record r; @@ -285,7 +285,7 @@ void run_dns_queue(void) queue a DNS query ****************************************************************************/ -BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question) +bool queue_dns_query(struct packet_struct *p,struct nmb_name *question) { if (in_dns || fd_in == -1) return False; @@ -317,7 +317,7 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question) we use this when we can't do async DNS lookups ****************************************************************************/ -BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question) +bool queue_dns_query(struct packet_struct *p,struct nmb_name *question) { struct name_record *namerec = NULL; struct in_addr dns_ip; diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index f0de0b8485..46808f51de 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -26,22 +26,22 @@ int ClientNMB = -1; int ClientDGRAM = -1; int global_nmb_port = -1; -extern BOOL rescan_listen_set; -extern BOOL global_in_nmbd; +extern bool rescan_listen_set; +extern bool global_in_nmbd; -extern BOOL override_logfile; +extern bool override_logfile; /* are we running as a daemon ? */ -static BOOL is_daemon; +static bool is_daemon; /* fork or run in foreground ? */ -static BOOL Fork = True; +static bool Fork = True; /* log to standard output ? */ -static BOOL log_stdout; +static bool log_stdout; /* have we found LanMan clients yet? */ -BOOL found_lm_clients = False; +bool found_lm_clients = False; /* what server type are we currently */ @@ -174,7 +174,7 @@ static void expire_names_and_servers(time_t t) Reload the list of network interfaces. ************************************************************************** */ -static BOOL reload_interfaces(time_t t) +static bool reload_interfaces(time_t t) { static time_t lastt; int n; @@ -286,9 +286,9 @@ static BOOL reload_interfaces(time_t t) Reload the services file. **************************************************************************** */ -static BOOL reload_nmbd_services(BOOL test) +static bool reload_nmbd_services(bool test) { - BOOL ret; + bool ret; set_remote_machine_name("nmbd", False); @@ -317,7 +317,7 @@ static BOOL reload_nmbd_services(BOOL test) /**************************************************************************** ** * React on 'smbcontrol nmbd reload-config' in the same way as to SIGHUP - * We use buf here to return BOOL result to process() when reload_interfaces() + * We use buf here to return bool result to process() when reload_interfaces() * detects that there are no subnets. **************************************************************************** */ @@ -337,7 +337,7 @@ static void msg_reload_nmbd_services(struct messaging_context *msg, /* If reload_interfaces() returned True */ /* we need to shutdown if there are no subnets... */ /* pass this info back to process() */ - *((BOOL*)data->data) = reload_interfaces(0); + *((bool *)data->data) = reload_interfaces(0); } } @@ -407,8 +407,8 @@ static void msg_nmbd_send_packet(struct messaging_context *msg, static void process(void) { - BOOL run_election; - BOOL no_subnets; + bool run_election; + bool no_subnets; while( True ) { time_t t = time(NULL); @@ -649,7 +649,7 @@ static void process(void) Open the socket communication. **************************************************************************** */ -static BOOL open_sockets(BOOL isdaemon, int port) +static bool open_sockets(bool isdaemon, int port) { /* * The sockets opened here will be used to receive broadcast @@ -693,10 +693,10 @@ static BOOL open_sockets(BOOL isdaemon, int port) int main(int argc, const char *argv[]) { pstring logfile; - static BOOL opt_interactive; + static bool opt_interactive; poptContext pc; static char *p_lmhosts = dyn_LMHOSTSFILE; - static BOOL no_process_group = False; + static bool no_process_group = False; int opt; struct poptOption long_options[] = { POPT_AUTOHELP diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index ac65917d23..8aedd2c478 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -71,7 +71,7 @@ static void remove_permanent_name_from_unicast( struct subnet_record *subrec, ******************************************************************/ static void reset_workgroup_state( struct subnet_record *subrec, const char *workgroup_name, - BOOL force_new_election ) + bool force_new_election ) { struct work_record *work; struct server_record *servrec; @@ -133,10 +133,10 @@ static void unbecome_local_master_success(struct subnet_record *subrec, struct nmb_name *released_name, struct in_addr released_ip) { - BOOL force_new_election = False; + bool force_new_election = False; unstring relname; - memcpy((char *)&force_new_election, userdata->data, sizeof(BOOL)); + memcpy((char *)&force_new_election, userdata->data, sizeof(bool)); DEBUG(3,("unbecome_local_master_success: released name %s.\n", nmb_namestr(released_name))); @@ -164,10 +164,10 @@ static void unbecome_local_master_fail(struct subnet_record *subrec, struct resp { struct name_record *namerec; struct userdata_struct *userdata = rrec->userdata; - BOOL force_new_election = False; + bool force_new_election = False; unstring failname; - memcpy((char *)&force_new_election, userdata->data, sizeof(BOOL)); + memcpy((char *)&force_new_election, userdata->data, sizeof(bool)); DEBUG(0,("unbecome_local_master_fail: failed to release name %s. \ Removing from namelist anyway.\n", nmb_namestr(fail_name))); @@ -195,7 +195,7 @@ Removing from namelist anyway.\n", nmb_namestr(fail_name))); ******************************************************************/ static void release_1d_name( struct subnet_record *subrec, const char *workgroup_name, - BOOL force_new_election) + bool force_new_election) { struct nmb_name nmbname; struct name_record *namerec; @@ -203,7 +203,7 @@ static void release_1d_name( struct subnet_record *subrec, const char *workgroup make_nmb_name(&nmbname, workgroup_name, 0x1d); if((namerec = find_name_on_subnet( subrec, &nmbname, FIND_SELF_NAME))!=NULL) { struct userdata_struct *userdata; - size_t size = sizeof(struct userdata_struct) + sizeof(BOOL); + size_t size = sizeof(struct userdata_struct) + sizeof(bool); if((userdata = (struct userdata_struct *)SMB_MALLOC(size)) == NULL) { DEBUG(0,("release_1d_name: malloc fail.\n")); @@ -212,8 +212,8 @@ static void release_1d_name( struct subnet_record *subrec, const char *workgroup userdata->copy_fn = NULL; userdata->free_fn = NULL; - userdata->userdata_len = sizeof(BOOL); - memcpy((char *)userdata->data, &force_new_election, sizeof(BOOL)); + userdata->userdata_len = sizeof(bool); + memcpy((char *)userdata->data, &force_new_election, sizeof(bool)); release_name(subrec, namerec, unbecome_local_master_success, @@ -268,7 +268,7 @@ static void release_msbrowse_name_fail( struct subnet_record *subrec, ******************************************************************/ void unbecome_local_master_browser(struct subnet_record *subrec, struct work_record *work, - BOOL force_new_election) + bool force_new_election) { struct name_record *namerec; struct nmb_name nmbname; diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index ef06ef0547..db32461f06 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -216,7 +216,7 @@ yet registered on subnet %s\n", nmb_namestr(&nmbname), subrec->subnet_name )); Determine if I win an election. ******************************************************************/ -static BOOL win_election(struct work_record *work, int version, +static bool win_election(struct work_record *work, int version, uint32 criterion, int timeup, const char *server_name) { int mytimeup = time(NULL) - StartupTime; @@ -328,10 +328,10 @@ done: be done by run_elections(). ***************************************************************************/ -BOOL check_elections(void) +bool check_elections(void) { struct subnet_record *subrec; - BOOL run_any_election = False; + bool run_any_election = False; for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { struct work_record *work; diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index ba533f4b0c..9fe344c39b 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -22,7 +22,7 @@ #include "includes.h" -extern BOOL found_lm_clients; +extern bool found_lm_clients; #if 0 diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index 292a580ef9..90773c1395 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -58,9 +58,9 @@ void process_name_release_request(struct subnet_record *subrec, struct in_addr owner_ip; struct nmb_name *question = &nmb->question.question_name; unstring qname; - BOOL bcast = nmb->header.nm_flags.bcast; + bool bcast = nmb->header.nm_flags.bcast; uint16 nb_flags = get_nb_flags(nmb->additional->rdata); - BOOL group = (nb_flags & NB_GROUP) ? True : False; + bool group = (nb_flags & NB_GROUP) ? True : False; struct name_record *namerec; int rcode = 0; @@ -153,7 +153,7 @@ void process_name_refresh_request(struct subnet_record *subrec, { struct nmb_packet *nmb = &p->packet.nmb; struct nmb_name *question = &nmb->question.question_name; - BOOL bcast = nmb->header.nm_flags.bcast; + bool bcast = nmb->header.nm_flags.bcast; struct in_addr from_ip; putip((char *)&from_ip,&nmb->additional->rdata[2]); @@ -190,9 +190,9 @@ void process_name_registration_request(struct subnet_record *subrec, { struct nmb_packet *nmb = &p->packet.nmb; struct nmb_name *question = &nmb->question.question_name; - BOOL bcast = nmb->header.nm_flags.bcast; + bool bcast = nmb->header.nm_flags.bcast; uint16 nb_flags = get_nb_flags(nmb->additional->rdata); - BOOL group = (nb_flags & NB_GROUP) ? True : False; + bool group = (nb_flags & NB_GROUP) ? True : False; struct name_record *namerec = NULL; int ttl = nmb->additional->ttl; struct in_addr from_ip; @@ -439,12 +439,12 @@ void process_name_query_request(struct subnet_record *subrec, struct packet_stru struct nmb_packet *nmb = &p->packet.nmb; struct nmb_name *question = &nmb->question.question_name; int name_type = question->name_type; - BOOL bcast = nmb->header.nm_flags.bcast; + bool bcast = nmb->header.nm_flags.bcast; int ttl=0; int rcode = 0; char *prdata = NULL; char rdata[6]; - BOOL success = False; + bool success = False; struct name_record *namerec = NULL; int reply_data_len = 0; int i; diff --git a/source3/nmbd/nmbd_lmhosts.c b/source3/nmbd/nmbd_lmhosts.c index eba7329418..8dda58e352 100644 --- a/source3/nmbd/nmbd_lmhosts.c +++ b/source3/nmbd/nmbd_lmhosts.c @@ -75,7 +75,7 @@ void load_lmhosts_file(const char *fname) subnet it will be found by normal name query processing. ****************************************************************************/ -BOOL find_name_in_lmhosts(struct nmb_name *nmbname, struct name_record **namerecp) +bool find_name_in_lmhosts(struct nmb_name *nmbname, struct name_record **namerecp) { struct name_record *namerec; diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index 8fa5439ee3..2eb376fc17 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -110,7 +110,7 @@ static void insert_refresh_name_into_unicast( struct subnet_record *subrec, Also add the magic Samba names. **************************************************************************/ -BOOL register_my_workgroup_and_names(void) +bool register_my_workgroup_and_names(void) { struct subnet_record *subrec; int i; diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 75259a3672..46a9830b25 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -97,7 +97,7 @@ void remove_name_from_namelist(struct subnet_record *subrec, struct name_record *find_name_on_subnet(struct subnet_record *subrec, const struct nmb_name *nmbname, - BOOL self_only) + bool self_only) { struct nmb_name uc_name; struct name_record *name_ret; @@ -139,7 +139,7 @@ struct name_record *find_name_on_subnet(struct subnet_record *subrec, ************************************************************************/ struct name_record *find_name_for_remote_broadcast_subnet(struct nmb_name *nmbname, - BOOL self_only) + bool self_only) { struct subnet_record *subrec; struct name_record *namerec; @@ -179,7 +179,7 @@ void update_name_ttl( struct name_record *namerec, int ttl ) Add an entry to a subnet name list. ***********************************************************************/ -BOOL add_name_to_subnet( struct subnet_record *subrec, +bool add_name_to_subnet( struct subnet_record *subrec, const char *name, int type, uint16 nb_flags, @@ -188,7 +188,7 @@ BOOL add_name_to_subnet( struct subnet_record *subrec, int num_ips, struct in_addr *iplist) { - BOOL ret = False; + bool ret = False; struct name_record *namerec; time_t time_now = time(NULL); @@ -333,7 +333,7 @@ static void remove_nth_ip_in_record( struct name_record *namerec, int ind) Utility function to check if an IP address exists in a name record. ******************************************************************/ -BOOL find_ip_in_name_record( struct name_record *namerec, struct in_addr ip ) +bool find_ip_in_name_record( struct name_record *namerec, struct in_addr ip ) { int i; diff --git a/source3/nmbd/nmbd_namequery.c b/source3/nmbd/nmbd_namequery.c index ea170d3aaa..c1c5f5238a 100644 --- a/source3/nmbd/nmbd_namequery.c +++ b/source3/nmbd/nmbd_namequery.c @@ -31,7 +31,7 @@ static void query_name_response( struct subnet_record *subrec, struct packet_struct *p) { struct nmb_packet *nmb = &p->packet.nmb; - BOOL success = False; + bool success = False; struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name; struct in_addr answer_ip; @@ -139,7 +139,7 @@ static void query_name_timeout_response(struct subnet_record *subrec, { struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb; /* We can only fail here, never succeed. */ - BOOL failed = True; + bool failed = True; struct nmb_name *question_name = &sent_nmb->question.question_name; if(rrec->num_msgs != 0) { @@ -168,7 +168,7 @@ static void query_name_timeout_response(struct subnet_record *subrec, name is not there we look for the name on the given subnet. ****************************************************************************/ -static BOOL query_local_namelists(struct subnet_record *subrec, struct nmb_name *nmbname, +static bool query_local_namelists(struct subnet_record *subrec, struct nmb_name *nmbname, struct name_record **namerecp) { struct name_record *namerec; @@ -192,7 +192,7 @@ static BOOL query_local_namelists(struct subnet_record *subrec, struct nmb_name Try and query for a name. ****************************************************************************/ -BOOL query_name(struct subnet_record *subrec, const char *name, int type, +bool query_name(struct subnet_record *subrec, const char *name, int type, query_name_success_function success_fn, query_name_fail_function fail_fn, struct userdata_struct *userdata) @@ -254,7 +254,7 @@ BOOL query_name(struct subnet_record *subrec, const char *name, int type, Try and query for a name from nmbd acting as a WINS server. ****************************************************************************/ -BOOL query_name_from_wins_server(struct in_addr ip_to, +bool query_name_from_wins_server(struct in_addr ip_to, const char *name, int type, query_name_success_function success_fn, query_name_fail_function fail_fn, diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index d781e0d89f..b7f5a3d45b 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -40,8 +40,8 @@ static void register_name_response(struct subnet_record *subrec, */ struct nmb_packet *nmb = &p->packet.nmb; - BOOL bcast = nmb->header.nm_flags.bcast; - BOOL success = True; + bool bcast = nmb->header.nm_flags.bcast; + bool success = True; struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name; struct nmb_name *answer_name = &nmb->answers->rr_name; struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb; @@ -248,8 +248,8 @@ static void register_name_timeout_response(struct subnet_record *subrec, */ struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb; - BOOL bcast = sent_nmb->header.nm_flags.bcast; - BOOL success = False; + bool bcast = sent_nmb->header.nm_flags.bcast; + bool success = False; struct nmb_name *question_name = &sent_nmb->question.question_name; uint16 nb_flags = 0; int ttl = 0; diff --git a/source3/nmbd/nmbd_namerelease.c b/source3/nmbd/nmbd_namerelease.c index cf19a3295e..4be7396f2e 100644 --- a/source3/nmbd/nmbd_namerelease.c +++ b/source3/nmbd/nmbd_namerelease.c @@ -34,8 +34,8 @@ static void release_name_response(struct subnet_record *subrec, * error. If we are releasing unicast, then we expect to get a response. */ struct nmb_packet *nmb = &p->packet.nmb; - BOOL bcast = nmb->header.nm_flags.bcast; - BOOL success = True; + bool bcast = nmb->header.nm_flags.bcast; + bool success = True; struct nmb_name *question_name = &rrec->packet->packet.nmb.question.question_name; struct nmb_name *answer_name = &nmb->answers->rr_name; struct in_addr released_ip; @@ -107,7 +107,7 @@ static void release_name_timeout_response(struct subnet_record *subrec, doesn't respond and someone else wants the name then the normal WACK/name query from the WINS server will cope */ struct nmb_packet *sent_nmb = &rrec->packet->packet.nmb; - BOOL bcast = sent_nmb->header.nm_flags.bcast; + bool bcast = sent_nmb->header.nm_flags.bcast; struct nmb_name *question_name = &sent_nmb->question.question_name; struct in_addr released_ip; @@ -150,7 +150,7 @@ static void wins_release_name(struct name_record *namerec, for (i = 0; i < namerec->data.num_ips; i++) { struct in_addr wins_ip = wins_srv_ip_tag(wins_tags[t], namerec->data.ip[i]); - BOOL last_one = ((i==namerec->data.num_ips - 1) && !wins_tags[t+1]); + bool last_one = ((i==namerec->data.num_ips - 1) && !wins_tags[t+1]); if (queue_release_name(unicast_subnet, release_name_response, release_name_timeout_response, diff --git a/source3/nmbd/nmbd_nodestatus.c b/source3/nmbd/nmbd_nodestatus.c index 8d51f13006..168ccf1ad4 100644 --- a/source3/nmbd/nmbd_nodestatus.c +++ b/source3/nmbd/nmbd_nodestatus.c @@ -77,7 +77,7 @@ static void node_status_timeout_response(struct subnet_record *subrec, Try and do a node status to a name - given the name & IP address. ****************************************************************************/ -BOOL node_status(struct subnet_record *subrec, struct nmb_name *nmbname, +bool node_status(struct subnet_record *subrec, struct nmb_name *nmbname, struct in_addr send_ip, node_status_success_function success_fn, node_status_fail_function fail_fn, struct userdata_struct *userdata) { diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index cb13febe46..b19b1d3599 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -30,7 +30,7 @@ extern int num_response_packets; static void queue_packet(struct packet_struct *packet); -BOOL rescan_listen_set = False; +bool rescan_listen_set = False; /******************************************************************* @@ -141,9 +141,9 @@ static uint16 generate_name_trn_id(void) Either loops back or sends out a completed NetBIOS packet. **************************************************************************/ -static BOOL send_netbios_packet(struct packet_struct *p) +static bool send_netbios_packet(struct packet_struct *p) { - BOOL loopback_this_packet = False; + bool loopback_this_packet = False; /* Check if we are sending to or from ourselves as a WINS server. */ if(ismyip_v4(p->ip) && (p->port == global_nmb_port)) @@ -174,7 +174,7 @@ static BOOL send_netbios_packet(struct packet_struct *p) **************************************************************************/ static struct packet_struct *create_and_init_netbios_packet(struct nmb_name *nmbname, - BOOL bcast, BOOL rec_des, + bool bcast, bool rec_des, struct in_addr to_ip) { struct packet_struct *packet = NULL; @@ -221,7 +221,7 @@ static struct packet_struct *create_and_init_netbios_packet(struct nmb_name *nmb Sets up the common elements of register, refresh or release packet. **************************************************************************/ -static BOOL create_and_init_additional_record(struct packet_struct *packet, +static bool create_and_init_additional_record(struct packet_struct *packet, uint16 nb_flags, const struct in_addr *register_ip) { @@ -269,7 +269,7 @@ static BOOL create_and_init_additional_record(struct packet_struct *packet, Sends out a name query. **************************************************************************/ -static BOOL initiate_name_query_packet( struct packet_struct *packet) +static bool initiate_name_query_packet( struct packet_struct *packet) { struct nmb_packet *nmb = NULL; @@ -291,7 +291,7 @@ static BOOL initiate_name_query_packet( struct packet_struct *packet) Sends out a name query - from a WINS server. **************************************************************************/ -static BOOL initiate_name_query_packet_from_wins_server( struct packet_struct *packet) +static bool initiate_name_query_packet_from_wins_server( struct packet_struct *packet) { struct nmb_packet *nmb = NULL; @@ -313,7 +313,7 @@ static BOOL initiate_name_query_packet_from_wins_server( struct packet_struct *p Sends out a name register. **************************************************************************/ -static BOOL initiate_name_register_packet( struct packet_struct *packet, +static bool initiate_name_register_packet( struct packet_struct *packet, uint16 nb_flags, const struct in_addr *register_ip) { struct nmb_packet *nmb = &packet->packet.nmb; @@ -337,7 +337,7 @@ static BOOL initiate_name_register_packet( struct packet_struct *packet, Sends out a multihomed name register. **************************************************************************/ -static BOOL initiate_multihomed_name_register_packet(struct packet_struct *packet, +static bool initiate_multihomed_name_register_packet(struct packet_struct *packet, uint16 nb_flags, struct in_addr *register_ip) { struct nmb_packet *nmb = &packet->packet.nmb; @@ -365,7 +365,7 @@ for name %s IP %s (bcast=%s) to IP %s\n", Sends out a name refresh. **************************************************************************/ -static BOOL initiate_name_refresh_packet( struct packet_struct *packet, +static bool initiate_name_refresh_packet( struct packet_struct *packet, uint16 nb_flags, struct in_addr *refresh_ip) { struct nmb_packet *nmb = &packet->packet.nmb; @@ -389,7 +389,7 @@ static BOOL initiate_name_refresh_packet( struct packet_struct *packet, Sends out a name release. **************************************************************************/ -static BOOL initiate_name_release_packet( struct packet_struct *packet, +static bool initiate_name_release_packet( struct packet_struct *packet, uint16 nb_flags, struct in_addr *release_ip) { struct nmb_packet *nmb = &packet->packet.nmb; @@ -413,7 +413,7 @@ static BOOL initiate_name_release_packet( struct packet_struct *packet, Sends out a node status. **************************************************************************/ -static BOOL initiate_node_status_packet( struct packet_struct *packet ) +static bool initiate_node_status_packet( struct packet_struct *packet ) { struct nmb_packet *nmb = &packet->packet.nmb; @@ -442,7 +442,7 @@ static BOOL initiate_node_status_packet( struct packet_struct *packet ) broadcast subnet. ****************************************************************************/ -static BOOL assert_check_subnet(struct subnet_record *subrec) +static bool assert_check_subnet(struct subnet_record *subrec) { if( subrec == remote_broadcast_subnet) { DEBUG(0,("assert_check_subnet: Attempt to send packet on remote broadcast subnet. \ @@ -587,7 +587,7 @@ struct response_record *queue_register_multihomed_name( struct subnet_record *su { struct packet_struct *p; struct response_record *rrec; - BOOL ret; + bool ret; /* Sanity check. */ if(subrec != unicast_subnet) { @@ -872,7 +872,7 @@ void reply_netbios_packet(struct packet_struct *orig_packet, struct nmb_packet *nmb = NULL; struct res_rec answers; struct nmb_packet *orig_nmb = &orig_packet->packet.nmb; - BOOL loopback_this_packet = False; + bool loopback_this_packet = False; int rr_type = RR_TYPE_NB; const char *packet_type = "unknown"; @@ -1179,7 +1179,7 @@ command code %d from %s IP %s to %s\n", subrec->subnet_name, command, nmb_namest stage as subsequent processing is expensive. ****************************************************************************/ -static BOOL listening(struct packet_struct *p,struct nmb_name *nbname) +static bool listening(struct packet_struct *p,struct nmb_name *nbname) { struct subnet_record *subrec = NULL; @@ -1307,9 +1307,9 @@ packet sent to name %s from IP %s\n", Validate a response nmb packet. ****************************************************************************/ -static BOOL validate_nmb_response_packet( struct nmb_packet *nmb ) +static bool validate_nmb_response_packet( struct nmb_packet *nmb ) { - BOOL ignore = False; + bool ignore = False; switch (nmb->header.opcode) { case NMB_NAME_REG_OPCODE: @@ -1358,9 +1358,9 @@ static BOOL validate_nmb_response_packet( struct nmb_packet *nmb ) Validate a request nmb packet. ****************************************************************************/ -static BOOL validate_nmb_packet( struct nmb_packet *nmb ) +static bool validate_nmb_packet( struct nmb_packet *nmb ) { - BOOL ignore = False; + bool ignore = False; switch (nmb->header.opcode) { case NMB_NAME_REG_OPCODE: @@ -1657,7 +1657,7 @@ on subnet %s\n", rrec->response_id, inet_ntoa(rrec->packet->ip), subrec->subnet_ plus the broadcast sockets. ***************************************************************************/ -static BOOL create_listen_fdset(fd_set **ppset, int **psock_array, int *listen_number, int *maxfd) +static bool create_listen_fdset(fd_set **ppset, int **psock_array, int *listen_number, int *maxfd) { int *sock_array = NULL; struct subnet_record *subrec = NULL; @@ -1729,7 +1729,7 @@ only use %d.\n", (count*2) + 2, FD_SETSIZE)); return True if the socket is dead ***************************************************************************/ -BOOL listen_for_packets(BOOL run_election) +bool listen_for_packets(bool run_election) { static fd_set *listen_set = NULL; static int listen_number = 0; @@ -1874,13 +1874,13 @@ BOOL listen_for_packets(BOOL run_election) Construct and send a netbios DGRAM. **************************************************************************/ -BOOL send_mailslot(BOOL unique, const char *mailslot,char *buf, size_t len, +bool send_mailslot(bool unique, const char *mailslot,char *buf, size_t len, const char *srcname, int src_type, const char *dstname, int dest_type, struct in_addr dest_ip,struct in_addr src_ip, int dest_port) { - BOOL loopback_this_packet = False; + bool loopback_this_packet = False; struct packet_struct p; struct dgram_packet *dgram = &p.packet.dgram; char *ptr,*p2; diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 4b5fe28d4e..feb7941cc3 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -48,7 +48,7 @@ void process_logon_packet(struct packet_struct *p, char *buf,int len, uint16 lmnttoken = 0; uint16 lm20token = 0; uint32 domainsidsize; - BOOL short_request = False; + bool short_request = False; char *getdc; char *uniuser; /* Unicode user name. */ pstring ascuser; diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index 640a1861ef..22a038ef2e 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -225,7 +225,7 @@ matching record.\n", id)); Check if a refresh is queued for a particular name on a particular subnet. **************************************************************************/ -BOOL is_refresh_already_queued(struct subnet_record *subrec, struct name_record *namerec) +bool is_refresh_already_queued(struct subnet_record *subrec, struct name_record *namerec) { struct response_record *rrec = NULL; diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index 661b68f331..6670c55bf3 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -26,7 +26,7 @@ #include "includes.h" extern int updatecount; -extern BOOL found_lm_clients; +extern bool found_lm_clients; /**************************************************************************** Send a browser reset packet. diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index 9bd80b7270..5ac4888365 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -288,7 +288,7 @@ void write_browse_list_entry(XFILE *fp, const char *name, uint32 rec_type, x_fprintf(fp, "\"%s\"\n", description); } -void write_browse_list(time_t t, BOOL force_write) +void write_browse_list(time_t t, bool force_write) { struct subnet_record *subrec; struct work_record *work; @@ -297,7 +297,7 @@ void write_browse_list(time_t t, BOOL force_write) uint32 stype; int i; XFILE *fp; - BOOL list_changed = force_write; + bool list_changed = force_write; static time_t lasttime = 0; /* Always dump if we're being told to by a signal. */ diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 7fd241cf62..39aa4577bb 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -188,7 +188,7 @@ struct subnet_record *make_normal_subnet(const struct interface *iface) Create subnet entries. **************************************************************************/ -BOOL create_subnets(void) +bool create_subnets(void) { /* We only count IPv4 interfaces whilst we're waiting. */ int num_interfaces = iface_count_v4(); @@ -323,7 +323,7 @@ BOOL create_subnets(void) Function to tell us if we can use the unicast subnet. ******************************************************************/ -BOOL we_are_a_wins_client(void) +bool we_are_a_wins_client(void) { if (wins_srv_count() > 0) { return True; diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 6b716bdf35..df71e6db43 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -63,7 +63,7 @@ static void callback(const char *sname, uint32 stype, static void sync_child(char *name, int nm_type, char *workgroup, - struct in_addr ip, BOOL local, BOOL servers, + struct in_addr ip, bool local, bool servers, char *fname) { fstring unix_workgroup; @@ -141,7 +141,7 @@ static void sync_child(char *name, int nm_type, void sync_browse_lists(struct work_record *work, char *name, int nm_type, - struct in_addr ip, BOOL local, BOOL servers) + struct in_addr ip, bool local, bool servers) { struct sync_record *s; static int counter; diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 66c060f652..38962c2b39 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -207,7 +207,7 @@ static TDB_DATA name_to_key(const struct nmb_name *nmbname) on the linked list. We will free this later in XXXX(). *****************************************************************************/ -struct name_record *find_name_on_wins_subnet(const struct nmb_name *nmbname, BOOL self_only) +struct name_record *find_name_on_wins_subnet(const struct nmb_name *nmbname, bool self_only) { TDB_DATA data, key; struct name_record *nr = NULL; @@ -262,7 +262,7 @@ struct name_record *find_name_on_wins_subnet(const struct nmb_name *nmbname, BOO Overwrite or add a given name in the wins.tdb. *****************************************************************************/ -static BOOL store_or_replace_wins_namerec(const struct name_record *namerec, int tdb_flag) +static bool store_or_replace_wins_namerec(const struct name_record *namerec, int tdb_flag) { TDB_DATA key, data; int ret; @@ -288,7 +288,7 @@ static BOOL store_or_replace_wins_namerec(const struct name_record *namerec, int Overwrite a given name in the wins.tdb. *****************************************************************************/ -BOOL wins_store_changed_namerec(const struct name_record *namerec) +bool wins_store_changed_namerec(const struct name_record *namerec) { return store_or_replace_wins_namerec(namerec, TDB_REPLACE); } @@ -297,7 +297,7 @@ BOOL wins_store_changed_namerec(const struct name_record *namerec) Primary interface into creating and overwriting records in the wins.tdb. *****************************************************************************/ -BOOL add_name_to_wins_subnet(const struct name_record *namerec) +bool add_name_to_wins_subnet(const struct name_record *namerec) { return store_or_replace_wins_namerec(namerec, TDB_INSERT); } @@ -307,7 +307,7 @@ BOOL add_name_to_wins_subnet(const struct name_record *namerec) on the linked list. *****************************************************************************/ -BOOL remove_name_from_wins_namelist(struct name_record *namerec) +bool remove_name_from_wins_namelist(struct name_record *namerec) { TDB_DATA key; int ret; @@ -412,7 +412,7 @@ static void update_wins_flag(struct name_record *namerec, int flags) Return the general ID value and increase it if requested. *****************************************************************************/ -static void get_global_id_and_update(SMB_BIG_UINT *current_id, BOOL update) +static void get_global_id_and_update(SMB_BIG_UINT *current_id, bool update) { /* * it's kept as a static here, to prevent people from messing @@ -482,7 +482,7 @@ static void wins_hook(const char *operation, struct name_record *namerec, int tt Determine if this packet should be allocated to the WINS server. *****************************************************************************/ -BOOL packet_is_for_wins_server(struct packet_struct *packet) +bool packet_is_for_wins_server(struct packet_struct *packet) { struct nmb_packet *nmb = &packet->packet.nmb; @@ -562,7 +562,7 @@ static int get_ttl_from_packet(struct nmb_packet *nmb) Load or create the WINS database. *****************************************************************************/ -BOOL initialise_wins(void) +bool initialise_wins(void) { time_t time_now = time(NULL); XFILE *fp; @@ -600,8 +600,8 @@ BOOL initialise_wins(void) int ttl; const char *ptr; char *p; - BOOL got_token; - BOOL was_ip; + bool got_token; + bool was_ip; int i; unsigned int hash; int version; @@ -804,9 +804,9 @@ void wins_process_name_refresh_request( struct subnet_record *subrec, { struct nmb_packet *nmb = &p->packet.nmb; struct nmb_name *question = &nmb->question.question_name; - BOOL bcast = nmb->header.nm_flags.bcast; + bool bcast = nmb->header.nm_flags.bcast; uint16 nb_flags = get_nb_flags(nmb->additional->rdata); - BOOL group = (nb_flags & NB_GROUP) ? True : False; + bool group = (nb_flags & NB_GROUP) ? True : False; struct name_record *namerec = NULL; int ttl = get_ttl_from_packet(nmb); struct in_addr from_ip; @@ -1110,12 +1110,12 @@ void wins_process_name_registration_request(struct subnet_record *subrec, unstring name; struct nmb_packet *nmb = &p->packet.nmb; struct nmb_name *question = &nmb->question.question_name; - BOOL bcast = nmb->header.nm_flags.bcast; + bool bcast = nmb->header.nm_flags.bcast; uint16 nb_flags = get_nb_flags(nmb->additional->rdata); int ttl = get_ttl_from_packet(nmb); struct name_record *namerec = NULL; struct in_addr from_ip; - BOOL registering_group_name = (nb_flags & NB_GROUP) ? True : False; + bool registering_group_name = (nb_flags & NB_GROUP) ? True : False; struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); putip((char *)&from_ip,&nmb->additional->rdata[2]); @@ -1480,12 +1480,12 @@ void wins_process_multihomed_name_registration_request( struct subnet_record *su { struct nmb_packet *nmb = &p->packet.nmb; struct nmb_name *question = &nmb->question.question_name; - BOOL bcast = nmb->header.nm_flags.bcast; + bool bcast = nmb->header.nm_flags.bcast; uint16 nb_flags = get_nb_flags(nmb->additional->rdata); int ttl = get_ttl_from_packet(nmb); struct name_record *namerec = NULL; struct in_addr from_ip; - BOOL group = (nb_flags & NB_GROUP) ? True : False; + bool group = (nb_flags & NB_GROUP) ? True : False; struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); unstring qname; @@ -1994,11 +1994,11 @@ void wins_process_name_release_request(struct subnet_record *subrec, { struct nmb_packet *nmb = &p->packet.nmb; struct nmb_name *question = &nmb->question.question_name; - BOOL bcast = nmb->header.nm_flags.bcast; + bool bcast = nmb->header.nm_flags.bcast; uint16 nb_flags = get_nb_flags(nmb->additional->rdata); struct name_record *namerec = NULL; struct in_addr from_ip; - BOOL releasing_group_name = (nb_flags & NB_GROUP) ? True : False;; + bool releasing_group_name = (nb_flags & NB_GROUP) ? True : False;; putip((char *)&from_ip,&nmb->additional->rdata[2]); @@ -2110,7 +2110,7 @@ release name %s as this record is not active anymore.\n", nmb_namestr(question) static int wins_processing_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state) { time_t t = *(time_t *)state; - BOOL store_record = False; + bool store_record = False; struct name_record *namerec = NULL; struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); @@ -2302,7 +2302,7 @@ static int wins_writedb_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA db } -void wins_write_database(time_t t, BOOL background) +void wins_write_database(time_t t, bool background) { static time_t last_write_time = 0; pstring fname, fnamenew; @@ -2380,7 +2380,7 @@ void nmbd_wins_new_entry(struct messaging_context *msg, struct name_record *namerec = NULL; struct name_record *new_namerec = NULL; struct nmb_name question; - BOOL overwrite=False; + bool overwrite=False; struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); int i; diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index 82c3a31669..1845401d9e 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -269,7 +269,7 @@ on subnet %s\n", name, subrec->subnet_name)); Dump a copy of the workgroup database into the log file. **************************************************************************/ -void dump_workgroups(BOOL force_write) +void dump_workgroups(bool force_write) { struct subnet_record *subrec; int debuglevel = force_write ? 0 : 4; -- cgit From 7f82fbad50906866bbb6c0950795644f1c18b099 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Fri, 19 Oct 2007 10:34:06 +0200 Subject: fix startup of smbd, nmbd, winbindd jra: POPT_ARG_VAL arguments need int values. I assume there're more places like this in the cmdline tools. Please fix this properly, as my commit is just a hack to get make test working again. in samba4 we have a workaround for this see smbd/server.c metze (This used to be commit 9cb1937fe8601e526b5c924930500e0a3b52abd5) --- source3/nmbd/nmbd.c | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 46808f51de..510e676e33 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -31,15 +31,6 @@ extern bool global_in_nmbd; extern bool override_logfile; -/* are we running as a daemon ? */ -static bool is_daemon; - -/* fork or run in foreground ? */ -static bool Fork = True; - -/* log to standard output ? */ -static bool log_stdout; - /* have we found LanMan clients yet? */ bool found_lm_clients = False; @@ -692,11 +683,14 @@ static bool open_sockets(bool isdaemon, int port) **************************************************************************** */ int main(int argc, const char *argv[]) { + static int is_daemon; + static int Fork = True; + static int log_stdout; pstring logfile; - static bool opt_interactive; + static int opt_interactive; poptContext pc; static char *p_lmhosts = dyn_LMHOSTSFILE; - static bool no_process_group = False; + static int no_process_group = False; int opt; struct poptOption long_options[] = { POPT_AUTOHELP -- cgit From 9a85533914119fb995fb61555c9f6e0018d4d181 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 19 Oct 2007 11:38:36 -0700 Subject: Fix the popt / bool issues. Some places we used BOOL where we meant int. Fix this. Thanks to metze for pointing this out. Jeremy. (This used to be commit 793a9d24a163cb6cf5a3a0aa5ae30e9f8cf4744a) --- source3/nmbd/nmbd.c | 41 ++++++++++++++++++++++++++++++++--------- 1 file changed, 32 insertions(+), 9 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 510e676e33..69117ee4ea 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -681,23 +681,31 @@ static bool open_sockets(bool isdaemon, int port) /**************************************************************************** ** main program **************************************************************************** */ + int main(int argc, const char *argv[]) { - static int is_daemon; - static int Fork = True; - static int log_stdout; + static bool is_daemon; + static bool opt_interactive; + static bool Fork = true; + static bool no_process_group; + static bool log_stdout; pstring logfile; - static int opt_interactive; poptContext pc; static char *p_lmhosts = dyn_LMHOSTSFILE; - static int no_process_group = False; int opt; + enum { + OPT_DAEMON = 1000, + OPT_INTERACTIVE, + OPT_FORK, + OPT_NO_PROCESS_GROUP, + OPT_LOG_STDOUT + }; struct poptOption long_options[] = { POPT_AUTOHELP - {"daemon", 'D', POPT_ARG_VAL, &is_daemon, True, "Become a daemon(default)" }, - {"interactive", 'i', POPT_ARG_VAL, &opt_interactive, True, "Run interactive (not a daemon)" }, - {"foreground", 'F', POPT_ARG_VAL, &Fork, False, "Run daemon in foreground (for daemontools & etc)" }, - {"no-process-group", 0, POPT_ARG_VAL, &no_process_group, True, "Don't create a new process group" }, + {"daemon", 'D', POPT_ARG_NONE, NULL, OPT_DAEMON, "Become a daemon(default)" }, + {"interactive", 'i', POPT_ARG_NONE, NULL, OPT_INTERACTIVE, "Run interactive (not a daemon)" }, + {"foreground", 'F', POPT_ARG_NONE, NULL, OPT_FORK, "Run daemon in foreground (for daemontools & etc)" }, + {"no-process-group", 0, POPT_ARG_NONE, NULL, OPT_NO_PROCESS_GROUP, "Don't create a new process group" }, {"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" }, {"hosts", 'H', POPT_ARG_STRING, &p_lmhosts, 'H', "Load a netbios hosts file"}, {"port", 'p', POPT_ARG_INT, &global_nmb_port, NMB_PORT, "Listen on the specified port" }, @@ -712,6 +720,21 @@ static bool open_sockets(bool isdaemon, int port) pc = poptGetContext("nmbd", argc, argv, long_options, 0); while ((opt = poptGetNextOpt(pc)) != -1) { switch (opt) { + case OPT_DAEMON: + is_daemon = true; + break; + case OPT_INTERACTIVE: + opt_interactive = true; + break; + case OPT_FORK: + Fork = false; + break; + case OPT_NO_PROCESS_GROUP: + no_process_group = true; + break; + case OPT_LOG_STDOUT: + log_stdout = true; + break; default: d_fprintf(stderr, "\nInvalid option %s: %s\n\n", poptBadOption(pc, 0), poptStrerror(opt)); -- cgit From 669d43af3159ad6be3e43361b2b40e3284821238 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 20 Oct 2007 10:12:55 +0200 Subject: fix move to OPT_LOG_STDOUT metze (This used to be commit 97f47e39139cef738a5f02980a0792417e0d365e) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 69117ee4ea..fe69587a4b 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -706,7 +706,7 @@ static bool open_sockets(bool isdaemon, int port) {"interactive", 'i', POPT_ARG_NONE, NULL, OPT_INTERACTIVE, "Run interactive (not a daemon)" }, {"foreground", 'F', POPT_ARG_NONE, NULL, OPT_FORK, "Run daemon in foreground (for daemontools & etc)" }, {"no-process-group", 0, POPT_ARG_NONE, NULL, OPT_NO_PROCESS_GROUP, "Don't create a new process group" }, - {"log-stdout", 'S', POPT_ARG_VAL, &log_stdout, True, "Log to stdout" }, + {"log-stdout", 'S', POPT_ARG_NONE, NULL, OPT_LOG_STDOUT, "Log to stdout" }, {"hosts", 'H', POPT_ARG_STRING, &p_lmhosts, 'H', "Load a netbios hosts file"}, {"port", 'p', POPT_ARG_INT, &global_nmb_port, NMB_PORT, "Listen on the specified port" }, POPT_COMMON_SAMBA -- cgit From f88b7a076be74a29a3bf876b4e2705f4a1ecf42b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 24 Oct 2007 14:16:54 -0700 Subject: This is a large patch (sorry). Migrate from struct in_addr to struct sockaddr_storage in most places that matter (ie. not the nmbd and NetBIOS lookups). This passes make test on an IPv4 box, but I'll have to do more work/testing on IPv6 enabled boxes. This should now give us a framework for testing and finishing the IPv6 migration. It's at the state where someone with a working IPv6 setup should (theorecically) be able to type : smbclient //ipv6-address/share and have it work. Jeremy. (This used to be commit 98e154c3125d5732c37a72d74b0eb5cd7b6155fd) --- source3/nmbd/nmbd.c | 65 ++++++++++++++++++++++++++-------------- source3/nmbd/nmbd_become_dmb.c | 2 +- source3/nmbd/nmbd_browsesync.c | 2 +- source3/nmbd/nmbd_lmhosts.c | 11 +++++-- source3/nmbd/nmbd_namelistdb.c | 4 +-- source3/nmbd/nmbd_nameregister.c | 2 +- source3/nmbd/nmbd_packets.c | 4 +-- source3/nmbd/nmbd_subnetdb.c | 8 +++-- source3/nmbd/nmbd_synclists.c | 4 ++- source3/nmbd/nmbd_winsserver.c | 24 +++++++-------- 10 files changed, 80 insertions(+), 46 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index fe69587a4b..c6be4914da 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -210,21 +210,22 @@ static bool reload_interfaces(time_t t) if (is_loopback_addr(&iface->ip)) { DEBUG(2,("reload_interfaces: Ignoring loopback " "interface %s\n", - print_sockaddr(str, sizeof(str), - &iface->ip, sizeof(iface->ip)) )); + print_sockaddr(str, sizeof(str), &iface->ip) )); continue; } for (subrec=subnetlist; subrec; subrec=subrec->next) { - if (ip_equal(ip, subrec->myip) && - ip_equal(nmask, subrec->mask_ip)) break; + if (ip_equal_v4(ip, subrec->myip) && + ip_equal_v4(nmask, subrec->mask_ip)) { + break; + } } if (!subrec) { /* it wasn't found! add it */ - DEBUG(2,("Found new interface %s\n", - print_sockaddr(str, sizeof(str), - &iface->ip, sizeof(iface->ip)) )); + DEBUG(2,("Found new interface %s\n", + print_sockaddr(str, + sizeof(str), &iface->ip) )); subrec = make_normal_subnet(iface); if (subrec) register_my_workgroup_one_subnet(subrec); @@ -247,8 +248,10 @@ static bool reload_interfaces(time_t t) } ip = ((struct sockaddr_in *)&iface->ip)->sin_addr; nmask = ((struct sockaddr_in *)&iface->netmask)->sin_addr; - if (ip_equal(ip, subrec->myip) && - ip_equal(nmask, subrec->mask_ip)) break; + if (ip_equal_v4(ip, subrec->myip) && + ip_equal_v4(nmask, subrec->mask_ip)) { + break; + } } if (n == -1) { /* oops, an interface has disapeared. This is @@ -257,12 +260,12 @@ static bool reload_interfaces(time_t t) instead we just wear the memory leak and remove it from the list of interfaces without freeing it */ - DEBUG(2,("Deleting dead interface %s\n", + DEBUG(2,("Deleting dead interface %s\n", inet_ntoa(subrec->myip))); close_subnet(subrec); } } - + rescan_listen_set = True; /* We need to shutdown if there are no subnets... */ @@ -376,7 +379,7 @@ static void msg_nmbd_send_packet(struct messaging_context *msg, for (subrec = FIRST_SUBNET; subrec != NULL; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { - if (ip_equal(*local_ip, subrec->myip)) { + if (ip_equal_v4(*local_ip, subrec->myip)) { p->fd = (p->packet_type == NMB_PACKET) ? subrec->nmb_sock : subrec->dgram_sock; break; @@ -642,6 +645,9 @@ static void process(void) static bool open_sockets(bool isdaemon, int port) { + struct sockaddr_storage ss; + const char *sock_addr = lp_socket_address(); + /* * The sockets opened here will be used to receive broadcast * packets *only*. Interface specific sockets are opened in @@ -650,19 +656,34 @@ static bool open_sockets(bool isdaemon, int port) * now deprecated. */ - if ( isdaemon ) + if (!interpret_string_addr(&ss, sock_addr, + AI_NUMERICHOST|AI_PASSIVE)) { + DEBUG(0,("open_sockets: unable to get socket address " + "from string %s", sock_addr)); + return false; + } + if (ss.ss_family != AF_INET) { + DEBUG(0,("open_sockets: unable to use IPv6 socket" + "%s in nmbd\n", + sock_addr)); + return false; + } + + if (isdaemon) { ClientNMB = open_socket_in(SOCK_DGRAM, port, - 0, interpret_addr(lp_socket_address()), - True); - else + 0, &ss, + true); + } else { ClientNMB = 0; - + } + ClientDGRAM = open_socket_in(SOCK_DGRAM, DGRAM_PORT, - 3, interpret_addr(lp_socket_address()), - True); + 3, &ss, + true); - if ( ClientNMB == -1 ) - return( False ); + if (ClientNMB == -1) { + return false; + } /* we are never interested in SIGPIPE */ BlockSignals(True,SIGPIPE); @@ -744,7 +765,7 @@ static bool open_sockets(bool isdaemon, int port) }; poptFreeContext(pc); - global_in_nmbd = True; + global_in_nmbd = true; StartupTime = time(NULL); diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index fb87927436..a0b2ef15f8 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -219,7 +219,7 @@ static void become_domain_master_query_success(struct subnet_record *subrec, allones_ip.s_addr = htonl(INADDR_BROADCAST); - if(ismyip_v4(ip) || ip_equal(allones_ip, ip) || is_zero_ip_v4(ip)) { + if(ismyip_v4(ip) || ip_equal_v4(allones_ip, ip) || is_zero_ip_v4(ip)) { if( DEBUGLVL( 3 ) ) { dbgtext( "become_domain_master_query_success():\n" ); dbgtext( "Our address (%s) ", inet_ntoa(ip) ); diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index e141b3e288..4effce0722 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -291,7 +291,7 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec, /* First check if we already have a dmb for this workgroup. */ - if(!is_zero_ip_v4(work->dmb_addr) && ip_equal(work->dmb_addr, answer_ip)) { + if(!is_zero_ip_v4(work->dmb_addr) && ip_equal_v4(work->dmb_addr, answer_ip)) { /* Do the local master browser announcement to the domain master browser name and IP. */ announce_local_master_browser_to_domain_master_browser( work ); diff --git a/source3/nmbd/nmbd_lmhosts.c b/source3/nmbd/nmbd_lmhosts.c index 8dda58e352..51e4858f32 100644 --- a/source3/nmbd/nmbd_lmhosts.c +++ b/source3/nmbd/nmbd_lmhosts.c @@ -32,7 +32,7 @@ void load_lmhosts_file(const char *fname) { pstring name; int name_type; - struct in_addr ipaddr; + struct sockaddr_storage ss; XFILE *fp = startlmhosts( fname ); if (!fp) { @@ -41,10 +41,17 @@ void load_lmhosts_file(const char *fname) return; } - while (getlmhostsent(fp, name, &name_type, &ipaddr) ) { + while (getlmhostsent(fp, name, &name_type, &ss) ) { + struct in_addr ipaddr; struct subnet_record *subrec = NULL; enum name_source source = LMHOSTS_NAME; + if (ss.ss_family != AF_INET) { + continue; + } + + ipaddr = ((struct sockaddr_in *)&ss)->sin_addr; + /* We find a relevent subnet to put this entry on, then add it. */ /* Go through all the broadcast subnets and see if the mask matches. */ for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index 46a9830b25..ae5f766e66 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -338,7 +338,7 @@ bool find_ip_in_name_record( struct name_record *namerec, struct in_addr ip ) int i; for(i = 0; i < namerec->data.num_ips; i++) { - if(ip_equal( namerec->data.ip[i], ip)) { + if(ip_equal_v4( namerec->data.ip[i], ip)) { return True; } } @@ -391,7 +391,7 @@ void remove_ip_from_name_record( struct name_record *namerec, int orig_num = namerec->data.num_ips; for(i = 0; i < orig_num; i++) { - if( ip_equal( remove_ip, namerec->data.ip[i]) ) { + if( ip_equal_v4( remove_ip, namerec->data.ip[i]) ) { remove_nth_ip_in_record( namerec, i); break; } diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index b7f5a3d45b..edcf258519 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -361,7 +361,7 @@ static void wins_next_registration(struct response_record *rrec) tag = (const char *)userdata->data; for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { - if (ip_equal(last_ip, subrec->myip)) { + if (ip_equal_v4(last_ip, subrec->myip)) { subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec); break; } diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index b19b1d3599..d49c8bab79 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -50,7 +50,7 @@ static int find_subnet_fd_for_address( struct in_addr local_ip ) struct subnet_record *subrec; for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - if(ip_equal(local_ip, subrec->myip)) + if(ip_equal_v4(local_ip, subrec->myip)) return subrec->nmb_sock; return ClientNMB; @@ -65,7 +65,7 @@ static int find_subnet_mailslot_fd_for_address( struct in_addr local_ip ) struct subnet_record *subrec; for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) - if(ip_equal(local_ip, subrec->myip)) + if(ip_equal_v4(local_ip, subrec->myip)) return subrec->dgram_sock; return ClientDGRAM; diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index 39aa4577bb..d100ad482a 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -85,13 +85,17 @@ static struct subnet_record *make_subnet(const char *name, enum subnet_type type nmb_sock = -1; dgram_sock = -1; } else { + struct sockaddr_storage ss; + + in_addr_to_sockaddr_storage(&ss, myip); + /* * Attempt to open the sockets on port 137/138 for this interface * and bind them. * Fail the subnet creation if this fails. */ - if((nmb_sock = open_socket_in(SOCK_DGRAM, global_nmb_port,0, myip.s_addr,True)) == -1) { + if((nmb_sock = open_socket_in(SOCK_DGRAM, global_nmb_port,0, &ss,true)) == -1) { if( DEBUGLVL( 0 ) ) { Debug1( "nmbd_subnetdb:make_subnet()\n" ); Debug1( " Failed to open nmb socket on interface %s ", inet_ntoa(myip) ); @@ -101,7 +105,7 @@ static struct subnet_record *make_subnet(const char *name, enum subnet_type type return NULL; } - if((dgram_sock = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3, myip.s_addr,True)) == -1) { + if((dgram_sock = open_socket_in(SOCK_DGRAM,DGRAM_PORT,3, &ss, true)) == -1) { if( DEBUGLVL( 0 ) ) { Debug1( "nmbd_subnetdb:make_subnet()\n" ); Debug1( " Failed to open dgram socket on interface %s ", inet_ntoa(myip) ); diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index df71e6db43..aaa56f9216 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -70,6 +70,7 @@ static void sync_child(char *name, int nm_type, struct cli_state *cli; uint32 local_type = local ? SV_TYPE_LOCAL_LIST_ONLY : 0; struct nmb_name called, calling; + struct sockaddr_storage ss; NTSTATUS status; /* W2K DMB's return empty browse lists on port 445. Use 139. @@ -85,7 +86,8 @@ static void sync_child(char *name, int nm_type, return; } - status = cli_connect(cli, name, &ip); + in_addr_to_sockaddr_storage(&ss, ip); + status = cli_connect(cli, name, &ss); if (!NT_STATUS_IS_OK(status)) { return; } diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 38962c2b39..70303af48b 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -914,7 +914,7 @@ void wins_process_name_refresh_request( struct subnet_record *subrec, * if the record is a replica: * we take ownership and update the version ID. */ - if (!ip_equal(namerec->data.wins_ip, our_fake_ip)) { + if (!ip_equal_v4(namerec->data.wins_ip, our_fake_ip)) { update_wins_owner(namerec, our_fake_ip); get_global_id_and_update(&namerec->data.id, True); } @@ -1030,7 +1030,7 @@ static void wins_register_query_fail(struct subnet_record *subrec, namerec = find_name_on_subnet(subrec, question_name, FIND_ANY_NAME); if ((namerec != NULL) && (namerec->data.source == REGISTER_NAME) && - ip_equal(rrec->packet->ip, *namerec->data.ip)) { + ip_equal_v4(rrec->packet->ip, *namerec->data.ip)) { remove_name_from_namelist( subrec, namerec); namerec = NULL; } @@ -1304,8 +1304,8 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio if( !registering_group_name && (namerec != NULL) && (namerec->data.num_ips == 1) - && ip_equal( namerec->data.ip[0], from_ip ) - && ip_equal(namerec->data.wins_ip, our_fake_ip) ) { + && ip_equal_v4( namerec->data.ip[0], from_ip ) + && ip_equal_v4(namerec->data.wins_ip, our_fake_ip) ) { update_name_ttl( namerec, ttl ); wins_hook("refresh", namerec, ttl); send_wins_name_registration_response( 0, ttl, p ); @@ -1633,7 +1633,7 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio * If it's a replica, we need to become the wins owner * to force the replication */ - if (!ip_equal(namerec->data.wins_ip, our_fake_ip)) { + if (!ip_equal_v4(namerec->data.wins_ip, our_fake_ip)) { get_global_id_and_update(&namerec->data.id, True); update_wins_owner(namerec, our_fake_ip); update_wins_flag(namerec, WINS_ACTIVE); @@ -2138,7 +2138,7 @@ static int wins_processing_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA } /* handle records, samba is the wins owner */ - if (ip_equal(namerec->data.wins_ip, our_fake_ip)) { + if (ip_equal_v4(namerec->data.wins_ip, our_fake_ip)) { switch (namerec->data.wins_flags & WINS_STATE_MASK) { case WINS_ACTIVE: namerec->data.wins_flags&=~WINS_STATE_MASK; @@ -2424,16 +2424,16 @@ void nmbd_wins_new_entry(struct messaging_context *msg, if (namerec->data.wins_flags&WINS_UNIQUE && record->wins_flags&WINS_UNIQUE) { /* the database record is a replica */ - if (!ip_equal(namerec->data.wins_ip, our_fake_ip)) { + if (!ip_equal_v4(namerec->data.wins_ip, our_fake_ip)) { if (namerec->data.wins_flags&WINS_ACTIVE && record->wins_flags&WINS_TOMBSTONED) { - if (ip_equal(namerec->data.wins_ip, record->wins_ip)) + if (ip_equal_v4(namerec->data.wins_ip, record->wins_ip)) overwrite=True; } else overwrite=True; } else { /* we are the wins owner of the database record */ /* the 2 records have the same IP address */ - if (ip_equal(namerec->data.ip[0], record->ip[0])) { + if (ip_equal_v4(namerec->data.ip[0], record->ip[0])) { if (namerec->data.wins_flags&WINS_ACTIVE && record->wins_flags&WINS_TOMBSTONED) get_global_id_and_update(&namerec->data.id, True); else @@ -2485,10 +2485,10 @@ void nmbd_wins_new_entry(struct messaging_context *msg, overwrite=True; } else { - if (ip_equal(record->wins_ip, namerec->data.wins_ip)) + if (ip_equal_v4(record->wins_ip, namerec->data.wins_ip)) overwrite=True; - if (ip_equal(namerec->data.wins_ip, our_fake_ip)) + if (ip_equal_v4(namerec->data.wins_ip, our_fake_ip)) if (namerec->data.wins_flags&WINS_UNIQUE) get_global_id_and_update(&namerec->data.id, True); @@ -2497,7 +2497,7 @@ void nmbd_wins_new_entry(struct messaging_context *msg, if (record->wins_flags&WINS_ACTIVE && namerec->data.wins_flags&WINS_ACTIVE) if (namerec->data.wins_flags&WINS_UNIQUE || namerec->data.wins_flags&WINS_MHOMED) - if (ip_equal(record->wins_ip, namerec->data.wins_ip)) + if (ip_equal_v4(record->wins_ip, namerec->data.wins_ip)) overwrite=True; } -- cgit From 851ef9e22f5f58202b0c5594b4432941afb0e130 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 30 Oct 2007 15:44:27 +0100 Subject: start smbd, nmbd and winbindd with the same startup message at debug level 0. metze (This used to be commit 95f76ae7a52c6b22db22d03fed6b0848d2a61bee) --- source3/nmbd/nmbd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index c6be4914da..6fadefe682 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -812,8 +812,8 @@ static bool open_sockets(bool isdaemon, int port) reopen_logs(); - DEBUG( 0, ( "Netbios nameserver version %s started.\n", SAMBA_VERSION_STRING) ); - DEBUGADD( 0, ( "%s\n", COPYRIGHT_STARTUP_MESSAGE ) ); + DEBUG(0,("nmbd version %s started.\n", SAMBA_VERSION_STRING)); + DEBUGADD(0,("%s\n", COPYRIGHT_STARTUP_MESSAGE)); if ( !reload_nmbd_services(False) ) return(-1); -- cgit From 88ee61625a5de5e443d14c54eab91a90d87cda85 Mon Sep 17 00:00:00 2001 From: "Gerald (Jerry) Carter" Date: Thu, 1 Nov 2007 15:53:44 -0400 Subject: Patch 2 of 3 from Debian Samba packagers: The point is doing the following associations: - non discardable state data (all TDB files that may need to be backed up) go to statedir - shared data (codepage stuff) go to codepagedir The patch *does not change* the default location for these directories. So, there is no behaviour change when applying it. The main change is for samba developers who have to think when dealing with files that previously pertained to libdir whether they: - go in statedir - go in codepagedir - stay in libdir (This used to be commit d6cdbfd875bb2653e831d314726c3240beb0a96b) --- source3/nmbd/nmbd_winsserver.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 70303af48b..736bbf4068 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -584,7 +584,7 @@ bool initialise_wins(void) add_samba_names_to_subnet(wins_server_subnet); - if((fp = x_fopen(lock_path(WINS_LIST),O_RDONLY,0)) == NULL) { + if((fp = x_fopen(state_path(WINS_LIST),O_RDONLY,0)) == NULL) { DEBUG(2,("initialise_wins: Can't open wins database file %s. Error was %s\n", WINS_LIST, strerror(errno) )); return True; @@ -2337,7 +2337,7 @@ void wins_write_database(time_t t, bool background) } } - slprintf(fname,sizeof(fname)-1,"%s/%s", lp_lockdir(), WINS_LIST); + slprintf(fname,sizeof(fname)-1,"%s/%s", dyn_STATEDIR(), WINS_LIST); all_string_sub(fname,"//", "/", 0); slprintf(fnamenew,sizeof(fnamenew)-1,"%s.%u", fname, (unsigned int)sys_getpid()); -- cgit From 51a0354d751f48a2542984c81e218da33669bbeb Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Sat, 3 Nov 2007 22:34:46 -0700 Subject: Remove more static data from lib/util_sock.c and callers. Jeremy. (This used to be commit 35aaa36f82c70964cee5d0778eb04547b226dd3f) --- source3/nmbd/nmbd_mynames.c | 5 +++-- source3/nmbd/nmbd_sendannounce.c | 4 ++-- source3/nmbd/nmbd_winsserver.c | 22 ++++++++++++++-------- 3 files changed, 19 insertions(+), 12 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index 2eb376fc17..62c8dd0cf0 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -162,12 +162,13 @@ bool register_my_workgroup_and_names(void) for(subrec = FIRST_SUBNET; subrec; subrec = subrec->next) { for (n=0;nsubnet_name )); for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) { /* The entries are of the form a.b.c.d */ - addr = *interpret_addr2(s2); + (void)interpret_addr2(&addr,s2); DEBUG(5,("announce_remote: Doing remote browse sync announce for server %s to IP %s.\n", global_myname(), inet_ntoa(addr) )); diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 736bbf4068..d4a2c8346e 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -680,7 +680,7 @@ bool initialise_wins(void) next_token(&ptr,ttl_str,NULL,sizeof(ttl_str)); for(i = 0; i < num_ips; i++) { next_token(&ptr, ip_str, NULL, sizeof(ip_str)); - ip_list[i] = *interpret_addr2(ip_str); + (void)interpret_addr2(&ip_list[i], ip_str); } next_token(&ptr,nb_flags_str,NULL, sizeof(nb_flags_str)); @@ -810,8 +810,9 @@ void wins_process_name_refresh_request( struct subnet_record *subrec, struct name_record *namerec = NULL; int ttl = get_ttl_from_packet(nmb); struct in_addr from_ip; - struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); + struct in_addr our_fake_ip; + (void)interpret_addr2(&our_fake_ip, "0.0.0.0"); putip( (char *)&from_ip, &nmb->additional->rdata[2] ); if(bcast) { @@ -1116,8 +1117,9 @@ void wins_process_name_registration_request(struct subnet_record *subrec, struct name_record *namerec = NULL; struct in_addr from_ip; bool registering_group_name = (nb_flags & NB_GROUP) ? True : False; - struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); + struct in_addr our_fake_ip; + (void)interpret_addr2(&our_fake_ip, "0.0.0.0"); putip((char *)&from_ip,&nmb->additional->rdata[2]); if(bcast) { @@ -1192,7 +1194,7 @@ to register name %s. Name already exists in WINS with source type %d.\n", */ if(registering_group_name && (question->name_type != 0x1c)) { - from_ip = *interpret_addr2("255.255.255.255"); + (void)interpret_addr2(&from_ip, "255.255.255.255"); } /* @@ -1397,8 +1399,9 @@ static void wins_multihomed_register_query_success(struct subnet_record *subrec, struct name_record *namerec = NULL; struct in_addr from_ip; int ttl; - struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); + struct in_addr our_fake_ip; + (void)interpret_addr2(&our_fake_ip, "0.0.0.0"); memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *)); nmb = &orig_reg_packet->packet.nmb; @@ -1486,9 +1489,10 @@ void wins_process_multihomed_name_registration_request( struct subnet_record *su struct name_record *namerec = NULL; struct in_addr from_ip; bool group = (nb_flags & NB_GROUP) ? True : False; - struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); + struct in_addr our_fake_ip; unstring qname; + (void)interpret_addr2(&our_fake_ip, "0.0.0.0"); putip((char *)&from_ip,&nmb->additional->rdata[2]); if(bcast) { @@ -2112,8 +2116,9 @@ static int wins_processing_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA time_t t = *(time_t *)state; bool store_record = False; struct name_record *namerec = NULL; - struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); + struct in_addr our_fake_ip; + (void)interpret_addr2(&our_fake_ip, "0.0.0.0"); if (kbuf.dsize != sizeof(unstring) + 1) { return 0; } @@ -2381,9 +2386,10 @@ void nmbd_wins_new_entry(struct messaging_context *msg, struct name_record *new_namerec = NULL; struct nmb_name question; bool overwrite=False; - struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0"); + struct in_addr our_fake_ip; int i; + (void)interpret_addr2(&our_fake_ip, "0.0.0.0"); if (buf==NULL) { return; } -- cgit From 36441da4240f3e3a296eed65f0796b25b7b05a3a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 5 Nov 2007 11:12:56 -0800 Subject: Remove the horror that was the global smb_rw_error. Each cli struct has it's own local copy of this variable, so use that in client code. In the smbd server, add one static to smbd/proccess.c and use that inside smbd. Fix a bunch of places where smb_rw_error could be set by calling read_data() in places where we weren't reading from the SMB client socket (ie. winbindd). Jeremy. (This used to be commit 255c2adf7b6ef30932b5bb9f142ccef4a5d3d0db) --- source3/nmbd/asyncdns.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index b9c9ffb1c6..33c1cb6cb1 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -87,7 +87,7 @@ static void asyncdns_process(void) DEBUGLEVEL = -1; while (1) { - if (read_data(fd_in, (char *)&r, sizeof(r)) != sizeof(r)) + if (read_data(fd_in, (char *)&r, sizeof(r), NULL) != sizeof(r)) break; pull_ascii_nstring( qname, sizeof(qname), r.name.name); @@ -208,7 +208,7 @@ void run_dns_queue(void) start_async_dns(); } - if ((size=read_data(fd_in, (char *)&r, sizeof(r))) != sizeof(r)) { + if ((size=read_data(fd_in, (char *)&r, sizeof(r), NULL)) != sizeof(r)) { if (size) { DEBUG(0,("Incomplete DNS answer from child!\n")); fd_in = -1; -- cgit From d40e47db4b5da41c8604a2058f3a0b0a82164f08 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 8 Nov 2007 17:25:45 -0800 Subject: Remove more fstring/pstring bad useage. Go talloc ! Jeremy. (This used to be commit 2a0173743d2cf615d52278f3dd87cc804abe2d16) --- source3/nmbd/nmbd_processlogon.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index feb7941cc3..50a614a390 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -394,13 +394,18 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", else { struct GUID domain_guid; UUID_FLAT flat_guid; - pstring domain; + char *domain; pstring hostname; char *component, *dc, *q1; char *q_orig = q; int str_offset; - get_mydnsdomname(domain); + domain = get_mydnsdomname(talloc_tos()); + if (!domain) { + DEBUG(2, + ("get_mydnsdomname failed.\n")); + return; + } get_myname(hostname); if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 8) { -- cgit From 5f4693d8f8cf435cb2c62787ba95acf2b0b5f7d2 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 8 Nov 2007 18:50:07 -0800 Subject: Remove more pstring/fstrings. Jeremy. (This used to be commit 7a1de5b44e84a7474e78518c6ba33b3fedc42b5f) --- source3/nmbd/nmbd_processlogon.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 50a614a390..8cbb87355a 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -395,7 +395,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", struct GUID domain_guid; UUID_FLAT flat_guid; char *domain; - pstring hostname; + char *hostname; char *component, *dc, *q1; char *q_orig = q; int str_offset; @@ -406,7 +406,12 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", ("get_mydnsdomname failed.\n")); return; } - get_myname(hostname); + hostname = get_myname(talloc_tos()); + if (!hostname) { + DEBUG(2, + ("get_myname failed.\n")); + return; + } if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 8) { return; -- cgit From 6c25260ec12552653eabed25451866e370108c37 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 9 Nov 2007 15:09:16 -0800 Subject: Remove more static fstring/pstrings. Fix socket option set on wrong fd (-1). Jeremy. (This used to be commit 52fe04df8e8c08126afe61d509fc1d3cb676e327) --- source3/nmbd/nmbd_synclists.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index aaa56f9216..300368cd60 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -28,8 +28,6 @@ #include "includes.h" -extern fstring local_machine; - struct sync_record { struct sync_record *next, *prev; unstring workgroup; @@ -92,7 +90,7 @@ static void sync_child(char *name, int nm_type, return; } - make_nmb_name(&calling, local_machine, 0x0); + make_nmb_name(&calling, get_local_machine_name(), 0x0); make_nmb_name(&called , name, nm_type); if (!cli_session_request(cli, &calling, &called)) { -- cgit From d41713b10770765cd0b30f8b5c8d6bddad4de2d6 Mon Sep 17 00:00:00 2001 From: "Gerald (Jerry) Carter" Date: Wed, 14 Nov 2007 20:51:14 -0600 Subject: Fix for CVE-2007-5398. == Subject: Remote code execution in Samba's WINS == server daemon (nmbd) when processing name == registration followed name query requests. == == CVE ID#: CVE-2007-5398 == == Versions: Samba 3.0.0 - 3.0.26a (inclusive) ... Secunia Research reported a vulnerability that allows for the execution of arbitrary code in nmbd. This defect may only be exploited when the "wins support" parameter has been enabled in smb.conf. (This used to be commit e40c372e0ddf631dd9162c1fdfaaa49c29915f23) --- source3/nmbd/nmbd_packets.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index d49c8bab79..b78ab5ba7e 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -970,6 +970,12 @@ for id %hu\n", packet_type, nmb_namestr(&orig_nmb->question.question_name), nmb->answers->ttl = ttl; if (data && len) { + if (len < 0 || len > sizeof(nmb->answers->rdata)) { + DEBUG(5,("reply_netbios_packet: " + "invalid packet len (%d)\n", + len )); + return; + } nmb->answers->rdlength = len; memcpy(nmb->answers->rdata, data, len); } -- cgit From 68be9a820059ee96dd26c527efd7c14e679d3f2c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 15 Nov 2007 14:19:52 -0800 Subject: More pstring removal. This one was tricky. I had to add one horror (pstring_clean_name()) which will have to remain until I've removed all pstrings from the client code. Jeremy. (This used to be commit 1ea3ac80146b83c2522b69e7747c823366a2b47d) --- source3/nmbd/nmbd.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 6fadefe682..beb178e59c 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -733,6 +733,7 @@ static bool open_sockets(bool isdaemon, int port) POPT_COMMON_SAMBA { NULL } }; + TALLOC_CTX *frame = talloc_stackframe(); /* Setup tos. */ load_case_tables(); @@ -927,6 +928,7 @@ static bool open_sockets(bool isdaemon, int port) /* We can only take signals in the select. */ BlockSignals( True, SIGTERM ); + TALLOC_FREE(frame); process(); if (dbf) -- cgit From c261545449f71d9b347a37518dab0d5ae4116f8b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 15 Nov 2007 17:59:12 -0800 Subject: Fix bug noticed by kukks where ip list didn't match namelist added to subnetdb. Could cause bogus IP addresses to be reported for the __SAMBA__ name. Jeremy. (This used to be commit ad9f14b6dcb05e8fa68b51ff26ff40fc445a4631) --- source3/nmbd/nmbd_namelistdb.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index ae5f766e66..f9cbcf4f59 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -192,6 +192,10 @@ bool add_name_to_subnet( struct subnet_record *subrec, struct name_record *namerec; time_t time_now = time(NULL); + if (num_ips == 0) { + return false; + } + namerec = SMB_MALLOC_P(struct name_record); if( NULL == namerec ) { DEBUG( 0, ( "add_name_to_subnet: malloc fail.\n" ) ); @@ -504,8 +508,12 @@ void add_samba_names_to_subnet( struct subnet_record *subrec ) return; } - for( bcast_subrecs = FIRST_SUBNET, i = 0; bcast_subrecs; bcast_subrecs = NEXT_SUBNET_EXCLUDING_UNICAST(bcast_subrecs), i++ ) + for( bcast_subrecs = FIRST_SUBNET, i = 0; bcast_subrecs && + i < num_ips; + bcast_subrecs = NEXT_SUBNET_EXCLUDING_UNICAST(bcast_subrecs), i++ ) { iplist[i] = bcast_subrecs->myip; + } + num_ips = i; } add_name_to_subnet(subrec,"*",0x0,samba_nb_type, PERMANENT_TTL, -- cgit From 9a41314ce8582875e0ec59efb670279f39b42ce3 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 19 Nov 2007 15:15:09 -0800 Subject: Remove pstring from nmbd. Jeremy. (This used to be commit a317f70c229f7730279eaa323f7ebfd499257f76) --- source3/nmbd/nmbd.c | 10 +++-- source3/nmbd/nmbd_browsesync.c | 6 +-- source3/nmbd/nmbd_elections.c | 6 +-- source3/nmbd/nmbd_incomingdgrams.c | 12 +++--- source3/nmbd/nmbd_lmhosts.c | 16 ++++--- source3/nmbd/nmbd_processlogon.c | 24 +++++------ source3/nmbd/nmbd_sendannounce.c | 24 +++++------ source3/nmbd/nmbd_serverlistdb.c | 50 +++++++++++++--------- source3/nmbd/nmbd_synclists.c | 31 +++++++------- source3/nmbd/nmbd_winsserver.c | 86 ++++++++++++++++++++++++-------------- 10 files changed, 154 insertions(+), 111 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index beb178e59c..17e56b0756 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -287,8 +287,7 @@ static bool reload_nmbd_services(bool test) set_remote_machine_name("nmbd", False); if ( lp_loaded() ) { - pstring fname; - pstrcpy( fname,lp_configfile()); + const char *fname = lp_configfile(); if (file_exist(fname,NULL) && !strcsequal(fname,dyn_CONFIGFILE)) { pstrcpy(dyn_CONFIGFILE,fname); test = False; @@ -710,7 +709,6 @@ static bool open_sockets(bool isdaemon, int port) static bool Fork = true; static bool no_process_group; static bool log_stdout; - pstring logfile; poptContext pc; static char *p_lmhosts = dyn_LMHOSTSFILE; int opt; @@ -773,8 +771,12 @@ static bool open_sockets(bool isdaemon, int port) sys_srandom(time(NULL) ^ sys_getpid()); if (!override_logfile) { - slprintf(logfile, sizeof(logfile)-1, "%s/log.nmbd", dyn_LOGFILEBASE); + char *logfile = NULL; + if (asprintf(&logfile, "%s/log.nmbd", dyn_LOGFILEBASE) < 0) { + exit(1); + } lp_set_logfile(logfile); + SAFE_FREE(logfile); } fault_setup((void (*)(void *))fault_continue ); diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 4effce0722..b630fd234d 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -98,7 +98,7 @@ As a local master browser, send an announce packet to the domain master browser. static void announce_local_master_browser_to_domain_master_browser( struct work_record *work) { - pstring outbuf; + char outbuf[1024]; unstring myname; unstring dmb_name; char *p; @@ -122,7 +122,7 @@ static void announce_local_master_browser_to_domain_master_browser( struct work_ strupper_m(myname); myname[15]='\0'; /* The call below does CH_UNIX -> CH_DOS conversion. JRA */ - push_pstring_base(p, myname, outbuf); + push_ascii(p, myname, sizeof(outbuf)-PTR_DIFF(p,outbuf)-1, STR_TERMINATE); p = skip_string(outbuf,sizeof(outbuf),p); @@ -136,7 +136,7 @@ static void announce_local_master_browser_to_domain_master_browser( struct work_ /* Target name for send_mailslot must be in UNIX charset. */ pull_ascii_nstring(dmb_name, sizeof(dmb_name), work->dmb_name.name); send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), - global_myname(), 0x0, dmb_name, 0x0, + global_myname(), 0x0, dmb_name, 0x0, work->dmb_addr, FIRST_SUBNET->myip, DGRAM_PORT); } diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index db32461f06..bafe87c044 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -32,7 +32,7 @@ extern time_t StartupTime; static void send_election_dgram(struct subnet_record *subrec, const char *workgroup_name, uint32 criterion, int timeup,const char *server_name) { - pstring outbuf; + char outbuf[1024]; unstring srv_name; char *p; @@ -51,9 +51,9 @@ static void send_election_dgram(struct subnet_record *subrec, const char *workgr unstrcpy(srv_name, server_name); strupper_m(srv_name); /* The following call does UNIX -> DOS charset conversion. */ - pstrcpy_base(p, srv_name, outbuf); + push_ascii(p, srv_name, sizeof(outbuf)-PTR_DIFF(p,outbuf)-1, STR_TERMINATE); p = skip_string(outbuf,sizeof(outbuf),p); - + send_mailslot(False, BROWSE_MAILSLOT, outbuf, PTR_DIFF(p,outbuf), global_myname(), 0, workgroup_name, 0x1e, diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index 9fe344c39b..c0aa385ff6 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -534,13 +534,13 @@ done: Send a backup list response. *****************************************************************************/ -static void send_backup_list_response(struct subnet_record *subrec, +static void send_backup_list_response(struct subnet_record *subrec, struct work_record *work, struct nmb_name *send_to_name, unsigned char max_number_requested, uint32 token, struct in_addr sendto_ip, int port) -{ +{ char outbuf[1024]; char *p, *countptr; unsigned int count = 0; @@ -554,9 +554,9 @@ static void send_backup_list_response(struct subnet_record *subrec, DEBUG(3,("send_backup_list_response: sending backup list for workgroup %s to %s IP %s\n", work->work_group, nmb_namestr(send_to_name), inet_ntoa(sendto_ip))); - + p = outbuf; - + SCVAL(p,0,ANN_GetBackupListResp); /* Backup list response opcode. */ p++; @@ -565,13 +565,13 @@ static void send_backup_list_response(struct subnet_record *subrec, SIVAL(p,0,token); /* The sender's unique info. */ p += 4; - + /* We always return at least one name - our own. */ count = 1; unstrcpy(myname, global_myname()); strupper_m(myname); myname[15]='\0'; - push_pstring_base(p, myname, outbuf); + push_ascii(p, myname, sizeof(outbuf)-PTR_DIFF(p,outbuf)-1, STR_TERMINATE); p = skip_string(outbuf,sizeof(outbuf),p); diff --git a/source3/nmbd/nmbd_lmhosts.c b/source3/nmbd/nmbd_lmhosts.c index 51e4858f32..75c03bb398 100644 --- a/source3/nmbd/nmbd_lmhosts.c +++ b/source3/nmbd/nmbd_lmhosts.c @@ -29,24 +29,27 @@ Load a lmhosts file. ****************************************************************************/ void load_lmhosts_file(const char *fname) -{ - pstring name; +{ + char *name = NULL; int name_type; struct sockaddr_storage ss; + TALLOC_CTX *ctx = talloc_init("load_lmhosts_file"); XFILE *fp = startlmhosts( fname ); if (!fp) { DEBUG(2,("load_lmhosts_file: Can't open lmhosts file %s. Error was %s\n", fname, strerror(errno))); + TALLOC_FREE(ctx); return; } - - while (getlmhostsent(fp, name, &name_type, &ss) ) { + + while (getlmhostsent(ctx, fp, &name, &name_type, &ss) ) { struct in_addr ipaddr; struct subnet_record *subrec = NULL; enum name_source source = LMHOSTS_NAME; if (ss.ss_family != AF_INET) { + TALLOC_FREE(name); continue; } @@ -58,7 +61,7 @@ void load_lmhosts_file(const char *fname) if(same_net_v4(ipaddr, subrec->bcast_ip, subrec->mask_ip)) break; } - + /* If none match add the name to the remote_broadcast_subnet. */ if(subrec == NULL) subrec = remote_broadcast_subnet; @@ -72,7 +75,8 @@ void load_lmhosts_file(const char *fname) (void)add_name_to_subnet(subrec,name,name_type,(uint16)NB_ACTIVE,PERMANENT_TTL,source,1,&ipaddr); } } - + + TALLOC_FREE(ctx); endlmhosts(fp); } diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 8cbb87355a..0ff0afd12d 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -39,9 +39,9 @@ void process_logon_packet(struct packet_struct *p, char *buf,int len, const char *mailslot) { struct dgram_packet *dgram = &p->packet.dgram; - pstring my_name; + fstring my_name; fstring reply_name; - pstring outbuf; + char outbuf[1024]; int code; uint16 token = 0; uint32 ntversion = 0; @@ -51,7 +51,7 @@ void process_logon_packet(struct packet_struct *p, char *buf,int len, bool short_request = False; char *getdc; char *uniuser; /* Unicode user name. */ - pstring ascuser; + fstring ascuser; char *unicomp; /* Unicode computer name. */ size_t size; struct sockaddr_storage ss; @@ -76,7 +76,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); return; } - pstrcpy(my_name, global_myname()); + fstrcpy(my_name, global_myname()); code = get_safe_SVAL(buf,len,buf,0,-1); DEBUG(4,("process_logon_packet: Logon from %s: code = 0x%x\n", inet_ntoa(p->ip), code)); @@ -107,7 +107,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); } token = SVAL(q,3); - fstrcpy(reply_name,my_name); + fstrcpy(reply_name,my_name); pull_ascii_fstring(mach_str, machine); pull_ascii_fstring(user_str, user); @@ -237,12 +237,12 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); q = ALIGN2(q, outbuf); q += dos_PutUniCode(q, my_name, - sizeof(pstring) - PTR_DIFF(q, outbuf), + sizeof(outbuf) - PTR_DIFF(q, outbuf), True); /* PDC name */ q += dos_PutUniCode(q, lp_workgroup(), - sizeof(pstring) - PTR_DIFF(q, outbuf), + sizeof(outbuf) - PTR_DIFF(q, outbuf), True); /* Domain name*/ - if (sizeof(pstring) - PTR_DIFF(q, outbuf) < 8) { + if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 8) { return; } SIVAL(q, 0, 1); /* our nt version */ @@ -355,7 +355,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", * database. If it isn't then we let smbd send an appropriate error. * Let's ignore the SID. */ - pull_ucs2_pstring(ascuser, uniuser); + pull_ucs2_fstring(ascuser, uniuser); pull_ucs2_fstring(asccomp, unicomp); DEBUG(5,("process_logon_packet: SAMLOGON user %s\n", ascuser)); @@ -381,13 +381,13 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", q += 2; q += dos_PutUniCode(q, reply_name, - sizeof(pstring) - PTR_DIFF(q, outbuf), + sizeof(outbuf) - PTR_DIFF(q, outbuf), True); q += dos_PutUniCode(q, ascuser, - sizeof(pstring) - PTR_DIFF(q, outbuf), + sizeof(outbuf) - PTR_DIFF(q, outbuf), True); q += dos_PutUniCode(q, lp_workgroup(), - sizeof(pstring) - PTR_DIFF(q, outbuf), + sizeof(outbuf) - PTR_DIFF(q, outbuf), True); } #ifdef HAVE_ADS diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index 56cd497568..73c875d248 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -457,7 +457,7 @@ void announce_remote(time_t t) char *s; const char *ptr; static time_t last_time = 0; - pstring s2; + fstring s2; struct in_addr addr; char *comment; int stype = lp_default_server_announce(); @@ -474,7 +474,7 @@ void announce_remote(time_t t) comment = string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH); for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) { - /* The entries are of the form a.b.c.d/WORKGROUP with + /* The entries are of the form a.b.c.d/WORKGROUP with WORKGROUP being optional */ const char *wgroup; char *pwgroup; @@ -489,7 +489,7 @@ void announce_remote(time_t t) wgroup = pwgroup; (void)interpret_addr2(&addr,s2); - + /* Announce all our names including aliases */ /* Give the ip address as the address of our first broadcast subnet. */ @@ -518,20 +518,20 @@ void announce_remote(time_t t) **************************************************************************/ void browse_sync_remote(time_t t) -{ +{ char *s; const char *ptr; - static time_t last_time = 0; - pstring s2; + static time_t last_time = 0; + fstring s2; struct in_addr addr; struct work_record *work; - pstring outbuf; + char outbuf[1024]; char *p; unstring myname; - + if (last_time && (t < (last_time + REMOTE_ANNOUNCE_INTERVAL))) return; - + last_time = t; s = lp_remote_browse_sync(); @@ -548,12 +548,12 @@ void browse_sync_remote(time_t t) lp_workgroup(), FIRST_SUBNET->subnet_name )); return; } - + if(!AM_LOCAL_MASTER_BROWSER(work)) { DEBUG(5,("browse_sync_remote: We can only do this if we are a local master browser \ for workgroup %s on subnet %s.\n", lp_workgroup(), FIRST_SUBNET->subnet_name )); return; - } + } memset(outbuf,'\0',sizeof(outbuf)); p = outbuf; @@ -563,7 +563,7 @@ for workgroup %s on subnet %s.\n", lp_workgroup(), FIRST_SUBNET->subnet_name )); unstrcpy(myname, global_myname()); strupper_m(myname); myname[15]='\0'; - push_pstring_base(p, myname, outbuf); + push_ascii(p, myname, sizeof(outbuf)-PTR_DIFF(p,outbuf)-1, STR_TERMINATE); p = skip_string(outbuf,sizeof(outbuf),p); diff --git a/source3/nmbd/nmbd_serverlistdb.c b/source3/nmbd/nmbd_serverlistdb.c index 5ac4888365..349c3f4df3 100644 --- a/source3/nmbd/nmbd_serverlistdb.c +++ b/source3/nmbd/nmbd_serverlistdb.c @@ -289,17 +289,19 @@ void write_browse_list_entry(XFILE *fp, const char *name, uint32 rec_type, } void write_browse_list(time_t t, bool force_write) -{ +{ struct subnet_record *subrec; struct work_record *work; struct server_record *servrec; - pstring fname,fnamenew; + char *fname; + char *fnamenew; uint32 stype; int i; XFILE *fp; bool list_changed = force_write; static time_t lasttime = 0; - + TALLOC_CTX *ctx = talloc_tos(); + /* Always dump if we're being told to by a signal. */ if(force_write == False) { if (!lasttime) @@ -311,7 +313,7 @@ void write_browse_list(time_t t, bool force_write) lasttime = t; dump_workgroups(force_write); - + for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { if(subrec->work_changed) { list_changed = True; @@ -323,22 +325,32 @@ void write_browse_list(time_t t, bool force_write) return; updatecount++; - - pstrcpy(fname,lp_lockdir()); + + fname = talloc_strdup(ctx, lp_lockdir()); + if (!fname) { + return; + } trim_char(fname,'\0' ,'/'); - pstrcat(fname,"/"); - pstrcat(fname,SERVER_LIST); - pstrcpy(fnamenew,fname); - pstrcat(fnamenew,"."); - + fname = talloc_asprintf_append(fname, + "/%s", + SERVER_LIST); + if (!fname) { + return; + } + fnamenew = talloc_asprintf(ctx, "%s.", + fname); + if (!fnamenew) { + return; + } + fp = x_fopen(fnamenew,O_WRONLY|O_CREAT|O_TRUNC, 0644); - + if (!fp) { DEBUG(0,("write_browse_list: Can't open file %s. Error was %s\n", fnamenew,strerror(errno))); return; - } - + } + /* * Write out a record for our workgroup. Use the record from the first * subnet. @@ -355,7 +367,7 @@ void write_browse_list(time_t t, bool force_write) SV_TYPE_DOMAIN_ENUM|SV_TYPE_NT|SV_TYPE_LOCAL_LIST_ONLY, work->local_master_browser_name, work->work_group); - /* + /* * We need to do something special for our own names. * This is due to the fact that we may be a local master browser on * one of our broadcast subnets, and a domain master on the unicast @@ -378,7 +390,7 @@ void write_browse_list(time_t t, bool force_write) write_browse_list_entry(fp, my_netbios_names(i), stype, string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH), lp_workgroup()); } - + for (subrec = FIRST_SUBNET; subrec ; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) { subrec->work_changed = False; @@ -399,7 +411,7 @@ void write_browse_list(time_t t, bool force_write) /* We have already written our names here. */ if(is_myname(servrec->serv.name)) - continue; + continue; serv_type = write_this_server_name(subrec, work, servrec); if(serv_type) { @@ -409,8 +421,8 @@ void write_browse_list(time_t t, bool force_write) } } } - } - + } + x_fclose(fp); unlink(fname); chmod(fnamenew,0644); diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 300368cd60..8abf60c8ce 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -32,7 +32,7 @@ struct sync_record { struct sync_record *next, *prev; unstring workgroup; unstring server; - pstring fname; + char *fname; struct in_addr ip; pid_t pid; }; @@ -159,15 +159,18 @@ done: if (!s) goto done; ZERO_STRUCTP(s); - + unstrcpy(s->workgroup, work->work_group); unstrcpy(s->server, name); s->ip = ip; - slprintf(s->fname, sizeof(pstring)-1, - "%s/sync.%d", lp_lockdir(), counter++); + if (asprintf(&s->fname, "%s/sync.%d", lp_lockdir(), counter++) < 0) { + SAFE_FREE(s); + goto done; + } + /* Safe to use as 0 means no size change. */ all_string_sub(s->fname,"//", "/", 0); - + DLIST_ADD(syncs, s); /* the parent forks and returns, leaving the child to do the @@ -183,7 +186,7 @@ done: fp = x_fopen(s->fname,O_WRONLY|O_CREAT|O_TRUNC, 0644); if (!fp) { END_PROFILE(sync_browse_lists); - _exit(1); + _exit(1); } sync_child(name, nm_type, work->work_group, ip, local, servers, @@ -247,7 +250,7 @@ static void complete_one(struct sync_record *s, /* Create the server in the workgroup. */ create_server_on_workgroup(work, sname,stype, lp_max_ttl(), comment); } - + /********************************************************************** Read the completed sync info. **********************************************************************/ @@ -257,8 +260,8 @@ static void complete_sync(struct sync_record *s) XFILE *f; unstring server, type_str; unsigned type; - pstring comment; - pstring line; + fstring comment; + char line[1024]; const char *ptr; int count=0; @@ -266,12 +269,12 @@ static void complete_sync(struct sync_record *s) if (!f) return; - + while (!x_feof(f)) { - - if (!fgets_slash(line,sizeof(pstring),f)) + + if (!fgets_slash(line,sizeof(line),f)) continue; - + ptr = line; if (!next_token(&ptr,server,NULL,sizeof(server)) || @@ -309,7 +312,7 @@ void sync_check_completion(void) /* it has completed - grab the info */ complete_sync(s); DLIST_REMOVE(syncs, s); - ZERO_STRUCTP(s); + SAFE_FREE(s->fname); SAFE_FREE(s); } } diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index d4a2c8346e..88cc395af4 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -437,10 +437,11 @@ static void get_global_id_and_update(SMB_BIG_UINT *current_id, bool update) static void wins_hook(const char *operation, struct name_record *namerec, int ttl) { - pstring command; + char *command = NULL; char *cmd = lp_wins_hook(); char *p, *namestr; int i; + TALLOC_CTX *ctx = talloc_tos(); wins_store_changed_namerec(namerec); @@ -462,20 +463,29 @@ static void wins_hook(const char *operation, struct name_record *namerec, int tt *p = 0; } - p = command; - p += slprintf(p, sizeof(command)-1, "%s %s %s %02x %d", - cmd, - operation, - namestr, - namerec->name.name_type, - ttl); + command = talloc_asprintf(ctx, + "%s %s %s %02x %d", + cmd, + operation, + namestr, + namerec->name.name_type, + ttl); + if (!command) { + return; + } for (i=0;idata.num_ips;i++) { - p += slprintf(p, sizeof(command) - (p-command) -1, " %s", inet_ntoa(namerec->data.ip[i])); + command = talloc_asprintf_append(command, + " %s", + inet_ntoa(namerec->data.ip[i])); + if (!command) { + return; + } } DEBUG(3,("calling wins hook for %s\n", nmb_namestr(&namerec->name))); smbrun(command, NULL); + TALLOC_FREE(command); } /**************************************************************************** @@ -566,7 +576,7 @@ bool initialise_wins(void) { time_t time_now = time(NULL); XFILE *fp; - pstring line; + char line[1024]; if(!lp_we_are_a_wins_server()) { return True; @@ -591,9 +601,11 @@ bool initialise_wins(void) } while (!x_feof(fp)) { - pstring name_str, ip_str, ttl_str, nb_flags_str; + fstring name_str; + char ip_str[1024]; + fstring ttl_str, nb_flags_str; unsigned int num_ips; - pstring name; + char *name; struct in_addr *ip_list; int type = 0; int nb_flags; @@ -608,9 +620,9 @@ bool initialise_wins(void) /* Read a line from the wins.dat file. Strips whitespace from the beginning and end of the line. */ - if (!fgets_slash(line,sizeof(pstring),fp)) + if (!fgets_slash(line,sizeof(line),fp)) continue; - + if (*line == '#') continue; @@ -626,7 +638,7 @@ bool initialise_wins(void) ptr = line; - /* + /* * Now we handle multiple IP addresses per name we need * to iterate over the line twice. The first time to * determine how many IP addresses there are, the second @@ -673,10 +685,10 @@ bool initialise_wins(void) x_fclose(fp); return False; } - + /* Reset and re-parse the line. */ ptr = line; - next_token(&ptr,name_str,NULL,sizeof(name_str)); + next_token(&ptr,name_str,NULL,sizeof(name_str)); next_token(&ptr,ttl_str,NULL,sizeof(ttl_str)); for(i = 0; i < num_ips; i++) { next_token(&ptr, ip_str, NULL, sizeof(ip_str)); @@ -694,19 +706,19 @@ bool initialise_wins(void) SAFE_FREE(ip_list); continue; } - + if(nb_flags_str[strlen(nb_flags_str)-1] == 'R') { nb_flags_str[strlen(nb_flags_str)-1] = '\0'; } - + /* Netbios name. # divides the name from the type (hex): netbios#xx */ - pstrcpy(name,name_str); - + name = name_str; + if((p = strchr(name,'#')) != NULL) { *p = 0; sscanf(p+1,"%x",&type); } - + /* Decode the netbios flags (hex) and the time-to-live (in seconds). */ sscanf(nb_flags_str,"%x",&nb_flags); sscanf(ttl_str,"%d",&ttl); @@ -716,7 +728,7 @@ bool initialise_wins(void) if(ttl != PERMANENT_TTL) { ttl -= time_now; } - + DEBUG( 4, ("initialise_wins: add name: %s#%02x ttl = %d first IP %s flags = %2x\n", name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); @@ -2310,10 +2322,11 @@ static int wins_writedb_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA db void wins_write_database(time_t t, bool background) { static time_t last_write_time = 0; - pstring fname, fnamenew; + char *fname = NULL; + char *fnamenew = NULL; XFILE *fp; - + if (background) { if (!last_write_time) { last_write_time = t; @@ -2342,28 +2355,37 @@ void wins_write_database(time_t t, bool background) } } - slprintf(fname,sizeof(fname)-1,"%s/%s", dyn_STATEDIR(), WINS_LIST); + if (asprintf(&fname, "%s/%s", dyn_STATEDIR(), WINS_LIST) < 0) { + goto err_exit; + } + /* This is safe as the 0 length means "don't expand". */ all_string_sub(fname,"//", "/", 0); - slprintf(fnamenew,sizeof(fnamenew)-1,"%s.%u", fname, (unsigned int)sys_getpid()); + + if (asprintf(&fnamenew, "%s.%u", fname, (unsigned int)sys_getpid()) < 0) { + goto err_exit; + } if((fp = x_fopen(fnamenew,O_WRONLY|O_CREAT,0644)) == NULL) { DEBUG(0,("wins_write_database: Can't open %s. Error was %s\n", fnamenew, strerror(errno))); - if (background) { - _exit(0); - } - return; + goto err_exit; } DEBUG(4,("wins_write_database: Dump of WINS name list.\n")); x_fprintf(fp,"VERSION %d %u\n", WINS_VERSION, 0); - + tdb_traverse(wins_tdb, wins_writedb_traverse_fn, fp); x_fclose(fp); chmod(fnamenew,0644); unlink(fname); rename(fnamenew,fname); + + err_exit: + + SAFE_FREE(fname); + SAFE_FREE(fnamenew); + if (background) { _exit(0); } -- cgit From f692694b99319ef1f534ea29f001922656402cdf Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 29 Nov 2007 17:25:41 -0800 Subject: Remove PSTRING_LEN from smbd/ nmbd/. Remove pstring from libsmb/clidfs.c except for a nasty hack (that will be removed when pstrings are gone from client/). Jeremy. (This used to be commit cc257b71d13daa47e6f2315d0f07a60eb4aaeca6) --- source3/nmbd/nmbd_sendannounce.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index 73c875d248..a4e646771f 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -34,7 +34,7 @@ extern bool found_lm_clients; void send_browser_reset(int reset_type, const char *to_name, int to_type, struct in_addr to_ip) { - char outbuf[PSTRING_LEN]; + char outbuf[1024]; char *p; DEBUG(3,("send_browser_reset: sending reset request type %d to %s<%02x> IP %s.\n", @@ -59,7 +59,7 @@ void send_browser_reset(int reset_type, const char *to_name, int to_type, struct void broadcast_announce_request(struct subnet_record *subrec, struct work_record *work) { - char outbuf[PSTRING_LEN]; + char outbuf[1024]; char *p; work->needannounce = True; @@ -90,7 +90,7 @@ static void send_announcement(struct subnet_record *subrec, int announce_type, time_t announce_interval, const char *server_name, int server_type, const char *server_comment) { - char outbuf[PSTRING_LEN]; + char outbuf[1024]; unstring upper_server_name; char *p; @@ -131,7 +131,7 @@ static void send_lm_announcement(struct subnet_record *subrec, int announce_type time_t announce_interval, char *server_name, int server_type, char *server_comment) { - char outbuf[PSTRING_LEN]; + char outbuf[1024]; char *p=outbuf; memset(outbuf,'\0',sizeof(outbuf)); -- cgit From acf15ae730c95443681404c76b67ccfca0253d8b Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 7 Dec 2007 12:26:32 -0800 Subject: Don't build rpctorture anymore - not maintained. Just remove. Remove all vestiges of pstring (except for smbctool as noted in previous commit). Jeremy (This used to be commit 4c32a22ac50ada3275d2ffba3c1aa08bee7d1549) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 17e56b0756..52f1cd15f5 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -289,7 +289,7 @@ static bool reload_nmbd_services(bool test) if ( lp_loaded() ) { const char *fname = lp_configfile(); if (file_exist(fname,NULL) && !strcsequal(fname,dyn_CONFIGFILE)) { - pstrcpy(dyn_CONFIGFILE,fname); + strlcpy(dyn_CONFIGFILE,fname,sizeof(dyn_CONFIGFILE)); test = False; } } -- cgit From 42cfffae80480eae4381902fff3f7c61f858a933 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 7 Dec 2007 17:32:32 -0800 Subject: Remove next_token - all uses must now be next_token_talloc. No more temptations to use static length strings. Jeremy. (This used to be commit ec003f39369910dee852b7cafb883ddaa321c2de) --- source3/nmbd/nmbd_sendannounce.c | 14 ++++++++---- source3/nmbd/nmbd_synclists.c | 18 +++++++++------ source3/nmbd/nmbd_winsserver.c | 49 ++++++++++++++++++++++++---------------- 3 files changed, 51 insertions(+), 30 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_sendannounce.c b/source3/nmbd/nmbd_sendannounce.c index a4e646771f..3cc9bb52b0 100644 --- a/source3/nmbd/nmbd_sendannounce.c +++ b/source3/nmbd/nmbd_sendannounce.c @@ -457,10 +457,11 @@ void announce_remote(time_t t) char *s; const char *ptr; static time_t last_time = 0; - fstring s2; + char *s2; struct in_addr addr; char *comment; int stype = lp_default_server_announce(); + TALLOC_CTX *frame = NULL; if (last_time && (t < (last_time + REMOTE_ANNOUNCE_INTERVAL))) return; @@ -473,7 +474,8 @@ void announce_remote(time_t t) comment = string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH); - for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) { + frame = talloc_stackframe(); + for (ptr=s; next_token_talloc(frame,&ptr,&s2,NULL); ) { /* The entries are of the form a.b.c.d/WORKGROUP with WORKGROUP being optional */ const char *wgroup; @@ -510,6 +512,7 @@ void announce_remote(time_t t) comment); } } + TALLOC_FREE(frame); } /**************************************************************************** @@ -522,12 +525,13 @@ void browse_sync_remote(time_t t) char *s; const char *ptr; static time_t last_time = 0; - fstring s2; + char *s2; struct in_addr addr; struct work_record *work; char outbuf[1024]; char *p; unstring myname; + TALLOC_CTX *frame = NULL; if (last_time && (t < (last_time + REMOTE_ANNOUNCE_INTERVAL))) return; @@ -567,7 +571,8 @@ for workgroup %s on subnet %s.\n", lp_workgroup(), FIRST_SUBNET->subnet_name )); p = skip_string(outbuf,sizeof(outbuf),p); - for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) { + frame = talloc_stackframe(); + for (ptr=s; next_token_talloc(frame,&ptr,&s2,NULL); ) { /* The entries are of the form a.b.c.d */ (void)interpret_addr2(&addr,s2); @@ -577,4 +582,5 @@ for workgroup %s on subnet %s.\n", lp_workgroup(), FIRST_SUBNET->subnet_name )); send_mailslot(True, BROWSE_MAILSLOT, outbuf,PTR_DIFF(p,outbuf), global_myname(), 0x0, "*", 0x0, addr, FIRST_SUBNET->myip, DGRAM_PORT); } + TALLOC_FREE(frame); } diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 8abf60c8ce..147df68a69 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -201,7 +201,7 @@ done: Handle one line from a completed sync file. **********************************************************************/ -static void complete_one(struct sync_record *s, +static void complete_one(struct sync_record *s, char *sname, uint32 stype, char *comment) { struct work_record *work; @@ -258,9 +258,10 @@ static void complete_one(struct sync_record *s, static void complete_sync(struct sync_record *s) { XFILE *f; - unstring server, type_str; + char *server; + char *type_str; unsigned type; - fstring comment; + char *comment; char line[1024]; const char *ptr; int count=0; @@ -271,15 +272,18 @@ static void complete_sync(struct sync_record *s) return; while (!x_feof(f)) { + TALLOC_CTX *frame = NULL; if (!fgets_slash(line,sizeof(line),f)) continue; ptr = line; - if (!next_token(&ptr,server,NULL,sizeof(server)) || - !next_token(&ptr,type_str,NULL, sizeof(type_str)) || - !next_token(&ptr,comment,NULL, sizeof(comment))) { + frame = talloc_stackframe(); + if (!next_token_talloc(frame,&ptr,&server,NULL) || + !next_token_talloc(frame,&ptr,&type_str,NULL) || + !next_token_talloc(frame,&ptr,&comment,NULL)) { + TALLOC_FREE(frame); continue; } @@ -288,8 +292,8 @@ static void complete_sync(struct sync_record *s) complete_one(s, server, type, comment); count++; + TALLOC_FREE(frame); } - x_fclose(f); unlink(s->fname); diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 88cc395af4..7dafa66b11 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -601,30 +601,33 @@ bool initialise_wins(void) } while (!x_feof(fp)) { - fstring name_str; - char ip_str[1024]; - fstring ttl_str, nb_flags_str; + char *name_str = NULL; + char *ip_str = NULL; + char *ttl_str = NULL, *nb_flags_str = NULL; unsigned int num_ips; - char *name; - struct in_addr *ip_list; + char *name = NULL; + struct in_addr *ip_list = NULL; int type = 0; int nb_flags; int ttl; const char *ptr; - char *p; + char *p = NULL; bool got_token; bool was_ip; int i; unsigned int hash; int version; + TALLOC_CTX *frame = NULL; /* Read a line from the wins.dat file. Strips whitespace from the beginning and end of the line. */ - if (!fgets_slash(line,sizeof(line),fp)) + if (!fgets_slash(line,sizeof(line),fp)) { continue; + } - if (*line == '#') + if (*line == '#') { continue; + } if (strncmp(line,"VERSION ", 8) == 0) { if (sscanf(line,"VERSION %d %u", &version, &hash) != 2 || @@ -645,13 +648,16 @@ bool initialise_wins(void) * time to actually parse them into the ip_list array. */ - if (!next_token(&ptr,name_str,NULL,sizeof(name_str))) { + frame = talloc_stackframe(); + if (!next_token_talloc(frame,&ptr,&name_str,NULL)) { DEBUG(0,("initialise_wins: Failed to parse name when parsing line %s\n", line )); + TALLOC_FREE(frame); continue; } - if (!next_token(&ptr,ttl_str,NULL,sizeof(ttl_str))) { + if (!next_token_talloc(frame,&ptr,ttl_str,NULL)) { DEBUG(0,("initialise_wins: Failed to parse time to live when parsing line %s\n", line )); + TALLOC_FREE(frame); continue; } @@ -660,22 +666,24 @@ bool initialise_wins(void) */ num_ips = 0; do { - got_token = next_token(&ptr,ip_str,NULL,sizeof(ip_str)); + got_token = next_token_talloc(frame,&ptr,&ip_str,NULL); was_ip = False; if(got_token && strchr(ip_str, '.')) { num_ips++; was_ip = True; } - } while( got_token && was_ip); + } while(got_token && was_ip); if(num_ips == 0) { DEBUG(0,("initialise_wins: Missing IP address when parsing line %s\n", line )); + TALLOC_FREE(frame); continue; } if(!got_token) { DEBUG(0,("initialise_wins: Missing nb_flags when parsing line %s\n", line )); + TALLOC_FREE(frame); continue; } @@ -683,20 +691,21 @@ bool initialise_wins(void) if((ip_list = SMB_MALLOC_ARRAY( struct in_addr, num_ips)) == NULL) { DEBUG(0,("initialise_wins: Malloc fail !\n")); x_fclose(fp); + TALLOC_FREE(frame); return False; } /* Reset and re-parse the line. */ ptr = line; - next_token(&ptr,name_str,NULL,sizeof(name_str)); - next_token(&ptr,ttl_str,NULL,sizeof(ttl_str)); + next_token_talloc(frame,&ptr,&name_str,NULL); + next_token_talloc(frame,&ptr,&ttl_str,NULL); for(i = 0; i < num_ips; i++) { - next_token(&ptr, ip_str, NULL, sizeof(ip_str)); + next_token_talloc(frame,&ptr, &ip_str, NULL); (void)interpret_addr2(&ip_list[i], ip_str); } - next_token(&ptr,nb_flags_str,NULL, sizeof(nb_flags_str)); + next_token_talloc(frame,&ptr,&nb_flags_str,NULL); - /* + /* * Deal with SELF or REGISTER name encoding. Default is REGISTER * for compatibility with old nmbds. */ @@ -704,6 +713,7 @@ bool initialise_wins(void) if(nb_flags_str[strlen(nb_flags_str)-1] == 'S') { DEBUG(5,("initialise_wins: Ignoring SELF name %s\n", line)); SAFE_FREE(ip_list); + TALLOC_FREE(frame); continue; } @@ -740,9 +750,10 @@ bool initialise_wins(void) name, type, ttl, inet_ntoa(ip_list[0]), nb_flags)); } + TALLOC_FREE(frame); SAFE_FREE(ip_list); - } - + } + x_fclose(fp); return True; } -- cgit From 0cdcd255a5ab2d776d1f4d010199ca9edd06c5e9 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 8 Dec 2007 11:20:53 +0100 Subject: Fix two incompatible pointer warnings Jeremy, please check (This used to be commit 60500fac30911500eade7c2a9aa13569dcab0911) --- source3/nmbd/nmbd_winsserver.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 7dafa66b11..7344a29fe4 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -655,7 +655,7 @@ bool initialise_wins(void) continue; } - if (!next_token_talloc(frame,&ptr,ttl_str,NULL)) { + if (!next_token_talloc(frame,&ptr,&ttl_str,NULL)) { DEBUG(0,("initialise_wins: Failed to parse time to live when parsing line %s\n", line )); TALLOC_FREE(frame); continue; -- cgit From 7faee02d0d351c5c039e8f1be7e82ce3a93cbe96 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Mon, 10 Dec 2007 11:30:37 -0800 Subject: Remove the char[1024] strings from dynconfig. Replace them with malloc'ing accessor functions. Should save a lot of static space :-). Jeremy. (This used to be commit 52dc5eaef2106015b3a8b659e818bdb15ad94b05) --- source3/nmbd/nmbd.c | 17 ++++++++++------- source3/nmbd/nmbd_winsserver.c | 2 +- 2 files changed, 11 insertions(+), 8 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 52f1cd15f5..344831ddca 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -288,8 +288,8 @@ static bool reload_nmbd_services(bool test) if ( lp_loaded() ) { const char *fname = lp_configfile(); - if (file_exist(fname,NULL) && !strcsequal(fname,dyn_CONFIGFILE)) { - strlcpy(dyn_CONFIGFILE,fname,sizeof(dyn_CONFIGFILE)); + if (file_exist(fname,NULL) && !strcsequal(fname,get_dyn_CONFIGFILE())) { + set_dyn_CONFIGFILE(fname); test = False; } } @@ -297,7 +297,7 @@ static bool reload_nmbd_services(bool test) if ( test && !lp_file_list_changed() ) return(True); - ret = lp_load( dyn_CONFIGFILE, True , False, False, True); + ret = lp_load(get_dyn_CONFIGFILE(), True , False, False, True); /* perhaps the config filename is now set */ if ( !test ) { @@ -710,7 +710,7 @@ static bool open_sockets(bool isdaemon, int port) static bool no_process_group; static bool log_stdout; poptContext pc; - static char *p_lmhosts = dyn_LMHOSTSFILE; + char *p_lmhosts = NULL; int opt; enum { OPT_DAEMON = 1000, @@ -772,7 +772,7 @@ static bool open_sockets(bool isdaemon, int port) if (!override_logfile) { char *logfile = NULL; - if (asprintf(&logfile, "%s/log.nmbd", dyn_LOGFILEBASE) < 0) { + if (asprintf(&logfile, "%s/log.nmbd", get_dyn_LOGFILEBASE()) < 0) { exit(1); } lp_set_logfile(logfile); @@ -903,8 +903,11 @@ static bool open_sockets(bool isdaemon, int port) } /* Load in any static local names. */ - load_lmhosts_file(p_lmhosts); - DEBUG(3,("Loaded hosts file %s\n", p_lmhosts)); + if (p_lmhosts) { + set_dyn_LMHOSTSFILE(p_lmhosts); + } + load_lmhosts_file(get_dyn_LMHOSTSFILE()); + DEBUG(3,("Loaded hosts file %s\n", get_dyn_LMHOSTSFILE())); /* If we are acting as a WINS server, initialise data structures. */ if( !initialise_wins() ) { diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index 7344a29fe4..96938b011a 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -2366,7 +2366,7 @@ void wins_write_database(time_t t, bool background) } } - if (asprintf(&fname, "%s/%s", dyn_STATEDIR(), WINS_LIST) < 0) { + if (asprintf(&fname, "%s/%s", get_dyn_STATEDIR(), WINS_LIST) < 0) { goto err_exit; } /* This is safe as the 0 length means "don't expand". */ -- cgit From 9e733924d9119a3a7a8b755557ffe458dda96d63 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 13 Dec 2007 16:44:24 -0800 Subject: Arg. The fix for CVE-2007-6015 hadn't been merged into 3.2. Do so now.... Jeremy. (This used to be commit 6b1246c29a0241c8e4bb98d659d847d010826b36) --- source3/nmbd/nmbd_packets.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index b78ab5ba7e..349d36ce70 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1918,6 +1918,12 @@ bool send_mailslot(bool unique, const char *mailslot,char *buf, size_t len, /* Setup the smb part. */ ptr -= 4; /* XXX Ugliness because of handling of tcp SMB length. */ memcpy(tmp,ptr,4); + + if (smb_size + 17*2 + strlen(mailslot) + 1 + len > MAX_DGRAM_SIZE) { + DEBUG(0, ("send_mailslot: Cannot write beyond end of packet\n")); + return false; + } + set_message(ptr,17,strlen(mailslot) + 1 + len,True); memcpy(ptr,tmp,4); -- cgit From afc93255d183eefb68e45b8ec6275f6a62cf9795 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 26 Dec 2007 17:12:36 -0800 Subject: Add SMB encryption. Still fixing client decrypt but negotiation works. Jeremy. (This used to be commit d78045601af787731f0737b8627450018902b104) --- source3/nmbd/nmbd_packets.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 349d36ce70..3bb1514203 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1924,7 +1924,7 @@ bool send_mailslot(bool unique, const char *mailslot,char *buf, size_t len, return false; } - set_message(ptr,17,strlen(mailslot) + 1 + len,True); + cli_set_message(ptr,17,strlen(mailslot) + 1 + len,True); memcpy(ptr,tmp,4); SCVAL(ptr,smb_com,SMBtrans); -- cgit From 0090ec236d16a2da7b5432083b079034c642a2fc Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 2 Jan 2008 11:56:07 -0800 Subject: Attempt to fix bug #3617. Mix of patches from Volker and myself. Use standard dlinklist macros. Jeremy. (This used to be commit 1b06ee69f6b737c1d6e7b29f8ae9621e6eb07d27) --- source3/nmbd/nmbd_packets.c | 5 +++++ source3/nmbd/nmbd_responserecordsdb.c | 24 ++---------------------- 2 files changed, 7 insertions(+), 22 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 3bb1514203..c1d373aa18 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1613,6 +1613,8 @@ void retransmit_or_expire_response_records(time_t t) for (subrec = FIRST_SUBNET; subrec; subrec = get_next_subnet_maybe_unicast_or_wins_server(subrec)) { struct response_record *rrec, *nextrrec; + restart: + for (rrec = subrec->responselist; rrec; rrec = nextrrec) { nextrrec = rrec->next; @@ -1651,6 +1653,9 @@ on subnet %s\n", rrec->response_id, inet_ntoa(rrec->packet->ip), subrec->subnet_ no timeout function. */ remove_response_record(subrec, rrec); } + /* We have changed subrec->responselist, + * restart from the beginning of this list. */ + goto restart; } /* !rrec->in_expitation_processing */ } /* rrec->repeat_count > 0 */ } /* rrec->repeat_time <= t */ diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index 22a038ef2e..6498ce04cf 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -31,26 +31,12 @@ int num_response_packets = 0; static void add_response_record(struct subnet_record *subrec, struct response_record *rrec) { - struct response_record *rrec2; - num_response_packets++; /* count of total number of packets still around */ DEBUG(4,("add_response_record: adding response record id:%hu to subnet %s. num_records:%d\n", rrec->response_id, subrec->subnet_name, num_response_packets)); - if (!subrec->responselist) { - subrec->responselist = rrec; - rrec->prev = NULL; - rrec->next = NULL; - return; - } - - for (rrec2 = subrec->responselist; rrec2->next; rrec2 = rrec2->next) - ; - - rrec2->next = rrec; - rrec->next = NULL; - rrec->prev = rrec2; + DLIST_ADD_END(subrec->responselist, rrec, struct response_record *); } /*************************************************************************** @@ -60,13 +46,7 @@ static void add_response_record(struct subnet_record *subrec, void remove_response_record(struct subnet_record *subrec, struct response_record *rrec) { - if (rrec->prev) - rrec->prev->next = rrec->next; - if (rrec->next) - rrec->next->prev = rrec->prev; - - if (subrec->responselist == rrec) - subrec->responselist = rrec->next; + DLIST_REMOVE(subrec->responselist, rrec); if(rrec->userdata) { if(rrec->userdata->free_fn) { -- cgit From 4881ed00ca1d0ab156863c6821db670c70f5d0ea Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 4 Jan 2008 23:26:47 -0800 Subject: More logical operation on bool. Jeremy. (This used to be commit 7e8e91aeb3795d26ae8591665981bc42d8b6122f) --- source3/nmbd/nmbd_elections.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index bafe87c044..b50d215b91 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -336,7 +336,9 @@ bool check_elections(void) for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec)) { struct work_record *work; for (work = subrec->workgrouplist; work; work = work->next) { - run_any_election |= work->RunningElection; + if (work->RunningElection) { + run_any_election = work->RunningElection; + } /* * Start an election if we have any chance of winning. -- cgit From 817e0d899d2604c8f0feabd6d0b4f20eae8bd2a1 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Wed, 9 Jan 2008 14:35:00 -0800 Subject: Ensure we don't take address of one past buffer. Jeremy. (This used to be commit 318cbcfae51fc5dae549c60107d12480d8e478c8) --- source3/nmbd/nmbd_incomingrequests.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index 90773c1395..ebe1948141 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -331,7 +331,7 @@ subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name), /* this is not an exact calculation. the 46 is for the stats buffer and the 60 is to leave room for the header etc */ - bufend = &rdata[MAX_DGRAM_SIZE] - (18 + 46 + 60); + bufend = &rdata[MAX_DGRAM_SIZE-1] - (18 + 46 + 60); countptr = buf = rdata; buf += 1; buf0 = buf; -- cgit From ff98a654d613daad484023250c6619ce09917f6e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 11 Jan 2008 23:56:48 -0800 Subject: Fix CID 475. work should not be checked against NULL here as it can never be null. Jeremy. (This used to be commit ecb52f50fe3ec8beda48b6c88e9a3ae5a6a98d52) --- source3/nmbd/nmbd_incomingdgrams.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index c0aa385ff6..75ab9419c2 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -257,7 +257,7 @@ void process_local_master_announce(struct subnet_record *subrec, struct packet_s uint32 servertype = IVAL(buf,23); fstring comment; unstring work_name; - struct work_record *work; + struct work_record *work = NULL; struct server_record *servrec; unstring source_name; @@ -344,7 +344,7 @@ a local master browser for workgroup %s and we think we are master. Forcing elec * This server is announcing it is going down. Remove it from the * workgroup. */ - if(!is_myname(server_name) && (work != NULL) && + if(!is_myname(server_name) && ((servrec = find_server_in_workgroup( work, server_name))!=NULL)) { remove_server_from_workgroup( work, servrec); } -- cgit From 587cf54c61c9f1f7bcae431a82035fd942716c32 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 23 Jan 2008 11:04:10 +0100 Subject: strtok -> strtok_r (This used to be commit fd34ce437057bb34cdc37f4b066e424000d36789) --- source3/nmbd/nmbd_processlogon.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 0ff0afd12d..10833e8089 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -399,6 +399,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", char *component, *dc, *q1; char *q_orig = q; int str_offset; + char *saveptr; domain = get_mydnsdomname(talloc_tos()); if (!domain) { @@ -444,7 +445,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", str_offset = q - q_orig; dc = domain; q1 = q; - while ((component = strtok(dc, "."))) { + while ((component = strtok_r(dc, ".", &saveptr)) != NULL) { dc = NULL; if (sizeof(outbuf) - PTR_DIFF(q, outbuf) < 1) { return; -- cgit From 0ff38a82632da0eed588e1d90d54c165068c52c9 Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 24 Jan 2008 15:52:45 +0100 Subject: Fix Coverity ID 465 (This used to be commit 8629a0e1c3da7c2d2b0c1d99224177c54bbae930) --- source3/nmbd/nmbd_synclists.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 147df68a69..5a2f5c46b4 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -81,12 +81,14 @@ static void sync_child(char *name, int nm_type, } if (!cli_set_port(cli, 139)) { + cli_shutdown(cli); return; } in_addr_to_sockaddr_storage(&ss, ip); status = cli_connect(cli, name, &ss); if (!NT_STATUS_IS_OK(status)) { + cli_shutdown(cli); return; } -- cgit From 1eb484d4b471c2c040df42a6566cc0805efc071a Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Thu, 24 Jan 2008 16:12:42 +0100 Subject: Fix Coverity ID 454 (This used to be commit 902d1d6709e47fbc8b538f28cb4364b006c431f8) --- source3/nmbd/nmbd.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 344831ddca..378b6f3dbe 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -676,11 +676,18 @@ static bool open_sockets(bool isdaemon, int port) ClientNMB = 0; } + if (ClientNMB == -1) { + return false; + } + ClientDGRAM = open_socket_in(SOCK_DGRAM, DGRAM_PORT, 3, &ss, true); - if (ClientNMB == -1) { + if (ClientDGRAM == -1) { + if (ClientNMB != 0) { + close(ClientNMB); + } return false; } -- cgit From b42a5d68a3ffd88fd60c64b6a75fe2d687d9c92d Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Sat, 26 Jan 2008 10:39:21 +0100 Subject: Convert read_data() to NTSTATUS (This used to be commit af40b71023f8c4a2133d996ea698c72b97624043) --- source3/nmbd/asyncdns.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 33c1cb6cb1..5e5565991e 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -87,8 +87,13 @@ static void asyncdns_process(void) DEBUGLEVEL = -1; while (1) { - if (read_data(fd_in, (char *)&r, sizeof(r), NULL) != sizeof(r)) + NTSTATUS status; + + status = read_data(fd_in, (char *)&r, sizeof(r)); + + if (!NT_STATUS_IS_OK(status)) { break; + } pull_ascii_nstring( qname, sizeof(qname), r.name.name); r.result.s_addr = interpret_addr(qname); @@ -194,7 +199,7 @@ void run_dns_queue(void) struct query_record r; struct packet_struct *p, *p2; struct name_record *namerec; - int size; + NTSTATUS status; if (fd_in == -1) return; @@ -208,11 +213,11 @@ void run_dns_queue(void) start_async_dns(); } - if ((size=read_data(fd_in, (char *)&r, sizeof(r), NULL)) != sizeof(r)) { - if (size) { - DEBUG(0,("Incomplete DNS answer from child!\n")); - fd_in = -1; - } + status = read_data(fd_in, (char *)&r, sizeof(r)); + + if (!NT_STATUS_IS_OK(status)) { + DEBUG(0, ("read from child failed: %s\n", nt_errstr(status))); + fd_in = -1; BlockSignals(True, SIGTERM); return; } -- cgit From 6346ab79a61be7325fdf3f16ac7f002f8128050c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 29 Feb 2008 05:51:09 -0800 Subject: Fix part of bug #3617 from valgrind trace. "Invalid read of size 1" errors. Jeremy. (This used to be commit d954a4954ba8ed6cb2c6074176a6008cfa398dd7) --- source3/nmbd/nmbd_namelistdb.c | 1 - source3/nmbd/nmbd_nameregister.c | 6 ++++-- 2 files changed, 4 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index f9cbcf4f59..6570fd4ec7 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -297,7 +297,6 @@ void standard_success_register(struct subnet_record *subrec, ******************************************************************/ void standard_fail_register( struct subnet_record *subrec, - struct response_record *rrec, struct nmb_name *nmbname ) { struct name_record *namerec; diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index edcf258519..98f129aa89 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -152,10 +152,11 @@ static void register_name_response(struct subnet_record *subrec, if( rrec->success_fn) (*(register_name_success_function)rrec->success_fn)(subrec, rrec->userdata, answer_name, nb_flags, ttl, register_ip); } else { + struct nmb_name qname = *question_name; if( rrec->fail_fn) (*(register_name_fail_function)rrec->fail_fn)(subrec, rrec, question_name); /* Remove the name. */ - standard_fail_register( subrec, rrec, question_name); + standard_fail_register( subrec, &qname); } /* Ensure we don't retry. */ @@ -280,10 +281,11 @@ static void register_name_timeout_response(struct subnet_record *subrec, if( rrec->success_fn) (*(register_name_success_function)rrec->success_fn)(subrec, rrec->userdata, question_name, nb_flags, ttl, registered_ip); } else { + struct nmb_name qname = *question_name; if( rrec->fail_fn) (*(register_name_fail_function)rrec->fail_fn)(subrec, rrec, question_name); /* Remove the name. */ - standard_fail_register( subrec, rrec, question_name); + standard_fail_register( subrec, &qname); } /* Ensure we don't retry. */ -- cgit From 6a7b6a1961b2bb74e25b4134422089f16a32cc9e Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 29 Feb 2008 06:55:33 -0800 Subject: Patch to fix the "Invalid read of size 4" errors. Bug #3617. Jeremy. (This used to be commit fa12667ec284fdda45b79cbf6bf548ab0faae34f) --- source3/nmbd/nmbd_responserecordsdb.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_responserecordsdb.c b/source3/nmbd/nmbd_responserecordsdb.c index 6498ce04cf..b042fb41ed 100644 --- a/source3/nmbd/nmbd_responserecordsdb.c +++ b/source3/nmbd/nmbd_responserecordsdb.c @@ -46,6 +46,24 @@ static void add_response_record(struct subnet_record *subrec, void remove_response_record(struct subnet_record *subrec, struct response_record *rrec) { + /* It is possible this can be called twice, + with a rrec pointer that has been freed. So + before we inderect into rrec, search for it + on the responselist first. Bug #3617. JRA. */ + + struct response_record *p = NULL; + + for (p = subrec->responselist; p; p = p->next) { + if (p == rrec) { + break; + } + } + + if (p == NULL) { + /* We didn't find rrec on the list. */ + return; + } + DLIST_REMOVE(subrec->responselist, rrec); if(rrec->userdata) { -- cgit From 868c5c986aa2a83ad9adcd1c03a75ccfec68fdff Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 6 Mar 2008 17:43:25 -0800 Subject: Fix bug #5267 - nmbd shuts down when network interfaces go down. Cause nmbd to wait for an interface, in a mode where SIGTERM will kills us (same way we wait on startup for an interface). Jeremy. (This used to be commit 5440c752ff270cc674d46f2dfa2ceb47dac030f6) --- source3/nmbd/nmbd.c | 68 ++++++++++++++++++++++++++++++----------------------- 1 file changed, 39 insertions(+), 29 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 378b6f3dbe..00d252940a 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -163,23 +163,31 @@ static void expire_names_and_servers(time_t t) /************************************************************************** ** Reload the list of network interfaces. + Doesn't return until a network interface is up. ************************************************************************** */ -static bool reload_interfaces(time_t t) +static void reload_interfaces(time_t t) { static time_t lastt; int n; struct subnet_record *subrec; - if (t && ((t - lastt) < NMBD_INTERFACES_RELOAD)) return False; + if (t && ((t - lastt) < NMBD_INTERFACES_RELOAD)) { + return; + } + lastt = t; - if (!interfaces_changed()) return False; + if (!interfaces_changed()) { + return; + } /* the list of probed interfaces has changed, we may need to add/remove some subnets */ load_interfaces(); + try_again: + /* find any interfaces that need adding */ for (n=iface_count() - 1; n >= 0; n--) { char str[INET6_ADDRSTRLEN]; @@ -268,12 +276,33 @@ static bool reload_interfaces(time_t t) rescan_listen_set = True; - /* We need to shutdown if there are no subnets... */ + /* We need to wait if there are no subnets... */ if (FIRST_SUBNET == NULL) { - DEBUG(0,("reload_interfaces: No subnets to listen to. Shutting down...\n")); - return True; + void (*saved_handler)(int); + + DEBUG(0,("reload_interfaces: " + "No subnets to listen to. Waiting..\n")); + + /* + * Whilst we're waiting for an interface, allow SIGTERM to + * cause us to exit. + */ + + saved_handler = CatchSignal( SIGTERM, SIGNAL_CAST SIG_DFL ); + + /* We only count IPv4 interfaces here. */ + while (iface_count_v4() == 0) { + sleep(5); + load_interfaces(); + } + + /* + * We got an interface, restore our normal term handler. + */ + + CatchSignal( SIGTERM, SIGNAL_CAST saved_handler ); + goto try_again; } - return False; } /**************************************************************************** ** @@ -310,8 +339,6 @@ static bool reload_nmbd_services(bool test) /**************************************************************************** ** * React on 'smbcontrol nmbd reload-config' in the same way as to SIGHUP - * We use buf here to return bool result to process() when reload_interfaces() - * detects that there are no subnets. **************************************************************************** */ static void msg_reload_nmbd_services(struct messaging_context *msg, @@ -324,14 +351,7 @@ static void msg_reload_nmbd_services(struct messaging_context *msg, dump_all_namelists(); reload_nmbd_services( True ); reopen_logs(); - - if (data->data) { - /* We were called from process() */ - /* If reload_interfaces() returned True */ - /* we need to shutdown if there are no subnets... */ - /* pass this info back to process() */ - *((bool *)data->data) = reload_interfaces(0); - } + reload_interfaces(0); } static void msg_nmbd_send_packet(struct messaging_context *msg, @@ -401,7 +421,6 @@ static void msg_nmbd_send_packet(struct messaging_context *msg, static void process(void) { bool run_election; - bool no_subnets; while( True ) { time_t t = time(NULL); @@ -612,26 +631,17 @@ static void process(void) */ if(reload_after_sighup) { - DATA_BLOB blob = data_blob_const(&no_subnets, - sizeof(no_subnets)); DEBUG( 0, ( "Got SIGHUP dumping debug info.\n" ) ); msg_reload_nmbd_services(nmbd_messaging_context(), NULL, MSG_SMB_CONF_UPDATED, - procid_self(), &blob); + procid_self(), NULL); - if(no_subnets) { - TALLOC_FREE(frame); - return; - } reload_after_sighup = 0; } /* check for new network interfaces */ - if(reload_interfaces(t)) { - TALLOC_FREE(frame); - return; - } + reload_interfaces(t); /* free up temp memory */ TALLOC_FREE(frame); -- cgit From f3d4cb5efa72c8665ed95dad605c7235d9ff568f Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 27 Mar 2008 14:23:20 -0700 Subject: Fix for termination problems when no interfaces found - bug #5267. Jeremy. (This used to be commit 4b03f4eb2da7a523967ace3d13e79406ade07d47) --- source3/nmbd/nmbd.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 00d252940a..9797a7adb6 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -182,11 +182,12 @@ static void reload_interfaces(time_t t) return; } + try_again: + /* the list of probed interfaces has changed, we may need to add/remove some subnets */ load_interfaces(); - try_again: /* find any interfaces that need adding */ for (n=iface_count() - 1; n >= 0; n--) { @@ -278,7 +279,6 @@ static void reload_interfaces(time_t t) /* We need to wait if there are no subnets... */ if (FIRST_SUBNET == NULL) { - void (*saved_handler)(int); DEBUG(0,("reload_interfaces: " "No subnets to listen to. Waiting..\n")); @@ -288,19 +288,28 @@ static void reload_interfaces(time_t t) * cause us to exit. */ - saved_handler = CatchSignal( SIGTERM, SIGNAL_CAST SIG_DFL ); + BlockSignals(false, SIGTERM); /* We only count IPv4 interfaces here. */ - while (iface_count_v4() == 0) { + while (iface_count_v4() == 0 && !got_sig_term) { sleep(5); load_interfaces(); } /* - * We got an interface, restore our normal term handler. + * Handle termination inband. + */ + + if (got_sig_term) { + got_sig_term = 0; + terminate(); + } + + /* + * We got an interface, go back to blocking term. */ - CatchSignal( SIGTERM, SIGNAL_CAST saved_handler ); + BlockSignals(true, SIGTERM); goto try_again; } } -- cgit From 948ebaf0330368ce8fb12ae65f8fcf550a6aab2a Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Thu, 10 Apr 2008 08:56:34 -0700 Subject: Fix the last reported debian problem with nmbd not waiting until interfaces come up. Jeremy. (This used to be commit 59a2f0873c789822d46f862042921a8ba8f2bd28) --- source3/nmbd/nmbd_subnetdb.c | 32 ++++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index d100ad482a..a4422d27d5 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -199,11 +199,16 @@ bool create_subnets(void) int i; struct in_addr unicast_ip, ipzero; - if(num_interfaces == 0) { - void (*saved_handler)(int); + try_interfaces_again: + if (iface_count_v4() == 0) { DEBUG(0,("create_subnets: No local interfaces !\n")); DEBUG(0,("create_subnets: Waiting for an interface to appear ...\n")); + } + + /* We only count IPv4 interfaces here. */ + while (iface_count_v4() == 0) { + void (*saved_handler)(int); /* * Whilst we're waiting for an interface, allow SIGTERM to @@ -212,11 +217,8 @@ bool create_subnets(void) saved_handler = CatchSignal( SIGTERM, SIGNAL_CAST SIG_DFL ); - /* We only count IPv4 interfaces here. */ - while (iface_count_v4() == 0) { - sleep(5); - load_interfaces(); - } + sleep(5); + load_interfaces(); /* * We got an interface, restore our normal term handler. @@ -268,9 +270,19 @@ bool create_subnets(void) /* We must have at least one subnet. */ if (subnetlist == NULL) { - DEBUG(0,("create_subnets: unable to create any subnet from " - "given interfaces. nmbd is terminating\n")); - return False; + void (*saved_handler)(int); + + DEBUG(0,("create_subnets: Unable to create any subnet from " + "given interfaces. Is your interface line in " + "smb.conf correct ?\n")); + + saved_handler = CatchSignal( SIGTERM, SIGNAL_CAST SIG_DFL ); + + sleep(5); + load_interfaces(); + + CatchSignal( SIGTERM, SIGNAL_CAST saved_handler ); + goto try_interfaces_again; } if (lp_we_are_a_wins_server()) { -- cgit From f85c4b6905235d5e11ebeadd3e8216e4ae8cc31c Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Fri, 11 Apr 2008 17:41:49 -0700 Subject: Fix bug #5386, don't keep printing the same waiting error message. Jeremy. (This used to be commit 12e6818df1c77810a59a2896f8c44c91fc24e7ae) --- source3/nmbd/nmbd.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 9797a7adb6..0349445317 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -170,6 +170,7 @@ static void reload_interfaces(time_t t) { static time_t lastt; int n; + bool print_waiting_msg = true; struct subnet_record *subrec; if (t && ((t - lastt) < NMBD_INTERFACES_RELOAD)) { @@ -188,7 +189,6 @@ static void reload_interfaces(time_t t) some subnets */ load_interfaces(); - /* find any interfaces that need adding */ for (n=iface_count() - 1; n >= 0; n--) { char str[INET6_ADDRSTRLEN]; @@ -280,8 +280,11 @@ static void reload_interfaces(time_t t) /* We need to wait if there are no subnets... */ if (FIRST_SUBNET == NULL) { - DEBUG(0,("reload_interfaces: " - "No subnets to listen to. Waiting..\n")); + if (print_waiting_msg) { + DEBUG(0,("reload_interfaces: " + "No subnets to listen to. Waiting..\n")); + print_waiting_msg = false; + } /* * Whilst we're waiting for an interface, allow SIGTERM to -- cgit From e21b283d6713794fb0a415a9313943867812884d Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 1 Apr 2008 14:01:28 +0200 Subject: dbwrap: wait for tdb2 change notifies in smbd, nmbd and winbindd metze (This used to be commit 64450cc1e441355aa8925b7183e90872eeab20b1) --- source3/nmbd/nmbd.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 0349445317..01fdbbc5a4 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -847,6 +847,8 @@ static bool open_sockets(bool isdaemon, int port) DEBUG(0,("nmbd version %s started.\n", SAMBA_VERSION_STRING)); DEBUGADD(0,("%s\n", COPYRIGHT_STARTUP_MESSAGE)); + db_tdb2_setup_messaging(NULL, false); + if ( !reload_nmbd_services(False) ) return(-1); @@ -898,6 +900,10 @@ static bool open_sockets(bool isdaemon, int port) } pidfile_create("nmbd"); + + /* get broadcast messages */ + claim_connection(NULL,"",FLAG_MSG_GENERAL|FLAG_MSG_DBWRAP); + messaging_register(nmbd_messaging_context(), NULL, MSG_FORCE_ELECTION, nmbd_message_election); #if 0 @@ -912,6 +918,8 @@ static bool open_sockets(bool isdaemon, int port) messaging_register(nmbd_messaging_context(), NULL, MSG_SEND_PACKET, msg_nmbd_send_packet); + db_tdb2_setup_messaging(nmbd_messaging_context(), true); + TimeInit(); DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); -- cgit From c5d1a3c710472711baeb8d1b74951f3006f48aaa Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 15 Apr 2008 10:38:21 +0200 Subject: nmbd: call reinit_after_fork() in all needed cases metze (This used to be commit f68829ff14c457bfa98cb2ef9e8ec2e1a0b1d64d) --- source3/nmbd/asyncdns.c | 5 +++++ source3/nmbd/nmbd.c | 5 +++++ 2 files changed, 10 insertions(+) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 5e5565991e..0329491c4a 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -164,6 +164,11 @@ void start_async_dns(void) CatchSignal(SIGHUP, SIG_IGN); CatchSignal(SIGTERM, SIGNAL_CAST sig_term ); + if (!reinit_after_fork(nmbd_messaging_context())) { + DEBUG(0,("reinit_after_fork() failed\n")); + smb_panic("reinit_after_fork() failed"); + } + asyncdns_process(); } diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 01fdbbc5a4..e765fcb725 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -901,6 +901,11 @@ static bool open_sockets(bool isdaemon, int port) pidfile_create("nmbd"); + if (!reinit_after_fork(nmbd_messaging_context())) { + DEBUG(0,("reinit_after_fork() failed\n")); + exit(1); + } + /* get broadcast messages */ claim_connection(NULL,"",FLAG_MSG_GENERAL|FLAG_MSG_DBWRAP); -- cgit From 384282c35f7af5a52125cb02809a0c05d45b1138 Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Tue, 15 Apr 2008 10:50:27 +0200 Subject: nmbd: create the messaging conntext earlier metze (This used to be commit 056ff094ad2c59992cfdb8b29696c08dab4113d7) --- source3/nmbd/nmbd.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index e765fcb725..9396219ea7 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -762,6 +762,8 @@ static bool open_sockets(bool isdaemon, int port) }; TALLOC_CTX *frame = talloc_stackframe(); /* Setup tos. */ + db_tdb2_setup_messaging(NULL, false); + load_case_tables(); global_nmb_port = NMB_PORT; @@ -847,7 +849,16 @@ static bool open_sockets(bool isdaemon, int port) DEBUG(0,("nmbd version %s started.\n", SAMBA_VERSION_STRING)); DEBUGADD(0,("%s\n", COPYRIGHT_STARTUP_MESSAGE)); - db_tdb2_setup_messaging(NULL, false); + if (!lp_load_initial_only(get_dyn_CONFIGFILE())) { + DEBUG(0, ("error opening config file\n")); + exit(1); + } + + if (nmbd_messaging_context() == NULL) { + return 1; + } + + db_tdb2_setup_messaging(nmbd_messaging_context(), true); if ( !reload_nmbd_services(False) ) return(-1); @@ -923,8 +934,6 @@ static bool open_sockets(bool isdaemon, int port) messaging_register(nmbd_messaging_context(), NULL, MSG_SEND_PACKET, msg_nmbd_send_packet); - db_tdb2_setup_messaging(nmbd_messaging_context(), true); - TimeInit(); DEBUG( 3, ( "Opening sockets %d\n", global_nmb_port ) ); -- cgit From bcbac69d1a38e128ffe8b763ac027d6eab33dcec Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Mon, 21 Apr 2008 19:59:27 +0200 Subject: cldap: avoid duplicate definitions so remove ads_cldap.h. Guenther (This used to be commit 538eefe22ad69540b9f73ffaa613d6be045de199) --- source3/nmbd/nmbd_processlogon.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 10833e8089..6e110dd1ca 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -424,8 +424,8 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", } q += 4; - SIVAL(q, 0, ADS_PDC|ADS_GC|ADS_LDAP|ADS_DS| - ADS_KDC|ADS_TIMESERV|ADS_CLOSEST|ADS_WRITABLE); + SIVAL(q, 0, NBT_SERVER_PDC|NBT_SERVER_GC|NBT_SERVER_LDAP|NBT_SERVER_DS| + NBT_SERVER_KDC|NBT_SERVER_TIMESERV|NBT_SERVER_CLOSEST|NBT_SERVER_WRITABLE); q += 4; /* Push Domain GUID */ -- cgit From 0c4093a234dfaca6d363a6e1358f2fbf421dcd3c Mon Sep 17 00:00:00 2001 From: Volker Lendecke Date: Wed, 23 Apr 2008 17:13:50 +0200 Subject: Fix CLEAR_IF_FIRST handling of messages.tdb We now open messages.tdb even before we do the become_daemon. become_daemon() involves a fork and an immediate exit of the parent, thus the parent_is_longlived argument must be set to false in this case. The parent is not really long lived :-) (This used to be commit 4f4781c6d17fe2db34dd5945fec52a7685448aec) --- source3/nmbd/asyncdns.c | 2 +- source3/nmbd/nmbd.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 0329491c4a..ab9b1ed740 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -164,7 +164,7 @@ void start_async_dns(void) CatchSignal(SIGHUP, SIG_IGN); CatchSignal(SIGTERM, SIGNAL_CAST sig_term ); - if (!reinit_after_fork(nmbd_messaging_context())) { + if (!reinit_after_fork(nmbd_messaging_context(), true)) { DEBUG(0,("reinit_after_fork() failed\n")); smb_panic("reinit_after_fork() failed"); } diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 9396219ea7..af4acc84d0 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -912,7 +912,7 @@ static bool open_sockets(bool isdaemon, int port) pidfile_create("nmbd"); - if (!reinit_after_fork(nmbd_messaging_context())) { + if (!reinit_after_fork(nmbd_messaging_context(), false)) { DEBUG(0,("reinit_after_fork() failed\n")); exit(1); } -- cgit From c1562aae9b0293c6f5726482f0c95d65befe8a3a Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 24 Jun 2008 12:44:50 +0200 Subject: nmbd: don't panic if messaging_init() fails - return NULL instead. Michael (This used to be commit e6a403209c29bd2ec2242d654ad45276de02cb44) --- source3/nmbd/nmbd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index af4acc84d0..5126715a47 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -54,7 +54,7 @@ struct messaging_context *nmbd_messaging_context(void) if (!ctx && !(ctx = messaging_init(NULL, server_id_self(), nmbd_event_context()))) { - smb_panic("Could not init nmbd messaging context"); + DEBUG(0, ("Could not init nmbd messaging context.\n")); } return ctx; } -- cgit From 7ec1678d6015ff7a5e262dc95bb6190748f1daff Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 24 Jun 2008 12:46:13 +0200 Subject: nmbd: untangle logic in nmbd_messaging_context() slightly. Michael (This used to be commit 3baf9eb6a2cc6a4a153303b457d3a7067948495e) --- source3/nmbd/nmbd.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 5126715a47..46c3f1dd3c 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -52,8 +52,11 @@ struct messaging_context *nmbd_messaging_context(void) { static struct messaging_context *ctx; - if (!ctx && !(ctx = messaging_init(NULL, server_id_self(), - nmbd_event_context()))) { + if (ctx == NULL) { + ctx = messaging_init(NULL, server_id_self(), + nmbd_event_context()); + } + if (ctx == NULL) { DEBUG(0, ("Could not init nmbd messaging context.\n")); } return ctx; -- cgit From 33e3e94e0cff075ec7d3364c4de73c154369ce06 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 9 Aug 2008 01:03:06 +0200 Subject: nmbd_packets: make queue_packet() public. Michael (This used to be commit 363eb90ce8380ce1bbc74673936ba1e6d7eee23b) --- source3/nmbd/nmbd_packets.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index c1d373aa18..4b97819a14 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -28,8 +28,6 @@ extern int global_nmb_port; extern int num_response_packets; -static void queue_packet(struct packet_struct *packet); - bool rescan_listen_set = False; @@ -1004,7 +1002,7 @@ for id %hu\n", packet_type, nmb_namestr(&orig_nmb->question.question_name), Queue a packet into a packet queue ******************************************************************/ -static void queue_packet(struct packet_struct *packet) +void queue_packet(struct packet_struct *packet) { struct packet_struct *p; -- cgit From 9b9948134eb9d145f5d6610b645440e3e4dd3942 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Sat, 9 Aug 2008 01:04:55 +0200 Subject: nmbd: add support for delayed initial samlogon packages. The hosts or networks configured with "init logon delayed hosts" have their initial samlogon packages (empty username) delayed by the value configured with "init logon delay" (defaulting to 100 milliseconds). This gives the administrator some control over what clients would consider the preferred logon server: they choose the server that repsonds most quickly. Michael (This used to be commit d52b9beede1fb14e1d7e3acd9765d6cd14dfcc3d) --- source3/nmbd/nmbd_processlogon.c | 92 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 86 insertions(+), 6 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 6e110dd1ca..f7990def07 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -31,6 +31,40 @@ struct sam_database_info { uint32 date_lo, date_hi; }; +/** + * check whether the client belongs to the hosts + * for which initial logon should be delayed... + */ +static bool delay_logon(const char *peer_name, const char *peer_addr) +{ + const char **delay_list = lp_init_logon_delayed_hosts(); + const char *peer[2]; + + if (delay_list == NULL) { + return False; + } + + peer[0] = peer_name; + peer[1] = peer_addr; + + return list_match(delay_list, (const char *)peer, client_match); +} + +static void delayed_init_logon_handler(struct event_context *event_ctx, + struct timed_event *te, + const struct timeval *now, + void *private_data) +{ + struct packet_struct *p = (struct packet_struct *)private_data; + + DEBUG(10, ("delayed_init_logon_handler (%lx): re-queuing packet.\n", + (unsigned long)te)); + + queue_packet(p); + + TALLOC_FREE(te); +} + /**************************************************************************** Process a domain logon packet **************************************************************************/ @@ -280,6 +314,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", { fstring getdc_str; fstring source_name; + char *source_addr; char *q = buf + 2; fstring asccomp; @@ -591,13 +626,58 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", pull_ascii_fstring(getdc_str, getdc); pull_ascii_nstring(source_name, sizeof(source_name), dgram->source_name.name); + source_addr = SMB_STRDUP(inet_ntoa(dgram->header.source_ip)); + if (source_addr == NULL) { + DEBUG(3, ("out of memory copying client" + " address string\n")); + return; + } + + /* + * handle delay. + * packets requeued after delay are marked as + * locked. + */ + if ((p->locked == False) && + (strlen(ascuser) == 0) && + delay_logon(source_name, source_addr)) + { + struct timeval when; + + DEBUG(3, ("process_logon_packet: " + "delaying initial logon " + "reply for client %s(%s) for " + "%u milliseconds\n", + source_name, source_addr, + lp_init_logon_delay())); + + when = timeval_current_ofs(0, + lp_init_logon_delay() * 1000); + p->locked = true; + event_add_timed(nmbd_event_context(), + NULL, + when, + "delayed_init_logon", + delayed_init_logon_handler, + p); + } else { + DEBUG(3, ("process_logon_packet: " + "processing delayed initial " + "logon reply for client " + "%s(%s)\n", + source_name, source_addr)); + + p->locked = false; + send_mailslot(true, getdc, + outbuf,PTR_DIFF(q,outbuf), + global_myname(), 0x0, + source_name, + dgram->source_name.name_type, + p->ip, ip, p->port); + } + + SAFE_FREE(source_addr); - send_mailslot(True, getdc, - outbuf,PTR_DIFF(q,outbuf), - global_myname(), 0x0, - source_name, - dgram->source_name.name_type, - p->ip, ip, p->port); break; } -- cgit From 0f41961e4ffaa602a5b19a1e0899bffa491c886f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Thu, 7 Aug 2008 16:20:05 +1000 Subject: first cut at adding full transactions for ctdb to samba3 (This used to be commit f91a3e0f7b7737c1d0667cd961ea950e2b93e592) --- source3/nmbd/nmbd.c | 4 ---- 1 file changed, 4 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 46c3f1dd3c..83005f05bd 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -765,8 +765,6 @@ static bool open_sockets(bool isdaemon, int port) }; TALLOC_CTX *frame = talloc_stackframe(); /* Setup tos. */ - db_tdb2_setup_messaging(NULL, false); - load_case_tables(); global_nmb_port = NMB_PORT; @@ -861,8 +859,6 @@ static bool open_sockets(bool isdaemon, int port) return 1; } - db_tdb2_setup_messaging(nmbd_messaging_context(), true); - if ( !reload_nmbd_services(False) ) return(-1); -- cgit From f23a6b7c93a419d70889f06b7b3ab18725399793 Mon Sep 17 00:00:00 2001 From: Jeremy Allison Date: Tue, 19 Aug 2008 17:30:30 -0700 Subject: Fix bug 5697 nmbd spins in reload_interfaces when only loopback has an IPv4 address reported by Ted Percival . Jeremy. (This used to be commit ab06efccf31fbc899536d2681a2076e6dfd65b9e) --- source3/nmbd/nmbd.c | 4 ++-- source3/nmbd/nmbd_subnetdb.c | 11 ++++++----- 2 files changed, 8 insertions(+), 7 deletions(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd.c b/source3/nmbd/nmbd.c index 83005f05bd..d9f2af4c10 100644 --- a/source3/nmbd/nmbd.c +++ b/source3/nmbd/nmbd.c @@ -296,8 +296,8 @@ static void reload_interfaces(time_t t) BlockSignals(false, SIGTERM); - /* We only count IPv4 interfaces here. */ - while (iface_count_v4() == 0 && !got_sig_term) { + /* We only count IPv4, non-loopback interfaces here. */ + while (iface_count_v4_nl() == 0 && !got_sig_term) { sleep(5); load_interfaces(); } diff --git a/source3/nmbd/nmbd_subnetdb.c b/source3/nmbd/nmbd_subnetdb.c index a4422d27d5..225def52cc 100644 --- a/source3/nmbd/nmbd_subnetdb.c +++ b/source3/nmbd/nmbd_subnetdb.c @@ -195,19 +195,20 @@ struct subnet_record *make_normal_subnet(const struct interface *iface) bool create_subnets(void) { /* We only count IPv4 interfaces whilst we're waiting. */ - int num_interfaces = iface_count_v4(); + int num_interfaces; int i; struct in_addr unicast_ip, ipzero; try_interfaces_again: - if (iface_count_v4() == 0) { - DEBUG(0,("create_subnets: No local interfaces !\n")); + /* Only count IPv4, non-loopback interfaces. */ + if (iface_count_v4_nl() == 0) { + DEBUG(0,("create_subnets: No local IPv4 non-loopback interfaces !\n")); DEBUG(0,("create_subnets: Waiting for an interface to appear ...\n")); } - /* We only count IPv4 interfaces here. */ - while (iface_count_v4() == 0) { + /* We only count IPv4, non-loopback interfaces here. */ + while (iface_count_v4_nl() == 0) { void (*saved_handler)(int); /* -- cgit From f51e1f4f93f61e58a5049d8212da5310a4f65b5d Mon Sep 17 00:00:00 2001 From: Günther Deschner Date: Wed, 20 Aug 2008 18:40:58 +0200 Subject: fix build warning. Guenther (This used to be commit a75055be5ff7ebe3476cfac86c6597a56a843c23) --- source3/nmbd/nmbd_processlogon.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd') diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index f7990def07..474ae1ca18 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -434,7 +434,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", char *component, *dc, *q1; char *q_orig = q; int str_offset; - char *saveptr; + char *saveptr = NULL; domain = get_mydnsdomname(talloc_tos()); if (!domain) { -- cgit