This patch fixes a bug which prevents ddns-scripts, which I wrote about a year 
ago, from working properly on big-endian systems. Fixes ticket #4294

Specifically, this fixes a defect in the shell_get script. An alternative 
strategy would be to remove shell_get altogether, as newer versions of busybox 
now support basic password authorization.  However, fixing the defect by merely 
patching the shell_get script, as I do in this patch, allows for backwards 
compatibility with older versions of openwrt/busybox, so I chose that approach.

Signed-off-by: Eric Bishop <ebis...@bu.edu>

Index: net/ddns-scripts/files/usr/lib/ddns/shell_get.sh
===================================================================
--- net/ddns-scripts/files/usr/lib/ddns/shell_get.sh    (revision 14082)
+++ net/ddns-scripts/files/usr/lib/ddns/shell_get.sh    (working copy)
@@ -33,8 +33,8 @@
 {
        original_str=$1
        
-       hex_str=$( echo -n "$original_str" | hexdump -v | awk '{ for ( i = 2; i 
<= NF; i++ ) {  h1=substr($i, 3, 2); h2=substr($i,0,2); printf("%s%s", h1, h2); 
}}' | awk ' { $0~gsub(/00$/, "") };{ i=1; while(i <= length($0) ){ block= 
substr($0, i, 3); printf("%s ", block); i=i+3;  }}' | awk ' {$0~gsub(/ $/, 
"")}; { print $0 }' )
-
+       
+       hex_str=$( echo -n "$original_str" | hexdump -v -e '1/1 "%02x"'  )
        length=$(echo $hex_str | awk  '{$0~gsub(/ /, "")}; { print length($0) 
}')
        remainder=$(($length % 3 ))
        if [ $remainder -eq 1 ]; then
@@ -42,10 +42,10 @@
        elif [ $remainder -eq 2 ]; then
                hex_str=$hex_str'0'
        fi
+       hex_str=$( echo -n "$hex_str" | awk ' { i=1; while(i <= length($0) ){ 
block= substr($0, i, 3); printf("%s ", block); i=i+3;  }}' )
 
 
 
-
        base_64_str=""
        for hex_block in $hex_str
        do
@@ -85,6 +85,7 @@
 
 
        user_pass=$(echo $full_url | awk ' BEGIN {FS="@"}; { if( $0~/@/ && 
$1~/^[^\?\/]+:[^\?\/]+$/ ) print $1 }')
+       
        host_and_args=""
        if [ -n "$user_pass" ]; then
                host_and_args=$(echo $full_url | awk ' $0~gsub(/^...@]+@/, "") 
{print $0}')
@@ -112,15 +113,15 @@
        retrieved_data=""
        if [ -n "$user_pass" ]; then
                auth_str=$(encode_base64 "$user_pass" )
-               #echo -e "GET $path HTTP/1.0\nHost: $host_name\nAuthorization: 
Basic $auth_str\nUser-Agent: shell_get 1.0\n\n"
-               retrieved_data=$(echo -e "GET $path HTTP/1.0\nHost: 
$host_name\nAuthorization: Basic $auth_str\nUser-Agent: shell_get 1.0\n\n" | nc 
"$host_name" $port_num | cat)
+               #printf "GET $path HTTP/1.0\nHost: $host_name\nAuthorization: 
Basic $auth_str\nUser-Agent: shell_get 1.0\n\n"
+               retrieved_data=$(printf "GET $path HTTP/1.0\nHost: 
$host_name\nAuthorization: Basic $auth_str\nUser-Agent: shell_get 1.0\n\n" | nc 
"$host_name" $port_num | cat)
 
        else
-               #echo -e "GET $path HTTP/1.0\nHost: $host_name\nUser-Agent: 
shell_get 1.0\n\n"
-               retrieved_data=$(echo -e "GET $path HTTP/1.0\nHost: 
$host_name\nUser-Agent: shell_get 1.0\n\n" | nc "$host_name" $port_num | cat)
+               #printf "GET $path HTTP/1.0\nHost: $host_name\nUser-Agent: 
shell_get 1.0\n\n"
+               retrieved_data=$(printf "GET $path HTTP/1.0\nHost: 
$host_name\nUser-Agent: shell_get 1.0\n\n" | nc "$host_name" $port_num | cat)
        fi
 
-       echo -e "$retrieved_data"
+       printf "$retrieved_data"
 
 }
 
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
http://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to