]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Add format options to save the value fetched and to later use that value
authorguy <guy>
Wed, 29 Dec 2004 03:10:24 +0000 (03:10 +0000)
committerguy <guy>
Wed, 29 Dec 2004 03:10:24 +0000 (03:10 +0000)
for counted strings, and use them where appropriate.

print-smb.c
smbutil.c

index 8f0e9ccf5dc19788810816dcbea137d2b9989b05..573e7c80d7bc7febe792170c68b5d85b793cb35f 100644 (file)
@@ -12,7 +12,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-     "@(#) $Header: /tcpdump/master/tcpdump/print-smb.c,v 1.39 2004-12-29 02:43:24 guy Exp $";
+     "@(#) $Header: /tcpdump/master/tcpdump/print-smb.c,v 1.40 2004-12-29 03:10:24 guy Exp $";
 #endif
 
 #include <tcpdump-stdinc.h>
@@ -123,10 +123,10 @@ trans2_qfsinfo(const u_char *param, const u_char *data, int pcnt, int dcnt)
            fmt = "idFileSystem=[W]\nSectorUnit=[D]\nUnit=[D]\nAvail=[D]\nSectorSize=[d]\n";
            break;
        case 2:
-           fmt = "CreationTime=[T2]VolNameLength=[B]\nVolumeLabel=[s12]\n";
+           fmt = "CreationTime=[T2]VolNameLength=[lb]\nVolumeLabel=[c]\n";
            break;
        case 0x105:
-           fmt = "Capabilities=[W]\nMaxFileLen=[D]\nVolNameLen=[D]\nVolume=[S]\n";
+           fmt = "Capabilities=[W]\nMaxFileLen=[D]\nVolNameLen=[lD]\nVolume=[C]\n";
            break;
        default:
            fmt = "UnknownLevel\n";
