mirror of
https://github.com/darkk/redsocks.git
synced 2025-08-27 04:05:31 +00:00
Move socks4 & socks5 login/password config syntax check to startup
This commit is contained in:
parent
3c7f635bf3
commit
003765ba98
10
socks4.c
10
socks4.c
@ -52,11 +52,14 @@ const int socks4_status_no_ident = 92;
|
||||
const int socks4_status_fake_ident = 93;
|
||||
|
||||
|
||||
void socks4_client_init(redsocks_client *client)
|
||||
static void socks4_instance_init(redsocks_instance *instance)
|
||||
{
|
||||
if (client->instance->config.password)
|
||||
redsocks_log_error(client, LOG_WARNING, "password is ignored for socks4 connections");
|
||||
if (instance->config.password)
|
||||
log_error(LOG_WARNING, "password <%s> is ignored for socks4 connections", instance->config.password);
|
||||
}
|
||||
|
||||
static void socks4_client_init(redsocks_client *client)
|
||||
{
|
||||
client->state = socks4_new;
|
||||
}
|
||||
|
||||
@ -139,6 +142,7 @@ relay_subsys socks4_subsys =
|
||||
.readcb = socks4_read_cb,
|
||||
.writecb = socks4_write_cb,
|
||||
.init = socks4_client_init,
|
||||
.instance_init = socks4_instance_init,
|
||||
};
|
||||
|
||||
|
||||
|
34
socks5.c
34
socks5.c
@ -61,28 +61,47 @@ const char* socks5_status_to_str(int socks5_status)
|
||||
}
|
||||
}
|
||||
|
||||
int socks5_is_valid_cred(const char *login, const char *password)
|
||||
bool socks5_is_valid_cred(const char *login, const char *password)
|
||||
{
|
||||
if (!login || !password)
|
||||
return 0;
|
||||
return false;
|
||||
if (strlen(login) > 255) {
|
||||
log_error(LOG_WARNING, "Socks5 login can't be more than 255 chars, <%s> is too long", login);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
if (strlen(password) > 255) {
|
||||
log_error(LOG_WARNING, "Socks5 password can't be more than 255 chars, <%s> is too long", password);
|
||||
return 0;
|
||||
return false;
|
||||
}
|
||||
return 1;
|
||||
return true;
|
||||
}
|
||||
|
||||
void socks5_client_init(redsocks_client *client)
|
||||
static void socks5_instance_init(redsocks_instance *instance)
|
||||
{
|
||||
redsocks_config *config = &instance->config;
|
||||
if (config->login || config->password) {
|
||||
bool deauth = false;
|
||||
if (config->login && config->password) {
|
||||
deauth = socks5_is_valid_cred(config->login, config->password);
|
||||
} else {
|
||||
log_error(LOG_WARNING, "Socks5 needs either both login and password or none of them");
|
||||
deauth = true;
|
||||
}
|
||||
if (deauth) {
|
||||
free(config->login);
|
||||
free(config->password);
|
||||
config->login = config->password = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void socks5_client_init(redsocks_client *client)
|
||||
{
|
||||
socks5_client *socks5 = red_payload(client);
|
||||
const redsocks_config *config = &client->instance->config;
|
||||
|
||||
client->state = socks5_new;
|
||||
socks5->do_password = socks5_is_valid_cred(config->login, config->password);
|
||||
socks5->do_password = (config->login && config->password) ? 1 : 0;
|
||||
}
|
||||
|
||||
static struct evbuffer *socks5_mkmethods(redsocks_client *client)
|
||||
@ -317,6 +336,7 @@ relay_subsys socks5_subsys =
|
||||
.readcb = socks5_read_cb,
|
||||
.writecb = socks5_write_cb,
|
||||
.init = socks5_client_init,
|
||||
.instance_init = socks5_instance_init,
|
||||
};
|
||||
|
||||
|
||||
|
2
socks5.h
2
socks5.h
@ -87,7 +87,7 @@ static const int socks5_status_Address_type_not_supported = 8;
|
||||
|
||||
|
||||
const char* socks5_status_to_str(int socks5_status);
|
||||
int socks5_is_valid_cred(const char *login, const char *password);
|
||||
bool socks5_is_valid_cred(const char *login, const char *password);
|
||||
|
||||
struct evbuffer *socks5_mkmethods_plain(int do_password);
|
||||
struct evbuffer *socks5_mkpassword_plain(const char *login, const char *password);
|
||||
|
Loading…
Reference in New Issue
Block a user