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