]> jfr.im git - solanum.git/blobdiff - extensions/m_mkpasswd.c
explicitly show IP in SNO_BANNED snotes
[solanum.git] / extensions / m_mkpasswd.c
index 788558f796b6d7e96441cccc45922e1a62e70570..66d7d6b080774f4996c538e909623e5aed476561 100644 (file)
@@ -17,9 +17,9 @@
 
 const char mkpasswd_desc[] = "Hash a password for use in ircd.conf";
 
-static int m_mkpasswd(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
+static void m_mkpasswd(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
                      int parc, const char *parv[]);
-static int mo_mkpasswd(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
+static void mo_mkpasswd(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p,
                       int parc, const char *parv[]);
 
 static char *make_md5_salt(int);
@@ -45,7 +45,7 @@ DECLARE_MODULE_AV2(mkpasswd, NULL, NULL, mkpasswd_clist, NULL, NULL, NULL, NULL,
  *     parv[1] = password
  *     parv[2] = type
  */
-static int
+static void
 m_mkpasswd(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        static time_t last_used = 0;
@@ -57,7 +57,7 @@ m_mkpasswd(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *sour
        if(EmptyString(parv[1]))
        {
                sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MKPASSWD");
-               return 0;
+               return;
        }
 
        if(parc < 3)
@@ -69,7 +69,7 @@ m_mkpasswd(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *sour
        {
                /* safe enough to give this on a local connect only */
                sendto_one(source_p, form_str(RPL_LOAD2HI), me.name, source_p->name, "MKPASSWD");
-               return 0;
+               return;
        }
        else
                last_used = rb_current_time();
@@ -84,19 +84,18 @@ m_mkpasswd(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *sour
        {
                sendto_one_notice(source_p,
                                  ":MKPASSWD syntax error:  MKPASSWD pass [SHA256|SHA512|MD5]");
-               return 0;
+               return;
        }
 
        crypted = rb_crypt(parv[1], salt);
        sendto_one_notice(source_p, ":Hash [%s] for %s: %s", hashtype, parv[1], crypted ? crypted : "???");
-       return 0;
 }
 
 /* mo_mkpasswd - mkpasswd message handler
  *     parv[1] = password
  *     parv[2] = type
  */
-static int
+static void
 mo_mkpasswd(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *source_p, int parc, const char *parv[])
 {
        char *salt;
@@ -107,7 +106,7 @@ mo_mkpasswd(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *sou
        if(EmptyString(parv[1]))
        {
                sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS), me.name, source_p->name, "MKPASSWD");
-               return 0;
+               return;
        }
 
        if(parc < 3)
@@ -125,12 +124,11 @@ mo_mkpasswd(struct MsgBuf *msgbuf_p, struct Client *client_p, struct Client *sou
        {
                sendto_one_notice(source_p,
                                  ":MKPASSWD syntax error:  MKPASSWD pass [SHA256|SHA512|MD5]");
-               return 0;
+               return;
        }
 
        crypted = rb_crypt(parv[1], salt);
        sendto_one_notice(source_p, ":Hash [%s] for %s: %s", hashtype, parv[1], crypted ? crypted : "???");
-       return 0;
 }
 
 char *
@@ -191,36 +189,31 @@ char *
 generate_poor_salt(char *salt, int length)
 {
        int i;
+
        srand(time(NULL));
        for(i = 0; i < length; i++)
-       {
                salt[i] = saltChars[rand() % 64];
-       }
+
        return (salt);
 }
 
 char *
 generate_random_salt(char *salt, int length)
 {
-       char *buf;
        int fd, i;
-       if((fd = open("/dev/random", O_RDONLY)) < 0)
-       {
+
+       if((fd = open("/dev/urandom", O_RDONLY)) < 0)
                return (generate_poor_salt(salt, length));
-       }
-       buf = calloc(1, length);
-       if(read(fd, buf, length) != length)
+
+       if(read(fd, salt, (size_t)length) != length)
        {
-               free(buf);
                close(fd);
                return (generate_poor_salt(salt, length));
        }
 
        for(i = 0; i < length; i++)
-       {
-               salt[i] = saltChars[abs(buf[i]) % 64];
-       }
-       free(buf);
+               salt[i] = saltChars[abs(salt[i]) % 64];
+
        close(fd);
        return (salt);
 }