diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src/util/os_installation.c | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) | |
download | gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.tar.gz gnunet-c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207.zip |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src/util/os_installation.c')
-rw-r--r-- | src/util/os_installation.c | 784 |
1 files changed, 392 insertions, 392 deletions
diff --git a/src/util/os_installation.c b/src/util/os_installation.c index c8590c8fb..a4ef199cc 100644 --- a/src/util/os_installation.c +++ b/src/util/os_installation.c | |||
@@ -43,13 +43,13 @@ | |||
43 | 43 | ||
44 | 44 | ||
45 | #define LOG(kind, ...) \ | 45 | #define LOG(kind, ...) \ |
46 | GNUNET_log_from(kind, "util-os-installation", __VA_ARGS__) | 46 | GNUNET_log_from (kind, "util-os-installation", __VA_ARGS__) |
47 | 47 | ||
48 | #define LOG_STRERROR_FILE(kind, syscall, filename) \ | 48 | #define LOG_STRERROR_FILE(kind, syscall, filename) \ |
49 | GNUNET_log_from_strerror_file(kind, \ | 49 | GNUNET_log_from_strerror_file (kind, \ |
50 | "util-os-installation", \ | 50 | "util-os-installation", \ |
51 | syscall, \ | 51 | syscall, \ |
52 | filename) | 52 | filename) |
53 | 53 | ||
54 | 54 | ||
55 | /** | 55 | /** |
@@ -89,7 +89,7 @@ static int gettextinit = 0; | |||
89 | * Return default project data used by 'libgnunetutil' for GNUnet. | 89 | * Return default project data used by 'libgnunetutil' for GNUnet. |
90 | */ | 90 | */ |
91 | const struct GNUNET_OS_ProjectData * | 91 | const struct GNUNET_OS_ProjectData * |
92 | GNUNET_OS_project_data_default(void) | 92 | GNUNET_OS_project_data_default (void) |
93 | { | 93 | { |
94 | return &default_pd; | 94 | return &default_pd; |
95 | } | 95 | } |
@@ -99,16 +99,16 @@ GNUNET_OS_project_data_default(void) | |||
99 | * @return current project data. | 99 | * @return current project data. |
100 | */ | 100 | */ |
101 | const struct GNUNET_OS_ProjectData * | 101 | const struct GNUNET_OS_ProjectData * |
102 | GNUNET_OS_project_data_get() | 102 | GNUNET_OS_project_data_get () |
103 | { | 103 | { |
104 | if (0 == gettextinit) | 104 | if (0 == gettextinit) |
105 | { | 105 | { |
106 | char *path = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_LOCALEDIR); | 106 | char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); |
107 | if (NULL != path) | 107 | if (NULL != path) |
108 | bindtextdomain(PACKAGE, path); | 108 | bindtextdomain (PACKAGE, path); |
109 | GNUNET_free(path); | 109 | GNUNET_free (path); |
110 | gettextinit = 1; | 110 | gettextinit = 1; |
111 | } | 111 | } |
112 | return current_pd; | 112 | return current_pd; |
113 | } | 113 | } |
114 | 114 | ||
@@ -119,17 +119,17 @@ GNUNET_OS_project_data_get() | |||
119 | * @param pd project data used to determine paths | 119 | * @param pd project data used to determine paths |
120 | */ | 120 | */ |
121 | void | 121 | void |
122 | GNUNET_OS_init(const struct GNUNET_OS_ProjectData *pd) | 122 | GNUNET_OS_init (const struct GNUNET_OS_ProjectData *pd) |
123 | { | 123 | { |
124 | if (0 == gettextinit) | 124 | if (0 == gettextinit) |
125 | { | 125 | { |
126 | char *path = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_LOCALEDIR); | 126 | char *path = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LOCALEDIR); |
127 | if (NULL != path) | 127 | if (NULL != path) |
128 | bindtextdomain(PACKAGE, path); | 128 | bindtextdomain (PACKAGE, path); |
129 | GNUNET_free(path); | 129 | GNUNET_free (path); |
130 | gettextinit = 1; | 130 | gettextinit = 1; |
131 | } | 131 | } |
132 | GNUNET_assert(NULL != pd); | 132 | GNUNET_assert (NULL != pd); |
133 | current_pd = pd; | 133 | current_pd = pd; |
134 | } | 134 | } |
135 | 135 | ||
@@ -141,7 +141,7 @@ GNUNET_OS_init(const struct GNUNET_OS_ProjectData *pd) | |||
141 | * @return NULL on error | 141 | * @return NULL on error |
142 | */ | 142 | */ |
143 | static char * | 143 | static char * |
144 | get_path_from_proc_maps() | 144 | get_path_from_proc_maps () |
145 | { | 145 | { |
146 | char fn[64]; | 146 | char fn[64]; |
147 | char line[1024]; | 147 | char line[1024]; |
@@ -149,22 +149,22 @@ get_path_from_proc_maps() | |||
149 | FILE *f; | 149 | FILE *f; |
150 | char *lgu; | 150 | char *lgu; |
151 | 151 | ||
152 | GNUNET_snprintf(fn, sizeof(fn), "/proc/%u/maps", getpid()); | 152 | GNUNET_snprintf (fn, sizeof(fn), "/proc/%u/maps", getpid ()); |
153 | if (NULL == (f = fopen(fn, "r"))) | 153 | if (NULL == (f = fopen (fn, "r"))) |
154 | return NULL; | 154 | return NULL; |
155 | while (NULL != fgets(line, sizeof(line), f)) | 155 | while (NULL != fgets (line, sizeof(line), f)) |
156 | { | ||
157 | if ((1 == sscanf (line, | ||
158 | "%*x-%*x %*c%*c%*c%*c %*x %*2x:%*2x %*u%*[ ]%1023s", | ||
159 | dir)) && | ||
160 | (NULL != (lgu = strstr (dir, current_pd->libname)))) | ||
156 | { | 161 | { |
157 | if ((1 == sscanf(line, | 162 | lgu[0] = '\0'; |
158 | "%*x-%*x %*c%*c%*c%*c %*x %*2x:%*2x %*u%*[ ]%1023s", | 163 | fclose (f); |
159 | dir)) && | 164 | return GNUNET_strdup (dir); |
160 | (NULL != (lgu = strstr(dir, current_pd->libname)))) | ||
161 | { | ||
162 | lgu[0] = '\0'; | ||
163 | fclose(f); | ||
164 | return GNUNET_strdup(dir); | ||
165 | } | ||
166 | } | 165 | } |
167 | fclose(f); | 166 | } |
167 | fclose (f); | ||
168 | return NULL; | 168 | return NULL; |
169 | } | 169 | } |
170 | 170 | ||
@@ -175,37 +175,37 @@ get_path_from_proc_maps() | |||
175 | * @return NULL on error | 175 | * @return NULL on error |
176 | */ | 176 | */ |
177 | static char * | 177 | static char * |
178 | get_path_from_proc_exe() | 178 | get_path_from_proc_exe () |
179 | { | 179 | { |
180 | char fn[64]; | 180 | char fn[64]; |
181 | char lnk[1024]; | 181 | char lnk[1024]; |
182 | ssize_t size; | 182 | ssize_t size; |
183 | char *lep; | 183 | char *lep; |
184 | 184 | ||
185 | GNUNET_snprintf(fn, sizeof(fn), "/proc/%u/exe", getpid()); | 185 | GNUNET_snprintf (fn, sizeof(fn), "/proc/%u/exe", getpid ()); |
186 | size = readlink(fn, lnk, sizeof(lnk) - 1); | 186 | size = readlink (fn, lnk, sizeof(lnk) - 1); |
187 | if (size <= 0) | 187 | if (size <= 0) |
188 | { | 188 | { |
189 | LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_ERROR, "readlink", fn); | 189 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_ERROR, "readlink", fn); |
190 | return NULL; | 190 | return NULL; |
191 | } | 191 | } |
192 | GNUNET_assert(((size_t)size) < sizeof(lnk)); | 192 | GNUNET_assert (((size_t) size) < sizeof(lnk)); |
193 | lnk[size] = '\0'; | 193 | lnk[size] = '\0'; |
194 | while ((lnk[size] != '/') && (size > 0)) | 194 | while ((lnk[size] != '/') && (size > 0)) |
195 | size--; | 195 | size--; |
196 | GNUNET_asprintf(&lep, "/%s/libexec/", current_pd->project_dirname); | 196 | GNUNET_asprintf (&lep, "/%s/libexec/", current_pd->project_dirname); |
197 | /* test for being in lib/gnunet/libexec/ or lib/MULTIARCH/gnunet/libexec */ | 197 | /* test for being in lib/gnunet/libexec/ or lib/MULTIARCH/gnunet/libexec */ |
198 | if ((((size_t)size) > strlen(lep)) && | 198 | if ((((size_t) size) > strlen (lep)) && |
199 | (0 == strcmp(lep, &lnk[size - strlen(lep)]))) | 199 | (0 == strcmp (lep, &lnk[size - strlen (lep)]))) |
200 | size -= strlen(lep) - 1; | 200 | size -= strlen (lep) - 1; |
201 | GNUNET_free(lep); | 201 | GNUNET_free (lep); |
202 | if ((size < 4) || (lnk[size - 4] != '/')) | 202 | if ((size < 4) || (lnk[size - 4] != '/')) |
203 | { | 203 | { |
204 | /* not installed in "/bin/" -- binary path probably useless */ | 204 | /* not installed in "/bin/" -- binary path probably useless */ |
205 | return NULL; | 205 | return NULL; |
206 | } | 206 | } |
207 | lnk[size] = '\0'; | 207 | lnk[size] = '\0'; |
208 | return GNUNET_strdup(lnk); | 208 | return GNUNET_strdup (lnk); |
209 | } | 209 | } |
210 | #endif | 210 | #endif |
211 | 211 | ||
@@ -227,7 +227,7 @@ typedef int (*MyNSGetExecutablePathProto) (char *buf, size_t *bufsize); | |||
227 | * @return NULL on error | 227 | * @return NULL on error |
228 | */ | 228 | */ |
229 | static char * | 229 | static char * |
230 | get_path_from_NSGetExecutablePath() | 230 | get_path_from_NSGetExecutablePath () |
231 | { | 231 | { |
232 | static char zero = '\0'; | 232 | static char zero = '\0'; |
233 | char *path; | 233 | char *path; |
@@ -236,22 +236,22 @@ get_path_from_NSGetExecutablePath() | |||
236 | 236 | ||
237 | path = NULL; | 237 | path = NULL; |
238 | if (NULL == | 238 | if (NULL == |
239 | (func = (MyNSGetExecutablePathProto)dlsym(RTLD_DEFAULT, | 239 | (func = (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, |
240 | "_NSGetExecutablePath"))) | 240 | "_NSGetExecutablePath"))) |
241 | return NULL; | 241 | return NULL; |
242 | path = &zero; | 242 | path = &zero; |
243 | len = 0; | 243 | len = 0; |
244 | /* get the path len, including the trailing \0 */ | 244 | /* get the path len, including the trailing \0 */ |
245 | (void)func(path, &len); | 245 | (void) func (path, &len); |
246 | if (0 == len) | 246 | if (0 == len) |
247 | return NULL; | 247 | return NULL; |
248 | path = GNUNET_malloc(len); | 248 | path = GNUNET_malloc (len); |
249 | if (0 != func(path, &len)) | 249 | if (0 != func (path, &len)) |
250 | { | 250 | { |
251 | GNUNET_free(path); | 251 | GNUNET_free (path); |
252 | return NULL; | 252 | return NULL; |
253 | } | 253 | } |
254 | len = strlen(path); | 254 | len = strlen (path); |
255 | while ((path[len] != '/') && (len > 0)) | 255 | while ((path[len] != '/') && (len > 0)) |
256 | len--; | 256 | len--; |
257 | path[len] = '\0'; | 257 | path[len] = '\0'; |
@@ -265,7 +265,7 @@ get_path_from_NSGetExecutablePath() | |||
265 | * @return NULL on error | 265 | * @return NULL on error |
266 | */ | 266 | */ |
267 | static char * | 267 | static char * |
268 | get_path_from_dyld_image() | 268 | get_path_from_dyld_image () |
269 | { | 269 | { |
270 | const char *path; | 270 | const char *path; |
271 | char *p; | 271 | char *p; |
@@ -273,23 +273,23 @@ get_path_from_dyld_image() | |||
273 | unsigned int i; | 273 | unsigned int i; |
274 | int c; | 274 | int c; |
275 | 275 | ||
276 | c = _dyld_image_count(); | 276 | c = _dyld_image_count (); |
277 | for (i = 0; i < c; i++) | 277 | for (i = 0; i < c; i++) |
278 | { | 278 | { |
279 | if (((const void *)_dyld_get_image_header(i)) != | 279 | if (((const void *) _dyld_get_image_header (i)) != |
280 | ((const void *)&_mh_dylib_header)) | 280 | ((const void *) &_mh_dylib_header)) |
281 | continue; | 281 | continue; |
282 | path = _dyld_get_image_name(i); | 282 | path = _dyld_get_image_name (i); |
283 | if ((NULL == path) || (0 == strlen(path))) | 283 | if ((NULL == path) || (0 == strlen (path))) |
284 | continue; | 284 | continue; |
285 | p = GNUNET_strdup(path); | 285 | p = GNUNET_strdup (path); |
286 | s = p + strlen(p); | 286 | s = p + strlen (p); |
287 | while ((s > p) && ('/' != *s)) | 287 | while ((s > p) && ('/' != *s)) |
288 | s--; | 288 | s--; |
289 | s++; | 289 | s++; |
290 | *s = '\0'; | 290 | *s = '\0'; |
291 | return p; | 291 | return p; |
292 | } | 292 | } |
293 | return NULL; | 293 | return NULL; |
294 | } | 294 | } |
295 | #endif | 295 | #endif |
@@ -303,7 +303,7 @@ get_path_from_dyld_image() | |||
303 | * @return path to binary, NULL if not found | 303 | * @return path to binary, NULL if not found |
304 | */ | 304 | */ |
305 | static char * | 305 | static char * |
306 | get_path_from_PATH(const char *binary) | 306 | get_path_from_PATH (const char *binary) |
307 | { | 307 | { |
308 | char *path; | 308 | char *path; |
309 | char *pos; | 309 | char *pos; |
@@ -311,36 +311,36 @@ get_path_from_PATH(const char *binary) | |||
311 | char *buf; | 311 | char *buf; |
312 | const char *p; | 312 | const char *p; |
313 | 313 | ||
314 | if (NULL == (p = getenv("PATH"))) | 314 | if (NULL == (p = getenv ("PATH"))) |
315 | return NULL; | 315 | return NULL; |
316 | 316 | ||
317 | path = GNUNET_strdup(p); /* because we write on it */ | 317 | path = GNUNET_strdup (p); /* because we write on it */ |
318 | 318 | ||
319 | buf = GNUNET_malloc(strlen(path) + strlen(binary) + 1 + 1); | 319 | buf = GNUNET_malloc (strlen (path) + strlen (binary) + 1 + 1); |
320 | pos = path; | 320 | pos = path; |
321 | while (NULL != (end = strchr(pos, PATH_SEPARATOR))) | 321 | while (NULL != (end = strchr (pos, PATH_SEPARATOR))) |
322 | { | 322 | { |
323 | *end = '\0'; | 323 | *end = '\0'; |
324 | sprintf(buf, "%s/%s", pos, binary); | 324 | sprintf (buf, "%s/%s", pos, binary); |
325 | if (GNUNET_DISK_file_test(buf) == GNUNET_YES) | 325 | if (GNUNET_DISK_file_test (buf) == GNUNET_YES) |
326 | { | ||
327 | pos = GNUNET_strdup(pos); | ||
328 | GNUNET_free(buf); | ||
329 | GNUNET_free(path); | ||
330 | return pos; | ||
331 | } | ||
332 | pos = end + 1; | ||
333 | } | ||
334 | sprintf(buf, "%s/%s", pos, binary); | ||
335 | if (GNUNET_YES == GNUNET_DISK_file_test(buf)) | ||
336 | { | 326 | { |
337 | pos = GNUNET_strdup(pos); | 327 | pos = GNUNET_strdup (pos); |
338 | GNUNET_free(buf); | 328 | GNUNET_free (buf); |
339 | GNUNET_free(path); | 329 | GNUNET_free (path); |
340 | return pos; | 330 | return pos; |
341 | } | 331 | } |
342 | GNUNET_free(buf); | 332 | pos = end + 1; |
343 | GNUNET_free(path); | 333 | } |
334 | sprintf (buf, "%s/%s", pos, binary); | ||
335 | if (GNUNET_YES == GNUNET_DISK_file_test (buf)) | ||
336 | { | ||
337 | pos = GNUNET_strdup (pos); | ||
338 | GNUNET_free (buf); | ||
339 | GNUNET_free (path); | ||
340 | return pos; | ||
341 | } | ||
342 | GNUNET_free (buf); | ||
343 | GNUNET_free (path); | ||
344 | return NULL; | 344 | return NULL; |
345 | } | 345 | } |
346 | 346 | ||
@@ -352,16 +352,16 @@ get_path_from_PATH(const char *binary) | |||
352 | * @return NULL on error (environment variable not set) | 352 | * @return NULL on error (environment variable not set) |
353 | */ | 353 | */ |
354 | static char * | 354 | static char * |
355 | get_path_from_GNUNET_PREFIX() | 355 | get_path_from_GNUNET_PREFIX () |
356 | { | 356 | { |
357 | const char *p; | 357 | const char *p; |
358 | 358 | ||
359 | if ((NULL != current_pd->env_varname) && | 359 | if ((NULL != current_pd->env_varname) && |
360 | (NULL != (p = getenv(current_pd->env_varname)))) | 360 | (NULL != (p = getenv (current_pd->env_varname)))) |
361 | return GNUNET_strdup(p); | 361 | return GNUNET_strdup (p); |
362 | if ((NULL != current_pd->env_varname_alt) && | 362 | if ((NULL != current_pd->env_varname_alt) && |
363 | (NULL != (p = getenv(current_pd->env_varname_alt)))) | 363 | (NULL != (p = getenv (current_pd->env_varname_alt)))) |
364 | return GNUNET_strdup(p); | 364 | return GNUNET_strdup (p); |
365 | return NULL; | 365 | return NULL; |
366 | } | 366 | } |
367 | 367 | ||
@@ -373,37 +373,37 @@ get_path_from_GNUNET_PREFIX() | |||
373 | * @return a pointer to the executable path, or NULL on error | 373 | * @return a pointer to the executable path, or NULL on error |
374 | */ | 374 | */ |
375 | static char * | 375 | static char * |
376 | os_get_gnunet_path() | 376 | os_get_gnunet_path () |
377 | { | 377 | { |
378 | char *ret; | 378 | char *ret; |
379 | 379 | ||
380 | if (NULL != (ret = get_path_from_GNUNET_PREFIX())) | 380 | if (NULL != (ret = get_path_from_GNUNET_PREFIX ())) |
381 | return ret; | 381 | return ret; |
382 | #if LINUX | 382 | #if LINUX |
383 | if (NULL != (ret = get_path_from_proc_maps())) | 383 | if (NULL != (ret = get_path_from_proc_maps ())) |
384 | return ret; | 384 | return ret; |
385 | /* try path *first*, before /proc/exe, as /proc/exe can be wrong */ | 385 | /* try path *first*, before /proc/exe, as /proc/exe can be wrong */ |
386 | if ((NULL != current_pd->binary_name) && | 386 | if ((NULL != current_pd->binary_name) && |
387 | (NULL != (ret = get_path_from_PATH(current_pd->binary_name)))) | 387 | (NULL != (ret = get_path_from_PATH (current_pd->binary_name)))) |
388 | return ret; | 388 | return ret; |
389 | if (NULL != (ret = get_path_from_proc_exe())) | 389 | if (NULL != (ret = get_path_from_proc_exe ())) |
390 | return ret; | 390 | return ret; |
391 | #endif | 391 | #endif |
392 | #if DARWIN | 392 | #if DARWIN |
393 | if (NULL != (ret = get_path_from_dyld_image())) | 393 | if (NULL != (ret = get_path_from_dyld_image ())) |
394 | return ret; | 394 | return ret; |
395 | if (NULL != (ret = get_path_from_NSGetExecutablePath())) | 395 | if (NULL != (ret = get_path_from_NSGetExecutablePath ())) |
396 | return ret; | 396 | return ret; |
397 | #endif | 397 | #endif |
398 | if ((NULL != current_pd->binary_name) && | 398 | if ((NULL != current_pd->binary_name) && |
399 | (NULL != (ret = get_path_from_PATH(current_pd->binary_name)))) | 399 | (NULL != (ret = get_path_from_PATH (current_pd->binary_name)))) |
400 | return ret; | 400 | return ret; |
401 | /* other attempts here */ | 401 | /* other attempts here */ |
402 | LOG(GNUNET_ERROR_TYPE_ERROR, | 402 | LOG (GNUNET_ERROR_TYPE_ERROR, |
403 | _( | 403 | _ ( |
404 | "Could not determine installation path for %s. Set `%s' environment variable.\n"), | 404 | "Could not determine installation path for %s. Set `%s' environment variable.\n"), |
405 | current_pd->project_dirname, | 405 | current_pd->project_dirname, |
406 | current_pd->env_varname); | 406 | current_pd->env_varname); |
407 | return NULL; | 407 | return NULL; |
408 | } | 408 | } |
409 | 409 | ||
@@ -413,16 +413,16 @@ os_get_gnunet_path() | |||
413 | * @return a pointer to the executable path, or NULL on error | 413 | * @return a pointer to the executable path, or NULL on error |
414 | */ | 414 | */ |
415 | static char * | 415 | static char * |
416 | os_get_exec_path() | 416 | os_get_exec_path () |
417 | { | 417 | { |
418 | char *ret = NULL; | 418 | char *ret = NULL; |
419 | 419 | ||
420 | #if LINUX | 420 | #if LINUX |
421 | if (NULL != (ret = get_path_from_proc_exe())) | 421 | if (NULL != (ret = get_path_from_proc_exe ())) |
422 | return ret; | 422 | return ret; |
423 | #endif | 423 | #endif |
424 | #if DARWIN | 424 | #if DARWIN |
425 | if (NULL != (ret = get_path_from_NSGetExecutablePath())) | 425 | if (NULL != (ret = get_path_from_NSGetExecutablePath ())) |
426 | return ret; | 426 | return ret; |
427 | #endif | 427 | #endif |
428 | /* other attempts here */ | 428 | /* other attempts here */ |
@@ -436,7 +436,7 @@ os_get_exec_path() | |||
436 | * @return a pointer to the dir path (to be freed by the caller) | 436 | * @return a pointer to the dir path (to be freed by the caller) |
437 | */ | 437 | */ |
438 | char * | 438 | char * |
439 | GNUNET_OS_installation_get_path(enum GNUNET_OS_InstallationPathKind dirkind) | 439 | GNUNET_OS_installation_get_path (enum GNUNET_OS_InstallationPathKind dirkind) |
440 | { | 440 | { |
441 | size_t n; | 441 | size_t n; |
442 | char *dirname; | 442 | char *dirname; |
@@ -448,215 +448,215 @@ GNUNET_OS_installation_get_path(enum GNUNET_OS_InstallationPathKind dirkind) | |||
448 | 448 | ||
449 | /* if wanted, try to get the current app's bin/ */ | 449 | /* if wanted, try to get the current app's bin/ */ |
450 | if (dirkind == GNUNET_OS_IPK_SELF_PREFIX) | 450 | if (dirkind == GNUNET_OS_IPK_SELF_PREFIX) |
451 | execpath = os_get_exec_path(); | 451 | execpath = os_get_exec_path (); |
452 | 452 | ||
453 | /* try to get GNUnet's bin/ or lib/, or if previous was unsuccessful some | 453 | /* try to get GNUnet's bin/ or lib/, or if previous was unsuccessful some |
454 | * guess for the current app */ | 454 | * guess for the current app */ |
455 | if (NULL == execpath) | 455 | if (NULL == execpath) |
456 | execpath = os_get_gnunet_path(); | 456 | execpath = os_get_gnunet_path (); |
457 | 457 | ||
458 | if (NULL == execpath) | 458 | if (NULL == execpath) |
459 | return NULL; | 459 | return NULL; |
460 | 460 | ||
461 | n = strlen(execpath); | 461 | n = strlen (execpath); |
462 | if (0 == n) | 462 | if (0 == n) |
463 | { | 463 | { |
464 | /* should never happen, but better safe than sorry */ | 464 | /* should never happen, but better safe than sorry */ |
465 | GNUNET_free(execpath); | 465 | GNUNET_free (execpath); |
466 | return NULL; | 466 | return NULL; |
467 | } | 467 | } |
468 | /* remove filename itself */ | 468 | /* remove filename itself */ |
469 | while ((n > 1) && (DIR_SEPARATOR == execpath[n - 1])) | 469 | while ((n > 1) && (DIR_SEPARATOR == execpath[n - 1])) |
470 | execpath[--n] = '\0'; | 470 | execpath[--n] = '\0'; |
471 | 471 | ||
472 | isbasedir = 1; | 472 | isbasedir = 1; |
473 | if ((n > 6) && ((0 == strcasecmp(&execpath[n - 6], "/lib32")) || | 473 | if ((n > 6) && ((0 == strcasecmp (&execpath[n - 6], "/lib32")) || |
474 | (0 == strcasecmp(&execpath[n - 6], "/lib64")))) | 474 | (0 == strcasecmp (&execpath[n - 6], "/lib64")))) |
475 | { | 475 | { |
476 | if ((GNUNET_OS_IPK_LIBDIR != dirkind) && | 476 | if ((GNUNET_OS_IPK_LIBDIR != dirkind) && |
477 | (GNUNET_OS_IPK_LIBEXECDIR != dirkind)) | 477 | (GNUNET_OS_IPK_LIBEXECDIR != dirkind)) |
478 | { | ||
479 | /* strip '/lib32' or '/lib64' */ | ||
480 | execpath[n - 6] = '\0'; | ||
481 | n -= 6; | ||
482 | } | ||
483 | else | ||
484 | isbasedir = 0; | ||
485 | } | ||
486 | else if ((n > 4) && ((0 == strcasecmp(&execpath[n - 4], "/bin")) || | ||
487 | (0 == strcasecmp(&execpath[n - 4], "/lib")))) | ||
488 | { | 478 | { |
489 | /* strip '/bin' or '/lib' */ | 479 | /* strip '/lib32' or '/lib64' */ |
490 | execpath[n - 4] = '\0'; | 480 | execpath[n - 6] = '\0'; |
491 | n -= 4; | 481 | n -= 6; |
492 | } | 482 | } |
483 | else | ||
484 | isbasedir = 0; | ||
485 | } | ||
486 | else if ((n > 4) && ((0 == strcasecmp (&execpath[n - 4], "/bin")) || | ||
487 | (0 == strcasecmp (&execpath[n - 4], "/lib")))) | ||
488 | { | ||
489 | /* strip '/bin' or '/lib' */ | ||
490 | execpath[n - 4] = '\0'; | ||
491 | n -= 4; | ||
492 | } | ||
493 | multiarch = NULL; | 493 | multiarch = NULL; |
494 | if (NULL != (libdir = strstr(execpath, "/lib/"))) | 494 | if (NULL != (libdir = strstr (execpath, "/lib/"))) |
495 | { | 495 | { |
496 | /* test for multi-arch path of the form "PREFIX/lib/MULTIARCH/"; | 496 | /* test for multi-arch path of the form "PREFIX/lib/MULTIARCH/"; |
497 | here we need to re-add 'multiarch' to lib and libexec paths later! */ | 497 | here we need to re-add 'multiarch' to lib and libexec paths later! */ |
498 | multiarch = &libdir[5]; | 498 | multiarch = &libdir[5]; |
499 | if (NULL == strchr(multiarch, '/')) | 499 | if (NULL == strchr (multiarch, '/')) |
500 | libdir[0] = | 500 | libdir[0] = |
501 | '\0'; /* Debian multiarch format, cut of from 'execpath' but preserve in multicarch */ | 501 | '\0'; /* Debian multiarch format, cut of from 'execpath' but preserve in multicarch */ |
502 | else | 502 | else |
503 | multiarch = | 503 | multiarch = |
504 | NULL; /* maybe not, multiarch still has a '/', which is not OK */ | 504 | NULL; /* maybe not, multiarch still has a '/', which is not OK */ |
505 | } | 505 | } |
506 | /* in case this was a directory named foo-bin, remove "foo-" */ | 506 | /* in case this was a directory named foo-bin, remove "foo-" */ |
507 | while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR)) | 507 | while ((n > 1) && (execpath[n - 1] == DIR_SEPARATOR)) |
508 | execpath[--n] = '\0'; | 508 | execpath[--n] = '\0'; |
509 | switch (dirkind) | 509 | switch (dirkind) |
510 | { | ||
511 | case GNUNET_OS_IPK_PREFIX: | ||
512 | case GNUNET_OS_IPK_SELF_PREFIX: | ||
513 | dirname = GNUNET_strdup (DIR_SEPARATOR_STR); | ||
514 | break; | ||
515 | |||
516 | case GNUNET_OS_IPK_BINDIR: | ||
517 | dirname = GNUNET_strdup (DIR_SEPARATOR_STR "bin" DIR_SEPARATOR_STR); | ||
518 | break; | ||
519 | |||
520 | case GNUNET_OS_IPK_LIBDIR: | ||
521 | if (isbasedir) | ||
522 | { | ||
523 | GNUNET_asprintf (&tmp, | ||
524 | "%s%s%s%s%s%s%s", | ||
525 | execpath, | ||
526 | DIR_SEPARATOR_STR "lib", | ||
527 | (NULL != multiarch) ? DIR_SEPARATOR_STR : "", | ||
528 | (NULL != multiarch) ? multiarch : "", | ||
529 | DIR_SEPARATOR_STR, | ||
530 | current_pd->project_dirname, | ||
531 | DIR_SEPARATOR_STR); | ||
532 | if (GNUNET_YES == GNUNET_DISK_directory_test (tmp, GNUNET_YES)) | ||
533 | { | ||
534 | GNUNET_free (execpath); | ||
535 | return tmp; | ||
536 | } | ||
537 | GNUNET_free (tmp); | ||
538 | tmp = NULL; | ||
539 | dirname = NULL; | ||
540 | if (4 == sizeof(void *)) | ||
541 | { | ||
542 | GNUNET_asprintf (&dirname, | ||
543 | DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR | ||
544 | "%s" DIR_SEPARATOR_STR, | ||
545 | current_pd->project_dirname); | ||
546 | GNUNET_asprintf (&tmp, "%s%s", execpath, dirname); | ||
547 | } | ||
548 | if (8 == sizeof(void *)) | ||
549 | { | ||
550 | GNUNET_asprintf (&dirname, | ||
551 | DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR | ||
552 | "%s" DIR_SEPARATOR_STR, | ||
553 | current_pd->project_dirname); | ||
554 | GNUNET_asprintf (&tmp, "%s%s", execpath, dirname); | ||
555 | } | ||
556 | |||
557 | if ((NULL != tmp) && | ||
558 | (GNUNET_YES == GNUNET_DISK_directory_test (tmp, GNUNET_YES))) | ||
559 | { | ||
560 | GNUNET_free (execpath); | ||
561 | GNUNET_free_non_null (dirname); | ||
562 | return tmp; | ||
563 | } | ||
564 | GNUNET_free (tmp); | ||
565 | GNUNET_free_non_null (dirname); | ||
566 | } | ||
567 | GNUNET_asprintf (&dirname, | ||
568 | DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR, | ||
569 | current_pd->project_dirname); | ||
570 | break; | ||
571 | |||
572 | case GNUNET_OS_IPK_DATADIR: | ||
573 | GNUNET_asprintf (&dirname, | ||
574 | DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR | ||
575 | "%s" DIR_SEPARATOR_STR, | ||
576 | current_pd->project_dirname); | ||
577 | break; | ||
578 | |||
579 | case GNUNET_OS_IPK_LOCALEDIR: | ||
580 | dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR | ||
581 | "locale" DIR_SEPARATOR_STR); | ||
582 | break; | ||
583 | |||
584 | case GNUNET_OS_IPK_ICONDIR: | ||
585 | dirname = GNUNET_strdup (DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR | ||
586 | "icons" DIR_SEPARATOR_STR); | ||
587 | break; | ||
588 | |||
589 | case GNUNET_OS_IPK_DOCDIR: | ||
590 | GNUNET_asprintf (&dirname, | ||
591 | DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR | ||
592 | "doc" DIR_SEPARATOR_STR | ||
593 | "%s" DIR_SEPARATOR_STR, | ||
594 | current_pd->project_dirname); | ||
595 | break; | ||
596 | |||
597 | case GNUNET_OS_IPK_LIBEXECDIR: | ||
598 | if (isbasedir) | ||
510 | { | 599 | { |
511 | case GNUNET_OS_IPK_PREFIX: | 600 | GNUNET_asprintf (&dirname, |
512 | case GNUNET_OS_IPK_SELF_PREFIX: | 601 | DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR |
513 | dirname = GNUNET_strdup(DIR_SEPARATOR_STR); | 602 | "libexec" DIR_SEPARATOR_STR, |
514 | break; | 603 | current_pd->project_dirname); |
515 | 604 | GNUNET_asprintf (&tmp, | |
516 | case GNUNET_OS_IPK_BINDIR: | 605 | "%s%s%s%s", |
517 | dirname = GNUNET_strdup(DIR_SEPARATOR_STR "bin" DIR_SEPARATOR_STR); | 606 | execpath, |
518 | break; | 607 | DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR, |
519 | 608 | (NULL != multiarch) ? multiarch : "", | |
520 | case GNUNET_OS_IPK_LIBDIR: | 609 | dirname); |
521 | if (isbasedir) | 610 | if (GNUNET_YES == GNUNET_DISK_directory_test (tmp, GNUNET_YES)) |
522 | { | 611 | { |
523 | GNUNET_asprintf(&tmp, | 612 | GNUNET_free (execpath); |
524 | "%s%s%s%s%s%s%s", | 613 | GNUNET_free (dirname); |
525 | execpath, | 614 | return tmp; |
526 | DIR_SEPARATOR_STR "lib", | 615 | } |
527 | (NULL != multiarch) ? DIR_SEPARATOR_STR : "", | 616 | GNUNET_free (tmp); |
528 | (NULL != multiarch) ? multiarch : "", | 617 | tmp = NULL; |
529 | DIR_SEPARATOR_STR, | 618 | dirname = NULL; |
530 | current_pd->project_dirname, | 619 | if (4 == sizeof(void *)) |
531 | DIR_SEPARATOR_STR); | 620 | { |
532 | if (GNUNET_YES == GNUNET_DISK_directory_test(tmp, GNUNET_YES)) | 621 | GNUNET_asprintf (&dirname, |
533 | { | 622 | DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR |
534 | GNUNET_free(execpath); | 623 | "%s" DIR_SEPARATOR_STR |
535 | return tmp; | 624 | "libexec" DIR_SEPARATOR_STR, |
536 | } | 625 | current_pd->project_dirname); |
537 | GNUNET_free(tmp); | 626 | GNUNET_asprintf (&tmp, "%s%s", execpath, dirname); |
538 | tmp = NULL; | 627 | } |
539 | dirname = NULL; | 628 | if (8 == sizeof(void *)) |
540 | if (4 == sizeof(void *)) | 629 | { |
541 | { | 630 | GNUNET_asprintf (&dirname, |
542 | GNUNET_asprintf(&dirname, | 631 | DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR |
543 | DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR | 632 | "%s" DIR_SEPARATOR_STR |
544 | "%s" DIR_SEPARATOR_STR, | 633 | "libexec" DIR_SEPARATOR_STR, |
545 | current_pd->project_dirname); | 634 | current_pd->project_dirname); |
546 | GNUNET_asprintf(&tmp, "%s%s", execpath, dirname); | 635 | GNUNET_asprintf (&tmp, "%s%s", execpath, dirname); |
547 | } | 636 | } |
548 | if (8 == sizeof(void *)) | 637 | if ((NULL != tmp) && |
549 | { | 638 | (GNUNET_YES == GNUNET_DISK_directory_test (tmp, GNUNET_YES))) |
550 | GNUNET_asprintf(&dirname, | 639 | { |
551 | DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR | 640 | GNUNET_free (execpath); |
552 | "%s" DIR_SEPARATOR_STR, | 641 | GNUNET_free_non_null (dirname); |
553 | current_pd->project_dirname); | 642 | return tmp; |
554 | GNUNET_asprintf(&tmp, "%s%s", execpath, dirname); | 643 | } |
555 | } | 644 | GNUNET_free (tmp); |
556 | 645 | GNUNET_free_non_null (dirname); | |
557 | if ((NULL != tmp) && | ||
558 | (GNUNET_YES == GNUNET_DISK_directory_test(tmp, GNUNET_YES))) | ||
559 | { | ||
560 | GNUNET_free(execpath); | ||
561 | GNUNET_free_non_null(dirname); | ||
562 | return tmp; | ||
563 | } | ||
564 | GNUNET_free(tmp); | ||
565 | GNUNET_free_non_null(dirname); | ||
566 | } | ||
567 | GNUNET_asprintf(&dirname, | ||
568 | DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR, | ||
569 | current_pd->project_dirname); | ||
570 | break; | ||
571 | |||
572 | case GNUNET_OS_IPK_DATADIR: | ||
573 | GNUNET_asprintf(&dirname, | ||
574 | DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR | ||
575 | "%s" DIR_SEPARATOR_STR, | ||
576 | current_pd->project_dirname); | ||
577 | break; | ||
578 | |||
579 | case GNUNET_OS_IPK_LOCALEDIR: | ||
580 | dirname = GNUNET_strdup(DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR | ||
581 | "locale" DIR_SEPARATOR_STR); | ||
582 | break; | ||
583 | |||
584 | case GNUNET_OS_IPK_ICONDIR: | ||
585 | dirname = GNUNET_strdup(DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR | ||
586 | "icons" DIR_SEPARATOR_STR); | ||
587 | break; | ||
588 | |||
589 | case GNUNET_OS_IPK_DOCDIR: | ||
590 | GNUNET_asprintf(&dirname, | ||
591 | DIR_SEPARATOR_STR "share" DIR_SEPARATOR_STR | ||
592 | "doc" DIR_SEPARATOR_STR | ||
593 | "%s" DIR_SEPARATOR_STR, | ||
594 | current_pd->project_dirname); | ||
595 | break; | ||
596 | |||
597 | case GNUNET_OS_IPK_LIBEXECDIR: | ||
598 | if (isbasedir) | ||
599 | { | ||
600 | GNUNET_asprintf(&dirname, | ||
601 | DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR | ||
602 | "libexec" DIR_SEPARATOR_STR, | ||
603 | current_pd->project_dirname); | ||
604 | GNUNET_asprintf(&tmp, | ||
605 | "%s%s%s%s", | ||
606 | execpath, | ||
607 | DIR_SEPARATOR_STR "lib" DIR_SEPARATOR_STR, | ||
608 | (NULL != multiarch) ? multiarch : "", | ||
609 | dirname); | ||
610 | if (GNUNET_YES == GNUNET_DISK_directory_test(tmp, GNUNET_YES)) | ||
611 | { | ||
612 | GNUNET_free(execpath); | ||
613 | GNUNET_free(dirname); | ||
614 | return tmp; | ||
615 | } | ||
616 | GNUNET_free(tmp); | ||
617 | tmp = NULL; | ||
618 | dirname = NULL; | ||
619 | if (4 == sizeof(void *)) | ||
620 | { | ||
621 | GNUNET_asprintf(&dirname, | ||
622 | DIR_SEPARATOR_STR "lib32" DIR_SEPARATOR_STR | ||
623 | "%s" DIR_SEPARATOR_STR | ||
624 | "libexec" DIR_SEPARATOR_STR, | ||
625 | current_pd->project_dirname); | ||
626 | GNUNET_asprintf(&tmp, "%s%s", execpath, dirname); | ||
627 | } | ||
628 | if (8 == sizeof(void *)) | ||
629 | { | ||
630 | GNUNET_asprintf(&dirname, | ||
631 | DIR_SEPARATOR_STR "lib64" DIR_SEPARATOR_STR | ||
632 | "%s" DIR_SEPARATOR_STR | ||
633 | "libexec" DIR_SEPARATOR_STR, | ||
634 | current_pd->project_dirname); | ||
635 | GNUNET_asprintf(&tmp, "%s%s", execpath, dirname); | ||
636 | } | ||
637 | if ((NULL != tmp) && | ||
638 | (GNUNET_YES == GNUNET_DISK_directory_test(tmp, GNUNET_YES))) | ||
639 | { | ||
640 | GNUNET_free(execpath); | ||
641 | GNUNET_free_non_null(dirname); | ||
642 | return tmp; | ||
643 | } | ||
644 | GNUNET_free(tmp); | ||
645 | GNUNET_free_non_null(dirname); | ||
646 | } | ||
647 | GNUNET_asprintf(&dirname, | ||
648 | DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR | ||
649 | "libexec" DIR_SEPARATOR_STR, | ||
650 | current_pd->project_dirname); | ||
651 | break; | ||
652 | |||
653 | default: | ||
654 | GNUNET_free(execpath); | ||
655 | return NULL; | ||
656 | } | 646 | } |
657 | GNUNET_asprintf(&tmp, "%s%s", execpath, dirname); | 647 | GNUNET_asprintf (&dirname, |
658 | GNUNET_free(dirname); | 648 | DIR_SEPARATOR_STR "%s" DIR_SEPARATOR_STR |
659 | GNUNET_free(execpath); | 649 | "libexec" DIR_SEPARATOR_STR, |
650 | current_pd->project_dirname); | ||
651 | break; | ||
652 | |||
653 | default: | ||
654 | GNUNET_free (execpath); | ||
655 | return NULL; | ||
656 | } | ||
657 | GNUNET_asprintf (&tmp, "%s%s", execpath, dirname); | ||
658 | GNUNET_free (dirname); | ||
659 | GNUNET_free (execpath); | ||
660 | return tmp; | 660 | return tmp; |
661 | } | 661 | } |
662 | 662 | ||
@@ -670,7 +670,7 @@ GNUNET_OS_installation_get_path(enum GNUNET_OS_InstallationPathKind dirkind) | |||
670 | * @return full path to the binary, if possible, otherwise copy of 'progname' | 670 | * @return full path to the binary, if possible, otherwise copy of 'progname' |
671 | */ | 671 | */ |
672 | char * | 672 | char * |
673 | GNUNET_OS_get_libexec_binary_path(const char *progname) | 673 | GNUNET_OS_get_libexec_binary_path (const char *progname) |
674 | { | 674 | { |
675 | static char *cache; | 675 | static char *cache; |
676 | char *libexecdir; | 676 | char *libexecdir; |
@@ -678,15 +678,15 @@ GNUNET_OS_get_libexec_binary_path(const char *progname) | |||
678 | 678 | ||
679 | if ((DIR_SEPARATOR == progname[0]) || | 679 | if ((DIR_SEPARATOR == progname[0]) || |
680 | (GNUNET_YES == | 680 | (GNUNET_YES == |
681 | GNUNET_STRINGS_path_is_absolute(progname, GNUNET_NO, NULL, NULL))) | 681 | GNUNET_STRINGS_path_is_absolute (progname, GNUNET_NO, NULL, NULL))) |
682 | return GNUNET_strdup(progname); | 682 | return GNUNET_strdup (progname); |
683 | if (NULL != cache) | 683 | if (NULL != cache) |
684 | libexecdir = cache; | 684 | libexecdir = cache; |
685 | else | 685 | else |
686 | libexecdir = GNUNET_OS_installation_get_path(GNUNET_OS_IPK_LIBEXECDIR); | 686 | libexecdir = GNUNET_OS_installation_get_path (GNUNET_OS_IPK_LIBEXECDIR); |
687 | if (NULL == libexecdir) | 687 | if (NULL == libexecdir) |
688 | return GNUNET_strdup(progname); | 688 | return GNUNET_strdup (progname); |
689 | GNUNET_asprintf(&binary, "%s%s", libexecdir, progname); | 689 | GNUNET_asprintf (&binary, "%s%s", libexecdir, progname); |
690 | cache = libexecdir; | 690 | cache = libexecdir; |
691 | return binary; | 691 | return binary; |
692 | } | 692 | } |
@@ -705,8 +705,8 @@ GNUNET_OS_get_libexec_binary_path(const char *progname) | |||
705 | * otherwise | 705 | * otherwise |
706 | */ | 706 | */ |
707 | char * | 707 | char * |
708 | GNUNET_OS_get_suid_binary_path(const struct GNUNET_CONFIGURATION_Handle *cfg, | 708 | GNUNET_OS_get_suid_binary_path (const struct GNUNET_CONFIGURATION_Handle *cfg, |
709 | const char *progname) | 709 | const char *progname) |
710 | { | 710 | { |
711 | static char *cache; | 711 | static char *cache; |
712 | char *binary = NULL; | 712 | char *binary = NULL; |
@@ -714,26 +714,26 @@ GNUNET_OS_get_suid_binary_path(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
714 | size_t path_len; | 714 | size_t path_len; |
715 | 715 | ||
716 | if (GNUNET_YES == | 716 | if (GNUNET_YES == |
717 | GNUNET_STRINGS_path_is_absolute(progname, GNUNET_NO, NULL, NULL)) | 717 | GNUNET_STRINGS_path_is_absolute (progname, GNUNET_NO, NULL, NULL)) |
718 | { | 718 | { |
719 | return GNUNET_strdup(progname); | 719 | return GNUNET_strdup (progname); |
720 | } | 720 | } |
721 | if (NULL != cache) | 721 | if (NULL != cache) |
722 | path = cache; | 722 | path = cache; |
723 | else | 723 | else |
724 | GNUNET_CONFIGURATION_get_value_string(cfg, | 724 | GNUNET_CONFIGURATION_get_value_string (cfg, |
725 | "PATHS", | 725 | "PATHS", |
726 | "SUID_BINARY_PATH", | 726 | "SUID_BINARY_PATH", |
727 | &path); | 727 | &path); |
728 | if ((NULL == path) || (0 == strlen(path))) | 728 | if ((NULL == path) || (0 == strlen (path))) |
729 | return GNUNET_OS_get_libexec_binary_path(progname); | 729 | return GNUNET_OS_get_libexec_binary_path (progname); |
730 | path_len = strlen(path); | 730 | path_len = strlen (path); |
731 | GNUNET_asprintf(&binary, | 731 | GNUNET_asprintf (&binary, |
732 | "%s%s%s", | 732 | "%s%s%s", |
733 | path, | 733 | path, |
734 | (path[path_len - 1] == DIR_SEPARATOR) ? "" | 734 | (path[path_len - 1] == DIR_SEPARATOR) ? "" |
735 | : DIR_SEPARATOR_STR, | 735 | : DIR_SEPARATOR_STR, |
736 | progname); | 736 | progname); |
737 | cache = path; | 737 | cache = path; |
738 | return binary; | 738 | return binary; |
739 | } | 739 | } |
@@ -756,72 +756,72 @@ GNUNET_OS_get_suid_binary_path(const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
756 | * #GNUNET_SYSERR on error (no such binary or not executable) | 756 | * #GNUNET_SYSERR on error (no such binary or not executable) |
757 | */ | 757 | */ |
758 | int | 758 | int |
759 | GNUNET_OS_check_helper_binary(const char *binary, | 759 | GNUNET_OS_check_helper_binary (const char *binary, |
760 | int check_suid, | 760 | int check_suid, |
761 | const char *params) | 761 | const char *params) |
762 | { | 762 | { |
763 | struct stat statbuf; | 763 | struct stat statbuf; |
764 | char *p; | 764 | char *p; |
765 | char *pf; | 765 | char *pf; |
766 | 766 | ||
767 | if ((GNUNET_YES == | 767 | if ((GNUNET_YES == |
768 | GNUNET_STRINGS_path_is_absolute(binary, GNUNET_NO, NULL, NULL)) || | 768 | GNUNET_STRINGS_path_is_absolute (binary, GNUNET_NO, NULL, NULL)) || |
769 | (0 == strncmp(binary, "./", 2))) | 769 | (0 == strncmp (binary, "./", 2))) |
770 | { | 770 | { |
771 | p = GNUNET_strdup(binary); | 771 | p = GNUNET_strdup (binary); |
772 | } | 772 | } |
773 | else | 773 | else |
774 | { | ||
775 | p = get_path_from_PATH (binary); | ||
776 | if (NULL != p) | ||
774 | { | 777 | { |
775 | p = get_path_from_PATH(binary); | 778 | GNUNET_asprintf (&pf, "%s/%s", p, binary); |
776 | if (NULL != p) | 779 | GNUNET_free (p); |
777 | { | 780 | p = pf; |
778 | GNUNET_asprintf(&pf, "%s/%s", p, binary); | ||
779 | GNUNET_free(p); | ||
780 | p = pf; | ||
781 | } | ||
782 | } | 781 | } |
782 | } | ||
783 | 783 | ||
784 | if (NULL == p) | 784 | if (NULL == p) |
785 | { | 785 | { |
786 | LOG(GNUNET_ERROR_TYPE_INFO, | 786 | LOG (GNUNET_ERROR_TYPE_INFO, |
787 | _("Could not find binary `%s' in PATH!\n"), | 787 | _ ("Could not find binary `%s' in PATH!\n"), |
788 | binary); | 788 | binary); |
789 | return GNUNET_SYSERR; | 789 | return GNUNET_SYSERR; |
790 | } | 790 | } |
791 | if (0 != access(p, X_OK)) | 791 | if (0 != access (p, X_OK)) |
792 | { | 792 | { |
793 | LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "access", p); | 793 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "access", p); |
794 | GNUNET_free(p); | 794 | GNUNET_free (p); |
795 | return GNUNET_SYSERR; | 795 | return GNUNET_SYSERR; |
796 | } | 796 | } |
797 | 797 | ||
798 | if (0 == getuid()) | 798 | if (0 == getuid ()) |
799 | { | 799 | { |
800 | /* as we run as root, we don't insist on SUID */ | 800 | /* as we run as root, we don't insist on SUID */ |
801 | GNUNET_free(p); | 801 | GNUNET_free (p); |
802 | return GNUNET_YES; | 802 | return GNUNET_YES; |
803 | } | 803 | } |
804 | 804 | ||
805 | if (0 != stat(p, &statbuf)) | 805 | if (0 != stat (p, &statbuf)) |
806 | { | 806 | { |
807 | LOG_STRERROR_FILE(GNUNET_ERROR_TYPE_WARNING, "stat", p); | 807 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "stat", p); |
808 | GNUNET_free(p); | 808 | GNUNET_free (p); |
809 | return GNUNET_SYSERR; | 809 | return GNUNET_SYSERR; |
810 | } | 810 | } |
811 | if (check_suid) | 811 | if (check_suid) |
812 | { | ||
813 | (void) params; | ||
814 | if ((0 != (statbuf.st_mode & S_ISUID)) && (0 == statbuf.st_uid)) | ||
812 | { | 815 | { |
813 | (void)params; | 816 | GNUNET_free (p); |
814 | if ((0 != (statbuf.st_mode & S_ISUID)) && (0 == statbuf.st_uid)) | 817 | return GNUNET_YES; |
815 | { | ||
816 | GNUNET_free(p); | ||
817 | return GNUNET_YES; | ||
818 | } | ||
819 | GNUNET_log(GNUNET_ERROR_TYPE_INFO, | ||
820 | _("Binary `%s' exists, but is not SUID\n"), | ||
821 | p); | ||
822 | /* binary exists, but not SUID */ | ||
823 | } | 818 | } |
824 | GNUNET_free(p); | 819 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, |
820 | _ ("Binary `%s' exists, but is not SUID\n"), | ||
821 | p); | ||
822 | /* binary exists, but not SUID */ | ||
823 | } | ||
824 | GNUNET_free (p); | ||
825 | return GNUNET_NO; | 825 | return GNUNET_NO; |
826 | } | 826 | } |
827 | 827 | ||