Migrate an LDIF from RFC 2307 to RFC 2307bis, ie the schema used in 389-ds 1.3.x to 1.4+.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BEGIN {} | |
/dn: uid=.*,ou=People,dc=ilri,dc=cgiar,dc=org/ { | |
print "# User migrated to RFC 2307bis"; | |
# Keep getting the next line until we have a blank one (which means this | |
# user's LDIF entry is finished). | |
while ($0 !~ /^$/) { | |
# Lines to update or remove. I comment them out by printing a hash and | |
# "&", which is a special awk syntax to print the pattern that matched. | |
switch($0) { | |
case /^objectClass: person/: | |
sub(/^objectClass: person/, "objectClass: nsPerson"); | |
# Print the line as it is after substitution | |
print; | |
# Break out of the switch statement | |
break; | |
case /^objectClass: organizationalPerson/: | |
sub(/^objectClass: organizationalPerson/, "objectClass: nsAccount"); | |
print; | |
break; | |
case /^objectClass: inetorgperson/: | |
sub(/^objectClass: inetorgperson/, "objectClass: nsOrgPerson"); | |
print; | |
break; | |
# givenName is not allowed | |
case /^givenName: .*/: | |
sub(/^givenName: .*/, "#&"); | |
print; | |
break; | |
# sn is not allowed | |
case /^sn: .*/: | |
sub(/^sn: .*/, "#&"); | |
print; | |
break; | |
# When we see a cn, copy the value to displayName and then print both | |
case /^cn: .*/: | |
displayName = gensub(/^cn: (.*)/, "displayName: \\1", "g", $0); | |
print; | |
print displayName; | |
break; | |
default: | |
print; | |
} | |
# Read the next record (aka line) immediately, which effectively runs the line | |
# through the switch cases again. Exit if we have reached the end of the file. | |
if (getline <= 0) { | |
exit; | |
} | |
} | |
} | |
# TODO: memberUid to member | |
/dn: cn=.*,ou=Groups,dc=ilri,dc=cgiar,dc=org/ { | |
print "# Group migrated to RFC 2307bis"; | |
while ($0 !~ /^$/) { | |
switch($0) { | |
case /^objectClass: groupofuniquenames/: | |
sub(/^objectClass: groupofuniquenames/, "objectClass: groupOfNames"); | |
print; | |
break; | |
case /^objectClass: posixgroup/: | |
sub(/^objectClass: posixgroup/, "objectClass: posixGroup"); | |
print; | |
print "objectClass: nsMemberOf"; | |
break; | |
default: | |
print; | |
} | |
if (getline <= 0) { | |
exit; | |
} | |
} | |
} | |
# Match and print all other lines in the LDIF | |
{ print } | |
END {} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment