fixed login
This commit is contained in:
parent
a6e644aab0
commit
3963e3516b
|
@ -3,7 +3,6 @@
|
||||||
|
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <crypt.h>
|
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
int pw_check(const char *prog_name, const struct passwd *pw, const char *pass) {
|
int pw_check(const char *prog_name, const struct passwd *pw, const char *pass) {
|
||||||
|
@ -20,11 +19,7 @@ int pw_check(const char *prog_name, const struct passwd *pw, const char *pass) {
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char *cryptpass = crypt(pass, pw->pw_passwd);
|
if (!strcmp(pass, pw->pw_passwd))
|
||||||
if (cryptpass == NULL)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
if (!strcmp(pw->pw_passwd, cryptpass))
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -6,9 +6,29 @@
|
||||||
#include <limits.h>
|
#include <limits.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
#include <termios.h>
|
||||||
#include "get_string.h"
|
#include "get_string.h"
|
||||||
#include "pw_check.h"
|
#include "pw_check.h"
|
||||||
|
|
||||||
|
#define ECHOFLAGS (ECHO | ECHOE | ECHOK | ECHONL)
|
||||||
|
|
||||||
|
int hide_input(int fd, int flag) {
|
||||||
|
struct termios term;
|
||||||
|
if (tcgetattr(fd, &term) < 0)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
if (flag)
|
||||||
|
term.c_lflag &= ~ECHOFLAGS;
|
||||||
|
|
||||||
|
else
|
||||||
|
term.c_lflag |= ECHOFLAGS;
|
||||||
|
|
||||||
|
if (tcsetattr(fd, TCSAFLUSH, &term) < 0)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
void login(const struct passwd *pw) {
|
void login(const struct passwd *pw) {
|
||||||
char *shell = pw->pw_shell[0] == '\0' ? "/bin/sh" : pw->pw_shell;
|
char *shell = pw->pw_shell[0] == '\0' ? "/bin/sh" : pw->pw_shell;
|
||||||
|
|
||||||
|
@ -42,6 +62,9 @@ struct passwd *proccess_input(char *hostname) {
|
||||||
|
|
||||||
/* Password */
|
/* Password */
|
||||||
printf("\nPassword:\n");
|
printf("\nPassword:\n");
|
||||||
|
if (hide_input(STDIN_FILENO, 1))
|
||||||
|
return NULL;
|
||||||
|
|
||||||
if (!mu_get_string("login", psswd, sizeof(psswd)))
|
if (!mu_get_string("login", psswd, sizeof(psswd)))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
@ -73,6 +96,7 @@ int main(void) {
|
||||||
signal(SIGHUP, SIG_IGN);
|
signal(SIGHUP, SIG_IGN);
|
||||||
|
|
||||||
struct passwd *pw = proccess_input(hostname);
|
struct passwd *pw = proccess_input(hostname);
|
||||||
|
hide_input(STDIN_FILENO, 0);
|
||||||
if (!pw)
|
if (!pw)
|
||||||
return 1;
|
return 1;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue