diff options
Diffstat (limited to 'src/main/extractor_plugpath.c')
-rw-r--r-- | src/main/extractor_plugpath.c | 445 |
1 files changed, 226 insertions, 219 deletions
diff --git a/src/main/extractor_plugpath.c b/src/main/extractor_plugpath.c index 461f25e..4374bc5 100644 --- a/src/main/extractor_plugpath.c +++ b/src/main/extractor_plugpath.c | |||
@@ -41,7 +41,7 @@ | |||
41 | * @param path a directory path | 41 | * @param path a directory path |
42 | */ | 42 | */ |
43 | typedef void (*EXTRACTOR_PathProcessor) (void *cls, | 43 | typedef void (*EXTRACTOR_PathProcessor) (void *cls, |
44 | const char *path); | 44 | const char *path); |
45 | 45 | ||
46 | 46 | ||
47 | /** | 47 | /** |
@@ -51,7 +51,7 @@ typedef void (*EXTRACTOR_PathProcessor) (void *cls, | |||
51 | * @return NULL if 'in' is NULL, otherwise 'in' with '/bin/' removed | 51 | * @return NULL if 'in' is NULL, otherwise 'in' with '/bin/' removed |
52 | */ | 52 | */ |
53 | static char * | 53 | static char * |
54 | cut_bin (char * in) | 54 | cut_bin (char *in) |
55 | { | 55 | { |
56 | size_t p; | 56 | size_t p; |
57 | 57 | ||
@@ -60,21 +60,21 @@ cut_bin (char * in) | |||
60 | p = strlen (in); | 60 | p = strlen (in); |
61 | if (p < 4) | 61 | if (p < 4) |
62 | return in; | 62 | return in; |
63 | if ( ('/' == in[p-1]) || | 63 | if ( ('/' == in[p - 1]) || |
64 | ('\\' == in[p-1]) ) | 64 | ('\\' == in[p - 1]) ) |
65 | in[--p] = '\0'; | 65 | in[--p] = '\0'; |
66 | if (0 == strcmp (&in[p-4], | 66 | if (0 == strcmp (&in[p - 4], |
67 | "/bin")) | 67 | "/bin")) |
68 | { | 68 | { |
69 | in[p-4] = '\0'; | 69 | in[p - 4] = '\0'; |
70 | p -= 4; | 70 | p -= 4; |
71 | } | 71 | } |
72 | else if (0 == strcmp (&in[p-4], | 72 | else if (0 == strcmp (&in[p - 4], |
73 | "\\bin")) | 73 | "\\bin")) |
74 | { | 74 | { |
75 | in[p-4] = '\0'; | 75 | in[p - 4] = '\0'; |
76 | p -= 4; | 76 | p -= 4; |
77 | } | 77 | } |
78 | return in; | 78 | return in; |
79 | } | 79 | } |
80 | 80 | ||
@@ -100,60 +100,62 @@ get_path_from_proc_exe () | |||
100 | FILE *f; | 100 | FILE *f; |
101 | 101 | ||
102 | snprintf (fn, | 102 | snprintf (fn, |
103 | sizeof (fn), | 103 | sizeof (fn), |
104 | "/proc/%u/maps", | 104 | "/proc/%u/maps", |
105 | getpid ()); | 105 | getpid ()); |
106 | if (NULL != (f = FOPEN (fn, "r"))) | 106 | if (NULL != (f = FOPEN (fn, "r"))) |
107 | { | ||
108 | while (NULL != fgets (line, 1024, f)) | ||
107 | { | 109 | { |
108 | while (NULL != fgets (line, 1024, f)) | 110 | if ( (1 == sscanf (line, |
109 | { | 111 | "%*x-%*x %*c%*c%*c%*c %*x %*2x:%*2x %*u%*[ ]%s", |
110 | if ( (1 == sscanf (line, | 112 | dir)) && |
111 | "%*x-%*x %*c%*c%*c%*c %*x %*2x:%*2x %*u%*[ ]%s", | 113 | (NULL != (lestr = strstr (dir, |
112 | dir)) && | 114 | "libextractor")) ) ) |
113 | (NULL != (lestr = strstr (dir, | 115 | { |
114 | "libextractor")) ) ) | 116 | lestr[0] = '\0'; |
115 | { | 117 | fclose (f); |
116 | lestr[0] = '\0'; | 118 | return strdup (dir); |
117 | fclose (f); | 119 | } |
118 | return strdup (dir); | ||
119 | } | ||
120 | } | ||
121 | fclose (f); | ||
122 | } | 120 | } |
121 | fclose (f); | ||
122 | } | ||
123 | snprintf (fn, | 123 | snprintf (fn, |
124 | sizeof (fn), | 124 | sizeof (fn), |
125 | "/proc/%u/exe", | 125 | "/proc/%u/exe", |
126 | getpid ()); | 126 | getpid ()); |
127 | if (NULL == (lnk = malloc (1029))) /* 1024 + 6 for "/lib/" catenation */ | 127 | if (NULL == (lnk = malloc (1029))) /* 1024 + 6 for "/lib/" catenation */ |
128 | return NULL; | 128 | return NULL; |
129 | size = readlink (fn, lnk, 1023); | 129 | size = readlink (fn, lnk, 1023); |
130 | if ( (size <= 0) || (size >= 1024) ) | 130 | if ( (size <= 0) || (size >= 1024) ) |
131 | { | 131 | { |
132 | free (lnk); | 132 | free (lnk); |
133 | return NULL; | 133 | return NULL; |
134 | } | 134 | } |
135 | lnk[size] = '\0'; | 135 | lnk[size] = '\0'; |
136 | while ( ('/' != lnk[size]) && | 136 | while ( ('/' != lnk[size]) && |
137 | (size > 0) ) | 137 | (size > 0) ) |
138 | size--; | 138 | size--; |
139 | if ( (size < 4) || | 139 | if ( (size < 4) || |
140 | ('/' != lnk[size-4]) ) | 140 | ('/' != lnk[size - 4]) ) |
141 | { | 141 | { |
142 | /* not installed in "/bin/" -- binary path probably useless */ | 142 | /* not installed in "/bin/" -- binary path probably useless */ |
143 | free (lnk); | 143 | free (lnk); |
144 | return NULL; | 144 | return NULL; |
145 | } | 145 | } |
146 | lnk[size] = '\0'; | 146 | lnk[size] = '\0'; |
147 | lnk = cut_bin (lnk); | 147 | lnk = cut_bin (lnk); |
148 | if (NULL == (ret = realloc (lnk, strlen(lnk) + 6))) | 148 | if (NULL == (ret = realloc (lnk, strlen (lnk) + 6))) |
149 | { | 149 | { |
150 | LOG_STRERROR ("realloc"); | 150 | LOG_STRERROR ("realloc"); |
151 | free (lnk); | 151 | free (lnk); |
152 | return NULL; | 152 | return NULL; |
153 | } | 153 | } |
154 | strcat (ret, "/lib/"); /* guess "lib/" as the library dir */ | 154 | strcat (ret, "/lib/"); /* guess "lib/" as the library dir */ |
155 | return ret; | 155 | return ret; |
156 | } | 156 | } |
157 | |||
158 | |||
157 | #endif | 159 | #endif |
158 | 160 | ||
159 | 161 | ||
@@ -162,8 +164,8 @@ static HMODULE le_dll = NULL; | |||
162 | 164 | ||
163 | BOOL WINAPI | 165 | BOOL WINAPI |
164 | DllMain (HINSTANCE hinstDLL, | 166 | DllMain (HINSTANCE hinstDLL, |
165 | DWORD fdwReason, | 167 | DWORD fdwReason, |
166 | LPVOID lpvReserved) | 168 | LPVOID lpvReserved) |
167 | { | 169 | { |
168 | switch (fdwReason) | 170 | switch (fdwReason) |
169 | { | 171 | { |
@@ -175,6 +177,7 @@ DllMain (HINSTANCE hinstDLL, | |||
175 | return TRUE; | 177 | return TRUE; |
176 | } | 178 | } |
177 | 179 | ||
180 | |||
178 | /** | 181 | /** |
179 | * Try to determine path with win32-specific function | 182 | * Try to determine path with win32-specific function |
180 | */ | 183 | */ |
@@ -190,20 +193,22 @@ get_path_from_module_filename () | |||
190 | GetModuleFileName (le_dll, path, 4096); | 193 | GetModuleFileName (le_dll, path, 4096); |
191 | idx = path + strlen (path); | 194 | idx = path + strlen (path); |
192 | while ( (idx > path) && | 195 | while ( (idx > path) && |
193 | ('\\' != *idx) && | 196 | ('\\' != *idx) && |
194 | ('/' != *idx) ) | 197 | ('/' != *idx) ) |
195 | idx--; | 198 | idx--; |
196 | *idx = '\0'; | 199 | *idx = '\0'; |
197 | path = cut_bin (path); | 200 | path = cut_bin (path); |
198 | if (NULL == (ret = realloc (path, strlen(path) + 6))) | 201 | if (NULL == (ret = realloc (path, strlen (path) + 6))) |
199 | { | 202 | { |
200 | LOG_STRERROR ("realloc"); | 203 | LOG_STRERROR ("realloc"); |
201 | free (path); | 204 | free (path); |
202 | return NULL; | 205 | return NULL; |
203 | } | 206 | } |
204 | strcat (ret, "/lib/"); /* guess "lib/" as the library dir */ | 207 | strcat (ret, "/lib/"); /* guess "lib/" as the library dir */ |
205 | return ret; | 208 | return ret; |
206 | } | 209 | } |
210 | |||
211 | |||
207 | #endif | 212 | #endif |
208 | 213 | ||
209 | 214 | ||
@@ -239,8 +244,8 @@ get_path_from_NSGetExecutablePath () | |||
239 | 244 | ||
240 | path = NULL; | 245 | path = NULL; |
241 | if (NULL == (func = | 246 | if (NULL == (func = |
242 | (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, | 247 | (MyNSGetExecutablePathProto) dlsym (RTLD_DEFAULT, |
243 | "_NSGetExecutablePath"))) | 248 | "_NSGetExecutablePath"))) |
244 | return NULL; | 249 | return NULL; |
245 | path = &zero; | 250 | path = &zero; |
246 | len = 0; | 251 | len = 0; |
@@ -249,10 +254,10 @@ get_path_from_NSGetExecutablePath () | |||
249 | if (0 == len) | 254 | if (0 == len) |
250 | return NULL; | 255 | return NULL; |
251 | if (NULL == (path = malloc (len))) | 256 | if (NULL == (path = malloc (len))) |
252 | { | 257 | { |
253 | LOG_STRERROR ("malloc"); | 258 | LOG_STRERROR ("malloc"); |
254 | return NULL; | 259 | return NULL; |
255 | } | 260 | } |
256 | if (0 != func (path, &len)) | 261 | if (0 != func (path, &len)) |
257 | { | 262 | { |
258 | free (path); | 263 | free (path); |
@@ -267,9 +272,9 @@ get_path_from_NSGetExecutablePath () | |||
267 | path = cut_bin (path); | 272 | path = cut_bin (path); |
268 | if (NULL == (ret = realloc (path, strlen (path) + 5))) | 273 | if (NULL == (ret = realloc (path, strlen (path) + 5))) |
269 | { | 274 | { |
270 | LOG_STRERROR ("realloc"); | 275 | LOG_STRERROR ("realloc"); |
271 | free (path); | 276 | free (path); |
272 | return NULL; | 277 | return NULL; |
273 | } | 278 | } |
274 | strcat (ret, "/lib/"); | 279 | strcat (ret, "/lib/"); |
275 | return ret; | 280 | return ret; |
@@ -292,26 +297,28 @@ get_path_from_dyld_image () | |||
292 | 297 | ||
293 | c = _dyld_image_count (); | 298 | c = _dyld_image_count (); |
294 | for (i = 0; i < c; i++) | 299 | for (i = 0; i < c; i++) |
300 | { | ||
301 | if (((void *) _dyld_get_image_header (i)) != (void *) &_mh_dylib_header) | ||
302 | continue; | ||
303 | path = _dyld_get_image_name (i); | ||
304 | if ( (NULL == path) || (0 == strlen (path)) ) | ||
305 | continue; | ||
306 | if (NULL == (p = strdup (path))) | ||
295 | { | 307 | { |
296 | if (((void *) _dyld_get_image_header (i)) != (void *) &_mh_dylib_header) | 308 | LOG_STRERROR ("strdup"); |
297 | continue; | 309 | return NULL; |
298 | path = _dyld_get_image_name (i); | ||
299 | if ( (NULL == path) || (0 == strlen (path)) ) | ||
300 | continue; | ||
301 | if (NULL == (p = strdup (path))) | ||
302 | { | ||
303 | LOG_STRERROR ("strdup"); | ||
304 | return NULL; | ||
305 | } | ||
306 | s = p + strlen (p); | ||
307 | while ( (s > p) && ('/' != *s) ) | ||
308 | s--; | ||
309 | s++; | ||
310 | *s = '\0'; | ||
311 | return p; | ||
312 | } | 310 | } |
311 | s = p + strlen (p); | ||
312 | while ( (s > p) && ('/' != *s) ) | ||
313 | s--; | ||
314 | s++; | ||
315 | *s = '\0'; | ||
316 | return p; | ||
317 | } | ||
313 | return NULL; | 318 | return NULL; |
314 | } | 319 | } |
320 | |||
321 | |||
315 | #endif | 322 | #endif |
316 | 323 | ||
317 | 324 | ||
@@ -322,7 +329,7 @@ get_path_from_dyld_image () | |||
322 | * @return path to binary, NULL if not found | 329 | * @return path to binary, NULL if not found |
323 | */ | 330 | */ |
324 | static char * | 331 | static char * |
325 | get_path_from_PATH() | 332 | get_path_from_PATH () |
326 | { | 333 | { |
327 | struct stat sbuf; | 334 | struct stat sbuf; |
328 | char *path; | 335 | char *path; |
@@ -335,61 +342,61 @@ get_path_from_PATH() | |||
335 | if (NULL == (p = getenv ("PATH"))) | 342 | if (NULL == (p = getenv ("PATH"))) |
336 | return NULL; | 343 | return NULL; |
337 | if (NULL == (path = strdup (p))) /* because we write on it */ | 344 | if (NULL == (path = strdup (p))) /* because we write on it */ |
338 | { | 345 | { |
339 | LOG_STRERROR ("strdup"); | 346 | LOG_STRERROR ("strdup"); |
340 | return NULL; | 347 | return NULL; |
341 | } | 348 | } |
342 | if (NULL == (buf = malloc (strlen (path) + 20))) | 349 | if (NULL == (buf = malloc (strlen (path) + 20))) |
343 | { | 350 | { |
344 | LOG_STRERROR ("malloc"); | 351 | LOG_STRERROR ("malloc"); |
345 | free (path); | 352 | free (path); |
346 | return NULL; | 353 | return NULL; |
347 | } | 354 | } |
348 | pos = path; | 355 | pos = path; |
349 | while (NULL != (end = strchr(pos, ':'))) | 356 | while (NULL != (end = strchr (pos, ':'))) |
350 | { | 357 | { |
351 | *end = '\0'; | 358 | *end = '\0'; |
352 | sprintf (buf, "%s/%s", pos, "extract"); | 359 | sprintf (buf, "%s/%s", pos, "extract"); |
353 | if (0 == stat(buf, &sbuf)) | 360 | if (0 == stat (buf, &sbuf)) |
354 | { | ||
355 | free (buf); | ||
356 | if (NULL == (pos = strdup (pos))) | ||
357 | { | ||
358 | LOG_STRERROR ("strdup"); | ||
359 | free (path); | ||
360 | return NULL; | ||
361 | } | ||
362 | free (path); | ||
363 | pos = cut_bin (pos); | ||
364 | if (NULL == (ret = realloc (pos, strlen (pos) + 6))) | ||
365 | { | ||
366 | LOG_STRERROR ("realloc"); | ||
367 | free (pos); | ||
368 | return NULL; | ||
369 | } | ||
370 | strcat (ret, "/lib/"); | ||
371 | return ret; | ||
372 | } | ||
373 | pos = end + 1; | ||
374 | } | ||
375 | sprintf (buf, "%s/%s", pos, "extract"); | ||
376 | if (0 == stat (buf, &sbuf)) | ||
377 | { | 361 | { |
378 | pos = strdup (pos); | ||
379 | free (buf); | 362 | free (buf); |
363 | if (NULL == (pos = strdup (pos))) | ||
364 | { | ||
365 | LOG_STRERROR ("strdup"); | ||
366 | free (path); | ||
367 | return NULL; | ||
368 | } | ||
380 | free (path); | 369 | free (path); |
381 | if (NULL == pos) | ||
382 | return NULL; | ||
383 | pos = cut_bin (pos); | 370 | pos = cut_bin (pos); |
384 | if (NULL == (ret = realloc (pos, strlen (pos) + 6))) | 371 | if (NULL == (ret = realloc (pos, strlen (pos) + 6))) |
385 | { | 372 | { |
386 | LOG_STRERROR ("realloc"); | 373 | LOG_STRERROR ("realloc"); |
387 | free (pos); | 374 | free (pos); |
388 | return NULL; | 375 | return NULL; |
389 | } | 376 | } |
390 | strcat (ret, "/lib/"); | 377 | strcat (ret, "/lib/"); |
391 | return ret; | 378 | return ret; |
392 | } | 379 | } |
380 | pos = end + 1; | ||
381 | } | ||
382 | sprintf (buf, "%s/%s", pos, "extract"); | ||
383 | if (0 == stat (buf, &sbuf)) | ||
384 | { | ||
385 | pos = strdup (pos); | ||
386 | free (buf); | ||
387 | free (path); | ||
388 | if (NULL == pos) | ||
389 | return NULL; | ||
390 | pos = cut_bin (pos); | ||
391 | if (NULL == (ret = realloc (pos, strlen (pos) + 6))) | ||
392 | { | ||
393 | LOG_STRERROR ("realloc"); | ||
394 | free (pos); | ||
395 | return NULL; | ||
396 | } | ||
397 | strcat (ret, "/lib/"); | ||
398 | return ret; | ||
399 | } | ||
393 | free (buf); | 400 | free (buf); |
394 | free (path); | 401 | free (path); |
395 | return NULL; | 402 | return NULL; |
@@ -405,7 +412,7 @@ get_path_from_PATH() | |||
405 | */ | 412 | */ |
406 | static char * | 413 | static char * |
407 | append_to_dir (const char *path, | 414 | append_to_dir (const char *path, |
408 | const char *fname) | 415 | const char *fname) |
409 | { | 416 | { |
410 | char *ret; | 417 | char *ret; |
411 | size_t slen; | 418 | size_t slen; |
@@ -414,31 +421,31 @@ append_to_dir (const char *path, | |||
414 | return NULL; | 421 | return NULL; |
415 | if (DIR_SEPARATOR == fname[0]) | 422 | if (DIR_SEPARATOR == fname[0]) |
416 | fname++; | 423 | fname++; |
417 | ret = malloc (slen + strlen(fname) + 2); | 424 | ret = malloc (slen + strlen (fname) + 2); |
418 | if (NULL == ret) | 425 | if (NULL == ret) |
419 | return NULL; | 426 | return NULL; |
420 | #ifdef MINGW | 427 | #ifdef MINGW |
421 | if ('\\' == path[slen-1]) | 428 | if ('\\' == path[slen - 1]) |
422 | sprintf (ret, | 429 | sprintf (ret, |
423 | "%s%s", | 430 | "%s%s", |
424 | path, | 431 | path, |
425 | fname); | 432 | fname); |
426 | else | 433 | else |
427 | sprintf (ret, | 434 | sprintf (ret, |
428 | "%s\\%s", | 435 | "%s\\%s", |
429 | path, | 436 | path, |
430 | fname); | 437 | fname); |
431 | #else | 438 | #else |
432 | if ('/' == path[slen-1]) | 439 | if ('/' == path[slen - 1]) |
433 | sprintf (ret, | 440 | sprintf (ret, |
434 | "%s%s", | 441 | "%s%s", |
435 | path, | 442 | path, |
436 | fname); | 443 | fname); |
437 | else | 444 | else |
438 | sprintf (ret, | 445 | sprintf (ret, |
439 | "%s/%s", | 446 | "%s/%s", |
440 | path, | 447 | path, |
441 | fname); | 448 | fname); |
442 | #endif | 449 | #endif |
443 | return ret; | 450 | return ret; |
444 | } | 451 | } |
@@ -453,7 +460,7 @@ append_to_dir (const char *path, | |||
453 | */ | 460 | */ |
454 | static void | 461 | static void |
455 | get_installation_paths (EXTRACTOR_PathProcessor pp, | 462 | get_installation_paths (EXTRACTOR_PathProcessor pp, |
456 | void *pp_cls) | 463 | void *pp_cls) |
457 | { | 464 | { |
458 | const char *p; | 465 | const char *p; |
459 | char *path; | 466 | char *path; |
@@ -463,19 +470,19 @@ get_installation_paths (EXTRACTOR_PathProcessor pp, | |||
463 | 470 | ||
464 | prefix = NULL; | 471 | prefix = NULL; |
465 | if (NULL != (p = getenv ("LIBEXTRACTOR_PREFIX"))) | 472 | if (NULL != (p = getenv ("LIBEXTRACTOR_PREFIX"))) |
473 | { | ||
474 | if (NULL == (d = strdup (p))) | ||
466 | { | 475 | { |
467 | if (NULL == (d = strdup (p))) | 476 | LOG_STRERROR ("strdup"); |
468 | { | ||
469 | LOG_STRERROR ("strdup"); | ||
470 | return; | ||
471 | } | ||
472 | for (prefix = strtok_r (d, PATH_SEPARATOR_STR, &saveptr); | ||
473 | NULL != prefix; | ||
474 | prefix = strtok_r (NULL, PATH_SEPARATOR_STR, &saveptr)) | ||
475 | pp (pp_cls, prefix); | ||
476 | free (d); | ||
477 | return; | 477 | return; |
478 | } | 478 | } |
479 | for (prefix = strtok_r (d, PATH_SEPARATOR_STR, &saveptr); | ||
480 | NULL != prefix; | ||
481 | prefix = strtok_r (NULL, PATH_SEPARATOR_STR, &saveptr)) | ||
482 | pp (pp_cls, prefix); | ||
483 | free (d); | ||
484 | return; | ||
485 | } | ||
479 | #if GNU_LINUX | 486 | #if GNU_LINUX |
480 | if (NULL == prefix) | 487 | if (NULL == prefix) |
481 | prefix = get_path_from_proc_exe (); | 488 | prefix = get_path_from_proc_exe (); |
@@ -497,12 +504,12 @@ get_installation_paths (EXTRACTOR_PathProcessor pp, | |||
497 | return; | 504 | return; |
498 | path = append_to_dir (prefix, PLUGINDIR); | 505 | path = append_to_dir (prefix, PLUGINDIR); |
499 | if (NULL != path) | 506 | if (NULL != path) |
500 | { | 507 | { |
501 | if (0 != strcmp (path, | 508 | if (0 != strcmp (path, |
502 | PLUGININSTDIR)) | 509 | PLUGININSTDIR)) |
503 | pp (pp_cls, path); | 510 | pp (pp_cls, path); |
504 | free (path); | 511 | free (path); |
505 | } | 512 | } |
506 | free (prefix); | 513 | free (prefix); |
507 | } | 514 | } |
508 | 515 | ||
@@ -532,7 +539,7 @@ struct SearchContext | |||
532 | */ | 539 | */ |
533 | static void | 540 | static void |
534 | find_plugin_in_path (void *cls, | 541 | find_plugin_in_path (void *cls, |
535 | const char *path) | 542 | const char *path) |
536 | { | 543 | { |
537 | struct SearchContext *sc = cls; | 544 | struct SearchContext *sc = cls; |
538 | DIR *dir; | 545 | DIR *dir; |
@@ -547,34 +554,34 @@ find_plugin_in_path (void *cls, | |||
547 | if (NULL == (dir = OPENDIR (path))) | 554 | if (NULL == (dir = OPENDIR (path))) |
548 | return; | 555 | return; |
549 | while (NULL != (ent = READDIR (dir))) | 556 | while (NULL != (ent = READDIR (dir))) |
557 | { | ||
558 | if ('.' == ent->d_name[0]) | ||
559 | continue; | ||
560 | dlen = strlen (ent->d_name); | ||
561 | if ( (dlen < 4) || | ||
562 | ( (0 != strcmp (&ent->d_name[dlen - 3], ".so")) && | ||
563 | (0 != strcasecmp (&ent->d_name[dlen - 4], ".dll")) ) ) | ||
564 | continue; /* only load '.so' and '.dll' */ | ||
565 | if (NULL == (sym_name = strrchr (ent->d_name, '_'))) | ||
566 | continue; | ||
567 | sym_name++; | ||
568 | if (NULL == (sym = strdup (sym_name))) | ||
569 | { | ||
570 | LOG_STRERROR ("strdup"); | ||
571 | CLOSEDIR (dir); | ||
572 | return; | ||
573 | } | ||
574 | dot = strchr (sym, '.'); | ||
575 | if (NULL != dot) | ||
576 | *dot = '\0'; | ||
577 | if (0 == strcmp (sym, sc->short_name)) | ||
550 | { | 578 | { |
551 | if ('.' == ent->d_name[0]) | 579 | sc->path = append_to_dir (path, ent->d_name); |
552 | continue; | ||
553 | dlen = strlen (ent->d_name); | ||
554 | if ( (dlen < 4) || | ||
555 | ( (0 != strcmp (&ent->d_name[dlen-3], ".so")) && | ||
556 | (0 != strcasecmp (&ent->d_name[dlen-4], ".dll")) ) ) | ||
557 | continue; /* only load '.so' and '.dll' */ | ||
558 | if (NULL == (sym_name = strrchr (ent->d_name, '_'))) | ||
559 | continue; | ||
560 | sym_name++; | ||
561 | if (NULL == (sym = strdup (sym_name))) | ||
562 | { | ||
563 | LOG_STRERROR ("strdup"); | ||
564 | CLOSEDIR (dir); | ||
565 | return; | ||
566 | } | ||
567 | dot = strchr (sym, '.'); | ||
568 | if (NULL != dot) | ||
569 | *dot = '\0'; | ||
570 | if (0 == strcmp (sym, sc->short_name)) | ||
571 | { | ||
572 | sc->path = append_to_dir (path, ent->d_name); | ||
573 | free (sym); | ||
574 | break; | ||
575 | } | ||
576 | free (sym); | 580 | free (sym); |
581 | break; | ||
577 | } | 582 | } |
583 | free (sym); | ||
584 | } | ||
578 | CLOSEDIR (dir); | 585 | CLOSEDIR (dir); |
579 | } | 586 | } |
580 | 587 | ||
@@ -591,7 +598,7 @@ EXTRACTOR_find_plugin_ (const char *short_name) | |||
591 | sc.path = NULL; | 598 | sc.path = NULL; |
592 | sc.short_name = short_name; | 599 | sc.short_name = short_name; |
593 | get_installation_paths (&find_plugin_in_path, | 600 | get_installation_paths (&find_plugin_in_path, |
594 | &sc); | 601 | &sc); |
595 | return sc.path; | 602 | return sc.path; |
596 | } | 603 | } |
597 | 604 | ||
@@ -621,7 +628,7 @@ struct DefaultLoaderContext | |||
621 | */ | 628 | */ |
622 | static void | 629 | static void |
623 | load_plugins_from_dir (void *cls, | 630 | load_plugins_from_dir (void *cls, |
624 | const char *path) | 631 | const char *path) |
625 | { | 632 | { |
626 | struct DefaultLoaderContext *dlc = cls; | 633 | struct DefaultLoaderContext *dlc = cls; |
627 | DIR *dir; | 634 | DIR *dir; |
@@ -634,31 +641,31 @@ load_plugins_from_dir (void *cls, | |||
634 | if (NULL == (dir = opendir (path))) | 641 | if (NULL == (dir = opendir (path))) |
635 | return; | 642 | return; |
636 | while (NULL != (ent = readdir (dir))) | 643 | while (NULL != (ent = readdir (dir))) |
644 | { | ||
645 | if (ent->d_name[0] == '.') | ||
646 | continue; | ||
647 | dlen = strlen (ent->d_name); | ||
648 | if ( (dlen < 4) || | ||
649 | ( (0 != strcmp (&ent->d_name[dlen - 3], ".so")) && | ||
650 | (0 != strcasecmp (&ent->d_name[dlen - 4], ".dll")) ) ) | ||
651 | continue; /* only load '.so' and '.dll' */ | ||
652 | if (NULL == (sym_name = strrchr (ent->d_name, '_'))) | ||
653 | continue; | ||
654 | sym_name++; | ||
655 | if (NULL == (sym = strdup (sym_name))) | ||
637 | { | 656 | { |
638 | if (ent->d_name[0] == '.') | 657 | LOG_STRERROR ("strdup"); |
639 | continue; | 658 | closedir (dir); |
640 | dlen = strlen (ent->d_name); | 659 | return; |
641 | if ( (dlen < 4) || | ||
642 | ( (0 != strcmp (&ent->d_name[dlen-3], ".so")) && | ||
643 | (0 != strcasecmp (&ent->d_name[dlen-4], ".dll")) ) ) | ||
644 | continue; /* only load '.so' and '.dll' */ | ||
645 | if (NULL == (sym_name = strrchr (ent->d_name, '_'))) | ||
646 | continue; | ||
647 | sym_name++; | ||
648 | if (NULL == (sym = strdup (sym_name))) | ||
649 | { | ||
650 | LOG_STRERROR ("strdup"); | ||
651 | closedir (dir); | ||
652 | return; | ||
653 | } | ||
654 | if (NULL != (dot = strchr (sym, '.'))) | ||
655 | *dot = '\0'; | ||
656 | dlc->res = EXTRACTOR_plugin_add (dlc->res, | ||
657 | sym, | ||
658 | NULL, | ||
659 | dlc->flags); | ||
660 | free (sym); | ||
661 | } | 660 | } |
661 | if (NULL != (dot = strchr (sym, '.'))) | ||
662 | *dot = '\0'; | ||
663 | dlc->res = EXTRACTOR_plugin_add (dlc->res, | ||
664 | sym, | ||
665 | NULL, | ||
666 | dlc->flags); | ||
667 | free (sym); | ||
668 | } | ||
662 | closedir (dir); | 669 | closedir (dir); |
663 | } | 670 | } |
664 | 671 | ||
@@ -685,7 +692,7 @@ EXTRACTOR_plugin_add_defaults (enum EXTRACTOR_Options flags) | |||
685 | dlc.res = NULL; | 692 | dlc.res = NULL; |
686 | dlc.flags = flags; | 693 | dlc.flags = flags; |
687 | get_installation_paths (&load_plugins_from_dir, | 694 | get_installation_paths (&load_plugins_from_dir, |
688 | &dlc); | 695 | &dlc); |
689 | return dlc.res; | 696 | return dlc.res; |
690 | } | 697 | } |
691 | 698 | ||