home *** CD-ROM | disk | FTP | other *** search
/ ftp.qualcomm.com / 2014.06.ftp.qualcomm.com.tar / ftp.qualcomm.com / eudora / servers / unix / password / pwserve-2 < prev    next >
Text File  |  1997-03-26  |  7KB  |  212 lines

  1. To: sdorner@qualcomm.com
  2. Subject: Password daemon for MH/Eudora
  3. Organisation: BNR Europe, HARLOW, Essex CM17 9NA, GB
  4. Phone: +44 279 402423
  5. From: Andrew Macpherson (Postmaster) <A.Macpherson@bnr.co.uk>
  6.  
  7.  
  8. Steve,
  9.  
  10. Thanks for helping John Bingham out so much.  Since you've added a password
  11. changer, here is a daemon for those sites which use MH bpop (ie pop support
  12. for non unix users from a unix host).  If it doesn't work the way you want
  13. I'll happily make changes.
  14.  
  15. #!/usr/bin/perl
  16. #
  17. # Author Andrew Macpherson
  18. #       <A.Macpherson@bnr.co.uk>
  19. #       /DD.ID=1248566/G=Andrew/S=Macpherson/PRMD=BNR/ADMD= /C=GB/
  20. #        to support the eudora password change protocol
  21. #
  22. # Entry for /etc/services:
  23. #       epass      106/tcp 
  24. # And for /etc/inetd.conf:
  25. #       epass      stream  tcp     nowait  pop  /path/to/in.poppass
  26. #
  27. # $Header: /tmp_mnt/u/andrew/andrew/src/poppass/RCS/in.poppass,v 1.4 14/11/92 16:29:12 andrew Exp $
  28. #
  29. # $Log: in.poppass,v $
  30. # Revision 1.4  14/11/92  16:29:12  andrew
  31. # Inetd looping with wait, admin features not so usefull
  32. # Revision 1.3  14/11/92  15:32:42  andrew
  33. # Add admin password reset capability
  34. # Revision 1.2  14/11/92  15:05:21  andrew
  35. # Off by 1 report of existing accounts.
  36. # Make use of the locking given by only allowing 1 daemon to
  37. # add users without losing password changes.
  38. # Revision 1.1  14/11/92  14:10:23  andrew
  39. # Initial revision
  40.  
  41. $| = 1;
  42. $Id = '$Id: in.poppass,v 1.4 14/11/92 16:29:12 andrew Exp $';
  43. $perl = '/usr/bin/perl' ;       # Used in system() later
  44.  
  45. $MyName="POPpass" ;
  46. require "syslog.pl";
  47. &openlog($MyName,"pid,cons,nowait", "auth");
  48.  
  49. $\ = "\r\n" ; # Set output seperator for chitchat over tcp
  50. chop( $host=`hostname` );
  51.  
  52. ( $me, $pop_pass, $b, $c, $d, $e, $f, $dir, $g ) = getpwnam("pop") ;
  53.  
  54. if ( ! $dir || ! -w $dir . '/POP' || ! chdir($dir) ) {
  55.     print "420 Configuration error, please tell postmaster@$host" ;
  56.     &syslog("notice", "Cannot access ${dir}/POP");
  57.     &closelog();
  58.     die;
  59. }
  60.  
  61. print "200 hello $host POP password service" ;
  62.  
  63. $user = '';
  64. $curcrypt = '' ;
  65. $newcrypt = '' ;
  66.  
  67. while(<>) {
  68.     chop;
  69.   ( $action, $arg, $extra ) = split(/\s+/, $_);
  70.     if ( $action =~ m/^user$/i ) {
  71.         $user = $arg ;
  72.         $curcrypt = '' ;
  73.         print "300 Hello $arg, please prove it with your password" ;
  74.     } elsif ( $action =~ m/^pass$/i ) {
  75.         $curcrypt = '' ;
  76.         if ( $user eq '' ) {
  77.             print "400 I need to know who you claim to be first" ;
  78.             next ;
  79.         }
  80.         &ValidUser($user, $arg) ; # Sets $curcrypt if true
  81.         if ($curcrypt eq '') {
  82.             &syslog('notice', "invalid POP password offered for $user");
  83.             sleep(20);  # Slow him down
  84.             print "500 Imposter! I have issued a security alert" ;
  85.             last;
  86.         }
  87.         if ( $user eq 'pop' ) {
  88.             print "200 Hail Oh great and glorious leader" ;
  89.         } else {
  90.             print "200 Ok, Now I believe you are $user" ;
  91.         }
  92.         &syslog('info', "POP user $user validated");
  93.     } elsif ( $action =~ m/^newpass$/i ) {
  94.         if ( $user eq '' ) {
  95.             print "400 Who are you? Logon with USER and PASS first" ;
  96.             next ;
  97.         }
  98.         if ( $curcrypt eq '' ) {
  99.             print "401 Until you give me your old password," .
  100.                      " I have to believe you are an Imposter";
  101.             next ;
  102.         }
  103.         if (crypt($arg, $curcrypt) eq $curcrypt) {
  104.             print "402 No it isn't, it's the same" ;
  105.             next;
  106.         }
  107.         $newcrypt = crypt($arg, substr($curcrypt,1,2));
  108.         $ok = system("$perl -pi.bak " .
  109.                "-e 's:$curcrypt:$newcrypt: if m/^$user:/ ;' POP" ) ;
  110.         if ( $ok / 256 ) {
  111.             print "500 Sorry, update failed" ;
  112.         } else {
  113.             print "200 OK";
  114.             $curcrypt = $newcrypt ;
  115.         }
  116.     } elsif ( $action =~ m/^quit$/i ) {
  117.         print "200 $host, Glad to help" ;
  118.         last ;
  119.     } elsif ( $action =~ m/^status$/i ) {
  120.         print "200 " . ($user eq '' ? "no user" : "user $user") .
  121.                  ($curcrypt eq '' ? ' not' : '') . ' authenticated' ;
  122.     } elsif ( $action =~ m/^version$/i ) {
  123.         print "200 $MyName $Id" ;
  124.     } elsif ( $action =~ m/^help$/i ) {
  125.         print "200 Supported actions:" .
  126.                  " USER PASS NEWPASS HELP QUIT STATUS VERSION" .
  127.                  (( $user eq 'pop' && $curcrypt ne '')
  128.                  ? " NEWUSER SETPASS" : "");
  129.     } elsif ( $user eq 'pop' && $curcrypt ne '' && $action =~ m/^newuser$/i ) {
  130.         if ( $arg ne '' && $extra ne '' ) {
  131.             &NewUser($arg, $extra) ;
  132.         } else {
  133.             print "400 Newuser user pass" ;
  134.         }
  135.     } elsif ( $user eq 'pop' && $curcrypt ne ''
  136.                     && $action =~ m/^setpass$/i
  137.                     && $arg ne '' && $extra ne '' ) {
  138.         $newcrypt = crypt($extra, substr($curcrypt,1,2));
  139.         $ok = system("$perl -pi.bak " .
  140.                "-e 's|$arg::$arg.*|$arg::$arg:$newcrypt::::::0| ;' POP" ) ;
  141.         if ( $ok / 256 ) {
  142.             print "500 Sorry, update failed" ;
  143.         } else {
  144.             print "200 OK";
  145.             $curcrypt = $newcrypt ;
  146.         }
  147.     } else {
  148.         print "400 I don't understand '$action' try help" ;
  149.     }
  150. }
  151. &closelog();
  152. exit 0;
  153.  
  154. sub ValidUser {
  155.     local($user, $pass) = @_ ;
  156.  
  157.     if ( $user eq 'pop' ) {
  158.         $curcrypt = $pop_pass if (crypt($pass, $pop_pass) eq $pop_pass);
  159.         return ;
  160.     }
  161.     $curcrypt = '';             # Just in case
  162.     open(POP, '<' . "POP") ;
  163.     @entry = grep(/^$user:/, <POP>);
  164.     close POP;
  165.     if ($#entry == -1) {
  166.         &syslog('notice', "POP user $user does not exist");
  167.         return;
  168.     }
  169.     if ($#entry != 0) {
  170.         $accts = $#entry + 1;
  171.         print "520 there are $accts POP accounts for $user" ;
  172.         &syslog('notice', "POP user $user has $accts accounts");
  173.         &closelog();
  174.         exit 1;
  175.     }
  176.     $entry = shift(@entry);
  177.   ( $a, $b, $c, $ppass, @rest) = split(/:/, $entry) ;
  178.     $curcrypt = $ppass if (crypt($pass, $ppass) eq $ppass);
  179. }
  180.  
  181. sub NewUser {
  182.     local($user, $pass) = @_ ;
  183.  
  184.     open(POP, '<' . "POP") ;
  185.     @entry = grep(/^$user:/, <POP>);
  186.     close POP;
  187.     if ($#entry != -1) {
  188.         &syslog('notice', "POP user $user already exists");
  189.         print "500 $user exists" ;
  190.         return ;
  191.     }
  192.     open(POP, '>>' . 'POP') ;
  193.     printf POP "$user::$user:" . crypt($pass, '//') . "::::::0\n" ;
  194.     close POP ;
  195.     print "200 $user added" ;
  196. }
  197. __END__
  198. This program was written to support Steve Dorner's Eudora program password
  199. changing routine for systems using the MH/pop.
  200.  
  201. It is released for general use.
  202.  
  203. Andrew Macpherson reserves and asserts the right to be known as the
  204. author of this work.
  205.  
  206.  
  207.