2 * Copyright (C) 2009 Martin Willi
3 * Hochschule fuer Technik Rapperswil, Switzerland
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
23 /* we need to fake the pluto symbol to dlopen() the xauth plugin */
26 int main(int argc
, char* argv
[])
29 integrity_checker_t
*integrity
;
31 /* avoid confusing leak reports in build process */
32 setenv("LEAK_DETECTIVE_DISABLE", "1", 0);
34 atexit(library_deinit
);
36 integrity
= integrity_checker_create(NULL
);
39 printf(" * checksums of files and loaded code segments.\n");
40 printf(" * created by %s\n", argv
[0]);
43 printf("#include <library.h>\n");
45 printf("integrity_checksum_t checksums[] = {\n");
46 fprintf(stderr
, "integrity test data:\n");
47 fprintf(stderr
, "module name, file size / checksum segment size / checksum\n");
48 for (i
= 1; i
< argc
; i
++)
50 char *name
, *path
, *sname
= NULL
;
51 void *handle
, *symbol
;
58 if ((name
= strstr(path
, "libstrongswan-")))
60 name
= strdup(name
+ strlen("libstrongswan-"));
61 name
[strlen(name
) - 3] = '"';
62 name
[strlen(name
) - 2] = ',';
63 name
[strlen(name
) - 1] = '\0';
64 if (asprintf(&sname
, "%.*s_plugin_create", strlen(name
) - 2,
67 fprintf(stderr
, "failed to format plugin constructor "
68 "for '%s', ignored", path
);
72 translate(sname
, "-", "_");
74 else if (strstr(path
, "libstrongswan.so"))
76 name
= strdup("libstrongswan\",");
77 sname
= strdup("library_init");
79 else if (strstr(path
, "libhydra.so"))
81 name
= strdup("libhydra\",");
82 sname
= strdup("libhydra_init");
84 else if (strstr(path
, "libcharon.so"))
86 name
= strdup("libcharon\",");
87 sname
= strdup("libcharon_init");
89 else if (strstr(path
, "pool"))
91 name
= strdup("pool\",");
93 else if (strstr(path
, "charon"))
95 name
= strdup("charon\",");
97 else if (strstr(path
, "pluto"))
99 name
= strdup("pluto\",");
101 else if (strstr(path
, "openac"))
103 name
= strdup("openac\",");
105 else if (strstr(path
, "scepclient"))
107 name
= strdup("scepclient\",");
109 else if (strstr(path
, "pki"))
111 name
= strdup("pki\",");
115 fprintf(stderr
, "don't know how to handle '%s', ignored", path
);
119 fsum
= integrity
->build_file(integrity
, path
, &fsize
);
123 handle
= dlopen(path
, RTLD_LAZY
);
126 symbol
= dlsym(handle
, sname
);
129 ssum
= integrity
->build_segment(integrity
, symbol
, &ssize
);
133 fprintf(stderr
, "symbol lookup failed: %s\n", dlerror());
139 fprintf(stderr
, "dlopen failed: %s\n", dlerror());
142 printf("\t{\"%-20s%7u, 0x%08x, %6u, 0x%08x},\n",
143 name
, fsize
, fsum
, ssize
, ssum
);
144 fprintf(stderr
, "\"%-20s%7u / 0x%08x %6u / 0x%08x\n",
145 name
, fsize
, fsum
, ssize
, ssum
);
151 printf("int checksum_count = countof(checksums);\n");
153 integrity
->destroy(integrity
);