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

Annotation of src/usr.bin/tcfs/tcfs_getfspath.c, Revision 1.6

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