Beispiel #1
0
 public Permissions(uint baseMask, uint everyoneMask, uint groupMask, uint nextOwnerMask, uint ownerMask)
 {
     BaseMask = (PermissionMask)baseMask;
     EveryoneMask = (PermissionMask)everyoneMask;
     GroupMask = (PermissionMask)groupMask;
     NextOwnerMask = (PermissionMask)nextOwnerMask;
     OwnerMask = (PermissionMask)ownerMask;
 }
 /// <summary>
 /// Returns a 3-character summary of the PermissionMask
 /// CMT if the mask allows copy, mod and transfer
 /// -MT if it disallows copy
 /// --T if it only allows transfer
 /// --- if it disallows everything
 /// </summary>
 /// <param name="mask"></param>
 /// <returns></returns>
 private static string PermMaskString(PermissionMask mask) {
     string str = "";
     if (((uint)mask | (uint)PermissionMask.Copy) == (uint)PermissionMask.Copy)
         str += "C";
     else
         str += "-";
     if (((uint)mask | (uint)PermissionMask.Modify) == (uint)PermissionMask.Modify)
         str += "M";
     else
         str += "-";
     if (((uint)mask | (uint)PermissionMask.Transfer) == (uint)PermissionMask.Transfer)
         str += "T";
     else
         str += "-";
     return str;
 }
 /// <summary>
 /// Deserialize the message
 /// </summary>
 /// <param name="map">An <see cref="OSDMap"/> containing the data</param>
 public void Deserialize(OSDMap map)
 {
     FolderID = map["folder_id"].AsUUID();
     AssetType = Utils.StringToAssetType(map["asset_type"].AsString());
     InventoryType = Utils.StringToInventoryType(map["inventory_type"].AsString());
     Name = map["name"].AsString();
     Description = map["description"].AsString();
     EveryoneMask = (PermissionMask)map["everyone_mask"].AsInteger();
     GroupMask = (PermissionMask)map["group_mask"].AsInteger();
     NextOwnerMask = (PermissionMask)map["next_owner_mask"].AsInteger();
 }
Beispiel #4
0
        /// <summary>
        /// Creates a wearable inventory item referencing an asset upload. 
        /// Second Life v1.9 uses this method to create wearable inventory items.
        /// </summary>
        /// <param name="parentFolder"></param>
        /// <param name="name"></param>
        /// <param name="description"></param>
        /// <param name="type"></param>
        /// <param name="wearableType"></param>
        /// <param name="invType"></param>
        /// <param name="nextOwnerMask"></param>
        /// <param name="callback"></param>
        /// <param name="assetTransactionID">Proper use is to upload the inventory's asset first, then provide the Asset's TransactionID here.</param>
        public void RequestCreateItem(UUID parentFolder, string name, string description, AssetType type, UUID assetTransactionID,
            InventoryType invType, WearableType wearableType, PermissionMask nextOwnerMask, ItemCreatedCallback callback)
        {
            CreateInventoryItemPacket create = new CreateInventoryItemPacket();
            create.AgentData.AgentID = _Agents.AgentID;
            create.AgentData.SessionID = _Agents.SessionID;

            create.InventoryBlock.CallbackID = RegisterItemCreatedCallback(callback);
            create.InventoryBlock.FolderID = parentFolder;
            create.InventoryBlock.TransactionID = assetTransactionID;
            create.InventoryBlock.NextOwnerMask = (uint)nextOwnerMask;
            create.InventoryBlock.Type = (sbyte)type;
            create.InventoryBlock.InvType = (sbyte)invType;
            create.InventoryBlock.WearableType = (byte)wearableType;
            create.InventoryBlock.Name = Utils.StringToBytes(name);
            create.InventoryBlock.Description = Utils.StringToBytes(description);

            _Network.SendPacket(create);
        }
Beispiel #5
0
 public static bool HasPermissions(PermissionMask perms, PermissionMask checkPerms)
 {
     return((perms & checkPerms) == checkPerms);
 }
