When using shadow in YP, the password field contains a ``x'' or ``##login'', not the encryped password. In this case, ypchsh/ypchfn will wrongly write the magic shadow word (x or ##login) to password field. Thus, user can not login until root reset his/her password. This patch preserves old password by re-encrypt it. The correctness of the old password is checked before sending new pw struct. --- yppasswd.c.orig Sun Mar 11 19:10:01 2001 +++ yppasswd.c Fri Aug 15 16:55:54 2003 @@ -663,6 +663,8 @@ char gecos[1024], *sp, new_gecos[1024]; char name[254], location[254], office[254], phone[254]; char oname[254], olocation[254], ooffice[254], ophone[254]; + char salt[2]; + time_t tm; printf (_("\nChanging full name for %s on %s.\n" "To accept the default, simply press return. To enter an empty\n" @@ -691,11 +693,19 @@ *sp = '\0'; yppwd.newpw.pw_gecos = strdup (new_gecos); + + time (&tm); + salt[0] = bin_to_ascii (tm & 0x3f); + salt[1] = bin_to_ascii ((tm >> 6) & 0x3f); + + yppwd.newpw.pw_passwd = strdup (crypt (yppwd.oldpass, salt)); } if (l_flag) { char new_shell[PATH_MAX]; + char salt[2]; + time_t tm; printf (_("\nChanging login shell for %s on %s.\n" "To accept the default, simply press return. To use the\n" @@ -707,6 +717,12 @@ return 1; yppwd.newpw.pw_shell = strdup (new_shell); + + time (&tm); + salt[0] = bin_to_ascii (tm & 0x3f); + salt[1] = bin_to_ascii ((tm >> 6) & 0x3f); + + yppwd.newpw.pw_passwd = strdup (crypt (yppwd.oldpass, salt)); } clnt = clnt_create (master, YPPASSWDPROG, YPPASSWDVERS, "udp");