diff options
author | Atul Kulkarni <atul.kulkarni@in.ibm.com> | 2013-09-10 01:19:52 +0200 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2013-10-02 00:06:31 +0200 |
commit | d560cd11e4de818ff997eea52d020e360c3ef7d0 (patch) | |
tree | 6b1e46e37e04d1412bfd6e59aed40fdb500076e2 /source3/utils | |
parent | f531c369eb65ab9c0150bb1693a1b89006254a12 (diff) | |
download | samba-d560cd11e4de818ff997eea52d020e360c3ef7d0.tar.gz |
net: add new function net_idmap_opendb_autorid()
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>
Reviewed-by: Volker Lendecke <vl@samba.org>
Diffstat (limited to 'source3/utils')
-rw-r--r-- | source3/utils/net_idmap.c | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index b12039bde99..c22c5d551d0 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -27,6 +27,7 @@ #include "../libcli/security/security.h" #include "net_idmap_check.h" #include "util_tdb.h" +#include "idmap_autorid_tdb.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 **********************************************************/ |