]> andersk Git - moira.git/blob - clients/moira/zephyr.c
Fix typo.
[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("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("");
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   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);
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);
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);
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);
87
88   return info[ZA_CLASS];
89 }
90
91
92 /* Get info from user.  Expects info to already be filled in with defaults */
93
94 static char **AskZephyrInfo(char **info, Bool rename)
95 {
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         {
107           newname = strdup(info[ZA_CLASS]);
108           if (GetValueFromUser("The new name for this class", &newname) ==
109               SUB_ERROR)
110             return NULL;
111           if (ValidName(newname))
112             break;
113         }
114     }
115
116   if (GetTypeFromUser("What kind of transmit restriction", "zace_type",
117                       &info[ZA_XMT_TYPE]) == SUB_ERROR)
118     return NULL;
119   if (strcasecmp(info[ZA_XMT_TYPE], "NONE") &&
120       strcasecmp(info[ZA_XMT_TYPE], "ALL"))
121     {
122       sprintf(buf, "Which %s: ", info[ZA_XMT_TYPE]);
123       if (GetValueFromUser(buf, &info[ZA_XMT_ID]) == SUB_ERROR)
124         return NULL;
125     }
126   if (GetTypeFromUser("What kind of subscription restriction", "zace_type",
127                       &info[ZA_SUB_TYPE]) == SUB_ERROR)
128     return NULL;
129   if (strcasecmp(info[ZA_SUB_TYPE], "NONE") &&
130       strcasecmp(info[ZA_SUB_TYPE], "ALL"))
131     {
132       sprintf(buf, "Which %s: ", info[ZA_SUB_TYPE]);
133       if (GetValueFromUser(buf, &info[ZA_SUB_ID]) == SUB_ERROR)
134         return NULL;
135     }
136   if (GetTypeFromUser("What kind of wildcard instance restriction",
137                       "zace_type", &info[ZA_IWS_TYPE]) == SUB_ERROR)
138     return NULL;
139   if (strcasecmp(info[ZA_IWS_TYPE], "NONE") &&
140       strcasecmp(info[ZA_IWS_TYPE], "ALL"))
141     {
142       sprintf(buf, "Which %s: ", info[ZA_IWS_TYPE]);
143       if (GetValueFromUser(buf, &info[ZA_IWS_ID]) == SUB_ERROR)
144         return NULL;
145     }
146   if (GetTypeFromUser("What kind of instance identity restriction",
147                       "zace_type", &info[ZA_IUI_TYPE]) == SUB_ERROR)
148     return NULL;
149   if (strcasecmp(info[ZA_IUI_TYPE], "NONE") &&
150       strcasecmp(info[ZA_IUI_TYPE], "ALL"))
151     {
152       sprintf(buf, "Which %s: ", info[ZA_IUI_TYPE]);
153       if (GetValueFromUser(buf, &info[ZA_IUI_ID]) == SUB_ERROR)
154         return NULL;
155     }
156   FreeAndClear(&info[ZA_MODTIME], TRUE);
157   FreeAndClear(&info[ZA_MODBY], TRUE);
158   FreeAndClear(&info[ZA_MODWITH], TRUE);
159
160   if (rename)
161     SlipInNewName(info, newname);
162   return info;
163 }
164
165
166 /* Menu entry for get zephyr */
167 int GetZephyr(int argc, char **argv)
168 {
169   struct mqelem *top;
170
171   top = GetZephyrInfo(argv[1]);
172   Loop(top, (void (*)(char **)) PrintZephyrInfo);
173   FreeQueue(top);
174   return DM_NORMAL;
175 }
176
177
178 /* Does the real work of a deletion */
179
180 void RealDeleteZephyr(char **info, Bool one_item)
181 {
182   int stat;
183
184   if ((stat = do_mr_query("delete_zephyr_class", 1, &info[ZA_CLASS],
185                           NULL, NULL)))
186     com_err(program_name, stat, " zephyr class restriction not deleted.");
187   else
188     Put_message("Zephyr class restriction deleted.");
189 }
190
191
192 /* Delete a zephyr class given it's name */
193
194 int DeleteZephyr(int argc, char **argv)
195 {
196   struct mqelem *elem = GetZephyrInfo(argv[1]);
197   QueryLoop(elem, PrintZephyrInfo, RealDeleteZephyr,
198             "Delete Zephyr class restriction for class ");
199   FreeQueue(elem);
200   return DM_NORMAL;
201 }
202
203
204 /* Add a new zephyr class */
205
206 int AddZephyr(int argc, char **argv)
207 {
208   char *info[MAX_ARGS_SIZE], **args;
209   int stat;
210
211   if (!ValidName(argv[1]))
212     return DM_NORMAL;
213
214   if (!(stat = do_mr_query("get_zephyr_class", 1, argv + 1, NULL, NULL)))
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;
230     }
231
232   if ((stat = do_mr_query("add_zephyr_class", CountArgs(args), args,
233                           NULL, NULL)))
234     com_err(program_name, stat, " in AddZephyr");
235
236   FreeInfo(info);
237   return DM_NORMAL;
238 }
239
240
241 /* Does the work of an update */
242
243 static void RealUpdateZephyr(char **info, Bool junk)
244 {
245   int stat;
246   char **args;
247
248   if (!(args = AskZephyrInfo(info, TRUE)))
249     {
250       Put_message("Aborted.");
251       return;
252     }
253   if ((stat = do_mr_query("update_zephyr_class", CountArgs(args), args,
254                           NULL, NULL)))
255     {
256       com_err(program_name, stat, " in UpdateZephyr.");
257       Put_message("Zephyr class ** NOT ** Updated.");
258     }
259   else
260     Put_message("Zephyr class successfully updated.");
261 }
262
263
264 /* Change zephyr info */
265
266 int ChngZephyr(int argc, char **argv)
267 {
268   struct mqelem *top;
269
270   top = GetZephyrInfo(argv[1]);
271   QueryLoop(top, NullPrint, RealUpdateZephyr, "Update class");
272
273   FreeQueue(top);
274   return DM_NORMAL;
275 }
This page took 0.097226 seconds and 5 git commands to generate.