~ubuntu-branches/ubuntu/gutsy/samba/gutsy-updates

« back to all changes in this revision

Viewing changes to source/nmbd/nmbd_namelistdb.c

  • Committer: Bazaar Package Importer
  • Author(s): Andrew Mitchell
  • Date: 2006-11-28 20:14:37 UTC
  • mfrom: (0.10.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20061128201437-a6x4lzlhempazocp
Tags: 3.0.23d-1ubuntu1
* Merge from debian unstable.
* Drop python2.4-samba, replace with python-samba. Added Conflicts/Replaces
  on python2.4-samba
* Drop track-connection-dos.patch, ubuntu-winbind-panic.patch, 
  ubuntu-fix-ldap.patch, ubuntu-setlocale.patch, ubuntu-setlocale-fixes.patch
* Remaining Ubuntu changes:
  - Revert Debian's installation of mount.cifs and umount.cifs as suid
  - Comment out the default [homes] shares and add more verbose comments to
    explain what they do and how they work (closes: launchpad.net/27608)
  - Add a "valid users = %S" stanza to the commented-out [homes] section, to
    show users how to restrict access to \\server\username to only username.
  - Change the (commented-out) "printer admin" example to use "@lpadmin"
    instead of "@ntadmin", since the lpadmin group is used for spool admin.
  - Alter the panic-action script to encourage users to report their
    bugs in Ubuntu packages to Ubuntu, rather than reporting to Debian.
    Modify text to more closely match the Debian script
  - Munge our init script to deal with the fact that our implementation
    (or lack thereof) of log_daemon_msg and log_progress_msg differs
    from Debian's implementation of the same (Ubuntu #19691)
  - Kept ubuntu-auxsrc.patch: some auxilliary sources (undocumented in 
    previous changelogs)
  - Set default workgroup to MSHOME

Show diffs side-by-side

added added

removed removed

Lines of Context:
77
77
 Remove a name from the namelist.
78
78
***************************************************************************/
79
79
 
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 )
82
82
{
83
 
        struct name_record *oldrec = NULL;
84
 
 
85
 
        ubi_trInsert( subrec->namelist, namerec, &(namerec->name), &oldrec );
86
 
        if( oldrec ) {
87
 
                SAFE_FREE( oldrec->data.ip );
88
 
                SAFE_FREE( oldrec );
 
83
        if (subrec == wins_server_subnet) 
 
84
                remove_name_from_wins_namelist(namerec);
 
85
        else {
 
86
                subrec->namelist_changed = True;
 
87
                DLIST_REMOVE(subrec->namelist, namerec);
89
88
        }
90
 
}
91
 
 
92
 
/**************************************************************************
93
 
 Remove a name from the namelist.
94
 
***************************************************************************/
95
 
 
96
 
void remove_name_from_namelist( struct subnet_record *subrec, 
97
 
                                struct name_record   *namerec )
98
 
{
99
 
        ubi_trRemove( subrec->namelist, namerec );
 
89
 
100
90
        SAFE_FREE(namerec->data.ip);
101
91
        ZERO_STRUCTP(namerec);
102
92
        SAFE_FREE(namerec);
103
 
        subrec->namelist_changed = True;
104
93
}
105
94
 
106
95
/**************************************************************************
111
100
                                const struct nmb_name *nmbname,
112
101
                                BOOL self_only)
113
102
{
114
 
        struct nmb_name     uc_name[1];
 
103
        struct nmb_name uc_name;
115
104
        struct name_record *name_ret;
116
105
 
117
 
        upcase_name( uc_name, nmbname );
118
 
        name_ret = (struct name_record *)ubi_trFind( subrec->namelist, uc_name );
 
106
        upcase_name( &uc_name, nmbname );
 
107
        
 
108
        if (subrec == wins_server_subnet) {
 
109
                return find_name_on_wins_subnet(&uc_name, self_only);
 
110
        }
 
111
 
 
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) {
 
114
                        break;
 
115
                }
 
116
        }
 
117
 
119
118
        if( name_ret ) {
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) ) );
124
 
                        return( NULL );
 
123
                        return NULL;
125
124
                }
126
125
 
127
126
                DEBUG( 9, ("find_name_on_subnet: on subnet %s - found name %s source=%d\n",
170
169
 
171
170
        namerec->data.refresh_time = time_now + MIN((ttl/2), MAX_REFRESH_TIME);
172
171
 
173
 
        namerec->subnet->namelist_changed = True;
 
172
        if (namerec->subnet == wins_server_subnet) {
 
173
                wins_store_changed_namerec(namerec);
 
174
        } else {
 
175
                namerec->subnet->namelist_changed = True;
 
176
        }
174
177
}
175
178
 
176
179
/**************************************************************************
177
180
 Add an entry to a subnet name list.
178
181
***********************************************************************/
179
182
 
180
 
struct name_record *add_name_to_subnet( struct subnet_record *subrec,
181
 
                                        const char           *name,
182
 
                                        int                   type,
183
 
                                        uint16                nb_flags,
184
 
                                        int                   ttl,
185
 
                                        enum name_source      source,
186
 
                                        int                   num_ips,
187
 
                                        struct in_addr       *iplist)
 
183
BOOL add_name_to_subnet( struct subnet_record *subrec,
 
184
                        const char *name,
 
185
                        int type,
 
186
                        uint16 nb_flags,
 
187
                        int ttl,
 
188
                        enum name_source source,
 
189
                        int num_ips,
 
190
                        struct in_addr *iplist)
188
191
{
 
192
        BOOL ret = False;
189
193
        struct name_record *namerec;
190
194
        time_t time_now = time(NULL);
191
195
 
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" ) );
195
 
                return( NULL );
 
199
                return False;
196
200
        }
197
201
 
198
202
        memset( (char *)namerec, '\0', sizeof(*namerec) );
201
205
                DEBUG( 0, ( "add_name_to_subnet: malloc fail when creating ip_flgs.\n" ) );
202
206
                ZERO_STRUCTP(namerec);
203
207
                SAFE_FREE(namerec);
204
 
                return NULL;
 
208
                return False;
205
209
        }
