3 * This is the file acl.c for the Moira Client, which allows users
4 * to quickly and easily maintain most parts of the Moira database.
5 * It Contains: Functions for handling generic ACLs.
7 * Copyright (C) 1999 by the Massachusetts Institute of Technology.
8 * For copying and distribution information, please see the file
12 #include <mit-copyright.h>
14 #include <moira_site.h>
25 void RealDeleteACL(char **info, Bool one_item);
26 void ChangeACL(char **info, Bool one_item);
28 /* Function Name: SetDefaults
29 * Description: sets the default values for ACL additions.
30 * Arguments: info - an array of char pointers to recieve defaults.
31 * Returns: char ** (this array, now filled).
34 static char **SetDefaults(char **info, char *host, char *target)
36 info[ACL_HOST] = strdup(host);
37 info[ACL_TARGET] = strdup(target);
38 info[ACL_KIND] = strdup("");
39 info[ACL_LIST] = strdup("");
40 info[ACL_MODTIME] = info[ACL_MODBY] = info[ACL_MODWITH] = NULL;
46 /* Function Name: GetACLInfo
47 * Description: Stores the info in a queue.
48 * Arguments: host, target - ACL to get info on
49 * Returns: a pointer to the first element in the queue or null
53 static struct mqelem *GetACLInfo(char *host, char *target)
56 struct mqelem *elem = NULL;
59 argv[0] = canonicalize_hostname(strdup(host));
61 stat = do_mr_query("get_acl", 2, argv, StoreInfo, &elem);
66 com_err(program_name, stat, " in GetACLInfo");
69 return QueueTop(elem);
72 /* Function Name: PrintACLInfo
73 * Description: Yet another specialized print function.
74 * Arguments: info - all info about this ACL.
75 * Returns: a static buffer...
78 static char *PrintACLInfo(char **info)
80 static char name[BUFSIZ];
84 if (!info) /* If no informaion */
86 Put_message("PrintACLInfo called with null info!");
90 sprintf(buf, "Host: %s", info[ACL_HOST]);
92 sprintf(buf, "Target file: %s", info[ACL_TARGET]);
94 sprintf(buf, "Kind: %-20s List: %s", info[ACL_KIND], info[ACL_LIST]);
97 sprintf(name, "%s:%s", info[ACL_HOST], info[ACL_TARGET]);
101 /* Function Name: AskACLInfo.
102 * Description: This function askes the user for information about an
103 * ACL and saves it into a structure.
104 * Arguments: info - a pointer the the structure to put the
109 static char **AskACLInfo(char **info)
111 char temp_buf[BUFSIZ];
117 info[ACL_HOST] = canonicalize_hostname(info[ACL_HOST]);
118 sprintf(temp_buf, "ACL %s:%s.", info[ACL_HOST], info[ACL_TARGET]);
119 Put_message(temp_buf);
122 if (GetTypeFromUser("Kind of ACL", "acl_kind", &info[ACL_KIND]) ==
125 if (GetValueFromUser("List name", &info[ACL_LIST]) == SUB_ERROR)
128 FreeAndClear(&info[ACL_MODTIME], TRUE);
129 FreeAndClear(&info[ACL_MODBY], TRUE);
130 FreeAndClear(&info[ACL_MODWITH], TRUE);
135 /* ---------------- ACL Menu ------------------ */
137 /* Function Name: GetACL
138 * Description: Get ACL information
139 * Arguments: argc, argv - host and target file
140 * Returns: DM_NORMAL.
143 int GetACL(int argc, char **argv)
147 top = GetACLInfo(argv[1], argv[2]);
148 Loop(top, (void (*)(char **)) PrintACLInfo);
149 FreeQueue(top); /* clean the queue. */
153 /* Function Name: RealDeleteACL
154 * Description: Does the real deletion work.
155 * Arguments: info - array of char *'s containing all useful info.
156 * one_item - a Boolean that is true if only one item
157 * in queue that dumped us here.
161 void RealDeleteACL(char **info, Bool one_item)
165 if ((stat = do_mr_query("delete_acl", 2, &info[ACL_HOST], NULL, NULL)))
166 com_err(program_name, stat, " ACL not deleted.");
168 Put_message("ACL deleted.");
171 /* Function Name: DeleteACL
172 * Description: Delete an ACL given its name.
173 * Arguments: argc, argv - host/target of the ACL
177 int DeleteACL(int argc, char **argv)
179 struct mqelem *elem = GetACLInfo(argv[1], argv[2]);
180 QueryLoop(elem, PrintACLInfo, RealDeleteACL, "Delete ACL");
186 /* Function Name: AddACL
187 * Description: Add an ACL
188 * Arguments: arc, argv - host/target of the ACL
189 * Returns: DM_NORMAL.
192 int AddACL(int argc, char **argv)
194 char *info[MAX_ARGS_SIZE], **args, *host;
197 argv[1] = canonicalize_hostname(strdup(argv[1]));
198 if (!(stat = do_mr_query("get_acl", 2, argv + 1, NULL, NULL)))
200 Put_message ("An ACL for that host and target already exists.");
204 else if (stat != MR_NO_MATCH)
206 com_err(program_name, stat, " in AddACL");
211 args = AskACLInfo(SetDefaults(info, argv[1], argv[2]));
215 Put_message("Aborted.");
219 if ((stat = do_mr_query("add_acl", CountArgs(args), args, NULL, NULL)))
220 com_err(program_name, stat, " in AddACL");