home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!sun-barr!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!news!lsi!mhost!up41!aspin
- From: aspin@up41 (David Aspinwall 7842)
- Newsgroups: comp.unix.shell
- Subject: Re: Password protection for terminal via shell.
- Message-ID: <1992Aug13.230023.14825@lsil.com>
- Date: 13 Aug 92 23:00:23 GMT
- References: <4734@daily-planet.concordia.ca>
- Sender: news@lsil.com (news caster)
- Organization: LSI Logic Corporation
- Lines: 47
- Nntp-Posting-Host: up41
- X-Newsreader: Tin 1.1 PL5
-
-
- If you don't want to embed the password in the script,
- and you can use perl, try doing something like this:
-
-
- #!/usr/bin/perl
- # lock terminal until user enters their password (or the root password)
-
- &ignore();
- system("stty -echo susp ^-");
- while (!&check_passwd(1)) {
- print "\nbetter luck next time\n";
- }
- system("reset");
-
-
-
- # ignore some signals
- sub ignore {
- $SIG{'INT'} = 'IGNORE';
- $SIG{'QUIT'} = 'IGNORE';
- $SIG{'HUP'} = 'IGNORE';
- $SIG{'TERM'} = 'IGNORE';
- }
-
-
-
- # check_passwd : prompts user to enter a password, and checks it
- # if a non-zero is passed in, check vs the root password as well
- # use the first 2 chars of the encrypted password as salt for crypt
- sub check_passwd {
- local ($allowroot) = @_;
-
- print "enter password: ";
- chop ($passwd = <>);
-
- ($name,$cryptpasswd) = getpwuid($<);
- return 1 if (crypt($passwd, substr($cryptpasswd, 0, 2)) eq $cryptpasswd);
-
- if ($allowroot) {
- ($name,$cryptpasswd) = getpwuid(0);
- return 1 if (crypt($passwd, substr($cryptpasswd, 0, 2)) eq $cryptpasswd);
- }
- return 0;
- }
-
- -- David Aspinwall aspin@lsil.com 408-433-7842
-