Using umask instead of explicit mode bits to create files/directories

Johannes Tyve Johannes.Tyve at sgu.se
Wed Nov 15 09:46:16 GMT 2000


At our site we use Samba 2.0.7 on Solaris 2.6. Solaris ACLs is used to
manage permissions on files and directories. 

After applying patch 106141 on our system the behavior of mkdir changed.
If a directory is created inside a direcory containing default-acl:s the
umask will not be applied. To get this behavior in samba we had to
modify two functions inside doscalls.c, dos_open() and dos_mkdir(). The
functions are modified to use umask insted of mode bits to create
files/directories.

I thought I should post my modifications back to the samba comunity to
hear your comments.

Functions inside lib/doscalls.c:
-------------------------------------------------------------------------------

/*******************************************************************
 Open() wrapper that calls dos_to_unix.
********************************************************************/

int dos_open(char *fname,int flags,mode_t mode)
{
  /* Modified 001113 by jste to use umask instead of requsted mode */
  int ret;
  mode_t fumask = 0777 - (mode & 0777);
  umask(fumask);
  mode = mode | 0777;
  /* End modification */

  ret = sys_open(dos_to_unix(fname,False),flags,mode);

  /* Restore umask */
  umask(0);

  return(ret);
}

/*******************************************************************
 Mkdir() that calls dos_to_unix.
 Cope with UNIXes that don't allow high order mode bits on mkdir.
 Patch from gcarter at lanier.com.
********************************************************************/

int dos_mkdir(char *dname,mode_t mode)
{
  int ret;

  /* Modified 001113 by jste to use umask instead of requsted mode */
  mode_t fumask = 0777 - (mode & 0777);
  umask(fumask);
  mode = mode | 0777;
  /* End modification */

  ret = mkdir(dos_to_unix(dname,False),mode);

  /* Restore umask */
  umask(0);

  return ret;
  /* We don't need this fix in solaris 2.6. Kind of strange to use
dos_chmod when the mkdir call returns success?!
  if(!ret) {
    return(dos_chmod(dname,mode));
  }
  else
  {
    return ret;
  }
  */
} 

-------------------------------------------------------------------------------
Regards Johannes Tyve




More information about the samba-technical mailing list