summaryrefslogtreecommitdiff
path: root/source3/passdb/pdb_get_set.c
blob: 0c338f317ecd665c2c01d41f174668f6b63a9449 (plain)
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
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
/* 
   Unix SMB/CIFS implementation.
   SAM_ACCOUNT access routines
   Copyright (C) Jeremy Allison 		1996-2001
   Copyright (C) Luke Kenneth Casson Leighton 	1996-1998
   Copyright (C) Gerald (Jerry) Carter		2000-2001
   Copyright (C) Andrew Bartlett		2001-2002
   Copyright (C) Stefan (metze) Metzmacher	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_PASSDB

/**
 * @todo Redefine this to NULL, but this changes the API becouse
 *       much of samba assumes that the pdb_get...() funtions 
 *       return pstrings.  (ie not null-pointers).
 *       See also pdb_fill_default_sam().
 */

#define PDB_NOT_QUITE_NULL ""

/*********************************************************************
 Collection of get...() functions for SAM_ACCOUNT_INFO.
 ********************************************************************/

uint16 pdb_get_acct_ctrl (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.acct_ctrl);
	else
		return (ACB_DISABLED);
}

time_t pdb_get_logon_time (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.logon_time);
	else
		return (0);
}

time_t pdb_get_logoff_time (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.logoff_time);
	else
		return (-1);
}

time_t pdb_get_kickoff_time (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.kickoff_time);
	else
		return (-1);
}

time_t pdb_get_pass_last_set_time (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.pass_last_set_time);
	else
		return (-1);
}

time_t pdb_get_pass_can_change_time (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.pass_can_change_time);
	else
		return (-1);
}

time_t pdb_get_pass_must_change_time (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.pass_must_change_time);
	else
		return (-1);
}

uint16 pdb_get_logon_divs (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.logon_divs);
	else
		return (-1);
}

uint32 pdb_get_hours_len (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.hours_len);
	else
		return (-1);
}

const uint8* pdb_get_hours (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.hours);
	else
		return (NULL);
}

const uint8* pdb_get_nt_passwd (const SAM_ACCOUNT *sampass)
{
	if (sampass) {
		SMB_ASSERT((!sampass->private.nt_pw.data) 
			   || sampass->private.nt_pw.length == NT_HASH_LEN);
		return ((uint8*)sampass->private.nt_pw.data);
	}
	else
		return (NULL);
}

const uint8* pdb_get_lanman_passwd (const SAM_ACCOUNT *sampass)
{
	if (sampass) {
		SMB_ASSERT((!sampass->private.lm_pw.data) 
			   || sampass->private.lm_pw.length == LM_HASH_LEN);
		return ((uint8*)sampass->private.lm_pw.data);
	}
	else
		return (NULL);
}

/* 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 passdb backends that might 
   want to store more than just the NTLM hashes.
*/
const char* pdb_get_plaintext_passwd (const SAM_ACCOUNT *sampass)
{
	if (sampass) {
		return (sampass->private.plaintext_pw);
	}
	else
		return (NULL);
}
const DOM_SID *pdb_get_user_sid(const SAM_ACCOUNT *sampass)
{
	if (sampass) 
		return &sampass->private.user_sid;
	else
		return (NULL);
}

const DOM_SID *pdb_get_group_sid(const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return &sampass->private.group_sid;
	else	
		return (NULL);
}	

/**
 * Get flags showing what is initalised in the SAM_ACCOUNT
 * @param sampass the SAM_ACCOUNT in question
 * @return the flags indicating the members initialised in the struct.
 **/
 
uint32 pdb_get_init_flag (const SAM_ACCOUNT *sampass)
{
        if (sampass)
		return sampass->private.init_flag;
	else 
                return FLAG_SAM_UNINIT;
}

uid_t pdb_get_uid (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.uid);
	else
		return (-1);
}

gid_t pdb_get_gid (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.gid);
	else
		return (-1);
}

const char* pdb_get_username (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.username);
	else
		return (NULL);
}

const char* pdb_get_domain (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.domain);
	else
		return (NULL);
}

const char* pdb_get_nt_username (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.nt_username);
	else
		return (NULL);
}

const char* pdb_get_fullname (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.full_name);
	else
		return (NULL);
}

const char* pdb_get_homedir (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.home_dir);
	else
		return (NULL);
}

const char* pdb_get_unix_homedir (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.unix_home_dir);
	else
		return (NULL);
}

const char* pdb_get_dir_drive (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.dir_drive);
	else
		return (NULL);
}

