s3-samr: fix init_samr_user_info{23,24} callers.
[Samba.git] / source / rpc_client / init_samr.c
blob18b9d2a43522b6a611cc10b9a752c73023ee95e7
1 /*
2 * Unix SMB/CIFS implementation.
3 * RPC Pipe client / server routines
4 * Copyright (C) Guenther Deschner 2008.
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "includes.h"
22 /*******************************************************************
23 inits a structure.
24 ********************************************************************/
26 void init_samr_DomInfo1(struct samr_DomInfo1 *r,
27 uint16_t min_password_length,
28 uint16_t password_history_length,
29 uint32_t password_properties,
30 int64_t max_password_age,
31 int64_t min_password_age)
33 r->min_password_length = min_password_length;
34 r->password_history_length = password_history_length;
35 r->password_properties = password_properties;
36 r->max_password_age = max_password_age;
37 r->min_password_age = min_password_age;
40 /*******************************************************************
41 inits a structure.
42 ********************************************************************/
44 void init_samr_DomInfo2(struct samr_DomInfo2 *r,
45 NTTIME force_logoff_time,
46 const char *comment,
47 const char *domain_name,
48 const char *primary,
49 uint64_t sequence_num,
50 uint32_t unknown2,
51 enum samr_Role role,
52 uint32_t unknown3,
53 uint32_t num_users,
54 uint32_t num_groups,
55 uint32_t num_aliases)
57 r->force_logoff_time = force_logoff_time;
58 init_lsa_String(&r->comment, comment);
59 init_lsa_String(&r->domain_name, domain_name);
60 init_lsa_String(&r->primary, primary);
61 r->sequence_num = sequence_num;
62 r->unknown2 = unknown2;
63 r->role = role;
64 r->unknown3 = unknown3;
65 r->num_users = num_users;
66 r->num_groups = num_groups;
67 r->num_aliases = num_aliases;
70 /*******************************************************************
71 inits a structure.
72 ********************************************************************/
74 void init_samr_DomInfo3(struct samr_DomInfo3 *r,
75 NTTIME force_logoff_time)
77 r->force_logoff_time = force_logoff_time;
80 /*******************************************************************
81 inits a structure.
82 ********************************************************************/
84 void init_samr_DomInfo4(struct samr_DomInfo4 *r,
85 const char *comment)
87 init_lsa_String(&r->comment, comment);
90 /*******************************************************************
91 inits a structure.
92 ********************************************************************/
94 void init_samr_DomInfo5(struct samr_DomInfo5 *r,
95 const char *domain_name)
97 init_lsa_String(&r->domain_name, domain_name);
100 /*******************************************************************
101 inits a structure.
102 ********************************************************************/
104 void init_samr_DomInfo6(struct samr_DomInfo6 *r,
105 const char *primary)
107 init_lsa_String(&r->primary, primary);
110 /*******************************************************************
111 inits a structure.
112 ********************************************************************/
114 void init_samr_DomInfo7(struct samr_DomInfo7 *r,
115 enum samr_Role role)
117 r->role = role;
120 /*******************************************************************
121 inits a structure.
122 ********************************************************************/
124 void init_samr_DomInfo8(struct samr_DomInfo8 *r,
125 uint64_t sequence_num,
126 NTTIME domain_create_time)
128 r->sequence_num = sequence_num;
129 r->domain_create_time = domain_create_time;
132 /*******************************************************************
133 inits a structure.
134 ********************************************************************/
136 void init_samr_DomInfo9(struct samr_DomInfo9 *r,
137 uint32_t unknown)
139 r->unknown = unknown;
142 /*******************************************************************
143 inits a structure.
144 ********************************************************************/
146 void init_samr_DomInfo12(struct samr_DomInfo12 *r,
147 uint64_t lockout_duration,
148 uint64_t lockout_window,
149 uint16_t lockout_threshold)
151 r->lockout_duration = lockout_duration;
152 r->lockout_window = lockout_window;
153 r->lockout_threshold = lockout_threshold;
156 /*******************************************************************
157 inits a samr_GroupInfoAll structure.
158 ********************************************************************/
160 void init_samr_group_info1(struct samr_GroupInfoAll *r,
161 const char *name,
162 uint32_t attributes,
163 uint32_t num_members,
164 const char *description)
166 DEBUG(5, ("init_samr_group_info1\n"));
168 init_lsa_String(&r->name, name);
169 r->attributes = attributes;
170 r->num_members = num_members;
171 init_lsa_String(&r->description, description);
174 /*******************************************************************
175 inits a lsa_String structure
176 ********************************************************************/
178 void init_samr_group_info2(struct lsa_String *r, const char *group_name)
180 DEBUG(5, ("init_samr_group_info2\n"));
182 init_lsa_String(r, group_name);
185 /*******************************************************************
186 inits a samr_GroupInfoAttributes structure.
187 ********************************************************************/
189 void init_samr_group_info3(struct samr_GroupInfoAttributes *r,
190 uint32_t attributes)
192 DEBUG(5, ("init_samr_group_info3\n"));
194 r->attributes = attributes;
197 /*******************************************************************
198 inits a lsa_String structure
199 ********************************************************************/
201 void init_samr_group_info4(struct lsa_String *r, const char *description)
203 DEBUG(5, ("init_samr_group_info4\n"));
205 init_lsa_String(r, description);
208 /*******************************************************************
209 inits a samr_GroupInfoAll structure.
210 ********************************************************************/
212 void init_samr_group_info5(struct samr_GroupInfoAll *r,
213 const char *name,
214 uint32_t attributes,
215 uint32_t num_members,
216 const char *description)
218 DEBUG(5, ("init_samr_group_info5\n"));
220 init_lsa_String(&r->name, name);
221 r->attributes = attributes;
222 r->num_members = num_members;
223 init_lsa_String(&r->description, description);
226 /*******************************************************************
227 inits a samr_AliasInfoAll structure.
228 ********************************************************************/
230 void init_samr_alias_info1(struct samr_AliasInfoAll *r,
231 const char *name,
232 uint32_t num_members,
233 const char *description)
235 DEBUG(5, ("init_samr_alias_info1\n"));
237 init_lsa_String(&r->name, name);
238 r->num_members = num_members;
239 init_lsa_String(&r->description, description);
242 /*******************************************************************
243 inits a lsa_String structure.
244 ********************************************************************/
246 void init_samr_alias_info3(struct lsa_String *r,
247 const char *description)
249 DEBUG(5, ("init_samr_alias_info3\n"));
251 init_lsa_String(r, description);
254 /*******************************************************************
255 inits a samr_UserInfo7 structure.
256 ********************************************************************/
258 void init_samr_user_info7(struct samr_UserInfo7 *r,
259 const char *account_name)
261 DEBUG(5, ("init_samr_user_info7\n"));
263 init_lsa_String(&r->account_name, account_name);
266 /*******************************************************************
267 inits a samr_UserInfo9 structure.
268 ********************************************************************/
270 void init_samr_user_info9(struct samr_UserInfo9 *r,
271 uint32_t primary_gid)
273 DEBUG(5, ("init_samr_user_info9\n"));
275 r->primary_gid = primary_gid;
278 /*******************************************************************
279 inits a SAM_USER_INFO_16 structure.
280 ********************************************************************/
282 void init_samr_user_info16(struct samr_UserInfo16 *r,
283 uint32_t acct_flags)
285 DEBUG(5, ("init_samr_user_info16\n"));
287 r->acct_flags = acct_flags;
290 /*******************************************************************
291 inits a samr_UserInfo18 structure.
292 ********************************************************************/
294 void init_samr_user_info18(struct samr_UserInfo18 *r,
295 const uint8 lm_pwd[16],
296 const uint8 nt_pwd[16])
298 DEBUG(5, ("init_samr_user_info18\n"));
300 r->lm_pwd_active =
301 memcpy(r->lm_pwd.hash, lm_pwd, sizeof(r->lm_pwd.hash)) ? true : false;
302 r->nt_pwd_active =
303 memcpy(r->nt_pwd.hash, nt_pwd, sizeof(r->nt_pwd.hash)) ? true : false;
306 /*******************************************************************
307 inits a samr_UserInfo20 structure.
308 ********************************************************************/
310 void init_samr_user_info20(struct samr_UserInfo20 *r,
311 struct lsa_BinaryString *parameters)
313 r->parameters = *parameters;
316 /*************************************************************************
317 inits a samr_UserInfo21 structure
318 *************************************************************************/
320 void init_samr_user_info21(struct samr_UserInfo21 *r,
321 NTTIME last_logon,
322 NTTIME last_logoff,
323 NTTIME last_password_change,
324 NTTIME acct_expiry,
325 NTTIME allow_password_change,
326 NTTIME force_password_change,
327 const char *account_name,
328 const char *full_name,
329 const char *home_directory,
330 const char *home_drive,
331 const char *logon_script,
332 const char *profile_path,
333 const char *description,
334 const char *workstations,
335 const char *comment,
336 struct lsa_BinaryString *parameters,
337 uint32_t rid,
338 uint32_t primary_gid,
339 uint32_t acct_flags,
340 uint32_t fields_present,
341 struct samr_LogonHours logon_hours,
342 uint16_t bad_password_count,
343 uint16_t logon_count,
344 uint16_t country_code,
345 uint16_t code_page,
346 uint8_t nt_password_set,
347 uint8_t lm_password_set,
348 uint8_t password_expired)
350 r->last_logon = last_logon;
351 r->last_logoff = last_logoff;
352 r->last_password_change = last_password_change;
353 r->acct_expiry = acct_expiry;
354 r->allow_password_change = allow_password_change;
355 r->force_password_change = force_password_change;
356 init_lsa_String(&r->account_name, account_name);
357 init_lsa_String(&r->full_name, full_name);
358 init_lsa_String(&r->home_directory, home_directory);
359 init_lsa_String(&r->home_drive, home_drive);
360 init_lsa_String(&r->logon_script, logon_script);
361 init_lsa_String(&r->profile_path, profile_path);
362 init_lsa_String(&r->description, description);
363 init_lsa_String(&r->workstations, workstations);
364 init_lsa_String(&r->comment, comment);
365 r->parameters = *parameters;
366 r->rid = rid;
367 r->primary_gid = primary_gid;
368 r->acct_flags = acct_flags;
369 r->fields_present = fields_present;
370 r->logon_hours = logon_hours;
371 r->bad_password_count = bad_password_count;
372 r->logon_count = logon_count;
373 r->country_code = country_code;
374 r->code_page = code_page;
375 r->nt_password_set = nt_password_set;
376 r->lm_password_set = lm_password_set;
377 r->password_expired = password_expired;
380 /*************************************************************************
381 init_samr_user_info23
382 *************************************************************************/
384 void init_samr_user_info23(struct samr_UserInfo23 *r,
385 NTTIME last_logon,
386 NTTIME last_logoff,
387 NTTIME last_password_change,
388 NTTIME acct_expiry,
389 NTTIME allow_password_change,
390 NTTIME force_password_change,
391 const char *account_name,
392 const char *full_name,
393 const char *home_directory,
394 const char *home_drive,
395 const char *logon_script,
396 const char *profile_path,
397 const char *description,
398 const char *workstations,
399 const char *comment,
400 struct lsa_BinaryString *parameters,
401 uint32_t rid,
402 uint32_t primary_gid,
403 uint32_t acct_flags,
404 uint32_t fields_present,
405 struct samr_LogonHours logon_hours,
406 uint16_t bad_password_count,
407 uint16_t logon_count,
408 uint16_t country_code,
409 uint16_t code_page,
410 uint8_t nt_password_set,
411 uint8_t lm_password_set,
412 uint8_t password_expired,
413 struct samr_CryptPassword *pwd_buf)
415 memset(r, '\0', sizeof(*r));
416 init_samr_user_info21(&r->info,
417 last_logon,
418 last_logoff,
419 last_password_change,
420 acct_expiry,
421 allow_password_change,
422 force_password_change,
423 account_name,
424 full_name,
425 home_directory,
426 home_drive,
427 logon_script,
428 profile_path,
429 description,
430 workstations,
431 comment,
432 parameters,
433 rid,
434 primary_gid,
435 acct_flags,
436 fields_present,
437 logon_hours,
438 bad_password_count,
439 logon_count,
440 country_code,
441 code_page,
442 nt_password_set,
443 lm_password_set,
444 password_expired);
446 r->password = *pwd_buf;
449 /*************************************************************************
450 init_samr_user_info24
451 *************************************************************************/
453 void init_samr_user_info24(struct samr_UserInfo24 *r,
454 struct samr_CryptPassword *pwd_buf,
455 uint8_t password_expired)
457 DEBUG(10, ("init_samr_user_info24:\n"));
459 r->password = *pwd_buf;
460 r->password_expired = password_expired;
463 /*************************************************************************
464 inits a samr_CryptPasswordEx structure
465 *************************************************************************/
467 void init_samr_CryptPasswordEx(const char *pwd,
468 DATA_BLOB *session_key,
469 struct samr_CryptPasswordEx *pwd_buf)
471 /* samr_CryptPasswordEx */
473 uchar pwbuf[532];
474 struct MD5Context md5_ctx;
475 uint8_t confounder[16];
476 DATA_BLOB confounded_session_key = data_blob(NULL, 16);
478 encode_pw_buffer(pwbuf, pwd, STR_UNICODE);
480 generate_random_buffer((uint8_t *)confounder, 16);
482 MD5Init(&md5_ctx);
483 MD5Update(&md5_ctx, confounder, 16);
484 MD5Update(&md5_ctx, session_key->data,
485 session_key->length);
486 MD5Final(confounded_session_key.data, &md5_ctx);
488 SamOEMhashBlob(pwbuf, 516, &confounded_session_key);
489 memcpy(&pwbuf[516], confounder, 16);
491 memcpy(pwd_buf->data, pwbuf, sizeof(pwbuf));
492 data_blob_free(&confounded_session_key);
495 /*************************************************************************
496 inits a samr_CryptPassword structure
497 *************************************************************************/
499 void init_samr_CryptPassword(const char *pwd,
500 DATA_BLOB *session_key,
501 struct samr_CryptPassword *pwd_buf)
503 /* samr_CryptPassword */
505 encode_pw_buffer(pwd_buf->data, pwd, STR_UNICODE);
506 SamOEMhashBlob(pwd_buf->data, 516, session_key);