3 Copyright Andrew Tridgell <tridge@samba.org> 2000
4 Copyright Tim Potter <tpot@samba.org> 2000
5 Copyright Andrew Bartlett <abartlet@samba.org> 2002
6 Copyright Guenther Deschner <gd@samba.org> 2005-2008
8 largely based on pam_userdb by Cristian Gafton <gafton@redhat.com> also
9 contains large slabs of code from pam_unix by Elliot Lee
10 <sopwith@redhat.com> (see copyright below for full details)
13 #include "pam_winbind.h"
15 enum pam_winbind_request_type
17 PAM_WINBIND_AUTHENTICATE
,
19 PAM_WINBIND_ACCT_MGMT
,
20 PAM_WINBIND_OPEN_SESSION
,
21 PAM_WINBIND_CLOSE_SESSION
,
22 PAM_WINBIND_CHAUTHTOK
,
26 static int wbc_error_to_pam_error(wbcErr status
)
31 case WBC_ERR_NOT_IMPLEMENTED
:
32 return PAM_SERVICE_ERR
;
33 case WBC_ERR_UNKNOWN_FAILURE
:
35 case WBC_ERR_NO_MEMORY
:
37 case WBC_ERR_INVALID_SID
:
38 case WBC_ERR_INVALID_PARAM
:
40 case WBC_ERR_WINBIND_NOT_AVAILABLE
:
41 return PAM_AUTHINFO_UNAVAIL
;
42 case WBC_ERR_DOMAIN_NOT_FOUND
:
43 return PAM_AUTHINFO_UNAVAIL
;
44 case WBC_ERR_INVALID_RESPONSE
:
46 case WBC_ERR_NSS_ERROR
:
47 return PAM_USER_UNKNOWN
;
48 case WBC_ERR_AUTH_ERROR
:
50 case WBC_ERR_UNKNOWN_USER
:
51 return PAM_USER_UNKNOWN
;
52 case WBC_ERR_UNKNOWN_GROUP
:
53 return PAM_USER_UNKNOWN
;
54 case WBC_ERR_PWD_CHANGE_FAILED
:
62 static const char *_pam_error_code_str(int err
)
68 return "PAM_OPEN_ERR";
70 return "PAM_SYMBOL_ERR";
72 return "PAM_SERVICE_ERR";
74 return "PAM_SYSTEM_ERR";
78 return "PAM_PERM_DENIED";
80 return "PAM_AUTH_ERR";
81 case PAM_CRED_INSUFFICIENT
:
82 return "PAM_CRED_INSUFFICIENT";
83 case PAM_AUTHINFO_UNAVAIL
:
84 return "PAM_AUTHINFO_UNAVAIL";
85 case PAM_USER_UNKNOWN
:
86 return "PAM_USER_UNKNOWN";
88 return "PAM_MAXTRIES";
89 case PAM_NEW_AUTHTOK_REQD
:
90 return "PAM_NEW_AUTHTOK_REQD";
91 case PAM_ACCT_EXPIRED
:
92 return "PAM_ACCT_EXPIRED";
94 return "PAM_SESSION_ERR";
95 case PAM_CRED_UNAVAIL
:
96 return "PAM_CRED_UNAVAIL";
97 case PAM_CRED_EXPIRED
:
98 return "PAM_CRED_EXPIRED";
100 return "PAM_CRED_ERR";
101 case PAM_NO_MODULE_DATA
:
102 return "PAM_NO_MODULE_DATA";
104 return "PAM_CONV_ERR";
105 case PAM_AUTHTOK_ERR
:
106 return "PAM_AUTHTOK_ERR";
107 case PAM_AUTHTOK_RECOVER_ERR
:
108 return "PAM_AUTHTOK_RECOVER_ERR";
109 case PAM_AUTHTOK_LOCK_BUSY
:
110 return "PAM_AUTHTOK_LOCK_BUSY";
111 case PAM_AUTHTOK_DISABLE_AGING
:
112 return "PAM_AUTHTOK_DISABLE_AGING";
114 return "PAM_TRY_AGAIN";
119 case PAM_AUTHTOK_EXPIRED
:
120 return "PAM_AUTHTOK_EXPIRED";
121 #ifdef PAM_MODULE_UNKNOWN
122 case PAM_MODULE_UNKNOWN
:
123 return "PAM_MODULE_UNKNOWN";
127 return "PAM_BAD_ITEM";
129 #ifdef PAM_CONV_AGAIN
131 return "PAM_CONV_AGAIN";
133 #ifdef PAM_INCOMPLETE
135 return "PAM_INCOMPLETE";
142 #define _PAM_LOG_FUNCTION_ENTER(function, ctx) \
144 _pam_log_debug(ctx, LOG_DEBUG, "[pamh: %p] ENTER: " \
145 function " (flags: 0x%04x)", ctx->pamh, ctx->flags); \
146 _pam_log_state(ctx); \
149 #define _PAM_LOG_FUNCTION_LEAVE(function, ctx, retval) \
151 _pam_log_debug(ctx, LOG_DEBUG, "[pamh: %p] LEAVE: " \
152 function " returning %d (%s)", ctx ? ctx->pamh : NULL, retval, \
153 _pam_error_code_str(retval)); \
154 _pam_log_state(ctx); \
159 #define MAX_PASSWD_TRIES 3
162 static char initialized
= 0;
164 static inline void textdomain_init(void);
165 static inline void textdomain_init(void)
168 bindtextdomain(MODULE_NAME
, LOCALEDIR
);
176 /* some syslogging */
177 static void _pam_log_int(const pam_handle_t
*pamh
,
180 va_list args
) PRINTF_ATTRIBUTE(3, 0);
182 #ifdef HAVE_PAM_VSYSLOG
183 static void _pam_log_int(const pam_handle_t
*pamh
,
188 pam_vsyslog(pamh
, err
, format
, args
);
191 static void _pam_log_int(const pam_handle_t
*pamh
,
201 va_copy(args2
, args
);
203 pam_get_item(pamh
, PAM_SERVICE
, (const void **) &service
);
205 ret
= vasprintf(&base
, format
, args
);
207 /* what else todo ? */
208 vsyslog(err
, format
, args2
);
213 syslog(err
, "%s(%s): %s", MODULE_NAME
, service
, base
);
217 #endif /* HAVE_PAM_VSYSLOG */
219 static bool _pam_log_is_silent(int ctrl
)
221 return on(ctrl
, WINBIND_SILENT
);
224 static void _pam_log(struct pwb_context
*r
, int err
, const char *format
, ...) PRINTF_ATTRIBUTE(3,4);
225 static void _pam_log(struct pwb_context
*r
, int err
, const char *format
, ...)
229 if (_pam_log_is_silent(r
->ctrl
)) {
233 va_start(args
, format
);
234 _pam_log_int(r
->pamh
, err
, format
, args
);
237 static void __pam_log(const pam_handle_t
*pamh
, int ctrl
, int err
, const char *format
, ...) PRINTF_ATTRIBUTE(4,5);
238 static void __pam_log(const pam_handle_t
*pamh
, int ctrl
, int err
, const char *format
, ...)
242 if (_pam_log_is_silent(ctrl
)) {
246 va_start(args
, format
);
247 _pam_log_int(pamh
, err
, format
, args
);
251 static bool _pam_log_is_debug_enabled(int ctrl
)
257 if (_pam_log_is_silent(ctrl
)) {
261 if (!(ctrl
& WINBIND_DEBUG_ARG
)) {
268 static bool _pam_log_is_debug_state_enabled(int ctrl
)
270 if (!(ctrl
& WINBIND_DEBUG_STATE
)) {
274 return _pam_log_is_debug_enabled(ctrl
);
277 static void _pam_log_debug(struct pwb_context
*r
, int err
, const char *format
, ...) PRINTF_ATTRIBUTE(3,4);
278 static void _pam_log_debug(struct pwb_context
*r
, int err
, const char *format
, ...)
282 if (!r
|| !_pam_log_is_debug_enabled(r
->ctrl
)) {
286 va_start(args
, format
);
287 _pam_log_int(r
->pamh
, err
, format
, args
);
290 static void __pam_log_debug(const pam_handle_t
*pamh
, int ctrl
, int err
, const char *format
, ...) PRINTF_ATTRIBUTE(4,5);
291 static void __pam_log_debug(const pam_handle_t
*pamh
, int ctrl
, int err
, const char *format
, ...)
295 if (!_pam_log_is_debug_enabled(ctrl
)) {
299 va_start(args
, format
);
300 _pam_log_int(pamh
, err
, format
, args
);
304 static void _pam_log_state_datum(struct pwb_context
*ctx
,
309 const void *data
= NULL
;
310 if (item_type
!= 0) {
311 pam_get_item(ctx
->pamh
, item_type
, &data
);
313 pam_get_data(ctx
->pamh
, key
, &data
);
316 const char *type
= (item_type
!= 0) ? "ITEM" : "DATA";
317 if (is_string
!= 0) {
318 _pam_log_debug(ctx
, LOG_DEBUG
,
319 "[pamh: %p] STATE: %s(%s) = \"%s\" (%p)",
320 ctx
->pamh
, type
, key
, (const char *)data
,
323 _pam_log_debug(ctx
, LOG_DEBUG
,
324 "[pamh: %p] STATE: %s(%s) = %p",
325 ctx
->pamh
, type
, key
, data
);
330 #define _PAM_LOG_STATE_DATA_POINTER(ctx, module_data_name) \
331 _pam_log_state_datum(ctx, 0, module_data_name, 0)
333 #define _PAM_LOG_STATE_DATA_STRING(ctx, module_data_name) \
334 _pam_log_state_datum(ctx, 0, module_data_name, 1)
336 #define _PAM_LOG_STATE_ITEM_POINTER(ctx, item_type) \
337 _pam_log_state_datum(ctx, item_type, #item_type, 0)
339 #define _PAM_LOG_STATE_ITEM_STRING(ctx, item_type) \
340 _pam_log_state_datum(ctx, item_type, #item_type, 1)
342 #ifdef DEBUG_PASSWORD
343 #define _LOG_PASSWORD_AS_STRING 1
345 #define _LOG_PASSWORD_AS_STRING 0
348 #define _PAM_LOG_STATE_ITEM_PASSWORD(ctx, item_type) \
349 _pam_log_state_datum(ctx, item_type, #item_type, \
350 _LOG_PASSWORD_AS_STRING)
352 * wrapper to preserve old behaviour of iniparser which ignored
353 * key values that had no value assigned like
355 * for a key like above newer iniparser will return a zero-length
356 * string, previously iniparser would return NULL
358 * JRA: For compatibility, tiniparser behaves like iniparser.
360 static const char *tiniparser_getstring_nonempty(struct tiniparser_dictionary
*d
,
364 const char *ret
= tiniparser_getstring(d
, key
, def
);
365 if (ret
&& strlen(ret
) == 0) {
371 static void _pam_log_state(struct pwb_context
*ctx
)
373 if (!ctx
|| !_pam_log_is_debug_state_enabled(ctx
->ctrl
)) {
377 _PAM_LOG_STATE_ITEM_STRING(ctx
, PAM_SERVICE
);
378 _PAM_LOG_STATE_ITEM_STRING(ctx
, PAM_USER
);
379 _PAM_LOG_STATE_ITEM_STRING(ctx
, PAM_TTY
);
380 _PAM_LOG_STATE_ITEM_STRING(ctx
, PAM_RHOST
);
381 _PAM_LOG_STATE_ITEM_STRING(ctx
, PAM_RUSER
);
382 _PAM_LOG_STATE_ITEM_PASSWORD(ctx
, PAM_OLDAUTHTOK
);
383 _PAM_LOG_STATE_ITEM_PASSWORD(ctx
, PAM_AUTHTOK
);
384 _PAM_LOG_STATE_ITEM_STRING(ctx
, PAM_USER_PROMPT
);
385 _PAM_LOG_STATE_ITEM_POINTER(ctx
, PAM_CONV
);
386 #ifdef PAM_FAIL_DELAY
387 _PAM_LOG_STATE_ITEM_POINTER(ctx
, PAM_FAIL_DELAY
);
389 #ifdef PAM_REPOSITORY
390 _PAM_LOG_STATE_ITEM_POINTER(ctx
, PAM_REPOSITORY
);
393 _PAM_LOG_STATE_DATA_STRING(ctx
, PAM_WINBIND_HOMEDIR
);
394 _PAM_LOG_STATE_DATA_STRING(ctx
, PAM_WINBIND_LOGONSCRIPT
);
395 _PAM_LOG_STATE_DATA_STRING(ctx
, PAM_WINBIND_LOGONSERVER
);
396 _PAM_LOG_STATE_DATA_STRING(ctx
, PAM_WINBIND_PROFILEPATH
);
397 _PAM_LOG_STATE_DATA_STRING(ctx
,
398 PAM_WINBIND_NEW_AUTHTOK_REQD
);
399 /* Use atoi to get PAM result code */
400 _PAM_LOG_STATE_DATA_STRING(ctx
,
401 PAM_WINBIND_NEW_AUTHTOK_REQD_DURING_AUTH
);
402 _PAM_LOG_STATE_DATA_POINTER(ctx
, PAM_WINBIND_PWD_LAST_SET
);
405 static int _pam_parse(const pam_handle_t
*pamh
,
409 enum pam_winbind_request_type type
,
410 struct tiniparser_dictionary
**result_d
)
413 const char *config_file
= NULL
;
416 struct tiniparser_dictionary
*d
= NULL
;
418 if (flags
& PAM_SILENT
) {
419 ctrl
|= WINBIND_SILENT
;
422 for (i
=argc
,v
=argv
; i
-- > 0; ++v
) {
423 if (!strncasecmp(*v
, "config", strlen("config"))) {
424 ctrl
|= WINBIND_CONFIG_FILE
;
430 if (config_file
== NULL
) {
431 config_file
= PAM_WINBIND_CONFIG_FILE
;
434 d
= tiniparser_load(config_file
);
436 goto config_from_pam
;
439 if (tiniparser_getboolean(d
, "global:debug", false)) {
440 ctrl
|= WINBIND_DEBUG_ARG
;
443 if (tiniparser_getboolean(d
, "global:debug_state", false)) {
444 ctrl
|= WINBIND_DEBUG_STATE
;
447 if (tiniparser_getboolean(d
, "global:cached_login", false)) {
448 ctrl
|= WINBIND_CACHED_LOGIN
;
451 if (tiniparser_getboolean(d
, "global:krb5_auth", false)) {
452 ctrl
|= WINBIND_KRB5_AUTH
;
455 if (tiniparser_getboolean(d
, "global:silent", false)) {
456 ctrl
|= WINBIND_SILENT
;
459 if (tiniparser_getstring_nonempty(d
, "global:krb5_ccache_type", NULL
) != NULL
) {
460 ctrl
|= WINBIND_KRB5_CCACHE_TYPE
;
463 if ((tiniparser_getstring_nonempty(d
, "global:require-membership-of", NULL
)
465 (tiniparser_getstring_nonempty(d
, "global:require_membership_of", NULL
)
467 ctrl
|= WINBIND_REQUIRED_MEMBERSHIP
;
470 if (tiniparser_getboolean(d
, "global:try_first_pass", false)) {
471 ctrl
|= WINBIND_TRY_FIRST_PASS_ARG
;
474 if (tiniparser_getint(d
, "global:warn_pwd_expire", 0)) {
475 ctrl
|= WINBIND_WARN_PWD_EXPIRE
;
478 if (tiniparser_getboolean(d
, "global:mkhomedir", false)) {
479 ctrl
|= WINBIND_MKHOMEDIR
;
482 if (tiniparser_getboolean(d
, "global:pwd_change_prompt", false)) {
483 ctrl
|= WINBIND_PWD_CHANGE_PROMPT
;
487 /* step through arguments */
488 for (i
=argc
,v
=argv
; i
-- > 0; ++v
) {
490 /* generic options */
491 if (!strcmp(*v
,"debug"))
492 ctrl
|= WINBIND_DEBUG_ARG
;
493 else if (!strcasecmp(*v
, "debug_state"))
494 ctrl
|= WINBIND_DEBUG_STATE
;
495 else if (!strcasecmp(*v
, "silent"))
496 ctrl
|= WINBIND_SILENT
;
497 else if (!strcasecmp(*v
, "use_authtok"))
498 ctrl
|= WINBIND_USE_AUTHTOK_ARG
;
499 else if (!strcasecmp(*v
, "try_authtok"))
500 ctrl
|= WINBIND_TRY_AUTHTOK_ARG
;
501 else if (!strcasecmp(*v
, "use_first_pass"))
502 ctrl
|= WINBIND_USE_FIRST_PASS_ARG
;
503 else if (!strcasecmp(*v
, "try_first_pass"))
504 ctrl
|= WINBIND_TRY_FIRST_PASS_ARG
;
505 else if (!strcasecmp(*v
, "unknown_ok"))
506 ctrl
|= WINBIND_UNKNOWN_OK_ARG
;
507 else if ((type
== PAM_WINBIND_AUTHENTICATE
508 || type
== PAM_WINBIND_SETCRED
)
509 && !strncasecmp(*v
, "require_membership_of",
510 strlen("require_membership_of")))
511 ctrl
|= WINBIND_REQUIRED_MEMBERSHIP
;
512 else if ((type
== PAM_WINBIND_AUTHENTICATE
513 || type
== PAM_WINBIND_SETCRED
)
514 && !strncasecmp(*v
, "require-membership-of",
515 strlen("require-membership-of")))
516 ctrl
|= WINBIND_REQUIRED_MEMBERSHIP
;
517 else if (!strcasecmp(*v
, "krb5_auth"))
518 ctrl
|= WINBIND_KRB5_AUTH
;
519 else if (!strncasecmp(*v
, "krb5_ccache_type",
520 strlen("krb5_ccache_type")))
521 ctrl
|= WINBIND_KRB5_CCACHE_TYPE
;
522 else if (!strcasecmp(*v
, "cached_login"))
523 ctrl
|= WINBIND_CACHED_LOGIN
;
524 else if (!strcasecmp(*v
, "mkhomedir"))
525 ctrl
|= WINBIND_MKHOMEDIR
;
526 else if (!strncasecmp(*v
, "warn_pwd_expire",
527 strlen("warn_pwd_expire")))
528 ctrl
|= WINBIND_WARN_PWD_EXPIRE
;
529 else if (!strcasecmp(*v
, "pwd_change_prompt"))
530 ctrl
|= WINBIND_PWD_CHANGE_PROMPT
;
531 else if (type
!= PAM_WINBIND_CLEANUP
) {
532 __pam_log(pamh
, ctrl
, LOG_ERR
,
533 "pam_parse: unknown option: %s", *v
);
543 tiniparser_freedict(d
);
550 static int _pam_winbind_free_context(struct pwb_context
*ctx
)
557 tiniparser_freedict(ctx
->dict
);
560 wbcCtxFree(ctx
->wbc_ctx
);
565 static int _pam_winbind_init_context(pam_handle_t
*pamh
,
569 enum pam_winbind_request_type type
,
570 struct pwb_context
**ctx_p
)
572 struct pwb_context
*r
= NULL
;
573 const char *service
= NULL
;
574 char service_name
[32] = {0};
581 r
= talloc_zero(NULL
, struct pwb_context
);
586 talloc_set_destructor(r
, _pam_winbind_free_context
);
592 ctrl_code
= _pam_parse(pamh
, flags
, argc
, argv
, type
, &r
->dict
);
593 if (ctrl_code
== -1) {
595 return PAM_SYSTEM_ERR
;
599 r
->wbc_ctx
= wbcCtxCreate();
600 if (r
->wbc_ctx
== NULL
) {
602 return PAM_SYSTEM_ERR
;
605 pam_get_item(pamh
, PAM_SERVICE
, (const void **)&service
);
607 snprintf(service_name
, sizeof(service_name
), "PAM_WINBIND[%s]", service
);
609 wbcSetClientProcessName(service_name
);
616 static void _pam_winbind_cleanup_func(pam_handle_t
*pamh
,
620 int ctrl
= _pam_parse(pamh
, 0, 0, NULL
, PAM_WINBIND_CLEANUP
, NULL
);
621 if (_pam_log_is_debug_state_enabled(ctrl
)) {
622 __pam_log_debug(pamh
, ctrl
, LOG_DEBUG
,
623 "[pamh: %p] CLEAN: cleaning up PAM data %p "
624 "(error_status = %d)", pamh
, data
,
631 static const struct ntstatus_errors
{
632 const char *ntstatus_string
;
633 const char *error_string
;
634 } ntstatus_errors
[] = {
637 {"NT_STATUS_BACKUP_CONTROLLER",
638 N_("No primary Domain Controller available")},
639 {"NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND",
640 N_("No domain controllers found")},
641 {"NT_STATUS_NO_LOGON_SERVERS",
642 N_("No logon servers")},
643 {"NT_STATUS_PWD_TOO_SHORT",
644 N_("Password too short")},
645 {"NT_STATUS_PWD_TOO_RECENT",
646 N_("The password was recently changed and cannot be changed again before %s")},
647 {"NT_STATUS_PWD_HISTORY_CONFLICT",
648 N_("Password is already in password history")},
649 {"NT_STATUS_PASSWORD_EXPIRED",
650 N_("Your password has expired")},
651 {"NT_STATUS_PASSWORD_MUST_CHANGE",
652 N_("You need to change your password now")},
653 {"NT_STATUS_INVALID_WORKSTATION",
654 N_("You are not allowed to logon from this workstation")},
655 {"NT_STATUS_INVALID_LOGON_HOURS",
656 N_("You are not allowed to logon at this time")},
657 {"NT_STATUS_ACCOUNT_EXPIRED",
658 N_("Your account has expired. "
659 "Please contact your System administrator")}, /* SCNR */
660 {"NT_STATUS_ACCOUNT_DISABLED",
661 N_("Your account is disabled. "
662 "Please contact your System administrator")}, /* SCNR */
663 {"NT_STATUS_ACCOUNT_LOCKED_OUT",
664 N_("Your account has been locked. "
665 "Please contact your System administrator")}, /* SCNR */
666 {"NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT",
667 N_("Invalid Trust Account")},
668 {"NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT",
669 N_("Invalid Trust Account")},
670 {"NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT",
671 N_("Invalid Trust Account")},
672 {"NT_STATUS_ACCESS_DENIED",
673 N_("Access is denied")},
677 static const char *_get_ntstatus_error_string(const char *nt_status_string
)
680 for (i
=0; ntstatus_errors
[i
].ntstatus_string
!= NULL
; i
++) {
681 if (!strcasecmp(ntstatus_errors
[i
].ntstatus_string
,
683 return _(ntstatus_errors
[i
].error_string
);
689 /* --- authentication management functions --- */
691 /* Attempt a conversation */
693 static int converse(const pam_handle_t
*pamh
,
695 const struct pam_message
**message
,
696 struct pam_response
**response
)
699 const struct pam_conv
*conv
;
701 retval
= pam_get_item(pamh
, PAM_CONV
, (const void **) &conv
);
702 if (retval
== PAM_SUCCESS
) {
703 retval
= conv
->conv(nargs
,
704 discard_const_p(const struct pam_message
*, message
),
705 response
, conv
->appdata_ptr
);
708 return retval
; /* propagate error status */
712 static int _make_remark(struct pwb_context
*ctx
,
716 int retval
= PAM_SUCCESS
;
718 const struct pam_message
*pmsg
[1];
719 struct pam_message msg
[1];
720 struct pam_response
*resp
;
722 if (ctx
->flags
& WINBIND_SILENT
) {
727 msg
[0].msg
= discard_const_p(char, text
);
728 msg
[0].msg_style
= type
;
731 retval
= converse(ctx
->pamh
, 1, pmsg
, &resp
);
734 _pam_drop_reply(resp
, 1);
739 static int _make_remark_v(struct pwb_context
*ctx
,
742 va_list args
) PRINTF_ATTRIBUTE(3, 0);
744 static int _make_remark_v(struct pwb_context
*ctx
,
752 ret
= vasprintf(&var
, format
, args
);
754 _pam_log(ctx
, LOG_ERR
, "memory allocation failure");
758 ret
= _make_remark(ctx
, type
, var
);
763 static int _make_remark_format(struct pwb_context
*ctx
, int type
, const char *format
, ...) PRINTF_ATTRIBUTE(3,4);
764 static int _make_remark_format(struct pwb_context
*ctx
, int type
, const char *format
, ...)
769 va_start(args
, format
);
770 ret
= _make_remark_v(ctx
, type
, format
, args
);
775 static int pam_winbind_request_log(struct pwb_context
*ctx
,
782 /* incorrect password */
783 _pam_log(ctx
, LOG_WARNING
, "user '%s' denied access "
784 "(incorrect password or invalid membership)", user
);
786 case PAM_ACCT_EXPIRED
:
787 /* account expired */
788 _pam_log(ctx
, LOG_WARNING
, "user '%s' account expired",
791 case PAM_AUTHTOK_EXPIRED
:
792 /* password expired */
793 _pam_log(ctx
, LOG_WARNING
, "user '%s' password expired",
796 case PAM_NEW_AUTHTOK_REQD
:
797 /* new password required */
798 _pam_log(ctx
, LOG_WARNING
, "user '%s' new password "
801 case PAM_USER_UNKNOWN
:
802 /* the user does not exist */
803 _pam_log_debug(ctx
, LOG_NOTICE
, "user '%s' not found",
805 if (ctx
->ctrl
& WINBIND_UNKNOWN_OK_ARG
) {
809 case PAM_AUTHTOK_ERR
:
810 /* Authentication token manipulation error */
811 _pam_log(ctx
, LOG_WARNING
, "user `%s' authentication token change failed "
812 "(pwd complexity/history/min_age not met?)", user
);
815 /* Otherwise, the authentication looked good */
816 if (strcmp(fn
, "wbcLogonUser") == 0) {
817 _pam_log(ctx
, LOG_NOTICE
,
818 "user '%s' granted access", user
);
820 _pam_log(ctx
, LOG_NOTICE
,
821 "user '%s' OK", user
);
825 /* we don't know anything about this return value */
826 _pam_log(ctx
, LOG_ERR
,
827 "internal module error (retval = %s(%d), user = '%s')",
828 _pam_error_code_str(retval
), retval
, user
);
833 static int wbc_auth_error_to_pam_error(struct pwb_context
*ctx
,
834 struct wbcAuthErrorInfo
*e
,
836 const char *username
,
839 int ret
= PAM_AUTH_ERR
;
841 if (WBC_ERROR_IS_OK(status
)) {
842 _pam_log_debug(ctx
, LOG_DEBUG
, "request %s succeeded",
845 return pam_winbind_request_log(ctx
, ret
, username
, fn
);
849 if (e
->pam_error
!= PAM_SUCCESS
) {
850 _pam_log(ctx
, LOG_ERR
,
851 "request %s failed: %s, "
852 "PAM error: %s (%d), NTSTATUS: %s, "
853 "Error message was: %s",
855 wbcErrorString(status
),
856 _pam_error_code_str(e
->pam_error
),
861 return pam_winbind_request_log(ctx
, ret
, username
, fn
);
864 _pam_log(ctx
, LOG_ERR
, "request %s failed, but PAM error 0!", fn
);
866 ret
= PAM_SERVICE_ERR
;
867 return pam_winbind_request_log(ctx
, ret
, username
, fn
);
870 ret
= wbc_error_to_pam_error(status
);
871 _pam_log(ctx
, LOG_ERR
,
872 "request %s failed: %s, PAM error: %s (%d)!",
873 fn
, wbcErrorString(status
),
874 _pam_error_code_str(ret
), ret
);
875 return pam_winbind_request_log(ctx
, ret
, username
, fn
);
878 #if defined(HAVE_PAM_RADIO_TYPE)
879 static bool _pam_winbind_change_pwd(struct pwb_context
*ctx
)
881 struct pam_message msg
;
882 const struct pam_message
*pmsg
;
883 struct pam_response
*resp
= NULL
;
887 msg
.msg_style
= PAM_RADIO_TYPE
;
888 msg
.msg
= _("Do you want to change your password now?");
889 ret
= converse(ctx
->pamh
, 1, &pmsg
, &resp
);
891 if (ret
== PAM_SUCCESS
) {
892 _pam_log(ctx
, LOG_CRIT
, "pam_winbind: system error!\n");
896 if (ret
!= PAM_SUCCESS
) {
899 _pam_log(ctx
, LOG_CRIT
, "Received [%s] reply from application.\n", resp
->resp
);
901 if ((resp
->resp
!= NULL
) && (strcasecmp(resp
->resp
, "yes") == 0)) {
905 _pam_drop_reply(resp
, 1);
909 static bool _pam_winbind_change_pwd(struct pwb_context
*ctx
)
916 * send a password expiry message if required
918 * @param ctx PAM winbind context.
919 * @param next_change expected (calculated) next expiry date.
920 * @param already_expired pointer to a boolean to indicate if the password is
923 * @return boolean Returns true if message has been sent, false if not.
926 static bool _pam_send_password_expiry_message(struct pwb_context
*ctx
,
930 bool *already_expired
,
934 struct tm tm_now
, tm_next_change
;
938 if (already_expired
) {
939 *already_expired
= false;
946 if (next_change
<= now
) {
947 PAM_WB_REMARK_DIRECT(ctx
, "NT_STATUS_PASSWORD_EXPIRED");
948 if (already_expired
) {
949 *already_expired
= true;
954 if ((next_change
< 0) ||
955 (next_change
> now
+ warn_pwd_expire
* SECONDS_PER_DAY
)) {
959 if ((localtime_r(&now
, &tm_now
) == NULL
) ||
960 (localtime_r(&next_change
, &tm_next_change
) == NULL
)) {
964 days
= (tm_next_change
.tm_yday
+tm_next_change
.tm_year
*365) -
965 (tm_now
.tm_yday
+tm_now
.tm_year
*365);
968 ret
= _make_remark(ctx
, PAM_TEXT_INFO
,
969 _("Your password expires today.\n"));
972 * If change_pwd and already_expired is null.
973 * We are just sending a notification message.
974 * We don't expect any response in this case.
977 if (!change_pwd
&& !already_expired
) {
982 * successfully sent the warning message.
983 * Give the user a chance to change pwd.
985 if (ret
== PAM_SUCCESS
&&
986 (ctx
->ctrl
& WINBIND_PWD_CHANGE_PROMPT
)) {
988 retval
= _pam_winbind_change_pwd(ctx
);
997 if (days
> 0 && days
< warn_pwd_expire
) {
999 ret
= _make_remark_format(ctx
, PAM_TEXT_INFO
,
1000 _("Your password will expire in %d %s.\n"),
1001 days
, (days
> 1) ? _("days"):_("day"));
1003 * If change_pwd and already_expired is null.
1004 * We are just sending a notification message.
1005 * We don't expect any response in this case.
1008 if (!change_pwd
&& !already_expired
) {
1013 * successfully sent the warning message.
1014 * Give the user a chance to change pwd.
1016 if (ret
== PAM_SUCCESS
&&
1017 (ctx
->ctrl
& WINBIND_PWD_CHANGE_PROMPT
)) {
1019 retval
= _pam_winbind_change_pwd(ctx
);
1032 * Send a warning if the password expires in the near future
1034 * @param ctx PAM winbind context.
1035 * @param response The full authentication response structure.
1036 * @param already_expired boolean, is the pwd already expired?
1041 static void _pam_warn_password_expiry(struct pwb_context
*ctx
,
1042 const struct wbcAuthUserInfo
*info
,
1043 int warn_pwd_expire
,
1044 bool *already_expired
,
1047 time_t now
= time(NULL
);
1048 time_t next_change
= 0;
1054 if (already_expired
) {
1055 *already_expired
= false;
1059 *change_pwd
= false;
1062 /* accounts with WBC_ACB_PWNOEXP set never receive a warning */
1063 if (info
->acct_flags
& WBC_ACB_PWNOEXP
) {
1067 /* no point in sending a warning if this is a grace logon */
1068 if (PAM_WB_GRACE_LOGON(info
->user_flags
)) {
1072 /* check if the info3 must change timestamp has been set */
1073 next_change
= info
->pass_must_change_time
;
1075 if (_pam_send_password_expiry_message(ctx
, next_change
, now
,
1082 /* no warning sent */
1085 #define IS_SID_STRING(name) (strncmp("S-", name, 2) == 0)
1088 * Append a string, making sure not to overflow and to always return a
1089 * NULL-terminated string.
1091 * @param dest Destination string buffer (must already be NULL-terminated).
1092 * @param src Source string buffer.
1093 * @param dest_buffer_size Size of dest buffer in bytes.
1095 * @return false if dest buffer is not big enough (no bytes copied), true on
1099 static bool safe_append_string(char *dest
,
1101 int dest_buffer_size
)
1104 len
= strlcat(dest
, src
, dest_buffer_size
);
1105 return (len
< dest_buffer_size
);
1109 * Convert a names into a SID string, appending it to a buffer.
1111 * @param ctx PAM winbind context.
1112 * @param user User in PAM request.
1113 * @param name Name to convert.
1114 * @param sid_list_buffer Where to append the string sid.
1115 * @param sid_list_buffer Size of sid_list_buffer (in bytes).
1117 * @return false on failure, true on success.
1119 static bool winbind_name_to_sid_string(struct pwb_context
*ctx
,
1122 char *sid_list_buffer
,
1123 int sid_list_buffer_size
)
1125 char sid_string
[WBC_SID_STRING_BUFLEN
];
1128 if (IS_SID_STRING(name
)) {
1129 strlcpy(sid_string
, name
, sizeof(sid_string
));
1132 struct wbcDomainSid sid
;
1133 enum wbcSidType type
;
1135 _pam_log_debug(ctx
, LOG_DEBUG
,
1136 "no sid given, looking up: %s\n", name
);
1138 wbc_status
= wbcCtxLookupName(ctx
->wbc_ctx
,
1143 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1144 _pam_log(ctx
, LOG_INFO
,
1145 "could not lookup name: %s\n", name
);
1149 wbcSidToStringBuf(&sid
, sid_string
, sizeof(sid_string
));
1152 if (!safe_append_string(sid_list_buffer
, sid_string
,
1153 sid_list_buffer_size
)) {
1160 * Convert a list of names into a list of sids.
1162 * @param ctx PAM winbind context.
1163 * @param user User in PAM request.
1164 * @param name_list List of names or string sids, separated by commas.
1165 * @param sid_list_buffer Where to put the list of string sids.
1166 * @param sid_list_buffer Size of sid_list_buffer (in bytes).
1168 * @return false on failure, true on success.
1170 static bool winbind_name_list_to_sid_string_list(struct pwb_context
*ctx
,
1172 const char *name_list
,
1173 char *sid_list_buffer
,
1174 int sid_list_buffer_size
)
1176 bool result
= false;
1177 char *current_name
= NULL
;
1178 const char *search_location
;
1182 if (sid_list_buffer_size
> 0) {
1183 sid_list_buffer
[0] = 0;
1186 search_location
= name_list
;
1187 while ((comma
= strchr(search_location
, ',')) != NULL
) {
1188 current_name
= strndup(search_location
,
1189 comma
- search_location
);
1190 if (NULL
== current_name
) {
1194 if (!winbind_name_to_sid_string(ctx
, user
,
1197 sid_list_buffer_size
)) {
1199 * If one group name failed, we must not fail
1200 * the authentication totally, continue with
1201 * the following group names. If user belongs to
1202 * one of the valid groups, we must allow it
1206 _pam_log(ctx
, LOG_INFO
, "cannot convert group %s to sid, "
1207 "check if group %s is valid group.", current_name
,
1209 _make_remark_format(ctx
, PAM_TEXT_INFO
, _("Cannot convert group %s "
1210 "to sid, please contact your administrator to see "
1211 "if group %s is valid."), current_name
, current_name
);
1212 SAFE_FREE(current_name
);
1213 search_location
= comma
+ 1;
1217 SAFE_FREE(current_name
);
1219 if (!safe_append_string(sid_list_buffer
, ",",
1220 sid_list_buffer_size
)) {
1224 search_location
= comma
+ 1;
1227 if (!winbind_name_to_sid_string(ctx
, user
, search_location
,
1229 sid_list_buffer_size
)) {
1230 _pam_log(ctx
, LOG_INFO
, "cannot convert group %s to sid, "
1231 "check if group %s is valid group.", search_location
,
1233 _make_remark_format(ctx
, PAM_TEXT_INFO
, _("Cannot convert group %s "
1234 "to sid, please contact your administrator to see "
1235 "if group %s is valid."), search_location
, search_location
);
1237 /* If no valid groups were converted we should fail outright */
1238 if (name_list
!= NULL
&& strlen(sid_list_buffer
) == 0) {
1243 * The lookup of the last name failed..
1244 * It results in require_member_of_sid ends with ','
1245 * It is malformatted parameter here, overwrite the last ','.
1247 len
= strlen(sid_list_buffer
);
1248 if ((len
!= 0) && (sid_list_buffer
[len
- 1] == ',')) {
1249 sid_list_buffer
[len
- 1] = '\0';
1256 SAFE_FREE(current_name
);
1261 * put krb5ccname variable into environment
1263 * @param ctx PAM winbind context.
1264 * @param krb5ccname env variable retrieved from winbindd.
1269 static void _pam_setup_krb5_env(struct pwb_context
*ctx
,
1270 struct wbcLogonUserInfo
*info
)
1275 const char *krb5ccname
= NULL
;
1277 if (off(ctx
->ctrl
, WINBIND_KRB5_AUTH
)) {
1285 for (i
=0; i
< info
->num_blobs
; i
++) {
1286 if (strcasecmp(info
->blobs
[i
].name
, "krb5ccname") == 0) {
1287 krb5ccname
= (const char *)info
->blobs
[i
].blob
.data
;
1292 if (!krb5ccname
|| (strlen(krb5ccname
) == 0)) {
1296 _pam_log_debug(ctx
, LOG_DEBUG
,
1297 "request returned KRB5CCNAME: %s", krb5ccname
);
1299 if (asprintf(&var
, "KRB5CCNAME=%s", krb5ccname
) == -1) {
1303 ret
= pam_putenv(ctx
->pamh
, var
);
1304 if (ret
!= PAM_SUCCESS
) {
1305 _pam_log(ctx
, LOG_ERR
,
1306 "failed to set KRB5CCNAME to %s: %s",
1307 var
, pam_strerror(ctx
->pamh
, ret
));
1313 * Copy unix username if available (further processed in PAM).
1315 * @param ctx PAM winbind context
1316 * @param user_ret A pointer that holds a pointer to a string
1317 * @param unix_username A username
1322 static void _pam_setup_unix_username(struct pwb_context
*ctx
,
1324 struct wbcLogonUserInfo
*info
)
1326 const char *unix_username
= NULL
;
1329 if (!user_ret
|| !info
) {
1333 for (i
=0; i
< info
->num_blobs
; i
++) {
1334 if (strcasecmp(info
->blobs
[i
].name
, "unix_username") == 0) {
1335 unix_username
= (const char *)info
->blobs
[i
].blob
.data
;
1340 if (!unix_username
|| !unix_username
[0]) {
1344 *user_ret
= strdup(unix_username
);
1348 * Set string into the PAM stack.
1350 * @param ctx PAM winbind context.
1351 * @param data_name Key name for pam_set_data.
1352 * @param value String value.
1357 static void _pam_set_data_string(struct pwb_context
*ctx
,
1358 const char *data_name
,
1363 if (!data_name
|| !value
|| (strlen(data_name
) == 0) ||
1364 (strlen(value
) == 0)) {
1368 ret
= pam_set_data(ctx
->pamh
, data_name
, talloc_strdup(NULL
, value
),
1369 _pam_winbind_cleanup_func
);
1370 if (ret
!= PAM_SUCCESS
) {
1371 _pam_log_debug(ctx
, LOG_DEBUG
,
1372 "Could not set data %s: %s\n",
1373 data_name
, pam_strerror(ctx
->pamh
, ret
));
1378 * Set info3 strings into the PAM stack.
1380 * @param ctx PAM winbind context.
1381 * @param data_name Key name for pam_set_data.
1382 * @param value String value.
1387 static void _pam_set_data_info3(struct pwb_context
*ctx
,
1388 const struct wbcAuthUserInfo
*info
)
1391 _pam_set_data_string(ctx
, PAM_WINBIND_HOMEDIR
,
1392 info
->home_directory
);
1393 _pam_set_data_string(ctx
, PAM_WINBIND_LOGONSCRIPT
,
1394 info
->logon_script
);
1395 _pam_set_data_string(ctx
, PAM_WINBIND_LOGONSERVER
,
1396 info
->logon_server
);
1397 _pam_set_data_string(ctx
, PAM_WINBIND_PROFILEPATH
,
1398 info
->profile_path
);
1403 * Free info3 strings in the PAM stack.
1405 * @param pamh PAM handle
1410 static void _pam_free_data_info3(pam_handle_t
*pamh
)
1412 pam_set_data(pamh
, PAM_WINBIND_HOMEDIR
, NULL
, NULL
);
1413 pam_set_data(pamh
, PAM_WINBIND_LOGONSCRIPT
, NULL
, NULL
);
1414 pam_set_data(pamh
, PAM_WINBIND_LOGONSERVER
, NULL
, NULL
);
1415 pam_set_data(pamh
, PAM_WINBIND_PROFILEPATH
, NULL
, NULL
);
1419 * Send PAM_ERROR_MSG for cached or grace logons.
1421 * @param ctx PAM winbind context.
1422 * @param username User in PAM request.
1423 * @param info3_user_flgs Info3 flags containing logon type bits.
1428 static void _pam_warn_logon_type(struct pwb_context
*ctx
,
1429 const char *username
,
1430 uint32_t info3_user_flgs
)
1432 /* inform about logon type */
1433 if (PAM_WB_GRACE_LOGON(info3_user_flgs
)) {
1435 _make_remark(ctx
, PAM_ERROR_MSG
,
1437 "Please change your password as soon you're "
1439 _pam_log_debug(ctx
, LOG_DEBUG
,
1440 "User %s logged on using grace logon\n",
1443 } else if (PAM_WB_CACHED_LOGON(info3_user_flgs
)) {
1445 _make_remark(ctx
, PAM_ERROR_MSG
,
1446 _("Domain Controller unreachable, "
1447 "using cached credentials instead. "
1448 "Network resources may be unavailable"));
1449 _pam_log_debug(ctx
, LOG_DEBUG
,
1450 "User %s logged on using cached credentials\n",
1456 * Send PAM_ERROR_MSG for krb5 errors.
1458 * @param ctx PAM winbind context.
1459 * @param username User in PAM request.
1460 * @param info3_user_flgs Info3 flags containing logon type bits.
1465 static void _pam_warn_krb5_failure(struct pwb_context
*ctx
,
1466 const char *username
,
1467 uint32_t info3_user_flgs
)
1469 if (PAM_WB_KRB5_CLOCK_SKEW(info3_user_flgs
)) {
1470 _make_remark(ctx
, PAM_ERROR_MSG
,
1471 _("Failed to establish your Kerberos Ticket cache "
1472 "due time differences\n"
1473 "with the domain controller. "
1474 "Please verify the system time.\n"));
1475 _pam_log_debug(ctx
, LOG_DEBUG
,
1476 "User %s: Clock skew when getting Krb5 TGT\n",
1481 static bool _pam_check_remark_auth_err(struct pwb_context
*ctx
,
1482 const struct wbcAuthErrorInfo
*e
,
1483 const char *nt_status_string
,
1486 const char *ntstatus
= NULL
;
1487 const char *error_string
= NULL
;
1489 if (!e
|| !pam_err
) {
1493 ntstatus
= e
->nt_string
;
1498 if (strcasecmp(ntstatus
, nt_status_string
) == 0) {
1500 error_string
= _get_ntstatus_error_string(nt_status_string
);
1502 _make_remark(ctx
, PAM_ERROR_MSG
, error_string
);
1503 *pam_err
= e
->pam_error
;
1507 if (e
->display_string
) {
1508 _make_remark(ctx
, PAM_ERROR_MSG
, _(e
->display_string
));
1509 *pam_err
= e
->pam_error
;
1513 _make_remark(ctx
, PAM_ERROR_MSG
, nt_status_string
);
1514 *pam_err
= e
->pam_error
;
1523 * Compose Password Restriction String for a PAM_ERROR_MSG conversation.
1525 * @param i The wbcUserPasswordPolicyInfo struct.
1527 * @return string (caller needs to talloc_free).
1530 static char *_pam_compose_pwd_restriction_string(struct pwb_context
*ctx
,
1531 struct wbcUserPasswordPolicyInfo
*i
)
1539 str
= talloc_asprintf(ctx
, _("Your password "));
1544 if (i
->min_length_password
> 0) {
1545 str
= talloc_asprintf_append(str
,
1546 _("must be at least %d characters; "),
1547 i
->min_length_password
);
1553 if (i
->password_history
> 0) {
1554 str
= talloc_asprintf_append(str
,
1555 _("cannot repeat any of your previous %d "
1557 i
->password_history
);
1563 if (i
->password_properties
& WBC_DOMAIN_PASSWORD_COMPLEX
) {
1564 str
= talloc_asprintf_append(str
,
1565 _("must contain capitals, numerals "
1567 "and cannot contain your account "
1574 str
= talloc_asprintf_append(str
,
1575 _("Please type a different password. "
1576 "Type a password which meets these requirements in "
1577 "both text boxes."));
1589 static int _pam_create_homedir(struct pwb_context
*ctx
,
1590 const char *dirname
,
1595 ret
= mkdir(dirname
, mode
);
1596 if (ret
!= 0 && errno
== EEXIST
) {
1599 ret
= stat(dirname
, &sbuf
);
1601 return PAM_PERM_DENIED
;
1604 if (!S_ISDIR(sbuf
.st_mode
)) {
1605 return PAM_PERM_DENIED
;
1610 _make_remark_format(ctx
, PAM_TEXT_INFO
,
1611 _("Creating directory: %s failed: %s"),
1612 dirname
, strerror(errno
));
1613 _pam_log(ctx
, LOG_ERR
, "could not create dir: %s (%s)",
1614 dirname
, strerror(errno
));
1615 return PAM_PERM_DENIED
;
1621 static int _pam_chown_homedir(struct pwb_context
*ctx
,
1622 const char *dirname
,
1626 if (chown(dirname
, uid
, gid
) != 0) {
1627 _pam_log(ctx
, LOG_ERR
, "failed to chown user homedir: %s (%s)",
1628 dirname
, strerror(errno
));
1629 return PAM_PERM_DENIED
;
1635 static int _pam_mkhomedir(struct pwb_context
*ctx
)
1637 struct passwd
*pwd
= NULL
;
1639 char *create_dir
= NULL
;
1640 char *user_dir
= NULL
;
1642 const char *username
;
1644 char *safe_ptr
= NULL
;
1647 /* Get the username */
1648 ret
= pam_get_user(ctx
->pamh
, &username
, NULL
);
1649 if ((ret
!= PAM_SUCCESS
) || (!username
)) {
1650 _pam_log_debug(ctx
, LOG_DEBUG
, "can not get the username");
1651 return PAM_SERVICE_ERR
;
1654 pwd
= getpwnam(username
);
1656 _pam_log_debug(ctx
, LOG_DEBUG
, "can not get the username");
1657 return PAM_USER_UNKNOWN
;
1659 _pam_log_debug(ctx
, LOG_DEBUG
, "homedir is: %s", pwd
->pw_dir
);
1661 ret
= _pam_create_homedir(ctx
, pwd
->pw_dir
, 0700);
1662 if (ret
== PAM_SUCCESS
) {
1663 ret
= _pam_chown_homedir(ctx
, pwd
->pw_dir
,
1668 if (ret
== PAM_SUCCESS
) {
1672 /* maybe we need to create parent dirs */
1673 create_dir
= talloc_strdup(ctx
, "/");
1678 /* find final directory */
1679 user_dir
= strrchr(pwd
->pw_dir
, '/');
1685 _pam_log(ctx
, LOG_DEBUG
, "final directory: %s", user_dir
);
1689 while ((token
= strtok_r(p
, "/", &safe_ptr
)) != NULL
) {
1695 _pam_log_debug(ctx
, LOG_DEBUG
, "token is %s", token
);
1697 create_dir
= talloc_asprintf_append(create_dir
, "%s/", token
);
1701 _pam_log_debug(ctx
, LOG_DEBUG
, "current_dir is %s", create_dir
);
1703 if (strcmp(token
, user_dir
) == 0) {
1704 _pam_log_debug(ctx
, LOG_DEBUG
, "assuming last directory: %s", token
);
1708 ret
= _pam_create_homedir(ctx
, create_dir
, mode
);
1709 if (ret
!= PAM_SUCCESS
) {
1714 return _pam_chown_homedir(ctx
, create_dir
,
1719 /* talk to winbindd */
1720 static int winbind_auth_request(struct pwb_context
*ctx
,
1725 const int warn_pwd_expire
,
1726 struct wbcAuthErrorInfo
**p_error
,
1727 struct wbcLogonUserInfo
**p_info
,
1728 time_t *pwd_last_set
,
1732 struct wbcLogonUserParams logon
;
1733 char membership_of
[1024];
1734 uid_t user_uid
= -1;
1735 uint32_t flags
= WBFLAG_PAM_INFO3_TEXT
;
1736 struct wbcLogonUserInfo
*info
= NULL
;
1737 struct wbcAuthUserInfo
*user_info
= NULL
;
1738 struct wbcAuthErrorInfo
*error
= NULL
;
1739 int ret
= PAM_AUTH_ERR
;
1741 const char *codes
[] = {
1742 "NT_STATUS_PASSWORD_EXPIRED",
1743 "NT_STATUS_PASSWORD_MUST_CHANGE",
1744 "NT_STATUS_INVALID_WORKSTATION",
1745 "NT_STATUS_INVALID_LOGON_HOURS",
1746 "NT_STATUS_ACCOUNT_EXPIRED",
1747 "NT_STATUS_ACCOUNT_DISABLED",
1748 "NT_STATUS_ACCOUNT_LOCKED_OUT",
1749 "NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT",
1750 "NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT",
1751 "NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT",
1752 "NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND",
1753 "NT_STATUS_NO_LOGON_SERVERS",
1754 "NT_STATUS_WRONG_PASSWORD",
1755 "NT_STATUS_ACCESS_DENIED"
1762 /* Krb5 auth always has to go against the KDC of the user's realm */
1764 if (ctx
->ctrl
& WINBIND_KRB5_AUTH
) {
1765 flags
|= WBFLAG_PAM_CONTACT_TRUSTDOM
;
1768 if (ctx
->ctrl
& (WINBIND_KRB5_AUTH
|WINBIND_CACHED_LOGIN
)) {
1769 struct passwd
*pwd
= NULL
;
1771 pwd
= getpwnam(user
);
1773 return PAM_USER_UNKNOWN
;
1775 user_uid
= pwd
->pw_uid
;
1778 if (ctx
->ctrl
& WINBIND_KRB5_AUTH
) {
1780 _pam_log_debug(ctx
, LOG_DEBUG
,
1781 "enabling krb5 login flag\n");
1783 flags
|= WBFLAG_PAM_KRB5
|
1784 WBFLAG_PAM_FALLBACK_AFTER_KRB5
;
1787 if (ctx
->ctrl
& WINBIND_CACHED_LOGIN
) {
1788 _pam_log_debug(ctx
, LOG_DEBUG
,
1789 "enabling cached login flag\n");
1790 flags
|= WBFLAG_PAM_CACHED_LOGIN
;
1795 flags
|= WBFLAG_PAM_UNIX_NAME
;
1798 if (cctype
!= NULL
) {
1799 _pam_log_debug(ctx
, LOG_DEBUG
,
1800 "enabling request for a %s krb5 ccache\n",
1804 if (member
!= NULL
) {
1806 ZERO_STRUCT(membership_of
);
1808 if (!winbind_name_list_to_sid_string_list(ctx
, user
, member
,
1810 sizeof(membership_of
))) {
1811 _pam_log_debug(ctx
, LOG_ERR
,
1812 "failed to serialize membership of sid "
1813 "\"%s\"\n", member
);
1814 return PAM_AUTH_ERR
;
1820 logon
.username
= user
;
1821 logon
.password
= pass
;
1824 wbc_status
= wbcAddNamedBlob(&logon
.num_blobs
,
1828 discard_const_p(uint8_t, cctype
),
1830 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1835 wbc_status
= wbcAddNamedBlob(&logon
.num_blobs
,
1841 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1845 wbc_status
= wbcAddNamedBlob(&logon
.num_blobs
,
1849 (uint8_t *)&user_uid
,
1851 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1856 wbc_status
= wbcAddNamedBlob(&logon
.num_blobs
,
1860 (uint8_t *)membership_of
,
1861 sizeof(membership_of
));
1862 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1867 wbc_status
= wbcCtxLogonUser(ctx
->wbc_ctx
,
1872 ret
= wbc_auth_error_to_pam_error(ctx
, error
, wbc_status
,
1873 user
, "wbcLogonUser");
1874 wbcFreeMemory(logon
.blobs
);
1877 if (info
&& info
->info
) {
1878 user_info
= info
->info
;
1881 if (pwd_last_set
&& user_info
) {
1882 *pwd_last_set
= user_info
->pass_last_set_time
;
1885 if (p_info
&& info
) {
1889 if (p_error
&& error
) {
1890 /* We want to process the error in the caller. */
1895 for (i
=0; i
<ARRAY_SIZE(codes
); i
++) {
1897 if (_pam_check_remark_auth_err(ctx
, error
, codes
[i
], &_ret
)) {
1903 if ((ret
== PAM_SUCCESS
) && user_info
&& info
) {
1905 bool already_expired
= false;
1906 bool change_pwd
= false;
1908 /* warn a user if the password is about to expire soon */
1909 _pam_warn_password_expiry(ctx
, user_info
,
1914 if (already_expired
== true) {
1916 SMB_TIME_T last_set
= user_info
->pass_last_set_time
;
1917 SMB_TIME_T must_set
= user_info
->pass_must_change_time
;
1919 _pam_log_debug(ctx
, LOG_DEBUG
,
1920 "Password has expired "
1921 "(Password was last set: %lld, "
1922 "it must be changed here "
1923 "%lld (now it's: %ld))\n",
1924 (long long int)last_set
,
1925 (long long int)must_set
,
1928 return PAM_AUTHTOK_EXPIRED
;
1932 ret
= PAM_NEW_AUTHTOK_REQD
;
1936 /* inform about logon type */
1937 _pam_warn_logon_type(ctx
, user
, user_info
->user_flags
);
1939 /* inform about krb5 failures */
1940 _pam_warn_krb5_failure(ctx
, user
, user_info
->user_flags
);
1942 /* set some info3 info for other modules in the stack */
1943 _pam_set_data_info3(ctx
, user_info
);
1945 /* put krb5ccname into env */
1946 _pam_setup_krb5_env(ctx
, info
);
1948 /* If winbindd returned a username, return the pointer to it
1950 _pam_setup_unix_username(ctx
, user_ret
, info
);
1954 wbcFreeMemory(logon
.blobs
);
1955 if (info
&& info
->blobs
&& !p_info
) {
1956 wbcFreeMemory(info
->blobs
);
1958 * We set blobs to NULL to prevent a use after free in the
1959 * in the wbcLogonUserInfoDestructor
1963 if (error
&& !p_error
) {
1964 wbcFreeMemory(error
);
1966 if (info
&& !p_info
) {
1967 wbcFreeMemory(info
);
1973 /* talk to winbindd */
1974 static int winbind_chauthtok_request(struct pwb_context
*ctx
,
1976 const char *oldpass
,
1977 const char *newpass
,
1978 time_t pwd_last_set
)
1981 struct wbcChangePasswordParams params
;
1982 struct wbcAuthErrorInfo
*error
= NULL
;
1983 struct wbcUserPasswordPolicyInfo
*policy
= NULL
;
1984 enum wbcPasswordChangeRejectReason reject_reason
= -1;
1988 const char *codes
[] = {
1989 "NT_STATUS_BACKUP_CONTROLLER",
1990 "NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND",
1991 "NT_STATUS_NO_LOGON_SERVERS",
1992 "NT_STATUS_ACCESS_DENIED",
1993 "NT_STATUS_PWD_TOO_SHORT", /* TODO: tell the min pwd length ? */
1994 "NT_STATUS_PWD_TOO_RECENT", /* TODO: tell the minage ? */
1995 "NT_STATUS_PWD_HISTORY_CONFLICT" /* TODO: tell the history length ? */
1997 int ret
= PAM_AUTH_ERR
;
1999 ZERO_STRUCT(params
);
2001 if (ctx
->ctrl
& WINBIND_KRB5_AUTH
) {
2002 flags
|= WBFLAG_PAM_KRB5
|
2003 WBFLAG_PAM_CONTACT_TRUSTDOM
;
2006 if (ctx
->ctrl
& WINBIND_CACHED_LOGIN
) {
2007 flags
|= WBFLAG_PAM_CACHED_LOGIN
;
2010 params
.account_name
= user
;
2011 params
.level
= WBC_CHANGE_PASSWORD_LEVEL_PLAIN
;
2012 params
.old_password
.plaintext
= oldpass
;
2013 params
.new_password
.plaintext
= newpass
;
2014 params
.flags
= flags
;
2016 wbc_status
= wbcCtxChangeUserPasswordEx(ctx
->wbc_ctx
,
2021 ret
= wbc_auth_error_to_pam_error(ctx
, error
, wbc_status
,
2022 user
, "wbcChangeUserPasswordEx");
2024 if (WBC_ERROR_IS_OK(wbc_status
)) {
2025 _pam_log(ctx
, LOG_NOTICE
,
2026 "user '%s' password changed", user
);
2031 wbcFreeMemory(policy
);
2035 for (i
=0; i
<ARRAY_SIZE(codes
); i
++) {
2037 if (_pam_check_remark_auth_err(ctx
, error
, codes
[i
], &_ret
)) {
2043 if (!strcasecmp(error
->nt_string
,
2044 "NT_STATUS_PASSWORD_RESTRICTION")) {
2046 char *pwd_restriction_string
= NULL
;
2047 SMB_TIME_T min_pwd_age
= 0;
2050 min_pwd_age
= policy
->min_passwordage
;
2053 /* FIXME: avoid to send multiple PAM messages after another */
2054 switch ((int)reject_reason
) {
2057 case WBC_PWD_CHANGE_NO_ERROR
:
2058 if ((min_pwd_age
> 0) &&
2059 (pwd_last_set
+ min_pwd_age
> time(NULL
))) {
2060 time_t next_change
= pwd_last_set
+ min_pwd_age
;
2061 #if defined(__clang__)
2062 #pragma clang diagnostic push
2063 #pragma clang diagnostic ignored "-Wformat-nonliteral"
2065 _make_remark_format(ctx
, PAM_ERROR_MSG
,
2066 _get_ntstatus_error_string("NT_STATUS_PWD_TOO_RECENT"),
2067 ctime(&next_change
));
2068 #if defined(__clang__)
2069 #pragma clang diagnostic pop
2074 case WBC_PWD_CHANGE_PASSWORD_TOO_SHORT
:
2075 PAM_WB_REMARK_DIRECT(ctx
,
2076 "NT_STATUS_PWD_TOO_SHORT");
2078 case WBC_PWD_CHANGE_PWD_IN_HISTORY
:
2079 PAM_WB_REMARK_DIRECT(ctx
,
2080 "NT_STATUS_PWD_HISTORY_CONFLICT");
2082 case WBC_PWD_CHANGE_NOT_COMPLEX
:
2083 _make_remark(ctx
, PAM_ERROR_MSG
,
2084 _("Password does not meet "
2085 "complexity requirements"));
2088 _pam_log_debug(ctx
, LOG_DEBUG
,
2089 "unknown password change "
2090 "reject reason: %d",
2095 pwd_restriction_string
=
2096 _pam_compose_pwd_restriction_string(ctx
, policy
);
2097 if (pwd_restriction_string
) {
2098 _make_remark(ctx
, PAM_ERROR_MSG
,
2099 pwd_restriction_string
);
2100 TALLOC_FREE(pwd_restriction_string
);
2104 wbcFreeMemory(error
);
2105 wbcFreeMemory(policy
);
2111 * Checks if a user has an account
2114 * 1 = User not found
2118 static int valid_user(struct pwb_context
*ctx
,
2121 /* check not only if the user is available over NSS calls, also make
2122 * sure it's really a winbind user, this is important when stacking PAM
2123 * modules in the 'account' or 'password' facility. */
2126 struct passwd
*pwd
= NULL
;
2127 struct passwd
*wb_pwd
= NULL
;
2129 pwd
= getpwnam(user
);
2134 wbc_status
= wbcCtxGetpwnam(ctx
->wbc_ctx
, user
, &wb_pwd
);
2135 wbcFreeMemory(wb_pwd
);
2136 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2137 _pam_log(ctx
, LOG_DEBUG
, "valid_user: wbcGetpwnam gave %s\n",
2138 wbcErrorString(wbc_status
));
2141 switch (wbc_status
) {
2142 case WBC_ERR_UNKNOWN_USER
:
2143 /* match other insane libwbclient return codes */
2144 case WBC_ERR_WINBIND_NOT_AVAILABLE
:
2145 case WBC_ERR_DOMAIN_NOT_FOUND
:
2147 case WBC_ERR_SUCCESS
:
2155 static char *_pam_delete(register char *xx
)
2163 * obtain a password from the user
2166 static int _winbind_read_password(struct pwb_context
*ctx
,
2168 const char *comment
,
2169 const char *prompt1
,
2170 const char *prompt2
,
2178 _pam_log(ctx
, LOG_DEBUG
, "getting password (0x%08x)", ctrl
);
2181 * make sure nothing inappropriate gets returned
2184 *pass
= token
= NULL
;
2187 * which authentication token are we getting?
2190 if (on(WINBIND__OLD_PASSWORD
, ctrl
)) {
2191 authtok_flag
= PAM_OLDAUTHTOK
;
2193 authtok_flag
= PAM_AUTHTOK
;
2197 * should we obtain the password from a PAM item ?
2200 if (on(WINBIND_TRY_FIRST_PASS_ARG
, ctrl
) ||
2201 on(WINBIND_USE_FIRST_PASS_ARG
, ctrl
)) {
2202 retval
= pam_get_item(ctx
->pamh
,
2204 (const void **) &item
);
2205 if (retval
!= PAM_SUCCESS
) {
2207 _pam_log(ctx
, LOG_ALERT
,
2208 "pam_get_item returned error "
2209 "to unix-read-password");
2211 } else if (item
!= NULL
) { /* we have a password! */
2214 _pam_log(ctx
, LOG_DEBUG
,
2215 "pam_get_item returned a password");
2217 } else if (on(WINBIND_USE_FIRST_PASS_ARG
, ctrl
)) {
2218 return PAM_AUTHTOK_RECOVER_ERR
; /* didn't work */
2219 } else if (on(WINBIND_USE_AUTHTOK_ARG
, ctrl
)
2220 && off(WINBIND__OLD_PASSWORD
, ctrl
)) {
2221 return PAM_AUTHTOK_RECOVER_ERR
;
2225 * getting here implies we will have to get the password from the
2230 struct pam_message msg
[3];
2231 const struct pam_message
*pmsg
[3];
2232 struct pam_response
*resp
;
2235 /* prepare to converse */
2237 if (comment
!= NULL
&& off(ctrl
, WINBIND_SILENT
)) {
2239 msg
[0].msg_style
= PAM_TEXT_INFO
;
2240 msg
[0].msg
= discard_const_p(char, comment
);
2247 msg
[i
].msg_style
= PAM_PROMPT_ECHO_OFF
;
2248 msg
[i
++].msg
= discard_const_p(char, prompt1
);
2251 if (prompt2
!= NULL
) {
2253 msg
[i
].msg_style
= PAM_PROMPT_ECHO_OFF
;
2254 msg
[i
++].msg
= discard_const_p(char, prompt2
);
2257 /* so call the conversation expecting i responses */
2259 retval
= converse(ctx
->pamh
, i
, pmsg
, &resp
);
2261 if (retval
== PAM_SUCCESS
) {
2262 retval
= PAM_AUTHTOK_RECOVER_ERR
;
2266 if (retval
!= PAM_SUCCESS
) {
2267 _pam_drop_reply(resp
, i
);
2271 /* interpret the response */
2273 token
= x_strdup(resp
[i
- replies
].resp
);
2275 _pam_log(ctx
, LOG_NOTICE
,
2276 "could not recover "
2277 "authentication token");
2278 retval
= PAM_AUTHTOK_RECOVER_ERR
;
2283 /* verify that password entered correctly */
2284 if (!resp
[i
- 1].resp
||
2285 strcmp(token
, resp
[i
- 1].resp
)) {
2286 _pam_delete(token
); /* mistyped */
2287 retval
= PAM_AUTHTOK_RECOVER_ERR
;
2288 _make_remark(ctx
, PAM_ERROR_MSG
,
2294 * tidy up the conversation (resp_retcode) is ignored
2295 * -- what is it for anyway? AGM
2297 _pam_drop_reply(resp
, i
);
2301 if (retval
!= PAM_SUCCESS
) {
2302 _pam_log_debug(ctx
, LOG_DEBUG
,
2303 "unable to obtain a password");
2306 /* 'token' is the entered password */
2308 /* we store this password as an item */
2310 retval
= pam_set_item(ctx
->pamh
, authtok_flag
, token
);
2311 _pam_delete(token
); /* clean it up */
2312 if (retval
!= PAM_SUCCESS
||
2313 (retval
= pam_get_item(ctx
->pamh
, authtok_flag
, (const void **) &item
)) != PAM_SUCCESS
) {
2315 _pam_log(ctx
, LOG_CRIT
, "error manipulating password");
2321 item
= NULL
; /* break link to password */
2326 static const char *get_conf_item_string(struct pwb_context
*ctx
,
2331 const char *parm_opt
= NULL
;
2333 if (!(ctx
->ctrl
& config_flag
)) {
2337 /* let the pam opt take precedence over the pam_winbind.conf option */
2338 for (i
=0; i
<ctx
->argc
; i
++) {
2340 if ((strncmp(ctx
->argv
[i
], item
, strlen(item
)) == 0)) {
2343 if ((p
= strchr(ctx
->argv
[i
], '=')) == NULL
) {
2344 _pam_log(ctx
, LOG_INFO
,
2345 "no \"=\" delimiter for \"%s\" found\n",
2349 _pam_log_debug(ctx
, LOG_INFO
,
2350 "PAM config: %s '%s'\n", item
, p
+1);
2358 key
= talloc_asprintf(ctx
, "global:%s", item
);
2363 parm_opt
= tiniparser_getstring_nonempty(ctx
->dict
, key
, NULL
);
2366 _pam_log_debug(ctx
, LOG_INFO
, "CONFIG file: %s '%s'\n",
2373 static int get_config_item_int(struct pwb_context
*ctx
,
2377 int i
, parm_opt
= -1;
2379 if (!(ctx
->ctrl
& config_flag
)) {
2383 /* let the pam opt take precedence over the pam_winbind.conf option */
2384 for (i
= 0; i
< ctx
->argc
; i
++) {
2386 if ((strncmp(ctx
->argv
[i
], item
, strlen(item
)) == 0)) {
2389 if ((p
= strchr(ctx
->argv
[i
], '=')) == NULL
) {
2390 _pam_log(ctx
, LOG_INFO
,
2391 "no \"=\" delimiter for \"%s\" found\n",
2395 parm_opt
= atoi(p
+ 1);
2396 _pam_log_debug(ctx
, LOG_INFO
,
2397 "PAM config: %s '%d'\n",
2406 key
= talloc_asprintf(ctx
, "global:%s", item
);
2411 parm_opt
= tiniparser_getint(ctx
->dict
, key
, -1);
2414 _pam_log_debug(ctx
, LOG_INFO
,
2415 "CONFIG file: %s '%d'\n",
2422 static const char *get_krb5_cc_type_from_config(struct pwb_context
*ctx
)
2424 return get_conf_item_string(ctx
, "krb5_ccache_type",
2425 WINBIND_KRB5_CCACHE_TYPE
);
2428 static const char *get_member_from_config(struct pwb_context
*ctx
)
2430 const char *ret
= NULL
;
2431 ret
= get_conf_item_string(ctx
, "require_membership_of",
2432 WINBIND_REQUIRED_MEMBERSHIP
);
2436 return get_conf_item_string(ctx
, "require-membership-of",
2437 WINBIND_REQUIRED_MEMBERSHIP
);
2440 static int get_warn_pwd_expire_from_config(struct pwb_context
*ctx
)
2443 ret
= get_config_item_int(ctx
, "warn_pwd_expire",
2444 WINBIND_WARN_PWD_EXPIRE
);
2445 /* no or broken setting */
2447 return DEFAULT_DAYS_TO_WARN_BEFORE_PWD_EXPIRES
;
2453 * Retrieve the winbind separator.
2455 * @param ctx PAM winbind context.
2457 * @return string separator character. NULL on failure.
2460 static char winbind_get_separator(struct pwb_context
*ctx
)
2463 static struct wbcInterfaceDetails
*details
= NULL
;
2466 wbc_status
= wbcCtxInterfaceDetails(ctx
->wbc_ctx
, &details
);
2467 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2468 _pam_log(ctx
, LOG_ERR
,
2469 "Could not retrieve winbind interface details: %s",
2470 wbcErrorString(wbc_status
));
2478 result
= details
->winbind_separator
;
2479 wbcFreeMemory(details
);
2485 * Convert a upn to a name.
2487 * @param ctx PAM winbind context.
2488 * @param upn User UPN to be translated.
2490 * @return converted name. NULL pointer on failure. Caller needs to free.
2493 static char* winbind_upn_to_username(struct pwb_context
*ctx
,
2497 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
2498 struct wbcDomainSid sid
;
2499 enum wbcSidType type
;
2500 char *domain
= NULL
;
2505 /* This cannot work when the winbind separator = @ */
2507 sep
= winbind_get_separator(ctx
);
2508 if (!sep
|| sep
== '@') {
2512 name
= talloc_strdup(ctx
, upn
);
2517 p
= strchr(name
, '@');
2525 /* Convert the UPN to a SID */
2527 wbc_status
= wbcCtxLookupName(ctx
->wbc_ctx
, domain
, name
, &sid
, &type
);
2528 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2532 /* Convert the the SID back to the sAMAccountName */
2534 wbc_status
= wbcCtxLookupSid(ctx
->wbc_ctx
, &sid
, &domain
, &name
, &type
);
2535 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2539 result
= talloc_asprintf(ctx
, "%s%c%s", domain
, sep
, name
);
2540 wbcFreeMemory(domain
);
2541 wbcFreeMemory(name
);
2545 static int _pam_delete_cred(pam_handle_t
*pamh
, int flags
,
2546 int argc
, enum pam_winbind_request_type type
,
2549 int retval
= PAM_SUCCESS
;
2550 struct pwb_context
*ctx
= NULL
;
2551 struct wbcLogoffUserParams logoff
;
2552 struct wbcAuthErrorInfo
*error
= NULL
;
2554 wbcErr wbc_status
= WBC_ERR_SUCCESS
;
2556 ZERO_STRUCT(logoff
);
2558 retval
= _pam_winbind_init_context(pamh
, flags
, argc
, argv
, type
, &ctx
);
2559 if (retval
!= PAM_SUCCESS
) {
2563 _PAM_LOG_FUNCTION_ENTER("_pam_delete_cred", ctx
);
2565 if (ctx
->ctrl
& WINBIND_KRB5_AUTH
) {
2567 /* destroy the ccache here */
2569 uint32_t wbc_flags
= 0;
2570 const char *ccname
= NULL
;
2571 struct passwd
*pwd
= NULL
;
2573 retval
= pam_get_user(pamh
, &user
, _("Username: "));
2574 if (retval
!= PAM_SUCCESS
) {
2575 _pam_log(ctx
, LOG_ERR
,
2576 "could not identify user");
2581 _pam_log(ctx
, LOG_ERR
,
2582 "username was NULL!");
2583 retval
= PAM_USER_UNKNOWN
;
2587 _pam_log_debug(ctx
, LOG_DEBUG
,
2588 "username [%s] obtained", user
);
2590 ccname
= pam_getenv(pamh
, "KRB5CCNAME");
2591 if (ccname
== NULL
) {
2592 _pam_log_debug(ctx
, LOG_DEBUG
,
2593 "user has no KRB5CCNAME environment");
2596 pwd
= getpwnam(user
);
2598 retval
= PAM_USER_UNKNOWN
;
2602 wbc_flags
= WBFLAG_PAM_KRB5
|
2603 WBFLAG_PAM_CONTACT_TRUSTDOM
;
2605 logoff
.username
= user
;
2608 wbc_status
= wbcAddNamedBlob(&logoff
.num_blobs
,
2612 discard_const_p(uint8_t, ccname
),
2614 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2619 wbc_status
= wbcAddNamedBlob(&logoff
.num_blobs
,
2623 (uint8_t *)&wbc_flags
,
2625 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2629 wbc_status
= wbcAddNamedBlob(&logoff
.num_blobs
,
2633 (uint8_t *)&pwd
->pw_uid
,
2634 sizeof(pwd
->pw_uid
));
2635 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2639 wbc_status
= wbcCtxLogoffUserEx(ctx
->wbc_ctx
, &logoff
, &error
);
2640 retval
= wbc_auth_error_to_pam_error(ctx
, error
, wbc_status
,
2641 user
, "wbcLogoffUser");
2642 wbcFreeMemory(logoff
.blobs
);
2643 logoff
.blobs
= NULL
;
2645 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2646 _pam_log(ctx
, LOG_INFO
,
2647 "failed to logoff user %s: %s\n",
2648 user
, wbcErrorString(wbc_status
));
2654 wbcFreeMemory(logoff
.blobs
);
2657 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2658 retval
= wbc_auth_error_to_pam_error(ctx
, error
, wbc_status
,
2659 user
, "wbcLogoffUser");
2661 wbcFreeMemory(error
);
2664 * Delete the krb5 ccname variable from the PAM environment
2665 * if it was set by winbind.
2667 if ((ctx
->ctrl
& WINBIND_KRB5_AUTH
) && pam_getenv(pamh
, "KRB5CCNAME")) {
2668 pam_putenv(pamh
, "KRB5CCNAME");
2671 _PAM_LOG_FUNCTION_LEAVE("_pam_delete_cred", ctx
, retval
);
2678 #ifdef SECURITY_OPENPAM_H_INCLUDED
2680 * Logic below is copied from openpam_check_error_code() in
2681 *./contrib/openpam/lib/libpam/openpam_dispatch.c on FreeBSD.
2683 static int openpam_convert_error_code(struct pwb_context
*ctx
,
2684 enum pam_winbind_request_type req
,
2687 if (r
== PAM_SUCCESS
||
2688 r
== PAM_SYSTEM_ERR
||
2689 r
== PAM_SERVICE_ERR
||
2691 r
== PAM_CONV_ERR
||
2692 r
== PAM_PERM_DENIED
||
2697 /* specific winbind request types */
2699 case PAM_WINBIND_AUTHENTICATE
:
2700 if (r
== PAM_AUTH_ERR
||
2701 r
== PAM_CRED_INSUFFICIENT
||
2702 r
== PAM_AUTHINFO_UNAVAIL
||
2703 r
== PAM_USER_UNKNOWN
||
2704 r
== PAM_MAXTRIES
) {
2708 case PAM_WINBIND_SETCRED
:
2709 if (r
== PAM_CRED_UNAVAIL
||
2710 r
== PAM_CRED_EXPIRED
||
2711 r
== PAM_USER_UNKNOWN
||
2712 r
== PAM_CRED_ERR
) {
2716 case PAM_WINBIND_ACCT_MGMT
:
2717 if (r
== PAM_USER_UNKNOWN
||
2718 r
== PAM_AUTH_ERR
||
2719 r
== PAM_NEW_AUTHTOK_REQD
||
2720 r
== PAM_ACCT_EXPIRED
) {
2724 case PAM_WINBIND_OPEN_SESSION
:
2725 case PAM_WINBIND_CLOSE_SESSION
:
2726 if (r
== PAM_SESSION_ERR
) {
2730 case PAM_WINBIND_CHAUTHTOK
:
2731 if (r
== PAM_PERM_DENIED
||
2732 r
== PAM_AUTHTOK_ERR
||
2733 r
== PAM_AUTHTOK_RECOVERY_ERR
||
2734 r
== PAM_AUTHTOK_LOCK_BUSY
||
2735 r
== PAM_AUTHTOK_DISABLE_AGING
||
2736 r
== PAM_TRY_AGAIN
) {
2743 _pam_log(ctx
, LOG_INFO
,
2744 "Converting PAM error [%d] to PAM_SERVICE_ERR.\n", r
);
2745 return PAM_SERVICE_ERR
;
2747 #define pam_error_code(a, b, c) openpam_convert_error_code(a, b, c)
2749 #define pam_error_code(a, b, c) (c)
2753 int pam_sm_authenticate(pam_handle_t
*pamh
, int flags
,
2754 int argc
, const char **argv
)
2756 const char *username
;
2757 const char *password
;
2758 const char *member
= NULL
;
2759 const char *cctype
= NULL
;
2760 int warn_pwd_expire
;
2761 int retval
= PAM_AUTH_ERR
;
2762 char *username_ret
= NULL
;
2763 char *new_authtok_required
= NULL
;
2764 char *real_username
= NULL
;
2765 struct pwb_context
*ctx
= NULL
;
2767 retval
= _pam_winbind_init_context(pamh
, flags
, argc
, argv
,
2768 PAM_WINBIND_AUTHENTICATE
, &ctx
);
2769 if (retval
!= PAM_SUCCESS
) {
2773 _PAM_LOG_FUNCTION_ENTER("pam_sm_authenticate", ctx
);
2775 /* Get the username */
2776 retval
= pam_get_user(pamh
, &username
, NULL
);
2777 if ((retval
!= PAM_SUCCESS
) || (!username
)) {
2778 _pam_log_debug(ctx
, LOG_DEBUG
,
2779 "can not get the username");
2780 retval
= PAM_SERVICE_ERR
;
2786 /* Decode the user name since AIX does not support logn user
2787 names by default. The name is encoded as _#uid. */
2789 if (username
[0] == '_') {
2790 uid_t id
= atoi(&username
[1]);
2791 struct passwd
*pw
= NULL
;
2793 if ((id
!=0) && ((pw
= getpwuid(id
)) != NULL
)) {
2794 real_username
= strdup(pw
->pw_name
);
2799 if (!real_username
) {
2800 /* Just making a copy of the username we got from PAM */
2801 if ((real_username
= strdup(username
)) == NULL
) {
2802 _pam_log_debug(ctx
, LOG_DEBUG
,
2803 "memory allocation failure when copying "
2805 retval
= PAM_SERVICE_ERR
;
2810 /* Maybe this was a UPN */
2812 if (strchr(real_username
, '@') != NULL
) {
2813 char *samaccountname
= NULL
;
2815 samaccountname
= winbind_upn_to_username(ctx
,
2817 if (samaccountname
) {
2818 free(real_username
);
2819 real_username
= strdup(samaccountname
);
2823 retval
= _winbind_read_password(ctx
, ctx
->ctrl
, NULL
,
2824 _("Password: "), NULL
,
2827 if (retval
!= PAM_SUCCESS
) {
2828 _pam_log(ctx
, LOG_ERR
,
2829 "Could not retrieve user's password");
2830 retval
= PAM_AUTHTOK_ERR
;
2834 /* Let's not give too much away in the log file */
2836 #ifdef DEBUG_PASSWORD
2837 _pam_log_debug(ctx
, LOG_INFO
,
2838 "Verify user '%s' with password '%s'",
2839 real_username
, password
);
2841 _pam_log_debug(ctx
, LOG_INFO
,
2842 "Verify user '%s'", real_username
);
2845 member
= get_member_from_config(ctx
);
2846 cctype
= get_krb5_cc_type_from_config(ctx
);
2847 warn_pwd_expire
= get_warn_pwd_expire_from_config(ctx
);
2849 /* Now use the username to look up password */
2850 retval
= winbind_auth_request(ctx
, real_username
, password
,
2851 member
, cctype
, warn_pwd_expire
,
2852 NULL
, NULL
, NULL
, &username_ret
);
2854 if (retval
== PAM_NEW_AUTHTOK_REQD
||
2855 retval
== PAM_AUTHTOK_EXPIRED
) {
2857 char *new_authtok_required_during_auth
= NULL
;
2859 new_authtok_required
= talloc_asprintf(NULL
, "%d", retval
);
2860 if (!new_authtok_required
) {
2861 retval
= PAM_BUF_ERR
;
2865 pam_set_data(pamh
, PAM_WINBIND_NEW_AUTHTOK_REQD
,
2866 new_authtok_required
,
2867 _pam_winbind_cleanup_func
);
2869 retval
= PAM_SUCCESS
;
2871 new_authtok_required_during_auth
= talloc_asprintf(NULL
, "%d", true);
2872 if (!new_authtok_required_during_auth
) {
2873 retval
= PAM_BUF_ERR
;
2877 pam_set_data(pamh
, PAM_WINBIND_NEW_AUTHTOK_REQD_DURING_AUTH
,
2878 new_authtok_required_during_auth
,
2879 _pam_winbind_cleanup_func
);
2886 pam_set_item (pamh
, PAM_USER
, username_ret
);
2887 _pam_log_debug(ctx
, LOG_INFO
,
2888 "Returned user was '%s'", username_ret
);
2892 if (real_username
) {
2893 free(real_username
);
2896 if (!new_authtok_required
) {
2897 pam_set_data(pamh
, PAM_WINBIND_NEW_AUTHTOK_REQD
, NULL
, NULL
);
2900 if (retval
!= PAM_SUCCESS
) {
2901 _pam_free_data_info3(pamh
);
2904 _PAM_LOG_FUNCTION_LEAVE("pam_sm_authenticate", ctx
, retval
);
2912 int pam_sm_setcred(pam_handle_t
*pamh
, int flags
,
2913 int argc
, const char **argv
)
2915 int ret
= PAM_SYSTEM_ERR
;
2916 struct pwb_context
*ctx
= NULL
;
2918 ret
= _pam_winbind_init_context(pamh
, flags
, argc
, argv
,
2919 PAM_WINBIND_SETCRED
, &ctx
);
2920 if (ret
!= PAM_SUCCESS
) {
2924 _PAM_LOG_FUNCTION_ENTER("pam_sm_setcred", ctx
);
2926 switch (flags
& ~PAM_SILENT
) {
2928 case PAM_DELETE_CRED
:
2929 ret
= _pam_delete_cred(pamh
, flags
, argc
,
2930 PAM_WINBIND_SETCRED
, argv
);
2932 case PAM_REFRESH_CRED
:
2933 _pam_log_debug(ctx
, LOG_WARNING
,
2934 "PAM_REFRESH_CRED not implemented");
2937 case PAM_REINITIALIZE_CRED
:
2938 _pam_log_debug(ctx
, LOG_WARNING
,
2939 "PAM_REINITIALIZE_CRED not implemented");
2942 case PAM_ESTABLISH_CRED
:
2943 _pam_log_debug(ctx
, LOG_WARNING
,
2944 "PAM_ESTABLISH_CRED not implemented");
2948 ret
= PAM_SYSTEM_ERR
;
2952 _PAM_LOG_FUNCTION_LEAVE("pam_sm_setcred", ctx
, ret
);
2956 return pam_error_code(ctx
, PAM_WINBIND_SETCRED
, ret
);
2960 * Account management. We want to verify that the account exists
2961 * before returning PAM_SUCCESS
2964 int pam_sm_acct_mgmt(pam_handle_t
*pamh
, int flags
,
2965 int argc
, const char **argv
)
2967 const char *username
;
2968 int ret
= PAM_USER_UNKNOWN
;
2969 const char *tmp
= NULL
;
2970 struct pwb_context
*ctx
= NULL
;
2972 ret
= _pam_winbind_init_context(pamh
, flags
, argc
, argv
,
2973 PAM_WINBIND_ACCT_MGMT
, &ctx
);
2974 if (ret
!= PAM_SUCCESS
) {
2978 _PAM_LOG_FUNCTION_ENTER("pam_sm_acct_mgmt", ctx
);
2981 /* Get the username */
2982 ret
= pam_get_user(pamh
, &username
, NULL
);
2983 if ((ret
!= PAM_SUCCESS
) || (!username
)) {
2984 _pam_log_debug(ctx
, LOG_DEBUG
,
2985 "can not get the username");
2986 ret
= PAM_SERVICE_ERR
;
2990 /* Verify the username */
2991 ret
= valid_user(ctx
, username
);
2994 /* some sort of system error. The log was already printed */
2995 ret
= PAM_SERVICE_ERR
;
2998 /* the user does not exist */
2999 _pam_log_debug(ctx
, LOG_NOTICE
, "user '%s' not found",
3001 if (ctx
->ctrl
& WINBIND_UNKNOWN_OK_ARG
) {
3005 ret
= PAM_USER_UNKNOWN
;
3008 pam_get_data(pamh
, PAM_WINBIND_NEW_AUTHTOK_REQD
,
3009 (const void **)&tmp
);
3013 case PAM_AUTHTOK_EXPIRED
:
3014 /* Since new token is required in this case */
3016 case PAM_NEW_AUTHTOK_REQD
:
3017 _pam_log(ctx
, LOG_WARNING
,
3018 "pam_sm_acct_mgmt success but %s is set",
3019 PAM_WINBIND_NEW_AUTHTOK_REQD
);
3020 _pam_log(ctx
, LOG_NOTICE
,
3021 "user '%s' needs new password",
3023 /* PAM_AUTHTOKEN_REQD does not exist, but is documented in the manpage */
3024 ret
= PAM_NEW_AUTHTOK_REQD
;
3027 _pam_log(ctx
, LOG_WARNING
,
3028 "pam_sm_acct_mgmt success");
3029 _pam_log(ctx
, LOG_NOTICE
,
3030 "user '%s' granted access", username
);
3036 /* Otherwise, the authentication looked good */
3037 _pam_log(ctx
, LOG_NOTICE
,
3038 "user '%s' granted access", username
);
3042 /* we don't know anything about this return value */
3043 _pam_log(ctx
, LOG_ERR
,
3044 "internal module error (ret = %d, user = '%s')",
3046 ret
= PAM_SERVICE_ERR
;
3050 /* should not be reached */
3055 _PAM_LOG_FUNCTION_LEAVE("pam_sm_acct_mgmt", ctx
, ret
);
3059 return pam_error_code(ctx
, PAM_WINBIND_ACCT_MGMT
, ret
);
3063 int pam_sm_open_session(pam_handle_t
*pamh
, int flags
,
3064 int argc
, const char **argv
)
3066 int ret
= PAM_SUCCESS
;
3067 struct pwb_context
*ctx
= NULL
;
3069 ret
= _pam_winbind_init_context(pamh
, flags
, argc
, argv
,
3070 PAM_WINBIND_OPEN_SESSION
, &ctx
);
3071 if (ret
!= PAM_SUCCESS
) {
3075 _PAM_LOG_FUNCTION_ENTER("pam_sm_open_session", ctx
);
3077 if (ctx
->ctrl
& WINBIND_MKHOMEDIR
) {
3078 /* check and create homedir */
3079 ret
= _pam_mkhomedir(ctx
);
3082 _PAM_LOG_FUNCTION_LEAVE("pam_sm_open_session", ctx
, ret
);
3086 return pam_error_code(ctx
, PAM_WINBIND_OPEN_SESSION
, ret
);
3090 int pam_sm_close_session(pam_handle_t
*pamh
, int flags
,
3091 int argc
, const char **argv
)
3093 int ret
= PAM_SUCCESS
;
3094 struct pwb_context
*ctx
= NULL
;
3096 ret
= _pam_winbind_init_context(pamh
, flags
, argc
, argv
,
3097 PAM_WINBIND_CLOSE_SESSION
, &ctx
);
3098 if (ret
!= PAM_SUCCESS
) {
3102 _PAM_LOG_FUNCTION_ENTER("pam_sm_close_session", ctx
);
3104 _PAM_LOG_FUNCTION_LEAVE("pam_sm_close_session", ctx
, ret
);
3108 return pam_error_code(ctx
, PAM_WINBIND_CLOSE_SESSION
, ret
);
3112 * evaluate whether we need to re-authenticate with kerberos after a
3115 * @param ctx PAM winbind context.
3116 * @param user The username
3118 * @return boolean Returns true if required, false if not.
3121 static bool _pam_require_krb5_auth_after_chauthtok(struct pwb_context
*ctx
,
3125 /* Make sure that we only do this if a) the chauthtok got initiated
3126 * during a logon attempt (authenticate->acct_mgmt->chauthtok) b) any
3127 * later password change via the "passwd" command if done by the user
3129 * NB. If we login from gdm or xdm and the password expires,
3130 * we change the password, but there is no memory cache.
3131 * Thus, even for passthrough login, we should do the
3132 * authentication again to update memory cache.
3136 const char *new_authtok_reqd_during_auth
= NULL
;
3137 struct passwd
*pwd
= NULL
;
3139 pam_get_data(ctx
->pamh
, PAM_WINBIND_NEW_AUTHTOK_REQD_DURING_AUTH
,
3140 (const void **) &new_authtok_reqd_during_auth
);
3141 pam_set_data(ctx
->pamh
, PAM_WINBIND_NEW_AUTHTOK_REQD_DURING_AUTH
,
3144 if (new_authtok_reqd_during_auth
) {
3148 pwd
= getpwnam(user
);
3153 if (getuid() == pwd
->pw_uid
) {
3162 int pam_sm_chauthtok(pam_handle_t
* pamh
, int flags
,
3163 int argc
, const char **argv
)
3167 bool cached_login
= false;
3169 /* <DO NOT free() THESE> */
3171 const char *pass_old
;
3172 const char *pass_new
;
3173 /* </DO NOT free() THESE> */
3178 char *username_ret
= NULL
;
3179 struct wbcAuthErrorInfo
*error
= NULL
;
3180 struct pwb_context
*ctx
= NULL
;
3182 ret
= _pam_winbind_init_context(pamh
, flags
, argc
, argv
,
3183 PAM_WINBIND_CHAUTHTOK
, &ctx
);
3184 if (ret
!= PAM_SUCCESS
) {
3188 _PAM_LOG_FUNCTION_ENTER("pam_sm_chauthtok", ctx
);
3190 cached_login
= (ctx
->ctrl
& WINBIND_CACHED_LOGIN
);
3192 /* clearing offline bit for auth */
3193 ctx
->ctrl
&= ~WINBIND_CACHED_LOGIN
;
3196 * First get the name of a user
3198 ret
= pam_get_user(pamh
, &user
, _("Username: "));
3199 if (ret
!= PAM_SUCCESS
) {
3200 _pam_log(ctx
, LOG_ERR
,
3201 "password - could not identify user");
3206 _pam_log(ctx
, LOG_ERR
, "username was NULL!");
3207 ret
= PAM_USER_UNKNOWN
;
3211 _pam_log_debug(ctx
, LOG_DEBUG
, "username [%s] obtained", user
);
3213 /* check if this is really a user in winbindd, not only in NSS */
3214 ret
= valid_user(ctx
, user
);
3217 ret
= PAM_USER_UNKNOWN
;
3220 ret
= PAM_SYSTEM_ERR
;
3227 * obtain and verify the current password (OLDAUTHTOK) for
3231 if (flags
& PAM_PRELIM_CHECK
) {
3232 time_t *pwdlastset_prelim
= NULL
;
3234 pwdlastset_prelim
= talloc_zero(NULL
, time_t);
3235 if (pwdlastset_prelim
== NULL
) {
3236 _pam_log(ctx
, LOG_CRIT
,
3237 "password - out of memory");
3242 /* instruct user what is happening */
3244 #define greeting _("Changing password for")
3245 Announce
= talloc_asprintf(ctx
, "%s %s", greeting
, user
);
3247 _pam_log(ctx
, LOG_CRIT
,
3248 "password - out of memory");
3254 lctrl
= ctx
->ctrl
| WINBIND__OLD_PASSWORD
;
3255 ret
= _winbind_read_password(ctx
, lctrl
,
3257 _("(current) NT password: "),
3259 (const char **) &pass_old
);
3260 TALLOC_FREE(Announce
);
3261 if (ret
!= PAM_SUCCESS
) {
3262 _pam_log(ctx
, LOG_NOTICE
,
3263 "password - (old) token not obtained");
3267 /* verify that this is the password for this user */
3269 ret
= winbind_auth_request(ctx
, user
, pass_old
,
3272 pwdlastset_prelim
, NULL
);
3274 if (ret
!= PAM_ACCT_EXPIRED
&&
3275 ret
!= PAM_AUTHTOK_EXPIRED
&&
3276 ret
!= PAM_NEW_AUTHTOK_REQD
&&
3277 ret
!= PAM_SUCCESS
) {
3282 pam_set_data(pamh
, PAM_WINBIND_PWD_LAST_SET
,
3284 _pam_winbind_cleanup_func
);
3286 ret
= pam_set_item(pamh
, PAM_OLDAUTHTOK
,
3287 (const void *) pass_old
);
3289 if (ret
!= PAM_SUCCESS
) {
3290 _pam_log(ctx
, LOG_CRIT
,
3291 "failed to set PAM_OLDAUTHTOK");
3293 } else if (flags
& PAM_UPDATE_AUTHTOK
) {
3294 const time_t *pwdlastset_update
= NULL
;
3297 * obtain the proposed password
3301 * get the old token back.
3304 ret
= pam_get_item(pamh
, PAM_OLDAUTHTOK
, (const void **) &pass_old
);
3306 if (ret
!= PAM_SUCCESS
) {
3307 _pam_log(ctx
, LOG_NOTICE
,
3308 "user not authenticated");
3312 lctrl
= ctx
->ctrl
& ~WINBIND_TRY_FIRST_PASS_ARG
;
3314 if (on(WINBIND_USE_AUTHTOK_ARG
, lctrl
)) {
3315 lctrl
|= WINBIND_USE_FIRST_PASS_ARG
;
3317 if (on(WINBIND_TRY_AUTHTOK_ARG
, lctrl
)) {
3318 lctrl
|= WINBIND_TRY_FIRST_PASS_ARG
;
3321 ret
= PAM_AUTHTOK_ERR
;
3322 while ((ret
!= PAM_SUCCESS
) && (retry
++ < MAX_PASSWD_TRIES
)) {
3324 * use_authtok is to force the use of a previously entered
3325 * password -- needed for pluggable password strength checking
3328 ret
= _winbind_read_password(ctx
, lctrl
,
3330 _("Enter new NT password: "),
3331 _("Retype new NT password: "),
3332 (const char **)&pass_new
);
3334 if (ret
!= PAM_SUCCESS
) {
3335 _pam_log_debug(ctx
, LOG_ALERT
,
3337 "new password not obtained");
3338 pass_old
= NULL
;/* tidy up */
3343 * At this point we know who the user is and what they
3344 * propose as their new password. Verify that the new
3345 * password is acceptable.
3348 if (pass_new
[0] == '\0') {/* "\0" password = NULL */
3354 * By reaching here we have approved the passwords and must now
3355 * rebuild the password database file.
3358 PAM_WINBIND_PWD_LAST_SET
,
3359 (const void **)(&pwdlastset_update
));
3362 * if cached creds were enabled, make sure to set the
3363 * WINBIND_CACHED_LOGIN bit here in order to have winbindd
3364 * update the cached creds storage - gd
3367 ctx
->ctrl
|= WINBIND_CACHED_LOGIN
;
3370 ret
= winbind_chauthtok_request(ctx
, user
, pass_old
,
3371 pass_new
, *pwdlastset_update
);
3372 if (ret
!= PAM_SUCCESS
) {
3373 pass_old
= pass_new
= NULL
;
3377 if (_pam_require_krb5_auth_after_chauthtok(ctx
, user
)) {
3379 const char *member
= NULL
;
3380 const char *cctype
= NULL
;
3381 int warn_pwd_expire
;
3382 struct wbcLogonUserInfo
*info
= NULL
;
3384 member
= get_member_from_config(ctx
);
3385 cctype
= get_krb5_cc_type_from_config(ctx
);
3386 warn_pwd_expire
= get_warn_pwd_expire_from_config(ctx
);
3388 /* Keep WINBIND_CACHED_LOGIN bit for
3389 * authentication after changing the password.
3390 * This will update the cached credentials in case
3391 * that winbindd_dual_pam_chauthtok() fails
3396 ret
= winbind_auth_request(ctx
, user
, pass_new
,
3399 NULL
, &username_ret
);
3400 pass_old
= pass_new
= NULL
;
3402 if (ret
== PAM_SUCCESS
) {
3404 struct wbcAuthUserInfo
*user_info
= NULL
;
3406 if (info
&& info
->info
) {
3407 user_info
= info
->info
;
3410 /* warn a user if the password is about to
3412 _pam_warn_password_expiry(ctx
, user_info
,
3416 /* set some info3 info for other modules in the
3418 _pam_set_data_info3(ctx
, user_info
);
3420 /* put krb5ccname into env */
3421 _pam_setup_krb5_env(ctx
, info
);
3424 pam_set_item(pamh
, PAM_USER
,
3426 _pam_log_debug(ctx
, LOG_INFO
,
3427 "Returned user was '%s'",
3434 if (info
&& info
->blobs
) {
3435 wbcFreeMemory(info
->blobs
);
3437 wbcFreeMemory(info
);
3442 ret
= PAM_SERVICE_ERR
;
3447 /* Deal with offline errors. */
3449 const char *codes
[] = {
3450 "NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND",
3451 "NT_STATUS_NO_LOGON_SERVERS",
3452 "NT_STATUS_ACCESS_DENIED"
3455 for (i
=0; i
<ARRAY_SIZE(codes
); i
++) {
3457 if (_pam_check_remark_auth_err(ctx
, error
, codes
[i
], &_ret
)) {
3463 wbcFreeMemory(error
);
3465 _PAM_LOG_FUNCTION_LEAVE("pam_sm_chauthtok", ctx
, ret
);
3469 return pam_error_code(ctx
, PAM_WINBIND_CHAUTHTOK
, ret
);
3474 /* static module data */
3476 struct pam_module _pam_winbind_modstruct
= {
3478 pam_sm_authenticate
,
3481 pam_sm_open_session
,
3482 pam_sm_close_session
,
3489 * Copyright (c) Andrew Tridgell <tridge@samba.org> 2000
3490 * Copyright (c) Tim Potter <tpot@samba.org> 2000
3491 * Copyright (c) Andrew Bartlettt <abartlet@samba.org> 2002
3492 * Copyright (c) Guenther Deschner <gd@samba.org> 2005-2008
3493 * Copyright (c) Jan Rêkorajski 1999.
3494 * Copyright (c) Andrew G. Morgan 1996-8.
3495 * Copyright (c) Alex O. Yuriev, 1996.
3496 * Copyright (c) Cristian Gafton 1996.
3497 * Copyright (C) Elliot Lee <sopwith@redhat.com> 1996, Red Hat Software.
3499 * Redistribution and use in source and binary forms, with or without
3500 * modification, are permitted provided that the following conditions
3502 * 1. Redistributions of source code must retain the above copyright
3503 * notice, and the entire permission notice in its entirety,
3504 * including the disclaimer of warranties.
3505 * 2. Redistributions in binary form must reproduce the above copyright
3506 * notice, this list of conditions and the following disclaimer in the
3507 * documentation and/or other materials provided with the distribution.
3508 * 3. The name of the author may not be used to endorse or promote
3509 * products derived from this software without specific prior
3510 * written permission.
3512 * ALTERNATIVELY, this product may be distributed under the terms of
3513 * the GNU Public License, in which case the provisions of the GPL are
3514 * required INSTEAD OF the above restrictions. (This clause is
3515 * necessary due to a potential bad interaction between the GPL and
3516 * the restrictions contained in a BSD-style copyright.)
3518 * THIS SOFTWARE IS PROVIDED `AS IS'' AND ANY EXPRESS OR IMPLIED
3519 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
3520 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
3521 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
3522 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
3523 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
3524 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3525 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3526 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3527 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
3528 * OF THE POSSIBILITY OF SUCH DAMAGE.