r25446: Merge some changes I made on the way home from SFO:
[jelmer/samba4-debian.git] / source / param / share_ldb.c
index 451d003a0de9f0ed22686de91af36915a772b842..5ddf0e3511f885c6588c418c2c071d9eb93b9664 100644 (file)
@@ -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 <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
@@ -26,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)
 {
@@ -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);
@@ -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);
@@ -289,7 +292,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) {
@@ -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;
                }
@@ -564,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);
 }
-