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 x = Goodcrypt_md5(pass_new, (const char *) result);
179 static char *getNISserver(pam_handle_t *pamh)
185 if ((err = yp_get_default_domain(&domainname)) != 0) {
186 _log_err(LOG_WARNING, pamh, "can't get local yp domain: %s\n",
190 if ((err = yp_master(domainname, "passwd.byname", &master)) != 0) {
191 _log_err(LOG_WARNING, pamh, "can't find the master ypserver: %s\n",
195 port = getrpcport(master, YPPASSWDPROG, YPPASSWDPROC_UPDATE, IPPROTO_UDP);
197 _log_err(LOG_WARNING, pamh,
198 "yppasswdd not running on NIS master host\n");
201 if (port >= IPPORT_RESERVED) {
202 _log_err(LOG_WARNING, pamh,
203 "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 char *md5pass = Goodcrypt_md5(newpass, s_pas);
229 if (!strcmp(md5pass, s_pas)) {
230 _pam_delete(md5pass);
231 retval = PAM_AUTHTOK_ERR;
234 s_pas = strtok(NULL, ":,");
235 _pam_delete(md5pass);
245 static int save_old_password(const char *forwho, const char *oldpass,
248 static char buf[16384];
249 static char nbuf[16384];
250 char *s_luser, *s_uid, *s_npas, *s_pas, *pass;
252 FILE *pwfile, *opwfile;
256 struct passwd *pwd = NULL;
262 if (oldpass == NULL) {
266 oldmask = umask(077);
267 pwfile = fopen(OPW_TMPFILE, "w");
269 if (pwfile == NULL) {
270 return PAM_AUTHTOK_ERR;
273 opwfile = fopen(OLD_PASSWORDS_FILE, "r");
274 if (opwfile == NULL) {
276 return PAM_AUTHTOK_ERR;
279 chown(OPW_TMPFILE, 0, 0);
280 chmod(OPW_TMPFILE, 0600);
282 while (fgets(buf, 16380, opwfile)) {
283 if (!strncmp(buf, forwho, strlen(forwho))) {
284 buf[strlen(buf) - 1] = '\0';
285 s_luser = strtok(buf, ":");
286 s_uid = strtok(NULL, ":");
287 s_npas = strtok(NULL, ":");
288 s_pas = strtok(NULL, ":");
289 npas = strtol(s_npas, NULL, 10) + 1;
290 while (npas > howmany) {
291 s_pas = strpbrk(s_pas, ",");
296 pass = crypt_md5_wrapper(oldpass);
298 snprintf(nbuf, sizeof(nbuf), "%s:%s:%d:%s\n",
299 s_luser, s_uid, npas, pass);
301 snprintf(nbuf, sizeof(nbuf),"%s:%s:%d:%s,%s\n",
302 s_luser, s_uid, npas, s_pas, pass);
304 if (fputs(nbuf, pwfile) < 0) {
309 } else if (fputs(buf, pwfile) < 0) {
317 pwd = getpwnam(forwho);
321 pass = crypt_md5_wrapper(oldpass);
322 snprintf(nbuf, sizeof(nbuf), "%s:%d:1:%s\n",
323 forwho, pwd->pw_uid, pass);
325 if (fputs(nbuf, pwfile) < 0) {
331 if (fclose(pwfile)) {
332 D(("error writing entries to old passwords file: %s\n",
338 rename(OPW_TMPFILE, OLD_PASSWORDS_FILE);
342 return PAM_AUTHTOK_ERR;
346 static int _update_passwd(const char *forwho, const char *towhat)
348 struct passwd *tmpent = NULL;
349 FILE *pwfile, *opwfile;
353 oldmask = umask(077);
354 pwfile = fopen(PW_TMPFILE, "w");
356 if (pwfile == NULL) {
357 return PAM_AUTHTOK_ERR;
360 opwfile = fopen("/etc/passwd", "r");
361 if (opwfile == NULL) {
363 return PAM_AUTHTOK_ERR;
366 chown(PW_TMPFILE, 0, 0);
367 chmod(PW_TMPFILE, 0644);
368 tmpent = fgetpwent(opwfile);
370 if (!strcmp(tmpent->pw_name, forwho)) {
373 const char *const_charp;
376 assigned_passwd.const_charp = towhat;
378 tmpent->pw_passwd = assigned_passwd.charp;
381 if (putpwent(tmpent, pwfile)) {
382 D(("error writing entry to password file: %s\n", strerror(errno)));
386 tmpent = fgetpwent(opwfile);
390 if (fclose(pwfile)) {
391 D(("error writing entries to password file: %s\n", strerror(errno)));
396 rename(PW_TMPFILE, "/etc/passwd");
400 return PAM_AUTHTOK_ERR;
404 static int _update_shadow(const char *forwho, char *towhat)
406 struct spwd *spwdent = NULL, *stmpent = NULL;
407 FILE *pwfile, *opwfile;
411 spwdent = getspnam(forwho);
412 if (spwdent == NULL) {
413 return PAM_USER_UNKNOWN;
415 oldmask = umask(077);
416 pwfile = fopen(SH_TMPFILE, "w");
418 if (pwfile == NULL) {
419 return PAM_AUTHTOK_ERR;
422 opwfile = fopen("/etc/shadow", "r");
423 if (opwfile == NULL) {
425 return PAM_AUTHTOK_ERR;
428 chown(SH_TMPFILE, 0, 0);
429 chmod(SH_TMPFILE, 0600);
430 stmpent = fgetspent(opwfile);
433 if (!strcmp(stmpent->sp_namp, forwho)) {
434 stmpent->sp_pwdp = towhat;
435 stmpent->sp_lstchg = time(NULL) / (60 * 60 * 24);
437 D(("Set password %s for %s", stmpent->sp_pwdp, forwho));
440 if (putspent(stmpent, pwfile)) {
441 D(("error writing entry to shadow file: %s\n", strerror(errno)));
446 stmpent = fgetspent(opwfile);
450 if (fclose(pwfile)) {
451 D(("error writing entries to shadow file: %s\n", strerror(errno)));
456 rename(SH_TMPFILE, "/etc/shadow");
460 return PAM_AUTHTOK_ERR;
464 static int _do_setpass(pam_handle_t* pamh, const char *forwho, char *fromwhat,
465 char *towhat, unsigned int ctrl, int remember)
467 struct passwd *pwd = NULL;
473 pwd = getpwnam(forwho);
477 return PAM_AUTHTOK_ERR;
479 if (on(UNIX_NIS, ctrl)) {
480 struct timeval timeout;
481 struct yppasswd yppwd;
487 /* Make RPC call to NIS server */
488 if ((master = getNISserver(pamh)) == NULL)
489 return PAM_TRY_AGAIN;
491 /* Initialize password information */
492 yppwd.newpw.pw_passwd = pwd->pw_passwd;
493 yppwd.newpw.pw_name = pwd->pw_name;
494 yppwd.newpw.pw_uid = pwd->pw_uid;
495 yppwd.newpw.pw_gid = pwd->pw_gid;
496 yppwd.newpw.pw_gecos = pwd->pw_gecos;
497 yppwd.newpw.pw_dir = pwd->pw_dir;
498 yppwd.newpw.pw_shell = pwd->pw_shell;
499 yppwd.oldpass = fromwhat;
500 yppwd.newpw.pw_passwd = towhat;
502 D(("Set password %s for %s", yppwd.newpw.pw_passwd, forwho));
504 /* The yppasswd.x file said `unix authentication required',
505 * so I added it. This is the only reason it is in here.
506 * My yppasswdd doesn't use it, but maybe some others out there
509 clnt = clnt_create(master, YPPASSWDPROG, YPPASSWDVERS, "udp");
510 clnt->cl_auth = authunix_create_default();
511 memset((char *) &status, '\0', sizeof(status));
514 err = clnt_call(clnt, YPPASSWDPROC_UPDATE,
515 (xdrproc_t) xdr_yppasswd, (char *) &yppwd,
516 (xdrproc_t) xdr_int, (char *) &status,
521 retval = PAM_TRY_AGAIN;
523 D(("Error while changing NIS password.\n"));
524 retval = PAM_TRY_AGAIN;
526 D(("The password has%s been changed on %s.",
527 (err || status) ? " not" : "", master));
529 auth_destroy(clnt->cl_auth);
531 if ((err || status) != 0) {
532 retval = PAM_TRY_AGAIN;
539 /* first, save old password */
540 if (save_old_password(forwho, fromwhat, remember)) {
541 return PAM_AUTHTOK_ERR;
543 if (on(UNIX_SHADOW, ctrl) || (strcmp(pwd->pw_passwd, "x") == 0)) {
544 retval = _update_shadow(forwho, towhat);
545 if (retval == PAM_SUCCESS)
546 retval = _update_passwd(forwho, "x");
548 retval = _update_passwd(forwho, towhat);
554 static int _unix_verify_shadow(const char *user, unsigned int ctrl)
556 struct passwd *pwd = NULL; /* Password and shadow password */
557 struct spwd *spwdent = NULL; /* file entries for the user */
559 int retval = PAM_SUCCESS;
561 /* UNIX passwords area */
563 pwd = getpwnam(user); /* Get password file entry... */
566 return PAM_AUTHINFO_UNAVAIL; /* We don't need to do the rest... */
568 if (strcmp(pwd->pw_passwd, "x") == 0) {
569 /* ...and shadow password file entry for this user, if shadowing
572 spwdent = getspnam(user);
576 return PAM_AUTHINFO_UNAVAIL;
578 if (strcmp(pwd->pw_passwd,"*NP*") == 0) { /* NIS+ */
581 save_uid = geteuid();
582 seteuid (pwd->pw_uid);
583 spwdent = getspnam( user );
587 return PAM_AUTHINFO_UNAVAIL;
592 if (spwdent != NULL) {
593 /* We have the user's information, now let's check if their account
594 has expired (60 * 60 * 24 = number of seconds in a day) */
596 if (off(UNIX__IAMROOT, ctrl)) {
597 /* Get the current number of days since 1970 */
598 curdays = time(NULL) / (60 * 60 * 24);
599 if ((curdays < (spwdent->sp_lstchg + spwdent->sp_min))
600 && (spwdent->sp_min != -1))
601 retval = PAM_AUTHTOK_ERR;
602 else if ((curdays > (spwdent->sp_lstchg + spwdent->sp_max + spwdent->sp_inact))
603 && (spwdent->sp_max != -1) && (spwdent->sp_inact != -1)
604 && (spwdent->sp_lstchg != 0))
606 * Their password change has been put off too long,
608 retval = PAM_ACCT_EXPIRED;
609 else if ((curdays > spwdent->sp_expire) && (spwdent->sp_expire != -1)
610 && (spwdent->sp_lstchg != 0))
612 * OR their account has just plain expired
614 retval = PAM_ACCT_EXPIRED;
620 static int _pam_unix_approve_pass(pam_handle_t * pamh
622 ,const char *pass_old
623 ,const char *pass_new)
626 const char *remark = NULL;
627 int retval = PAM_SUCCESS;
629 D(("&new=%p, &old=%p", pass_old, pass_new));
630 D(("new=[%s]", pass_new));
631 D(("old=[%s]", pass_old));
633 if (pass_new == NULL || (pass_old && !strcmp(pass_old, pass_new))) {
634 if (on(UNIX_DEBUG, ctrl)) {
635 _log_err(LOG_DEBUG, pamh, "bad authentication token");
637 _make_remark(pamh, ctrl, PAM_ERROR_MSG, pass_new == NULL ?
638 "No password supplied" : "Password unchanged");
639 return PAM_AUTHTOK_ERR;
642 * if one wanted to hardwire authentication token strength
643 * checking this would be the place - AGM
646 retval = pam_get_item(pamh, PAM_USER, (const void **) &user);
647 if (retval != PAM_SUCCESS) {
648 if (on(UNIX_DEBUG, ctrl)) {
649 _log_err(LOG_ERR, pamh, "Can not get username");
650 return PAM_AUTHTOK_ERR;
653 if (off(UNIX__IAMROOT, ctrl)) {
655 remark = FascistCheck(pass_new, CRACKLIB_DICTS);
656 D(("called cracklib [%s]", remark));
658 if (strlen(pass_new) < 6)
659 remark = "You must choose a longer password";
660 D(("lenth check [%s]", remark));
662 if (on(UNIX_REMEMBER_PASSWD, ctrl))
663 if ((retval = check_old_password(user, pass_new)) != PAM_SUCCESS)
664 remark = "Password has been already used. Choose another.";
667 _make_remark(pamh, ctrl, PAM_ERROR_MSG, remark);
668 retval = PAM_AUTHTOK_ERR;
674 PAM_EXTERN int pam_sm_chauthtok(pam_handle_t * pamh, int flags,
675 int argc, const char **argv)
677 unsigned int ctrl, lctrl;
681 /* <DO NOT free() THESE> */
683 char *pass_old, *pass_new;
684 /* </DO NOT free() THESE> */
689 /* our current locking system requires that we lock the
690 entire password database. This avoids both livelock
692 /* These values for the number of attempts and the sleep time
693 are, of course, completely arbitrary.
694 My reading of the PAM docs is that, once pam_chauthtok() has been
695 called with PAM_UPDATE_AUTHTOK, we are obliged to take any
696 reasonable steps to make sure the token is updated; so retrying
697 for 1/10 sec. isn't overdoing it.
698 The other possibility is to call lckpwdf() on the first
699 pam_chauthtok() pass, and hold the lock until released in the
700 second pass--but is this guaranteed to work? -SRL */
702 while((retval = lckpwdf()) != 0 && i < 100) {
706 return PAM_AUTHTOK_LOCK_BUSY;
709 ctrl = _set_ctrl(pamh, flags, &remember, argc, argv);
712 * First get the name of a user
714 retval = pam_get_user(pamh, &user, "Username: ");
715 if (retval == PAM_SUCCESS) {
717 * Various libraries at various times have had bugs related to
718 * '+' or '-' as the first character of a user name. Don't take
719 * any chances here. Require that the username starts with an
720 * alphanumeric character.
722 if (user == NULL || !isalnum(*user)) {
723 _log_err(LOG_ERR, pamh, "bad username [%s]", user);
727 return PAM_USER_UNKNOWN;
729 if (retval == PAM_SUCCESS && on(UNIX_DEBUG, ctrl))
730 _log_err(LOG_DEBUG, pamh, "username [%s] obtained",
733 if (on(UNIX_DEBUG, ctrl))
734 _log_err(LOG_DEBUG, pamh,
735 "password - could not identify user");
742 D(("Got username of %s", user));
745 * This is not an AUTH module!
747 if (on(UNIX__NONULL, ctrl))
748 set(UNIX__NULLOK, ctrl);
750 if (on(UNIX__PRELIM, ctrl)) {
752 * obtain and verify the current password (OLDAUTHTOK) for
759 if (_unix_blankpasswd(ctrl, user)) {
764 } else if (off(UNIX__IAMROOT, ctrl)) {
766 /* instruct user what is happening */
767 #define greeting "Changing password for "
768 Announce = (char *) malloc(sizeof(greeting) + strlen(user));
769 if (Announce == NULL) {
770 _log_err(LOG_CRIT, pamh,
771 "password - out of memory");
777 (void) strcpy(Announce, greeting);
778 (void) strcpy(Announce + sizeof(greeting) - 1, user);
782 set(UNIX__OLD_PASSWD, lctrl);
783 retval = _unix_read_password(pamh, lctrl
785 ,"(current) UNIX password: "
788 ,(const char **) &pass_old);
791 if (retval != PAM_SUCCESS) {
792 _log_err(LOG_NOTICE, pamh
793 ,"password - (old) token not obtained");
799 /* verify that this is the password for this user */
801 retval = _unix_verify_password(pamh, user, pass_old, ctrl);
803 D(("process run by root so do nothing this time around"));
805 retval = PAM_SUCCESS; /* root doesn't have too */
808 if (retval != PAM_SUCCESS) {
809 D(("Authentication failed"));
816 retval = pam_set_item(pamh, PAM_OLDAUTHTOK, (const void *) pass_old);
818 if (retval != PAM_SUCCESS) {
819 _log_err(LOG_CRIT, pamh,
820 "failed to set PAM_OLDAUTHTOK");
822 retval = _unix_verify_shadow(user, ctrl);
823 if (retval == PAM_AUTHTOK_ERR) {
824 if (off(UNIX__IAMROOT, ctrl))
825 _make_remark(pamh, ctrl, PAM_ERROR_MSG,
826 "You must wait longer to change your password");
828 retval = PAM_SUCCESS;
830 } else if (on(UNIX__UPDATE, ctrl)) {
832 * tpass is used below to store the _pam_md() return; it
833 * should be _pam_delete()'d.
840 * obtain the proposed password
846 * get the old token back. NULL was ok only if root [at this
847 * point we assume that this has already been enforced on a
848 * previous call to this function].
851 if (off(UNIX_NOT_SET_PASS, ctrl)) {
852 retval = pam_get_item(pamh, PAM_OLDAUTHTOK
853 ,(const void **) &pass_old);
855 retval = pam_get_data(pamh, _UNIX_OLD_AUTHTOK
856 ,(const void **) &pass_old);
857 if (retval == PAM_NO_MODULE_DATA) {
858 retval = PAM_SUCCESS;
862 D(("pass_old [%s]", pass_old));
864 if (retval != PAM_SUCCESS) {
865 _log_err(LOG_NOTICE, pamh, "user not authenticated");
871 retval = _unix_verify_shadow(user, ctrl);
872 if (retval != PAM_SUCCESS) {
873 _log_err(LOG_NOTICE, pamh, "user not authenticated 2");
879 D(("get new password now"));
883 if (on(UNIX_USE_AUTHTOK, lctrl)) {
884 set(UNIX_USE_FIRST_PASS, lctrl);
887 retval = PAM_AUTHTOK_ERR;
888 while ((retval != PAM_SUCCESS) && (retry++ < MAX_PASSWD_TRIES)) {
890 * use_authtok is to force the use of a previously entered
891 * password -- needed for pluggable password strength checking
894 retval = _unix_read_password(pamh, lctrl
896 ,"Enter new UNIX password: "
897 ,"Retype new UNIX password: "
899 ,(const char **) &pass_new);
901 if (retval != PAM_SUCCESS) {
902 if (on(UNIX_DEBUG, ctrl)) {
903 _log_err(LOG_ALERT, pamh
904 ,"password - new password not obtained");
906 pass_old = NULL; /* tidy up */
912 D(("returned to _unix_chauthtok"));
915 * At this point we know who the user is and what they
916 * propose as their new password. Verify that the new
917 * password is acceptable.
920 if (pass_new[0] == '\0') { /* "\0" password = NULL */
923 retval = _pam_unix_approve_pass(pamh, ctrl, pass_old, pass_new);
926 if (retval != PAM_SUCCESS) {
927 _log_err(LOG_NOTICE, pamh,
928 "new password not acceptable");
929 pass_new = pass_old = NULL; /* tidy up */
936 * By reaching here we have approved the passwords and must now
937 * rebuild the password database file.
941 * First we encrypt the new password.
944 if (on(UNIX_MD5_PASS, ctrl)) {
945 tpass = crypt_md5_wrapper(pass_new);
948 * Salt manipulation is stolen from Rick Faith's passwd
949 * program. Sorry Rick :) -- alex
956 salt[0] = bin_to_ascii(tm & 0x3f);
957 salt[1] = bin_to_ascii((tm >> 6) & 0x3f);
960 if (off(UNIX_BIGCRYPT, ctrl) && strlen(pass_new) > 8) {
962 * to avoid using the _extensions_ of the bigcrypt()
963 * function we truncate the newly entered password
965 char *temp = malloc(9);
968 _log_err(LOG_CRIT, pamh,
969 "out of memory for password");
970 pass_new = pass_old = NULL; /* tidy up */
976 /* copy first 8 bytes of password */
977 strncpy(temp, pass_new, 8);
980 /* no longer need cleartext */
981 tpass = bigcrypt(temp, salt);
983 _pam_delete(temp); /* tidy up */
985 tpass = bigcrypt(pass_new, salt);
989 D(("password processed"));
991 /* update the password database(s) -- race conditions..? */
993 retval = _do_setpass(pamh, user, pass_old, tpass, ctrl,
996 pass_old = pass_new = NULL;
997 } else { /* something has broken with the module */
998 _log_err(LOG_ALERT, pamh,
999 "password received unknown request");
1003 D(("retval was %d", retval));
1012 /* static module data */
1014 struct pam_module _pam_unix_passwd_modstruct = {