1*bc4097aaSchristos /* $NetBSD: userauth.c,v 1.1.1.1 2012/03/23 21:20:15 christos Exp $ */
2*bc4097aaSchristos
3*bc4097aaSchristos #include <sys/types.h>
4*bc4097aaSchristos #include <sys/socket.h>
5*bc4097aaSchristos #include <fcntl.h>
6*bc4097aaSchristos #include <sys/ioctl.h>
7*bc4097aaSchristos #include <stdio.h>
8*bc4097aaSchristos #include <stdlib.h>
9*bc4097aaSchristos #include <netinet/in.h>
10*bc4097aaSchristos #include <net/if.h>
11*bc4097aaSchristos #include "ip_compat.h"
12*bc4097aaSchristos #include "ip_fil.h"
13*bc4097aaSchristos #include "ip_auth.h"
14*bc4097aaSchristos
15*bc4097aaSchristos extern int errno;
16*bc4097aaSchristos
main()17*bc4097aaSchristos main()
18*bc4097aaSchristos {
19*bc4097aaSchristos struct frauth fra;
20*bc4097aaSchristos struct frauth *frap = &fra;
21*bc4097aaSchristos fr_info_t *fin = &fra.fra_info;
22*bc4097aaSchristos fr_ip_t *fi = &fin->fin_fi;
23*bc4097aaSchristos char yn[16];
24*bc4097aaSchristos int fd;
25*bc4097aaSchristos
26*bc4097aaSchristos fd = open(IPL_NAME, O_RDWR);
27*bc4097aaSchristos fra.fra_len = 0;
28*bc4097aaSchristos fra.fra_buf = NULL;
29*bc4097aaSchristos while (ioctl(fd, SIOCAUTHW, &frap) == 0) {
30*bc4097aaSchristos if (fra.fra_info.fin_out)
31*bc4097aaSchristos fra.fra_pass = FR_OUTQUE;
32*bc4097aaSchristos else
33*bc4097aaSchristos fra.fra_pass = FR_INQUE;
34*bc4097aaSchristos
35*bc4097aaSchristos printf("%s ", inet_ntoa(fi->fi_src));
36*bc4097aaSchristos if (fi->fi_flx & FI_TCPUDP)
37*bc4097aaSchristos printf("port %d ", fin->fin_data[0]);
38*bc4097aaSchristos printf("-> %s ", inet_ntoa(fi->fi_dst));
39*bc4097aaSchristos if (fi->fi_flx & FI_TCPUDP)
40*bc4097aaSchristos printf("port %d ", fin->fin_data[1]);
41*bc4097aaSchristos printf("\n");
42*bc4097aaSchristos printf("Allow packet through ? [y/n]");
43*bc4097aaSchristos fflush(stdout);
44*bc4097aaSchristos if (!fgets(yn, sizeof(yn), stdin))
45*bc4097aaSchristos break;
46*bc4097aaSchristos fflush(stdin);
47*bc4097aaSchristos if (yn[0] == 'n' || yn[0] == 'N')
48*bc4097aaSchristos fra.fra_pass |= FR_BLOCK;
49*bc4097aaSchristos else if (yn[0] == 'y' || yn[0] == 'Y') {
50*bc4097aaSchristos fra.fra_pass |= FR_PASS;
51*bc4097aaSchristos if (fra.fra_info.fin_fi.fi_flx & FI_TCPUDP)
52*bc4097aaSchristos fra.fra_pass |= FR_KEEPSTATE;
53*bc4097aaSchristos } else
54*bc4097aaSchristos fra.fra_pass |= FR_NOMATCH;
55*bc4097aaSchristos printf("answer = %c (%x), id %d idx %d\n", yn[0],
56*bc4097aaSchristos fra.fra_pass, fra.fra_info.fin_id, fra.fra_index);
57*bc4097aaSchristos if (ioctl(fd, SIOCAUTHR, &frap) != 0)
58*bc4097aaSchristos perror("SIOCAUTHR");
59*bc4097aaSchristos }
60*bc4097aaSchristos fprintf(stderr, "errno=%d \n", errno);
61*bc4097aaSchristos perror("frauth-SIOCAUTHW");
62*bc4097aaSchristos }
63