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