xref: /illumos-gate/usr/src/lib/gss_mechs/mech_krb5/krb5/krb/mk_req.c (revision 7c478bd95313f5f23a4c958a745db2134aa03244)
1 /*
2  * Copyright 2002 Sun Microsystems, Inc.  All rights reserved.
3  * Use is subject to license terms.
4  */
5 
6 #pragma ident	"%Z%%M%	%I%	%E% SMI"
7 
8 /*
9  * lib/krb5/krb/mk_req.c
10  *
11  * Copyright 1990,1991 by the Massachusetts Institute of Technology.
12  * All Rights Reserved.
13  *
14  * Export of this software from the United States of America may
15  *   require a specific license from the United States Government.
16  *   It is the responsibility of any person or organization contemplating
17  *   export to obtain such a license before exporting.
18  *
19  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
20  * distribute this software and its documentation for any purpose and
21  * without fee is hereby granted, provided that the above copyright
22  * notice appear in all copies and that both that copyright notice and
23  * this permission notice appear in supporting documentation, and that
24  * the name of M.I.T. not be used in advertising or publicity pertaining
25  * to distribution of the software without specific, written prior
26  * permission.  Furthermore if you modify this software you must label
27  * your software as modified software and not distribute it in such a
28  * fashion that it might be confused with the original M.I.T. software.
29  * M.I.T. makes no representations about the suitability of
30  * this software for any purpose.  It is provided "as is" without express
31  * or implied warranty.
32  *
33  *
34  * krb5_mk_req() routine.
35  */
36 
37 #include <k5-int.h>
38 #include <auth_con.h>
39 
40 /*
41  Formats a KRB_AP_REQ message into outbuf.
42 
43  server specifies the principal of the server to receive the message; if
44  credentials are not present in the credentials cache for this server, the
45  TGS request with default parameters is used in an attempt to obtain
46  such credentials, and they are stored in ccache.
47 
48  kdc_options specifies the options requested for the
49  ap_req_options specifies the KRB_AP_REQ options desired.
50 
51  checksum specifies the checksum to be used in the authenticator.
52 
53  The outbuf buffer storage is allocated, and should be freed by the
54  caller when finished.
55 
56  returns system errors
57 */
58 
59 KRB5_DLLIMP krb5_error_code KRB5_CALLCONV
60 krb5_mk_req(context, auth_context, ap_req_options, service, hostname, in_data,
61 	      ccache, outbuf)
62     krb5_context          context;
63     krb5_auth_context   FAR * auth_context;
64     const krb5_flags      ap_req_options;
65     char		FAR * service;
66     char		FAR * hostname;
67     krb5_data           FAR * in_data;
68     krb5_ccache 	  ccache;
69     krb5_data 		FAR * outbuf;
70 {
71     krb5_error_code 	  retval;
72     krb5_principal	  server;
73     krb5_creds 		* credsp;
74     krb5_creds 		  creds;
75 
76     retval = krb5_sname_to_principal(context, hostname, service,
77 				     KRB5_NT_SRV_HST, &server);
78     if (retval)
79       return retval;
80 
81     /* obtain ticket & session key */
82     memset((char *)&creds, 0, sizeof(creds));
83     if ((retval = krb5_copy_principal(context, server, &creds.server)))
84 	goto cleanup_princ;
85 
86     if ((retval = krb5_cc_get_principal(context, ccache, &creds.client)) != 0)
87 	goto cleanup_creds;
88 
89     if ((retval = krb5_get_credentials(context, 0,
90 				       ccache, &creds, &credsp)) != 0)
91 	goto cleanup_creds;
92 
93     retval = krb5_mk_req_extended(context, auth_context, ap_req_options,
94 				  in_data, credsp, outbuf);
95 
96     krb5_free_creds(context, credsp);
97 
98 cleanup_creds:
99     krb5_free_cred_contents(context, &creds);
100 
101 cleanup_princ:
102     krb5_free_principal(context, server);
103 
104     return retval;
105 }
106