Beispiel #6
0
        public static bool checkPerms(BotClient Client, SimObject exportPrim, OutputDelegate Failure, bool mustModify)
        {
            if (exportPrim != null)
            {
                var Properties = exportPrim.Properties;
                if (Properties == null)
                {
                    Client.Objects.RequestObjectPropertiesFamily(exportPrim.GetSimulator(), exportPrim.ID, true);
                    Failure("No props yet for " + named(exportPrim));
                    return(false);
                }
                // Check for export permission first
                //GotPermissions = false;
                //
                //if (!GotPermissions)
                // {
                //   Properties = exportPrim.Properties ?? new Primitive.ObjectProperties();
                //}
                //   GotPermissionsEvent.WaitOne(1000 * 10, false);
                if (Properties.OwnerID != Client.Self.AgentID &&
                    Properties.OwnerID != Client.MasterKey &&
                    Properties.GroupID != Client.Self.ActiveGroup)
                {
                    Failure("That object is owned by " + Properties.OwnerID + ", we don't have permission " +
                            "to export " + named(exportPrim));
                }

                SimAvatarClient theAvatar = Client.TheSimAvatar;
                PermissionWho   pw        = theAvatar.EffectivePermissionWho(exportPrim);
                PermissionMask  pm        = theAvatar.EffectivePermissionsMask(exportPrim);

                bool modify = Permissions.HasPermissions(pm, PermissionMask.Modify);

                bool cmt = Permissions.HasPermissions(pm, PermissionMask.Copy) ||
                           Permissions.HasPermissions(pm, PermissionMask.Modify) ||
                           Permissions.HasPermissions(pm, PermissionMask.Transfer);

                if (mustModify)
                {
                    if (!modify)
                    {
                        Failure("ObjPerms NOMODIFY " + pm + " for " + pw + " on " + named(exportPrim));
                        return(false);
                    }
                }
                if (!cmt)
                {
                    Failure("ObjPerms " + pm + " for " + pw + " on " + named(exportPrim));
                    return(false);
                }

                //List<SimObject> family = new List<SimObject>();
                //family.Add(exportPrim);
                //family.AddRange(exportPrim.Children);

                /*bool complete = RequestObjectProperties(family, 250, exportPrim.GetSimulator());
                 * exportedPrims.AddRange(family);
                 *
                 * if (!complete)
                 * {
                 *  Logger.Log("Warning: Unable to retrieve full properties for:", Helpers.LogLevel.Warning, Client);
                 *  foreach (UUID uuid in PrimsWaiting.Keys)
                 *      Logger.Log(uuid.ToString(), Helpers.LogLevel.Warning, Client);
                 * }
                 * return true;*/
            }
            return(true);
        }
