xref: /illumos-gate/usr/src/uts/common/gssapi/mechs/krb5/mech/util_set.c (revision 2d6eb4a5e0a47d30189497241345dc5466bb68ab)
1*ab9b2e15Sgtb /*
2*ab9b2e15Sgtb  * Copyright 2007 Sun Microsystems, Inc.  All rights reserved.
3*ab9b2e15Sgtb  * Use is subject to license terms.
4*ab9b2e15Sgtb  */
5*ab9b2e15Sgtb 
67c478bd9Sstevel@tonic-gate /*
77c478bd9Sstevel@tonic-gate  * Copyright 1995 by OpenVision Technologies, Inc.
87c478bd9Sstevel@tonic-gate  *
97c478bd9Sstevel@tonic-gate  * Permission to use, copy, modify, distribute, and sell this software
107c478bd9Sstevel@tonic-gate  * and its documentation for any purpose is hereby granted without fee,
117c478bd9Sstevel@tonic-gate  * provided that the above copyright notice appears in all copies and
127c478bd9Sstevel@tonic-gate  * that both that copyright notice and this permission notice appear in
137c478bd9Sstevel@tonic-gate  * supporting documentation, and that the name of OpenVision not be used
147c478bd9Sstevel@tonic-gate  * in advertising or publicity pertaining to distribution of the software
157c478bd9Sstevel@tonic-gate  * without specific, written prior permission. OpenVision makes no
167c478bd9Sstevel@tonic-gate  * representations about the suitability of this software for any
177c478bd9Sstevel@tonic-gate  * purpose.  It is provided "as is" without express or implied warranty.
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * OPENVISION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
207c478bd9Sstevel@tonic-gate  * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
217c478bd9Sstevel@tonic-gate  * EVENT SHALL OPENVISION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
227c478bd9Sstevel@tonic-gate  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
237c478bd9Sstevel@tonic-gate  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
247c478bd9Sstevel@tonic-gate  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
257c478bd9Sstevel@tonic-gate  * PERFORMANCE OF THIS SOFTWARE.
267c478bd9Sstevel@tonic-gate  */
277c478bd9Sstevel@tonic-gate 
287c478bd9Sstevel@tonic-gate /*
29*ab9b2e15Sgtb  * $Id: util_set.c 16165 2004-03-14 05:31:43Z raeburn $
307c478bd9Sstevel@tonic-gate  */
317c478bd9Sstevel@tonic-gate 
32*ab9b2e15Sgtb #include <mechglueP.h>  /* SUNW15resync - for MALLOC/FREE */
33*ab9b2e15Sgtb #include "gssapiP_generic.h"
347c478bd9Sstevel@tonic-gate 
35*ab9b2e15Sgtb struct _g_set_elt {
367c478bd9Sstevel@tonic-gate    void *key;
377c478bd9Sstevel@tonic-gate    void *value;
38*ab9b2e15Sgtb    struct _g_set_elt *next;
397c478bd9Sstevel@tonic-gate };
407c478bd9Sstevel@tonic-gate 
g_set_init(g_set_elt * s)41*ab9b2e15Sgtb int g_set_init(g_set_elt *s)
427c478bd9Sstevel@tonic-gate {
437c478bd9Sstevel@tonic-gate    *s = NULL;
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate    return(0);
467c478bd9Sstevel@tonic-gate }
477c478bd9Sstevel@tonic-gate 
48*ab9b2e15Sgtb #if 0
49*ab9b2e15Sgtb int g_set_destroy(g_set_elt *s)
507c478bd9Sstevel@tonic-gate {
517c478bd9Sstevel@tonic-gate    g_set next;
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate    while (*s) {
547c478bd9Sstevel@tonic-gate       next = (*s)->next;
557c478bd9Sstevel@tonic-gate       FREE(*s, sizeof(struct _g_set));
567c478bd9Sstevel@tonic-gate       *s = next;
577c478bd9Sstevel@tonic-gate    }
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate    return(0);
607c478bd9Sstevel@tonic-gate }
61*ab9b2e15Sgtb #endif
627c478bd9Sstevel@tonic-gate 
g_set_entry_add(g_set_elt * s,void * key,void * value)63*ab9b2e15Sgtb int g_set_entry_add(g_set_elt *s, void *key, void *value)
647c478bd9Sstevel@tonic-gate {
65*ab9b2e15Sgtb    g_set_elt first;
667c478bd9Sstevel@tonic-gate 
67*ab9b2e15Sgtb    if ((first = (struct _g_set_elt *) MALLOC(sizeof(struct _g_set_elt))) == NULL)
687c478bd9Sstevel@tonic-gate       return(ENOMEM);
697c478bd9Sstevel@tonic-gate 
707c478bd9Sstevel@tonic-gate    first->key = key;
717c478bd9Sstevel@tonic-gate    first->value = value;
727c478bd9Sstevel@tonic-gate    first->next = *s;
737c478bd9Sstevel@tonic-gate 
747c478bd9Sstevel@tonic-gate    *s = first;
757c478bd9Sstevel@tonic-gate 
767c478bd9Sstevel@tonic-gate    return(0);
777c478bd9Sstevel@tonic-gate }
787c478bd9Sstevel@tonic-gate 
g_set_entry_delete(g_set_elt * s,void * key)79*ab9b2e15Sgtb int g_set_entry_delete(g_set_elt *s, void *key)
807c478bd9Sstevel@tonic-gate {
81*ab9b2e15Sgtb    g_set_elt *p;
827c478bd9Sstevel@tonic-gate 
837c478bd9Sstevel@tonic-gate    for (p=s; *p; p = &((*p)->next)) {
847c478bd9Sstevel@tonic-gate       if ((*p)->key == key) {
85*ab9b2e15Sgtb 	 g_set_elt next = (*p)->next;
86*ab9b2e15Sgtb 	 FREE(*p, sizeof(struct _g_set_elt));
877c478bd9Sstevel@tonic-gate 	 *p = next;
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate 	 return(0);
907c478bd9Sstevel@tonic-gate       }
917c478bd9Sstevel@tonic-gate    }
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate    return(-1);
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate 
g_set_entry_get(g_set_elt * s,void * key,void ** value)96*ab9b2e15Sgtb int g_set_entry_get(g_set_elt *s, void *key, void **value)
977c478bd9Sstevel@tonic-gate {
98*ab9b2e15Sgtb    g_set_elt p;
997c478bd9Sstevel@tonic-gate 
1007c478bd9Sstevel@tonic-gate    for (p = *s; p; p = p->next) {
1017c478bd9Sstevel@tonic-gate       if (p->key == key) {
1027c478bd9Sstevel@tonic-gate 	 *value = p->value;
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate 	 return(0);
1057c478bd9Sstevel@tonic-gate       }
1067c478bd9Sstevel@tonic-gate    }
1077c478bd9Sstevel@tonic-gate 
1087c478bd9Sstevel@tonic-gate    *value = NULL;
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate    return(-1);
1117c478bd9Sstevel@tonic-gate }
112