import HEAD into svn+ssh://svn.samba.org/home/svn/samba/trunk
[metze/old/v3-2-winbind-ndr.git] / source / utils / net_groupmap.c
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  *
8  *  This program is free software; you can redistribute it and/or modify
9  *  it under the terms of the GNU General Public License as published by
10  *  the Free Software Foundation; either version 2 of the License, or
11  *  (at your option) any later version.
12  *
13  *  This program is distributed in the hope that it will be useful,
14  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
15  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  *  GNU General Public License for more details.
17  *
18  *  You should have received a copy of the GNU General Public License
19  *  along with this program; if not, write to the Free Software
20  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22
23
24 #include "includes.h"
25 #include "../utils/net.h"
26
27
28 /*********************************************************
29  utility function to parse an integer parameter from 
30  "parameter = value"
31 **********************************************************/
32 static uint32 get_int_param( const char* param )
33 {
34         char *p;
35         
36         p = strchr( param, '=' );
37         if ( !p )
38                 return 0;
39                 
40         return atoi(p+1);
41 }
42
43 /*********************************************************
44  utility function to parse an integer parameter from 
45  "parameter = value"
46 **********************************************************/
47 static char* get_string_param( const char* param )
48 {
49         char *p;
50         
51         p = strchr( param, '=' );
52         if ( !p )
53                 return NULL;
54                 
55         return (p+1);
56 }
57
58 /*********************************************************
59  Figure out if the input was an NT group or a SID string.
60  Return the SID.
61 **********************************************************/
62 static BOOL get_sid_from_input(DOM_SID *sid, char *input)
63 {
64         GROUP_MAP map;
65
66         if (StrnCaseCmp( input, "S-", 2)) {
67                 /* Perhaps its the NT group name? */
68                 if (!pdb_getgrnam(&map, input)) {
69                         printf("NT Group %s doesn't exist in mapping DB\n", input);
70                         return False;
71                 } else {
72                         *sid = map.sid;
73                 }
74         } else {
75                 if (!string_to_sid(sid, input)) {
76                         printf("converting sid %s from a string failed!\n", input);
77                         return False;
78                 }
79         }
80         return True;
81 }
82
83 /*********************************************************
84  Dump a GROUP_MAP entry to stdout (long or short listing)
85 **********************************************************/
86
87 static void print_map_entry ( GROUP_MAP map, BOOL long_list )
88 {
89         fstring string_sid;
90         fstring group_type;
91         
92         decode_sid_name_use(group_type, map.sid_name_use);
93         sid_to_string(string_sid, &map.sid);
94                 
95         if (!long_list)
96                 d_printf("%s (%s) -> %s\n", map.nt_name, string_sid, gidtoname(map.gid));
97         else {
98                 d_printf("%s\n", map.nt_name);
99                 d_printf("\tSID       : %s\n", string_sid);
100                 d_printf("\tUnix group: %s\n", gidtoname(map.gid));
101                 d_printf("\tGroup type: %s\n", group_type);
102                 d_printf("\tComment   : %s\n", map.comment);
103         }
104
105 }
106 /*********************************************************
107  List the groups.
108 **********************************************************/
109 static int net_groupmap_list(int argc, const char **argv)
110 {
111         int entries;
112         BOOL long_list = False;
113         int i;
114         fstring ntgroup = "";
115         fstring sid_string = "";
116         
117         /* get the options */
118         for ( i=0; i<argc; i++ ) {
119                 if ( !StrCaseCmp(argv[i], "verbose")) {
120                         long_list = True;
121                 }
122                 else if ( !StrnCaseCmp(argv[i], "ntgroup", strlen("ntgroup")) ) {
123                         fstrcpy( ntgroup, get_string_param( argv[i] ) );
124                         if ( !ntgroup[0] ) {
125                                 d_printf("must supply a name\n");
126                                 return -1;
127                         }               
128                 }
129                 else if ( !StrnCaseCmp(argv[i], "sid", strlen("sid")) ) {
130                         fstrcpy( sid_string, get_string_param( argv[i] ) );
131                         if ( !sid_string[0] ) {
132                                 d_printf("must supply a SID\n");
133                                 return -1;
134                         }               
135                 }
136                 else {
137                         d_printf("Bad option: %s\n", argv[i]);
138                         return -1;
139                 }
140         }
141
142         /* list a single group is given a name */
143         if ( ntgroup[0] || sid_string[0] ) {
144                 DOM_SID sid;
145                 GROUP_MAP map;
146                 
147                 if ( sid_string[0] )
148                         fstrcpy( ntgroup, sid_string);
149                         
150                 if (!get_sid_from_input(&sid, ntgroup)) {
151                         return -1;
152                 }
153
154                 /* Get the current mapping from the database */
155                 if(!pdb_getgrsid(&map, sid)) {
156                         d_printf("Failure to local group SID in the database\n");
157                         return -1;
158                 }
159         
160                 print_map_entry( map, long_list );
161         }
162         else {
163                 GROUP_MAP *map=NULL;
164                 /* enumerate all group mappings */
165                 if (!pdb_enum_group_mapping(SID_NAME_UNKNOWN, &map, &entries, ENUM_ALL_MAPPED))
166                         return -1;
167         
168                 for (i=0; i<entries; i++) {
169                         print_map_entry( map[i], long_list );
170                 }
171
172                 SAFE_FREE(map);
173         }
174
175         return 0;
176 }
177
178 /*********************************************************
179  Add a new group mapping entry
180 **********************************************************/
181
182 static int net_groupmap_add(int argc, const char **argv)
183 {
184         DOM_SID sid;
185         fstring ntgroup = "";
186         fstring unixgrp = "";
187         fstring string_sid = "";
188         fstring type = "";
189         fstring ntcomment = "";
190         enum SID_NAME_USE sid_type = SID_NAME_DOM_GRP;
191         uint32 rid = 0; 
192         gid_t gid;
193         int i;
194         
195         /* get the options */
196         for ( i=0; i<argc; i++ ) {
197                 if ( !StrnCaseCmp(argv[i], "rid", strlen("rid")) ) {
198                         rid = get_int_param(argv[i]);
199                         if ( rid < DOMAIN_GROUP_RID_ADMINS ) {
200                                 d_printf("RID must be greater than %d\n", (uint32)DOMAIN_GROUP_RID_ADMINS-1);
201                                 return -1;
202                         }
203                 }
204                 else if ( !StrnCaseCmp(argv[i], "unixgroup", strlen("unixgroup")) ) {
205                         fstrcpy( unixgrp, get_string_param( argv[i] ) );
206                         if ( !unixgrp[0] ) {
207                                 d_printf("must supply a name\n");
208                                 return -1;
209                         }               
210                 }
211                 else if ( !StrnCaseCmp(argv[i], "ntgroup", strlen("ntgroup")) ) {
212                         fstrcpy( ntgroup, get_string_param( argv[i] ) );
213                         if ( !ntgroup[0] ) {
214                                 d_printf("must supply a name\n");
215                                 return -1;
216                         }               
217                 }
218                 else if ( !StrnCaseCmp(argv[i], "sid", strlen("sid")) ) {
219                         fstrcpy( string_sid, get_string_param( argv[i] ) );
220                         if ( !string_sid[0] ) {
221                                 d_printf("must supply a SID\n");
222                                 return -1;
223                         }               
224                 }
225                 else if ( !StrnCaseCmp(argv[i], "comment", strlen("comment")) ) {
226                         fstrcpy( ntcomment, get_string_param( argv[i] ) );
227                         if ( !ntcomment[0] ) {
228                                 d_printf("must supply a comment string\n");
229                                 return -1;
230                         }                               
231                 }
232                 else if ( !StrnCaseCmp(argv[i], "type", strlen("type")) )  {
233                         fstrcpy( type, get_string_param( argv[i] ) );
234                         switch ( type[0] ) {
235                                 case 'b':
236                                 case 'B':
237                                         sid_type = SID_NAME_WKN_GRP;
238                                         break;
239                                 case 'd':
240                                 case 'D':
241                                         sid_type = SID_NAME_DOM_GRP;
242                                         break;
243                                 case 'l':
244                                 case 'L':
245                                         sid_type = SID_NAME_ALIAS;
246                                         break;
247                         }
248                 }
249                 else {
250                         d_printf("Bad option: %s\n", argv[i]);
251                         return -1;
252                 }
253         }
254
255         if ( !unixgrp[0] ) {
256                 d_printf("Usage: net groupmap add {rid=<int>|sid=<string>} unixgroup=<string> [type=<domain|local|builtin>] [ntgroup=<string>] [comment=<string>]\n");
257                 return -1;
258         }
259         
260         if ( (gid = nametogid(unixgrp)) == (gid_t)-1 ) {
261                 d_printf("Can't lookup UNIX group %s\n", unixgrp);
262                 return -1;
263         }
264         
265         if ( (rid == 0) && (string_sid[0] == '\0') ) {
266                 d_printf("No rid or sid specified, choosing algorithmic mapping\n");
267                 rid = pdb_gid_to_group_rid(gid);
268         }
269
270         /* append the rid to our own domain/machine SID if we don't have a full SID */
271         if ( !string_sid[0] ) {
272                 sid_copy(&sid, get_global_sam_sid());
273                 sid_append_rid(&sid, rid);
274                 sid_to_string(string_sid, &sid);
275         }
276
277         if (!ntcomment[0])
278                 fstrcpy(ntcomment, "Local Unix group");
279                 
280         if (!ntgroup[0] )
281                 fstrcpy( ntgroup, unixgrp );
282                 
283         
284         if (!add_initial_entry(gid, string_sid, sid_type, ntgroup, ntcomment)) {
285                 d_printf("adding entry for group %s failed!\n", ntgroup);
286                 return -1;
287         }
288
289         d_printf("Successully added group %s to the mapping db\n", ntgroup);
290         return 0;
291 }
292
293 static int net_groupmap_modify(int argc, const char **argv)
294 {
295         DOM_SID sid;
296         GROUP_MAP map;
297         fstring ntcomment = "";
298         fstring type = "";
299         fstring ntgroup = "";
300         fstring unixgrp = "";
301         fstring sid_string = "";
302         enum SID_NAME_USE sid_type = SID_NAME_UNKNOWN;
303         int i;
304         gid_t gid;
305
306         /* get the options */
307         for ( i=0; i<argc; i++ ) {
308                 if ( !StrnCaseCmp(argv[i], "ntgroup", strlen("ntgroup")) ) {
309                         fstrcpy( ntgroup, get_string_param( argv[i] ) );
310                         if ( !ntgroup[0] ) {
311                                 d_printf("must supply a name\n");
312                                 return -1;
313                         }               
314                 }
315                 else if ( !StrnCaseCmp(argv[i], "sid", strlen("sid")) ) {
316                         fstrcpy( sid_string, get_string_param( argv[i] ) );
317                         if ( !sid_string[0] ) {
318                                 d_printf("must supply a name\n");
319                                 return -1;
320                         }               
321                 }
322                 else if ( !StrnCaseCmp(argv[i], "comment", strlen("comment")) ) {
323                         fstrcpy( ntcomment, get_string_param( argv[i] ) );
324                         if ( !ntcomment[0] ) {
325                                 d_printf("must supply a comment string\n");
326                                 return -1;
327                         }                               
328                 }
329                 else if ( !StrnCaseCmp(argv[i], "unixgroup", strlen("unixgroup")) ) {
330                         fstrcpy( unixgrp, get_string_param( argv[i] ) );
331                         if ( !unixgrp[0] ) {
332                                 d_printf("must supply a group name\n");
333                                 return -1;
334                         }                               
335                 }
336                 else if ( !StrnCaseCmp(argv[i], "type", strlen("type")) )  {
337                         fstrcpy( type, get_string_param( argv[i] ) );
338                         switch ( type[0] ) {
339                                 case 'd':
340                                 case 'D':
341                                         sid_type = SID_NAME_DOM_GRP;
342                                         break;
343                                 case 'l':
344                                 case 'L':
345                                         sid_type = SID_NAME_ALIAS;
346                                         break;
347                         }
348                 }
349                 else {
350                         d_printf("Bad option: %s\n", argv[i]);
351                         return -1;
352                 }
353         }
354         
355         if ( !ntgroup[0] && !sid_string[0] ) {
356                 d_printf("Usage: net groupmap modify {ntgroup=<string>|sid=<SID>} [comment=<string>] [unixgroup=<string>] [type=<domain|local>]\n");
357                 return -1;
358         }
359
360         /* give preference to the SID; if both the ntgroup name and SID
361            are defined, use the SID and assume that the group name could be a 
362            new name */
363                 
364         if ( sid_string[0] ) {  
365                 if (!get_sid_from_input(&sid, sid_string)) {
366                         return -1;
367                 }
368         }
369         else {
370                 if (!get_sid_from_input(&sid, ntgroup)) {
371                         return -1;
372                 }
373         }       
374
375         /* Get the current mapping from the database */
376         if(!pdb_getgrsid(&map, sid)) {
377                 d_printf("Failure to local group SID in the database\n");
378                 return -1;
379         }
380         
381         /*
382          * Allow changing of group type only between domain and local
383          * We disallow changing Builtin groups !!! (SID problem)
384          */ 
385         if (sid_type != SID_NAME_UNKNOWN) { 
386                 if (map.sid_name_use == SID_NAME_WKN_GRP) {
387                         d_printf("You can only change between domain and local groups.\n");
388                         return -1;
389                 }
390                 
391                 map.sid_name_use=sid_type;
392         }
393
394         /* Change comment if new one */
395         if ( ntcomment[0] )
396                 fstrcpy( map.comment, ntcomment );
397                 
398         if ( ntgroup[0] )
399                 fstrcpy( map.nt_name, ntgroup );
400                 
401         if ( unixgrp[0] ) {
402                 gid = nametogid( unixgrp );
403                 if ( gid == -1 ) {
404                         d_printf("Unable to lookup UNIX group %s.  Make sure the group exists.\n",
405                                 unixgrp);
406                         return -1;
407                 }
408                 
409                 map.gid = gid;
410         }
411
412         if ( !pdb_update_group_mapping_entry(&map) ) {
413                 d_printf("Could not update group database\n");
414                 return -1;
415         }
416         
417         d_printf("Updated mapping entry for %s\n", map.nt_name);
418
419         return 0;
420 }
421
422 static int net_groupmap_delete(int argc, const char **argv)
423 {
424         DOM_SID sid;
425         fstring ntgroup = "";
426         fstring sid_string = "";
427         int i;
428
429         /* get the options */
430         for ( i=0; i<argc; i++ ) {
431                 if ( !StrnCaseCmp(argv[i], "ntgroup", strlen("ntgroup")) ) {
432                         fstrcpy( ntgroup, get_string_param( argv[i] ) );
433                         if ( !ntgroup[0] ) {
434                                 d_printf("must supply a name\n");
435                                 return -1;
436                         }               
437                 }
438                 else if ( !StrnCaseCmp(argv[i], "sid", strlen("sid")) ) {
439                         fstrcpy( sid_string, get_string_param( argv[i] ) );
440                         if ( !sid_string[0] ) {
441                                 d_printf("must supply a SID\n");
442                                 return -1;
443                         }               
444                 }
445                 else {
446                         d_printf("Bad option: %s\n", argv[i]);
447                         return -1;
448                 }
449         }
450         
451         if ( !ntgroup[0] && !sid_string[0]) {
452                 d_printf("Usage: net groupmap delete {ntgroup=<string>|sid=<SID>}\n");
453                 return -1;
454         }
455         
456         /* give preference to the SID if we have that */
457         
458         if ( sid_string[0] )
459                 fstrcpy( ntgroup, sid_string );
460                 
461         if ( !get_sid_from_input(&sid, ntgroup) ) {
462                 d_printf("Unable to resolve group %s to a SID\n", ntgroup);
463                 return -1;
464         }
465
466         if ( !pdb_delete_group_mapping_entry(sid) ) {
467                 printf("Failed to removing group %s from the mapping db!\n", ntgroup);
468                 return -1;
469         }
470
471         d_printf("Sucessfully removed %s from the mapping db\n", ntgroup);
472
473         return 0;
474 }
475
476 static int net_groupmap_set(int argc, const char **argv)
477 {
478         const char *ntgroup = NULL;
479         struct group *grp = NULL;
480         GROUP_MAP map;
481         BOOL have_map = False;
482
483         if ((argc < 1) || (argc > 2)) {
484                 d_printf("Usage: net groupmap set \"NT Group\" "
485                          "[\"unix group\"] [-C \"comment\"] [-L] [-D]\n");
486                 return -1;
487         }
488
489         if ( opt_localgroup && opt_domaingroup ) {
490                 d_printf("Can only specify -L or -D, not both\n");
491                 return -1;
492         }
493
494         ntgroup = argv[0];
495
496         if (argc == 2) {
497                 grp = getgrnam(argv[1]);
498
499                 if (grp == NULL) {
500                         d_printf("Could not find unix group %s\n", argv[1]);
501                         return -1;
502                 }
503         }
504
505         have_map = pdb_getgrnam(&map, ntgroup);
506
507         if (!have_map) {
508                 DOM_SID sid;
509                 have_map = ( (strncmp(ntgroup, "S-", 2) == 0) &&
510                              string_to_sid(&sid, ntgroup) &&
511                              pdb_getgrsid(&map, sid) );
512         }
513
514         if (!have_map) {
515
516                 /* Ok, add it */
517
518                 if (grp == NULL) {
519                         d_printf("Could not find group mapping for %s\n",
520                                  ntgroup);
521                         return -1;
522                 }
523
524                 map.gid = grp->gr_gid;
525
526                 if (opt_rid == 0) {
527                         opt_rid = pdb_gid_to_group_rid(map.gid);
528                 }
529
530                 sid_copy(&map.sid, get_global_sam_sid());
531                 sid_append_rid(&map.sid, opt_rid);
532
533                 map.sid_name_use = SID_NAME_DOM_GRP;
534                 fstrcpy(map.nt_name, ntgroup);
535                 fstrcpy(map.comment, "");
536
537                 if (!pdb_add_group_mapping_entry(&map)) {
538                         d_printf("Could not add mapping entry for %s\n",
539                                  ntgroup);
540                         return -1;
541                 }
542         }
543
544         /* Now we have a mapping entry, update that stuff */
545
546         if ( opt_localgroup || opt_domaingroup ) {
547                 if (map.sid_name_use == SID_NAME_WKN_GRP) {
548                         d_printf("Can't change type of the BUILTIN group %s\n",
549                                  map.nt_name);
550                         return -1;
551                 }
552         }
553
554         if (opt_localgroup)
555                 map.sid_name_use = SID_NAME_ALIAS;
556
557         if (opt_domaingroup)
558                 map.sid_name_use = SID_NAME_DOM_GRP;
559
560         /* The case (opt_domaingroup && opt_localgroup) was tested for above */
561
562         if (strlen(opt_comment) > 0)
563                 fstrcpy(map.comment, opt_comment);
564
565         if (strlen(opt_newntname) > 0)
566                 fstrcpy(map.nt_name, opt_newntname);
567
568         if (grp != NULL)
569                 map.gid = grp->gr_gid;
570
571         if (!pdb_update_group_mapping_entry(&map)) {
572                 d_printf("Could not update group mapping for %s\n", ntgroup);
573                 return -1;
574         }
575
576         return 0;
577 }
578
579 static int net_groupmap_cleanup(int argc, const char **argv)
580 {
581         GROUP_MAP *map = NULL;
582         int i, entries;
583
584         if (!pdb_enum_group_mapping(SID_NAME_UNKNOWN, &map, &entries,
585                                     ENUM_ALL_MAPPED)) {
586                 d_printf("Could not list group mappings\n");
587                 return -1;
588         }
589
590         for (i=0; i<entries; i++) {
591
592                 if (map[i].sid_name_use == SID_NAME_WKN_GRP)
593                         continue;
594
595                 if (map[i].gid == -1)
596                         printf("Group %s is not mapped\n", map[i].nt_name);
597
598                 if (!sid_check_is_in_our_domain(&map[i].sid)) {
599                         printf("Deleting mapping for NT Group %s, sid %s\n",
600                                map[i].nt_name,
601                                sid_string_static(&map[i].sid));
602                         pdb_delete_group_mapping_entry(map[i].sid);
603                 }
604         }
605
606         SAFE_FREE(map);
607
608         return 0;
609 }
610
611 static int net_groupmap_addmem(int argc, const char **argv)
612 {
613         DOM_SID alias, member;
614
615         if ( (argc != 2) || 
616              !string_to_sid(&alias, argv[0]) ||
617              !string_to_sid(&member, argv[1]) ) {
618                 d_printf("Usage: net groupmap addmem alias-sid member-sid\n");
619                 return -1;
620         }
621
622         if (!pdb_add_aliasmem(&alias, &member)) {
623                 d_printf("Could not add sid %s to alias %s\n",
624                          argv[1], argv[0]);
625                 return -1;
626         }
627
628         return 0;
629 }
630
631 static int net_groupmap_delmem(int argc, const char **argv)
632 {
633         DOM_SID alias, member;
634
635         if ( (argc != 2) || 
636              !string_to_sid(&alias, argv[0]) ||
637              !string_to_sid(&member, argv[1]) ) {
638                 d_printf("Usage: net groupmap delmem alias-sid member-sid\n");
639                 return -1;
640         }
641
642         if (!pdb_del_aliasmem(&alias, &member)) {
643                 d_printf("Could not delete sid %s from alias %s\n",
644                          argv[1], argv[0]);
645                 return -1;
646         }
647
648         return 0;
649 }
650
651 static int net_groupmap_listmem(int argc, const char **argv)
652 {
653         DOM_SID alias;
654         DOM_SID *members;
655         int i, num;
656         NTSTATUS result;
657
658         if ( (argc != 1) || 
659              !string_to_sid(&alias, argv[0]) ) {
660                 d_printf("Usage: net groupmap listmem alias-sid\n");
661                 return -1;
662         }
663
664         if (!pdb_enum_aliasmem(&alias, &members, &num)) {
665                 d_printf("Could not list members for sid %s: %s\n",
666                          argv[0], nt_errstr(result));
667                 return -1;
668         }
669
670         for (i = 0; i < num; i++) {
671                 printf("%s\n", sid_string_static(&(members[i])));
672         }
673
674         SAFE_FREE(members);
675
676         return 0;
677 }
678
679 static int net_groupmap_memberships(int argc, const char **argv)
680 {
681         DOM_SID member;
682         DOM_SID *aliases;
683         int i, num;
684         NTSTATUS result;
685
686         if ( (argc != 1) || 
687              !string_to_sid(&member, argv[0]) ) {
688                 d_printf("Usage: net groupmap memberof sid\n");
689                 return -1;
690         }
691
692         if (!pdb_enum_alias_memberships(&member, &aliases, &num)) {
693                 d_printf("Could not list memberships for sid %s: %s\n",
694                          argv[0], nt_errstr(result));
695                 return -1;
696         }
697
698         for (i = 0; i < num; i++) {
699                 printf("%s\n", sid_string_static(&(aliases[i])));
700         }
701
702         SAFE_FREE(aliases);
703
704         return 0;
705 }
706
707 int net_help_groupmap(int argc, const char **argv)
708 {
709         d_printf("net groupmap add"\
710                 "\n  Create a new group mapping\n");
711         d_printf("net groupmap modify"\
712                 "\n  Update a group mapping\n");
713         d_printf("net groupmap delete"\
714                 "\n  Remove a group mapping\n");
715         d_printf("net groupmap addmember"\
716                  "\n  Add a foreign alias member\n");
717         d_printf("net groupmap delmember"\
718                  "\n  Delete a foreign alias member\n");
719         d_printf("net groupmap listmembers"\
720                  "\n  List foreign group members\n");
721         d_printf("net groupmap memberships"\
722                  "\n  List foreign group memberships\n");
723         d_printf("net groupmap list"\
724                 "\n  List current group map\n");
725         d_printf("net groupmap set"\
726                 "\n  Set group mapping\n");
727         d_printf("net groupmap cleanup"\
728                 "\n  Remove foreign group mapping entries\n");
729         
730         return -1;
731 }
732
733
734 /***********************************************************
735  migrated functionality from smbgroupedit
736  **********************************************************/
737 int net_groupmap(int argc, const char **argv)
738 {
739         struct functable func[] = {
740                 {"add", net_groupmap_add},
741                 {"modify", net_groupmap_modify},
742                 {"delete", net_groupmap_delete},
743                 {"set", net_groupmap_set},
744                 {"cleanup", net_groupmap_cleanup},
745                 {"addmem", net_groupmap_addmem},
746                 {"delmem", net_groupmap_delmem},
747                 {"listmem", net_groupmap_listmem},
748                 {"memberships", net_groupmap_memberships},
749                 {"list", net_groupmap_list},
750                 {"help", net_help_groupmap},
751                 {NULL, NULL}
752         };
753
754         /* we shouldn't have silly checks like this */
755 #if 0
756         if (getuid() != 0) {
757                 d_printf("You must be root to edit group mappings.\nExiting...\n");
758                 return -1;
759         }
760 #endif
761         
762         if ( argc )
763                 return net_run_function(argc, argv, func, net_help_groupmap);
764
765         return net_help_groupmap( argc, argv );
766 }
767