@@ -210,14 +210,14 @@ print_trans2(const u_char *words, const u_char *dat, const u_char *buf, const u_
            return;
        } else {
            smb_fdata(words + 1,
-               "TotParam=[d]\nTotData=[d]\nMaxParam=[d]\nMaxData=[d]\nMaxSetup=[d]\nFlags=[w]\nTimeOut=[D]\nRes1=[w]\nParamCnt=[d]\nParamOff=[d]\nDataCnt=[d]\nDataOff=[d]\nSetupCnt=[d]\n",
+               "TotParam=[d]\nTotData=[d]\nMaxParam=[d]\nMaxData=[d]\nMaxSetup=[b][P1]\nFlags=[w]\nTimeOut=[D]\nRes1=[w]\nParamCnt=[d]\nParamOff=[d]\nDataCnt=[d]\nDataOff=[d]\nSetupCnt=[b][P1]\n",
                words + 1 + 14 * 2, unicodestr);
        }
        f1 = fn->descript.req_f1;
        f2 = fn->descript.req_f2;
     } else {
        smb_fdata(words + 1,
-           "TotParam=[d]\nTotData=[d]\nRes1=[w]\nParamCnt=[d]\nParamOff=[d]\nParamDisp[d]\nDataCnt=[d]\nDataOff=[d]\nDataDisp=[d]\nSetupCnt=[d]\n",
+           "TotParam=[d]\nTotData=[d]\nRes1=[w]\nParamCnt=[d]\nParamOff=[d]\nParamDisp[d]\nDataCnt=[d]\nDataOff=[d]\nDataDisp=[d]\nSetupCnt=[b][P1]\n",
            words + 1 + 10 * 2, unicodestr);
        f1 = fn->descript.rep_f1;
        f2 = fn->descript.rep_f2;
@@ -777,8 +777,8 @@ static struct smbfns smb_fns[] = {
     { SMBnttranss, "SMBnttranss", 0, DEFDESCRIPT },
 
     { SMBntcreateX, "SMBntcreateX", FLG_CHAIN,
-       { "Com2=[w]\nOff2=[d]\nRes=[b]\nNameLen=[d]\nFlags=[W]\nRootDirectoryFid=[D]\nAccessMask=[W]\nAllocationSize=[L]\nExtFileAttributes=[W]\nShareAccess=[W]\nCreateDisposition=[W]\nCreateOptions=[W]\nImpersonationLevel=[W]\nSecurityFlags=[b]\n",
-         "Path=[S]\n",
+       { "Com2=[w]\nOff2=[d]\nRes=[b]\nNameLen=[ld]\nFlags=[W]\nRootDirectoryFid=[D]\nAccessMask=[W]\nAllocationSize=[L]\nExtFileAttributes=[W]\nShareAccess=[W]\nCreateDisposition=[W]\nCreateOptions=[W]\nImpersonationLevel=[W]\nSecurityFlags=[b]\n",
+         "Path=[C]\n",
          "Com2=[w]\nOff2=[d]\nOplockLevel=[b]\nFid=[d]\nCreateAction=[W]\nCreateTime=[T3]LastAccessTime=[T3]LastWriteTime=[T3]ChangeTime=[T3]ExtFileAttributes=[W]\nAllocationSize=[L]\nEndOfFile=[L]\nFileType=[w]\nDeviceState=[w]\nDirectory=[b]\n",
          NULL, NULL } },
 
index 14e600a56cd526d9e66d2317707b43b8d192c914..7d157b66feee7851b0e0b10e1353fb115aa57646 100644 (file)
--- a/smbutil.c
+++ b/smbutil.c
@@ -12,7 +12,7 @@
 
 #ifndef lint
 static const char rcsid[] _U_ =
-     "@(#) $Header: /tcpdump/master/tcpdump/smbutil.c,v 1.32 2004-12-28 22:29:45 guy Exp $";
+     "@(#) $Header: /tcpdump/master/tcpdump/smbutil.c,v 1.33 2004-12-29 03:10:25 guy Exp $";
 #endif
 
 #include <tcpdump-stdinc.h>
@@ -25,6 +25,7 @@ static const char rcsid[] _U_ =
 #include "extract.h"
 #include "smb.h"
 
+static u_int32_t stringlen;
 extern const u_char *startbuf;
 
 /*
@@ -328,38 +329,87 @@ write_bits(unsigned int val, const char *fmt)
 }
 
 /* convert a UCS2 string into iso-8859-1 string */
+#define MAX_UNISTR_SIZE        1000
 static const char *
-unistr(const u_char *s, int *len, int use_unicode)
+unistr(const u_char *s, u_int32_t *len, int use_unicode)
 {
-    static char buf[1000];
-    int l=0;
-
-    if (!use_unicode) {
-       *len = strlen((const char *)s) + 1;
-       return (const char *)s;
+    static char buf[MAX_UNISTR_SIZE+1];
+    size_t l = 0;
+    u_int32_t strsize;
+    const u_char *sp;
+
+    if (use_unicode) {
+       /*
+        * Skip padding that puts the string on an even boundary.
+        */
+       if (((s - startbuf) % 2) != 0)
+           s++;
     }
-
-    /*
-     * Skip padding that puts the string on an even boundary.
-     */
-    if (((s - startbuf) % 2) != 0)
-       s++;
-
-    *len = 0;
-
-    if (s[0] == 0 && s[1] != 0) {
-       s++;
-       *len = 1;
+    if (*len == 0) {
+       /*
+        * Null-terminated string.
+        */
+       strsize = 0;
+       sp = s;
+       if (!use_unicode) {
+           for (;;) {
+               *len += 1;
+               if (sp[0] == 0)
+                   break;
+               sp++;
+           }
+           strsize = *len - 1;
+       } else {
+           for (;;) {
+               *len += 2;
+               if (sp[0] == 0 && sp[1] == 0)
+                   break;
+               sp += 2;
+           }
+           strsize = *len - 2;
+       }
+    } else {
+       /*
+        * Counted string.
+        */
+       strsize = *len;
     }
-
-    while (l < (int)(sizeof(buf) - 1) && s[0] && s[1] == 0) {
-       buf[l] = s[0];
-       s += 2;
-       l++;
-       *len += 2;
+    if (!use_unicode) {
+       while (strsize != 0) {
+           if (l >= MAX_UNISTR_SIZE)
+               break;
+           if (isprint(s[0]))
+               buf[l] = s[0];
+           else {
+               if (s[0] == 0)
+                   break;
+               buf[l] = '.';
+           }
+           l++;
+           s++;
+           strsize--;
+       }
+    } else {
+       while (strsize != 0) {
+           if (l >= MAX_UNISTR_SIZE)
+               break;
+           if (s[1] == 0 && isprint(s[0])) {
+               /* It's a printable ASCII character */
+               buf[l] = s[0];
+           } else {
+               /* It's a non-ASCII character or a non-printable ASCII character */
+               if (s[0] == 0 && s[1] == 0)
+                   break;
+               buf[l] = '.';
+           }
+           l++;
+           s += 2;
+           if (strsize == 1)
+               break;
+           strsize -= 2;
+       }
     }
     buf[l] = 0;
-    *len += 2;
     return buf;
 }
 
@@ -509,12 +559,43 @@ smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf,
            fmt++;
            break;
          }
+       case 'l':
+         {
+           fmt++;
+           switch (*fmt) {
+
+           case 'b':
+               TCHECK(buf[0]);
+               stringlen = buf[0];
+               printf("%u", stringlen);
+               buf += 1;
+               break;
+
+           case 'd':
+               TCHECK2(buf[0], 2);
+               stringlen = reverse ? EXTRACT_16BITS(buf) :
+                                     EXTRACT_LE_16BITS(buf);
+               printf("%u", stringlen);
+               buf += 2;
+               break;
+
+           case 'D':
+               TCHECK2(buf[0], 4);
+               stringlen = reverse ? EXTRACT_32BITS(buf) :
+                                     EXTRACT_LE_32BITS(buf);
+               printf("%u", stringlen);
+               buf += 4;
+               break;
+           }
+           fmt++;
+           break;
+         }
        case 'S':
        case 'R':       /* like 'S', but always ASCII */
          {
            /*XXX unistr() */
-           printf("%.*s", (int)PTR_DIFF(maxbuf, buf),
-               unistr(buf, &len, (*fmt == 'R') ? 0 : unicodestr));
+           len = 0;
+           printf("%s", unistr(buf, &len, (*fmt == 'R') ? 0 : unicodestr));
            buf += len;
            fmt++;
            break;
@@ -525,8 +606,8 @@ smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf,
            if (*buf != 4 && *buf != 2)
                printf("Error! ASCIIZ buffer of type %u (safety=%lu)\n", *buf,
                    (unsigned long)PTR_DIFF(maxbuf, buf));
-           printf("%.*s", (int)PTR_DIFF(maxbuf, buf + 1),
-               unistr(buf + 1, &len, (*fmt == 'Y') ? 0 : unicodestr));
+           len = 0;
+           printf("%s", unistr(buf + 1, &len, (*fmt == 'Y') ? 0 : unicodestr));
            buf += len + 1;
            fmt++;
            break;
@@ -541,6 +622,27 @@ smb_fdata1(const u_char *buf, const char *fmt, const u_char *maxbuf,
                fmt++;
            break;
          }
+       case 'c':
+         {
+           TCHECK2(*buf, stringlen);
+           printf("%-*.*s", stringlen, stringlen, buf);
+           buf += stringlen;
+           fmt++;
+           while (isdigit((unsigned char)*fmt))
+               fmt++;
+           break;
+         }
+       case 'C':
+         {
+           const char *s;
+           s = unistr(buf, &stringlen, unicodestr);
+           if (s == NULL)
+               goto trunc;
+           printf("%s", s);
+           buf += stringlen;
+           fmt++;
+           break;
+         }
        case 'h':
          {
            int l = atoi(fmt + 1);