summaryrefslogtreecommitdiff
path: root/sql
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2005-02-25 16:33:49 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2005-02-25 16:33:49 +0000
commit5a7943fe15f700caef1019b531841877b6c97ff0 (patch)
tree963d188e5b460d566d5c55b951c5fcb024d397c2 /sql
parentde6599e04a21054e73e050c1606e531e5bfb61a6 (diff)
downloadmailutils-5a7943fe15f700caef1019b531841877b6c97ff0.tar.gz
mailutils-5a7943fe15f700caef1019b531841877b6c97ff0.tar.bz2
(mu_check_mysql_scrambled_password): New function.
Diffstat (limited to 'sql')
-rw-r--r--sql/mysql.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/sql/mysql.c b/sql/mysql.c
index 866e2400c..aecb7e7b0 100644
--- a/sql/mysql.c
+++ b/sql/mysql.c
@@ -194,6 +194,36 @@ errstr (mu_sql_connection_t conn)
return mysql_error (mp->mysql);
}
+/* Check whether a plaintext password MESSAGE matches MySQL scrambled password
+ PASSWORD */
+int
+mu_check_mysql_scrambled_password (const char *scrambled, const char *message)
+{
+ unsigned long hash_pass[2], hash_message[2];
+ char buf[17];
+
+ if (strlen (scrambled) < 16)
+ return 1;
+ if (strlen (scrambled) > 16)
+ {
+ const char *p;
+ /* Try to normalize it by cutting off trailing whitespace */
+ for (p = scrambled + strlen (scrambled) - 1;
+ p > scrambled && isspace (*p); p--)
+ ;
+ if (p - scrambled != 15)
+ return 1;
+ memcpy (buf, scrambled, 16);
+ buf[17] = 0;
+ scrambled = buf;
+ }
+
+ get_salt_from_password (hash_pass, scrambled);
+ hash_password (hash_message, message);
+ return !(hash_message[0] == hash_pass[0]
+ && hash_message[1] == hash_pass[1]);
+}
+
MU_DECL_SQL_DISPATCH_T(mysql) = {
"mysql",
3306,

Return to:

Send suggestions and report system problems to the System administrator.