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