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