PolicyKit: Branch 'master'
David Zeuthen
david at kemper.freedesktop.org
Wed Aug 12 11:49:37 PDT 2009
configure.ac | 25 +++++
docs/polkit/polkit-1-sections.txt | 1
src/polkit/Makefile.am | 63 +++++++++++++
src/polkit/polkit.h | 2
src/polkit/polkitcheckauthorizationflags.c | 6 -
src/polkit/polkitenumtypes.c.template | 39 ++++++++
src/polkit/polkitenumtypes.h.template | 24 +++++
src/polkit/polkiterror.c | 6 -
src/polkit/polkitidentity.c | 4
src/polkit/polkitimplicitauthorization.c | 6 -
src/polkit/polkitsubject.c | 2
src/polkit/polkitunixgroup.c | 40 ++++----
src/polkit/polkitunixgroup.h | 6 -
src/polkit/polkitunixprocess.c | 109 ++++++++++++++----------
src/polkit/polkitunixprocess.h | 12 +-
src/polkit/polkitunixsession.c | 30 +++---
src/polkit/polkitunixsession.h | 4
src/polkit/polkitunixuser.c | 34 +++----
src/polkit/polkitunixuser.h | 6 -
src/polkitbackend/polkitbackendsessionmonitor.c | 15 +--
src/programs/pkexec.c | 17 +++
21 files changed, 306 insertions(+), 145 deletions(-)
New commits:
commit a7aacbb57823f5001e1db69cb82cba57195c6a58
Author: David Zeuthen <davidz at redhat.com>
Date: Wed Aug 12 14:40:46 2009 -0400
Generate GI gir and typelibs for libpolkit-gobject-1
This includes changing from POSIX types (uid_t, gid_t, pid_t) to
gint. Won't affect much since the size is the same. And we want this
anyway since it is needed to build the library on non-POSIX platforms.
diff --git a/configure.ac b/configure.ac
index 3ea3818..8c838ef 100644
--- a/configure.ac
+++ b/configure.ac
@@ -381,7 +381,7 @@ AC_DEFINE_UNQUOTED(PAM_FILE_INCLUDE_PASSWORD, "$PAM_FILE_INCLUDE_PASSWORD", [pam
AC_DEFINE_UNQUOTED(PAM_FILE_INCLUDE_SESSION, "$PAM_FILE_INCLUDE_SESSION", [pam file session])
dnl ---------------------------------------------------------------------------
-dnl - check OS
+dnl - check OS
dnl ---------------------------------------------------------------------------
case "$host_os" in
*linux*)
@@ -394,9 +394,29 @@ case "$host_os" in
;;
esac
+# GObject introspection
+#
+AC_ARG_ENABLE([introspection],
+ AS_HELP_STRING([--enable-introspection], [enable GObject introspection]),
+ [], [enable_introspection=yes])
+if test "x$enable_introspection" = xyes; then
+ PKG_CHECK_MODULES([INTROSPECTION], [gobject-introspection-1.0 >= 0.6.2])
+ AC_DEFINE([ENABLE_INTROSPECTION], [1], [enable GObject introspection support])
+ AC_SUBST([G_IR_SCANNER], [$($PKG_CONFIG --variable=g_ir_scanner gobject-introspection-1.0)])
+ AC_SUBST([G_IR_COMPILER], [$($PKG_CONFIG --variable=g_ir_compiler gobject-introspection-1.0)])
+ AC_SUBST([G_IR_GENERATE], [$($PKG_CONFIG --variable=g_ir_generate gobject-introspection-1.0)])
+ #AC_SUBST([GIRDIR], [$($PKG_CONFIG --variable=girdir gobject-introspection-1.0)])
+ #AC_SUBST([GIRTYPELIBDIR], [$($PKG_CONFIG --variable=typelibdir gobject-introspection-1.0)])
+ GIRDIR=${datadir}/gir-1.0
+ GIRTYPELIBDIR=${libdir}/girepository-1.0
+ AC_SUBST(GIRDIR)
+ AC_SUBST(GIRTYPELIBDIR)
+fi
+AM_CONDITIONAL([ENABLE_INTROSPECTION], [test "x$enable_introspection" = xyes])
+
# ********************
-# Internationalisation
+# Internationalization
# ********************
IT_PROG_INTLTOOL([0.40.0])
@@ -448,6 +468,7 @@ echo "
cflags: ${CFLAGS}
cppflags: ${CPPFLAGS}
xsltproc: ${XSLTPROC}
+ introspection: ${enable_introspection}
Distribution/OS: ${with_os_type}
user for PolicyKit: ${POLKIT_USER}
diff --git a/docs/polkit/polkit-1-sections.txt b/docs/polkit/polkit-1-sections.txt
index e3fb70e..9219fb8 100644
--- a/docs/polkit/polkit-1-sections.txt
+++ b/docs/polkit/polkit-1-sections.txt
@@ -139,6 +139,7 @@ polkit_unix_process_new_full
polkit_unix_process_get_pid
polkit_unix_process_get_start_time
polkit_unix_process_set_pid
+polkit_unix_process_get_owner
<SUBSECTION Standard>
PolkitUnixProcessClass
POLKIT_UNIX_PROCESS
diff --git a/src/polkit/Makefile.am b/src/polkit/Makefile.am
index 2739cd3..436054b 100644
--- a/src/polkit/Makefile.am
+++ b/src/polkit/Makefile.am
@@ -17,8 +17,21 @@ INCLUDES = \
BUILT_SOURCES = \
polkit-built-sources.stamp \
+ polkitenumtypes.c polkitenumtypes.h \
$(NULL)
+enum_headers = polkitcheckauthorizationflags.h polkiterror.h polkitimplicitauthorization.h
+
+polkitenumtypes.h: $(enum_headers) polkitenumtypes.h.template
+ ( top_builddir=`cd $(top_builddir) && pwd`; \
+ cd $(srcdir) && glib-mkenums --template polkitenumtypes.h.template $(enum_headers)) > \
+ polkitenumtypes.h.tmp && mv polkitenumtypes.h.tmp polkitenumtypes.h
+
+polkitenumtypes.c: $(enum_headers) polkitenumtypes.c.template
+ ( top_builddir=`cd $(top_builddir) && pwd`; \
+ cd $(srcdir) && glib-mkenums --template polkitenumtypes.c.template $(enum_headers)) > \
+ polkitenumtypes.c.tmp && mv polkitenumtypes.c.tmp polkitenumtypes.c
+
# Build all the PolicyKit D-Bus code here, even the code we
# only in the daemon for agent interaction
#
@@ -43,6 +56,7 @@ libpolkit_gobject_1include_HEADERS = \
polkit.h \
polkitprivate.h \
polkittypes.h \
+ polkitenumtypes.h \
polkitactiondescription.h \
polkitdetails.h \
polkitauthority.h \
@@ -92,6 +106,55 @@ libpolkit_gobject_1_la_LIBADD = \
$(EGG_DBUS_LIBS) \
$(NULL)
+if ENABLE_INTROSPECTION
+girdir = $(GIRDIR)
+gir_DATA = Polkit-1.0.gir
+
+typelibsdir = $(GIRTYPELIBDIR)
+typelibs_DATA = Polkit-1.0.typelib
+
+Polkit-1.0.gir: libpolkit-gobject-1.la $(G_IR_SCANNER) Makefile.am
+ $(G_IR_SCANNER) -v \
+ --namespace Polkit \
+ --nsversion=1.0 \
+ --include=Gio-2.0 \
+ --library=polkit-gobject-1 \
+ --output $@ \
+ --pkg=glib-2.0 \
+ --pkg=gobject-2.0 \
+ --pkg=gio-2.0 \
+ $(EGG_DBUS_CFLAGS) \
+ -I$(top_srcdir)/src \
+ -D_POLKIT_COMPILATION \
+ -DEGG_DBUS_I_KNOW_API_IS_SUBJECT_TO_CHANGE \
+ $(srcdir)/polkit.h \
+ $(srcdir)/polkittypes.h \
+ $(srcdir)/polkitactiondescription.h \
+ $(srcdir)/polkitauthority.h \
+ $(srcdir)/polkitauthorizationresult.h \
+ $(srcdir)/polkitcheckauthorizationflags.h \
+ $(srcdir)/polkitdetails.h \
+ $(builddir)/polkitenumtypes.h \
+ $(srcdir)/polkiterror.h \
+ $(srcdir)/polkitidentity.h \
+ $(srcdir)/polkitimplicitauthorization.h \
+ $(srcdir)/polkitsubject.h \
+ $(srcdir)/polkitsystembusname.h \
+ $(srcdir)/polkittemporaryauthorization.h \
+ $(srcdir)/polkitunixgroup.h \
+ $(srcdir)/polkitunixprocess.h \
+ $(srcdir)/polkitunixsession.h \
+ $(srcdir)/polkitunixuser.h \
+ $(NULL)
+
+Polkit-1.0.typelib: Polkit-1.0.gir $(G_IR_COMPILER)
+ $(G_IR_COMPILER) $< -o $@
+
+endif # ENABLE_INTROSPECTION
+
+EXTRA_DIST = Polkit-1.0.gir polkitenumtypes.h.template polkitenumtypes.c.template
+CLEANFILES = $(gir_DATA) $(typelibs_DATA)
+
dist-hook :
(for i in $(polkit_built_sources) $(BUILT_SOURCES) ; do rm -f $(distdir)/$$i ; done)
diff --git a/src/polkit/polkit.h b/src/polkit/polkit.h
index 9c16710..c878194 100644
--- a/src/polkit/polkit.h
+++ b/src/polkit/polkit.h
@@ -24,6 +24,8 @@
#define _POLKIT_INSIDE_POLKIT_H 1
+#include <polkit/polkittypes.h>
+#include <polkit/polkitenumtypes.h>
#include <polkit/polkitimplicitauthorization.h>
#include <polkit/polkitactiondescription.h>
#include <polkit/polkiterror.h>
diff --git a/src/polkit/polkitcheckauthorizationflags.c b/src/polkit/polkitcheckauthorizationflags.c
index f6e1e23..16a9125 100644
--- a/src/polkit/polkitcheckauthorizationflags.c
+++ b/src/polkit/polkitcheckauthorizationflags.c
@@ -26,10 +26,4 @@
#include "polkitcheckauthorizationflags.h"
#include "polkitprivate.h"
-GType
-polkit_check_authorization_flags_get_type (void)
-{
- return _polkit_check_authorization_flags_get_type ();
-}
-
diff --git a/src/polkit/polkitenumtypes.c.template b/src/polkit/polkitenumtypes.c.template
new file mode 100644
index 0000000..7704cca
--- /dev/null
+++ b/src/polkit/polkitenumtypes.c.template
@@ -0,0 +1,39 @@
+/*** BEGIN file-header ***/
+#include <polkit/polkit.h>
+
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+/* enumerations from "@filename@" */
+/*** END file-production ***/
+
+/*** BEGIN value-header ***/
+GType
+ at enum_name@_get_type (void)
+{
+ static volatile gsize g_define_type_id__volatile = 0;
+
+ if (g_once_init_enter (&g_define_type_id__volatile))
+ {
+ static const G at Type@Value values[] = {
+/*** END value-header ***/
+
+/*** BEGIN value-production ***/
+ { @VALUENAME@, "@VALUENAME@", "@valuenick@" },
+/*** END value-production ***/
+
+/*** BEGIN value-tail ***/
+ { 0, NULL, NULL }
+ };
+ GType g_define_type_id =
+ g_ at type@_register_static (g_intern_static_string ("@EnumName@"), values);
+ g_once_init_leave (&g_define_type_id__volatile, g_define_type_id);
+ }
+
+ return g_define_type_id__volatile;
+}
+
+/*** END value-tail ***/
+
+/*** BEGIN file-tail ***/
+/*** END file-tail ***/
diff --git a/src/polkit/polkitenumtypes.h.template b/src/polkit/polkitenumtypes.h.template
new file mode 100644
index 0000000..2ce48a6
--- /dev/null
+++ b/src/polkit/polkitenumtypes.h.template
@@ -0,0 +1,24 @@
+/*** BEGIN file-header ***/
+#ifndef __POLKIT_ENUM_TYPES_H__
+#define __POLKIT_ENUM_TYPES_H__
+
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+/*** END file-header ***/
+
+/*** BEGIN file-production ***/
+
+/* enumerations from "@filename@" */
+/*** END file-production ***/
+
+/*** BEGIN value-header ***/
+GType @enum_name at _get_type (void) G_GNUC_CONST;
+#define @ENUMPREFIX at _TYPE_@ENUMSHORT@ (@enum_name at _get_type ())
+/*** END value-header ***/
+
+/*** BEGIN file-tail ***/
+G_END_DECLS
+
+#endif /* __POLKIT_ENUM_TYPES_H__ */
+/*** END file-tail ***/
diff --git a/src/polkit/polkiterror.c b/src/polkit/polkiterror.c
index 0d9f39d..9a50d10 100644
--- a/src/polkit/polkiterror.c
+++ b/src/polkit/polkiterror.c
@@ -40,9 +40,3 @@ polkit_error_quark (void)
return _polkit_error_quark ();
}
-GType
-polkit_error_get_type (void)
-{
- return _polkit_error_get_type ();
-}
-
diff --git a/src/polkit/polkitidentity.c b/src/polkit/polkitidentity.c
index 08fd6ac..e1b14d6 100644
--- a/src/polkit/polkitidentity.c
+++ b/src/polkit/polkitidentity.c
@@ -155,7 +155,7 @@ polkit_identity_from_string (const gchar *str,
&endptr,
10);
if (*endptr == '\0')
- identity = polkit_unix_user_new ((uid_t) val);
+ identity = polkit_unix_user_new ((gint) val);
else
identity = polkit_unix_user_new_for_name (str + sizeof "unix-user:" - 1,
error);
@@ -166,7 +166,7 @@ polkit_identity_from_string (const gchar *str,
&endptr,
10);
if (*endptr == '\0')
- identity = polkit_unix_group_new ((gid_t) val);
+ identity = polkit_unix_group_new ((gint) val);
else
identity = polkit_unix_group_new_for_name (str + sizeof "unix-group:" - 1,
error);
diff --git a/src/polkit/polkitimplicitauthorization.c b/src/polkit/polkitimplicitauthorization.c
index 53d9923..1d6a933 100644
--- a/src/polkit/polkitimplicitauthorization.c
+++ b/src/polkit/polkitimplicitauthorization.c
@@ -36,12 +36,6 @@
* Possible implicit authorizations.
*/
-GType
-polkit_implicit_authorization_get_type (void)
-{
- return _polkit_implicit_authorization_get_type ();
-}
-
gboolean
polkit_implicit_authorization_from_string (const gchar *string,
PolkitImplicitAuthorization *out_implicit_authorization)
diff --git a/src/polkit/polkitsubject.c b/src/polkit/polkitsubject.c
index b2f9290..04067da 100644
--- a/src/polkit/polkitsubject.c
+++ b/src/polkit/polkitsubject.c
@@ -225,7 +225,7 @@ polkit_subject_from_string (const gchar *str,
10);
if (*endptr == '\0')
{
- subject = polkit_unix_process_new ((pid_t) val);
+ subject = polkit_unix_process_new ((gint) val);
if (polkit_unix_process_get_start_time (POLKIT_UNIX_PROCESS (subject)) == 0)
{
g_object_unref (subject);
diff --git a/src/polkit/polkitunixgroup.c b/src/polkit/polkitunixgroup.c
index 0c2e473..733a2c5 100644
--- a/src/polkit/polkitunixgroup.c
+++ b/src/polkit/polkitunixgroup.c
@@ -48,7 +48,7 @@ struct _PolkitUnixGroup
{
GObject parent_instance;
- gid_t gid;
+ gint gid;
};
struct _PolkitUnixGroupClass
@@ -75,16 +75,16 @@ polkit_unix_group_init (PolkitUnixGroup *unix_group)
static void
polkit_unix_group_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
PolkitUnixGroup *unix_group = POLKIT_UNIX_GROUP (object);
switch (prop_id)
{
case PROP_GID:
- g_value_set_uint (value, unix_group->gid);
+ g_value_set_int (value, unix_group->gid);
break;
default:
@@ -104,7 +104,7 @@ polkit_unix_group_set_property (GObject *object,
switch (prop_id)
{
case PROP_GID:
- unix_group->gid = g_value_get_uint (value);
+ unix_group->gid = g_value_get_int (value);
break;
default:
@@ -128,17 +128,17 @@ polkit_unix_group_class_init (PolkitUnixGroupClass *klass)
*/
g_object_class_install_property (gobject_class,
PROP_GID,
- g_param_spec_uint ("gid",
- "Group ID",
- "The UNIX group ID",
- 0,
- G_MAXUINT,
- 0,
- G_PARAM_CONSTRUCT |
- G_PARAM_READWRITE |
- G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_BLURB |
- G_PARAM_STATIC_NICK));
+ g_param_spec_int ("gid",
+ "Group ID",
+ "The UNIX group ID",
+ 0,
+ G_MAXINT,
+ 0,
+ G_PARAM_CONSTRUCT |
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_BLURB |
+ G_PARAM_STATIC_NICK));
}
@@ -150,7 +150,7 @@ polkit_unix_group_class_init (PolkitUnixGroupClass *klass)
*
* Returns: A UNIX group id.
*/
-gid_t
+gint
polkit_unix_group_get_gid (PolkitUnixGroup *group)
{
return group->gid;
@@ -165,7 +165,7 @@ polkit_unix_group_get_gid (PolkitUnixGroup *group)
*/
void
polkit_unix_group_set_gid (PolkitUnixGroup *group,
- gid_t gid)
+ gint gid)
{
group->gid = gid;
}
@@ -179,7 +179,7 @@ polkit_unix_group_set_gid (PolkitUnixGroup *group,
* Returns: A #PolkitUnixGroup object. Free with g_object_unref().
*/
PolkitIdentity *
-polkit_unix_group_new (gid_t gid)
+polkit_unix_group_new (gint gid)
{
return POLKIT_IDENTITY (g_object_new (POLKIT_TYPE_UNIX_GROUP,
"gid", gid,
diff --git a/src/polkit/polkitunixgroup.h b/src/polkit/polkitunixgroup.h
index 49e171a..3165cf9 100644
--- a/src/polkit/polkitunixgroup.h
+++ b/src/polkit/polkitunixgroup.h
@@ -47,12 +47,12 @@ typedef struct _PolkitUnixGroup PolkitUnixGroup;
typedef struct _PolkitUnixGroupClass PolkitUnixGroupClass;
GType polkit_unix_group_get_type (void) G_GNUC_CONST;
-PolkitIdentity *polkit_unix_group_new (gid_t gid);
+PolkitIdentity *polkit_unix_group_new (gint gid);
PolkitIdentity *polkit_unix_group_new_for_name (const gchar *name,
GError **error);
-gid_t polkit_unix_group_get_gid (PolkitUnixGroup *group);
+gint polkit_unix_group_get_gid (PolkitUnixGroup *group);
void polkit_unix_group_set_gid (PolkitUnixGroup *group,
- gid_t gid);
+ gint gid);
G_END_DECLS
diff --git a/src/polkit/polkitunixprocess.c b/src/polkit/polkitunixprocess.c
index d559a4f..f8e6fd9 100644
--- a/src/polkit/polkitunixprocess.c
+++ b/src/polkit/polkitunixprocess.c
@@ -33,6 +33,8 @@
#endif
#include <stdlib.h>
#include <string.h>
+#include <errno.h>
+
#include "polkitunixprocess.h"
#include "polkitsubject.h"
#include "polkitprivate.h"
@@ -59,7 +61,7 @@ struct _PolkitUnixProcess
{
GObject parent_instance;
- pid_t pid;
+ gint pid;
guint64 start_time;
};
@@ -77,11 +79,11 @@ enum
static void subject_iface_init (PolkitSubjectIface *subject_iface);
-static guint64 get_start_time_for_pid (pid_t pid,
+static guint64 get_start_time_for_pid (gint pid,
GError **error);
#ifdef HAVE_FREEBSD
-static gboolean get_kinfo_proc (pid_t pid, struct kinfo_proc *p);
+static gboolean get_kinfo_proc (gint pid, struct kinfo_proc *p);
#endif
G_DEFINE_TYPE_WITH_CODE (PolkitUnixProcess, polkit_unix_process, G_TYPE_OBJECT,
@@ -104,7 +106,7 @@ polkit_unix_process_get_property (GObject *object,
switch (prop_id)
{
case PROP_PID:
- g_value_set_uint (value, unix_process->pid);
+ g_value_set_int (value, unix_process->pid);
break;
case PROP_START_TIME:
@@ -128,7 +130,7 @@ polkit_unix_process_set_property (GObject *object,
switch (prop_id)
{
case PROP_PID:
- polkit_unix_process_set_pid (unix_process, g_value_get_uint (value));
+ polkit_unix_process_set_pid (unix_process, g_value_get_int (value));
break;
default:
@@ -152,17 +154,17 @@ polkit_unix_process_class_init (PolkitUnixProcessClass *klass)
*/
g_object_class_install_property (gobject_class,
PROP_PID,
- g_param_spec_uint ("pid",
- "Process ID",
- "The UNIX process ID",
- 0,
- G_MAXUINT,
- 0,
- G_PARAM_CONSTRUCT |
- G_PARAM_READWRITE |
- G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_BLURB |
- G_PARAM_STATIC_NICK));
+ g_param_spec_int ("pid",
+ "Process ID",
+ "The UNIX process ID",
+ 0,
+ G_MAXINT,
+ 0,
+ G_PARAM_CONSTRUCT |
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_BLURB |
+ G_PARAM_STATIC_NICK));
/**
* PolkitUnixProcess:start-time:
@@ -192,48 +194,67 @@ polkit_unix_process_class_init (PolkitUnixProcessClass *klass)
*
* Returns: The process id for @process.
*/
-pid_t
+gint
polkit_unix_process_get_pid (PolkitUnixProcess *process)
{
return process->pid;
}
/**
- * polkit_unix_pid_get_uid:
- * @pid: A process ID.
- * @uid: A pointer to a uid_t.
+ * polkit_unix_process_get_owner:
+ * @process: A #PolkitUnixProcess.
+ * @error: Return location for error or %NULL.
*
- * Gets the uid for a given @pid.
+ * Gets the uid of the owner of @process.
*
- * Returns: 0 on success, -1 on failure.
- */
-int
-polkit_unix_pid_get_uid (pid_t pid, uid_t *uid)
+ * Returns: The UNIX user id of the owner for @process or 0 if @error is set.
+ **/
+gint
+polkit_unix_process_get_owner (PolkitUnixProcess *process,
+ GError **error)
{
-#ifndef HAVE_FREEBSD
+ gint result;
+#ifdef HAVE_FREEBSD
+ struct kinfo_proc p;
+#else
struct stat statbuf;
char procbuf[32];
-#else
- struct kinfo_proc p;
#endif
- g_return_val_if_fail (uid != NULL, -1);
- g_return_val_if_fail (pid > 0, -1);
+ result = 0;
-#ifndef HAVE_FREEBSD
- g_snprintf (procbuf, sizeof procbuf, "/proc/%d", pid);
- if (stat (procbuf, &statbuf) != 0)
- return -1;
+#ifdef HAVE_FREEBSD
+ if (get_kinfo_proc (process->pid, &p) == 0)
+ {
+ g_set_error (error,
+ POLKIT_ERROR,
+ POLKIT_ERROR_FAILED,
+ "get_kinfo_proc() failed for pid %d: %s",
+ process->pid,
+ g_strerror (errno));
+ goto out;
+ }
- *uid = statbuf.st_uid;
+ result = p.ki_uid;
#else
- if (! get_kinfo_proc (pid, &p))
- return -1;
+ g_snprintf (procbuf, sizeof procbuf, "/proc/%d", process->pid);
+ if (stat (procbuf, &statbuf) != 0)
+ {
+ g_set_error (error,
+ POLKIT_ERROR,
+ POLKIT_ERROR_FAILED,
+ "stat() failed for /proc/%d: %s",
+ process->pid,
+ g_strerror (errno));
+ goto out;
+ }
- *uid = p.ki_uid;
+ result = statbuf.st_uid;
#endif
- return 0;
+ out:
+
+ return result;
}
/**
@@ -259,10 +280,10 @@ polkit_unix_process_get_start_time (PolkitUnixProcess *process)
*/
void
polkit_unix_process_set_pid (PolkitUnixProcess *process,
- pid_t pid)
+ gint pid)
{
process->pid = pid;
- if (pid != (pid_t) -1)
+ if (pid != (gint) -1)
process->start_time = get_start_time_for_pid (pid, NULL);
}
@@ -278,7 +299,7 @@ polkit_unix_process_set_pid (PolkitUnixProcess *process,
* Returns: A #PolkitSubject. Free with g_object_unref().
*/
PolkitSubject *
-polkit_unix_process_new (pid_t pid)
+polkit_unix_process_new (gint pid)
{
return POLKIT_SUBJECT (g_object_new (POLKIT_TYPE_UNIX_PROCESS,
"pid", pid,
@@ -295,12 +316,12 @@ polkit_unix_process_new (pid_t pid)
* Returns: A #PolkitSubject. Free with g_object_unref().
*/
PolkitSubject *
-polkit_unix_process_new_full (pid_t pid,
+polkit_unix_process_new_full (gint pid,
guint64 start_time)
{
PolkitUnixProcess *process;
- process = POLKIT_UNIX_PROCESS (polkit_unix_process_new ((pid_t) -1));
+ process = POLKIT_UNIX_PROCESS (polkit_unix_process_new ((gint) -1));
process->pid = pid;
process->start_time = start_time;
diff --git a/src/polkit/polkitunixprocess.h b/src/polkit/polkitunixprocess.h
index 731ee61..b88cd03 100644
--- a/src/polkit/polkitunixprocess.h
+++ b/src/polkit/polkitunixprocess.h
@@ -47,16 +47,16 @@ typedef struct _PolkitUnixProcess PolkitUnixProcess;
typedef struct _PolkitUnixProcessClass PolkitUnixProcessClass;
GType polkit_unix_process_get_type (void) G_GNUC_CONST;
-PolkitSubject *polkit_unix_process_new (pid_t pid);
-PolkitSubject *polkit_unix_process_new_full (pid_t pid,
+PolkitSubject *polkit_unix_process_new (gint pid);
+PolkitSubject *polkit_unix_process_new_full (gint pid,
guint64 start_time);
-pid_t polkit_unix_process_get_pid (PolkitUnixProcess *process);
-int polkit_unix_pid_get_uid (pid_t pid, uid_t *uid);
+gint polkit_unix_process_get_pid (PolkitUnixProcess *process);
guint64 polkit_unix_process_get_start_time (PolkitUnixProcess *process);
-
void polkit_unix_process_set_pid (PolkitUnixProcess *process,
- pid_t pid);
+ gint pid);
+gint polkit_unix_process_get_owner (PolkitUnixProcess *process,
+ GError **error);
G_END_DECLS
diff --git a/src/polkit/polkitunixsession.c b/src/polkit/polkitunixsession.c
index fc6a18b..cdf49d2 100644
--- a/src/polkit/polkitunixsession.c
+++ b/src/polkit/polkitunixsession.c
@@ -50,7 +50,7 @@ struct _PolkitUnixSession
gchar *session_id;
- pid_t pid;
+ gint pid;
};
struct _PolkitUnixSessionClass
@@ -126,7 +126,7 @@ polkit_unix_session_set_property (GObject *object,
break;
case PROP_PID:
- session->pid = g_value_get_uint (value);
+ session->pid = g_value_get_int (value);
break;
default:
@@ -169,17 +169,17 @@ polkit_unix_session_class_init (PolkitUnixSessionClass *klass)
*/
g_object_class_install_property (gobject_class,
PROP_PID,
- g_param_spec_uint ("pid",
- "Process ID",
- "Process ID to use for looking up the session",
- 0,
- G_MAXUINT,
- 0,
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_WRITABLE |
- G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_BLURB |
- G_PARAM_STATIC_NICK));
+ g_param_spec_int ("pid",
+ "Process ID",
+ "Process ID to use for looking up the session",
+ 0,
+ G_MAXINT,
+ 0,
+ G_PARAM_CONSTRUCT_ONLY |
+ G_PARAM_WRITABLE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_BLURB |
+ G_PARAM_STATIC_NICK));
}
@@ -247,7 +247,7 @@ polkit_unix_session_new (const gchar *session_id)
* use polkit_unix_session_new_for_process_sync().
**/
void
-polkit_unix_session_new_for_process (pid_t pid,
+polkit_unix_session_new_for_process (gint pid,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data)
@@ -307,7 +307,7 @@ polkit_unix_session_new_for_process_finish (GAsyncResult *res,
* Returns: A #PolkitUnixSession for @pid or %NULL if @error is set. Free with g_object_unref().
**/
PolkitSubject *
-polkit_unix_session_new_for_process_sync (pid_t pid,
+polkit_unix_session_new_for_process_sync (gint pid,
GCancellable *cancellable,
GError **error)
{
diff --git a/src/polkit/polkitunixsession.h b/src/polkit/polkitunixsession.h
index e858094..2674abe 100644
--- a/src/polkit/polkitunixsession.h
+++ b/src/polkit/polkitunixsession.h
@@ -46,13 +46,13 @@ typedef struct _PolkitUnixSessionClass PolkitUnixSessionClass;
GType polkit_unix_session_get_type (void) G_GNUC_CONST;
PolkitSubject *polkit_unix_session_new (const gchar *session_id);
-void polkit_unix_session_new_for_process (pid_t pid,
+void polkit_unix_session_new_for_process (gint pid,
GCancellable *cancellable,
GAsyncReadyCallback callback,
gpointer user_data);
PolkitSubject *polkit_unix_session_new_for_process_finish (GAsyncResult *res,
GError **error);
-PolkitSubject *polkit_unix_session_new_for_process_sync (pid_t pid,
+PolkitSubject *polkit_unix_session_new_for_process_sync (gint pid,
GCancellable *cancellable,
GError **error);
const gchar *polkit_unix_session_get_session_id (PolkitUnixSession *session);
diff --git a/src/polkit/polkitunixuser.c b/src/polkit/polkitunixuser.c
index 1f5af13..f9915f0 100644
--- a/src/polkit/polkitunixuser.c
+++ b/src/polkit/polkitunixuser.c
@@ -48,7 +48,7 @@ struct _PolkitUnixUser
{
GObject parent_instance;
- uid_t uid;
+ gint uid;
};
struct _PolkitUnixUserClass
@@ -84,7 +84,7 @@ polkit_unix_user_get_property (GObject *object,
switch (prop_id)
{
case PROP_UID:
- g_value_set_uint (value, unix_user->uid);
+ g_value_set_int (value, unix_user->uid);
break;
default:
@@ -104,7 +104,7 @@ polkit_unix_user_set_property (GObject *object,
switch (prop_id)
{
case PROP_UID:
- unix_user->uid = g_value_get_uint (value);
+ unix_user->uid = g_value_get_int (value);
break;
default:
@@ -128,17 +128,17 @@ polkit_unix_user_class_init (PolkitUnixUserClass *klass)
*/
g_object_class_install_property (gobject_class,
PROP_UID,
- g_param_spec_uint ("uid",
- "User ID",
- "The UNIX user ID",
- 0,
- G_MAXUINT,
- 0,
- G_PARAM_CONSTRUCT |
- G_PARAM_READWRITE |
- G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_BLURB |
- G_PARAM_STATIC_NICK));
+ g_param_spec_int ("uid",
+ "User ID",
+ "The UNIX user ID",
+ 0,
+ G_MAXINT,
+ 0,
+ G_PARAM_CONSTRUCT |
+ G_PARAM_READWRITE |
+ G_PARAM_STATIC_NAME |
+ G_PARAM_STATIC_BLURB |
+ G_PARAM_STATIC_NICK));
}
@@ -150,7 +150,7 @@ polkit_unix_user_class_init (PolkitUnixUserClass *klass)
*
* Returns: A UNIX user id.
*/
-uid_t
+gint
polkit_unix_user_get_uid (PolkitUnixUser *user)
{
return user->uid;
@@ -165,7 +165,7 @@ polkit_unix_user_get_uid (PolkitUnixUser *user)
*/
void
polkit_unix_user_set_uid (PolkitUnixUser *user,
- uid_t uid)
+ gint uid)
{
user->uid = uid;
}
@@ -179,7 +179,7 @@ polkit_unix_user_set_uid (PolkitUnixUser *user,
* Returns: A #PolkitUnixUser object. Free with g_object_unref().
*/
PolkitIdentity *
-polkit_unix_user_new (uid_t uid)
+polkit_unix_user_new (gint uid)
{
return POLKIT_IDENTITY (g_object_new (POLKIT_TYPE_UNIX_USER,
"uid", uid,
diff --git a/src/polkit/polkitunixuser.h b/src/polkit/polkitunixuser.h
index 2346c8a..8d4a9e1 100644
--- a/src/polkit/polkitunixuser.h
+++ b/src/polkit/polkitunixuser.h
@@ -47,12 +47,12 @@ typedef struct _PolkitUnixUser PolkitUnixUser;
typedef struct _PolkitUnixUserClass PolkitUnixUserClass;
GType polkit_unix_user_get_type (void) G_GNUC_CONST;
-PolkitIdentity *polkit_unix_user_new (uid_t uid);
+PolkitIdentity *polkit_unix_user_new (gint uid);
PolkitIdentity *polkit_unix_user_new_for_name (const gchar *name,
GError **error);
-uid_t polkit_unix_user_get_uid (PolkitUnixUser *user);
+gint polkit_unix_user_get_uid (PolkitUnixUser *user);
void polkit_unix_user_set_uid (PolkitUnixUser *user,
- uid_t uid);
+ gint uid);
G_END_DECLS
diff --git a/src/polkitbackend/polkitbackendsessionmonitor.c b/src/polkitbackend/polkitbackendsessionmonitor.c
index ecdd6a6..2028250 100644
--- a/src/polkitbackend/polkitbackendsessionmonitor.c
+++ b/src/polkitbackend/polkitbackendsessionmonitor.c
@@ -418,17 +418,14 @@ polkit_backend_session_monitor_get_user_for_subject (PolkitBackendSessionMonitor
if (POLKIT_IS_UNIX_PROCESS (subject))
{
- pid_t pid;
-
- pid = polkit_unix_process_get_pid (POLKIT_UNIX_PROCESS (subject));
+ GError *local_error;
- if (polkit_unix_pid_get_uid (pid, &uid) != 0)
+ local_error = NULL;
+ uid = polkit_unix_process_get_owner (POLKIT_UNIX_PROCESS (subject), &local_error);
+ if (local_error != NULL)
{
- g_set_error (error,
- POLKIT_ERROR,
- POLKIT_ERROR_FAILED,
- "Cannot get user for pid %d",
- pid);
+ g_propagate_error (error, local_error);
+ g_error_free (local_error);
goto out;
}
user = polkit_unix_user_new (uid);
diff --git a/src/programs/pkexec.c b/src/programs/pkexec.c
index 8f9efdf..89b958e 100644
--- a/src/programs/pkexec.c
+++ b/src/programs/pkexec.c
@@ -351,10 +351,22 @@ main (int argc, char *argv[])
pid_of_caller = getpgrp ();
}
+ subject = polkit_unix_process_new (pid_of_caller);
+ if (subject == NULL)
+ {
+ g_printerr ("No such process for pid %d: %s\n", (gint) pid_of_caller, error->message);
+ g_error_free (error);
+ goto out;
+ }
+
/* paranoia: check that the uid of pid_of_caller matches getuid() */
- if (polkit_unix_pid_get_uid (pid_of_caller, &uid_of_caller) != 0)
+ error = NULL;
+ uid_of_caller = polkit_unix_process_get_owner (POLKIT_UNIX_PROCESS (subject),
+ &error);
+ if (error != NULL)
{
- g_printerr ("Error determing pid of caller (pid %d): %s\n", (gint) pid_of_caller, g_strerror (errno));
+ g_printerr ("Error determing pid of caller (pid %d): %s\n", (gint) pid_of_caller, error->message);
+ g_error_free (error);
goto out;
}
if (uid_of_caller != getuid ())
@@ -364,7 +376,6 @@ main (int argc, char *argv[])
}
authority = polkit_authority_get ();
- subject = polkit_unix_process_new (pid_of_caller);
details = polkit_details_new ();
More information about the hal-commit
mailing list