* fhandler.cc (fhandler_base::open): Drop local wpath and upath
variables. Call pc.get_object_attr to create object attributes. * fhandler_disk_file.cc (fhandler_disk_file::opendir): Ditto. * syscalls.cc (unlink_nt): Ditto. * path.cc (path_conv::set_normalized_path): Set wide_path to NULL. (path_conv::get_nt_native_path): Drop parameter. Create path in wide_path/uni_path members. (path_conv::get_object_attr): New method to create object attributes. (path_conv::get_wide_win32_path): New method to create Win32 wide path. (path_conv::check): Initialize wide_path to NULL. (path_conv::~path_conv): cfree wide_path. * path.h (class path_conv): New members wide_path and uni_path. Add declarations of get_object_attr and get_wide_win32_path. (path_conv::path_conv): Initialize wide_path to NULL. (path_conv::get_nt_native_path): Drop parameter.
This commit is contained in:
		| @@ -1,3 +1,21 @@ | |||||||
|  | 2007-07-19  Corinna Vinschen  <corinna@vinschen.de> | ||||||
|  |  | ||||||
|  | 	* fhandler.cc (fhandler_base::open): Drop local wpath and upath | ||||||
|  | 	variables.  Call pc.get_object_attr to create object attributes. | ||||||
|  | 	* fhandler_disk_file.cc (fhandler_disk_file::opendir): Ditto. | ||||||
|  | 	* syscalls.cc (unlink_nt): Ditto. | ||||||
|  | 	* path.cc (path_conv::set_normalized_path): Set wide_path to NULL. | ||||||
|  | 	(path_conv::get_nt_native_path): Drop parameter.  Create path in | ||||||
|  | 	wide_path/uni_path members. | ||||||
|  | 	(path_conv::get_object_attr): New method to create object attributes. | ||||||
|  | 	(path_conv::get_wide_win32_path): New method to create Win32 wide path. | ||||||
|  | 	(path_conv::check): Initialize wide_path to NULL. | ||||||
|  | 	(path_conv::~path_conv): cfree wide_path. | ||||||
|  | 	* path.h (class path_conv): New members wide_path and uni_path. | ||||||
|  | 	Add declarations of get_object_attr and get_wide_win32_path. | ||||||
|  | 	(path_conv::path_conv): Initialize wide_path to NULL. | ||||||
|  | 	(path_conv::get_nt_native_path): Drop parameter. | ||||||
|  |  | ||||||
| 2007-07-19  Corinna Vinschen  <corinna@vinschen.de> | 2007-07-19  Corinna Vinschen  <corinna@vinschen.de> | ||||||
|  |  | ||||||
| 	* sec_helper.cc: Remove unused code. | 	* sec_helper.cc: Remove unused code. | ||||||
|   | |||||||
| @@ -457,10 +457,6 @@ done: | |||||||
| int | int | ||||||
| fhandler_base::open (int flags, mode_t mode) | fhandler_base::open (int flags, mode_t mode) | ||||||
| { | { | ||||||
|   WCHAR wpath[CYG_MAX_PATH + 10]; |  | ||||||
|   UNICODE_STRING upath = {0, sizeof (wpath), wpath}; |  | ||||||
|   pc.get_nt_native_path (upath); |  | ||||||
|  |  | ||||||
|   int res = 0; |   int res = 0; | ||||||
|   HANDLE x; |   HANDLE x; | ||||||
|   ULONG file_attributes = 0; |   ULONG file_attributes = 0; | ||||||
| @@ -475,8 +471,7 @@ fhandler_base::open (int flags, mode_t mode) | |||||||
|  |  | ||||||
|   syscall_printf ("(%s, %p)", get_win32_name (), flags); |   syscall_printf ("(%s, %p)", get_win32_name (), flags); | ||||||
|  |  | ||||||
|   InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE | OBJ_INHERIT, |   pc.get_object_attr (attr, sa); | ||||||
| 			      NULL, sa.lpSecurityDescriptor); |  | ||||||
|  |  | ||||||
|   switch (query_open ()) |   switch (query_open ()) | ||||||
|     { |     { | ||||||
|   | |||||||
| @@ -1575,16 +1575,11 @@ fhandler_disk_file::opendir (int fd) | |||||||
| 	      OBJECT_ATTRIBUTES attr; | 	      OBJECT_ATTRIBUTES attr; | ||||||
| 	      NTSTATUS status; | 	      NTSTATUS status; | ||||||
| 	      IO_STATUS_BLOCK io; | 	      IO_STATUS_BLOCK io; | ||||||
| 	      WCHAR wpath[CYG_MAX_PATH + 10] = { 0 }; |  | ||||||
| 	      UNICODE_STRING upath = {0, sizeof (wpath), wpath}; |  | ||||||
| 	      SECURITY_ATTRIBUTES sa = sec_none; |  | ||||||
|  |  | ||||||
| 	      pc.get_nt_native_path (upath); |  | ||||||
| 	      InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE, |  | ||||||
| 					  NULL, sa.lpSecurityDescriptor); |  | ||||||
| 	      status = NtOpenFile (&get_handle (), | 	      status = NtOpenFile (&get_handle (), | ||||||
| 				   SYNCHRONIZE | FILE_LIST_DIRECTORY, | 				   SYNCHRONIZE | FILE_LIST_DIRECTORY, | ||||||
| 				   &attr, &io, FILE_SHARE_VALID_FLAGS, | 				   pc.get_object_attr (attr, sec_none_nih), | ||||||
|  | 				   &io, FILE_SHARE_VALID_FLAGS, | ||||||
| 				   FILE_SYNCHRONOUS_IO_NONALERT | 				   FILE_SYNCHRONOUS_IO_NONALERT | ||||||
| 				   | FILE_OPEN_FOR_BACKUP_INTENT | 				   | FILE_OPEN_FOR_BACKUP_INTENT | ||||||
| 				   | FILE_DIRECTORY_FILE); | 				   | FILE_DIRECTORY_FILE); | ||||||
|   | |||||||
| @@ -79,6 +79,7 @@ details. */ | |||||||
| #include "environ.h" | #include "environ.h" | ||||||
| #include <assert.h> | #include <assert.h> | ||||||
| #include <ntdll.h> | #include <ntdll.h> | ||||||
|  | #include <wchar.h> | ||||||
|  |  | ||||||
| bool dos_file_warning = true; | bool dos_file_warning = true; | ||||||
| static int normalize_win32_path (const char *, char *, char *&); | static int normalize_win32_path (const char *, char *, char *&); | ||||||
| @@ -539,6 +540,7 @@ path_conv::set_normalized_path (const char *path_copy, bool strip_tail) | |||||||
|     } |     } | ||||||
|  |  | ||||||
|   memcpy (normalized_path, path_copy, n); |   memcpy (normalized_path, path_copy, n); | ||||||
|  |   wide_path = NULL; | ||||||
| } | } | ||||||
|  |  | ||||||
| PUNICODE_STRING | PUNICODE_STRING | ||||||
| @@ -566,9 +568,40 @@ get_nt_native_path (const char *path, UNICODE_STRING &upath) | |||||||
| } | } | ||||||
|  |  | ||||||
| PUNICODE_STRING | PUNICODE_STRING | ||||||
| path_conv::get_nt_native_path (UNICODE_STRING &upath) | path_conv::get_nt_native_path () | ||||||
| { | { | ||||||
|   return ::get_nt_native_path (path, upath); |   if (!wide_path) | ||||||
|  |     { | ||||||
|  |       uni_path.Length = 0; | ||||||
|  |       uni_path.MaximumLength = (strlen (path) + 10) * sizeof (WCHAR); | ||||||
|  |       wide_path = (PWCHAR) cmalloc (HEAP_STR, uni_path.MaximumLength); | ||||||
|  |       uni_path.Buffer = wide_path; | ||||||
|  |       ::get_nt_native_path (path, uni_path); | ||||||
|  |     } | ||||||
|  |   return &uni_path; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | POBJECT_ATTRIBUTES | ||||||
|  | path_conv::get_object_attr (OBJECT_ATTRIBUTES &attr, SECURITY_ATTRIBUTES &sa) | ||||||
|  | { | ||||||
|  |   if (!get_nt_native_path ()) | ||||||
|  |     return NULL; | ||||||
|  |   InitializeObjectAttributes (&attr, &uni_path, | ||||||
|  | 			      OBJ_CASE_INSENSITIVE | ||||||
|  | 			      | (sa.bInheritHandle ? OBJ_INHERIT : 0), | ||||||
|  | 			      NULL, sa.lpSecurityDescriptor); | ||||||
|  |   return &attr; | ||||||
|  | } | ||||||
|  |  | ||||||
|  | PWCHAR | ||||||
|  | path_conv::get_wide_win32_path (PWCHAR wc) | ||||||
|  | { | ||||||
|  |   get_nt_native_path (); | ||||||
|  |   if (!wide_path || wide_path[1] != L'?') /* Native NT device path */ | ||||||
|  |     return NULL; | ||||||
|  |   wcscpy (wc, wide_path); | ||||||
|  |   wc[1] = L'\\'; | ||||||
|  |   return wc; | ||||||
| } | } | ||||||
|  |  | ||||||
| void | void | ||||||
| @@ -640,6 +673,7 @@ path_conv::check (const char *src, unsigned opt, | |||||||
|   path_flags = 0; |   path_flags = 0; | ||||||
|   known_suffix = NULL; |   known_suffix = NULL; | ||||||
|   fileattr = INVALID_FILE_ATTRIBUTES; |   fileattr = INVALID_FILE_ATTRIBUTES; | ||||||
|  |   wide_path = NULL; | ||||||
|   case_clash = false; |   case_clash = false; | ||||||
|   memset (&dev, 0, sizeof (dev)); |   memset (&dev, 0, sizeof (dev)); | ||||||
|   fs.clear (); |   fs.clear (); | ||||||
| @@ -1147,6 +1181,11 @@ path_conv::~path_conv () | |||||||
|       cfree (normalized_path); |       cfree (normalized_path); | ||||||
|       normalized_path = NULL; |       normalized_path = NULL; | ||||||
|     } |     } | ||||||
|  |   if (wide_path) | ||||||
|  |     { | ||||||
|  |       cfree (wide_path); | ||||||
|  |       wide_path = NULL; | ||||||
|  |     } | ||||||
| } | } | ||||||
|  |  | ||||||
| /* Return true if src_path is a valid, internally supported device name. | /* Return true if src_path is a valid, internally supported device name. | ||||||
|   | |||||||
| @@ -156,6 +156,8 @@ class path_conv | |||||||
| { | { | ||||||
|   DWORD fileattr; |   DWORD fileattr; | ||||||
|   fs_info fs; |   fs_info fs; | ||||||
|  |   PWCHAR wide_path; | ||||||
|  |   UNICODE_STRING uni_path; | ||||||
|   void add_ext_from_sym (symlink_info&); |   void add_ext_from_sym (symlink_info&); | ||||||
|  public: |  public: | ||||||
|  |  | ||||||
| @@ -236,7 +238,8 @@ class path_conv | |||||||
| 	      const suffix_info *suffixes = NULL)  __attribute__ ((regparm(3))); | 	      const suffix_info *suffixes = NULL)  __attribute__ ((regparm(3))); | ||||||
|  |  | ||||||
|   path_conv (const device& in_dev): fileattr (INVALID_FILE_ATTRIBUTES), |   path_conv (const device& in_dev): fileattr (INVALID_FILE_ATTRIBUTES), | ||||||
|      path_flags (0), known_suffix (NULL), error (0), dev (in_dev) |      wide_path (NULL), path_flags (0), known_suffix (NULL), error (0), | ||||||
|  |      dev (in_dev) | ||||||
|     { |     { | ||||||
|       strcpy (path, in_dev.native); |       strcpy (path, in_dev.native); | ||||||
|     } |     } | ||||||
| @@ -253,14 +256,18 @@ class path_conv | |||||||
|     check (src, opt | PC_NULLEMPTY, suffixes); |     check (src, opt | PC_NULLEMPTY, suffixes); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   path_conv (): fileattr (INVALID_FILE_ATTRIBUTES), path_flags (0), |   path_conv (): fileattr (INVALID_FILE_ATTRIBUTES), wide_path (NULL), | ||||||
|   		known_suffix (NULL), error (0), normalized_path (NULL) |   		path_flags (0), known_suffix (NULL), error (0), | ||||||
|  | 		normalized_path (NULL) | ||||||
|     {path[0] = '\0';} |     {path[0] = '\0';} | ||||||
|  |  | ||||||
|   ~path_conv (); |   ~path_conv (); | ||||||
|   void set_name (const char *win32, const char *posix); |   void set_name (const char *win32, const char *posix); | ||||||
|   inline char *get_win32 () { return path; } |   inline char *get_win32 () { return path; } | ||||||
|   PUNICODE_STRING get_nt_native_path (UNICODE_STRING &upath); |   PUNICODE_STRING get_nt_native_path (); | ||||||
|  |   POBJECT_ATTRIBUTES get_object_attr (OBJECT_ATTRIBUTES &attr, | ||||||
|  | 				      SECURITY_ATTRIBUTES &sa); | ||||||
|  |   PWCHAR get_wide_win32_path (PWCHAR wc); | ||||||
|   operator char *() {return path;} |   operator char *() {return path;} | ||||||
|   operator const char *() {return path;} |   operator const char *() {return path;} | ||||||
|   operator DWORD &() {return fileattr;} |   operator DWORD &() {return fileattr;} | ||||||
|   | |||||||
| @@ -234,8 +234,6 @@ try_to_bin (path_conv &win32_path, HANDLE h) | |||||||
| DWORD | DWORD | ||||||
| unlink_nt (path_conv &win32_name, bool setattrs) | unlink_nt (path_conv &win32_name, bool setattrs) | ||||||
| { | { | ||||||
|   WCHAR wpath[CYG_MAX_PATH + 10]; |  | ||||||
|   UNICODE_STRING upath = {0, sizeof (wpath), wpath}; |  | ||||||
|   OBJECT_ATTRIBUTES attr; |   OBJECT_ATTRIBUTES attr; | ||||||
|   IO_STATUS_BLOCK io; |   IO_STATUS_BLOCK io; | ||||||
|   NTSTATUS status; |   NTSTATUS status; | ||||||
| @@ -269,9 +267,7 @@ unlink_nt (path_conv &win32_name, bool setattrs) | |||||||
|   if (win32_name.is_rep_symlink ()) |   if (win32_name.is_rep_symlink ()) | ||||||
|     flags |= FILE_OPEN_REPARSE_POINT; |     flags |= FILE_OPEN_REPARSE_POINT; | ||||||
|  |  | ||||||
|   win32_name.get_nt_native_path (upath); |   win32_name.get_object_attr (attr, sec_none_nih); | ||||||
|   InitializeObjectAttributes (&attr, &upath, OBJ_CASE_INSENSITIVE | OBJ_INHERIT, |  | ||||||
| 			      NULL, sec_none_nih.lpSecurityDescriptor); |  | ||||||
|   /* First try to open the file with sharing not allowed.  If the file |   /* First try to open the file with sharing not allowed.  If the file | ||||||
|      has an open handle on it, this will fail.  That indicates that the |      has an open handle on it, this will fail.  That indicates that the | ||||||
|      file has to be moved to the recycle bin so that it actually disappears |      file has to be moved to the recycle bin so that it actually disappears | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user