summaryrefslogtreecommitdiff
path: root/usr.bin/tcfs/tcfs_getfspath.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/tcfs_getfspath.c
parent47bc7a26b81967e77c0f021899f1544966df67e2 (diff)
Initial import of very much rewritten TCFS userland. This code is still
nasty.
Diffstat (limited to 'usr.bin/tcfs/tcfs_getfspath.c')
-rw-r--r--usr.bin/tcfs/tcfs_getfspath.c101
1 files changed, 101 insertions, 0 deletions
diff --git a/usr.bin/tcfs/tcfs_getfspath.c b/usr.bin/tcfs/tcfs_getfspath.c
new file mode 100644
index 00000000000..0774fa95adb
--- /dev/null
+++ b/usr.bin/tcfs/tcfs_getfspath.c
@@ -0,0 +1,101 @@
+/* $OpenBSD: tcfs_getfspath.c,v 1.1 2000/06/18 22:07:24 provos Exp $ */
+/*
+ * 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 <strings.h>
+#include <stdlib.h>
+#include <fstab.h>
+
+#define WHITESPACE " \t\r\n"
+
+int
+tcfs_label_getcipher (char *label)
+{
+ int ciphernum;
+
+ if (tcfs_get_label (label, NULL, &ciphernum))
+ return ciphernum;
+
+ return (-1);
+}
+
+int
+tcfs_getfspath (char *label2search, char *path)
+{
+ return tcfs_get_label (label2search, path, NULL);
+}
+
+int
+tcfs_get_label(char *label2search, char *path, int *ciphernumber)
+{
+ FILE *fp;
+ char *label, *line, *p, *tag, *mountpoint, *cipherfield;
+ int found = 0;
+
+ if ((fp = fopen(_PATH_FSTAB,"r")) == NULL)
+ return (0);
+
+ if ((line = calloc(1024, sizeof(char))) == NULL)
+ goto out;
+
+ while (!feof(fp) && !found) {
+ p = line;
+ fgets (p, 1024, fp);
+ p = p + strspn(p, WHITESPACE);
+ while (!found) {
+ strsep(&p, WHITESPACE); /* device */
+ if (p == NULL)
+ break;
+ p = p + strspn(p, WHITESPACE);
+ mountpoint = strsep(&p, WHITESPACE); /* mount point */
+ if (p == NULL)
+ break;
+ tag = strsep(&p, WHITESPACE); /* file system */
+ if (p == NULL || strcmp(tag, "tcfs"))
+ break;
+
+ /* find the correct label */
+ label = strstr(p, "label=");
+ cipherfield = strstr(p, "cipher=");
+ if (label == NULL)
+ break;
+ p = label + 6;
+ label = strsep(&p, WHITESPACE ",");
+ if (!strlen(label) || strcmp(label, label2search))
+ break;
+
+ if (path) {
+ strcpy(path, mountpoint);
+ found = 1;
+ }
+
+ if (ciphernumber) {
+ if (cipherfield == NULL)
+ break;
+ p = cipherfield + 7;
+ cipherfield = strsep(&p, WHITESPACE ",");
+ if (!strlen(cipherfield))
+ break;
+
+ *ciphernumber = strtol(cipherfield, &p, 0);
+ if (cipherfield != p)
+ found = 1;
+ }
+ }
+ }
+ free(line);
+ out:
+ fclose (fp);
+
+ return found;
+}