<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: suexec code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sat, 17 May 2008 08:44:53 GMT</pubDate>
    <description>DZone Snippets: suexec code</description>
    <item>
      <title>runas - Run a program under a specific user / group (poor man's suexec)</title>
      <link>http://snippets.dzone.com/posts/show/5344</link>
      <description>&lt;code&gt;#!/usr/bin/env ruby&lt;br /&gt;&lt;br /&gt;# runas - Run another program under the privileges of a specified user and group.&lt;br /&gt;# This is necessary because sudo demands a password, as we need it to be hands off.&lt;br /&gt;# A poor man's suexec basically.&lt;br /&gt;&lt;br /&gt;require 'etc'&lt;br /&gt;&lt;br /&gt;user, group, cmd = ARGV&lt;br /&gt;&lt;br /&gt;begin&lt;br /&gt;  uid = Etc.getpwnam(user).uid&lt;br /&gt;  gid = Etc.getgrnam(group).gid&lt;br /&gt;&lt;br /&gt;  unless Process.euid == uid &amp;&amp; Process.egid == gid&lt;br /&gt;    Process.initgroups(user, gid)&lt;br /&gt;    Process::GID.change_privilege(gid)&lt;br /&gt;    Process::UID.change_privilege(uid)&lt;br /&gt;  end&lt;br /&gt;&lt;br /&gt;  exec cmd&lt;br /&gt;rescue&lt;br /&gt;  puts "Could not run as #{user}:#{group}"&lt;br /&gt;  exit 1&lt;br /&gt;end&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Usage example: ./runas username groupname "sleep 10"</description>
      <pubDate>Thu, 10 Apr 2008 08:07:10 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/5344</guid>
      <author>peter (Peter Cooperx)</author>
    </item>
    <item>
      <title>Suexec'ed PHP-FastCGI on Apache2</title>
      <link>http://snippets.dzone.com/posts/show/81</link>
      <description>A PHP cgi binary compiled with fcgi support&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&gt; /usr/local/www/cgi-bin/php5-fcgi -v&lt;br /&gt;PHP 5.0.3 (cgi-fcgi) (built: Dec 30 2004 22:44:32)&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;Central config in httpd.conf&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;&lt;IfModule mod_fastcgi.c&gt;&lt;br /&gt;FastCgiIpcDir /usr/local/www/fcgi_ipc/tmp&lt;br /&gt;AddHandler fastcgi-script .fcgi&lt;br /&gt;FastCgiSuexec /usr/local/sbin/suexec&lt;br /&gt;FastCgiConfig -singleThreshold 100 -killInterval 300 -autoUpdate -idle-timeout 240 -pass-header HTTP_AUTHORIZATION&lt;br /&gt;&lt;/IfModule&gt;&lt;br /&gt;&lt;Location /php-fastcgi/&gt;&lt;br /&gt;Options ExecCGI        &lt;br /&gt;SetHandler fastcgi-script&lt;br /&gt;&lt;/Location&gt;&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;In a virtual host&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;SuexecUserGroup ${USER} ${GROUP}&lt;br /&gt;ScriptAlias /php-fastcgi/ ${HOME}/php-fastcgi/ &lt;br /&gt;AddType application/x-httpd-fastphp .php&lt;br /&gt;Action application/x-httpd-fastphp /php-fastcgi/php5-fcgi&lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;And then the ${HOME}/php-fastcgi/php5-fcgi wrapper	&lt;br /&gt;&lt;br /&gt;&lt;code&gt;&lt;br /&gt;#!/bin/sh &lt;br /&gt;PHPRC="/usr/local/etc" &lt;br /&gt;export PHPRC &lt;br /&gt;PHP_FCGI_CHILDREN=8 &lt;br /&gt;export PHP_FCGI_CHILDREN &lt;br /&gt;PHP_FCGI_MAX_REQUESTS=5000 &lt;br /&gt;export PHP_FCGI_MAX_REQUESTS &lt;br /&gt;exec /usr/local/www/cgi-bin/php5-fcgi &lt;br /&gt;&lt;/code&gt;&lt;br /&gt;&lt;br /&gt;The PHPRC environment sets the directory where php.ini is to be found</description>
      <pubDate>Fri, 08 Apr 2005 19:18:10 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/81</guid>
      <author>jason (Jason Hoffman)</author>
    </item>
  </channel>
</rss>
