this patch does a number of things:
authorAndrew Tridgell <tridge@samba.org>
Tue, 13 Mar 2001 00:55:19 +0000 (00:55 +0000)
committerAndrew Tridgell <tridge@samba.org>
Tue, 13 Mar 2001 00:55:19 +0000 (00:55 +0000)
- removes SMB_ALIGNMENT. That macro caused all sorts of problems with
  getting unicode aligned right in sub-protocols (such as SMBtrans and
  SMBtrans2). I believe the performance reasons for having
  SMB_ALIGNMENT has gone away with the new variants of the SMB
  protocol anyway, as newer commands tend to have their own internal
  alignment.

- fix the locations where we set smb_flg2 to absolute values. We must
  never do this if we want a hope of coping with unicode.

- add initial support for unicode on the wire in smbd. Currently
  enabled using SMBD_USE_UNICODE environment variable.
(This used to be commit b98b1435e9d8f8622444c9ff33082977e661f16b)

source3/include/local.h
source3/smbd/ipc.c
source3/smbd/nttrans.c
source3/smbd/process.c
source3/smbd/reply.c
source3/smbd/trans2.c

index b5590f9f912595c5b847d6446bcc521c452700d0..f693d186239b687a7450779111ef6b533f79a52a 100644 (file)
    accessible to root */
 #define DUMP_CORE 1
 
-#define SMB_ALIGNMENT 1
-
-
 /* shall we support browse requests via a FIFO to nmbd? */
 #define ENABLE_FIFO 1
 
