Annotation of src/usr.bin/tcfs/tcfsrmkey.c, Revision 1.5
1.5 ! provos 1: /* $OpenBSD: tcfsrmkey.c,v 1.4 2000/06/19 22:42:29 aaron Exp $ */
1.3 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:
15: #include <sys/types.h>
1.2 fgsch 16: #include <sys/param.h>
17: #include <sys/mount.h>
1.1 provos 18: #include <ctype.h>
19: #include <pwd.h>
1.2 fgsch 20: #include <stdio.h>
21: #include <stdlib.h>
22: #include <string.h>
1.1 provos 23: #include <unistd.h>
24:
25: #include <miscfs/tcfs/tcfs.h>
26: #include "tcfslib.h"
27: #include "tcfserrors.h"
28: #include <grp.h>
29:
30: extern char *optarg;
31: extern int optind;
32: char *rmkey_usage=
33: "usage: tcfsrmkey [-f fliesystem-label][-g group][-p mount-point]\n";
34:
35: int
36: rmkey_main(int argc, char *argv[])
37: {
38: uid_t uid;
39: gid_t gid;
40: int es;
41: char x;
42: char fslabel[MAXPATHLEN], fspath[MAXPATHLEN];
43: int havempname = FALSE, havefsname = FALSE, isgroupkey = FALSE;
44: int havename = FALSE, havefspath = FALSE;
45:
1.4 aaron 46: while ((x = getopt(argc, argv, "f:p:g:")) != EOF) {
1.1 provos 47: switch(x) {
48: case 'p':
49: havempname = TRUE;
50: strlcpy(fspath, optarg, sizeof(fspath));
51: break;
52: case 'f':
53: havefsname = TRUE;
54: strlcpy(fslabel, optarg, sizeof(fslabel));
55: break;
56: case 'g':
57: isgroupkey = TRUE;
58: gid = atoi(optarg);
59: if (!gid && optarg[0] != 0) {
60: struct group *grp;
61: grp = (struct group *)getgrnam(optarg);
62: if (!grp)
63: tcfs_error(ER_CUSTOM,
64: "Nonexistant group\n");
65: gid = grp->gr_gid;
66: }
67: break;
68: default:
69: tcfs_error(ER_CUSTOM, rmkey_usage);
70: exit(ER_UNKOPT);
71: }
72: }
73: if (argc-optind)
1.4 aaron 74: tcfs_error(ER_UNKOPT, NULL);
1.1 provos 75:
76: if (havefsname && havempname) {
77: tcfs_error(ER_CUSTOM, rmkey_usage);
78: exit(1);
79: }
80:
81: if (havefsname) {
82: es = tcfs_getfspath(fslabel, fspath);
83: havename = TRUE;
84: }
85:
86: if (havefspath)
87: havename = TRUE;
88:
89: if (!havename)
1.4 aaron 90: es = tcfs_getfspath("default", fspath);
1.1 provos 91:
92: if(!es) {
1.4 aaron 93: tcfs_error(ER_CUSTOM, "fs-label not found!\n");
1.1 provos 94: exit(1);
95: }
96:
97: uid = getuid();
98:
99: if (isgroupkey) {
1.4 aaron 100: es = tcfs_group_disable(fspath, uid, gid);
1.1 provos 101: if(es == -1)
102: tcfs_error(ER_CUSTOM, "problems updating filesystem");
103: exit(0);
104: }
105:
1.4 aaron 106: es = tcfs_user_disable(fspath, uid);
1.1 provos 107:
108: if (es == -1)
1.4 aaron 109: tcfs_error(ER_CUSTOM, "problems updating filesystem");
1.1 provos 110:
111: exit(0);
112: }