forked from soccera/rdo
Add support for platforms without shadow.h
This commit is contained in:
parent
0b30c02c4a
commit
c3f0b728ba
1 changed files with 23 additions and 8 deletions
31
rdo.c
31
rdo.c
|
@ -1,18 +1,36 @@
|
|||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
#include <err.h>
|
||||
#include <shadow.h>
|
||||
#include <crypt.h>
|
||||
#include <unistd.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __linux__
|
||||
#include <shadow.h>
|
||||
#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]);
|
||||
|
|
Loading…
Add table
Reference in a new issue