Revert r4101 - instead, do a FLUSH PRIVILEGES when the user manager dialog is opened, to ensure that non-flushed users can be edited. Users with uppercase chars in their host name cannot be edited - disable such nodes with a hint on how to manually fix that.

This commit is contained in:
Ansgar Becker
2012-03-27 23:17:20 +00:00
parent 2c1d6808c1
commit 269d3a0791

View File

@@ -154,7 +154,6 @@ type
FUsers: TUserList;
FModified, FAdded: Boolean;
CloneGrants: TStringList;
FFocusedUserGrants: TStringList;
FPrivObjects: TPrivObjList;
PrivsGlobal, PrivsDb, PrivsTable, PrivsRoutine, PrivsColumn: TStringList;
FConnection: TDBConnection;
@@ -301,6 +300,7 @@ begin
// Load user@host list
try
FConnection.Query('FLUSH PRIVILEGES');
Users := FConnection.GetResults(
'SELECT '+FConnection.QuoteIdent('user')+', '+FConnection.QuoteIdent('host')+', '+FConnection.QuoteIdent('password')+' '+
'FROM '+FConnection.QuoteIdent('mysql')+'.'+FConnection.QuoteIdent('user')
@@ -412,33 +412,10 @@ end;
procedure TUserManagerForm.listUsersFocusChanging(Sender: TBaseVirtualTree; OldNode,
NewNode: PVirtualNode; OldColumn, NewColumn: TColumnIndex; var Allowed: Boolean);
var
User: PUser;
Msg: String;
begin
// Allow selecting a user? Also, set allowed to false if new node is the same as
// the old one, otherwise OnFocusChanged will be triggered.
Allowed := (NewNode <> OldNode) and (not Assigned(NewNode) or (not (vsDisabled in NewNode.States)));
if Allowed and (not FAdded) and Assigned(NewNode) then begin
// Check grants before node has focus. Could be a non-yet flushed user which throws
// "There is no such grant defined for user"
// when firing SHOW GRANTS. See http://www.heidisql.com/forum.php?t=10364
User := Sender.GetNodeData(NewNode);
try
FFocusedUserGrants := FConnection.GetCol('SHOW GRANTS FOR '+esc(User.Username)+'@'+esc(User.Host));
except
on E:EDatabaseError do begin
Allowed := False;
Include(NewNode.States, vsDisabled);
Msg := FConnection.LastError;
if FConnection.LastErrorCode = 1141 then
Msg := Msg + CRLF + CRLF + 'You need to run FLUSH PRIVILEGES before you can edit this user.';
MessageDialog(Msg, mtError, [mbOK]);
end;
end;
end;
if Allowed and FModified then begin
case MessageDialog('Save modified user?', mtConfirmation, [mbYes, mbNo, mbCancel]) of
mrYes: begin
@@ -510,7 +487,7 @@ begin
Grants.Add('GRANT USAGE ON *.* TO '+UserHost);
end;
end else
Grants := FFocusedUserGrants;
Grants := FConnection.GetCol('SHOW GRANTS FOR '+esc(User.Username)+'@'+esc(User.Host));
{ GRANT USAGE ON *.* TO 'newbie'@'%' IDENTIFIED BY PASSWORD '*99D8973ECC09819DF81624F051BFF4FC6695140B' REQUIRE (NONE | ssl_option [[AND] ssl_option] ...) WITH GRANT OPTION
GRANT SELECT ON `avtoserver`.* TO 'newbie'@'%'
@@ -798,7 +775,9 @@ begin
Msg := '';
if Assigned(Node) then begin
User := Sender.GetNodeData(Node);
case Length(User.Password) of
if User.Host <> LowerCase(User.Host) then begin
Msg := 'This user is broken due to uppercase characters in its hostname. Please fix that in the mysql.user table.';
end else case Length(User.Password) of
0: Msg := 'This user has an empty password.';
16, 41: Msg := '';
else Msg := 'This user is inactive due to an invalid length of its encrypted password. Please fix that in the mysql.user table.';
@@ -822,7 +801,7 @@ var
begin
User := Sender.GetNodeData(Node);
User^ := FUsers[Node.Index];
if not (Length(User.Password) in [0, 16, 41]) then
if (not (Length(User.Password) in [0, 16, 41])) or (LowerCase(User.Host) <> User.Host) then
Include(InitialStates, ivsDisabled);
end;