Beispiel #7
0
 public static bool HasPermission(this PermissionMask mask, PermissionMask permission)
 {
     return((mask & permission) == permission);
 }
        private void SetPerms(Simulator CurrentSim, List <uint> localIDs, PermissionWho who, PermissionMask Perms,
                              bool tf)
        {
            try
            {
                if (!skipPerms)
                {
                    PermCount = 0;

                    if ((Perms & PermissionMask.Modify) == PermissionMask.Modify)
                    {
                        Client.Objects.SetPermissions(CurrentSim, localIDs, who, PermissionMask.Modify,
                                                      tf);
                    }
                    PermsSent = true;

                    //  if (!GotPermissionsEvent.WaitOne(1000 * 30, false))
                    //     return Failure("failed to set the modify bit, permissions in an unknown state";

                    PermCount = 0;
                    if ((Perms & PermissionMask.Copy) == PermissionMask.Copy)
                    {
                        Client.Objects.SetPermissions(CurrentSim, localIDs, who, PermissionMask.Copy,
                                                      tf);
                    }

                    PermsSent = true;

                    //  if (!GotPermissionsEvent.WaitOne(1000 * 30, false))
                    //   return Failure("failed to set the copy bit, permissions in an unknown state";

                    PermCount = 0;
                    if ((Perms & PermissionMask.Transfer) == PermissionMask.Transfer)
                    {
                        Client.Objects.SetPermissions(CurrentSim, localIDs, who, PermissionMask.Transfer,
                                                      tf);
                    }

                    PermsSent = true;

                    PermCount = 0;
                    if ((Perms & PermissionMask.Move) == PermissionMask.Move)
                    {
                        Client.Objects.SetPermissions(CurrentSim, localIDs, who, PermissionMask.Transfer,
                                                      tf);
                    }

                    PermsSent = true;
                }

                /*
                 * else
                 * {
                 *  Client.Objects.SetPermissions(CurrentSim, localIDs, PermissionWho.Owner, PermissionMask.All, true);
                 *  Client.Objects.SetPermissions(CurrentSim, localIDs, PermissionWho.Group, PermissionMask.Modify, true);
                 *  Client.Objects.SetPermissions(CurrentSim, localIDs, PermissionWho.Group, PermissionMask.All, true);
                 * }
                 * //  if (!GotPermissionsEvent.WaitOne(1000 * 30, false))
                 * //    return Failure("failed to set the transfer bit, permissions in an unknown state";
                 */
            }
            catch (Exception e)
            {
                DLRConsole.DebugWriteLine("ERROR {0}", e);
            }
        }
        public int RevokePermission(int userId, int resourceId, ResourceType resourceType, PermissionMask mask)
        {
            var masks = new List <PermissionMask>()
            {
                mask
            };

            return(RevokePermission(userId, resourceId, resourceType, masks));
        }
        public bool HasPermission(int userId, int resourceId, ResourceType resourceType, PermissionMask mask)
        {
            var userResourcePerm = GetPermission(userId, TokenType.User, resourceId, resourceType);

            Tracking(userId, ActionType.CheckPermission, resourceType, resourceId, (int)mask);

            return(_permCalculator.HasPermission(userResourcePerm.Permission, mask));
        }
 public bool HasUserRolePermission(int userId, int resourceId, ResourceType resourceType, PermissionMask mask)
 {
     return(ValidatePermission(userId, resourceId, resourceType, mask));
 }
        private bool ValidatePermission(RoleType roleId, int resourceId, ResourceType resourceType, PermissionMask mask)
        {
            if (roleId == RoleType.Administrator)
            {
                return(true);
            }

            var roleFeaturePerm = GetPermission((int)roleId, TokenType.Role, resourceId, resourceType);

            if (_permCalculator.HasPermission(roleFeaturePerm.Permission, mask))
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
        private bool ValidatePermission(int userId, int resourceId, ResourceType resourceType, PermissionMask mask)
        {
            bool hasPerm = false;
            var  roles   = GetRoles(userId);

            foreach (var role in roles)
            {
                //管理员具有所有权限
                if (role.RoleId == RoleType.Administrator)
                {
                    hasPerm = true;
                    break;
                }
                //交易员具有查看和执行交易指令的权限
                if (resourceType == ResourceType.TradeCommand && role.RoleId == RoleType.Dealer &&
                    (mask == PermissionMask.View || mask == PermissionMask.Execute)
                    )
                {
                    hasPerm = true;
                    break;
                }
                if (ValidatePermission(role.RoleId, resourceId, resourceType, mask))
                {
                    hasPerm = true;
                    break;
                }
            }

            return(hasPerm);
        }
 /// <summary>
 /// Check whether the role has the specified permission for the given resource.
 /// </summary>
 /// <param name="roleId">An integer value of the role id.</param>
 /// <param name="resourceId">An integer value of the resource id.</param>
 /// <param name="resourceType">An enum type of the resource type.</param>
 /// <param name="mask">An enum type of the permission.</param>
 /// <returns>It will return true if it has the permission, otherwise it will return false.</returns>
 public bool HasRolePermission(RoleType roleId, int resourceId, ResourceType resourceType, PermissionMask mask)
 {
     return(ValidatePermission(roleId, resourceId, resourceType, mask));
 }
Beispiel #15
0
 public static bool HasPermissions(PermissionMask perms, PermissionMask checkPerms)
 {
     return (perms & checkPerms) == checkPerms;
 }
Beispiel #16
0
 public void RequestCreateItem(LLUUID parentFolder, string name, string description, AssetType type, 
     InventoryType invType, PermissionMask nextOwnerMask, ItemCreatedCallback callback)
 {
     // Even though WearableType 0 is Shape, in this context it is treated as NOT_WEARABLE
     RequestCreateItem(parentFolder, name, description, type, invType, (WearableType)0, nextOwnerMask, 
         callback);
 }
 public int GetGrantPermission(int perm, PermissionMask mask)
 {
     return(_permCalculator.GrantPermission(perm, mask));
 }
Beispiel #18
0
 /// <summary>
 /// remove the permission: perm & ~rights. The same rights can be revoked repeatedly because only the bit is change after
 /// the calculation and its value is always 0.
 /// </summary>
 /// <param name="perm">The origin permission value.</param>
 /// <param name="mask">The rights.</param>
 /// <returns>A new permission value after removing the rights.</returns>
 public int RevokePermission(int perm, PermissionMask mask)
 {
     return(RemovePermission(perm, mask));
 }
 public int GetRevokePermission(int perm, PermissionMask mask)
 {
     return(_permCalculator.RevokePermission(perm, mask));
 }
Beispiel #20
0
        private void TraverseDir(InventoryNode node, string path)
        {
            var nodes = new List <InventoryNode>(node.Nodes.Values);

            foreach (InventoryNode n in nodes)
            {
                traversed++;
                try
                {
                    if (IsHandleCreated && (traversed % 13 == 0))
                    {
                        BeginInvoke(new MethodInvoker(() =>
                        {
                            lblStatus.Text = string.Format("Traversed {0} nodes...", traversed);
                        }));
                    }

                    if (n.Data is InventoryFolder)
                    {
                        WriteCSVLine("Folder", path, n.Data.Name, "", "", "", "");
                        TraverseDir(n, Path.Combine(path, METAboltInstance.SafeFileName(n.Data.Name)));
                    }
                    else
                    {
                        InventoryItem item      = (InventoryItem)n.Data;
                        string        creator   = item.CreatorID == UUID.Zero ? string.Empty : instance.Names.Get(item.CreatorID, true);
                        string        lastOwner = item.LastOwnerID == UUID.Zero ? string.Empty : instance.Names.Get(item.LastOwnerID, true);
                        string        type      = item.AssetType.ToString();
                        if (item.InventoryType == InventoryType.Wearable)
                        {
                            type = ((WearableType)item.Flags).ToString();
                        }
                        string created = item.CreationDate.ToString("yyyy-MM-dd HH:mm:ss");
                        WriteCSVLine(type, path, item.Name, item.Description, created, creator, lastOwner);

                        PermissionMask fullPerm = PermissionMask.Modify | PermissionMask.Copy | PermissionMask.Transfer;
                        if ((item.Permissions.OwnerMask & fullPerm) != fullPerm)
                        {
                            continue;
                        }

                        string filePartial = Path.Combine(path, METAboltInstance.SafeFileName(n.Data.Name));
                        string fullName    = folderName + filePartial;
                        switch (item.AssetType)
                        {
                        case AssetType.LSLText:
                            client.Settings.USE_ASSET_CACHE = false;
                            fullName += ".lsl";
                            break;

                        case AssetType.Notecard: fullName += ".txt"; break;

                        case AssetType.Texture: fullName += ".png"; break;

                        default: fullName += ".bin"; break;
                        }
                        string dirName = Path.GetDirectoryName(fullName);
                        bool   dateOK  = item.CreationDate > new DateTime(1970, 1, 2);

                        if (
                            (item.AssetType == AssetType.LSLText && cbScripts.Checked) ||
                            (item.AssetType == AssetType.Notecard && cbNoteCards.Checked) ||
                            (item.AssetType == AssetType.Texture && cbImages.Checked)
                            )
                        {
                            ListViewItem lvi = new ListViewItem();
                            lvi.Text = n.Data.Name;
                            lvi.Tag  = n.Data;
                            lvi.Name = n.Data.UUID.ToString();

                            ListViewItem.ListViewSubItem fileName = new ListViewItem.ListViewSubItem(lvi, filePartial);
                            lvi.SubItems.Add(fileName);

                            ListViewItem.ListViewSubItem status = new ListViewItem.ListViewSubItem(lvi, "Fetching asset");
                            lvi.SubItems.Add(status);

                            //bool cached = dateOK && File.Exists(fullName) && File.GetCreationTimeUtc(fullName) == item.CreationDate;

                            //if (cached)
                            //{
                            //    status.Text = "Cached";
                            //}

                            BeginInvoke(new MethodInvoker(() =>
                            {
                                lvwFiles.Items.Add(lvi);
                                lvwFiles.EnsureVisible(lvwFiles.Items.Count - 1);
                            }));

                            //if (cached) continue;

                            Asset receivedAsset = null;
                            using (AutoResetEvent done = new AutoResetEvent(false))
                            {
                                if (item.AssetType == AssetType.Texture)
                                {
                                    client.Assets.RequestImage(item.AssetUUID, (state, asset) =>
                                    {
                                        if (state == TextureRequestState.Finished && asset != null && asset.Decode())
                                        {
                                            receivedAsset = asset;
                                            done.Set();
                                        }
                                    });
                                }
                                else
                                {
                                    client.Assets.RequestInventoryAsset(item, true, (AssetDownload transfer, Asset asset) =>
                                    {
                                        if (transfer.Success)
                                        {
                                            receivedAsset = asset;
                                        }
                                        done.Set();
                                    }
                                                                        );
                                }

                                done.WaitOne(30 * 1000, false);
                            }

                            client.Settings.USE_ASSET_CACHE = true;

                            if (receivedAsset == null)
                            {
                                BeginInvoke(new MethodInvoker(() => status.Text = "Failed to fetch asset"));
                            }
                            else
                            {
                                BeginInvoke(new MethodInvoker(() => status.Text = "Saving..."));

                                try
                                {
                                    if (!Directory.Exists(dirName))
                                    {
                                        Directory.CreateDirectory(dirName);
                                    }

                                    switch (item.AssetType)
                                    {
                                    case AssetType.Notecard:
                                        AssetNotecard note = (AssetNotecard)receivedAsset;
                                        if (note.Decode())
                                        {
                                            File.WriteAllText(fullName, note.BodyText, System.Text.Encoding.UTF8);
                                            if (dateOK)
                                            {
                                                File.SetCreationTimeUtc(fullName, item.CreationDate);
                                                File.SetLastWriteTimeUtc(fullName, item.CreationDate);
                                            }
                                        }
                                        else
                                        {
                                            Logger.Log(string.Format("Falied to decode asset for '{0}' - {1}", item.Name, receivedAsset.AssetID), Helpers.LogLevel.Warning, client);
                                        }

                                        break;

                                    case AssetType.LSLText:
                                        AssetScriptText script = (AssetScriptText)receivedAsset;
                                        if (script.Decode())
                                        {
                                            File.WriteAllText(fullName, script.Source, System.Text.Encoding.UTF8);
                                            if (dateOK)
                                            {
                                                File.SetCreationTimeUtc(fullName, item.CreationDate);
                                                File.SetLastWriteTimeUtc(fullName, item.CreationDate);
                                            }
                                        }
                                        else
                                        {
                                            Logger.Log(string.Format("Falied to decode asset for '{0}' - {1}", item.Name, receivedAsset.AssetID), Helpers.LogLevel.Warning, client);
                                        }

                                        break;

                                    case AssetType.Texture:
                                        AssetTexture imgAsset = (AssetTexture)receivedAsset;
                                        var          img      = LoadTGAClass.LoadTGA(new MemoryStream(imgAsset.Image.ExportTGA()));
                                        img.Save(fullName, System.Drawing.Imaging.ImageFormat.Png);
                                        if (dateOK)
                                        {
                                            File.SetCreationTimeUtc(fullName, item.CreationDate);
                                            File.SetLastWriteTimeUtc(fullName, item.CreationDate);
                                        }
                                        break;
                                    }

                                    BeginInvoke(new MethodInvoker(() =>
                                    {
                                        fileName.Text  = fullName;
                                        status.Text    = "Saved";
                                        lblStatus.Text = string.Format("Saved {0} items", ++fetched);
                                    }));
                                }
                                catch (Exception ex)
                                {
                                    BeginInvoke(new MethodInvoker(() => status.Text = "Failed to save " + Path.GetFileName(fullName) + ": " + ex.Message));
                                }
                            }
                        }
                    }
                }
                catch { }
            }
        }
Beispiel #21
0
 public static bool HasPermission(this PermissionMask mask, PermissionMask permission)
 {
     return (mask & permission) == permission;
 }
Beispiel #22
0
        public override string Execute(string[] args, LLUUID fromAgentID)
        {
            LLUUID           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 (!LLUUID.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]");
                }
            }

            Client.DebugLog("Using PermissionMask: " + Perms.ToString());

            // Find the requested prim
            rootPrim = Client.Network.CurrentSim.Objects.Find(delegate(Primitive prim) { return(prim.ID == rootID); });
            if (rootPrim == null)
            {
                return("Cannot find requested prim " + rootID.ToString());
            }
            else
            {
                Client.DebugLog("Found requested prim " + rootPrim.ID.ToString());
            }

            if (rootPrim.ParentID != 0)
            {
                // This is not actually a root prim, find the root
                if (!Client.Network.CurrentSim.Objects.TryGetPrimitive(rootPrim.ParentID, out rootPrim))
                {
                    return("Cannot find root prim for requested object");
                }
                else
                {
                    Client.DebugLog("Set root prim to " + rootPrim.ID.ToString());
                }
            }

            // Find all of the child objects linked to this root
            childPrims = Client.Network.CurrentSim.Objects.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 & LLObject.ObjectFlags.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");
        }
