mirror of https://github.com/postgres/postgres
that kept me from making perl secure. Attached is uuencoded tarball to add PL/perl to postgresql. Things I know don't work. -- triggers -- SPI The README file has a _VERY_ short tutorial. Mark HollomonREL7_0_PATCHES
parent
d242b64ba2
commit
c02f1ead48
@ -0,0 +1,113 @@ |
|||||||
|
use DynaLoader; |
||||||
|
use Config; |
||||||
|
use ExtUtils::Embed; |
||||||
|
|
||||||
|
# |
||||||
|
# massage the ld options |
||||||
|
# |
||||||
|
my $ldopts = ldopts(); |
||||||
|
chomp($ldopts); |
||||||
|
|
||||||
|
# |
||||||
|
# get the location of the Opcode module |
||||||
|
# |
||||||
|
my $opcode = ''; |
||||||
|
{ |
||||||
|
|
||||||
|
$modname = 'Opcode'; |
||||||
|
|
||||||
|
my $dir; |
||||||
|
foreach (@INC) { |
||||||
|
if (-d "$_/auto/$modname") { |
||||||
|
$dir = "$_/auto/$modname"; |
||||||
|
last; |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if (defined $dir) { |
||||||
|
$opcode = DynaLoader::dl_findfile("-L$dir", $modname); |
||||||
|
} |
||||||
|
|
||||||
|
} |
||||||
|
|
||||||
|
open(MAKEFILE, ">Makefile"); |
||||||
|
|
||||||
|
print MAKEFILE <<_STATIC_; |
||||||
|
#------------------------------------------------------------------------- |
||||||
|
# |
||||||
|
# Makefile |
||||||
|
# Makefile for the plperl shared object |
||||||
|
# |
||||||
|
# AUTOGENERATED Makefile.pl |
||||||
|
# |
||||||
|
|
||||||
|
# |
||||||
|
# Tell make where the postgresql sources live |
||||||
|
# |
||||||
|
SRCDIR= ../../../src |
||||||
|
include \$(SRCDIR)/Makefile.global |
||||||
|
|
||||||
|
|
||||||
|
# use the same compiler as perl did |
||||||
|
CC= $Config{cc} |
||||||
|
|
||||||
|
# get the compiler options that perl wants. |
||||||
|
CFLAGS+= @{[ccopts()]} |
||||||
|
# including the ones for dynamic loading |
||||||
|
CFLAGS+= $Config{cccdlflags} |
||||||
|
|
||||||
|
# add the includes for postgreSQL |
||||||
|
CFLAGS+= -I\$(LIBPQDIR) -I\$(SRCDIR)/include |
||||||
|
|
||||||
|
# For fmgr.h |
||||||
|
CFLAGS+= -I\$(SRCDIR)/backend |
||||||
|
|
||||||
|
|
||||||
|
# add the postgreSQL libraries |
||||||
|
LDADD+= -L\$(LIBPQDIR) -lpq |
||||||
|
|
||||||
|
LDFLAGS+= $Config{lddlflags} \\ |
||||||
|
$ldopts \\ |
||||||
|
-lperl |
||||||
|
|
||||||
|
# |
||||||
|
# DLOBJS is the dynamically-loaded object file. |
||||||
|
# |
||||||
|
DLOBJS= plperl\$(DLSUFFIX) |
||||||
|
|
||||||
|
INFILES= \$(DLOBJS) |
||||||
|
|
||||||
|
SHLIB_EXTRA_LIBS+= $opcode |
||||||
|
|
||||||
|
# |
||||||
|
# plus exports files |
||||||
|
# |
||||||
|
ifdef EXPSUFF |
||||||
|
INFILES+= \$(DLOBJS:.o=\$(EXPSUFF)) |
||||||
|
endif |
||||||
|
|
||||||
|
%.so: %.o |
||||||
|
\$(CC) -o \$@ \$< \$(LDFLAGS) \$(SHLIB_EXTRA_LIBS) \$(LDADD) |
||||||
|
|
||||||
|
|
||||||
|
# |
||||||
|
# Build the shared lib |
||||||
|
# |
||||||
|
plperl : plperl.lo |
||||||
|
libtool \$(CC) -o plperl.so plperl.lo \$(SHLIB_EXTRA_LIBS) \$(LDADD) \$(LDFLAGS) |
||||||
|
|
||||||
|
%.lo : %.c |
||||||
|
libtool \$(CC) -c \$(CFLAGS) \$< |
||||||
|
|
||||||
|
|
||||||
|
# |
||||||
|
# Clean |
||||||
|
# |
||||||
|
clean: |
||||||
|
rm -f \$(INFILES) *.o *.lo |
||||||
|
rm -rf .libs |
||||||
|
rm -f Makefile |
||||||
|
|
||||||
|
dep depend: |
||||||
|
|
||||||
|
_STATIC_ |
@ -0,0 +1,41 @@ |
|||||||
|
>perl Makefile.pl |
||||||
|
>make |
||||||
|
|
||||||
|
copy the resulting library somewhere that |
||||||
|
the postgresql backend can see it. assume |
||||||
|
that path is /usr/local/pgsql/modules/plperl.so |
||||||
|
|
||||||
|
CREATE FUNCTION plperl_call_handler() RETURNS opaque |
||||||
|
AS '/usr/local/pgsql/modules/plperl.so' LANGUAGE 'C'; |
||||||
|
|
||||||
|
CREATE TRUSTED PROCEDURAL LANGUAGE 'plperl' |
||||||
|
HANDLER plperl_call_handler |
||||||
|
LANCOMPILER 'PL/Perl'; |
||||||
|
|
||||||
|
-- here is simple example |
||||||
|
CREATE FUNCTION addints(int4, int4) RETURNS int4 AS ' |
||||||
|
return $_[0] + $_[1] |
||||||
|
' LANGUAGE 'plperl'; |
||||||
|
|
||||||
|
SELECT addints(3,4); |
||||||
|
|
||||||
|
-- of course, you can pass tuples; |
||||||
|
CREATE TABLE twoints ( a integer, b integer); |
||||||
|
CREATE FUNCTION addtwoints(twoints) RETURNS integer AS ' |
||||||
|
$tup = shift; |
||||||
|
return $tup->{"a"} + $tup->{"b"}; |
||||||
|
' LANGUAGE 'plperl'; |
||||||
|
|
||||||
|
SELECT addtwoints(twoints) from twoints; |
||||||
|
|
||||||
|
-- here is one that will fail. Creating the function |
||||||
|
-- will work, but using it will fail. |
||||||
|
CREATE FUNCTION badfunc() RETURNS int4 AS ' |
||||||
|
open(TEMP, ">/tmp/badfile"); |
||||||
|
print TEMP "Gotcha!\n"; |
||||||
|
return 1; |
||||||
|
' LANGUAGE 'plperl'; |
||||||
|
|
||||||
|
SELECT badfunc(); |
||||||
|
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
Loading…
Reference in new issue