net: add "net idmap set range" (for autorid backend)
authorMichael Adam <obnox@samba.org>
Mon, 9 Sep 2013 14:09:52 +0000 (16:09 +0200)
committerMichael Adam <obnox@samba.org>
Tue, 1 Oct 2013 08:49:23 +0000 (10:49 +0200)
This lets the admin store a range for a domain/index pair.
Call syntax is:

net idmap set range <RANGE> <DOMSID> [<INDEX>]

INDEX defaults to 0.

Pair-Programmed-With: Atul Kulkarni <atul.kulkarni@in.ibm.com>

Signed-off-by: Michael Adam <obnox@samba.org>
Signed-off-by: Atul Kulkarni <atul.kulkarni@in.ibm.com>
source3/utils/net_idmap.c

index 016ce85dd4896d7fb4625b85fc695fa93124c80b..5b9e3db23d7289f8ce1b941b521bea443aa2196d 100644 (file)
@@ -647,6 +647,76 @@ static int net_idmap_set_mapping(struct net_context *c,
        return -1;
 }
 
+static void net_idmap_autorid_set_range_usage(void)
+{
+       d_printf("%s\n%s",
+                _("Usage:"),
+                _("net idmap set range"
+                  " <range> <SID> [<index>] [--db=<inputfile>]\n"
+                  "  Store a domain-range mapping for a given domain.\n"
+                  "    range\tRange number to be set for the domain\n"
+                  "    SID\t\tSID of the domain\n"
+                  "    index\trange-index number to be set for the domain\n"
+                  "    inputfile\tTDB file to add mapping to.\n"));
+}
+
+static int net_idmap_autorid_set_range(struct net_context *c,
+                                      int argc, const char **argv)
+{
+       int ret = -1;
+       TALLOC_CTX *mem_ctx;
+       struct db_context *db = NULL;
+       fstring domsid;
+       uint32_t rangenum;
+       uint32_t range_index = 0;
+       NTSTATUS status;
+
+       if (c->display_usage) {
+               net_idmap_autorid_set_range_usage();
+               return 0;
+       }
+
+       if (argc < 2  || argc > 3) {
+               net_idmap_autorid_set_range_usage();
+               return -1;
+       }
+
+       if (sscanf(argv[0], "%"SCNu32, &rangenum) != 1) {
+               d_printf("%s: %s\n", _("Invalid range specification"), argv[0]);
+               net_idmap_autorid_set_range_usage();
+               return -1;
+       }
+
+       fstrcpy(domsid, argv[1]);
+
+       if (argc == 3) {
+               if (sscanf(argv[2], "%"SCNu32, &range_index) != 1) {
+                       d_printf("%s: %s\n",
+                                _("Invalid index specification"), argv[2]);
+                       net_idmap_autorid_set_range_usage();
+                       return -1;
+               }
+       }
+
+       mem_ctx = talloc_stackframe();
+       if (!net_idmap_opendb_autorid(mem_ctx, c, false, &db)) {
+               goto done;
+       }
+
+       status = idmap_autorid_setrange(db, domsid, range_index, rangenum);
+       if (!NT_STATUS_IS_OK(status)) {
+               d_fprintf(stderr, "%s: %s\n",
+                         _("Failed to save domain mapping"), nt_errstr(status));
+               goto done;
+       }
+
+       ret = 0;
+
+done:
+       talloc_free(mem_ctx);
+       return ret;
+}
+
 static bool idmap_store_secret(const char *backend,
                               const char *domain,
                               const char *identity,
@@ -785,6 +855,14 @@ static int net_idmap_set(struct net_context *c, int argc, const char **argv)
                        N_("net idmap set mapping\n"
                           "  Not implemented yet")
                },
+               {
+                       "range",
+                       net_idmap_autorid_set_range,
+                       NET_TRANSPORT_LOCAL,
+                       N_("Store a domain-range mapping"),
+                       N_("net idmap set range\n"
+                          "  Store a domain-range mapping")
+               },
                {
                        "config",
                        net_idmap_autorid_set_config,