Beispiel #23
0
 private static Enum Reperm(PermissionMask mask, ImportSettings settings)
 {
     if (settings.Contains("sameperms")) return mask;
     if (settings.Contains("+xfer+copy")) return mask | PermissionMask.Copy | PermissionMask.Transfer;
     return PermissionMask.All;
 }
Beispiel #24
0
 public void RequestCreateItem(UUID parentFolder, string name, string description, AssetType type,
     InventoryType invType, WearableType wearableType, PermissionMask nextOwnerMask,
     ItemCreatedCallback callback)
 {
     RequestCreateItem(parentFolder, name, description, type, UUID.Zero, invType, wearableType, nextOwnerMask, callback);
 }
        private void SetPerms(Simulator CurrentSim, List<uint> localIDs, PermissionWho who, PermissionMask Perms,
                              bool tf)
        {
            try
            {
                if (!skipPerms)
                {
                    PermCount = 0;

                    if ((Perms & PermissionMask.Modify) == PermissionMask.Modify)
                        Client.Objects.SetPermissions(CurrentSim, localIDs, who, PermissionMask.Modify,
                                                      tf);
                    PermsSent = true;

                    //  if (!GotPermissionsEvent.WaitOne(1000 * 30, false))
                    //     return Failure("failed to set the modify bit, permissions in an unknown state";

                    PermCount = 0;
                    if ((Perms & PermissionMask.Copy) == PermissionMask.Copy)
                        Client.Objects.SetPermissions(CurrentSim, localIDs, who, PermissionMask.Copy,
                                                      tf);

                    PermsSent = true;

                    //  if (!GotPermissionsEvent.WaitOne(1000 * 30, false))
                    //   return Failure("failed to set the copy bit, permissions in an unknown state";

                    PermCount = 0;
                    if ((Perms & PermissionMask.Transfer) == PermissionMask.Transfer)
                        Client.Objects.SetPermissions(CurrentSim, localIDs, who, PermissionMask.Transfer,
                                                      tf);

                    PermsSent = true;

                    PermCount = 0;
                    if ((Perms & PermissionMask.Move) == PermissionMask.Move)
                        Client.Objects.SetPermissions(CurrentSim, localIDs, who, PermissionMask.Transfer,
                                                      tf);

                    PermsSent = true;
                }
                /*
                else
                {
                    Client.Objects.SetPermissions(CurrentSim, localIDs, PermissionWho.Owner, PermissionMask.All, true);
                    Client.Objects.SetPermissions(CurrentSim, localIDs, PermissionWho.Group, PermissionMask.Modify, true);
                    Client.Objects.SetPermissions(CurrentSim, localIDs, PermissionWho.Group, PermissionMask.All, true);
                }
                //  if (!GotPermissionsEvent.WaitOne(1000 * 30, false))
                //    return Failure("failed to set the transfer bit, permissions in an unknown state";
                */
            }
            catch (Exception e)
            {
                DLRConsole.DebugWriteLine("ERROR {0}", e);
            }
        }
