Added a manager that adds and removes users from allow and deny tables.
authorThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sat, 20 Jun 2009 02:27:24 +0000 (23:27 -0300)
committerThadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
Sat, 20 Jun 2009 02:27:24 +0000 (23:27 -0300)
.gitignore
Makefile.am
ppmanager.c [new file with mode: 0644]

index 3e26df6..8db59bf 100644 (file)
@@ -12,3 +12,4 @@ install-sh
 missing
 *.o
 popproxy
+ppmanager
index c571530..b317328 100644 (file)
@@ -1,6 +1,7 @@
-bin_PROGRAMS = popproxy
+bin_PROGRAMS = popproxy ppmanager
 popproxy_SOURCES = popproxy.c log.c log.h nethook.c nethook.h \
        proto_detect.c proto_detect.h jabber.c jabber.h jabber_server.c \
        iksemel_extra.c iksemel_extra.h null.c null.h ssl.c ssl.h \
        ssl_server.c pop.c pop.h usermap.c usermap.h
 sysconf_DATA = popproxy.conf
+ppmanager = ppmanager.c
diff --git a/ppmanager.c b/ppmanager.c
new file mode 100644 (file)
index 0000000..45752fa
--- /dev/null
@@ -0,0 +1,92 @@
+/*
+** Copyright (C) 2006 Thadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
+** Copyright (C) 2009 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
+**  
+** 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+**  
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <depot.h>
+
+enum
+{
+  ACTION_ADD,
+  ACTION_DEL,
+  ACTION_LIST
+};
+
+void
+usage (char *programname)
+{
+  fprintf (stderr, "%s {allow | deny} {add | del | list} [user]\n",
+           programname);
+  exit (1);
+}
+
+int
+main (int argc, char **argv)
+{
+  DEPOT *dp;
+  int action;
+  char *db;
+  char *username;
+  int r = 0;
+  if (argc < 3)
+    usage (argv[0]);
+  if (!strcmp (argv[1], "deny"))
+    db = "/var/lib/popproxy/deny.db";
+  else if (!strcmp (argv[1], "allow"))
+    db = "/var/lib/popproxy/allow.db";
+  else
+    usage (argv[0]);
+  if (!strcmp (argv[2], "add"))
+    action = ACTION_ADD;
+  else if (!strcmp (argv[2], "del"))
+    action = ACTION_DEL;
+  else if (!strcmp (argv[2], "list"))
+    action = ACTION_LIST;
+  else
+    usage (argv[0]);
+  if ((action == ACTION_ADD || action == ACTION_DEL) && argc < 4)
+    usage (argv[0]);
+  username = argv[3];
+  dp = dpopen (db, DP_OWRITER | DP_OCREAT, 0);
+  if (dp == NULL)
+    {
+      fprintf (stderr, "Could not create database.\n");
+      exit (1);
+    }
+  switch (action)
+    {
+    case ACTION_ADD:
+      dpput (dp, username, -1, "", -1, DP_DOVER);
+      break;
+    case ACTION_DEL:
+      dpout (dp, username, -1);
+      break;
+    case ACTION_LIST:
+      fprintf (stderr, "Action not implemented.\n");
+      r = 1;
+      break;
+    default:
+      fprintf (stderr, "Action unrecognized.\n");
+      r = 1;
+    }
+  dpclose (dp);
+  return r;
+}