Comm.pl good on Linux, bad on HP-UX 
Author Message
 Comm.pl good on Linux, bad on HP-UX

I built the attached script on my Linux host, where it works great.
But I copied it to one of our HP-UX 10.20 systems, and it fails there
with these messages:

        $ gpasswd -V oldpswd newpswd cronus
        cronus is pingable
        Trying for file handle on cronus
        getpty_svr4: stat(Comm'PTY)=(1073741827,5133,8630,1,0,0,
                -1677721594,0,877622835,
                878050356,878050356,,), 6=-1677721594
        ptsname not found, using Solaris minor numbers
        rdev=-1677721594
        slave=/dev/pts/6, ptsname(3)=/dev/pts/6
        system (pt_chmod 3)
        could not open slave, /dev/pts/6, errno=Permission denied
                at /opt/perl5/lib/Comm.pl line 1342.    

I'm using perl 5.00401 on both Linux and HP-UX, and Comm.pl-1.8.tar.gz.
Here's a listing of gpasswd, which you're free to copy, if you'd find it
useful:

#!/usr/bin/perl
# --------------------------------------------------------------------------
# Changelog
# 971027 Created by Smitty.
# --------------------------------------------------------------------------
# Description:
#
# [hostnames | \]
#  gpasswd [-v] <old password> <new password> [<hostname1> <hostname2>...]
#
# -v is for verbose messages.  If you use -V, Comm.pl will also be told to
#       be verbose. Without -v, gpasswd will only list those hosts it
#       failed to changes passwords on.
# <hostname1> <hostname2>... is optional.  It's the list of hosts on which
#       passwords are to be changes.  If no hosts are listed, gpasswd expects
#       a list to be on STDIN.
#
# Used to globally change your unix login passwords.  You must supply the old
# and new passwords as arguments, and the list of hosts on which to change
# passwords, either on the command line, or on STDIN.  This command will
# rlogin to each host, issue the passwd command, and supply the old and new
# passwords, then logout(exit).
# --------------------------------------------------------------------------
require "Comm.pl";
&Comm::init( 1.8 );
$|=1; # No buffering of STDOUT.

# -------------------------------------------------------------------------
# Subroutines.
sub sr() {
# -------------------------------------------------------------------------

# If $send isn't a null string, sends it on $pty.  Then it waits for a
# response.  Returns 1 if a response is matched, 0 otherwise.
# -------------------------------------------------------------------------

        print $pty "$send\n" if ($send ne "");
        ( $match, $err, $before, $after ) =

        return(0) if ( ! defined $match );
        print("Got $match\n") if($debug);
        return(1);

Quote:
} # End sr.

# -------------------------------------------------------------------------
# Mainline.
$os=`uname -s`; chop($os);
if ($os eq "Linux") {
        $ping="ping -c 1 ";
        $pingaft="";
Quote:
} else {

        $ping="/etc/ping ";
        $pingaft=" 64 1";
Quote:
}

$nis_master="helios";
$seconds||=10; # seconds to wait before timeout.


$ENV{"TERM"}="vt100:$display";

%rlogin=();     # Indicates which hosts got successful rlogins.
%prompt=();     # Indicates which hosts got a shell prompt.
%nis=();        # Indicates which hosts are NIS but not the master.
%passwd=();     # Indicates which hosts got a successful passwd change.

LOOP: while($arg = shift) { # Process the command arguments.
        last if (substr($arg,0,1) ne "-");
        if (length($arg) > 2) { # Do only one option at a time.
                $narg="-".substr($arg,2);

                $arg = substr($arg,0,2);
        }
        SWITCH: {
                if ($arg eq "-v" || $arg eq "-V") {
                        $debug=1;
                        $Debug=$debug if ($arg eq "-V") ; # Tell Comm.pl.
                        last SWITCH;
                }
                die("Unknown parameter = $arg\n");
        } # End SWITCH.

Quote:
} # End LOOP.

$old = $arg;
$new = shift;
die("You must suppy the old and new passwords.\n")
        if (!defined($old) || !defined($new));


        while (<>) { # Get any hosts listed on STDIN.
                chop;

        }
