Various fixes for non-Latin filenames.
authorCarl Hetherington <cth@carlh.net>
Tue, 26 Nov 2013 20:58:42 +0000 (20:58 +0000)
committerCarl Hetherington <cth@carlh.net>
Tue, 26 Nov 2013 20:58:42 +0000 (20:58 +0000)
src/certificates.cc
src/kdm.cc
src/signer_chain.cc

index 818d5f7252810840ad8521a896ca71b4a333ae01..aa7972a55411d1ec972040347d76196783fb1a82 100644 (file)
@@ -29,6 +29,7 @@
 #include "certificates.h"
 #include "compose.hpp"
 #include "exceptions.h"
+#include "util.h"
 
 using std::list;
 using std::string;
@@ -49,7 +50,7 @@ Certificate::Certificate (boost::filesystem::path filename)
        : _certificate (0)
        , _public_key (0)
 {
-       FILE* f = fopen (filename.string().c_str(), "r");
+       FILE* f = fopen_boost (filename, "r");
        if (!f) {
                throw FileError ("could not open file", filename);
        }
index 2005f58a49e3aa82754c426dfe20287f62db22dd..9d40cff746df4408e5781c1602cc8f1aec7b91fe 100644 (file)
@@ -50,7 +50,7 @@ KDM::KDM (boost::filesystem::path kdm, boost::filesystem::path private_key)
 {
        /* Read the private key */
           
-       FILE* private_key_file = fopen (private_key.string().c_str(), "r");
+       FILE* private_key_file = fopen_boost (private_key, "r");
        if (!private_key_file) {
                throw FileError ("could not find RSA private key file", private_key);
        }
index ba9ef33522cef27aa2ab8b9ec2151f74c9ab164a..daed2d0b666a980bc0256964b957089e32ae40b3 100644 (file)
@@ -37,11 +37,35 @@ using std::cout;
 
 static void command (string cmd)
 {
-       int const r = system (cmd.c_str ());
-#ifdef LIBDCP_WINDOWS  
-       int const code = r;
+#ifdef LIBDCP_WINDOWS
+       /* We need to use CreateProcessW on Windows so that the UTF-8/16 mess
+          is handled correctly.
+       */
+       int const wn = MultiByteToWideChar (CP_UTF8, 0, cmd.c_str(), -1, 0, 0);
+       wchar_t* buffer = new wchar_t[wn];
+       if (MultiByteToWideChar (CP_UTF8, 0, cmd.c_str(), -1, buffer, wn) == 0) {
+               delete[] buffer;
+               return;
+       }
+
+       int code = 1;
+
+       STARTUPINFOW startup_info;
+       memset (&startup_info, 0, sizeof (startup_info));
+       startup_info.cb = sizeof (startup_info);
+       PROCESS_INFORMATION process_info;
+       if (CreateProcessW (0, buffer, 0, 0, FALSE, CREATE_NO_WINDOW, 0, 0, &startup_info, &process_info)) {
+               WaitForSingleObject (process_info.hProcess, INFINITE);
+               CloseHandle (process_info.hProcess);
+               CloseHandle (process_info.hThread);
+               DWORD c;
+               GetExitCodeProcess (process_info.hProcess, &c);
+               code = c;
+       }
+
+       delete[] buffer;
 #else
-       int const code = WEXITSTATUS (r);
+       int const code = WEXITSTATUS (system (cmd.c_str ()));
 #endif
        if (code) {
                stringstream s;
@@ -63,7 +87,7 @@ public_key_digest (boost::filesystem::path private_key, boost::filesystem::path
        
        /* Create the public key from the private key */
        stringstream s;
-       s << "\"" << openssl.string() << "\" rsa -outform PEM -pubout -in " << private_key.string() << " > " << public_name.string ();
+       s << "\"" << openssl.string() << "\" rsa -outform PEM -pubout -in " << private_key.string() << " -out " << public_name.string ();
        command (s.str().c_str ());
 
        /* Read in the public key from the file */
@@ -72,7 +96,7 @@ public_key_digest (boost::filesystem::path private_key, boost::filesystem::path
        ifstream f (public_name.string().c_str ());
 
        bool read = false;
-       while (1) {
+       while (f.good ()) {
                string line;
                getline (f, line);
                if (line.length() >= 10 && line.substr(0, 10) == "-----BEGIN") {