diff options
Diffstat (limited to 'src/util/os_installation.c')
-rw-r--r-- | src/util/os_installation.c | 274 |
1 files changed, 135 insertions, 139 deletions
diff --git a/src/util/os_installation.c b/src/util/os_installation.c index 98080a3ed..a7a6ae915 100644 --- a/src/util/os_installation.c +++ b/src/util/os_installation.c | |||
@@ -60,16 +60,16 @@ get_path_from_proc_maps () | |||
60 | if (f == NULL) | 60 | if (f == NULL) |
61 | return NULL; | 61 | return NULL; |
62 | while (NULL != fgets (line, sizeof (line), f)) | 62 | while (NULL != fgets (line, sizeof (line), f)) |
63 | { | ||
64 | if ((1 == | ||
65 | sscanf (line, "%*x-%*x %*c%*c%*c%*c %*x %*2u:%*2u %*u%*[ ]%s", dir)) && | ||
66 | (NULL != (lgu = strstr (dir, "libgnunetutil")))) | ||
63 | { | 67 | { |
64 | if ((1 == | 68 | lgu[0] = '\0'; |
65 | sscanf (line, "%*x-%*x %*c%*c%*c%*c %*x %*2u:%*2u %*u%*[ ]%s", | 69 | fclose (f); |
66 | dir)) && (NULL != (lgu = strstr (dir, "libgnunetutil")))) | 70 | return GNUNET_strdup (dir); |
67 | { | ||
68 | lgu[0] = '\0'; | ||
69 | fclose (f); | ||
70 | return GNUNET_strdup (dir); | ||
71 | } | ||
72 | } | 71 | } |
72 | } | ||
73 | fclose (f); | 73 | fclose (f); |
74 | return NULL; | 74 | return NULL; |
75 | } | 75 | } |
@@ -87,19 +87,19 @@ get_path_from_proc_exe () | |||
87 | GNUNET_snprintf (fn, sizeof (fn), "/proc/%u/exe", getpid ()); | 87 | GNUNET_snprintf (fn, sizeof (fn), "/proc/%u/exe", getpid ()); |
88 | size = readlink (fn, lnk, sizeof (lnk) - 1); | 88 | size = readlink (fn, lnk, sizeof (lnk) - 1); |
89 | if (size <= 0) | 89 | if (size <= 0) |
90 | { | 90 | { |
91 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "readlink", fn); | 91 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "readlink", fn); |
92 | return NULL; | 92 | return NULL; |
93 | } | 93 | } |
94 | GNUNET_assert (size < sizeof (lnk)); | 94 | GNUNET_assert (size < sizeof (lnk)); |
95 | lnk[size] = '\0'; | 95 | lnk[size] = '\0'; |
96 | while ((lnk[size] != '/') && (size > 0)) | 96 | while ((lnk[size] != '/') && (size > 0)) |
97 | size--; | 97 | size--; |
98 | if ((size < 4) || (lnk[size - 4] != '/')) | 98 | if ((size < 4) || (lnk[size - 4] != '/')) |
99 | { | 99 | { |
100 | /* not installed in "/bin/" -- binary path probably useless */ | 100 | /* not installed in "/bin/" -- binary path probably useless */ |
101 | return NULL; | 101 | return NULL; |
102 | } | 102 | } |
103 | lnk[size] = '\0'; | 103 | lnk[size] = '\0'; |
104 | return GNUNET_strdup (lnk); | 104 | return GNUNET_strdup (lnk); |
105 | } | 105 | } |
@@ -138,7 +138,7 @@ get_path_from_NSGetExecutablePath () | |||
138 | 138 | ||
139 | path = NULL; | 139 | path = NULL; |
140 | func = | 140 | func = |
141 | (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, "_NSGetExecutablePath"); | 141 | (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, "_NSGetExecutablePath"); |
142 | if (!func) | 142 | if (!func) |
143 | return NULL; | 143 | return NULL; |
144 | path = &zero; | 144 | path = &zero; |
@@ -150,10 +150,10 @@ get_path_from_NSGetExecutablePath () | |||
150 | path = GNUNET_malloc (len); | 150 | path = GNUNET_malloc (len); |
151 | ret = func (path, &len); | 151 | ret = func (path, &len); |
152 | if (ret != 0) | 152 | if (ret != 0) |
153 | { | 153 | { |
154 | GNUNET_free (path); | 154 | GNUNET_free (path); |
155 | return NULL; | 155 | return NULL; |
156 | } | 156 | } |
157 | len = strlen (path); | 157 | len = strlen (path); |
158 | while ((path[len] != '/') && (len > 0)) | 158 | while ((path[len] != '/') && (len > 0)) |
159 | len--; | 159 | len--; |
@@ -172,22 +172,22 @@ get_path_from_dyld_image () | |||
172 | p = NULL; | 172 | p = NULL; |
173 | c = _dyld_image_count (); | 173 | c = _dyld_image_count (); |
174 | for (i = 0; i < c; i++) | 174 | for (i = 0; i < c; i++) |
175 | { | ||
176 | if (_dyld_get_image_header (i) == &_mh_dylib_header) | ||
175 | { | 177 | { |
176 | if (_dyld_get_image_header (i) == &_mh_dylib_header) | 178 | path = _dyld_get_image_name (i); |
177 | { | 179 | if (path != NULL && strlen (path) > 0) |
178 | path = _dyld_get_image_name (i); | 180 | { |
179 | if (path != NULL && strlen (path) > 0) | 181 | p = GNUNET_strdup (path); |
180 | { | 182 | s = p + strlen (p); |
181 | p = GNUNET_strdup (path); | 183 | while ((s > p) && (*s != '/')) |
182 | s = p + strlen (p); | 184 | s--; |
183 | while ((s > p) && (*s != '/')) | 185 | s++; |
184 | s--; | 186 | *s = '\0'; |
185 | s++; | 187 | } |
186 | *s = '\0'; | 188 | break; |
187 | } | ||
188 | break; | ||
189 | } | ||
190 | } | 189 | } |
190 | } | ||
191 | return p; | 191 | return p; |
192 | } | 192 | } |
193 | #endif | 193 | #endif |
@@ -211,30 +211,30 @@ get_path_from_PATH (const char *binary) | |||
211 | p = getenv ("PATH"); | 211 | p = getenv ("PATH"); |
212 | if (p == NULL) | 212 | if (p == NULL) |
213 | return NULL; | 213 | return NULL; |
214 | path = GNUNET_strdup (p); /* because we write on it */ | 214 | path = GNUNET_strdup (p); /* because we write on it */ |
215 | buf = GNUNET_malloc (strlen (path) + 20); | 215 | buf = GNUNET_malloc (strlen (path) + 20); |
216 | pos = path; | 216 | pos = path; |
217 | while (NULL != (end = strchr (pos, PATH_SEPARATOR))) | 217 | while (NULL != (end = strchr (pos, PATH_SEPARATOR))) |
218 | { | 218 | { |
219 | *end = '\0'; | 219 | *end = '\0'; |
220 | sprintf (buf, "%s/%s", pos, binary); | 220 | sprintf (buf, "%s/%s", pos, binary); |
221 | if (GNUNET_DISK_file_test (buf) == GNUNET_YES) | 221 | if (GNUNET_DISK_file_test (buf) == GNUNET_YES) |
222 | { | ||
223 | pos = GNUNET_strdup (pos); | ||
224 | GNUNET_free (buf); | ||
225 | GNUNET_free (path); | ||
226 | return pos; | ||
227 | } | ||
228 | pos = end + 1; | ||
229 | } | ||
230 | sprintf (buf, "%s/%s", pos, binary); | ||
231 | if (GNUNET_DISK_file_test (buf) == GNUNET_YES) | ||
232 | { | 222 | { |
233 | pos = GNUNET_strdup (pos); | 223 | pos = GNUNET_strdup (pos); |
234 | GNUNET_free (buf); | 224 | GNUNET_free (buf); |
235 | GNUNET_free (path); | 225 | GNUNET_free (path); |
236 | return pos; | 226 | return pos; |
237 | } | 227 | } |
228 | pos = end + 1; | ||
229 | } | ||
230 | sprintf (buf, "%s/%s", pos, binary); | ||
231 | if (GNUNET_DISK_file_test (buf) == GNUNET_YES) | ||
232 | { | ||
233 | pos = GNUNET_strdup (pos); | ||
234 | GNUNET_free (buf); | ||
235 | GNUNET_free (path); | ||
236 | return pos; | ||
237 | } | ||
238 | GNUNET_free (buf); | 238 | GNUNET_free (buf); |
239 | GNUNET_free (path); | 239 | GNUNET_free (path); |
240 | return NULL; | 240 | return NULL; |
@@ -359,11 +359,11 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) | |||
359 | 359 | ||
360 | n = strlen (execpath); | 360 | n = strlen (execpath); |
361 | if (n == 0) | 361 | if (n == 0) |
362 | { | 362 | { |
363 | /* should never happen, but better safe than sorry */ | 363 | /* should never happen, but better safe than sorry */ |
364 | GNUNET_free (execpath); | 364 | GNUNET_free (execpath); |
365 | return NULL; | 365 | return NULL; |
366 | } | 366 | } |
367 | /* remove filename itself */ | 367 | /* remove filename itself */ |
368 | while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR)) | 368 | while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR)) |
369 | execpath[--n] = '\0'; | 369 | execpath[--n] = '\0'; |
@@ -372,62 +372,59 @@ GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) | |||
372 | if ((n > 5) && | 372 | if ((n > 5) && |
373 | ((0 == strcasecmp (&execpath[n - 5], "lib32")) || | 373 | ((0 == strcasecmp (&execpath[n - 5], "lib32")) || |
374 | (0 == strcasecmp (&execpath[n - 5], "lib64")))) | 374 | (0 == strcasecmp (&execpath[n - 5], "lib64")))) |
375 | { | ||
376 | if (dirkind != GNUNET_OS_IPK_LIBDIR) | ||
375 | { | 377 | { |
376 | if (dirkind != GNUNET_OS_IPK_LIBDIR) | 378 | /* strip '/lib32' or '/lib64' */ |
377 | { | 379 | execpath[n - 5] = '\0'; |
378 | /* strip '/lib32' or '/lib64' */ | 380 | n -= 5; |
379 | execpath[n - 5] = '\0'; | ||
380 | n -= 5; | ||
381 | } | ||
382 | else | ||
383 | isbasedir = 0; | ||
384 | } | 381 | } |
382 | else | ||
383 | isbasedir = 0; | ||
384 | } | ||
385 | else if ((n > 3) && | 385 | else if ((n > 3) && |
386 | ((0 == strcasecmp (&execpath[n - 3], "bin")) || | 386 | ((0 == strcasecmp (&execpath[n - 3], "bin")) || |
387 | (0 == strcasecmp (&execpath[n - 3], "lib")))) | 387 | (0 == strcasecmp (&execpath[n - 3], "lib")))) |
388 | { | 388 | { |
389 | /* strip '/bin' or '/lib' */ | 389 | /* strip '/bin' or '/lib' */ |
390 | execpath[n - 3] = '\0'; | 390 | execpath[n - 3] = '\0'; |
391 | n -= 3; | 391 | n -= 3; |
392 | } | 392 | } |
393 | /* in case this was a directory named foo-bin, remove "foo-" */ | 393 | /* in case this was a directory named foo-bin, remove "foo-" */ |
394 | while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR)) | 394 | while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR)) |
395 | execpath[--n] = '\0'; | 395 | execpath[--n] = '\0'; |
396 | switch (dirkind) | 396 | switch (dirkind) |
397 | { | 397 | { |
398 | case GNUNET_OS_IPK_PREFIX: | 398 | case GNUNET_OS_IPK_PREFIX: |
399 | case GNUNET_OS_IPK_SELF_PREFIX: | 399 | case GNUNET_OS_IPK_SELF_PREFIX: |
400 | dirname = DIR_SEPARATOR_STR; | 400 | dirname = DIR_SEPARATOR_STR; |
401 | break; | 401 | break; |
402 | case GNUNET_OS_IPK_BINDIR: | 402 | case GNUNET_OS_IPK_BINDIR: |
403 | dirname = DIR_SEPARATOR_STR "bin" DIR_SEPARATOR_STR; | 403 | dirname = DIR_SEPARATOR_STR "bin" DIR_SEPARATOR_STR; |
404 | break; | 404 | break; |
405 | case GNUNET_OS_IPK_LIBDIR: | 405 | case GNUNET_OS_IPK_LIBDIR: |
406 | if (isbasedir) | 406 | if (isbasedir) |
407 | dirname = | ||
408 | DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR "gnunet" | ||
409 | DIR_SEPARATOR_STR; | ||
410 | else | ||
411 | dirname = DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR; | ||
412 | break; | ||
413 | case GNUNET_OS_IPK_DATADIR: | ||
414 | dirname = | ||
415 | DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "gnunet" | ||
416 | DIR_SEPARATOR_STR; | ||
417 | break; | ||
418 | case GNUNET_OS_IPK_LOCALEDIR: | ||
419 | dirname = | ||
420 | DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "locale" | ||
421 | DIR_SEPARATOR_STR; | ||
422 | break; | ||
423 | case GNUNET_OS_IPK_ICONDIR: | ||
424 | dirname = | 407 | dirname = |
425 | DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "icons" DIR_SEPARATOR_STR; | 408 | DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR; |
426 | break; | 409 | else |
427 | default: | 410 | dirname = DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR; |
428 | GNUNET_free (execpath); | 411 | break; |
429 | return NULL; | 412 | case GNUNET_OS_IPK_DATADIR: |
430 | } | 413 | dirname = |
414 | DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "gnunet" DIR_SEPARATOR_STR; | ||
415 | break; | ||
416 | case GNUNET_OS_IPK_LOCALEDIR: | ||
417 | dirname = | ||
418 | DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "locale" DIR_SEPARATOR_STR; | ||
419 | break; | ||
420 | case GNUNET_OS_IPK_ICONDIR: | ||
421 | dirname = | ||
422 | DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR "icons" DIR_SEPARATOR_STR; | ||
423 | break; | ||
424 | default: | ||
425 | GNUNET_free (execpath); | ||
426 | return NULL; | ||
427 | } | ||
431 | tmp = GNUNET_malloc (strlen (execpath) + strlen (dirname) + 1); | 428 | tmp = GNUNET_malloc (strlen (execpath) + strlen (dirname) + 1); |
432 | sprintf (tmp, "%s%s", execpath, dirname); | 429 | sprintf (tmp, "%s%s", execpath, dirname); |
433 | GNUNET_free (execpath); | 430 | GNUNET_free (execpath); |
@@ -460,59 +457,58 @@ GNUNET_OS_check_helper_binary (const char *binary) | |||
460 | GNUNET_asprintf (&binaryexe, "%s.exe", binary); | 457 | GNUNET_asprintf (&binaryexe, "%s.exe", binary); |
461 | p = get_path_from_PATH (binaryexe); | 458 | p = get_path_from_PATH (binaryexe); |
462 | if (p != NULL) | 459 | if (p != NULL) |
463 | { | 460 | { |
464 | GNUNET_asprintf (&pf, "%s/%s", p, binaryexe); | 461 | GNUNET_asprintf (&pf, "%s/%s", p, binaryexe); |
465 | GNUNET_free (p); | 462 | GNUNET_free (p); |
466 | p = pf; | 463 | p = pf; |
467 | } | 464 | } |
468 | free (binaryexe); | 465 | free (binaryexe); |
469 | #else | 466 | #else |
470 | p = get_path_from_PATH (binary); | 467 | p = get_path_from_PATH (binary); |
471 | if (p != NULL) | 468 | if (p != NULL) |
472 | { | 469 | { |
473 | GNUNET_asprintf (&pf, "%s/%s", p, binary); | 470 | GNUNET_asprintf (&pf, "%s/%s", p, binary); |
474 | GNUNET_free (p); | 471 | GNUNET_free (p); |
475 | p = pf; | 472 | p = pf; |
476 | } | 473 | } |
477 | #endif | 474 | #endif |
478 | if (p == NULL) | 475 | if (p == NULL) |
479 | { | 476 | { |
480 | LOG (GNUNET_ERROR_TYPE_INFO, | 477 | LOG (GNUNET_ERROR_TYPE_INFO, _("Could not find binary `%s' in PATH!\n"), |
481 | _("Could not find binary `%s' in PATH!\n"), binary); | 478 | binary); |
482 | return GNUNET_SYSERR; | 479 | return GNUNET_SYSERR; |
483 | } | 480 | } |
484 | if (0 != STAT (p, &statbuf)) | 481 | if (0 != STAT (p, &statbuf)) |
485 | { | 482 | { |
486 | LOG (GNUNET_ERROR_TYPE_WARNING, _("stat (%s) failed: %s\n"), p, | 483 | LOG (GNUNET_ERROR_TYPE_WARNING, _("stat (%s) failed: %s\n"), p, |
487 | STRERROR (errno)); | 484 | STRERROR (errno)); |
488 | GNUNET_free (p); | 485 | GNUNET_free (p); |
489 | return GNUNET_SYSERR; | 486 | return GNUNET_SYSERR; |
490 | } | 487 | } |
491 | #ifndef MINGW | 488 | #ifndef MINGW |
492 | if ((0 != (statbuf.st_mode & S_ISUID)) && (statbuf.st_uid == 0)) | 489 | if ((0 != (statbuf.st_mode & S_ISUID)) && (statbuf.st_uid == 0)) |
493 | { | 490 | { |
494 | GNUNET_free (p); | 491 | GNUNET_free (p); |
495 | return GNUNET_YES; | 492 | return GNUNET_YES; |
496 | } | 493 | } |
497 | if (0 == ACCESS (p, X_OK)) | 494 | if (0 == ACCESS (p, X_OK)) |
498 | { | 495 | { |
499 | GNUNET_free (p); | 496 | GNUNET_free (p); |
500 | return GNUNET_NO; | 497 | return GNUNET_NO; |
501 | } | 498 | } |
502 | GNUNET_free (p); | 499 | GNUNET_free (p); |
503 | return GNUNET_SYSERR; | 500 | return GNUNET_SYSERR; |
504 | #else | 501 | #else |
505 | GNUNET_free (p); | 502 | GNUNET_free (p); |
506 | rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP); | 503 | rawsock = socket (AF_INET, SOCK_RAW, IPPROTO_ICMP); |
507 | if (INVALID_SOCKET == rawsock) | 504 | if (INVALID_SOCKET == rawsock) |
508 | { | 505 | { |
509 | DWORD err = GetLastError (); | 506 | DWORD err = GetLastError (); |
510 | 507 | ||
511 | LOG (GNUNET_ERROR_TYPE_INFO, | 508 | LOG (GNUNET_ERROR_TYPE_INFO, |
512 | "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) failed! GLE = %d\n", | 509 | "socket (AF_INET, SOCK_RAW, IPPROTO_ICMP) failed! GLE = %d\n", err); |
513 | err); | 510 | return GNUNET_NO; /* not running as administrator */ |
514 | return GNUNET_NO; /* not running as administrator */ | 511 | } |
515 | } | ||
516 | closesocket (rawsock); | 512 | closesocket (rawsock); |
517 | return GNUNET_YES; | 513 | return GNUNET_YES; |
518 | #endif | 514 | #endif |