]> andersk Git - moira.git/blobdiff - clients/mailmaint/mailmaint.c
Build without krb4 if it's unavailable.
[moira.git] / clients / mailmaint / mailmaint.c
index 554b1a1c3a52bbc49e7de32504851b54635cdf58..27ef2d7b1f0b1bb76d5f120abfa0736c1fbbac96 100644 (file)
 #include <mit-copyright.h>
 #include <moira.h>
 #include <moira_site.h>
+#include <mrclient.h>
 
 #include <ctype.h>
+#ifdef HAVE_CURSES
+#ifdef _WIN32
+#include <conio.h>
+#ifdef MOUSE_MOVED
+#undef MOUSE_MOVED
+#endif
+#endif /*_WIN32*/
 #include <curses.h>
-#include <pwd.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#ifdef HAVE_UNISTD_H
 #include <unistd.h>
-
-#include <krb.h>
+#endif
+
+#ifdef _WIN32
+#define INPUT_MASK 0xff
+#ifdef getchar
+#undef getchar
+#endif
+#define getchar() _getch()
+#ifdef title
+#undef title
+#endif
+static void DELETE_A_CHAR(void)
+{
+    int x, y;
+    getsyx(&y, &x);
+    x -= 1;
+    mvdelch(y,x);
+}
+#else /* !_WIN32 */
+#define INPUT_MASK 0x7f
+#define DELETE_A_CHAR() printf("\b \b");
+#endif /* !_WIN32 */
 
 RCSID("$Header$");
 
@@ -31,6 +60,9 @@ RCSID("$Header$");
 #define LISTMAX 50
 #define LISTSIZE 32
 #define CTL(ch) ((ch) & 037)
+#ifdef MAX
+#undef MAX
+#endif
 #define MAX(A, B) ((A) > (B) ? (A) : (B))
 
 char *whoami;          /* should not be static, for logging package */
@@ -84,6 +116,7 @@ void end_display(void);
 void display_menu(MENU *menu);
 void pack_main_menu(void);
 void pack_help_menu(void);
+void free_menu(MENU* menu);
 void highlight(MENU *menu);
 void title(char *buff);
 void center_text(int row, char *buff);
@@ -107,7 +140,7 @@ int main(int argc, char *argv[])
 {
   void (*old_hook)(const char *, long, const char *, va_list);
   int use_menu = 1, k_errno;
-  char buf[BUFSIZ], pname[ANAME_SZ], *motd;
+  char buf[BUFSIZ];
 
   if ((whoami = strrchr(argv[0], '/')) == NULL)
     whoami = argv[0];
@@ -128,72 +161,58 @@ int main(int argc, char *argv[])
       current_li->modwith = NULL;
     }
 
-  if ((k_errno = tf_init(TKT_FILE, R_TKT_FIL)) ||
-      (k_errno = tf_get_pname(pname)))
+  username = mrcl_krb_user();
+  if (!username)
+    exit(1);
+  
+  if (mrcl_connect(NULL, "mailmaint", 2, 1))
+    exit(2);
+
+  initscr();
+  if ((LINES < 24) || (COLS < 60))
     {
-      com_err(whoami, k_errno, "reading Kerberos ticket file");
-      exit(1);
+      display_buff("Display window too small.\n\n");
+      sprintf(buf, "Current window parameters are (%d lines, %d columns)\n",
+             LINES, COLS);
+      display_buff(buf);
+      display_buff("Please resize your window\n");
+      display_buff("to at least 24 lines and 60 columns.\n");
+      exit(0);
     }
-  tf_close();
-  username = pname;
 
-  printf("Connecting to database for %s...please hold on.\n", username);
+  raw();
+  noecho();
+  old_hook = set_com_err_hook(menu_err_hook);
+  position[0] = oldpos[0] = 1;
+  level = 0;
 
-  status = mr_connect(NULL);
-  if (status)
-    {
-      sprintf(buf, "\nConnection to Moira server failed");
-      goto punt;
-    }
+  pack_main_menu();
+  pack_help_menu();
+  display_menu(main_menu);
+  get_main_input();
+  cls();
+  endwin();
+  set_com_err_hook(old_hook);
 