Beispiel #26
0
        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";
        }
Beispiel #27
0
 /// <summary>
 /// Check the permission by AND with PermissionMask.
 /// Compare the bit value of rights place.
 /// 1 means having rights, 0 means no rights.
 /// </summary>
 /// <param name="perm">The permission value.</param>
 /// <param name="mask">The rights.</param>
 /// <returns>Returns integer value after calculation. It needs to compare with the rights. It is equal to the right,
 /// it means having rights.
 /// </returns>
 private int CheckPermission(int perm, PermissionMask mask)
 {
     return(perm & (int)mask);
 }
 public void Deserialize(OSDMap map)
 {
     NewInventoryItem = map["new_inventory_item"].AsUUID();
     NewAsset = map["new_asset"].AsUUID();
     State = map["state"].AsString();
     NewBaseMask = (PermissionMask)map["new_base_mask"].AsInteger();
     NewEveryoneMask = (PermissionMask)map["new_everyone_mask"].AsInteger();
     NewOwnerMask = (PermissionMask)map["new_owner_mask"].AsInteger();
     NewNextOwnerMask = (PermissionMask)map["new_next_owner_mask"].AsInteger();
 }
Beispiel #29
0
 /// <summary>
 /// Add the permission: perm | rights. The same rights can be granted repeatedly because only the bit is changed after
 /// the calculation and its value is always 1.
 /// </summary>
 /// <param name="perm">The original permission value.</param>
 /// <param name="mask">The rights.</param>
 /// <returns>A new permission value after adding the rights.</returns>
 private int AddPermission(int perm, PermissionMask mask)
 {
     return(perm | (int)mask);
 }
