Hi all,

I know this mailing list is about qmail, but I have some doubts about perl pogram
as checkpassword.
I use this perl program "checkpassword", because I use Postgres Database to
authenticate my users.
There are somethings into this perl program that I am not able to figure out.
First:
I start POP3 through inetd using the following line into the inted.conf file:

pop3 stream tcp nowait root /var/qmail/bin/qmail-popup qmail-popup mydomain.com
/bin/checkpassword  /var/qmail/bin/qmail-pop3d Maildir

I know that qmail-popup is a responsible program to get username and password from the
network and after  it gets it  runs a sub-program (checkpassword) to check username
and password and set the environment variables.
I have three questions about it:
How does qmail-popup get the username and password from the network?
How does qmail-popup send to sub-program (checkpassword) the
informations about username and password?
More specifically what is the format of the data sent to this sub-program (checkpassword)?

I have the checkpassword program done, but I would like you to help me about understanding
what the program does. If someone could help about my checkpassword program I would thank.

This is my checkpassword program:

The most important line that I'd like to figure out is about how it gets from the qmail-popup the
informations about username and password, how it gets to split this information and what means
the lines started with $ENV.
If it gets from the standart input, where is it? In the expression "<&=3"?
If the lines $ENV are to set up the environment variables why must it do this?
What Do the procedures in bold do?
About the connection with database I don't have any problem.

#!/usr/bin/perl
#
use Pg;
my $TABLE = 'emails';

$conn = PQsetdb('','','','','ab');

%ENV = () ;

my( $len, $buf, ) ;
open( USER, "<&=3" )
  or exit( -3 ) ;
$len = read( USER, $buf, 512 ) ;
close USER ;
exit(-3) if $len < 4 ;

# extract null-terminated user/pass pair from buf
my( $user, $pass ) = split /\x00/, $buf ;
$user = lc $user ;
$buf = "\x00" x $len ;

# Verifying the username and password

$domain = 'ab.com.br';

$result = PQexec($conn,"SELECT * from $TABLE where email= '$user' AND password = '$pass';");

if (PQntuples($result) > 0) {

if (-e "/home/$domain/$user") {
 

}
else
{

 system("mkdir /home/$domain/\"$user\"");
 system ("/var/qmail/bin/maildirmake /home/$domain/\"$user\"/Maildir");
 system (" echo ./Maildir/ > /home/$domain/\"$user\"/.qmail");
 system (" touch /home/$domain/$user/.timestamp");
 system("/usr/sbin/chown -R alias.qnofiles /home/$domain/\"$user\"");
 system("/usr/sbin/chown -R alias.qnofiles /home/$domain/\"$user\"/*");
 system (" touch /home/$domain/$user/.timestamp");

}
}

$ENV{'USER'}  = $user;
$ENV{'UID'}   = "alias"; #$ary[0][3];
$ENV{'GID'}   = "qnofiles"; #$ary[0][4];
$ENV{'HOME'}  = "/home/$domain/$ENV{'USER'}";
$ENV{'SHELL'} = "/bin/date";

  exit(-4) unless $ENV{UID} ;
  $ENV{HOME} =~ m!((?:/\w[-_.\w]+)+)! ;
  $ENV{HOME} = $1 ;
  chdir $ENV{HOME} ;
  $> = $ENV{UID} ;
  $) = $ENV{GID} ;
  exec @ARGV;
  exit(0);
  exit( -4 );
 
 

Thanks in advance!
Cleiton

Reply via email to