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