Line 0
Link Here
|
|
|
1 |
--- ngrep.c.orig 2006-11-28 17:38:43.000000000 +0400 |
2 |
+++ ngrep.c 2014-12-12 11:14:13.000000000 +0400 |
3 |
@@ -97,6 +97,10 @@ |
4 |
#include "regex-0.12/regex.h" |
5 |
#endif |
6 |
|
7 |
+#ifdef HAVE_CAPSICUM |
8 |
+#include <sys/capability.h> |
9 |
+#endif /* HAVE CAPSICUM */ |
10 |
+ |
11 |
#include "ngrep.h" |
12 |
|
13 |
|
14 |
@@ -186,6 +190,10 @@ uint32_t ws_row, ws_col = 80, ws_col_for |
15 |
int main(int argc, char **argv) { |
16 |
int32_t c; |
17 |
|
18 |
+#ifdef HAVE_CAPSICUM |
19 |
+ cap_rights_t rights; |
20 |
+#endif /* HAVE_CAPSICUM */ |
21 |
+ |
22 |
signal(SIGINT, clean_exit); |
23 |
signal(SIGABRT, clean_exit); |
24 |
|
25 |
@@ -416,6 +424,23 @@ int main(int argc, char **argv) { |
26 |
clean_exit(-1); |
27 |
} |
28 |
|
29 |
+#ifdef HAVE_CAPSICUM |
30 |
+ cap_rights_init(&rights, CAP_IOCTL, CAP_READ); |
31 |
+ if (cap_rights_limit(pcap_fileno(pd), &rights) < 0 && |
32 |
+ errno != ENOSYS) { |
33 |
+ fprintf(stderr, "unable to limit pcap descriptor"); |
34 |
+ clean_exit(-1); |
35 |
+ } |
36 |
+ |
37 |
+ static const unsigned long cmds[] = { BIOCGSTATS }; |
38 |
+ if (cap_ioctls_limit(pcap_fileno(pd), cmds, |
39 |
+ sizeof(cmds) / sizeof(cmds[0])) < 0 && errno != ENOSYS) { |
40 |
+ fprintf(stderr, "unable to limit ioctls on pcap descriptor"); |
41 |
+ clean_exit(-1); |
42 |
+ } |
43 |
+ |
44 |
+#endif /* HAVE CAPSICUM */ |
45 |
+ |
46 |
if (match_data) { |
47 |
if (bin_match) { |
48 |
uint32_t i = 0, n; |
49 |
@@ -603,6 +628,20 @@ int main(int argc, char **argv) { |
50 |
drop_privs(); |
51 |
#endif |
52 |
|
53 |
+#ifdef HAVE_CAPSICUM |
54 |
+ cap_rights_init(&rights); |
55 |
+ |
56 |
+ if (cap_rights_limit(STDIN_FILENO, &rights) < 0 && errno != ENOSYS) { |
57 |
+ fprintf(stderr, "can't limit stdin"); |
58 |
+ clean_exit(-1); |
59 |
+ } |
60 |
+ |
61 |
+ if (cap_enter() < 0 && errno != ENOSYS) { |
62 |
+ fprintf(stderr, "Can't enter capability mode"); |
63 |
+ clean_exit(-1); |
64 |
+ } |
65 |
+#endif /* HAVE_CAPSICUM */ |
66 |
+ |
67 |
while (pcap_loop(pd, 0, (pcap_handler)process, 0)); |
68 |
|
69 |
clean_exit(0); |