]> git.pld-linux.org Git - packages/polkit.git/blame - systemd-fallback.patch
up to 121 (new js engine)
[packages/polkit.git] / systemd-fallback.patch
CommitLineData
c5786473
JB
1--- polkit-0.114/src/polkit/polkitunixsession.c.orig 2018-03-23 16:09:30.000000000 +0100
2+++ polkit-0.114/src/polkit/polkitunixsession.c 2018-04-12 19:03:50.775644785 +0200
9c761957
JB
3@@ -29,6 +29,12 @@
4 #include "polkiterror.h"
5 #include "polkitprivate.h"
6
7+#ifdef HAVE_LIBSYSTEMD
8+# include <stdlib.h>
9+# include <systemd/sd-daemon.h>
10+# include <systemd/sd-login.h>
11+#endif
12+
13 /**
14 * SECTION:polkitunixsession
15 * @title: PolkitUnixSession
c5786473 16@@ -363,35 +369,49 @@ polkit_unix_session_exists_sync (PolkitS
9c761957
JB
17 {
18 PolkitUnixSession *session = POLKIT_UNIX_SESSION (subject);
19 GDBusConnection *connection;
20- GVariant *result;
21+ GVariant *result = NULL;
22 gboolean ret;
23
24+ connection = NULL;
25 ret = FALSE;
26
27- connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, cancellable, error);
28- if (connection == NULL)
29- goto out;
30+#ifdef HAVE_LIBSYSTEMD
31+ uid_t uid;
32
33- result = g_dbus_connection_call_sync (connection,
34- "org.freedesktop.ConsoleKit", /* name */
35- session->session_id, /* object path */
36- "org.freedesktop.ConsoleKit.Session", /* interface name */
37- "GetUser", /* method */
38- NULL, /* parameters */
39- G_VARIANT_TYPE ("(u)"),
40- G_DBUS_CALL_FLAGS_NONE,
41- -1,
42- cancellable,
43- error);
44- if (result == NULL)
45- goto out;
46+ if (sd_booted () > 0)
47+ {
48+ if (sd_session_get_uid (session->session_id, &uid) == 0)
49+ ret = TRUE;
50+ }
51+ else
52+#endif /* HAVE_LIBSYSTEMD */
53+ {
54+ connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, cancellable, error);
55+ if (connection == NULL)
56+ goto out;
57+
58+ result = g_dbus_connection_call_sync (connection,
59+ "org.freedesktop.ConsoleKit", /* name */
60+ session->session_id, /* object path */
61+ "org.freedesktop.ConsoleKit.Session", /* interface name */
62+ "GetUser", /* method */
63+ NULL, /* parameters */
64+ G_VARIANT_TYPE ("(u)"),
65+ G_DBUS_CALL_FLAGS_NONE,
66+ -1,
67+ cancellable,
68+ error);
69+ if (result == NULL)
70+ goto out;
71
72- ret = TRUE;
73- g_variant_unref (result);
74+ ret = TRUE;
75+ g_variant_unref (result);
76+ }
77
78 out:
79 if (connection != NULL)
80 g_object_unref (connection);
81+
82 return ret;
83 }
84
c5786473 85@@ -474,6 +494,7 @@ polkit_unix_session_initable_init (GInit
9c761957
JB
86 GVariant *result;
87 gboolean ret;
88
89+ result = NULL;
90 connection = NULL;
91 ret = FALSE;
92
c5786473 93@@ -484,28 +505,65 @@ polkit_unix_session_initable_init (GInit
9c761957
JB
94 goto out;
95 }
96
97- connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, cancellable, error);
98- if (connection == NULL)
99- goto out;
c5786473
JB
100+#ifdef HAVE_LIBSYSTEMD
101+ char *s;
102+ uid_t uid;
103+
104+ if (sd_booted () > 0)
105+ {
106+ if (sd_pid_get_session (session->pid, &s) == 0)
107+ {
108+ session->session_id = g_strdup (s);
109+ free (s);
110+ ret = TRUE;
111+ goto out;
112+ }
113+
114+ /* Now do process -> uid -> graphical session (systemd version 213)*/
115+ if (sd_pid_get_owner_uid (session->pid, &uid) < 0)
116+ goto error;
117
9c761957
JB
118- result = g_dbus_connection_call_sync (connection,
119- "org.freedesktop.ConsoleKit", /* name */
120- "/org/freedesktop/ConsoleKit/Manager", /* object path */
121- "org.freedesktop.ConsoleKit.Manager", /* interface name */
122- "GetSessionForUnixProcess", /* method */
123- g_variant_new ("(u)", session->pid), /* parameters */
124- G_VARIANT_TYPE ("(o)"),
125- G_DBUS_CALL_FLAGS_NONE,
126- -1,
127- cancellable,
128- error);
129- if (result == NULL)
130- goto out;
c5786473 131+ if (sd_uid_get_display (uid, &s) >= 0)
9c761957 132+ {
c5786473
JB
133+ session->session_id = g_strdup (s);
134+ free (s);
135+ ret = TRUE;
136+ goto out;
137+ }
138
139- g_variant_get (result, "(o)", &session->session_id);
140- g_variant_unref (result);
141+error:
9c761957
JB
142+ g_set_error (error,
143+ POLKIT_ERROR,
144+ POLKIT_ERROR_FAILED,
145+ "No session for pid %d",
146+ (gint) session->pid);
147+ }
148+ else
149+#endif /* HAVE_LIBSYSTEMD */
150+ {
151+ connection = g_bus_get_sync (G_BUS_TYPE_SYSTEM, cancellable, error);
152+ if (connection == NULL)
153+ goto out;
154+
155+ result = g_dbus_connection_call_sync (connection,
156+ "org.freedesktop.ConsoleKit", /* name */
157+ "/org/freedesktop/ConsoleKit/Manager", /* object path */
158+ "org.freedesktop.ConsoleKit.Manager", /* interface name */
159+ "GetSessionForUnixProcess", /* method */
160+ g_variant_new ("(u)", session->pid), /* parameters */
161+ G_VARIANT_TYPE ("(o)"),
162+ G_DBUS_CALL_FLAGS_NONE,
163+ -1,
164+ cancellable,
165+ error);
166+ if (result == NULL)
167+ goto out;
168
c5786473 169- ret = TRUE;
9c761957
JB
170+ g_variant_get (result, "(o)", &session->session_id);
171+ g_variant_unref (result);
c5786473 172+
9c761957
JB
173+ ret = TRUE;
174+ }
175
176 out:
177 if (connection != NULL)
c5786473
JB
178--- polkit-0.114/src/polkit/polkitunixsession-systemd.c.orig 2018-04-12 18:55:30.995650493 +0200
179+++ polkit-0.114/src/polkit/polkitunixsession-systemd.c 1970-01-01 01:00:00.000000000 +0100
180@@ -1,504 +0,0 @@
186114f9
ŁK
181-/*
182- * Copyright (C) 2011 Red Hat, Inc.
183- *
184- * This library is free software; you can redistribute it and/or
185- * modify it under the terms of the GNU Lesser General Public
186- * License as published by the Free Software Foundation; either
187- * version 2 of the License, or (at your option) any later version.
188- *
189- * This library is distributed in the hope that it will be useful,
190- * but WITHOUT ANY WARRANTY; without even the implied warranty of
191- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
192- * Lesser General Public License for more details.
193- *
194- * You should have received a copy of the GNU Lesser General
195- * Public License along with this library; if not, write to the
196- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
197- * Boston, MA 02111-1307, USA.
198- *
199- * Author: Matthias Clasen
200- */
201-
202-#ifdef HAVE_CONFIG_H
203-# include "config.h"
204-#endif
205-
a7e49982 206-#include <stdlib.h>
186114f9
ŁK
207-#include <string.h>
208-#include "polkitunixsession.h"
209-#include "polkitsubject.h"
210-#include "polkiterror.h"
211-#include "polkitprivate.h"
212-
213-#include <systemd/sd-login.h>
214-
215-/**
216- * SECTION:polkitunixsession
217- * @title: PolkitUnixSession
218- * @short_description: Unix sessions
219- *
220- * An object that represents an user session.
221- *
222- * The session id is an opaque string obtained from ConsoleKit.
223- */
224-
225-/**
226- * PolkitUnixSession:
227- *
228- * The #PolkitUnixSession struct should not be accessed directly.
229- */
230-struct _PolkitUnixSession
231-{
232- GObject parent_instance;
233-
234- gchar *session_id;
235-
236- gint pid;
237-};
238-
239-struct _PolkitUnixSessionClass
240-{
241- GObjectClass parent_class;
242-};
243-
244-enum
245-{
246- PROP_0,
247- PROP_SESSION_ID,
248- PROP_PID,
249-};
250-
251-static void subject_iface_init (PolkitSubjectIface *subject_iface);
252-static void initable_iface_init (GInitableIface *initable_iface);
253-static void async_initable_iface_init (GAsyncInitableIface *async_initable_iface);
254-
255-G_DEFINE_TYPE_WITH_CODE (PolkitUnixSession, polkit_unix_session, G_TYPE_OBJECT,
256- G_IMPLEMENT_INTERFACE (POLKIT_TYPE_SUBJECT, subject_iface_init)
257- G_IMPLEMENT_INTERFACE (G_TYPE_INITABLE, initable_iface_init)
258- G_IMPLEMENT_INTERFACE (G_TYPE_ASYNC_INITABLE, async_initable_iface_init)
259- );
260-
261-static void
262-polkit_unix_session_init (PolkitUnixSession *session)
263-{
264-}
265-
266-static void
267-polkit_unix_session_finalize (GObject *object)
268-{
269- PolkitUnixSession *session = POLKIT_UNIX_SESSION (object);
270-
271- g_free (session->session_id);
272-
273- if (G_OBJECT_CLASS (polkit_unix_session_parent_class)->finalize != NULL)
274- G_OBJECT_CLASS (polkit_unix_session_parent_class)->finalize (object);
275-}
276-
277-static void
278-polkit_unix_session_get_property (GObject *object,
279- guint prop_id,
280- GValue *value,
281- GParamSpec *pspec)
282-{
283- PolkitUnixSession *session = POLKIT_UNIX_SESSION (object);
284-
285- switch (prop_id)
286- {
287- case PROP_SESSION_ID:
288- g_value_set_string (value, session->session_id);
289- break;
290-
291- default:
292- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
293- break;
294- }
295-}
296-
297-static void
298-polkit_unix_session_set_property (GObject *object,
299- guint prop_id,
300- const GValue *value,
301- GParamSpec *pspec)
302-{
303- PolkitUnixSession *session = POLKIT_UNIX_SESSION (object);
304-
305- switch (prop_id)
306- {
307- case PROP_SESSION_ID:
308- polkit_unix_session_set_session_id (session, g_value_get_string (value));
309- break;
310-
311- case PROP_PID:
312- session->pid = g_value_get_int (value);
313- break;
314-
315- default:
316- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
317- break;
318- }
319-}
320-
321-static void
322-polkit_unix_session_class_init (PolkitUnixSessionClass *klass)
323-{
324- GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
325-
326- gobject_class->finalize = polkit_unix_session_finalize;
327- gobject_class->get_property = polkit_unix_session_get_property;
328- gobject_class->set_property = polkit_unix_session_set_property;
329-
330- /**
331- * PolkitUnixSession:session-id:
332- *
333- * The UNIX session id.
334- */
335- g_object_class_install_property (gobject_class,
336- PROP_SESSION_ID,
337- g_param_spec_string ("session-id",
338- "Session ID",
339- "The UNIX session ID",
340- NULL,
341- G_PARAM_CONSTRUCT |
342- G_PARAM_READWRITE |
343- G_PARAM_STATIC_NAME |
344- G_PARAM_STATIC_BLURB |
345- G_PARAM_STATIC_NICK));
346-
347-
348- /**
349- * PolkitUnixSession:pid:
350- *
351- * The UNIX process id to look up the session.
352- */
353- g_object_class_install_property (gobject_class,
354- PROP_PID,
355- g_param_spec_int ("pid",
356- "Process ID",
357- "Process ID to use for looking up the session",
358- 0,
359- G_MAXINT,
360- 0,
361- G_PARAM_CONSTRUCT_ONLY |
362- G_PARAM_WRITABLE |
363- G_PARAM_STATIC_NAME |
364- G_PARAM_STATIC_BLURB |
365- G_PARAM_STATIC_NICK));
366-
367-}
368-
369-/**
370- * polkit_unix_session_get_session_id:
371- * @session: A #PolkitUnixSession.
372- *
373- * Gets the session id for @session.
374- *
375- * Returns: The session id for @session. Do not free this string, it
376- * is owned by @session.
377- **/
378-const gchar *
379-polkit_unix_session_get_session_id (PolkitUnixSession *session)
380-{
381- g_return_val_if_fail (POLKIT_IS_UNIX_SESSION (session), NULL);
382- return session->session_id;
383-}
384-
385-/**
386- * polkit_unix_session_set_session_id:
387- * @session: A #PolkitUnixSession.
388- * @session_id: The session id.
389- *
390- * Sets the session id for @session to @session_id.
391- **/
392-void
393-polkit_unix_session_set_session_id (PolkitUnixSession *session,
394- const gchar *session_id)
395-{
396- g_return_if_fail (POLKIT_IS_UNIX_SESSION (session));
397- /*g_return_if_fail (session_id != NULL);*/
398- g_free (session->session_id);
399- session->session_id = g_strdup (session_id);
400-}
401-
402-/**
403- * polkit_unix_session_new:
404- * @session_id: The session id.
405- *
406- * Creates a new #PolkitUnixSession for @session_id.
407- *
408- * Returns: (transfer full): A #PolkitUnixSession. Free with g_object_unref().
409- **/
410-PolkitSubject *
411-polkit_unix_session_new (const gchar *session_id)
412-{
413- return POLKIT_SUBJECT (g_object_new (POLKIT_TYPE_UNIX_SESSION,
414- "session-id", session_id,
415- NULL));
416-}
417-
418-/**
419- * polkit_unix_session_new_for_process:
420- * @pid: The process id of the process to get the session for.
421- * @cancellable: (allow-none): A #GCancellable or %NULL.
422- * @callback: A #GAsyncReadyCallback to call when the request is satisfied
423- * @user_data: The data to pass to @callback.
424- *
425- * Asynchronously creates a new #PolkitUnixSession object for the
426- * process with process id @pid.
427- *
428- * When the operation is finished, @callback will be invoked in the
429- * <link linkend="g-main-context-push-thread-default">thread-default
430- * main loop</link> of the thread you are calling this method
431- * from. You can then call
432- * polkit_unix_session_new_for_process_finish() to get the result of
433- * the operation.
434- *
435- * This method constructs the object asynchronously, for the synchronous and blocking version
436- * use polkit_unix_session_new_for_process_sync().
437- **/
438-void
439-polkit_unix_session_new_for_process (gint pid,
440- GCancellable *cancellable,
441- GAsyncReadyCallback callback,
442- gpointer user_data)
443-{
444- g_async_initable_new_async (POLKIT_TYPE_UNIX_SESSION,
445- G_PRIORITY_DEFAULT,
446- cancellable,
447- callback,
448- user_data,
449- "pid", pid,
450- NULL);
451-}
452-
453-/**
454- * polkit_unix_session_new_for_process_finish:
455- * @res: A #GAsyncResult obtained from the #GAsyncReadyCallback passed to polkit_unix_session_new_for_process().
456- * @error: (allow-none): Return location for error.
457- *
458- * Finishes constructing a #PolkitSubject for a process id.
459- *
460- * Returns: (transfer full) (allow-none): A #PolkitUnixSession for the @pid passed to
461- * polkit_unix_session_new_for_process() or %NULL if @error is
462- * set. Free with g_object_unref().
463- **/
464-PolkitSubject *
465-polkit_unix_session_new_for_process_finish (GAsyncResult *res,
466- GError **error)
467-{
468- GObject *object;
469- GObject *source_object;
470-
471- source_object = g_async_result_get_source_object (res);
472- g_assert (source_object != NULL);
473-
474- object = g_async_initable_new_finish (G_ASYNC_INITABLE (source_object),
475- res,
476- error);
477- g_object_unref (source_object);
478-
479- if (object != NULL)
480- return POLKIT_SUBJECT (object);
481- else
482- return NULL;
483-}
484-
485-
486-/**
487- * polkit_unix_session_new_for_process_sync:
488- * @pid: The process id of the process to get the session for.
489- * @cancellable: (allow-none): A #GCancellable or %NULL.
490- * @error: (allow-none): Return location for error.
491- *
492- * Creates a new #PolkitUnixSession for the process with process id @pid.
493- *
494- * This is a synchronous call - the calling thread is blocked until a
495- * reply is received. For the asynchronous version, see
496- * polkit_unix_session_new_for_process().
497- *
498- * Returns: (allow-none) (transfer full): A #PolkitUnixSession for
499- * @pid or %NULL if @error is set. Free with g_object_unref().
500- **/
501-PolkitSubject *
502-polkit_unix_session_new_for_process_sync (gint pid,
503- GCancellable *cancellable,
504- GError **error)
505-{
506- return POLKIT_SUBJECT (g_initable_new (POLKIT_TYPE_UNIX_SESSION,
507- cancellable,
508- error,
509- "pid", pid,
510- NULL));
511-}
512-
513-static guint
514-polkit_unix_session_hash (PolkitSubject *subject)
515-{
516- PolkitUnixSession *session = POLKIT_UNIX_SESSION (subject);
517-
518- return g_str_hash (session->session_id);
519-}
520-
521-static gboolean
522-polkit_unix_session_equal (PolkitSubject *a,
523- PolkitSubject *b)
524-{
525- PolkitUnixSession *session_a;
526- PolkitUnixSession *session_b;
527-
528- session_a = POLKIT_UNIX_SESSION (a);
529- session_b = POLKIT_UNIX_SESSION (b);
530-
531- return g_strcmp0 (session_a->session_id, session_b->session_id) == 0;
532-}
533-
534-static gchar *
535-polkit_unix_session_to_string (PolkitSubject *subject)
536-{
537- PolkitUnixSession *session = POLKIT_UNIX_SESSION (subject);
538-
539- return g_strdup_printf ("unix-session:%s", session->session_id);
540-}
541-
542-static gboolean
543-polkit_unix_session_exists_sync (PolkitSubject *subject,
a7e49982
MB
544- GCancellable *cancellable,
545- GError **error)
186114f9
ŁK
546-{
547- PolkitUnixSession *session = POLKIT_UNIX_SESSION (subject);
a7e49982 548- gboolean ret = FALSE;
186114f9
ŁK
549- uid_t uid;
550-
a7e49982
MB
551- if (sd_session_get_uid (session->session_id, &uid) == 0)
552- ret = TRUE;
186114f9
ŁK
553-
554- return ret;
555-}
556-
557-static void
558-exists_in_thread_func (GSimpleAsyncResult *res,
559- GObject *object,
560- GCancellable *cancellable)
561-{
562- GError *error;
563- error = NULL;
564- if (!polkit_unix_session_exists_sync (POLKIT_SUBJECT (object),
565- cancellable,
566- &error))
567- {
568- g_simple_async_result_set_from_error (res, error);
569- g_error_free (error);
570- }
571-}
572-
573-static void
574-polkit_unix_session_exists (PolkitSubject *subject,
575- GCancellable *cancellable,
576- GAsyncReadyCallback callback,
577- gpointer user_data)
578-{
579- GSimpleAsyncResult *simple;
580-
581- g_return_if_fail (POLKIT_IS_UNIX_SESSION (subject));
582-
583- simple = g_simple_async_result_new (G_OBJECT (subject),
584- callback,
585- user_data,
586- polkit_unix_session_exists);
587- g_simple_async_result_run_in_thread (simple,
588- exists_in_thread_func,
589- G_PRIORITY_DEFAULT,
590- cancellable);
591- g_object_unref (simple);
592-}
593-
594-static gboolean
595-polkit_unix_session_exists_finish (PolkitSubject *subject,
596- GAsyncResult *res,
597- GError **error)
598-{
599- GSimpleAsyncResult *simple = G_SIMPLE_ASYNC_RESULT (res);
600- gboolean ret;
601-
602- g_warn_if_fail (g_simple_async_result_get_source_tag (simple) == polkit_unix_session_exists);
603-
604- ret = FALSE;
605-
606- if (g_simple_async_result_propagate_error (simple, error))
607- goto out;
608-
609- ret = g_simple_async_result_get_op_res_gboolean (simple);
610-
611- out:
612- return ret;
613-}
614-
615-static void
616-subject_iface_init (PolkitSubjectIface *subject_iface)
617-{
618- subject_iface->hash = polkit_unix_session_hash;
619- subject_iface->equal = polkit_unix_session_equal;
620- subject_iface->to_string = polkit_unix_session_to_string;
621- subject_iface->exists = polkit_unix_session_exists;
622- subject_iface->exists_finish = polkit_unix_session_exists_finish;
623- subject_iface->exists_sync = polkit_unix_session_exists_sync;
624-}
625-
626-static gboolean
627-polkit_unix_session_initable_init (GInitable *initable,
628- GCancellable *cancellable,
629- GError **error)
630-{
631- PolkitUnixSession *session = POLKIT_UNIX_SESSION (initable);
a7e49982
MB
632- gboolean ret = FALSE;
633- char *s;
c5786473 634- uid_t uid;
186114f9
ŁK
635-
636- if (session->session_id != NULL)
637- {
638- /* already set, nothing to do */
639- ret = TRUE;
640- goto out;
641- }
642-
a7e49982
MB
643- if (sd_pid_get_session (session->pid, &s) == 0)
644- {
645- session->session_id = g_strdup (s);
646- free (s);
647- ret = TRUE;
648- goto out;
649- }
650-
c5786473
JB
651- /* Now do process -> uid -> graphical session (systemd version 213)*/
652- if (sd_pid_get_owner_uid (session->pid, &uid) < 0)
653- goto error;
654-
655- if (sd_uid_get_display (uid, &s) >= 0)
656- {
657- session->session_id = g_strdup (s);
658- free (s);
659- ret = TRUE;
660- goto out;
661- }
662-
663-error:
a7e49982
MB
664- g_set_error (error,
665- POLKIT_ERROR,
666- POLKIT_ERROR_FAILED,
667- "No session for pid %d",
668- (gint) session->pid);
186114f9
ŁK
669-
670-out:
671- return ret;
672-}
673-
674-static void
675-initable_iface_init (GInitableIface *initable_iface)
676-{
677- initable_iface->init = polkit_unix_session_initable_init;
678-}
679-
680-static void
681-async_initable_iface_init (GAsyncInitableIface *async_initable_iface)
682-{
683- /* use default implementation to run GInitable code in a thread */
684-}
fbe373fc
JP
685--- polkit-v.121/src/polkitbackend/polkitbackendcommon.h.orig 2022-07-11 10:46:06.000000000 +0200
686+++ polkit-v.121/src/polkitbackend/polkitbackendcommon.h 2022-07-13 23:30:49.653425289 +0200
687@@ -47,6 +47,7 @@
9c761957
JB
688 #include <polkit/polkitprivate.h>
689
690 #ifdef HAVE_LIBSYSTEMD
691+#include <systemd/sd-daemon.h>
692 #include <systemd/sd-login.h>
693 #endif /* HAVE_LIBSYSTEMD */
694
fbe373fc
JP
695--- polkit-0.114.orig/src/polkitbackend/polkitbackendjsauthority.cpp 2015-06-19 22:39:58.000000000 +0200
696+++ polkit-0.114/src/polkitbackend/polkitbackendjsauthority.cpp 2015-09-26 23:40:21.674982125 +0200
9c761957
JB
697@@ -794,6 +795,8 @@
698 }
699
700 #ifdef HAVE_LIBSYSTEMD
701+ if (sd_booted () > 0)
702+ {
703 if (sd_pid_get_session (pid, &session_str) == 0)
704 {
705 if (sd_session_get_seat (session_str, &seat_str) == 0)
706@@ -801,6 +804,7 @@
707 /* do nothing */
708 }
709 }
710+ }
711 #endif /* HAVE_LIBSYSTEMD */
712
713 g_assert (POLKIT_IS_UNIX_USER (user_for_subject));
4e85edc6
JB
714--- polkit-0.115/src/polkitbackend/polkitbackendsessionmonitor.c.orig 2018-06-26 15:17:52.000000000 +0200
715+++ polkit-0.115/src/polkitbackend/polkitbackendsessionmonitor.c 2018-09-29 10:42:52.104190929 +0200
9c761957
JB
716@@ -26,6 +26,12 @@
717 #include <string.h>
718 #include <glib/gstdio.h>
186114f9 719
77f30838 720+#ifdef HAVE_LIBSYSTEMD
a7e49982 721+# include <stdlib.h>
186114f9
ŁK
722+# include <systemd/sd-daemon.h>
723+# include <systemd/sd-login.h>
9c761957 724+#endif /* HAVE_LIBSYSTEMD */
186114f9 725+
9c761957 726 #include <polkit/polkit.h>
4e85edc6 727 #include <polkit/polkitprivate.h>
9c761957 728 #include "polkitbackendsessionmonitor.h"
4e85edc6 729@@ -40,6 +46,88 @@
9c761957
JB
730 * The #PolkitBackendSessionMonitor class is a utility class to track and monitor sessions.
731 */
186114f9 732
77f30838 733+#ifdef HAVE_LIBSYSTEMD
9c761957
JB
734+typedef struct
735+{
736+ GSource source;
737+ GPollFD pollfd;
738+ sd_login_monitor *monitor;
739+} SdSource;
740+
741+static gboolean
742+sd_source_prepare (GSource *source,
743+ gint *timeout)
744+{
745+ *timeout = -1;
746+ return FALSE;
747+}
748+
749+static gboolean
750+sd_source_check (GSource *source)
751+{
752+ SdSource *sd_source = (SdSource *)source;
753+
754+ return sd_source->pollfd.revents != 0;
755+}
756+
757+static gboolean
758+sd_source_dispatch (GSource *source,
759+ GSourceFunc callback,
760+ gpointer user_data)
761+
762+{
763+ SdSource *sd_source = (SdSource *)source;
764+ gboolean ret;
765+
766+ g_warn_if_fail (callback != NULL);
767+
768+ ret = (*callback) (user_data);
769+
770+ sd_login_monitor_flush (sd_source->monitor);
771+
772+ return ret;
773+}
774+
775+static void
776+sd_source_finalize (GSource *source)
777+{
778+ SdSource *sd_source = (SdSource*)source;
779+
780+ sd_login_monitor_unref (sd_source->monitor);
781+}
782+
783+static GSourceFuncs sd_source_funcs = {
784+ sd_source_prepare,
785+ sd_source_check,
786+ sd_source_dispatch,
787+ sd_source_finalize
788+};
789+
790+static GSource *
791+sd_source_new (void)
792+{
793+ GSource *source;
794+ SdSource *sd_source;
795+ int ret;
796+
797+ source = g_source_new (&sd_source_funcs, sizeof (SdSource));
798+ sd_source = (SdSource *)source;
799+
800+ if ((ret = sd_login_monitor_new (NULL, &sd_source->monitor)) < 0)
186114f9 801+ {
9c761957 802+ g_printerr ("Error getting login monitor: %d", ret);
186114f9
ŁK
803+ }
804+ else
b20b0410 805+ {
9c761957
JB
806+ sd_source->pollfd.fd = sd_login_monitor_get_fd (sd_source->monitor);
807+ sd_source->pollfd.events = G_IO_IN;
808+ g_source_add_poll (source, &sd_source->pollfd);
b20b0410 809+ }
a7e49982 810+
9c761957
JB
811+ return source;
812+}
813+#endif /* HAVE_LIBSYSTEMD */
814+
815 struct _PolkitBackendSessionMonitor
816 {
817 GObject parent_instance;
4e85edc6 818@@ -49,6 +137,10 @@
9c761957
JB
819 GKeyFile *database;
820 GFileMonitor *database_monitor;
821 time_t database_mtime;
822+
823+#ifdef HAVE_LIBSYSTEMD
824+ GSource *sd_source;
825+#endif /* HAVE_LIBSYSTEMD */
826 };
186114f9 827
9c761957 828 struct _PolkitBackendSessionMonitorClass
4e85edc6 829@@ -71,6 +163,18 @@
a7e49982 830
9c761957 831 /* ---------------------------------------------------------------------------------------------------- */
186114f9 832
9c761957
JB
833+#ifdef HAVE_LIBSYSTEMD
834+static gboolean
835+sessions_changed (gpointer user_data)
836+{
837+ PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (user_data);
838+
839+ g_signal_emit (monitor, signals[CHANGED_SIGNAL], 0);
840+
841+ return TRUE;
842+}
843+#endif /* HAVE_LIBSYSTEMD */
844+
845 static gboolean
846 reload_database (PolkitBackendSessionMonitor *monitor,
847 GError **error)
4e85edc6 848@@ -177,31 +281,47 @@
9c761957 849 g_error_free (error);
186114f9
ŁK
850 }
851
9c761957
JB
852- error = NULL;
853- if (!ensure_database (monitor, &error))
77f30838 854+#ifdef HAVE_LIBSYSTEMD
9c761957
JB
855+ monitor->sd_source = NULL;
856+
186114f9 857+ if (sd_booted () > 0)
9c761957
JB
858 {
859- g_printerr ("Error loading " CKDB_PATH ": %s", error->message);
860- g_error_free (error);
861+ monitor->sd_source = sd_source_new ();
862+ g_source_set_callback (monitor->sd_source, sessions_changed, monitor, NULL);
863+ g_source_attach (monitor->sd_source, NULL);
a7e49982 864+
9c761957
JB
865+ monitor->database_monitor = NULL;
866+ monitor->database = NULL;
867 }
a7e49982 868+ else
77f30838 869+#endif /* HAVE_LIBSYSTEMD */
a7e49982 870+ {
9c761957
JB
871+ error = NULL;
872+ if (!ensure_database (monitor, &error))
873+ {
874+ g_printerr ("Error loading " CKDB_PATH ": %s", error->message);
875+ g_error_free (error);
876+ }
186114f9 877
9c761957
JB
878- error = NULL;
879- file = g_file_new_for_path (CKDB_PATH);
880- monitor->database_monitor = g_file_monitor_file (file,
881+ error = NULL;
882+ file = g_file_new_for_path (CKDB_PATH);
883+ monitor->database_monitor = g_file_monitor_file (file,
884 G_FILE_MONITOR_NONE,
885 NULL,
886 &error);
887- g_object_unref (file);
888- if (monitor->database_monitor == NULL)
889- {
890- g_printerr ("Error monitoring " CKDB_PATH ": %s", error->message);
891- g_error_free (error);
892- }
893- else
894- {
895- g_signal_connect (monitor->database_monitor,
896- "changed",
897- G_CALLBACK (on_file_monitor_changed),
898- monitor);
899+ g_object_unref (file);
900+ if (monitor->database_monitor == NULL)
901+ {
902+ g_printerr ("Error monitoring " CKDB_PATH ": %s", error->message);
903+ g_error_free (error);
904+ }
905+ else
906+ {
907+ g_signal_connect (monitor->database_monitor,
908+ "changed",
909+ G_CALLBACK (on_file_monitor_changed),
910+ monitor);
911+ }
912 }
913 }
186114f9 914
4e85edc6 915@@ -219,6 +339,12 @@
9c761957
JB
916 if (monitor->database != NULL)
917 g_key_file_free (monitor->database);
b20b0410 918
9c761957
JB
919+ if (monitor->sd_source != NULL)
920+ {
921+ g_source_destroy (monitor->sd_source);
922+ g_source_unref (monitor->sd_source);
923+ }
924+
925 if (G_OBJECT_CLASS (polkit_backend_session_monitor_parent_class)->finalize != NULL)
926 G_OBJECT_CLASS (polkit_backend_session_monitor_parent_class)->finalize (object);
927 }
4e85edc6 928@@ -332,6 +458,26 @@
77f30838 929 }
9c761957 930 else if (POLKIT_IS_UNIX_SESSION (subject))
77f30838 931 {
9c761957
JB
932+#ifdef HAVE_LIBSYSTEMD
933+ if (monitor->sd_source != NULL)
4e85edc6
JB
934+ {
935+ uid_t uid;
936+
937+ if (sd_session_get_uid (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (subject)), &uid) < 0)
938+ {
939+ g_set_error (error,
940+ POLKIT_ERROR,
941+ POLKIT_ERROR_FAILED,
942+ "Error getting uid for session");
943+ goto out;
944+ }
945+
946+ ret = polkit_unix_user_new (uid);
947+ matches = TRUE;
948+ }
9c761957
JB
949+ else
950+#endif /* HAVE_LIBSYSTEMD */
4e85edc6
JB
951+ {
952 gint uid;
953 gchar *group;
954
955@@ -354,6 +500,7 @@
9c761957
JB
956
957 ret = polkit_unix_user_new (uid);
4e85edc6
JB
958 matches = TRUE;
959+ }
9c761957 960 }
4e85edc6
JB
961
962 out:
963@@ -379,35 +526,26 @@
9c761957
JB
964 PolkitSubject *subject,
965 GError **error)
966 {
967- PolkitSubject *session;
186114f9 968-
9c761957
JB
969- session = NULL;
970+ PolkitSubject *session = NULL;
971+ pid_t pid;
972
973 if (POLKIT_IS_UNIX_PROCESS (subject))
186114f9 974- {
9c761957
JB
975- const gchar *session_id;
976- GVariant *result;
977- result = g_dbus_connection_call_sync (monitor->system_bus,
978- "org.freedesktop.ConsoleKit",
979- "/org/freedesktop/ConsoleKit/Manager",
980- "org.freedesktop.ConsoleKit.Manager",
981- "GetSessionForUnixProcess",
982- g_variant_new ("(u)", polkit_unix_process_get_pid (POLKIT_UNIX_PROCESS (subject))),
983- G_VARIANT_TYPE ("(o)"),
984- G_DBUS_CALL_FLAGS_NONE,
985- -1, /* timeout_msec */
986- NULL, /* GCancellable */
987- error);
988- if (result == NULL)
989- goto out;
990- g_variant_get (result, "(&o)", &session_id);
991- session = polkit_unix_session_new (session_id);
992- g_variant_unref (result);
993+ { /* We already have a process; now do process -> pid */
994+ pid = polkit_unix_process_get_pid (POLKIT_UNIX_PROCESS (subject));
995 }
996 else if (POLKIT_IS_SYSTEM_BUS_NAME (subject))
997- {
998- guint32 pid;
999- const gchar *session_id;
1000+ { /* Convert bus name to process / pid */
1001+#ifdef HAVE_LIBSYSTEMD
1002+ if (monitor->sd_source != NULL)
1003+ {
1004+ PolkitUnixProcess *process = (PolkitUnixProcess*)polkit_system_bus_name_get_process_sync (POLKIT_SYSTEM_BUS_NAME(subject), NULL, error);
1005+ if (!process)
1006+ goto out;
1007+ pid = polkit_unix_process_get_pid (process);
1008+ g_object_unref (process);
1009+ } else
1010+#endif
1011+ {
1012 GVariant *result;
1013
1014 result = g_dbus_connection_call_sync (monitor->system_bus,
4e85edc6 1015@@ -425,23 +563,7 @@
9c761957
JB
1016 goto out;
1017 g_variant_get (result, "(u)", &pid);
1018 g_variant_unref (result);
186114f9 1019-
9c761957
JB
1020- result = g_dbus_connection_call_sync (monitor->system_bus,
1021- "org.freedesktop.ConsoleKit",
1022- "/org/freedesktop/ConsoleKit/Manager",
1023- "org.freedesktop.ConsoleKit.Manager",
1024- "GetSessionForUnixProcess",
1025- g_variant_new ("(u)", pid),
1026- G_VARIANT_TYPE ("(o)"),
1027- G_DBUS_CALL_FLAGS_NONE,
1028- -1, /* timeout_msec */
1029- NULL, /* GCancellable */
1030- error);
1031- if (result == NULL)
1032- goto out;
1033- g_variant_get (result, "(&o)", &session_id);
1034- session = polkit_unix_session_new (session_id);
1035- g_variant_unref (result);
1036+ }
1037 }
1038 else
1039 {
4e85edc6 1040@@ -450,8 +572,57 @@
9c761957
JB
1041 POLKIT_ERROR_NOT_SUPPORTED,
1042 "Cannot get user for subject of type %s",
1043 g_type_name (G_TYPE_FROM_INSTANCE (subject)));
1044+ goto out;
1045 }
1046
1047+ /* Now do pid -> same session */
1048+#ifdef HAVE_LIBSYSTEMD
1049+ if (monitor->sd_source != NULL)
1050+ {
1051+ gchar *session_id;
1052+ if (sd_pid_get_session (pid, &session_id) >= 0)
1053+ {
1054+ session = polkit_unix_session_new (session_id);
1055+ free (session_id);
1056+ goto out;
1057+ }
1058+#if HAVE_SD_UID_GET_DISPLAY
1059+ uid_t uid;
1060+ /* Now do pid -> uid -> graphical session (systemd version 213)*/
1061+ if (sd_pid_get_owner_uid (pid, &uid) < 0)
1062+ goto out;
1063+
1064+ if (sd_uid_get_display (uid, &session_id) >= 0)
1065+ {
1066+ session = polkit_unix_session_new (session_id);
1067+ free (session_id);
1068+ goto out;
1069+ }
1070+#endif
1071+ }
1072+ else
1073+#endif /* HAVE_LIBSYSTEMD */
1074+ {
1075+ gchar *session_id;
1076+ GVariant *result;
1077+ result = g_dbus_connection_call_sync (monitor->system_bus,
1078+ "org.freedesktop.ConsoleKit",
1079+ "/org/freedesktop/ConsoleKit/Manager",
1080+ "org.freedesktop.ConsoleKit.Manager",
1081+ "GetSessionForUnixProcess",
1082+ g_variant_new ("(u)", pid),
1083+ G_VARIANT_TYPE ("(o)"),
1084+ G_DBUS_CALL_FLAGS_NONE,
1085+ -1, /* timeout_msec */
1086+ NULL, /* GCancellable */
1087+ error);
1088+ if (result == NULL)
1089+ goto out;
1090+ g_variant_get (result, "(&o)", &session_id);
1091+ session = polkit_unix_session_new (session_id);
1092+ g_variant_unref (result);
1093+ }
1094+
1095 out:
1096
1097 return session;
4e85edc6 1098@@ -502,7 +673,22 @@
9c761957
JB
1099 polkit_backend_session_monitor_is_session_local (PolkitBackendSessionMonitor *monitor,
1100 PolkitSubject *session)
1101 {
1102- return get_boolean (monitor, session, "is_local");
1103+#ifdef HAVE_LIBSYSTEMD
1104+ if (monitor->sd_source != NULL)
1105+ {
1106+ char *seat;
1107+
1108+ if (!sd_session_get_seat (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (session)), &seat))
1109+ {
1110+ free (seat);
1111+ return TRUE;
1112+ }
1113+
1114+ return FALSE;
1115+ }
1116+ else
1117+#endif /* HAVE_LIBSYSTEMD */
1118+ return get_boolean (monitor, session, "is_local");
1119 }
1120
1121
4e85edc6 1122@@ -510,6 +696,44 @@
9c761957
JB
1123 polkit_backend_session_monitor_is_session_active (PolkitBackendSessionMonitor *monitor,
1124 PolkitSubject *session)
1125 {
1126- return get_boolean (monitor, session, "is_active");
1127+#ifdef HAVE_LIBSYSTEMD
1128+ if (monitor->sd_source != NULL)
1129+ {
1130+ const char *session_id;
1131+ char *state;
1132+ uid_t uid;
1133+ gboolean is_active = FALSE;
1134+
1135+ session_id = polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (session));
1136+
1137+ g_debug ("Checking whether session %s is active.", session_id);
1138+
1139+ /* Check whether *any* of the user's current sessions are active. */
1140+ if (sd_session_get_uid (session_id, &uid) < 0)
1141+ goto fallback;
1142+
1143+ g_debug ("Session %s has UID %u.", session_id, uid);
1144+
1145+ if (sd_uid_get_state (uid, &state) < 0)
1146+ goto fallback;
1147+
1148+ g_debug ("UID %u has state %s.", uid, state);
1149+
1150+ is_active = (g_strcmp0 (state, "active") == 0);
1151+ free (state);
1152+
1153+ return is_active;
1154+
1155+fallback:
1156+ /* Fall back to checking the session. This is not ideal, since the user
1157+ * might have multiple sessions, and we cannot guarantee to have chosen
1158+ * the active one.
1159+ *
1160+ * See: https://bugs.freedesktop.org/show_bug.cgi?id=76358. */
1161+ return sd_session_is_active (session_id);
1162+ }
1163+ else
1164+#endif /* HAVE_LIBSYSTEMD */
1165+ return get_boolean (monitor, session, "is_active");
1166 }
1167
4e85edc6
JB
1168--- polkit-0.115/src/polkitbackend/polkitbackendsessionmonitor-systemd.c.orig 2018-09-29 09:48:19.240894967 +0200
1169+++ polkit-0.115/src/polkitbackend/polkitbackendsessionmonitor-systemd.c 1970-01-01 01:00:00.000000000 +0100
1170@@ -1,455 +0,0 @@
9c761957
JB
1171-/*
1172- * Copyright (C) 2011 Red Hat, Inc.
1173- *
1174- * This library is free software; you can redistribute it and/or
1175- * modify it under the terms of the GNU Lesser General Public
1176- * License as published by the Free Software Foundation; either
1177- * version 2 of the License, or (at your option) any later version.
1178- *
1179- * This library is distributed in the hope that it will be useful,
1180- * but WITHOUT ANY WARRANTY; without even the implied warranty of
1181- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
1182- * Lesser General Public License for more details.
1183- *
1184- * You should have received a copy of the GNU Lesser General
1185- * Public License along with this library; if not, write to the
1186- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
1187- * Boston, MA 02111-1307, USA.
1188- *
1189- * Author: Matthias Clasen
1190- */
186114f9 1191-
9c761957
JB
1192-#include "config.h"
1193-#include <errno.h>
1194-#include <pwd.h>
1195-#include <grp.h>
1196-#include <string.h>
1197-#include <glib/gstdio.h>
1198-#include <systemd/sd-login.h>
1199-#include <stdlib.h>
186114f9 1200-
9c761957 1201-#include <polkit/polkit.h>
4e85edc6 1202-#include <polkit/polkitprivate.h>
9c761957 1203-#include "polkitbackendsessionmonitor.h"
186114f9 1204-
9c761957
JB
1205-/* <internal>
1206- * SECTION:polkitbackendsessionmonitor
1207- * @title: PolkitBackendSessionMonitor
1208- * @short_description: Monitor sessions
1209- *
1210- * The #PolkitBackendSessionMonitor class is a utility class to track and monitor sessions.
1211- */
186114f9 1212-
9c761957
JB
1213-typedef struct
1214-{
1215- GSource source;
1216- GPollFD pollfd;
1217- sd_login_monitor *monitor;
1218-} SdSource;
186114f9
ŁK
1219-
1220-static gboolean
9c761957
JB
1221-sd_source_prepare (GSource *source,
1222- gint *timeout)
186114f9 1223-{
9c761957
JB
1224- *timeout = -1;
1225- return FALSE;
1226-}
1227-
1228-static gboolean
1229-sd_source_check (GSource *source)
1230-{
1231- SdSource *sd_source = (SdSource *)source;
1232-
1233- return sd_source->pollfd.revents != 0;
1234-}
1235-
1236-static gboolean
1237-sd_source_dispatch (GSource *source,
1238- GSourceFunc callback,
1239- gpointer user_data)
1240-
1241-{
1242- SdSource *sd_source = (SdSource *)source;
1243- gboolean ret;
1244-
1245- g_warn_if_fail (callback != NULL);
1246-
1247- ret = (*callback) (user_data);
1248-
1249- sd_login_monitor_flush (sd_source->monitor);
1250-
1251- return ret;
1252-}
1253-
1254-static void
1255-sd_source_finalize (GSource *source)
1256-{
1257- SdSource *sd_source = (SdSource*)source;
1258-
1259- sd_login_monitor_unref (sd_source->monitor);
1260-}
1261-
1262-static GSourceFuncs sd_source_funcs = {
1263- sd_source_prepare,
1264- sd_source_check,
1265- sd_source_dispatch,
1266- sd_source_finalize
1267-};
1268-
1269-static GSource *
1270-sd_source_new (void)
1271-{
1272- GSource *source;
1273- SdSource *sd_source;
1274- int ret;
1275-
1276- source = g_source_new (&sd_source_funcs, sizeof (SdSource));
1277- sd_source = (SdSource *)source;
1278-
1279- if ((ret = sd_login_monitor_new (NULL, &sd_source->monitor)) < 0)
1280- {
1281- g_printerr ("Error getting login monitor: %d", ret);
1282- }
1283- else
1284- {
1285- sd_source->pollfd.fd = sd_login_monitor_get_fd (sd_source->monitor);
1286- sd_source->pollfd.events = G_IO_IN;
1287- g_source_add_poll (source, &sd_source->pollfd);
1288- }
1289-
1290- return source;
1291-}
1292-
1293-struct _PolkitBackendSessionMonitor
1294-{
1295- GObject parent_instance;
1296-
1297- GDBusConnection *system_bus;
1298-
1299- GSource *sd_source;
1300-};
1301-
1302-struct _PolkitBackendSessionMonitorClass
1303-{
1304- GObjectClass parent_class;
1305-
1306- void (*changed) (PolkitBackendSessionMonitor *monitor);
1307-};
1308-
1309-
1310-enum
1311-{
1312- CHANGED_SIGNAL,
1313- LAST_SIGNAL,
1314-};
1315-
1316-static guint signals[LAST_SIGNAL] = {0};
1317-
1318-G_DEFINE_TYPE (PolkitBackendSessionMonitor, polkit_backend_session_monitor, G_TYPE_OBJECT);
1319-
1320-/* ---------------------------------------------------------------------------------------------------- */
1321-
1322-static gboolean
1323-sessions_changed (gpointer user_data)
1324-{
1325- PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (user_data);
1326-
1327- g_signal_emit (monitor, signals[CHANGED_SIGNAL], 0);
186114f9
ŁK
1328-
1329- return TRUE;
1330-}
1331-
1332-
1333-static void
1334-polkit_backend_session_monitor_init (PolkitBackendSessionMonitor *monitor)
1335-{
1336- GError *error;
1337-
1338- error = NULL;
1339- monitor->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, &error);
1340- if (monitor->system_bus == NULL)
1341- {
1342- g_printerr ("Error getting system bus: %s", error->message);
1343- g_error_free (error);
1344- }
1345-
1346- monitor->sd_source = sd_source_new ();
1347- g_source_set_callback (monitor->sd_source, sessions_changed, monitor, NULL);
1348- g_source_attach (monitor->sd_source, NULL);
1349-}
1350-
1351-static void
1352-polkit_backend_session_monitor_finalize (GObject *object)
1353-{
1354- PolkitBackendSessionMonitor *monitor = POLKIT_BACKEND_SESSION_MONITOR (object);
1355-
1356- if (monitor->system_bus != NULL)
1357- g_object_unref (monitor->system_bus);
1358-
1359- if (monitor->sd_source != NULL)
1360- {
1361- g_source_destroy (monitor->sd_source);
1362- g_source_unref (monitor->sd_source);
1363- }
1364-
1365- if (G_OBJECT_CLASS (polkit_backend_session_monitor_parent_class)->finalize != NULL)
1366- G_OBJECT_CLASS (polkit_backend_session_monitor_parent_class)->finalize (object);
1367-}
1368-
1369-static void
1370-polkit_backend_session_monitor_class_init (PolkitBackendSessionMonitorClass *klass)
1371-{
1372- GObjectClass *gobject_class;
1373-
1374- gobject_class = G_OBJECT_CLASS (klass);
1375-
1376- gobject_class->finalize = polkit_backend_session_monitor_finalize;
1377-
1378- /**
1379- * PolkitBackendSessionMonitor::changed:
1380- * @monitor: A #PolkitBackendSessionMonitor
1381- *
1382- * Emitted when something changes.
1383- */
1384- signals[CHANGED_SIGNAL] = g_signal_new ("changed",
1385- POLKIT_BACKEND_TYPE_SESSION_MONITOR,
1386- G_SIGNAL_RUN_LAST,
1387- G_STRUCT_OFFSET (PolkitBackendSessionMonitorClass, changed),
1388- NULL, /* accumulator */
1389- NULL, /* accumulator data */
1390- g_cclosure_marshal_VOID__VOID,
1391- G_TYPE_NONE,
1392- 0);
1393-}
1394-
1395-PolkitBackendSessionMonitor *
1396-polkit_backend_session_monitor_new (void)
1397-{
1398- PolkitBackendSessionMonitor *monitor;
1399-
1400- monitor = POLKIT_BACKEND_SESSION_MONITOR (g_object_new (POLKIT_BACKEND_TYPE_SESSION_MONITOR, NULL));
1401-
1402- return monitor;
1403-}
1404-
1405-/* ---------------------------------------------------------------------------------------------------- */
1406-
1407-GList *
1408-polkit_backend_session_monitor_get_sessions (PolkitBackendSessionMonitor *monitor)
1409-{
1410- /* TODO */
1411- return NULL;
1412-}
1413-
1414-/* ---------------------------------------------------------------------------------------------------- */
1415-
1416-/**
1417- * polkit_backend_session_monitor_get_user:
1418- * @monitor: A #PolkitBackendSessionMonitor.
1419- * @subject: A #PolkitSubject.
4e85edc6 1420- * @result_matches: If not %NULL, set to indicate whether the return value matches current (RACY) state.
186114f9
ŁK
1421- * @error: Return location for error.
1422- *
1423- * Gets the user corresponding to @subject or %NULL if no user exists.
1424- *
4e85edc6
JB
1425- * NOTE: For a #PolkitUnixProcess, the UID is read from @subject (which may
1426- * come from e.g. a D-Bus client), so it may not correspond to the actual UID
1427- * of the referenced process (at any point in time). This is indicated by
1428- * setting @result_matches to %FALSE; the caller may reject such subjects or
1429- * require additional privileges. @result_matches == %TRUE only indicates that
1430- * the UID matched the underlying process at ONE point in time, it may not match
1431- * later.
1432- *
186114f9
ŁK
1433- * Returns: %NULL if @error is set otherwise a #PolkitUnixUser that should be freed with g_object_unref().
1434- */
1435-PolkitIdentity *
1436-polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor *monitor,
1437- PolkitSubject *subject,
4e85edc6 1438- gboolean *result_matches,
186114f9
ŁK
1439- GError **error)
1440-{
1441- PolkitIdentity *ret;
4e85edc6 1442- gboolean matches;
186114f9
ŁK
1443-
1444- ret = NULL;
4e85edc6 1445- matches = FALSE;
186114f9
ŁK
1446-
1447- if (POLKIT_IS_UNIX_PROCESS (subject))
1448- {
4e85edc6
JB
1449- gint subject_uid, current_uid;
1450- GError *local_error;
1451-
1452- subject_uid = polkit_unix_process_get_uid (POLKIT_UNIX_PROCESS (subject));
1453- if (subject_uid == -1)
186114f9
ŁK
1454- {
1455- g_set_error (error,
1456- POLKIT_ERROR,
1457- POLKIT_ERROR_FAILED,
1458- "Unix process subject does not have uid set");
1459- goto out;
1460- }
4e85edc6
JB
1461- local_error = NULL;
1462- current_uid = polkit_unix_process_get_racy_uid__ (POLKIT_UNIX_PROCESS (subject), &local_error);
1463- if (local_error != NULL)
1464- {
1465- g_propagate_error (error, local_error);
1466- goto out;
1467- }
1468- ret = polkit_unix_user_new (subject_uid);
1469- matches = (subject_uid == current_uid);
186114f9
ŁK
1470- }
1471- else if (POLKIT_IS_SYSTEM_BUS_NAME (subject))
1472- {
77f30838 1473- ret = (PolkitIdentity*)polkit_system_bus_name_get_user_sync (POLKIT_SYSTEM_BUS_NAME (subject), NULL, error);
4e85edc6 1474- matches = TRUE;
186114f9
ŁK
1475- }
1476- else if (POLKIT_IS_UNIX_SESSION (subject))
1477- {
4e85edc6 1478- uid_t uid;
186114f9
ŁK
1479-
1480- if (sd_session_get_uid (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (subject)), &uid) < 0)
1481- {
1482- g_set_error (error,
1483- POLKIT_ERROR,
1484- POLKIT_ERROR_FAILED,
1485- "Error getting uid for session");
1486- goto out;
1487- }
1488-
1489- ret = polkit_unix_user_new (uid);
4e85edc6 1490- matches = TRUE;
186114f9
ŁK
1491- }
1492-
1493- out:
4e85edc6
JB
1494- if (result_matches != NULL)
1495- {
1496- *result_matches = matches;
1497- }
186114f9
ŁK
1498- return ret;
1499-}
1500-
1501-/**
1502- * polkit_backend_session_monitor_get_session_for_subject:
1503- * @monitor: A #PolkitBackendSessionMonitor.
1504- * @subject: A #PolkitSubject.
1505- * @error: Return location for error.
1506- *
1507- * Gets the session corresponding to @subject or %NULL if no session exists.
1508- *
1509- * Returns: %NULL if @error is set otherwise a #PolkitUnixSession that should be freed with g_object_unref().
1510- */
1511-PolkitSubject *
1512-polkit_backend_session_monitor_get_session_for_subject (PolkitBackendSessionMonitor *monitor,
1513- PolkitSubject *subject,
1514- GError **error)
1515-{
77f30838
JB
1516- PolkitUnixProcess *tmp_process = NULL;
1517- PolkitUnixProcess *process = NULL;
1518- PolkitSubject *session = NULL;
1519- char *session_id = NULL;
1520- pid_t pid;
1521-#if HAVE_SD_UID_GET_DISPLAY
1522- uid_t uid;
1523-#endif
186114f9
ŁK
1524-
1525- if (POLKIT_IS_UNIX_PROCESS (subject))
77f30838 1526- process = POLKIT_UNIX_PROCESS (subject); /* We already have a process */
186114f9
ŁK
1527- else if (POLKIT_IS_SYSTEM_BUS_NAME (subject))
1528- {
77f30838
JB
1529- /* Convert bus name to process */
1530- tmp_process = (PolkitUnixProcess*)polkit_system_bus_name_get_process_sync (POLKIT_SYSTEM_BUS_NAME (subject), NULL, error);
1531- if (!tmp_process)
1532- goto out;
1533- process = tmp_process;
186114f9
ŁK
1534- }
1535- else
1536- {
1537- g_set_error (error,
1538- POLKIT_ERROR,
1539- POLKIT_ERROR_NOT_SUPPORTED,
77f30838 1540- "Cannot get session for subject of type %s",
186114f9
ŁK
1541- g_type_name (G_TYPE_FROM_INSTANCE (subject)));
1542- }
1543-
77f30838
JB
1544- /* Now do process -> pid -> same session */
1545- g_assert (process != NULL);
1546- pid = polkit_unix_process_get_pid (process);
186114f9 1547-
77f30838
JB
1548- if (sd_pid_get_session (pid, &session_id) >= 0)
1549- {
1550- session = polkit_unix_session_new (session_id);
1551- goto out;
1552- }
1553-
1554-#if HAVE_SD_UID_GET_DISPLAY
1555- /* Now do process -> uid -> graphical session (systemd version 213)*/
1556- if (sd_pid_get_owner_uid (pid, &uid) < 0)
1557- goto out;
1558-
1559- if (sd_uid_get_display (uid, &session_id) >= 0)
1560- {
1561- session = polkit_unix_session_new (session_id);
1562- goto out;
1563- }
1564-#endif
1565-
1566- out:
1567- free (session_id);
1568- if (tmp_process) g_object_unref (tmp_process);
186114f9
ŁK
1569- return session;
1570-}
1571-
1572-gboolean
1573-polkit_backend_session_monitor_is_session_local (PolkitBackendSessionMonitor *monitor,
1574- PolkitSubject *session)
1575-{
1576- char *seat;
1577-
1578- if (!sd_session_get_seat (polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (session)), &seat))
1579- {
1580- free (seat);
1581- return TRUE;
1582- }
1583-
1584- return FALSE;
1585-}
1586-
1587-
1588-gboolean
1589-polkit_backend_session_monitor_is_session_active (PolkitBackendSessionMonitor *monitor,
1590- PolkitSubject *session)
1591-{
77f30838
JB
1592- const char *session_id;
1593- char *state;
1594- uid_t uid;
1595- gboolean is_active = FALSE;
1596-
1597- session_id = polkit_unix_session_get_session_id (POLKIT_UNIX_SESSION (session));
1598-
1599- g_debug ("Checking whether session %s is active.", session_id);
1600-
1601- /* Check whether *any* of the user's current sessions are active. */
1602- if (sd_session_get_uid (session_id, &uid) < 0)
1603- goto fallback;
1604-
1605- g_debug ("Session %s has UID %u.", session_id, uid);
1606-
1607- if (sd_uid_get_state (uid, &state) < 0)
1608- goto fallback;
1609-
1610- g_debug ("UID %u has state %s.", uid, state);
1611-
1612- is_active = (g_strcmp0 (state, "active") == 0);
1613- free (state);
1614-
1615- return is_active;
1616-
1617-fallback:
1618- /* Fall back to checking the session. This is not ideal, since the user
1619- * might have multiple sessions, and we cannot guarantee to have chosen
1620- * the active one.
1621- *
1622- * See: https://bugs.freedesktop.org/show_bug.cgi?id=76358. */
1623- return sd_session_is_active (session_id);
186114f9
ŁK
1624-}
1625-
fbe373fc
JP
1626diff -ur polkit-v.121.orig/meson.build polkit-v.121/meson.build
1627--- polkit-v.121.orig/meson.build 2022-07-11 10:46:06.000000000 +0200
1628+++ polkit-v.121/meson.build 2022-07-13 23:02:30.432622964 +0200
1629@@ -187,7 +187,8 @@
1630 if session_tracking == 'libsystemd-login'
1631 logind_dep = dependency('libsystemd', required: false)
1632 if not logind_dep.found()
1633- logind_dep = dependency('libsystemd-login', not_found_message: 'libsystemd support requested but libsystemd or libsystemd-login library not found')
1634+ logind_dep = [ dependency('libsystemd-login', not_found_message: 'libsystemd support requested but libsystemd or libsystemd-login library not found'),dependency('libsystemd-daemon', not_found_message: 'libsystemd support requested but libsystemd or libsystemd-daemon library not found')]
1635+
1636 endif
1637 else
1638 logind_dep = dependency('libelogind', not_found_message: 'libelogind support requested but libelogind library not found')
1639diff -ur polkit-v.121.orig/src/polkit/meson.build polkit-v.121/src/polkit/meson.build
1640--- polkit-v.121.orig/src/polkit/meson.build 2022-07-11 10:46:06.000000000 +0200
1641+++ polkit-v.121/src/polkit/meson.build 2022-07-13 23:11:05.333520578 +0200
1642@@ -77,13 +77,11 @@
1643 c_flags = '-D_POLKIT_COMPILATION'
1644
1645 if enable_logind
1646- sources += 'polkitunixsession-systemd.c'
1647-
1648 deps += logind_dep
1649-else
1650- sources += 'polkitunixsession.c'
1651 endif
1652
1653+ sources += 'polkitunixsession.c'
1654+
1655 libpolkit_gobject = shared_library(
1656 name,
1657 sources: sources,
1658diff -ur polkit-v.121.orig/src/polkitbackend/meson.build polkit-v.121/src/polkitbackend/meson.build
1659--- polkit-v.121.orig/src/polkitbackend/meson.build 2022-07-11 10:46:06.000000000 +0200
1660+++ polkit-v.121/src/polkitbackend/meson.build 2022-07-13 23:05:09.917827287 +0200
1661@@ -43,12 +43,9 @@
1662 endif
1663
1664 if enable_logind
1665- sources += files('polkitbackendsessionmonitor-systemd.c')
1666-
1667 deps += logind_dep
1668-else
1669- sources += files('polkitbackendsessionmonitor.c')
1670 endif
1671+ sources += files('polkitbackendsessionmonitor.c')
1672
1673 libpolkit_backend = static_library(
1674 name,
This page took 0.281845 seconds and 4 git commands to generate.