diff options
author | Gregor Beck <gbeck@sernet.de> | 2011-02-08 12:06:07 +0100 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2011-02-09 14:00:34 +0100 |
commit | e2795f566407bb97ea42a13cee1deb830e93dbb0 (patch) | |
tree | a803f7d4f91dd1bfa73c4d00808e939ce15673be /source3/utils | |
parent | 1f1a165ea9104891eb51f84ab07dc4977938024b (diff) | |
download | samba-e2795f566407bb97ea42a13cee1deb830e93dbb0.tar.gz samba-e2795f566407bb97ea42a13cee1deb830e93dbb0.tar.bz2 samba-e2795f566407bb97ea42a13cee1deb830e93dbb0.zip |
s3:net factor out net_idmap_dbfile
Diffstat (limited to 'source3/utils')
-rw-r--r-- | source3/utils/net_idmap.c | 70 |
1 files changed, 37 insertions, 33 deletions
diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index 3f9fa80059..525ca951a9 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -55,6 +55,38 @@ static int net_idmap_dump_one_entry(struct db_record *rec, return 0; } +static const char* net_idmap_dbfile(struct net_context *c) +{ + const char* dbfile = NULL; + + if (c->opt_db != NULL) { + dbfile = talloc_strdup(talloc_tos(), c->opt_db); + } else if (strequal(lp_idmap_backend(), "tdb")) { + dbfile = state_path("winbindd_idmap.tdb"); + } else if (strequal(lp_idmap_backend(), "tdb2")) { + dbfile = lp_parm_talloc_string(-1, "tdb", "idmap2.tdb", NULL); + if (dbfile == NULL) { + dbfile = talloc_asprintf(talloc_tos(), "%s/idmap2.tdb", + lp_private_dir()); + } + } else { + char* backend = talloc_strdup(talloc_tos(), lp_idmap_backend()); + char* args = strchr(backend, ':'); + if (args != NULL) { + *args = '\0'; + } + + d_printf(_("Sorry, 'idmap backend = %s' is currently not supported\n"), + backend); + + talloc_free(backend); + } + if (dbfile == NULL) { + DEBUG(0,("Out of memory\n")); + } + return dbfile; +} + /*********************************************************** Dump the current idmap **********************************************************/ @@ -140,14 +172,15 @@ static int net_idmap_restore(struct net_context *c, int argc, const char **argv) TALLOC_CTX *mem_ctx; FILE *input = NULL; struct db_context *db; - char *dbfile = NULL; + const char *dbfile = NULL; int ret = 0; if (c->display_usage) { d_printf("%s\n%s", _("Usage:"), - _("net idmap restore [<inputfile>]\n" + _("net idmap restore [--db=<TDB>] [<inputfile>]\n" " Restore ID mappings from file\n" + " TDB\tFile to store ID mappings to." " inputfile\tFile to load ID mappings from. If not " "given, load data from stdin.\n")); return 0; @@ -155,38 +188,9 @@ static int net_idmap_restore(struct net_context *c, int argc, const char **argv) mem_ctx = talloc_stackframe(); - if (strequal(lp_idmap_backend(), "tdb")) { - dbfile = state_path("winbindd_idmap.tdb"); - if (dbfile == NULL) { - d_fprintf(stderr, _("Out of memory!\n")); - return -1; - } - } else if (strequal(lp_idmap_backend(), "tdb2")) { - dbfile = lp_parm_talloc_string(-1, "tdb", "idmap2.tdb", NULL); - if (dbfile == NULL) { - dbfile = talloc_asprintf(mem_ctx, "%s/idmap2.tdb", - lp_private_dir()); - } - } else { - char *backend, *args; - - backend = talloc_strdup(mem_ctx, lp_idmap_backend()); - args = strchr(backend, ':'); - if (args != NULL) { - *args = '\0'; - } - - d_printf(_("Sorry, 'net idmap restore' is currently not " - "supported for idmap backend = %s.\n" - "Only tdb and tdb2 are supported.\n"), - backend); - - ret = -1; - goto done; - } + dbfile = net_idmap_dbfile(c); - d_fprintf(stderr, _("restoring id mapping to %s data base in '%s'\n"), - lp_idmap_backend(), dbfile); + d_fprintf(stderr, _("restoring id mapping to %s\n"), dbfile); if (argc == 1) { input = fopen(argv[0], "r"); |