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("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_XMT_ID] = strdup("");
35 info[ZA_SUB_ID] = strdup("");
36 info[ZA_IWS_ID] = strdup("");
37 info[ZA_IUI_ID] = strdup("");
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 sprintf(buf, "Transmit ACL: %s %s", info[ZA_XMT_TYPE],
74 strcasecmp(info[ZA_XMT_TYPE], "NONE") ? info[ZA_XMT_ID] : "");
76 sprintf(buf, "Subscription ACL: %s %s", info[ZA_SUB_TYPE],
77 strcasecmp(info[ZA_SUB_TYPE], "NONE") ? info[ZA_SUB_ID] : "");
79 sprintf(buf, "Instance Wildcard ACL: %s %s", info[ZA_IWS_TYPE],
80 strcasecmp(info[ZA_IWS_TYPE], "NONE") ? info[ZA_IWS_ID] : "");
82 sprintf(buf, "Instance Indentity ACL: %s %s", info[ZA_IUI_TYPE],
83 strcasecmp(info[ZA_IUI_TYPE], "NONE") ? info[ZA_IUI_ID] : "");
85 sprintf(buf, MOD_FORMAT, info[ZA_MODBY], info[ZA_MODTIME], info[ZA_MODWITH]);
88 return info[ZA_CLASS];
92 /* Get info from user. Expects info to already be filled in with defaults */
94 static char **AskZephyrInfo(char **info, Bool rename)
96 char buf[BUFSIZ], *newname;
99 sprintf(buf, "Zephyr class restrictions for %s.", info[ZA_CLASS]);
107 newname = strdup(info[ZA_CLASS]);
108 if (GetValueFromUser("The new name for this class", &newname) ==
111 if (ValidName(newname))
116 if (GetTypeFromUser("What kind of transmit restriction", "zace_type",
117 &info[ZA_XMT_TYPE]) == SUB_ERROR)
119 if (strcasecmp(info[ZA_XMT_TYPE], "NONE") &&
120 strcasecmp(info[ZA_XMT_TYPE], "ALL"))
122 sprintf(buf, "Which %s: ", info[ZA_XMT_TYPE]);
123 if (GetValueFromUser(buf, &info[ZA_XMT_ID]) == SUB_ERROR)
126 if (GetTypeFromUser("What kind of subscription restriction", "zace_type",
127 &info[ZA_SUB_TYPE]) == SUB_ERROR)
129 if (strcasecmp(info[ZA_SUB_TYPE], "NONE") &&
130 strcasecmp(info[ZA_SUB_TYPE], "ALL"))
132 sprintf(buf, "Which %s: ", info[ZA_SUB_TYPE]);
133 if (GetValueFromUser(buf, &info[ZA_SUB_ID]) == SUB_ERROR)
136 if (GetTypeFromUser("What kind of wildcard instance restriction",
137 "zace_type", &info[ZA_IWS_TYPE]) == SUB_ERROR)
139 if (strcasecmp(info[ZA_IWS_TYPE], "NONE") &&
140 strcasecmp(info[ZA_IWS_TYPE], "ALL"))
142 sprintf(buf, "Which %s: ", info[ZA_IWS_TYPE]);
143 if (GetValueFromUser(buf, &info[ZA_IWS_ID]) == SUB_ERROR)
146 if (GetTypeFromUser("What kind of instance identity restriction",
147 "zace_type", &info[ZA_IUI_TYPE]) == SUB_ERROR)
149 if (strcasecmp(info[ZA_IUI_TYPE], "NONE") &&
150 strcasecmp(info[ZA_IUI_TYPE], "ALL"))
152 sprintf(buf, "Which %s: ", info[ZA_IUI_TYPE]);
153 if (GetValueFromUser(buf, &info[ZA_IUI_ID]) == SUB_ERROR)
156 FreeAndClear(&info[ZA_MODTIME], TRUE);
157 FreeAndClear(&info[ZA_MODBY], TRUE);
158 FreeAndClear(&info[ZA_MODWITH], TRUE);
161 SlipInNewName(info, newname);
166 /* Menu entry for get zephyr */
167 int GetZephyr(int argc, char **argv)
171 top = GetZephyrInfo(argv[1]);
172 Loop(top, (void (*)(char **)) PrintZephyrInfo);
178 /* Does the real work of a deletion */
180 void RealDeleteZephyr(char **info, Bool one_item)
184 if ((stat = do_mr_query("delete_zephyr_class", 1, &info[ZA_CLASS],
186 com_err(program_name, stat, " zephyr class restriction not deleted.");
188 Put_message("Zephyr class restriction deleted.");
192 /* Delete a zephyr class given it's name */
194 int DeleteZephyr(int argc, char **argv)
196 struct mqelem *elem = GetZephyrInfo(argv[1]);
197 QueryLoop(elem, PrintZephyrInfo, RealDeleteZephyr,
198 "Delete Zephyr class restriction for class ");
204 /* Add a new zephyr class */
206 int AddZephyr(int argc, char **argv)
208 char *info[MAX_ARGS_SIZE], **args;
211 if (!ValidName(argv[1]))
214 if (!(stat = do_mr_query("get_zephyr_class", 1, argv + 1, NULL, NULL)))
216 Put_message ("A Zephyr class by that name already exists.");
219 else if (stat != MR_NO_MATCH)
221 com_err(program_name, stat, " in AddZehpyr");
225 args = AskZephyrInfo(SetDefaults(info, argv[1]), FALSE);
228 Put_message("Aborted.");
232 if ((stat = do_mr_query("add_zephyr_class", CountArgs(args), args,
234 com_err(program_name, stat, " in AddZephyr");
241 /* Does the work of an update */
243 static void RealUpdateZephyr(char **info, Bool junk)
248 if (!(args = AskZephyrInfo(info, TRUE)))
250 Put_message("Aborted.");
253 if ((stat = do_mr_query("update_zephyr_class", CountArgs(args), args,
256 com_err(program_name, stat, " in UpdateZephyr.");
257 Put_message("Zephyr class ** NOT ** Updated.");
260 Put_message("Zephyr class successfully updated.");
264 /* Change zephyr info */
266 int ChngZephyr(int argc, char **argv)
270 top = GetZephyrInfo(argv[1]);
271 QueryLoop(top, NullPrint, RealUpdateZephyr, "Update class");