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(const struct winbindd_response *resp,
211 struct wbcAuthErrorInfo **_e)
213 wbcErr wbc_status = WBC_ERR_SUCCESS;
214 struct wbcAuthErrorInfo *e;
216 e = talloc(NULL, struct wbcAuthErrorInfo);
217 BAIL_ON_PTR_ERROR(e, wbc_status);
219 e->nt_status = resp->data.auth.nt_status;
220 e->pam_error = resp->data.auth.pam_error;
221 e->nt_string = talloc_strdup(e, resp->data.auth.nt_status_string);
222 BAIL_ON_PTR_ERROR(e->nt_string, wbc_status);
224 e->display_string = talloc_strdup(e, resp->data.auth.error_string);
225 BAIL_ON_PTR_ERROR(e->display_string, wbc_status);
235 static wbcErr wbc_create_password_policy_info(const struct winbindd_response *resp,
236 struct wbcUserPasswordPolicyInfo **_i)
238 wbcErr wbc_status = WBC_ERR_SUCCESS;
239 struct wbcUserPasswordPolicyInfo *i;
241 i = talloc(NULL, struct wbcUserPasswordPolicyInfo);
242 BAIL_ON_PTR_ERROR(i, wbc_status);
244 i->min_passwordage = resp->data.auth.policy.min_passwordage;
245 i->min_length_password = resp->data.auth.policy.min_length_password;
246 i->password_history = resp->data.auth.policy.password_history;
247 i->password_properties = resp->data.auth.policy.password_properties;
248 i->expire = resp->data.auth.policy.expire;
258 static wbcErr wbc_create_logon_info(struct winbindd_response *resp,
259 struct wbcLogonUserInfo **_i)
261 wbcErr wbc_status = WBC_ERR_SUCCESS;
262 struct wbcLogonUserInfo *i;
264 i = talloc_zero(NULL, struct wbcLogonUserInfo);
265 BAIL_ON_PTR_ERROR(i, wbc_status);
267 wbc_status = wbc_create_auth_info(i, resp, &i->info);
268 BAIL_ON_WBC_ERROR(wbc_status);
270 if (resp->data.auth.krb5ccname &&
271 strlen(resp->data.auth.krb5ccname)) {
272 wbc_status = wbcAddNamedBlob(&i->num_blobs,
276 (uint8_t *)resp->data.auth.krb5ccname,
277 strlen(resp->data.auth.krb5ccname)+1);
278 BAIL_ON_WBC_ERROR(wbc_status);
281 if (resp->data.auth.unix_username &&
282 strlen(resp->data.auth.unix_username)) {
283 wbc_status = wbcAddNamedBlob(&i->num_blobs,
287 (uint8_t *)resp->data.auth.unix_username,
288 strlen(resp->data.auth.unix_username)+1);
289 BAIL_ON_WBC_ERROR(wbc_status);
295 if (!WBC_ERROR_IS_OK(wbc_status) && i) {
296 wbcFreeMemory(i->blobs);
303 /* Authenticate with more detailed information */
304 wbcErr wbcAuthenticateUserEx(const struct wbcAuthUserParams *params,
305 struct wbcAuthUserInfo **info,
306 struct wbcAuthErrorInfo **error)
308 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
310 struct winbindd_request request;
311 struct winbindd_response response;
313 ZERO_STRUCT(request);
314 ZERO_STRUCT(response);
321 wbc_status = WBC_ERR_INVALID_PARAM;
322 BAIL_ON_WBC_ERROR(wbc_status);
325 if (!params->account_name) {
326 wbc_status = WBC_ERR_INVALID_PARAM;
327 BAIL_ON_WBC_ERROR(wbc_status);
330 /* Initialize request */
332 switch (params->level) {
333 case WBC_AUTH_USER_LEVEL_PLAIN:
334 cmd = WINBINDD_PAM_AUTH;
335 request.flags = WBFLAG_PAM_INFO3_TEXT |
336 WBFLAG_PAM_USER_SESSION_KEY |
339 if (!params->password.plaintext) {
340 wbc_status = WBC_ERR_INVALID_PARAM;
341 BAIL_ON_WBC_ERROR(wbc_status);
344 if (params->domain_name && params->domain_name[0]) {
345 /* We need to get the winbind separator :-( */
346 struct winbindd_response sep_response;
348 ZERO_STRUCT(sep_response);
350 wbc_status = wbcRequestResponse(WINBINDD_INFO,
351 NULL, &sep_response);
352 BAIL_ON_WBC_ERROR(wbc_status);
354 snprintf(request.data.auth.user,
355 sizeof(request.data.auth.user)-1,
358 sep_response.data.info.winbind_separator,
359 params->account_name);
361 strncpy(request.data.auth.user,
362 params->account_name,
363 sizeof(request.data.auth.user)-1);
366 strncpy(request.data.auth.pass,
367 params->password.plaintext,
368 sizeof(request.data.auth.pass)-1);
371 case WBC_AUTH_USER_LEVEL_HASH:
372 wbc_status = WBC_ERR_NOT_IMPLEMENTED;
373 BAIL_ON_WBC_ERROR(wbc_status);
376 case WBC_AUTH_USER_LEVEL_RESPONSE:
377 cmd = WINBINDD_PAM_AUTH_CRAP;
378 request.flags = WBFLAG_PAM_INFO3_TEXT |
379 WBFLAG_PAM_USER_SESSION_KEY |
382 if (params->password.response.lm_length &&
383 !params->password.response.lm_data) {
384 wbc_status = WBC_ERR_INVALID_PARAM;
385 BAIL_ON_WBC_ERROR(wbc_status);
387 if (params->password.response.lm_length == 0 &&
388 params->password.response.lm_data) {
389 wbc_status = WBC_ERR_INVALID_PARAM;
390 BAIL_ON_WBC_ERROR(wbc_status);
393 if (params->password.response.nt_length &&
394 !params->password.response.nt_data) {
395 wbc_status = WBC_ERR_INVALID_PARAM;
396 BAIL_ON_WBC_ERROR(wbc_status);
398 if (params->password.response.nt_length == 0&&
399 params->password.response.nt_data) {
400 wbc_status = WBC_ERR_INVALID_PARAM;
401 BAIL_ON_WBC_ERROR(wbc_status);
404 strncpy(request.data.auth_crap.user,
405 params->account_name,
406 sizeof(request.data.auth_crap.user)-1);
407 if (params->domain_name) {
408 strncpy(request.data.auth_crap.domain,
410 sizeof(request.data.auth_crap.domain)-1);
412 if (params->workstation_name) {
413 strncpy(request.data.auth_crap.workstation,
414 params->workstation_name,
415 sizeof(request.data.auth_crap.workstation)-1);
418 request.data.auth_crap.logon_parameters =
419 params->parameter_control;
421 memcpy(request.data.auth_crap.chal,
422 params->password.response.challenge,
423 sizeof(request.data.auth_crap.chal));
425 request.data.auth_crap.lm_resp_len =
426 MIN(params->password.response.lm_length,
427 sizeof(request.data.auth_crap.lm_resp));
428 if (params->password.response.lm_data) {
429 memcpy(request.data.auth_crap.lm_resp,
430 params->password.response.lm_data,
431 request.data.auth_crap.lm_resp_len);
433 request.data.auth_crap.nt_resp_len = params->password.response.nt_length;
434 if (params->password.response.nt_length > sizeof(request.data.auth_crap.nt_resp)) {
435 request.flags |= WBFLAG_BIG_NTLMV2_BLOB;
436 request.extra_len = params->password.response.nt_length;
437 request.extra_data.data = talloc_zero_array(NULL, char, request.extra_len);
438 if (request.extra_data.data == NULL) {
439 wbc_status = WBC_ERR_NO_MEMORY;
440 BAIL_ON_WBC_ERROR(wbc_status);
442 memcpy(request.extra_data.data,
443 params->password.response.nt_data,
444 request.data.auth_crap.nt_resp_len);
445 } else if (params->password.response.nt_data) {
446 memcpy(request.data.auth_crap.nt_resp,
447 params->password.response.nt_data,
448 request.data.auth_crap.nt_resp_len);
456 wbc_status = WBC_ERR_INVALID_PARAM;
457 BAIL_ON_WBC_ERROR(wbc_status);
461 request.flags |= params->flags;
464 wbc_status = wbcRequestResponse(cmd,
467 if (response.data.auth.nt_status != 0) {
469 wbc_status = wbc_create_error_info(&response,
471 BAIL_ON_WBC_ERROR(wbc_status);
474 wbc_status = WBC_ERR_AUTH_ERROR;
475 BAIL_ON_WBC_ERROR(wbc_status);
477 BAIL_ON_WBC_ERROR(wbc_status);
480 wbc_status = wbc_create_auth_info(NULL,
483 BAIL_ON_WBC_ERROR(wbc_status);
487 winbindd_free_response(&response);
489 talloc_free(request.extra_data.data);
494 /* Trigger a verification of the trust credentials of a specific domain */
495 wbcErr wbcCheckTrustCredentials(const char *domain,
496 struct wbcAuthErrorInfo **error)
498 struct winbindd_request request;
499 struct winbindd_response response;
500 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
502 ZERO_STRUCT(request);
503 ZERO_STRUCT(response);
506 strncpy(request.domain_name, domain,
507 sizeof(request.domain_name)-1);
512 wbc_status = wbcRequestResponse(WINBINDD_CHECK_MACHACC,
515 if (response.data.auth.nt_status != 0) {
517 wbc_status = wbc_create_error_info(&response,
519 BAIL_ON_WBC_ERROR(wbc_status);
522 wbc_status = WBC_ERR_AUTH_ERROR;
523 BAIL_ON_WBC_ERROR(wbc_status);
525 BAIL_ON_WBC_ERROR(wbc_status);
531 /* Trigger a change of the trust credentials for a specific domain */
532 wbcErr wbcChangeTrustCredentials(const char *domain,
533 struct wbcAuthErrorInfo **error)
535 struct winbindd_request request;
536 struct winbindd_response response;
537 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
539 ZERO_STRUCT(request);
540 ZERO_STRUCT(response);
543 strncpy(request.domain_name, domain,
544 sizeof(request.domain_name)-1);
549 wbc_status = wbcRequestResponse(WINBINDD_CHANGE_MACHACC,
552 if (response.data.auth.nt_status != 0) {
554 wbc_status = wbc_create_error_info(&response,
556 BAIL_ON_WBC_ERROR(wbc_status);
559 wbc_status = WBC_ERR_AUTH_ERROR;
560 BAIL_ON_WBC_ERROR(wbc_status);
562 BAIL_ON_WBC_ERROR(wbc_status);
569 * Trigger a no-op NETLOGON call. Lightweight version of
570 * wbcCheckTrustCredentials
572 wbcErr wbcPingDc(const char *domain, struct wbcAuthErrorInfo **error)
574 struct winbindd_request request;
575 struct winbindd_response response;
576 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
580 * the current protocol doesn't support
581 * specifying a domain
583 wbc_status = WBC_ERR_NOT_IMPLEMENTED;
584 BAIL_ON_WBC_ERROR(wbc_status);
587 ZERO_STRUCT(request);
588 ZERO_STRUCT(response);
592 wbc_status = wbcRequestResponse(WINBINDD_PING_DC,
595 if (response.data.auth.nt_status != 0) {
597 wbc_status = wbc_create_error_info(&response,
599 BAIL_ON_WBC_ERROR(wbc_status);
602 wbc_status = WBC_ERR_AUTH_ERROR;
603 BAIL_ON_WBC_ERROR(wbc_status);
605 BAIL_ON_WBC_ERROR(wbc_status);
611 /* Trigger an extended logoff notification to Winbind for a specific user */
612 wbcErr wbcLogoffUserEx(const struct wbcLogoffUserParams *params,
613 struct wbcAuthErrorInfo **error)
615 struct winbindd_request request;
616 struct winbindd_response response;
617 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
622 if (!params || !params->username) {
623 wbc_status = WBC_ERR_INVALID_PARAM;
624 BAIL_ON_WBC_ERROR(wbc_status);
627 if ((params->num_blobs > 0) && (params->blobs == NULL)) {
628 wbc_status = WBC_ERR_INVALID_PARAM;
629 BAIL_ON_WBC_ERROR(wbc_status);
631 if ((params->num_blobs == 0) && (params->blobs != NULL)) {
632 wbc_status = WBC_ERR_INVALID_PARAM;
633 BAIL_ON_WBC_ERROR(wbc_status);
636 ZERO_STRUCT(request);
637 ZERO_STRUCT(response);
639 strncpy(request.data.logoff.user, params->username,
640 sizeof(request.data.logoff.user)-1);
642 for (i=0; i<params->num_blobs; i++) {
644 if (strcasecmp(params->blobs[i].name, "ccfilename") == 0) {
645 if (params->blobs[i].blob.data) {
646 strncpy(request.data.logoff.krb5ccname,
647 (const char *)params->blobs[i].blob.data,
648 sizeof(request.data.logoff.krb5ccname) - 1);
653 if (strcasecmp(params->blobs[i].name, "user_uid") == 0) {
654 if (params->blobs[i].blob.data) {
655 memcpy(&request.data.logoff.uid,
656 params->blobs[i].blob.data,
657 MIN(params->blobs[i].blob.length,
658 sizeof(request.data.logoff.uid)));
663 if (strcasecmp(params->blobs[i].name, "flags") == 0) {
664 if (params->blobs[i].blob.data) {
665 memcpy(&request.flags,
666 params->blobs[i].blob.data,
667 MIN(params->blobs[i].blob.length,
668 sizeof(request.flags)));
676 wbc_status = wbcRequestResponse(WINBINDD_PAM_LOGOFF,
680 /* Take the response above and return it to the caller */
681 if (response.data.auth.nt_status != 0) {
683 wbc_status = wbc_create_error_info(&response,
685 BAIL_ON_WBC_ERROR(wbc_status);
688 wbc_status = WBC_ERR_AUTH_ERROR;
689 BAIL_ON_WBC_ERROR(wbc_status);
691 BAIL_ON_WBC_ERROR(wbc_status);
697 /* Trigger a logoff notification to Winbind for a specific user */
698 wbcErr wbcLogoffUser(const char *username,
700 const char *ccfilename)
702 struct winbindd_request request;
703 struct winbindd_response response;
704 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
709 wbc_status = WBC_ERR_INVALID_PARAM;
710 BAIL_ON_WBC_ERROR(wbc_status);
713 ZERO_STRUCT(request);
714 ZERO_STRUCT(response);
716 strncpy(request.data.logoff.user, username,
717 sizeof(request.data.logoff.user)-1);
718 request.data.logoff.uid = uid;
721 strncpy(request.data.logoff.krb5ccname, ccfilename,
722 sizeof(request.data.logoff.krb5ccname)-1);
727 wbc_status = wbcRequestResponse(WINBINDD_PAM_LOGOFF,
731 /* Take the response above and return it to the caller */
737 /* Change a password for a user with more detailed information upon failure */
738 wbcErr wbcChangeUserPasswordEx(const struct wbcChangePasswordParams *params,
739 struct wbcAuthErrorInfo **error,
740 enum wbcPasswordChangeRejectReason *reject_reason,
741 struct wbcUserPasswordPolicyInfo **policy)
743 struct winbindd_request request;
744 struct winbindd_response response;
745 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
750 if (!params->account_name) {
751 wbc_status = WBC_ERR_INVALID_PARAM;
752 BAIL_ON_WBC_ERROR(wbc_status);
767 ZERO_STRUCT(request);
768 ZERO_STRUCT(response);
770 switch (params->level) {
771 case WBC_CHANGE_PASSWORD_LEVEL_PLAIN:
772 cmd = WINBINDD_PAM_CHAUTHTOK;
774 if (!params->account_name) {
775 wbc_status = WBC_ERR_INVALID_PARAM;
776 BAIL_ON_WBC_ERROR(wbc_status);
779 strncpy(request.data.chauthtok.user, params->account_name,
780 sizeof(request.data.chauthtok.user) - 1);
782 if (params->old_password.plaintext) {
783 strncpy(request.data.chauthtok.oldpass,
784 params->old_password.plaintext,
785 sizeof(request.data.chauthtok.oldpass) - 1);
788 if (params->new_password.plaintext) {
789 strncpy(request.data.chauthtok.newpass,
790 params->new_password.plaintext,
791 sizeof(request.data.chauthtok.newpass) - 1);
795 case WBC_CHANGE_PASSWORD_LEVEL_RESPONSE:
796 cmd = WINBINDD_PAM_CHNG_PSWD_AUTH_CRAP;
798 if (!params->account_name || !params->domain_name) {
799 wbc_status = WBC_ERR_INVALID_PARAM;
800 BAIL_ON_WBC_ERROR(wbc_status);
803 if (params->old_password.response.old_lm_hash_enc_length &&
804 !params->old_password.response.old_lm_hash_enc_data) {
805 wbc_status = WBC_ERR_INVALID_PARAM;
806 BAIL_ON_WBC_ERROR(wbc_status);
809 if (params->old_password.response.old_lm_hash_enc_length == 0 &&
810 params->old_password.response.old_lm_hash_enc_data) {
811 wbc_status = WBC_ERR_INVALID_PARAM;
812 BAIL_ON_WBC_ERROR(wbc_status);
815 if (params->old_password.response.old_nt_hash_enc_length &&
816 !params->old_password.response.old_nt_hash_enc_data) {
817 wbc_status = WBC_ERR_INVALID_PARAM;
818 BAIL_ON_WBC_ERROR(wbc_status);
821 if (params->old_password.response.old_nt_hash_enc_length == 0 &&
822 params->old_password.response.old_nt_hash_enc_data) {
823 wbc_status = WBC_ERR_INVALID_PARAM;
824 BAIL_ON_WBC_ERROR(wbc_status);
827 if (params->new_password.response.lm_length &&
828 !params->new_password.response.lm_data) {
829 wbc_status = WBC_ERR_INVALID_PARAM;
830 BAIL_ON_WBC_ERROR(wbc_status);
833 if (params->new_password.response.lm_length == 0 &&
834 params->new_password.response.lm_data) {
835 wbc_status = WBC_ERR_INVALID_PARAM;
836 BAIL_ON_WBC_ERROR(wbc_status);
839 if (params->new_password.response.nt_length &&
840 !params->new_password.response.nt_data) {
841 wbc_status = WBC_ERR_INVALID_PARAM;
842 BAIL_ON_WBC_ERROR(wbc_status);
845 if (params->new_password.response.nt_length == 0 &&
846 params->new_password.response.nt_data) {
847 wbc_status = WBC_ERR_INVALID_PARAM;
848 BAIL_ON_WBC_ERROR(wbc_status);
851 strncpy(request.data.chng_pswd_auth_crap.user,
852 params->account_name,
853 sizeof(request.data.chng_pswd_auth_crap.user) - 1);
855 strncpy(request.data.chng_pswd_auth_crap.domain,
857 sizeof(request.data.chng_pswd_auth_crap.domain) - 1);
859 if (params->new_password.response.nt_data) {
860 memcpy(request.data.chng_pswd_auth_crap.new_nt_pswd,
861 params->new_password.response.nt_data,
862 request.data.chng_pswd_auth_crap.new_nt_pswd_len);
863 request.data.chng_pswd_auth_crap.new_nt_pswd_len =
864 params->new_password.response.nt_length;
867 if (params->new_password.response.lm_data) {
868 memcpy(request.data.chng_pswd_auth_crap.new_lm_pswd,
869 params->new_password.response.lm_data,
870 request.data.chng_pswd_auth_crap.new_lm_pswd_len);
871 request.data.chng_pswd_auth_crap.new_lm_pswd_len =
872 params->new_password.response.lm_length;
875 if (params->old_password.response.old_nt_hash_enc_data) {
876 memcpy(request.data.chng_pswd_auth_crap.old_nt_hash_enc,
877 params->old_password.response.old_nt_hash_enc_data,
878 request.data.chng_pswd_auth_crap.old_nt_hash_enc_len);
879 request.data.chng_pswd_auth_crap.old_nt_hash_enc_len =
880 params->old_password.response.old_nt_hash_enc_length;
883 if (params->old_password.response.old_lm_hash_enc_data) {
884 memcpy(request.data.chng_pswd_auth_crap.old_lm_hash_enc,
885 params->old_password.response.old_lm_hash_enc_data,
886 request.data.chng_pswd_auth_crap.old_lm_hash_enc_len);
887 request.data.chng_pswd_auth_crap.old_lm_hash_enc_len =
888 params->old_password.response.old_lm_hash_enc_length;
893 wbc_status = WBC_ERR_INVALID_PARAM;
894 BAIL_ON_WBC_ERROR(wbc_status);
900 wbc_status = wbcRequestResponse(cmd,
903 if (WBC_ERROR_IS_OK(wbc_status)) {
907 /* Take the response above and return it to the caller */
909 if (response.data.auth.nt_status != 0) {
911 wbc_status = wbc_create_error_info(&response,
913 BAIL_ON_WBC_ERROR(wbc_status);
919 wbc_status = wbc_create_password_policy_info(&response,
921 BAIL_ON_WBC_ERROR(wbc_status);
925 *reject_reason = response.data.auth.reject_reason;
928 wbc_status = WBC_ERR_PWD_CHANGE_FAILED;
929 BAIL_ON_WBC_ERROR(wbc_status);
935 /* Change a password for a user */
936 wbcErr wbcChangeUserPassword(const char *username,
937 const char *old_password,
938 const char *new_password)
940 wbcErr wbc_status = WBC_ERR_SUCCESS;
941 struct wbcChangePasswordParams params;
945 params.account_name = username;
946 params.level = WBC_CHANGE_PASSWORD_LEVEL_PLAIN;
947 params.old_password.plaintext = old_password;
948 params.new_password.plaintext = new_password;
950 wbc_status = wbcChangeUserPasswordEx(¶ms,
954 BAIL_ON_WBC_ERROR(wbc_status);
961 wbcErr wbcLogonUser(const struct wbcLogonUserParams *params,
962 struct wbcLogonUserInfo **info,
963 struct wbcAuthErrorInfo **error,
964 struct wbcUserPasswordPolicyInfo **policy)
966 wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
968 struct winbindd_request request;
969 struct winbindd_response response;
972 ZERO_STRUCT(request);
973 ZERO_STRUCT(response);
986 wbc_status = WBC_ERR_INVALID_PARAM;
987 BAIL_ON_WBC_ERROR(wbc_status);
990 if (!params->username) {
991 wbc_status = WBC_ERR_INVALID_PARAM;
992 BAIL_ON_WBC_ERROR(wbc_status);
995 if ((params->num_blobs > 0) && (params->blobs == NULL)) {
996 wbc_status = WBC_ERR_INVALID_PARAM;
997 BAIL_ON_WBC_ERROR(wbc_status);
999 if ((params->num_blobs == 0) && (params->blobs != NULL)) {
1000 wbc_status = WBC_ERR_INVALID_PARAM;
1001 BAIL_ON_WBC_ERROR(wbc_status);
1004 /* Initialize request */
1006 cmd = WINBINDD_PAM_AUTH;
1007 request.flags = WBFLAG_PAM_INFO3_TEXT |
1008 WBFLAG_PAM_USER_SESSION_KEY |
1011 if (!params->password) {
1012 wbc_status = WBC_ERR_INVALID_PARAM;
1013 BAIL_ON_WBC_ERROR(wbc_status);
1016 strncpy(request.data.auth.user,
1018 sizeof(request.data.auth.user)-1);
1020 strncpy(request.data.auth.pass,
1022 sizeof(request.data.auth.pass)-1);
1024 for (i=0; i<params->num_blobs; i++) {
1026 if (strcasecmp(params->blobs[i].name, "krb5_cc_type") == 0) {
1027 if (params->blobs[i].blob.data) {
1028 strncpy(request.data.auth.krb5_cc_type,
1029 (const char *)params->blobs[i].blob.data,
1030 sizeof(request.data.auth.krb5_cc_type) - 1);
1035 if (strcasecmp(params->blobs[i].name, "user_uid") == 0) {
1036 if (params->blobs[i].blob.data) {
1037 memcpy(&request.data.auth.uid,
1038 params->blobs[i].blob.data,
1039 MIN(sizeof(request.data.auth.uid),
1040 params->blobs[i].blob.length));
1045 if (strcasecmp(params->blobs[i].name, "flags") == 0) {
1046 if (params->blobs[i].blob.data) {
1049 params->blobs[i].blob.data,
1051 params->blobs[i].blob.length));
1052 request.flags |= flags;
1057 if (strcasecmp(params->blobs[i].name, "membership_of") == 0) {
1058 if (params->blobs[i].blob.data &&
1059 params->blobs[i].blob.data[0] > 0) {
1060 strncpy(request.data.auth.require_membership_of_sid,
1061 (const char *)params->blobs[i].blob.data,
1062 sizeof(request.data.auth.require_membership_of_sid) - 1);
1068 wbc_status = wbcRequestResponse(cmd,
1072 if (response.data.auth.nt_status != 0) {
1074 wbc_status = wbc_create_error_info(&response,
1076 BAIL_ON_WBC_ERROR(wbc_status);
1079 wbc_status = WBC_ERR_AUTH_ERROR;
1080 BAIL_ON_WBC_ERROR(wbc_status);
1082 BAIL_ON_WBC_ERROR(wbc_status);
1085 wbc_status = wbc_create_logon_info(&response,
1087 BAIL_ON_WBC_ERROR(wbc_status);
1091 wbc_status = wbc_create_password_policy_info(&response,
1093 BAIL_ON_WBC_ERROR(wbc_status);
1097 winbindd_free_response(&response);
1102 /* Authenticate a user with cached credentials */
1103 wbcErr wbcCredentialCache(struct wbcCredentialCacheParams *params,
1104 struct wbcCredentialCacheInfo **info,
1105 struct wbcAuthErrorInfo **error)
1107 wbcErr status = WBC_ERR_UNKNOWN_FAILURE;
1108 struct wbcCredentialCacheInfo *result = NULL;
1109 struct winbindd_request request;
1110 struct winbindd_response response;
1111 struct wbcNamedBlob *initial_blob = NULL;
1112 struct wbcNamedBlob *challenge_blob = NULL;
1115 ZERO_STRUCT(request);
1116 ZERO_STRUCT(response);
1121 if (error != NULL) {
1124 if ((params == NULL)
1125 || (params->account_name == NULL)
1126 || (params->level != WBC_CREDENTIAL_CACHE_LEVEL_NTLMSSP)) {
1127 status = WBC_ERR_INVALID_PARAM;
1131 if (params->domain_name != NULL) {
1132 status = wbcRequestResponse(WINBINDD_INFO, NULL, &response);
1133 if (!WBC_ERROR_IS_OK(status)) {
1136 snprintf(request.data.ccache_ntlm_auth.user,
1137 sizeof(request.data.ccache_ntlm_auth.user)-1,
1138 "%s%c%s", params->domain_name,
1139 response.data.info.winbind_separator,
1140 params->account_name);
1142 strncpy(request.data.ccache_ntlm_auth.user,
1143 params->account_name,
1144 sizeof(request.data.ccache_ntlm_auth.user)-1);
1146 request.data.ccache_ntlm_auth.uid = getuid();
1148 for (i=0; i<params->num_blobs; i++) {
1149 if (strcasecmp(params->blobs[i].name, "initial_blob") == 0) {
1150 initial_blob = ¶ms->blobs[i];
1153 if (strcasecmp(params->blobs[i].name, "challenge_blob") == 0) {
1154 challenge_blob = ¶ms->blobs[i];
1159 request.data.ccache_ntlm_auth.initial_blob_len = 0;
1160 request.data.ccache_ntlm_auth.challenge_blob_len = 0;
1161 request.extra_len = 0;
1163 if (initial_blob != NULL) {
1164 request.data.ccache_ntlm_auth.initial_blob_len =
1165 initial_blob->blob.length;
1166 request.extra_len += initial_blob->blob.length;
1168 if (challenge_blob != NULL) {
1169 request.data.ccache_ntlm_auth.challenge_blob_len =
1170 challenge_blob->blob.length;
1171 request.extra_len += challenge_blob->blob.length;
1174 if (request.extra_len != 0) {
1175 request.extra_data.data = talloc_array(
1176 NULL, char, request.extra_len);
1177 if (request.extra_data.data == NULL) {
1178 status = WBC_ERR_NO_MEMORY;
1182 if (initial_blob != NULL) {
1183 memcpy(request.extra_data.data,
1184 initial_blob->blob.data, initial_blob->blob.length);
1186 if (challenge_blob != NULL) {
1187 memcpy(request.extra_data.data
1188 + request.data.ccache_ntlm_auth.initial_blob_len,
1189 challenge_blob->blob.data,
1190 challenge_blob->blob.length);
1193 status = wbcRequestResponse(WINBINDD_CCACHE_NTLMAUTH, &request,
1195 if (!WBC_ERROR_IS_OK(status)) {
1199 result = talloc(NULL, struct wbcCredentialCacheInfo);
1200 if (result == NULL) {
1201 status = WBC_ERR_NO_MEMORY;
1204 result->num_blobs = 0;
1205 result->blobs = talloc(result, struct wbcNamedBlob);
1206 if (result->blobs == NULL) {
1207 status = WBC_ERR_NO_MEMORY;
1210 status = wbcAddNamedBlob(&result->num_blobs, &result->blobs,
1212 (uint8_t *)response.extra_data.data,
1213 response.data.ccache_ntlm_auth.auth_blob_len);
1214 if (!WBC_ERROR_IS_OK(status)) {
1217 status = wbcAddNamedBlob(
1218 &result->num_blobs, &result->blobs, "session_key", 0,
1219 response.data.ccache_ntlm_auth.session_key,
1220 sizeof(response.data.ccache_ntlm_auth.session_key));
1221 if (!WBC_ERROR_IS_OK(status)) {
1225 winbindd_free_response(&response);
1227 return WBC_ERR_SUCCESS;
1230 TALLOC_FREE(request.extra_data.data);
1231 winbindd_free_response(&response);
1232 talloc_free(result);
1236 /* Authenticate a user with cached credentials */
1237 wbcErr wbcCredentialSave(const char *user, const char *password)
1239 struct winbindd_request request;
1240 struct winbindd_response response;
1242 ZERO_STRUCT(request);
1243 ZERO_STRUCT(response);
1245 strncpy(request.data.ccache_save.user, user,
1246 sizeof(request.data.ccache_save.user)-1);
1247 strncpy(request.data.ccache_save.pass, password,
1248 sizeof(request.data.ccache_save.pass)-1);
1249 request.data.ccache_save.uid = getuid();
1251 return wbcRequestResponse(WINBINDD_CCACHE_SAVE, &request, &response);