2 *Copyright (C) 2003-2004 Harold L Hunt II All Rights Reserved.
4 *Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 *"Software"), to deal in the Software without restriction, including
7 *without limitation the rights to use, copy, modify, merge, publish,
8 *distribute, sublicense, and/or sell copies of the Software, and to
9 *permit persons to whom the Software is furnished to do so, subject to
10 *the following conditions:
12 *The above copyright notice and this permission notice shall be
13 *included in all copies or substantial portions of the Software.
15 *THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 *EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 *MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 *NONINFRINGEMENT. IN NO EVENT SHALL HAROLD L HUNT II BE LIABLE FOR
19 *ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
20 *CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21 *WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 *Except as contained in this notice, the name of Harold L Hunt II
24 *shall not be used in advertising or otherwise to promote the sale, use
25 *or other dealings in this Software without prior written authorization
26 *from Harold L Hunt II.
28 * Authors: Harold L Hunt II
31 #ifdef HAVE_XWIN_CONFIG_H
32 #include <xwin-config.h>
38 /* Includes for authorization */
39 #include "securitysrv.h"
41 #include "os/mitauth.h"
49 #define AUTH_NAME "MIT-MAGIC-COOKIE-1"
55 static XID g_authId
= 0;
56 static unsigned int g_uiAuthDataLen
= 0;
57 static char *g_pAuthData
= NULL
;
58 static xcb_auth_info_t auth_info
;
61 * Code to generate a MIT-MAGIC-COOKIE-1, copied from under XCSECURITY
66 GenerateAuthorization(unsigned name_length
,
70 unsigned *data_length_return
, char **data_return
)
72 return MitGenerateCookie(data_length
, data
,
73 FakeClientID(0), data_length_return
, data_return
);
78 * Generate authorization cookie for internal server clients
82 winGenerateAuthorization(void)
85 SecurityAuthorizationPtr pAuth
= NULL
;
88 /* Call OS layer to generate authorization key */
89 g_authId
= GenerateAuthorization(strlen(AUTH_NAME
),
91 0, NULL
, &g_uiAuthDataLen
, &g_pAuthData
);
92 if ((XID
) ~0L == g_authId
) {
93 ErrorF("winGenerateAuthorization - GenerateAuthorization failed\n");
98 winDebug("winGenerateAuthorization - GenerateAuthorization success!\n"
99 "AuthDataLen: %d AuthData: %s\n",
100 g_uiAuthDataLen
, g_pAuthData
);
103 auth_info
.name
= strdup(AUTH_NAME
);
104 auth_info
.namelen
= strlen(AUTH_NAME
);
105 auth_info
.data
= g_pAuthData
;
106 auth_info
.datalen
= g_uiAuthDataLen
;
109 /* Allocate structure for additional auth information */
110 pAuth
= (SecurityAuthorizationPtr
)
111 malloc(sizeof(SecurityAuthorizationRec
));
113 ErrorF("winGenerateAuthorization - Failed allocating "
114 "SecurityAuthorizationPtr.\n");
118 /* Fill in the auth fields */
119 pAuth
->id
= g_authId
;
120 pAuth
->timeout
= 0; /* live for x seconds after refcnt == 0 */
122 pAuth
->trustLevel
= XSecurityClientTrusted
;
123 pAuth
->refcnt
= 1; /* this auth must stick around */
124 pAuth
->secondsRemaining
= 0;
126 pAuth
->eventClients
= NULL
;
128 /* Add the authorization to the server's auth list */
129 if (!AddResource(g_authId
, SecurityAuthorizationResType
, pAuth
)) {
130 ErrorF("winGenerateAuthorization - AddResource failed for auth.\n");
139 winGetXcbAuthInfo(void)