UNIX->smbpasswd synch

Peter Samuelson peter at cadcamlab.org
Sun Jun 18 17:25:47 GMT 2000


[Peter Samuelson <peter at wire.cadcamlab.org>]
> Tests so far indicate that Linux `su' behaves rather strangely.  If
> it has a controlling tty, it wants this to be stdin, even when run as
> root (so it doesn't need to prompt for a password).

I figured it out!  I'm feeling a bit stupid right now.  Linux `su' is
entirely deterministic and sensible after all.

The problem was that `su' had no idea it was supposed to be running as
root, since the real uid was non-root.  So, naturally, it was wanting
to prompt for a password.

I give up.  Switching to Perl.

Peter



#!/usr/bin/perl -w

# cleanse the path since Perl thinks we're running setuid
$ENV{PATH} = '/usr/local/samba/bin:/usr/bin';

# possibly this should come from smb.conf...
$ntpdc='MYNTSERVER';

# un-setuid
$) = $(;	# egids = gids
$> = $<;	# euid = uid

# debugging
#open STDOUT, ">>/tmp/passwdchange.out";
#open STDERR, ">>/tmp/passwdchange.err";
close STDOUT;
close STDERR;

while (<STDIN>) {
  if (m/([^ ]+) (.*)/) {
    if ($1 eq 'user') { $u = $2; next; }
    elsif ($1 eq 'password') { $n = $2; next; }
    elsif ($1 eq 'oldpassword') { $o = $2; next; }
  }
# print STDERR "Unexpected line: $_\n";
}

if (defined($o)) {
  # todo: error checking?
  open OUT, "|smbpasswd -s -r '$ntpdc' -U '$u'";
  print OUT "$o\n$n\n$n\n";
  close OUT;
}


More information about the samba-ntdom mailing list