📄 smbldap-migrate-pwdump-accounts
字号:
#!/usr/bin/perl -w# $Id: smbldap-migrate-pwdump-accounts,v 1.1 2005/03/08 09:29:47 jtournier Exp $## This code was developped by IDEALX (http://IDEALX.org/) and# contributors (their names can be found in the CONTRIBUTORS file).## Copyright (C) 2002 IDEALX## This program is free software; you can redistribute it and/or# modify it under the terms of the GNU General Public License# as published by the Free Software Foundation; either version 2# of the License, or (at your option) any later version.## This program is distributed in the hope that it will be useful,# but WITHOUT ANY WARRANTY; without even the implied warranty of# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the# GNU General Public License for more details.## You should have received a copy of the GNU General Public License# along with this program; if not, write to the Free Software# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,# USA.# Purpose of smbldap-migrate-accounts : add NT sam entries from pwdump # to ldapuse strict;use Getopt::Std;use FindBin;use FindBin qw($RealBin);use lib "$RealBin/";use smbldap_tools;# smbldap-migrate (-? or -h for help)## Read pwdump entries on stdin, and add them to the ldap server.# Output uncreated/unmodified entries (see parameters -C -U)# in pwdump format to stdout.# Errors, debug and stats are output to stderr.sub modify_account { my ($login, $basedn, $lmpwd, $ntpwd, $gecos, $homedir) = @_; # bind to a directory with dn and password my $ldap_master=connect_ldap_master(); my $modify = $ldap_master->modify ("uid=$login,$basedn", changes => [ replace => [sambaLMPassword => "$lmpwd"], replace => [sambaNTPassword => "$ntpwd"], replace => [gecos => "$gecos"], replace => [sambaHomePath => "$homedir"] ] ); $modify->code && die "failed to modify entry: ", $modify->error ; # take down the session $ldap_master->unbind; }#####################my %Options;my $ok = getopts('awA:CUW:?h', \%Options);if ( (!$ok) || ($Options{'?'}) || ($Options{'h'}) ) { print "Usage: $0 [-awAWCU?]\n"; print " -a process only people, ignore computers\n"; print " -w process only computers, ignore persons\n"; print " -A <opts> option string passed verbatim to smbldap-useradd for persons\n"; print " -W <opts> option string passed verbatim to smbldap-useradd for computers\n"; print " -C if entry not found, don't create it and log it to stdout (default: create it)\n"; print " -U if entry found, don't update it and log it to stdout (default: update it)\n"; print " -?|-h show this help message\n"; exit (1);}my %processed = ( 'user' => 0, 'machine' => 0);my %created = ( 'user' => 0, 'machine' => 0);my %updated = ( 'user' => 0, 'machine' => 0);my %logged = ( 'user' => 0, 'machine' => 0);my %errors = ( 'user' => 0, 'machine' => 0);my %existing = ( 'user' => 0, 'machine' => 0);my $specialskipped = 0;while (<>) { my ($login, $rid, $lmpwd, $ntpwd, $gecos, $homedir, $b) = split(/:/, $_); my $usertype; my $userbasedn; my $entry_type = 'user'; if ($login =~ m/.*\$$/ ) { # computer $processed{'machine'}++; $entry_type = 'machine'; if (defined($Options{'a'})) { print STDERR "ignoring $login\n"; next; } $usertype = "-w $Options{'W'}"; $userbasedn = $config{computersdn}; } else { # people $processed{'user'}++; if (defined($Options{'w'})) { print STDERR "ignoring $login\n"; next; } if ($rid < 1000) { $specialskipped++; print STDERR "$login seems to be a special Win account (rid=$rid), skipping\n"; next; } $usertype = "-a $Options{'A'}"; $userbasedn = $config{usersdn}; } # normalize homedir # uncomment to replace configured share with share from pwdump # if ($homedir eq "") { $homedir = $config{userSmbHome}; # } # normalize gecos if (!($gecos eq "")) { $gecos =~ tr/晾履徉怃晴扇仕崎桕腈吞衔盱钕疡右灾篁赧谫苒
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -