Re: simple C function

From: "Ross J(dot) Reedstrom" <reedstrm(at)wallace(dot)ece(dot)rice(dot)edu>
To: M(dot)Mazurek(at)poznan(dot)multinet(dot)pl
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: simple C function
Date: 2000-05-19 17:19:22
Message-ID: 20000519121922.B9113@rice.edu
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, May 19, 2000 at 05:54:55PM +0200, M(dot)Mazurek(at)poznan(dot)multinet(dot)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(at)rice(dot)edu>
NSBRI Research Scientist/Programmer
Computer and Information Technology Institute
Rice University, 6100 S. Main St., Houston, TX 77005

Attachment Content-Type Size
sqlcrypt.c text/x-csrc 1.1 KB

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2000-05-19 17:36:29 Re: Performance (was: The New Slashdot Setup (includes MySql server))
Previous Message Bruce Momjian 2000-05-19 17:17:32 Auto-uppercase inserted column