From 64f91aa87a63968bc84b033e3d0b15f153c262f0 Mon Sep 17 00:00:00 2001 From: Thadeu Lima de Souza Cascardo Date: Fri, 19 Jun 2009 23:27:24 -0300 Subject: [PATCH] Added a manager that adds and removes users from allow and deny tables. --- .gitignore | 1 + Makefile.am | 3 +- ppmanager.c | 92 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 95 insertions(+), 1 deletion(-) create mode 100644 ppmanager.c diff --git a/.gitignore b/.gitignore index 3e26df6..8db59bf 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ install-sh missing *.o popproxy +ppmanager diff --git a/Makefile.am b/Makefile.am index c571530..b317328 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 index 0000000..45752fa --- /dev/null +++ b/ppmanager.c @@ -0,0 +1,92 @@ +/* +** Copyright (C) 2006 Thadeu Lima de Souza Cascardo +** Copyright (C) 2009 Thadeu Lima de Souza Cascardo +** +** 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 +#include +#include +#include + +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; +} -- 2.20.1