8764ee8eaca47a4620491e1c20960f6e2cb8b73c
[openafs.git] / src / WINNT / afsd / afskfw-int.h
1 /*
2 * Copyright (c) 2004, 2005, 2006, 2007 Secure Endpoints Inc.
3 * Copyright (c) 2003 SkyRope, LLC
4  * All rights reserved.
5  * 
6  * Redistribution and use in source and binary forms, with or without 
7  * modification, are permitted provided that the following conditions are met:
8  * 
9  * - Redistributions of source code must retain the above copyright notice, 
10  *   this list of conditions and the following disclaimer.
11  * - Redistributions in binary form must reproduce the above copyright notice, 
12  *   this list of conditions and the following disclaimer in the documentation 
13  *   and/or other materials provided with the distribution.
14  * - Neither the name of Skyrope, LLC nor the names of its contributors may be 
15  *   used to endorse or promote products derived from this software without 
16  *   specific prior written permission from Skyrope, LLC.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
20  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
21  * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
22  * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29  *
30  * Portions of this code are derived from portions of the MIT
31  * Leash Ticket Manager and LoadFuncs utilities.  For these portions the
32  * following copyright applies.
33  *
34  * Copyright (c) 2003,2004 by the Massachusetts Institute of Technology.
35  * All rights reserved.
36  *
37  * Export of this software from the United States of America may
38  *   require a specific license from the United States Government.
39  *   It is the responsibility of any person or organization contemplating
40  *   export to obtain such a license before exporting.
41  *
42  * WITHIN THAT CONSTRAINT, permission to use, copy, modify, and
43  * distribute this software and its documentation for any purpose and
44  * without fee is hereby granted, provided that the above copyright
45  * notice appear in all copies and that both that copyright notice and
46  * this permission notice appear in supporting documentation, and that
47  * the name of M.I.T. not be used in advertising or publicity pertaining
48  * to distribution of the software without specific, written prior
49  * permission.  Furthermore if you modify this software you must label
50  * your software as modified software and not distribute it in such a
51  * fashion that it might be confused with the original M.I.T. software.
52  * M.I.T. makes no representations about the suitability of
53  * this software for any purpose.  It is provided "as is" without express
54  * or implied warranty.
55  *
56  */
57
58 #ifndef AFSKRB5_INT_H
59 #define AFSKRB5_INT_H
60
61 #include <windows.h>
62 #ifdef USE_MS2MIT
63 #define SECURITY_WIN32
64 #include <security.h>
65 #if _WIN32_WINNT < 0x0501
66 #undef _WIN32_WINNT
67 #define _WIN32_WINNT 0x0501
68 #endif
69 #include <ntsecapi.h>
70 #endif /* USE_MS2MIT */
71 #include <stdio.h>
72 #include <string.h>
73 #include <time.h>
74 #include <winsock2.h>
75
76 #ifdef USE_MS2MIT
77 #include <loadfuncs-lsa.h>
78 #endif /* USE_MS2MIT */
79
80 #include <afs/stds.h>
81 #include <krb5.h>
82
83 #include <rxkad.h>
84
85 /* Defined in the KRBV4W32 version of krb.h but not the Kerberos V version */
86 /* Required for some of the loadfuncs headers */
87 typedef struct ktext far *KTEXT;
88 typedef struct ktext far *KTEXT_FP;
89 #include <KerberosIV/krb.h>
90
91 /* AFS has its own version of com_err.h */
92 typedef afs_int32 errcode_t;
93
94 #include <loadfuncs-com_err.h>
95 #include <loadfuncs-krb5.h>
96 #include <loadfuncs-profile.h>
97 #include <loadfuncs-krb.h>
98 #include <loadfuncs-krb524.h>
99 #include <loadfuncs-leash.h>
100
101 // service definitions
102 #define SERVICE_DLL   "advapi32.dll"
103 typedef SC_HANDLE (WINAPI *FP_OpenSCManagerA)(char *, char *, DWORD);
104 typedef SC_HANDLE (WINAPI *FP_OpenServiceA)(SC_HANDLE, char *, DWORD);
105 typedef BOOL (WINAPI *FP_QueryServiceStatus)(SC_HANDLE, LPSERVICE_STATUS);
106 typedef BOOL (WINAPI *FP_CloseServiceHandle)(SC_HANDLE);
107
108 #define KRB5_DEFAULT_LIFE            60*60*10 /* 10 hours */
109 #define LSA_CCNAME                   "MSLSA:"
110
111 #ifndef KTC_ERROR
112 #define KTC_ERROR      11862784L
113 #define KTC_TOOBIG     11862785L
114 #define KTC_INVAL      11862786L
115 #define KTC_NOENT      11862787L
116 #define KTC_PIOCTLFAIL 11862788L
117 #define KTC_NOPIOCTL   11862789L
118 #define KTC_NOCELL     11862790L
119 #define KTC_NOCM       11862791L
120 #endif
121
122 /* User Query data structures and functions */
123
124 struct textField {
125     char * buf;                       /* Destination buffer address */
126     int    len;                       /* Destination buffer length */
127     char * label;                     /* Label for this field */
128     char * def;                       /* Default response for this field */
129     int    echo;                      /* 0 = no, 1 = yes, 2 = asterisks */
130 };
131
132 #define ID_TEXT       150
133 #define ID_MID_TEXT   300
134
135 struct principal_ccache_data {
136     struct principal_ccache_data * next;
137     char * principal;
138     char * ccache_name;
139     int    from_lsa;
140     int    expired;
141     int    expiration_time;
142     int    renew;
143 };
144
145 struct cell_principal_map {
146     struct cell_principal_map * next;
147     char * cell;
148     char * principal;
149     int    active;
150 };
151
152 /* In order to avoid including the private CCAPI headers */
153 typedef int cc_int32;
154
155 #define CC_API_VER_1 1
156 #define CC_API_VER_2 2
157
158 #define CCACHE_API cc_int32
159
160 /*
161 ** The Official Error Codes
162 */
163 #define CC_NOERROR           0
164 #define CC_BADNAME           1
165 #define CC_NOTFOUND          2
166 #define CC_END               3
167 #define CC_IO                4
168 #define CC_WRITE             5
169 #define CC_NOMEM             6
170 #define CC_FORMAT            7
171 #define CC_LOCKED            8
172 #define CC_BAD_API_VERSION   9
173 #define CC_NO_EXIST          10
174 #define CC_NOT_SUPP          11
175 #define CC_BAD_PARM          12
176 #define CC_ERR_CACHE_ATTACH  13
177 #define CC_ERR_CACHE_RELEASE 14
178 #define CC_ERR_CACHE_FULL    15
179 #define CC_ERR_CRED_VERSION  16
180
181 enum {
182     CC_CRED_VUNKNOWN = 0,       // For validation
183     CC_CRED_V4 = 1,
184     CC_CRED_V5 = 2,
185     CC_CRED_VMAX = 3            // For validation
186 };
187
188 typedef struct opaque_dll_control_block_type* apiCB;
189 typedef struct _infoNC {
190     char*     name;
191     char*     principal;
192     cc_int32  vers;
193 } infoNC;
194
195 TYPEDEF_FUNC(
196 CCACHE_API,
197 CALLCONV_C,
198 cc_initialize,
199     (
200     apiCB** cc_ctx,           // <  DLL's primary control structure.
201                               //    returned here, passed everywhere else
202     cc_int32 api_version,     // >  ver supported by caller (use CC_API_VER_1)
203     cc_int32*  api_supported, // <  if ~NULL, max ver supported by DLL
204     const char** vendor       // <  if ~NULL, vendor name in read only C string
205     )
206 );
207
208 TYPEDEF_FUNC(
209 CCACHE_API,
210 CALLCONV_C,
211 cc_shutdown,
212     (
213     apiCB** cc_ctx            // <> DLL's primary control structure. NULL after
214     )
215 );
216
217 TYPEDEF_FUNC(
218 CCACHE_API,
219 CALLCONV_C,
220 cc_get_NC_info,
221     (
222     apiCB* cc_ctx,          // >  DLL's primary control structure
223     struct _infoNC*** ppNCi // <  (NULL before call) null terminated,
224                             //    list of a structs (free via cc_free_infoNC())
225     )
226 );
227
228 TYPEDEF_FUNC(
229 CCACHE_API,
230 CALLCONV_C,
231 cc_free_NC_info,
232     (
233     apiCB* cc_ctx,
234     struct _infoNC*** ppNCi // <  free list of structs returned by
235                             //    cc_get_cache_names().  set to NULL on return
236     )
237 );
238
239 #ifdef _WIN64
240 #define CCAPI_DLL   "krbcc64.dll"
241 #else
242 #define CCAPI_DLL   "krbcc32.dll"
243 #endif
244
245 /* Function Prototypes */
246 DWORD GetServiceStatus(LPSTR, LPSTR, DWORD *);
247 void KFW_AFS_error(LONG, LPCSTR);
248
249 void UnloadFuncs(FUNC_INFO [], HINSTANCE);
250 int  LoadFuncs(const char*, FUNC_INFO [], HINSTANCE*, int*, int, int, int);
251 int  KFW_get_ccache(krb5_context, krb5_principal, krb5_ccache *);
252 int  KFW_error(krb5_error_code, LPCSTR, int, krb5_context *, krb5_ccache *);
253 int  KFW_kinit(krb5_context, krb5_ccache, HWND, char *, char *, krb5_deltat,
254                 DWORD, DWORD, krb5_deltat, DWORD, DWORD);
255 int  KFW_renew(krb5_context, krb5_ccache);
256 int  KFW_destroy(krb5_context, krb5_ccache);
257 BOOL KFW_ms2mit(krb5_context, krb5_ccache, BOOL);
258 int  KFW_AFS_unlog(void);
259 int  KFW_AFS_klog(krb5_context, krb5_ccache, char*, char*, char*, int, char*);
260 void KFW_import_ccache_data(void);
261 BOOL MSLSA_IsKerberosLogon();
262 char *afs_realm_of_cell(krb5_context, struct afsconf_cell *);
263 #endif /* AFSKFW_INT_H */