#!/usr/bin/perl
# cpanel - fix-exim-permissions                   Copyright(c) 2016 cPanel, Inc.
#                                                           All rights Reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

use strict;

BEGIN { unshift @INC, '/usr/local/cpanel'; }

use Cpanel::SafeRun  ();
use Cpanel::SafeFile ();

our $EXIM_PL = '/etc/exim.pl';

sub is_affected {
    return 0 unless -e $EXIM_PL;
    return ( ( stat($EXIM_PL) )[2] & 0777 ) == 0;
}

sub fix {
    chmod( 0644, $EXIM_PL );
    return !is_affected();
}

sub script {
    return 0 unless is_affected();

    my $is_fixed = fix();
    print "exim.pl fix was " . ( $is_fixed ? "successful" : "unsuccessful" ), "\n";
    return !$is_fixed;
}

exit script() unless caller;
