1 /*
2  * ProFTPD - FTP server daemon
3  * Copyright (c) 2001-2016 The ProFTPD Project team
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., 51 Franklin Street, Suite 500, Boston, MA 02110-1335, USA.
18  *
19  * As a special exemption, The ProFTPD Project team and other respective
20  * copyright holders give permission to link this program with OpenSSL, and
21  * distribute the resulting executable, without including the source code for
22  * OpenSSL in the source distribution.
23  */
24 
25 /* Feature management code */
26 
27 #include "conf.h"
28 
29 static pool *feat_pool = NULL;
30 static pr_table_t *feat_tab = NULL;
31 
pr_feat_add(const char * feat)32 int pr_feat_add(const char *feat) {
33   if (feat == NULL) {
34     errno = EINVAL;
35     return -1;
36   }
37 
38   /* If no feature-tracking list has been allocated, create one. */
39   if (feat_pool == NULL) {
40     feat_pool = make_sub_pool(permanent_pool);
41     pr_pool_tag(feat_pool, "Feat API");
42     feat_tab = pr_table_alloc(feat_pool, 0);
43   }
44 
45   /* Make sure that the feature being added isn't already in the list. */
46   if (pr_table_exists(feat_tab, feat) > 0) {
47     errno = EEXIST;
48     return -1;
49   }
50 
51   return pr_table_add(feat_tab, pstrdup(feat_pool, feat), "", 0);
52 }
53 
pr_feat_remove(const char * feat)54 int pr_feat_remove(const char *feat) {
55   const void *res;
56 
57   if (feat_tab == NULL) {
58     errno = EPERM;
59     return -1;
60   }
61 
62   if (feat == NULL) {
63     errno = EINVAL;
64     return -1;
65   }
66 
67   res = pr_table_remove(feat_tab, feat, NULL);
68   if (res != NULL) {
69     return 0;
70   }
71 
72   errno = ENOENT;
73   return -1;
74 }
75 
pr_feat_get(void)76 const char *pr_feat_get(void) {
77   if (feat_tab == NULL) {
78     errno = EPERM;
79     return NULL;
80   }
81 
82   (void) pr_table_rewind(feat_tab);
83   return pr_table_next(feat_tab);
84 }
85 
pr_feat_get_next(void)86 const char *pr_feat_get_next(void) {
87   if (feat_tab == NULL) {
88     errno = EPERM;
89     return NULL;
90   }
91 
92   return pr_table_next(feat_tab);
93 }
94