summaryrefslogtreecommitdiff
path: root/usr.bin/tcfs/tcfsrun.c
diff options
context:
space:
mode:
authorNiels Provos <provos@cvs.openbsd.org>2000-06-18 22:07:26 +0000
committerNiels Provos <provos@cvs.openbsd.org>2000-06-18 22:07:26 +0000
commit48893562fdfa12c4f376d2556da18e817a34484f (patch)
tree033e9aaa47f5617ba6ffbcf7e071ffb8f8f71b07 /usr.bin/tcfs/tcfsrun.c
parent47bc7a26b81967e77c0f021899f1544966df67e2 (diff)
Initial import of very much rewritten TCFS userland. This code is still
nasty.
Diffstat (limited to 'usr.bin/tcfs/tcfsrun.c')
-rw-r--r--usr.bin/tcfs/tcfsrun.c96
1 files changed, 96 insertions, 0 deletions
diff --git a/usr.bin/tcfs/tcfsrun.c b/usr.bin/tcfs/tcfsrun.c
new file mode 100644
index 00000000000..0010561f9ba
--- /dev/null
+++ b/usr.bin/tcfs/tcfsrun.c
@@ -0,0 +1,96 @@
+/*
+ * 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);
+}
+
+