]> andersk Git - moira.git/blobdiff - clients/moira/namespace.c
Build without krb4 if it's unavailable.
[moira.git] / clients / moira / namespace.c
index 17eb2005e5d9b8efd71466b0aa951893ac5bf540..ad6e748de1e082119de1341268081ca1b89cdfb1 100644 (file)
@@ -1,4 +1,4 @@
-/* $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.
@@ -14,6 +14,7 @@
 
 #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$");
 
@@ -164,7 +159,9 @@ Menu namespace_menu = {
   }
 };
 
+#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.
@@ -172,12 +169,11 @@ Bool use_menu = TRUE;             /* whether or not we are using a menu. */
  *     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], '/')))
@@ -187,6 +183,10 @@ void main(int argc, char **argv)
   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;
@@ -196,7 +196,22 @@ void main(int argc, char **argv)
       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)
              {
@@ -210,41 +225,26 @@ void main(int argc, char **argv)
        }
     }
 
-  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);
     }
 
   /*
@@ -257,9 +257,11 @@ void main(int argc, char **argv)
   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);
@@ -267,6 +269,7 @@ void main(int argc, char **argv)
 
   menu = &namespace_menu;
 
+#ifdef HAVE_CURSES
   if (use_menu)                /* Start menus that execute program */
     {
       Start_paging();
@@ -274,6 +277,7 @@ void main(int argc, char **argv)
       Stop_paging();
     }
   else                 /* Start program without menus. */
+#endif
     Start_no_menu(menu);
 
   mr_disconnect();
@@ -315,8 +319,10 @@ static void Usage(void)
 static void Signal_Handler(void)
 {
   Put_message("Signal caught - exiting");
+#ifdef HAVE_CURSES
   if (use_menu)
     Cleanup_menu();
+#endif
   mr_disconnect();
   exit(1);
 }
This page took 0.038191 seconds and 4 git commands to generate.