changeset 144:dc9970d7b9bf

Merged
author Sascha Wilde <wilde@intevation.de>
date Mon, 24 Mar 2014 16:10:26 +0100 (2014-03-24)
parents b026e6d2a161 (current diff) 52993db093f4 (diff)
children 27ebd96798c4
files
diffstat 9 files changed, 124 insertions(+), 113 deletions(-) [+]
line wrap: on
line diff
--- a/cinst/CMakeLists.txt	Mon Mar 24 16:09:47 2014 +0100
+++ b/cinst/CMakeLists.txt	Mon Mar 24 16:10:26 2014 +0100
@@ -5,6 +5,7 @@
 include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../common)
 
 set(CINST_SOURCES
+    ${CMAKE_CURRENT_SOURCE_DIR}/windowsstore.c
     ${CMAKE_CURRENT_SOURCE_DIR}/main.c
 )
 
--- a/cinst/main.c	Mon Mar 24 16:09:47 2014 +0100
+++ b/cinst/main.c	Mon Mar 24 16:10:26 2014 +0100
@@ -1,4 +1,6 @@
-/** @brief Main entry point for the cinst process.
+/**
+ * @file main.c
+ * @brief Main entry point for the cinst process.
  *
  *  The cinst process may or may not be run with elevated
  *  privileges. When run with elevated privileges this
@@ -29,40 +31,10 @@
 #include <string.h>
 #include <assert.h>
 
-#include <polarssl/base64.h>
-
 #include "strhelp.h"
 #include "listutil.h"
 #include "errorcodes.h"
-
-#ifdef WIN32
-#include <windows.h>
-#include <wincrypt.h>
-#endif
-
-#ifdef WIN32
-LPWSTR getLastErrorMsg() {
-    LPWSTR bufPtr = NULL;
-    DWORD err = GetLastError();
-    FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
-                   FORMAT_MESSAGE_FROM_SYSTEM |
-                   FORMAT_MESSAGE_IGNORE_INSERTS,
-                   NULL, err, 0, (LPWSTR)&bufPtr, 0, NULL);
-    if (!bufPtr) {
-        HMODULE hWinhttp = GetModuleHandleW(L"winhttp");
-        if (hWinhttp) {
-            FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
-                           FORMAT_MESSAGE_FROM_HMODULE |
-                           FORMAT_MESSAGE_IGNORE_INSERTS,
-                           hWinhttp, HRESULT_CODE(err), 0,
-                           (LPWSTR)&bufPtr, 0, NULL);
-        }
-    }
-    if (!bufPtr)
-        printf("Error getting last error\n");
-    return bufPtr;
-}
-#endif
+#include "windowsstore.h"
 
 /* The certificate list + instructions may only be so long as
  * twice the accepted certificatelist size */
@@ -160,81 +132,6 @@
 }
 */
 
