1 | /* |
---|
2 | * |
---|
3 | * Copyright (C) 1989 by the Massachusetts Institute of Technology |
---|
4 | * Developed by the MIT Student Information Processing Board (SIPB). |
---|
5 | * For copying information, see the file mit-copyright.h in this release. |
---|
6 | * |
---|
7 | */ |
---|
8 | /* |
---|
9 | * $Id: list_acl.c,v 1.14 2006-03-10 07:11:31 ghudson Exp $ |
---|
10 | * |
---|
11 | */ |
---|
12 | |
---|
13 | #ifndef lint |
---|
14 | static char rcsid_list_acl_c[] = |
---|
15 | "$Id: list_acl.c,v 1.14 2006-03-10 07:11:31 ghudson Exp $"; |
---|
16 | #endif /* lint */ |
---|
17 | |
---|
18 | #include <string.h> |
---|
19 | #include <stdio.h> |
---|
20 | #include <stdlib.h> |
---|
21 | #include <discuss/discuss.h> |
---|
22 | #include "globals.h" |
---|
23 | |
---|
24 | extern char *local_realm(); |
---|
25 | |
---|
26 | list_acl(argc, argv) |
---|
27 | int argc; |
---|
28 | char **argv; |
---|
29 | { |
---|
30 | dsc_acl *list; |
---|
31 | int code; |
---|
32 | char *modes; |
---|
33 | |
---|
34 | if (!dsc_public.attending) { |
---|
35 | (void) fprintf(stderr, "No current meeting.\n"); |
---|
36 | return; |
---|
37 | } |
---|
38 | /* |
---|
39 | * List access to current meeting. |
---|
40 | */ |
---|
41 | |
---|
42 | if (argc == 1) { |
---|
43 | /* long form; dump the access control list */ |
---|
44 | dsc_get_acl(&dsc_public.nb, &code, &list); |
---|
45 | if (code) { |
---|
46 | fprintf(stderr, "Can't read ACL: %s\n", |
---|
47 | error_message(code)); |
---|
48 | return; |
---|
49 | } |
---|
50 | print_acl(list); |
---|
51 | acl_destroy(list); |
---|
52 | } |
---|
53 | |
---|
54 | while(++argv,--argc) { |
---|
55 | dsc_get_access(&dsc_public.nb, *argv, &modes, &code); |
---|
56 | if (code) { |
---|
57 | fprintf(stderr, "Can't read ACL for %s: %s\n", |
---|
58 | *argv, error_message(code)); |
---|
59 | continue; |
---|
60 | } |
---|
61 | printf("%-10s %s\n", modes, *argv); |
---|
62 | free(modes); |
---|
63 | } |
---|
64 | return; |
---|
65 | } |
---|
66 | |
---|
67 | print_acl(list) |
---|
68 | dsc_acl *list; |
---|
69 | { |
---|
70 | register dsc_acl_entry *ae; |
---|
71 | register int n; |
---|
72 | for (ae = list->acl_entries, n = list->acl_length; n; --n, ++ae) |
---|
73 | printf("%-10s %s\n", ae->modes, ae->principal); |
---|
74 | } |
---|
75 | |
---|
76 | static char buf[120]; |
---|
77 | |
---|
78 | set_acl(argc, argv) |
---|
79 | int argc; |
---|
80 | register char **argv; |
---|
81 | { |
---|
82 | register char *modes, *principal; |
---|
83 | int code; |
---|
84 | |
---|
85 | |
---|
86 | if (!dsc_public.attending) { |
---|
87 | (void) fprintf(stderr, "No current meeting.\n"); |
---|
88 | return; |
---|
89 | } |
---|
90 | if (argc != 3) { |
---|
91 | printf("usage: %s [ modes | null ] principal \n", argv[0]); |
---|
92 | return; |
---|
93 | } |
---|
94 | if(!strcmp("null", argv[1])) modes = ""; |
---|
95 | else modes = argv[1]; |
---|
96 | |
---|
97 | if (strcmp(argv[2],"*") != 0 && strchr(argv[2], '@') == 0) { |
---|
98 | strcpy(buf, argv[2]); |
---|
99 | strcat(buf, "@"); |
---|
100 | strcat(buf, local_realm()); |
---|
101 | principal = buf; |
---|
102 | } else principal=argv[2]; |
---|
103 | |
---|
104 | dsc_set_access(&dsc_public.nb, principal, modes, &code); |
---|
105 | if(code) fprintf(stderr, "Can't set access for %s: %s\n", |
---|
106 | principal, error_message(code)); |
---|
107 | } |
---|
108 | |
---|
109 | del_acl(argc, argv) |
---|
110 | int argc; |
---|
111 | register char **argv; |
---|
112 | { |
---|
113 | int code; |
---|
114 | register char *principal; |
---|
115 | |
---|
116 | if (!dsc_public.attending) { |
---|
117 | (void) fprintf(stderr, "No current meeting.\n"); |
---|
118 | return; |
---|
119 | } |
---|
120 | if (argc < 2) { |
---|
121 | printf("usage: %s principal [ , principal ... ]\n", *argv); |
---|
122 | return; |
---|
123 | } |
---|
124 | |
---|
125 | while(++argv,--argc) { |
---|
126 | if (strcmp(*argv,"*") != 0 && strchr(*argv, '@') == 0) { |
---|
127 | strcpy(buf, *argv); |
---|
128 | strcat(buf, "@"); |
---|
129 | strcat(buf, local_realm()); |
---|
130 | principal = buf; |
---|
131 | } else principal = *argv; |
---|
132 | dsc_delete_access(&dsc_public.nb, principal, &code); |
---|
133 | if(code) fprintf(stderr, "Can't delete access of %s: %s\n", |
---|
134 | principal, error_message(code)); |
---|
135 | } |
---|
136 | } |
---|