]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Merge branch 'master' of git+ssh://bpf.tcpdump.org/tcpdump/master/git/tcpdump
authorMichael Richardson <[email protected]>
Sat, 19 Jul 2014 17:50:32 +0000 (13:50 -0400)
committerMichael Richardson <[email protected]>
Sat, 19 Jul 2014 17:50:32 +0000 (13:50 -0400)
CREDITS
config.h.in
configure
configure.in
print-802_11.c
print-lldp.c
print-snmp.c
tcpdump.1.in
tcpdump.c

diff --git a/CREDITS b/CREDITS
index 66a7f81c63cc0a81392fa7ea9243834bd27215bb..b8ef1e07a93cb5a3ec1bb593e1761f5f2ba2406c 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -116,6 +116,7 @@ Additional people who have contributed patches:
     Krzysztof Halasa              <khc at pm dot waw dot pl>
     Larry Lile                    <lile at stdio dot com>
     Lennert Buytenhek             <buytenh at gnu dot org>
+    Loganaden Velvindron          <logan at elandsys dot com>
     Longinus00                    <Longinus00 at gmail dot com>
     Loris Degioanni               <loris at netgroup-serv dot polito dot it>
     Love Hörnquist-Ã…strand        <lha at stacken dot kth dot se>
index eb48e22418d69a8b4767a99ffa217fc79584da38..2138832fcd4eb006fe64405c2512fb16e9e8ac17 100644 (file)
@@ -9,6 +9,21 @@
 /* Define to 1 if you have the `bpf_dump' function. */
 #undef HAVE_BPF_DUMP
 
+/* capsicum support available */
+#undef HAVE_CAPSICUM
+
+/* Define to 1 if you have the `cap_enter' function. */
+#undef HAVE_CAP_ENTER
+
+/* Define to 1 if you have the `cap_ioctls_limit' function. */
+#undef HAVE_CAP_IOCTLS_LIMIT
+
+/* Define to 1 if you have the `cap_rights_init' function. */
+#undef HAVE_CAP_RIGHTS_INIT
+
+/* Define to 1 if you have the `cap_rights_limit' function. */
+#undef HAVE_CAP_RIGHTS_LIMIT
+
 /* Define to 1 if you have the declaration of `ether_ntohost', and to 0 if you
    don't. */
 #undef HAVE_DECL_ETHER_NTOHOST
@@ -67,6 +82,9 @@
 /* Define to 1 if you have the <net/pfvar.h> header file. */
 #undef HAVE_NET_PFVAR_H
 
+/* Define to 1 if you have the `openat' function. */
+#undef HAVE_OPENAT
+
 /* Define to 1 if you have the <openssl/evp.h> header file. */
 #undef HAVE_OPENSSL_EVP_H
 
index 08c2a6af2c66801ce11dccc56c9f109b434005c1..516fdfcd674e794d438d71ed8c13a3849fce4c62 100755 (executable)
--- a/configure
+++ b/configure
@@ -703,6 +703,7 @@ with_smi
 enable_smb
 with_user
 with_chroot
+with_sandbox_capsicum
 enable_ipv6
 with_crypto
 '
@@ -1340,6 +1341,7 @@ Optional Packages:
   --without-smi           don't link with libsmi
   --with-user=USERNAME    drop privileges by default to USERNAME
   --with-chroot=DIRECTORY when dropping privileges, chroot to DIRECTORY
+ --with-sandbox-capsicum
   --with-crypto           use OpenSSL libcrypto [default=yes, if available]
 
 Some influential environment variables:
@@ -4516,6 +4518,48 @@ else
 $as_echo "no" >&6; }
 fi
 
