public override string Execute(string[] args, UUID fromAgentID) { UUID rootID; Primitive rootPrim; List <Primitive> childPrims; List <uint> localIDs = new List <uint>(); // Reset class-wide variables PermsSent = false; Objects.Clear(); Perms = PermissionMask.None; PermCount = 0; if (args.Length < 1 || args.Length > 4) { return("Usage prim-uuid [copy] [mod] [xfer]"); } if (!UUID.TryParse(args[0], out rootID)) { return("Usage prim-uuid [copy] [mod] [xfer]"); } for (int i = 1; i < args.Length; i++) { switch (args[i].ToLower()) { case "copy": Perms |= PermissionMask.Copy; break; case "mod": Perms |= PermissionMask.Modify; break; case "xfer": Perms |= PermissionMask.Transfer; break; default: return("Usage prim-uuid [copy] [mod] [xfer]"); } } Logger.DebugLog("Using PermissionMask: " + Perms.ToString(), Client); // Find the requested prim rootPrim = Client.Network.CurrentSim.ObjectsPrimitives.Find(delegate(Primitive prim) { return(prim.ID == rootID); }); if (rootPrim == null) { return("Cannot find requested prim " + rootID.ToString()); } else { Logger.DebugLog("Found requested prim " + rootPrim.ID.ToString(), Client); } if (rootPrim.ParentID != 0) { // This is not actually a root prim, find the root if (!Client.Network.CurrentSim.ObjectsPrimitives.TryGetValue(rootPrim.ParentID, out rootPrim)) { return("Cannot find root prim for requested object"); } else { Logger.DebugLog("Set root prim to " + rootPrim.ID.ToString(), Client); } } // Find all of the child objects linked to this root childPrims = Client.Network.CurrentSim.ObjectsPrimitives.FindAll(delegate(Primitive prim) { return(prim.ParentID == rootPrim.LocalID); }); // Build a dictionary of primitives for referencing later Objects[rootPrim.ID] = rootPrim; for (int i = 0; i < childPrims.Count; i++) { Objects[childPrims[i].ID] = childPrims[i]; } // Build a list of all the localIDs to set permissions for localIDs.Add(rootPrim.LocalID); for (int i = 0; i < childPrims.Count; i++) { localIDs.Add(childPrims[i].LocalID); } // Go through each of the three main permissions and enable or disable them #region Set Linkset Permissions PermCount = 0; if ((Perms & PermissionMask.Modify) == PermissionMask.Modify) { Client.Objects.SetPermissions(Client.Network.CurrentSim, localIDs, PermissionWho.NextOwner, PermissionMask.Modify, true); } else { Client.Objects.SetPermissions(Client.Network.CurrentSim, localIDs, PermissionWho.NextOwner, PermissionMask.Modify, false); } PermsSent = true; if (!GotPermissionsEvent.WaitOne(1000 * 30, false)) { return("Failed to set the modify bit, permissions in an unknown state"); } PermCount = 0; if ((Perms & PermissionMask.Copy) == PermissionMask.Copy) { Client.Objects.SetPermissions(Client.Network.CurrentSim, localIDs, PermissionWho.NextOwner, PermissionMask.Copy, true); } else { Client.Objects.SetPermissions(Client.Network.CurrentSim, localIDs, PermissionWho.NextOwner, PermissionMask.Copy, false); } PermsSent = true; if (!GotPermissionsEvent.WaitOne(1000 * 30, false)) { return("Failed to set the copy bit, permissions in an unknown state"); } PermCount = 0; if ((Perms & PermissionMask.Transfer) == PermissionMask.Transfer) { Client.Objects.SetPermissions(Client.Network.CurrentSim, localIDs, PermissionWho.NextOwner, PermissionMask.Transfer, true); } else { Client.Objects.SetPermissions(Client.Network.CurrentSim, localIDs, PermissionWho.NextOwner, PermissionMask.Transfer, false); } PermsSent = true; if (!GotPermissionsEvent.WaitOne(1000 * 30, false)) { return("Failed to set the transfer bit, permissions in an unknown state"); } #endregion Set Linkset Permissions // Check each prim for task inventory and set permissions on the task inventory int taskItems = 0; foreach (Primitive prim in Objects.Values) { if ((prim.Flags & PrimFlags.InventoryEmpty) == 0) { List <InventoryBase> items = Client.Inventory.GetTaskInventory(prim.ID, prim.LocalID, 1000 * 30); if (items != null) { for (int i = 0; i < items.Count; i++) { if (!(items[i] is InventoryFolder)) { InventoryItem item = (InventoryItem)items[i]; item.Permissions.NextOwnerMask = Perms; Client.Inventory.UpdateTaskInventory(prim.LocalID, item); ++taskItems; } } } } } return("Set permissions to " + Perms.ToString() + " on " + localIDs.Count + " objects and " + taskItems + " inventory items"); }
public override CmdResult ExecuteRequest(CmdRequest args) { bool permsSent = false; int permCount = 0; AutoResetEvent GotPermissionsEvent = new AutoResetEvent(false); UUID selectedObject = UUID.Zero; Dictionary <UUID, Primitive> objects = new Dictionary <UUID, Primitive>(); PermissionMask perms = PermissionMask.None; EventHandler <ObjectPropertiesEventArgs> callback = new EventHandler <ObjectPropertiesEventArgs>((s, e) => { if (permsSent) { if (objects.ContainsKey(e.Properties.ObjectID)) { // FIXME: Confirm the current operation against properties.Permissions.NextOwnerMask ++permCount; if (permCount >= objects.Count) { GotPermissionsEvent.Set(); } } } }); try { Client.Objects.ObjectProperties += callback; // Reset class-wide variables permsSent = false; objects.Clear(); perms = PermissionMask.None; permCount = 0; if (args.Length < 1 || args.Length > 4) { return(ShowUsage()); //"Usage prim-uuid [copy] [mod] [xfer]"; } int argsUsed; List <SimObject> PS = WorldSystem.GetSingleArg(args, out argsUsed); if (IsEmpty(PS)) { return(Failure("Cannot find objects from " + args.str)); } for (int i = argsUsed; i < args.Length; i++) { switch (args[i].ToLower()) { case "copy": perms |= PermissionMask.Copy; break; case "mod": perms |= PermissionMask.Modify; break; case "xfer": perms |= PermissionMask.Transfer; break; default: return(ShowUsage()); //"Usage prim-uuid [copy] [mod] [xfer]"; } } WriteLine("Using PermissionMask: " + perms.ToString()); // Find the requested prim foreach (var rPrim in PS) { Primitive rootPrim = rPrim.Prim; Simulator curSim = WorldSystem.GetSimulator(rootPrim); WriteLine("Found requested prim " + rootPrim.ID.ToString()); if (rootPrim.ParentID != 0) { // This is not actually a root prim, find the root if (!curSim.ObjectsPrimitives.TryGetValue(rootPrim.ParentID, out rootPrim)) { Failure("Cannot find root prim for requested object"); } else { Logger.DebugLog("Set root prim to " + rootPrim.ID.ToString(), Client); } } List <Primitive> childPrims; // Find all of the child objects linked to this root childPrims = curSim.ObjectsPrimitives.FindAll( delegate(Primitive prim) { return(prim.ParentID == rootPrim.LocalID); }); // Build a dictionary of primitives for referencing later objects[rootPrim.ID] = rootPrim; for (int i = 0; i < childPrims.Count; i++) { objects[childPrims[i].ID] = childPrims[i]; } List <uint> localIDs = new List <uint>(); // Build a list of all the localIDs to set permissions for localIDs.Add(rootPrim.LocalID); for (int i = 0; i < childPrims.Count; i++) { localIDs.Add(childPrims[i].LocalID); } // Go through each of the three main permissions and enable or disable them #region Set Linkset Permissions permCount = 0; if ((perms & PermissionMask.Modify) == PermissionMask.Modify) { Client.Objects.SetPermissions(curSim, localIDs, PermissionWho.NextOwner, PermissionMask.Modify, true); } else { Client.Objects.SetPermissions(curSim, localIDs, PermissionWho.NextOwner, PermissionMask.Modify, false); } permsSent = true; if (!GotPermissionsEvent.WaitOne(1000 * 30, false)) { Failure("failed to set the modify bit, permissions in an unknown state"); } permCount = 0; if ((perms & PermissionMask.Copy) == PermissionMask.Copy) { Client.Objects.SetPermissions(curSim, localIDs, PermissionWho.NextOwner, PermissionMask.Copy, true); } else { Client.Objects.SetPermissions(curSim, localIDs, PermissionWho.NextOwner, PermissionMask.Copy, false); } permsSent = true; if (!GotPermissionsEvent.WaitOne(1000 * 30, false)) { Failure("failed to set the copy bit, permissions in an unknown state"); } permCount = 0; if ((perms & PermissionMask.Transfer) == PermissionMask.Transfer) { Client.Objects.SetPermissions(curSim, localIDs, PermissionWho.NextOwner, PermissionMask.Transfer, true); } else { Client.Objects.SetPermissions(curSim, localIDs, PermissionWho.NextOwner, PermissionMask.Transfer, false); } permsSent = true; if (!GotPermissionsEvent.WaitOne(1000 * 30, false)) { Failure("failed to set the transfer bit, permissions in an unknown state"); } #endregion Set Linkset Permissions // Check each prim for task inventory and set permissions on the task inventory int taskItems = 0; foreach (Primitive prim in objects.Values) { if ((prim.Flags & PrimFlags.InventoryEmpty) == 0) { List <InventoryBase> items = Client.Inventory.GetTaskInventory(prim.ID, prim.LocalID, 1000 * 30); if (items != null) { for (int i = 0; i < items.Count; i++) { if (!(items[i] is InventoryFolder)) { InventoryItem item = (InventoryItem)items[i]; item.Permissions.NextOwnerMask = perms; Client.Inventory.UpdateTaskInventory(prim.LocalID, item); ++taskItems; } } } } } AddSuccess("Set permissions to " + perms.ToString() + " on " + localIDs.Count + " objects and " + taskItems + " inventory items"); } } finally { Client.Objects.ObjectProperties -= callback; } return(SuccessOrFailure()); }
public override string Execute(string[] args, UUID fromAgentID) { UUID rootID; Primitive rootPrim; List<Primitive> childPrims; List<uint> localIDs = new List<uint>(); // Reset class-wide variables PermsSent = false; Objects.Clear(); Perms = PermissionMask.None; PermCount = 0; if (args.Length < 1 || args.Length > 4) return "Usage prim-uuid [copy] [mod] [xfer]"; if (!UUID.TryParse(args[0], out rootID)) return "Usage prim-uuid [copy] [mod] [xfer]"; for (int i = 1; i < args.Length; i++) { switch (args[i].ToLower()) { case "copy": Perms |= PermissionMask.Copy; break; case "mod": Perms |= PermissionMask.Modify; break; case "xfer": Perms |= PermissionMask.Transfer; break; default: return "Usage prim-uuid [copy] [mod] [xfer]"; } } Logger.DebugLog("Using PermissionMask: " + Perms.ToString(), Client); // Find the requested prim rootPrim = Client.Network.CurrentSim.ObjectsPrimitives.Find(delegate(Primitive prim) { return prim.ID == rootID; }); if (rootPrim == null) return "Cannot find requested prim " + rootID.ToString(); else Logger.DebugLog("Found requested prim " + rootPrim.ID.ToString(), Client); if (rootPrim.ParentID != 0) { // This is not actually a root prim, find the root if (!Client.Network.CurrentSim.ObjectsPrimitives.TryGetValue(rootPrim.ParentID, out rootPrim)) return "Cannot find root prim for requested object"; else Logger.DebugLog("Set root prim to " + rootPrim.ID.ToString(), Client); } // Find all of the child objects linked to this root childPrims = Client.Network.CurrentSim.ObjectsPrimitives.FindAll(delegate(Primitive prim) { return prim.ParentID == rootPrim.LocalID; }); // Build a dictionary of primitives for referencing later Objects[rootPrim.ID] = rootPrim; for (int i = 0; i < childPrims.Count; i++) Objects[childPrims[i].ID] = childPrims[i]; // Build a list of all the localIDs to set permissions for localIDs.Add(rootPrim.LocalID); for (int i = 0; i < childPrims.Count; i++) localIDs.Add(childPrims[i].LocalID); // Go through each of the three main permissions and enable or disable them #region Set Linkset Permissions PermCount = 0; if ((Perms & PermissionMask.Modify) == PermissionMask.Modify) Client.Objects.SetPermissions(Client.Network.CurrentSim, localIDs, PermissionWho.NextOwner, PermissionMask.Modify, true); else Client.Objects.SetPermissions(Client.Network.CurrentSim, localIDs, PermissionWho.NextOwner, PermissionMask.Modify, false); PermsSent = true; if (!GotPermissionsEvent.WaitOne(1000 * 30, false)) return "Failed to set the modify bit, permissions in an unknown state"; PermCount = 0; if ((Perms & PermissionMask.Copy) == PermissionMask.Copy) Client.Objects.SetPermissions(Client.Network.CurrentSim, localIDs, PermissionWho.NextOwner, PermissionMask.Copy, true); else Client.Objects.SetPermissions(Client.Network.CurrentSim, localIDs, PermissionWho.NextOwner, PermissionMask.Copy, false); PermsSent = true; if (!GotPermissionsEvent.WaitOne(1000 * 30, false)) return "Failed to set the copy bit, permissions in an unknown state"; PermCount = 0; if ((Perms & PermissionMask.Transfer) == PermissionMask.Transfer) Client.Objects.SetPermissions(Client.Network.CurrentSim, localIDs, PermissionWho.NextOwner, PermissionMask.Transfer, true); else Client.Objects.SetPermissions(Client.Network.CurrentSim, localIDs, PermissionWho.NextOwner, PermissionMask.Transfer, false); PermsSent = true; if (!GotPermissionsEvent.WaitOne(1000 * 30, false)) return "Failed to set the transfer bit, permissions in an unknown state"; #endregion Set Linkset Permissions // Check each prim for task inventory and set permissions on the task inventory int taskItems = 0; foreach (Primitive prim in Objects.Values) { if ((prim.Flags & PrimFlags.InventoryEmpty) == 0) { List<InventoryBase> items = Client.Inventory.GetTaskInventory(prim.ID, prim.LocalID, 1000 * 30); if (items != null) { for (int i = 0; i < items.Count; i++) { if (!(items[i] is InventoryFolder)) { InventoryItem item = (InventoryItem)items[i]; item.Permissions.NextOwnerMask = Perms; Client.Inventory.UpdateTaskInventory(prim.LocalID, item); ++taskItems; } } } } } return "Set permissions to " + Perms.ToString() + " on " + localIDs.Count + " objects and " + taskItems + " inventory items"; }
/// <summary> /// Check whether the user has specified permission to access the feature. /// </summary> /// <param name="userId">An integer value of the user id.</param> /// <param name="featureCode">A string value of the feature code.</param> /// <param name="mask">The permission mask to define the create/edit/remove/... permissions.</param> /// <returns>It will return true if the user has the specified permission, otherwise it will return false.</returns> public bool HasFeaturePermission(int userId, string featureCode, PermissionMask mask) { bool hasPerm = false; var feature = GetFeature(featureCode); if (feature != null) { hasPerm = ValidatePermission(userId, feature.Id, ResourceType.Feature, mask); } _userActionTrackingBLL.Create(userId, Model.UsageTracking.ActionType.CheckPermission, ResourceType.Feature, feature.Id, 1, ActionStatus.Normal, mask.ToString()); return(hasPerm); }