206
210
 
207
211
        namerec->subnet = subrec;
234
238
 
235
239
        namerec->data.refresh_time = time_now + MIN((ttl/2), MAX_REFRESH_TIME);
236
240
 
237
 
        /* Now add the record to the name list. */    
238
 
        update_name_in_namelist( subrec, namerec );
239
 
 
240
241
        DEBUG( 3, ( "add_name_to_subnet: Added netbios name %s with first IP %s \
241
242
ttl=%d nb_flags=%2x to subnet %s\n",
242
243
                nmb_namestr( &namerec->name ),
245
246
                (unsigned int)nb_flags,
246
247
                subrec->subnet_name ) );
247
248
 
248
 
        subrec->namelist_changed = True;
249
 
 
250
 
        return(namerec);
 
249
        /* Now add the record to the name list. */    
 
250
 
 
251
        if (subrec == wins_server_subnet) {
 
252
                ret = add_name_to_wins_subnet(namerec);
 
253
                /* Free namerec - it's stored in the tdb. */
 
254
                SAFE_FREE(namerec->data.ip);
 
255
                SAFE_FREE(namerec);
 
256
        } else {
 
257
                DLIST_ADD(subrec->namelist, namerec);
 
258
                subrec->namelist_changed = True;
 
259
                ret = True;
 
260
        }
 
261
 
 
262
        return ret;
251
263
}
252
264
 
253
265
/*******************************************************************
311
323
        }
312
324
 
313
325
        namerec->data.num_ips--;
314
 
        namerec->subnet->namelist_changed = True;
 
326
        if (namerec->subnet == wins_server_subnet) {
 
327
                wins_store_changed_namerec(namerec);
 
328
        } else {
 
329
                namerec->subnet->namelist_changed = True;
 
330
        }
315
331
}
316
332
 
317
333
/*******************************************************************
357
373
        namerec->data.ip = new_list;
358
374
        namerec->data.num_ips += 1;
359
375
 
360
 
        namerec->subnet->namelist_changed = True;
 
376
        if (namerec->subnet == wins_server_subnet) {
 
377
                wins_store_changed_namerec(namerec);
 
378
        } else {
 
379
                namerec->subnet->namelist_changed = True;
 
380
        }
361
381
}
362
382
 
363
383
/*******************************************************************
406
426
                if( namerec->data.num_ips == orig_num ) {
407
427
                        DEBUG( 0, ( "standard_success_release: Name release for name %s IP %s \
408
428
on subnet %s. This ip is not known for this name.\n", nmb_namestr(nmbname), inet_ntoa(released_ip), subrec->subnet_name ) );
409
 
        }
 
429
                }
410
430
        }
411
431
 
412
432
        if( namerec->data.num_ips == 0 ) {
415
435
}
416
436
 
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
******************************************************************/
420
441
 
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)
422
443
{
423
444
        struct name_record *namerec;
424
445
        struct name_record *next_namerec;
425
446
 
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 \
443
464
}
444
465
 
445
466
/*******************************************************************
446
 
  Expires old names in all subnet namelists.
 
467
 Expires old names in all subnet namelists.
 
468
 NB. Does not touch the wins_subnet.
447
469
******************************************************************/
448
470
 
449
471
void expire_names(time_t t)
505
527
 Dump a name_record struct.
506
528
**************************************************************************/
507
529
 
508
 
static void dump_subnet_namelist( struct subnet_record *subrec, XFILE *fp)
 
