}
#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