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

Michael Tokarev mjt at tls.msk.ru
Tue Aug 22 16:37:59 GMT 2000


Robert Dahlem wrote:
[]
> >
> >int dos_mkdir(char *dname,mode_t mode)
> >{
> >  int ret;
> >  ret = mkdir(dos_to_unix(dname,False),mode);
> >#ifdef HAVE_BROKEN_MKDIR
> >  if (!ret)
> >    ret=dos_chmod(dname,mode);
> >#endif
> >  return ret;
> >}
> >
> >where HAVE_BROKEN_MKDIR should be set by autoconf
> >_only_when_mkdir_is_broken_.  That's all.
> 
> I agree on the HAVE_BROKEN_MKDIR mimic but I do not agree on whats
> between #ifdef and #endif: In the case of mkdir() in a directory with
> SGID bit set the simple dos_chmod() would destroy SGID on the newly
> created directory (besides "inherit permissions = yes" beeing totally
> broken in this case). One have to take care not to reset any bits
> automagically set by the operating system.
> 
> A mix from both proposals could be:
> 
> int dos_mkdir(char *dname,mode_t mode)
> {
>   int ret;
>   SMB_STRUCT_STAT sbuf;
> 
>   ret=mkdir(dos_to_unix(dname,False),mode);
> #ifdef HAVE_BROKEN_MKDIR
>   if(!ret && !dos_stat(dname,&sbuf) && mode & ~sbuf.st_mode)
>     dos_chmod(dname,sbuf.st_mode | mode & ~sbuf.st_mode);
> #endif
>   return ret;
> }


Probably you are right.  Again, we don't know of that bad
system with broken mkdir (maybe you knows?) and how it is
broken, and what else features that system have (recall my
example with dos fs on linux where chmod will not succed).
Ok, in your case chmod return value is ignored.

And test for autoconf still missing.

BTW, this will be better written as (just polishing,
same logic):

int dos_mkdir(char *dname,mode_t mode)
{
  int ret = mkdir(dos_to_unix(dname,False),mode);
#ifdef HAVE_BROKEN_MKDIR
  SMB_STRUCT_STAT sbuf;
  if(!ret && !dos_stat(dname,&sbuf) && mode & ~sbuf.st_mode)
    dos_chmod(dname,sbuf.st_mode | mode & ~sbuf.st_mode);
#endif
  return ret;
}

(note that sbuf will be unused in your case if !HAVE_BROKEN_MKDIR).

Regards,
 Michael.




More information about the samba-technical mailing list