#include "net_idmap_check.h"
#include "util_tdb.h"
#include "idmap_autorid_tdb.h"
+#include "lib/util/smb_strtox.h"
#define ALLOC_CHECK(mem) do { \
if (!mem) { \
return 0;
}
-static const char* net_idmap_dbfile(struct net_context *c,
- struct net_idmap_ctx *ctx)
+/* returns db path for idmap backend alloced on talloc_tos */
+static char *net_idmap_dbfile(struct net_context *c,
+ struct net_idmap_ctx *ctx)
{
- const char* dbfile = NULL;
+ char *dbfile = NULL;
const char *backend = NULL;
backend = lp_idmap_default_backend();
d_fprintf(stderr, _("Out of memory!\n"));
}
} else if (strequal(backend, "tdb")) {
- dbfile = state_path("winbindd_idmap.tdb");
+ dbfile = state_path(talloc_tos(), "winbindd_idmap.tdb");
if (dbfile == NULL) {
d_fprintf(stderr, _("Out of memory!\n"));
}
}
ctx->backend = TDB;
} else if (strequal(backend, "autorid")) {
- dbfile = state_path("autorid.tdb");
+ dbfile = state_path(talloc_tos(), "autorid.tdb");
if (dbfile == NULL) {
d_fprintf(stderr, _("Out of memory!\n"));
}
struct db_context **db)
{
bool ret = false;
- const char *dbfile;
+ char *dbfile = NULL;
struct net_idmap_ctx ctx = { .backend = AUTORID };
if (c == NULL) {
if (readonly) {
*db = db_open(mem_ctx, dbfile, 0, TDB_DEFAULT, O_RDONLY, 0,
- DBWRAP_LOCK_ORDER_1);
+ DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
if (*db == NULL) {
d_fprintf(stderr,
_("Could not open autorid db (%s): %s\n"),
ret = true;
done:
+ talloc_free(dbfile);
return ret;
}
d_fprintf(stderr, _("dumping id mapping from %s\n"), dbfile);
db = db_open(mem_ctx, dbfile, 0, TDB_DEFAULT, O_RDONLY, 0,
- DBWRAP_LOCK_ORDER_1);
+ DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
if (db == NULL) {
d_fprintf(stderr, _("Could not open idmap db (%s): %s\n"),
dbfile, strerror(errno));
}
db = db_open(mem_ctx, dbfile, 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0644,
- DBWRAP_LOCK_ORDER_1);
+ DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
if (db == NULL) {
d_fprintf(stderr, _("Could not open idmap db (%s): %s\n"),
dbfile, strerror(errno));
if ( (len > 0) && (line[len-1] == '\n') )
line[len-1] = '\0';
- if (sscanf(line, "GID %lu %128s", &idval, sid_string) == 2)
+ if (sscanf(line, "GID %lu %127s", &idval, sid_string) == 2)
{
ret = net_idmap_store_id_mapping(db, ID_TYPE_GID,
idval, sid_string);
if (ret != 0) {
break;
}
- } else if (sscanf(line, "UID %lu %128s", &idval, sid_string) == 2)
+ } else if (sscanf(line, "UID %lu %127s", &idval, sid_string) == 2)
{
ret = net_idmap_store_id_mapping(db, ID_TYPE_UID,
idval, sid_string);
d_fprintf(stderr, _("deleting id mapping from %s\n"), dbfile);
db = db_open(mem_ctx, dbfile, 0, TDB_DEFAULT, O_RDWR, 0,
- DBWRAP_LOCK_ORDER_1);
+ DBWRAP_LOCK_ORDER_1, DBWRAP_FLAG_NONE);
if (db == NULL) {
d_fprintf(stderr, _("Could not open idmap db (%s): %s\n"),
dbfile, strerror(errno));
static bool parse_uint32(const char *str, uint32_t *result)
{
unsigned long val;
- char *endptr;
+ int error = 0;
- val = strtoul(str, &endptr, 10);
-
- if (str == endptr) {
- return false;
- }
- if (*endptr != '\0') {
- return false;
- }
- if ((val == ULONG_MAX) && (errno == ERANGE)) {
- return false;
- }
- if ((val & UINT32_MAX) != val) {
- /* overflow */
+ val = smb_strtoul(str, NULL, 10, &error, SMB_STR_FULL_STR_CONV);
+ if (error != 0) {
return false;
}
+
*result = val; /* Potential crop */
return true;
}
}
domsid = argv[0];
+ range_index = 0;
if (argc == 2) {
ok = parse_uint32(argv[1], &range_index);
{
d_printf("%s\n%s",
_("Usage:"),
- _("net idmap delete ranges [-f] [--db=<TDB>] <SID>)\n"
+ _("net idmap delete ranges [-f] [--db=<TDB>] <SID>\n"
" Delete all domain range mappings for a given domain.\n"
" -f\tforce\n"
" TDB\tidmap database\n"
"ranges",
net_idmap_autorid_delete_ranges,
NET_TRANSPORT_LOCAL,
- N_("Delete all domain range mapping for a given "
+ N_("Delete all domain range mappings for a given "
"domain"),
N_("net idmap delete ranges <SID>\n"
" Delete a domain range mapping")
static int net_idmap_check(struct net_context *c, int argc, const char **argv)
{
- const char* dbfile;
+ char *dbfile;
struct check_options opts;
struct net_idmap_ctx ctx = { .backend = TDB };
+ int ret;
if ( argc > 1 || c->display_usage) {
d_printf("%s\n%s",
" --repair,-r\trepair\n"
" --auto,-a\tnoninteractive mode\n"
" --test,-T\tdry run\n"
- " --fore,-f\tforce\n"
+ " --force,-f\tforce\n"
" --lock,-l\tlock db while doing the check\n"
" TDB\tidmap database\n"));
return c->display_usage ? 0 : -1;
}
- dbfile = (argc > 0) ? argv[0] : net_idmap_dbfile(c, &ctx);
+ if (argc > 0) {
+ dbfile = talloc_strdup(talloc_tos(), argv[0]);
+ } else {
+ dbfile = net_idmap_dbfile(c, &ctx);
+ }
if (dbfile == NULL) {
return -1;
}
if (ctx.backend != TDB) {
d_fprintf(stderr, _("Sorry, checking of non-TDB databases is "
"currently not supported\n"));
+ talloc_free(dbfile);
return -1;
}
.repair = c->opt_repair || c->opt_reboot,
};
- return net_idmap_check_db(dbfile, &opts);
+ ret = net_idmap_check_db(dbfile, &opts);
+ talloc_free(dbfile);
+ return ret;
}
/***********************************************************
N_("net idmap delete\n"
" Delete entries from the ID mapping database")
},
- {
- "secret",
- net_idmap_secret,
- NET_TRANSPORT_LOCAL,
- N_("Set secret for specified domain"),
- N_("net idmap secret <DOMAIN> <secret>\n"
- " Set secret for specified domain")
- },
{
"check",
net_idmap_check,