*** poppassd.c-orig Thu Aug 23 00:02:40 2001 --- poppassd.c Thu Aug 23 14:53:22 2001 *************** *** 169,174 **** --- 169,175 ---- #define PASSWD_BINARY "/usr/bin/passwd" /* TBD: config.h */ #define SMBPASSWD_BINARY "/usr/bin/smbpasswd" /* TBD: config.h */ + #define POPAUTH_BINARY "/usr/local/sbin/popauth"/* TBD: config.h */ #include "config.h" *************** *** 283,289 **** static char *P1[] = { ! "changing *\nold password: ", /* shadow */ "enter login password: ", /* Solaris */ "old smb password: ", /* smb */ "" --- 284,291 ---- static char *P1[] = { ! "changing password for *\nold password: ", /* shadow */ ! "changing *\nold password: ", /* APOP */ "enter login password: ", /* Solaris */ "old smb password: ", /* smb */ "" *************** *** 334,341 **** #define RUN_PASSWD 1 #define RUN_SMBPASSWD 2 - int main ( int argc, char *argv[] ) { char line [BUFSIZE] = ""; --- 336,343 ---- #define RUN_PASSWD 1 #define RUN_SMBPASSWD 2 + #define RUN_POPAUTH 4 int main ( int argc, char *argv[] ) { char line [BUFSIZE] = ""; *************** *** 342,348 **** char oldpass [BUFSIZE] = ""; char newpass [BUFSIZE] = ""; int nopt = -1; ! static char options [] = "dl:p:Rs:t:vy:?"; int mode = 0; char *ptr = NULL; POP p; --- 344,350 ---- char oldpass [BUFSIZE] = ""; char newpass [BUFSIZE] = ""; int nopt = -1; ! static char options [] = "dal:p:Rs:t:vy:?"; int mode = 0; char *ptr = NULL; POP p; *************** *** 383,389 **** { case '?': fprintf ( stderr, "%s [-?] [-d] [-l 0|1|2] [-p [passd-path]] " ! "[-R] [-s [smbpasswd-path]]\n\t" "[-t trace-file] [-v] [-y log-facility]\n", pname ); exit (1); --- 385,391 ---- { case '?': fprintf ( stderr, "%s [-?] [-d] [-l 0|1|2] [-p [passd-path]] " ! "[-a] [-R] [-s [smbpasswd-path]]\n\t" "[-t trace-file] [-v] [-y log-facility]\n", pname ); exit (1); *************** *** 416,421 **** --- 418,430 ---- "Changing standard passwords using %s", pwd_binary ); break; + case 'a': + mode |= RUN_POPAUTH; + pwd_binary = POPAUTH_BINARY; + TRACE ( trace_file, POP_DEBUG, HERE, + "Changing APOP passwords using %s", pwd_binary ); + break; + case 't': verbose = TRUE; trace_name = strdup ( optarg ); *************** *** 577,583 **** #endif ! if ( chkPass ( userid, oldpass, pw, &p ) == FAILURE ) { syslog ( LOG_ERR, "password failure for %s", userid ); WriteToClient ( "500 Invalid user or password" ); --- 586,593 ---- #endif ! if ( !( mode & RUN_POPAUTH ) ! && chkPass ( userid, oldpass, pw, &p ) == FAILURE ) { syslog ( LOG_ERR, "password failure for %s", userid ); WriteToClient ( "500 Invalid user or password" ); *************** *** 604,609 **** --- 614,622 ---- if (mode & RUN_SMBPASSWD) runchild ( userid, oldpass, newpass, 1 ); + if (mode & RUN_POPAUTH) + runchild ( userid, oldpass, newpass, 2 ); + /* all done */ syslog ( LOG_ERR, "password changed for %s", userid ); *************** *** 655,661 **** if (talktochild (master, userid, oldpass, newpass, emess, smb) == FAILURE) { logit ( trace_file, LOG_ERR, HERE, ! "%s failed for %s", smb ? "smbpasswd" : "passwd", userid ); WriteToClient ("500 %s", emess[0] ? emess : "Unable to change password"); exit(1); --- 668,674 ---- if (talktochild (master, userid, oldpass, newpass, emess, smb) == FAILURE) { logit ( trace_file, LOG_ERR, HERE, ! "%s failed for %s", smb == 2 ? "apop" : smb? "smbpasswd" : "passwd", userid ); WriteToClient ("500 %s", emess[0] ? emess : "Unable to change password"); exit(1); *************** *** 778,784 **** * If we're changing the samba password, stay as root and force the change * so it's always in sync. */ ! if (!smb) { TRACE ( trace_file, POP_DEBUG, HERE, "...changing standard password" ); setregid ( pw->pw_gid, pw->pw_gid ); --- 791,797 ---- * If we're changing the samba password, stay as root and force the change * so it's always in sync. */ ! if (smb == 0) { TRACE ( trace_file, POP_DEBUG, HERE, "...changing standard password" ); setregid ( pw->pw_gid, pw->pw_gid ); *************** *** 789,794 **** --- 802,818 ---- err_msg ( HERE, "can't exec %s", pwd_binary ); exit ( 1 ); } + else if (smb == 2) + { + TRACE ( trace_file, POP_DEBUG, HERE, "...changing APOP password" ); + setregid ( pw->pw_gid, pw->pw_gid ); + setreuid ( pw->pw_uid, pw->pw_uid ); + + execl ( pwd_binary, "popauth", NULL ); + + err_msg ( HERE, "can't exec %s", pwd_binary ); + exit ( 1 ); + } else { TRACE ( trace_file, POP_DEBUG, HERE, "...changing smb password" ); *************** *** 879,885 **** master, userid, asroot ); /* only get current password if not root */ ! if (!asroot) { /* wait for current password prompt */ if (!expect(master, P1, buf)) return FAILURE; --- 903,909 ---- master, userid, asroot ); /* only get current password if not root */ ! if (asroot != 1) { /* wait for current password prompt */ if (!expect(master, P1, buf)) return FAILURE; *************** *** 1193,1199 **** { char err_msg [ 1024 ]; - if ( auth_user ( p, pass, pw, err_msg, sizeof(err_msg) ) == POP_SUCCESS ) return SUCCESS; else --- 1217,1222 ----