Advertisement
Guest User

Untitled

a guest
Apr 29th, 2014
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Diff 93.04 KB | None | 0 0
  1. diff --git a/plugins/datetime/Makefile.am b/plugins/datetime/Makefile.am
  2. index eb25394..92d5a3c 100644
  3. --- a/plugins/datetime/Makefile.am
  4. +++ b/plugins/datetime/Makefile.am
  5. @@ -1,68 +1,16 @@
  6.  plugin_name = datetime
  7.  
  8. -dbus_servicesdir = $(datadir)/dbus-1/system-services
  9. -dbus_confdir = $(sysconfdir)/dbus-1/system.d
  10.  polkitdir = $(datadir)/polkit-1/actions
  11. -
  12. -dbus_services_in_files = org.cinnamon.SettingsDaemon.DateTimeMechanism.service.in
  13.  polkit_in_files = org.cinnamon.settingsdaemon.datetimemechanism.policy.in
  14.  
  15. -csd-datetime-mechanism-glue.h: $(srcdir)/csd-datetime-mechanism.xml
  16. -   $(AM_V_GEN) dbus-binding-tool \
  17. -           --prefix=csd_datetime_mechanism --mode=glib-server  \
  18. -           --output=csd-datetime-mechanism-glue.h          \
  19. -           $(srcdir)/csd-datetime-mechanism.xml
  20. -
  21. -
  22. -if HAVE_POLKIT
  23. -libexec_PROGRAMS = csd-datetime-mechanism
  24. -noinst_PROGRAMS = test-system-timezone
  25. -endif
  26. -
  27. -csd_datetime_mechanism_SOURCES =       \
  28. -   csd-datetime-mechanism.c        \
  29. -   csd-datetime-mechanism.h        \
  30. -   csd-datetime-mechanism-debian.c     \
  31. -   csd-datetime-mechanism-debian.h     \
  32. -   csd-datetime-mechanism-main.c       \
  33. -   system-timezone.c           \
  34. -   system-timezone.h
  35. -
  36. -
  37.  if HAVE_POLKIT
  38. -BUILT_SOURCES = csd-datetime-mechanism-glue.h
  39. -endif
  40. -
  41. -AM_CFLAGS = $(POLKIT_CFLAGS)
  42. -csd_datetime_mechanism_LDADD = $(POLKIT_LIBS)
  43. -
  44. -test_system_timezone_SOURCES = test-system-timezone.c system-timezone.c system-timezone.h
  45. -test_system_timezone_LDADD = $(POLKIT_LIBS)
  46. -
  47. -if HAVE_POLKIT
  48. -dbus_services_DATA = $(dbus_services_in_files:.service.in=.service)
  49. -
  50. -$(dbus_services_DATA): $(dbus_services_in_files)
  51. -   $(AM_V_GEN)sed -e "s|\@LIBEXECDIR\@|$(libexecdir)|" $< > $@
  52. -
  53. -dbus_conf_DATA = org.cinnamon.SettingsDaemon.DateTimeMechanism.conf
  54.  
  55.  @INTLTOOL_POLICY_RULE@
  56.  polkit_DATA = $(polkit_in_files:.policy.in=.policy)
  57.  
  58.  else
  59. -dbus_services_DATA =
  60. -dbus_conf_DATA =
  61.  polkit_DATA =
  62.  endif
  63.  
  64. -EXTRA_DIST =                       \
  65. -   $(dbus_services_in_files)           \
  66. -   org.cinnamon.SettingsDaemon.DateTimeMechanism.conf  \
  67. -   $(polkit_in_files)              \
  68. -   gsd-datetime-mechanism.xml
  69. +EXTRA_DIST = $(polkit_in_files)
  70.  
  71. -CLEANFILES =       \
  72. -   org.cinnamon.SettingsDaemon.DateTimeMechanism.service   \
  73. -   org.cinnamon.settingsdaemon.datetimemechanism.policy    \
  74. -   $(BUILT_SOURCES)
  75. diff --git a/plugins/datetime/csd-datetime-mechanism-debian.c b/plugins/datetime/csd-datetime-mechanism-debian.c
  76. deleted file mode 100644
  77. index aa3f60c..0000000
  78. --- a/plugins/datetime/csd-datetime-mechanism-debian.c
  79. +++ /dev/null
  80. @@ -1,200 +0,0 @@
  81. -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
  82. - *
  83. - * Copyright (C) 2007 David Zeuthen <david@fubar.dk>
  84. - * Copyright (C) 2011 Bastien Nocera <hadess@hadess.net>
  85. - *
  86. - * This program is free software; you can redistribute it and/or modify
  87. - * it under the terms of the GNU General Public License as published by
  88. - * the Free Software Foundation; either version 2 of the License, or
  89. - * (at your option) any later version.
  90. - *
  91. - * This program is distributed in the hope that it will be useful,
  92. - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  93. - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  94. - * GNU General Public License for more details.
  95. - *
  96. - * You should have received a copy of the GNU General Public License
  97. - * along with this program; if not, write to the Free Software
  98. - * Foundation, Inc., 51 Franklin Street - Suite 500, Boston, MA 02110-1335, USA.
  99. - *
  100. - */
  101. -
  102. -#ifdef HAVE_CONFIG_H
  103. -#  include "config.h"
  104. -#endif
  105. -
  106. -#include "csd-datetime-mechanism-debian.h"
  107. -#include "csd-datetime-mechanism.h"
  108. -
  109. -static void
  110. -_get_using_ntpdate (gboolean *can_use, gboolean *is_using, GError ** error)
  111. -{
  112. -        if (!g_file_test ("/usr/sbin/ntpdate-debian", G_FILE_TEST_EXISTS))
  113. -                return;
  114. -
  115. -        *can_use = TRUE;
  116. -
  117. -        if (g_file_test ("/etc/network/if-up.d/ntpdate", G_FILE_TEST_EXISTS))
  118. -                *is_using = TRUE;
  119. -}
  120. -
  121. -static void
  122. -_get_using_ntpd (gboolean *can_use, gboolean *is_using, GError ** error)
  123. -{
  124. -        int exit_status;
  125. -        GError *tmp_error = NULL;
  126. -
  127. -        if (!g_file_test ("/usr/sbin/ntpd", G_FILE_TEST_EXISTS))
  128. -                return;
  129. -
  130. -        *can_use = TRUE;
  131. -
  132. -        if (!g_spawn_command_line_sync ("/usr/sbin/service ntp status",
  133. -                                        NULL, NULL, &exit_status, &tmp_error)) {
  134. -                if (error != NULL && *error == NULL) {
  135. -                        *error = g_error_new (CSD_DATETIME_MECHANISM_ERROR,
  136. -                                              CSD_DATETIME_MECHANISM_ERROR_GENERAL,
  137. -                                              "Error spawning /usr/sbin/service: %s",
  138. -                                              tmp_error->message);
  139. -                }
  140. -                g_error_free (tmp_error);
  141. -                return;
  142. -        }
  143. -
  144. -        if (exit_status == 0)
  145. -                *is_using = TRUE;
  146. -}
  147. -
  148. -gboolean
  149. -_get_using_ntp_debian (DBusGMethodInvocation   *context)
  150. -{
  151. -        gboolean can_use_ntp = FALSE;
  152. -        gboolean is_using_ntp = FALSE;
  153. -        GError *error = NULL;
  154. -
  155. -        /* In Debian, ntpdate is used whenever the network comes up. So if
  156. -           either ntpdate or ntpd is installed and available, can_use is true.
  157. -           If either is active, is_using is true. */
  158. -        _get_using_ntpdate (&can_use_ntp, &is_using_ntp, &error);
  159. -        _get_using_ntpd (&can_use_ntp, &is_using_ntp, &error);
  160. -
  161. -        if (error == NULL) {
  162. -                dbus_g_method_return (context, can_use_ntp, is_using_ntp);
  163. -                return TRUE;
  164. -        } else {
  165. -                dbus_g_method_return_error (context, error);
  166. -                g_error_free (error);
  167. -                return FALSE;
  168. -        }
  169. -}
  170. -
  171. -static void
  172. -_set_using_ntpdate (gboolean using_ntp, GError **error)
  173. -{
  174. -        const gchar *cmd = NULL;
  175. -        GError  *tmp_error = NULL;
  176. -
  177. -        /* Debian uses an if-up.d script to sync network time when an interface
  178. -           comes up.  This is a separate mechanism from ntpd altogether. */
  179. -
  180. -#define NTPDATE_ENABLED  "/etc/network/if-up.d/ntpdate"
  181. -#define NTPDATE_DISABLED "/etc/network/if-up.d/ntpdate.disabled"
  182. -
  183. -        if (using_ntp && g_file_test (NTPDATE_DISABLED, G_FILE_TEST_EXISTS))
  184. -                cmd = "/bin/mv -f "NTPDATE_DISABLED" "NTPDATE_ENABLED;
  185. -        else if (!using_ntp && g_file_test (NTPDATE_ENABLED, G_FILE_TEST_EXISTS))
  186. -                cmd = "/bin/mv -f "NTPDATE_ENABLED" "NTPDATE_DISABLED;
  187. -        else
  188. -                 return;
  189. -
  190. -        if (!g_spawn_command_line_sync (cmd, NULL, NULL, NULL, &tmp_error)) {
  191. -                if (error != NULL && *error == NULL) {
  192. -                        *error = g_error_new (CSD_DATETIME_MECHANISM_ERROR,
  193. -                                              CSD_DATETIME_MECHANISM_ERROR_GENERAL,
  194. -                                              "Error spawning /bin/mv: %s",
  195. -                                              tmp_error->message);
  196. -                }
  197. -                g_error_free (tmp_error);
  198. -                return;
  199. -        }
  200. -
  201. -        /* Kick start ntpdate to sync time immediately */
  202. -        if (using_ntp &&
  203. -            !g_spawn_command_line_sync ("/etc/network/if-up.d/ntpdate",
  204. -                                        NULL, NULL, NULL, &tmp_error)) {
  205. -                if (error != NULL && *error == NULL) {
  206. -                        *error = g_error_new (CSD_DATETIME_MECHANISM_ERROR,
  207. -                                              CSD_DATETIME_MECHANISM_ERROR_GENERAL,
  208. -                                              "Error spawning /etc/network/if-up.d/ntpdate: %s",
  209. -                                              tmp_error->message);
  210. -                }
  211. -                g_error_free (tmp_error);
  212. -                return;
  213. -        }
  214. -}
  215. -
  216. -static void
  217. -_set_using_ntpd (gboolean using_ntp, GError **error)
  218. -{
  219. -        GError *tmp_error = NULL;
  220. -        int exit_status;
  221. -        char *cmd;
  222. -
  223. -        if (!g_file_test ("/usr/sbin/ntpd", G_FILE_TEST_EXISTS))
  224. -                return;
  225. -
  226. -        cmd = g_strconcat ("/usr/sbin/update-rc.d ntp ", using_ntp ? "enable" : "disable", NULL);
  227. -
  228. -        if (!g_spawn_command_line_sync (cmd, NULL, NULL, &exit_status, &tmp_error)) {
  229. -                if (error != NULL && *error == NULL) {
  230. -                        *error = g_error_new (CSD_DATETIME_MECHANISM_ERROR,
  231. -                                              CSD_DATETIME_MECHANISM_ERROR_GENERAL,
  232. -                                              "Error spawning '%s': %s",
  233. -                                              cmd, tmp_error->message);
  234. -                }
  235. -                g_error_free (tmp_error);
  236. -                g_free (cmd);
  237. -                return;
  238. -        }
  239. -
  240. -        g_free (cmd);
  241. -
  242. -        cmd = g_strconcat ("/usr/sbin/service ntp ", using_ntp ? "restart" : "stop", NULL);;
  243. -
  244. -        if (!g_spawn_command_line_sync (cmd, NULL, NULL, &exit_status, &tmp_error)) {
  245. -                if (error != NULL && *error == NULL) {
  246. -                        *error = g_error_new (CSD_DATETIME_MECHANISM_ERROR,
  247. -                                              CSD_DATETIME_MECHANISM_ERROR_GENERAL,
  248. -                                              "Error spawning '%s': %s",
  249. -                                              cmd, tmp_error->message);
  250. -                }
  251. -                g_error_free (tmp_error);
  252. -                g_free (cmd);
  253. -                return;
  254. -        }
  255. -
  256. -        g_free (cmd);
  257. -}
  258. -
  259. -gboolean
  260. -_set_using_ntp_debian  (DBusGMethodInvocation   *context,
  261. -                        gboolean                 using_ntp)
  262. -{
  263. -        GError *error = NULL;
  264. -
  265. -        /* In Debian, ntpdate and ntpd may be installed separately, so don't
  266. -           assume both are valid. */
  267. -
  268. -        _set_using_ntpdate (using_ntp, &error);
  269. -        _set_using_ntpd (using_ntp, &error);
  270. -
  271. -        if (error == NULL) {
  272. -                dbus_g_method_return (context);
  273. -                return TRUE;
  274. -        } else {
  275. -                dbus_g_method_return_error (context, error);
  276. -                g_error_free (error);
  277. -                return FALSE;
  278. -        }
  279. -}
  280. -
  281. diff --git a/plugins/datetime/csd-datetime-mechanism-debian.h b/plugins/datetime/csd-datetime-mechanism-debian.h
  282. deleted file mode 100644
  283. index a96b1e7..0000000
  284. --- a/plugins/datetime/csd-datetime-mechanism-debian.h
  285. +++ /dev/null
  286. @@ -1,27 +0,0 @@
  287. -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
  288. - *
  289. - * Copyright (C) 2007 David Zeuthen <david@fubar.dk>
  290. - * Copyright (C) 2011 Bastien Nocera <hadess@hadess.net>
  291. - *
  292. - * This program is free software; you can redistribute it and/or modify
  293. - * it under the terms of the GNU General Public License as published by
  294. - * the Free Software Foundation; either version 2 of the License, or
  295. - * (at your option) any later version.
  296. - *
  297. - * This program is distributed in the hope that it will be useful,
  298. - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  299. - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  300. - * GNU General Public License for more details.
  301. - *
  302. - * You should have received a copy of the GNU General Public License
  303. - * along with this program; if not, write to the Free Software
  304. - * Foundation, Inc., 51 Franklin Street - Suite 500, Boston, MA 02110-1335, USA.
  305. - *
  306. - */
  307. -
  308. -#include <glib.h>
  309. -#include <dbus/dbus-glib.h>
  310. -
  311. -gboolean _get_using_ntp_debian (DBusGMethodInvocation   *context);
  312. -gboolean _set_using_ntp_debian  (DBusGMethodInvocation   *context,
  313. -                                 gboolean                 using_ntp);
  314. diff --git a/plugins/datetime/csd-datetime-mechanism-main.c b/plugins/datetime/csd-datetime-mechanism-main.c
  315. deleted file mode 100644
  316. index aebd1d2..0000000
  317. --- a/plugins/datetime/csd-datetime-mechanism-main.c
  318. +++ /dev/null
  319. @@ -1,171 +0,0 @@
  320. -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
  321. - *
  322. - * Copyright (C) 2007 David Zeuthen <david@fubar.dk>
  323. - *
  324. - * This program is free software; you can redistribute it and/or modify
  325. - * it under the terms of the GNU General Public License as published by
  326. - * the Free Software Foundation; either version 2 of the License, or
  327. - * (at your option) any later version.
  328. - *
  329. - * This program is distributed in the hope that it will be useful,
  330. - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  331. - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  332. - * GNU General Public License for more details.
  333. - *
  334. - * You should have received a copy of the GNU General Public License
  335. - * along with this program; if not, write to the Free Software
  336. - * Foundation, Inc., 51 Franklin Street - Suite 500, Boston, MA 02110-1335, USA.
  337. - *
  338. - */
  339. -
  340. -#ifdef HAVE_CONFIG_H
  341. -#  include "config.h"
  342. -#endif
  343. -
  344. -#include <stdlib.h>
  345. -#include <stdio.h>
  346. -#include <unistd.h>
  347. -#include <signal.h>
  348. -#include <errno.h>
  349. -#include <string.h>
  350. -#include <sys/types.h>
  351. -#include <sys/stat.h>
  352. -#include <fcntl.h>
  353. -
  354. -#include <glib.h>
  355. -#include <glib-object.h>
  356. -
  357. -#include <dbus/dbus-glib.h>
  358. -#include <dbus/dbus-glib-lowlevel.h>
  359. -
  360. -
  361. -#include "csd-datetime-mechanism.h"
  362. -
  363. -static DBusGProxy *
  364. -get_bus_proxy (DBusGConnection *connection)
  365. -{
  366. -        DBusGProxy *bus_proxy;
  367. -
  368. -        bus_proxy = dbus_g_proxy_new_for_name (connection,
  369. -                                               DBUS_SERVICE_DBUS,
  370. -                                               DBUS_PATH_DBUS,
  371. -                                               DBUS_INTERFACE_DBUS);
  372. -        return bus_proxy;
  373. -}
  374. -
  375. -#define BUS_NAME "org.cinnamon.SettingsDaemon.DateTimeMechanism"
  376. -
  377. -static gboolean
  378. -acquire_name_on_proxy (DBusGProxy *bus_proxy)
  379. -{
  380. -        GError     *error;
  381. -        guint       result;
  382. -        gboolean    res;
  383. -        gboolean    ret;
  384. -
  385. -        ret = FALSE;
  386. -
  387. -        if (bus_proxy == NULL) {
  388. -                goto out;
  389. -        }
  390. -
  391. -        error = NULL;
  392. -        res = dbus_g_proxy_call (bus_proxy,
  393. -                                 "RequestName",
  394. -                                 &error,
  395. -                                 G_TYPE_STRING, BUS_NAME,
  396. -                                 G_TYPE_UINT, 0,
  397. -                                 G_TYPE_INVALID,
  398. -                                 G_TYPE_UINT, &result,
  399. -                                 G_TYPE_INVALID);
  400. -        if (! res) {
  401. -                if (error != NULL) {
  402. -                        g_warning ("Failed to acquire %s: %s", BUS_NAME, error->message);
  403. -                        g_error_free (error);
  404. -                } else {
  405. -                        g_warning ("Failed to acquire %s", BUS_NAME);
  406. -                }
  407. -                goto out;
  408. -    }
  409. -
  410. -    if (result != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
  411. -                if (error != NULL) {
  412. -                        g_warning ("Failed to acquire %s: %s", BUS_NAME, error->message);
  413. -                        g_error_free (error);
  414. -                } else {
  415. -                        g_warning ("Failed to acquire %s", BUS_NAME);
  416. -                }
  417. -                goto out;
  418. -        }
  419. -
  420. -        ret = TRUE;
  421. -
  422. - out:
  423. -        return ret;
  424. -}
  425. -
  426. -static DBusGConnection *
  427. -get_system_bus (void)
  428. -{
  429. -        GError          *error;
  430. -        DBusGConnection *bus;
  431. -
  432. -        error = NULL;
  433. -        bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
  434. -        if (bus == NULL) {
  435. -                g_warning ("Couldn't connect to system bus: %s", error->message);
  436. -                g_error_free (error);
  437. -        }
  438. -        return bus;
  439. -}
  440. -
  441. -int
  442. -main (int argc, char **argv)
  443. -{
  444. -        GMainLoop             *loop;
  445. -        CsdDatetimeMechanism  *mechanism;
  446. -        DBusGProxy            *bus_proxy;
  447. -        DBusGConnection       *connection;
  448. -        int                    ret;
  449. -
  450. -        ret = 1;
  451. -
  452. -        if (! g_thread_supported ()) {
  453. -                g_thread_init (NULL);
  454. -        }
  455. -        dbus_g_thread_init ();
  456. -        g_type_init ();
  457. -
  458. -        connection = get_system_bus ();
  459. -        if (connection == NULL) {
  460. -                goto out;
  461. -        }
  462. -
  463. -        bus_proxy = get_bus_proxy (connection);
  464. -        if (bus_proxy == NULL) {
  465. -                g_warning ("Could not construct bus_proxy object; bailing out");
  466. -                goto out;
  467. -        }
  468. -
  469. -        if (!acquire_name_on_proxy (bus_proxy) ) {
  470. -                g_warning ("Could not acquire name; bailing out");
  471. -                goto out;
  472. -        }
  473. -
  474. -        mechanism = csd_datetime_mechanism_new ();
  475. -
  476. -        if (mechanism == NULL) {
  477. -                goto out;
  478. -        }
  479. -
  480. -        loop = g_main_loop_new (NULL, FALSE);
  481. -
  482. -        g_main_loop_run (loop);
  483. -
  484. -        g_object_unref (mechanism);
  485. -        g_main_loop_unref (loop);
  486. -        ret = 0;
  487. -
  488. -out:
  489. -        return ret;
  490. -}
  491. diff --git a/plugins/datetime/csd-datetime-mechanism.c b/plugins/datetime/csd-datetime-mechanism.c
  492. deleted file mode 100644
  493. index 554731b..0000000
  494. --- a/plugins/datetime/csd-datetime-mechanism.c
  495. +++ /dev/null
  496. @@ -1,756 +0,0 @@
  497. -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
  498. - *
  499. - * Copyright (C) 2007 David Zeuthen <david@fubar.dk>
  500. - *
  501. - * This program is free software; you can redistribute it and/or modify
  502. - * it under the terms of the GNU General Public License as published by
  503. - * the Free Software Foundation; either version 2 of the License, or
  504. - * (at your option) any later version.
  505. - *
  506. - * This program is distributed in the hope that it will be useful,
  507. - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  508. - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  509. - * GNU General Public License for more details.
  510. - *
  511. - * You should have received a copy of the GNU General Public License
  512. - * along with this program; if not, write to the Free Software
  513. - * Foundation, Inc., 51 Franklin Street - Suite 500, Boston, MA 02110-1335, USA.
  514. - *
  515. - */
  516. -
  517. -#ifdef HAVE_CONFIG_H
  518. -#  include "config.h"
  519. -#endif
  520. -
  521. -#include <stdlib.h>
  522. -#include <stdio.h>
  523. -#include <fcntl.h>
  524. -#include <unistd.h>
  525. -#include <string.h>
  526. -#include <sys/wait.h>
  527. -#include <errno.h>
  528. -#include <sys/time.h>
  529. -
  530. -#include <glib.h>
  531. -#include <glib-object.h>
  532. -
  533. -#include <dbus/dbus-glib.h>
  534. -#include <dbus/dbus-glib-lowlevel.h>
  535. -
  536. -#include <polkit/polkit.h>
  537. -
  538. -#include "system-timezone.h"
  539. -
  540. -#include "csd-datetime-mechanism.h"
  541. -#include "csd-datetime-mechanism-glue.h"
  542. -
  543. -/* NTP helper functions for various distributions */
  544. -#include "csd-datetime-mechanism-debian.h"
  545. -
  546. -static gboolean
  547. -do_exit (gpointer user_data)
  548. -{
  549. -        g_debug ("Exiting due to inactivity");
  550. -        exit (1);
  551. -        return FALSE;
  552. -}
  553. -
  554. -static void
  555. -reset_killtimer (void)
  556. -{
  557. -        static guint timer_id = 0;
  558. -
  559. -        if (timer_id > 0) {
  560. -                g_source_remove (timer_id);
  561. -                timer_id = 0;
  562. -        }
  563. -        g_debug ("Setting killtimer to 30 seconds...");
  564. -        timer_id = g_timeout_add_seconds (30, do_exit, NULL);
  565. -}
  566. -
  567. -struct CsdDatetimeMechanismPrivate
  568. -{
  569. -        DBusGConnection *system_bus_connection;
  570. -        DBusGProxy      *system_bus_proxy;
  571. -        PolkitAuthority *auth;
  572. -};
  573. -
  574. -static void     csd_datetime_mechanism_finalize    (GObject     *object);
  575. -
  576. -G_DEFINE_TYPE (CsdDatetimeMechanism, csd_datetime_mechanism, G_TYPE_OBJECT)
  577. -
  578. -#define CSD_DATETIME_MECHANISM_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), CSD_DATETIME_TYPE_MECHANISM, CsdDatetimeMechanismPrivate))
  579. -
  580. -GQuark
  581. -csd_datetime_mechanism_error_quark (void)
  582. -{
  583. -        static GQuark ret = 0;
  584. -
  585. -        if (ret == 0) {
  586. -                ret = g_quark_from_static_string ("csd_datetime_mechanism_error");
  587. -        }
  588. -
  589. -        return ret;
  590. -}
  591. -
  592. -
  593. -#define ENUM_ENTRY(NAME, DESC) { NAME, "" #NAME "", DESC }
  594. -
  595. -GType
  596. -csd_datetime_mechanism_error_get_type (void)
  597. -{
  598. -        static GType etype = 0;
  599. -        
  600. -        if (etype == 0)
  601. -        {
  602. -                static const GEnumValue values[] =
  603. -                        {
  604. -                                ENUM_ENTRY (CSD_DATETIME_MECHANISM_ERROR_GENERAL, "GeneralError"),
  605. -                                ENUM_ENTRY (CSD_DATETIME_MECHANISM_ERROR_NOT_PRIVILEGED, "NotPrivileged"),
  606. -                                ENUM_ENTRY (CSD_DATETIME_MECHANISM_ERROR_INVALID_TIMEZONE_FILE, "InvalidTimezoneFile"),
  607. -                                { 0, 0, 0 }
  608. -                        };
  609. -                
  610. -                g_assert (CSD_DATETIME_MECHANISM_NUM_ERRORS == G_N_ELEMENTS (values) - 1);
  611. -                
  612. -                etype = g_enum_register_static ("CsdDatetimeMechanismError", values);
  613. -        }
  614. -        
  615. -        return etype;
  616. -}
  617. -
  618. -
  619. -static GObject *
  620. -csd_datetime_mechanism_constructor (GType                  type,
  621. -                                    guint                  n_construct_properties,
  622. -                                    GObjectConstructParam *construct_properties)
  623. -{
  624. -        CsdDatetimeMechanism      *mechanism;
  625. -
  626. -        mechanism = CSD_DATETIME_MECHANISM (G_OBJECT_CLASS (csd_datetime_mechanism_parent_class)->constructor (
  627. -                                                type,
  628. -                                                n_construct_properties,
  629. -                                                construct_properties));
  630. -
  631. -        return G_OBJECT (mechanism);
  632. -}
  633. -
  634. -static void
  635. -csd_datetime_mechanism_class_init (CsdDatetimeMechanismClass *klass)
  636. -{
  637. -        GObjectClass   *object_class = G_OBJECT_CLASS (klass);
  638. -
  639. -        object_class->constructor = csd_datetime_mechanism_constructor;
  640. -        object_class->finalize = csd_datetime_mechanism_finalize;
  641. -
  642. -        g_type_class_add_private (klass, sizeof (CsdDatetimeMechanismPrivate));
  643. -
  644. -        dbus_g_object_type_install_info (CSD_DATETIME_TYPE_MECHANISM, &dbus_glib_csd_datetime_mechanism_object_info);
  645. -
  646. -        dbus_g_error_domain_register (CSD_DATETIME_MECHANISM_ERROR, NULL, CSD_DATETIME_MECHANISM_TYPE_ERROR);
  647. -
  648. -}
  649. -
  650. -static void
  651. -csd_datetime_mechanism_init (CsdDatetimeMechanism *mechanism)
  652. -{
  653. -        mechanism->priv = CSD_DATETIME_MECHANISM_GET_PRIVATE (mechanism);
  654. -
  655. -}
  656. -
  657. -static void
  658. -csd_datetime_mechanism_finalize (GObject *object)
  659. -{
  660. -        CsdDatetimeMechanism *mechanism;
  661. -
  662. -        g_return_if_fail (object != NULL);
  663. -        g_return_if_fail (CSD_DATETIME_IS_MECHANISM (object));
  664. -
  665. -        mechanism = CSD_DATETIME_MECHANISM (object);
  666. -
  667. -        g_return_if_fail (mechanism->priv != NULL);
  668. -
  669. -        g_object_unref (mechanism->priv->system_bus_proxy);
  670. -
  671. -        G_OBJECT_CLASS (csd_datetime_mechanism_parent_class)->finalize (object);
  672. -}
  673. -
  674. -static gboolean
  675. -register_mechanism (CsdDatetimeMechanism *mechanism)
  676. -{
  677. -        GError *error = NULL;
  678. -
  679. -        mechanism->priv->auth = polkit_authority_get_sync (NULL, &error);
  680. -        if (mechanism->priv->auth == NULL) {
  681. -                if (error != NULL) {
  682. -                        g_critical ("error getting system bus: %s", error->message);
  683. -                        g_error_free (error);
  684. -                }
  685. -                goto error;
  686. -        }
  687. -
  688. -        mechanism->priv->system_bus_connection = dbus_g_bus_get (DBUS_BUS_SYSTEM, &error);
  689. -        if (mechanism->priv->system_bus_connection == NULL) {
  690. -                if (error != NULL) {
  691. -                        g_critical ("error getting system bus: %s", error->message);
  692. -                        g_error_free (error);
  693. -                }
  694. -                goto error;
  695. -        }
  696. -
  697. -        dbus_g_connection_register_g_object (mechanism->priv->system_bus_connection, "/",
  698. -                                             G_OBJECT (mechanism));
  699. -
  700. -        mechanism->priv->system_bus_proxy = dbus_g_proxy_new_for_name (mechanism->priv->system_bus_connection,
  701. -                                                                      DBUS_SERVICE_DBUS,
  702. -                                                                      DBUS_PATH_DBUS,
  703. -                                                                      DBUS_INTERFACE_DBUS);
  704. -
  705. -        reset_killtimer ();
  706. -
  707. -        return TRUE;
  708. -
  709. -error:
  710. -        return FALSE;
  711. -}
  712. -
  713. -
  714. -CsdDatetimeMechanism *
  715. -csd_datetime_mechanism_new (void)
  716. -{
  717. -        GObject *object;
  718. -        gboolean res;
  719. -
  720. -        object = g_object_new (CSD_DATETIME_TYPE_MECHANISM, NULL);
  721. -
  722. -        res = register_mechanism (CSD_DATETIME_MECHANISM (object));
  723. -        if (! res) {
  724. -                g_object_unref (object);
  725. -                return NULL;
  726. -        }
  727. -
  728. -        return CSD_DATETIME_MECHANISM (object);
  729. -}
  730. -
  731. -static gboolean
  732. -_check_polkit_for_action (CsdDatetimeMechanism *mechanism, DBusGMethodInvocation *context)
  733. -{
  734. -        const char *action = "org.cinnamon.settingsdaemon.datetimemechanism.configure";
  735. -        const char *sender;
  736. -        GError *error;
  737. -        PolkitSubject *subject;
  738. -        PolkitAuthorizationResult *result;
  739. -
  740. -        error = NULL;
  741. -
  742. -        /* Check that caller is privileged */
  743. -        sender = dbus_g_method_get_sender (context);
  744. -        subject = polkit_system_bus_name_new (sender);
  745. -
  746. -        result = polkit_authority_check_authorization_sync (mechanism->priv->auth,
  747. -                                                            subject,
  748. -                                                            action,
  749. -                                                            NULL,
  750. -                                                            POLKIT_CHECK_AUTHORIZATION_FLAGS_ALLOW_USER_INTERACTION,
  751. -                                                            NULL, &error);
  752. -        g_object_unref (subject);
  753. -
  754. -        if (error) {
  755. -                dbus_g_method_return_error (context, error);
  756. -                g_error_free (error);
  757. -
  758. -                return FALSE;
  759. -        }
  760. -
  761. -        if (!polkit_authorization_result_get_is_authorized (result)) {
  762. -                error = g_error_new (CSD_DATETIME_MECHANISM_ERROR,
  763. -                                     CSD_DATETIME_MECHANISM_ERROR_NOT_PRIVILEGED,
  764. -                                     "Not Authorized for action %s", action);
  765. -                dbus_g_method_return_error (context, error);
  766. -                g_error_free (error);
  767. -                g_object_unref (result);
  768. -
  769. -                return FALSE;
  770. -        }
  771. -
  772. -        g_object_unref (result);
  773. -
  774. -        return TRUE;
  775. -}
  776. -
  777. -static gboolean
  778. -_sync_hwclock (DBusGMethodInvocation *context)
  779. -{
  780. -        GError *error;
  781. -
  782. -        error = NULL;
  783. -
  784. -        if (g_file_test ("/sbin/hwclock",
  785. -                         G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_EXECUTABLE)) {
  786. -                int exit_status;
  787. -                if (!g_spawn_command_line_sync ("/sbin/hwclock --systohc", NULL, NULL, &exit_status, &error)) {
  788. -                        GError *error2;
  789. -                        error2 = g_error_new (CSD_DATETIME_MECHANISM_ERROR,
  790. -                                              CSD_DATETIME_MECHANISM_ERROR_GENERAL,
  791. -                                              "Error spawning /sbin/hwclock: %s", error->message);
  792. -                        g_error_free (error);
  793. -                        dbus_g_method_return_error (context, error2);
  794. -                        g_error_free (error2);
  795. -                        return FALSE;
  796. -                }
  797. -                if (WEXITSTATUS (exit_status) != 0) {
  798. -                        error = g_error_new (CSD_DATETIME_MECHANISM_ERROR,
  799. -                                             CSD_DATETIME_MECHANISM_ERROR_GENERAL,
  800. -                                             "/sbin/hwclock returned %d", exit_status);
  801. -                        dbus_g_method_return_error (context, error);
  802. -                        g_error_free (error);
  803. -                        return FALSE;
  804. -                }
  805. -        }
  806. -
  807. -        return TRUE;
  808. -}
  809. -
  810. -static gboolean
  811. -_set_time (CsdDatetimeMechanism  *mechanism,
  812. -           const struct timeval  *tv,
  813. -           DBusGMethodInvocation *context)
  814. -{
  815. -        GError *error;
  816. -
  817. -        if (!_check_polkit_for_action (mechanism, context))
  818. -                return FALSE;
  819. -
  820. -        if (settimeofday (tv, NULL) != 0) {
  821. -                error = g_error_new (CSD_DATETIME_MECHANISM_ERROR,
  822. -                                     CSD_DATETIME_MECHANISM_ERROR_GENERAL,
  823. -                                     "Error calling settimeofday({%lld,%lld}): %s",
  824. -                                     (gint64) tv->tv_sec, (gint64) tv->tv_usec,
  825. -                                     strerror (errno));
  826. -                dbus_g_method_return_error (context, error);
  827. -                g_error_free (error);
  828. -                return FALSE;
  829. -        }
  830. -
  831. -        if (!_sync_hwclock (context))
  832. -                return FALSE;
  833. -
  834. -        dbus_g_method_return (context);
  835. -        return TRUE;
  836. -}
  837. -
  838. -static gboolean
  839. -_set_date (CsdDatetimeMechanism  *mechanism,
  840. -           guint                  day,
  841. -           guint                  month,
  842. -           guint                  year,
  843. -           DBusGMethodInvocation *context)
  844. -{
  845. -        GDateTime *time;
  846. -        char *date_str, *time_str;
  847. -        char *date_cmd;
  848. -        int exit_status;
  849. -        GError *error;
  850. -
  851. -        date_str = g_strdup_printf ("%02d/%02d/%d", month, day, year);
  852. -        error = NULL;
  853. -
  854. -        time = g_date_time_new_now_local ();
  855. -        time_str = g_date_time_format (time, "%R:%S");
  856. -        g_date_time_unref (time);
  857. -
  858. -        date_cmd = g_strdup_printf ("/bin/date -s \"%s %s\" +\"%%D %%R:%%S\"", date_str, time_str);
  859. -        g_free (date_str);
  860. -        g_free (time_str);
  861. -
  862. -        if (!g_spawn_command_line_sync (date_cmd, NULL, NULL, &exit_status, &error)) {
  863. -                GError *error2;
  864. -                error2 = g_error_new (CSD_DATETIME_MECHANISM_ERROR,
  865. -                                      CSD_DATETIME_MECHANISM_ERROR_GENERAL,
  866. -                                      "Error spawning /bin/date: %s", error->message);
  867. -                g_error_free (error);
  868. -                dbus_g_method_return_error (context, error2);
  869. -                g_error_free (error2);
  870. -                g_free (date_cmd);
  871. -                return FALSE;
  872. -        }
  873. -        g_free (date_cmd);
  874. -        if (WEXITSTATUS (exit_status) != 0) {
  875. -                error = g_error_new (CSD_DATETIME_MECHANISM_ERROR,
  876. -                                     CSD_DATETIME_MECHANISM_ERROR_GENERAL,
  877. -                                     "/bin/date returned %d", exit_status);
  878. -                dbus_g_method_return_error (context, error);
  879. -                g_error_free (error);
  880. -                return FALSE;
  881. -        }
  882. -
  883. -        if (!_sync_hwclock (context))
  884. -                return FALSE;
  885. -
  886. -        return TRUE;
  887. -}
  888. -
  889. -/* exported methods */
  890. -
  891. -gboolean
  892. -csd_datetime_mechanism_set_time (CsdDatetimeMechanism  *mechanism,
  893. -                                 gint64                 seconds_since_epoch,
  894. -                                 DBusGMethodInvocation *context)
  895. -{
  896. -        struct timeval tv;
  897. -
  898. -        reset_killtimer ();
  899. -        g_debug ("SetTime(%" G_GINT64_FORMAT ") called", seconds_since_epoch);
  900. -
  901. -        tv.tv_sec = (time_t) seconds_since_epoch;
  902. -        tv.tv_usec = 0;
  903. -        return _set_time (mechanism, &tv, context);
  904. -}
  905. -
  906. -gboolean
  907. -csd_datetime_mechanism_set_date (CsdDatetimeMechanism  *mechanism,
  908. -                                 guint                  day,
  909. -                                 guint                  month,
  910. -                                 guint                  year,
  911. -                                 DBusGMethodInvocation *context)
  912. -{
  913. -        reset_killtimer ();
  914. -        g_debug ("SetDate(%d, %d, %d) called", day, month, year);
  915. -
  916. -        return _set_date (mechanism, day, month, year, context);
  917. -}
  918. -
  919. -gboolean
  920. -csd_datetime_mechanism_adjust_time (CsdDatetimeMechanism  *mechanism,
  921. -                                    gint64                 seconds_to_add,
  922. -                                    DBusGMethodInvocation *context)
  923. -{
  924. -        struct timeval tv;
  925. -
  926. -        reset_killtimer ();
  927. -        g_debug ("AdjustTime(%" G_GINT64_FORMAT " ) called", seconds_to_add);
  928. -
  929. -        if (gettimeofday (&tv, NULL) != 0) {
  930. -                GError *error;
  931. -                error = g_error_new (CSD_DATETIME_MECHANISM_ERROR,
  932. -                                     CSD_DATETIME_MECHANISM_ERROR_GENERAL,
  933. -                                     "Error calling gettimeofday(): %s", strerror (errno));
  934. -                dbus_g_method_return_error (context, error);
  935. -                g_error_free (error);
  936. -                return FALSE;
  937. -        }
  938. -
  939. -        tv.tv_sec += (time_t) seconds_to_add;
  940. -        return _set_time (mechanism, &tv, context);
  941. -}
  942. -
  943. -static gboolean
  944. -csd_datetime_check_tz_name (const char *tz,
  945. -                            GError    **error)
  946. -{
  947. -        GFile *file;
  948. -        char *tz_path, *actual_path;
  949. -        gboolean retval;
  950. -
  951. -        retval = TRUE;
  952. -        tz_path = g_build_filename (SYSTEM_ZONEINFODIR, tz, NULL);
  953. -
  954. -        /* Get the actual resolved path */
  955. -        file = g_file_new_for_path (tz_path);
  956. -        actual_path = g_file_get_path (file);
  957. -        g_object_unref (file);
  958. -
  959. -        /* The tz name passed had relative paths in it */
  960. -        if (g_strcmp0 (tz_path, actual_path) != 0) {
  961. -                g_set_error (error, CSD_DATETIME_MECHANISM_ERROR,
  962. -                             CSD_DATETIME_MECHANISM_ERROR_INVALID_TIMEZONE_FILE,
  963. -                             "Timezone file '%s' was invalid.",
  964. -                             tz);
  965. -                retval = FALSE;
  966. -        }
  967. -
  968. -        g_free (tz_path);
  969. -        g_free (actual_path);
  970. -
  971. -        return retval;
  972. -}
  973. -
  974. -gboolean
  975. -csd_datetime_mechanism_set_timezone (CsdDatetimeMechanism  *mechanism,
  976. -                                     const char            *tz,
  977. -                                     DBusGMethodInvocation *context)
  978. -{
  979. -        GError *error;
  980. -
  981. -        reset_killtimer ();
  982. -        g_debug ("SetTimezone('%s') called", tz);
  983. -
  984. -        if (!_check_polkit_for_action (mechanism, context))
  985. -                return FALSE;
  986. -
  987. -        error = NULL;
  988. -
  989. -        if (!csd_datetime_check_tz_name (tz, &error))
  990. -                return FALSE;
  991. -
  992. -        if (!system_timezone_set (tz, &error)) {
  993. -                GError *error2;
  994. -                int     code;
  995. -
  996. -                if (error->code == SYSTEM_TIMEZONE_ERROR_INVALID_TIMEZONE_FILE)
  997. -                        code = CSD_DATETIME_MECHANISM_ERROR_INVALID_TIMEZONE_FILE;
  998. -                else
  999. -                        code = CSD_DATETIME_MECHANISM_ERROR_GENERAL;
  1000. -
  1001. -                error2 = g_error_new (CSD_DATETIME_MECHANISM_ERROR,
  1002. -                                      code, "%s", error->message);
  1003. -
  1004. -                g_error_free (error);
  1005. -
  1006. -                dbus_g_method_return_error (context, error2);
  1007. -                g_error_free (error2);
  1008. -
  1009. -                return FALSE;
  1010. -        }
  1011. -
  1012. -        dbus_g_method_return (context);
  1013. -        return TRUE;
  1014. -}
  1015. -
  1016. -
  1017. -gboolean
  1018. -csd_datetime_mechanism_get_timezone (CsdDatetimeMechanism   *mechism,
  1019. -                                     DBusGMethodInvocation  *context)
  1020. -{
  1021. -  gchar *timezone;
  1022. -
  1023. -  reset_killtimer ();
  1024. -
  1025. -  timezone = system_timezone_find ();
  1026. -
  1027. -  dbus_g_method_return (context, timezone);
  1028. -
  1029. -  return TRUE;
  1030. -}
  1031. -
  1032. -gboolean
  1033. -csd_datetime_mechanism_get_hardware_clock_using_utc (CsdDatetimeMechanism  *mechanism,
  1034. -                                                     DBusGMethodInvocation *context)
  1035. -{
  1036. -        char **lines;
  1037. -        char *data;
  1038. -        gsize len;
  1039. -        GError *error;
  1040. -        gboolean is_utc;
  1041. -
  1042. -        error = NULL;
  1043. -
  1044. -        if (!g_file_get_contents ("/etc/adjtime", &data, &len, &error)) {
  1045. -                GError *error2;
  1046. -                error2 = g_error_new (CSD_DATETIME_MECHANISM_ERROR,
  1047. -                                      CSD_DATETIME_MECHANISM_ERROR_GENERAL,
  1048. -                                      "Error reading /etc/adjtime file: %s", error->message);
  1049. -                g_error_free (error);
  1050. -                dbus_g_method_return_error (context, error2);
  1051. -                g_error_free (error2);
  1052. -                return FALSE;
  1053. -        }
  1054. -
  1055. -        lines = g_strsplit (data, "\n", 0);
  1056. -        g_free (data);
  1057. -
  1058. -        if (g_strv_length (lines) < 3) {
  1059. -                error = g_error_new (CSD_DATETIME_MECHANISM_ERROR,
  1060. -                                     CSD_DATETIME_MECHANISM_ERROR_GENERAL,
  1061. -                                     "Cannot parse /etc/adjtime");
  1062. -                dbus_g_method_return_error (context, error);
  1063. -                g_error_free (error);
  1064. -                g_strfreev (lines);
  1065. -                return FALSE;
  1066. -        }
  1067. -
  1068. -        if (strcmp (lines[2], "UTC") == 0) {
  1069. -                is_utc = TRUE;
  1070. -        } else if (strcmp (lines[2], "LOCAL") == 0) {
  1071. -                is_utc = FALSE;
  1072. -        } else {
  1073. -                error = g_error_new (CSD_DATETIME_MECHANISM_ERROR,
  1074. -                                     CSD_DATETIME_MECHANISM_ERROR_GENERAL,
  1075. -                                     "Expected UTC or LOCAL at line 3 of /etc/adjtime; found '%s'", lines[2]);
  1076. -                dbus_g_method_return_error (context, error);
  1077. -                g_error_free (error);
  1078. -                g_strfreev (lines);
  1079. -                return FALSE;
  1080. -        }
  1081. -        g_strfreev (lines);
  1082. -        dbus_g_method_return (context, is_utc);
  1083. -        return TRUE;
  1084. -}
  1085. -
  1086. -gboolean
  1087. -csd_datetime_mechanism_set_hardware_clock_using_utc (CsdDatetimeMechanism  *mechanism,
  1088. -                                                     gboolean               using_utc,
  1089. -                                                     DBusGMethodInvocation *context)
  1090. -{
  1091. -        GError *error;
  1092. -
  1093. -        error = NULL;
  1094. -
  1095. -        if (!_check_polkit_for_action (mechanism, context))
  1096. -                return FALSE;
  1097. -
  1098. -        if (g_file_test ("/sbin/hwclock",
  1099. -                         G_FILE_TEST_EXISTS | G_FILE_TEST_IS_REGULAR | G_FILE_TEST_IS_EXECUTABLE)) {
  1100. -                int exit_status;
  1101. -                char *cmd;
  1102. -                cmd = g_strdup_printf ("/sbin/hwclock %s --systohc", using_utc ? "--utc" : "--localtime");
  1103. -                if (!g_spawn_command_line_sync (cmd, NULL, NULL, &exit_status, &error)) {
  1104. -                        GError *error2;
  1105. -                        error2 = g_error_new (CSD_DATETIME_MECHANISM_ERROR,
  1106. -                                              CSD_DATETIME_MECHANISM_ERROR_GENERAL,
  1107. -                                              "Error spawning /sbin/hwclock: %s", error->message);
  1108. -                        g_error_free (error);
  1109. -                        dbus_g_method_return_error (context, error2);
  1110. -                        g_error_free (error2);
  1111. -                        g_free (cmd);
  1112. -                        return FALSE;
  1113. -                }
  1114. -                g_free (cmd);
  1115. -                if (WEXITSTATUS (exit_status) != 0) {
  1116. -                        error = g_error_new (CSD_DATETIME_MECHANISM_ERROR,
  1117. -                                             CSD_DATETIME_MECHANISM_ERROR_GENERAL,
  1118. -                                             "/sbin/hwclock returned %d", exit_status);
  1119. -                        dbus_g_method_return_error (context, error);
  1120. -                        g_error_free (error);
  1121. -                        return FALSE;
  1122. -                }
  1123. -
  1124. -        }
  1125. -        dbus_g_method_return (context);
  1126. -        return TRUE;
  1127. -}
  1128. -
  1129. -gboolean
  1130. -csd_datetime_mechanism_get_using_ntp  (CsdDatetimeMechanism    *mechanism,
  1131. -                                       DBusGMethodInvocation   *context)
  1132. -{
  1133. -        GError *error = NULL;
  1134. -        gboolean ret;
  1135. -
  1136. -        if (g_file_test ("/usr/sbin/update-rc.d", G_FILE_TEST_EXISTS)) /* Debian */
  1137. -                ret = _get_using_ntp_debian (context);
  1138. -        else {
  1139. -                error = g_error_new (CSD_DATETIME_MECHANISM_ERROR,
  1140. -                                     CSD_DATETIME_MECHANISM_ERROR_GENERAL,
  1141. -                                     "Error enabling NTP: OS variant not supported");
  1142. -                dbus_g_method_return_error (context, error);
  1143. -                g_error_free (error);
  1144. -                return FALSE;
  1145. -        }
  1146. -
  1147. -        return ret;
  1148. -}
  1149. -
  1150. -gboolean
  1151. -csd_datetime_mechanism_set_using_ntp  (CsdDatetimeMechanism    *mechanism,
  1152. -                                       gboolean                 using_ntp,
  1153. -                                       DBusGMethodInvocation   *context)
  1154. -{
  1155. -        GError *error;
  1156. -        gboolean ret;
  1157. -
  1158. -        error = NULL;
  1159. -
  1160. -        if (!_check_polkit_for_action (mechanism, context))
  1161. -                return FALSE;
  1162. -
  1163. -        if (g_file_test ("/usr/sbin/update-rc.d", G_FILE_TEST_EXISTS)) /* Debian */
  1164. -                ret = _set_using_ntp_debian (context, using_ntp);
  1165. -        else {
  1166. -                error = g_error_new (CSD_DATETIME_MECHANISM_ERROR,
  1167. -                                     CSD_DATETIME_MECHANISM_ERROR_GENERAL,
  1168. -                                     "Error enabling NTP: OS variant not supported");
  1169. -                dbus_g_method_return_error (context, error);
  1170. -                g_error_free (error);
  1171. -                return FALSE;
  1172. -        }
  1173. -
  1174. -        return ret;
  1175. -}
  1176. -
  1177. -static void
  1178. -check_can_do (CsdDatetimeMechanism  *mechanism,
  1179. -              const char            *action,
  1180. -              DBusGMethodInvocation *context)
  1181. -{
  1182. -        const char *sender;
  1183. -        PolkitSubject *subject;
  1184. -        PolkitAuthorizationResult *result;
  1185. -        GError *error;
  1186. -
  1187. -        /* Check that caller is privileged */
  1188. -        sender = dbus_g_method_get_sender (context);
  1189. -        subject = polkit_system_bus_name_new (sender);
  1190. -
  1191. -        error = NULL;
  1192. -        result = polkit_authority_check_authorization_sync (mechanism->priv->auth,
  1193. -                                                            subject,
  1194. -                                                            action,
  1195. -                                                            NULL,
  1196. -                                                            0,
  1197. -                                                            NULL,
  1198. -                                                            &error);
  1199. -        g_object_unref (subject);
  1200. -
  1201. -        if (error) {
  1202. -                dbus_g_method_return_error (context, error);
  1203. -                g_error_free (error);
  1204. -                return;
  1205. -        }
  1206. -
  1207. -        if (polkit_authorization_result_get_is_authorized (result)) {
  1208. -                dbus_g_method_return (context, 2);
  1209. -        }
  1210. -        else if (polkit_authorization_result_get_is_challenge (result)) {
  1211. -                dbus_g_method_return (context, 1);
  1212. -        }
  1213. -        else {
  1214. -                dbus_g_method_return (context, 0);
  1215. -        }
  1216. -
  1217. -        g_object_unref (result);
  1218. -}
  1219. -
  1220. -
  1221. -gboolean
  1222. -csd_datetime_mechanism_can_set_time (CsdDatetimeMechanism  *mechanism,
  1223. -                                     DBusGMethodInvocation *context)
  1224. -{
  1225. -        check_can_do (mechanism,
  1226. -                      "org.cinnamon.settingsdaemon.datetimemechanism.configure",
  1227. -                      context);
  1228. -
  1229. -        return TRUE;
  1230. -}
  1231. -
  1232. -gboolean
  1233. -csd_datetime_mechanism_can_set_timezone (CsdDatetimeMechanism  *mechanism,
  1234. -                                         DBusGMethodInvocation *context)
  1235. -{
  1236. -        check_can_do (mechanism,
  1237. -                      "org.cinnamon.settingsdaemon.datetimemechanism.configure",
  1238. -                      context);
  1239. -
  1240. -        return TRUE;
  1241. -}
  1242. -
  1243. -gboolean
  1244. -csd_datetime_mechanism_can_set_using_ntp (CsdDatetimeMechanism  *mechanism,
  1245. -                                          DBusGMethodInvocation *context)
  1246. -{
  1247. -        check_can_do (mechanism,
  1248. -                      "org.cinnamon.settingsdaemon.datetimemechanism.configure",
  1249. -                      context);
  1250. -
  1251. -        return TRUE;
  1252. -}
  1253. \ No newline at end of file
  1254. diff --git a/plugins/datetime/csd-datetime-mechanism.h b/plugins/datetime/csd-datetime-mechanism.h
  1255. deleted file mode 100644
  1256. index efc69ac..0000000
  1257. --- a/plugins/datetime/csd-datetime-mechanism.h
  1258. +++ /dev/null
  1259. @@ -1,112 +0,0 @@
  1260. -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
  1261. - *
  1262. - * Copyright (C) 2007 David Zeuthen <david@fubar.dk>
  1263. - *
  1264. - * This program is free software; you can redistribute it and/or modify
  1265. - * it under the terms of the GNU General Public License as published by
  1266. - * the Free Software Foundation; either version 2 of the License, or
  1267. - * (at your option) any later version.
  1268. - *
  1269. - * This program is distributed in the hope that it will be useful,
  1270. - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1271. - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1272. - * GNU General Public License for more details.
  1273. - *
  1274. - * You should have received a copy of the GNU General Public License
  1275. - * along with this program; if not, write to the Free Software
  1276. - * Foundation, Inc., 51 Franklin Street - Suite 500, Boston, MA 02110-1335, USA.
  1277. - *
  1278. - */
  1279. -
  1280. -#ifndef CSD_DATETIME_MECHANISM_H
  1281. -#define CSD_DATETIME_MECHANISM_H
  1282. -
  1283. -#include <glib-object.h>
  1284. -#include <dbus/dbus-glib.h>
  1285. -
  1286. -G_BEGIN_DECLS
  1287. -
  1288. -#define CSD_DATETIME_TYPE_MECHANISM         (csd_datetime_mechanism_get_type ())
  1289. -#define CSD_DATETIME_MECHANISM(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), CSD_DATETIME_TYPE_MECHANISM, CsdDatetimeMechanism))
  1290. -#define CSD_DATETIME_MECHANISM_CLASS(k)     (G_TYPE_CHECK_CLASS_CAST((k), CSD_DATETIME_TYPE_MECHANISM, CsdDatetimeMechanismClass))
  1291. -#define CSD_DATETIME_IS_MECHANISM(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), CSD_DATETIME_TYPE_MECHANISM))
  1292. -#define CSD_DATETIME_IS_MECHANISM_CLASS(k)  (G_TYPE_CHECK_CLASS_TYPE ((k), CSD_DATETIME_TYPE_MECHANISM))
  1293. -#define CSD_DATETIME_MECHANISM_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), CSD_DATETIME_TYPE_MECHANISM, CsdDatetimeMechanismClass))
  1294. -
  1295. -typedef struct CsdDatetimeMechanismPrivate CsdDatetimeMechanismPrivate;
  1296. -
  1297. -typedef struct
  1298. -{
  1299. -        GObject        parent;
  1300. -        CsdDatetimeMechanismPrivate *priv;
  1301. -} CsdDatetimeMechanism;
  1302. -
  1303. -typedef struct
  1304. -{
  1305. -        GObjectClass   parent_class;
  1306. -} CsdDatetimeMechanismClass;
  1307. -
  1308. -typedef enum
  1309. -{
  1310. -        CSD_DATETIME_MECHANISM_ERROR_GENERAL,
  1311. -        CSD_DATETIME_MECHANISM_ERROR_NOT_PRIVILEGED,
  1312. -        CSD_DATETIME_MECHANISM_ERROR_INVALID_TIMEZONE_FILE,
  1313. -        CSD_DATETIME_MECHANISM_NUM_ERRORS
  1314. -} CsdDatetimeMechanismError;
  1315. -
  1316. -#define CSD_DATETIME_MECHANISM_ERROR csd_datetime_mechanism_error_quark ()
  1317. -
  1318. -GType csd_datetime_mechanism_error_get_type (void);
  1319. -#define CSD_DATETIME_MECHANISM_TYPE_ERROR (csd_datetime_mechanism_error_get_type ())
  1320. -
  1321. -
  1322. -GQuark                     csd_datetime_mechanism_error_quark         (void);
  1323. -GType                      csd_datetime_mechanism_get_type            (void);
  1324. -CsdDatetimeMechanism      *csd_datetime_mechanism_new                 (void);
  1325. -
  1326. -/* exported methods */
  1327. -gboolean            csd_datetime_mechanism_get_timezone (CsdDatetimeMechanism   *mechanism,
  1328. -                                                         DBusGMethodInvocation  *context);
  1329. -gboolean            csd_datetime_mechanism_set_timezone (CsdDatetimeMechanism   *mechanism,
  1330. -                                                         const char             *zone_file,
  1331. -                                                         DBusGMethodInvocation  *context);
  1332. -
  1333. -gboolean            csd_datetime_mechanism_can_set_timezone (CsdDatetimeMechanism  *mechanism,
  1334. -                                                             DBusGMethodInvocation *context);
  1335. -
  1336. -gboolean            csd_datetime_mechanism_set_time     (CsdDatetimeMechanism  *mechanism,
  1337. -                                                         gint64                 seconds_since_epoch,
  1338. -                                                         DBusGMethodInvocation *context);
  1339. -
  1340. -gboolean             csd_datetime_mechanism_set_date     (CsdDatetimeMechanism  *mechanism,
  1341. -                                                          guint                  day,
  1342. -                                                          guint                  month,
  1343. -                                                          guint                  year,
  1344. -                                                          DBusGMethodInvocation *context);
  1345. -
  1346. -gboolean            csd_datetime_mechanism_can_set_time (CsdDatetimeMechanism  *mechanism,
  1347. -                                                         DBusGMethodInvocation *context);
  1348. -
  1349. -gboolean            csd_datetime_mechanism_adjust_time  (CsdDatetimeMechanism  *mechanism,
  1350. -                                                         gint64                 seconds_to_add,
  1351. -                                                         DBusGMethodInvocation *context);
  1352. -
  1353. -gboolean            csd_datetime_mechanism_get_hardware_clock_using_utc  (CsdDatetimeMechanism  *mechanism,
  1354. -                                                                          DBusGMethodInvocation *context);
  1355. -
  1356. -gboolean            csd_datetime_mechanism_set_hardware_clock_using_utc  (CsdDatetimeMechanism  *mechanism,
  1357. -                                                                          gboolean               using_utc,
  1358. -                                                                          DBusGMethodInvocation *context);
  1359. -
  1360. -gboolean            csd_datetime_mechanism_get_using_ntp  (CsdDatetimeMechanism    *mechanism,
  1361. -                                                           DBusGMethodInvocation   *context);
  1362. -
  1363. -gboolean            csd_datetime_mechanism_set_using_ntp  (CsdDatetimeMechanism    *mechanism,
  1364. -                                                           gboolean                 using_ntp,
  1365. -                                                           DBusGMethodInvocation   *context);
  1366. -
  1367. -gboolean            csd_datetime_mechanism_can_set_using_ntp (CsdDatetimeMechanism  *mechanism,
  1368. -                                                              DBusGMethodInvocation *context);
  1369. -G_END_DECLS
  1370. -
  1371. -#endif /* CSD_DATETIME_MECHANISM_H */
  1372. diff --git a/plugins/datetime/csd-datetime-mechanism.xml b/plugins/datetime/csd-datetime-mechanism.xml
  1373. deleted file mode 100644
  1374. index c8cd5df..0000000
  1375. --- a/plugins/datetime/csd-datetime-mechanism.xml
  1376. +++ /dev/null
  1377. @@ -1,129 +0,0 @@
  1378. -<!DOCTYPE node PUBLIC "-//freedesktop//DTD D-BUS Object Introspection 1.0//EN" "http://www.freedesktop.org/standards/dbus/1.0/introspect.dtd">
  1379. -<node name="/">
  1380. -  <interface name="org.cinnamon.SettingsDaemon.DateTimeMechanism">
  1381. -    <method name="SetTimezone">
  1382. -      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
  1383. -      <arg name="tz" direction="in" type="s"/>
  1384. -    </method>
  1385. -
  1386. -    <method name="GetTimezone">
  1387. -      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
  1388. -      <arg name="timezone" direction="out" type="s"/>
  1389. -    </method>
  1390. -
  1391. -    <method name="CanSetTimezone">
  1392. -      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
  1393. -      <arg name="value" direction="out" type="i">
  1394. -        <doc:doc>
  1395. -          <doc:summary>Whether the caller can set the timezone</doc:summary>
  1396. -          <doc:description>
  1397. -            <doc:para>
  1398. -              The return value is not a boolean, but an integer with the following meaning:
  1399. -              <doc:list>
  1400. -                <doc:item>
  1401. -                  <doc:term>0</doc:term>
  1402. -                  <doc:definition>the caller cannot set the timezone</doc:definition>
  1403. -                </doc:item>
  1404. -                <doc:item>
  1405. -                  <doc:term>1</doc:term>
  1406. -                  <doc:definition>the caller will be challenged before being able to set the timezone</doc:definition>
  1407. -                </doc:item>
  1408. -                <doc:item>
  1409. -                  <doc:term>2</doc:term>
  1410. -                  <doc:definition>the caller is authorized to set the timezone</doc:definition>
  1411. -                </doc:item>
  1412. -              </doc:list>
  1413. -            </doc:para>
  1414. -          </doc:description>
  1415. -        </doc:doc>
  1416. -      </arg>
  1417. -    </method>
  1418. -    <method name="SetDate">
  1419. -      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
  1420. -      <arg name="day" direction="in" type="u"/>
  1421. -      <arg name="month" direction="in" type="u"/>
  1422. -      <arg name="year" direction="in" type="u"/>
  1423. -    </method>
  1424. -    <method name="SetTime">
  1425. -      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
  1426. -      <arg name="seconds_since_epoch" direction="in" type="x"/>
  1427. -    </method>
  1428. -    <method name="CanSetTime">
  1429. -      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
  1430. -      <arg name="value" direction="out" type="i">
  1431. -        <doc:doc>
  1432. -          <doc:summary>Whether the caller can set the time</doc:summary>
  1433. -          <doc:description>
  1434. -            <doc:para>
  1435. -              The return value is not a boolean, but an integer with the following meaning:
  1436. -              <doc:list>
  1437. -                <doc:item>
  1438. -                  <doc:term>0</doc:term>
  1439. -                  <doc:definition>the caller cannot set the time</doc:definition>
  1440. -                </doc:item>
  1441. -                <doc:item>
  1442. -                  <doc:term>1</doc:term>
  1443. -                  <doc:definition>the caller will be challenged before being able to set the time</doc:definition>
  1444. -                </doc:item>
  1445. -                <doc:item>
  1446. -                  <doc:term>2</doc:term>
  1447. -                  <doc:definition>the caller is authorized to set the time</doc:definition>
  1448. -                </doc:item>
  1449. -              </doc:list>
  1450. -            </doc:para>
  1451. -          </doc:description>
  1452. -        </doc:doc>
  1453. -      </arg>
  1454. -    </method>
  1455. -    <method name="AdjustTime">
  1456. -      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
  1457. -      <arg name="seconds_to_add" direction="in" type="x"/>
  1458. -    </method>
  1459. -
  1460. -    <method name="GetHardwareClockUsingUtc">
  1461. -      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
  1462. -      <arg name="is_using_utc" direction="out" type="b"/>
  1463. -    </method>
  1464. -    <method name="SetHardwareClockUsingUtc">
  1465. -      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
  1466. -      <arg name="is_using_utc" direction="in" type="b"/>
  1467. -    </method>
  1468. -
  1469. -    <method name="GetUsingNtp">
  1470. -      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
  1471. -      <arg name="can_use_ntp" direction="out" type="b"/>
  1472. -      <arg name="is_using_ntp" direction="out" type="b"/>
  1473. -    </method>
  1474. -    <method name="SetUsingNtp">
  1475. -      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
  1476. -      <arg name="is_using_ntp" direction="in" type="b"/>
  1477. -    </method>
  1478. -    <method name="CanSetUsingNtp">
  1479. -      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
  1480. -      <arg name="value" direction="out" type="i">
  1481. -        <doc:doc>
  1482. -          <doc:summary>Whether the caller can set the "use NTP" setting</doc:summary>
  1483. -          <doc:description>
  1484. -            <doc:para>
  1485. -              The return value is not a boolean, but an integer with the following meaning:
  1486. -              <doc:list>
  1487. -                <doc:item>
  1488. -                  <doc:term>0</doc:term>
  1489. -                  <doc:definition>the caller cannot change the "use NTP" setting</doc:definition>
  1490. -                </doc:item>
  1491. -                <doc:item>
  1492. -                  <doc:term>1</doc:term>
  1493. -                  <doc:definition>the caller will be challenged before being able to change "use NTP" setting</doc:definition>
  1494. -                </doc:item>
  1495. -                <doc:item>
  1496. -                  <doc:term>2</doc:term>
  1497. -                  <doc:definition>the caller is authorized to change the "use NTP" setting</doc:definition>
  1498. -                </doc:item>
  1499. -              </doc:list>
  1500. -            </doc:para>
  1501. -          </doc:description>
  1502. -        </doc:doc>
  1503. -      </arg>
  1504. -    </method>
  1505. -  </interface>
  1506. -</node>
  1507. diff --git a/plugins/datetime/org.cinnamon.SettingsDaemon.DateTimeMechanism.conf b/plugins/datetime/org.cinnamon.SettingsDaemon.DateTimeMechanism.conf
  1508. deleted file mode 100644
  1509. index 8895d74..0000000
  1510. --- a/plugins/datetime/org.cinnamon.SettingsDaemon.DateTimeMechanism.conf
  1511. +++ /dev/null
  1512. @@ -1,19 +0,0 @@
  1513. -<?xml version="1.0" encoding="UTF-8"?> <!-- -*- XML -*- -->
  1514. -
  1515. -<!DOCTYPE busconfig PUBLIC
  1516. - "-//freedesktop//DTD D-BUS Bus Configuration 1.0//EN"
  1517. - "http://www.freedesktop.org/standards/dbus/1.0/busconfig.dtd">
  1518. -<busconfig>
  1519. -
  1520. -  <!-- Only root can own the service -->
  1521. -  <policy user="root">
  1522. -    <allow own="org.cinnamon.SettingsDaemon.DateTimeMechanism"/>
  1523. -    <allow send_destination="org.cinnamon.SettingsDaemon.DateTimeMechanism"/>
  1524. -  </policy>
  1525. -
  1526. -  <!-- Allow anyone to invoke methods on the interfaces -->
  1527. -  <policy context="default">
  1528. -    <allow send_destination="org.cinnamon.SettingsDaemon.DateTimeMechanism"/>
  1529. -  </policy>
  1530. -
  1531. -</busconfig>
  1532. diff --git a/plugins/datetime/org.cinnamon.SettingsDaemon.DateTimeMechanism.service.in b/plugins/datetime/org.cinnamon.SettingsDaemon.DateTimeMechanism.service.in
  1533. deleted file mode 100644
  1534. index 4194c55..0000000
  1535. --- a/plugins/datetime/org.cinnamon.SettingsDaemon.DateTimeMechanism.service.in
  1536. +++ /dev/null
  1537. @@ -1,4 +0,0 @@
  1538. -[D-BUS Service]
  1539. -Name=org.cinnamon.SettingsDaemon.DateTimeMechanism
  1540. -Exec=@LIBEXECDIR@/csd-datetime-mechanism
  1541. -User=root
  1542. diff --git a/plugins/datetime/system-timezone.c b/plugins/datetime/system-timezone.c
  1543. deleted file mode 100644
  1544. index bb555fc..0000000
  1545. --- a/plugins/datetime/system-timezone.c
  1546. +++ /dev/null
  1547. @@ -1,924 +0,0 @@
  1548. -/* System timezone handling
  1549. - *
  1550. - * Copyright (C) 2008 Novell, Inc.
  1551. - *
  1552. - * Authors: Vincent Untz <vuntz@gnome.org>
  1553. - *
  1554. - * This program is free software; you can redistribute it and/or modify
  1555. - * it under the terms of the GNU General Public License as published by
  1556. - * the Free Software Foundation; either version 2 of the License, or
  1557. - * (at your option) any later version.
  1558. - *
  1559. - * This program is distributed in the hope that it will be useful,
  1560. - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1561. - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  1562. - * GNU General Public License for more details.
  1563. - *
  1564. - * You should have received a copy of the GNU General Public License
  1565. - * along with this program; if not, write to the Free Software
  1566. - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
  1567. - *
  1568. - * Some code is based on previous code in clock-location.c and on code from
  1569. - * tz.c (shipped with version <= 2.22.0). Those files were under the same
  1570. - * license, with those authors and copyrights:
  1571. - *
  1572. - * clock-location.c:
  1573. - * ================
  1574. - * No header, but most of the work was done (AFAIK) by
  1575. - * Federico Mena Quintero <federico@novell.com>
  1576. - * Matthias Clasen <mclasen@redhat.com>
  1577. - *
  1578. - * tz.c:
  1579. - * ====
  1580. - * Copyright (C) 2000-2001 Ximian, Inc.
  1581. - * Copyright (C) 2004 Sun Microsystems, Inc.
  1582. - *
  1583. - * Authors: Hans Petter Jansson <hpj@ximian.com>
  1584. - *     additional functions by Erwann Chenede <erwann.chenede@sun.com>
  1585. - *     reworked by Vincent Untz <vuntz@gnome.org>
  1586. - *
  1587. - * Largely based on Michael Fulbright's work on Anaconda.
  1588. - */
  1589. -
  1590. -/* FIXME: it'd be nice to filter out the timezones that we might get when
  1591. - * parsing config files that are not in zone.tab. Note that it's also wrong
  1592. - * in some cases: eg, in tzdata2008b, Asia/Calcutta got renamed to
  1593. - * Asia/Kolkata and the old name is not in zone.tab. */
  1594. -
  1595. -#include <string.h>
  1596. -#include <unistd.h>
  1597. -
  1598. -#include <glib.h>
  1599. -#include <glib/gstdio.h>
  1600. -#include <gio/gio.h>
  1601. -
  1602. -#include "system-timezone.h"
  1603. -
  1604. -/* Files that we look at */
  1605. -#define ETC_TIMEZONE        "/etc/timezone"
  1606. -#define ETC_TIMEZONE_MAJ    "/etc/TIMEZONE"
  1607. -#define ETC_RC_CONF         "/etc/rc.conf"
  1608. -#define ETC_SYSCONFIG_CLOCK "/etc/sysconfig/clock"
  1609. -#define ETC_CONF_D_CLOCK    "/etc/conf.d/clock"
  1610. -#define ETC_LOCALTIME       "/etc/localtime"
  1611. -
  1612. -/* The first 4 characters in a timezone file, from tzfile.h */
  1613. -#define TZ_MAGIC "TZif"
  1614. -
  1615. -static GObject *systz_singleton = NULL;
  1616. -
  1617. -G_DEFINE_TYPE (SystemTimezone, system_timezone, G_TYPE_OBJECT)
  1618. -
  1619. -typedef struct {
  1620. -        char *tz;
  1621. -        char *env_tz;
  1622. -} SystemTimezonePrivate;
  1623. -
  1624. -static GObject *system_timezone_constructor (GType                  type,
  1625. -                                             guint                  n_construct_properties,
  1626. -                                             GObjectConstructParam *construct_properties);
  1627. -static void system_timezone_finalize (GObject *obj);
  1628. -
  1629. -#define PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE ((o), SYSTEM_TIMEZONE_TYPE, SystemTimezonePrivate))
  1630. -
  1631. -SystemTimezone *
  1632. -system_timezone_new (void)
  1633. -{
  1634. -        return g_object_new (SYSTEM_TIMEZONE_TYPE, NULL);
  1635. -}
  1636. -
  1637. -const char *
  1638. -system_timezone_get (SystemTimezone *systz)
  1639. -{
  1640. -        SystemTimezonePrivate *priv;
  1641. -
  1642. -        g_return_val_if_fail (IS_SYSTEM_TIMEZONE (systz), NULL);
  1643. -
  1644. -        priv = PRIVATE (systz);
  1645. -        return priv->tz;
  1646. -}
  1647. -
  1648. -const char *
  1649. -system_timezone_get_env (SystemTimezone *systz)
  1650. -{
  1651. -        SystemTimezonePrivate *priv;
  1652. -
  1653. -        g_return_val_if_fail (IS_SYSTEM_TIMEZONE (systz), NULL);
  1654. -
  1655. -        priv = PRIVATE (systz);
  1656. -        return priv->env_tz;
  1657. -}
  1658. -
  1659. -static void
  1660. -system_timezone_class_init (SystemTimezoneClass *class)
  1661. -{
  1662. -        GObjectClass *g_obj_class = G_OBJECT_CLASS (class);
  1663. -
  1664. -        g_obj_class->constructor = system_timezone_constructor;
  1665. -        g_obj_class->finalize = system_timezone_finalize;
  1666. -
  1667. -        g_type_class_add_private (class, sizeof (SystemTimezonePrivate));
  1668. -}
  1669. -
  1670. -static void
  1671. -system_timezone_init (SystemTimezone *systz)
  1672. -{
  1673. -        SystemTimezonePrivate *priv = PRIVATE (systz);
  1674. -
  1675. -        priv->tz = NULL;
  1676. -        priv->env_tz = NULL;
  1677. -}
  1678. -
  1679. -static GObject *
  1680. -system_timezone_constructor (GType                  type,
  1681. -                             guint                  n_construct_properties,
  1682. -                             GObjectConstructParam *construct_properties)
  1683. -{
  1684. -        GObject *obj;
  1685. -        SystemTimezonePrivate *priv;
  1686. -
  1687. -        /* This is a singleton, we don't need to have it per-applet */
  1688. -        if (systz_singleton)
  1689. -                return g_object_ref (systz_singleton);
  1690. -
  1691. -        obj = G_OBJECT_CLASS (system_timezone_parent_class)->constructor (
  1692. -                                                type,
  1693. -                                                n_construct_properties,
  1694. -                                                construct_properties);
  1695. -
  1696. -        priv = PRIVATE (obj);
  1697. -
  1698. -        priv->tz = system_timezone_find ();
  1699. -
  1700. -        priv->env_tz = g_strdup (g_getenv ("TZ"));
  1701. -
  1702. -        systz_singleton = obj;
  1703. -
  1704. -        return systz_singleton;
  1705. -}
  1706. -
  1707. -static void
  1708. -system_timezone_finalize (GObject *obj)
  1709. -{
  1710. -        SystemTimezonePrivate *priv = PRIVATE (obj);
  1711. -
  1712. -        if (priv->tz) {
  1713. -                g_free (priv->tz);
  1714. -                priv->tz = NULL;
  1715. -        }
  1716. -
  1717. -        if (priv->env_tz) {
  1718. -                g_free (priv->env_tz);
  1719. -                priv->env_tz = NULL;
  1720. -        }
  1721. -
  1722. -        G_OBJECT_CLASS (system_timezone_parent_class)->finalize (obj);
  1723. -
  1724. -        g_assert (obj == systz_singleton);
  1725. -
  1726. -        systz_singleton = NULL;
  1727. -}
  1728. -
  1729. -/*
  1730. - * Code to deal with the system timezone on all distros.
  1731. - * There's no dependency on the SystemTimezone GObject here.
  1732. - *
  1733. - * Here's what we know:
  1734. - *
  1735. - *  + /etc/localtime contains the binary data of the timezone.
  1736. - *    It can be a symlink to the actual data file, a hard link to the data
  1737. - *    file, or just a copy. So we can determine the timezone with this
  1738. - *    (reading the symlink, comparing inodes, or comparing content).
  1739. - *
  1740. - *  + However, most distributions also have the timezone setting
  1741. - *    configured somewhere else. This might be better to read it from there.
  1742. - *
  1743. - *    Debian/Ubuntu/Gentoo (new): content of /etc/timezone
  1744. - *    Fedora/Mandriva: the ZONE key in /etc/sysconfig/clock
  1745. - *    openSUSE: the TIMEZONE key in /etc/sysconfig/clock
  1746. - *    Solaris/OpenSolaris: the TZ key in /etc/TIMEZONE
  1747. - *    Arch Linux: the TIMEZONE key in /etc/rc.conf
  1748. - *    Gentoo (old): the ZONE key in /etc/conf.d/clock
  1749. - *
  1750. - *    FIXME: reading the system-tools-backends, it seems there's this too:
  1751. - *           Solaris: the TZ key in /etc/default/init
  1752. - *                    /etc/TIMEZONE seems to be a link to /etc/default/init
  1753. - *
  1754. - * First, some functions to handle those system config files.
  1755. - *
  1756. - */
  1757. -
  1758. -/* This works for Debian and derivatives (including Ubuntu), and new Gentoo */
  1759. -static char *
  1760. -system_timezone_read_etc_timezone (void)
  1761. -{
  1762. -        FILE    *etc_timezone;
  1763. -        GString *reading;
  1764. -        int      c;
  1765. -
  1766. -        etc_timezone = g_fopen (ETC_TIMEZONE, "r");
  1767. -        if (!etc_timezone)
  1768. -                return NULL;
  1769. -
  1770. -        reading = g_string_new ("");
  1771. -
  1772. -        c = fgetc (etc_timezone);
  1773. -        /* only get the first line, we'll validate the value later */
  1774. -        while (c != EOF && !g_ascii_isspace (c)) {
  1775. -                reading = g_string_append_c (reading, c);
  1776. -                c = fgetc (etc_timezone);
  1777. -        }
  1778. -
  1779. -        fclose (etc_timezone);
  1780. -
  1781. -        if (reading->str && reading->str[0] != '\0')
  1782. -                return g_string_free (reading, FALSE);
  1783. -        else
  1784. -                g_string_free (reading, TRUE);
  1785. -
  1786. -        return NULL;
  1787. -}
  1788. -
  1789. -static gboolean
  1790. -system_timezone_write_etc_timezone (const char  *tz,
  1791. -                                    GError     **error)
  1792. -{
  1793. -        char     *content;
  1794. -        GError   *our_error;
  1795. -        gboolean  retval;
  1796. -
  1797. -        if (!g_file_test (ETC_TIMEZONE, G_FILE_TEST_IS_REGULAR))
  1798. -                return TRUE;
  1799. -
  1800. -        content = g_strdup_printf ("%s\n", tz);
  1801. -
  1802. -        our_error = NULL;
  1803. -        retval = g_file_set_contents (ETC_TIMEZONE, content, -1, &our_error);
  1804. -        g_free (content);
  1805. -
  1806. -        if (!retval) {
  1807. -                g_set_error (error, SYSTEM_TIMEZONE_ERROR,
  1808. -                             SYSTEM_TIMEZONE_ERROR_GENERAL,
  1809. -                             ETC_TIMEZONE" cannot be overwritten: %s",
  1810. -                             our_error->message);
  1811. -                g_error_free (our_error);
  1812. -        }
  1813. -
  1814. -        return retval;
  1815. -}
  1816. -
  1817. -
  1818. -/* Read a file that looks like a key-file (but there's no need for groups)
  1819. - * and get the last value for a specific key */
  1820. -static char *
  1821. -system_timezone_read_key_file (const char *filename,
  1822. -                               const char *key)
  1823. -{
  1824. -        GIOChannel *channel;
  1825. -        char       *key_eq;
  1826. -        char       *line;
  1827. -        char       *retval;
  1828. -
  1829. -        if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR))
  1830. -                return NULL;
  1831. -
  1832. -        channel = g_io_channel_new_file (filename, "r", NULL);
  1833. -        if (!channel)
  1834. -                return NULL;
  1835. -
  1836. -        key_eq = g_strdup_printf ("%s=", key);
  1837. -        retval = NULL;
  1838. -
  1839. -        while (g_io_channel_read_line (channel, &line, NULL,
  1840. -                                       NULL, NULL) == G_IO_STATUS_NORMAL) {
  1841. -                if (g_str_has_prefix (line, key_eq)) {
  1842. -                        char *value;
  1843. -                        int   len;
  1844. -
  1845. -                        value = line + strlen (key_eq);
  1846. -                        g_strstrip (value);
  1847. -
  1848. -                        len = strlen (value);
  1849. -
  1850. -                        if (value[0] == '\"') {
  1851. -                                if (value[len - 1] == '\"') {
  1852. -                                        if (retval)
  1853. -                                                g_free (retval);
  1854. -
  1855. -                                        retval = g_strndup (value + 1,
  1856. -                                                            len - 2);
  1857. -                                }
  1858. -                        } else {
  1859. -                                if (retval)
  1860. -                                        g_free (retval);
  1861. -
  1862. -                                retval = g_strdup (line + strlen (key_eq));
  1863. -                        }
  1864. -
  1865. -                        g_strstrip (retval);
  1866. -                }
  1867. -
  1868. -                g_free (line);
  1869. -        }
  1870. -
  1871. -        g_free (key_eq);
  1872. -        g_io_channel_unref (channel);
  1873. -
  1874. -        return retval;
  1875. -}
  1876. -
  1877. -static gboolean
  1878. -system_timezone_write_key_file (const char  *filename,
  1879. -                                const char  *key,
  1880. -                                const char  *value,
  1881. -                                GError     **error)
  1882. -{
  1883. -        GError    *our_error;
  1884. -        char      *content;
  1885. -        gsize      len;
  1886. -        char      *key_eq;
  1887. -        char     **lines;
  1888. -        gboolean   replaced;
  1889. -        gboolean   retval;
  1890. -        int        n;
  1891. -        
  1892. -        if (!g_file_test (filename, G_FILE_TEST_IS_REGULAR))
  1893. -                return TRUE;
  1894. -
  1895. -        our_error = NULL;
  1896. -
  1897. -        if (!g_file_get_contents (filename, &content, &len, &our_error)) {
  1898. -                g_set_error (error, SYSTEM_TIMEZONE_ERROR,
  1899. -                             SYSTEM_TIMEZONE_ERROR_GENERAL,
  1900. -                             "%s cannot be read: %s",
  1901. -                             filename, our_error->message);
  1902. -                g_error_free (our_error);
  1903. -                return FALSE;
  1904. -        }
  1905. -
  1906. -        lines = g_strsplit (content, "\n", 0);
  1907. -        g_free (content);
  1908. -
  1909. -        key_eq = g_strdup_printf ("%s=", key);
  1910. -        replaced = FALSE;
  1911. -
  1912. -        for (n = 0; lines[n] != NULL; n++) {
  1913. -                if (g_str_has_prefix (lines[n], key_eq)) {
  1914. -                        char     *old_value;
  1915. -                        gboolean  use_quotes;
  1916. -
  1917. -                        old_value = lines[n] + strlen (key_eq);
  1918. -                        g_strstrip (old_value);
  1919. -                        use_quotes = old_value[0] == '\"';
  1920. -
  1921. -                        g_free (lines[n]);
  1922. -
  1923. -                        if (use_quotes)
  1924. -                                lines[n] = g_strdup_printf ("%s\"%s\"",
  1925. -                                                            key_eq, value);
  1926. -                        else
  1927. -                                lines[n] = g_strdup_printf ("%s%s",
  1928. -                                                            key_eq, value);
  1929. -
  1930. -                        replaced = TRUE;
  1931. -                }
  1932. -        }
  1933. -
  1934. -        g_free (key_eq);
  1935. -
  1936. -        if (!replaced) {
  1937. -                g_strfreev (lines);
  1938. -                return TRUE;
  1939. -        }
  1940. -
  1941. -        content = g_strjoinv ("\n", lines);
  1942. -        g_strfreev (lines);
  1943. -
  1944. -        retval = g_file_set_contents (filename, content, -1, &our_error);
  1945. -        g_free (content);
  1946. -
  1947. -        if (!retval) {
  1948. -                g_set_error (error, SYSTEM_TIMEZONE_ERROR,
  1949. -                             SYSTEM_TIMEZONE_ERROR_GENERAL,
  1950. -                             "%s cannot be overwritten: %s",
  1951. -                             filename, our_error->message);
  1952. -                g_error_free (our_error);
  1953. -        }
  1954. -
  1955. -        return retval;
  1956. -}
  1957. -
  1958. -/* This works for Solaris/OpenSolaris */
  1959. -static char *
  1960. -system_timezone_read_etc_TIMEZONE (void)
  1961. -{
  1962. -        return system_timezone_read_key_file (ETC_TIMEZONE_MAJ,
  1963. -                                              "TZ");
  1964. -}
  1965. -
  1966. -static gboolean
  1967. -system_timezone_write_etc_TIMEZONE (const char  *tz,
  1968. -                                    GError     **error)
  1969. -{
  1970. -        return system_timezone_write_key_file (ETC_TIMEZONE_MAJ,
  1971. -                                               "TZ", tz, error);
  1972. -}
  1973. -
  1974. -/* This works for Fedora and Mandriva */
  1975. -static char *
  1976. -system_timezone_read_etc_sysconfig_clock (void)
  1977. -{
  1978. -        return system_timezone_read_key_file (ETC_SYSCONFIG_CLOCK,
  1979. -                                              "ZONE");
  1980. -}
  1981. -
  1982. -static gboolean
  1983. -system_timezone_write_etc_sysconfig_clock (const char  *tz,
  1984. -                                           GError     **error)
  1985. -{
  1986. -        return system_timezone_write_key_file (ETC_SYSCONFIG_CLOCK,
  1987. -                                               "ZONE", tz, error);
  1988. -}
  1989. -
  1990. -/* This works for openSUSE */
  1991. -static char *
  1992. -system_timezone_read_etc_sysconfig_clock_alt (void)
  1993. -{
  1994. -        return system_timezone_read_key_file (ETC_SYSCONFIG_CLOCK,
  1995. -                                              "TIMEZONE");
  1996. -}
  1997. -
  1998. -static gboolean
  1999. -system_timezone_write_etc_sysconfig_clock_alt (const char  *tz,
  2000. -                                               GError     **error)
  2001. -{
  2002. -        return system_timezone_write_key_file (ETC_SYSCONFIG_CLOCK,
  2003. -                                               "TIMEZONE", tz, error);
  2004. -}
  2005. -
  2006. -/* This works for old Gentoo */
  2007. -static char *
  2008. -system_timezone_read_etc_conf_d_clock (void)
  2009. -{
  2010. -        return system_timezone_read_key_file (ETC_CONF_D_CLOCK,
  2011. -                                              "TIMEZONE");
  2012. -}
  2013. -
  2014. -static gboolean
  2015. -system_timezone_write_etc_conf_d_clock (const char  *tz,
  2016. -                                        GError     **error)
  2017. -{
  2018. -        return system_timezone_write_key_file (ETC_CONF_D_CLOCK,
  2019. -                                               "TIMEZONE", tz, error);
  2020. -}
  2021. -
  2022. -/* This works for Arch Linux */
  2023. -static char *
  2024. -system_timezone_read_etc_rc_conf (void)
  2025. -{
  2026. -        return system_timezone_read_key_file (ETC_RC_CONF,
  2027. -                                              "TIMEZONE");
  2028. -}
  2029. -
  2030. -static gboolean
  2031. -system_timezone_write_etc_rc_conf (const char  *tz,
  2032. -                                   GError     **error)
  2033. -{
  2034. -        return system_timezone_write_key_file (ETC_RC_CONF,
  2035. -                                               "TIMEZONE", tz, error);
  2036. -}
  2037. -
  2038. -/*
  2039. - *
  2040. - * First, getting the timezone.
  2041. - *
  2042. - */
  2043. -
  2044. -static char *
  2045. -system_timezone_strip_path_if_valid (const char *filename)
  2046. -{
  2047. -        int skip;
  2048. -
  2049. -        if (!filename || !g_str_has_prefix (filename, SYSTEM_ZONEINFODIR"/"))
  2050. -                return NULL;
  2051. -
  2052. -        /* Timezone data files also live under posix/ and right/ for some
  2053. -         * reason.
  2054. -         * FIXME: make sure accepting those files is valid. I think "posix" is
  2055. -         * okay, not sure about "right" */
  2056. -        if (g_str_has_prefix (filename, SYSTEM_ZONEINFODIR"/posix/"))
  2057. -                skip = strlen (SYSTEM_ZONEINFODIR"/posix/");
  2058. -        else if (g_str_has_prefix (filename, SYSTEM_ZONEINFODIR"/right/"))
  2059. -                skip = strlen (SYSTEM_ZONEINFODIR"/right/");
  2060. -        else
  2061. -                skip = strlen (SYSTEM_ZONEINFODIR"/");
  2062. -
  2063. -        return g_strdup (filename + skip);
  2064. -}
  2065. -
  2066. -/* Read the soft symlink from /etc/localtime */
  2067. -static char *
  2068. -system_timezone_read_etc_localtime_softlink (void)
  2069. -{
  2070. -        char *file;
  2071. -        char *tz;
  2072. -
  2073. -        if (!g_file_test (ETC_LOCALTIME, G_FILE_TEST_IS_SYMLINK))
  2074. -                return NULL;
  2075. -
  2076. -        file = g_file_read_link (ETC_LOCALTIME, NULL);
  2077. -        tz = system_timezone_strip_path_if_valid (file);
  2078. -        g_free (file);
  2079. -
  2080. -        return tz;
  2081. -}
  2082. -
  2083. -typedef gboolean (*CompareFiles) (struct stat *a_stat,
  2084. -                                  struct stat *b_stat,
  2085. -                                  const char  *a_content,
  2086. -                                  gsize        a_content_len,
  2087. -                                  const char  *b_filename);
  2088. -
  2089. -static char *
  2090. -recursive_compare (struct stat  *localtime_stat,
  2091. -                   const char   *localtime_content,
  2092. -                   gsize         localtime_content_len,
  2093. -                   char         *file,
  2094. -                   CompareFiles  compare_func)
  2095. -{
  2096. -        struct stat file_stat;
  2097. -
  2098. -        if (g_stat (file, &file_stat) != 0)
  2099. -                return NULL;
  2100. -
  2101. -        if (S_ISREG (file_stat.st_mode)) {
  2102. -                if (compare_func (localtime_stat,
  2103. -                                  &file_stat,
  2104. -                                  localtime_content,
  2105. -                                  localtime_content_len,
  2106. -                                  file))
  2107. -                        return system_timezone_strip_path_if_valid (file);
  2108. -                else
  2109. -                        return NULL;
  2110. -        } else if (S_ISDIR (file_stat.st_mode)) {
  2111. -                GDir       *dir = NULL;
  2112. -                char       *ret = NULL;
  2113. -                const char *subfile = NULL;
  2114. -                char       *subpath = NULL;
  2115. -
  2116. -                dir = g_dir_open (file, 0, NULL);
  2117. -                if (dir == NULL)
  2118. -                        return NULL;
  2119. -
  2120. -                while ((subfile = g_dir_read_name (dir)) != NULL) {
  2121. -                        subpath = g_build_filename (file, subfile, NULL);
  2122. -
  2123. -                        ret = recursive_compare (localtime_stat,
  2124. -                                                 localtime_content,
  2125. -                                                 localtime_content_len,
  2126. -                                                 subpath,
  2127. -                                                 compare_func);
  2128. -
  2129. -                        g_free (subpath);
  2130. -
  2131. -                        if (ret != NULL)
  2132. -                                break;
  2133. -                }
  2134. -
  2135. -                g_dir_close (dir);
  2136. -
  2137. -                return ret;
  2138. -        }
  2139. -
  2140. -        return NULL;
  2141. -}
  2142. -
  2143. -
  2144. -static gboolean
  2145. -files_are_identical_inode (struct stat *a_stat,
  2146. -                           struct stat *b_stat,
  2147. -                           const char  *a_content,
  2148. -                           gsize        a_content_len,
  2149. -                           const char  *b_filename)
  2150. -{
  2151. -        return (a_stat->st_ino == b_stat->st_ino);
  2152. -}
  2153. -
  2154. -
  2155. -/* Determine if /etc/localtime is a hard link to some file, by looking at
  2156. - * the inodes */
  2157. -static char *
  2158. -system_timezone_read_etc_localtime_hardlink (void)
  2159. -{
  2160. -        struct stat stat_localtime;
  2161. -
  2162. -        if (g_stat (ETC_LOCALTIME, &stat_localtime) != 0)
  2163. -                return NULL;
  2164. -
  2165. -        if (!S_ISREG (stat_localtime.st_mode))
  2166. -                return NULL;
  2167. -
  2168. -        return recursive_compare (&stat_localtime,
  2169. -                                  NULL,
  2170. -                                  0,
  2171. -                                  SYSTEM_ZONEINFODIR,
  2172. -                                  files_are_identical_inode);
  2173. -}
  2174. -
  2175. -static gboolean
  2176. -files_are_identical_content (struct stat *a_stat,
  2177. -                             struct stat *b_stat,
  2178. -                             const char  *a_content,
  2179. -                             gsize        a_content_len,
  2180. -                             const char  *b_filename)
  2181. -{
  2182. -        char  *b_content = NULL;
  2183. -        gsize  b_content_len = -1;
  2184. -        int    cmp;
  2185. -
  2186. -        if (a_stat->st_size != b_stat->st_size)
  2187. -                return FALSE;
  2188. -
  2189. -        if (!g_file_get_contents (b_filename,
  2190. -                                  &b_content, &b_content_len, NULL))
  2191. -                return FALSE;
  2192. -
  2193. -        if (a_content_len != b_content_len) {
  2194. -                g_free (b_content);
  2195. -                return FALSE;
  2196. -        }
  2197. -
  2198. -        cmp = memcmp (a_content, b_content, a_content_len);
  2199. -        g_free (b_content);
  2200. -
  2201. -        return (cmp == 0);
  2202. -}
  2203. -
  2204. -/* Determine if /etc/localtime is a copy of a timezone file */
  2205. -static char *
  2206. -system_timezone_read_etc_localtime_content (void)
  2207. -{
  2208. -        struct stat  stat_localtime;
  2209. -        char        *localtime_content = NULL;
  2210. -        gsize        localtime_content_len = -1;
  2211. -        char        *retval;
  2212. -
  2213. -        if (g_stat (ETC_LOCALTIME, &stat_localtime) != 0)
  2214. -                return NULL;
  2215. -
  2216. -        if (!S_ISREG (stat_localtime.st_mode))
  2217. -                return NULL;
  2218. -
  2219. -        if (!g_file_get_contents (ETC_LOCALTIME,
  2220. -                                  &localtime_content,
  2221. -                                  &localtime_content_len,
  2222. -                                  NULL))
  2223. -                return NULL;
  2224. -
  2225. -        retval = recursive_compare (&stat_localtime,
  2226. -                                   localtime_content,
  2227. -                                   localtime_content_len,
  2228. -                                   SYSTEM_ZONEINFODIR,
  2229. -                                   files_are_identical_content);
  2230. -
  2231. -        g_free (localtime_content);
  2232. -
  2233. -        return retval;
  2234. -}
  2235. -
  2236. -typedef char * (*GetSystemTimezone) (void);
  2237. -/* The order of the functions here define the priority of the methods used
  2238. - * to find the timezone. First method has higher priority. */
  2239. -static GetSystemTimezone get_system_timezone_methods[] = {
  2240. -        /* cheap and "more correct" than data from a config file */
  2241. -        system_timezone_read_etc_localtime_softlink,
  2242. -        /* reading various config files */
  2243. -        system_timezone_read_etc_timezone,
  2244. -        system_timezone_read_etc_sysconfig_clock,
  2245. -        system_timezone_read_etc_sysconfig_clock_alt,
  2246. -        system_timezone_read_etc_TIMEZONE,
  2247. -        system_timezone_read_etc_rc_conf,
  2248. -        /* reading deprecated config files */
  2249. -        system_timezone_read_etc_conf_d_clock,
  2250. -        /* reading /etc/timezone directly. Expensive since we have to stat
  2251. -         * many files */
  2252. -        system_timezone_read_etc_localtime_hardlink,
  2253. -        system_timezone_read_etc_localtime_content,
  2254. -        NULL
  2255. -};
  2256. -
  2257. -static gboolean
  2258. -system_timezone_is_valid (const char *tz)
  2259. -{
  2260. -        const char *c;
  2261. -
  2262. -        if (!tz)
  2263. -                return FALSE;
  2264. -
  2265. -        for (c = tz; *c != '\0'; c++) {
  2266. -                if (!(g_ascii_isalnum (*c) ||
  2267. -                      *c == '/' || *c == '-' || *c == '_'))
  2268. -                        return FALSE;
  2269. -        }
  2270. -
  2271. -        return TRUE;
  2272. -}
  2273. -
  2274. -char *
  2275. -system_timezone_find (void)
  2276. -{
  2277. -        char *tz;
  2278. -        int   i;
  2279. -
  2280. -        for (i = 0; get_system_timezone_methods[i] != NULL; i++) {
  2281. -                tz = get_system_timezone_methods[i] ();
  2282. -
  2283. -                if (system_timezone_is_valid (tz))
  2284. -                        return tz;
  2285. -
  2286. -                g_free (tz);
  2287. -        }
  2288. -
  2289. -        return g_strdup ("UTC");
  2290. -}
  2291. -
  2292. -/*
  2293. - *
  2294. - * Now, setting the timezone.
  2295. - *
  2296. - */
  2297. -
  2298. -static gboolean
  2299. -system_timezone_is_zone_file_valid (const char  *zone_file,
  2300. -                                    GError     **error)
  2301. -{
  2302. -        GError     *our_error;
  2303. -        GIOChannel *channel;
  2304. -        char        buffer[strlen (TZ_MAGIC)];
  2305. -        gsize       read;
  2306. -
  2307. -        /* First, check the zone_file is properly rooted */
  2308. -        if (!g_str_has_prefix (zone_file, SYSTEM_ZONEINFODIR"/")) {
  2309. -                g_set_error (error, SYSTEM_TIMEZONE_ERROR,
  2310. -                             SYSTEM_TIMEZONE_ERROR_INVALID_TIMEZONE_FILE,
  2311. -                             "Timezone file needs to be under "SYSTEM_ZONEINFODIR);
  2312. -                return FALSE;
  2313. -        }
  2314. -
  2315. -        /* Second, check it's a regular file that exists */
  2316. -        if (!g_file_test (zone_file, G_FILE_TEST_IS_REGULAR)) {
  2317. -                g_set_error (error, SYSTEM_TIMEZONE_ERROR,
  2318. -                             SYSTEM_TIMEZONE_ERROR_INVALID_TIMEZONE_FILE,
  2319. -                             "No such timezone file %s", zone_file);
  2320. -                return FALSE;
  2321. -        }
  2322. -
  2323. -        /* Third, check that it's a tzfile (see tzfile(5)). The file has a 4
  2324. -         * bytes header which is TZ_MAGIC.
  2325. -         *
  2326. -         * TODO: is there glibc API for this? */
  2327. -        our_error = NULL;
  2328. -        channel = g_io_channel_new_file (zone_file, "r", &our_error);
  2329. -        if (!our_error)
  2330. -                g_io_channel_read_chars (channel,
  2331. -                                         buffer, strlen (TZ_MAGIC),
  2332. -                                         &read, &our_error);
  2333. -        if (channel)
  2334. -                g_io_channel_unref (channel);
  2335. -
  2336. -        if (our_error) {
  2337. -                g_set_error (error, SYSTEM_TIMEZONE_ERROR,
  2338. -                             SYSTEM_TIMEZONE_ERROR_INVALID_TIMEZONE_FILE,
  2339. -                             "Timezone file %s cannot be read: %s",
  2340. -                             zone_file, our_error->message);
  2341. -                g_error_free (our_error);
  2342. -                return FALSE;
  2343. -        }
  2344. -
  2345. -        if (read != strlen (TZ_MAGIC) || strncmp (buffer, TZ_MAGIC, strlen (TZ_MAGIC)) != 0) {
  2346. -                g_set_error (error, SYSTEM_TIMEZONE_ERROR,
  2347. -                             SYSTEM_TIMEZONE_ERROR_INVALID_TIMEZONE_FILE,
  2348. -                             "%s is not a timezone file",
  2349. -                             zone_file);
  2350. -                return FALSE;
  2351. -        }
  2352. -
  2353. -        return TRUE;
  2354. -}
  2355. -
  2356. -static gboolean
  2357. -system_timezone_set_etc_timezone (const char  *zone_file,
  2358. -                                  GError     **error)
  2359. -{
  2360. -        GError *our_error;
  2361. -        char   *content;
  2362. -        gsize   len;
  2363. -
  2364. -        if (!system_timezone_is_zone_file_valid (zone_file, error))
  2365. -                return FALSE;
  2366. -
  2367. -        /* If /etc/localtime is a symlink, write a symlink */
  2368. -        if (g_file_test (ETC_LOCALTIME, G_FILE_TEST_IS_SYMLINK)) {
  2369. -                if (g_unlink (ETC_LOCALTIME) == 0 &&
  2370. -                    symlink (zone_file, ETC_LOCALTIME) == 0)
  2371. -                        return TRUE;
  2372. -
  2373. -                /* If we couldn't symlink the file, we'll just fallback on
  2374. -                 * copying it */
  2375. -        }
  2376. -
  2377. -        /* Else copy the file to /etc/localtime. We explicitly avoid doing
  2378. -         * hard links since they break with different partitions */
  2379. -        our_error = NULL;
  2380. -        if (!g_file_get_contents (zone_file, &content, &len, &our_error)) {
  2381. -                g_set_error (error, SYSTEM_TIMEZONE_ERROR,
  2382. -                             SYSTEM_TIMEZONE_ERROR_GENERAL,
  2383. -                             "Timezone file %s cannot be read: %s",
  2384. -                             zone_file, our_error->message);
  2385. -                g_error_free (our_error);
  2386. -                return FALSE;
  2387. -        }
  2388. -
  2389. -        if (!g_file_set_contents (ETC_LOCALTIME, content, len, &our_error)) {
  2390. -                g_set_error (error, SYSTEM_TIMEZONE_ERROR,
  2391. -                             SYSTEM_TIMEZONE_ERROR_GENERAL,
  2392. -                             ETC_LOCALTIME" cannot be overwritten: %s",
  2393. -                             our_error->message);
  2394. -                g_error_free (our_error);
  2395. -                g_free (content);
  2396. -                return FALSE;
  2397. -        }
  2398. -
  2399. -        g_free (content);
  2400. -
  2401. -        return TRUE;
  2402. -}
  2403. -
  2404. -typedef gboolean (*SetSystemTimezone) (const char  *tz,
  2405. -                                       GError     **error);
  2406. -/* The order here does not matter too much: we'll try to change all files
  2407. - * that already have a timezone configured. It matters in case of error,
  2408. - * since the process will be stopped and the last methods won't be called.
  2409. - * So we use the same order as in get_system_timezone_methods */
  2410. -static SetSystemTimezone set_system_timezone_methods[] = {
  2411. -        /* writing various config files if they exist and have the
  2412. -         * setting already present */
  2413. -        system_timezone_write_etc_timezone,
  2414. -        system_timezone_write_etc_sysconfig_clock,
  2415. -        system_timezone_write_etc_sysconfig_clock_alt,
  2416. -        system_timezone_write_etc_TIMEZONE,
  2417. -        system_timezone_write_etc_rc_conf,
  2418. -        /* writing deprecated config files if they exist and have the
  2419. -         * setting already present */
  2420. -        system_timezone_write_etc_conf_d_clock,
  2421. -        NULL
  2422. -};
  2423. -
  2424. -static gboolean
  2425. -system_timezone_update_config (const char  *tz,
  2426. -                               GError     **error)
  2427. -{
  2428. -        int i;
  2429. -
  2430. -        for (i = 0; set_system_timezone_methods[i] != NULL; i++) {
  2431. -                if (!set_system_timezone_methods[i] (tz, error))
  2432. -                        return FALSE;
  2433. -                /* FIXME: maybe continue to change all config files if
  2434. -                 * possible? */
  2435. -        }
  2436. -
  2437. -        return TRUE;
  2438. -}
  2439. -
  2440. -gboolean
  2441. -system_timezone_set (const char  *tz,
  2442. -                     GError     **error)
  2443. -{
  2444. -        char     *zone_file;
  2445. -        gboolean  retval;
  2446. -
  2447. -        g_return_val_if_fail (error == NULL || *error == NULL, FALSE);
  2448. -
  2449. -        zone_file = g_build_filename (SYSTEM_ZONEINFODIR, tz, NULL);
  2450. -
  2451. -        /* FIXME: is it right to return FALSE even when /etc/localtime was
  2452. -         * changed but not the config files? */
  2453. -        retval = system_timezone_set_etc_timezone (zone_file, error) &&
  2454. -                 system_timezone_update_config (tz, error);
  2455. -
  2456. -        g_free (zone_file);
  2457. -
  2458. -        return retval;
  2459. -}
  2460. -
  2461. -GQuark
  2462. -system_timezone_error_quark (void)
  2463. -{
  2464. -        static GQuark ret = 0;
  2465. -
  2466. -        if (ret == 0) {
  2467. -                ret = g_quark_from_static_string ("system-timezone-error");
  2468. -        }
  2469. -
  2470. -        return ret;
  2471. -}
  2472. diff --git a/plugins/datetime/system-timezone.h b/plugins/datetime/system-timezone.h
  2473. deleted file mode 100644
  2474. index 140b065..0000000
  2475. --- a/plugins/datetime/system-timezone.h
  2476. +++ /dev/null
  2477. @@ -1,80 +0,0 @@
  2478. -/* System timezone handling
  2479. - *
  2480. - * Copyright (C) 2008 Novell, Inc.
  2481. - *
  2482. - * Authors: Vincent Untz <vuntz@gnome.org>
  2483. - *
  2484. - * This program is free software; you can redistribute it and/or modify
  2485. - * it under the terms of the GNU General Public License as published by
  2486. - * the Free Software Foundation; either version 2 of the License, or
  2487. - * (at your option) any later version.
  2488. - *
  2489. - * This program is distributed in the hope that it will be useful,
  2490. - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2491. - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  2492. - * GNU General Public License for more details.
  2493. - *
  2494. - * You should have received a copy of the GNU General Public License
  2495. - * along with this program; if not, write to the Free Software
  2496. - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
  2497. - */
  2498. -
  2499. -#ifndef __SYSTEM_TIMEZONE_H__
  2500. -#define __SYSTEM_TIMEZONE_H__
  2501. -
  2502. -#include <glib.h>
  2503. -#include <glib-object.h>
  2504. -
  2505. -G_BEGIN_DECLS
  2506. -
  2507. -#ifdef HAVE_SOLARIS
  2508. -#define SYSTEM_ZONEINFODIR "/usr/share/lib/zoneinfo/tab"
  2509. -#else
  2510. -#define SYSTEM_ZONEINFODIR "/usr/share/zoneinfo"
  2511. -#endif
  2512. -
  2513. -
  2514. -#define SYSTEM_TIMEZONE_TYPE         (system_timezone_get_type ())
  2515. -#define SYSTEM_TIMEZONE(o)           (G_TYPE_CHECK_INSTANCE_CAST ((o), SYSTEM_TIMEZONE_TYPE, SystemTimezone))
  2516. -#define SYSTEM_TIMEZONE_CLASS(c)     (G_TYPE_CHECK_CLASS_CAST ((c), SYSTEM_TIMEZONE_TYPE, SystemTimezoneClass))
  2517. -#define IS_SYSTEM_TIMEZONE(o)        (G_TYPE_CHECK_INSTANCE_TYPE ((o), SYSTEM_TIMEZONE_TYPE))
  2518. -#define IS_SYSTEM_TIMEZONE_CLASS(c)  (G_TYPE_CHECK_CLASS_TYPE ((c), SYSTEM_TIMEZONE_TYPE))
  2519. -#define SYSTEM_TIMEZONE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), SYSTEM_TIMEZONE_TYPE, SystemTimezoneClass))
  2520. -
  2521. -typedef struct
  2522. -{
  2523. -        GObject g_object;
  2524. -} SystemTimezone;
  2525. -
  2526. -typedef struct
  2527. -{
  2528. -        GObjectClass g_object_class;
  2529. -} SystemTimezoneClass;
  2530. -
  2531. -GType system_timezone_get_type (void);
  2532. -
  2533. -SystemTimezone *system_timezone_new (void);
  2534. -
  2535. -const char *system_timezone_get (SystemTimezone *systz);
  2536. -const char *system_timezone_get_env (SystemTimezone *systz);
  2537. -
  2538. -/* Functions to set the timezone. They won't be used by the applet, but
  2539. - * by a program with more privileges */
  2540. -
  2541. -#define SYSTEM_TIMEZONE_ERROR system_timezone_error_quark ()
  2542. -GQuark system_timezone_error_quark (void);
  2543. -
  2544. -typedef enum
  2545. -{
  2546. -        SYSTEM_TIMEZONE_ERROR_GENERAL,
  2547. -        SYSTEM_TIMEZONE_ERROR_INVALID_TIMEZONE_FILE,
  2548. -        SYSTEM_TIMEZONE_NUM_ERRORS
  2549. -} SystemTimezoneError;
  2550. -
  2551. -char *system_timezone_find (void);
  2552. -
  2553. -gboolean system_timezone_set (const char  *tz,
  2554. -                              GError     **error);
  2555. -
  2556. -G_END_DECLS
  2557. -#endif /* __SYSTEM_TIMEZONE_H__ */
  2558. diff --git a/plugins/datetime/test-system-timezone.c b/plugins/datetime/test-system-timezone.c
  2559. deleted file mode 100644
  2560. index 79f8668..0000000
  2561. --- a/plugins/datetime/test-system-timezone.c
  2562. +++ /dev/null
  2563. @@ -1,93 +0,0 @@
  2564. -/* Test for system timezone handling
  2565. - *
  2566. - * Copyright (C) 2008-2010 Novell, Inc.
  2567. - *
  2568. - * Authors: Vincent Untz <vuntz@gnome.org>
  2569. - *
  2570. - * This program is free software; you can redistribute it and/or modify
  2571. - * it under the terms of the GNU General Public License as published by
  2572. - * the Free Software Foundation; either version 2 of the License, or
  2573. - * (at your option) any later version.
  2574. - *
  2575. - * This program is distributed in the hope that it will be useful,
  2576. - * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2577. - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  2578. - * GNU General Public License for more details.
  2579. - *
  2580. - * You should have received a copy of the GNU General Public License
  2581. - * along with this program; if not, write to the Free Software
  2582. - * Foundation, Inc., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
  2583. - */
  2584. -
  2585. -#include <glib.h>
  2586. -#include "system-timezone.h"
  2587. -
  2588. -static void
  2589. -timezone_print (void)
  2590. -{
  2591. -   SystemTimezone *systz;
  2592. -
  2593. -   systz = system_timezone_new ();
  2594. -        g_print ("Current timezone: %s\n", system_timezone_get (systz));
  2595. -   g_object_unref (systz);
  2596. -}
  2597. -
  2598. -static int
  2599. -timezone_set (const char *new_tz)
  2600. -{
  2601. -        GError *error;
  2602. -
  2603. -        error = NULL;
  2604. -        if (!system_timezone_set (new_tz, &error)) {
  2605. -                g_printerr ("%s\n", error->message);
  2606. -                g_error_free (error);
  2607. -                return 1;
  2608. -        }
  2609. -
  2610. -   return 0;
  2611. -}
  2612. -
  2613. -int
  2614. -main (int    argc,
  2615. -      char **argv)
  2616. -{
  2617. -   int      retval;
  2618. -
  2619. -   gboolean  get = FALSE;
  2620. -   char     *tz_set = NULL;
  2621. -
  2622. -   GError         *error;
  2623. -   GOptionContext *context;
  2624. -        GOptionEntry options[] = {
  2625. -                { "get", 'g', 0, G_OPTION_ARG_NONE, &get, "Get the current timezone", NULL },
  2626. -                { "set", 's', 0, G_OPTION_ARG_STRING, &tz_set, "Set the timezone to TIMEZONE", "TIMEZONE" },
  2627. -                { NULL, 0, 0, 0, NULL, NULL, NULL }
  2628. -        };
  2629. -
  2630. -   retval = 0;
  2631. -
  2632. -   g_type_init ();
  2633. -
  2634. -   context = g_option_context_new ("");
  2635. -   g_option_context_add_main_entries (context, options, NULL);
  2636. -
  2637. -   error = NULL;
  2638. -   if (!g_option_context_parse (context, &argc, &argv, &error)) {
  2639. -       g_printerr ("%s\n", error->message);
  2640. -       g_error_free (error);
  2641. -       g_option_context_free (context);
  2642. -
  2643. -       return 1;
  2644. -   }
  2645. -
  2646. -   g_option_context_free (context);
  2647. -
  2648. -   if (get || (!tz_set))
  2649. -       timezone_print ();
  2650. -   else if (tz_set)
  2651. -       retval = timezone_set (tz_set);
  2652. -   else
  2653. -       g_assert_not_reached ();
  2654. -
  2655. -        return retval;
  2656. -}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement