From eb9a2c3ae76b862254669b798b51b2b848616b6a Mon Sep 17 00:00:00 2001 From: Mark Spruiell Date: Tue, 7 Apr 2015 13:51:23 -0700 Subject: ICE-6402 - IceSSL.DefaultDir fixes --- cpp/src/IceSSL/Util.cpp | 35 +++++++++++++---------------------- 1 file changed, 13 insertions(+), 22 deletions(-) (limited to 'cpp/src/IceSSL/Util.cpp') diff --git a/cpp/src/IceSSL/Util.cpp b/cpp/src/IceSSL/Util.cpp index 974227c1a86..907ebdb18ad 100644 --- a/cpp/src/IceSSL/Util.cpp +++ b/cpp/src/IceSSL/Util.cpp @@ -46,11 +46,13 @@ IceSSL::readFile(const string& file, vector& buffer) buffer.resize(static_cast(is.tellg())); is.seekg(0, is.beg); - is.read(&buffer[0], buffer.size()); - - if(!is.good()) + if(!buffer.empty()) { - throw CertificateReadException(__FILE__, __LINE__, "error reading file " + file); + is.read(&buffer[0], buffer.size()); + if(!is.good()) + { + throw CertificateReadException(__FILE__, __LINE__, "error reading file " + file); + } } } @@ -1395,29 +1397,18 @@ IceSSL::findCertificates(const string& prop, const string& storeSpec, const stri bool IceSSL::checkPath(string& path, const string& defaultDir, bool dir) { - // - // Check if file exists. If not, try prepending the default - // directory and check again. If the path exists, the string - // argument is modified and true is returned. Otherwise - // false is returned. - // - IceUtilInternal::structstat st; - int err = IceUtilInternal::stat(path, &st); - if(err == 0) + if(IceUtilInternal::isAbsolutePath(path)) { - return dir ? S_ISDIR(st.st_mode) != 0 : S_ISREG(st.st_mode) != 0; + return dir ? IceUtilInternal::directoryExists(path) : IceUtilInternal::fileExists(path); } + // + // If a default directory is provided, the given path is relative to the default directory. + // if(!defaultDir.empty()) { - string s = defaultDir + IceUtilInternal::separator + path; - err = ::IceUtilInternal::stat(s.c_str(), &st); - if(err == 0 && ((!dir && S_ISREG(st.st_mode)) || (dir && S_ISDIR(st.st_mode)))) - { - path = s; - return true; - } + path = defaultDir + IceUtilInternal::separator + path; } - return false; + return dir ? IceUtilInternal::directoryExists(path) : IceUtilInternal::fileExists(path); } -- cgit v1.2.3