Patch for smbd/open.c for changing file mode on open-truncate

Glen Gibb grg at ridley.unimelb.edu.au
Sat Oct 26 11:35:01 GMT 2002


Hi all,

I've discovered a problem with the way XP (maybe previous versions as
well) copy profiles to the server when map hidden is enabled.

When creating hidden files, XP does the following:

1. a temporary file is created which is NOT hidden but which is empty
(using NT Create AndX)
2. the file is closed
3. the file is opened with truncate using NT Create AndX, with the hidden
file flag set

The problem is the file has been created in step 1 with one file mode (eg
600), and then in step 3 it is opened with a different mode (eg. 601) even
though it is truncated. This is not permitted by open_file_shared1 (in
smbd/open.c).

The attached patch attempts to change the mode on open truncate, and only
if that fails does the NT Create AndX return an error.

Can someone check over the patch to make sure I'm not doing something I
shouldn't. This works on 2.2.6, and should also work on HEAD (the relevant
section of open.c is the same).

Thanks
Glen Gibb
Ridley College

-------------- next part --------------
*** open.c.orig	Sat Oct 26 20:23:24 2002
--- open.c	Sat Oct 26 21:03:29 2002
***************
*** 822,832 ****
  	/* We only care about matching attributes on file exists and truncate. */
  	if (file_existed && (GET_FILE_OPEN_DISPOSITION(ofun) == FILE_EXISTS_TRUNCATE)) {
  		if (!open_match_attributes(conn, fname, psbuf->st_mode, mode)) {
! 			DEBUG(5,("open_file_shared: attributes missmatch for file %s (0%o, 0%o)\n",
! 						fname, psbuf->st_mode, mode ));
! 			file_free(fsp);
! 			errno = EACCES;
! 			return NULL;
  		}
  	}
  
--- 822,834 ----
  	/* We only care about matching attributes on file exists and truncate. */
  	if (file_existed && (GET_FILE_OPEN_DISPOSITION(ofun) == FILE_EXISTS_TRUNCATE)) {
  		if (!open_match_attributes(conn, fname, psbuf->st_mode, mode)) {
! 			if (vfs_chmod(conn,fname,mode) != 0) {
! 				DEBUG(5,("open_file_shared: attributes missmatch for file %s (0%o, 0%o)\n",
! 							fname, psbuf->st_mode, mode ));
! 				file_free(fsp);
! 				errno = EACCES;
! 				return NULL;
! 			}
  		}
  	}
  


More information about the samba-technical mailing list