]>
Commit | Line | Data |
---|---|---|
703082ea | 1 | /* $Header$ |
2 | * | |
3 | * Zephyr ACL routines for the Moira client | |
4 | * | |
5 | * Copyright 1990 by the Massachusetts Institute of Technology. | |
5eaef520 | 6 | * |
703082ea | 7 | * For further information on copyright and distribution see the |
8 | * file mit-copyright.h | |
9 | */ | |
10 | ||
11 | #include <stdio.h> | |
24419c79 | 12 | #include <string.h> |
703082ea | 13 | #include <ctype.h> |
14 | #include <moira.h> | |
15 | #include <moira_site.h> | |
16 | #include <menu.h> | |
17 | #include <mit-copyright.h> | |
18 | ||
19 | #include "defs.h" | |
20 | #include "f_defs.h" | |
21 | #include "globals.h" | |
22 | ||
23 | ||
24 | /* Set the default values for zephyr additions. */ | |
25 | ||
5eaef520 | 26 | static char **SetDefaults(char **info, char *name) |
703082ea | 27 | { |
5eaef520 | 28 | info[ZA_CLASS] = strsave(name); |
29 | info[ZA_XMT_TYPE] = strsave("LIST"); | |
30 | info[ZA_SUB_TYPE] = strsave("LIST"); | |
31 | info[ZA_IWS_TYPE] = strsave("LIST"); | |
32 | info[ZA_IUI_TYPE] = strsave("LIST"); | |
33 | info[ZA_XMT_ID] = strsave("empty"); | |
34 | info[ZA_SUB_ID] = strsave("empty"); | |
35 | info[ZA_IWS_ID] = strsave("empty"); | |
36 | info[ZA_IUI_ID] = strsave("empty"); | |
37 | info[ZA_MODTIME] = info[ZA_MODBY] = info[ZA_MODWITH] = NULL; | |
38 | info[ZA_END] = NULL; | |
39 | return info; | |
703082ea | 40 | } |
41 | ||
42 | ||
43 | /* Get info from database */ | |
44 | ||
5eaef520 | 45 | static struct qelem *GetZephyrInfo(char *name) |
703082ea | 46 | { |
5eaef520 | 47 | int stat; |
48 | struct qelem *elem = NULL; | |
49 | ||
50 | if ((stat = do_mr_query("get_zephyr_class", 1, &name, StoreInfo, | |
51 | (char *)&elem))) | |
52 | { | |
53 | com_err(program_name, stat, " in GetZephyrInfo"); | |
54 | return NULL; | |
703082ea | 55 | } |
5eaef520 | 56 | return QueueTop(elem); |
703082ea | 57 | } |
58 | ||
59 | ||
60 | /* Print zephyr acl info */ | |
61 | ||
5eaef520 | 62 | static void PrintZephyrInfo(char **info) |
703082ea | 63 | { |
5eaef520 | 64 | char buf[BUFSIZ]; |
703082ea | 65 | |
5eaef520 | 66 | if (!info) |
67 | { | |
68 | Put_message("PrintZephyrInfo called with null info!"); | |
69 | return; | |
703082ea | 70 | } |
5eaef520 | 71 | sprintf(buf, " Zephyr class: %s", info[ZA_CLASS]); |
72 | Put_message(buf); | |
73 | if (!strcmp(info[ZA_XMT_ID], "WILDCARD")) | |
74 | { | |
75 | free(info[ZA_XMT_ID]); | |
76 | info[ZA_XMT_ID] = strsave("*.*@*"); | |
703082ea | 77 | } |
5eaef520 | 78 | sprintf(buf, "Transmit ACL: %s %s", info[ZA_XMT_TYPE], |
79 | strcasecmp(info[ZA_XMT_TYPE], "NONE") ? info[ZA_XMT_ID] : ""); | |
80 | Put_message(buf); | |
81 | if (!strcmp(info[ZA_SUB_ID], "WILDCARD")) | |
82 | { | |
83 | free(info[ZA_SUB_ID]); | |
84 | info[ZA_SUB_ID] = strsave("*.*@*"); | |
703082ea | 85 | } |
5eaef520 | 86 | sprintf(buf, "Subscription ACL: %s %s", info[ZA_SUB_TYPE], |
87 | strcasecmp(info[ZA_SUB_TYPE], "NONE") ? info[ZA_SUB_ID] : ""); | |
88 | Put_message(buf); | |
89 | if (!strcmp(info[ZA_IWS_ID], "WILDCARD")) | |
90 | { | |
91 | free(info[ZA_IWS_ID]); | |
92 | info[ZA_IWS_ID] = strsave("*.*@*"); | |
703082ea | 93 | } |
5eaef520 | 94 | sprintf(buf, "Instance Wildcard ACL: %s %s", info[ZA_IWS_TYPE], |
95 | strcasecmp(info[ZA_IWS_TYPE], "NONE") ? info[ZA_IWS_ID] : ""); | |
96 | Put_message(buf); | |
97 | if (!strcmp(info[ZA_IUI_ID], "WILDCARD")) | |
98 | { | |
99 | free(info[ZA_IUI_ID]); | |
100 | info[ZA_IUI_ID] = strsave("*.*@*"); | |
703082ea | 101 | } |
5eaef520 | 102 | sprintf(buf, "Instance Indentity ACL: %s %s", info[ZA_IUI_TYPE], |
103 | strcasecmp(info[ZA_IUI_TYPE], "NONE") ? info[ZA_IUI_ID] : ""); | |
104 | Put_message(buf); | |
105 | sprintf(buf, MOD_FORMAT, info[ZA_MODBY], info[ZA_MODTIME], info[ZA_MODWITH]); | |
106 | Put_message(buf); | |
703082ea | 107 | } |
108 | ||
109 | ||
110 | /* Get info from user. Expects info to already be filled in with defaults */ | |
111 | ||
5eaef520 | 112 | static char **AskZephyrInfo(char **info, Bool rename) |
703082ea | 113 | { |
5eaef520 | 114 | char buf[BUFSIZ], *newname; |
115 | ||
116 | Put_message(""); | |
117 | sprintf(buf, "Zephyr class restrictions for %s.", info[ZA_CLASS]); | |
118 | Put_message(buf); | |
119 | Put_message(""); | |
120 | ||
121 | if (rename) | |
122 | { | |
123 | while (1) | |
124 | { | |
125 | newname = Strsave(info[ZA_CLASS]); | |
126 | if (GetValueFromUser("The new name for this class", &newname) == | |
127 | SUB_ERROR) | |
128 | return NULL; | |
129 | if (ValidName(newname)) | |
130 | break; | |
131 | } | |
703082ea | 132 | } |
133 | ||
5eaef520 | 134 | if (GetTypeFromUser("What kind of transmit restriction", "ace_type", |
135 | &info[ZA_XMT_TYPE]) == SUB_ERROR) | |
136 | return NULL; | |
137 | if (strcasecmp(info[ZA_XMT_TYPE], "NONE")) | |
138 | { | |
139 | if (!strcmp(info[ZA_XMT_ID], "WILDCARD")) | |
140 | { | |
141 | free(info[ZA_XMT_ID]); | |
142 | info[ZA_XMT_ID] = strsave("*.*@*"); | |
703082ea | 143 | } |
5eaef520 | 144 | sprintf(buf, "Which %s: ", info[ZA_XMT_TYPE]); |
145 | if (GetValueFromUser(buf, &info[ZA_XMT_ID]) == SUB_ERROR) | |
146 | return NULL; | |
147 | if (!strcmp(info[ZA_XMT_ID], "*.*@*")) | |
148 | { | |
149 | free(info[ZA_XMT_ID]); | |
150 | info[ZA_XMT_ID] = strsave("WILDCARD"); | |
703082ea | 151 | } |
152 | } | |
5eaef520 | 153 | if (GetTypeFromUser("What kind of subscription restriction", "ace_type", |
154 | &info[ZA_SUB_TYPE]) == SUB_ERROR) | |
155 | return NULL; | |
156 | if (strcasecmp(info[ZA_SUB_TYPE], "NONE")) | |
157 | { | |
158 | if (!strcmp(info[ZA_SUB_ID], "WILDCARD")) | |
159 | { | |
160 | free(info[ZA_SUB_ID]); | |
161 | info[ZA_SUB_ID] = strsave("*.*@*"); | |
703082ea | 162 | } |
5eaef520 | 163 | sprintf(buf, "Which %s: ", info[ZA_SUB_TYPE]); |
164 | if (GetValueFromUser(buf, &info[ZA_SUB_ID]) == SUB_ERROR) | |
165 | return NULL; | |
166 | if (!strcmp(info[ZA_SUB_ID], "*.*@*")) | |
167 | { | |
168 | free(info[ZA_SUB_ID]); | |
169 | info[ZA_SUB_ID] = strsave("WILDCARD"); | |
703082ea | 170 | } |
171 | } | |
5eaef520 | 172 | if (GetTypeFromUser("What kind of wildcard instance restriction", |
173 | "ace_type", &info[ZA_IWS_TYPE]) == SUB_ERROR) | |
174 | return NULL; | |
175 | if (strcasecmp(info[ZA_IWS_TYPE], "NONE") != 0) | |
176 | { | |
177 | if (!strcmp(info[ZA_IWS_ID], "WILDCARD")) | |
178 | { | |
179 | free(info[ZA_IWS_ID]); | |
180 | info[ZA_IWS_ID] = strsave("*.*@*"); | |
703082ea | 181 | } |
5eaef520 | 182 | sprintf(buf, "Which %s: ", info[ZA_IWS_TYPE]); |
183 | if (GetValueFromUser(buf, &info[ZA_IWS_ID]) == SUB_ERROR) | |
184 | return NULL; | |
185 | if (!strcmp(info[ZA_IWS_ID], "*.*@*")) | |
186 | { | |
187 | free(info[ZA_IWS_ID]); | |
188 | info[ZA_IWS_ID] = strsave("WILDCARD"); | |
703082ea | 189 | } |
190 | } | |
5eaef520 | 191 | if (GetTypeFromUser("What kind of instance identity restriction", |
192 | "ace_type", &info[ZA_IUI_TYPE]) == SUB_ERROR) | |
193 | return NULL; | |
194 | if (strcasecmp(info[ZA_IUI_TYPE], "NONE")) | |
195 | { | |
196 | if (!strcmp(info[ZA_IUI_ID], "WILDCARD")) | |
197 | { | |
198 | free(info[ZA_IUI_ID]); | |
199 | info[ZA_IUI_ID] = strsave("*.*@*"); | |
703082ea | 200 | } |
5eaef520 | 201 | sprintf(buf, "Which %s: ", info[ZA_IUI_TYPE]); |
202 | if (GetValueFromUser(buf, &info[ZA_IUI_ID]) == SUB_ERROR) | |
203 | return NULL; | |
204 | if (!strcmp(info[ZA_IUI_ID], "*.*@*")) | |
205 | { | |
206 | free(info[ZA_IUI_ID]); | |
207 | info[ZA_IUI_ID] = strsave("WILDCARD"); | |
703082ea | 208 | } |
209 | } | |
5eaef520 | 210 | FreeAndClear(&info[ZA_MODTIME], TRUE); |
211 | FreeAndClear(&info[ZA_MODBY], TRUE); | |
212 | FreeAndClear(&info[ZA_MODWITH], TRUE); | |
703082ea | 213 | |
5eaef520 | 214 | if (rename) |
215 | SlipInNewName(info, newname); | |
216 | return info; | |
703082ea | 217 | } |
218 | ||
219 | ||
220 | /* Menu entry for get zephyr */ | |
5eaef520 | 221 | int GetZephyr(int argc, char **argv) |
703082ea | 222 | { |
5eaef520 | 223 | struct qelem *top; |
703082ea | 224 | |
5eaef520 | 225 | top = GetZephyrInfo(argv[1]); |
226 | Loop(top, (void *) PrintZephyrInfo); | |
227 | FreeQueue(top); | |
228 | return DM_NORMAL; | |
703082ea | 229 | } |
230 | ||
231 | ||
232 | /* Does the real work of a deletion */ | |
233 | ||
5eaef520 | 234 | void RealDeleteZephyr(char **info, Bool one_item) |
703082ea | 235 | { |
5eaef520 | 236 | int stat; |
703082ea | 237 | |
5eaef520 | 238 | if ((stat = do_mr_query("delete_zephyr_class", 1, &info[ZA_CLASS], |
239 | Scream, NULL))) | |
240 | com_err(program_name, stat, " zephyr class restriction not deleted."); | |
241 | else | |
242 | Put_message("Zephyr class restriction deleted."); | |
703082ea | 243 | } |
244 | ||
245 | ||
246 | /* Delete a zephyr class given it's name */ | |
247 | ||
5eaef520 | 248 | int DeleteZephyr(int argc, char **argv) |
703082ea | 249 | { |
5eaef520 | 250 | struct qelem *elem = GetZephyrInfo(argv[1]); |
251 | QueryLoop(elem, PrintZephyrInfo, RealDeleteZephyr, | |
252 | "Delete Zephyr class restriction for class "); | |
253 | FreeQueue(elem); | |
254 | return DM_NORMAL; | |
703082ea | 255 | } |
256 | ||
257 | ||
258 | /* Add a new zephyr class */ | |
259 | ||
5eaef520 | 260 | int AddZephyr(int argc, char **argv) |
703082ea | 261 | { |
5eaef520 | 262 | char *info[MAX_ARGS_SIZE], **args; |
263 | int stat; | |
264 | ||
265 | if (!ValidName(argv[1])) | |
266 | return DM_NORMAL; | |
267 | ||
268 | if (!(stat = do_mr_query("get_zephyr_class", 1, argv + 1, | |
269 | NullFunc, NULL))) | |
270 | { | |
271 | Put_message ("A Zephyr class by that name already exists."); | |
272 | return DM_NORMAL; | |
273 | } | |
274 | else if (stat != MR_NO_MATCH) | |
275 | { | |
276 | com_err(program_name, stat, " in AddZehpyr"); | |
277 | return DM_NORMAL; | |
278 | } | |
279 | ||
280 | args = AskZephyrInfo(SetDefaults(info, argv[1]), FALSE); | |
281 | if (!args) | |
282 | { | |
283 | Put_message("Aborted."); | |
284 | return DM_NORMAL; | |
703082ea | 285 | } |
286 | ||
5eaef520 | 287 | if ((stat = do_mr_query("add_zephyr_class", CountArgs(args), args, |
288 | NullFunc, NULL))) | |
289 | com_err(program_name, stat, " in AddZephyr"); | |
703082ea | 290 | |
5eaef520 | 291 | FreeInfo(info); |
292 | return DM_NORMAL; | |
703082ea | 293 | } |
294 | ||
295 | ||
296 | /* Does the work of an update */ | |
297 | ||
5eaef520 | 298 | static void RealUpdateZephyr(char **info, Bool junk) |
703082ea | 299 | { |
5eaef520 | 300 | int stat; |
301 | char **args; | |
302 | ||
303 | if (!(args = AskZephyrInfo(info, TRUE))) | |
304 | { | |
305 | Put_message("Aborted."); | |
306 | return; | |
703082ea | 307 | } |
5eaef520 | 308 | if ((stat = do_mr_query("update_zephyr_class", CountArgs(args), args, |
309 | Scream, NULL))) | |
310 | { | |
311 | com_err(program_name, stat, " in UpdateZephyr."); | |
312 | Put_message("Zephyr class ** NOT ** Updated."); | |
703082ea | 313 | } |
5eaef520 | 314 | else |
315 | Put_message("Zephyr class successfully updated."); | |
703082ea | 316 | } |
317 | ||
318 | ||
319 | /* Change zephyr info */ | |
320 | ||
5eaef520 | 321 | int ChngZephyr(int argc, char **argv) |
703082ea | 322 | { |
5eaef520 | 323 | struct qelem *top; |
703082ea | 324 | |
5eaef520 | 325 | top = GetZephyrInfo(argv[1]); |
326 | QueryLoop(top, NullPrint, RealUpdateZephyr, "Update class"); | |
703082ea | 327 | |
5eaef520 | 328 | FreeQueue(top); |
329 | return DM_NORMAL; | |
703082ea | 330 | } |