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