Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-20435

ALTER USER prints bad error message if specified user account does not exist

Details

    Description

      GRANT prints a very nice error message if the specified user account does not exist and sql_mode has NO_AUTO_CREATE_USER set. In contrast, ALTER USER prints a generic error message, so the root cause can be difficult to determine in some cases.

      GRANT:

      MariaDB [(none)]> CREATE USER IF NOT EXISTS 'testuser'@'127.0.0.1' IDENTIFIED BY 'Pa$swd123';
      Query OK, 0 rows affected (0.001 sec)
       
      MariaDB [(none)]> GRANT SELECT ON *.* TO 'testuserr'@'127.0.0.1';
      ERROR 1133 (28000): Can't find any matching row in the user table
      

      ALTER USER:

      MariaDB [(none)]> CREATE USER IF NOT EXISTS 'testuser'@'127.0.0.1' IDENTIFIED BY 'Pa$swd123';
      Query OK, 0 rows affected (0.001 sec)
       
      MariaDB [(none)]> ALTER USER 'testuserr'@'127.0.0.1' IDENTIFIED VIA ed25519 USING PASSWORD('Pa$swd123');
      ERROR 1396 (HY000): Operation ALTER USER failed for 'testuserr'@'127.0.0.1'
      

      I think that ALTER USER's error message should be similar to the one used by GRANT in this case.

      Attachments

        Issue Links

          Activity

            robertbindar Robert Bindar added a comment - serg can you please review https://github.com/MariaDB/server/commit/d87e079c4350ee0cdc8f80522b9c35c57c0c5928 ?

            I think it went a bit off. See how wrong_users is used — there are lots of commands that accept a list of users. They all (but not GRANT) print something at the end. This doesn't work very well when many users are specified. Consider GRANT ROLE for example:

            create user foo@bar;
            create role role1;
            error 1133;
            GRANT role1 TO foo1@bar, foo@bar, foo2@bar;
            show warnings;
            show grants for foo@bar;
            drop role role1;
            drop user foo@bar;
            

            The error and SHOW WARNINGS are:

            GRANT role1 TO foo1@bar, foo@bar, foo2@bar;
            ERROR 28000: Can't find any matching row in the user table
            show warnings;
            Level   Code    Message
            Error   1133    Can't find any matching row in the user table
            Error   1133    Can't find any matching row in the user table
            Error   1961    Cannot grant role 'role1' to: 'foo1'@'bar','foo2'@'bar'
            

            I'd think the error should've been 1961, and two 1133 should be in SHOW WARNINGS only.
            On the other hand, when there's only one user specified, it's probably more user-friendly to report 1133 as an error and no 1961 at all.
            Then the fix should cover all commands that accept many users, basically everything that uses grant_list rule in the parser. And the behavior for them all should be consistent: for one user only report the specific error, for many users do thd->clear_error() and report the generic error with the list.

            GeoffMontee what do you think?

            serg Sergei Golubchik added a comment - I think it went a bit off. See how wrong_users is used — there are lots of commands that accept a list of users. They all (but not GRANT) print something at the end. This doesn't work very well when many users are specified. Consider GRANT ROLE for example: create user foo@bar; create role role1; error 1133; GRANT role1 TO foo1@bar, foo@bar, foo2@bar; show warnings; show grants for foo@bar; drop role role1; drop user foo@bar; The error and SHOW WARNINGS are: GRANT role1 TO foo1@bar, foo@bar, foo2@bar; ERROR 28000: Can't find any matching row in the user table show warnings; Level Code Message Error 1133 Can't find any matching row in the user table Error 1133 Can't find any matching row in the user table Error 1961 Cannot grant role 'role1' to: 'foo1'@'bar','foo2'@'bar' I'd think the error should've been 1961, and two 1133 should be in SHOW WARNINGS only. On the other hand, when there's only one user specified, it's probably more user-friendly to report 1133 as an error and no 1961 at all. Then the fix should cover all commands that accept many users, basically everything that uses grant_list rule in the parser. And the behavior for them all should be consistent: for one user only report the specific error, for many users do thd->clear_error() and report the generic error with the list. GeoffMontee what do you think?

            Hi serg,

            Your suggestion sounds reasonable to me. Thanks!

            GeoffMontee Geoff Montee (Inactive) added a comment - Hi serg , Your suggestion sounds reasonable to me. Thanks!

            People

              cvicentiu Vicențiu Ciorbaru
              GeoffMontee Geoff Montee (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.