#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$");
#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 */
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);
{
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];
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:
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)
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]--;
}
}
}
+#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);
show_text(currow, STARTCOL, "Press any Key to continue...");
getchar();
}
+ free(buf);
clrwin(DISPROW);
}
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++;
printbuf = calloc(maxcol, 1);
}
}
- if (strlen(buf) % maxcol != 0)
+ if (len % maxcol != 0)
{
start_display_buff(printbuf);
- free(printbuf);
}
+ if (printbuf)
+ free(printbuf);
return;
}
show_text(DISPROW + 4, STARTCOL, "Press any Key to continue...");
getchar();
}
+ free(buf);
clrwin(DISPROW);
}
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);
}
show_text(currow, STARTCOL, "Press any Key to continue...");
getchar();
clrwin(DISPROW);
+ free(buf);
}
/****************************************************/
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);
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);
}
/****************************************************/
erase_line(currow, STARTCOL);
show_text(currow, STARTCOL, "Flushing query...");
moreflg = 1;
- return;
+ goto cleanup;
}
clrwin(DISPROW + 2);
currow = DISPROW + 2;
currow++;
}
toggle = !toggle;
+ cleanup:
+ free(buffer);
}
/****************************************************/
show_text(currow, STARTCOL, "Press any key to continue...");
getchar();
clrwin(DISPROW);
+ free(buffer);
}
/****************************************************/
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);
}
/****************************************************/
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)
{
/****************************************************/
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();
/****************************************************/
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();
}
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'):
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)
{