diff options
Diffstat (limited to 'src/util/os_installation.c')
-rw-r--r-- | src/util/os_installation.c | 378 |
1 files changed, 171 insertions, 207 deletions
diff --git a/src/util/os_installation.c b/src/util/os_installation.c index f51bfd287..8dacd431d 100644 --- a/src/util/os_installation.c +++ b/src/util/os_installation.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -44,9 +44,14 @@ | |||
44 | #endif | 44 | #endif |
45 | 45 | ||
46 | 46 | ||
47 | #define LOG(kind,...) GNUNET_log_from (kind, "util-os-installation", __VA_ARGS__) | 47 | #define LOG(kind, ...) \ |
48 | GNUNET_log_from (kind, "util-os-installation", __VA_ARGS__) | ||
48 | 49 | ||
49 | #define LOG_STRERROR_FILE(kind,syscall,filename) GNUNET_log_from_strerror_file (kind, "util-os-installation", syscall, filename) | 50 | #define LOG_STRERROR_FILE(kind, syscall, filename) \ |
51 | GNUNET_log_from_strerror_file (kind, \ | ||
52 | "util-os-installation", \ | ||
53 | syscall, \ | ||
54 | filename) | ||
50 | 55 | ||
51 | 56 | ||
52 | /** | 57 | /** |
@@ -99,13 +104,13 @@ const struct GNUNET_OS_ProjectData * | |||
99 | GNUNET_OS_project_data_get () | 104 | GNUNET_OS_project_data_get () |
100 | { | 105 | { |
101 | if (0 == gettextinit) | 106 | if (0 == gettextinit) |
102 | { | 107 | { |
103 | char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); | 108 | char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); |
104 | if (NULL != path) | 109 | if (NULL != path) |
105 | BINDTEXTDOMAIN (PACKAGE, path); | 110 | BINDTEXTDOMAIN (PACKAGE, path); |
106 | GNUNET_free(path); | 111 | GNUNET_free (path); |
107 | gettextinit = 1; | 112 | gettextinit = 1; |
108 | } | 113 | } |
109 | return current_pd; | 114 | return current_pd; |
110 | } | 115 | } |
111 | 116 | ||
@@ -119,13 +124,13 @@ void | |||
119 | GNUNET_OS_init (const struct GNUNET_OS_ProjectData *pd) | 124 | GNUNET_OS_init (const struct GNUNET_OS_ProjectData *pd) |
120 | { | 125 | { |
121 | if (0 == gettextinit) | 126 | if (0 == gettextinit) |
122 | { | 127 | { |
123 | char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); | 128 | char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); |
124 | if (NULL != path) | 129 | if (NULL != path) |
125 | BINDTEXTDOMAIN (PACKAGE, path); | 130 | BINDTEXTDOMAIN (PACKAGE, path); |
126 | GNUNET_free(path); | 131 | GNUNET_free (path); |
127 | gettextinit = 1; | 132 | gettextinit = 1; |
128 | } | 133 | } |
129 | GNUNET_assert (NULL != pd); | 134 | GNUNET_assert (NULL != pd); |
130 | current_pd = pd; | 135 | current_pd = pd; |
131 | } | 136 | } |
@@ -151,10 +156,10 @@ get_path_from_proc_maps () | |||
151 | return NULL; | 156 | return NULL; |
152 | while (NULL != fgets (line, sizeof (line), f)) | 157 | while (NULL != fgets (line, sizeof (line), f)) |
153 | { | 158 | { |
154 | if ((1 == | 159 | if ((1 == SSCANF (line, |
155 | SSCANF (line, "%*x-%*x %*c%*c%*c%*c %*x %*2x:%*2x %*u%*[ ]%1023s", dir)) && | 160 | "%*x-%*x %*c%*c%*c%*c %*x %*2x:%*2x %*u%*[ ]%1023s", |
156 | (NULL != (lgu = strstr (dir, | 161 | dir)) && |
157 | current_pd->libname)))) | 162 | (NULL != (lgu = strstr (dir, current_pd->libname)))) |
158 | { | 163 | { |
159 | lgu[0] = '\0'; | 164 | lgu[0] = '\0'; |
160 | FCLOSE (f); | 165 | FCLOSE (f); |
@@ -179,35 +184,24 @@ get_path_from_proc_exe () | |||
179 | ssize_t size; | 184 | ssize_t size; |
180 | char *lep; | 185 | char *lep; |
181 | 186 | ||
182 | GNUNET_snprintf (fn, | 187 | GNUNET_snprintf (fn, sizeof (fn), "/proc/%u/exe", getpid ()); |
183 | sizeof (fn), | 188 | size = readlink (fn, lnk, sizeof (lnk) - 1); |
184 | "/proc/%u/exe", | ||
185 | getpid ()); | ||
186 | size = readlink (fn, | ||
187 | lnk, | ||
188 | sizeof (lnk) - 1); | ||
189 | if (size <= 0) | 189 | if (size <= 0) |
190 | { | 190 | { |
191 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, | 191 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "readlink", fn); |
192 | "readlink", | ||
193 | fn); | ||
194 | return NULL; | 192 | return NULL; |
195 | } | 193 | } |
196 | GNUNET_assert ( ((size_t) size) < sizeof (lnk)); | 194 | GNUNET_assert (((size_t) size) < sizeof (lnk)); |
197 | lnk[size] = '\0'; | 195 | lnk[size] = '\0'; |
198 | while ((lnk[size] != '/') && (size > 0)) | 196 | while ((lnk[size] != '/') && (size > 0)) |
199 | size--; | 197 | size--; |
200 | GNUNET_asprintf (&lep, | 198 | GNUNET_asprintf (&lep, "/%s/libexec/", current_pd->project_dirname); |
201 | "/%s/libexec/", | ||
202 | current_pd->project_dirname); | ||
203 | /* test for being in lib/gnunet/libexec/ or lib/MULTIARCH/gnunet/libexec */ | 199 | /* test for being in lib/gnunet/libexec/ or lib/MULTIARCH/gnunet/libexec */ |
204 | if ( (((size_t) size) > strlen (lep)) && | 200 | if ((((size_t) size) > strlen (lep)) && |
205 | (0 == strcmp (lep, | 201 | (0 == strcmp (lep, &lnk[size - strlen (lep)]))) |
206 | &lnk[size - strlen (lep)])) ) | ||
207 | size -= strlen (lep) - 1; | 202 | size -= strlen (lep) - 1; |
208 | GNUNET_free (lep); | 203 | GNUNET_free (lep); |
209 | if ( (size < 4) || | 204 | if ((size < 4) || (lnk[size - 4] != '/')) |
210 | (lnk[size - 4] != '/') ) | ||
211 | { | 205 | { |
212 | /* not installed in "/bin/" -- binary path probably useless */ | 206 | /* not installed in "/bin/" -- binary path probably useless */ |
213 | return NULL; | 207 | return NULL; |
@@ -228,21 +222,19 @@ static HINSTANCE dll_instance; | |||
228 | * and hInstance saving. | 222 | * and hInstance saving. |
229 | */ | 223 | */ |
230 | BOOL WINAPI | 224 | BOOL WINAPI |
231 | DllMain (HINSTANCE hinstDLL, | 225 | DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) |
232 | DWORD fdwReason, | ||
233 | LPVOID lpvReserved) | ||
234 | { | 226 | { |
235 | switch (fdwReason) | 227 | switch (fdwReason) |
236 | { | 228 | { |
237 | case DLL_PROCESS_ATTACH: | 229 | case DLL_PROCESS_ATTACH: |
238 | dll_instance = hinstDLL; | 230 | dll_instance = hinstDLL; |
239 | break; | 231 | break; |
240 | case DLL_THREAD_ATTACH: | 232 | case DLL_THREAD_ATTACH: |
241 | break; | 233 | break; |
242 | case DLL_THREAD_DETACH: | 234 | case DLL_THREAD_DETACH: |
243 | break; | 235 | break; |
244 | case DLL_PROCESS_DETACH: | 236 | case DLL_PROCESS_DETACH: |
245 | break; | 237 | break; |
246 | } | 238 | } |
247 | return TRUE; | 239 | return TRUE; |
248 | } | 240 | } |
@@ -271,13 +263,11 @@ get_path_from_module_filename () | |||
271 | do | 263 | do |
272 | { | 264 | { |
273 | pathlen = pathlen * 2; | 265 | pathlen = pathlen * 2; |
274 | modulepath = GNUNET_realloc (modulepath, | 266 | modulepath = GNUNET_realloc (modulepath, pathlen * sizeof (wchar_t)); |
275 | pathlen * sizeof (wchar_t)); | ||
276 | SetLastError (0); | 267 | SetLastError (0); |
277 | real_pathlen = GetModuleFileNameW (dll_instance, | 268 | real_pathlen = |
278 | modulepath, | 269 | GetModuleFileNameW (dll_instance, modulepath, pathlen * sizeof (wchar_t)); |
279 | pathlen * sizeof (wchar_t)); | 270 | } while (real_pathlen >= pathlen && pathlen < 16 * 1024); |
280 | } while (real_pathlen >= pathlen && pathlen < 16*1024); | ||
281 | if (real_pathlen >= pathlen) | 271 | if (real_pathlen >= pathlen) |
282 | GNUNET_assert (0); | 272 | GNUNET_assert (0); |
283 | /* To be safe */ | 273 | /* To be safe */ |
@@ -319,7 +309,8 @@ get_path_from_module_filename () | |||
319 | } | 309 | } |
320 | 310 | ||
321 | /* modulepath is GNUNET_PREFIX */ | 311 | /* modulepath is GNUNET_PREFIX */ |
322 | u8_string = u16_to_u8 (modulepath, wcslen (modulepath), NULL, &u8_string_length); | 312 | u8_string = |
313 | u16_to_u8 (modulepath, wcslen (modulepath), NULL, &u8_string_length); | ||
323 | if (NULL == u8_string) | 314 | if (NULL == u8_string) |
324 | GNUNET_assert (0); | 315 | GNUNET_assert (0); |
325 | 316 | ||
@@ -343,9 +334,7 @@ get_path_from_module_filename () | |||
343 | * @param number of bytes available in @a buf | 334 | * @param number of bytes available in @a buf |
344 | * @return 0 on success, otherwise desired number of bytes is stored in 'bufsize' | 335 | * @return 0 on success, otherwise desired number of bytes is stored in 'bufsize' |
345 | */ | 336 | */ |
346 | typedef int | 337 | typedef int (*MyNSGetExecutablePathProto) (char *buf, size_t *bufsize); |
347 | (*MyNSGetExecutablePathProto) (char *buf, | ||
348 | size_t *bufsize); | ||
349 | 338 | ||
350 | 339 | ||
351 | /** | 340 | /** |
@@ -362,8 +351,9 @@ get_path_from_NSGetExecutablePath () | |||
362 | MyNSGetExecutablePathProto func; | 351 | MyNSGetExecutablePathProto func; |
363 | 352 | ||
364 | path = NULL; | 353 | path = NULL; |
365 | if (NULL == (func = | 354 | if (NULL == |
366 | (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, "_NSGetExecutablePath"))) | 355 | (func = (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, |
356 | "_NSGetExecutablePath"))) | ||
367 | return NULL; | 357 | return NULL; |
368 | path = &zero; | 358 | path = &zero; |
369 | len = 0; | 359 | len = 0; |
@@ -403,10 +393,10 @@ get_path_from_dyld_image () | |||
403 | for (i = 0; i < c; i++) | 393 | for (i = 0; i < c; i++) |
404 | { | 394 | { |
405 | if (((const void *) _dyld_get_image_header (i)) != | 395 | if (((const void *) _dyld_get_image_header (i)) != |
406 | ((const void *) &_mh_dylib_header) ) | 396 | ((const void *) &_mh_dylib_header)) |
407 | continue; | 397 | continue; |
408 | path = _dyld_get_image_name (i); | 398 | path = _dyld_get_image_name (i); |
409 | if ( (NULL == path) || (0 == strlen (path)) ) | 399 | if ((NULL == path) || (0 == strlen (path))) |
410 | continue; | 400 | continue; |
411 | p = GNUNET_strdup (path); | 401 | p = GNUNET_strdup (path); |
412 | s = p + strlen (p); | 402 | s = p + strlen (p); |
@@ -443,7 +433,7 @@ get_path_from_PATH (const char *binary) | |||
443 | /* On W32 look in CWD first. */ | 433 | /* On W32 look in CWD first. */ |
444 | GNUNET_asprintf (&path, ".%c%s", PATH_SEPARATOR, p); | 434 | GNUNET_asprintf (&path, ".%c%s", PATH_SEPARATOR, p); |
445 | #else | 435 | #else |
446 | path = GNUNET_strdup (p); /* because we write on it */ | 436 | path = GNUNET_strdup (p); /* because we write on it */ |
447 | #endif | 437 | #endif |
448 | buf = GNUNET_malloc (strlen (path) + strlen (binary) + 1 + 1); | 438 | buf = GNUNET_malloc (strlen (path) + strlen (binary) + 1 + 1); |
449 | pos = path; | 439 | pos = path; |
@@ -485,11 +475,11 @@ get_path_from_GNUNET_PREFIX () | |||
485 | { | 475 | { |
486 | const char *p; | 476 | const char *p; |
487 | 477 | ||
488 | if ( (NULL != current_pd->env_varname) && | 478 | if ((NULL != current_pd->env_varname) && |
489 | (NULL != (p = getenv (current_pd->env_varname))) ) | 479 | (NULL != (p = getenv (current_pd->env_varname)))) |
490 | return GNUNET_strdup (p); | 480 | return GNUNET_strdup (p); |
491 | if ( (NULL != current_pd->env_varname_alt) && | 481 | if ((NULL != current_pd->env_varname_alt) && |
492 | (NULL != (p = getenv (current_pd->env_varname_alt))) ) | 482 | (NULL != (p = getenv (current_pd->env_varname_alt)))) |
493 | return GNUNET_strdup (p); | 483 | return GNUNET_strdup (p); |
494 | return NULL; | 484 | return NULL; |
495 | } | 485 | } |
@@ -512,8 +502,8 @@ os_get_gnunet_path () | |||
512 | if (NULL != (ret = get_path_from_proc_maps ())) | 502 | if (NULL != (ret = get_path_from_proc_maps ())) |
513 | return ret; | 503 | return ret; |
514 | /* try path *first*, before /proc/exe, as /proc/exe can be wrong */ | 504 | /* try path *first*, before /proc/exe, as /proc/exe can be wrong */ |
515 | if ( (NULL != current_pd->binary_name) && | 505 | if ((NULL != current_pd->binary_name) && |
516 | (NULL != (ret = get_path_from_PATH (current_pd->binary_name))) ) | 506 | (NULL != (ret = get_path_from_PATH (current_pd->binary_name)))) |
517 | return ret; | 507 | return ret; |
518 | if (NULL != (ret = get_path_from_proc_exe ())) | 508 | if (NULL != (ret = get_path_from_proc_exe ())) |
519 | return ret; | 509 | return ret; |
@@ -528,12 +518,13 @@ os_get_gnunet_path () | |||
528 | if (NULL != (ret = get_path_from_NSGetExecutablePath ())) | 518 | if (NULL != (ret = get_path_from_NSGetExecutablePath ())) |
529 | return ret; | 519 | return ret; |
530 | #endif | 520 | #endif |
531 | if ( (NULL != current_pd->binary_name) && | 521 | if ((NULL != current_pd->binary_name) && |
532 | (NULL != (ret = get_path_from_PATH (current_pd->binary_name))) ) | 522 | (NULL != (ret = get_path_from_PATH (current_pd->binary_name)))) |
533 | return ret; | 523 | return ret; |
534 | /* other attempts here */ | 524 | /* other attempts here */ |
535 | LOG (GNUNET_ERROR_TYPE_ERROR, | 525 | LOG (GNUNET_ERROR_TYPE_ERROR, |
536 | _("Could not determine installation path for %s. Set `%s' environment variable.\n"), | 526 | _ ( |
527 | "Could not determine installation path for %s. Set `%s' environment variable.\n"), | ||
537 | current_pd->project_dirname, | 528 | current_pd->project_dirname, |
538 | current_pd->env_varname); | 529 | current_pd->env_varname); |
539 | return NULL; | 530 | return NULL; |
@@ -606,12 +597,11 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) | |||
606 | execpath[--n] = '\0'; | 597 | execpath[--n] = '\0'; |
607 | 598 | ||
608 | isbasedir = 1; | 599 | isbasedir = 1; |
609 | if ((n > 6) && | 600 | if ((n > 6) && ((0 == strcasecmp (&execpath[n - 6], "/lib32")) || |
610 | ((0 == strcasecmp (&execpath[n - 6], "/lib32")) || | 601 | (0 == strcasecmp (&execpath[n - 6], "/lib64")))) |
611 | (0 == strcasecmp (&execpath[n - 6], "/lib64")))) | ||
612 | { | 602 | { |
613 | if ( (GNUNET_OS_IPK_LIBDIR != dirkind) && | 603 | if ((GNUNET_OS_IPK_LIBDIR != dirkind) && |
614 | (GNUNET_OS_IPK_LIBEXECDIR != dirkind) ) | 604 | (GNUNET_OS_IPK_LIBEXECDIR != dirkind)) |
615 | { | 605 | { |
616 | /* strip '/lib32' or '/lib64' */ | 606 | /* strip '/lib32' or '/lib64' */ |
617 | execpath[n - 6] = '\0'; | 607 | execpath[n - 6] = '\0'; |
@@ -620,9 +610,8 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) | |||
620 | else | 610 | else |
621 | isbasedir = 0; | 611 | isbasedir = 0; |
622 | } | 612 | } |
623 | else if ((n > 4) && | 613 | else if ((n > 4) && ((0 == strcasecmp (&execpath[n - 4], "/bin")) || |
624 | ((0 == strcasecmp (&execpath[n - 4], "/bin")) || | 614 | (0 == strcasecmp (&execpath[n - 4], "/lib")))) |
625 | (0 == strcasecmp (&execpath[n - 4], "/lib")))) | ||
626 | { | 615 | { |
627 | /* strip '/bin' or '/lib' */ | 616 | /* strip '/bin' or '/lib' */ |
628 | execpath[n - 4] = '\0'; | 617 | execpath[n - 4] = '\0'; |
@@ -635,9 +624,11 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) | |||
635 | here we need to re-add 'multiarch' to lib and libexec paths later! */ | 624 | here we need to re-add 'multiarch' to lib and libexec paths later! */ |
636 | multiarch = &libdir[5]; | 625 | multiarch = &libdir[5]; |
637 | if (NULL == strchr (multiarch, '/')) | 626 | if (NULL == strchr (multiarch, '/')) |
638 | libdir[0] = '\0'; /* Debian multiarch format, cut of from 'execpath' but preserve in multicarch */ | 627 | libdir[0] = |
628 | '\0'; /* Debian multiarch format, cut of from 'execpath' but preserve in multicarch */ | ||
639 | else | 629 | else |
640 | multiarch = NULL; /* maybe not, multiarch still has a '/', which is not OK */ | 630 | multiarch = |
631 | NULL; /* maybe not, multiarch still has a '/', which is not OK */ | ||
641 | } | 632 | } |
642 | /* in case this was a directory named foo-bin, remove "foo-" */ | 633 | /* in case this was a directory named foo-bin, remove "foo-" */ |
643 | while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR)) | 634 | while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR)) |
@@ -663,8 +654,7 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) | |||
663 | DIR_SEPARATOR_STR, | 654 | DIR_SEPARATOR_STR, |
664 | current_pd->project_dirname, | 655 | current_pd->project_dirname, |
665 | DIR_SEPARATOR_STR); | 656 | DIR_SEPARATOR_STR); |
666 | if (GNUNET_YES == | 657 | if (GNUNET_YES == GNUNET_DISK_directory_test (tmp, GNUNET_YES)) |
667 | GNUNET_DISK_directory_test (tmp, GNUNET_YES)) | ||
668 | { | 658 | { |
669 | GNUNET_free (execpath); | 659 | GNUNET_free (execpath); |
670 | return tmp; | 660 | return tmp; |
@@ -674,28 +664,23 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) | |||
674 | dirname = NULL; | 664 | dirname = NULL; |
675 | if (4 == sizeof (void *)) | 665 | if (4 == sizeof (void *)) |
676 | { | 666 | { |
677 | GNUNET_asprintf (&dirname, | 667 | GNUNET_asprintf (&dirname, |
678 | DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR, | 668 | DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR |
669 | "%s" DIR_SEPARATOR_STR, | ||
679 | current_pd->project_dirname); | 670 | current_pd->project_dirname); |
680 | GNUNET_asprintf (&tmp, | 671 | GNUNET_asprintf (&tmp, "%s%s", execpath, dirname); |
681 | "%s%s", | ||
682 | execpath, | ||
683 | dirname); | ||
684 | } | 672 | } |
685 | if (8 == sizeof (void *)) | 673 | if (8 == sizeof (void *)) |
686 | { | 674 | { |
687 | GNUNET_asprintf (&dirname, | 675 | GNUNET_asprintf (&dirname, |
688 | DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR, | 676 | DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR |
677 | "%s" DIR_SEPARATOR_STR, | ||
689 | current_pd->project_dirname); | 678 | current_pd->project_dirname); |
690 | GNUNET_asprintf (&tmp, | 679 | GNUNET_asprintf (&tmp, "%s%s", execpath, dirname); |
691 | "%s%s", | ||
692 | execpath, | ||
693 | dirname); | ||
694 | } | 680 | } |
695 | 681 | ||
696 | if ( (NULL != tmp) && | 682 | if ((NULL != tmp) && |
697 | (GNUNET_YES == | 683 | (GNUNET_YES == GNUNET_DISK_directory_test (tmp, GNUNET_YES))) |
698 | GNUNET_DISK_directory_test (tmp, GNUNET_YES)) ) | ||
699 | { | 684 | { |
700 | GNUNET_free (execpath); | 685 | GNUNET_free (execpath); |
701 | GNUNET_free_non_null (dirname); | 686 | GNUNET_free_non_null (dirname); |
@@ -710,25 +695,31 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) | |||
710 | break; | 695 | break; |
711 | case GNUNET_OS_IPK_DATADIR: | 696 | case GNUNET_OS_IPK_DATADIR: |
712 | GNUNET_asprintf (&dirname, | 697 | GNUNET_asprintf (&dirname, |
713 | DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR, | 698 | DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR |
699 | "%s" DIR_SEPARATOR_STR, | ||
714 | current_pd->project_dirname); | 700 | current_pd->project_dirname); |
715 | break; | 701 | break; |
716 | case GNUNET_OS_IPK_LOCALEDIR: | 702 | case GNUNET_OS_IPK_LOCALEDIR: |
717 | dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "locale" DIR_SEPARATOR_STR); | 703 | dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR |
704 | "locale" DIR_SEPARATOR_STR); | ||
718 | break; | 705 | break; |
719 | case GNUNET_OS_IPK_ICONDIR: | 706 | case GNUNET_OS_IPK_ICONDIR: |
720 | dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "icons" DIR_SEPARATOR_STR); | 707 | dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR |
708 | "icons" DIR_SEPARATOR_STR); | ||
721 | break; | 709 | break; |
722 | case GNUNET_OS_IPK_DOCDIR: | 710 | case GNUNET_OS_IPK_DOCDIR: |
723 | GNUNET_asprintf (&dirname, | 711 | GNUNET_asprintf (&dirname, |
724 | DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "doc" DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR, | 712 | DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR |
713 | "doc" DIR_SEPARATOR_STR | ||
714 | "%s" DIR_SEPARATOR_STR, | ||
725 | current_pd->project_dirname); | 715 | current_pd->project_dirname); |
726 | break; | 716 | break; |
727 | case GNUNET_OS_IPK_LIBEXECDIR: | 717 | case GNUNET_OS_IPK_LIBEXECDIR: |
728 | if (isbasedir) | 718 | if (isbasedir) |
729 | { | 719 | { |
730 | GNUNET_asprintf (&dirname, | 720 | GNUNET_asprintf (&dirname, |
731 | DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR "libexec" DIR_SEPARATOR_STR, | 721 | DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR |
722 | "libexec" DIR_SEPARATOR_STR, | ||
732 | current_pd->project_dirname); | 723 | current_pd->project_dirname); |
733 | GNUNET_asprintf (&tmp, | 724 | GNUNET_asprintf (&tmp, |
734 | "%s%s%s%s", | 725 | "%s%s%s%s", |
@@ -736,8 +727,7 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) | |||
736 | DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR, | 727 | DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR, |
737 | (NULL != multiarch) ? multiarch : "", | 728 | (NULL != multiarch) ? multiarch : "", |
738 | dirname); | 729 | dirname); |
739 | if (GNUNET_YES == | 730 | if (GNUNET_YES == GNUNET_DISK_directory_test (tmp, GNUNET_YES)) |
740 | GNUNET_DISK_directory_test (tmp, GNUNET_YES)) | ||
741 | { | 731 | { |
742 | GNUNET_free (execpath); | 732 | GNUNET_free (execpath); |
743 | GNUNET_free (dirname); | 733 | GNUNET_free (dirname); |
@@ -749,26 +739,23 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) | |||
749 | if (4 == sizeof (void *)) | 739 | if (4 == sizeof (void *)) |
750 | { | 740 | { |
751 | GNUNET_asprintf (&dirname, | 741 | GNUNET_asprintf (&dirname, |
752 | DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR "libexec" DIR_SEPARATOR_STR, | 742 | DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR |
743 | "%s" DIR_SEPARATOR_STR | ||
744 | "libexec" DIR_SEPARATOR_STR, | ||
753 | current_pd->project_dirname); | 745 | current_pd->project_dirname); |
754 | GNUNET_asprintf (&tmp, | 746 | GNUNET_asprintf (&tmp, "%s%s", execpath, dirname); |
755 | "%s%s", | ||
756 | execpath, | ||
757 | dirname); | ||
758 | } | 747 | } |
759 | if (8 == sizeof (void *)) | 748 | if (8 == sizeof (void *)) |
760 | { | 749 | { |
761 | GNUNET_asprintf (&dirname, | 750 | GNUNET_asprintf (&dirname, |
762 | DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR "libexec" DIR_SEPARATOR_STR, | 751 | DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR |
752 | "%s" DIR_SEPARATOR_STR | ||
753 | "libexec" DIR_SEPARATOR_STR, | ||
763 | current_pd->project_dirname); | 754 | current_pd->project_dirname); |
764 | GNUNET_asprintf (&tmp, | 755 | GNUNET_asprintf (&tmp, "%s%s", execpath, dirname); |
765 | "%s%s", | ||
766 | execpath, | ||
767 | dirname); | ||
768 | } | 756 | } |
769 | if ( (NULL != tmp) && | 757 | if ((NULL != tmp) && |
770 | (GNUNET_YES == | 758 | (GNUNET_YES == GNUNET_DISK_directory_test (tmp, GNUNET_YES))) |
771 | GNUNET_DISK_directory_test (tmp, GNUNET_YES)) ) | ||
772 | { | 759 | { |
773 | GNUNET_free (execpath); | 760 | GNUNET_free (execpath); |
774 | GNUNET_free_non_null (dirname); | 761 | GNUNET_free_non_null (dirname); |
@@ -778,17 +765,15 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) | |||
778 | GNUNET_free_non_null (dirname); | 765 | GNUNET_free_non_null (dirname); |
779 | } | 766 | } |
780 | GNUNET_asprintf (&dirname, | 767 | GNUNET_asprintf (&dirname, |
781 | DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR "libexec" DIR_SEPARATOR_STR, | 768 | DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR |
769 | "libexec" DIR_SEPARATOR_STR, | ||
782 | current_pd->project_dirname); | 770 | current_pd->project_dirname); |
783 | break; | 771 | break; |
784 | default: | 772 | default: |
785 | GNUNET_free (execpath); | 773 | GNUNET_free (execpath); |
786 | return NULL; | 774 | return NULL; |
787 | } | 775 | } |
788 | GNUNET_asprintf (&tmp, | 776 | GNUNET_asprintf (&tmp, "%s%s", execpath, dirname); |
789 | "%s%s", | ||
790 | execpath, | ||
791 | dirname); | ||
792 | GNUNET_free (dirname); | 777 | GNUNET_free (dirname); |
793 | GNUNET_free (execpath); | 778 | GNUNET_free (execpath); |
794 | return tmp; | 779 | return tmp; |
@@ -810,11 +795,9 @@ GNUNET_OS_get_libexec_binary_path (const char *progname) | |||
810 | char *libexecdir; | 795 | char *libexecdir; |
811 | char *binary; | 796 | char *binary; |
812 | 797 | ||
813 | if ( (DIR_SEPARATOR == progname[0]) || | 798 | if ((DIR_SEPARATOR == progname[0]) || |
814 | (GNUNET_YES == | 799 | (GNUNET_YES == |
815 | GNUNET_STRINGS_path_is_absolute (progname, | 800 | GNUNET_STRINGS_path_is_absolute (progname, GNUNET_NO, NULL, NULL))) |
816 | GNUNET_NO, | ||
817 | NULL, NULL)) ) | ||
818 | return GNUNET_strdup (progname); | 801 | return GNUNET_strdup (progname); |
819 | if (NULL != cache) | 802 | if (NULL != cache) |
820 | libexecdir = cache; | 803 | libexecdir = cache; |
@@ -822,10 +805,7 @@ GNUNET_OS_get_libexec_binary_path (const char *progname) | |||
822 | libexecdir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBEXECDIR); | 805 | libexecdir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBEXECDIR); |
823 | if (NULL == libexecdir) | 806 | if (NULL == libexecdir) |
824 | return GNUNET_strdup (progname); | 807 | return GNUNET_strdup (progname); |
825 | GNUNET_asprintf (&binary, | 808 | GNUNET_asprintf (&binary, "%s%s", libexecdir, progname); |
826 | "%s%s", | ||
827 | libexecdir, | ||
828 | progname); | ||
829 | cache = libexecdir; | 809 | cache = libexecdir; |
830 | return binary; | 810 | return binary; |
831 | } | 811 | } |
@@ -853,9 +833,7 @@ GNUNET_OS_get_suid_binary_path (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
853 | size_t path_len; | 833 | size_t path_len; |
854 | 834 | ||
855 | if (GNUNET_YES == | 835 | if (GNUNET_YES == |
856 | GNUNET_STRINGS_path_is_absolute (progname, | 836 | GNUNET_STRINGS_path_is_absolute (progname, GNUNET_NO, NULL, NULL)) |
857 | GNUNET_NO, | ||
858 | NULL, NULL)) | ||
859 | { | 837 | { |
860 | return GNUNET_strdup (progname); | 838 | return GNUNET_strdup (progname); |
861 | } | 839 | } |
@@ -866,14 +844,15 @@ GNUNET_OS_get_suid_binary_path (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
866 | "PATHS", | 844 | "PATHS", |
867 | "SUID_BINARY_PATH", | 845 | "SUID_BINARY_PATH", |
868 | &path); | 846 | &path); |
869 | if (NULL == path || 0 == strlen (path)) | 847 | if ((NULL == path)||(0 == strlen (path))) |
870 | return GNUNET_OS_get_libexec_binary_path (progname); | 848 | return GNUNET_OS_get_libexec_binary_path (progname); |
871 | path_len = strlen (path); | 849 | path_len = strlen (path); |
872 | GNUNET_asprintf (&binary, | 850 | GNUNET_asprintf (&binary, |
873 | "%s%s%s", | 851 | "%s%s%s", |
874 | path, | 852 | path, |
875 | (path[path_len - 1] == DIR_SEPARATOR) ? "" : DIR_SEPARATOR_STR, | 853 | (path[path_len - 1] == DIR_SEPARATOR) ? "" |
876 | progname); | 854 | : DIR_SEPARATOR_STR, |
855 | progname); | ||
877 | cache = path; | 856 | cache = path; |
878 | return binary; | 857 | return binary; |
879 | } | 858 | } |
@@ -906,14 +885,10 @@ GNUNET_OS_check_helper_binary (const char *binary, | |||
906 | #ifdef MINGW | 885 | #ifdef MINGW |
907 | char *binaryexe; | 886 | char *binaryexe; |
908 | 887 | ||
909 | GNUNET_asprintf (&binaryexe, | 888 | GNUNET_asprintf (&binaryexe, "%s.exe", binary); |
910 | "%s.exe", | 889 | if ((GNUNET_YES == |
911 | binary); | 890 | GNUNET_STRINGS_path_is_absolute (binaryexe, GNUNET_NO, NULL, NULL)) || |
912 | if ( (GNUNET_YES == | 891 | (0 == strncmp (binary, "./", 2))) |
913 | GNUNET_STRINGS_path_is_absolute (binaryexe, | ||
914 | GNUNET_NO, | ||
915 | NULL, NULL)) || | ||
916 | (0 == strncmp (binary, "./", 2)) ) | ||
917 | p = GNUNET_strdup (binaryexe); | 892 | p = GNUNET_strdup (binaryexe); |
918 | else | 893 | else |
919 | { | 894 | { |
@@ -927,12 +902,9 @@ GNUNET_OS_check_helper_binary (const char *binary, | |||
927 | } | 902 | } |
928 | GNUNET_free (binaryexe); | 903 | GNUNET_free (binaryexe); |
929 | #else | 904 | #else |
930 | if ( (GNUNET_YES == | 905 | if ((GNUNET_YES == |
931 | GNUNET_STRINGS_path_is_absolute (binary, | 906 | GNUNET_STRINGS_path_is_absolute (binary, GNUNET_NO, NULL, NULL)) || |
932 | GNUNET_NO, | 907 | (0 == strncmp (binary, "./", 2))) |
933 | NULL, | ||
934 | NULL)) || | ||
935 | (0 == strncmp (binary, "./", 2)) ) | ||
936 | { | 908 | { |
937 | p = GNUNET_strdup (binary); | 909 | p = GNUNET_strdup (binary); |
938 | } | 910 | } |
@@ -941,10 +913,7 @@ GNUNET_OS_check_helper_binary (const char *binary, | |||
941 | p = get_path_from_PATH (binary); | 913 | p = get_path_from_PATH (binary); |
942 | if (NULL != p) | 914 | if (NULL != p) |
943 | { | 915 | { |
944 | GNUNET_asprintf (&pf, | 916 | GNUNET_asprintf (&pf, "%s/%s", p, binary); |
945 | "%s/%s", | ||
946 | p, | ||
947 | binary); | ||
948 | GNUNET_free (p); | 917 | GNUNET_free (p); |
949 | p = pf; | 918 | p = pf; |
950 | } | 919 | } |
@@ -953,16 +922,13 @@ GNUNET_OS_check_helper_binary (const char *binary, | |||
953 | if (NULL == p) | 922 | if (NULL == p) |
954 | { | 923 | { |
955 | LOG (GNUNET_ERROR_TYPE_INFO, | 924 | LOG (GNUNET_ERROR_TYPE_INFO, |
956 | _("Could not find binary `%s' in PATH!\n"), | 925 | _ ("Could not find binary `%s' in PATH!\n"), |
957 | binary); | 926 | binary); |
958 | return GNUNET_SYSERR; | 927 | return GNUNET_SYSERR; |
959 | } | 928 | } |
960 | if (0 != ACCESS (p, | 929 | if (0 != ACCESS (p, X_OK)) |
961 | X_OK)) | ||
962 | { | 930 | { |
963 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, | 931 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", p); |
964 | "access", | ||
965 | p); | ||
966 | GNUNET_free (p); | 932 | GNUNET_free (p); |
967 | return GNUNET_SYSERR; | 933 | return GNUNET_SYSERR; |
968 | } | 934 | } |
@@ -974,12 +940,9 @@ GNUNET_OS_check_helper_binary (const char *binary, | |||
974 | return GNUNET_YES; | 940 | return GNUNET_YES; |
975 | } | 941 | } |
976 | #endif | 942 | #endif |
977 | if (0 != STAT (p, | 943 | if (0 != STAT (p, &statbuf)) |
978 | &statbuf)) | ||
979 | { | 944 | { |
980 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, | 945 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", p); |
981 | "stat", | ||
982 | p); | ||
983 | GNUNET_free (p); | 946 | GNUNET_free (p); |
984 | return GNUNET_SYSERR; | 947 | return GNUNET_SYSERR; |
985 | } | 948 | } |
@@ -987,14 +950,13 @@ GNUNET_OS_check_helper_binary (const char *binary, | |||
987 | { | 950 | { |
988 | #ifndef MINGW | 951 | #ifndef MINGW |
989 | (void) params; | 952 | (void) params; |
990 | if ( (0 != (statbuf.st_mode & S_ISUID)) && | 953 | if ((0 != (statbuf.st_mode & S_ISUID)) && (0 == statbuf.st_uid)) |
991 | (0 == statbuf.st_uid) ) | ||
992 | { | 954 | { |
993 | GNUNET_free (p); | 955 | GNUNET_free (p); |
994 | return GNUNET_YES; | 956 | return GNUNET_YES; |
995 | } | 957 | } |
996 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, | 958 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
997 | _("Binary `%s' exists, but is not SUID\n"), | 959 | _ ("Binary `%s' exists, but is not SUID\n"), |
998 | p); | 960 | p); |
999 | /* binary exists, but not SUID */ | 961 | /* binary exists, but not SUID */ |
1000 | #else | 962 | #else |
@@ -1003,50 +965,52 @@ GNUNET_OS_check_helper_binary (const char *binary, | |||
1003 | PROCESS_INFORMATION proc; | 965 | PROCESS_INFORMATION proc; |
1004 | DWORD exit_value; | 966 | DWORD exit_value; |
1005 | 967 | ||
1006 | GNUNET_snprintf (parameters, | 968 | GNUNET_snprintf (parameters, sizeof (parameters), "-d %s", params); |
1007 | sizeof (parameters), | ||
1008 | "-d %s", params); | ||
1009 | memset (&start, 0, sizeof (start)); | 969 | memset (&start, 0, sizeof (start)); |
1010 | start.cb = sizeof (start); | 970 | start.cb = sizeof (start); |
1011 | memset (&proc, 0, sizeof (proc)); | 971 | memset (&proc, 0, sizeof (proc)); |
1012 | 972 | ||
1013 | 973 | ||
1014 | // Start the child process. | 974 | // Start the child process. |
1015 | if ( ! (CreateProcess( p, // current windows (2k3 and up can handle / instead of \ in paths)) | 975 | if (! (CreateProcess ( |
1016 | parameters, // execute dryrun/priviliege checking mode | 976 | p, // current windows (2k3 and up can handle / instead of \ in paths)) |
1017 | NULL, // Process handle not inheritable | 977 | parameters, // execute dryrun/priviliege checking mode |
1018 | NULL, // Thread handle not inheritable | 978 | NULL, // Process handle not inheritable |
1019 | FALSE, // Set handle inheritance to FALSE | 979 | NULL, // Thread handle not inheritable |
1020 | CREATE_DEFAULT_ERROR_MODE, // No creation flags | 980 | FALSE, // Set handle inheritance to FALSE |
1021 | NULL, // Use parent's environment block | 981 | CREATE_DEFAULT_ERROR_MODE, // No creation flags |
1022 | NULL, // Use parent's starting directory | 982 | NULL, // Use parent's environment block |
1023 | &start, // Pointer to STARTUPINFO structure | 983 | NULL, // Use parent's starting directory |
1024 | &proc ) // Pointer to PROCESS_INFORMATION structure | 984 | &start, // Pointer to STARTUPINFO structure |
1025 | )) | 985 | &proc) // Pointer to PROCESS_INFORMATION structure |
1026 | { | 986 | )) |
1027 | LOG (GNUNET_ERROR_TYPE_ERROR, | 987 | { |
1028 | _("CreateProcess failed for binary %s (%d).\n"), | 988 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1029 | p, GetLastError()); | 989 | _ ("CreateProcess failed for binary %s (%d).\n"), |
1030 | return GNUNET_SYSERR; | 990 | p, |
991 | GetLastError ()); | ||
992 | return GNUNET_SYSERR; | ||
1031 | } | 993 | } |
1032 | 994 | ||
1033 | // Wait until child process exits. | 995 | // Wait until child process exits. |
1034 | WaitForSingleObject( proc.hProcess, INFINITE ); | 996 | WaitForSingleObject (proc.hProcess, INFINITE); |
1035 | 997 | ||
1036 | if ( ! GetExitCodeProcess (proc.hProcess, &exit_value)){ | 998 | if (! GetExitCodeProcess (proc.hProcess, &exit_value)) |
1037 | LOG (GNUNET_ERROR_TYPE_ERROR, | 999 | { |
1038 | _("GetExitCodeProcess failed for binary %s (%d).\n"), | 1000 | LOG (GNUNET_ERROR_TYPE_ERROR, |
1039 | p, GetLastError() ); | 1001 | _ ("GetExitCodeProcess failed for binary %s (%d).\n"), |
1040 | return GNUNET_SYSERR; | 1002 | p, |
1041 | } | 1003 | GetLastError ()); |
1004 | return GNUNET_SYSERR; | ||
1005 | } | ||
1042 | // Close process and thread handles. | 1006 | // Close process and thread handles. |
1043 | CloseHandle( proc.hProcess ); | 1007 | CloseHandle (proc.hProcess); |
1044 | CloseHandle( proc.hThread ); | 1008 | CloseHandle (proc.hThread); |
1045 | 1009 | ||
1046 | if (!exit_value) | 1010 | if (! exit_value) |
1047 | return GNUNET_YES; | 1011 | return GNUNET_YES; |
1048 | #endif | 1012 | #endif |
1049 | } | 1013 | } |
1050 | GNUNET_free (p); | 1014 | GNUNET_free (p); |
1051 | return GNUNET_NO; | 1015 | return GNUNET_NO; |
1052 | } | 1016 | } |