diff options
author | dec05eba <dec05eba@protonmail.com> | 2024-04-06 15:08:28 +0200 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2024-04-06 15:08:28 +0200 |
commit | 9776cc4e7e9037bde5d5ece69f7d1f959da4bfd5 (patch) | |
tree | 2ab9da26edc1410a0141f99a0d5b5932c4cadd87 | |
parent | 9b5c4b5a1e68843ed187ca0dcec83dd8a4a83e18 (diff) |
Resolve /proc/self/exe fullpath
-rw-r--r-- | .gitignore | 4 | ||||
-rw-r--r-- | README.md | 6 | ||||
-rwxr-xr-x | build.sh | 2 | ||||
-rw-r--r-- | main.c | 15 |
4 files changed, 18 insertions, 9 deletions
@@ -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 @@ -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. @@ -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 @@ -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 }; |