Get CURRENT_USER in a MySQL trigger returns an invalid value

I have an old application (no source code) that connects to a productive MySQL database. For business reasons, we must restrict access to the database. For this reason, I wrote a MySQL trigger that will restrict users who have access to the database based on the identifier.

Users authenticate in the database through the application with their own identifier and their private passwords.

The problem arises inside the trigger: I have a sentence SELECT...WHERE, and the sentence WHEREis:SUBSTRING_INDEX(CURRENT_USER(), @, 1)

Basically, every time a user deletes a specific database / table in an application, I would like to capture this user (which is also displayed in the Processes of MySQL server) and based on the capture execute a SELECTwhich will return a UNIQUE ID for this user. Based on this ID, a check will be performed IF, and access to save data will be granted or revoked.

The problem is that even if I log into the application with User X, the CURRENT_USER()MySQL function somehow captures my domain user no matter what I do. It must capture the user of the domain that is executing this trigger.

Full trigger:

DROP TRIGGER dbname.disable_order_insert_trigger;

DELIMITER $
use dbname$

CREATE TRIGGER disable_order_insert_trigger BEFORE INSERT ON 
dbname.dbtable

FOR EACH ROW
BEGIN
    DECLARE compCode INT unsigned DEFAULT 0;        
    SET @compCode = 1;

    SELECT COMPCODE
    INTO @compCode
    FROM dbname.user_info_table
    WHERE dbname.user_info_table.USERID = SUBSTRING_INDEX(CURRENT_USER(), "@", 1) 
    AND dbname.user_info_table.COMPCODE = 1172 LIMIT 1; 
    SELECT CURRENT_USER() INTO OUTFILE 'C:\\temp\\compCode.txt';

IF @compCode = 1172 THEN 
    CALL something;
END IF;

END;
$
DELIMITER ; 

SHOW TRIGGERS;

MySQL , PC/ OUTFILE . CURRENT_USER() ?

MySQL: 5.1.19-beta-community-nt-debug. Definer , .

+4
1

wchiquto, USER(), CURRENT_USER().

sp, CURRENT_USER() sp define.

+2

Source: https://habr.com/ru/post/1684809/


All Articles