commit e12e2ca1cf331ae974595b0cf09c71d4abcfb2a9
parent f8a0ff0167a6856bf549cc4959ab41b33e95d34e
Author: hhvn <dev@hhvn.uk>
Date: Sat, 23 Apr 2022 19:15:27 +0100
Support passwords
Diffstat:
5 files changed, 32 insertions(+), 13 deletions(-)
diff --git a/src/commands.c b/src/commands.c
@@ -464,6 +464,7 @@ command_connect) {
char *nick = NULL;
char *username = NULL;
char *realname = NULL;
+ char *password = NULL;
int tls = -1, tls_verify = -1; /* tell serv_update not to change */
int ret;
struct passwd *user;
@@ -472,6 +473,7 @@ command_connect) {
opt_nick,
opt_username,
opt_realname,
+ opt_password,
#ifdef TLS
opt_tls,
opt_tls_verify,
@@ -488,6 +490,9 @@ command_connect) {
{"real", CMD_ARG, opt_realname},
{"comment", CMD_ARG, opt_realname},
+ {"pass", CMD_ARG, opt_password},
+ {"password", CMD_ARG, opt_password},
+ {"auth", CMD_ARG, opt_password},
#ifdef TLS
{"tls", CMD_NARG, opt_tls},
{"ssl", CMD_NARG, opt_tls},
@@ -512,6 +517,9 @@ command_connect) {
case opt_realname:
realname = command_optarg;
break;
+ case opt_password:
+ password = command_optarg;
+ break;
#ifdef TLS
case opt_tls:
tls = 1;
@@ -537,7 +545,7 @@ command_connect) {
tserver = server;
}
if (server) {
- serv_update(tserver, nick, username, realname, tls, tls_verify);
+ serv_update(tserver, nick, username, realname, password, tls, tls_verify);
serv_connect(tserver);
}
return;
@@ -566,7 +574,8 @@ command_connect) {
port = "6667";
}
- tserver = serv_add(&servers, network, host, port, nick, username, realname, tls, tls_verify);
+ tserver = serv_add(&servers, network, host, port, nick,
+ username, realname, password, tls, tls_verify);
serv_connect(tserver);
if (!nouich)
ui_select(tserver, NULL);
diff --git a/src/data/commands.h b/src/data/commands.h
@@ -148,7 +148,8 @@ struct Command commands[] = {
"but will hide it unless this command is used.", NULL}},
{"connect", command_connect, 0, {
"usage: /connect [-network <name>] [-nick <nick>] [-user <user>]",
- " [-real <comment>] [-tls] [-verify] [host] [port]",
+ " [-real <comment>] [-pass <password]",
+ " [-tls] [-verify] [host] [port]",
"Connect to a network/server.",
"If no host is given, it will attempt to connect to the\n",
"selected server if it is disconnected\n",
diff --git a/src/hirc.h b/src/hirc.h
@@ -117,12 +117,12 @@ void serv_connect(struct Server *server);
void serv_read(struct Server *sp);
int serv_write(struct Server *server, char *format, ...);
struct Server * serv_create(char *name, char *host, char *port, char *nick,
- char *username, char *realname, int tls, int tls_verify);
+ char *username, char *realname, char *password, int tls, int tls_verify);
void serv_update(struct Server *sp, char *nick, char *username,
- char *realname, int tls, int tls_verify);
+ char *realname, char *password, int tls, int tls_verify);
struct Server * serv_get(struct Server **head, char *name);
-struct Server * serv_add(struct Server **head, char *name, char *host,
- char *port, char *nick, char *username, char *realname, int tls, int tls_verify);
+struct Server * serv_add(struct Server **head, char *name, char *host, char *port, char *nick,
+ char *username, char *realname, char *password, int tls, int tls_verify);
int serv_len(struct Server **head);
int serv_poll(struct Server **head, int timeout);
int serv_remove(struct Server **head, char *name);
diff --git a/src/serv.c b/src/serv.c
@@ -41,6 +41,7 @@ serv_free(struct Server *server) {
pfree(&server->name);
pfree(&server->username);
pfree(&server->realname);
+ pfree(&server->password);
pfree(&server->host);
pfree(&server->port);
pfree(&server->rpollfd);
@@ -67,8 +68,8 @@ serv_free(struct Server *server) {
}
struct Server *
-serv_create(char *name, char *host, char *port, char *nick,
- char *username, char *realname, int tls, int tls_verify) {
+serv_create(char *name, char *host, char *port, char *nick, char *username,
+ char *realname, char *password, int tls, int tls_verify) {
struct Server *server;
int i;
@@ -87,6 +88,7 @@ serv_create(char *name, char *host, char *port, char *nick,
server->name = estrdup(name);
server->username = username ? estrdup(username) : NULL;
server->realname = realname ? estrdup(realname) : NULL;
+ server->password = password ? estrdup(password) : NULL;
server->host = estrdup(host);
server->port = estrdup(port);
server->supports = NULL;
@@ -123,7 +125,7 @@ serv_create(char *name, char *host, char *port, char *nick,
void
serv_update(struct Server *sp, char *nick, char *username,
- char *realname, int tls, int tls_verify) {
+ char *realname, char *password, int tls, int tls_verify) {
if (!sp)
return;
if (nick) {
@@ -138,6 +140,10 @@ serv_update(struct Server *sp, char *nick, char *username,
pfree(&sp->realname);
sp->username = estrdup(nick);
}
+ if (password) {
+ pfree(&sp->password);
+ sp->password = estrdup(password);
+ }
#ifdef TLS
if (tls >= 0 && !sp->tls) {
sp->tls = tls;
@@ -152,11 +158,11 @@ serv_update(struct Server *sp, char *nick, char *username,
}
struct Server *
-serv_add(struct Server **head, char *name, char *host, char *port,
- char *nick, char *username, char *realname, int tls, int tls_verify) {
+serv_add(struct Server **head, char *name, char *host, char *port, char *nick,
+ char *username, char *realname, char *password, int tls, int tls_verify) {
struct Server *new, *p;
- if ((new = serv_create(name, host, port, nick, username, realname, tls, tls_verify)) == NULL)
+ if ((new = serv_create(name, host, port, nick, username, realname, password, tls, tls_verify)) == NULL)
return NULL;
if (!*head) {
@@ -321,6 +327,8 @@ serv_connect(struct Server *server) {
freeaddrinfo(ai);
server->connectfail = 0;
+ if (server->password)
+ serv_write(server, "PASS %s\r\n", server->password);
serv_write(server, "NICK %s\r\n", server->self->nick);
serv_write(server, "USER %s * * :%s\r\n",
server->username ? server->username : server->self->nick,
diff --git a/src/struct.h b/src/struct.h
@@ -173,6 +173,7 @@ struct Server {
char *name;
char *username;
char *realname;
+ char *password;
char *host;
char *port;
struct Support *supports;