ext/jail.h
author Mahlon E. Smith <mahlon@martini.nu>
Tue, 03 Mar 2009 22:23:45 +0000
changeset 7 4460fc10c6a3
parent 6 2d52adc4adcc
permissions -rw-r--r--
* Now with 87% more hot jail action! * Predeclared all C methods in jail.h, so they could be arranged in logical order in jail.c * Fixed the extconf namespace. * Added rdoc. * Added usage examples, demonstrating jls, jexec, and jail ruby equivalents. * Re-added the "attach and execute within a block" code. * Added Enumerable and Comparable support. * Return 'path' as a Pathname object. TODO: * Create the actual 'jParallel' shell binary, now that we have a good backend framework. * Tests? How? * Add support for recently committed (will be part of 7.2-RELEASE) multiple IPs per jail, and jail labels.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     1
/*
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     2
 *  jail.h - Header for the ruby jail extension
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     3
 *
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     4
 *  vim: set nosta noet ts=4 sw=4:
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     5
 *
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     6
 *  $Id$
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     7
 *  
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     8
 *  Authors:
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
     9
 *    * Michael Granger <ged@FaerieMUD.org>
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    10
 *    * Mahlon E. Smith <mahlon@martini.nu>
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    11
 *  
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    12
 *  Copyright (c) 2008, Michael Granger and Mahlon Smith
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    13
 *  All rights reserved.
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    14
 *  
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    15
 *  Redistribution and use in source and binary forms, with or without
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    16
 *  modification, are permitted provided that the following conditions are met:
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    17
 *  
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    18
 *    * Redistributions of source code must retain the above copyright notice,
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    19
 *      this list of conditions and the following disclaimer.
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    20
 *  
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    21
 *    * Redistributions in binary form must reproduce the above copyright notice,
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    22
 *      this list of conditions and the following disclaimer in the documentation
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    23
 *      and/or other materials provided with the distribution.
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    24
 *  
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    25
 *    * Neither the name of the author/s, nor the names of the project's
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    26
 *      contributors may be used to endorse or promote products derived from this
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    27
 *      software without specific prior written permission.
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    28
 *  
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    29
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    30
 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    31
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    32
 *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    33
 *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    34
 *  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    35
 *  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    36
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    37
 *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    38
 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    39
 *  
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    40
 */
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    41
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    42
#ifndef _BSDJAIL_H_
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    43
#define _BSDJAIL_H_
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    44
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    45
#include "ruby.h"
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    46
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    47
#include <stdio.h>
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    48
#include <sys/param.h>
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    49
#include <sys/jail.h>
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    50
#include <sys/types.h>
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    51
#include <sys/sysctl.h>
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    52
#include <unistd.h>
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    53
#include <arpa/inet.h>
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    54
#include <errno.h>
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    55
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    56
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    57
/* Debugging functions/macros */
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    58
#ifdef HAVE_STDARG_PROTOTYPES
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    59
#include <stdarg.h>
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    60
#define va_init_list(a,b) va_start(a,b)
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    61
extern void rbjail_debug(const char *fmt, ...);
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    62
#else
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    63
#include <stdargs.h>
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    64
#define va_init_list(a,b) va_start(a)
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    65
extern void rbjail_debug(fmt, va_alist);
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    66
#endif
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    67
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    68
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    69
/* Debugging macro */
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    70
#if DEBUG
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    71
#  define debugMsg(f)	rbjail_debug f
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    72
#else /* ! DEBUG */
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    73
#  define debugMsg(f) 
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    74
#endif /* DEBUG */
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    75
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    76
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    77
#endif /* _BSDJAIL_H_ */
2d52adc4adcc * Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff changeset
    78
7
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    79
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    80
/* --------------------------------------------------------------
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    81
 * Predeclarations
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    82
 * -------------------------------------------------------------- */
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    83
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    84
// globals
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    85
//
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    86
VALUE rbjail_mBSD;
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    87
VALUE rbjail_cBSDJail;
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    88
VALUE rbjail_cIPAddr;
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    89
VALUE rbjail_cPathname;
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    90
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    91
// utility
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    92
//
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    93
static struct xprison * rbjail_check_jail( VALUE self );
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    94
static struct xprison * rbjail_get_jailptr( VALUE self );
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    95
static int rbjail_do_attach( int jid );
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    96
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    97
// memory management
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    98
//
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
    99
static VALUE rbjail_alloc( VALUE class, struct xprison *xp );
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   100
static void rbjail_gc_free( struct xprison *ptr );
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   101
static VALUE rbjail_s_alloc( VALUE class );
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   102
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   103
// class
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   104
//
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   105
static VALUE rbjail_jail( int argc, VALUE *argv, VALUE self );
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   106
static VALUE rbjail_find( int argc, VALUE *argv, VALUE self );
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   107
static VALUE rbjail_find_by_jid( VALUE self, VALUE jid );
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   108
static VALUE rbjail_class_attach( VALUE self, VALUE arg );
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   109
static VALUE rbjail_compare( VALUE self, VALUE other );
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   110
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   111
// instance
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   112
//
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   113
static VALUE rbjail_inspect( VALUE self );
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   114
static VALUE rbjail_get_ip( VALUE self );
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   115
static VALUE rbjail_get_jid( VALUE self );
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   116
static VALUE rbjail_get_host( VALUE self );
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   117
static VALUE rbjail_get_path( VALUE self );
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   118
static VALUE rbjail_instance_attach( VALUE self );
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   119
static VALUE rbjail_attach_block( int jid );
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   120
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   121
void Init_jail( void );
4460fc10c6a3 * Now with 87% more hot jail action!
Mahlon E. Smith <mahlon@martini.nu>
parents: 6
diff changeset
   122