Jump to content

Changing / adding attributes on LDAP ( 389-console) for all the UID's and Changing all password to one common password in Punjab's IFMS-IWDMS Project

From TetraWiki
Revision as of 12:35, 24 September 2015 by Biswajit (talk | contribs) (Created page with "category:Punjab's IFMS-IWDMS Project '''Problem''' : Add one Attribute "carLicense: 16777216 " to all or selected OU on LDAP Server of 389-console Referance - https://ww...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Problem : Add one Attribute "carLicense: 16777216 " to all or selected OU on LDAP Server of 389-console

Referance - https://www.centos.org/docs/5/html/CDS/ag/8.0/Creating_Directory_Entries-LDIF_Update_Statements.html

Step 1 - Create a file with all DN per line by following command. This command will fetch all the entries of dn from an OU "ou=IFMS,ou=People,dc=pbifmsiwdms,dc=pjb"

ldapsearch -x -D "cn=Directory Manager"   -w asd1234f  -b  ou=IFMS,ou=People,dc=pbifmsiwdms,dc=pjb -LLL  -s sub "(objectclass=*)" dn  > /tmp/biswajit.csv

The Above command will give truncated lines so better to use following command

ldapsearch -x -D "cn=Directory Manager"   -w asd1234f  -b  ou=IFMS,ou=People,dc=pbifmsiwdms,dc=pjb -LLL  -s sub "(objectclass=*)" dn |  perl -p00e 's/\r?\n //g'  > /tmp/biswajit.csv

Once you have got all the line in the a File ( called biswajit.csv ) then lines needs to be modified from

dn: uid=tcs1,ou=People,dc=pbifmsiwdms,dc=pjb
dn: uid=tcs3,ou=People,dc=pbifmsiwdms,dc=pjb
dn: uid=nobody,ou=People,dc=pbifmsiwdms,dc=pjb

to

dn: uid=tcs1,ou=People,dc=pbifmsiwdms,dc=pjb
changetype: modify
add: carLicense
carLicense: 16777216
-
dn: uid=tcs3,ou=People,dc=pbifmsiwdms,dc=pjb
changetype: modify
add: carLicense
carLicense: 16777216
-
dn: uid=nobody,ou=People,dc=pbifmsiwdms,dc=pjb
changetype: modify
add: carLicense
carLicense: 16777216
-

For achieving the above , please create a file ( say add.txt ) create /tmp/modify.txt file is

changetype: modify
add: carLicense
carLicense: 16777216

Then execute the following for introduce the additional line for add the attributes

sed -i '/dn: uid=/r /tmp/modify.txt' /tmp/biswajit.csv

file will look like

dn: uid=tcs1,ou=People,dc=pbifmsiwdms,dc=pjb
changetype: modify
add: carLicense
carLicense: 16777216

Now you can run the modify ldap command to add/change that attribute

ldapmodify -xvc -D"cn=Directory Manager"   -w asd1234f -f /tmp/biswajit.csv   >> /tmp/erro.ldif

Problem: Password Changing Via CLI on LDAP Server for all users

Referance https://www.centos.org/docs/5/html/CDS/ag/8.0/User_Account_Management-Managing_the_Password_Policy.html#Managing_the_Password_Policy-Setting_User_Passwords

Grep all the uid in a file by

ldapsearch -x -D "cn=Directory Manager"   -w asd1234f  -b  ou=IWDMS,ou=People,dc=pbifmsiwdms,dc=pjb -LLL  -s sub "(objectclass=*)" dn |  perl -p00e 's/\r?\n //g'  > /tmp/biswajit.csv

then grep only uid= by

cat /tmp/biswajit.csv | grep uid= > change_pass_uid.txt

Then modify the file to contain the following line format ( I have used libreoffice's calc to do it )


ldappasswd -h localhost -p 389 -ZZ -D "cn=Directory Manager" -w asd1234f -s pbGOVT#531 "uid=Administrator,ou=People,dc=pbifmsiwdms,dc=pjb"
ldappasswd -h localhost -p 389 -ZZ -D "cn=Directory Manager" -w asd1234f -s pbGOVT#531 "uid=tcs1,ou=People,dc=pbifmsiwdms,dc=pjb"
ldappasswd -h localhost -p 389 -ZZ -D "cn=Directory Manager" -w asd1234f -s pbGOVT#531 "uid=tcs3,ou=People,dc=pbifmsiwdms,dc=pjb"
ldappasswd -h localhost -p 389 -ZZ -D "cn=Directory Manager" -w asd1234f -s pbGOVT#531 "uid=nobody,ou=People,dc=pbifmsiwdms,dc=pjb"
ldappasswd -h localhost -p 389 -ZZ -D "cn=Directory Manager" -w asd1234f -s pbGOVT#531 "uid=PBEMP50,ou=People,dc=pbifmsiwdms,dc=pjb"
ldappasswd -h localhost -p 389 -ZZ -D "cn=Directory Manager" -w asd1234f -s pbGOVT#531 "uid=PBEMP51,ou=People,dc=pbifmsiwdms,dc=pjb"
ldappasswd -h localhost -p 389 -ZZ -D "cn=Directory Manager" -w asd1234f -s pbGOVT#531 "uid=pbemp52,ou=People,dc=pbifmsiwdms,dc=pjb"
ldappasswd -h localhost -p 389 -ZZ -D "cn=Directory Manager" -w asd1234f -s pbGOVT#531 "uid=pbemp53,ou=People,dc=pbifmsiwdms,dc=pjb"
ldappasswd -h localhost -p 389 -ZZ -D "cn=Directory Manager" -w asd1234f -s pbGOVT#531 "uid=pbemp54,ou=People,dc=pbifmsiwdms,dc=pjb"

Run this on the root login shell . check for errors if any