Index: smbd/open.c =================================================================== --- smbd/open.c (revision 4002) +++ smbd/open.c (working copy) @@ -979,7 +979,7 @@ struct pending_message_list *pml = NULL; uint16 mid = get_current_mid(); /* We add aARCH to this as this mode is only used if the file is created new. */ - mode_t mode = unix_mode(conn,new_dos_mode | aARCH,fname); + mode_t mode = unix_mode(conn,new_dos_mode | aARCH,fname, True); if (oplock_request == INTERNAL_OPEN_ONLY) { internal_only_open = True; @@ -1440,7 +1440,7 @@ if (action == FILE_WAS_OVERWRITTEN || action == FILE_WAS_CREATED) { /* Files should be initially set as archive */ if (lp_map_archive(SNUM(conn)) || lp_store_dos_attributes(SNUM(conn))) { - file_set_dosmode(conn, fname, new_dos_mode | aARCH, NULL); + file_set_dosmode(conn, fname, new_dos_mode | aARCH, NULL, True); } } @@ -1601,7 +1601,7 @@ return NULL; } - if(vfs_MkDir(conn,fname, unix_mode(conn,aDIR, fname)) < 0) { + if(vfs_MkDir(conn,fname, unix_mode(conn,aDIR, fname, True)) < 0) { DEBUG(2,("open_directory: unable to create %s. Error was %s\n", fname, strerror(errno) )); file_free(fsp); Index: smbd/posix_acls.c =================================================================== --- smbd/posix_acls.c (revision 4002) +++ smbd/posix_acls.c (working copy) @@ -1864,7 +1864,7 @@ int snum = SNUM(fsp->conn); mode_t and_bits = (mode_t)0; mode_t or_bits = (mode_t)0; - mode_t mode = interitable_mode ? unix_mode( fsp->conn, FILE_ATTRIBUTE_ARCHIVE, fsp->fsp_name) : S_IRUSR; + mode_t mode = interitable_mode ? unix_mode( fsp->conn, FILE_ATTRIBUTE_ARCHIVE, fsp->fsp_name, False) : S_IRUSR; if (fsp->is_directory) mode |= (S_IWUSR|S_IXUSR); Index: smbd/nttrans.c =================================================================== --- smbd/nttrans.c (revision 4002) +++ smbd/nttrans.c (working copy) @@ -1661,7 +1661,7 @@ /* Grrr. We have to do this as open_file_shared1 adds aARCH when it creates the file. This isn't the correct thing to do in the copy case. JRA */ - file_set_dosmode(conn, newname, fmode, &sbuf2); + file_set_dosmode(conn, newname, fmode, &sbuf2, True); if (ret < (SMB_OFF_T)sbuf1.st_size) { return NT_STATUS_DISK_FULL; Index: smbd/reply.c =================================================================== --- smbd/reply.c (revision 4002) +++ smbd/reply.c (working copy) @@ -719,7 +719,7 @@ mode &= ~aDIR; if (check_name(fname,conn)) { - ok = (file_set_dosmode(conn,fname,mode,NULL) == 0); + ok = (file_set_dosmode(conn,fname,mode,&sbuf,False) == 0); } } else { ok = True; @@ -3286,7 +3286,7 @@ } if (check_name(directory, conn)) - ret = vfs_MkDir(conn,directory,unix_mode(conn,aDIR,directory)); + ret = vfs_MkDir(conn,directory,unix_mode(conn,aDIR,directory,True)); if (ret == -1) { if(errno == ENOENT) { Index: smbd/fileio.c =================================================================== --- smbd/fileio.c (revision 4002) +++ smbd/fileio.c (working copy) @@ -191,7 +191,7 @@ int dosmode = dos_mode(fsp->conn,fsp->fsp_name,&st); fsp->size = (SMB_BIG_UINT)st.st_size; if ((lp_store_dos_attributes(SNUM(fsp->conn)) || MAP_ARCHIVE(fsp->conn)) && !IS_DOS_ARCHIVE(dosmode)) { - file_set_dosmode(fsp->conn,fsp->fsp_name,dosmode | aARCH,&st); + file_set_dosmode(fsp->conn,fsp->fsp_name,dosmode | aARCH,&st, False); } /* Index: smbd/trans2.c =================================================================== --- smbd/trans2.c (revision 4002) +++ smbd/trans2.c (working copy) @@ -3935,7 +3935,7 @@ DEBUG(10,("call_trans2setfilepathinfo: file %s : setting dos mode %x\n", fname, dosmode )); - if(file_set_dosmode(conn, fname, dosmode, NULL)) { + if(file_set_dosmode(conn, fname, dosmode, &sbuf, False)) { DEBUG(2,("file_set_dosmode of %s failed (%s)\n", fname, strerror(errno))); return(UNIXERROR(ERRDOS,ERRnoaccess)); } @@ -4020,7 +4020,7 @@ return ERROR_NT(NT_STATUS_OBJECT_PATH_NOT_FOUND); } if (check_name(directory,conn)) - ret = vfs_MkDir(conn,directory,unix_mode(conn,aDIR,directory)); + ret = vfs_MkDir(conn,directory,unix_mode(conn,aDIR,directory,True)); if(ret < 0) { DEBUG(5,("call_trans2mkdir error (%s)\n", strerror(errno))); Index: smbd/dosmode.c =================================================================== --- smbd/dosmode.c (revision 4002) +++ smbd/dosmode.c (working copy) @@ -23,7 +23,7 @@ /**************************************************************************** Change a dos mode to a unix mode. Base permission for files: - if inheriting + if creating file and inheriting apply read/write bits from parent directory. else everybody gets read bit set @@ -43,7 +43,7 @@ } ****************************************************************************/ -mode_t unix_mode(connection_struct *conn, int dosmode, const char *fname) +mode_t unix_mode(connection_struct *conn, int dosmode, const char *fname, BOOL creating_file) { mode_t result = (S_IRUSR | S_IRGRP | S_IROTH | S_IWUSR | S_IWGRP | S_IWOTH); mode_t dir_mode = 0; /* Mode of the parent directory if inheriting. */ @@ -52,7 +52,7 @@ result &= ~(S_IWUSR | S_IWGRP | S_IWOTH); } - if (fname && lp_inherit_perms(SNUM(conn))) { + if (fname && creating_file && lp_inherit_perms(SNUM(conn))) { char *dname; SMB_STRUCT_STAT sbuf; @@ -329,7 +329,7 @@ chmod a file - but preserve some bits. ********************************************************************/ -int file_set_dosmode(connection_struct *conn, const char *fname, uint32 dosmode, SMB_STRUCT_STAT *st) +int file_set_dosmode(connection_struct *conn, const char *fname, uint32 dosmode, SMB_STRUCT_STAT *st, BOOL creating_file) { SMB_STRUCT_STAT st1; int mask=0; @@ -338,7 +338,7 @@ int ret = -1; DEBUG(10,("file_set_dosmode: setting dos mode 0x%x on file %s\n", dosmode, fname)); - if (!st) { + if (!st || (st && !VALID_STAT(*st))) { st = &st1; if (SMB_VFS_STAT(conn,fname,st)) return(-1); @@ -359,7 +359,7 @@ return 0; } - unixmode = unix_mode(conn,dosmode,fname); + unixmode = unix_mode(conn,dosmode,fname, creating_file); /* preserve the s bits */ mask |= (S_ISUID | S_ISGID);