make sure we don't walk past the end of the current SMB buffer when
[sfrench/samba-autobuild/.git] / source3 / smbd / reply.c
index 4dcb674ff1247894b41cd3adfa9cde383ab73991..0ccdf7c241b6caad9fae8f70d27b38f6011d4abf 100644 (file)
@@ -163,10 +163,10 @@ int reply_tcon(connection_struct *conn,
        *service = *password = *dev = 0;
 
        p = smb_buf(inbuf)+1;
-       p += srvstr_pull(inbuf, service, p, sizeof(service), -1, STR_TERMINATE) + 1;
-       pwlen = srvstr_pull(inbuf, password, p, sizeof(password), -1, STR_TERMINATE) + 1;
+       p += srvstr_pull_buf(inbuf, service, p, sizeof(service), STR_TERMINATE) + 1;
+       pwlen = srvstr_pull_buf(inbuf, password, p, sizeof(password), STR_TERMINATE) + 1;
        p += pwlen;
-       p += srvstr_pull(inbuf, dev, p, sizeof(dev), -1, STR_TERMINATE) + 1;
+       p += srvstr_pull_buf(inbuf, dev, p, sizeof(dev), STR_TERMINATE) + 1;
 
        p = strrchr_m(service,'\\');
        if (p) {
@@ -233,7 +233,7 @@ int reply_tcon_and_X(connection_struct *conn, char *inbuf,char *outbuf,int lengt
        }
 
        p = smb_buf(inbuf) + passlen;
-       p += srvstr_pull(inbuf, path, p, sizeof(path), -1, STR_TERMINATE);
+       p += srvstr_pull_buf(inbuf, path, p, sizeof(path), STR_TERMINATE);
 
        /*
         * the service name can be either: \\server\share
@@ -285,7 +285,8 @@ int reply_tcon_and_X(connection_struct *conn, char *inbuf,char *outbuf,int lengt
                
                /* what does setting this bit do? It is set by NT4 and
                   may affect the ability to autorun mounted cdroms */
-               SSVAL(outbuf, smb_vwv2, SMB_SUPPORT_SEARCH_BITS); 
+               SSVAL(outbuf, smb_vwv2, SMB_SUPPORT_SEARCH_BITS|
+                               (lp_csc_policy(SNUM(conn)) << 2));
                
                init_dfsroot(conn, inbuf, outbuf);
        }
@@ -376,7 +377,7 @@ int reply_chkpth(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
   SMB_STRUCT_STAT sbuf;
   START_PROFILE(SMBchkpth);
 
-  srvstr_pull(inbuf, name, smb_buf(inbuf) + 1, sizeof(name), -1, STR_TERMINATE);
+  srvstr_pull_buf(inbuf, name, smb_buf(inbuf) + 1, sizeof(name), STR_TERMINATE);
 
   RESOLVE_DFSPATH(name, conn, inbuf, outbuf);
 
@@ -428,7 +429,7 @@ int reply_getatr(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
   START_PROFILE(SMBgetatr);
 
   p = smb_buf(inbuf) + 1;
-  p += srvstr_pull(inbuf, fname, p, sizeof(fname), -1, STR_TERMINATE);
+  p += srvstr_pull_buf(inbuf, fname, p, sizeof(fname), STR_TERMINATE);
 
   RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
   
@@ -463,12 +464,7 @@ int reply_getatr(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
   
   if (!ok)
   {
-    if((errno == ENOENT) && bad_path)
-    {
-      unix_ERR_class = ERRDOS;
-      unix_ERR_code = ERRbadpath;
-    }
-
+    set_bad_path_error(errno, bad_path);
     END_PROFILE(SMBgetatr);
     return(UNIXERROR(ERRDOS,ERRbadfile));
   }
@@ -509,7 +505,7 @@ int reply_setatr(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
   START_PROFILE(SMBsetatr);
 
   p = smb_buf(inbuf) + 1;
-  p += srvstr_pull(inbuf, fname, p, sizeof(fname), -1, STR_TERMINATE);
+  p += srvstr_pull_buf(inbuf, fname, p, sizeof(fname), STR_TERMINATE);
   unix_convert(fname,conn,0,&bad_path,&sbuf);
 
   mode = SVAL(inbuf,smb_vwv0);
@@ -527,12 +523,7 @@ int reply_setatr(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
   
   if (!ok)
   {
-    if((errno == ENOENT) && bad_path)
-    {
-      unix_ERR_class = ERRDOS;
-      unix_ERR_code = ERRbadpath;
-    }
-
+    set_bad_path_error(errno, bad_path);
     END_PROFILE(SMBsetatr);
     return(UNIXERROR(ERRDOS,ERRnoaccess));
   }
@@ -551,23 +542,46 @@ int reply_setatr(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
 ****************************************************************************/
 int reply_dskattr(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize)
 {
-  int outsize = 0;
-  SMB_BIG_UINT dfree,dsize,bsize;
-  START_PROFILE(SMBdskattr);
-  
-  conn->vfs_ops.disk_free(conn,".",True,&bsize,&dfree,&dsize);
-  
-  outsize = set_message(outbuf,5,0,True);
+       int outsize = 0;
+       SMB_BIG_UINT dfree,dsize,bsize;
+       START_PROFILE(SMBdskattr);
+
+       conn->vfs_ops.disk_free(conn,".",True,&bsize,&dfree,&dsize);
   
-  SSVAL(outbuf,smb_vwv0,dsize);
-  SSVAL(outbuf,smb_vwv1,bsize/512);
-  SSVAL(outbuf,smb_vwv2,512);
-  SSVAL(outbuf,smb_vwv3,dfree);
+       outsize = set_message(outbuf,5,0,True);
+       
+       if (Protocol <= PROTOCOL_LANMAN2) {
+               double total_space, free_space;
+               /* we need to scale this to a number that DOS6 can handle. We
+                  use floating point so we can handle large drives on systems
+                  that don't have 64 bit integers 
 
-  DEBUG(3,("dskattr dfree=%d\n", (unsigned int)dfree));
+                  we end up displaying a maximum of 2G to DOS systems
+               */
+               total_space = dsize * (double)bsize;
+               free_space = dfree * (double)bsize;
 
-  END_PROFILE(SMBdskattr);
-  return(outsize);
+               dsize = (total_space+63*512) / (64*512);
+               dfree = (free_space+63*512) / (64*512);
+               
+               if (dsize > 0xFFFF) dsize = 0xFFFF;
+               if (dfree > 0xFFFF) dfree = 0xFFFF;
+
+               SSVAL(outbuf,smb_vwv0,dsize);
+               SSVAL(outbuf,smb_vwv1,64); /* this must be 64 for dos systems */
+               SSVAL(outbuf,smb_vwv2,512); /* and this must be 512 */
+               SSVAL(outbuf,smb_vwv3,dfree);
+       } else {
+               SSVAL(outbuf,smb_vwv0,dsize);
+               SSVAL(outbuf,smb_vwv1,bsize/512);
+               SSVAL(outbuf,smb_vwv2,512);
+               SSVAL(outbuf,smb_vwv3,dfree);
+       }
+
+       DEBUG(3,("dskattr dfree=%d\n", (unsigned int)dfree));
+
+       END_PROFILE(SMBdskattr);
+       return(outsize);
 }
 
 
@@ -611,7 +625,7 @@ int reply_search(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
   maxentries = SVAL(inbuf,smb_vwv0); 
   dirtype = SVAL(inbuf,smb_vwv1);
   p = smb_buf(inbuf) + 1;
-  p += srvstr_pull(inbuf, path, p, sizeof(path), -1, STR_TERMINATE);
+  p += srvstr_pull_buf(inbuf, path, p, sizeof(path), STR_TERMINATE);
   p++;
   status_len = SVAL(p, 0);
   p += 2;
@@ -678,12 +692,8 @@ int reply_search(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
       {
         if(dptr_num == -2)
         {
-          if((errno == ENOENT) && bad_path)
-          {
-            unix_ERR_class = ERRDOS;
-            unix_ERR_code = ERRbadpath;
-          }
-                END_PROFILE(SMBsearch);
+          set_bad_path_error(errno, bad_path);
+          END_PROFILE(SMBsearch);
           return (UNIXERROR(ERRDOS,ERRnofids));
         }
                END_PROFILE(SMBsearch);
@@ -796,7 +806,7 @@ int reply_fclose(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
 
   outsize = set_message(outbuf,1,0,True);
   p = smb_buf(inbuf) + 1;
-  p += srvstr_pull(inbuf, path, p, sizeof(path), -1, STR_TERMINATE);
+  p += srvstr_pull_buf(inbuf, path, p, sizeof(path), STR_TERMINATE);
   p++;
   status_len = SVAL(p,0);
   p += 2;
@@ -844,7 +854,7 @@ int reply_open(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
  
   share_mode = SVAL(inbuf,smb_vwv0);
 
-  srvstr_pull(inbuf, fname, smb_buf(inbuf)+1, sizeof(fname), -1, STR_TERMINATE);
+  srvstr_pull_buf(inbuf, fname, smb_buf(inbuf)+1, sizeof(fname), STR_TERMINATE);
 
   RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
 
@@ -857,11 +867,7 @@ int reply_open(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
 
   if (!fsp)
   {
-    if((errno == ENOENT) && bad_path)
-    {
-      unix_ERR_class = ERRDOS;
-      unix_ERR_code = ERRbadpath;
-    }
+    set_bad_path_error(errno, bad_path);
     END_PROFILE(SMBopen);
     return(UNIXERROR(ERRDOS,ERRnoaccess));
   }
@@ -938,7 +944,7 @@ int reply_open_and_X(connection_struct *conn, char *inbuf,char *outbuf,int lengt
   }
 
   /* XXXX we need to handle passed times, sattr and flags */
-  srvstr_pull(inbuf, fname, smb_buf(inbuf), sizeof(fname), -1, STR_TERMINATE);
+  srvstr_pull_buf(inbuf, fname, smb_buf(inbuf), sizeof(fname), STR_TERMINATE);
 
   RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
 
@@ -951,11 +957,7 @@ int reply_open_and_X(connection_struct *conn, char *inbuf,char *outbuf,int lengt
       
   if (!fsp)
   {
-    if((errno == ENOENT) && bad_path)
-    {
-      unix_ERR_class = ERRDOS;
-      unix_ERR_code = ERRbadpath;
-    }
+    set_bad_path_error(errno, bad_path);
     END_PROFILE(SMBopenX);
     return(UNIXERROR(ERRDOS,ERRnoaccess));
   }
@@ -1061,7 +1063,7 @@ int reply_mknew(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
   com = SVAL(inbuf,smb_com);
 
   createmode = SVAL(inbuf,smb_vwv0);
-  srvstr_pull(inbuf, fname, smb_buf(inbuf) + 1, sizeof(fname), -1, STR_TERMINATE);
+  srvstr_pull_buf(inbuf, fname, smb_buf(inbuf) + 1, sizeof(fname), STR_TERMINATE);
 
   RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
 
@@ -1090,11 +1092,7 @@ int reply_mknew(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
   
   if (!fsp)
   {
-    if((errno == ENOENT) && bad_path) 
-    {
-      unix_ERR_class = ERRDOS;
-      unix_ERR_code = ERRbadpath;
-    }
+    set_bad_path_error(errno, bad_path);
     END_PROFILE(SMBcreate);
     return(UNIXERROR(ERRDOS,ERRnoaccess));
   }
@@ -1137,7 +1135,7 @@ int reply_ctemp(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
   START_PROFILE(SMBctemp);
 
   createmode = SVAL(inbuf,smb_vwv0);
-  srvstr_pull(inbuf, fname, smb_buf(inbuf)+1, sizeof(fname), -1, STR_TERMINATE);
+  srvstr_pull_buf(inbuf, fname, smb_buf(inbuf)+1, sizeof(fname), STR_TERMINATE);
   pstrcat(fname,"\\TMXXXXXX");
 
   RESOLVE_DFSPATH(fname, conn, inbuf, outbuf);
@@ -1164,11 +1162,8 @@ int reply_ctemp(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
   /* close fd from smb_mkstemp() */
   close(tmpfd);
 
-       if (!fsp) {
-               if((errno == ENOENT) && bad_path) {
-      unix_ERR_class = ERRDOS;
-      unix_ERR_code = ERRbadpath;
-    }
+  if (!fsp) {
+    set_bad_path_error(errno, bad_path);
     END_PROFILE(SMBctemp);
     return(UNIXERROR(ERRDOS,ERRnoaccess));
   }
@@ -1206,6 +1201,41 @@ int reply_ctemp(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
   return(outsize);
 }
 
+/*******************************************************************
+ Check if a user is allowed to rename a file.
+********************************************************************/
+
+static NTSTATUS can_rename(char *fname,connection_struct *conn, SMB_STRUCT_STAT *pst)
+{
+       int smb_action;
+       int access_mode;
+       files_struct *fsp;
+
+       if (!CAN_WRITE(conn))
+               return NT_STATUS_MEDIA_WRITE_PROTECTED;
+       
+       if (S_ISDIR(pst->st_mode))
+               return NT_STATUS_OK;
+
+       /* We need a better way to return NT status codes from open... */
+       unix_ERR_class = 0;
+       unix_ERR_code = 0;
+
+       fsp = open_file_shared1(conn, fname, pst, DELETE_ACCESS, SET_DENY_MODE(DENY_ALL),
+               (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN), 0, 0, &access_mode, &smb_action);
+
+       if (!fsp) {
+               NTSTATUS ret = NT_STATUS_ACCESS_DENIED;
+               if (unix_ERR_class == ERRDOS && unix_ERR_code == ERRbadshare)
+                       ret = NT_STATUS_SHARING_VIOLATION;
+               unix_ERR_class = 0;
+               unix_ERR_code = 0;
+               return ret;
+       }
+       close_file(fsp,False);
+       return NT_STATUS_OK;
+}
+
 /*******************************************************************
  Check if a user is allowed to delete a file.
 ********************************************************************/
@@ -1214,6 +1244,9 @@ static NTSTATUS can_delete(char *fname,connection_struct *conn, int dirtype)
 {
        SMB_STRUCT_STAT sbuf;
        int fmode;
+       int smb_action;
+       int access_mode;
+       files_struct *fsp;
 
        if (!CAN_WRITE(conn))
                return NT_STATUS_MEDIA_WRITE_PROTECTED;
@@ -1231,9 +1264,22 @@ static NTSTATUS can_delete(char *fname,connection_struct *conn, int dirtype)
        if ((fmode & ~dirtype) & (aHIDDEN | aSYSTEM))
                return NT_STATUS_CANNOT_DELETE;
 
-       if (!check_file_sharing(conn,fname,False))
-               return NT_STATUS_SHARING_VIOLATION;
+       /* We need a better way to return NT status codes from open... */
+       unix_ERR_class = 0;
+       unix_ERR_code = 0;
+
+       fsp = open_file_shared1(conn, fname, &sbuf, DELETE_ACCESS, SET_DENY_MODE(DENY_ALL),
+               (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN), 0, 0, &access_mode, &smb_action);
 
+       if (!fsp) {
+               NTSTATUS ret = NT_STATUS_ACCESS_DENIED;
+               if (unix_ERR_class == ERRDOS && unix_ERR_code == ERRbadshare)
+                       ret = NT_STATUS_SHARING_VIOLATION;
+               unix_ERR_class = 0;
+               unix_ERR_code = 0;
+               return ret;
+       }
+       close_file(fsp,False);
        return NT_STATUS_OK;
 }
 
@@ -1250,7 +1296,6 @@ NTSTATUS unlink_internals(connection_struct *conn, int dirtype, char *name)
        int count=0;
        NTSTATUS error = NT_STATUS_OK;
        BOOL has_wild;
-       BOOL exists=False;
        BOOL bad_path = False;
        BOOL rc = True;
        SMB_STRUCT_STAT sbuf;
@@ -1278,8 +1323,8 @@ NTSTATUS unlink_internals(connection_struct *conn, int dirtype, char *name)
         * Tine Smukavec <valentin.smukavec@hermes.si>.
         */
        
-       if (!rc && is_mangled(mask))
-               check_mangled_cache( mask );
+       if (!rc && mangle_is_mangled(mask))
+               mangle_check_cache( mask );
        
        has_wild = ms_has_wild(mask);
        
@@ -1292,8 +1337,6 @@ NTSTATUS unlink_internals(connection_struct *conn, int dirtype, char *name)
                if (vfs_unlink(conn,directory) == 0) {
                        count++;
                }
-               if (!count)
-                       exists = vfs_file_exist(conn,directory,&sbuf);    
        } else {
                void *dirptr = NULL;
                char *dname;
@@ -1350,7 +1393,7 @@ int reply_unlink(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
        
        dirtype = SVAL(inbuf,smb_vwv0);
        
-       srvstr_pull(inbuf, name, smb_buf(inbuf) + 1, sizeof(name), -1, STR_TERMINATE);
+       srvstr_pull_buf(inbuf, name, smb_buf(inbuf) + 1, sizeof(name), STR_TERMINATE);
        
        RESOLVE_DFSPATH(name, conn, inbuf, outbuf);
        
@@ -1822,12 +1865,15 @@ int reply_writebraw(connection_struct *conn, char *inbuf,char *outbuf, int size,
        /* we won't return a status if write through is not selected - this follows what WfWg does */
        END_PROFILE(SMBwritebraw);
        if (!write_through && total_written==tcount) {
+
+#if RABBIT_PELLET_FIX
                /*
                 * Fix for "rabbit pellet" mode, trigger an early TCP ack by
                 * sending a SMBkeepalive. Thanks to DaveCB at Sun for this. JRA.
                 */
                if (!send_keepalive(smbd_server_fd()))
                        exit_server("reply_writebraw: send of keepalive failed");
+#endif
                return(-1);
        }
 
@@ -2676,6 +2722,9 @@ NTSTATUS mkdir_internal(connection_struct *conn, pstring directory)
                ret = vfs_mkdir(conn,directory,unix_mode(conn,aDIR,directory));
        
        if (ret == -1) {
+               NTSTATUS nterr = set_bad_path_error(errno, bad_path);
+               if (!NT_STATUS_IS_OK(nterr))
+                       return nterr;
                return map_nt_error_from_unix(errno);
        }
        
@@ -2693,7 +2742,7 @@ int reply_mkdir(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
        NTSTATUS status;
        START_PROFILE(SMBmkdir);
  
-       srvstr_pull(inbuf, directory, smb_buf(inbuf) + 1, sizeof(directory), -1, STR_TERMINATE);
+       srvstr_pull_buf(inbuf, directory, smb_buf(inbuf) + 1, sizeof(directory), STR_TERMINATE);
 
        status = mkdir_internal(conn, directory);
        if (!NT_STATUS_IS_OK(status))
@@ -2854,7 +2903,7 @@ int reply_rmdir(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
   SMB_STRUCT_STAT sbuf;
   START_PROFILE(SMBrmdir);
 
-  srvstr_pull(inbuf, directory, smb_buf(inbuf) + 1, sizeof(directory), -1, STR_TERMINATE);
+  srvstr_pull_buf(inbuf, directory, smb_buf(inbuf) + 1, sizeof(directory), STR_TERMINATE);
 
   RESOLVE_DFSPATH(directory, conn, inbuf, outbuf)
 
@@ -2868,11 +2917,7 @@ int reply_rmdir(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
   
   if (!ok)
   {
-    if((errno == ENOENT) && bad_path)
-    {
-      unix_ERR_class = ERRDOS;
-      unix_ERR_code = ERRbadpath;
-    }
+    set_bad_path_error(errno, bad_path);
     END_PROFILE(SMBrmdir);
     return(UNIXERROR(ERRDOS,ERRbadpath));
   }
@@ -2950,21 +2995,6 @@ static BOOL resolve_wildcards(char *name1,char *name2)
   return(True);
 }
 
-/*******************************************************************
- Check if a user is allowed to rename a file.
-********************************************************************/
-
-static NTSTATUS can_rename(char *fname,connection_struct *conn)
-{
-       if (!CAN_WRITE(conn))
-               return NT_STATUS_ACCESS_DENIED;
-
-       if (!check_file_sharing(conn,fname,True))
-               return NT_STATUS_SHARING_VIOLATION;
-
-       return NT_STATUS_OK;
-}
-
 /****************************************************************************
  The guts of the rename command, split out so it may be called by the NT SMB
  code. 
@@ -3018,20 +3048,8 @@ NTSTATUS rename_internals(connection_struct *conn, char *name, char *newname, BO
         * Tine Smukavec <valentin.smukavec@hermes.si>.
         */
 
-#if 0
-       if (!rc && is_mangled(mask))
-               check_mangled_cache( mask );
-#endif
-       if (!rc)
-       {
-               char *unmangled;
-               
-               unmangled = dos_unmangle(mask);
-               if (unmangled)
-                       strncpy(mask, unmangled, strlen(unmangled) + 1);
-                       
-               SAFE_FREE(unmangled);
-       }
+       if (!rc && mangle_is_mangled(mask))
+               mangle_check_cache( mask );
 
        has_wild = ms_has_wild(mask);
 
@@ -3039,7 +3057,7 @@ NTSTATUS rename_internals(connection_struct *conn, char *name, char *newname, BO
                /*
                 * No wildcards - just process the one file.
                 */
-               BOOL is_short_name = is_8_3(name, True);
+               BOOL is_short_name = mangle_is_8_3(name, True);
 
                /* Add a terminating '/' to the directory name. */
                pstrcat(directory,"/");
@@ -3099,7 +3117,7 @@ directory = %s, newname = %s, newname_last_component = %s, is_8_3 = %d\n",
                 * The source object must exist.
                 */
 
-               if (!vfs_object_exist(conn, directory, NULL)) {
+               if (!vfs_object_exist(conn, directory, &sbuf1)) {
                        DEBUG(3,("rename_internals: source doesn't exist doing rename %s -> %s\n",
                                directory,newname));
 
@@ -3124,7 +3142,7 @@ directory = %s, newname = %s, newname_last_component = %s, is_8_3 = %d\n",
                        return error;
                }
 
-               error = can_rename(directory,conn);
+               error = can_rename(directory,conn,&sbuf1);
 
                if (!NT_STATUS_IS_OK(error)) {
                        DEBUG(3,("rename_internals: Error %s rename %s -> %s\n",
@@ -3190,7 +3208,12 @@ directory = %s, newname = %s, newname_last_component = %s, is_8_3 = %d\n",
                                
                                error = NT_STATUS_ACCESS_DENIED;
                                slprintf(fname,sizeof(fname)-1,"%s/%s",directory,dname);
-                               error = can_rename(fname,conn);
+                               if (!vfs_object_exist(conn, fname, &sbuf1)) {
+                                       error = NT_STATUS_OBJECT_NAME_NOT_FOUND;
+                                       DEBUG(6,("rename %s failed. Error %s\n", fname, nt_errstr(error)));
+                                       continue;
+                               }
+                               error = can_rename(fname,conn,&sbuf1);
                                if (!NT_STATUS_IS_OK(error)) {
                                        DEBUG(6,("rename %s refused\n", fname));
                                        continue;
@@ -3241,9 +3264,9 @@ int reply_mv(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
        START_PROFILE(SMBmv);
 
        p = smb_buf(inbuf) + 1;
-       p += srvstr_pull(inbuf, name, p, sizeof(name), -1, STR_TERMINATE);
+       p += srvstr_pull_buf(inbuf, name, p, sizeof(name), STR_TERMINATE);
        p++;
-       p += srvstr_pull(inbuf, newname, p, sizeof(newname), -1, STR_TERMINATE);
+       p += srvstr_pull_buf(inbuf, newname, p, sizeof(newname), STR_TERMINATE);
        
        RESOLVE_DFSPATH(name, conn, inbuf, outbuf);
        RESOLVE_DFSPATH(newname, conn, inbuf, outbuf);
@@ -3373,8 +3396,8 @@ int reply_copy(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
   *directory = *mask = 0;
 
   p = smb_buf(inbuf);
-  p += srvstr_pull(inbuf, name, p, sizeof(name), -1, STR_TERMINATE);
-  p += srvstr_pull(inbuf, newname, p, sizeof(newname), -1, STR_TERMINATE);
+  p += srvstr_pull_buf(inbuf, name, p, sizeof(name), STR_TERMINATE);
+  p += srvstr_pull_buf(inbuf, newname, p, sizeof(newname), STR_TERMINATE);
    
   DEBUG(3,("reply_copy : %s -> %s\n",name,newname));
    
@@ -3429,21 +3452,8 @@ int reply_copy(connection_struct *conn, char *inbuf,char *outbuf, int dum_size,
    * Tine Smukavec <valentin.smukavec@hermes.si>.
    */
 
-#if 0
-       if (!rc && is_mangled(mask))
-               check_mangled_cache( mask );
-#endif
-       if (!rc)
-       {
-               char *unmangled;
-               
-               unmangled = dos_unmangle(mask);
-               if (unmangled)
-                       strncpy(mask, unmangled, strlen(unmangled) + 1);
-                       
-               SAFE_FREE(unmangled);
-       }
-
+  if (!rc && mangle_is_mangled(mask))
+         mangle_check_cache( mask );
 
   has_wild = ms_has_wild(mask);
 
@@ -3539,7 +3549,7 @@ int reply_setdir(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
     return ERROR_DOS(ERRDOS,ERRnoaccess);
   }
 
-  srvstr_pull(inbuf, newdir, smb_buf(inbuf) + 1, sizeof(newdir), -1, STR_TERMINATE);
+  srvstr_pull_buf(inbuf, newdir, smb_buf(inbuf) + 1, sizeof(newdir), STR_TERMINATE);
   
   if (strlen(newdir) == 0) {
          ok = True;