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