SMBC_rename_ctx() for an already existing target

Jeremy Allison jra at samba.org
Mon Jun 15 17:13:26 MDT 2015


On Mon, Jun 15, 2015 at 03:12:16AM -0600, Har Gagan Sahai wrote:
> 
> Hi Samba Team, 
> 
> 
> Looking for more information on the way SMBC_rename in libsmbclient library is handling the rename operation when the target location is already existing. 
> 
> 
> The SMBC_rename_ctx() tries for the rename and then it checks for the errno value. If the value of errno is EEXIST then it deletes file on its own and re-try the rename operation.  This is the code snippet from the SMBC_rename_ctx() where this decision is taken place : 
> 
> 
>      if (!NT_STATUS_IS_OK(cli_rename(targetcli1, targetpath1, targetpath2))) { 
>                 int eno = SMBC_errno(ocontext, targetcli1); 
> 
> 
>                 if (eno != EEXIST || 
>                     !NT_STATUS_IS_OK(cli_unlink(targetcli1, targetpath2, FILE_ATTRIBUTE_SYSTEM | FILE_ATTRIBUTE_HIDDEN)) || 
>                     !NT_STATUS_IS_OK(cli_rename(targetcli1, targetpath1, targetpath2))) { 
> 
> 
>                         errno = eno; 
>                         TALLOC_FREE(frame); 
>                         return -1; 
> 
> 
>                 } 
>         } 
> 
> 
> Looking for some explanation on this approach of deleting the file in the call, rather than giving control to the user to decide whether it wants to delete the target, skip this as no-op etc ? Doesn't it sound like a bug ? 

Yes, this call needs fixing. There was some code created
to do this (adding an 'overwrite' flag) that became stalled
on an issue talking to downlevel servers. I still have this
fix somewhere I can finish up (given a bug report :-).


More information about the samba-technical mailing list