Quote:
}


        $rlogin{$host}=0; # Add hostname to keys.
        next unless (`$ping $host $pingaft` =~ / 0% packet loss/);
        print("$host is pingable\n") if ($debug);
        print("Trying for file handle on $host\n") if ($debug);
        ( $pty, $tty, $pid ) = &open_proc( "rlogin $host");
        next unless ($rlogin{$host}=defined($pty));
        print("Got file handle for login process on $host\n") if ($debug);
        BLOCK: { # Lets me use last/next.
                last if ( ! &sr("", $prompt, "DISPLAY:", "Password:"));

                if ($match eq "Password:") {
                        last if ( ! &sr($old, $prompt, "login:"));
                        if ($match eq "login:") {
                                print("Password invalid on $host\n")
                                        if ($debug);
                                last;
                        }
                }
                if ($match eq "DISPLAY:") {
                        print $pty "\n";
                        last if ( ! &sr("",
                                "not ping-able. Try another",
                                $prompt));
                        if ($match eq "not ping-able. Try another") {
                                last if ( ! &sr("n", $prompt));
                        }
                }
                print("Got shell prompt on $host\n") if($debug);
                $prompt{$host}=1;

                if (&sr("nistest","yes")) { # Host uses NIS.
                        $nis{$host}=1;
                        print("$host uses NIS\n") if ($debug);
                        if ($host ne $nis_master) {
                                print("Password should only be changed on ".
                                        $nis_master."\n") if ($debug);
                                last;
                        }
                        $cmd="yppasswd";
                        $confirm="The NIS passwd has been changed";
                } else {
                        $cmd="passwd";
                        $confirm=$prompt;
                }
                $new_prompt="New password:"; # Same for both.

                last if ( ! &sr($cmd, "Old password:", "Old NIS password:"));

                last if ( ! &sr($old, $new_prompt,
                        "Your entry does not match the old password.",
                        "Sorry."));
                last if ($match ne $new_prompt);

                last if ( ! &sr($new,
                        "Re-enter new password:",
                        "Retype new password:",
                        "Enter the new password again:"));

                last if ( ! &sr($new, $confirm, $prompt));
                if ($match !~ $confirm) {
                        print("$before\n") if($debug);
                        last;
                }
                print("Password changed on $host\n") if($debug);
                $passwd{$host}=1;

                last if ( ! &sr("exit", "rlogin: connection closed."));
                print("Got logged out of $host OK\n") if($debug);
        } # End BLOCK
        if ($debug && !defined($match)) {
                print("before=$before\n");
                print("match=$match\n");
                print("after=$after\n");
                print("err=$err\n");
        }
        if (defined($pty)) {
                print("Closing file handle\n") if($debug);
                &close_it($pty);
        }

Quote:
}

if ($debug) {
        foreach $host (sort keys(%rlogin)) {
                if(!$rlogin{$host}) {
                        print("Failed to rlogin to $host\n")
                } else {
                        print("Failed to get a shell prompt on $host\n")
                                if(!$prompt{$host});
                }
        }
Quote:
}

$rc=0;
foreach $host (sort keys(%rlogin)) {
        next if ($passwd{$host}); # Password was changed ok.
        next if ($nis{$host} && $passwd{$nis_master}); # NIS master changed.
        $rc=1; # At least one password failed to be changed.
        print("Failed to change the password on $host\n")
Quote:
}

print("Finis.\n") if($debug);
exit($rc);
--


Tue, 18 Apr 2000 03:00:00 GMT  
 Comm.pl good on Linux, bad on HP-UX


Quote:
>I built the attached script on my Linux host, where it works great.
>But I copied it to one of our HP-UX 10.20 systems, and it fails there
>with these messages:

>    $ gpasswd -V oldpswd newpswd cronus
>    cronus is pingable
>    Trying for file handle on cronus
>    getpty_svr4: stat(Comm'PTY)=(1073741827,5133,8630,1,0,0,
>            -1677721594,0,877622835,
>            878050356,878050356,,), 6=-1677721594
>    ptsname not found, using Solaris minor numbers

                                 ^^^^^^^

Quote:
>    rdev=-1677721594
>    slave=/dev/pts/6, ptsname(3)=/dev/pts/6
>    system (pt_chmod 3)
>    could not open slave, /dev/pts/6, errno=Permission denied
>            at /opt/perl5/lib/Comm.pl line 1342.    

>I'm using perl 5.00401 on both Linux and HP-UX, and Comm.pl-1.8.tar.gz.
>Here's a listing of gpasswd, which you're free to copy, if you'd find it
>useful:

Your problem appears to be that Comm.pl thinks it is running on
a Solaris machine.  Look at the Comm::init function to figure out why
this is the case.  In addition you may need to compile the helper programs
and put them in your path.

Matthew



Wed, 19 Apr 2000 03:00:00 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. Comm.pl good on Linux, bad on HP-UX

2. Comm.pl and HP-UX V11

3. Seeking Comm.pl for HP-UX (9/10)

4. Comm.pl on hpux 10.20

5. Comm.pl & HPUX 10.01

6. HPUX Comm.pl or IPC

7. Comm.pl to simlate expect does not work on hp

8. comm.pl for hp??

9. Comm.pl to simlate expect does not work on hp

10. Comm.pl works fine on Linux, not on SunOS

11. Comm.pl and Linux

12. Comm.pl and Linux (2.2 or greater)

 

 
Powered by phpBB® Forum Software