mirror of
https://github.com/coturn/coturn.git
synced 2025-11-01 23:41:09 +01:00
refactor is_secure_username
This commit is contained in:
parent
5ff0d8b4fa
commit
bb821cee2e
@ -867,11 +867,11 @@ char *turn_strdup_func(const char* s, const char* function, int line) {
|
|||||||
|
|
||||||
////////////////////////////////
|
////////////////////////////////
|
||||||
|
|
||||||
int is_secure_username(const u08bits *username)
|
int is_secure_string(const u08bits *string)
|
||||||
{
|
{
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
if(username) {
|
if(string) {
|
||||||
unsigned char *s0 = (unsigned char*)turn_strdup((const char*)username);
|
unsigned char *s0 = (unsigned char*)turn_strdup((const char*)string);
|
||||||
unsigned char *s = s0;
|
unsigned char *s = s0;
|
||||||
while(*s) {
|
while(*s) {
|
||||||
*s = (unsigned char)tolower((int)*s);
|
*s = (unsigned char)tolower((int)*s);
|
||||||
@ -891,4 +891,3 @@ int is_secure_username(const u08bits *username)
|
|||||||
}
|
}
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////////
|
//////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|||||||
@ -78,7 +78,7 @@ void rollover_logfile(void);
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
|
|
||||||
int is_secure_username(const u08bits *username);
|
int is_secure_string(const u08bits *string);
|
||||||
|
|
||||||
///////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
|||||||
@ -1790,7 +1790,7 @@ static int adminmain(int argc, char **argv)
|
|||||||
#endif
|
#endif
|
||||||
case 'u':
|
case 'u':
|
||||||
STRCPY(user,optarg);
|
STRCPY(user,optarg);
|
||||||
if(!is_secure_username((u08bits*)user)) {
|
if(!is_secure_string((u08bits*)user)) {
|
||||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Wrong user name structure or symbols, choose another name: %s\n",user);
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "Wrong user name structure or symbols, choose another name: %s\n",user);
|
||||||
exit(-1);
|
exit(-1);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1029,7 +1029,7 @@ static int handle_turn_allocate(turn_turnserver *server,
|
|||||||
}
|
}
|
||||||
ns_bcopy(value,username,ulen);
|
ns_bcopy(value,username,ulen);
|
||||||
username[ulen]=0;
|
username[ulen]=0;
|
||||||
if(!is_secure_username(username)) {
|
if(!is_secure_string(username)) {
|
||||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "%s: wrong username: %s\n", __FUNCTION__, (char*)username);
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "%s: wrong username: %s\n", __FUNCTION__, (char*)username);
|
||||||
username[0]=0;
|
username[0]=0;
|
||||||
*err_code = 400;
|
*err_code = 400;
|
||||||
@ -3383,7 +3383,7 @@ static int check_stun_auth(turn_turnserver *server,
|
|||||||
ns_bcopy(stun_attr_get_value(sar),usname,alen);
|
ns_bcopy(stun_attr_get_value(sar),usname,alen);
|
||||||
usname[alen]=0;
|
usname[alen]=0;
|
||||||
|
|
||||||
if(!is_secure_username(usname)) {
|
if(!is_secure_string(usname)) {
|
||||||
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "%s: wrong username: %s\n", __FUNCTION__, (char*)usname);
|
TURN_LOG_FUNC(TURN_LOG_LEVEL_ERROR, "%s: wrong username: %s\n", __FUNCTION__, (char*)usname);
|
||||||
usname[0]=0;
|
usname[0]=0;
|
||||||
*err_code = 400;
|
*err_code = 400;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user