From 278b76fabf31abe8fc4fbe6ca1c0ad6af830fcb7 Mon Sep 17 00:00:00 2001 From: "Jannis M. Hoffmann" Date: Sun, 10 Sep 2023 15:39:25 +0200 Subject: added test pam to replace MockMaildir ReadMail implementation --- lib/JWebmail/Model/ReadMails/QMailAuthuser.pm | 23 ++++++++++------------- 1 file changed, 10 insertions(+), 13 deletions(-) (limited to 'lib/JWebmail/Model/ReadMails/QMailAuthuser.pm') diff --git a/lib/JWebmail/Model/ReadMails/QMailAuthuser.pm b/lib/JWebmail/Model/ReadMails/QMailAuthuser.pm index b2015aa..5190e26 100644 --- a/lib/JWebmail/Model/ReadMails/QMailAuthuser.pm +++ b/lib/JWebmail/Model/ReadMails/QMailAuthuser.pm @@ -4,6 +4,8 @@ use v5.24; use warnings; use utf8; +use JWebmail::Config 'MAILDIR_EXTRACTOR'; + use IPC::Open2; use JSON::PP 'decode_json'; use Params::Check 'check'; @@ -11,7 +13,6 @@ use Role::Tiny::With; use Scalar::Util 'blessed'; use namespace::clean; -use JWebmail::Config 'MAILDIR_EXTRACTOR'; with 'JWebmail::Model::ReadMails::Role'; @@ -74,9 +75,9 @@ package JWebmail::Model::ReadMails::QMailAuthuser::Error { my $QMailAuthuserCheck = { - virtual_user => {required => 1}, - mailbox_path => {required => 1}, - qmail_dir => {default => '/var/qmail/'}, + virtual_user => {required => 1}, + mailbox_path => {required => 1}, + authenticator => {required => 1}, }; sub new { @@ -174,12 +175,12 @@ sub build_arg { my $self = shift; my ($user_mail_addr, $mode, $args) = @_; - return $self->{qmail_dir} . "/bin/qmail-authuser true 3<&0" + return $self->{authenticator} . ' true 3<&0' if $mode eq 'auth'; my ($user_name) = $user_mail_addr =~ /(\w*)@/; - return $self->{qmail_dir}.'/bin/qmail-authuser ' + return $self->{authenticator} . ' ' . join(' ', map { my $x = s/(['\\])/\\$1/gr; "'$x'" } ($self->{prog}, $self->{mailbox_path}, $self->{virtual_user}, $user_name, $mode, @$args)) . ' 3<&0'; } @@ -210,11 +211,6 @@ sub read_qmauth { my $rs; if (eof $reader) { - # for regular open - close $reader - or warn "closing read pipe failed: $!"; - $rs = $?; - # for IPC::Open2 if (waitpid($pid, 0) == $pid) { $rs = $?; @@ -244,18 +240,19 @@ sub read_qmauth { }; } elsif ($rs == 3 << 8 || $rs == 0) { + $rc = $rs >> 8; eval { $resp = decode_json $input if $input; 1 } or do { $resp = { info => "error decoding response", response => $input, cause => $@, - return_code => $rs >> 8, + return_code => $rc, }; - $rc = 3; }; } else { + $rc = $rs >> 8; $resp = { info => "got unsuccessful return code by qmail-authuser", return_code => $rc, -- cgit v1.2.3