aboutsummaryrefslogtreecommitdiffstats
path: root/src/auth/crypt.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/auth/crypt.c101
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;
+}