Extending PostgreSQL Using C

Started by Boulat Khakimovabout 25 years ago6 messagesdocs
Jump to latest
#1Boulat Khakimov
boulat@inet-interactif.com

Hi,

Im writing a C function for PG to do one way encryption using crypt.
Here is the source code

#include <ctype.h>
#include <unistd.h>
#include "postgres.h"
#include "utils/builtins.h"

text *encrypt(text *string){
text *ret;
int m;

if ((string == (text *) NULL) || ((m = VARSIZE(string) -
VARHDRSZ) <= 0))
return string;

ret = (text *) palloc(20);

ret = (text *) crypt(string,"AB");

return ret;

}

then I compile it like so:

gcc -I/usr/src/postgresql-7.0.3/src/include \
-I/usr/src/postgresql-7.0.3/src/backend -O2 -Wall
-Wmissing-prototypes \
-Wmissing-declarations \
-I/usr/src/postgresql-7.0.3/src/interfaces/libpq \
-I/usr/src/postgresql-7.0.3/src/include -fpic -c -o encrypt.o
encrypt.c

gcc -shared -o encrypt.so encrypt.o

rm encrypt.o

then in PG, I do the following

test=> CREATE FUNCTION encrypt(text)
test->RETURNS text
test->AS '/[full path here]/encrypt.so'
test->LANGUAGE 'C';
CREATE

Now when I try
test=> SELECT encrypt('Blah');
it gives me this error

ERROR: Can't find function encrypt in file /[full path here]/encrypt.so

Why do I get this error????
Any ideas?

Regards,
Boulat Khakimov

--
Nothing Like the Sun

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Boulat Khakimov (#1)
Re: Extending PostgreSQL Using C

Boulat Khakimov <boulat@inet-interactif.com> writes:

ERROR: Can't find function encrypt in file /[full path here]/encrypt.so
Why do I get this error????

Offhand I see nothing wrong with your procedure. Try running 'nm' on
the .so file to see what symbols it says the .so defines.

What platform is this on, anyway?

regards, tom lane

#3Boulat Khakimov
boulat@inet-interactif.com
In reply to: Boulat Khakimov (#1)
Re: Extending PostgreSQL Using C

Tom Lane wrote:

Boulat Khakimov <boulat@inet-interactif.com> writes:

ERROR: Can't find function encrypt in file /[full path here]/encrypt.so
Why do I get this error????

Offhand I see nothing wrong with your procedure. Try running 'nm' on
the .so file to see what symbols it says the .so defines.

What platform is this on, anyway?

Linux 2.2.18 #23 Tue Feb 6 13:21:15 EST 2001 i686 unknown

Regards,
Boulat

--
Nothing Like the Sun

#4Hannu Krosing
hannu@tm.ee
In reply to: Boulat Khakimov (#1)
Re: Extending PostgreSQL Using C

Boulat Khakimov wrote:

Hi,

Im writing a C function for PG to do one way encryption using crypt.
Here is the source code

it gives me this error

ERROR: Can't find function encrypt in file /[full path here]/encrypt.so

Why do I get this error????
Any ideas?

Can _postgres_ user read /[full path here]/encrypt.so ?

---------------
Hannu

#5Tom Lane
tgl@sss.pgh.pa.us
In reply to: Hannu Krosing (#4)
Re: Extending PostgreSQL Using C

Hannu Krosing <hannu@tm.ee> writes:

Boulat Khakimov wrote:

ERROR: Can't find function encrypt in file /[full path here]/encrypt.so

Can _postgres_ user read /[full path here]/encrypt.so ?

Presumably so. If he were unable to load the .so file, he'd be getting
a different error message. This message indicates that he got past the
load step, but dl_sym is unable to resolve the symbol "encrypt".

I asked about the symbol names shown by nm(1), but got no answer ...

regards, tom lane

#6Nishad Prakash
prakashn@uci.edu
In reply to: Tom Lane (#5)
Re: Extending PostgreSQL Using C

On Wed, 7 Mar 2001, Tom Lane wrote:

Hannu Krosing <hannu@tm.ee> writes:

Boulat Khakimov wrote:

ERROR: Can't find function encrypt in file /[full path here]/encrypt.so

Can _postgres_ user read /[full path here]/encrypt.so ?

Presumably so. If he were unable to load the .so file, he'd be getting
a different error message. This message indicates that he got past the
load step, but dl_sym is unable to resolve the symbol "encrypt".

I asked about the symbol names shown by nm(1), but got no answer ...

It should be noted that encrypt() is a function already declared in
unistd.h, which the OP is including. Could that be causing some problem
since the OP is using the same name?

Nishad
--
"Underneath the concrete, the dream is still alive" -- Talking Heads