const char* pdb_get_logon_script (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.logon_script);
	else
		return (NULL);
}

const char* pdb_get_profile_path (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.profile_path);
	else
		return (NULL);
}

const char* pdb_get_acct_desc (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.acct_desc);
	else
		return (NULL);
}

const char* pdb_get_workstations (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.workstations);
	else
		return (NULL);
}

const char* pdb_get_unknown_str (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.unknown_str);
	else
		return (NULL);
}

const char* pdb_get_munged_dial (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.munged_dial);
	else
		return (NULL);
}

uint32 pdb_get_unknown3 (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.unknown_3);
	else
		return (-1);
}

uint32 pdb_get_unknown5 (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.unknown_5);
	else
		return (-1);
}

uint32 pdb_get_unknown6 (const SAM_ACCOUNT *sampass)
{
	if (sampass)
		return (sampass->private.unknown_6);
	else
		return (-1);
}

/*********************************************************************
 Collection of set...() functions for SAM_ACCOUNT_INFO.
 ********************************************************************/

BOOL pdb_set_acct_ctrl (SAM_ACCOUNT *sampass, uint16 flags)
{
	if (!sampass)
		return False;
		
	if (sampass) {
		sampass->private.acct_ctrl = flags;
		return True;
	}
	
	return False;
}

BOOL pdb_set_logon_time (SAM_ACCOUNT *sampass, time_t mytime, BOOL store)
{
	if (!sampass)
		return False;

	sampass->private.logon_time = mytime;

	if (store)
		pdb_set_init_flag(sampass, FLAG_SAM_LOGONTIME); 

	return True;
}

BOOL pdb_set_logoff_time (SAM_ACCOUNT *sampass, time_t mytime, BOOL store)
{
	if (!sampass)
		return False;

	sampass->private.logoff_time = mytime;

	if (store)
		pdb_set_init_flag(sampass, FLAG_SAM_LOGOFFTIME); 

	return True;
}

BOOL pdb_set_kickoff_time (SAM_ACCOUNT *sampass, time_t mytime, BOOL store)
{
	if (!sampass)
		return False;

	sampass->private.kickoff_time = mytime;

	if (store)
		pdb_set_init_flag(sampass, FLAG_SAM_KICKOFFTIME); 

	return True;
}

BOOL pdb_set_pass_can_change_time (SAM_ACCOUNT *sampass, time_t mytime, BOOL store)
{
	if (!sampass)
		return False;

	sampass->private.pass_can_change_time = mytime;

	if (store)
		pdb_set_init_flag(sampass, FLAG_SAM_CANCHANGETIME); 

	return True;
}

BOOL pdb_set_pass_must_change_time (SAM_ACCOUNT *sampass, time_t mytime, BOOL store)
{
	if (!sampass)
		return False;

	sampass->private.pass_must_change_time = mytime;

	if (store)
		pdb_set_init_flag(sampass, FLAG_SAM_MUSTCHANGETIME); 

	return True;
}

BOOL pdb_set_pass_last_set_time (SAM_ACCOUNT *sampass, time_t mytime)
{
	if (!sampass)
		return False;

	sampass->private.pass_last_set_time = mytime;

	return True;
}

BOOL pdb_set_hours_len (SAM_ACCOUNT *sampass, uint32 len)
{
	if (!sampass)
		return False;

	sampass->private.hours_len = len;
	return True;
}

BOOL pdb_set_logon_divs (SAM_ACCOUNT *sampass, uint16 hours)
{
	if (!sampass)
		return False;

	sampass->private.logon_divs = hours;
	return True;
}

/**
 * Set flags showing what is initalised in the SAM_ACCOUNT
 * @param sampass the SAM_ACCOUNT in question
 * @param flag The *new* flag to be set.  Old flags preserved
 *             this flag is only added.  
 **/
 
BOOL pdb_set_init_flag (SAM_ACCOUNT *sampass, uint32 flag)
{
        if (!sampass)
                return False;

        sampass->private.init_flag |= flag;

        return True;
}

BOOL pdb_set_uid (SAM_ACCOUNT *sampass, const uid_t uid)
{
	if (!sampass)
		return False;
	
	DEBUG(10, ("pdb_set_uid: setting uid %d, was %d\n", 
		   (int)uid, (int)sampass->private.uid));
 
	sampass->private.uid = uid;
	pdb_set_init_flag(sampass, FLAG_SAM_UID); 

	return True;

}

BOOL pdb_set_gid (SAM_ACCOUNT *sampass, const gid_t gid)
{
	if (!sampass)
		return False;
		
	DEBUG(10, ("pdb_set_gid: setting gid %d, was %d\n", 
		   (int)gid, (int)sampass->private.gid));
 
	sampass->private.gid = gid; 
	pdb_set_init_flag(sampass, FLAG_SAM_GID); 

	return True;

}

BOOL pdb_set_user_sid (SAM_ACCOUNT *sampass, DOM_SID *u_sid)
{
	if (!sampass || !u_sid)
		return False;
	
	sid_copy(&sampass->private.user_sid, u_sid);

	DEBUG(10, ("pdb_set_user_sid: setting user sid %s\n", 
		    sid_string_static(&sampass->private.user_sid)));
	
	return True;
}

BOOL pdb_set_user_sid_from_string (SAM_ACCOUNT *sampass, fstring u_sid)
{
	DOM_SID new_sid;
	if (!sampass || !u_sid)
		return False;

	DEBUG(10, ("pdb_set_user_sid_from_string: setting user sid %s\n",
		   u_sid));

	if (!string_to_sid(&new_sid, u_sid)) { 
		DEBUG(1, ("pdb_set_user_sid_from_string: %s isn't a valid SID!\n", u_sid));
		return False;
	}
	 
	if (!pdb_set_user_sid(sampass, &new_sid)) {
		DEBUG(1, ("pdb_set_user_sid_from_string: could not set sid %s on SAM_ACCOUNT!\n", u_sid));
		return False;
	}

	return True;
}

BOOL pdb_set_group_sid (SAM_ACCOUNT *sampass, DOM_SID *g_sid)
{
	if (!sampass || !g_sid)
		return False;

	sid_copy(&sampass->private.group_sid, g_sid);

	DEBUG(10, ("pdb_set_group_sid: setting group sid %s\n", 
		    sid_string_static(&sampass->private.group_sid)));

	return True;
}

BOOL pdb_set_group_sid_from_string (SAM_ACCOUNT *sampass, fstring g_sid)
{
	DOM_SID new_sid;
	if (!sampass || !g_sid)
		return False;

	DEBUG(10, ("pdb_set_group_sid_from_string: setting group sid %s\n",
		   g_sid));

	if (!string_to_sid(&new_sid, g_sid)) { 
		DEBUG(1, ("pdb_set_group_sid_from_string: %s isn't a valid SID!\n", g_sid));
		return False;
	}
	 
	if (!pdb_set_group_sid(sampass, &new_sid)) {
		DEBUG(1, ("pdb_set_group_sid_from_string: could not set sid %s on SAM_ACCOUNT!\n", g_sid));
		return False;
	}
	return True;
}

/*********************************************************************
 Set the user's UNIX name.
 ********************************************************************/

BOOL pdb_set_username(SAM_ACCOUNT *sampass, const char *username)
{	
	if (!sampass)
		return False;
 
	if (username) { 
		DEBUG(10, ("pdb_set_username: setting username %s, was %s\n", username,
			(sampass->private.username)?(sampass->private.username):"NULL"));

		sampass->private.username = talloc_strdup(sampass->mem_ctx, username);

		if (!sampass->private.username) {
			DEBUG(0, ("pdb_set_username: talloc_strdup() failed!\n"));
			return False;
		}

	} else {
		sampass->private.username = PDB_NOT_QUITE_NULL;
	}

	return True;
}

/*********************************************************************
 Set the domain name.
 ********************************************************************/

BOOL pdb_set_domain(SAM_ACCOUNT *sampass, const char *domain)
{	
	if (!sampass)
		return False;

	if (domain) { 
		DEBUG(10, ("pdb_set_domain: setting domain %s, was %s\n", domain,
			(sampass->private.domain)?(sampass->private.domain):"NULL"));

		sampass->private.domain = talloc_strdup(sampass->mem_ctx, domain);

		if (!sampass->private.domain) {
			DEBUG(0, ("pdb_set_domain: talloc_strdup() failed!\n"));
			return False;
		}

	} else {
		sampass->private.domain = PDB_NOT_QUITE_NULL;
	}

	return True;
}

/*********************************************************************
 Set the user's NT name.
 ********************************************************************/

