Skip to content

Commit

Permalink
Synchronise easytls-tctip.lib with scripts
Browse files Browse the repository at this point in the history
Signed-off-by: Richard T Bonhomme <[email protected]>
  • Loading branch information
TinCanTech committed Dec 12, 2021
1 parent 0c9267a commit ac05a2b
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 22 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ easypfp
easytls-script.conf
easytls-server.pid
easytls-*.vars
copy-tcpip.sh
ia-*.*
et-tdir*/*
noca/*
Expand Down
39 changes: 18 additions & 21 deletions easytls
Original file line number Diff line number Diff line change
Expand Up @@ -5187,7 +5187,7 @@ expand_ip6_address ()
temp_valid_hextets="${temp_valid_hextets#*:}"
hex_count=$(( hex_count - 1 ))
done
# Save "The violence inherant in the system"
# Save "The violence inherent in the system"
unset -v hex_count delim
verbose_easytls_tctip_lib "full_valid_hextets: ${full_valid_hextets}"

Expand Down Expand Up @@ -5236,6 +5236,8 @@ expand_ip6_address ()
# Return full_valid_hextets full_subnet_addr6
} # => expand_ip6_address ()

#=# b66633f8-3746-436a-901f-29638199b187

# Validate IPv4 data
validate_ip4_data ()
{
Expand All @@ -5245,6 +5247,8 @@ validate_ip4_data ()
# Syntax
case "${temp_ip_addr}" in
*[!0123456789./]* | .* | *. | *..* | */*.* ) return 11 ;;
*.*.*.* ) : ;; #OK
* ) return 1 ;;
esac

# Netmask
Expand All @@ -5267,7 +5271,7 @@ validate_ip4_data ()
unset -v mask_dec imsk_dec

# Address
unset -v valid_octets octet_delim
unset -v valid_octets delim
i=0
while [ -n "${temp_ip_addr}" ]; do
i=$(( i + 1 ))
Expand All @@ -5283,8 +5287,8 @@ validate_ip4_data ()
return 15
fi

valid_octets="${valid_octets}${octet_delim}${octet}"
octet_delim='.'
valid_octets="${valid_octets}${delim}${octet}"
delim='.'

# Break after last octet
[ "${temp_ip_addr}" != "${temp_ip_addr#*.}" ] || break
Expand All @@ -5294,7 +5298,7 @@ validate_ip4_data ()
done
# *.*.*.* four octets?
[ ${i} -eq 4 ] || return 16
unset -v temp_ip_addr octet_delim octet i
unset -v temp_ip_addr delim octet i

# Valid IPv4 to decimal
ip2dec "${valid_octets}" || return 19
Expand Down Expand Up @@ -5343,7 +5347,7 @@ validate_ip6_data ()
valid_mask_len="${mask_len}"

# Address
unset -v valid_hextets hextet_delim
unset -v valid_hextets delim
i=0
while [ -n "${temp_ip_addr}" ]; do
i=$(( i + 1 ))
Expand All @@ -5356,34 +5360,26 @@ validate_ip6_data ()
# Does not count as double_colon
[ ! $lead_colon ] || return 19
lead_colon=1
hextet=:
hextet=":"
else
# right-hand colon in '::'
# The left-hand colon was stripped with the last hextet
[ ! $double_colon ] || return 17
double_colon=1
hextet=":"
unset -v hextet_delim
unset -v delim
fi
fi

# Left to right
temptet=${temp_ip_addr%%:*}
hextet=${hextet:-${temptet}}
temptet="${temp_ip_addr%%:*}"
hextet="${hextet:-${temptet}}"
unset -v temptet

if [ "${hextet}" = ":" ]; then
# OK
:
else
# Normal hextet
# Leading zero
if [ "${hextet}" != "${hextet#0}" ]; then
[ "${hextet}" = "0" ] || {
return 14
}
fi

# Range: 0 < hextet < 65535
if [ 0 -gt $(( 0x${hextet} )) ] || [ $(( 0x${hextet} )) -gt 65535 ]
then
Expand All @@ -5392,8 +5388,8 @@ validate_ip6_data ()
fi

[ $lead_colon ] && [ ${i} -eq 1 ] && unset -v hextet
valid_hextets="${valid_hextets}${hextet_delim}${hextet}"
hextet_delim=':'
valid_hextets="${valid_hextets}${delim}${hextet}"
delim=':'

# Break after last hextet
[ "${temp_ip_addr}" != "${temp_ip_addr#*:}" ] || break
Expand All @@ -5408,7 +5404,8 @@ validate_ip6_data ()
else
[ ${i} -eq 8 ] || return 16
fi
unset -v temp_ip_addr hextet_delim hextet i double_colon lead_colon
# Save the atmosphere
unset -v temp_ip_addr delim hextet i double_colon lead_colon
# shellcheck disable=SC2034
full_valid_ip6_addr="${valid_hextets}/${valid_mask_len}"
# Return: valid_hextets ; valid_mask_len ; full_valid_ip6_addr
Expand Down
2 changes: 1 addition & 1 deletion easytls-client-connect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ expand_ip6_address ()
temp_valid_hextets="${temp_valid_hextets#*:}"
hex_count=$(( hex_count - 1 ))
done
# Save "The violence inherant in the system"
# Save "The violence inherent in the system"
unset -v hex_count delim
verbose_easytls_tctip_lib "full_valid_hextets: ${full_valid_hextets}"

Expand Down

1 comment on commit ac05a2b

@TinCanTech
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.