is it possible execute a perl script with admin rights or as a specific user?

本秂侑毒 提交于 2019-12-11 05:29:30

问题


I'm writing a perl script in which I've to shutdown my mssql server ,do some operation and then I've to restart it.I know 1 way is to use netstat to stopt the service but I cann't use that. So I tried installing DBI and DBD::ODBC module. More info here :Shutdown MSSQL server from perl script DBI But when I trying to shutdown my server using this command

$dbh->prepare("SHUTDOWN WITH NOWAIT ");

It's not working for me : I got this response from the community

SHUTDOWN permissions are assigned to members of the sysadmin and serveradmin fixed server roles, and they are not transferable. I'd consider it unlike(hopefully) that perl is run with this rights.

So please tell me is there a way to run the above command as these users ? or what can I do other than this . Note that I have a constraint tha tI cann't simply stop it as windows service.


回答1:


If the scripts are executed through a web browser then the user executing the scripts will be defined by the web server. It will probably not be a good idea to fiddle with this user. Just leave things as they are.

What you can do is to create a Perl script that is being run by a privileged user on a consistent basis with CRON.

This script being run by CRON can check for specific content like a file which has been written by a script where the user executing the script has lesser privileges.

So the way it could work is as follows:

  1. You execute browser.cgi through a browser to do a specific task.

  2. browser.cgi writes instructions to a file.

  3. Every 1 minute priveleged.cgi executes via CRON. (The root user could execute priveleged.cgi)

  4. priveleged.cgi reads the file browser.cgi has written for instructions and starts and stops services according to the instructions.



来源:https://stackoverflow.com/questions/16396077/is-it-possible-execute-a-perl-script-with-admin-rights-or-as-a-specific-user

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!