diff options
-rw-r--r-- | source3/utils/net_groupmap.c | 189 |
1 files changed, 138 insertions, 51 deletions
diff --git a/source3/utils/net_groupmap.c b/source3/utils/net_groupmap.c index 4b4ec45dea..cea1b0a3d7 100644 --- a/source3/utils/net_groupmap.c +++ b/source3/utils/net_groupmap.c @@ -79,6 +79,16 @@ static int net_groupmap_list(struct net_context *c, int argc, const char **argv) size_t i; fstring ntgroup = ""; fstring sid_string = ""; + const char list_usage_str[] = "net groupmap list [verbose] " + "[ntgroup=NT group] [sid=SID]\n" + " verbose\tPrint verbose list\n" + " ntgroup\tNT group to list\n" + " sid\tSID of group to list"; + + if (c->display_usage) { + d_printf("Usage:\n%s\n", list_usage_str); + return 0; + } if (c->opt_verbose || c->opt_long_list_entries) long_list = true; @@ -104,6 +114,7 @@ static int net_groupmap_list(struct net_context *c, int argc, const char **argv) } else { d_fprintf(stderr, "Bad option: %s\n", argv[i]); + d_printf("Usage:\n%s\n", list_usage_str); return -1; } } @@ -163,6 +174,10 @@ static int net_groupmap_add(struct net_context *c, int argc, const char **argv) GROUP_MAP map; const char *name_type; + const char add_usage_str[] = "net groupmap add {rid=<int>|sid=<string>}" + " unixgroup=<string> " + "[type=<domain|local|builtin>] " + "[ntgroup=<string>] [comment=<string>]"; ZERO_STRUCT(map); @@ -170,6 +185,11 @@ static int net_groupmap_add(struct net_context *c, int argc, const char **argv) map.sid_name_use = SID_NAME_DOM_GRP; name_type = "domain group"; + if (c->display_usage) { + d_printf("Usage\n%s\n", add_usage_str); + return 0; + } + /* get the options */ for ( i=0; i<argc; i++ ) { if ( !StrnCaseCmp(argv[i], "rid", strlen("rid")) ) { @@ -237,7 +257,7 @@ static int net_groupmap_add(struct net_context *c, int argc, const char **argv) } if ( !unixgrp[0] ) { - d_printf("Usage: net groupmap add {rid=<int>|sid=<string>} unixgroup=<string> [type=<domain|local|builtin>] [ntgroup=<string>] [comment=<string>]\n"); + d_printf("Usage:\n%s\n", add_usage_str); return -1; } @@ -315,6 +335,16 @@ static int net_groupmap_modify(struct net_context *c, int argc, const char **arg enum lsa_SidType sid_type = SID_NAME_UNKNOWN; int i; gid_t gid; + const char modify_usage_str[] = "net groupmap modify " + "{ntgroup=<string>|sid=<SID>} " + "[comment=<string>] " + "[unixgroup=<string>] " + "[type=<domain|local>]"; + + if (c->display_usage) { + d_printf("Usage:\n%s\n", modify_usage_str); + return 0; + } /* get the options */ for ( i=0; i<argc; i++ ) { @@ -366,7 +396,7 @@ static int net_groupmap_modify(struct net_context *c, int argc, const char **arg } if ( !ntgroup[0] && !sid_string[0] ) { - d_printf("Usage: net groupmap modify {ntgroup=<string>|sid=<SID>} [comment=<string>] [unixgroup=<string>] [type=<domain|local>]\n"); + d_printf("Usage:\n%s\n", modify_usage_str); return -1; } @@ -441,6 +471,13 @@ static int net_groupmap_delete(struct net_context *c, int argc, const char **arg fstring ntgroup = ""; fstring sid_string = ""; int i; + const char delete_usage_str[] = "net groupmap delete " + "{ntgroup=<string>|sid=<SID>}"; + + if (c->display_usage) { + d_printf("Usage:\n%s\n", delete_usage_str); + return 0; + } /* get the options */ for ( i=0; i<argc; i++ ) { @@ -465,7 +502,7 @@ static int net_groupmap_delete(struct net_context *c, int argc, const char **arg } if ( !ntgroup[0] && !sid_string[0]) { - d_printf("Usage: net groupmap delete {ntgroup=<string>|sid=<SID>}\n"); + d_printf("Usage:\n%s\n", delete_usage_str); return -1; } @@ -496,7 +533,7 @@ static int net_groupmap_set(struct net_context *c, int argc, const char **argv) GROUP_MAP map; bool have_map = false; - if ((argc < 1) || (argc > 2)) { + if ((argc < 1) || (argc > 2) || c->display_usage) { d_printf("Usage: net groupmap set \"NT Group\" " "[\"unix group\"] [-C \"comment\"] [-L] [-D]\n"); return -1; @@ -604,6 +641,13 @@ static int net_groupmap_cleanup(struct net_context *c, int argc, const char **ar GROUP_MAP *map = NULL; size_t i, entries; + if (c->display_usage) { + d_printf("Usage:\n" + "net groupmap cleanup\n" + " Delete all group mappings\n"); + return 0; + } + if (!pdb_enum_group_mapping(NULL, SID_NAME_UNKNOWN, &map, &entries, ENUM_ALL_MAPPED)) { d_fprintf(stderr, "Could not list group mappings\n"); @@ -633,6 +677,7 @@ static int net_groupmap_addmem(struct net_context *c, int argc, const char **arg DOM_SID alias, member; if ( (argc != 2) || + c->display_usage || !string_to_sid(&alias, argv[0]) || !string_to_sid(&member, argv[1]) ) { d_printf("Usage: net groupmap addmem alias-sid member-sid\n"); @@ -652,7 +697,8 @@ static int net_groupmap_delmem(struct net_context *c, int argc, const char **arg { DOM_SID alias, member; - if ( (argc != 2) || + if ( (argc != 2) || + c->display_usage || !string_to_sid(&alias, argv[0]) || !string_to_sid(&member, argv[1]) ) { d_printf("Usage: net groupmap delmem alias-sid member-sid\n"); @@ -674,7 +720,8 @@ static int net_groupmap_listmem(struct net_context *c, int argc, const char **ar DOM_SID *members; size_t i, num; - if ( (argc != 1) || + if ( (argc != 1) || + c->display_usage || !string_to_sid(&alias, argv[0]) ) { d_printf("Usage: net groupmap listmem alias-sid\n"); return -1; @@ -730,7 +777,8 @@ static int net_groupmap_memberships(struct net_context *c, int argc, const char TALLOC_CTX *mem_ctx; DOM_SID *domain_sid, *builtin_sid, member; - if ( (argc != 1) || + if ( (argc != 1) || + c->display_usage || !string_to_sid(&member, argv[0]) ) { d_printf("Usage: net groupmap memberof sid\n"); return -1; @@ -758,51 +806,93 @@ static int net_groupmap_memberships(struct net_context *c, int argc, const char return 0; } -int net_groupmap_usage(struct net_context *c, int argc, const char **argv) -{ - d_printf("net groupmap add"\ - "\n Create a new group mapping\n"); - d_printf("net groupmap modify"\ - "\n Update a group mapping\n"); - d_printf("net groupmap delete"\ - "\n Remove a group mapping\n"); - d_printf("net groupmap addmem"\ - "\n Add a foreign alias member\n"); - d_printf("net groupmap delmem"\ - "\n Delete a foreign alias member\n"); - d_printf("net groupmap listmem"\ - "\n List foreign group members\n"); - d_printf("net groupmap memberships"\ - "\n List foreign group memberships\n"); - d_printf("net groupmap list"\ - "\n List current group map\n"); - d_printf("net groupmap set"\ - "\n Set group mapping\n"); - d_printf("net groupmap cleanup"\ - "\n Remove foreign group mapping entries\n"); - - return -1; -} - - /*********************************************************** migrated functionality from smbgroupedit **********************************************************/ int net_groupmap(struct net_context *c, int argc, const char **argv) { - struct functable func[] = { - {"add", net_groupmap_add}, - {"modify", net_groupmap_modify}, - {"delete", net_groupmap_delete}, - {"set", net_groupmap_set}, - {"cleanup", net_groupmap_cleanup}, - {"addmem", net_groupmap_addmem}, - {"delmem", net_groupmap_delmem}, - {"listmem", net_groupmap_listmem}, - {"memberships", net_groupmap_memberships}, - {"list", net_groupmap_list}, - {"help", net_groupmap_usage}, - {NULL, NULL} + struct functable3 func[] = { + { + "add", + net_groupmap_add, + NET_TRANSPORT_LOCAL, + "Create a new group mapping", + "net groupmap add\n" + " Create a new group mapping" + }, + { + "modify", + net_groupmap_modify, + NET_TRANSPORT_LOCAL, + "Update a group mapping", + "net groupmap modify\n" + " Modify an existing group mapping" + }, + { + "delete", + net_groupmap_delete, + NET_TRANSPORT_LOCAL, + "Remove a group mapping", + "net groupmap delete\n" + " Remove a group mapping" + }, + { + "set", + net_groupmap_set, + NET_TRANSPORT_LOCAL, + "Set group mapping", + "net groupmap set\n" + " Set a group mapping" + }, + { + "cleanup", + net_groupmap_cleanup, + NET_TRANSPORT_LOCAL, + "Remove foreign group mapping entries", + "net groupmap cleanup\n" + " Remove foreign group mapping entries" + }, + { + "addmem", + net_groupmap_addmem, + NET_TRANSPORT_LOCAL, + "Add a foreign alias member", + "net groupmap addmem\n" + " Add a foreign alias member" + }, + { + "delmem", + net_groupmap_delmem, + NET_TRANSPORT_LOCAL, + "Delete foreign alias member", + "net groupmap delmem\n" + " Delete foreign alias member" + }, + { + "listmem", + net_groupmap_listmem, + NET_TRANSPORT_LOCAL, + "List foreign group members", + "net groupmap listmem\n" + " List foreign alias members" + }, + { + "memberships", + net_groupmap_memberships, + NET_TRANSPORT_LOCAL, + "List foreign group memberships", + "net groupmap memberships\n" + " List foreign group memberships" + }, + { + "list", + net_groupmap_list, + NET_TRANSPORT_LOCAL, + "List current group map", + "net groupmap list\n" + " List current group map" + }, + {NULL, NULL, 0, NULL, NULL} }; /* we shouldn't have silly checks like this */ @@ -811,9 +901,6 @@ int net_groupmap(struct net_context *c, int argc, const char **argv) return -1; } - if ( argc ) - return net_run_function(c,argc, argv, func, net_groupmap_usage); - - return net_groupmap_usage(c, argc, argv); + return net_run_function3(c,argc, argv, "net groupmap", func); } |