]> andersk Git - moira.git/blobdiff - clients/mailmaint/mailmaint.c
posixify source
[moira.git] / clients / mailmaint / mailmaint.c
index 503051b1caf196f589049eae981026d77e8d8619..7f085aa5f55391a619064a10147894f41878c2d1 100644 (file)
@@ -3,6 +3,10 @@
  *     $Header$
  */
 
+/*  (c) Copyright 1988 by the Massachusetts Institute of Technology. */
+/*  For copying and distribution information, please see the file */
+/*  <mit-copyright.h>. */
+
 #ifndef lint
 static char rcsid_mailmaint_c[] = "$Header$";
 #endif lint
@@ -14,15 +18,17 @@ static char rcsid_mailmaint_c[] = "$Header$";
 /***********************************************************************/
 #include <stdio.h>
 #include <pwd.h>
-#include <menu.h>
 #include <signal.h>
-#include <strings.h>
+#include <string.h>
 #include <curses.h>
 #include <sys/types.h>
 #include <varargs.h>
 #include <com_err.h>
 #include <ctype.h>
-#include "mit-copyright.h"
+#include <moira.h>
+#include <moira_site.h>
+#include <mit-copyright.h>
+
 
 #define STARTCOL 0
 #define STARTROW 3
@@ -35,25 +41,36 @@ static char rcsid_mailmaint_c[] = "$Header$";
 
 char *whoami;          /* should not be static, for logging package */
 static int status;
-static void scream();
+static int scream();
 extern char *strsave();
-int menu_err_hook();
+#ifdef __STDC__
+void menu_err_hook(const char *who, long code, const char *fmt, va_list args);
+#else
+void menu_err_hook();
+#define const
+#endif
 
 typedef struct list_info {
-    char *acl;
+    int active;
+    int public;
+    int hidden;
+    int maillist;
+    int group;
+    char *acl_type;
+    char *acl_name;
     char *desc;
-    char *expdate;
+    char *modtime;
+    char *modby;
+    char *modwith;
 }         List_info;
 
 static char *ascbuff = {"0123456789"};
-static int 
-print_2(), print_1();
+static int print_2(), print_1();
 static List_info *current_li = (List_info *) NULL;
 static int get_list_info();
 static int fetch_list_info();
 
 char *malloc();
-char *rindex();
 char *getlogin();
 extern char *strsave();
 char *getenv();
@@ -74,6 +91,10 @@ int level, found_some, currow, page, num_members;
 int moreflg, toggle, first_time;
 char *uname;
 
+/* This crock is because the original code was very broken and this makes
+ * it work.  Someday, we should abandon the code or fix it right.
+ */
+#define mvcur(oy,ox,ny,nx) move(ny,nx)
 
 /****************************************************/
 /*ARGSUSED*/
