private void HandleCheckBoxClick(CheckBox source, AceType aceType, AceRights aceRight) { foreach (var ace in acl) { if (ace.AceType == aceType && ace.AccountSID == selectedUser) { if (source.Checked) { ace.Add(aceRight); } else { ace.Remove(aceRight); } return; } } // The ace type doesn't exist var newAce = new AccessControlEntry(selectedUser) { AceType = aceType }; newAce.Add(aceRight); acl.Add(newAce); }
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(); } } }
private void HandleCheckBoxClick(CheckBox source, AceType aceType, AceRights aceRight) { foreach (AccessControlEntry ace in this.acl) { if (ace.AceType == aceType && ace.AccountSID == this.selectedUser) { if (source.Checked) { ace.Add(aceRight); } else { ace.Remove(aceRight); } return; } } // The ace type doesn't exist AccessControlEntry newAce = new AccessControlEntry(this.selectedUser); newAce.AceType = aceType; newAce.Add(aceRight); this.acl.Add(newAce); }