Annotation of src/usr.bin/tcfs/tcfsrun.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:
13: #include <stdio.h>
14: #include <sys/types.h>
15: #include <ctype.h>
16: #include <pwd.h>
17: #include <unistd.h>
18: #include <sys/param.h>
19: #include <sys/mount.h>
20: #include <sys/wait.h>
21: #include <des.h>
22:
23: #include <miscfs/tcfs/tcfs.h>
24:
25: char *cmd_def="/bin/sh";
26: char *run_usage = "usage: tcfsrun [-p mount-point | -f fs-label] [cmd] [args...]";
27:
28: int
29: run_main(int argc, char *argv[], char *envp[])
30: {
31: char *key, *fs, *cmd, x;
32: char *args, fspath[MAXPATHLEN], cmdname[MAXPATHLEN];
33: uid_t uid;
34: pid_t pid;
35: int es,i = 1;
36: int havefspath = 0,havecmd = 0;
37:
38: uid = getuid();
39:
40: while ((x = getopt(argc,argv,"p:f:")) != EOF) {
41: switch(x) {
42: case 'p':
43: strlcpy(fspath, optarg, sizeof(fspath));
44: havefspath = 1;
45: break;
46: case 'f':
47: es = tcfs_getfspath(optarg,fspath);
48: if (!es) {
49: fprintf(stderr,
50: "filesystem label not found!\n");
51: exit(1);
52: }
53: havefspath=1;
54: break;
55: }
56: }
57:
58: if (argc - optind) {
59: strlcpy(cmdname, argv[optind], sizeof(cmdname));
60: havecmd = 1;
61: cmd = cmdname;
62: }
63:
64: if (!havefspath) {
65: es = tcfs_getfspath("default",fspath);
66: if (!es)
67: exit(1);
68: }
69:
70: if (!havecmd)
71: cmd = cmd_def;
72:
73: key = getpass("tcfs key:");
74:
75: pid = fork();
76: if (!pid) {
77: pid = getpid();
78: if (tcfs_proc_enable(fspath, uid, pid, key) != -1) {
79: setuid(uid);
80: execve(cmd,argv + optind, envp);
81: }
82:
83: fprintf(stderr, "Operation failed\n");
84: exit(1);
85: }
86:
87: wait(0);
88:
89: if (tcfs_proc_disable(fspath,uid,pid) == -1) {
90: fprintf (stderr, "Problems removing process key\n");
91: exit(1);
92: }
93: exit(0);
94: }
95:
96: