diff options
Diffstat (limited to 'roles/IMAP/files/usr/local/bin/dovecot-auth-proxy.pl')
-rwxr-xr-x | roles/IMAP/files/usr/local/bin/dovecot-auth-proxy.pl | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/roles/IMAP/files/usr/local/bin/dovecot-auth-proxy.pl b/roles/IMAP/files/usr/local/bin/dovecot-auth-proxy.pl index 399e65f..5b2c74e 100755 --- a/roles/IMAP/files/usr/local/bin/dovecot-auth-proxy.pl +++ b/roles/IMAP/files/usr/local/bin/dovecot-auth-proxy.pl @@ -57,73 +57,75 @@ server(); waitpid $_ => 0 foreach @CHILDREN; exit $?; ############################################################################# sub server() { for (my $n = 0; $n < 1; $n++) { accept(my $conn, $S) or do { next if $! == EINTR; die "accept: $!"; }; my $hello = $conn->getline() // ''; unless ($hello =~ /\AH(\d+)\t(\d+)\t(\d+)(?:\t.*)?\n\z/) { warn "Invalid greeting line: $hello\n"; close $conn or warn "Can't close: $!"; next; } # <major-version> <minor-version> <value type> - unless ($1 == 2 and $2 == 0 and $3 == 0) { + unless ($1 == 2 and $2 == 1 and $3 == 0) { warn "Unsupported protocol version $1.$2 (or value type $3)\n"; close $conn or warn "Can't close: $!"; next; } my $cmd = $conn->getline() // ''; - if ($cmd =~ /\AI(\d+)\t(.*)\n\z/) { - iterate($conn, $1, $2); + if ($cmd =~ /\AI(\d+)\t(\d+)\t(.*)\n\z/) { + iterate($conn, $1, $2, $3); } else { fail($conn => "Unknown command line: $cmd"); } close $conn or warn "Can't close: $!"; } } sub fail($;$) { my ($fh, $msg) = @_; $fh->printflush("F\n"); warn "$msg\n" if defined $msg; } # list all users, even the inactive ones -sub iterate($$$) { - my ($fh, $flags, $prefix) = @_; +sub iterate($$$$) { + my ($fh, $flags, $max_rows, $prefix) = @_; unless ($flags == 0) { fail($fh => "Unsupported iterate flags $flags"); return; } opendir my $dh, '.' or do { fail($fh => "opendir: $!"); return; }; + my $count = 0; while (defined (my $d = readdir $dh)) { next if $d eq '.' or $d eq '..'; opendir my $dh, $d or do { fail($fh => "opendir: $!"); return; }; - while (defined (my $l = readdir $dh)) { + while (defined (my $l = readdir $dh) and ($max_rows <= 0 or $count < $max_rows)) { next if $l eq '.' or $l eq '..'; my $user = $l.'@'.$d; next unless $user =~ /\A[a-zA-Z0-9\.\-_@]+\z/; # skip invalid user names $fh->printf("O%s%s\t\n", $prefix, $user); + $count++; } closedir $dh or warn "closedir: $!"; } closedir $dh or warn "closedir: $!"; $fh->printflush("\n"); } |