static void cont_sasl(struct client_data *client, int res) {
if (client->saslusername) {
if (res == 0) {
- copy_strf(&databuf, ":%s 903 * :SASL authentication successful\r\n", hostname), sendbuf(client);
+ rpl_saslsuccess(), sendbuf(client);
client_chghost(client, client->saslusername, 0);
} else {
- copy_strf(&databuf, ":%s 904 * :SASL authentication failed\r\n", hostname), sendbuf(client);
+ err_saslfail(), sendbuf(client);
}
free(client->saslusername);
client->saslusername = 0;
if (!args[0])
return err_needmoreparams(client, command), sendbuf(client), 0;
if (client->username && client->username[0] != '~')
- return copy_strf(&databuf, ":%s 907 * :You have already authenticated using SASL\r\n", hostname), sendbuf(client), 0;
+ return err_saslalready(), sendbuf(client), 0;
if (!(client->umode & UMODE_SECURE))
- return copy_strf(&databuf, ":%s 904 * :SASL authentication failed\r\n", hostname), sendbuf(client), 0;
+ return err_saslfail(), sendbuf(client), 0;
if (client->saslusername)
return 0; // not ideal, but we can't respond to the new message before responding to the old one
if (!client->saslbuf) {
if (strcmp(args[0], "PLAIN") != 0 && strcmp(args[0], "EXTERNAL") != 0)
- return copy_strf(&databuf, ":%s 908 * PLAIN,EXTERNAL :are available SASL mechanisms\r\n", hostname), sendbuf(client), 0;
+ return rpl_saslmechs(), sendbuf(client), 0;
copy_strf(&databuf, ":%s AUTHENTICATE +\r\n", hostname), sendbuf(client);
// RFC 4616 spec says the three parts of the response can be up to 255 bytes long
// That's 255*3 + 2, but we'll add another NUL byte after the pass, so it's 768.
// len < 400 - copy the data, finish
// data is + - don't copy, finish
if (len == 1 && args[0][0] == '*') {
- copy_strf(&databuf, ":%s 906 * :SASL auhtentication aborted\r\n", hostname), sendbuf(client);
+ err_saslaborted(), sendbuf(client);
goto saslcleanup;
}
if (len != 1 || args[0][0] != '+') {
if (len > 400 || client->saslbufLen + len > 1024) {
memset(args[0], 0, len);
if (len > 400)
- copy_strf(&databuf, ":%s 905 * :SASL message too long\r\n", hostname), sendbuf(client);
+ err_sasltoolong(), sendbuf(client);
else
- copy_strf(&databuf, ":%s 904 * :SASL authentication failed\r\n", hostname), sendbuf(client);
+ err_saslfail(), sendbuf(client);
goto saslcleanup;
}
memcpy(client->saslbuf + client->saslbufLen, args[0], len);
#endif
}
if (res != -1) {
- copy_strf(&databuf, ":%s 903 * :SASL authentication successful\r\n", hostname), sendbuf(client);
+ rpl_saslsuccess(), sendbuf(client);
client_chghost(client, username, 0);
} else {
saslerr:
- copy_strf(&databuf, ":%s 904 * :SASL authentication failed\r\n", hostname), sendbuf(client);
+ err_saslfail(), sendbuf(client);
}
saslcleanup:
memset(client->saslbuf, 0, 1024);
if (client->regstate != REG_INIT || !client->nick_reg || !client->username || client->passwait || client->webircwait || client->saslusername)
return;
if (client->saslbuf) {
- copy_strf(&databuf, ":%s 906 * :SASL auhtentication aborted\r\n", hostname), sendbuf(client);
+ err_saslaborted(), sendbuf(client);
if (client->saslbuf) {
memset(client->saslbuf, 0, 1024);
free(client->saslbuf);
// notify the user of their new account name, and update the +r mode
if (willbeloggedin) {
if (newusername)
- copy_strf(&databuf, ":%s 900 %s %s %s :You are now logged in as %s\r\n",
- hostname, client->nick ? client->nick : "*", client->nuh, client->username, client->username), sendbuf(client);
+ rpl_loggedin(client), sendbuf(client);
client->umode |= UMODE_REGISTERED;
} else {
if (wasloggedin)
- copy_strf(&databuf, ":%s 901 %s %s :You are now logged out\r\n",
- hostname, client->nick ? client->nick : "*", client->nuh), sendbuf(client);
+ rpl_loggedout(client), sendbuf(client);
client->umode &= ~UMODE_REGISTERED;
}
if (is_registered(client) && wasloggedin != willbeloggedin)
{
copy_strf(&databuf, ":%s 734 %s %d %s :Monitor list is full.\r\n", hostname, client->nick, limit, targets);
}
-// 900 RPL_LOGGEDIN
-// 901 RPL_LOGGEDOUT
+void rpl_loggedin(struct client_data *client) // 900
+{
+ copy_strf(&databuf, ":%s 900 %s %s %s :You are now logged in as %s\r\n",
+ hostname, client->nick ? client->nick : "*", client->nuh, client->username, client->username);
+}
+void rpl_loggedout(struct client_data *client) // 901
+{
+ copy_strf(&databuf, ":%s 901 %s %s :You are now logged out\r\n",
+ hostname, client->nick ? client->nick : "*", client->nuh);
+}
// 902 ERR_NICKLOCKED
-// 903 RPL_SASLSUCCESS
-// 904 ERR_SASLFAIL
-// 905 ERR_SASLTOOLONG
-// 906 ERR_SASLABORTED
-// 907 ERR_SASLALREADY
-// 908 RPL_SASLMECHS
+void rpl_saslsuccess(void) // 903
+{
+ copy_strf(&databuf, ":%s 903 * :SASL authentication successful\r\n", hostname);
+}
+void err_saslfail(void) // 904
+{
+ copy_strf(&databuf, ":%s 904 * :SASL authentication failed\r\n", hostname);
+}
+void err_sasltoolong(void) // 905
+{
+ copy_strf(&databuf, ":%s 905 * :SASL message too long\r\n", hostname);
+}
+void err_saslaborted(void) // 906
+{
+ copy_strf(&databuf, ":%s 906 * :SASL auhtentication aborted\r\n", hostname);
+}
+void err_saslalready(void) // 907
+{
+ copy_strf(&databuf, ":%s 907 * :You have already authenticated using SASL\r\n", hostname);
+}
+void rpl_saslmechs(void) // 908
+{
+ copy_strf(&databuf, ":%s 908 * PLAIN,EXTERNAL :are available SASL mechanisms\r\n", hostname);
+}
void rpl_accesslist(struct client_data *client, struct channel *chan, char mode, const char *mask) // 910
{
char modes[2] = {mode,0};