]> jfr.im git - solanum.git/blobdiff - tools/mkpasswd.c
Merge pull request #351 from ophion-project/upstream/sasl
[solanum.git] / tools / mkpasswd.c
index 8762255e2796c6b8a12fc8060205b3e23cac30d8..8b8c96c186f6adb2fa2a67fb021c38d08418c904 100644 (file)
@@ -38,12 +38,11 @@ static char *make_sha512_salt(int);
 static char *make_sha512_salt_para(char *);
 static char *make_bf_salt(int, int);
 static char *make_bf_salt_para(int, char *);
-static char *int_to_base64(int);
 static char *generate_random_salt(char *, int);
 static char *generate_poor_salt(char *, int);
 
-static void full_usage(void);
-static void brief_usage(void);
+static void full_usage(void) __attribute__((noreturn));
+static void brief_usage(void) __attribute__((noreturn));
 
 static char saltChars[] = "./0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
        /* 0 .. 63, ascii - 64 */
@@ -91,7 +90,7 @@ main(int argc, char *argv[])
        int c;
        char *saltpara = NULL;
        char *salt;
-       char *hashed;
+       char *hashed, *hashed2;
        int flag = 0;
        int length = 0;         /* Not Set */
        int rounds = 0;         /* Not set, since blowfish needs 4 by default, a side effect
@@ -195,10 +194,24 @@ main(int argc, char *argv[])
        }
        else
        {
-               hashed = strdup(rb_crypt(getpass("plaintext: "), salt));
+               plaintext = getpass("plaintext: ");
+               hashed = rb_crypt(plaintext, salt);
+               if (!hashed)
+               {
+                       fprintf(stderr, "rb_crypt() failed\n");
+                       return 1;
+               }
+               hashed = strdup(hashed);
+
                plaintext = getpass("again: ");
+               hashed2 = rb_crypt(plaintext, salt);
+               if (!hashed2)
+               {
+                       fprintf(stderr, "rb_crypt() failed\n");
+                       return 1;
+               }
 
-               if (strcmp(rb_crypt(plaintext, salt), hashed) != 0)
+               if (strcmp(hashed, hashed2) != 0)
                {
                        fprintf(stderr, "Passwords do not match\n");
                        return 1;
@@ -209,24 +222,6 @@ main(int argc, char *argv[])
        return 0;
 }
 
-char *
-int_to_base64(int value)
-{
-       static char buf[5];
-       int i;
-
-       for(i = 0; i < 4; i++)
-       {
-               buf[i] = saltChars[value & 63];
-               value >>= 6;    /* Right shifting 6 places is the same as dividing by 64 */
-       }
-
-       buf[i] = '\0';          /* not REALLY needed as it's static, and thus initialized
-                                ** to \0.
-                                */
-       return buf;
-}
-
 char *
 make_md5_salt_para(char *saltpara)
 {