From b396ad07d131fba4945060b35c870abec626cbc8 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 15 Apr 2008 13:49:59 +0200 Subject: libsmbconf: add handling of "NULL" strings to smbconf_add_string_to_array() Michael (This used to be commit aba261a9143bc7ab681b1c57ccfc08da0cffcfe7) --- source3/lib/smbconf/smbconf_util.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/source3/lib/smbconf/smbconf_util.c b/source3/lib/smbconf/smbconf_util.c index 1a3a0ded44..20bd51a62b 100644 --- a/source3/lib/smbconf/smbconf_util.c +++ b/source3/lib/smbconf/smbconf_util.c @@ -82,7 +82,7 @@ WERROR smbconf_add_string_to_array(TALLOC_CTX *mem_ctx, { char **new_array = NULL; - if ((array == NULL) || (string == NULL)) { + if (array == NULL) { return WERR_INVALID_PARAM; } @@ -91,10 +91,14 @@ WERROR smbconf_add_string_to_array(TALLOC_CTX *mem_ctx, return WERR_NOMEM; } - new_array[count] = talloc_strdup(new_array, string); - if (new_array[count] == NULL) { - TALLOC_FREE(new_array); - return WERR_NOMEM; + if (string == NULL) { + new_array[count] = NULL; + } else { + new_array[count] = talloc_strdup(new_array, string); + if (new_array[count] == NULL) { + TALLOC_FREE(new_array); + return WERR_NOMEM; + } } *array = new_array; -- cgit From 0e7497936ce71a65af00ac08fa372082310c2fba Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 15 Apr 2008 13:50:27 +0200 Subject: libsmbconf: add handling of NULL strings to smbconf_find_in_array(). Michael (This used to be commit a5923bafe9b543d50dca06d251186948baeac8cc) --- source3/lib/smbconf/smbconf_util.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/source3/lib/smbconf/smbconf_util.c b/source3/lib/smbconf/smbconf_util.c index 20bd51a62b..b2e253dd26 100644 --- a/source3/lib/smbconf/smbconf_util.c +++ b/source3/lib/smbconf/smbconf_util.c @@ -111,12 +111,14 @@ bool smbconf_find_in_array(const char *string, char **list, { uint32_t i; - if ((string == NULL) || (list == NULL)) { + if (list == NULL) { return false; } for (i = 0; i < num_entries; i++) { - if (strequal(string, list[i])) { + if (((string == NULL) && (list[i] == NULL)) || + strequal(string, list[i])) + { if (entry != NULL) { *entry = i; } -- cgit From e700800720aec4b9a85a5c3cbc95cd78a03defaa Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 15 Apr 2008 14:36:39 +0200 Subject: libsmbconf: allow NULL sharename in smbconf_share_exists(). Michael (This used to be commit cb23052b2055d77924b2a593ec14f0c1de9a3b51) --- source3/lib/smbconf/smbconf.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 541b163bfb..0359e000d3 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -183,9 +183,6 @@ WERROR smbconf_get_share_names(struct smbconf_ctx *ctx, bool smbconf_share_exists(struct smbconf_ctx *ctx, const char *servicename) { - if (servicename == NULL) { - return false; - } return ctx->ops->share_exists(ctx, servicename); } -- cgit From 34e8ec54ce46a620515836b0d584dc1f59522e37 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 15 Apr 2008 14:37:15 +0200 Subject: libsmbconf: default to the NULL section when a parameter is encountered w/o section Michael (This used to be commit e1b98f1cbce72d12085d86da834f0949ecbfbf67) --- source3/lib/smbconf/smbconf_txt_simple.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/source3/lib/smbconf/smbconf_txt_simple.c b/source3/lib/smbconf/smbconf_txt_simple.c index 1ce9069020..bd7693047c 100644 --- a/source3/lib/smbconf/smbconf_txt_simple.c +++ b/source3/lib/smbconf/smbconf_txt_simple.c @@ -121,8 +121,14 @@ static bool smbconf_txt_do_parameter(const char *param_name, struct txt_cache *cache = tpd->cache; if (cache->num_shares == 0) { - /* not in any share ... */ - return false; + /* + * not in any share yet, + * initialize the "empty" section (NULL): + * parameters without a previous [section] are stored here. + */ + if (!smbconf_txt_do_section(NULL, private_data)) { + return false; + } } param_names = cache->param_names[cache->current_share]; -- cgit From 7624bab9631b004815decfeced58ee72ebe125cb Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 15 Apr 2008 14:38:36 +0200 Subject: net conf: fix output of out-of-share parameters in test mode import Michael (This used to be commit 5424e07e7d3e842488cba7ae389124f01221c5ba) --- source3/utils/net_conf.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 88cc15e0eb..7d1658ba94 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -150,10 +150,18 @@ static WERROR import_process_service(struct smbconf_ctx *conf_ctx, TALLOC_CTX *mem_ctx = talloc_stackframe(); if (opt_testmode) { - d_printf("[%s]\n", servicename); - for (idx = 0; idx < num_params; idx ++) { - d_printf("\t%s = %s\n", param_names[idx], - param_values[idx]); + if (servicename != NULL) { + d_printf("[%s]\n", servicename); + for (idx = 0; idx < num_params; idx++) { + d_printf("\t%s = %s\n", param_names[idx], + param_values[idx]); + } + } + else { + for (idx = 0; idx < num_params; idx++) { + d_printf("%s = %s\n", param_names[idx], + param_values[idx]); + } } d_printf("\n"); goto done; -- cgit From 747d4a8f044adeb43dd251e2e6a44641c838785b Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 15 Apr 2008 16:06:57 +0200 Subject: libsmbconf: make sure to always list the NULL section first in text backend. Michael (This used to be commit b50fdf321dc8056caa2b057cbd7f83792dfbcd4d) --- source3/lib/smbconf/smbconf_txt_simple.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/source3/lib/smbconf/smbconf_txt_simple.c b/source3/lib/smbconf/smbconf_txt_simple.c index bd7693047c..d2dc24a117 100644 --- a/source3/lib/smbconf/smbconf_txt_simple.c +++ b/source3/lib/smbconf/smbconf_txt_simple.c @@ -307,10 +307,21 @@ static WERROR smbconf_txt_get_share_names(struct smbconf_ctx *ctx, goto done; } - /* make sure "global" is always listed first */ + /* make sure "global" is always listed first, + * possibly after NULL section */ + + if (smbconf_share_exists(ctx, NULL)) { + werr = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names, + 0, NULL); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + added_count++; + } + if (smbconf_share_exists(ctx, GLOBAL_NAME)) { werr = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names, - 0, GLOBAL_NAME); + added_count, GLOBAL_NAME); if (!W_ERROR_IS_OK(werr)) { goto done; } @@ -318,7 +329,9 @@ static WERROR smbconf_txt_get_share_names(struct smbconf_ctx *ctx, } for (count = 0; count < pd(ctx)->cache->num_shares; count++) { - if (strequal(pd(ctx)->cache->share_names[count], GLOBAL_NAME)) { + if (strequal(pd(ctx)->cache->share_names[count], GLOBAL_NAME) || + (pd(ctx)->cache->share_names[count] == NULL)) + { continue; } -- cgit From 770b1923dc7735c2681c9976201569896feb74d9 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 15 Apr 2008 17:36:11 +0200 Subject: net conf: simplify logic in test output of net conf import. Michael (This used to be commit 367c8b133b2f3e73155f20f689602909eef9827b) --- source3/utils/net_conf.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 7d1658ba94..293485aab1 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -150,18 +150,14 @@ static WERROR import_process_service(struct smbconf_ctx *conf_ctx, TALLOC_CTX *mem_ctx = talloc_stackframe(); if (opt_testmode) { + const char *indent = ""; if (servicename != NULL) { d_printf("[%s]\n", servicename); - for (idx = 0; idx < num_params; idx++) { - d_printf("\t%s = %s\n", param_names[idx], - param_values[idx]); - } + indent = "\t"; } - else { - for (idx = 0; idx < num_params; idx++) { - d_printf("%s = %s\n", param_names[idx], - param_values[idx]); - } + for (idx = 0; idx < num_params; idx++) { + d_printf("%s%s = %s\n", indent, param_names[idx], + param_values[idx]); } d_printf("\n"); goto done; -- cgit From ed85ea4248688005d1769894f0b2f2e86d822fde Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 15 Apr 2008 17:36:44 +0200 Subject: net conf: adapt output of NULL share params in net conf list. don't list NULL share name and don't indent these parameters Michael (This used to be commit 0212b38913945ce3c8b14734804d81f1cd315621) --- source3/utils/net_conf.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/source3/utils/net_conf.c b/source3/utils/net_conf.c index 293485aab1..4fffcf8a8c 100644 --- a/source3/utils/net_conf.c +++ b/source3/utils/net_conf.c @@ -246,11 +246,16 @@ static int net_conf_list(struct smbconf_ctx *conf_ctx, } for (share_count = 0; share_count < num_shares; share_count++) { - d_printf("[%s]\n", share_names[share_count]); + const char *indent = ""; + if (share_names[share_count] != NULL) { + d_printf("[%s]\n", share_names[share_count]); + indent = "\t"; + } for (param_count = 0; param_count < num_params[share_count]; param_count++) { - d_printf("\t%s = %s\n", + d_printf("%s%s = %s\n", + indent, param_names[share_count][param_count], param_values[share_count][param_count]); } -- cgit From be504b9d32e970428175a0cba8fdcceb4369721f Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 15 Apr 2008 17:37:39 +0200 Subject: libsmbconf: don't complain with WERR_ALREADY_EXISTS for NULL share in smbconf_create_share(). These are values stored inside the base key for registry. This is not getting deleted. Michael (This used to be commit aa167de8252bb615bd21fb3fd9468383b8357d32) --- source3/lib/smbconf/smbconf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source3/lib/smbconf/smbconf.c b/source3/lib/smbconf/smbconf.c index 0359e000d3..9565540df4 100644 --- a/source3/lib/smbconf/smbconf.c +++ b/source3/lib/smbconf/smbconf.c @@ -192,7 +192,7 @@ bool smbconf_share_exists(struct smbconf_ctx *ctx, WERROR smbconf_create_share(struct smbconf_ctx *ctx, const char *servicename) { - if (smbconf_share_exists(ctx, servicename)) { + if ((servicename != NULL) && smbconf_share_exists(ctx, servicename)) { return WERR_ALREADY_EXISTS; } -- cgit From bcaac7fa36329acd8220a4d7dbfc9a2ca9c12b58 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 15 Apr 2008 17:39:01 +0200 Subject: libmsbconf: add handling of NULL share parameters to registry backend. Michael (This used to be commit 6c1181fda2f040d9555917b10a65bc0dfc1f0593) --- source3/lib/smbconf/smbconf_reg.c | 106 +++++++++++++++++++++++++++++++++----- 1 file changed, 92 insertions(+), 14 deletions(-) diff --git a/source3/lib/smbconf/smbconf_reg.c b/source3/lib/smbconf/smbconf_reg.c index 2bdc11fa7f..39b05f7016 100644 --- a/source3/lib/smbconf/smbconf_reg.c +++ b/source3/lib/smbconf/smbconf_reg.c @@ -131,12 +131,11 @@ static WERROR smbconf_reg_open_service_key(TALLOC_CTX *mem_ctx, char *path = NULL; if (servicename == NULL) { - DEBUG(3, ("Error: NULL servicename given.\n")); - werr = WERR_INVALID_PARAM; - goto done; + path = talloc_strdup(mem_ctx, ctx->path); + } else { + path = talloc_asprintf(mem_ctx, "%s\\%s", ctx->path, + servicename); } - - path = talloc_asprintf(mem_ctx, "%s\\%s", ctx->path, servicename); if (path == NULL) { werr = WERR_NOMEM; goto done; @@ -544,6 +543,65 @@ done: return werr; } +static bool smbconf_reg_key_has_values(struct registry_key *key) +{ + WERROR werr; + uint32_t num_subkeys; + uint32_t max_subkeylen; + uint32_t max_subkeysize; + uint32_t num_values; + uint32_t max_valnamelen; + uint32_t max_valbufsize; + uint32_t secdescsize; + NTTIME last_changed_time; + + werr = reg_queryinfokey(key, &num_subkeys, &max_subkeylen, + &max_subkeysize, &num_values, &max_valnamelen, + &max_valbufsize, &secdescsize, + &last_changed_time); + if (!W_ERROR_IS_OK(werr)) { + return false; + } + + return (num_values != 0); +} + +/** + * delete all values from a key + */ +static WERROR smbconf_reg_delete_values(struct registry_key *key) +{ + WERROR werr; + char *valname; + struct registry_value *valvalue; + uint32_t count; + TALLOC_CTX *mem_ctx = talloc_stackframe(); + + for (count = 0; + werr = reg_enumvalue(mem_ctx, key, count, &valname, &valvalue), + W_ERROR_IS_OK(werr); + count++) + { + werr = reg_deletevalue(key, valname); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + } + if (!W_ERROR_EQUAL(WERR_NO_MORE_ITEMS, werr)) { + DEBUG(1, ("smbconf_reg_delete_values: " + "Error enumerating values of %s: %s\n", + key->key->name, + dos_errstr(werr))); + goto done; + } + + werr = WERR_OK; + +done: + TALLOC_FREE(mem_ctx); + return werr; +} + /********************************************************************** * * smbconf operations: registry implementations @@ -707,20 +765,30 @@ static WERROR smbconf_reg_get_share_names(struct smbconf_ctx *ctx, goto done; } - /* make sure "global" is always listed first */ - if (smbconf_share_exists(ctx, GLOBAL_NAME)) { + /* if there are values in the base key, return NULL as share name */ + werr = smbconf_reg_open_base_key(tmp_ctx, ctx, + SEC_RIGHTS_ENUM_SUBKEYS, &key); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + + if (smbconf_reg_key_has_values(key)) { werr = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names, - 0, GLOBAL_NAME); + 0, NULL); if (!W_ERROR_IS_OK(werr)) { goto done; } added_count++; } - werr = smbconf_reg_open_base_key(tmp_ctx, ctx, - SEC_RIGHTS_ENUM_SUBKEYS, &key); - if (!W_ERROR_IS_OK(werr)) { - goto done; + /* make sure "global" is always listed first */ + if (smbconf_share_exists(ctx, GLOBAL_NAME)) { + werr = smbconf_add_string_to_array(tmp_ctx, &tmp_share_names, + 1, GLOBAL_NAME); + if (!W_ERROR_IS_OK(werr)) { + goto done; + } + added_count++; } for (count = 0; @@ -789,7 +857,13 @@ static WERROR smbconf_reg_create_share(struct smbconf_ctx *ctx, TALLOC_CTX *mem_ctx = talloc_stackframe(); struct registry_key *key = NULL; - werr = smbconf_reg_create_service_key(mem_ctx, ctx, servicename, &key); + if (servicename == NULL) { + werr = smbconf_reg_open_base_key(mem_ctx, ctx, REG_KEY_WRITE, + &key); + } else { + werr = smbconf_reg_create_service_key(mem_ctx, ctx, + servicename, &key); + } TALLOC_FREE(mem_ctx); return werr; @@ -836,7 +910,11 @@ static WERROR smbconf_reg_delete_share(struct smbconf_ctx *ctx, goto done; } - werr = reg_deletekey_recursive(key, key, servicename); + if (servicename != NULL) { + werr = reg_deletekey_recursive(key, key, servicename); + } else { + werr = smbconf_reg_delete_values(key); + } done: TALLOC_FREE(mem_ctx); -- cgit From b64be89a6ddd1b9c62df98801f34f4d9116a06bf Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Tue, 15 Apr 2008 20:41:14 +0200 Subject: auth: add SeDiskOperatorsPrivilege to get_root_nt_token to fix registry shares. Michael (This used to be commit 6bb107b17d557c27d035ca518ab61296814a3cea) --- source3/auth/token_util.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/source3/auth/token_util.c b/source3/auth/token_util.c index fc93060fc6..6720a2cbd8 100644 --- a/source3/auth/token_util.c +++ b/source3/auth/token_util.c @@ -105,6 +105,8 @@ NT_USER_TOKEN *get_root_nt_token( void ) token = create_local_nt_token(NULL, &u_sid, False, 1, &global_sid_Builtin_Administrators); + token->privileges = se_disk_operators; + memcache_add_talloc( NULL, SINGLETON_CACHE_TALLOC, data_blob_string_const("root_nt_token"), token); -- cgit