Annotation of src/usr.bin/tcfs/tcfsrmgroup.c, Revision 1.3
1.1 provos 1: /*
2: * Transparent Cryptographic File System (TCFS) for NetBSD
3: * Author and mantainer: Luigi Catuogno [luicat@tcfs.unisa.it]
4: *
5: * references: http://tcfs.dia.unisa.it
6: * tcfs-bsd@tcfs.unisa.it
7: */
8:
9: /*
10: * Base utility set v0.1
11: */
12:
1.3 ! fgsch 13: #include <grp.h>
1.1 provos 14: #include <stdio.h>
1.3 ! fgsch 15: #include <stdlib.h>
1.1 provos 16:
17: #include <miscfs/tcfs/tcfs.h>
18: #include "tcfslib.h"
19: #include "tcfserrors.h"
20:
21: char *rmgroup_usage="Usage: %s [OPTION]...
22: Remove a TCFS group from the TCFS group database.
23:
24: -g <group> Specifies the TCFS group to be removed
25: -h Shows this help
26: -v Makes the output a little more verbose\n";
27:
28: int
29: rmgroup_main (int argn, char *argv[])
30: {
31: int index, val;
32: gid_t gid;
33: int have_gid = FALSE, be_verbose = FALSE;
34:
35: /*
36: * Going to check the arguments
37: */
38: while ((val = getopt(argn, argv, "hg:v")) != EOF)
39: switch (val) {
40: case 'g':
41: gid = (gid_t)atoi(optarg);
42: if (!gid && optarg[0] != '0') { /* group name given */
43: struct group *group_id;
44:
45: group_id=getgrnam(optarg);
46: if (!group_id)
47: tcfs_error (ER_CUSTOM, "Nonexistent group.");
48: gid=group_id->gr_gid;
49: }
50:
51: have_gid=TRUE;
52: break;
53: case 'h':
54: show_usage (rmgroup_usage, argv[0]);
55: exit (OK);
56: case 'v':
57: be_verbose=TRUE;
58: break;
59: default:
60: fprintf (stderr, "Try %s --help for more informations.\n", argv[0]);
61: exit (ER_UNKOPT);
62: }
63:
64: if (argn-optind)
65: tcfs_error (ER_UNKOPT, NULL);
66:
67: if (!have_gid) {
68: char *buff = NULL;
69: int len;
70:
71: buff = (char*)calloc(2048, sizeof(char));
72: if (!buff)
73: tcfs_error (ER_MEM, NULL);
74:
75: printf ("Group id of the TCFS group to remove from the database: ");
76: fgets (buff,2048,stdin);
1.2 provos 77: len = strlen(buff) - 1;
1.1 provos 78: buff[len] = buff[len] == '\n' ? 0 : buff[len];
79: gid=(gid_t)atoi(buff);
80:
81: if (!gid && optarg[0] != '0') { /* group name given */
82: struct group *group_id;
83:
84: group_id = getgrnam(optarg);
85: if (!group_id)
86: tcfs_error (ER_CUSTOM, "Nonexistent group.");
87: gid=group_id->gr_gid;
88: }
89:
90: if (gid <=0 )
91: tcfs_error (ER_CUSTOM, "A positive ID please!");
92:
93: free (buff);
94: }
95:
96: if (!tcfs_rmgroup (gid))
97: tcfs_error (ER_CUSTOM, "Wrong ID or an error as occurred.\n");
98: }