File: [local] / src / usr.bin / tcfs / Attic / tcfsrun.c (download)
Revision 1.1.1.1 (vendor branch), Sun Jun 18 22:07:24 2000 UTC (23 years, 11 months ago) by provos
Branch: PROVOS001
CVS Tags: TCFS00 Changes since 1.1: +0 -0 lines
Initial import of very much rewritten TCFS userland. This code is still
nasty.
|
/*
* Transparent Cryptographic File System (TCFS) for NetBSD
* Author and mantainer: Luigi Catuogno [luicat@tcfs.unisa.it]
*
* references: http://tcfs.dia.unisa.it
* tcfs-bsd@tcfs.unisa.it
*/
/*
* Base utility set v0.1
*/
#include <stdio.h>
#include <sys/types.h>
#include <ctype.h>
#include <pwd.h>
#include <unistd.h>
#include <sys/param.h>
#include <sys/mount.h>
#include <sys/wait.h>
#include <des.h>
#include <miscfs/tcfs/tcfs.h>
char *cmd_def="/bin/sh";
char *run_usage = "usage: tcfsrun [-p mount-point | -f fs-label] [cmd] [args...]";
int
run_main(int argc, char *argv[], char *envp[])
{
char *key, *fs, *cmd, x;
char *args, fspath[MAXPATHLEN], cmdname[MAXPATHLEN];
uid_t uid;
pid_t pid;
int es,i = 1;
int havefspath = 0,havecmd = 0;
uid = getuid();
while ((x = getopt(argc,argv,"p:f:")) != EOF) {
switch(x) {
case 'p':
strlcpy(fspath, optarg, sizeof(fspath));
havefspath = 1;
break;
case 'f':
es = tcfs_getfspath(optarg,fspath);
if (!es) {
fprintf(stderr,
"filesystem label not found!\n");
exit(1);
}
havefspath=1;
break;
}
}
if (argc - optind) {
strlcpy(cmdname, argv[optind], sizeof(cmdname));
havecmd = 1;
cmd = cmdname;
}
if (!havefspath) {
es = tcfs_getfspath("default",fspath);
if (!es)
exit(1);
}
if (!havecmd)
cmd = cmd_def;
key = getpass("tcfs key:");
pid = fork();
if (!pid) {
pid = getpid();
if (tcfs_proc_enable(fspath, uid, pid, key) != -1) {
setuid(uid);
execve(cmd,argv + optind, envp);
}
fprintf(stderr, "Operation failed\n");
exit(1);
}
wait(0);
if (tcfs_proc_disable(fspath,uid,pid) == -1) {
fprintf (stderr, "Problems removing process key\n");
exit(1);
}
exit(0);
}