protected override bool ReleaseHandle()
        {
#pragma warning suppress 56523
            return(SafeNativeMethods.CertCloseStore(handle, 0));
        }
        protected override bool ReleaseHandle()
        {
#pragma warning suppress 56523
            IntPtr r = SafeNativeMethods.LocalFree(handle);
            return(r == IntPtr.Zero);
        }
Exemplo n.º 3
0
 public void MapGeneric(ref GenericAccess generic)
 {
     SafeNativeMethods.MapGenericMask(out generic.Mask, ref ServiceGenericMapping);
 }
Exemplo n.º 4
0
        static void ReserveURL(string networkURL, string securityDescriptor)
        {
            int retVal = SafeNativeMethods.NoError;

            try
            {
                retVal = SafeNativeMethods.HttpInitialize(HttpWrapper.HttpApiVersion1, SafeNativeMethods.HTTP_INITIALIZE_CONFIG, IntPtr.Zero);

                if (SafeNativeMethods.NoError == retVal)
                {
                    HttpServiceConfigUrlAclKey   keyDesc   = new HttpServiceConfigUrlAclKey(networkURL);
                    HttpServiceConfigUrlAclParam paramDesc = new HttpServiceConfigUrlAclParam(securityDescriptor);

                    HttpServiceConfigUrlAclSet configInformation = new HttpServiceConfigUrlAclSet();
                    configInformation.KeyDesc   = keyDesc;
                    configInformation.ParamDesc = paramDesc;

                    int configInformationLength = Marshal.SizeOf(configInformation);

                    retVal = SafeNativeMethods.HttpSetServiceConfiguration_UrlAcl(IntPtr.Zero,
                                                                                  HttpServiceConfigId.HttpServiceConfigUrlAclInfo,
                                                                                  ref configInformation,
                                                                                  configInformationLength,
                                                                                  IntPtr.Zero);

                    if (SafeNativeMethods.ErrorAlreadyExists == retVal)
                    {
                        retVal = SafeNativeMethods.HttpDeleteServiceConfiguration_UrlAcl(IntPtr.Zero,
                                                                                         HttpServiceConfigId.HttpServiceConfigUrlAclInfo,
                                                                                         ref configInformation,
                                                                                         configInformationLength,
                                                                                         IntPtr.Zero);

                        if (SafeNativeMethods.NoError == retVal)
                        {
                            retVal = SafeNativeMethods.HttpSetServiceConfiguration_UrlAcl(IntPtr.Zero,
                                                                                          HttpServiceConfigId.HttpServiceConfigUrlAclInfo,
                                                                                          ref configInformation,
                                                                                          configInformationLength,
                                                                                          IntPtr.Zero);
                        }
                    }
                }
            }
            finally
            {
                SafeNativeMethods.HttpTerminate(SafeNativeMethods.HTTP_INITIALIZE_CONFIG, IntPtr.Zero);
            }

            if (SafeNativeMethods.NoError != retVal)
            {
                if (SafeNativeMethods.ErrorAlreadyExists == retVal)
                {
                    throw new WsatAdminException(WsatAdminErrorCode.REGISTER_HTTPS_PORT_ALREADYEXISTS,
                                                 SR.GetString(SR.ErrorRegisterHttpsPortAlreadyExists));
                }
                else
                {
                    throw new WsatAdminException(WsatAdminErrorCode.REGISTER_HTTPS_PORT,
                                                 SR.GetString(SR.ErrorRegisterHttpsPort, retVal));
                }
            }
        }
Exemplo n.º 5
0
        // this method is called by SecurityInfoCCW.GetSecurity
        // its return is the SecurityDescriptor in binary format
        // it loads the data from the registry
        // [loads data from registry to UI]
        public IntPtr GetSecurity(SecurityInfos requestedInformation, bool wantDefault)
        {
            if (requestedInformation == SecurityInfos.DiscretionaryAcl)
            {
                StringBuilder securityDescriptorBuilder = new StringBuilder("D:");

                System.Collections.ArrayList kerb = new System.Collections.ArrayList(current.KerberosGlobalAcl);
                System.Collections.ArrayList indexesOfInvalidItems = new System.Collections.ArrayList();
                for (int i = 0; i < kerb.Count; i++)
                {
                    try
                    {
                        string sid = ((new NTAccount((string)kerb[i])).Translate(typeof(SecurityIdentifier))).ToString();
                        securityDescriptorBuilder.Append("(A;;LCSWRP;;;" + sid + ")");
                    }
                    catch (ArgumentException) // invalid account, do not consider it
                    {
                        indexesOfInvalidItems.Add(i);
                    }
                    catch (IdentityNotMappedException)
                    {
                        indexesOfInvalidItems.Add(i);
                    }
                }

                //remove invalid items based on indexesOfInvalidItems
                for (int i = indexesOfInvalidItems.Count - 1; i >= 0; i--)
                {
                    kerb.RemoveAt((int)indexesOfInvalidItems[i]);
                }

                // rebuild the ACL, taking care not to leave it null
                if (kerb.Count <= 0)
                {
                    current.KerberosGlobalAcl = new string[] { "" };
                }
                else
                {
                    current.KerberosGlobalAcl = (string[])kerb.ToArray(typeof(string));
                }

                IntPtr securityDescriptor;
                int    size = 0;

                // call external function for transformig String SecurityDescriptors
                // into their internal representation
#pragma warning suppress 56523
                bool ret = SafeNativeMethods.ConvertStringSecurityDescriptorToSecurityDescriptor(
                    securityDescriptorBuilder.ToString(),
                    1, /*
                        * must be SDDL_REVISION_1 == 1 always
                        */
                    out securityDescriptor,
                    out size
                    );
                if (!ret)
                {
                    return(IntPtr.Zero);
                }
                return(securityDescriptor);
            }
            return(IntPtr.Zero);
        }