Re: [pgsql-hackers-win32] More SSL questions..

From: "Magnus Hagander" <mha(at)sollentuna(dot)net>
To: "Matthew T(dot) O'Connor" <matthew(at)zeut(dot)net>, "Tom Lane" <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: "T(dot)J(dot)" <tjtoocool(at)phreaker(dot)net>, <pgsql-bugs(at)postgresql(dot)org>, <pgsql-hackers-win32(at)postgresql(dot)org>
Subject: Re: [pgsql-hackers-win32] More SSL questions..
Date: 2005-01-05 08:53:14
Message-ID: 6BCB9D8A16AC4241919521715F4D8BCE4764D8@algol.sollentuna.se
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs pgsql-hackers pgsql-hackers-win32

> >OK ... are you supposed to find it out by looking at the environment
> >vars, or is there another API defined?
> >
> >I am planning to consolidate the platform dependency into a function
> >defined like
> >
> > static bool pqGetHomeDirectory(char *buf, int bufsize)
> > {
> > -- Obtain pathname of user's home directory, store in
> > -- buf[] (of size bufsize)
> > -- Return TRUE if succeeded, FALSE if not
> > }
> >
> >If someone can whip up and test a WIN32 version of this,
> I'll take care
> >of the rest.
> >
> >
>
> I can't do the coding, but I took a quick look at msdn and I
> think this is relevant:
>
> http://msdn.microsoft.com/library/default.asp?url=/library/en-
> us/shellcc/platform/shell/reference/functions/shgetfolderpath.asp
>
> HRESULT SHGetFolderPath(
> HWND /hwndOwner/,
> int /nFolder/,
> HANDLE /hToken/,
> DWORD /dwFlags/,
> LPTSTR /pszPath/
> );
>
>
> Also, for nFolder, it looks like the we want to use a value
> of CSIDL_PROFILE (0x0028).
>
> Hope that helps someone out there.

No, we should use CSIDL_APPDATA. Two reasons:
1) Never put things in the root of the profile :P
2) CSIDL_APPDATA is supported on 9x (4.71 of the shell which,IIRC, is
Win95, as long as you have IE4 or newer install. And I doubt a lot of
people don't have that). Remember that our *client side code* support
9x.

(Then of course it should have "postgresql" (or ".postgresql" for
consiscency with *nix) appended to it)

Also, SHGetFolderPath() rqeuires Win2k. There is
SHGetSpecialFolderPath() for all versions.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc
/platform/shell/reference/functions/shgetspecialfolderpath.asp

Tom also wrote:

> Now that I look at it, there are several places that are depending on
> getenv("HOME") or getenv("USERPROFILE") (on Windows) as the meaning of
"home directory". In particular ~/.pgpass is sought > there, and psql
also uses get_home_path in a lot of places.

> Seems like we should be consistent about this --- either we trust
$HOME or we don't.

Don't trust $HOME on win32. There is no such thing.It's set by Cygwin,
and it's set by the MingW shell, but it's not set by Windows. HOMEDRIVE,
HOMEPATH and HOMESHARE are set, but not HOME.

You can trust USERPROFILE in NT based OSes. Not sure about 9x. Using the
API above is a much nicer way of doing it.

So, a quick implementation (not tested, but shouldn't be too hard) of
your functino would be:
static bool pqGetHomeDirectory(char *buf, int bufsize)
{
char tmppath[MAX_PATH+16]; /* Add 16 chars for "/.postgresql/"
*/
ZeroMemory(tmppath,sizeof(tmppath));
if (!SHGetSpecialFolderPath(NULL, tmppath, CSIDL_APPDATA,
FALSE)) {
return FALSE;
strcat(tmppath,"/.postgresql/");
if (strlen(tmppath) > bufsize)
return FALSE; /* Better than returning a chopped-off
path */
strcpy(buf, tmppath);
return TRUE;
}

You're going to have to add #include <shlobj.h> to the file as well.

//Magnus

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Magnus Hagander 2005-01-05 08:59:50 Re: BUG #1372: Service won't start with tcpip_socket = true
Previous Message Tom Lane 2005-01-05 06:58:55 Re: BUG #1371: Short-circuit evaluation on PL/PgSQL

Browse pgsql-hackers by date

  From Date Subject
Next Message Alin Vaida 2005-01-05 09:17:44 Re: [PATCHES] Final call for translation updates
Previous Message Yann Michel 2005-01-05 08:11:41 Re: query rewrite using materialized views

Browse pgsql-hackers-win32 by date

  From Date Subject
Next Message Andrew Dunstan 2005-01-05 12:47:18 Re: [BUGS] More SSL questions..
Previous Message Matthew T. O'Connor 2005-01-05 01:09:08 Re: [pgsql-hackers-win32] More SSL questions..