]> andersk Git - moira.git/commitdiff
add acl and tag support, fix up zephyr support
authordanw <danw>
Fri, 7 Jan 2000 21:14:04 +0000 (21:14 +0000)
committerdanw <danw>
Fri, 7 Jan 2000 21:14:04 +0000 (21:14 +0000)
clients/moira/Makefile.in
clients/moira/acl.c [new file with mode: 0644]
clients/moira/f_defs.h
clients/moira/lists.c
clients/moira/menus.c
clients/moira/zephyr.c

index ededb157f4895d9f0e766776654352d392f28d73..ffdb399a5044fa5e662b7ee016c444ec8e3fb1cf 100644 (file)
@@ -23,7 +23,7 @@ prefix=@prefix@
 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
diff --git a/clients/moira/acl.c b/clients/moira/acl.c
new file mode 100644 (file)
index 0000000..3009def
--- /dev/null
@@ -0,0 +1,224 @@
+/* $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;
+}
index f5181a4d2a58d340c00ec94da6d7650fb4603104..394c79cd8313b1b3c62ff0be23607ee77f9e8ae3 100644 (file)
 #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);
@@ -89,6 +94,10 @@ int ListUserMembers(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);
index fb2d3cca5a0cd7eab9e4c11d68abf8c0a33336ac..337c22fb9d8923107533718ebf25f35a77ec8736 100644 (file)
@@ -28,7 +28,7 @@ RCSID("$Header$");
 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
@@ -50,6 +50,7 @@ int GetMemberInfo(char *action, char **ret_argv);
 
 static char current_list[BUFSIZ];
 
+
 /*     Function Name: PrintListAce
  *     Description: This function prints the list ace information.
  *     Arguments: info - an info structure.
@@ -513,11 +514,12 @@ int ListmaintMemberMenuExit(Menu *m)
 /*     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;
@@ -527,8 +529,9 @@ void ListMembersByType(char *type)
   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)
     {
@@ -550,7 +553,7 @@ void ListMembersByType(char *type)
 
 int ListAllMembers(int argc, char **argv)
 {
-  ListMembersByType(NULL);
+  ListMembersByType(NULL, 0);
   return DM_NORMAL;
 }
 
@@ -562,7 +565,7 @@ int ListAllMembers(int argc, char **argv)
 
 int ListUserMembers(int argc, char **argv)
 {
-  ListMembersByType("USER");
+  ListMembersByType("USER", 0);
   return DM_NORMAL;
 }
 
@@ -574,7 +577,7 @@ int ListUserMembers(int argc, char **argv)
 
 int ListListMembers(int argc, char **argv)
 {
-  ListMembersByType("LIST");
+  ListMembersByType("LIST", 0);
   return DM_NORMAL;
 }
 
@@ -586,7 +589,7 @@ int ListListMembers(int argc, char **argv)
 
 int ListStringMembers(int argc, char **argv)
 {
-  ListMembersByType("STRING");
+  ListMembersByType("STRING", 0);
   return DM_NORMAL;
 }
 
@@ -719,6 +722,49 @@ int DeleteMember(int argc, char **argv)
   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.
index 2c4146e1a01162759f82036880eebf6431dbe1d1..f535c70724859527e029288847076f40659376e9 100644 (file)
@@ -77,6 +77,21 @@ Menu list_info_menu = {
   }
 };
 
+/*
+ * 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
  */
@@ -85,7 +100,7 @@ Menu 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),
@@ -94,6 +109,7 @@ Menu list_member_menu = {
     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)
   }
 };
@@ -732,6 +748,33 @@ Menu zephyr_menu = {
   }
 };
 
+/*
+ * 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
@@ -780,6 +823,7 @@ Menu moira_top_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)
   }
 };
index 02de7eacfb88add977198f701393eba5282983a7..5d704c15ca2972c389dba60b3bb5b252791f5ff5 100644 (file)
@@ -113,37 +113,41 @@ static char **AskZephyrInfo(char **info, Bool rename)
        }
     }
 
-  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)
This page took 0.060018 seconds and 5 git commands to generate.