« Email threads algorithm - 邮件线索排序算法 | Main | Bookmark system - 几个不错的书签系统 »

版权声明:可以任意转载,转载时请务必以超链接形式标明文章原始出处和作者信息及本声明。
本文网址:http://www.hzqbbc.com/blog/arch/2005/10/setenv_fail_in.html
 

October 21, 2005

SetEnv fail in Suexec - Suexec下setenv失效

有时候,最不起眼的问题却最耗时间。

早上10点多想起还没完成ExtMail的0.19 release中计划要增加的功能:per domain template , 于是开始动手。

本来是一个非常简单的功能,几行code就搞定,利用的是Apache等webserver的SetEnv,将特定信息导入环境变量中,谁知道怪事发生了。

在httpd.conf中,有如下的配置:

SetEnv EXTMAIL_TEMPLDIR "/var/www/extmail/newhtml"

可是在perl代码里,却死活没办法通过访问$ENV{'EXTMAIL_TEMPLDIR'}来获得这个值。

开始有点怀疑是不是自己写错了,查了一下Apache的docs,看看配置指令有没问题,可又没发现问题。又在google上到处搜索,甚至搜索到了perl的beginner 的邮件列表,可是所有有关的问题都几乎是一样的答案,通过SetEnv传递环境变量。

后来,忽然想起自己的extmail是工作在SuExec+SELinux双重保护的环境里,会不会因为这个原因导致了自定义的环境变量被屏蔽掉?

于是做了一个试验,关闭了Suexec,结果就成功了。于是还是老老实实的仔细看Apache手册的env模块,才发现了根源:

Some Caveats

It is not possible to override or change the standard CGI variables using the environment manipulation directives.

When suexec is used to launch CGI scripts, the environment will be cleaned down to a set of safe variables before CGI scripts are launched. The list of safe variables is defined at compile-time in suexec.c.

For portability reasons, the names of environment variables may contain only letters, numbers, and the underscore character. In addition, the first character may not be a number. Characters which do not match this restriction will be replaced by an underscore when passed to CGI scripts and SSI pages.

第二段就写得很清晰,“the environment will be cleaned down to a set of safe variables before CGI scripts are launched.”。

只怪当时心切没耐着性子看,当时也没联想到Suexec的问题。

知道这个问题的根源以后,设计又可以继续下去

Posted by hzqbbc at October 21, 2005 02:32 PM

Comments

Post a comment




Remember Me?

(you may use HTML tags for style)