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