3 ## Convert an LDIF file containing sambaAccount entries
4 ## to the new sambaSamAccount objectclass
6 ## Copyright Gerald (Jerry) Carter 2003
8 ## Usage: convertSambaAccount <Domain SID> <input ldif> <output ldif>
15 my ( $domain, $domsid );
17 my ( $entry, @objclasses, $obj );
18 my ( $is_samba_account );
19 my ( %attr_map, $key );
22 print "Usage: convertSambaAccount domain_sid input_ldif output_ldif\n";
27 lmPassword
=> 'sambaLMPassword',
28 ntPassword
=> 'sambaNTPassword',
29 pwdLastSet
=> 'sambaPwdLastSet',
30 pwdMustChange
=> 'sambaPwdMustChange',
31 pwdCanChange
=> 'sambaPwdCanChange',
32 homeDrive
=> 'sambaHomeDrive',
33 smbHome
=> 'sambaHomePath',
34 scriptPath
=> 'sambaLogonScript',
35 profilePath
=> 'sambaProfilePath',
36 kickoffTime
=> 'sambaKickoffTime',
37 logonTime
=> 'sambaLogonTime',
38 logoffTime
=> 'sambaLogoffTime',
39 userWorkstations
=> 'sambaUserWorkstations',
40 domain
=> 'sambaDomainName',
41 acctFlags
=> 'sambaAcctFlags',
46 $ldif = Net
::LDAP
::LDIF
->new ($ARGV[1], "r")
48 $ldif2 = Net
::LDAP
::LDIF
->new ($ARGV[2], "w")
51 while ( !$ldif->eof ) {
53 $entry = $ldif->read_entry();
55 ## skip entry if we find an error
56 if ( $ldif->error() ) {
57 print "Error msg: ",$ldif->error(),"\n";
58 print "Error lines:\n",$ldif->error_lines(),"\n";
63 ## check to see if we have anything to do on this
64 ## entry. If not just write it out
66 @objclasses = $entry->get_value( "objectClass" );
67 undef ( $is_samba_account );
68 foreach $obj ( @objclasses ) {
69 if ( "$obj" eq "sambaAccount" ) {
70 $is_samba_account = 1;
74 if ( !defined ( $is_samba_account ) ) {
75 $ldif2->write_entry( $entry );
80 ## start editing the sambaAccount
83 $entry->delete( 'objectclass' => [ 'sambaAccount' ] );
84 $entry->add( 'objectclass' => 'sambaSamAccount' );
86 $entry->add( 'sambaSID' => $domsid."-".$entry->get_value( "rid" ) );
87 $entry->delete( 'rid' );
89 if ( $entry->get_value( "primaryGroupID" ) ) {
90 $entry->add( 'sambaPrimaryGroupSID' => $domsid."-".$entry->get_value( "primaryGroupID" ) );
91 $entry->delete( 'primaryGroupID' );
95 foreach $key ( keys %attr_map ) {
96 if ( $entry->get_value($key) ) {
97 $entry->add( $attr_map{$key} => $entry->get_value($key) );
98 $entry->delete( $key );
102 $ldif2->write_entry( $entry );