Annotation of src/usr.bin/tcfs/tcfs_getfspath.c, Revision 1.3
1.3 ! aaron 1: /* $OpenBSD: tcfs_getfspath.c,v 1.2 2000/06/19 20:35:47 fgsch Exp $ */
1.2 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 <stdio.h>
16: #include <strings.h>
17: #include <stdlib.h>
18: #include <fstab.h>
19:
20: #define WHITESPACE " \t\r\n"
21:
22: int
1.3 ! aaron 23: tcfs_label_getcipher(char *label)
1.1 provos 24: {
25: int ciphernum;
26:
1.3 ! aaron 27: if (tcfs_get_label(label, NULL, &ciphernum))
! 28: return (ciphernum);
1.1 provos 29:
30: return (-1);
31: }
32:
33: int
1.3 ! aaron 34: tcfs_getfspath(char *label2search, char *path)
1.1 provos 35: {
1.3 ! aaron 36: return (tcfs_get_label(label2search, path, NULL));
1.1 provos 37: }
38:
39: int
40: tcfs_get_label(char *label2search, char *path, int *ciphernumber)
41: {
42: FILE *fp;
43: char *label, *line, *p, *tag, *mountpoint, *cipherfield;
44: int found = 0;
45:
1.3 ! aaron 46: if ((fp = fopen(_PATH_FSTAB, "r")) == NULL)
1.1 provos 47: return (0);
48:
1.3 ! aaron 49: if ((line = (char *)malloc(1024)) == NULL)
1.1 provos 50: goto out;
51:
52: while (!feof(fp) && !found) {
53: p = line;
1.3 ! aaron 54: fgets(p, 1024, fp);
1.1 provos 55: p = p + strspn(p, WHITESPACE);
56: while (!found) {
57: strsep(&p, WHITESPACE); /* device */
58: if (p == NULL)
59: break;
60: p = p + strspn(p, WHITESPACE);
61: mountpoint = strsep(&p, WHITESPACE); /* mount point */
62: if (p == NULL)
63: break;
64: tag = strsep(&p, WHITESPACE); /* file system */
65: if (p == NULL || strcmp(tag, "tcfs"))
66: break;
67:
68: /* find the correct label */
69: label = strstr(p, "label=");
70: cipherfield = strstr(p, "cipher=");
71: if (label == NULL)
72: break;
73: p = label + 6;
74: label = strsep(&p, WHITESPACE ",");
75: if (!strlen(label) || strcmp(label, label2search))
76: break;
77:
78: if (path) {
79: strcpy(path, mountpoint);
80: found = 1;
81: }
82:
83: if (ciphernumber) {
84: if (cipherfield == NULL)
85: break;
86: p = cipherfield + 7;
87: cipherfield = strsep(&p, WHITESPACE ",");
88: if (!strlen(cipherfield))
89: break;
90:
91: *ciphernumber = strtol(cipherfield, &p, 0);
92: if (cipherfield != p)
93: found = 1;
94: }
95: }
96: }
97: free(line);
98: out:
1.3 ! aaron 99: fclose(fp);
1.1 provos 100:
101: return found;
102: }