CreateFile access/sharing problem
Vitaliy Margolen
wine-devel at kievinfo.com
Thu Oct 6 01:10:53 CDT 2005
Wednesday, October 5, 2005, 10:57:48 PM, Robert Shearman wrote:
> Bill Medland wrote:
>>On October 5, 2005 03:56 pm, Robert Shearman wrote:
>>
>>
>>> There is a port of that function into
>>>
>>>wineserver in server/token.c called map_generic_mask that I
>>>used for the purpose of mapping generic access rights in the
>>>token functions. The problem with translating from generic
>>>access rights is that they don't map onto Unix access rights
>>>very well. I suspect that the best solution is to request read
>>>access if any of the NT read rights are requested and
>>>similarly for the write rights.
>>>
>>>
>>
>>Except that is largely irrelevant in this particular case. It's
>>the mapping from GENERIC to <OBJECT>_... (e.g. FILE_) that is
>>relevant, and as Vitaliy pointed out, that is in the object
>>area.
>>
> It is not irrelevant. Yes, as Vitaliy pointed out the architecture needs
> to be changed so that all of the objects have a generic mapping and that
> mapping is done automatically, but we are in code freeze and I don't
> think those sorts of changes are acceptable. I think that adding in a
> mapping for the file object only in the wineserver is acceptable. The
> one line can be abstracted out later.
> Just to make it clear, the question about NT rights mapping to Unix
> rights matters wherever the mapping is done.
I think this is the way it might look like. It's a hack and not the real
solution.
WARNING:
I haven't tested this beyond notepad so it might not work at all or have some
major problems. For all I know it might wipe out your entire hard drive
especially if you running wine as a root. <g>
Vitaliy
-------------- next part --------------
Index: server/fd.c
===================================================================
RCS file: /home/wine/wine/server/fd.c,v
retrieving revision 1.49
diff -u -p -r1.49 fd.c
--- server/fd.c 24 Aug 2005 18:33:51 -0000 1.49
+++ server/fd.c 6 Oct 2005 06:05:21 -0000
@@ -1638,15 +1638,17 @@ DECL_HANDLER(flush_file)
DECL_HANDLER(get_handle_fd)
{
struct fd *fd;
+ unsigned int access = req->access;
+ map_generic_mask(&access, &file_generic_mapping);
reply->fd = -1;
- if ((fd = get_handle_fd_obj( current->process, req->handle, req->access )))
+ if ((fd = get_handle_fd_obj( current->process, req->handle, access )))
{
int unix_fd = get_unix_fd( fd );
if (unix_fd != -1)
{
- int cached_fd = get_handle_unix_fd( current->process, req->handle, req->access );
+ int cached_fd = get_handle_unix_fd( current->process, req->handle, access );
if (cached_fd != -1) reply->fd = cached_fd;
else if (!get_error()) send_client_fd( current->process, unix_fd, req->handle );
}
Index: server/file.c
===================================================================
RCS file: /home/wine/wine/server/file.c,v
retrieving revision 1.100
diff -u -p -r1.100 file.c
--- server/file.c 8 Aug 2005 15:11:03 -0000 1.100
+++ server/file.c 6 Oct 2005 06:05:21 -0000
@@ -59,6 +59,30 @@ struct file
unsigned int options; /* file options (FILE_DELETE_ON_CLOSE, FILE_SYNCHRONOUS...) */
};
+GENERIC_MAPPING file_generic_mapping =
+{
+ FILE_GENERIC_READ,
+ FILE_GENERIC_WRITE,
+ FILE_GENERIC_EXECUTE,
+ FILE_ALL_ACCESS
+};
+void WINAPI map_generic_mask( unsigned int *AccessMask, const GENERIC_MAPPING *GenericMapping)
+{
+ if (*AccessMask & GENERIC_READ)
+ *AccessMask |= GenericMapping->GenericRead;
+
+ if (*AccessMask & GENERIC_WRITE)
+ *AccessMask |= GenericMapping->GenericWrite;
+
+ if (*AccessMask & GENERIC_EXECUTE)
+ *AccessMask |= GenericMapping->GenericExecute;
+
+ if (*AccessMask & GENERIC_ALL)
+ *AccessMask |= GenericMapping->GenericAll;
+
+ *AccessMask &= 0x0FFFFFFF;
+}
+
static void file_dump( struct object *obj, int verbose );
static struct fd *file_get_fd( struct object *obj );
static void file_destroy( struct object *obj );
@@ -140,12 +164,12 @@ static struct object *create_file( const
default: set_error( STATUS_INVALID_PARAMETER ); goto error;
}
- switch(access & (GENERIC_READ | GENERIC_WRITE))
+ switch(access & 3)
{
case 0: break;
- case GENERIC_READ: flags |= O_RDONLY; break;
- case GENERIC_WRITE: flags |= O_WRONLY; break;
- case GENERIC_READ|GENERIC_WRITE: flags |= O_RDWR; break;
+ case FILE_READ_DATA: flags |= O_RDONLY; break;
+ case FILE_WRITE_DATA: flags |= O_WRONLY; break;
+ case FILE_READ_DATA|FILE_WRITE_DATA: flags |= O_RDWR; break;
}
mode = (attrs & FILE_ATTRIBUTE_READONLY) ? 0444 : 0666;
@@ -219,8 +243,8 @@ static int file_get_poll_events( struct
struct file *file = get_fd_user( fd );
int events = 0;
assert( file->obj.ops == &file_ops );
- if (file->access & GENERIC_READ) events |= POLLIN;
- if (file->access & GENERIC_WRITE) events |= POLLOUT;
+ if (file->access & FILE_READ_DATA) events |= POLLIN;
+ if (file->access & FILE_WRITE_DATA) events |= POLLOUT;
return events;
}
@@ -348,12 +372,14 @@ int grow_file( struct file *file, file_p
DECL_HANDLER(create_file)
{
struct object *file;
+ unsigned int access = req->access;
reply->handle = 0;
- if ((file = create_file( get_req_data(), get_req_data_size(), req->access,
+ map_generic_mask(&access, &file_generic_mapping);
+ if ((file = create_file( get_req_data(), get_req_data_size(), access,
req->sharing, req->create, req->options, req->attrs )))
{
- reply->handle = alloc_handle( current->process, file, req->access, req->inherit );
+ reply->handle = alloc_handle( current->process, file, access, req->inherit );
release_object( file );
}
}
@@ -363,16 +389,18 @@ DECL_HANDLER(alloc_file_handle)
{
struct file *file;
int fd;
+ unsigned int access = req->access;
+ map_generic_mask(&access, &file_generic_mapping);
reply->handle = 0;
if ((fd = thread_get_inflight_fd( current, req->fd )) == -1)
{
set_error( STATUS_INVALID_HANDLE );
return;
}
- if ((file = create_file_for_fd( fd, req->access, FILE_SHARE_READ | FILE_SHARE_WRITE )))
+ if ((file = create_file_for_fd( fd, access, FILE_SHARE_READ | FILE_SHARE_WRITE )))
{
- reply->handle = alloc_handle( current->process, file, req->access, req->inherit );
+ reply->handle = alloc_handle( current->process, file, access, req->inherit );
release_object( file );
}
}
Index: server/file.h
===================================================================
RCS file: /home/wine/wine/server/file.h,v
retrieving revision 1.24
diff -u -p -r1.24 file.h
--- server/file.h 14 Jul 2005 12:18:05 -0000 1.24
+++ server/file.h 6 Oct 2005 06:05:21 -0000
@@ -27,6 +27,9 @@ struct fd;
typedef unsigned __int64 file_pos_t;
+extern GENERIC_MAPPING file_generic_mapping;
+extern void WINAPI map_generic_mask( unsigned int *AccessMask, const GENERIC_MAPPING *GenericMapping);
+
/* operations valid on file descriptor objects */
struct fd_ops
{
More information about the wine-devel
mailing list