Buongiorno A tutti!![]()
Sono un neofita completo con il PERL è perciò vi chiedo una mano per risolvere un problemino:
Utilizzo questo script (authpam.pl ver. 1.0 che molti sicuremente conosceranno) per autenticare gli utenti di un mail server su linux:
use Authen::PAM;
$| = 1; #force STDOUT autoflush after each write
my ($seq,$vrfy,$mode,$user,$passw);
sub pam_conv_func {
my @res;
while ( @_ ) {
my $msg_type = shift;
my $msg = shift;
#print $msg;
push @res, 0;
push @res, $passw;
}
push @res, PAM_SUCCESS;
return @res;
}
while(<STDIN>) {
($seq,$vrfy,$mode,$user,$passw) = split(/ /);
unless($mode =~ /^\(.*\)$/) {
$passw=$user; $user=$mode;
}
unless($seq && $vrfy && $user && $passw) {
print "$seq ERROR Wrong arguments\n";
} elsif($vrfy ne 'VRFY') {
print "$seq ERROR Only clear text passwords supported\n";
} else {
my ($res,$pamh);
chomp($passw);
if($user =~/(.+)\@.+/) {$user=$1;}
if(($res=pam_start("login", $user, \&pam_conv_func, $pamh))!=PAM_SUCCESS ||
($res=pam_authenticate($pamh, 0))!=PAM_SUCCESS ||
($res=pam_end($pamh, 0))!=PAM_SUCCESS) {
print "$seq ERROR ".pam_strerror($pamh,$res)."\n";
} else {
print "$seq OK \n";
}
}
}
Funziona tutto benissimo, ma...la riga: if($user =~/(.+)\@.+/) {$user=$1;} fa si che se l'utente da autenticare è 'mionome@miodominio.it' lo script passa al PAM 'mionome'. Mi piacerebbe riuscire ad autenticare utenti di diversi domini, in pratica vorrei che lo script lavorasse così: se l'utente è mioutente@miodominio1.it al PAM venga passato ad esempio MIODOMINIO1.LOCAL\\mioutente e se invece lutente è mioutente@miodominio2.com al venga passato ad esempio MIODOM2.PRIV\\mioutente ecc.
Che modifiche posso fare per ottenere questo risultato?
Grazie a tutti.