Re: [GENERAL] encrypted field

Поиск
Список
Период
Сортировка
От Henrique Pantarotto
Тема Re: [GENERAL] encrypted field
Дата
Msg-id 99091709221907.09551@scanner.cepa.com.br
обсуждение исходный текст
Ответ на encrypted field  (Gregoire Pichon <grpichon@yahoo.com>)
Ответы Re: [GENERAL] encrypted field  ("Ross J. Reedstrom" <reedstrm@wallace.ece.rice.edu>)
Список pgsql-general
** Sorry folks.. before anyone flames me: this is not a "stupid C trigger", it
is only a "stupid C *function*".. ;-)  Since I am implementing a couple of
triggers, I have this word in my mind..  you know?  Sorry...
So you do: s/trigger/function/g below, okay?  ;-)
**

Hello Greg,

I've created a stupid little C trigger that is kinda like MySQL's "encrypt"
function.  I use it to store passwords in the UNIX crypt format.

Here's the encrypt.c:

--------------------------------------------------------
/*
*
*  Henrique Pantarotto (scanner@cepa.com.br)
*  Funcao para encriptar senhas (Function to encrypt passwords)
*  September 1999
*
*  Create trigger like this:
*  create function encrypt(text) returns text as
*  '/usr/local/pgsql/hpmail/encrypt.so' language 'c';
*
*/

#include <stdio.h>
#include <strings.h>
#include <unistd.h>

#include <postgres.h>
#include <utils/builtins.h>

text *encrypt (text *user);

text *encrypt(text *user)
{
 char *password;

 password = crypt(textout(user), "HP");

 return textin(password);

}
----------------------------------------------------------


Compile using something like this:

1: gcc -I/down/postgresql-6.5.1/src/include -I$/down/postgresql-6.5.1/src/backend -O2 -Wall -Wmissing-prototypes -fpic
-I/down/postgresql-6.5.1/src/include-c -o encrypt.o encrypt.c 
2: gcc -shared -o encrypt.so encrypt.o

(my postgres sources are in /down/postgresql-6.5.1, you'll need to change this
path)

And last, you create the trigger in PostgreSQL using this:

create function encrypt(text) returns text as '/usr/local/pgsql/encrypt.so' language 'c';


If everything is okay, you'll probably have: select encrypt('secret') working
and showing:

encrypt
------------
HPK1Jt2NX21G.
(1 row)

blabla=>


PS: Note that all crypted passwords are created with salt "HP" (my name
initials..) You can change that, or if you know C, you can do in a way that it
will pick two random characters (the way it should really be).

I'm no experience C programmer, nor an experienced PostgreSQL user, so maybe
there's a smarter way to do this same thing.. (there might be even a built in
function that I don't know).


Good luck and regards from Brazil,

Henrique Pantarotto
Sao Paulo, SP - Brasil
scanner@cepa.com.br


On sex, 17 set 1999, Gregoire Pichon wrote:
> Hello,
>
> How can I crypt the field of a table?
> This field will contain secret data, I need therefore
> to crypt this field to avoid those data to be stored
> on the disk unprotected.
>
> Where can I found documentation on this topic?
>
> Thanks
> Greg
>
> __________________________________________________
> Do You Yahoo!?
> Bid and sell for free at http://auctions.yahoo.com
>
> ************
--
Henrique Pantarotto
CEPAnet Internet Provider
webmaster / analista de sistemas
Email: scanner@cepa.com.br
Tel: (011) 5506-8477
Cel: (011) 9706-3444
LINUX FRIEND

В списке pgsql-general по дате отправления:

Предыдущее
От: Gregoire Pichon
Дата:
Сообщение: encrypted field
Следующее
От: Henrique Pantarotto
Дата:
Сообщение: Re: [GENERAL] encrypted field