static int try_auth_userdb_passwd(const char *hmac_flag, const char *service, const char *uid, const char *opwd_buf, const char *npwd_buf) { char *opwd; char *npwd; int rc; if (hmac_flag) { DPRINTF("Trying to change password for %s", hmac_flag); DPWPRINTF("Old password=%s, new password=%s", opwd_buf, npwd_buf); opwd=hmacpw(opwd_buf, hmac_flag); if (!opwd) return 1; npwd=hmacpw(npwd_buf, hmac_flag); if (!npwd) { free(opwd); return (1); } } else { DPRINTF("Trying to change system password for %s", service); DPWPRINTF("Old password=%s, new password=%s", opwd_buf, npwd_buf); opwd=strdup(opwd_buf); if (!opwd) { return (1); } npwd=userdb_mkmd5pw(npwd_buf); if (!npwd || !(npwd=strdup(npwd))) { free(opwd); errno=EPERM; return (1); } } rc=dochangepwd1(service, uid, opwd, npwd, hmac_flag); free(opwd); free(npwd); return (rc); }
int auth_userdb_passwd(const char *service, const char *uid, const char *opwd_buf, const char *npwd_buf) { char *opwd; char *npwd; int rc; int hmac_flag=0; if (bad(uid) || bad(service) || bad(opwd_buf) || bad(npwd_buf) || strchr(uid, '/')) { errno=EPERM; return (1); } #if HAVE_HMACLIB if (strncmp(service, "hmac-", 5) == 0) { opwd=hmacpw(opwd_buf, service+5); npwd=hmacpw(npwd_buf, service+5); if (!opwd) { if (npwd) free(npwd); errno=EPERM; return (1); } hmac_flag=1; } else #endif { opwd=strdup(opwd_buf); if (!opwd) { errno=EPERM; return (1); } npwd=userdb_mkmd5pw(npwd_buf); if (!npwd || !(npwd=strdup(npwd))) { free(opwd); errno=EPERM; return (1); } } rc=dochangepwd1(service, uid, opwd, npwd, hmac_flag); free(opwd); free(npwd); return (rc); }