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
;
483 /* step through arguments */
484 for (i
=argc
,v
=argv
; i
-- > 0; ++v
) {
486 /* generic options */
487 if (!strcmp(*v
,"debug"))
488 ctrl
|= WINBIND_DEBUG_ARG
;
489 else if (!strcasecmp(*v
, "debug_state"))
490 ctrl
|= WINBIND_DEBUG_STATE
;
491 else if (!strcasecmp(*v
, "silent"))
492 ctrl
|= WINBIND_SILENT
;
493 else if (!strcasecmp(*v
, "use_authtok"))
494 ctrl
|= WINBIND_USE_AUTHTOK_ARG
;
495 else if (!strcasecmp(*v
, "try_authtok"))
496 ctrl
|= WINBIND_TRY_AUTHTOK_ARG
;
497 else if (!strcasecmp(*v
, "use_first_pass"))
498 ctrl
|= WINBIND_USE_FIRST_PASS_ARG
;
499 else if (!strcasecmp(*v
, "try_first_pass"))
500 ctrl
|= WINBIND_TRY_FIRST_PASS_ARG
;
501 else if (!strcasecmp(*v
, "unknown_ok"))
502 ctrl
|= WINBIND_UNKNOWN_OK_ARG
;
503 else if ((type
== PAM_WINBIND_AUTHENTICATE
504 || type
== PAM_WINBIND_SETCRED
)
505 && !strncasecmp(*v
, "require_membership_of",
506 strlen("require_membership_of")))
507 ctrl
|= WINBIND_REQUIRED_MEMBERSHIP
;
508 else if ((type
== PAM_WINBIND_AUTHENTICATE
509 || type
== PAM_WINBIND_SETCRED
)
510 && !strncasecmp(*v
, "require-membership-of",
511 strlen("require-membership-of")))
512 ctrl
|= WINBIND_REQUIRED_MEMBERSHIP
;
513 else if (!strcasecmp(*v
, "krb5_auth"))
514 ctrl
|= WINBIND_KRB5_AUTH
;
515 else if (!strncasecmp(*v
, "krb5_ccache_type",
516 strlen("krb5_ccache_type")))
517 ctrl
|= WINBIND_KRB5_CCACHE_TYPE
;
518 else if (!strcasecmp(*v
, "cached_login"))
519 ctrl
|= WINBIND_CACHED_LOGIN
;
520 else if (!strcasecmp(*v
, "mkhomedir"))
521 ctrl
|= WINBIND_MKHOMEDIR
;
522 else if (!strncasecmp(*v
, "warn_pwd_expire",
523 strlen("warn_pwd_expire")))
524 ctrl
|= WINBIND_WARN_PWD_EXPIRE
;
525 else if (type
!= PAM_WINBIND_CLEANUP
) {
526 __pam_log(pamh
, ctrl
, LOG_ERR
,
527 "pam_parse: unknown option: %s", *v
);
537 tiniparser_freedict(d
);
544 static int _pam_winbind_free_context(struct pwb_context
*ctx
)
551 tiniparser_freedict(ctx
->dict
);
554 wbcCtxFree(ctx
->wbc_ctx
);
559 static int _pam_winbind_init_context(pam_handle_t
*pamh
,
563 enum pam_winbind_request_type type
,
564 struct pwb_context
**ctx_p
)
566 struct pwb_context
*r
= NULL
;
567 const char *service
= NULL
;
568 char service_name
[32] = {0};
575 r
= talloc_zero(NULL
, struct pwb_context
);
580 talloc_set_destructor(r
, _pam_winbind_free_context
);
586 ctrl_code
= _pam_parse(pamh
, flags
, argc
, argv
, type
, &r
->dict
);
587 if (ctrl_code
== -1) {
589 return PAM_SYSTEM_ERR
;
593 r
->wbc_ctx
= wbcCtxCreate();
594 if (r
->wbc_ctx
== NULL
) {
596 return PAM_SYSTEM_ERR
;
599 pam_get_item(pamh
, PAM_SERVICE
, (const void **)&service
);
601 snprintf(service_name
, sizeof(service_name
), "PAM_WINBIND[%s]", service
);
603 wbcSetClientProcessName(service_name
);
610 static void _pam_winbind_cleanup_func(pam_handle_t
*pamh
,
614 int ctrl
= _pam_parse(pamh
, 0, 0, NULL
, PAM_WINBIND_CLEANUP
, NULL
);
615 if (_pam_log_is_debug_state_enabled(ctrl
)) {
616 __pam_log_debug(pamh
, ctrl
, LOG_DEBUG
,
617 "[pamh: %p] CLEAN: cleaning up PAM data %p "
618 "(error_status = %d)", pamh
, data
,
625 static const struct ntstatus_errors
{
626 const char *ntstatus_string
;
627 const char *error_string
;
628 } ntstatus_errors
[] = {
631 {"NT_STATUS_BACKUP_CONTROLLER",
632 N_("No primary Domain Controller available")},
633 {"NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND",
634 N_("No domain controllers found")},
635 {"NT_STATUS_NO_LOGON_SERVERS",
636 N_("No logon servers")},
637 {"NT_STATUS_PWD_TOO_SHORT",
638 N_("Password too short")},
639 {"NT_STATUS_PWD_TOO_RECENT",
640 N_("The password was recently changed and cannot be changed again before %s")},
641 {"NT_STATUS_PWD_HISTORY_CONFLICT",
642 N_("Password is already in password history")},
643 {"NT_STATUS_PASSWORD_EXPIRED",
644 N_("Your password has expired")},
645 {"NT_STATUS_PASSWORD_MUST_CHANGE",
646 N_("You need to change your password now")},
647 {"NT_STATUS_INVALID_WORKSTATION",
648 N_("You are not allowed to logon from this workstation")},
649 {"NT_STATUS_INVALID_LOGON_HOURS",
650 N_("You are not allowed to logon at this time")},
651 {"NT_STATUS_ACCOUNT_EXPIRED",
652 N_("Your account has expired. "
653 "Please contact your System administrator")}, /* SCNR */
654 {"NT_STATUS_ACCOUNT_DISABLED",
655 N_("Your account is disabled. "
656 "Please contact your System administrator")}, /* SCNR */
657 {"NT_STATUS_ACCOUNT_LOCKED_OUT",
658 N_("Your account has been locked. "
659 "Please contact your System administrator")}, /* SCNR */
660 {"NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT",
661 N_("Invalid Trust Account")},
662 {"NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT",
663 N_("Invalid Trust Account")},
664 {"NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT",
665 N_("Invalid Trust Account")},
666 {"NT_STATUS_ACCESS_DENIED",
667 N_("Access is denied")},
671 static const char *_get_ntstatus_error_string(const char *nt_status_string
)
674 for (i
=0; ntstatus_errors
[i
].ntstatus_string
!= NULL
; i
++) {
675 if (!strcasecmp(ntstatus_errors
[i
].ntstatus_string
,
677 return _(ntstatus_errors
[i
].error_string
);
683 /* --- authentication management functions --- */
685 /* Attempt a conversation */
687 static int converse(const pam_handle_t
*pamh
,
689 const struct pam_message
**message
,
690 struct pam_response
**response
)
693 const struct pam_conv
*conv
;
695 retval
= pam_get_item(pamh
, PAM_CONV
, (const void **) &conv
);
696 if (retval
== PAM_SUCCESS
) {
697 retval
= conv
->conv(nargs
,
698 discard_const_p(const struct pam_message
*, message
),
699 response
, conv
->appdata_ptr
);
702 return retval
; /* propagate error status */
706 static int _make_remark(struct pwb_context
*ctx
,
710 int retval
= PAM_SUCCESS
;
712 const struct pam_message
*pmsg
[1];
713 struct pam_message msg
[1];
714 struct pam_response
*resp
;
716 if (ctx
->flags
& WINBIND_SILENT
) {
721 msg
[0].msg
= discard_const_p(char, text
);
722 msg
[0].msg_style
= type
;
725 retval
= converse(ctx
->pamh
, 1, pmsg
, &resp
);
728 _pam_drop_reply(resp
, 1);
733 static int _make_remark_v(struct pwb_context
*ctx
,
736 va_list args
) PRINTF_ATTRIBUTE(3, 0);
738 static int _make_remark_v(struct pwb_context
*ctx
,
746 ret
= vasprintf(&var
, format
, args
);
748 _pam_log(ctx
, LOG_ERR
, "memory allocation failure");
752 ret
= _make_remark(ctx
, type
, var
);
757 static int _make_remark_format(struct pwb_context
*ctx
, int type
, const char *format
, ...) PRINTF_ATTRIBUTE(3,4);
758 static int _make_remark_format(struct pwb_context
*ctx
, int type
, const char *format
, ...)
763 va_start(args
, format
);
764 ret
= _make_remark_v(ctx
, type
, format
, args
);
769 static int pam_winbind_request_log(struct pwb_context
*ctx
,
776 /* incorrect password */
777 _pam_log(ctx
, LOG_WARNING
, "user '%s' denied access "
778 "(incorrect password or invalid membership)", user
);
780 case PAM_ACCT_EXPIRED
:
781 /* account expired */
782 _pam_log(ctx
, LOG_WARNING
, "user '%s' account expired",
785 case PAM_AUTHTOK_EXPIRED
:
786 /* password expired */
787 _pam_log(ctx
, LOG_WARNING
, "user '%s' password expired",
790 case PAM_NEW_AUTHTOK_REQD
:
791 /* new password required */
792 _pam_log(ctx
, LOG_WARNING
, "user '%s' new password "
795 case PAM_USER_UNKNOWN
:
796 /* the user does not exist */
797 _pam_log_debug(ctx
, LOG_NOTICE
, "user '%s' not found",
799 if (ctx
->ctrl
& WINBIND_UNKNOWN_OK_ARG
) {
803 case PAM_AUTHTOK_ERR
:
804 /* Authentication token manipulation error */
805 _pam_log(ctx
, LOG_WARNING
, "user `%s' authentication token change failed "
806 "(pwd complexity/history/min_age not met?)", user
);
809 /* Otherwise, the authentication looked good */
810 if (strcmp(fn
, "wbcLogonUser") == 0) {
811 _pam_log(ctx
, LOG_NOTICE
,
812 "user '%s' granted access", user
);
814 _pam_log(ctx
, LOG_NOTICE
,
815 "user '%s' OK", user
);
819 /* we don't know anything about this return value */
820 _pam_log(ctx
, LOG_ERR
,
821 "internal module error (retval = %s(%d), user = '%s')",
822 _pam_error_code_str(retval
), retval
, user
);
827 static int wbc_auth_error_to_pam_error(struct pwb_context
*ctx
,
828 struct wbcAuthErrorInfo
*e
,
830 const char *username
,
833 int ret
= PAM_AUTH_ERR
;
835 if (WBC_ERROR_IS_OK(status
)) {
836 _pam_log_debug(ctx
, LOG_DEBUG
, "request %s succeeded",
839 return pam_winbind_request_log(ctx
, ret
, username
, fn
);
843 if (e
->pam_error
!= PAM_SUCCESS
) {
844 _pam_log(ctx
, LOG_ERR
,
845 "request %s failed: %s, "
846 "PAM error: %s (%d), NTSTATUS: %s, "
847 "Error message was: %s",
849 wbcErrorString(status
),
850 _pam_error_code_str(e
->pam_error
),
855 return pam_winbind_request_log(ctx
, ret
, username
, fn
);
858 _pam_log(ctx
, LOG_ERR
, "request %s failed, but PAM error 0!", fn
);
860 ret
= PAM_SERVICE_ERR
;
861 return pam_winbind_request_log(ctx
, ret
, username
, fn
);
864 ret
= wbc_error_to_pam_error(status
);
865 _pam_log(ctx
, LOG_ERR
,
866 "request %s failed: %s, PAM error: %s (%d)!",
867 fn
, wbcErrorString(status
),
868 _pam_error_code_str(ret
), ret
);
869 return pam_winbind_request_log(ctx
, ret
, username
, fn
);
872 #if defined(HAVE_PAM_RADIO_TYPE)
873 static bool _pam_winbind_change_pwd(struct pwb_context
*ctx
)
875 struct pam_message msg
;
876 const struct pam_message
*pmsg
;
877 struct pam_response
*resp
= NULL
;
881 msg
.msg_style
= PAM_RADIO_TYPE
;
882 msg
.msg
= _("Do you want to change your password now?");
883 ret
= converse(ctx
->pamh
, 1, &pmsg
, &resp
);
885 if (ret
== PAM_SUCCESS
) {
886 _pam_log(ctx
, LOG_CRIT
, "pam_winbind: system error!\n");
890 if (ret
!= PAM_SUCCESS
) {
893 _pam_log(ctx
, LOG_CRIT
, "Received [%s] reply from application.\n", resp
->resp
);
895 if ((resp
->resp
!= NULL
) && (strcasecmp(resp
->resp
, "yes") == 0)) {
899 _pam_drop_reply(resp
, 1);
903 static bool _pam_winbind_change_pwd(struct pwb_context
*ctx
)
910 * send a password expiry message if required
912 * @param ctx PAM winbind context.
913 * @param next_change expected (calculated) next expiry date.
914 * @param already_expired pointer to a boolean to indicate if the password is
917 * @return boolean Returns true if message has been sent, false if not.
920 static bool _pam_send_password_expiry_message(struct pwb_context
*ctx
,
924 bool *already_expired
,
928 struct tm tm_now
, tm_next_change
;
932 if (already_expired
) {
933 *already_expired
= false;
940 if (next_change
<= now
) {
941 PAM_WB_REMARK_DIRECT(ctx
, "NT_STATUS_PASSWORD_EXPIRED");
942 if (already_expired
) {
943 *already_expired
= true;
948 if ((next_change
< 0) ||
949 (next_change
> now
+ warn_pwd_expire
* SECONDS_PER_DAY
)) {
953 if ((localtime_r(&now
, &tm_now
) == NULL
) ||
954 (localtime_r(&next_change
, &tm_next_change
) == NULL
)) {
958 days
= (tm_next_change
.tm_yday
+tm_next_change
.tm_year
*365) -
959 (tm_now
.tm_yday
+tm_now
.tm_year
*365);
962 ret
= _make_remark(ctx
, PAM_TEXT_INFO
,
963 _("Your password expires today.\n"));
966 * If change_pwd and already_expired is null.
967 * We are just sending a notification message.
968 * We don't expect any response in this case.
971 if (!change_pwd
&& !already_expired
) {
976 * successfully sent the warning message.
977 * Give the user a chance to change pwd.
979 if (ret
== PAM_SUCCESS
) {
981 retval
= _pam_winbind_change_pwd(ctx
);
990 if (days
> 0 && days
< warn_pwd_expire
) {
992 ret
= _make_remark_format(ctx
, PAM_TEXT_INFO
,
993 _("Your password will expire in %d %s.\n"),
994 days
, (days
> 1) ? _("days"):_("day"));
996 * If change_pwd and already_expired is null.
997 * We are just sending a notification message.
998 * We don't expect any response in this case.
1001 if (!change_pwd
&& !already_expired
) {
1006 * successfully sent the warning message.
1007 * Give the user a chance to change pwd.
1009 if (ret
== PAM_SUCCESS
) {
1011 retval
= _pam_winbind_change_pwd(ctx
);
1024 * Send a warning if the password expires in the near future
1026 * @param ctx PAM winbind context.
1027 * @param response The full authentication response structure.
1028 * @param already_expired boolean, is the pwd already expired?
1033 static void _pam_warn_password_expiry(struct pwb_context
*ctx
,
1034 const struct wbcAuthUserInfo
*info
,
1035 int warn_pwd_expire
,
1036 bool *already_expired
,
1039 time_t now
= time(NULL
);
1040 time_t next_change
= 0;
1046 if (already_expired
) {
1047 *already_expired
= false;
1051 *change_pwd
= false;
1054 /* accounts with WBC_ACB_PWNOEXP set never receive a warning */
1055 if (info
->acct_flags
& WBC_ACB_PWNOEXP
) {
1059 /* no point in sending a warning if this is a grace logon */
1060 if (PAM_WB_GRACE_LOGON(info
->user_flags
)) {
1064 /* check if the info3 must change timestamp has been set */
1065 next_change
= info
->pass_must_change_time
;
1067 if (_pam_send_password_expiry_message(ctx
, next_change
, now
,
1074 /* no warning sent */
1077 #define IS_SID_STRING(name) (strncmp("S-", name, 2) == 0)
1080 * Append a string, making sure not to overflow and to always return a
1081 * NULL-terminated string.
1083 * @param dest Destination string buffer (must already be NULL-terminated).
1084 * @param src Source string buffer.
1085 * @param dest_buffer_size Size of dest buffer in bytes.
1087 * @return false if dest buffer is not big enough (no bytes copied), true on
1091 static bool safe_append_string(char *dest
,
1093 int dest_buffer_size
)
1096 len
= strlcat(dest
, src
, dest_buffer_size
);
1097 return (len
< dest_buffer_size
);
1101 * Convert a names into a SID string, appending it to a buffer.
1103 * @param ctx PAM winbind context.
1104 * @param user User in PAM request.
1105 * @param name Name to convert.
1106 * @param sid_list_buffer Where to append the string sid.
1107 * @param sid_list_buffer Size of sid_list_buffer (in bytes).
1109 * @return false on failure, true on success.
1111 static bool winbind_name_to_sid_string(struct pwb_context
*ctx
,
1114 char *sid_list_buffer
,
1115 int sid_list_buffer_size
)
1117 char sid_string
[WBC_SID_STRING_BUFLEN
];
1120 if (IS_SID_STRING(name
)) {
1121 strlcpy(sid_string
, name
, sizeof(sid_string
));
1124 struct wbcDomainSid sid
;
1125 enum wbcSidType type
;
1127 _pam_log_debug(ctx
, LOG_DEBUG
,
1128 "no sid given, looking up: %s\n", name
);
1130 wbc_status
= wbcCtxLookupName(ctx
->wbc_ctx
,
1135 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1136 _pam_log(ctx
, LOG_INFO
,
1137 "could not lookup name: %s\n", name
);
1141 wbcSidToStringBuf(&sid
, sid_string
, sizeof(sid_string
));
1144 if (!safe_append_string(sid_list_buffer
, sid_string
,
1145 sid_list_buffer_size
)) {
1152 * Convert a list of names into a list of sids.
1154 * @param ctx PAM winbind context.
1155 * @param user User in PAM request.
1156 * @param name_list List of names or string sids, separated by commas.
1157 * @param sid_list_buffer Where to put the list of string sids.
1158 * @param sid_list_buffer Size of sid_list_buffer (in bytes).
1160 * @return false on failure, true on success.
1162 static bool winbind_name_list_to_sid_string_list(struct pwb_context
*ctx
,
1164 const char *name_list
,
1165 char *sid_list_buffer
,
1166 int sid_list_buffer_size
)
1168 bool result
= false;
1169 char *current_name
= NULL
;
1170 const char *search_location
;
1174 if (sid_list_buffer_size
> 0) {
1175 sid_list_buffer
[0] = 0;
1178 search_location
= name_list
;
1179 while ((comma
= strchr(search_location
, ',')) != NULL
) {
1180 current_name
= strndup(search_location
,
1181 comma
- search_location
);
1182 if (NULL
== current_name
) {
1186 if (!winbind_name_to_sid_string(ctx
, user
,
1189 sid_list_buffer_size
)) {
1191 * If one group name failed, we must not fail
1192 * the authentication totally, continue with
1193 * the following group names. If user belongs to
1194 * one of the valid groups, we must allow it
1198 _pam_log(ctx
, LOG_INFO
, "cannot convert group %s to sid, "
1199 "check if group %s is valid group.", current_name
,
1201 _make_remark_format(ctx
, PAM_TEXT_INFO
, _("Cannot convert group %s "
1202 "to sid, please contact your administrator to see "
1203 "if group %s is valid."), current_name
, current_name
);
1204 SAFE_FREE(current_name
);
1205 search_location
= comma
+ 1;
1209 SAFE_FREE(current_name
);
1211 if (!safe_append_string(sid_list_buffer
, ",",
1212 sid_list_buffer_size
)) {
1216 search_location
= comma
+ 1;
1219 if (!winbind_name_to_sid_string(ctx
, user
, search_location
,
1221 sid_list_buffer_size
)) {
1222 _pam_log(ctx
, LOG_INFO
, "cannot convert group %s to sid, "
1223 "check if group %s is valid group.", search_location
,
1225 _make_remark_format(ctx
, PAM_TEXT_INFO
, _("Cannot convert group %s "
1226 "to sid, please contact your administrator to see "
1227 "if group %s is valid."), search_location
, search_location
);
1229 /* If no valid groups were converted we should fail outright */
1230 if (name_list
!= NULL
&& strlen(sid_list_buffer
) == 0) {
1235 * The lookup of the last name failed..
1236 * It results in require_member_of_sid ends with ','
1237 * It is malformatted parameter here, overwrite the last ','.
1239 len
= strlen(sid_list_buffer
);
1240 if ((len
!= 0) && (sid_list_buffer
[len
- 1] == ',')) {
1241 sid_list_buffer
[len
- 1] = '\0';
1248 SAFE_FREE(current_name
);
1253 * put krb5ccname variable into environment
1255 * @param ctx PAM winbind context.
1256 * @param krb5ccname env variable retrieved from winbindd.
1261 static void _pam_setup_krb5_env(struct pwb_context
*ctx
,
1262 struct wbcLogonUserInfo
*info
)
1267 const char *krb5ccname
= NULL
;
1269 if (off(ctx
->ctrl
, WINBIND_KRB5_AUTH
)) {
1277 for (i
=0; i
< info
->num_blobs
; i
++) {
1278 if (strcasecmp(info
->blobs
[i
].name
, "krb5ccname") == 0) {
1279 krb5ccname
= (const char *)info
->blobs
[i
].blob
.data
;
1284 if (!krb5ccname
|| (strlen(krb5ccname
) == 0)) {
1288 _pam_log_debug(ctx
, LOG_DEBUG
,
1289 "request returned KRB5CCNAME: %s", krb5ccname
);
1291 if (asprintf(&var
, "KRB5CCNAME=%s", krb5ccname
) == -1) {
1295 ret
= pam_putenv(ctx
->pamh
, var
);
1296 if (ret
!= PAM_SUCCESS
) {
1297 _pam_log(ctx
, LOG_ERR
,
1298 "failed to set KRB5CCNAME to %s: %s",
1299 var
, pam_strerror(ctx
->pamh
, ret
));
1305 * Copy unix username if available (further processed in PAM).
1307 * @param ctx PAM winbind context
1308 * @param user_ret A pointer that holds a pointer to a string
1309 * @param unix_username A username
1314 static void _pam_setup_unix_username(struct pwb_context
*ctx
,
1316 struct wbcLogonUserInfo
*info
)
1318 const char *unix_username
= NULL
;
1321 if (!user_ret
|| !info
) {
1325 for (i
=0; i
< info
->num_blobs
; i
++) {
1326 if (strcasecmp(info
->blobs
[i
].name
, "unix_username") == 0) {
1327 unix_username
= (const char *)info
->blobs
[i
].blob
.data
;
1332 if (!unix_username
|| !unix_username
[0]) {
1336 *user_ret
= strdup(unix_username
);
1340 * Set string into the PAM stack.
1342 * @param ctx PAM winbind context.
1343 * @param data_name Key name for pam_set_data.
1344 * @param value String value.
1349 static void _pam_set_data_string(struct pwb_context
*ctx
,
1350 const char *data_name
,
1355 if (!data_name
|| !value
|| (strlen(data_name
) == 0) ||
1356 (strlen(value
) == 0)) {
1360 ret
= pam_set_data(ctx
->pamh
, data_name
, talloc_strdup(NULL
, value
),
1361 _pam_winbind_cleanup_func
);
1362 if (ret
!= PAM_SUCCESS
) {
1363 _pam_log_debug(ctx
, LOG_DEBUG
,
1364 "Could not set data %s: %s\n",
1365 data_name
, pam_strerror(ctx
->pamh
, ret
));
1370 * Set info3 strings into the PAM stack.
1372 * @param ctx PAM winbind context.
1373 * @param data_name Key name for pam_set_data.
1374 * @param value String value.
1379 static void _pam_set_data_info3(struct pwb_context
*ctx
,
1380 const struct wbcAuthUserInfo
*info
)
1383 _pam_set_data_string(ctx
, PAM_WINBIND_HOMEDIR
,
1384 info
->home_directory
);
1385 _pam_set_data_string(ctx
, PAM_WINBIND_LOGONSCRIPT
,
1386 info
->logon_script
);
1387 _pam_set_data_string(ctx
, PAM_WINBIND_LOGONSERVER
,
1388 info
->logon_server
);
1389 _pam_set_data_string(ctx
, PAM_WINBIND_PROFILEPATH
,
1390 info
->profile_path
);
1395 * Free info3 strings in the PAM stack.
1397 * @param pamh PAM handle
1402 static void _pam_free_data_info3(pam_handle_t
*pamh
)
1404 pam_set_data(pamh
, PAM_WINBIND_HOMEDIR
, NULL
, NULL
);
1405 pam_set_data(pamh
, PAM_WINBIND_LOGONSCRIPT
, NULL
, NULL
);
1406 pam_set_data(pamh
, PAM_WINBIND_LOGONSERVER
, NULL
, NULL
);
1407 pam_set_data(pamh
, PAM_WINBIND_PROFILEPATH
, NULL
, NULL
);
1411 * Send PAM_ERROR_MSG for cached or grace logons.
1413 * @param ctx PAM winbind context.
1414 * @param username User in PAM request.
1415 * @param info3_user_flgs Info3 flags containing logon type bits.
1420 static void _pam_warn_logon_type(struct pwb_context
*ctx
,
1421 const char *username
,
1422 uint32_t info3_user_flgs
)
1424 /* inform about logon type */
1425 if (PAM_WB_GRACE_LOGON(info3_user_flgs
)) {
1427 _make_remark(ctx
, PAM_ERROR_MSG
,
1429 "Please change your password as soon you're "
1431 _pam_log_debug(ctx
, LOG_DEBUG
,
1432 "User %s logged on using grace logon\n",
1435 } else if (PAM_WB_CACHED_LOGON(info3_user_flgs
)) {
1437 _make_remark(ctx
, PAM_ERROR_MSG
,
1438 _("Domain Controller unreachable, "
1439 "using cached credentials instead. "
1440 "Network resources may be unavailable"));
1441 _pam_log_debug(ctx
, LOG_DEBUG
,
1442 "User %s logged on using cached credentials\n",
1448 * Send PAM_ERROR_MSG for krb5 errors.
1450 * @param ctx PAM winbind context.
1451 * @param username User in PAM request.
1452 * @param info3_user_flgs Info3 flags containing logon type bits.
1457 static void _pam_warn_krb5_failure(struct pwb_context
*ctx
,
1458 const char *username
,
1459 uint32_t info3_user_flgs
)
1461 if (PAM_WB_KRB5_CLOCK_SKEW(info3_user_flgs
)) {
1462 _make_remark(ctx
, PAM_ERROR_MSG
,
1463 _("Failed to establish your Kerberos Ticket cache "
1464 "due time differences\n"
1465 "with the domain controller. "
1466 "Please verify the system time.\n"));
1467 _pam_log_debug(ctx
, LOG_DEBUG
,
1468 "User %s: Clock skew when getting Krb5 TGT\n",
1473 static bool _pam_check_remark_auth_err(struct pwb_context
*ctx
,
1474 const struct wbcAuthErrorInfo
*e
,
1475 const char *nt_status_string
,
1478 const char *ntstatus
= NULL
;
1479 const char *error_string
= NULL
;
1481 if (!e
|| !pam_err
) {
1485 ntstatus
= e
->nt_string
;
1490 if (strcasecmp(ntstatus
, nt_status_string
) == 0) {
1492 error_string
= _get_ntstatus_error_string(nt_status_string
);
1494 _make_remark(ctx
, PAM_ERROR_MSG
, error_string
);
1495 *pam_err
= e
->pam_error
;
1499 if (e
->display_string
) {
1500 _make_remark(ctx
, PAM_ERROR_MSG
, _(e
->display_string
));
1501 *pam_err
= e
->pam_error
;
1505 _make_remark(ctx
, PAM_ERROR_MSG
, nt_status_string
);
1506 *pam_err
= e
->pam_error
;
1515 * Compose Password Restriction String for a PAM_ERROR_MSG conversation.
1517 * @param i The wbcUserPasswordPolicyInfo struct.
1519 * @return string (caller needs to talloc_free).
1522 static char *_pam_compose_pwd_restriction_string(struct pwb_context
*ctx
,
1523 struct wbcUserPasswordPolicyInfo
*i
)
1531 str
= talloc_asprintf(ctx
, _("Your password "));
1536 if (i
->min_length_password
> 0) {
1537 str
= talloc_asprintf_append(str
,
1538 _("must be at least %d characters; "),
1539 i
->min_length_password
);
1545 if (i
->password_history
> 0) {
1546 str
= talloc_asprintf_append(str
,
1547 _("cannot repeat any of your previous %d "
1549 i
->password_history
);
1555 if (i
->password_properties
& WBC_DOMAIN_PASSWORD_COMPLEX
) {
1556 str
= talloc_asprintf_append(str
,
1557 _("must contain capitals, numerals "
1559 "and cannot contain your account "
1566 str
= talloc_asprintf_append(str
,
1567 _("Please type a different password. "
1568 "Type a password which meets these requirements in "
1569 "both text boxes."));
1581 static int _pam_create_homedir(struct pwb_context
*ctx
,
1582 const char *dirname
,
1587 ret
= mkdir(dirname
, mode
);
1588 if (ret
!= 0 && errno
== EEXIST
) {
1591 ret
= stat(dirname
, &sbuf
);
1593 return PAM_PERM_DENIED
;
1596 if (!S_ISDIR(sbuf
.st_mode
)) {
1597 return PAM_PERM_DENIED
;
1602 _make_remark_format(ctx
, PAM_TEXT_INFO
,
1603 _("Creating directory: %s failed: %s"),
1604 dirname
, strerror(errno
));
1605 _pam_log(ctx
, LOG_ERR
, "could not create dir: %s (%s)",
1606 dirname
, strerror(errno
));
1607 return PAM_PERM_DENIED
;
1613 static int _pam_chown_homedir(struct pwb_context
*ctx
,
1614 const char *dirname
,
1618 if (chown(dirname
, uid
, gid
) != 0) {
1619 _pam_log(ctx
, LOG_ERR
, "failed to chown user homedir: %s (%s)",
1620 dirname
, strerror(errno
));
1621 return PAM_PERM_DENIED
;
1627 static int _pam_mkhomedir(struct pwb_context
*ctx
)
1629 struct passwd
*pwd
= NULL
;
1631 char *create_dir
= NULL
;
1632 char *user_dir
= NULL
;
1634 const char *username
;
1636 char *safe_ptr
= NULL
;
1639 /* Get the username */
1640 ret
= pam_get_user(ctx
->pamh
, &username
, NULL
);
1641 if ((ret
!= PAM_SUCCESS
) || (!username
)) {
1642 _pam_log_debug(ctx
, LOG_DEBUG
, "can not get the username");
1643 return PAM_SERVICE_ERR
;
1646 pwd
= getpwnam(username
);
1648 _pam_log_debug(ctx
, LOG_DEBUG
, "can not get the username");
1649 return PAM_USER_UNKNOWN
;
1651 _pam_log_debug(ctx
, LOG_DEBUG
, "homedir is: %s", pwd
->pw_dir
);
1653 ret
= _pam_create_homedir(ctx
, pwd
->pw_dir
, 0700);
1654 if (ret
== PAM_SUCCESS
) {
1655 ret
= _pam_chown_homedir(ctx
, pwd
->pw_dir
,
1660 if (ret
== PAM_SUCCESS
) {
1664 /* maybe we need to create parent dirs */
1665 create_dir
= talloc_strdup(ctx
, "/");
1670 /* find final directory */
1671 user_dir
= strrchr(pwd
->pw_dir
, '/');
1677 _pam_log(ctx
, LOG_DEBUG
, "final directory: %s", user_dir
);
1681 while ((token
= strtok_r(p
, "/", &safe_ptr
)) != NULL
) {
1687 _pam_log_debug(ctx
, LOG_DEBUG
, "token is %s", token
);
1689 create_dir
= talloc_asprintf_append(create_dir
, "%s/", token
);
1693 _pam_log_debug(ctx
, LOG_DEBUG
, "current_dir is %s", create_dir
);
1695 if (strcmp(token
, user_dir
) == 0) {
1696 _pam_log_debug(ctx
, LOG_DEBUG
, "assuming last directory: %s", token
);
1700 ret
= _pam_create_homedir(ctx
, create_dir
, mode
);
1701 if (ret
!= PAM_SUCCESS
) {
1706 return _pam_chown_homedir(ctx
, create_dir
,
1711 /* talk to winbindd */
1712 static int winbind_auth_request(struct pwb_context
*ctx
,
1717 const int warn_pwd_expire
,
1718 struct wbcAuthErrorInfo
**p_error
,
1719 struct wbcLogonUserInfo
**p_info
,
1720 time_t *pwd_last_set
,
1724 struct wbcLogonUserParams logon
;
1725 char membership_of
[1024];
1726 uid_t user_uid
= -1;
1727 uint32_t flags
= WBFLAG_PAM_INFO3_TEXT
;
1728 struct wbcLogonUserInfo
*info
= NULL
;
1729 struct wbcAuthUserInfo
*user_info
= NULL
;
1730 struct wbcAuthErrorInfo
*error
= NULL
;
1731 int ret
= PAM_AUTH_ERR
;
1733 const char *codes
[] = {
1734 "NT_STATUS_PASSWORD_EXPIRED",
1735 "NT_STATUS_PASSWORD_MUST_CHANGE",
1736 "NT_STATUS_INVALID_WORKSTATION",
1737 "NT_STATUS_INVALID_LOGON_HOURS",
1738 "NT_STATUS_ACCOUNT_EXPIRED",
1739 "NT_STATUS_ACCOUNT_DISABLED",
1740 "NT_STATUS_ACCOUNT_LOCKED_OUT",
1741 "NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT",
1742 "NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT",
1743 "NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT",
1744 "NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND",
1745 "NT_STATUS_NO_LOGON_SERVERS",
1746 "NT_STATUS_WRONG_PASSWORD",
1747 "NT_STATUS_ACCESS_DENIED"
1754 /* Krb5 auth always has to go against the KDC of the user's realm */
1756 if (ctx
->ctrl
& WINBIND_KRB5_AUTH
) {
1757 flags
|= WBFLAG_PAM_CONTACT_TRUSTDOM
;
1760 if (ctx
->ctrl
& (WINBIND_KRB5_AUTH
|WINBIND_CACHED_LOGIN
)) {
1761 struct passwd
*pwd
= NULL
;
1763 pwd
= getpwnam(user
);
1765 return PAM_USER_UNKNOWN
;
1767 user_uid
= pwd
->pw_uid
;
1770 if (ctx
->ctrl
& WINBIND_KRB5_AUTH
) {
1772 _pam_log_debug(ctx
, LOG_DEBUG
,
1773 "enabling krb5 login flag\n");
1775 flags
|= WBFLAG_PAM_KRB5
|
1776 WBFLAG_PAM_FALLBACK_AFTER_KRB5
;
1779 if (ctx
->ctrl
& WINBIND_CACHED_LOGIN
) {
1780 _pam_log_debug(ctx
, LOG_DEBUG
,
1781 "enabling cached login flag\n");
1782 flags
|= WBFLAG_PAM_CACHED_LOGIN
;
1787 flags
|= WBFLAG_PAM_UNIX_NAME
;
1790 if (cctype
!= NULL
) {
1791 _pam_log_debug(ctx
, LOG_DEBUG
,
1792 "enabling request for a %s krb5 ccache\n",
1796 if (member
!= NULL
) {
1798 ZERO_STRUCT(membership_of
);
1800 if (!winbind_name_list_to_sid_string_list(ctx
, user
, member
,
1802 sizeof(membership_of
))) {
1803 _pam_log_debug(ctx
, LOG_ERR
,
1804 "failed to serialize membership of sid "
1805 "\"%s\"\n", member
);
1806 return PAM_AUTH_ERR
;
1812 logon
.username
= user
;
1813 logon
.password
= pass
;
1816 wbc_status
= wbcAddNamedBlob(&logon
.num_blobs
,
1820 discard_const_p(uint8_t, cctype
),
1822 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1827 wbc_status
= wbcAddNamedBlob(&logon
.num_blobs
,
1833 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1837 wbc_status
= wbcAddNamedBlob(&logon
.num_blobs
,
1841 (uint8_t *)&user_uid
,
1843 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1848 wbc_status
= wbcAddNamedBlob(&logon
.num_blobs
,
1852 (uint8_t *)membership_of
,
1853 sizeof(membership_of
));
1854 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1859 wbc_status
= wbcCtxLogonUser(ctx
->wbc_ctx
,
1864 ret
= wbc_auth_error_to_pam_error(ctx
, error
, wbc_status
,
1865 user
, "wbcLogonUser");
1866 wbcFreeMemory(logon
.blobs
);
1869 if (info
&& info
->info
) {
1870 user_info
= info
->info
;
1873 if (pwd_last_set
&& user_info
) {
1874 *pwd_last_set
= user_info
->pass_last_set_time
;
1877 if (p_info
&& info
) {
1881 if (p_error
&& error
) {
1882 /* We want to process the error in the caller. */
1887 for (i
=0; i
<ARRAY_SIZE(codes
); i
++) {
1889 if (_pam_check_remark_auth_err(ctx
, error
, codes
[i
], &_ret
)) {
1895 if ((ret
== PAM_SUCCESS
) && user_info
&& info
) {
1897 bool already_expired
= false;
1898 bool change_pwd
= false;
1900 /* warn a user if the password is about to expire soon */
1901 _pam_warn_password_expiry(ctx
, user_info
,
1906 if (already_expired
== true) {
1908 SMB_TIME_T last_set
= user_info
->pass_last_set_time
;
1909 SMB_TIME_T must_set
= user_info
->pass_must_change_time
;
1911 _pam_log_debug(ctx
, LOG_DEBUG
,
1912 "Password has expired "
1913 "(Password was last set: %lld, "
1914 "it must be changed here "
1915 "%lld (now it's: %ld))\n",
1916 (long long int)last_set
,
1917 (long long int)must_set
,
1920 return PAM_AUTHTOK_EXPIRED
;
1924 ret
= PAM_NEW_AUTHTOK_REQD
;
1928 /* inform about logon type */
1929 _pam_warn_logon_type(ctx
, user
, user_info
->user_flags
);
1931 /* inform about krb5 failures */
1932 _pam_warn_krb5_failure(ctx
, user
, user_info
->user_flags
);
1934 /* set some info3 info for other modules in the stack */
1935 _pam_set_data_info3(ctx
, user_info
);
1937 /* put krb5ccname into env */
1938 _pam_setup_krb5_env(ctx
, info
);
1940 /* If winbindd returned a username, return the pointer to it
1942 _pam_setup_unix_username(ctx
, user_ret
, info
);
1946 wbcFreeMemory(logon
.blobs
);
1947 if (info
&& info
->blobs
&& !p_info
) {
1948 wbcFreeMemory(info
->blobs
);
1950 * We set blobs to NULL to prevent a use after free in the
1951 * in the wbcLogonUserInfoDestructor
1955 if (error
&& !p_error
) {
1956 wbcFreeMemory(error
);
1958 if (info
&& !p_info
) {
1959 wbcFreeMemory(info
);
1965 /* talk to winbindd */
1966 static int winbind_chauthtok_request(struct pwb_context
*ctx
,
1968 const char *oldpass
,
1969 const char *newpass
,
1970 time_t pwd_last_set
)
1973 struct wbcChangePasswordParams params
;
1974 struct wbcAuthErrorInfo
*error
= NULL
;
1975 struct wbcUserPasswordPolicyInfo
*policy
= NULL
;
1976 enum wbcPasswordChangeRejectReason reject_reason
= -1;
1980 const char *codes
[] = {
1981 "NT_STATUS_BACKUP_CONTROLLER",
1982 "NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND",
1983 "NT_STATUS_NO_LOGON_SERVERS",
1984 "NT_STATUS_ACCESS_DENIED",
1985 "NT_STATUS_PWD_TOO_SHORT", /* TODO: tell the min pwd length ? */
1986 "NT_STATUS_PWD_TOO_RECENT", /* TODO: tell the minage ? */
1987 "NT_STATUS_PWD_HISTORY_CONFLICT" /* TODO: tell the history length ? */
1989 int ret
= PAM_AUTH_ERR
;
1991 ZERO_STRUCT(params
);
1993 if (ctx
->ctrl
& WINBIND_KRB5_AUTH
) {
1994 flags
|= WBFLAG_PAM_KRB5
|
1995 WBFLAG_PAM_CONTACT_TRUSTDOM
;
1998 if (ctx
->ctrl
& WINBIND_CACHED_LOGIN
) {
1999 flags
|= WBFLAG_PAM_CACHED_LOGIN
;
2002 params
.account_name
= user
;
2003 params
.level
= WBC_CHANGE_PASSWORD_LEVEL_PLAIN
;
2004 params
.old_password
.plaintext
= oldpass
;
2005 params
.new_password
.plaintext
= newpass
;
2006 params
.flags
= flags
;
2008 wbc_status
= wbcCtxChangeUserPasswordEx(ctx
->wbc_ctx
,
2013 ret
= wbc_auth_error_to_pam_error(ctx
, error
, wbc_status
,
2014 user
, "wbcChangeUserPasswordEx");
2016 if (WBC_ERROR_IS_OK(wbc_status
)) {
2017 _pam_log(ctx
, LOG_NOTICE
,
2018 "user '%s' password changed", user
);
2023 wbcFreeMemory(policy
);
2027 for (i
=0; i
<ARRAY_SIZE(codes
); i
++) {
2029 if (_pam_check_remark_auth_err(ctx
, error
, codes
[i
], &_ret
)) {
2035 if (!strcasecmp(error
->nt_string
,
2036 "NT_STATUS_PASSWORD_RESTRICTION")) {
2038 char *pwd_restriction_string
= NULL
;
2039 SMB_TIME_T min_pwd_age
= 0;
2042 min_pwd_age
= policy
->min_passwordage
;
2045 /* FIXME: avoid to send multiple PAM messages after another */
2046 switch ((int)reject_reason
) {
2049 case WBC_PWD_CHANGE_NO_ERROR
:
2050 if ((min_pwd_age
> 0) &&
2051 (pwd_last_set
+ min_pwd_age
> time(NULL
))) {
2052 time_t next_change
= pwd_last_set
+ min_pwd_age
;
2053 _make_remark_format(ctx
, PAM_ERROR_MSG
,
2054 _get_ntstatus_error_string("NT_STATUS_PWD_TOO_RECENT"),
2055 ctime(&next_change
));
2059 case WBC_PWD_CHANGE_PASSWORD_TOO_SHORT
:
2060 PAM_WB_REMARK_DIRECT(ctx
,
2061 "NT_STATUS_PWD_TOO_SHORT");
2063 case WBC_PWD_CHANGE_PWD_IN_HISTORY
:
2064 PAM_WB_REMARK_DIRECT(ctx
,
2065 "NT_STATUS_PWD_HISTORY_CONFLICT");
2067 case WBC_PWD_CHANGE_NOT_COMPLEX
:
2068 _make_remark(ctx
, PAM_ERROR_MSG
,
2069 _("Password does not meet "
2070 "complexity requirements"));
2073 _pam_log_debug(ctx
, LOG_DEBUG
,
2074 "unknown password change "
2075 "reject reason: %d",
2080 pwd_restriction_string
=
2081 _pam_compose_pwd_restriction_string(ctx
, policy
);
2082 if (pwd_restriction_string
) {
2083 _make_remark(ctx
, PAM_ERROR_MSG
,
2084 pwd_restriction_string
);
2085 TALLOC_FREE(pwd_restriction_string
);
2089 wbcFreeMemory(error
);
2090 wbcFreeMemory(policy
);
2096 * Checks if a user has an account
2099 * 1 = User not found
2103 static int valid_user(struct pwb_context
*ctx
,
2106 /* check not only if the user is available over NSS calls, also make
2107 * sure it's really a winbind user, this is important when stacking PAM
2108 * modules in the 'account' or 'password' facility. */
2111 struct passwd
*pwd
= NULL
;
2112 struct passwd
*wb_pwd
= NULL
;
2114 pwd
= getpwnam(user
);
2119 wbc_status
= wbcCtxGetpwnam(ctx
->wbc_ctx
, user
, &wb_pwd
);
2120 wbcFreeMemory(wb_pwd
);
2121 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2122 _pam_log(ctx
, LOG_DEBUG
, "valid_user: wbcGetpwnam gave %s\n",
2123 wbcErrorString(wbc_status
));
2126 switch (wbc_status
) {
2127 case WBC_ERR_UNKNOWN_USER
:
2128 /* match other insane libwbclient return codes */
2129 case WBC_ERR_WINBIND_NOT_AVAILABLE
:
2130 case WBC_ERR_DOMAIN_NOT_FOUND
:
2132 case WBC_ERR_SUCCESS
:
2140 static char *_pam_delete(register char *xx
)
2148 * obtain a password from the user
2151 static int _winbind_read_password(struct pwb_context
*ctx
,
2153 const char *comment
,
2154 const char *prompt1
,
2155 const char *prompt2
,
2163 _pam_log(ctx
, LOG_DEBUG
, "getting password (0x%08x)", ctrl
);
2166 * make sure nothing inappropriate gets returned
2169 *pass
= token
= NULL
;
2172 * which authentication token are we getting?
2175 if (on(WINBIND__OLD_PASSWORD
, ctrl
)) {
2176 authtok_flag
= PAM_OLDAUTHTOK
;
2178 authtok_flag
= PAM_AUTHTOK
;
2182 * should we obtain the password from a PAM item ?
2185 if (on(WINBIND_TRY_FIRST_PASS_ARG
, ctrl
) ||
2186 on(WINBIND_USE_FIRST_PASS_ARG
, ctrl
)) {
2187 retval
= pam_get_item(ctx
->pamh
,
2189 (const void **) &item
);
2190 if (retval
!= PAM_SUCCESS
) {
2192 _pam_log(ctx
, LOG_ALERT
,
2193 "pam_get_item returned error "
2194 "to unix-read-password");
2196 } else if (item
!= NULL
) { /* we have a password! */
2199 _pam_log(ctx
, LOG_DEBUG
,
2200 "pam_get_item returned a password");
2202 } else if (on(WINBIND_USE_FIRST_PASS_ARG
, ctrl
)) {
2203 return PAM_AUTHTOK_RECOVER_ERR
; /* didn't work */
2204 } else if (on(WINBIND_USE_AUTHTOK_ARG
, ctrl
)
2205 && off(WINBIND__OLD_PASSWORD
, ctrl
)) {
2206 return PAM_AUTHTOK_RECOVER_ERR
;
2210 * getting here implies we will have to get the password from the
2215 struct pam_message msg
[3];
2216 const struct pam_message
*pmsg
[3];
2217 struct pam_response
*resp
;
2220 /* prepare to converse */
2222 if (comment
!= NULL
&& off(ctrl
, WINBIND_SILENT
)) {
2224 msg
[0].msg_style
= PAM_TEXT_INFO
;
2225 msg
[0].msg
= discard_const_p(char, comment
);
2232 msg
[i
].msg_style
= PAM_PROMPT_ECHO_OFF
;
2233 msg
[i
++].msg
= discard_const_p(char, prompt1
);
2236 if (prompt2
!= NULL
) {
2238 msg
[i
].msg_style
= PAM_PROMPT_ECHO_OFF
;
2239 msg
[i
++].msg
= discard_const_p(char, prompt2
);
2242 /* so call the conversation expecting i responses */
2244 retval
= converse(ctx
->pamh
, i
, pmsg
, &resp
);
2246 if (retval
== PAM_SUCCESS
) {
2247 retval
= PAM_AUTHTOK_RECOVER_ERR
;
2251 if (retval
!= PAM_SUCCESS
) {
2252 _pam_drop_reply(resp
, i
);
2256 /* interpret the response */
2258 token
= x_strdup(resp
[i
- replies
].resp
);
2260 _pam_log(ctx
, LOG_NOTICE
,
2261 "could not recover "
2262 "authentication token");
2263 retval
= PAM_AUTHTOK_RECOVER_ERR
;
2268 /* verify that password entered correctly */
2269 if (!resp
[i
- 1].resp
||
2270 strcmp(token
, resp
[i
- 1].resp
)) {
2271 _pam_delete(token
); /* mistyped */
2272 retval
= PAM_AUTHTOK_RECOVER_ERR
;
2273 _make_remark(ctx
, PAM_ERROR_MSG
,
2279 * tidy up the conversation (resp_retcode) is ignored
2280 * -- what is it for anyway? AGM
2282 _pam_drop_reply(resp
, i
);
2286 if (retval
!= PAM_SUCCESS
) {
2287 _pam_log_debug(ctx
, LOG_DEBUG
,
2288 "unable to obtain a password");
2291 /* 'token' is the entered password */
2293 /* we store this password as an item */
2295 retval
= pam_set_item(ctx
->pamh
, authtok_flag
, token
);
2296 _pam_delete(token
); /* clean it up */
2297 if (retval
!= PAM_SUCCESS
||
2298 (retval
= pam_get_item(ctx
->pamh
, authtok_flag
, (const void **) &item
)) != PAM_SUCCESS
) {
2300 _pam_log(ctx
, LOG_CRIT
, "error manipulating password");
2306 item
= NULL
; /* break link to password */
2311 static const char *get_conf_item_string(struct pwb_context
*ctx
,
2316 const char *parm_opt
= NULL
;
2318 if (!(ctx
->ctrl
& config_flag
)) {
2322 /* let the pam opt take precedence over the pam_winbind.conf option */
2323 for (i
=0; i
<ctx
->argc
; i
++) {
2325 if ((strncmp(ctx
->argv
[i
], item
, strlen(item
)) == 0)) {
2328 if ((p
= strchr(ctx
->argv
[i
], '=')) == NULL
) {
2329 _pam_log(ctx
, LOG_INFO
,
2330 "no \"=\" delimiter for \"%s\" found\n",
2334 _pam_log_debug(ctx
, LOG_INFO
,
2335 "PAM config: %s '%s'\n", item
, p
+1);
2343 key
= talloc_asprintf(ctx
, "global:%s", item
);
2348 parm_opt
= tiniparser_getstring_nonempty(ctx
->dict
, key
, NULL
);
2351 _pam_log_debug(ctx
, LOG_INFO
, "CONFIG file: %s '%s'\n",
2358 static int get_config_item_int(struct pwb_context
*ctx
,
2362 int i
, parm_opt
= -1;
2364 if (!(ctx
->ctrl
& config_flag
)) {
2368 /* let the pam opt take precedence over the pam_winbind.conf option */
2369 for (i
= 0; i
< ctx
->argc
; i
++) {
2371 if ((strncmp(ctx
->argv
[i
], item
, strlen(item
)) == 0)) {
2374 if ((p
= strchr(ctx
->argv
[i
], '=')) == NULL
) {
2375 _pam_log(ctx
, LOG_INFO
,
2376 "no \"=\" delimiter for \"%s\" found\n",
2380 parm_opt
= atoi(p
+ 1);
2381 _pam_log_debug(ctx
, LOG_INFO
,
2382 "PAM config: %s '%d'\n",
2391 key
= talloc_asprintf(ctx
, "global:%s", item
);
2396 parm_opt
= tiniparser_getint(ctx
->dict
, key
, -1);
2399 _pam_log_debug(ctx
, LOG_INFO
,
2400 "CONFIG file: %s '%d'\n",
2407 static const char *get_krb5_cc_type_from_config(struct pwb_context
*ctx
)
2409 return get_conf_item_string(ctx
, "krb5_ccache_type",
2410 WINBIND_KRB5_CCACHE_TYPE
);
2413 static const char *get_member_from_config(struct pwb_context
*ctx
)
2415 const char *ret
= NULL
;
2416 ret
= get_conf_item_string(ctx
, "require_membership_of",
2417 WINBIND_REQUIRED_MEMBERSHIP
);
2421 return get_conf_item_string(ctx
, "require-membership-of",
2422 WINBIND_REQUIRED_MEMBERSHIP
);
2425 static int get_warn_pwd_expire_from_config(struct pwb_context
*ctx
)
2428 ret
= get_config_item_int(ctx
, "warn_pwd_expire",
2429 WINBIND_WARN_PWD_EXPIRE
);
2430 /* no or broken setting */
2432 return DEFAULT_DAYS_TO_WARN_BEFORE_PWD_EXPIRES
;
2438 * Retrieve the winbind separator.
2440 * @param ctx PAM winbind context.
2442 * @return string separator character. NULL on failure.
2445 static char winbind_get_separator(struct pwb_context
*ctx
)
2448 static struct wbcInterfaceDetails
*details
= NULL
;
2450 wbc_status
= wbcCtxInterfaceDetails(ctx
->wbc_ctx
, &details
);
2451 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2452 _pam_log(ctx
, LOG_ERR
,
2453 "Could not retrieve winbind interface details: %s",
2454 wbcErrorString(wbc_status
));
2462 return details
->winbind_separator
;
2467 * Convert a upn to a name.
2469 * @param ctx PAM winbind context.
2470 * @param upn User UPN to be translated.
2472 * @return converted name. NULL pointer on failure. Caller needs to free.
2475 static char* winbind_upn_to_username(struct pwb_context
*ctx
,
2479 wbcErr wbc_status
= WBC_ERR_UNKNOWN_FAILURE
;
2480 struct wbcDomainSid sid
;
2481 enum wbcSidType type
;
2482 char *domain
= NULL
;
2487 /* This cannot work when the winbind separator = @ */
2489 sep
= winbind_get_separator(ctx
);
2490 if (!sep
|| sep
== '@') {
2494 name
= talloc_strdup(ctx
, upn
);
2499 p
= strchr(name
, '@');
2507 /* Convert the UPN to a SID */
2509 wbc_status
= wbcCtxLookupName(ctx
->wbc_ctx
, domain
, name
, &sid
, &type
);
2510 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2514 /* Convert the the SID back to the sAMAccountName */
2516 wbc_status
= wbcCtxLookupSid(ctx
->wbc_ctx
, &sid
, &domain
, &name
, &type
);
2517 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2521 result
= talloc_asprintf(ctx
, "%s%c%s", domain
, sep
, name
);
2522 wbcFreeMemory(domain
);
2523 wbcFreeMemory(name
);
2527 static int _pam_delete_cred(pam_handle_t
*pamh
, int flags
,
2528 int argc
, enum pam_winbind_request_type type
,
2531 int retval
= PAM_SUCCESS
;
2532 struct pwb_context
*ctx
= NULL
;
2533 struct wbcLogoffUserParams logoff
;
2534 struct wbcAuthErrorInfo
*error
= NULL
;
2536 wbcErr wbc_status
= WBC_ERR_SUCCESS
;
2538 ZERO_STRUCT(logoff
);
2540 retval
= _pam_winbind_init_context(pamh
, flags
, argc
, argv
, type
, &ctx
);
2541 if (retval
!= PAM_SUCCESS
) {
2545 _PAM_LOG_FUNCTION_ENTER("_pam_delete_cred", ctx
);
2547 if (ctx
->ctrl
& WINBIND_KRB5_AUTH
) {
2549 /* destroy the ccache here */
2551 uint32_t wbc_flags
= 0;
2552 const char *ccname
= NULL
;
2553 struct passwd
*pwd
= NULL
;
2555 retval
= pam_get_user(pamh
, &user
, _("Username: "));
2556 if (retval
!= PAM_SUCCESS
) {
2557 _pam_log(ctx
, LOG_ERR
,
2558 "could not identify user");
2563 _pam_log(ctx
, LOG_ERR
,
2564 "username was NULL!");
2565 retval
= PAM_USER_UNKNOWN
;
2569 _pam_log_debug(ctx
, LOG_DEBUG
,
2570 "username [%s] obtained", user
);
2572 ccname
= pam_getenv(pamh
, "KRB5CCNAME");
2573 if (ccname
== NULL
) {
2574 _pam_log_debug(ctx
, LOG_DEBUG
,
2575 "user has no KRB5CCNAME environment");
2578 pwd
= getpwnam(user
);
2580 retval
= PAM_USER_UNKNOWN
;
2584 wbc_flags
= WBFLAG_PAM_KRB5
|
2585 WBFLAG_PAM_CONTACT_TRUSTDOM
;
2587 logoff
.username
= user
;
2590 wbc_status
= wbcAddNamedBlob(&logoff
.num_blobs
,
2594 discard_const_p(uint8_t, ccname
),
2596 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2601 wbc_status
= wbcAddNamedBlob(&logoff
.num_blobs
,
2605 (uint8_t *)&wbc_flags
,
2607 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2611 wbc_status
= wbcAddNamedBlob(&logoff
.num_blobs
,
2615 (uint8_t *)&pwd
->pw_uid
,
2616 sizeof(pwd
->pw_uid
));
2617 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2621 wbc_status
= wbcCtxLogoffUserEx(ctx
->wbc_ctx
, &logoff
, &error
);
2622 retval
= wbc_auth_error_to_pam_error(ctx
, error
, wbc_status
,
2623 user
, "wbcLogoffUser");
2624 wbcFreeMemory(logoff
.blobs
);
2625 logoff
.blobs
= NULL
;
2627 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2628 _pam_log(ctx
, LOG_INFO
,
2629 "failed to logoff user %s: %s\n",
2630 user
, wbcErrorString(wbc_status
));
2636 wbcFreeMemory(logoff
.blobs
);
2639 if (!WBC_ERROR_IS_OK(wbc_status
)) {
2640 retval
= wbc_auth_error_to_pam_error(ctx
, error
, wbc_status
,
2641 user
, "wbcLogoffUser");
2643 wbcFreeMemory(error
);
2646 * Delete the krb5 ccname variable from the PAM environment
2647 * if it was set by winbind.
2649 if ((ctx
->ctrl
& WINBIND_KRB5_AUTH
) && pam_getenv(pamh
, "KRB5CCNAME")) {
2650 pam_putenv(pamh
, "KRB5CCNAME");
2653 _PAM_LOG_FUNCTION_LEAVE("_pam_delete_cred", ctx
, retval
);
2660 #ifdef SECURITY_OPENPAM_H_INCLUDED
2662 * Logic below is copied from openpam_check_error_code() in
2663 *./contrib/openpam/lib/libpam/openpam_dispatch.c on FreeBSD.
2665 static int openpam_convert_error_code(struct pwb_context
*ctx
,
2666 enum pam_winbind_request_type req
,
2669 if (r
== PAM_SUCCESS
||
2670 r
== PAM_SYSTEM_ERR
||
2671 r
== PAM_SERVICE_ERR
||
2673 r
== PAM_CONV_ERR
||
2674 r
== PAM_PERM_DENIED
||
2679 /* specific winbind request types */
2681 case PAM_WINBIND_AUTHENTICATE
:
2682 if (r
== PAM_AUTH_ERR
||
2683 r
== PAM_CRED_INSUFFICIENT
||
2684 r
== PAM_AUTHINFO_UNAVAIL
||
2685 r
== PAM_USER_UNKNOWN
||
2686 r
== PAM_MAXTRIES
) {
2690 case PAM_WINBIND_SETCRED
:
2691 if (r
== PAM_CRED_UNAVAIL
||
2692 r
== PAM_CRED_EXPIRED
||
2693 r
== PAM_USER_UNKNOWN
||
2694 r
== PAM_CRED_ERR
) {
2698 case PAM_WINBIND_ACCT_MGMT
:
2699 if (r
== PAM_USER_UNKNOWN
||
2700 r
== PAM_AUTH_ERR
||
2701 r
== PAM_NEW_AUTHTOK_REQD
||
2702 r
== PAM_ACCT_EXPIRED
) {
2706 case PAM_WINBIND_OPEN_SESSION
:
2707 case PAM_WINBIND_CLOSE_SESSION
:
2708 if (r
== PAM_SESSION_ERR
) {
2712 case PAM_WINBIND_CHAUTHTOK
:
2713 if (r
== PAM_PERM_DENIED
||
2714 r
== PAM_AUTHTOK_ERR
||
2715 r
== PAM_AUTHTOK_RECOVERY_ERR
||
2716 r
== PAM_AUTHTOK_LOCK_BUSY
||
2717 r
== PAM_AUTHTOK_DISABLE_AGING
||
2718 r
== PAM_TRY_AGAIN
) {
2725 _pam_log(ctx
, LOG_INFO
,
2726 "Converting PAM error [%d] to PAM_SERVICE_ERR.\n", r
);
2727 return PAM_SERVICE_ERR
;
2729 #define pam_error_code(a, b, c) openpam_convert_error_code(a, b, c)
2731 #define pam_error_code(a, b, c) (c)
2735 int pam_sm_authenticate(pam_handle_t
*pamh
, int flags
,
2736 int argc
, const char **argv
)
2738 const char *username
;
2739 const char *password
;
2740 const char *member
= NULL
;
2741 const char *cctype
= NULL
;
2742 int warn_pwd_expire
;
2743 int retval
= PAM_AUTH_ERR
;
2744 char *username_ret
= NULL
;
2745 char *new_authtok_required
= NULL
;
2746 char *real_username
= NULL
;
2747 struct pwb_context
*ctx
= NULL
;
2749 retval
= _pam_winbind_init_context(pamh
, flags
, argc
, argv
,
2750 PAM_WINBIND_AUTHENTICATE
, &ctx
);
2751 if (retval
!= PAM_SUCCESS
) {
2755 _PAM_LOG_FUNCTION_ENTER("pam_sm_authenticate", ctx
);
2757 /* Get the username */
2758 retval
= pam_get_user(pamh
, &username
, NULL
);
2759 if ((retval
!= PAM_SUCCESS
) || (!username
)) {
2760 _pam_log_debug(ctx
, LOG_DEBUG
,
2761 "can not get the username");
2762 retval
= PAM_SERVICE_ERR
;
2768 /* Decode the user name since AIX does not support logn user
2769 names by default. The name is encoded as _#uid. */
2771 if (username
[0] == '_') {
2772 uid_t id
= atoi(&username
[1]);
2773 struct passwd
*pw
= NULL
;
2775 if ((id
!=0) && ((pw
= getpwuid(id
)) != NULL
)) {
2776 real_username
= strdup(pw
->pw_name
);
2781 if (!real_username
) {
2782 /* Just making a copy of the username we got from PAM */
2783 if ((real_username
= strdup(username
)) == NULL
) {
2784 _pam_log_debug(ctx
, LOG_DEBUG
,
2785 "memory allocation failure when copying "
2787 retval
= PAM_SERVICE_ERR
;
2792 /* Maybe this was a UPN */
2794 if (strchr(real_username
, '@') != NULL
) {
2795 char *samaccountname
= NULL
;
2797 samaccountname
= winbind_upn_to_username(ctx
,
2799 if (samaccountname
) {
2800 free(real_username
);
2801 real_username
= strdup(samaccountname
);
2805 retval
= _winbind_read_password(ctx
, ctx
->ctrl
, NULL
,
2806 _("Password: "), NULL
,
2809 if (retval
!= PAM_SUCCESS
) {
2810 _pam_log(ctx
, LOG_ERR
,
2811 "Could not retrieve user's password");
2812 retval
= PAM_AUTHTOK_ERR
;
2816 /* Let's not give too much away in the log file */
2818 #ifdef DEBUG_PASSWORD
2819 _pam_log_debug(ctx
, LOG_INFO
,
2820 "Verify user '%s' with password '%s'",
2821 real_username
, password
);
2823 _pam_log_debug(ctx
, LOG_INFO
,
2824 "Verify user '%s'", real_username
);
2827 member
= get_member_from_config(ctx
);
2828 cctype
= get_krb5_cc_type_from_config(ctx
);
2829 warn_pwd_expire
= get_warn_pwd_expire_from_config(ctx
);
2831 /* Now use the username to look up password */
2832 retval
= winbind_auth_request(ctx
, real_username
, password
,
2833 member
, cctype
, warn_pwd_expire
,
2834 NULL
, NULL
, NULL
, &username_ret
);
2836 if (retval
== PAM_NEW_AUTHTOK_REQD
||
2837 retval
== PAM_AUTHTOK_EXPIRED
) {
2839 char *new_authtok_required_during_auth
= NULL
;
2841 new_authtok_required
= talloc_asprintf(NULL
, "%d", retval
);
2842 if (!new_authtok_required
) {
2843 retval
= PAM_BUF_ERR
;
2847 pam_set_data(pamh
, PAM_WINBIND_NEW_AUTHTOK_REQD
,
2848 new_authtok_required
,
2849 _pam_winbind_cleanup_func
);
2851 retval
= PAM_SUCCESS
;
2853 new_authtok_required_during_auth
= talloc_asprintf(NULL
, "%d", true);
2854 if (!new_authtok_required_during_auth
) {
2855 retval
= PAM_BUF_ERR
;
2859 pam_set_data(pamh
, PAM_WINBIND_NEW_AUTHTOK_REQD_DURING_AUTH
,
2860 new_authtok_required_during_auth
,
2861 _pam_winbind_cleanup_func
);
2868 pam_set_item (pamh
, PAM_USER
, username_ret
);
2869 _pam_log_debug(ctx
, LOG_INFO
,
2870 "Returned user was '%s'", username_ret
);
2874 if (real_username
) {
2875 free(real_username
);
2878 if (!new_authtok_required
) {
2879 pam_set_data(pamh
, PAM_WINBIND_NEW_AUTHTOK_REQD
, NULL
, NULL
);
2882 if (retval
!= PAM_SUCCESS
) {
2883 _pam_free_data_info3(pamh
);
2886 _PAM_LOG_FUNCTION_LEAVE("pam_sm_authenticate", ctx
, retval
);
2894 int pam_sm_setcred(pam_handle_t
*pamh
, int flags
,
2895 int argc
, const char **argv
)
2897 int ret
= PAM_SYSTEM_ERR
;
2898 struct pwb_context
*ctx
= NULL
;
2900 ret
= _pam_winbind_init_context(pamh
, flags
, argc
, argv
,
2901 PAM_WINBIND_SETCRED
, &ctx
);
2902 if (ret
!= PAM_SUCCESS
) {
2906 _PAM_LOG_FUNCTION_ENTER("pam_sm_setcred", ctx
);
2908 switch (flags
& ~PAM_SILENT
) {
2910 case PAM_DELETE_CRED
:
2911 ret
= _pam_delete_cred(pamh
, flags
, argc
,
2912 PAM_WINBIND_SETCRED
, argv
);
2914 case PAM_REFRESH_CRED
:
2915 _pam_log_debug(ctx
, LOG_WARNING
,
2916 "PAM_REFRESH_CRED not implemented");
2919 case PAM_REINITIALIZE_CRED
:
2920 _pam_log_debug(ctx
, LOG_WARNING
,
2921 "PAM_REINITIALIZE_CRED not implemented");
2924 case PAM_ESTABLISH_CRED
:
2925 _pam_log_debug(ctx
, LOG_WARNING
,
2926 "PAM_ESTABLISH_CRED not implemented");
2930 ret
= PAM_SYSTEM_ERR
;
2934 _PAM_LOG_FUNCTION_LEAVE("pam_sm_setcred", ctx
, ret
);
2938 return pam_error_code(ctx
, PAM_WINBIND_SETCRED
, ret
);
2942 * Account management. We want to verify that the account exists
2943 * before returning PAM_SUCCESS
2946 int pam_sm_acct_mgmt(pam_handle_t
*pamh
, int flags
,
2947 int argc
, const char **argv
)
2949 const char *username
;
2950 int ret
= PAM_USER_UNKNOWN
;
2951 const char *tmp
= NULL
;
2952 struct pwb_context
*ctx
= NULL
;
2954 ret
= _pam_winbind_init_context(pamh
, flags
, argc
, argv
,
2955 PAM_WINBIND_ACCT_MGMT
, &ctx
);
2956 if (ret
!= PAM_SUCCESS
) {
2960 _PAM_LOG_FUNCTION_ENTER("pam_sm_acct_mgmt", ctx
);
2963 /* Get the username */
2964 ret
= pam_get_user(pamh
, &username
, NULL
);
2965 if ((ret
!= PAM_SUCCESS
) || (!username
)) {
2966 _pam_log_debug(ctx
, LOG_DEBUG
,
2967 "can not get the username");
2968 ret
= PAM_SERVICE_ERR
;
2972 /* Verify the username */
2973 ret
= valid_user(ctx
, username
);
2976 /* some sort of system error. The log was already printed */
2977 ret
= PAM_SERVICE_ERR
;
2980 /* the user does not exist */
2981 _pam_log_debug(ctx
, LOG_NOTICE
, "user '%s' not found",
2983 if (ctx
->ctrl
& WINBIND_UNKNOWN_OK_ARG
) {
2987 ret
= PAM_USER_UNKNOWN
;
2990 pam_get_data(pamh
, PAM_WINBIND_NEW_AUTHTOK_REQD
,
2991 (const void **)&tmp
);
2995 case PAM_AUTHTOK_EXPIRED
:
2996 /* Since new token is required in this case */
2998 case PAM_NEW_AUTHTOK_REQD
:
2999 _pam_log(ctx
, LOG_WARNING
,
3000 "pam_sm_acct_mgmt success but %s is set",
3001 PAM_WINBIND_NEW_AUTHTOK_REQD
);
3002 _pam_log(ctx
, LOG_NOTICE
,
3003 "user '%s' needs new password",
3005 /* PAM_AUTHTOKEN_REQD does not exist, but is documented in the manpage */
3006 ret
= PAM_NEW_AUTHTOK_REQD
;
3009 _pam_log(ctx
, LOG_WARNING
,
3010 "pam_sm_acct_mgmt success");
3011 _pam_log(ctx
, LOG_NOTICE
,
3012 "user '%s' granted access", username
);
3018 /* Otherwise, the authentication looked good */
3019 _pam_log(ctx
, LOG_NOTICE
,
3020 "user '%s' granted access", username
);
3024 /* we don't know anything about this return value */
3025 _pam_log(ctx
, LOG_ERR
,
3026 "internal module error (ret = %d, user = '%s')",
3028 ret
= PAM_SERVICE_ERR
;
3032 /* should not be reached */
3037 _PAM_LOG_FUNCTION_LEAVE("pam_sm_acct_mgmt", ctx
, ret
);
3041 return pam_error_code(ctx
, PAM_WINBIND_ACCT_MGMT
, ret
);
3045 int pam_sm_open_session(pam_handle_t
*pamh
, int flags
,
3046 int argc
, const char **argv
)
3048 int ret
= PAM_SUCCESS
;
3049 struct pwb_context
*ctx
= NULL
;
3051 ret
= _pam_winbind_init_context(pamh
, flags
, argc
, argv
,
3052 PAM_WINBIND_OPEN_SESSION
, &ctx
);
3053 if (ret
!= PAM_SUCCESS
) {
3057 _PAM_LOG_FUNCTION_ENTER("pam_sm_open_session", ctx
);
3059 if (ctx
->ctrl
& WINBIND_MKHOMEDIR
) {
3060 /* check and create homedir */
3061 ret
= _pam_mkhomedir(ctx
);
3064 _PAM_LOG_FUNCTION_LEAVE("pam_sm_open_session", ctx
, ret
);
3068 return pam_error_code(ctx
, PAM_WINBIND_OPEN_SESSION
, ret
);
3072 int pam_sm_close_session(pam_handle_t
*pamh
, int flags
,
3073 int argc
, const char **argv
)
3075 int ret
= PAM_SUCCESS
;
3076 struct pwb_context
*ctx
= NULL
;
3078 ret
= _pam_winbind_init_context(pamh
, flags
, argc
, argv
,
3079 PAM_WINBIND_CLOSE_SESSION
, &ctx
);
3080 if (ret
!= PAM_SUCCESS
) {
3084 _PAM_LOG_FUNCTION_ENTER("pam_sm_close_session", ctx
);
3086 _PAM_LOG_FUNCTION_LEAVE("pam_sm_close_session", ctx
, ret
);
3090 return pam_error_code(ctx
, PAM_WINBIND_CLOSE_SESSION
, ret
);
3094 * evaluate whether we need to re-authenticate with kerberos after a
3097 * @param ctx PAM winbind context.
3098 * @param user The username
3100 * @return boolean Returns true if required, false if not.
3103 static bool _pam_require_krb5_auth_after_chauthtok(struct pwb_context
*ctx
,
3107 /* Make sure that we only do this if a) the chauthtok got initiated
3108 * during a logon attempt (authenticate->acct_mgmt->chauthtok) b) any
3109 * later password change via the "passwd" command if done by the user
3111 * NB. If we login from gdm or xdm and the password expires,
3112 * we change the password, but there is no memory cache.
3113 * Thus, even for passthrough login, we should do the
3114 * authentication again to update memory cache.
3118 const char *new_authtok_reqd_during_auth
= NULL
;
3119 struct passwd
*pwd
= NULL
;
3121 pam_get_data(ctx
->pamh
, PAM_WINBIND_NEW_AUTHTOK_REQD_DURING_AUTH
,
3122 (const void **) &new_authtok_reqd_during_auth
);
3123 pam_set_data(ctx
->pamh
, PAM_WINBIND_NEW_AUTHTOK_REQD_DURING_AUTH
,
3126 if (new_authtok_reqd_during_auth
) {
3130 pwd
= getpwnam(user
);
3135 if (getuid() == pwd
->pw_uid
) {
3144 int pam_sm_chauthtok(pam_handle_t
* pamh
, int flags
,
3145 int argc
, const char **argv
)
3149 bool cached_login
= false;
3151 /* <DO NOT free() THESE> */
3153 const char *pass_old
;
3154 const char *pass_new
;
3155 /* </DO NOT free() THESE> */
3160 char *username_ret
= NULL
;
3161 struct wbcAuthErrorInfo
*error
= NULL
;
3162 struct pwb_context
*ctx
= NULL
;
3164 ret
= _pam_winbind_init_context(pamh
, flags
, argc
, argv
,
3165 PAM_WINBIND_CHAUTHTOK
, &ctx
);
3166 if (ret
!= PAM_SUCCESS
) {
3170 _PAM_LOG_FUNCTION_ENTER("pam_sm_chauthtok", ctx
);
3172 cached_login
= (ctx
->ctrl
& WINBIND_CACHED_LOGIN
);
3174 /* clearing offline bit for auth */
3175 ctx
->ctrl
&= ~WINBIND_CACHED_LOGIN
;
3178 * First get the name of a user
3180 ret
= pam_get_user(pamh
, &user
, _("Username: "));
3181 if (ret
!= PAM_SUCCESS
) {
3182 _pam_log(ctx
, LOG_ERR
,
3183 "password - could not identify user");
3188 _pam_log(ctx
, LOG_ERR
, "username was NULL!");
3189 ret
= PAM_USER_UNKNOWN
;
3193 _pam_log_debug(ctx
, LOG_DEBUG
, "username [%s] obtained", user
);
3195 /* check if this is really a user in winbindd, not only in NSS */
3196 ret
= valid_user(ctx
, user
);
3199 ret
= PAM_USER_UNKNOWN
;
3202 ret
= PAM_SYSTEM_ERR
;
3209 * obtain and verify the current password (OLDAUTHTOK) for
3213 if (flags
& PAM_PRELIM_CHECK
) {
3214 time_t pwdlastset_prelim
= 0;
3216 /* instruct user what is happening */
3218 #define greeting _("Changing password for")
3219 Announce
= talloc_asprintf(ctx
, "%s %s", greeting
, user
);
3221 _pam_log(ctx
, LOG_CRIT
,
3222 "password - out of memory");
3228 lctrl
= ctx
->ctrl
| WINBIND__OLD_PASSWORD
;
3229 ret
= _winbind_read_password(ctx
, lctrl
,
3231 _("(current) NT password: "),
3233 (const char **) &pass_old
);
3234 TALLOC_FREE(Announce
);
3235 if (ret
!= PAM_SUCCESS
) {
3236 _pam_log(ctx
, LOG_NOTICE
,
3237 "password - (old) token not obtained");
3241 /* verify that this is the password for this user */
3243 ret
= winbind_auth_request(ctx
, user
, pass_old
,
3246 &pwdlastset_prelim
, NULL
);
3248 if (ret
!= PAM_ACCT_EXPIRED
&&
3249 ret
!= PAM_AUTHTOK_EXPIRED
&&
3250 ret
!= PAM_NEW_AUTHTOK_REQD
&&
3251 ret
!= PAM_SUCCESS
) {
3256 pam_set_data(pamh
, PAM_WINBIND_PWD_LAST_SET
,
3257 (void *)pwdlastset_prelim
, NULL
);
3259 ret
= pam_set_item(pamh
, PAM_OLDAUTHTOK
,
3260 (const void *) pass_old
);
3262 if (ret
!= PAM_SUCCESS
) {
3263 _pam_log(ctx
, LOG_CRIT
,
3264 "failed to set PAM_OLDAUTHTOK");
3266 } else if (flags
& PAM_UPDATE_AUTHTOK
) {
3268 time_t pwdlastset_update
= 0;
3271 * obtain the proposed password
3275 * get the old token back.
3278 ret
= pam_get_item(pamh
, PAM_OLDAUTHTOK
, (const void **) &pass_old
);
3280 if (ret
!= PAM_SUCCESS
) {
3281 _pam_log(ctx
, LOG_NOTICE
,
3282 "user not authenticated");
3286 lctrl
= ctx
->ctrl
& ~WINBIND_TRY_FIRST_PASS_ARG
;
3288 if (on(WINBIND_USE_AUTHTOK_ARG
, lctrl
)) {
3289 lctrl
|= WINBIND_USE_FIRST_PASS_ARG
;
3291 if (on(WINBIND_TRY_AUTHTOK_ARG
, lctrl
)) {
3292 lctrl
|= WINBIND_TRY_FIRST_PASS_ARG
;
3295 ret
= PAM_AUTHTOK_ERR
;
3296 while ((ret
!= PAM_SUCCESS
) && (retry
++ < MAX_PASSWD_TRIES
)) {
3298 * use_authtok is to force the use of a previously entered
3299 * password -- needed for pluggable password strength checking
3302 ret
= _winbind_read_password(ctx
, lctrl
,
3304 _("Enter new NT password: "),
3305 _("Retype new NT password: "),
3306 (const char **)&pass_new
);
3308 if (ret
!= PAM_SUCCESS
) {
3309 _pam_log_debug(ctx
, LOG_ALERT
,
3311 "new password not obtained");
3312 pass_old
= NULL
;/* tidy up */
3317 * At this point we know who the user is and what they
3318 * propose as their new password. Verify that the new
3319 * password is acceptable.
3322 if (pass_new
[0] == '\0') {/* "\0" password = NULL */
3328 * By reaching here we have approved the passwords and must now
3329 * rebuild the password database file.
3331 pam_get_data(pamh
, PAM_WINBIND_PWD_LAST_SET
,
3332 (const void **) &pwdlastset_update
);
3335 * if cached creds were enabled, make sure to set the
3336 * WINBIND_CACHED_LOGIN bit here in order to have winbindd
3337 * update the cached creds storage - gd
3340 ctx
->ctrl
|= WINBIND_CACHED_LOGIN
;
3343 ret
= winbind_chauthtok_request(ctx
, user
, pass_old
,
3344 pass_new
, pwdlastset_update
);
3345 if (ret
!= PAM_SUCCESS
) {
3346 pass_old
= pass_new
= NULL
;
3350 if (_pam_require_krb5_auth_after_chauthtok(ctx
, user
)) {
3352 const char *member
= NULL
;
3353 const char *cctype
= NULL
;
3354 int warn_pwd_expire
;
3355 struct wbcLogonUserInfo
*info
= NULL
;
3357 member
= get_member_from_config(ctx
);
3358 cctype
= get_krb5_cc_type_from_config(ctx
);
3359 warn_pwd_expire
= get_warn_pwd_expire_from_config(ctx
);
3361 /* Keep WINBIND_CACHED_LOGIN bit for
3362 * authentication after changing the password.
3363 * This will update the cached credentials in case
3364 * that winbindd_dual_pam_chauthtok() fails
3369 ret
= winbind_auth_request(ctx
, user
, pass_new
,
3372 NULL
, &username_ret
);
3373 pass_old
= pass_new
= NULL
;
3375 if (ret
== PAM_SUCCESS
) {
3377 struct wbcAuthUserInfo
*user_info
= NULL
;
3379 if (info
&& info
->info
) {
3380 user_info
= info
->info
;
3383 /* warn a user if the password is about to
3385 _pam_warn_password_expiry(ctx
, user_info
,
3389 /* set some info3 info for other modules in the
3391 _pam_set_data_info3(ctx
, user_info
);
3393 /* put krb5ccname into env */
3394 _pam_setup_krb5_env(ctx
, info
);
3397 pam_set_item(pamh
, PAM_USER
,
3399 _pam_log_debug(ctx
, LOG_INFO
,
3400 "Returned user was '%s'",
3407 if (info
&& info
->blobs
) {
3408 wbcFreeMemory(info
->blobs
);
3410 wbcFreeMemory(info
);
3415 ret
= PAM_SERVICE_ERR
;
3420 /* Deal with offline errors. */
3422 const char *codes
[] = {
3423 "NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND",
3424 "NT_STATUS_NO_LOGON_SERVERS",
3425 "NT_STATUS_ACCESS_DENIED"
3428 for (i
=0; i
<ARRAY_SIZE(codes
); i
++) {
3430 if (_pam_check_remark_auth_err(ctx
, error
, codes
[i
], &_ret
)) {
3436 wbcFreeMemory(error
);
3438 _PAM_LOG_FUNCTION_LEAVE("pam_sm_chauthtok", ctx
, ret
);
3442 return pam_error_code(ctx
, PAM_WINBIND_CHAUTHTOK
, ret
);
3447 /* static module data */
3449 struct pam_module _pam_winbind_modstruct
= {
3451 pam_sm_authenticate
,
3454 pam_sm_open_session
,
3455 pam_sm_close_session
,
3462 * Copyright (c) Andrew Tridgell <tridge@samba.org> 2000
3463 * Copyright (c) Tim Potter <tpot@samba.org> 2000
3464 * Copyright (c) Andrew Bartlettt <abartlet@samba.org> 2002
3465 * Copyright (c) Guenther Deschner <gd@samba.org> 2005-2008
3466 * Copyright (c) Jan Rêkorajski 1999.
3467 * Copyright (c) Andrew G. Morgan 1996-8.
3468 * Copyright (c) Alex O. Yuriev, 1996.
3469 * Copyright (c) Cristian Gafton 1996.
3470 * Copyright (C) Elliot Lee <sopwith@redhat.com> 1996, Red Hat Software.
3472 * Redistribution and use in source and binary forms, with or without
3473 * modification, are permitted provided that the following conditions
3475 * 1. Redistributions of source code must retain the above copyright
3476 * notice, and the entire permission notice in its entirety,
3477 * including the disclaimer of warranties.
3478 * 2. Redistributions in binary form must reproduce the above copyright
3479 * notice, this list of conditions and the following disclaimer in the
3480 * documentation and/or other materials provided with the distribution.
3481 * 3. The name of the author may not be used to endorse or promote
3482 * products derived from this software without specific prior
3483 * written permission.
3485 * ALTERNATIVELY, this product may be distributed under the terms of
3486 * the GNU Public License, in which case the provisions of the GPL are
3487 * required INSTEAD OF the above restrictions. (This clause is
3488 * necessary due to a potential bad interaction between the GPL and
3489 * the restrictions contained in a BSD-style copyright.)
3491 * THIS SOFTWARE IS PROVIDED `AS IS'' AND ANY EXPRESS OR IMPLIED
3492 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
3493 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
3494 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
3495 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
3496 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
3497 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
3498 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
3499 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
3500 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
3501 * OF THE POSSIBILITY OF SUCH DAMAGE.