]> andersk Git - moira.git/blobdiff - clients/passwd/chsh.c
*** empty log message ***
[moira.git] / clients / passwd / chsh.c
index 75bb9ed10ed6b6ced510d7261ec358810bb9e33d..f000a263a5955eedb404600af63352d5fb4509bd 100644 (file)
@@ -13,7 +13,7 @@ static char *rcsid_chsh_c = "$Header$";
 #endif not lint
 
 /*
- * Talk to the SMS database to change a person's login shell.  The chosen
+ * Talk to the MOIRA database to change a person's login shell.  The chosen
  * shell must exist.  A warning will be issued if the shell is not in 
  * /etc/shells.
  * 
@@ -25,17 +25,20 @@ static char *rcsid_chsh_c = "$Header$";
  *
  */
 
+#ifdef POSIX
+#include <unistd.h>
+#endif
 #include <sys/types.h>
 #include <stdio.h>
-#include <strings.h>
+#include <string.h>
 #include <sys/file.h>
 #include <krb.h>
 #include <ctype.h>
 #include <errno.h>
 
-/* SMS includes */
-#include <sms.h>
-#include <sms_app.h>
+/* MOIRA includes */
+#include <moira.h>
+#include <moira_site.h>
 #include "mit-copyright.h"
 
 char *whoami;
@@ -52,7 +55,7 @@ main(argc, argv)
     int k_errno;
     char *whoami;
 
-    if ((whoami = rindex(argv[0], '/')) == NULL)
+    if ((whoami = strrchr(argv[0], '/')) == NULL)
        whoami = argv[0];
     else
        whoami++;
@@ -86,16 +89,16 @@ main(argc, argv)
 
 leave(status)
   int status;
-  /* This should be called rather than exit once connection to sms server
+  /* This should be called rather than exit once connection to moira server
      has been established. */
 {
-    sms_disconnect();
+    mr_disconnect();
     exit(status);
 }
 
 scream()
 {
-    com_err(whoami, 0, "Unexpected return value from SMS -- programmer botch");
+    com_err(whoami, 0, "Unexpected return value from Moira -- programmer botch");
     leave(1);
 }
 
@@ -103,8 +106,9 @@ chsh(uname)
   char *uname;
 {
     int status;                        /* general purpose exit status */
-    int q_argc;                        /* argc for sms_query */
-    char *q_argv[U_END];       /* argv for sms_query */
+    int q_argc;                        /* argc for mr_query */
+    char *q_argv[U_END];       /* argv for mr_query */
+    char *motd;                        /* determine MR server status */
 
     int got_one = 0;           /* have we got a new shell yet? */
     char shell[BUFSIZ];                /* the new shell */
@@ -113,13 +117,23 @@ chsh(uname)
 
     /* Try each query.  If we ever fail, print error message and exit. */
 
-    status = sms_connect(SMS_SERVER);
+    status = mr_connect(NULL);
     if (status) {
-       com_err(whoami, status, " while connecting to SMS");
+       com_err(whoami, status, " while connecting to Moira");
        exit(1);
     }
 
-    status = sms_auth("chsh"); /* Don't use argv[0] - too easy to fake */
+    status = mr_motd(&motd);
+    if (status) {
+        com_err(whoami, status, " unable to check server status");
+       leave(1);
+    }
+    if (motd) {
+       fprintf(stderr, "The Moira server is currently unavailable:\n%s\n", motd);
+       leave(1);
+    }
+
+    status = mr_auth("chsh");  /* Don't use argv[0] - too easy to fake */
     if (status) {
        com_err(whoami, status, 
                " while authenticating -- run \"kinit\" and try again.");
@@ -132,7 +146,7 @@ chsh(uname)
     q_argv[USH_SHELL] = "junk";
     q_argc = USH_END;
 
-    if (status = sms_access("update_user_shell", q_argc, q_argv))
+    if (status = mr_access("update_user_shell", q_argc, q_argv))
     {
        com_err(whoami, status, "; shell not\nchanged.");
        leave(2);
@@ -145,7 +159,7 @@ chsh(uname)
     q_argv[NAME] = uname;
     q_argc = NAME + 1;
 
-    if ((status = sms_query("get_user_by_login", q_argc, q_argv, 
+    if ((status = mr_query("get_user_account_by_login", q_argc, q_argv, 
                            get_shell, (char *) uname)))
     {
        com_err(whoami, status, " while getting user information.");
@@ -156,7 +170,8 @@ chsh(uname)
     while (!got_one)
     {
        printf("New shell: ");
-       (void) fgets(shell, sizeof(shell), stdin);
+       if (fgets(shell, sizeof(shell), stdin) == NULL)
+         leave(0);
        got_one = (strlen(shell) > 1);
     }
 
@@ -172,7 +187,7 @@ chsh(uname)
     q_argv[USH_NAME] = uname;
     q_argv[USH_SHELL] = shell; 
     q_argc = USH_END;
-    if (status = sms_query("update_user_shell", q_argc, q_argv, 
+    if (status = mr_query("update_user_shell", q_argc, q_argv, 
                           scream, (char *) NULL))
     {
        com_err(whoami, status, " while changing shell.");
@@ -180,7 +195,7 @@ chsh(uname)
     }
 
     printf("Shell successfully changed.\n");
-    sms_disconnect();
+    mr_disconnect();
 
     return(0);
 }
@@ -193,7 +208,7 @@ get_shell(argc, argv, uname)
     /* We'll just take the first information we get since login names 
        cannot be duplicated in the database. */
     
-    if (strcmp(argv[U_NAME], uname))
+    if (argc < U_END || strcmp(argv[U_NAME], uname))
     {
        fprintf(stderr, "Some internal error has occurred.  Try again.\n");
        leave(3);
@@ -203,7 +218,7 @@ get_shell(argc, argv, uname)
     printf("by user %s with %s.\n", argv[U_MODBY], argv[U_MODWITH]);
     printf("Current shell for %s is %s.\n", uname, argv[U_SHELL]); 
     
-    return(SMS_ABORT);         /* Don't pay attention to other matches. */
+    return(MR_ABORT);          /* Don't pay attention to other matches. */
 }
     
 void check_shell(shell)
@@ -217,7 +232,7 @@ void check_shell(shell)
            ok = 1;
            break;
        }
-       else if (strcmp(shell, 1+rindex(valid_shell, '/')) == NULL) {
+       else if (strcmp(shell, 1+strrchr(valid_shell, '/')) == NULL) {
            ok = 1;
            (void) strcpy(shell, valid_shell);
            break;
@@ -248,3 +263,22 @@ usage()
     fprintf(stderr, "Usage: %s [user]\n", whoami);
     exit(1);
 }
+
+#if defined(ultrix) || defined(_AIX)
+char *getusershell()
+{
+    static int count = 1;
+
+    switch (count++) {
+    case 1:
+       return("/bin/sh");
+    case 2:
+       return("/bin/csh");
+    case 3:
+       return(NULL);
+    default:
+       count = 1;
+       return(getusershell());
+    }
+}
+#endif
This page took 0.055476 seconds and 4 git commands to generate.