Windows global stuff:
[krb5.git] / src / lib / krb5 / krb / copy_tick.c
1 /*
2  * lib/krb5/krb/copy_tick.c
3  *
4  * Copyright 1990,1991 by the Massachusetts Institute of Technology.
5  * All Rights Reserved.
6  *
7  * Export of this software from the United States of America may
8  *   require a specific license from the United States Government.
9  *   It is the responsibility of any person or organization contemplating
10  *   export to obtain such a license before exporting.
11  * 
12  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
13  * distribute this software and its documentation for any purpose and
14  * without fee is hereby granted, provided that the above copyright
15  * notice appear in all copies and that both that copyright notice and
16  * this permission notice appear in supporting documentation, and that
17  * the name of M.I.T. not be used in advertising or publicity pertaining
18  * to distribution of the software without specific, written prior
19  * permission.  M.I.T. makes no representations about the suitability of
20  * this software for any purpose.  It is provided "as is" without express
21  * or implied warranty.
22  * 
23  *
24  * krb5_copy_ticket()
25  */
26
27 #include "k5-int.h"
28
29 static krb5_error_code
30 krb5_copy_enc_tkt_part(context, partfrom, partto)
31     krb5_context context;
32     const krb5_enc_tkt_part *partfrom;
33     krb5_enc_tkt_part **partto;
34 {
35     krb5_error_code retval;
36     krb5_enc_tkt_part *tempto;
37
38     if (!(tempto = (krb5_enc_tkt_part *)malloc(sizeof(*tempto))))
39         return ENOMEM;
40     *tempto = *partfrom;
41     retval = krb5_copy_keyblock(context, partfrom->session,
42                                 &tempto->session);
43     if (retval) {
44         krb5_xfree(tempto);
45         return retval;
46     }
47     retval = krb5_copy_principal(context, partfrom->client, &tempto->client);
48     if (retval) {
49         krb5_free_keyblock(context, tempto->session);
50         krb5_xfree(tempto);
51         return retval;
52     }
53     tempto->transited = partfrom->transited;
54     if (tempto->transited.tr_contents.length == 0) {
55         tempto->transited.tr_contents.data = 0;
56     } else {
57         tempto->transited.tr_contents.data =
58           malloc(partfrom->transited.tr_contents.length);
59         if (!tempto->transited.tr_contents.data) {
60             krb5_free_principal(context, tempto->client);
61             krb5_free_keyblock(context, tempto->session);
62             krb5_xfree(tempto);
63             return ENOMEM;
64         }
65         memcpy((char *)tempto->transited.tr_contents.data,
66                (char *)partfrom->transited.tr_contents.data,
67                partfrom->transited.tr_contents.length);
68     }
69
70     retval = krb5_copy_addresses(context, partfrom->caddrs, &tempto->caddrs);
71     if (retval) {
72         krb5_xfree(tempto->transited.tr_contents.data);
73         krb5_free_principal(context, tempto->client);
74         krb5_free_keyblock(context, tempto->session);
75         krb5_xfree(tempto);
76         return retval;
77     }
78     if (partfrom->authorization_data) {
79         retval = krb5_copy_authdata(context, partfrom->authorization_data,
80                                     &tempto->authorization_data);
81         if (retval) {
82             krb5_free_addresses(context, tempto->caddrs);
83             krb5_xfree(tempto->transited.tr_contents.data);
84             krb5_free_principal(context, tempto->client);
85             krb5_free_keyblock(context, tempto->session);
86             krb5_xfree(tempto);
87             return retval;
88         }
89     }
90     *partto = tempto;
91     return 0;
92 }
93
94 krb5_error_code
95 krb5_copy_ticket(context, from, pto)
96     krb5_context context;
97     const krb5_ticket *from;
98     krb5_ticket **pto;
99 {
100     krb5_error_code retval;
101     krb5_ticket *tempto;
102     krb5_data *scratch;
103
104     if (!(tempto = (krb5_ticket *)malloc(sizeof(*tempto))))
105         return ENOMEM;
106     *tempto = *from;
107     retval = krb5_copy_principal(context, from->server, &tempto->server);
108     if (retval) {
109         krb5_xfree(tempto);
110         return retval;
111     }
112     retval = krb5_copy_data(context, &from->enc_part.ciphertext, &scratch);
113     if (retval) {
114         krb5_free_principal(context, tempto->server);
115         krb5_xfree(tempto);
116         return retval;
117     }
118     tempto->enc_part.ciphertext = *scratch;
119     krb5_xfree(scratch);
120     retval = krb5_copy_enc_tkt_part(context, from->enc_part2, &tempto->enc_part2);
121     if (retval) {
122         krb5_xfree(tempto->enc_part.ciphertext.data);
123         krb5_free_principal(context, tempto->server);
124         krb5_xfree(tempto);
125         return retval;
126     }   
127     *pto = tempto;
128     return 0;
129 }