-  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)
-    {
-      sprintf(buf, "\nAuthorization failed.\n");
-      goto punt;
-    }
+  free_menu(main_menu);
+  free_menu(help_menu);
+
+  if (current_li->acl_type)
+    free(current_li->acl_type);
+  if (current_li->acl_name)
+    free(current_li->acl_name);
+  if (current_li->desc)
+    free(current_li->desc);
+  if (current_li->modtime)
+    free(current_li->modtime);
+  if (current_li->modby)
+    free(current_li->modby);
+  if (current_li->modwith)
+    free(current_li->modwith);
+  free(current_li);
+
+  mr_disconnect();
 
-  if (use_menu)
-    {
-      initscr();
-      if ((LINES < 24) || (COLS < 60))
-       {
-         display_buff("Display window too small.\n\n");
-         sprintf(buf,
-                 "Current window parameters are (%d lines, %d columns)\n",
-                 LINES, COLS);
-         display_buff(buf);
-         display_buff("Please resize your window\n");
-         display_buff("to at least 24 lines and 60 columns.\n");
-         exit(0);
-       }
-      raw();
-      noecho();
-      old_hook = set_com_err_hook(menu_err_hook);
-      position[0] = oldpos[0] = 1;
-      level = 0;
-      pack_main_menu();
-      pack_help_menu();
-      display_menu(main_menu);
-      get_main_input();
-      cls();
-      endwin();
-      set_com_err_hook(old_hook);
-    }
   exit(0);
 
 punt:
@@ -214,7 +233,7 @@ void get_main_input(void)
       currow = DISPROW + 2;
       page = 1;
       toggle = num_members = moreflg = 0;
-      c = getchar() & 0x7f;    /* mask parity bit */
+      c = getchar() & INPUT_MASK;      /* mask parity bit */
       if (c == '\r' || c == '\n')
        {
          if (position[level] == 7)
@@ -268,11 +287,12 @@ void get_main_input(void)
          if (retflg)
            delete_member();
          break;
+#ifndef _WIN32
        case 27:                /* escape */
-         c = getchar() & 0x7f;
+         c = getchar() & INPUT_MASK;
          if (c == 91)
            {
-             c = getchar() & 0x7f;
+             c = getchar() & INPUT_MASK;
              if (c == 65)      /* up arrow */
                {
                  position[level]--;
@@ -289,6 +309,25 @@ void get_main_input(void)
                    }
                }
            }
+#else /* _WIN32 */
+       case 0xe0:
+         c = getchar() & INPUT_MASK;
+         if (c == 0x48)        /* up arrow */
+           {
+             position[level]--;
+             if (!position[level])
+               position[level] = 7;
+           }
+         else
+           {
+             if (c == 0x50)    /* down arrow */
+               {
+                 position[level]++;
+                 if (position[level] > 7)
+                   position[level] = 1;
+               }
+           }
+#endif /* _WIN32 */
          break;
        default:
          printf("%c", 7);
@@ -334,6 +373,7 @@ void show_list_info(void)
       show_text(currow, STARTCOL, "Press any Key to continue...");
       getchar();
     }
+  free(buf);
   clrwin(DISPROW);
 }
 
@@ -341,14 +381,16 @@ void show_list_info(void)
 void display_buff(char *buf)
 {
   int i, cnt;
-  char *printbuf;
+  char *printbuf = NULL;
   int maxcol;
+  int len;
 
   maxcol = COLS;
 
   cnt = 0;
   printbuf = calloc(maxcol, 1);
-  for (i = 0; i <= strlen(buf); i++)
+  len = strlen(buf);
+  for (i = 0; i <= len; i++)
     {
       printbuf[cnt] = buf[i];
       cnt++;
@@ -360,11 +402,12 @@ void display_buff(char *buf)
          printbuf = calloc(maxcol, 1);
        }
     }
-  if (strlen(buf) % maxcol != 0)
+  if (len % maxcol != 0)
     {
       start_display_buff(printbuf);
-      free(printbuf);
     }
+  if (printbuf)
+    free(printbuf);
   return;
 }
 
@@ -427,6 +470,7 @@ void add_member(void)
       show_text(DISPROW + 4, STARTCOL, "Press any Key to continue...");
       getchar();
     }
+  free(buf);
   clrwin(DISPROW);
 }
 
@@ -457,7 +501,11 @@ void delete_member(void)
       currow = DISPROW + 4;
       show_text(DISPROW + 4, STARTCOL, "Press any Key to continue...");
       getchar();
+      free(argv[0]);
+      free(argv[1]);
+      free(argv[2]);
     }
+  free(buf);
   clrwin(DISPROW);
 }
 
