2 * lib/krb5/krb/mk_req.c
4 * Copyright 1990,1991 by the Massachusetts Institute of Technology.
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.
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.
24 * krb5_mk_req() routine.
31 Formats a KRB_AP_REQ message into outbuf.
33 server specifies the principal of the server to receive the message; if
34 credentials are not present in the credentials cache for this server, the
35 TGS request with default parameters is used in an attempt to obtain
36 such credentials, and they are stored in ccache.
38 kdc_options specifies the options requested for the
39 ap_req_options specifies the KRB_AP_REQ options desired.
41 checksum specifies the checksum to be used in the authenticator.
43 The outbuf buffer storage is allocated, and should be freed by the
49 extern krb5_flags krb5_kdc_default_options;
51 krb5_error_code INTERFACE
52 krb5_mk_req(context, auth_context, ap_req_options, service, hostname, in_data,
55 krb5_auth_context ** auth_context;
56 const krb5_flags ap_req_options;
63 krb5_error_code retval;
64 krb5_principal server;
70 if (retval = krb5_get_host_realm(context, hostname, &realm))
74 if (retval = krb5_build_principal(context, &server, strlen(realm[0]),
75 realm[0], service, hostname, NULL))
78 /* obtain ticket & session key */
79 memset((char *)&creds, 0, sizeof(creds));
80 if (retval = krb5_copy_principal(context, server, &creds.server))
83 if (retval = krb5_cc_get_principal(context, ccache, &creds.client))
86 if (retval = krb5_get_credentials(context, krb5_kdc_default_options,
87 ccache, &creds, &credsp))
90 retval = krb5_mk_req_extended(context, auth_context, ap_req_options,
91 in_data, credsp, outbuf);
93 krb5_free_creds(context, credsp);
96 krb5_free_cred_contents(context, &creds);
99 krb5_free_principal(context, server);
102 krb5_free_host_realm(context, realm);