2006-11-26 11:13:41 -07:00
|
|
|
/*
|
|
|
|
|
|
|
|
Copyright 1988, 1998 The Open Group
|
|
|
|
|
|
|
|
Permission to use, copy, modify, distribute, and sell this software and its
|
|
|
|
documentation for any purpose is hereby granted without fee, provided that
|
|
|
|
the above copyright notice appear in all copies and that both that
|
|
|
|
copyright notice and this permission notice appear in supporting
|
|
|
|
documentation.
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included
|
|
|
|
in all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
|
|
|
|
OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
|
|
|
|
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
|
|
|
|
OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
|
|
|
|
Except as contained in this notice, the name of The Open Group shall
|
|
|
|
not be used in advertising or otherwise to promote the sale, use or
|
|
|
|
other dealings in this Software without prior written authorization
|
|
|
|
from The Open Group.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* XDM-AUTHENTICATION-1 (XDMCP authentication) and
|
|
|
|
* XDM-AUTHORIZATION-1 (client authorization) protocols
|
|
|
|
*
|
|
|
|
* Author: Keith Packard, MIT X Consortium
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_DIX_CONFIG_H
|
|
|
|
#include <dix-config.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <X11/X.h>
|
|
|
|
#define XSERV_t
|
|
|
|
#define TRANS_SERVER
|
|
|
|
#define TRANS_REOPEN
|
|
|
|
#include <X11/Xtrans/Xtrans.h>
|
|
|
|
#include "os.h"
|
|
|
|
#include "osdep.h"
|
|
|
|
#include "dixstruct.h"
|
|
|
|
|
|
|
|
#ifdef HASXDMAUTH
|
|
|
|
|
|
|
|
static Bool authFromXDMCP;
|
|
|
|
|
|
|
|
#ifdef XDMCP
|
|
|
|
#include <X11/Xmd.h>
|
|
|
|
#undef REQUEST
|
|
|
|
#include <X11/Xdmcp.h>
|
|
|
|
|
|
|
|
/* XDM-AUTHENTICATION-1 */
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static XdmAuthKeyRec privateKey;
|
2006-11-26 11:13:41 -07:00
|
|
|
static char XdmAuthenticationName[] = "XDM-AUTHENTICATION-1";
|
2012-06-10 07:21:05 -06:00
|
|
|
|
2006-11-26 11:13:41 -07:00
|
|
|
#define XdmAuthenticationNameLen (sizeof XdmAuthenticationName - 1)
|
2014-09-27 11:52:59 -06:00
|
|
|
static XdmAuthKeyRec global_rho;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static Bool
|
|
|
|
XdmAuthenticationValidator(ARRAY8Ptr privateData, ARRAY8Ptr incomingData,
|
|
|
|
xdmOpCode packet_type)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmAuthKeyPtr incoming;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmcpUnwrap(incomingData->data, (unsigned char *) &privateKey,
|
|
|
|
incomingData->data, incomingData->length);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (packet_type == ACCEPT) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (incomingData->length != 8)
|
|
|
|
return FALSE;
|
|
|
|
incoming = (XdmAuthKeyPtr) incomingData->data;
|
|
|
|
XdmcpDecrementKey(incoming);
|
2014-09-27 11:52:59 -06:00
|
|
|
return XdmcpCompareKeys(incoming, &global_rho);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Bool
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmAuthenticationGenerator(ARRAY8Ptr privateData, ARRAY8Ptr outgoingData,
|
|
|
|
xdmOpCode packet_type)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
|
|
|
outgoingData->length = 0;
|
|
|
|
outgoingData->data = 0;
|
|
|
|
if (packet_type == REQUEST) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (XdmcpAllocARRAY8(outgoingData, 8))
|
2014-09-27 11:52:59 -06:00
|
|
|
XdmcpWrap((unsigned char *) &global_rho, (unsigned char *) &privateKey,
|
2012-06-10 07:21:05 -06:00
|
|
|
outgoingData->data, 8);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Bool
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmAuthenticationAddAuth(int name_len, const char *name,
|
|
|
|
int data_len, char *data)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
Bool ret;
|
|
|
|
|
|
|
|
XdmcpUnwrap((unsigned char *) data, (unsigned char *) &privateKey,
|
|
|
|
(unsigned char *) data, data_len);
|
2006-11-26 11:13:41 -07:00
|
|
|
authFromXDMCP = TRUE;
|
2012-06-10 07:21:05 -06:00
|
|
|
ret = AddAuthorization(name_len, name, data_len, data);
|
2006-11-26 11:13:41 -07:00
|
|
|
authFromXDMCP = FALSE;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define atox(c) ('0' <= c && c <= '9' ? c - '0' : \
|
|
|
|
'a' <= c && c <= 'f' ? c - 'a' + 10 : \
|
|
|
|
'A' <= c && c <= 'F' ? c - 'A' + 10 : -1)
|
|
|
|
|
|
|
|
static int
|
2012-06-10 07:21:05 -06:00
|
|
|
HexToBinary(const char *in, char *out, int len)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
int top, bottom;
|
|
|
|
|
|
|
|
while (len > 0) {
|
|
|
|
top = atox(in[0]);
|
|
|
|
if (top == -1)
|
|
|
|
return 0;
|
|
|
|
bottom = atox(in[1]);
|
|
|
|
if (bottom == -1)
|
|
|
|
return 0;
|
|
|
|
*out++ = (top << 4) | bottom;
|
|
|
|
in += 2;
|
|
|
|
len -= 2;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
if (len)
|
2012-06-10 07:21:05 -06:00
|
|
|
return 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
*out++ = '\0';
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmAuthenticationInit(const char *cookie, int cookie_len)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2010-12-05 08:36:02 -07:00
|
|
|
memset(privateKey.data, 0, 8);
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!strncmp(cookie, "0x", 2) || !strncmp(cookie, "0X", 2)) {
|
|
|
|
if (cookie_len > 2 + 2 * 8)
|
|
|
|
cookie_len = 2 + 2 * 8;
|
|
|
|
HexToBinary(cookie + 2, (char *) privateKey.data, cookie_len - 2);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
else {
|
|
|
|
if (cookie_len > 7)
|
|
|
|
cookie_len = 7;
|
|
|
|
memmove(privateKey.data + 1, cookie, cookie_len);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2014-09-27 11:52:59 -06:00
|
|
|
XdmcpGenerateKey(&global_rho);
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmcpRegisterAuthentication(XdmAuthenticationName, XdmAuthenticationNameLen,
|
2014-09-27 11:52:59 -06:00
|
|
|
(char *) &global_rho,
|
|
|
|
sizeof(global_rho),
|
2012-06-10 07:21:05 -06:00
|
|
|
(ValidatorFunc) XdmAuthenticationValidator,
|
|
|
|
(GeneratorFunc) XdmAuthenticationGenerator,
|
|
|
|
(AddAuthorFunc) XdmAuthenticationAddAuth);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
#endif /* XDMCP */
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* XDM-AUTHORIZATION-1 */
|
|
|
|
typedef struct _XdmAuthorization {
|
2012-06-10 07:21:05 -06:00
|
|
|
struct _XdmAuthorization *next;
|
|
|
|
XdmAuthKeyRec rho;
|
|
|
|
XdmAuthKeyRec key;
|
|
|
|
XID id;
|
2006-11-26 11:13:41 -07:00
|
|
|
} XdmAuthorizationRec, *XdmAuthorizationPtr;
|
|
|
|
|
|
|
|
static XdmAuthorizationPtr xdmAuth;
|
|
|
|
|
|
|
|
typedef struct _XdmClientAuth {
|
2012-06-10 07:21:05 -06:00
|
|
|
struct _XdmClientAuth *next;
|
|
|
|
XdmAuthKeyRec rho;
|
|
|
|
char client[6];
|
|
|
|
long time;
|
2006-11-26 11:13:41 -07:00
|
|
|
} XdmClientAuthRec, *XdmClientAuthPtr;
|
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
static XdmClientAuthPtr xdmClients;
|
|
|
|
static long clockOffset;
|
|
|
|
static Bool gotClock;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
#define TwentyMinutes (20 * 60)
|
|
|
|
#define TwentyFiveMinutes (25 * 60)
|
|
|
|
|
|
|
|
static Bool
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmClientAuthCompare(const XdmClientAuthPtr a, const XdmClientAuthPtr b)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
int i;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!XdmcpCompareKeys(&a->rho, &b->rho))
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
for (i = 0; i < 6; i++)
|
2012-06-10 07:21:05 -06:00
|
|
|
if (a->client[i] != b->client[i])
|
|
|
|
return FALSE;
|
2006-11-26 11:13:41 -07:00
|
|
|
return a->time == b->time;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmClientAuthDecode(const unsigned char *plain, XdmClientAuthPtr auth)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
int i, j;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
j = 0;
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i < 8; i++) {
|
|
|
|
auth->rho.data[i] = plain[j];
|
|
|
|
++j;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i < 6; i++) {
|
|
|
|
auth->client[i] = plain[j];
|
|
|
|
++j;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
auth->time = 0;
|
2012-06-10 07:21:05 -06:00
|
|
|
for (i = 0; i < 4; i++) {
|
|
|
|
auth->time |= plain[j] << ((3 - i) << 3);
|
|
|
|
j++;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmClientAuthTimeout(long now)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmClientAuthPtr client, next, prev;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
prev = 0;
|
2012-06-10 07:21:05 -06:00
|
|
|
for (client = xdmClients; client; client = next) {
|
|
|
|
next = client->next;
|
2015-11-07 09:48:51 -07:00
|
|
|
if (labs(now - client->time) > TwentyFiveMinutes) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (prev)
|
|
|
|
prev->next = next;
|
|
|
|
else
|
|
|
|
xdmClients = next;
|
|
|
|
free(client);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
prev = client;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static XdmClientAuthPtr
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmAuthorizationValidate(unsigned char *plain, int length,
|
|
|
|
XdmAuthKeyPtr rho, ClientPtr xclient,
|
|
|
|
const char **reason)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmClientAuthPtr client, existing;
|
|
|
|
long now;
|
|
|
|
int i;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
if (length != (192 / 8)) {
|
2012-06-10 07:21:05 -06:00
|
|
|
if (reason)
|
|
|
|
*reason = "Bad XDM authorization key length";
|
|
|
|
return NULL;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
client = malloc(sizeof(XdmClientAuthRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!client)
|
2012-06-10 07:21:05 -06:00
|
|
|
return NULL;
|
|
|
|
XdmClientAuthDecode(plain, client);
|
|
|
|
if (!XdmcpCompareKeys(&client->rho, rho)) {
|
|
|
|
free(client);
|
|
|
|
if (reason)
|
|
|
|
*reason = "Invalid XDM-AUTHORIZATION-1 key (failed key comparison)";
|
|
|
|
return NULL;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
for (i = 18; i < 24; i++)
|
2012-06-10 07:21:05 -06:00
|
|
|
if (plain[i] != 0) {
|
|
|
|
free(client);
|
|
|
|
if (reason)
|
|
|
|
*reason = "Invalid XDM-AUTHORIZATION-1 key (failed NULL check)";
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
if (xclient) {
|
2012-06-10 07:21:05 -06:00
|
|
|
int family, addr_len;
|
|
|
|
Xtransaddr *addr;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
if (_XSERVTransGetPeerAddr(((OsCommPtr) xclient->osPrivate)->trans_conn,
|
|
|
|
&family, &addr_len, &addr) == 0
|
|
|
|
&& _XSERVTransConvertAddress(&family, &addr_len, &addr) == 0) {
|
2006-11-26 11:13:41 -07:00
|
|
|
#if defined(TCPCONN) || defined(STREAMSCONN)
|
2012-06-10 07:21:05 -06:00
|
|
|
if (family == FamilyInternet &&
|
|
|
|
memcmp((char *) addr, client->client, 4) != 0) {
|
|
|
|
free(client);
|
|
|
|
free(addr);
|
|
|
|
if (reason)
|
|
|
|
*reason =
|
|
|
|
"Invalid XDM-AUTHORIZATION-1 key (failed address comparison)";
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
2012-06-10 07:21:05 -06:00
|
|
|
free(addr);
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
now = time(0);
|
2012-06-10 07:21:05 -06:00
|
|
|
if (!gotClock) {
|
|
|
|
clockOffset = client->time - now;
|
|
|
|
gotClock = TRUE;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
now += clockOffset;
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmClientAuthTimeout(now);
|
2015-11-07 09:48:51 -07:00
|
|
|
if (labs(client->time - now) > TwentyMinutes) {
|
2012-06-10 07:21:05 -06:00
|
|
|
free(client);
|
|
|
|
if (reason)
|
|
|
|
*reason = "Excessive XDM-AUTHORIZATION-1 time offset";
|
|
|
|
return NULL;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
for (existing = xdmClients; existing; existing = existing->next) {
|
|
|
|
if (XdmClientAuthCompare(existing, client)) {
|
|
|
|
free(client);
|
|
|
|
if (reason)
|
|
|
|
*reason = "XDM authorization key matches an existing client!";
|
|
|
|
return NULL;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return client;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmAddCookie(unsigned short data_length, const char *data, XID id)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmAuthorizationPtr new;
|
|
|
|
unsigned char *rho_bits, *key_bits;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
switch (data_length) {
|
|
|
|
case 16: /* auth from files is 16 bytes long */
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef XDMCP
|
2012-06-10 07:21:05 -06:00
|
|
|
if (authFromXDMCP) {
|
|
|
|
/* R5 xdm sent bogus authorization data in the accept packet,
|
|
|
|
* but we can recover */
|
2014-09-27 11:52:59 -06:00
|
|
|
rho_bits = global_rho.data;
|
2012-06-10 07:21:05 -06:00
|
|
|
key_bits = (unsigned char *) data;
|
|
|
|
key_bits[0] = '\0';
|
|
|
|
}
|
|
|
|
else
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
2012-06-10 07:21:05 -06:00
|
|
|
{
|
|
|
|
rho_bits = (unsigned char *) data;
|
|
|
|
key_bits = (unsigned char *) (data + 8);
|
|
|
|
}
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef XDMCP
|
2012-06-10 07:21:05 -06:00
|
|
|
case 8: /* auth from XDMCP is 8 bytes long */
|
2014-09-27 11:52:59 -06:00
|
|
|
rho_bits = global_rho.data;
|
2012-06-10 07:21:05 -06:00
|
|
|
key_bits = (unsigned char *) data;
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
default:
|
2012-06-10 07:21:05 -06:00
|
|
|
return 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
/* the first octet of the key must be zero */
|
|
|
|
if (key_bits[0] != '\0')
|
2012-06-10 07:21:05 -06:00
|
|
|
return 0;
|
|
|
|
new = malloc(sizeof(XdmAuthorizationRec));
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!new)
|
2012-06-10 07:21:05 -06:00
|
|
|
return 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
new->next = xdmAuth;
|
|
|
|
xdmAuth = new;
|
2012-06-10 07:21:05 -06:00
|
|
|
memmove(new->key.data, key_bits, (int) 8);
|
|
|
|
memmove(new->rho.data, rho_bits, (int) 8);
|
2006-11-26 11:13:41 -07:00
|
|
|
new->id = id;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
XID
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmCheckCookie(unsigned short cookie_length, const char *cookie,
|
|
|
|
ClientPtr xclient, const char **reason)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmAuthorizationPtr auth;
|
|
|
|
XdmClientAuthPtr client;
|
|
|
|
unsigned char *plain;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
|
|
|
/* Auth packets must be a multiple of 8 bytes long */
|
|
|
|
if (cookie_length & 7)
|
2012-06-10 07:21:05 -06:00
|
|
|
return (XID) -1;
|
2010-12-05 08:36:02 -07:00
|
|
|
plain = malloc(cookie_length);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!plain)
|
2012-06-10 07:21:05 -06:00
|
|
|
return (XID) -1;
|
|
|
|
for (auth = xdmAuth; auth; auth = auth->next) {
|
|
|
|
XdmcpUnwrap((unsigned char *) cookie, (unsigned char *) &auth->key,
|
|
|
|
plain, cookie_length);
|
|
|
|
if ((client =
|
|
|
|
XdmAuthorizationValidate(plain, cookie_length, &auth->rho, xclient,
|
|
|
|
reason)) != NULL) {
|
|
|
|
client->next = xdmClients;
|
|
|
|
xdmClients = client;
|
|
|
|
free(plain);
|
|
|
|
return auth->id;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
free(plain);
|
2006-11-26 11:13:41 -07:00
|
|
|
return (XID) -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmResetCookie(void)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmAuthorizationPtr auth, next_auth;
|
|
|
|
XdmClientAuthPtr client, next_client;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
for (auth = xdmAuth; auth; auth = next_auth) {
|
|
|
|
next_auth = auth->next;
|
|
|
|
free(auth);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
xdmAuth = 0;
|
2012-06-10 07:21:05 -06:00
|
|
|
for (client = xdmClients; client; client = next_client) {
|
|
|
|
next_client = client->next;
|
|
|
|
free(client);
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
xdmClients = (XdmClientAuthPtr) 0;
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
XID
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmToID(unsigned short cookie_length, char *cookie)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmAuthorizationPtr auth;
|
|
|
|
XdmClientAuthPtr client;
|
|
|
|
unsigned char *plain;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2010-12-05 08:36:02 -07:00
|
|
|
plain = malloc(cookie_length);
|
2006-11-26 11:13:41 -07:00
|
|
|
if (!plain)
|
2012-06-10 07:21:05 -06:00
|
|
|
return (XID) -1;
|
|
|
|
for (auth = xdmAuth; auth; auth = auth->next) {
|
|
|
|
XdmcpUnwrap((unsigned char *) cookie, (unsigned char *) &auth->key,
|
|
|
|
plain, cookie_length);
|
|
|
|
if ((client =
|
|
|
|
XdmAuthorizationValidate(plain, cookie_length, &auth->rho, NULL,
|
|
|
|
NULL)) != NULL) {
|
|
|
|
free(client);
|
|
|
|
free(cookie);
|
|
|
|
free(plain);
|
|
|
|
return auth->id;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2010-12-05 08:36:02 -07:00
|
|
|
free(cookie);
|
|
|
|
free(plain);
|
2006-11-26 11:13:41 -07:00
|
|
|
return (XID) -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmFromID(XID id, unsigned short *data_lenp, char **datap)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmAuthorizationPtr auth;
|
|
|
|
|
|
|
|
for (auth = xdmAuth; auth; auth = auth->next) {
|
|
|
|
if (id == auth->id) {
|
|
|
|
*data_lenp = 16;
|
|
|
|
*datap = (char *) &auth->rho;
|
|
|
|
return 1;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmRemoveCookie(unsigned short data_length, const char *data)
|
2006-11-26 11:13:41 -07:00
|
|
|
{
|
2012-06-10 07:21:05 -06:00
|
|
|
XdmAuthorizationPtr auth;
|
|
|
|
XdmAuthKeyPtr key_bits, rho_bits;
|
2006-11-26 11:13:41 -07:00
|
|
|
|
2012-06-10 07:21:05 -06:00
|
|
|
switch (data_length) {
|
2006-11-26 11:13:41 -07:00
|
|
|
case 16:
|
2012-06-10 07:21:05 -06:00
|
|
|
rho_bits = (XdmAuthKeyPtr) data;
|
|
|
|
key_bits = (XdmAuthKeyPtr) (data + 8);
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
#ifdef XDMCP
|
|
|
|
case 8:
|
2014-09-27 11:52:59 -06:00
|
|
|
rho_bits = &global_rho;
|
2012-06-10 07:21:05 -06:00
|
|
|
key_bits = (XdmAuthKeyPtr) data;
|
|
|
|
break;
|
2006-11-26 11:13:41 -07:00
|
|
|
#endif
|
|
|
|
default:
|
2012-06-10 07:21:05 -06:00
|
|
|
return 0;
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
2012-06-10 07:21:05 -06:00
|
|
|
for (auth = xdmAuth; auth; auth = auth->next) {
|
|
|
|
if (XdmcpCompareKeys(rho_bits, &auth->rho) &&
|
|
|
|
XdmcpCompareKeys(key_bits, &auth->key)) {
|
|
|
|
xdmAuth = auth->next;
|
|
|
|
free(auth);
|
|
|
|
return 1;
|
|
|
|
}
|
2006-11-26 11:13:41 -07:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|