summaryrefslogtreecommitdiff
path: root/source3/nmbd/nmbd_namelistdb.c
diff options
context:
space:
mode:
authorChristopher R. Hertel <crh@samba.org>1998-06-09 01:56:18 +0000
committerChristopher R. Hertel <crh@samba.org>1998-06-09 01:56:18 +0000
commit96bc4042779570e6239b2626888ea0ca9be17391 (patch)
treea09e276a5dda748eda4af3e97d46149da6d92c6e /source3/nmbd/nmbd_namelistdb.c
parentae260b9688676afc712fec0890b3cd79dfb53331 (diff)
downloadsamba-96bc4042779570e6239b2626888ea0ca9be17391.tar.gz
samba-96bc4042779570e6239b2626888ea0ca9be17391.tar.bz2
samba-96bc4042779570e6239b2626888ea0ca9be17391.zip
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)
Diffstat (limited to 'source3/nmbd/nmbd_namelistdb.c')
-rw-r--r--source3/nmbd/nmbd_namelistdb.c231
1 files changed, 134 insertions, 97 deletions
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, &registered_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, &registered_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())