1b528cefcSMark Murray /*
2*ae771770SStanislav Sedov * Copyright (c) 1997 - 2001 Kungliga Tekniska Högskolan
3b528cefcSMark Murray * (Royal Institute of Technology, Stockholm, Sweden).
4b528cefcSMark Murray * All rights reserved.
5b528cefcSMark Murray *
6b528cefcSMark Murray * Redistribution and use in source and binary forms, with or without
7b528cefcSMark Murray * modification, are permitted provided that the following conditions
8b528cefcSMark Murray * are met:
9b528cefcSMark Murray *
10b528cefcSMark Murray * 1. Redistributions of source code must retain the above copyright
11b528cefcSMark Murray * notice, this list of conditions and the following disclaimer.
12b528cefcSMark Murray *
13b528cefcSMark Murray * 2. Redistributions in binary form must reproduce the above copyright
14b528cefcSMark Murray * notice, this list of conditions and the following disclaimer in the
15b528cefcSMark Murray * documentation and/or other materials provided with the distribution.
16b528cefcSMark Murray *
17b528cefcSMark Murray * 3. Neither the name of the Institute nor the names of its contributors
18b528cefcSMark Murray * may be used to endorse or promote products derived from this software
19b528cefcSMark Murray * without specific prior written permission.
20b528cefcSMark Murray *
21b528cefcSMark Murray * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
22b528cefcSMark Murray * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23b528cefcSMark Murray * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24b528cefcSMark Murray * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
25b528cefcSMark Murray * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26b528cefcSMark Murray * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27b528cefcSMark Murray * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28b528cefcSMark Murray * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29b528cefcSMark Murray * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30b528cefcSMark Murray * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31b528cefcSMark Murray * SUCH DAMAGE.
32b528cefcSMark Murray */
33b528cefcSMark Murray
34b528cefcSMark Murray #include "krb5_locl.h"
35b528cefcSMark Murray
36*ae771770SStanislav Sedov KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_rd_error(krb5_context context,const krb5_data * msg,KRB_ERROR * result)37b528cefcSMark Murray krb5_rd_error(krb5_context context,
38c19800e8SDoug Rabson const krb5_data *msg,
39b528cefcSMark Murray KRB_ERROR *result)
40b528cefcSMark Murray {
41b528cefcSMark Murray
42b528cefcSMark Murray size_t len;
43b528cefcSMark Murray krb5_error_code ret;
44adb0ddaeSAssar Westerlund
45b528cefcSMark Murray ret = decode_KRB_ERROR(msg->data, msg->length, result, &len);
46c19800e8SDoug Rabson if(ret) {
47*ae771770SStanislav Sedov krb5_clear_error_message(context);
48b528cefcSMark Murray return ret;
49c19800e8SDoug Rabson }
50b528cefcSMark Murray result->error_code += KRB5KDC_ERR_NONE;
51b528cefcSMark Murray return 0;
52b528cefcSMark Murray }
53b528cefcSMark Murray
54*ae771770SStanislav Sedov KRB5_LIB_FUNCTION void KRB5_LIB_CALL
krb5_free_error_contents(krb5_context context,krb5_error * error)55b528cefcSMark Murray krb5_free_error_contents (krb5_context context,
56b528cefcSMark Murray krb5_error *error)
57b528cefcSMark Murray {
58b528cefcSMark Murray free_KRB_ERROR(error);
59c19800e8SDoug Rabson memset(error, 0, sizeof(*error));
60b528cefcSMark Murray }
61b528cefcSMark Murray
62*ae771770SStanislav Sedov KRB5_LIB_FUNCTION void KRB5_LIB_CALL
krb5_free_error(krb5_context context,krb5_error * error)63b528cefcSMark Murray krb5_free_error (krb5_context context,
64b528cefcSMark Murray krb5_error *error)
65b528cefcSMark Murray {
66b528cefcSMark Murray krb5_free_error_contents (context, error);
67b528cefcSMark Murray free (error);
68b528cefcSMark Murray }
69adb0ddaeSAssar Westerlund
70*ae771770SStanislav Sedov KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
krb5_error_from_rd_error(krb5_context context,const krb5_error * error,const krb5_creds * creds)71adb0ddaeSAssar Westerlund krb5_error_from_rd_error(krb5_context context,
72adb0ddaeSAssar Westerlund const krb5_error *error,
73adb0ddaeSAssar Westerlund const krb5_creds *creds)
74adb0ddaeSAssar Westerlund {
75adb0ddaeSAssar Westerlund krb5_error_code ret;
76adb0ddaeSAssar Westerlund
77adb0ddaeSAssar Westerlund ret = error->error_code;
78adb0ddaeSAssar Westerlund if (error->e_text != NULL) {
79*ae771770SStanislav Sedov krb5_set_error_message(context, ret, "%s", *error->e_text);
80adb0ddaeSAssar Westerlund } else {
81adb0ddaeSAssar Westerlund char clientname[256], servername[256];
82adb0ddaeSAssar Westerlund
83adb0ddaeSAssar Westerlund if (creds != NULL) {
84adb0ddaeSAssar Westerlund krb5_unparse_name_fixed(context, creds->client,
85adb0ddaeSAssar Westerlund clientname, sizeof(clientname));
86adb0ddaeSAssar Westerlund krb5_unparse_name_fixed(context, creds->server,
87adb0ddaeSAssar Westerlund servername, sizeof(servername));
88adb0ddaeSAssar Westerlund }
89adb0ddaeSAssar Westerlund
90adb0ddaeSAssar Westerlund switch (ret) {
91adb0ddaeSAssar Westerlund case KRB5KDC_ERR_NAME_EXP :
92*ae771770SStanislav Sedov krb5_set_error_message(context, ret,
93*ae771770SStanislav Sedov N_("Client %s%s%s expired", ""),
94adb0ddaeSAssar Westerlund creds ? "(" : "",
95adb0ddaeSAssar Westerlund creds ? clientname : "",
96adb0ddaeSAssar Westerlund creds ? ")" : "");
97adb0ddaeSAssar Westerlund break;
98adb0ddaeSAssar Westerlund case KRB5KDC_ERR_SERVICE_EXP :
99*ae771770SStanislav Sedov krb5_set_error_message(context, ret,
100*ae771770SStanislav Sedov N_("Server %s%s%s expired", ""),
101adb0ddaeSAssar Westerlund creds ? "(" : "",
102adb0ddaeSAssar Westerlund creds ? servername : "",
103adb0ddaeSAssar Westerlund creds ? ")" : "");
104adb0ddaeSAssar Westerlund break;
105adb0ddaeSAssar Westerlund case KRB5KDC_ERR_C_PRINCIPAL_UNKNOWN :
106*ae771770SStanislav Sedov krb5_set_error_message(context, ret,
107*ae771770SStanislav Sedov N_("Client %s%s%s unknown", ""),
108adb0ddaeSAssar Westerlund creds ? "(" : "",
109adb0ddaeSAssar Westerlund creds ? clientname : "",
110adb0ddaeSAssar Westerlund creds ? ")" : "");
111adb0ddaeSAssar Westerlund break;
112adb0ddaeSAssar Westerlund case KRB5KDC_ERR_S_PRINCIPAL_UNKNOWN :
113*ae771770SStanislav Sedov krb5_set_error_message(context, ret,
114*ae771770SStanislav Sedov N_("Server %s%s%s unknown", ""),
115adb0ddaeSAssar Westerlund creds ? "(" : "",
116adb0ddaeSAssar Westerlund creds ? servername : "",
117adb0ddaeSAssar Westerlund creds ? ")" : "");
118adb0ddaeSAssar Westerlund break;
119adb0ddaeSAssar Westerlund default :
120*ae771770SStanislav Sedov krb5_clear_error_message(context);
121adb0ddaeSAssar Westerlund break;
122adb0ddaeSAssar Westerlund }
123adb0ddaeSAssar Westerlund }
124adb0ddaeSAssar Westerlund return ret;
125adb0ddaeSAssar Westerlund }
126