suricata
util-privs.h
Go to the documentation of this file.
1 /* Copyright (C) 2007-2010 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \file
20  *
21  * \author Gurvinder Singh <gurvindersinghdahiya@gmail.com>
22  */
23 
24 #ifndef _UTIL_PRIVS_H
25 #define _UTIL_PRIVS_H
26 
27 #define SC_CAP_NONE 0x01
28 #define SC_CAP_SYS_ADMIN 0x02
29 #define SC_CAP_SYS_RAW_IO 0x04
30 #define SC_CAP_IPC_LOCK 0x08
31 #define SC_CAP_NET_ADMIN 0x10
32 #define SC_CAP_NET_RAW 0x20
33 #define SC_CAP_NET_BIND_SERVICE 0x40
34 #define SC_CAP_NET_BROADCAST 0x80
35 
36 #ifdef HAVE_LIBCAP_NG
37 #include <cap-ng.h>
38 #include "threadvars.h"
39 
40 /**Drop the privileges of the given thread tv, based on the thread cap_flags
41  * which implies the capability requirement of the given thread. Initially all
42  * caps are dropped and later, the required caps are set for the given thread
43  */
44 void SCDropCaps(ThreadVars *tv);
45 /*
46 #define SCDropCaps(tv) ({ \
47  capng_clear(CAPNG_SELECT_BOTH); \
48  capng_apply(CAPNG_SELECT_BOTH); \
49  if (tv->cap_flags & SC_CAP_IPC_LOCK) { \
50  capng_update(CAPNG_ADD, (capng_type_t) (CAPNG_EFFECTIVE | CAPNG_PERMITTED), CAP_IPC_LOCK); \
51  capng_apply(CAPNG_SELECT_CAPS); \
52  SCLogDebug("For thread \"%s\" CAP_IPC_LOCK has been set", tv->name); \
53  } \
54  if (tv->cap_flags & SC_CAP_NET_ADMIN) { \
55  capng_update(CAPNG_ADD, (capng_type_t) (CAPNG_EFFECTIVE | CAPNG_PERMITTED), CAP_NET_ADMIN); \
56  capng_apply(CAPNG_SELECT_CAPS); \
57  SCLogDebug("For thread \"%s\" CAP_NET_ADMIN has been set", tv->name); \
58  } \
59  if (tv->cap_flags & SC_CAP_NET_BIND_SERVICE) { \
60  capng_update(CAPNG_ADD, (capng_type_t) (CAPNG_EFFECTIVE | CAPNG_PERMITTED), CAP_NET_BIND_SERVICE); \
61  capng_apply(CAPNG_SELECT_CAPS); \
62  SCLogDebug("For thread \"%s\" CAP_NET_BIND_SERVICE has been set", tv->name); \
63  } \
64  if (tv->cap_flags & SC_CAP_NET_BROADCAST) { \
65  capng_update(CAPNG_ADD, (capng_type_t) (CAPNG_EFFECTIVE | CAPNG_PERMITTED), CAP_NET_BROADCAST); \
66  capng_apply(CAPNG_SELECT_CAPS); \
67  SCLogDebug("For thread \"%s\" CAP_NET_BROADCAST has been set", tv->name); \
68  } \
69  if (tv->cap_flags & SC_CAP_NET_RAW) { \
70  capng_update(CAPNG_ADD, (capng_type_t) (CAPNG_EFFECTIVE | CAPNG_PERMITTED), CAP_NET_RAW); \
71  capng_apply(CAPNG_SELECT_CAPS); \
72  SCLogDebug("For thread \"%s\" CAP_NET_RAW has been set", tv->name); \
73  } \
74  if (tv->cap_flags & SC_CAP_SYS_ADMIN) { \
75  capng_update(CAPNG_ADD, (capng_type_t) (CAPNG_EFFECTIVE | CAPNG_PERMITTED), CAP_SYS_ADMIN); \
76  capng_apply(CAPNG_SELECT_CAPS); \
77  SCLogDebug("For thread \"%s\" CAP_SYS_ADMIN has been set", tv->name); \
78  } \
79  if (tv->cap_flags & SC_CAP_SYS_RAW_IO) { \
80  capng_update(CAPNG_ADD, (capng_type_t) (CAPNG_EFFECTIVE | CAPNG_PERMITTED), CAP_SYS_RAWIO); \
81  capng_apply(CAPNG_SELECT_CAPS); \
82  SCLogDebug("For thread \"%s\" CAP_SYS_RAWIO has been set", tv->name); \
83  } \
84 })
85 */
86 void SCDropMainThreadCaps(uint32_t , uint32_t );
87 
88 #else
89 #define SCDropCaps(...)
90 #define SCDropMainThreadCaps(...)
91 #endif /* HAVE_LIBCAP_NG */
92 
93 void SCGetUserID(const char *, const char *, uint32_t *, uint32_t *);
94 void SCGetGroupID(const char *, uint32_t *);
95 
96 #ifdef __OpenBSD__
97 int SCPledge(void);
98 #else /* __OpenBSD__ */
99 #define SCPledge(...)
100 #endif /* __OpenBSD__ */
101 
102 #endif /* _UTIL_PRIVS_H */
103 
SCGetGroupID
void SCGetGroupID(const char *, uint32_t *)
Function to get the group ID from the specified group name.
Definition: util-privs.c:217
SCPledge
#define SCPledge(...)
Definition: util-privs.h:99
SCDropCaps
#define SCDropCaps(...)
Definition: util-privs.h:89
SCGetUserID
void SCGetUserID(const char *, const char *, uint32_t *, uint32_t *)
Function to get the user and group ID from the specified user name.
Definition: util-privs.c:150
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
SCDropMainThreadCaps
#define SCDropMainThreadCaps(...)
Definition: util-privs.h:90
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
threadvars.h