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_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;
46 /* Get info from database */
48 static struct mqelem *GetZephyrInfo(char *name)
51 struct mqelem *elem = NULL;
53 if ((stat = do_mr_query("get_zephyr_class", 1, &name, StoreInfo, &elem)))
55 com_err(program_name, stat, " in GetZephyrInfo");
58 return QueueTop(elem);
62 /* Print zephyr acl info */
64 static char *PrintZephyrInfo(char **info)
70 Put_message("PrintZephyrInfo called with null info!");
73 sprintf(buf, " Zephyr class: %s", info[ZA_CLASS]);
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] : "");
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] : "");
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] : "");
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] : "");
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] : "");
95 sprintf(buf, MOD_FORMAT, info[ZA_MODBY], info[ZA_MODTIME], info[ZA_MODWITH]);
98 return info[ZA_CLASS];
102 /* Get info from user. Expects info to already be filled in with defaults */
104 static char **AskZephyrInfo(char **info, Bool rename)
106 char buf[BUFSIZ], *newname;
109 sprintf(buf, "Zephyr class restrictions for %s.", info[ZA_CLASS]);
117 newname = strdup(info[ZA_CLASS]);
118 if (GetValueFromUser("The new name for this class", &newname) ==
121 if (ValidName(newname))
126 if (GetTypeFromUser("What kind of transmit restriction", "zace_type",
127 &info[ZA_XMT_TYPE]) == SUB_ERROR)
129 if (strcasecmp(info[ZA_XMT_TYPE], "NONE") &&
130 strcasecmp(info[ZA_XMT_TYPE], "ALL"))
132 sprintf(buf, "Which %s: ", info[ZA_XMT_TYPE]);
133 if (GetValueFromUser(buf, &info[ZA_XMT_ID]) == SUB_ERROR)
136 if (GetTypeFromUser("What kind of subscription restriction", "zace_type",
137 &info[ZA_SUB_TYPE]) == SUB_ERROR)
139 if (strcasecmp(info[ZA_SUB_TYPE], "NONE") &&
140 strcasecmp(info[ZA_SUB_TYPE], "ALL"))
142 sprintf(buf, "Which %s: ", info[ZA_SUB_TYPE]);
143 if (GetValueFromUser(buf, &info[ZA_SUB_ID]) == SUB_ERROR)
146 if (GetTypeFromUser("What kind of wildcard instance restriction",
147 "zace_type", &info[ZA_IWS_TYPE]) == SUB_ERROR)
149 if (strcasecmp(info[ZA_IWS_TYPE], "NONE") &&
150 strcasecmp(info[ZA_IWS_TYPE], "ALL"))
152 sprintf(buf, "Which %s: ", info[ZA_IWS_TYPE]);
153 if (GetValueFromUser(buf, &info[ZA_IWS_ID]) == SUB_ERROR)
156 if (GetTypeFromUser("What kind of instance identity restriction",
157 "zace_type", &info[ZA_IUI_TYPE]) == SUB_ERROR)
159 if (strcasecmp(info[ZA_IUI_TYPE], "NONE") &&
160 strcasecmp(info[ZA_IUI_TYPE], "ALL"))
162 sprintf(buf, "Which %s: ", info[ZA_IUI_TYPE]);
163 if (GetValueFromUser(buf, &info[ZA_IUI_ID]) == SUB_ERROR)
166 if (GetTypeFromUser("What kind of Administrator", "ace_type",
167 &info[ZA_OWNER_TYPE]) == SUB_ERROR)
169 if (strcasecmp(info[ZA_OWNER_TYPE], "NONE"))
171 sprintf(buf, "Which %s: ", info[ZA_OWNER_TYPE]);
172 if (GetValueFromUser(buf, &info[ZA_OWNER_ID]) == SUB_ERROR)
175 FreeAndClear(&info[ZA_MODTIME], TRUE);
176 FreeAndClear(&info[ZA_MODBY], TRUE);
177 FreeAndClear(&info[ZA_MODWITH], TRUE);
180 SlipInNewName(info, newname);
185 /* Menu entry for get zephyr */
186 int GetZephyr(int argc, char **argv)
190 top = GetZephyrInfo(argv[1]);
191 Loop(top, (void (*)(char **)) PrintZephyrInfo);
197 /* Does the real work of a deletion */
199 void RealDeleteZephyr(char **info, Bool one_item)
203 if ((stat = do_mr_query("delete_zephyr_class", 1, &info[ZA_CLASS],
205 com_err(program_name, stat, " zephyr class restriction not deleted.");
207 Put_message("Zephyr class restriction deleted.");
211 /* Delete a zephyr class given it's name */
213 int DeleteZephyr(int argc, char **argv)
215 struct mqelem *elem = GetZephyrInfo(argv[1]);
216 QueryLoop(elem, PrintZephyrInfo, RealDeleteZephyr,
217 "Delete Zephyr class restriction for class ");
223 /* Add a new zephyr class */
225 int AddZephyr(int argc, char **argv)
227 char *info[MAX_ARGS_SIZE], **args;
230 if (!ValidName(argv[1]))
233 if (!(stat = do_mr_query("get_zephyr_class", 1, argv + 1, NULL, NULL)))
235 Put_message ("A Zephyr class by that name already exists.");
238 else if (stat != MR_NO_MATCH)
240 com_err(program_name, stat, " in AddZehpyr");
244 args = AskZephyrInfo(SetDefaults(info, argv[1]), FALSE);
247 Put_message("Aborted.");
251 if ((stat = do_mr_query("add_zephyr_class", CountArgs(args), args,
253 com_err(program_name, stat, " in AddZephyr");
260 /* Does the work of an update */
262 static void RealUpdateZephyr(char **info, Bool junk)
267 if (!(args = AskZephyrInfo(info, TRUE)))
269 Put_message("Aborted.");
272 if ((stat = do_mr_query("update_zephyr_class", CountArgs(args), args,
275 com_err(program_name, stat, " in UpdateZephyr.");
276 Put_message("Zephyr class ** NOT ** Updated.");
279 Put_message("Zephyr class successfully updated.");
283 /* Change zephyr info */
285 int ChngZephyr(int argc, char **argv)
289 top = GetZephyrInfo(argv[1]);
290 QueryLoop(top, NullPrint, RealUpdateZephyr, "Update class");