BOOL pdb_set_nt_username(SAM_ACCOUNT *sampass, const char *nt_username)
{
	if (!sampass)
		return False;

	if (nt_username) { 
		DEBUG(10, ("pdb_set_nt_username: setting nt username %s, was %s\n", nt_username,
			(sampass->private.nt_username)?(sampass->private.nt_username):"NULL"));
 
		sampass->private.nt_username = talloc_strdup(sampass->mem_ctx, nt_username);
		
		if (!sampass->private.nt_username) {
			DEBUG(0, ("pdb_set_nt_username: talloc_strdup() failed!\n"));
			return False;
		}

	} else {
		sampass->private.nt_username = PDB_NOT_QUITE_NULL;
	}

	return True;
}

/*********************************************************************
 Set the user's full name.
 ********************************************************************/

BOOL pdb_set_fullname(SAM_ACCOUNT *sampass, const char *full_name)
{
	if (!sampass)
		return False;

	if (full_name) { 
		DEBUG(10, ("pdb_set_full_name: setting full name %s, was %s\n", full_name,
			(sampass->private.full_name)?(sampass->private.full_name):"NULL"));
	
		sampass->private.full_name = talloc_strdup(sampass->mem_ctx, full_name);

		if (!sampass->private.full_name) {
			DEBUG(0, ("pdb_set_fullname: talloc_strdup() failed!\n"));
			return False;
		}

	} else {
		sampass->private.full_name = PDB_NOT_QUITE_NULL;
	}

	return True;
}

/*********************************************************************
 Set the user's logon script.
 ********************************************************************/

BOOL pdb_set_logon_script(SAM_ACCOUNT *sampass, const char *logon_script, BOOL store)
{
	if (!sampass)
		return False;

	if (logon_script) { 
		DEBUG(10, ("pdb_set_logon_script: setting logon script %s, was %s\n", logon_script,
			(sampass->private.logon_script)?(sampass->private.logon_script):"NULL"));
 
		sampass->private.logon_script = talloc_strdup(sampass->mem_ctx, logon_script);

		if (!sampass->private.logon_script) {
			DEBUG(0, ("pdb_set_logon_script: talloc_strdup() failed!\n"));
			return False;
		}

	} else {
		sampass->private.logon_script = PDB_NOT_QUITE_NULL;
	}
	
	if (store) {
		DEBUG(10, ("pdb_set_logon_script: setting logon script sam flag!\n"));
		pdb_set_init_flag(sampass, FLAG_SAM_LOGONSCRIPT);
	}

	return True;
}

/*********************************************************************
 Set the user's profile path.
 ********************************************************************/

BOOL pdb_set_profile_path (SAM_ACCOUNT *sampass, const char *profile_path, BOOL store)
{
	if (!sampass)
		return False;

	if (profile_path) { 
		DEBUG(10, ("pdb_set_profile_path: setting profile path %s, was %s\n", profile_path,
			(sampass->private.profile_path)?(sampass->private.profile_path):"NULL"));
 
		sampass->private.profile_path = talloc_strdup(sampass->mem_ctx, profile_path);
		
		if (!sampass->private.profile_path) {
			DEBUG(0, ("pdb_set_profile_path: talloc_strdup() failed!\n"));
			return False;
		}

	} else {
		sampass->private.profile_path = PDB_NOT_QUITE_NULL;
	}

	if (store) {
		DEBUG(10, ("pdb_set_profile_path: setting profile path sam flag!\n"));
		pdb_set_init_flag(sampass, FLAG_SAM_PROFILE);
	}

	return True;
}

/*********************************************************************
 Set the user's directory drive.
 ********************************************************************/

BOOL pdb_set_dir_drive (SAM_ACCOUNT *sampass, const char *dir_drive, BOOL store)
{
	if (!sampass)
		return False;

	if (dir_drive) { 
		DEBUG(10, ("pdb_set_dir_drive: setting dir drive %s, was %s\n", dir_drive,
			(sampass->private.dir_drive)?(sampass->private.dir_drive):"NULL"));
 
		sampass->private.dir_drive = talloc_strdup(sampass->mem_ctx, dir_drive);
		
		if (!sampass->private.dir_drive) {
			DEBUG(0, ("pdb_set_dir_drive: talloc_strdup() failed!\n"));
			return False;
		}

	} else {
		sampass->private.dir_drive = PDB_NOT_QUITE_NULL;
	}
	
	if (store) {
		DEBUG(10, ("pdb_set_dir_drive: setting dir drive sam flag!\n"));
		pdb_set_init_flag(sampass, FLAG_SAM_DRIVE);
	}

	return True;
}

