]> andersk Git - moira.git/blobdiff - clients/moira/lists.c
Diane Delgado's changes for a fixed table-locking order
[moira.git] / clients / moira / lists.c
index 4fe459608b08537a4bd38136d7475e347cff280e..173c3909b1ca31416f35e4857fe716d7aa680177 100644 (file)
@@ -2,33 +2,33 @@
   static char rcsid_module_c[] = "$Header$";
 #endif lint
 
-/*     This is the file lists.c for allmaint, the SMS client that allows
- *      a user to maintaint most important parts of the SMS database.
- *     It Contains: 
+/*     This is the file lists.c for the MOIRA Client, which allows a nieve
+ *      user to quickly and easily maintain most parts of the MOIRA database.
+ *     It Contains: All list manipulation functions, except delete.
  *     
- *     Borrowed from listmaint code:   4/12/88
- *     By:                             Chris D. Peterson
+ *     Created:        4/12/88
+ *     By:             Chris D. Peterson
  *
  *      $Source$
  *      $Author$
  *      $Header$
  *     
- *     Copyright 1987, 1988 by the Massachusetts Institute of Technology.
+ *     Copyright 1988 by the Massachusetts Institute of Technology.
  *
  *     For further information on copyright and distribution 
  *     see the file mit-copyright.h
  */
 
 #include <stdio.h>
-#include <strings.h>
-#include <sms.h>
+#include <string.h>
+#include <moira.h>
+#include <moira_site.h>
 #include <menu.h>
 
 #include "mit-copyright.h"
-#include "allmaint.h"
-#include "allmaint_funcs.h"
+#include "defs.h"
+#include "f_defs.h"
 #include "globals.h"
-#include "infodefs.h"
 
 #define LIST    0
 #define MEMBERS 1
