net: implement "net idmap delete ranges" master-idmap-autorid
authorMichael Adam <obnox@samba.org>
Wed, 18 Sep 2013 01:19:58 +0000 (03:19 +0200)
committerMichael Adam <obnox@samba.org>
Tue, 1 Oct 2013 08:49:26 +0000 (10:49 +0200)
Inspired by a patch by Atul Kulkarni <atul.kulkarni@in.ibm.com>.

Signed-off-by: Michael Adam <obnox@samba.org>
source3/utils/net_idmap.c

index 3a89197f548e9ba0c13cf33633dea9a1f1d00956..450f6321b5fbb00670a7fee1018af52b18ef6988 100644 (file)
@@ -713,6 +713,63 @@ done:
        return ret;
 }
 
+static void net_idmap_autorid_delete_ranges_usage(void)
+{
+       d_printf("%s\n%s",
+                _("Usage:"),
+                _("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"
+                  "    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;
+       fstring 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;
+       }
+
+       fstrcpy(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[] = {
@@ -732,6 +789,14 @@ static int net_idmap_delete(struct net_context *c, int argc, const char **argv)
                        N_("net idmap delete range <RANGE>|(<SID>[ <INDEX>])\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 <SID>\n"
+                          "  Delete a domain range mapping")
+               },
                {NULL, NULL, 0, NULL, NULL}
        };