aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore4
-rw-r--r--README.md6
-rwxr-xr-xbuild.sh2
-rw-r--r--main.c15
4 files changed, 18 insertions, 9 deletions
diff --git a/.gitignore b/.gitignore
index b8743f7..2b5a920 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,3 @@
-kms-server-proxy
+kms-server-proxy*
depends/libcap/libcap/*.o
-depends/libcap/libcap/libcap.a \ No newline at end of file
+depends/libcap/libcap/libcap.a
diff --git a/README.md b/README.md
index 6f18154..a927133 100644
--- a/README.md
+++ b/README.md
@@ -1,10 +1,14 @@
-This program fixes password prompt spam in GPU Screen Recorder when used from flatpak.
+This program fixes password prompt spam in GPU Screen Recorder when used from flatpak and keep removing the password prompt spam even after updating GPU Screen Recorder flatpak.
This program is meant to be ran with flatpak-spawn --host. This program is not meant to be run by the user and is automatically launched from GPU Screen Recorder flatpak.
When this program is first run, it executes itself with pkexec and in that case it sets CAP_SYS_ADMIN capability on itself
after copying self to ~/.local/share/gpu-screen-recorder and launches gsr-kms-server (in flatpak location).
When this program is run after that it will check if its run from ~/.local/share/gpu-screen-recorder or launch that and it will see that the program has CAP_SYS_ADMIN capability
and will launch gsr-kms-server (in flatpak location). This program also sets CAP_SYS_ADMIN on gsr-kms-server in the flatpak app directory.
+Fallbacks are used. For example if it fails to create the file in ~/.local/share/gpu-screen-recorder and set capability on that then the gsr-kms-server is used directly,
+which will keep its capabilities until GPU Screen Recorder flatpak is updated. If setting capabilities on gsr-kms-server also fails then gsr-kms-server is launched with pkexec,
+so a password prompt will show up.
+
The reason all of this is needed is because `setcap cap_sys_admin+ep gsr-kms-server` can't be done in the flatpak because of sandboxing so this is only done when you install GPU Screen Recorder
from source/aur to workaround that limitation.
diff --git a/build.sh b/build.sh
index af8729e..2f8c54d 100755
--- a/build.sh
+++ b/build.sh
@@ -6,4 +6,4 @@ cd "$script_dir"
cd depends/libcap/libcap
make SHARED=no GOLANG=no PTHREADS=no
cd ../../../
-gcc main.c -o kms-server-proxy -fstack-protector-all -O3 -s -flto -Wall -Wextra -Werror -DNDEBUG -static -static-libgcc -I./depends/libcap/libcap/include ./depends/libcap/libcap/libcap.a
+gcc main.c -o kms-server-proxy-1 -fstack-protector-all -O3 -s -flto -Wall -Wextra -Werror -DNDEBUG -static -static-libgcc -I./depends/libcap/libcap/include ./depends/libcap/libcap/libcap.a
diff --git a/main.c b/main.c
index c9f21c8..e59691f 100644
--- a/main.c
+++ b/main.c
@@ -9,12 +9,17 @@
#include <sys/sendfile.h>
#include <sys/capability.h>
-static int get_self_filepath(char *buffer, size_t size) {
- ssize_t bytes_written = readlink("/proc/self/exe", buffer, size - 1);
+static int get_self_filepath(char *buffer) {
+ char self_path[PATH_MAX];
+
+ ssize_t bytes_written = readlink("/proc/self/exe", self_path, sizeof(self_path) - 1);
if(bytes_written == -1)
return 0;
- buffer[bytes_written] = '\0';
+ self_path[bytes_written] = '\0';
+ if(!realpath(self_path, buffer))
+ return 0;
+
return 1;
}
@@ -115,11 +120,11 @@ int main(int argc, char **argv) {
const char *user_homepath = argv[3];
char self_path[PATH_MAX];
- if(!get_self_filepath(self_path, sizeof(self_path)))
+ if(!get_self_filepath(self_path))
return 1;
char kms_server_proxy_local_filepath[PATH_MAX];
- snprintf(kms_server_proxy_local_filepath, sizeof(kms_server_proxy_local_filepath), "%s/.local/share/gpu-screen-recorder/kms-server-proxy", user_homepath);
+ snprintf(kms_server_proxy_local_filepath, sizeof(kms_server_proxy_local_filepath), "%s/.local/share/gpu-screen-recorder/kms-server-proxy-1", user_homepath);
if(file_has_sys_admin_capability(gsr_kms_server_filepath)) {
const char *args[] = { gsr_kms_server_filepath, initial_socket_path, card_path, NULL };