This commit is contained in:
Jephté Clain 2015-04-16 12:36:00 +04:00
parent ba3798febe
commit 00088b30b2
1 changed files with 106 additions and 106 deletions

View File

@ -13,7 +13,7 @@ function def_match_attr() {
return attr \":\" return attr \":\"
} }
function norm_attr(attr) { function norm_attr(attr) {
return tolower(attr) return tolower(attr)
} }
function match_attr(attr) { function match_attr(attr) {
attr = tolower(attr) attr = tolower(attr)
@ -88,7 +88,7 @@ BEGIN {
} }
END { END {
if (inline) print line if (inline) print line
} }
' '
} }
@ -170,23 +170,23 @@ END { dump_ldif() }
function tl_addattr() { function tl_addattr() {
awk ' awk '
/^dn:/ { /^dn:/ {
lastattr = "" lastattr = ""
dn = $0 dn = $0
next next
} }
{ {
attr = $1 attr = $1
if (attr != "") { if (attr != "") {
if (dn != "") { if (dn != "") {
print dn print dn
print "changetype: add" print "changetype: add"
dn = "" dn = ""
}
sub(/:+$/, "", attr)
} }
print sub(/:+$/, "", attr)
lastattr = attr }
print
lastattr = attr
} }
' '
} }
@ -195,33 +195,33 @@ function tl_modifyattr() {
local modtype="$1" local modtype="$1"
awkrun modtype="$modtype" ' awkrun modtype="$modtype" '
/^dn:/ { /^dn:/ {
lastattr = "" lastattr = ""
dn = $0 dn = $0
next next
} }
{ {
attr = $1 attr = $1
if (attr == "") { if (attr == "") {
if (lastattr != "") { if (lastattr != "") {
print "-" print "-"
}
} else {
if (dn != "") {
print dn
print "changetype: modify"
dn = ""
}
sub(/:+$/, "", attr)
if (lastattr != attr) {
if (lastattr != "") {
print "-"
}
print modtype ": " attr
}
} }
print } else {
lastattr = attr if (dn != "") {
print dn
print "changetype: modify"
dn = ""
}
sub(/:+$/, "", attr)
if (lastattr != attr) {
if (lastattr != "") {
print "-"
}
print modtype ": " attr
}
}
print
lastattr = attr
} }
' '
} }
@ -229,33 +229,33 @@ function tl_modifyattr() {
function tl_deleteattr() { function tl_deleteattr() {
awk ' awk '
/^dn:/ { /^dn:/ {
lastattr = "" lastattr = ""
dn = $0 dn = $0
next next
} }
{ {
attr = $1 attr = $1
if (attr == "") { if (attr == "") {
if (lastattr != "") { if (lastattr != "") {
print "-" print "-"
print print
}
} else {
if (dn != "") {
print dn
print "changetype: modify"
dn = ""
}
sub(/:+$/, "", attr)
if (lastattr != attr) {
if (lastattr != "") {
print "-"
}
print "delete: " attr
}
} }
lastattr = attr } else {
if (dn != "") {
print dn
print "changetype: modify"
dn = ""
}
sub(/:+$/, "", attr)
if (lastattr != attr) {
if (lastattr != "") {
print "-"
}
print "delete: " attr
}
}
lastattr = attr
} }
' '
} }
@ -263,11 +263,11 @@ function tl_deleteattr() {
function tl_deleteentry() { function tl_deleteentry() {
awk ' awk '
/^dn:/ { /^dn:/ {
dn = $0 dn = $0
print dn print dn
print "changetype: delete" print "changetype: delete"
print "" print ""
next next
} }
' '
} }
@ -275,11 +275,11 @@ function tl_deleteentry() {
function tl_touchentry() { function tl_touchentry() {
awk ' awk '
/^dn:/ { /^dn:/ {
dn = $0 dn = $0
print dn print dn
print "changetype: modify" print "changetype: modify"
print "" print ""
next next
} }
' '
} }
@ -288,7 +288,7 @@ function tl_keepattr() {
local match_attr="$1" local match_attr="$1"
awk "$match_attr"' awk "$match_attr"'
$0 == "" || match_attr($1) { $0 == "" || match_attr($1) {
print print
} }
' '
} }
@ -447,11 +447,11 @@ add && match_attr($1) {
print_values() print_values()
} }
add && $0 == "" { add && $0 == "" {
print_values() print_values()
} }
{ print } { print }
END { END {
if (add) print_values() if (add) print_values()
} }
' '
awk "$script" awk "$script"
@ -496,7 +496,7 @@ add && $0 == "" {
} }
{ print } { print }
END { END {
if (add && !found) print_values() if (add && !found) print_values()
} }
' '
awk "$script" awk "$script"
@ -584,28 +584,28 @@ function tl_decode() {
local match_attr="$1" local match_attr="$1"
awkrun -f "$match_attr"' awkrun -f "$match_attr"'
function split_base64(text, result) { function split_base64(text, result) {
result = "" result = ""
while (text != "") { while (text != "") {
if (result != "") result = result "\n" if (result != "") result = result "\n"
result = result substr(text, 1, 64) result = result substr(text, 1, 64)
text = substr(text, 65) text = substr(text, 65)
} }
return result return result
} }
/^[^:]+:: / && match_attr($1) { /^[^:]+:: / && match_attr($1) {
name = $0; sub(/::.*$/, "", name) name = $0; sub(/::.*$/, "", name)
value = $0; sub(/^[^:]+:: /, "", value) value = $0; sub(/^[^:]+:: /, "", value)
decoded_value = b64decode(value) decoded_value = b64decode(value)
#cmd = "echo '\''" split_base64(value) "'\'' | openssl base64 -d" #cmd = "echo '\''" split_base64(value) "'\'' | openssl base64 -d"
#decoded_value = "" #decoded_value = ""
#while ((cmd | getline line) > 0) { #while ((cmd | getline line) > 0) {
# decoded_value = decoded_value line # decoded_value = decoded_value line
#} #}
#close(cmd) #close(cmd)
print name ": " decoded_value print name ": " decoded_value
next next
} }
{ print } { print }
' '
@ -615,23 +615,23 @@ function tl_encode() {
local match_attr="$1" local match_attr="$1"
awkrun "$match_attr"' awkrun "$match_attr"'
function quote(text) { function quote(text) {
# remplacer les quotes par le caractere echappement approprie # remplacer les quotes par le caractere echappement approprie
gsub('"/'/, \"'\\\\''\""', text) gsub('"/'/, \"'\\\\''\""', text)
return text return text
} }
/^[^:]+: / && match_attr($1) { /^[^:]+: / && match_attr($1) {
name = $0; sub(/:.*$/, "", name) name = $0; sub(/:.*$/, "", name)
value = $0; sub(/^[^:]+: /, "", value) value = $0; sub(/^[^:]+: /, "", value)
cmd = "echo '\''" quote(value) "'\'' | openssl base64" cmd = "echo '\''" quote(value) "'\'' | openssl base64"
coded_value = "" coded_value = ""
while ((cmd | getline line) > 0) { while ((cmd | getline line) > 0) {
coded_value = coded_value line coded_value = coded_value line
} }
close(cmd) close(cmd)
print name ":: " coded_value print name ":: " coded_value
next next
} }
{ print } { print }
' '