]> git.ipfire.org Git - thirdparty/squid.git/blob - helpers/external_acl/ip_user/main.c
Import of fix-ranges branch
[thirdparty/squid.git] / helpers / external_acl / ip_user / main.c
1 /* $Id: main.c,v 1.3 2003/01/23 00:36:01 robertc Exp $
2 * Copyright (C) 2002 Rodrigo Campos
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
17 *
18 * Author: Rodrigo Campos (rodrigo@geekbunker.org)
19 *
20 */
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <unistd.h>
24 #include <string.h>
25
26
27 #include "ip_user.h"
28
29
30 void
31 usage (char *program_name)
32 {
33 fprintf (stderr, "Usage:\n%s -f <configuration file>\n",
34 program_name);
35 }
36
37 int
38 main (int argc, char *argv[])
39 {
40 FILE *FH;
41 char *filename = NULL;
42 char *program_name = argv[0];
43 char *cp;
44 char *username, *address;
45 char line[BUFSIZE];
46 struct ip_user_dict *current_entry;
47 int ch;
48
49 setvbuf (stdout, NULL, _IOLBF, 0);
50 while ((ch = getopt (argc, argv, "f:")) != -1) {
51 switch (ch) {
52 case 'f':
53 filename = optarg;
54 break;
55 default:
56 usage (program_name);
57 exit (1);
58 }
59 }
60 if (filename == NULL) {
61 usage (program_name);
62 exit(1);
63 }
64 FH = fopen (filename, "r");
65 current_entry = load_dict (FH);
66
67 while (fgets (line, sizeof (line), stdin)) {
68 if ((cp = strchr (line, '\n')) != NULL) {
69 *cp = '\0';
70 }
71 if ((cp = strtok (line, " \t")) != NULL) {
72 address = cp;
73 username = strtok (NULL, " \t");
74 } else {
75 fprintf (stderr, "helper: unable to read tokens\n");
76 printf ("ERR\n");
77 continue;
78 }
79 #ifdef DEBUG
80 printf ("result: %d\n",
81 dict_lookup (current_entry, username, address));
82 #endif
83 if ((dict_lookup (current_entry, username, address)) != 0) {
84 printf ("OK\n");
85 } else {
86 printf ("ERR\n");
87 }
88
89
90 }
91
92
93 fclose (FH);
94 return 0;
95 }