3 * Zephyr ACL routines for the Moira client
5 * Copyright 1990 by the Massachusetts Institute of Technology.
7 * For further information on copyright and distribution see the
15 #include <moira_site.h>
17 #include <mit-copyright.h>
24 /* Set the default values for zephyr additions. */
27 SetDefaults(info, name)
31 info[ZA_CLASS] = strsave(name);
32 info[ZA_XMT_TYPE] = strsave("LIST");
33 info[ZA_SUB_TYPE] = strsave("LIST");
34 info[ZA_IWS_TYPE] = strsave("LIST");
35 info[ZA_IUI_TYPE] = strsave("LIST");
36 info[ZA_XMT_ID] = strsave("empty");
37 info[ZA_SUB_ID] = strsave("empty");
38 info[ZA_IWS_ID] = strsave("empty");
39 info[ZA_IUI_ID] = strsave("empty");
40 info[ZA_MODTIME] = info[ZA_MODBY] = info[ZA_MODWITH] = NULL;
46 /* Get info from database */
53 struct qelem *elem = NULL;
55 if ((stat = do_mr_query("get_zephyr_class", 1, &name, StoreInfo,
56 (char *)&elem)) != 0) {
57 com_err(program_name, stat, " in GetZephyrInfo");
60 return(QueueTop(elem));
64 /* Print zephyr acl info */
73 Put_message("PrintZephyrInfo called with null info!");
76 sprintf(buf, " Zephyr class: %s", info[ZA_CLASS]);
78 if (!strcmp(info[ZA_XMT_ID], "WILDCARD")) {
79 free(info[ZA_XMT_ID]);
80 info[ZA_XMT_ID] = strsave("*.*@*");
82 sprintf(buf, "Transmit ACL: %s %s", info[ZA_XMT_TYPE],
83 strcasecmp(info[ZA_XMT_TYPE], "NONE")?info[ZA_XMT_ID]:"");
85 if (!strcmp(info[ZA_SUB_ID], "WILDCARD")) {
86 free(info[ZA_SUB_ID]);
87 info[ZA_SUB_ID] = strsave("*.*@*");
89 sprintf(buf, "Subscription ACL: %s %s", info[ZA_SUB_TYPE],
90 strcasecmp(info[ZA_SUB_TYPE], "NONE")?info[ZA_SUB_ID]:"");
92 if (!strcmp(info[ZA_IWS_ID], "WILDCARD")) {
93 free(info[ZA_IWS_ID]);
94 info[ZA_IWS_ID] = strsave("*.*@*");
96 sprintf(buf, "Instance Wildcard ACL: %s %s", info[ZA_IWS_TYPE],
97 strcasecmp(info[ZA_IWS_TYPE], "NONE")?info[ZA_IWS_ID]:"");
99 if (!strcmp(info[ZA_IUI_ID], "WILDCARD")) {
100 free(info[ZA_IUI_ID]);
101 info[ZA_IUI_ID] = strsave("*.*@*");
103 sprintf(buf, "Instance Indentity ACL: %s %s", info[ZA_IUI_TYPE],
104 strcasecmp(info[ZA_IUI_TYPE], "NONE")?info[ZA_IUI_ID]:"");
106 sprintf(buf, MOD_FORMAT, info[ZA_MODBY], info[ZA_MODTIME],
112 /* Get info from user. Expects info to already be filled in with defaults */
115 AskZephyrInfo(info, rename)
119 char buf[BUFSIZ], *newname;
122 sprintf(buf, "Zephyr class restrictions for %s.", info[ZA_CLASS]);
128 newname = Strsave(info[ZA_CLASS]);
129 if (GetValueFromUser("The new name for this class", &newname) ==
132 if (ValidName(newname))
137 if (GetTypeFromUser("What kind of transmit restriction", "ace_type",
138 &info[ZA_XMT_TYPE]) == SUB_ERROR)
140 if (strcasecmp(info[ZA_XMT_TYPE], "NONE") != 0) {
141 if (!strcmp(info[ZA_XMT_ID], "WILDCARD")) {
142 free(info[ZA_XMT_ID]);
143 info[ZA_XMT_ID] = strsave("*.*@*");
145 sprintf(buf, "Which %s: ", info[ZA_XMT_TYPE]);
146 if (GetValueFromUser(buf, &info[ZA_XMT_ID]) == SUB_ERROR)
148 if (!strcmp(info[ZA_XMT_ID], "*.*@*")) {
149 free(info[ZA_XMT_ID]);
150 info[ZA_XMT_ID] = strsave("WILDCARD");
153 if (GetTypeFromUser("What kind of subscription restriction", "ace_type",
154 &info[ZA_SUB_TYPE]) == SUB_ERROR)
156 if (strcasecmp(info[ZA_SUB_TYPE], "NONE") != 0) {
157 if (!strcmp(info[ZA_SUB_ID], "WILDCARD")) {
158 free(info[ZA_SUB_ID]);
159 info[ZA_SUB_ID] = strsave("*.*@*");
161 sprintf(buf, "Which %s: ", info[ZA_SUB_TYPE]);
162 if (GetValueFromUser(buf, &info[ZA_SUB_ID]) == SUB_ERROR)
164 if (!strcmp(info[ZA_SUB_ID], "*.*@*")) {
165 free(info[ZA_SUB_ID]);
166 info[ZA_SUB_ID] = strsave("WILDCARD");
169 if (GetTypeFromUser("What kind of wildcard instance restriction",
170 "ace_type", &info[ZA_IWS_TYPE]) == SUB_ERROR)
172 if (strcasecmp(info[ZA_IWS_TYPE], "NONE") != 0) {
173 if (!strcmp(info[ZA_IWS_ID], "WILDCARD")) {
174 free(info[ZA_IWS_ID]);
175 info[ZA_IWS_ID] = strsave("*.*@*");
177 sprintf(buf, "Which %s: ", info[ZA_IWS_TYPE]);
178 if (GetValueFromUser(buf, &info[ZA_IWS_ID]) == SUB_ERROR)
180 if (!strcmp(info[ZA_IWS_ID], "*.*@*")) {
181 free(info[ZA_IWS_ID]);
182 info[ZA_IWS_ID] = strsave("WILDCARD");
185 if (GetTypeFromUser("What kind of instance identity restriction",
186 "ace_type", &info[ZA_IUI_TYPE]) == SUB_ERROR)
188 if (strcasecmp(info[ZA_IUI_TYPE], "NONE") != 0) {
189 if (!strcmp(info[ZA_IUI_ID], "WILDCARD")) {
190 free(info[ZA_IUI_ID]);
191 info[ZA_IUI_ID] = strsave("*.*@*");
193 sprintf(buf, "Which %s: ", info[ZA_IUI_TYPE]);
194 if (GetValueFromUser(buf, &info[ZA_IUI_ID]) == SUB_ERROR)
196 if (!strcmp(info[ZA_IUI_ID], "*.*@*")) {
197 free(info[ZA_IUI_ID]);
198 info[ZA_IUI_ID] = strsave("WILDCARD");
201 FreeAndClear(&info[ZA_MODTIME], TRUE);
202 FreeAndClear(&info[ZA_MODBY], TRUE);
203 FreeAndClear(&info[ZA_MODWITH], TRUE);
206 SlipInNewName(info, newname);
211 /* Menu entry for get zephyr */
213 GetZephyr(argc, argv)
219 top = GetZephyrInfo(argv[1]);
220 Loop(top, (void *) PrintZephyrInfo);
226 /* Does the real work of a deletion */
229 RealDeleteZephyr(info, one_item)
235 if ((stat = do_mr_query("delete_zephyr_class", 1, &info[ZA_CLASS],
237 com_err(program_name, stat, " zephyr class restriction not deleted.");
239 Put_message("Zephyr class restriction deleted.");
243 /* Delete a zephyr class given it's name */
246 DeleteZephyr(argc, argv)
250 struct qelem *elem = GetZephyrInfo(argv[1]);
251 QueryLoop(elem, PrintZephyrInfo, RealDeleteZephyr,
252 "Delete Zephyr class restriction for class ");
258 /* Add a new zephyr class */
261 AddZephyr(argc, argv)
265 char *info[MAX_ARGS_SIZE], **args;
268 if ( !ValidName(argv[1]) )
271 if ((stat = do_mr_query("get_zephyr_class", 1, argv + 1,
272 NullFunc, NULL)) == 0) {
273 Put_message ("A Zephyr class by that name already exists.");
275 } else if (stat != MR_NO_MATCH) {
276 com_err(program_name, stat, " in AddZehpyr");
280 args = AskZephyrInfo(SetDefaults(info, argv[1]), FALSE);
282 Put_message("Aborted.");
286 if ((stat = do_mr_query("add_zephyr_class", CountArgs(args), args,
287 NullFunc, NULL)) != 0)
288 com_err(program_name, stat, " in AddZephyr");
295 /* Does the work of an update */
298 RealUpdateZephyr(info, junk)
305 if ((args = AskZephyrInfo(info, TRUE)) == NULL) {
306 Put_message("Aborted.");
309 if ((stat = do_mr_query("update_zephyr_class", CountArgs(args), args,
310 Scream, (char *) NULL)) != MR_SUCCESS) {
311 com_err(program_name, stat, " in UpdateZephyr.");
312 Put_message("Zephyr class ** NOT ** Updated.");
315 Put_message("Zephyr class successfully updated.");
319 /* Change zephyr info */
322 ChngZephyr(argc, argv)
328 top = GetZephyrInfo(argv[1]);
329 QueryLoop(top, NullPrint, RealUpdateZephyr, "Update class");