]> andersk Git - moira.git/blame - clients/moira/zephyr.c
deal with new get_pobox output
[moira.git] / clients / moira / zephyr.c
CommitLineData
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
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);
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 46static 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 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);
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 94static 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
5eaef520 116 if (GetTypeFromUser("What kind of transmit restriction", "ace_type",
117 &info[ZA_XMT_TYPE]) == SUB_ERROR)
118 return NULL;
119 if (strcasecmp(info[ZA_XMT_TYPE], "NONE"))
120 {
5eaef520 121 sprintf(buf, "Which %s: ", info[ZA_XMT_TYPE]);
122 if (GetValueFromUser(buf, &info[ZA_XMT_ID]) == SUB_ERROR)
123 return NULL;
703082ea 124 }
5eaef520 125 if (GetTypeFromUser("What kind of subscription restriction", "ace_type",
126 &info[ZA_SUB_TYPE]) == SUB_ERROR)
127 return NULL;
128 if (strcasecmp(info[ZA_SUB_TYPE], "NONE"))
129 {
5eaef520 130 sprintf(buf, "Which %s: ", info[ZA_SUB_TYPE]);
131 if (GetValueFromUser(buf, &info[ZA_SUB_ID]) == SUB_ERROR)
132 return NULL;
703082ea 133 }
5eaef520 134 if (GetTypeFromUser("What kind of wildcard instance restriction",
135 "ace_type", &info[ZA_IWS_TYPE]) == SUB_ERROR)
136 return NULL;
137 if (strcasecmp(info[ZA_IWS_TYPE], "NONE") != 0)
138 {
5eaef520 139 sprintf(buf, "Which %s: ", info[ZA_IWS_TYPE]);
140 if (GetValueFromUser(buf, &info[ZA_IWS_ID]) == SUB_ERROR)
141 return NULL;
703082ea 142 }
5eaef520 143 if (GetTypeFromUser("What kind of instance identity restriction",
144 "ace_type", &info[ZA_IUI_TYPE]) == SUB_ERROR)
145 return NULL;
146 if (strcasecmp(info[ZA_IUI_TYPE], "NONE"))
147 {
5eaef520 148 sprintf(buf, "Which %s: ", info[ZA_IUI_TYPE]);
149 if (GetValueFromUser(buf, &info[ZA_IUI_ID]) == SUB_ERROR)
150 return NULL;
703082ea 151 }
5eaef520 152 FreeAndClear(&info[ZA_MODTIME], TRUE);
153 FreeAndClear(&info[ZA_MODBY], TRUE);
154 FreeAndClear(&info[ZA_MODWITH], TRUE);
703082ea 155
5eaef520 156 if (rename)
157 SlipInNewName(info, newname);
158 return info;
703082ea 159}
160
161
162/* Menu entry for get zephyr */
5eaef520 163int GetZephyr(int argc, char **argv)
703082ea 164{
600b459e 165 struct mqelem *top;
703082ea 166
5eaef520 167 top = GetZephyrInfo(argv[1]);
a6da9354 168 Loop(top, (void (*)(char **)) PrintZephyrInfo);
5eaef520 169 FreeQueue(top);
170 return DM_NORMAL;
703082ea 171}
172
173
174/* Does the real work of a deletion */
175
5eaef520 176void RealDeleteZephyr(char **info, Bool one_item)
703082ea 177{
5eaef520 178 int stat;
703082ea 179
5eaef520 180 if ((stat = do_mr_query("delete_zephyr_class", 1, &info[ZA_CLASS],
7ac48069 181 NULL, NULL)))
5eaef520 182 com_err(program_name, stat, " zephyr class restriction not deleted.");
183 else
184 Put_message("Zephyr class restriction deleted.");
703082ea 185}
186
187
188/* Delete a zephyr class given it's name */
189
5eaef520 190int DeleteZephyr(int argc, char **argv)
703082ea 191{
600b459e 192 struct mqelem *elem = GetZephyrInfo(argv[1]);
5eaef520 193 QueryLoop(elem, PrintZephyrInfo, RealDeleteZephyr,
194 "Delete Zephyr class restriction for class ");
195 FreeQueue(elem);
196 return DM_NORMAL;
703082ea 197}
198
199
200/* Add a new zephyr class */
201
5eaef520 202int AddZephyr(int argc, char **argv)
703082ea 203{
5eaef520 204 char *info[MAX_ARGS_SIZE], **args;
205 int stat;
206
207 if (!ValidName(argv[1]))
208 return DM_NORMAL;
209
7ac48069 210 if (!(stat = do_mr_query("get_zephyr_class", 1, argv + 1, NULL, NULL)))
5eaef520 211 {
212 Put_message ("A Zephyr class by that name already exists.");
213 return DM_NORMAL;
214 }
215 else if (stat != MR_NO_MATCH)
216 {
217 com_err(program_name, stat, " in AddZehpyr");
218 return DM_NORMAL;
219 }
220
221 args = AskZephyrInfo(SetDefaults(info, argv[1]), FALSE);
222 if (!args)
223 {
224 Put_message("Aborted.");
225 return DM_NORMAL;
703082ea 226 }
227
5eaef520 228 if ((stat = do_mr_query("add_zephyr_class", CountArgs(args), args,
7ac48069 229 NULL, NULL)))
5eaef520 230 com_err(program_name, stat, " in AddZephyr");
703082ea 231
5eaef520 232 FreeInfo(info);
233 return DM_NORMAL;
703082ea 234}
235
236
237/* Does the work of an update */
238
5eaef520 239static void RealUpdateZephyr(char **info, Bool junk)
703082ea 240{
5eaef520 241 int stat;
242 char **args;
243
244 if (!(args = AskZephyrInfo(info, TRUE)))
245 {
246 Put_message("Aborted.");
247 return;
703082ea 248 }
5eaef520 249 if ((stat = do_mr_query("update_zephyr_class", CountArgs(args), args,
7ac48069 250 NULL, NULL)))
5eaef520 251 {
252 com_err(program_name, stat, " in UpdateZephyr.");
253 Put_message("Zephyr class ** NOT ** Updated.");
703082ea 254 }
5eaef520 255 else
256 Put_message("Zephyr class successfully updated.");
703082ea 257}
258
259
260/* Change zephyr info */
261
5eaef520 262int ChngZephyr(int argc, char **argv)
703082ea 263{
600b459e 264 struct mqelem *top;
703082ea 265
5eaef520 266 top = GetZephyrInfo(argv[1]);
267 QueryLoop(top, NullPrint, RealUpdateZephyr, "Update class");
703082ea 268
5eaef520 269 FreeQueue(top);
270 return DM_NORMAL;
703082ea 271}
This page took 0.190157 seconds and 5 git commands to generate.