[comp.lang.perl] Perlscript as login-shell

perf@efd.lth.se (Per Foreby) (02/13/91)

I have written a small perl script which some users get as their login
shell. The general idea is to make the workstation personal, but allow
the owner to `su' to another user. The password file contains entries
like `+user:' for authorized users and `+:::::/perl-script' which
matces all other users.

My approch (in pseudo-perl):

if (getlogin () == $ENV{'USER'})
    print ("sorry...");
else
   exec (login-shell-from-yellow-pages);

The problem: I can't find any way to distinguish between `su user' and
`su - user'. In c this is simple (*argv[0] == '-'), but perls $0 only
gives me the name of the script.

I fear the problem is without solution, but please surprise me!

 
--

--
Per Foreby; perf@efd.lth.se; LTH-E, Box 118, S-221 00 LUND, Sweden; 046-107492

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (02/13/91)

In article <PERF.91Feb13001253@osiris.efd.lth.se> perf@efd.lth.se (Per Foreby) writes:
: The problem: I can't find any way to distinguish between `su user' and
: `su - user'. In c this is simple (*argv[0] == '-'), but perls $0 only
: gives me the name of the script.
: 
: I fear the problem is without solution, but please surprise me!

In 4.0, you can get at this with $^P, the name Perl was invoked by.
There's also $^D to access debug flags, and $^I to access the -i flag,
and I may add $^W to access the -w flag.

Maybe I should add a flag that makes the tokener accept metacharacters
in place of keywords...   :-)  :-)  :-)

Larry

allbery@NCoast.ORG (Brandon S. Allbery KB8JRR) (02/18/91)

As quoted from <11418@jpl-devvax.JPL.NASA.GOV> by lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall):
+---------------
| In 4.0, you can get at this with $^P, the name Perl was invoked by.
| There's also $^D to access debug flags, and $^I to access the -i flag,
| and I may add $^W to access the -w flag.
| 
| Maybe I should add a flag that makes the tokener accept metacharacters
| in place of keywords...   :-)  :-)  :-)
+---------------

I've been thinking about the $^x business, Larry.  How about changing the
special variables to be normally-named variables in package Perl?  That way,
the debug flags, for example, might be $Perl'debug_flags instead of $^D.
It's more readable --- and, much more importantly, you won't run out of
variables.

++Brandon
-- 
Me: Brandon S. Allbery			    VHF/UHF: KB8JRR on 220, 2m, 440
Internet: allbery@NCoast.ORG		    Packet: KB8JRR @ WA8BXN
America OnLine: KB8JRR			    AMPR: KB8JRR.AmPR.ORG [44.70.4.88]
uunet!usenet.ins.cwru.edu!ncoast!allbery    Delphi: ALLBERY

composer@chem.bu.edu (Jeff Kellem) (02/18/91)

In article <1991Feb17.171303.20400@NCoast.ORG> allbery@NCoast.ORG (Brandon S. Allbery KB8JRR) writes:
 > I've been thinking about the $^x business, Larry.  How about changing the
 > special variables to be normally-named variables in package Perl?  That way,
 > the debug flags, for example, might be $Perl'debug_flags instead of $^D.
 > It's more readable --- and, much more importantly, you won't run out of
 > variables.

But, for those that are lazy, it's easier to type $^x.  ;-}

			-jeff

Jeff Kellem
Internet: composer@chem.bu.edu

rbj@uunet.UU.NET (Root Boy Jim) (02/19/91)

allbery@ncoast.ORG (Brandon S. Allbery KB8JRR) writes:
>It's more readable --

What are you, some kinda reactionary?
-- 
		[rbj@uunet 1] stty sane
		unknown mode: sane

tneff@bfmny0.BFM.COM (Tom Neff) (02/21/91)

In article <1991Feb17.171303.20400@NCoast.ORG> allbery@ncoast.ORG (Brandon S. Allbery KB8JRR) writes:
>I've been thinking about the $^x business, Larry.  How about changing the
>special variables to be normally-named variables in package Perl?  That way,
>the debug flags, for example, might be $Perl'debug_flags instead of $^D.
>It's more readable --- and, much more importantly, you won't run out of
>variables.

Naturally, losing the short names would break most existing scripts, BUT
I still like the idea of having verbose, descriptive names!  They could
essentially be aliases for the short forms: $. <-> $Perl'line_num and so
forth.  New, weird variables might be introduced only in the new form
rather than try and scrape up another one character symbol.

allbery@NCoast.ORG (Brandon S. Allbery KB8JRR) (02/23/91)

As quoted from <123269@uunet.UU.NET> by rbj@uunet.UU.NET (Root Boy Jim):
+---------------
| allbery@ncoast.ORG (Brandon S. Allbery KB8JRR) writes:
| >It's more readable --
| 
| What are you, some kinda reactionary?
+---------------

No, I've been getting (and taking) a lot of grief at work about someone no
longer with the company whose coding style was dense, unreadable, and
uncommented.  (It looked a lot like a verbose APL, if you can imagine such a
beast.)

++Brandon
-- 
Me: Brandon S. Allbery			    VHF/UHF: KB8JRR on 220, 2m, 440
Internet: allbery@NCoast.ORG		    Packet: KB8JRR @ WA8BXN
America OnLine: KB8JRR			    AMPR: KB8JRR.AmPR.ORG [44.70.4.88]
uunet!usenet.ins.cwru.edu!ncoast!allbery    Delphi: ALLBERY