author | Mahlon E. Smith <mahlon@martini.nu> |
Sat, 28 Feb 2009 04:54:46 +0000 | |
branch | mahlon-misc |
changeset 12 | 5fd07a9e7e7b |
parent 11 | ext/bsdjail.c@e908d309e7ec |
permissions | -rw-r--r-- |
0 | 1 |
/* |
12
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
2 |
* jail.c - Ruby jparallel |
11 | 3 |
* |
4 |
* vim: set nosta noet ts=4 sw=4: |
|
12
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
5 |
* |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
6 |
* $Id$ |
0 | 7 |
* |
8 |
* Authors: |
|
12
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
9 |
* * Michael Granger <ged@FaerieMUD.org> |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
10 |
* * Mahlon E. Smith <mahlon@martini.nu> |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
11 |
* |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
12 |
* Copyright (c) 2008, Michael Granger and Mahlon E. Smith |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
13 |
* All rights reserved. |
0 | 14 |
* |
12
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
15 |
* Redistribution and use in source and binary forms, with or without |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
16 |
* modification, are permitted provided that the following conditions are met: |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
17 |
* |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
18 |
* * Redistributions of source code must retain the above copyright notice, |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
19 |
* this list of conditions and the following disclaimer. |
0 | 20 |
* |
12
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
21 |
* * Redistributions in binary form must reproduce the above copyright notice, |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
22 |
* this list of conditions and the following disclaimer in the documentation |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
23 |
* and/or other materials provided with the distribution. |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
24 |
* |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
25 |
* * Neither the name of the author/s, nor the names of the project's |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
26 |
* contributors may be used to endorse or promote products derived from this |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
27 |
* software without specific prior written permission. |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
28 |
* |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
29 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
30 |
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
31 |
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
32 |
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
33 |
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
34 |
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
35 |
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
36 |
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
37 |
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
38 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
0 | 39 |
* |
40 |
*/ |
|
41 |
||
12
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
42 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
43 |
#include "jail.h" |
0 | 44 |
|
45 |
VALUE rbjail_mBSD; |
|
46 |
VALUE rbjail_cBSDJail; |
|
12
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
47 |
VALUE rbjail_cIPAddr; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
48 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
49 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
50 |
/* |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
51 |
* Debug logging function |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
52 |
*/ |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
53 |
void |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
54 |
#ifdef HAVE_STDARG_PROTOTYPES |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
55 |
rbjail_debug(const char *fmt, ...) |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
56 |
#else |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
57 |
rbjail_debug( const char *fmt, va_dcl ) |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
58 |
#endif |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
59 |
{ |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
60 |
char buf[BUFSIZ], buf2[BUFSIZ]; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
61 |
va_list args; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
62 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
63 |
if ( !RTEST(ruby_debug) ) return; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
64 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
65 |
snprintf( buf, BUFSIZ, "Debug>>> %s", fmt ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
66 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
67 |
va_init_list( args, fmt ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
68 |
vsnprintf( buf2, BUFSIZ, buf, args ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
69 |
fputs( buf2, stderr ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
70 |
fputs( "\n", stderr ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
71 |
fflush( stderr ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
72 |
va_end( args ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
73 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
74 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
75 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
76 |
/* |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
77 |
* Object validity checker. Returns the data pointer. |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
78 |
*/ |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
79 |
static struct xprison * |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
80 |
rbjail_check_jail( VALUE self ) { |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
81 |
debugMsg(( "Checking a BSD::Jail object (%d).", self )); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
82 |
Check_Type( self, T_DATA ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
83 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
84 |
if ( !rb_obj_is_kind_of(self, rbjail_cBSDJail) ) { |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
85 |
rb_raise( rb_eTypeError, "wrong argument type %s (expected BSD::Jail)", |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
86 |
rb_class2name(CLASS_OF( self )) ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
87 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
88 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
89 |
return DATA_PTR( self ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
90 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
91 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
92 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
93 |
/* |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
94 |
* Fetch the data pointer and check it for sanity. |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
95 |
*/ |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
96 |
static struct xprison * |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
97 |
rbjail_get_jailptr( VALUE self ) { |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
98 |
struct xprison *ptr = rbjail_check_jail( self ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
99 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
100 |
debugMsg(( "Fetching a Jail (%p).", ptr )); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
101 |
if ( !ptr ) |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
102 |
rb_raise( rb_eRuntimeError, "uninitialized Jail" ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
103 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
104 |
return ptr; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
105 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
106 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
107 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
108 |
/* |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
109 |
* Copy memory from the given 'xp' to a ruby managed object. |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
110 |
*/ |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
111 |
static VALUE |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
112 |
rbjail_alloc( VALUE class, struct xprison *xp ) |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
113 |
{ |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
114 |
struct xprison *rbjail_xp = ALLOC( struct xprison ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
115 |
VALUE rbjail = rb_funcall( class, rb_intern("allocate"), 0 ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
116 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
117 |
// replace the null pointer obj with an xprison ptr. |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
118 |
// |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
119 |
memcpy( rbjail_xp, xp, sizeof( struct xprison ) ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
120 |
DATA_PTR( rbjail ) = rbjail_xp; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
121 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
122 |
return rbjail; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
123 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
124 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
125 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
126 |
/* |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
127 |
* |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
128 |
*/ |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
129 |
static VALUE |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
130 |
rbjail_get_ip( VALUE self ) |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
131 |
{ |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
132 |
struct xprison *xp = rbjail_get_jailptr( self ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
133 |
struct in_addr in; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
134 |
char *ip; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
135 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
136 |
in.s_addr = ntohl( xp->pr_ip ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
137 |
ip = inet_ntoa(in); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
138 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
139 |
return rb_funcall( rbjail_cIPAddr, rb_intern("new"), 1, rb_str_new2(ip) ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
140 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
141 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
142 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
143 |
/* |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
144 |
* |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
145 |
*/ |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
146 |
static VALUE |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
147 |
rbjail_get_jid( VALUE self ) |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
148 |
{ |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
149 |
struct xprison *xp = rbjail_get_jailptr( self ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
150 |
return INT2FIX( xp->pr_id ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
151 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
152 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
153 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
154 |
/* |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
155 |
* |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
156 |
*/ |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
157 |
static VALUE |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
158 |
rbjail_get_host( VALUE self ) |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
159 |
{ |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
160 |
struct xprison *xp = rbjail_get_jailptr( self ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
161 |
return rb_str_new2( xp->pr_host ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
162 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
163 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
164 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
165 |
/* |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
166 |
* |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
167 |
*/ |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
168 |
static VALUE |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
169 |
rbjail_get_path( VALUE self ) |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
170 |
{ |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
171 |
struct xprison *xp = rbjail_get_jailptr( self ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
172 |
return rb_str_new2( xp->pr_path ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
173 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
174 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
175 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
176 |
/* |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
177 |
* GC Free function |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
178 |
*/ |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
179 |
static void |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
180 |
rbjail_gc_free( struct xprison *ptr ) { |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
181 |
if ( ptr ) { |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
182 |
xfree( ptr ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
183 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
184 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
185 |
else { |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
186 |
debugMsg(( "Not freeing an uninitialized jail" )); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
187 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
188 |
} |
0 | 189 |
|
190 |
||
191 |
/* |
|
12
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
192 |
* Allocate a new ruby object with a NULL pointer. |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
193 |
*/ |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
194 |
static VALUE |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
195 |
rbjail_s_alloc( VALUE class ) |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
196 |
{ |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
197 |
return Data_Wrap_Struct( class, NULL, rbjail_gc_free, NULL ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
198 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
199 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
200 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
201 |
/* |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
202 |
* Create a new jail object. |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
203 |
* Returns the +id+ of the newly created jail. |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
204 |
*/ |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
205 |
static VALUE |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
206 |
rbjail_jail( int argc, VALUE *argv, VALUE self ) { |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
207 |
struct jail j; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
208 |
struct in_addr in; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
209 |
VALUE ip, path, host, securelevel; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
210 |
int id; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
211 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
212 |
rb_scan_args( argc, argv, "31", &ip, &path, &host, &securelevel ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
213 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
214 |
if ( inet_aton( RSTRING_PTR( rb_obj_as_string(ip) ), &in ) == 0 ) |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
215 |
rb_raise( rb_eArgError, "Could not make sense of ip number: %s", ip ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
216 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
217 |
SafeStringValue(path); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
218 |
SafeStringValue(host); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
219 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
220 |
j.version = 0; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
221 |
j.path = RSTRING_PTR( path ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
222 |
j.hostname = RSTRING_PTR( host ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
223 |
j.ip_number = ntohl( in.s_addr ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
224 |
id = jail(&j); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
225 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
226 |
if ( id == -1 ) rb_sys_fail( "jail" ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
227 |
if ( chdir("/") == -1 ) rb_sys_fail( "chdir" ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
228 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
229 |
debugMsg(( "New jail created with id: %d\n", id )); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
230 |
return INT2FIX( id ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
231 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
232 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
233 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
234 |
/* |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
235 |
* Iterate over the currently instantiated jails, returning a jail |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
236 |
* object that matches the given string/ip/JID -- or nil if none do. |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
237 |
* Without an argument, return an array of all JIDs. |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
238 |
*/ |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
239 |
static VALUE |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
240 |
rbjail_find( int argc, VALUE *argv, VALUE self ) |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
241 |
{ |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
242 |
struct xprison *sxp, *xp; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
243 |
struct in_addr in; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
244 |
size_t i, len; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
245 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
246 |
VALUE arg, rbjail; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
247 |
VALUE jails = rb_ary_new(); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
248 |
int jid = 0, compare = 0; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
249 |
char *str = ""; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
250 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
251 |
rb_scan_args( argc, argv, "01", &arg ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
252 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
253 |
// An argument was passed, so let's figure out what it was |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
254 |
// and try to compare it to the current jails. |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
255 |
// |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
256 |
if ( argc == 1 ) { |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
257 |
switch ( TYPE(arg) ) { |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
258 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
259 |
// find by JID |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
260 |
// |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
261 |
case T_FIXNUM: |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
262 |
jid = FIX2INT( arg ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
263 |
break; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
264 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
265 |
// find by IP/hostname |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
266 |
// |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
267 |
case T_OBJECT: |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
268 |
case T_DATA: |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
269 |
case T_STRING: |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
270 |
str = RSTRING_PTR( rb_obj_as_string(arg) ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
271 |
compare = 1; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
272 |
break; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
273 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
274 |
default: |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
275 |
rb_raise( rb_eTypeError, "invalid argument to find(): %s", |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
276 |
RSTRING_PTR(rb_inspect(arg)) ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
277 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
278 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
279 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
280 |
// Get the size of the xprison and allocate memory to it. |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
281 |
// |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
282 |
if ( sysctlbyname("security.jail.list", NULL, &len, NULL, 0) == -1 ) |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
283 |
rb_sys_fail("sysctlbyname(): security.jail.list"); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
284 |
if ( len <= 0 ) { |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
285 |
rb_sys_fail("sysctlbyname(): unable to determine xprison size"); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
286 |
return Qnil; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
287 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
288 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
289 |
sxp = xp = malloc( len ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
290 |
if ( sxp == NULL ) { |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
291 |
rb_sys_fail("sysctlbyname(): unable to allocate memory"); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
292 |
return Qnil; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
293 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
294 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
295 |
// Get and sanity check the current prison list |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
296 |
// |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
297 |
if ( sysctlbyname("security.jail.list", xp, &len, NULL, 0) == -1 ) { |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
298 |
if ( errno == ENOMEM ) free( sxp ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
299 |
rb_sys_fail("sysctlbyname(): out of memory"); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
300 |
return Qnil; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
301 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
302 |
if ( len < sizeof(*xp) || len % sizeof(*xp) || xp->pr_version != XPRISON_VERSION ) |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
303 |
rb_fatal("Kernel and userland out of sync"); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
304 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
305 |
// No arguments to find() -- return an array of all JIDs |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
306 |
// |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
307 |
if ( argc == 0 ) { |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
308 |
for ( i = 0; i < len / sizeof(*xp); i++ ) { |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
309 |
rb_ary_push( jails, rbjail_alloc( self, xp ) ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
310 |
xp++; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
311 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
312 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
313 |
free( sxp ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
314 |
return jails; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
315 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
316 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
317 |
// Argument passed to find(): walk the jail list, comparing the arg |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
318 |
// with each current jail. Return first match. |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
319 |
// |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
320 |
for ( i = 0; i < len / sizeof(*xp); i++ ) { |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
321 |
in.s_addr = ntohl(xp->pr_ip); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
322 |
if (( compare == 0 && xp->pr_id == jid ) || |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
323 |
( compare == 1 && |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
324 |
(( strcmp( str, inet_ntoa(in) ) == 0 ) || |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
325 |
( strcmp( str, xp->pr_host ) == 0 )) |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
326 |
)) { |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
327 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
328 |
debugMsg(( "Located jail: %d", xp->pr_id )); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
329 |
rbjail = rbjail_alloc( self, xp ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
330 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
331 |
free( sxp ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
332 |
return rbjail; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
333 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
334 |
else { |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
335 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
336 |
xp++; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
337 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
338 |
} |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
339 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
340 |
free( sxp ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
341 |
return Qnil; |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
342 |
} |
0 | 343 |
|
344 |
||
345 |
static void |
|
346 |
rbjail_do_jail_attach( int jid ) |
|
347 |
{ |
|
348 |
if ( jail_attach(jid) == -1 ) |
|
349 |
rb_sys_fail( "jail_attach" ); |
|
350 |
} |
|
351 |
||
12
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
352 |
|
0 | 353 |
/* Mostly ripped off from Ruby's process.c */ |
354 |
static VALUE |
|
355 |
rbjail_attach_block( int jid ) |
|
356 |
{ |
|
11 | 357 |
int pid; |
0 | 358 |
|
11 | 359 |
rb_secure(2); |
0 | 360 |
|
11 | 361 |
fflush(stdout); |
362 |
fflush(stderr); |
|
0 | 363 |
|
364 |
switch ( pid = fork() ) { |
|
365 |
case 0: |
|
366 |
rb_thread_atfork(); |
|
367 |
if ( rb_block_given_p() ) { |
|
368 |
int status; |
|
369 |
||
370 |
rbjail_do_jail_attach( jid ); |
|
371 |
rb_protect( rb_yield, Qundef, &status ); |
|
372 |
ruby_stop( status ); |
|
373 |
} |
|
374 |
return Qnil; |
|
375 |
||
376 |
case -1: |
|
377 |
rb_sys_fail( "fork(2)" ); |
|
378 |
return Qnil; |
|
379 |
||
380 |
default: |
|
381 |
return INT2FIX( pid ); |
|
382 |
} |
|
383 |
} |
|
384 |
||
385 |
static VALUE |
|
386 |
rbjail_attach( int argc, VALUE *argv, VALUE self ) |
|
387 |
{ |
|
388 |
VALUE jidnum, rval; |
|
389 |
int jid; |
|
11 | 390 |
|
0 | 391 |
rb_scan_args( argc, argv, "1", &jidnum ); |
392 |
jid = NUM2INT( jidnum ); |
|
393 |
||
394 |
if ( rb_block_given_p() ) { |
|
395 |
rval = rbjail_attach_block( jid ); |
|
396 |
} |
|
11 | 397 |
|
0 | 398 |
else { |
399 |
rbjail_do_jail_attach( jid ); |
|
400 |
rval = Qtrue; |
|
401 |
} |
|
11 | 402 |
|
0 | 403 |
return rval; |
404 |
} |
|
405 |
||
12
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
406 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
407 |
/* |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
408 |
* Ruby initializer. |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
409 |
*/ |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
410 |
void |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
411 |
Init_jail( void ) |
0 | 412 |
{ |
12
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
413 |
rbjail_mBSD = rb_define_module( "BSD" ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
414 |
rbjail_cBSDJail = rb_define_class_under( rbjail_mBSD, "Jail", rb_cObject ); |
0 | 415 |
|
12
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
416 |
rb_require("ipaddr"); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
417 |
rbjail_cIPAddr = rb_const_get( rb_cObject, rb_intern("IPAddr") ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
418 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
419 |
rb_define_alloc_func( rbjail_cBSDJail, rbjail_s_alloc ); |
0 | 420 |
|
12
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
421 |
// Make the 'new' method private. |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
422 |
rb_funcall( rbjail_cBSDJail, rb_intern("private_class_method"), 1, ID2SYM(rb_intern("new")) ); |
0 | 423 |
|
12
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
424 |
// main utility functions |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
425 |
// |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
426 |
rb_define_singleton_method( rbjail_cBSDJail, "jail", rbjail_jail, -1 ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
427 |
rb_define_singleton_method( rbjail_cBSDJail, "find", rbjail_find, -1 ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
428 |
rb_define_method( rbjail_cBSDJail, "attach", rbjail_attach, -1 ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
429 |
// rb_define_alias( rbjail_cBSDJail, "list", "find" ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
430 |
|
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
431 |
// accessor functions |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
432 |
// |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
433 |
rb_define_method( rbjail_cBSDJail, "jid", rbjail_get_jid, 0 ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
434 |
rb_define_method( rbjail_cBSDJail, "ip", rbjail_get_ip, 0 ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
435 |
rb_define_method( rbjail_cBSDJail, "host", rbjail_get_host, 0 ); |
5fd07a9e7e7b
* Added jail header dependencies for mkmf Makefile.
Mahlon E. Smith <mahlon@martini.nu>
parents:
11
diff
changeset
|
436 |
rb_define_method( rbjail_cBSDJail, "path", rbjail_get_path, 0 ); |
0 | 437 |
} |
438 |
||
439 |