SQL-сервер выполняется как ошибки разрешения в триггере

Как насчет следующего:

if find /some/dir/ -maxdepth 0 -empty | read v; then echo "Empty dir"; fi

Таким образом, там не является никакая потребность в генерации полного списка содержания каталога. Эти read должен и отбросить вывод и заставить выражение оценить к истинному только, когда что-то читается (т.е. /some/dir/ найден пустым find).

10
задан Josh 27 February 2013 в 15:49
поделиться

3 ответа

Это связано с областью действия от имени пользователя - переключение контекста на пользователя уровня базы данных по умолчанию ограничено только этой базой данных (а приведенный выше код выполняется вне данной базы данных через базу данных msdb), и аутентификатор только для базы данных недействителен. По ссылке выше вы найдете несколько вариантов решения / временного решения.

16
ответ дан 3 December 2019 в 16:10
поделиться

The triggers's EXECUTE AS is the same as EXECUTE AS USER = '...', not the same as EXECUTE AS LOGIN = '...'. chadhoc already pointed out the link to the EXECUTE AS impersonation context and its constraints. Basically, because the trigger's EXECUTE AS clause is guaranteed by dbo, not by sysadmin, it is trusted only inside the context of the database.

There are two alternatives:

  1. The one size fits all sledgehammer: ALTER DATABASE SET TRUSTWORTHY ON;. This will elevate mark the database as trusted and the execution context can go outside the database, if the loggin that owns the database has the propper rights. This is not recommended on a highly secured environement as it opens the doors to various elevation of priviledges if not properly constrained, and is very difficult to properly constrain.

  2. The surgical precission option: code signing. See Call a procedure in another database from an activated procedure for an example. This is not for the faint of heart, it involves several complex steps: generate a certificate, sign the procedure, drop the private key, copy the certificate into msdb, create an user derived from the certificate in msdb, grant authenticate database on the certificate derived user, grante EXECUTE on sp_send_mail on the certificate derived user. Any mistake at any of these steps will render the whole sequence useless so is very easy to screw it up, but the result is absolute bulletproof from a security point of view.

10
ответ дан 3 December 2019 в 16:10
поделиться

Отправлять электронное письмо с помощью триггера - плохая идея. Ты не Я хочу, чтобы не было возможности вносить изменения в данные, если почтовый сервер не работает.

Лучше отправить информацию для электронного письма в другую таблицу, которая затем отправляет электронное письмо из периодически выполняемого задания. Один, который работает, скажем, каждые пять минут.

Есть еще кое-что, называемое Service Broker, которое я раньше не использовал, что может помочь в этой задаче, вы можете взглянуть на это.

0
ответ дан 3 December 2019 в 16:10
поделиться
Другие вопросы по тегам:

Похожие вопросы: