37#include <sys/socket.h>
40#include <netinet/in.h>
62#define DICT_BUFFER_SIZE 8196
84 current_entry = first_entry;
86 unsigned int lineCount = 0;
87 while (fgets(line,
sizeof(line), FH) !=
nullptr) {
94 if ((cp = strchr (line,
'\n')) !=
nullptr) {
98 if (strtok(line,
"\t ") !=
nullptr) {
103 if ((
username = strtok(
nullptr,
"\t ")) ==
nullptr) {
104 debug(
"Missing username on line %u of dictionary file\n", lineCount);
109 if ((cp = strtok (line,
"/")) !=
nullptr) {
112 cp = strtok (
nullptr,
"/");
115 current_entry->
netmask = (inet_addr(cp));
117 (((inet_addr (tmpbuf))) & current_entry->
netmask);
120 current_entry->
address = (inet_addr(tmpbuf));
121 current_entry->
netmask = (inet_addr(
"255.255.255.255"));
126 (
char*)calloc(strlen(
username) + 1,
sizeof(char));
152 while (current_entry->
username !=
nullptr) {
153 debug(
"user: %s\naddr: %lu\nmask: %lu\n\n",
157 if ((inet_addr (
address) & (
unsigned long) current_entry->
161 if ((strchr (current_entry->
username,
'@')) ==
nullptr) {
179 if ((strcmp(dict_username,
username)) == 0) {
182 if ((strcmp(dict_username,
"ALL")) == 0) {
197 if ((g = getgrnam(dict_group)) ==
nullptr) {
198 debug(
"Group does not exist '%s'\n", dict_group);
201 while (*(g->gr_mem) !=
nullptr) {
202 if (strcmp(*((g->gr_mem)++), username) == 0) {
214 fprintf (stderr,
"Usage:\n%s [-d] -f <configuration file>\n",
221 char *filename =
nullptr;
224 char *username, *address;
229 setvbuf (stdout,
nullptr, _IOLBF, 0);
230 while ((ch =
getopt(argc, argv,
"df:h")) != -1) {
242 fprintf(stderr,
"%s: FATAL: Unknown parameter option '%c'",
program_name, ch);
247 if (filename ==
nullptr) {
248 fprintf(stderr,
"%s: FATAL: No Filename configured.",
program_name);
252 FILE *FH = fopen(filename,
"r");
255 fprintf(stderr,
"%s: FATAL: Unable to open file '%s': %s",
program_name, filename,
xstrerr(xerrno));
261 if ((cp = strchr (line,
'\n')) ==
nullptr) {
263 fprintf(stderr,
"%s: ERROR: Input Too Large: %s\n",
program_name, line);
264 while (fgets(line,
sizeof(line), stdin)) {
265 fprintf(stderr,
"%s: ERROR: Input Too Large..: %s\n",
program_name, line);
266 if (strchr(line,
'\n') !=
nullptr)
#define HELPER_INPUT_BUFFER
void debug(const char *format,...)
int main(int argc, char *argv[])
struct ip_user_dict * load_dict(FILE *)
static void usage(const char *program_name)
int match_user(char *, char *)
int match_group(char *, char *)
int dict_lookup(struct ip_user_dict *, char *, char *)
int getopt(int nargc, char *const *nargv, const char *ostr)
void rfc1738_unescape(char *url)
struct ip_user_dict * next_entry
const char * xstrerr(int error)