restructure of HandleSys admin permissions and interface

removal of HandleSys helper functions
removed useless BaseContext stuff from Engine
put SourceMod specific stuff in BaseContext
cleaned up broken Handle code

--HG--
extra : convert_revision : svn%3A39bc706e-5318-0410-9160-8a85361fbb7c/trunk%40267
This commit is contained in:
David Anderson
2007-01-04 02:08:27 +00:00
parent 15beb5afb0
commit 4bd40d69e1
13 changed files with 436 additions and 240 deletions
+100 -81
View File
@@ -43,34 +43,72 @@ namespace SourceMod
HandleError_Limit, /* The limited number of handles has been reached */
HandleError_Identity, /* The identity token was not usable */
HandleError_Owner, /* Owners do not match for this operation */
HandleError_Version, /* Unrecognized security structure version */
HandleError_Parameter, /* An invalid parameter was passed */
HandleError_NoInherit, /* This type cannot be inherited */
};
/**
* Access rights specific to a type
*/
enum HTypeAccessRight
{
HTypeAccess_Create = 0, /* Handles of this type can be created (DEFAULT=false) */
HTypeAccess_Inherit, /* Sub-types can inherit this type (DEFAULT=false) */
/* -------------- */
HTypeAccess_TOTAL, /* Total number of type access rights */
};
/**
* Access rights specific to a Handle. These rights are exclusive.
* For example, you do not need "read" access to delete or clone.
*/
enum HandleAccessRight
{
HandleAccess_Create, /* TYPE: Instances can be created by other objects (this makes it searchable) */
HandleAccess_Read, /* HANDLES: Can be read by other objects */
HandleAccess_IdentDelete, /* HANDLES: Can be deleted by other identities */
HandleAccess_OwnerDelete, /* HANDLES: Can be deleted by other owners */
HandleAccess_Inherit, /* TYPE: Can be inherited by new types */
HandleAccess_Clone, /* HANDLES: Can be cloned */
HandleAccess_Read, /* Can be read (DEFAULT=ident only) */
HandleAccess_Delete, /* Can be deleted (DEFAULT=owner only) */
HandleAccess_Clone, /* Can be cloned (DEFAULT=any) */
/* ------------- */
HandleAccess_TOTAL, /* Total number of access rights */
};
#define HANDLE_RESTRICT_IDENTITY (1<<0) /* Access is restricted to the identity */
#define HANDLE_RESTRICT_OWNER (1<<1) /* Access is restricted to the owner */
/**
* This is used to define per-type access rights.
*/
struct TypeAccess
{
TypeAccess()
{
hsVersion = SMINTERFACE_HANDLESYSTEM_VERSION;
}
unsigned int hsVersion;
IdentityToken_t *ident;
bool access[HTypeAccess_TOTAL];
};
/**
* This is used to define per-Handle access rights.
*/
struct HandleAccess
{
HandleAccess()
{
hsVersion = SMINTERFACE_HANDLESYSTEM_VERSION;
}
unsigned int hsVersion;
unsigned int access[HandleAccess_TOTAL];
};
/**
* This pair of tokens is used for identification.
*/
struct HandleSecurity
{
HandleSecurity()
{
owner = NULL;
access[HandleAccess_Create] = true;
access[HandleAccess_Read] = true;
access[HandleAccess_IdentDelete] = true;
access[HandleAccess_Inherit] = true;
access[HandleAccess_Clone] = true;
access[HandleAccess_OwnerDelete] = false;
}
IdentityToken_t *owner; /* Owner of the handle */
bool access[HandleAccess_TOTAL]; /* World access rights */
IdentityToken_t *pOwner; /* Owner of the Handle */
IdentityToken_t *pIdentity; /* Owner of the Type */
};
class IHandleTypeDispatch
@@ -99,17 +137,6 @@ namespace SourceMod
return SMINTERFACE_HANDLESYSTEM_NAME;
}
public:
/**
* @brief Creates a new Handle type.
* NOTE: Handle names must be unique if not private.
*
* @param name Name of handle type (NULL or "" to be anonymous)
* @param dispatch Pointer to a valid IHandleTypeDispatch object.
* @return A new HandleType_t unique ID, or 0 on failure.
*/
virtual HandleType_t CreateType(const char *name,
IHandleTypeDispatch *dispatch) =0;
/**
* @brief Creates a new Handle type.
* NOTE: Currently, a child type may not have its own children.
@@ -118,39 +145,30 @@ namespace SourceMod
* @param name Name of handle type (NULL or "" to be anonymous)
* @param dispatch Pointer to a valid IHandleTypeDispatch object.
* @param parent Parent handle to inherit from, 0 for none.
* @param security Pointer to a temporary HandleSecurity object, NULL to use default
* or inherited permissions.
* @param ident Security token for any permissions.
* @param typeAccess Pointer to a TypeAccess object, NULL to use default
* or inherited permissions. Pointer can be temporary.
* @param hndlAccess Pointer to a HandleAccess object to define default
* default permissions on each Handle. NULL to use default
* permissions.
* @param ident Security token for any permissions. If typeAccess is NULL, this
* becomes the owning identity.
* @param err Optional pointer to store an error code.
* @return A new HandleType_t unique ID, or 0 on failure.
*/
virtual HandleType_t CreateTypeEx(const char *name,
virtual HandleType_t CreateType(const char *name,
IHandleTypeDispatch *dispatch,
HandleType_t parent,
const HandleSecurity *security,
IdentityToken_t *ident) =0;
/**
* @brief Creates a sub-type for a Handle.
* NOTE: Currently, a child type may not have its own children.
* NOTE: Handle names must be unique if not private.
* NOTE: This is a wrapper around the above.
*
* @param name Name of a handle.
* @param parent Parent handle type.
* @param dispatch Pointer to a valid IHandleTypeDispatch object.
* @return A new HandleType_t unique ID.
*/
virtual HandleType_t CreateChildType(const char *name,
HandleType_t parent,
IHandleTypeDispatch *dispatch) =0;
const TypeAccess *typeAccess,
const HandleAccess *hndlAccess,
IdentityToken_t *ident,
HandleError *err) =0;
/**
* @brief Removes a handle type.
* NOTE: This removes all child types.
*
* @param token Identity token. Removal fails if the token does not match.
* @param type Type chain to remove.
* @param ident Identity token. Removal fails if the token does not match.
* @return True on success, false on failure.
*/
virtual bool RemoveType(HandleType_t type, IdentityToken_t *ident) =0;
@@ -169,29 +187,16 @@ namespace SourceMod
*
* @param type Type to use on the handle.
* @param object Object to bind to the handle.
* @param owner Owner for the handle. NULL means anonymous (no owner).
* @param ident Identity token if any security rights are needed.
* @param owner Owner of the new Handle (may be NULL).
* @param ident Identity for type access if needed (may be NULL).
* @param err Optional pointer to store an error code.
* @return A new Handle_t, or 0 on failure.
*/
virtual Handle_t CreateHandle(HandleType_t type,
void *object,
IdentityToken_t *owner,
IdentityToken_t *ident) =0;
/**
* @brief Creates a new handle.
* NOTE: This is a wrapper around the above function.
*
* @param type Type to use on the handle.
* @param object Object to bind to the handle.
* @param pOwner Plugin context that will own this handle. NULL for none.
* @param ident Identity token if any security rights are needed.
* @return A new Handle_t.
*/
virtual Handle_t CreateScriptHandle(HandleType_t type,
void *object,
SourcePawn::IPluginContext *pOwner,
IdentityToken_t *ident) =0;
void *object,
IdentityToken_t *owner,
IdentityToken_t *ident,
HandleError *err) =0;
/**
* @brief Frees the memory associated with a handle and calls any destructors.
@@ -199,34 +204,48 @@ namespace SourceMod
* only perform any further action if the counter hits 0.
*
* @param type Handle_t identifier to destroy.
* @param owner Owner of handle (NULL for none).
* @param ident Identity token, for destroying secure handles (NULL for none).
* @param pSecurity Security information struct (may be NULL).
* @return A HandleError error code.
*/
virtual HandleError FreeHandle(Handle_t handle, IdentityToken_t *owner, IdentityToken_t *ident) =0;
virtual HandleError FreeHandle(Handle_t handle, const HandleSecurity *pSecurity) =0;
/**
* @brief Clones a handle by adding to its internal reference count. Its data,
* type, and security permissions remain the same.
*
* @param handle Handle to duplicate. Any non-free handle target is valid.
* @param newhandle If non-NULL, stores the duplicated handle in the pointer.
* @param owner New owner of cloned handle.
* @param ident Security token, if needed.
* @param newhandle Stores the duplicated handle in the pointer (must not be NULL).
* @param newOwner New owner of cloned handle.
* @param pSecurity Security information struct (may be NULL).
* @return A HandleError error code.
*/
virtual HandleError CloneHandle(Handle_t handle, Handle_t *newhandle, IdentityToken_t *owner, IdentityToken_t *ident) =0;
virtual HandleError CloneHandle(Handle_t handle,
Handle_t *newhandle,
IdentityToken_t *newOwner,
const HandleSecurity *pSecurity) =0;
/**
* @brief Retrieves the contents of a handle.
*
* @param handle Handle_t from which to retrieve contents.
* @param type Expected type to read as. 0 ignores typing rules.
* @param ident Identity token to validate as.
* @param pSecurity Security information struct (may be NULL).
* @param object Optional address to store object in.
* @return HandleError error code.
*/
virtual HandleError ReadHandle(Handle_t handle, HandleType_t type, IdentityToken_t *ident, void **object) =0;
virtual HandleError ReadHandle(Handle_t handle,
HandleType_t type,
const HandleSecurity *pSecurity,
void **object) =0;
/**
* @brief Sets access permissions on one or more structures.
*
* @param pTypeAccess Optional TypeAccess buffer to initialize with the default values.
* @param pHandleAccess Optional HandleAccess buffer to initialize with the default values.
* @return True on success, false if version is unsupported.
*/
virtual bool InitAccessDefaults(TypeAccess *pTypeAccess, HandleAccess *pHandleAccess) =0;
};
};