[Pkg-shadow-devel] Bug#479406: su fails for users with a POSIX script as their login shell

Stephane Chazelas Stephane_Chazelas at yahoo.fr
Mon May 5 10:18:47 UTC 2008


BTW, this code (thanksfully disabled on Linux) is wrong:

        /* Linux handles #! in the kernel, and bash doesn't make
           sense of "#!" so it wouldn't work anyway...  --marekm */
#ifndef __linux__
        /*
         * It is perfectly OK to have a shell script for a login
         * shell, and this code attempts to support that.  It
         * relies on the standard shell being able to make sense
         * of the "#!" magic number.
         */
        if (err == ENOEXEC) {
                FILE *fp;

                if ((fp = fopen (file, "r"))) {
                        if (getc (fp) == '#' && getc (fp) == '!') {
                                fclose (fp);
                                execle ("/bin/sh", "sh",
                                        file, (char *) 0, envp);
                                err = errno;
                        } else {
                                fclose (fp);
                        }
                }
        }
#endif

(in libmisc/shell.c)

No "standard shell" would ever parse the "#!" if called as "sh
the-file". Some (such as zsh or some other shells compiled on
systems that don't support #! (basically, no modern one)) may
parse that line if called as sh -c 'that-file' as they would try
to execute it (not interprete it) and upon the ENOEXEC parse the
#! line to substitute for the kernel that fails to do this.

The end result is that it causes sh (instead of the specified
interpreter) to interpret the script.

I think that code should be removed altogether.

Cheers,
Stéphane





More information about the Pkg-shadow-devel mailing list