From 151fc7400611b90f3236c74e3c40e8f75385fdee Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 23 Jul 2006 18:47:56 +0000 Subject: r17207: Add the ldb based shares configuration module (This used to be commit df1da91d4fe0233763398f46fe663e0b879054c3) --- source4/param/share_ldb.c | 281 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 281 insertions(+) create mode 100644 source4/param/share_ldb.c (limited to 'source4/param/share_ldb.c') diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c new file mode 100644 index 0000000000..58cab91521 --- /dev/null +++ b/source4/param/share_ldb.c @@ -0,0 +1,281 @@ +/* + Unix SMB/CIFS implementation. + + LDB based services configuration + + Copyright (C) Simo Sorce 2006 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include "includes.h" +#include "ldb/include/ldb.h" +#include "ldb/include/ldb_errors.h" +#include "auth/auth.h" +#include "db_wrap.h" +#include "param/share.h" + +static NTSTATUS sldb_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, struct share_context **ctx) +{ + struct ldb_context *sdb; + + *ctx = talloc(mem_ctx, struct share_context); + if (!*ctx) { + DEBUG(0, ("ERROR: Out of memory!\n")); + return NT_STATUS_NO_MEMORY; + } + + sdb = ldb_wrap_connect( *ctx, + private_path(*ctx, "share.ldb"), + system_session(*ctx), + NULL, 0, NULL); + + if (!sdb) { + talloc_free(*ctx); + return NT_STATUS_UNSUCCESSFUL; + } + + (*ctx)->ops = ops; + (*ctx)->priv_data = (void *)sdb; + + return NT_STATUS_OK; +} + +static const char *sldb_string_option(struct share_config *scfg, const char *opt_name, const char *defval) +{ + struct ldb_message *msg; + struct ldb_message_element *el; + + if (scfg == NULL) return defval; + + msg = talloc_get_type(scfg->opaque, struct ldb_message); + + if (strchr(opt_name, ':')) { + char *name, *p; + + name = talloc_strdup(scfg, opt_name); + if (!name) { + return NULL; + } + p = strchr(name, ':'); + *p = '-'; + + el = ldb_msg_find_element(msg, name); + } else { + el = ldb_msg_find_element(msg, opt_name); + } + + if (el == NULL) { + return defval; + } + + return (const char *)(el->values[0].data); +} + +static int sldb_int_option(struct share_config *scfg, const char *opt_name, int defval) +{ + const char *val; + int ret; + + val = sldb_string_option(scfg, opt_name, NULL); + if (val == NULL) return defval; + + errno = 0; + ret = (int)strtol(val, NULL, 10); + if (errno) return -1; + + return ret; +} + +static BOOL sldb_bool_option(struct share_config *scfg, const char *opt_name, BOOL defval) +{ + const char *val; + + val = sldb_string_option(scfg, opt_name, NULL); + if (val == NULL) return defval; + + if (strcasecmp(val, "true") == 0) return True; + + return False; +} + +static const char **sldb_string_list_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name) +{ + struct ldb_message *msg; + struct ldb_message_element *el; + const char **list; + int i; + + if (scfg == NULL) return NULL; + + msg = talloc_get_type(scfg->opaque, struct ldb_message); + + if (strchr(opt_name, ':')) { + char *name, *p; + + name = talloc_strdup(scfg, opt_name); + if (!name) { + return NULL; + } + p = strchr(name, ':'); + *p = '-'; + + el = ldb_msg_find_element(msg, name); + } else { + el = ldb_msg_find_element(msg, opt_name); + } + + if (el == NULL) { + return NULL; + } + + list = talloc_array(mem_ctx, const char *, el->num_values + 1); + if (!list) return NULL; + + for (i = 0; i < el->num_values; i++) { + list[i] = (const char *)(el->values[i].data); + } + list[i] = NULL; + + return list; +} + +static NTSTATUS sldb_list_all(TALLOC_CTX *mem_ctx, + struct share_context *ctx, + int *count, + const char ***names) +{ + int ret, i, j; + const char **n; + struct ldb_context *ldb; + struct ldb_result *res; + TALLOC_CTX *tmp_ctx; + + tmp_ctx = talloc_new(mem_ctx); + if (!tmp_ctx) { + DEBUG(0,("ERROR: Out of memory!\n")); + return NT_STATUS_NO_MEMORY; + } + + ldb = talloc_get_type(ctx->priv_data, struct ldb_context); + + ret = ldb_search(ldb, ldb_dn_explode(tmp_ctx, "CN=SHARES"), LDB_SCOPE_SUBTREE, "(name=*)", NULL, &res); + if (ret != LDB_SUCCESS) { + talloc_free(tmp_ctx); + return NT_STATUS_UNSUCCESSFUL; + } + talloc_steal(tmp_ctx, res); + + n = talloc_array(mem_ctx, const char *, res->count); + if (!n) { + DEBUG(0,("ERROR: Out of memory!\n")); + talloc_free(tmp_ctx); + return NT_STATUS_NO_MEMORY; + } + + for (i = 0, j = 0; i < res->count; i++) { + n[j] = talloc_strdup(n, ldb_msg_find_string(res->msgs[i], "name", NULL)); + if (!n[j]) { + DEBUG(0,("WARNING: Malformed share object in share database\n!")); + continue; + } + j++; + } + + *names = n; + *count = j; + talloc_free(tmp_ctx); + + return NT_STATUS_OK; +} + +static NTSTATUS sldb_get_config(TALLOC_CTX *mem_ctx, + struct share_context *ctx, + const char *name, + struct share_config **scfg) +{ + int ret; + struct share_config *s; + struct ldb_context *ldb; + struct ldb_result *res; + TALLOC_CTX *tmp_ctx; + char *filter; + + tmp_ctx = talloc_new(mem_ctx); + if (!tmp_ctx) { + DEBUG(0,("ERROR: Out of memory!\n")); + return NT_STATUS_NO_MEMORY; + } + + ldb = talloc_get_type(ctx->priv_data, struct ldb_context); + + filter = talloc_asprintf(tmp_ctx,"(name=%s)", name); + if (!filter) { + DEBUG(0,("ERROR: Out of memory!\n")); + talloc_free(tmp_ctx); + return NT_STATUS_NO_MEMORY; + } + ret = ldb_search(ldb, ldb_dn_explode(tmp_ctx, "CN=SHARES"), LDB_SCOPE_SUBTREE, filter, NULL, &res); + if (ret != LDB_SUCCESS || res->count != 1) { + talloc_free(tmp_ctx); + return NT_STATUS_OBJECT_NAME_NOT_FOUND; + } + talloc_steal(tmp_ctx, res); + + s = talloc(tmp_ctx, struct share_config); + if (!s) { + DEBUG(0,("ERROR: Out of memory!\n")); + talloc_free(tmp_ctx); + return NT_STATUS_NO_MEMORY; + } + + s->name = talloc_strdup(s, ldb_msg_find_string(res->msgs[0], "name", NULL)); + if (!s->name) { + DEBUG(0,("ERROR: Invalid share object!\n")); + talloc_free(tmp_ctx); + return NT_STATUS_UNSUCCESSFUL; + } + + s->opaque = talloc_steal(s, res->msgs[0]); + if (!s->opaque) { + DEBUG(0,("ERROR: Invalid share object!\n")); + talloc_free(tmp_ctx); + return NT_STATUS_UNSUCCESSFUL; + } + + s->ctx = ctx; + + *scfg = talloc_steal(mem_ctx, s); + + talloc_free(tmp_ctx); + return NT_STATUS_OK; +} + +NTSTATUS share_ldb_init(void *mem_ctx) +{ + struct share_ops ops; + + ops.name = "ldb"; + ops.init = sldb_init; + ops.string_option = sldb_string_option; + ops.int_option = sldb_int_option; + ops.bool_option = sldb_bool_option; + ops.string_list_option = sldb_string_list_option; + ops.list_all = sldb_list_all; + ops.get_config = sldb_get_config; + + return share_register(&ops); +} + -- cgit From a23b63a8e54db7d0ec98ad95cdca11dd4d039e17 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 13 Aug 2006 08:00:36 +0000 Subject: r17516: Change helper function names to make more clear what they are meant to do (This used to be commit ad75cf869550af66119d0293503024d41d834e02) --- source4/param/share_ldb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/param/share_ldb.c') diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index 58cab91521..8353d6f132 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -186,7 +186,7 @@ static NTSTATUS sldb_list_all(TALLOC_CTX *mem_ctx, } for (i = 0, j = 0; i < res->count; i++) { - n[j] = talloc_strdup(n, ldb_msg_find_string(res->msgs[i], "name", NULL)); + n[j] = talloc_strdup(n, ldb_msg_find_attr_as_string(res->msgs[i], "name", NULL)); if (!n[j]) { DEBUG(0,("WARNING: Malformed share object in share database\n!")); continue; @@ -241,7 +241,7 @@ static NTSTATUS sldb_get_config(TALLOC_CTX *mem_ctx, return NT_STATUS_NO_MEMORY; } - s->name = talloc_strdup(s, ldb_msg_find_string(res->msgs[0], "name", NULL)); + s->name = talloc_strdup(s, ldb_msg_find_attr_as_string(res->msgs[0], "name", NULL)); if (!s->name) { DEBUG(0,("ERROR: Invalid share object!\n")); talloc_free(tmp_ctx); -- cgit From a1bc3fb02e27a3d12c9ef4d09ce012ebe4e03674 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Mon, 21 Aug 2006 03:51:55 +0000 Subject: r17647: the init fns should not take a mem_ctx (This used to be commit e32fdc7e684b088629a5e858dd5bf0b80507ed65) --- source4/param/share_ldb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/param/share_ldb.c') diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index 8353d6f132..8349ad7fe5 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -263,7 +263,7 @@ static NTSTATUS sldb_get_config(TALLOC_CTX *mem_ctx, return NT_STATUS_OK; } -NTSTATUS share_ldb_init(void *mem_ctx) +NTSTATUS share_ldb_init(void) { struct share_ops ops; -- cgit From b0fb34fd24f5d73cfc2d3aca09379d85b9fb57dd Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Fri, 15 Sep 2006 05:18:53 +0000 Subject: r18542: Some late nite work. Now we can add and remove a share from the "Computer Management" console (not yet modify!) usinf share backend = ldb (This used to be commit ae2f6d4a5a372a37b9783a02bb8e7f16588b21f0) --- source4/param/share_ldb.c | 143 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 133 insertions(+), 10 deletions(-) (limited to 'source4/param/share_ldb.c') diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index 8349ad7fe5..2fd43c04a7 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -263,18 +263,141 @@ static NTSTATUS sldb_get_config(TALLOC_CTX *mem_ctx, return NT_STATUS_OK; } +#define SHARE_ADD_STRING(type, data) do { \ + err = ldb_msg_add_string(msg, type, data); \ + if (err != LDB_SUCCESS) { \ + DEBUG(2,("ERROR: unable to add share %s to ldb msg\n", type)); \ + ret = NT_STATUS_UNSUCCESSFUL; \ + goto done; \ + } } while(0) + +NTSTATUS sldb_create(struct share_context *ctx, struct share_info *info) +{ + struct ldb_context *ldb; + struct ldb_message *msg; + TALLOC_CTX *tmp_ctx; + NTSTATUS ret; + char *conns; + int err; + + if (!info->name || !info->type || !info->path) { + return NT_STATUS_INVALID_PARAMETER; + } + + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { + DEBUG(0,("ERROR: Out of memory!\n")); + return NT_STATUS_NO_MEMORY; + } + + ldb = talloc_get_type(ctx->priv_data, struct ldb_context); + + msg = ldb_msg_new(tmp_ctx); + if (!msg) { + DEBUG(0,("ERROR: Out of memory!\n")); + ret = NT_STATUS_NO_MEMORY; + goto done; + } + + /* TODO: escape info->name */ + msg->dn = ldb_dn_string_compose(tmp_ctx, ldb_dn_new(tmp_ctx), "CN=%s,CN=SHARES", info->name); + if (!msg->dn) { + DEBUG(0,("ERROR: Out of memory!\n")); + ret = NT_STATUS_NO_MEMORY; + goto done; + } + + SHARE_ADD_STRING("cn", info->name); + SHARE_ADD_STRING("objectClass", "top"); + SHARE_ADD_STRING("objectClass", "share"); + + SHARE_ADD_STRING(SHARE_NAME, info->name); + SHARE_ADD_STRING(SHARE_TYPE, info->type); + SHARE_ADD_STRING(SHARE_PATH, info->path); + if (strcmp(info->type, "DISK") == 0) { + SHARE_ADD_STRING(SHARE_NTVFS_HANDLER, "default"); + } + if (info->comment) { + SHARE_ADD_STRING(SHARE_COMMENT, info->comment); + } + + if (info->password) { + SHARE_ADD_STRING(SHARE_PASSWORD, info->password); + } + + /* TODO: Security Descriptor */ + + SHARE_ADD_STRING(SHARE_AVAILABLE, "True"); + SHARE_ADD_STRING(SHARE_BROWSEABLE, "True"); + SHARE_ADD_STRING(SHARE_READONLY, "False"); + conns = talloc_asprintf(tmp_ctx, "%d", info->max_users); + SHARE_ADD_STRING(SHARE_MAX_CONNECTIONS, conns); + + err = ldb_add(ldb, msg); + if (err != LDB_SUCCESS) { + DEBUG(2,("ERROR: unable to add share %s to share.ldb\n" + " err=%d [%s]\n", info->name, err, ldb_errstring(ldb))); + ret = NT_STATUS_UNSUCCESSFUL; + goto done; + } + + ret = NT_STATUS_OK; +done: + talloc_free(tmp_ctx); + return ret; +} + +NTSTATUS sldb_remove(struct share_context *ctx, const char *name) +{ + struct ldb_context *ldb; + struct ldb_dn *dn; + TALLOC_CTX *tmp_ctx; + NTSTATUS ret; + int err; + + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { + DEBUG(0,("ERROR: Out of memory!\n")); + return NT_STATUS_NO_MEMORY; + } + + ldb = talloc_get_type(ctx->priv_data, struct ldb_context); + + dn = ldb_dn_string_compose(tmp_ctx, ldb_dn_new(tmp_ctx), "CN=%s,CN=SHARES", name); + if (!dn) { + DEBUG(0,("ERROR: Out of memory!\n")); + ret = NT_STATUS_NO_MEMORY; + goto done; + } + + err = ldb_delete(ldb, dn); + if (err != LDB_SUCCESS) { + DEBUG(2,("ERROR: unable to remove share %s from share.ldb\n" + " err=%d [%s]\n", name, err, ldb_errstring(ldb))); + ret = NT_STATUS_UNSUCCESSFUL; + goto done; + } + + ret = NT_STATUS_OK; +done: + talloc_free(tmp_ctx); + return ret; +} + NTSTATUS share_ldb_init(void) { - struct share_ops ops; - - ops.name = "ldb"; - ops.init = sldb_init; - ops.string_option = sldb_string_option; - ops.int_option = sldb_int_option; - ops.bool_option = sldb_bool_option; - ops.string_list_option = sldb_string_list_option; - ops.list_all = sldb_list_all; - ops.get_config = sldb_get_config; + static struct share_ops ops = { + .name = "ldb", + .init = sldb_init, + .string_option = sldb_string_option, + .int_option = sldb_int_option, + .bool_option = sldb_bool_option, + .string_list_option = sldb_string_list_option, + .list_all = sldb_list_all, + .get_config = sldb_get_config, + .create = sldb_create, + .remove = sldb_remove + }; return share_register(&ops); } -- cgit From c4d45aac9da6b4fdade4e8ff3434a412af6db8fc Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 17 Sep 2006 00:15:13 +0000 Subject: r18590: Some more work on the srvsvc pipe (This used to be commit 2c035787d47c6055c4081021f30d08929f178ca3) --- source4/param/share_ldb.c | 243 ++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 214 insertions(+), 29 deletions(-) (limited to 'source4/param/share_ldb.c') diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index 2fd43c04a7..21f6938f69 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -174,7 +174,7 @@ static NTSTATUS sldb_list_all(TALLOC_CTX *mem_ctx, ret = ldb_search(ldb, ldb_dn_explode(tmp_ctx, "CN=SHARES"), LDB_SCOPE_SUBTREE, "(name=*)", NULL, &res); if (ret != LDB_SUCCESS) { talloc_free(tmp_ctx); - return NT_STATUS_UNSUCCESSFUL; + return NT_STATUS_BAD_NETWORK_NAME; } talloc_steal(tmp_ctx, res); @@ -230,7 +230,7 @@ static NTSTATUS sldb_get_config(TALLOC_CTX *mem_ctx, ret = ldb_search(ldb, ldb_dn_explode(tmp_ctx, "CN=SHARES"), LDB_SCOPE_SUBTREE, filter, NULL, &res); if (ret != LDB_SUCCESS || res->count != 1) { talloc_free(tmp_ctx); - return NT_STATUS_OBJECT_NAME_NOT_FOUND; + return NT_STATUS_BAD_NETWORK_NAME; } talloc_steal(tmp_ctx, res); @@ -263,24 +263,48 @@ static NTSTATUS sldb_get_config(TALLOC_CTX *mem_ctx, return NT_STATUS_OK; } -#define SHARE_ADD_STRING(type, data) do { \ - err = ldb_msg_add_string(msg, type, data); \ +#define SHARE_ADD_STRING(name, value) do { \ + err = ldb_msg_add_string(msg, name, value); \ if (err != LDB_SUCCESS) { \ - DEBUG(2,("ERROR: unable to add share %s to ldb msg\n", type)); \ + DEBUG(2,("ERROR: unable to add string share option %s to ldb msg\n", name)); \ ret = NT_STATUS_UNSUCCESSFUL; \ goto done; \ } } while(0) -NTSTATUS sldb_create(struct share_context *ctx, struct share_info *info) +#define SHARE_ADD_INT(name, value) do { \ + err = ldb_msg_add_fmt(msg, name, "%d", value); \ + if (err != LDB_SUCCESS) { \ + DEBUG(2,("ERROR: unable to add integer share option %s to ldb msg\n", name)); \ + ret = NT_STATUS_UNSUCCESSFUL; \ + goto done; \ + } } while(0) + +#define SHARE_ADD_BLOB(name, value) do { \ + err = ldb_msg_add_value(msg, name, value); \ + if (err != LDB_SUCCESS) { \ + DEBUG(2,("ERROR: unable to add blob share option %s to ldb msg\n", name)); \ + ret = NT_STATUS_UNSUCCESSFUL; \ + goto done; \ + } } while(0) + +NTSTATUS sldb_create(struct share_context *ctx, const char *name, struct share_info *info, int count) { struct ldb_context *ldb; struct ldb_message *msg; TALLOC_CTX *tmp_ctx; NTSTATUS ret; - char *conns; - int err; - - if (!info->name || !info->type || !info->path) { + int err, i, j; + + for (i = 0, j = 0; i < count || j != 0x03; i++) { + if (strcasecmp(info[i].name, SHARE_TYPE) == 0) j |= 0x02; + if (strcasecmp(info[i].name, SHARE_PATH) == 0) j |= 0x01; + if (strcasecmp(info[i].name, SHARE_NAME) == 0) { + if (strcasecmp(name, (char *)info[i].value) != 0) { + return NT_STATUS_INVALID_PARAMETER; + } + } + } + if (!name || j != 0x03) { return NT_STATUS_INVALID_PARAMETER; } @@ -300,29 +324,36 @@ NTSTATUS sldb_create(struct share_context *ctx, struct share_info *info) } /* TODO: escape info->name */ - msg->dn = ldb_dn_string_compose(tmp_ctx, ldb_dn_new(tmp_ctx), "CN=%s,CN=SHARES", info->name); + msg->dn = ldb_dn_string_compose(tmp_ctx, ldb_dn_new(tmp_ctx), "CN=%s,CN=SHARES", name); if (!msg->dn) { DEBUG(0,("ERROR: Out of memory!\n")); ret = NT_STATUS_NO_MEMORY; goto done; } - SHARE_ADD_STRING("cn", info->name); SHARE_ADD_STRING("objectClass", "top"); SHARE_ADD_STRING("objectClass", "share"); - - SHARE_ADD_STRING(SHARE_NAME, info->name); - SHARE_ADD_STRING(SHARE_TYPE, info->type); - SHARE_ADD_STRING(SHARE_PATH, info->path); - if (strcmp(info->type, "DISK") == 0) { - SHARE_ADD_STRING(SHARE_NTVFS_HANDLER, "default"); - } - if (info->comment) { - SHARE_ADD_STRING(SHARE_COMMENT, info->comment); - } - - if (info->password) { - SHARE_ADD_STRING(SHARE_PASSWORD, info->password); + SHARE_ADD_STRING("cn", name); + SHARE_ADD_STRING(SHARE_NAME, name); + + for (i = 0; i < count; i++) { + if (strcasecmp(info[i].name, SHARE_NAME) == 0) continue; + + switch (info[i].type) { + case SHARE_INFO_STRING: + SHARE_ADD_STRING(info[i].name, (char *)info[i].value); + break; + case SHARE_INFO_INT: + SHARE_ADD_INT(info[i].name, *((int *)info[i].value)); + break; + case SHARE_INFO_BLOB: + SHARE_ADD_BLOB(info[i].name, (DATA_BLOB *)info[i].value); + break; + default: + DEBUG(2,("ERROR: Invalid share info type for %s\n", info[i].name)); + ret = NT_STATUS_INVALID_PARAMETER; + goto done; + } } /* TODO: Security Descriptor */ @@ -330,14 +361,167 @@ NTSTATUS sldb_create(struct share_context *ctx, struct share_info *info) SHARE_ADD_STRING(SHARE_AVAILABLE, "True"); SHARE_ADD_STRING(SHARE_BROWSEABLE, "True"); SHARE_ADD_STRING(SHARE_READONLY, "False"); - conns = talloc_asprintf(tmp_ctx, "%d", info->max_users); - SHARE_ADD_STRING(SHARE_MAX_CONNECTIONS, conns); err = ldb_add(ldb, msg); if (err != LDB_SUCCESS) { DEBUG(2,("ERROR: unable to add share %s to share.ldb\n" - " err=%d [%s]\n", info->name, err, ldb_errstring(ldb))); - ret = NT_STATUS_UNSUCCESSFUL; + " err=%d [%s]\n", name, err, ldb_errstring(ldb))); + if (err == LDB_ERR_NO_SUCH_OBJECT) { + ret = NT_STATUS_BAD_NETWORK_NAME; + } else { + ret = NT_STATUS_UNSUCCESSFUL; + } + goto done; + } + + ret = NT_STATUS_OK; +done: + talloc_free(tmp_ctx); + return ret; +} + +#define SHARE_MOD_STRING(name, value) do { \ + err = ldb_msg_add_empty(msg, name, LDB_FLAG_MOD_REPLACE); \ + if (err != LDB_SUCCESS) { \ + DEBUG(2,("ERROR: unable to add string share option %s to ldb msg\n", name)); \ + ret = NT_STATUS_UNSUCCESSFUL; \ + goto done; \ + } \ + err = ldb_msg_add_string(msg, name, value); \ + if (err != LDB_SUCCESS) { \ + DEBUG(2,("ERROR: unable to add string share option %s to ldb msg\n", name)); \ + ret = NT_STATUS_UNSUCCESSFUL; \ + goto done; \ + } } while(0) + +#define SHARE_MOD_INT(name, value) do { \ + err = ldb_msg_add_empty(msg, name, LDB_FLAG_MOD_REPLACE); \ + if (err != LDB_SUCCESS) { \ + DEBUG(2,("ERROR: unable to add string share option %s to ldb msg\n", name)); \ + ret = NT_STATUS_UNSUCCESSFUL; \ + goto done; \ + } \ + err = ldb_msg_add_fmt(msg, name, "%d", value); \ + if (err != LDB_SUCCESS) { \ + DEBUG(2,("ERROR: unable to add integer share option %s to ldb msg\n", name)); \ + ret = NT_STATUS_UNSUCCESSFUL; \ + goto done; \ + } } while(0) + +#define SHARE_MOD_BLOB(name, value) do { \ + err = ldb_msg_add_empty(msg, name, LDB_FLAG_MOD_REPLACE); \ + if (err != LDB_SUCCESS) { \ + DEBUG(2,("ERROR: unable to add string share option %s to ldb msg\n", name)); \ + ret = NT_STATUS_UNSUCCESSFUL; \ + goto done; \ + } \ + err = ldb_msg_add_value(msg, name, value); \ + if (err != LDB_SUCCESS) { \ + DEBUG(2,("ERROR: unable to add blob share option %s to ldb msg\n", name)); \ + ret = NT_STATUS_UNSUCCESSFUL; \ + goto done; \ + } } while(0) + +NTSTATUS sldb_set(struct share_context *ctx, const char *name, struct share_info *info, int count) +{ + struct ldb_context *ldb; + struct ldb_message *msg; + TALLOC_CTX *tmp_ctx; + NTSTATUS ret; + bool rename = False; + char *newname; + int err, i; + + if (!name) { + return NT_STATUS_INVALID_PARAMETER; + } + + tmp_ctx = talloc_new(NULL); + if (!tmp_ctx) { + DEBUG(0,("ERROR: Out of memory!\n")); + return NT_STATUS_NO_MEMORY; + } + + ldb = talloc_get_type(ctx->priv_data, struct ldb_context); + + msg = ldb_msg_new(tmp_ctx); + if (!msg) { + DEBUG(0,("ERROR: Out of memory!\n")); + ret = NT_STATUS_NO_MEMORY; + goto done; + } + + /* TODO: escape name */ + msg->dn = ldb_dn_string_compose(tmp_ctx, ldb_dn_new(tmp_ctx), "CN=%s,CN=SHARES", name); + if (!msg->dn) { + DEBUG(0,("ERROR: Out of memory!\n")); + ret = NT_STATUS_NO_MEMORY; + goto done; + } + + for (i = 0; i < count; i++) { + if (strcasecmp(info[i].name, SHARE_NAME) == 0) { + if (strcasecmp(name, (char *)info[i].value) != 0) { + rename = True; + newname = (char *)info[i].value; + SHARE_MOD_STRING("cn", (char *)info[i].value); + } + } + + switch (info[i].type) { + case SHARE_INFO_STRING: + SHARE_MOD_STRING(info[i].name, (char *)info[i].value); + break; + case SHARE_INFO_INT: + SHARE_MOD_INT(info[i].name, *((int *)info[i].value)); + break; + case SHARE_INFO_BLOB: + SHARE_MOD_BLOB(info[i].name, (DATA_BLOB *)info[i].value); + break; + default: + DEBUG(2,("ERROR: Invalid share info type for %s\n", info[i].name)); + ret = NT_STATUS_INVALID_PARAMETER; + goto done; + } + } + + if (rename) { + struct ldb_dn *olddn, *newdn; + + olddn = msg->dn; + + /* TODO: escape newname */ + newdn = ldb_dn_string_compose(tmp_ctx, ldb_dn_new(tmp_ctx), "CN=%s,CN=SHARES", newname); + if (!newdn) { + DEBUG(0,("ERROR: Out of memory!\n")); + ret = NT_STATUS_NO_MEMORY; + goto done; + } + + err = ldb_rename(ldb, olddn, newdn); + if (err != LDB_SUCCESS) { + DEBUG(2,("ERROR: unable to rename share %s (to %s)\n" + " err=%d [%s]\n", name, newname, err, ldb_errstring(ldb))); + if (err == LDB_ERR_NO_SUCH_OBJECT) { + ret = NT_STATUS_BAD_NETWORK_NAME; + } else { + ret = NT_STATUS_UNSUCCESSFUL; + } + goto done; + } + + msg->dn = newdn; + } + + err = ldb_modify(ldb, msg); + if (err != LDB_SUCCESS) { + DEBUG(2,("ERROR: unable to add share %s to share.ldb\n" + " err=%d [%s]\n", name, err, ldb_errstring(ldb))); + if (err == LDB_ERR_NO_SUCH_OBJECT) { + ret = NT_STATUS_BAD_NETWORK_NAME; + } else { + ret = NT_STATUS_UNSUCCESSFUL; + } goto done; } @@ -396,6 +580,7 @@ NTSTATUS share_ldb_init(void) .list_all = sldb_list_all, .get_config = sldb_get_config, .create = sldb_create, + .set = sldb_set, .remove = sldb_remove }; -- cgit From 9dd6cac44a63c20e616cf15815bef61303da56c2 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 17 Sep 2006 03:00:05 +0000 Subject: r18591: Better defaults for share creation Fix logic error in paged_results (This used to be commit 34ce1f8e1bab2debb508aa8bf478231389a77d42) --- source4/param/share_ldb.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'source4/param/share_ldb.c') diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index 21f6938f69..fba204c834 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -361,6 +361,8 @@ NTSTATUS sldb_create(struct share_context *ctx, const char *name, struct share_i SHARE_ADD_STRING(SHARE_AVAILABLE, "True"); SHARE_ADD_STRING(SHARE_BROWSEABLE, "True"); SHARE_ADD_STRING(SHARE_READONLY, "False"); + SHARE_ADD_STRING(SHARE_NTVFS_HANDLER, "unixuid"); + SHARE_ADD_STRING(SHARE_NTVFS_HANDLER, "posix"); err = ldb_add(ldb, msg); if (err != LDB_SUCCESS) { @@ -428,7 +430,7 @@ NTSTATUS sldb_set(struct share_context *ctx, const char *name, struct share_info struct ldb_message *msg; TALLOC_CTX *tmp_ctx; NTSTATUS ret; - bool rename = False; + bool do_rename = False; char *newname; int err, i; @@ -462,7 +464,7 @@ NTSTATUS sldb_set(struct share_context *ctx, const char *name, struct share_info for (i = 0; i < count; i++) { if (strcasecmp(info[i].name, SHARE_NAME) == 0) { if (strcasecmp(name, (char *)info[i].value) != 0) { - rename = True; + do_rename = True; newname = (char *)info[i].value; SHARE_MOD_STRING("cn", (char *)info[i].value); } @@ -485,7 +487,7 @@ NTSTATUS sldb_set(struct share_context *ctx, const char *name, struct share_info } } - if (rename) { + if (do_rename) { struct ldb_dn *olddn, *newdn; olddn = msg->dn; -- cgit From 59b66744f7318d8197f0d2029bf3b641dafa327e Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Sun, 15 Oct 2006 23:14:19 +0000 Subject: r19299: Fix possible memleaks (This used to be commit 6fad80bb09113a60689061a2de67711c9924708b) --- source4/param/share_ldb.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'source4/param/share_ldb.c') diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index fba204c834..ac56b950c8 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -172,11 +172,11 @@ static NTSTATUS sldb_list_all(TALLOC_CTX *mem_ctx, ldb = talloc_get_type(ctx->priv_data, struct ldb_context); ret = ldb_search(ldb, ldb_dn_explode(tmp_ctx, "CN=SHARES"), LDB_SCOPE_SUBTREE, "(name=*)", NULL, &res); + talloc_steal(tmp_ctx, res); if (ret != LDB_SUCCESS) { talloc_free(tmp_ctx); return NT_STATUS_BAD_NETWORK_NAME; } - talloc_steal(tmp_ctx, res); n = talloc_array(mem_ctx, const char *, res->count); if (!n) { @@ -228,11 +228,11 @@ static NTSTATUS sldb_get_config(TALLOC_CTX *mem_ctx, return NT_STATUS_NO_MEMORY; } ret = ldb_search(ldb, ldb_dn_explode(tmp_ctx, "CN=SHARES"), LDB_SCOPE_SUBTREE, filter, NULL, &res); + talloc_steal(tmp_ctx, res); if (ret != LDB_SUCCESS || res->count != 1) { talloc_free(tmp_ctx); return NT_STATUS_BAD_NETWORK_NAME; } - talloc_steal(tmp_ctx, res); s = talloc(tmp_ctx, struct share_config); if (!s) { -- cgit From 7f833458ca0083654e34cbfde1c6c6510cab1826 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 25 Oct 2006 01:42:59 +0000 Subject: r19489: Change ldb_msg_add_value and ldb_msg_add_empty to take a foruth argument. This is a pointer to an element pointer. If it is not null it will be filled with the pointer of the manipulated element. Will avoid double searches on the elements list in some cases. (This used to be commit 0fa5d4bc225b83e9f63ac6d75bffc4c08eb6b620) --- source4/param/share_ldb.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'source4/param/share_ldb.c') diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index ac56b950c8..62b529e6cf 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -280,7 +280,7 @@ static NTSTATUS sldb_get_config(TALLOC_CTX *mem_ctx, } } while(0) #define SHARE_ADD_BLOB(name, value) do { \ - err = ldb_msg_add_value(msg, name, value); \ + err = ldb_msg_add_value(msg, name, value, NULL); \ if (err != LDB_SUCCESS) { \ DEBUG(2,("ERROR: unable to add blob share option %s to ldb msg\n", name)); \ ret = NT_STATUS_UNSUCCESSFUL; \ @@ -383,7 +383,7 @@ done: } #define SHARE_MOD_STRING(name, value) do { \ - err = ldb_msg_add_empty(msg, name, LDB_FLAG_MOD_REPLACE); \ + err = ldb_msg_add_empty(msg, name, LDB_FLAG_MOD_REPLACE, NULL); \ if (err != LDB_SUCCESS) { \ DEBUG(2,("ERROR: unable to add string share option %s to ldb msg\n", name)); \ ret = NT_STATUS_UNSUCCESSFUL; \ @@ -397,7 +397,7 @@ done: } } while(0) #define SHARE_MOD_INT(name, value) do { \ - err = ldb_msg_add_empty(msg, name, LDB_FLAG_MOD_REPLACE); \ + err = ldb_msg_add_empty(msg, name, LDB_FLAG_MOD_REPLACE, NULL); \ if (err != LDB_SUCCESS) { \ DEBUG(2,("ERROR: unable to add string share option %s to ldb msg\n", name)); \ ret = NT_STATUS_UNSUCCESSFUL; \ @@ -411,13 +411,13 @@ done: } } while(0) #define SHARE_MOD_BLOB(name, value) do { \ - err = ldb_msg_add_empty(msg, name, LDB_FLAG_MOD_REPLACE); \ + err = ldb_msg_add_empty(msg, name, LDB_FLAG_MOD_REPLACE, NULL); \ if (err != LDB_SUCCESS) { \ DEBUG(2,("ERROR: unable to add string share option %s to ldb msg\n", name)); \ ret = NT_STATUS_UNSUCCESSFUL; \ goto done; \ } \ - err = ldb_msg_add_value(msg, name, value); \ + err = ldb_msg_add_value(msg, name, value, NULL); \ if (err != LDB_SUCCESS) { \ DEBUG(2,("ERROR: unable to add blob share option %s to ldb msg\n", name)); \ ret = NT_STATUS_UNSUCCESSFUL; \ -- cgit From 4889eb9f7aae9349e426d0f6d2217adff67eaebd Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Wed, 22 Nov 2006 00:59:34 +0000 Subject: r19831: Big ldb_dn optimization and interfaces enhancement patch This patch changes a lot of the code in ldb_dn.c, and also removes and add a number of manipulation functions around. The aim is to avoid validating a dn if not necessary as the validation code is necessarily slow. This is mainly to speed up internal operations where input is not user generated and so we can assume the DNs need no validation. The code is designed to keep the data as a string if possible. The code is not yet 100% perfect, but pass all the tests so far. A memleak is certainly present, I'll work on that next. Simo. (This used to be commit a580c871d3784602a9cce32d33419e63c8236e63) --- source4/param/share_ldb.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'source4/param/share_ldb.c') diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index 62b529e6cf..8db3a02f1c 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -171,7 +171,7 @@ static NTSTATUS sldb_list_all(TALLOC_CTX *mem_ctx, ldb = talloc_get_type(ctx->priv_data, struct ldb_context); - ret = ldb_search(ldb, ldb_dn_explode(tmp_ctx, "CN=SHARES"), LDB_SCOPE_SUBTREE, "(name=*)", NULL, &res); + ret = ldb_search(ldb, ldb_dn_new(tmp_ctx, ldb, "CN=SHARES"), LDB_SCOPE_SUBTREE, "(name=*)", NULL, &res); talloc_steal(tmp_ctx, res); if (ret != LDB_SUCCESS) { talloc_free(tmp_ctx); @@ -227,7 +227,7 @@ static NTSTATUS sldb_get_config(TALLOC_CTX *mem_ctx, talloc_free(tmp_ctx); return NT_STATUS_NO_MEMORY; } - ret = ldb_search(ldb, ldb_dn_explode(tmp_ctx, "CN=SHARES"), LDB_SCOPE_SUBTREE, filter, NULL, &res); + ret = ldb_search(ldb, ldb_dn_new(tmp_ctx, ldb, "CN=SHARES"), LDB_SCOPE_SUBTREE, filter, NULL, &res); talloc_steal(tmp_ctx, res); if (ret != LDB_SUCCESS || res->count != 1) { talloc_free(tmp_ctx); @@ -324,7 +324,7 @@ NTSTATUS sldb_create(struct share_context *ctx, const char *name, struct share_i } /* TODO: escape info->name */ - msg->dn = ldb_dn_string_compose(tmp_ctx, ldb_dn_new(tmp_ctx), "CN=%s,CN=SHARES", name); + msg->dn = ldb_dn_new_fmt(tmp_ctx, ldb, "CN=%s,CN=SHARES", name); if (!msg->dn) { DEBUG(0,("ERROR: Out of memory!\n")); ret = NT_STATUS_NO_MEMORY; @@ -454,7 +454,7 @@ NTSTATUS sldb_set(struct share_context *ctx, const char *name, struct share_info } /* TODO: escape name */ - msg->dn = ldb_dn_string_compose(tmp_ctx, ldb_dn_new(tmp_ctx), "CN=%s,CN=SHARES", name); + msg->dn = ldb_dn_new_fmt(tmp_ctx, ldb, "CN=%s,CN=SHARES", name); if (!msg->dn) { DEBUG(0,("ERROR: Out of memory!\n")); ret = NT_STATUS_NO_MEMORY; @@ -493,7 +493,7 @@ NTSTATUS sldb_set(struct share_context *ctx, const char *name, struct share_info olddn = msg->dn; /* TODO: escape newname */ - newdn = ldb_dn_string_compose(tmp_ctx, ldb_dn_new(tmp_ctx), "CN=%s,CN=SHARES", newname); + newdn = ldb_dn_new_fmt(tmp_ctx, ldb, "CN=%s,CN=SHARES", newname); if (!newdn) { DEBUG(0,("ERROR: Out of memory!\n")); ret = NT_STATUS_NO_MEMORY; @@ -549,7 +549,7 @@ NTSTATUS sldb_remove(struct share_context *ctx, const char *name) ldb = talloc_get_type(ctx->priv_data, struct ldb_context); - dn = ldb_dn_string_compose(tmp_ctx, ldb_dn_new(tmp_ctx), "CN=%s,CN=SHARES", name); + dn = ldb_dn_new_fmt(tmp_ctx, ldb, "CN=%s,CN=SHARES", name); if (!dn) { DEBUG(0,("ERROR: Out of memory!\n")); ret = NT_STATUS_NO_MEMORY; -- cgit From ea212eb00fd358e7335648b9cd556227e53df367 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Tue, 5 Dec 2006 04:25:27 +0000 Subject: r20034: Start using ldb_search_exp_fmt() (This used to be commit 4f07542143ddf5066f0360d965f26a8470504047) --- source4/param/share_ldb.c | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) (limited to 'source4/param/share_ldb.c') diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index 8db3a02f1c..451d003a0d 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -211,7 +211,6 @@ static NTSTATUS sldb_get_config(TALLOC_CTX *mem_ctx, struct ldb_context *ldb; struct ldb_result *res; TALLOC_CTX *tmp_ctx; - char *filter; tmp_ctx = talloc_new(mem_ctx); if (!tmp_ctx) { @@ -221,14 +220,9 @@ static NTSTATUS sldb_get_config(TALLOC_CTX *mem_ctx, ldb = talloc_get_type(ctx->priv_data, struct ldb_context); - filter = talloc_asprintf(tmp_ctx,"(name=%s)", name); - if (!filter) { - DEBUG(0,("ERROR: Out of memory!\n")); - talloc_free(tmp_ctx); - return NT_STATUS_NO_MEMORY; - } - ret = ldb_search(ldb, ldb_dn_new(tmp_ctx, ldb, "CN=SHARES"), LDB_SCOPE_SUBTREE, filter, NULL, &res); - talloc_steal(tmp_ctx, res); + ret = ldb_search_exp_fmt(ldb, tmp_ctx, &res, + ldb_dn_new(tmp_ctx, ldb, "CN=SHARES"), LDB_SCOPE_SUBTREE, NULL, + "(name=%s)", name); if (ret != LDB_SUCCESS || res->count != 1) { talloc_free(tmp_ctx); return NT_STATUS_BAD_NETWORK_NAME; -- cgit From 0fe8434b3b4fa0c7c56a6f2e04d3257cd4227e74 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Wed, 18 Apr 2007 13:28:04 +0000 Subject: r22336: Add some more share tests. (This used to be commit dfc88ad698644fe90f0275c457e7b84ddde302a4) --- source4/param/share_ldb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/param/share_ldb.c') diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index 451d003a0d..2d865588a9 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -289,7 +289,7 @@ NTSTATUS sldb_create(struct share_context *ctx, const char *name, struct share_i NTSTATUS ret; int err, i, j; - for (i = 0, j = 0; i < count || j != 0x03; i++) { + for (i = 0, j = 0; i < count && j != 0x03; i++) { if (strcasecmp(info[i].name, SHARE_TYPE) == 0) j |= 0x02; if (strcasecmp(info[i].name, SHARE_PATH) == 0) j |= 0x01; if (strcasecmp(info[i].name, SHARE_NAME) == 0) { -- cgit From 5b1a01a9c09d5ff68ae78f77b5f69d1c3aa6ab5c Mon Sep 17 00:00:00 2001 From: Stefan Metzmacher Date: Sat, 28 Apr 2007 08:37:36 +0000 Subject: r22546: use the same error codes in both share backends metze (This used to be commit e0fae01e4cf93393b57514ffc08c126abf034e11) --- source4/param/share_ldb.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'source4/param/share_ldb.c') diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index 2d865588a9..97a88e8f77 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -175,7 +175,7 @@ static NTSTATUS sldb_list_all(TALLOC_CTX *mem_ctx, talloc_steal(tmp_ctx, res); if (ret != LDB_SUCCESS) { talloc_free(tmp_ctx); - return NT_STATUS_BAD_NETWORK_NAME; + return NT_STATUS_INTERNAL_DB_CORRUPTION; } n = talloc_array(mem_ctx, const char *, res->count); @@ -223,9 +223,12 @@ static NTSTATUS sldb_get_config(TALLOC_CTX *mem_ctx, ret = ldb_search_exp_fmt(ldb, tmp_ctx, &res, ldb_dn_new(tmp_ctx, ldb, "CN=SHARES"), LDB_SCOPE_SUBTREE, NULL, "(name=%s)", name); - if (ret != LDB_SUCCESS || res->count != 1) { + if (ret != LDB_SUCCESS || res->count > 1) { talloc_free(tmp_ctx); - return NT_STATUS_BAD_NETWORK_NAME; + return NT_STATUS_INTERNAL_DB_CORRUPTION; + } else if (res->count != 1) { + talloc_free(tmp_ctx); + return NT_STATUS_OBJECT_NAME_NOT_FOUND; } s = talloc(tmp_ctx, struct share_config); @@ -363,7 +366,9 @@ NTSTATUS sldb_create(struct share_context *ctx, const char *name, struct share_i DEBUG(2,("ERROR: unable to add share %s to share.ldb\n" " err=%d [%s]\n", name, err, ldb_errstring(ldb))); if (err == LDB_ERR_NO_SUCH_OBJECT) { - ret = NT_STATUS_BAD_NETWORK_NAME; + ret = NT_STATUS_OBJECT_NAME_NOT_FOUND; + } else if (err == LDB_ERR_ENTRY_ALREADY_EXISTS) { + ret = NT_STATUS_OBJECT_NAME_COLLISION; } else { ret = NT_STATUS_UNSUCCESSFUL; } @@ -499,7 +504,7 @@ NTSTATUS sldb_set(struct share_context *ctx, const char *name, struct share_info DEBUG(2,("ERROR: unable to rename share %s (to %s)\n" " err=%d [%s]\n", name, newname, err, ldb_errstring(ldb))); if (err == LDB_ERR_NO_SUCH_OBJECT) { - ret = NT_STATUS_BAD_NETWORK_NAME; + ret = NT_STATUS_OBJECT_NAME_COLLISION; } else { ret = NT_STATUS_UNSUCCESSFUL; } @@ -514,7 +519,7 @@ NTSTATUS sldb_set(struct share_context *ctx, const char *name, struct share_info DEBUG(2,("ERROR: unable to add share %s to share.ldb\n" " err=%d [%s]\n", name, err, ldb_errstring(ldb))); if (err == LDB_ERR_NO_SUCH_OBJECT) { - ret = NT_STATUS_BAD_NETWORK_NAME; + ret = NT_STATUS_OBJECT_NAME_COLLISION; } else { ret = NT_STATUS_UNSUCCESSFUL; } -- cgit From 0479a2f1cbae51fcd8dbdc3c148c808421fb4d25 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Tue, 10 Jul 2007 02:07:03 +0000 Subject: r23792: convert Samba4 to GPLv3 There are still a few tidyups of old FSF addresses to come (in both s3 and s4). More commits soon. (This used to be commit fcf38a38ac691abd0fa51b89dc951a08e89fdafa) --- source4/param/share_ldb.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'source4/param/share_ldb.c') diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index 97a88e8f77..fe65cb7a58 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -7,7 +7,7 @@ This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or + the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, @@ -16,8 +16,7 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + along with this program. If not, see . */ #include "includes.h" -- cgit From ffeee68e4b72dd94fee57366bd8d38b8c284c3d4 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 8 Sep 2007 12:42:09 +0000 Subject: r25026: Move param/param.h out of includes.h (This used to be commit abe8349f9b4387961ff3665d8c589d61cd2edf31) --- source4/param/share_ldb.c | 1 + 1 file changed, 1 insertion(+) (limited to 'source4/param/share_ldb.c') diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index fe65cb7a58..586000f503 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -25,6 +25,7 @@ #include "auth/auth.h" #include "db_wrap.h" #include "param/share.h" +#include "param/param.h" static NTSTATUS sldb_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, struct share_context **ctx) { -- cgit From 2f3551ca7cee59d4d053cceb87abdf1da1b3a1ad Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 1 Oct 2007 18:52:55 +0000 Subject: r25446: Merge some changes I made on the way home from SFO: 2007-09-29 More higher-level passing around of lp_ctx. 2007-09-29 Fix warning. 2007-09-29 Pass loadparm contexts on a higher level. 2007-09-29 Avoid using global loadparm context. (This used to be commit 3468952e771ab31f90b6c374ade01c5550810f42) --- source4/param/share_ldb.c | 37 ++++++++++++++++++------------------- 1 file changed, 18 insertions(+), 19 deletions(-) (limited to 'source4/param/share_ldb.c') diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index 586000f503..5ddf0e3511 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -37,10 +37,10 @@ static NTSTATUS sldb_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, stru return NT_STATUS_NO_MEMORY; } - sdb = ldb_wrap_connect( *ctx, - private_path(*ctx, "share.ldb"), - system_session(*ctx), - NULL, 0, NULL); + sdb = ldb_wrap_connect(*ctx, global_loadparm, + private_path(*ctx, global_loadparm, "share.ldb"), + system_session(*ctx), + NULL, 0, NULL); if (!sdb) { talloc_free(*ctx); @@ -569,22 +569,21 @@ done: return ret; } +static const struct share_ops ops = { + .name = "ldb", + .init = sldb_init, + .string_option = sldb_string_option, + .int_option = sldb_int_option, + .bool_option = sldb_bool_option, + .string_list_option = sldb_string_list_option, + .list_all = sldb_list_all, + .get_config = sldb_get_config, + .create = sldb_create, + .set = sldb_set, + .remove = sldb_remove +}; + NTSTATUS share_ldb_init(void) { - static struct share_ops ops = { - .name = "ldb", - .init = sldb_init, - .string_option = sldb_string_option, - .int_option = sldb_int_option, - .bool_option = sldb_bool_option, - .string_list_option = sldb_string_list_option, - .list_all = sldb_list_all, - .get_config = sldb_get_config, - .create = sldb_create, - .set = sldb_set, - .remove = sldb_remove - }; - return share_register(&ops); } - -- cgit From d5a93dfcb950ecd52d8dea7a2a5d667feb6259ca Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Sat, 6 Oct 2007 21:39:52 +0000 Subject: r25547: Convert to standard bool type. (This used to be commit 97a241692c4b8dc45e086aa9b959f2cd30b8d6c9) --- source4/param/share_ldb.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) (limited to 'source4/param/share_ldb.c') diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index 5ddf0e3511..019b161639 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -99,16 +99,16 @@ static int sldb_int_option(struct share_config *scfg, const char *opt_name, int return ret; } -static BOOL sldb_bool_option(struct share_config *scfg, const char *opt_name, BOOL defval) +static bool sldb_bool_option(struct share_config *scfg, const char *opt_name, bool defval) { const char *val; val = sldb_string_option(scfg, opt_name, NULL); if (val == NULL) return defval; - if (strcasecmp(val, "true") == 0) return True; + if (strcasecmp(val, "true") == 0) return true; - return False; + return false; } static const char **sldb_string_list_option(TALLOC_CTX *mem_ctx, struct share_config *scfg, const char *opt_name) @@ -355,9 +355,9 @@ NTSTATUS sldb_create(struct share_context *ctx, const char *name, struct share_i /* TODO: Security Descriptor */ - SHARE_ADD_STRING(SHARE_AVAILABLE, "True"); - SHARE_ADD_STRING(SHARE_BROWSEABLE, "True"); - SHARE_ADD_STRING(SHARE_READONLY, "False"); + SHARE_ADD_STRING(SHARE_AVAILABLE, "true"); + SHARE_ADD_STRING(SHARE_BROWSEABLE, "true"); + SHARE_ADD_STRING(SHARE_READONLY, "false"); SHARE_ADD_STRING(SHARE_NTVFS_HANDLER, "unixuid"); SHARE_ADD_STRING(SHARE_NTVFS_HANDLER, "posix"); @@ -429,7 +429,7 @@ NTSTATUS sldb_set(struct share_context *ctx, const char *name, struct share_info struct ldb_message *msg; TALLOC_CTX *tmp_ctx; NTSTATUS ret; - bool do_rename = False; + bool do_rename = false; char *newname; int err, i; @@ -463,7 +463,7 @@ NTSTATUS sldb_set(struct share_context *ctx, const char *name, struct share_info for (i = 0; i < count; i++) { if (strcasecmp(info[i].name, SHARE_NAME) == 0) { if (strcasecmp(name, (char *)info[i].value) != 0) { - do_rename = True; + do_rename = true; newname = (char *)info[i].value; SHARE_MOD_STRING("cn", (char *)info[i].value); } -- cgit From ca0b72a1fdb7bd965065e833df34662afef0423e Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Fri, 16 Nov 2007 20:12:00 +0100 Subject: r26003: Split up DB_WRAP, as first step in an attempt to sanitize dependencies. (This used to be commit 56dfcb4f2f8e74c9d8b2fe3a0df043781188a555) --- source4/param/share_ldb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/param/share_ldb.c') diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index 019b161639..ece9c0544b 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -23,7 +23,7 @@ #include "ldb/include/ldb.h" #include "ldb/include/ldb_errors.h" #include "auth/auth.h" -#include "db_wrap.h" +#include "ldb_wrap.h" #include "param/share.h" #include "param/param.h" -- cgit From 43696d2752e2faad34fb3ed2a7dbf01d40ffdc46 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Mon, 3 Dec 2007 15:53:28 +0100 Subject: r26252: Specify loadparm_context explicitly when creating sessions. (This used to be commit 7280c1e9415daabb2712db1372e23f9846272ede) --- source4/param/share_ldb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/param/share_ldb.c') diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index ece9c0544b..487359eff6 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -39,7 +39,7 @@ static NTSTATUS sldb_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, stru sdb = ldb_wrap_connect(*ctx, global_loadparm, private_path(*ctx, global_loadparm, "share.ldb"), - system_session(*ctx), + system_session(*ctx, global_loadparm), NULL, 0, NULL); if (!sdb) { -- cgit From e31abef15f7696cf39e9e81307f153da93568e02 Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 13 Dec 2007 22:46:55 +0100 Subject: r26440: Remove more uses of global_loadparm. (This used to be commit 8858cf39722f192865e531164c72039fd18d7a8d) --- source4/param/share_ldb.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'source4/param/share_ldb.c') diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index 487359eff6..bdea94a5cd 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -27,7 +27,8 @@ #include "param/share.h" #include "param/param.h" -static NTSTATUS sldb_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, struct share_context **ctx) +static NTSTATUS sldb_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, struct loadparm_context *lp_ctx, + struct share_context **ctx) { struct ldb_context *sdb; @@ -37,9 +38,9 @@ static NTSTATUS sldb_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, stru return NT_STATUS_NO_MEMORY; } - sdb = ldb_wrap_connect(*ctx, global_loadparm, - private_path(*ctx, global_loadparm, "share.ldb"), - system_session(*ctx, global_loadparm), + sdb = ldb_wrap_connect(*ctx, lp_ctx, + private_path(*ctx, lp_ctx, "share.ldb"), + system_session(*ctx, lp_ctx), NULL, 0, NULL); if (!sdb) { -- cgit From 80d1d2a4db91eba72a4a8da0ed89691f8c25d97f Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 21 Feb 2008 16:18:01 +0100 Subject: Clarify comments. (This used to be commit 5193b383761129e59241cd2cc6000f0b038b49d4) --- source4/param/share_ldb.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'source4/param/share_ldb.c') diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index bdea94a5cd..fb40f1e9bf 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -1,7 +1,7 @@ /* Unix SMB/CIFS implementation. - LDB based services configuration + LDB based shares configuration Copyright (C) Simo Sorce 2006 -- cgit From 21fc7673780aa1d7c0caab7b17ff9171238913ba Mon Sep 17 00:00:00 2001 From: Jelmer Vernooij Date: Thu, 17 Apr 2008 12:23:44 +0200 Subject: Specify event_context to ldb_wrap_connect explicitly. (This used to be commit b4e1ae07a284c044704322446c94351c2decff91) --- source4/param/share_ldb.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'source4/param/share_ldb.c') diff --git a/source4/param/share_ldb.c b/source4/param/share_ldb.c index fb40f1e9bf..eba1665cc9 100644 --- a/source4/param/share_ldb.c +++ b/source4/param/share_ldb.c @@ -27,7 +27,9 @@ #include "param/share.h" #include "param/param.h" -static NTSTATUS sldb_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, struct loadparm_context *lp_ctx, +static NTSTATUS sldb_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, + struct event_context *ev_ctx, + struct loadparm_context *lp_ctx, struct share_context **ctx) { struct ldb_context *sdb; @@ -38,7 +40,7 @@ static NTSTATUS sldb_init(TALLOC_CTX *mem_ctx, const struct share_ops *ops, stru return NT_STATUS_NO_MEMORY; } - sdb = ldb_wrap_connect(*ctx, lp_ctx, + sdb = ldb_wrap_connect(*ctx, ev_ctx, lp_ctx, private_path(*ctx, lp_ctx, "share.ldb"), system_session(*ctx, lp_ctx), NULL, 0, NULL); -- cgit