/*********************************************************************
 Set the user's home directory.
 ********************************************************************/

BOOL pdb_set_homedir (SAM_ACCOUNT *sampass, const char *home_dir, BOOL store)
{
	if (!sampass)
		return False;

	if (home_dir) { 
		DEBUG(10, ("pdb_set_homedir: setting home dir %s, was %s\n", home_dir,
			(sampass->private.home_dir)?(sampass->private.home_dir):"NULL"));
 
		sampass->private.home_dir = talloc_strdup(sampass->mem_ctx, home_dir);
		
		if (!sampass->private.home_dir) {
			DEBUG(0, ("pdb_set_home_dir: talloc_strdup() failed!\n"));
			return False;
		}

	} else {
		sampass->private.home_dir = PDB_NOT_QUITE_NULL;
	}

	if (store) {
		DEBUG(10, ("pdb_set_homedir: setting home dir sam flag!\n"));
		pdb_set_init_flag(sampass, FLAG_SAM_SMBHOME);
	}

	return True;
}

/*********************************************************************
 Set the user's unix home directory.
 ********************************************************************/

BOOL pdb_set_unix_homedir (SAM_ACCOUNT *sampass, const char *unix_home_dir)
{
	if (!sampass)
		return False;

	if (unix_home_dir) { 
		DEBUG(10, ("pdb_set_unix_homedir: setting home dir %s, was %s\n", unix_home_dir,
			(sampass->private.unix_home_dir)?(sampass->private.unix_home_dir):"NULL"));
 
		sampass->private.unix_home_dir = talloc_strdup(sampass->mem_ctx, 
							  unix_home_dir);
		
		if (!sampass->private.unix_home_dir) {
			DEBUG(0, ("pdb_set_unix_home_dir: talloc_strdup() failed!\n"));
			return False;
		}

	} else {
		sampass->private.unix_home_dir = PDB_NOT_QUITE_NULL;
	}

	return True;
}

/*********************************************************************
 Set the user's account description.
 ********************************************************************/

BOOL pdb_set_acct_desc (SAM_ACCOUNT *sampass, const char *acct_desc)
{
	if (!sampass)
		return False;

	if (acct_desc) { 
		sampass->private.acct_desc = talloc_strdup(sampass->mem_ctx, acct_desc);

		if (!sampass->private.acct_desc) {
			DEBUG(0, ("pdb_set_acct_desc: talloc_strdup() failed!\n"));
			return False;
		}

	} else {
		sampass->private.acct_desc = PDB_NOT_QUITE_NULL;
	}

	return True;
}

/*********************************************************************
 Set the user's workstation allowed list.
 ********************************************************************/

BOOL pdb_set_workstations (SAM_ACCOUNT *sampass, const char *workstations)
{
	if (!sampass)
		return False;

	if (workstations) { 
		DEBUG(10, ("pdb_set_workstations: setting workstations %s, was %s\n", workstations,
			(sampass->private.workstations)?(sampass->private.workstations):"NULL"));
 
		sampass->private.workstations = talloc_strdup(sampass->mem_ctx, workstations);

		if (!sampass->private.workstations) {
			DEBUG(0, ("pdb_set_workstations: talloc_strdup() failed!\n"));
			return False;
		}

	} else {
		sampass->private.workstations = PDB_NOT_QUITE_NULL;
	}

	return True;
}

/*********************************************************************
 Set the user's 'unknown_str', whatever the heck this actually is...
 ********************************************************************/

BOOL pdb_set_unknown_str (SAM_ACCOUNT *sampass, const char *unknown_str)
{
	if (!sampass)
		return False;

	if (unknown_str) { 
		sampass->private.unknown_str = talloc_strdup(sampass->mem_ctx, unknown_str);
		
		if (!sampass->private.unknown_str) {
			DEBUG(0, ("pdb_set_unknown_str: talloc_strdup() failed!\n"));
			return False;
		}

	} else {
		sampass->private.unknown_str = PDB_NOT_QUITE_NULL;
	}

	return True;
}

/*********************************************************************
 Set the user's dial string.
 ********************************************************************/

BOOL pdb_set_munged_dial (SAM_ACCOUNT *sampass, const char *munged_dial)
{
	if (!sampass)
		return False;

	if (munged_dial) { 
		sampass->private.munged_dial = talloc_strdup(sampass->mem_ctx, munged_dial);
		
		if (!sampass->private.munged_dial) {
			DEBUG(0, ("pdb_set_munged_dial: talloc_strdup() failed!\n"));
			return False;
		}

	} else {
		sampass->private.munged_dial = PDB_NOT_QUITE_NULL;
	}

	return True;
}

