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