@@ -61,8 +61,7 @@ char ** info;
 {
     char buf[BUFSIZ];
 
-    Put_message(" ");
-    sprintf(buf, "Item Administered: %-20s Name: %s", info[ACE_TYPE], 
+    sprintf(buf, "Item: %-20s Name: %s", info[ACE_TYPE], 
            info[ACE_NAME]);
     Put_message(buf);
 }
@@ -89,7 +88,7 @@ char ** info;
     else
        Put_message("This list is NOT a mailing list.");
     if ( atoi(info[L_GROUP]) ) {
-       (void) sprintf(buf,"This list is Group and its ID number is %s",
+       (void) sprintf(buf,"This list is Group and its ID number is %s",
                       info[L_GID]);
        Put_message(buf);
     }
@@ -133,7 +132,7 @@ char * name1, *name2;
     switch(type) {
     case LIST:
        args[0] = name1;
-       if ( (status = sms_query("get_list_info", 1, args,
+       if ( (status = do_mr_query("get_list_info", 1, args,
                               StoreInfo, (char *) &elem)) != 0) {
            com_err(program_name, status, " in get_list_info");
            return (NULL);
@@ -141,7 +140,7 @@ char * name1, *name2;
        break;
     case MEMBERS:
        args[0] = name1;
-       if ( (status = sms_query("get_members_of_list", 1, args,
+       if ( (status = do_mr_query("get_members_of_list", 1, args,
                               StoreInfo, (char *) &elem)) != 0) {
            com_err(program_name, status, " in get_members_of_list");
            return (NULL);
@@ -150,7 +149,7 @@ char * name1, *name2;
     case GLOM:
        args[0] = name1;        
        args[1] = name2;        
-       if ( (status =  sms_query("get_lists_of_member", 2, args,
+       if ( (status =  do_mr_query("get_lists_of_member", 2, args,
                               StoreInfo, (char *) &elem)) != 0) {
            com_err(program_name, status, " in get_list_of_members");
            return (NULL);
@@ -159,7 +158,7 @@ char * name1, *name2;
     case ACE_USE:
        args[0] = name1;        
        args[1] = name2;        
-       if ( (status =  sms_query("get_ace_use", 2, args,
+       if ( (status =  do_mr_query("get_ace_use", 2, args,
                               StoreInfo, (char *) &elem)) != 0) {
            com_err(program_name, status, " in get_ace_use");
            return (NULL);
@@ -191,28 +190,46 @@ Bool name;
     Put_message(" ");
 
     if (name) {
-       newname = Strsave(info[L_NAME]);
-       GetValueFromUser("The new name for this list", &newname);
+       while (1) {
+           newname = Strsave(info[L_NAME]);
+           if (GetValueFromUser("The new name for this list", &newname) ==
+               SUB_ERROR)
+             return(NULL);
+           if (ValidName(newname))
+             break;
+       }
     }
-    GetYesNoValueFromUser("Is this an active list", &info[L_ACTIVE]);
-    GetYesNoValueFromUser("Is this a public list", &info[L_PUBLIC]);
-    GetYesNoValueFromUser("Is this a hidden list", &info[L_HIDDEN]);
-    GetYesNoValueFromUser("Is this a maillist", &info[L_MAILLIST]);
-    GetYesNoValueFromUser("is this a group", &info[L_GROUP]);
+    if (GetYesNoValueFromUser("Is this an active list", &info[L_ACTIVE]) ==
+       SUB_ERROR)
+      return(NULL);
+    if (GetYesNoValueFromUser("Is this a public list", &info[L_PUBLIC]) ==
+       SUB_ERROR)
+      return(NULL);
+    if (GetYesNoValueFromUser("Is this a hidden list", &info[L_HIDDEN]) ==
+       SUB_ERROR)
+      return(NULL);
+    if (GetYesNoValueFromUser("Is this a maillist", &info[L_MAILLIST]) ==
+       SUB_ERROR)
+      return(NULL);
+    if (GetYesNoValueFromUser("Is this a group", &info[L_GROUP]) == SUB_ERROR)
+      return(NULL);
     if (atoi(info[L_GROUP]))
-       GetValueFromUser("What is the GID for this group.", &info[L_GID]);
-
-    GetValueFromUser("What Type of Administrator (none, user, list): ",
-                    &info[L_ACE_TYPE]);
-    if ( (strcmp(info[L_ACE_TYPE], "USER") == 0) || 
-       (strcmp(info[L_ACE_TYPE], "user") == 0) )
-       GetValueFromUser("Who will be the administrator of this list: ",
-                        &info[L_ACE_NAME]);
-    if ( (strcmp(info[L_ACE_TYPE], "LIST") == 0) ||
-       (strcmp(info[L_ACE_TYPE], "list") == 0) )
-       GetValueFromUser("Which group will be the administrator of this list: ",
-                        &info[L_ACE_NAME]);
-    GetValueFromUser("Description: ", &info[L_DESC]);
+      if (GetValueFromUser("What is the GID for this group.", &info[L_GID]) ==
+         SUB_ERROR)
+       return(NULL);
+
+    if (GetTypeFromUser("What Type of Administrator", "ace_type",
+                       &info[L_ACE_TYPE]) == SUB_ERROR)
+      return(NULL);
+    if ((strcasecmp(info[L_ACE_TYPE], "NONE") != 0) &&
+       (strcasecmp(info[L_ACE_TYPE], "none") != 0)) {
+       sprintf(temp_buf, "Which %s will be the administrator of this list: ",
+               info[L_ACE_TYPE]);
+       if (GetValueFromUser(temp_buf, &info[L_ACE_NAME]) == SUB_ERROR)
+         return(NULL);
+    }
+    if (GetValueFromUser("Description: ", &info[L_DESC]) == SUB_ERROR)
+      return(NULL);
 
     FreeAndClear(&info[L_MODTIME], TRUE);
     FreeAndClear(&info[L_MODBY], TRUE);
@@ -269,9 +286,12 @@ Bool junk;
     register int stat;
     char ** args;
     
-    args = AskListInfo(info, TRUE);
-    if ( (stat = sms_query("update_list", CountArgs(args), args, 
-                          Scream, (char *) NULL)) != SMS_SUCCESS) {
+    if ((args = AskListInfo(info, TRUE)) == NULL) {
+       Put_message("Aborted.");
+       return;
+    }
+    if ( (stat = do_mr_query("update_list", CountArgs(args), args, 
+                          Scream, (char *) NULL)) != MR_SUCCESS) {
        com_err(program_name, stat, " in UpdateList."); 
        Put_message("List ** NOT ** Updated.");
     }
@@ -340,21 +360,42 @@ char **argv;
 {
     static char *info[MAX_ARGS_SIZE], **add_args;
     int status, ret_code = SUB_NORMAL;
+    struct qelem *elem = NULL;
 
-    status = sms_query("get_list_info", 1, argv + 1, NullFunc, 
+    if (!ValidName(argv[1]))
+      return(DM_NORMAL);
+    status = do_mr_query("get_list_info", 1, argv + 1, NullFunc, 
                       (char *) NULL);
-    if (status != SMS_NO_MATCH) {
-       if (status == SMS_SUCCESS)
+    if (status != MR_NO_MATCH) {
+       if (status == MR_SUCCESS)
            Put_message("This list already exists.");
        else
            com_err(program_name, status, " in AddList.");      
        return(SUB_ERROR);
     }
 
-    add_args = AskListInfo(SetDefaults(info,argv[1]), FALSE);
+    /*
+     * If the listname is less than 8 characters, make sure it doesn't
+     * collide with a username.
+     */
+    if ((strlen(argv[1]) <= 8) &&
+       do_mr_query("get_user_account_by_login", 1, argv + 1,
+                   StoreInfo, (char *) &elem) == 0) {
+           Put_message("A user by that name already exists in the database.");
+           Loop(QueueTop(elem), FreeInfo);
+           FreeQueue(elem);
+           if (YesNoQuestion("Crate a list with the same name",
+                             FALSE) != TRUE)
+                   return(SUB_ERROR);
+    }
+    
+    if ((add_args = AskListInfo(SetDefaults(info,argv[1]), FALSE)) == NULL) {
+       Put_message("Aborted.");
+       return(SUB_ERROR);
+    }
 
-    if ( (status = sms_query("add_list", CountArgs(add_args), add_args,
-                            Scream, (char *) NULL)) != SMS_SUCCESS) {
+    if ( (status = do_mr_query("add_list", CountArgs(add_args), add_args,
+                            Scream, (char *) NULL)) != MR_SUCCESS) {
        com_err(program_name, status, " in AddList.");  
        Put_message("List Not Created.");
        ret_code = SUB_ERROR;
@@ -424,16 +465,16 @@ char **argv;
     }
     else 
        /* All we want to know is if it exists. */
-       switch( (stat = sms_query("count_members_of_list", 1, argv + 1,
+       switch( (stat = do_mr_query("count_members_of_list", 1, argv + 1,
                                   NullFunc, (char *) NULL))) {
-       case SMS_SUCCESS:
+       case MR_SUCCESS:
            break;
-       case SMS_LIST:
+       case MR_LIST:
            Put_message("This list does not exist.");
            return(DM_QUIT);
-       case SMS_ACCESS:
+       case MR_PERM:
            Put_message("You are not allowed to view this list.");
-           return(DM_QUIT);
+           break;
        default:
            com_err(program_name, stat, " in get_list_info");
            return(DM_QUIT);
@@ -469,7 +510,7 @@ Menu *m;
  *      NOTE: if type is NULL, all lists members are listed.
  */
 
-void
+int
 ListMembersByType(type)
 char * type;
 {
@@ -481,9 +522,11 @@ char * type;
     args[1] = NULL;
 
     found_some = FALSE;
-    if ( (status = sms_query("get_members_of_list", CountArgs(args), args, 
-                            PrintByType, type)) != 0)
+    if ( (status = do_mr_query("get_members_of_list", CountArgs(args), args, 
+                            PrintByType, type)) != 0) {
        com_err(program_name, status, " in ListMembersByType");
+       return(DM_NORMAL);
+    }
     if (!found_some) {
        if (type == NULL)
            Put_message("List is empty (no members).");
@@ -557,33 +600,23 @@ int
 GetMemberInfo(action, ret_argv)
 char *action, **ret_argv;
 {
-    char temp_buf[BUFSIZ], ret_buf[BUFSIZ];
-    register int status;
+    char temp_buf[BUFSIZ];
 
     ret_argv[LM_LIST] = Strsave(current_list);
-    ret_argv[LM_MEMBER] = "nobody";
-    ret_argv[LM_TYPE]= "user";
 
-    switch (status = sms_access("add_member_to_list", 3, ret_argv)) {
-    case SMS_SUCCESS:
-       break;
-    case SMS_PERM:
-       Put_message("You are not allowed to add members to this list.");
-       return(SUB_ERROR);
-    default:
-       com_err(program_name, status, NULL);
-       return(SUB_ERROR);
-    }
-    PromptWithDefault("Type of member (user, list, or string)",
-                       ret_buf, BUFSIZ, "user");
-    ret_argv[LM_TYPE]= Strsave(ret_buf);
+    ret_argv[LM_TYPE] = Strsave("user");
+    if (GetTypeFromUser("Type of member", "member", &ret_argv[LM_TYPE]) ==
+       SUB_ERROR)
+      return(SUB_ERROR);
 
     sprintf(temp_buf,"Name of %s to %s", ret_argv[LM_TYPE], action);
-    PromptWithDefault(temp_buf, ret_buf, BUFSIZ, user);
-    ret_argv[LM_MEMBER] = Strsave(ret_buf);
+    ret_argv[LM_MEMBER] = Strsave(user);
+    if (GetValueFromUser(temp_buf, &ret_argv[LM_MEMBER]) == SUB_ERROR)
+      return(SUB_ERROR);
     ret_argv[LM_END] = NULL;           /* NULL terminate this list. */
 
-    if (!ValidName( ret_argv[LM_MEMBER] ) ) {
+    if (strcasecmp(ret_argv[LM_TYPE], "string") &&
+       !ValidName( ret_argv[LM_MEMBER] ) ) {
        FreeInfo(ret_argv);
        return(SUB_ERROR);
     }
@@ -599,15 +632,40 @@ char *action, **ret_argv;
 int
 AddMember()
 {
-    char *args[10], temp_buf[BUFSIZ];
+    char *args[10], temp_buf[BUFSIZ], *p;
     register int status;
+    struct qelem *mailhubs, *elem, *GetTypeValues();
 
     if ( GetMemberInfo("add", args) == SUB_ERROR )
        return(DM_NORMAL);
 
-    if ( (status = sms_query("add_member_to_list", CountArgs(args), args,
-                          Scream, NULL)) != SMS_SUCCESS) {
-       if (status == SMS_EXISTS) {
+    if (!strcmp(args[LM_TYPE], "STRING")) {
+       if (p = strchr(args[LM_MEMBER], '@')) {
+           char *host = canonicalize_hostname(strsave(++p));
+           mailhubs = GetTypeValues("mailhub");
+           for (elem = mailhubs; elem; elem = elem->q_forw) {
+               if (!strcasecmp(host, elem->q_data)) {
+                   free(host);
+                   host = strsave(args[LM_MEMBER]);
+                   *(--p) = 0;
+                   sprintf(temp_buf, "String \"%s\" should be USER or LIST \"%s\" because it is a local name.",
+                           host, args[LM_MEMBER]);
+                   Put_message(temp_buf);
+                   free(args[LM_TYPE]);
+                   free(host);
+                   return(DM_NORMAL);
+               }
+           }
+           free(host);
+       } else if (!strchr(args[LM_MEMBER], '!')) {
+           Put_message("Member which is not a foreign mail address should not be type STRING.");
+           return(DM_NORMAL);
+       }
+    }
+
+    if ( (status = do_mr_query("add_member_to_list", CountArgs(args), args,
+                          Scream, NULL)) != MR_SUCCESS) {
+       if (status == MR_EXISTS) {
            sprintf(temp_buf, "The %s %s is already a member of LIST %s.",
                    args[LM_TYPE], args[LM_MEMBER], args[LM_LIST]);
            Put_message(temp_buf);
@@ -636,7 +694,7 @@ DeleteMember()
        return(DM_NORMAL);
 
     if (Confirm("Are you sure you want to delete this member?") ) {
-       if (status = sms_query("delete_member_from_list", CountArgs(args),
+       if (status = do_mr_query("delete_member_from_list", CountArgs(args),
                               args, Scream, NULL))
            com_err(program_name, status, " in DeleteMember");
        else
@@ -662,17 +720,17 @@ int
 InterRemoveItemFromLists()
 {
     register int status;
-    char type[BUFSIZ], name[BUFSIZ], *args[10], buf[BUFSIZ];
+    char *type, *name, *args[10], buf[BUFSIZ];
     struct qelem *top, *elem;
 
-    if ( !(PromptWithDefault("Type of member (user, list, string)", type, 
-                           BUFSIZ, "user")) )
+    type = strsave("USER");
+    if (GetTypeFromUser("Type of member", "member", &type) == SUB_ERROR)
        return(DM_NORMAL);
     
     sprintf(buf, "Name of %s", type);
-    if ( !(PromptWithDefault(buf, name, BUFSIZ, user)) ) {
-       return(DM_NORMAL);
-    }
+    name = strsave(user);
+    if (GetValueFromUser(buf, &name) == SUB_ERROR)
+      return(DM_NORMAL);
 
     if (!ValidName(name))
        return(DM_NORMAL);
@@ -690,7 +748,7 @@ InterRemoveItemFromLists()
            args[DM_LIST] = info[GLOM_NAME];
            args[DM_TYPE] = type;
            args[DM_MEMBER] = name;
-           if ( (status = sms_query("delete_member_from_list", 3, args,
+           if ( (status = do_mr_query("delete_member_from_list", 3, args,
                               Scream, (char *) NULL)) != 0)
                /* should probabally check to delete list. */
                com_err(program_name, status, " in delete_member");
@@ -723,31 +781,32 @@ ListByMember()
     Bool maillist, group;
     struct qelem *top, *elem;
 
-    if ( !(PromptWithDefault("Type of member (user, list, string)", buf, 
-                           BUFSIZ, "user")) )
+    type = strsave("USER");
+    if (GetTypeFromUser("Type of member", "member", &type) == SUB_ERROR)
        return(DM_NORMAL);
+    
+    sprintf(buf, "Name of %s", type);
+    name = strsave(user);
+    if (GetValueFromUser(buf, &name) == SUB_ERROR)
+      return(DM_NORMAL);
 
     /* What we really want is a recursive search */
-    sprintf(temp_buf, "R%s", buf); 
-    type = Strsave(temp_buf);
-
-    sprintf(temp_buf, "Name of %s", buf);
-    if ( !(PromptWithDefault(temp_buf, buf, BUFSIZ, user)) ) {
-       free(type);
-       return(DM_NORMAL);
-    }
-    name = Strsave(buf);
+    sprintf(temp_buf, "R%s", type);
+    free(type); type = Strsave(temp_buf);
 
-    maillist = YesNoQuestion("Show only Lists that are Maillists (y/n) ?",
-                            TRUE);
-    group = YesNoQuestion("Show only Lists that are Groups (y/n) ?", TRUE);
+    if ((maillist = YesNoQuestion("Show Lists that are Maillists (y/n) ?",
+                                 TRUE)) == -1)
+      return(DM_NORMAL);
+    if ((group = YesNoQuestion("Show Lists that are Groups (y/n) ?",
+                              TRUE)) == -1)
+      return(DM_NORMAL);
 
     elem = top = GetListInfo(GLOM, type, name);
 
     while (elem != NULL) {
        info = (char**) elem->q_data;
-       if (maillist != TRUE || !strcmp(info[GLOM_MAILLIST], "1")) 
-           if (group != TRUE || !strcmp(info[GLOM_GROUP], "1")) 
+       if ((maillist == TRUE && !strcmp(info[GLOM_MAILLIST], "1")) ||
+           (group == TRUE && !strcmp(info[GLOM_GROUP], "1")))
                Put_message(info[GLOM_NAME]);
        elem = elem->q_forw;
     }
@@ -768,24 +827,27 @@ ListByAdministrator()
     char buf[BUFSIZ], temp_buf[BUFSIZ], *type, *name;
     struct qelem *top;
 
-    if ( !(PromptWithDefault("Type of member (user, list, string)", buf, 
-                           BUFSIZ, "user")) )
+    type = strsave("USER");
+    if (GetTypeFromUser("Type of member", "member", &type) == SUB_ERROR)
        return(DM_NORMAL);
-
-    if ( YesNoQuestion("Do you want a recursive search (y/n)", TRUE) == 1 ) {
-       sprintf(temp_buf, "R%s", buf);  /* "USER" to "RUSER" etc. */
-       type = Strsave(temp_buf);
-    }
-    else 
-       type = Strsave(buf);
     
-    sprintf(temp_buf, "Name of %s", buf);
-    if ( !(PromptWithDefault(temp_buf, buf, BUFSIZ, user)) ) {
+    sprintf(buf, "Name of %s", type);
+    name = strsave(user);
+    if (GetValueFromUser(buf, &name) == SUB_ERROR)
+      return(DM_NORMAL);
+
+    switch (YesNoQuestion("Do you want a recursive search (y/n)", FALSE)) {
+    case TRUE:
+       sprintf(temp_buf, "R%s", type); /* "USER" to "RUSER" etc. */
        free(type);
+       type = Strsave(temp_buf);
+       break;
+    case FALSE:
+       break;
+    default:
        return(DM_NORMAL);
     }
-    name = Strsave(buf);
-
+    
     top = GetListInfo(ACE_USE, type, name);
     Loop(top, PrintListAce);
 
@@ -793,57 +855,6 @@ ListByAdministrator()
     return (DM_NORMAL);
 }
 
-/*     Function Name: ListAllGroups
- *     Description: This function lists all visable groups.
- *     Arguments: none.
- *     Returns: DM_NORMAL.
- */
-
-ListAllGroups()
-{
-    register int status;
-    static char * args[] = {
-       "TRUE",                 /* active */
-       "DONTCARE",             /* public */
-       "FALSE",                /* hidden */
-       "DONTCARE",             /* maillist */
-       "TRUE",                 /* group. */
-    };
-
-    if (YesNoQuestion("This query will take a while, Do you wish to continue?",
-                      TRUE) == TRUE )
-       if (status = sms_query("qualified_get_lists", 5, args,
-                              Print, (char *) NULL) != 0)
-           com_err(program_name, status, " in ListAllGroups");
-    return (DM_NORMAL);
-}
-
-/*     Function Name: ListAllMailLists
- *     Description: This function lists all visable maillists.
- *     Arguments: none
- *     Returns: DM_NORMAL.
- */
-
-ListAllMailLists()
-{
-    register int status;
-    static char * args[] = {
-       "TRUE",                 /* active */
-       "DONTCARE",             /* public */
-       "FALSE",                /* hidden */
-       "TRUE",                 /* maillist */
-       "DONTCARE",             /* group. */
-    };
-
-    if (YesNoQuestion("This query will take a while. Do you wish to continue?",
-                      TRUE) == TRUE )
-       if (status = sms_query("qualified_get_lists", 5, args,
-                              Print, (char *) NULL) != 0)
-           com_err(program_name, status, " in ListAllGroups");
-
-    return (DM_NORMAL);        
-}
-
 /*     Function Name: ListAllPublicMailLists
  *     Description: This function lists all public mailing lists.
  *     Arguments: none
@@ -863,20 +874,9 @@ ListAllPublicMailLists()
 
     if (YesNoQuestion("This query will take a while. Do you wish to continue?",
                       TRUE) == TRUE )
-       if (status = sms_query("qualified_get_lists", 5, args,
+       if (status = do_mr_query("qualified_get_lists", 5, args,
                               Print, (char *) NULL) != 0)
            com_err(program_name, status, " in ListAllGroups");
 
     return (DM_NORMAL);        
 }
-
-/*
- * Local Variables:
- * mode: c
- * c-indent-level: 4
- * c-continued-statement-offset: 4
- * c-brace-offset: -4
- * c-argdecl-indent: 4
- * c-label-offset: -4
- * End:
- */
This page took 0.055618 seconds and 4 git commands to generate.