• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

proftpd / proftpd / 30135626854

25 Jul 2026 12:15AM UTC coverage: 93.034% (+0.6%) from 92.428%
30135626854

push

github

51363 of 55209 relevant lines covered (93.03%)

219.82 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

63.44
/tests/api/privs.c
1
/*
2
 * ProFTPD - FTP server testsuite
3
 * Copyright (c) 2015-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
/* Privs API tests */
25

26
#include "tests.h"
27

28
static pool *p = NULL;
29

30
static uid_t privs_uid = (uid_t) -1;
31
static gid_t privs_gid = (gid_t) -1;
32

33
static void set_up(void) {
34
  if (p == NULL) {
6✔
35
    p = permanent_pool = make_sub_pool(NULL);
6✔
36
  }
6✔
37

38
  init_privs();
39
  privs_uid = getuid();
6✔
40
  privs_gid = getgid();
6✔
41

6✔
42
  if (getenv("TEST_VERBOSE") != NULL) {
43
    pr_trace_set_levels("privs", 1, 20);
6✔
44
  }
6✔
45
}
46

6✔
47
static void tear_down(void) {
48
  if (getenv("TEST_VERBOSE") != NULL) {
6✔
49
    pr_trace_set_levels("privs", 0, 0);
6✔
50
  }
6✔
51

52
  if (p) {
53
    destroy_pool(p);
6✔
54
    p = permanent_pool = NULL;
6✔
55
  }
6✔
56
}
57

6✔
58
START_TEST (privs_set_nonroot_daemon_test) {
59
  int nonroot, res;
1✔
60

1✔
61
  res = set_nonroot_daemon(-1);
62
  ck_assert_msg(res < 0, "Failed to handle non-Boolean parameter");
1✔
63
  ck_assert_msg(errno == EINVAL, "Expected EINVAL (%d), got %s (%d)", EINVAL,
1✔
64
    strerror(errno), errno);
1✔
65

66
  nonroot = set_nonroot_daemon(TRUE);
67
  ck_assert_msg(nonroot == FALSE || nonroot == TRUE,  "Expected true/false, got %d",
1✔
68
    nonroot);
1✔
69
  set_nonroot_daemon(nonroot);
70
}
1✔
71
END_TEST
1✔
72

73
START_TEST (privs_setup_test) {
74
  int nonroot, res;
1✔
75

1✔
76
  if (privs_uid != 0) {
77
    res = pr_privs_setup(privs_uid, privs_gid, __FILE__, __LINE__);
1✔
78
    ck_assert_msg(res == 0, "Failed to setup privs: %s", strerror(errno));
×
79
    ck_assert_msg(session.uid == privs_uid, "Expected %lu, got %lu",
×
80
      (unsigned long) privs_uid, (unsigned long) session.uid);
×
81
    ck_assert_msg(session.gid == privs_gid, "Expected %lu, got %lu",
82
      (unsigned long) privs_gid, (unsigned long) session.gid);
×
83

84
    nonroot = set_nonroot_daemon(FALSE);
85

×
86
    res = pr_privs_setup(privs_uid, privs_gid, __FILE__, __LINE__);
87
    ck_assert_msg(res == 0, "Failed to setup privs: %s", strerror(errno));
×
88
    ck_assert_msg(session.uid == privs_uid, "Expected %lu, got %lu",
×
89
      (unsigned long) privs_uid, (unsigned long) session.uid);
×
90
    ck_assert_msg(session.gid == privs_gid, "Expected %lu, got %lu",
91
      (unsigned long) privs_gid, (unsigned long) session.gid);
×
92

93
    set_nonroot_daemon(nonroot);
94
  }
×
95
}
96
END_TEST
1✔
97

98
START_TEST (privs_root_test) {
99
  int nonroot, res;
1✔
100

1✔
101
  if (privs_uid != 0) {
102
    res = pr_privs_root(__FILE__, __LINE__);
1✔
103
    ck_assert_msg(res == 0, "Failed to set root privs: %s", strerror(errno));
×
104

×
105
    nonroot = set_nonroot_daemon(FALSE);
106

×
107
    res = pr_privs_root(__FILE__, __LINE__);
108
    ck_assert_msg(res == 0, "Failed to set root privs: %s", strerror(errno));
×
109

×
110
    set_nonroot_daemon(nonroot);
111
  }
×
112
}
113
END_TEST
1✔
114

115
START_TEST (privs_user_test) {
116
  int nonroot, res;
1✔
117

1✔
118
  if (privs_uid != 0) {
119
    res = pr_privs_user(__FILE__, __LINE__);
1✔
120
    ck_assert_msg(res == 0, "Failed to set user privs: %s", strerror(errno));
×
121

×
122
    nonroot = set_nonroot_daemon(FALSE);
123

×
124
    res = pr_privs_user(__FILE__, __LINE__);
125
    ck_assert_msg(res == 0, "Failed to set user privs: %s", strerror(errno));
×
126

×
127
    set_nonroot_daemon(nonroot);
128
  }
×
129
}
130
END_TEST
1✔
131

132
START_TEST (privs_relinquish_test) {
133
  int nonroot, res;
1✔
134

1✔
135
  if (privs_uid != 0) {
136
    res = pr_privs_relinquish(__FILE__, __LINE__);
1✔
137
    ck_assert_msg(res == 0, "Failed to relinquish privs: %s", strerror(errno));
×
138

×
139
    nonroot = set_nonroot_daemon(FALSE);
140

×
141
    res = pr_privs_relinquish(__FILE__, __LINE__);
142
    ck_assert_msg(res == 0, "Failed to relinquish privs: %s", strerror(errno));
×
143

×
144
    set_nonroot_daemon(nonroot);
145
  }
×
146
}
147
END_TEST
1✔
148

149
START_TEST (privs_revoke_test) {
150
  int nonroot, res;
1✔
151

1✔
152
  if (privs_uid != 0) {
153
    res = pr_privs_revoke(__FILE__, __LINE__);
1✔
154
    ck_assert_msg(res == 0, "Failed to revoke privs: %s", strerror(errno));
×
155

×
156
    nonroot = set_nonroot_daemon(FALSE);
157

×
158
    res = pr_privs_revoke(__FILE__, __LINE__);
159
    ck_assert_msg(res == 0, "Failed to revoke privs: %s", strerror(errno));
×
160

×
161
    set_nonroot_daemon(nonroot);
162
  }
×
163
}
164
END_TEST
1✔
165

166
Suite *tests_get_privs_suite(void) {
167
  Suite *suite;
890✔
168
  TCase *testcase;
890✔
169

890✔
170
  suite = suite_create("privs");
171

890✔
172
  testcase = tcase_create("base");
173
  tcase_add_checked_fixture(testcase, set_up, tear_down);
890✔
174

890✔
175
  tcase_add_test(testcase, privs_set_nonroot_daemon_test);
176
  tcase_add_test(testcase, privs_setup_test);
890✔
177
  tcase_add_test(testcase, privs_root_test);
890✔
178
  tcase_add_test(testcase, privs_user_test);
890✔
179
  tcase_add_test(testcase, privs_relinquish_test);
890✔
180
  tcase_add_test(testcase, privs_revoke_test);
890✔
181

890✔
182
  suite_add_tcase(suite, testcase);
183
  return suite;
890✔
184
}
890✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE TRIAL · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc