From bb4bdd529dce4dd3306b249911587736f2f23a40 Mon Sep 17 00:00:00 2001 From: sth Date: Wed, 18 Jun 2003 12:38:27 +0000 Subject: [PATCH] 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 --- src/include/winconfig.h | 2 ++ src/pkcs15init/profile.c | 20 ++++++++++++++++++-- 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/include/winconfig.h b/src/include/winconfig.h index aeef6c90..882ccbba 100644 --- a/src/include/winconfig.h +++ b/src/include/winconfig.h @@ -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 */ diff --git a/src/pkcs15init/profile.c b/src/pkcs15init/profile.c index 76ae2221..8200674c 100644 --- a/src/pkcs15init/profile.c +++ b/src/pkcs15init/profile.c @@ -36,6 +36,9 @@ #include #include "pkcs15-init.h" #include "profile.h" +#ifdef _WIN32 +#include +#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;