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

Add a data type for privileges

    XMLWordPrintable

Details

    Description

      As of version 10.5.1, we pass all constants like SELECT_ACL, CREATE_ALC, SUPER_ACL, etc, and their bit-OR combinations using "uint" variables all around the code.

      Under terms of MENT-595, we'll add more privileges, so the uint storage won't be enough, so the code needs to be changed to be ulonglong-compatible.

      Instead of simply changing uint to ulonglong, let's introduce a enum to store privilege bits:

      enum privilege_t: unsigned long long
      {
        NO_ACL                = (0),
        SELECT_ACL            = (1UL << 0),
        INSERT_ACL            = (1UL << 1),
        UPDATE_ACL            = (1UL << 2),
        DELETE_ACL            = (1UL << 3),
        CREATE_ACL            = (1UL << 4),
        DROP_ACL              = (1UL << 5),
        RELOAD_ACL            = (1UL << 6),
        SHUTDOWN_ACL          = (1UL << 7),
        PROCESS_ACL           = (1UL << 8),
        FILE_ACL              = (1UL << 9),
        GRANT_ACL             = (1UL << 10),
        REFERENCES_ACL        = (1UL << 11),
        INDEX_ACL             = (1UL << 12),
        ALTER_ACL             = (1UL << 13),
        SHOW_DB_ACL           = (1UL << 14),
        SUPER_ACL             = (1UL << 15),
        CREATE_TMP_ACL        = (1UL << 16),
        LOCK_TABLES_ACL       = (1UL << 17),
        EXECUTE_ACL           = (1UL << 18),
        REPL_SLAVE_ACL        = (1UL << 19),
        REPL_CLIENT_ACL       = (1UL << 20),
        CREATE_VIEW_ACL       = (1UL << 21),
        SHOW_VIEW_ACL         = (1UL << 22),
        CREATE_PROC_ACL       = (1UL << 23),
        ALTER_PROC_ACL        = (1UL << 24),
        CREATE_USER_ACL       = (1UL << 25),
        EVENT_ACL             = (1UL << 26),
        TRIGGER_ACL           = (1UL << 27),
        CREATE_TABLESPACE_ACL = (1UL << 28),
        DELETE_HISTORY_ACL    = (1UL << 29),
        ALL_KNOWN_ACL         = (1UL << 30) - 1 // A combination of all defined bits
      };
      

      To avoid changes in the code, let's define bit-AND, bit-OR operators for the new data type:

      static inline constexpr privilege_t operator&(privilege_t a, privilege_t b)
      {
        return static_cast<privilege_t>(static_cast<ulonglong>(a) &
                                        static_cast<ulonglong>(b));
      }
      

      Attachments

        Issue Links

          Activity

            People

              bar Alexander Barkov
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

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