-/* $Id $
+/* $Id$
*
* This is the file main.c for the Moira Client, which allows users
* to quickly and easily maintain most parts of the Moira database.
#include <mit-copyright.h>
#include <moira.h>
+#include <mrclient.h>
#include "defs.h"
#include "f_defs.h"
#include "globals.h"
#include <signal.h>
#include <stdio.h>
#include <string.h>
-#if 0
-#include <pwd.h>
-#include <sys/types.h>
-#endif
-
-#include <krb.h>
RCSID("$Header$");
}
};
+#ifdef HAVE_CURSES
Bool use_menu = TRUE; /* whether or not we are using a menu. */
+#endif
/* Function Name: main
* Description: The main driver for the Moira Client.
* Returns: doesn't return.
*/
-void main(int argc, char **argv)
+int main(int argc, char **argv)
{
int status;
Menu *menu;
char *motd, **arg;
- char pname[ANAME_SZ];
struct sigaction act;
if (!(program_name = strrchr(argv[0], '/')))
program_name = strdup(program_name);
whoami = strdup(program_name); /* used by menu.c, ugh !!! */
+ user = mrcl_krb_user();
+ if (!user)
+ exit(1);
+
verbose = TRUE;
arg = argv;
moira_server = NULL;
if (**arg == '-')
{
if (!strcmp(*arg, "-nomenu"))
- use_menu = FALSE;
+ {
+#ifdef HAVE_CURSES
+ use_menu = FALSE;
+#else
+ ;
+#endif
+ }
+ else if (!strcmp(*arg, "-menu"))
+ {
+#ifdef HAVE_CURSES
+ use_menu = TRUE;
+#else
+ fprintf(stderr, "%s: No curses support. -menu option ignored\n",
+ whoami);
+#endif
+ }
else if (!strcmp(*arg, "-db"))
if (arg - argv < argc - 1)
{
}
}
- if ((status = mr_connect(moira_server)))
- ErrorExit("\nConnection to Moira server failed", status);
-
- /* do this now since calling mr_connect initialized the krb error table
- * for us.
- */
- if ((status = tf_init(TKT_FILE, R_TKT_FIL)) ||
- (status = tf_get_pname(pname)))
- {
- com_err(whoami, status, "cannot find your ticket file");
- exit(1);
- }
- tf_close();
- user = strdup(pname);
+ if (mrcl_connect(moira_server, program_name, QUERY_VERSION, 0)
+ != MRCL_SUCCESS)
+ exit(1);
- if ((status = mr_motd(&motd)))
- ErrorExit("\nUnable to check server status", status);
- if (motd)
+ if ((status = mr_krb5_auth(program_name)))
{
- fprintf(stderr, "The Moira server is currently unavailable:\n%s\n",
- motd);
- mr_disconnect();
- exit(1);
- }
+ if (status == MR_UNKNOWN_PROC)
+ status = mr_auth(program_name);
- if ((status = mr_auth(program_name)))
- {
- if (status == MR_USER_AUTH)
+ if (status)
{
- char buf[BUFSIZ];
- com_err(program_name, status, "\nPress [RETURN] to continue");
- fgets(buf, BUFSIZ, stdin);
+ if (status == MR_USER_AUTH)
+ {
+ char buf[BUFSIZ];
+ com_err(program_name, status, "\nPress [RETURN] to continue");
+ fgets(buf, BUFSIZ, stdin);
+ }
+ else
+ ErrorExit("\nAuthorization failed -- please run kinit", status);
}
- else
- ErrorExit("\nAuthorization failed -- please run kinit", status);
}
/*
act.sa_handler = Signal_Handler;
sigaction(SIGHUP, &act, NULL);
sigaction(SIGQUIT, &act, NULL);
+#ifdef HAVE_CURSES
if (use_menu)
sigaction(SIGINT, &act, NULL);
else
+#endif
{
act.sa_handler = CatchInterrupt;
sigaction(SIGINT, &act, NULL);
menu = &namespace_menu;
+#ifdef HAVE_CURSES
if (use_menu) /* Start menus that execute program */
{
Start_paging();
Stop_paging();
}
else /* Start program without menus. */
+#endif
Start_no_menu(menu);
mr_disconnect();
static void Signal_Handler(void)
{
Put_message("Signal caught - exiting");
+#ifdef HAVE_CURSES
if (use_menu)
Cleanup_menu();
+#endif
mr_disconnect();
exit(1);
}