mirror of
https://github.com/samba-team/samba.git
synced 2025-08-03 04:22:09 +03:00
s3-net: add command "net idmap check"
This is a tool to check the consistency of an idmap tdb database. The default mode is to scan the database and list invalid entries, e.g. records with an invalid format, or records which are valid but for which the reverse mapping entry is missing. With the "--repair" switch, one can enter an interactive repair mode which will prompt for each invalid entry found with the option to delete, skip or edit the record. There is also a non-interactive repair mode triggered by "--auto" which will remove all records with invalid content and fill up mappings which are missing the reverse entry. The "--test" parameter lets "net idmap check" only list the changes that would be written and not actually commit them to the database. The "--lock" option allows to lock the database already in the first reading traverse, in order to remove the race when the database has to be closed and reopened again before writing the changes. Signed-off-by: Michael Adam <obnox@samba.org> Autobuild-User: Michael Adam <obnox@samba.org> Autobuild-Date: Mon Apr 4 18:21:09 CEST 2011 on sn-devel-104
This commit is contained in:
committed by
Michael Adam
parent
8fc8c88007
commit
a217ec64ec
@ -1147,7 +1147,7 @@ LIBNET_SAMSYNC_OBJ = libnet/libnet_samsync.o \
|
||||
NET_OBJ1 = utils/net.o utils/net_ads.o utils/net_help.o \
|
||||
utils/net_rap.o utils/net_rpc.o utils/net_rpc_samsync.o \
|
||||
utils/net_rpc_join.o utils/net_time.o utils/net_lookup.o \
|
||||
utils/net_cache.o utils/net_groupmap.o utils/net_idmap.o \
|
||||
utils/net_cache.o utils/net_groupmap.o utils/net_idmap.o utils/net_idmap_check.o\
|
||||
utils/net_status.o utils/net_rpc_printer.o utils/net_rpc_rights.o \
|
||||
utils/net_rpc_service.o utils/net_rpc_registry.o utils/net_usershare.o \
|
||||
utils/netlookup.o utils/net_sam.o utils/net_rpc_shell.o \
|
||||
|
@ -817,6 +817,9 @@ static struct functable net_func[] = {
|
||||
{"clean-old-entries", 0, POPT_ARG_NONE, &c->opt_clean_old_entries},
|
||||
/* Options for 'net idmap'*/
|
||||
{"db", 0, POPT_ARG_STRING, &c->opt_db},
|
||||
{"lock", 0, POPT_ARG_NONE, &c->opt_lock},
|
||||
{"auto", 'a', POPT_ARG_NONE, &c->opt_auto},
|
||||
{"repair", 0, POPT_ARG_NONE, &c->opt_repair},
|
||||
POPT_COMMON_SAMBA
|
||||
{ 0, 0, 0, 0}
|
||||
};
|
||||
|
@ -76,6 +76,9 @@ struct net_context {
|
||||
int opt_single_obj_repl;
|
||||
int opt_clean_old_entries;
|
||||
const char *opt_db;
|
||||
int opt_lock;
|
||||
int opt_auto;
|
||||
int opt_repair;
|
||||
|
||||
int opt_have_ip;
|
||||
struct sockaddr_storage opt_dest_ip;
|
||||
|
@ -17,7 +17,6 @@
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#define FOO(x) (x)
|
||||
#include "includes.h"
|
||||
#include "system/filesys.h"
|
||||
#include "utils/net.h"
|
||||
@ -25,6 +24,7 @@
|
||||
#include "idmap.h"
|
||||
#include "dbwrap.h"
|
||||
#include "../libcli/security/security.h"
|
||||
#include "net_idmap_check.h"
|
||||
|
||||
#define ALLOC_CHECK(mem) do { \
|
||||
if (!mem) { \
|
||||
@ -535,6 +535,43 @@ static int net_idmap_secret(struct net_context *c, int argc, const char **argv)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int net_idmap_check(struct net_context *c, int argc, const char **argv)
|
||||
{
|
||||
const char* dbfile;
|
||||
struct check_options opts;
|
||||
|
||||
if ( argc > 1 || c->display_usage) {
|
||||
d_printf("%s\n%s",
|
||||
_("Usage:"),
|
||||
_("net idmap check [-f] [-a] [-T] [-v] [--auto] [[--db=]<TDB>]\n"
|
||||
" Check an idmap database.\n"
|
||||
" --repair,-r\trepair\n"
|
||||
" --fore,-f\tforce\n"
|
||||
" --auto,-a\tnoninteractive mode\n"
|
||||
" --test,-T\tdry run\n"
|
||||
" --lock\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);
|
||||
if (dbfile == NULL) {
|
||||
return -1;
|
||||
}
|
||||
d_fprintf(stderr, _("check database: %s\n"), dbfile);
|
||||
|
||||
opts = (struct check_options) {
|
||||
.lock = c->opt_lock,
|
||||
.test = c->opt_testmode,
|
||||
.automatic = c->opt_auto,
|
||||
.verbose = c->opt_verbose,
|
||||
.force = c->opt_force,
|
||||
.repair = c->opt_repair || c->opt_reboot,
|
||||
};
|
||||
|
||||
return net_idmap_check_db(dbfile, &opts);
|
||||
}
|
||||
|
||||
static int net_idmap_aclmapset(struct net_context *c, int argc, const char **argv)
|
||||
{
|
||||
TALLOC_CTX *mem_ctx;
|
||||
@ -653,6 +690,14 @@ int net_idmap(struct net_context *c, int argc, const char **argv)
|
||||
N_("net idmap aclmapset\n"
|
||||
" Set acl map")
|
||||
},
|
||||
{
|
||||
"check",
|
||||
net_idmap_check,
|
||||
NET_TRANSPORT_LOCAL,
|
||||
N_("Check id mappings"),
|
||||
N_("net idmap check\n"
|
||||
" Check id mappings")
|
||||
},
|
||||
{NULL, NULL, 0, NULL, NULL}
|
||||
};
|
||||
|
||||
|
1006
source3/utils/net_idmap_check.c
Normal file
1006
source3/utils/net_idmap_check.c
Normal file
File diff suppressed because it is too large
Load Diff
48
source3/utils/net_idmap_check.h
Normal file
48
source3/utils/net_idmap_check.h
Normal file
@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Samba Unix/Linux SMB client library
|
||||
*
|
||||
* Copyright (C) Gregor Beck 2011
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Check the idmap database.
|
||||
* @author Gregor Beck <gb@sernet.de>
|
||||
* @date Mar 2011
|
||||
*/
|
||||
|
||||
#ifndef NET_IDMAP_CHECK_H
|
||||
#define NET_IDMAP_CHECK_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
struct net_context;
|
||||
|
||||
struct check_options {
|
||||
bool test;
|
||||
bool verbose;
|
||||
bool lock;
|
||||
bool automatic;
|
||||
bool force;
|
||||
bool repair;
|
||||
};
|
||||
|
||||
int net_idmap_check_db(const char* db, const struct check_options* opts);
|
||||
|
||||
#endif /* NET_IDMAP_CHECK_H */
|
||||
|
||||
/*Local Variables:*/
|
||||
/*mode: c*/
|
||||
/*End:*/
|
@ -530,7 +530,8 @@ LIBNET_SAMSYNC_SRC = '''libnet/libnet_samsync.c
|
||||
NET_SRC1 = '''utils/net.c utils/net_ads.c utils/net_help.c
|
||||
utils/net_rap.c utils/net_rpc.c utils/net_rpc_samsync.c
|
||||
utils/net_rpc_join.c utils/net_time.c utils/net_lookup.c
|
||||
utils/net_cache.c utils/net_groupmap.c utils/net_idmap.c
|
||||
utils/net_cache.c utils/net_groupmap.c
|
||||
utils/net_idmap.c utils/net_idmap_check.c
|
||||
utils/net_status.c utils/net_rpc_printer.c utils/net_rpc_rights.c
|
||||
utils/net_rpc_service.c utils/net_rpc_registry.c utils/net_usershare.c
|
||||
utils/netlookup.c utils/net_sam.c utils/net_rpc_shell.c
|
||||
|
Reference in New Issue
Block a user