--- /dev/null
+/*
+ * $Source$
+ * $Author$
+ *
+ * Copyright 1990 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/mit-copyright.h>.
+ *
+ * krb5_copy_cred()
+ */
+
+#if !defined(lint) && !defined(SABER)
+static char rcsid_copy_cred_c [] =
+"$Id$";
+#endif /* !lint & !SABER */
+
+#include <krb5/copyright.h>
+
+#include <krb5/krb5.h>
+
+#include <krb5/ext-proto.h>
+
+#include <errno.h>
+
+
+/*
+ * Copy credentials, allocating fresh storage where needed.
+ */
+
+krb5_error_code
+krb5_copy_cred(incred, outcred)
+krb5_creds *incred, **outcred;
+{
+ krb5_creds *tempcred;
+ krb5_error_code retval;
+ krb5_data *scratch;
+
+ if (!(tempcred = (krb5_creds *)malloc(sizeof(*tempcred))))
+ return ENOMEM;
+
+ *tempcred = *incred; /* copy everything quickly */
+ if (retval = krb5_copy_principal(incred->client, &tempcred->client))
+ goto cleanlast;
+ if (retval = krb5_copy_principal(incred->server, &tempcred->server))
+ goto cleanclient;
+ if (retval = krb5_copy_keyblock(&incred->keyblock, &tempcred->keyblock))
+ goto cleanserver;
+ if (retval = krb5_copy_data(&incred->ticket, &scratch))
+ goto cleanblock;
+ tempcred->ticket = *scratch;
+ free((char *)scratch);
+ if (retval = krb5_copy_data(&incred->second_ticket,
+ &scratch))
+ goto cleanticket;
+
+ tempcred->second_ticket = *scratch;
+ free((char *)scratch);
+
+ *outcred = tempcred;
+ return 0;
+
+ cleanticket:
+ free(tempcred->ticket.data);
+ cleanblock:
+ free((char *)tempcred->keyblock.contents);
+ cleanserver:
+ krb5_free_principal(tempcred->server);
+ cleanclient:
+ krb5_free_principal(tempcred->client);
+ cleanlast:
+ free((char *)tempcred);
+ return retval;
+}
--- /dev/null
+/*
+ * $Source$
+ * $Author$
+ *
+ * Copyright 1990 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/mit-copyright.h>.
+ *
+ * krb5_copy_data()
+ */
+
+#if !defined(lint) && !defined(SABER)
+static char rcsid_copy_data_c[] =
+"$Id$";
+#endif /* !lint & !SABER */
+
+#include <krb5/copyright.h>
+#include <krb5/krb5.h>
+#include <errno.h>
+#include <krb5/ext-proto.h>
+
+/*
+ * Copy a data structure, with fresh allocation.
+ */
+krb5_error_code
+krb5_copy_data(indata, outdata)
+krb5_data *indata, **outdata;
+{
+ krb5_data *tempdata;
+
+ if (!(tempdata = (krb5_data *)malloc(sizeof(*tempdata))))
+ return ENOMEM;
+
+ *tempdata = *indata;
+ if (!(tempdata->data = malloc(tempdata->length))) {
+ free((char *)tempdata);
+ return ENOMEM;
+ }
+ bcopy((char *)indata->data, (char *)tempdata->data, tempdata->length);
+ *outdata = tempdata;
+ return 0;
+}
--- /dev/null
+/*
+ * $Source$
+ * $Author$
+ *
+ * Copyright 1990 by the Massachusetts Institute of Technology.
+ *
+ * For copying and distribution information, please see the file
+ * <krb5/mit-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 <errno.h>
+
+#include <krb5/ext-proto.h>
+
+/*
+ * Copy a principal structure, with fresh allocation.
+ */
+krb5_error_code
+krb5_copy_principal(inprinc, outprinc)
+krb5_principal inprinc, *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 ENOMEM;
+ }
+
+ *outprinc = tempprinc;
+ return 0;
+}