1 /***********************************************************************\
2 *                               subauth.d                               *
3 *                                                                       *
4 *                       Windows API header module                       *
5 *                                                                       *
6 *                 Translated from MinGW Windows headers                 *
7 *                                                                       *
8 *                       Placed into public domain                       *
9 \***********************************************************************/
10 module win32.subauth;
11 version(Windows):
12 
13 private import win32.ntdef, win32.windef;
14 
15 /+
16 alias LONG NTSTATUS;
17 alias NTSTATUS* PNTSTATUS;
18 +/
19 
20 enum : ULONG {
21 	MSV1_0_PASSTHRU    = 1,
22 	MSV1_0_GUEST_LOGON = 2
23 }
24 
25 // USER_ALL_INFORMATION.WhichFields (Undocumented)
26 const ULONG
27 	MSV1_0_VALIDATION_LOGOFF_TIME  = 1,
28 	MSV1_0_VALIDATION_KICKOFF_TIME = 2,
29 	MSV1_0_VALIDATION_LOGON_SERVER = 4,
30 	MSV1_0_VALIDATION_LOGON_DOMAIN = 8,
31 	MSV1_0_VALIDATION_SESSION_KEY  = 16,
32 	MSV1_0_VALIDATION_USER_FLAGS   = 32,
33 	MSV1_0_VALIDATION_USER_ID      = 64;
34 
35 // ?ActionsPerformed? (Undocumented)
36 const MSV1_0_SUBAUTH_ACCOUNT_DISABLED = 1;
37 const MSV1_0_SUBAUTH_PASSWORD         = 2;
38 const MSV1_0_SUBAUTH_WORKSTATIONS = 4;
39 const MSV1_0_SUBAUTH_LOGON_HOURS = 8;
40 const MSV1_0_SUBAUTH_ACCOUNT_EXPIRY = 16;
41 const MSV1_0_SUBAUTH_PASSWORD_EXPIRY = 32;
42 const MSV1_0_SUBAUTH_ACCOUNT_TYPE = 64;
43 const MSV1_0_SUBAUTH_LOCKOUT = 128;
44 
45 const NEXT_FREE_ACCOUNT_CONTROL_BIT = 131072;
46 
47 const SAM_DAYS_PER_WEEK    = 7;
48 const SAM_HOURS_PER_WEEK   = 168;
49 const SAM_MINUTES_PER_WEEK = 10080;
50 
51 enum : NTSTATUS {
52 	STATUS_SUCCESS                = 0,
53 	STATUS_INVALID_INFO_CLASS     = 0xC0000003,
54 	STATUS_NO_SUCH_USER           = 0xC0000064,
55 	STATUS_WRONG_PASSWORD         = 0xC000006A,
56 	STATUS_PASSWORD_RESTRICTION   = 0xC000006C,
57 	STATUS_LOGON_FAILURE          = 0xC000006D,
58 	STATUS_ACCOUNT_RESTRICTION    = 0xC000006E,
59 	STATUS_INVALID_LOGON_HOURS    = 0xC000006F,
60 	STATUS_INVALID_WORKSTATION    = 0xC0000070,
61 	STATUS_PASSWORD_EXPIRED       = 0xC0000071,
62 	STATUS_ACCOUNT_DISABLED       = 0xC0000072,
63 	STATUS_INSUFFICIENT_RESOURCES = 0xC000009A,
64 	STATUS_ACCOUNT_EXPIRED        = 0xC0000193,
65 	STATUS_PASSWORD_MUST_CHANGE   = 0xC0000224,
66 	STATUS_ACCOUNT_LOCKED_OUT     = 0xC0000234
67 }
68 
69 // Note: undocumented in MSDN
70 // USER_ALL_INFORMATION.UserAccountControl
71 const ULONG
72 	USER_ACCOUNT_DISABLED                = 1,
73 	USER_HOME_DIRECTORY_REQUIRED         = 2,
74 	USER_PASSWORD_NOT_REQUIRED           = 4,
75 	USER_TEMP_DUPLICATE_ACCOUNT          = 8,
76 	USER_NORMAL_ACCOUNT                  = 16,
77 	USER_MNS_LOGON_ACCOUNT               = 32,
78 	USER_INTERDOMAIN_TRUST_ACCOUNT       = 64,
79 	USER_WORKSTATION_TRUST_ACCOUNT       = 128,
80 	USER_SERVER_TRUST_ACCOUNT            = 256,
81 	USER_DONT_EXPIRE_PASSWORD            = 512,
82 	USER_ACCOUNT_AUTO_LOCKED             = 1024,
83 	USER_ENCRYPTED_TEXT_PASSWORD_ALLOWED = 2048,
84 	USER_SMARTCARD_REQUIRED              = 4096,
85 	USER_TRUSTED_FOR_DELEGATION          = 8192,
86 	USER_NOT_DELEGATED                   = 16384,
87 	USER_USE_DES_KEY_ONLY                = 32768,
88 	USER_DONT_REQUIRE_PREAUTH            = 65536,
89 
90 	USER_MACHINE_ACCOUNT_MASK            = 448,
91 	USER_ACCOUNT_TYPE_MASK               = 472,
92 	USER_ALL_PARAMETERS                  = 2097152;
93 
94 /+
95 struct UNICODE_STRING {
96 	USHORT Length;
97 	USHORT MaximumLength;
98 	PWSTR Buffer;
99 }
100 alias UNICODE_STRING* PUNICODE_STRING;
101 
102 struct STRING {
103 	USHORT Length;
104 	USHORT MaximumLength;
105 	PCHAR Buffer;
106 }
107 alias STRING* PSTRING;
108 +/
109 
110 mixin DECLARE_HANDLE!("SAM_HANDLE");
111 alias SAM_HANDLE* PSAM_HANDLE;
112 
113 struct OLD_LARGE_INTEGER {
114 	ULONG LowPart;
115 	LONG HighPart;
116 }
117 alias OLD_LARGE_INTEGER* POLD_LARGE_INTEGER;
118 
119 enum NETLOGON_LOGON_INFO_CLASS {
120 	NetlogonInteractiveInformation = 1,
121 	NetlogonNetworkInformation,
122 	NetlogonServiceInformation,
123 	NetlogonGenericInformation,
124 	NetlogonInteractiveTransitiveInformation,
125 	NetlogonNetworkTransitiveInformation,
126 	NetlogonServiceTransitiveInformation
127 }
128 
129 
130 const CYPHER_BLOCK_LENGTH = 8;
131 const USER_SESSION_KEY_LENGTH = CYPHER_BLOCK_LENGTH * 2;
132 const CLEAR_BLOCK_LENGTH = 8;
133 
134 struct CYPHER_BLOCK {
135 	CHAR[CYPHER_BLOCK_LENGTH] data;
136 }
137 alias CYPHER_BLOCK* PCYPHER_BLOCK;
138 
139 struct CLEAR_BLOCK {
140 	CHAR[CLEAR_BLOCK_LENGTH] data;
141 }
142 alias CLEAR_BLOCK* PCLEAR_BLOCK;
143 
144 struct LM_OWF_PASSWORD {
145 	CYPHER_BLOCK[2] data;
146 }
147 alias LM_OWF_PASSWORD* PLM_OWF_PASSWORD;
148 
149 struct USER_SESSION_KEY {
150 	CYPHER_BLOCK[2] data;
151 }
152 alias USER_SESSION_KEY* PUSER_SESSION_KEY;
153 
154 alias CLEAR_BLOCK LM_CHALLENGE;
155 alias LM_CHALLENGE* PLM_CHALLENGE;
156 
157 alias LM_OWF_PASSWORD NT_OWF_PASSWORD;
158 alias NT_OWF_PASSWORD* PNT_OWF_PASSWORD;
159 alias LM_CHALLENGE NT_CHALLENGE;
160 alias NT_CHALLENGE* PNT_CHALLENGE;
161 
162 struct LOGON_HOURS {
163 	USHORT UnitsPerWeek;
164 	PUCHAR LogonHours;
165 }
166 alias LOGON_HOURS* PLOGON_HOURS;
167 
168 struct SR_SECURITY_DESCRIPTOR {
169 	ULONG Length;
170 	PUCHAR SecurityDescriptor;
171 }
172 alias SR_SECURITY_DESCRIPTOR* PSR_SECURITY_DESCRIPTOR;
173 
174 align(4):
175 struct USER_ALL_INFORMATION {
176 	LARGE_INTEGER LastLogon;
177 	LARGE_INTEGER LastLogoff;
178 	LARGE_INTEGER PasswordLastSet;
179 	LARGE_INTEGER AccountExpires;
180 	LARGE_INTEGER PasswordCanChange;
181 	LARGE_INTEGER PasswordMustChange;
182 	UNICODE_STRING UserName;
183 	UNICODE_STRING FullName;
184 	UNICODE_STRING HomeDirectory;
185 	UNICODE_STRING HomeDirectoryDrive;
186 	UNICODE_STRING ScriptPath;
187 	UNICODE_STRING ProfilePath;
188 	UNICODE_STRING AdminComment;
189 	UNICODE_STRING WorkStations;
190 	UNICODE_STRING UserComment;
191 	UNICODE_STRING Parameters;
192 	UNICODE_STRING LmPassword;
193 	UNICODE_STRING NtPassword;
194 	UNICODE_STRING PrivateData;
195 	SR_SECURITY_DESCRIPTOR SecurityDescriptor;
196 	ULONG UserId;
197 	ULONG PrimaryGroupId;
198 	ULONG UserAccountControl;
199 	ULONG WhichFields;
200 	LOGON_HOURS LogonHours;
201 	USHORT BadPasswordCount;
202 	USHORT LogonCount;
203 	USHORT CountryCode;
204 	USHORT CodePage;
205 	BOOLEAN LmPasswordPresent;
206 	BOOLEAN NtPasswordPresent;
207 	BOOLEAN PasswordExpired;
208 	BOOLEAN PrivateDataSensitive;
209 }
210 alias USER_ALL_INFORMATION* PUSER_ALL_INFORMATION;
211 align:
212 
213 struct MSV1_0_VALIDATION_INFO {
214 	LARGE_INTEGER LogoffTime;
215 	LARGE_INTEGER KickoffTime;
216 	UNICODE_STRING LogonServer;
217 	UNICODE_STRING LogonDomainName;
218 	USER_SESSION_KEY SessionKey;
219 	BOOLEAN Authoritative;
220 	ULONG UserFlags;
221 	ULONG WhichFields;
222 	ULONG UserId;
223 }
224 alias MSV1_0_VALIDATION_INFO* PMSV1_0_VALIDATION_INFO;
225 
226 struct NETLOGON_LOGON_IDENTITY_INFO {
227 	UNICODE_STRING LogonDomainName;
228 	ULONG ParameterControl;
229 	OLD_LARGE_INTEGER LogonId;
230 	UNICODE_STRING UserName;
231 	UNICODE_STRING Workstation;
232 }
233 alias NETLOGON_LOGON_IDENTITY_INFO* PNETLOGON_LOGON_IDENTITY_INFO;
234 
235 struct NETLOGON_INTERACTIVE_INFO {
236 	NETLOGON_LOGON_IDENTITY_INFO Identity;
237 	LM_OWF_PASSWORD LmOwfPassword;
238 	NT_OWF_PASSWORD NtOwfPassword;
239 }
240 alias NETLOGON_INTERACTIVE_INFO* PNETLOGON_INTERACTIVE_INFO;
241 
242 struct NETLOGON_GENERIC_INFO {
243 	NETLOGON_LOGON_IDENTITY_INFO Identity;
244 	UNICODE_STRING PackageName;
245 	ULONG DataLength;
246 	PUCHAR LogonData;
247 }
248 alias NETLOGON_GENERIC_INFO* PNETLOGON_GENERIC_INFO;
249 
250 struct NETLOGON_NETWORK_INFO {
251 	NETLOGON_LOGON_IDENTITY_INFO Identity;
252 	LM_CHALLENGE LmChallenge;
253 	STRING NtChallengeResponse;
254 	STRING LmChallengeResponse;
255 }
256 alias NETLOGON_NETWORK_INFO* PNETLOGON_NETWORK_INFO;
257 
258 struct NETLOGON_SERVICE_INFO {
259 	NETLOGON_LOGON_IDENTITY_INFO Identity;
260 	LM_OWF_PASSWORD LmOwfPassword;
261 	NT_OWF_PASSWORD NtOwfPassword;
262 }
263 alias NETLOGON_SERVICE_INFO* PNETLOGON_SERVICE_INFO;
264 
265 extern (Windows) {
266 NTSTATUS Msv1_0SubAuthenticationRoutine(NETLOGON_LOGON_INFO_CLASS,PVOID,
267 	ULONG,PUSER_ALL_INFORMATION,PULONG,PULONG,
268 	PBOOLEAN,PLARGE_INTEGER,PLARGE_INTEGER);
269 NTSTATUS Msv1_0SubAuthenticationFilter(NETLOGON_LOGON_INFO_CLASS,PVOID,
270 	ULONG,PUSER_ALL_INFORMATION,PULONG,PULONG,
271 	PBOOLEAN,PLARGE_INTEGER,PLARGE_INTEGER);
272 NTSTATUS Msv1_0SubAuthenticationRoutineGeneric(PVOID,ULONG,PULONG,PVOID*);
273 NTSTATUS Msv1_0SubAuthenticationRoutineEx(NETLOGON_LOGON_INFO_CLASS,PVOID,
274 	ULONG,PUSER_ALL_INFORMATION,SAM_HANDLE,
275 	PMSV1_0_VALIDATION_INFO,PULONG);
276 }