On Fri, May 19, 2000 at 05:54:55PM +0200, M.Mazurek@poznan.multinet.pl wrote:
> Hi,
> I'm trying to write a simple C function:
>
> char *pg_crypt (char *pass) {
> char *salt="xyz";
> char *res;
> res = (char *) palloc(14);
> res=crypt(pass,salt);
> return res;
> }
you can't pass char pointers around like that for pgsql functions.
Here's my version of the above function. It includes random salt
selection if you don't supply it. (Hmm, I suppose I should put
this is contrib, eh? I did start with someone elses boilerplate,
so I'm not sure about the #define at the top.)
I compile it on linux with gcc as so:
gcc -fPIC -shared -I /usr/local/pgsql/include -L /usr/local/pgsql/lib \
-o sqlcrypt.so sqlcrypt.c
And install it like so:
CREATE FUNCTION "sqlcrypt" (text,text ) RETURNS text AS '/usr/local/lib/sqlcrypt
.so' LANGUAGE 'C';
CREATE FUNCTION "sqlcrypt" (text ) RETURNS text AS 'select sqlcrypt($1,'''')' LA
NGUAGE 'SQL';
Ross
--
Ross J. Reedstrom, Ph.D., <reedstrm@rice.edu>
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St., Houston, TX 77005