Move type declerations to start of main

This commit is contained in:
sw1tchbl4d3 2021-07-15 16:17:54 +02:00
parent 225e6b0d6b
commit 2f4ff0812a

24
rdo.c
View file

@ -29,7 +29,7 @@ void getconf(FILE* fp, const char* entry, char* result, size_t len_result) {
errx(1, "Could not get '%s' entry in config", entry); errx(1, "Could not get '%s' entry in config", entry);
} }
void runprog(int argc, char** argv) { int runprog(int argc, char** argv) {
for(int i=0; i<argc; i++) for(int i=0; i<argc; i++)
argv[i] = argv[i + 1]; argv[i] = argv[i + 1];
@ -40,21 +40,20 @@ void runprog(int argc, char** argv) {
if (execvp(argv[0], argv) != 0) if (execvp(argv[0], argv) != 0)
perror(argv[0]); perror(argv[0]);
return 0;
} }
int main(int argc, char** argv) { int main(int argc, char** argv) {
char username[64]; char username[64], wrong_pw_sleep[64], password[128];
char wrong_pw_sleep[64]; unsigned int sleep_ms, tries;
unsigned int sleep_ms;
if (argc < 2) if (argc < 2)
errx(1, "Please specify a program to run"); errx(1, "Please specify a program to run");
int ruid = getuid(); int ruid = getuid();
if (ruid == 0) { if (ruid == 0)
runprog(argc, argv); return runprog(argc, argv);
return 0;
}
FILE* fp = fopen("/etc/rdo.conf", "r"); FILE* fp = fopen("/etc/rdo.conf", "r");
@ -80,16 +79,13 @@ int main(int argc, char** argv) {
if (!shadowEntry) if (!shadowEntry)
err(1, "Could not get shadow entry"); err(1, "Could not get shadow entry");
int tries = 0; tries = 0;
char password[128];
while (tries < 3) { while (tries < 3) {
if (!readpassphrase("(rdo) Password: ", password, sizeof(password), RPP_REQUIRE_TTY)) if (!readpassphrase("(rdo) Password: ", password, sizeof(password), RPP_REQUIRE_TTY))
err(1, "Could not get passphrase"); err(1, "Could not get passphrase");
if (strcmp(shadowEntry->sp_pwdp, crypt(password, shadowEntry->sp_pwdp)) == 0) { if (strcmp(shadowEntry->sp_pwdp, crypt(password, shadowEntry->sp_pwdp)) == 0)
runprog(argc, argv); return runprog(argc, argv);
return 0;
}
usleep(sleep_ms); usleep(sleep_ms);
fprintf(stderr, "Wrong password.\n"); fprintf(stderr, "Wrong password.\n");