"Fossies" - the Fresh Open Source Software Archive

Member "sudo-1.9.11p3/plugins/sudoers/regress/env_match/check_env_pattern.c" (12 Jun 2022, 2026 Bytes) of package /linux/misc/sudo-1.9.11p3.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "check_env_pattern.c" see the Fossies "Dox" file reference documentation.

    1 /*
    2  * SPDX-License-Identifier: ISC
    3  *
    4  * Copyright (c) 2017 Todd C. Miller <Todd.Miller@sudo.ws>
    5  *
    6  * Permission to use, copy, modify, and distribute this software for any
    7  * purpose with or without fee is hereby granted, provided that the above
    8  * copyright notice and this permission notice appear in all copies.
    9  *
   10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
   11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
   12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
   13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
   14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
   15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
   16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
   17  */
   18 
   19 #include <config.h>
   20 
   21 #include <stdio.h>
   22 #include <stdlib.h>
   23 #include <string.h>
   24 
   25 #include "sudoers.h"
   26 
   27 sudo_dso_public int main(int argc, char *argv[]);
   28 
   29 int
   30 main(int argc, char *argv[])
   31 {
   32     FILE *fp = stdin;
   33     char pattern[1024], string[1024];
   34     int errors = 0, tests = 0, got, want;
   35 
   36     initprogname(argc > 0 ? argv[0] : "check_env_pattern");
   37 
   38     if (argc > 1) {
   39     if ((fp = fopen(argv[1], "r")) == NULL) {
   40         perror(argv[1]);
   41         exit(EXIT_FAILURE);
   42     }
   43     }
   44 
   45     /*
   46      * Read in test file, which is formatted thusly:
   47      *
   48      * pattern string 1/0
   49      *
   50      */
   51     for (;;) {
   52     bool full_match = false;
   53 
   54     got = fscanf(fp, "%s %s %d\n", pattern, string, &want);
   55     if (got == EOF)
   56         break;
   57     if (got == 3) {
   58         got = matches_env_pattern(pattern, string, &full_match);
   59         if (full_match)
   60         got++;
   61         if (got != want) {
   62         fprintf(stderr,
   63             "%s: %s %s: want %d, got %d\n",
   64             getprogname(), pattern, string, want, got);
   65         errors++;
   66         }
   67         tests++;
   68     }
   69     }
   70     if (tests != 0) {
   71     printf("%s: %d test%s run, %d errors, %d%% success rate\n",
   72         getprogname(), tests, tests == 1 ? "" : "s", errors,
   73         (tests - errors) * 100 / tests);
   74     }
   75     exit(errors);
   76 }