1 /* $XConsortium: secauth.c /main/4 1996/11/27 16:57:14 swick $ */
3 Copyright (c) 1996 X Consortium
5 Permission is hereby granted, free of charge, to any person obtaining
6 a copy of this software and associated documentation files (the
7 "Software"), to deal in the Software without restriction, including
8 without limitation the rights to use, copy, modify, merge, publish,
9 distribute, sublicense, and sell copies of the Software, and to
10 permit persons to whom the Software is furnished to do so, subject to
11 the following conditions:
13 The above copyright notice and this permission notice shall be included
14 in all copies or substantial portions of the Software.
16 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 IN NO EVENT SHALL THE X CONSORTIUM BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 OTHER DEALINGS IN THE SOFTWARE.
24 Except as contained in this notice, the name of the X Consortium shall
25 not be used in advertising or otherwise to promote the sale, use or
26 other dealings in this Software without prior written authorization
27 from the X Consortium.
33 #include "dixstruct.h"
35 /*================================================================
36 BEGIN ORL VNC modification
37 Need function prototype for SecurityGetSitePolicyStrings even when
38 XCSECURITY isn't defined */
43 #define _SECURITY_SERVER
44 #include "extensions/security.h"
49 /* END ORL VNC modification
50 ================================================================*/
52 static char InvalidPolicyReason[] = "invalid policy specification";
53 static char PolicyViolationReason[] = "policy violation";
56 AuthCheckSitePolicy(data_lengthP, dataP, client, reason)
57 unsigned short *data_lengthP;
62 char *policy = *dataP;
70 if ((length = *data_lengthP) < 2) {
71 *reason = InvalidPolicyReason;
75 permit = (*policy++ == 0);
76 nPolicies = *policy++;
80 sitePolicies = SecurityGetSitePolicyStrings(&nSitePolicies);
83 int strLen, sitePolicy;
86 *reason = InvalidPolicyReason;
91 if (--length < strLen) {
92 *reason = InvalidPolicyReason;
98 for (sitePolicy = 0; sitePolicy < nSitePolicies; sitePolicy++)
100 char *testPolicy = sitePolicies[sitePolicy];
101 if ((strLen == strlen(testPolicy)) &&
102 (strncmp(policy, testPolicy, strLen) == 0))
104 found = TRUE; /* need to continue parsing the policy... */
117 *reason = PolicyViolationReason;
121 *data_lengthP = length;
127 AuthSecurityCheck (data_length, data, client, reason)
128 unsigned short data_length;
134 OsCommPtr oc = (OsCommPtr)client->osPrivate;
135 register ConnectionInputPtr oci = oc->input;
136 xConnSetupPrefix csp;
139 if (client->clientState == ClientStateCheckedSecurity)
141 *reason = "repeated security check not permitted";
144 else if (data_length > 0)
146 char policy_mask = *data++;
148 if (--data_length == 1) {
149 *reason = InvalidPolicyReason;
153 if (policy_mask & 0x01) /* Extensions policy */
155 /* AuthCheckExtensionPolicy(&data_length, &data, client, reason) */
156 *reason = "security policy not implemented";
160 if (policy_mask & 0x02) /* Site policy */
162 if (!AuthCheckSitePolicy(&data_length, &data, client, reason))
166 if (data_length > 0) { /* did we consume the whole policy? */
167 *reason = InvalidPolicyReason;
172 else if (!GetAccessControl())
174 *reason = "server host access control is disabled";
178 client->clientState = ClientStateCheckingSecurity;
180 csp.success = 2 /* Authenticate */;
181 csp.lengthReason = 0;
183 csp.majorVersion = X_PROTOCOL;
184 csp.minorVersion = X_PROTOCOL_REVISION;
186 WriteSConnSetupPrefix(client, &csp);
188 (void)WriteToClient(client, sz_xConnSetupPrefix, (char *) &csp);
191 * Next time the client sends the real auth data, we want
192 * ProcEstablishConnection to be called.
196 freq.length = (sz_xReq + sz_xConnClientPrefix) >> 2;
197 client->swapped = FALSE;
198 if (!InsertFakeRequest(client, (char *)&freq, sz_xReq))
200 *reason = "internal error";
206 *reason = "method not supported";