#include #include #include #include #include #include #include #include int getconf(FILE* fp, const char* entry, char* result, size_t len_result) { char* line = NULL; size_t len = 0; fseek(fp, 0, SEEK_SET); while (getline(&line, &len, fp) != -1) { if (strncmp(entry, line, strlen(entry)) == 0) { strtok(line, "="); char* token = strtok(NULL, "="); if (token) { strncpy(result, token, len_result); result[strcspn(result, "\n")] = 0; return 0; } } } return 1; } void runprog(int argc, char** argv) { for(int i=0; ipw_uid; if (uid != ruid && ruid != 0) errx(1, "You are not in the username file"); struct spwd* shadowEntry = getspnam(username); if (!shadowEntry) err(1, "Could not get shadow entry"); int tries = 0; char password[128]; while (tries < 3) { if (!readpassphrase("(rdo) Password: ", password, sizeof(password), RPP_REQUIRE_TTY)) err(1, "Could not get passphrase"); if (strcmp(shadowEntry->sp_pwdp, crypt(password, shadowEntry->sp_pwdp)) == 0) { runprog(argc, argv); return 0; } fprintf(stderr, "Wrong password.\n"); tries++; } errx(1, "Too many wrong password attempts."); return 1; }