r4007: Fix bug #2088 - ensure inherit permissions is only applied on a new file,
authorJeremy Allison <jra@samba.org>
Tue, 30 Nov 2004 00:22:04 +0000 (00:22 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 15:53:27 +0000 (10:53 -0500)
not an existing one.
Jeremy.

source/smbd/dosmode.c
source/smbd/fileio.c
source/smbd/nttrans.c
source/smbd/open.c
source/smbd/posix_acls.c
source/smbd/reply.c
source/smbd/trans2.c

index 7199b3ebbf3e6d69daa8d7fd81d461631502def8..fefcaca09d5db31742a62a0617cf09559aa9d499 100644 (file)
@@ -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 @@ mode_t unix_mode(connection_struct *conn, int dosmode, const char *fname)
                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 @@ uint32 dos_mode(connection_struct *conn, const char *path,SMB_STRUCT_STAT *sbuf)
  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 file_set_dosmode(connection_struct *conn, const char *fname, uint32 dosmode,
        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 @@ int file_set_dosmode(connection_struct *conn, const char *fname, uint32 dosmode,
                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);
index dde254644ff35ae78516f90dcdf27786ffc010fa..060fbb124dbdb60b24cef13392b0334056287002 100644 (file)
@@ -191,7 +191,7 @@ ssize_t write_file(files_struct *fsp, char *data, SMB_OFF_T pos, size_t n)
                        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 8e62a0f8bf7faac17365a563a883e62c2c270f89..42953a1b7a1751c82ab4e973aa72ddd1a3c4945d 100644 (file)
@@ -1661,7 +1661,7 @@ static NTSTATUS copy_internals(connection_struct *conn, char *oldname, char *new
 
        /* 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 1b5ba1228f48f53ea5e4a5df706df200af43ebe0..7cadf5adbacfc1857c579790c7ced5d1bc737388 100644 (file)
@@ -979,7 +979,7 @@ files_struct *open_file_shared1(connection_struct *conn,char *fname, SMB_STRUCT_
        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 @@ flags=0x%X flags2=0x%X mode=0%o returned %d\n",
        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 @@ files_struct *open_directory(connection_struct *conn, char *fname, SMB_STRUCT_ST
                                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 d2e12fc82a9ffa72a6d4c7e79cea1c62dddf227a..ab46bae3462f2940cb5c7b9fef1566fab4d6268a 100644 (file)
@@ -1864,7 +1864,7 @@ static mode_t create_default_mode(files_struct *fsp, BOOL interitable_mode)
        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 376ef24ff720da5bb8e3743735d41ded2f461e84..2806b796b35740df0b9301d3093d4861571f8f7b 100644 (file)
@@ -719,7 +719,7 @@ int reply_setatr(connection_struct *conn, char *inbuf,char *outbuf, int dum_size
                        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 @@ NTSTATUS mkdir_internal(connection_struct *conn, pstring directory)
        }
 
        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 81ffe1dbe025bc349481ab9b039ba3644a7bc78c..4a10511a0e4c664baf4efb021c47f3e6f6166521 100644 (file)
@@ -3935,7 +3935,7 @@ size = %.0f, uid = %u, gid = %u, raw perms = 0%o\n",
 
                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 @@ static int call_trans2mkdir(connection_struct *conn, char *inbuf, char *outbuf,
                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)));