[1834] in Moira Commits

home help back first fref pref prev next nref lref last post

/svn/moira r3981 - trunk/moira/clients/chsh

daemon@ATHENA.MIT.EDU (Garry Zacheiss)
Tue Feb 16 16:13:12 2010

Date: Tue, 16 Feb 2010 16:13:05 -0500
From: Garry Zacheiss <zacheiss@MIT.EDU>
Message-Id: <201002162113.o1GLD5b7008165@drugstore.mit.edu>
To: moira-commits@mit.edu
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

Author: zacheiss
Date: 2010-02-16 16:13:05 -0500 (Tue, 16 Feb 2010)
New Revision: 3981

Modified:
   trunk/moira/clients/chsh/chsh.c
Log:
Support -s flag for specifying shell from the command line.

Modified: trunk/moira/clients/chsh/chsh.c
===================================================================
--- trunk/moira/clients/chsh/chsh.c	2010-02-16 20:29:54 UTC (rev 3980)
+++ trunk/moira/clients/chsh/chsh.c	2010-02-16 21:13:05 UTC (rev 3981)
@@ -23,6 +23,7 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#include <sys/param.h>
 
 #define argis(a, b) (!strcmp(*arg + 1, a) || !strcmp(*arg + 1, b))
 
@@ -47,10 +48,9 @@
   char *q_argv[U_END];          /* argv for mr_query */
   char *motd;                   /* determine Moira server status */
   int got_one = 0;              /* Have we got a shell yet? */
-  char shell[BUFSIZ];           /* Our new shell */
   int windowsflg = 0, unixflg = 0;  
   char **arg = argv;
-  char *server = NULL;
+  char *server = NULL, *shell = NULL;
 
   if ((whoami = strrchr(argv[0], '/')) == NULL)
     whoami = argv[0];
@@ -66,6 +66,16 @@
 	    windowsflg++;
 	  else if (argis("u", "unixshell"))
 	    unixflg++;
+	  else if (argis("s", "shell"))
+	    {
+	      if (arg - argv < argc - 1)
+		{
+		  ++arg;
+		  shell = *arg;
+		}
+	      else
+		usage();
+	    }
 	  else if (argis("db", "database"))
 	    {
 	      if (arg - argv < argc - 1)
@@ -96,7 +106,7 @@
   if (unixflg && windowsflg)
     usage();
   
-  if (mrcl_connect(server, "chsh", 12, 1) != MRCL_SUCCESS)
+  if (mrcl_connect(server, "chsh", 14, 1) != MRCL_SUCCESS)
     exit(1);
 
   /* First, do an access check */
@@ -133,18 +143,25 @@
 	  com_err(whoami, status, "while getting user information.");
 	  exit(2);
 	}
-      
-      /* Ask for new shell */
-      while (!got_one)
+
+
+      if (!shell)
 	{
-	  printf("New shell: ");
-	  if (!fgets(shell, sizeof(shell), stdin))
-	    exit(0);
-	  got_one = (strlen(shell) > 1);
+	  /* Ask for new shell */
+	  while (!got_one)
+	    {
+	      shell = malloc(MAXPATHLEN);
+	      if (!shell)
+		exit(1);
+	      printf("New shell: ");
+	      if (!fgets(shell, MAXPATHLEN, stdin))
+		exit(0);
+	      got_one = (strlen(shell) > 1);
+	    }
+
+	  shell[strlen(shell) - 1] = 0; /* trim newline */
 	}
-      
-      shell[strlen(shell) - 1] = 0;	/* strip off newline */
-      
+
       /* Make sure we have a valid shell.  This routine could exit */
       check_shell(shell);
       
@@ -171,17 +188,23 @@
 	  com_err(whoami, status, "while getting user information.");
 	  exit(2);
 	}
+
+      if (!shell)
+	{
+	  /* Ask for new Windows shell */
+	  while(!got_one)
+	    {
+	      shell = malloc(MAXPATHLEN);
+	      if (!shell)
+		exit(1);
+	      printf("New Windows shell: ");
+	      if (!fgets(shell, MAXPATHLEN, stdin))
+		exit(0);
+	      got_one = (strlen(shell) > 1);
+	    }
       
-      /* Ask for new Windows shell */
-      while(!got_one)
-	{
-	  printf("New Windows shell: ");
-	  if (!fgets(shell, sizeof(shell), stdin))
-	    exit(0);
-	  got_one = (strlen(shell) > 1);
+	  shell[strlen(shell) - 1] = 0; /* strip off newline */
 	}
-      
-      shell[strlen(shell) - 1] = 0; /* strip off newline */
 
       /* Change shell */
       
@@ -300,7 +323,7 @@
 
 void usage(void)
 {
-  fprintf(stderr, "Usage: %s [-w|-u] [user]\n", whoami);
+  fprintf(stderr, "Usage: %s [-w|-u] [-s shell] [user]\n", whoami);
   exit(1);
 }
 


home help back first fref pref prev next nref lref last post