home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / shell / 3484 < prev    next >
Encoding:
Internet Message Format  |  1992-08-13  |  1.6 KB

  1. Path: sparky!uunet!sun-barr!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!usc!news!lsi!mhost!up41!aspin
  2. From: aspin@up41 (David Aspinwall 7842)
  3. Newsgroups: comp.unix.shell
  4. Subject: Re: Password protection for terminal via shell.
  5. Message-ID: <1992Aug13.230023.14825@lsil.com>
  6. Date: 13 Aug 92 23:00:23 GMT
  7. References: <4734@daily-planet.concordia.ca>
  8. Sender: news@lsil.com (news caster)
  9. Organization: LSI Logic Corporation
  10. Lines: 47
  11. Nntp-Posting-Host: up41
  12. X-Newsreader: Tin 1.1 PL5
  13.  
  14.  
  15. If you don't want to embed the password in the script,
  16. and you can use perl, try doing something like this:
  17.  
  18.  
  19. #!/usr/bin/perl
  20. # lock terminal until user enters their password (or the root password)
  21.  
  22. &ignore();
  23. system("stty -echo susp ^-");
  24. while (!&check_passwd(1)) {
  25.     print "\nbetter luck next time\n";
  26. }
  27. system("reset");
  28.  
  29.  
  30.  
  31. # ignore some signals
  32. sub ignore {
  33.     $SIG{'INT'} = 'IGNORE';
  34.     $SIG{'QUIT'} = 'IGNORE';
  35.     $SIG{'HUP'} = 'IGNORE';
  36.     $SIG{'TERM'} = 'IGNORE';
  37. }
  38.  
  39.  
  40.  
  41. # check_passwd : prompts user to enter a password, and checks it
  42. #   if a non-zero is passed in, check vs the root password as well
  43. #   use the first 2 chars of the encrypted password as salt for crypt
  44. sub check_passwd {
  45.     local ($allowroot) = @_;
  46.  
  47.     print "enter password: ";
  48.     chop ($passwd = <>);
  49.  
  50.     ($name,$cryptpasswd) = getpwuid($<);
  51.     return 1 if (crypt($passwd, substr($cryptpasswd, 0, 2)) eq $cryptpasswd);
  52.  
  53.     if ($allowroot) {
  54.     ($name,$cryptpasswd) = getpwuid(0);
  55.     return 1 if (crypt($passwd, substr($cryptpasswd, 0, 2)) eq $cryptpasswd);
  56.     }
  57.     return 0;
  58. }
  59.  
  60.         -- David Aspinwall    aspin@lsil.com    408-433-7842
  61.