Path: blob/main/logsrvd/regress/logsrvd_conf/logsrvd_conf_test.c
1532 views
/*1* SPDX-License-Identifier: ISC2*3* Copyright (c) 2022 Todd C. Miller <[email protected]>4*5* Permission to use, copy, modify, and distribute this software for any6* purpose with or without fee is hereby granted, provided that the above7* copyright notice and this permission notice appear in all copies.8*9* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES10* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF11* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR12* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES13* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN14* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF15* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.16*/1718#include <config.h>1920#include <sys/socket.h>2122#ifdef HAVE_STDBOOL_H23# include <stdbool.h>24#else25# include <compat/stdbool.h>26#endif /* HAVE_STDBOOL_H */27#include <stdio.h>28#include <stdlib.h>29#include <string.h>30#include <unistd.h>3132#include <sudo_compat.h>33#include <sudo_util.h>34#include <sudo_iolog.h>35#include <sudo_queue.h>36#include <logsrvd.h>3738sudo_dso_public int main(int argc, char *argv[]);3940sudo_noreturn static void41usage(void)42{43fprintf(stderr, "usage: %s [-v] conf_file\n", getprogname());44exit(EXIT_FAILURE);45}4647/*48* Simple test driver for logsrvd_conf_read().49* Just pases the file, errors to standard error.50*/51int52main(int argc, char *argv[])53{54bool verbose = false;55int ch, ntests, errors = 0;5657initprogname(argc > 0 ? argv[0] : "conf_test");5859while ((ch = getopt(argc, argv, "v")) != -1) {60switch (ch) {61case 'v':62verbose = true;63break;64default:65usage();66/* NOTREACHED */67}68}69argc -= optind;70argv += optind;7172if (argc < 1)73usage();7475for (ntests = 0; ntests < argc; ntests++) {76const char *path = argv[ntests];77if (verbose)78printf("reading %s\n", path);79if (!logsrvd_conf_read(path))80errors++;81}82logsrvd_conf_cleanup();8384if (ntests != 0) {85printf("%s: %d tests run, %d errors, %d%% success rate\n",86getprogname(), ntests, errors, (ntests - errors) * 100 / ntests);87}88return errors;89}909192