diff options
author | dec05eba <dec05eba@protonmail.com> | 2025-02-22 17:57:10 +0100 |
---|---|---|
committer | dec05eba <dec05eba@protonmail.com> | 2025-02-22 17:57:10 +0100 |
commit | 8c86bf1c3da587ed8657e2744a6d6e3af21406da (patch) | |
tree | 84c75cf50d8b83d5ffabbc2f72dfef4f15b034e1 | |
parent | fd92a55ac3888ab9266c927c491558cd60d59b99 (diff) |
-rw-r--r-- | main.c | 35 |
1 files changed, 28 insertions, 7 deletions
@@ -144,7 +144,7 @@ static bool set_gsr_files_set_permissions_and_capabilities(const char *kms_serve } /* |gsr_global_hotkeys_local_filepath| can be NULL */ -static bool setup_local_gsr_files(const char *user_homepath, const char *kms_server_proxy_local_filepath) { +static bool setup_local_gsr_files(const char *user_homepath, const char *kms_server_proxy_local_filepath, const char *kms_server_proxy_home) { if(!create_local_kms_server_proxy_directory(user_homepath)) { fprintf(stderr, "Error: failed to create ~/.local/share/gpu-screen-recorder directory\n"); return false; @@ -155,6 +155,11 @@ static bool setup_local_gsr_files(const char *user_homepath, const char *kms_ser return false; } + if(!copy_file_atomic(KMS_SERVER_PROXY_FILEPATH, kms_server_proxy_home)) { + fprintf(stderr, "Error: failed to copy kms-server-proxy to %s\n", kms_server_proxy_home); + return false; + } + return true; } @@ -175,17 +180,25 @@ static int setup_gsr_ui(const char *user_homepath) { /* Update kms-server-proxy-N to kms-server-proxy-N+1 on update (update that needs to run before this program launches itself) */ snprintf(kms_server_proxy_local_filepath, sizeof(kms_server_proxy_local_filepath), "%s/.local/share/gpu-screen-recorder/kms-server-proxy-2", user_homepath); + /* Weird-ass distros like openSUSE only allow pkexec for files in $HOME!!! */ + char kms_server_proxy_home[PATH_MAX]; + snprintf(kms_server_proxy_home, sizeof(kms_server_proxy_home), "%s/kms-server-proxy", user_homepath); + if(geteuid() == 0) { /* is current user root? */ + remove(kms_server_proxy_home); if(!set_gsr_files_set_permissions_and_capabilities(kms_server_proxy_local_filepath)) return 1; return 0; } else { - if(!setup_local_gsr_files(user_homepath, kms_server_proxy_local_filepath)) + if(!setup_local_gsr_files(user_homepath, kms_server_proxy_local_filepath, kms_server_proxy_home)) return 1; - const char *args[] = { "pkexec", kms_server_proxy_local_filepath, "setup-gsr-ui", user_homepath, NULL }; - return execvp(args[0], (char *const*)args); + const char *args[] = { "pkexec", kms_server_proxy_home, "setup-gsr-ui", user_homepath, NULL }; + const int result = execvp(args[0], (char *const*)args); + perror("pkexec"); + remove(kms_server_proxy_home); + return result; } } @@ -200,6 +213,10 @@ static int launch_gsr_kms_server(const char *initial_socket_path, const char *ca /* Update kms-server-proxy-N to kms-server-proxy-N+1 on update (update that needs to run before this program launches itself) */ snprintf(kms_server_proxy_local_filepath, sizeof(kms_server_proxy_local_filepath), "%s/.local/share/gpu-screen-recorder/kms-server-proxy-2", user_homepath); + /* Weird-ass distros like openSUSE only allow pkexec for files in $HOME!!! */ + char kms_server_proxy_home[PATH_MAX]; + snprintf(kms_server_proxy_home, sizeof(kms_server_proxy_home), "%s/kms-server-proxy", user_homepath); + if(file_has_sys_admin_capability(kms_server_proxy_local_filepath)) { /* Need to resolve kms_server_proxy_local_filepath because /home can be a symlink to another location */ char kms_server_proxy_local_filepath_full[PATH_MAX]; @@ -225,17 +242,21 @@ static int launch_gsr_kms_server(const char *initial_socket_path, const char *ca const char *args[] = { GSR_KMS_SERVER_FILEPATH, initial_socket_path, card_path, NULL }; return execvp(args[0], (char *const*)args); } else if(geteuid() == 0) { /* is current user root? */ + remove(kms_server_proxy_home); if(!set_gsr_files_set_permissions_and_capabilities(kms_server_proxy_local_filepath)) return 1; const char *args[] = { GSR_KMS_SERVER_FILEPATH, initial_socket_path, card_path, NULL }; return execv(args[0], (char *const*)args); } else { - if(!setup_local_gsr_files(user_homepath, kms_server_proxy_local_filepath)) + if(!setup_local_gsr_files(user_homepath, kms_server_proxy_local_filepath, kms_server_proxy_home)) return 1; - const char *args[] = { "pkexec", kms_server_proxy_local_filepath, initial_socket_path, card_path, user_homepath, NULL }; - return execvp(args[0], (char *const*)args); + const char *args[] = { "pkexec", kms_server_proxy_home, initial_socket_path, card_path, user_homepath, NULL }; + const int result = execvp(args[0], (char *const*)args); + perror("pkexec"); + remove(kms_server_proxy_home); + return result; } } |