diff --git a/rdo.c b/rdo.c index 089b20b..6d25adb 100644 --- a/rdo.c +++ b/rdo.c @@ -1,18 +1,36 @@ #include #include #include -#include #include #include #include #include #include +#ifdef __linux__ +#include +#endif + #include "readpassphrase.h" #include "sessions.h" #define VERSION "1.4.2" +char* getpwhash(struct passwd* pw) { + if (pw->pw_passwd[0] != 'x') + return pw->pw_passwd; + +#ifdef __linux__ + struct spwd* pw_entry = getspnam(pw->pw_name); + + if (!pw_entry || !pw_entry->sp_pwdp) + err(1, "Could not get shadow entry"); + return pw_entry->sp_pwdp; +#endif + + errx(1, "Could not get hashed password entry"); +} + void getconf(FILE* fp, const char* entry, char* result, size_t len_result) { char* line = NULL; size_t len = 0; @@ -114,23 +132,20 @@ int main(int argc, char** argv) { if (!current_member) errx(1, "You are not allowed to execute rdo."); - struct spwd* shadowEntry = getspnam(pw->pw_name); - - if (!shadowEntry || !shadowEntry->sp_pwdp) - err(1, "Could not get shadow entry"); + char* user_hashed_pw = getpwhash(pw); tries = 0; while (tries < 3) { if (!readpassphrase("(rdo) Password: ", password, sizeof(password), read_pw_from_stdin)) err(1, "Could not get passphrase"); - char* hashed_pw = crypt(password, shadowEntry->sp_pwdp); + char* given_hashed_pw = crypt(password, user_hashed_pw); memset(password, 0, sizeof(password)); - if (!hashed_pw) + if (!given_hashed_pw) errx(1, "Could not hash password, does your user have a password?"); - if (strcmp(shadowEntry->sp_pwdp, hashed_pw) == 0) { + if (strcmp(given_hashed_pw, user_hashed_pw) == 0) { if (!read_pw_from_stdin) setsession(getppid(), ts_ttl, ruid); runprog(&argv[read_pw_from_stdin+1]);