xref: /freebsd/crypto/krb5/src/windows/kfwlogon/kfwlogon.h (revision f1c4c3daccbaf3820f0e2224de53df12fc952fcc)
1 /*
2 
3 Copyright 2005,2006 by the Massachusetts Institute of Technology
4 Copyright 2007 by Secure Endpoints Inc.
5 
6 All rights reserved.
7 
8 Permission to use, copy, modify, and distribute this software and its
9 documentation for any purpose and without fee is hereby granted,
10 provided that the above copyright notice appear in all copies and that
11 both that copyright notice and this permission notice appear in
12 supporting documentation, and that the name of the Massachusetts
13 Institute of Technology (M.I.T.) not be used in advertising or publicity
14 pertaining to distribution of the software without specific, written
15 prior permission.
16 
17 M.I.T. DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
18 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
19 M.I.T. BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
20 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
21 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
22 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
23 SOFTWARE.
24 
25 */
26 
27 /* We only support VC 1200 and above anyway */
28 #pragma once
29 
30 /* _WIN32_WINNT must be 0x0501 or greater to pull in definition of
31  * all required LSA data types when the Vista SDK NtSecAPI.h is used.
32  */
33 #ifndef _WIN32_WINNT
34 #define _WIN32_WINNT 0x0501
35 #else
36 #if _WIN32_WINNT < 0x0501
37 #undef _WIN32_WINNT
38 #define _WIN32_WINNT 0x0501
39 #endif
40 #endif
41 
42 #include <windows.h>
43 #include <npapi.h>
44 #define SECURITY_WIN32
45 #include <security.h>
46 #include <ntsecapi.h>
47 #include <tchar.h>
48 #include <strsafe.h>
49 
50 typedef int errcode_t;
51 
52 #include <loadfuncs-lsa.h>
53 #include <krb5.h>
54 #include <loadfuncs-com_err.h>
55 #include <loadfuncs-krb5.h>
56 #include <loadfuncs-profile.h>
57 #include <loadfuncs-leash.h>
58 
59 // service definitions
60 #define SERVICE_DLL   "advapi32.dll"
61 typedef SC_HANDLE (WINAPI *FP_OpenSCManagerA)(char *, char *, DWORD);
62 typedef SC_HANDLE (WINAPI *FP_OpenServiceA)(SC_HANDLE, char *, DWORD);
63 typedef BOOL (WINAPI *FP_QueryServiceStatus)(SC_HANDLE, LPSERVICE_STATUS);
64 typedef BOOL (WINAPI *FP_CloseServiceHandle)(SC_HANDLE);
65 
66 /* In order to avoid including the private CCAPI headers */
67 typedef int cc_int32;
68 
69 #define CC_API_VER_1 1
70 #define CC_API_VER_2 2
71 
72 #define CCACHE_API cc_int32
73 
74 /*
75 ** The Official Error Codes
76 */
77 #define CC_NOERROR           0
78 #define CC_BADNAME           1
79 #define CC_NOTFOUND          2
80 #define CC_END               3
81 #define CC_IO                4
82 #define CC_WRITE             5
83 #define CC_NOMEM             6
84 #define CC_FORMAT            7
85 #define CC_LOCKED            8
86 #define CC_BAD_API_VERSION   9
87 #define CC_NO_EXIST          10
88 #define CC_NOT_SUPP          11
89 #define CC_BAD_PARM          12
90 #define CC_ERR_CACHE_ATTACH  13
91 #define CC_ERR_CACHE_RELEASE 14
92 #define CC_ERR_CACHE_FULL    15
93 #define CC_ERR_CRED_VERSION  16
94 
95 enum {
96     CC_CRED_VUNKNOWN = 0,       // For validation
97     /* CC_CRED_V4 = 1, */
98     CC_CRED_V5 = 2,
99     CC_CRED_VMAX = 3            // For validation
100 };
101 
102 typedef struct opaque_dll_control_block_type* apiCB;
103 typedef struct _infoNC {
104     char*     name;
105     char*     principal;
106     cc_int32  vers;
107 } infoNC;
108 
109 TYPEDEF_FUNC(
110 CCACHE_API,
111 CALLCONV_C,
112 cc_initialize,
113     (
114     apiCB** cc_ctx,           // <  DLL's primary control structure.
115                               //    returned here, passed everywhere else
116     cc_int32 api_version,     // >  ver supported by caller (use CC_API_VER_1)
117     cc_int32*  api_supported, // <  if ~NULL, max ver supported by DLL
118     const char** vendor       // <  if ~NULL, vendor name in read only C string
119     )
120 );
121 
122 TYPEDEF_FUNC(
123 CCACHE_API,
124 CALLCONV_C,
125 cc_shutdown,
126     (
127     apiCB** cc_ctx            // <> DLL's primary control structure. NULL after
128     )
129 );
130 
131 TYPEDEF_FUNC(
132 CCACHE_API,
133 CALLCONV_C,
134 cc_get_NC_info,
135     (
136     apiCB* cc_ctx,          // >  DLL's primary control structure
137     struct _infoNC*** ppNCi // <  (NULL before call) null terminated,
138                             //    list of a structs (free via cc_free_infoNC())
139     )
140 );
141 
142 TYPEDEF_FUNC(
143 CCACHE_API,
144 CALLCONV_C,
145 cc_free_NC_info,
146     (
147     apiCB* cc_ctx,
148     struct _infoNC*** ppNCi // <  free list of structs returned by
149                             //    cc_get_cache_names().  set to NULL on return
150     )
151 );
152 /* End private ccapiv2 headers */
153 
154 #ifdef _WIN64
155 #define CCAPI_DLL   "krbcc64.dll"
156 #else
157 #define CCAPI_DLL   "krbcc32.dll"
158 #endif
159 
160 
161 /* */
162 #define MAX_USERNAME_LENGTH 256
163 #define MAX_PASSWORD_LENGTH 256
164 #define MAX_DOMAIN_LENGTH 256
165 
166 #define KFW_LOGON_EVENT_NAME TEXT("MIT Kerberos")
167 
168 BOOLEAN WINAPI DllMain(HANDLE dll, DWORD reason, PVOID reserved);
169 
170 DWORD APIENTRY NPGetCaps(DWORD index);
171 
172 DWORD APIENTRY NPLogonNotify(
173 	PLUID lpLogonId,
174 	LPCWSTR lpAuthentInfoType,
175 	LPVOID lpAuthentInfo,
176 	LPCWSTR lpPreviousAuthentInfoType,
177 	LPVOID lpPreviousAuthentInfo,
178 	LPWSTR lpStationName,
179 	LPVOID StationHandle,
180 	LPWSTR *lpLogonScript);
181 
182 DWORD APIENTRY NPPasswordChangeNotify(
183 	LPCWSTR lpAuthentInfoType,
184 	LPVOID lpAuthentInfo,
185 	LPCWSTR lpPreviousAuthentInfoType,
186 	LPVOID lpPreviousAuthentInfo,
187 	LPWSTR lpStationName,
188 	LPVOID StationHandle,
189 	DWORD dwChangeInfo);
190 
191 #ifdef __cplusplus
192 extern "C" {
193 #endif
194 
195 void DebugEvent0(char *a);
196 void DebugEvent(char *b,...);
197 
198 DWORD MapAuthError(DWORD code);
199 
200 static BOOL WINAPI UnicodeStringToANSI(UNICODE_STRING uInputString, LPSTR lpszOutputString, int nOutStringLen);
201 
202 int KFW_is_available(void);
203 int KFW_get_cred( char * username, char * password, int lifetime, char ** reasonP );
204 void KFW_copy_cache_to_system_file(const char * user, const char * filename);
205 int KFW_destroy_tickets_for_principal(char * user);
206 int KFW_set_ccache_dacl(char *filename, HANDLE hUserToken);
207 int KFW_set_ccache_dacl_with_user_sid(char *filename, PSID pUserSID);
208 int KFW_obtain_user_temp_directory(HANDLE hUserToken, char *newfilename, int size);
209 void KFW_cleanup_orphaned_caches(void);
210 
211 void CALLBACK LogonEventHandlerA(HWND hwnd, HINSTANCE hinst, LPSTR lpszCmdLine, int nCmdShow);
212 
213 #ifdef __cplusplus
214 }
215 #endif
216