Skip to content

Commit

Permalink
Fix user manager throwing an exception when mysql.user.authentication…
Browse files Browse the repository at this point in the history
…_string is NULL.
  • Loading branch information
stuconnolly committed Mar 21, 2017
1 parent 48fd60c commit 5906a91
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 14 deletions.
6 changes: 3 additions & 3 deletions Source/SPUserManager.h
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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;
Expand Down
36 changes: 25 additions & 11 deletions Source/SPUserManager.m
Expand Up @@ -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];
Expand Down Expand Up @@ -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"];
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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]) {
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1446,9 +1464,6 @@ - (BOOL)_checkAndDisplayMySqlError
return YES;
}

#pragma mark -
#pragma mark Private API

/**
* Renames a user account using the supplied parameters.
*
Expand Down Expand Up @@ -1511,7 +1526,6 @@ - (void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self];


SPClear(managedObjectContext);
SPClear(persistentStoreCoordinator);
SPClear(managedObjectModel);
Expand Down

0 comments on commit 5906a91

Please sign in to comment.