Coverage Report

Created: 2024-09-30 06:24

/src/proftpd/src/feat.c
Line
Count
Source (jump to first uncovered line)
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
32
0
int pr_feat_add(const char *feat) {
33
0
  if (feat == NULL) {
34
0
    errno = EINVAL;
35
0
    return -1;
36
0
  }
37
38
  /* If no feature-tracking list has been allocated, create one. */
39
0
  if (feat_pool == NULL) {
40
0
    feat_pool = make_sub_pool(permanent_pool);
41
0
    pr_pool_tag(feat_pool, "Feat API");
42
0
    feat_tab = pr_table_alloc(feat_pool, 0);
43
0
  }
44
45
  /* Make sure that the feature being added isn't already in the list. */
46
0
  if (pr_table_exists(feat_tab, feat) > 0) {
47
0
    errno = EEXIST;
48
0
    return -1;
49
0
  }
50
51
0
  return pr_table_add(feat_tab, pstrdup(feat_pool, feat), "", 0);
52
0
}
53
54
0
int pr_feat_remove(const char *feat) {
55
0
  const void *res;
56
57
0
  if (feat_tab == NULL) {
58
0
    errno = EPERM;
59
0
    return -1;
60
0
  }
61
62
0
  if (feat == NULL) {
63
0
    errno = EINVAL;
64
0
    return -1;
65
0
  }
66
67
0
  res = pr_table_remove(feat_tab, feat, NULL);
68
0
  if (res != NULL) {
69
0
    return 0;
70
0
  }
71
72
0
  errno = ENOENT;
73
0
  return -1;
74
0
}
75
76
0
const char *pr_feat_get(void) {
77
0
  if (feat_tab == NULL) {
78
0
    errno = EPERM;
79
0
    return NULL;
80
0
  }
81
82
0
  (void) pr_table_rewind(feat_tab);
83
0
  return pr_table_next(feat_tab);
84
0
}
85
86
0
const char *pr_feat_get_next(void) {
87
0
  if (feat_tab == NULL) {
88
0
    errno = EPERM;
89
0
    return NULL;
90
0
  }
91
92
0
  return pr_table_next(feat_tab);
93
0
}