Samba-LDAP
view release on metacpan or search on metacpan
scripts/smbldap-userinfo view on Meta::CPAN
#!/usr/bin/perl -w
# Created by P.Wieleba@iem.pw.edu.pl in 2004
use strict;
use Getopt::Std;
use FindBin;
use FindBin qw($RealBin);
use lib "$RealBin/";
use smbldap_tools;
# function declaration
sub exist_in_tab;
my %Options;
my $ok = getopts('f:r:w:h:o:s:?v', \%Options);
if ( (!$ok) || ($Options{'?'}) ) {
print "Usage: $0 [-frwhosh?] username\n";
print " -?|-h show this help message\n";
print " -f full_name\n";
print " -r room_no\n";
print " -w work_ph\n";
print " -h home_ph\n";
print " -o other\n";
print " -s shell\n";
print " -v show modified user record\n";
exit (1);
}
my $user;
my $pass;
if ( $< != 0 ) {
my $current_user = getpwuid($<);
if ($current_user and $ARGV[0] and $current_user ne $ARGV[0] ) {
die "Only root can change other users inormation\n";
}
} else {
if ( $ARGV[0] ) {
$user = $ARGV[0];
}
$pass = 1;
}
if (!defined($user)) {
$user = getpwuid($<);
}
my ($dn,$ldap_master);
# First, connecting to the directory
if ($< != 0) {
# non-root user
if (!defined($pass)) {
# prompt for password
print "UNIX password: ";
system "stty -echo" if (-t STDIN);
chomp($pass=<STDIN>);
system "stty echo" if (-t STDIN);
print "\n";
$config{masterDN}="uid=$user,$config{usersdn}";
$config{masterPw}="$pass";
$ldap_master=connect_ldap_master();
$dn=$config{masterDN};
if (!is_user_valid($user, $dn, $pass)) {
print "Authentication failure\n";
exit (10);
}
}
} else {
# root user
$ldap_master=connect_ldap_master();
# test existence of user in LDAP
my $dn_line;
if (!defined($dn_line = get_user_dn($user))) {
print "$0: user $user doesn't exist\n";
exit (10);
}
$dn = get_dn_from_line($dn_line);
}
my %eng = (
'shell' => 'User Shell',
'name' => 'Full Name',
'office' => 'Room Number',
'wphone' => 'Work Phone',
'hphone' => 'Home Phone',
'other' => 'Other'
);
# obtain old values
my $entry = read_user_entry($user);
my $gecos = $entry->get_value('gecos');
my %old;
( $old{'name'},
$old{'office'},
$old{'wphone'},
$old{'hphone'},
$old{'other'}
) = split(/,/,$gecos);
$old{'shell'} = $entry->get_value('LoginShell');
# unbind from LDAP
$ldap_master->unbind();
foreach my $key (keys %old) {
!defined($old{$key}) and $old{$key}="";
( run in 0.597 second using v1.01-cache-2.11-cpan-f56aa216473 )