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
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,"/");
*/
update_name_ttl(namerec, ttl);
send_wins_name_registration_response(0, ttl, p);
+ wins_hook("refresh", namerec, ttl);
return;
}
else if(group)
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]);
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;
}
*/
update_name_ttl(namerec, ttl);
send_wins_name_registration_response(0, ttl, p);
+ wins_hook("refresh", namerec, ttl);
return;
}
}
{
update_name_ttl( namerec, ttl );
send_wins_name_registration_response( 0, ttl, p );
+ wins_hook("refresh", namerec, ttl);
return;
}
(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);
}
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);
* 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;
}
}
{
update_name_ttl(namerec, ttl);
send_wins_name_registration_response(0, ttl, p);
+ wins_hook("refresh", namerec, ttl);
return;
}
(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);
}
int ttl = 0;
int i;
- bzero(rdata,6);
+ memset(rdata,'\0',6);
if(rcode == 0)
{
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.
*/
}
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)