#include #include #include #include #include #include #include void runprog(int argc, char** argv) { for(int i=0; ipw_uid; if (uid != ruid && ruid != 0) { fprintf(stderr, "You are not in the username file.\n"); return -4; } struct spwd* shadowEntry = getspnam(username); if (!shadowEntry) { fprintf(stderr, "Could not get shadow entry, suid bit not set or username invalid?\n"); return -5; } int tries = 0; char password[128]; while (tries < 3) { if (!readpassphrase("(rdo) Password: ", password, sizeof(password), RPP_REQUIRE_TTY)) { fprintf(stderr, "Could not get passphrase, not in a TTY?\n"); return -7; } if (strcmp(shadowEntry->sp_pwdp, crypt(password, shadowEntry->sp_pwdp)) == 0) { runprog(argc, argv); return 0; } fprintf(stderr, "Wrong password.\n"); tries++; } return -6; }