1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
|
/*
Unix SMB/CIFS implementation.
SAM_USER_HANDLE access routines
Copyright (C) Andrew Bartlett 2002
Copyright (C) Stefan (metze) Metzmacher 2002
Copyright (C) Jelmer Vernooij 2002
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "includes.h"
#undef DBGC_CLASS
#define DBGC_CLASS DBGC_SAM
NTSTATUS sam_get_user_domain_sid (const SAM_USER_HANDLE *sampass, DOM_SID **sid)
{
NTSTATUS status;
SAM_DOMAIN_HANDLE *domain;
if (!sampass || !sid) return NT_STATUS_UNSUCCESSFUL;
if (!NT_STATUS_IS_OK(status = sam_get_user_domain(sampass, &domain))){
DEBUG(0, ("sam_get_user_domain_sid: Can't get domain for user\n"));
return status;
}
return sam_get_domain_sid(domain, sid);
}
NTSTATUS sam_get_user_domain_name (const SAM_USER_HANDLE *sampass, char **domain_name)
{
NTSTATUS status;
SAM_DOMAIN_HANDLE *domain;
if (!sampass || !domain_name) return NT_STATUS_UNSUCCESSFUL;
if (!NT_STATUS_IS_OK(status = sam_get_user_domain(sampass, &domain))){
DEBUG(0, ("sam_get_user_domain_name: Can't get domain for user\n"));
return status;
}
return sam_get_domain_name(domain, domain_name);
}
NTSTATUS sam_get_user_acct_ctrl (const SAM_USER_HANDLE *sampass, uint16 *acct_ctrl)
{
if(!sampass || !acct_ctrl) return NT_STATUS_UNSUCCESSFUL;
*acct_ctrl = sampass->private.acct_ctrl;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_logon_time (const SAM_USER_HANDLE *sampass, NTTIME *logon_time)
{
if(!sampass || !logon_time) return NT_STATUS_UNSUCCESSFUL;
*logon_time = sampass->private.logon_time;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_logoff_time (const SAM_USER_HANDLE *sampass, NTTIME *logoff_time)
{
if(!sampass || !logoff_time) return NT_STATUS_UNSUCCESSFUL;
*logoff_time = sampass->private.logoff_time;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_kickoff_time (const SAM_USER_HANDLE *sampass, NTTIME *kickoff_time)
{
if (!sampass || !kickoff_time) return NT_STATUS_UNSUCCESSFUL;
*kickoff_time = sampass->private.kickoff_time;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_pass_last_set_time (const SAM_USER_HANDLE *sampass, NTTIME *pass_last_set_time)
{
if (!sampass || !pass_last_set_time) return NT_STATUS_UNSUCCESSFUL;
*pass_last_set_time = sampass->private.pass_last_set_time;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_pass_can_change_time (const SAM_USER_HANDLE *sampass, NTTIME *pass_can_change_time)
{
if (!sampass || !pass_can_change_time) return NT_STATUS_UNSUCCESSFUL;
*pass_can_change_time = sampass->private.pass_can_change_time;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_pass_must_change_time (const SAM_USER_HANDLE *sampass, NTTIME *pass_must_change_time)
{
if (!sampass || !pass_must_change_time) return NT_STATUS_UNSUCCESSFUL;
*pass_must_change_time = sampass->private.pass_must_change_time;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_logon_divs (const SAM_USER_HANDLE *sampass, uint16 *logon_divs)
{
if (!sampass || !logon_divs) return NT_STATUS_UNSUCCESSFUL;
*logon_divs = sampass->private.logon_divs;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_hours_len (const SAM_USER_HANDLE *sampass, uint32 *hours_len)
{
if (!sampass || !hours_len) return NT_STATUS_UNSUCCESSFUL;
*hours_len = sampass->private.hours_len;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_hours (const SAM_USER_HANDLE *sampass, uint8 **hours)
{
if (!sampass || !hours) return NT_STATUS_UNSUCCESSFUL;
*hours = sampass->private.hours;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_nt_pwd (const SAM_USER_HANDLE *sampass, DATA_BLOB *nt_pwd)
{
if (!sampass) return NT_STATUS_UNSUCCESSFUL;
SMB_ASSERT((!sampass->private.nt_pw.data)
|| sampass->private.nt_pw.length == NT_HASH_LEN);
*nt_pwd = sampass->private.nt_pw;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_lm_pwd (const SAM_USER_HANDLE *sampass, DATA_BLOB *lm_pwd)
{
if (!sampass) return NT_STATUS_UNSUCCESSFUL;
SMB_ASSERT((!sampass->private.lm_pw.data)
|| sampass->private.lm_pw.length == LM_HASH_LEN);
*lm_pwd = sampass->private.lm_pw;
return NT_STATUS_OK;
}
/* Return the plaintext password if known. Most of the time
it isn't, so don't assume anything magic about this function.
Used to pass the plaintext to sam backends that might
want to store more than just the NTLM hashes.
*/
NTSTATUS sam_get_user_plaintext_pwd (const SAM_USER_HANDLE *sampass, DATA_BLOB **plain_pwd)
{
if (!sampass || !plain_pwd) return NT_STATUS_UNSUCCESSFUL;
*plain_pwd = &(sampass->private.plaintext_pw);
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_sid(const SAM_USER_HANDLE *sampass, DOM_SID **sid)
{
if (!sampass) return NT_STATUS_UNSUCCESSFUL;
*sid = &(sampass->private.user_sid);
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_pgroup(const SAM_USER_HANDLE *sampass, DOM_SID **sid)
{
if (!sampass) return NT_STATUS_UNSUCCESSFUL;
*sid = &(sampass->private.group_sid);
return NT_STATUS_OK;
}
/**
* Get flags showing what is initalised in the SAM_USER_HANDLE
* @param sampass the SAM_USER_HANDLE in question
* @return the flags indicating the members initialised in the struct.
**/
NTSTATUS sam_get_user_init_flag (const SAM_USER_HANDLE *sampass, uint32 *initflag)
{
if (!sampass) return NT_STATUS_UNSUCCESSFUL;
*initflag = sampass->private.init_flag;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_name (const SAM_USER_HANDLE *sampass, char **username)
{
if (!sampass) return NT_STATUS_UNSUCCESSFUL;
*username = sampass->private.username;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_domain (const SAM_USER_HANDLE *sampass, SAM_DOMAIN_HANDLE **domain)
{
if (!sampass) return NT_STATUS_UNSUCCESSFUL;
*domain = sampass->private.domain;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_fullname (const SAM_USER_HANDLE *sampass, char **fullname)
{
if (!sampass) return NT_STATUS_UNSUCCESSFUL;
*fullname = sampass->private.full_name;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_homedir (const SAM_USER_HANDLE *sampass, char **homedir)
{
if (!sampass) return NT_STATUS_UNSUCCESSFUL;
*homedir = sampass->private.home_dir;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_unix_home_dir (const SAM_USER_HANDLE *sampass, char **uhomedir)
{
if (!sampass) return NT_STATUS_UNSUCCESSFUL;
*uhomedir = sampass->private.unix_home_dir;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_dir_drive (const SAM_USER_HANDLE *sampass, char **dirdrive)
{
if (!sampass) return NT_STATUS_UNSUCCESSFUL;
*dirdrive = sampass->private.dir_drive;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_logon_script (const SAM_USER_HANDLE *sampass, char **logon_script)
{
if (!sampass) return NT_STATUS_UNSUCCESSFUL;
*logon_script = sampass->private.logon_script;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_profile_path (const SAM_USER_HANDLE *sampass, char **profile_path)
{
if (!sampass) return NT_STATUS_UNSUCCESSFUL;
*profile_path = sampass->private.profile_path;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_description (const SAM_USER_HANDLE *sampass, char **description)
{
if (!sampass) return NT_STATUS_UNSUCCESSFUL;
*description = sampass->private.acct_desc;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_workstations (const SAM_USER_HANDLE *sampass, char **workstations)
{
if (!sampass) return NT_STATUS_UNSUCCESSFUL;
*workstations = sampass->private.workstations;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_unknown_str (const SAM_USER_HANDLE *sampass, char **unknown_str)
{
if (!sampass) return NT_STATUS_UNSUCCESSFUL;
*unknown_str = sampass->private.unknown_str;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_munged_dial (const SAM_USER_HANDLE *sampass, char **munged_dial)
{
if (!sampass) return NT_STATUS_UNSUCCESSFUL;
*munged_dial = sampass->private.munged_dial;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_unknown_1 (const SAM_USER_HANDLE *sampass, uint32 *unknown1)
{
if (!sampass || !unknown1) return NT_STATUS_UNSUCCESSFUL;
*unknown1 = sampass->private.unknown_1;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_unknown_2 (const SAM_USER_HANDLE *sampass, uint32 *unknown2)
{
if (!sampass || !unknown2) return NT_STATUS_UNSUCCESSFUL;
*unknown2 = sampass->private.unknown_2;
return NT_STATUS_OK;
}
NTSTATUS sam_get_user_unknown_3 (const SAM_USER_HANDLE *sampass, uint32 *unknown3)
{
if (!sampass || !unknown3) return NT_STATUS_UNSUCCESSFUL;
*unknown3 = sampass->private.unknown_3;
return NT_STATUS_OK;
}
/*********************************************************************
Collection of set...() functions for SAM_USER_HANDLE_INFO.
********************************************************************/
NTSTATUS sam_set_user_acct_ctrl (SAM_USER_HANDLE *sampass, uint16 flags)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
sampass->private.acct_ctrl = flags;
return NT_STATUS_OK;
}
NTSTATUS sam_set_user_logon_time (SAM_USER_HANDLE *sampass, NTTIME mytime, BOOL store)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
sampass->private.logon_time = mytime;
if (store)
sam_set_user_init_flag(sampass, FLAG_SAM_LOGONTIME);
return NT_STATUS_UNSUCCESSFUL;
}
NTSTATUS sam_set_user_logoff_time (SAM_USER_HANDLE *sampass, NTTIME mytime, BOOL store)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
sampass->private.logoff_time = mytime;
if (store)
sam_set_user_init_flag(sampass, FLAG_SAM_LOGOFFTIME);
return NT_STATUS_OK;
}
NTSTATUS sam_set_user_kickoff_time (SAM_USER_HANDLE *sampass, NTTIME mytime, BOOL store)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
sampass->private.kickoff_time = mytime;
if (store)
sam_set_user_init_flag(sampass, FLAG_SAM_KICKOFFTIME);
return NT_STATUS_OK;
}
NTSTATUS sam_set_user_pass_can_change_time (SAM_USER_HANDLE *sampass, NTTIME mytime, BOOL store)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
sampass->private.pass_can_change_time = mytime;
if (store)
sam_set_user_init_flag(sampass, FLAG_SAM_CANCHANGETIME);
return NT_STATUS_OK;
}
NTSTATUS sam_set_user_pass_must_change_time (SAM_USER_HANDLE *sampass, NTTIME mytime, BOOL store)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
sampass->private.pass_must_change_time = mytime;
if (store)
sam_set_user_init_flag(sampass, FLAG_SAM_MUSTCHANGETIME);
return NT_STATUS_OK;
}
NTSTATUS sam_set_user_pass_last_set_time (SAM_USER_HANDLE *sampass, NTTIME mytime)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
sampass->private.pass_last_set_time = mytime;
return NT_STATUS_OK;
}
NTSTATUS sam_set_user_hours_len (SAM_USER_HANDLE *sampass, uint32 len)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
sampass->private.hours_len = len;
return NT_STATUS_OK;
}
NTSTATUS sam_set_user_logon_divs (SAM_USER_HANDLE *sampass, uint16 hours)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
sampass->private.logon_divs = hours;
return NT_STATUS_OK;
}
/**
* Set flags showing what is initalised in the SAM_USER_HANDLE
* @param sampass the SAM_USER_HANDLE in question
* @param flag The *new* flag to be set. Old flags preserved
* this flag is only added.
**/
NTSTATUS sam_set_user_init_flag (SAM_USER_HANDLE *sampass, uint32 flag)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
sampass->private.init_flag |= flag;
return NT_STATUS_OK;
}
NTSTATUS sam_set_user_sid (SAM_USER_HANDLE *sampass, DOM_SID *u_sid)
{
if (!sampass || !u_sid)
return NT_STATUS_UNSUCCESSFUL;
sid_copy(&sampass->private.user_sid, u_sid);
DEBUG(10, ("sam_set_user_sid: setting user sid %s\n",
sid_string_static(&sampass->private.user_sid)));
return NT_STATUS_OK;
}
NTSTATUS sam_set_user_sid_from_string (SAM_USER_HANDLE *sampass, fstring u_sid)
{
DOM_SID new_sid;
if (!sampass || !u_sid)
return NT_STATUS_UNSUCCESSFUL;
DEBUG(10, ("sam_set_user_sid_from_string: setting user sid %s\n",
u_sid));
if (!string_to_sid(&new_sid, u_sid)) {
DEBUG(1, ("sam_set_user_sid_from_string: %s isn't a valid SID!\n", u_sid));
return NT_STATUS_UNSUCCESSFUL;
}
if (!NT_STATUS_IS_OK(sam_set_user_sid(sampass, &new_sid))) {
DEBUG(1, ("sam_set_user_sid_from_string: could not set sid %s on SAM_USER_HANDLE!\n", u_sid));
return NT_STATUS_UNSUCCESSFUL;
}
return NT_STATUS_OK;
}
NTSTATUS sam_set_user_pgroup_sid (SAM_USER_HANDLE *sampass, DOM_SID *g_sid)
{
if (!sampass || !g_sid)
return NT_STATUS_UNSUCCESSFUL;
sid_copy(&sampass->private.group_sid, g_sid);
DEBUG(10, ("sam_set_group_sid: setting group sid %s\n",
sid_string_static(&sampass->private.group_sid)));
return NT_STATUS_OK;
}
NTSTATUS sam_set_user_pgroup_string (SAM_USER_HANDLE *sampass, fstring g_sid)
{
DOM_SID new_sid;
if (!sampass || !g_sid)
return NT_STATUS_UNSUCCESSFUL;
DEBUG(10, ("sam_set_group_sid_from_string: setting group sid %s\n",
g_sid));
if (!string_to_sid(&new_sid, g_sid)) {
DEBUG(1, ("sam_set_group_sid_from_string: %s isn't a valid SID!\n", g_sid));
return NT_STATUS_UNSUCCESSFUL;
}
if (!NT_STATUS_IS_OK(sam_set_user_pgroup_sid(sampass, &new_sid))) {
DEBUG(1, ("sam_set_group_sid_from_string: could not set sid %s on SAM_USER_HANDLE!\n", g_sid));
return NT_STATUS_UNSUCCESSFUL;
}
return NT_STATUS_OK;
}
/*********************************************************************
Set the domain name.
********************************************************************/
NTSTATUS sam_set_user_domain(SAM_USER_HANDLE *sampass, SAM_DOMAIN_HANDLE *domain)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
sampass->private.domain = domain;
return NT_STATUS_OK;
}
/*********************************************************************
Set the user's NT name.
********************************************************************/
NTSTATUS sam_set_user_username(SAM_USER_HANDLE *sampass, const char *nt_username)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
DEBUG(10, ("sam_set_user_username: setting nt username %s, was %s\n", nt_username, sampass->private.username));
sampass->private.username = talloc_strdup(sampass->mem_ctx, nt_username);
return NT_STATUS_OK;
}
/*********************************************************************
Set the user's full name.
********************************************************************/
NTSTATUS sam_set_user_fullname(SAM_USER_HANDLE *sampass, const char *full_name)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
DEBUG(10, ("sam_set_user_fullname: setting full name %s, was %s\n", full_name, sampass->private.full_name));
sampass->private.full_name = talloc_strdup(sampass->mem_ctx, full_name);
return NT_STATUS_OK;
}
/*********************************************************************
Set the user's logon script.
********************************************************************/
NTSTATUS sam_set_user_logon_script(SAM_USER_HANDLE *sampass, const char *logon_script, BOOL store)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
DEBUG(10, ("sam_set_logon_script: from %s to %s\n", logon_script, sampass->private.logon_script));
sampass->private.logon_script = talloc_strdup(sampass->mem_ctx, logon_script);
sam_set_user_init_flag(sampass, FLAG_SAM_LOGONSCRIPT);
return NT_STATUS_OK;
}
/*********************************************************************
Set the user's profile path.
********************************************************************/
NTSTATUS sam_set_user_profile_path (SAM_USER_HANDLE *sampass, const char *profile_path, BOOL store)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
DEBUG(10, ("sam_set_profile_path: setting profile path %s, was %s\n", profile_path, sampass->private.profile_path));
sampass->private.profile_path = talloc_strdup(sampass->mem_ctx, profile_path);
if (store) {
DEBUG(10, ("sam_set_profile_path: setting profile path sam flag!\n"));
sam_set_user_init_flag(sampass, FLAG_SAM_PROFILE);
}
return NT_STATUS_OK;
}
/*********************************************************************
Set the user's directory drive.
********************************************************************/
NTSTATUS sam_set_user_dir_drive (SAM_USER_HANDLE *sampass, const char *dir_drive, BOOL store)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
DEBUG(10, ("sam_set_dir_drive: setting dir drive %s, was %s\n", dir_drive,
sampass->private.dir_drive));
sampass->private.dir_drive = talloc_strdup(sampass->mem_ctx, dir_drive);
if (store) {
DEBUG(10, ("sam_set_dir_drive: setting dir drive sam flag!\n"));
sam_set_user_init_flag(sampass, FLAG_SAM_DRIVE);
}
return NT_STATUS_OK;
}
/*********************************************************************
Set the user's home directory.
********************************************************************/
NTSTATUS sam_set_user_homedir (SAM_USER_HANDLE *sampass, const char *home_dir, BOOL store)
{
if (!sampass) return NT_STATUS_UNSUCCESSFUL;
DEBUG(10, ("sam_set_homedir: setting home dir %s, was %s\n", home_dir,
sampass->private.home_dir));
sampass->private.home_dir = talloc_strdup(sampass->mem_ctx, home_dir);
if (store) {
DEBUG(10, ("sam_set_homedir: setting home dir sam flag!\n"));
sam_set_user_init_flag(sampass, FLAG_SAM_SMBHOME);
}
return NT_STATUS_OK;
}
/*********************************************************************
Set the user's unix home directory.
********************************************************************/
NTSTATUS sam_set_user_unix_homedir (SAM_USER_HANDLE *sampass, const char *unix_home_dir)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
DEBUG(10, ("sam_set_unix_homedir: setting home dir %s, was %s\n", unix_home_dir,
sampass->private.unix_home_dir));
sampass->private.unix_home_dir = talloc_strdup(sampass->mem_ctx, unix_home_dir);
return NT_STATUS_OK;
}
/*********************************************************************
Set the user's account description.
********************************************************************/
NTSTATUS sam_set_user_acct_desc (SAM_USER_HANDLE *sampass, const char *acct_desc)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
sampass->private.acct_desc = talloc_strdup(sampass->mem_ctx, acct_desc);
return NT_STATUS_OK;
}
/*********************************************************************
Set the user's workstation allowed list.
********************************************************************/
NTSTATUS sam_set_user_workstations (SAM_USER_HANDLE *sampass, const char *workstations)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
DEBUG(10, ("sam_set_workstations: setting workstations %s, was %s\n", workstations,
sampass->private.workstations));
sampass->private.workstations = talloc_strdup(sampass->mem_ctx, workstations);
return NT_STATUS_OK;
}
/*********************************************************************
Set the user's 'unknown_str', whatever the heck this actually is...
********************************************************************/
NTSTATUS sam_set_user_unknown_str (SAM_USER_HANDLE *sampass, const char *unknown_str)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
sampass->private.unknown_str = talloc_strdup(sampass->mem_ctx, unknown_str);
return NT_STATUS_OK;
}
/*********************************************************************
Set the user's dial string.
********************************************************************/
NTSTATUS sam_set_user_munged_dial (SAM_USER_HANDLE *sampass, const char *munged_dial)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
sampass->private.munged_dial = talloc_strdup(sampass->mem_ctx, munged_dial);
return NT_STATUS_OK;
}
/*********************************************************************
Set the user's NT hash.
********************************************************************/
NTSTATUS sam_set_user_nt_pwd (SAM_USER_HANDLE *sampass, DATA_BLOB data)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
sampass->private.nt_pw = data;
return NT_STATUS_OK;
}
/*********************************************************************
Set the user's LM hash.
********************************************************************/
NTSTATUS sam_set_user_lm_pwd (SAM_USER_HANDLE *sampass, DATA_BLOB data)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
sampass->private.lm_pw = data;
return NT_STATUS_OK;
}
/*********************************************************************
Set the user's plaintext password only (base procedure, see helper
below)
********************************************************************/
NTSTATUS sam_set_user_plaintext_pw_only (SAM_USER_HANDLE *sampass, DATA_BLOB data)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
sampass->private.plaintext_pw = data;
return NT_STATUS_OK;
}
NTSTATUS sam_set_user_unknown_1 (SAM_USER_HANDLE *sampass, uint32 unkn)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
sampass->private.unknown_1 = unkn;
return NT_STATUS_OK;
}
NTSTATUS sam_set_user_unknown_2 (SAM_USER_HANDLE *sampass, uint32 unkn)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
sampass->private.unknown_2 = unkn;
return NT_STATUS_OK;
}
NTSTATUS sam_set_user_unknown_3 (SAM_USER_HANDLE *sampass, uint32 unkn)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
sampass->private.unknown_3 = unkn;
return NT_STATUS_OK;
}
NTSTATUS sam_set_user_hours (SAM_USER_HANDLE *sampass, const uint8 *hours)
{
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
if (!hours) {
memset ((char *)sampass->private.hours, 0, MAX_HOURS_LEN);
return NT_STATUS_OK;
}
memcpy (sampass->private.hours, hours, MAX_HOURS_LEN);
return NT_STATUS_OK;
}
/* Helpful interfaces to the above */
/*********************************************************************
Sets the last changed times and must change times for a normal
password change.
********************************************************************/
NTSTATUS sam_set_user_pass_changed_now (SAM_USER_HANDLE *sampass)
{
uint32 expire;
NTTIME temptime;
if (!sampass)
return NT_STATUS_UNSUCCESSFUL;
unix_to_nt_time(&temptime, time(NULL));
if (!NT_STATUS_IS_OK(sam_set_user_pass_last_set_time (sampass, temptime)))
return NT_STATUS_UNSUCCESSFUL;
if (!account_policy_get(AP_MAX_PASSWORD_AGE, &expire)
|| (expire==(uint32)-1)) {
get_nttime_max(&temptime);
if (!NT_STATUS_IS_OK(sam_set_user_pass_must_change_time (sampass, temptime, False)))
return NT_STATUS_UNSUCCESSFUL;
} else {
/* FIXME: Add expire to temptime */
if (!NT_STATUS_IS_OK(sam_get_user_pass_last_set_time(sampass,&temptime)) || !NT_STATUS_IS_OK(sam_set_user_pass_must_change_time (sampass, temptime,True)))
return NT_STATUS_UNSUCCESSFUL;
}
return NT_STATUS_OK;
}
/*********************************************************************
Set the user's PLAINTEXT password. Used as an interface to the above.
Also sets the last change time to NOW.
********************************************************************/
NTSTATUS sam_set_plaintext_passwd (SAM_USER_HANDLE *sampass, const char *plaintext)
{
DATA_BLOB data;
uchar new_lanman_p16[16];
uchar new_nt_p16[16];
if (!sampass || !plaintext)
return NT_STATUS_UNSUCCESSFUL;
nt_lm_owf_gen (plaintext, new_nt_p16, new_lanman_p16);
data = data_blob(new_nt_p16, 16);
if (!NT_STATUS_IS_OK(sam_set_user_nt_pwd (sampass, data)))
return NT_STATUS_UNSUCCESSFUL;
data = data_blob(new_lanman_p16, 16);
if (!NT_STATUS_IS_OK(sam_set_user_lm_pwd (sampass, data)))
return NT_STATUS_UNSUCCESSFUL;
if (!NT_STATUS_IS_OK(sam_set_user_pass_changed_now (sampass)))
return NT_STATUS_UNSUCCESSFUL;
return NT_STATUS_OK;
}
|