r17727: Start pulling in changes for 3.0.23c
[Samba/gbeck.git] / source / nsswitch / pam_winbind.c
bloba81561fc9ab528e766b22e98288dcc10a6d90599
1 /* pam_winbind module
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"
15 /* data tokens */
17 #define MAX_PASSWD_TRIES 3
19 /* some syslogging */
20 static void _pam_log(int err, const char *format, ...)
22 va_list args;
24 va_start(args, format);
25 openlog(MODULE_NAME, LOG_CONS|LOG_PID, LOG_AUTH);
26 vsyslog(err, format, args);
27 va_end(args);
28 closelog();
31 static void _pam_log_debug(int ctrl, int err, const char *format, ...)
33 va_list args;
35 if (!(ctrl & WINBIND_DEBUG_ARG)) {
36 return;
39 va_start(args, format);
40 openlog(MODULE_NAME, LOG_CONS|LOG_PID, LOG_AUTH);
41 vsyslog(err, format, args);
42 va_end(args);
43 closelog();
46 static int _pam_parse(int argc, const char **argv, dictionary **d)
48 int ctrl = 0;
49 const char *config_file = NULL;
50 int i;
51 const char **v;
53 if (d == NULL) {
54 goto config_from_pam;
57 for (i=argc,v=argv; i-- > 0; ++v) {
58 if (!strncasecmp(*v, "config", strlen("config"))) {
59 ctrl |= WINBIND_CONFIG_FILE;
60 config_file = v[i];
61 break;
65 if (config_file == NULL) {
66 config_file = PAM_WINBIND_CONFIG_FILE;
69 *d = iniparser_load(CONST_DISCARD(char *, config_file));
70 if (*d == NULL) {
71 goto config_from_pam;
74 if (iniparser_getboolean(*d, CONST_DISCARD(char *, "global:debug"), False)) {
75 ctrl |= WINBIND_DEBUG_ARG;
78 if (iniparser_getboolean(*d, CONST_DISCARD(char *, "global:cached_login"), False)) {
79 ctrl |= WINBIND_CACHED_LOGIN;
82 if (iniparser_getboolean(*d, CONST_DISCARD(char *, "global:krb5_auth"), False)) {
83 ctrl |= WINBIND_KRB5_AUTH;
86 if (iniparser_getstr(*d, CONST_DISCARD(char *,"global:krb5_ccache_type")) != NULL) {
87 ctrl |= WINBIND_KRB5_CCACHE_TYPE;
90 if ((iniparser_getstr(*d, CONST_DISCARD(char *, "global:require-membership-of")) != NULL) ||
91 (iniparser_getstr(*d, CONST_DISCARD(char *, "global:require_membership_of")) != NULL)) {
92 ctrl |= WINBIND_REQUIRED_MEMBERSHIP;
95 config_from_pam:
96 /* step through arguments */
97 for (i=argc,v=argv; i-- > 0; ++v) {
99 /* generic options */
100 if (!strcmp(*v,"debug"))
101 ctrl |= WINBIND_DEBUG_ARG;
102 else if (!strcasecmp(*v, "use_authtok"))
103 ctrl |= WINBIND_USE_AUTHTOK_ARG;
104 else if (!strcasecmp(*v, "use_first_pass"))
105 ctrl |= WINBIND_USE_FIRST_PASS_ARG;
106 else if (!strcasecmp(*v, "try_first_pass"))
107 ctrl |= WINBIND_TRY_FIRST_PASS_ARG;
108 else if (!strcasecmp(*v, "unknown_ok"))
109 ctrl |= WINBIND_UNKNOWN_OK_ARG;
110 else if (!strncasecmp(*v, "require_membership_of", strlen("require_membership_of")))
111 ctrl |= WINBIND_REQUIRED_MEMBERSHIP;
112 else if (!strncasecmp(*v, "require-membership-of", strlen("require-membership-of")))
113 ctrl |= WINBIND_REQUIRED_MEMBERSHIP;
114 else if (!strcasecmp(*v, "krb5_auth"))
115 ctrl |= WINBIND_KRB5_AUTH;
116 else if (!strncasecmp(*v, "krb5_ccache_type", strlen("krb5_ccache_type")))
117 ctrl |= WINBIND_KRB5_CCACHE_TYPE;
118 else if (!strcasecmp(*v, "cached_login"))
119 ctrl |= WINBIND_CACHED_LOGIN;
120 else {
121 _pam_log(LOG_ERR, "pam_parse: unknown option; %s", *v);
125 return ctrl;
128 static void _pam_winbind_cleanup_func(pam_handle_t *pamh, void *data, int error_status)
130 SAFE_FREE(data);
133 static const struct ntstatus_errors {
134 const char *ntstatus_string;
135 const char *error_string;
136 } ntstatus_errors[] = {
137 {"NT_STATUS_OK", "Success"},
138 {"NT_STATUS_BACKUP_CONTROLLER", "No primary Domain Controler available"},
139 {"NT_STATUS_PWD_TOO_SHORT", "Password too short"},
140 {"NT_STATUS_PWD_TOO_RECENT", "The password of this user is too recent to change"},
141 {"NT_STATUS_PWD_HISTORY_CONFLICT", "Password is already in password history"},
142 {"NT_STATUS_PASSWORD_EXPIRED", "Your password has expired"},
143 {"NT_STATUS_PASSWORD_MUST_CHANGE", "You need to change your password now"},
144 {"NT_STATUS_INVALID_WORKSTATION", "You are not allowed to logon from this workstation"},
145 {"NT_STATUS_INVALID_LOGON_HOURS", "You are not allowed to logon at this time"},
146 {"NT_STATUS_ACCOUNT_EXPIRED", "Your account has expired. Please contact your System administrator"}, /* SCNR */
147 {"NT_STATUS_ACCOUNT_DISABLED", "Your account is disabled. Please contact your System administrator"}, /* SCNR */
148 {"NT_STATUS_ACCOUNT_LOCKED_OUT", "Your account has been locked. Please contact your System administrator"}, /* SCNR */
149 {"NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT", "Invalid Trust Account"},
150 {"NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT", "Invalid Trust Account"},
151 {"NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT", "Invalid Trust Account"},
152 {"NT_STATUS_ACCESS_DENIED", "Access is denied"},
153 {NULL, NULL}
156 const char *_get_ntstatus_error_string(const char *nt_status_string)
158 int i;
159 for (i=0; ntstatus_errors[i].ntstatus_string != NULL; i++) {
160 if (!strcasecmp(ntstatus_errors[i].ntstatus_string, nt_status_string)) {
161 return ntstatus_errors[i].error_string;
164 return NULL;
167 /* --- authentication management functions --- */
169 /* Attempt a conversation */
171 static int converse(pam_handle_t *pamh, int nargs,
172 struct pam_message **message,
173 struct pam_response **response)
175 int retval;
176 struct pam_conv *conv;
178 retval = pam_get_item(pamh, PAM_CONV, (const void **) &conv );
179 if (retval == PAM_SUCCESS) {
180 retval = conv->conv(nargs, (const struct pam_message **)message,
181 response, conv->appdata_ptr);
184 return retval; /* propagate error status */
188 static int _make_remark(pam_handle_t * pamh, int type, const char *text)
190 int retval = PAM_SUCCESS;
192 struct pam_message *pmsg[1], msg[1];
193 struct pam_response *resp;
195 pmsg[0] = &msg[0];
196 msg[0].msg = CONST_DISCARD(char *, text);
197 msg[0].msg_style = type;
199 resp = NULL;
200 retval = converse(pamh, 1, pmsg, &resp);
202 if (resp) {
203 _pam_drop_reply(resp, 1);
205 return retval;
208 static int _make_remark_format(pam_handle_t * pamh, int type, const char *format, ...)
210 va_list args;
211 char *var;
212 int ret;
214 va_start(args, format);
215 vasprintf(&var, format, args);
216 va_end(args);
218 ret = _make_remark(pamh, type, var);
219 SAFE_FREE(var);
220 return ret;
223 static int pam_winbind_request(pam_handle_t * pamh, int ctrl,
224 enum winbindd_cmd req_type,
225 struct winbindd_request *request,
226 struct winbindd_response *response)
228 /* Fill in request and send down pipe */
229 init_request(request, req_type);
231 if (write_sock(request, sizeof(*request), 0) == -1) {
232 _pam_log(LOG_ERR, "write to socket failed!");
233 close_sock();
234 return PAM_SERVICE_ERR;
237 /* Wait for reply */
238 if (read_reply(response) == -1) {
239 _pam_log(LOG_ERR, "read from socket failed!");
240 close_sock();
241 return PAM_SERVICE_ERR;
244 /* We are done with the socket - close it and avoid mischeif */
245 close_sock();
247 /* Copy reply data from socket */
248 if (response->result != WINBINDD_OK) {
249 if (response->data.auth.pam_error != PAM_SUCCESS) {
250 _pam_log(LOG_ERR, "request failed: %s, PAM error was %s (%d), NT error was %s",
251 response->data.auth.error_string,
252 pam_strerror(pamh, response->data.auth.pam_error),
253 response->data.auth.pam_error,
254 response->data.auth.nt_status_string);
255 return response->data.auth.pam_error;
256 } else {
257 _pam_log(LOG_ERR, "request failed, but PAM error 0!");
258 return PAM_SERVICE_ERR;
262 return PAM_SUCCESS;
265 static int pam_winbind_request_log(pam_handle_t * pamh,
266 int ctrl,
267 enum winbindd_cmd req_type,
268 struct winbindd_request *request,
269 struct winbindd_response *response,
270 const char *user)
272 int retval;
274 retval = pam_winbind_request(pamh, ctrl, req_type, request, response);
276 switch (retval) {
277 case PAM_AUTH_ERR:
278 /* incorrect password */
279 _pam_log(LOG_WARNING, "user `%s' denied access (incorrect password or invalid membership)", user);
280 return retval;
281 case PAM_ACCT_EXPIRED:
282 /* account expired */
283 _pam_log(LOG_WARNING, "user `%s' account expired", user);
284 return retval;
285 case PAM_AUTHTOK_EXPIRED:
286 /* password expired */
287 _pam_log(LOG_WARNING, "user `%s' password expired", user);
288 return retval;
289 case PAM_NEW_AUTHTOK_REQD:
290 /* new password required */
291 _pam_log(LOG_WARNING, "user `%s' new password required", user);
292 return retval;
293 case PAM_USER_UNKNOWN:
294 /* the user does not exist */
295 _pam_log_debug(ctrl, LOG_NOTICE, "user `%s' not found", user);
296 if (ctrl & WINBIND_UNKNOWN_OK_ARG) {
297 return PAM_IGNORE;
299 return retval;
300 case PAM_SUCCESS:
301 if (req_type == WINBINDD_PAM_AUTH) {
302 /* Otherwise, the authentication looked good */
303 _pam_log(LOG_NOTICE, "user '%s' granted access", user);
304 } else if (req_type == WINBINDD_PAM_CHAUTHTOK) {
305 /* Otherwise, the authentication looked good */
306 _pam_log(LOG_NOTICE, "user '%s' password changed", user);
307 } else {
308 /* Otherwise, the authentication looked good */
309 _pam_log(LOG_NOTICE, "user '%s' OK", user);
312 return retval;
313 default:
314 /* we don't know anything about this return value */
315 _pam_log(LOG_ERR, "internal module error (retval = %d, user = `%s')",
316 retval, user);
317 return retval;
321 /* talk to winbindd */
322 static int winbind_auth_request(pam_handle_t * pamh,
323 int ctrl,
324 const char *user,
325 const char *pass,
326 const char *member,
327 const char *cctype,
328 int process_result,
329 time_t *pwd_last_set)
331 struct winbindd_request request;
332 struct winbindd_response response;
333 int ret;
335 ZERO_STRUCT(request);
336 ZERO_STRUCT(response);
338 if (pwd_last_set) {
339 *pwd_last_set = 0;
342 strncpy(request.data.auth.user, user,
343 sizeof(request.data.auth.user)-1);
345 strncpy(request.data.auth.pass, pass,
346 sizeof(request.data.auth.pass)-1);
348 request.data.auth.krb5_cc_type[0] = '\0';
349 request.data.auth.uid = -1;
351 request.flags = WBFLAG_PAM_INFO3_TEXT | WBFLAG_PAM_CONTACT_TRUSTDOM;
353 if (ctrl & WINBIND_KRB5_AUTH) {
355 struct passwd *pwd = NULL;
357 _pam_log_debug(ctrl, LOG_DEBUG, "enabling krb5 login flag\n");
359 request.flags |= WBFLAG_PAM_KRB5 | WBFLAG_PAM_FALLBACK_AFTER_KRB5;
361 pwd = getpwnam(user);
362 if (pwd == NULL) {
363 return PAM_USER_UNKNOWN;
365 request.data.auth.uid = pwd->pw_uid;
368 if (ctrl & WINBIND_CACHED_LOGIN) {
369 _pam_log_debug(ctrl, LOG_DEBUG, "enabling cached login flag\n");
370 request.flags |= WBFLAG_PAM_CACHED_LOGIN;
373 if (cctype != NULL) {
374 strncpy(request.data.auth.krb5_cc_type, cctype,
375 sizeof(request.data.auth.krb5_cc_type) - 1);
376 _pam_log_debug(ctrl, LOG_DEBUG, "enabling request for a %s krb5 ccache\n", cctype);
379 request.data.auth.require_membership_of_sid[0] = '\0';
381 if (member != NULL) {
382 strncpy(request.data.auth.require_membership_of_sid, member,
383 sizeof(request.data.auth.require_membership_of_sid)-1);
386 /* lookup name? */
387 if ( (member != NULL) && (strncmp("S-", member, 2) != 0) ) {
389 struct winbindd_request sid_request;
390 struct winbindd_response sid_response;
392 ZERO_STRUCT(sid_request);
393 ZERO_STRUCT(sid_response);
395 _pam_log_debug(ctrl, LOG_DEBUG, "no sid given, looking up: %s\n", member);
397 /* fortunatly winbindd can handle non-separated names */
398 strncpy(sid_request.data.name.name, member,
399 sizeof(sid_request.data.name.name) - 1);
401 if (pam_winbind_request_log(pamh, ctrl, WINBINDD_LOOKUPNAME, &sid_request, &sid_response, user)) {
402 _pam_log(LOG_INFO, "could not lookup name: %s\n", member);
403 return PAM_AUTH_ERR;
406 member = sid_response.data.sid.sid;
408 strncpy(request.data.auth.require_membership_of_sid, member,
409 sizeof(request.data.auth.require_membership_of_sid)-1);
412 ret = pam_winbind_request_log(pamh, ctrl, WINBINDD_PAM_AUTH, &request, &response, user);
414 if (pwd_last_set) {
415 *pwd_last_set = response.data.auth.info3.pass_last_set_time;
418 if ((ctrl & WINBIND_KRB5_AUTH) &&
419 response.data.auth.krb5ccname[0] != '\0') {
421 char var[PATH_MAX];
423 _pam_log_debug(ctrl, LOG_DEBUG, "request returned KRB5CCNAME: %s",
424 response.data.auth.krb5ccname);
426 snprintf(var, sizeof(var), "KRB5CCNAME=%s", response.data.auth.krb5ccname);
428 ret = pam_putenv(pamh, var);
429 if (ret != PAM_SUCCESS) {
430 _pam_log(LOG_ERR, "failed to set KRB5CCNAME to %s", var);
431 return ret;
435 if (!process_result) {
436 return ret;
439 if (ret) {
440 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_PASSWORD_EXPIRED");
441 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_PASSWORD_MUST_CHANGE");
442 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_INVALID_WORKSTATION");
443 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_INVALID_LOGON_HOURS");
444 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_ACCOUNT_EXPIRED");
445 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_ACCOUNT_DISABLED");
446 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_ACCOUNT_LOCKED_OUT");
447 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT");
448 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_NOLOGON_SERVER_TRUST_ACCOUNT");
449 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_NOLOGON_INTERDOMAIN_TRUST_ACCOUNT");
452 /* handle the case where the auth was ok, but the password must expire right now */
453 /* good catch from Ralf Haferkamp: an expiry of "never" is translated to -1 */
454 if ( ! (response.data.auth.info3.acct_flags & ACB_PWNOEXP) &&
455 (response.data.auth.policy.expire > 0) &&
456 (response.data.auth.info3.pass_last_set_time + response.data.auth.policy.expire < time(NULL))) {
458 ret = PAM_AUTHTOK_EXPIRED;
460 _pam_log_debug(ctrl, LOG_DEBUG,"Password has expired (Password was last set: %d, "
461 "the policy says it should expire here %d (now it's: %d)\n",
462 response.data.auth.info3.pass_last_set_time,
463 response.data.auth.info3.pass_last_set_time + response.data.auth.policy.expire,
464 time(NULL));
466 PAM_WB_REMARK_DIRECT_RET(pamh, "NT_STATUS_PASSWORD_EXPIRED");
470 /* warn a user if the password is about to expire soon */
471 if ( ! (response.data.auth.info3.acct_flags & ACB_PWNOEXP) &&
472 (response.data.auth.policy.expire) &&
473 (response.data.auth.info3.pass_last_set_time + response.data.auth.policy.expire > time(NULL) ) ) {
475 int days = response.data.auth.policy.expire / SECONDS_PER_DAY;
476 if (days <= DAYS_TO_WARN_BEFORE_PWD_EXPIRES) {
477 _make_remark_format(pamh, PAM_TEXT_INFO, "Your password will expire in %d days", days);
481 if (response.data.auth.info3.user_flgs & LOGON_CACHED_ACCOUNT) {
482 _make_remark(pamh, PAM_ERROR_MSG, "Logging on using cached account. Network ressources can be unavailable");
483 _pam_log_debug(ctrl, LOG_DEBUG,"User %s logged on using cached account\n", user);
486 /* save the CIFS homedir for pam_cifs / pam_mount */
487 if (response.data.auth.info3.home_dir[0] != '\0') {
489 int ret2 = pam_set_data(pamh, PAM_WINBIND_HOMEDIR,
490 (void *) strdup(response.data.auth.info3.home_dir),
491 _pam_winbind_cleanup_func);
492 if (ret2) {
493 _pam_log_debug(ctrl, LOG_DEBUG, "Could not set data: %s",
494 pam_strerror(pamh, ret2));
499 /* save the logon script path for other PAM modules */
500 if (response.data.auth.info3.logon_script[0] != '\0') {
502 int ret2 = pam_set_data(pamh, PAM_WINBIND_LOGONSCRIPT,
503 (void *) strdup(response.data.auth.info3.logon_script),
504 _pam_winbind_cleanup_func);
505 if (ret2) {
506 _pam_log_debug(ctrl, LOG_DEBUG, "Could not set data: %s",
507 pam_strerror(pamh, ret2));
511 return ret;
514 /* talk to winbindd */
515 static int winbind_chauthtok_request(pam_handle_t * pamh,
516 int ctrl,
517 const char *user,
518 const char *oldpass,
519 const char *newpass,
520 time_t pwd_last_set)
522 struct winbindd_request request;
523 struct winbindd_response response;
524 int ret;
526 ZERO_STRUCT(request);
527 ZERO_STRUCT(response);
529 if (request.data.chauthtok.user == NULL) return -2;
531 strncpy(request.data.chauthtok.user, user,
532 sizeof(request.data.chauthtok.user) - 1);
534 if (oldpass != NULL) {
535 strncpy(request.data.chauthtok.oldpass, oldpass,
536 sizeof(request.data.chauthtok.oldpass) - 1);
537 } else {
538 request.data.chauthtok.oldpass[0] = '\0';
541 if (newpass != NULL) {
542 strncpy(request.data.chauthtok.newpass, newpass,
543 sizeof(request.data.chauthtok.newpass) - 1);
544 } else {
545 request.data.chauthtok.newpass[0] = '\0';
548 if (ctrl & WINBIND_KRB5_AUTH) {
549 request.flags = WBFLAG_PAM_KRB5 | WBFLAG_PAM_CONTACT_TRUSTDOM;
552 ret = pam_winbind_request_log(pamh, ctrl, WINBINDD_PAM_CHAUTHTOK, &request, &response, user);
554 if (ret == PAM_SUCCESS) {
555 return ret;
558 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_BACKUP_CONTROLLER");
559 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_ACCESS_DENIED");
561 /* TODO: tell the min pwd length ? */
562 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_PWD_TOO_SHORT");
564 /* TODO: tell the minage ? */
565 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_PWD_TOO_RECENT");
567 /* TODO: tell the history length ? */
568 PAM_WB_REMARK_CHECK_RESPONSE_RET(pamh, response, "NT_STATUS_PWD_HISTORY_CONFLICT");
570 if (!strcasecmp(response.data.auth.nt_status_string, "NT_STATUS_PASSWORD_RESTRICTION")) {
572 /* FIXME: avoid to send multiple PAM messages after another */
573 switch (response.data.auth.reject_reason) {
574 case -1:
575 break;
576 case REJECT_REASON_OTHER:
577 if ((response.data.auth.policy.min_passwordage > 0) &&
578 (pwd_last_set + response.data.auth.policy.min_passwordage > time(NULL))) {
579 PAM_WB_REMARK_DIRECT(pamh, "NT_STATUS_PWD_TOO_RECENT");
581 break;
582 case REJECT_REASON_TOO_SHORT:
583 PAM_WB_REMARK_DIRECT(pamh, "NT_STATUS_PWD_TOO_SHORT");
584 break;
585 case REJECT_REASON_IN_HISTORY:
586 PAM_WB_REMARK_DIRECT(pamh, "NT_STATUS_PWD_HISTORY_CONFLICT");
587 break;
588 case REJECT_REASON_NOT_COMPLEX:
589 _make_remark(pamh, PAM_ERROR_MSG, "Password does not meet complexity requirements");
590 break;
591 default:
592 _pam_log_debug(ctrl, LOG_DEBUG,
593 "unknown password change reject reason: %d",
594 response.data.auth.reject_reason);
595 break;
598 _make_remark_format(pamh, PAM_ERROR_MSG,
599 "Your password must be at least %d characters; "
600 "cannot repeat any of the your previous %d passwords"
601 "%s. "
602 "Please type a different password. "
603 "Type a password which meets these requirements in both text boxes.",
604 response.data.auth.policy.min_length_password,
605 response.data.auth.policy.password_history,
606 (response.data.auth.policy.password_properties & DOMAIN_PASSWORD_COMPLEX) ?
607 "; must contain capitals, numerals or punctuation; and cannot contain your account or full name" :
608 "");
612 return ret;
616 * Checks if a user has an account
618 * return values:
619 * 1 = User not found
620 * 0 = OK
621 * -1 = System error
623 static int valid_user(const char *user, pam_handle_t *pamh, int ctrl)
625 /* check not only if the user is available over NSS calls, also make
626 * sure it's really a winbind user, this is important when stacking PAM
627 * modules in the 'account' or 'password' facility. */
629 struct passwd *pwd = NULL;
630 struct winbindd_request request;
631 struct winbindd_response response;
632 int ret;
634 ZERO_STRUCT(request);
635 ZERO_STRUCT(response);
637 pwd = getpwnam(user);
638 if (pwd == NULL) {
639 return 1;
642 strncpy(request.data.username, user,
643 sizeof(request.data.username) - 1);
645 ret = pam_winbind_request_log(pamh, ctrl, WINBINDD_GETPWNAM, &request, &response, user);
647 switch (ret) {
648 case PAM_USER_UNKNOWN:
649 return 1;
650 case PAM_SUCCESS:
651 return 0;
652 default:
653 break;
655 return -1;
658 static char *_pam_delete(register char *xx)
660 _pam_overwrite(xx);
661 _pam_drop(xx);
662 return NULL;
666 * obtain a password from the user
669 static int _winbind_read_password(pam_handle_t * pamh,
670 unsigned int ctrl,
671 const char *comment,
672 const char *prompt1,
673 const char *prompt2,
674 const char **pass)
676 int authtok_flag;
677 int retval;
678 const char *item;
679 char *token;
682 * make sure nothing inappropriate gets returned
685 *pass = token = NULL;
688 * which authentication token are we getting?
691 authtok_flag = on(WINBIND__OLD_PASSWORD, ctrl) ? PAM_OLDAUTHTOK : PAM_AUTHTOK;
694 * should we obtain the password from a PAM item ?
697 if (on(WINBIND_TRY_FIRST_PASS_ARG, ctrl) || on(WINBIND_USE_FIRST_PASS_ARG, ctrl)) {
698 retval = pam_get_item(pamh, authtok_flag, (const void **) &item);
699 if (retval != PAM_SUCCESS) {
700 /* very strange. */
701 _pam_log(LOG_ALERT,
702 "pam_get_item returned error to unix-read-password"
704 return retval;
705 } else if (item != NULL) { /* we have a password! */
706 *pass = item;
707 item = NULL;
708 return PAM_SUCCESS;
709 } else if (on(WINBIND_USE_FIRST_PASS_ARG, ctrl)) {
710 return PAM_AUTHTOK_RECOVER_ERR; /* didn't work */
711 } else if (on(WINBIND_USE_AUTHTOK_ARG, ctrl)
712 && off(WINBIND__OLD_PASSWORD, ctrl)) {
713 return PAM_AUTHTOK_RECOVER_ERR;
717 * getting here implies we will have to get the password from the
718 * user directly.
722 struct pam_message msg[3], *pmsg[3];
723 struct pam_response *resp;
724 int i, replies;
726 /* prepare to converse */
728 if (comment != NULL) {
729 pmsg[0] = &msg[0];
730 msg[0].msg_style = PAM_TEXT_INFO;
731 msg[0].msg = CONST_DISCARD(char *, comment);
732 i = 1;
733 } else {
734 i = 0;
737 pmsg[i] = &msg[i];
738 msg[i].msg_style = PAM_PROMPT_ECHO_OFF;
739 msg[i++].msg = CONST_DISCARD(char *, prompt1);
740 replies = 1;
742 if (prompt2 != NULL) {
743 pmsg[i] = &msg[i];
744 msg[i].msg_style = PAM_PROMPT_ECHO_OFF;
745 msg[i++].msg = CONST_DISCARD(char *, prompt2);
746 ++replies;
748 /* so call the conversation expecting i responses */
749 resp = NULL;
750 retval = converse(pamh, i, pmsg, &resp);
752 if (resp != NULL) {
754 /* interpret the response */
756 if (retval == PAM_SUCCESS) { /* a good conversation */
758 token = x_strdup(resp[i - replies].resp);
759 if (token != NULL) {
760 if (replies == 2) {
761 /* verify that password entered correctly */
762 if (!resp[i - 1].resp
763 || strcmp(token, resp[i - 1].resp)) {
764 _pam_delete(token); /* mistyped */
765 retval = PAM_AUTHTOK_RECOVER_ERR;
766 _make_remark(pamh, PAM_ERROR_MSG, MISTYPED_PASS);
769 } else {
770 _pam_log(LOG_NOTICE, "could not recover authentication token");
771 retval = PAM_AUTHTOK_RECOVER_ERR;
776 * tidy up the conversation (resp_retcode) is ignored
777 * -- what is it for anyway? AGM
780 _pam_drop_reply(resp, i);
782 } else {
783 retval = (retval == PAM_SUCCESS)
784 ? PAM_AUTHTOK_RECOVER_ERR : retval;
788 if (retval != PAM_SUCCESS) {
789 _pam_log_debug(ctrl, LOG_DEBUG,
790 "unable to obtain a password");
791 return retval;
793 /* 'token' is the entered password */
795 /* we store this password as an item */
797 retval = pam_set_item(pamh, authtok_flag, token);
798 _pam_delete(token); /* clean it up */
799 if (retval != PAM_SUCCESS ||
800 (retval = pam_get_item(pamh, authtok_flag, (const void **) &item)) != PAM_SUCCESS) {
802 _pam_log(LOG_CRIT, "error manipulating password");
803 return retval;
807 *pass = item;
808 item = NULL; /* break link to password */
810 return PAM_SUCCESS;
813 const char *get_conf_item_string(int argc,
814 const char **argv,
815 int ctrl,
816 dictionary *d,
817 const char *item,
818 int flag)
820 int i = 0;
821 char *parm = NULL;
822 const char *parm_opt = NULL;
823 char *key = NULL;
825 if (!(ctrl & flag)) {
826 goto out;
829 /* let the pam opt take precedence over the pam_winbind.conf option */
831 if (d != NULL) {
833 if (!asprintf(&key, "global:%s", item)) {
834 goto out;
837 parm_opt = iniparser_getstr(d, key);
838 SAFE_FREE(key);
841 for ( i=0; i<argc; i++ ) {
843 if ((strncmp(argv[i], item, strlen(item)) == 0)) {
844 char *p;
846 parm = strdup(argv[i]);
848 if ( (p = strchr( parm, '=' )) == NULL) {
849 _pam_log(LOG_INFO, "no \"=\" delimiter for \"%s\" found\n", item);
850 goto out;
852 SAFE_FREE(parm);
853 _pam_log_debug(ctrl, LOG_INFO, "PAM config: %s '%s'\n", item, p+1);
854 return p + 1;
858 if (d != NULL) {
859 _pam_log_debug(ctrl, LOG_INFO, "CONFIG file: %s '%s'\n", item, parm_opt);
861 out:
862 SAFE_FREE(parm);
863 return parm_opt;
866 const char *get_krb5_cc_type_from_config(int argc, const char **argv, int ctrl, dictionary *d)
868 return get_conf_item_string(argc, argv, ctrl, d, "krb5_ccache_type", WINBIND_KRB5_CCACHE_TYPE);
871 const char *get_member_from_config(int argc, const char **argv, int ctrl, dictionary *d)
873 const char *ret = NULL;
874 ret = get_conf_item_string(argc, argv, ctrl, d, "require_membership_of", WINBIND_REQUIRED_MEMBERSHIP);
875 if (ret) {
876 return ret;
878 return get_conf_item_string(argc, argv, ctrl, d, "require-membership-of", WINBIND_REQUIRED_MEMBERSHIP);
881 PAM_EXTERN
882 int pam_sm_authenticate(pam_handle_t *pamh, int flags,
883 int argc, const char **argv)
885 const char *username;
886 const char *password;
887 const char *member = NULL;
888 const char *cctype = NULL;
889 int retval = PAM_AUTH_ERR;
890 dictionary *d;
892 /* parse arguments */
893 int ctrl = _pam_parse(argc, argv, &d);
894 if (ctrl == -1) {
895 retval = PAM_SYSTEM_ERR;
896 goto out;
899 _pam_log_debug(ctrl, LOG_DEBUG,"pam_winbind: pam_sm_authenticate (flags: 0x%04x)", flags);
901 /* Get the username */
902 retval = pam_get_user(pamh, &username, NULL);
903 if ((retval != PAM_SUCCESS) || (!username)) {
904 _pam_log_debug(ctrl, LOG_DEBUG, "can not get the username");
905 retval = PAM_SERVICE_ERR;
906 goto out;
909 retval = _winbind_read_password(pamh, ctrl, NULL,
910 "Password: ", NULL,
911 &password);
913 if (retval != PAM_SUCCESS) {
914 _pam_log(LOG_ERR, "Could not retrieve user's password");
915 retval = PAM_AUTHTOK_ERR;
916 goto out;
919 /* Let's not give too much away in the log file */
921 #ifdef DEBUG_PASSWORD
922 _pam_log_debug(ctrl, LOG_INFO, "Verify user `%s' with password `%s'",
923 username, password);
924 #else
925 _pam_log_debug(ctrl, LOG_INFO, "Verify user `%s'", username);
926 #endif
928 member = get_member_from_config(argc, argv, ctrl, d);
930 cctype = get_krb5_cc_type_from_config(argc, argv, ctrl, d);
932 /* Now use the username to look up password */
933 retval = winbind_auth_request(pamh, ctrl, username, password, member, cctype, True, NULL);
935 if (retval == PAM_NEW_AUTHTOK_REQD ||
936 retval == PAM_AUTHTOK_EXPIRED) {
938 char *buf;
940 if (!asprintf(&buf, "%d", retval)) {
941 retval = PAM_BUF_ERR;
942 goto out;
945 pam_set_data( pamh, PAM_WINBIND_NEW_AUTHTOK_REQD, (void *)buf, _pam_winbind_cleanup_func);
947 retval = PAM_SUCCESS;
948 goto out;
951 out:
952 if (d) {
953 iniparser_freedict(d);
955 return retval;
958 PAM_EXTERN
959 int pam_sm_setcred(pam_handle_t *pamh, int flags,
960 int argc, const char **argv)
962 /* parse arguments */
963 int ctrl = _pam_parse(argc, argv, NULL);
964 if (ctrl == -1) {
965 return PAM_SYSTEM_ERR;
968 _pam_log_debug(ctrl, LOG_DEBUG,"pam_winbind: pam_sm_setcred (flags: 0x%04x)", flags);
970 if (flags & PAM_DELETE_CRED) {
971 return pam_sm_close_session(pamh, flags, argc, argv);
974 return PAM_SUCCESS;
978 * Account management. We want to verify that the account exists
979 * before returning PAM_SUCCESS
981 PAM_EXTERN
982 int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags,
983 int argc, const char **argv)
985 const char *username;
986 int retval = PAM_USER_UNKNOWN;
987 void *tmp = NULL;
989 /* parse arguments */
990 int ctrl = _pam_parse(argc, argv, NULL);
991 if (ctrl == -1) {
992 return PAM_SYSTEM_ERR;
995 _pam_log_debug(ctrl, LOG_DEBUG,"pam_winbind: pam_sm_acct_mgmt (flags: 0x%04x)", flags);
998 /* Get the username */
999 retval = pam_get_user(pamh, &username, NULL);
1000 if ((retval != PAM_SUCCESS) || (!username)) {
1001 _pam_log_debug(ctrl, LOG_DEBUG,"can not get the username");
1002 return PAM_SERVICE_ERR;
1005 /* Verify the username */
1006 retval = valid_user(username, pamh, ctrl);
1007 switch (retval) {
1008 case -1:
1009 /* some sort of system error. The log was already printed */
1010 return PAM_SERVICE_ERR;
1011 case 1:
1012 /* the user does not exist */
1013 _pam_log_debug(ctrl, LOG_NOTICE, "user `%s' not found", username);
1014 if (ctrl & WINBIND_UNKNOWN_OK_ARG) {
1015 return PAM_IGNORE;
1017 return PAM_USER_UNKNOWN;
1018 case 0:
1019 pam_get_data( pamh, PAM_WINBIND_NEW_AUTHTOK_REQD, (const void **)&tmp);
1020 if (tmp != NULL) {
1021 retval = atoi(tmp);
1022 switch (retval) {
1023 case PAM_AUTHTOK_EXPIRED:
1024 /* fall through, since new token is required in this case */
1025 case PAM_NEW_AUTHTOK_REQD:
1026 _pam_log(LOG_WARNING, "pam_sm_acct_mgmt success but %s is set",
1027 PAM_WINBIND_NEW_AUTHTOK_REQD);
1028 _pam_log(LOG_NOTICE, "user '%s' needs new password", username);
1029 /* PAM_AUTHTOKEN_REQD does not exist, but is documented in the manpage */
1030 return PAM_NEW_AUTHTOK_REQD;
1031 default:
1032 _pam_log(LOG_WARNING, "pam_sm_acct_mgmt success");
1033 _pam_log(LOG_NOTICE, "user '%s' granted access", username);
1034 return PAM_SUCCESS;
1038 /* Otherwise, the authentication looked good */
1039 _pam_log(LOG_NOTICE, "user '%s' granted access", username);
1040 return PAM_SUCCESS;
1041 default:
1042 /* we don't know anything about this return value */
1043 _pam_log(LOG_ERR, "internal module error (retval = %d, user = `%s')",
1044 retval, username);
1045 return PAM_SERVICE_ERR;
1048 /* should not be reached */
1049 return PAM_IGNORE;
1052 PAM_EXTERN
1053 int pam_sm_open_session(pam_handle_t *pamh, int flags,
1054 int argc, const char **argv)
1056 /* parse arguments */
1057 int ctrl = _pam_parse(argc, argv, NULL);
1058 if (ctrl == -1) {
1059 return PAM_SYSTEM_ERR;
1062 _pam_log_debug(ctrl, LOG_DEBUG,"pam_winbind: pam_sm_open_session handler (flags: 0x%04x)", flags);
1064 return PAM_SUCCESS;
1067 PAM_EXTERN
1068 int pam_sm_close_session(pam_handle_t *pamh, int flags,
1069 int argc, const char **argv)
1071 dictionary *d;
1072 int retval = PAM_SUCCESS;
1074 /* parse arguments */
1075 int ctrl = _pam_parse(argc, argv, &d);
1076 if (ctrl == -1) {
1077 retval = PAM_SYSTEM_ERR;
1078 goto out;
1081 _pam_log_debug(ctrl, LOG_DEBUG,"pam_winbind: pam_sm_close_session handler (flags: 0x%04x)", flags);
1083 if (!(flags & PAM_DELETE_CRED)) {
1084 retval = PAM_SUCCESS;
1085 goto out;
1088 if (ctrl & WINBIND_KRB5_AUTH) {
1090 /* destroy the ccache here */
1091 struct winbindd_request request;
1092 struct winbindd_response response;
1093 const char *user;
1094 const char *ccname = NULL;
1095 struct passwd *pwd = NULL;
1097 ZERO_STRUCT(request);
1098 ZERO_STRUCT(response);
1100 retval = pam_get_user(pamh, &user, "Username: ");
1101 if (retval == PAM_SUCCESS) {
1102 if (user == NULL) {
1103 _pam_log(LOG_ERR, "username was NULL!");
1104 retval = PAM_USER_UNKNOWN;
1105 goto out;
1107 if (retval == PAM_SUCCESS) {
1108 _pam_log_debug(ctrl, LOG_DEBUG, "username [%s] obtained", user);
1110 } else {
1111 _pam_log_debug(ctrl, LOG_DEBUG, "could not identify user");
1112 goto out;
1115 ccname = pam_getenv(pamh, "KRB5CCNAME");
1116 if (ccname == NULL) {
1117 _pam_log_debug(ctrl, LOG_DEBUG, "user has no KRB5CCNAME environment");
1118 retval = PAM_SUCCESS;
1119 goto out;
1122 strncpy(request.data.logoff.user, user,
1123 sizeof(request.data.logoff.user) - 1);
1125 strncpy(request.data.logoff.krb5ccname, ccname,
1126 sizeof(request.data.logoff.krb5ccname) - 1);
1128 pwd = getpwnam(user);
1129 if (pwd == NULL) {
1130 retval = PAM_USER_UNKNOWN;
1131 goto out;
1133 request.data.logoff.uid = pwd->pw_uid;
1135 request.flags = WBFLAG_PAM_KRB5 | WBFLAG_PAM_CONTACT_TRUSTDOM;
1137 retval = pam_winbind_request_log(pamh, ctrl, WINBINDD_PAM_LOGOFF, &request, &response, user);
1140 out:
1141 if (d) {
1142 iniparser_freedict(d);
1144 return retval;
1149 PAM_EXTERN
1150 int pam_sm_chauthtok(pam_handle_t * pamh, int flags,
1151 int argc, const char **argv)
1153 unsigned int lctrl;
1154 int retval;
1155 unsigned int ctrl;
1157 /* <DO NOT free() THESE> */
1158 const char *user;
1159 char *pass_old, *pass_new;
1160 /* </DO NOT free() THESE> */
1162 char *Announce;
1164 int retry = 0;
1165 dictionary *d;
1167 ctrl = _pam_parse(argc, argv, &d);
1168 if (ctrl == -1) {
1169 retval = PAM_SYSTEM_ERR;
1170 goto out;
1173 _pam_log_debug(ctrl, LOG_DEBUG,"pam_winbind: pam_sm_chauthtok (flags: 0x%04x)", flags);
1175 /* clearing offline bit for the auth in the password change */
1176 ctrl &= ~WINBIND_CACHED_LOGIN;
1179 * First get the name of a user
1181 retval = pam_get_user(pamh, &user, "Username: ");
1182 if (retval == PAM_SUCCESS) {
1183 if (user == NULL) {
1184 _pam_log(LOG_ERR, "username was NULL!");
1185 retval = PAM_USER_UNKNOWN;
1186 goto out;
1188 if (retval == PAM_SUCCESS) {
1189 _pam_log_debug(ctrl, LOG_DEBUG, "username [%s] obtained",
1190 user);
1192 } else {
1193 _pam_log_debug(ctrl, LOG_DEBUG,
1194 "password - could not identify user");
1195 goto out;
1198 /* check if this is really a user in winbindd, not only in NSS */
1199 retval = valid_user(user, pamh, ctrl);
1200 switch (retval) {
1201 case 1:
1202 retval = PAM_USER_UNKNOWN;
1203 goto out;
1204 case -1:
1205 retval = PAM_SYSTEM_ERR;
1206 goto out;
1207 default:
1208 break;
1212 * obtain and verify the current password (OLDAUTHTOK) for
1213 * the user.
1216 if (flags & PAM_PRELIM_CHECK) {
1218 time_t pwdlastset_prelim = 0;
1220 /* instruct user what is happening */
1221 #define greeting "Changing password for "
1222 Announce = (char *) malloc(sizeof(greeting) + strlen(user));
1223 if (Announce == NULL) {
1224 _pam_log(LOG_CRIT, "password - out of memory");
1225 retval = PAM_BUF_ERR;
1226 goto out;
1228 (void) strcpy(Announce, greeting);
1229 (void) strcpy(Announce + sizeof(greeting) - 1, user);
1230 #undef greeting
1232 lctrl = ctrl | WINBIND__OLD_PASSWORD;
1233 retval = _winbind_read_password(pamh, lctrl,
1234 Announce,
1235 "(current) NT password: ",
1236 NULL,
1237 (const char **) &pass_old);
1238 if (retval != PAM_SUCCESS) {
1239 _pam_log(LOG_NOTICE, "password - (old) token not obtained");
1240 goto out;
1242 /* verify that this is the password for this user */
1244 retval = winbind_auth_request(pamh, ctrl, user, pass_old, NULL, NULL, False, &pwdlastset_prelim);
1246 if (retval != PAM_ACCT_EXPIRED &&
1247 retval != PAM_AUTHTOK_EXPIRED &&
1248 retval != PAM_NEW_AUTHTOK_REQD &&
1249 retval != PAM_SUCCESS) {
1250 pass_old = NULL;
1251 goto out;
1254 pam_set_data(pamh, PAM_WINBIND_PWD_LAST_SET, (void *)pwdlastset_prelim, _pam_winbind_cleanup_func);
1256 retval = pam_set_item(pamh, PAM_OLDAUTHTOK, (const void *) pass_old);
1257 pass_old = NULL;
1258 if (retval != PAM_SUCCESS) {
1259 _pam_log(LOG_CRIT, "failed to set PAM_OLDAUTHTOK");
1261 } else if (flags & PAM_UPDATE_AUTHTOK) {
1263 time_t pwdlastset_update = 0;
1266 * obtain the proposed password
1270 * get the old token back.
1273 retval = pam_get_item(pamh, PAM_OLDAUTHTOK,
1274 (const void **) &pass_old);
1276 if (retval != PAM_SUCCESS) {
1277 _pam_log(LOG_NOTICE, "user not authenticated");
1278 goto out;
1281 lctrl = ctrl;
1283 if (on(WINBIND_USE_AUTHTOK_ARG, lctrl)) {
1284 lctrl |= WINBIND_USE_FIRST_PASS_ARG;
1286 retry = 0;
1287 retval = PAM_AUTHTOK_ERR;
1288 while ((retval != PAM_SUCCESS) && (retry++ < MAX_PASSWD_TRIES)) {
1290 * use_authtok is to force the use of a previously entered
1291 * password -- needed for pluggable password strength checking
1294 retval = _winbind_read_password(pamh, lctrl,
1295 NULL,
1296 "Enter new NT password: ",
1297 "Retype new NT password: ",
1298 (const char **) &pass_new);
1300 if (retval != PAM_SUCCESS) {
1301 _pam_log_debug(ctrl, LOG_ALERT
1302 ,"password - new password not obtained");
1303 pass_old = NULL;/* tidy up */
1304 goto out;
1308 * At this point we know who the user is and what they
1309 * propose as their new password. Verify that the new
1310 * password is acceptable.
1313 if (pass_new[0] == '\0') {/* "\0" password = NULL */
1314 pass_new = NULL;
1319 * By reaching here we have approved the passwords and must now
1320 * rebuild the password database file.
1322 pam_get_data( pamh, PAM_WINBIND_PWD_LAST_SET, (const void **)&pwdlastset_update);
1324 retval = winbind_chauthtok_request(pamh, ctrl, user, pass_old, pass_new, pwdlastset_update);
1325 if (retval) {
1326 _pam_overwrite(pass_new);
1327 _pam_overwrite(pass_old);
1328 pass_old = pass_new = NULL;
1329 goto out;
1332 /* just in case we need krb5 creds after a password change over msrpc */
1334 if (ctrl & WINBIND_KRB5_AUTH) {
1336 const char *member = get_member_from_config(argc, argv, ctrl, d);
1337 const char *cctype = get_krb5_cc_type_from_config(argc, argv, ctrl, d);
1339 retval = winbind_auth_request(pamh, ctrl, user, pass_new, member, cctype, False, NULL);
1340 _pam_overwrite(pass_new);
1341 _pam_overwrite(pass_old);
1342 pass_old = pass_new = NULL;
1344 } else {
1345 retval = PAM_SERVICE_ERR;
1348 out:
1349 if (d) {
1350 iniparser_freedict(d);
1352 return retval;
1355 #ifdef PAM_STATIC
1357 /* static module data */
1359 struct pam_module _pam_winbind_modstruct = {
1360 MODULE_NAME,
1361 pam_sm_authenticate,
1362 pam_sm_setcred,
1363 pam_sm_acct_mgmt,
1364 pam_sm_open_session,
1365 pam_sm_close_session,
1366 pam_sm_chauthtok
1369 #endif
1372 * Copyright (c) Andrew Tridgell <tridge@samba.org> 2000
1373 * Copyright (c) Tim Potter <tpot@samba.org> 2000
1374 * Copyright (c) Andrew Bartlettt <abartlet@samba.org> 2002
1375 * Copyright (c) Guenther Deschner <gd@samba.org> 2005-2006
1376 * Copyright (c) Jan Rêkorajski 1999.
1377 * Copyright (c) Andrew G. Morgan 1996-8.
1378 * Copyright (c) Alex O. Yuriev, 1996.
1379 * Copyright (c) Cristian Gafton 1996.
1380 * Copyright (C) Elliot Lee <sopwith@redhat.com> 1996, Red Hat Software.
1382 * Redistribution and use in source and binary forms, with or without
1383 * modification, are permitted provided that the following conditions
1384 * are met:
1385 * 1. Redistributions of source code must retain the above copyright
1386 * notice, and the entire permission notice in its entirety,
1387 * including the disclaimer of warranties.
1388 * 2. Redistributions in binary form must reproduce the above copyright
1389 * notice, this list of conditions and the following disclaimer in the
1390 * documentation and/or other materials provided with the distribution.
1391 * 3. The name of the author may not be used to endorse or promote
1392 * products derived from this software without specific prior
1393 * written permission.
1395 * ALTERNATIVELY, this product may be distributed under the terms of
1396 * the GNU Public License, in which case the provisions of the GPL are
1397 * required INSTEAD OF the above restrictions. (This clause is
1398 * necessary due to a potential bad interaction between the GPL and
1399 * the restrictions contained in a BSD-style copyright.)
1401 * THIS SOFTWARE IS PROVIDED `AS IS'' AND ANY EXPRESS OR IMPLIED
1402 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1403 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
1404 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
1405 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
1406 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1407 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
1408 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
1409 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
1410 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
1411 * OF THE POSSIBILITY OF SUCH DAMAGE.