/*********************************************************************
 Set the user's NT hash.
 ********************************************************************/

BOOL pdb_set_nt_passwd (SAM_ACCOUNT *sampass, const uint8 *pwd)
{
	if (!sampass)
		return False;

	data_blob_clear_free(&sampass->private.nt_pw);
	
	sampass->private.nt_pw = data_blob(pwd, NT_HASH_LEN);

	return True;
}

/*********************************************************************
 Set the user's LM hash.
 ********************************************************************/

BOOL pdb_set_lanman_passwd (SAM_ACCOUNT *sampass, const uint8 pwd[16])
{
	if (!sampass)
		return False;

	data_blob_clear_free(&sampass->private.lm_pw);
	
	sampass->private.lm_pw = data_blob(pwd, LM_HASH_LEN);

	return True;
}

/*********************************************************************
 Set the user's plaintext password only (base procedure, see helper
 below)
 ********************************************************************/

BOOL pdb_set_plaintext_pw_only (SAM_ACCOUNT *sampass, const char *password)
{
	if (!sampass)
		return False;

	if (password) { 
		if (sampass->private.plaintext_pw!=NULL) 
			memset(sampass->private.plaintext_pw,'\0',strlen(sampass->private.plaintext_pw)+1);
		sampass->private.plaintext_pw = talloc_strdup(sampass->mem_ctx, password);
		
		if (!sampass->private.plaintext_pw) {
			DEBUG(0, ("pdb_set_unknown_str: talloc_strdup() failed!\n"));
			return False;
		}

	} else {
		sampass->private.plaintext_pw = NULL;
	}

	return True;
}

BOOL pdb_set_unknown_3 (SAM_ACCOUNT *sampass, uint32 unkn)
{
	if (!sampass)
		return False;

	sampass->private.unknown_3 = unkn;
	return True;
}

BOOL pdb_set_unknown_5 (SAM_ACCOUNT *sampass, uint32 unkn)
{
	if (!sampass)
		return False;

	sampass->private.unknown_5 = unkn;
	return True;
}

BOOL pdb_set_unknown_6 (SAM_ACCOUNT *sampass, uint32 unkn)
{
	if (!sampass)
		return False;

	sampass->private.unknown_6 = unkn;
	return True;
}

BOOL pdb_set_hours (SAM_ACCOUNT *sampass, const uint8 *hours)
{
	if (!sampass)
		return False;

	if (!hours) {
		memset ((char *)sampass->private.hours, 0, MAX_HOURS_LEN);
		return True;
	}
	
	memcpy (sampass->private.hours, hours, MAX_HOURS_LEN);

	return True;
}


/* Helpful interfaces to the above */

/*********************************************************************
 Sets the last changed times and must change times for a normal
 password change.
 ********************************************************************/

BOOL pdb_set_pass_changed_now (SAM_ACCOUNT *sampass)
{
	uint32 expire;

	if (!sampass)
		return False;
	
	if (!pdb_set_pass_last_set_time (sampass, time(NULL)))
		return False;

	if (!account_policy_get(AP_MAX_PASSWORD_AGE, &expire) 
	    || (expire==(uint32)-1)) {
		if (!pdb_set_pass_must_change_time (sampass, get_time_t_max(), False))
			return False;
	} else {
		if (!pdb_set_pass_must_change_time (sampass, 
						    pdb_get_pass_last_set_time(sampass)
						    + expire, True))
			return False;
	}
	
	return True;
}

/*********************************************************************
 Set the user's PLAINTEXT password.  Used as an interface to the above.
 Also sets the last change time to NOW.
 ********************************************************************/

BOOL pdb_set_plaintext_passwd (SAM_ACCOUNT *sampass, const char *plaintext)
{
	uchar new_lanman_p16[16];
	uchar new_nt_p16[16];

	if (!sampass || !plaintext)
		return False;
	
	nt_lm_owf_gen (plaintext, new_nt_p16, new_lanman_p16);

	if (!pdb_set_nt_passwd (sampass, new_nt_p16)) 
		return False;

	if (!pdb_set_lanman_passwd (sampass, new_lanman_p16)) 
		return False;

	if (!pdb_set_plaintext_pw_only (sampass, plaintext)) 
		return False;

	if (!pdb_set_pass_changed_now (sampass))
		return False;

	return True;
}