Annotation of embedaddon/sudo/plugins/sudoers/regress/check_symbols/check_symbols.c, revision 1.1.1.4

1.1       misho       1: /*
1.1.1.2   misho       2:  * Copyright (c) 2012-2013 Todd C. Miller <Todd.Miller@courtesan.com>
1.1       misho       3:  *
                      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.
                      7:  *
                      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.
                     15:  */
                     16: 
                     17: #include <config.h>
                     18: 
                     19: #include <sys/types.h>
                     20: #include <stdio.h>
                     21: #ifdef STDC_HEADERS
                     22: # include <stdlib.h>
                     23: # include <stddef.h>
                     24: #else
                     25: # ifdef HAVE_STDLIB_H
                     26: #  include <stdlib.h>
                     27: # endif
                     28: #endif /* STDC_HEADERS */
                     29: #ifdef HAVE_STRING_H
                     30: # if defined(HAVE_MEMORY_H) && !defined(STDC_HEADERS)
                     31: #  include <memory.h>
                     32: # endif
                     33: # include <string.h>
                     34: #endif /* HAVE_STRING_H */
                     35: #ifdef HAVE_STRINGS_H
                     36: # include <strings.h>
                     37: #endif /* HAVE_STRINGS_H */
                     38: #include <errno.h>
                     39: #include <limits.h>
                     40: 
                     41: #include "missing.h"
1.1.1.4 ! misho      42: #include "sudo_dso.h"
        !            43: #include "sudo_util.h"
1.1.1.3   misho      44: #include "fatal.h"
1.1       misho      45: 
                     46: #ifndef LINE_MAX
                     47: # define LINE_MAX 2048
                     48: #endif
                     49: 
1.1.1.2   misho      50: __dso_public int main(int argc, char *argv[]);
                     51: 
1.1       misho      52: static void
                     53: usage(void)
                     54: {
1.1.1.4 ! misho      55:     fprintf(stderr, "usage: %s plugin.so symbols_file\n", getprogname());
1.1       misho      56:     exit(1);
                     57: }
                     58: 
                     59: int
                     60: main(int argc, char *argv[])
                     61: {
                     62:     void *handle, *sym;
                     63:     const char *plugin_path;
                     64:     const char *symbols_file;
                     65:     char *cp, line[LINE_MAX];
                     66:     FILE *fp;
                     67:     int ntests = 0, errors = 0;
                     68: 
1.1.1.4 ! misho      69:     initprogname(argc > 0 ? argv[0] : "check_symbols");
1.1       misho      70: 
                     71:     if (argc != 3)
                     72:        usage();
                     73:     plugin_path = argv[1];
                     74:     symbols_file = argv[2];
                     75: 
1.1.1.4 ! misho      76:     handle = sudo_dso_load(plugin_path, SUDO_DSO_LAZY|SUDO_DSO_GLOBAL);
1.1       misho      77:     if (handle == NULL)
1.1.1.4 ! misho      78:        fatalx_nodebug("unable to load %s: %s", plugin_path, sudo_dso_strerror());
1.1       misho      79: 
                     80:     fp = fopen(symbols_file, "r");
                     81:     if (fp == NULL)
1.1.1.2   misho      82:        fatal_nodebug("unable to open %s", symbols_file);
1.1       misho      83: 
                     84:     while (fgets(line, sizeof(line), fp) != NULL) {
                     85:        ntests++;
                     86:        if ((cp = strchr(line, '\n')) != NULL)
                     87:            *cp = '\0';
1.1.1.4 ! misho      88:        sym = sudo_dso_findsym(handle, line);
1.1       misho      89:        if (sym == NULL) {
1.1.1.2   misho      90:            printf("%s: test %d: unable to resolve symbol %s: %s\n",
1.1.1.4 ! misho      91:                getprogname(), ntests, line, sudo_dso_strerror());
1.1       misho      92:            errors++;
                     93:        }
                     94:     }
                     95: 
                     96:     /*
                     97:      * Make sure unexported symbols are not available.
                     98:      */
1.1.1.2   misho      99:     ntests++;
1.1.1.4 ! misho     100:     sym = sudo_dso_findsym(handle, "user_in_group");
1.1       misho     101:     if (sym != NULL) {
1.1.1.2   misho     102:        printf("%s: test %d: able to resolve local symbol user_in_group\n",
                    103:            getprogname(), ntests);
1.1       misho     104:        errors++;
                    105:     }
                    106: 
1.1.1.4 ! misho     107:     sudo_dso_unload(handle);
1.1       misho     108: 
1.1.1.2   misho     109:     printf("%s: %d tests run, %d errors, %d%% success rate\n", getprogname(),
1.1       misho     110:        ntests, errors, (ntests - errors) * 100 / ntests);
                    111: 
                    112:     exit(errors);
                    113: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>