X-Git-Url: http://git.samba.org/?a=blobdiff_plain;f=source3%2Fnmbd%2Fnmbd_winsserver.c;h=20436c5813059af0427931af69c78384c0d69a5b;hb=30567b8f9bc0f5a39a3a65039277aa5f839622cd;hp=0f27351d2d324650ff16b2f3d6372530bf32c7d0;hpb=4d5f58c2b945e7a2263ba42749f73c7ba72ab3c7;p=samba.git
diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c
index 0f27351d2d3..20436c58130 100644
--- a/source3/nmbd/nmbd_winsserver.c
+++ b/source3/nmbd/nmbd_winsserver.c
@@ -6,7 +6,7 @@
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
@@ -15,8 +15,7 @@
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
- along with this program; if not, write to the Free Software
- Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ along with this program. If not, see .
Converted to store WINS data in a tdb. Dec 2005. JRA.
*/
@@ -125,7 +124,7 @@ static struct name_record *wins_record_to_name_record(TDB_DATA key, TDB_DATA dat
namerec->data.refresh_time = (time_t)refresh_time;
namerec->data.id = id_low;
#if defined(HAVE_LONGLONG)
- namerec->data.id |= ((SMB_BIG_UINT)id_high << 32);
+ namerec->data.id |= ((uint64_t)id_high << 32);
#endif
namerec->data.wins_ip.s_addr = saddr;
namerec->data.wins_flags = wins_flags,
@@ -208,7 +207,7 @@ static TDB_DATA name_to_key(const struct nmb_name *nmbname)
on the linked list. We will free this later in XXXX().
*****************************************************************************/
-struct name_record *find_name_on_wins_subnet(const struct nmb_name *nmbname, BOOL self_only)
+struct name_record *find_name_on_wins_subnet(const struct nmb_name *nmbname, bool self_only)
{
TDB_DATA data, key;
struct name_record *nr = NULL;
@@ -263,7 +262,7 @@ struct name_record *find_name_on_wins_subnet(const struct nmb_name *nmbname, BOO
Overwrite or add a given name in the wins.tdb.
*****************************************************************************/
-static BOOL store_or_replace_wins_namerec(const struct name_record *namerec, int tdb_flag)
+static bool store_or_replace_wins_namerec(const struct name_record *namerec, int tdb_flag)
{
TDB_DATA key, data;
int ret;
@@ -289,7 +288,7 @@ static BOOL store_or_replace_wins_namerec(const struct name_record *namerec, int
Overwrite a given name in the wins.tdb.
*****************************************************************************/
-BOOL wins_store_changed_namerec(const struct name_record *namerec)
+bool wins_store_changed_namerec(const struct name_record *namerec)
{
return store_or_replace_wins_namerec(namerec, TDB_REPLACE);
}
@@ -298,7 +297,7 @@ BOOL wins_store_changed_namerec(const struct name_record *namerec)
Primary interface into creating and overwriting records in the wins.tdb.
*****************************************************************************/
-BOOL add_name_to_wins_subnet(const struct name_record *namerec)
+bool add_name_to_wins_subnet(const struct name_record *namerec)
{
return store_or_replace_wins_namerec(namerec, TDB_INSERT);
}
@@ -308,7 +307,7 @@ BOOL add_name_to_wins_subnet(const struct name_record *namerec)
on the linked list.
*****************************************************************************/
-BOOL remove_name_from_wins_namelist(struct name_record *namerec)
+bool remove_name_from_wins_namelist(struct name_record *namerec)
{
TDB_DATA key;
int ret;
@@ -413,14 +412,14 @@ static void update_wins_flag(struct name_record *namerec, int flags)
Return the general ID value and increase it if requested.
*****************************************************************************/
-static void get_global_id_and_update(SMB_BIG_UINT *current_id, BOOL update)
+static void get_global_id_and_update(uint64_t *current_id, bool update)
{
/*
* it's kept as a static here, to prevent people from messing
* with the value directly
*/
- static SMB_BIG_UINT general_id = 1;
+ static uint64_t general_id = 1;
DEBUG(5,("get_global_id_and_update: updating version ID: %d\n", (int)general_id));
@@ -438,10 +437,11 @@ static void get_global_id_and_update(SMB_BIG_UINT *current_id, BOOL update)
static void wins_hook(const char *operation, struct name_record *namerec, int ttl)
{
- pstring command;
+ char *command = NULL;
char *cmd = lp_wins_hook();
char *p, *namestr;
int i;
+ TALLOC_CTX *ctx = talloc_tos();
wins_store_changed_namerec(namerec);
@@ -463,27 +463,36 @@ static void wins_hook(const char *operation, struct name_record *namerec, int tt
*p = 0;
}
- p = command;
- p += slprintf(p, sizeof(command)-1, "%s %s %s %02x %d",
- cmd,
- operation,
- namestr,
- namerec->name.name_type,
- ttl);
+ command = talloc_asprintf(ctx,
+ "%s %s %s %02x %d",
+ cmd,
+ operation,
+ namestr,
+ namerec->name.name_type,
+ ttl);
+ if (!command) {
+ return;
+ }
for (i=0;idata.num_ips;i++) {
- p += slprintf(p, sizeof(command) - (p-command) -1, " %s", inet_ntoa(namerec->data.ip[i]));
+ command = talloc_asprintf_append(command,
+ " %s",
+ inet_ntoa(namerec->data.ip[i]));
+ if (!command) {
+ return;
+ }
}
DEBUG(3,("calling wins hook for %s\n", nmb_namestr(&namerec->name)));
smbrun(command, NULL);
+ TALLOC_FREE(command);
}
/****************************************************************************
Determine if this packet should be allocated to the WINS server.
*****************************************************************************/
-BOOL packet_is_for_wins_server(struct packet_struct *packet)
+bool packet_is_for_wins_server(struct packet_struct *packet)
{
struct nmb_packet *nmb = &packet->packet.nmb;
@@ -563,18 +572,18 @@ static int get_ttl_from_packet(struct nmb_packet *nmb)
Load or create the WINS database.
*****************************************************************************/
-BOOL initialise_wins(void)
+bool initialise_wins(void)
{
time_t time_now = time(NULL);
XFILE *fp;
- pstring line;
+ char line[1024];
if(!lp_we_are_a_wins_server()) {
return True;
}
/* Open the wins.tdb. */
- wins_tdb = tdb_open_log(lock_path("wins.tdb"), 0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST, O_CREAT|O_RDWR, 0600);
+ wins_tdb = tdb_open_log(state_path("wins.tdb"), 0, TDB_DEFAULT|TDB_CLEAR_IF_FIRST, O_CREAT|O_RDWR, 0600);
if (!wins_tdb) {
DEBUG(0,("initialise_wins: failed to open wins.tdb. Error was %s\n",
strerror(errno) ));
@@ -585,35 +594,40 @@ BOOL initialise_wins(void)
add_samba_names_to_subnet(wins_server_subnet);
- if((fp = x_fopen(lock_path(WINS_LIST),O_RDONLY,0)) == NULL) {
+ if((fp = x_fopen(state_path(WINS_LIST),O_RDONLY,0)) == NULL) {
DEBUG(2,("initialise_wins: Can't open wins database file %s. Error was %s\n",
WINS_LIST, strerror(errno) ));
return True;
}
while (!x_feof(fp)) {
- pstring name_str, ip_str, ttl_str, nb_flags_str;
+ char *name_str = NULL;
+ char *ip_str = NULL;
+ char *ttl_str = NULL, *nb_flags_str = NULL;
unsigned int num_ips;
- pstring name;
- struct in_addr *ip_list;
+ char *name = NULL;
+ struct in_addr *ip_list = NULL;
int type = 0;
int nb_flags;
int ttl;
const char *ptr;
- char *p;
- BOOL got_token;
- BOOL was_ip;
+ char *p = NULL;
+ bool got_token;
+ bool was_ip;
int i;
unsigned int hash;
int version;
+ TALLOC_CTX *frame = NULL;
/* Read a line from the wins.dat file. Strips whitespace
from the beginning and end of the line. */
- if (!fgets_slash(line,sizeof(pstring),fp))
+ if (!fgets_slash(line,sizeof(line),fp)) {
continue;
-
- if (*line == '#')
+ }
+
+ if (*line == '#') {
continue;
+ }
if (strncmp(line,"VERSION ", 8) == 0) {
if (sscanf(line,"VERSION %d %u", &version, &hash) != 2 ||
@@ -627,20 +641,23 @@ BOOL initialise_wins(void)
ptr = line;
- /*
+ /*
* Now we handle multiple IP addresses per name we need
* to iterate over the line twice. The first time to
* determine how many IP addresses there are, the second
* time to actually parse them into the ip_list array.
*/
- if (!next_token(&ptr,name_str,NULL,sizeof(name_str))) {
+ frame = talloc_stackframe();
+ if (!next_token_talloc(frame,&ptr,&name_str,NULL)) {
DEBUG(0,("initialise_wins: Failed to parse name when parsing line %s\n", line ));
+ TALLOC_FREE(frame);
continue;
}
- if (!next_token(&ptr,ttl_str,NULL,sizeof(ttl_str))) {
+ if (!next_token_talloc(frame,&ptr,&ttl_str,NULL)) {
DEBUG(0,("initialise_wins: Failed to parse time to live when parsing line %s\n", line ));
+ TALLOC_FREE(frame);
continue;
}
@@ -649,22 +666,24 @@ BOOL initialise_wins(void)
*/
num_ips = 0;
do {
- got_token = next_token(&ptr,ip_str,NULL,sizeof(ip_str));
+ got_token = next_token_talloc(frame,&ptr,&ip_str,NULL);
was_ip = False;
if(got_token && strchr(ip_str, '.')) {
num_ips++;
was_ip = True;
}
- } while( got_token && was_ip);
+ } while(got_token && was_ip);
if(num_ips == 0) {
DEBUG(0,("initialise_wins: Missing IP address when parsing line %s\n", line ));
+ TALLOC_FREE(frame);
continue;
}
if(!got_token) {
DEBUG(0,("initialise_wins: Missing nb_flags when parsing line %s\n", line ));
+ TALLOC_FREE(frame);
continue;
}
@@ -672,20 +691,21 @@ BOOL initialise_wins(void)
if((ip_list = SMB_MALLOC_ARRAY( struct in_addr, num_ips)) == NULL) {
DEBUG(0,("initialise_wins: Malloc fail !\n"));
x_fclose(fp);
+ TALLOC_FREE(frame);
return False;
}
-
+
/* Reset and re-parse the line. */
ptr = line;
- next_token(&ptr,name_str,NULL,sizeof(name_str));
- next_token(&ptr,ttl_str,NULL,sizeof(ttl_str));
+ next_token_talloc(frame,&ptr,&name_str,NULL);
+ next_token_talloc(frame,&ptr,&ttl_str,NULL);
for(i = 0; i < num_ips; i++) {
- next_token(&ptr, ip_str, NULL, sizeof(ip_str));
- ip_list[i] = *interpret_addr2(ip_str);
+ next_token_talloc(frame,&ptr, &ip_str, NULL);
+ ip_list[i] = interpret_addr2(ip_str);
}
- next_token(&ptr,nb_flags_str,NULL, sizeof(nb_flags_str));
+ next_token_talloc(frame,&ptr,&nb_flags_str,NULL);
- /*
+ /*
* Deal with SELF or REGISTER name encoding. Default is REGISTER
* for compatibility with old nmbds.
*/
@@ -693,21 +713,22 @@ BOOL initialise_wins(void)
if(nb_flags_str[strlen(nb_flags_str)-1] == 'S') {
DEBUG(5,("initialise_wins: Ignoring SELF name %s\n", line));
SAFE_FREE(ip_list);
+ TALLOC_FREE(frame);
continue;
}
-
+
if(nb_flags_str[strlen(nb_flags_str)-1] == 'R') {
nb_flags_str[strlen(nb_flags_str)-1] = '\0';
}
-
+
/* Netbios name. # divides the name from the type (hex): netbios#xx */
- pstrcpy(name,name_str);
-
+ name = name_str;
+
if((p = strchr(name,'#')) != NULL) {
*p = 0;
sscanf(p+1,"%x",&type);
}
-
+
/* Decode the netbios flags (hex) and the time-to-live (in seconds). */
sscanf(nb_flags_str,"%x",&nb_flags);
sscanf(ttl_str,"%d",&ttl);
@@ -717,7 +738,7 @@ BOOL initialise_wins(void)
if(ttl != PERMANENT_TTL) {
ttl -= time_now;
}
-
+
DEBUG( 4, ("initialise_wins: add name: %s#%02x ttl = %d first IP %s flags = %2x\n",
name, type, ttl, inet_ntoa(ip_list[0]), nb_flags));
@@ -729,9 +750,10 @@ BOOL initialise_wins(void)
name, type, ttl, inet_ntoa(ip_list[0]), nb_flags));
}
+ TALLOC_FREE(frame);
SAFE_FREE(ip_list);
- }
-
+ }
+
x_fclose(fp);
return True;
}
@@ -805,14 +827,15 @@ void wins_process_name_refresh_request( struct subnet_record *subrec,
{
struct nmb_packet *nmb = &p->packet.nmb;
struct nmb_name *question = &nmb->question.question_name;
- BOOL bcast = nmb->header.nm_flags.bcast;
+ bool bcast = nmb->header.nm_flags.bcast;
uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
- BOOL group = (nb_flags & NB_GROUP) ? True : False;
+ bool group = (nb_flags & NB_GROUP) ? True : False;
struct name_record *namerec = NULL;
int ttl = get_ttl_from_packet(nmb);
struct in_addr from_ip;
- struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0");
+ struct in_addr our_fake_ip;
+ our_fake_ip = interpret_addr2("0.0.0.0");
putip( (char *)&from_ip, &nmb->additional->rdata[2] );
if(bcast) {
@@ -915,7 +938,7 @@ void wins_process_name_refresh_request( struct subnet_record *subrec,
* if the record is a replica:
* we take ownership and update the version ID.
*/
- if (!ip_equal(namerec->data.wins_ip, our_fake_ip)) {
+ if (!ip_equal_v4(namerec->data.wins_ip, our_fake_ip)) {
update_wins_owner(namerec, our_fake_ip);
get_global_id_and_update(&namerec->data.id, True);
}
@@ -991,7 +1014,7 @@ static void wins_register_query_success(struct subnet_record *subrec,
DEBUG(3,("wins_register_query_success: Original client at IP %s still wants the \
name %s. Rejecting registration request.\n", inet_ntoa(ip), nmb_namestr(question_name) ));
- send_wins_name_registration_response(RFS_ERR, 0, orig_reg_packet);
+ send_wins_name_registration_response(ACT_ERR, 0, orig_reg_packet);
orig_reg_packet->locked = False;
free_packet(orig_reg_packet);
@@ -1031,7 +1054,7 @@ static void wins_register_query_fail(struct subnet_record *subrec,
namerec = find_name_on_subnet(subrec, question_name, FIND_ANY_NAME);
if ((namerec != NULL) && (namerec->data.source == REGISTER_NAME) &&
- ip_equal(rrec->packet->ip, *namerec->data.ip)) {
+ ip_equal_v4(rrec->packet->ip, *namerec->data.ip)) {
remove_name_from_namelist( subrec, namerec);
namerec = NULL;
}
@@ -1111,14 +1134,15 @@ void wins_process_name_registration_request(struct subnet_record *subrec,
unstring name;
struct nmb_packet *nmb = &p->packet.nmb;
struct nmb_name *question = &nmb->question.question_name;
- BOOL bcast = nmb->header.nm_flags.bcast;
+ bool bcast = nmb->header.nm_flags.bcast;
uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
int ttl = get_ttl_from_packet(nmb);
struct name_record *namerec = NULL;
struct in_addr from_ip;
- BOOL registering_group_name = (nb_flags & NB_GROUP) ? True : False;
- struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0");
+ bool registering_group_name = (nb_flags & NB_GROUP) ? True : False;
+ struct in_addr our_fake_ip;
+ our_fake_ip = interpret_addr2("0.0.0.0");
putip((char *)&from_ip,&nmb->additional->rdata[2]);
if(bcast) {
@@ -1193,7 +1217,7 @@ to register name %s. Name already exists in WINS with source type %d.\n",
*/
if(registering_group_name && (question->name_type != 0x1c)) {
- from_ip = *interpret_addr2("255.255.255.255");
+ from_ip = interpret_addr2("255.255.255.255");
}
/*
@@ -1274,7 +1298,7 @@ already exists in WINS as a GROUP name.\n", nmb_namestr(question) ));
if ( namerec != NULL ) {
pull_ascii_nstring(name, sizeof(name), namerec->name.name);
if( is_myname(name) ) {
- if(!ismyip(from_ip)) {
+ if(!ismyip_v4(from_ip)) {
DEBUG(3,("wins_process_name_registration_request: Attempt to register name %s. Name \
is one of our (WINS server) names. Denying registration.\n", nmb_namestr(question) ));
send_wins_name_registration_response(RFS_ERR, 0, p);
@@ -1305,8 +1329,8 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio
if( !registering_group_name
&& (namerec != NULL)
&& (namerec->data.num_ips == 1)
- && ip_equal( namerec->data.ip[0], from_ip )
- && ip_equal(namerec->data.wins_ip, our_fake_ip) ) {
+ && ip_equal_v4( namerec->data.ip[0], from_ip )
+ && ip_equal_v4(namerec->data.wins_ip, our_fake_ip) ) {
update_name_ttl( namerec, ttl );
wins_hook("refresh", namerec, ttl);
send_wins_name_registration_response( 0, ttl, p );
@@ -1398,8 +1422,9 @@ static void wins_multihomed_register_query_success(struct subnet_record *subrec,
struct name_record *namerec = NULL;
struct in_addr from_ip;
int ttl;
- struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0");
+ struct in_addr our_fake_ip;
+ our_fake_ip = interpret_addr2("0.0.0.0");
memcpy((char *)&orig_reg_packet, userdata->data, sizeof(struct packet_struct *));
nmb = &orig_reg_packet->packet.nmb;
@@ -1481,15 +1506,16 @@ void wins_process_multihomed_name_registration_request( struct subnet_record *su
{
struct nmb_packet *nmb = &p->packet.nmb;
struct nmb_name *question = &nmb->question.question_name;
- BOOL bcast = nmb->header.nm_flags.bcast;
+ bool bcast = nmb->header.nm_flags.bcast;
uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
int ttl = get_ttl_from_packet(nmb);
struct name_record *namerec = NULL;
struct in_addr from_ip;
- BOOL group = (nb_flags & NB_GROUP) ? True : False;
- struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0");
+ bool group = (nb_flags & NB_GROUP) ? True : False;
+ struct in_addr our_fake_ip;
unstring qname;
+ our_fake_ip = interpret_addr2("0.0.0.0");
putip((char *)&from_ip,&nmb->additional->rdata[2]);
if(bcast) {
@@ -1596,7 +1622,7 @@ already exists in WINS as a GROUP name.\n", nmb_namestr(question) ));
*/
if((namerec != NULL) && (is_myname(namerec->name.name)) ) {
- if(!ismyip(from_ip)) {
+ if(!ismyip_v4(from_ip)) {
DEBUG(3,("wins_process_multihomed_name_registration_request: Attempt to register name %s. Name \
is one of our (WINS server) names. Denying registration.\n", nmb_namestr(question) ));
send_wins_name_registration_response(RFS_ERR, 0, p);
@@ -1634,7 +1660,7 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio
* If it's a replica, we need to become the wins owner
* to force the replication
*/
- if (!ip_equal(namerec->data.wins_ip, our_fake_ip)) {
+ if (!ip_equal_v4(namerec->data.wins_ip, our_fake_ip)) {
get_global_id_and_update(&namerec->data.id, True);
update_wins_owner(namerec, our_fake_ip);
update_wins_flag(namerec, WINS_ACTIVE);
@@ -1995,11 +2021,11 @@ void wins_process_name_release_request(struct subnet_record *subrec,
{
struct nmb_packet *nmb = &p->packet.nmb;
struct nmb_name *question = &nmb->question.question_name;
- BOOL bcast = nmb->header.nm_flags.bcast;
+ bool bcast = nmb->header.nm_flags.bcast;
uint16 nb_flags = get_nb_flags(nmb->additional->rdata);
struct name_record *namerec = NULL;
struct in_addr from_ip;
- BOOL releasing_group_name = (nb_flags & NB_GROUP) ? True : False;;
+ bool releasing_group_name = (nb_flags & NB_GROUP) ? True : False;;
putip((char *)&from_ip,&nmb->additional->rdata[2]);
@@ -2111,10 +2137,11 @@ release name %s as this record is not active anymore.\n", nmb_namestr(question)
static int wins_processing_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
{
time_t t = *(time_t *)state;
- BOOL store_record = False;
+ bool store_record = False;
struct name_record *namerec = NULL;
- struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0");
+ struct in_addr our_fake_ip;
+ our_fake_ip = interpret_addr2("0.0.0.0");
if (kbuf.dsize != sizeof(unstring) + 1) {
return 0;
}
@@ -2139,8 +2166,8 @@ static int wins_processing_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA
}
/* handle records, samba is the wins owner */
- if (ip_equal(namerec->data.wins_ip, our_fake_ip)) {
- switch (namerec->data.wins_flags | WINS_STATE_MASK) {
+ if (ip_equal_v4(namerec->data.wins_ip, our_fake_ip)) {
+ switch (namerec->data.wins_flags & WINS_STATE_MASK) {
case WINS_ACTIVE:
namerec->data.wins_flags&=~WINS_STATE_MASK;
namerec->data.wins_flags|=WINS_RELEASED;
@@ -2165,7 +2192,7 @@ static int wins_processing_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA
goto done;
}
} else {
- switch (namerec->data.wins_flags | WINS_STATE_MASK) {
+ switch (namerec->data.wins_flags & WINS_STATE_MASK) {
case WINS_ACTIVE:
/* that's not as MS says it should be */
namerec->data.wins_flags&=~WINS_STATE_MASK;
@@ -2303,13 +2330,14 @@ static int wins_writedb_traverse_fn(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA db
}
-void wins_write_database(time_t t, BOOL background)
+void wins_write_database(time_t t, bool background)
{
static time_t last_write_time = 0;
- pstring fname, fnamenew;
+ char *fname = NULL;
+ char *fnamenew = NULL;
XFILE *fp;
-
+
if (background) {
if (!last_write_time) {
last_write_time = t;
@@ -2333,32 +2361,42 @@ void wins_write_database(time_t t, BOOL background)
if (tdb_reopen(wins_tdb)) {
DEBUG(0,("wins_write_database: tdb_reopen failed. Error was %s\n",
strerror(errno)));
+ _exit(0);
return;
}
}
- slprintf(fname,sizeof(fname)-1,"%s/%s", lp_lockdir(), WINS_LIST);
+ if (!(fname = state_path(WINS_LIST))) {
+ goto err_exit;
+ }
+ /* This is safe as the 0 length means "don't expand". */
all_string_sub(fname,"//", "/", 0);
- slprintf(fnamenew,sizeof(fnamenew)-1,"%s.%u", fname, (unsigned int)sys_getpid());
+
+ if (asprintf(&fnamenew, "%s.%u", fname, (unsigned int)sys_getpid()) < 0) {
+ goto err_exit;
+ }
if((fp = x_fopen(fnamenew,O_WRONLY|O_CREAT,0644)) == NULL) {
DEBUG(0,("wins_write_database: Can't open %s. Error was %s\n", fnamenew, strerror(errno)));
- if (background) {
- _exit(0);
- }
- return;
+ goto err_exit;
}
DEBUG(4,("wins_write_database: Dump of WINS name list.\n"));
x_fprintf(fp,"VERSION %d %u\n", WINS_VERSION, 0);
-
+
tdb_traverse(wins_tdb, wins_writedb_traverse_fn, fp);
x_fclose(fp);
chmod(fnamenew,0644);
unlink(fname);
rename(fnamenew,fname);
+
+ err_exit:
+
+ SAFE_FREE(fnamenew);
+ TALLOC_FREE(fname);
+
if (background) {
_exit(0);
}
@@ -2380,10 +2418,11 @@ void nmbd_wins_new_entry(struct messaging_context *msg,
struct name_record *namerec = NULL;
struct name_record *new_namerec = NULL;
struct nmb_name question;
- BOOL overwrite=False;
- struct in_addr our_fake_ip = *interpret_addr2("0.0.0.0");
+ bool overwrite=False;
+ struct in_addr our_fake_ip;
int i;
+ our_fake_ip = interpret_addr2("0.0.0.0");
if (buf==NULL) {
return;
}
@@ -2424,16 +2463,16 @@ void nmbd_wins_new_entry(struct messaging_context *msg,
if (namerec->data.wins_flags&WINS_UNIQUE && record->wins_flags&WINS_UNIQUE) {
/* the database record is a replica */
- if (!ip_equal(namerec->data.wins_ip, our_fake_ip)) {
+ if (!ip_equal_v4(namerec->data.wins_ip, our_fake_ip)) {
if (namerec->data.wins_flags&WINS_ACTIVE && record->wins_flags&WINS_TOMBSTONED) {
- if (ip_equal(namerec->data.wins_ip, record->wins_ip))
+ if (ip_equal_v4(namerec->data.wins_ip, record->wins_ip))
overwrite=True;
} else
overwrite=True;
} else {
/* we are the wins owner of the database record */
/* the 2 records have the same IP address */
- if (ip_equal(namerec->data.ip[0], record->ip[0])) {
+ if (ip_equal_v4(namerec->data.ip[0], record->ip[0])) {
if (namerec->data.wins_flags&WINS_ACTIVE && record->wins_flags&WINS_TOMBSTONED)
get_global_id_and_update(&namerec->data.id, True);
else
@@ -2485,10 +2524,10 @@ void nmbd_wins_new_entry(struct messaging_context *msg,
overwrite=True;
}
else {
- if (ip_equal(record->wins_ip, namerec->data.wins_ip))
+ if (ip_equal_v4(record->wins_ip, namerec->data.wins_ip))
overwrite=True;
- if (ip_equal(namerec->data.wins_ip, our_fake_ip))
+ if (ip_equal_v4(namerec->data.wins_ip, our_fake_ip))
if (namerec->data.wins_flags&WINS_UNIQUE)
get_global_id_and_update(&namerec->data.id, True);
@@ -2497,7 +2536,7 @@ void nmbd_wins_new_entry(struct messaging_context *msg,
if (record->wins_flags&WINS_ACTIVE && namerec->data.wins_flags&WINS_ACTIVE)
if (namerec->data.wins_flags&WINS_UNIQUE ||
namerec->data.wins_flags&WINS_MHOMED)
- if (ip_equal(record->wins_ip, namerec->data.wins_ip))
+ if (ip_equal_v4(record->wins_ip, namerec->data.wins_ip))
overwrite=True;
}