Annotation of src/usr.bin/tcfs/tcfsrmgroup.c, Revision 1.7
1.7 ! aaron 1: /* $OpenBSD: tcfsrmgroup.c,v 1.6 2000/06/19 22:42:29 aaron Exp $ */
1.4 fgsch 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
1.6 aaron 31: rmgroup_main(int argn, char *argv[])
1.1 provos 32: {
1.5 fgsch 33: int val;
1.1 provos 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:
1.6 aaron 47: group_id = getgrnam(optarg);
1.1 provos 48: if (!group_id)
1.6 aaron 49: tcfs_error(ER_CUSTOM, "Nonexistent group.");
50: gid = group_id->gr_gid;
1.1 provos 51: }
52:
1.6 aaron 53: have_gid = TRUE;
1.1 provos 54: break;
55: case 'h':
1.6 aaron 56: show_usage(rmgroup_usage, argv[0]);
57: exit(OK);
1.1 provos 58: case 'v':
1.6 aaron 59: be_verbose = TRUE;
1.1 provos 60: break;
61: default:
1.7 ! aaron 62: fprintf(stderr,
! 63: "Try %s --help for more informations.\n", argv[0]);
1.6 aaron 64: exit(ER_UNKOPT);
1.1 provos 65: }
66:
1.6 aaron 67: if (argn - optind)
68: tcfs_error(ER_UNKOPT, NULL);
1.1 provos 69:
70: if (!have_gid) {
71: char *buff = NULL;
72: int len;
73:
1.7 ! aaron 74: buff = (char *)calloc(2048, sizeof(char));
1.1 provos 75: if (!buff)
1.6 aaron 76: tcfs_error(ER_MEM, NULL);
1.1 provos 77:
1.7 ! aaron 78: printf("Group ID of the TCFS group to remove from the database: ");
1.6 aaron 79: fgets(buff, 2048, stdin);
1.2 provos 80: len = strlen(buff) - 1;
1.1 provos 81: buff[len] = buff[len] == '\n' ? 0 : buff[len];
1.6 aaron 82: gid = (gid_t)atoi(buff);
1.1 provos 83:
84: if (!gid && optarg[0] != '0') { /* group name given */
85: struct group *group_id;
86:
87: group_id = getgrnam(optarg);
88: if (!group_id)
1.6 aaron 89: tcfs_error(ER_CUSTOM, "Nonexistent group.");
90: gid = group_id->gr_gid;
1.1 provos 91: }
92:
1.6 aaron 93: if (gid <= 0)
94: tcfs_error(ER_CUSTOM, "A positive ID please!");
1.1 provos 95:
1.6 aaron 96: free(buff);
1.1 provos 97: }
98:
1.6 aaron 99: if (!tcfs_rmgroup(gid))
100: tcfs_error(ER_CUSTOM, "Wrong ID or an error as occurred.\n");
1.1 provos 101: }