Fix to sidestep nonexistent/nonexecutable shell. 4.2BSD.
Hans Albertsson
hans-su at log-hb.UUCP
Sat May 12 22:30:30 AEST 1984
[Wasn't that tasty?]
If the desired shell ( as entered in /etc/passwd ) doesn't
exist, or isn't executable, login simply quits.
If this happens to be the shell used by root, you're in deep
trouble.
The following fix to login.c tries for the standard shells
in turn, testing each on the way, first csh, then sh.
Possibly applies to other unices, but found on 4.2BSD.
In response to all disbelieving cries:
YES it DID happen to me...
My own fault, too.
Here are the rcsdiffs.
Apply to /usr/src/bin/login.c
------------------------------------------------------------------------
RCS file: login.c,v
retrieving revision 1.1
retrieving revision 1.5
diff -r1.1 -r1.5
65a66
> extern char *sys_errlist[];
155c156,157
< if (!strcmp(pwd->pw_shell, "/bin/csh")) {
---
> if (!strcmp(pwd->pw_shell, "/bin/csh") ||
> !strcmp(pwd->pw_shell, "/bin/tcsh") ) {
201a204,222
> /*
> * See if the suggested shell is executable. Otherwise use a default
> * shell. Hoping that "sh" at least isn't in trouble...
> *
> */
> #define X_OK 1
> if (access( pwd->pw_shell, X_OK ) == -1 ) {
> printf("Desired shell(%s) unavailable.\n",
> pwd->pw_shell);
> printf("%s: %s\n",pwd->pw_shell,sys_errlist[errno]);
> pwd->pw_shell = "/bin/csh";
> if (access( pwd->pw_shell, X_OK ) == -1 ) {
> pwd->pw_shell = "/bin/sh";
> if (access( pwd->pw_shell, X_OK ) == -1 ) {
> printf("Cannot find usable shell. Find a guru.");
> }
> }
> printf("Using %s instead.\n",pwd->pw_shell);
> }
------------------------------------------------------------------------
--
{decvax,philabs}!mcvax!enea!log-hb!hans
Hans Albertsson,
TeleLOGIC AB
Box 1001,
S-14901 Nynashamn,
SWEDEN
More information about the Comp.unix.wizards
mailing list