]> andersk Git - moira.git/blame - clients/moira/zephyr.c
Need to fill in the "user" variable with mrcl_krb_user().
[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");
7c74578c 34 info[ZA_OWNER_TYPE] = strdup("NONE");
fe0b1121 35 info[ZA_XMT_ID] = strdup("");
36 info[ZA_SUB_ID] = strdup("");
37 info[ZA_IWS_ID] = strdup("");
38 info[ZA_IUI_ID] = strdup("");
7c74578c 39 info[ZA_OWNER_ID] = strdup("");
5eaef520 40 info[ZA_MODTIME] = info[ZA_MODBY] = info[ZA_MODWITH] = NULL;
41 info[ZA_END] = NULL;
42 return info;
703082ea 43}
44
45
46/* Get info from database */
47
600b459e 48static struct mqelem *GetZephyrInfo(char *name)
703082ea 49{
5eaef520 50 int stat;
600b459e 51 struct mqelem *elem = NULL;
5eaef520 52
7ac48069 53 if ((stat = do_mr_query("get_zephyr_class", 1, &name, StoreInfo, &elem)))
5eaef520 54 {
55 com_err(program_name, stat, " in GetZephyrInfo");
56 return NULL;
703082ea 57 }
5eaef520 58 return QueueTop(elem);
703082ea 59}
60
61
62/* Print zephyr acl info */
63
7ac48069 64static char *PrintZephyrInfo(char **info)
703082ea 65{
5eaef520 66 char buf[BUFSIZ];
703082ea 67
5eaef520 68 if (!info)
69 {
70 Put_message("PrintZephyrInfo called with null info!");
7ac48069 71 return NULL;
703082ea 72 }
5eaef520 73 sprintf(buf, " Zephyr class: %s", info[ZA_CLASS]);
74 Put_message(buf);
5eaef520 75 sprintf(buf, "Transmit ACL: %s %s", info[ZA_XMT_TYPE],
7c74578c 76 (strcasecmp(info[ZA_XMT_TYPE], "NONE") &&
77 strcasecmp(info[ZA_XMT_TYPE], "ALL")) ? info[ZA_XMT_ID] : "");
5eaef520 78 Put_message(buf);
5eaef520 79 sprintf(buf, "Subscription ACL: %s %s", info[ZA_SUB_TYPE],
7c74578c 80 (strcasecmp(info[ZA_SUB_TYPE], "NONE") &&
81 strcasecmp(info[ZA_SUB_TYPE], "ALL")) ? info[ZA_SUB_ID] : "");
5eaef520 82 Put_message(buf);
5eaef520 83 sprintf(buf, "Instance Wildcard ACL: %s %s", info[ZA_IWS_TYPE],
7c74578c 84 (strcasecmp(info[ZA_IWS_TYPE], "NONE") &&
85 strcasecmp(info[ZA_IWS_TYPE], "ALL")) ? info[ZA_IWS_ID] : "");
5eaef520 86 Put_message(buf);
115fa5cb 87 sprintf(buf, "Instance Identity ACL: %s %s", info[ZA_IUI_TYPE],
7c74578c 88 (strcasecmp(info[ZA_IUI_TYPE], "NONE") &&
89 strcasecmp(info[ZA_IUI_TYPE], "ALL")) ? info[ZA_IUI_ID] : "");
90 Put_message(buf);
91 sprintf(buf, "Owner: %s %s", info[ZA_OWNER_TYPE],
92 (strcasecmp(info[ZA_OWNER_TYPE], "NONE") &&
93 strcasecmp(info[ZA_OWNER_TYPE], "ALL")) ? info[ZA_OWNER_ID] : "");
5eaef520 94 Put_message(buf);
95 sprintf(buf, MOD_FORMAT, info[ZA_MODBY], info[ZA_MODTIME], info[ZA_MODWITH]);
96 Put_message(buf);
7ac48069 97
98 return info[ZA_CLASS];
703082ea 99}
100
101
102/* Get info from user. Expects info to already be filled in with defaults */
103
5eaef520 104static char **AskZephyrInfo(char **info, Bool rename)
703082ea 105{
5eaef520 106 char buf[BUFSIZ], *newname;
107
108 Put_message("");
109 sprintf(buf, "Zephyr class restrictions for %s.", info[ZA_CLASS]);
110 Put_message(buf);
111 Put_message("");
112
113 if (rename)
114 {
115 while (1)
116 {
7ac48069 117 newname = strdup(info[ZA_CLASS]);
5eaef520 118 if (GetValueFromUser("The new name for this class", &newname) ==
119 SUB_ERROR)
120 return NULL;
121 if (ValidName(newname))
122 break;
123 }
703082ea 124 }
125
17bbb3bc 126 if (GetTypeFromUser("What kind of transmit restriction", "zace_type",
5eaef520 127 &info[ZA_XMT_TYPE]) == SUB_ERROR)
128 return NULL;
17bbb3bc 129 if (strcasecmp(info[ZA_XMT_TYPE], "NONE") &&
130 strcasecmp(info[ZA_XMT_TYPE], "ALL"))
5eaef520 131 {
5eaef520 132 sprintf(buf, "Which %s: ", info[ZA_XMT_TYPE]);
133 if (GetValueFromUser(buf, &info[ZA_XMT_ID]) == SUB_ERROR)
134 return NULL;
703082ea 135 }
17bbb3bc 136 if (GetTypeFromUser("What kind of subscription restriction", "zace_type",
5eaef520 137 &info[ZA_SUB_TYPE]) == SUB_ERROR)
138 return NULL;
17bbb3bc 139 if (strcasecmp(info[ZA_SUB_TYPE], "NONE") &&
140 strcasecmp(info[ZA_SUB_TYPE], "ALL"))
5eaef520 141 {
5eaef520 142 sprintf(buf, "Which %s: ", info[ZA_SUB_TYPE]);
143 if (GetValueFromUser(buf, &info[ZA_SUB_ID]) == SUB_ERROR)
144 return NULL;
703082ea 145 }
5eaef520 146 if (GetTypeFromUser("What kind of wildcard instance restriction",
17bbb3bc 147 "zace_type", &info[ZA_IWS_TYPE]) == SUB_ERROR)
5eaef520 148 return NULL;
17bbb3bc 149 if (strcasecmp(info[ZA_IWS_TYPE], "NONE") &&
150 strcasecmp(info[ZA_IWS_TYPE], "ALL"))
5eaef520 151 {
5eaef520 152 sprintf(buf, "Which %s: ", info[ZA_IWS_TYPE]);
153 if (GetValueFromUser(buf, &info[ZA_IWS_ID]) == SUB_ERROR)
154 return NULL;
703082ea 155 }
5eaef520 156 if (GetTypeFromUser("What kind of instance identity restriction",
17bbb3bc 157 "zace_type", &info[ZA_IUI_TYPE]) == SUB_ERROR)
5eaef520 158 return NULL;
17bbb3bc 159 if (strcasecmp(info[ZA_IUI_TYPE], "NONE") &&
160 strcasecmp(info[ZA_IUI_TYPE], "ALL"))
5eaef520 161 {
5eaef520 162 sprintf(buf, "Which %s: ", info[ZA_IUI_TYPE]);
163 if (GetValueFromUser(buf, &info[ZA_IUI_ID]) == SUB_ERROR)
164 return NULL;
703082ea 165 }
7c74578c 166 if (GetTypeFromUser("What kind of Administrator", "ace_type",
167 &info[ZA_OWNER_TYPE]) == SUB_ERROR)
168 return NULL;
169 if (strcasecmp(info[ZA_OWNER_TYPE], "NONE"))
170 {
171 sprintf(buf, "Which %s: ", info[ZA_OWNER_TYPE]);
172 if (GetValueFromUser(buf, &info[ZA_OWNER_ID]) == SUB_ERROR)
173 return NULL;
174 }
5eaef520 175 FreeAndClear(&info[ZA_MODTIME], TRUE);
176 FreeAndClear(&info[ZA_MODBY], TRUE);
177 FreeAndClear(&info[ZA_MODWITH], TRUE);
703082ea 178
5eaef520 179 if (rename)
180 SlipInNewName(info, newname);
181 return info;
703082ea 182}
183
184
185/* Menu entry for get zephyr */
5eaef520 186int GetZephyr(int argc, char **argv)
703082ea 187{
600b459e 188 struct mqelem *top;
703082ea 189
5eaef520 190 top = GetZephyrInfo(argv[1]);
a6da9354 191 Loop(top, (void (*)(char **)) PrintZephyrInfo);
5eaef520 192 FreeQueue(top);
193 return DM_NORMAL;
703082ea 194}
195
196
197/* Does the real work of a deletion */
198
5eaef520 199void RealDeleteZephyr(char **info, Bool one_item)
703082ea 200{
5eaef520 201 int stat;
703082ea 202
5eaef520 203 if ((stat = do_mr_query("delete_zephyr_class", 1, &info[ZA_CLASS],
7ac48069 204 NULL, NULL)))
5eaef520 205 com_err(program_name, stat, " zephyr class restriction not deleted.");
206 else
207 Put_message("Zephyr class restriction deleted.");
703082ea 208}
209
210
211/* Delete a zephyr class given it's name */
212
5eaef520 213int DeleteZephyr(int argc, char **argv)
703082ea 214{
600b459e 215 struct mqelem *elem = GetZephyrInfo(argv[1]);
5eaef520 216 QueryLoop(elem, PrintZephyrInfo, RealDeleteZephyr,
217 "Delete Zephyr class restriction for class ");
218 FreeQueue(elem);
219 return DM_NORMAL;
703082ea 220}
221
222
223/* Add a new zephyr class */
224
5eaef520 225int AddZephyr(int argc, char **argv)
703082ea 226{
5eaef520 227 char *info[MAX_ARGS_SIZE], **args;
228 int stat;
229
230 if (!ValidName(argv[1]))
231 return DM_NORMAL;
232
7ac48069 233 if (!(stat = do_mr_query("get_zephyr_class", 1, argv + 1, NULL, NULL)))
5eaef520 234 {
235 Put_message ("A Zephyr class by that name already exists.");
236 return DM_NORMAL;
237 }
238 else if (stat != MR_NO_MATCH)
239 {
240 com_err(program_name, stat, " in AddZehpyr");
241 return DM_NORMAL;
242 }
243
244 args = AskZephyrInfo(SetDefaults(info, argv[1]), FALSE);
245 if (!args)
246 {
247 Put_message("Aborted.");
248 return DM_NORMAL;
703082ea 249 }
250
5eaef520 251 if ((stat = do_mr_query("add_zephyr_class", CountArgs(args), args,
7ac48069 252 NULL, NULL)))
5eaef520 253 com_err(program_name, stat, " in AddZephyr");
703082ea 254
5eaef520 255 FreeInfo(info);
256 return DM_NORMAL;
703082ea 257}
258
259
260/* Does the work of an update */
261
5eaef520 262static void RealUpdateZephyr(char **info, Bool junk)
703082ea 263{
5eaef520 264 int stat;
265 char **args;
266
267 if (!(args = AskZephyrInfo(info, TRUE)))
268 {
269 Put_message("Aborted.");
270 return;
703082ea 271 }
5eaef520 272 if ((stat = do_mr_query("update_zephyr_class", CountArgs(args), args,
7ac48069 273 NULL, NULL)))
5eaef520 274 {
275 com_err(program_name, stat, " in UpdateZephyr.");
276 Put_message("Zephyr class ** NOT ** Updated.");
703082ea 277 }
5eaef520 278 else
279 Put_message("Zephyr class successfully updated.");
703082ea 280}
281
282
283/* Change zephyr info */
284
5eaef520 285int ChngZephyr(int argc, char **argv)
703082ea 286{
600b459e 287 struct mqelem *top;
703082ea 288
5eaef520 289 top = GetZephyrInfo(argv[1]);
290 QueryLoop(top, NullPrint, RealUpdateZephyr, "Update class");
703082ea 291
5eaef520 292 FreeQueue(top);
293 return DM_NORMAL;
703082ea 294}
This page took 0.154326 seconds and 5 git commands to generate.