--- /dev/null
+/*
+** 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;
+}