1 | /********************************************************************** |
---|
2 | * File Exchange access control list client |
---|
3 | * |
---|
4 | * $Id: fxblanche.c,v 1.1 1999-09-28 22:10:57 danw Exp $ |
---|
5 | * |
---|
6 | * Copyright 1989, 1990 by the Massachusetts Institute of Technology. |
---|
7 | * |
---|
8 | * For copying and distribution information, please see the file |
---|
9 | * <mit-copyright.h>. |
---|
10 | **********************************************************************/ |
---|
11 | |
---|
12 | #include <mit-copyright.h> |
---|
13 | |
---|
14 | #ifndef lint |
---|
15 | static char rcsid_fxblanche_c[] = "$Id: fxblanche.c,v 1.1 1999-09-28 22:10:57 danw Exp $"; |
---|
16 | #endif /* lint */ |
---|
17 | |
---|
18 | #include <stdio.h> |
---|
19 | #include <fx/fxcl.h> |
---|
20 | #include <ctype.h> |
---|
21 | #include <string.h> |
---|
22 | |
---|
23 | FX * |
---|
24 | open_course(course, module) |
---|
25 | char *course, *module; |
---|
26 | { |
---|
27 | FX *fxp; |
---|
28 | long code; |
---|
29 | |
---|
30 | if (!course) { |
---|
31 | fprintf(stderr, "%s: No course specified.\n", module); |
---|
32 | exit(1); |
---|
33 | } |
---|
34 | fxp = fx_open(course, &code); |
---|
35 | if (code) com_err(module, code, "(%s)", course); |
---|
36 | if (fxp == NULL) exit(1); |
---|
37 | return(fxp); |
---|
38 | } |
---|
39 | |
---|
40 | void |
---|
41 | show_list(fxp, course, module, acl, verbose) |
---|
42 | FX *fxp; |
---|
43 | char *course, *module, *acl; |
---|
44 | int verbose; |
---|
45 | { |
---|
46 | stringlist_res *sr; |
---|
47 | stringlist l; |
---|
48 | long code; |
---|
49 | |
---|
50 | if (!fxp) fxp = open_course(course, module); |
---|
51 | code = fx_acl_list(fxp, acl, &sr); |
---|
52 | if (code) { |
---|
53 | com_err(module, code, "(%s)", acl); |
---|
54 | exit(1); |
---|
55 | } |
---|
56 | if (verbose) printf("Members of the %s list for %s:\n", acl, course); |
---|
57 | l = sr->stringlist_res_u.list; |
---|
58 | while(l) { |
---|
59 | if (verbose) printf("\t%s\n", full_name(l->s)); |
---|
60 | else printf("%s\n", l->s); |
---|
61 | l = l->next; |
---|
62 | } |
---|
63 | return; |
---|
64 | } |
---|
65 | |
---|
66 | main(argc, argv) |
---|
67 | int argc; |
---|
68 | char *argv[]; |
---|
69 | { |
---|
70 | FX *fxp = NULL; |
---|
71 | long code; |
---|
72 | char *acl; |
---|
73 | int i; |
---|
74 | char *course; |
---|
75 | int specified = 0, verbose = 1; |
---|
76 | static char USAGE[] = "Usage: %s course [options]\n"; |
---|
77 | |
---|
78 | course = (char *) getenv("COURSE"); |
---|
79 | acl = ACL_GRADER; |
---|
80 | |
---|
81 | for (i=1; i<argc; i++) { |
---|
82 | if (argv[i][0] == '-') { |
---|
83 | switch(argv[i][1]) { |
---|
84 | case 'c': |
---|
85 | course = argv[++i]; |
---|
86 | if (fxp) { |
---|
87 | fx_close(fxp); |
---|
88 | fxp = NULL; |
---|
89 | } |
---|
90 | break; |
---|
91 | case 'a': |
---|
92 | specified++; |
---|
93 | if (!fxp) fxp = open_course(course, argv[0]); |
---|
94 | code = fx_acl_add(fxp, acl, argv[++i]); |
---|
95 | if (code) { |
---|
96 | com_err(argv[0], code, "(%s %s)", acl, argv[i]); |
---|
97 | exit(1); |
---|
98 | } |
---|
99 | if (verbose) |
---|
100 | printf("Added %s to the %s list for %s.\n", |
---|
101 | full_name(argv[i]), acl, course); |
---|
102 | break; |
---|
103 | case 'd': |
---|
104 | specified++; |
---|
105 | if (!fxp) fxp = open_course(course, argv[0]); |
---|
106 | code = fx_acl_del(fxp, acl, argv[++i]); |
---|
107 | if (code) { |
---|
108 | com_err(argv[0], code, "(%s %s)", acl, argv[i]); |
---|
109 | exit(1); |
---|
110 | } |
---|
111 | if (verbose) |
---|
112 | printf("Deleted %s from the %s list for %s.\n", |
---|
113 | full_name(argv[i]), acl, course); |
---|
114 | break; |
---|
115 | case 'm': |
---|
116 | specified++; |
---|
117 | show_list(fxp, course, argv[0], acl, verbose); |
---|
118 | break; |
---|
119 | case 'l': |
---|
120 | acl = argv[++i]; |
---|
121 | break; |
---|
122 | case 'q': |
---|
123 | verbose = 0; |
---|
124 | break; |
---|
125 | case 'v': |
---|
126 | verbose = 1; |
---|
127 | break; |
---|
128 | default: |
---|
129 | fprintf(stderr, USAGE, argv[0]); |
---|
130 | break; |
---|
131 | } |
---|
132 | continue; |
---|
133 | } |
---|
134 | course = argv[i]; |
---|
135 | } |
---|
136 | if (!specified) show_list(fxp, course, argv[0], acl, verbose); |
---|
137 | exit(0); |
---|
138 | } |
---|