1 | #!/usr/bin/perl -w |
---|
2 | |
---|
3 | # $Id: smbldap-usermod 5894 2012-09-28 10:09:27Z edwin $ |
---|
4 | # |
---|
5 | # This code was developped by IDEALX (http://IDEALX.org/) and |
---|
6 | # contributors (their names can be found in the CONTRIBUTORS file). |
---|
7 | # |
---|
8 | # Copyright (C) 2001-2002 IDEALX |
---|
9 | # |
---|
10 | # This program is free software; you can redistribute it and/or |
---|
11 | # modify it under the terms of the GNU General Public License |
---|
12 | # as published by the Free Software Foundation; either version 2 |
---|
13 | # of the License, or (at your option) any later version. |
---|
14 | # |
---|
15 | # This program is distributed in the hope that it will be useful, |
---|
16 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
17 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
18 | # GNU General Public License for more details. |
---|
19 | # |
---|
20 | # You should have received a copy of the GNU General Public License |
---|
21 | # along with this program; if not, write to the Free Software |
---|
22 | # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, |
---|
23 | # USA. |
---|
24 | |
---|
25 | # Purpose of smbldap-usermod : user (posix,shadow,samba) modification |
---|
26 | |
---|
27 | use strict; |
---|
28 | use FindBin; |
---|
29 | use FindBin qw($RealBin); |
---|
30 | use lib "$RealBin/"; |
---|
31 | use smbldap_tools; |
---|
32 | |
---|
33 | ##################### |
---|
34 | |
---|
35 | use Getopt::Std; |
---|
36 | my %Options; |
---|
37 | my $nscd_status; |
---|
38 | |
---|
39 | my $ok = getopts('A:B:C:D:E:F:O:H:IJM:n:N:S:PT:ame:f:u:g:G:d:l:r:s:c:ok:?hzZxX', \%Options); |
---|
40 | if ( (!$ok) || (@ARGV < 1) || ($Options{'?'}) || ($Options{'h'}) ) { |
---|
41 | print_banner; |
---|
42 | print "Usage: $0 [-awmugdsckABCDEFGHIPSMT?h] username\n"; |
---|
43 | print "Available options are:\n"; |
---|
44 | print " -c gecos\n"; |
---|
45 | print " -d home directory\n"; |
---|
46 | #print " -m move home directory\n"; |
---|
47 | #print " -f inactive days\n"; |
---|
48 | print " -r new username (cn, sn and dn are updated)\n"; |
---|
49 | print " -u uid\n"; |
---|
50 | print " -o uid can be non unique\n"; |
---|
51 | print " -O Organisatie\n"; |
---|
52 | print " -g gid\n"; |
---|
53 | print " -G supplementary groups (comma separated)\n"; |
---|
54 | print " -s shell\n"; |
---|
55 | print " -n givenName (first name)\n"; |
---|
56 | print " -N canonical name\n"; |
---|
57 | print " -S surname\n"; |
---|
58 | print " -P ends by invoking smbldap-passwd\n"; |
---|
59 | print " For samba users:\n"; |
---|
60 | print " -a add sambaSAMAccount objectclass\n"; |
---|
61 | print " -e expire date (\"YYYY-MM-DD HH:MM:SS\")\n"; |
---|
62 | print " -A can change password ? 0 if no, 1 if yes\n"; |
---|
63 | print " -B must change password ? 0 if no, 1 if yes\n"; |
---|
64 | print " -C sambaHomePath (SMB home share, like '\\\\PDC-SRV\\homes')\n"; |
---|
65 | print " -D sambaHomeDrive (letter associated with home share, like 'H:')\n"; |
---|
66 | print " -E sambaLogonScript (DOS script to execute on login)\n"; |
---|
67 | print " -F sambaProfilePath (profile directory, like '\\\\PDC-SRV\\profiles\\foo')\n"; |
---|
68 | print " -H sambaAcctFlags (samba account control bits like '[NDHTUMWSLKI]')\n"; |
---|
69 | print " -I disable an user. Can't be used with -H or -J\n"; |
---|
70 | print " -J enable an user. Can't be used with -H or -I\n"; |
---|
71 | print " -M mailAddresses (comma seperated)\n"; |
---|
72 | print " -T mailToAddress (forward address) (comma seperated)\n"; |
---|
73 | print " For zarafa users:\n"; |
---|
74 | print " -X Enable Zarafa usage for this user.\n"; |
---|
75 | print " -x Disable Zarafa usage for this user.\n"; |
---|
76 | print " -Z Enable Zarafa admin rights.\n"; |
---|
77 | print " -z Disable Zarafa admin rights.\n"; |
---|
78 | print " -?|-h show this help message\n"; |
---|
79 | exit (1); |
---|
80 | } |
---|
81 | |
---|
82 | if ($< != 0) { |
---|
83 | print "You must be root to modify an user\n"; |
---|
84 | exit (1); |
---|
85 | } |
---|
86 | # Read only first @ARGV |
---|
87 | my $user = $ARGV[0]; |
---|
88 | |
---|
89 | # Let's connect to the directory first |
---|
90 | my $ldap_master=connect_ldap_master(); |
---|
91 | |
---|
92 | # Read user data |
---|
93 | my $user_entry = read_user_entry($user); |
---|
94 | if (!defined($user_entry)) { |
---|
95 | print "$0: user $user doesn't exist\n"; |
---|
96 | exit (1); |
---|
97 | } |
---|
98 | |
---|
99 | my $samba = 0; |
---|
100 | if (grep ($_ =~ /^sambaSamAccount$/i, $user_entry->get_value('objectClass'))) { |
---|
101 | $samba = 1; |
---|
102 | } |
---|
103 | |
---|
104 | # get the dn of the user |
---|
105 | my $dn= $user_entry->dn(); |
---|
106 | |
---|
107 | my $tmp; |
---|
108 | my @mods; |
---|
109 | my @dels; |
---|
110 | if (defined($tmp = $Options{'a'})) { |
---|
111 | # Let's connect to the directory first |
---|
112 | my $winmagic = 2147483647; |
---|
113 | my $valpwdcanchange = 0; |
---|
114 | my $valpwdmustchange = $winmagic; |
---|
115 | my $valpwdlastset = 0; |
---|
116 | my $valacctflags = "[UX]"; |
---|
117 | my $user_entry=read_user_entry($user); |
---|
118 | my $uidNumber = $user_entry->get_value('uidNumber'); |
---|
119 | my $userRid = 2 * $uidNumber + 1000; |
---|
120 | # apply changes |
---|
121 | my $modify = $ldap_master->modify ( "$dn", |
---|
122 | changes => [ |
---|
123 | add => [objectClass => 'sambaSAMAccount'], |
---|
124 | add => [sambaPwdLastSet => "$valpwdlastset"], |
---|
125 | add => [sambaLogonTime => '0'], |
---|
126 | add => [sambaLogoffTime => '2147483647'], |
---|
127 | add => [sambaKickoffTime => '2147483647'], |
---|
128 | add => [sambaPwdCanChange => "$valpwdcanchange"], |
---|
129 | add => [sambaPwdMustChange => "$valpwdmustchange"], |
---|
130 | add => [displayName => "$config{userGecos}"], |
---|
131 | add => [sambaSID=> "$config{SID}-$userRid"], |
---|
132 | add => [sambaAcctFlags => "$valacctflags"], |
---|
133 | ] |
---|
134 | ); |
---|
135 | $modify->code && warn "failed to modify entry: ", $modify->error ; |
---|
136 | } |
---|
137 | |
---|
138 | # Process options |
---|
139 | my $changed_uid; |
---|
140 | my $_userUidNumber; |
---|
141 | my $_userRid; |
---|
142 | if (defined($tmp = $Options{'u'})) { |
---|
143 | if (defined($Options{'o'})) { |
---|
144 | $nscd_status = system "/etc/init.d/nscd status >/dev/null 2>&1"; |
---|
145 | |
---|
146 | if ($nscd_status == 0) { |
---|
147 | system "/etc/init.d/nscd stop > /dev/null 2>&1"; |
---|
148 | } |
---|
149 | |
---|
150 | if (getpwuid($tmp)) { |
---|
151 | if ($nscd_status == 0) { |
---|
152 | system "/etc/init.d/nscd start > /dev/null 2>&1"; |
---|
153 | } |
---|
154 | |
---|
155 | print "$0: uid number $tmp exists\n"; |
---|
156 | exit (6); |
---|
157 | } |
---|
158 | if ($nscd_status == 0) { |
---|
159 | system "/etc/init.d/nscd start > /dev/null 2>&1"; |
---|
160 | } |
---|
161 | |
---|
162 | } |
---|
163 | push(@mods, 'uidNumber', $tmp); |
---|
164 | $_userUidNumber = $tmp; |
---|
165 | if ($samba) { |
---|
166 | # as rid we use 2 * uid + 1000 |
---|
167 | my $_userRid = 2 * $_userUidNumber + 1000; |
---|
168 | if (defined($Options{'x'})) { |
---|
169 | $_userRid= sprint("%x", $_userRid); |
---|
170 | } |
---|
171 | push(@mods, 'sambaSID', $config{SID}.'-'.$_userRid); |
---|
172 | } |
---|
173 | $changed_uid = 1; |
---|
174 | } |
---|
175 | |
---|
176 | my $changed_gid; |
---|
177 | my $_userGidNumber; |
---|
178 | my $_userGroupSID; |
---|
179 | if (defined($tmp = $Options{'g'})) { |
---|
180 | $_userGidNumber = parse_group($tmp); |
---|
181 | if ($_userGidNumber < 0) { |
---|
182 | print "$0: group $tmp doesn't exist\n"; |
---|
183 | exit (6); |
---|
184 | } |
---|
185 | push(@mods, 'gidNumber', $_userGidNumber); |
---|
186 | if ($samba) { |
---|
187 | # as grouprid we use the sambaSID attribute's value of the group |
---|
188 | my $group_entry = read_group_entry_gid($_userGidNumber); |
---|
189 | my $_userGroupSID = $group_entry->get_value('sambaSID'); |
---|
190 | unless ($_userGroupSID) { |
---|
191 | print "Error: sambaPrimaryGroupSid could not be set (sambaSID for group $_userGidNumber does not exist\n"; |
---|
192 | exit (7); |
---|
193 | } |
---|
194 | push(@mods, 'sambaPrimaryGroupSid', $_userGroupSID); |
---|
195 | } |
---|
196 | $changed_gid = 1; |
---|
197 | } |
---|
198 | |
---|
199 | if (defined($tmp = $Options{'s'})) { |
---|
200 | push(@mods, 'loginShell' => $tmp); |
---|
201 | } |
---|
202 | |
---|
203 | if (defined($tmp = $Options{'O'})) { |
---|
204 | push(@mods, 'o' => $tmp); |
---|
205 | } |
---|
206 | |
---|
207 | |
---|
208 | |
---|
209 | if (defined($tmp = $Options{'c'})) { |
---|
210 | push(@mods, 'gecos' => $tmp, |
---|
211 | 'description' => $tmp); |
---|
212 | if ($samba == 1) { |
---|
213 | push(@mods, 'displayName' => $tmp); |
---|
214 | } |
---|
215 | } |
---|
216 | |
---|
217 | if (defined($tmp = $Options{'d'})) { |
---|
218 | push(@mods, 'homeDirectory' => $tmp); |
---|
219 | } |
---|
220 | |
---|
221 | if (defined($tmp = $Options{'N'})) { |
---|
222 | push(@mods, 'cn' => $tmp); |
---|
223 | } |
---|
224 | |
---|
225 | #added by datux to set given name for OX |
---|
226 | if (defined($tmp = $Options{'n'})) { |
---|
227 | push(@mods, 'givenName' => $tmp); |
---|
228 | } |
---|
229 | |
---|
230 | if (defined($tmp = $Options{'S'})) { |
---|
231 | push(@mods, 'sn' => $tmp); |
---|
232 | } |
---|
233 | |
---|
234 | my $mailobj = 0; |
---|
235 | #Omgehacked voor open exchange: (alias ipv mail, en geen maillocaladress) |
---|
236 | if ($tmp= $Options{'M'}) { |
---|
237 | # action si + or - for adding or deleting an entry |
---|
238 | my $action= ''; |
---|
239 | if ($tmp =~ s/^([+-])+\s*//) { |
---|
240 | $action= $1; |
---|
241 | } |
---|
242 | my @userMailLocal = &split_arg_comma($tmp); |
---|
243 | my @mail; |
---|
244 | foreach my $m (@userMailLocal) { |
---|
245 | my $domain = $config{mailDomain}; |
---|
246 | if ($m =~ /^(.+)@/) { |
---|
247 | push (@mail, $m); |
---|
248 | # mailLocalAddress contains only the first part |
---|
249 | $m= $1; |
---|
250 | } else { |
---|
251 | push(@mail, $m.($domain ? '@'.$domain : '')); |
---|
252 | } |
---|
253 | } |
---|
254 | if ($action) { |
---|
255 | #my @old_MailLocal; |
---|
256 | my @old_mail; |
---|
257 | @old_mail = $user_entry->get_value('alias'); |
---|
258 | # @old_MailLocal = $user_entry->get_value('mailLocalAddress'); |
---|
259 | if ($action eq '+') { |
---|
260 | # @userMailLocal = &list_union(\@old_MailLocal, \@userMailLocal); |
---|
261 | @mail = &list_union(\@old_mail, \@mail); |
---|
262 | } elsif ($action eq '-') { |
---|
263 | # @userMailLocal = &list_minus(\@old_MailLocal, \@userMailLocal); |
---|
264 | @mail = &list_minus(\@old_mail, \@mail); |
---|
265 | } |
---|
266 | } |
---|
267 | #push(@mods, 'mailLocalAddress', [ @userMailLocal ]); |
---|
268 | push(@mods, 'alias' => [ @mail ]); |
---|
269 | push(@mods, 'mail' => $mail[0]); |
---|
270 | #$mailobj = 1; |
---|
271 | } |
---|
272 | |
---|
273 | if ($tmp= $Options{'T'}) { |
---|
274 | my $action= ''; |
---|
275 | my @old; |
---|
276 | # action si + or - for adding or deleting an entry |
---|
277 | if ($tmp =~ s/^([+-])+\s*//) { |
---|
278 | $action= $1; |
---|
279 | } |
---|
280 | my @userMailTo = &split_arg_comma($tmp); |
---|
281 | if ($action) { |
---|
282 | @old = $user_entry->get_value('mailRoutingAddress'); |
---|
283 | } |
---|
284 | if ($action eq '+') { |
---|
285 | @userMailTo = &list_union(\@old, \@userMailTo); |
---|
286 | } elsif ($action eq '-') { |
---|
287 | @userMailTo = &list_minus(\@old, \@userMailTo); |
---|
288 | } |
---|
289 | push(@mods, 'mailRoutingAddress', [ @userMailTo ]); |
---|
290 | $mailobj = 1; |
---|
291 | } |
---|
292 | if ($mailobj) { |
---|
293 | my @objectclass = $user_entry->get_value('objectClass'); |
---|
294 | if (! grep ($_ =~ /^inetLocalMailRecipient$/i, @objectclass)) { |
---|
295 | push(@mods, 'objectClass' => [ @objectclass, 'inetLocalMailRecipient' ]); |
---|
296 | } |
---|
297 | } |
---|
298 | |
---|
299 | |
---|
300 | if (defined($tmp = $Options{'G'})) { |
---|
301 | my $action= ''; |
---|
302 | if ($tmp =~ s/^([+-])+\s*//) { |
---|
303 | $action= $1; |
---|
304 | } |
---|
305 | if ($action eq '-') { |
---|
306 | # remove user from specified groups |
---|
307 | foreach my $gname (&split_arg_comma($tmp)) { |
---|
308 | group_remove_member($gname, $user); |
---|
309 | } |
---|
310 | } else { |
---|
311 | if ($action ne '+') { |
---|
312 | my @old = &find_groups_of($user); |
---|
313 | # remove user from old groups |
---|
314 | foreach my $gname (@old) { |
---|
315 | if ($gname ne "") { |
---|
316 | group_remove_member($gname, $user); |
---|
317 | } |
---|
318 | } |
---|
319 | } |
---|
320 | # add user to new groups |
---|
321 | add_grouplist_user($tmp, $user); |
---|
322 | } |
---|
323 | } |
---|
324 | |
---|
325 | # |
---|
326 | # A : sambaPwdCanChange |
---|
327 | # B : sambaPwdMustChange |
---|
328 | # C : sambaHomePath |
---|
329 | # D : sambaHomeDrive |
---|
330 | # E : sambaLogonScript |
---|
331 | # F : sambaProfilePath |
---|
332 | # H : sambaAcctFlags |
---|
333 | |
---|
334 | my $attr; |
---|
335 | my $winmagic = 2147483647; |
---|
336 | |
---|
337 | $samba = is_samba_user($user); |
---|
338 | |
---|
339 | if (defined($tmp = $Options{'e'})) { |
---|
340 | if ($samba == 1) { |
---|
341 | my $kickoffTime=`date --date='$tmp' +%s`; |
---|
342 | chomp($kickoffTime); |
---|
343 | push(@mods, 'sambakickoffTime' => $kickoffTime); |
---|
344 | } else { |
---|
345 | print "User $user is not a samba user\n"; |
---|
346 | } |
---|
347 | } |
---|
348 | |
---|
349 | my $_sambaPwdCanChange; |
---|
350 | if (defined($tmp = $Options{'A'})) { |
---|
351 | if ($samba == 1) { |
---|
352 | $attr = "sambaPwdCanChange"; |
---|
353 | if ($tmp != 0) { |
---|
354 | $_sambaPwdCanChange=0; |
---|
355 | } else { |
---|
356 | $_sambaPwdCanChange=$winmagic; |
---|
357 | } |
---|
358 | push(@mods, 'sambaPwdCanChange' => $_sambaPwdCanChange); |
---|
359 | } else { |
---|
360 | print "User $user is not a samba user\n"; |
---|
361 | } |
---|
362 | } |
---|
363 | |
---|
364 | my $_sambaPwdMustChange; |
---|
365 | if (defined($tmp = $Options{'B'})) { |
---|
366 | if ($samba == 1) { |
---|
367 | if ($tmp != 0) { |
---|
368 | $_sambaPwdMustChange=0; |
---|
369 | # To force a user to change his password: |
---|
370 | # . the attribut sambaPwdLastSet must be != 0 |
---|
371 | # . the attribut sambaAcctFlags must not match the 'X' flag |
---|
372 | my $_sambaAcctFlags; |
---|
373 | my $flags = $user_entry->get_value('sambaAcctFlags'); |
---|
374 | if ( defined $flags and $flags =~ /X/ ) { |
---|
375 | my $letters; |
---|
376 | if ($flags =~ /(\w+)/) { |
---|
377 | $letters = $1; |
---|
378 | } |
---|
379 | $letters =~ s/X//; |
---|
380 | $_sambaAcctFlags="\[$letters\]"; |
---|
381 | push(@mods, 'sambaAcctFlags' => $_sambaAcctFlags); |
---|
382 | } |
---|
383 | my $_sambaPwdLastSet = $user_entry->get_value('sambaPwdLastSet'); |
---|
384 | if ($_sambaPwdLastSet == 0) { |
---|
385 | push(@mods, 'sambaPwdLastSet' => $winmagic); |
---|
386 | } |
---|
387 | } else { |
---|
388 | $_sambaPwdMustChange=$winmagic; |
---|
389 | } |
---|
390 | push(@mods, 'sambaPwdMustChange' => $_sambaPwdMustChange); |
---|
391 | } else { |
---|
392 | print "User $user is not a samba user\n"; |
---|
393 | } |
---|
394 | } |
---|
395 | |
---|
396 | if (defined($tmp = $Options{'C'})) { |
---|
397 | if ($samba == 1) { |
---|
398 | if ($tmp eq "" and defined $user_entry->get_value('sambaHomePath')) { |
---|
399 | push(@dels, 'sambaHomePath' => []); |
---|
400 | } elsif ($tmp ne "") { |
---|
401 | push(@mods, 'sambaHomePath' => $tmp); |
---|
402 | } |
---|
403 | } else { |
---|
404 | print "User $user is not a samba user\n"; |
---|
405 | } |
---|
406 | } |
---|
407 | |
---|
408 | my $_sambaHomeDrive; |
---|
409 | if (defined($tmp = $Options{'D'})) { |
---|
410 | if ($samba == 1) { |
---|
411 | if ($tmp eq "" and defined $user_entry->get_value('sambaHomeDrive')) { |
---|
412 | push(@dels, 'sambaHomeDrive' => []); |
---|
413 | } elsif ($tmp ne "") { |
---|
414 | $tmp = $tmp.":" unless ($tmp =~ /:/); |
---|
415 | push(@mods, 'sambaHomeDrive' => $tmp); |
---|
416 | } |
---|
417 | } else { |
---|
418 | print "User $user is not a samba user\n"; |
---|
419 | } |
---|
420 | } |
---|
421 | |
---|
422 | if (defined($tmp = $Options{'E'})) { |
---|
423 | if ($samba == 1) { |
---|
424 | if ($tmp eq "" and defined $user_entry->get_value('sambaLogonScript')) { |
---|
425 | push(@dels, 'sambaLogonScript' => []); |
---|
426 | } elsif ($tmp ne "") { |
---|
427 | push(@mods, 'sambaLogonScript' => $tmp); |
---|
428 | } |
---|
429 | } else { |
---|
430 | print "User $user is not a samba user\n"; |
---|
431 | } |
---|
432 | } |
---|
433 | |
---|
434 | if (defined($tmp = $Options{'F'})) { |
---|
435 | if ($samba == 1) { |
---|
436 | if ($tmp eq "" and defined $user_entry->get_value('sambaProfilePath')) { |
---|
437 | push(@dels, 'sambaProfilePath' => []); |
---|
438 | } elsif ($tmp ne "") { |
---|
439 | push(@mods, 'sambaProfilePath' => $tmp); |
---|
440 | } |
---|
441 | } else { |
---|
442 | print "User $user is not a samba user\n"; |
---|
443 | } |
---|
444 | } |
---|
445 | |
---|
446 | if ($samba == 1 and (defined $Options{'H'} or defined $Options{'I'} or defined $Options{'J'})) { |
---|
447 | my $_sambaAcctFlags; |
---|
448 | if (defined($tmp = $Options{'H'})) { |
---|
449 | #$tmp =~ s/\\/\\\\/g; |
---|
450 | $_sambaAcctFlags=$tmp; |
---|
451 | } else { |
---|
452 | # I or J |
---|
453 | my $flags; |
---|
454 | $flags = $user_entry->get_value('sambaAcctFlags'); |
---|
455 | |
---|
456 | if (defined($tmp = $Options{'I'})) { |
---|
457 | if ( !($flags =~ /D/) ) { |
---|
458 | my $letters; |
---|
459 | if ($flags =~ /(\w+)/) { |
---|
460 | $letters = $1; |
---|
461 | } |
---|
462 | $_sambaAcctFlags="\[D$letters\]"; |
---|
463 | } |
---|
464 | } elsif (defined($tmp = $Options{'J'})) { |
---|
465 | if ( $flags =~ /D/ ) { |
---|
466 | my $letters; |
---|
467 | if ($flags =~ /(\w+)/) { |
---|
468 | $letters = $1; |
---|
469 | } |
---|
470 | $letters =~ s/D//; |
---|
471 | $_sambaAcctFlags="\[$letters\]"; |
---|
472 | } |
---|
473 | } |
---|
474 | } |
---|
475 | |
---|
476 | |
---|
477 | if ($_sambaAcctFlags and "$_sambaAcctFlags" ne '') { |
---|
478 | push(@mods, 'sambaAcctFlags' => $_sambaAcctFlags); |
---|
479 | } |
---|
480 | |
---|
481 | } elsif (!$samba == 1 and (defined $Options{'H'} or defined $Options{'I'} or defined $Options{'J'})) { |
---|
482 | print "User $user is not a samba user\n"; |
---|
483 | } |
---|
484 | |
---|
485 | # Zarafa stuff |
---|
486 | my $zarafaobj=0; |
---|
487 | if (defined($tmp = $Options{'X'})) { |
---|
488 | push(@mods, 'zarafaSharedStoreOnly' => 0); |
---|
489 | $zarafaobj = 1; |
---|
490 | } |
---|
491 | if (defined($tmp = $Options{'x'})) { |
---|
492 | push(@mods, 'zarafaSharedStoreOnly' => 1); |
---|
493 | $zarafaobj = 1; |
---|
494 | } |
---|
495 | if (defined($tmp = $Options{'Z'})) { |
---|
496 | push(@mods, 'zarafaAdmin' => 1); |
---|
497 | $zarafaobj = 1; |
---|
498 | } |
---|
499 | if (defined($tmp = $Options{'z'})) { |
---|
500 | push(@mods, 'zarafaAdmin' => 0); |
---|
501 | $zarafaobj = 1; |
---|
502 | } |
---|
503 | if ($zarafaobj) { |
---|
504 | my @objectclass = $user_entry->get_value('objectClass'); |
---|
505 | if (! grep ($_ =~ /^zarafa-user$/i, @objectclass)) { |
---|
506 | push(@mods, 'objectClass' => [ @objectclass, 'zarafa-user' ]); |
---|
507 | } |
---|
508 | } |
---|
509 | |
---|
510 | |
---|
511 | |
---|
512 | # apply changes |
---|
513 | my $modify = $ldap_master->modify ( "$dn", |
---|
514 | 'replace' => { @mods } |
---|
515 | ); |
---|
516 | $modify->code && warn "failed to modify entry: ", $modify->error ; |
---|
517 | |
---|
518 | # we can delete only if @dels is not empty: we check the number of elements |
---|
519 | my $nb_to_del=scalar(@dels); |
---|
520 | if ($nb_to_del != 0) { |
---|
521 | $modify = $ldap_master->modify ( "$dn", |
---|
522 | 'delete' => { @dels } |
---|
523 | ); |
---|
524 | $modify->code && warn "failed to modify entry: ", $modify->error ; |
---|
525 | } |
---|
526 | # take down session |
---|
527 | $ldap_master->unbind; |
---|
528 | |
---|
529 | if (defined(my $new_user= $Options{'r'})) { |
---|
530 | my $ldap_master=connect_ldap_master(); |
---|
531 | chomp($new_user); |
---|
532 | # read eventual new user entry |
---|
533 | my $new_user_entry = read_user_entry($new_user); |
---|
534 | if (defined($new_user_entry)) { |
---|
535 | print "$0: user $new_user already exists, cannot rename\n"; |
---|
536 | exit (1); |
---|
537 | } |
---|
538 | my $modify = $ldap_master->moddn ( |
---|
539 | "uid=$user,$config{usersdn}", |
---|
540 | newrdn => "uid=$new_user", |
---|
541 | deleteoldrdn => "1", |
---|
542 | newsuperior => "$config{usersdn}" |
---|
543 | ); |
---|
544 | $modify->code && die "failed to change dn", $modify->error; |
---|
545 | |
---|
546 | # change cn, sn attributes |
---|
547 | my $user_entry = read_user_entry($new_user); |
---|
548 | my $dn= $user_entry->dn(); |
---|
549 | my @mods; |
---|
550 | push(@mods, 'sn' => $new_user); |
---|
551 | push(@mods, 'cn' => $new_user); |
---|
552 | $modify = $ldap_master->modify ("$dn", |
---|
553 | changes => [ |
---|
554 | 'replace' => [ @mods ] |
---|
555 | ] |
---|
556 | ); |
---|
557 | $modify->code && warn "failed to change cn and sn attributes: ", $modify->error; |
---|
558 | |
---|
559 | # changing username in groups |
---|
560 | my @groups = &find_groups_of($user); |
---|
561 | foreach my $gname (@groups) { |
---|
562 | if ($gname ne "") { |
---|
563 | my $dn_line = get_group_dn($gname); |
---|
564 | my $dn = get_dn_from_line("$dn_line"); |
---|
565 | print "updating group $gname\n"; |
---|
566 | $modify = $ldap_master->modify("$dn", |
---|
567 | changes => [ |
---|
568 | 'delete' => [memberUid => $user], |
---|
569 | 'add' => [memberUid => $new_user] |
---|
570 | ]); |
---|
571 | $modify->code && warn "failed to change cn and sn attributes: ", $modify->error; |
---|
572 | } |
---|
573 | } |
---|
574 | $ldap_master->unbind; |
---|
575 | } |
---|
576 | |
---|
577 | $nscd_status = system "/etc/init.d/nscd status >/dev/null 2>&1"; |
---|
578 | |
---|
579 | if ($nscd_status == 0) { |
---|
580 | system "/etc/init.d/nscd restart > /dev/null 2>&1"; |
---|
581 | } |
---|
582 | |
---|
583 | if (defined($Options{'P'})) { |
---|
584 | exec "$RealBin/smbldap-passwd $user" |
---|
585 | } |
---|
586 | |
---|
587 | |
---|
588 | ############################################################ |
---|
589 | |
---|
590 | =head1 NAME |
---|
591 | |
---|
592 | smbldap-usermod - Modify a user account |
---|
593 | |
---|
594 | =head1 SYNOPSIS |
---|
595 | |
---|
596 | smbldap-usermod [-a] [-c comment] [-d home_dir] [-e expiration_date] [-g initial_group] [-l login_name] [-p passwd] [-s shell] [-u uid [ -o]] [-x] [-A canchange] [-B mustchange] [-C smbhome] [-D homedrive] [-E scriptpath] [-F profilepath] [-G group[,...]] [-H acctflags] [-N canonical_name] [-S surname] [-P] login |
---|
597 | |
---|
598 | =head1 DESCRIPTION |
---|
599 | |
---|
600 | The smbldap-usermod command modifies the system account files to reflect the changes that are specified on the command line. The options which apply to the usermod command are |
---|
601 | |
---|
602 | -a |
---|
603 | Add the sambaSAMAccount objectclass to the specified user account. This allow the user to become a samba user. |
---|
604 | |
---|
605 | -c comment |
---|
606 | The new value of the user's comment field (gecos). |
---|
607 | |
---|
608 | -d home_dir |
---|
609 | The user's new login directory. |
---|
610 | |
---|
611 | -e expiration_date |
---|
612 | Set the expiration date for the user account. This only affect samba account. The date must be in the following format : YYYY-MM-DD HH:MM:SS. This option call the external 'date' command to set calculate the number of seconds from Junary 1 1970 to the specified date. |
---|
613 | |
---|
614 | -g initial_group |
---|
615 | The group name or number of the user's new initial login group. The group name must exist. A group number must refer to an already existing group. The default group number is 1. |
---|
616 | |
---|
617 | -G group,[...] |
---|
618 | A list of supplementary groups which the user is also a member of. Each group is separated from the next by a comma, with no intervening whitespace. The groups are subject to the same restrictions as the group given with the -g option. If the user is currently a member of a group which is not listed, the user will be removed from the group |
---|
619 | |
---|
620 | -l login_name |
---|
621 | The name of the user will be changed from login to login_name. Nothing else is changed. In particular, the user's home directory name should probably be changed to reflect the new login name. |
---|
622 | |
---|
623 | -s shell |
---|
624 | The name of the user's new login shell. Setting this field to blank causes the system to select the default login shell. |
---|
625 | |
---|
626 | -u uid |
---|
627 | The numerical value of the user's ID. This value must be unique, unless the -o option is used. The value must be non negative. Any files which the user owns and which are located in the directory tree rooted at the user's home directory will have the file user ID changed automatically. Files outside of the user's home directory must be altered manually. |
---|
628 | |
---|
629 | -r new_user |
---|
630 | Allow to rename a user. This option will update the cn, sn and dn attribute for the user. You can |
---|
631 | also update others attributes using the corresponding script options. |
---|
632 | |
---|
633 | -x |
---|
634 | Creates rid and primaryGroupID in hex instead of decimal (for Samba 2.2.2 unpatched only - higher versions always use decimal) |
---|
635 | |
---|
636 | -A |
---|
637 | can change password ? 0 if no, 1 if yes |
---|
638 | |
---|
639 | -B |
---|
640 | must change password ? 0 if no, 1 if yes |
---|
641 | |
---|
642 | -C |
---|
643 | sambaHomePath (SMB home share, like '\\\\PDC-SRV\\homes') |
---|
644 | |
---|
645 | -D |
---|
646 | sambaHomeDrive (letter associated with home share, like 'H:') |
---|
647 | |
---|
648 | -E |
---|
649 | sambaLogonScript, relative to the [netlogon] share (DOS script to execute on login, like 'foo.bat') |
---|
650 | |
---|
651 | -F |
---|
652 | sambaProfilePath (profile directory, like '\\\\PDC-SRV\\profiles\\foo') |
---|
653 | |
---|
654 | -H |
---|
655 | sambaAcctFlags, spaces and trailing bracket are ignored (samba account control bits like '[NDHTUMWSLKI]') |
---|
656 | |
---|
657 | -I |
---|
658 | disable user. Can't be used with -H or -J |
---|
659 | |
---|
660 | -J |
---|
661 | enable user. Can't be used with -H or -I |
---|
662 | |
---|
663 | -N |
---|
664 | set the canonical name (attribut cn) |
---|
665 | |
---|
666 | -S |
---|
667 | Set the surname |
---|
668 | |
---|
669 | -P |
---|
670 | End by invoking smbldap-passwd to change the user password (both unix and samba passwords) |
---|
671 | |
---|
672 | =head1 SEE ALSO |
---|
673 | |
---|
674 | usermod(1) |
---|
675 | |
---|
676 | =cut |
---|
677 | |
---|
678 | #' |
---|