From f348d148b463ca61cbc48d2aadeaa099f7150425 Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Wed, 8 Jun 2011 16:27:06 +1000 Subject: s3-param Remove special case for global_scope() There is no reason this can't be a normal constant string in the loadparm system. (Past reasons were that we didn't have lp_set_cmdline()) Andrew Bartlett --- source3/include/proto.h | 3 +-- source3/lib/popt_common.c | 2 +- source3/lib/util_names.c | 27 --------------------------- source3/libsmb/nmblib.c | 10 +++++----- source3/nmbd/nmbd_packets.c | 8 ++++---- source3/nmbd/nmbd_winsserver.c | 4 ++-- source3/param/loadparm.c | 14 ++------------ source3/param/loadparm_ctx.c | 2 +- source3/utils/smbcontrol.c | 2 +- 9 files changed, 17 insertions(+), 55 deletions(-) (limited to 'source3') diff --git a/source3/include/proto.h b/source3/include/proto.h index 2edd72e026..edcb025101 100644 --- a/source3/include/proto.h +++ b/source3/include/proto.h @@ -504,8 +504,6 @@ const char *get_global_sam_name(void); enum protocol_types get_Protocol(void); void set_Protocol(enum protocol_types p); bool all_zero(const uint8_t *ptr, size_t size); -bool set_global_scope(const char *scope); -const char *global_scope(void); void gfree_names(void); void gfree_all( void ); const char *my_netbios_names(int i); @@ -1198,6 +1196,7 @@ char *lp_passwd_program(void); char *lp_passwd_chat(void); const char *lp_passwordserver(void); const char *lp_name_resolve_order(void); +const char *lp_netbios_scope(void); const char *lp_workgroup(void); const char *lp_realm(void); const char *lp_dnsdomain(void); diff --git a/source3/lib/popt_common.c b/source3/lib/popt_common.c index 628ed65820..58f0478a76 100644 --- a/source3/lib/popt_common.c +++ b/source3/lib/popt_common.c @@ -143,7 +143,7 @@ static void popt_common_callback(poptContext con, case 'i': if (arg) { - set_global_scope(arg); + lp_set_cmdline("netbios scope", arg); } break; diff --git a/source3/lib/util_names.c b/source3/lib/util_names.c index d8ebf213cf..78d7988367 100644 --- a/source3/lib/util_names.c +++ b/source3/lib/util_names.c @@ -30,35 +30,9 @@ static char *smb_myname; static char *smb_myworkgroup; -static char *smb_scope; static int smb_num_netbios_names; static char **smb_my_netbios_names; -/*********************************************************************** - Allocate and set scope. Ensure upper case. -***********************************************************************/ - -bool set_global_scope(const char *scope) -{ - SAFE_FREE(smb_scope); - smb_scope = SMB_STRDUP(scope); - if (!smb_scope) - return False; - strupper_m(smb_scope); - return True; -} - -/********************************************************************* - Ensure scope is never null string. -*********************************************************************/ - -const char *global_scope(void) -{ - if (!smb_scope) - set_global_scope(""); - return smb_scope; -} - static void free_netbios_names_array(void) { int i; @@ -102,7 +76,6 @@ static bool set_my_netbios_names(const char *name, int i) void gfree_names(void) { gfree_netbios_names(); - SAFE_FREE( smb_scope ); free_netbios_names_array(); free_local_machine_name(); } diff --git a/source3/libsmb/nmblib.c b/source3/libsmb/nmblib.c index f4d5ec7bbb..767ff81476 100644 --- a/source3/libsmb/nmblib.c +++ b/source3/libsmb/nmblib.c @@ -936,7 +936,7 @@ void make_nmb_name( struct nmb_name *n, const char *name, int type) strupper_m(unix_name); push_ascii(n->name, unix_name, sizeof(n->name), STR_TERMINATE); n->name_type = (unsigned int)type & 0xFF; - push_ascii(n->scope, global_scope(), 64, STR_TERMINATE); + push_ascii(n->scope, lp_netbios_scope(), 64, STR_TERMINATE); } /******************************************************************* @@ -1261,7 +1261,7 @@ char *name_mangle(TALLOC_CTX *mem_ctx, const char *In, char name_type) char *result; char *p; - result = talloc_array(mem_ctx, char, 33 + strlen(global_scope()) + 2); + result = talloc_array(mem_ctx, char, 33 + strlen(lp_netbios_scope()) + 2); if (result == NULL) { return NULL; } @@ -1296,8 +1296,8 @@ char *name_mangle(TALLOC_CTX *mem_ctx, const char *In, char name_type) p[0] = '\0'; /* Add the scope string. */ - for( i = 0, len = 0; *(global_scope()) != '\0'; i++, len++ ) { - switch( (global_scope())[i] ) { + for( i = 0, len = 0; *(lp_netbios_scope()) != '\0'; i++, len++ ) { + switch( (lp_netbios_scope())[i] ) { case '\0': p[0] = len; if( len > 0 ) @@ -1309,7 +1309,7 @@ char *name_mangle(TALLOC_CTX *mem_ctx, const char *In, char name_type) len = -1; break; default: - p[len+1] = (global_scope())[i]; + p[len+1] = (lp_netbios_scope())[i]; break; } } diff --git a/source3/nmbd/nmbd_packets.c b/source3/nmbd/nmbd_packets.c index 3d51849287..a89f49c8fc 100644 --- a/source3/nmbd/nmbd_packets.c +++ b/source3/nmbd/nmbd_packets.c @@ -1073,9 +1073,9 @@ static void process_browse_packet(struct packet_struct *p, const char *buf,int l /* 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); - if (!strequal(scope, global_scope())) { + if (!strequal(scope, lp_netbios_scope())) { DEBUG(7,("process_browse_packet: Discarding datagram from IP %s. Scope (%s) \ -mismatch with our scope (%s).\n", inet_ntoa(p->ip), scope, global_scope())); +mismatch with our scope (%s).\n", inet_ntoa(p->ip), scope, lp_netbios_scope())); return; } @@ -1161,9 +1161,9 @@ static void process_lanman_packet(struct packet_struct *p, const char *buf,int l /* 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); - if (!strequal(scope, global_scope())) { + if (!strequal(scope, lp_netbios_scope())) { DEBUG(7,("process_lanman_packet: Discarding datagram from IP %s. Scope (%s) \ -mismatch with our scope (%s).\n", inet_ntoa(p->ip), scope, global_scope())); +mismatch with our scope (%s).\n", inet_ntoa(p->ip), scope, lp_netbios_scope())); return; } diff --git a/source3/nmbd/nmbd_winsserver.c b/source3/nmbd/nmbd_winsserver.c index d569154719..1370535b7c 100644 --- a/source3/nmbd/nmbd_winsserver.c +++ b/source3/nmbd/nmbd_winsserver.c @@ -75,7 +75,7 @@ static void wins_delete_all_1b_in_memory_records(void) } /**************************************************************************** - Convert a wins.tdb record to a struct name_record. Add in our global_scope(). + Convert a wins.tdb record to a struct name_record. Add in our lp_netbios_scope(). *****************************************************************************/ static struct name_record *wins_record_to_name_record(TDB_DATA key, TDB_DATA data) @@ -128,7 +128,7 @@ static struct name_record *wins_record_to_name_record(TDB_DATA key, TDB_DATA dat push_ascii_nstring(namerec->name.name, (const char *)key.dptr); namerec->name.name_type = key.dptr[sizeof(unstring)]; /* Add the scope. */ - push_ascii(namerec->name.scope, global_scope(), 64, STR_TERMINATE); + push_ascii(namerec->name.scope, lp_netbios_scope(), 64, STR_TERMINATE); /* We're using a byte-by-byte compare, so we must be sure that * unused space doesn't have garbage in it. diff --git a/source3/param/loadparm.c b/source3/param/loadparm.c index 56f039f46e..619faf69eb 100644 --- a/source3/param/loadparm.c +++ b/source3/param/loadparm.c @@ -708,7 +708,6 @@ static bool handle_idmap_gid( int snum, const char *pszParmValue, char **ptr); static bool handle_debug_list( int snum, const char *pszParmValue, char **ptr ); static bool handle_realm( int snum, const char *pszParmValue, char **ptr ); static bool handle_netbios_aliases( int snum, const char *pszParmValue, char **ptr ); -static bool handle_netbios_scope( int snum, const char *pszParmValue, char **ptr ); static bool handle_charset( int snum, const char *pszParmValue, char **ptr ); static bool handle_dos_charset( int snum, const char *pszParmValue, char **ptr ); static bool handle_printing( int snum, const char *pszParmValue, char **ptr); @@ -1048,7 +1047,7 @@ static struct parm_struct parm_table[] = { .type = P_USTRING, .p_class = P_GLOBAL, .ptr = &Globals.szNetbiosScope, - .special = handle_netbios_scope, + .special = NULL, .enum_list = NULL, .flags = FLAG_ADVANCED, }, @@ -5618,6 +5617,7 @@ FN_GLOBAL_STRING(lp_passwd_chat, &Globals.szPasswdChat) FN_GLOBAL_CONST_STRING(lp_passwordserver, &Globals.szPasswordServer) FN_GLOBAL_CONST_STRING(lp_name_resolve_order, &Globals.szNameResolveOrder) FN_GLOBAL_CONST_STRING(lp_workgroup, &Globals.szWorkgroup) +FN_GLOBAL_CONST_STRING(lp_netbios_scope, &Globals.szNetbiosScope) FN_GLOBAL_CONST_STRING(lp_realm, &Globals.szRealmUpper) FN_GLOBAL_CONST_STRING(lp_dnsdomain, &Globals.szDnsDomain) FN_GLOBAL_CONST_STRING(lp_afs_username_map, &Globals.szAfsUsernameMap) @@ -7599,16 +7599,6 @@ static bool handle_realm(int snum, const char *pszParmValue, char **ptr) return ret; } -static bool handle_netbios_scope(int snum, const char *pszParmValue, char **ptr) -{ - bool ret; - - ret = set_global_scope(pszParmValue); - string_set(&Globals.szNetbiosScope,global_scope()); - - return ret; -} - static bool handle_netbios_aliases(int snum, const char *pszParmValue, char **ptr) { TALLOC_FREE(Globals.szNetbiosAliases); diff --git a/source3/param/loadparm_ctx.c b/source3/param/loadparm_ctx.c index cc2468651a..d07ef45d36 100644 --- a/source3/param/loadparm_ctx.c +++ b/source3/param/loadparm_ctx.c @@ -49,7 +49,7 @@ static const struct loadparm_s3_context s3_fns = .workgroup = lp_workgroup, .netbios_name = global_myname, - .netbios_scope = global_scope, + .netbios_scope = lp_netbios_scope, .lanman_auth = lp_lanman_auth, .ntlm_auth = lp_ntlm_auth, diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c index 0a3a94a1df..5520dcf608 100644 --- a/source3/utils/smbcontrol.c +++ b/source3/utils/smbcontrol.c @@ -1202,7 +1202,7 @@ static void my_make_nmb_name( struct nmb_name *n, const char *name, int type) strupper_m(unix_name); push_ascii(n->name, unix_name, sizeof(n->name), STR_TERMINATE); n->name_type = (unsigned int)type & 0xFF; - push_ascii(n->scope, global_scope(), 64, STR_TERMINATE); + push_ascii(n->scope, lp_netbios_scope(), 64, STR_TERMINATE); } static bool do_nodestatus(struct messaging_context *msg_ctx, -- cgit