]> andersk Git - moira.git/blob - clients/moira/zephyr.c
ef86803a21b76a47287d3d2c55ffaacabd0e0ed6
[moira.git] / clients / moira / zephyr.c
1 /* $Id $
2  *
3  * Zephyr ACL routines for the Moira client
4  *
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>.
8  */
9
10 #include <mit-copyright.h>
11 #include <moira.h>
12 #include <moira_site.h>
13 #include "defs.h"
14 #include "f_defs.h"
15 #include "globals.h"
16
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);
24
25 /* Set the default values for zephyr additions. */
26
27 static char **SetDefaults(char **info, char *name)
28 {
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;
39   info[ZA_END] = NULL;
40   return info;
41 }
42
43
44 /* Get info from database */
45
46 static struct mqelem *GetZephyrInfo(char *name)
47 {
48   int stat;
49   struct mqelem *elem = NULL;
50
51   if ((stat = do_mr_query("get_zephyr_class", 1, &name, StoreInfo, &elem)))
52     {
53       com_err(program_name, stat, " in GetZephyrInfo");
54       return NULL;
55     }
56   return QueueTop(elem);
57 }
58
59
60 /* Print zephyr acl info */
61
62 static char *PrintZephyrInfo(char **info)
63 {
64   char buf[BUFSIZ];
65
66   if (!info)
67     {
68       Put_message("PrintZephyrInfo called with null info!");
69       return NULL;
70     }
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]);
76       info[ZA_XMT_ID] = strdup("*.*@*");
77     }
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]);
84       info[ZA_SUB_ID] = strdup("*.*@*");
85     }
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]);
92       info[ZA_IWS_ID] = strdup("*.*@*");
93     }
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]);
100       info[ZA_IUI_ID] = strdup("*.*@*");
101     }
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);
107
108   return info[ZA_CLASS];
109 }
110
111
112 /* Get info from user.  Expects info to already be filled in with defaults */
113
114 static char **AskZephyrInfo(char **info, Bool rename)
115 {
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         {
127           newname = strdup(info[ZA_CLASS]);
128           if (GetValueFromUser("The new name for this class", &newname) ==
129               SUB_ERROR)
130             return NULL;
131           if (ValidName(newname))
132             break;
133         }
134     }
135
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]);
144           info[ZA_XMT_ID] = strdup("*.*@*");
145         }
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]);
152           info[ZA_XMT_ID] = strdup("WILDCARD");
153         }
154     }
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]);
163           info[ZA_SUB_ID] = strdup("*.*@*");
164         }
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]);
171           info[ZA_SUB_ID] = strdup("WILDCARD");
172         }
173     }
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]);
182           info[ZA_IWS_ID] = strdup("*.*@*");
183         }
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]);
190           info[ZA_IWS_ID] = strdup("WILDCARD");
191         }
192     }
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]);
201           info[ZA_IUI_ID] = strdup("*.*@*");
202         }
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]);
209           info[ZA_IUI_ID] = strdup("WILDCARD");
210         }
211     }
212   FreeAndClear(&info[ZA_MODTIME], TRUE);
213   FreeAndClear(&info[ZA_MODBY], TRUE);
214   FreeAndClear(&info[ZA_MODWITH], TRUE);
215
216   if (rename)
217     SlipInNewName(info, newname);
218   return info;
219 }
220
221
222 /* Menu entry for get zephyr */
223 int GetZephyr(int argc, char **argv)
224 {
225   struct mqelem *top;
226
227   top = GetZephyrInfo(argv[1]);
228   Loop(top, (void *) PrintZephyrInfo);
229   FreeQueue(top);
230   return DM_NORMAL;
231 }
232
233
234 /* Does the real work of a deletion */
235
236 void RealDeleteZephyr(char **info, Bool one_item)
237 {
238   int stat;
239
240   if ((stat = do_mr_query("delete_zephyr_class", 1, &info[ZA_CLASS],
241                           NULL, NULL)))
242     com_err(program_name, stat, " zephyr class restriction not deleted.");
243   else
244     Put_message("Zephyr class restriction deleted.");
245 }
246
247
248 /* Delete a zephyr class given it's name */
249
250 int DeleteZephyr(int argc, char **argv)
251 {
252   struct mqelem *elem = GetZephyrInfo(argv[1]);
253   QueryLoop(elem, PrintZephyrInfo, RealDeleteZephyr,
254             "Delete Zephyr class restriction for class ");
255   FreeQueue(elem);
256   return DM_NORMAL;
257 }
258
259
260 /* Add a new zephyr class */
261
262 int AddZephyr(int argc, char **argv)
263 {
264   char *info[MAX_ARGS_SIZE], **args;
265   int stat;
266
267   if (!ValidName(argv[1]))
268     return DM_NORMAL;
269
270   if (!(stat = do_mr_query("get_zephyr_class", 1, argv + 1, NULL, NULL)))
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;
286     }
287
288   if ((stat = do_mr_query("add_zephyr_class", CountArgs(args), args,
289                           NULL, NULL)))
290     com_err(program_name, stat, " in AddZephyr");
291
292   FreeInfo(info);
293   return DM_NORMAL;
294 }
295
296
297 /* Does the work of an update */
298
299 static void RealUpdateZephyr(char **info, Bool junk)
300 {
301   int stat;
302   char **args;
303
304   if (!(args = AskZephyrInfo(info, TRUE)))
305     {
306       Put_message("Aborted.");
307       return;
308     }
309   if ((stat = do_mr_query("update_zephyr_class", CountArgs(args), args,
310                           NULL, NULL)))
311     {
312       com_err(program_name, stat, " in UpdateZephyr.");
313       Put_message("Zephyr class ** NOT ** Updated.");
314     }
315   else
316     Put_message("Zephyr class successfully updated.");
317 }
318
319
320 /* Change zephyr info */
321
322 int ChngZephyr(int argc, char **argv)
323 {
324   struct mqelem *top;
325
326   top = GetZephyrInfo(argv[1]);
327   QueryLoop(top, NullPrint, RealUpdateZephyr, "Update class");
328
329   FreeQueue(top);
330   return DM_NORMAL;
331 }
This page took 0.372895 seconds and 3 git commands to generate.