-#ifdef WIN32
-/** @brief Install certificates into Windows store
- *
- * @param [in] to_install NULL terminated array of base64 encoded certificates.
- * @param [in] user_store set to True if the certificates should be installed
- *             only for the current user. O for system wide installation.
- * @returns 0 on success an errorcode otherwise.
- */
-int install_certificates_win(const char **to_install, int user_store)
-{
-    int i = 0;
-    HCERTSTORE hStore = NULL;
-
-    if (user_store) {
-        // Access user store
-        hStore = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0,
-                               0, CERT_SYSTEM_STORE_CURRENT_USER, L"Root");
-    } else {
-        // Access machine store
-        hStore = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0,
-                               0, CERT_SYSTEM_STORE_LOCAL_MACHINE, L"Root");
-    }
-
-    if (!hStore) {
-        return ERR_STORE_ACCESS_DENIED;
-    }
-
-    while (to_install[i]) {
-        size_t needed_len = 0;
-        size_t cert_len = strnlen(to_install[i], MAX_LINE_LENGTH);
-        int ret = -1;
-        unsigned char *buf;
-
-        /* Check the needed size for the buffer */
-        ret = base64_decode(NULL, &needed_len,
-                            (unsigned char *)to_install[i], cert_len);
-
-        if (ret != 0 && ret != POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) {
-            return ERR_INVALID_INSTRUCTIONS;
-        }
-
-        buf = xmalloc(needed_len);
-        memset (buf, 0, needed_len);
-
-        ret = base64_decode(buf, &needed_len,
-                            (unsigned char *)to_install[i], cert_len);
-
-        if (ret != 0) {
-            return ERR_INVALID_INSTRUCTIONS;
-        }
-
-        ret = CertAddEncodedCertificateToStore (hStore,
-                                                X509_ASN_ENCODING,
-                                                (PBYTE)buf,
-                                                needed_len,
-                                                CERT_STORE_ADD_ALWAYS,
-                                                NULL);
-
-        if (ret == 0) {
-            LPWSTR error = getLastErrorMsg();
-            if (error) {
-                printf("Failed to add certificate: %S \n", error);
-                LocalFree(error);
-            }
-        }
-        i++;
-        free(buf);
-    }
-    if(hStore) {
-        CertCloseStore(hStore, 0);
-    }
-    return 0;
-}
-#endif
-
 int main() {
     char **to_install = NULL;
     char **to_remove = NULL;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cinst/windowsstore.c	Mon Mar 24 16:10:26 2014 +0100
@@ -0,0 +1,93 @@
+#ifdef WIN32
+
+#include <polarssl/base64.h>
+#include "windowsstore.h"
+
+static LPWSTR getLastErrorMsg() {
+    LPWSTR bufPtr = NULL;
+    DWORD err = GetLastError();
+    FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+                   FORMAT_MESSAGE_FROM_SYSTEM |
+                   FORMAT_MESSAGE_IGNORE_INSERTS,
+                   NULL, err, 0, (LPWSTR)&bufPtr, 0, NULL);
+    if (!bufPtr) {
+        HMODULE hWinhttp = GetModuleHandleW(L"winhttp");
+        if (hWinhttp) {
+            FormatMessageW(FORMAT_MESSAGE_ALLOCATE_BUFFER |
+                           FORMAT_MESSAGE_FROM_HMODULE |
+                           FORMAT_MESSAGE_IGNORE_INSERTS,
+                           hWinhttp, HRESULT_CODE(err), 0,
+                           (LPWSTR)&bufPtr, 0, NULL);
+        }
+    }
+    if (!bufPtr)
+        printf("Error getting last error\n");
+    return bufPtr;
+}
+
+int install_certificates_win(const char **to_install, int user_store)
+{
+    int i = 0;
+    HCERTSTORE hStore = NULL;
+
+    if (user_store) {
+        // Access user store
+        hStore = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0,
+                               0, CERT_SYSTEM_STORE_CURRENT_USER, L"Root");
+    } else {
+        // Access machine store
+        hStore = CertOpenStore(CERT_STORE_PROV_SYSTEM, 0,
+                               0, CERT_SYSTEM_STORE_LOCAL_MACHINE, L"Root");
+    }
+
+    if (!hStore) {
+        return ERR_STORE_ACCESS_DENIED;
+    }
+
+    while (to_install[i]) {
+        size_t needed_len = 0;
+        size_t cert_len = strnlen(to_install[i], MAX_LINE_LENGTH);
+        int ret = -1;
+        unsigned char *buf;
+
+        /* Check the needed size for the buffer */
+        ret = base64_decode(NULL, &needed_len,
+                            (unsigned char *)to_install[i], cert_len);
+
+        if (ret != 0 && ret != POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) {
+            return ERR_INVALID_INSTRUCTIONS;
+        }
+
+        buf = xmalloc(needed_len);
+        memset (buf, 0, needed_len);
+
+        ret = base64_decode(buf, &needed_len,
+                            (unsigned char *)to_install[i], cert_len);
+
+        if (ret != 0) {
+            return ERR_INVALID_INSTRUCTIONS;
+        }
+
+        ret = CertAddEncodedCertificateToStore (hStore,
+                                                X509_ASN_ENCODING,
+                                                (PBYTE)buf,
+                                                needed_len,
+                                                CERT_STORE_ADD_ALWAYS,
+                                                NULL);
+
+        if (ret == 0) {
+            LPWSTR error = getLastErrorMsg();
+            if (error) {
+                printf("Failed to add certificate: %S \n", error);
+                LocalFree(error);
+            }
+        }
+        i++;
+        free(buf);
+    }
+    if(hStore) {
+        CertCloseStore(hStore, 0);
+    }
+    return 0;
+}
+#endif // WIN32
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/cinst/windowsstore.h	Mon Mar 24 16:10:26 2014 +0100
@@ -0,0 +1,17 @@
+#ifdef WIN32
+#ifndef WINDOWSSTORE_H
+#define WINDOWSSTORE_H
+
+#include <windows.h>
+#include <wincrypt.h>
+/** @brief Install certificates into Windows store
+ *
+ * @param [in] to_install NULL terminated array of base64 encoded certificates.
+ * @param [in] user_store set to True if the certificates should be installed
+ *             only for the current user. O for system wide installation.
+ * @returns 0 on success an errorcode otherwise.
+ */
+int install_certificates_win(const char **to_install, int user_store)
+
+#endif // WINDOWSSTORE_H
+#endif // WIN32
--- a/ui/tests/CMakeLists.txt	Mon Mar 24 16:09:47 2014 +0100
+++ b/ui/tests/CMakeLists.txt	Mon Mar 24 16:10:26 2014 +0100
@@ -3,6 +3,7 @@
 include_directories(${CMAKE_CURRENT_BINARY_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/.. ${CMAKE_CURRENT_SOURCE_DIR}/../../common)
 
 find_package(Qt5Test)
+include_directories(${Qt5Test_INCLUDE_DIRS})
 find_program(HIAWATHA_EXECUTABLE hiawatha)
 
 if (NOT HIAWATHA_EXECUTABLE)
@@ -28,9 +29,11 @@
 add_m13_test(certlistparsertest.cpp "${CERTIFICATELIST_SOURCES}")
 
 # Downloader
-set(DOWNLOADER_SOURCES_WITH_RESOURCES ${DOWNLOADER_SOURCES})
-qt5_add_resources(DOWNLOADER_SOURCES_WITH_RESOURCES ${M13UI_RESOURCES})
-add_m13_test(downloadertest.cpp "${DOWNLOADER_SOURCES_WITH_RESOURCES}")
+if (HIAWATHA_EXECUTABLE)
+  set(DOWNLOADER_SOURCES_WITH_RESOURCES ${DOWNLOADER_SOURCES})
+  qt5_add_resources(DOWNLOADER_SOURCES_WITH_RESOURCES ${M13UI_RESOURCES})
+  add_m13_test(downloadertest.cpp "${DOWNLOADER_SOURCES_WITH_RESOURCES}")
+endif()
 
 # Cinstprocess
 add_m13_test(cinstprocesstest.cpp "${CERTIFICATELIST_SOURCES}")
--- a/ui/tests/certlistparsertest.h	Mon Mar 24 16:09:47 2014 +0100
+++ b/ui/tests/certlistparsertest.h	Mon Mar 24 16:10:26 2014 +0100
@@ -2,7 +2,7 @@
 #define CERTLISTPARSERTEST_H
 
 #include <QObject>
-#include <QtTest/QtTest>
+#include <QtTest>
 
 class CertificateList;
 
--- a/ui/tests/cinstprocesstest.cpp	Mon Mar 24 16:09:47 2014 +0100
+++ b/ui/tests/cinstprocesstest.cpp	Mon Mar 24 16:10:26 2014 +0100
@@ -6,7 +6,6 @@
 #include <QDir>
 #include <QFile>
 #include <QProcess>
-#include <QTest>
 
 #define RELATIVE_CINST_PATH "../../cinst/cinst"
 
--- a/ui/tests/cinstprocesstest.h	Mon Mar 24 16:09:47 2014 +0100
+++ b/ui/tests/cinstprocesstest.h	Mon Mar 24 16:10:26 2014 +0100
@@ -7,6 +7,7 @@
 
 #include <QObject>
 #include <QProcess>
+#include <QTest>
 #include "certificatelist.h"
 
 class CinstProcessTest: public QObject
--- a/ui/tests/downloadertest.h	Mon Mar 24 16:09:47 2014 +0100
+++ b/ui/tests/downloadertest.h	Mon Mar 24 16:10:26 2014 +0100
@@ -2,7 +2,7 @@
 #define DOWNLOADERTEST_H
 
 #include <QObject>
-#include <QtTest/QtTest>
+#include <QtTest>
 #include <QProcess>
 #include <QTemporaryDir>
 #include <QSignalSpy>

http://wald.intevation.org/projects/trustbridge/