#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) {
ret = true;
done:
+ talloc_free(dbfile);
return ret;
}
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);
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;
}
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;
}
/***********************************************************