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 单通道放大电路的工作原理
  • ¥30 YOLO检测微调结果p为1
  • ¥20 求快手直播间榜单匿名采集ID用户名简单能学会的
  • ¥15 DS18B20内部ADC模数转换器
  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题