Annotation of src/usr.bin/tcfs/tcfsputkey.c, Revision 1.1.1.1
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: * $Source: /usr/src/tcfs-utils_0.1/bin/RCS/tcfsputkey.c,v $
13: * $State: Exp $
14: * $Revision: 1.1 $
15: * $Author: luicat $
16: * $Date: 2000/01/14 13:44:04 $
17: *
18: */
19:
20: static const char *RCSid="$id: $";
21:
22: /* RCS_HEADER_ENDS_HERE */
23:
24:
25:
26: #include <stdio.h>
27: #include <sys/types.h>
28: #include <sys/param.h>
29: #include <ctype.h>
30: #include <pwd.h>
31: #include <unistd.h>
32: #include <sys/param.h>
33: #include <sys/mount.h>
34: #include <des.h>
35:
36: #include <miscfs/tcfs/tcfs.h>
37: #include "tcfslib.h"
38: #include "tcfserrors.h"
39: #include <grp.h>
40:
41: extern char *optarg;
42: extern int optind;
43: char *putkey_usage=
44: "usage: tcfsputkey [-k][-f fliesystem-label][-g group][-p mount-point]\n";
45:
46: int
47: putkey_main(int argc, char *argv[])
48: {
49: u_char *key,*fs,*user,*password,*tcfskey;
50: uid_t uid;
51: gid_t gid;
52: int es, treshold;
53: char x;
54: tcfspwdb *info;
55: tcfsgpwdb *ginfo;
56: char fslabel[MAXPATHLEN], fspath[MAXPATHLEN];
57: int def = TRUE, havempname = FALSE, havefsname = FALSE;
58: int isgroupkey = FALSE;
59: int havefs = FALSE;
60: int havename = FALSE, havefspath = FALSE, havekey = FALSE;
61:
62: while ((x = getopt(argc,argv,"kf:p:g:")) != EOF) {
63: switch(x) {
64: case 'k':
65: def = FALSE;
66: break;
67: case 'p':
68: havempname = TRUE;
69: strlcpy(fspath, optarg, sizeof(fspath));
70: break;
71: case 'f':
72: havefsname = TRUE;
73: strlcpy(fslabel, optarg, sizeof(fslabel));
74: break;
75: case 'g':
76: isgroupkey = TRUE;
77: def = TRUE;
78: gid = atoi(optarg);
79: if (!gid && optarg[0] != 0) {
80: struct group *grp;
81: grp = (struct group *)getgrnam(optarg);
82: if (!grp)
83: tcfs_error(ER_CUSTOM, "Nonexistant group\n");
84: gid = grp->gr_gid;
85: }
86: break;
87: default:
88: tcfs_error(ER_CUSTOM, putkey_usage);
89: exit(ER_UNKOPT);
90: }
91: }
92: if (argc - optind)
93: tcfs_error(ER_UNKOPT,NULL);
94:
95: if (havefsname && havempname) {
96: tcfs_error(ER_CUSTOM, putkey_usage);
97: exit(1);
98: }
99:
100: if (havefsname) {
101: es=tcfs_getfspath(fslabel,fspath);
102: havename = TRUE;
103: }
104:
105: if (havefspath)
106: havename = TRUE;
107:
108: if (!havename)
109: es=tcfs_getfspath("default",fspath);
110:
111: if (!es) {
112: tcfs_error(ER_CUSTOM,"fs-label not found!\n");
113: exit(1);
114: }
115:
116: uid = getuid();
117:
118: if (isgroupkey) {
119: if (!unix_auth(&user,&password,TRUE))
120: tcfs_error(ER_AUTH,user);
121:
122: if (!tcfsgpwdbr_new(&ginfo))
123: tcfs_error(ER_MEM,NULL);
124:
125: if (!tcfs_ggetpwnam(user,gid,&ginfo))
126: tcfs_error(ER_CUSTOM,"Default key non found");
127:
128: if (!strlen(ginfo->gkey))
129: tcfs_error(ER_CUSTOM,"Invalid default key");
130:
131: tcfskey = (char*)malloc(UUKEYSIZE);
132: if (!tcfskey)
133: tcfs_error(ER_MEM,NULL);
134:
135: treshold = ginfo->soglia;
136:
137: tcfs_decrypt_key(user, password, ginfo->gkey, tcfskey,
138: GROUPKEY);
139:
140: es = tcfs_group_enable(fspath,uid,gid,treshold,tcfskey);
141:
142: if(es == -1) {
143: tcfs_error(ER_CUSTOM,"problems updating filesystem");
144: }
145:
146: exit(0);
147: }
148:
149:
150: if(!def) {
151: tcfskey = getpass("Insert tcfs-key:");
152: havekey = TRUE;
153: } else {
154: if(!unix_auth(&user,&password,TRUE))
155: tcfs_error(ER_AUTH,user);
156:
157: if(!tcfspwdbr_new(&info))
158: tcfs_error(ER_MEM,NULL);
159:
160: if(!tcfs_getpwnam(user,&info))
161: tcfs_error(ER_CUSTOM,"Default key non found");
162:
163: if(!strlen(info->upw))
164: tcfs_error(ER_CUSTOM,"Invalid default key");
165:
166: tcfskey = (char*)malloc(UUKEYSIZE);
167: if(!tcfskey)
168: tcfs_error(ER_MEM,NULL);
169:
170: tcfs_decrypt_key (user, password, info->upw, tcfskey, USERKEY);
171: havekey = TRUE;
172: }
173:
174: es = tcfs_user_enable(fspath, uid, tcfskey);
175:
176: if(es == -1)
177: tcfs_error(ER_CUSTOM,"problems updating filesystem");
178:
179: exit(0);
180: }