1
0
Fork 0
forked from soccera/rdo

Add support for platforms without shadow.h

This commit is contained in:
sw1tchbl4d3 2023-02-02 19:14:46 +01:00
parent 0b30c02c4a
commit c3f0b728ba

31
rdo.c
View file

@ -1,18 +1,36 @@
#include <pwd.h> #include <pwd.h>
#include <grp.h> #include <grp.h>
#include <err.h> #include <err.h>
#include <shadow.h>
#include <crypt.h> #include <crypt.h>
#include <unistd.h> #include <unistd.h>
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#ifdef __linux__
#include <shadow.h>
#endif
#include "readpassphrase.h" #include "readpassphrase.h"
#include "sessions.h" #include "sessions.h"
#define VERSION "1.4.2" #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) { void getconf(FILE* fp, const char* entry, char* result, size_t len_result) {
char* line = NULL; char* line = NULL;
size_t len = 0; size_t len = 0;
@ -114,23 +132,20 @@ int main(int argc, char** argv) {
if (!current_member) if (!current_member)
errx(1, "You are not allowed to execute rdo."); errx(1, "You are not allowed to execute rdo.");
struct spwd* shadowEntry = getspnam(pw->pw_name); char* user_hashed_pw = getpwhash(pw);
if (!shadowEntry || !shadowEntry->sp_pwdp)
err(1, "Could not get shadow entry");
tries = 0; tries = 0;
while (tries < 3) { while (tries < 3) {
if (!readpassphrase("(rdo) Password: ", password, sizeof(password), read_pw_from_stdin)) if (!readpassphrase("(rdo) Password: ", password, sizeof(password), read_pw_from_stdin))
err(1, "Could not get passphrase"); 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)); memset(password, 0, sizeof(password));
if (!hashed_pw) if (!given_hashed_pw)
errx(1, "Could not hash password, does your user have a password?"); 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) if (!read_pw_from_stdin)
setsession(getppid(), ts_ttl, ruid); setsession(getppid(), ts_ttl, ruid);
runprog(&argv[read_pw_from_stdin+1]); runprog(&argv[read_pw_from_stdin+1]);