-
Notifications
You must be signed in to change notification settings - Fork 2
/
caps.c
74 lines (60 loc) · 2.07 KB
/
caps.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/***
This file is part of Stallone.
Copyright 2007 Ted Percival <ted@midg3t.net>
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
***/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <errno.h>
#include <string.h>
#ifdef HAVE_SYS_CAPABILITY_H
# include <sys/capability.h>
#endif
#include <libdaemon/dlog.h>
int avahi_natpm_drop_caps(void) {
int ret = 0;
#if defined(HAVE_SYS_CAPABILITY_H) && defined(HAVE_LIBCAP)
cap_t caps;
#if LIBCAP_MADE_THE_POINTER_CONST_LIKE_IT_SHOULD_HAVE_BEEN
const /* continues... */
#endif
cap_value_t inherit_caps[] = { CAP_NET_ADMIN };
/* Not setting any effective or permitted flags, meaning this process
* wants to be totally incapable (except for its inheritable set) */
caps = cap_init();
if (!caps)
return -1;
if (-1 == cap_set_flag(caps, CAP_INHERITABLE,
sizeof(inherit_caps) / sizeof(inherit_caps[0]),
inherit_caps, CAP_SET))
{
daemon_log(LOG_WARNING,
"%s: Unable to assign inheritable capabilities: %s",
__func__, strerror(errno));
ret = -1;
goto cleanup;
}
if (-1 == cap_set_proc(caps)) {
daemon_log(LOG_ERR, "%s: Unable to set reduced capability set: %s",
__func__, strerror(errno));
ret = -1;
goto cleanup;
}
cleanup:
cap_free(caps);
#endif /* libcap */
return ret;
}
/* vim: ts=4 sw=4 et tw=80
*/