Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, I was wondering what exactly this code is doing line by line . To me it\'

ID: 3669684 • Letter: H

Question

Hello,

I was wondering what exactly this code is doing line by line. To me it's seems like it's not doing much, but only works if it is implemented. For context im using a global named mutex to see if "blank" is running as a service. I only need to implement the security stuff if I run in a windows service and not if I just run a c++ program. If I don't implement security stuff I get access denied.

SECURITY_DESCRIPTOR SecDes;
  
   if (!InitializeSecurityDescriptor(&SecDes, SECURITY_DESCRIPTOR_REVISION))
   {
       // return some error value
       return -1;
   }

   if (!SetSecurityDescriptorDacl(&SecDes, TRUE, NULL, FALSE))
   {
       // return some error value
       return -2;
   }

   SECURITY_ATTRIBUTES SecAttr;
   SecAttr.nLength = sizeof(SecAttr);
   SecAttr.lpSecurityDescriptor = &SecDes;
   SecAttr.bInheritHandle = TRUE;

   isServiceRunningMutex = CreateMutex(
&SecAttr, // default security descriptor
               FALSE,                       // mutex ot owned
               stuff); // object name

Explanation / Answer

CreateMutex() function needs security descriptor object

In the given two if bloks, first we are initialize security descriptor using InitializeSecurityDescriptor. If initialization of security descriptor fails, we are returning -1,

Next, we are setting security descriptor information in a discretionary access control list (DACL). If that fails, we are returning -2.

Finally the initialized security descriptor is passed to createMutex function.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote