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