3 * Zephyr ACL routines for the Moira client
5 * Copyright (C) 1990-1998 by the Massachusetts Institute of Technology.
6 * For copying and distribution information, please see the file
10 #include <mit-copyright.h>
12 #include <moira_site.h>
23 void RealDeleteZephyr(char **info, Bool one_item);
25 /* Set the default values for zephyr additions. */
27 static char **SetDefaults(char **info, char *name)
29 info[ZA_CLASS] = strdup(name);
30 info[ZA_XMT_TYPE] = strdup("LIST");
31 info[ZA_SUB_TYPE] = strdup("LIST");
32 info[ZA_IWS_TYPE] = strdup("LIST");
33 info[ZA_IUI_TYPE] = strdup("LIST");
34 info[ZA_XMT_ID] = strdup("empty");
35 info[ZA_SUB_ID] = strdup("empty");
36 info[ZA_IWS_ID] = strdup("empty");
37 info[ZA_IUI_ID] = strdup("empty");
38 info[ZA_MODTIME] = info[ZA_MODBY] = info[ZA_MODWITH] = NULL;
44 /* Get info from database */
46 static struct mqelem *GetZephyrInfo(char *name)
49 struct mqelem *elem = NULL;
51 if ((stat = do_mr_query("get_zephyr_class", 1, &name, StoreInfo, &elem)))
53 com_err(program_name, stat, " in GetZephyrInfo");
56 return QueueTop(elem);
60 /* Print zephyr acl info */
62 static char *PrintZephyrInfo(char **info)
68 Put_message("PrintZephyrInfo called with null info!");
71 sprintf(buf, " Zephyr class: %s", info[ZA_CLASS]);
73 if (!strcmp(info[ZA_XMT_ID], "WILDCARD"))
75 free(info[ZA_XMT_ID]);
76 info[ZA_XMT_ID] = strdup("*.*@*");
78 sprintf(buf, "Transmit ACL: %s %s", info[ZA_XMT_TYPE],
79 strcasecmp(info[ZA_XMT_TYPE], "NONE") ? info[ZA_XMT_ID] : "");
81 if (!strcmp(info[ZA_SUB_ID], "WILDCARD"))
83 free(info[ZA_SUB_ID]);
84 info[ZA_SUB_ID] = strdup("*.*@*");
86 sprintf(buf, "Subscription ACL: %s %s", info[ZA_SUB_TYPE],
87 strcasecmp(info[ZA_SUB_TYPE], "NONE") ? info[ZA_SUB_ID] : "");
89 if (!strcmp(info[ZA_IWS_ID], "WILDCARD"))
91 free(info[ZA_IWS_ID]);
92 info[ZA_IWS_ID] = strdup("*.*@*");
94 sprintf(buf, "Instance Wildcard ACL: %s %s", info[ZA_IWS_TYPE],
95 strcasecmp(info[ZA_IWS_TYPE], "NONE") ? info[ZA_IWS_ID] : "");
97 if (!strcmp(info[ZA_IUI_ID], "WILDCARD"))
99 free(info[ZA_IUI_ID]);
100 info[ZA_IUI_ID] = strdup("*.*@*");
102 sprintf(buf, "Instance Indentity ACL: %s %s", info[ZA_IUI_TYPE],
103 strcasecmp(info[ZA_IUI_TYPE], "NONE") ? info[ZA_IUI_ID] : "");
105 sprintf(buf, MOD_FORMAT, info[ZA_MODBY], info[ZA_MODTIME], info[ZA_MODWITH]);
108 return info[ZA_CLASS];
112 /* Get info from user. Expects info to already be filled in with defaults */
114 static char **AskZephyrInfo(char **info, Bool rename)
116 char buf[BUFSIZ], *newname;
119 sprintf(buf, "Zephyr class restrictions for %s.", info[ZA_CLASS]);
127 newname = strdup(info[ZA_CLASS]);
128 if (GetValueFromUser("The new name for this class", &newname) ==
131 if (ValidName(newname))
136 if (GetTypeFromUser("What kind of transmit restriction", "ace_type",
137 &info[ZA_XMT_TYPE]) == SUB_ERROR)
139 if (strcasecmp(info[ZA_XMT_TYPE], "NONE"))
141 if (!strcmp(info[ZA_XMT_ID], "WILDCARD"))
143 free(info[ZA_XMT_ID]);
144 info[ZA_XMT_ID] = strdup("*.*@*");
146 sprintf(buf, "Which %s: ", info[ZA_XMT_TYPE]);
147 if (GetValueFromUser(buf, &info[ZA_XMT_ID]) == SUB_ERROR)
149 if (!strcmp(info[ZA_XMT_ID], "*.*@*"))
151 free(info[ZA_XMT_ID]);
152 info[ZA_XMT_ID] = strdup("WILDCARD");
155 if (GetTypeFromUser("What kind of subscription restriction", "ace_type",
156 &info[ZA_SUB_TYPE]) == SUB_ERROR)
158 if (strcasecmp(info[ZA_SUB_TYPE], "NONE"))
160 if (!strcmp(info[ZA_SUB_ID], "WILDCARD"))
162 free(info[ZA_SUB_ID]);
163 info[ZA_SUB_ID] = strdup("*.*@*");
165 sprintf(buf, "Which %s: ", info[ZA_SUB_TYPE]);
166 if (GetValueFromUser(buf, &info[ZA_SUB_ID]) == SUB_ERROR)
168 if (!strcmp(info[ZA_SUB_ID], "*.*@*"))
170 free(info[ZA_SUB_ID]);
171 info[ZA_SUB_ID] = strdup("WILDCARD");
174 if (GetTypeFromUser("What kind of wildcard instance restriction",
175 "ace_type", &info[ZA_IWS_TYPE]) == SUB_ERROR)
177 if (strcasecmp(info[ZA_IWS_TYPE], "NONE") != 0)
179 if (!strcmp(info[ZA_IWS_ID], "WILDCARD"))
181 free(info[ZA_IWS_ID]);
182 info[ZA_IWS_ID] = strdup("*.*@*");
184 sprintf(buf, "Which %s: ", info[ZA_IWS_TYPE]);
185 if (GetValueFromUser(buf, &info[ZA_IWS_ID]) == SUB_ERROR)
187 if (!strcmp(info[ZA_IWS_ID], "*.*@*"))
189 free(info[ZA_IWS_ID]);
190 info[ZA_IWS_ID] = strdup("WILDCARD");
193 if (GetTypeFromUser("What kind of instance identity restriction",
194 "ace_type", &info[ZA_IUI_TYPE]) == SUB_ERROR)
196 if (strcasecmp(info[ZA_IUI_TYPE], "NONE"))
198 if (!strcmp(info[ZA_IUI_ID], "WILDCARD"))
200 free(info[ZA_IUI_ID]);
201 info[ZA_IUI_ID] = strdup("*.*@*");
203 sprintf(buf, "Which %s: ", info[ZA_IUI_TYPE]);
204 if (GetValueFromUser(buf, &info[ZA_IUI_ID]) == SUB_ERROR)
206 if (!strcmp(info[ZA_IUI_ID], "*.*@*"))
208 free(info[ZA_IUI_ID]);
209 info[ZA_IUI_ID] = strdup("WILDCARD");
212 FreeAndClear(&info[ZA_MODTIME], TRUE);
213 FreeAndClear(&info[ZA_MODBY], TRUE);
214 FreeAndClear(&info[ZA_MODWITH], TRUE);
217 SlipInNewName(info, newname);
222 /* Menu entry for get zephyr */
223 int GetZephyr(int argc, char **argv)
227 top = GetZephyrInfo(argv[1]);
228 Loop(top, (void *) PrintZephyrInfo);
234 /* Does the real work of a deletion */
236 void RealDeleteZephyr(char **info, Bool one_item)
240 if ((stat = do_mr_query("delete_zephyr_class", 1, &info[ZA_CLASS],
242 com_err(program_name, stat, " zephyr class restriction not deleted.");
244 Put_message("Zephyr class restriction deleted.");
248 /* Delete a zephyr class given it's name */
250 int DeleteZephyr(int argc, char **argv)
252 struct mqelem *elem = GetZephyrInfo(argv[1]);
253 QueryLoop(elem, PrintZephyrInfo, RealDeleteZephyr,
254 "Delete Zephyr class restriction for class ");
260 /* Add a new zephyr class */
262 int AddZephyr(int argc, char **argv)
264 char *info[MAX_ARGS_SIZE], **args;
267 if (!ValidName(argv[1]))
270 if (!(stat = do_mr_query("get_zephyr_class", 1, argv + 1, NULL, NULL)))
272 Put_message ("A Zephyr class by that name already exists.");
275 else if (stat != MR_NO_MATCH)
277 com_err(program_name, stat, " in AddZehpyr");
281 args = AskZephyrInfo(SetDefaults(info, argv[1]), FALSE);
284 Put_message("Aborted.");
288 if ((stat = do_mr_query("add_zephyr_class", CountArgs(args), args,
290 com_err(program_name, stat, " in AddZephyr");
297 /* Does the work of an update */
299 static void RealUpdateZephyr(char **info, Bool junk)
304 if (!(args = AskZephyrInfo(info, TRUE)))
306 Put_message("Aborted.");
309 if ((stat = do_mr_query("update_zephyr_class", CountArgs(args), args,
312 com_err(program_name, stat, " in UpdateZephyr.");
313 Put_message("Zephyr class ** NOT ** Updated.");
316 Put_message("Zephyr class successfully updated.");
320 /* Change zephyr info */
322 int ChngZephyr(int argc, char **argv)
326 top = GetZephyrInfo(argv[1]);
327 QueryLoop(top, NullPrint, RealUpdateZephyr, "Update class");