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 #ifndef HAVE_LIBCAP_NG
37 #define SCDropCaps(...)
38 #define SCDropMainThreadCaps(...)
39 #else
40 #include <cap-ng.h>
41 
42 /**Drop the previliges of the given thread tv, based on the thread cap_flags
43  * which implies the capability requirement of the given thread. Initially all
44  * caps are dropped and later, the required caps are set for the given thread
45  */
46 void SCDropCaps(ThreadVars *tv);
47 /*
48 #define SCDropCaps(tv) ({ \
49  capng_clear(CAPNG_SELECT_BOTH); \
50  capng_apply(CAPNG_SELECT_BOTH); \
51  if (tv->cap_flags & SC_CAP_IPC_LOCK) { \
52  capng_update(CAPNG_ADD, (capng_type_t) (CAPNG_EFFECTIVE | CAPNG_PERMITTED), CAP_IPC_LOCK); \
53  capng_apply(CAPNG_SELECT_CAPS); \
54  SCLogDebug("For thread \"%s\" CAP_IPC_LOCK has been set", tv->name); \
55  } \
56  if (tv->cap_flags & SC_CAP_NET_ADMIN) { \
57  capng_update(CAPNG_ADD, (capng_type_t) (CAPNG_EFFECTIVE | CAPNG_PERMITTED), CAP_NET_ADMIN); \
58  capng_apply(CAPNG_SELECT_CAPS); \
59  SCLogDebug("For thread \"%s\" CAP_NET_ADMIN has been set", tv->name); \
60  } \
61  if (tv->cap_flags & SC_CAP_NET_BIND_SERVICE) { \
62  capng_update(CAPNG_ADD, (capng_type_t) (CAPNG_EFFECTIVE | CAPNG_PERMITTED), CAP_NET_BIND_SERVICE); \
63  capng_apply(CAPNG_SELECT_CAPS); \
64  SCLogDebug("For thread \"%s\" CAP_NET_BIND_SERVICE has been set", tv->name); \
65  } \
66  if (tv->cap_flags & SC_CAP_NET_BROADCAST) { \
67  capng_update(CAPNG_ADD, (capng_type_t) (CAPNG_EFFECTIVE | CAPNG_PERMITTED), CAP_NET_BROADCAST); \
68  capng_apply(CAPNG_SELECT_CAPS); \
69  SCLogDebug("For thread \"%s\" CAP_NET_BROADCAST has been set", tv->name); \
70  } \
71  if (tv->cap_flags & SC_CAP_NET_RAW) { \
72  capng_update(CAPNG_ADD, (capng_type_t) (CAPNG_EFFECTIVE | CAPNG_PERMITTED), CAP_NET_RAW); \
73  capng_apply(CAPNG_SELECT_CAPS); \
74  SCLogDebug("For thread \"%s\" CAP_NET_RAW has been set", tv->name); \
75  } \
76  if (tv->cap_flags & SC_CAP_SYS_ADMIN) { \
77  capng_update(CAPNG_ADD, (capng_type_t) (CAPNG_EFFECTIVE | CAPNG_PERMITTED), CAP_SYS_ADMIN); \
78  capng_apply(CAPNG_SELECT_CAPS); \
79  SCLogDebug("For thread \"%s\" CAP_SYS_ADMIN has been set", tv->name); \
80  } \
81  if (tv->cap_flags & SC_CAP_SYS_RAW_IO) { \
82  capng_update(CAPNG_ADD, (capng_type_t) (CAPNG_EFFECTIVE | CAPNG_PERMITTED), CAP_SYS_RAWIO); \
83  capng_apply(CAPNG_SELECT_CAPS); \
84  SCLogDebug("For thread \"%s\" CAP_SYS_RAWIO has been set", tv->name); \
85  } \
86 })
87 */
88 void SCDropMainThreadCaps(uint32_t , uint32_t );
89 
90 #endif /* HAVE_LIBCAP_NG */
91 
92 int SCGetUserID(const char *, const char *, uint32_t *, uint32_t *);
93 int SCGetGroupID(const char *, uint32_t *);
94 
95 #ifdef __OpenBSD__
96 int SCPledge(void);
97 #else /* __OpenBSD__ */
98 #define SCPledge(...)
99 #endif /* __OpenBSD__ */
100 
101 #endif /* _UTIL_PRIVS_H */
102 
SCGetGroupID
int SCGetGroupID(const char *, uint32_t *)
Function to get the group ID from the specified group name.
Definition: util-privs.c:213
SCPledge
#define SCPledge(...)
Definition: util-privs.h:98
SCDropCaps
#define SCDropCaps(...)
Definition: util-privs.h:37
SCGetUserID
int 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:149
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:56
SCDropMainThreadCaps
#define SCDropMainThreadCaps(...)
Definition: util-privs.h:38
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:31