]> andersk Git - moira.git/blob - clients/moira/zephyr.c
ffb7de0999f6863cc8a545c29cf3e9c6e61bf8e9
[moira.git] / clients / moira / zephyr.c
1 /* $Header$
2  *
3  * Zephyr ACL routines for the Moira client
4  *
5  * Copyright 1990 by the Massachusetts Institute of Technology.
6  * 
7  * For further information on copyright and distribution see the
8  * file mit-copyright.h
9  */
10
11 #include <stdio.h>
12 #include <strings.h>
13 #include <ctype.h>
14 #include <moira.h>
15 #include <moira_site.h>
16 #include <menu.h>
17 #include <mit-copyright.h>
18
19 #include "defs.h"
20 #include "f_defs.h"
21 #include "globals.h"
22
23
24 /* Set the default values for zephyr additions. */
25
26 static char **
27 SetDefaults(info, name)
28 char **info;
29 char *name;
30 {
31     info[ZA_CLASS] = strsave(name);
32     info[ZA_XMT_TYPE] = strsave("LIST");
33     info[ZA_SUB_TYPE] = strsave("LIST");
34     info[ZA_IWS_TYPE] = strsave("LIST");
35     info[ZA_IUI_TYPE] = strsave("LIST");
36     info[ZA_XMT_ID] = strsave("empty");
37     info[ZA_SUB_ID] = strsave("empty");
38     info[ZA_IWS_ID] = strsave("empty");
39     info[ZA_IUI_ID] = strsave("empty");
40     info[ZA_MODTIME] = info[ZA_MODBY] = info[ZA_MODWITH] = NULL;
41     info[ZA_END] = NULL;
42     return(info);
43 }
44
45
46 /* Get info from database */
47
48 static struct qelem *
49 GetZephyrInfo(name)
50 char *name;
51 {
52     int stat;
53     struct qelem *elem = NULL;
54
55     if ((stat = do_mr_query("get_zephyr_class", 1, &name, StoreInfo,
56                             (char *)&elem)) != 0) {
57         com_err(program_name, stat, " in GetZephyrInfo");
58         return(NULL);
59     }
60     return(QueueTop(elem));
61 }
62
63
64 /* Print zephyr acl info */
65
66 static void
67 PrintZephyrInfo(info)
68 char **info;
69 {
70     char buf[BUFSIZ];
71
72     if (!info) {
73         Put_message("PrintZephyrInfo called with null info!");
74         return;
75     }
76     sprintf(buf, "        Zephyr class: %s", info[ZA_CLASS]);
77     Put_message(buf);
78     if (!strcmp(info[ZA_XMT_ID], "WILDCARD")) {
79         free(info[ZA_XMT_ID]);
80         info[ZA_XMT_ID] = strsave("*.*@*");
81     }
82     sprintf(buf, "Transmit ACL:           %s %s", info[ZA_XMT_TYPE],
83             strcasecmp(info[ZA_XMT_TYPE], "NONE")?info[ZA_XMT_ID]:"");
84     Put_message(buf);
85     if (!strcmp(info[ZA_SUB_ID], "WILDCARD")) {
86         free(info[ZA_SUB_ID]);
87         info[ZA_SUB_ID] = strsave("*.*@*");
88     }
89     sprintf(buf, "Subscription ACL:       %s %s", info[ZA_SUB_TYPE],
90             strcasecmp(info[ZA_SUB_TYPE], "NONE")?info[ZA_SUB_ID]:"");
91     Put_message(buf);
92     if (!strcmp(info[ZA_IWS_ID], "WILDCARD")) {
93         free(info[ZA_IWS_ID]);
94         info[ZA_IWS_ID] = strsave("*.*@*");
95     }
96     sprintf(buf, "Instance Wildcard ACL:  %s %s", info[ZA_IWS_TYPE],
97             strcasecmp(info[ZA_IWS_TYPE], "NONE")?info[ZA_IWS_ID]:"");
98     Put_message(buf);
99     if (!strcmp(info[ZA_IUI_ID], "WILDCARD")) {
100         free(info[ZA_IUI_ID]);
101         info[ZA_IUI_ID] = strsave("*.*@*");
102     }
103     sprintf(buf, "Instance Indentity ACL: %s %s", info[ZA_IUI_TYPE],
104             strcasecmp(info[ZA_IUI_TYPE], "NONE")?info[ZA_IUI_ID]:"");
105     Put_message(buf);
106     sprintf(buf, MOD_FORMAT, info[ZA_MODBY], info[ZA_MODTIME], 
107             info[ZA_MODWITH]);
108     Put_message(buf);
109 }
110
111
112 /* Get info from user.  Expects info to already be filled in with defaults */
113
114 static char **
115 AskZephyrInfo(info, rename)
116 char **info;
117 Bool rename;
118 {
119     char buf[BUFSIZ], *newname;
120
121     Put_message("");
122     sprintf(buf, "Zephyr class restrictions for %s.", info[ZA_CLASS]);
123     Put_message(buf);
124     Put_message("");
125
126     if (rename) {
127         while (1) {
128             newname = Strsave(info[ZA_CLASS]);
129             if (GetValueFromUser("The new name for this class", &newname) ==
130                 SUB_ERROR)
131               return(NULL);
132             if (ValidName(newname))
133               break;
134         }         
135     }
136
137     if (GetTypeFromUser("What kind of transmit restriction", "ace_type",
138                         &info[ZA_XMT_TYPE]) == SUB_ERROR)
139       return(NULL);
140     if (strcasecmp(info[ZA_XMT_TYPE], "NONE") != 0) {
141         if (!strcmp(info[ZA_XMT_ID], "WILDCARD")) {
142             free(info[ZA_XMT_ID]);
143             info[ZA_XMT_ID] = strsave("*.*@*");
144         }
145         sprintf(buf, "Which %s: ", info[ZA_XMT_TYPE]);
146         if (GetValueFromUser(buf, &info[ZA_XMT_ID]) == SUB_ERROR)
147           return(NULL);
148         if (!strcmp(info[ZA_XMT_ID], "*.*@*")) {
149             free(info[ZA_XMT_ID]);
150             info[ZA_XMT_ID] = strsave("WILDCARD");
151         }
152     }
153     if (GetTypeFromUser("What kind of subscription restriction", "ace_type",
154                         &info[ZA_SUB_TYPE]) == SUB_ERROR)
155       return(NULL);
156     if (strcasecmp(info[ZA_SUB_TYPE], "NONE") != 0) {
157         if (!strcmp(info[ZA_SUB_ID], "WILDCARD")) {
158             free(info[ZA_SUB_ID]);
159             info[ZA_SUB_ID] = strsave("*.*@*");
160         }
161         sprintf(buf, "Which %s: ", info[ZA_SUB_TYPE]);
162         if (GetValueFromUser(buf, &info[ZA_SUB_ID]) == SUB_ERROR)
163           return(NULL);
164         if (!strcmp(info[ZA_SUB_ID], "*.*@*")) {
165             free(info[ZA_SUB_ID]);
166             info[ZA_SUB_ID] = strsave("WILDCARD");
167         }
168     }
169     if (GetTypeFromUser("What kind of wildcard instance restriction",
170                         "ace_type", &info[ZA_IWS_TYPE]) == SUB_ERROR)
171       return(NULL);
172     if (strcasecmp(info[ZA_IWS_TYPE], "NONE") != 0) {
173         if (!strcmp(info[ZA_IWS_ID], "WILDCARD")) {
174             free(info[ZA_IWS_ID]);
175             info[ZA_IWS_ID] = strsave("*.*@*");
176         }
177         sprintf(buf, "Which %s: ", info[ZA_IWS_TYPE]);
178         if (GetValueFromUser(buf, &info[ZA_IWS_ID]) == SUB_ERROR)
179           return(NULL);
180         if (!strcmp(info[ZA_IWS_ID], "*.*@*")) {
181             free(info[ZA_IWS_ID]);
182             info[ZA_IWS_ID] = strsave("WILDCARD");
183         }
184     }
185     if (GetTypeFromUser("What kind of instance identity restriction",
186                         "ace_type", &info[ZA_IUI_TYPE]) == SUB_ERROR)
187       return(NULL);
188     if (strcasecmp(info[ZA_IUI_TYPE], "NONE") != 0) {
189         if (!strcmp(info[ZA_IUI_ID], "WILDCARD")) {
190             free(info[ZA_IUI_ID]);
191             info[ZA_IUI_ID] = strsave("*.*@*");
192         }
193         sprintf(buf, "Which %s: ", info[ZA_IUI_TYPE]);
194         if (GetValueFromUser(buf, &info[ZA_IUI_ID]) == SUB_ERROR)
195           return(NULL);
196         if (!strcmp(info[ZA_IUI_ID], "*.*@*")) {
197             free(info[ZA_IUI_ID]);
198             info[ZA_IUI_ID] = strsave("WILDCARD");
199         }
200     }
201     FreeAndClear(&info[ZA_MODTIME], TRUE);
202     FreeAndClear(&info[ZA_MODBY], TRUE);
203     FreeAndClear(&info[ZA_MODWITH], TRUE);
204
205     if (rename)
206       SlipInNewName(info, newname);
207     return(info);
208 }
209
210
211 /* Menu entry for get zephyr */
212 int
213 GetZephyr(argc, argv)
214 int argc;
215 char **argv;
216 {
217     struct qelem *top;
218
219     top = GetZephyrInfo(argv[1]);
220     Loop(top, (void *) PrintZephyrInfo);
221     FreeQueue(top);
222     return (DM_NORMAL);
223 }
224
225
226 /* Does the real work of a deletion */
227
228 void
229 RealDeleteZephyr(info, one_item)
230 char **info;
231 Bool one_item;
232 {
233     int stat;
234
235     if ((stat = do_mr_query("delete_zephyr_class", 1, &info[ZA_CLASS],
236                             Scream, NULL)) != 0)
237       com_err(program_name, stat, " zephyr class restriction not deleted.");
238     else
239       Put_message("Zephyr class restriction deleted.");
240 }
241
242
243 /* Delete a zephyr class given it's name */
244
245 int
246 DeleteZephyr(argc, argv)
247 int argc;
248 char **argv;
249 {
250     struct qelem *elem = GetZephyrInfo(argv[1]);
251     QueryLoop(elem, PrintZephyrInfo, RealDeleteZephyr,
252               "Delete Zephyr class restriction for class ");
253     FreeQueue(elem);
254     return (DM_NORMAL);
255 }
256
257
258 /* Add a new zephyr class */
259
260 int
261 AddZephyr(argc, argv)
262 char **argv;
263 int argc;
264 {
265     char *info[MAX_ARGS_SIZE], **args;
266     int stat;
267
268     if ( !ValidName(argv[1]) )
269       return(DM_NORMAL);
270
271     if ((stat = do_mr_query("get_zephyr_class", 1, argv + 1,
272                             NullFunc, NULL)) == 0) {
273         Put_message ("A Zephyr class by that name already exists.");
274         return(DM_NORMAL);
275     } else if (stat != MR_NO_MATCH) {
276         com_err(program_name, stat, " in AddZehpyr");
277         return(DM_NORMAL);
278     } 
279
280     args = AskZephyrInfo(SetDefaults(info, argv[1]), FALSE);
281     if (args == NULL) {
282         Put_message("Aborted.");
283         return(DM_NORMAL);
284     }
285
286     if ((stat = do_mr_query("add_zephyr_class", CountArgs(args), args, 
287                             NullFunc, NULL)) != 0)
288       com_err(program_name, stat, " in AddZephyr");
289
290     FreeInfo(info);
291     return (DM_NORMAL);
292 }
293
294
295 /* Does the work of an update */
296
297 static void
298 RealUpdateZephyr(info, junk)
299 char **info;
300 Bool junk;
301 {
302     int stat;
303     char **args;
304     
305     if ((args = AskZephyrInfo(info, TRUE)) == NULL) {
306         Put_message("Aborted.");
307         return;
308     }
309     if ((stat = do_mr_query("update_zephyr_class", CountArgs(args), args, 
310                             Scream, (char *) NULL)) != MR_SUCCESS) {
311         com_err(program_name, stat, " in UpdateZephyr.");       
312         Put_message("Zephyr class ** NOT ** Updated.");
313     }
314     else
315       Put_message("Zephyr class successfully updated.");
316 }
317
318
319 /* Change zephyr info */
320
321 int
322 ChngZephyr(argc, argv)
323 int argc;
324 char **argv;
325 {
326     struct qelem *top;
327
328     top = GetZephyrInfo(argv[1]);
329     QueryLoop(top, NullPrint, RealUpdateZephyr, "Update class");
330
331     FreeQueue(top);
332     return(DM_NORMAL);
333 }
This page took 0.048478 seconds and 3 git commands to generate.