From 4974f9c886b6c06d92689e6889c3df70d53f75d2d238c135a9583aa838e6e570 Mon Sep 17 00:00:00 2001 From: "R. Tyler Croy" Date: Sun, 2 Feb 2020 21:11:33 +0000 Subject: [PATCH 1/2] - Upgrade to the recently released 0.5.1, which includes previously applied patches OBS-URL: https://build.opensuse.org/package/show/utilities/brightnessctl?expand=0&rev=10 --- 0.4.tar.gz | 3 - 0.5.1.tar.gz | 3 + ...-inconsistency-in-README-thanks-AJGQ.patch | 26 --- ...ort-the-new-SetBrightness-logind-API.patch | 155 ------------------ ...ake-the-use-of-SetBrightness-dynamic.patch | 115 ------------- ...suid-permissions-when-logind-is-used.patch | 41 ----- brightnessctl.changes | 6 + brightnessctl.spec | 21 +-- 8 files changed, 18 insertions(+), 352 deletions(-) delete mode 100644 0.4.tar.gz create mode 100644 0.5.1.tar.gz delete mode 100644 0001-Fixed-inconsistency-in-README-thanks-AJGQ.patch delete mode 100644 0002-Support-the-new-SetBrightness-logind-API.patch delete mode 100644 0003-Make-the-use-of-SetBrightness-dynamic.patch delete mode 100644 0004-Use-non-suid-permissions-when-logind-is-used.patch diff --git a/0.4.tar.gz b/0.4.tar.gz deleted file mode 100644 index ea33589..0000000 --- a/0.4.tar.gz +++ /dev/null @@ -1,3 +0,0 @@ -version https://git-lfs.github.com/spec/v1 -oid sha256:ac86de0df8dcfd60a415465daabca283192ceb8de6c53b8844e628709ccd0cef -size 7170 diff --git a/0.5.1.tar.gz b/0.5.1.tar.gz new file mode 100644 index 0000000..bdc3393 --- /dev/null +++ b/0.5.1.tar.gz @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a68869e23f56ac4f2e28f1783002810ddbf10f95e1af9b48b2912fb169f46994 +size 8284 diff --git a/0001-Fixed-inconsistency-in-README-thanks-AJGQ.patch b/0001-Fixed-inconsistency-in-README-thanks-AJGQ.patch deleted file mode 100644 index e46c695..0000000 --- a/0001-Fixed-inconsistency-in-README-thanks-AJGQ.patch +++ /dev/null @@ -1,26 +0,0 @@ -From 5bee979cd84347369027b45b5df5d917b3231ab6 Mon Sep 17 00:00:00 2001 -From: Hummer12007 -Date: Fri, 2 Aug 2019 15:23:38 +0300 -Subject: [PATCH 1/4] Fixed inconsistency in README (thanks @AJGQ) - -Closes #28 ---- - README.md | 2 +- - 1 file changed, 1 insertion(+), 1 deletion(-) - -diff --git a/README.md b/README.md -index 92b65b0..0042bb4 100644 ---- a/README.md -+++ b/README.md -@@ -23,7 +23,7 @@ Modifying brightness requires write permissions for device files. `brightnessctl - - 2) installing `brightnessctl` as a suid binary. - --The behavior is controlled by the `INSTALL_UDEV_RULES` flag (setting it to `1` installs the udev rules, `0` is the default value). -+The behavior is controlled by the `INSTALL_UDEV_RULES` flag (setting it to `1` installs the udev rules, it is the default value). - - ## Usage - ``` --- -2.25.0 - diff --git a/0002-Support-the-new-SetBrightness-logind-API.patch b/0002-Support-the-new-SetBrightness-logind-API.patch deleted file mode 100644 index e4647ac..0000000 --- a/0002-Support-the-new-SetBrightness-logind-API.patch +++ /dev/null @@ -1,155 +0,0 @@ -From d8dfd8ed49762922e9ff8ebd19b2607fc6cd60aa Mon Sep 17 00:00:00 2001 -From: Antoine Damhet -Date: Tue, 10 Sep 2019 00:24:05 +0200 -Subject: [PATCH 2/4] Support the new `SetBrightness` logind API - -This API from `org.freedesktop.login1.Session` allows an unprivileged -user with an active session to change its own backlight. - -Systemd >= v243 is needed. - -Signed-off-by: Antoine Damhet ---- - Makefile | 6 ++++++ - README.md | 6 +++++- - brightnessctl.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++- - 3 files changed, 58 insertions(+), 2 deletions(-) - -diff --git a/Makefile b/Makefile -index f324efd..22ff475 100644 ---- a/Makefile -+++ b/Makefile -@@ -11,6 +11,12 @@ INSTALL_UDEV_RULES = 1 - INSTALL_UDEV_1 = install_udev_rules - UDEVDIR ?= /lib/udev/rules.d - -+ifdef ENABLE_SYSTEMD -+ CFLAGS += ${shell pkg-config --cflags libsystemd} -+ LDLIBS += ${shell pkg-config --libs libsystemd} -+ CPPFLAGS += -DENABLE_SYSTEMD -+endif -+ - MODE_0 = 4711 - MODE_1 = 0755 - MODE = ${MODE_${INSTALL_UDEV_RULES}} -diff --git a/README.md b/README.md -index 0042bb4..b57d3df 100644 ---- a/README.md -+++ b/README.md -@@ -17,14 +17,18 @@ One can build and install the program using `make install`. Consult the Makefile - - ## Permissions - --Modifying brightness requires write permissions for device files. `brightnessctl` accomplishes this (without using `sudo`/`su`/etc.) by either of the following means: -+Modifying brightness requires write permissions for device files or systemd support. `brightnessctl` accomplishes this (without using `sudo`/`su`/etc.) by either of the following means: - - 1) installing relevant udev rules to add permissions to backlight class devices for users in `video` and leds for users in `input`. (done by default) - - 2) installing `brightnessctl` as a suid binary. - -+3) using the `systemd-logind` API. -+ - The behavior is controlled by the `INSTALL_UDEV_RULES` flag (setting it to `1` installs the udev rules, it is the default value). - -+The systemd support (since v243) is controlled by the `ENABLE_SYSTEMD` flag (in that case it is recommended to set `INSTALL_UDEV_RULES` to 0). -+ - ## Usage - ``` - Usage: brightnessctl [options] [operation] [value] -diff --git a/brightnessctl.c b/brightnessctl.c -index eb3ce3c..3fec6ec 100644 ---- a/brightnessctl.c -+++ b/brightnessctl.c -@@ -14,6 +14,10 @@ - #include - #include - -+#ifdef ENABLE_SYSTEMD -+# include -+#endif -+ - static char *path = "/sys/class"; - static char *classes[] = { "backlight", "leds", NULL }; - -@@ -101,7 +105,12 @@ int main(int argc, char **argv) { - struct device *devs[255]; - struct device *dev; - struct utsname name; -- char *dev_name, *file_path, *sys_run_dir; -+ char *dev_name, *sys_run_dir; -+ -+#ifndef ENABLE_SYSTEMD -+ char *file_path; -+#endif -+ - int n, c, phelp = 0; - if (uname(&name)) - fail("Unable to determine current OS. Exiting!\n"); -@@ -194,6 +203,8 @@ int main(int argc, char **argv) { - fail("Invalid value given"); - if (!(dev = find_device(devs, dev_name))) - fail("Device '%s' not found.\n", dev_name); -+ -+#ifndef ENABLE_SYSTEMD - if ((p.operation == SET || p.restore) && !p.pretend && geteuid()) { - errno = 0; - file_path = cat_with('/', path, dev->class, dev->id, "brightness"); -@@ -204,6 +215,8 @@ int main(int argc, char **argv) { - } - free(file_path); - } -+#endif -+ - if ((sys_run_dir = getenv("XDG_RUNTIME_DIR"))) - run_dir = dir_child(sys_run_dir, "brightnessctl"); - if (p.save) -@@ -325,6 +338,37 @@ apply: - d->curr_brightness = new; - } - -+#ifdef ENABLE_SYSTEMD -+ -+bool write_device(struct device *d) { -+ sd_bus *bus = NULL; -+ int r = sd_bus_default_system(&bus); -+ if (r < 0) { -+ fprintf(stderr, "Can't connect to system bus: %s\n", strerror(-r)); -+ return false; -+ } -+ -+ r = sd_bus_call_method(bus, -+ "org.freedesktop.login1", -+ "/org/freedesktop/login1/session/auto", -+ "org.freedesktop.login1.Session", -+ "SetBrightness", -+ NULL, -+ NULL, -+ "ssu", -+ d->class, -+ d->id, -+ d->curr_brightness); -+ if (r < 0) -+ fprintf(stderr, "Failed to set brightness: %s\n", strerror(-r)); -+ -+ sd_bus_unref(bus); -+ -+ return r >= 0; -+} -+ -+#else -+ - bool write_device(struct device *d) { - FILE *f; - char c[16]; -@@ -348,6 +392,8 @@ fail: - return !errno; - } - -+#endif -+ - bool read_device(struct device *d, char *class, char *id) { - DIR *dirp; - FILE *f; --- -2.25.0 - diff --git a/0003-Make-the-use-of-SetBrightness-dynamic.patch b/0003-Make-the-use-of-SetBrightness-dynamic.patch deleted file mode 100644 index 82ce159..0000000 --- a/0003-Make-the-use-of-SetBrightness-dynamic.patch +++ /dev/null @@ -1,115 +0,0 @@ -From 658d5d058cb03a94269f8eec5b7ac4f1e8c43880 Mon Sep 17 00:00:00 2001 -From: Antoine Damhet -Date: Tue, 10 Sep 2019 08:52:59 +0200 -Subject: [PATCH 3/4] Make the use of `SetBrightness` dynamic - -It will only be used if the user do not have the permission to directly -write to the backlight device. - -Signed-off-by: Antoine Damhet ---- - brightnessctl.c | 31 +++++++++++++++---------------- - 1 file changed, 15 insertions(+), 16 deletions(-) - -diff --git a/brightnessctl.c b/brightnessctl.c -index 3fec6ec..576e591 100644 ---- a/brightnessctl.c -+++ b/brightnessctl.c -@@ -38,7 +38,7 @@ static char *class_path(char *); - static void apply_value(struct device *, struct value *); - static int apply_operation(struct device *, enum operation, struct value *); - static bool parse_value(struct value *, char *); --static bool write_device(struct device *); -+static bool do_write_device(struct device *); - static bool read_device(struct device *, char *, char *); - static int read_class(struct device **, char *); - static int read_devices(struct device **); -@@ -50,6 +50,10 @@ static bool restore_device_data(struct device *); - static bool ensure_dir(char *); - #define ensure_run_dir() ensure_dir(run_dir) - -+#ifdef ENABLE_SYSTEMD -+static bool logind_set_brightness(struct device *); -+#endif -+ - struct device { - char *class; - char *id; -@@ -101,16 +105,13 @@ static const struct option options[] = { - {NULL,} - }; - -+static bool (*write_device)(struct device *) = do_write_device; -+ - int main(int argc, char **argv) { - struct device *devs[255]; - struct device *dev; - struct utsname name; -- char *dev_name, *sys_run_dir; -- --#ifndef ENABLE_SYSTEMD -- char *file_path; --#endif -- -+ char *dev_name, *file_path, *sys_run_dir; - int n, c, phelp = 0; - if (uname(&name)) - fail("Unable to determine current OS. Exiting!\n"); -@@ -203,20 +204,20 @@ int main(int argc, char **argv) { - fail("Invalid value given"); - if (!(dev = find_device(devs, dev_name))) - fail("Device '%s' not found.\n", dev_name); -- --#ifndef ENABLE_SYSTEMD - if ((p.operation == SET || p.restore) && !p.pretend && geteuid()) { - errno = 0; - file_path = cat_with('/', path, dev->class, dev->id, "brightness"); - if (access(file_path, W_OK)) { -+#ifdef ENABLE_SYSTEMD -+ write_device = logind_set_brightness; -+#else - perror("Can't modify brightness"); - fail("\nYou should run this program with root privileges.\n" - "Alternatively, get write permissions for device files.\n"); -+#endif - } - free(file_path); - } --#endif -- - if ((sys_run_dir = getenv("XDG_RUNTIME_DIR"))) - run_dir = dir_child(sys_run_dir, "brightnessctl"); - if (p.save) -@@ -340,7 +341,7 @@ apply: - - #ifdef ENABLE_SYSTEMD - --bool write_device(struct device *d) { -+bool logind_set_brightness(struct device *d) { - sd_bus *bus = NULL; - int r = sd_bus_default_system(&bus); - if (r < 0) { -@@ -367,9 +368,9 @@ bool write_device(struct device *d) { - return r >= 0; - } - --#else -+#endif - --bool write_device(struct device *d) { -+bool do_write_device(struct device *d) { - FILE *f; - char c[16]; - size_t s = sprintf(c, "%u", d->curr_brightness); -@@ -392,8 +393,6 @@ fail: - return !errno; - } - --#endif -- - bool read_device(struct device *d, char *class, char *id) { - DIR *dirp; - FILE *f; --- -2.25.0 - diff --git a/0004-Use-non-suid-permissions-when-logind-is-used.patch b/0004-Use-non-suid-permissions-when-logind-is-used.patch deleted file mode 100644 index 205598c..0000000 --- a/0004-Use-non-suid-permissions-when-logind-is-used.patch +++ /dev/null @@ -1,41 +0,0 @@ -From 4e815152fb366972ca24ce17d3d25f337a3b01b9 Mon Sep 17 00:00:00 2001 -From: Christian Kellner -Date: Sun, 26 Jan 2020 13:15:40 +0100 -Subject: [PATCH 4/4] Use non-suid permissions when logind is used - -When systemd-logind and its D-Bus API is used to actual change the -brightness of devices the binary does not have to be suid, which is -desired for security reasons. ---- - Makefile | 9 +++++---- - 1 file changed, 5 insertions(+), 4 deletions(-) - -diff --git a/Makefile b/Makefile -index 22ff475..fcd746a 100644 ---- a/Makefile -+++ b/Makefile -@@ -11,16 +11,17 @@ INSTALL_UDEV_RULES = 1 - INSTALL_UDEV_1 = install_udev_rules - UDEVDIR ?= /lib/udev/rules.d - -+MODE_0 = 4711 -+MODE_1 = 0755 -+MODE = ${MODE_${INSTALL_UDEV_RULES}} -+ - ifdef ENABLE_SYSTEMD - CFLAGS += ${shell pkg-config --cflags libsystemd} - LDLIBS += ${shell pkg-config --libs libsystemd} - CPPFLAGS += -DENABLE_SYSTEMD -+ MODE = 0755 - endif - --MODE_0 = 4711 --MODE_1 = 0755 --MODE = ${MODE_${INSTALL_UDEV_RULES}} -- - all: brightnessctl brightnessctl.1 - - install: all ${INSTALL_UDEV_${INSTALL_UDEV_RULES}} --- -2.25.0 - diff --git a/brightnessctl.changes b/brightnessctl.changes index 9427069..b07afda 100644 --- a/brightnessctl.changes +++ b/brightnessctl.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Sun Feb 2 21:10:59 UTC 2020 - R. Tyler Croy + +- Upgrade to the recently released 0.5.1, which includes previously applied + patches + ------------------------------------------------------------------- Thu Jan 30 08:52:07 UTC 2020 - Dan Čermák diff --git a/brightnessctl.spec b/brightnessctl.spec index 5309037..55f8abf 100644 --- a/brightnessctl.spec +++ b/brightnessctl.spec @@ -25,20 +25,13 @@ %global use_logind 0 %endif Name: brightnessctl -Version: 0.4 +Version: 0.5.1 Release: 0 Summary: Tool to read and control device brightness License: MIT URL: https://github.com/Hummer12007/%{name} Source: %{URL}/archive/%{version}.tar.gz -# required to resolve cherry pick conflicts -# https://github.com/Hummer12007/brightnessctl/commit/aa6a71cd8206992a64269239f038dbf5f516e54a -Patch0: 0001-Fixed-inconsistency-in-README-thanks-AJGQ.patch -# https://github.com/Hummer12007/brightnessctl/pull/33 -Patch1: 0002-Support-the-new-SetBrightness-logind-API.patch -Patch2: 0003-Make-the-use-of-SetBrightness-dynamic.patch -# https://github.com/Hummer12007/brightnessctl/pull/41 -Patch3: 0004-Use-non-suid-permissions-when-logind-is-used.patch +PreReq: permissions BuildRequires: gcc BuildRequires: make %if %{use_logind} @@ -53,9 +46,6 @@ A utility to read and control the display brightness. %prep %autosetup -N -%if %{use_logind} -%autopatch -p1 -%endif %build %if %{use_logind} @@ -74,6 +64,13 @@ export CFLAGS="%{optflags}" %make_install UDEVDIR=%{_udevrulesdir} %endif +%post +%if 0%{?set_permissions:1} + %set_permissions %name +%else + %run_permissions +%endif + %files %doc README.md %license LICENSE From 1d7fbe810fd7b7c90cb28efb1ddcd7666ca902e9c75086a9eabb542f4f51bd39 Mon Sep 17 00:00:00 2001 From: "R. Tyler Croy" Date: Tue, 4 Feb 2020 03:20:03 +0000 Subject: [PATCH 2/2] Removed patches (adding this for the bot): 0001-Fixed-inconsistency-in-README-thanks-AJGQ.patch 0002-Support-the-new-SetBrightness-logind-API.patch 0003-Make-the-use-of-SetBrightness-dynamic.patch 0004-Use-non-suid-permissions-when-logind-is-used.patch OBS-URL: https://build.opensuse.org/package/show/utilities/brightnessctl?expand=0&rev=11 --- brightnessctl.changes | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/brightnessctl.changes b/brightnessctl.changes index b07afda..d086361 100644 --- a/brightnessctl.changes +++ b/brightnessctl.changes @@ -4,6 +4,13 @@ Sun Feb 2 21:10:59 UTC 2020 - R. Tyler Croy - Upgrade to the recently released 0.5.1, which includes previously applied patches +Removed patches (adding this for the bot): + + 0001-Fixed-inconsistency-in-README-thanks-AJGQ.patch + 0002-Support-the-new-SetBrightness-logind-API.patch + 0003-Make-the-use-of-SetBrightness-dynamic.patch + 0004-Use-non-suid-permissions-when-logind-is-used.patch + ------------------------------------------------------------------- Thu Jan 30 08:52:07 UTC 2020 - Dan Čermák