author | Mahlon E. Smith <mahlon@martini.nu> |
Sat, 28 Feb 2009 06:52:48 +0000 | |
changeset 6 | 2d52adc4adcc |
child 7 | 4460fc10c6a3 |
permissions | -rw-r--r-- |
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.c - Ruby jparallel |
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 E. 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 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
43 |
#include "jail.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 |
VALUE rbjail_mBSD; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
46 |
VALUE rbjail_cBSDJail; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
47 |
VALUE rbjail_cIPAddr; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
48 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
49 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
50 |
/* |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
51 |
* Debug logging function |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
52 |
*/ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
53 |
void |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
54 |
#ifdef HAVE_STDARG_PROTOTYPES |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
55 |
rbjail_debug(const char *fmt, ...) |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
56 |
#else |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
57 |
rbjail_debug( const char *fmt, va_dcl ) |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
58 |
#endif |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
59 |
{ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
60 |
char buf[BUFSIZ], buf2[BUFSIZ]; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
61 |
va_list args; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
62 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
63 |
if ( !RTEST(ruby_debug) ) return; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
64 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
65 |
snprintf( buf, BUFSIZ, "Debug>>> %s", fmt ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
66 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
67 |
va_init_list( args, fmt ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
68 |
vsnprintf( buf2, BUFSIZ, buf, args ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
69 |
fputs( buf2, stderr ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
70 |
fputs( "\n", stderr ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
71 |
fflush( stderr ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
72 |
va_end( args ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
73 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
74 |
|
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 |
* Object validity checker. Returns the data pointer. |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
78 |
*/ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
79 |
static struct xprison * |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
80 |
rbjail_check_jail( VALUE self ) { |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
81 |
debugMsg(( "Checking a BSD::Jail object (%d).", self )); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
82 |
Check_Type( self, T_DATA ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
83 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
84 |
if ( !rb_obj_is_kind_of(self, rbjail_cBSDJail) ) { |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
85 |
rb_raise( rb_eTypeError, "wrong argument type %s (expected BSD::Jail)", |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
86 |
rb_class2name(CLASS_OF( self )) ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
87 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
88 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
89 |
return DATA_PTR( self ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
90 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
91 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
92 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
93 |
/* |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
94 |
* Fetch the data pointer and check it for sanity. |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
95 |
*/ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
96 |
static struct xprison * |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
97 |
rbjail_get_jailptr( VALUE self ) { |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
98 |
struct xprison *ptr = rbjail_check_jail( self ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
99 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
100 |
debugMsg(( "Fetching a Jail (%p).", ptr )); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
101 |
if ( !ptr ) |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
102 |
rb_raise( rb_eRuntimeError, "uninitialized Jail" ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
103 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
104 |
return ptr; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
105 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
106 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
107 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
108 |
/* |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
109 |
* Copy memory from the given 'xp' to a ruby managed object. |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
110 |
*/ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
111 |
static VALUE |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
112 |
rbjail_alloc( VALUE class, struct xprison *xp ) |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
113 |
{ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
114 |
struct xprison *rbjail_xp = ALLOC( struct xprison ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
115 |
VALUE rbjail = rb_funcall( class, rb_intern("allocate"), 0 ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
116 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
117 |
// replace the null pointer obj with an xprison ptr. |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
118 |
// |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
119 |
memcpy( rbjail_xp, xp, sizeof( struct xprison ) ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
120 |
DATA_PTR( rbjail ) = rbjail_xp; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
121 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
122 |
return rbjail; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
123 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
124 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
125 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
126 |
/* |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
127 |
* |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
128 |
*/ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
129 |
static VALUE |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
130 |
rbjail_get_ip( VALUE self ) |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
131 |
{ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
132 |
struct xprison *xp = rbjail_get_jailptr( self ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
133 |
struct in_addr in; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
134 |
char *ip; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
135 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
136 |
in.s_addr = ntohl( xp->pr_ip ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
137 |
ip = inet_ntoa(in); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
138 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
139 |
return rb_funcall( rbjail_cIPAddr, rb_intern("new"), 1, rb_str_new2(ip) ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
140 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
141 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
142 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
143 |
/* |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
144 |
* |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
145 |
*/ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
146 |
static VALUE |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
147 |
rbjail_get_jid( VALUE self ) |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
148 |
{ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
149 |
struct xprison *xp = rbjail_get_jailptr( self ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
150 |
return INT2FIX( xp->pr_id ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
151 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
152 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
153 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
154 |
/* |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
155 |
* |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
156 |
*/ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
157 |
static VALUE |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
158 |
rbjail_get_host( VALUE self ) |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
159 |
{ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
160 |
struct xprison *xp = rbjail_get_jailptr( self ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
161 |
return rb_str_new2( xp->pr_host ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
162 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
163 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
164 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
165 |
/* |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
166 |
* |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
167 |
*/ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
168 |
static VALUE |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
169 |
rbjail_get_path( VALUE self ) |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
170 |
{ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
171 |
struct xprison *xp = rbjail_get_jailptr( self ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
172 |
return rb_str_new2( xp->pr_path ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
173 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
174 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
175 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
176 |
/* |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
177 |
* GC Free function |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
178 |
*/ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
179 |
static void |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
180 |
rbjail_gc_free( struct xprison *ptr ) { |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
181 |
if ( ptr ) { |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
182 |
xfree( ptr ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
183 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
184 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
185 |
else { |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
186 |
debugMsg(( "Not freeing an uninitialized jail" )); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
187 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
188 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
189 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
190 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
191 |
/* |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
192 |
* Allocate a new ruby object with a NULL pointer. |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
193 |
*/ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
194 |
static VALUE |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
195 |
rbjail_s_alloc( VALUE class ) |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
196 |
{ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
197 |
return Data_Wrap_Struct( class, NULL, rbjail_gc_free, NULL ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
198 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
199 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
200 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
201 |
/* |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
202 |
* Create a new jail object. |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
203 |
* Returns the +id+ of the newly created jail. |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
204 |
*/ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
205 |
static VALUE |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
206 |
rbjail_jail( int argc, VALUE *argv, VALUE self ) { |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
207 |
struct jail j; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
208 |
struct in_addr in; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
209 |
VALUE ip, path, host, securelevel; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
210 |
int id; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
211 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
212 |
rb_scan_args( argc, argv, "31", &ip, &path, &host, &securelevel ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
213 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
214 |
if ( inet_aton( RSTRING_PTR( rb_obj_as_string(ip) ), &in ) == 0 ) |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
215 |
rb_raise( rb_eArgError, "Could not make sense of ip number: %s", ip ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
216 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
217 |
SafeStringValue(path); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
218 |
SafeStringValue(host); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
219 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
220 |
j.version = 0; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
221 |
j.path = RSTRING_PTR( path ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
222 |
j.hostname = RSTRING_PTR( host ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
223 |
j.ip_number = ntohl( in.s_addr ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
224 |
id = jail(&j); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
225 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
226 |
if ( id == -1 ) rb_sys_fail( "jail" ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
227 |
if ( chdir("/") == -1 ) rb_sys_fail( "chdir" ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
228 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
229 |
debugMsg(( "New jail created with id: %d\n", id )); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
230 |
return INT2FIX( id ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
231 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
232 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
233 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
234 |
/* |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
235 |
* Iterate over the currently instantiated jails, returning a jail |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
236 |
* object that matches the given string/ip/JID -- or nil if none do. |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
237 |
* Without an argument, return an array of all JIDs. |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
238 |
*/ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
239 |
static VALUE |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
240 |
rbjail_find( int argc, VALUE *argv, VALUE self ) |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
241 |
{ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
242 |
struct xprison *sxp, *xp; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
243 |
struct in_addr in; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
244 |
size_t i, len; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
245 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
246 |
VALUE arg, rbjail; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
247 |
VALUE jails = rb_ary_new(); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
248 |
int jid = 0, compare = 0; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
249 |
char *str = ""; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
250 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
251 |
rb_scan_args( argc, argv, "01", &arg ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
252 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
253 |
// An argument was passed, so let's figure out what it was |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
254 |
// and try to compare it to the current jails. |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
255 |
// |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
256 |
if ( argc == 1 ) { |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
257 |
switch ( TYPE(arg) ) { |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
258 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
259 |
// find by JID |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
260 |
// |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
261 |
case T_FIXNUM: |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
262 |
jid = FIX2INT( arg ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
263 |
break; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
264 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
265 |
// find by IP/hostname |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
266 |
// |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
267 |
case T_OBJECT: |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
268 |
case T_DATA: |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
269 |
case T_STRING: |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
270 |
str = RSTRING_PTR( rb_obj_as_string(arg) ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
271 |
compare = 1; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
272 |
break; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
273 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
274 |
default: |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
275 |
rb_raise( rb_eTypeError, "invalid argument to find(): %s", |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
276 |
RSTRING_PTR(rb_inspect(arg)) ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
277 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
278 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
279 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
280 |
// Get the size of the xprison and allocate memory to it. |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
281 |
// |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
282 |
if ( sysctlbyname("security.jail.list", NULL, &len, NULL, 0) == -1 ) |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
283 |
rb_sys_fail("sysctlbyname(): security.jail.list"); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
284 |
if ( len <= 0 ) { |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
285 |
rb_sys_fail("sysctlbyname(): unable to determine xprison size"); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
286 |
return Qnil; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
287 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
288 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
289 |
sxp = xp = malloc( len ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
290 |
if ( sxp == NULL ) { |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
291 |
rb_sys_fail("sysctlbyname(): unable to allocate memory"); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
292 |
return Qnil; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
293 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
294 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
295 |
// Get and sanity check the current prison list |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
296 |
// |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
297 |
if ( sysctlbyname("security.jail.list", xp, &len, NULL, 0) == -1 ) { |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
298 |
if ( errno == ENOMEM ) free( sxp ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
299 |
rb_sys_fail("sysctlbyname(): out of memory"); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
300 |
return Qnil; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
301 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
302 |
if ( len < sizeof(*xp) || len % sizeof(*xp) || xp->pr_version != XPRISON_VERSION ) |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
303 |
rb_fatal("Kernel and userland out of sync"); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
304 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
305 |
// No arguments to find() -- return an array of all JIDs |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
306 |
// |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
307 |
if ( argc == 0 ) { |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
308 |
for ( i = 0; i < len / sizeof(*xp); i++ ) { |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
309 |
rb_ary_push( jails, rbjail_alloc( self, xp ) ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
310 |
xp++; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
311 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
312 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
313 |
free( sxp ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
314 |
return jails; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
315 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
316 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
317 |
// Argument passed to find(): walk the jail list, comparing the arg |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
318 |
// with each current jail. Return first match. |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
319 |
// |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
320 |
for ( i = 0; i < len / sizeof(*xp); i++ ) { |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
321 |
in.s_addr = ntohl(xp->pr_ip); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
322 |
if (( compare == 0 && xp->pr_id == jid ) || |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
323 |
( compare == 1 && |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
324 |
(( strcmp( str, inet_ntoa(in) ) == 0 ) || |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
325 |
( strcmp( str, xp->pr_host ) == 0 )) |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
326 |
)) { |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
327 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
328 |
debugMsg(( "Located jail: %d", xp->pr_id )); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
329 |
rbjail = rbjail_alloc( self, xp ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
330 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
331 |
free( sxp ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
332 |
return rbjail; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
333 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
334 |
else { |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
335 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
336 |
xp++; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
337 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
338 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
339 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
340 |
free( sxp ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
341 |
return Qnil; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
342 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
343 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
344 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
345 |
static void |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
346 |
rbjail_do_jail_attach( int jid ) |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
347 |
{ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
348 |
if ( jail_attach(jid) == -1 ) |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
349 |
rb_sys_fail( "jail_attach" ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
350 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
351 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
352 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
353 |
/* Mostly ripped off from Ruby's process.c */ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
354 |
static VALUE |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
355 |
rbjail_attach_block( int jid ) |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
356 |
{ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
357 |
int pid; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
358 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
359 |
rb_secure(2); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
360 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
361 |
fflush(stdout); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
362 |
fflush(stderr); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
363 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
364 |
switch ( pid = fork() ) { |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
365 |
case 0: |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
366 |
rb_thread_atfork(); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
367 |
if ( rb_block_given_p() ) { |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
368 |
int status; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
369 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
370 |
rbjail_do_jail_attach( jid ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
371 |
rb_protect( rb_yield, Qundef, &status ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
372 |
ruby_stop( status ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
373 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
374 |
return Qnil; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
375 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
376 |
case -1: |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
377 |
rb_sys_fail( "fork(2)" ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
378 |
return Qnil; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
379 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
380 |
default: |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
381 |
return INT2FIX( pid ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
382 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
383 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
384 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
385 |
static VALUE |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
386 |
rbjail_attach( int argc, VALUE *argv, VALUE self ) |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
387 |
{ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
388 |
VALUE jidnum, rval; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
389 |
int jid; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
390 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
391 |
rb_scan_args( argc, argv, "1", &jidnum ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
392 |
jid = NUM2INT( jidnum ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
393 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
394 |
if ( rb_block_given_p() ) { |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
395 |
rval = rbjail_attach_block( jid ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
396 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
397 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
398 |
else { |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
399 |
rbjail_do_jail_attach( jid ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
400 |
rval = Qtrue; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
401 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
402 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
403 |
return rval; |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
404 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
405 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
406 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
407 |
/* |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
408 |
* Ruby initializer. |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
409 |
*/ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
410 |
void |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
411 |
Init_jail( void ) |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
412 |
{ |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
413 |
rbjail_mBSD = rb_define_module( "BSD" ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
414 |
rbjail_cBSDJail = rb_define_class_under( rbjail_mBSD, "Jail", rb_cObject ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
415 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
416 |
rb_require("ipaddr"); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
417 |
rbjail_cIPAddr = rb_const_get( rb_cObject, rb_intern("IPAddr") ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
418 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
419 |
rb_define_alloc_func( rbjail_cBSDJail, rbjail_s_alloc ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
420 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
421 |
// Make the 'new' method private. |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
422 |
rb_funcall( rbjail_cBSDJail, rb_intern("private_class_method"), 1, ID2SYM(rb_intern("new")) ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
423 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
424 |
// main utility functions |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
425 |
// |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
426 |
rb_define_singleton_method( rbjail_cBSDJail, "jail", rbjail_jail, -1 ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
427 |
rb_define_singleton_method( rbjail_cBSDJail, "find", rbjail_find, -1 ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
428 |
rb_define_method( rbjail_cBSDJail, "attach", rbjail_attach, -1 ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
429 |
// rb_define_alias( rbjail_cBSDJail, "list", "find" ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
430 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
431 |
// accessor functions |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
432 |
// |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
433 |
rb_define_method( rbjail_cBSDJail, "jid", rbjail_get_jid, 0 ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
434 |
rb_define_method( rbjail_cBSDJail, "ip", rbjail_get_ip, 0 ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
435 |
rb_define_method( rbjail_cBSDJail, "host", rbjail_get_host, 0 ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
436 |
rb_define_method( rbjail_cBSDJail, "path", rbjail_get_path, 0 ); |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
437 |
} |
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
438 |
|
2d52adc4adcc
* Merge of the mahlon experimental branch.
Mahlon E. Smith <mahlon@martini.nu>
parents:
diff
changeset
|
439 |