aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/linden/indra/llinventory/llpermissions.h
diff options
context:
space:
mode:
authorJacek Antonelli2008-08-15 23:44:46 -0500
committerJacek Antonelli2008-08-15 23:44:46 -0500
commit38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4 (patch)
treeadca584755d22ca041a2dbfc35d4eca01f70b32c /linden/indra/llinventory/llpermissions.h
parentREADME.txt (diff)
downloadmeta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.zip
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.gz
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.bz2
meta-impy-38d6d37f2d982fa959e9e8a4a3f7e1ccfad7b5d4.tar.xz
Second Life viewer sources 1.13.2.12
Diffstat (limited to 'linden/indra/llinventory/llpermissions.h')
-rw-r--r--linden/indra/llinventory/llpermissions.h445
1 files changed, 445 insertions, 0 deletions
diff --git a/linden/indra/llinventory/llpermissions.h b/linden/indra/llinventory/llpermissions.h
new file mode 100644
index 0000000..d8a6b0a
--- /dev/null
+++ b/linden/indra/llinventory/llpermissions.h
@@ -0,0 +1,445 @@
1/**
2 * @file llpermissions.h
3 * @brief Permissions structures for objects.
4 *
5 * Copyright (c) 2002-2007, Linden Research, Inc.
6 *
7 * The source code in this file ("Source Code") is provided by Linden Lab
8 * to you under the terms of the GNU General Public License, version 2.0
9 * ("GPL"), unless you have obtained a separate licensing agreement
10 * ("Other License"), formally executed by you and Linden Lab. Terms of
11 * the GPL can be found in doc/GPL-license.txt in this distribution, or
12 * online at http://secondlife.com/developers/opensource/gplv2
13 *
14 * There are special exceptions to the terms and conditions of the GPL as
15 * it is applied to this Source Code. View the full text of the exception
16 * in the file doc/FLOSS-exception.txt in this software distribution, or
17 * online at http://secondlife.com/developers/opensource/flossexception
18 *
19 * By copying, modifying or distributing this software, you acknowledge
20 * that you have read and understood your obligations described above,
21 * and agree to abide by those obligations.
22 *
23 * ALL LINDEN LAB SOURCE CODE IS PROVIDED "AS IS." LINDEN LAB MAKES NO
24 * WARRANTIES, EXPRESS, IMPLIED OR OTHERWISE, REGARDING ITS ACCURACY,
25 * COMPLETENESS OR PERFORMANCE.
26 */
27
28#ifndef LL_LLPERMISSIONS_H
29#define LL_LLPERMISSIONS_H
30
31#include <stdio.h>
32#include <iostream>
33
34#include "llpermissionsflags.h"
35#include "llsd.h"
36#include "lluuid.h"
37#include "llxmlnode.h"
38#include "reflective.h"
39
40// prototypes
41class LLMessageSystem;
42extern void mask_to_string(U32 mask, char* str);
43template<class T> class LLMetaClassT;
44
45//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
46// Class LLPermissions
47//
48// Class which encapsulates object and inventory permissions/ownership/etc.
49//
50// Permissions where originally a static state creator/owner and set
51// of cap bits. Since then, it has grown to include group information,
52// last owner, masks for different people. The implementation has been
53// chosen such that a uuid is stored for each current/past owner, and
54// a bitmask is stored for the base permissions, owner permissions,
55// group permissions, and everyone else permissions.
56//
57// The base permissions represent the most permissive state that the
58// permissions can possibly be in. Thus, if the base permissions do
59// not allow copying, no one can ever copy the object. The permissions
60// also maintain a tree-like hierarchy of permissions, thus, if we
61// (for sake of discussions) denote more permissive as '>', then this
62// is invariant:
63//
64// base mask >= owner mask >= group mask
65// >= everyone mask
66// >= next owner mask
67// NOTE: the group mask does not effect everyone or next, everyone
68// does not effect group or next, etc.
69//
70// It is considered a fair use right to move or delete any object you
71// own. Another fair use right is the ability to give away anything
72// which you cannot copy. One way to look at that is that if you have
73// a unique item, you can always give that one copy you have to
74// someone else.
75//
76// Most of the bitmask is easy to understand, PERM_COPY means you can
77// copy !PERM_TRANSFER means you cannot transfer, etc. Given that we
78// now track the concept of 'next owner' inside of the permissions
79// object, we can describe some new meta-meaning to the PERM_MODIFY
80// flag. PERM_MODIFY is usually meant to note if you can change an
81// item, but since we record next owner permissions, we can interpret
82// a no-modify object as 'you cannot modify this object and you cannot
83// make derivative works.' When evaluating functionality, and
84// comparisons against permissions, keep this concept in mind for
85// logical consistency.
86//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
87
88class LLPermissions : public LLReflective
89{
90private:
91 LLUUID mCreator; // null if object created by system
92 LLUUID mOwner; // null if object "unowned" (owned by system)
93 LLUUID mLastOwner; // object's last owner
94 LLUUID mGroup; // The group association
95
96 PermissionMask mMaskBase; // initially permissive, progressively AND restricted by each owner
97
98 PermissionMask mMaskOwner; // set by owner, applies to owner only, restricts lower permissions
99 PermissionMask mMaskEveryone; // set by owner, applies to everyone else
100
101 PermissionMask mMaskGroup; // set by owner, applies to group that is associated with permissions
102
103 PermissionMask mMaskNextOwner; // set by owner, applied to base on transfer.
104
105 // Usually set in the fixOwnership() method based on current uuid
106 // values.
107 bool mIsGroupOwned;
108
109 // Correct for fair use - you can never take away the right to
110 // move stuff you own, and you can never take away the right to
111 // transfer something you cannot otherwise copy.
112 void fixFairUse();
113
114 // Fix internal consistency for group/agent ownership
115 void fixOwnership();
116
117public:
118 static const LLPermissions DEFAULT;
119
120 LLPermissions(); // defaults to created by system
121 //~LLPermissions();
122
123 // base initialization code
124 void init(const LLUUID& creator, const LLUUID& owner,
125 const LLUUID& last_owner, const LLUUID& group);
126 void initMasks(PermissionMask base, PermissionMask owner,
127 PermissionMask everyone, PermissionMask group,
128 PermissionMask next);
129
130 //
131 // ACCESSORS
132 //
133
134 // return the agent_id of the agent that created the item
135 const LLUUID& getCreator() const { return mCreator; }
136
137 // return the agent_id of the owner. returns LLUUID::null if group
138 // owned or public (a really big group).
139 const LLUUID& getOwner() const { return mOwner; }
140
141 // return the group_id of the group associated with the
142 // object. group_id == owner_id if the object is group owned.
143 const LLUUID& getGroup() const { return mGroup; }
144
145 // return the agent_id of the last agent owner. Only returns
146 // LLUUID::null if there has never been a previous owner.
147 const LLUUID& getLastOwner() const { return mLastOwner; }
148
149 U32 getMaskBase() const { return mMaskBase; }
150 U32 getMaskOwner() const { return mMaskOwner; }
151 U32 getMaskGroup() const { return mMaskGroup; }
152 U32 getMaskEveryone() const { return mMaskEveryone; }
153 U32 getMaskNextOwner() const { return mMaskNextOwner; }
154
155 // return TRUE if the object has any owner
156 bool isOwned() const { return (mOwner.notNull() || mIsGroupOwned); }
157
158 // return TRUE if group_id is owner.
159 bool isGroupOwned() const { return mIsGroupOwned; }
160
161 // This API returns TRUE if the object is owned at all, and FALSE
162 // otherwise. If it is owned at all, owner id is filled with
163 // either the owner id or the group id, and the is_group_owned
164 // parameter is appropriately filled. The values of owner_id and
165 // is_group_owned are not changed if the object is not owned.
166 BOOL getOwnership(LLUUID& owner_id, BOOL& is_group_owned) const;
167
168 // Gets the 'safe' owner. This should never return LLUUID::null.
169 // If no group owned, return the agent owner id normally.
170 // If group owned, return the group id.
171 // If not owned, return a random uuid which should have no power.
172 LLUUID getSafeOwner() const;
173
174 // return a cheap crc
175 U32 getCRC32() const;
176
177
178 //
179 // MANIPULATORS
180 //
181
182 // Fix hierarchy of permissions, applies appropriate permissions
183 // at each level to ensure that base permissions are respected,
184 // and also ensures that if base cannot transfer, then group and
185 // other cannot copy.
186 void fix();
187
188 // All of these methods just do exactly what they say. There is no
189 // permissions checking to see if the operation is allowed, and do
190 // not fix the permissions hierarchy. So please only use these
191 // methods when you are know what you're doing and coding on
192 // behalf of the system - ie, acting as god.
193 void set(const LLPermissions& permissions);
194 void setMaskBase(U32 mask) { mMaskBase = mask; }
195 void setMaskOwner(U32 mask) { mMaskOwner = mask; }
196 void setMaskEveryone(U32 mask) { mMaskEveryone = mask;}
197 void setMaskGroup(U32 mask) { mMaskGroup = mask;}
198 void setMaskNext(U32 mask) { mMaskNextOwner = mask; }
199
200 // Allow accumulation of permissions. Results in the tightest
201 // permissions possible. In the case of clashing UUIDs, it sets
202 // the ID to LLUUID::null.
203 void accumulate(const LLPermissions& perm);
204
205 //
206 // CHECKED MANIPULATORS
207 //
208
209 // These functions return true on success. They return false if
210 // the given agent isn't allowed to make the change. You can pass
211 // LLUUID::null as the agent id if the change is being made by the
212 // simulator itself, not on behalf of any agent - this will always
213 // succeed. Passing in group id of LLUUID:null means no group, and
214 // does not offer special permission to do anything.
215
216 // saves last owner, sets current owner, and sets the group.
217 // set is_atomic = true means that this permission represents
218 // an atomic permission and not a collection of permissions.
219 // Currently, the only way to have a collection is when an object
220 // has inventory and is then itself rolled up into an inventory
221 // item.
222 BOOL setOwnerAndGroup(const LLUUID& agent, const LLUUID& owner, const LLUUID& group, bool is_atomic);
223
224 // saves last owner, sets owner to uuid null, sets group
225 // owned. group_id must be the group of the object (that's who it
226 // is being deeded to) and the object must be group
227 // modify. Technically, the agent id and group id are not
228 // necessary, but I wanted this function to look like the other
229 // checked manipulators (since that is how it is used.) If the
230 // agent is the system or (group == mGroup and group modify and
231 // owner transfer) then this function will deed the permissions,
232 // set the next owner mask, and return TRUE. Otherwise, no change
233 // is effected, and the function returns FALSE.
234 BOOL deedToGroup(const LLUUID& agent, const LLUUID& group);
235 // Attempt to set or clear the given bitmask. Returns TRUE if you
236 // are allowed to modify the permissions. If you attempt to turn
237 // on bits not allowed by the base bits, the function will return
238 // TRUE, but those bits will not be set.
239 BOOL setBaseBits( const LLUUID& agent, BOOL set, PermissionMask bits);
240 BOOL setOwnerBits( const LLUUID& agent, BOOL set, PermissionMask bits);
241 BOOL setGroupBits( const LLUUID& agent, const LLUUID& group, BOOL set, PermissionMask bits);
242 BOOL setEveryoneBits(const LLUUID& agent, const LLUUID& group, BOOL set, PermissionMask bits);
243 BOOL setNextOwnerBits(const LLUUID& agent, const LLUUID& group, BOOL set, PermissionMask bits);
244
245 //
246 // METHODS
247 //
248
249 // All the allow* functions return true if the given agent or
250 // group can perform the function. Prefer using this set of
251 // operations to check permissions on an object. These return
252 // true if the given agent or group can perform the function.
253 // They also return true if the object isn't owned, or the
254 // requesting agent is a system agent. See llpermissionsflags.h
255 // for bits.
256 BOOL allowOperationBy(PermissionBit op, const LLUUID& agent, const LLUUID& group = LLUUID::null) const;
257
258 inline BOOL allowModifyBy(const LLUUID &agent_id) const;
259 inline BOOL allowCopyBy(const LLUUID& agent_id) const;
260 inline BOOL allowMoveBy(const LLUUID& agent_id) const;
261 inline BOOL allowModifyBy(const LLUUID &agent_id, const LLUUID& group) const;
262 inline BOOL allowCopyBy(const LLUUID& agent_id, const LLUUID& group) const;
263 inline BOOL allowMoveBy(const LLUUID &agent_id, const LLUUID &group) const;
264
265 // This somewhat specialized function is meant for testing if the
266 // current owner is allowed to transfer to the specified agent id.
267 inline BOOL allowTransferTo(const LLUUID &agent_id) const;
268
269 //
270 // DEPRECATED.
271 //
272 // These return true if the given agent can perform the function.
273 // They also return true if the object isn't owned, or the
274 // requesting agent is a system agent. See llpermissionsflags.h
275 // for bits.
276 //BOOL allowDeleteBy(const LLUUID& agent_id) const { return allowModifyBy(agent_id); }
277 //BOOL allowEditBy(const LLUUID& agent_id) const { return allowModifyBy(agent_id); }
278 // saves last owner and sets current owner
279 //BOOL setOwner(const LLUUID& agent, const LLUUID& owner);
280 // This method saves the last owner, sets the current owner to the
281 // one provided, and sets the base mask as indicated.
282 //BOOL setOwner(const LLUUID& agent, const LLUUID& owner, U32 new_base_mask);
283
284 // Attempt to set or clear the given bitmask. Returns TRUE if you
285 // are allowed to modify the permissions. If you attempt to turn
286 // on bits not allowed by the base bits, the function will return
287 // TRUE, but those bits will not be set.
288 //BOOL setGroupBits( const LLUUID& agent, BOOL set, PermissionMask bits);
289 //BOOL setEveryoneBits(const LLUUID& agent, BOOL set, PermissionMask bits);
290
291 //
292 // MISC METHODS and OPERATORS
293 //
294
295 // For messaging system support
296 void packMessage(LLMessageSystem* msg) const;
297 void unpackMessage(LLMessageSystem* msg, const char* block, S32 block_num = 0);
298
299 // Load/save support
300 BOOL importFile(FILE* fp);
301 BOOL exportFile(FILE* fp) const;
302
303 BOOL importLegacyStream(std::istream& input_stream);
304 BOOL exportLegacyStream(std::ostream& output_stream) const;
305
306 LLXMLNode *exportFileXML() const;
307 bool importXML(LLXMLNode* node);
308
309 bool operator==(const LLPermissions &rhs) const;
310 bool operator!=(const LLPermissions &rhs) const;
311
312 friend std::ostream& operator<<(std::ostream &s, const LLPermissions &perm);
313
314 // Reflection.
315 friend class LLMetaClassT<LLPermissions>;
316 virtual const LLMetaClass& getMetaClass() const;
317};
318
319// Inlines
320BOOL LLPermissions::allowModifyBy(const LLUUID& agent, const LLUUID& group) const
321{
322 return allowOperationBy(PERM_MODIFY, agent, group);
323}
324
325BOOL LLPermissions::allowCopyBy(const LLUUID& agent, const LLUUID& group) const
326{
327 return allowOperationBy(PERM_COPY, agent, group);
328}
329
330
331BOOL LLPermissions::allowMoveBy(const LLUUID& agent, const LLUUID& group) const
332{
333 return allowOperationBy(PERM_MOVE, agent, group);
334}
335
336BOOL LLPermissions::allowModifyBy(const LLUUID& agent) const
337{
338 return allowOperationBy(PERM_MODIFY, agent, LLUUID::null);
339}
340
341BOOL LLPermissions::allowCopyBy(const LLUUID& agent) const
342{
343 return allowOperationBy(PERM_COPY, agent, LLUUID::null);
344}
345
346BOOL LLPermissions::allowMoveBy(const LLUUID& agent) const
347{
348 return allowOperationBy(PERM_MOVE, agent, LLUUID::null);
349}
350
351BOOL LLPermissions::allowTransferTo(const LLUUID &agent_id) const
352{
353 if (mIsGroupOwned)
354 {
355 return allowOperationBy(PERM_TRANSFER, mGroup, mGroup);
356 }
357 else
358 {
359 return ((mOwner == agent_id) ? TRUE : allowOperationBy(PERM_TRANSFER, mOwner));
360 }
361}
362
363//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
364// Class LLAggregatePermissions
365//
366// Class which encapsulates object and inventory permissions,
367// ownership, etc. Currently, it only aggregates PERM_COPY,
368// PERM_MODIFY, and PERM_TRANSFER.
369//
370// Usually you will construct an instance and hand the object several
371// permissions masks to aggregate the copy, modify, and
372// transferability into a nice trinary value.
373//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
374
375class LLAggregatePermissions
376{
377public:
378 enum EValue
379 {
380 AP_EMPTY = 0x00,
381 AP_NONE = 0x01,
382 AP_SOME = 0x02,
383 AP_ALL = 0x03
384 };
385
386 // construct an empty aggregate permissions
387 LLAggregatePermissions();
388
389 // pass in a PERM_COPY, PERM_TRANSFER, etc, and get out a EValue
390 // enumeration describing the current aggregate permissions.
391 EValue getValue(PermissionBit bit) const;
392
393 // returns the permissions packed into the 6 LSB of a U8:
394 // 00TTMMCC
395 // where TT = transfer, MM = modify, and CC = copy
396 // LSB is to the right
397 U8 getU8() const;
398
399 // return TRUE is the aggregate permissions are empty, otherwise FALSE.
400 BOOL isEmpty() const ;
401
402 // pass in a PERM_COPY, PERM_TRANSFER, etc, and an EValue
403 // enumeration to specifically set that value. Not implemented
404 // because I'm not sure it's a useful api.
405 //void setValue(PermissionBit bit, EValue);
406
407 // Given a mask, aggregate the useful permissions.
408 void aggregate(PermissionMask mask);
409
410 // Aggregate aggregates
411 void aggregate(const LLAggregatePermissions& ag);
412
413 // message handling
414 void packMessage(LLMessageSystem* msg, const char* field) const;
415 void unpackMessage(LLMessageSystem* msg, const char* block, const char *field, S32 block_num = 0);
416
417 static const LLAggregatePermissions empty;
418
419 friend std::ostream& operator<<(std::ostream &s, const LLAggregatePermissions &perm);
420
421protected:
422 enum EPermIndex
423 {
424 PI_COPY = 0,
425 PI_MODIFY = 1,
426 PI_TRANSFER = 2,
427 PI_END = 3,
428 PI_COUNT = 3
429 };
430 void aggregateBit(EPermIndex idx, BOOL allowed);
431 void aggregateIndex(EPermIndex idx, U8 bits);
432 static EPermIndex perm2PermIndex(PermissionBit bit);
433
434 // structure used to store the aggregate so far.
435 U8 mBits[PI_COUNT];
436};
437
438// These functions convert between structured data and permissions as
439// appropriate for serialization. The permissions are a map of things
440// like 'creator_id', 'owner_id', etc, with the value copied from the
441// permission object.
442LLSD ll_create_sd_from_permissions(const LLPermissions& perm);
443LLPermissions ll_permissions_from_sd(const LLSD& sd_perm);
444
445#endif