1*b0d17251Schristos /*
2*b0d17251Schristos * Copyright 2020-2021 The OpenSSL Project Authors. All Rights Reserved.
3*b0d17251Schristos *
4*b0d17251Schristos * Licensed under the Apache License 2.0 (the "License"). You may not use
5*b0d17251Schristos * this file except in compliance with the License. You can obtain a copy
6*b0d17251Schristos * in the file LICENSE in the source distribution or at
7*b0d17251Schristos * https://www.openssl.org/source/license.html
8*b0d17251Schristos */
9*b0d17251Schristos
10*b0d17251Schristos /*
11*b0d17251Schristos * Extremely simple dynamic loader, must never be linked with anything other
12*b0d17251Schristos * than the standard C library. Its purpose is to try to load a dynamic module
13*b0d17251Schristos * and verify the presence of one symbol, if that's given.
14*b0d17251Schristos */
15*b0d17251Schristos
16*b0d17251Schristos #include <stdio.h>
17*b0d17251Schristos #include <stdlib.h>
18*b0d17251Schristos #include <openssl/core.h>
19*b0d17251Schristos #include "simpledynamic.h"
20*b0d17251Schristos
test_load(const char * path,const char * symbol)21*b0d17251Schristos static int test_load(const char *path, const char *symbol)
22*b0d17251Schristos {
23*b0d17251Schristos #ifdef SD_INIT
24*b0d17251Schristos SD sd = SD_INIT;
25*b0d17251Schristos SD_SYM sym;
26*b0d17251Schristos int ret;
27*b0d17251Schristos
28*b0d17251Schristos if (!sd_load(path, &sd, SD_MODULE))
29*b0d17251Schristos return 0;
30*b0d17251Schristos ret = symbol == NULL || sd_sym(sd, symbol, &sym);
31*b0d17251Schristos if (!sd_close(sd))
32*b0d17251Schristos ret = 0;
33*b0d17251Schristos return ret;
34*b0d17251Schristos #else
35*b0d17251Schristos fprintf(stderr, "No dynamic loader\n");
36*b0d17251Schristos return 0;
37*b0d17251Schristos #endif
38*b0d17251Schristos }
39*b0d17251Schristos
main(int argc,char * argv[])40*b0d17251Schristos int main(int argc, char *argv[])
41*b0d17251Schristos {
42*b0d17251Schristos const char *m, *s;
43*b0d17251Schristos
44*b0d17251Schristos if (argc != 2 && argc != 3) {
45*b0d17251Schristos fprintf(stderr, "Usage: %s sharedobject [ entrypoint ]\n", argv[0]);
46*b0d17251Schristos return 1;
47*b0d17251Schristos }
48*b0d17251Schristos
49*b0d17251Schristos m = argv[1];
50*b0d17251Schristos s = argc == 3 ? argv[2] : NULL;
51*b0d17251Schristos
52*b0d17251Schristos return test_load(m, s) ? 0 : 1;
53*b0d17251Schristos }
54