working on oauth
This commit is contained in:
parent
31089e909c
commit
433485e07c
@ -85,6 +85,7 @@ LOW_DEFAULT_PORTS_BOUNDARY,HIGH_DEFAULT_PORTS_BOUNDARY,0,0,0,"",
|
||||
0,NULL,0,NULL,DEFAULT_GENERAL_RELAY_SERVERS_NUMBER,0,
|
||||
////////////// Auth server /////////////////////////////////////
|
||||
{NULL,NULL,NULL,0,NULL},
|
||||
"",
|
||||
/////////////// AUX SERVERS ////////////////
|
||||
{NULL,0,{0,NULL}},0,
|
||||
/////////////// ALTERNATE SERVERS ////////////////
|
||||
@ -1556,7 +1557,7 @@ static int adminmain(int argc, char **argv)
|
||||
static void print_features(unsigned long mfn)
|
||||
{
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "\nRFC 3489/5389/5766/5780/6062/6156 STUN/TURN Server\nVersion %s\n",TURN_SOFTWARE);
|
||||
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "Server name: %s\n",turn_params.oauth_server_name);
|
||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_INFO, "\nMax number of open files/sockets allowed for this process: %lu\n",mfn);
|
||||
if(turn_params.net_engine_version == 1)
|
||||
mfn = mfn/3;
|
||||
@ -1678,6 +1679,16 @@ static void drop_privileges(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void init_oauth_server_name(void) {
|
||||
struct utsname name;
|
||||
if(!uname(&name)) {
|
||||
STRCPY(turn_params.oauth_server_name,name.nodename);
|
||||
}
|
||||
if(!turn_params.oauth_server_name[0]) {
|
||||
STRCPY(turn_params.oauth_server_name,TURN_SOFTWARE);
|
||||
}
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
int c = 0;
|
||||
@ -1703,6 +1714,7 @@ int main(int argc, char **argv)
|
||||
init_listener();
|
||||
init_secrets_list(&turn_params.default_users_db.ram_db.static_auth_secrets);
|
||||
init_dynamic_ip_lists();
|
||||
init_oauth_server_name();
|
||||
|
||||
if (!strstr(argv[0], "turnadmin")) {
|
||||
|
||||
|
||||
@ -51,6 +51,7 @@
|
||||
#include <sys/time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/resource.h>
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#include <pwd.h>
|
||||
#include <grp.h>
|
||||
@ -65,8 +66,6 @@
|
||||
#include <openssl/crypto.h>
|
||||
#include <openssl/opensslv.h>
|
||||
|
||||
#include <sys/utsname.h>
|
||||
|
||||
#include "ns_turn_utils.h"
|
||||
#include "ns_turn_khash.h"
|
||||
|
||||
@ -272,6 +271,7 @@ typedef struct _turn_params_ {
|
||||
////////////// Auth server ////////////////
|
||||
|
||||
struct auth_server authserver;
|
||||
char oauth_server_name[1025];
|
||||
|
||||
/////////////// AUX SERVERS ////////////////
|
||||
|
||||
|
||||
@ -1797,4 +1797,23 @@ void init_listener(void)
|
||||
ns_bzero(&turn_params.listener,sizeof(struct listener_server));
|
||||
}
|
||||
|
||||
void get_oauth_server_name(const char* realm, char *server_name, size_t server_name_size)
|
||||
{
|
||||
if(server_name && server_name_size) {
|
||||
strncpy(server_name,turn_params.oauth_server_name,server_name_size);
|
||||
if(realm && realm[0]) {
|
||||
char* sat = strstr(server_name,"@");
|
||||
if(sat) {
|
||||
*sat = 0;
|
||||
}
|
||||
size_t snl = strlen(server_name);
|
||||
size_t rl = strlen(realm);
|
||||
if(snl+1+rl<server_name_size) {
|
||||
strncpy(server_name+snl,"@",1);
|
||||
strncpy(server_name+snl+1,realm,rl+1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
///////////////////////////////
|
||||
|
||||
@ -265,6 +265,8 @@ void get_realm_options_by_name(char *realm, realm_options_t* ro);
|
||||
int get_canonic_origin(const char* o, char *co, int sz);
|
||||
int get_default_protocol_port(const char* scheme, size_t slen);
|
||||
|
||||
void get_oauth_server_name(const char* realm, char *server_name, size_t server_name_size);
|
||||
|
||||
///////////////////////////////////////
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
||||
@ -150,7 +150,7 @@ static int inc_quota(ts_ur_super_session* ss, u08bits *username)
|
||||
if(ss && !(ss->quota_used) && ss->server && ((turn_turnserver*)ss->server)->chquotacb && username) {
|
||||
|
||||
if(((turn_turnserver*)ss->server)->ct == TURN_CREDENTIALS_LONG_TERM) {
|
||||
if(!(ss->realm_set)) {
|
||||
if(!(ss->origin_set)) {
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
@ -3483,7 +3483,7 @@ static int handle_turn_command(turn_turnserver *server, ts_ur_super_session *ss,
|
||||
}
|
||||
|
||||
/* check that the realm is the same as in the original request */
|
||||
if(ss->realm_set) {
|
||||
if(ss->origin_set) {
|
||||
stun_attr_ref sar = stun_attr_get_first_str(ioa_network_buffer_data(in_buffer->nbh),
|
||||
ioa_network_buffer_get_size(in_buffer->nbh));
|
||||
|
||||
@ -3540,7 +3540,7 @@ static int handle_turn_command(turn_turnserver *server, ts_ur_super_session *ss,
|
||||
}
|
||||
|
||||
/* get the initial origin value */
|
||||
if(!err_code && !(ss->realm_set) && (method == STUN_METHOD_ALLOCATE)) {
|
||||
if(!err_code && !(ss->origin_set) && (method == STUN_METHOD_ALLOCATE)) {
|
||||
|
||||
stun_attr_ref sar = stun_attr_get_first_str(ioa_network_buffer_data(in_buffer->nbh),
|
||||
ioa_network_buffer_get_size(in_buffer->nbh));
|
||||
@ -3571,7 +3571,7 @@ static int handle_turn_command(turn_turnserver *server, ts_ur_super_session *ss,
|
||||
ioa_network_buffer_get_size(in_buffer->nbh), sar);
|
||||
}
|
||||
|
||||
ss->realm_set = 1;
|
||||
ss->origin_set = 1;
|
||||
}
|
||||
|
||||
if(!err_code && !(*resp_constructed) && !no_response) {
|
||||
|
||||
@ -101,7 +101,7 @@ struct _ts_ur_super_session {
|
||||
char s_mobile_id[33];
|
||||
/* Realm */
|
||||
realm_options_t realm_options;
|
||||
int realm_set;
|
||||
int origin_set;
|
||||
s08bits origin[STUN_MAX_ORIGIN_SIZE + 1];
|
||||
/* Bandwidth */
|
||||
band_limit_t bps;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user