diff options
author | lurchi <lurchi@strangeplace.net> | 2019-06-29 12:56:33 +0200 |
---|---|---|
committer | lurchi <lurchi@strangeplace.net> | 2019-06-29 12:56:33 +0200 |
commit | 8073ee2c2c7d76447790907e1e9af099c5011d5b (patch) | |
tree | ff38aec39565ae17ac21c01de10c59fc69246e8c /src | |
parent | dec6cf00dfa65bf1607c0cfcd80f2170d533b02b (diff) | |
download | gnunet-8073ee2c2c7d76447790907e1e9af099c5011d5b.tar.gz gnunet-8073ee2c2c7d76447790907e1e9af099c5011d5b.zip |
introduce GNUNET_OS_get_suid_binary_path
Diffstat (limited to 'src')
-rw-r--r-- | src/include/gnunet_os_lib.h | 17 | ||||
-rw-r--r-- | src/util/os_installation.c | 48 |
2 files changed, 65 insertions, 0 deletions
diff --git a/src/include/gnunet_os_lib.h b/src/include/gnunet_os_lib.h index 285dfb68d..6eb4ce5eb 100644 --- a/src/include/gnunet_os_lib.h +++ b/src/include/gnunet_os_lib.h | |||
@@ -318,6 +318,23 @@ GNUNET_OS_get_libexec_binary_path (const char *progname); | |||
318 | 318 | ||
319 | 319 | ||
320 | /** | 320 | /** |
321 | * Given the name of a helper, service or daemon binary construct the full | ||
322 | * path to the binary using the SUID_BINARY_PATH in the PATHS section of the | ||
323 | * configuration. If that option is not present, fall back to | ||
324 | * GNUNET_OS_get_libexec_binary_path. If @a progname is an absolute path, a | ||
325 | * copy of this path is returned. | ||
326 | * | ||
327 | * @param cfg configuration to inspect | ||
328 | * @param progname name of the binary | ||
329 | * @return full path to the binary, if possible, a copy of @a progname | ||
330 | * otherwise | ||
331 | */ | ||
332 | char * | ||
333 | GNUNET_OS_get_suid_binary_path (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
334 | const char *progname); | ||
335 | |||
336 | |||
337 | /** | ||
321 | * Callback function invoked for each interface found. | 338 | * Callback function invoked for each interface found. |
322 | * | 339 | * |
323 | * @param cls closure | 340 | * @param cls closure |
diff --git a/src/util/os_installation.c b/src/util/os_installation.c index f2d24f85e..e0568e6dd 100644 --- a/src/util/os_installation.c +++ b/src/util/os_installation.c | |||
@@ -805,6 +805,54 @@ GNUNET_OS_get_libexec_binary_path (const char *progname) | |||
805 | 805 | ||
806 | 806 | ||
807 | /** | 807 | /** |
808 | * Given the name of a helper, service or daemon binary construct the full | ||
809 | * path to the binary using the SUID_BINARY_PATH in the PATHS section of the | ||
810 | * configuration. If that option is not present, fall back to | ||
811 | * GNUNET_OS_get_libexec_binary_path. If @a progname is an absolute path, a | ||
812 | * copy of this path is returned. | ||
813 | * | ||
814 | * @param cfg configuration to inspect | ||
815 | * @param progname name of the binary | ||
816 | * @return full path to the binary, if possible, a copy of @a progname | ||
817 | * otherwise | ||
818 | */ | ||
819 | char * | ||
820 | GNUNET_OS_get_suid_binary_path (const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
821 | const char *progname) | ||
822 | { | ||
823 | static const char *cache; | ||
824 | char *binary = NULL; | ||
825 | char *path = NULL; | ||
826 | size_t path_len; | ||
827 | |||
828 | if (GNUNET_YES == | ||
829 | GNUNET_STRINGS_path_is_absolute (progname, | ||
830 | GNUNET_NO, | ||
831 | NULL, NULL)) | ||
832 | { | ||
833 | return GNUNET_strdup (progname); | ||
834 | } | ||
835 | if (NULL != cache) | ||
836 | path = cache; | ||
837 | else | ||
838 | GNUNET_CONFIGURATION_get_value_string (cfg, | ||
839 | "PATHS", | ||
840 | "SUID_BINARY_PATH", | ||
841 | &path); | ||
842 | if (NULL == path) | ||
843 | return GNUNET_OS_get_libexec_binary_path (progname); | ||
844 | path_len = strlen (path); | ||
845 | GNUNET_asprintf (&binary, | ||
846 | "%s%s%s", | ||
847 | path, | ||
848 | (path[path_len - 1] == DIR_SEPARATOR) ? "" : DIR_SEPARATOR_STR, | ||
849 | progname); | ||
850 | cache = path; | ||
851 | return binary; | ||
852 | } | ||
853 | |||
854 | |||
855 | /** | ||
808 | * Check whether an executable exists and possibly if the suid bit is | 856 | * Check whether an executable exists and possibly if the suid bit is |
809 | * set on the file. Attempts to find the file using the current PATH | 857 | * set on the file. Attempts to find the file using the current PATH |
810 | * environment variable as a search path. | 858 | * environment variable as a search path. |