2 * Copyright (c) 2012 Todd C. Miller <Todd.Miller@courtesan.com>
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 #include <sys/types.h>
28 #endif /* STDC_HEADERS */
30 # if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS)
34 #endif /* HAVE_STRING_H */
37 #endif /* HAVE_STRINGS_H */
41 # include "compat/dlfcn.h"
50 # define LINE_MAX 2048
56 fprintf(stderr, "usage: load_symbols plugin.so symbols_file\n");
61 main(int argc, char *argv[])
64 const char *plugin_path;
65 const char *symbols_file;
66 char *cp, line[LINE_MAX];
68 int ntests = 0, errors = 0;
70 #if !defined(HAVE_GETPROGNAME) && !defined(HAVE___PROGNAME)
71 setprogname(argc > 0 ? argv[0] : "check_symbols");
76 plugin_path = argv[1];
77 symbols_file = argv[2];
79 handle = dlopen(plugin_path, RTLD_LAZY|RTLD_GLOBAL);
81 errorx2(1, "unable to dlopen %s: %s", plugin_path, dlerror());
83 fp = fopen(symbols_file, "r");
85 error2(1, "unable to open %s", symbols_file);
87 while (fgets(line, sizeof(line), fp) != NULL) {
89 if ((cp = strchr(line, '\n')) != NULL)
91 sym = dlsym(handle, line);
93 warningx2("unable to resolve symbol %s: %s", line, dlerror());
99 * Make sure unexported symbols are not available.
101 sym = dlsym(handle, "user_in_group");
103 warningx2("able to resolve local symbol user_in_group");
110 printf("check_symbols: %d tests run, %d errors, %d%% success rate\n",
111 ntests, errors, (ntests - errors) * 100 / ntests);