From 7c2b83d15eb5e64a4ad7b8dcd1bbd73bfe78de24 Mon Sep 17 00:00:00 2001 From: Michael Adam Date: Wed, 18 Sep 2013 03:19:58 +0200 Subject: net: implement "net idmap delete ranges" Inspired by a patch by Atul Kulkarni . Signed-off-by: Michael Adam Reviewed-by: Volker Lendecke --- source3/utils/net_idmap.c | 67 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) (limited to 'source3/utils') diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index 0a583111f5..6638312277 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -733,6 +733,64 @@ done: return ret; } +static void net_idmap_autorid_delete_ranges_usage(void) +{ + d_printf("%s\n%s", + _("Usage:"), + _("net idmap delete ranges [-f] [--db=] )\n" + " Delete all domain range mappings for a given domain.\n" + " -f\tforce\n" + " TDB\tidmap database\n" + " SID\t\tSID of the domain\n")); +} + +static int net_idmap_autorid_delete_ranges(struct net_context *c, int argc, + const char **argv) +{ + int ret = -1; + struct db_context *db = NULL; + NTSTATUS status; + const char *domsid; + TALLOC_CTX *mem_ctx = NULL; + bool force = (c->opt_force != 0); + int count = 0; + + if (c->display_usage) { + net_idmap_autorid_delete_ranges_usage(); + return 0; + } + + if (argc != 1) { + net_idmap_autorid_delete_ranges_usage(); + return -1; + } + + domsid = argv[0]; + + mem_ctx = talloc_stackframe(); + if (!net_idmap_opendb_autorid(mem_ctx, c, false, &db)) { + goto done; + } + + status = idmap_autorid_delete_domain_ranges(db, domsid, force, &count); + if (!NT_STATUS_IS_OK(status)) { + d_fprintf(stderr, "%s %s: %s\n", + _("Failed to delete domain range mappings for " + "domain"), + domsid, + nt_errstr(status)); + goto done; + } + + d_printf(_("deleted %d domain mappings\n"), count); + + ret = 0; + +done: + talloc_free(mem_ctx); + return ret; +} + static int net_idmap_delete(struct net_context *c, int argc, const char **argv) { struct functable func[] = { @@ -752,6 +810,15 @@ static int net_idmap_delete(struct net_context *c, int argc, const char **argv) N_("net idmap delete range |([ ])\n" " Delete a domain range mapping") }, + { + "ranges", + net_idmap_autorid_delete_ranges, + NET_TRANSPORT_LOCAL, + N_("Delete all domain range mapping for a given " + "domain"), + N_("net idmap delete ranges \n" + " Delete a domain range mapping") + }, {NULL, NULL, 0, NULL, NULL} }; -- cgit