Mail-SpamAssassin
view release on metacpan or search on metacpan
lib/Mail/SpamAssassin.pm view on Meta::CPAN
$self->{conf} ||= Mail::SpamAssassin::Conf->new($self);
$self->{plugins} = Mail::SpamAssassin::PluginHandler->new($self);
$self->{save_pattern_hits} ||= 0;
# Make sure that we clean $PATH if we're tainted
Mail::SpamAssassin::Util::clean_path_in_taint_mode();
if (!defined $self->{username}) {
$self->{username} = (Mail::SpamAssassin::Util::portable_getpwuid ($>))[0];
}
$self->create_locker();
$self;
}
sub create_locker {
my ($self) = @_;
lib/Mail/SpamAssassin.pm view on Meta::CPAN
if ($helper_dir) {
my $dir = File::Spec->catdir($helper_dir, ".spamassassin");
return if $self->test_global_state_dir($dir);
}
# try user home (if different from helper home)
my $home;
if (am_running_on_windows()) {
# Windows has a special folder for common appdata (Bug 8050)
$home = Mail::SpamAssassin::Util::common_application_data_directory();
} else {
$home = (Mail::SpamAssassin::Util::portable_getpwuid ($>))[7];
}
if ($home && $home ne $helper_dir) {
my $dir = File::Spec->catdir($home, ".spamassassin");
return if $self->test_global_state_dir($dir);
}
# try LOCAL_STATE_DIR
return if $self->test_global_state_dir($self->{LOCAL_STATE_DIR});
# fallback to userstate
$self->{global_state_dir} = $self->get_and_create_userstate_dir();
dbg("config: global_state_dir set to userstate_dir: $self->{global_state_dir}");
lib/Mail/SpamAssassin.pm view on Meta::CPAN
return $userprofile if ($userprofile && $userprofile =~ m/^[a-z]\:[\/\\]/i);
return $userprofile if ($userprofile =~ m/^\\\\/);
return $home if ($home && $home =~ m/^[a-z]\:[\/\\]/i);
return $home if ($home =~ m/^\\\\/);
return '';
} else {
return $home if ($home && index($home, '/') != -1);
return (getpwnam($name))[7] if ($name ne '');
return (getpwuid($>))[7];
}
}
sub sed_path {
my ($self, $path) = @_;
return if !defined $path;
if (exists($self->{conf}->{sed_path_cache}->{$path})) {
return $self->{conf}->{sed_path_cache}->{$path};
}
lib/Mail/SpamAssassin/ArchiveIterator.pm view on Meta::CPAN
sub _fix_globs {
my ($self, $path) = @_;
unless (defined $home) {
$home = $ENV{'HOME'};
# No $HOME set? Try to find it, portably.
unless ($home) {
if (!Mail::SpamAssassin::Util::am_running_on_windows()) {
$home = (Mail::SpamAssassin::Util::portable_getpwuid($<))[7];
} else {
my $vol = $ENV{'HOMEDRIVE'} || 'C:';
my $dir = $ENV{'HOMEPATH'} || '\\';
$home = File::Spec->catpath($vol, $dir, '');
}
# Fall back to no replacement at all.
$home ||= '~';
}
}
lib/Mail/SpamAssassin/Dns.pm view on Meta::CPAN
}
}
Mail::SpamAssassin::Util::clean_path_in_taint_mode();
my $newhome;
if ($self->{main}->{home_dir_for_helpers}) {
$newhome = $self->{main}->{home_dir_for_helpers};
} else {
# use spamd -u user's home dir
$newhome = (Mail::SpamAssassin::Util::portable_getpwuid ($>))[7];
}
if ($newhome) {
$ENV{'HOME'} = Mail::SpamAssassin::Util::untaint_file_path ($newhome);
}
# enforce SIGCHLD as DEFAULT; IGNORE causes spurious kernel warnings
# on Red Hat NPTL kernels (bug 1536), and some users of the
# Mail::SpamAssassin modules set SIGCHLD to be a fatal signal
# for some reason! (bug 3507)
lib/Mail/SpamAssassin/Util.pm view on Meta::CPAN
utf8::encode($str) if utf8::is_utf8($str); # force octets
my $bits = unpack("B*", $str)."0000";
my $output;
local($1);
$output .= $base32_bitchr{$1} while ($bits =~ /(.{5})/g);
return $output;
}
###########################################################################
sub portable_getpwuid {
if (defined &Mail::SpamAssassin::Util::_getpwuid_wrapper) {
return Mail::SpamAssassin::Util::_getpwuid_wrapper(@_);
}
my $sts;
if (!RUNNING_ON_WINDOWS) {
$sts = eval ' sub _getpwuid_wrapper { getpwuid($_[0]); }; 1 ';
} else {
dbg("util: defining getpwuid() wrapper using 'unknown' as username");
$sts = eval ' sub _getpwuid_wrapper { _fake_getpwuid($_[0]); }; 1 ';
}
if (!$sts) {
my $eval_stat = $@ ne '' ? $@ : "errno=$!"; chomp $eval_stat;
warn "util: failed to define getpwuid() wrapper: $eval_stat\n";
} else {
return Mail::SpamAssassin::Util::_getpwuid_wrapper(@_);
}
}
sub _fake_getpwuid {
return (
'unknown', # name,
'x', # passwd,
$_[0], # uid,
0, # gid,
'', # quota,
'', # comment,
'', # gcos,
'/', # dir,
'', # shell,
lib/Mail/SpamAssassin/Util.pm view on Meta::CPAN
return $time if defined($time);
}
return time;
}
###########################################################################
sub get_user_groups {
my $suid = shift;
dbg("util: get_user_groups: uid is $suid\n");
my ($user, $gid) = (getpwuid($suid))[0,3];
my $rgids = "$gid ";
while (my($name,$gid,$members) = (getgrent())[0,2,3]) {
if (grep { $_ eq $user } split(/ /, $members)) {
$rgids .= "$gid ";
dbg("util: get_user_groups: added $gid ($name) to group list which is now: $rgids\n");
}
}
endgrent;
chop $rgids;
return ($rgids);
spamc/spamc.c view on Meta::CPAN
goto fail;
goto pass;
}
#ifndef _WIN32
/* Get the passwd information for the effective uid spamc is running
* under. Setting errno to zero is recommended in the manpage.
*/
errno = 0;
curr_user = getpwuid(geteuid());
if (curr_user == NULL) {
perror("getpwuid() failed");
goto fail;
}
/* Since "curr_user" points to static library data, we don't wish to
* risk some other part of the system overwriting it, so we copy the
* username to our own buffer -- then this won't arise as a problem.
*/
*username = strdup(curr_user->pw_name);
if (*username == NULL) {
goto fail;
spamd-apache2/bin/apache-spamd.pl view on Meta::CPAN
if (exists $opt->{httpd_conf}) {
die "ERROR: --httpd_conf must be a regular file\n"
if -e $opt->{httpd_conf} && !-f _;
$opt->{httpd_conf} = File::Spec->rel2abs($opt->{httpd_conf})
unless $opt->{httpd_conf} eq '-';
}
unless ($opt->{username}) {
warn "$0: Running as root, huh? Asking for trouble, aren't we?\n" if $< == 0;
$opt->{username} = getpwuid($>); # weird apache behaviour on 64bit machines if it's missing
warn "$0: setting User to '$opt->{username}', pass --username to override\n"
if $opt->{debug} =~ /\b(?:all|info|spamd|prefork|config)\b/;
}
#
# start processing command line and preparing config / cmd line for Apache
#
my @directives; # -C ... (or write these to a temporary config file)
my @run = ( # arguments to exec()
t/SATest.pm view on Meta::CPAN
close PREFS
or die "error closing $localrules/99_test_default.cf: $!";
$home = $ENV{'HOME'};
$home ||= $ENV{'WINDIR'} if (defined $ENV{'WINDIR'});
$cwd = getcwd;
$ENV{'TEST_DIR'} = $cwd;
$testname = $tname;
$spamd_run_as_user = ($RUNNING_ON_WINDOWS || ($> == 0)) ? "nobody" : (getpwuid($>))[0] ;
}
# remove all rules - $localrules/*.cf
# when you want to only use rules declared inside a specific *.t
sub clear_localrules {
for $tainted (<$localrules/*.cf>) {
$tainted =~ /(.*)/;
my $file = $1;
# Keep some useful, should not contain any rules
next if $file =~ /10_default_prefs.cf$/;
( run in 0.633 second using v1.01-cache-2.11-cpan-8d75d55dd25 )