1From 6c8022392713955c5ae0061e22b50a16a1c2252a Mon Sep 17 00:00:00 2001 2From: Simon McVittie <smcv@collabora.com> 3Date: Thu, 15 Jul 2021 12:36:05 +0000 4Subject: [PATCH] Improve meson_post_install script 5 6[Retrieved from: 7https://gitlab.freedesktop.org/polkit/polkit/-/commit/6c8022392713955c5ae0061e22b50a16a1c2252a] 8Signed-off-by: Fabrice Fontaine <fontaine.fabrice@gmail.com> 9--- 10 .gitlab-ci.yml | 3 +-- 11 meson_post_install.py | 58 +++++++++++++++++++++++++++++++++++-------- 12 2 files changed, 49 insertions(+), 12 deletions(-) 13 14diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml 15index 8ac3e9f..6d0abb4 100644 16--- a/.gitlab-ci.yml 17+++ b/.gitlab-ci.yml 18@@ -26,8 +26,6 @@ build_stable: 19 before_script: 20 - dnf upgrade -y --nogpgcheck fedora-release fedora-repos* 21 - dnf update -y && dnf install -y $DEPENDENCIES 22- - getent group polkitd >/dev/null || groupadd -r polkitd 23- - getent passwd polkitd >/dev/null || useradd -r -g polkitd -d / -s /sbin/nologin -c "User for polkitd" polkitd 24 25 script: 26 - meson setup 27@@ -43,6 +41,7 @@ build_stable: 28 - meson compile -C builddir 29 - meson test -C builddir 30 - meson install -C builddir 31+ - DESTDIR=$(pwd)/DESTDIR meson install -C builddir 32 artifacts: 33 name: 'test logs' 34 when: 'always' 35diff --git a/meson_post_install.py b/meson_post_install.py 36index 0a0fccf..0ab7469 100644 37--- a/meson_post_install.py 38+++ b/meson_post_install.py 39@@ -1,20 +1,44 @@ 40 #!/usr/bin/env python3 41 42-import getpass 43 import os 44 import pwd 45 import sys 46 47+destdir = os.environ.get('DESTDIR') 48 prefix = os.environ['MESON_INSTALL_DESTDIR_PREFIX'] 49 50-bindir = os.path.join(prefix, sys.argv[1]) 51-pkgdatadir = os.path.join(prefix, sys.argv[2]) 52-pkglibdir = os.path.join(prefix, sys.argv[3]) 53-pkgsysconfdir = os.path.join(prefix, sys.argv[4]) 54+def destdir_path(p): 55+ if os.path.isabs(p): 56+ if destdir is None: 57+ return p 58+ else: 59+ return os.path.join(destdir, os.path.relpath(p, '/')) 60+ else: 61+ return os.path.join(prefix, p) 62 63-polkitd_uid = pwd.getpwnam(sys.argv[5]).pw_uid 64+bindir = destdir_path(sys.argv[1]) 65+pkgdatadir = destdir_path(sys.argv[2]) 66+pkglibdir = destdir_path(sys.argv[3]) 67+pkgsysconfdir = destdir_path(sys.argv[4]) 68+polkitd_user = sys.argv[5] 69 70-os.chmod(os.path.join(bindir, 'pkexec'), 0o4775) 71+try: 72+ polkitd_uid = pwd.getpwnam(polkitd_user).pw_uid 73+except KeyError: 74+ polkitd_uid = None 75+ 76+dst = os.path.join(bindir, 'pkexec') 77+ 78+if os.geteuid() == 0: 79+ os.chmod(dst, 0o4755) 80+ os.chown(dst, 0, -1) 81+else: 82+ print( 83+ 'Owner and mode of {} need to be setuid root (04755) after ' 84+ 'installation'.format( 85+ dst, 86+ ) 87+ ) 88 89 dst_dirs = [ 90 os.path.join(pkgsysconfdir, 'rules.d'), 91@@ -24,13 +48,27 @@ dst_dirs = [ 92 for dst in dst_dirs: 93 if not os.path.exists(dst): 94 os.makedirs(dst, mode=0o700) 95- if getpass.getuser() == "root": 96+ if os.geteuid() == 0 and polkitd_uid is not None: 97 os.chown(dst, polkitd_uid, -1) 98+ else: 99+ print( 100+ 'Owner of {} needs to be set to {} after installation'.format( 101+ dst, polkitd_user, 102+ ) 103+ ) 104 105 # polkit-agent-helper-1 need to be setuid root because it's used to 106 # authenticate not only the invoking user, but possibly also root 107 # and/or other users. 108 dst = os.path.join(pkglibdir, 'polkit-agent-helper-1') 109-os.chmod(dst, 0o4755) 110-if getpass.getuser() == "root": 111+ 112+if os.geteuid() == 0: 113+ os.chmod(dst, 0o4755) 114 os.chown(dst, 0, -1) 115+else: 116+ print( 117+ 'Owner and mode of {} need to be setuid root (04755) after ' 118+ 'installation'.format( 119+ dst, 120+ ) 121+ ) 122-- 123GitLab 124 125