11901Swollman/*
21901Swollman * Copyright (c) 1997 - 1999 Kungliga Tekniska H��gskolan
31901Swollman * (Royal Institute of Technology, Stockholm, Sweden).
41901Swollman * All rights reserved.
51901Swollman *
61901Swollman * Redistribution and use in source and binary forms, with or without
71901Swollman * modification, are permitted provided that the following conditions
88870Srgrimes * are met:
91901Swollman *
101901Swollman * 1. Redistributions of source code must retain the above copyright
111901Swollman *    notice, this list of conditions and the following disclaimer.
128870Srgrimes *
131901Swollman * 2. Redistributions in binary form must reproduce the above copyright
141901Swollman *    notice, this list of conditions and the following disclaimer in the
151901Swollman *    documentation and/or other materials provided with the distribution.
168870Srgrimes *
171901Swollman * 3. Neither the name of the Institute nor the names of its contributors
181901Swollman *    may be used to endorse or promote products derived from this software
191901Swollman *    without specific prior written permission.
208870Srgrimes *
211901Swollman * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
221901Swollman * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
231901Swollman * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
248870Srgrimes * ARE DISCLAIMED.  IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
251901Swollman * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
261901Swollman * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
271901Swollman * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
281901Swollman * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
291901Swollman * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
301901Swollman * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
311901Swollman * SUCH DAMAGE.
321901Swollman */
3350476Speter
341901Swollman#include "kadm5_locl.h"
351901Swollman
361901SwollmanRCSID("$Id$");
371901Swollman
381901Swollmanvoid
391901Swollmankadm5_free_key_data(void *server_handle,
401901Swollman		    int16_t *n_key_data,
411901Swollman		    krb5_key_data *key_data)
421901Swollman{
431901Swollman    int i;
441901Swollman    for(i = 0; i < *n_key_data; i++){
451901Swollman	if(key_data[i].key_data_contents[0]){
461901Swollman	    memset(key_data[i].key_data_contents[0],
471901Swollman		   0,
481901Swollman		   key_data[i].key_data_length[0]);
491901Swollman	    free(key_data[i].key_data_contents[0]);
5021081Speter	}
5111666Sphk	if(key_data[i].key_data_contents[1])
521901Swollman	    free(key_data[i].key_data_contents[1]);
5311666Sphk    }
541901Swollman    *n_key_data = 0;
551901Swollman}
561901Swollman
571901Swollman
581901Swollmanvoid
591901Swollmankadm5_free_principal_ent(void *server_handle,
601901Swollman			 kadm5_principal_ent_t princ)
611901Swollman{
621901Swollman    kadm5_server_context *context = server_handle;
631901Swollman    if(princ->principal)
641901Swollman	krb5_free_principal(context->context, princ->principal);
651901Swollman    if(princ->mod_name)
661901Swollman	krb5_free_principal(context->context, princ->mod_name);
671901Swollman    kadm5_free_key_data(server_handle, &princ->n_key_data, princ->key_data);
681901Swollman    while(princ->n_tl_data && princ->tl_data) {
691901Swollman	krb5_tl_data *tp;
701901Swollman	tp = princ->tl_data;
711901Swollman	princ->tl_data = tp->tl_data_next;
721901Swollman	princ->n_tl_data--;
731901Swollman	memset(tp->tl_data_contents, 0, tp->tl_data_length);
741901Swollman	free(tp->tl_data_contents);
751901Swollman	free(tp);
761901Swollman    }
771901Swollman    if (princ->key_data != NULL)
781901Swollman	free (princ->key_data);
791901Swollman}
801901Swollman
811901Swollmanvoid
821901Swollmankadm5_free_name_list(void *server_handle,
831901Swollman		     char **names,
841901Swollman		     int *count)
851901Swollman{
861901Swollman    int i;
871901Swollman    for(i = 0; i < *count; i++)
881901Swollman	free(names[i]);
891901Swollman    free(names);
901901Swollman    *count = 0;
911901Swollman}
921901Swollman