exec_prefix=@exec_prefix@
bindir=@bindir@
-MOBJS= attach.o cluster.o delete.o globals.o lists.o main.o menu.o \
+MOBJS= acl.o attach.o cluster.o delete.o globals.o lists.o main.o menu.o \
menus.o nfs.o pobox.o quota.o user.o utils.o dcmmaint.o printer.o \
misc.o zephyr.o
NOBJS= namespace.o globals.o lists.o menu.o pobox.o user.o utils.o misc.o
--- /dev/null
+/* $Id$
+ *
+ * This is the file acl.c for the Moira Client, which allows users
+ * to quickly and easily maintain most parts of the Moira database.
+ * It Contains: Functions for handling generic ACLs.
+ *
+ * Copyright (C) 1999 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
+ */
+
+#include <mit-copyright.h>
+#include <moira.h>
+#include <moira_site.h>
+#include "defs.h"
+#include "f_defs.h"
+#include "globals.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+RCSID("$Header$");
+
+void RealDeleteACL(char **info, Bool one_item);
+void ChangeACL(char **info, Bool one_item);
+
+/* Function Name: SetDefaults
+ * Description: sets the default values for ACL additions.
+ * Arguments: info - an array of char pointers to recieve defaults.
+ * Returns: char ** (this array, now filled).
+ */
+
+static char **SetDefaults(char **info, char *host, char *target)
+{
+ info[ACL_HOST] = strdup(host);
+ info[ACL_TARGET] = strdup(target);
+ info[ACL_KIND] = strdup("");
+ info[ACL_LIST] = strdup("");
+ info[ACL_MODTIME] = info[ACL_MODBY] = info[ACL_MODWITH] = NULL;
+
+ info[ACL_END] = NULL;
+ return info;
+}
+
+/* Function Name: GetACLInfo
+ * Description: Stores the info in a queue.
+ * Arguments: host, target - ACL to get info on
+ * Returns: a pointer to the first element in the queue or null
+ * if ACL not found.
+ */
+
+static struct mqelem *GetACLInfo(char *host, char *target)
+{
+ int stat;
+ struct mqelem *elem = NULL;
+ char *argv[2];
+
+ argv[0] = canonicalize_hostname(strdup(host));
+ argv[1] = target;
+ stat = do_mr_query("get_acl", 2, argv, StoreInfo, &elem);
+ free(argv[0]);
+
+ if (stat)
+ {
+ com_err(program_name, stat, " in GetACLInfo");
+ return NULL;
+ }
+ return QueueTop(elem);
+}
+
+/* Function Name: PrintACLInfo
+ * Description: Yet another specialized print function.
+ * Arguments: info - all info about this ACL.
+ * Returns: a static buffer...
+ */
+
+static char *PrintACLInfo(char **info)
+{
+ static char name[BUFSIZ];
+ char buf[BUFSIZ];
+ int status;
+
+ if (!info) /* If no informaion */
+ {
+ Put_message("PrintACLInfo called with null info!");
+ return NULL;
+ }
+ Put_message("");
+ sprintf(buf, "Host: %s", info[ACL_HOST]);
+ Put_message(buf);
+ sprintf(buf, "Target file: %s", info[ACL_TARGET]);
+ Put_message(buf);
+ sprintf(buf, "Kind: %-20s List: %s", info[ACL_KIND], info[ACL_LIST]);
+ Put_message(buf);
+
+ sprintf(name, "%s:%s", info[ACL_HOST], info[ACL_TARGET]);
+ return name;
+}
+
+/* Function Name: AskACLInfo.
+ * Description: This function askes the user for information about an
+ * ACL and saves it into a structure.
+ * Arguments: info - a pointer the the structure to put the
+ * info into.
+ * Returns: none.
+ */
+
+static char **AskACLInfo(char **info)
+{
+ char temp_buf[BUFSIZ];
+ char *args[3];
+ char *s, *d;
+ int status;
+
+ Put_message("");
+ info[ACL_HOST] = canonicalize_hostname(info[ACL_HOST]);
+ sprintf(temp_buf, "ACL %s:%s.", info[ACL_HOST], info[ACL_TARGET]);
+ Put_message(temp_buf);
+ Put_message("");
+
+ if (GetTypeFromUser("Kind of ACL", "acl_kind", &info[ACL_KIND]) ==
+ SUB_ERROR)
+ return NULL;
+ if (GetValueFromUser("List name", &info[ACL_LIST]) == SUB_ERROR)
+ return NULL;
+
+ FreeAndClear(&info[ACL_MODTIME], TRUE);
+ FreeAndClear(&info[ACL_MODBY], TRUE);
+ FreeAndClear(&info[ACL_MODWITH], TRUE);
+
+ return info;
+}
+
+/* ---------------- ACL Menu ------------------ */
+
+/* Function Name: GetACL
+ * Description: Get ACL information
+ * Arguments: argc, argv - host and target file
+ * Returns: DM_NORMAL.
+ */
+
+int GetACL(int argc, char **argv)
+{
+ struct mqelem *top;
+
+ top = GetACLInfo(argv[1], argv[2]);
+ Loop(top, (void (*)(char **)) PrintACLInfo);
+ FreeQueue(top); /* clean the queue. */
+ return DM_NORMAL;
+}
+
+/* Function Name: RealDeleteACL
+ * Description: Does the real deletion work.
+ * Arguments: info - array of char *'s containing all useful info.
+ * one_item - a Boolean that is true if only one item
+ * in queue that dumped us here.
+ * Returns: none.
+ */
+
+void RealDeleteACL(char **info, Bool one_item)
+{
+ int stat;
+
+ if ((stat = do_mr_query("delete_acl", 2, &info[ACL_HOST], NULL, NULL)))
+ com_err(program_name, stat, " ACL not deleted.");
+ else
+ Put_message("ACL deleted.");
+}
+
+/* Function Name: DeleteACL
+ * Description: Delete an ACL given its name.
+ * Arguments: argc, argv - host/target of the ACL
+ * Returns: none.
+ */
+
+int DeleteACL(int argc, char **argv)
+{
+ struct mqelem *elem = GetACLInfo(argv[1], argv[2]);
+ QueryLoop(elem, PrintACLInfo, RealDeleteACL, "Delete ACL");
+
+ FreeQueue(elem);
+ return DM_NORMAL;
+}
+
+/* Function Name: AddACL
+ * Description: Add an ACL
+ * Arguments: arc, argv - host/target of the ACL
+ * Returns: DM_NORMAL.
+ */
+
+int AddACL(int argc, char **argv)
+{
+ char *info[MAX_ARGS_SIZE], **args, *host;
+ int stat;
+
+ argv[1] = canonicalize_hostname(strdup(argv[1]));
+ if (!(stat = do_mr_query("get_acl", 2, argv + 1, NULL, NULL)))
+ {
+ Put_message ("An ACL for that host and target already exists.");
+ free(argv[1]);
+ return DM_NORMAL;
+ }
+ else if (stat != MR_NO_MATCH)
+ {
+ com_err(program_name, stat, " in AddACL");
+ free(argv[1]);
+ return DM_NORMAL;
+ }
+
+ args = AskACLInfo(SetDefaults(info, argv[1], argv[2]));
+ free(argv[1]);
+ if (!args)
+ {
+ Put_message("Aborted.");
+ return DM_NORMAL;
+ }
+
+ if ((stat = do_mr_query("add_acl", CountArgs(args), args, NULL, NULL)))
+ com_err(program_name, stat, " in AddACL");
+
+ FreeInfo(info);
+ return DM_NORMAL;
+}
#ifndef _f_defs_
#define _f_defs_
+/* acl.c */
+int GetACL(int argc, char **argv);
+int AddACL(int argc, char **argv);
+int DeleteACL(int argc, char **argv);
+
/* attach.c */
int GetFS(int argc, char **argv);
int ListListMembers(int argc, char **argv);
int ListStringMembers(int argc, char **argv);
+int TagMember(int argc, char **argv);
+int DeleteTag(int argc, char **argv);
+int ListMembersWithTags(int argc, char **argv);
+
int ShowListInfo(int argc, char **argv);
int UpdateList(int argc, char **argv);
int InterRemoveItemFromLists(int argc, char **argv);
struct mqelem *GetListInfo(int type, char *name1, char *name2);
char **AskListInfo(char **info, Bool name);
int AddList(int argc, char **argv);
-void ListMembersByType(char *type);
+void ListMembersByType(char *type, int tags);
int GetMemberInfo(char *action, char **ret_argv);
#define LIST 0
static char current_list[BUFSIZ];
+
/* Function Name: PrintListAce
* Description: This function prints the list ace information.
* Arguments: info - an info structure.
/* Function Name: ListMembersByType
* Description: This function lists the users of a list by type.
* Arguments: type - the type of the list "USER", "LIST", or "STRING".
+ * tags - whether or not to display tags
* Returns: none.
* NOTE: if type is NULL, all lists members are listed.
*/
-void ListMembersByType(char *type)
+void ListMembersByType(char *type, int tags)
{
char temp_buf[BUFSIZ];
int status;
args[1] = NULL;
found_some = FALSE;
- if ((status = do_mr_query("get_members_of_list", CountArgs(args), args,
- PrintByType, type)))
+ if ((status = do_mr_query(tags ? "get_tagged_members_of_list" :
+ "get_members_of_list", CountArgs(args),
+ args, PrintByType, type)))
com_err(program_name, status, " in ListMembersByType");
if (!found_some)
{
int ListAllMembers(int argc, char **argv)
{
- ListMembersByType(NULL);
+ ListMembersByType(NULL, 0);
return DM_NORMAL;
}
int ListUserMembers(int argc, char **argv)
{
- ListMembersByType("USER");
+ ListMembersByType("USER", 0);
return DM_NORMAL;
}
int ListListMembers(int argc, char **argv)
{
- ListMembersByType("LIST");
+ ListMembersByType("LIST", 0);
return DM_NORMAL;
}
int ListStringMembers(int argc, char **argv)
{
- ListMembersByType("STRING");
+ ListMembersByType("STRING", 0);
return DM_NORMAL;
}
return DM_NORMAL;
}
+/* Function Name: TagMember
+ * Description: Add a tag to a list member
+ * Arguments:
+ * Returns: DM_NORMAL
+ */
+
+int TagMember(int argc, char **argv)
+{
+ char *args[10];
+ int status;
+ char temp_buf[BUFSIZ];
+
+ if (GetMemberInfo("tag", args) == SUB_ERROR)
+ return DM_NORMAL;
+
+ args[LM_TAG] = strdup("");
+ if (GetValueFromUser("Tag" , &args[LM_TAG]) == SUB_ERROR)
+ {
+ Put_message("Aborted.");
+ return DM_NORMAL;
+ }
+ args[LM_TAG_END] = NULL; /* NULL terminate this list. */
+
+ if ((status = do_mr_query("tag_member_of_list", CountArgs(args),
+ args, NULL, NULL)))
+ com_err(program_name, status, " in TagMember");
+
+ FreeInfo(args);
+ return DM_NORMAL;
+}
+
+/* Function Name: ListAllMembers
+ * Description: lists all members of the current list.
+ * Arguments:
+ * Returns: DM_NORMAL
+ */
+
+int ListMembersWithTags(int argc, char **argv)
+{
+ ListMembersByType(NULL, 1);
+ return DM_NORMAL;
+}
+
/* Function Name: InterRemoveItemFromLists
* Description: This function allows interactive removal of an item
* (user, string, list) for all list that it is on.
}
};
+/*
+ * List Member Tags Menu
+ */
+
+Menu list_tags_menu = {
+ NULL,
+ NULL,
+ "List Member Tags Menu",
+ 2,
+ {
+ SIMPLEFUNC("change", "Change the tag on a list member", TagMember),
+ SIMPLEFUNC("show", "Show all list members with tags", ListMembersWithTags),
+ }
+};
+
/*
* List Member Menu
*/
ListmaintMemberMenuEntry,
ListmaintMemberMenuExit,
NULL,
- 7,
+ 8,
{
SIMPLEFUNC("add", "Add a member to this list", AddMember),
SIMPLEFUNC("remove", "Remove a member from this list", DeleteMember),
SIMPLEFUNC("list", "Show the members of type LIST", ListListMembers),
SIMPLEFUNC("string", "Show the members of type STRING",
ListStringMembers),
+ SUBMENU("tags", "List Member Tags Menu", &list_tags_menu),
SIMPLEFUNC("verbose", "Toggle Verbosity of Delete", ToggleVerboseMode)
}
};
}
};
+/*
+ * ACL Menu
+ */
+
+Menu acl_menu = {
+ NULLFUNC,
+ NULLFUNC,
+ "Generic ACL Menu",
+ 3,
+ {
+ { GetACL, NULLMENU, 3, {
+ {"get", "Get ACL Information"},
+ {"host", "Machine: "},
+ {"target", "Target file: "}
+ } },
+ { AddACL, NULLMENU, 3, {
+ {"add", "Add New ACL"},
+ {"host", "Machine: "},
+ {"target", "Target file: "}
+ } },
+ { DeleteACL, NULLMENU, 3, {
+ {"delete", "Delete ACL"},
+ {"host", "Machine: "},
+ {"target", "Target file: "}
+ } },
+ }
+};
/*
* Miscellaneous Menu
SUBMENU("user", "User Menu", &user_menu),
SUBMENU("zephyr", "Zephyr ACLS Menu", &zephyr_menu),
SUBMENU("dcm", "DCM Menu", &dcm_menu),
+ SUBMENU("acl", "Generic ACL Menu", &acl_menu),
SUBMENU("misc", "Miscellaneous Menu", &misc_menu)
}
};
}
}
- if (GetTypeFromUser("What kind of transmit restriction", "ace_type",
+ if (GetTypeFromUser("What kind of transmit restriction", "zace_type",
&info[ZA_XMT_TYPE]) == SUB_ERROR)
return NULL;
- if (strcasecmp(info[ZA_XMT_TYPE], "NONE"))
+ if (strcasecmp(info[ZA_XMT_TYPE], "NONE") &&
+ strcasecmp(info[ZA_XMT_TYPE], "ALL"))
{
sprintf(buf, "Which %s: ", info[ZA_XMT_TYPE]);
if (GetValueFromUser(buf, &info[ZA_XMT_ID]) == SUB_ERROR)
return NULL;
}
- if (GetTypeFromUser("What kind of subscription restriction", "ace_type",
+ if (GetTypeFromUser("What kind of subscription restriction", "zace_type",
&info[ZA_SUB_TYPE]) == SUB_ERROR)
return NULL;
- if (strcasecmp(info[ZA_SUB_TYPE], "NONE"))
+ if (strcasecmp(info[ZA_SUB_TYPE], "NONE") &&
+ strcasecmp(info[ZA_SUB_TYPE], "ALL"))
{
sprintf(buf, "Which %s: ", info[ZA_SUB_TYPE]);
if (GetValueFromUser(buf, &info[ZA_SUB_ID]) == SUB_ERROR)
return NULL;
}
if (GetTypeFromUser("What kind of wildcard instance restriction",
- "ace_type", &info[ZA_IWS_TYPE]) == SUB_ERROR)
+ "zace_type", &info[ZA_IWS_TYPE]) == SUB_ERROR)
return NULL;
- if (strcasecmp(info[ZA_IWS_TYPE], "NONE") != 0)
+ if (strcasecmp(info[ZA_IWS_TYPE], "NONE") &&
+ strcasecmp(info[ZA_IWS_TYPE], "ALL"))
{
sprintf(buf, "Which %s: ", info[ZA_IWS_TYPE]);
if (GetValueFromUser(buf, &info[ZA_IWS_ID]) == SUB_ERROR)
return NULL;
}
if (GetTypeFromUser("What kind of instance identity restriction",
- "ace_type", &info[ZA_IUI_TYPE]) == SUB_ERROR)
+ "zace_type", &info[ZA_IUI_TYPE]) == SUB_ERROR)
return NULL;
- if (strcasecmp(info[ZA_IUI_TYPE], "NONE"))
+ if (strcasecmp(info[ZA_IUI_TYPE], "NONE") &&
+ strcasecmp(info[ZA_IUI_TYPE], "ALL"))
{
sprintf(buf, "Which %s: ", info[ZA_IUI_TYPE]);
if (GetValueFromUser(buf, &info[ZA_IUI_ID]) == SUB_ERROR)