duanmou9228 2013-08-14 06:56
浏览 89
已采纳

将用户权限从PHP / Apache传递到Perl脚本

I am a fairly new PHP coder. I have an Apache server running PHP 4.3.9 on which I am trying to bang up a small tool for our internal users. The tool is structured in the following way: PHP code ---calls---> Perl script ---accesses---> File on a protected file system

When you open up the .php page in the browser, authentication is automatic. It is taken care of in the background by, I believe, LDAP. $_SERVER["PHP_AUTH_USER"] & $_SERVER["PHP_AUTH_PW"] get populated automatically and correctly.

If I run a whoami in my PHP code, then I see the user as 'apache'. So the Perl script is called in the context and with the privileges of user 'apache'. These privileges are used to access the file on the protected file system. 'apache' doesn't have the required privileges to access this file & the Perl script fails. If I SSH to this server and run the Perl script directly on the shell, it works without any problems because it runs under my user privileges.

What I want to do is to run the Perl script with the privileges of the already authenticated user. I can probably figure out a way to just pass $_SERVER["PHP_AUTH_USER"] & $_SERVER["PHP_AUTH_PW"] to the Perl script as an argument and the use it to access the file. I was wondering if there is a better way to do it.

Any recommendations? Thanks in advance!

  • 写回答

1条回答 默认 最新

  • duanchoupo1104 2013-08-14 08:23
    关注

    There's lots of ways to do this - the trick is doing it securely.

    Ultimately the Perl script has to run with a different uid than the webserver. You've not said whether it's practical to change the code of the perl script. Possible solutions are:

    1) amend the Perl script to run as a daemon, allowing socket connections to invoke from your PHP code - since you want to run it potentially as multiple users then it would need to run as root and know how to authenticate the credentials sent to it.

    2) configure sudo on the system to allow the webserver uid to run the Perl script as a different user and prompt for authentication

    3) configure [x]inetd to listen on a specific port and run the script as the desired uid when your PHP code connects - again this needs to start as root, validate the credentials and setuid() but doesn't need to run as a daemon.

    4) use the ssh extensions in PHP to create a ssh connection to localhost as the desired user and run the script

    (I don't see how invoking it via crontab provides for privilege seperation).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