2.0.7: inherit permissions = yes breaks setting read-only on files

Robert Dahlem Robert.Dahlem at gmx.net
Tue Aug 22 14:26:08 GMT 2000


Michael,

On Tue, 22 Aug 2000 15:45:08 +0400, Michael Tokarev wrote:

>> While testing the upgrade from 2.0.6 to 2.0.7 I found some kind of
>> misbehaviour of inherit permissions.
>> 
>[]
>> And really: the patch from 2.0.6 to 2.0.7 is:
>> 
>>  int dos_mkdir(char *dname,mode_t mode)
>>  {
>> -  return(mkdir(dos_to_unix(dname,False),mode));
>> +  int ret = mkdir(dos_to_unix(dname,False),mode);
>> +  if(!ret)
>> +    return(dos_chmod(dname,mode));
>> +  else
>> +    return ret;
>>  }
>
>[]
>
>This is a known bug that of Samba Team still can't decide if it is a 
>bug or not.  

They seem to be pretty busy with the ongoing quarrels. :-)

>> I'm quite sure this does not do what was intended: the part behind
>> 
>>         if(!ret)
>> 
>> gets called when mkdir() does NOT fail, but it should be called 
>> when mkdir() DOES fail.
>
>Nope, by that bad design chmod should be called only if mkdir succed,
>or chmod will fail also.

Oops. I thougt that the original patch tried to handle the situation
with some (broken?) UNIXes where mkdir() in fact creates the directory,
fails to set all the wanted bits and reports the later fact with a
return code != 0

How about handling that situation with something like the following? It
leaves the return code from mkdir() intact for every but that special
case (dir created but bits missing AND cannot be set afterwards).

int dos_mkdir(char *dname,mode_t mode)                                 
        
{                                                                      
        
  int ret;                                                             
        
  SMB_STRUCT_STAT sbuf;                                                
        
                                                                       
        
  ret=mkdir(dos_to_unix(dname,False),mode);                            
        
  /* Check if bits are missing, add them if true.                      
        
     Consider bits automagically set by UNIX,                          
        
     i.e. SGID bit from parent dir                                     
        
  */                                                                   
        
  if(!dos_stat(dname,&sbuf) && mode & ~sbuf.st_mode)                   
        
    ret=dos_chmod(dname,sbuf.st_mode | mode & ~sbuf.st_mode);          
        
  return ret;                                                          
        
}

This works on my systems but naturally never comes to dos_chmod() due
to my Unixes not beeing broken (in this point :-).

One could probably avoid two (implicit) out of three calls to
dos_to_unix() while optimizing this code ...

Regards,
        Robert

---------------------------------------------------------------
Robert.Dahlem at gmx.net           Fax +49-69-432647
---------------------------------------------------------------




More information about the samba mailing list