У меня есть скомпилированная базовая программа аутентификации Linux, но я не понимаю, что требуется для возврата «Вы вошли в систему!». Я знаю пароль, но не ассоциированный UID.
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <pwd.h>
#define TRUE 1
#define FALSE 0
#define LENGTH 8
int main(int argc, char *argv[])
{
char user[LENGTH];
char prompt[] = "password: ";
struct passwd *passwddata;
char *user_pass;
while(TRUE)
{
printf("login: ");
fflush(NULL);
if (gets(user) == NULL)
exit(0);
user_pass = getpass(prompt);
passwddata = getpwnam(user);
if (passwddata != NULL)
{
if (!strcmp(user_pass, "login"))
{
printf("You have been logged in! \n");
break;
}
}
printf ("You are not %s, don't try to fool the system.\n", user);
}
return 0 ;
}