From: Sascha Hauer <s.hauer@pengutronix.de>
To: Barebox List <barebox@lists.infradead.org>
Subject: [PATCH 2/5] login: cleanup password code
Date: Thu, 27 Aug 2015 17:26:11 +0200 [thread overview]
Message-ID: <1440689174-731-2-git-send-email-s.hauer@pengutronix.de> (raw)
In-Reply-To: <1440689174-731-1-git-send-email-s.hauer@pengutronix.de>
- 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@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
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2015-08-27 15:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-08-27 15:26 [PATCH 1/5] login: rework login mechanism Sascha Hauer
2015-08-27 15:26 ` Sascha Hauer [this message]
2015-08-27 15:26 ` [PATCH 3/5] login: check return value of digest_alloc Sascha Hauer
2015-08-27 15:26 ` [PATCH 4/5] crypto: fix selecting of digests Sascha Hauer
2015-08-27 15:26 ` [PATCH 5/5] login: explain PASSWORD_DEFAULT option Sascha Hauer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1440689174-731-2-git-send-email-s.hauer@pengutronix.de \
--to=s.hauer@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox