Exemple #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)));
            }
        }
Exemple #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));
        }
Exemple #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));
            }
        }
Exemple #4
0
 static extern bool QueryServiceObjectSecurity(SafeServiceHandle hService,
                                               SecurityInformation dwSecurityInformation,
                                               [Out] byte[] lpSecurityDescriptor,
                                               int cbBufSize,
                                               out int pcbBytesNeeded);
Exemple #5
0
 static extern SafeServiceHandle OpenService(
     SafeServiceHandle hSCManager,
     string lpServiceName,
     ServiceAccessRights dwDesiredAccess
     );