[BACK]Return to tcfsrun.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / tcfs

Annotation of src/usr.bin/tcfs/tcfsrun.c, Revision 1.9

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