Match Class C,B,A addresses

Match Class C,B,A addresses
This commit is contained in:
MassimilianoPinto
2014-09-29 12:08:10 +02:00
parent a11303bd58
commit 76320c056b
2 changed files with 46 additions and 12 deletions

View File

@ -333,7 +333,7 @@ getUsers(SERVICE *service, struct users *users)
continue; continue;
} }
/* handle ANY, Class C */ /* handle ANY, Class C,B,A */
/* if host == '%', 0 serv_addrkeeps its 0 */ /* if host == '%', 0 serv_addrkeeps its 0 */
if (strcmp(row[1], "%") == 0) { if (strcmp(row[1], "%") == 0) {
@ -342,12 +342,24 @@ getUsers(SERVICE *service, struct users *users)
} else { } else {
char *tmp; char *tmp;
strcpy(ret_ip, row[1]); strcpy(ret_ip, row[1]);
if ((tmp = strrchr(ret_ip, '%')) != NULL) { tmp = ret_ip+strlen(ret_ip);
// found class C
found_range = 1; while(tmp) {
// set fake 1 if (tmp == %) {
*tmp = '1'; /* set last byte only to 1
* avoiding setipadress failure
* for Class C address
*/
if (found_range == 1)
*tmp = 1;
else
*tmp = 0;
found_range++;
} }
tmp--;
}
} }
if (setipaddress(&serv_addr.sin_addr, ret_ip)) { if (setipaddress(&serv_addr.sin_addr, ret_ip)) {
@ -355,7 +367,7 @@ getUsers(SERVICE *service, struct users *users)
memcpy(&key.ipv4, &serv_addr, sizeof(serv_addr)); memcpy(&key.ipv4, &serv_addr, sizeof(serv_addr));
if (found_range) { if (found_range) {
/* let's zero the last IP byte: a.b.c.0 */ /* let's zero the last IP byte: a.b.c.0 we set above to 1*/
key.ipv4.sin_addr.s_addr &= 0x00FFFFFF; key.ipv4.sin_addr.s_addr &= 0x00FFFFFF;
} }

View File

@ -1350,7 +1350,6 @@ int gw_find_mysql_user_password_sha1(char *username, uint8_t *gateway_password,
user_password = mysql_users_fetch(service->users, &key); user_password = mysql_users_fetch(service->users, &key);
if (!user_password) { if (!user_password) {
int lastbyte=0;
/* The user is not authenticated @ current host */ /* The user is not authenticated @ current host */
/* 1) Check for localhost first. /* 1) Check for localhost first.
@ -1371,11 +1370,10 @@ int gw_find_mysql_user_password_sha1(char *username, uint8_t *gateway_password,
} }
/* /*
* 2) try class C * 2) try class C,B,A
* continue to wildcard if no match
*/ */
lastbyte = key.ipv4.sin_addr.s_addr & 0xFF000000;
// Class C
key.ipv4.sin_addr.s_addr &= 0x00FFFFFF; key.ipv4.sin_addr.s_addr &= 0x00FFFFFF;
user_password = mysql_users_fetch(service->users, &key); user_password = mysql_users_fetch(service->users, &key);
@ -1387,6 +1385,30 @@ int gw_find_mysql_user_password_sha1(char *username, uint8_t *gateway_password,
return 0; return 0;
} }
// Class B
key.ipv4.sin_addr.s_addr &= 0x0000FFFF;
user_password = mysql_users_fetch(service->users, &key);
if (user_password) {
if (strlen(user_password))
gw_hex2bin(gateway_password, user_password, SHA_DIGEST_LENGTH * 2);
return 0;
}
// Class A
key.ipv4.sin_addr.s_addr &= 0x000000FF;
user_password = mysql_users_fetch(service->users, &key);
if (user_password) {
if (strlen(user_password))
gw_hex2bin(gateway_password, user_password, SHA_DIGEST_LENGTH * 2);
return 0;
}
/* 3) Continue and check for wildcard host, user@% /* 3) Continue and check for wildcard host, user@%
* Return 1 if no match * Return 1 if no match
*/ */