Technical article 105590

With ksh login, the second invocation of su in shell script causes core dump.

OpenServer 5.0.2

Written · Last revised

Problem

The second invocation of su from an executable shell script causes
core dump.  This occurs when the user who executes the script has
the login shell as ksh.  Here is an example that demonstrates
the problem:

An executable shell script file called "sutest", that contains the following two lines, is created:

su - root -c "ls"
su - root -c "ls"

Note that in this example the user being su'd to is "root", but it could just as well be a regular user. Also note that the actual command, "ls", was arbitrarily used for this example.

If the sutest script is executed, one of the following may occur after execution of the first su:

1. The following is displayed on execution of the second su:

Password:
Last   successful real login for ....
Last unsuccessful real login for ....
sutest[2]: <pid> Memory fault(coredump)

2. The process simply hangs after completion of the first su.

The problem seems to occur if both the user being su'd to and
the user executing the sutest script both have their login shell
set to /bin/ksh.  If either the user being su'd to or the user
executing the shell script have their login shell as /bin/sh,
execution of the script works fine.

Solution

This problem has been reported to SCO Engineering and is scheduled
to be addressed in an upcoming release.  In the meantime, here are
some suggested workarounds:
1. Specify only one invocation of su in the shell script.  For
example:
su root -c "cmd1; cmd2"

2. Using scoadmin(ADM), change either your login shell or the login shell of the user su'ing to, from ksh to sh.

3. Before invocation of the shell script, type:  exec sh

4. If feasible, do not include the "-" option to the su command. For example, instead of the prior script, do something like this instead:

su root -c "ls"
su root -c "ls"

If you do need the user's environment in the command, you can implement this by creating a secondary shell script (named "sutest2" for this example) similar to this:

. /usr/$LOGIN/.profile
. /usr/$LOGIN/.kshrc
eval $*

(where <LOGIN> is the login you are su'ing to)

and invoke as:
su root -c "LOGIN=root sutest2 ls"
su root -c "LOGIN=root sutest2 ls"

The following did *NOT* serve as effective workarounds:

1. Before invocation of the shell script, typing:  /bin/sh

2. Setting/unsetting SHELL to either sh or ksh, and specifying "#!/bin/xx" (where xx is either sh or ksh) on the first line of the script.

Note:  The su(C) man page states that "The following statements
[pert. to using the "-" option] are true only if the optional
program named in the shell field of the specified user's password
file entry is like 'sh'".

See also

Manual pages: su(C), ksh(C), sh(C)

From the Xinuos technical article database, record 105590. Reproduced with permission. The original is at www.sco.com/ta/105590, which is reachable but blocked from search engines. Xinuos marks this article against a retired product line. That refers to the product’s lifecycle, not to whether the advice still works — plenty of it still applies to running systems.

Next step

Need this fixed rather than explained?

Tell us the release, what the system runs and what it is doing. We will reply by email with what we would do next.

  • You deal with the people who do the work
  • No obligation, and no upgrade required before we will help
  • We tell you plainly if something is not worth doing

Send an enquiry

We reply by email. If a server is down, say so in the first line. You can also write to help@scoexpert.com.