Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Shared memory between "service" and "user" process ....

252 views
Skip to first unread message

Thomas Leitner

unread,
Jul 4, 1997, 3:00:00 AM7/4/97
to

Hi,

I have written two NT services which communicate via a shared memory
block. Now a user process (display process) should attach to the same
shared memory, though this does not work due to a "access denied"
error on OpenFileMapping.

I'm creating the shared memory in the service with:

CreateFileMapping((HANDLE) 0xffffffff, NULL, PAGE_READWRITE, 0,
size, name);

this works perfectly between services and between user processes
but when a user process wants to "OpenFileMapping" such a shared memory
allocated by a service, I get an "access denied" error.

I suppose I need to setup the SECURITY_ATTRIBUTES (second parameter
of CreateFileMapping) in a special way to allow the user process
to attach to this shared memory.

So my question: Can anyone tell me how to setup an SECURITY_ATTRIBUTES
structure to get this going?

Thanks a lot -- Tom

--
--------------------------------------------------------------------------
T o m L e i t n e r Dept. of Communications
Graz University of Technology,
e-mail : t...@finwds01.tu-graz.ac.at Inffeldgasse 12
Phone : +43-316-873-7455 A-8010 Graz / Austria / Europe
Fax : +43-316-463-697
Home page : http://wiis.tu-graz.ac.at/people/tom.html
PGP public key on : ftp://wiis.tu-graz.ac.at/pgp-keys/tom.asc or send
mail with subject "get Thomas Leitner" to pgp-pub...@keys.pgp.net
--------------------------------------------------------------------------

Zaphod

unread,
Jul 14, 1997, 3:00:00 AM7/14/97
to Thomas Leitner

Hi

I solve this problem by creating the
FILE MAPPING by the User-Process. Now
the Win32-Service can open this
FileMapping and the User-Process can
communicate with the Service.

I have got the same Problem with Mutex.
If a Win32-Service call "CreateMutex" a
normal process cannot open this Mutex.
The Error is also "Access denied".

Sigmar

Paul Conti

unread,
Jul 14, 1997, 3:00:00 AM7/14/97
to

Try something like the following the code:
Have your service call mutex_init() and your users call mutex_open()
of course you can add real security to all of this by reading up on
the security calls and adding the correct attributes.
you must also pass in a unique name to the mutex_init() call and use the
same
name in the mutex_open calls.
Note also that the same or simular security descripter
can be passed in to your CreateFile() call for your memory mapped file
so your service can create it and your users can just open it.

/* MUTEX stuff */

int mutex_init(HANDLE *mutex,const TCHAR *attr)
{
SECURITY_ATTRIBUTES SecurityAttributes;
SECURITY_DESCRIPTOR SecurityDescriptor;

// set security to NULL so everyone can read/write our memory file
InitializeSecurityDescriptor(&SecurityDescriptor,
SECURITY_DESCRIPTOR_REVISION);

SetSecurityDescriptorDacl(&SecurityDescriptor, // address of security
descriptor
TRUE, // flag for presence of discretionary ACL
NULL, // discretionary ACL of NULL gives everyone access
FALSE // flag for default discretionary ACL
);

SecurityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES);
SecurityAttributes.lpSecurityDescriptor = (LPVOID)&SecurityDescriptor;
SecurityAttributes.bInheritHandle = FALSE;

*mutex = CreateMutex(&SecurityAttributes, // no security attributes
FALSE, // initially not owned
attr); // name of mutex
if (*mutex == NULL)
{
LPSTR lpMsgBuf;

FormatMessage( FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM,
NULL,
GetLastError(),
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL );

// Display the string.
printf("Can't create mutex: %u\n", GetLastError());

// Free the buffer.
LocalFree( lpMsgBuf );
return 1;
}
return 0;
}

int mutex_open(HANDLE *mutex, const TCHAR *attr)
{
*mutex = OpenMutex(MUTEX_ALL_ACCESS, // full access
FALSE, // no inherit
attr); // name of mutex
if (*mutex == NULL)
return 1;
return 0;
}

0 new messages