530
void dump_name_record( struct name_record *namerec, XFILE *fp)
509
531
{
510
 
        struct name_record *namerec;
511
532
        const char *src_type;
512
533
        struct tm *tm;
513
534
        int i;
514
535
 
 
536
        x_fprintf(fp,"\tName = %s\t", nmb_namestr(&namerec->name));
 
537
        switch(namerec->data.source) {
 
538
                case LMHOSTS_NAME:
 
539
                        src_type = "LMHOSTS_NAME";
 
540
                        break;
 
541
                case WINS_PROXY_NAME:
 
542
                        src_type = "WINS_PROXY_NAME";
 
543
                        break;
 
544
                case REGISTER_NAME:
 
545
                        src_type = "REGISTER_NAME";
 
546
                        break;
 
547
                case SELF_NAME:
 
548
                        src_type = "SELF_NAME";
 
549
                        break;
 
550
                case DNS_NAME:
 
551
                        src_type = "DNS_NAME";
 
552
                        break;
 
553
                case DNSFAIL_NAME:
 
554
                        src_type = "DNSFAIL_NAME";
 
555
                        break;
 
556
                case PERMANENT_NAME:
 
557
                        src_type = "PERMANENT_NAME";
 
558
                        break;
 
559
                default:
 
560
                        src_type = "unknown!";
 
561
                        break;
 
562
        }
 
563
 
 
564
        x_fprintf(fp,"Source = %s\nb_flags = %x\t", src_type, namerec->data.nb_flags);
 
565
 
 
566
        if(namerec->data.death_time != PERMANENT_TTL) {
 
567
                const char *asct;
 
568
                tm = localtime(&namerec->data.death_time);
 
569
                if (!tm) {
 
570
                        return;
 
571
                }
 
572
                asct = asctime(tm);
 
573
                if (!asct) {
 
574
                        return;
 
575
                }
 
576
                x_fprintf(fp, "death_time = %s\t", asct);
 
577
        } else {
 
578
                x_fprintf(fp, "death_time = PERMANENT\t");
 
579
        }
 
580
 
 
581
        if(namerec->data.refresh_time != PERMANENT_TTL) {
 
582
                const char *asct;
 
583
                tm = localtime(&namerec->data.refresh_time);
 
584
                if (!tm) {
 
585
                        return;
 
586
                }
 
587
                asct = asctime(tm);
 
588
                if (!asct) {
 
589
                        return;
 
590
                }
 
591
                x_fprintf(fp, "refresh_time = %s\n", asct);
 
592
        } else {
 
593
                x_fprintf(fp, "refresh_time = PERMANENT\n");
 
594
        }
 
595
 
 
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]));
 
599
        }
 
600
 
 
601
        x_fprintf(fp, "\n\n");
 
602
        
 
603
}
 
604
 
 
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
**************************************************************************/
 
609
 
 
610
static void dump_subnet_namelist( struct subnet_record *subrec, XFILE *fp)
 
611
{
 
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 ) ) {
518
 
 
519
 
                x_fprintf(fp,"\tName = %s\t", nmb_namestr(&namerec->name));
520
 
                switch(namerec->data.source) {
521
 
                        case LMHOSTS_NAME:
522
 
                                src_type = "LMHOSTS_NAME";
523
 
                                break;
524
 
                        case WINS_PROXY_NAME:
525
 
                                src_type = "WINS_PROXY_NAME";
526
 
                                break;
527
 
                        case REGISTER_NAME:
528
 
                                src_type = "REGISTER_NAME";
529
 
                                break;
530
 
                        case SELF_NAME:
531
 
                                src_type = "SELF_NAME";
532
 
                                break;
533
 
                        case DNS_NAME:
534
 
                                src_type = "DNS_NAME";
535
 
                                break;
536
 
                        case DNSFAIL_NAME:
537
 
                                src_type = "DNSFAIL_NAME";
538
 
                                break;
539
 
                        case PERMANENT_NAME:
540
 
                                src_type = "PERMANENT_NAME";
541
 
                                break;
542
 
                        default:
543
 
                                src_type = "unknown!";
544
 
                                break;
545
 
                }
546
 
 
547
 
                x_fprintf(fp,"Source = %s\nb_flags = %x\t", src_type, namerec->data.nb_flags);
548
 
 
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));
552
 
                } else {
553
 
                        x_fprintf(fp, "death_time = PERMANENT\t");
554
 
                }
555
 
 
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));
559
 
                } else {
560
 
                        x_fprintf(fp, "refresh_time = PERMANENT\n");
561
 
                }
562
 
 
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]));
566
 
        }
567
 
 
568
 
                x_fprintf(fp, "\n\n");
 
614
        for( namerec = subrec->namelist; namerec; namerec = namerec->next) {
 
615
                dump_name_record(namerec, fp);
569
616
        }
570
617
}
571
618
 
587
634
                return;
588
635
        }
589
636
      
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 );
 
639
        }
592
640
 
593
 
        if( !we_are_a_wins_client() )
 
641
        if (!we_are_a_wins_client()) {
594
642
                dump_subnet_namelist( unicast_subnet, fp );
 
643
        }
595
644
 
596
 
        if( remote_broadcast_subnet->namelist != NULL )
 
645
        if (remote_broadcast_subnet->namelist != NULL) {
597
646
                dump_subnet_namelist( remote_broadcast_subnet, fp );
598
 
 
599
 
        if( wins_server_subnet != NULL )
600
 
                dump_subnet_namelist( wins_server_subnet, fp );
 
647
        }
 
648
 
 
649
        if (wins_server_subnet != NULL) {
 
650
                dump_wins_subnet_namelist(fp );
 
651
        }
 
652
 
601
653
        x_fclose( fp );
602
654
}