diff options
Diffstat (limited to 'kms')
-rw-r--r-- | kms/client/kms_client.c | 45 | ||||
-rw-r--r-- | kms/server/kms_server.c | 2 | ||||
-rw-r--r-- | kms/server/project.conf | 3 |
3 files changed, 44 insertions, 6 deletions
diff --git a/kms/client/kms_client.c b/kms/client/kms_client.c index 587dda3..ff8a3d5 100644 --- a/kms/client/kms_client.c +++ b/kms/client/kms_client.c @@ -105,6 +105,40 @@ static void strncpy_safe(char *dst, const char *src, int len) { dst[min_len] = '\0'; } +static bool find_program_in_path(const char *program_name, char *filepath, int filepath_len) { + const char *path = getenv("PATH"); + if(!path) + return false; + + int program_name_len = strlen(program_name); + const char *end = path + strlen(path); + while(path != end) { + const char *part_end = strchr(path, ':'); + const char *next = part_end; + if(part_end) { + next = part_end + 1; + } else { + part_end = end; + next = end; + } + + int len = part_end - path; + if(len + 1 + program_name_len < filepath_len) { + memcpy(filepath, path, len); + filepath[len] = '/'; + memcpy(filepath + len + 1, program_name, program_name_len); + filepath[len + 1 + program_name_len] = '\0'; + + if(access(filepath, F_OK) == 0) + return true; + } + + path = next; + } + + return false; +} + int gsr_kms_client_init(gsr_kms_client *self, const char *card_path) { self->kms_server_pid = -1; self->socket_fd = -1; @@ -118,11 +152,12 @@ int gsr_kms_client_init(gsr_kms_client *self, const char *card_path) { return -1; } - // This doesn't work on nixos, but we dont want to use $PATH because we want to make this as safe as possible by running pkexec - // on a path that only root can modify. If we use "gsr-kms-server" instead then $PATH can be modified in ~/.bashrc for example - // which will overwrite the path to gsr-kms-server and the user can end up running a malicious program that pretends to be gsr-kms-server. - // If there is a safe way to do this on nixos, then please tell me; or use gpu-screen-recorder flatpak instead. - const char *server_filepath = "/usr/bin/gsr-kms-server"; + char server_filepath[PATH_MAX]; + if(!find_program_in_path("gsr-kms-server", server_filepath, sizeof(server_filepath))) { + fprintf(stderr, "gsr error: gsr_kms_client_init: gsr-kms-server is not installed\n"); + return -1; + } + bool has_perm = 0; const bool inside_flatpak = getenv("FLATPAK_ID") != NULL; if(!inside_flatpak) { diff --git a/kms/server/kms_server.c b/kms/server/kms_server.c index a15eb2b..dc24224 100644 --- a/kms/server/kms_server.c +++ b/kms/server/kms_server.c @@ -306,7 +306,7 @@ static void strncpy_safe(char *dst, const char *src, int len) { int main(int argc, char **argv) { if(argc != 3) { - fprintf(stderr, "usage: kms_server <domain_socket_path> <card_path>\n"); + fprintf(stderr, "usage: gsr-kms-server <domain_socket_path> <card_path>\n"); return 1; } diff --git a/kms/server/project.conf b/kms/server/project.conf index cf863c1..26a1947 100644 --- a/kms/server/project.conf +++ b/kms/server/project.conf @@ -4,5 +4,8 @@ type = "executable" version = "1.0.0" platforms = ["posix"] +[config] +error_on_warning = "true" + [dependencies] libdrm = ">=2" |