From: Alexey Melnikov Date: Mon, 13 Jun 2011 17:41:02 +0000 (+0100) Subject: Use SHGetFolderPath(APPDATA) on Windows to correctly find out location of the config... X-Git-Tag: tr-beta1~106^2~16 X-Git-Url: http://www.project-moonshot.org/gitweb/?p=moonshot.git;a=commitdiff_plain;h=1c9b742b90f237cbf4600890c3377b54d3b595cc Use SHGetFolderPath(APPDATA) on Windows to correctly find out location of the config file --- diff --git a/moonshot/mech_eap/util_cred.c b/moonshot/mech_eap/util_cred.c index d0ca5af..fa27987 100644 --- a/moonshot/mech_eap/util_cred.c +++ b/moonshot/mech_eap/util_cred.c @@ -36,7 +36,18 @@ #include "gssapiP_eap.h" +#if defined(WIN32) +///This didn't work for me when Visual Studio 2005 Express is used: +///#include +#include + +#if !defined(snprintf) +#define snprintf _snprintf +#endif + +#else #include +#endif #include /* for BUFSIZ */ OM_uint32 @@ -117,9 +128,12 @@ readDefaultIdentityAndCreds(OM_uint32 *minor, { OM_uint32 major, tmpMinor; FILE *fp = NULL; - char pwbuf[BUFSIZ], buf[BUFSIZ]; + char buf[BUFSIZ]; char *ccacheName; +#if !defined(WIN32) + char pwbuf[BUFSIZ]; struct passwd *pw = NULL, pwd; +#endif defaultIdentity->length = 0; defaultIdentity->value = NULL; @@ -129,6 +143,7 @@ readDefaultIdentityAndCreds(OM_uint32 *minor, ccacheName = getenv("GSSEAP_IDENTITY"); if (ccacheName == NULL) { +#if !defined(WIN32) if (getpwuid_r(getuid(), &pwd, pwbuf, sizeof(pwbuf), &pw) != 0 || pw == NULL || pw->pw_dir == NULL) { major = GSS_S_CRED_UNAVAIL; @@ -138,6 +153,23 @@ readDefaultIdentityAndCreds(OM_uint32 *minor, snprintf(buf, sizeof(buf), "%s/.gss_eap_id", pw->pw_dir); ccacheName = buf; +#else + TCHAR szPath[MAX_PATH]; + + if(!SUCCEEDED(SHGetFolderPath(NULL, + CSIDL_APPDATA, /* |CSIDL_FLAG_CREATE */ + NULL, /* User access token */ + 0, /* == SHGFP_TYPE_CURRENT from ShlObj.h */ + szPath))) { + major = GSS_S_CRED_UNAVAIL; +////Needs to be correctly converted from the GetLastError(); + *minor = errno; + goto cleanup; + } + + snprintf(buf, sizeof(buf), "%s/.gss_eap_id", szPath); + ccacheName = buf; +#endif } fp = fopen(ccacheName, "r");