0
  "   ˆl–Ðz¾”Jj"TÒ�zàœ¸”Å£Æƒ"gÀÄ +    #!/usr/local/cpanel/3rdparty/bin/perl

# cpanel - scripts/checklink                       Copyright 2022 cPanel, L.L.C.
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

mkdir( "/usr/local/cpanel/tests", 0700 );
system( "chown", "cpanel:cpanel", "/usr/local/cpanel/tests" );

setuids("cpanel");

unlink("/usr/local/cpanel/tests/linktest1");
unlink("/usr/local/cpanel/tests/linktest2");
open( LINKTEST, ">/usr/local/cpanel/tests/linktest1" ) || die "Unable to create file for link test";
close(LINKTEST);
link( "/usr/local/cpanel/tests/linktest1", "/usr/local/cpanel/tests/linktest2" );
if ( -f "/usr/local/cpanel/tests/linktest2" ) {
    print "Test Passed!!\n";
}
else {
    print "Test Failed!!   $!\n";
}

sub setuids {
    my ($user) = $_[0];
    my ( $uid, $gid );
    ( undef, undef, $uid, $gid ) = getpwnam($user);
    if ( !( $) = "$gid $gid" ) ) {
        print "error setting gid\n";
        exit;
    }

    if ( !( $( = int($gid) ) ) {
        print "error setting gid\n";
        exit;
    }
    if ( !( ( $> = $uid ) && ( $< = $uid ) ) ) {
        die "error setting uid ($uid) [$user]\n";
    }
    return $uid;
}
  	   ˆ¿Æ0ÀÄ  	   ˆ¿Æ0ÀÄ     ˆ¾Æƒi¡5ÀÄ H    #!/usr/local/cpanel/3rdparty/bin/perl

# cpanel - scripts/fixetchosts                     Copyright 2022 cPanel, L.L.C.
#                                                           All rights reserved.
# copyright@cpanel.net                                         http://cpanel.net
# This code is subject to the cPanel license. Unauthorized copying is prohibited

package scripts::fixetchosts;

use strict;
use Cpanel::SafeFile             ();
use Cpanel::Validate::Hostname   ();
use Cpanel::IP::Loopback         ();
use Cpanel::DIp::MainIP          ();
use Cpanel::Sys::Hostname::FQDN  ();
use Cpanel::FileUtils::TouchFile ();
use IO::Handle                   ();

exit script(@ARGV) unless caller;

sub script {
    return run('/etc/hosts');
}

sub run {
    my ($file)        = @_;
    my $mainip        = Cpanel::DIp::MainIP::getmainserverip();
    my $hostname      = Cpanel::Sys::Hostname::FQDN::get_fqdn_hostname();
    my $shorthostname = Cpanel::Sys::Hostname::FQDN::get_short_hostname();

    # CPANEL-36014: If the returned hostname ends with a trailing dot, strip it.
    $hostname =~ s/\.$//;

    Cpanel::FileUtils::TouchFile::touchfile($file);
    die "The hostname $hostname is not valid.\n" unless Cpanel::Validate::Hostname::is_valid($hostname);

    update( $file, $mainip, $hostname, $shorthostname );
    return 0;
}

sub update {
    my ( $file, $mainip, $hostname, $shorthostname ) = @_;

    my $hosts_fh   = IO::Handle->new();
    my $hosts_lock = Cpanel::SafeFile::safeopen( $hosts_fh, '+<', $file );
    if ($hosts_lock) {
        my %SEENIP;
        my @ETCHOSTS;

        while ( my $line = readline $hosts_fh ) {
            chomp $line;
            if ( $line =~ m/^\s*#/ || $line =~ m/^\s*$/ ) {
                push @ETCHOSTS, { 'raw' => $line };
            }
            else {
                my ( $ip, $hosts ) = split( /\s+/, $line, 2 );
                my @line_hosts;
                foreach my $host ( split( /\s+/, $hosts ) ) {
                    next if ( $ip ne $mainip && $host eq $hostname );                                   # Drop mismatch hostnames for the main IP
                    next if ( $ip eq $mainip && ( $host eq $hostname || $host eq $shorthostname ) );    # These will be re-added
                    push @line_hosts, $host if ( !grep { $_ eq $host } @line_hosts );                   # Drop duplicates while preserving order
                }

                if ( !@line_hosts ) {                                                                   ## Drop empty lines
                    next if $ip eq $mainip;                                                             # Prevent duplic