summaryrefslogtreecommitdiff
path: root/lib/test-securenets.c
blob: 46577a5e7ba41bebc72461a970a8e6cb4c145cca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
/* Copyright (c) 2014, 2016  Thorsten Kukuk
   Author: Thorsten Kukuk <kukuk@suse.de>

   The YP Server is free software; you can redistribute it and/or
   modify it under the terms of the GNU General Public License
   version 2 as published by the Free Software Foundation.

   The YP Server is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   General Public License for more details.

   You should have received a copy of the GNU General Public License
   along with this program.  If not, see <http://www.gnu.org/licenses/>. */

#include <rpc/rpc.h>
#include <rpc/rpc_com.h>

#include "access.h"

extern int debug_flag;
extern const char *securenetsfile;

static int
check_entry (int af, char *ip)
{
  struct __rpc_sockinfo si;
  struct netconfig *nconf = NULL;
  struct netbuf *nbuf;
  const char *netid;
  char uaddr[100];

  snprintf (uaddr, 100, "%s.0.0", ip);

  nbuf = __rpc_uaddr2taddr_af (af, uaddr);
  if (nbuf == NULL)
    {
      fprintf (stderr, "uaddr2taddr (\"%s\") failed\n", ip);
      return 1;
    }

  si.si_af = af;
  si.si_proto = IPPROTO_UDP;
  if (!__rpc_sockinfo2netid (&si, &netid))
    {
      fprintf (stderr, "__rpc_sockinfo2netid() failed\n");
      return 1;
    }
  nconf = getnetconfigent (netid);
  if (nconf == NULL)
    {
      fprintf (stderr, "getnetconfigent (%s) failed\n", netid);
      return 1;
    }
  if (securenet_host (nconf, nbuf) != 1)
    return 1;


  return 0;
}

int
main (void)
{
  debug_flag = 1;
  securenetsfile = "securenets.test";

  if (load_securenets () != 0)
    return 1;
  /* dump_securenets (); */

  /* success */
  if (check_entry (AF_INET, "127.0.0.1") != 0)
    return 1;
  /* success */
  if (check_entry (AF_INET6, "::1") != 0)
    return 1;
  /* success */
  if (check_entry (AF_INET6, "fe80::202:b3ff:ad:245") != 0)
    return 1;
  /* fail */
  if (check_entry (AF_INET, "10.10.0.87") != 1)
    return 1;
  /* fail */
  if (check_entry (AF_INET6, "fe80::202:b3fe:ff:ff") != 1)
    return 1;

  return 0;
}