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];
83 if (!info) /* If no informaion */
85 Put_message("PrintACLInfo called with null info!");
89 sprintf(buf, "Host: %s", info[ACL_HOST]);
91 sprintf(buf, "Target file: %s", info[ACL_TARGET]);
93 sprintf(buf, "Kind: %-20s List: %s", info[ACL_KIND], info[ACL_LIST]);
96 sprintf(name, "%s:%s", info[ACL_HOST], info[ACL_TARGET]);
100 /* Function Name: AskACLInfo.
101 * Description: This function askes the user for information about an
102 * ACL and saves it into a structure.
103 * Arguments: info - a pointer the the structure to put the
108 static char **AskACLInfo(char **info)
110 char temp_buf[BUFSIZ];
113 info[ACL_HOST] = canonicalize_hostname(info[ACL_HOST]);
114 sprintf(temp_buf, "ACL %s:%s.", info[ACL_HOST], info[ACL_TARGET]);
115 Put_message(temp_buf);
118 if (GetTypeFromUser("Kind of ACL", "acl_kind", &info[ACL_KIND]) ==
121 if (GetValueFromUser("List name", &info[ACL_LIST]) == SUB_ERROR)
124 FreeAndClear(&info[ACL_MODTIME], TRUE);
125 FreeAndClear(&info[ACL_MODBY], TRUE);
126 FreeAndClear(&info[ACL_MODWITH], TRUE);
131 /* ---------------- ACL Menu ------------------ */
133 /* Function Name: GetACL
134 * Description: Get ACL information
135 * Arguments: argc, argv - host and target file
136 * Returns: DM_NORMAL.
139 int GetACL(int argc, char **argv)
143 top = GetACLInfo(argv[1], argv[2]);
144 Loop(top, (void (*)(char **)) PrintACLInfo);
145 FreeQueue(top); /* clean the queue. */
149 /* Function Name: RealDeleteACL
150 * Description: Does the real deletion work.
151 * Arguments: info - array of char *'s containing all useful info.
152 * one_item - a Boolean that is true if only one item
153 * in queue that dumped us here.
157 void RealDeleteACL(char **info, Bool one_item)
161 if ((stat = do_mr_query("delete_acl", 2, &info[ACL_HOST], NULL, NULL)))
162 com_err(program_name, stat, " ACL not deleted.");
164 Put_message("ACL deleted.");
167 /* Function Name: DeleteACL
168 * Description: Delete an ACL given its name.
169 * Arguments: argc, argv - host/target of the ACL
173 int DeleteACL(int argc, char **argv)
175 struct mqelem *elem = GetACLInfo(argv[1], argv[2]);
176 QueryLoop(elem, PrintACLInfo, RealDeleteACL, "Delete ACL");
182 /* Function Name: AddACL
183 * Description: Add an ACL
184 * Arguments: arc, argv - host/target of the ACL
185 * Returns: DM_NORMAL.
188 int AddACL(int argc, char **argv)
190 char *info[MAX_ARGS_SIZE], **args;
193 argv[1] = canonicalize_hostname(strdup(argv[1]));
194 if (!(stat = do_mr_query("get_acl", 2, argv + 1, NULL, NULL)))
196 Put_message ("An ACL for that host and target already exists.");
200 else if (stat != MR_NO_MATCH)
202 com_err(program_name, stat, " in AddACL");
207 args = AskACLInfo(SetDefaults(info, argv[1], argv[2]));
211 Put_message("Aborted.");
215 if ((stat = do_mr_query("add_acl", CountArgs(args), args, NULL, NULL)))
216 com_err(program_name, stat, " in AddACL");