r17915: Saturn fixes
[Samba/gbeck.git] / source / utils / net_groupmap.c
blob10a672bc1f05d65ef0af33df942dbe0359ce0207
1 /*
2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Andrew Tridgell 1992-2000,
5 * Copyright (C) Jean François Micouleau 1998-2001.
6 * Copyright (C) Gerald Carter 2003,
7 * Copyright (C) Volker Lendecke 2004
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include "includes.h"
26 #include "utils/net.h"
29 /*********************************************************
30 utility function to parse an integer parameter from
31 "parameter = value"
32 **********************************************************/
33 static uint32 get_int_param( const char* param )
35 char *p;
37 p = strchr( param, '=' );
38 if ( !p )
39 return 0;
41 return atoi(p+1);
44 /*********************************************************
45 utility function to parse an integer parameter from
46 "parameter = value"
47 **********************************************************/
48 static char* get_string_param( const char* param )
50 char *p;
52 p = strchr( param, '=' );
53 if ( !p )
54 return NULL;
56 return (p+1);
59 /*********************************************************
60 Figure out if the input was an NT group or a SID string.
61 Return the SID.
62 **********************************************************/
63 static BOOL get_sid_from_input(DOM_SID *sid, char *input)
65 GROUP_MAP map;
67 if (StrnCaseCmp( input, "S-", 2)) {
68 /* Perhaps its the NT group name? */
69 if (!pdb_getgrnam(&map, input)) {
70 printf("NT Group %s doesn't exist in mapping DB\n", input);
71 return False;
72 } else {
73 *sid = map.sid;
75 } else {
76 if (!string_to_sid(sid, input)) {
77 printf("converting sid %s from a string failed!\n", input);
78 return False;
81 return True;
84 /*********************************************************
85 Dump a GROUP_MAP entry to stdout (long or short listing)
86 **********************************************************/
88 static void print_map_entry ( GROUP_MAP map, BOOL long_list )
90 if (!long_list)
91 d_printf("%s (%s) -> %s\n", map.nt_name,
92 sid_string_static(&map.sid), gidtoname(map.gid));
93 else {
94 d_printf("%s\n", map.nt_name);
95 d_printf("\tSID : %s\n", sid_string_static(&map.sid));
96 d_printf("\tUnix gid : %d\n", map.gid);
97 d_printf("\tUnix group: %s\n", gidtoname(map.gid));
98 d_printf("\tGroup type: %s\n",
99 sid_type_lookup(map.sid_name_use));
100 d_printf("\tComment : %s\n", map.comment);
104 /*********************************************************
105 List the groups.
106 **********************************************************/
107 static int net_groupmap_list(int argc, const char **argv)
109 size_t entries;
110 BOOL long_list = False;
111 size_t i;
112 fstring ntgroup = "";
113 fstring sid_string = "";
115 if (opt_verbose || opt_long_list_entries)
116 long_list = True;
118 /* get the options */
119 for ( i=0; i<argc; i++ ) {
120 if ( !StrCaseCmp(argv[i], "verbose")) {
121 long_list = True;
123 else if ( !StrnCaseCmp(argv[i], "ntgroup", strlen("ntgroup")) ) {
124 fstrcpy( ntgroup, get_string_param( argv[i] ) );
125 if ( !ntgroup[0] ) {
126 d_fprintf(stderr, "must supply a name\n");
127 return -1;
130 else if ( !StrnCaseCmp(argv[i], "sid", strlen("sid")) ) {
131 fstrcpy( sid_string, get_string_param( argv[i] ) );
132 if ( !sid_string[0] ) {
133 d_fprintf(stderr, "must supply a SID\n");
134 return -1;
137 else {
138 d_fprintf(stderr, "Bad option: %s\n", argv[i]);
139 return -1;
143 /* list a single group is given a name */
144 if ( ntgroup[0] || sid_string[0] ) {
145 DOM_SID sid;
146 GROUP_MAP map;
148 if ( sid_string[0] )
149 fstrcpy( ntgroup, sid_string);
151 if (!get_sid_from_input(&sid, ntgroup)) {
152 return -1;
155 /* Get the current mapping from the database */
156 if(!pdb_getgrsid(&map, sid)) {
157 d_fprintf(stderr, "Failure to local group SID in the database\n");
158 return -1;
161 print_map_entry( map, long_list );
163 else {
164 GROUP_MAP *map=NULL;
165 /* enumerate all group mappings */
166 if (!pdb_enum_group_mapping(NULL, SID_NAME_UNKNOWN, &map, &entries, ENUM_ALL_MAPPED))
167 return -1;
169 for (i=0; i<entries; i++) {
170 print_map_entry( map[i], long_list );
173 SAFE_FREE(map);
176 return 0;
179 /*********************************************************
180 Add a new group mapping entry
181 **********************************************************/
183 static int net_groupmap_add(int argc, const char **argv)
185 DOM_SID sid;
186 fstring ntgroup = "";
187 fstring unixgrp = "";
188 fstring string_sid = "";
189 fstring type = "";
190 fstring ntcomment = "";
191 enum SID_NAME_USE sid_type = SID_NAME_DOM_GRP;
192 uint32 rid = 0;
193 gid_t gid;
194 int i;
195 const char *name_type = "domain group";
197 /* get the options */
198 for ( i=0; i<argc; i++ ) {
199 if ( !StrnCaseCmp(argv[i], "rid", strlen("rid")) ) {
200 rid = get_int_param(argv[i]);
201 if ( rid < DOMAIN_GROUP_RID_ADMINS ) {
202 d_fprintf(stderr, "RID must be greater than %d\n", (uint32)DOMAIN_GROUP_RID_ADMINS-1);
203 return -1;
206 else if ( !StrnCaseCmp(argv[i], "unixgroup", strlen("unixgroup")) ) {
207 fstrcpy( unixgrp, get_string_param( argv[i] ) );
208 if ( !unixgrp[0] ) {
209 d_fprintf(stderr, "must supply a name\n");
210 return -1;
213 else if ( !StrnCaseCmp(argv[i], "ntgroup", strlen("ntgroup")) ) {
214 fstrcpy( ntgroup, get_string_param( argv[i] ) );
215 if ( !ntgroup[0] ) {
216 d_fprintf(stderr, "must supply a name\n");
217 return -1;
220 else if ( !StrnCaseCmp(argv[i], "sid", strlen("sid")) ) {
221 fstrcpy( string_sid, get_string_param( argv[i] ) );
222 if ( !string_sid[0] ) {
223 d_fprintf(stderr, "must supply a SID\n");
224 return -1;
227 else if ( !StrnCaseCmp(argv[i], "comment", strlen("comment")) ) {
228 fstrcpy( ntcomment, get_string_param( argv[i] ) );
229 if ( !ntcomment[0] ) {
230 d_fprintf(stderr, "must supply a comment string\n");
231 return -1;
234 else if ( !StrnCaseCmp(argv[i], "type", strlen("type")) ) {
235 fstrcpy( type, get_string_param( argv[i] ) );
236 switch ( type[0] ) {
237 case 'b':
238 case 'B':
239 sid_type = SID_NAME_WKN_GRP;
240 name_type = "wellknown group";
241 break;
242 case 'd':
243 case 'D':
244 sid_type = SID_NAME_DOM_GRP;
245 name_type = "domain group";
246 break;
247 case 'l':
248 case 'L':
249 sid_type = SID_NAME_ALIAS;
250 name_type = "alias (local) group";
251 break;
252 default:
253 d_fprintf(stderr, "unknown group type %s\n", type);
254 return -1;
257 else {
258 d_fprintf(stderr, "Bad option: %s\n", argv[i]);
259 return -1;
263 if ( !unixgrp[0] ) {
264 d_printf("Usage: net groupmap add {rid=<int>|sid=<string>} unixgroup=<string> [type=<domain|local|builtin>] [ntgroup=<string>] [comment=<string>]\n");
265 return -1;
268 if ( (gid = nametogid(unixgrp)) == (gid_t)-1 ) {
269 d_fprintf(stderr, "Can't lookup UNIX group %s\n", unixgrp);
270 return -1;
274 GROUP_MAP map;
275 if (pdb_getgrgid(&map, gid)) {
276 d_printf("Unix group %s already mapped to SID %s\n",
277 unixgrp, sid_string_static(&map.sid));
278 return -1;
282 if ( (rid == 0) && (string_sid[0] == '\0') ) {
283 d_printf("No rid or sid specified, choosing a RID\n");
284 if (pdb_rid_algorithm()) {
285 rid = algorithmic_pdb_gid_to_group_rid(gid);
286 } else {
287 if (!pdb_new_rid(&rid)) {
288 d_printf("Could not get new RID\n");
291 d_printf("Got RID %d\n", rid);
294 /* append the rid to our own domain/machine SID if we don't have a full SID */
295 if ( !string_sid[0] ) {
296 sid_copy(&sid, get_global_sam_sid());
297 sid_append_rid(&sid, rid);
298 sid_to_string(string_sid, &sid);
301 if (!ntcomment[0]) {
302 switch (sid_type) {
303 case SID_NAME_WKN_GRP:
304 fstrcpy(ntcomment, "Wellknown Unix group");
305 break;
306 case SID_NAME_DOM_GRP:
307 fstrcpy(ntcomment, "Domain Unix group");
308 break;
309 case SID_NAME_ALIAS:
310 fstrcpy(ntcomment, "Local Unix group");
311 break;
312 default:
313 fstrcpy(ntcomment, "Unix group");
314 break;
318 if (!ntgroup[0] )
319 fstrcpy( ntgroup, unixgrp );
322 if (!NT_STATUS_IS_OK(add_initial_entry(gid, string_sid, sid_type, ntgroup, ntcomment))) {
323 d_fprintf(stderr, "adding entry for group %s failed!\n", ntgroup);
324 return -1;
327 d_printf("Successfully added group %s to the mapping db as a %s\n",
328 ntgroup, name_type);
329 return 0;
332 static int net_groupmap_modify(int argc, const char **argv)
334 DOM_SID sid;
335 GROUP_MAP map;
336 fstring ntcomment = "";
337 fstring type = "";
338 fstring ntgroup = "";
339 fstring unixgrp = "";
340 fstring sid_string = "";
341 enum SID_NAME_USE sid_type = SID_NAME_UNKNOWN;
342 int i;
343 gid_t gid;
345 /* get the options */
346 for ( i=0; i<argc; i++ ) {
347 if ( !StrnCaseCmp(argv[i], "ntgroup", strlen("ntgroup")) ) {
348 fstrcpy( ntgroup, get_string_param( argv[i] ) );
349 if ( !ntgroup[0] ) {
350 d_fprintf(stderr, "must supply a name\n");
351 return -1;
354 else if ( !StrnCaseCmp(argv[i], "sid", strlen("sid")) ) {
355 fstrcpy( sid_string, get_string_param( argv[i] ) );
356 if ( !sid_string[0] ) {
357 d_fprintf(stderr, "must supply a name\n");
358 return -1;
361 else if ( !StrnCaseCmp(argv[i], "comment", strlen("comment")) ) {
362 fstrcpy( ntcomment, get_string_param( argv[i] ) );
363 if ( !ntcomment[0] ) {
364 d_fprintf(stderr, "must supply a comment string\n");
365 return -1;
368 else if ( !StrnCaseCmp(argv[i], "unixgroup", strlen("unixgroup")) ) {
369 fstrcpy( unixgrp, get_string_param( argv[i] ) );
370 if ( !unixgrp[0] ) {
371 d_fprintf(stderr, "must supply a group name\n");
372 return -1;
375 else if ( !StrnCaseCmp(argv[i], "type", strlen("type")) ) {
376 fstrcpy( type, get_string_param( argv[i] ) );
377 switch ( type[0] ) {
378 case 'd':
379 case 'D':
380 sid_type = SID_NAME_DOM_GRP;
381 break;
382 case 'l':
383 case 'L':
384 sid_type = SID_NAME_ALIAS;
385 break;
388 else {
389 d_fprintf(stderr, "Bad option: %s\n", argv[i]);
390 return -1;
394 if ( !ntgroup[0] && !sid_string[0] ) {
395 d_printf("Usage: net groupmap modify {ntgroup=<string>|sid=<SID>} [comment=<string>] [unixgroup=<string>] [type=<domain|local>]\n");
396 return -1;
399 /* give preference to the SID; if both the ntgroup name and SID
400 are defined, use the SID and assume that the group name could be a
401 new name */
403 if ( sid_string[0] ) {
404 if (!get_sid_from_input(&sid, sid_string)) {
405 return -1;
408 else {
409 if (!get_sid_from_input(&sid, ntgroup)) {
410 return -1;
414 /* Get the current mapping from the database */
415 if(!pdb_getgrsid(&map, sid)) {
416 d_fprintf(stderr, "Failure to local group SID in the database\n");
417 return -1;
421 * Allow changing of group type only between domain and local
422 * We disallow changing Builtin groups !!! (SID problem)
424 if (sid_type == SID_NAME_UNKNOWN) {
425 d_fprintf(stderr, "Can't map to an unknown group type.\n");
426 return -1;
429 if (map.sid_name_use == SID_NAME_WKN_GRP) {
430 d_fprintf(stderr, "You can only change between domain and local groups.\n");
431 return -1;
434 map.sid_name_use=sid_type;
436 /* Change comment if new one */
437 if ( ntcomment[0] )
438 fstrcpy( map.comment, ntcomment );
440 if ( ntgroup[0] )
441 fstrcpy( map.nt_name, ntgroup );
443 if ( unixgrp[0] ) {
444 gid = nametogid( unixgrp );
445 if ( gid == -1 ) {
446 d_fprintf(stderr, "Unable to lookup UNIX group %s. Make sure the group exists.\n",
447 unixgrp);
448 return -1;
451 map.gid = gid;
454 if ( !NT_STATUS_IS_OK(pdb_update_group_mapping_entry(&map)) ) {
455 d_fprintf(stderr, "Could not update group database\n");
456 return -1;
459 d_printf("Updated mapping entry for %s\n", map.nt_name);
461 return 0;
464 static int net_groupmap_delete(int argc, const char **argv)
466 DOM_SID sid;
467 fstring ntgroup = "";
468 fstring sid_string = "";
469 int i;
471 /* get the options */
472 for ( i=0; i<argc; i++ ) {
473 if ( !StrnCaseCmp(argv[i], "ntgroup", strlen("ntgroup")) ) {
474 fstrcpy( ntgroup, get_string_param( argv[i] ) );
475 if ( !ntgroup[0] ) {
476 d_fprintf(stderr, "must supply a name\n");
477 return -1;
480 else if ( !StrnCaseCmp(argv[i], "sid", strlen("sid")) ) {
481 fstrcpy( sid_string, get_string_param( argv[i] ) );
482 if ( !sid_string[0] ) {
483 d_fprintf(stderr, "must supply a SID\n");
484 return -1;
487 else {
488 d_fprintf(stderr, "Bad option: %s\n", argv[i]);
489 return -1;
493 if ( !ntgroup[0] && !sid_string[0]) {
494 d_printf("Usage: net groupmap delete {ntgroup=<string>|sid=<SID>}\n");
495 return -1;
498 /* give preference to the SID if we have that */
500 if ( sid_string[0] )
501 fstrcpy( ntgroup, sid_string );
503 if ( !get_sid_from_input(&sid, ntgroup) ) {
504 d_fprintf(stderr, "Unable to resolve group %s to a SID\n", ntgroup);
505 return -1;
508 if ( !NT_STATUS_IS_OK(pdb_delete_group_mapping_entry(sid)) ) {
509 d_fprintf(stderr, "Failed to removing group %s from the mapping db!\n", ntgroup);
510 return -1;
513 d_printf("Sucessfully removed %s from the mapping db\n", ntgroup);
515 return 0;
518 static int net_groupmap_set(int argc, const char **argv)
520 const char *ntgroup = NULL;
521 struct group *grp = NULL;
522 GROUP_MAP map;
523 BOOL have_map = False;
525 if ((argc < 1) || (argc > 2)) {
526 d_printf("Usage: net groupmap set \"NT Group\" "
527 "[\"unix group\"] [-C \"comment\"] [-L] [-D]\n");
528 return -1;
531 if ( opt_localgroup && opt_domaingroup ) {
532 d_printf("Can only specify -L or -D, not both\n");
533 return -1;
536 ntgroup = argv[0];
538 if (argc == 2) {
539 grp = getgrnam(argv[1]);
541 if (grp == NULL) {
542 d_fprintf(stderr, "Could not find unix group %s\n", argv[1]);
543 return -1;
547 have_map = pdb_getgrnam(&map, ntgroup);
549 if (!have_map) {
550 DOM_SID sid;
551 have_map = ( (strncmp(ntgroup, "S-", 2) == 0) &&
552 string_to_sid(&sid, ntgroup) &&
553 pdb_getgrsid(&map, sid) );
556 if (!have_map) {
558 /* Ok, add it */
560 if (grp == NULL) {
561 d_fprintf(stderr, "Could not find group mapping for %s\n",
562 ntgroup);
563 return -1;
566 map.gid = grp->gr_gid;
568 if (opt_rid == 0) {
569 if ( pdb_rid_algorithm() )
570 opt_rid = algorithmic_pdb_gid_to_group_rid(map.gid);
571 else {
572 if ( !pdb_new_rid((uint32*)&opt_rid) ) {
573 d_fprintf( stderr, "Could not allocate new RID\n");
574 return -1;
579 sid_copy(&map.sid, get_global_sam_sid());
580 sid_append_rid(&map.sid, opt_rid);
582 map.sid_name_use = SID_NAME_DOM_GRP;
583 fstrcpy(map.nt_name, ntgroup);
584 fstrcpy(map.comment, "");
586 if (!NT_STATUS_IS_OK(pdb_add_group_mapping_entry(&map))) {
587 d_fprintf(stderr, "Could not add mapping entry for %s\n",
588 ntgroup);
589 return -1;
593 /* Now we have a mapping entry, update that stuff */
595 if ( opt_localgroup || opt_domaingroup ) {
596 if (map.sid_name_use == SID_NAME_WKN_GRP) {
597 d_fprintf(stderr, "Can't change type of the BUILTIN group %s\n",
598 map.nt_name);
599 return -1;
603 if (opt_localgroup)
604 map.sid_name_use = SID_NAME_ALIAS;
606 if (opt_domaingroup)
607 map.sid_name_use = SID_NAME_DOM_GRP;
609 /* The case (opt_domaingroup && opt_localgroup) was tested for above */
611 if (strlen(opt_comment) > 0)
612 fstrcpy(map.comment, opt_comment);
614 if (strlen(opt_newntname) > 0)
615 fstrcpy(map.nt_name, opt_newntname);
617 if (grp != NULL)
618 map.gid = grp->gr_gid;
620 if (!NT_STATUS_IS_OK(pdb_update_group_mapping_entry(&map))) {
621 d_fprintf(stderr, "Could not update group mapping for %s\n", ntgroup);
622 return -1;
625 return 0;
628 static int net_groupmap_cleanup(int argc, const char **argv)
630 GROUP_MAP *map = NULL;
631 size_t i, entries;
633 if (!pdb_enum_group_mapping(NULL, SID_NAME_UNKNOWN, &map, &entries,
634 ENUM_ALL_MAPPED)) {
635 d_fprintf(stderr, "Could not list group mappings\n");
636 return -1;
639 for (i=0; i<entries; i++) {
641 if (map[i].gid == -1)
642 printf("Group %s is not mapped\n", map[i].nt_name);
644 if (!sid_check_is_in_our_domain(&map[i].sid)) {
645 printf("Deleting mapping for NT Group %s, sid %s\n",
646 map[i].nt_name,
647 sid_string_static(&map[i].sid));
648 pdb_delete_group_mapping_entry(map[i].sid);
652 SAFE_FREE(map);
654 return 0;
657 static int net_groupmap_addmem(int argc, const char **argv)
659 DOM_SID alias, member;
661 if ( (argc != 2) ||
662 !string_to_sid(&alias, argv[0]) ||
663 !string_to_sid(&member, argv[1]) ) {
664 d_printf("Usage: net groupmap addmem alias-sid member-sid\n");
665 return -1;
668 if (!NT_STATUS_IS_OK(pdb_add_aliasmem(&alias, &member))) {
669 d_fprintf(stderr, "Could not add sid %s to alias %s\n",
670 argv[1], argv[0]);
671 return -1;
674 return 0;
677 static int net_groupmap_delmem(int argc, const char **argv)
679 DOM_SID alias, member;
681 if ( (argc != 2) ||
682 !string_to_sid(&alias, argv[0]) ||
683 !string_to_sid(&member, argv[1]) ) {
684 d_printf("Usage: net groupmap delmem alias-sid member-sid\n");
685 return -1;
688 if (!NT_STATUS_IS_OK(pdb_del_aliasmem(&alias, &member))) {
689 d_fprintf(stderr, "Could not delete sid %s from alias %s\n",
690 argv[1], argv[0]);
691 return -1;
694 return 0;
697 static int net_groupmap_listmem(int argc, const char **argv)
699 DOM_SID alias;
700 DOM_SID *members;
701 size_t i, num;
703 if ( (argc != 1) ||
704 !string_to_sid(&alias, argv[0]) ) {
705 d_printf("Usage: net groupmap listmem alias-sid\n");
706 return -1;
709 members = NULL;
710 num = 0;
712 if (!NT_STATUS_IS_OK(pdb_enum_aliasmem(&alias, &members, &num))) {
713 d_fprintf(stderr, "Could not list members for sid %s\n", argv[0]);
714 return -1;
717 for (i = 0; i < num; i++) {
718 printf("%s\n", sid_string_static(&(members[i])));
721 SAFE_FREE(members);
723 return 0;
726 static BOOL print_alias_memberships(TALLOC_CTX *mem_ctx,
727 const DOM_SID *domain_sid,
728 const DOM_SID *member)
730 uint32 *alias_rids;
731 size_t i, num_alias_rids;
733 alias_rids = NULL;
734 num_alias_rids = 0;
736 if (!NT_STATUS_IS_OK(pdb_enum_alias_memberships(
737 mem_ctx, domain_sid, member, 1,
738 &alias_rids, &num_alias_rids))) {
739 d_fprintf(stderr, "Could not list memberships for sid %s\n",
740 sid_string_static(member));
741 return False;
744 for (i = 0; i < num_alias_rids; i++) {
745 DOM_SID alias;
746 sid_copy(&alias, domain_sid);
747 sid_append_rid(&alias, alias_rids[i]);
748 printf("%s\n", sid_string_static(&alias));
751 return True;
754 static int net_groupmap_memberships(int argc, const char **argv)
756 TALLOC_CTX *mem_ctx;
757 DOM_SID *domain_sid, *builtin_sid, member;
759 if ( (argc != 1) ||
760 !string_to_sid(&member, argv[0]) ) {
761 d_printf("Usage: net groupmap memberof sid\n");
762 return -1;
765 mem_ctx = talloc_init("net_groupmap_memberships");
766 if (mem_ctx == NULL) {
767 d_fprintf(stderr, "talloc_init failed\n");
768 return -1;
771 domain_sid = get_global_sam_sid();
772 builtin_sid = string_sid_talloc(mem_ctx, "S-1-5-32");
773 if ((domain_sid == NULL) || (builtin_sid == NULL)) {
774 d_fprintf(stderr, "Could not get domain sid\n");
775 return -1;
778 if (!print_alias_memberships(mem_ctx, domain_sid, &member) ||
779 !print_alias_memberships(mem_ctx, builtin_sid, &member))
780 return -1;
782 talloc_destroy(mem_ctx);
784 return 0;
787 int net_help_groupmap(int argc, const char **argv)
789 d_printf("net groupmap add"\
790 "\n Create a new group mapping\n");
791 d_printf("net groupmap modify"\
792 "\n Update a group mapping\n");
793 d_printf("net groupmap delete"\
794 "\n Remove a group mapping\n");
795 d_printf("net groupmap addmem"\
796 "\n Add a foreign alias member\n");
797 d_printf("net groupmap delmem"\
798 "\n Delete a foreign alias member\n");
799 d_printf("net groupmap listmem"\
800 "\n List foreign group members\n");
801 d_printf("net groupmap memberships"\
802 "\n List foreign group memberships\n");
803 d_printf("net groupmap list"\
804 "\n List current group map\n");
805 d_printf("net groupmap set"\
806 "\n Set group mapping\n");
807 d_printf("net groupmap cleanup"\
808 "\n Remove foreign group mapping entries\n");
810 return -1;
814 /***********************************************************
815 migrated functionality from smbgroupedit
816 **********************************************************/
817 int net_groupmap(int argc, const char **argv)
819 struct functable func[] = {
820 {"add", net_groupmap_add},
821 {"modify", net_groupmap_modify},
822 {"delete", net_groupmap_delete},
823 {"set", net_groupmap_set},
824 {"cleanup", net_groupmap_cleanup},
825 {"addmem", net_groupmap_addmem},
826 {"delmem", net_groupmap_delmem},
827 {"listmem", net_groupmap_listmem},
828 {"memberships", net_groupmap_memberships},
829 {"list", net_groupmap_list},
830 {"help", net_help_groupmap},
831 {NULL, NULL}
834 /* we shouldn't have silly checks like this */
835 if (getuid() != 0) {
836 d_fprintf(stderr, "You must be root to edit group mappings.\n");
837 return -1;
840 if ( argc )
841 return net_run_function(argc, argv, func, net_help_groupmap);
843 return net_help_groupmap( argc, argv );