Cannot call FTP from a UDP process
search cancel

Cannot call FTP from a UDP process

book

Article ID: 417933

calendar_today

Updated On:

Products

CA Harvest Software Change Manager

Issue/Introduction

After upgrading zLinux OS from SLES 12 SP5 -> SLES 15 SP6, UDP process that worked pre OS upgrade fails on the FTP call

Environment

CA Harvest Change Manager 14.x

Resolution

There are two (2) potential solutions for the issue with the Perl FTP script from Harvest UDPs:
 
Approach #1 - Use a “re-exec” trick inside the script

You can modify the Perl script (which utilizes Net::FTP) as follows:

#!/usr/bin/perl
BEGIN {
    # ---- Define prefixes ----
    my $ld_prefix    = '/usr/lib64:/lib64:/usr/lib';
    my $shlib_prefix = '/usr/lib64:/lib64:/usr/lib';
    my $path_prefix  = '/usr/bin';

    # ---- Prepend safe library paths ----
    $ENV{'LD_LIBRARY_PATH'} =
        $ld_prefix . ($ENV{'LD_LIBRARY_PATH'} ? ":$ENV{'LD_LIBRARY_PATH'}" : '');
    $ENV{'SHLIB_PATH'} =
        $shlib_prefix . ($ENV{'SHLIB_PATH'} ? ":$ENV{'SHLIB_PATH'}" : '');

    # ---- Prepend safe executable path ----
    $ENV{'PATH'} =
        $path_prefix . ($ENV{'PATH'} ? ":$ENV{'PATH'}" : '');

    # ---- Re-exec to apply clean environment before any dynamic loads ----
    unless ($ENV{'__LD_FIX_DONE__'}) {
        $ENV{'__LD_FIX_DONE__'} = 1;
        exec($^X, $0, @ARGV);
    }
}
...
use Net::FTP;
...

Summary: Modifies the order of library precedence prior to their actual loading
Advantage: This is a safe and clean approach
Disadvantage: If you have multiple scripts that invoke Net::FTP, you will need to modify all of them manually
 
Approach #2 - Use a symbolic link wrapper for Perl

1.  Move the real Perl binary

mv /usr/bin/perl /usr/bin/perl.real

2.  Create a wrapper script at /usr/bin/perl:

#!/bin/bash
# --- Wrapper for Perl with safe environment prepending ---

# Define safe prefixes
LD_PREFIX="/usr/lib64:/lib64:/usr/lib"
SHLIB_PREFIX="/usr/lib64:/lib64:/usr/lib"
PATH_PREFIX="/usr/bin"

# Prepend safe library paths if not already first
if [ -n "$LD_LIBRARY_PATH" ]; then
    export LD_LIBRARY_PATH="${LD_PREFIX}:$LD_LIBRARY_PATH"
else
    export LD_LIBRARY_PATH="$LD_PREFIX"
fi

if [ -n "$SHLIB_PATH" ]; then
    export SHLIB_PATH="${SHLIB_PREFIX}:$SHLIB_PATH"
else
    export SHLIB_PATH="$SHLIB_PREFIX"
fi

# Prepend /usr/bin to PATH
if [ -n "$PATH" ]; then
    export PATH="${PATH_PREFIX}:$PATH"
else
    export PATH="$PATH_PREFIX"
fi

# Execute the real Perl binary
exec /usr/bin/perl.real "$@"

3. Make it executable:

chmod +x /usr/bin/perl

Summary: Establishes a secure wrapper around the Perl executable, ensuring that the library path precedence is set prior to invoking the actual executable
Advantage: No changes to the scripts are necessary at all
Disadvantage: This will affect all Perl scripts system-wide
 
Please choose the approach that best meets your needs.