From 296bdc5df65e753c96666507cee1f3bcff1b89d3 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 27 Aug 2015 16:12:46 +0300 Subject: [PATCH] Fixed errors and added comments. --- server/core/dbusers.c | 40 ++++++++++++++++++++++------------------ server/core/monitor.c | 4 +++- server/core/service.c | 2 +- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/server/core/dbusers.c b/server/core/dbusers.c index 724381313..e8f38ab13 100644 --- a/server/core/dbusers.c +++ b/server/core/dbusers.c @@ -2322,6 +2322,8 @@ int add_wildcard_users(USERS *users, char* name, char* host, char* password, cha * SHOW DATABASES permissions. If permissions are not adequate, an error message * is logged. * @param service Service to inspect + * @return True if service permissions are correct. False if one or more permissions + * are missing or if an error occurred. */ bool check_service_permissions(SERVICE* service) { @@ -2394,19 +2396,20 @@ bool check_service_permissions(SERVICE* service) service->name,mysql_error(mysql)); } } - - if((res = mysql_use_result(mysql)) == NULL) + else { - skygw_log_write(LE,"%s: Error: Result retrieval failed when checking for" - " permissions to the mysql.user table: %s", + if((res = mysql_use_result(mysql)) == NULL) + { + skygw_log_write(LE,"%s: Error: Result retrieval failed when checking for" + " permissions to the mysql.user table: %s", service->name,mysql_error(mysql)); - mysql_close(mysql); - free(dpasswd); - return rval; + mysql_close(mysql); + free(dpasswd); + return rval; + } + + mysql_free_result(res); } - - mysql_free_result(res); - if(mysql_query(mysql,"SELECT user, host, db FROM mysql.db limit 1") != 0) { if(mysql_errno(mysql) == ER_TABLEACCESS_DENIED_ERROR) @@ -2421,17 +2424,18 @@ bool check_service_permissions(SERVICE* service) service->name,mysql_error(mysql)); } } - - if((res = mysql_use_result(mysql)) == NULL) - { - skygw_log_write(LE,"%s: Error: Result retrieval failed when checking for permissions to the mysql.db table: %s", - service->name,mysql_error(mysql)); - } else { - mysql_free_result(res); + if((res = mysql_use_result(mysql)) == NULL) + { + skygw_log_write(LE,"%s: Error: Result retrieval failed when checking for permissions to the mysql.db table: %s", + service->name,mysql_error(mysql)); + } + else + { + mysql_free_result(res); + } } - mysql_close(mysql); free(dpasswd); return rval; diff --git a/server/core/monitor.c b/server/core/monitor.c index f0a004086..52d4c5f28 100644 --- a/server/core/monitor.c +++ b/server/core/monitor.c @@ -455,6 +455,8 @@ int *data; * Check if the monitor user has all required permissions to operate properly. * this checks for REPLICATION CLIENT permissions * @param service Monitor to inspect + * @return False if an error with monitor permissions was detected or if an + * error occurred. True if permissions are correct. */ bool check_monitor_permissions(MONITOR* monitor) { @@ -499,7 +501,7 @@ bool check_monitor_permissions(MONITOR* monitor) if(mysql_errno(mysql) == ER_SPECIFIC_ACCESS_DENIED_ERROR) { skygw_log_write(LE,"%s: Error: User '%s' is missing REPLICATION CLIENT privileges. MySQL error message: %s", - monitor->name,mysql_error(mysql)); + monitor->name,user,mysql_error(mysql)); rval = false; } else diff --git a/server/core/service.c b/server/core/service.c index b5a0066e5..cc31fcfa1 100644 --- a/server/core/service.c +++ b/server/core/service.c @@ -421,7 +421,7 @@ int listeners = 0; if(!check_service_permissions(service)) { skygw_log_write_flush(LE, - "%s: Inadequate user permissions for service. Service not started.", + "%s: Error: Inadequate user permissions for service. Service not started.", service->name); service->state = SERVICE_STATE_FAILED; return 0;