]> jfr.im git - solanum.git/blobdiff - extensions/m_mkpasswd.c
Add .travis.yml
[solanum.git] / extensions / m_mkpasswd.c
index b8fad447cb893369fc1b29ccc6908d14c641a6a6..80fe64f8e7a35bc90d102e610f46d279a4a96488 100644 (file)
@@ -10,6 +10,8 @@
 #include "numeric.h"
 #include "s_conf.h"
 #include "modules.h"
+#include "messages.h"
+#include "send.h"
 
 #include <string.h>
 
@@ -46,6 +48,7 @@ m_mkpasswd(struct Client *client_p, struct Client *source_p, int parc, const cha
 {
        static time_t last_used = 0;
        char *salt;
+       const char *crypted;
        const char *hashtype;
        const char hashdefault[] = "SHA512";
 
@@ -82,7 +85,8 @@ m_mkpasswd(struct Client *client_p, struct Client *source_p, int parc, const cha
                return 0;
        }
 
-       sendto_one_notice(source_p, ":Hash [%s] for %s: %s", hashtype, parv[1], rb_crypt(parv[1], salt));
+       crypted = rb_crypt(parv[1], salt);
+       sendto_one_notice(source_p, ":Hash [%s] for %s: %s", hashtype, parv[1], crypted ? crypted : "???");
        return 0;
 }
 
@@ -94,6 +98,7 @@ static int
 mo_mkpasswd(struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        char *salt;
+       const char *crypted;
        const char *hashtype;
        const char hashdefault[] = "SHA512";
 
@@ -121,7 +126,8 @@ mo_mkpasswd(struct Client *client_p, struct Client *source_p, int parc, const ch
                return 0;
        }
 
-       sendto_one_notice(source_p, ":Hash [%s] for %s: %s", hashtype, parv[1], rb_crypt(parv[1], salt));
+       crypted = rb_crypt(parv[1], salt);
+       sendto_one_notice(source_p, ":Hash [%s] for %s: %s", hashtype, parv[1], crypted ? crypted : "???");
        return 0;
 }
 
@@ -204,6 +210,7 @@ generate_random_salt(char *salt, int length)
        if(read(fd, buf, length) != length)
        {
                free(buf);
+               close(fd);
                return (generate_poor_salt(salt, length));
        }
 
@@ -212,5 +219,6 @@ generate_random_salt(char *salt, int length)
                salt[i] = saltChars[abs(buf[i]) % 64];
        }
        free(buf);
+       close(fd);
        return (salt);
 }