From: Marc Horowitz Date: Fri, 12 Apr 1996 00:40:24 +0000 (+0000) Subject: Integrated OpenVision's changes into the most recent MIT code. This X-Git-Tag: krb5-1.0-beta6~219 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=8c52f12d549bf919078def74f25f36fd921f521a;p=krb5.git Integrated OpenVision's changes into the most recent MIT code. This revision is what I'd call the easy stuff. Some more controversial stuff remains to be done, which is why I'm doing a checkin now. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@7797 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/lib/gssapi/generic/util_localhost.c b/src/lib/gssapi/generic/util_localhost.c new file mode 100644 index 000000000..13856e320 --- /dev/null +++ b/src/lib/gssapi/generic/util_localhost.c @@ -0,0 +1,50 @@ +/* + * Copyright 1993 by OpenVision Technologies, 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 appears in all copies and + * that both that copyright notice and this permission notice appear in + * supporting documentation, and that the name of OpenVision not be used + * in advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. OpenVision makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF + * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * $Id$ + */ + +/* This file could be OS specific */ + +#include + +#include "gssapiP_generic.h" + +#ifndef MAXHOSTNAMELEN +#define MAXHOSTNAMELEN 64 +#endif + +char *g_local_host_name() +{ + char buf[MAXHOSTNAMELEN+1], *ptr; + + if (gethostname(buf, sizeof(buf)) < 0) + return 0; + + buf[sizeof(buf)-1] = '\0'; + + if (! (ptr = xmalloc(strlen(buf) + 1))) + return 0; + + return strcpy(ptr, buf); +} diff --git a/src/lib/gssapi/generic/util_ordering.c b/src/lib/gssapi/generic/util_ordering.c new file mode 100644 index 000000000..2a9e82bf2 --- /dev/null +++ b/src/lib/gssapi/generic/util_ordering.c @@ -0,0 +1,177 @@ +/* + * Copyright 1993 by OpenVision Technologies, 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 appears in all copies and + * that both that copyright notice and this permission notice appear in + * supporting documentation, and that the name of OpenVision not be used + * in advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. OpenVision makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF + * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * $Id$ + */ + +/* + * functions to check sequence numbers for replay and sequencing + */ + +#include "gssapiP_generic.h" + +#define QUEUE_LENGTH 20 + +typedef struct _queue { + int do_replay; + int do_sequence; + int start; + int length; + unsigned int firstnum; + unsigned int elem[QUEUE_LENGTH]; +} queue; + +/* rep invariant: + * - the queue is a circular queue. The first element (q->elem[q->start]) + * is the oldest. The last element is the newest. + */ + +#define QSIZE(q) (sizeof((q)->elem)/sizeof((q)->elem[0])) +#define QELEM(q,i) ((q)->elem[(i)%QSIZE(q)]) + +static void +queue_insert(queue *q, int after, unsigned int seqnum) +{ + /* insert. this is not the fastest way, but it's easy, and it's + optimized for insert at end, which is the common case */ + int i; + + /* common case: at end, after == q->start+q->length-1 */ + + /* move all the elements (after,last] up one slot */ + + for (i=q->start+q->length-1; i>after; i--) + QELEM(q,i+1) = QELEM(q,i); + + /* fill in slot after+1 */ + + QELEM(q,after+1) = seqnum; + + /* Either increase the length by one, or move the starting point up + one (deleting the first element, which got bashed above), as + appropriate. */ + + if (q->length == QSIZE(q)) { + q->start++; + if (q->start == QSIZE(q)) + q->start = 0; + } else { + q->length++; + } +} + +OM_uint32 +g_order_init(void **vqueue, unsigned int seqnum, + int do_replay, int do_sequence) +{ + queue *q; + + if ((q = (queue *) malloc(sizeof(queue))) == NULL) + return(ENOMEM); + + q->do_replay = do_replay; + q->do_sequence = do_sequence; + + q->start = 0; + q->length = 1; + q->firstnum = seqnum; + q->elem[q->start] = seqnum-1; + + *vqueue = (void *) q; + return(0); +} + +OM_uint32 +g_order_check(void **vqueue, unsigned int seqnum) +{ + queue *q; + int i; + + q = (queue *) (*vqueue); + + if (!q->do_replay && !q->do_sequence) + return(GSS_S_COMPLETE); + + /* rule 1: expected sequence number */ + + if (seqnum == QELEM(q,q->start+q->length-1)+1) { + queue_insert(q, q->start+q->length-1, seqnum); + return(GSS_S_COMPLETE); + } + + /* rule 2: > expected sequence number */ + + if ((seqnum > QELEM(q,q->start+q->length-1)+1) || + (seqnum < q->firstnum)) { + queue_insert(q, q->start+q->length-1, seqnum); + if (q->do_replay && !q->do_sequence) + return(GSS_S_COMPLETE); + else + return(GSS_S_GAP_TOKEN); + } + + /* rule 3: seqnum < seqnum(first) */ + + if ((seqnum < QELEM(q,q->start)) && + (seqnum >= q->firstnum)) { + if (q->do_replay && !q->do_sequence) + return(GSS_S_OLD_TOKEN); + else + return(GSS_S_UNSEQ_TOKEN); + } + + /* rule 4+5: seqnum in [seqnum(first),seqnum(last)] */ + + else { + if (seqnum == QELEM(q,q->start+q->length-1)) + return(GSS_S_DUPLICATE_TOKEN); + + for (i=q->start; istart+q->length-1; i++) { + if (seqnum == QELEM(q,i)) + return(GSS_S_DUPLICATE_TOKEN); + if ((seqnum > QELEM(q,i)) && (seqnum < QELEM(q,i+1))) { + queue_insert(q, i, seqnum); + if (q->do_replay && !q->do_sequence) + return(GSS_S_COMPLETE); + else + return(GSS_S_UNSEQ_TOKEN); + } + } + } + + /* this should never happen */ + return(GSS_S_FAILURE); +} + +void +g_order_free(void **vqueue) +{ + queue *q; + int i; + + q = (queue *) (*vqueue); + + free(q); + + *vqueue = NULL; +} diff --git a/src/lib/gssapi/generic/util_set.c b/src/lib/gssapi/generic/util_set.c new file mode 100644 index 000000000..169ccb28a --- /dev/null +++ b/src/lib/gssapi/generic/util_set.c @@ -0,0 +1,103 @@ +/* + * Copyright 1995 by OpenVision Technologies, 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 appears in all copies and + * that both that copyright notice and this permission notice appear in + * supporting documentation, and that the name of OpenVision not be used + * in advertising or publicity pertaining to distribution of the software + * without specific, written prior permission. OpenVision makes no + * representations about the suitability of this software for any + * purpose. It is provided "as is" without express or implied warranty. + * + * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO + * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR + * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF + * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR + * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR + * PERFORMANCE OF THIS SOFTWARE. + */ + +/* + * $Id$ + */ + +#include "gssapiP_generic.h" + +struct _g_set { + void *key; + void *value; + struct _g_set *next; +}; + +int g_set_init(g_set *s) +{ + *s = NULL; + + return(0); +} + +int g_set_destroy(g_set *s) +{ + g_set next; + + while (*s) { + next = (*s)->next; + free(*s); + *s = next; + } + + return(0); +} + +int g_set_entry_add(g_set *s, void *key, void *value) +{ + g_set first; + + if ((first = (struct _g_set *) malloc(sizeof(struct _g_set))) == NULL) + return(ENOMEM); + + first->key = key; + first->value = value; + first->next = *s; + + *s = first; + + return(0); +} + +int g_set_entry_delete(g_set *s, void *key) +{ + g_set *p; + + for (p=s; *p; p = &((*p)->next)) { + if ((*p)->key == key) { + g_set next = (*p)->next; + free(*p); + *p = next; + + return(0); + } + } + + return(-1); +} + +int g_set_entry_get(g_set *s, void *key, void **value) +{ + g_set p; + + for (p = *s; p; p = p->next) { + if (p->key == key) { + *value = p->value; + + return(0); + } + } + + *value = NULL; + + return(-1); +}