Beispiel #30
0
        /// <summary>
        /// Set the permissions on multiple objects
        /// </summary>
        /// <param name="simulator">A reference to the <seealso cref="OpenMetaverse.Simulator"/> object where the objects reside</param>
        /// <param name="localIDs">An array which contains the IDs of the objects to set the permissions on</param>
        /// <param name="who">The new Who mask to set</param>
        /// <param name="permissions">The new Permissions mark to set</param>
        /// <param name="set">TODO: What does this do?</param>
        public void SetPermissions(Simulator simulator, List<uint> localIDs, PermissionWho who,
            PermissionMask permissions, bool set)
        {
            ObjectPermissionsPacket packet = new ObjectPermissionsPacket();

            packet.AgentData.AgentID = Client.Self.AgentID;
            packet.AgentData.SessionID = Client.Self.SessionID;

            // Override can only be used by gods
            packet.HeaderData.Override = false;

            packet.ObjectData = new ObjectPermissionsPacket.ObjectDataBlock[localIDs.Count];

            for (int i = 0; i < localIDs.Count; i++)
            {
                packet.ObjectData[i] = new ObjectPermissionsPacket.ObjectDataBlock();

                packet.ObjectData[i].ObjectLocalID = localIDs[i];
                packet.ObjectData[i].Field = (byte)who;
                packet.ObjectData[i].Mask = (uint)permissions;
                packet.ObjectData[i].Set = Convert.ToByte(set);
            }

            Client.Network.SendPacket(packet, simulator);
        }
Beispiel #31
0
 /// <summary>
 /// remove the permission: perm & ~rights. The same rights can be revoked repeatedly because only the bit is change after
 /// the calculation and its value is always 0.
 /// </summary>
 /// <param name="perm">The origin permission value.</param>
 /// <param name="mask">The rights.</param>
 /// <returns>A new permission value after removing the rights.</returns>
 private int RemovePermission(int perm, PermissionMask mask)
 {
     return(perm & ~((int)mask));
 }
Beispiel #32
0
        /// <summary>
        /// Check the permission by AND with PermissionMask.
        /// Compare the bit value of rights place.
        /// 1 means having rights, 0 means no rights.
        /// </summary>
        /// <param name="perm">The permission value.</param>
        /// <param name="mask">The rights.</param>
        /// <returns>Returns true if it has rights, false if it does not have.</returns>
        public bool HasPermission(int perm, PermissionMask mask)
        {
            int result = CheckPermission(perm, mask);

            return(result == (int)mask);
        }
Beispiel #33
0
 /// <summary>
 /// Add the permission: perm & rights. The same rights can be granted repeatedly because only the bit is changed after
 /// the calculation and its value is always 1.
 /// </summary>
 /// <param name="perm">The original permission value.</param>
 /// <param name="mask">The rights.</param>
 /// <returns>A new permission value after adding the rights.</returns>
 public int GrantPermission(int perm, PermissionMask mask)
 {
     return(AddPermission(perm, mask));
 }
