Use %%license, license needs to be in -libs as it's the only guaranteed installed package, Move to mozjs38, Other upstream fixes, Spec cleanups

This commit is contained in:
Peter Robinson 2017-03-30 18:50:11 +01:00
parent fcbd678dee
commit 53c8f9ed7f
6 changed files with 3000 additions and 33 deletions

View File

@ -87,3 +87,88 @@ index bf0ee48..b8096b3 100644
gained_authorization = session->is_authenticated;
g_debug ("Authentication complete, is_authenticated = %d", session->is_authenticated);
}
From 673ef80ed0079d8a4343fb2567b483be17c58969 Mon Sep 17 00:00:00 2001
From: Stef Walter <stefw@redhat.com>
Date: Fri, 11 Mar 2016 10:00:43 +0100
Subject: [PATCH 15/29] polkitagent: Fix access after dereference on hashtable
If an authentication is going on while the agent listener is
going away, then we access memory that has been freed.
g_hash_table_lookup_node: assertion failed: (hash_table->ref_count > 0)'
https://bugs.freedesktop.org/show_bug.cgi?id=94486
---
src/polkitagent/polkitagentlistener.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/src/polkitagent/polkitagentlistener.c b/src/polkitagent/polkitagentlistener.c
index 80d1dc1..491e4b9 100644
--- a/src/polkitagent/polkitagentlistener.c
+++ b/src/polkitagent/polkitagentlistener.c
@@ -569,8 +569,8 @@ polkit_agent_register_listener (PolkitAgentListener *listener,
typedef struct
{
- Server *server;
gchar *cookie;
+ GHashTable *cookie_to_pending_auth;
GDBusMethodInvocation *invocation;
GCancellable *cancellable;
} AuthData;
@@ -581,6 +581,7 @@ auth_data_free (AuthData *data)
g_free (data->cookie);
g_object_unref (data->invocation);
g_object_unref (data->cancellable);
+ g_hash_table_unref (data->cookie_to_pending_auth);
g_free (data);
}
@@ -607,7 +608,7 @@ auth_cb (GObject *source_object,
g_dbus_method_invocation_return_value (data->invocation, NULL);
}
- g_hash_table_remove (data->server->cookie_to_pending_auth, data->cookie);
+ g_hash_table_remove (data->cookie_to_pending_auth, data->cookie);
auth_data_free (data);
}
@@ -668,7 +669,7 @@ auth_agent_handle_begin_authentication (Server *server,
identities = g_list_reverse (identities);
data = g_new0 (AuthData, 1);
- data->server = server;
+ data->cookie_to_pending_auth = g_hash_table_ref (server->cookie_to_pending_auth);
data->cookie = g_strdup (cookie);
data->invocation = g_object_ref (invocation);
data->cancellable = g_cancellable_new ();
--
2.12.1
From f529fa4ac03f491678c7520d7a2d1c05491feab1 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= <mitr@redhat.com>
Date: Sat, 12 Mar 2016 03:40:20 +0100
Subject: [PATCH 16/29] Fix a memory leak of PolkitAgentListener's Server
object
https://bugs.freedesktop.org/show_bug.cgi?id=94506
---
src/polkitagent/polkitagentlistener.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/src/polkitagent/polkitagentlistener.c b/src/polkitagent/polkitagentlistener.c
index 491e4b9..4704b03 100644
--- a/src/polkitagent/polkitagentlistener.c
+++ b/src/polkitagent/polkitagentlistener.c
@@ -129,6 +129,8 @@ server_free (Server *server)
g_object_unref (server->subject);
g_free (server->object_path);
+
+ g_free (server);
}
static gboolean
--
2.12.1

View File

@ -0,0 +1,489 @@
From 3272a988655c3236b55bad70e9a3af20857f384b Mon Sep 17 00:00:00 2001
From: Colin Walters <walters@verbum.org>
Date: Mon, 12 Dec 2016 12:39:43 -0500
Subject: [PATCH 28/29] build: Pull in GCC warning infra from ostree
I'm trying to keep a relatively standard set around, and the code
there is cleaner than what we had before.
Also, injecting as WARN_CFLAGS rather than changing CFLAGS during
autoconf avoids any surprises from new warnings breaking autoconf
checks.
---
buildutil/attributes.m4 | 292 ++++++++++++++++++++++++++++++++++++++++++
configure.ac | 91 +++----------
src/examples/Makefile.am | 1 +
src/polkit/Makefile.am | 1 +
src/polkitagent/Makefile.am | 1 +
src/polkitbackend/Makefile.am | 1 +
src/programs/Makefile.am | 1 +
7 files changed, 318 insertions(+), 70 deletions(-)
create mode 100644 buildutil/attributes.m4
diff --git a/buildutil/attributes.m4 b/buildutil/attributes.m4
new file mode 100644
index 0000000..51ac88b
--- /dev/null
+++ b/buildutil/attributes.m4
@@ -0,0 +1,292 @@
+dnl Macros to check the presence of generic (non-typed) symbols.
+dnl Copyright (c) 2006-2008 Diego Pettenò <flameeyes@gmail.com>
+dnl Copyright (c) 2006-2008 xine project
+dnl Copyright (c) 2012 Lucas De Marchi <lucas.de.marchi@gmail.com>
+dnl
+dnl This program is free software; you can redistribute it and/or modify
+dnl it under the terms of the GNU General Public License as published by
+dnl the Free Software Foundation; either version 2, or (at your option)
+dnl any later version.
+dnl
+dnl This program is distributed in the hope that it will be useful,
+dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
+dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+dnl GNU General Public License for more details.
+dnl
+dnl You should have received a copy of the GNU General Public License
+dnl along with this program; if not, write to the Free Software
+dnl Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+dnl 02110-1301, USA.
+dnl
+dnl As a special exception, the copyright owners of the
+dnl macro gives unlimited permission to copy, distribute and modify the
+dnl configure scripts that are the output of Autoconf when processing the
+dnl Macro. You need not follow the terms of the GNU General Public
+dnl License when using or distributing such scripts, even though portions
+dnl of the text of the Macro appear in them. The GNU General Public
+dnl License (GPL) does govern all other use of the material that
+dnl constitutes the Autoconf Macro.
+dnl
+dnl This special exception to the GPL applies to versions of the
+dnl Autoconf Macro released by this project. When you make and
+dnl distribute a modified version of the Autoconf Macro, you may extend
+dnl this special exception to the GPL to apply to your modified version as
+dnl well.
+
+dnl Check if FLAG in ENV-VAR is supported by compiler and append it
+dnl to WHERE-TO-APPEND variable. Note that we invert -Wno-* checks to
+dnl -W* as gcc cannot test for negated warnings. If a C snippet is passed,
+dnl use it, otherwise use a simple main() definition that just returns 0.
+dnl CC_CHECK_FLAG_APPEND([WHERE-TO-APPEND], [ENV-VAR], [FLAG], [C-SNIPPET])
+
+AC_DEFUN([CC_CHECK_FLAG_APPEND], [
+ AC_CACHE_CHECK([if $CC supports flag $3 in envvar $2],
+ AS_TR_SH([cc_cv_$2_$3]),
+ [eval "AS_TR_SH([cc_save_$2])='${$2}'"
+ eval "AS_TR_SH([$2])='${cc_save_$2} -Werror `echo "$3" | sed 's/^-Wno-/-W/'`'"
+ AC_LINK_IFELSE([AC_LANG_SOURCE(ifelse([$4], [],
+ [int main(void) { return 0; } ],
+ [$4]))],
+ [eval "AS_TR_SH([cc_cv_$2_$3])='yes'"],
+ [eval "AS_TR_SH([cc_cv_$2_$3])='no'"])
+ eval "AS_TR_SH([$2])='$cc_save_$2'"])
+
+ AS_IF([eval test x$]AS_TR_SH([cc_cv_$2_$3])[ = xyes],
+ [eval "$1='${$1} $3'"])
+])
+
+dnl CC_CHECK_FLAGS_APPEND([WHERE-TO-APPEND], [ENV-VAR], [FLAG1 FLAG2], [C-SNIPPET])
+AC_DEFUN([CC_CHECK_FLAGS_APPEND], [
+ for flag in [$3]; do
+ CC_CHECK_FLAG_APPEND([$1], [$2], $flag, [$4])
+ done
+])
+
+dnl Check if the flag is supported by linker (cacheable)
+dnl CC_CHECK_LDFLAGS([FLAG], [ACTION-IF-FOUND],[ACTION-IF-NOT-FOUND])
+
+AC_DEFUN([CC_CHECK_LDFLAGS], [
+ AC_CACHE_CHECK([if $CC supports $1 flag],
+ AS_TR_SH([cc_cv_ldflags_$1]),
+ [ac_save_LDFLAGS="$LDFLAGS"
+ LDFLAGS="$LDFLAGS $1"
+ AC_LINK_IFELSE([int main() { return 1; }],
+ [eval "AS_TR_SH([cc_cv_ldflags_$1])='yes'"],
+ [eval "AS_TR_SH([cc_cv_ldflags_$1])="])
+ LDFLAGS="$ac_save_LDFLAGS"
+ ])
+
+ AS_IF([eval test x$]AS_TR_SH([cc_cv_ldflags_$1])[ = xyes],
+ [$2], [$3])
+])
+
+dnl define the LDFLAGS_NOUNDEFINED variable with the correct value for
+dnl the current linker to avoid undefined references in a shared object.
+AC_DEFUN([CC_NOUNDEFINED], [
+ dnl We check $host for which systems to enable this for.
+ AC_REQUIRE([AC_CANONICAL_HOST])
+
+ case $host in
+ dnl FreeBSD (et al.) does not complete linking for shared objects when pthreads
+ dnl are requested, as different implementations are present; to avoid problems
+ dnl use -Wl,-z,defs only for those platform not behaving this way.
+ *-freebsd* | *-openbsd*) ;;
+ *)
+ dnl First of all check for the --no-undefined variant of GNU ld. This allows
+ dnl for a much more readable command line, so that people can understand what
+ dnl it does without going to look for what the heck -z defs does.
+ for possible_flags in "-Wl,--no-undefined" "-Wl,-z,defs"; do
+ CC_CHECK_LDFLAGS([$possible_flags], [LDFLAGS_NOUNDEFINED="$possible_flags"])
+ break
+ done
+ ;;
+ esac
+
+ AC_SUBST([LDFLAGS_NOUNDEFINED])
+])
+
+dnl Check for a -Werror flag or equivalent. -Werror is the GCC
+dnl and ICC flag that tells the compiler to treat all the warnings
+dnl as fatal. We usually need this option to make sure that some
+dnl constructs (like attributes) are not simply ignored.
+dnl
+dnl Other compilers don't support -Werror per se, but they support
+dnl an equivalent flag:
+dnl - Sun Studio compiler supports -errwarn=%all
+AC_DEFUN([CC_CHECK_WERROR], [
+ AC_CACHE_CHECK(
+ [for $CC way to treat warnings as errors],
+ [cc_cv_werror],
+ [CC_CHECK_CFLAGS_SILENT([-Werror], [cc_cv_werror=-Werror],
+ [CC_CHECK_CFLAGS_SILENT([-errwarn=%all], [cc_cv_werror=-errwarn=%all])])
+ ])
+])
+
+AC_DEFUN([CC_CHECK_ATTRIBUTE], [
+ AC_REQUIRE([CC_CHECK_WERROR])
+ AC_CACHE_CHECK([if $CC supports __attribute__(( ifelse([$2], , [$1], [$2]) ))],
+ AS_TR_SH([cc_cv_attribute_$1]),
+ [ac_save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $cc_cv_werror"
+ AC_COMPILE_IFELSE([AC_LANG_SOURCE([$3])],
+ [eval "AS_TR_SH([cc_cv_attribute_$1])='yes'"],
+ [eval "AS_TR_SH([cc_cv_attribute_$1])='no'"])
+ CFLAGS="$ac_save_CFLAGS"
+ ])
+
+ AS_IF([eval test x$]AS_TR_SH([cc_cv_attribute_$1])[ = xyes],
+ [AC_DEFINE(
+ AS_TR_CPP([SUPPORT_ATTRIBUTE_$1]), 1,
+ [Define this if the compiler supports __attribute__(( ifelse([$2], , [$1], [$2]) ))]
+ )
+ $4],
+ [$5])
+])
+
+AC_DEFUN([CC_ATTRIBUTE_CONSTRUCTOR], [
+ CC_CHECK_ATTRIBUTE(
+ [constructor],,
+ [void __attribute__((constructor)) ctor() { int a; }],
+ [$1], [$2])
+])
+
+AC_DEFUN([CC_ATTRIBUTE_FORMAT], [
+ CC_CHECK_ATTRIBUTE(
+ [format], [format(printf, n, n)],
+ [void __attribute__((format(printf, 1, 2))) printflike(const char *fmt, ...) { fmt = (void *)0; }],
+ [$1], [$2])
+])
+
+AC_DEFUN([CC_ATTRIBUTE_FORMAT_ARG], [
+ CC_CHECK_ATTRIBUTE(
+ [format_arg], [format_arg(printf)],
+ [char *__attribute__((format_arg(1))) gettextlike(const char *fmt) { fmt = (void *)0; }],
+ [$1], [$2])
+])
+
+AC_DEFUN([CC_ATTRIBUTE_VISIBILITY], [
+ CC_CHECK_ATTRIBUTE(
+ [visibility_$1], [visibility("$1")],
+ [void __attribute__((visibility("$1"))) $1_function() { }],
+ [$2], [$3])
+])
+
+AC_DEFUN([CC_ATTRIBUTE_NONNULL], [
+ CC_CHECK_ATTRIBUTE(
+ [nonnull], [nonnull()],
+ [void __attribute__((nonnull())) some_function(void *foo, void *bar) { foo = (void*)0; bar = (void*)0; }],
+ [$1], [$2])
+])
+
+AC_DEFUN([CC_ATTRIBUTE_UNUSED], [
+ CC_CHECK_ATTRIBUTE(
+ [unused], ,
+ [void some_function(void *foo, __attribute__((unused)) void *bar);],
+ [$1], [$2])
+])
+
+AC_DEFUN([CC_ATTRIBUTE_SENTINEL], [
+ CC_CHECK_ATTRIBUTE(
+ [sentinel], ,
+ [void some_function(void *foo, ...) __attribute__((sentinel));],
+ [$1], [$2])
+])
+
+AC_DEFUN([CC_ATTRIBUTE_DEPRECATED], [
+ CC_CHECK_ATTRIBUTE(
+ [deprecated], ,
+ [void some_function(void *foo, ...) __attribute__((deprecated));],
+ [$1], [$2])
+])
+
+AC_DEFUN([CC_ATTRIBUTE_ALIAS], [
+ CC_CHECK_ATTRIBUTE(
+ [alias], [weak, alias],
+ [void other_function(void *foo) { }
+ void some_function(void *foo) __attribute__((weak, alias("other_function")));],
+ [$1], [$2])
+])
+
+AC_DEFUN([CC_ATTRIBUTE_MALLOC], [
+ CC_CHECK_ATTRIBUTE(
+ [malloc], ,
+ [void * __attribute__((malloc)) my_alloc(int n);],
+ [$1], [$2])
+])
+
+AC_DEFUN([CC_ATTRIBUTE_PACKED], [
+ CC_CHECK_ATTRIBUTE(
+ [packed], ,
+ [struct astructure { char a; int b; long c; void *d; } __attribute__((packed));],
+ [$1], [$2])
+])
+
+AC_DEFUN([CC_ATTRIBUTE_CONST], [
+ CC_CHECK_ATTRIBUTE(
+ [const], ,
+ [int __attribute__((const)) twopow(int n) { return 1 << n; } ],
+ [$1], [$2])
+])
+
+AC_DEFUN([CC_FLAG_VISIBILITY], [
+ AC_REQUIRE([CC_CHECK_WERROR])
+ AC_CACHE_CHECK([if $CC supports -fvisibility=hidden],
+ [cc_cv_flag_visibility],
+ [cc_flag_visibility_save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $cc_cv_werror"
+ CC_CHECK_CFLAGS_SILENT([-fvisibility=hidden],
+ cc_cv_flag_visibility='yes',
+ cc_cv_flag_visibility='no')
+ CFLAGS="$cc_flag_visibility_save_CFLAGS"])
+
+ AS_IF([test "x$cc_cv_flag_visibility" = "xyes"],
+ [AC_DEFINE([SUPPORT_FLAG_VISIBILITY], 1,
+ [Define this if the compiler supports the -fvisibility flag])
+ $1],
+ [$2])
+])
+
+AC_DEFUN([CC_FUNC_EXPECT], [
+ AC_REQUIRE([CC_CHECK_WERROR])
+ AC_CACHE_CHECK([if compiler has __builtin_expect function],
+ [cc_cv_func_expect],
+ [ac_save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $cc_cv_werror"
+ AC_COMPILE_IFELSE([AC_LANG_SOURCE(
+ [int some_function() {
+ int a = 3;
+ return (int)__builtin_expect(a, 3);
+ }])],
+ [cc_cv_func_expect=yes],
+ [cc_cv_func_expect=no])
+ CFLAGS="$ac_save_CFLAGS"
+ ])
+
+ AS_IF([test "x$cc_cv_func_expect" = "xyes"],
+ [AC_DEFINE([SUPPORT__BUILTIN_EXPECT], 1,
+ [Define this if the compiler supports __builtin_expect() function])
+ $1],
+ [$2])
+])
+
+AC_DEFUN([CC_ATTRIBUTE_ALIGNED], [
+ AC_REQUIRE([CC_CHECK_WERROR])
+ AC_CACHE_CHECK([highest __attribute__ ((aligned ())) supported],
+ [cc_cv_attribute_aligned],
+ [ac_save_CFLAGS="$CFLAGS"
+ CFLAGS="$CFLAGS $cc_cv_werror"
+ for cc_attribute_align_try in 64 32 16 8 4 2; do
+ AC_COMPILE_IFELSE([AC_LANG_SOURCE([
+ int main() {
+ static char c __attribute__ ((aligned($cc_attribute_align_try))) = 0;
+ return c;
+ }])], [cc_cv_attribute_aligned=$cc_attribute_align_try; break])
+ done
+ CFLAGS="$ac_save_CFLAGS"
+ ])
+
+ if test "x$cc_cv_attribute_aligned" != "x"; then
+ AC_DEFINE_UNQUOTED([ATTRIBUTE_ALIGNED_MAX], [$cc_cv_attribute_aligned],
+ [Define the highest alignment supported])
+ fi
+])
diff --git a/configure.ac b/configure.ac
index f457a84..af2c8dd 100644
--- a/configure.ac
+++ b/configure.ac
@@ -4,6 +4,7 @@ AC_PREREQ(2.59c)
AC_INIT([polkit], [0.114], [http://lists.freedesktop.org/mailman/listinfo/polkit-devel], , [http://www.freedesktop.org/wiki/Software/polkit])
AM_INIT_AUTOMAKE([])
AC_CONFIG_HEADERS(config.h)
+AC_CONFIG_MACRO_DIR([buildutil])
AM_MAINTAINER_MODE
m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
@@ -52,76 +53,26 @@ GTK_DOC_CHECK([1.3])
#### gcc warning flags
-if test "x$GCC" = "xyes"; then
- changequote(,)dnl
- case " $CFLAGS " in
- *[\ \ ]-Wall[\ \ ]*) ;;
- *) CFLAGS="$CFLAGS -Wall" ;;
- esac
-
- case " $CFLAGS " in
- *[\ \ ]-Wchar-subscripts[\ \ ]*) ;;
- *) CFLAGS="$CFLAGS -Wchar-subscripts" ;;
- esac
-
- case " $CFLAGS " in
- *[\ \ ]-Wmissing-declarations[\ \ ]*) ;;
- *) CFLAGS="$CFLAGS -Wmissing-declarations" ;;
- esac
-
- case " $CFLAGS " in
- *[\ \ ]-Wnested-externs[\ \ ]*) ;;
- *) CFLAGS="$CFLAGS -Wnested-externs" ;;
- esac
-
- case " $CFLAGS " in
- *[\ \ ]-Wpointer-arith[\ \ ]*) ;;
- *) CFLAGS="$CFLAGS -Wpointer-arith" ;;
- esac
-
- case " $CFLAGS " in
- *[\ \ ]-Wcast-align[\ \ ]*) ;;
- *) CFLAGS="$CFLAGS -Wcast-align" ;;
- esac
-
- case " $CFLAGS " in
- *[\ \ ]-Wsign-compare[\ \ ]*) ;;
- *) CFLAGS="$CFLAGS -Wsign-compare" ;;
- esac
-
- case " $CFLAGS " in
- *[\ \ ]-Wformat[\ \ ]*) ;;
- *) CFLAGS="$CFLAGS -Wformat" ;;
- esac
-
- case " $CFLAGS " in
- *[\ \ ]-Wformat-security[\ \ ]*) ;;
- *) CFLAGS="$CFLAGS -Wformat-security" ;;
- esac
-
- if test "x$enable_ansi" = "xyes"; then
- case " $CFLAGS " in
- *[\ \ ]-ansi[\ \ ]*) ;;
- *) CFLAGS="$CFLAGS -ansi" ;;
- esac
-
- case " $CFLAGS " in
- *[\ \ ]-D_POSIX_C_SOURCE*) ;;
- *) CFLAGS="$CFLAGS -D_POSIX_C_SOURCE=199309L" ;;
- esac
-
- case " $CFLAGS " in
- *[\ \ ]-D_BSD_SOURCE[\ \ ]*) ;;
- *) CFLAGS="$CFLAGS -D_BSD_SOURCE" ;;
- esac
-
- case " $CFLAGS " in
- *[\ \ ]-pedantic[\ \ ]*) ;;
- *) CFLAGS="$CFLAGS -pedantic" ;;
- esac
- fi
- changequote([,])dnl
-fi
+CC_CHECK_FLAGS_APPEND([WARN_CFLAGS], [CFLAGS], [\
+ -pipe \
+ -Wall \
+ -Werror=empty-body \
+ -Werror=strict-prototypes \
+ -Werror=missing-prototypes \
+ -Werror=implicit-function-declaration \
+ "-Werror=format=2 -Werror=format-security -Werror=format-nonliteral" \
+ -Werror=pointer-arith -Werror=init-self \
+ -Werror=missing-declarations \
+ -Werror=return-type \
+ -Werror=overflow \
+ -Werror=int-conversion \
+ -Werror=parenthesis \
+ -Werror=incompatible-pointer-types \
+ -Werror=misleading-indentation \
+ -Werror=missing-include-dirs -Werror=aggregate-return \
+ -Werror=declaration-after-statement \
+])
+AC_SUBST(WARN_CFLAGS)
PKG_CHECK_MODULES(GLIB, [gmodule-2.0 gio-unix-2.0 >= 2.30.0])
AC_SUBST(GLIB_CFLAGS)
diff --git a/src/examples/Makefile.am b/src/examples/Makefile.am
index 71c4991..9b885f3 100644
--- a/src/examples/Makefile.am
+++ b/src/examples/Makefile.am
@@ -1,5 +1,6 @@
NULL =
+AM_CFLAGS = -std=gnu99 $(WARN_CFLAGS)
AM_CPPFLAGS = \
-I$(top_builddir)/src \
diff --git a/src/polkit/Makefile.am b/src/polkit/Makefile.am
index 51befaf..ca36355 100644
--- a/src/polkit/Makefile.am
+++ b/src/polkit/Makefile.am
@@ -1,5 +1,6 @@
NULL =
+AM_CFLAGS = -std=gnu99 $(WARN_CFLAGS)
AM_CPPFLAGS = \
-I$(top_builddir)/src \
-I$(top_srcdir)/src \
diff --git a/src/polkitagent/Makefile.am b/src/polkitagent/Makefile.am
index 4b64165..49720db 100644
--- a/src/polkitagent/Makefile.am
+++ b/src/polkitagent/Makefile.am
@@ -1,5 +1,6 @@
NULL =
+AM_CFLAGS = -std=gnu99 $(WARN_CFLAGS)
AM_CPPFLAGS = \
-I$(top_builddir)/src \
-I$(top_srcdir)/src \
diff --git a/src/polkitbackend/Makefile.am b/src/polkitbackend/Makefile.am
index ca62474..e48b739 100644
--- a/src/polkitbackend/Makefile.am
+++ b/src/polkitbackend/Makefile.am
@@ -2,6 +2,7 @@ NULL =
BUILT_SOURCES =
+AM_CFLAGS = -std=gnu99 $(WARN_CFLAGS)
AM_CPPFLAGS = \
-I$(top_builddir)/src \
-I$(top_srcdir)/src \
diff --git a/src/programs/Makefile.am b/src/programs/Makefile.am
index 880b90b..d69853c 100644
--- a/src/programs/Makefile.am
+++ b/src/programs/Makefile.am
@@ -1,6 +1,7 @@
NULL =
+AM_CFLAGS = -std=gnu99 $(WARN_CFLAGS)
AM_CPPFLAGS = \
-I$(top_builddir)/src \
-I$(top_srcdir)/src \
--
2.12.1

