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-2007
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 #define _PAM_LOG_FUNCTION_ENTER(function, pamh, ctrl, flags) \
17 _pam_log_debug(pamh, ctrl, LOG_DEBUG, "[pamh: %p] ENTER: " \
18 function " (flags: 0x%04x)", pamh, flags); \
19 _pam_log_state(pamh, ctrl); \
22 #define _PAM_LOG_FUNCTION_LEAVE(function, pamh, ctrl, retval) \
24 _pam_log_debug(pamh, ctrl, LOG_DEBUG, "[pamh: %p] LEAVE: " \
25 function " returning %d", pamh, retval); \
26 _pam_log_state(pamh, ctrl); \
31 #define MAX_PASSWD_TRIES 3
34 * Work around the pam API that has functions with void ** as parameters
35 * These lead to strict aliasing warnings with gcc.
37 static int _pam_get_item(const pam_handle_t *pamh,
41 const void **item = (const void **)_item;
42 return pam_get_item(pamh, item_type, item);
44 static int _pam_get_data(const pam_handle_t *pamh,
45 const char *module_data_name,
48 const void **data = (const void **)_data;
49 return pam_get_data(pamh, module_data_name, data);
54 #ifdef HAVE_PAM_VSYSLOG
55 static void _pam_log_int(const pam_handle_t *pamh,
60 pam_vsyslog(pamh, err, format, args);
63 static void _pam_log_int(const pam_handle_t *pamh,
71 _pam_get_item(pamh, PAM_SERVICE, &service);
73 format2 = (char *)malloc(strlen(MODULE_NAME)+strlen(format)+strlen(service)+5);
74 if (format2 == NULL) {
75 /* what else todo ? */
76 vsyslog(err, format, args);
80 sprintf(format2, "%s(%s): %s", MODULE_NAME, service, format);
81 vsyslog(err, format2, args);
84 #endif /* HAVE_PAM_VSYSLOG */
86 static bool _pam_log_is_silent(int ctrl)
88 return on(ctrl, WINBIND_SILENT);
91 static void _pam_log(const pam_handle_t *pamh, int ctrl, int err, const char *format, ...) PRINTF_ATTRIBUTE(4,5);
92 static void _pam_log(const pam_handle_t *pamh, int ctrl, int err, const char *format, ...)
96 if (_pam_log_is_silent(ctrl)) {
100 va_start(args, format);
101 _pam_log_int(pamh, err, format, args);
105 static bool _pam_log_is_debug_enabled(int ctrl)
111 if (_pam_log_is_silent(ctrl)) {
115 if (!(ctrl & WINBIND_DEBUG_ARG)) {
122 static bool _pam_log_is_debug_state_enabled(int ctrl)
124 if (!(ctrl & WINBIND_DEBUG_STATE)) {
128 return _pam_log_is_debug_enabled(ctrl);
131 static void _pam_log_debug(const pam_handle_t *pamh, int ctrl, int err, const char *format, ...) PRINTF_ATTRIBUTE(4,5);
132 static void _pam_log_debug(const pam_handle_t *pamh, int ctrl, int err, const char *format, ...)
136 if (!_pam_log_is_debug_enabled(ctrl)) {
140 va_start(args, format);
141 _pam_log_int(pamh, err, format, args);
145 static void _pam_log_state_datum(const pam_handle_t *pamh,
151 const void *data = NULL;
152 if (item_type != 0) {
153 pam_get_item(pamh, item_type, &data);
155 pam_get_data(pamh, key, &data);
158 const char *type = (item_type != 0) ? "ITEM" : "DATA";
159 if (is_string != 0) {
160 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
161 "[pamh: %p] STATE: %s(%s) = \"%s\" (%p)",
162 pamh, type, key, (const char *)data,
165 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
166 "[pamh: %p] STATE: %s(%s) = %p",
167 pamh, type, key, data);
172 #define _PAM_LOG_STATE_DATA_POINTER(pamh, ctrl, module_data_name) \
173 _pam_log_state_datum(pamh, ctrl, 0, module_data_name, 0)
175 #define _PAM_LOG_STATE_DATA_STRING(pamh, ctrl, module_data_name) \
176 _pam_log_state_datum(pamh, ctrl, 0, module_data_name, 1)
178 #define _PAM_LOG_STATE_ITEM_POINTER(pamh, ctrl, item_type) \
179 _pam_log_state_datum(pamh, ctrl, item_type, #item_type, 0)
181 #define _PAM_LOG_STATE_ITEM_STRING(pamh, ctrl, item_type) \
182 _pam_log_state_datum(pamh, ctrl, item_type, #item_type, 1)
184 #ifdef DEBUG_PASSWORD
185 #define _LOG_PASSWORD_AS_STRING 1
187 #define _LOG_PASSWORD_AS_STRING 0
190 #define _PAM_LOG_STATE_ITEM_PASSWORD(pamh, ctrl, item_type) \
191 _pam_log_state_datum(pamh, ctrl, item_type, #item_type, \
192 _LOG_PASSWORD_AS_STRING)
194 static void _pam_log_state(const pam_handle_t *pamh, int ctrl)
196 if (!_pam_log_is_debug_state_enabled(ctrl)) {
200 _PAM_LOG_STATE_ITEM_STRING(pamh, ctrl, PAM_SERVICE);
201 _PAM_LOG_STATE_ITEM_STRING(pamh, ctrl, PAM_USER);
202 _PAM_LOG_STATE_ITEM_STRING(pamh, ctrl, PAM_TTY);
203 _PAM_LOG_STATE_ITEM_STRING(pamh, ctrl, PAM_RHOST);
204 _PAM_LOG_STATE_ITEM_STRING(pamh, ctrl, PAM_RUSER);
205 _PAM_LOG_STATE_ITEM_PASSWORD(pamh, ctrl, PAM_OLDAUTHTOK);
206 _PAM_LOG_STATE_ITEM_PASSWORD(pamh, ctrl, PAM_AUTHTOK);
207 _PAM_LOG_STATE_ITEM_STRING(pamh, ctrl, PAM_USER_PROMPT);
208 _PAM_LOG_STATE_ITEM_POINTER(pamh, ctrl, PAM_CONV);
209 #ifdef PAM_FAIL_DELAY
210 _PAM_LOG_STATE_ITEM_POINTER(pamh, ctrl, PAM_FAIL_DELAY);
212 #ifdef PAM_REPOSITORY
213 _PAM_LOG_STATE_ITEM_POINTER(pamh, ctrl, PAM_REPOSITORY);
216 _PAM_LOG_STATE_DATA_STRING(pamh, ctrl, PAM_WINBIND_HOMEDIR);
217 _PAM_LOG_STATE_DATA_STRING(pamh, ctrl, PAM_WINBIND_LOGONSCRIPT);
218 _PAM_LOG_STATE_DATA_STRING(pamh, ctrl, PAM_WINBIND_LOGONSERVER);
219 _PAM_LOG_STATE_DATA_STRING(pamh, ctrl, PAM_WINBIND_PROFILEPATH);
220 _PAM_LOG_STATE_DATA_STRING(pamh, ctrl,
221 PAM_WINBIND_NEW_AUTHTOK_REQD);
222 /* Use atoi to get PAM result code */
223 _PAM_LOG_STATE_DATA_STRING(pamh, ctrl,
224 PAM_WINBIND_NEW_AUTHTOK_REQD_DURING_AUTH);
225 _PAM_LOG_STATE_DATA_POINTER(pamh, ctrl, PAM_WINBIND_PWD_LAST_SET);
228 static int _pam_parse(const pam_handle_t *pamh,
232 dictionary **result_d)
235 const char *config_file = NULL;
238 dictionary *d = NULL;
240 if (flags & PAM_SILENT) {
241 ctrl |= WINBIND_SILENT;
244 for (i=argc,v=argv; i-- > 0; ++v) {
245 if (!strncasecmp(*v, "config", strlen("config"))) {
246 ctrl |= WINBIND_CONFIG_FILE;
252 if (config_file == NULL) {
253 config_file = PAM_WINBIND_CONFIG_FILE;
256 d = iniparser_load(config_file);
258 goto config_from_pam;
261 if (iniparser_getboolean(d, "global:debug", false)) {
262 ctrl |= WINBIND_DEBUG_ARG;
265 if (iniparser_getboolean(d, "global:debug_state", false)) {
266 ctrl |= WINBIND_DEBUG_STATE;
269 if (iniparser_getboolean(d, "global:cached_login", false)) {
270 ctrl |= WINBIND_CACHED_LOGIN;
273 if (iniparser_getboolean(d, "global:krb5_auth", false)) {
274 ctrl |= WINBIND_KRB5_AUTH;
277 if (iniparser_getboolean(d, "global:silent", false)) {
278 ctrl |= WINBIND_SILENT;
281 if (iniparser_getstr(d, "global:krb5_ccache_type") != NULL) {
282 ctrl |= WINBIND_KRB5_CCACHE_TYPE;
285 if ((iniparser_getstr(d, "global:require-membership-of") != NULL) ||
286 (iniparser_getstr(d, "global:require_membership_of") != NULL)) {
287 ctrl |= WINBIND_REQUIRED_MEMBERSHIP;
290 if (iniparser_getboolean(d, "global:try_first_pass", false)) {
291 ctrl |= WINBIND_TRY_FIRST_PASS_ARG;
294 if (iniparser_getint(d, "global:warn_pwd_expire", 0)) {
295 ctrl |= WINBIND_WARN_PWD_EXPIRE;
299 /* step through arguments */
300 for (i=argc,v=argv; i-- > 0; ++v) {
302 /* generic options */
303 if (!strcmp(*v,"debug"))
304 ctrl |= WINBIND_DEBUG_ARG;
305 else if (!strcasecmp(*v, "debug_state"))
306 ctrl |= WINBIND_DEBUG_STATE;
307 else if (!strcasecmp(*v, "silent"))
308 ctrl |= WINBIND_SILENT;
309 else if (!strcasecmp(*v, "use_authtok"))
310 ctrl |= WINBIND_USE_AUTHTOK_ARG;
311 else if (!strcasecmp(*v, "use_first_pass"))
312 ctrl |= WINBIND_USE_FIRST_PASS_ARG;
313 else if (!strcasecmp(*v, "try_first_pass"))
314 ctrl |= WINBIND_TRY_FIRST_PASS_ARG;
315 else if (!strcasecmp(*v, "unknown_ok"))
316 ctrl |= WINBIND_UNKNOWN_OK_ARG;
317 else if (!strncasecmp(*v, "require_membership_of",
318 strlen("require_membership_of")))
319 ctrl |= WINBIND_REQUIRED_MEMBERSHIP;
320 else if (!strncasecmp(*v, "require-membership-of",
321 strlen("require-membership-of")))
322 ctrl |= WINBIND_REQUIRED_MEMBERSHIP;
323 else if (!strcasecmp(*v, "krb5_auth"))
324 ctrl |= WINBIND_KRB5_AUTH;
325 else if (!strncasecmp(*v, "krb5_ccache_type",
326 strlen("krb5_ccache_type")))
327 ctrl |= WINBIND_KRB5_CCACHE_TYPE;
328 else if (!strcasecmp(*v, "cached_login"))
329 ctrl |= WINBIND_CACHED_LOGIN;
331 _pam_log(pamh, ctrl, LOG_ERR,
332 "pam_parse: unknown option: %s", *v);
342 iniparser_freedict(d);
349 static void _pam_winbind_free_context(struct pwb_context *ctx)
352 iniparser_freedict(ctx->dict);
358 static int _pam_winbind_init_context(const pam_handle_t *pamh,
362 struct pwb_context **ctx_p)
364 struct pwb_context *r = NULL;
366 r = (struct pwb_context *)malloc(sizeof(struct pwb_context));
377 r->ctrl = _pam_parse(pamh, flags, argc, argv, &r->dict);
379 _pam_winbind_free_context(r);
380 return PAM_SYSTEM_ERR;
388 static void _pam_winbind_cleanup_func(pam_handle_t *pamh,
392 int ctrl = _pam_parse(pamh, 0, 0, NULL, NULL);
393 if (_pam_log_is_debug_state_enabled(ctrl)) {
394 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
395 "[pamh: %p] CLEAN: cleaning up PAM data %p "
396 "(error_status = %d)", pamh, data,
403 static const struct ntstatus_errors {
404 const char *ntstatus_string;
405 const char *error_string;
406 } ntstatus_errors[] = {
409 {"NT_STATUS_BACKUP_CONTROLLER",
410 "No primary Domain Controler available"},
411 {"NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND",
412 "No domain controllers found"},
413 {"NT_STATUS_NO_LOGON_SERVERS",
415 {"NT_STATUS_PWD_TOO_SHORT",
416 "Password too short"},
417 {"NT_STATUS_PWD_TOO_RECENT",
418 "The password of this user is too recent to change"},
419 {"NT_STATUS_PWD_HISTORY_CONFLICT",
420 "Password is already in password history"},
421 {"NT_STATUS_PASSWORD_EXPIRED",
422 "Your password has expired"},
423 {"NT_STATUS_PASSWORD_MUST_CHANGE",
424 "You need to change your password now"},
425 {"NT_STATUS_INVALID_WORKSTATION",
426 "You are not allowed to logon from this workstation"},
427 {"NT_STATUS_INVALID_LOGON_HOURS",
428 "You are not allowed to logon at this time"},
429 {"NT_STATUS_ACCOUNT_EXPIRED",
430 "Your account has expired. "
431 "Please contact your System administrator"}, /* SCNR */
432 {"NT_STATUS_ACCOUNT_DISABLED",
433 "Your account is disabled. "
434 "Please contact your System administrator"}, /* SCNR */
435 {"NT_STATUS_ACCOUNT_LOCKED_OUT",
436 "Your account has been locked. "
437 "Please contact your System administrator"}, /* SCNR */
438 {"NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT",
439 "Invalid Trust Account"},
440 {"NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT",
441 "Invalid Trust Account"},
442 {"NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT",
443 "Invalid Trust Account"},
444 {"NT_STATUS_ACCESS_DENIED",
449 static const char *_get_ntstatus_error_string(const char *nt_status_string)
452 for (i=0; ntstatus_errors[i].ntstatus_string != NULL; i++) {
453 if (!strcasecmp(ntstatus_errors[i].ntstatus_string,
455 return ntstatus_errors[i].error_string;
461 /* --- authentication management functions --- */
463 /* Attempt a conversation */
465 static int converse(pam_handle_t *pamh,
467 struct pam_message **message,
468 struct pam_response **response)
471 struct pam_conv *conv;
473 retval = _pam_get_item(pamh, PAM_CONV, &conv);
474 if (retval == PAM_SUCCESS) {
475 retval = conv->conv(nargs,
476 (const struct pam_message **)message,
477 response, conv->appdata_ptr);
480 return retval; /* propagate error status */
484 static int _make_remark(pam_handle_t * pamh,
489 int retval = PAM_SUCCESS;
491 struct pam_message *pmsg[1], msg[1];
492 struct pam_response *resp;
494 if (flags & WINBIND_SILENT) {
499 msg[0].msg = discard_const_p(char, text);
500 msg[0].msg_style = type;
503 retval = converse(pamh, 1, pmsg, &resp);
506 _pam_drop_reply(resp, 1);
511 static int _make_remark_v(pam_handle_t *pamh,
520 ret = vasprintf(&var, format, args);
522 _pam_log(pamh, 0, LOG_ERR, "memory allocation failure");
526 ret = _make_remark(pamh, flags, type, var);
531 static int _make_remark_format(pam_handle_t * pamh, int flags, int type, const char *format, ...) PRINTF_ATTRIBUTE(4,5);
532 static int _make_remark_format(pam_handle_t * pamh, int flags, int type, const char *format, ...)
537 va_start(args, format);
538 ret = _make_remark_v(pamh, flags, type, format, args);
543 static int pam_winbind_request(pam_handle_t *pamh,
545 enum winbindd_cmd req_type,
546 struct winbindd_request *request,
547 struct winbindd_response *response)
549 /* Fill in request and send down pipe */
550 winbindd_init_request(request, req_type);
552 if (winbind_write_sock(request, sizeof(*request), 0, 0) == -1) {
553 _pam_log(pamh, ctrl, LOG_ERR,
554 "pam_winbind_request: write to socket failed!");
555 winbind_close_sock();
556 return PAM_SERVICE_ERR;
560 if (winbindd_read_reply(response) == -1) {
561 _pam_log(pamh, ctrl, LOG_ERR,
562 "pam_winbind_request: read from socket failed!");
563 winbind_close_sock();
564 return PAM_SERVICE_ERR;
567 /* We are done with the socket - close it and avoid mischeif */
568 winbind_close_sock();
570 /* Copy reply data from socket */
571 if (response->result == WINBINDD_OK) {
575 /* no need to check for pam_error codes for getpwnam() */
578 case WINBINDD_GETPWNAM:
579 case WINBINDD_LOOKUPNAME:
580 if (strlen(response->data.auth.nt_status_string) > 0) {
581 _pam_log(pamh, ctrl, LOG_ERR,
582 "request failed, NT error was %s",
583 response->data.auth.nt_status_string);
585 _pam_log(pamh, ctrl, LOG_ERR, "request failed");
587 return PAM_USER_UNKNOWN;
592 if (response->data.auth.pam_error != PAM_SUCCESS) {
593 _pam_log(pamh, ctrl, LOG_ERR,
594 "request failed: %s, "
595 "PAM error was %s (%d), NT error was %s",
596 response->data.auth.error_string,
597 pam_strerror(pamh, response->data.auth.pam_error),
598 response->data.auth.pam_error,
599 response->data.auth.nt_status_string);
600 return response->data.auth.pam_error;
603 _pam_log(pamh, ctrl, LOG_ERR, "request failed, but PAM error 0!");
605 return PAM_SERVICE_ERR;
608 static int pam_winbind_request_log(pam_handle_t *pamh,
610 enum winbindd_cmd req_type,
611 struct winbindd_request *request,
612 struct winbindd_response *response,
617 retval = pam_winbind_request(pamh, ctrl, req_type, request, response);
621 /* incorrect password */
622 _pam_log(pamh, ctrl, LOG_WARNING, "user '%s' denied access "
623 "(incorrect password or invalid membership)", user);
625 case PAM_ACCT_EXPIRED:
626 /* account expired */
627 _pam_log(pamh, ctrl, LOG_WARNING, "user '%s' account expired",
630 case PAM_AUTHTOK_EXPIRED:
631 /* password expired */
632 _pam_log(pamh, ctrl, LOG_WARNING, "user '%s' password expired",
635 case PAM_NEW_AUTHTOK_REQD:
636 /* new password required */
637 _pam_log(pamh, ctrl, LOG_WARNING, "user '%s' new password "
640 case PAM_USER_UNKNOWN:
641 /* the user does not exist */
642 _pam_log_debug(pamh, ctrl, LOG_NOTICE, "user '%s' not found",
644 if (ctrl & WINBIND_UNKNOWN_OK_ARG) {
649 /* Otherwise, the authentication looked good */
653 case WINBINDD_PAM_AUTH:
654 _pam_log(pamh, ctrl, LOG_NOTICE,
655 "user '%s' granted access", user);
657 case WINBINDD_PAM_CHAUTHTOK:
658 _pam_log(pamh, ctrl, LOG_NOTICE,
659 "user '%s' password changed", user);
662 _pam_log(pamh, ctrl, LOG_NOTICE,
663 "user '%s' OK", user);
669 /* we don't know anything about this return value */
670 _pam_log(pamh, ctrl, LOG_ERR,
671 "internal module error (retval = %d, user = '%s')",
678 * send a password expiry message if required
680 * @param pamh PAM handle
681 * @param ctrl PAM winbind options.
682 * @param next_change expected (calculated) next expiry date.
683 * @param already_expired pointer to a boolean to indicate if the password is
686 * @return boolean Returns true if message has been sent, false if not.
689 static bool _pam_send_password_expiry_message(pam_handle_t *pamh,
694 bool *already_expired)
697 struct tm tm_now, tm_next_change;
699 if (already_expired) {
700 *already_expired = false;
703 if (next_change <= now) {
704 PAM_WB_REMARK_DIRECT(pamh, ctrl, "NT_STATUS_PASSWORD_EXPIRED");
705 if (already_expired) {
706 *already_expired = true;
711 if ((next_change < 0) ||
712 (next_change > now + warn_pwd_expire * SECONDS_PER_DAY)) {
716 if ((localtime_r(&now, &tm_now) == NULL) ||
717 (localtime_r(&next_change, &tm_next_change) == NULL)) {
721 days = (tm_next_change.tm_yday+tm_next_change.tm_year*365) -
722 (tm_now.tm_yday+tm_now.tm_year*365);
725 _make_remark(pamh, ctrl, PAM_TEXT_INFO,
726 "Your password expires today");
730 if (days > 0 && days < warn_pwd_expire) {
731 _make_remark_format(pamh, ctrl, PAM_TEXT_INFO,
732 "Your password will expire in %d %s",
733 days, (days > 1) ? "days":"day");
741 * Send a warning if the password expires in the near future
743 * @param pamh PAM handle
744 * @param ctrl PAM winbind options.
745 * @param response The full authentication response structure.
746 * @param already_expired boolean, is the pwd already expired?
751 static void _pam_warn_password_expiry(pam_handle_t *pamh,
753 const struct winbindd_response *response,
755 bool *already_expired)
757 time_t now = time(NULL);
758 time_t next_change = 0;
760 if (already_expired) {
761 *already_expired = false;
764 /* accounts with ACB_PWNOEXP set never receive a warning */
765 if (response->data.auth.info3.acct_flags & ACB_PWNOEXP) {
769 /* no point in sending a warning if this is a grace logon */
770 if (PAM_WB_GRACE_LOGON(response->data.auth.info3.user_flgs)) {
774 /* check if the info3 must change timestamp has been set */
775 next_change = response->data.auth.info3.pass_must_change_time;
777 if (_pam_send_password_expiry_message(pamh, flags, next_change, now,
783 /* now check for the global password policy */
784 /* good catch from Ralf Haferkamp: an expiry of "never" is translated
786 if (response->data.auth.policy.expire <= 0) {
790 next_change = response->data.auth.info3.pass_last_set_time +
791 response->data.auth.policy.expire;
793 if (_pam_send_password_expiry_message(pamh, flags, next_change, now,
799 /* no warning sent */
802 #define IS_SID_STRING(name) (strncmp("S-", name, 2) == 0)
805 * Append a string, making sure not to overflow and to always return a
806 * NULL-terminated string.
808 * @param dest Destination string buffer (must already be NULL-terminated).
809 * @param src Source string buffer.
810 * @param dest_buffer_size Size of dest buffer in bytes.
812 * @return false if dest buffer is not big enough (no bytes copied), true on
816 static bool safe_append_string(char *dest,
818 int dest_buffer_size)
820 int dest_length = strlen(dest);
821 int src_length = strlen(src);
823 if (dest_length + src_length + 1 > dest_buffer_size) {
827 memcpy(dest + dest_length, src, src_length + 1);
832 * Convert a names into a SID string, appending it to a buffer.
834 * @param pamh PAM handle
835 * @param ctrl PAM winbind options.
836 * @param user User in PAM request.
837 * @param name Name to convert.
838 * @param sid_list_buffer Where to append the string sid.
839 * @param sid_list_buffer Size of sid_list_buffer (in bytes).
841 * @return false on failure, true on success.
843 static bool winbind_name_to_sid_string(pam_handle_t *pamh,
847 char *sid_list_buffer,
848 int sid_list_buffer_size)
850 const char* sid_string;
851 struct winbindd_response sid_response;
854 if (IS_SID_STRING(name)) {
857 struct winbindd_request sid_request;
859 ZERO_STRUCT(sid_request);
860 ZERO_STRUCT(sid_response);
862 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
863 "no sid given, looking up: %s\n", name);
865 /* fortunatly winbindd can handle non-separated names */
866 strncpy(sid_request.data.name.name, name,
867 sizeof(sid_request.data.name.name) - 1);
869 if (pam_winbind_request_log(pamh, ctrl, WINBINDD_LOOKUPNAME,
870 &sid_request, &sid_response,
872 _pam_log(pamh, ctrl, LOG_INFO,
873 "could not lookup name: %s\n", name);
877 sid_string = sid_response.data.sid.sid;
880 if (!safe_append_string(sid_list_buffer, sid_string,
881 sid_list_buffer_size)) {
889 * Convert a list of names into a list of sids.
891 * @param pamh PAM handle
892 * @param ctrl PAM winbind options.
893 * @param user User in PAM request.
894 * @param name_list List of names or string sids, separated by commas.
895 * @param sid_list_buffer Where to put the list of string sids.
896 * @param sid_list_buffer Size of sid_list_buffer (in bytes).
898 * @return false on failure, true on success.
900 static bool winbind_name_list_to_sid_string_list(pam_handle_t *pamh,
903 const char *name_list,
904 char *sid_list_buffer,
905 int sid_list_buffer_size)
908 char *current_name = NULL;
909 const char *search_location;
912 if (sid_list_buffer_size > 0) {
913 sid_list_buffer[0] = 0;
916 search_location = name_list;
917 while ((comma = strstr(search_location, ",")) != NULL) {
918 current_name = strndup(search_location,
919 comma - search_location);
920 if (NULL == current_name) {
924 if (!winbind_name_to_sid_string(pamh, ctrl, user,
927 sid_list_buffer_size)) {
931 SAFE_FREE(current_name);
933 if (!safe_append_string(sid_list_buffer, ",",
934 sid_list_buffer_size)) {
938 search_location = comma + 1;
941 if (!winbind_name_to_sid_string(pamh, ctrl, user, search_location,
943 sid_list_buffer_size)) {
950 SAFE_FREE(current_name);
955 * put krb5ccname variable into environment
957 * @param pamh PAM handle
958 * @param ctrl PAM winbind options.
959 * @param krb5ccname env variable retrieved from winbindd.
964 static void _pam_setup_krb5_env(pam_handle_t *pamh,
966 const char *krb5ccname)
971 if (off(ctrl, WINBIND_KRB5_AUTH)) {
975 if (!krb5ccname || (strlen(krb5ccname) == 0)) {
979 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
980 "request returned KRB5CCNAME: %s", krb5ccname);
982 if (snprintf(var, sizeof(var), "KRB5CCNAME=%s", krb5ccname) == -1) {
986 ret = pam_putenv(pamh, var);
988 _pam_log(pamh, ctrl, LOG_ERR,
989 "failed to set KRB5CCNAME to %s: %s",
990 var, pam_strerror(pamh, ret));
995 * Set string into the PAM stack.
997 * @param pamh PAM handle
998 * @param ctrl PAM winbind options.
999 * @param data_name Key name for pam_set_data.
1000 * @param value String value.
1005 static void _pam_set_data_string(pam_handle_t *pamh,
1007 const char *data_name,
1012 if (!data_name || !value || (strlen(data_name) == 0) ||
1013 (strlen(value) == 0)) {
1017 ret = pam_set_data(pamh, data_name, (void *)strdup(value),
1018 _pam_winbind_cleanup_func);
1020 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
1021 "Could not set data %s: %s\n",
1022 data_name, pam_strerror(pamh, ret));
1028 * Set info3 strings into the PAM stack.
1030 * @param pamh PAM handle
1031 * @param ctrl PAM winbind options.
1032 * @param data_name Key name for pam_set_data.
1033 * @param value String value.
1038 static void _pam_set_data_info3(pam_handle_t *pamh,
1040 struct winbindd_response *response)
1042 _pam_set_data_string(pamh, ctrl, PAM_WINBIND_HOMEDIR,
1043 response->data.auth.info3.home_dir);
1044 _pam_set_data_string(pamh, ctrl, PAM_WINBIND_LOGONSCRIPT,
1045 response->data.auth.info3.logon_script);
1046 _pam_set_data_string(pamh, ctrl, PAM_WINBIND_LOGONSERVER,
1047 response->data.auth.info3.logon_srv);
1048 _pam_set_data_string(pamh, ctrl, PAM_WINBIND_PROFILEPATH,
1049 response->data.auth.info3.profile_path);
1053 * Free info3 strings in the PAM stack.
1055 * @param pamh PAM handle
1060 static void _pam_free_data_info3(pam_handle_t *pamh)
1062 pam_set_data(pamh, PAM_WINBIND_HOMEDIR, NULL, NULL);
1063 pam_set_data(pamh, PAM_WINBIND_LOGONSCRIPT, NULL, NULL);
1064 pam_set_data(pamh, PAM_WINBIND_LOGONSERVER, NULL, NULL);
1065 pam_set_data(pamh, PAM_WINBIND_PROFILEPATH, NULL, NULL);
1069 * Send PAM_ERROR_MSG for cached or grace logons.
1071 * @param pamh PAM handle
1072 * @param ctrl PAM winbind options.
1073 * @param username User in PAM request.
1074 * @param info3_user_flgs Info3 flags containing logon type bits.
1079 static void _pam_warn_logon_type(pam_handle_t *pamh,
1081 const char *username,
1082 uint32_t info3_user_flgs)
1084 /* inform about logon type */
1085 if (PAM_WB_GRACE_LOGON(info3_user_flgs)) {
1087 _make_remark(pamh, ctrl, PAM_ERROR_MSG,
1089 "Please change your password as soon you're "
1091 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
1092 "User %s logged on using grace logon\n",
1095 } else if (PAM_WB_CACHED_LOGON(info3_user_flgs)) {
1097 _make_remark(pamh, ctrl, PAM_ERROR_MSG,
1098 "Domain Controller unreachable, "
1099 "using cached credentials instead. "
1100 "Network resources may be unavailable");
1101 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
1102 "User %s logged on using cached credentials\n",
1108 * Send PAM_ERROR_MSG for krb5 errors.
1110 * @param pamh PAM handle
1111 * @param ctrl PAM winbind options.
1112 * @param username User in PAM request.
1113 * @param info3_user_flgs Info3 flags containing logon type bits.
1118 static void _pam_warn_krb5_failure(pam_handle_t *pamh,
1120 const char *username,
1121 uint32_t info3_user_flgs)
1123 if (PAM_WB_KRB5_CLOCK_SKEW(info3_user_flgs)) {
1124 _make_remark(pamh, ctrl, PAM_ERROR_MSG,
1125 "Failed to establish your Kerberos Ticket cache "
1126 "due time differences\n"
1127 "with the domain controller. "
1128 "Please verify the system time.\n");
1129 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
1130 "User %s: Clock skew when getting Krb5 TGT\n",
1136 * Compose Password Restriction String for a PAM_ERROR_MSG conversation.
1138 * @param response The struct winbindd_response.
1140 * @return string (caller needs to free).
1143 static char *_pam_compose_pwd_restriction_string(struct winbindd_response *response)
1146 size_t offset = 0, ret = 0, str_size = 1024;
1148 str = (char *)malloc(str_size);
1153 memset(str, '\0', str_size);
1155 offset = snprintf(str, str_size, "Your password ");
1160 if (response->data.auth.policy.min_length_password > 0) {
1161 ret = snprintf(str+offset, str_size-offset,
1162 "must be at least %d characters; ",
1163 response->data.auth.policy.min_length_password);
1170 if (response->data.auth.policy.password_history > 0) {
1171 ret = snprintf(str+offset, str_size-offset,
1172 "cannot repeat any of your previous %d "
1174 response->data.auth.policy.password_history);
1181 if (response->data.auth.policy.password_properties &
1182 DOMAIN_PASSWORD_COMPLEX) {
1183 ret = snprintf(str+offset, str_size-offset,
1184 "must contain capitals, numerals "
1186 "and cannot contain your account "
1194 ret = snprintf(str+offset, str_size-offset,
1195 "Please type a different password. "
1196 "Type a password which meets these requirements in "
1197 "both text boxes.");
1209 /* talk to winbindd */
1210 static int winbind_auth_request(pam_handle_t * pamh,
1216 const int warn_pwd_expire,
1217 struct winbindd_response *p_response,
1218 time_t *pwd_last_set,
1221 struct winbindd_request request;
1222 struct winbindd_response response;
1224 bool already_expired = false;
1226 ZERO_STRUCT(request);
1227 ZERO_STRUCT(response);
1233 strncpy(request.data.auth.user, user,
1234 sizeof(request.data.auth.user)-1);
1236 strncpy(request.data.auth.pass, pass,
1237 sizeof(request.data.auth.pass)-1);
1239 request.data.auth.krb5_cc_type[0] = '\0';
1240 request.data.auth.uid = -1;
1242 request.flags = WBFLAG_PAM_INFO3_TEXT | WBFLAG_PAM_GET_PWD_POLICY;
1244 /* Krb5 auth always has to go against the KDC of the user's realm */
1246 if (ctrl & WINBIND_KRB5_AUTH) {
1247 request.flags |= WBFLAG_PAM_CONTACT_TRUSTDOM;
1250 if (ctrl & (WINBIND_KRB5_AUTH|WINBIND_CACHED_LOGIN)) {
1251 struct passwd *pwd = NULL;
1253 pwd = getpwnam(user);
1255 return PAM_USER_UNKNOWN;
1257 request.data.auth.uid = pwd->pw_uid;
1260 if (ctrl & WINBIND_KRB5_AUTH) {
1262 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
1263 "enabling krb5 login flag\n");
1265 request.flags |= WBFLAG_PAM_KRB5 |
1266 WBFLAG_PAM_FALLBACK_AFTER_KRB5;
1269 if (ctrl & WINBIND_CACHED_LOGIN) {
1270 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
1271 "enabling cached login flag\n");
1272 request.flags |= WBFLAG_PAM_CACHED_LOGIN;
1277 request.flags |= WBFLAG_PAM_UNIX_NAME;
1280 if (cctype != NULL) {
1281 strncpy(request.data.auth.krb5_cc_type, cctype,
1282 sizeof(request.data.auth.krb5_cc_type) - 1);
1283 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
1284 "enabling request for a %s krb5 ccache\n",
1288 request.data.auth.require_membership_of_sid[0] = '\0';
1290 if (member != NULL) {
1292 if (!winbind_name_list_to_sid_string_list(pamh, ctrl, user,
1294 request.data.auth.require_membership_of_sid,
1295 sizeof(request.data.auth.require_membership_of_sid))) {
1297 _pam_log_debug(pamh, ctrl, LOG_ERR,
1298 "failed to serialize membership of sid "
1299 "\"%s\"\n", member);
1300 return PAM_AUTH_ERR;
1304 ret = pam_winbind_request_log(pamh, ctrl, WINBINDD_PAM_AUTH,
1305 &request, &response, user);
1308 *pwd_last_set = response.data.auth.info3.pass_last_set_time;
1312 /* We want to process the response in the caller. */
1313 *p_response = response;
1318 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, ctrl, response,
1319 "NT_STATUS_PASSWORD_EXPIRED");
1320 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, ctrl, response,
1321 "NT_STATUS_PASSWORD_MUST_CHANGE");
1322 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, ctrl, response,
1323 "NT_STATUS_INVALID_WORKSTATION");
1324 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, ctrl, response,
1325 "NT_STATUS_INVALID_LOGON_HOURS");
1326 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, ctrl, response,
1327 "NT_STATUS_ACCOUNT_EXPIRED");
1328 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, ctrl, response,
1329 "NT_STATUS_ACCOUNT_DISABLED");
1330 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, ctrl, response,
1331 "NT_STATUS_ACCOUNT_LOCKED_OUT");
1332 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, ctrl, response,
1333 "NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT");
1334 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, ctrl, response,
1335 "NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT");
1336 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, ctrl, response,
1337 "NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT");
1338 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, ctrl, response,
1339 "NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND");
1340 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, ctrl, response,
1341 "NT_STATUS_NO_LOGON_SERVERS");
1342 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, ctrl, response,
1343 "NT_STATUS_WRONG_PASSWORD");
1344 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, ctrl, response,
1345 "NT_STATUS_ACCESS_DENIED");
1348 if (ret == PAM_SUCCESS) {
1350 /* warn a user if the password is about to expire soon */
1351 _pam_warn_password_expiry(pamh, ctrl, &response,
1355 if (already_expired == true) {
1356 SMB_TIME_T last_set;
1357 last_set = response.data.auth.info3.pass_last_set_time;
1358 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
1359 "Password has expired "
1360 "(Password was last set: %lld, "
1361 "the policy says it should expire here "
1362 "%lld (now it's: %lu))\n",
1363 (long long int)last_set,
1364 (long long int)last_set +
1365 response.data.auth.policy.expire,
1368 return PAM_AUTHTOK_EXPIRED;
1371 /* inform about logon type */
1372 _pam_warn_logon_type(pamh, ctrl, user,
1373 response.data.auth.info3.user_flgs);
1375 /* inform about krb5 failures */
1376 _pam_warn_krb5_failure(pamh, ctrl, user,
1377 response.data.auth.info3.user_flgs);
1379 /* set some info3 info for other modules in the stack */
1380 _pam_set_data_info3(pamh, ctrl, &response);
1382 /* put krb5ccname into env */
1383 _pam_setup_krb5_env(pamh, ctrl, response.data.auth.krb5ccname);
1385 /* If winbindd returned a username, return the pointer to it
1387 if (user_ret && response.data.auth.unix_username[0]) {
1388 /* We have to trust it's a null terminated string. */
1389 *user_ret = strndup(response.data.auth.unix_username,
1390 sizeof(response.data.auth.unix_username) - 1);
1397 /* talk to winbindd */
1398 static int winbind_chauthtok_request(pam_handle_t * pamh,
1401 const char *oldpass,
1402 const char *newpass,
1403 time_t pwd_last_set)
1405 struct winbindd_request request;
1406 struct winbindd_response response;
1409 ZERO_STRUCT(request);
1410 ZERO_STRUCT(response);
1412 if (request.data.chauthtok.user == NULL) {
1416 strncpy(request.data.chauthtok.user, user,
1417 sizeof(request.data.chauthtok.user) - 1);
1419 if (oldpass != NULL) {
1420 strncpy(request.data.chauthtok.oldpass, oldpass,
1421 sizeof(request.data.chauthtok.oldpass) - 1);
1423 request.data.chauthtok.oldpass[0] = '\0';
1426 if (newpass != NULL) {
1427 strncpy(request.data.chauthtok.newpass, newpass,
1428 sizeof(request.data.chauthtok.newpass) - 1);
1430 request.data.chauthtok.newpass[0] = '\0';
1433 if (ctrl & WINBIND_KRB5_AUTH) {
1434 request.flags = WBFLAG_PAM_KRB5 |
1435 WBFLAG_PAM_CONTACT_TRUSTDOM;
1438 ret = pam_winbind_request_log(pamh, ctrl, WINBINDD_PAM_CHAUTHTOK,
1439 &request, &response, user);
1441 if (ret == PAM_SUCCESS) {
1445 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, ctrl, response,
1446 "NT_STATUS_BACKUP_CONTROLLER");
1447 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, ctrl, response,
1448 "NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND");
1449 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, ctrl, response,
1450 "NT_STATUS_NO_LOGON_SERVERS");
1451 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, ctrl, response,
1452 "NT_STATUS_ACCESS_DENIED");
1454 /* TODO: tell the min pwd length ? */
1455 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, ctrl, response,
1456 "NT_STATUS_PWD_TOO_SHORT");
1458 /* TODO: tell the minage ? */
1459 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, ctrl, response,
1460 "NT_STATUS_PWD_TOO_RECENT");
1462 /* TODO: tell the history length ? */
1463 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, ctrl, response,
1464 "NT_STATUS_PWD_HISTORY_CONFLICT");
1466 if (!strcasecmp(response.data.auth.nt_status_string,
1467 "NT_STATUS_PASSWORD_RESTRICTION")) {
1469 char *pwd_restriction_string = NULL;
1470 SMB_TIME_T min_pwd_age;
1471 uint32_t reject_reason = response.data.auth.reject_reason;
1472 min_pwd_age = response.data.auth.policy.min_passwordage;
1474 /* FIXME: avoid to send multiple PAM messages after another */
1475 switch (reject_reason) {
1478 case SAMR_REJECT_OTHER:
1479 if ((min_pwd_age > 0) &&
1480 (pwd_last_set + min_pwd_age > time(NULL))) {
1481 PAM_WB_REMARK_DIRECT(pamh, ctrl,
1482 "NT_STATUS_PWD_TOO_RECENT");
1485 case SAMR_REJECT_TOO_SHORT:
1486 PAM_WB_REMARK_DIRECT(pamh, ctrl,
1487 "NT_STATUS_PWD_TOO_SHORT");
1489 case SAMR_REJECT_IN_HISTORY:
1490 PAM_WB_REMARK_DIRECT(pamh, ctrl,
1491 "NT_STATUS_PWD_HISTORY_CONFLICT");
1493 case SAMR_REJECT_COMPLEXITY:
1494 _make_remark(pamh, ctrl, PAM_ERROR_MSG,
1495 "Password does not meet "
1496 "complexity requirements");
1499 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
1500 "unknown password change "
1501 "reject reason: %d",
1506 pwd_restriction_string =
1507 _pam_compose_pwd_restriction_string(&response);
1508 if (pwd_restriction_string) {
1509 _make_remark(pamh, ctrl, PAM_ERROR_MSG,
1510 pwd_restriction_string);
1511 SAFE_FREE(pwd_restriction_string);
1519 * Checks if a user has an account
1522 * 1 = User not found
1526 static int valid_user(pam_handle_t *pamh,
1530 /* check not only if the user is available over NSS calls, also make
1531 * sure it's really a winbind user, this is important when stacking PAM
1532 * modules in the 'account' or 'password' facility. */
1534 struct passwd *pwd = NULL;
1535 struct winbindd_request request;
1536 struct winbindd_response response;
1539 ZERO_STRUCT(request);
1540 ZERO_STRUCT(response);
1542 pwd = getpwnam(user);
1547 strncpy(request.data.username, user,
1548 sizeof(request.data.username) - 1);
1550 ret = pam_winbind_request_log(pamh, ctrl, WINBINDD_GETPWNAM,
1551 &request, &response, user);
1554 case PAM_USER_UNKNOWN:
1564 static char *_pam_delete(register char *xx)
1572 * obtain a password from the user
1575 static int _winbind_read_password(pam_handle_t * pamh,
1577 const char *comment,
1578 const char *prompt1,
1579 const char *prompt2,
1587 _pam_log(pamh, ctrl, LOG_DEBUG, "getting password (0x%08x)", ctrl);
1590 * make sure nothing inappropriate gets returned
1593 *pass = token = NULL;
1596 * which authentication token are we getting?
1599 if (on(WINBIND__OLD_PASSWORD, ctrl)) {
1600 authtok_flag = PAM_OLDAUTHTOK;
1602 authtok_flag = PAM_AUTHTOK;
1606 * should we obtain the password from a PAM item ?
1609 if (on(WINBIND_TRY_FIRST_PASS_ARG, ctrl) ||
1610 on(WINBIND_USE_FIRST_PASS_ARG, ctrl)) {
1611 retval = _pam_get_item(pamh, authtok_flag, &item);
1612 if (retval != PAM_SUCCESS) {
1614 _pam_log(pamh, ctrl, LOG_ALERT,
1615 "pam_get_item returned error "
1616 "to unix-read-password");
1618 } else if (item != NULL) { /* we have a password! */
1621 _pam_log(pamh, ctrl, LOG_DEBUG,
1622 "pam_get_item returned a password");
1624 } else if (on(WINBIND_USE_FIRST_PASS_ARG, ctrl)) {
1625 return PAM_AUTHTOK_RECOVER_ERR; /* didn't work */
1626 } else if (on(WINBIND_USE_AUTHTOK_ARG, ctrl)
1627 && off(WINBIND__OLD_PASSWORD, ctrl)) {
1628 return PAM_AUTHTOK_RECOVER_ERR;
1632 * getting here implies we will have to get the password from the
1637 struct pam_message msg[3], *pmsg[3];
1638 struct pam_response *resp;
1641 /* prepare to converse */
1643 if (comment != NULL && off(ctrl, WINBIND_SILENT)) {
1645 msg[0].msg_style = PAM_TEXT_INFO;
1646 msg[0].msg = discard_const_p(char, comment);
1653 msg[i].msg_style = PAM_PROMPT_ECHO_OFF;
1654 msg[i++].msg = discard_const_p(char, prompt1);
1657 if (prompt2 != NULL) {
1659 msg[i].msg_style = PAM_PROMPT_ECHO_OFF;
1660 msg[i++].msg = discard_const_p(char, prompt2);
1663 /* so call the conversation expecting i responses */
1665 retval = converse(pamh, i, pmsg, &resp);
1667 if (retval == PAM_SUCCESS) {
1668 retval = PAM_AUTHTOK_RECOVER_ERR;
1672 if (retval != PAM_SUCCESS) {
1673 _pam_drop_reply(resp, i);
1677 /* interpret the response */
1679 token = x_strdup(resp[i - replies].resp);
1681 _pam_log(pamh, ctrl, LOG_NOTICE,
1682 "could not recover "
1683 "authentication token");
1684 retval = PAM_AUTHTOK_RECOVER_ERR;
1689 /* verify that password entered correctly */
1690 if (!resp[i - 1].resp ||
1691 strcmp(token, resp[i - 1].resp)) {
1692 _pam_delete(token); /* mistyped */
1693 retval = PAM_AUTHTOK_RECOVER_ERR;
1694 _make_remark(pamh, ctrl, PAM_ERROR_MSG,
1700 * tidy up the conversation (resp_retcode) is ignored
1701 * -- what is it for anyway? AGM
1703 _pam_drop_reply(resp, i);
1707 if (retval != PAM_SUCCESS) {
1708 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
1709 "unable to obtain a password");
1712 /* 'token' is the entered password */
1714 /* we store this password as an item */
1716 retval = pam_set_item(pamh, authtok_flag, token);
1717 _pam_delete(token); /* clean it up */
1718 if (retval != PAM_SUCCESS ||
1719 (retval = _pam_get_item(pamh, authtok_flag, &item)) != PAM_SUCCESS) {
1721 _pam_log(pamh, ctrl, LOG_CRIT, "error manipulating password");
1727 item = NULL; /* break link to password */
1732 static const char *get_conf_item_string(const pam_handle_t *pamh,
1741 const char *parm_opt = NULL;
1743 if (!(ctrl & config_flag)) {
1747 /* let the pam opt take precedence over the pam_winbind.conf option */
1748 for (i=0; i<argc; i++) {
1750 if ((strncmp(argv[i], item, strlen(item)) == 0)) {
1753 if ((p = strchr(argv[i], '=')) == NULL) {
1754 _pam_log(pamh, ctrl, LOG_INFO,
1755 "no \"=\" delimiter for \"%s\" found\n",
1759 _pam_log_debug(pamh, ctrl, LOG_INFO,
1760 "PAM config: %s '%s'\n", item, p+1);
1768 if (!asprintf(&key, "global:%s", item)) {
1772 parm_opt = iniparser_getstr(d, key);
1775 _pam_log_debug(pamh, ctrl, LOG_INFO, "CONFIG file: %s '%s'\n",
1782 static int get_config_item_int(const pam_handle_t *pamh,
1790 int i, parm_opt = -1;
1792 if (!(ctrl & config_flag)) {
1796 /* let the pam opt take precedence over the pam_winbind.conf option */
1797 for (i = 0; i < argc; i++) {
1799 if ((strncmp(argv[i], item, strlen(item)) == 0)) {
1802 if ((p = strchr(argv[i], '=')) == NULL) {
1803 _pam_log(pamh, ctrl, LOG_INFO,
1804 "no \"=\" delimiter for \"%s\" found\n",
1808 parm_opt = atoi(p + 1);
1809 _pam_log_debug(pamh, ctrl, LOG_INFO,
1810 "PAM config: %s '%d'\n",
1819 if (!asprintf(&key, "global:%s", item)) {
1823 parm_opt = iniparser_getint(d, key, -1);
1826 _pam_log_debug(pamh, ctrl, LOG_INFO,
1827 "CONFIG file: %s '%d'\n",
1834 static const char *get_krb5_cc_type_from_config(const pam_handle_t *pamh,
1840 return get_conf_item_string(pamh, argc, argv, ctrl, d,
1842 WINBIND_KRB5_CCACHE_TYPE);
1845 static const char *get_member_from_config(const pam_handle_t *pamh,
1851 const char *ret = NULL;
1852 ret = get_conf_item_string(pamh, argc, argv, ctrl, d,
1853 "require_membership_of",
1854 WINBIND_REQUIRED_MEMBERSHIP);
1858 return get_conf_item_string(pamh, argc, argv, ctrl, d,
1859 "require-membership-of",
1860 WINBIND_REQUIRED_MEMBERSHIP);
1863 static int get_warn_pwd_expire_from_config(const pam_handle_t *pamh,
1870 ret = get_config_item_int(pamh, argc, argv, ctrl, d,
1872 WINBIND_WARN_PWD_EXPIRE);
1873 /* no or broken setting */
1875 return DEFAULT_DAYS_TO_WARN_BEFORE_PWD_EXPIRES;
1881 * Retrieve the winbind separator.
1883 * @param pamh PAM handle
1884 * @param ctrl PAM winbind options.
1886 * @return string separator character. NULL on failure.
1889 static char winbind_get_separator(pam_handle_t *pamh,
1892 struct winbindd_request request;
1893 struct winbindd_response response;
1895 ZERO_STRUCT(request);
1896 ZERO_STRUCT(response);
1898 if (pam_winbind_request_log(pamh, ctrl, WINBINDD_INFO,
1899 &request, &response, NULL)) {
1903 return response.data.info.winbind_separator;
1907 * Convert a upn to a name.
1909 * @param pamh PAM handle
1910 * @param ctrl PAM winbind options.
1911 * @param upn USer UPN to be trabslated.
1913 * @return converted name. NULL pointer on failure. Caller needs to free.
1916 static char* winbind_upn_to_username(pam_handle_t *pamh,
1920 struct winbindd_request req;
1921 struct winbindd_response resp;
1924 int account_name_len;
1927 /* This cannot work when the winbind separator = @ */
1929 sep = winbind_get_separator(pamh, ctrl);
1930 if (!sep || sep == '@') {
1934 /* Convert the UPN to a SID */
1939 strncpy(req.data.name.dom_name, "",
1940 sizeof(req.data.name.dom_name) - 1);
1941 strncpy(req.data.name.name, upn,
1942 sizeof(req.data.name.name) - 1);
1943 retval = pam_winbind_request_log(pamh, ctrl, WINBINDD_LOOKUPNAME,
1945 if (retval != PAM_SUCCESS) {
1949 /* Convert the the SID back to the sAMAccountName */
1952 strncpy(req.data.sid, resp.data.sid.sid, sizeof(req.data.sid)-1);
1954 retval = pam_winbind_request_log(pamh, ctrl, WINBINDD_LOOKUPSID,
1956 if (retval != PAM_SUCCESS) {
1960 account_name_len = asprintf(&account_name, "%s\\%s",
1961 resp.data.name.dom_name,
1962 resp.data.name.name);
1964 return account_name;
1968 int pam_sm_authenticate(pam_handle_t *pamh, int flags,
1969 int argc, const char **argv)
1971 const char *username;
1972 const char *password;
1973 const char *member = NULL;
1974 const char *cctype = NULL;
1975 int warn_pwd_expire;
1976 int retval = PAM_AUTH_ERR;
1977 dictionary *d = NULL;
1978 char *username_ret = NULL;
1979 char *new_authtok_required = NULL;
1980 char *real_username = NULL;
1982 /* parse arguments */
1983 int ctrl = _pam_parse(pamh, flags, argc, argv, &d);
1985 retval = PAM_SYSTEM_ERR;
1989 _PAM_LOG_FUNCTION_ENTER("pam_sm_authenticate", pamh, ctrl, flags);
1991 /* Get the username */
1992 retval = pam_get_user(pamh, &username, NULL);
1993 if ((retval != PAM_SUCCESS) || (!username)) {
1994 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
1995 "can not get the username");
1996 retval = PAM_SERVICE_ERR;
2002 /* Decode the user name since AIX does not support logn user
2003 names by default. The name is encoded as _#uid. */
2005 if (username[0] == '_') {
2006 uid_t id = atoi(&username[1]);
2007 struct passwd *pw = NULL;
2009 if ((id!=0) && ((pw = getpwuid(id)) != NULL)) {
2010 real_username = strdup(pw->pw_name);
2015 if (!real_username) {
2016 /* Just making a copy of the username we got from PAM */
2017 if ((real_username = strdup(username)) == NULL) {
2018 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
2019 "memory allocation failure when copying "
2021 retval = PAM_SERVICE_ERR;
2026 /* Maybe this was a UPN */
2028 if (strchr(real_username, '@') != NULL) {
2029 char *samaccountname = NULL;
2031 samaccountname = winbind_upn_to_username(pamh, ctrl,
2033 if (samaccountname) {
2034 free(real_username);
2035 real_username = samaccountname;
2039 retval = _winbind_read_password(pamh, ctrl, NULL,
2043 if (retval != PAM_SUCCESS) {
2044 _pam_log(pamh, ctrl, LOG_ERR,
2045 "Could not retrieve user's password");
2046 retval = PAM_AUTHTOK_ERR;
2050 /* Let's not give too much away in the log file */
2052 #ifdef DEBUG_PASSWORD
2053 _pam_log_debug(pamh, ctrl, LOG_INFO,
2054 "Verify user '%s' with password '%s'",
2055 real_username, password);
2057 _pam_log_debug(pamh, ctrl, LOG_INFO,
2058 "Verify user '%s'", real_username);
2061 member = get_member_from_config(pamh, argc, argv, ctrl, d);
2063 cctype = get_krb5_cc_type_from_config(pamh, argc, argv, ctrl, d);
2065 warn_pwd_expire = get_warn_pwd_expire_from_config(pamh, argc, argv,
2068 /* Now use the username to look up password */
2069 retval = winbind_auth_request(pamh, ctrl, real_username, password,
2070 member, cctype, warn_pwd_expire, NULL,
2071 NULL, &username_ret);
2073 if (retval == PAM_NEW_AUTHTOK_REQD ||
2074 retval == PAM_AUTHTOK_EXPIRED) {
2076 char *new_authtok_required_during_auth = NULL;
2078 if (!asprintf(&new_authtok_required, "%d", retval)) {
2079 retval = PAM_BUF_ERR;
2083 pam_set_data(pamh, PAM_WINBIND_NEW_AUTHTOK_REQD,
2084 new_authtok_required,
2085 _pam_winbind_cleanup_func);
2087 retval = PAM_SUCCESS;
2089 if (!asprintf(&new_authtok_required_during_auth, "%d", true)) {
2090 retval = PAM_BUF_ERR;
2094 pam_set_data(pamh, PAM_WINBIND_NEW_AUTHTOK_REQD_DURING_AUTH,
2095 new_authtok_required_during_auth,
2096 _pam_winbind_cleanup_func);
2103 pam_set_item (pamh, PAM_USER, username_ret);
2104 _pam_log_debug(pamh, ctrl, LOG_INFO,
2105 "Returned user was '%s'", username_ret);
2109 if (real_username) {
2110 free(real_username);
2114 iniparser_freedict(d);
2117 if (!new_authtok_required) {
2118 pam_set_data(pamh, PAM_WINBIND_NEW_AUTHTOK_REQD, NULL, NULL);
2121 if (retval != PAM_SUCCESS) {
2122 _pam_free_data_info3(pamh);
2125 _PAM_LOG_FUNCTION_LEAVE("pam_sm_authenticate", pamh, ctrl, retval);
2131 int pam_sm_setcred(pam_handle_t *pamh, int flags,
2132 int argc, const char **argv)
2134 int ret = PAM_SYSTEM_ERR;
2135 dictionary *d = NULL;
2137 /* parse arguments */
2138 int ctrl = _pam_parse(pamh, flags, argc, argv, &d);
2140 ret = PAM_SYSTEM_ERR;
2144 _PAM_LOG_FUNCTION_ENTER("pam_sm_setcred", pamh, ctrl, flags);
2146 switch (flags & ~PAM_SILENT) {
2148 case PAM_DELETE_CRED:
2149 ret = pam_sm_close_session(pamh, flags, argc, argv);
2151 case PAM_REFRESH_CRED:
2152 _pam_log_debug(pamh, ctrl, LOG_WARNING,
2153 "PAM_REFRESH_CRED not implemented");
2156 case PAM_REINITIALIZE_CRED:
2157 _pam_log_debug(pamh, ctrl, LOG_WARNING,
2158 "PAM_REINITIALIZE_CRED not implemented");
2161 case PAM_ESTABLISH_CRED:
2162 _pam_log_debug(pamh, ctrl, LOG_WARNING,
2163 "PAM_ESTABLISH_CRED not implemented");
2167 ret = PAM_SYSTEM_ERR;
2173 iniparser_freedict(d);
2176 _PAM_LOG_FUNCTION_LEAVE("pam_sm_setcred", pamh, ctrl, ret);
2182 * Account management. We want to verify that the account exists
2183 * before returning PAM_SUCCESS
2186 int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags,
2187 int argc, const char **argv)
2189 const char *username;
2190 int ret = PAM_USER_UNKNOWN;
2192 dictionary *d = NULL;
2194 /* parse arguments */
2195 int ctrl = _pam_parse(pamh, flags, argc, argv, &d);
2197 return PAM_SYSTEM_ERR;
2200 _PAM_LOG_FUNCTION_ENTER("pam_sm_acct_mgmt", pamh, ctrl, flags);
2203 /* Get the username */
2204 ret = pam_get_user(pamh, &username, NULL);
2205 if ((ret != PAM_SUCCESS) || (!username)) {
2206 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
2207 "can not get the username");
2208 ret = PAM_SERVICE_ERR;
2212 /* Verify the username */
2213 ret = valid_user(pamh, ctrl, username);
2216 /* some sort of system error. The log was already printed */
2217 ret = PAM_SERVICE_ERR;
2220 /* the user does not exist */
2221 _pam_log_debug(pamh, ctrl, LOG_NOTICE, "user '%s' not found",
2223 if (ctrl & WINBIND_UNKNOWN_OK_ARG) {
2227 ret = PAM_USER_UNKNOWN;
2230 pam_get_data(pamh, PAM_WINBIND_NEW_AUTHTOK_REQD,
2231 (const void **)&tmp);
2233 ret = atoi((const char *)tmp);
2235 case PAM_AUTHTOK_EXPIRED:
2236 /* fall through, since new token is required in this case */
2237 case PAM_NEW_AUTHTOK_REQD:
2238 _pam_log(pamh, ctrl, LOG_WARNING,
2239 "pam_sm_acct_mgmt success but %s is set",
2240 PAM_WINBIND_NEW_AUTHTOK_REQD);
2241 _pam_log(pamh, ctrl, LOG_NOTICE,
2242 "user '%s' needs new password",
2244 /* PAM_AUTHTOKEN_REQD does not exist, but is documented in the manpage */
2245 ret = PAM_NEW_AUTHTOK_REQD;
2248 _pam_log(pamh, ctrl, LOG_WARNING,
2249 "pam_sm_acct_mgmt success");
2250 _pam_log(pamh, ctrl, LOG_NOTICE,
2251 "user '%s' granted access", username);
2257 /* Otherwise, the authentication looked good */
2258 _pam_log(pamh, ctrl, LOG_NOTICE,
2259 "user '%s' granted access", username);
2263 /* we don't know anything about this return value */
2264 _pam_log(pamh, ctrl, LOG_ERR,
2265 "internal module error (ret = %d, user = '%s')",
2267 ret = PAM_SERVICE_ERR;
2271 /* should not be reached */
2277 iniparser_freedict(d);
2280 _PAM_LOG_FUNCTION_LEAVE("pam_sm_acct_mgmt", pamh, ctrl, ret);
2286 int pam_sm_open_session(pam_handle_t *pamh, int flags,
2287 int argc, const char **argv)
2289 int ret = PAM_SYSTEM_ERR;
2290 dictionary *d = NULL;
2292 /* parse arguments */
2293 int ctrl = _pam_parse(pamh, flags, argc, argv, &d);
2295 ret = PAM_SYSTEM_ERR;
2299 _PAM_LOG_FUNCTION_ENTER("pam_sm_open_session", pamh, ctrl, flags);
2305 iniparser_freedict(d);
2308 _PAM_LOG_FUNCTION_LEAVE("pam_sm_open_session", pamh, ctrl, ret);
2314 int pam_sm_close_session(pam_handle_t *pamh, int flags,
2315 int argc, const char **argv)
2317 dictionary *d = NULL;
2318 int retval = PAM_SUCCESS;
2320 /* parse arguments */
2321 int ctrl = _pam_parse(pamh, flags, argc, argv, &d);
2323 retval = PAM_SYSTEM_ERR;
2327 _PAM_LOG_FUNCTION_ENTER("pam_sm_close_session", pamh, ctrl, flags);
2329 if (!(flags & PAM_DELETE_CRED)) {
2330 retval = PAM_SUCCESS;
2334 if (ctrl & WINBIND_KRB5_AUTH) {
2336 /* destroy the ccache here */
2337 struct winbindd_request request;
2338 struct winbindd_response response;
2340 const char *ccname = NULL;
2341 struct passwd *pwd = NULL;
2343 ZERO_STRUCT(request);
2344 ZERO_STRUCT(response);
2346 retval = pam_get_user(pamh, &user, "Username: ");
2348 _pam_log(pamh, ctrl, LOG_ERR,
2349 "could not identify user");
2354 _pam_log(pamh, ctrl, LOG_ERR,
2355 "username was NULL!");
2356 retval = PAM_USER_UNKNOWN;
2360 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
2361 "username [%s] obtained", user);
2363 ccname = pam_getenv(pamh, "KRB5CCNAME");
2364 if (ccname == NULL) {
2365 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
2366 "user has no KRB5CCNAME environment");
2369 strncpy(request.data.logoff.user, user,
2370 sizeof(request.data.logoff.user) - 1);
2373 strncpy(request.data.logoff.krb5ccname, ccname,
2374 sizeof(request.data.logoff.krb5ccname) - 1);
2377 pwd = getpwnam(user);
2379 retval = PAM_USER_UNKNOWN;
2382 request.data.logoff.uid = pwd->pw_uid;
2384 request.flags = WBFLAG_PAM_KRB5 |
2385 WBFLAG_PAM_CONTACT_TRUSTDOM;
2387 retval = pam_winbind_request_log(pamh, ctrl,
2388 WINBINDD_PAM_LOGOFF,
2389 &request, &response, user);
2394 iniparser_freedict(d);
2397 _PAM_LOG_FUNCTION_LEAVE("pam_sm_close_session", pamh, ctrl, retval);
2403 * evaluate whether we need to re-authenticate with kerberos after a
2406 * @param pamh PAM handle
2407 * @param ctrl PAM winbind options.
2408 * @param user The username
2410 * @return boolean Returns true if required, false if not.
2413 static bool _pam_require_krb5_auth_after_chauthtok(pam_handle_t *pamh,
2418 /* Make sure that we only do this if a) the chauthtok got initiated
2419 * during a logon attempt (authenticate->acct_mgmt->chauthtok) b) any
2420 * later password change via the "passwd" command if done by the user
2423 char *new_authtok_reqd_during_auth = NULL;
2424 struct passwd *pwd = NULL;
2426 if (!(ctrl & WINBIND_KRB5_AUTH)) {
2430 _pam_get_data(pamh, PAM_WINBIND_NEW_AUTHTOK_REQD_DURING_AUTH,
2431 &new_authtok_reqd_during_auth);
2432 pam_set_data(pamh, PAM_WINBIND_NEW_AUTHTOK_REQD_DURING_AUTH,
2435 if (new_authtok_reqd_during_auth) {
2439 pwd = getpwnam(user);
2444 if (getuid() == pwd->pw_uid) {
2453 int pam_sm_chauthtok(pam_handle_t * pamh, int flags,
2454 int argc, const char **argv)
2460 /* <DO NOT free() THESE> */
2462 char *pass_old, *pass_new;
2463 /* </DO NOT free() THESE> */
2468 dictionary *d = NULL;
2469 char *username_ret = NULL;
2470 struct winbindd_response response;
2472 ZERO_STRUCT(response);
2474 ctrl = _pam_parse(pamh, flags, argc, argv, &d);
2476 ret = PAM_SYSTEM_ERR;
2480 _PAM_LOG_FUNCTION_ENTER("pam_sm_chauthtok", pamh, ctrl, flags);
2482 /* clearing offline bit for the auth in the password change */
2483 ctrl &= ~WINBIND_CACHED_LOGIN;
2486 * First get the name of a user
2488 ret = pam_get_user(pamh, &user, "Username: ");
2490 _pam_log(pamh, ctrl, LOG_ERR,
2491 "password - could not identify user");
2496 _pam_log(pamh, ctrl, LOG_ERR, "username was NULL!");
2497 ret = PAM_USER_UNKNOWN;
2501 _pam_log_debug(pamh, ctrl, LOG_DEBUG, "username [%s] obtained", user);
2503 /* check if this is really a user in winbindd, not only in NSS */
2504 ret = valid_user(pamh, ctrl, user);
2507 ret = PAM_USER_UNKNOWN;
2510 ret = PAM_SYSTEM_ERR;
2517 * obtain and verify the current password (OLDAUTHTOK) for
2521 if (flags & PAM_PRELIM_CHECK) {
2522 time_t pwdlastset_prelim = 0;
2524 /* instruct user what is happening */
2525 #define greeting "Changing password for "
2526 Announce = (char *) malloc(sizeof(greeting) + strlen(user));
2527 if (Announce == NULL) {
2528 _pam_log(pamh, ctrl, LOG_CRIT,
2529 "password - out of memory");
2533 (void) strcpy(Announce, greeting);
2534 (void) strcpy(Announce + sizeof(greeting) - 1, user);
2537 lctrl = ctrl | WINBIND__OLD_PASSWORD;
2538 ret = _winbind_read_password(pamh, lctrl,
2540 "(current) NT password: ",
2542 (const char **) &pass_old);
2543 if (ret != PAM_SUCCESS) {
2544 _pam_log(pamh, ctrl, LOG_NOTICE,
2545 "password - (old) token not obtained");
2549 /* verify that this is the password for this user */
2551 ret = winbind_auth_request(pamh, ctrl, user, pass_old,
2552 NULL, NULL, 0, &response,
2553 &pwdlastset_prelim, NULL);
2555 if (ret != PAM_ACCT_EXPIRED &&
2556 ret != PAM_AUTHTOK_EXPIRED &&
2557 ret != PAM_NEW_AUTHTOK_REQD &&
2558 ret != PAM_SUCCESS) {
2563 pam_set_data(pamh, PAM_WINBIND_PWD_LAST_SET,
2564 (void *)pwdlastset_prelim, NULL);
2566 ret = pam_set_item(pamh, PAM_OLDAUTHTOK,
2567 (const void *) pass_old);
2569 if (ret != PAM_SUCCESS) {
2570 _pam_log(pamh, ctrl, LOG_CRIT,
2571 "failed to set PAM_OLDAUTHTOK");
2573 } else if (flags & PAM_UPDATE_AUTHTOK) {
2575 time_t pwdlastset_update = 0;
2578 * obtain the proposed password
2582 * get the old token back.
2585 ret = _pam_get_item(pamh, PAM_OLDAUTHTOK, &pass_old);
2587 if (ret != PAM_SUCCESS) {
2588 _pam_log(pamh, ctrl, LOG_NOTICE,
2589 "user not authenticated");
2593 lctrl = ctrl & ~WINBIND_TRY_FIRST_PASS_ARG;
2595 if (on(WINBIND_USE_AUTHTOK_ARG, lctrl)) {
2596 lctrl |= WINBIND_USE_FIRST_PASS_ARG;
2599 ret = PAM_AUTHTOK_ERR;
2600 while ((ret != PAM_SUCCESS) && (retry++ < MAX_PASSWD_TRIES)) {
2602 * use_authtok is to force the use of a previously entered
2603 * password -- needed for pluggable password strength checking
2606 ret = _winbind_read_password(pamh, lctrl,
2608 "Enter new NT password: ",
2609 "Retype new NT password: ",
2610 (const char **)&pass_new);
2612 if (ret != PAM_SUCCESS) {
2613 _pam_log_debug(pamh, ctrl, LOG_ALERT,
2615 "new password not obtained");
2616 pass_old = NULL;/* tidy up */
2621 * At this point we know who the user is and what they
2622 * propose as their new password. Verify that the new
2623 * password is acceptable.
2626 if (pass_new[0] == '\0') {/* "\0" password = NULL */
2632 * By reaching here we have approved the passwords and must now
2633 * rebuild the password database file.
2635 _pam_get_data(pamh, PAM_WINBIND_PWD_LAST_SET,
2636 &pwdlastset_update);
2638 ret = winbind_chauthtok_request(pamh, ctrl, user, pass_old,
2639 pass_new, pwdlastset_update);
2641 _pam_overwrite(pass_new);
2642 _pam_overwrite(pass_old);
2643 pass_old = pass_new = NULL;
2647 if (_pam_require_krb5_auth_after_chauthtok(pamh, ctrl, user)) {
2649 const char *member = NULL;
2650 const char *cctype = NULL;
2651 int warn_pwd_expire;
2653 member = get_member_from_config(pamh, argc, argv,
2655 cctype = get_krb5_cc_type_from_config(pamh, argc, argv,
2657 warn_pwd_expire = get_warn_pwd_expire_from_config(pamh,
2664 ret = winbind_auth_request(pamh, ctrl, user, pass_new,
2665 member, cctype, 0, &response,
2666 NULL, &username_ret);
2667 _pam_overwrite(pass_new);
2668 _pam_overwrite(pass_old);
2669 pass_old = pass_new = NULL;
2671 if (ret == PAM_SUCCESS) {
2673 /* warn a user if the password is about to
2675 _pam_warn_password_expiry(pamh, ctrl, &response,
2679 /* set some info3 info for other modules in the
2681 _pam_set_data_info3(pamh, ctrl, &response);
2683 /* put krb5ccname into env */
2684 _pam_setup_krb5_env(pamh, ctrl,
2685 response.data.auth.krb5ccname);
2688 pam_set_item(pamh, PAM_USER,
2690 _pam_log_debug(pamh, ctrl, LOG_INFO,
2691 "Returned user was '%s'",
2700 ret = PAM_SERVICE_ERR;
2705 iniparser_freedict(d);
2708 /* Deal with offline errors. */
2709 PAM_WB_REMARK_CHECK_RESPONSE(pamh, ctrl, response,
2710 "NT_STATUS_NO_LOGON_SERVERS");
2711 PAM_WB_REMARK_CHECK_RESPONSE(pamh, ctrl, response,
2712 "NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND");
2713 PAM_WB_REMARK_CHECK_RESPONSE(pamh, ctrl, response,
2714 "NT_STATUS_ACCESS_DENIED");
2716 _PAM_LOG_FUNCTION_LEAVE("pam_sm_chauthtok", pamh, ctrl, ret);
2723 /* static module data */
2725 struct pam_module _pam_winbind_modstruct = {
2727 pam_sm_authenticate,
2730 pam_sm_open_session,
2731 pam_sm_close_session,
2738 * Copyright (c) Andrew Tridgell <tridge@samba.org> 2000
2739 * Copyright (c) Tim Potter <tpot@samba.org> 2000
2740 * Copyright (c) Andrew Bartlettt <abartlet@samba.org> 2002
2741 * Copyright (c) Guenther Deschner <gd@samba.org> 2005-2007
2742 * Copyright (c) Jan Rêkorajski 1999.
2743 * Copyright (c) Andrew G. Morgan 1996-8.
2744 * Copyright (c) Alex O. Yuriev, 1996.
2745 * Copyright (c) Cristian Gafton 1996.
2746 * Copyright (C) Elliot Lee <sopwith@redhat.com> 1996, Red Hat Software.
2748 * Redistribution and use in source and binary forms, with or without
2749 * modification, are permitted provided that the following conditions
2751 * 1. Redistributions of source code must retain the above copyright
2752 * notice, and the entire permission notice in its entirety,
2753 * including the disclaimer of warranties.
2754 * 2. Redistributions in binary form must reproduce the above copyright
2755 * notice, this list of conditions and the following disclaimer in the
2756 * documentation and/or other materials provided with the distribution.
2757 * 3. The name of the author may not be used to endorse or promote
2758 * products derived from this software without specific prior
2759 * written permission.
2761 * ALTERNATIVELY, this product may be distributed under the terms of
2762 * the GNU Public License, in which case the provisions of the GPL are
2763 * required INSTEAD OF the above restrictions. (This clause is
2764 * necessary due to a potential bad interaction between the GPL and
2765 * the restrictions contained in a BSD-style copyright.)
2767 * THIS SOFTWARE IS PROVIDED `AS IS'' AND ANY EXPRESS OR IMPLIED
2768 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
2769 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2770 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
2771 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
2772 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2773 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2774 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
2775 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2776 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
2777 * OF THE POSSIBILITY OF SUCH DAMAGE.