Beispiel #34
0
        public void RequestCreateItem(LLUUID parentFolder, string name, string description, AssetType type, 
            InventoryType invType, WearableType wearableType, PermissionMask nextOwnerMask, 
            ItemCreatedCallback callback)
        {
            CreateInventoryItemPacket create = new CreateInventoryItemPacket();
            create.AgentData.AgentID = _Client.Self.AgentID;
            create.AgentData.SessionID = _Client.Self.SessionID;

            create.InventoryBlock.CallbackID = RegisterItemCreatedCallback(callback);
            create.InventoryBlock.FolderID = parentFolder;
            create.InventoryBlock.TransactionID = LLUUID.Random();
            create.InventoryBlock.NextOwnerMask = (uint)nextOwnerMask;
            create.InventoryBlock.Type = (sbyte)type;
            create.InventoryBlock.InvType = (sbyte)invType;
            create.InventoryBlock.WearableType = (byte)wearableType;
            create.InventoryBlock.Name = Helpers.StringToField(name);
            create.InventoryBlock.Description = Helpers.StringToField(description);

            _Client.Network.SendPacket(create);
        }
        public override CmdResult ExecuteRequest(CmdRequest args)
        {
            //opensim drew this line because of clients might be hardcoded to only support 255? or was this trying to copy linden?
            try
            {
                //Client.Objects.OnObjectProperties += callback;
                int              argsUsed;
                Simulator        CurSim     = TryGetSim(args, out argsUsed) ?? Client.Network.CurrentSim;
                UUID             groupID    = UUID.Zero;
                Simulator        CurrentSim = CurSim;
                Permissions      AddPerms   = new Permissions();
                Permissions      SubPerms   = new Permissions();
                bool             doTaskInv  = false;
                List <Primitive> TaskPrims  = new List <Primitive>();
                List <uint>      localIDs   = new List <uint>();

                // Reset class-wide variables
                PermsSent = false;
                Objects.Clear();
                PermCount = 0;
                bool oneAtATime = false;

                if (args.Length < 3)
                {
                    return(ShowUsage());
                }

                if (!UUIDTryParse(args, 0, out groupID, out argsUsed))
                {
                    return(ShowUsage());
                }

                args.AdvanceArgs(argsUsed);
                List <SimObject> PS = WorldSystem.GetSingleArg(args, out argsUsed);
                if (IsEmpty(PS))
                {
                    return(Failure("Cannot find objects from " + args.str));
                }

                PermissionWho who = 0;

                bool deed = false;
                for (int i = argsUsed; i < args.Length; i++)
                {
                    bool           add      = true;
                    bool           setPerms = false;
                    string         arg      = args[i];
                    int            whoint   = (int)who;
                    PermissionMask Perms    = PermsAdd[whoint];
                    if (arg.StartsWith("+"))
                    {
                        arg = arg.Substring(1);
                    }
                    else if (arg.StartsWith("-"))
                    {
                        arg   = arg.Substring(1);
                        add   = false;
                        Perms = PermsSub[whoint];
                    }

                    switch (arg.ToLower())
                    {
                    // change owner referall
                    case "who":
                        who = 0;
                        break;

                    case "o":
                        who |= PermissionWho.Owner;
                        break;

                    case "g":
                        who |= PermissionWho.Group;
                        break;

                    case "e":
                        who |= PermissionWho.Everyone;
                        break;

                    case "n":
                        who |= PermissionWho.NextOwner;
                        break;

                    case "a":
                        who = PermissionWho.All;
                        break;

                    // change perms for owner
                    case "copy":
                        Perms   |= PermissionMask.Copy;
                        setPerms = true;
                        break;

                    case "mod":
                        Perms   |= PermissionMask.Modify;
                        setPerms = true;
                        break;

                    case "xfer":
                        Perms   |= PermissionMask.Transfer;
                        setPerms = true;
                        break;

                    case "all":
                        Perms   |= PermissionMask.All;
                        setPerms = true;
                        break;

                    case "dmg":
                        Perms   |= PermissionMask.Damage;
                        setPerms = true;
                        break;

                    case "move":
                        Perms   |= PermissionMask.Move;
                        setPerms = true;
                        break;

                    // dont change perms at all
                    case "noperms":
                        skipPerms = true;
                        break;

                    // deed (implies will use group)
                    case "deed":
                        deed = true;
                        break;

                    // set object group
                    case "group":
                        i++;
                        setGroup = true;
                        groupID  = Client.GroupName2UUID(args[i]);
                        break;

                    case "task":
                        doTaskInv = true;
                        break;

                    case "incr":
                        oneAtATime = true;
                        break;

                    default:
                        return(ShowUsage());
                    }
                    if (setPerms)
                    {
                        skipPerms = false;
                        if (add)
                        {
                            PermsAdd[whoint] = Perms;
                        }
                        else
                        {
                            PermsSub[whoint] = Perms;
                        }
                    }
                }
                ulong CurrentSimHandle = CurrentSim.Handle;
                foreach (SimObject o in PS)
                {
                    if (o is SimAvatar)
                    {
                        continue;
                    }
                    if (o.RegionHandle != CurrentSimHandle)
                    {
                        continue;
                    }
                    // Find the requested prim
                    Primitive rootPrim = o.Prim;
                    if (rootPrim == null)
                    {
                        continue;
                    }
                    localIDs.Add(rootPrim.LocalID);
                    Objects[rootPrim.ID] = rootPrim;
                    if (doTaskInv)
                    {
                        TaskPrims.Add(rootPrim);
                    }

                    continue;
                    ;
                    UUID rootID = UUID.Zero;
                    if (rootPrim == null)
                    {
                        return(Failure("Cannot find requested prim " + rootID.ToString()));
                    }
                    else
                    {
                        WriteLine("Found requested prim " + rootPrim.ID.ToString(), Client);
                    }

                    if (rootPrim.ParentID != 0)
                    {
                        // This is not actually a root prim, find the root
                        if (!CurrentSim.ObjectsPrimitives.TryGetValue(rootPrim.ParentID, out rootPrim))
                        {
                            return(Failure("Cannot find root prim for requested object"));
                        }
                        else
                        {
                            WriteLine("Set root prim to " + rootPrim.ID.ToString(), Client);
                        }
                    }

                    List <Primitive> childPrims;
                    // Find all of the child objects linked to this root
                    childPrims =
                        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);
                    }

                    if (doTaskInv)
                    {
                        TaskPrims.AddRange(childPrims);
                        TaskPrims.Add(rootPrim);
                    }
                }

                WriteLine("Using PermissionMask: +" + PermsAdd.ToString() + " -" + PermsSub.ToString(), Client);


                // Go through each of the three main permissions and enable or disable them

                #region Set Linkset Permissions

                if (oneAtATime)
                {
                    List <uint> smallList = new List <uint>();
                    foreach (var o in Objects.Values)
                    {
                        if (o.OwnerID == Client.Self.AgentID)
                        //if (o.GroupID!=groupID)
                        {
                            if (doTaskInv)
                            {
                                TaskPrims.Add(o);
                            }
                            smallList.Clear();
                            smallList.Add(o.LocalID);
                            SetDeed(CurrentSim, smallList, groupID, deed);
                        }
                    }
                }
                else
                {
                    if (localIDs.Count < 50)
                    {
                        SetDeed(CurrentSim, localIDs, groupID, deed);
                    }
                    else
                    {
                        List <uint> smallList = new List <uint>();
                        while (localIDs.Count > 0)
                        {
                            if (localIDs.Count < 50)
                            {
                                SetDeed(CurrentSim, localIDs, groupID, deed);
                                break;
                            }
                            smallList.Clear();
                            smallList.AddRange(localIDs.GetRange(0, 50));
                            SetDeed(CurrentSim, smallList, groupID, deed);
                            localIDs.RemoveRange(0, 50);
                        }
                    }
                }

                #endregion Set Linkset Permissions

                // Check each prim for task inventory and set permissions on the task inventory
                int taskItems = 0;
                if (doTaskInv)
                {
                    foreach (Primitive prim in TaskPrims)
                    {
                        if ((prim.Flags & PrimFlags.InventoryEmpty) == 0)
                        {
                            List <InventoryBase> items = Client.Inventory.GetTaskInventory(prim.ID, prim.LocalID, 1000 * 10);

                            if (items != null)
                            {
                                for (int i = 0; i < items.Count; i++)
                                {
                                    if (!(items[i] is InventoryFolder))
                                    {
                                        InventoryItem item = (InventoryItem)items[i];

                                        // prev and not (W or All)
                                        item.Permissions.GroupMask &=
                                            ~(PermsSub[(int)PermissionWho.Group] | PermsSub[(int)PermissionWho.All]);
                                        item.Permissions.OwnerMask &=
                                            ~(PermsSub[(int)PermissionWho.Owner] | PermsSub[(int)PermissionWho.All]);
                                        item.Permissions.NextOwnerMask &=
                                            ~(PermsSub[(int)PermissionWho.NextOwner] |
                                              PermsSub[(int)PermissionWho.All]);
                                        item.Permissions.EveryoneMask &=
                                            ~(PermsSub[(int)PermissionWho.Everyone] | PermsSub[(int)PermissionWho.All]);

                                        // prev and (W or All)
                                        item.Permissions.GroupMask |= PermsAdd[(int)PermissionWho.Group] |
                                                                      PermsAdd[(int)PermissionWho.All];
                                        item.Permissions.OwnerMask |= PermsAdd[(int)PermissionWho.Owner] |
                                                                      PermsAdd[(int)PermissionWho.All];
                                        item.Permissions.NextOwnerMask |= PermsAdd[(int)PermissionWho.NextOwner] |
                                                                          PermsAdd[(int)PermissionWho.All];
                                        item.Permissions.EveryoneMask |= PermsAdd[(int)PermissionWho.Everyone] |
                                                                         PermsAdd[(int)PermissionWho.All];

                                        Client.Inventory.UpdateTaskInventory(prim.LocalID, item);
                                        ++taskItems;
                                    }
                                }
                            }
                        }
                    }
                }

                return
                    (Success("Using PermissionMask: +" + PermsAdd.ToString() + " -" + PermsSub.ToString() + " on " +
                             Objects.Count + " objects and " + taskItems + " inventory items"));
            }
            finally
            {
                // Client.Objects.OnObjectProperties -= callback;
            }
        }