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