Destroy SSL connection properly.
[cascardo/rnetproxy.git] / ppmanager.c
1 /*
2 ** Copyright (C) 2006 Thadeu Lima de Souza Cascardo <cascardo@minaslivre.org>
3 ** Copyright (C) 2009 Thadeu Lima de Souza Cascardo <cascardo@holoscopio.com>
4 **  
5 ** This program is free software; you can redistribute it and/or modify
6 ** it under the terms of the GNU General Public License as published by
7 ** the Free Software Foundation; either version 2 of the License, or
8 ** (at your option) any later version.
9 **  
10 ** This program is distributed in the hope that it will be useful,
11 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
12 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 ** GNU General Public License for more details.
14 **  
15 ** You should have received a copy of the GNU General Public License
16 ** along with this program; if not, write to the Free Software
17 ** Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 **  
19 */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <string.h>
24 #include <depot.h>
25
26 enum
27 {
28   ACTION_ADD,
29   ACTION_DEL,
30   ACTION_LIST
31 };
32
33 void
34 usage (char *programname)
35 {
36   fprintf (stderr, "%s {allow | deny} {add | del | list} [user]\n",
37            programname);
38   exit (1);
39 }
40
41 int
42 main (int argc, char **argv)
43 {
44   DEPOT *dp;
45   int action;
46   char *db;
47   char *username;
48   int r = 0;
49   if (argc < 3)
50     usage (argv[0]);
51   if (!strcmp (argv[1], "deny"))
52     db = "/var/lib/popproxy/deny.db";
53   else if (!strcmp (argv[1], "allow"))
54     db = "/var/lib/popproxy/allow.db";
55   else
56     usage (argv[0]);
57   if (!strcmp (argv[2], "add"))
58     action = ACTION_ADD;
59   else if (!strcmp (argv[2], "del"))
60     action = ACTION_DEL;
61   else if (!strcmp (argv[2], "list"))
62     action = ACTION_LIST;
63   else
64     usage (argv[0]);
65   if ((action == ACTION_ADD || action == ACTION_DEL) && argc < 4)
66     usage (argv[0]);
67   username = argv[3];
68   dp = dpopen (db, DP_OWRITER | DP_OCREAT, 0);
69   if (dp == NULL)
70     {
71       fprintf (stderr, "Could not create database.\n");
72       exit (1);
73     }
74   switch (action)
75     {
76     case ACTION_ADD:
77       dpput (dp, username, -1, "", -1, DP_DOVER);
78       break;
79     case ACTION_DEL:
80       dpout (dp, username, -1);
81       break;
82     case ACTION_LIST:
83       fprintf (stderr, "Action not implemented.\n");
84       r = 1;
85       break;
86     default:
87       fprintf (stderr, "Action unrecognized.\n");
88       r = 1;
89     }
90   dpclose (dp);
91   return r;
92 }