CreateFileMapping, Vista, Global namespace, SeCreateGlobalPrivilege...

| 2 Comments

I'm fixing up my performance monitoring code and this uses shared memory to communicate between the perfmon extension DLL and the application. Since I'm tightening up security I decided to explicitly pass in the security attributes, which has a possitive knock-on effect to several of my Win32 tools classes which now also need to deal with security properly rather than just conveniently... Of course once you're passing explicit security attributes around rather than simply passing 0 to the APIs you can get back some of the convenience of the not-needing-to-think-about-it style of security by passing in an "allow all" security descriptor. And then those clever Microsofties step in and deal with that ;)

CreateFileMapping(), which is used to create shared memory segments now requires that you have the SeCreateGlobalPrivilege (SE_CREATE_GLOBAL_NAME) on your account if you wish to create the object in the global namespace. Strangely you can still create other kernel objects, such as events, in the global namespace without SeCreateGlobalPrivilege... This is all documented in the docs for both CreateFileMapping() and kernel object namespaces, which is good, but, of course, those pages didn't come up when I did my initial Google search and I've got a slightly older set of help installed locally in VS...

And now I need to think about the testing implications of this. So far it looks like it will cause me to reduce the encapsulation of a class or two slightly; where the class would have taken a string for an name and then built an instance of CGlobalName to ensure that the name was in the global namespace it must now take an instance of IKernelObjectName and rely on the programmer to pass it an instance of CGlobalName when being used in an application and an instance of CLocalName or CUnqualifiedName when being used in test... And, of course, now I'm thinking about how I can run my tests, automatically, under accounts with various privs...

2 Comments

And, of course, now I'm thinking about how I can run my tests, automatically, under accounts with various privs...

Sysinternals psexec -- unlike M$ runas, you can supply the [clear-text] password as a parameter :)

Ah, cunning. Though I expect I'll add it to the requirements list for my distributed build and test system...

Leave a comment