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/nmbd_namelistdb.c | 586 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 586 insertions(+) create mode 100644 source3/nmbd/nmbd_namelistdb.c (limited to 'source3/nmbd/nmbd_namelistdb.c') 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); +} -- 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/nmbd_namelistdb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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 -- 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/nmbd_namelistdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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; -- 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_namelistdb.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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"); -- 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_namelistdb.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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_namelistdb.c | 231 ++++++++++++++++++++++++----------------- 1 file changed, 134 insertions(+), 97 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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()) -- 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/nmbd_namelistdb.c') 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_namelistdb.c | 357 ++++++++++++++++++++++------------------- 1 file changed, 190 insertions(+), 167 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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 ); } -- 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_namelistdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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 ); } -- 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_namelistdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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; -- 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_namelistdb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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, -- 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_namelistdb.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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; } -- 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_namelistdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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 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_namelistdb.c | 15 --------------- 1 file changed, 15 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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. * ************************************************************************** ** -- 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/nmbd_namelistdb.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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: -- 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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) { -- 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 ++ 1 file changed, 2 insertions(+) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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 */ /* ************************************************************************** ** -- 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/nmbd_namelistdb.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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 ) -- 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 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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; } -- 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_namelistdb.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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; -- 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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. */ -- 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 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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 ); } -- 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_namelistdb.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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); } /**************************************************************************** -- 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/nmbd_namelistdb.c | 2 -- 1 file changed, 2 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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 */ -- 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_namelistdb.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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 ) ) -- 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/nmbd_namelistdb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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 -- 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_namelistdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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 */ -- 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_namelistdb.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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. */ -- 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 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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; -- 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_namelistdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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. -- 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/nmbd_namelistdb.c | 800 ++++++++++++++++++++--------------------- 1 file changed, 380 insertions(+), 420 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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 ); } -- 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/nmbd_namelistdb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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 { -- 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/nmbd_namelistdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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 ); -- 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_namelistdb.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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; -- 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_namelistdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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"); -- 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/nmbd_namelistdb.c') 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/nmbd_namelistdb.c | 327 ++++++++++++++++++++++++----------------- 1 file changed, 190 insertions(+), 137 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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 ); } -- 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/nmbd_namelistdb.c') 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 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 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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); -- 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 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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"); } -- 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 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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", -- 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/nmbd_namelistdb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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, -- 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/nmbd_namelistdb.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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 . */ -- 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/nmbd_namelistdb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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; -- 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_namelistdb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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; } -- 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/nmbd_namelistdb.c') 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 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 - 1 file changed, 1 deletion(-) (limited to 'source3/nmbd/nmbd_namelistdb.c') 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; -- cgit