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