From 96e45626c43b7674b66e0258b0b1730d5ce71357 Mon Sep 17 00:00:00 2001 From: Eamon Walsh Date: Wed, 2 Aug 2006 20:29:59 -0400 Subject: [PATCH] Rebase Security extension to use devPrivates for storing security state. --- Xext/security.c | 51 ++++++++++++++++++++++---------------------- Xext/xace.c | 48 ----------------------------------------- Xext/xace.h | 16 -------------- dix/dispatch.c | 3 --- dix/extension.c | 4 +--- include/dixstruct.h | 3 --- include/extnsionst.h | 3 --- 7 files changed, 27 insertions(+), 101 deletions(-) diff --git a/Xext/security.c b/Xext/security.c index b96ac28c3..2c3415378 100644 --- a/Xext/security.c +++ b/Xext/security.c @@ -62,7 +62,8 @@ in this Software without prior written authorization from The Open Group. static int SecurityErrorBase; /* first Security error number */ static int SecurityEventBase; /* first Security event number */ -static int slot; /* Xace security state number */ +static int securityClientPrivateIndex; +static int securityExtnsnPrivateIndex; /* this is what we store as client security state */ typedef struct { @@ -70,9 +71,14 @@ typedef struct { XID authId; } SecurityClientStateRec; -#define STATEPTR(obj) ((obj)->securityState[slot]) -#define TRUSTLEVEL(obj) (((SecurityClientStateRec*)STATEPTR(obj))->trustLevel) -#define AUTHID(obj) (((SecurityClientStateRec*)STATEPTR(obj))->authId) +#define STATEVAL(extnsn) \ + ((extnsn)->devPrivates[securityExtnsnPrivateIndex].val) +#define STATEPTR(client) \ + ((client)->devPrivates[securityClientPrivateIndex].ptr) +#define TRUSTLEVEL(client) \ + (((SecurityClientStateRec*)STATEPTR(client))->trustLevel) +#define AUTHID(client) \ + (((SecurityClientStateRec*)STATEPTR(client))->authId) CallbackListPtr SecurityValidateGroupCallback = NULL; /* see security.h */ @@ -1118,6 +1124,11 @@ CALLBACK(SecurityClientStateCallback) switch (client->clientState) { + case ClientStateInitial: + TRUSTLEVEL(serverClient) = XSecurityClientTrusted; + AUTHID(serverClient) = None; + break; + case ClientStateRunning: { XID authId = AuthorizationIDOfClient(client); @@ -1148,7 +1159,6 @@ CALLBACK(SecurityClientStateCallback) case ClientStateRetained: /* client disconnected */ { SecurityAuthorizationPtr pAuth; - pointer freeit; /* client may not have any state (bad authorization) */ if (!STATEPTR(client)) @@ -1164,10 +1174,6 @@ CALLBACK(SecurityClientStateCallback) SecurityStartAuthorizationTimer(pAuth); } } - /* free security state */ - freeit = STATEPTR(client); - STATEPTR(client) = NULL; - xfree(freeit); break; } default: break; @@ -1208,7 +1214,7 @@ CALLBACK(SecurityCheckExtAccess) XaceExtAccessRec *rec = (XaceExtAccessRec*)calldata; if ((TRUSTLEVEL(rec->client) != XSecurityClientTrusted) && - !STATEPTR(rec->ext)) + !STATEVAL(rec->ext)) rec->rval = FALSE; } @@ -1234,7 +1240,7 @@ CALLBACK(SecurityDeclareExtSecure) XaceDeclareExtSecureRec *rec = (XaceDeclareExtSecureRec*)calldata; /* security state for extensions is simply a boolean trust value */ - STATEPTR(rec->ext) = (pointer)rec->secure; + STATEVAL(rec->ext) = rec->secure; } /**********************************************************************/ @@ -1842,10 +1848,6 @@ static void SecurityResetProc( ExtensionEntry *extEntry) { - pointer freeit = STATEPTR(serverClient); - STATEPTR(serverClient) = NULL; - xfree(freeit); - XaceUnregisterExtension(slot); SecurityFreePropertyAccessList(); SecurityFreeSitePolicyStrings(); } /* SecurityResetProc */ @@ -1882,13 +1884,16 @@ XSecurityOptions(argc, argv, i) void SecurityExtensionSetup(INITARGS) { - /* allocate space for security state (freed in SecurityResetProc) */ - STATEPTR(serverClient) = xalloc(sizeof(SecurityClientStateRec)); - if (!STATEPTR(serverClient)) - FatalError("serverClient: couldn't allocate security state\n"); + /* Allocate the client private index */ + securityClientPrivateIndex = AllocateClientPrivateIndex(); + if (!AllocateClientPrivate(securityClientPrivateIndex, + sizeof (SecurityClientStateRec))) + FatalError("SecurityExtensionSetup: Can't allocate client private.\n"); - TRUSTLEVEL(serverClient) = XSecurityClientTrusted; - AUTHID(serverClient) = None; + /* Allocate the extension private index */ + securityExtnsnPrivateIndex = AllocateExtensionPrivateIndex(); + if (!AllocateExtensionPrivate(securityExtnsnPrivateIndex, 0)) + FatalError("SecurityExtensionSetup: Can't allocate extnsn private.\n"); /* register callbacks */ #define XaceRC XaceRegisterCallback @@ -1934,10 +1939,6 @@ SecurityExtensionInit(INITARGS) if (!AddCallback(&ClientStateCallback, SecurityClientStateCallback, NULL)) return; - slot = XaceRegisterExtension(SECURITY_EXTENSION_NAME); - if (slot < 0) - return; - extEntry = AddExtension(SECURITY_EXTENSION_NAME, XSecurityNumberEvents, XSecurityNumberErrors, ProcSecurityDispatch, SProcSecurityDispatch, diff --git a/Xext/xace.c b/Xext/xace.c index 75fb8a35b..eb9540a8f 100644 --- a/Xext/xace.c +++ b/Xext/xace.c @@ -26,9 +26,6 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. CallbackListPtr XaceHooks[XACE_NUM_HOOKS] = {0}; -static Bool stateSlotsUsed[XACE_STATE_SLOTS] = {0}; -static char *stateExtNames[XACE_STATE_SLOTS] = {0}; - /* Proc vectors for untrusted clients, swapped and unswapped versions. * These are the same as the normal proc vectors except that extensions * that haven't declared themselves secure will have ProcBadRequest plugged @@ -43,43 +40,6 @@ int (*SwappedUntrustedProcVector[256])( ClientPtr /*client*/ ); -/* Register with the security module, which allows an extension to store - * security state. The return value is the index which should be passed - * to the state macros, or -1 if no more slots are available. - */ -int XaceRegisterExtension(name) - char *name; -{ - int i; - for (i=0; ireplyBytesRemaining = 0; -#ifdef XACE - XACE_STATE_INIT(client->securityState); -#endif #ifdef XAPPGROUP client->appgroup = NULL; #endif diff --git a/dix/extension.c b/dix/extension.c index 40e1373b6..46b7e14b4 100644 --- a/dix/extension.c +++ b/dix/extension.c @@ -131,6 +131,7 @@ AddExtension(char *name, int NumEvents, int NumErrors, ext = (ExtensionEntry *) xalloc(totalExtensionSize); if (!ext || !InitExtensionPrivates(ext)) return((ExtensionEntry *) NULL); + bzero(ext, totalExtensionSize); ext->name = (char *)xalloc(strlen(name) + 1); ext->num_aliases = 0; ext->aliases = (char **)NULL; @@ -180,9 +181,6 @@ AddExtension(char *name, int NumEvents, int NumErrors, ext->errorBase = 0; ext->errorLast = 0; } -#ifdef XACE - XACE_STATE_INIT(ext->securityState); -#endif return(ext); } diff --git a/include/dixstruct.h b/include/dixstruct.h index 1ac7d84b6..a6f674990 100644 --- a/include/dixstruct.h +++ b/include/dixstruct.h @@ -130,9 +130,6 @@ typedef struct _Client { int requestLogIndex; #endif unsigned long replyBytesRemaining; -#ifdef XACE - pointer securityState[4]; /* 4 slots for use */ -#endif #ifdef XAPPGROUP struct _AppGroupRec* appgroup; #endif diff --git a/include/extnsionst.h b/include/extnsionst.h index 35aa97e1a..e28732f80 100644 --- a/include/extnsionst.h +++ b/include/extnsionst.h @@ -72,9 +72,6 @@ typedef struct _ExtensionEntry { unsigned short (* MinorOpcode)( /* called for errors */ ClientPtr /* client */); DevUnion *devPrivates; -#ifdef XACE - pointer securityState[4]; /* 4 slots for use */ -#endif } ExtensionEntry; /*