@@ -483,6 +531,7 @@ void list_by_member(void)
   show_text(currow, STARTCOL, "Press any Key to continue...");
   getchar();
   clrwin(DISPROW);
+  free(buf);
 }
 
 /****************************************************/
@@ -491,7 +540,7 @@ void show_all(void)
   char c;
 
   show_text(DISPROW, STARTCOL, "This function may take a while... proceed? [n] ");
-  c = getchar() & 0x7f;
+  c = getchar() & INPUT_MASK;
   if (c == 'y' || c == 'Y')
     {
       move(DISPROW + 1, STARTCOL);
@@ -580,12 +629,14 @@ void list_members(void)
          show_text(currow, STARTCOL, "Press any key to continue...");
          getchar();
          clrwin(DISPROW);
-         return;
+         goto cleanup;
        }
       end_display();
-      return;
+      goto cleanup;
     }
   clrwin(DISPROW);
+ cleanup:
+  free(buf);
 }
 
 /****************************************************/
@@ -621,7 +672,7 @@ void start_display(char *buff)
          erase_line(currow, STARTCOL);
          show_text(currow, STARTCOL, "Flushing query...");
          moreflg = 1;
-         return;
+         goto cleanup;
        }
       clrwin(DISPROW + 2);
       currow = DISPROW + 2;
@@ -639,6 +690,8 @@ void start_display(char *buff)
       currow++;
     }
   toggle = !toggle;
+ cleanup:
+  free(buffer);
 }
 
 /****************************************************/
@@ -660,6 +713,7 @@ void end_display(void)
   show_text(currow, STARTCOL, "Press any key to continue...");
   getchar();
   clrwin(DISPROW);
+  free(buffer);
 }
 
 /****************************************************/
@@ -715,6 +769,7 @@ void pack_main_menu(void)
   main_menu->items[4] = strdup("5.  Add yourself to a mailing list.");
   main_menu->items[5] = strdup("6.  Delete yourself from a mailing list.");
   main_menu->items[6] = strdup("q.  Quit.");
+  free(buf);
 }
 
 /****************************************************/
@@ -732,6 +787,17 @@ void pack_help_menu(void)
   help_menu->items[4] = strdup("Press any key to continue.");
 }
 
+/****************************************************/
+void free_menu(MENU* menu)
+{
+  int i;
+  for (i = 0; i < menu->num_items; i++)
+    free(menu->items[i]);
+  free(menu->items);
+  free(menu->title);
+  free(menu);
+}
+
 /****************************************************/
 void highlight(MENU *menu)
 {
@@ -754,7 +820,7 @@ void highlight(MENU *menu)
 /****************************************************/
 void title(char *buff)
 {
-  move(0, MAX(0, (COLS - strlen(buff)) >> 1));
+  move(0, MAX(0, (COLS - (int)strlen(buff)) >> 1));
   standout();
   addstr(buff);
   refresh();
@@ -764,7 +830,7 @@ void title(char *buff)
 /****************************************************/
 void center_text(int row, char *buff)
 {
-  move(row, MAX(0, (COLS - strlen(buff)) >> 1));
+  move(row, MAX(0, (COLS - (int)strlen(buff)) >> 1));
   addstr(buff);
   refresh();
 }
@@ -866,10 +932,11 @@ int Prompt(char *prompt, char *buf, int buflen, int crok)
 
   addstr(prompt);
   refresh();
+
   for (p = buf; abs(strlen(p) - strlen(buf)) <= buflen;)
     {
       refresh();
-      c = getchar() & 0x7f;
+      c = getchar() & INPUT_MASK;
       switch (c)
        {
        case CTL('C'):
@@ -894,16 +961,22 @@ int Prompt(char *prompt, char *buf, int buflen, int crok)
          if (p > buf)
            {
              p--;
-             printf("\b \b");
+             DELETE_A_CHAR();
            }
          break;
        case CTL('U'):
        case CTL('G'):
        case CTL('['):
          while (p-- > buf)
-           printf("\b \b");
+           DELETE_A_CHAR();
          p = buf;
          break;
+#ifdef _WIN32
+       case 0xe0:
+         c = getchar() & INPUT_MASK;
+         putchar(CTL('G'));
+         break;
+#endif /*_WIN32*/
        default:
          if (abs(strlen(p) - strlen(buf)) >= buflen)
            {
This page took 0.087551 seconds and 4 git commands to generate.