+
+# Check whether --with-sandbox-capsicum was given.
+if test "${with_sandbox_capsicum+set}" = set; then :
+  withval=$with_sandbox_capsicum;
+fi
+
+#
+# Check whether various functions are available.  If any are, set
+# ac_lbl_capsicum_function_seen to yes; if any are not, set
+# ac_lbl_capsicum_function_not_seen to yes.
+#
+# All of them must be available in order to enable capsicum sandboxing.
+#
+if test ! -z "$with_sandbox-capsicum" && test "$with_sandbox-capsicum" != "no" ; then
+       for ac_func in cap_enter cap_rights_init cap_rights_limit cap_ioctls_limit openat
+do :
+  as_ac_var=`$as_echo "ac_cv_func_$ac_func" | $as_tr_sh`
+ac_fn_c_check_func "$LINENO" "$ac_func" "$as_ac_var"
+if eval test \"x\$"$as_ac_var"\" = x"yes"; then :
+  cat >>confdefs.h <<_ACEOF
+#define `$as_echo "HAVE_$ac_func" | $as_tr_cpp` 1
+_ACEOF
+ ac_lbl_capsicum_function_seen=yes
+else
+  ac_lbl_capsicum_function_not_seen=yes
+fi
+done
+
+fi
+{ $as_echo "$as_me:${as_lineno-$LINENO}: checking whether to sandbox using capsicum" >&5
+$as_echo_n "checking whether to sandbox using capsicum... " >&6; }
+if test "x$ac_lbl_capsicum_function_seen" = "xyes" -a "x$ac_lbl_capsicum_function_not_seen" != "xyes"; then
+
+$as_echo "#define HAVE_CAPSICUM 1" >>confdefs.h
+
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: yes" >&5
+$as_echo "yes" >&6; }
+else
+       { $as_echo "$as_me:${as_lineno-$LINENO}: result: no" >&5
+$as_echo "no" >&6; }
+fi
+
 #
 # We must check this before checking whether to enable IPv6, because,
 # on some platforms (such as SunOS 5.x), the test program requires
index c88f4705f0efd85ee19007757a39d295f54ac1d1..a63087d7a8d77abaa0ac43add3498d05c6fe8409 100644 (file)
@@ -177,6 +177,27 @@ else
        AC_MSG_RESULT(no)
 fi
 
+AC_ARG_WITH(sandbox-capsicum, [ --with-sandbox-capsicum ])
+#
+# Check whether various functions are available.  If any are, set
+# ac_lbl_capsicum_function_seen to yes; if any are not, set
+# ac_lbl_capsicum_function_not_seen to yes.
+#
+# All of them must be available in order to enable capsicum sandboxing.
+#
+if test ! -z "$with_sandbox-capsicum" && test "$with_sandbox-capsicum" != "no" ; then
+       AC_CHECK_FUNCS(cap_enter cap_rights_init cap_rights_limit cap_ioctls_limit openat,
+           ac_lbl_capsicum_function_seen=yes,
+           ac_lbl_capsicum_function_not_seen=yes)
+fi
+AC_MSG_CHECKING([whether to sandbox using capsicum])
+if test "x$ac_lbl_capsicum_function_seen" = "xyes" -a "x$ac_lbl_capsicum_function_not_seen" != "xyes"; then
+       AC_DEFINE(HAVE_CAPSICUM, 1, [capsicum support available])
+       AC_MSG_RESULT(yes)
+else
+       AC_MSG_RESULT(no)
+fi
+
 #
 # We must check this before checking whether to enable IPv6, because,
 # on some platforms (such as SunOS 5.x), the test program requires
