Exemplo n.º 1
0
        public MainForm(NamespaceManagerAction action, string url)
        {
            nsManager = new HttpApi();
            InitializeComponent();

            this.action = action;
            this.initialUrl = url;
        }
Exemplo n.º 2
0
        public static ActionResult AddNamespace(Session session)
        {
            session.Log("Begin AddNamespace");
            HttpApi nsManager = null;
            try
            {
                nsManager = new HttpApi();
                List<SecurityIdentity> userList = new List<SecurityIdentity>();
                Dictionary<string, SecurityDescriptor> nsTable = nsManager.QueryHttpNamespaceAcls();

                string url = "http://+:8888/";

                SecurityDescriptor newSd = new SecurityDescriptor();
                newSd.DACL = new AccessControlList();
                foreach (AccessControlEntry ace in newSd.DACL)
                {
                    if (!userList.Contains(ace.AccountSID))
                    {
                        userList.Add(ace.AccountSID);
                    }
                }

                try
                {
                    SecurityIdentity sid = SecurityIdentity.SecurityIdentityFromWellKnownSid(WELL_KNOWN_SID_TYPE.WinWorldSid);
                    if (!userList.Contains(sid))
                    {
                        AccessControlEntry ace = new AccessControlEntry(sid);
                        ace.AceType = AceType.AccessAllowed;
                        ace.Add(AceRights.GenericAll);
                        ace.Add(AceRights.GenericExecute);
                        ace.Add(AceRights.GenericRead);
                        ace.Add(AceRights.GenericWrite);
                        newSd.DACL.Add(ace);
                        userList.Add(sid);
                    }
                }
                catch (Exception ex)
                {
                    session.Log("User or group name was not found. " + ex.Message);
                    return ActionResult.Failure;
                }

                // If entry already exists, rebuild it
                // as security settings could be wrong
                if (nsTable.ContainsKey(url))
                {
                    AccessControlList original = nsTable[url].DACL;
                    bool removed = false;

                    try
                    {
                        nsManager.RemoveHttpHamespaceAcl(url);
                        removed = true;
                        nsTable[url].DACL = newSd.DACL;
                        nsManager.SetHttpNamespaceAcl(url, nsTable[url]);
                    }
                    catch (Exception ex)
                    {
                        session.Log("Error Setting ACL. " + ex.Message);
                        if (removed)
                        {
                            try
                            {
                                nsTable[url].DACL = original;
                                nsManager.SetHttpNamespaceAcl(url, nsTable[url]);
                            }
                            catch (Exception ex2)
                            {
                                session.Log("Unable to Restore Original ACL, ACL may be corrupt. " + ex2.Message);
                                return ActionResult.Failure;
                            }
                        }

                        session.Log("Original ACL restored.");
                        return ActionResult.Failure;
                    }
                }
                else
                {
                    try
                    {
                        nsManager.SetHttpNamespaceAcl(url, newSd);
                        nsTable.Add(url, newSd);
                    }
                    catch (Exception ex)
                    {
                        session.Log("Error Adding ACL. " + ex.Message);
                        return ActionResult.Failure;
                    }
                }

                return ActionResult.Success;
            }
            finally
            {
                if (nsManager != null)
                {
                    nsManager.Dispose();
                }
            }
        }
Exemplo n.º 3
0
        public static ActionResult RemoveNamespace(Session session)
        {
            session.Log("Begin RemoveNamespace");

            HttpApi nsManager = null;
            try
            {
                nsManager = new HttpApi();
                Dictionary<string, SecurityDescriptor> nsTable = nsManager.QueryHttpNamespaceAcls();

                string url = "http://+:8888/";
                if (nsTable.ContainsKey(url))
                {
                    try
                    {
                        nsManager.RemoveHttpHamespaceAcl(url);
                    }
                    catch (Exception ex)
                    {
                        session.Log("Error removing ACL. " + ex.Message);
                        return ActionResult.Failure;
                    }
                }

                return ActionResult.Success;
            }
            finally
            {
                if (nsManager != null)
                {
                    nsManager.Dispose();
                }
            }
        }
Exemplo n.º 4
0
 public MainForm()
 {
     nsManager = new HttpApi();
     InitializeComponent();
 }
Exemplo n.º 5
0
        public Dictionary <string, SecurityDescriptor> QueryHttpNamespaceAcls()
        {
            Dictionary <string, SecurityDescriptor> nsTable = new Dictionary <string, SecurityDescriptor>();

            HTTP_SERVICE_CONFIG_URLACL_QUERY query = new HTTP_SERVICE_CONFIG_URLACL_QUERY();

            query.QueryDesc = HTTP_SERVICE_CONFIG_QUERY_TYPE.HttpServiceConfigQueryNext;

            IntPtr pQuery = Marshal.AllocHGlobal(Marshal.SizeOf(query));

            try
            {
                uint retval = NO_ERROR;
                for (query.dwToken = 0; true; query.dwToken++)
                {
                    Marshal.StructureToPtr(query, pQuery, false);

                    try
                    {
                        uint returnSize = 0;

                        // Get Size
                        retval = HttpQueryServiceConfiguration(IntPtr.Zero, HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, pQuery, (uint)Marshal.SizeOf(query), IntPtr.Zero, 0, ref returnSize, IntPtr.Zero);

                        if (retval == ERROR_NO_MORE_ITEMS)
                        {
                            break;
                        }
                        if (retval != ERROR_INSUFFICIENT_BUFFER)
                        {
                            throw new Exception("HttpQueryServiceConfiguration returned unexpected error code.");
                        }

                        IntPtr pConfig = Marshal.AllocHGlobal((IntPtr)returnSize);

                        try
                        {
                            retval = HttpApi.HttpQueryServiceConfiguration(IntPtr.Zero, HTTP_SERVICE_CONFIG_ID.HttpServiceConfigUrlAclInfo, pQuery, (uint)Marshal.SizeOf(query), pConfig, returnSize, ref returnSize, IntPtr.Zero);

                            if (retval == NO_ERROR)
                            {
                                HTTP_SERVICE_CONFIG_URLACL_SET config = (HTTP_SERVICE_CONFIG_URLACL_SET)Marshal.PtrToStructure(pConfig, typeof(HTTP_SERVICE_CONFIG_URLACL_SET));

                                nsTable.Add(config.KeyDesc.pUrlPrefix, SecurityDescriptor.SecurityDescriptorFromString(config.ParamDesc.pStringSecurityDescriptor));
                            }
                        }
                        finally
                        {
                            Marshal.FreeHGlobal(pConfig);
                        }
                    }
                    finally
                    {
                        Marshal.DestroyStructure(pQuery, typeof(HTTP_SERVICE_CONFIG_URLACL_QUERY));
                    }
                }

                if (retval != ERROR_NO_MORE_ITEMS)
                {
                    throw new Exception("HttpQueryServiceConfiguration returned unexpected error code.");
                }
            }
            finally
            {
                Marshal.FreeHGlobal(pQuery);
            }

            return(nsTable);
        }
Exemplo n.º 6
0
 protected void Dispose(bool p)
 {
     HttpApi.HttpTerminate(HttpApi.HTTP_INITIALIZE_CONFIG, IntPtr.Zero);
 }