Perl CGI PHP 会话权限被拒绝

发布于 2024-12-19 10:22:18 字数 1126 浏览 0 评论 0原文

我正在尝试将 PHP 会话变量放入 Perl CGI 脚本中。我有下面的 perl 代码,它似乎可以让我获取 PHPSESSID,然后将其与存储会话文件的目录一起传递给 PHP::Session。

my $cookie_name='PHPSESSID'; 
my $sess_query = new CGI;
my $session_name = $sess_query->cookie($cookie_name);
my $session = PHP::Session->new($session_name,{save_path =>'/var/lib/php/session/'});

当我收到权限被拒绝错误时,就会出现问题

[Fri Dec 2 16:52:44 2011] upload.cgi: /var/lib/php/session/sess_417ar7qsh4sh853gqs3bj454i5: 权限在 /var/www/html/xxx/upload.cgi 第 22 行被拒绝,引荐来源:。 ..

...第 22 行是上面的 PHP::Session->new 行 代码。

我的 httpd 服务器以用户 apache 身份运行,cgi 脚本由 apache 拥有,/var/lib/php/session/ 中的所有会话文件也是如此,所以我想知道为什么 CGI 不这样做脚本能够读取会话文件。

我在网上读到有人使用 LWP 作为一种解决方法,但这不是我的偏好,因为我觉得这对我所缺少的权限来说是愚蠢的。


更新:添加信息 - 这是会话文件 - 正如您所看到的,会话文件存在并且属于 apache,但 CGI perl 脚本无法读取这些文件:

-rw-------. 1 apache apache   0 Dec  2 16:58 /var/lib/php/session/sess_417ar7qsh4sh853gqs3bj454i5
-rw-------. 1 apache apache 126 Dec  2 16:58 /var/lib/php/session/sess_f39ot5ul3bu55uu7d1rg3aqq02

I'm trying to get PHP session variables into a Perl CGI script. I've got the following perl code below which seems to work in getting me the PHPSESSID which I then pass to the PHP::Session along with the directory where the session files are stored.

my $cookie_name='PHPSESSID'; 
my $sess_query = new CGI;
my $session_name = $sess_query->cookie($cookie_name);
my $session = PHP::Session->new($session_name,{save_path =>'/var/lib/php/session/'});

My problem is occuring when I get a permission denied error

[Fri Dec 2 16:52:44 2011] upload.cgi: /var/lib/php/session/sess_417ar7qsh4sh853gqs3bj454i5: Permission denied at /var/www/html/xxx/upload.cgi line 22, referer:...

The line 22 is the PHP::Session->new line in the above code.

My httpd server is running as user apache and the cgi scripts are owned by apache as are all the sesssion files in /var/lib/php/session/ so I'm wondering why wouldn't the CGI script be able to read the session files.

I read online where one person use LWP as a workaround, but that's not my preference as I feel this is something silly on permissions that I'm missing.


UPDATE: Added info - here are the session files - as you can see the session file exists and is owned by apache, but the CGI perl script can't read these:

-rw-------. 1 apache apache   0 Dec  2 16:58 /var/lib/php/session/sess_417ar7qsh4sh853gqs3bj454i5
-rw-------. 1 apache apache 126 Dec  2 16:58 /var/lib/php/session/sess_f39ot5ul3bu55uu7d1rg3aqq02

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

已下线请稍等 2024-12-26 10:22:18

问题确实是 SELinux...在这种情况下,不是 1 个 AVC 警报,而是 5 个警报 - 与读取目录中的文件所需的每个文件 I/O 操作相对应的一个警报。它们按顺序触发,但可以使用下面的 {} 语法来允许。

这可以通过以下方法解决:

allow httpd_sys_script_t httpd_var_run_t: dir search;
allow httpd_sys_script_t httpd_var_run_t: file { lock read ioctl open getattr};

谈论使用腰带和背带!

感谢您的帮助!

The problem was indeed SELinux...and in this case, not 1 AVC alert, but 5 - one alert corresponding to each file I/O action needed to read a file in the directory. they fire sequentially, but can be allowed using {} syntax below.

this can be solved by:

allow httpd_sys_script_t httpd_var_run_t: dir search;
allow httpd_sys_script_t httpd_var_run_t: file { lock read ioctl open getattr};

Talk about using a belt and suspenders!

Thanks for the help!

R

爱人如己 2024-12-26 10:22:18

...所以我想知道为什么 CGI 脚本无法读取
会话文件。

文档 中,它说:

保存路径

    存储会话文件的目录路径。默认值:/tmp。

我不认为您和这个模块正在考虑相同的会话文件。

...so I'm wondering why wouldn't the CGI script be able to read the
session files.

In the documentation it says:

save_path

    path to directory where session files are stored. default: /tmp.

I don't think you and this module are thinking of the same session files.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文