net: add new function net_idmap_opendb_autorid()
authorAtul Kulkarni <atul.kulkarni@in.ibm.com>
Mon, 9 Sep 2013 23:19:52 +0000 (01:19 +0200)
committerMichael Adam <obnox@samba.org>
Tue, 1 Oct 2013 08:49:22 +0000 (10:49 +0200)
This checks the backend is autorid, and opens the db if so.
If readonly == true, the DB is simply opened for reading.
If readonly == false, the DB is created if necessary and
initialized with HWMs.

Pair-Programmed-With: Michael Adam <obnox@samba.org>

Signed-off-by: Atul Kulkarni <atul.kulkarni@in.ibm.com>
Signed-off-by: Michael Adam <obnox@samba.org>
source3/utils/net_idmap.c
source3/wscript_build

index b12039bde990c1371ff295298bf8109161833205..3fbc4823d0d3e2e1c190b327d452c4bbf0e0a943 100644 (file)
@@ -27,6 +27,7 @@
 #include "../libcli/security/security.h"
 #include "net_idmap_check.h"
 #include "util_tdb.h"
+#include "idmap_autorid.h"
 
 #define ALLOC_CHECK(mem) do { \
        if (!mem) { \
@@ -180,6 +181,56 @@ static const char* net_idmap_dbfile(struct net_context *c,
        return dbfile;
 }
 
+static bool net_idmap_opendb_autorid(TALLOC_CTX *mem_ctx,
+                                    struct net_context *c,
+                                    bool readonly,
+                                    struct db_context **db)
+{
+       bool ret = false;
+       const char *dbfile;
+       struct net_idmap_ctx ctx = { .backend = AUTORID };
+
+       if (c == NULL) {
+               goto done;
+       }
+
+       dbfile = net_idmap_dbfile(c, &ctx);
+       if (dbfile == NULL) {
+               goto done;
+       }
+
+       if (ctx.backend != AUTORID) {
+               d_fprintf(stderr, _("Unsupported backend\n"));
+               goto done;
+       }
+
+       if (readonly) {
+               *db = db_open(mem_ctx, dbfile, 0, TDB_DEFAULT, O_RDONLY, 0,
+                            DBWRAP_LOCK_ORDER_1);
+               if (*db == NULL) {
+                       d_fprintf(stderr,
+                                 _("Could not open autorid db (%s): %s\n"),
+                                dbfile, strerror(errno));
+                       goto done;
+               }
+       } else {
+               NTSTATUS status;
+               status = idmap_autorid_db_init(dbfile, mem_ctx, db);
+               if (!NT_STATUS_IS_OK(status)) {
+                       d_fprintf(stderr,
+                               _("Error calling idmap_autorid_db_init: %s\n"),
+                               nt_errstr(status));
+                       goto done;
+               }
+       }
+
+       ret = true;
+
+done:
+       return ret;
+}
+
+
 /***********************************************************
  Dump the current idmap
  **********************************************************/
index 2122d15bb8d6a26713b6cb8ba0fa5e30daf870f3..40d03b24293e92923bc99688d353c0f0c1d7ddc4 100755 (executable)
@@ -1112,7 +1112,8 @@ bld.SAMBA3_BINARY('net',
                  RPC_NDR_DSSETUP
                  RPC_NDR_INITSHUTDOWN
                  printing_migrate
-                 trusts_util''')
+                 trusts_util
+                 IDMAP_AUTORID_TDB''')
 
 bld.SAMBA3_BINARY('profiles',
                  source='utils/profiles.c',