[Pkg-owncloud-commits] [owncloud-client] 276/333: Add a trust ssl certificate switch

Sandro Knauß hefee-guest at moszumanska.debian.org
Thu Apr 17 23:17:03 UTC 2014


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 8625ec250b269f4ac711ef9529876bd0adc68fb4
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Tue Apr 1 15:59:14 2014 +0200

    Add a trust ssl certificate switch
---
 csync/src/csync_owncloud.c      |  9 +++++----
 src/owncloudcmd/owncloudcmd.cpp | 33 ++++++++++++++++++++++++---------
 2 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/csync/src/csync_owncloud.c b/csync/src/csync_owncloud.c
index 35da836..41dc2c5 100644
--- a/csync/src/csync_owncloud.c
+++ b/csync/src/csync_owncloud.c
@@ -61,6 +61,7 @@ int _connected = 0;                   /* flag to indicate if a connection exists
                                      the dav_session is valid */
 
 csync_auth_callback _authcb;
+void *_userdata;
 long long chunked_total_size = 0;
 long long chunked_done = 0;
 
@@ -163,7 +164,7 @@ static int verify_sslcert(void *userdata, int failures,
         /* call the csync callback */
         DEBUG_WEBDAV("Call the csync callback for SSL problems");
         memset( buf, 0, NE_ABUFSIZ );
-        (*_authcb) ( problem, buf, NE_ABUFSIZ-1, 1, 0, NULL );
+        (*_authcb) ( problem, buf, NE_ABUFSIZ-1, 1, 0, _userdata );
         if( buf[0] == 'y' || buf[0] == 'Y') {
             ret = 0;
         } else {
@@ -202,12 +203,12 @@ static int ne_auth( void *userdata, const char *realm, int attempt,
             /* call the csync callback */
             DEBUG_WEBDAV("Call the csync callback for %s", realm );
             memset( buf, 0, NE_ABUFSIZ );
-            (*_authcb) ("Enter your username: ", buf, NE_ABUFSIZ-1, 1, 0, NULL );
+            (*_authcb) ("Enter your username: ", buf, NE_ABUFSIZ-1, 1, 0, _userdata );
             if( strlen(buf) < NE_ABUFSIZ ) {
                 strcpy( username, buf );
             }
             memset( buf, 0, NE_ABUFSIZ );
-            (*_authcb) ("Enter your password: ", buf, NE_ABUFSIZ-1, 0, 0, NULL );
+            (*_authcb) ("Enter your password: ", buf, NE_ABUFSIZ-1, 0, 0, _userdata );
             if( strlen(buf) < NE_ABUFSIZ) {
                 strcpy( password, buf );
             }
@@ -1047,8 +1048,8 @@ int owncloud_set_property(const char *key, void *data) {
 }
 
 void owncloud_init(csync_auth_callback cb, void *userdata) {
-    (void) userdata;
 
+    _userdata = userdata;
     _authcb = cb;
     _connected = 0;  /* triggers dav_connect to go through the whole neon setup */
 
diff --git a/src/owncloudcmd/owncloudcmd.cpp b/src/owncloudcmd/owncloudcmd.cpp
index bf92a91..94d9991 100644
--- a/src/owncloudcmd/owncloudcmd.cpp
+++ b/src/owncloudcmd/owncloudcmd.cpp
@@ -43,23 +43,33 @@ public slots:
     }
 };
 
-int getauth(const char* prompt, char* buf, size_t len, int, int, void*)
-{
-    std::cout << "** Authentication required: \n" << prompt << std::endl;
-    std::string s;
-    std::getline(std::cin, s);
-    strncpy( buf, s.c_str(), len );
-    return 0;
-}
-
 struct CmdOptions {
     QString source_dir;
     QString target_url;
     QString config_directory;
     QString proxy;
     bool silent;
+    bool trustSSL;
 };
 
+int getauth(const char* prompt, char* buf, size_t len, int a, int b, void *userdata)
+{
+    (void) a;
+    (void) b;
+
+    struct CmdOptions *opts = (struct CmdOptions*) userdata;
+
+    std::cout << "** Authentication required: \n" << prompt << std::endl;
+    std::string s;
+    if(opts && opts->trustSSL) {
+        s = "yes";
+    } else {
+        std::getline(std::cin, s);
+    }
+    strncpy( buf, s.c_str(), len );
+    return 0;
+}
+
 void help()
 {
     std::cout << "owncloudcmd - command line ownCloud client tool." << std::endl;
@@ -74,6 +84,7 @@ void help()
     std::cout << "  --confdir = configdir: Read config from there." << std::endl;
     std::cout << "  --httpproxy = proxy:   Specify a http proxy to use." << std::endl;
     std::cout << "                         Proxy is http://server:port" << std::endl;
+    std::cout << "  --trust                Trust the SSL certification." << std::endl;
     std::cout << "" << std::endl;
     exit(1);
 
@@ -116,6 +127,8 @@ void parseOptions( const QStringList& app_args, CmdOptions *options )
             options->proxy = it.next();
         } else if( option == "--silent") {
             options->silent = true;
+        } else if( option == "--trust") {
+            options->trustSSL = true;
         } else {
             help();
         }
@@ -131,6 +144,7 @@ int main(int argc, char **argv) {
 
     CmdOptions options;
     options.silent = false;
+    options.trustSSL = false;
     ClientProxy clientProxy;
 
     parseOptions( app.arguments(), &options );
@@ -167,6 +181,7 @@ int main(int argc, char **argv) {
     csync_set_log_level(options.silent ? 1 : 11);
     Logger::instance()->setLogFile("-");
 
+    csync_set_userdata(_csync_ctx, &options);
     csync_set_auth_callback( _csync_ctx, getauth );
 
     if( csync_init( _csync_ctx ) < 0 ) {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list