[ILUG] Synchronising yp and samba passwords

From: Cormac McClean (cmcclean at domain ait.ie)
Date: Thu 04 Oct 2001 - 12:16:08 IST


Hi,

I am in the process of RTFMs[0], but I was wondering if anyone had any
pointers.

We've set up a Linux server for students which uses NFS/NIS and Samba
to give them access to their home directories from Linux and Windows NT.
I'm writing a perl script to synchronise passwords for NIS and Samba, and
I've run into a problem using Expect.

Here's the subroutine. I'm passing in the username and new password.

sub SetPasswd {
        my ($username, $passwd) = at domain _;

        my $pobj = Expect->spawn($passwdex, $username);

        die "Unable to spawn $passwdex:$!\n" unless (defined ($pobj));

        $pobj->log_stdout(0);

        $pobj->expect(10, "New password: ");
        sleep 1;

        print $pobj "$passwd\r"; ### <--- Problem here
        $pobj->expect(10, "Re-enter new password: ");
        print $pobj "$passwd\r"; ### <--- and here

        $result = (defined ($pobj->expect(10, "successfully changed")) ?
                                "" : "password change failed");

        $pobj->soft_close();

        return $result;
}

It's taken from "Perl for System Administration" (O'Reilly). At the moment
I'm testing with the yppasswd program (so $passwdex is /usr/bin/yppasswd).
What's happening is that the spawn is occurring, but not working properly.
For one thing, I'm getting error messages relating to the lines
        print $pobj "passwd\r";
which are:
print on closed filehandle Symbol::GEN0 at /usr/local/bin/sync_pass.pl line
64, <STDIN> chunk 4.
which indicates that the spawn has not been successful (and yet $pobj is
defined, otherwise the script would die at that point).

Any suggestions? Or is there an alternative way to synchronise the NIS and
Samba passwords? Perhaps by using configuring Samba to use the NIS passwords?
Just thought of that....

Thanks in advance,
Cormac.

[0] Manuals include "Uisng Samba", "Managing NFS and NIS", "Perl for System
Administration", and various other O'Reilly books... I have a veritable
shrine to O'Reilly Publishing in my office.



This archive was generated by hypermail 2.1.6 : Thu 06 Feb 2003 - 13:12:30 GMT