Permalink
Browse files

Fix user manager throwing an exception when mysql.user.authentication…

…_string is NULL.
  • Loading branch information...
stuconnolly committed Mar 21, 2017
1 parent 48fd60c commit 5906a91397ed42e74ab7671c8b1e98fb9bbf8c73
Showing with 28 additions and 14 deletions.
  1. +3 −3 Source/SPUserManager.h
  2. +25 −11 Source/SPUserManager.m
View
@@ -81,7 +81,7 @@
BOOL isInitializing;
NSMutableString *errorsString;
// MySQL 5.7.6 removes the "Password" columns and only uses the "plugin"+"authentication_string" columns
// MySQL 5.7.6 removes the "Password" columns and only uses the "plugin" + "authentication_string" columns
BOOL requiresPost576PasswordHandling;
}
@@ -114,14 +114,14 @@
- (IBAction)closeErrorsSheet:(id)sender;
- (IBAction)doubleClickSchemaPriv:(id)sender;
// Schema Privieges
// Schema privieges
- (IBAction)addSchemaPriv:(id)sender;
- (IBAction)removeSchemaPriv:(id)sender;
// Refresh
- (IBAction)refresh:(id)sender;
// Core Data notifications
// Core data notifications
- (BOOL)insertUser:(SPUserMO *)user;
- (BOOL)deleteUser:(SPUserMO *)user;
- (BOOL)updateUser:(SPUserMO *)user;
View
@@ -221,20 +221,24 @@ - (void)_initializeUsers
*/
- (void)_initializeTree:(NSArray *)items
{
// Retrieve all the user data in order to be able to initialise the schema privs for each child,
// copying into a dictionary keyed by user, each with all the host rows.
NSMutableDictionary *schemaPrivilegeData = [NSMutableDictionary dictionary];
SPMySQLResult *queryResults = [connection queryString:@"SELECT * FROM mysql.db"];
[queryResults setReturnDataAsStrings:YES];
for (NSDictionary *privRow in queryResults) {
for (NSDictionary *privRow in queryResults)
{
if (![schemaPrivilegeData objectForKey:[privRow objectForKey:@"User"]]) {
[schemaPrivilegeData setObject:[NSMutableArray array] forKey:[privRow objectForKey:@"User"]];
}
[[schemaPrivilegeData objectForKey:[privRow objectForKey:@"User"]] addObject:privRow];
// If "all database" values were found, add them to the schemas list if not already present
NSString *schemaName = [privRow objectForKey:@"Db"];
if ([schemaName isEqualToString:@""] || [schemaName isEqualToString:@"%"]) {
if (![schemas containsObject:schemaName]) {
[schemas addObject:schemaName];
@@ -269,11 +273,20 @@ - (void)_initializeTree:(NSArray *)items
// original values for comparison purposes
[parent setPrimitiveValue:username forKey:@"user"];
[parent setPrimitiveValue:username forKey:@"originaluser"];
if(requiresPost576PasswordHandling) {
if (requiresPost576PasswordHandling) {
[parent setPrimitiveValue:[item objectForKey:@"plugin"] forKey:@"plugin"];
NSString *pwHash = [item objectForKey:@"authentication_string"];
[parent setPrimitiveValue:pwHash forKey:@"authentication_string"];
if([pwHash length]) [parent setPrimitiveValue:@"sequelpro_dummy_password" forKey:@"password"]; // for the UI dialog
NSString *passwordHash = [item objectForKey:@"authentication_string"];
if (![passwordHash isNSNull]) {
[parent setPrimitiveValue:passwordHash forKey:@"authentication_string"];
// for the UI dialog
if ([passwordHash length]) {
[parent setPrimitiveValue:@"sequelpro_dummy_password" forKey:@"password"];
}
}
}
else {
[parent setPrimitiveValue:[item objectForKey:@"Password"] forKey:@"password"];
@@ -535,7 +548,6 @@ - (IBAction)doCancel:(id)sender
*/
- (IBAction)doApply:(id)sender
{
// If editing can't be committed, cancel the apply
if (![treeController commitEditing]) {
return;
@@ -953,6 +965,9 @@ - (void)contextDidChange:(NSNotification *)notification
if (!isInitializing) [outlineView reloadData];
}
#pragma mark -
#pragma mark Core data notifications
- (BOOL)updateUser:(SPUserMO *)user
{
if (![user parent]) {
@@ -1290,6 +1305,9 @@ - (BOOL)grantPrivilegesToUser:(SPUserMO *)user skippingRevoke:(BOOL)skipRevoke
return YES;
}
#pragma mark -
#pragma mark Private API
/**
* Gets any NSManagedObject (SPUser) from the managedObjectContext that may
* already exist with the given username.
@@ -1446,9 +1464,6 @@ - (BOOL)_checkAndDisplayMySqlError
return YES;
}
#pragma mark -
#pragma mark Private API
/**
* Renames a user account using the supplied parameters.
*
@@ -1511,7 +1526,6 @@ - (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];
SPClear(managedObjectContext);
SPClear(persistentStoreCoordinator);
SPClear(managedObjectModel);

0 comments on commit 5906a91

Please sign in to comment.