*** empty log message ***
authorJohn Kohl <jtkohl@mit.edu>
Tue, 27 Mar 1990 11:54:33 +0000 (11:54 +0000)
committerJohn Kohl <jtkohl@mit.edu>
Tue, 27 Mar 1990 11:54:33 +0000 (11:54 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@423 dc483132-0cff-0310-8789-dd5450dbe970

src/lib/krb5/krb/copy_creds.c [new file with mode: 0644]
src/lib/krb5/krb/copy_data.c [new file with mode: 0644]
src/lib/krb5/krb/copy_princ.c [new file with mode: 0644]

diff --git a/src/lib/krb5/krb/copy_creds.c b/src/lib/krb5/krb/copy_creds.c
new file mode 100644 (file)
index 0000000..46e9a1c
--- /dev/null
@@ -0,0 +1,74 @@
+/*
+ * $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;
+}
diff --git a/src/lib/krb5/krb/copy_data.c b/src/lib/krb5/krb/copy_data.c
new file mode 100644 (file)
index 0000000..7a84e5f
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * $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;
+}
diff --git a/src/lib/krb5/krb/copy_princ.c b/src/lib/krb5/krb/copy_princ.c
new file mode 100644 (file)
index 0000000..c450b90
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * $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;
+}