diff options
author | Jukka Rissanen <jukka.rissanen@linux.intel.com> | 2012-05-03 16:15:08 +0300 |
---|---|---|
committer | Patrik Flykt <patrik.flykt@linux.intel.com> | 2012-05-04 12:51:03 +0300 |
commit | a5f540db7354b76bcabd0a05d8eb8ba2bff4e911 (patch) | |
tree | ada94fd27c9029eb28c8c66713b4fa53b58d27ae /plugins | |
parent | 26ace5c59f790bce0f1988b88874c6f2c480fd5a (diff) | |
download | connman-a5f540db7354b76bcabd0a05d8eb8ba2bff4e911.tar.gz connman-a5f540db7354b76bcabd0a05d8eb8ba2bff4e911.tar.bz2 connman-a5f540db7354b76bcabd0a05d8eb8ba2bff4e911.zip |
loopback: Check hostname/domainname validity
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/loopback.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/plugins/loopback.c b/plugins/loopback.c index 1800c490..a111eeed 100644 --- a/plugins/loopback.c +++ b/plugins/loopback.c @@ -39,6 +39,7 @@ #include <connman/plugin.h> #include <connman/utsname.h> #include <connman/log.h> +#include <connman/inet.h> static in_addr_t loopback_address; static in_addr_t loopback_netmask; @@ -206,12 +207,21 @@ static const char *loopback_get_hostname(void) static int loopback_set_hostname(const char *hostname) { - int err; + const char *ptr; + int err, len; if (g_strcmp0(hostname, "<hostname>") == 0) return 0; - if (sethostname(hostname, strlen(hostname)) < 0) { + len = strlen(hostname); + + if (connman_inet_check_hostname(hostname, len) == FALSE) + return -EINVAL; + + if ((ptr = strstr(hostname, ".")) != NULL) + len = ptr - hostname; + + if (sethostname(hostname, len) < 0) { err = -errno; connman_error("Failed to set hostname to %s", hostname); return err; @@ -224,9 +234,14 @@ static int loopback_set_hostname(const char *hostname) static int loopback_set_domainname(const char *domainname) { - int err; + int err, len; + + len = strlen(domainname); + + if (connman_inet_check_hostname(domainname, len) == FALSE) + return -EINVAL; - if (setdomainname(domainname, strlen(domainname)) < 0) { + if (setdomainname(domainname, len) < 0) { err = -errno; connman_error("Failed to set domainname to %s", domainname); return err; |