From 8957cbc53f721786e4b4db674597f79e838186d0 Mon Sep 17 00:00:00 2001 From: "C. McEnroe" Date: Mon, 4 Nov 2019 17:27:13 -0500 Subject: Hash client passwords with crypt --- client.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'client.c') diff --git a/client.c b/client.c index c951590..35faa4b 100644 --- a/client.c +++ b/client.c @@ -25,6 +25,7 @@ #include #include #include +#include enum Need { NeedNick = 1 << 0, @@ -96,7 +97,7 @@ static void passRequired(struct Client *client) { client->error = true; } -static void sync(struct Client *client) { +static void maybeSync(struct Client *client) { if (client->need == NeedPass) passRequired(client); if (!client->need) stateSync(client); } @@ -106,7 +107,7 @@ typedef void Handler(struct Client *client, struct Message *msg); static void handleNick(struct Client *client, struct Message *msg) { (void)msg; client->need &= ~NeedNick; - sync(client); + maybeSync(client); } static void handleUser(struct Client *client, struct Message *msg) { @@ -119,17 +120,21 @@ static void handleUser(struct Client *client, struct Message *msg) { } else { client->need &= ~NeedUser; client->consumer = ringConsumer(msg->params[0]); - sync(client); + maybeSync(client); } } static void handlePass(struct Client *client, struct Message *msg) { if (!clientPass) return; - if (!msg->params[0] || strcmp(msg->params[0], clientPass)) { + if (!msg->params[0]) { passRequired(client); - } else { + return; + } + if (!strcmp(crypt(msg->params[0], clientPass), clientPass)) { client->need &= ~NeedPass; - sync(client); + maybeSync(client); + } else { + passRequired(client); } } @@ -139,7 +144,7 @@ static void handleCap(struct Client *client, struct Message *msg) { if (!strcmp(msg->params[0], "END")) { if (!client->need) return; client->need &= ~NeedCapEnd; - sync(client); + maybeSync(client); } else if (!strcmp(msg->params[0], "LS")) { if (client->need) client->need |= NeedCapEnd; -- cgit 1.4.1