aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorkremlin <ian@kremlin.cc>2014-08-16 03:47:55 +0800
committerkremlin <ian@kremlin.cc>2014-08-16 03:47:55 +0800
commit3ccecdd66ce8503f958d2bd34abca7219a13b14d (patch)
tree6ecca8af6e068951cf15885e2288415914b0bb00
parent904d744df98f63a70ec8832764bdfba1adda073a (diff)
downloadsystembsd-3ccecdd66ce8503f958d2bd34abca7219a13b14d.tar
systembsd-3ccecdd66ce8503f958d2bd34abca7219a13b14d.tar.gz
systembsd-3ccecdd66ce8503f958d2bd34abca7219a13b14d.tar.bz2
systembsd-3ccecdd66ce8503f958d2bd34abca7219a13b14d.tar.lz
systembsd-3ccecdd66ce8503f958d2bd34abca7219a13b14d.tar.xz
systembsd-3ccecdd66ce8503f958d2bd34abca7219a13b14d.tar.zst
systembsd-3ccecdd66ce8503f958d2bd34abca7219a13b14d.zip
polish hostname setter func, fix logic issues with prop
handle_set_hostname works almost perfectly (still needs polkit auth checking). returns logical D-Bus errors and sets hostname property correctly now.
-rw-r--r--src/interfaces/hostnamed/hostnamed.c43
1 files changed, 31 insertions, 12 deletions
diff --git a/src/interfaces/hostnamed/hostnamed.c b/src/interfaces/hostnamed/hostnamed.c
index 19a196c..7d2fbc6 100644
--- a/src/interfaces/hostnamed/hostnamed.c
+++ b/src/interfaces/hostnamed/hostnamed.c
@@ -120,9 +120,8 @@ on_handle_set_hostname(Hostname1 *hn1_passed_interf,
GVariant *params;
gchar *proposed_hostname, *valid_hostname_buf;
gboolean policykit_auth, ret;
- size_t check_length, bad_length;
+ size_t check_length;
- bad_length = MAXHOSTNAMELEN + 1;
proposed_hostname = NULL;
ret = FALSE;
@@ -131,15 +130,22 @@ on_handle_set_hostname(Hostname1 *hn1_passed_interf,
if(proposed_hostname && (valid_hostname_buf = g_hostname_to_ascii(proposed_hostname))) {
- check_length = strnlen(proposed_hostname, bad_length);
+ check_length = strnlen(proposed_hostname, MAXHOSTNAMELEN + 1);
- if(check_length < bad_length && !sethostname(proposed_hostname, check_length))
- ret = TRUE;
- }
+ if(check_length > MAXHOSTNAMELEN)
+ g_dbus_method_invocation_return_dbus_error(invoc, "org.freedesktop.hostname1.Error.ENAMETOOLONG", "Hostname string exceeded maximum length.");
- if(ret)
- hostname1_complete_set_hostname(hn1_passed_interf, invoc);
+ else if(sethostname(proposed_hostname, check_length))
+ g_dbus_method_invocation_return_dbus_error(invoc, "org.freedesktop.hostname1.Error.EACCES", "Insufficient permissions to change hostname.");
+ else {
+ HOSTNAME = proposed_hostname;
+ hostname1_set_hostname(hn1_passed_interf, HOSTNAME);
+ ret = TRUE;
+ hostname1_complete_set_hostname(hn1_passed_interf, invoc);
+ }
+ }
+
if(proposed_hostname)
g_free(proposed_hostname);
if(valid_hostname_buf)
@@ -189,21 +195,34 @@ on_handle_set_icon_name(Hostname1 *hn1_passed_interf,
const gchar *
our_get_hostname() {
- if(HOSTNAME)
+ gchar *hostname_buf;
+ hostname_buf = (gchar *)g_malloc0(MAXHOSTNAMELEN);
+
+ if(gethostname(hostname_buf, MAXHOSTNAMELEN))
+ return "localhost.home.network"; /* TODO bomb out here probably */
+
+ else if(!g_strcmp0(HOSTNAME, hostname_buf)) {
+
+ g_free(hostname_buf);
return HOSTNAME;
+ }
+
+ g_ptr_array_add(hostnamed_freeable, hostname_buf);
+ HOSTNAME = hostname_buf;
+ hostname1_set_hostname(hostnamed_interf, HOSTNAME);
- return "localhost";
+ return HOSTNAME;
}
const gchar *
our_get_static_hostname() {
- if(STATIC_HOSTNAME)
+ if(STATIC_HOSTNAME && g_strcmp0(STATIC_HOSTNAME, ""))
return STATIC_HOSTNAME;
else if(HOSTNAME)
return HOSTNAME;
- return "localhost";
+ return "localhost.home.network";
}
const gchar *