Commit 57bb3db2 authored by Yuanle Song's avatar Yuanle Song
Browse files

check config file is valid after sourcing it.

parent a3a87c05
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -17,6 +17,7 @@ UPDATE_NOCHG=5
FATAL_ERROR_EXISTS=6
BAD_IP_ADDRESS=7
NO_CONF=50
BAD_CONF=51

# stores responses from remote DDNS provider's server.  usually it will be
# very short, like a word or two. but if there is a server error, it could be
@@ -53,6 +54,22 @@ fatal_err() {
# which host to update and it's credentials.
if [ -f "$CONFIG_FILE" ]; then
	. "$CONFIG_FILE"

	# check that config file is valid.
	msgs=""
	if [ -z "$HOSTNAME" -o -z "$USERNAME" -o -z "$PASSWORD" ]; then
		msg=$msg"Error: HOSTNAME, USERNAME, or PASSWORD is not set.\n"
	fi
	if [ `echo -n "$USERNAME" | wc -m` -gt 24 ]; then
		msg=$msg"Error: USERNAME should be less than 24 characters.\n"
	fi
	if [ `echo -n "$PASSWORD" | wc -m` -gt 24 ]; then
		msg=$msg"Error: PASSWORD should be less than 24 characters.\n"
	fi
	if [ -n "$msg" ]; then
		fatal_err `printf "Error: Bad config file. $msg"`
		exit $BAD_CONF
	fi
else
	err "Error: No config file found at $CONFIG_FILE."
	exit $NO_CONF