diff options
author | kremlin <ian@kremlin.cc> | 2014-06-08 14:19:46 +0800 |
---|---|---|
committer | kremlin <ian@kremlin.cc> | 2014-06-08 14:19:46 +0800 |
commit | 929eb2a9b45b11b5e3d76f1d4ac744853b7ab2fe (patch) | |
tree | 0e5b63a087995ced6a05473084c4893fd5bdf7ce /src/main.h | |
parent | faab2eee0d3cdd778fef60dd7d9e8976a001a1b8 (diff) | |
download | systembsd-929eb2a9b45b11b5e3d76f1d4ac744853b7ab2fe.tar systembsd-929eb2a9b45b11b5e3d76f1d4ac744853b7ab2fe.tar.gz systembsd-929eb2a9b45b11b5e3d76f1d4ac744853b7ab2fe.tar.bz2 systembsd-929eb2a9b45b11b5e3d76f1d4ac744853b7ab2fe.tar.lz systembsd-929eb2a9b45b11b5e3d76f1d4ac744853b7ab2fe.tar.xz systembsd-929eb2a9b45b11b5e3d76f1d4ac744853b7ab2fe.tar.zst systembsd-929eb2a9b45b11b5e3d76f1d4ac744853b7ab2fe.zip |
started work on xml file installation/configuration
Diffstat (limited to 'src/main.h')
-rw-r--r-- | src/main.h | 121 |
1 files changed, 72 insertions, 49 deletions
@@ -1,51 +1,74 @@ #include <gio/gio.h> +#include "xml_defs.h" -#ifdef NO BUILTIN XML -//TODO install conf -#endif - -#ifndef NO_BUILTIN_XML -gchar **hostnamed_config_xml = -"<!DOCTYPE busconfig PUBLIC" -" \"-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN\"" -" \"http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd\">" -"<busconfig>" -" <!-- Only members of 'wheel' and user 'daemon' may set hostnames -->" -" <policy group=\"wheel\">" -" <allow own=\"org.freedesktop.hostname1\"/>" -" <allow send_destination=\"org.freedesktop.hostname1\"/>" -" <allow receive_sender=\"org.freedesktop.hostname1\"/>" -" </policy>" -" <policy user=\"daemon\">" -" <allow own=\"org.freedesktop.hostname1\"/>" -" <allow send_destination=\"org.freedesktop.hostname1\"/>" -" <allow receive_sender=\"org.freedesktop.hostname1\"/>" -" </policy>" -"</busconfig>"; - -gchar **hostnamed_ispect_xml = -"<!-- Taken from Gentoo Linux's OpenRC settingsd -->" -"<node name=\"/org/freedesktop/hostname1\">" -" <interface name=\"org.freedesktop.hostname1\">" -" <method name=\"SetHostname\">" -" <arg direction=\"in\" type=\"s\" name=\"name\"/>" -" <arg direction=\"in\" type=\"b\" name=\"user_interaction\"/>" -" </method>" -" <method name=\"SetStaticHostname\">" -" <arg direction=\"in\" type=\"s\" name=\"name\"/>" -" <arg direction=\"in\" type=\"b\" name=\"user_interaction\"/>" -" </method>" -" <method name=\"SetPrettyHostname\">" -" <arg direction=\"in\" type=\"s\" name=\"name\"/>" -" <arg direction=\"in\" type=\"b\" name=\"user_interaction\"/>" -" </method>" -" <method name=\"SetIconName\">" -" <arg direction=\"in\" type=\"s\" name=\"name\"/>" -" <arg direction=\"in\" type=\"b\" name=\"user_interaction\"/>" -" </method>" -" <property name=\"Hostname\" type=\"s\" access=\"read\"/>" -" <property name=\"StaticHostname\" type=\"s\" access=\"read\"/>" -" <property name=\"PrettyHostname\" type=\"s\" access=\"read\"/>" -" <property name=\"IconName\" type=\"s\" access=\"read\"/>" -" </interface>" -"</node>"; +//expects valid input, always free() output +const gchar **get_prefixs(gchar *path, gchar *dname) { + gsize size = sizeof(path) + sizeof(dname) + 11; //11 extra bytes for file suffix + const gchar **ret = (gchar**) g_malloc0(2 * size); + + g_snprintf(ret[0], size, "%s%s-ispect.xml", path, dname); + g_snprintf(ret[1], size, "%s%s-config.xml", path, dname); + + return ret; +} + +const GString *strjoin(gchar *sep, GString strings[]) { + GString *cur; + GString *out; + gint n; + + while((cur = &strings[n]) != NULL) { + g_string_append(out, cur); + n++; + } + + return out; +} + +gboolean install_conf() { + gchar *our_conf_uri = "systemd-utl/xml-conf/"; + gchar **data_dir = g_get_system_data_dirs(); + + if(g_strcmp0(data_dir[0], NULL)) { + const gchar our_conf_path[256]; + g_snprintf(our_conf_path, sizeof our_conf_path, "%s%s", *data_dir, our_conf_uri); + GError **errors; + + /*TODO permissions w/ this */ + g_mkdir_with_parents(our_conf_path, 0644); + + const gchar **hostnamed_prefixs = get_prefixs(our_conf_path, "hostnamed"); + const GString *hostnamed_ispect_xml = strjoin("\n", hostnamed_ispect_xml_def); + const GString *hostnamed_config_xml = strjoin("\n", hostnamed_config_xml_def); + + const gchar **timedated_prefixs = get_prefixs(our_conf_path, "timedated"); + const GString *timedated_ispect_xml = strjoin("\n", timedated_ispect_xml_def); + const GString *timedated_config_xml = strjoin("\n", timedated_config_xml_def); + + const gchar **localed_prefixs = get_prefixs(our_conf_path, "localed"); + const GString *localed_ispect_xml = strjoin("\n", localed_ispect_xml_def); + const GString *localed_config_xml = strjoin("\n", localed_config_xml_def); + + const gchar **logind_prefixs = get_prefixs(our_conf_path, "logind"); + const GString *logind_ispect_xml = strjoin("\n", logind_ispect_xml_def); + const GString *logind_config_xml = strjoin("\n", logind_config_xml_def); + + g_file_set_contents(*hostnamed_prefixs[0], hostnamed_config_xml, -1, errors); + g_file_set_contents(*hostnamed_prefixs[1], hostnamed_config_xml, -1, errors); + + g_file_set_contents(*timedated_prefixs[0], timedated_config_xml, -1, errors); + g_file_set_contents(*timedated_prefixs[1], timedated_config_xml, -1, errors); + + g_file_set_contents(*localed_prefixs[0], localed_config_xml, -1, errors); + g_file_set_contents(*localed_prefixs[1], localed_config_xml, -1, errors); + + g_file_set_contents(*logind_prefixs[0], logind_config_xml, -1, errors); + g_file_set_contents(*logind_prefixs[1], logind_config_xml, -1, errors); + + /* TODO: free() strings */ + + return (errors[0] == NULL); + + } else + return FALSE; +} |