version 1.1.1.2, 2012/05/29 12:26:49
|
version 1.1.1.4, 2014/06/15 16:12:55
|
Line 1
|
Line 1
|
/* |
/* |
* Copyright (c) 2011 Todd C. Miller <Todd.Miller@courtesan.com> | * Copyright (c) 2011-2013 Todd C. Miller <Todd.Miller@courtesan.com> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
Line 41
|
Line 41
|
|
|
#include <netinet/in.h> |
#include <netinet/in.h> |
#include <arpa/inet.h> |
#include <arpa/inet.h> |
#include <netdb.h> |
|
|
|
#define SUDO_ERROR_WRAP 0 |
#define SUDO_ERROR_WRAP 0 |
|
|
Line 49
|
Line 48
|
#include "parse.h" |
#include "parse.h" |
#include "interfaces.h" |
#include "interfaces.h" |
|
|
static int check_addr_printf(int msg_type, const char *fmt, ...); | __dso_public int main(int argc, char *argv[]); |
|
|
/* for match_addr.c */ |
|
struct interface *interfaces; |
|
sudo_printf_t sudo_printf = check_addr_printf; |
|
|
|
sudo_conv_t sudo_conv; /* NULL in non-plugin */ |
|
|
|
static int |
static int |
check_addr(char *input) |
check_addr(char *input) |
{ |
{ |
int expected, matched; |
int expected, matched; |
|
const char *errstr; |
size_t len; |
size_t len; |
char *cp; |
char *cp; |
|
|
Line 72 check_addr(char *input)
|
Line 66 check_addr(char *input)
|
cp = input + len; |
cp = input + len; |
while (isspace((unsigned char)*cp)) |
while (isspace((unsigned char)*cp)) |
cp++; |
cp++; |
expected = atoi(cp); | expected = strtonum(cp, 0, 1, &errstr); |
| if (errstr != NULL) |
| fatalx("expecting 0 or 1, got %s", cp); |
input[len] = '\0'; |
input[len] = '\0'; |
|
|
matched = addr_matches(input); |
matched = addr_matches(input); |
Line 86 check_addr(char *input)
|
Line 82 check_addr(char *input)
|
static void |
static void |
usage(void) |
usage(void) |
{ |
{ |
fprintf(stderr, "usage: check_addr datafile\n"); | fprintf(stderr, "usage: %s datafile\n", getprogname()); |
exit(1); |
exit(1); |
} |
} |
|
|
Line 98 main(int argc, char *argv[])
|
Line 94 main(int argc, char *argv[])
|
size_t len; |
size_t len; |
FILE *fp; |
FILE *fp; |
|
|
#if !defined(HAVE_GETPROGNAME) && !defined(HAVE___PROGNAME) | initprogname(argc > 0 ? argv[0] : "check_addr"); |
setprogname(argc > 0 ? argv[0] : "check_addr"); | |
#endif | |
|
|
if (argc != 2) |
if (argc != 2) |
usage(); |
usage(); |
|
|
fp = fopen(argv[1], "r"); |
fp = fopen(argv[1], "r"); |
if (fp == NULL) |
if (fp == NULL) |
errorx(1, "unable to open %s", argv[1]); | fatalx("unable to open %s", argv[1]); |
|
|
/* |
/* |
* Input is in the following format. There are two types of |
* Input is in the following format. There are two types of |
Line 151 main(int argc, char *argv[])
|
Line 145 main(int argc, char *argv[])
|
ntests, errors, (ntests - errors) * 100 / ntests); |
ntests, errors, (ntests - errors) * 100 / ntests); |
|
|
exit(errors); |
exit(errors); |
} |
|
|
|
/* STUB */ |
|
void |
|
cleanup(int gotsig) |
|
{ |
|
return; |
|
} |
|
|
|
static int |
|
check_addr_printf(int msg_type, const char *fmt, ...) |
|
{ |
|
va_list ap; |
|
FILE *fp; |
|
|
|
switch (msg_type) { |
|
case SUDO_CONV_INFO_MSG: |
|
fp = stdout; |
|
break; |
|
case SUDO_CONV_ERROR_MSG: |
|
fp = stderr; |
|
break; |
|
default: |
|
errno = EINVAL; |
|
return -1; |
|
} |
|
|
|
va_start(ap, fmt); |
|
vfprintf(fp, fmt, ap); |
|
va_end(ap); |
|
|
|
return 0; |
|
} |
} |