Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WWSympa: New "cgi" authentication simply using credentials provided by HTTP server #1499

Merged
merged 1 commit into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions src/cgi/wwsympa.fcgi.in
Original file line number Diff line number Diff line change
Expand Up @@ -1317,6 +1317,10 @@ while ($query = Sympa::WWW::FastCGI->new) {
$param->{'ssl_cipher_usekeysize'} =
$ENV{SSL_CIPHER_USEKEYSIZE};
}
} elsif (my $email = _cgi_get_authenticated_user()) {
$param->{'user'}{'email'} = $email unless $email eq 'nobody';
$session->{'email'} = $email;
$session->{'auth'} = 'cgi';
} elsif (($session->{'email'}) && ($session->{'email'} ne 'nobody')) {
$param->{'user'}{'email'} = $session->{'email'};
} elsif ($in{'ticket'} =~ /(S|P)T\-/) {
Expand Down Expand Up @@ -3073,6 +3077,30 @@ sub do_ticket {

}

sub _cgi_get_authenticated_user {
foreach my $auth (grep { $_->{auth_type} eq 'cgi' }
@{$Conf::Conf{'auth_services'}{$robot} || []}) {
if (length($auth->{auth_scheme} // '')) {
next unless lc $auth->{auth_scheme} eq lc($ENV{AUTH_TYPE} // '');
}

my $email = $ENV{$auth->{remote_user_variable}};
next unless Sympa::Tools::Text::valid_email($email);
next unless $email =~ m{$auth->{regexp}}i;
if (length($auth->{negative_regexp} // '')) {
next if $email =~ m{$auth->{negative_regexp}}i;
}

return Sympa::Tools::Text::canonic_email($email);
}

# As soon as cgi authentication is deactivated, the user should logout.
return 'nobody' if $session->{'auth'} eq 'cgi';

# Otherwise no cgi mechanisms available.
return undef;
}

# Login WWSympa
sub do_login {
wwslog('info', '(%s)', $in{'email'});
Expand Down
12 changes: 11 additions & 1 deletion src/lib/Conf.pm
Original file line number Diff line number Diff line change
Expand Up @@ -843,6 +843,13 @@ sub _load_auth {
my $current_paragraph;

my %valid_keywords = (
'cgi' => {
'auth_scheme' => '.*',
'remote_user_variable' => '.+',
'regexp' => '.*',
'negative_regexp' => '.*',
},

'ldap' => {
'regexp' => '.*',
'negative_regexp' => '.*',
Expand Down Expand Up @@ -953,7 +960,7 @@ sub _load_auth {
if (/^\s*authentication_info_url\s+(.*\S)\s*$/o) {
$Conf{'authentication_info_url'}{$robot} = $1;
next;
} elsif (/^\s*(ldap|cas|user_table|generic_sso)\s*$/io) {
} elsif (/^\s*(cgi|ldap|user_table|cas|generic_sso)\s*$/io) {
$current_paragraph->{'auth_type'} = lc($1);
} elsif (/^\s*(\S+)\s+(.*\S)\s*$/o) {
my ($keyword, $value) = ($1, $2);
Expand Down Expand Up @@ -1074,6 +1081,9 @@ sub _load_auth {
$current_paragraph->{'scope'} ||= 'sub';
} elsif ($current_paragraph->{'auth_type'} eq 'user_table') {
;
} elsif ($current_paragraph->{'auth_type'} eq 'cgi') {
$current_paragraph->{'remote_user_variable'} ||=
'REMOTE_USER';
}
# setting default
$current_paragraph->{'regexp'} = '.*'
Expand Down