]> andersk Git - moira.git/commitdiff
rewrite the local getusershell to actually read /etc/shells rather
authordanw <danw>
Tue, 22 Jun 1999 01:09:21 +0000 (01:09 +0000)
committerdanw <danw>
Tue, 22 Jun 1999 01:09:21 +0000 (01:09 +0000)
than hard-coding a list of valid shells, so it matches the behavior of
systems with a getusershell in libc.

as a side effect, this makes /bin/athena/bash an acceptable shell on
8.3 machines now.

clients/passwd/chsh.c

index 6a4db2ba749f7cc51c9975128db5f2ae6d9cc0e1..a10bde303bd03cacb103861b00bc49e3c6ff017b 100644 (file)
@@ -223,23 +223,47 @@ void usage(void)
 }
 
 #ifndef HAVE_GETUSERSHELL
+#include <sys/param.h>
+
 char *getusershell(void)
 {
-  static int count = 1;
+  static FILE *shells = NULL;
+
+  /* In a sane universe, no shell will have a length longer than
+   * MAXPATHLEN. If any line in /etc/shells does, we'll lose, but
+   * not much. shrug.
+   */
+  static char buf[MAXPATHLEN];
+  char *p;
+
+  if (!shells)
+    {
+      shells = fopen("/etc/shells", "r");
+      if (!shells)
+       {
+         fprintf(stderr, "%s: Can't open /etc/shells. Unable to determine if "
+                 "this is a normal shell.\n\n", whoami);
+         return NULL;
+       }
+    }
 
-  switch (count++)
+  while (1)
     {
-    case 1:
-      return "/bin/sh";
-    case 2:
-      return "/bin/csh";
-    case 3:
-      return "/bin/athena/tcsh";
-    case 4:
-      return NULL;
-    default:
-      count = 1;
-      return getusershell();
+      if (!fgets(buf, sizeof(buf), shells))
+       {
+         fclose(shells);
+         shells = NULL;
+         return NULL;
+       }
+
+      if (buf[0] != '/')
+       continue;
+
+      p = strchr(buf, '\n');
+      if (p)
+       *p = '\0';
+
+      return buf;
     }
 }
 #endif
This page took 0.044071 seconds and 5 git commands to generate.