Code cleanup

Code cleanup
This commit is contained in:
MassimilianoPinto
2014-09-30 13:19:03 +02:00
parent 5f6d04e7db
commit c3dd8d973a

View File

@ -1348,14 +1348,15 @@ int gw_find_mysql_user_password_sha1(char *username, uint8_t *gateway_password,
key.user, key.user,
dcb->remote))); dcb->remote)));
/* look for user@current_host now */ /* look for user@current_ipv4 now */
user_password = mysql_users_fetch(service->users, &key); user_password = mysql_users_fetch(service->users, &key);
if (!user_password) { if (!user_password) {
/* The user is not authenticated @ current host */ /* The user is not authenticated @ current IPv4 */
/* 1) Check for localhost first. while (1) {
* The check for localhost is 127.0.0.1 (IPv4 only) /*
* (1) Check for localhost first: 127.0.0.1 (IPv4 only)
*/ */
if ((key.ipv4.sin_addr.s_addr == 0x0100007F) && !dcb->service->localhost_match_wildcard_host) { if ((key.ipv4.sin_addr.s_addr == 0x0100007F) && !dcb->service->localhost_match_wildcard_host) {
@ -1368,57 +1369,48 @@ int gw_find_mysql_user_password_sha1(char *username, uint8_t *gateway_password,
key.user, key.user,
dcb->remote))); dcb->remote)));
return 1; break;
} }
/* /*
* 2) try class C,B,A * (2) check for possible IPv4 class C,B,A networks
*/ */
// Class C /* Class C check */
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);
if (user_password) { if (user_password) {
if (strlen(user_password))
gw_hex2bin(gateway_password, user_password, SHA_DIGEST_LENGTH * 2);
fprintf(stderr, "+++ Matched Class C for %s\n", dcb->remote); fprintf(stderr, "+++ Matched Class C for %s\n", dcb->remote);
return 0; break;
} }
// Class B /* Class B check */
key.ipv4.sin_addr.s_addr &= 0x0000FFFF; key.ipv4.sin_addr.s_addr &= 0x0000FFFF;
user_password = mysql_users_fetch(service->users, &key); user_password = mysql_users_fetch(service->users, &key);
if (user_password) { if (user_password) {
if (strlen(user_password))
gw_hex2bin(gateway_password, user_password, SHA_DIGEST_LENGTH * 2);
fprintf(stderr, "++ Matched Class B for %s\n", dcb->remote); fprintf(stderr, "++ Matched Class B for %s\n", dcb->remote);
return 0; break;
} }
// Class A /* Class A check */
key.ipv4.sin_addr.s_addr &= 0x000000FF; key.ipv4.sin_addr.s_addr &= 0x000000FF;
user_password = mysql_users_fetch(service->users, &key); user_password = mysql_users_fetch(service->users, &key);
if (user_password) { if (user_password) {
if (strlen(user_password))
gw_hex2bin(gateway_password, user_password, SHA_DIGEST_LENGTH * 2);
fprintf(stderr, "+ Matched Class A for %s\n", dcb->remote); fprintf(stderr, "+ Matched Class A for %s\n", dcb->remote);
return 0; break;
} }
/* 3) Continue and check for wildcard host, user@% /*
* Return 1 if no match * (3) Continue check for wildcard host, user@%
*/ */
memset(&key.ipv4, 0, sizeof(struct sockaddr_in)); memset(&key.ipv4, 0, sizeof(struct sockaddr_in));
@ -1434,9 +1426,10 @@ 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) {
/* the user@% was not found. /*
* Return 1 * the user@% has not been found.
*/ */
LOGIF(LD, LOGIF(LD,
(skygw_log_write_flush( (skygw_log_write_flush(
LOGFILE_DEBUG, LOGFILE_DEBUG,
@ -1444,14 +1437,18 @@ int gw_find_mysql_user_password_sha1(char *username, uint8_t *gateway_password,
pthread_self(), pthread_self(),
key.user, key.user,
dcb->remote))); dcb->remote)));
return 1; break;
} }
fprintf(stderr, "%% Matched ANY for %s\n", dcb->remote); fprintf(stderr, "%% Matched ANY for %s\n", dcb->remote);
break;
}
} }
/* user@host found: now check the password /* If user@host has been found we get the the password in binary format*/
* if (user_password) {
/*
* Convert the hex data (40 bytes) to binary (20 bytes). * Convert the hex data (40 bytes) to binary (20 bytes).
* The gateway_password represents the SHA1(SHA1(real_password)). * The gateway_password represents the SHA1(SHA1(real_password)).
* Please note: the real_password is unknown and SHA1(real_password) is unknown as well * Please note: the real_password is unknown and SHA1(real_password) is unknown as well
@ -1461,6 +1458,9 @@ int gw_find_mysql_user_password_sha1(char *username, uint8_t *gateway_password,
gw_hex2bin(gateway_password, user_password, SHA_DIGEST_LENGTH * 2); gw_hex2bin(gateway_password, user_password, SHA_DIGEST_LENGTH * 2);
return 0; return 0;
} else {
return 1;
}
} }
/** /**