-AC_INIT(rxpd, 0.1pre)
+AC_INIT(rxpd, 0.1pre, 'ct@pipapo.org')
AC_CONFIG_SRCDIR(src/rxpd.c)
AM_INIT_AUTOMAKE
AC_PREREQ(2.59)
void
-usage(void)
+version (void)
+{
+ printf (
+ " Regex Policy Daemon ("PACKAGE_STRING")\n\n"
+ " Copyright (C)\n"
+ " 2007, Christian Thaeter <ct@pipapo.org>\n\n"
+ " This is free software. You may redistribute copies of it under the terms of\n"
+ " the GNU General Public License <http://www.gnu.org/licenses/gpl.html>.\n"
+ " There is NO WARRANTY, to the extent permitted by law.\n"
+ );
+}
+
+void
+usage (void)
{
/*
- rxpd [options] ..files..
+ rxpd [OPTIONS] RULES..
-v verbosity
-V version
-d daemonize
-6 ipv6
-r resolve names
-l log log hits to logfile
- */
+ -h usage
+ -U user switch to user
+ */
}
-
int
main (int argc, char** argv)
{
- struct rxpd_base* rxpd = rxpd_init ("./");
- struct event_base* event = event_init();
+ struct rxpd_base* rxpd;
+ rxpd = rxpd_init (event_init ());
// parse commandline args
-
- // read files
- struct rxpd_file* file = rxpd_file_new (rxpd, "test");
- rxpd_file_load (file);
-
- struct rxpd_file* file2 = rxpd_file_new (rxpd, "test2");
- rxpd_file_load (file2);
+ opterr = 0;
+
+ int opt;
+
+ while ((opt = getopt (argc, argv, "vVdDb:qt:u:p:i46rl:h")) != -1)
+ switch (opt)
+ {
+ case 'v':
+ if (rxpd->verbosity < LOG_DEBUG)
+ ++rxpd->verbosity;
+ break;
+ case 'V':
+ version ();
+ exit (EXIT_SUCCESS);
+ case 'd':
+ rxpd->daemonize = 1;
+ break;
+ case 'D':
+ if (rxpd->verbosity < LOG_NOTICE)
+ rxpd->verbosity = LOG_NOTICE;
+ rxpd->daemonize = 0;
+ break;
+ case 'b':
+ if (!rxpd->basedir)
+ rxpd->basedir = rxpd_strdup (optarg);
+ else
+ rxpd_die ("basedir already set\n");
+ break;
+ case 'q':
+ rxpd->verbosity = LOG_ALERT;
+ break;
+ case 't':
+ //rxpd_socket_new_tcp4 (rxpd, NULL, 2374)
+ //rxpd_socket_new_tcp6 (rxpd, NULL, 2374)
+ break;
+#if 0 /*not yet implemented*/
+ case 'u':
+ //rxpd_socket_new_unix (rxpd, NULL, 2374);
+ break;
+#endif
+ case 'p':
+ if (!rxpd->policy)
+ rxpd->policy = rxpd_file_new (rxpd, optarg);
+ else
+ rxpd_die ("policy already set\n");
+ break;
+ case 'i':
+ rxpd->regflags |= REG_ICASE;
+ break;
+#if 0 /*not yet implemented*/
+ case '4':
+ break;
+ case '6':
+ break;
+ case 'r':
+ break;
+ case 'l:':
+ break;
+#endif
+ case 'h':
+ usage ();
+ exit (0);
+ break;
+ default:
+ rxpd_log (rxpd, LOG_ALERT, "Unknown option\n");
+ exit (EXIT_FAILURE);
+ }
+
+ if (rxpd->daemonize && daemon(0, 0))
+ rxpd_die ("Couldn't daemonize\n");
+
+ if (!rxpd->basedir)
+ {
+ rxpd_log (rxpd, LOG_ALERT, "Basedir not set (use -b BASEDIR)\n");
+ exit (EXIT_FAILURE);
+ }
+
+ if (llist_is_empty (&rxpd->sockets))
+ {
+ rxpd_log (rxpd, LOG_ALERT, "No listening sockets (use -t TCP or -u UNIX)\n");
+ exit (EXIT_FAILURE);
+ }
+
+ if (rxpd->policy && !rxpd_file_load (rxpd->policy))
+ {
+ rxpd_log (rxpd, LOG_ALERT, "Failed loading policy file\n");
+ exit (EXIT_FAILURE);
+ }
+
+
+
+ // add all files
+
+ //load all files
// initialize listening connections
// port 2374
- rxpd_socket_schedule (rxpd_socket_new_tcp4 (rxpd, NULL, 2374));
+ //rxpd_socket_schedule (rxpd_socket_new_tcp4 (rxpd, NULL, 2374));
//rxpd_socket_new_unix (rxpd, "/tmp/rxpd");
{
va_list ap;
va_start (ap, fmt);
- if (level <= self->verbosity)
+ if (level <= (self?self->verbosity:LOG_DEBUG))
{
if (self->daemonize)
vsyslog (level, fmt, ap);
- else
- vfprintf (stderr, fmt, ap);
+ vfprintf (stderr, fmt, ap);
}
va_end (ap);
}
self = rxpd_malloc (sizeof (struct rxpd_file));
self->filename = filename;
+ self->base = base;
const char* basename = strrchr (filename, '/');
if (basename)
++basename;
// TODO test excess line length = error
char buf[4096];
+ rxpd_log (self->base, LOG_NOTICE, "loading '%s'\n", self->filename);
+
while (fgets (buf, 4096, f))
{
size_t last = strlen(buf);
if (!rule)
abort();
- printf("loaded rule '%s'\n", rule->string);
+ rxpd_log (self->base, LOG_DEBUG, "new rule '%s'\n", rule->string);
llist_insert_tail (&self->rules, &rule->node);
}
return 1;
}
else
- return 0;
+ {
+ rxpd_log (self->base, LOG_ERR, "failed loading '%s'\n", self->filename);
+ return 0;
+ }
}
int
}
fclose (f);
+ rxpd_log (self->base, LOG_NOTICE, "saved '%s'\n", self->filename);
return 1;
}
else
- return 0;
+ {
+ rxpd_log (self->base, LOG_ERR, "failed saving '%s'\n", self->filename);
+ return 0;
+ }
}
int
// abort ();
// TODO
- printf ("incoming connection\n");
+ rxpd_log (base, LOG_INFO, "incoming connection\n");
self->base = base;
{
(void) event;
- //TODO printf ("parse cmd\n");
struct rxpd_connection* self = (struct rxpd_connection*) ptr;
-
char* line;
line = rxpd_buffer_readline (&self->in, 0);
if (!line)
{
+ rxpd_log (self->base, LOG_ERR, "no data\n");
rxpd_buffer_printf (&self->out, "#ERROR: no data\n");
close (fd);
return;
}
+ rxpd_log (self->base, LOG_DEBUG, "parse command '%s'\n", line);
+
static const struct cmd_table
{
enum rxpd_cmd_e nr;
break;
if (!i->cmd)
{
+ rxpd_log (self->base, LOG_ERR, "no command\n");
rxpd_buffer_printf (&self->out, "#ERROR: no command\n");
rxpd_connection_delete (self);
return;
self->file = rxpd_file_new (self->base, &line[i->sz]);
if (!self->file)
{
+ rxpd_log (self->base, LOG_ERR, "illeagal filename\n");
rxpd_buffer_printf (&self->out, "#ERROR: illegal filename\n");
rxpd_connection_delete (self);
return;
psplay node; // key points to basename part of filename
const char* filename; // full filename
//TODO later struct stat last_stat;
+ struct rxpd_base* base;
llist rules;
};