@@ -82,14 +103,15 @@ main(argc, argv)
     char *argv[];
 
 {
-    int (*old_hook)();
+#ifdef __STDC__
+    void (*old_hook)(const char *, long, const char *, va_list);
+#else
+    void (*old_hook)();
+#endif
     int use_menu = 1;
-    char buf[BUFSIZ];
-
-    init_sms_err_tbl();
-    init_krb_err_tbl();
+    char buf[BUFSIZ], *motd;
 
-    if ((whoami = rindex(argv[0], '/')) == NULL)
+    if ((whoami = strrchr(argv[0], '/')) == NULL)
        whoami = argv[0];
     else
        whoami++;
@@ -100,9 +122,12 @@ main(argc, argv)
        goto punt;
     }
     else {
-       current_li->acl = (char *) NULL;
+       current_li->acl_type = (char *) NULL;
+       current_li->acl_name = (char *) NULL;
        current_li->desc = (char *) NULL;
-       current_li->expdate = (char *) NULL;
+       current_li->modtime = (char *) NULL;
+       current_li->modby = (char *) NULL;
+       current_li->modwith = (char *) NULL;
     }
     if ((uname = getlogin()) == NULL) {
        struct passwd *getpwuid();
@@ -113,13 +138,24 @@ main(argc, argv)
 
     printf("Connecting to database for %s...please hold on.\n", uname);
 
-    status = sms_connect();
+    status = mr_connect(NULL);
     if (status) {
-       (void) sprintf(buf, "\nConnection to SMS server failed");
+       (void) sprintf(buf, "\nConnection to Moira server failed");
        goto punt;
     }
 
-    status = sms_auth();
+    status = mr_motd(&motd);
+    if (status) {
+        com_err(whoami, status, " unable to check server status");
+       mr_disconnect();
+       exit(2);
+    }
+    if (motd) {
+       fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd);
+       mr_disconnect();
+       exit(2);
+    }
+    status = mr_auth("mailmaint");
     if (status) {
        (void) sprintf(buf, "\nAuthorization failed.\n");
        goto punt;
@@ -128,12 +164,12 @@ main(argc, argv)
     if (use_menu) {
        (void) initscr();
        if ((LINES < 24) || (COLS < 60)) {
-           Put_message("Display window too small.\n\n");
+           display_buff("Display window too small.\n\n");
            (void) sprintf(buf, "Current window parameters are (%d \
 lines, %d columns)\n", LINES, COLS);
-           Put_message(buf);
-           Put_message("Please resize your window\n");
-           Put_message("to at least 24 lines and 60 columns.\n");
+           display_buff(buf);
+           display_buff("Please resize your window\n");
+           display_buff("to at least 24 lines and 60 columns.\n");
            exit(0);
        }
        raw();
@@ -168,8 +204,8 @@ get_main_input()
        currow = DISPROW + 2;
        page = 1;
        toggle = num_members = moreflg = 0;
-       c = getchar();
-       if (c == 13) {
+       c = getchar() & 0x7f;   /* mask parity bit */
+       if (c == '\r' || c == '\n') {
            if (position[level] == 7)
                c = 'q';
            else
@@ -226,9 +262,9 @@ get_main_input()
            }
            break;
        case 27:                /* up arrow */
-           c = getchar();
+           c = getchar() & 0x7f;
            if (c == 91) {
-               c = getchar();
+               c = getchar() & 0x7f;
                if (c == 65) {
                    position[level]--;
                    if (!position[level])
@@ -255,23 +291,25 @@ get_main_input()
 show_list_info()
 {
     char *buf;
-    char c;
 
-    show_text(DISPROW, STARTCOL, "Show information about a list.\n\r");
+    show_text(DISPROW, STARTCOL, "Show information about a list.\n");
     buf = calloc((unsigned)1024, 1);
-    if (Prompt("Enter List Name: ", buf, LISTSIZE) == 1) {
-       Put_message("\n\r");
+    if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1) {
+       display_buff("\n");
        if (fetch_list_info(buf, current_li) == 0) {
-           (void) sprintf(buf, "Description: %s\n\r", current_li->desc);
+           (void) sprintf(buf, "Description: %s\n", current_li->desc);
            if (strlen(buf) > 60)
                (void) display_buff(buf);
            else
                show_text(currow, STARTCOL, buf);
            currow++;
-           (void) sprintf(buf, "List Administrator: %s", current_li->acl);
+           (void) sprintf(buf, "List Administrator: %s %s",
+                          current_li->acl_type, current_li->acl_name);
            show_text(currow, STARTCOL, buf);
            currow++;
-           (void) sprintf(buf, "Expiration date: %s", current_li->expdate);
+           (void) sprintf(buf, "Modified on %s by user %s with %s",
+                          current_li->modtime, current_li->modby,
+                          current_li->modwith);
            show_text(currow, STARTCOL, buf);
            currow++;
        }
@@ -330,8 +368,8 @@ start_display_buff(buff)
        currow++;
        mvcur(0, 0, currow, STARTCOL);
        refresh();
-       if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1) == 0) {
-           Put_message("Flushing query...");
+       if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1, 0) == 0) {
+           display_buff("Flushing query...");
            moreflg = 1;
            return (0);
        }
@@ -348,28 +386,23 @@ start_display_buff(buff)
 /****************************************************/
 add_member()
 {
-    static char *argv[] = {
-       "add_member_to_list",
-       0,
-       0,
-       0
-       };
+    char *argv[3];
     char *buf;
-    char c;
 
-    show_text(DISPROW, STARTCOL, "Add yourself to a list\n\r");
+    show_text(DISPROW, STARTCOL, "Add yourself to a list\n");
     buf = calloc(LISTMAX, 1);
-    if (Prompt("Enter List Name: ", buf, LISTSIZE) == 1) {
-       Put_message("\r\n");
-       argv[1] = strsave(buf);
-       argv[2] = strsave("user");
-       argv[3] = strsave(uname);
-       if (status = sms_query_internal(3, argv, scream, (char *) NULL)) {
-           Put_message("\r\n");
+    if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1) {
+       display_buff("\n");
+       argv[0] = strsave(buf);
+       argv[1] = strsave("user");
+       argv[2] = strsave(uname);
+       if (status = mr_query("add_member_to_list", 3, argv,
+                              scream, (char *) NULL)) {
+           display_buff("\n");
            com_err(whoami, status, " found.\n");
        }
        else {
-           (void) sprintf(buf, "User %s added to list\r", uname);
+           (void) sprintf(buf, "User %s added to list\n", uname);
            show_text(DISPROW + 3, STARTCOL, buf);
        }
        currow = DISPROW + 4;
@@ -382,28 +415,23 @@ add_member()
 /****************************************************/
 delete_member()
 {
-    static char *argv[] = {
-       "delete_member_from_list",
-       0,
-       0,
-       0
-       };
+    char *argv[3];
     char *buf;
-    char c;
 
-    show_text(DISPROW, STARTCOL, "Remove yourself from a list\n\r");
+    show_text(DISPROW, STARTCOL, "Remove yourself from a list\n");
     buf = calloc(LISTMAX, 1);
-    if (Prompt("Enter List Name: ", buf, LISTSIZE) == 1) {
-       Put_message("\r\n");
-       argv[1] = strsave(buf);
-       argv[2] = strsave("user");
-       argv[3] = strsave(uname);
-       if (status = sms_query_internal(3, argv, scream, (char *) NULL)) {
-           Put_message("\r\n");
+    if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1) {
+       display_buff("\n");
+       argv[0] = strsave(buf);
+       argv[1] = strsave("user");
+       argv[2] = strsave(uname);
+       if (status = mr_query("delete_member_from_list", 3, argv,
+                              scream, (char *) NULL)) {
+           display_buff("\n");
            com_err(whoami, status, " found.\n");
        }
        else {
-           (void) sprintf(buf, "User %s deleted from list\r", uname);
+           (void) sprintf(buf, "User %s deleted from list\n", uname);
            show_text(DISPROW + 3, STARTCOL, buf);
        }
        currow = DISPROW + 4;
@@ -418,20 +446,20 @@ list_by_member()
 {
     char *nargv[3];
     char *buf;
-    char c;
 
-    nargv[1] = strsave("user");
+    nargv[1] = strsave("ruser");
     nargv[2] = strsave(uname);
     buf = calloc(BUFSIZ, 1);
-    (void) sprintf(buf, "%s is on the following lists:\r", uname);
+    (void) sprintf(buf, "%s is on the following lists:\n", uname);
     show_text(DISPROW, STARTCOL, buf);
     mvcur(0, 0, currow, STARTCOL);
     refresh();
-    if (status = sms_query("get_lists_of_member", 2, nargv + 1,
+    if (status = mr_query("get_lists_of_member", 2, nargv + 1,
                           print_1, (char *) NULL)) {
-       Put_message("\r\n");
+       display_buff("\n");
        com_err(whoami, status, " in get_lists_of_member");
     }
+    currow++;
     show_text(currow, STARTCOL, "Press any Key to continue...");
     (void) getchar();
     clrwin(DISPROW);
@@ -445,8 +473,8 @@ show_all()
 
     show_text(DISPROW, STARTCOL, "This function may take a \
 while... proceed? [y] ");
-    c = getchar();
-    if (c == 'y' || c == 'Y') {
+    c = getchar() & 0x7f;
+    if (c == 'y' || c == 'Y' || c == '\n') {
        move(DISPROW + 1, STARTCOL);
        addstr("Processing query...please hold");
        refresh();
@@ -467,8 +495,8 @@ print_1(argc, argv, callback)
 {
     char buf[BUFSIZ];
 
-    /* no newline 'cause Put_message adds one */
-    (void) sprintf(buf, "%s\r", argv[0]);
+    /* no newline 'cause display_buff adds one */
+    (void) sprintf(buf, "%s\n", argv[0]);
     (void) start_display(buf);
 
     return (0);
@@ -490,7 +518,7 @@ print_all(argc, argv, callback)
        show_text(DISPROW + 1, STARTCOL, "All mailing lists:");
        first_time = 0;
     }
-    (void) sprintf(buf, "%s\r", argv[0]);
+    (void) sprintf(buf, "%s\n", argv[0]);
     (void) start_display(buf);
 
     return (0);
@@ -499,16 +527,19 @@ print_all(argc, argv, callback)
 /****************************************************/
 list_all_groups()
 {
-
+    char *argv[5];
+    argv[0] = argv[1] = argv[3] = "true";
+    argv[4] = "dontcare";
+    argv[2] = "false";
     first_time = 1;
-    if (status = sms_query("get_all_visible_maillists", 0, (char **) NULL,
+    if (status = mr_query("qualified_get_lists", 5, argv,
                           print_all, (char *) NULL)) {
-       Put_message("\r\n");
+       display_buff("\n");
        com_err(whoami, status, " in list_all_groups\n");
     }
     end_display();
 
-    return (DM_NORMAL);                /* HA! */
+    return (0);
 }
 
 /****************************************************/
@@ -523,13 +554,13 @@ list_members()
     mvcur(0, 0, DISPROW, STARTCOL);
     refresh();
     buf = calloc(LISTMAX, 1);
-    if (Prompt("Enter List Name: ", buf, LISTSIZE) == 1) {
+    if (Prompt("Enter List Name: ", buf, LISTSIZE, 1) == 1) {
        (void) sprintf(buffer, "The members of list '%s' are:", buf);
        show_text(DISPROW + 1, STARTCOL, buffer);
        argv[0] = buf;
-       if (status = sms_query("get_members_of_list", 1, argv,
+       if (status = mr_query("get_members_of_list", 1, argv,
                               print_2, (char *) NULL)) {
-           Put_message("\r\n");
+           display_buff("\n");
            com_err(whoami, status, " found.\n");
            currow++;
        }
@@ -545,7 +576,7 @@ list_members()
        return(0);
     }
     clrwin(DISPROW);
-    return (DM_NORMAL);                /* HA! */
+    return (0);
 }
 
 /****************************************************/
@@ -576,11 +607,10 @@ start_display(buff)
     buffer = calloc(50, 1);
     if (currow >= LINES - 2) {
        page++;
-       currow++;
        mvcur(0, 0, currow, STARTCOL);
        refresh();
-       if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1) == 0) {
-           Put_message("Flushing query...");
+       if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1, 0) == 0) {
+           display_buff("Flushing query...");
            moreflg = 1;
            return (0);
        }
@@ -604,7 +634,7 @@ start_display(buff)
 /****************************************************/
 end_display()
 {
-    char *buffer, c;
+    char *buffer;
 
     if (moreflg) {
        clrwin(DISPROW);
@@ -613,7 +643,7 @@ end_display()
 
     buffer = calloc(50, 1);
     currow++;
-    (void) sprintf(buffer, "End of List. %d Total Members\r", num_members);
+    (void) sprintf(buffer, "End of List. %d Total Members\n", num_members - 1);
     show_text(currow, STARTCOL, buffer);
     currow++;
     show_text(currow, STARTCOL, "Press any key to continue...");
@@ -663,7 +693,7 @@ pack_main_menu()
     buf = calloc(50, 1);
     (void) sprintf(buf, "Mail List Program for %s", uname);
     main_menu->title = strsave(buf);
-    main_menu->items[0] = strsave("1.  Show all mailing lists.");
+    main_menu->items[0] = strsave("1.  Show all public mailing lists.");
     main_menu->items[1] = strsave("2.  Get all members of a mailing list.");
     main_menu->items[2] = strsave("3.  Display lists of which you are a member.");
     main_menu->items[3] = strsave("4.  Show description of list.");
@@ -735,8 +765,8 @@ show_text(row, col, buff)
     char *buff;
 {
     mvcur(0, 0, row, col);
+    addstr(buff);
     refresh();
-    printf("%s", buff);
 }
 
 /****************************************************/
@@ -752,7 +782,7 @@ erase_line(row, col)
     buff[i] = 0;               /* just to be sure ! */
     move(row, col);
     mvcur(0, 0, row, col);
-    printf("%s", buff);
+    addstr(buff);
     refresh();
 }
 
@@ -782,22 +812,23 @@ clrwin(erase_row)
     mvcur(0, 0, erase_row, STARTCOL);
     refresh();
     for (i = erase_row; i <= currow - 1; i++) {
-       printf("%s\n\r", buff);
+       addstr(buff);
     }
-    printf("%s", buff);
+    addstr(buff);
     mvcur(erase_row, STARTCOL, STARTROW + oldpos[level] - 1, STARTCOL);
     refresh();
 }
 
 /****************************************************/
 
-static void 
+static int
 scream()
 {
-    com_err(whoami, status, "\nAn SMS update returned a value -- programmer \
+    com_err(whoami, status, "\nA Moira update returned a value -- programmer \
 botch\n");
-    sms_disconnect();
+    mr_disconnect();
     exit(1);
+    return(0); /* to keep compiler happy */
 }
 
 /****************************************************/
@@ -810,7 +841,7 @@ fetch_list_info(list, li)
     char *argv[1];
 
     argv[0] = list;
-    return sms_query("get_list_info", 1, argv, get_list_info, (char *) NULL);
+    return mr_query("get_list_info", 1, argv, get_list_info, (char *) NULL);
 }
 
 /* ARGSUSED */
@@ -820,15 +851,24 @@ get_list_info(argc, argv)
     char **argv;
 {
 
-    if (current_li->acl)
-       free(current_li->acl);
-    current_li->acl = strsave(argv[2]);
+    if (current_li->acl_type)
+       free(current_li->acl_type);
+    current_li->acl_type = strsave(argv[7]);
+    if (current_li->acl_name)
+       free(current_li->acl_name);
+    current_li->acl_name = strsave(argv[8]);
     if (current_li->desc)
        free(current_li->desc);
-    current_li->desc = strsave(argv[3]);
-    if (current_li->expdate)
-       free(current_li->expdate);
-    current_li->expdate = strsave(argv[4]);
+    current_li->desc = strsave(argv[9]);
+    if (current_li->modtime)
+       free(current_li->modtime);
+    current_li->modtime = strsave(argv[10]);
+    if (current_li->modby)
+       free(current_li->modby);
+    current_li->modby = strsave(argv[11]);
+    if (current_li->modwith)
+       free(current_li->modwith);
+    current_li->modwith = strsave(argv[12]);
     return (0);
 }
 
@@ -838,20 +878,20 @@ get_list_info(argc, argv)
 /****************************************************/
 /* Prompt the user for input */
 int 
-Prompt(prompt, buf, buflen)
+Prompt(prompt, buf, buflen, crok)
     char *prompt;
     char *buf;
     int buflen;
+    int crok;
 {
     int c;
     char *p;
-    int x, oldx;
 
-    printf("%s", prompt);
+    addstr(prompt);
     refresh();
     for (p = buf; abs(strlen(p) - strlen(buf)) <= buflen;) {
        refresh();
-       c = getchar();
+       c = getchar() & 0x7f;
        switch (c) {
        case CTL('C'):
            return 0;
@@ -863,7 +903,8 @@ Prompt(prompt, buf, buflen)
            return (0);
        case '\n':
        case '\r':
-           Put_message("\r");
+           if (crok)
+               display_buff("\n");
            *p = '\0';
            if (strlen(buf) < 1)/* only \n or \r in buff */
                return (-1);
@@ -873,16 +914,14 @@ Prompt(prompt, buf, buflen)
        case '\177':
            if (p > buf) {
                p--;
-               x--;
-               Put_message("\b");
-               Put_message(" ");
-               Put_message("\b");
+               printf("\b \b");
            }
            break;
        case CTL('U'):
        case CTL('G'):
        case CTL('['):
-           x = oldx;
+           while (p-- > buf)
+               printf("\b \b");
            p = buf;
            break;
        default:
@@ -893,7 +932,6 @@ Prompt(prompt, buf, buflen)
            if (isprint(c)) {
                (void) addch(c);
                *p++ = c;
-               x++;
            }
            else
                (void) putchar(CTL('G'));
@@ -909,17 +947,15 @@ Prompt(prompt, buf, buflen)
  * curses instead of around it.
  */
 
-int
+void
 menu_err_hook(who, code, fmt, args)
-    char *who;
-    int code;
-    char *fmt;
+    const char *who;
+    long code;
+    const char *fmt;
     va_list args;
 {
     char buf[BUFSIZ], *cp;
 
-    FILE _strbuf;
-
     (void) strcpy(buf, who);
     for (cp = buf; *cp; cp++);
     *cp++ = ':';
@@ -929,22 +965,11 @@ menu_err_hook(who, code, fmt, args)
        while (*cp)
            cp++;
     }
-    _strbuf._flag = _IOWRT + _IOSTRG;
-    _strbuf._ptr = cp;
-    _strbuf._cnt = BUFSIZ - (cp - buf);
-    _doprnt(fmt, args, &_strbuf);
-    (void) putc('\0', &_strbuf);
-    Put_message(buf);
+#if defined(AIX386) || defined(sun)
+    vsprintf(cp, fmt, args);
+#else
+    /* can do this because we never pass more than 1 arg here anyway... */
+    sprintf(cp, fmt, args);
+#endif
+    display_buff(buf);
 }
-
-
-/*
- * 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.06659 seconds and 4 git commands to generate.