Skip to content

Commit 5906a91

Browse files
committed
Fix user manager throwing an exception when mysql.user.authentication_string is NULL.
1 parent 48fd60c commit 5906a91

File tree

2 files changed

+28
-14
lines changed

2 files changed

+28
-14
lines changed

Diff for: Source/SPUserManager.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@
8181
BOOL isInitializing;
8282
NSMutableString *errorsString;
8383

84-
// MySQL 5.7.6 removes the "Password" columns and only uses the "plugin"+"authentication_string" columns
84+
// MySQL 5.7.6 removes the "Password" columns and only uses the "plugin" + "authentication_string" columns
8585
BOOL requiresPost576PasswordHandling;
8686
}
8787

@@ -114,14 +114,14 @@
114114
- (IBAction)closeErrorsSheet:(id)sender;
115115
- (IBAction)doubleClickSchemaPriv:(id)sender;
116116

117-
// Schema Privieges
117+
// Schema privieges
118118
- (IBAction)addSchemaPriv:(id)sender;
119119
- (IBAction)removeSchemaPriv:(id)sender;
120120

121121
// Refresh
122122
- (IBAction)refresh:(id)sender;
123123

124-
// Core Data notifications
124+
// Core data notifications
125125
- (BOOL)insertUser:(SPUserMO *)user;
126126
- (BOOL)deleteUser:(SPUserMO *)user;
127127
- (BOOL)updateUser:(SPUserMO *)user;

Diff for: Source/SPUserManager.m

+25-11
Original file line numberDiff line numberDiff line change
@@ -221,20 +221,24 @@ - (void)_initializeUsers
221221
*/
222222
- (void)_initializeTree:(NSArray *)items
223223
{
224-
225224
// Retrieve all the user data in order to be able to initialise the schema privs for each child,
226225
// copying into a dictionary keyed by user, each with all the host rows.
227226
NSMutableDictionary *schemaPrivilegeData = [NSMutableDictionary dictionary];
228227
SPMySQLResult *queryResults = [connection queryString:@"SELECT * FROM mysql.db"];
228+
229229
[queryResults setReturnDataAsStrings:YES];
230-
for (NSDictionary *privRow in queryResults) {
230+
231+
for (NSDictionary *privRow in queryResults)
232+
{
231233
if (![schemaPrivilegeData objectForKey:[privRow objectForKey:@"User"]]) {
232234
[schemaPrivilegeData setObject:[NSMutableArray array] forKey:[privRow objectForKey:@"User"]];
233235
}
236+
234237
[[schemaPrivilegeData objectForKey:[privRow objectForKey:@"User"]] addObject:privRow];
235238

236239
// If "all database" values were found, add them to the schemas list if not already present
237240
NSString *schemaName = [privRow objectForKey:@"Db"];
241+
238242
if ([schemaName isEqualToString:@""] || [schemaName isEqualToString:@"%"]) {
239243
if (![schemas containsObject:schemaName]) {
240244
[schemas addObject:schemaName];
@@ -269,11 +273,20 @@ - (void)_initializeTree:(NSArray *)items
269273
// original values for comparison purposes
270274
[parent setPrimitiveValue:username forKey:@"user"];
271275
[parent setPrimitiveValue:username forKey:@"originaluser"];
272-
if(requiresPost576PasswordHandling) {
276+
277+
if (requiresPost576PasswordHandling) {
273278
[parent setPrimitiveValue:[item objectForKey:@"plugin"] forKey:@"plugin"];
274-
NSString *pwHash = [item objectForKey:@"authentication_string"];
275-
[parent setPrimitiveValue:pwHash forKey:@"authentication_string"];
276-
if([pwHash length]) [parent setPrimitiveValue:@"sequelpro_dummy_password" forKey:@"password"]; // for the UI dialog
279+
280+
NSString *passwordHash = [item objectForKey:@"authentication_string"];
281+
282+
if (![passwordHash isNSNull]) {
283+
[parent setPrimitiveValue:passwordHash forKey:@"authentication_string"];
284+
285+
// for the UI dialog
286+
if ([passwordHash length]) {
287+
[parent setPrimitiveValue:@"sequelpro_dummy_password" forKey:@"password"];
288+
}
289+
}
277290
}
278291
else {
279292
[parent setPrimitiveValue:[item objectForKey:@"Password"] forKey:@"password"];
@@ -535,7 +548,6 @@ - (IBAction)doCancel:(id)sender
535548
*/
536549
- (IBAction)doApply:(id)sender
537550
{
538-
539551
// If editing can't be committed, cancel the apply
540552
if (![treeController commitEditing]) {
541553
return;
@@ -953,6 +965,9 @@ - (void)contextDidChange:(NSNotification *)notification
953965
if (!isInitializing) [outlineView reloadData];
954966
}
955967

968+
#pragma mark -
969+
#pragma mark Core data notifications
970+
956971
- (BOOL)updateUser:(SPUserMO *)user
957972
{
958973
if (![user parent]) {
@@ -1290,6 +1305,9 @@ - (BOOL)grantPrivilegesToUser:(SPUserMO *)user skippingRevoke:(BOOL)skipRevoke
12901305
return YES;
12911306
}
12921307

1308+
#pragma mark -
1309+
#pragma mark Private API
1310+
12931311
/**
12941312
* Gets any NSManagedObject (SPUser) from the managedObjectContext that may
12951313
* already exist with the given username.
@@ -1446,9 +1464,6 @@ - (BOOL)_checkAndDisplayMySqlError
14461464
return YES;
14471465
}
14481466

1449-
#pragma mark -
1450-
#pragma mark Private API
1451-
14521467
/**
14531468
* Renames a user account using the supplied parameters.
14541469
*
@@ -1511,7 +1526,6 @@ - (void)dealloc
15111526
{
15121527
[[NSNotificationCenter defaultCenter] removeObserver:self];
15131528

1514-
15151529
SPClear(managedObjectContext);
15161530
SPClear(persistentStoreCoordinator);
15171531
SPClear(managedObjectModel);

0 commit comments

Comments
 (0)