Search code examples
perlcpansetuid

Can cpan's use of the .local directory be redirected?


I have a setuid program which then calls cpan as root on behalf of the user. This works for commands like yum, but fails for cpan. My problem is that the users' home directories are NFS mounted shares, and use the root-squash option, so root has no access to the user's home directory.

Cpan attempts to create a .local directory in the user's home, which fails due to the root-squash.

Is there a way to configure cpan such that it would use another path as its base for building the package? Or, is there a way to set up root as the userid of record so that cpan would attempt to create the .local file there?

Sample output:

./cloudSoftware cpan foobar mkdir /home/auto/ts00086/.local: Permission denied at /usr/share/perl5/CPAN/HandleConfig.pm line 589.


Solution

  • cpan_home_dir_candidates generates a list of directories.

    1. The first dir in the list that contains CPAN/MyConfig.pm is used.
    2. Otherwise, the first dir in the list that exists is used.
    3. Otherwise, the first dir in the list is used.

    So how is the list built?

    if ($CPAN::META->has_usable('File::HomeDir')) {
        if ($^O ne 'darwin') {
            push @dirs, File::HomeDir->my_data;
            # my_data is ~/Library/Application Support on darwin,
            # which causes issues in the toolchain.
        }
        push @dirs, File::HomeDir->my_home;
    }
    # Windows might not have HOME, so check it first
    push @dirs, $ENV{HOME} if $ENV{HOME};
    ...
    

    Options include:

    • Changing the HOME env var (if File::HomeDir isn't installed).
    • Editing cpan_home_dir_candidates in CPAN/HandleConfig.pm to add push @dirs, "/alt/dir";
    • ...