index 4f76a4aa7c799c87c749e493768881dd31143814..697e2c92600078769cf449b9d913fd52d14fc6c4 100644 (file)
@@ -1187,9 +1187,7 @@ static const char *status_text[] = {
        "The request has not been successful as one or more parameters "
          "have invalid values",                                /* 38 */
        "The TS has not been created because the request cannot be honored. "
-         "However, a suggested TSPEC is provided so that the initiating QSTA"
-         "may attempt to set another TS with the suggested changes to the "
-         "TSPEC",                                              /* 39 */
+         "Try again with the suggested changes to the TSPEC",  /* 39 */
        "Invalid Information Element",                          /* 40 */
        "Group Cipher is not valid",                            /* 41 */
        "Pairwise Cipher is not valid",                         /* 42 */
index 3564e568cdf773e7a9de557d58d8b492e2f08ed6..e499507bba7e80d7b082aa294d2695e0967dfc0c 100644 (file)
@@ -1180,9 +1180,12 @@ lldp_private_dcbx_print(netdissect_options *ndo,
            ND_PRINT((ndo, "\n\t      SubType: %d", *(tptr + 3)));
            ND_PRINT((ndo, "\n\t      Priority Allocation"));
 
+           /*
+            * Array of 8 4-bit priority group ID values; we fetch all
+            * 32 bits and extract each nibble.
+            */
            pgval = EXTRACT_32BITS(tptr+4);
            for (i = 0; i <= 7; i++) {
-               tval = *(tptr+4+(i/2));
                ND_PRINT((ndo, "\n\t          PgId_%d: %d",
                        i, (pgval >> (28 - 4 * i)) & 0xF));
            }
index 40d559da4bbb91180fe4a4a0e9d27ccfc9f5948b..53bc210a367e99d70668e54f92c429623b375c54 100644 (file)
@@ -898,6 +898,7 @@ smi_decode_oid(netdissect_options *ndo,
        u_char *p = (u_char *)elem->data.raw;
        uint32_t asnlen = elem->asnlen;
        int o = 0, first = -1, i = asnlen;
+       unsigned int firstval;
 
        for (*oidlen = 0; ndo->ndo_sflag && i-- > 0; p++) {
                ND_TCHECK(*p);
@@ -911,12 +912,12 @@ smi_decode_oid(netdissect_options *ndo,
                 */
                if (first < 0) {
                        first = 0;
+                       firstval = o / OIDMUX;
+                       if (firstval > 2) firstval = 2;
+                       o -= firstval * OIDMUX;
                        if (*oidlen < oidsize) {
-                           oid[*oidlen] = o / OIDMUX;
-                           if (oid[*oidlen] > 2) oid[*oidlen] = 2;
+                           oid[(*oidlen)++] = firstval;
                        }
-                       o -= oid[*oidlen] * OIDMUX;
-                       if (*oidlen < oidsize) (*oidlen)++;
                }
                if (*oidlen < oidsize) {
                        oid[(*oidlen)++] = o;
index efc086535cc0b75b74cc5324575edaf2f8915bbf..a96646928b09e1975c30f2943819ccf49ae29e49 100644 (file)
 .\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
 .\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 .\"
-.TH TCPDUMP 1  "6 May 2014"
+.TH TCPDUMP 1  "11 July 2014"
 .SH NAME
 tcpdump \- dump traffic on a network
 .SH SYNOPSIS
 .na
 .B tcpdump
 [
-.B \-AbdDefhHIJKlLnNOpqRStuUvxX
+.B \-AbdDefhHIJKlLnNOpqRStuUvxX#
 ] [
 .B \-B
 .I buffer_size
-] [
+]
+.br
+.ti +8
+[
 .B \-c
 .I count
 ]
@@ -534,7 +537,11 @@ E.g.,
 if you give this flag then \fItcpdump\fP will print ``nic''
 instead of ``nic.ddn.mil''.
 .TP
+.B \-#
+.PD 0
+.TP
 .B \-\-number
+.PD
 Print an optional packet number at the beginning of the line.
 .TP
 .B \-O
index 7db319aa43d6006ebde49c242141de6a7fe86eb8..11dc8bc8b854f356ccbe805ef0308357afbd637f 100644 (file)
--- a/tcpdump.c
+++ b/tcpdump.c
@@ -72,6 +72,13 @@ extern int SIZE_BUF;
 #include <stdlib.h>
 #include <string.h>
 #include <limits.h>
+#ifdef HAVE_CAPSICUM
+#include <sys/capability.h>
+#include <sys/ioccom.h>
+#include <net/bpf.h>
+#include <fcntl.h>
+#include <libgen.h>
+#endif /* HAVE_CAPSICUM */
 #ifndef WIN32
 #include <sys/wait.h>
 #include <sys/resource.h>
@@ -441,6 +448,9 @@ struct dump_info {
        char    *CurrentFileName;
        pcap_t  *pd;
        pcap_dumper_t *p;
+#ifdef HAVE_CAPSICUM
+       int     dirfd;
+#endif
 };
 
 #ifdef HAVE_PCAP_SET_TSTAMP_TYPE
@@ -648,9 +658,8 @@ show_devices_and_exit (void)
  * component of the entry for the long option, and have a case for that
  * option in the switch statement.
  */
-#define OPTION_NUMBER          128
-#define OPTION_VERSION         129
-#define OPTION_TSTAMP_PRECISION        130
+#define OPTION_VERSION         128
+#define OPTION_TSTAMP_PRECISION        129
 
 static const struct option longopts[] = {
 #if defined(HAVE_PCAP_CREATE) || defined(WIN32)
@@ -686,7 +695,7 @@ static const struct option longopts[] = {
        { "debug-filter-parser", no_argument, NULL, 'Y' },
 #endif
        { "relinquish-privileges", required_argument, NULL, 'Z' },
-       { "number", no_argument, NULL, OPTION_NUMBER },
+       { "number", no_argument, NULL, '#' },
        { "version", no_argument, NULL, OPTION_VERSION },
        { NULL, 0, NULL, 0 }
 };
@@ -910,6 +919,11 @@ main(int argc, char **argv)
 #endif
        int status;
        FILE *VFile;
+#ifdef HAVE_CAPSICUM
+       cap_rights_t rights;
+       int cansandbox;
+#endif /* HAVE_CAPSICUM */
+
 #ifdef WIN32
        if(wsockinit() != 0) return 1;
 #endif /* WIN32 */
@@ -945,7 +959,7 @@ main(int argc, char **argv)
 #endif
 
        while (
-           (op = getopt_long(argc, argv, "aAb" B_FLAG "c:C:d" D_FLAG "eE:fF:G:hHi:" I_FLAG j_FLAG J_FLAG "KlLm:M:nNOpq" Q_FLAG "r:Rs:StT:u" U_FLAG "vV:w:W:xXy:Yz:Z:", longopts, NULL)) != -1)
+           (op = getopt_long(argc, argv, "aAb" B_FLAG "c:C:d" D_FLAG "eE:fF:G:hHi:" I_FLAG j_FLAG J_FLAG "KlLm:M:nNOpq" Q_FLAG "r:Rs:StT:u" U_FLAG "vV:w:W:xXy:Yz:Z:#", longopts, NULL)) != -1)
                switch (op) {
 
                case 'a':
@@ -1306,7 +1320,7 @@ main(int argc, char **argv)
                        username = strdup(optarg);
                        break;
 
-               case OPTION_NUMBER:
+               case '#':
                        gndo->ndo_packet_number = 1;
                        break;
 
@@ -1423,6 +1437,13 @@ main(int argc, char **argv)
 
                if (pd == NULL)
                        error("%s", ebuf);
+#ifdef HAVE_CAPSICUM
+               cap_rights_init(&rights, CAP_READ);
+               if (cap_rights_limit(fileno(pcap_file(pd)), &rights) < 0 &&
+                   errno != ENOSYS) {
+                       error("unable to limit pcap descriptor");
+               }
+#endif
                dlt = pcap_datalink(pd);
                dlt_name = pcap_datalink_val_to_name(dlt);
                if (dlt_name == NULL) {
@@ -1687,6 +1708,21 @@ main(int argc, char **argv)
 
        if (pcap_setfilter(pd, &fcode) < 0)
                error("%s", pcap_geterr(pd));
+#ifdef HAVE_CAPSICUM
+       if (RFileName == NULL && VFileName == NULL) {
+               static const unsigned long cmds[] = { BIOCGSTATS };
+
+               cap_rights_init(&rights, CAP_IOCTL, CAP_READ);
+               if (cap_rights_limit(pcap_fileno(pd), &rights) < 0 &&
+                   errno != ENOSYS) {
+                       error("unable to limit pcap descriptor");
+               }
+               if (cap_ioctls_limit(pcap_fileno(pd), cmds,
+                   sizeof(cmds) / sizeof(cmds[0])) < 0 && errno != ENOSYS) {
+                       error("unable to limit ioctls on pcap descriptor");
+               }
+       }
+#endif
        if (WFileName) {
                pcap_dumper_t *p;
                /* Do not exceed the default PATH_MAX for files. */
@@ -1708,9 +1744,32 @@ main(int argc, char **argv)
 #endif
                if (p == NULL)
                        error("%s", pcap_geterr(pd));
+#ifdef HAVE_CAPSICUM
+               cap_rights_init(&rights, CAP_SEEK, CAP_WRITE);
+               if (cap_rights_limit(fileno(pcap_dump_file(p)), &rights) < 0 &&
+                   errno != ENOSYS) {
+                       error("unable to limit dump descriptor");
+               }
+#endif
                if (Cflag != 0 || Gflag != 0) {
-                       callback = dump_packet_and_trunc;
+#ifdef HAVE_CAPSICUM
+                       dumpinfo.WFileName = strdup(basename(WFileName));
+                       dumpinfo.dirfd = open(dirname(WFileName),
+                           O_DIRECTORY | O_RDONLY);
+                       if (dumpinfo.dirfd < 0) {
+                               error("unable to open directory %s",
+                                   dirname(WFileName));
+                       }
+                       cap_rights_init(&rights, CAP_CREATE, CAP_FCNTL,
+                           CAP_FTRUNCATE, CAP_LOOKUP, CAP_SEEK, CAP_WRITE);
+                       if (cap_rights_limit(dumpinfo.dirfd, &rights) < 0 &&
+                           errno != ENOSYS) {
+                               error("unable to limit directory rights");
+                       }
+#else  /* !HAVE_CAPSICUM */
                        dumpinfo.WFileName = WFileName;
+#endif
+                       callback = dump_packet_and_trunc;
                        dumpinfo.pd = pd;
                        dumpinfo.p = p;
                        pcap_userdata = (u_char *)&dumpinfo;
@@ -1780,6 +1839,15 @@ main(int argc, char **argv)
                (void)fflush(stderr);
        }
 #endif /* WIN32 */
+
+#ifdef HAVE_CAPSICUM
+       cansandbox = (nflag && VFileName == NULL && zflag == NULL);
+       if (cansandbox && cap_enter() < 0 && errno != ENOSYS)
+               error("unable to enter the capability mode");
+       if (cap_sandboxed())
+               fprintf(stderr, "capability mode sandbox enabled\n");
+#endif /* HAVE_CAPSICUM */
+
        do {
                status = pcap_loop(pd, cnt, callback, pcap_userdata);
                if (WFileName == NULL) {
@@ -1827,6 +1895,13 @@ main(int argc, char **argv)
                                pd = pcap_open_offline(RFileName, ebuf);
                                if (pd == NULL)
                                        error("%s", ebuf);
+#ifdef HAVE_CAPSICUM
+                               cap_rights_init(&rights, CAP_READ);
+                               if (cap_rights_limit(fileno(pcap_file(pd)),
+                                   &rights) < 0 && errno != ENOSYS) {
+                                       error("unable to limit pcap descriptor");
+                               }
+#endif
                                new_dlt = pcap_datalink(pd);
                                if (WFileName && new_dlt != dlt)
                                        error("%s: new dlt does not match original", RFileName);
@@ -1995,6 +2070,9 @@ static void
 dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *sp)
 {
        struct dump_info *dump_info;
+#ifdef HAVE_CAPSICUM
+       cap_rights_t rights;
+#endif
 
        ++packets_captured;
 
@@ -2023,6 +2101,11 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s
 
                /* If the time is greater than the specified window, rotate */
                if (t - Gflag_time >= Gflag) {
+#ifdef HAVE_CAPSICUM
+                       FILE *fp;
+                       int fd;
+#endif
+
                        /* Update the Gflag_time */
                        Gflag_time = t;
                        /* Update Gflag_count */
@@ -2076,13 +2159,36 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s
                        capng_update(CAPNG_ADD, CAPNG_EFFECTIVE, CAP_DAC_OVERRIDE);
                        capng_apply(CAPNG_EFFECTIVE);
 #endif /* HAVE_CAP_NG_H */
+#ifdef HAVE_CAPSICUM
+                       fd = openat(dump_info->dirfd,
+                           dump_info->CurrentFileName,
+                           O_CREAT | O_WRONLY | O_TRUNC, 0644);
+                       if (fd < 0) {
+                               error("unable to open file %s",
+                                   dump_info->CurrentFileName);
+                       }
+                       fp = fdopen(fd, "w");
+                       if (fp == NULL) {
+                               error("unable to fdopen file %s",
+                                   dump_info->CurrentFileName);
+                       }
+                       dump_info->p = pcap_dump_fopen(dump_info->pd, fp);
+#else  /* !HAVE_CAPSICUM */
                        dump_info->p = pcap_dump_open(dump_info->pd, dump_info->CurrentFileName);
+#endif
 #ifdef HAVE_CAP_NG_H
                        capng_update(CAPNG_DROP, CAPNG_EFFECTIVE, CAP_DAC_OVERRIDE);
                        capng_apply(CAPNG_EFFECTIVE);
 #endif /* HAVE_CAP_NG_H */
                        if (dump_info->p == NULL)
                                error("%s", pcap_geterr(pd));
+#ifdef HAVE_CAPSICUM
+                       cap_rights_init(&rights, CAP_SEEK, CAP_WRITE);
+                       if (cap_rights_limit(fileno(pcap_dump_file(dump_info->p)),
+                           &rights) < 0 && errno != ENOSYS) {
+                               error("unable to limit dump descriptor");
+                       }
+#endif
                }
        }
 
@@ -2092,6 +2198,11 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s
         * file could put it over Cflag.
         */
        if (Cflag != 0 && pcap_dump_ftell(dump_info->p) > Cflag) {
+#ifdef HAVE_CAPSICUM
+               FILE *fp;
+               int fd;
+#endif
+
                /*
                 * Close the current file and open a new one.
                 */
@@ -2114,9 +2225,31 @@ dump_packet_and_trunc(u_char *user, const struct pcap_pkthdr *h, const u_char *s
                if (dump_info->CurrentFileName == NULL)
                        error("dump_packet_and_trunc: malloc");
                MakeFilename(dump_info->CurrentFileName, dump_info->WFileName, Cflag_count, WflagChars);
+#ifdef HAVE_CAPSICUM
+               fd = openat(dump_info->dirfd, dump_info->CurrentFileName,
+                   O_CREAT | O_WRONLY | O_TRUNC, 0644);
+               if (fd < 0) {
+                       error("unable to open file %s",
+                           dump_info->CurrentFileName);
+               }
+               fp = fdopen(fd, "w");
+               if (fp == NULL) {
+                       error("unable to fdopen file %s",
+                           dump_info->CurrentFileName);
+               }
+               dump_info->p = pcap_dump_fopen(dump_info->pd, fp);
+#else  /* !HAVE_CAPSICUM */
                dump_info->p = pcap_dump_open(dump_info->pd, dump_info->CurrentFileName);
+#endif
                if (dump_info->p == NULL)
                        error("%s", pcap_geterr(pd));
+#ifdef HAVE_CAPSICUM
+               cap_rights_init(&rights, CAP_SEEK, CAP_WRITE);
+               if (cap_rights_limit(fileno(pcap_dump_file(dump_info->p)),
+                   &rights) < 0 && errno != ENOSYS) {
+                       error("unable to limit dump descriptor");
+               }
+#endif
        }
 
        pcap_dump((u_char *)dump_info->p, h, sp);
@@ -2365,7 +2498,7 @@ print_usage(void)
 {
        print_version();
        (void)fprintf(stderr,
-"Usage: %s [-aAbd" D_FLAG "efhH" I_FLAG J_FLAG "KlLnNOpqRStu" U_FLAG "vxX]" B_FLAG_USAGE " [ -c count ]\n", program_name);
+"Usage: %s [-aAbd" D_FLAG "efhH" I_FLAG J_FLAG "KlLnNOpqRStu" U_FLAG "vxX#]" B_FLAG_USAGE " [ -c count ]\n", program_name);
        (void)fprintf(stderr,
 "\t\t[ -C file_size ] [ -E algo:secret ] [ -F file ] [ -G seconds ]\n");
        (void)fprintf(stderr,