aboutsummaryrefslogtreecommitdiff
path: root/src/lib/krb5/krb/copy_princ.c
blob: ad13beb666ec02bd4d95c0f524fe49da2e199a99 (plain)
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
/*
 * $Source$
 * $Author$
 *
 * Copyright 1990 by the Massachusetts Institute of Technology.
 *
 * For copying and distribution information, please see the file
 * <krb5/copyright.h>.
 *
 * krb5_copy_principal()
 */

#if !defined(lint) && !defined(SABER)
static char rcsid_copy_princ_c[] =
"$Id$";
#endif	/* !lint & !SABER */

#include <krb5/copyright.h>
#include <krb5/krb5.h>

#include <krb5/ext-proto.h>

/*
 * Copy a principal structure, with fresh allocation.
 */
krb5_error_code
krb5_copy_principal(inprinc, outprinc)
krb5_const_principal inprinc;
krb5_principal *outprinc;
{
    krb5_error_code retval;
    krb5_principal tempprinc;
    register int nelems;

    for (nelems = 0; inprinc[nelems]; nelems++);

    /* one more for a null terminated list */
    if (!(tempprinc = (krb5_principal) calloc(nelems+1, sizeof(krb5_data *))))
	return ENOMEM;

    for (nelems = 0; inprinc[nelems]; nelems++)
	if (retval = krb5_copy_data(inprinc[nelems], &tempprinc[nelems])) {
	    krb5_free_principal(tempprinc);
	    return retval;
	}

    *outprinc = tempprinc;
    return 0;
}