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