Lines 24-30
sub read_shadow_file;
Link Here
|
24 |
|
24 |
|
25 |
my %Options; |
25 |
my %Options; |
26 |
|
26 |
|
27 |
my $ok = getopts('M:P:S:vn?hd:a', \%Options); |
27 |
my $ok = getopts('M:P:S:vn?hd:auw', \%Options); |
28 |
|
28 |
|
29 |
if ( (!$ok) || ($Options{'?'}) || ($Options{'h'}) || (!keys(%Options)) ) { |
29 |
if ( (!$ok) || ($Options{'?'}) || ($Options{'h'}) || (!keys(%Options)) ) { |
30 |
print "Usage: $0 [-PSMvn?hda]\n"; |
30 |
print "Usage: $0 [-PSMvn?hda]\n"; |
Lines 36-41
if ( (!$ok) || ($Options{'?'}) || ($Opti
Link Here
|
36 |
print " -n do everything execpt updating LDAP\n"; |
36 |
print " -n do everything execpt updating LDAP\n"; |
37 |
print " -d obj_nam delete and add (not just update) existing entry in LDAP\n"; |
37 |
print " -d obj_nam delete and add (not just update) existing entry in LDAP\n"; |
38 |
print " -a adds sambaSamAccount objectClass\n"; |
38 |
print " -a adds sambaSamAccount objectClass\n"; |
|
|
39 |
print " -u process only people, ignore computers\n"; |
40 |
print " -w process only computers, ignore persons\n"; |
41 |
|
39 |
exit (1); |
42 |
exit (1); |
40 |
} |
43 |
} |
41 |
|
44 |
|
Lines 60-65
if ( $Options{'M'} ) {
Link Here
|
60 |
} |
63 |
} |
61 |
|
64 |
|
62 |
my $ldap_master=connect_ldap_master(); |
65 |
my $ldap_master=connect_ldap_master(); |
|
|
66 |
my $typeuser = undef; |
63 |
|
67 |
|
64 |
while ( my $line=<$INFILE> ) { |
68 |
while ( my $line=<$INFILE> ) { |
65 |
chop($line); |
69 |
chop($line); |
Lines 67-72
while ( my $line=<$INFILE> ) {
Link Here
|
67 |
next if ( $line =~ /^#/ ); |
71 |
next if ( $line =~ /^#/ ); |
68 |
next if ( $line =~ /^\+/ ); |
72 |
next if ( $line =~ /^\+/ ); |
69 |
my $entry = undef; |
73 |
my $entry = undef; |
|
|
74 |
my $login = undef; |
75 |
|
70 |
if ($Options{'M'}) { |
76 |
if ($Options{'M'}) { |
71 |
my($user,$pwd,$uid,$gid,$class,$change,$expire,$gecos,$homedir,$shell) = split(/:/,$line); |
77 |
my($user,$pwd,$uid,$gid,$class,$change,$expire,$gecos,$homedir,$shell) = split(/:/,$line); |
72 |
# if user is not in LDAP new entry will be created |
78 |
# if user is not in LDAP new entry will be created |
Lines 82-87
while ( my $line=<$INFILE> ) {
Link Here
|
82 |
# if user is not in LDAP new entry will be created |
88 |
# if user is not in LDAP new entry will be created |
83 |
$entry = get_user_entry($ldap_master,$user); |
89 |
$entry = get_user_entry($ldap_master,$user); |
84 |
$entry = migrate_user($entry,$user,$pwd,$uid,$gid,$gecos,$homedir,$shell,undef); |
90 |
$entry = migrate_user($entry,$user,$pwd,$uid,$gid,$gecos,$homedir,$shell,undef); |
|
|
91 |
$login = $user; |
85 |
|
92 |
|
86 |
# should I delete next functionality |
93 |
# should I delete next functionality |
87 |
# add shadow entries if also -S defined |
94 |
# add shadow entries if also -S defined |
Lines 94-99
while ( my $line=<$INFILE> ) {
Link Here
|
94 |
# if user is not in LDAP new entry will be created |
101 |
# if user is not in LDAP new entry will be created |
95 |
$entry = get_user_entry($ldap_master,$user); |
102 |
$entry = get_user_entry($ldap_master,$user); |
96 |
$entry = migrate_shadow_user($entry,$user,$pwd,$lastchg,$min,$max,$warn,$inactive,$expire,$flag); |
103 |
$entry = migrate_shadow_user($entry,$user,$pwd,$lastchg,$min,$max,$warn,$inactive,$expire,$flag); |
|
|
104 |
$login = $user; |
105 |
} |
106 |
|
107 |
if ($login =~ m/.*\$$/ ) { # computer |
108 |
$typeuser = "usersdn"; |
109 |
if (defined($Options{'u'})) { |
110 |
print "ignoring $login type: $typeuser\n"; |
111 |
next; |
112 |
} |
113 |
} else { # people |
114 |
$typeuser = "computersdn"; |
115 |
if (defined($Options{'w'})) { |
116 |
print "ignoring $login type: $typeuser\n"; |
117 |
next; |
118 |
} |
97 |
} |
119 |
} |
98 |
|
120 |
|
99 |
if ($entry) { |
121 |
if ($entry) { |
Lines 116-122
while ( my $line=<$INFILE> ) {
Link Here
|
116 |
my $userRid = 2 * $userUidNumber + 1000; |
138 |
my $userRid = 2 * $userUidNumber + 1000; |
117 |
# let's test if this SID already exist |
139 |
# let's test if this SID already exist |
118 |
my $user_sid = "$config{SID}-$userRid"; |
140 |
my $user_sid = "$config{SID}-$userRid"; |
119 |
my $test_exist_sid = does_sid_exist($user_sid,$config{usersdn}); |
141 |
my $test_exist_sid = does_sid_exist($user_sid,$config{$typeuser}); |
120 |
if ($test_exist_sid->count == 1) { |
142 |
if ($test_exist_sid->count == 1) { |
121 |
print "User SID already owned by\n"; |
143 |
print "User SID already owned by\n"; |
122 |
# there should not exist more than one entry, but ... |
144 |
# there should not exist more than one entry, but ... |
Lines 230-243
sub get_user_entry
Link Here
|
230 |
my($ldap_master,$user) = @_; |
252 |
my($ldap_master,$user) = @_; |
231 |
|
253 |
|
232 |
# do not use read_user_entry() |
254 |
# do not use read_user_entry() |
233 |
my $mesg = $ldap_master->search( base => $config{usersdn}, |
255 |
my $mesg = $ldap_master->search( base => $config{$typeuser}, |
234 |
scope => 'one', |
256 |
scope => 'one', |
235 |
filter => "(uid=$user)" |
257 |
filter => "(uid=$user)" |
236 |
); |
258 |
); |
237 |
my $entry; |
259 |
my $entry; |
238 |
if ( $mesg->count() != 1 ) { |
260 |
if ( $mesg->count() != 1 ) { |
239 |
$entry = Net::LDAP::Entry->new(); |
261 |
$entry = Net::LDAP::Entry->new(); |
240 |
$entry->dn("uid=$user,$config{usersdn}"); |
262 |
$entry->dn("uid=$user,$config{$typeuser}"); |
241 |
} else { |
263 |
} else { |
242 |
$entry = $mesg->entry(0); # ???? |
264 |
$entry = $mesg->entry(0); # ???? |
243 |
} |
265 |
} |