2 Unix SMB/CIFS implementation.
4 Copyright (C) Simo Sorce 2002
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 2 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, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 /* Functions to get/set info from a GUMS object */
25 NTSTATUS
gums_create_object(GUMS_OBJECT
**obj
, uint32 type
)
31 mem_ctx
= talloc_init("gums_create_object");
33 DEBUG(0, ("gums_create_object: Out of memory!\n"));
35 return NT_STATUS_NO_MEMORY
;
38 go
= talloc_zero(mem_ctx
, sizeof(GUMS_OBJECT
));
40 DEBUG(0, ("gums_create_object: Out of memory!\n"));
41 talloc_destroy(mem_ctx
);
43 return NT_STATUS_NO_MEMORY
;
46 go
->mem_ctx
= mem_ctx
;
48 go
->version
= GUMS_OBJECT_VERSION
;
52 go
->domain
= (GUMS_DOMAIN
*)talloc_zero(mem_ctx
, sizeof(GUMS_DOMAIN
));
54 ret
= NT_STATUS_NO_MEMORY
;
55 DEBUG(0, ("gums_create_object: Out of memory!\n"));
62 case GUMS_OBJ_WORKSTATION_TRUST:
63 case GUMS_OBJ_SERVER_TRUST:
64 case GUMS_OBJ_DOMAIN_TRUST:
66 case GUMS_OBJ_NORMAL_USER
:
67 go
->user
= (GUMS_USER
*)talloc_zero(mem_ctx
, sizeof(GUMS_USER
));
69 ret
= NT_STATUS_NO_MEMORY
;
70 DEBUG(0, ("gums_create_object: Out of memory!\n"));
73 gums_set_user_acct_ctrl(go
, ACB_NORMAL
);
74 gums_set_user_hours(go
, 0, NULL
);
80 go
->group
= (GUMS_GROUP
*)talloc_zero(mem_ctx
, sizeof(GUMS_GROUP
));
82 ret
= NT_STATUS_NO_MEMORY
;
83 DEBUG(0, ("gums_create_object: Out of memory!\n"));
90 /* TODO: throw error */
91 ret
= NT_STATUS_OBJECT_TYPE_MISMATCH
;
99 talloc_destroy(go
->mem_ctx
);
104 NTSTATUS
gums_create_privilege(GUMS_PRIVILEGE
**priv
)
109 mem_ctx
= talloc_init("gums_create_privilege");
111 DEBUG(0, ("gums_create_privilege: Out of memory!\n"));
113 return NT_STATUS_NO_MEMORY
;
116 pri
= talloc_zero(mem_ctx
, sizeof(GUMS_PRIVILEGE
));
118 DEBUG(0, ("gums_create_privilege: Out of memory!\n"));
119 talloc_destroy(mem_ctx
);
121 return NT_STATUS_NO_MEMORY
;
124 pri
->mem_ctx
= mem_ctx
;
125 pri
->version
= GUMS_PRIVILEGE_VERSION
;
131 NTSTATUS
gums_destroy_object(GUMS_OBJECT
**obj
)
134 return NT_STATUS_INVALID_PARAMETER
;
137 talloc_destroy((*obj
)->mem_ctx
);
143 NTSTATUS
gums_destroy_privilege(GUMS_PRIVILEGE
**priv
)
145 if (!priv
|| !(*priv
))
146 return NT_STATUS_INVALID_PARAMETER
;
148 if ((*priv
)->mem_ctx
)
149 talloc_destroy((*priv
)->mem_ctx
);
155 void gums_reset_object(GUMS_OBJECT
*go
)
160 go
->description
= NULL
;
163 case GUMS_OBJ_DOMAIN
:
164 memset(go
->domain
, 0, sizeof(GUMS_DOMAIN
));
168 case GUMS_OBJ_WORKSTATION_TRUST:
169 case GUMS_OBJ_SERVER_TRUST:
170 case GUMS_OBJ_DOMAIN_TRUST:
172 case GUMS_OBJ_NORMAL_USER
:
173 memset(go
->user
, 0, sizeof(GUMS_USER
));
174 gums_set_user_acct_ctrl(go
, ACB_NORMAL
);
179 memset(go
->group
, 0, sizeof(GUMS_GROUP
));
187 uint32
gums_get_object_type(const GUMS_OBJECT
*obj
)
195 uint32
gums_get_object_seq_num(const GUMS_OBJECT
*obj
)
203 uint32
gums_get_object_version(const GUMS_OBJECT
*obj
)
211 const SEC_DESC
*gums_get_sec_desc(const GUMS_OBJECT
*obj
)
216 return obj
->sec_desc
;
219 const DOM_SID
*gums_get_object_sid(const GUMS_OBJECT
*obj
)
227 const char *gums_get_object_name(const GUMS_OBJECT
*obj
)
235 const char *gums_get_object_description(const GUMS_OBJECT
*obj
)
240 return obj
->description
;
243 NTSTATUS
gums_set_object_seq_num(GUMS_OBJECT
*obj
, uint32 seq_num
)
246 return NT_STATUS_INVALID_PARAMETER
;
248 obj
->seq_num
= seq_num
;
252 NTSTATUS
gums_set_object_version(GUMS_OBJECT
*obj
, uint32 version
)
255 return NT_STATUS_INVALID_PARAMETER
;
257 obj
->version
= version
;
261 NTSTATUS
gums_set_sec_desc(GUMS_OBJECT
*obj
, const SEC_DESC
*sec_desc
)
263 if (!obj
|| !sec_desc
)
264 return NT_STATUS_INVALID_PARAMETER
;
266 obj
->sec_desc
= dup_sec_desc(obj
->mem_ctx
, sec_desc
);
267 if (!(obj
->sec_desc
)) return NT_STATUS_UNSUCCESSFUL
;
271 NTSTATUS
gums_set_object_sid(GUMS_OBJECT
*obj
, const DOM_SID
*sid
)
274 return NT_STATUS_INVALID_PARAMETER
;
276 obj
->sid
= sid_dup_talloc(obj
->mem_ctx
, sid
);
277 if (!(obj
->sid
)) return NT_STATUS_UNSUCCESSFUL
;
281 NTSTATUS
gums_set_object_name(GUMS_OBJECT
*obj
, const char *name
)
284 return NT_STATUS_INVALID_PARAMETER
;
286 obj
->name
= (char *)talloc_strdup(obj
->mem_ctx
, name
);
287 if (!(obj
->name
)) return NT_STATUS_UNSUCCESSFUL
;
291 NTSTATUS
gums_set_object_description(GUMS_OBJECT
*obj
, const char *description
)
293 if (!obj
|| !description
)
294 return NT_STATUS_INVALID_PARAMETER
;
296 obj
->description
= (char *)talloc_strdup(obj
->mem_ctx
, description
);
297 if (!(obj
->description
)) return NT_STATUS_UNSUCCESSFUL
;
302 NTSTATUS gums_get_object_privileges(PRIVILEGE_SET **priv_set, const GUMS_OBJECT *obj)
305 return NT_STATUS_INVALID_PARAMETER;
307 *priv_set = obj->priv_set;
312 uint32
gums_get_domain_next_rid(const GUMS_OBJECT
*obj
)
314 if (obj
->type
!= GUMS_OBJ_DOMAIN
)
317 return obj
->domain
->next_rid
;
320 NTSTATUS
gums_set_domain_next_rid(GUMS_OBJECT
*obj
, uint32 rid
)
323 return NT_STATUS_INVALID_PARAMETER
;
325 if (obj
->type
!= GUMS_OBJ_DOMAIN
)
326 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
328 obj
->domain
->next_rid
= rid
;
332 /* User specific functions */
334 const DOM_SID
*gums_get_user_pri_group(const GUMS_OBJECT
*obj
)
336 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
)
339 return obj
->user
->group_sid
;
342 const DATA_BLOB
gums_get_user_nt_pwd(const GUMS_OBJECT
*obj
)
346 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
)
347 return data_blob(NULL
, 0);
349 pdb_sethexpwd(p
, (unsigned char *)(obj
->user
->nt_pw
.data
), 0);
350 DEBUG(100, ("Reading NT Password=[%s]\n", p
));
352 return obj
->user
->nt_pw
;
355 const DATA_BLOB
gums_get_user_lm_pwd(const GUMS_OBJECT
*obj
)
359 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
)
360 return data_blob(NULL
, 0);
362 pdb_sethexpwd(p
, (unsigned char *)(obj
->user
->lm_pw
.data
), 0);
363 DEBUG(100, ("Reading LM Password=[%s]\n", p
));
365 return obj
->user
->lm_pw
;
368 const char *gums_get_user_fullname(const GUMS_OBJECT
*obj
)
370 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
)
373 return obj
->user
->full_name
;
376 const char *gums_get_user_homedir(const GUMS_OBJECT
*obj
)
378 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
)
381 return obj
->user
->home_dir
;
384 const char *gums_get_user_dir_drive(const GUMS_OBJECT
*obj
)
386 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
)
389 return obj
->user
->dir_drive
;
392 const char *gums_get_user_profile_path(const GUMS_OBJECT
*obj
)
394 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
)
397 return obj
->user
->profile_path
;
400 const char *gums_get_user_logon_script(const GUMS_OBJECT
*obj
)
402 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
)
405 return obj
->user
->logon_script
;
408 const char *gums_get_user_workstations(const GUMS_OBJECT
*obj
)
410 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
)
413 return obj
->user
->workstations
;
416 const char *gums_get_user_unknown_str(const GUMS_OBJECT
*obj
)
418 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
)
421 return obj
->user
->unknown_str
;
424 const char *gums_get_user_munged_dial(const GUMS_OBJECT
*obj
)
426 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
)
429 return obj
->user
->munged_dial
;
432 NTTIME
gums_get_user_logon_time(const GUMS_OBJECT
*obj
)
434 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
) {
436 init_nt_time(&null_time
);
440 return obj
->user
->logon_time
;
443 NTTIME
gums_get_user_logoff_time(const GUMS_OBJECT
*obj
)
445 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
) {
447 init_nt_time(&null_time
);
451 return obj
->user
->logoff_time
;
454 NTTIME
gums_get_user_kickoff_time(const GUMS_OBJECT
*obj
)
456 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
) {
458 init_nt_time(&null_time
);
462 return obj
->user
->kickoff_time
;
465 NTTIME
gums_get_user_pass_last_set_time(const GUMS_OBJECT
*obj
)
467 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
) {
469 init_nt_time(&null_time
);
473 return obj
->user
->pass_last_set_time
;
476 NTTIME
gums_get_user_pass_can_change_time(const GUMS_OBJECT
*obj
)
478 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
) {
480 init_nt_time(&null_time
);
484 return obj
->user
->pass_can_change_time
;
487 NTTIME
gums_get_user_pass_must_change_time(const GUMS_OBJECT
*obj
)
489 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
) {
491 init_nt_time(&null_time
);
495 return obj
->user
->pass_must_change_time
;
498 uint16
gums_get_user_acct_ctrl(const GUMS_OBJECT
*obj
)
500 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
)
503 return obj
->user
->acct_ctrl
;
506 uint16
gums_get_user_logon_divs(const GUMS_OBJECT
*obj
)
508 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
)
511 return obj
->user
->logon_divs
;
514 uint32
gums_get_user_hours_len(const GUMS_OBJECT
*obj
)
516 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
)
519 return obj
->user
->hours_len
;
522 const uint8
*gums_get_user_hours(const GUMS_OBJECT
*obj
)
524 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
)
527 return obj
->user
->hours
;
530 uint32
gums_get_user_unknown_3(const GUMS_OBJECT
*obj
)
532 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
)
535 return obj
->user
->unknown_3
;
538 uint16
gums_get_user_bad_password_count(const GUMS_OBJECT
*obj
)
540 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
)
543 return obj
->user
->bad_password_count
;
546 uint16
gums_get_user_logon_count(const GUMS_OBJECT
*obj
)
548 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
)
551 return obj
->user
->logon_count
;
554 uint32
gums_get_user_unknown_6(const GUMS_OBJECT
*obj
)
556 if (!obj
|| obj
->type
!= GUMS_OBJ_NORMAL_USER
)
559 return obj
->user
->unknown_6
;
562 NTSTATUS
gums_set_user_pri_group(GUMS_OBJECT
*obj
, const DOM_SID
*sid
)
565 return NT_STATUS_INVALID_PARAMETER
;
567 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
568 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
570 obj
->user
->group_sid
= sid_dup_talloc(obj
->mem_ctx
, sid
);
571 if (!(obj
->user
->group_sid
)) return NT_STATUS_NO_MEMORY
;
575 NTSTATUS
gums_set_user_nt_pwd(GUMS_OBJECT
*obj
, const DATA_BLOB nt_pwd
)
581 return NT_STATUS_INVALID_PARAMETER
;
583 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
584 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
586 obj
->user
->nt_pw
= data_blob_talloc(obj
->mem_ctx
, nt_pwd
.data
, nt_pwd
.length
);
588 memcpy(r
, nt_pwd
.data
, 16);
589 pdb_sethexpwd(p
, r
, 0);
590 DEBUG(100, ("Setting NT Password=[%s]\n", p
));
595 NTSTATUS
gums_set_user_lm_pwd(GUMS_OBJECT
*obj
, const DATA_BLOB lm_pwd
)
601 return NT_STATUS_INVALID_PARAMETER
;
603 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
604 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
606 obj
->user
->lm_pw
= data_blob_talloc(obj
->mem_ctx
, lm_pwd
.data
, lm_pwd
.length
);
608 memcpy(r
, lm_pwd
.data
, 16);
609 pdb_sethexpwd(p
, r
, 0);
610 DEBUG(100, ("Setting LM Password=[%s]\n", p
));
615 NTSTATUS
gums_set_user_fullname(GUMS_OBJECT
*obj
, const char *fullname
)
617 if (!obj
|| !fullname
)
618 return NT_STATUS_INVALID_PARAMETER
;
620 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
621 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
623 obj
->user
->full_name
= (char *)talloc_strdup(obj
->mem_ctx
, fullname
);
624 if (!(obj
->user
->full_name
)) return NT_STATUS_NO_MEMORY
;
628 NTSTATUS
gums_set_user_homedir(GUMS_OBJECT
*obj
, const char *homedir
)
630 if (!obj
|| !homedir
)
631 return NT_STATUS_INVALID_PARAMETER
;
633 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
634 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
636 obj
->user
->home_dir
= (char *)talloc_strdup(obj
->mem_ctx
, homedir
);
637 if (!(obj
->user
->home_dir
)) return NT_STATUS_NO_MEMORY
;
641 NTSTATUS
gums_set_user_dir_drive(GUMS_OBJECT
*obj
, const char *dir_drive
)
643 if (!obj
|| !dir_drive
)
644 return NT_STATUS_INVALID_PARAMETER
;
646 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
647 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
649 obj
->user
->dir_drive
= (char *)talloc_strdup(obj
->mem_ctx
, dir_drive
);
650 if (!(obj
->user
->dir_drive
)) return NT_STATUS_NO_MEMORY
;
654 NTSTATUS
gums_set_user_logon_script(GUMS_OBJECT
*obj
, const char *logon_script
)
656 if (!obj
|| !logon_script
)
657 return NT_STATUS_INVALID_PARAMETER
;
659 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
660 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
662 obj
->user
->logon_script
= (char *)talloc_strdup(obj
->mem_ctx
, logon_script
);
663 if (!(obj
->user
->logon_script
)) return NT_STATUS_NO_MEMORY
;
667 NTSTATUS
gums_set_user_profile_path(GUMS_OBJECT
*obj
, const char *profile_path
)
669 if (!obj
|| !profile_path
)
670 return NT_STATUS_INVALID_PARAMETER
;
672 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
673 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
675 obj
->user
->profile_path
= (char *)talloc_strdup(obj
->mem_ctx
, profile_path
);
676 if (!(obj
->user
->profile_path
)) return NT_STATUS_NO_MEMORY
;
680 NTSTATUS
gums_set_user_workstations(GUMS_OBJECT
*obj
, const char *workstations
)
682 if (!obj
|| !workstations
)
683 return NT_STATUS_INVALID_PARAMETER
;
685 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
686 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
688 obj
->user
->workstations
= (char *)talloc_strdup(obj
->mem_ctx
, workstations
);
689 if (!(obj
->user
->workstations
)) return NT_STATUS_NO_MEMORY
;
693 NTSTATUS
gums_set_user_unknown_str(GUMS_OBJECT
*obj
, const char *unknown_str
)
695 if (!obj
|| !unknown_str
)
696 return NT_STATUS_INVALID_PARAMETER
;
698 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
699 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
701 obj
->user
->unknown_str
= (char *)talloc_strdup(obj
->mem_ctx
, unknown_str
);
702 if (!(obj
->user
->unknown_str
)) return NT_STATUS_NO_MEMORY
;
706 NTSTATUS
gums_set_user_munged_dial(GUMS_OBJECT
*obj
, const char *munged_dial
)
708 if (!obj
|| !munged_dial
)
709 return NT_STATUS_INVALID_PARAMETER
;
711 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
712 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
714 obj
->user
->munged_dial
= (char *)talloc_strdup(obj
->mem_ctx
, munged_dial
);
715 if (!(obj
->user
->munged_dial
)) return NT_STATUS_NO_MEMORY
;
719 NTSTATUS
gums_set_user_logon_time(GUMS_OBJECT
*obj
, NTTIME logon_time
)
722 return NT_STATUS_INVALID_PARAMETER
;
724 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
725 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
727 obj
->user
->logon_time
= logon_time
;
731 NTSTATUS
gums_set_user_logoff_time(GUMS_OBJECT
*obj
, NTTIME logoff_time
)
734 return NT_STATUS_INVALID_PARAMETER
;
736 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
737 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
739 obj
->user
->logoff_time
= logoff_time
;
743 NTSTATUS
gums_set_user_kickoff_time(GUMS_OBJECT
*obj
, NTTIME kickoff_time
)
746 return NT_STATUS_INVALID_PARAMETER
;
748 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
749 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
751 obj
->user
->kickoff_time
= kickoff_time
;
755 NTSTATUS
gums_set_user_pass_last_set_time(GUMS_OBJECT
*obj
, NTTIME pass_last_set_time
)
758 return NT_STATUS_INVALID_PARAMETER
;
760 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
761 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
763 obj
->user
->pass_last_set_time
= pass_last_set_time
;
767 NTSTATUS
gums_set_user_pass_can_change_time(GUMS_OBJECT
*obj
, NTTIME pass_can_change_time
)
770 return NT_STATUS_INVALID_PARAMETER
;
772 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
773 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
775 obj
->user
->pass_can_change_time
= pass_can_change_time
;
779 NTSTATUS
gums_set_user_pass_must_change_time(GUMS_OBJECT
*obj
, NTTIME pass_must_change_time
)
782 return NT_STATUS_INVALID_PARAMETER
;
784 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
785 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
787 obj
->user
->pass_must_change_time
= pass_must_change_time
;
791 NTSTATUS
gums_set_user_acct_ctrl(GUMS_OBJECT
*obj
, uint16 acct_ctrl
)
794 return NT_STATUS_INVALID_PARAMETER
;
796 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
797 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
799 obj
->user
->acct_ctrl
= acct_ctrl
;
803 NTSTATUS
gums_set_user_logon_divs(GUMS_OBJECT
*obj
, uint16 logon_divs
)
806 return NT_STATUS_INVALID_PARAMETER
;
808 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
809 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
811 obj
->user
->logon_divs
= logon_divs
;
815 NTSTATUS
gums_set_user_hours(GUMS_OBJECT
*obj
, uint32 hours_len
, const uint8
*hours
)
818 return NT_STATUS_INVALID_PARAMETER
;
820 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
821 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
823 obj
->user
->hours_len
= hours_len
;
825 DEBUG(10, ("gums_set_user_hours: Warning, hours_len is zero!\n"));
827 obj
->user
->hours
= (uint8
*)talloc(obj
->mem_ctx
, MAX_HOURS_LEN
);
828 if (!(obj
->user
->hours
))
829 return NT_STATUS_NO_MEMORY
;
831 memcpy(obj
->user
->hours
, hours
, hours_len
);
836 NTSTATUS
gums_set_user_unknown_3(GUMS_OBJECT
*obj
, uint32 unknown_3
)
839 return NT_STATUS_INVALID_PARAMETER
;
841 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
842 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
844 obj
->user
->unknown_3
= unknown_3
;
848 NTSTATUS
gums_set_user_bad_password_count(GUMS_OBJECT
*obj
, uint16 bad_password_count
)
851 return NT_STATUS_INVALID_PARAMETER
;
853 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
854 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
856 obj
->user
->bad_password_count
= bad_password_count
;
860 NTSTATUS
gums_set_user_logon_count(GUMS_OBJECT
*obj
, uint16 logon_count
)
863 return NT_STATUS_INVALID_PARAMETER
;
865 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
866 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
868 obj
->user
->logon_count
= logon_count
;
872 NTSTATUS
gums_set_user_unknown_6(GUMS_OBJECT
*obj
, uint32 unknown_6
)
875 return NT_STATUS_INVALID_PARAMETER
;
877 if (obj
->type
!= GUMS_OBJ_NORMAL_USER
)
878 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
880 obj
->user
->unknown_6
= unknown_6
;
884 /* Group specific functions */
886 const DOM_SID
*gums_get_group_members(int *count
, const GUMS_OBJECT
*obj
)
888 if (!count
|| !obj
|| !(obj
->type
== GUMS_OBJ_GROUP
|| obj
->type
== GUMS_OBJ_ALIAS
)) {
893 *count
= obj
->group
->count
;
894 return obj
->group
->members
;
897 NTSTATUS
gums_set_group_members(GUMS_OBJECT
*obj
, uint32 count
, DOM_SID
*members
)
901 if (!obj
|| ((count
> 0) && !members
))
902 return NT_STATUS_INVALID_PARAMETER
;
904 if (obj
->type
!= GUMS_OBJ_GROUP
&&
905 obj
->type
!= GUMS_OBJ_ALIAS
)
906 return NT_STATUS_OBJECT_TYPE_MISMATCH
;
908 obj
->group
->count
= count
;
911 obj
->group
->members
= (DOM_SID
*)talloc(obj
->mem_ctx
, count
* sizeof(DOM_SID
));
912 if (!(obj
->group
->members
)) {
913 return NT_STATUS_NO_MEMORY
;
919 sid_copy(&(obj
->group
->members
[n
]), &(members
[n
]));
923 obj
->group
->members
= 0;
929 /* Privilege specific functions */
931 const LUID_ATTR
*gums_get_priv_luid_attr(const GUMS_PRIVILEGE
*priv
)
937 return priv
->privilege
;
940 const DOM_SID
*gums_get_priv_members(int *count
, const GUMS_PRIVILEGE
*priv
)
942 if (!count
|| !priv
) {
947 *count
= priv
->count
;
948 return priv
->members
;
951 NTSTATUS
gums_set_priv_luid_attr(GUMS_PRIVILEGE
*priv
, LUID_ATTR
*luid_attr
)
953 if (!luid_attr
|| !priv
)
954 return NT_STATUS_INVALID_PARAMETER
;
956 priv
->privilege
= (LUID_ATTR
*)talloc_memdup(priv
->mem_ctx
, luid_attr
, sizeof(LUID_ATTR
));
957 if (!(priv
->privilege
)) return NT_STATUS_NO_MEMORY
;
961 NTSTATUS
gums_set_priv_members(GUMS_PRIVILEGE
*priv
, uint32 count
, DOM_SID
*members
)
965 if (!priv
|| !members
|| !members
)
966 return NT_STATUS_INVALID_PARAMETER
;
969 priv
->members
= (DOM_SID
*)talloc(priv
->mem_ctx
, count
* sizeof(DOM_SID
));
970 if (!(priv
->members
))
971 return NT_STATUS_NO_MEMORY
;
975 sid_copy(&(priv
->members
[n
]), &(members
[n
]));
982 /* data_store set functions */
984 NTSTATUS
gums_create_commit_set(GUMS_COMMIT_SET
**com_set
, DOM_SID
*sid
, uint32 type
)
988 mem_ctx
= talloc_init("commit_set");
990 return NT_STATUS_NO_MEMORY
;
992 *com_set
= (GUMS_COMMIT_SET
*)talloc_zero(mem_ctx
, sizeof(GUMS_COMMIT_SET
));
993 if (*com_set
== NULL
) {
994 talloc_destroy(mem_ctx
);
995 return NT_STATUS_NO_MEMORY
;
998 (*com_set
)->mem_ctx
= mem_ctx
;
999 (*com_set
)->type
= type
;
1000 sid_copy(&((*com_set
)->sid
), sid
);
1002 return NT_STATUS_OK
;
1005 NTSTATUS
gums_cs_grow_data_set(GUMS_COMMIT_SET
*com_set
, int size
)
1007 GUMS_DATA_SET
*data_set
;
1009 com_set
->count
= com_set
->count
+ size
;
1010 if (com_set
->count
== size
) { /* data set is empty*/
1011 data_set
= (GUMS_DATA_SET
*)talloc_zero(com_set
->mem_ctx
, sizeof(GUMS_DATA_SET
));
1013 data_set
= (GUMS_DATA_SET
*)talloc_realloc(com_set
->mem_ctx
, com_set
->data
, sizeof(GUMS_DATA_SET
) * com_set
->count
);
1015 if (data_set
== NULL
)
1016 return NT_STATUS_NO_MEMORY
;
1018 com_set
->data
= data_set
;
1020 return NT_STATUS_OK
;
1023 NTSTATUS
gums_cs_set_sec_desc(GUMS_COMMIT_SET
*com_set
, SEC_DESC
*sec_desc
)
1026 GUMS_DATA_SET
*data_set
;
1027 SEC_DESC
*new_sec_desc
;
1029 if (!com_set
|| !sec_desc
)
1030 return NT_STATUS_INVALID_PARAMETER
;
1032 if (!NT_STATUS_IS_OK(ret
= gums_cs_grow_data_set(com_set
, 1)))
1035 data_set
= &((com_set
->data
)[com_set
->count
- 1]);
1037 data_set
->type
= GUMS_SET_SEC_DESC
;
1038 new_sec_desc
= dup_sec_desc(com_set
->mem_ctx
, sec_desc
);
1039 if (new_sec_desc
== NULL
)
1040 return NT_STATUS_NO_MEMORY
;
1042 (SEC_DESC
*)(data_set
->data
) = new_sec_desc
;
1044 return NT_STATUS_OK
;
1048 NTSTATUS gums_cs_add_privilege(GUMS_PRIV_COMMIT_SET *com_set, LUID_ATTR priv)
1051 GUMS_DATA_SET *data_set;
1052 LUID_ATTR *new_priv;
1055 return NT_STATUS_INVALID_PARAMETER;
1057 if (!NT_STATUS_OK(ret = gums_pcs_grow_data_set(com_set, 1)))
1060 data_set = ((com_set->data)[com_set->count - 1]);
1062 data_set->type = GUMS_ADD_PRIVILEGE;
1063 if (!NT_STATUS_IS_OK(ret = dupalloc_luid_attr(com_set->mem_ctx, &new_priv, priv)))
1066 (SEC_DESC *)(data_set->data) = new_priv;
1068 return NT_STATUS_OK;
1071 NTSTATUS gums_cs_del_privilege(GUMS_PRIV_COMMIT_SET *com_set, LUID_ATTR priv)
1074 GUMS_DATA_SET *data_set;
1075 LUID_ATTR *new_priv;
1078 return NT_STATUS_INVALID_PARAMETER;
1080 if (!NT_STATUS_OK(ret = gums_pcs_grow_data_set(com_set, 1)))
1083 data_set = ((com_set->data)[com_set->count - 1]);
1085 data_set->type = GUMS_DEL_PRIVILEGE;
1086 if (!NT_STATUS_IS_OK(ret = dupalloc_luid_attr(com_set->mem_ctx, &new_priv, priv)))
1089 (SEC_DESC *)(data_set->data) = new_priv;
1091 return NT_STATUS_OK;
1094 NTSTATUS gums_cs_set_privilege_set(GUMS_PRIV_COMMIT_SET *com_set, PRIVILEGE_SET *priv_set)
1097 GUMS_DATA_SET *data_set;
1098 PRIVILEGE_SET *new_priv_set;
1100 if (!com_set || !priv_set)
1101 return NT_STATUS_INVALID_PARAMETER;
1103 if (!NT_STATUS_OK(ret = gums_pcs_grow_data_set(com_set, 1)))
1106 data_set = ((com_set->data)[com_set->count - 1]);
1108 data_set->type = GUMS_SET_PRIVILEGE;
1109 if (!NT_STATUS_IS_OK(ret = init_priv_set_with_ctx(com_set->mem_ctx, &new_priv_set)))
1112 if (!NT_STATUS_IS_OK(ret = dup_priv_set(new_priv_set, priv_set)))
1115 (SEC_DESC *)(data_set->data) = new_priv_set;
1117 return NT_STATUS_OK;
1121 NTSTATUS
gums_cs_set_string(GUMS_COMMIT_SET
*com_set
, uint32 type
, char *str
)
1124 GUMS_DATA_SET
*data_set
;
1127 if (!com_set
|| !str
|| type
< GUMS_SET_NAME
|| type
> GUMS_SET_MUNGED_DIAL
)
1128 return NT_STATUS_INVALID_PARAMETER
;
1130 if (!NT_STATUS_IS_OK(ret
= gums_cs_grow_data_set(com_set
, 1)))
1133 data_set
= &((com_set
->data
)[com_set
->count
- 1]);
1135 data_set
->type
= type
;
1136 new_str
= talloc_strdup(com_set
->mem_ctx
, str
);
1137 if (new_str
== NULL
)
1138 return NT_STATUS_NO_MEMORY
;
1140 (char *)(data_set
->data
) = new_str
;
1142 return NT_STATUS_OK
;
1145 NTSTATUS
gums_cs_set_name(GUMS_COMMIT_SET
*com_set
, char *name
)
1147 return gums_cs_set_string(com_set
, GUMS_SET_NAME
, name
);
1150 NTSTATUS
gums_cs_set_description(GUMS_COMMIT_SET
*com_set
, char *desc
)
1152 return gums_cs_set_string(com_set
, GUMS_SET_DESCRIPTION
, desc
);
1155 NTSTATUS
gums_cs_set_full_name(GUMS_COMMIT_SET
*com_set
, char *full_name
)
1157 if (com_set
->type
!= GUMS_OBJ_NORMAL_USER
)
1158 return NT_STATUS_INVALID_PARAMETER
;
1160 return gums_cs_set_string(com_set
, GUMS_SET_NAME
, full_name
);
1163 NTSTATUS
gums_cs_set_home_directory(GUMS_COMMIT_SET
*com_set
, char *home_dir
)
1165 if (com_set
->type
!= GUMS_OBJ_NORMAL_USER
)
1166 return NT_STATUS_INVALID_PARAMETER
;
1168 return gums_cs_set_string(com_set
, GUMS_SET_NAME
, home_dir
);
1171 NTSTATUS
gums_cs_set_drive(GUMS_COMMIT_SET
*com_set
, char *drive
)
1173 if (com_set
->type
!= GUMS_OBJ_NORMAL_USER
)
1174 return NT_STATUS_INVALID_PARAMETER
;
1176 return gums_cs_set_string(com_set
, GUMS_SET_NAME
, drive
);
1179 NTSTATUS
gums_cs_set_logon_script(GUMS_COMMIT_SET
*com_set
, char *logon_script
)
1181 if (com_set
->type
!= GUMS_OBJ_NORMAL_USER
)
1182 return NT_STATUS_INVALID_PARAMETER
;
1184 return gums_cs_set_string(com_set
, GUMS_SET_NAME
, logon_script
);
1187 NTSTATUS
gums_cs_set_profile_path(GUMS_COMMIT_SET
*com_set
, char *prof_path
)
1189 if (com_set
->type
!= GUMS_OBJ_NORMAL_USER
)
1190 return NT_STATUS_INVALID_PARAMETER
;
1192 return gums_cs_set_string(com_set
, GUMS_SET_NAME
, prof_path
);
1195 NTSTATUS
gums_cs_set_workstations(GUMS_COMMIT_SET
*com_set
, char *wks
)
1197 if (com_set
->type
!= GUMS_OBJ_NORMAL_USER
)
1198 return NT_STATUS_INVALID_PARAMETER
;
1200 return gums_cs_set_string(com_set
, GUMS_SET_NAME
, wks
);
1203 NTSTATUS
gums_cs_set_unknown_string(GUMS_COMMIT_SET
*com_set
, char *unkn_str
)
1205 if (com_set
->type
!= GUMS_OBJ_NORMAL_USER
)
1206 return NT_STATUS_INVALID_PARAMETER
;
1208 return gums_cs_set_string(com_set
, GUMS_SET_NAME
, unkn_str
);
1211 NTSTATUS
gums_cs_set_munged_dial(GUMS_COMMIT_SET
*com_set
, char *munged_dial
)
1213 if (com_set
->type
!= GUMS_OBJ_NORMAL_USER
)
1214 return NT_STATUS_INVALID_PARAMETER
;
1216 return gums_cs_set_string(com_set
, GUMS_SET_NAME
, munged_dial
);
1219 NTSTATUS
gums_cs_set_nttime(GUMS_COMMIT_SET
*com_set
, uint32 type
, NTTIME
*nttime
)
1222 GUMS_DATA_SET
*data_set
;
1225 if (!com_set
|| !nttime
|| type
< GUMS_SET_LOGON_TIME
|| type
> GUMS_SET_PASS_MUST_CHANGE_TIME
)
1226 return NT_STATUS_INVALID_PARAMETER
;
1228 if (!NT_STATUS_IS_OK(ret
= gums_cs_grow_data_set(com_set
, 1)))
1231 data_set
= &((com_set
->data
)[com_set
->count
- 1]);
1233 data_set
->type
= type
;
1234 new_time
= talloc(com_set
->mem_ctx
, sizeof(NTTIME
));
1235 if (new_time
== NULL
)
1236 return NT_STATUS_NO_MEMORY
;
1238 new_time
->low
= nttime
->low
;
1239 new_time
->high
= nttime
->high
;
1240 (char *)(data_set
->data
) = new_time
;
1242 return NT_STATUS_OK
;
1245 NTSTATUS
gums_cs_set_logon_time(GUMS_COMMIT_SET
*com_set
, NTTIME
*logon_time
)
1247 if (com_set
->type
!= GUMS_OBJ_NORMAL_USER
)
1248 return NT_STATUS_INVALID_PARAMETER
;
1250 return gums_cs_set_nttime(com_set
, GUMS_SET_LOGON_TIME
, logon_time
);
1253 NTSTATUS
gums_cs_set_logoff_time(GUMS_COMMIT_SET
*com_set
, NTTIME
*logoff_time
)
1255 if (com_set
->type
!= GUMS_OBJ_NORMAL_USER
)
1256 return NT_STATUS_INVALID_PARAMETER
;
1258 return gums_cs_set_nttime(com_set
, GUMS_SET_LOGOFF_TIME
, logoff_time
);
1261 NTSTATUS
gums_cs_set_kickoff_time(GUMS_COMMIT_SET
*com_set
, NTTIME
*kickoff_time
)
1263 if (com_set
->type
!= GUMS_OBJ_NORMAL_USER
)
1264 return NT_STATUS_INVALID_PARAMETER
;
1266 return gums_cs_set_nttime(com_set
, GUMS_SET_KICKOFF_TIME
, kickoff_time
);
1269 NTSTATUS
gums_cs_set_pass_last_set_time(GUMS_COMMIT_SET
*com_set
, NTTIME
*pls_time
)
1271 if (com_set
->type
!= GUMS_OBJ_NORMAL_USER
)
1272 return NT_STATUS_INVALID_PARAMETER
;
1274 return gums_cs_set_nttime(com_set
, GUMS_SET_LOGON_TIME
, pls_time
);
1277 NTSTATUS
gums_cs_set_pass_can_change_time(GUMS_COMMIT_SET
*com_set
, NTTIME
*pcc_time
)
1279 if (com_set
->type
!= GUMS_OBJ_NORMAL_USER
)
1280 return NT_STATUS_INVALID_PARAMETER
;
1282 return gums_cs_set_nttime(com_set
, GUMS_SET_LOGON_TIME
, pcc_time
);
1285 NTSTATUS
gums_cs_set_pass_must_change_time(GUMS_COMMIT_SET
*com_set
, NTTIME
*pmc_time
)
1287 if (com_set
->type
!= GUMS_OBJ_NORMAL_USER
)
1288 return NT_STATUS_INVALID_PARAMETER
;
1290 return gums_cs_set_nttime(com_set
, GUMS_SET_LOGON_TIME
, pmc_time
);
1293 NTSTATUS
gums_cs_add_sids_to_group(GUMS_COMMIT_SET
*com_set
, const DOM_SID
**sids
, const uint32 count
)
1296 GUMS_DATA_SET
*data_set
;
1300 if (!com_set
|| !sids
)
1301 return NT_STATUS_INVALID_PARAMETER
;
1303 if (!NT_STATUS_IS_OK(ret
= gums_cs_grow_data_set(com_set
, 1)))
1306 data_set
= &((com_set
->data
)[com_set
->count
- 1]);
1308 data_set
->type
= GUMS_ADD_SID_LIST
;
1309 new_sids
= (DOM_SID
**)talloc(com_set
->mem_ctx
, (sizeof(void *) * count
));
1310 if (new_sids
== NULL
)
1311 return NT_STATUS_NO_MEMORY
;
1312 for (i
= 0; i
< count
; i
++) {
1313 new_sids
[i
] = sid_dup_talloc(com_set
->mem_ctx
, sids
[i
]);
1314 if (new_sids
[i
] == NULL
)
1315 return NT_STATUS_NO_MEMORY
;
1318 (SEC_DESC
*)(data_set
->data
) = new_sids
;
1320 return NT_STATUS_OK
;
1323 NTSTATUS
gums_cs_add_users_to_group(GUMS_COMMIT_SET
*com_set
, const DOM_SID
**sids
, const uint32 count
)
1325 if (!com_set
|| !sids
)
1326 return NT_STATUS_INVALID_PARAMETER
;
1327 if (com_set
->type
!= GUMS_OBJ_GROUP
|| com_set
->type
!= GUMS_OBJ_ALIAS
)
1328 return NT_STATUS_INVALID_PARAMETER
;
1330 return gums_cs_add_sids_to_group(com_set
, sids
, count
);
1333 NTSTATUS
gums_cs_add_groups_to_group(GUMS_COMMIT_SET
*com_set
, const DOM_SID
**sids
, const uint32 count
)
1335 if (!com_set
|| !sids
)
1336 return NT_STATUS_INVALID_PARAMETER
;
1337 if (com_set
->type
!= GUMS_OBJ_ALIAS
)
1338 return NT_STATUS_INVALID_PARAMETER
;
1340 return gums_cs_add_sids_to_group(com_set
, sids
, count
);
1343 NTSTATUS
gums_cs_del_sids_from_group(GUMS_COMMIT_SET
*com_set
, const DOM_SID
**sids
, const uint32 count
)
1346 GUMS_DATA_SET
*data_set
;
1350 if (!com_set
|| !sids
)
1351 return NT_STATUS_INVALID_PARAMETER
;
1352 if (com_set
->type
!= GUMS_OBJ_GROUP
|| com_set
->type
!= GUMS_OBJ_ALIAS
)
1353 return NT_STATUS_INVALID_PARAMETER
;
1355 if (!NT_STATUS_IS_OK(ret
= gums_cs_grow_data_set(com_set
, 1)))
1358 data_set
= &((com_set
->data
)[com_set
->count
- 1]);
1360 data_set
->type
= GUMS_DEL_SID_LIST
;
1361 new_sids
= (DOM_SID
**)talloc(com_set
->mem_ctx
, (sizeof(void *) * count
));
1362 if (new_sids
== NULL
)
1363 return NT_STATUS_NO_MEMORY
;
1364 for (i
= 0; i
< count
; i
++) {
1365 new_sids
[i
] = sid_dup_talloc(com_set
->mem_ctx
, sids
[i
]);
1366 if (new_sids
[i
] == NULL
)
1367 return NT_STATUS_NO_MEMORY
;
1370 (SEC_DESC
*)(data_set
->data
) = new_sids
;
1372 return NT_STATUS_OK
;
1375 NTSTATUS
gums_ds_set_sids_in_group(GUMS_COMMIT_SET
*com_set
, const DOM_SID
**sids
, const uint32 count
)
1378 GUMS_DATA_SET
*data_set
;
1382 if (!com_set
|| !sids
)
1383 return NT_STATUS_INVALID_PARAMETER
;
1384 if (com_set
->type
!= GUMS_OBJ_GROUP
|| com_set
->type
!= GUMS_OBJ_ALIAS
)
1385 return NT_STATUS_INVALID_PARAMETER
;
1387 if (!NT_STATUS_IS_OK(ret
= gums_cs_grow_data_set(com_set
, 1)))
1390 data_set
= &((com_set
->data
)[com_set
->count
- 1]);
1392 data_set
->type
= GUMS_SET_SID_LIST
;
1393 new_sids
= (DOM_SID
**)talloc(com_set
->mem_ctx
, (sizeof(void *) * count
));
1394 if (new_sids
== NULL
)
1395 return NT_STATUS_NO_MEMORY
;
1396 for (i
= 0; i
< count
; i
++) {
1397 new_sids
[i
] = sid_dup_talloc(com_set
->mem_ctx
, sids
[i
]);
1398 if (new_sids
[i
] == NULL
)
1399 return NT_STATUS_NO_MEMORY
;
1402 (SEC_DESC
*)(data_set
->data
) = new_sids
;
1404 return NT_STATUS_OK
;
1407 NTSTATUS
gums_commit_data(GUMS_COMMIT_SET
*set
)
1410 GUMS_FUNCTIONS
*fns
;
1412 if (!NT_STATUS_IS_OK(ret
= get_gums_fns(&fns
))) {
1413 DEBUG(0, ("gums_commit_data: unable to get gums functions! backend uninitialized?\n"));
1416 return fns
->set_object_values(&(set
->sid
), set
->count
, set
->data
);
1419 NTSTATUS
gums_destroy_commit_set(GUMS_COMMIT_SET
**com_set
)
1421 talloc_destroy((*com_set
)->mem_ctx
);
1424 return NT_STATUS_OK
;