77
77
Remove a name from the namelist.
78
78
***************************************************************************/
80
static void update_name_in_namelist( struct subnet_record *subrec,
81
struct name_record *namerec )
80
void remove_name_from_namelist(struct subnet_record *subrec,
81
struct name_record *namerec )
83
struct name_record *oldrec = NULL;
85
ubi_trInsert( subrec->namelist, namerec, &(namerec->name), &oldrec );
87
SAFE_FREE( oldrec->data.ip );
83
if (subrec == wins_server_subnet)
84
remove_name_from_wins_namelist(namerec);
86
subrec->namelist_changed = True;
87
DLIST_REMOVE(subrec->namelist, namerec);
92
/**************************************************************************
93
Remove a name from the namelist.
94
***************************************************************************/
96
void remove_name_from_namelist( struct subnet_record *subrec,
97
struct name_record *namerec )
99
ubi_trRemove( subrec->namelist, namerec );
100
90
SAFE_FREE(namerec->data.ip);
101
91
ZERO_STRUCTP(namerec);
102
92
SAFE_FREE(namerec);
103
subrec->namelist_changed = True;
106
95
/**************************************************************************
111
100
const struct nmb_name *nmbname,
114
struct nmb_name uc_name[1];
103
struct nmb_name uc_name;
115
104
struct name_record *name_ret;
117
upcase_name( uc_name, nmbname );
118
name_ret = (struct name_record *)ubi_trFind( subrec->namelist, uc_name );
106
upcase_name( &uc_name, nmbname );
108
if (subrec == wins_server_subnet) {
109
return find_name_on_wins_subnet(&uc_name, self_only);
112
for( name_ret = subrec->namelist; name_ret; name_ret = name_ret->next) {
113
if (memcmp(&uc_name, &name_ret->name, sizeof(struct nmb_name)) == 0) {
120
119
/* Self names only - these include permanent names. */
121
120
if( self_only && (name_ret->data.source != SELF_NAME) && (name_ret->data.source != PERMANENT_NAME) ) {
122
121
DEBUG( 9, ( "find_name_on_subnet: on subnet %s - self name %s NOT FOUND\n",
123
122
subrec->subnet_name, nmb_namestr(nmbname) ) );
127
126
DEBUG( 9, ("find_name_on_subnet: on subnet %s - found name %s source=%d\n",
171
170
namerec->data.refresh_time = time_now + MIN((ttl/2), MAX_REFRESH_TIME);
173
namerec->subnet->namelist_changed = True;
172
if (namerec->subnet == wins_server_subnet) {
173
wins_store_changed_namerec(namerec);
175
namerec->subnet->namelist_changed = True;
176
179
/**************************************************************************
177
180
Add an entry to a subnet name list.
178
181
***********************************************************************/
180
struct name_record *add_name_to_subnet( struct subnet_record *subrec,
185
enum name_source source,
187
struct in_addr *iplist)
183
BOOL add_name_to_subnet( struct subnet_record *subrec,
188
enum name_source source,
190
struct in_addr *iplist)
189
193
struct name_record *namerec;
190
194
time_t time_now = time(NULL);
192
196
namerec = SMB_MALLOC_P(struct name_record);
193
197
if( NULL == namerec ) {
194
198
DEBUG( 0, ( "add_name_to_subnet: malloc fail.\n" ) );
198
202
memset( (char *)namerec, '\0', sizeof(*namerec) );
417
437
/*******************************************************************
418
Expires old names in a subnet namelist.
438
Expires old names in a subnet namelist.
439
NB. Does not touch the wins_subnet - no wins specific processing here.
419
440
******************************************************************/
421
void expire_names_on_subnet(struct subnet_record *subrec, time_t t)
442
static void expire_names_on_subnet(struct subnet_record *subrec, time_t t)
423
444
struct name_record *namerec;
424
445
struct name_record *next_namerec;
426
for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); namerec; namerec = next_namerec ) {
427
next_namerec = (struct name_record *)ubi_trNext( namerec );
447
for( namerec = subrec->namelist; namerec; namerec = next_namerec ) {
448
next_namerec = namerec->next;
428
449
if( (namerec->data.death_time != PERMANENT_TTL) && (namerec->data.death_time < t) ) {
429
450
if( namerec->data.source == SELF_NAME ) {
430
451
DEBUG( 3, ( "expire_names_on_subnet: Subnet %s not expiring SELF \
505
527
Dump a name_record struct.
506
528
**************************************************************************/
508
static void dump_subnet_namelist( struct subnet_record *subrec, XFILE *fp)
530
void dump_name_record( struct name_record *namerec, XFILE *fp)
510
struct name_record *namerec;
511
532
const char *src_type;
536
x_fprintf(fp,"\tName = %s\t", nmb_namestr(&namerec->name));
537
switch(namerec->data.source) {
539
src_type = "LMHOSTS_NAME";
541
case WINS_PROXY_NAME:
542
src_type = "WINS_PROXY_NAME";
545
src_type = "REGISTER_NAME";
548
src_type = "SELF_NAME";
551
src_type = "DNS_NAME";
554
src_type = "DNSFAIL_NAME";
557
src_type = "PERMANENT_NAME";
560
src_type = "unknown!";
564
x_fprintf(fp,"Source = %s\nb_flags = %x\t", src_type, namerec->data.nb_flags);
566
if(namerec->data.death_time != PERMANENT_TTL) {
568
tm = localtime(&namerec->data.death_time);
576
x_fprintf(fp, "death_time = %s\t", asct);
578
x_fprintf(fp, "death_time = PERMANENT\t");
581
if(namerec->data.refresh_time != PERMANENT_TTL) {
583
tm = localtime(&namerec->data.refresh_time);
591
x_fprintf(fp, "refresh_time = %s\n", asct);
593
x_fprintf(fp, "refresh_time = PERMANENT\n");
596
x_fprintf(fp, "\t\tnumber of IPS = %d", namerec->data.num_ips);
597
for(i = 0; i < namerec->data.num_ips; i++) {
598
x_fprintf(fp, "\t%s", inet_ntoa(namerec->data.ip[i]));
601
x_fprintf(fp, "\n\n");
605
/****************************************************************************
606
Dump the contents of the namelists on all the subnets (including unicast)
607
into a file. Initiated by SIGHUP - used to debug the state of the namelists.
608
**************************************************************************/
610
static void dump_subnet_namelist( struct subnet_record *subrec, XFILE *fp)
612
struct name_record *namerec;
515
613
x_fprintf(fp, "Subnet %s\n----------------------\n", subrec->subnet_name);
516
for( namerec = (struct name_record *)ubi_trFirst( subrec->namelist ); namerec;
517
namerec = (struct name_record *)ubi_trNext( namerec ) ) {
519
x_fprintf(fp,"\tName = %s\t", nmb_namestr(&namerec->name));
520
switch(namerec->data.source) {
522
src_type = "LMHOSTS_NAME";
524
case WINS_PROXY_NAME:
525
src_type = "WINS_PROXY_NAME";
528
src_type = "REGISTER_NAME";
531
src_type = "SELF_NAME";
534
src_type = "DNS_NAME";
537
src_type = "DNSFAIL_NAME";
540
src_type = "PERMANENT_NAME";
543
src_type = "unknown!";
547
x_fprintf(fp,"Source = %s\nb_flags = %x\t", src_type, namerec->data.nb_flags);
549
if(namerec->data.death_time != PERMANENT_TTL) {
550
tm = localtime(&namerec->data.death_time);
551
x_fprintf(fp, "death_time = %s\t", asctime(tm));
553
x_fprintf(fp, "death_time = PERMANENT\t");
556
if(namerec->data.refresh_time != PERMANENT_TTL) {
557
tm = localtime(&namerec->data.refresh_time);
558
x_fprintf(fp, "refresh_time = %s\n", asctime(tm));
560
x_fprintf(fp, "refresh_time = PERMANENT\n");
563
x_fprintf(fp, "\t\tnumber of IPS = %d", namerec->data.num_ips);
564
for(i = 0; i < namerec->data.num_ips; i++) {
565
x_fprintf(fp, "\t%s", inet_ntoa(namerec->data.ip[i]));
568
x_fprintf(fp, "\n\n");
614
for( namerec = subrec->namelist; namerec; namerec = namerec->next) {
615
dump_name_record(namerec, fp);
590
for( subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec) )
637
for (subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_INCLUDING_UNICAST(subrec)) {
591
638
dump_subnet_namelist( subrec, fp );
593
if( !we_are_a_wins_client() )
641
if (!we_are_a_wins_client()) {
594
642
dump_subnet_namelist( unicast_subnet, fp );
596
if( remote_broadcast_subnet->namelist != NULL )
645
if (remote_broadcast_subnet->namelist != NULL) {
597
646
dump_subnet_namelist( remote_broadcast_subnet, fp );
599
if( wins_server_subnet != NULL )
600
dump_subnet_namelist( wins_server_subnet, fp );
649
if (wins_server_subnet != NULL) {
650
dump_wins_subnet_namelist(fp );