Merge branch 'devel' of git://uglyman.kremlin.cc/git/systembsd into devel
authorkremlin <ian@kremlin.cc>
Mon, 25 Aug 2014 19:57:22 +0000 (14:57 -0500)
committerkremlin <ian@kremlin.cc>
Mon, 25 Aug 2014 19:57:22 +0000 (14:57 -0500)
src/interfaces/timedated/timedated.c
src/interfaces/timedated/timedated.h
src/util.c

index e79682a1989b3f6f580e59b5ee08f4a50f630426..56f62b2887b760b49765d739e72e586b9e1db825 100644 (file)
 #include <limits.h>
 #include <signal.h>
 
-#include <sys/param.h>
+#include <sys/types.h>
+#include <time.h>
 #include <string.h>
 
 #include <glib/gprintf.h>
 #include <glib-unix.h>
+#include <glib/gstdio.h>
 #include <polkit/polkit.h>
 
 #include "timedated-gen.h"
@@ -38,6 +40,9 @@ GMainLoop *timedated_loop;
 guint bus_descriptor;
 gboolean dbus_interface_exported; /* reliable because of gdbus operational guarantees */
 
+const gchar *OS_LOCALTIME     = "/etc/localtime";      /* current timezone file */
+const gchar *OS_TIMEZONE_PATH = "/usr/share/zoneinfo"; /* path to system timezone files */
+
 /* --- begin method/property/dbus signal code --- */
 
 static gboolean
@@ -75,7 +80,34 @@ on_handle_set_ntp(Timedate1 *hn1_passed_interf,
 const gchar *
 our_get_timezone() {
 
-    return "";
+    GStatBuf *stat_zoneinfo;
+    gchar *find_cmd, *readlink_path, *ret;
+    GError *err = NULL;
+
+    find_cmd      = (gchar *)   g_malloc0(2048);
+    stat_zoneinfo = (GStatBuf*) g_malloc0(8192);
+
+    if(g_stat(OS_LOCALTIME, stat_zoneinfo)) {
+
+        g_printf("could not read from %s! please symlink or copy a timezone file from %s to %s!\n", OS_LOCALTIME, OS_TIMEZONE_PATH, OS_LOCALTIME);
+        ret = NULL;
+
+    } else if(g_file_test(OS_LOCALTIME, G_FILE_TEST_IS_SYMLINK)) {
+
+        readlink_path = g_file_read_link(OS_LOCALTIME, &err);
+        ret = parse_timezone_path(readlink_path);
+
+        if(readlink_path)
+            g_free(readlink_path);
+
+    } else {
+
+        g_printf("%s is not a symlink! attempting to match checksums in %s...\n", OS_LOCALTIME, OS_TIMEZONE_PATH);
+        g_sprintf(find_cmd, "find %s -type f", OS_TIMEZONE_PATH);
+        ret = NULL;
+    }
+
+    return ret;
 }
 
 gboolean
@@ -248,3 +280,26 @@ int main() {
 
     return 0;
 }
+
+static gchar *parse_timezone_path(gchar *full_path) {
+
+    gchar *prefix_pattern;
+    GRegex *prefix, *posix, *right;
+    GError *err = NULL;
+
+    if(!full_path)
+        return NULL;
+
+    prefix_pattern = (gchar *) g_malloc0(4096);
+    g_sprintf(prefix_pattern, "^%s/$", OS_TIMEZONE_PATH);
+
+    prefix = g_regex_new(prefix_pattern, 0, 0, &err);
+    posix  = g_regex_new("^posix/$",     0, 0, &err);
+    right  = g_regex_new("^right/$",     0, 0, &err);
+
+    g_regex_unref(prefix);
+    g_regex_unref(right);
+    g_regex_unref(posix);
+
+    return NULL; /* TODO temp */
+}
index 8f766513492e13ab2a278c6a959d1b21fa919f5f..693106a182c0affb3fcfaec23af3babe5243e058 100644 (file)
@@ -15,3 +15,5 @@
  */
 
 void timedated_mem_clean();
+static gchar *parse_timezone_path(gchar *full_path);
+
index bb5670a18d2ebcd8762197f60ab9769cae934d9e..aea6b8db35410fa6aa61f54a8479f48c2ea7d729 100644 (file)
 
 const gint MAX_TOKENS = 20;
 
+/* return must be g_free()'d */
+gchar *get_file_sha256(const gchar *path) {
+
+    gchar *checksum;
+    GMappedFile *file;
+    GBytes *data;
+    GError *err = NULL;
+
+    file = g_mapped_file_new(path, FALSE, &err);
+
+    if(file) {
+
+        data = g_mapped_file_get_bytes(file);
+        g_mapped_file_unref(file);
+        checksum = g_compute_checksum_for_bytes(G_CHECKSUM_SHA256, data);
+        return checksum;
+    } else
+        return NULL;
+}
+
 /* return must be g_free()'d */
 gchar *config_get(const gchar *path, gchar *key) {