This commit was manufactured by cvs2svn to create branch 'SAMBA_3_0'.(This used to...
[vlendec/samba-autobuild/.git] / source3 / nsswitch / pam_winbind.c
1 /* pam_winbind module
2
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
7    largely based on pam_userdb by Christian Gafton <gafton@redhat.com> 
8    also contains large slabs of code from pam_unix by Elliot Lee <sopwith@redhat.com>
9    (see copyright below for full details)
10 */
11
12 #include "pam_winbind.h"
13
14 /* data tokens */
15
16 #define MAX_PASSWD_TRIES        3
17
18 /* some syslogging */
19 static void _pam_log(int err, const char *format, ...)
20 {
21         va_list args;
22
23         va_start(args, format);
24         openlog(MODULE_NAME, LOG_CONS|LOG_PID, LOG_AUTH);
25         vsyslog(err, format, args);
26         va_end(args);
27         closelog();
28 }
29
30 static int _pam_parse(int argc, const char **argv)
31 {
32         int ctrl;
33         /* step through arguments */
34         for (ctrl = 0; argc-- > 0; ++argv) {
35
36                 /* generic options */
37                 
38                 if (!strcmp(*argv,"debug"))
39                         ctrl |= WINBIND_DEBUG_ARG;
40                 else if (!strcasecmp(*argv, "use_authtok"))
41                         ctrl |= WINBIND_USE_AUTHTOK_ARG;
42                 else if (!strcasecmp(*argv, "use_first_pass"))
43                         ctrl |= WINBIND_USE_FIRST_PASS_ARG;
44                 else if (!strcasecmp(*argv, "try_first_pass"))
45                         ctrl |= WINBIND_TRY_FIRST_PASS_ARG;
46                 else if (!strcasecmp(*argv, "unknown_ok"))
47                         ctrl |= WINBIND_UNKNOWN_OK_ARG;
48                 else {
49                         _pam_log(LOG_ERR, "pam_parse: unknown option; %s", *argv);
50                 }
51         }
52         
53         return ctrl;
54 }
55
56 /* --- authentication management functions --- */
57
58 /* Attempt a conversation */
59
60 static int converse(pam_handle_t *pamh, int nargs,
61                     struct pam_message **message,
62                     struct pam_response **response)
63 {
64     int retval;
65     struct pam_conv *conv;
66
67     retval = pam_get_item(pamh, PAM_CONV, (const void **) &conv ) ;
68     if (retval == PAM_SUCCESS) {
69         retval = conv->conv(nargs, (const struct pam_message **)message,
70                             response, conv->appdata_ptr);
71     }
72         
73     return retval; /* propagate error status */
74 }
75
76
77 static int _make_remark(pam_handle_t * pamh, int type, const char *text)
78 {
79         int retval = PAM_SUCCESS;
80
81         struct pam_message *pmsg[1], msg[1];
82         struct pam_response *resp;
83         
84         pmsg[0] = &msg[0];
85         msg[0].msg = text;
86         msg[0].msg_style = type;
87         
88         resp = NULL;
89         retval = converse(pamh, 1, pmsg, &resp);
90         
91         if (resp) {
92                 _pam_drop_reply(resp, 1);
93         }
94         return retval;
95 }
96
97 static int pam_winbind_request(enum winbindd_cmd req_type,
98                                struct winbindd_request *request,
99                                struct winbindd_response *response)
100 {
101
102         /* Fill in request and send down pipe */
103         init_request(request, req_type);
104         
105         if (write_sock(request, sizeof(*request)) == -1) {
106                 _pam_log(LOG_ERR, "write to socket failed!");
107                 close_sock();
108                 return PAM_SERVICE_ERR;
109         }
110         
111         /* Wait for reply */
112         if (read_reply(response) == -1) {
113                 _pam_log(LOG_ERR, "read from socket failed!");
114                 close_sock();
115                 return PAM_SERVICE_ERR;
116         }
117
118         /* We are done with the socket - close it and avoid mischeif */
119         close_sock();
120
121         /* Copy reply data from socket */
122         if (response->result != WINBINDD_OK) {
123                 if (response->data.auth.pam_error != PAM_SUCCESS) {
124                         _pam_log(LOG_ERR, "request failed, PAM error was %d, NT error was %s", 
125                                  response->data.auth.pam_error,
126                                  response->data.auth.nt_status_string);
127                         return response->data.auth.pam_error;
128                 } else {
129                         _pam_log(LOG_ERR, "request failed, but PAM error 0!");
130                         return PAM_SERVICE_ERR;
131                 }
132         }
133         
134         return PAM_SUCCESS;
135 }
136
137 static int pam_winbind_request_log(enum winbindd_cmd req_type,
138                                struct winbindd_request *request,
139                                struct winbindd_response *response,
140                                    int ctrl,
141                                    const char *user)
142 {
143         int retval;
144
145         retval = pam_winbind_request(req_type, request, response);
146
147         switch (retval) {
148         case PAM_AUTH_ERR:
149                 /* incorrect password */
150                 _pam_log(LOG_WARNING, "user `%s' denied access (incorrect password)", user);
151                 return retval;
152         case PAM_ACCT_EXPIRED:
153                 /* account expired */
154                 _pam_log(LOG_WARNING, "user `%s' account expired", user);
155                 return retval;
156         case PAM_AUTHTOK_EXPIRED:
157                 /* password expired */
158                 _pam_log(LOG_WARNING, "user `%s' password expired", user);
159                 return retval;
160         case PAM_NEW_AUTHTOK_REQD:
161                 /* password expired */
162                 _pam_log(LOG_WARNING, "user `%s' new password required", user);
163                 return retval;
164         case PAM_USER_UNKNOWN:
165                 /* the user does not exist */
166                 if (ctrl & WINBIND_DEBUG_ARG)
167                         _pam_log(LOG_NOTICE, "user `%s' not found",
168                                  user);
169                 if (ctrl & WINBIND_UNKNOWN_OK_ARG) {
170                         return PAM_IGNORE;
171                 }        
172                 return retval;
173         case PAM_SUCCESS:
174                 if (req_type == WINBINDD_PAM_AUTH) {
175                         /* Otherwise, the authentication looked good */
176                         _pam_log(LOG_NOTICE, "user '%s' granted acces", user);
177                 } else if (req_type == WINBINDD_PAM_CHAUTHTOK) {
178                         /* Otherwise, the authentication looked good */
179                         _pam_log(LOG_NOTICE, "user '%s' password changed", user);
180                 } else { 
181                         /* Otherwise, the authentication looked good */
182                         _pam_log(LOG_NOTICE, "user '%s' OK", user);
183                 }
184                 return retval;
185         default:
186                 /* we don't know anything about this return value */
187                 _pam_log(LOG_ERR, "internal module error (retval = %d, user = `%s'",
188                          retval, user);
189                 return retval;
190         }
191 }
192
193 /* talk to winbindd */
194 static int winbind_auth_request(const char *user, const char *pass, int ctrl)
195 {
196         struct winbindd_request request;
197         struct winbindd_response response;
198
199         ZERO_STRUCT(request);
200
201         strncpy(request.data.auth.user, user, 
202                 sizeof(request.data.auth.user)-1);
203
204         strncpy(request.data.auth.pass, pass, 
205                 sizeof(request.data.auth.pass)-1);
206         
207         
208         return pam_winbind_request_log(WINBINDD_PAM_AUTH, &request, &response, ctrl, user);
209 }
210
211 /* talk to winbindd */
212 static int winbind_chauthtok_request(const char *user, const char *oldpass,
213                                      const char *newpass, int ctrl)
214 {
215         struct winbindd_request request;
216         struct winbindd_response response;
217
218         ZERO_STRUCT(request);
219
220         if (request.data.chauthtok.user == NULL) return -2;
221
222         strncpy(request.data.chauthtok.user, user, 
223                 sizeof(request.data.chauthtok.user) - 1);
224
225         if (oldpass != NULL) {
226             strncpy(request.data.chauthtok.oldpass, oldpass, 
227                     sizeof(request.data.chauthtok.oldpass) - 1);
228         } else {
229             request.data.chauthtok.oldpass[0] = '\0';
230         }
231         
232         if (newpass != NULL) {
233             strncpy(request.data.chauthtok.newpass, newpass, 
234                     sizeof(request.data.chauthtok.newpass) - 1);
235         } else {
236             request.data.chauthtok.newpass[0] = '\0';
237         }
238         
239         return pam_winbind_request_log(WINBINDD_PAM_CHAUTHTOK, &request, &response, ctrl, user);
240 }
241
242 /*
243  * Checks if a user has an account
244  *
245  * return values:
246  *       1  = User not found
247  *       0  = OK
248  *      -1  = System error
249  */
250 static int valid_user(const char *user)
251 {
252         if (getpwnam(user)) return 0;
253         return 1;
254 }
255
256 static char *_pam_delete(register char *xx)
257 {
258     _pam_overwrite(xx);
259     _pam_drop(xx);
260     return NULL;
261 }
262
263 /*
264  * obtain a password from the user
265  */
266
267 static int _winbind_read_password(pam_handle_t * pamh
268                                   ,unsigned int ctrl
269                                   ,const char *comment
270                                   ,const char *prompt1
271                                   ,const char *prompt2
272                                   ,const char **pass)
273 {
274         int authtok_flag;
275         int retval;
276         const char *item;
277         char *token;
278
279         /*
280          * make sure nothing inappropriate gets returned
281          */
282
283         *pass = token = NULL;
284
285         /*
286          * which authentication token are we getting?
287          */
288
289         authtok_flag = on(WINBIND__OLD_PASSWORD, ctrl) ? PAM_OLDAUTHTOK : PAM_AUTHTOK;
290
291         /*
292          * should we obtain the password from a PAM item ?
293          */
294
295         if (on(WINBIND_TRY_FIRST_PASS_ARG, ctrl) || on(WINBIND_USE_FIRST_PASS_ARG, ctrl)) {
296                 retval = pam_get_item(pamh, authtok_flag, (const void **) &item);
297                 if (retval != PAM_SUCCESS) {
298                         /* very strange. */
299                         _pam_log(LOG_ALERT, 
300                                  "pam_get_item returned error to unix-read-password"
301                             );
302                         return retval;
303                 } else if (item != NULL) {      /* we have a password! */
304                         *pass = item;
305                         item = NULL;
306                         return PAM_SUCCESS;
307                 } else if (on(WINBIND_USE_FIRST_PASS_ARG, ctrl)) {
308                         return PAM_AUTHTOK_RECOVER_ERR;         /* didn't work */
309                 } else if (on(WINBIND_USE_AUTHTOK_ARG, ctrl)
310                            && off(WINBIND__OLD_PASSWORD, ctrl)) {
311                         return PAM_AUTHTOK_RECOVER_ERR;
312                 }
313         }
314         /*
315          * getting here implies we will have to get the password from the
316          * user directly.
317          */
318
319         {
320                 struct pam_message msg[3], *pmsg[3];
321                 struct pam_response *resp;
322                 int i, replies;
323
324                 /* prepare to converse */
325
326                 if (comment != NULL) {
327                         pmsg[0] = &msg[0];
328                         msg[0].msg_style = PAM_TEXT_INFO;
329                         msg[0].msg = comment;
330                         i = 1;
331                 } else {
332                         i = 0;
333                 }
334
335                 pmsg[i] = &msg[i];
336                 msg[i].msg_style = PAM_PROMPT_ECHO_OFF;
337                 msg[i++].msg = prompt1;
338                 replies = 1;
339
340                 if (prompt2 != NULL) {
341                         pmsg[i] = &msg[i];
342                         msg[i].msg_style = PAM_PROMPT_ECHO_OFF;
343                         msg[i++].msg = prompt2;
344                         ++replies;
345                 }
346                 /* so call the conversation expecting i responses */
347                 resp = NULL;
348                 retval = converse(pamh, i, pmsg, &resp);
349
350                 if (resp != NULL) {
351
352                         /* interpret the response */
353
354                         if (retval == PAM_SUCCESS) {    /* a good conversation */
355
356                                 token = x_strdup(resp[i - replies].resp);
357                                 if (token != NULL) {
358                                         if (replies == 2) {
359
360                                                 /* verify that password entered correctly */
361                                                 if (!resp[i - 1].resp
362                                                     || strcmp(token, resp[i - 1].resp)) {
363                                                         _pam_delete(token);     /* mistyped */
364                                                         retval = PAM_AUTHTOK_RECOVER_ERR;
365                                                         _make_remark(pamh                                                                   ,PAM_ERROR_MSG, MISTYPED_PASS);
366                                                 }
367                                         }
368                                 } else {
369                                         _pam_log(LOG_NOTICE
370                                                  ,"could not recover authentication token");
371                                 }
372
373                         }
374                         /*
375                          * tidy up the conversation (resp_retcode) is ignored
376                          * -- what is it for anyway? AGM
377                          */
378
379                         _pam_drop_reply(resp, i);
380
381                 } else {
382                         retval = (retval == PAM_SUCCESS)
383                             ? PAM_AUTHTOK_RECOVER_ERR : retval;
384                 }
385         }
386
387         if (retval != PAM_SUCCESS) {
388                 if (on(WINBIND_DEBUG_ARG, ctrl))
389                         _pam_log(LOG_DEBUG,
390                                  "unable to obtain a password");
391                 return retval;
392         }
393         /* 'token' is the entered password */
394
395         /* we store this password as an item */
396         
397         retval = pam_set_item(pamh, authtok_flag, token);
398         _pam_delete(token);     /* clean it up */
399         if (retval != PAM_SUCCESS
400             || (retval = pam_get_item(pamh, authtok_flag
401                                       ,(const void **) &item))
402             != PAM_SUCCESS) {
403                 
404                 _pam_log(LOG_CRIT, "error manipulating password");
405                 return retval;
406                 
407         }
408
409         *pass = item;
410         item = NULL;            /* break link to password */
411
412         return PAM_SUCCESS;
413 }
414
415 PAM_EXTERN
416 int pam_sm_authenticate(pam_handle_t *pamh, int flags,
417                         int argc, const char **argv)
418 {
419      const char *username;
420      const char *password;
421      int retval = PAM_AUTH_ERR;
422     
423      /* parse arguments */
424      int ctrl = _pam_parse(argc, argv);
425
426      /* Get the username */
427      retval = pam_get_user(pamh, &username, NULL);
428      if ((retval != PAM_SUCCESS) || (!username)) {
429         if (ctrl & WINBIND_DEBUG_ARG)
430             _pam_log(LOG_DEBUG,"can not get the username");
431         return PAM_SERVICE_ERR;
432      }
433      
434      retval = _winbind_read_password(pamh, ctrl, NULL, 
435                                      "Password: ", NULL,
436                                      &password);
437      
438      if (retval != PAM_SUCCESS) {
439          _pam_log(LOG_ERR, "Could not retrieve user's password");
440          return PAM_AUTHTOK_ERR;
441      }
442      
443      if (ctrl & WINBIND_DEBUG_ARG) {
444
445              /* Let's not give too much away in the log file */
446
447 #ifdef DEBUG_PASSWORD
448          _pam_log(LOG_INFO, "Verify user `%s' with password `%s'",
449                   username, password);
450 #else
451          _pam_log(LOG_INFO, "Verify user `%s'", username);
452 #endif
453      }
454
455      /* Now use the username to look up password */
456      return winbind_auth_request(username, password, ctrl);
457 }
458
459 PAM_EXTERN
460 int pam_sm_setcred(pam_handle_t *pamh, int flags,
461                    int argc, const char **argv)
462 {
463     return PAM_SUCCESS;
464 }
465
466 /*
467  * Account management. We want to verify that the account exists 
468  * before returning PAM_SUCCESS
469  */
470 PAM_EXTERN
471 int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags,
472                    int argc, const char **argv)
473 {
474     const char *username;
475     int retval = PAM_USER_UNKNOWN;
476
477     /* parse arguments */
478     int ctrl = _pam_parse(argc, argv);
479
480     /* Get the username */
481     retval = pam_get_user(pamh, &username, NULL);
482     if ((retval != PAM_SUCCESS) || (!username)) {
483         if (ctrl & WINBIND_DEBUG_ARG)
484             _pam_log(LOG_DEBUG,"can not get the username");
485         return PAM_SERVICE_ERR;
486     }
487
488     /* Verify the username */
489     retval = valid_user(username);
490     switch (retval) {
491         case -1:
492             /* some sort of system error. The log was already printed */
493             return PAM_SERVICE_ERR;
494         case 1:
495             /* the user does not exist */
496             if (ctrl & WINBIND_DEBUG_ARG)
497                 _pam_log(LOG_NOTICE, "user `%s' not found",
498                          username);
499             if (ctrl & WINBIND_UNKNOWN_OK_ARG)
500                 return PAM_IGNORE;
501             return PAM_USER_UNKNOWN;
502         case 0:
503             /* Otherwise, the authentication looked good */
504             _pam_log(LOG_NOTICE, "user '%s' granted acces", username);
505             return PAM_SUCCESS;
506         default:
507             /* we don't know anything about this return value */
508             _pam_log(LOG_ERR, "internal module error (retval = %d, user = `%s'",
509                      retval, username);
510             return PAM_SERVICE_ERR;
511     }
512     
513     /* should not be reached */
514     return PAM_IGNORE;
515 }
516 PAM_EXTERN
517 int pam_sm_open_session(pam_handle_t *pamh, int flags,
518                 int argc, const char **argv)
519 {
520         /* parse arguments */
521         int ctrl = _pam_parse(argc, argv);
522         if (ctrl & WINBIND_DEBUG_ARG)
523               _pam_log(LOG_DEBUG,"libpam_winbind:pam_sm_open_session handler");
524         return PAM_SUCCESS;
525 }
526 PAM_EXTERN
527 int pam_sm_close_session(pam_handle_t *pamh, int flags,
528                 int argc, const char **argv)
529 {
530         /* parse arguments */
531         int ctrl = _pam_parse(argc, argv);
532         if (ctrl & WINBIND_DEBUG_ARG)
533               _pam_log(LOG_DEBUG,"libpam_winbind:pam_sm_close_session handler");
534         return PAM_SUCCESS;
535 }
536
537
538
539 PAM_EXTERN int pam_sm_chauthtok(pam_handle_t * pamh, int flags,
540                                 int argc, const char **argv)
541 {
542         unsigned int lctrl;
543         int retval;
544         unsigned int ctrl = _pam_parse(argc, argv);
545
546         /* <DO NOT free() THESE> */
547         const char *user;
548         char *pass_old, *pass_new;
549         /* </DO NOT free() THESE> */
550
551         char *Announce;
552         
553         int retry = 0;
554
555         /*
556          * First get the name of a user
557          */
558         retval = pam_get_user(pamh, &user, "Username: ");
559         if (retval == PAM_SUCCESS) {
560                 if (user == NULL) {
561                         _pam_log(LOG_ERR, "username was NULL!");
562                         return PAM_USER_UNKNOWN;
563                 }
564                 if (retval == PAM_SUCCESS && on(WINBIND_DEBUG_ARG, ctrl))
565                         _pam_log(LOG_DEBUG, "username [%s] obtained",
566                                  user);
567         } else {
568                 if (on(WINBIND_DEBUG_ARG, ctrl))
569                         _pam_log(LOG_DEBUG,
570                                  "password - could not identify user");
571                 return retval;
572         }
573
574         /*
575          * obtain and verify the current password (OLDAUTHTOK) for
576          * the user.
577          */
578
579         if (flags & PAM_PRELIM_CHECK) {
580                 
581                 /* instruct user what is happening */
582 #define greeting "Changing password for "
583                 Announce = (char *) malloc(sizeof(greeting) + strlen(user));
584                 if (Announce == NULL) {
585                 _pam_log(LOG_CRIT, 
586                          "password - out of memory");
587                 return PAM_BUF_ERR;
588                 }
589                 (void) strcpy(Announce, greeting);
590                 (void) strcpy(Announce + sizeof(greeting) - 1, user);
591 #undef greeting
592                 
593                 lctrl = ctrl | WINBIND__OLD_PASSWORD;
594                 retval = _winbind_read_password(pamh, lctrl
595                                                 ,Announce
596                                                 ,"(current) NT password: "
597                                                 ,NULL
598                                                 ,(const char **) &pass_old);
599                 free(Announce);
600                 
601                 if (retval != PAM_SUCCESS) {
602                         _pam_log(LOG_NOTICE
603                                  ,"password - (old) token not obtained");
604                         return retval;
605                 }
606                 /* verify that this is the password for this user */
607                 
608                 retval = winbind_auth_request(user, pass_old, ctrl);
609                 
610                 if (retval != PAM_ACCT_EXPIRED 
611                     && retval != PAM_AUTHTOK_EXPIRED
612                     && retval != PAM_NEW_AUTHTOK_REQD 
613                     && retval != PAM_SUCCESS) {
614                         pass_old = NULL;
615                         return retval;
616                 }
617                 
618                 retval = pam_set_item(pamh, PAM_OLDAUTHTOK, (const void *) pass_old);
619                 pass_old = NULL;
620                 if (retval != PAM_SUCCESS) {
621                         _pam_log(LOG_CRIT, 
622                                  "failed to set PAM_OLDAUTHTOK");
623                 }
624         } else if (flags & PAM_UPDATE_AUTHTOK) {
625         
626                 /*
627                  * obtain the proposed password
628                  */
629                 
630                 /*
631                  * get the old token back. 
632                  */
633                 
634                 retval = pam_get_item(pamh, PAM_OLDAUTHTOK
635                                       ,(const void **) &pass_old);
636                 
637                 if (retval != PAM_SUCCESS) {
638                         _pam_log(LOG_NOTICE, "user not authenticated");
639                         return retval;
640                 }
641                 
642                 lctrl = ctrl;
643                 
644                 if (on(WINBIND_USE_AUTHTOK_ARG, lctrl)) {
645                         ctrl = WINBIND_USE_FIRST_PASS_ARG | lctrl;
646                 }
647                 retry = 0;
648                 retval = PAM_AUTHTOK_ERR;
649                 while ((retval != PAM_SUCCESS) && (retry++ < MAX_PASSWD_TRIES)) {
650                         /*
651                          * use_authtok is to force the use of a previously entered
652                          * password -- needed for pluggable password strength checking
653                          */
654                         
655                         retval = _winbind_read_password(pamh, lctrl
656                                                         ,NULL
657                                                         ,"Enter new NT password: "
658                                                         ,"Retype new NT password: "
659                                                         ,(const char **) &pass_new);
660                         
661                         if (retval != PAM_SUCCESS) {
662                                 if (on(WINBIND_DEBUG_ARG, ctrl)) {
663                                         _pam_log(LOG_ALERT
664                                                  ,"password - new password not obtained");
665                                 }
666                                 pass_old = NULL;/* tidy up */
667                                 return retval;
668                         }
669
670                         /*
671                          * At this point we know who the user is and what they
672                          * propose as their new password. Verify that the new
673                          * password is acceptable.
674                          */
675                         
676                         if (pass_new[0] == '\0') {/* "\0" password = NULL */
677                                 pass_new = NULL;
678                         }
679                 }
680                 
681                 /*
682                  * By reaching here we have approved the passwords and must now
683                  * rebuild the password database file.
684                  */
685
686                 retval = winbind_chauthtok_request(user, pass_old, pass_new, ctrl);
687                 _pam_overwrite(pass_new);
688                 _pam_overwrite(pass_old);
689                 pass_old = pass_new = NULL;
690         } else {
691                 retval = PAM_SERVICE_ERR;
692         }
693         
694         return retval;
695 }
696
697 #ifdef PAM_STATIC
698
699 /* static module data */
700
701 struct pam_module _pam_winbind_modstruct = {
702      MODULE_NAME,
703      pam_sm_authenticate,
704      pam_sm_setcred,
705      pam_sm_acct_mgmt,
706      pam_sm_open_session,
707      pam_sm_close_session,
708      pam_sm_chauthtok
709 };
710
711 #endif
712
713 /*
714  * Copyright (c) Andrew Tridgell  <tridge@samba.org>   2000
715  * Copyright (c) Tim Potter       <tpot@samba.org>     2000
716  * Copyright (c) Andrew Bartlettt <abartlet@samba.org> 2002
717  * Copyright (c) Jan Rêkorajski 1999.
718  * Copyright (c) Andrew G. Morgan 1996-8.
719  * Copyright (c) Alex O. Yuriev, 1996.
720  * Copyright (c) Cristian Gafton 1996.
721  * Copyright (C) Elliot Lee <sopwith@redhat.com> 1996, Red Hat Software. 
722  *
723  * Redistribution and use in source and binary forms, with or without
724  * modification, are permitted provided that the following conditions
725  * are met:
726  * 1. Redistributions of source code must retain the above copyright
727  *    notice, and the entire permission notice in its entirety,
728  *    including the disclaimer of warranties.
729  * 2. Redistributions in binary form must reproduce the above copyright
730  *    notice, this list of conditions and the following disclaimer in the
731  *    documentation and/or other materials provided with the distribution.
732  * 3. The name of the author may not be used to endorse or promote
733  *    products derived from this software without specific prior
734  *    written permission.
735  *
736  * ALTERNATIVELY, this product may be distributed under the terms of
737  * the GNU Public License, in which case the provisions of the GPL are
738  * required INSTEAD OF the above restrictions.  (This clause is
739  * necessary due to a potential bad interaction between the GPL and
740  * the restrictions contained in a BSD-style copyright.)
741  *
742  * THIS SOFTWARE IS PROVIDED `AS IS'' AND ANY EXPRESS OR IMPLIED
743  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
744  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
745  * DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
746  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
747  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
748  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
749  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
750  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
751  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
752  * OF THE POSSIBILITY OF SUCH DAMAGE.
753  */