2 Unix SMB/CIFS implementation.
3 Authentication utility functions
4 Copyright (C) Volker Lendecke 2010
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/>.
21 #include "libcli/security/security.h"
22 #include "librpc/gen_ndr/netlogon.h"
23 #include "nsswitch/libwbclient/wbclient.h"
24 #include "librpc/gen_ndr/auth.h"
25 #include "auth/auth_sam_reply.h"
28 #define DBGC_CLASS DBGC_AUTH
30 static NTSTATUS
wbcsids_to_samr_RidWithAttributeArray(
32 struct samr_RidWithAttributeArray
*groups
,
33 const struct dom_sid
*domain_sid
,
34 const struct wbcSidWithAttr
*sids
,
37 unsigned int i
, j
= 0;
40 groups
->rids
= talloc_array(mem_ctx
,
41 struct samr_RidWithAttribute
, num_sids
);
43 return NT_STATUS_NO_MEMORY
;
46 /* a wbcDomainSid is the same as a dom_sid */
47 for (i
= 0; i
< num_sids
; i
++) {
48 ok
= sid_peek_check_rid(domain_sid
,
49 (const struct dom_sid
*)&sids
[i
].sid
,
50 &groups
->rids
[j
].rid
);
53 groups
->rids
[j
].attributes
= SE_GROUP_MANDATORY
|
54 SE_GROUP_ENABLED_BY_DEFAULT
|
63 static NTSTATUS
wbcsids_to_netr_SidAttrArray(
64 const struct dom_sid
*domain_sid
,
65 const struct wbcSidWithAttr
*sids
,
68 struct netr_SidAttr
**_info3_sids
,
69 uint32_t *info3_num_sids
)
71 unsigned int i
, j
= 0;
72 struct netr_SidAttr
*info3_sids
;
74 info3_sids
= talloc_array(mem_ctx
, struct netr_SidAttr
, num_sids
);
75 if (info3_sids
== NULL
) {
76 return NT_STATUS_NO_MEMORY
;
79 /* a wbcDomainSid is the same as a dom_sid */
80 for (i
= 0; i
< num_sids
; i
++) {
81 const struct dom_sid
*sid
;
83 sid
= (const struct dom_sid
*)&sids
[i
].sid
;
85 if (dom_sid_in_domain(domain_sid
, sid
)) {
89 info3_sids
[j
].sid
= dom_sid_dup(info3_sids
, sid
);
90 if (info3_sids
[j
].sid
== NULL
) {
91 talloc_free(info3_sids
);
92 return NT_STATUS_NO_MEMORY
;
94 info3_sids
[j
].attributes
= SE_GROUP_MANDATORY
|
95 SE_GROUP_ENABLED_BY_DEFAULT
|
101 *_info3_sids
= info3_sids
;
107 #define RET_NOMEM(ptr) do { \
109 TALLOC_FREE(info3); \
113 struct netr_SamInfo3
*wbcAuthUserInfo_to_netr_SamInfo3(TALLOC_CTX
*mem_ctx
,
114 const struct wbcAuthUserInfo
*info
)
116 struct netr_SamInfo3
*info3
;
117 struct dom_sid user_sid
;
118 struct dom_sid group_sid
;
119 struct dom_sid domain_sid
;
123 memcpy(&user_sid
, &info
->sids
[0].sid
, sizeof(user_sid
));
124 memcpy(&group_sid
, &info
->sids
[1].sid
, sizeof(group_sid
));
126 info3
= talloc_zero(mem_ctx
, struct netr_SamInfo3
);
127 if (!info3
) return NULL
;
129 unix_to_nt_time(&info3
->base
.logon_time
, info
->logon_time
);
130 unix_to_nt_time(&info3
->base
.logoff_time
, info
->logoff_time
);
131 unix_to_nt_time(&info3
->base
.kickoff_time
, info
->kickoff_time
);
132 unix_to_nt_time(&info3
->base
.last_password_change
, info
->pass_last_set_time
);
133 unix_to_nt_time(&info3
->base
.allow_password_change
,
134 info
->pass_can_change_time
);
135 unix_to_nt_time(&info3
->base
.force_password_change
,
136 info
->pass_must_change_time
);
138 if (info
->account_name
) {
139 info3
->base
.account_name
.string
=
140 talloc_strdup(info3
, info
->account_name
);
141 RET_NOMEM(info3
->base
.account_name
.string
);
143 if (info
->full_name
) {
144 info3
->base
.full_name
.string
=
145 talloc_strdup(info3
, info
->full_name
);
146 RET_NOMEM(info3
->base
.full_name
.string
);
148 if (info
->logon_script
) {
149 info3
->base
.logon_script
.string
=
150 talloc_strdup(info3
, info
->logon_script
);
151 RET_NOMEM(info3
->base
.logon_script
.string
);
153 if (info
->profile_path
) {
154 info3
->base
.profile_path
.string
=
155 talloc_strdup(info3
, info
->profile_path
);
156 RET_NOMEM(info3
->base
.profile_path
.string
);
158 if (info
->home_directory
) {
159 info3
->base
.home_directory
.string
=
160 talloc_strdup(info3
, info
->home_directory
);
161 RET_NOMEM(info3
->base
.home_directory
.string
);
163 if (info
->home_drive
) {
164 info3
->base
.home_drive
.string
=
165 talloc_strdup(info3
, info
->home_drive
);
166 RET_NOMEM(info3
->base
.home_drive
.string
);
169 info3
->base
.logon_count
= info
->logon_count
;
170 info3
->base
.bad_password_count
= info
->bad_password_count
;
172 sid_copy(&domain_sid
, &user_sid
);
173 sid_split_rid(&domain_sid
, &info3
->base
.rid
);
175 ok
= sid_peek_check_rid(&domain_sid
, &group_sid
,
176 &info3
->base
.primary_gid
);
178 DEBUG(1, ("The primary group sid domain does not"
179 "match user sid domain for user: %s\n",
180 info
->account_name
));
185 status
= wbcsids_to_samr_RidWithAttributeArray(info3
,
190 if (!NT_STATUS_IS_OK(status
)) {
195 status
= wbcsids_to_netr_SidAttrArray(&domain_sid
,
201 if (!NT_STATUS_IS_OK(status
)) {
206 info3
->base
.user_flags
= info
->user_flags
;
207 memcpy(info3
->base
.key
.key
, info
->user_session_key
, 16);
209 if (info
->logon_server
) {
210 info3
->base
.logon_server
.string
=
211 talloc_strdup(info3
, info
->logon_server
);
212 RET_NOMEM(info3
->base
.logon_server
.string
);
214 if (info
->domain_name
) {
215 info3
->base
.logon_domain
.string
=
216 talloc_strdup(info3
, info
->domain_name
);
217 RET_NOMEM(info3
->base
.logon_domain
.string
);
220 info3
->base
.domain_sid
= dom_sid_dup(info3
, &domain_sid
);
221 RET_NOMEM(info3
->base
.domain_sid
);
223 memcpy(info3
->base
.LMSessKey
.key
, info
->lm_session_key
, 8);
224 info3
->base
.acct_flags
= info
->acct_flags
;