2 Unix SMB/CIFS implementation.
6 Copyright (C) Gerald (Jerry) Carter 2007
7 Copyright (C) Guenther Deschner 2008
8 Copyright (C) Volker Lendecke 2009
10 This library is free software; you can redistribute it and/or
11 modify it under the terms of the GNU Lesser General Public
12 License as published by the Free Software Foundation; either
13 version 3 of the License, or (at your option) any later version.
15 This library is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 Library General Public License for more details.
20 You should have received a copy of the GNU Lesser General Public License
21 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 /* Required Headers */
27 #include "libwbclient.h"
28 #include "../winbind_client.h"
30 /* Authenticate a username/password pair */
31 wbcErr wbcAuthenticateUser(const char *username,
34 wbcErr wbc_status = WBC_ERR_SUCCESS;
35 struct wbcAuthUserParams params;
39 params.account_name = username;
40 params.level = WBC_AUTH_USER_LEVEL_PLAIN;
41 params.password.plaintext = password;
43 wbc_status = wbcAuthenticateUserEx(¶ms, NULL, NULL);
44 BAIL_ON_WBC_ERROR(wbc_status);
50 static wbcErr wbc_create_auth_info(TALLOC_CTX *mem_ctx,
51 const struct winbindd_response *resp,
52 struct wbcAuthUserInfo **_i)
54 wbcErr wbc_status = WBC_ERR_SUCCESS;
55 struct wbcAuthUserInfo *i;
56 struct wbcDomainSid domain_sid;
61 i = talloc(mem_ctx, struct wbcAuthUserInfo);
62 BAIL_ON_PTR_ERROR(i, wbc_status);
64 i->user_flags = resp->data.auth.info3.user_flgs;
66 i->account_name = talloc_strdup(i, resp->data.auth.info3.user_name);
67 BAIL_ON_PTR_ERROR(i->account_name, wbc_status);
68 i->user_principal= NULL;
69 i->full_name = talloc_strdup(i, resp->data.auth.info3.full_name);
70 BAIL_ON_PTR_ERROR(i->full_name, wbc_status);
71 i->domain_name = talloc_strdup(i, resp->data.auth.info3.logon_dom);
72 BAIL_ON_PTR_ERROR(i->domain_name, wbc_status);
73 i->dns_domain_name= NULL;
75 i->acct_flags = resp->data.auth.info3.acct_flags;
76 memcpy(i->user_session_key,
77 resp->data.auth.user_session_key,
78 sizeof(i->user_session_key));
79 memcpy(i->lm_session_key,
80 resp->data.auth.first_8_lm_hash,
81 sizeof(i->lm_session_key));
83 i->logon_count = resp->data.auth.info3.logon_count;
84 i->bad_password_count = resp->data.auth.info3.bad_pw_count;
86 i->logon_time = resp->data.auth.info3.logon_time;
87 i->logoff_time = resp->data.auth.info3.logoff_time;
88 i->kickoff_time = resp->data.auth.info3.kickoff_time;
89 i->pass_last_set_time = resp->data.auth.info3.pass_last_set_time;
90 i->pass_can_change_time = resp->data.auth.info3.pass_can_change_time;
91 i->pass_must_change_time= resp->data.auth.info3.pass_must_change_time;
93 i->logon_server = talloc_strdup(i, resp->data.auth.info3.logon_srv);
94 BAIL_ON_PTR_ERROR(i->logon_server, wbc_status);
95 i->logon_script = talloc_strdup(i, resp->data.auth.info3.logon_script);
96 BAIL_ON_PTR_ERROR(i->logon_script, wbc_status);
97 i->profile_path = talloc_strdup(i, resp->data.auth.info3.profile_path);
98 BAIL_ON_PTR_ERROR(i->profile_path, wbc_status);
99 i->home_directory= talloc_strdup(i, resp->data.auth.info3.home_dir);
100 BAIL_ON_PTR_ERROR(i->home_directory, wbc_status);
101 i->home_drive = talloc_strdup(i, resp->data.auth.info3.dir_drive);
102 BAIL_ON_PTR_ERROR(i->home_drive, wbc_status);
105 i->num_sids += resp->data.auth.info3.num_groups;
106 i->num_sids += resp->data.auth.info3.num_other_sids;
108 i->sids = talloc_array(i, struct wbcSidWithAttr, i->num_sids);
109 BAIL_ON_PTR_ERROR(i->sids, wbc_status);
111 wbc_status = wbcStringToSid(resp->data.auth.info3.dom_sid,
113 BAIL_ON_WBC_ERROR(wbc_status);
115 #define _SID_COMPOSE(s, d, r, a) { \
117 if ((s).sid.num_auths < WBC_MAXSUBAUTHS) { \
118 (s).sid.sub_auths[(s).sid.num_auths++] = r; \
120 wbc_status = WBC_ERR_INVALID_SID; \
121 BAIL_ON_WBC_ERROR(wbc_status); \
123 (s).attributes = a; \
127 _SID_COMPOSE(i->sids[sn], domain_sid,
128 resp->data.auth.info3.user_rid,
131 _SID_COMPOSE(i->sids[sn], domain_sid,
132 resp->data.auth.info3.group_rid,
136 p = (char *)resp->extra_data.data;
138 wbc_status = WBC_ERR_INVALID_RESPONSE;
139 BAIL_ON_WBC_ERROR(wbc_status);
142 for (j=0; j < resp->data.auth.info3.num_groups; j++) {
147 char *e = strchr(p, '\n');
149 wbc_status = WBC_ERR_INVALID_RESPONSE;
150 BAIL_ON_WBC_ERROR(wbc_status);
155 ret = sscanf(s, "0x%08X:0x%08X", &rid, &attrs);
157 wbc_status = WBC_ERR_INVALID_RESPONSE;
158 BAIL_ON_WBC_ERROR(wbc_status);
161 _SID_COMPOSE(i->sids[sn], domain_sid,
166 for (j=0; j < resp->data.auth.info3.num_other_sids; j++) {
171 char *e = strchr(p, '\n');
173 wbc_status = WBC_ERR_INVALID_RESPONSE;
174 BAIL_ON_WBC_ERROR(wbc_status);
181 wbc_status = WBC_ERR_INVALID_RESPONSE;
182 BAIL_ON_WBC_ERROR(wbc_status);
187 ret = sscanf(a, "0x%08X",
190 wbc_status = WBC_ERR_INVALID_RESPONSE;
191 BAIL_ON_WBC_ERROR(wbc_status);
194 wbc_status = wbcStringToSid(s, &i->sids[sn].sid);
195 BAIL_ON_WBC_ERROR(wbc_status);
197 i->sids[sn].attributes = attrs;
210 static wbcErr wbc_create_error_info(TALLOC_CTX *mem_ctx,
211 const struct winbindd_response *resp,
212 struct wbcAuthErrorInfo **_e)
214 wbcErr wbc_status = WBC_ERR_SUCCESS;
215 struct wbcAuthErrorInfo *e;
217 e = talloc(mem_ctx, struct wbcAuthErrorInfo);
218 BAIL_ON_PTR_ERROR(e, wbc_status);
220 e->nt_status = resp->data.auth.nt_status;
221 e->pam_error = resp->data.auth.pam_error;
222 e->nt_string = talloc_strdup(e, resp->data.auth.nt_status_string);
223 BAIL_ON_PTR_ERROR(e->nt_string, wbc_status);
225 e->display_string = talloc_strdup(e, resp->data.auth.error_string);
226 BAIL_ON_PTR_ERROR(e->display_string, wbc_status);
236 static wbcErr wbc_create_password_policy_info(TALLOC_CTX *mem_ctx,
237 const struct winbindd_response *resp,
238 struct wbcUserPasswordPolicyInfo **_i)
240 wbcErr wbc_status = WBC_ERR_SUCCESS;
241 struct wbcUserPasswordPolicyInfo *i;
243 i = talloc(mem_ctx, struct wbcUserPasswordPolicyInfo);
244 BAIL_ON_PTR_ERROR(i, wbc_status);
246 i->min_passwordage = resp->data.auth.policy.min_passwordage;
247 i->min_length_password = resp->data.auth.policy.min_length_password;
248 i->password_history = resp->data.auth.policy.password_history;
249 i->password_properties = resp->data.auth.policy.password_properties;
250 i->expire = resp->data.auth.policy.expire;
260 static wbcErr wbc_create_logon_info(TALLOC_CTX *mem_ctx,
261 struct winbindd_response *resp,
262 struct wbcLogonUserInfo **_i)
264 wbcErr wbc_status = WBC_ERR_SUCCESS;
265 struct wbcLogonUserInfo *i;
267 i = talloc_zero(mem_ctx, struct wbcLogonUserInfo);
268 BAIL_ON_PTR_ERROR(i, wbc_status);
270 wbc_status = wbc_create_auth_info(i, resp, &i->info);
271 BAIL_ON_WBC_ERROR(wbc_status);
273 if (resp->data.auth.krb5ccname &&
274 strlen(resp->data.auth.krb5ccname)) {
275 wbc_status = wbcAddNamedBlob(&i->num_blobs,
279 (uint8_t *)resp->data.auth.krb5ccname,
280 strlen(resp->data.auth.krb5ccname)+1);
281 BAIL_ON_WBC_ERROR(wbc_status);
284 if (resp->data.auth.unix_username &&
285 strlen(resp->data.auth.unix_username)) {
286 wbc_status = wbcAddNamedBlob(&i->num_blobs,
290 (uint8_t *)resp->data.auth.unix_username,
291 strlen(resp->data.auth.unix_username)+1);
292 BAIL_ON_WBC_ERROR(wbc_status);
298 if (!WBC_ERROR_IS_OK(wbc_status) && i) {
299 wbcFreeMemory(i->blobs);
306 /* Authenticate with more detailed information */
307 wbcErr wbcAuthenticateUserEx(const struct wbcAuthUserParams *params,
308 struct wbcAuthUserInfo **info,
309 struct wbcAuthErrorInfo **error)
311 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
313 struct winbindd_request request;
314 struct winbindd_response response;
316 ZERO_STRUCT(request);
317 ZERO_STRUCT(response);
324 wbc_status = WBC_ERR_INVALID_PARAM;
325 BAIL_ON_WBC_ERROR(wbc_status);
328 if (!params->account_name) {
329 wbc_status = WBC_ERR_INVALID_PARAM;
330 BAIL_ON_WBC_ERROR(wbc_status);
333 /* Initialize request */
335 switch (params->level) {
336 case WBC_AUTH_USER_LEVEL_PLAIN:
337 cmd = WINBINDD_PAM_AUTH;
338 request.flags = WBFLAG_PAM_INFO3_TEXT |
339 WBFLAG_PAM_USER_SESSION_KEY |
342 if (!params->password.plaintext) {
343 wbc_status = WBC_ERR_INVALID_PARAM;
344 BAIL_ON_WBC_ERROR(wbc_status);
347 if (params->domain_name && params->domain_name[0]) {
348 /* We need to get the winbind separator :-( */
349 struct winbindd_response sep_response;
351 ZERO_STRUCT(sep_response);
353 wbc_status = wbcRequestResponse(WINBINDD_INFO,
354 NULL, &sep_response);
355 BAIL_ON_WBC_ERROR(wbc_status);
357 snprintf(request.data.auth.user,
358 sizeof(request.data.auth.user)-1,
361 sep_response.data.info.winbind_separator,
362 params->account_name);
364 strncpy(request.data.auth.user,
365 params->account_name,
366 sizeof(request.data.auth.user)-1);
369 strncpy(request.data.auth.pass,
370 params->password.plaintext,
371 sizeof(request.data.auth.pass)-1);
374 case WBC_AUTH_USER_LEVEL_HASH:
375 wbc_status = WBC_ERR_NOT_IMPLEMENTED;
376 BAIL_ON_WBC_ERROR(wbc_status);
379 case WBC_AUTH_USER_LEVEL_RESPONSE:
380 cmd = WINBINDD_PAM_AUTH_CRAP;
381 request.flags = WBFLAG_PAM_INFO3_TEXT |
382 WBFLAG_PAM_USER_SESSION_KEY |
385 if (params->password.response.lm_length &&
386 !params->password.response.lm_data) {
387 wbc_status = WBC_ERR_INVALID_PARAM;
388 BAIL_ON_WBC_ERROR(wbc_status);
390 if (params->password.response.lm_length == 0 &&
391 params->password.response.lm_data) {
392 wbc_status = WBC_ERR_INVALID_PARAM;
393 BAIL_ON_WBC_ERROR(wbc_status);
396 if (params->password.response.nt_length &&
397 !params->password.response.nt_data) {
398 wbc_status = WBC_ERR_INVALID_PARAM;
399 BAIL_ON_WBC_ERROR(wbc_status);
401 if (params->password.response.nt_length == 0&&
402 params->password.response.nt_data) {
403 wbc_status = WBC_ERR_INVALID_PARAM;
404 BAIL_ON_WBC_ERROR(wbc_status);
407 strncpy(request.data.auth_crap.user,
408 params->account_name,
409 sizeof(request.data.auth_crap.user)-1);
410 if (params->domain_name) {
411 strncpy(request.data.auth_crap.domain,
413 sizeof(request.data.auth_crap.domain)-1);
415 if (params->workstation_name) {
416 strncpy(request.data.auth_crap.workstation,
417 params->workstation_name,
418 sizeof(request.data.auth_crap.workstation)-1);
421 request.data.auth_crap.logon_parameters =
422 params->parameter_control;
424 memcpy(request.data.auth_crap.chal,
425 params->password.response.challenge,
426 sizeof(request.data.auth_crap.chal));
428 request.data.auth_crap.lm_resp_len =
429 MIN(params->password.response.lm_length,
430 sizeof(request.data.auth_crap.lm_resp));
431 if (params->password.response.lm_data) {
432 memcpy(request.data.auth_crap.lm_resp,
433 params->password.response.lm_data,
434 request.data.auth_crap.lm_resp_len);
436 request.data.auth_crap.nt_resp_len = params->password.response.nt_length;
437 if (params->password.response.nt_length > sizeof(request.data.auth_crap.nt_resp)) {
438 request.flags |= WBFLAG_BIG_NTLMV2_BLOB;
439 request.extra_len = params->password.response.nt_length;
440 request.extra_data.data = talloc_zero_array(NULL, char, request.extra_len);
441 if (request.extra_data.data == NULL) {
442 wbc_status = WBC_ERR_NO_MEMORY;
443 BAIL_ON_WBC_ERROR(wbc_status);
445 memcpy(request.extra_data.data,
446 params->password.response.nt_data,
447 request.data.auth_crap.nt_resp_len);
448 } else if (params->password.response.nt_data) {
449 memcpy(request.data.auth_crap.nt_resp,
450 params->password.response.nt_data,
451 request.data.auth_crap.nt_resp_len);
459 wbc_status = WBC_ERR_INVALID_PARAM;
460 BAIL_ON_WBC_ERROR(wbc_status);
464 request.flags |= params->flags;
467 wbc_status = wbcRequestResponse(cmd,
470 if (response.data.auth.nt_status != 0) {
472 wbc_status = wbc_create_error_info(NULL,
475 BAIL_ON_WBC_ERROR(wbc_status);
478 wbc_status = WBC_ERR_AUTH_ERROR;
479 BAIL_ON_WBC_ERROR(wbc_status);
481 BAIL_ON_WBC_ERROR(wbc_status);
484 wbc_status = wbc_create_auth_info(NULL,
487 BAIL_ON_WBC_ERROR(wbc_status);
491 winbindd_free_response(&response);
493 talloc_free(request.extra_data.data);
498 /* Trigger a verification of the trust credentials of a specific domain */
499 wbcErr wbcCheckTrustCredentials(const char *domain,
500 struct wbcAuthErrorInfo **error)
502 struct winbindd_request request;
503 struct winbindd_response response;
504 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
506 ZERO_STRUCT(request);
507 ZERO_STRUCT(response);
510 strncpy(request.domain_name, domain,
511 sizeof(request.domain_name)-1);
516 wbc_status = wbcRequestResponse(WINBINDD_CHECK_MACHACC,
519 if (response.data.auth.nt_status != 0) {
521 wbc_status = wbc_create_error_info(NULL,
524 BAIL_ON_WBC_ERROR(wbc_status);
527 wbc_status = WBC_ERR_AUTH_ERROR;
528 BAIL_ON_WBC_ERROR(wbc_status);
530 BAIL_ON_WBC_ERROR(wbc_status);
536 /* Trigger a change of the trust credentials for a specific domain */
537 wbcErr wbcChangeTrustCredentials(const char *domain,
538 struct wbcAuthErrorInfo **error)
540 struct winbindd_request request;
541 struct winbindd_response response;
542 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
544 ZERO_STRUCT(request);
545 ZERO_STRUCT(response);
548 strncpy(request.domain_name, domain,
549 sizeof(request.domain_name)-1);
554 wbc_status = wbcRequestResponse(WINBINDD_CHANGE_MACHACC,
557 if (response.data.auth.nt_status != 0) {
559 wbc_status = wbc_create_error_info(NULL,
562 BAIL_ON_WBC_ERROR(wbc_status);
565 wbc_status = WBC_ERR_AUTH_ERROR;
566 BAIL_ON_WBC_ERROR(wbc_status);
568 BAIL_ON_WBC_ERROR(wbc_status);
575 * Trigger a no-op NETLOGON call. Lightweight version of
576 * wbcCheckTrustCredentials
578 wbcErr wbcPingDc(const char *domain, struct wbcAuthErrorInfo **error)
580 struct winbindd_request request;
581 struct winbindd_response response;
582 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
586 * the current protocol doesn't support
587 * specifying a domain
589 wbc_status = WBC_ERR_NOT_IMPLEMENTED;
590 BAIL_ON_WBC_ERROR(wbc_status);
593 ZERO_STRUCT(request);
594 ZERO_STRUCT(response);
598 wbc_status = wbcRequestResponse(WINBINDD_PING_DC,
601 if (response.data.auth.nt_status != 0) {
603 wbc_status = wbc_create_error_info(NULL,
606 BAIL_ON_WBC_ERROR(wbc_status);
609 wbc_status = WBC_ERR_AUTH_ERROR;
610 BAIL_ON_WBC_ERROR(wbc_status);
612 BAIL_ON_WBC_ERROR(wbc_status);
618 /* Trigger an extended logoff notification to Winbind for a specific user */
619 wbcErr wbcLogoffUserEx(const struct wbcLogoffUserParams *params,
620 struct wbcAuthErrorInfo **error)
622 struct winbindd_request request;
623 struct winbindd_response response;
624 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
629 if (!params || !params->username) {
630 wbc_status = WBC_ERR_INVALID_PARAM;
631 BAIL_ON_WBC_ERROR(wbc_status);
634 if ((params->num_blobs > 0) && (params->blobs == NULL)) {
635 wbc_status = WBC_ERR_INVALID_PARAM;
636 BAIL_ON_WBC_ERROR(wbc_status);
638 if ((params->num_blobs == 0) && (params->blobs != NULL)) {
639 wbc_status = WBC_ERR_INVALID_PARAM;
640 BAIL_ON_WBC_ERROR(wbc_status);
643 ZERO_STRUCT(request);
644 ZERO_STRUCT(response);
646 strncpy(request.data.logoff.user, params->username,
647 sizeof(request.data.logoff.user)-1);
649 for (i=0; i<params->num_blobs; i++) {
651 if (strcasecmp(params->blobs[i].name, "ccfilename") == 0) {
652 if (params->blobs[i].blob.data) {
653 strncpy(request.data.logoff.krb5ccname,
654 (const char *)params->blobs[i].blob.data,
655 sizeof(request.data.logoff.krb5ccname) - 1);
660 if (strcasecmp(params->blobs[i].name, "user_uid") == 0) {
661 if (params->blobs[i].blob.data) {
662 memcpy(&request.data.logoff.uid,
663 params->blobs[i].blob.data,
664 MIN(params->blobs[i].blob.length,
665 sizeof(request.data.logoff.uid)));
670 if (strcasecmp(params->blobs[i].name, "flags") == 0) {
671 if (params->blobs[i].blob.data) {
672 memcpy(&request.flags,
673 params->blobs[i].blob.data,
674 MIN(params->blobs[i].blob.length,
675 sizeof(request.flags)));
683 wbc_status = wbcRequestResponse(WINBINDD_PAM_LOGOFF,
687 /* Take the response above and return it to the caller */
688 if (response.data.auth.nt_status != 0) {
690 wbc_status = wbc_create_error_info(NULL,
693 BAIL_ON_WBC_ERROR(wbc_status);
696 wbc_status = WBC_ERR_AUTH_ERROR;
697 BAIL_ON_WBC_ERROR(wbc_status);
699 BAIL_ON_WBC_ERROR(wbc_status);
705 /* Trigger a logoff notification to Winbind for a specific user */
706 wbcErr wbcLogoffUser(const char *username,
708 const char *ccfilename)
710 struct winbindd_request request;
711 struct winbindd_response response;
712 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
717 wbc_status = WBC_ERR_INVALID_PARAM;
718 BAIL_ON_WBC_ERROR(wbc_status);
721 ZERO_STRUCT(request);
722 ZERO_STRUCT(response);
724 strncpy(request.data.logoff.user, username,
725 sizeof(request.data.logoff.user)-1);
726 request.data.logoff.uid = uid;
729 strncpy(request.data.logoff.krb5ccname, ccfilename,
730 sizeof(request.data.logoff.krb5ccname)-1);
735 wbc_status = wbcRequestResponse(WINBINDD_PAM_LOGOFF,
739 /* Take the response above and return it to the caller */
745 /* Change a password for a user with more detailed information upon failure */
746 wbcErr wbcChangeUserPasswordEx(const struct wbcChangePasswordParams *params,
747 struct wbcAuthErrorInfo **error,
748 enum wbcPasswordChangeRejectReason *reject_reason,
749 struct wbcUserPasswordPolicyInfo **policy)
751 struct winbindd_request request;
752 struct winbindd_response response;
753 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
758 if (!params->account_name) {
759 wbc_status = WBC_ERR_INVALID_PARAM;
760 BAIL_ON_WBC_ERROR(wbc_status);
775 ZERO_STRUCT(request);
776 ZERO_STRUCT(response);
778 switch (params->level) {
779 case WBC_CHANGE_PASSWORD_LEVEL_PLAIN:
780 cmd = WINBINDD_PAM_CHAUTHTOK;
782 if (!params->account_name) {
783 wbc_status = WBC_ERR_INVALID_PARAM;
784 BAIL_ON_WBC_ERROR(wbc_status);
787 strncpy(request.data.chauthtok.user, params->account_name,
788 sizeof(request.data.chauthtok.user) - 1);
790 if (params->old_password.plaintext) {
791 strncpy(request.data.chauthtok.oldpass,
792 params->old_password.plaintext,
793 sizeof(request.data.chauthtok.oldpass) - 1);
796 if (params->new_password.plaintext) {
797 strncpy(request.data.chauthtok.newpass,
798 params->new_password.plaintext,
799 sizeof(request.data.chauthtok.newpass) - 1);
803 case WBC_CHANGE_PASSWORD_LEVEL_RESPONSE:
804 cmd = WINBINDD_PAM_CHNG_PSWD_AUTH_CRAP;
806 if (!params->account_name || !params->domain_name) {
807 wbc_status = WBC_ERR_INVALID_PARAM;
808 BAIL_ON_WBC_ERROR(wbc_status);
811 if (params->old_password.response.old_lm_hash_enc_length &&
812 !params->old_password.response.old_lm_hash_enc_data) {
813 wbc_status = WBC_ERR_INVALID_PARAM;
814 BAIL_ON_WBC_ERROR(wbc_status);
817 if (params->old_password.response.old_lm_hash_enc_length == 0 &&
818 params->old_password.response.old_lm_hash_enc_data) {
819 wbc_status = WBC_ERR_INVALID_PARAM;
820 BAIL_ON_WBC_ERROR(wbc_status);
823 if (params->old_password.response.old_nt_hash_enc_length &&
824 !params->old_password.response.old_nt_hash_enc_data) {
825 wbc_status = WBC_ERR_INVALID_PARAM;
826 BAIL_ON_WBC_ERROR(wbc_status);
829 if (params->old_password.response.old_nt_hash_enc_length == 0 &&
830 params->old_password.response.old_nt_hash_enc_data) {
831 wbc_status = WBC_ERR_INVALID_PARAM;
832 BAIL_ON_WBC_ERROR(wbc_status);
835 if (params->new_password.response.lm_length &&
836 !params->new_password.response.lm_data) {
837 wbc_status = WBC_ERR_INVALID_PARAM;
838 BAIL_ON_WBC_ERROR(wbc_status);
841 if (params->new_password.response.lm_length == 0 &&
842 params->new_password.response.lm_data) {
843 wbc_status = WBC_ERR_INVALID_PARAM;
844 BAIL_ON_WBC_ERROR(wbc_status);
847 if (params->new_password.response.nt_length &&
848 !params->new_password.response.nt_data) {
849 wbc_status = WBC_ERR_INVALID_PARAM;
850 BAIL_ON_WBC_ERROR(wbc_status);
853 if (params->new_password.response.nt_length == 0 &&
854 params->new_password.response.nt_data) {
855 wbc_status = WBC_ERR_INVALID_PARAM;
856 BAIL_ON_WBC_ERROR(wbc_status);
859 strncpy(request.data.chng_pswd_auth_crap.user,
860 params->account_name,
861 sizeof(request.data.chng_pswd_auth_crap.user) - 1);
863 strncpy(request.data.chng_pswd_auth_crap.domain,
865 sizeof(request.data.chng_pswd_auth_crap.domain) - 1);
867 if (params->new_password.response.nt_data) {
868 memcpy(request.data.chng_pswd_auth_crap.new_nt_pswd,
869 params->new_password.response.nt_data,
870 request.data.chng_pswd_auth_crap.new_nt_pswd_len);
871 request.data.chng_pswd_auth_crap.new_nt_pswd_len =
872 params->new_password.response.nt_length;
875 if (params->new_password.response.lm_data) {
876 memcpy(request.data.chng_pswd_auth_crap.new_lm_pswd,
877 params->new_password.response.lm_data,
878 request.data.chng_pswd_auth_crap.new_lm_pswd_len);
879 request.data.chng_pswd_auth_crap.new_lm_pswd_len =
880 params->new_password.response.lm_length;
883 if (params->old_password.response.old_nt_hash_enc_data) {
884 memcpy(request.data.chng_pswd_auth_crap.old_nt_hash_enc,
885 params->old_password.response.old_nt_hash_enc_data,
886 request.data.chng_pswd_auth_crap.old_nt_hash_enc_len);
887 request.data.chng_pswd_auth_crap.old_nt_hash_enc_len =
888 params->old_password.response.old_nt_hash_enc_length;
891 if (params->old_password.response.old_lm_hash_enc_data) {
892 memcpy(request.data.chng_pswd_auth_crap.old_lm_hash_enc,
893 params->old_password.response.old_lm_hash_enc_data,
894 request.data.chng_pswd_auth_crap.old_lm_hash_enc_len);
895 request.data.chng_pswd_auth_crap.old_lm_hash_enc_len =
896 params->old_password.response.old_lm_hash_enc_length;
901 wbc_status = WBC_ERR_INVALID_PARAM;
902 BAIL_ON_WBC_ERROR(wbc_status);
908 wbc_status = wbcRequestResponse(cmd,
911 if (WBC_ERROR_IS_OK(wbc_status)) {
915 /* Take the response above and return it to the caller */
917 if (response.data.auth.nt_status != 0) {
919 wbc_status = wbc_create_error_info(NULL,
922 BAIL_ON_WBC_ERROR(wbc_status);
928 wbc_status = wbc_create_password_policy_info(NULL,
931 BAIL_ON_WBC_ERROR(wbc_status);
935 *reject_reason = response.data.auth.reject_reason;
938 wbc_status = WBC_ERR_PWD_CHANGE_FAILED;
939 BAIL_ON_WBC_ERROR(wbc_status);
945 /* Change a password for a user */
946 wbcErr wbcChangeUserPassword(const char *username,
947 const char *old_password,
948 const char *new_password)
950 wbcErr wbc_status = WBC_ERR_SUCCESS;
951 struct wbcChangePasswordParams params;
955 params.account_name = username;
956 params.level = WBC_CHANGE_PASSWORD_LEVEL_PLAIN;
957 params.old_password.plaintext = old_password;
958 params.new_password.plaintext = new_password;
960 wbc_status = wbcChangeUserPasswordEx(¶ms,
964 BAIL_ON_WBC_ERROR(wbc_status);
971 wbcErr wbcLogonUser(const struct wbcLogonUserParams *params,
972 struct wbcLogonUserInfo **info,
973 struct wbcAuthErrorInfo **error,
974 struct wbcUserPasswordPolicyInfo **policy)
976 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
978 struct winbindd_request request;
979 struct winbindd_response response;
982 ZERO_STRUCT(request);
983 ZERO_STRUCT(response);
996 wbc_status = WBC_ERR_INVALID_PARAM;
997 BAIL_ON_WBC_ERROR(wbc_status);
1000 if (!params->username) {
1001 wbc_status = WBC_ERR_INVALID_PARAM;
1002 BAIL_ON_WBC_ERROR(wbc_status);
1005 if ((params->num_blobs > 0) && (params->blobs == NULL)) {
1006 wbc_status = WBC_ERR_INVALID_PARAM;
1007 BAIL_ON_WBC_ERROR(wbc_status);
1009 if ((params->num_blobs == 0) && (params->blobs != NULL)) {
1010 wbc_status = WBC_ERR_INVALID_PARAM;
1011 BAIL_ON_WBC_ERROR(wbc_status);
1014 /* Initialize request */
1016 cmd = WINBINDD_PAM_AUTH;
1017 request.flags = WBFLAG_PAM_INFO3_TEXT |
1018 WBFLAG_PAM_USER_SESSION_KEY |
1021 if (!params->password) {
1022 wbc_status = WBC_ERR_INVALID_PARAM;
1023 BAIL_ON_WBC_ERROR(wbc_status);
1026 strncpy(request.data.auth.user,
1028 sizeof(request.data.auth.user)-1);
1030 strncpy(request.data.auth.pass,
1032 sizeof(request.data.auth.pass)-1);
1034 for (i=0; i<params->num_blobs; i++) {
1036 if (strcasecmp(params->blobs[i].name, "krb5_cc_type") == 0) {
1037 if (params->blobs[i].blob.data) {
1038 strncpy(request.data.auth.krb5_cc_type,
1039 (const char *)params->blobs[i].blob.data,
1040 sizeof(request.data.auth.krb5_cc_type) - 1);
1045 if (strcasecmp(params->blobs[i].name, "user_uid") == 0) {
1046 if (params->blobs[i].blob.data) {
1047 memcpy(&request.data.auth.uid,
1048 params->blobs[i].blob.data,
1049 MIN(sizeof(request.data.auth.uid),
1050 params->blobs[i].blob.length));
1055 if (strcasecmp(params->blobs[i].name, "flags") == 0) {
1056 if (params->blobs[i].blob.data) {
1059 params->blobs[i].blob.data,
1061 params->blobs[i].blob.length));
1062 request.flags |= flags;
1067 if (strcasecmp(params->blobs[i].name, "membership_of") == 0) {
1068 if (params->blobs[i].blob.data &&
1069 params->blobs[i].blob.data[0] > 0) {
1070 strncpy(request.data.auth.require_membership_of_sid,
1071 (const char *)params->blobs[i].blob.data,
1072 sizeof(request.data.auth.require_membership_of_sid) - 1);
1078 wbc_status = wbcRequestResponse(cmd,
1082 if (response.data.auth.nt_status != 0) {
1084 wbc_status = wbc_create_error_info(NULL,
1087 BAIL_ON_WBC_ERROR(wbc_status);
1090 wbc_status = WBC_ERR_AUTH_ERROR;
1091 BAIL_ON_WBC_ERROR(wbc_status);
1093 BAIL_ON_WBC_ERROR(wbc_status);
1096 wbc_status = wbc_create_logon_info(NULL,
1099 BAIL_ON_WBC_ERROR(wbc_status);
1103 wbc_status = wbc_create_password_policy_info(NULL,
1106 BAIL_ON_WBC_ERROR(wbc_status);
1110 winbindd_free_response(&response);
1115 /* Authenticate a user with cached credentials */
1116 wbcErr wbcCredentialCache(struct wbcCredentialCacheParams *params,
1117 struct wbcCredentialCacheInfo **info,
1118 struct wbcAuthErrorInfo **error)
1120 return WBC_ERR_NOT_IMPLEMENTED;
1123 /* Authenticate a user with cached credentials */
1124 wbcErr wbcCredentialSave(const char *user, const char *password)
1126 struct winbindd_request request;
1127 struct winbindd_response response;
1129 ZERO_STRUCT(request);
1130 ZERO_STRUCT(response);
1132 strncpy(request.data.ccache_save.user, user,
1133 sizeof(request.data.ccache_save.user)-1);
1134 strncpy(request.data.ccache_save.pass, password,
1135 sizeof(request.data.ccache_save.pass)-1);
1136 request.data.ccache_save.uid = getuid();
1138 return wbcRequestResponse(WINBINDD_CCACHE_SAVE, &request, &response);