1
0
mirror of https://gitlab.xiph.org/xiph/icecast-server.git synced 2024-12-04 14:46:30 -05:00

Fix relaying to work with new auth scheme.

svn path=/trunk/icecast/; revision=3838
This commit is contained in:
Michael Smith 2002-08-16 14:55:56 +00:00
parent 913ec3481a
commit 121720a4cc
5 changed files with 37 additions and 12 deletions

View File

@ -12,6 +12,7 @@
</limits> </limits>
<source-password>hackme</source-password> <source-password>hackme</source-password>
<relay-password>hackme</relay-password>
<directory> <directory>
<touch-freq>5</touch-freq> <touch-freq>5</touch-freq>
@ -28,6 +29,7 @@
<!--<master-server>127.0.0.1</master-server>--> <!--<master-server>127.0.0.1</master-server>-->
<!--<master-server-port>8001</master-server-port>--> <!--<master-server-port>8001</master-server-port>-->
<!--<master-update-interval>120</master-update-interval>--> <!--<master-update-interval>120</master-update-interval>-->
<!--<master-password>hackme/master-password>-->
<paths> <paths>
<basedir>/usr/local/icecast</basedir> <basedir>/usr/local/icecast</basedir>

View File

@ -14,6 +14,7 @@
#define CONFIG_DEFAULT_HEADER_TIMEOUT 15 #define CONFIG_DEFAULT_HEADER_TIMEOUT 15
#define CONFIG_DEFAULT_SOURCE_TIMEOUT 10 #define CONFIG_DEFAULT_SOURCE_TIMEOUT 10
#define CONFIG_DEFAULT_SOURCE_PASSWORD "changeme" #define CONFIG_DEFAULT_SOURCE_PASSWORD "changeme"
#define CONFIG_DEFAULT_RELAY_PASSWORD "changeme"
#define CONFIG_DEFAULT_ICE_LOGIN 0 #define CONFIG_DEFAULT_ICE_LOGIN 0
#define CONFIG_DEFAULT_TOUCH_FREQ 5 #define CONFIG_DEFAULT_TOUCH_FREQ 5
#define CONFIG_DEFAULT_HOSTNAME "localhost" #define CONFIG_DEFAULT_HOSTNAME "localhost"
@ -69,6 +70,8 @@ void config_shutdown(void)
xmlFree(c->admin); xmlFree(c->admin);
if (c->source_password && c->source_password != CONFIG_DEFAULT_SOURCE_PASSWORD) if (c->source_password && c->source_password != CONFIG_DEFAULT_SOURCE_PASSWORD)
xmlFree(c->source_password); xmlFree(c->source_password);
if (c->relay_password && c->relay_password != CONFIG_DEFAULT_SOURCE_PASSWORD)
xmlFree(c->relay_password);
if (c->hostname && c->hostname != CONFIG_DEFAULT_HOSTNAME) if (c->hostname && c->hostname != CONFIG_DEFAULT_HOSTNAME)
xmlFree(c->hostname); xmlFree(c->hostname);
if (c->base_dir && c->base_dir != CONFIG_DEFAULT_BASE_DIR) if (c->base_dir && c->base_dir != CONFIG_DEFAULT_BASE_DIR)
@ -157,6 +160,7 @@ static void _set_defaults(void)
_configuration.header_timeout = CONFIG_DEFAULT_HEADER_TIMEOUT; _configuration.header_timeout = CONFIG_DEFAULT_HEADER_TIMEOUT;
_configuration.source_timeout = CONFIG_DEFAULT_SOURCE_TIMEOUT; _configuration.source_timeout = CONFIG_DEFAULT_SOURCE_TIMEOUT;
_configuration.source_password = CONFIG_DEFAULT_SOURCE_PASSWORD; _configuration.source_password = CONFIG_DEFAULT_SOURCE_PASSWORD;
_configuration.relay_password = CONFIG_DEFAULT_RELAY_PASSWORD;
_configuration.ice_login = CONFIG_DEFAULT_ICE_LOGIN; _configuration.ice_login = CONFIG_DEFAULT_ICE_LOGIN;
_configuration.touch_freq = CONFIG_DEFAULT_TOUCH_FREQ; _configuration.touch_freq = CONFIG_DEFAULT_TOUCH_FREQ;
_configuration.dir_list = NULL; _configuration.dir_list = NULL;
@ -166,6 +170,7 @@ static void _set_defaults(void)
_configuration.master_server = NULL; _configuration.master_server = NULL;
_configuration.master_server_port = CONFIG_DEFAULT_PORT; _configuration.master_server_port = CONFIG_DEFAULT_PORT;
_configuration.master_update_interval = CONFIG_MASTER_UPDATE_INTERVAL; _configuration.master_update_interval = CONFIG_MASTER_UPDATE_INTERVAL;
_configuration.master_password = NULL;
_configuration.base_dir = CONFIG_DEFAULT_BASE_DIR; _configuration.base_dir = CONFIG_DEFAULT_BASE_DIR;
_configuration.log_dir = CONFIG_DEFAULT_LOG_DIR; _configuration.log_dir = CONFIG_DEFAULT_LOG_DIR;
_configuration.webroot_dir = CONFIG_DEFAULT_WEBROOT_DIR; _configuration.webroot_dir = CONFIG_DEFAULT_WEBROOT_DIR;
@ -202,6 +207,9 @@ static void _parse_root(xmlDocPtr doc, xmlNodePtr node)
if (_configuration.source_password && _configuration.source_password != CONFIG_DEFAULT_SOURCE_PASSWORD) xmlFree(_configuration.source_password); if (_configuration.source_password && _configuration.source_password != CONFIG_DEFAULT_SOURCE_PASSWORD) xmlFree(_configuration.source_password);
_configuration.source_password = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); _configuration.source_password = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
} }
} else if (strcmp(node->name, "relay-password") == 0) {
if (_configuration.relay_password && _configuration.relay_password != CONFIG_DEFAULT_RELAY_PASSWORD) xmlFree(_configuration.relay_password);
_configuration.relay_password = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
} else if (strcmp(node->name, "icelogin") == 0) { } else if (strcmp(node->name, "icelogin") == 0) {
tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
_configuration.ice_login = atoi(tmp); _configuration.ice_login = atoi(tmp);
@ -219,6 +227,9 @@ static void _parse_root(xmlDocPtr doc, xmlNodePtr node)
} else if (strcmp(node->name, "master-server") == 0) { } else if (strcmp(node->name, "master-server") == 0) {
if (_configuration.master_server) xmlFree(_configuration.master_server); if (_configuration.master_server) xmlFree(_configuration.master_server);
_configuration.master_server = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); _configuration.master_server = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
} else if (strcmp(node->name, "master-password") == 0) {
if (_configuration.master_password) xmlFree(_configuration.master_password);
_configuration.master_password = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
} else if (strcmp(node->name, "master-server-port") == 0) { } else if (strcmp(node->name, "master-server-port") == 0) {
tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1); tmp = (char *)xmlNodeListGetString(doc, node->xmlChildrenNode, 1);
_configuration.master_server_port = atoi(tmp); _configuration.master_server_port = atoi(tmp);

