1 /* -*- mode: c; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2 /*
3 * Copyright 2009 by the Massachusetts Institute of Technology. All
4 * Rights Reserved.
5 *
6 * Export of this software from the United States of America may
7 * require a specific license from the United States Government.
8 * It is the responsibility of any person or organization contemplating
9 * export to obtain such a license before exporting.
10 *
11 * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
12 * distribute this software and its documentation for any purpose and
13 * without fee is hereby granted, provided that the above copyright
14 * notice appear in all copies and that both that copyright notice and
15 * this permission notice appear in supporting documentation, and that
16 * the name of M.I.T. not be used in advertising or publicity pertaining
17 * to distribution of the software without specific, written prior
18 * permission. Furthermore if you modify this software you must label
19 * your software as modified software and not distribute it in such a
20 * fashion that it might be confused with the original M.I.T. software.
21 * M.I.T. makes no representations about the suitability of
22 * this software for any purpose. It is provided "as is" without express
23 * or implied warranty.
24 *
25 * krb5_authdata_export_authdata()
26 */
27
28 #include "k5-int.h"
29 #include "authdata.h"
30 #include "auth_con.h"
31 #include "int-proto.h"
32
33 krb5_error_code KRB5_CALLCONV
krb5_authdata_export_authdata(krb5_context kcontext,krb5_authdata_context context,krb5_flags flags,krb5_authdata *** pauthdata)34 krb5_authdata_export_authdata(krb5_context kcontext,
35 krb5_authdata_context context,
36 krb5_flags flags,
37 krb5_authdata ***pauthdata)
38 {
39 int i;
40 krb5_error_code code = 0;
41 krb5_authdata **authdata = NULL;
42 unsigned int len = 0;
43
44 *pauthdata = NULL;
45
46 for (i = 0; i < context->n_modules; i++) {
47 struct _krb5_authdata_context_module *module = &context->modules[i];
48 krb5_authdata **authdata2 = NULL;
49 int j;
50
51 if ((module->flags & flags) == 0)
52 continue;
53
54 if (module->ftable->export_authdata == NULL)
55 continue;
56
57 code = (*module->ftable->export_authdata)(kcontext,
58 context,
59 module->plugin_context,
60 *(module->request_context_pp),
61 flags,
62 &authdata2);
63 if (code == ENOENT)
64 code = 0;
65 else if (code != 0)
66 break;
67
68 if (authdata2 == NULL)
69 continue;
70
71 for (j = 0; authdata2[j] != NULL; j++)
72 ;
73
74 authdata = realloc(authdata, (len + j + 1) * sizeof(krb5_authdata *));
75 if (authdata == NULL)
76 return ENOMEM;
77
78 memcpy(&authdata[len], authdata2, j * sizeof(krb5_authdata *));
79 free(authdata2);
80
81 len += j;
82 }
83
84 if (authdata != NULL)
85 authdata[len] = NULL;
86
87 if (code != 0) {
88 krb5_free_authdata(kcontext, authdata);
89 return code;
90 }
91
92 *pauthdata = authdata;
93
94 return 0;
95 }
96