index 3b9e34b4d71127ddb0eb9823d1aa6cc2f83d7548..3cc9aca99e2f73828ec662f0d5295a9c5f6194d9 100644 (file)
@@ -102,7 +102,7 @@ void send_trans_reply(char *outbuf,
        if (buffer_too_large)
        {
                /* issue a buffer size warning.  on a DCE/RPC pipe, expect an SMBreadX... */
-               SIVAL(outbuf, smb_flg2, FLAGS2_32_BIT_ERROR_CODES);
+               SIVAL(outbuf, smb_flg2, SVAL(outbuf, smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
                SIVAL(outbuf, smb_rcls, 0x80000000 | STATUS_BUFFER_OVERFLOW);
        }
 
@@ -376,7 +376,7 @@ int reply_trans(connection_struct *conn, char *inbuf,char *outbuf, int size, int
        START_PROFILE(SMBtrans);
 
        memset(name, '\0',sizeof(name));
-       fstrcpy(name,smb_buf(inbuf));
+       srvstr_pull(inbuf, name, smb_buf(inbuf), sizeof(name), -1, STR_TERMINATE|STR_CONVERT);
 
        if (dscnt > tdscnt || pscnt > tpscnt) {
                exit_server("invalid trans parameters\n");
index 1ccac83b78acc92def67de13bcc5f6651329b8ad..5eadd2bc8e0c77e5d891a42497b1ff83a52f86f9 100644 (file)
@@ -243,7 +243,7 @@ static int send_nt_replies(char *inbuf, char *outbuf, int bufsize, uint32 nt_err
  strings in NT calls AND DOESN'T SET THE UNICODE BIT !!!!!!!
 ****************************************************************************/
 
-static void get_filename( char *fname, char *inbuf, int data_offset, int data_len, int fname_len)
+static void get_filename(char *fname, char *inbuf, int data_offset, int data_len, int fname_len)
 {
   /*
    * We need various heuristics here to detect a unicode string... JRA.
@@ -613,7 +613,7 @@ static int do_ntcreate_pipe_open(connection_struct *conn,
                               ((uint32)sizeof(fname)-1));
 
        get_filename(fname, inbuf, smb_buf(inbuf)-inbuf, 
-                  smb_buflen(inbuf),fname_len);
+                    smb_buflen(inbuf),fname_len);
        if ((ret = nt_open_pipe(fname, conn, inbuf, outbuf, &pnum)) != 0)
                return ret;
 
@@ -725,7 +725,7 @@ int reply_ntcreate_and_X(connection_struct *conn,
                    smb_buflen(inbuf),fname_len);
 
         if( strchr(fname, ':')) {
-          SSVAL(outbuf, smb_flg2, FLAGS2_32_BIT_ERROR_CODES);
+          SSVAL(outbuf, smb_flg2, SVAL(outbuf,smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
           END_PROFILE(SMBntcreateX);
           return(ERROR(0, NT_STATUS_OBJECT_PATH_NOT_FOUND));
         }
@@ -866,7 +866,8 @@ int reply_ntcreate_and_X(connection_struct *conn,
 
                                if (create_options & FILE_NON_DIRECTORY_FILE) {
                                        restore_case_semantics(file_attributes);
-                                       SSVAL(outbuf, smb_flg2, FLAGS2_32_BIT_ERROR_CODES);
+                                       SSVAL(outbuf, smb_flg2, 
+                                             SVAL(outbuf,smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
                                        END_PROFILE(SMBntcreateX);
                                        return(ERROR(0, NT_STATUS_FILE_IS_A_DIRECTORY));
                                }
@@ -1239,7 +1240,7 @@ static int call_nt_transact_create(connection_struct *conn,
                             total_parameter_count - 53 - fname_len, fname_len);
 
       if( strchr(fname, ':')) {
-          SSVAL(outbuf, smb_flg2, FLAGS2_32_BIT_ERROR_CODES);
+          SSVAL(outbuf, smb_flg2, SVAL(outbuf,smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
           return(ERROR(0, NT_STATUS_OBJECT_PATH_NOT_FOUND));
       }
 
@@ -1346,7 +1347,8 @@ static int call_nt_transact_create(connection_struct *conn,
 
                        if (create_options & FILE_NON_DIRECTORY_FILE) {
                                restore_case_semantics(file_attributes);
-                               SSVAL(outbuf, smb_flg2, FLAGS2_32_BIT_ERROR_CODES);
+                               SSVAL(outbuf, smb_flg2, 
+                                     SVAL(outbuf,smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
                                return(ERROR(0, NT_STATUS_FILE_IS_A_DIRECTORY));
                        }
        
@@ -1894,8 +1896,7 @@ due to being in oplock break state.\n" ));
   }
 
   if (Protocol >= PROTOCOL_NT1) {
-    uint16 flg2 = SVAL(outbuf,smb_flg2);
-    SSVAL(outbuf,smb_flg2,flg2 | 0x40); /* IS_LONG_NAME */
+    SSVAL(outbuf,smb_flg2,SVAL(outbuf,smb_flg2) | 0x40); /* IS_LONG_NAME */
   }
 
   /* Now we must call the relevant NT_TRANS function */
index a34555adc17b94212adb56ec4a310109de6a248b..dea7130cfedfcf05c761565dcbe38374fdae7dc8 100644 (file)
@@ -897,7 +897,8 @@ void construct_reply_common(char *inbuf,char *outbuf)
   CVAL(outbuf,smb_reh) = 0;
   SCVAL(outbuf,smb_flg, FLAG_REPLY | (CVAL(inbuf,smb_flg) & FLAG_CASELESS_PATHNAMES)); /* bit 7 set
                                  means a reply */
-  SSVAL(outbuf,smb_flg2,FLAGS2_LONG_PATH_COMPONENTS);
+  SSVAL(outbuf,smb_flg2,
+       (SVAL(inbuf,smb_flg2)&FLAGS2_UNICODE_STRINGS) | FLAGS2_LONG_PATH_COMPONENTS);
        /* say we support long filenames */
 
   SSVAL(outbuf,smb_err,SMB_SUCCESS);
@@ -1188,9 +1189,6 @@ void smbd_process(void)
        if ((InBuffer == NULL) || (OutBuffer == NULL)) 
                return;
 
-       InBuffer += SMB_ALIGNMENT;
-       OutBuffer += SMB_ALIGNMENT;
-
        max_recv = MIN(lp_maxxmit(),BUFFER_SIZE);
 
        /* re-initialise the timezone */
index 04e7b4c101d0246446ba07baae920860df04f99f..1240d16a986bc01bbcf92c6040e65797af8d07f3 100644 (file)
@@ -336,16 +336,21 @@ int reply_tcon_and_X(connection_struct *conn, char *inbuf,char *outbuf,int lengt
        }
 
        if (Protocol < PROTOCOL_NT1) {
-               set_message(outbuf,2,strlen(devicename)+1,True);
-               pstrcpy(smb_buf(outbuf),devicename);
+               set_message(outbuf,2,0,True);
+               p = smb_buf(outbuf);
+               p += srvstr_push(inbuf, outbuf, p, devicename, -1, 
+                                STR_CONVERT|STR_TERMINATE|STR_ASCII);
+               set_message_end(outbuf,p);
        } else {
                char *fsname = lp_fstype(SNUM(conn));
 
                set_message(outbuf,3,0,True);
 
                p = smb_buf(outbuf);
-               p += srvstr_push(inbuf, outbuf, p, devicename, -1, STR_CONVERT|STR_TERMINATE);
-               p += srvstr_push(inbuf, outbuf, p, fsname, -1, STR_CONVERT|STR_TERMINATE);
+               p += srvstr_push(inbuf, outbuf, p, devicename, -1, 
+                                STR_CONVERT|STR_TERMINATE|STR_ASCII);
+               p += srvstr_push(inbuf, outbuf, p, fsname, -1, 
+                                STR_CONVERT|STR_TERMINATE);
                
                set_message_end(outbuf,p);
                
@@ -444,50 +449,50 @@ static int session_trust_account(connection_struct *conn, char *inbuf, char *out
     sam_trust_acct = pdb_getsampwnam(user);
   } else {
     DEBUG(0,("session_trust_account: Trust account %s only supported with security = user\n", user));
-    SSVAL(outbuf, smb_flg2, FLAGS2_32_BIT_ERROR_CODES);
+    SSVAL(outbuf, smb_flg2, SVAL(outbuf, smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
     return(ERROR(0, NT_STATUS_LOGON_FAILURE));
   }
 
   if (sam_trust_acct == NULL) {
     /* lkclXXXX: workstation entry doesn't exist */
     DEBUG(0,("session_trust_account: Trust account %s user doesn't exist\n",user));
-    SSVAL(outbuf, smb_flg2, FLAGS2_32_BIT_ERROR_CODES);
+    SSVAL(outbuf, smb_flg2, SVAL(outbuf, smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
     return(ERROR(0, NT_STATUS_NO_SUCH_USER));
   } else {
     if ((smb_passlen != 24) || (smb_nt_passlen != 24)) {
       DEBUG(0,("session_trust_account: Trust account %s - password length wrong.\n", user));
-      SSVAL(outbuf, smb_flg2, FLAGS2_32_BIT_ERROR_CODES);
+      SSVAL(outbuf, smb_flg2, SVAL(outbuf, smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
       return(ERROR(0, NT_STATUS_LOGON_FAILURE));
     }
 
     if (!smb_password_ok(sam_trust_acct, NULL, (unsigned char *)smb_passwd, (unsigned char *)smb_nt_passwd)) {
       DEBUG(0,("session_trust_account: Trust Account %s - password failed\n", user));
-      SSVAL(outbuf, smb_flg2, FLAGS2_32_BIT_ERROR_CODES);
+      SSVAL(outbuf, smb_flg2, SVAL(outbuf, smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
       return(ERROR(0, NT_STATUS_LOGON_FAILURE));
     }
 
     acct_ctrl = pdb_get_acct_ctrl(sam_trust_acct);
     if (acct_ctrl & ACB_DOMTRUST) {
       DEBUG(0,("session_trust_account: Domain trust account %s denied by server\n",user));
-      SSVAL(outbuf, smb_flg2, FLAGS2_32_BIT_ERROR_CODES);
+      SSVAL(outbuf, smb_flg2, SVAL(outbuf, smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
       return(ERROR(0, NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT));
     }
 
     if (acct_ctrl & ACB_SVRTRUST) {
       DEBUG(0,("session_trust_account: Server trust account %s denied by server\n",user));
-      SSVAL(outbuf, smb_flg2, FLAGS2_32_BIT_ERROR_CODES);
+      SSVAL(outbuf, smb_flg2, SVAL(outbuf, smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
       return(ERROR(0, NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT));
     }
 
     if (acct_ctrl & ACB_WSTRUST) {
       DEBUG(4,("session_trust_account: Wksta trust account %s denied by server\n", user));
-      SSVAL(outbuf, smb_flg2, FLAGS2_32_BIT_ERROR_CODES);
+      SSVAL(outbuf, smb_flg2, SVAL(outbuf, smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
       return(ERROR(0, NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT));
     }
   }
 
   /* don't know what to do: indicate logon failure */
-  SSVAL(outbuf, smb_flg2, FLAGS2_32_BIT_ERROR_CODES);
+  SSVAL(outbuf, smb_flg2, SVAL(outbuf, smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
   return(ERROR(0, NT_STATUS_LOGON_FAILURE));
 }
 
@@ -670,7 +675,7 @@ static int bad_password_error(char *inbuf,char *outbuf)
 
   if(((ra_type == RA_WINNT) || (ra_type == RA_WIN2K)) &&
       (global_client_caps & (CAP_NT_SMBS | CAP_STATUS32 ))) {
-    SSVAL(outbuf,smb_flg2,FLAGS2_32_BIT_ERROR_CODES);
+    SSVAL(outbuf,smb_flg2,SVAL(outbuf, smb_flg2) | FLAGS2_32_BIT_ERROR_CODES);
     return(ERROR(0,NT_STATUS_LOGON_FAILURE));
   }
 
@@ -1203,11 +1208,7 @@ int reply_getatr(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
   SIVAL(outbuf,smb_vwv3,(uint32)size);
 
   if (Protocol >= PROTOCOL_NT1) {
-    char *p = strrchr(fname,'/');
-    uint16 flg2 = SVAL(outbuf,smb_flg2);
-    if (!p) p = fname;
-    if (!is_8_3(fname, True))
-      SSVAL(outbuf,smb_flg2,flg2 | 0x40); /* IS_LONG_NAME */
+         SSVAL(outbuf,smb_flg2,SVAL(outbuf, smb_flg2) | 0x40); /* IS_LONG_NAME */
   }
   
   DEBUG( 3, ( "getatr name=%s mode=%d size=%d\n", fname, mode, (uint32)size ) );
@@ -1480,8 +1481,7 @@ int reply_search(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
   SSVAL(smb_buf(outbuf),1,numentries*DIR_STRUCT_SIZE);
 
   if (Protocol >= PROTOCOL_NT1) {
-    uint16 flg2 = SVAL(outbuf,smb_flg2);
-    SSVAL(outbuf,smb_flg2,flg2 | 0x40); /* IS_LONG_NAME */
+    SSVAL(outbuf,smb_flg2,SVAL(outbuf, smb_flg2) | 0x40); /* IS_LONG_NAME */
   }
   
   outsize += DIR_STRUCT_SIZE*numentries;
index 6cc65d1b21be0fd082939e4029d43bbe28c905ab..76bb7fd4ccca3efed7395a7ea8ca212d2e81a788 100644 (file)
@@ -305,6 +305,7 @@ static BOOL exact_match(char *str,char *mask, BOOL case_sig)
   get a level dependent lanman2 dir entry.
 ****************************************************************************/
 static BOOL get_lanman2_dir_entry(connection_struct *conn,
+                                 void *inbuf, void *outbuf,
                                 char *path_mask,int dirtype,int info_level,
                                 int requires_resume_key,
                                 BOOL dont_descend,char **ppdata, 
@@ -318,7 +319,7 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
   pstring mask;
   pstring pathreal;
   pstring fname;
-  char *p, *pdata = *ppdata;
+  char *p, *q, *pdata = *ppdata;
   uint32 reskey=0;
   int prev_dirpos=0;
   int mode=0;
@@ -460,10 +461,12 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
       SIVAL(p,l1_cbFile,(uint32)size);
       SIVAL(p,l1_cbFileAlloc,SMB_ROUNDUP(size,1024));
       SSVAL(p,l1_attrFile,mode);
-      SCVAL(p,l1_cchName,strlen(fname));
-      pstrcpy(p + l1_achName, fname);
-      nameptr = p + l1_achName;
-      p += l1_achName + strlen(fname) + 1;
+      p += l1_achName;
+      nameptr = p;
+      len = srvstr_push(inbuf, outbuf, p, fname, -1, 
+                       STR_TERMINATE|STR_CONVERT);
+      SCVAL(p, -1, len);
+      p += len;
       break;
 
     case 2:
@@ -479,10 +482,12 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
       SIVAL(p,l2_cbFileAlloc,SMB_ROUNDUP(size,1024));
       SSVAL(p,l2_attrFile,mode);
       SIVAL(p,l2_cbList,0); /* No extended attributes */
-      SCVAL(p,l2_cchName,strlen(fname));
-      pstrcpy(p + l2_achName, fname);
-      nameptr = p + l2_achName;
-      p += l2_achName + strlen(fname) + 1;
+      p += l2_achName;
+      nameptr = p;
+      len = srvstr_push(inbuf, outbuf, p, fname, -1, 
+                       STR_TERMINATE|STR_CONVERT);
+      SCVAL(p, -1, len);
+      p += len;
       break;
 
     case 3:
@@ -494,10 +499,12 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
       SIVAL(p,20,SMB_ROUNDUP(size,1024));
       SSVAL(p,24,mode);
       SIVAL(p,26,4);
-      CVAL(p,30) = strlen(fname);
-      pstrcpy(p+31, fname);
-      nameptr = p+31;
-      p += 31 + strlen(fname) + 1;
+      p += 31;
+      nameptr = p;
+      len = srvstr_push(inbuf, outbuf, p, fname, -1, 
+                       STR_TERMINATE|STR_CONVERT);
+      SCVAL(p, -1, len);
+      p += len;
       break;
 
     case 4:
@@ -505,24 +512,26 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
         SIVAL(p,0,reskey);
         p += 4;
       }
-      SIVAL(p,0,33+strlen(fname)+1);
+      q = p;
       put_dos_date2(p,4,cdate);
       put_dos_date2(p,8,adate);
       put_dos_date2(p,12,mdate);
       SIVAL(p,16,(uint32)size);
       SIVAL(p,20,SMB_ROUNDUP(size,1024));
       SSVAL(p,24,mode);
-      CVAL(p,32) = strlen(fname);
-      pstrcpy(p + 33, fname);
-      nameptr = p+33;
-      p += 33 + strlen(fname) + 1;
+      p += 33;
+      nameptr = p;
+      len = srvstr_push(inbuf, outbuf, p, fname, -1, 
+                       STR_TERMINATE|STR_CONVERT);
+      SCVAL(p, -1, len);
+      p += len;
+      SIVAL(q,4,PTR_DIFF(p, q));
+
       break;
 
     case SMB_FIND_FILE_BOTH_DIRECTORY_INFO:
       was_8_3 = is_8_3(fname, True);
-      len = 94+strlen(fname);
-      len = (len + 3) & ~3;
-      SIVAL(p,0,len); p += 4;
+      p += 4;
       SIVAL(p,0,reskey); p += 4;
       put_long_date(p,cdate); p += 8;
       put_long_date(p,adate); p += 8;
@@ -532,28 +541,33 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
       SOFF_T(p,8,size);
       p += 16;
       SIVAL(p,0,nt_extmode); p += 4;
-      SIVAL(p,0,strlen(fname)); p += 4;
+      q = p; p += 4;
       SIVAL(p,0,0); p += 4;
       if (!was_8_3) {
-             fstrcpy(p+2,fname);
-             if(!name_map_mangle(p+2,True,True,SNUM(conn)))
-            (p+2)[12] = 0; 
-             strupper(p+2);
-             SSVAL(p, 0, strlen(p+2));
+             pstring mangled_name;
+             pstrcpy(mangled_name, fname);
+             name_map_mangle(mangled_name,True,True,SNUM(conn));
+             mangled_name[12] = 0;
+             len = srvstr_push(inbuf, outbuf, p+2, mangled_name, 24, 
+                               STR_CONVERT|STR_UPPER);
+             SSVAL(p, 0, len);
       } else {
              SSVAL(p,0,0);
              *(p+2) = 0;
       }
       p += 2 + 24;
-      /* nameptr = p;  */
-      pstrcpy(p,fname); p += strlen(p);
+      len = srvstr_push(inbuf, outbuf, p, fname, -1, 
+                       STR_TERMINATE|STR_CONVERT);
+      SIVAL(q,0,len);
+      p += len;
+      len = PTR_DIFF(p, pdata);
+      len = (len + 3) & ~3;
+      SIVAL(pdata,0,len);
       p = pdata + len;
       break;
 
     case SMB_FIND_FILE_DIRECTORY_INFO:
-      len = 64+strlen(fname);
-      len = (len + 3) & ~3;
-      SIVAL(p,0,len); p += 4;
+      p += 4;
       SIVAL(p,0,reskey); p += 4;
       put_long_date(p,cdate); p += 8;
       put_long_date(p,adate); p += 8;
@@ -563,16 +577,20 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
       SOFF_T(p,8,size);
       p += 16;
       SIVAL(p,0,nt_extmode); p += 4;
-      SIVAL(p,0,strlen(fname)); p += 4;
-      pstrcpy(p,fname);
+      p += 4;
+      len = srvstr_push(inbuf, outbuf, p, fname, -1, 
+                       STR_TERMINATE|STR_CONVERT);
+      SIVAL(p, -4, len);
+      p += len;
+      len = PTR_DIFF(p, pdata);
+      len = (len + 3) & ~3;
+      SIVAL(pdata,0,len);
       p = pdata + len;
       break;
       
       
     case SMB_FIND_FILE_FULL_DIRECTORY_INFO:
-      len = 68+strlen(fname);
-      len = (len + 3) & ~3;
-      SIVAL(p,0,len); p += 4;
+      p += 4;
       SIVAL(p,0,reskey); p += 4;
       put_long_date(p,cdate); p += 8;
       put_long_date(p,adate); p += 8;
@@ -582,19 +600,31 @@ static BOOL get_lanman2_dir_entry(connection_struct *conn,
       SOFF_T(p,8,size);
       p += 16;
       SIVAL(p,0,nt_extmode); p += 4;
-      SIVAL(p,0,strlen(fname)); p += 4;
+      p += 4;
       SIVAL(p,0,0); p += 4;
-      pstrcpy(p,fname);
+
+      len = srvstr_push(inbuf, outbuf, p, fname, -1, 
+                       STR_TERMINATE|STR_CONVERT);
+      SIVAL(p, -4, len);
+      p += len;
+
+      len = PTR_DIFF(p, pdata);
+      len = (len + 3) & ~3;
+      SIVAL(pdata,0,len);
       p = pdata + len;
       break;
 
     case SMB_FIND_FILE_NAMES_INFO:
-      len = 12+strlen(fname);
-      len = (len + 3) & ~3;
-      SIVAL(p,0,len); p += 4;
+      p += 4;
       SIVAL(p,0,reskey); p += 4;
-      SIVAL(p,0,strlen(fname)); p += 4;
-      pstrcpy(p,fname);
+      p += 4;
+      len = srvstr_push(inbuf, outbuf, p, fname, -1, 
+                       STR_TERMINATE|STR_CONVERT);
+      SIVAL(p, -4, len);
+      p += len;
+      len = PTR_DIFF(p, pdata);
+      len = (len + 3) & ~3;
+      SIVAL(pdata,0,len);
       p = pdata + len;
       break;
 
@@ -677,12 +707,14 @@ static int call_trans2findfirst(connection_struct *conn,
       return(ERROR(ERRDOS,ERRunknownlevel));
     }
 
-  pstrcpy(directory, params + 12); /* Complete directory path with 
-                                    wildcard mask appended */
+  srvstr_pull(inbuf, directory, params+12, sizeof(directory), -1, STR_TERMINATE);
 
-  RESOLVE_FINDFIRST_DFSPATH(directory, conn, inbuf, outbuf);
+  DEBUG(0,("path=%s params=%p inbuf=%p params[0]=%c params[1]=%d params[2]=%c params[3]=%d\n",
+          directory,
+          params, inbuf,
+          params[12], params[13], params[14], params[15]));
 
-  DEBUG(5,("path=%s\n",directory));
+  RESOLVE_FINDFIRST_DFSPATH(directory, conn, inbuf, outbuf);
 
   unix_convert(directory,conn,0,&bad_path,&sbuf);
   if(!check_name(directory,conn)) {
@@ -772,10 +804,12 @@ static int call_trans2findfirst(connection_struct *conn,
     }
     else
     {
-      finished = !get_lanman2_dir_entry(conn,mask,dirtype,info_level,
-                   requires_resume_key,dont_descend,
-                   &p,pdata,space_remaining, &out_of_space, &got_exact_match,
-                   &last_name_off);
+      finished = !get_lanman2_dir_entry(conn,
+                                       inbuf, outbuf,
+                                       mask,dirtype,info_level,
+                                       requires_resume_key,dont_descend,
+                                       &p,pdata,space_remaining, &out_of_space, &got_exact_match,
+                                       &last_name_off);
     }
 
     if (finished && out_of_space)
@@ -1046,10 +1080,12 @@ resume_key = %d resume name = %s continue=%d level = %d\n",
     }
     else
     {
-      finished = !get_lanman2_dir_entry(conn,mask,dirtype,info_level,
-                   requires_resume_key,dont_descend,
-                   &p,pdata,space_remaining, &out_of_space, &got_exact_match,
-                   &last_name_off);
+      finished = !get_lanman2_dir_entry(conn,
+                                       inbuf, outbuf,
+                                       mask,dirtype,info_level,
+                                       requires_resume_key,dont_descend,
+                                       &p,pdata,space_remaining, &out_of_space, &got_exact_match,
+                                       &last_name_off);
     }
 
     if (finished && out_of_space)
@@ -1208,7 +1244,7 @@ static int call_trans2qfsinfo(connection_struct *conn,
           vnamelen = dos_PutUniCode(pdata+18, vname, sizeof(pstring), False);
              data_len = 18 + vnamelen;
              SIVAL(pdata,12,vnamelen);
-                 SSVAL(outbuf,smb_flg2,SVAL(outbuf,smb_flg2)|FLAGS2_UNICODE_STRINGS);
+             SSVAL(outbuf,smb_flg2,SVAL(outbuf,smb_flg2)|FLAGS2_UNICODE_STRINGS);
       }
 
       DEBUG(5,("call_trans2qfsinfo : SMB_QUERY_FS_VOLUME_INFO namelen = %d, vol = %s\n", 
@@ -2391,8 +2427,7 @@ int reply_trans2(connection_struct *conn,
        }
        
        if (Protocol >= PROTOCOL_NT1) {
-               uint16 flg2 = SVAL(outbuf,smb_flg2);
-               SSVAL(outbuf,smb_flg2,flg2 | 0x40); /* IS_LONG_NAME */
+               SSVAL(outbuf,smb_flg2,SVAL(outbuf,smb_flg2) | 0x40); /* IS_LONG_NAME */
        }
 
        /* Now we must call the relevant TRANS2 function */