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.

/*
 *  jail.h - Header for the ruby jail extension
 *
 *  vim: set nosta noet ts=4 sw=4:
 *
 *  $Id$
 *  
 *  Authors:
 *    * Michael Granger <ged@FaerieMUD.org>
 *    * Mahlon E. Smith <mahlon@martini.nu>
 *  
 *  Copyright (c) 2008, Michael Granger and Mahlon Smith
 *  All rights reserved.
 *  
 *  Redistribution and use in source and binary forms, with or without
 *  modification, are permitted provided that the following conditions are met:
 *  
 *    * Redistributions of source code must retain the above copyright notice,
 *      this list of conditions and the following disclaimer.
 *  
 *    * Redistributions in binary form must reproduce the above copyright notice,
 *      this list of conditions and the following disclaimer in the documentation
 *      and/or other materials provided with the distribution.
 *  
 *    * Neither the name of the author/s, nor the names of the project's
 *      contributors may be used to endorse or promote products derived from this
 *      software without specific prior written permission.
 *  
 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 *  AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 *  IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
 *  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
 *  FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 *  DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
 *  SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 *  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *  OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *  
 */

#ifndef _BSDJAIL_H_
#define _BSDJAIL_H_

#include "ruby.h"

#include <stdio.h>
#include <sys/param.h>
#include <sys/jail.h>
#include <sys/types.h>
#include <sys/sysctl.h>
#include <unistd.h>
#include <arpa/inet.h>
#include <errno.h>


/* Debugging functions/macros */
#ifdef HAVE_STDARG_PROTOTYPES
#include <stdarg.h>
#define va_init_list(a,b) va_start(a,b)
extern void rbjail_debug(const char *fmt, ...);
#else
#include <stdargs.h>
#define va_init_list(a,b) va_start(a)
extern void rbjail_debug(fmt, va_alist);
#endif


/* Debugging macro */
#if DEBUG
#  define debugMsg(f)	rbjail_debug f
#else /* ! DEBUG */
#  define debugMsg(f) 
#endif /* DEBUG */


#endif /* _BSDJAIL_H_ */


/* --------------------------------------------------------------
 * Predeclarations
 * -------------------------------------------------------------- */

// globals
//
VALUE rbjail_mBSD;
VALUE rbjail_cBSDJail;
VALUE rbjail_cIPAddr;
VALUE rbjail_cPathname;

// utility
//
static struct xprison * rbjail_check_jail( VALUE self );
static struct xprison * rbjail_get_jailptr( VALUE self );
static int rbjail_do_attach( int jid );

// memory management
//
static VALUE rbjail_alloc( VALUE class, struct xprison *xp );
static void rbjail_gc_free( struct xprison *ptr );
static VALUE rbjail_s_alloc( VALUE class );

// class
//
static VALUE rbjail_jail( int argc, VALUE *argv, VALUE self );
static VALUE rbjail_find( int argc, VALUE *argv, VALUE self );
static VALUE rbjail_find_by_jid( VALUE self, VALUE jid );
static VALUE rbjail_class_attach( VALUE self, VALUE arg );
static VALUE rbjail_compare( VALUE self, VALUE other );

// instance
//
static VALUE rbjail_inspect( VALUE self );
static VALUE rbjail_get_ip( VALUE self );
static VALUE rbjail_get_jid( VALUE self );
static VALUE rbjail_get_host( VALUE self );
static VALUE rbjail_get_path( VALUE self );
static VALUE rbjail_instance_attach( VALUE self );
static VALUE rbjail_attach_block( int jid );

void Init_jail( void );