]> andersk Git - moira.git/blame - clients/moira/zephyr.c
second code style cleanup: void/void * usage, proper #includes. try to
[moira.git] / clients / moira / zephyr.c
CommitLineData
7ac48069 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
21RCSID("$Header$");
22
23void RealDeleteZephyr(char **info, Bool one_item);
703082ea 24
25/* Set the default values for zephyr additions. */
26
5eaef520 27static char **SetDefaults(char **info, char *name)
703082ea 28{
7ac48069 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");
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
5eaef520 46static struct qelem *GetZephyrInfo(char *name)
703082ea 47{
5eaef520 48 int stat;
49 struct qelem *elem = NULL;
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 62static 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);
73 if (!strcmp(info[ZA_XMT_ID], "WILDCARD"))
74 {
75 free(info[ZA_XMT_ID]);
7ac48069 76 info[ZA_XMT_ID] = strdup("*.*@*");
703082ea 77 }
5eaef520 78 sprintf(buf, "Transmit ACL: %s %s", info[ZA_XMT_TYPE],
79 strcasecmp(info[ZA_XMT_TYPE], "NONE") ? info[ZA_XMT_ID] : "");
80 Put_message(buf);
81 if (!strcmp(info[ZA_SUB_ID], "WILDCARD"))
82 {
83 free(info[ZA_SUB_ID]);
7ac48069 84 info[ZA_SUB_ID] = strdup("*.*@*");
703082ea 85 }
5eaef520 86 sprintf(buf, "Subscription ACL: %s %s", info[ZA_SUB_TYPE],
87 strcasecmp(info[ZA_SUB_TYPE], "NONE") ? info[ZA_SUB_ID] : "");
88 Put_message(buf);
89 if (!strcmp(info[ZA_IWS_ID], "WILDCARD"))
90 {
91 free(info[ZA_IWS_ID]);
7ac48069 92 info[ZA_IWS_ID] = strdup("*.*@*");
703082ea 93 }
5eaef520 94 sprintf(buf, "Instance Wildcard ACL: %s %s", info[ZA_IWS_TYPE],
95 strcasecmp(info[ZA_IWS_TYPE], "NONE") ? info[ZA_IWS_ID] : "");
96 Put_message(buf);
97 if (!strcmp(info[ZA_IUI_ID], "WILDCARD"))
98 {
99 free(info[ZA_IUI_ID]);
7ac48069 100 info[ZA_IUI_ID] = strdup("*.*@*");
703082ea 101 }
5eaef520 102 sprintf(buf, "Instance Indentity ACL: %s %s", info[ZA_IUI_TYPE],
103 strcasecmp(info[ZA_IUI_TYPE], "NONE") ? info[ZA_IUI_ID] : "");
104 Put_message(buf);
105 sprintf(buf, MOD_FORMAT, info[ZA_MODBY], info[ZA_MODTIME], info[ZA_MODWITH]);
106 Put_message(buf);
7ac48069 107
108 return info[ZA_CLASS];
703082ea 109}
110
111
112/* Get info from user. Expects info to already be filled in with defaults */
113
5eaef520 114static char **AskZephyrInfo(char **info, Bool rename)
703082ea 115{
5eaef520 116 char buf[BUFSIZ], *newname;
117
118 Put_message("");
119 sprintf(buf, "Zephyr class restrictions for %s.", info[ZA_CLASS]);
120 Put_message(buf);
121 Put_message("");
122
123 if (rename)
124 {
125 while (1)
126 {
7ac48069 127 newname = strdup(info[ZA_CLASS]);
5eaef520 128 if (GetValueFromUser("The new name for this class", &newname) ==
129 SUB_ERROR)
130 return NULL;
131 if (ValidName(newname))
132 break;
133 }
703082ea 134 }
135
5eaef520 136 if (GetTypeFromUser("What kind of transmit restriction", "ace_type",
137 &info[ZA_XMT_TYPE]) == SUB_ERROR)
138 return NULL;
139 if (strcasecmp(info[ZA_XMT_TYPE], "NONE"))
140 {
141 if (!strcmp(info[ZA_XMT_ID], "WILDCARD"))
142 {
143 free(info[ZA_XMT_ID]);
7ac48069 144 info[ZA_XMT_ID] = strdup("*.*@*");
703082ea 145 }
5eaef520 146 sprintf(buf, "Which %s: ", info[ZA_XMT_TYPE]);
147 if (GetValueFromUser(buf, &info[ZA_XMT_ID]) == SUB_ERROR)
148 return NULL;
149 if (!strcmp(info[ZA_XMT_ID], "*.*@*"))
150 {
151 free(info[ZA_XMT_ID]);
7ac48069 152 info[ZA_XMT_ID] = strdup("WILDCARD");
703082ea 153 }
154 }
5eaef520 155 if (GetTypeFromUser("What kind of subscription restriction", "ace_type",
156 &info[ZA_SUB_TYPE]) == SUB_ERROR)
157 return NULL;
158 if (strcasecmp(info[ZA_SUB_TYPE], "NONE"))
159 {
160 if (!strcmp(info[ZA_SUB_ID], "WILDCARD"))
161 {
162 free(info[ZA_SUB_ID]);
7ac48069 163 info[ZA_SUB_ID] = strdup("*.*@*");
703082ea 164 }
5eaef520 165 sprintf(buf, "Which %s: ", info[ZA_SUB_TYPE]);
166 if (GetValueFromUser(buf, &info[ZA_SUB_ID]) == SUB_ERROR)
167 return NULL;
168 if (!strcmp(info[ZA_SUB_ID], "*.*@*"))
169 {
170 free(info[ZA_SUB_ID]);
7ac48069 171 info[ZA_SUB_ID] = strdup("WILDCARD");
703082ea 172 }
173 }
5eaef520 174 if (GetTypeFromUser("What kind of wildcard instance restriction",
175 "ace_type", &info[ZA_IWS_TYPE]) == SUB_ERROR)
176 return NULL;
177 if (strcasecmp(info[ZA_IWS_TYPE], "NONE") != 0)
178 {
179 if (!strcmp(info[ZA_IWS_ID], "WILDCARD"))
180 {
181 free(info[ZA_IWS_ID]);
7ac48069 182 info[ZA_IWS_ID] = strdup("*.*@*");
703082ea 183 }
5eaef520 184 sprintf(buf, "Which %s: ", info[ZA_IWS_TYPE]);
185 if (GetValueFromUser(buf, &info[ZA_IWS_ID]) == SUB_ERROR)
186 return NULL;
187 if (!strcmp(info[ZA_IWS_ID], "*.*@*"))
188 {
189 free(info[ZA_IWS_ID]);
7ac48069 190 info[ZA_IWS_ID] = strdup("WILDCARD");
703082ea 191 }
192 }
5eaef520 193 if (GetTypeFromUser("What kind of instance identity restriction",
194 "ace_type", &info[ZA_IUI_TYPE]) == SUB_ERROR)
195 return NULL;
196 if (strcasecmp(info[ZA_IUI_TYPE], "NONE"))
197 {
198 if (!strcmp(info[ZA_IUI_ID], "WILDCARD"))
199 {
200 free(info[ZA_IUI_ID]);
7ac48069 201 info[ZA_IUI_ID] = strdup("*.*@*");
703082ea 202 }
5eaef520 203 sprintf(buf, "Which %s: ", info[ZA_IUI_TYPE]);
204 if (GetValueFromUser(buf, &info[ZA_IUI_ID]) == SUB_ERROR)
205 return NULL;
206 if (!strcmp(info[ZA_IUI_ID], "*.*@*"))
207 {
208 free(info[ZA_IUI_ID]);
7ac48069 209 info[ZA_IUI_ID] = strdup("WILDCARD");
703082ea 210 }
211 }
5eaef520 212 FreeAndClear(&info[ZA_MODTIME], TRUE);
213 FreeAndClear(&info[ZA_MODBY], TRUE);
214 FreeAndClear(&info[ZA_MODWITH], TRUE);
703082ea 215
5eaef520 216 if (rename)
217 SlipInNewName(info, newname);
218 return info;
703082ea 219}
220
221
222/* Menu entry for get zephyr */
5eaef520 223int GetZephyr(int argc, char **argv)
703082ea 224{
5eaef520 225 struct qelem *top;
703082ea 226
5eaef520 227 top = GetZephyrInfo(argv[1]);
228 Loop(top, (void *) PrintZephyrInfo);
229 FreeQueue(top);
230 return DM_NORMAL;
703082ea 231}
232
233
234/* Does the real work of a deletion */
235
5eaef520 236void RealDeleteZephyr(char **info, Bool one_item)
703082ea 237{
5eaef520 238 int stat;
703082ea 239
5eaef520 240 if ((stat = do_mr_query("delete_zephyr_class", 1, &info[ZA_CLASS],
7ac48069 241 NULL, NULL)))
5eaef520 242 com_err(program_name, stat, " zephyr class restriction not deleted.");
243 else
244 Put_message("Zephyr class restriction deleted.");
703082ea 245}
246
247
248/* Delete a zephyr class given it's name */
249
5eaef520 250int DeleteZephyr(int argc, char **argv)
703082ea 251{
5eaef520 252 struct qelem *elem = GetZephyrInfo(argv[1]);
253 QueryLoop(elem, PrintZephyrInfo, RealDeleteZephyr,
254 "Delete Zephyr class restriction for class ");
255 FreeQueue(elem);
256 return DM_NORMAL;
703082ea 257}
258
259
260/* Add a new zephyr class */
261
5eaef520 262int AddZephyr(int argc, char **argv)
703082ea 263{
5eaef520 264 char *info[MAX_ARGS_SIZE], **args;
265 int stat;
266
267 if (!ValidName(argv[1]))
268 return DM_NORMAL;
269
7ac48069 270 if (!(stat = do_mr_query("get_zephyr_class", 1, argv + 1, NULL, NULL)))
5eaef520 271 {
272 Put_message ("A Zephyr class by that name already exists.");
273 return DM_NORMAL;
274 }
275 else if (stat != MR_NO_MATCH)
276 {
277 com_err(program_name, stat, " in AddZehpyr");
278 return DM_NORMAL;
279 }
280
281 args = AskZephyrInfo(SetDefaults(info, argv[1]), FALSE);
282 if (!args)
283 {
284 Put_message("Aborted.");
285 return DM_NORMAL;
703082ea 286 }
287
5eaef520 288 if ((stat = do_mr_query("add_zephyr_class", CountArgs(args), args,
7ac48069 289 NULL, NULL)))
5eaef520 290 com_err(program_name, stat, " in AddZephyr");
703082ea 291
5eaef520 292 FreeInfo(info);
293 return DM_NORMAL;
703082ea 294}
295
296
297/* Does the work of an update */
298
5eaef520 299static void RealUpdateZephyr(char **info, Bool junk)
703082ea 300{
5eaef520 301 int stat;
302 char **args;
303
304 if (!(args = AskZephyrInfo(info, TRUE)))
305 {
306 Put_message("Aborted.");
307 return;
703082ea 308 }
5eaef520 309 if ((stat = do_mr_query("update_zephyr_class", CountArgs(args), args,
7ac48069 310 NULL, NULL)))
5eaef520 311 {
312 com_err(program_name, stat, " in UpdateZephyr.");
313 Put_message("Zephyr class ** NOT ** Updated.");
703082ea 314 }
5eaef520 315 else
316 Put_message("Zephyr class successfully updated.");
703082ea 317}
318
319
320/* Change zephyr info */
321
5eaef520 322int ChngZephyr(int argc, char **argv)
703082ea 323{
5eaef520 324 struct qelem *top;
703082ea 325
5eaef520 326 top = GetZephyrInfo(argv[1]);
327 QueryLoop(top, NullPrint, RealUpdateZephyr, "Update class");
703082ea 328
5eaef520 329 FreeQueue(top);
330 return DM_NORMAL;
703082ea 331}
This page took 0.147989 seconds and 5 git commands to generate.