diff options
author | Andrew Tridgell <tridge@samba.org> | 2000-03-27 06:24:35 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 2000-03-27 06:24:35 +0000 |
commit | 8128237889de2c2f9f93152e6c6823b7b57fddf2 (patch) | |
tree | 7d3b540a7c4e207a089959f03618bce43d449456 /source | |
parent | d772390b24cc9e2cb3959a494e964f403fd23500 (diff) | |
download | samba-8128237889de2c2f9f93152e6c6823b7b57fddf2.tar.gz samba-8128237889de2c2f9f93152e6c6823b7b57fddf2.tar.xz samba-8128237889de2c2f9f93152e6c6823b7b57fddf2.zip |
more merging of head code into tng (under lukes supervision!)
only 2 files left in source/nmbd/ ...
Diffstat (limited to 'source')
-rw-r--r-- | source/nmbd/nmbd_responserecordsdb.c | 3 | ||||
-rw-r--r-- | source/nmbd/nmbd_sendannounce.c | 12 | ||||
-rw-r--r-- | source/nmbd/nmbd_serverlistdb.c | 5 | ||||
-rw-r--r-- | source/nmbd/nmbd_subnetdb.c | 70 | ||||
-rw-r--r-- | source/nmbd/nmbd_synclists.c | 11 | ||||
-rw-r--r-- | source/nmbd/nmbd_winsproxy.c | 6 | ||||
-rw-r--r-- | source/nmbd/nmbd_winsserver.c | 96 | ||||
-rw-r--r-- | source/nmbd/nmbd_workgroupdb.c | 31 |
8 files changed, 142 insertions, 92 deletions
diff --git a/source/nmbd/nmbd_responserecordsdb.c b/source/nmbd/nmbd_responserecordsdb.c index 0c698760bb6..1b6e1ca16db 100644 --- a/source/nmbd/nmbd_responserecordsdb.c +++ b/source/nmbd/nmbd_responserecordsdb.c @@ -28,7 +28,6 @@ extern int ClientNMB; extern int DEBUGLEVEL; -extern pstring scope; extern struct in_addr ipzero; int num_response_packets = 0; @@ -119,7 +118,7 @@ struct response_record *make_response_record( struct subnet_record *subrec, return NULL; } - bzero((char *)rrec, sizeof(*rrec)); + memset((char *)rrec, '\0', sizeof(*rrec)); rrec->response_id = nmb->header.name_trn_id; diff --git a/source/nmbd/nmbd_sendannounce.c b/source/nmbd/nmbd_sendannounce.c index 38c8deafe72..87115a1eb0d 100644 --- a/source/nmbd/nmbd_sendannounce.c +++ b/source/nmbd/nmbd_sendannounce.c @@ -46,7 +46,7 @@ void send_browser_reset(int reset_type, char *to_name, int to_type, struct in_ad DEBUG(3,("send_browser_reset: sending reset request type %d to %s<%02x> IP %s.\n", reset_type, to_name, to_type, inet_ntoa(to_ip) )); - bzero(outbuf,sizeof(outbuf)); + memset(outbuf,'\0',sizeof(outbuf)); p = outbuf; CVAL(p,0) = ANN_ResetBrowserState; p++; @@ -73,7 +73,7 @@ void broadcast_announce_request(struct subnet_record *subrec, struct work_record DEBUG(3,("broadcast_announce_request: sending announce request for workgroup %s \ to subnet %s\n", work->work_group, subrec->subnet_name)); - bzero(outbuf,sizeof(outbuf)); + memset(outbuf,'\0',sizeof(outbuf)); p = outbuf; CVAL(p,0) = ANN_AnnouncementRequest; p++; @@ -101,7 +101,7 @@ static void send_announcement(struct subnet_record *subrec, int announce_type, pstring outbuf; char *p; - bzero(outbuf,sizeof(outbuf)); + memset(outbuf,'\0',sizeof(outbuf)); p = outbuf+1; CVAL(outbuf,0) = announce_type; @@ -142,7 +142,7 @@ static void send_lm_announcement(struct subnet_record *subrec, int announce_type pstring outbuf; char *p=outbuf; - bzero(outbuf,sizeof(outbuf)); + memset(outbuf,'\0',sizeof(outbuf)); SSVAL(p,0,announce_type); SIVAL(p,2,server_type & ~SV_TYPE_LOCAL_LIST_ONLY); @@ -504,7 +504,7 @@ void announce_remote(time_t t) if (!*s) return; - comment = lp_serverstring(); + comment = string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH); for (ptr=s; next_token(&ptr,s2,NULL,sizeof(s2)); ) { @@ -587,7 +587,7 @@ for workgroup %s on subnet %s.\n", global_myworkgroup, FIRST_SUBNET->subnet_name return; } - bzero(outbuf,sizeof(outbuf)); + memset(outbuf,'\0',sizeof(outbuf)); p = outbuf; CVAL(p,0) = ANN_MasterAnnouncement; p++; diff --git a/source/nmbd/nmbd_serverlistdb.c b/source/nmbd/nmbd_serverlistdb.c index d30e8da64ce..41009bc68f0 100644 --- a/source/nmbd/nmbd_serverlistdb.c +++ b/source/nmbd/nmbd_serverlistdb.c @@ -156,7 +156,7 @@ workgroup %s. This is a bug.\n", name, work->work_group)); return NULL; } - bzero((char *)servrec,sizeof(*servrec)); + memset((char *)servrec,'\0',sizeof(*servrec)); servrec->subnet = work->subnet; @@ -399,7 +399,8 @@ void write_browse_list(time_t t, BOOL force_write) slprintf(tmp, sizeof(tmp)-1, "\"%s\"", my_netbios_names[i]); fprintf(fp, "%-25s ", tmp); fprintf(fp, "%08x ", stype); - slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", lp_serverstring()); + slprintf(tmp, sizeof(tmp)-1, "\"%s\" ", + string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH)); fprintf(fp, "%-30s", tmp); fprintf(fp, "\"%s\"\n", global_myworkgroup); } diff --git a/source/nmbd/nmbd_subnetdb.c b/source/nmbd/nmbd_subnetdb.c index 1b7b2b5da23..37b50f85250 100644 --- a/source/nmbd/nmbd_subnetdb.c +++ b/source/nmbd/nmbd_subnetdb.c @@ -55,22 +55,7 @@ extern uint16 samba_nb_type; /* Samba's NetBIOS name type. */ static void add_subnet(struct subnet_record *subrec) { - struct subnet_record *subrec2; - - if (!subnetlist) - { - subnetlist = subrec; - subrec->prev = NULL; - subrec->next = NULL; - return; - } - - for (subrec2 = subnetlist; subrec2->next; subrec2 = subrec2->next) - ; - - subrec2->next = subrec; - subrec->next = NULL; - subrec->prev = subrec2; + DLIST_ADD(subnetlist, subrec); } /* ************************************************************************** ** @@ -96,19 +81,41 @@ static int namelist_entry_compare( ubi_trItemPtr Item, ubi_trNodePtr Node ) Debug1( "nmbd_subnetdb:namelist_entry_compare()\n" ); Debug1( "%d == memcmp( \"%s\", \"%s\", %d )\n", memcmp( Item, &(NR->name), sizeof(struct nmb_name) ), - nmb_namestr(Iname), nmb_namestr(&NR->name), sizeof(struct nmb_name) ); + nmb_namestr(Iname), nmb_namestr(&NR->name), (int)sizeof(struct nmb_name) ); } return( memcmp( Item, &(NR->name), sizeof(struct nmb_name) ) ); } /* namelist_entry_compare */ + +/**************************************************************************** +stop listening on a subnet +we don't free the record as we don't have proper reference counting for it +yet and it may be in use by a response record + ****************************************************************************/ +void close_subnet(struct subnet_record *subrec) +{ + DLIST_REMOVE(subnetlist, subrec); + + if (subrec->dgram_sock != -1) { + close(subrec->dgram_sock); + subrec->dgram_sock = -1; + } + if (subrec->nmb_sock != -1) { + close(subrec->nmb_sock); + subrec->nmb_sock = -1; + } +} + + + /**************************************************************************** Create a subnet entry. ****************************************************************************/ static struct subnet_record *make_subnet(char *name, enum subnet_type type, - struct in_addr myip, struct in_addr bcast_ip, - struct in_addr mask_ip) + struct in_addr myip, struct in_addr bcast_ip, + struct in_addr mask_ip) { struct subnet_record *subrec = NULL; int nmb_sock, dgram_sock; @@ -170,7 +177,7 @@ static struct subnet_record *make_subnet(char *name, enum subnet_type type, return(NULL); } - bzero( (char *)subrec, sizeof(*subrec) ); + memset( (char *)subrec, '\0', sizeof(*subrec) ); (void)ubi_trInitTree( subrec->namelist, namelist_entry_compare, ubi_trOVERWRITE ); @@ -202,6 +209,23 @@ static struct subnet_record *make_subnet(char *name, enum subnet_type type, return subrec; } + +/**************************************************************************** + Create a normal subnet +**************************************************************************/ +struct subnet_record *make_normal_subnet(struct interface *iface) +{ + struct subnet_record *subrec; + + subrec = make_subnet(inet_ntoa(iface->ip), NORMAL_SUBNET, + iface->ip, iface->bcast, iface->nmask); + if (subrec) { + add_subnet(subrec); + } + return subrec; +} + + /**************************************************************************** Create subnet entries. **************************************************************************/ @@ -225,13 +249,9 @@ BOOL create_subnets(void) for (i = 0 ; i < num_interfaces; i++) { - struct subnet_record *subrec; struct interface *iface = get_interface(i); - if((subrec = make_subnet(inet_ntoa(iface->ip), NORMAL_SUBNET, - iface->ip, iface->bcast,iface->nmask)) == NULL) - return False; - add_subnet(subrec); + if (!make_normal_subnet(iface)) return False; } /* diff --git a/source/nmbd/nmbd_synclists.c b/source/nmbd/nmbd_synclists.c index dae25b6eca3..7bf17903778 100644 --- a/source/nmbd/nmbd_synclists.c +++ b/source/nmbd/nmbd_synclists.c @@ -32,7 +32,6 @@ #include "smb.h" extern int DEBUGLEVEL; -extern pstring scope; struct sync_record { struct sync_record *next, *prev; @@ -40,7 +39,7 @@ struct sync_record { fstring server; pstring fname; struct in_addr ip; - int pid; + pid_t pid; }; /* a linked list of current sync connections */ @@ -77,8 +76,8 @@ static void sync_child(char *name, int nm_type, return; } - make_nmb_name(&calling, local_machine, 0x0 , scope); - make_nmb_name(&called , name , nm_type, scope); + make_nmb_name(&calling, local_machine, 0x0); + make_nmb_name(&called , name , nm_type); if (!cli_session_request(&cli, &calling, &called)) { @@ -103,7 +102,7 @@ static void sync_child(char *name, int nm_type, } /* Fetch a workgroup list. */ - cli_NetServerEnum(&cli, workgroup, + cli_NetServerEnum(&cli, cli.server_domain?cli.server_domain:workgroup, local_type|SV_TYPE_DOMAIN_ENUM, callback); @@ -147,7 +146,7 @@ void sync_browse_lists(struct work_record *work, slprintf(s->fname, sizeof(pstring)-1, "%s/sync.%d", lp_lockdir(), counter++); - string_sub(s->fname,"//", "/"); + all_string_sub(s->fname,"//", "/", 0); DLIST_ADD(syncs, s); diff --git a/source/nmbd/nmbd_winsproxy.c b/source/nmbd/nmbd_winsproxy.c index 43beb9acd85..24ba192cdb3 100644 --- a/source/nmbd/nmbd_winsproxy.c +++ b/source/nmbd/nmbd_winsproxy.c @@ -203,11 +203,11 @@ void make_wins_proxy_name_query_request( struct subnet_record *subrec, struct packet_struct *incoming_packet, struct nmb_name *question_name) { - char ud[sizeof(struct userdata_struct) + sizeof(struct subrec *) + - sizeof(struct packet_struct *)]; + long *ud[(sizeof(struct userdata_struct) + sizeof(struct subrec *) + + sizeof(struct packet_struct *))/sizeof(long *) + 1]; struct userdata_struct *userdata = (struct userdata_struct *)ud; - bzero(ud, sizeof(ud)); + memset(ud, '\0', sizeof(ud)); userdata->copy_fn = wins_proxy_userdata_copy_fn; userdata->free_fn = wins_proxy_userdata_free_fn; diff --git a/source/nmbd/nmbd_winsserver.c b/source/nmbd/nmbd_winsserver.c index 35ca5af62c4..2b99a8ce53b 100644 --- a/source/nmbd/nmbd_winsserver.c +++ b/source/nmbd/nmbd_winsserver.c @@ -30,6 +30,41 @@ extern int DEBUGLEVEL; extern struct in_addr ipzero; +/**************************************************************************** +possibly call the WINS hook external program when a WINS change is made +*****************************************************************************/ +static void wins_hook(char *operation, struct name_record *namerec, int ttl) +{ + pstring command; + char *cmd = lp_wins_hook(); + char *p; + int i; + + if (!cmd || !*cmd) return; + + for (p=namerec->name.name; *p; p++) { + if (!(isalnum((int)*p) || strchr("._-",*p))) { + DEBUG(3,("not calling wins hook for invalid name %s\n", nmb_namestr(&namerec->name))); + return; + } + } + + p = command; + p += slprintf(p, sizeof(command), "%s %s %s %02x %d", + cmd, + operation, + namerec->name.name, + namerec->name.name_type, + ttl); + + for (i=0;i<namerec->data.num_ips;i++) { + p += slprintf(p, sizeof(command) - (p-command), " %s", inet_ntoa(namerec->data.ip[i])); + } + + DEBUG(3,("calling wins hook for %s\n", nmb_namestr(&namerec->name))); + smbrun(command, NULL, False); +} + /**************************************************************************** hash our interfaces and netbios names settings @@ -137,7 +172,6 @@ Load or create the WINS database. BOOL initialise_wins(void) { - pstring fname; time_t time_now = time(NULL); FILE *fp; pstring line; @@ -147,20 +181,10 @@ BOOL initialise_wins(void) add_samba_names_to_subnet(wins_server_subnet); -#ifndef SYNC_DNS - /* Setup the async dns. */ - start_async_dns(); -#endif - - pstrcpy(fname,lp_lockdir()); - trim_string(fname,NULL,"/"); - pstrcat(fname,"/"); - pstrcat(fname,WINS_LIST); - - if((fp = sys_fopen(fname,"r")) == NULL) + if((fp = sys_fopen(lock_path(WINS_LIST),"r")) == NULL) { DEBUG(2,("initialise_wins: Can't open wins database file %s. Error was %s\n", - fname, strerror(errno) )); + WINS_LIST, strerror(errno) )); return True; } @@ -456,6 +480,7 @@ does not match group bit in WINS for this name.\n", nmb_namestr(question), group */ update_name_ttl(namerec, ttl); send_wins_name_registration_response(0, ttl, p); + wins_hook("refresh", namerec, ttl); return; } else if(group) @@ -636,7 +661,7 @@ void wins_process_name_registration_request(struct subnet_record *subrec, int ttl = get_ttl_from_packet(nmb); struct name_record *namerec = NULL; struct in_addr from_ip; - BOOL registering_group_name = (nb_flags & NB_GROUP) ? True : False;; + BOOL registering_group_name = (nb_flags & NB_GROUP) ? True : False; putip((char *)&from_ip,&nmb->additional->rdata[2]); @@ -715,7 +740,7 @@ to register name %s. Name already exists in WINS with source type %d.\n", if(!registering_group_name && (question->name_type == 0x1d)) { DEBUG(3,("wins_process_name_registration_request: Ignoring request \ -to register name %s from IP %s.", nmb_namestr(question), inet_ntoa(p->ip) )); +to register name %s from IP %s.\n", nmb_namestr(question), inet_ntoa(p->ip) )); send_wins_name_registration_response(0, ttl, p); return; } @@ -785,6 +810,7 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio */ update_name_ttl(namerec, ttl); send_wins_name_registration_response(0, ttl, p); + wins_hook("refresh", namerec, ttl); return; } } @@ -801,6 +827,7 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio { update_name_ttl( namerec, ttl ); send_wins_name_registration_response( 0, ttl, p ); + wins_hook("refresh", namerec, ttl); return; } @@ -811,7 +838,7 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio if( namerec != NULL ) { - char ud[sizeof(struct userdata_struct) + sizeof(struct packet_struct *)]; + long *ud[(sizeof(struct userdata_struct) + sizeof(struct packet_struct *))/sizeof(long *) + 1]; struct userdata_struct *userdata = (struct userdata_struct *)ud; /* @@ -858,6 +885,9 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio (void)add_name_to_subnet( subrec, question->name, question->name_type, nb_flags, ttl, REGISTER_NAME, 1, &from_ip ); + if ((namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME))) { + wins_hook("add", namerec, ttl); + } send_wins_name_registration_response(0, ttl, p); } @@ -916,6 +946,7 @@ a subsequent IP addess.\n", nmb_namestr(question_name) )); add_ip_to_name_record(namerec, from_ip); update_name_ttl(namerec, ttl); send_wins_name_registration_response(0, ttl, orig_reg_packet); + wins_hook("add", namerec, ttl); orig_reg_packet->locked = False; free_packet(orig_reg_packet); @@ -1082,11 +1113,16 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio * It's one of our names and one of our IP's. Ensure the IP is in the record and * update the ttl. */ - if(!find_ip_in_name_record(namerec, from_ip)) - add_ip_to_name_record(namerec, from_ip); - update_name_ttl(namerec, ttl); - send_wins_name_registration_response(0, ttl, p); - return; + if(!find_ip_in_name_record(namerec, from_ip)) { + add_ip_to_name_record(namerec, from_ip); + wins_hook("add", namerec, ttl); + } else { + wins_hook("refresh", namerec, ttl); + } + + update_name_ttl(namerec, ttl); + send_wins_name_registration_response(0, ttl, p); + return; } } @@ -1099,6 +1135,7 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio { update_name_ttl(namerec, ttl); send_wins_name_registration_response(0, ttl, p); + wins_hook("refresh", namerec, ttl); return; } @@ -1109,7 +1146,7 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio if(namerec != NULL) { - char ud[sizeof(struct userdata_struct) + sizeof(struct packet_struct *)]; + long *ud[(sizeof(struct userdata_struct) + sizeof(struct packet_struct *))/sizeof(long *) + 1]; struct userdata_struct *userdata = (struct userdata_struct *)ud; /* @@ -1139,9 +1176,12 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio * the recursion desired flag is not set (you were right Luke :-). * This function should *only* be called from the WINS server * code. JRA. + * + * Note that this packet is sent to the current owner of the name, + * not the person who sent the packet */ - query_name_from_wins_server( p->ip, + query_name_from_wins_server( namerec->data.ip[0], question->name, question->name_type, wins_multihomed_register_query_success, @@ -1158,6 +1198,10 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio (void)add_name_to_subnet( subrec, question->name, question->name_type, nb_flags, ttl, REGISTER_NAME, 1, &from_ip ); + if ((namerec = find_name_on_subnet(subrec, question, FIND_ANY_NAME))) { + wins_hook("add", namerec, ttl); + } + send_wins_name_registration_response(0, ttl, p); } @@ -1253,7 +1297,7 @@ void send_wins_name_query_response(int rcode, struct packet_struct *p, int ttl = 0; int i; - bzero(rdata,6); + memset(rdata,'\0',6); if(rcode == 0) { @@ -1495,6 +1539,8 @@ release name %s as IP %s is not one of the known IP's for this name.\n", send_wins_name_release_response(0, p); remove_ip_from_name_record(namerec, from_ip); + wins_hook("delete", namerec, 0); + /* * Remove the name entirely if no IP addresses left. */ @@ -1552,7 +1598,7 @@ void wins_write_database(BOOL background) } slprintf(fname,sizeof(fname),"%s/%s", lp_lockdir(), WINS_LIST); - string_sub(fname,"//", "/"); + all_string_sub(fname,"//", "/", 0); slprintf(fnamenew,sizeof(fnamenew),"%s.%u", fname, (unsigned int)getpid()); if((fp = sys_fopen(fnamenew,"w")) == NULL) diff --git a/source/nmbd/nmbd_workgroupdb.c b/source/nmbd/nmbd_workgroupdb.c index 0f66b140a81..5514e78dc1c 100644 --- a/source/nmbd/nmbd_workgroupdb.c +++ b/source/nmbd/nmbd_workgroupdb.c @@ -43,26 +43,9 @@ int workgroup_count = 0; /* unique index key: one for each workgroup */ static void add_workgroup(struct subnet_record *subrec, struct work_record *work) { - struct work_record *w2; - - work->subnet = subrec; - - if (!subrec->workgrouplist) - { - subrec->workgrouplist = work; - work->prev = NULL; - work->next = NULL; - return; - } - - for (w2 = subrec->workgrouplist; w2->next; w2 = w2->next) - ; - - w2->next = work; - work->next = NULL; - work->prev = w2; - - subrec->work_changed = True; + work->subnet = subrec; + DLIST_ADD(subrec->workgrouplist, work); + subrec->work_changed = True; } /**************************************************************************** @@ -80,7 +63,7 @@ static struct work_record *create_workgroup(char *name, int ttl) DEBUG(0,("create_workgroup: malloc fail !\n")); return NULL; } - bzero((char *)work, sizeof(*work)); + memset((char *)work, '\0', sizeof(*work)); StrnCpy(work->work_group,name,sizeof(work->work_group)-1); work->serverlist = NULL; @@ -254,7 +237,8 @@ void initiate_myworkgroup_startup(struct subnet_record *subrec, struct work_reco if we are so configured. */ if ((subrec != unicast_subnet) && (subrec != remote_broadcast_subnet) && - (subrec != wins_server_subnet) && lp_preferred_master()) + (subrec != wins_server_subnet) && lp_preferred_master() && + lp_local_master()) { DEBUG(3, ("initiate_myworkgroup_startup: preferred master startup for \ workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name)); @@ -283,7 +267,8 @@ workgroup %s on subnet %s\n", work->work_group, subrec->subnet_name)); SV_TYPE_DOMAIN_MASTER|SV_TYPE_DOMAIN_MEMBER); create_server_on_workgroup(work,name,stype|SV_TYPE_LOCAL_LIST_ONLY, - PERMANENT_TTL, lp_serverstring()); + PERMANENT_TTL, + string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH)); DEBUG(3,("initiate_myworkgroup_startup: Added server name entry %s \ on subnet %s\n", name, subrec->subnet_name)); } |