| 1 | /* |
| 2 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 3 | */ |
| 4 | |
| 5 | #include "config.h" |
| 6 | |
| 7 | #include <glib.h> |
| 8 | #include <gmodule.h> |
| 9 | |
| 10 | #include "gsm_gksu.h" |
| 11 | |
| 12 | |
| 13 | static gboolean (*gksu_run) (const char *, GError **); |
| 14 | |
| 15 | |
| 16 | static void |
| 17 | load_gksu (void) |
| 18 | { |
| 19 | static GModule *module = NULL; |
| 20 | |
| 21 | if (g_once_init_enter_pointer (&module)) { |
| 22 | GModule *gksu = g_module_open ("libgksu2.so", |
| 23 | static_cast<GModuleFlags>(G_MODULE_BIND_LAZY | G_MODULE_BIND_LOCAL)); |
| 24 | |
| 25 | if (!g_module_symbol (gksu, "gksu_run", (gpointer *) &gksu_run)) { |
| 26 | g_debug ("Could not load gksu_run from libgksu2.so"); |
| 27 | return; |
| 28 | } else { |
| 29 | g_debug ("Loaded gksu_run from libgksu2.so"); |
| 30 | } |
| 31 | |
| 32 | g_once_init_leave_pointer (&module, g_steal_pointer (&gksu)); |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | |
| 37 | gboolean |
| 38 | gsm_gksu_create_root_password_dialog (const char *command) |
| 39 | { |
| 40 | g_autoptr (GError) e = NULL; |
| 41 | |
| 42 | /* Returns FALSE or TRUE on success, depends on version ... */ |
| 43 | gksu_run (command, &e); |
| 44 | |
| 45 | if (e) { |
| 46 | g_critical ("Could not run gksu_run(\"%s\") : %s\n", |
| 47 | command, |
| 48 | e->message); |
| 49 | return FALSE; |
| 50 | } |
| 51 | |
| 52 | g_message ("gksu_run did fine\n"); |
| 53 | return TRUE; |
| 54 | } |
| 55 | |
| 56 | |
| 57 | gboolean |
| 58 | procman_has_gksu (void) |
| 59 | { |
| 60 | load_gksu (); |
| 61 | return gksu_run != NULL; |
| 62 | } |