diff options
| author | Mattias Andrée <m@maandree.se> | 2026-02-22 13:49:08 +0100 |
|---|---|---|
| committer | Mattias Andrée <m@maandree.se> | 2026-02-22 13:49:08 +0100 |
| commit | 86138fc92d6e5f92d9d3fcceb32b849e8504f619 (patch) | |
| tree | f361b9cea99dbe4d77d0dd8f9cbc00f67c105d6b /src/auth/crypt.c | |
| parent | Udpdate for new version of glibc (diff) | |
| download | cerberus-86138fc92d6e5f92d9d3fcceb32b849e8504f619.tar.gz cerberus-86138fc92d6e5f92d9d3fcceb32b849e8504f619.tar.bz2 cerberus-86138fc92d6e5f92d9d3fcceb32b849e8504f619.tar.xz | |
Signed-off-by: Mattias Andrée <m@maandree.se>
Diffstat (limited to '')
| -rw-r--r-- | src/auth/crypt.c | 101 |
1 files changed, 50 insertions, 51 deletions
diff --git a/src/auth/crypt.c b/src/auth/crypt.c index 4573c5a..5012580 100644 --- a/src/auth/crypt.c +++ b/src/auth/crypt.c @@ -1,7 +1,7 @@ /** * cerberus – Minimal login program * - * Copyright © 2013, 2014, 2015, 2016, 2020 Mattias Andrée (maandree@kth.se) + * Copyright © 2013, 2014, 2015, 2016, 2020 Mattias Andrée (m@maandree.se) * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -46,12 +46,12 @@ /** * Function that can be used to read a passphrase from the terminal */ -static char* (*passphrase_reader)(void) = NULL; +static char *(*passphrase_reader)(void) = NULL; /** * The username of the user to log in to */ -static char* login_username; +static char *login_username; @@ -62,12 +62,13 @@ static char* login_username; * @param username The username of the user to log in to * @param reader Function that can be used to read a passphrase from the terminal */ -void initialise_crypt(char* remote, char* username, char* (*reader)(void)) +void +initialise_crypt(char *remote, char *username, char *(*reader)(void)) { - (void) remote; - - login_username = username; - passphrase_reader = reader; + (void) remote; + + login_username = username; + passphrase_reader = reader; } @@ -76,54 +77,52 @@ void initialise_crypt(char* remote, char* username, char* (*reader)(void)) * * @return 0: failed, 1: success, 2: auto-authenticated */ -char authenticate_crypt(void) +char +authenticate_crypt(void) { #ifdef HAVE_SHADOW - struct spwd* shadow_entry = NULL; + struct spwd *shadow_entry = NULL; #endif - struct passwd* passwd_entry = NULL; - char* crypted; - char* entered; - struct termios stty; - + struct passwd *passwd_entry = NULL; + char *crypted; + char *entered; + struct termios stty; + #ifdef HAVE_SHADOW - shadow_entry = getspnam(login_username); - endspent(); - - if (shadow_entry) - crypted = shadow_entry->sp_pwdp; - else - { + shadow_entry = getspnam(login_username); + endspent(); + + if (shadow_entry) { + crypted = shadow_entry->sp_pwdp; + } else { #endif - passwd_entry = getpwnam(login_username); - if (passwd_entry) - crypted = passwd_entry->pw_passwd; - else - { - perror("getpwnam"); - endpwent(); - sleep(ERROR_SLEEP); - _exit(1); - } - endpwent(); + passwd_entry = getpwnam(login_username); + if (passwd_entry) { + crypted = passwd_entry->pw_passwd; + } else { + perror("getpwnam"); + endpwent(); + sleep(ERROR_SLEEP); + _exit(1); + } + endpwent(); #ifdef HAVE_SHADOW - } + } #endif - - if (!(crypted && *crypted)) /* empty means that no passphrase is required (not even Enter) */ - return 2; - - entered = crypt(passphrase_reader(), crypted /* salt argument stops parsing when encrypted begins */); - if (entered && !strcmp(entered, crypted)) - return 1; - - /* Clear ISIG (and everything else) to prevent the user - * from skipping the brute force protection sleep. */ - tcgetattr(STDIN_FILENO, &stty); - stty.c_lflag = 0; - tcsetattr(STDIN_FILENO, TCSAFLUSH, &stty); - - printf("\nPassphrase incorrect.\nOnly perfect spellers may\nenter this system.\n"); - return 0; -} + if (!(crypted && *crypted)) /* empty means that no passphrase is required (not even Enter) */ + return 2; + + entered = crypt(passphrase_reader(), crypted /* salt argument stops parsing when encrypted begins */); + if (entered && !strcmp(entered, crypted)) + return 1; + + /* Clear ISIG (and everything else) to prevent the user + * from skipping the brute force protection sleep. */ + tcgetattr(STDIN_FILENO, &stty); + stty.c_lflag = 0; + tcsetattr(STDIN_FILENO, TCSAFLUSH, &stty); + + printf("\nPassphrase incorrect.\nOnly perfect spellers may\nenter this system.\n"); + return 0; +} |
