my( $name, $val );
die "Invalid syntax on line $_\n" unless( ( $name, $val ) = /^\s*(.*\S)\s*=\s*(.*\S)\s*$/ );
$val =~ s/^"(.*)"$/$1/;
+ ( $val ) = ( $val =~ /(.*)/ ); #Untaint the value - config is considered part of the program
$config{$name} = $val;
}
close CONFIG;
use strict;
use warnings;
use PciIds::Config;
+use PciIds::Users;
use base 'Exporter';
our @EXPORT = qw(&sendMail);
sub sendMail( $$$ ) {
my( $to, $subject, $body ) = @_;
my( $from, $sendmail ) = confList( [ 'from_addr', 'sendmail' ] );
+ my $error;
+ ( $error, $to ) = emailCheck( $to, undef );
+ die "Invalid email in database $to\n" if defined $error;
$body =~ s/^\.$/../gm;
open SENDMAIL, "|$sendmail -f$from $to" or die 'Can not send mail';
print SENDMAIL "From: $from\n".
return undef;
}
-sub emailCheck( $$ ) {
- my( $email, $tables ) = @_;
- my $newmail;
- return 'Does not look like an email address' unless ( ( $newmail ) = ( $email =~ /^([^,? "'`;]+@[^@,?\/ "'`;]+)$/ ) );#make sure the mail is not only reasonable looking, but safe to work with too
- return 'Email too long' if length $newmail > 255;
- return 'An account for this email address already exists' if( $tables->hasEmail( $newmail ) );
- return ( undef, $newmail );
-}
-
sub registerSubmit( $$$ ) {#A registration form has been submited
my( $req, $args, $tables ) = @_;
my( $data, $error ) = getForm( {
my( %privnames, %privnums );
-our @EXPORT = qw(&addUser &emailConfirm &checkConfirmHash &saltedPasswd &genAuthToken &checkAuthToken &hasRight &getRightDefs &genResetHash &changePasswd &pushProfile);
+our @EXPORT = qw(&addUser &emailConfirm &checkConfirmHash &saltedPasswd &genAuthToken &checkAuthToken &hasRight &getRightDefs &genResetHash &changePasswd &pushProfile &emailCheck);
+
+sub emailCheck( $$ ) {
+ my( $email, $tables ) = @_;
+ my $newmail;
+ return 'Does not look like an email address' unless ( ( $newmail ) = ( $email =~ /^([^,? "'`;]+@[^@,?\/ "'`;]+)$/ ) );#make sure the mail is not only reasonable looking, but safe to work with too
+ return 'Email too long' if length $newmail > 255;
+ return 'An account for this email address already exists' if( ( defined $tables ) && $tables->hasEmail( $newmail ) );
+ return ( undef, $newmail );
+}
sub saltedPasswd( $$ ) {
my( $email, $passwd ) = @_;