]> andersk Git - moira.git/blobdiff - clients/moira/main.c
Replaced all the EQUEL with ESQL. A few lines may not be proper
[moira.git] / clients / moira / main.c
index a32c5be7d1c156e164f5742c49b8b09e3ebfa4ee..c3fe52982d403b035f2319103cc882217b927b02 100644 (file)
@@ -2,9 +2,9 @@
   static char rcsid_module_c[] = "$Header$";
 #endif lint
 
-/*     This is the file main.c for the SMS Client, which allows a nieve
- *      user to quickly and easily maintain most parts of the SMS database.
- *     It Contains: The main driver for the SMS Client.
+/*     This is the file main.c for the Moira Client, which allows a nieve
+ *      user to quickly and easily maintain most parts of the Moira database.
+ *     It Contains: The main driver for the Moira Client.
  *     
  *     Created:        4/12/88
  *     By:             Chris D. Peterson
@@ -24,8 +24,9 @@
 #include <stdio.h>
 #include <strings.h>
 #include <sys/types.h>
-#include <sms.h>
+#include <moira.h>
 #include <menu.h>
+#include <krb_et.h>
 
 #include "mit-copyright.h"
 #include "defs.h"
 #include "globals.h"
 
 char * whoami;                 /* used by menu.c ugh!!! */
+char * moira_server;
+int interrupt = 0;
 
-extern Menu sms_top_menu, list_menu, user_menu, dcm_menu;
+extern Menu moira_top_menu, list_menu, user_menu, dcm_menu;
 
 #ifndef DEBUG
-static void SignalHandler();
+static void SignalHandler(), CatchInterrupt();
 #endif DEBUG
 
 static void ErrorExit(), Usage();
@@ -45,10 +48,14 @@ char *getlogin();
 uid_t getuid();
 struct passwd *getpwuid();
 
+#ifdef _AIX
+Bool use_menu = FALSE;         /* whether or not we are using a menu. */
+#else
 Bool use_menu = TRUE;          /* whether or not we are using a menu. */
+#endif
 
 /*     Function Name: main
- *     Description: The main driver for the SMS Client.
+ *     Description: The main driver for the Moira Client.
  *     Arguments: argc, argv - standard command line args.
  *     Returns: doesn't return.
  */
@@ -60,6 +67,7 @@ main(argc, argv)
 {
     int status;
     Menu *menu;
+    char *motd, **arg;
 
     if ((user = getlogin()) == NULL) 
        user = getpwuid((int) getuid())->pw_name;
@@ -72,29 +80,49 @@ main(argc, argv)
     program_name = Strsave(program_name);
     whoami = Strsave(program_name); /* used by menu.c,  ugh !!! */
 
-    init_sms_err_tbl();
-    init_krb_err_tbl();
     verbose = TRUE;
-
-    switch (argc) {
-    case 2:
-      if (strcmp(argv[1], "-nomenu") == 0)
-       use_menu = FALSE;
-      else 
-       Usage();
-      break;
-    case 1:
-      break;
-    default:
-      Usage();
-      break;
+    arg = argv;
+    moira_server = NULL;
+
+    while (++arg - argv < argc) {
+       if (**arg == '-') {
+           if (!strcmp(*arg, "-nomenu"))
+             use_menu = FALSE;
+           else if (!strcmp(*arg, "-db"))
+             if (arg - argv < argc - 1) {
+                 ++arg;
+                 moira_server = *arg;
+             } else
+               Usage(argv);
+           else
+             Usage(argv);
+       }
     }
 
-    if ( status = sms_connect(SMS_SERVER) ) 
-       ErrorExit("\nConnection to SMS server failed", status);
+    if ( status = mr_connect(moira_server) ) 
+       ErrorExit("\nConnection to Moira server failed", status);
+
+    if ( status = mr_motd(&motd) )
+        ErrorExit("\nUnable to check server status", status);
+    if (motd) {
+       fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd);
+       mr_disconnect();
+       exit(1);
+    }
 
-    if ( status = sms_auth(program_name) ) 
-       ErrorExit("\nAuthorization failed -- please run kinit", status);
+    if ( status = mr_auth(program_name) ) {
+       if (status == MR_USER_AUTH) {
+           char buf[BUFSIZ];
+           com_err(program_name, status, "\nPress [RETURN] to continue");
+           gets(buf);
+       } else {
+         if (status >= ERROR_TABLE_BASE_krb &&
+             status <= ERROR_TABLE_BASE_krb + 256)
+           ErrorExit("\nAuthorization failed -- please run kinit", status);
+         else
+           ErrorExit("\nAuthorization failed.", status);
+       }
+    }
 
 /*
  * These signals should not be set until just before we fire up the menu
@@ -103,8 +131,11 @@ main(argc, argv)
 
 #ifndef DEBUG
     (void) signal(SIGHUP, SignalHandler);
-    (void) signal(SIGINT, SignalHandler); 
     (void) signal(SIGQUIT, SignalHandler);
+    if (use_menu)
+      (void) signal(SIGINT, SignalHandler); 
+    else
+      (void) signal(SIGINT, CatchInterrupt); 
 #endif DEBUG
 
     if (!strcmp(program_name, "listmaint"))
@@ -114,7 +145,7 @@ main(argc, argv)
     else if (!strcmp(program_name, "dcmmaint"))
       menu = &dcm_menu;
     else
-      menu = &sms_top_menu;
+      menu = &moira_top_menu;
 
     if (use_menu) {            /* Start menus that execute program */
         Start_paging();
@@ -124,7 +155,7 @@ main(argc, argv)
     else                       /* Start program without menus. */
        Start_no_menu(menu);
 
-    sms_disconnect();
+    mr_disconnect();
     exit(0);
 }
 
@@ -141,7 +172,7 @@ int status;
 char * buf;    
 {
     com_err(program_name, status, buf);
-    sms_disconnect();
+    mr_disconnect();
     exit(1);
 }
 
@@ -171,7 +202,15 @@ SignalHandler()
     Put_message("Signal caught - exiting");
     if (use_menu)
       Cleanup_menu();
-    sms_disconnect();
+    mr_disconnect();
     exit(1);
 }
+
+
+static void
+CatchInterrupt()
+{
+    Put_message("Interrupt! Press RETURN to continue");
+    interrupt = 1;
+}
 #endif DEBUG
This page took 0.041073 seconds and 4 git commands to generate.