Re: Re: Now for the VARDATA, VARSIZE, and VARHDRSZ stuff

From: Lonnie Cumberland <lonnie_cumberland(at)yahoo(dot)com>
To: Brendan Guenther <guenthe8(at)msu(dot)edu>
Cc: pgsql-interfaces(at)postgresql(dot)org
Subject: Re: Re: Now for the VARDATA, VARSIZE, and VARHDRSZ stuff
Date: 2001-04-20 13:12:02
Message-ID: 20010420131202.44750.qmail@web12503.mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-interfaces pgsql-sql

Hello Brendan,

I too was having this problem, but now think that I am getting a very good
handle on these interfaces.

Being that you are trying to hash the standard unix crypt function to look over
the password file, I think that this solution might help you.

I have a simple an efficient C++ solution to this problem:

My "unixcrypt" functions now looks like this

---------------------------------------------------------------
text *unix_encrypt(text *inarg, text *inpass)
{
char temp[25];
int temp_len;

// Take the "text" variables directly to the "strings"
string instr(VARDATA(inarg),0,VARSIZE(inarg)-VARHDRSZ);
string passPhrase(VARDATA(inpass),0,VARSIZE(inpass)-VARHDRSZ);

strcpy(temp,crypt(instr.c_str(),passPhrase.c_str()));
temp_len=strlen(temp);

string outstr(temp,0,temp_len);

// Set up the outgoing DB "text" variable
int32 new_text_size = outstr.size()+4;
text *new_text = (text *) palloc(new_text_size);
memset((void *) new_text, 0, new_text_size);
VARATT_SIZEP(new_text) = new_text_size;

// Move the variable over from the string
strncpy(VARDATA(new_text),outstr.c_str(),outstr.size());

return new_text;
}
----------------------------------------------------------------------------

Be sure to include the header:

#include <unistd.h> // for unix crypt function

---------------------------------------------------------------------------

hope that this helps,

Lonnie

--- Brendan Guenther <guenthe8(at)msu(dot)edu> wrote:
>
>
> Peter Eisentraut wrote:
>
> > The best things might be not to mess with this but call textin() and
> > textout() to convert your data to C strings.
>
> I can't seem to find documentation for textin() and textout() can somebody
> point
> me in the right direction for this or provide an example. I'm having similar
> problems that Lonnie is having with VARDATA and I think this might help. I'm
> trying to link in a C function that makes use of OpenSSL's libcrypto
> functions.
>
> Basically I just need to hash and verify passwords in the database, so as an
> alternate question, if I'm missing something and there is a better way to do
> password storage let me know.
>
> Thanks,
> --
> Brendan Guenther
> guenthe8(at)msu(dot)edu
>
>
> ---------------------------(end of broadcast)---------------------------
> TIP 6: Have you searched our list archives?
>
> http://www.postgresql.org/search.mpl

__________________________________________________
Do You Yahoo!?
Yahoo! Auctions - buy the things you want at great prices
http://auctions.yahoo.com/

In response to

Browse pgsql-interfaces by date

  From Date Subject
Next Message Lonnie Cumberland 2001-04-20 15:04:26 Client/Server Security question
Previous Message Brendan Guenther 2001-04-20 11:11:44 Re: Now for the VARDATA, VARSIZE, and VARHDRSZ stuff

Browse pgsql-sql by date

  From Date Subject
Next Message Lonnie Cumberland 2001-04-20 15:04:26 Client/Server Security question
Previous Message Mateusz Mazur 2001-04-20 13:11:16 Thank you