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