]>
git.ipfire.org Git - thirdparty/squid.git/blob - helpers/external_acl/ip_user/main.c
1 /* $Id: main.c,v 1.6 2007/07/19 03:36:12 hno Exp $
2 * Copyright (C) 2002 Rodrigo Campos
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.
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.
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.
18 * Author: Rodrigo Campos (rodrigo@geekbunker.org)
32 usage (char *program_name
)
34 fprintf (stderr
, "Usage:\n%s -f <configuration file>\n",
39 main (int argc
, char *argv
[])
42 char *filename
= NULL
;
43 char *program_name
= argv
[0];
45 char *username
, *address
;
47 struct ip_user_dict
*current_entry
;
50 setvbuf (stdout
, NULL
, _IOLBF
, 0);
51 while ((ch
= getopt (argc
, argv
, "f:")) != -1) {
61 if (filename
== NULL
) {
65 FH
= fopen (filename
, "r");
66 current_entry
= load_dict (FH
);
68 while (fgets (line
, sizeof (line
), stdin
)) {
69 if ((cp
= strchr (line
, '\n')) == NULL
) {
70 /* too large message received.. skip and deny */
71 fprintf(stderr
, "%s: ERROR: Too large: %s\n", argv
[0], line
);
72 while (fgets(line
, sizeof(line
), stdin
)) {
73 fprintf(stderr
, "%s: ERROR: Too large..: %s\n", argv
[0], line
);
74 if (strchr(line
, '\n') != NULL
)
80 address
= strtok (line
, " \t");
81 username
= strtok (NULL
, " \t");
82 if (!address
|| !username
) {
83 fprintf (stderr
, "%s: unable to read tokens\n", argv
[0]);
86 rfc1738_unescape(address
);
87 rfc1738_unescape(username
);
89 printf ("result: %d\n",
90 dict_lookup (current_entry
, username
, address
));
92 if ((dict_lookup (current_entry
, username
, address
)) != 0) {