Let sc_profile_locate() behave about the same way under Win32 than under Linux

git-svn-id: https://www.opensc-project.org/svnp/opensc/trunk@1213 c6295689-39f2-0310-b995-f0e70906c6a9
This commit is contained in:
sth 2003-06-18 12:38:27 +00:00
parent 97da0b6149
commit bb4bdd529d
2 changed files with 20 additions and 2 deletions

View File

@ -45,6 +45,8 @@
*/
#define OPENSC_CONF_PATH "%windir%\\opensc.conf"
#define SC_PKCS15_PROFILE_DIRECTORY "%windir%\\"
#define PATH_MAX _MAX_PATH
/* src/common/getpass.c */

View File

@ -36,6 +36,9 @@
#include <opensc/scconf.h>
#include "pkcs15-init.h"
#include "profile.h"
#ifdef _WIN32
#include <windows.h>
#endif
#define DEF_PRKEY_RSA_ACCESS 0x1D
#define DEF_PRKEY_DSA_ACCESS 0x12
@ -350,6 +353,7 @@ static const char *
sc_profile_locate(const char *name)
{
static char path[1024];
char profile_dir[MAX_PATH];
/* Name with suffix tagged onto it? */
snprintf(path, sizeof(path), "%s.%s", name, SC_PKCS15_PROFILE_SUFFIX);
@ -360,14 +364,26 @@ sc_profile_locate(const char *name)
if (strchr(path, '/'))
return path;
#ifndef _WIN32
strncpy(profile_dir, SC_PKCS15_PROFILE_DIRECTORY, sizeof(profile_dir));
#else
if (!strncmp(SC_PKCS15_PROFILE_DIRECTORY, "%windir%", 8)) {
GetWindowsDirectory(profile_dir, sizeof(profile_dir));
strncat(profile_dir, SC_PKCS15_PROFILE_DIRECTORY + 8,
sizeof(profile_dir) - strlen(profile_dir));
}
else
strncpy(profile_dir, SC_PKCS15_PROFILE_DIRECTORY, sizeof(profile_dir));
#endif
/* Try directory */
snprintf(path, sizeof(path), "%s/%s",
SC_PKCS15_PROFILE_DIRECTORY, name);
profile_dir, name);
if (access(path, R_OK) == 0)
return path;
snprintf(path, sizeof(path), "%s/%s.%s",
SC_PKCS15_PROFILE_DIRECTORY, name,
profile_dir, name,
SC_PKCS15_PROFILE_SUFFIX);
if (access(path, R_OK) == 0)
return path;