robin
robin

Reputation: 19

Lua script to stop firing a query in mysql via mysql proxy

I am a beginner to lua language.The main concept is when a user fire the DROP TABLE command in mysql it should not be executed.But he can fire all other commands as usual in mysql.But i don't want to use GRANTS for this.Is there any luaScript to perform this action via mysql-proxy?

For example:

mysql> DROP TABLE T1;
Please wait for authentication

Also is LuaSql helpful to perform this task via mysql-proxy?

Hope i made the idea clear.Someone help me solve out this issue.Thanks in advance.

Upvotes: 1

Views: 317

Answers (1)

Sim
Sim

Reputation: 4188

Yes, you can do that. The idea here is to check a query whether or not it fulfills the requirements you want to filter and if so NOT sending it to the server

function read_query(packet)
        if string.byte(packet) == proxy.COM_QUERY then
                query = packet:sub(2)
                if condition(query) then
                   proxy.response = {
                           type = proxy.MYSQLD_PACKET_OK,
                   }
                   return proxy.PROXY_SEND_RESULT
                end
        end
end

This checks each query the proxy receives for condition and if it matches it will just return a SUCCESS to the client without delivering the query. Thus effectively dropping the query.

Upvotes: 0

Related Questions