[PATCH 2/5] login: cleanup password code

Sascha Hauer s.hauer at pengutronix.de
Thu Aug 27 08:26:11 PDT 2015


- make some locally used functions static
- remove read_passwd which is unused
- some refactoring to make code pathes clearer

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
 common/password.c  | 48 +++++++++---------------------------------------
 include/password.h | 20 +-------------------
 2 files changed, 10 insertions(+), 58 deletions(-)

diff --git a/common/password.c b/common/password.c
index 6532143..0cb79b8 100644
--- a/common/password.c
+++ b/common/password.c
@@ -158,17 +158,7 @@ static unsigned char to_hexa(unsigned char c)
 	return c;
 }
 
-int read_passwd(unsigned char *sum, size_t length)
-{
-	if (is_passwd_env_enable())
-		return read_env_passwd(sum, length);
-	else if (is_passwd_default_enable())
-		return read_default_passwd(sum, length);
-	else
-		return -EINVAL;
-}
-
-int read_default_passwd(unsigned char *sum, size_t length)
+static int read_default_passwd(unsigned char *sum, size_t length)
 {
 	int i = 0;
 	int len = strlen(default_passwd);
@@ -195,7 +185,7 @@ int read_default_passwd(unsigned char *sum, size_t length)
 }
 EXPORT_SYMBOL(read_default_passwd);
 
-int read_env_passwd(unsigned char *sum, size_t length)
+static int read_env_passwd(unsigned char *sum, size_t length)
 {
 	int fd;
 	int ret = 0;
@@ -286,7 +276,7 @@ exit:
 }
 EXPORT_SYMBOL(write_env_passwd);
 
-static int __check_passwd(unsigned char* passwd, size_t length, int std)
+static int check_passwd(unsigned char *passwd, size_t length)
 {
 	struct digest *d = NULL;
 	unsigned char *passwd1_sum;
@@ -308,10 +298,12 @@ static int __check_passwd(unsigned char* passwd, size_t length, int std)
 
 	passwd2_sum = passwd1_sum + hash_len;
 
-	if (std)
+	if (is_passwd_env_enable())
 		ret = read_env_passwd(passwd2_sum, hash_len);
-	else
+	else if (is_passwd_default_enable())
 		ret = read_default_passwd(passwd2_sum, hash_len);
+	else
+		ret = -EINVAL;
 
 	if (ret < 0)
 		goto err;
@@ -345,28 +337,6 @@ err:
 	return ret;
 }
 
-int check_default_passwd(unsigned char* passwd, size_t length)
-{
-	return __check_passwd(passwd, length, 0);
-}
-EXPORT_SYMBOL(check_default_passwd);
-
-int check_env_passwd(unsigned char* passwd, size_t length)
-{
-	return __check_passwd(passwd, length, 1);
-}
-EXPORT_SYMBOL(check_env_passwd);
-
-int check_passwd(unsigned char* passwd, size_t length)
-{
-	if (is_passwd_env_enable())
-		return check_env_passwd(passwd, length);
-	else if (is_passwd_default_enable())
-		return check_default_passwd(passwd, length);
-	else
-		return -EINVAL;
-}
-
 int set_env_passwd(unsigned char* passwd, size_t length)
 {
 	struct digest *d = NULL;
@@ -423,7 +393,7 @@ EXPORT_SYMBOL(set_env_passwd);
 #endif
 
 static int logged_in;
-static int login_timeout;
+static int login_timeout = 60;
 static char *login_fail_command;
 
 /**
@@ -438,7 +408,7 @@ void login(void)
 	unsigned char passwd[PASSWD_MAX_LENGTH];
 	int ret;
 
-	if (!is_passwd_enable())
+	if (!is_passwd_default_enable() && !is_passwd_env_enable())
 		return;
 
 	if (logged_in)
diff --git a/include/password.h b/include/password.h
index fec831f..8b99618 100644
--- a/include/password.h
+++ b/include/password.h
@@ -26,21 +26,8 @@
 #define CLEAR	(1 << 2)
 
 int password(unsigned char *passwd, size_t length, int flags, int timeout);
-
-int read_passwd(unsigned char *sum, size_t length);
-int check_passwd(unsigned char* passwd, size_t length);
-
-int read_env_passwd(unsigned char *sum, size_t length);
-int write_env_passwd(unsigned char *sum, size_t length);
-
-int read_default_passwd(unsigned char *sum, size_t length);
-int is_passwd_default_enable(void);
-int check_default_passwd(unsigned char* passwd, size_t length);
-
-int is_passwd_env_enable(void);
 int passwd_env_disable(void);
-int check_env_passwd(unsigned char* passwd, size_t length);
-int set_env_passwd(unsigned char* passwd, size_t length);
+int set_env_passwd(unsigned char *passwd, size_t length);
 
 #ifdef CONFIG_PASSWORD
 void login(void);
@@ -50,9 +37,4 @@ static inline void login(void)
 }
 #endif
 
-static inline int is_passwd_enable(void)
-{
-	return is_passwd_default_enable() || is_passwd_env_enable();
-}
-
 #endif /* __PASSWORD_H__ */
-- 
2.5.0




More information about the barebox mailing list