diff options
25 files changed, 197 insertions, 176 deletions
diff --git a/source3/include/nameserv.h b/source3/include/nameserv.h index 1e867d620b..5362960d62 100644 --- a/source3/include/nameserv.h +++ b/source3/include/nameserv.h @@ -226,8 +226,8 @@ struct name_record { /* Browser cache for synchronising browse lists. */ struct browse_cache_record { ubi_dlNode node[1]; - nstring lmb_name; - nstring work_group; + fstring lmb_name; + fstring work_group; struct in_addr ip; time_t sync_time; time_t death_time; /* The time the record must be removed. */ @@ -265,9 +265,9 @@ struct work_record { enum logon_state log_state; /* Work group info. */ - nstring work_group; + fstring work_group; int token; /* Used when communicating with backup browsers. */ - nstring local_master_browser_name; /* Current local master browser. */ + fstring local_master_browser_name; /* Current local master browser. */ /* Announce info. */ time_t lastannounce_time; diff --git a/source3/lib/charcnv.c b/source3/lib/charcnv.c index 7227a946bc..d38bfdb534 100644 --- a/source3/lib/charcnv.c +++ b/source3/lib/charcnv.c @@ -839,7 +839,7 @@ size_t push_ascii_nstring(void *dest, const char *src) } dest_len = 0; - for (i = 0; i < buffer_len; i++) { + for (i = 0; buffer[i] != 0 && (i < buffer_len); i++) { unsigned char mb[10]; /* Convert one smb_ucs2_t character at a time. */ size_t mb_len = convert_string(CH_UCS2, CH_DOS, buffer+i, sizeof(smb_ucs2_t), mb, sizeof(mb), False); @@ -847,6 +847,7 @@ size_t push_ascii_nstring(void *dest, const char *src) memcpy((char *)dest + dest_len, mb, mb_len); dest_len += mb_len; } else { + errno = E2BIG; break; } } @@ -912,9 +913,11 @@ size_t pull_ascii_fstring(char *dest, const void *src) return pull_ascii(dest, src, sizeof(fstring), -1, STR_TERMINATE); } -size_t pull_ascii_nstring(char *dest, const void *src) +/* When pulling an nstring it can expand into a larger size (dos cp -> utf8). Cope with this. */ + +size_t pull_ascii_nstring(char *dest, size_t dest_len, const void *src) { - return pull_ascii(dest, src, sizeof(nstring), sizeof(nstring), STR_TERMINATE); + return pull_ascii(dest, src, dest_len, sizeof(nstring), STR_TERMINATE); } /** diff --git a/source3/lib/util_str.c b/source3/lib/util_str.c index b8cf052862..2be8b7eb64 100644 --- a/source3/lib/util_str.c +++ b/source3/lib/util_str.c @@ -1307,7 +1307,6 @@ char *strstr_m(const char *src, const char *findstr) char *retp; size_t findstr_len = 0; - size_t find_w_len; /* for correctness */ if (!findstr[0]) { diff --git a/source3/libsmb/libsmbclient.c b/source3/libsmb/libsmbclient.c index 37e794478d..35e8a9786b 100644 --- a/source3/libsmb/libsmbclient.c +++ b/source3/libsmb/libsmbclient.c @@ -1787,7 +1787,7 @@ static SMBCFILE *smbc_opendir_ctx(SMBCCTX *context, const char *fname) if (!is_ipaddress(server) && /* Not an IP addr so check next */ (resolve_name(server, &rem_ip, 0x1d) || /* Found LMB */ resolve_name(server, &rem_ip, 0x1b) )) { /* Found DMB */ - pstring buserver; + fstring buserver; dir->dir_type = SMBC_SERVER; diff --git a/source3/libsmb/namequery.c b/source3/libsmb/namequery.c index b6d1f8bda2..b9bc4e1166 100644 --- a/source3/libsmb/namequery.c +++ b/source3/libsmb/namequery.c @@ -163,7 +163,7 @@ struct node_status *node_status_query(int fd,struct nmb_name *name, a servers name given its IP. Return the matched name in *name. **************************************************************************/ -BOOL name_status_find(const char *q_name, int q_type, int type, struct in_addr to_ip, char *name) +BOOL name_status_find(const char *q_name, int q_type, int type, struct in_addr to_ip, fstring name) { struct node_status *status = NULL; struct nmb_name nname; @@ -202,7 +202,7 @@ BOOL name_status_find(const char *q_name, int q_type, int type, struct in_addr t if (i == count) goto done; - pull_ascii_nstring(name, status[i].name); + pull_ascii_nstring(name, sizeof(fstring), status[i].name); /* Store the result in the cache. */ /* but don't store an entry for 0x1c names here. Here we have diff --git a/source3/libsmb/nmblib.c b/source3/libsmb/nmblib.c index cbe495cd95..bc2cca0e0e 100644 --- a/source3/libsmb/nmblib.c +++ b/source3/libsmb/nmblib.c @@ -285,7 +285,7 @@ static void put_name(char *dest, const char *name, int pad, unsigned int name_ty static int put_nmb_name(char *buf,int offset,struct nmb_name *name) { int ret,m; - fstring buf1; + nstring buf1; char *p; if (strcmp(name->name,"*") == 0) { @@ -1230,17 +1230,24 @@ static int name_interpret(char *in, fstring name) int name_mangle( char *In, char *Out, char name_type ) { int i; - int c; int len; - char buf[20]; + nstring buf; char *p = Out; /* Safely copy the input string, In, into buf[]. */ - memset( buf, 0, 20 ); - if (strcmp(In,"*") == 0) { - buf[0] = '*'; - } else { - slprintf( buf, sizeof(buf) - 1, "%-15.15s%c", In, name_type ); + if (strcmp(In,"*") == 0) + put_name(buf, "*", '\0', 0x00); + else { + /* We use an fstring here as mb dos names can expend x3 when + going to utf8. */ + fstring buf_unix; + nstring buf_dos; + + pull_ascii_fstring(buf_unix, In); + strupper_m(buf_unix); + + push_ascii_nstring(buf_dos, buf_unix); + put_name(buf, buf_dos, ' ', name_type); } /* Place the length of the first field into the output buffer. */ @@ -1249,9 +1256,8 @@ int name_mangle( char *In, char *Out, char name_type ) /* Now convert the name to the rfc1001/1002 format. */ for( i = 0; i < MAX_NETBIOSNAME_LEN; i++ ) { - c = toupper( buf[i] ); - p[i*2] = ( (c >> 4) & 0x000F ) + 'A'; - p[(i*2)+1] = (c & 0x000F) + 'A'; + p[i*2] = ( (buf[i] >> 4) & 0x000F ) + 'A'; + p[(i*2)+1] = (buf[i] & 0x000F) + 'A'; } p += 32; p[0] = '\0'; diff --git a/source3/nmbd/asyncdns.c b/source3/nmbd/asyncdns.c index 6d5d487b11..dafbff7af2 100644 --- a/source3/nmbd/asyncdns.c +++ b/source3/nmbd/asyncdns.c @@ -27,9 +27,9 @@ static struct name_record *add_dns_result(struct nmb_name *question, struct in_addr addr) { int name_type = question->name_type; - nstring qname; + fstring qname; - pull_ascii_nstring(qname, question->name); + pull_ascii_nstring(qname, sizeof(qname), question->name); if (!addr.s_addr) { /* add the fail to WINS cache of names. give it 1 hour in the cache */ diff --git a/source3/nmbd/nmbd_become_dmb.c b/source3/nmbd/nmbd_become_dmb.c index 46d37fbb81..c9b0a22580 100644 --- a/source3/nmbd/nmbd_become_dmb.c +++ b/source3/nmbd/nmbd_become_dmb.c @@ -37,11 +37,11 @@ static void become_domain_master_fail(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *fail_name) { - nstring failname; + fstring failname; struct work_record *work; struct server_record *servrec; - pull_ascii_nstring(failname, fail_name->name); + pull_ascii_nstring(failname, sizeof(failname), fail_name->name); work = find_workgroup_on_subnet(subrec, failname); if(!work) { DEBUG(0,("become_domain_master_fail: Error - cannot find \ @@ -80,11 +80,11 @@ static void become_domain_master_stage2(struct subnet_record *subrec, uint16 nb_flags, int ttl, struct in_addr registered_ip) { - nstring regname; + fstring regname; struct work_record *work; struct server_record *servrec; - pull_ascii_nstring(regname, registered_name->name); + pull_ascii_nstring(regname, sizeof(regname), registered_name->name); work = find_workgroup_on_subnet( subrec, regname); if(!work) { @@ -200,8 +200,8 @@ static void become_domain_master_query_success(struct subnet_record *subrec, struct nmb_name *nmbname, struct in_addr ip, struct res_rec *rrec) { - nstring name; - pull_ascii_nstring(name, nmbname->name); + fstring name; + pull_ascii_nstring(name, sizeof(name), nmbname->name); /* If the given ip is not ours, then we can't become a domain controler as the name is already registered. @@ -241,7 +241,7 @@ static void become_domain_master_query_fail(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *question_name, int fail_code) { - nstring name; + fstring name; /* If the query was unicast, and the error is not NAM_ERR (name didn't exist), then this is a failure. Otherwise, not finding the name is what we want. */ @@ -254,7 +254,7 @@ querying WINS server for name %s.\n", } /* Otherwise - not having the name allows us to register it. */ - pull_ascii_nstring(name, question_name->name); + pull_ascii_nstring(name, sizeof(name), question_name->name); become_domain_master_stage1(subrec, name); } diff --git a/source3/nmbd/nmbd_become_lmb.c b/source3/nmbd/nmbd_become_lmb.c index 2370c7ba36..8d66320f3e 100644 --- a/source3/nmbd/nmbd_become_lmb.c +++ b/source3/nmbd/nmbd_become_lmb.c @@ -33,11 +33,11 @@ extern uint16 samba_nb_type; /* Samba's NetBIOS name type. */ void insert_permanent_name_into_unicast( struct subnet_record *subrec, struct nmb_name *nmbname, uint16 nb_type ) { - nstring name; + fstring name; struct name_record *namerec; if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) == NULL) { - pull_ascii_nstring(name, nmbname->name); + pull_ascii_nstring(name, sizeof(name), nmbname->name); /* The name needs to be created on the unicast subnet. */ (void)add_name_to_subnet( unicast_subnet, name, nmbname->name_type, nb_type, @@ -135,7 +135,7 @@ static void unbecome_local_master_success(struct subnet_record *subrec, struct in_addr released_ip) { BOOL force_new_election = False; - nstring relname; + fstring relname; memcpy((char *)&force_new_election, userdata->data, sizeof(BOOL)); @@ -143,7 +143,7 @@ static void unbecome_local_master_success(struct subnet_record *subrec, nmb_namestr(released_name))); /* Now reset the workgroup and server state. */ - pull_ascii_nstring(relname, released_name->name); + pull_ascii_nstring(relname, sizeof(relname), released_name->name); reset_workgroup_state( subrec, relname, force_new_election ); if( DEBUGLVL( 0 ) ) { @@ -166,7 +166,7 @@ static void unbecome_local_master_fail(struct subnet_record *subrec, struct resp struct name_record *namerec; struct userdata_struct *userdata = rrec->userdata; BOOL force_new_election = False; - nstring failname; + fstring failname; memcpy((char *)&force_new_election, userdata->data, sizeof(BOOL)); @@ -179,7 +179,7 @@ Removing from namelist anyway.\n", nmb_namestr(fail_name))); remove_name_from_namelist(subrec, namerec); /* Now reset the workgroup and server state. */ - pull_ascii_nstring(failname, fail_name->name); + pull_ascii_nstring(failname, sizeof(failname), fail_name->name); reset_workgroup_state( subrec, failname, force_new_election ); if( DEBUGLVL( 0 ) ) { @@ -330,9 +330,9 @@ static void become_local_master_stage2(struct subnet_record *subrec, struct server_record *sl; struct work_record *work; struct server_record *servrec; - nstring regname; + fstring regname; - pull_ascii_nstring(regname, registered_name->name); + pull_ascii_nstring(regname, sizeof(regname), registered_name->name); work = find_workgroup_on_subnet( subrec, regname); if(!work) { @@ -410,13 +410,13 @@ static void become_local_master_fail2(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *fail_name) { - nstring failname; + fstring failname; struct work_record *work; DEBUG(0,("become_local_master_fail2: failed to register name %s on subnet %s. \ Failed to become a local master browser.\n", nmb_namestr(fail_name), subrec->subnet_name)); - pull_ascii_nstring(failname, fail_name->name); + pull_ascii_nstring(failname, sizeof(failname), fail_name->name); work = find_workgroup_on_subnet( subrec, failname); if(!work) { @@ -590,5 +590,5 @@ local_master_browser_name for workgroup %s to workgroup name.\n", } #endif - nstrcpy(work->local_master_browser_name, newname); + fstrcpy(work->local_master_browser_name, newname); } diff --git a/source3/nmbd/nmbd_browserdb.c b/source3/nmbd/nmbd_browserdb.c index 443edf599d..d781259156 100644 --- a/source3/nmbd/nmbd_browserdb.c +++ b/source3/nmbd/nmbd_browserdb.c @@ -106,8 +106,8 @@ struct browse_cache_record *create_browser_in_lmb_cache( const char *work_name, /* Allow the new lmb to miss an announce period before we remove it. */ browc->death_time = now + ( (CHECK_TIME_MST_ANNOUNCE + 2) * 60 ); - nstrcpy( browc->lmb_name, browser_name); - nstrcpy( browc->work_group, work_name); + fstrcpy( browc->lmb_name, browser_name); + fstrcpy( browc->work_group, work_name); strupper_m( browc->lmb_name ); strupper_m( browc->work_group ); diff --git a/source3/nmbd/nmbd_browsesync.c b/source3/nmbd/nmbd_browsesync.c index 6cde88651f..454c349767 100644 --- a/source3/nmbd/nmbd_browsesync.c +++ b/source3/nmbd/nmbd_browsesync.c @@ -146,7 +146,7 @@ As a local master browser, do a sync with a domain master browser. static void sync_with_dmb(struct work_record *work) { - nstring dmb_name; + fstring dmb_name; if( DEBUGLVL( 2 ) ) { dbgtext( "sync_with_dmb:\n" ); @@ -156,7 +156,7 @@ static void sync_with_dmb(struct work_record *work) dbgtext( "for workgroup %s\n", work->work_group ); } - pull_ascii_nstring(dmb_name, work->dmb_name.name); + pull_ascii_nstring(dmb_name, sizeof(fstring), work->dmb_name.name); sync_browse_lists(work, dmb_name, work->dmb_name.name_type, work->dmb_addr, False, True); } @@ -197,11 +197,11 @@ static void domain_master_node_status_success(struct subnet_record *subrec, p += 1; while (numnames--) { - nstring qname; + fstring qname; uint16 nb_flags; int name_type; - pull_ascii_nstring(qname, p); + pull_ascii_nstring(qname, sizeof(qname), p); name_type = CVAL(p,15); nb_flags = get_nb_flags(&p[16]); trim_char(qname,'\0',' '); @@ -278,9 +278,9 @@ static void find_domain_master_name_query_success(struct subnet_record *subrec, struct nmb_name nmbname; struct userdata_struct *userdata; size_t size = sizeof(struct userdata_struct) + sizeof(fstring)+1; - nstring qname; + fstring qname; - pull_ascii_nstring(qname, q_name->name); + pull_ascii_nstring(qname, sizeof(qname), q_name->name); if( !(work = find_workgroup_on_subnet(subrec, qname)) ) { if( DEBUGLVL( 0 ) ) { dbgtext( "find_domain_master_name_query_success:\n" ); @@ -420,11 +420,11 @@ static void get_domain_master_name_node_status_success(struct subnet_record *sub p += 1; while (numnames--) { - nstring qname; + fstring qname; uint16 nb_flags; int name_type; - pull_ascii_nstring(qname, p); + pull_ascii_nstring(qname, sizeof(qname), p); name_type = CVAL(p,15); nb_flags = get_nb_flags(&p[16]); trim_char(qname,'\0',' '); @@ -460,7 +460,7 @@ static void get_domain_master_name_node_status_success(struct subnet_record *sub return; /* remember who the master is */ - nstrcpy(work->local_master_browser_name, server_name); + fstrcpy(work->local_master_browser_name, server_name); make_nmb_name(&nmbname, server_name, 0x20); work->dmb_name = nmbname; work->dmb_addr = from_ip; @@ -647,7 +647,7 @@ void sync_all_dmbs(time_t t) /* sync with a probability of 1/count */ for (work=unicast_subnet->workgrouplist; work; work = work->next) { if (strncmp(lp_workgroup(), work->work_group, sizeof(nstring))) { - nstring dmb_name; + fstring dmb_name; if (((unsigned)sys_random()) % count != 0) continue; @@ -662,7 +662,7 @@ void sync_all_dmbs(time_t t) 0x20); } - pull_ascii_nstring(dmb_name, work->dmb_name.name); + pull_ascii_nstring(dmb_name, sizeof(dmb_name), work->dmb_name.name); DEBUG(3,("Initiating DMB<->DMB sync with %s(%s)\n", dmb_name, inet_ntoa(work->dmb_addr))); diff --git a/source3/nmbd/nmbd_elections.c b/source3/nmbd/nmbd_elections.c index 19b00f1f4d..882c26ce80 100644 --- a/source3/nmbd/nmbd_elections.c +++ b/source3/nmbd/nmbd_elections.c @@ -70,8 +70,8 @@ static void check_for_master_browser_success(struct subnet_record *subrec, struct nmb_name *answer_name, struct in_addr answer_ip, struct res_rec *rrec) { - nstring aname; - pull_ascii_nstring(aname, answer_name->name); + fstring aname; + pull_ascii_nstring(aname, sizeof(aname), answer_name->name); DEBUG(3,("check_for_master_browser_success: Local master browser for workgroup %s exists at \ IP %s (just checking).\n", aname, inet_ntoa(answer_ip) )); } @@ -85,10 +85,10 @@ static void check_for_master_browser_fail( struct subnet_record *subrec, struct nmb_name *question_name, int fail_code) { - nstring workgroup_name; + fstring workgroup_name; struct work_record *work; - pull_ascii_nstring(workgroup_name,question_name->name); + pull_ascii_nstring(workgroup_name,sizeof(workgroup_name),question_name->name); work = find_workgroup_on_subnet(subrec, workgroup_name); if(work == NULL) { @@ -263,12 +263,12 @@ void process_election(struct subnet_record *subrec, struct packet_struct *p, cha int version = CVAL(buf,0); uint32 criterion = IVAL(buf,1); int timeup = IVAL(buf,5)/1000; - nstring server_name; + fstring server_name; struct work_record *work; - nstring workgroup_name; + fstring workgroup_name; - pull_ascii_nstring(server_name, buf+13); - pull_ascii_nstring(workgroup_name, dgram->dest_name.name); + pull_ascii_nstring(server_name, sizeof(server_name), buf+13); + pull_ascii_nstring(workgroup_name, sizeof(workgroup_name), dgram->dest_name.name); START_PROFILE(election); server_name[15] = 0; diff --git a/source3/nmbd/nmbd_incomingdgrams.c b/source3/nmbd/nmbd_incomingdgrams.c index f646e39716..1450610e19 100644 --- a/source3/nmbd/nmbd_incomingdgrams.c +++ b/source3/nmbd/nmbd_incomingdgrams.c @@ -97,21 +97,21 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p { struct dgram_packet *dgram = &p->packet.dgram; int ttl = IVAL(buf,1)/1000; - nstring announce_name; + fstring announce_name; uint32 servertype = IVAL(buf,23); fstring comment; struct work_record *work; struct server_record *servrec; - nstring work_name; - nstring source_name; + fstring work_name; + fstring source_name; START_PROFILE(host_announce); pull_ascii_fstring(comment, buf+31); comment[42] = 0; - pull_ascii_nstring(announce_name, buf+5); - pull_ascii_nstring(source_name, dgram->source_name.name); + pull_ascii_nstring(announce_name, sizeof(announce_name), buf+5); + pull_ascii_nstring(source_name, sizeof(source_name), dgram->source_name.name); DEBUG(3,("process_host_announce: from %s<%02x> IP %s to \ %s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip), @@ -133,7 +133,7 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p } /* For a host announce the workgroup name is the destination name. */ - pull_ascii_nstring(work_name, dgram->dest_name.name); + pull_ascii_nstring(work_name, sizeof(work_name), dgram->dest_name.name); /* * Syntax servers version 5.1 send HostAnnounce packets to @@ -144,7 +144,7 @@ void process_host_announce(struct subnet_record *subrec, struct packet_struct *p */ if(strequal(work_name, global_myname())) - nstrcpy(work_name,lp_workgroup()); + fstrcpy(work_name,lp_workgroup()); /* * We are being very agressive here in adding a workgroup @@ -198,19 +198,19 @@ void process_workgroup_announce(struct subnet_record *subrec, struct packet_stru { struct dgram_packet *dgram = &p->packet.dgram; int ttl = IVAL(buf,1)/1000; - nstring workgroup_announce_name; - nstring master_name; + fstring workgroup_announce_name; + fstring master_name; uint32 servertype = IVAL(buf,23); struct work_record *work; - nstring source_name; - nstring dest_name; + fstring source_name; + fstring dest_name; START_PROFILE(workgroup_announce); - pull_ascii_nstring(workgroup_announce_name,buf+5); - pull_ascii_nstring(master_name,buf+31); - pull_ascii_nstring(source_name,dgram->source_name.name); - pull_ascii_nstring(dest_name,dgram->dest_name.name); + pull_ascii_nstring(workgroup_announce_name,sizeof(workgroup_announce_name),buf+5); + pull_ascii_nstring(master_name,sizeof(master_name),buf+31); + pull_ascii_nstring(source_name,sizeof(source_name),dgram->source_name.name); + pull_ascii_nstring(dest_name,sizeof(dest_name),dgram->dest_name.name); DEBUG(3,("process_workgroup_announce: from %s<%02x> IP %s to \ %s for workgroup %s.\n", source_name, source_name[15], inet_ntoa(p->ip), @@ -255,21 +255,21 @@ void process_local_master_announce(struct subnet_record *subrec, struct packet_s { struct dgram_packet *dgram = &p->packet.dgram; int ttl = IVAL(buf,1)/1000; - nstring server_name; + fstring server_name; uint32 servertype = IVAL(buf,23); fstring comment; - nstring work_name; + fstring work_name; struct work_record *work; struct server_record *servrec; - nstring source_name; + fstring source_name; START_PROFILE(local_master_announce); - pull_ascii_nstring(server_name,buf+5); + pull_ascii_nstring(server_name,sizeof(server_name),buf+5); pull_ascii_fstring(comment, buf+31); comment[42] = 0; - pull_ascii_nstring(source_name, dgram->source_name.name); - pull_ascii_nstring(work_name, dgram->dest_name.name); + pull_ascii_nstring(source_name, sizeof(source_name), dgram->source_name.name); + pull_ascii_nstring(work_name, sizeof(work_name), dgram->dest_name.name); DEBUG(3,("process_local_master_announce: from %s<%02x> IP %s to \ %s for server %s.\n", source_name, source_name[15], inet_ntoa(p->ip), @@ -369,13 +369,13 @@ done: void process_master_browser_announce(struct subnet_record *subrec, struct packet_struct *p,char *buf) { - nstring local_master_name; + fstring local_master_name; struct work_record *work; struct browse_cache_record *browrec; START_PROFILE(master_browser_announce); - pull_ascii_nstring(local_master_name,buf); + pull_ascii_nstring(local_master_name,sizeof(local_master_name),buf); DEBUG(3,("process_master_browser_announce: Local master announce from %s IP %s.\n", local_master_name, inet_ntoa(p->ip))); @@ -425,11 +425,11 @@ void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct int osmajor=CVAL(buf,5); /* major version of node software */ int osminor=CVAL(buf,6); /* minor version of node software */ int ttl = SVAL(buf,7); - nstring announce_name; + fstring announce_name; struct work_record *work; struct server_record *servrec; - nstring work_name; - nstring source_name; + fstring work_name; + fstring source_name; fstring comment; char *s = buf+9; @@ -437,10 +437,10 @@ void process_lm_host_announce(struct subnet_record *subrec, struct packet_struct s = skip_string(s,1); pull_ascii(comment, s, sizeof(fstring), 43, STR_TERMINATE); - pull_ascii_nstring(announce_name,buf+9); - pull_ascii_nstring(source_name,dgram->source_name.name); + pull_ascii_nstring(announce_name,sizeof(announce_name),buf+9); + pull_ascii_nstring(source_name,sizeof(source_name),dgram->source_name.name); /* For a LanMan host announce the workgroup name is the destination name. */ - pull_ascii_nstring(work_name,dgram->dest_name.name); + pull_ascii_nstring(work_name,sizeof(work_name),dgram->dest_name.name); DEBUG(3,("process_lm_host_announce: LM Announcement from %s IP %s to \ %s for server %s.\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), @@ -479,7 +479,7 @@ originate from OS/2 Warp client. Ignoring packet.\n")); */ if(strequal(work_name, global_myname())) - nstrcpy(work_name,lp_workgroup()); + fstrcpy(work_name,lp_workgroup()); /* * We are being very agressive here in adding a workgroup @@ -541,7 +541,7 @@ static void send_backup_list_response(struct subnet_record *subrec, char outbuf[1024]; char *p, *countptr; unsigned int count = 0; - nstring send_to_namestr; + fstring send_to_namestr; #if 0 struct server_record *servrec; #endif @@ -612,7 +612,7 @@ static void send_backup_list_response(struct subnet_record *subrec, SCVAL(countptr, 0, count); - pull_ascii_nstring(send_to_namestr, send_to_name->name); + pull_ascii_nstring(send_to_namestr, sizeof(send_to_namestr), send_to_name->name); DEBUG(4,("send_backup_list_response: sending response to %s<00> IP %s with %d servers.\n", send_to_namestr, inet_ntoa(sendto_ip), count)); @@ -642,11 +642,11 @@ void process_get_backup_list_request(struct subnet_record *subrec, unsigned char max_number_requested = CVAL(buf,0); uint32 token = IVAL(buf,1); /* Sender's key index for the workgroup. */ int name_type = dgram->dest_name.name_type; - nstring workgroup_name; + fstring workgroup_name; struct subnet_record *search_subrec = subrec; START_PROFILE(get_backup_list); - pull_ascii_nstring(workgroup_name, dgram->dest_name.name); + pull_ascii_nstring(workgroup_name, sizeof(workgroup_name), dgram->dest_name.name); DEBUG(3,("process_get_backup_list_request: request from %s IP %s to %s.\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), @@ -774,11 +774,11 @@ void process_announce_request(struct subnet_record *subrec, struct packet_struct { struct dgram_packet *dgram = &p->packet.dgram; struct work_record *work; - nstring workgroup_name; + fstring workgroup_name; START_PROFILE(announce_request); - pull_ascii_nstring(workgroup_name, dgram->dest_name.name); + pull_ascii_nstring(workgroup_name, sizeof(workgroup_name), dgram->dest_name.name); DEBUG(3,("process_announce_request: Announce request from %s IP %s to %s.\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name))); @@ -814,11 +814,11 @@ done: void process_lm_announce_request(struct subnet_record *subrec, struct packet_struct *p, char *buf) { struct dgram_packet *dgram = &p->packet.dgram; - nstring workgroup_name; + fstring workgroup_name; START_PROFILE(lm_announce_request); - pull_ascii_nstring(workgroup_name, dgram->dest_name.name); + pull_ascii_nstring(workgroup_name, sizeof(workgroup_name), dgram->dest_name.name); DEBUG(3,("process_lm_announce_request: Announce request from %s IP %s to %s.\n", nmb_namestr(&dgram->source_name), inet_ntoa(p->ip), nmb_namestr(&dgram->dest_name))); diff --git a/source3/nmbd/nmbd_incomingrequests.c b/source3/nmbd/nmbd_incomingrequests.c index dd999fbdf7..d43cefc0df 100644 --- a/source3/nmbd/nmbd_incomingrequests.c +++ b/source3/nmbd/nmbd_incomingrequests.c @@ -58,7 +58,7 @@ void process_name_release_request(struct subnet_record *subrec, struct nmb_packet *nmb = &p->packet.nmb; struct in_addr owner_ip; struct nmb_name *question = &nmb->question.question_name; - nstring qname; + fstring qname; BOOL bcast = nmb->header.nm_flags.bcast; uint16 nb_flags = get_nb_flags(nmb->additional->rdata); BOOL group = (nb_flags & NB_GROUP) ? True : False; @@ -98,7 +98,7 @@ subnet %s from owner IP %s\n", * names and *don't set the group bit* !!!!! */ - pull_ascii_nstring(qname, question->name); + pull_ascii_nstring(qname, sizeof(qname), question->name); if( !group && !ismyip(owner_ip) && strequal(qname, lp_workgroup()) && ((question->name_type == 0x0) || (question->name_type == 0x1e))) { DEBUG(6,("process_name_release_request: FTP OnNet bug workaround. Ignoring \ @@ -275,11 +275,13 @@ We put our own names first, then in alphabetical order. static int status_compare(char *n1,char *n2) { - nstring name1, name2; + fstring name1, name2; int l1,l2,l3; - pull_ascii_nstring(name1, n1); - pull_ascii_nstring(name2, n2); + memset(name1, '\0', sizeof(name1)); + memset(name2, '\0', sizeof(name2)); + pull_ascii_nstring(name1, sizeof(name1), n1); + pull_ascii_nstring(name2, sizeof(name2), n2); n1 = name1; n2 = name2; @@ -298,7 +300,7 @@ static int status_compare(char *n1,char *n2) (l1!=l3 || strncmp(n1,global_myname(),l3) != 0)) return 1; - return memcmp(n1,n2,sizeof(nstring)); + return memcmp(n1,n2,sizeof(fstring)); } /**************************************************************************** @@ -308,14 +310,14 @@ static int status_compare(char *n1,char *n2) void process_node_status_request(struct subnet_record *subrec, struct packet_struct *p) { struct nmb_packet *nmb = &p->packet.nmb; - nstring qname; + fstring qname; int ques_type = nmb->question.question_name.name_type; char rdata[MAX_DGRAM_SIZE]; char *countptr, *buf, *bufend, *buf0; int names_added,i; struct name_record *namerec; - pull_ascii_nstring(qname, nmb->question.question_name.name); + pull_ascii_nstring(qname, sizeof(qname), nmb->question.question_name.name); DEBUG(3,("process_node_status_request: status request for name %s from IP %s on \ subnet %s.\n", nmb_namestr(&nmb->question.question_name), inet_ntoa(p->ip), subrec->subnet_name)); @@ -342,9 +344,9 @@ subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name), while (buf < bufend) { if( (namerec->data.source == SELF_NAME) || (namerec->data.source == PERMANENT_NAME) ) { int name_type = namerec->name.name_type; - nstring name; + fstring name; - pull_ascii_nstring(name, namerec->name.name); + pull_ascii_nstring(name, sizeof(name), namerec->name.name); strupper_m(name); if (!strequal(name,"*") && !strequal(name,"__SAMBA__") && @@ -352,10 +354,11 @@ subnet %s - name not found.\n", nmb_namestr(&nmb->question.question_name), ques_type < 0x1b || ques_type >= 0x20 || strequal(qname, name))) { /* Start with the name. */ - nstring tmp_name; - memset(tmp_name,'\0',sizeof(tmp_name)); - snprintf(tmp_name, sizeof(tmp_name), "%-15.15s",name); - push_ascii_nstring(buf, tmp_name); + size_t len; + push_ascii_nstring(buf, name); + len = strlen(buf); + memset(buf + len, ' ', MAX_NETBIOSNAME_LEN - len - 1); + buf[MAX_NETBIOSNAME_LEN - 1] = '\0'; /* Put the name type and netbios flags in the buffer. */ diff --git a/source3/nmbd/nmbd_logonnames.c b/source3/nmbd/nmbd_logonnames.c index f79fc56f7b..b6e841139f 100644 --- a/source3/nmbd/nmbd_logonnames.c +++ b/source3/nmbd/nmbd_logonnames.c @@ -35,11 +35,11 @@ static void become_logon_server_fail(struct subnet_record *subrec, struct response_record *rrec, struct nmb_name *fail_name) { - nstring failname; + fstring failname; struct work_record *work; struct server_record *servrec; - pull_ascii_nstring(failname, fail_name->name); + pull_ascii_nstring(failname, sizeof(failname), fail_name->name); work = find_workgroup_on_subnet(subrec, failname); if(!work) { DEBUG(0,("become_logon_server_fail: Error - cannot find \ @@ -76,11 +76,11 @@ static void become_logon_server_success(struct subnet_record *subrec, uint16 nb_flags, int ttl, struct in_addr registered_ip) { - nstring reg_name; + fstring reg_name; struct work_record *work; struct server_record *servrec; - pull_ascii_nstring(reg_name, registered_name->name); + pull_ascii_nstring(reg_name, sizeof(reg_name), registered_name->name); work = find_workgroup_on_subnet( subrec, reg_name); if(!work) { DEBUG(0,("become_logon_server_success: Error - cannot find \ diff --git a/source3/nmbd/nmbd_mynames.c b/source3/nmbd/nmbd_mynames.c index f02fbe1640..83a8361ed9 100644 --- a/source3/nmbd/nmbd_mynames.c +++ b/source3/nmbd/nmbd_mynames.c @@ -93,8 +93,8 @@ static void insert_refresh_name_into_unicast( struct subnet_record *subrec, } if((namerec = find_name_on_subnet(unicast_subnet, nmbname, FIND_SELF_NAME)) == NULL) { - nstring name; - pull_ascii_nstring(name, nmbname->name); + fstring name; + pull_ascii_nstring(name, sizeof(name), nmbname->name); /* The name needs to be created on the unicast subnet. */ (void)add_name_to_subnet( unicast_subnet, name, nmbname->name_type, nb_type, diff --git a/source3/nmbd/nmbd_namelistdb.c b/source3/nmbd/nmbd_namelistdb.c index d1c9afd608..9f89abdbb2 100644 --- a/source3/nmbd/nmbd_namelistdb.c +++ b/source3/nmbd/nmbd_namelistdb.c @@ -45,13 +45,13 @@ void set_samba_nb_type(void) static void upcase_name( struct nmb_name *target, struct nmb_name *source ) { int i; - nstring targ; + fstring targ; fstring scope; if( NULL != source ) memcpy( target, source, sizeof( struct nmb_name ) ); - pull_ascii_nstring(targ, target->name); + pull_ascii_nstring(targ, sizeof(targ), target->name); strupper_m( targ ); push_ascii_nstring( target->name, targ); @@ -255,8 +255,8 @@ void standard_success_register(struct subnet_record *subrec, namerec = find_name_on_subnet( subrec, nmbname, FIND_SELF_NAME ); if( NULL == namerec ) { - nstring name; - pull_ascii_nstring(name, nmbname->name); + fstring name; + pull_ascii_nstring(name, sizeof(name), nmbname->name); add_name_to_subnet( subrec, name, nmbname->name_type, nb_flags, ttl, SELF_NAME, 1, ®istered_ip ); } else { diff --git a/source3/nmbd/nmbd_nameregister.c b/source3/nmbd/nmbd_nameregister.c index 0397f56512..4fbdd143e1 100644 --- a/source3/nmbd/nmbd_nameregister.c +++ b/source3/nmbd/nmbd_nameregister.c @@ -85,8 +85,8 @@ static void register_name_response(struct subnet_record *subrec, */ #if 1 /* OLD_SAMBA_SERVER_HACK */ - nstring ans_name; - pull_ascii_nstring(ans_name, answer_name->name); + fstring ans_name; + pull_ascii_nstring(ans_name, sizeof(ans_name), answer_name->name); if((nmb->header.rcode == ACT_ERR) && strequal(lp_workgroup(), ans_name) && (answer_name->name_type == 0x1b)) { /* Pretend we did not get this. */ @@ -418,7 +418,7 @@ static void multihomed_register_name(struct nmb_name *nmbname, uint16 nb_flags, struct subnet_record *subrec; char **wins_tags; struct in_addr *ip_list; - nstring name; + fstring name; for(subrec = FIRST_SUBNET; subrec; subrec = NEXT_SUBNET_EXCLUDING_UNICAST(subrec) ) num_ips++; @@ -434,7 +434,7 @@ static void multihomed_register_name(struct nmb_name *nmbname, uint16 nb_flags, ip_list[i] = subrec->myip; } - pull_ascii_nstring(name, nmbname->name); + pull_ascii_nstring(name, sizeof(name), nmbname->name); add_name_to_subnet(unicast_subnet, name, nmbname->name_type, nb_flags, lp_max_ttl(), SELF_NAME, num_ips, ip_list); @@ -473,17 +473,18 @@ void register_name(struct subnet_record *subrec, struct nmb_name nmbname; nstring nname; - if (strlen(name)+1 > sizeof(nstring)) { - memcpy(nname, name,sizeof(nstring)-1); - nname[sizeof(nstring)-1] = '\0'; + errno = 0; + push_ascii_nstring(nname, name); + if (errno == E2BIG) { + fstring tname; + pull_ascii_nstring(tname, sizeof(tname), nname); DEBUG(0,("register_name: NetBIOS name %s is too long. Truncating to %s\n", - name, nname)); + name, tname)); + make_nmb_name(&nmbname, tname, type); } else { - nstrcpy(nname,name); + make_nmb_name(&nmbname, name, type); } - make_nmb_name(&nmbname, nname, type); - /* Always set the NB_ACTIVE flag on the name we are registering. Doesn't make sense without it. */ diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index c318689fd1..b5cbaab00b 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1034,7 +1034,7 @@ static void process_browse_packet(struct packet_struct *p, char *buf,int len) int command = CVAL(buf,0); struct subnet_record *subrec = find_subnet_for_dgram_browse_packet(p); char scope[64]; - nstring src_name; + fstring src_name; /* Drop the packet if it's a different NetBIOS scope, or the source is from one of our names. */ pull_ascii(scope, dgram->dest_name.scope, 64, 64, STR_TERMINATE); @@ -1044,7 +1044,7 @@ mismatch with our scope (%s).\n", inet_ntoa(p->ip), scope, global_scope())); return; } - pull_ascii_nstring(src_name, dgram->source_name.name); + pull_ascii_nstring(src_name, sizeof(src_name), dgram->source_name.name); if (is_myname(src_name)) { DEBUG(0,("process_browse_packet: Discarding datagram from IP %s. Source name \ %s is one of our names !\n", inet_ntoa(p->ip), nmb_namestr(&dgram->source_name))); @@ -1121,7 +1121,7 @@ static void process_lanman_packet(struct packet_struct *p, char *buf,int len) int command = SVAL(buf,0); struct subnet_record *subrec = find_subnet_for_dgram_browse_packet(p); char scope[64]; - nstring src_name; + fstring src_name; /* Drop the packet if it's a different NetBIOS scope, or the source is from one of our names. */ @@ -1132,7 +1132,7 @@ mismatch with our scope (%s).\n", inet_ntoa(p->ip), scope, global_scope())); return; } - pull_ascii_nstring(src_name, dgram->source_name.name); + pull_ascii_nstring(src_name, sizeof(src_name), dgram->source_name.name); if (is_myname(src_name)) { DEBUG(0,("process_lanman_packet: Discarding datagram from IP %s. Source name \ %s is one of our names !\n", inet_ntoa(p->ip), nmb_namestr(&dgram->source_name))); diff --git a/source3/nmbd/nmbd_processlogon.c b/source3/nmbd/nmbd_processlogon.c index 13aefabd26..ff2aea6c08 100644 --- a/source3/nmbd/nmbd_processlogon.c +++ b/source3/nmbd/nmbd_processlogon.c @@ -141,7 +141,7 @@ logons are not enabled.\n", inet_ntoa(p->ip) )); case QUERYFORPDC: { fstring mach_str, getdc_str; - nstring source_name; + fstring source_name; char *q = buf + 2; char *machine = q; @@ -220,7 +220,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", dump_data(4, outbuf, PTR_DIFF(q, outbuf)); pull_ascii_fstring(getdc_str, getdc); - pull_ascii_nstring(source_name, dgram->source_name.name); + pull_ascii_nstring(source_name, sizeof(source_name), dgram->source_name.name); send_mailslot(True, getdc_str, outbuf,PTR_DIFF(q,outbuf), @@ -435,7 +435,7 @@ reporting %s domain %s 0x%x ntversion=%x lm_nt token=%x lm_20 token=%x\n", dump_data(4, outbuf, PTR_DIFF(q, outbuf)); pull_ascii_fstring(getdc_str, getdc); - pull_ascii_nstring(source_name, dgram->source_name.name); + pull_ascii_nstring(source_name, sizeof(source_name), dgram->source_name.name); send_mailslot(True, getdc, outbuf,PTR_DIFF(q,outbuf), diff --git a/source3/nmbd/nmbd_synclists.c b/source3/nmbd/nmbd_synclists.c index 6a0576a5a4..424af1e2e3 100644 --- a/source3/nmbd/nmbd_synclists.c +++ b/source3/nmbd/nmbd_synclists.c @@ -31,8 +31,8 @@ struct sync_record { struct sync_record *next, *prev; - nstring workgroup; - nstring server; + fstring workgroup; + fstring server; pstring fname; struct in_addr ip; pid_t pid; @@ -148,8 +148,8 @@ done: ZERO_STRUCTP(s); - nstrcpy(s->workgroup, work->work_group); - nstrcpy(s->server, name); + fstrcpy(s->workgroup, work->work_group); + fstrcpy(s->server, name); s->ip = ip; slprintf(s->fname, sizeof(pstring)-1, @@ -206,7 +206,7 @@ static void complete_one(struct sync_record *s, sname, lp_max_ttl()); if (work) { /* remember who the master is */ - nstrcpy(work->local_master_browser_name, comment); + fstrcpy(work->local_master_browser_name, comment); } } return; diff --git a/source3/nmbd/nmbd_winsproxy.c b/source3/nmbd/nmbd_winsproxy.c index bace112752..d91818698e 100644 --- a/source3/nmbd/nmbd_winsproxy.c +++ b/source3/nmbd/nmbd_winsproxy.c @@ -30,7 +30,7 @@ static void wins_proxy_name_query_request_success( struct subnet_record *subrec, struct userdata_struct *userdata, struct nmb_name *nmbname, struct in_addr ip, struct res_rec *rrec) { - nstring name; + fstring name; struct packet_struct *original_packet; struct subnet_record *orig_broadcast_subnet; struct name_record *namerec; @@ -73,7 +73,7 @@ returned for name %s.\n", nmb_namestr(nmbname) )); if(rrec == PERMANENT_TTL) ttl = lp_max_ttl(); - pull_ascii_nstring(name, nmbname->name); + pull_ascii_nstring(name, sizeof(name), nmbname->name); namerec = add_name_to_subnet( orig_broadcast_subnet, name, nmbname->name_type, nb_flags, ttl, WINS_PROXY_NAME, num_ips, iplist ); @@ -193,7 +193,7 @@ void make_wins_proxy_name_query_request( struct subnet_record *subrec, long *ud[(sizeof(struct userdata_struct) + sizeof(struct subrec *) + sizeof(struct packet_struct *))/sizeof(long *) + 1]; struct userdata_struct *userdata = (struct userdata_struct *)ud; - nstring qname; + fstring qname; memset(ud, '\0', sizeof(ud)); @@ -205,7 +205,7 @@ void make_wins_proxy_name_query_request( struct subnet_record *subrec, sizeof(struct packet_struct *)); /* Now use the unicast subnet to query the name with the WINS server. */ - pull_ascii_nstring(qname, question_name->name); + pull_ascii_nstring(qname, sizeof(qname), question_name->name); query_name( unicast_subnet, qname, question_name->name_type, wins_proxy_name_query_request_success, wins_proxy_name_query_request_fail, diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index aae1cf633f..fd7718e2a6 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -744,7 +744,7 @@ querying for name %s in order to replace it and this reply.\n", nmb_namestr(ques void wins_process_name_registration_request(struct subnet_record *subrec, struct packet_struct *p) { - nstring name; + fstring name; struct nmb_packet *nmb = &p->packet.nmb; struct nmb_name *question = &nmb->question.question_name; BOOL bcast = nmb->header.nm_flags.bcast; @@ -906,7 +906,7 @@ already exists in WINS as a GROUP name.\n", nmb_namestr(question) )); */ if ( namerec != NULL ) - pull_ascii_nstring(name, namerec->name.name); + pull_ascii_nstring(name, sizeof(name), namerec->name.name); if( is_myname(name) ) { if(!ismyip(from_ip)) { @@ -983,7 +983,7 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio * code. JRA. */ - pull_ascii_nstring(name, question->name); + pull_ascii_nstring(name, sizeof(name), question->name); query_name_from_wins_server( *namerec->data.ip, name, question->name_type, @@ -997,7 +997,7 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio * Name did not exist - add it. */ - pull_ascii_nstring(name, question->name); + pull_ascii_nstring(name, sizeof(name), question->name); add_name_to_subnet( subrec, name, question->name_type, nb_flags, ttl, REGISTER_NAME, 1, &from_ip); @@ -1119,7 +1119,7 @@ void wins_process_multihomed_name_registration_request( struct subnet_record *su 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"); - nstring qname; + fstring qname; putip((char *)&from_ip,&nmb->additional->rdata[2]); @@ -1318,7 +1318,7 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio * not the person who sent the packet */ - pull_ascii_nstring( qname, question->name); + pull_ascii_nstring( qname, sizeof(qname), question->name); query_name_from_wins_server( namerec->data.ip[0], qname, question->name_type, @@ -1333,7 +1333,7 @@ is one of our (WINS server) names. Denying registration.\n", nmb_namestr(questio * Name did not exist - add it. */ - pull_ascii_nstring( qname, question->name); + pull_ascii_nstring( qname, sizeof(qname), question->name); add_name_to_subnet( subrec, qname, question->name_type, nb_flags, ttl, REGISTER_NAME, 1, &from_ip); @@ -1479,7 +1479,7 @@ void wins_process_name_query_request(struct subnet_record *subrec, struct nmb_packet *nmb = &p->packet.nmb; struct nmb_name *question = &nmb->question.question_name; struct name_record *namerec = NULL; - nstring qname; + fstring qname; DEBUG(3,("wins_process_name_query: name query for name %s from IP %s\n", nmb_namestr(question), inet_ntoa(p->ip) )); @@ -1491,7 +1491,7 @@ void wins_process_name_query_request(struct subnet_record *subrec, * to discover other domains that may not have a presence on their subnet. */ - pull_ascii_nstring(qname, question->name); + pull_ascii_nstring(qname, sizeof(qname), question->name); if(strequal( qname, "*") && (question->name_type == 0x1b)) { process_wins_dmb_query_request( subrec, p); return; @@ -1845,8 +1845,8 @@ void wins_write_database(BOOL background) DEBUGADD(4,("%2x\n", namerec->data.nb_flags )); if( namerec->data.source == REGISTER_NAME ) { - nstring name; - pull_ascii_nstring(name, namerec->name.name); + fstring name; + pull_ascii_nstring(name, sizeof(name), namerec->name.name); x_fprintf(fp, "\"%s#%02x\" %d ", name,namerec->name.name_type, /* Ignore scope. */ (int)namerec->data.death_time); diff --git a/source3/nmbd/nmbd_workgroupdb.c b/source3/nmbd/nmbd_workgroupdb.c index b9fab4b278..bd2737ef97 100644 --- a/source3/nmbd/nmbd_workgroupdb.c +++ b/source3/nmbd/nmbd_workgroupdb.c @@ -48,6 +48,8 @@ static struct work_record *create_workgroup(const char *name, int ttl) { struct work_record *work; struct subnet_record *subrec; + nstring nname; + int t = -1; if((work = (struct work_record *)malloc(sizeof(*work))) == NULL) { @@ -55,15 +57,18 @@ static struct work_record *create_workgroup(const char *name, int ttl) return NULL; } memset((char *)work, '\0', sizeof(*work)); - - if (strlen(name)+1 > sizeof(nstring)) { - memcpy(work->work_group,name,sizeof(nstring)-1); - work->work_group[sizeof(nstring)-1] = '\0'; - DEBUG(0,("create_workgroup: workgroup name %s is too long. Truncating to %s\n", - name, work->work_group )); - } else { - nstrcpy(work->work_group,name); - } + + errno = 0; + push_ascii_nstring(nname, name); + if (errno == E2BIG) { + fstring tname; + pull_ascii_nstring(tname, sizeof(tname), nname); + fstrcpy(work->work_group,tname); + DEBUG(0,("create_workgroup: workgroup name %s is too long. Truncating to %s\n", + name, tname)); + } else { + fstrcpy(work->work_group,name); + } work->serverlist = NULL; work->RunningElection = False; diff --git a/source3/smbd/negprot.c b/source3/smbd/negprot.c index 28e3cf97d1..96961368fb 100644 --- a/source3/smbd/negprot.c +++ b/source3/smbd/negprot.c @@ -169,6 +169,8 @@ static int reply_lanman2(char *inbuf, char *outbuf) static int negprot_spnego(char *p) { DATA_BLOB blob; + nstring dos_name; + fstring unix_name; uint8 guid[17]; const char *OIDs_krb5[] = {OID_KERBEROS5, OID_KERBEROS5_OLD, @@ -181,7 +183,11 @@ static int negprot_spnego(char *p) global_spnego_negotiated = True; ZERO_STRUCT(guid); - safe_strcpy((char *)guid, global_myname(), sizeof(guid)-1); + + safe_strcpy(unix_name, global_myname(), sizeof(unix_name)-1); + strlower_m(unix_name); + push_ascii_nstring(dos_name, unix_name); + safe_strcpy((char *)guid, dos_name, sizeof(guid)-1); #ifdef DEVELOPER /* valgrind fixer... */ @@ -192,8 +198,6 @@ static int negprot_spnego(char *p) } #endif - strlower_m((char *)guid); - #if 0 /* strangely enough, NT does not sent the single OID NTLMSSP when not a ADS member, it sends no OIDs at all |