public static void CreateMQ(string mqPath) { var mq = System.Messaging.MessageQueue.Create(mqPath, false); var list = new AccessControlList() { }; list.Add(new AccessControlEntry() { EntryType = AccessControlEntryType.Allow, GenericAccessRights = GenericAccessRights.All, StandardAccessRights = StandardAccessRights.All, Trustee = new Trustee("ANONYMOUS LOGON") }); list.Add(new AccessControlEntry() { EntryType = AccessControlEntryType.Allow, GenericAccessRights = GenericAccessRights.All, StandardAccessRights = StandardAccessRights.All, Trustee = new Trustee("Everyone") }); mq.SetPermissions(list); mq.Label = mqPath; }
public void SetPermissions_Accesscontrollist() { // <snippet26> // Connect to a queue on the local computer. MessageQueue queue = new MessageQueue(".\\exampleQueue"); // Create an AccessControlList. AccessControlList list = new AccessControlList(); // Create a new trustee to represent the "Everyone" user group. Trustee tr = new Trustee("Everyone"); // Create an AccessControlEntry, granting the trustee read access to // the queue. AccessControlEntry entry = new AccessControlEntry( tr, GenericAccessRights.Read, StandardAccessRights.Read, AccessControlEntryType.Allow); // Add the AccessControlEntry to the AccessControlList. list.Add(entry); // Apply the AccessControlList to the queue. queue.SetPermissions(list); // </snippet26> }
private void ButtonAdd_Click(object sender, EventArgs e) { if (InputBox.Show("Add User or Group", "Enter the User or Group Name:", out var accountName) == DialogResult.OK) { try { var sid = SecurityIdentity.SecurityIdentityFromName(accountName); if (MessageBox.Show(string.Format("Add user or group: {0}?", sid.Name), "User or Group Found", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) { if (!userList.Contains(sid)) { var ace = new AccessControlEntry(sid) { AceType = AceType.AccessAllowed }; acl.Add(ace); userList.Add(sid); ListUsersAndGroups.Items.Add(sid); ListUsersAndGroups.SelectedItem = sid; } else { MessageBox.Show("The selected user or group already exists.", "Duplicate User or Group", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } } catch (Exception ex) { MessageBox.Show("User or group name was not found. " + ex.Message, "User or Group Not Found", MessageBoxButtons.OK, MessageBoxIcon.Warning); } } }
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 void AddQueue(string name) { var queue = MessageQueue.Create(@".\Private$\" + name); var list = new AccessControlList(); var entry = new AccessControlEntry( new Trustee("Wszyscy"), GenericAccessRights.All, StandardAccessRights.All, AccessControlEntryType.Allow); list.Add(entry); queue.SetPermissions(list); _queues.Add(queue); }
protected void btnAdd_Click(object sender, System.EventArgs e) { AccessControlList ACLr = (AccessControlList)ViewState["ACL"]; AccessControlEntry ACEr; string sRight = ""; switch (ddRights.SelectedValue) { case "1": sRight = "Read"; break; case "2": sRight = "Write"; break; case "3": sRight = "Admin"; break; default: break; } if (ddGroups.SelectedValue == "0") { ACEr = new AccessControlEntry(ddUsers.SelectedValue, sRight, (rbList.SelectedValue == "0")); } else { int iPrincipalId = (ddUsers.SelectedValue == "0") ? int.Parse(ddGroups.SelectedValue) : int.Parse(ddUsers.SelectedValue); ACEr = new AccessControlEntry(iPrincipalId, sRight, (rbList.SelectedValue == "0")); } ACLr.Add(ACEr); ViewState["ACL"] = ACLr; ListItem _li = ddGroups.SelectedItem; if (_li != null) { BindUsers(int.Parse(_li.Value)); } BinddgMembers(); }
/// <summary> /// LOCAL ONLY - Creates a new MessageQueue if none exists, or returns existing MessageQueue /// </summary> /// <param name="messageQueueName"></param> /// <param name="privateQueue"></param> /// <returns></returns> public static MessageQueue CreateMessageQueue(string messageQueueName, bool privateQueue = true) { AccessControlList acl = new AccessControlList(); Trustee tr = new Trustee("ANONYMOUS LOGON"); AccessControlEntry entry = new AccessControlEntry(tr, GenericAccessRights.All, StandardAccessRights.All, AccessControlEntryType.Allow); acl.Add(entry); if (privateQueue) { if (!MessageQueue.Exists(".\\private$\\" + messageQueueName)) { // Create the queue if it does not exist. MessageQueue myMQ = MessageQueue.Create(".\\private$\\" + messageQueueName); myMQ.SetPermissions(acl); return(myMQ); } else { return(new MessageQueue(".\\private$\\" + messageQueueName)); } } else { if (!MessageQueue.Exists(".\\" + messageQueueName)) { // Create the queue if it does not exist. MessageQueue myMQ = MessageQueue.Create(".\\" + messageQueueName); myMQ.SetPermissions(acl); return(myMQ); } else { return(new MessageQueue(".\\" + messageQueueName)); } } }