Beispiel #1
0
        private static ServiceSecurityInformation GetServiceSecurityInformation(SafeServiceHandle scm, string name)
        {
            using (SafeServiceHandle service = OpenService(scm, name, ServiceAccessRights.QueryConfig | ServiceAccessRights.ReadControl))
            {
                if (service.IsInvalid)
                {
                    throw new Win32Exception();
                }

                return(new ServiceSecurityInformation(name, GetServiceSecurityDescriptor(service), GetTriggersForService(service)));
            }
        }
Beispiel #2
0
        static SecurityDescriptor GetServiceSecurityDescriptor(SafeServiceHandle handle)
        {
            int required = 0;

            byte[] sd = new byte[8192];
            if (!QueryServiceObjectSecurity(handle, SecurityInformation.AllBasic, sd, sd.Length, out required))
            {
                throw new Win32Exception();
            }

            return(new SecurityDescriptor(sd));
        }
Beispiel #3
0
        public static ServiceSecurityInformation GetServiceSecurityInformation(string name)
        {
            using (SafeServiceHandle scm = OpenSCManager(null, null,
                                                         ServiceControlManagerAccessRights.Connect | ServiceControlManagerAccessRights.ReadControl))
            {
                if (scm.IsInvalid)
                {
                    throw new Win32Exception();
                }

                return(GetServiceSecurityInformation(scm, name));
            }
        }
Beispiel #4
0
 static extern bool QueryServiceObjectSecurity(SafeServiceHandle hService,
                                               SecurityInformation dwSecurityInformation,
                                               [Out] byte[] lpSecurityDescriptor,
                                               int cbBufSize,
                                               out int pcbBytesNeeded);
Beispiel #5
0
 static extern SafeServiceHandle OpenService(
     SafeServiceHandle hSCManager,
     string lpServiceName,
     ServiceAccessRights dwDesiredAccess
     );