]> andersk Git - moira.git/blobdiff - clients/moira/namespace.c
Build without krb4 if it's unavailable.
[moira.git] / clients / moira / namespace.c
index 2764443d6a3a77336549ffb754022f722886e299..ad6e748de1e082119de1341268081ca1b89cdfb1 100644 (file)
@@ -1,43 +1,39 @@
-#if (!defined(lint) && !defined(SABER))
-  static char rcsid_module_c[] = "$Header$";
-#endif
-
-/*     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.
+/* $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.
  *     It Contains: The main driver for the Moira Client.
  *
  *     Created:        4/12/88
  *     By:             Chris D. Peterson
  *
- *      $Source$
- *      $Author$
- *      $Header$
- *
- *     Copyright 1988 by the Massachusetts Institute of Technology.
- *
- *     For further information on copyright and distribution
- *     see the file mit-copyright.h
+ * Copyright (C) 1988-1998 by the Massachusetts Institute of Technology.
+ * For copying and distribution information, please see the file
+ * <mit-copyright.h>.
  */
 
-#include <pwd.h>
+#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>
-#include <sys/types.h>
-#include <moira.h>
-#include <menu.h>
-#include <krb.h>
 
+RCSID("$Header$");
 
-#include "mit-copyright.h"
-#include "defs.h"
-#include "f_defs.h"
-#include "globals.h"
+static void ErrorExit(char *buf, int status);
+static void Usage(void);
+static void Signal_Handler(void);
+static void CatchInterrupt(void);
+int NewListHelp(int argc, char **argv);
 
 char *whoami;                  /* used by menu.c ugh!!! */
 char *moira_server;
 int interrupt = 0;
-int NewListHelp();
 
 /*
  * List Information Menu
@@ -163,15 +159,9 @@ Menu namespace_menu = {
   }
 };
 
-
-static void Signal_Handler(), CatchInterrupt();
-
-static void ErrorExit(), Usage();
-char *getlogin();
-uid_t getuid();
-struct passwd *getpwuid();
-
+#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.
@@ -179,20 +169,23 @@ 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], '/')))
     program_name = argv[0];
   else
     program_name++;
-  program_name = Strsave(program_name);
-  whoami = Strsave(program_name); /* used by menu.c,  ugh !!! */
+  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;
@@ -203,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)
              {
@@ -211,47 +219,32 @@ void main(int argc, char **argv)
                moira_server = *arg;
              }
            else
-             Usage(argv);
+             Usage();
          else
-           Usage(argv);
+           Usage();
        }
     }
 
-  if ((status = mr_connect(moira_server)))
-    ErrorExit("\nConnection to Moira server failed", status);
+  if (mrcl_connect(moira_server, program_name, QUERY_VERSION, 0)
+      != MRCL_SUCCESS)
+    exit(1);
 
-  /* 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)))
+  if ((status = mr_krb5_auth(program_name)))
     {
-      com_err(whoami, status, "cannot find your ticket file");
-      exit(1);
-    }
-  tf_close();
-  user = Strsave(pname);
+      if (status == MR_UNKNOWN_PROC)
+       status = mr_auth(program_name);
 
-  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 = 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);
     }
 
   /*
@@ -261,19 +254,22 @@ void main(int argc, char **argv)
 
   sigemptyset(&act.sa_mask);
   act.sa_flags = 0;
-  act.sa_handler = (void (*)()) Signal_Handler;
+  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 = (void (*)()) CatchInterrupt;
+      act.sa_handler = CatchInterrupt;
       sigaction(SIGINT, &act, NULL);
     }
 
   menu = &namespace_menu;
 
+#ifdef HAVE_CURSES
   if (use_menu)                /* Start menus that execute program */
     {
       Start_paging();
@@ -281,6 +277,7 @@ void main(int argc, char **argv)
       Stop_paging();
     }
   else                 /* Start program without menus. */
+#endif
     Start_no_menu(menu);
 
   mr_disconnect();
@@ -322,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);
 }
@@ -338,13 +337,13 @@ static void CatchInterrupt(void)
 
 /* Dummy routine to be able to link against the rest of the moira client */
 
-int DeleteUser(void)
+int DeleteUser(int argc, char **argv)
 {
   return DM_QUIT;
 }
 
 
-int NewListHelp(void)
+int NewListHelp(int argc, char **argv)
 {
   static char *message[] = {
     "A list can be a mailing list, an Athena group list, or both.  Each",
This page took 0.039266 seconds and 4 git commands to generate.