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

Annotation of src/usr.bin/tcfs/tcfsflag.c, Revision 1.7

1.7     ! provos      1: /*     $OpenBSD: tcfsflag.c,v 1.6 2000/06/19 23:06:25 aaron Exp $      */
1.4       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 <errno.h>
                     17: #include <fcntl.h>
                     18: #include <sys/types.h>
                     19: #include <ctype.h>
                     20: #include <pwd.h>
                     21: #include <unistd.h>
                     22: #include <sys/param.h>
                     23: #include <sys/mount.h>
                     24: #include <sys/wait.h>
                     25:
                     26: #include <miscfs/tcfs/tcfs.h>
                     27: #include <miscfs/tcfs/tcfs_fileinfo.h>
                     28: #include "tcfsdefines.h"
                     29:
                     30: tcfs_flags tcfs_getflags(int);
1.5       aaron      31: tcfs_flags tcfs_setflags(int, tcfs_flags);
1.1       provos     32:
                     33: int
                     34: flags_main(int argc, char *argv[])
                     35: {
1.3       provos     36:        int fd, flag;
1.1       provos     37:        tcfs_flags i;
1.3       provos     38:        char cmd;
1.1       provos     39:
1.2       provos     40:        seteuid(getuid());
                     41:        setuid(getuid());
                     42:
1.1       provos     43:        if (argc < 3) {
1.5       aaron      44:                fprintf(stderr, "tcfsflags [op]{r,x,g} file\n"
1.3       provos     45:                         "\t op can either be + or -.\n\n");
1.1       provos     46:                exit(1);
                     47:        }
                     48:
1.5       aaron      49:        fd = open(argv[2], O_RDONLY);
1.1       provos     50:        if (!fd) {
                     51:                fprintf(stderr, "open failed\n");
                     52:                exit(1);
                     53:        }
                     54:
                     55:        i = tcfs_getflags(fd);
                     56:        if (i.flag == -1) {
1.5       aaron      57:                fprintf(stderr, "getflags error\n");
1.1       provos     58:                close(fd);
                     59:                exit(1);
                     60:        }
                     61:
1.3       provos     62:        if (argv[1][0] == '-' || argv[1][0] == '+') {
                     63:                cmd = argv[1][1];
                     64:                flag = argv[1][0] == '+' ? 1 : 0;
                     65:        } else {
                     66:                flag = -1;
                     67:                cmd = argv[1][0];
                     68:        }
                     69:
                     70:        switch(cmd) {
1.1       provos     71:        case 'r':
1.6       aaron      72:                printf("%s x:%d g:%d\n", argv[2], FI_CFLAG(&i), FI_GSHAR(&i));
1.1       provos     73:                exit(0);
                     74:        case 'x':
1.3       provos     75:                if (flag == -1)
                     76:                        flag = ~(FI_CFLAG(&i));;
                     77:                FI_SET_CF(&i, flag);
1.1       provos     78:                break;
                     79:        case 'g':
1.3       provos     80:                if (flag == -1)
                     81:                        flag = ~(FI_GSHAR(&i));
                     82:                FI_SET_GS(&i, flag);
1.1       provos     83:                break;
1.3       provos     84:        default:
                     85:                fprintf(stderr, "%s: unknown option: %c\n", argv[0], cmd);
                     86:                exit(1);
1.1       provos     87:        }
                     88:
1.2       provos     89:        i = tcfs_setflags(fd, i);
1.1       provos     90:        if (i.flag == -1) {
1.2       provos     91:                fprintf(stderr, "setflags error\n");
1.1       provos     92:                exit(1);
                     93:        }
                     94:        close(fd);
                     95:
                     96:        exit(0);
                     97: }
                     98: