Subject: Re: only one program per login References: <fd1496bf.0405251239.1c21d7db@posting.google.com>
<20040526021350.GA23909@jpradley.jpr.com>
<40b40112@dnews.tpgi.com.au>
<kOSdnclUFqRrrSndRVn-iQ@comcast.com> From: spcecdt@deeptht.armory.com (John DuBois) Date: 26 May 2004 22:44:31 GMT Message-ID: <40b51dcf$0$430$8eec23a@newsreader.tycho.net> In article <kOSdnclUFqRrrSndRVn-iQ@comcast.com>, Brian K. White <brian@aljex.com> wrote: >>>>> #!/bin/sh >>>>> . /etc/profile >>>>> run myprogram >>>> >>>> wouldn't it also be advisable to 'exec myprogram' at the end of the >>>> script, instead of just running it? >I don't think it's exactly a stupid idea. > >If you had many users logging in at once, and if they each had several >concurrent sessions, then this could be a significantly adviseable step >because it requires one less slot in the process stack (and maybe 3 file >descriptors to go with it?) for each login. > >I have verified this by testing.
Yes, there should probably be an 'exec' there.
Side note: ksh93 is smart enough to not fork-before-exec for a simple command
on the very last line of a script, as long as you haven't asked it to do
anything that requires continued monitoring.
>It also makes the user slightly less likely to be able to break out of the
>script to the shell.
>They can't stuff the keyboard buffer while still in the binary and cause a
>break in that microsecond between binary exit and the next line in the
>script. Sure you should be able to secure that with trap and stty but this
>is even more sure.
Using the scheme I described (setting the user's login shell to be the script),
there is nothing that the user can do to wrest control over the shell. The
shell isn't reading its standard input for commands, it's reading the shell
program. It is exactly as secure (in this sense) as a compiled program.
"Breaking out at just the right moment" is only a concern if you are using the
scheme in which the user's login shell is the shell binary, and you try to keep
control within the user's .profile. There, the shell is prepared to switch its
input from the .profile to the user's tty as soon as it is finished sourcing
the .profile (which can indeed be skipped by sending an interrupt character at
just the right moment).
John
--
John DuBois spcecdt@armory.com KC6QKZ/AE http://www.armory.com/~spcecdt/
Have you tried Searching this site?
Unix/Linux/Mac OS X support by phone, email or on-site: Support Rates
This is a Unix/Linux resource website. It contains technical articles about Unix, Linux and general computing related subjects, opinion, news, help files, how-to's, tutorials and more. We appreciate comments and article submissions.
Many of the products and books I review are things I purchased for my own use. Some were given to me specifically for the purpose of reviewing them. I resell or can earn commissions from the sale of some of these items. Links within these pages may be affiliate links that pay me for referring you to them. That's mostly insignificant amounts of money; whenever it is not I have made my relationship plain. I also may own stock in companies mentioned here. If you have any question, please do feel free to contact me.
Specific links that take you to pages that allow you to purchase the item I reviewed are very likely to pay me a commission. Many of the books I review were given to me by the publishers specifically for the purpose of writing a review. These gifts and referral fees do not affect my opinions; I often give bad reviews anyway.
We use Google third-party advertising companies to serve ads when you visit our website. These companies may use information (not including your name, address, email address, or telephone number) about your visits to this and other websites in order to provide advertisements about goods and services of interest to you. If you would like more information about this practice and to know your choices about not having this information used by these companies, click here.
Click here to add your comments
Don't miss responses! Subscribe to Comments by RSS or by Email
Click here to add your comments
If you want a picture to show with your comment, go get a Gravatar