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-2006
8 largely based on pam_userdb by Cristian Gafton <gafton@redhat.com>
9 also contains large slabs of code from pam_unix by Elliot Lee <sopwith@redhat.com>
10 (see copyright below for full details)
13 #include "pam_winbind.h"
17 #define MAX_PASSWD_TRIES 3
20 * Work around the pam API that has functions with void ** as parameters.
21 * These lead to strict aliasing warnings with gcc.
23 static int _pam_get_item(const pam_handle_t *pamh, int item_type,
26 const void **item = (const void **)_item;
27 return pam_get_item(pamh, item_type, item);
29 static int _pam_get_data(const pam_handle_t *pamh,
30 const char *module_data_name, const void *_data)
32 const void **data = (const void **)_data;
33 return pam_get_data(pamh, module_data_name, data);
38 #ifdef HAVE_PAM_VSYSLOG
39 static void _pam_log_int(const pam_handle_t *pamh, int err, const char *format, va_list args)
41 pam_vsyslog(pamh, err, format, args);
44 static void _pam_log_int(const pam_handle_t *pamh, int err, const char *format, va_list args)
49 _pam_get_item(pamh, PAM_SERVICE, &service);
51 format2 = malloc(strlen(MODULE_NAME)+strlen(format)+strlen(service)+5);
52 if (format2 == NULL) {
53 /* what else todo ? */
54 vsyslog(err, format, args);
58 sprintf(format2, "%s(%s): %s", MODULE_NAME, service, format);
59 vsyslog(err, format2, args);
62 #endif /* HAVE_PAM_VSYSLOG */
64 static void _pam_log(const pam_handle_t *pamh, int ctrl, int err, const char *format, ...)
68 if (ctrl & WINBIND_SILENT) {
72 va_start(args, format);
73 _pam_log_int(pamh, err, format, args);
77 static void _pam_log_debug(const pam_handle_t *pamh, int ctrl, int err, const char *format, ...)
81 if (ctrl & WINBIND_SILENT) {
85 if (!(ctrl & WINBIND_DEBUG_ARG)) {
89 va_start(args, format);
90 _pam_log_int(pamh, err, format, args);
94 static int _pam_parse(const pam_handle_t *pamh, int flags, int argc, const char **argv, dictionary **d)
97 const char *config_file = NULL;
101 if (flags & PAM_SILENT) {
102 ctrl |= WINBIND_SILENT;
106 goto config_from_pam;
109 for (i=argc,v=argv; i-- > 0; ++v) {
110 if (!strncasecmp(*v, "config", strlen("config"))) {
111 ctrl |= WINBIND_CONFIG_FILE;
117 if (config_file == NULL) {
118 config_file = PAM_WINBIND_CONFIG_FILE;
121 *d = iniparser_load(config_file);
123 goto config_from_pam;
126 if (iniparser_getboolean(*d, "global:debug", False)) {
127 ctrl |= WINBIND_DEBUG_ARG;
130 if (iniparser_getboolean(*d, "global:cached_login", False)) {
131 ctrl |= WINBIND_CACHED_LOGIN;
134 if (iniparser_getboolean(*d, "global:krb5_auth", False)) {
135 ctrl |= WINBIND_KRB5_AUTH;
138 if (iniparser_getboolean(*d, "global:silent", False)) {
139 ctrl |= WINBIND_SILENT;
142 if (iniparser_getstr(*d, "global:krb5_ccache_type") != NULL) {
143 ctrl |= WINBIND_KRB5_CCACHE_TYPE;
146 if ((iniparser_getstr(*d, "global:require-membership-of") != NULL) ||
147 (iniparser_getstr(*d, "global:require_membership_of") != NULL)) {
148 ctrl |= WINBIND_REQUIRED_MEMBERSHIP;
152 /* step through arguments */
153 for (i=argc,v=argv; i-- > 0; ++v) {
155 /* generic options */
156 if (!strcmp(*v,"debug"))
157 ctrl |= WINBIND_DEBUG_ARG;
158 else if (!strcasecmp(*v, "use_authtok"))
159 ctrl |= WINBIND_USE_AUTHTOK_ARG;
160 else if (!strcasecmp(*v, "use_first_pass"))
161 ctrl |= WINBIND_USE_FIRST_PASS_ARG;
162 else if (!strcasecmp(*v, "try_first_pass"))
163 ctrl |= WINBIND_TRY_FIRST_PASS_ARG;
164 else if (!strcasecmp(*v, "unknown_ok"))
165 ctrl |= WINBIND_UNKNOWN_OK_ARG;
166 else if (!strncasecmp(*v, "require_membership_of", strlen("require_membership_of")))
167 ctrl |= WINBIND_REQUIRED_MEMBERSHIP;
168 else if (!strncasecmp(*v, "require-membership-of", strlen("require-membership-of")))
169 ctrl |= WINBIND_REQUIRED_MEMBERSHIP;
170 else if (!strcasecmp(*v, "krb5_auth"))
171 ctrl |= WINBIND_KRB5_AUTH;
172 else if (!strncasecmp(*v, "krb5_ccache_type", strlen("krb5_ccache_type")))
173 ctrl |= WINBIND_KRB5_CCACHE_TYPE;
174 else if (!strcasecmp(*v, "cached_login"))
175 ctrl |= WINBIND_CACHED_LOGIN;
177 _pam_log(pamh, ctrl, LOG_ERR, "pam_parse: unknown option: %s", *v);
185 static void _pam_winbind_cleanup_func(pam_handle_t *pamh, void *data, int error_status)
191 static const struct ntstatus_errors {
192 const char *ntstatus_string;
193 const char *error_string;
194 } ntstatus_errors[] = {
195 {"NT_STATUS_OK", "Success"},
196 {"NT_STATUS_BACKUP_CONTROLLER", "No primary Domain Controler available"},
197 {"NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND", "No domain controllers found"},
198 {"NT_STATUS_NO_LOGON_SERVERS", "No logon servers"},
199 {"NT_STATUS_PWD_TOO_SHORT", "Password too short"},
200 {"NT_STATUS_PWD_TOO_RECENT", "The password of this user is too recent to change"},
201 {"NT_STATUS_PWD_HISTORY_CONFLICT", "Password is already in password history"},
202 {"NT_STATUS_PASSWORD_EXPIRED", "Your password has expired"},
203 {"NT_STATUS_PASSWORD_MUST_CHANGE", "You need to change your password now"},
204 {"NT_STATUS_INVALID_WORKSTATION", "You are not allowed to logon from this workstation"},
205 {"NT_STATUS_INVALID_LOGON_HOURS", "You are not allowed to logon at this time"},
206 {"NT_STATUS_ACCOUNT_EXPIRED", "Your account has expired. Please contact your System administrator"}, /* SCNR */
207 {"NT_STATUS_ACCOUNT_DISABLED", "Your account is disabled. Please contact your System administrator"}, /* SCNR */
208 {"NT_STATUS_ACCOUNT_LOCKED_OUT", "Your account has been locked. Please contact your System administrator"}, /* SCNR */
209 {"NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT", "Invalid Trust Account"},
210 {"NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT", "Invalid Trust Account"},
211 {"NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT", "Invalid Trust Account"},
212 {"NT_STATUS_ACCESS_DENIED", "Access is denied"},
216 const char *_get_ntstatus_error_string(const char *nt_status_string)
219 for (i=0; ntstatus_errors[i].ntstatus_string != NULL; i++) {
220 if (!strcasecmp(ntstatus_errors[i].ntstatus_string, nt_status_string)) {
221 return ntstatus_errors[i].error_string;
227 /* --- authentication management functions --- */
229 /* Attempt a conversation */
231 static int converse(pam_handle_t *pamh, int nargs,
232 struct pam_message **message,
233 struct pam_response **response)
236 struct pam_conv *conv;
238 retval = _pam_get_item(pamh, PAM_CONV, &conv );
239 if (retval == PAM_SUCCESS) {
240 retval = conv->conv(nargs, (const struct pam_message **)message,
241 response, conv->appdata_ptr);
244 return retval; /* propagate error status */
248 static int _make_remark(pam_handle_t * pamh, int type, const char *text)
250 int retval = PAM_SUCCESS;
252 struct pam_message *pmsg[1], msg[1];
253 struct pam_response *resp;
256 msg[0].msg = CONST_DISCARD(char *, text);
257 msg[0].msg_style = type;
260 retval = converse(pamh, 1, pmsg, &resp);
263 _pam_drop_reply(resp, 1);
268 static int _make_remark_format(pam_handle_t * pamh, int type, const char *format, ...)
274 va_start(args, format);
275 vasprintf(&var, format, args);
278 ret = _make_remark(pamh, type, var);
283 static int pam_winbind_request(pam_handle_t * pamh, int ctrl,
284 enum winbindd_cmd req_type,
285 struct winbindd_request *request,
286 struct winbindd_response *response)
288 /* Fill in request and send down pipe */
289 init_request(request, req_type);
291 if (write_sock(request, sizeof(*request), 0) == -1) {
292 _pam_log(pamh, ctrl, LOG_ERR, "pam_winbind_request: write to socket failed!");
294 return PAM_SERVICE_ERR;
298 if (read_reply(response) == -1) {
299 _pam_log(pamh, ctrl, LOG_ERR, "pam_winbind_request: read from socket failed!");
301 return PAM_SERVICE_ERR;
304 /* We are done with the socket - close it and avoid mischeif */
307 /* Copy reply data from socket */
308 if (response->result != WINBINDD_OK) {
309 if (response->data.auth.pam_error != PAM_SUCCESS) {
310 _pam_log(pamh, ctrl, LOG_ERR, "request failed: %s, PAM error was %s (%d), NT error was %s",
311 response->data.auth.error_string,
312 pam_strerror(pamh, response->data.auth.pam_error),
313 response->data.auth.pam_error,
314 response->data.auth.nt_status_string);
315 return response->data.auth.pam_error;
317 _pam_log(pamh, ctrl, LOG_ERR, "request failed, but PAM error 0!");
318 return PAM_SERVICE_ERR;
325 static int pam_winbind_request_log(pam_handle_t * pamh,
327 enum winbindd_cmd req_type,
328 struct winbindd_request *request,
329 struct winbindd_response *response,
334 retval = pam_winbind_request(pamh, ctrl, req_type, request, response);
338 /* incorrect password */
339 _pam_log(pamh, ctrl, LOG_WARNING, "user '%s' denied access (incorrect password or invalid membership)", user);
341 case PAM_ACCT_EXPIRED:
342 /* account expired */
343 _pam_log(pamh, ctrl, LOG_WARNING, "user '%s' account expired", user);
345 case PAM_AUTHTOK_EXPIRED:
346 /* password expired */
347 _pam_log(pamh, ctrl, LOG_WARNING, "user '%s' password expired", user);
349 case PAM_NEW_AUTHTOK_REQD:
350 /* new password required */
351 _pam_log(pamh, ctrl, LOG_WARNING, "user '%s' new password required", user);
353 case PAM_USER_UNKNOWN:
354 /* the user does not exist */
355 _pam_log_debug(pamh, ctrl, LOG_NOTICE, "user '%s' not found", user);
356 if (ctrl & WINBIND_UNKNOWN_OK_ARG) {
361 if (req_type == WINBINDD_PAM_AUTH) {
362 /* Otherwise, the authentication looked good */
363 _pam_log(pamh, ctrl, LOG_NOTICE, "user '%s' granted access", user);
364 } else if (req_type == WINBINDD_PAM_CHAUTHTOK) {
365 /* Otherwise, the authentication looked good */
366 _pam_log(pamh, ctrl, LOG_NOTICE, "user '%s' password changed", user);
368 /* Otherwise, the authentication looked good */
369 _pam_log(pamh, ctrl, LOG_NOTICE, "user '%s' OK", user);
374 /* we don't know anything about this return value */
375 _pam_log(pamh, ctrl, LOG_ERR, "internal module error (retval = %d, user = '%s')",
381 /* talk to winbindd */
382 static int winbind_auth_request(pam_handle_t * pamh,
388 struct winbindd_response *p_response,
389 time_t *pwd_last_set,
392 struct winbindd_request request;
393 struct winbindd_response response;
396 ZERO_STRUCT(request);
397 ZERO_STRUCT(response);
403 strncpy(request.data.auth.user, user,
404 sizeof(request.data.auth.user)-1);
406 strncpy(request.data.auth.pass, pass,
407 sizeof(request.data.auth.pass)-1);
409 request.data.auth.krb5_cc_type[0] = '\0';
410 request.data.auth.uid = -1;
412 request.flags = WBFLAG_PAM_INFO3_TEXT | WBFLAG_PAM_CONTACT_TRUSTDOM;
414 if (ctrl & WINBIND_KRB5_AUTH) {
416 struct passwd *pwd = NULL;
418 _pam_log_debug(pamh, ctrl, LOG_DEBUG, "enabling krb5 login flag\n");
420 request.flags |= WBFLAG_PAM_KRB5 | WBFLAG_PAM_FALLBACK_AFTER_KRB5;
422 pwd = getpwnam(user);
424 return PAM_USER_UNKNOWN;
426 request.data.auth.uid = pwd->pw_uid;
429 if (ctrl & WINBIND_CACHED_LOGIN) {
430 _pam_log_debug(pamh, ctrl, LOG_DEBUG, "enabling cached login flag\n");
431 request.flags |= WBFLAG_PAM_CACHED_LOGIN;
436 request.flags |= WBFLAG_PAM_UNIX_NAME;
439 if (cctype != NULL) {
440 strncpy(request.data.auth.krb5_cc_type, cctype,
441 sizeof(request.data.auth.krb5_cc_type) - 1);
442 _pam_log_debug(pamh, ctrl, LOG_DEBUG, "enabling request for a %s krb5 ccache\n", cctype);
445 request.data.auth.require_membership_of_sid[0] = '\0';
447 if (member != NULL) {
448 strncpy(request.data.auth.require_membership_of_sid, member,
449 sizeof(request.data.auth.require_membership_of_sid)-1);
453 if ( (member != NULL) && (strncmp("S-", member, 2) != 0) ) {
455 struct winbindd_request sid_request;
456 struct winbindd_response sid_response;
458 ZERO_STRUCT(sid_request);
459 ZERO_STRUCT(sid_response);
461 _pam_log_debug(pamh, ctrl, LOG_DEBUG, "no sid given, looking up: %s\n", member);
463 /* fortunatly winbindd can handle non-separated names */
464 strncpy(sid_request.data.name.name, member,
465 sizeof(sid_request.data.name.name) - 1);
467 if (pam_winbind_request_log(pamh, ctrl, WINBINDD_LOOKUPNAME, &sid_request, &sid_response, user)) {
468 _pam_log(pamh, ctrl, LOG_INFO, "could not lookup name: %s\n", member);
472 member = sid_response.data.sid.sid;
474 strncpy(request.data.auth.require_membership_of_sid, member,
475 sizeof(request.data.auth.require_membership_of_sid)-1);
478 ret = pam_winbind_request_log(pamh, ctrl, WINBINDD_PAM_AUTH, &request, &response, user);
481 *pwd_last_set = response.data.auth.info3.pass_last_set_time;
484 if ((ctrl & WINBIND_KRB5_AUTH) &&
485 response.data.auth.krb5ccname[0] != '\0') {
489 _pam_log_debug(pamh, ctrl, LOG_DEBUG, "request returned KRB5CCNAME: %s",
490 response.data.auth.krb5ccname);
492 snprintf(var, sizeof(var), "KRB5CCNAME=%s", response.data.auth.krb5ccname);
494 ret = pam_putenv(pamh, var);
495 if (ret != PAM_SUCCESS) {
496 _pam_log(pamh, ctrl, LOG_ERR, "failed to set KRB5CCNAME to %s", var);
502 /* We want to process the response in the caller. */
503 *p_response = response;
508 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_PASSWORD_EXPIRED");
509 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_PASSWORD_MUST_CHANGE");
510 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_INVALID_WORKSTATION");
511 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_INVALID_LOGON_HOURS");
512 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_ACCOUNT_EXPIRED");
513 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_ACCOUNT_DISABLED");
514 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_ACCOUNT_LOCKED_OUT");
515 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT");
516 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT");
517 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT");
518 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND");
519 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_NO_LOGON_SERVERS");
522 /* handle the case where the auth was ok, but the password must expire right now */
523 /* good catch from Ralf Haferkamp: an expiry of "never" is translated to -1 */
524 if ( ! (response.data.auth.info3.acct_flags & ACB_PWNOEXP) &&
525 (response.data.auth.policy.expire > 0) &&
526 (response.data.auth.info3.pass_last_set_time + response.data.auth.policy.expire < time(NULL))) {
528 ret = PAM_AUTHTOK_EXPIRED;
530 _pam_log_debug(pamh, ctrl, LOG_DEBUG,"Password has expired (Password was last set: %d, "
531 "the policy says it should expire here %d (now it's: %d)\n",
532 response.data.auth.info3.pass_last_set_time,
533 response.data.auth.info3.pass_last_set_time + response.data.auth.policy.expire,
536 PAM_WB_REMARK_DIRECT_RET(pamh, "NT_STATUS_PASSWORD_EXPIRED");
540 /* warn a user if the password is about to expire soon */
541 if ( ! (response.data.auth.info3.acct_flags & ACB_PWNOEXP) &&
542 (response.data.auth.policy.expire) &&
543 (response.data.auth.info3.pass_last_set_time + response.data.auth.policy.expire > time(NULL) ) ) {
545 int days = (response.data.auth.info3.pass_last_set_time + response.data.auth.policy.expire -
546 time(NULL))/ SECONDS_PER_DAY;
547 if (days <= DAYS_TO_WARN_BEFORE_PWD_EXPIRES) {
548 _make_remark_format(pamh, PAM_TEXT_INFO, "Your password will expire in %d days", days);
552 if (response.data.auth.info3.user_flgs & LOGON_CACHED_ACCOUNT) {
553 _make_remark(pamh, PAM_ERROR_MSG, "Logging on using cached account. Network ressources can be unavailable");
554 _pam_log_debug(pamh, ctrl, LOG_DEBUG,"User %s logged on using cached account\n", user);
557 /* save the CIFS homedir for pam_cifs / pam_mount */
558 if (response.data.auth.info3.home_dir[0] != '\0') {
560 int ret2 = pam_set_data(pamh, PAM_WINBIND_HOMEDIR,
561 (void *) strdup(response.data.auth.info3.home_dir),
562 _pam_winbind_cleanup_func);
564 _pam_log_debug(pamh, ctrl, LOG_DEBUG, "Could not set data: %s",
565 pam_strerror(pamh, ret2));
570 /* save the logon script path for other PAM modules */
571 if (response.data.auth.info3.logon_script[0] != '\0') {
573 int ret2 = pam_set_data(pamh, PAM_WINBIND_LOGONSCRIPT,
574 (void *) strdup(response.data.auth.info3.logon_script),
575 _pam_winbind_cleanup_func);
577 _pam_log_debug(pamh, ctrl, LOG_DEBUG, "Could not set data: %s",
578 pam_strerror(pamh, ret2));
582 /* save the profile path for other PAM modules */
583 if (response.data.auth.info3.profile_path[0] != '\0') {
585 int ret2 = pam_set_data(pamh, PAM_WINBIND_PROFILEPATH,
586 (void *) strdup(response.data.auth.info3.profile_path),
587 _pam_winbind_cleanup_func);
589 _pam_log_debug(pamh, ctrl, LOG_DEBUG, "Could not set data: %s",
590 pam_strerror(pamh, ret2));
594 /* If winbindd returned a username, return the pointer to it here. */
595 if (user_ret && response.extra_data.data) {
596 /* We have to trust it's a null terminated string. */
597 *user_ret = (char *)response.extra_data.data;
603 /* talk to winbindd */
604 static int winbind_chauthtok_request(pam_handle_t * pamh,
611 struct winbindd_request request;
612 struct winbindd_response response;
615 ZERO_STRUCT(request);
616 ZERO_STRUCT(response);
618 if (request.data.chauthtok.user == NULL) return -2;
620 strncpy(request.data.chauthtok.user, user,
621 sizeof(request.data.chauthtok.user) - 1);
623 if (oldpass != NULL) {
624 strncpy(request.data.chauthtok.oldpass, oldpass,
625 sizeof(request.data.chauthtok.oldpass) - 1);
627 request.data.chauthtok.oldpass[0] = '\0';
630 if (newpass != NULL) {
631 strncpy(request.data.chauthtok.newpass, newpass,
632 sizeof(request.data.chauthtok.newpass) - 1);
634 request.data.chauthtok.newpass[0] = '\0';
637 if (ctrl & WINBIND_KRB5_AUTH) {
638 request.flags = WBFLAG_PAM_KRB5 | WBFLAG_PAM_CONTACT_TRUSTDOM;
641 ret = pam_winbind_request_log(pamh, ctrl, WINBINDD_PAM_CHAUTHTOK, &request, &response, user);
643 if (ret == PAM_SUCCESS) {
647 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_BACKUP_CONTROLLER");
648 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND");
649 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_NO_LOGON_SERVERS");
650 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_ACCESS_DENIED");
652 /* TODO: tell the min pwd length ? */
653 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_PWD_TOO_SHORT");
655 /* TODO: tell the minage ? */
656 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_PWD_TOO_RECENT");
658 /* TODO: tell the history length ? */
659 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_PWD_HISTORY_CONFLICT");
661 if (!strcasecmp(response.data.auth.nt_status_string, "NT_STATUS_PASSWORD_RESTRICTION")) {
663 /* FIXME: avoid to send multiple PAM messages after another */
664 switch (response.data.auth.reject_reason) {
667 case REJECT_REASON_OTHER:
668 if ((response.data.auth.policy.min_passwordage > 0) &&
669 (pwd_last_set + response.data.auth.policy.min_passwordage > time(NULL))) {
670 PAM_WB_REMARK_DIRECT(pamh, "NT_STATUS_PWD_TOO_RECENT");
673 case REJECT_REASON_TOO_SHORT:
674 PAM_WB_REMARK_DIRECT(pamh, "NT_STATUS_PWD_TOO_SHORT");
676 case REJECT_REASON_IN_HISTORY:
677 PAM_WB_REMARK_DIRECT(pamh, "NT_STATUS_PWD_HISTORY_CONFLICT");
679 case REJECT_REASON_NOT_COMPLEX:
680 _make_remark(pamh, PAM_ERROR_MSG, "Password does not meet complexity requirements");
683 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
684 "unknown password change reject reason: %d",
685 response.data.auth.reject_reason);
689 _make_remark_format(pamh, PAM_ERROR_MSG,
690 "Your password must be at least %d characters; "
691 "cannot repeat any of the your previous %d passwords"
693 "Please type a different password. "
694 "Type a password which meets these requirements in both text boxes.",
695 response.data.auth.policy.min_length_password,
696 response.data.auth.policy.password_history,
697 (response.data.auth.policy.password_properties & DOMAIN_PASSWORD_COMPLEX) ?
698 "; must contain capitals, numerals or punctuation; and cannot contain your account or full name" :
707 * Checks if a user has an account
714 static int valid_user(pam_handle_t *pamh, int ctrl, const char *user)
716 /* check not only if the user is available over NSS calls, also make
717 * sure it's really a winbind user, this is important when stacking PAM
718 * modules in the 'account' or 'password' facility. */
720 struct passwd *pwd = NULL;
721 struct winbindd_request request;
722 struct winbindd_response response;
725 ZERO_STRUCT(request);
726 ZERO_STRUCT(response);
728 pwd = getpwnam(user);
733 strncpy(request.data.username, user,
734 sizeof(request.data.username) - 1);
736 ret = pam_winbind_request_log(pamh, ctrl, WINBINDD_GETPWNAM, &request, &response, user);
739 case PAM_USER_UNKNOWN:
749 static char *_pam_delete(register char *xx)
757 * obtain a password from the user
760 static int _winbind_read_password(pam_handle_t * pamh,
773 * make sure nothing inappropriate gets returned
776 *pass = token = NULL;
779 * which authentication token are we getting?
782 authtok_flag = on(WINBIND__OLD_PASSWORD, ctrl) ? PAM_OLDAUTHTOK : PAM_AUTHTOK;
785 * should we obtain the password from a PAM item ?
788 if (on(WINBIND_TRY_FIRST_PASS_ARG, ctrl) || on(WINBIND_USE_FIRST_PASS_ARG, ctrl)) {
789 retval = _pam_get_item(pamh, authtok_flag, &item);
790 if (retval != PAM_SUCCESS) {
792 _pam_log(pamh, ctrl, LOG_ALERT,
793 "pam_get_item returned error to unix-read-password"
796 } else if (item != NULL) { /* we have a password! */
800 } else if (on(WINBIND_USE_FIRST_PASS_ARG, ctrl)) {
801 return PAM_AUTHTOK_RECOVER_ERR; /* didn't work */
802 } else if (on(WINBIND_USE_AUTHTOK_ARG, ctrl)
803 && off(WINBIND__OLD_PASSWORD, ctrl)) {
804 return PAM_AUTHTOK_RECOVER_ERR;
808 * getting here implies we will have to get the password from the
813 struct pam_message msg[3], *pmsg[3];
814 struct pam_response *resp;
817 /* prepare to converse */
819 if (comment != NULL) {
821 msg[0].msg_style = PAM_TEXT_INFO;
822 msg[0].msg = CONST_DISCARD(char *, comment);
829 msg[i].msg_style = PAM_PROMPT_ECHO_OFF;
830 msg[i++].msg = CONST_DISCARD(char *, prompt1);
833 if (prompt2 != NULL) {
835 msg[i].msg_style = PAM_PROMPT_ECHO_OFF;
836 msg[i++].msg = CONST_DISCARD(char *, prompt2);
839 /* so call the conversation expecting i responses */
841 retval = converse(pamh, i, pmsg, &resp);
845 /* interpret the response */
847 if (retval == PAM_SUCCESS) { /* a good conversation */
849 token = x_strdup(resp[i - replies].resp);
852 /* verify that password entered correctly */
853 if (!resp[i - 1].resp
854 || strcmp(token, resp[i - 1].resp)) {
855 _pam_delete(token); /* mistyped */
856 retval = PAM_AUTHTOK_RECOVER_ERR;
857 _make_remark(pamh, PAM_ERROR_MSG, MISTYPED_PASS);
861 _pam_log(pamh, ctrl, LOG_NOTICE, "could not recover authentication token");
862 retval = PAM_AUTHTOK_RECOVER_ERR;
867 * tidy up the conversation (resp_retcode) is ignored
868 * -- what is it for anyway? AGM
871 _pam_drop_reply(resp, i);
874 retval = (retval == PAM_SUCCESS)
875 ? PAM_AUTHTOK_RECOVER_ERR : retval;
879 if (retval != PAM_SUCCESS) {
880 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
881 "unable to obtain a password");
884 /* 'token' is the entered password */
886 /* we store this password as an item */
888 retval = pam_set_item(pamh, authtok_flag, token);
889 _pam_delete(token); /* clean it up */
890 if (retval != PAM_SUCCESS ||
891 (retval = _pam_get_item(pamh, authtok_flag, &item)) != PAM_SUCCESS) {
893 _pam_log(pamh, ctrl, LOG_CRIT, "error manipulating password");
899 item = NULL; /* break link to password */
904 const char *get_conf_item_string(const pam_handle_t *pamh,
913 const char *parm_opt = NULL;
916 if (!(ctrl & config_flag)) {
920 /* let the pam opt take precedence over the pam_winbind.conf option */
924 if (!asprintf(&key, "global:%s", item)) {
928 parm_opt = iniparser_getstr(d, key);
932 for ( i=0; i<argc; i++ ) {
934 if ((strncmp(argv[i], item, strlen(item)) == 0)) {
937 if ( (p = strchr( argv[i], '=' )) == NULL) {
938 _pam_log(pamh, ctrl, LOG_INFO, "no \"=\" delimiter for \"%s\" found\n", item);
941 _pam_log_debug(pamh, ctrl, LOG_INFO, "PAM config: %s '%s'\n", item, p+1);
947 _pam_log_debug(pamh, ctrl, LOG_INFO, "CONFIG file: %s '%s'\n", item, parm_opt);
953 const char *get_krb5_cc_type_from_config(const pam_handle_t *pamh, int argc, const char **argv, int ctrl, dictionary *d)
955 return get_conf_item_string(pamh, argc, argv, ctrl, d, "krb5_ccache_type", WINBIND_KRB5_CCACHE_TYPE);
958 const char *get_member_from_config(const pam_handle_t *pamh, int argc, const char **argv, int ctrl, dictionary *d)
960 const char *ret = NULL;
961 ret = get_conf_item_string(pamh, argc, argv, ctrl, d, "require_membership_of", WINBIND_REQUIRED_MEMBERSHIP);
965 return get_conf_item_string(pamh, argc, argv, ctrl, d, "require-membership-of", WINBIND_REQUIRED_MEMBERSHIP);
969 int pam_sm_authenticate(pam_handle_t *pamh, int flags,
970 int argc, const char **argv)
972 const char *username;
973 const char *password;
974 const char *member = NULL;
975 const char *cctype = NULL;
976 int retval = PAM_AUTH_ERR;
977 dictionary *d = NULL;
978 char *username_ret = NULL;
980 /* parse arguments */
981 int ctrl = _pam_parse(pamh, flags, argc, argv, &d);
983 retval = PAM_SYSTEM_ERR;
987 _pam_log_debug(pamh, ctrl, LOG_DEBUG, "pam_winbind: pam_sm_authenticate (flags: 0x%04x)", flags);
989 /* Get the username */
990 retval = pam_get_user(pamh, &username, NULL);
991 if ((retval != PAM_SUCCESS) || (!username)) {
992 _pam_log_debug(pamh, ctrl, LOG_DEBUG, "can not get the username");
993 retval = PAM_SERVICE_ERR;
997 retval = _winbind_read_password(pamh, ctrl, NULL,
1001 if (retval != PAM_SUCCESS) {
1002 _pam_log(pamh, ctrl, LOG_ERR, "Could not retrieve user's password");
1003 retval = PAM_AUTHTOK_ERR;
1007 /* Let's not give too much away in the log file */
1009 #ifdef DEBUG_PASSWORD
1010 _pam_log_debug(pamh, ctrl, LOG_INFO, "Verify user '%s' with password '%s'",
1011 username, password);
1013 _pam_log_debug(pamh, ctrl, LOG_INFO, "Verify user '%s'", username);
1016 member = get_member_from_config(pamh, argc, argv, ctrl, d);
1018 cctype = get_krb5_cc_type_from_config(pamh, argc, argv, ctrl, d);
1020 /* Now use the username to look up password */
1021 retval = winbind_auth_request(pamh, ctrl, username, password, member,
1022 cctype, NULL, NULL, &username_ret);
1024 if (retval == PAM_NEW_AUTHTOK_REQD ||
1025 retval == PAM_AUTHTOK_EXPIRED) {
1029 if (!asprintf(&buf, "%d", retval)) {
1030 retval = PAM_BUF_ERR;
1034 pam_set_data( pamh, PAM_WINBIND_NEW_AUTHTOK_REQD, (void *)buf, _pam_winbind_cleanup_func);
1036 retval = PAM_SUCCESS;
1042 pam_set_item (pamh, PAM_USER, username_ret);
1043 _pam_log_debug(pamh, ctrl, LOG_INFO, "Returned user was '%s'", username_ret);
1048 iniparser_freedict(d);
1054 int pam_sm_setcred(pam_handle_t *pamh, int flags,
1055 int argc, const char **argv)
1057 int ret = PAM_SYSTEM_ERR;
1058 dictionary *d = NULL;
1060 /* parse arguments */
1061 int ctrl = _pam_parse(pamh, flags, argc, argv, &d);
1063 ret = PAM_SYSTEM_ERR;
1067 _pam_log_debug(pamh, ctrl, LOG_DEBUG, "pam_winbind: pam_sm_setcred (flags: 0x%04x)", flags);
1069 switch (flags & ~PAM_SILENT) {
1071 case PAM_DELETE_CRED:
1072 ret = pam_sm_close_session(pamh, flags, argc, argv);
1074 case PAM_REFRESH_CRED:
1075 _pam_log_debug(pamh, ctrl, LOG_WARNING, "PAM_REFRESH_CRED not implemented");
1078 case PAM_REINITIALIZE_CRED:
1079 _pam_log_debug(pamh, ctrl, LOG_WARNING, "PAM_REINITIALIZE_CRED not implemented");
1082 case PAM_ESTABLISH_CRED:
1083 _pam_log_debug(pamh, ctrl, LOG_WARNING, "PAM_ESTABLISH_CRED not implemented");
1087 ret = PAM_SYSTEM_ERR;
1093 iniparser_freedict(d);
1100 * Account management. We want to verify that the account exists
1101 * before returning PAM_SUCCESS
1104 int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags,
1105 int argc, const char **argv)
1107 const char *username;
1108 int ret = PAM_USER_UNKNOWN;
1110 dictionary *d = NULL;
1112 /* parse arguments */
1113 int ctrl = _pam_parse(pamh, flags, argc, argv, &d);
1115 return PAM_SYSTEM_ERR;
1118 _pam_log_debug(pamh, ctrl, LOG_DEBUG, "pam_winbind: pam_sm_acct_mgmt (flags: 0x%04x)", flags);
1121 /* Get the username */
1122 ret = pam_get_user(pamh, &username, NULL);
1123 if ((ret != PAM_SUCCESS) || (!username)) {
1124 _pam_log_debug(pamh, ctrl, LOG_DEBUG,"can not get the username");
1125 ret = PAM_SERVICE_ERR;
1129 /* Verify the username */
1130 ret = valid_user(pamh, ctrl, username);
1133 /* some sort of system error. The log was already printed */
1134 ret = PAM_SERVICE_ERR;
1137 /* the user does not exist */
1138 _pam_log_debug(pamh, ctrl, LOG_NOTICE, "user '%s' not found", username);
1139 if (ctrl & WINBIND_UNKNOWN_OK_ARG) {
1143 ret = PAM_USER_UNKNOWN;
1146 pam_get_data( pamh, PAM_WINBIND_NEW_AUTHTOK_REQD, (const void **)&tmp);
1148 ret = atoi((const char *)tmp);
1150 case PAM_AUTHTOK_EXPIRED:
1151 /* fall through, since new token is required in this case */
1152 case PAM_NEW_AUTHTOK_REQD:
1153 _pam_log(pamh, ctrl, LOG_WARNING, "pam_sm_acct_mgmt success but %s is set",
1154 PAM_WINBIND_NEW_AUTHTOK_REQD);
1155 _pam_log(pamh, ctrl, LOG_NOTICE, "user '%s' needs new password", username);
1156 /* PAM_AUTHTOKEN_REQD does not exist, but is documented in the manpage */
1157 ret = PAM_NEW_AUTHTOK_REQD;
1160 _pam_log(pamh, ctrl, LOG_WARNING, "pam_sm_acct_mgmt success");
1161 _pam_log(pamh, ctrl, LOG_NOTICE, "user '%s' granted access", username);
1167 /* Otherwise, the authentication looked good */
1168 _pam_log(pamh, ctrl, LOG_NOTICE, "user '%s' granted access", username);
1172 /* we don't know anything about this return value */
1173 _pam_log(pamh, ctrl, LOG_ERR, "internal module error (ret = %d, user = '%s')",
1175 ret = PAM_SERVICE_ERR;
1179 /* should not be reached */
1185 iniparser_freedict(d);
1192 int pam_sm_open_session(pam_handle_t *pamh, int flags,
1193 int argc, const char **argv)
1195 int ret = PAM_SYSTEM_ERR;
1196 dictionary *d = NULL;
1198 /* parse arguments */
1199 int ctrl = _pam_parse(pamh, flags, argc, argv, &d);
1201 ret = PAM_SYSTEM_ERR;
1205 _pam_log_debug(pamh, ctrl, LOG_DEBUG, "pam_winbind: pam_sm_open_session handler (flags: 0x%04x)", flags);
1211 iniparser_freedict(d);
1218 int pam_sm_close_session(pam_handle_t *pamh, int flags,
1219 int argc, const char **argv)
1221 dictionary *d = NULL;
1222 int retval = PAM_SUCCESS;
1224 /* parse arguments */
1225 int ctrl = _pam_parse(pamh, flags, argc, argv, &d);
1227 retval = PAM_SYSTEM_ERR;
1231 _pam_log_debug(pamh, ctrl, LOG_DEBUG, "pam_winbind: pam_sm_close_session handler (flags: 0x%04x)", flags);
1233 if (!(flags & PAM_DELETE_CRED)) {
1234 retval = PAM_SUCCESS;
1238 if (ctrl & WINBIND_KRB5_AUTH) {
1240 /* destroy the ccache here */
1241 struct winbindd_request request;
1242 struct winbindd_response response;
1244 const char *ccname = NULL;
1245 struct passwd *pwd = NULL;
1247 ZERO_STRUCT(request);
1248 ZERO_STRUCT(response);
1250 retval = pam_get_user(pamh, &user, "Username: ");
1251 if (retval == PAM_SUCCESS) {
1253 _pam_log(pamh, ctrl, LOG_ERR, "username was NULL!");
1254 retval = PAM_USER_UNKNOWN;
1257 if (retval == PAM_SUCCESS) {
1258 _pam_log_debug(pamh, ctrl, LOG_DEBUG, "username [%s] obtained", user);
1261 _pam_log_debug(pamh, ctrl, LOG_DEBUG, "could not identify user");
1265 ccname = pam_getenv(pamh, "KRB5CCNAME");
1266 if (ccname == NULL) {
1267 _pam_log_debug(pamh, ctrl, LOG_DEBUG, "user has no KRB5CCNAME environment");
1270 strncpy(request.data.logoff.user, user,
1271 sizeof(request.data.logoff.user) - 1);
1274 strncpy(request.data.logoff.krb5ccname, ccname,
1275 sizeof(request.data.logoff.krb5ccname) - 1);
1278 pwd = getpwnam(user);
1280 retval = PAM_USER_UNKNOWN;
1283 request.data.logoff.uid = pwd->pw_uid;
1285 request.flags = WBFLAG_PAM_KRB5 | WBFLAG_PAM_CONTACT_TRUSTDOM;
1287 retval = pam_winbind_request_log(pamh, ctrl, WINBINDD_PAM_LOGOFF, &request, &response, user);
1292 iniparser_freedict(d);
1300 int pam_sm_chauthtok(pam_handle_t * pamh, int flags,
1301 int argc, const char **argv)
1307 /* <DO NOT free() THESE> */
1309 char *pass_old, *pass_new;
1310 /* </DO NOT free() THESE> */
1315 dictionary *d = NULL;
1317 ctrl = _pam_parse(pamh, flags, argc, argv, &d);
1319 ret = PAM_SYSTEM_ERR;
1323 _pam_log_debug(pamh, ctrl, LOG_DEBUG, "pam_winbind: pam_sm_chauthtok (flags: 0x%04x)", flags);
1325 /* clearing offline bit for the auth in the password change */
1326 ctrl &= ~WINBIND_CACHED_LOGIN;
1329 * First get the name of a user
1331 ret = pam_get_user(pamh, &user, "Username: ");
1332 if (ret == PAM_SUCCESS) {
1334 _pam_log(pamh, ctrl, LOG_ERR, "username was NULL!");
1335 ret = PAM_USER_UNKNOWN;
1338 if (ret == PAM_SUCCESS) {
1339 _pam_log_debug(pamh, ctrl, LOG_DEBUG, "username [%s] obtained",
1343 _pam_log_debug(pamh, ctrl, LOG_DEBUG,
1344 "password - could not identify user");
1348 /* check if this is really a user in winbindd, not only in NSS */
1349 ret = valid_user(pamh, ctrl, user);
1352 ret = PAM_USER_UNKNOWN;
1355 ret = PAM_SYSTEM_ERR;
1362 * obtain and verify the current password (OLDAUTHTOK) for
1366 if (flags & PAM_PRELIM_CHECK) {
1367 struct winbindd_response response;
1368 time_t pwdlastset_prelim = 0;
1370 /* instruct user what is happening */
1371 #define greeting "Changing password for "
1372 Announce = (char *) malloc(sizeof(greeting) + strlen(user));
1373 if (Announce == NULL) {
1374 _pam_log(pamh, ctrl, LOG_CRIT, "password - out of memory");
1378 (void) strcpy(Announce, greeting);
1379 (void) strcpy(Announce + sizeof(greeting) - 1, user);
1382 lctrl = ctrl | WINBIND__OLD_PASSWORD;
1383 ret = _winbind_read_password(pamh, lctrl,
1385 "(current) NT password: ",
1387 (const char **) &pass_old);
1388 if (ret != PAM_SUCCESS) {
1389 _pam_log(pamh, ctrl, LOG_NOTICE, "password - (old) token not obtained");
1393 /* We don't need krb5 env set for password change test. */
1394 ctrl &= ~WINBIND_KRB5_AUTH;
1396 /* verify that this is the password for this user */
1398 ret = winbind_auth_request(pamh, ctrl, user, pass_old,
1399 NULL, NULL, &response, &pwdlastset_prelim, NULL);
1401 if (ret != PAM_ACCT_EXPIRED &&
1402 ret != PAM_AUTHTOK_EXPIRED &&
1403 ret != PAM_NEW_AUTHTOK_REQD &&
1404 ret != PAM_SUCCESS) {
1407 iniparser_freedict(d);
1409 /* Deal with offline errors. */
1410 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh,
1412 "NT_STATUS_NO_LOGON_SERVERS");
1413 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh,
1415 "NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND");
1416 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh,
1418 "NT_STATUS_ACCESS_DENIED");
1422 pam_set_data(pamh, PAM_WINBIND_PWD_LAST_SET, (void *)pwdlastset_prelim, NULL);
1424 ret = pam_set_item(pamh, PAM_OLDAUTHTOK, (const void *) pass_old);
1426 if (ret != PAM_SUCCESS) {
1427 _pam_log(pamh, ctrl, LOG_CRIT, "failed to set PAM_OLDAUTHTOK");
1429 } else if (flags & PAM_UPDATE_AUTHTOK) {
1431 time_t pwdlastset_update = 0;
1434 * obtain the proposed password
1438 * get the old token back.
1441 ret = _pam_get_item(pamh, PAM_OLDAUTHTOK, &pass_old);
1443 if (ret != PAM_SUCCESS) {
1444 _pam_log(pamh, ctrl, LOG_NOTICE, "user not authenticated");
1450 if (on(WINBIND_USE_AUTHTOK_ARG, lctrl)) {
1451 lctrl |= WINBIND_USE_FIRST_PASS_ARG;
1454 ret = PAM_AUTHTOK_ERR;
1455 while ((ret != PAM_SUCCESS) && (retry++ < MAX_PASSWD_TRIES)) {
1457 * use_authtok is to force the use of a previously entered
1458 * password -- needed for pluggable password strength checking
1461 ret = _winbind_read_password(pamh, lctrl,
1463 "Enter new NT password: ",
1464 "Retype new NT password: ",
1465 (const char **) &pass_new);
1467 if (ret != PAM_SUCCESS) {
1468 _pam_log_debug(pamh, ctrl, LOG_ALERT
1469 ,"password - new password not obtained");
1470 pass_old = NULL;/* tidy up */
1475 * At this point we know who the user is and what they
1476 * propose as their new password. Verify that the new
1477 * password is acceptable.
1480 if (pass_new[0] == '\0') {/* "\0" password = NULL */
1486 * By reaching here we have approved the passwords and must now
1487 * rebuild the password database file.
1489 _pam_get_data( pamh, PAM_WINBIND_PWD_LAST_SET,
1490 &pwdlastset_update);
1492 ret = winbind_chauthtok_request(pamh, ctrl, user, pass_old, pass_new, pwdlastset_update);
1494 _pam_overwrite(pass_new);
1495 _pam_overwrite(pass_old);
1496 pass_old = pass_new = NULL;
1500 /* just in case we need krb5 creds after a password change over msrpc */
1502 if (ctrl & WINBIND_KRB5_AUTH) {
1503 struct winbindd_response response;
1505 const char *member = get_member_from_config(pamh, argc, argv, ctrl, d);
1506 const char *cctype = get_krb5_cc_type_from_config(pamh, argc, argv, ctrl, d);
1508 ret = winbind_auth_request(pamh, ctrl, user, pass_new,
1509 member, cctype, &response, NULL, NULL);
1510 _pam_overwrite(pass_new);
1511 _pam_overwrite(pass_old);
1512 pass_old = pass_new = NULL;
1514 iniparser_freedict(d);
1516 /* Deal with offline errors. */
1517 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh,
1519 "NT_STATUS_NO_LOGON_SERVERS");
1520 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh,
1522 "NT_STATUS_DOMAIN_CONTROLLER_NOT_FOUND");
1523 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh,
1525 "NT_STATUS_ACCESS_DENIED");
1529 ret = PAM_SERVICE_ERR;
1534 iniparser_freedict(d);
1541 /* static module data */
1543 struct pam_module _pam_winbind_modstruct = {
1545 pam_sm_authenticate,
1548 pam_sm_open_session,
1549 pam_sm_close_session,
1556 * Copyright (c) Andrew Tridgell <tridge@samba.org> 2000
1557 * Copyright (c) Tim Potter <tpot@samba.org> 2000
1558 * Copyright (c) Andrew Bartlettt <abartlet@samba.org> 2002
1559 * Copyright (c) Guenther Deschner <gd@samba.org> 2005-2006
1560 * Copyright (c) Jan Rêkorajski 1999.
1561 * Copyright (c) Andrew G. Morgan 1996-8.
1562 * Copyright (c) Alex O. Yuriev, 1996.
1563 * Copyright (c) Cristian Gafton 1996.
1564 * Copyright (C) Elliot Lee <sopwith@redhat.com> 1996, Red Hat Software.
1566 * Redistribution and use in source and binary forms, with or without
1567 * modification, are permitted provided that the following conditions
1569 * 1. Redistributions of source code must retain the above copyright
1570 * notice, and the entire permission notice in its entirety,
1571 * including the disclaimer of warranties.
1572 * 2. Redistributions in binary form must reproduce the above copyright
1573 * notice, this list of conditions and the following disclaimer in the
1574 * documentation and/or other materials provided with the distribution.
1575 * 3. The name of the author may not be used to endorse or promote
1576 * products derived from this software without specific prior
1577 * written permission.
1579 * ALTERNATIVELY, this product may be distributed under the terms of
1580 * the GNU Public License, in which case the provisions of the GPL are
1581 * required INSTEAD OF the above restrictions. (This clause is
1582 * necessary due to a potential bad interaction between the GPL and
1583 * the restrictions contained in a BSD-style copyright.)
1585 * THIS SOFTWARE IS PROVIDED `AS IS'' AND ANY EXPRESS OR IMPLIED
1586 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1587 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1588 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
1589 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1590 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1591 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1592 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
1593 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1594 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
1595 * OF THE POSSIBILITY OF SUCH DAMAGE.