diff options
author | Michael Adam <obnox@samba.org> | 2013-09-12 13:45:22 +0200 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2013-10-02 00:50:12 +0200 |
commit | 54a33ebf273d8f5c9d66b20257f7baf5cc920386 (patch) | |
tree | b1a363751629ed031e830c0c1837e5dbb486a89b | |
parent | 1dd9218de9b7b78fd23d3d19315c49dd4a9c3142 (diff) | |
download | samba-54a33ebf273d8f5c9d66b20257f7baf5cc920386.tar.gz samba-54a33ebf273d8f5c9d66b20257f7baf5cc920386.tar.bz2 samba-54a33ebf273d8f5c9d66b20257f7baf5cc920386.zip |
net: implement "net idmap delete range"
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
-rw-r--r-- | source3/utils/net_idmap.c | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index e151bf90a0..6ce62c4f29 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -646,6 +646,93 @@ static bool parse_uint32(const char *str, uint32_t *result) return true; } +static void net_idmap_autorid_delete_range_usage(void) +{ + d_printf("%s\n%s", + _("Usage:"), + _("net idmap delete range [-f] [--db=<TDB>] <RANGE>|(<SID>[ <INDEX>])\n" + " Delete a domain range mapping from the database.\n" + " -f\tforce\n" + " TDB\tidmap database\n" + " RANGE\tthe range number to delete\n" + " SID\t\tSID of the domain\n" + " INDEX\trange index number do delete for the domain\n")); +} + +static int net_idmap_autorid_delete_range(struct net_context *c, int argc, + const char **argv) +{ + int ret = -1; + struct db_context *db = NULL; + NTSTATUS status; + uint32_t rangenum; + uint32_t range_index; + const char *domsid; + TALLOC_CTX *mem_ctx = NULL; + bool ok; + bool force = (c->opt_force != 0); + + if (c->display_usage) { + net_idmap_autorid_delete_range_usage(); + return 0; + } + + if (argc < 1 || argc > 2) { + net_idmap_autorid_delete_range_usage(); + return -1; + } + + mem_ctx = talloc_stackframe(); + if (!net_idmap_opendb_autorid(mem_ctx, c, false, &db)) { + goto done; + } + + ok = parse_uint32(argv[0], &rangenum); + if (ok) { + d_printf("%s: %"PRIu32"\n", _("Deleting range number"), + rangenum); + + status = idmap_autorid_delete_range_by_num(db, rangenum, + force); + if (!NT_STATUS_IS_OK(status)) { + d_fprintf(stderr, "%s: %s\n", + _("Failed to delete domain range mapping"), + nt_errstr(status)); + } else { + ret = 0; + } + + goto done; + } + + domsid = argv[0]; + + if (argc == 2) { + ok = parse_uint32(argv[1], &range_index); + if (!ok) { + d_printf("%s: %s\n", + _("Invalid index specification"), argv[1]); + net_idmap_autorid_delete_range_usage(); + goto done; + } + } + + status = idmap_autorid_delete_range_by_sid(db, domsid, range_index, + force); + if (!NT_STATUS_IS_OK(status)) { + d_fprintf(stderr, "%s: %s\n", + _("Failed to delete domain range mapping"), + nt_errstr(status)); + goto done; + } + + 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[] = { @@ -657,6 +744,14 @@ static int net_idmap_delete(struct net_context *c, int argc, const char **argv) N_("net idmap delete mapping <ID>\n" " Delete ID mapping") }, + { + "range", + net_idmap_autorid_delete_range, + NET_TRANSPORT_LOCAL, + N_("Delete a domain range mapping"), + N_("net idmap delete range <RANGE>|(<SID>[ <INDEX>])\n" + " Delete a domain range mapping") + }, {NULL, NULL, 0, NULL, NULL} }; |