summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Nagy <robert@openbsd.org>2022-11-09 23:58:46 +0100
committerRobert Nagy <robert@openbsd.org>2022-11-09 23:58:46 +0100
commit3b22b7cc4f1425390903811b773526aa5a318713 (patch)
tree95815dc06395e7a498eb2f8b61d1c9435f596065
parent989c95ebc603776791b962691e20a3a2882c1b96 (diff)
downloadConsoleKit2-3b22b7cc4f1425390903811b773526aa5a318713.tar.gz
add initial shim for sd_* functions
-rw-r--r--libconsolekit/Makefile.am3
-rw-r--r--libconsolekit/libconsolekit.c58
-rw-r--r--libconsolekit/libconsolekit.h5
-rw-r--r--libconsolekit/sd-compat.c144
-rw-r--r--libconsolekit/sd-login.h8
5 files changed, 218 insertions, 0 deletions
diff --git a/libconsolekit/Makefile.am b/libconsolekit/Makefile.am
index d5fe59c..1b63304 100644
--- a/libconsolekit/Makefile.am
+++ b/libconsolekit/Makefile.am
@@ -16,11 +16,14 @@ libconsolekitincludedir = $(includedir)/ConsoleKit/
libconsolekitinclude_HEADERS = \
libconsolekit.h \
+ sd-login.h \
$(NULL)
libconsolekit_la_SOURCES = \
libconsolekit.c \
libconsolekit.h \
+ sd-compat.c \
+ sd-login.h \
$(NULL)
diff --git a/libconsolekit/libconsolekit.c b/libconsolekit/libconsolekit.c
index 6d6693f..a86b353 100644
--- a/libconsolekit/libconsolekit.c
+++ b/libconsolekit/libconsolekit.c
@@ -263,6 +263,64 @@ lib_consolekit_seat_get_active (LibConsoleKit *ck,
}
/**
+ * lib_consolekit_uid_get_sessions:
+ **/
+gint
+lib_consolekit_uid_get_sessions (LibConsoleKit *ck,
+ uid_t uid,
+ gchar ***sessions,
+ GError **error)
+{
+ GDBusProxy *manager_proxy = NULL;
+ GVariant *variant = NULL;
+
+ if (ck == NULL) {
+ g_set_error (error,
+ CONSOLEKIT_ERROR,
+ CONSOLEKIT_ERROR_INVALID_INPUT,
+ "Invalid LibConsoleKit");
+ return -1;
+ }
+
+ /* connect to the ConsoleKit manager */
+ manager_proxy = g_dbus_proxy_new_for_bus_sync (G_BUS_TYPE_SYSTEM,
+ G_DBUS_PROXY_FLAGS_DO_NOT_LOAD_PROPERTIES | G_DBUS_PROXY_FLAGS_DO_NOT_CONNECT_SIGNALS,
+ NULL,
+ CK_NAME,
+ CK_MANAGER_PATH,
+ CK_MANAGER_NAME,
+ NULL,
+ error);
+
+ /* failed to connect */
+ if (manager_proxy == NULL) {
+ return FALSE;
+ }
+
+ variant = g_dbus_proxy_call_sync (manager_proxy,
+ "GetSessionsForUnixUser",
+ g_variant_new ("(u)", uid),
+ G_DBUS_CALL_FLAGS_NONE,
+ -1,
+ NULL,
+ error);
+
+ /* We're done with the seat proxy */
+ g_clear_object(&manager_proxy);
+
+ if (variant == NULL) {
+ return -1;
+ }
+
+ g_variant_get (variant, "(^ao)", sessions);
+
+ g_variant_unref (variant);
+ variant = NULL;
+
+ return g_strv_length (*sessions);
+}
+
+/**
* lib_consolekit_seat_get_sessions:
* @ck : A #LibConsoleKit
* @seat : The seat to query
diff --git a/libconsolekit/libconsolekit.h b/libconsolekit/libconsolekit.h
index fd75362..3619898 100644
--- a/libconsolekit/libconsolekit.h
+++ b/libconsolekit/libconsolekit.h
@@ -142,6 +142,11 @@ gboolean lib_consolekit_pid_get_session (LibConsoleKit *ck,
GError **error);
+gint
+lib_consolekit_uid_get_sessions (LibConsoleKit *ck,
+ uid_t uid,
+ gchar ***sessions,
+ GError **error);
#endif /* LIB_CONSOLEKIT_H_ */
diff --git a/libconsolekit/sd-compat.c b/libconsolekit/sd-compat.c
new file mode 100644
index 0000000..69a1576
--- /dev/null
+++ b/libconsolekit/sd-compat.c
@@ -0,0 +1,144 @@
+#include "config.h"
+
+#include <sys/types.h>
+
+#include <glib.h>
+#include <glib-object.h>
+#include <glib/gstdio.h>
+#include <glib/gi18n.h>
+#include <gio/gio.h>
+
+#include "libconsolekit.h"
+
+int
+sd_session_get_class(const char *session, char **class)
+{
+ LibConsoleKit *ck = NULL;
+ GError *error = NULL;
+
+ ck = lib_consolekit_new ();
+
+ lib_consolekit_session_get_class (ck, session, class, &error);
+ if (error) {
+ g_warning ("Unable to determine session class: %s",
+ error ? error->message : "");
+ g_error_free (error);
+ g_object_unref (ck);
+ return -ENXIO;
+ }
+
+ g_object_unref (ck);
+
+ return 0;
+}
+
+int
+sd_session_get_seat(const char *session, char **seat)
+{
+ LibConsoleKit *ck = NULL;
+ GError *error = NULL;
+
+ ck = lib_consolekit_new ();
+
+ lib_consolekit_session_get_seat (ck, session, seat, &error);
+ if (error) {
+ g_warning ("Unable to determine seat: %s",
+ error ? error->message : "");
+ g_error_free (error);
+ g_object_unref (ck);
+ return -ENXIO;
+ }
+
+ g_object_unref (ck);
+
+ return 0;
+}
+
+int
+sd_session_get_type(const char *session, char **type)
+{
+ LibConsoleKit *ck = NULL;
+ GError *error = NULL;
+
+ ck = lib_consolekit_new ();
+
+ lib_consolekit_session_get_type (ck, session, type, &error);
+ if (error) {
+ g_warning ("Unable to determine seat type: %s",
+ error ? error->message : "");
+ g_error_free (error);
+ g_object_unref (ck);
+ return -ENXIO;
+ }
+
+ g_object_unref (ck);
+
+ return 0;
+}
+
+int
+sd_session_get_state(const char *session, char **state)
+{
+ LibConsoleKit *ck = NULL;
+ GError *error = NULL;
+
+ ck = lib_consolekit_new ();
+
+ lib_consolekit_session_get_state (ck, session, state, &error);
+ if (error) {
+ g_warning ("Unable to determine seat state: %s",
+ error ? error->message : "");
+ g_error_free (error);
+ g_object_unref (ck);
+ return -ENXIO;
+ }
+
+ g_object_unref (ck);
+
+ return 0;
+}
+
+int
+sd_session_get_uid(const char *session, uid_t *uid)
+{
+ LibConsoleKit *ck = NULL;
+ GError *error = NULL;
+
+ ck = lib_consolekit_new ();
+
+ lib_consolekit_session_get_uid (ck, session, uid, &error);
+ if (error) {
+ g_warning ("Unable to determine session uid: %s",
+ error ? error->message : "");
+ g_error_free (error);
+ g_object_unref (ck);
+ return -ENXIO;
+ }
+
+ g_object_unref (ck);
+
+ return 0;
+}
+
+int
+sd_uid_get_sessions(uid_t uid, int require_active, char ***sessions)
+{
+ LibConsoleKit *ck = NULL;
+ GError *error = NULL;
+ int ret = 0;
+
+ ck = lib_consolekit_new ();
+
+ ret = lib_consolekit_uid_get_sessions (ck, uid, sessions, &error);
+ if (error) {
+ g_warning ("Unable to determine session uid: %s",
+ error ? error->message : "");
+ g_error_free (error);
+ g_object_unref (ck);
+ return -ENXIO;
+ }
+
+ g_object_unref (ck);
+
+ return ret;
+}
diff --git a/libconsolekit/sd-login.h b/libconsolekit/sd-login.h
new file mode 100644
index 0000000..262966c
--- /dev/null
+++ b/libconsolekit/sd-login.h
@@ -0,0 +1,8 @@
+#include <sys/types.h>
+
+int sd_session_get_class(const char *session, char **class);
+int sd_session_get_seat(const char *session, char **seat);
+int sd_session_get_type(const char *session, char **type);
+int sd_session_get_state(const char *session, char **state);
+int sd_session_get_uid(const char *session, uid_t *uid);
+int sd_uid_get_sessions(uid_t uid, int require_active, char ***sessions);