svn commit: samba r4007 - in branches/SAMBA_3_0/source/smbd: .

jra at samba.org jra at samba.org
Tue Nov 30 00:22:10 GMT 2004


Author: jra
Date: 2004-11-30 00:22:04 +0000 (Tue, 30 Nov 2004)
New Revision: 4007

WebSVN: http://websvn.samba.org/cgi-bin/viewcvs.cgi?view=rev&root=samba&rev=4007

Log:
Fix bug #2088 - ensure inherit permissions is only applied on a new file,
not an existing one.
Jeremy.

Modified:
   branches/SAMBA_3_0/source/smbd/dosmode.c
   branches/SAMBA_3_0/source/smbd/fileio.c
   branches/SAMBA_3_0/source/smbd/nttrans.c
   branches/SAMBA_3_0/source/smbd/open.c
   branches/SAMBA_3_0/source/smbd/posix_acls.c
   branches/SAMBA_3_0/source/smbd/reply.c
   branches/SAMBA_3_0/source/smbd/trans2.c


Changeset:
Modified: branches/SAMBA_3_0/source/smbd/dosmode.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/dosmode.c	2004-11-30 00:22:02 UTC (rev 4006)
+++ branches/SAMBA_3_0/source/smbd/dosmode.c	2004-11-30 00:22:04 UTC (rev 4007)
@@ -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);

Modified: branches/SAMBA_3_0/source/smbd/fileio.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/fileio.c	2004-11-30 00:22:02 UTC (rev 4006)
+++ branches/SAMBA_3_0/source/smbd/fileio.c	2004-11-30 00:22:04 UTC (rev 4007)
@@ -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);
 			}
 
 			/*

Modified: branches/SAMBA_3_0/source/smbd/nttrans.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/nttrans.c	2004-11-30 00:22:02 UTC (rev 4006)
+++ branches/SAMBA_3_0/source/smbd/nttrans.c	2004-11-30 00:22:04 UTC (rev 4007)
@@ -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;

Modified: branches/SAMBA_3_0/source/smbd/open.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/open.c	2004-11-30 00:22:02 UTC (rev 4006)
+++ branches/SAMBA_3_0/source/smbd/open.c	2004-11-30 00:22:04 UTC (rev 4007)
@@ -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);

Modified: branches/SAMBA_3_0/source/smbd/posix_acls.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/posix_acls.c	2004-11-30 00:22:02 UTC (rev 4006)
+++ branches/SAMBA_3_0/source/smbd/posix_acls.c	2004-11-30 00:22:04 UTC (rev 4007)
@@ -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);

Modified: branches/SAMBA_3_0/source/smbd/reply.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/reply.c	2004-11-30 00:22:02 UTC (rev 4006)
+++ branches/SAMBA_3_0/source/smbd/reply.c	2004-11-30 00:22:04 UTC (rev 4007)
@@ -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) {

Modified: branches/SAMBA_3_0/source/smbd/trans2.c
===================================================================
--- branches/SAMBA_3_0/source/smbd/trans2.c	2004-11-30 00:22:02 UTC (rev 4006)
+++ branches/SAMBA_3_0/source/smbd/trans2.c	2004-11-30 00:22:04 UTC (rev 4007)
@@ -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)));



More information about the samba-cvs mailing list