Ignore the coding style change commit during git blame
[xserver.git] / hw / xwin / winauth.c
blob5bc5a7316c9f19a2384895b47c0edd1da8e7c4e6
1 /*
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>
33 #endif
35 #include "winauth.h"
36 #include "winmsg.h"
38 /* Includes for authorization */
39 #include "securitysrv.h"
40 #include "os/osdep.h"
41 #include "os/mitauth.h"
43 #include <xcb/xcb.h>
46 * Constants
49 #define AUTH_NAME "MIT-MAGIC-COOKIE-1"
52 * Locals
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
64 #ifndef XCSECURITY
65 XID
66 GenerateAuthorization(unsigned name_length,
67 const char *name,
68 unsigned data_length,
69 const char *data,
70 unsigned *data_length_return, char **data_return)
72 return MitGenerateCookie(data_length, data,
73 FakeClientID(0), data_length_return, data_return);
75 #endif
78 * Generate authorization cookie for internal server clients
81 BOOL
82 winGenerateAuthorization(void)
84 #ifdef XCSECURITY
85 SecurityAuthorizationPtr pAuth = NULL;
86 #endif
88 /* Call OS layer to generate authorization key */
89 g_authId = GenerateAuthorization(strlen(AUTH_NAME),
90 AUTH_NAME,
91 0, NULL, &g_uiAuthDataLen, &g_pAuthData);
92 if ((XID) ~0L == g_authId) {
93 ErrorF("winGenerateAuthorization - GenerateAuthorization failed\n");
94 return FALSE;
97 else {
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;
108 #ifdef XCSECURITY
109 /* Allocate structure for additional auth information */
110 pAuth = (SecurityAuthorizationPtr)
111 malloc(sizeof(SecurityAuthorizationRec));
112 if (!(pAuth)) {
113 ErrorF("winGenerateAuthorization - Failed allocating "
114 "SecurityAuthorizationPtr.\n");
115 return FALSE;
118 /* Fill in the auth fields */
119 pAuth->id = g_authId;
120 pAuth->timeout = 0; /* live for x seconds after refcnt == 0 */
121 pAuth->group = None;
122 pAuth->trustLevel = XSecurityClientTrusted;
123 pAuth->refcnt = 1; /* this auth must stick around */
124 pAuth->secondsRemaining = 0;
125 pAuth->timer = NULL;
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");
131 return FALSE;
133 #endif
135 return TRUE;
138 xcb_auth_info_t *
139 winGetXcbAuthInfo(void)
141 if (g_pAuthData)
142 return &auth_info;
144 return NULL;