33
33
* ENHANCEMENTS, OR MODIFICATIONS.
34
34
*
35
35
* IDENTIFICATION
36
- * $Header: /cvsroot/pgsql/src/pl/plperl/plperl.c,v 1.21 2001/06/09 02:19:07 tgl Exp $
36
+ * $Header: /cvsroot/pgsql/src/pl/plperl/plperl.c,v 1.22 2001/06/18 21:40:06 momjian Exp $
37
37
*
38
38
**********************************************************************/
39
39
@@ -95,6 +95,7 @@ typedef struct plperl_proc_desc
95
95
Oid arg_out_elem [FUNC_MAX_ARGS ];
96
96
int arg_out_len [FUNC_MAX_ARGS ];
97
97
int arg_is_rel [FUNC_MAX_ARGS ];
98
+ bool lanpltrusted ;
98
99
SV * reference ;
99
100
} plperl_proc_desc ;
100
101
@@ -121,7 +122,7 @@ typedef struct plperl_query_desc
121
122
static int plperl_firstcall = 1 ;
122
123
static int plperl_call_level = 0 ;
123
124
static int plperl_restart_in_progress = 0 ;
124
- static PerlInterpreter * plperl_safe_interp = NULL ;
125
+ static PerlInterpreter * plperl_interp = NULL ;
125
126
static HV * plperl_proc_hash = NULL ;
126
127
127
128
#if REALLYHAVEITONTHEBALL
@@ -133,7 +134,7 @@ static Tcl_HashTable *plperl_query_hash = NULL;
133
134
* Forward declarations
134
135
**********************************************************************/
135
136
static void plperl_init_all (void );
136
- static void plperl_init_safe_interp (void );
137
+ static void plperl_init_interp (void );
137
138
138
139
Datum plperl_call_handler (PG_FUNCTION_ARGS );
139
140
@@ -201,11 +202,11 @@ plperl_init_all(void)
201
202
/************************************************************
202
203
* Destroy the existing safe interpreter
203
204
************************************************************/
204
- if (plperl_safe_interp != NULL )
205
+ if (plperl_interp != NULL )
205
206
{
206
- perl_destruct (plperl_safe_interp );
207
- perl_free (plperl_safe_interp );
208
- plperl_safe_interp = NULL ;
207
+ perl_destruct (plperl_interp );
208
+ perl_free (plperl_interp );
209
+ plperl_interp = NULL ;
209
210
}
210
211
211
212
/************************************************************
@@ -229,40 +230,41 @@ plperl_init_all(void)
229
230
/************************************************************
230
231
* Now recreate a new safe interpreter
231
232
************************************************************/
232
- plperl_init_safe_interp ();
233
+ plperl_init_interp ();
233
234
234
235
plperl_firstcall = 0 ;
235
236
return ;
236
237
}
237
238
238
239
239
240
/**********************************************************************
240
- * plperl_init_safe_interp () - Create the safe Perl interpreter
241
+ * plperl_init_interp () - Create the safe Perl interpreter
241
242
**********************************************************************/
242
243
static void
243
- plperl_init_safe_interp (void )
244
+ plperl_init_interp (void )
244
245
{
245
246
246
247
char * embedding [3 ] = {
247
248
"" , "-e" ,
248
249
249
250
/*
250
- * no commas between the next 4 please. They are supposed to be
251
+ * no commas between the next 5 please. They are supposed to be
251
252
* one string
252
253
*/
253
254
"require Safe; SPI::bootstrap();"
254
255
"sub ::mksafefunc { my $x = new Safe; $x->permit_only(':default');$x->permit(':base_math');"
255
256
"$x->share(qw[&elog &DEBUG &NOTICE &ERROR]);"
256
257
" return $x->reval(qq[sub { $_[0] }]); }"
258
+ "sub ::mkunsafefunc {return eval(qq[ sub { $_[0] } ]); }"
257
259
};
258
260
259
- plperl_safe_interp = perl_alloc ();
260
- if (!plperl_safe_interp )
261
- elog (ERROR , "plperl_init_safe_interp (): could not allocate perl interpreter" );
261
+ plperl_interp = perl_alloc ();
262
+ if (!plperl_interp )
263
+ elog (ERROR , "plperl_init_interp (): could not allocate perl interpreter" );
262
264
263
- perl_construct (plperl_safe_interp );
264
- perl_parse (plperl_safe_interp , plperl_init_shared_libs , 3 , embedding , NULL );
265
- perl_run (plperl_safe_interp );
265
+ perl_construct (plperl_interp );
266
+ perl_parse (plperl_interp , plperl_init_shared_libs , 3 , embedding , NULL );
267
+ perl_run (plperl_interp );
266
268
267
269
268
270
@@ -336,7 +338,7 @@ plperl_call_handler(PG_FUNCTION_ARGS)
336
338
**********************************************************************/
337
339
static
338
340
SV *
339
- plperl_create_sub (char * s )
341
+ plperl_create_sub (char * s , bool trusted )
340
342
{
341
343
dSP ;
342
344
@@ -348,7 +350,8 @@ plperl_create_sub(char *s)
348
350
PUSHMARK (SP );
349
351
XPUSHs (sv_2mortal (newSVpv (s , 0 )));
350
352
PUTBACK ;
351
- count = perl_call_pv ("mksafefunc" , G_SCALAR | G_EVAL | G_KEEPERR );
353
+ count = perl_call_pv ( (trusted ?"mksafefunc" :"mkunsafefunc" ),
354
+ G_SCALAR | G_EVAL | G_KEEPERR );
352
355
SPAGAIN ;
353
356
354
357
if (SvTRUE (ERRSV ))
@@ -397,15 +400,15 @@ plperl_create_sub(char *s)
397
400
*
398
401
**********************************************************************/
399
402
400
- extern void boot_Opcode _ ((CV * cv ));
403
+ extern void boot_DynaLoader _ ((CV * cv ));
401
404
extern void boot_SPI _ ((CV * cv ));
402
405
403
406
static void
404
407
plperl_init_shared_libs (void )
405
408
{
406
409
char * file = __FILE__ ;
407
410
408
- newXS ("Opcode::bootstrap " , boot_Opcode , file );
411
+ newXS ("DynaLoader::boot_DynaLoader " , boot_DynaLoader , file );
409
412
newXS ("SPI::bootstrap" , boot_SPI , file );
410
413
}
411
414
@@ -529,8 +532,10 @@ plperl_func_handler(PG_FUNCTION_ARGS)
529
532
* Then we load the procedure into the safe interpreter.
530
533
************************************************************/
531
534
HeapTuple procTup ;
535
+ HeapTuple langTup ;
532
536
HeapTuple typeTup ;
533
537
Form_pg_proc procStruct ;
538
+ Form_pg_language langStruct ;
534
539
Form_pg_type typeStruct ;
535
540
char * proc_source ;
536
541
@@ -541,6 +546,7 @@ plperl_func_handler(PG_FUNCTION_ARGS)
541
546
prodesc -> proname = malloc (strlen (internal_proname ) + 1 );
542
547
strcpy (prodesc -> proname , internal_proname );
543
548
549
+
544
550
/************************************************************
545
551
* Lookup the pg_proc tuple by Oid
546
552
************************************************************/
@@ -556,6 +562,24 @@ plperl_func_handler(PG_FUNCTION_ARGS)
556
562
}
557
563
procStruct = (Form_pg_proc ) GETSTRUCT (procTup );
558
564
565
+ /************************************************************
566
+ * Lookup the pg_language tuple by Oid
567
+ ************************************************************/
568
+ langTup = SearchSysCache (LANGOID ,
569
+ ObjectIdGetDatum (procStruct -> prolang ),
570
+ 0 , 0 , 0 );
571
+ if (!HeapTupleIsValid (langTup ))
572
+ {
573
+ free (prodesc -> proname );
574
+ free (prodesc );
575
+ elog (ERROR , "plperl: cache lookup for language %u failed" ,
576
+ procStruct -> prolang );
577
+ }
578
+ langStruct = (Form_pg_language ) GETSTRUCT (langTup );
579
+
580
+ prodesc -> lanpltrusted = langStruct -> lanpltrusted ;
581
+ ReleaseSysCache (langTup );
582
+
559
583
/************************************************************
560
584
* Get the required information for input conversion of the
561
585
* return value.
@@ -634,7 +658,7 @@ plperl_func_handler(PG_FUNCTION_ARGS)
634
658
/************************************************************
635
659
* Create the procedure in the interpreter
636
660
************************************************************/
637
- prodesc -> reference = plperl_create_sub (proc_source );
661
+ prodesc -> reference = plperl_create_sub (proc_source , prodesc -> lanpltrusted );
638
662
pfree (proc_source );
639
663
if (!prodesc -> reference )
640
664
{
0 commit comments