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 90 91 92 93 94 95 96 97 98 99 100 101 102 103
|
/* $Id: main.c,v 1.4 2006/05/22 20:42:04 hno Exp $
* Copyright (C) 2002 Rodrigo Campos
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program 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, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* Author: Rodrigo Campos (rodrigo@geekbunker.org)
*
*/
#include "util.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include "ip_user.h"
void
usage (char *program_name)
{
fprintf (stderr, "Usage:\n%s -f <configuration file>\n",
program_name);
}
int
main (int argc, char *argv[])
{
FILE *FH;
char *filename = NULL;
char *program_name = argv[0];
char *cp;
char *username, *address;
char line[BUFSIZE];
struct ip_user_dict *current_entry;
int ch;
setvbuf (stdout, NULL, _IOLBF, 0);
while ((ch = getopt (argc, argv, "f:")) != -1) {
switch (ch) {
case 'f':
filename = optarg;
break;
default:
usage (program_name);
exit (1);
}
}
if (filename == NULL) {
usage (program_name);
exit(1);
}
FH = fopen (filename, "r");
current_entry = load_dict (FH);
while (fgets (line, sizeof (line), stdin)) {
if ((cp = strchr (line, '\n')) == NULL) {
/* too large message received.. skip and deny */
fprintf(stderr, "%s: ERROR: Too large: %s\n", argv[0], line);
while (fgets(line, sizeof(line), stdin)) {
fprintf(stderr, "%s: ERROR: Too large..: %s\n", argv[0], line);
if (strchr(line, '\n') != NULL)
break;
}
goto error;
}
*cp = '\0';
address = strtok (line, " \t");
username = strtok (NULL, " \t");
if (!address || !username) {
fprintf (stderr, "%s: unable to read tokens\n", argv[0]);
goto error;
}
rfc1738_unescape(address);
rfc1738_unescape(username);
#ifdef DEBUG
printf ("result: %d\n",
dict_lookup (current_entry, username, address));
#endif
if ((dict_lookup (current_entry, username, address)) != 0) {
printf ("OK\n");
} else {
error:
printf ("ERR\n");
}
}
fclose (FH);
return 0;
}
|