704
polkit-mozjs24.patch Normal file
View File

@ -0,0 +1,704 @@
From 0676f33aa741a87634ffc3b9ef82c7d092c997ec Mon Sep 17 00:00:00 2001
From: Jeremy Linton <jeremy.linton@arm.com>
Date: Fri, 26 Aug 2016 14:01:46 -0500
Subject: [PATCH 24/29] change mozjs interface module to c++
The JSAPI is now a full C++ interface. Convert the polkit
to JavaScript interface module to C++ compilation in order to
support newer versions of spidermonkey.
Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
---
configure.ac | 3 +++
src/polkitbackend/Makefile.am | 7 ++++++-
.../{polkitbackendjsauthority.c => polkitbackendjsauthority.cpp} | 0
test/polkitbackend/Makefile.am | 3 +++
4 files changed, 12 insertions(+), 1 deletion(-)
rename src/polkitbackend/{polkitbackendjsauthority.c => polkitbackendjsauthority.cpp} (100%)
diff --git a/configure.ac b/configure.ac
index 97d4222..18c1f4e 100644
--- a/configure.ac
+++ b/configure.ac
@@ -30,6 +30,8 @@ AC_PROG_MAKE_SET
AC_PROG_LN_S
AC_SYS_LARGEFILE
AM_PROG_CC_C_O
+AC_PROG_CXX
+AX_CXX_COMPILE_STDCXX_11()
# Taken from dbus
AC_ARG_ENABLE(ansi, [ --enable-ansi enable -ansi -pedantic gcc flags],enable_ansi=$enableval,enable_ansi=no)
@@ -142,6 +144,7 @@ AS_IF([test x${with_mozjs} != xauto], [
])
])
AC_SUBST(LIBJS_CFLAGS)
+AC_SUBST(LIBJS_CXXFLAGS)
AC_SUBST(LIBJS_LIBS)
EXPAT_LIB=""
diff --git a/src/polkitbackend/Makefile.am b/src/polkitbackend/Makefile.am
index a80ca36..5655d17 100644
--- a/src/polkitbackend/Makefile.am
+++ b/src/polkitbackend/Makefile.am
@@ -32,7 +32,7 @@ libpolkit_backend_1_la_SOURCES = \
polkitbackendprivate.h \
polkitbackendauthority.h polkitbackendauthority.c \
polkitbackendinteractiveauthority.h polkitbackendinteractiveauthority.c \
- polkitbackendjsauthority.h polkitbackendjsauthority.c \
+ polkitbackendjsauthority.h polkitbackendjsauthority.cpp \
polkitbackendactionpool.h polkitbackendactionpool.c \
polkitbackendactionlookup.h polkitbackendactionlookup.c \
$(NULL)
@@ -53,6 +53,8 @@ libpolkit_backend_1_la_CFLAGS = \
$(LIBJS_CFLAGS) \
$(NULL)
+libpolkit_backend_1_la_CXXFLAGS = $(libpolkit_backend_1_la_CFLAGS) -fpermissive
+
libpolkit_backend_1_la_LIBADD = \
$(GLIB_LIBS) \
$(LIBSYSTEMD_LIBS) \
@@ -73,6 +75,9 @@ polkitd_SOURCES = \
polkitd.c \
$(NULL)
+# force C++ link via dummy C++ file, (see GNU automake manual section 8.3.5)
+nodist_EXTRA_polkitd_SOURCES = dummy-force-cpp-link.cxx
+
polkitd_CFLAGS = \
-DPOLKIT_BACKEND_I_KNOW_API_IS_SUBJECT_TO_CHANGE \
-DG_LOG_DOMAIN=\"polkitd-1\" \
diff --git a/src/polkitbackend/polkitbackendjsauthority.c b/src/polkitbackend/polkitbackendjsauthority.cpp
similarity index 100%
rename from src/polkitbackend/polkitbackendjsauthority.c
rename to src/polkitbackend/polkitbackendjsauthority.cpp
diff --git a/test/polkitbackend/Makefile.am b/test/polkitbackend/Makefile.am
index 8859c1f..53bfb2a 100644
--- a/test/polkitbackend/Makefile.am
+++ b/test/polkitbackend/Makefile.am
@@ -35,6 +35,9 @@ TEST_PROGS =
TEST_PROGS += polkitbackendjsauthoritytest
polkitbackendjsauthoritytest_SOURCES = test-polkitbackendjsauthority.c
+# force C++ link via dummy C++ file, (see GNU automake manual section 8.3.5)
+nodist_EXTRA_polkitbackendjsauthoritytest_SOURCES = dummy-force-cpp-link.cxx
+
# ----------------------------------------------------------------------------------------------------
--
2.12.1
From 03dafd1fac8154c0a581395f1b7bf29e56a83491 Mon Sep 17 00:00:00 2001
From: Jeremy Linton <jeremy.linton@arm.com>
Date: Fri, 26 Aug 2016 14:01:47 -0500
Subject: [PATCH 25/29] Switch to hard requiring mozjs24
Remove mozjs185 and mozjs17 from autoconf and replace them
with mozjs24.
Now that polkitbackendjsauthority is compiling in C++ mode
and the autoconf supports mozjs24, update the module so
that it builds with mozjs24.
Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
---
configure.ac | 14 +----
src/polkitbackend/polkitbackendjsauthority.cpp | 74 ++++++++------------------
2 files changed, 25 insertions(+), 63 deletions(-)
diff --git a/configure.ac b/configure.ac
index 18c1f4e..f457a84 100644
--- a/configure.ac
+++ b/configure.ac
@@ -131,18 +131,8 @@ AC_DEFINE([GLIB_VERSION_MIN_REQUIRED], [GLIB_VERSION_2_30],
AC_DEFINE([GLIB_VERSION_MAX_ALLOWED], [G_ENCODE_VERSION(2,34)],
[Notify us when we'll need to transition away from g_type_init()])
-AC_ARG_WITH(mozjs, AS_HELP_STRING([--with-mozjs=@<:@mozjs185/mozjs-17.0|auto@:>@],
- [Specify version of Spidermonkey to use]),,
- with_mozjs=auto)
-AS_IF([test x${with_mozjs} != xauto], [
- PKG_CHECK_MODULES(LIBJS, ${with_mozjs})
-], [
- PKG_CHECK_MODULES(LIBJS, [mozjs185], have_mozjs185=yes, have_mozjs185=no)
- AS_IF([test x${have_mozjs185} = xno], [
- PKG_CHECK_MODULES(LIBJS, [mozjs-17.0], have_mozjs17=yes,
- [AC_MSG_ERROR([Could not find mozjs185 or mozjs-17.0; see http://ftp.mozilla.org/pub/mozilla.org/js/])])
- ])
-])
+PKG_CHECK_MODULES(LIBJS, [mozjs-24])
+
AC_SUBST(LIBJS_CFLAGS)
AC_SUBST(LIBJS_CXXFLAGS)
AC_SUBST(LIBJS_LIBS)
diff --git a/src/polkitbackend/polkitbackendjsauthority.cpp b/src/polkitbackend/polkitbackendjsauthority.cpp
index 2112868..1541856 100644
--- a/src/polkitbackend/polkitbackendjsauthority.cpp
+++ b/src/polkitbackend/polkitbackendjsauthority.cpp
@@ -92,11 +92,7 @@ struct _PolkitBackendJsAuthorityPrivate
};
static JSBool execute_script_with_runaway_killer (PolkitBackendJsAuthority *authority,
-#if JS_VERSION == 186
JSScript *script,
-#else
- JSObject *script,
-#endif
jsval *rval);
static void utils_spawn (const gchar *const *argv,
@@ -157,17 +153,13 @@ static JSClass js_global_class = {
"global",
JSCLASS_GLOBAL_FLAGS,
JS_PropertyStub,
- JS_PropertyStub,
+ JS_DeletePropertyStub,
JS_PropertyStub,
JS_StrictPropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
-#if JS_VERSION == 186
NULL,
-#else
- JS_FinalizeStub,
-#endif
JSCLASS_NO_OPTIONAL_MEMBERS
};
@@ -177,17 +169,13 @@ static JSClass js_polkit_class = {
"Polkit",
0,
JS_PropertyStub,
- JS_PropertyStub,
+ JS_DeletePropertyStub,
JS_PropertyStub,
JS_StrictPropertyStub,
JS_EnumerateStub,
JS_ResolveStub,
JS_ConvertStub,
-#if JS_VERSION == 186
NULL,
-#else
- JS_FinalizeStub,
-#endif
JSCLASS_NO_OPTIONAL_MEMBERS
};
@@ -300,22 +288,14 @@ load_scripts (PolkitBackendJsAuthority *authority)
for (l = files; l != NULL; l = l->next)
{
const gchar *filename = l->data;
-#if JS_VERSION == 186
- JSScript *script;
-#else
- JSObject *script;
-#endif
+ JS::RootedScript script(authority->priv->cx);
+ JS::CompileOptions options(authority->priv->cx);
+ JS::RootedObject obj(authority->priv->cx,authority->priv->js_global);
+ options.setUTF8(true);
+ script = JS::Compile (authority->priv->cx,
+ obj, options,
+ filename);
-#if JS_VERSION == 186
- script = JS_CompileUTF8File (authority->priv->cx,
- authority->priv->js_global,
- filename);
-
-#else
- script = JS_CompileFile (authority->priv->cx,
- authority->priv->js_global,
- filename);
-#endif
if (script == NULL)
{
polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority),
@@ -355,6 +335,8 @@ reload_scripts (PolkitBackendJsAuthority *authority)
JS_BeginRequest (authority->priv->cx);
+ JSAutoCompartment ac(authority->priv->cx, authority->priv->js_global);
+
if (!JS_CallFunctionName(authority->priv->cx,
authority->priv->js_polkit,
"_deleteRules",
@@ -369,11 +351,7 @@ reload_scripts (PolkitBackendJsAuthority *authority)
polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority),
"Collecting garbage unconditionally...");
-#if JS_VERSION == 186
JS_GC (authority->priv->rt);
-#else
- JS_GC (authority->priv->cx);
-#endif
load_scripts (authority);
@@ -465,7 +443,7 @@ polkit_backend_js_authority_constructed (GObject *object)
PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (object);
gboolean entered_request = FALSE;
- authority->priv->rt = JS_NewRuntime (8L * 1024L * 1024L);
+ authority->priv->rt = JS_NewRuntime (8L * 1024L * 1024L, JS_USE_HELPER_THREADS);
if (authority->priv->rt == NULL)
goto fail;
@@ -479,19 +457,17 @@ polkit_backend_js_authority_constructed (GObject *object)
JS_SetOptions (authority->priv->cx,
JSOPTION_VAROBJFIX
/* | JSOPTION_JIT | JSOPTION_METHODJIT*/);
- JS_SetVersion(authority->priv->cx, JSVERSION_LATEST);
JS_SetErrorReporter(authority->priv->cx, report_error);
JS_SetContextPrivate (authority->priv->cx, authority);
JS_BeginRequest(authority->priv->cx);
entered_request = TRUE;
- authority->priv->js_global =
-#if JS_VERSION == 186
- JS_NewGlobalObject (authority->priv->cx, &js_global_class, NULL);
-#else
- JS_NewCompartmentAndGlobalObject (authority->priv->cx, &js_global_class, NULL);
-#endif
+ {
+ JS::CompartmentOptions compart_opts;
+ compart_opts.setVersion(JSVERSION_LATEST);
+ authority->priv->js_global = JS_NewGlobalObject (authority->priv->cx, &js_global_class, NULL, compart_opts);
+ JSAutoCompartment ac(authority->priv->cx, authority->priv->js_global);
if (authority->priv->js_global == NULL)
goto fail;
@@ -548,11 +524,12 @@ polkit_backend_js_authority_constructed (GObject *object)
setup_file_monitors (authority);
load_scripts (authority);
-
+ }
JS_EndRequest (authority->priv->cx);
entered_request = FALSE;
G_OBJECT_CLASS (polkit_backend_js_authority_parent_class)->constructed (object);
+
return;
fail:
@@ -766,7 +743,6 @@ subject_to_jsval (PolkitBackendJsAuthority *authority,
char *session_str = NULL;
src = "new Subject();";
-
if (!JS_EvaluateScript (authority->priv->cx,
authority->priv->js_global,
src, strlen (src),
@@ -999,11 +975,7 @@ rkt_on_timeout (gpointer user_data)
g_mutex_unlock (&authority->priv->rkt_timeout_pending_mutex);
/* Supposedly this is thread-safe... */
-#if JS_VERSION == 186
JS_TriggerOperationCallback (authority->priv->rt);
-#else
- JS_TriggerOperationCallback (authority->priv->cx);
-#endif
/* keep source around so we keep trying to kill even if the JS bit catches the exception
* thrown in js_operation_callback()
@@ -1041,11 +1013,7 @@ runaway_killer_teardown (PolkitBackendJsAuthority *authority)
static JSBool
execute_script_with_runaway_killer (PolkitBackendJsAuthority *authority,
-#if JS_VERSION == 186
JSScript *script,
-#else
- JSObject *script,
-#endif
jsval *rval)
{
JSBool ret;
@@ -1103,6 +1071,8 @@ polkit_backend_js_authority_get_admin_auth_identities (PolkitBackendInteractiveA
JS_BeginRequest (authority->priv->cx);
+ JSAutoCompartment ac(authority->priv->cx, authority->priv->js_global);
+
if (!action_and_details_to_jsval (authority, action_id, details, &argv[0], &error))
{
polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority),
@@ -1212,6 +1182,8 @@ polkit_backend_js_authority_check_authorization_sync (PolkitBackendInteractiveAu
JS_BeginRequest (authority->priv->cx);
+ JSAutoCompartment ac(authority->priv->cx, authority->priv->js_global);
+
if (!action_and_details_to_jsval (authority, action_id, details, &argv[0], &error))
{
polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority),
--
2.12.1
From e845ef53aec8ec502c8edac957929e2d337b2302 Mon Sep 17 00:00:00 2001
From: Jeremy Linton <jeremy.linton@arm.com>
Date: Fri, 26 Aug 2016 14:01:48 -0500
Subject: [PATCH 26/29] Fix warnings caused by building with C++
C++ needs explicit casts for many pointer type conversions
For example char * to void * should have a cast. Fix a
number of these cases. Also, correct a white space indentation
error left in the last patch for review clarity.
Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
---
src/polkitbackend/Makefile.am | 2 +-
src/polkitbackend/polkitbackendjsauthority.cpp | 138 ++++++++++++-------------
2 files changed, 70 insertions(+), 70 deletions(-)
diff --git a/src/polkitbackend/Makefile.am b/src/polkitbackend/Makefile.am
index 5655d17..ca62474 100644
--- a/src/polkitbackend/Makefile.am
+++ b/src/polkitbackend/Makefile.am
@@ -53,7 +53,7 @@ libpolkit_backend_1_la_CFLAGS = \
$(LIBJS_CFLAGS) \
$(NULL)
-libpolkit_backend_1_la_CXXFLAGS = $(libpolkit_backend_1_la_CFLAGS) -fpermissive
+libpolkit_backend_1_la_CXXFLAGS = $(libpolkit_backend_1_la_CFLAGS)
libpolkit_backend_1_la_LIBADD = \
$(GLIB_LIBS) \
diff --git a/src/polkitbackend/polkitbackendjsauthority.cpp b/src/polkitbackend/polkitbackendjsauthority.cpp
index 1541856..ce3a980 100644
--- a/src/polkitbackend/polkitbackendjsauthority.cpp
+++ b/src/polkitbackend/polkitbackendjsauthority.cpp
@@ -287,7 +287,7 @@ load_scripts (PolkitBackendJsAuthority *authority)
for (l = files; l != NULL; l = l->next)
{
- const gchar *filename = l->data;
+ const gchar *filename = (gchar *)l->data;
JS::RootedScript script(authority->priv->cx);
JS::CompileOptions options(authority->priv->cx);
JS::RootedObject obj(authority->priv->cx,authority->priv->js_global);
@@ -464,66 +464,66 @@ polkit_backend_js_authority_constructed (GObject *object)
entered_request = TRUE;
{
- JS::CompartmentOptions compart_opts;
- compart_opts.setVersion(JSVERSION_LATEST);
- authority->priv->js_global = JS_NewGlobalObject (authority->priv->cx, &js_global_class, NULL, compart_opts);
- JSAutoCompartment ac(authority->priv->cx, authority->priv->js_global);
-
- if (authority->priv->js_global == NULL)
- goto fail;
- JS_AddObjectRoot (authority->priv->cx, &authority->priv->js_global);
-
- if (!JS_InitStandardClasses (authority->priv->cx, authority->priv->js_global))
- goto fail;
-
- authority->priv->js_polkit = JS_DefineObject (authority->priv->cx,
- authority->priv->js_global,
- "polkit",
- &js_polkit_class,
- NULL,
- JSPROP_ENUMERATE);
- if (authority->priv->js_polkit == NULL)
- goto fail;
- JS_AddObjectRoot (authority->priv->cx, &authority->priv->js_polkit);
-
- if (!JS_DefineFunctions (authority->priv->cx,
- authority->priv->js_polkit,
- js_polkit_functions))
- goto fail;
+ JS::CompartmentOptions compart_opts;
+ compart_opts.setVersion(JSVERSION_LATEST);
+ authority->priv->js_global = JS_NewGlobalObject (authority->priv->cx, &js_global_class, NULL, compart_opts);
+ JSAutoCompartment ac(authority->priv->cx, authority->priv->js_global);
- if (!JS_EvaluateScript (authority->priv->cx,
- authority->priv->js_global,
- init_js, strlen (init_js), /* init.js */
- "init.js", /* filename */
- 0, /* lineno */
- NULL)) /* rval */
- {
+ if (authority->priv->js_global == NULL)
goto fail;
- }
-
- if (authority->priv->rules_dirs == NULL)
- {
- authority->priv->rules_dirs = g_new0 (gchar *, 3);
- authority->priv->rules_dirs[0] = g_strdup (PACKAGE_SYSCONF_DIR "/polkit-1/rules.d");
- authority->priv->rules_dirs[1] = g_strdup (PACKAGE_DATA_DIR "/polkit-1/rules.d");
- }
+ JS_AddObjectRoot (authority->priv->cx, &authority->priv->js_global);
- g_mutex_init (&authority->priv->rkt_init_mutex);
- g_cond_init (&authority->priv->rkt_init_cond);
- g_mutex_init (&authority->priv->rkt_timeout_pending_mutex);
+ if (!JS_InitStandardClasses (authority->priv->cx, authority->priv->js_global))
+ goto fail;
- authority->priv->runaway_killer_thread = g_thread_new ("runaway-killer-thread",
- runaway_killer_thread_func,
- authority);
+ authority->priv->js_polkit = JS_DefineObject (authority->priv->cx,
+ authority->priv->js_global,
+ "polkit",
+ &js_polkit_class,
+ NULL,
+ JSPROP_ENUMERATE);
+ if (authority->priv->js_polkit == NULL)
+ goto fail;
+ JS_AddObjectRoot (authority->priv->cx, &authority->priv->js_polkit);
- /* wait for runaway_killer_thread to set up its GMainContext */
- g_mutex_lock (&authority->priv->rkt_init_mutex);
- while (authority->priv->rkt_context == NULL)
- g_cond_wait (&authority->priv->rkt_init_cond, &authority->priv->rkt_init_mutex);
- g_mutex_unlock (&authority->priv->rkt_init_mutex);
+ if (!JS_DefineFunctions (authority->priv->cx,
+ authority->priv->js_polkit,
+ js_polkit_functions))
+ goto fail;
- setup_file_monitors (authority);
- load_scripts (authority);
+ if (!JS_EvaluateScript (authority->priv->cx,
+ authority->priv->js_global,
+ init_js, strlen (init_js), /* init.js */
+ "init.js", /* filename */
+ 0, /* lineno */
+ NULL)) /* rval */
+ {
+ goto fail;
+ }
+
+ if (authority->priv->rules_dirs == NULL)
+ {
+ authority->priv->rules_dirs = g_new0 (gchar *, 3);
+ authority->priv->rules_dirs[0] = g_strdup (PACKAGE_SYSCONF_DIR "/polkit-1/rules.d");
+ authority->priv->rules_dirs[1] = g_strdup (PACKAGE_DATA_DIR "/polkit-1/rules.d");
+ }
+
+ g_mutex_init (&authority->priv->rkt_init_mutex);
+ g_cond_init (&authority->priv->rkt_init_cond);
+ g_mutex_init (&authority->priv->rkt_timeout_pending_mutex);
+
+ authority->priv->runaway_killer_thread = g_thread_new ("runaway-killer-thread",
+ runaway_killer_thread_func,
+ authority);
+
+ /* wait for runaway_killer_thread to set up its GMainContext */
+ g_mutex_lock (&authority->priv->rkt_init_mutex);
+ while (authority->priv->rkt_context == NULL)
+ g_cond_wait (&authority->priv->rkt_init_cond, &authority->priv->rkt_init_mutex);
+ g_mutex_unlock (&authority->priv->rkt_init_mutex);
+
+ setup_file_monitors (authority);
+ load_scripts (authority);
}
JS_EndRequest (authority->priv->cx);
entered_request = FALSE;
@@ -559,7 +559,7 @@ polkit_backend_js_authority_finalize (GObject *object)
{
GFileMonitor *monitor = authority->priv->dir_monitors[n];
g_signal_handlers_disconnect_by_func (monitor,
- G_CALLBACK (on_dir_monitor_changed),
+ (gpointer*)G_CALLBACK (on_dir_monitor_changed),
authority);
g_object_unref (monitor);
}
@@ -645,7 +645,7 @@ polkit_backend_js_authority_class_init (PolkitBackendJsAuthorityClass *klass)
NULL,
NULL,
G_TYPE_STRV,
- G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE));
+ GParamFlags(G_PARAM_CONSTRUCT_ONLY | G_PARAM_WRITABLE)));
g_type_class_add_private (klass, sizeof (PolkitBackendJsAuthorityPrivate));
@@ -685,7 +685,7 @@ set_property_strv (PolkitBackendJsAuthority *authority,
JSString *jsstr;
jsval val;
- jsstr = JS_NewStringCopyZ (authority->priv->cx, g_ptr_array_index(value, n));
+ jsstr = JS_NewStringCopyZ (authority->priv->cx, (char *)g_ptr_array_index(value, n));
val = STRING_TO_JSVAL (jsstr);
JS_SetElement (authority->priv->cx, array_object, n, &val);
}
@@ -1347,8 +1347,8 @@ spawn_cb (GObject *source_object,
GAsyncResult *res,
gpointer user_data)
{
- SpawnData *data = user_data;
- data->res = g_object_ref (res);
+ SpawnData *data = (SpawnData *)user_data;
+ data->res = (GAsyncResult*)g_object_ref (res);
g_main_loop_quit (data->loop);
}
@@ -1657,7 +1657,7 @@ static void
utils_on_cancelled (GCancellable *cancellable,
gpointer user_data)
{
- UtilsSpawnData *data = user_data;
+ UtilsSpawnData *data = (UtilsSpawnData *)user_data;
GError *error;
error = NULL;
@@ -1672,7 +1672,7 @@ utils_read_child_stderr (GIOChannel *channel,
GIOCondition condition,
gpointer user_data)
{
- UtilsSpawnData *data = user_data;
+ UtilsSpawnData *data = (UtilsSpawnData *)user_data;
gchar buf[1024];
gsize bytes_read;
@@ -1686,7 +1686,7 @@ utils_read_child_stdout (GIOChannel *channel,
GIOCondition condition,
gpointer user_data)
{
- UtilsSpawnData *data = user_data;
+ UtilsSpawnData *data = (UtilsSpawnData *)user_data;
gchar buf[1024];
gsize bytes_read;
@@ -1700,7 +1700,7 @@ utils_child_watch_cb (GPid pid,
gint status,
gpointer user_data)
{
- UtilsSpawnData *data = user_data;
+ UtilsSpawnData *data = (UtilsSpawnData *)user_data;
gchar *buf;
gsize buf_size;
@@ -1729,7 +1729,7 @@ utils_child_watch_cb (GPid pid,
static gboolean
utils_timeout_cb (gpointer user_data)
{
- UtilsSpawnData *data = user_data;
+ UtilsSpawnData *data = (UtilsSpawnData *)user_data;
data->timed_out = TRUE;
@@ -1758,12 +1758,12 @@ utils_spawn (const gchar *const *argv,
data->simple = g_simple_async_result_new (NULL,
callback,
user_data,
- utils_spawn);
+ (gpointer*)utils_spawn);
data->main_context = g_main_context_get_thread_default ();
if (data->main_context != NULL)
g_main_context_ref (data->main_context);
- data->cancellable = cancellable != NULL ? g_object_ref (cancellable) : NULL;
+ data->cancellable = cancellable != NULL ? (GCancellable*)g_object_ref (cancellable) : NULL;
data->child_stdout = g_string_new (NULL);
data->child_stderr = g_string_new (NULL);
@@ -1796,7 +1796,7 @@ utils_spawn (const gchar *const *argv,
if (!g_spawn_async_with_pipes (NULL, /* working directory */
(gchar **) argv,
NULL, /* envp */
- G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD,
+ GSpawnFlags(G_SPAWN_SEARCH_PATH | G_SPAWN_DO_NOT_REAP_CHILD),
NULL, /* child_setup */
NULL, /* child_setup's user_data */
&(data->child_pid),
@@ -1863,7 +1863,7 @@ utils_spawn_finish (GAsyncResult *res,
if (g_simple_async_result_propagate_error (simple, error))
goto out;
- data = g_simple_async_result_get_op_res_gpointer (simple);
+ data = (UtilsSpawnData*)g_simple_async_result_get_op_res_gpointer (simple);
if (data->timed_out)
{
--
2.12.1
From 2d4d117eeadde9b56ac49e82a2d701a6f6e387b5 Mon Sep 17 00:00:00 2001
From: Jeremy Linton <jeremy.linton@arm.com>
Date: Fri, 26 Aug 2016 14:01:49 -0500
Subject: [PATCH 27/29] Replace autocompartment
The autocompartment definition in the previous patches seems to be fine, but
constructing the autocompartment for the lifetime of the global object is probably
a better way to handle this.
Signed-off-by: Jeremy Linton <jeremy.linton@arm.com>
---
src/polkitbackend/polkitbackendjsauthority.cpp | 15 ++++++++-------
1 file changed, 8 insertions(+), 7 deletions(-)
diff --git a/src/polkitbackend/polkitbackendjsauthority.cpp b/src/polkitbackend/polkitbackendjsauthority.cpp
index ce3a980..6a0b4ab 100644
--- a/src/polkitbackend/polkitbackendjsauthority.cpp
+++ b/src/polkitbackend/polkitbackendjsauthority.cpp
@@ -76,6 +76,7 @@ struct _PolkitBackendJsAuthorityPrivate
JSRuntime *rt;
JSContext *cx;
JSObject *js_global;
+ JSAutoCompartment *ac;
JSObject *js_polkit;
GThread *runaway_killer_thread;
@@ -335,8 +336,6 @@ reload_scripts (PolkitBackendJsAuthority *authority)
JS_BeginRequest (authority->priv->cx);
- JSAutoCompartment ac(authority->priv->cx, authority->priv->js_global);
-
if (!JS_CallFunctionName(authority->priv->cx,
authority->priv->js_polkit,
"_deleteRules",
@@ -467,10 +466,15 @@ polkit_backend_js_authority_constructed (GObject *object)
JS::CompartmentOptions compart_opts;
compart_opts.setVersion(JSVERSION_LATEST);
authority->priv->js_global = JS_NewGlobalObject (authority->priv->cx, &js_global_class, NULL, compart_opts);
- JSAutoCompartment ac(authority->priv->cx, authority->priv->js_global);
if (authority->priv->js_global == NULL)
goto fail;
+
+ authority->priv->ac = new JSAutoCompartment(authority->priv->cx, authority->priv->js_global);
+
+ if (authority->priv->ac == NULL)
+ goto fail;
+
JS_AddObjectRoot (authority->priv->cx, &authority->priv->js_global);
if (!JS_InitStandardClasses (authority->priv->cx, authority->priv->js_global))
@@ -568,6 +572,7 @@ polkit_backend_js_authority_finalize (GObject *object)
JS_BeginRequest (authority->priv->cx);
JS_RemoveObjectRoot (authority->priv->cx, &authority->priv->js_polkit);
+ delete authority->priv->ac;
JS_RemoveObjectRoot (authority->priv->cx, &authority->priv->js_global);
JS_EndRequest (authority->priv->cx);
@@ -1071,8 +1076,6 @@ polkit_backend_js_authority_get_admin_auth_identities (PolkitBackendInteractiveA
JS_BeginRequest (authority->priv->cx);
- JSAutoCompartment ac(authority->priv->cx, authority->priv->js_global);
-
if (!action_and_details_to_jsval (authority, action_id, details, &argv[0], &error))
{
polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority),
@@ -1182,8 +1185,6 @@ polkit_backend_js_authority_check_authorization_sync (PolkitBackendInteractiveAu
JS_BeginRequest (authority->priv->cx);
- JSAutoCompartment ac(authority->priv->cx, authority->priv->js_global);
-
if (!action_and_details_to_jsval (authority, action_id, details, &argv[0], &error))
{
polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority),
--
2.12.1

971
polkit-mozjs38.patch Normal file
View File

@ -0,0 +1,971 @@
Update polkit to use a more recent version of the mozjs library.
This is falls into a few general categorizes. Further C macros
have been replaced with C++ methods. Types which are native (bool)
are now used, rather than mozjs specific ones (JS_Bool). Further
most of the API's now require rooted handles, rather than js value
types so, we temporarily root many of the values we are passing into
the API. Plus the usual API churn (removal of the argv methods,
changes to the compile/evaluate sequences, etc) is dealt with.
Currently mozjs38 is about two years old, and so it has a slightly
better security/etc statement. Gnome has moved off mozjs24 and is
intending to land on mozjs38 in the near future. Lets try to keep
polkit in step with gnome.
Signed-off-by: Jeremy Linton <jeremy.linton at arm.com>
---
configure.ac | 2 +-
src/polkitbackend/polkitbackendjsauthority.cpp | 422 +++++++++++++------------
2 files changed, 213 insertions(+), 211 deletions(-)
diff --git a/configure.ac b/configure.ac
index af2c8dd..093f5ea 100644
--- a/configure.ac
+++ b/configure.ac
@@ -82,7 +82,7 @@ AC_DEFINE([GLIB_VERSION_MIN_REQUIRED], [GLIB_VERSION_2_30],
AC_DEFINE([GLIB_VERSION_MAX_ALLOWED], [G_ENCODE_VERSION(2,34)],
[Notify us when we'll need to transition away from g_type_init()])
-PKG_CHECK_MODULES(LIBJS, [mozjs-24])
+PKG_CHECK_MODULES(LIBJS, [mozjs-38])
AC_SUBST(LIBJS_CFLAGS)
AC_SUBST(LIBJS_CXXFLAGS)
diff --git a/src/polkitbackend/polkitbackendjsauthority.cpp b/src/polkitbackend/polkitbackendjsauthority.cpp
index 6a0b4ab..68bc147 100644
--- a/src/polkitbackend/polkitbackendjsauthority.cpp
+++ b/src/polkitbackend/polkitbackendjsauthority.cpp
@@ -30,6 +30,7 @@
#include <netdb.h>
#endif
#include <string.h>
+#pragma GCC diagnostic ignored "-Wdeprecated-declarations"
#include <glib/gstdio.h>
#include <locale.h>
#include <glib/gi18n-lib.h>
@@ -43,9 +44,13 @@
#include <systemd/sd-login.h>
#endif /* HAVE_LIBSYSTEMD */
+#pragma GCC diagnostic ignored "-Winvalid-offsetof"
#include <jsapi.h>
+#pragma GCC diagnostic error "-Winvalid-offsetof"
+#include "js/Conversions.h"
#include "initjs.h" /* init.js */
+#pragma GCC diagnostic error "-Wdeprecated-declarations"
#ifdef JSGC_USE_EXACT_ROOTING
/* See https://developer.mozilla.org/en-US/docs/SpiderMonkey/Internals/GC/Exact_Stack_Rooting
@@ -75,9 +80,9 @@ struct _PolkitBackendJsAuthorityPrivate
JSRuntime *rt;
JSContext *cx;
- JSObject *js_global;
+ JS::RootedObject *js_global;
JSAutoCompartment *ac;
- JSObject *js_polkit;
+ JS::RootedObject *js_polkit;
GThread *runaway_killer_thread;
GMutex rkt_init_mutex;
@@ -92,9 +97,10 @@ struct _PolkitBackendJsAuthorityPrivate
GList *scripts;
};
-static JSBool execute_script_with_runaway_killer (PolkitBackendJsAuthority *authority,
- JSScript *script,
- jsval *rval);
+static bool execute_script_with_runaway_killer (PolkitBackendJsAuthority *authority,
+ JS::RootedScript *script,
+ JS::RootedValue *rval);
+
static void utils_spawn (const gchar *const *argv,
guint timeout_seconds,
@@ -153,15 +159,6 @@ G_DEFINE_TYPE (PolkitBackendJsAuthority, polkit_backend_js_authority, POLKIT_BAC
static JSClass js_global_class = {
"global",
JSCLASS_GLOBAL_FLAGS,
- JS_PropertyStub,
- JS_DeletePropertyStub,
- JS_PropertyStub,
- JS_StrictPropertyStub,
- JS_EnumerateStub,
- JS_ResolveStub,
- JS_ConvertStub,
- NULL,
- JSCLASS_NO_OPTIONAL_MEMBERS
};
/* ---------------------------------------------------------------------------------------------------- */
@@ -169,20 +166,11 @@ static JSClass js_global_class = {
static JSClass js_polkit_class = {
"Polkit",
0,
- JS_PropertyStub,
- JS_DeletePropertyStub,
- JS_PropertyStub,
- JS_StrictPropertyStub,
- JS_EnumerateStub,
- JS_ResolveStub,
- JS_ConvertStub,
- NULL,
- JSCLASS_NO_OPTIONAL_MEMBERS
};
-static JSBool js_polkit_log (JSContext *cx, unsigned argc, jsval *vp);
-static JSBool js_polkit_spawn (JSContext *cx, unsigned argc, jsval *vp);
-static JSBool js_polkit_user_is_in_netgroup (JSContext *cx, unsigned argc, jsval *vp);
+static bool js_polkit_log (JSContext *cx, unsigned argc, jsval *vp);
+static bool js_polkit_spawn (JSContext *cx, unsigned argc, jsval *vp);
+static bool js_polkit_user_is_in_netgroup (JSContext *cx, unsigned argc, jsval *vp);
static JSFunctionSpec js_polkit_functions[] =
{
@@ -288,16 +276,16 @@ load_scripts (PolkitBackendJsAuthority *authority)
for (l = files; l != NULL; l = l->next)
{
+ bool ret;
const gchar *filename = (gchar *)l->data;
JS::RootedScript script(authority->priv->cx);
JS::CompileOptions options(authority->priv->cx);
- JS::RootedObject obj(authority->priv->cx,authority->priv->js_global);
options.setUTF8(true);
- script = JS::Compile (authority->priv->cx,
- obj, options,
- filename);
+ ret = JS::Compile (authority->priv->cx,
+ *authority->priv->js_global, options,
+ filename, &script);
- if (script == NULL)
+ if (ret != true)
{
polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority),
"Error compiling script %s",
@@ -306,9 +294,10 @@ load_scripts (PolkitBackendJsAuthority *authority)
}
/* evaluate the script */
- jsval rval;
+ JS::RootedValue rval(authority->priv->cx);
+
if (!execute_script_with_runaway_killer (authority,
- script,
+ &script,
&rval))
{
polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority),
@@ -331,15 +320,13 @@ load_scripts (PolkitBackendJsAuthority *authority)
static void
reload_scripts (PolkitBackendJsAuthority *authority)
{
- jsval argv[1] = {JSVAL_NULL};
- jsval rval = JSVAL_NULL;
-
JS_BeginRequest (authority->priv->cx);
+ JS::AutoValueArray<1> argv(authority->priv->cx);
+ JS::RootedValue rval(authority->priv->cx);
if (!JS_CallFunctionName(authority->priv->cx,
- authority->priv->js_polkit,
+ *authority->priv->js_polkit,
"_deleteRules",
- 0,
argv,
&rval))
{
@@ -442,7 +429,9 @@ polkit_backend_js_authority_constructed (GObject *object)
PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (object);
gboolean entered_request = FALSE;
- authority->priv->rt = JS_NewRuntime (8L * 1024L * 1024L, JS_USE_HELPER_THREADS);
+ JS_Init();
+
+ authority->priv->rt = JS_NewRuntime (8L * 1024L * 1024L);
if (authority->priv->rt == NULL)
goto fail;
@@ -450,13 +439,7 @@ polkit_backend_js_authority_constructed (GObject *object)
if (authority->priv->cx == NULL)
goto fail;
- /* TODO: JIT'ing doesn't work will with killing runaway scripts... I think
- * this is just a SpiderMonkey bug. So disable the JIT for now.
- */
- JS_SetOptions (authority->priv->cx,
- JSOPTION_VAROBJFIX
- /* | JSOPTION_JIT | JSOPTION_METHODJIT*/);
- JS_SetErrorReporter(authority->priv->cx, report_error);
+ JS_SetErrorReporter(authority->priv->rt, report_error);
JS_SetContextPrivate (authority->priv->cx, authority);
JS_BeginRequest(authority->priv->cx);
@@ -465,45 +448,49 @@ polkit_backend_js_authority_constructed (GObject *object)
{
JS::CompartmentOptions compart_opts;
compart_opts.setVersion(JSVERSION_LATEST);
- authority->priv->js_global = JS_NewGlobalObject (authority->priv->cx, &js_global_class, NULL, compart_opts);
-
+ JSAutoRequest ar(authority->priv->cx);
+
+ authority->priv->js_global = new JS::RootedObject(authority->priv->cx,
+ JS_NewGlobalObject (authority->priv->cx,
+ &js_global_class,
+ nullptr,
+ JS::DontFireOnNewGlobalHook,
+ compart_opts));
if (authority->priv->js_global == NULL)
goto fail;
- authority->priv->ac = new JSAutoCompartment(authority->priv->cx, authority->priv->js_global);
-
+ authority->priv->ac = new JSAutoCompartment(authority->priv->cx, *authority->priv->js_global);
if (authority->priv->ac == NULL)
goto fail;
- JS_AddObjectRoot (authority->priv->cx, &authority->priv->js_global);
-
- if (!JS_InitStandardClasses (authority->priv->cx, authority->priv->js_global))
+ if (!JS_InitStandardClasses (authority->priv->cx, *authority->priv->js_global))
goto fail;
- authority->priv->js_polkit = JS_DefineObject (authority->priv->cx,
- authority->priv->js_global,
- "polkit",
- &js_polkit_class,
- NULL,
- JSPROP_ENUMERATE);
+ authority->priv->js_polkit = new JS::RootedObject(authority->priv->cx,
+ JS_DefineObject (authority->priv->cx,
+ *authority->priv->js_global,
+ "polkit",
+ &js_polkit_class,
+ JSPROP_ENUMERATE));
if (authority->priv->js_polkit == NULL)
goto fail;
- JS_AddObjectRoot (authority->priv->cx, &authority->priv->js_polkit);
if (!JS_DefineFunctions (authority->priv->cx,
- authority->priv->js_polkit,
+ *authority->priv->js_polkit,
js_polkit_functions))
goto fail;
- if (!JS_EvaluateScript (authority->priv->cx,
- authority->priv->js_global,
- init_js, strlen (init_js), /* init.js */
+ JS::CompileOptions options(authority->priv->cx);
+ options.setUTF8(true);
+ JS::RootedValue result(authority->priv->cx);
+
+ if (!JS::Evaluate(authority->priv->cx,
+ *authority->priv->js_global,
+ options,
"init.js", /* filename */
- 0, /* lineno */
- NULL)) /* rval */
- {
+ &result
+ ))
goto fail;
- }
if (authority->priv->rules_dirs == NULL)
{
@@ -571,14 +558,15 @@ polkit_backend_js_authority_finalize (GObject *object)
g_strfreev (authority->priv->rules_dirs);
JS_BeginRequest (authority->priv->cx);
- JS_RemoveObjectRoot (authority->priv->cx, &authority->priv->js_polkit);
+ delete authority->priv->js_polkit;
+ delete authority->priv->js_global;
delete authority->priv->ac;
- JS_RemoveObjectRoot (authority->priv->cx, &authority->priv->js_global);
JS_EndRequest (authority->priv->cx);
JS_DestroyContext (authority->priv->cx);
JS_DestroyRuntime (authority->priv->rt);
- /* JS_ShutDown (); */
+
+ JS_ShutDown();
G_OBJECT_CLASS (polkit_backend_js_authority_parent_class)->finalize (object);
}
@@ -661,21 +649,22 @@ polkit_backend_js_authority_class_init (PolkitBackendJsAuthorityClass *klass)
/* authority->priv->cx must be within a request */
static void
set_property_str (PolkitBackendJsAuthority *authority,
- JSObject *obj,
+ JS::RootedObject *obj,
const gchar *name,
const gchar *value)
{
JSString *value_jsstr;
- jsval value_jsval;
+ JS::Value value_jsval;
value_jsstr = JS_NewStringCopyZ (authority->priv->cx, value);
value_jsval = STRING_TO_JSVAL (value_jsstr);
- JS_SetProperty (authority->priv->cx, obj, name, &value_jsval);
+ JS::RootedValue svalue(authority->priv->cx, value_jsval);
+ JS_SetProperty (authority->priv->cx, *obj, name, svalue);
}
/* authority->priv->cx must be within a request */
static void
set_property_strv (PolkitBackendJsAuthority *authority,
- JSObject *obj,
+ JS::RootedObject *obj,
const gchar *name,
GPtrArray *value)
{
@@ -683,7 +672,8 @@ set_property_strv (PolkitBackendJsAuthority *authority,
JSObject *array_object;
guint n;
- array_object = JS_NewArrayObject (authority->priv->cx, 0, NULL);
+ array_object = JS_NewArrayObject (authority->priv->cx, 0);
+ JS::RootedObject rooted_array_object(authority->priv->cx, array_object);
for (n = 0; n < value->len; n++)
{
@@ -691,36 +681,39 @@ set_property_strv (PolkitBackendJsAuthority *authority,
jsval val;
jsstr = JS_NewStringCopyZ (authority->priv->cx, (char *)g_ptr_array_index(value, n));
- val = STRING_TO_JSVAL (jsstr);
- JS_SetElement (authority->priv->cx, array_object, n, &val);
+ JS::RootedString svalue(authority->priv->cx, jsstr);
+ JS_SetElement (authority->priv->cx, rooted_array_object, (uint32_t)n, svalue);
}
value_jsval = OBJECT_TO_JSVAL (array_object);
- JS_SetProperty (authority->priv->cx, obj, name, &value_jsval);
+ JS::RootedValue svalue(authority->priv->cx, value_jsval);
+ JS_SetProperty (authority->priv->cx, *obj, name, svalue);
}
/* authority->priv->cx must be within a request */
static void
set_property_int32 (PolkitBackendJsAuthority *authority,
- JSObject *obj,
+ JS::RootedObject *obj,
const gchar *name,
gint32 value)
{
jsval value_jsval;
value_jsval = INT_TO_JSVAL ((gint32) value);
- JS_SetProperty (authority->priv->cx, obj, name, &value_jsval);
+ JS::RootedValue svalue(authority->priv->cx, value_jsval);
+ JS_SetProperty (authority->priv->cx, *obj, name, svalue);
}
/* authority->priv->cx must be within a request */
static void
set_property_bool (PolkitBackendJsAuthority *authority,
- JSObject *obj,
+ JS::RootedObject *obj,
const gchar *name,
gboolean value)
{
jsval value_jsval;
- value_jsval = BOOLEAN_TO_JSVAL ((JSBool) value);
- JS_SetProperty (authority->priv->cx, obj, name, &value_jsval);
+ value_jsval = BOOLEAN_TO_JSVAL ((bool) value);
+ JS::RootedValue svalue(authority->priv->cx, value_jsval);
+ JS_SetProperty (authority->priv->cx, *obj, name, svalue);
}
/* ---------------------------------------------------------------------------------------------------- */
@@ -732,11 +725,10 @@ subject_to_jsval (PolkitBackendJsAuthority *authority,
PolkitIdentity *user_for_subject,
gboolean subject_is_local,
gboolean subject_is_active,
- jsval *out_jsval,
+ JS::RootedValue *out_jsval,
GError **error)
{
gboolean ret = FALSE;
- jsval ret_jsval;
const char *src;
JSObject *obj;
pid_t pid;
@@ -747,19 +739,21 @@ subject_to_jsval (PolkitBackendJsAuthority *authority,
char *seat_str = NULL;
char *session_str = NULL;
+ JS::CompileOptions options(authority->priv->cx);
+ options.setUTF8(true);
+
src = "new Subject();";
- if (!JS_EvaluateScript (authority->priv->cx,
- authority->priv->js_global,
- src, strlen (src),
- __FILE__, __LINE__,
- &ret_jsval))
+
+ if (!JS::Evaluate(authority->priv->cx,
+ *authority->priv->js_global,
+ options,
+ src, strlen (src),
+ out_jsval))
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Evaluating '%s' failed", src);
goto out;
}
- obj = JSVAL_TO_OBJECT (ret_jsval);
-
if (POLKIT_IS_UNIX_PROCESS (subject))
{
pid = polkit_unix_process_get_pid (POLKIT_UNIX_PROCESS (subject));
@@ -832,14 +826,17 @@ subject_to_jsval (PolkitBackendJsAuthority *authority,
}
}
- set_property_int32 (authority, obj, "pid", pid);
- set_property_str (authority, obj, "user", user_name);
- set_property_strv (authority, obj, "groups", groups);
- set_property_str (authority, obj, "seat", seat_str);
- set_property_str (authority, obj, "session", session_str);
- set_property_bool (authority, obj, "local", subject_is_local);
- set_property_bool (authority, obj, "active", subject_is_active);
-
+ {
+ JS::RootedObject outret(authority->priv->cx, &out_jsval->toObject());
+
+ set_property_int32 (authority, &outret, "pid", pid);
+ set_property_str (authority, &outret, "user", user_name);
+ set_property_strv (authority, &outret, "groups", groups);
+ set_property_str (authority, &outret, "seat", seat_str);
+ set_property_str (authority, &outret, "session", session_str);
+ set_property_bool (authority, &outret, "local", subject_is_local);
+ set_property_bool (authority, &outret, "active", subject_is_active);
+ }
ret = TRUE;
out:
@@ -849,9 +846,6 @@ subject_to_jsval (PolkitBackendJsAuthority *authority,
if (groups != NULL)
g_ptr_array_unref (groups);
- if (ret && out_jsval != NULL)
- *out_jsval = ret_jsval;
-
return ret;
}
@@ -862,48 +856,50 @@ static gboolean
action_and_details_to_jsval (PolkitBackendJsAuthority *authority,
const gchar *action_id,
PolkitDetails *details,
- jsval *out_jsval,
+ JS::RootedValue *out_jsval,
GError **error)
{
gboolean ret = FALSE;
- jsval ret_jsval;
const char *src;
JSObject *obj;
gchar **keys;
guint n;
+ JS::CompileOptions options(authority->priv->cx);
+ options.setUTF8(true);
+
src = "new Action();";
- if (!JS_EvaluateScript (authority->priv->cx,
- authority->priv->js_global,
- src, strlen (src),
- __FILE__, __LINE__,
- &ret_jsval))
+ if (!JS::Evaluate(authority->priv->cx,
+ *authority->priv->js_global,
+ options,
+ src, strlen (src),
+ out_jsval))
{
g_set_error (error, G_IO_ERROR, G_IO_ERROR_FAILED, "Evaluating '%s' failed", src);
goto out;
}
- obj = JSVAL_TO_OBJECT (ret_jsval);
+ {
+ JS::RootedObject outret(authority->priv->cx, &out_jsval->toObject());
- set_property_str (authority, obj, "id", action_id);
+ set_property_str (authority, &outret, "id", action_id);
- keys = polkit_details_get_keys (details);
- for (n = 0; keys != NULL && keys[n] != NULL; n++)
- {
- gchar *key;
- const gchar *value;
- key = g_strdup_printf ("_detail_%s", keys[n]);
- value = polkit_details_lookup (details, keys[n]);
- set_property_str (authority, obj, key, value);
- g_free (key);
- }
- g_strfreev (keys);
+ keys = polkit_details_get_keys (details);
+ for (n = 0; keys != NULL && keys[n] != NULL; n++)
+ {
+ gchar *key;
+ const gchar *value;
+ key = g_strdup_printf ("_detail_%s", keys[n]);
+ value = polkit_details_lookup (details, keys[n]);
+ set_property_str (authority, &outret, key, value);
+ g_free (key);
+ }
+ g_strfreev (keys);
+ }
ret = TRUE;
out:
- if (ret && out_jsval != NULL)
- *out_jsval = ret_jsval;
return ret;
}
@@ -939,7 +935,7 @@ runaway_killer_thread_func (gpointer user_data)
/* ---------------------------------------------------------------------------------------------------- */
-static JSBool
+static bool
js_operation_callback (JSContext *cx)
{
PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (JS_GetContextPrivate (cx));
@@ -953,7 +949,7 @@ js_operation_callback (JSContext *cx)
if (!authority->priv->rkt_timeout_pending)
{
g_mutex_unlock (&authority->priv->rkt_timeout_pending_mutex);
- return JS_TRUE;
+ return true;
}
authority->priv->rkt_timeout_pending = FALSE;
g_mutex_unlock (&authority->priv->rkt_timeout_pending_mutex);
@@ -962,12 +958,11 @@ js_operation_callback (JSContext *cx)
polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority), "Terminating runaway script");
/* Throw an exception - this way the JS code can ignore the runaway script handling */
- JS_SetOperationCallback (authority->priv->cx, NULL);
val_str = JS_NewStringCopyZ (cx, "Terminating runaway script");
val = STRING_TO_JSVAL (val_str);
- JS_SetPendingException (authority->priv->cx, val);
- JS_SetOperationCallback (authority->priv->cx, js_operation_callback);
- return JS_FALSE;
+ JS::RootedValue svalue(authority->priv->cx, val);
+ JS_SetPendingException (authority->priv->cx, svalue);
+ return false;
}
static gboolean
@@ -980,7 +975,7 @@ rkt_on_timeout (gpointer user_data)
g_mutex_unlock (&authority->priv->rkt_timeout_pending_mutex);
/* Supposedly this is thread-safe... */
- JS_TriggerOperationCallback (authority->priv->rt);
+ JS_RequestInterruptCallback (authority->priv->rt);
/* keep source around so we keep trying to kill even if the JS bit catches the exception
* thrown in js_operation_callback()
@@ -1004,49 +999,48 @@ runaway_killer_setup (PolkitBackendJsAuthority *authority)
/* ... rkt_on_timeout() will then poke the JSContext so js_operation_callback() is
* called... and from there we throw an exception
*/
- JS_SetOperationCallback (authority->priv->cx, js_operation_callback);
+ JS_SetInterruptCallback (authority->priv->rt, js_operation_callback);
+
}
static void
runaway_killer_teardown (PolkitBackendJsAuthority *authority)
{
- JS_SetOperationCallback (authority->priv->cx, NULL);
+ JS_SetInterruptCallback (authority->priv->rt, NULL);
g_source_destroy (authority->priv->rkt_source);
g_source_unref (authority->priv->rkt_source);
authority->priv->rkt_source = NULL;
}
-static JSBool
+static bool
execute_script_with_runaway_killer (PolkitBackendJsAuthority *authority,
- JSScript *script,
- jsval *rval)
+ JS::RootedScript *script,
+ JS::RootedValue *rval)
{
- JSBool ret;
+ bool ret;
runaway_killer_setup (authority);
ret = JS_ExecuteScript (authority->priv->cx,
- authority->priv->js_global,
- script,
+ *authority->priv->js_global,
+ *script,
rval);
runaway_killer_teardown (authority);
return ret;
}
-static JSBool
+static bool
call_js_function_with_runaway_killer (PolkitBackendJsAuthority *authority,
const char *function_name,
- unsigned argc,
- jsval *argv,
- jsval *rval)
+ JS::AutoValueArray<2> *argv,
+ JS::RootedValue *rval)
{
- JSBool ret;
+ bool ret;
runaway_killer_setup (authority);
ret = JS_CallFunctionName(authority->priv->cx,
- authority->priv->js_polkit,
+ *authority->priv->js_polkit,
function_name,
- argc,
- argv,
+ *argv,
rval);
runaway_killer_teardown (authority);
return ret;
@@ -1066,17 +1060,18 @@ polkit_backend_js_authority_get_admin_auth_identities (PolkitBackendInteractiveA
{
PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (_authority);
GList *ret = NULL;
- jsval argv[2] = {JSVAL_NULL, JSVAL_NULL};
- jsval rval = JSVAL_NULL;
+ JS::AutoValueArray<2> argv(authority->priv->cx);
+ JS::RootedValue argv0(authority->priv->cx);
+ JS::RootedValue argv1(authority->priv->cx);
+ JS::RootedValue rval(authority->priv->cx);
guint n;
GError *error = NULL;
- JSString *ret_jsstr;
gchar *ret_str = NULL;
gchar **ret_strs = NULL;
JS_BeginRequest (authority->priv->cx);
- if (!action_and_details_to_jsval (authority, action_id, details, &argv[0], &error))
+ if (!action_and_details_to_jsval (authority, action_id, details, &argv0, &error))
{
polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority),
"Error converting action and details to JS object: %s",
@@ -1090,7 +1085,7 @@ polkit_backend_js_authority_get_admin_auth_identities (PolkitBackendInteractiveA
user_for_subject,
subject_is_local,
subject_is_active,
- &argv[1],
+ &argv1,
&error))
{
polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority),
@@ -1099,11 +1094,12 @@ polkit_backend_js_authority_get_admin_auth_identities (PolkitBackendInteractiveA
g_clear_error (&error);
goto out;
}
-
+ argv[0].setObject(argv0.toObject());
+ argv[1].setObject(argv1.toObject());
if (!call_js_function_with_runaway_killer (authority,
"_runAdminRules",
- G_N_ELEMENTS (argv),
- argv,
+ // G_N_ELEMENTS (argv),
+ &argv,
&rval))
{
polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority),
@@ -1111,14 +1107,17 @@ polkit_backend_js_authority_get_admin_auth_identities (PolkitBackendInteractiveA
goto out;
}
- if (!JSVAL_IS_STRING (rval))
+ if (!rval.isString())
{
g_warning ("Expected a string");
goto out;
}
- ret_jsstr = JSVAL_TO_STRING (rval);
- ret_str = g_utf16_to_utf8 (JS_GetStringCharsZ (authority->priv->cx, ret_jsstr), -1, NULL, NULL, NULL);
+ {
+ JS::RootedString ToUtf8(authority->priv->cx,rval.toString());
+ ret_str = JS_EncodeStringToUTF8(authority->priv->cx, ToUtf8);
+ }
+
if (ret_str == NULL)
{
g_warning ("Error converting resulting string to UTF-8: %s", error->message);
@@ -1136,8 +1135,8 @@ polkit_backend_js_authority_get_admin_auth_identities (PolkitBackendInteractiveA
if (identity == NULL)
{
polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority),
- "Identity `%s' is not valid, ignoring",
- identity_str);
+ "Identity `%s' is not valid, ignoring ret strs %s",
+ identity_str, ret_str);
}
else
{
@@ -1148,7 +1147,7 @@ polkit_backend_js_authority_get_admin_auth_identities (PolkitBackendInteractiveA
out:
g_strfreev (ret_strs);
- g_free (ret_str);
+ JS_free(authority->priv->cx, ret_str);
/* fallback to root password auth */
if (ret == NULL)
ret = g_list_prepend (ret, polkit_unix_user_new (0));
@@ -1175,17 +1174,18 @@ polkit_backend_js_authority_check_authorization_sync (PolkitBackendInteractiveAu
{
PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (_authority);
PolkitImplicitAuthorization ret = implicit;
- jsval argv[2] = {JSVAL_NULL, JSVAL_NULL};
- jsval rval = JSVAL_NULL;
+ JS::AutoValueArray<2> argv(authority->priv->cx);
+ JS::RootedValue argv0(authority->priv->cx);
+ JS::RootedValue argv1(authority->priv->cx);
+ JS::RootedValue rval(authority->priv->cx);
GError *error = NULL;
- JSString *ret_jsstr;
- const jschar *ret_utf16;
+
gchar *ret_str = NULL;
gboolean good = FALSE;
JS_BeginRequest (authority->priv->cx);
- if (!action_and_details_to_jsval (authority, action_id, details, &argv[0], &error))
+ if (!action_and_details_to_jsval (authority, action_id, details, &argv0, &error))
{
polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority),
"Error converting action and details to JS object: %s",
@@ -1199,7 +1199,7 @@ polkit_backend_js_authority_check_authorization_sync (PolkitBackendInteractiveAu
user_for_subject,
subject_is_local,
subject_is_active,
- &argv[1],
+ &argv1,
&error))
{
polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority),
@@ -1209,10 +1209,13 @@ polkit_backend_js_authority_check_authorization_sync (PolkitBackendInteractiveAu
goto out;
}
+ argv[0].setObject(argv0.toObject());
+ argv[1].setObject(argv1.toObject());
+
if (!call_js_function_with_runaway_killer (authority,
"_runRules",
- G_N_ELEMENTS (argv),
- argv,
+ // G_N_ELEMENTS (argv),
+ &argv,
&rval))
{
polkit_backend_authority_log (POLKIT_BACKEND_AUTHORITY (authority),
@@ -1220,22 +1223,17 @@ polkit_backend_js_authority_check_authorization_sync (PolkitBackendInteractiveAu
goto out;
}
- if (JSVAL_IS_NULL (rval))
- {
- /* this fine, means there was no match, use implicit authorizations */
- good = TRUE;
- goto out;
- }
-
- if (!JSVAL_IS_STRING (rval))
+ if (!rval.isString())
{
g_warning ("Expected a string");
goto out;
}
- ret_jsstr = JSVAL_TO_STRING (rval);
- ret_utf16 = JS_GetStringCharsZ (authority->priv->cx, ret_jsstr);
- ret_str = g_utf16_to_utf8 (ret_utf16, -1, NULL, NULL, &error);
+ {
+ JS::RootedString ToUtf8(authority->priv->cx,rval.toString());
+ ret_str = JS_EncodeStringToUTF8(authority->priv->cx, ToUtf8);
+ }
+
if (ret_str == NULL)
{
g_warning ("Error converting resulting string to UTF-8: %s", error->message);
@@ -1257,7 +1255,7 @@ polkit_backend_js_authority_check_authorization_sync (PolkitBackendInteractiveAu
out:
if (!good)
ret = POLKIT_IMPLICIT_AUTHORIZATION_NOT_AUTHORIZED;
- g_free (ret_str);
+ JS_free(authority->priv->cx, ret_str);
JS_MaybeGC (authority->priv->cx);
@@ -1268,26 +1266,26 @@ polkit_backend_js_authority_check_authorization_sync (PolkitBackendInteractiveAu
/* ---------------------------------------------------------------------------------------------------- */
-static JSBool
+static bool
js_polkit_log (JSContext *cx,
unsigned argc,
jsval *vp)
{
/* PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (JS_GetContextPrivate (cx)); */
- JSBool ret = JS_FALSE;
+ bool ret = false;
JSString *str;
char *s;
- if (!JS_ConvertArguments (cx, argc, JS_ARGV (cx, vp), "S", &str))
- goto out;
+ JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
+ str = JS::ToString(cx, args[0]);
s = JS_EncodeString (cx, str);
JS_ReportWarning (cx, s);
JS_free (cx, s);
- ret = JS_TRUE;
+ ret = true;
- JS_SET_RVAL (cx, vp, JSVAL_VOID); /* return undefined */
+ args.rval().setUndefined(); //returned undefined
out:
return ret;
}
@@ -1353,13 +1351,13 @@ spawn_cb (GObject *source_object,
g_main_loop_quit (data->loop);
}
-static JSBool
+static bool
js_polkit_spawn (JSContext *cx,
- unsigned js_argc,
+ unsigned argc,
jsval *vp)
{
/* PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (JS_GetContextPrivate (cx)); */
- JSBool ret = JS_FALSE;
+ bool ret = false;
JSObject *array_object;
gchar *standard_output = NULL;
gchar *standard_error = NULL;
@@ -1372,11 +1370,13 @@ js_polkit_spawn (JSContext *cx,
GMainLoop *loop = NULL;
SpawnData data = {0};
guint n;
+ JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- if (!JS_ConvertArguments (cx, js_argc, JS_ARGV (cx, vp), "o", &array_object))
- goto out;
+ array_object=JS::ToObject(cx, args[0]);
+
+ JS::RootedObject opts(cx, array_object);
- if (!JS_GetArrayLength (cx, array_object, &array_len))
+ if (!JS_GetArrayLength (cx, opts, &array_len))
{
JS_ReportError (cx, "Failed to get array length");
goto out;
@@ -1387,18 +1387,19 @@ js_polkit_spawn (JSContext *cx,
{
jsval elem_val;
char *s;
+ JS::RootedValue elemval(cx, elem_val);
- if (!JS_GetElement (cx, array_object, n, &elem_val))
+ if (!JS_GetElement (cx, opts, n, &elemval))
{
JS_ReportError (cx, "Failed to get element %d", n);
goto out;
}
- if (!JSVAL_IS_STRING (elem_val))
- {
+ if (!elemval.isString())
+ {
JS_ReportError (cx, "Element %d is not a string", n);
goto out;
- }
- s = JS_EncodeString (cx, JSVAL_TO_STRING (elem_val));
+ }
+ s = JS_EncodeString (cx, elemval.toString());
argv[n] = g_strdup (s);
JS_free (cx, s);
}
@@ -1456,10 +1457,10 @@ js_polkit_spawn (JSContext *cx,
goto out;
}
- ret = JS_TRUE;
+ ret = true;
ret_jsstr = JS_NewStringCopyZ (cx, standard_output);
- JS_SET_RVAL (cx, vp, STRING_TO_JSVAL (ret_jsstr));
+ args.rval().setString(ret_jsstr);
out:
g_strfreev (argv);
@@ -1476,21 +1477,22 @@ js_polkit_spawn (JSContext *cx,
/* ---------------------------------------------------------------------------------------------------- */
-static JSBool
+static bool
js_polkit_user_is_in_netgroup (JSContext *cx,
unsigned argc,
jsval *vp)
{
/* PolkitBackendJsAuthority *authority = POLKIT_BACKEND_JS_AUTHORITY (JS_GetContextPrivate (cx)); */
- JSBool ret = JS_FALSE;
+ bool ret = false;
JSString *user_str;
JSString *netgroup_str;
char *user;
char *netgroup;
- JSBool is_in_netgroup = JS_FALSE;
+ bool is_in_netgroup = false;
+ JS::CallArgs args = JS::CallArgsFromVp(argc, vp);
- if (!JS_ConvertArguments (cx, argc, JS_ARGV (cx, vp), "SS", &user_str, &netgroup_str))
- goto out;
+ user_str = JS::ToString(cx, args[0]);
+ netgroup_str = JS::ToString(cx, args[1]);
user = JS_EncodeString (cx, user_str);
netgroup = JS_EncodeString (cx, netgroup_str);
@@ -1500,15 +1502,15 @@ js_polkit_user_is_in_netgroup (JSContext *cx,
user,
NULL)) /* domain */
{
- is_in_netgroup = JS_TRUE;
+ is_in_netgroup = true;
}
JS_free (cx, netgroup);
JS_free (cx, user);
- ret = JS_TRUE;
+ ret = true;
- JS_SET_RVAL (cx, vp, BOOLEAN_TO_JSVAL (is_in_netgroup));
+ args.rval().setBoolean(is_in_netgroup);
out:
return ret;
}
--
2.11.0

View File

@ -0,0 +1,720 @@
From 6ff6548e021938b1ec41137b8964e5079dfe2bfa Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Miloslav=20Trma=C4=8D?= <mitr@redhat.com>
Date: Wed, 23 Mar 2016 13:18:58 +0100
Subject: [PATCH 17/29] Remove polkitbackendconfigsource.[ch]
It is no longer used since the move to JavaScript, and we don't want to
maintain it unnecessarily.
https://bugs.freedesktop.org/show_bug.cgi?id=94670
---
src/polkitbackend/Makefile.am | 1 -
src/polkitbackend/polkitbackendconfigsource.c | 565 ---------------------
src/polkitbackend/polkitbackendconfigsource.h | 98 ----
.../polkitbackendinteractiveauthority.c | 1 -
4 files changed, 665 deletions(-)
delete mode 100644 src/polkitbackend/polkitbackendconfigsource.c
delete mode 100644 src/polkitbackend/polkitbackendconfigsource.h
diff --git a/src/polkitbackend/Makefile.am b/src/polkitbackend/Makefile.am
index 547ca82..a80ca36 100644
--- a/src/polkitbackend/Makefile.am
+++ b/src/polkitbackend/Makefile.am
@@ -34,7 +34,6 @@ libpolkit_backend_1_la_SOURCES = \
polkitbackendinteractiveauthority.h polkitbackendinteractiveauthority.c \
polkitbackendjsauthority.h polkitbackendjsauthority.c \
polkitbackendactionpool.h polkitbackendactionpool.c \
- polkitbackendconfigsource.h polkitbackendconfigsource.c \
polkitbackendactionlookup.h polkitbackendactionlookup.c \
$(NULL)
diff --git a/src/polkitbackend/polkitbackendconfigsource.c b/src/polkitbackend/polkitbackendconfigsource.c
deleted file mode 100644
index 838bc6a..0000000
--- a/src/polkitbackend/polkitbackendconfigsource.c
+++ /dev/null
@@ -1,565 +0,0 @@
-/*
- * Copyright (C) 2008 Red Hat, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * Author: David Zeuthen <davidz@redhat.com>
- */
-
-#include "config.h"
-
-#include <polkit/polkit.h>
-#include "polkitbackendconfigsource.h"
-
-/* <internal>
- * SECTION:polkitbackendconfigsource
- * @title: PolkitBackendConfigSource
- * @short_description: Access configuration files
- *
- * The #PolkitBackendConfigSource class is a utility class to read
- * configuration data from a set of prioritized key-value files in a
- * given directory.
- */
-
-struct _PolkitBackendConfigSourcePrivate
-{
- GFile *directory;
-
- GFileMonitor *directory_monitor;
-
- /* sorted according to priority, higher priority is first */
- GList *key_files;
-
- gboolean has_data;
-};
-
-enum
-{
- PROP_0,
- PROP_DIRECTORY,
-};
-
-enum
-{
- CHANGED_SIGNAL,
- LAST_SIGNAL,
-};
-
-static guint signals[LAST_SIGNAL] = {0};
-
-static void polkit_backend_config_source_purge (PolkitBackendConfigSource *source);
-
-static void polkit_backend_config_source_ensure (PolkitBackendConfigSource *source);
-
-G_DEFINE_TYPE (PolkitBackendConfigSource, polkit_backend_config_source, G_TYPE_OBJECT);
-
-/* ---------------------------------------------------------------------------------------------------- */
-
-static void
-polkit_backend_config_source_init (PolkitBackendConfigSource *source)
-{
- source->priv = G_TYPE_INSTANCE_GET_PRIVATE (source,
- POLKIT_BACKEND_TYPE_CONFIG_SOURCE,
- PolkitBackendConfigSourcePrivate);
-}
-
-static void
-polkit_backend_config_source_finalize (GObject *object)
-{
- PolkitBackendConfigSource *source = POLKIT_BACKEND_CONFIG_SOURCE (object);
-
- if (source->priv->directory != NULL)
- g_object_unref (source->priv->directory);
-
- if (source->priv->directory_monitor != NULL)
- g_object_unref (source->priv->directory_monitor);
-
- g_list_foreach (source->priv->key_files, (GFunc) g_key_file_free, NULL);
- g_list_free (source->priv->key_files);
-
- if (G_OBJECT_CLASS (polkit_backend_config_source_parent_class)->finalize != NULL)
- G_OBJECT_CLASS (polkit_backend_config_source_parent_class)->finalize (object);
-}
-
-
-static void
-polkit_backend_config_source_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
-{
- PolkitBackendConfigSource *source = POLKIT_BACKEND_CONFIG_SOURCE (object);
-
- switch (prop_id)
- {
- case PROP_DIRECTORY:
- g_value_set_object (value, source->priv->directory);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-polkit_backend_config_source_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
-{
- PolkitBackendConfigSource *source = POLKIT_BACKEND_CONFIG_SOURCE (object);
-
- switch (prop_id)
- {
- case PROP_DIRECTORY:
- source->priv->directory = g_value_dup_object (value);
- break;
-
- default:
- G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
- break;
- }
-}
-
-static void
-directory_monitor_changed (GFileMonitor *monitor,
- GFile *file,
- GFile *other_file,
- GFileMonitorEvent event_type,
- gpointer user_data)
-{
- PolkitBackendConfigSource *source;
-
- source = POLKIT_BACKEND_CONFIG_SOURCE (user_data);
-
- if (file != NULL)
- {
- gchar *name;
-
- name = g_file_get_basename (file);
-
- //g_debug ("event_type=%d file=%p name=%s", event_type, file, name);
-
- if (!g_str_has_prefix (name, ".") &&
- !g_str_has_prefix (name, "#") &&
- g_str_has_suffix (name, ".conf") &&
- (event_type == G_FILE_MONITOR_EVENT_CREATED ||
- event_type == G_FILE_MONITOR_EVENT_DELETED ||
- event_type == G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT))
- {
-
- //g_debug ("match");
-
- /* now throw away all caches */
- polkit_backend_config_source_purge (source);
- g_signal_emit_by_name (source, "changed");
- }
-
- g_free (name);
- }
-}
-
-static void
-polkit_backend_config_source_constructed (GObject *object)
-{
- PolkitBackendConfigSource *source = POLKIT_BACKEND_CONFIG_SOURCE (object);
- GError *error;
-
- error = NULL;
- source->priv->directory_monitor = g_file_monitor_directory (source->priv->directory,
- G_FILE_MONITOR_NONE,
- NULL,
- &error);
- if (source->priv->directory_monitor == NULL)
- {
- gchar *dir_name;
- dir_name = g_file_get_uri (source->priv->directory);
- g_warning ("Error monitoring directory %s: %s", dir_name, error->message);
- g_free (dir_name);
- g_error_free (error);
- }
- else
- {
- g_signal_connect (source->priv->directory_monitor,
- "changed",
- (GCallback) directory_monitor_changed,
- source);
- }
-
- if (G_OBJECT_CLASS (polkit_backend_config_source_parent_class)->constructed != NULL)
- G_OBJECT_CLASS (polkit_backend_config_source_parent_class)->constructed (object);
-}
-
-static void
-polkit_backend_config_source_class_init (PolkitBackendConfigSourceClass *klass)
-{
- GObjectClass *gobject_class;
-
- gobject_class = G_OBJECT_CLASS (klass);
-
- gobject_class->get_property = polkit_backend_config_source_get_property;
- gobject_class->set_property = polkit_backend_config_source_set_property;
- gobject_class->constructed = polkit_backend_config_source_constructed;
- gobject_class->finalize = polkit_backend_config_source_finalize;
-
- g_type_class_add_private (klass, sizeof (PolkitBackendConfigSourcePrivate));
-
- /**
- * PolkitBackendConfigSource:directory:
- *
- * The directory to watch for configuration files.
- */
- g_object_class_install_property (gobject_class,
- PROP_DIRECTORY,
- g_param_spec_object ("directory",
- "Directory",
- "The directory to watch for configuration files",
- G_TYPE_FILE,
- G_PARAM_CONSTRUCT_ONLY |
- G_PARAM_READWRITE |
- G_PARAM_STATIC_NAME |
- G_PARAM_STATIC_BLURB |
- G_PARAM_STATIC_NICK));
-
- /**
- * PolkitBackendConfiguSource::changed:
- * @source: A #PolkitBackendConfigSource.
- *
- * Emitted when configuration files in #PolkitBackendConfiguSource:directory changes.
- */
- signals[CHANGED_SIGNAL] = g_signal_new ("changed",
- POLKIT_BACKEND_TYPE_CONFIG_SOURCE,
- G_SIGNAL_RUN_LAST,
- G_STRUCT_OFFSET (PolkitBackendConfigSourceClass, changed),
- NULL,
- NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE,
- 0);
-}
-
-/**
- * polkit_backend_config_source_new:
- * @directory: The directory to watch.
- *
- * Creates a new #PolkitBackendConfigSource object that reads
- * configuration from @directory. To watch for configuration changes,
- * connect to the #PolkitBackendConfigSource::changed signal.
- *
- * Returns: A #PolkitBackendConfigSource for @directory. Free with
- * g_object_unref().
- **/
-PolkitBackendConfigSource *
-polkit_backend_config_source_new (GFile *directory)
-{
- PolkitBackendConfigSource *source;
-
- source = POLKIT_BACKEND_CONFIG_SOURCE (g_object_new (POLKIT_BACKEND_TYPE_CONFIG_SOURCE,
- "directory", directory,
- NULL));
-
- return source;
-}
-
-static void
-polkit_backend_config_source_purge (PolkitBackendConfigSource *source)
-{
- g_list_foreach (source->priv->key_files, (GFunc) g_key_file_free, NULL);
- g_list_free (source->priv->key_files);
- source->priv->key_files = NULL;
-
- source->priv->has_data = FALSE;
-}
-
-static gint
-compare_filename (GFile *a, GFile *b)
-{
- gchar *a_uri;
- gchar *b_uri;
- gint ret;
-
- a_uri = g_file_get_uri (a);
- b_uri = g_file_get_uri (b);
-
- /* TODO: use ASCII sort function? */
- ret = -g_strcmp0 (a_uri, b_uri);
-
- return ret;
-}
-
-static void
-polkit_backend_config_source_ensure (PolkitBackendConfigSource *source)
-{
- GFileEnumerator *enumerator;
- GFileInfo *file_info;
- GError *error;
- GList *files;
- GList *l;
-
- files = NULL;
-
- if (source->priv->has_data)
- goto out;
-
- polkit_backend_config_source_purge (source);
-
- error = NULL;
- enumerator = g_file_enumerate_children (source->priv->directory,
- "standard::name",
- G_FILE_QUERY_INFO_NONE,
- NULL,
- &error);
- if (enumerator == NULL)
- {
- gchar *dir_name;
- dir_name = g_file_get_uri (source->priv->directory);
- g_warning ("Error enumerating files in %s: %s", dir_name, error->message);
- g_free (dir_name);
- g_error_free (error);
- goto out;
- }
-
- while ((file_info = g_file_enumerator_next_file (enumerator, NULL, &error)) != NULL)
- {
- const gchar *name;
-
- name = g_file_info_get_name (file_info);
-
- /* only consider files ending in .conf */
- if (g_str_has_suffix (name, ".conf"))
- files = g_list_prepend (files, g_file_get_child (source->priv->directory, name));
-
- g_object_unref (file_info);
- }
- g_object_unref (enumerator);
- if (error != NULL)
- {
- g_warning ("Error enumerating files: %s", error->message);
- g_error_free (error);
- goto out;
- }
-
- files = g_list_sort (files, (GCompareFunc) compare_filename);
-
- /* process files; highest priority comes first */
- for (l = files; l != NULL; l = l->next)
- {
- GFile *file = G_FILE (l->data);
- gchar *filename;
- GKeyFile *key_file;
-
- filename = g_file_get_path (file);
-
- key_file = g_key_file_new ();
-
- error = NULL;
- if (!g_key_file_load_from_file (key_file,
- filename,
- G_KEY_FILE_NONE,
- NULL))
- {
- g_warning ("Error loading key-file %s: %s", filename, error->message);
- g_error_free (error);
- error = NULL;
- g_key_file_free (key_file);
- }
- else
- {
- source->priv->key_files = g_list_prepend (source->priv->key_files, key_file);
- }
-
- g_free (filename);
- }
-
- source->priv->key_files = g_list_reverse (source->priv->key_files);
- source->priv->has_data = TRUE;
-
- out:
- g_list_foreach (files, (GFunc) g_object_unref, NULL);
- g_list_free (files);
-}
-
-static GKeyFile *
-find_key_file (PolkitBackendConfigSource *source,
- const gchar *group,
- const gchar *key,
- GError **error)
-{
- GList *l;
- GKeyFile *ret;
-
- ret = NULL;
-
- for (l = source->priv->key_files; l != NULL; l = l->next)
- {
- GKeyFile *key_file = l->data;
-
- if (g_key_file_has_key (key_file, group, key, NULL))
- {
- ret = key_file;
- goto out;
- }
- }
-
- out:
- if (ret == NULL)
- g_set_error_literal (error,
- G_KEY_FILE_ERROR,
- G_KEY_FILE_ERROR_NOT_FOUND,
- "Group/Key combo not found in any config file");
- return ret;
-}
-
-/**
- * polkit_backend_config_source_get_integer:
- * @source: A PolkitBackendConfigSource.
- * @group: A group name.
- * @key: A key name.
- * @error: Return location for error or %NULL.
- *
- * Gets the value associated with @key under @group_name.
- *
- * Returns: The value or 0 if @error is set.
- **/
-gint
-polkit_backend_config_source_get_integer (PolkitBackendConfigSource *source,
- const gchar *group,
- const gchar *key,
- GError **error)
-{
- GKeyFile *key_file;
-
- polkit_backend_config_source_ensure (source);
-
- key_file = find_key_file (source, group, key, error);
- if (key_file == NULL)
- return 0;
-
- return g_key_file_get_integer (key_file, group, key, error);
-}
-
-/**
- * polkit_backend_config_source_get_boolean:
- * @source: A PolkitBackendConfigSource.
- * @group: A group name.
- * @key: A key name.
- * @error: Return location for error or %NULL.
- *
- * Gets the value associated with @key under @group_name.
- *
- * Returns: The value or %FALSE if @error is set.
- **/
-gboolean
-polkit_backend_config_source_get_boolean (PolkitBackendConfigSource *source,
- const gchar *group,
- const gchar *key,
- GError **error)
-{
- GKeyFile *key_file;
-
- polkit_backend_config_source_ensure (source);
-
- key_file = find_key_file (source, group, key, error);
- if (key_file == NULL)
- return FALSE;
-
- return g_key_file_get_boolean (key_file, group, key, error);
-}
-
-/**
- * polkit_backend_config_source_get_double:
- * @source: A PolkitBackendConfigSource.
- * @group: A group name.
- * @key: A key name.
- * @error: Return location for error or %NULL.
- *
- * Gets the value associated with @key under @group_name.
- *
- * Returns: The value or 0.0 if @error is set.
- **/
-gdouble
-polkit_backend_config_source_get_double (PolkitBackendConfigSource *source,
- const gchar *group,
- const gchar *key,
- GError **error)
-{
- GKeyFile *key_file;
-
- polkit_backend_config_source_ensure (source);
-
- key_file = find_key_file (source, group, key, error);
- if (key_file == NULL)
- return 0.0;
-
- return g_key_file_get_double (key_file, group, key, error);
-}
-
-/**
- * polkit_backend_config_source_get_string:
- * @source: A PolkitBackendConfigSource.
- * @group: A group name.
- * @key: A key name.
- * @error: Return location for error or %NULL.
- *
- * Gets the value associated with @key under @group_name.
- *
- * Returns: The value or %NULL if @error is set.
- **/
-gchar *
-polkit_backend_config_source_get_string (PolkitBackendConfigSource *source,
- const gchar *group,
- const gchar *key,
- GError **error)
-{
- GKeyFile *key_file;
-
- polkit_backend_config_source_ensure (source);
-
- key_file = find_key_file (source, group, key, error);
- if (key_file == NULL)
- return NULL;
-
- return g_key_file_get_string (key_file, group, key, error);
-}
-
-/**
- * polkit_backend_config_source_get_string_list:
- * @source: A PolkitBackendConfigSource.
- * @group: A group name.
- * @key: A key name.
- * @error: Return location for error or %NULL.
- *
- * Gets the values associated with @key under @group_name.
- *
- * Returns: The value or %NULL if @error is set.
- **/
-gchar **
-polkit_backend_config_source_get_string_list (PolkitBackendConfigSource *source,
- const gchar *group,
- const gchar *key,
- GError **error)
-{
- GKeyFile *key_file;
-
- polkit_backend_config_source_ensure (source);
-
- key_file = find_key_file (source, group, key, error);
- if (key_file == NULL)
- return NULL;
-
- return g_key_file_get_string_list (key_file, group, key, NULL, error);
-}
diff --git a/src/polkitbackend/polkitbackendconfigsource.h b/src/polkitbackend/polkitbackendconfigsource.h
deleted file mode 100644
index f9a48c8..0000000
--- a/src/polkitbackend/polkitbackendconfigsource.h
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Copyright (C) 2008 Red Hat, Inc.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General
- * Public License along with this library; if not, write to the
- * Free Software Foundation, Inc., 59 Temple Place, Suite 330,
- * Boston, MA 02111-1307, USA.
- *
- * Author: David Zeuthen <davidz@redhat.com>
- */
-
-#if !defined (_POLKIT_BACKEND_COMPILATION) || defined(_POLKIT_BACKEND_INSIDE_POLKIT_BACKEND_H)
-#error "This is a private header file."
-#endif
-
-#ifndef __POLKIT_BACKEND_CONFIG_SOURCE_H
-#define __POLKIT_BACKEND_CONFIG_SOURCE_H
-
-#include <glib-object.h>
-#include <gio/gio.h>
-#include <polkitbackend/polkitbackendtypes.h>
-
-G_BEGIN_DECLS
-
-#define POLKIT_BACKEND_TYPE_CONFIG_SOURCE (polkit_backend_config_source_get_type ())
-#define POLKIT_BACKEND_CONFIG_SOURCE(o) (G_TYPE_CHECK_INSTANCE_CAST ((o), POLKIT_BACKEND_TYPE_CONFIG_SOURCE, PolkitBackendConfigSource))
-#define POLKIT_BACKEND_CONFIG_SOURCE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST ((k), POLKIT_BACKEND_TYPE_CONFIG_SOURCE, PolkitBackendConfigSourceClass))
-#define POLKIT_BACKEND_CONFIG_SOURCE_GET_CLASS(o) (G_TYPE_INSTANCE_GET_CLASS ((o), POLKIT_BACKEND_TYPE_CONFIG_SOURCE,PolkitBackendConfigSourceClass))
-#define POLKIT_BACKEND_IS_CONFIG_SOURCE(o) (G_TYPE_CHECK_INSTANCE_TYPE ((o), POLKIT_BACKEND_TYPE_CONFIG_SOURCE))
-#define POLKIT_BACKEND_IS_CONFIG_SOURCE_CLASS(k) (G_TYPE_CHECK_CLASS_TYPE ((k), POLKIT_BACKEND_TYPE_CONFIG_SOURCE))
-
-typedef struct _PolkitBackendConfigSource PolkitBackendConfigSource;
-typedef struct _PolkitBackendConfigSourceClass PolkitBackendConfigSourceClass;
-typedef struct _PolkitBackendConfigSourcePrivate PolkitBackendConfigSourcePrivate;
-
-struct _PolkitBackendConfigSource
-{
- GObject parent_instance;
- PolkitBackendConfigSourcePrivate *priv;
-};
-
-struct _PolkitBackendConfigSourceClass
-{
- /*< public >*/
- GObjectClass parent_class;
-
- /* Signals */
- void (*changed) (PolkitBackendConfigSource *config_source);
-
- /*< private >*/
- /* Padding for future expansion */
- void (*_polkit_reserved1) (void);
- void (*_polkit_reserved2) (void);
- void (*_polkit_reserved3) (void);
- void (*_polkit_reserved4) (void);
- void (*_polkit_reserved5) (void);
- void (*_polkit_reserved6) (void);
- void (*_polkit_reserved7) (void);
- void (*_polkit_reserved8) (void);
-};
-
-GType polkit_backend_config_source_get_type (void) G_GNUC_CONST;
-PolkitBackendConfigSource *polkit_backend_config_source_new (GFile *directory);
-gint polkit_backend_config_source_get_integer (PolkitBackendConfigSource *source,
- const gchar *group,
- const gchar *key,
- GError **error);
-gboolean polkit_backend_config_source_get_boolean (PolkitBackendConfigSource *source,
- const gchar *group,
- const gchar *key,
- GError **error);
-gdouble polkit_backend_config_source_get_double (PolkitBackendConfigSource *source,
- const gchar *group,
- const gchar *key,
- GError **error);
-gchar *polkit_backend_config_source_get_string (PolkitBackendConfigSource *source,
- const gchar *group,
- const gchar *key,
- GError **error);
-gchar **polkit_backend_config_source_get_string_list (PolkitBackendConfigSource *source,
- const gchar *group,
- const gchar *key,
- GError **error);
-
-G_END_DECLS
-
-#endif /* __POLKIT_BACKEND_CONFIG_SOURCE_H */
-
diff --git a/src/polkitbackend/polkitbackendinteractiveauthority.c b/src/polkitbackend/polkitbackendinteractiveauthority.c
index 967b764..ccfd608 100644
--- a/src/polkitbackend/polkitbackendinteractiveauthority.c
+++ b/src/polkitbackend/polkitbackendinteractiveauthority.c
@@ -36,7 +36,6 @@
#include "polkitbackendinteractiveauthority.h"
#include "polkitbackendactionpool.h"
#include "polkitbackendsessionmonitor.h"
-#include "polkitbackendconfigsource.h"
#include <polkit/polkitprivate.h>
--
2.12.1

View File

@ -1,19 +1,27 @@
%global _default_patch_fuzz 2
# Only enable if using patches that touches configure.ac,
# Makefile.am or other build system related files
#
#define enable_autoreconf 1
%define enable_autoreconf 1
Summary: An authorization framework
Name: polkit
Version: 0.113
Release: 7%{?dist}
Release: 8%{?dist}
License: LGPLv2+
URL: http://www.freedesktop.org/wiki/Software/polkit
Source0: http://www.freedesktop.org/software/polkit/releases/%{name}-%{version}.tar.gz
Source1: http://www.freedesktop.org/software/polkit/releases/%{name}-%{version}.tar.gz.sign
# https://bugs.freedesktop.org/show_bug.cgi?id=99741
Patch0: polkit-0.113-agent-leaks.patch
Group: System Environment/Libraries
Patch1: polkit-remove-polkitbackendconfigsource.-ch.patch
Patch2: polkit-mozjs24.patch
Patch3: polkit-build-Pull-in-GCC-warning-infra-from-ostree.patch
# https://lists.freedesktop.org/archives/polkit-devel/2017-March/000527.html
Patch4: polkit-mozjs38.patch
BuildRequires: glib2-devel >= 2.30.0
BuildRequires: expat-devel
BuildRequires: pam-devel
@ -21,7 +29,7 @@ BuildRequires: gtk-doc
BuildRequires: intltool
BuildRequires: gobject-introspection-devel
BuildRequires: systemd, systemd-devel
BuildRequires: mozjs17-devel
BuildRequires: mozjs38-devel
%if 0%{?enable_autoreconf}
BuildRequires: autoconf
@ -37,19 +45,6 @@ Requires(post): /sbin/ldconfig, systemd
Requires(preun): systemd
Requires(postun): /sbin/ldconfig, systemd
Obsoletes: PolicyKit <= 0.10
Provides: PolicyKit = 0.11
# polkit saw some API/ABI changes from 0.96 to 0.97 so require a
# sufficiently new polkit-gnome package
Conflicts: polkit-gnome < 0.97
Obsoletes: polkit-desktop-policy < 0.103
Provides: polkit-desktop-policy = 0.103
Obsoletes: polkit-js-engine < 0.110-4
Provides: polkit-js-engine = %{version}-%{release}
# when -libs was split out, handle multilib upgrade path -- rex
Obsoletes: polkit < 0.113-3
@ -64,8 +59,6 @@ Group: Development/Libraries
Requires: %{name}-libs%{?_isa} = %{version}-%{release}
Requires: %name-docs = %{version}-%{release}
Requires: glib2-devel
Obsoletes: PolicyKit-devel <= 0.10
Provides: PolicyKit-devel = 0.11
%description devel
Development files for polkit.
@ -74,8 +67,6 @@ Development files for polkit.
Summary: Development documentation for polkit
Group: Development/Libraries
Requires: %name-devel = %{version}-%{release}
Obsoletes: PolicyKit-docs <= 0.10
Provides: PolicyKit-docs = 0.11
BuildArch: noarch
%description docs
@ -92,26 +83,28 @@ Libraries files for polkit.
%prep
%setup -q
%patch0 -p1 -b .agent-leaks
%patch1 -p1 -b .rem
%patch2 -p1 -b .js24
%patch3 -p1 -b .ost
%patch4 -p1 -b .js38
%build
%if 0%{?enable_autoreconf}
autoreconf -i
autoreconf -vif
%endif
# we can't use _hardened_build here, see
# https://bugzilla.redhat.com/show_bug.cgi?id=962005
export CFLAGS='-fPIC %optflags'
export LDFLAGS='-pie -Wl,-z,now -Wl,-z,relro'
%configure --enable-gtk-doc \
--disable-static \
--enable-introspection \
--disable-examples \
--enable-libsystemd-login=yes --with-mozjs=mozjs-17.0
make V=1
make %{?_smp_mflags} V=1
%install
make install DESTDIR=$RPM_BUILD_ROOT INSTALL='install -p'
make install DESTDIR=%{buildroot} INSTALL='install -p'
rm -f $RPM_BUILD_ROOT%{_libdir}/*.la
# Remove libtool archives and static libs
find %{buildroot} -type f -name "*.la" -delete
%find_lang polkit-1
@ -133,8 +126,7 @@ exit 0
%systemd_postun_with_restart polkit.service
%files -f polkit-1.lang
%defattr(-,root,root,-)
%doc COPYING NEWS README
%doc NEWS README
%{_datadir}/man/man1/*
%{_datadir}/man/man8/*
%{_datadir}/dbus-1/system-services/*
@ -159,24 +151,30 @@ exit 0
%attr(4755,root,root) %{_prefix}/lib/polkit-1/polkit-agent-helper-1
%files devel
%defattr(-,root,root,-)
%{_libdir}/lib*.so
%{_libdir}/pkgconfig/*.pc
%{_datadir}/gir-1.0/*.gir
%{_includedir}/*
%files docs
%defattr(-,root,root,-)
%{_datadir}/gtk-doc
%post libs -p /sbin/ldconfig
%postun libs -p /sbin/ldconfig
%files libs
%{!?_licensedir:%global license %%doc}
%license COPYING
%{_libdir}/lib*.so.*
%{_libdir}/girepository-1.0/*.typelib
%changelog
* Thu Mar 30 2017 Peter Robinson <pbrobinson@fedoraproject.org> 0.113-8
- Use %%license, license needs to be in -libs as it's the only guaranteed installed package
- Move to mozjs38
- Other upstream fixes
- Spec cleanups
* Mon Feb 13 2017 Miloslav Trmač <mitr@redhat.com> - 0.113-7
- Fix memory leaks when calling authentication agents
Resolves: #1380166