NetIDMgr updates
[krb5.git] / src / windows / identity / plugins / krb4 / errorfuncs.c
1 /*\r
2  * Copyright (c) 2005 Massachusetts Institute of Technology\r
3  *\r
4  * Permission is hereby granted, free of charge, to any person\r
5  * obtaining a copy of this software and associated documentation\r
6  * files (the "Software"), to deal in the Software without\r
7  * restriction, including without limitation the rights to use, copy,\r
8  * modify, merge, publish, distribute, sublicense, and/or sell copies\r
9  * of the Software, and to permit persons to whom the Software is\r
10  * furnished to do so, subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be\r
13  * included in all copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
19  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
20  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
22  * SOFTWARE.\r
23  */\r
24 \r
25 /* $Id$ */\r
26 \r
27 #include<krbcred.h>\r
28 #include<kherror.h>\r
29 \r
30 #include<strsafe.h>\r
31 \r
32 extern void (__cdecl *pinitialize_krb_error_func)();\r
33 extern void (__cdecl *pinitialize_kadm_error_table)();\r
34 \r
35 \r
36 khm_int32 init_error_funcs()\r
37 {\r
38 \r
39 #if 0\r
40     /*TODO: Do something about this */\r
41     if (plsh_LoadKrb4LeashErrorTables)\r
42             plsh_LoadKrb4LeashErrorTables(hLeashInst, 0);\r
43 #endif\r
44     return KHM_ERROR_SUCCESS;\r
45 }\r
46 \r
47 khm_int32 exit_error_funcs()\r
48 {\r
49     return KHM_ERROR_SUCCESS;\r
50 }\r
51 \r
52 // Global Variables.\r
53 static long lsh_errno;\r
54 static char *err_context;       /* error context */\r
55 extern int (*Lcom_err)(LPSTR,long,LPSTR,...);\r
56 extern LPSTR (*Lerror_message)(long);\r
57 extern LPSTR (*Lerror_table_name)(long);\r
58 \r
59 #ifdef WIN16\r
60 #define UNDERSCORE "_"\r
61 #else\r
62 #define UNDERSCORE\r
63 #endif\r
64 \r
65 HWND GetRootParent (HWND Child)\r
66 {\r
67     HWND Last = NULL;\r
68     while (Child)\r
69     {\r
70         Last = Child;\r
71         Child = GetParent (Child);\r
72     }\r
73     return Last;\r
74 }\r
75 \r
76 \r
77 LPSTR err_describe(LPSTR buf, size_t len, long code)\r
78 {\r
79     LPSTR cp, com_err_msg;\r
80     int offset;\r
81     long table_num;\r
82     char *etype;\r
83 \r
84     offset = (int) (code & 255);\r
85     table_num = code - offset;\r
86     com_err_msg = Lerror_message(code);\r
87 \r
88     switch(table_num)\r
89     {\r
90     case krb_err_base:\r
91     case kadm_err_base:\r
92         break;\r
93     default:\r
94         StringCbCopyA(buf, len, com_err_msg);\r
95         return buf;\r
96     }\r
97 \r
98     cp = buf;\r
99     if (table_num == krb_err_base)\r
100         switch(offset)\r
101         {\r
102         case KDC_NAME_EXP:           /* 001 Principal expired */\r
103         case KDC_SERVICE_EXP:        /* 002 Service expired */\r
104         case KDC_AUTH_EXP:           /* 003 Auth expired */\r
105         case KDC_PKT_VER:            /* 004 Protocol version unknown */\r
106         case KDC_P_MKEY_VER:         /* 005 Wrong master key version */\r
107         case KDC_S_MKEY_VER:         /* 006 Wrong master key version */\r
108         case KDC_BYTE_ORDER:         /* 007 Byte order unknown */\r
109         case KDC_PR_N_UNIQUE:        /* 009 Principal not unique */\r
110         case KDC_NULL_KEY:           /* 010 Principal has null key */\r
111         case KDC_GEN_ERR:            /* 011 Generic error from KDC */\r
112         case INTK_W_NOTALL   :       /* 061 Not ALL tickets returned */\r
113         case INTK_PROT       :       /* 063 Protocol Error */\r
114         case INTK_ERR        :       /* 070 Other error */\r
115             com_err_msg = "Something weird happened... try again, and if Leash"\r
116                 " continues to fail, contact Network Services as listed in the "\r
117                 "About box.";\r
118             break;\r
119         case KDC_PR_UNKNOWN:         /* 008 Principal unknown */\r
120             com_err_msg = "You have entered an unknown username/instance/realm"\r
121                 " combination.";\r
122             break;\r
123         case GC_TKFIL                :       /* 021 Can't read ticket file */\r
124         case GC_NOTKT                :       /* 022 Can't find ticket or TGT */\r
125             com_err_msg = "Something is wrong with the memory where your "\r
126                 "tickets are stored. Try exiting Windows and restarting your "\r
127                 "computer.";\r
128             break;\r
129         case MK_AP_TGTEXP    :       /* 026 TGT Expired */\r
130             /* no extra error msg */\r
131             break;\r
132         case RD_AP_TIME              :       /* 037 delta_t too big */\r
133             com_err_msg = "Your computer's clock is out of sync with the "\r
134                 "Kerberos server.  Please see the help file about correcting "\r
135                 "your clock.";\r
136             break;\r
137 \r
138         case RD_AP_UNDEC             :       /* 031 Can't decode authenticator */\r
139         case RD_AP_EXP               :       /* 032 Ticket expired */\r
140         case RD_AP_NYV               :       /* 033 Ticket not yet valid */\r
141         case RD_AP_REPEAT    :       /* 034 Repeated request */\r
142         case RD_AP_NOT_US    :       /* 035 The ticket isn't for us */\r
143         case RD_AP_INCON             :       /* 036 Request is inconsistent */\r
144         case RD_AP_BADD              :       /* 038 Incorrect net address */\r
145         case RD_AP_VERSION   :       /* 039 protocol version mismatch */\r
146         case RD_AP_MSG_TYPE  :       /* 040 invalid msg type */\r
147         case RD_AP_MODIFIED  :       /* 041 message stream modified */\r
148         case RD_AP_ORDER             :       /* 042 message out of order */\r
149         case RD_AP_UNAUTHOR  :       /* 043 unauthorized request */\r
150             /* no extra error msg */\r
151             break;\r
152         case GT_PW_NULL:     /* 51    Current PW is null */\r
153         case GT_PW_BADPW:    /* 52    Incorrect current password */\r
154         case GT_PW_PROT:     /* 53    Protocol Error */\r
155         case GT_PW_KDCERR:   /* 54    Error returned by KDC */\r
156         case GT_PW_NULLTKT:  /* 55    Null tkt returned by KDC */\r
157             /* no error msg yet */\r
158             break;\r
159           \r
160             /* Values returned by send_to_kdc */\r
161         case SKDC_RETRY   :  /* 56    Retry count exceeded */\r
162         case SKDC_CANT    :  /* 57    Can't send request */\r
163             com_err_msg = "Cannot contact the kerberos server for the selected realm.";\r
164             break;\r
165             /* no error message on purpose: */\r
166         case INTK_BADPW      :       /* 062 Incorrect password */\r
167             break;\r
168         default:\r
169             /* no extra error msg */\r
170             break;\r
171         }\r
172     else\r
173         switch(code)\r
174         {\r
175         case KADM_INSECURE_PW:\r
176             /* if( kadm_info != NULL ){\r
177              * wsprintf(buf, "%s\n%s", com_err_msg, kadm_info);\r
178              * } else {\r
179              * wsprintf(buf, "%s\nPlease see the help file for information "\r
180              * "about secure passwords.", com_err_msg);\r
181              * }\r
182              * com_err_msg = buf;\r
183              */\r
184 \r
185             /* The above code would be preferred since it allows site specific\r
186              * information to be delivered from the Kerberos server. However the\r
187              * message box is too small for VGA screens.\r
188              * It does work well if we only have to support 1024x768\r
189              */\r
190         \r
191             com_err_msg = "You have entered an insecure or weak password.";\r
192         \r
193         default:\r
194             /* no extra error msg */\r
195             break;\r
196         }\r
197     if(com_err_msg != buf) {\r
198         StringCbCopyA(buf, len, com_err_msg);\r
199     }\r
200     cp = buf + strlen(buf);\r
201     *cp++ = '\n';\r
202     switch(table_num) {\r
203     case krb_err_base:\r
204         etype = "Kerberos";\r
205         break;\r
206     case kadm_err_base:\r
207         etype = "Kerberos supplemental";\r
208         break;\r
209     default:\r
210         etype = Lerror_table_name(table_num);\r
211         break;\r
212     }\r
213     StringCbPrintfA((LPSTR) cp, len - (cp-buf), (LPSTR) "(%s error %d"\r
214 #ifdef DEBUG_COM_ERR\r
215              " (absolute error %ld)"\r
216 #endif\r
217              ")", etype, offset\r
218              //")\nPress F1 for help on this error.", etype, offset\r
219 #ifdef DEBUG_COM_ERR \r
220              , code\r
221 #endif\r
222         );\r
223   \r
224     return (LPSTR)buf;\r
225 }\r
226 \r