1 #ifdef HAVE_XWIN_CONFIG_H
2 #include <xwin-config.h>
4 #if defined(XCSECURITY)
6 *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
8 *Permission is hereby granted, free of charge, to any person obtaining
9 * a copy of this software and associated documentation files (the
10 *"Software"), to deal in the Software without restriction, including
11 *without limitation the rights to use, copy, modify, merge, publish,
12 *distribute, sublicense, and/or sell copies of the Software, and to
13 *permit persons to whom the Software is furnished to do so, subject to
14 *the following conditions:
16 *The above copyright notice and this permission notice shall be
17 *included in all copies or substantial portions of the Software.
19 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
20 *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
22 *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
23 *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
24 *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
25 *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 *Except as contained in this notice, the name of Harold L Hunt II
28 *shall not be used in advertising or otherwise to promote the sale, use
29 *or other dealings in this Software without prior written authorization
30 *from Harold L Hunt II.
32 * Authors: Harold L Hunt II
37 /* Includes for authorization */
38 #include <X11/Xauth.h>
39 #include "securitysrv.h"
40 #include <X11/extensions/securstr.h>
47 #define AUTH_NAME "MIT-MAGIC-COOKIE-1"
55 unsigned int g_uiAuthDataLen
= 0;
56 char *g_pAuthData
= NULL
;
60 * Generate authorization cookie for internal server clients
64 winGenerateAuthorization ()
66 Bool fFreeAuth
= FALSE
;
67 SecurityAuthorizationPtr pAuth
= NULL
;
69 /* Call OS layer to generate authorization key */
70 g_authId
= GenerateAuthorization (strlen (AUTH_NAME
),
76 if ((XID
) ~0L == g_authId
)
78 ErrorF ("winGenerateAuthorization - GenerateAuthorization failed\n");
84 ErrorF ("winGenerateAuthorization - GenerateAuthorization success!\n"
85 "AuthDataLen: %d AuthData: %s\n",
86 g_uiAuthDataLen
, g_pAuthData
);
90 /* Allocate structure for additional auth information */
91 pAuth
= (SecurityAuthorizationPtr
)
92 xalloc (sizeof (SecurityAuthorizationRec
));
95 ErrorF ("winGenerateAuthorization - Failed allocating "
96 "SecurityAuthorizationPtr.\n");
100 /* Fill in the auth fields */
101 pAuth
->id
= g_authId
;
102 pAuth
->timeout
= 0; /* live for x seconds after refcnt == 0 */
104 pAuth
->trustLevel
= XSecurityClientTrusted
;
105 pAuth
->refcnt
= 1; /* this auth must stick around */
106 pAuth
->secondsRemaining
= 0;
108 pAuth
->eventClients
= NULL
;
110 /* Add the authorization to the server's auth list */
111 if (!AddResource (g_authId
,
112 SecurityAuthorizationResType
,
115 ErrorF ("winGenerateAuthorization - AddResource failed for auth.\n");
120 /* Don't free the auth data, since it is still used internally */