home *** CD-ROM | disk | FTP | other *** search
/ CD Actual 25 / CDROM25.iso / Share / linux / apache / contrib / modules / mod_setclass.c < prev    next >
Encoding:
C/C++ Source or Header  |  1998-06-11  |  5.8 KB  |  163 lines

  1. /* ====================================================================
  2.  * Copyright (c) 1995-1997 The Apache Group.  All rights reserved.
  3.  *
  4.  * Redistribution and use in source and binary forms, with or without
  5.  * modification, are permitted provided that the following conditions
  6.  * are met:
  7.  *
  8.  * 1. Redistributions of source code must retain the above copyright
  9.  *    notice, this list of conditions and the following disclaimer.
  10.  *
  11.  * 2. Redistributions in binary form must reproduce the above copyright
  12.  *    notice, this list of conditions and the following disclaimer in
  13.  *    the documentation and/or other materials provided with the
  14.  *    distribution.
  15.  *
  16.  * 3. All advertising materials mentioning features or use of this
  17.  *    software must display the following acknowledgment:
  18.  *    "This product includes software developed by the Apache Group
  19.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  20.  *
  21.  * 4. The names "Apache Server" and "Apache Group" must not be used to
  22.  *    endorse or promote products derived from this software without
  23.  *    prior written permission. For written permission, please contact
  24.  *    apache@apache.org.
  25.  * 
  26.  * 5. Redistributions of any form whatsoever must retain the following
  27.  *    acknowledgment:
  28.  *    "This product includes software developed by the Apache Group
  29.  *    for use in the Apache HTTP server project (http://www.apache.org/)."
  30.  *    
  31.  * THIS SOFTWARE IS PROVIDED BY THE APACHE GROUP ``AS IS'' AND ANY
  32.  * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
  33.  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
  34.  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE APACHE GROUP OR
  35.  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  36.  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  37.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
  38.  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  39.  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  40.  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  41.  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
  42.  * OF THE POSSIBILITY OF SUCH DAMAGE.
  43.  * ====================================================================
  44.  *    
  45.  * This software consists of voluntary contributions made by many
  46.  * individuals on behalf of the Apache Group and was originally based
  47.  * on public domain software written at the National Center for
  48.  * Supercomputing Applications, University of Illinois, Urbana-Champaign.
  49.  * For more information on the Apache Group and the Apache HTTP server
  50.  * project, please see <http://www.apache.org/>.
  51.  *    
  52.  */
  53.  
  54. /* 
  55.  
  56. Here's my FreeBSD module that puts Apache under the restrictions of
  57. a /etc/login.conf class.  Give it some limits for CPU time and memory
  58. and the nasty runaways will have the legs kicked from under them..
  59.  
  60. Create a dedicated class called 'httpd' e.g.
  61.  
  62. httpd:\
  63.     :coredumpsize=0:\
  64.     :datasize=30M:\
  65.     :datasize-cur=30M:\
  66.     :maxproc=256:\
  67.     :maxproc-cur@:\
  68.     :memoryuse-cur=30M:\
  69.     :memorylocked-cur=30M:\
  70.     :openfiles=1024:\
  71.     :cputime=5m:\
  72.     :openfiles-cur=1024:\
  73.     :stacksize=16M:\
  74.     :tc=default:
  75.    
  76.  
  77. and then add this to your conf.
  78.  
  79. <IfModule mod_setclass.c>
  80.     LoginClass httpd
  81. </IfModule>
  82.  
  83. I use the module to protect against runaways that tend to be more frequent
  84. with new/revised mod_perl handlers.
  85.  
  86. --- Rob hartill
  87.  
  88. */
  89.  
  90. #include "httpd.h"
  91. #include "http_config.h"
  92. #include "http_log.h"
  93.  
  94. #include <sys/types.h>
  95. #include <login_cap.h>
  96.  
  97. typedef struct {
  98.     char *class;
  99. } process_class_rec;
  100.  
  101. module MODULE_VAR_EXPORT setclass_module;
  102.  
  103. static void *create_class_store(pool *p, server_rec *dummy)
  104. {
  105.         process_class_rec *new =
  106.                 (process_class_rec *) ap_palloc(p, sizeof(process_class_rec));
  107.         new->class = NULL;
  108.         return new;
  109. }
  110.  
  111. static void set_freebsd_class(server_rec *s, pool *p) 
  112. {
  113.         int err;
  114.         process_class_rec *class_rec =
  115.                 ap_get_module_config(s->module_config, &setclass_module);
  116.         if (class_rec->class) {
  117.             err = setclasscontext(class_rec->class, LOGIN_SETRESOURCES);
  118.             if (err == -1) ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, s,
  119.                      "Failed to set loginclass to: %s", class_rec->class);
  120.  
  121.         }
  122. }
  123.  
  124. static const char *remember_class(cmd_parms *cmd, void *dconf, char *class)
  125. {
  126.         process_class_rec *class_rec = ap_get_module_config(cmd->server->module_config, &setclass_module);
  127.         class_rec->class = ap_pstrdup(cmd->pool, class);
  128. /*        ap_aplog_error(APLOG_MARK, APLOG_NOTICE|APLOG_NOERRNO, cmd->server,
  129.                "loginclass will be set to '%s' for each child; see syslog for errors", class);
  130. */
  131.         return NULL;
  132. }
  133.  
  134. static command_rec class_cmds[] =
  135. {
  136.         {"LoginClass", remember_class, NULL, RSRC_CONF, TAKE1,
  137.         "a login class name"},
  138.         {NULL}
  139. };
  140.  
  141. module MODULE_VAR_EXPORT setclass_module =
  142. {
  143.     STANDARD_MODULE_STUFF,
  144.     NULL,                       /* initializer */
  145.     NULL,                       /* dir config creater */
  146.     NULL,                       /* dir merger --- default is to override */
  147.     create_class_store,         /* server config */
  148.     NULL,                       /* merge server configs */
  149.     class_cmds,                 /* command table */
  150.     NULL,                       /* handlers */
  151.     NULL,                       /* filename translation */
  152.     NULL,                       /* check_user_id */
  153.     NULL,                       /* check auth */
  154.     NULL,                       /* check access */
  155.     NULL,                       /* type_checker */
  156.     NULL,                       /* fixups */
  157.     NULL,                       /* logger */
  158.     NULL,                       /* header parser */
  159.     set_freebsd_class,          /* child_init */
  160.     NULL,                       /* child_exit */
  161.     NULL                        /* post read-request */
  162. };
  163.