1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160
|
/*
* Copyright 1993 Network Computing Devices, Inc.
*
* 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, and that the name Network Computing Devices, Inc. not be
* used in advertising or publicity pertaining to distribution of this
* software without specific, written prior permission.
*
* THIS SOFTWARE IS PROVIDED `AS-IS'. NETWORK COMPUTING DEVICES, INC.,
* DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING WITHOUT
* LIMITATION ALL IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE, OR NONINFRINGEMENT. IN NO EVENT SHALL NETWORK
* COMPUTING DEVICES, INC., BE LIABLE FOR ANY DAMAGES WHATSOEVER, INCLUDING
* SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES, INCLUDING LOSS OF USE, DATA,
* OR PROFITS, EVEN IF ADVISED OF THE POSSIBILITY THEREOF, AND REGARDLESS OF
* WHETHER IN AN ACTION IN CONTRACT, TORT OR NEGLIGENCE, ARISING OUT OF OR IN
* CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*
* $NCDId: @(#)mitauth.c,v 1.2 1993/08/28 00:34:18 lemke Exp $
*/
/*
* Some portions derived from:
*
* MIT-MAGIC-COOKIE-1 authorization scheme
*
*
* Copyright 1988 Massachusetts Institute of Technology
*
* Permission to use, copy, modify, and distribute this software and its
* documentation for any purpose and without fee is hereby granted, provided
* that the above copyright notice appear in all copies and that both that
* copyright notice and this permission notice appear in supporting
* documentation, and that the name of M.I.T. not be used in advertising or
* publicity pertaining to distribution of the software without specific,
* written prior permission. M.I.T. makes no representations about the
* suitability of this software for any purpose. It is provided "as is"
* without express or implied warranty.
*
* Author: Keith Packard, MIT X Consortium
*/
#include <audio/audio.h>
#include "os.h"
static struct auth {
struct auth *next;
unsigned short len;
char *data;
AuID id;
} *mit_auth;
int
MitAddCookie (data_length, data, id)
unsigned short data_length;
char *data;
AuID id;
{
struct auth *new;
new = (struct auth *) xalloc (sizeof (struct auth));
if (!new)
return 0;
new->data = (char *) xalloc ((unsigned) data_length);
if (!new->data) {
xfree(new);
return 0;
}
new->next = mit_auth;
mit_auth = new;
bcopy (data, new->data, (int) data_length);
new->len = data_length;
new->id = id;
return 1;
}
AuID
MitCheckCookie (data_length, data)
unsigned short data_length;
char *data;
{
struct auth *auth;
for (auth = mit_auth; auth; auth=auth->next) {
if (data_length == auth->len &&
bcmp (data, auth->data, (int) data_length) == 0)
return auth->id;
}
return (AuID) -1;
}
int
MitResetCookie ()
{
struct auth *auth, *next;
for (auth = mit_auth; auth; auth=next) {
next = auth->next;
xfree (auth->data);
xfree (auth);
}
mit_auth = 0;
}
AuID
MitToID (data_length, data)
unsigned short data_length;
char *data;
{
struct auth *auth;
for (auth = mit_auth; auth; auth=auth->next) {
if (data_length == auth->len &&
bcmp (data, auth->data, data_length) == 0)
return auth->id;
}
return (AuID) -1;
}
MitFromID (id, data_lenp, datap)
AuID id;
unsigned short *data_lenp;
char **datap;
{
struct auth *auth;
for (auth = mit_auth; auth; auth=auth->next) {
if (id == auth->id) {
*data_lenp = auth->len;
*datap = auth->data;
return 1;
}
}
return 0;
}
MitRemoveCookie (data_length, data)
unsigned short data_length;
char *data;
{
struct auth *auth, *prev;
prev = 0;
for (auth = mit_auth; auth; auth=auth->next) {
if (data_length == auth->len &&
bcmp (data, auth->data, data_length) == 0)
{
if (prev)
prev->next = auth->next;
else
mit_auth = auth->next;
xfree (auth->data);
xfree (auth);
return 1;
}
}
return 0;
}
|