diff options
author | Michael Adam <obnox@samba.org> | 2013-09-18 02:39:51 +0200 |
---|---|---|
committer | Michael Adam <obnox@samba.org> | 2013-10-02 00:50:13 +0200 |
commit | fe8a8b50b59e6ca14c799f25635a5c2b43c0962a (patch) | |
tree | ca6627e238077517e5bacc8ff51914f46df889e2 /source3/utils | |
parent | 97dfa06151e8ea843c393f63c2c4b956810b2994 (diff) | |
download | samba-fe8a8b50b59e6ca14c799f25635a5c2b43c0962a.tar.gz samba-fe8a8b50b59e6ca14c799f25635a5c2b43c0962a.tar.bz2 samba-fe8a8b50b59e6ca14c799f25635a5c2b43c0962a.zip |
net: add "net idmap get ranges" operation for autorid
Implemented using the idmap_autorid_iterate_domain_ranges_read() function.
Based on earlier patch by Atul Kulkarni <atul.kulkarni@in.ibm.com>.
Signed-off-by: Michael Adam <obnox@samba.org>
Reviewed-by: Volker Lendecke <vl@samba.org>
Diffstat (limited to 'source3/utils')
-rw-r--r-- | source3/utils/net_idmap.c | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/source3/utils/net_idmap.c b/source3/utils/net_idmap.c index 6ce62c4f29..0a583111f5 100644 --- a/source3/utils/net_idmap.c +++ b/source3/utils/net_idmap.c @@ -1088,6 +1088,76 @@ done: return ret; } +static NTSTATUS net_idmap_autorid_print_range(struct db_context *db, + const char *domsid, + uint32_t range_index, + uint32_t rangenum, + void *private_data) +{ + if (range_index == 0) { + printf("RANGE %"PRIu32": %s\n", rangenum, domsid); + } else { + printf("RANGE %"PRIu32": %s#%"PRIu32"\n", rangenum, domsid, + range_index); + } + + return NT_STATUS_OK; +} + +static void net_idmap_autorid_get_ranges_usage(void) +{ + d_printf("%s\n%s", + _("Usage:"), + _("net idmap get ranges <SID> [--db=<inputfile>]\n" + " Get all ranges for a given domain.\n" + " SID\t\tSID of the domain\n" + " inputfile\tTDB file to add mapping to.\n")); +} + +static int net_idmap_autorid_get_ranges(struct net_context *c, int argc, + const char **argv) +{ + int ret = -1; + TALLOC_CTX *mem_ctx; + struct db_context *db = NULL; + const char *domsid; + NTSTATUS status; + + if (c->display_usage) { + net_idmap_autorid_get_ranges_usage(); + return 0; + } + + if (argc != 1) { + net_idmap_autorid_get_ranges_usage(); + return -1; + } + + domsid = argv[0]; + + mem_ctx = talloc_stackframe(); + if (!net_idmap_opendb_autorid(mem_ctx, c, true, &db)) { + goto done; + } + + status = idmap_autorid_iterate_domain_ranges_read(db, + domsid, + net_idmap_autorid_print_range, + NULL, /* private_data */ + NULL /* count */); + if (!NT_STATUS_IS_OK(status)) { + d_fprintf(stderr, "%s: %s\n", + _("Error getting domain ranges"), nt_errstr(status)); + goto done; + } + + ret = 0; + +done: + talloc_free(mem_ctx); + return ret; +} + static int net_idmap_autorid_get_config(struct net_context *c, int argc, const char **argv) { @@ -1142,6 +1212,14 @@ static int net_idmap_get(struct net_context *c, int argc, const char **argv) " Get the range for a domain and range-index") }, { + "ranges", + net_idmap_autorid_get_ranges, + NET_TRANSPORT_LOCAL, + N_("Get all ranges for a domain"), + N_("net idmap get ranges <SID>\n" + " Get all ranges for a domain") + }, + { "config", net_idmap_autorid_get_config, NET_TRANSPORT_LOCAL, |