]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Move test_password_{one,many} to libcrypt-util.c
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 8 Sep 2020 13:21:21 +0000 (15:21 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 15 Sep 2020 09:52:30 +0000 (11:52 +0200)
They are only used under src/home/, but I want to add tests in test-libcrypt-util.c.
And the functions are almost trivial, so I think it is OK to move them to shared.

src/home/home-util.c
src/home/home-util.h
src/home/user-record-pwquality.c
src/shared/libcrypt-util.c
src/shared/libcrypt-util.h

index 3fd57639f84192d0a329ed8a8e5554cf57d44d0a..8e28e3ab76af00ddd397f8d5aec0fe699f932603 100644 (file)
@@ -1,7 +1,6 @@
 /* SPDX-License-Identifier: LGPL-2.1+ */
 
 #include "dns-domain.h"
-#include "errno-util.h"
 #include "home-util.h"
 #include "libcrypt-util.h"
 #include "memory-util.h"
@@ -134,35 +133,3 @@ int bus_message_append_secret(sd_bus_message *m, UserRecord *secret) {
 
         return sd_bus_message_append(m, "s", formatted);
 }
-
-int test_password_one(const char *hashed_password, const char *password) {
-        struct crypt_data cc = {};
-        const char *k;
-        bool b;
-
-        errno = 0;
-        k = crypt_r(password, hashed_password, &cc);
-        if (!k) {
-                explicit_bzero_safe(&cc, sizeof(cc));
-                return errno_or_else(EINVAL);
-        }
-
-        b = streq(k, hashed_password);
-        explicit_bzero_safe(&cc, sizeof(cc));
-        return b;
-}
-
-int test_password_many(char **hashed_password, const char *password) {
-        char **hpw;
-        int r;
-
-        STRV_FOREACH(hpw, hashed_password) {
-                r = test_password_one(*hpw, password);
-                if (r < 0)
-                        return r;
-                if (r > 0)
-                        return true;
-        }
-
-        return false;
-}
index 6161d4c3d06da2f6ade7533f483dd1d4c40d0b54..73602e4f8ec0462ded7226dd208d0d8558da4cbf 100644 (file)
@@ -21,6 +21,3 @@ int bus_message_append_secret(sd_bus_message *m, UserRecord *secret);
 /* Many of our operations might be slow due to crypto, fsck, recursive chown() and so on. For these
  * operations permit a *very* long timeout */
 #define HOME_SLOW_BUS_CALL_TIMEOUT_USEC (2*USEC_PER_MINUTE)
-
-int test_password_one(const char *hashed_password, const char *password);
-int test_password_many(char **hashed_password, const char *password);
index a5d632c7727229885e5468f64c4bd12dc6ff507f..08d7dc01695bbda398c9ce917ceb3948a9519533 100644 (file)
@@ -3,6 +3,7 @@
 #include "bus-common-errors.h"
 #include "errno-util.h"
 #include "home-util.h"
+#include "libcrypt-util.h"
 #include "pwquality-util.h"
 #include "strv.h"
 #include "user-record-pwquality.h"
index cb12cd65f37f3ef36c7921e4e4b722683dda694e..1faf683d715bc8fc3921c399ce37ffa6cc35cc24 100644 (file)
@@ -117,3 +117,35 @@ bool looks_like_hashed_password(const char *s) {
 
         return !STR_IN_SET(s, "x", "*");
 }
+
+int test_password_one(const char *hashed_password, const char *password) {
+        struct crypt_data cc = {};
+        const char *k;
+        bool b;
+
+        errno = 0;
+        k = crypt_r(password, hashed_password, &cc);
+        if (!k) {
+                explicit_bzero_safe(&cc, sizeof(cc));
+                return errno_or_else(EINVAL);
+        }
+
+        b = streq(k, hashed_password);
+        explicit_bzero_safe(&cc, sizeof(cc));
+        return b;
+}
+
+int test_password_many(char **hashed_password, const char *password) {
+        char **hpw;
+        int r;
+
+        STRV_FOREACH(hpw, hashed_password) {
+                r = test_password_one(*hpw, password);
+                if (r < 0)
+                        return r;
+                if (r > 0)
+                        return true;
+        }
+
+        return false;
+}
index 2f8c352ab3710d261218e2753a1120b1d03bd8b7..5be4e64a52c8bbed7899bbd7e46be42237277029 100644 (file)
@@ -23,3 +23,5 @@ static inline int hash_password(const char *password, char **ret) {
         return hash_password_full(password, NULL, NULL, ret);
 }
 bool looks_like_hashed_password(const char *s);
+int test_password_one(const char *hashed_password, const char *password);
+int test_password_many(char **hashed_password, const char *password);