View File

@ -27,6 +27,7 @@ typedef struct ice_config_tag
int ice_login; int ice_login;
char *source_password; char *source_password;
char *relay_password;
int touch_freq; int touch_freq;
ice_config_dir_t *dir_list; ice_config_dir_t *dir_list;
@ -37,6 +38,7 @@ typedef struct ice_config_tag
char *master_server; char *master_server;
int master_server_port; int master_server_port;
int master_update_interval; int master_update_interval;
char *master_password;
char *base_dir; char *base_dir;
char *log_dir; char *log_dir;

View File

@ -337,7 +337,7 @@ fail:
return 0; return 0;
} }
static int _check_source_pass_http(http_parser_t *parser) static int _check_source_pass_http(http_parser_t *parser, char *correctuser)
{ {
/* This will look something like "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" */ /* This will look something like "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==" */
char *header = httpp_getvar(parser, "authorization"); char *header = httpp_getvar(parser, "authorization");
@ -368,7 +368,7 @@ static int _check_source_pass_http(http_parser_t *parser)
username = userpass; username = userpass;
password = tmp+1; password = tmp+1;
if(strcmp(username, "source") || strcmp(password, correctpass)) { if(strcmp(username, correctuser) || strcmp(password, correctpass)) {
free(userpass); free(userpass);
return 0; return 0;
} }
@ -393,12 +393,12 @@ static int _check_source_pass_ice(http_parser_t *parser)
return 1; return 1;
} }
static int _check_source_pass(http_parser_t *parser) static int _check_source_pass(http_parser_t *parser, char *user)
{ {
if(config_get_config()->ice_login) if(config_get_config()->ice_login)
return _check_source_pass_ice(parser); return _check_source_pass_ice(parser);
else else
return _check_source_pass_http(parser); return _check_source_pass_http(parser, user);
} }
static void _handle_source_request(connection_t *con, static void _handle_source_request(connection_t *con,
@ -411,8 +411,8 @@ static void _handle_source_request(connection_t *con,
INFO1("Source logging in at mountpoint \"%s\"", uri); INFO1("Source logging in at mountpoint \"%s\"", uri);
stats_event_inc(NULL, "source_connections"); stats_event_inc(NULL, "source_connections");
if (!_check_source_pass(parser)) { if (!_check_source_pass(parser, "source")) {
INFO1("Source (%s) attempted to login with bad password", uri); INFO1("Source (%s) attempted to login with invalid or missing password", uri);
client_send_401(client); client_send_401(client);
return; return;
} }
@ -442,7 +442,7 @@ static void _handle_stats_request(connection_t *con,
stats_event_inc(NULL, "stats_connections"); stats_event_inc(NULL, "stats_connections");
if (!_check_source_pass(parser)) { if (!_check_source_pass(parser, "stats")) {
ERROR0("Bad password for stats connection"); ERROR0("Bad password for stats connection");
connection_close(con); connection_close(con);
httpp_destroy(parser); httpp_destroy(parser);
@ -486,8 +486,8 @@ static void _handle_get_request(connection_t *con,
*/ */
/* TODO: add GUID-xxxxxx */ /* TODO: add GUID-xxxxxx */
if (strcmp(uri, "/stats.xml") == 0) { if (strcmp(uri, "/stats.xml") == 0) {
if (!_check_source_pass(parser)) { if (!_check_source_pass(parser, "stats")) {
INFO1("Source (%s) attempted to login with bad password", uri); INFO0("Request for stats.xml with incorrect or no password");
client_send_401(client); client_send_401(client);
return; return;
} }
@ -548,7 +548,7 @@ static void _handle_get_request(connection_t *con,
} }
if (strcmp(uri, "/allstreams.txt") == 0) { if (strcmp(uri, "/allstreams.txt") == 0) {
if (!_check_source_pass(parser)) { if (!_check_source_pass(parser, "relay")) {
INFO0("Client attempted to fetch allstreams.txt with bad password"); INFO0("Client attempted to fetch allstreams.txt with bad password");
client_send_401(client); client_send_401(client);
} else { } else {

View File

@ -72,6 +72,9 @@ static void *_slave_thread(void *arg) {
http_parser_t *parser; http_parser_t *parser;
client_t *client; client_t *client;
int interval = config_get_config()->master_update_interval; int interval = config_get_config()->master_update_interval;
char *authheader, *data;
int len;
char *username = "relay";
while (_initialized) { while (_initialized) {
if (config_get_config()->master_update_interval > ++interval) { if (config_get_config()->master_update_interval > ++interval) {
@ -86,8 +89,15 @@ static void *_slave_thread(void *arg) {
WARN0("Relay slave failed to contact master server to fetch stream list"); WARN0("Relay slave failed to contact master server to fetch stream list");
continue; continue;
} }
// FIXME: This is now broken...
sock_write(mastersock, "GET /allstreams.txt HTTP/1.0\r\nice-password: %s\r\n\r\n", config_get_config()->source_password); len = strlen(username) + strlen(config_get_config()->master_password) + 1;
authheader = malloc(len+1);
strcpy(authheader, username);
strcat(authheader, ":");
strcat(authheader, config_get_config()->master_password);
data = util_base64_encode(authheader);
sock_write(mastersock, "GET /allstreams.txt HTTP/1.0\r\nAuthorization: Basic %s\r\n\r\n", data);
free(data);
while (sock_read_line(mastersock, buf, sizeof(buf))) { while (sock_read_line(mastersock, buf, sizeof(buf))) {
buf[strlen(buf)] = 0; buf[strlen(buf)] = 0;
avl_tree_rlock(global.source_tree); avl_tree_rlock(global.source_tree);