First import
[xorg_rtime.git] / xorg-server-1.4 / hw / xwin / winauth.c
blobb57a35abfbf514b6bf3463a5f4148ca016c5aca0
1 #ifdef HAVE_XWIN_CONFIG_H
2 #include <xwin-config.h>
3 #endif
4 #if defined(XCSECURITY)
5 /*
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
35 #include "win.h"
37 /* Includes for authorization */
38 #include <X11/Xauth.h>
39 #include "securitysrv.h"
40 #include <X11/extensions/securstr.h>
44 * Constants
47 #define AUTH_NAME "MIT-MAGIC-COOKIE-1"
51 * Globals
54 XID g_authId = 0;
55 unsigned int g_uiAuthDataLen = 0;
56 char *g_pAuthData = NULL;
60 * Generate authorization cookie for internal server clients
63 Bool
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),
71 AUTH_NAME,
73 NULL,
74 &g_uiAuthDataLen,
75 &g_pAuthData);
76 if ((XID) ~0L == g_authId)
78 ErrorF ("winGenerateAuthorization - GenerateAuthorization failed\n");
79 goto auth_bailout;
81 #if 0
82 else
84 ErrorF ("winGenerateAuthorization - GenerateAuthorization success!\n"
85 "AuthDataLen: %d AuthData: %s\n",
86 g_uiAuthDataLen, g_pAuthData);
88 #endif
90 /* Allocate structure for additional auth information */
91 pAuth = (SecurityAuthorizationPtr)
92 xalloc (sizeof (SecurityAuthorizationRec));
93 if (!(pAuth))
95 ErrorF ("winGenerateAuthorization - Failed allocating "
96 "SecurityAuthorizationPtr.\n");
97 goto auth_bailout;
100 /* Fill in the auth fields */
101 pAuth->id = g_authId;
102 pAuth->timeout = 0; /* live for x seconds after refcnt == 0 */
103 pAuth->group = None;
104 pAuth->trustLevel = XSecurityClientTrusted;
105 pAuth->refcnt = 1; /* this auth must stick around */
106 pAuth->secondsRemaining = 0;
107 pAuth->timer = NULL;
108 pAuth->eventClients = NULL;
110 /* Add the authorization to the server's auth list */
111 if (!AddResource (g_authId,
112 SecurityAuthorizationResType,
113 pAuth))
115 ErrorF ("winGenerateAuthorization - AddResource failed for auth.\n");
116 fFreeAuth = TRUE;
117 goto auth_bailout;
120 /* Don't free the auth data, since it is still used internally */
121 pAuth = NULL;
123 return TRUE;
125 auth_bailout:
126 if (fFreeAuth)
127 xfree (pAuth);
129 return FALSE;
131 #endif