2 * Main coding by Elliot Lee <sopwith@redhat.com>, Red Hat Software.
4 * Copyright (c) Jan Rêkorajski, 1999.
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, and the entire permission notice in its entirety,
11 * including the disclaimer of warranties.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote
16 * products derived from this software without specific prior
19 * ALTERNATIVELY, this product may be distributed under the terms of
20 * the GNU Public License, in which case the provisions of the GPL are
21 * required INSTEAD OF the above restrictions. (This clause is
22 * necessary due to a potential bad interaction between the GPL and
23 * the restrictions contained in a BSD-style copyright.)
25 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
26 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
27 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
28 * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
29 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
32 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
35 * OF THE POSSIBILITY OF SUCH DAMAGE.
38 #include <security/_pam_aconf.h>
47 #include <sys/types.h>
51 #include <time.h> /* for time() */
57 #include <rpcsvc/yp_prot.h>
58 #include <rpcsvc/ypclnt.h>
64 #include <security/_pam_macros.h>
66 /* indicate the following groups are defined */
68 #define PAM_SM_PASSWORD
70 #include <security/pam_modules.h>
73 #include <security/pam_appl.h>
74 #endif /* LINUX_PAM */
80 #if !((__GLIBC__ == 2) && (__GLIBC_MINOR__ >= 1))
81 extern int getrpcport(const char *host, unsigned long prognum,
82 unsigned long versnum, unsigned int proto);
83 #endif /* GNU libc 2.1 */
86 * PAM framework looks for these entry-points to pass control to the
87 * password changing module.
91 #include "./lckpwdf.-c"
94 extern char *bigcrypt(const char *key, const char *salt);
98 Gets in username (has to be done) from the calling program
99 Does authentication of user (only if we are not running as root)
100 Gets new password/checks for sanity
104 /* passwd/salt conversion macros */
106 #define ascii_to_bin(c) ((c)>='a'?(c-59):(c)>='A'?((c)-53):(c)-'.')
107 #define bin_to_ascii(c) ((c)>=38?((c)-38+'a'):(c)>=12?((c)-12+'A'):(c)+'.')
111 #define _UNIX_OLD_AUTHTOK "-UN*X-OLD-PASS"
112 #define _UNIX_NEW_AUTHTOK "-UN*X-NEW-PASS"
114 #define MAX_PASSWD_TRIES 3
115 #define PW_TMPFILE "/etc/npasswd"
116 #define SH_TMPFILE "/etc/nshadow"
117 #define CRACKLIB_DICTS "/usr/share/dict/cracklib_dict"
118 #define OPW_TMPFILE "/etc/security/nopasswd"
119 #define OLD_PASSWORDS_FILE "/etc/security/opasswd"
122 * i64c - convert an integer to a radix 64 character
124 static int i64c(int i)
134 if (i >= 2 && i <= 11)
135 return ('0' - 2 + i);
136 if (i >= 12 && i <= 37)
137 return ('A' - 12 + i);
138 if (i >= 38 && i <= 63)
139 return ('a' - 38 + i);
143 static char *crypt_md5_wrapper(const char *pass_new)
146 * Code lifted from Marek Michalkiewicz's shadow suite. (CG)
147 * removed use of static variables (AGM)
152 unsigned char result[16];
153 char *cp = (char *) result;
154 unsigned char tmp[16];
159 gettimeofday(&tv, (struct timezone *) 0);
160 GoodMD5Update(&ctx, (void *) &tv, sizeof tv);
162 GoodMD5Update(&ctx, (void *) &i, sizeof i);
164 GoodMD5Update(&ctx, (void *) &i, sizeof i);
165 GoodMD5Update(&ctx, result, sizeof result);
166 GoodMD5Final(tmp, &ctx);
167 strcpy(cp, "$1$"); /* magic for the MD5 */
169 for (i = 0; i < 8; i++)
170 *cp++ = i64c(tmp[i] & 077);
173 /* no longer need cleartext */
174 e = Goodcrypt_md5(pass_new, (const char *) result);
175 x = x_strdup(e); /* put e in malloc()ed memory */
176 _pam_overwrite(e); /* clean up */
181 static char *getNISserver(void)
187 if ((err = yp_get_default_domain(&domainname)) != 0) {
188 _log_err(LOG_WARNING, "can't get local yp domain: %s\n",
192 if ((err = yp_master(domainname, "passwd.byname", &master)) != 0) {
193 _log_err(LOG_WARNING, "can't find the master ypserver: %s\n",
197 port = getrpcport(master, YPPASSWDPROG, YPPASSWDPROC_UPDATE, IPPROTO_UDP);
199 _log_err(LOG_WARNING, "yppasswdd not running on NIS master host\n");
202 if (port >= IPPORT_RESERVED) {
203 _log_err(LOG_WARNING, "yppasswd daemon running on illegal port.\n");
209 static int check_old_password(const char *forwho, const char *newpass)
211 static char buf[16384];
212 char *s_luser, *s_uid, *s_npas, *s_pas;
213 int retval = PAM_SUCCESS;
216 opwfile = fopen(OLD_PASSWORDS_FILE, "r");
218 return PAM_AUTHTOK_ERR;
220 while (fgets(buf, 16380, opwfile)) {
221 if (!strncmp(buf, forwho, strlen(forwho))) {
222 buf[strlen(buf) - 1] = '\0';
223 s_luser = strtok(buf, ":,");
224 s_uid = strtok(NULL, ":,");
225 s_npas = strtok(NULL, ":,");
226 s_pas = strtok(NULL, ":,");
227 while (s_pas != NULL) {
228 if (!strcmp(Goodcrypt_md5(newpass, s_pas), s_pas)) {
229 retval = PAM_AUTHTOK_ERR;
232 s_pas = strtok(NULL, ":,");
242 static int save_old_password(const char *forwho, const char *oldpass, int howmany)
244 static char buf[16384];
245 static char nbuf[16384];
246 char *s_luser, *s_uid, *s_npas, *s_pas, *pass;
247 int retval = 0, npas;
248 FILE *pwfile, *opwfile;
252 struct passwd *pwd = NULL;
260 oldmask = umask(077);
261 pwfile = fopen(OPW_TMPFILE, "w");
263 opwfile = fopen(OLD_PASSWORDS_FILE, "r");
264 if (pwfile == NULL || opwfile == NULL)
265 return PAM_AUTHTOK_ERR;
266 chown(OPW_TMPFILE, 0, 0);
267 chmod(OPW_TMPFILE, 0600);
269 while (fgets(buf, 16380, opwfile)) {
270 if (!strncmp(buf, forwho, strlen(forwho))) {
271 buf[strlen(buf) - 1] = '\0';
272 s_luser = strtok(buf, ":");
273 s_uid = strtok(NULL, ":");
274 s_npas = strtok(NULL, ":");
275 s_pas = strtok(NULL, ":");
276 npas = strtol(s_npas, NULL, 10) + 1;
277 while (npas > howmany) {
278 s_pas = strpbrk(s_pas, ",");
283 pass = crypt_md5_wrapper(oldpass);
285 sprintf(nbuf, "%s:%s:%d:%s\n", s_luser, s_uid, npas, pass);
287 sprintf(nbuf, "%s:%s:%d:%s,%s\n", s_luser, s_uid, npas, s_pas, pass);
288 if (fputs(nbuf, pwfile) < 0) {
289 retval = PAM_AUTHTOK_ERR;
294 } else if (fputs(buf, pwfile) < 0) {
295 retval = PAM_AUTHTOK_ERR;
302 pwd = getpwnam(forwho);
304 retval = PAM_AUTHTOK_ERR;
307 pass = crypt_md5_wrapper(oldpass);
308 sprintf(nbuf, "%s:%d:1:%s\n", forwho, pwd->pw_uid, pass);
309 if (fputs(nbuf, pwfile) < 0) {
310 retval = PAM_AUTHTOK_ERR;
315 if (fclose(pwfile)) {
316 fprintf(stderr, "error writing entries to old passwords file: %s\n",
318 retval = PAM_AUTHTOK_ERR;
322 rename(OPW_TMPFILE, OLD_PASSWORDS_FILE);
329 static int _update_passwd(const char *forwho, char *towhat)
331 struct passwd *tmpent = NULL;
332 FILE *pwfile, *opwfile;
337 oldmask = umask(077);
338 pwfile = fopen(PW_TMPFILE, "w");
340 opwfile = fopen("/etc/passwd", "r");
341 if (pwfile == NULL || opwfile == NULL)
342 return PAM_AUTHTOK_ERR;
343 chown(PW_TMPFILE, 0, 0);
344 chmod(PW_TMPFILE, 0644);
345 tmpent = fgetpwent(opwfile);
347 if (!strcmp(tmpent->pw_name, forwho)) {
348 tmpent->pw_passwd = towhat;
350 if (putpwent(tmpent, pwfile)) {
351 fprintf(stderr, "error writing entry to password file: %s\n",
354 retval = PAM_AUTHTOK_ERR;
357 tmpent = fgetpwent(opwfile);
361 if (fclose(pwfile)) {
362 fprintf(stderr, "error writing entries to password file: %s\n",
364 retval = PAM_AUTHTOK_ERR;
368 rename(PW_TMPFILE, "/etc/passwd");
375 static int _update_shadow(const char *forwho, char *towhat)
377 struct spwd *spwdent = NULL, *stmpent = NULL;
378 FILE *pwfile, *opwfile;
383 spwdent = getspnam(forwho);
385 return PAM_USER_UNKNOWN;
386 oldmask = umask(077);
387 pwfile = fopen(SH_TMPFILE, "w");
389 opwfile = fopen("/etc/shadow", "r");
390 if (pwfile == NULL || opwfile == NULL)
391 return PAM_AUTHTOK_ERR;
392 chown(SH_TMPFILE, 0, 0);
393 chmod(SH_TMPFILE, 0600);
394 stmpent = fgetspent(opwfile);
396 if (!strcmp(stmpent->sp_namp, forwho)) {
397 stmpent->sp_pwdp = towhat;
398 stmpent->sp_lstchg = time(NULL) / (60 * 60 * 24);
400 D(("Set password %s for %s", stmpent->sp_pwdp, forwho));
402 if (putspent(stmpent, pwfile)) {
403 fprintf(stderr, "error writing entry to shadow file: %s\n",
406 retval = PAM_AUTHTOK_ERR;
409 stmpent = fgetspent(opwfile);
413 if (fclose(pwfile)) {
414 fprintf(stderr, "error writing entries to shadow file: %s\n",
416 retval = PAM_AUTHTOK_ERR;
420 rename(SH_TMPFILE, "/etc/shadow");
427 static int _do_setpass(const char *forwho, char *fromwhat, char *towhat,
428 unsigned int ctrl, int remember)
430 struct passwd *pwd = NULL;
436 pwd = getpwnam(forwho);
440 return PAM_AUTHTOK_ERR;
442 if (on(UNIX_NIS, ctrl)) {
443 struct timeval timeout;
444 struct yppasswd yppwd;
450 /* Make RPC call to NIS server */
451 if ((master = getNISserver()) == NULL)
452 return PAM_TRY_AGAIN;
454 /* Initialize password information */
455 yppwd.newpw.pw_passwd = pwd->pw_passwd;
456 yppwd.newpw.pw_name = pwd->pw_name;
457 yppwd.newpw.pw_uid = pwd->pw_uid;
458 yppwd.newpw.pw_gid = pwd->pw_gid;
459 yppwd.newpw.pw_gecos = pwd->pw_gecos;
460 yppwd.newpw.pw_dir = pwd->pw_dir;
461 yppwd.newpw.pw_shell = pwd->pw_shell;
462 yppwd.oldpass = fromwhat;
463 yppwd.newpw.pw_passwd = towhat;
465 D(("Set password %s for %s", yppwd.newpw.pw_passwd, forwho));
467 /* The yppasswd.x file said `unix authentication required',
468 * so I added it. This is the only reason it is in here.
469 * My yppasswdd doesn't use it, but maybe some others out there
472 clnt = clnt_create(master, YPPASSWDPROG, YPPASSWDVERS, "udp");
473 clnt->cl_auth = authunix_create_default();
474 memset((char *) &status, '\0', sizeof(status));
477 err = clnt_call(clnt, YPPASSWDPROC_UPDATE,
478 (xdrproc_t) xdr_yppasswd, (char *) &yppwd,
479 (xdrproc_t) xdr_int, (char *) &status,
484 retval = PAM_TRY_AGAIN;
486 fprintf(stderr, "Error while changing NIS password.\n");
487 retval = PAM_TRY_AGAIN;
489 printf("\nThe password has%s been changed on %s.\n",
490 (err || status) ? " not" : "", master);
492 auth_destroy(clnt->cl_auth);
494 if ((err || status) != 0) {
495 retval = PAM_TRY_AGAIN;
502 /* first, save old password */
503 if (save_old_password(forwho, fromwhat, remember)) {
504 return PAM_AUTHTOK_ERR;
506 if (on(UNIX_SHADOW, ctrl) || (strcmp(pwd->pw_passwd, "x") == 0)) {
507 retval = _update_shadow(forwho, towhat);
508 if (retval == PAM_SUCCESS)
509 retval = _update_passwd(forwho, "x");
511 retval = _update_passwd(forwho, towhat);
517 static int _unix_verify_shadow(const char *user, unsigned int ctrl)
519 struct passwd *pwd = NULL; /* Password and shadow password */
520 struct spwd *spwdent = NULL; /* file entries for the user */
522 int retval = PAM_SUCCESS;
524 /* UNIX passwords area */
526 pwd = getpwnam(user); /* Get password file entry... */
529 return PAM_AUTHINFO_UNAVAIL; /* We don't need to do the rest... */
531 if (strcmp(pwd->pw_passwd, "x") == 0) {
532 /* ...and shadow password file entry for this user, if shadowing
535 spwdent = getspnam(user);
539 return PAM_AUTHINFO_UNAVAIL;
541 if (strcmp(pwd->pw_passwd,"*NP*") == 0) { /* NIS+ */
544 save_uid = geteuid();
545 seteuid (pwd->pw_uid);
546 spwdent = getspnam( user );
550 return PAM_AUTHINFO_UNAVAIL;
555 if (spwdent != NULL) {
556 /* We have the user's information, now let's check if their account
557 has expired (60 * 60 * 24 = number of seconds in a day) */
559 if (off(UNIX__IAMROOT, ctrl)) {
560 /* Get the current number of days since 1970 */
561 curdays = time(NULL) / (60 * 60 * 24);
562 if ((curdays < (spwdent->sp_lstchg + spwdent->sp_min))
563 && (spwdent->sp_min != -1))
564 retval = PAM_AUTHTOK_ERR;
565 else if ((curdays > (spwdent->sp_lstchg + spwdent->sp_max + spwdent->sp_inact))
566 && (spwdent->sp_max != -1) && (spwdent->sp_inact != -1)
567 && (spwdent->sp_lstchg != 0))
569 * Their password change has been put off too long,
571 retval = PAM_ACCT_EXPIRED;
572 else if ((curdays > spwdent->sp_expire) && (spwdent->sp_expire != -1)
573 && (spwdent->sp_lstchg != 0))
575 * OR their account has just plain expired
577 retval = PAM_ACCT_EXPIRED;
583 static int _pam_unix_approve_pass(pam_handle_t * pamh
585 ,const char *pass_old
586 ,const char *pass_new)
590 int retval = PAM_SUCCESS;
592 D(("&new=%p, &old=%p", pass_old, pass_new));
593 D(("new=[%s]", pass_new));
594 D(("old=[%s]", pass_old));
596 if (pass_new == NULL || (pass_old && !strcmp(pass_old, pass_new))) {
597 if (on(UNIX_DEBUG, ctrl)) {
598 _log_err(LOG_DEBUG, "bad authentication token");
600 _make_remark(pamh, ctrl, PAM_ERROR_MSG, pass_new == NULL ?
601 "No password supplied" : "Password unchanged");
602 return PAM_AUTHTOK_ERR;
605 * if one wanted to hardwire authentication token strength
606 * checking this would be the place - AGM
609 retval = pam_get_item(pamh, PAM_USER, (const void **) &user);
610 if (retval != PAM_SUCCESS) {
611 if (on(UNIX_DEBUG, ctrl)) {
612 _log_err(LOG_ERR, "Can not get username");
613 return PAM_AUTHTOK_ERR;
616 if (off(UNIX__IAMROOT, ctrl)) {
618 remark = FascistCheck(pass_new, CRACKLIB_DICTS);
619 D(("called cracklib [%s]", remark));
621 if (strlen(pass_new) < 6)
622 remark = "You must choose a longer password";
623 D(("lenth check [%s]", remark));
625 if (on(UNIX_REMEMBER_PASSWD, ctrl))
626 if ((retval = check_old_password(user, pass_new)) != PAM_SUCCESS)
627 remark = "Password has been already used. Choose another.";
630 _make_remark(pamh, ctrl, PAM_ERROR_MSG, remark);
631 retval = PAM_AUTHTOK_ERR;
637 PAM_EXTERN int pam_sm_chauthtok(pam_handle_t * pamh, int flags,
638 int argc, const char **argv)
640 unsigned int ctrl, lctrl;
644 /* <DO NOT free() THESE> */
646 char *pass_old, *pass_new;
647 /* </DO NOT free() THESE> */
652 /* our current locking system requires that we lock the
653 entire password database. This avoids both livelock
655 /* These values for the number of attempts and the sleep time
656 are, of course, completely arbitrary.
657 My reading of the PAM docs is that, once pam_chauthtok() has been
658 called with PAM_UPDATE_AUTHTOK, we are obliged to take any
659 reasonable steps to make sure the token is updated; so retrying
660 for 1/10 sec. isn't overdoing it.
661 The other possibility is to call lckpwdf() on the first
662 pam_chauthtok() pass, and hold the lock until released in the
663 second pass--but is this guaranteed to work? -SRL */
665 while((retval = lckpwdf()) != 0 && i < 100) {
669 return PAM_AUTHTOK_LOCK_BUSY;
672 ctrl = _set_ctrl(flags, &remember, argc, argv);
675 * First get the name of a user
677 retval = pam_get_user(pamh, &user, "Username: ");
678 if (retval == PAM_SUCCESS) {
680 * Various libraries at various times have had bugs related to
681 * '+' or '-' as the first character of a user name. Don't take
682 * any chances here. Require that the username starts with an
683 * alphanumeric character.
685 if (user == NULL || !isalnum(*user)) {
686 _log_err(LOG_ERR, "bad username [%s]", user);
690 return PAM_USER_UNKNOWN;
692 if (retval == PAM_SUCCESS && on(UNIX_DEBUG, ctrl))
693 _log_err(LOG_DEBUG, "username [%s] obtained", user);
695 if (on(UNIX_DEBUG, ctrl))
696 _log_err(LOG_DEBUG, "password - could not identify user");
703 D(("Got username of %s", user));
706 * This is not an AUTH module!
708 if (on(UNIX__NONULL, ctrl))
709 set(UNIX__NULLOK, ctrl);
711 if (on(UNIX__PRELIM, ctrl)) {
713 * obtain and verify the current password (OLDAUTHTOK) for
720 if (_unix_blankpasswd(ctrl, user)) {
725 } else if (off(UNIX__IAMROOT, ctrl)) {
727 /* instruct user what is happening */
728 #define greeting "Changing password for "
729 Announce = (char *) malloc(sizeof(greeting) + strlen(user));
730 if (Announce == NULL) {
731 _log_err(LOG_CRIT, "password - out of memory");
737 (void) strcpy(Announce, greeting);
738 (void) strcpy(Announce + sizeof(greeting) - 1, user);
742 set(UNIX__OLD_PASSWD, lctrl);
743 retval = _unix_read_password(pamh, lctrl
745 ,"(current) UNIX password: "
748 ,(const char **) &pass_old);
751 if (retval != PAM_SUCCESS) {
753 ,"password - (old) token not obtained");
759 /* verify that this is the password for this user */
761 retval = _unix_verify_password(pamh, user, pass_old, ctrl);
763 D(("process run by root so do nothing this time around"));
765 retval = PAM_SUCCESS; /* root doesn't have too */
768 if (retval != PAM_SUCCESS) {
769 D(("Authentication failed"));
776 retval = pam_set_item(pamh, PAM_OLDAUTHTOK, (const void *) pass_old);
778 if (retval != PAM_SUCCESS) {
779 _log_err(LOG_CRIT, "failed to set PAM_OLDAUTHTOK");
781 retval = _unix_verify_shadow(user, ctrl);
782 if (retval == PAM_AUTHTOK_ERR) {
783 if (off(UNIX__IAMROOT, ctrl))
784 _make_remark(pamh, ctrl, PAM_ERROR_MSG,
785 "You must wait longer to change your password");
787 retval = PAM_SUCCESS;
789 } else if (on(UNIX__UPDATE, ctrl)) {
791 * tpass is used below to store the _pam_md() return; it
792 * should be _pam_delete()'d.
799 * obtain the proposed password
805 * get the old token back. NULL was ok only if root [at this
806 * point we assume that this has already been enforced on a
807 * previous call to this function].
810 if (off(UNIX_NOT_SET_PASS, ctrl)) {
811 retval = pam_get_item(pamh, PAM_OLDAUTHTOK
812 ,(const void **) &pass_old);
814 retval = pam_get_data(pamh, _UNIX_OLD_AUTHTOK
815 ,(const void **) &pass_old);
816 if (retval == PAM_NO_MODULE_DATA) {
817 retval = PAM_SUCCESS;
821 D(("pass_old [%s]", pass_old));
823 if (retval != PAM_SUCCESS) {
824 _log_err(LOG_NOTICE, "user not authenticated");
830 retval = _unix_verify_shadow(user, ctrl);
831 if (retval != PAM_SUCCESS) {
832 _log_err(LOG_NOTICE, "user not authenticated 2");
838 D(("get new password now"));
842 if (on(UNIX_USE_AUTHTOK, lctrl)) {
843 set(UNIX_USE_FIRST_PASS, lctrl);
846 retval = PAM_AUTHTOK_ERR;
847 while ((retval != PAM_SUCCESS) && (retry++ < MAX_PASSWD_TRIES)) {
849 * use_authtok is to force the use of a previously entered
850 * password -- needed for pluggable password strength checking
853 retval = _unix_read_password(pamh, lctrl
855 ,"Enter new UNIX password: "
856 ,"Retype new UNIX password: "
858 ,(const char **) &pass_new);
860 if (retval != PAM_SUCCESS) {
861 if (on(UNIX_DEBUG, ctrl)) {
863 ,"password - new password not obtained");
865 pass_old = NULL; /* tidy up */
871 D(("returned to _unix_chauthtok"));
874 * At this point we know who the user is and what they
875 * propose as their new password. Verify that the new
876 * password is acceptable.
879 if (pass_new[0] == '\0') { /* "\0" password = NULL */
882 retval = _pam_unix_approve_pass(pamh, ctrl, pass_old, pass_new);
885 if (retval != PAM_SUCCESS) {
886 _log_err(LOG_NOTICE, "new password not acceptable");
887 _pam_overwrite(pass_new);
888 _pam_overwrite(pass_old);
889 pass_new = pass_old = NULL; /* tidy up */
896 * By reaching here we have approved the passwords and must now
897 * rebuild the password database file.
901 * First we encrypt the new password.
904 if (on(UNIX_MD5_PASS, ctrl)) {
905 tpass = crypt_md5_wrapper(pass_new);
908 * Salt manipulation is stolen from Rick Faith's passwd
909 * program. Sorry Rick :) -- alex
916 salt[0] = bin_to_ascii(tm & 0x3f);
917 salt[1] = bin_to_ascii((tm >> 6) & 0x3f);
920 if (off(UNIX_BIGCRYPT, ctrl) && strlen(pass_new) > 8) {
922 * to avoid using the _extensions_ of the bigcrypt()
923 * function we truncate the newly entered password
925 char *temp = malloc(9);
929 _log_err(LOG_CRIT, "out of memory for password");
930 _pam_overwrite(pass_new);
931 _pam_overwrite(pass_old);
932 pass_new = pass_old = NULL; /* tidy up */
938 /* copy first 8 bytes of password */
939 strncpy(temp, pass_new, 8);
942 /* no longer need cleartext */
943 e = bigcrypt(temp, salt);
947 _pam_delete(temp); /* tidy up */
951 /* no longer need cleartext */
952 e = bigcrypt(pass_new, salt);
959 D(("password processed"));
961 /* update the password database(s) -- race conditions..? */
963 retval = _do_setpass(user, pass_old, tpass, ctrl, remember);
964 _pam_overwrite(pass_new);
965 _pam_overwrite(pass_old);
967 pass_old = pass_new = NULL;
968 } else { /* something has broken with the module */
969 _log_err(LOG_ALERT, "password received unknown request");
973 D(("retval was %d", retval));
982 /* static module data */
984 struct pam_module _pam_unix_passwd_modstruct = {