cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anim...@apache.org
Subject [12/19] git commit: updated refs/heads/4.3 to c1af92f
Date Fri, 07 Feb 2014 22:11:01 GMT
CLOUDSTACK-6053: While adding a primary or secondary of type smb the password wasn't
encoded. This cause createStoragePool or addImageStore command to fail if special
characters were present. Updated the code to pass user, password and domain as part
of details while adding primary or secondary. Also made changes on server side to
handle it.
(cherry picked from commit f0b861fedeea9e752665a42231f910112c5b8b46)

Signed-off-by: Animesh Chaturvedi <animesh@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/4961c138
Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/4961c138
Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/4961c138

Branch: refs/heads/4.3
Commit: 4961c1385a210fd33d1a43a5721b98b0563cb60b
Parents: 9536569
Author: Devdeep Singh <devdeep@gmail.com>
Authored: Fri Feb 7 17:46:03 2014 +0530
Committer: Animesh Chaturvedi <animesh@apache.org>
Committed: Fri Feb 7 13:21:39 2014 -0800

----------------------------------------------------------------------
 .../storage/datastore/db/ImageStoreVO.java      |  3 --
 .../storage/datastore/db/StoragePoolVO.java     |  3 --
 .../image/datastore/ImageStoreHelper.java       | 25 +++++++++++++++++
 .../datastore/PrimaryDataStoreHelper.java       | 29 ++++++++++++++++++++
 .../api/query/dao/ImageStoreJoinDaoImpl.java    |  4 +--
 ui/scripts/sharedFunctions.js                   |  2 +-
 ui/scripts/system.js                            | 15 ++++++++--
 ui/scripts/zoneWizard.js                        | 15 ++++++++--
 utils/src/com/cloud/utils/UriUtils.java         | 25 ++++++-----------
 9 files changed, 90 insertions(+), 31 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4961c138/engine/schema/src/org/apache/cloudstack/storage/datastore/db/ImageStoreVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/ImageStoreVO.java
b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/ImageStoreVO.java
index 97ae9c8..387e096 100644
--- a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/ImageStoreVO.java
+++ b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/ImageStoreVO.java
@@ -154,9 +154,6 @@ public class ImageStoreVO implements ImageStore {
 
     public void setUrl(String url) {
         this.url = url;
-        if ("cifs".equalsIgnoreCase(this.protocol)) {
-            this.url = UriUtils.getUpdateUri(url, true);
-        }
     }
 
     public Date getCreated() {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4961c138/engine/schema/src/org/apache/cloudstack/storage/datastore/db/StoragePoolVO.java
----------------------------------------------------------------------
diff --git a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/StoragePoolVO.java
b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/StoragePoolVO.java
index 7d52858..0d1e43d 100644
--- a/engine/schema/src/org/apache/cloudstack/storage/datastore/db/StoragePoolVO.java
+++ b/engine/schema/src/org/apache/cloudstack/storage/datastore/db/StoragePoolVO.java
@@ -279,9 +279,6 @@ public class StoragePoolVO implements StoragePool {
 
     public void setPath(String path) {
         this.path = path;
-        if (this.poolType == StoragePoolType.SMB) {
-            this.path = UriUtils.getUpdateUri(this.path, true);
-        }
     }
 
     public void setUserInfo(String userInfo) {

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4961c138/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreHelper.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreHelper.java
b/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreHelper.java
index 0f5b817..187d6e4 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreHelper.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/image/datastore/ImageStoreHelper.java
@@ -18,6 +18,8 @@
  */
 package org.apache.cloudstack.storage.image.datastore;
 
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.UUID;
@@ -34,6 +36,7 @@ import org.apache.cloudstack.storage.datastore.db.ImageStoreDetailsDao;
 import org.apache.cloudstack.storage.datastore.db.ImageStoreVO;
 import org.apache.cloudstack.storage.datastore.db.SnapshotDataStoreDao;
 
+import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.storage.DataStoreRole;
 import com.cloud.storage.ScopeType;
 import com.cloud.utils.crypt.DBEncryptionUtil;
@@ -96,6 +99,28 @@ public class ImageStoreHelper {
             store.setName(store.getUuid());
         }
         store.setRole((DataStoreRole) params.get("role"));
+
+        if ("cifs".equalsIgnoreCase((String) params.get("protocol")) && details !=
null) {
+            String user = details.get("user");
+            String password = details.get("password");
+            String domain = details.get("domain");
+            String updatedPath = (String) params.get("url");
+
+            if (user == null || password == null) {
+                String errMsg = "Missing cifs user and password details. Add them as details
parameter.";
+                throw new InvalidParameterValueException(errMsg);
+            } else {
+                try {
+                    password = DBEncryptionUtil.encrypt(URLEncoder.encode(password, "UTF-8"));
+                    details.put("password", password);
+                    updatedPath += "?user=" + user + "&password=" + password + "&domain="
+ domain;
+                } catch (UnsupportedEncodingException e) {
+                    throw new CloudRuntimeException("Error while generating the cifs url.
" + e.getMessage());
+                }
+                store.setUrl(updatedPath);
+            }
+        }
+
         store = imageStoreDao.persist(store);
 
         // persist details

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4961c138/engine/storage/src/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java
----------------------------------------------------------------------
diff --git a/engine/storage/src/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java
b/engine/storage/src/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java
index 95dc40b..c2bb31f 100644
--- a/engine/storage/src/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java
+++ b/engine/storage/src/org/apache/cloudstack/storage/volume/datastore/PrimaryDataStoreHelper.java
@@ -18,6 +18,8 @@
  */
 package org.apache.cloudstack.storage.volume.datastore;
 
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
 import java.util.List;
 import java.util.Map;
 
@@ -36,13 +38,17 @@ import com.cloud.agent.api.StoragePoolInfo;
 import com.cloud.capacity.Capacity;
 import com.cloud.capacity.CapacityVO;
 import com.cloud.capacity.dao.CapacityDao;
+import com.cloud.exception.InvalidParameterValueException;
 import com.cloud.storage.DataStoreRole;
 import com.cloud.storage.ScopeType;
 import com.cloud.hypervisor.Hypervisor.HypervisorType;
 import com.cloud.storage.StorageManager;
 import com.cloud.storage.StoragePoolHostVO;
 import com.cloud.storage.StoragePoolStatus;
+import com.cloud.storage.Storage.StoragePoolType;
 import com.cloud.storage.dao.StoragePoolHostDao;
+import com.cloud.utils.UriUtils;
+import com.cloud.utils.crypt.DBEncryptionUtil;
 import com.cloud.utils.db.TransactionLegacy;
 import com.cloud.utils.exception.CloudRuntimeException;
 
@@ -86,6 +92,29 @@ public class PrimaryDataStoreHelper {
         dataStoreVO.setHypervisor(params.getHypervisorType());
 
         Map<String, String> details = params.getDetails();
+        if (params.getType() == StoragePoolType.SMB && details != null) {
+            String user = details.get("user");
+            String password = details.get("password");
+            String domain = details.get("domain");
+            String updatedPath = params.getPath();
+
+            if (user == null || password == null) {
+                String errMsg = "Missing cifs user and password details. Add them as details
parameter.";
+                s_logger.warn(errMsg);
+                throw new InvalidParameterValueException(errMsg);
+            } else {
+                try {
+                    password = DBEncryptionUtil.encrypt(URLEncoder.encode(password, "UTF-8"));
+                    details.put("password", password);
+                    updatedPath += "?user=" + user + "&password=" + password + "&domain="
+ domain;
+                } catch (UnsupportedEncodingException e) {
+                    throw new CloudRuntimeException("Error while generating the cifs url.
" + e.getMessage());
+                }
+            }
+
+            dataStoreVO.setPath(updatedPath);
+        }
+
         String tags = params.getTags();
         if (tags != null) {
             String[] tokens = tags.split(",");

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4961c138/server/src/com/cloud/api/query/dao/ImageStoreJoinDaoImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/query/dao/ImageStoreJoinDaoImpl.java b/server/src/com/cloud/api/query/dao/ImageStoreJoinDaoImpl.java
index 447a1ad..23cde00 100644
--- a/server/src/com/cloud/api/query/dao/ImageStoreJoinDaoImpl.java
+++ b/server/src/com/cloud/api/query/dao/ImageStoreJoinDaoImpl.java
@@ -86,7 +86,7 @@ public class ImageStoreJoinDaoImpl extends GenericDaoBase<ImageStoreJoinVO,
Long
         osResponse.setZoneName(ids.getZoneName());
 
         String detailName = ids.getDetailName();
-        if ( detailName != null && detailName.length() > 0 ){
+        if ( detailName != null && detailName.length() > 0 && !detailName.equals(ApiConstants.PASSWORD))
{
             String detailValue = ids.getDetailValue();
             if (detailName.equals(ApiConstants.KEY) || detailName.equals(ApiConstants.S3_SECRET_KEY))
{
                 detailValue = DBEncryptionUtil.decrypt(detailValue);
@@ -105,7 +105,7 @@ public class ImageStoreJoinDaoImpl extends GenericDaoBase<ImageStoreJoinVO,
Long
     @Override
     public ImageStoreResponse setImageStoreResponse(ImageStoreResponse response, ImageStoreJoinVO
ids) {
         String detailName = ids.getDetailName();
-        if ( detailName != null && detailName.length() > 0 ){
+        if ( detailName != null && detailName.length() > 0 && !detailName.equals(ApiConstants.PASSWORD))
{
             String detailValue = ids.getDetailValue();
             if (detailName.equals(ApiConstants.KEY) || detailName.equals(ApiConstants.S3_SECRET_KEY))
{
                 detailValue = DBEncryptionUtil.decrypt(detailValue);

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4961c138/ui/scripts/sharedFunctions.js
----------------------------------------------------------------------
diff --git a/ui/scripts/sharedFunctions.js b/ui/scripts/sharedFunctions.js
index b9dc2f3..2a15967 100644
--- a/ui/scripts/sharedFunctions.js
+++ b/ui/scripts/sharedFunctions.js
@@ -1253,7 +1253,7 @@ var processPropertiesInImagestoreObject = function(jsonObj) {
         	url += 'cifs://';
         }
         
-        url += (server + path + '?user=' + smbUsername + '&password=' + smbPassword +
'&domain=' + smbDomain);
+        url += (server + path);
                
         return url;
     }

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4961c138/ui/scripts/system.js
----------------------------------------------------------------------
diff --git a/ui/scripts/system.js b/ui/scripts/system.js
index 743427b..500a339 100644
--- a/ui/scripts/system.js
+++ b/ui/scripts/system.js
@@ -14759,7 +14759,10 @@
                                     var path = args.data.path;
                                     if (path.substring(0, 1) != "/")
                                         path = "/" + path;
-                                    url = smbURL(server, path, args.data.smbUsername, args.data.smbPassword,
args.data.smbDomain);                                
+                                    url = smbURL(server, path);
+                                    array1.push("&details[0].user=" + args.data.smbUsername);
+                                    array1.push("&details[1].password=" + todb(args.data.smbPassword));
+                                    array1.push("&details[2].domain=" + args.data.smbDomain);
                                 } else if (args.data.protocol == "PreSetup") {          
                         
                                     var path = args.data.path;
                                     if (path.substring(0, 1) != "/")
@@ -16157,12 +16160,18 @@
                                         	var zoneid = args.data.zoneid;
                                             var nfs_server = args.data.nfsServer;
                                             var path = args.data.path;
-                                            var url = smbURL(nfs_server, path, args.data.smbUsername,
args.data.smbPassword, args.data.smbDomain);
+                                            var url = smbURL(nfs_server, path);
 
                                             $.extend(data, {
                                                 provider: args.data.provider,
                                                 zoneid: zoneid,
-                                                url: url
+                                                url: url,
+                                                'details[0].key': 'user',
+                                                'details[0].value': args.data.smbUsername,
+                                                'details[1].key': 'password',
+                                                'details[1].value': args.data.smbPassword,
+                                                'details[2].key': 'domain',
+                                                'details[2].value': args.data.smbDomain
                                             });
 
                                             $.ajax({

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4961c138/ui/scripts/zoneWizard.js
----------------------------------------------------------------------
diff --git a/ui/scripts/zoneWizard.js b/ui/scripts/zoneWizard.js
index b26c8bf..006bf7d 100755
--- a/ui/scripts/zoneWizard.js
+++ b/ui/scripts/zoneWizard.js
@@ -4128,7 +4128,10 @@
                     	var path = args.data.primaryStorage.path;
                         if (path.substring(0, 1) != "/")
                             path = "/" + path;
-                        url = smbURL(server, path, args.data.primaryStorage.smbUsername,
args.data.primaryStorage.smbPassword, args.data.primaryStorage.smbDomain);
+                        url = smbURL(server, path);
+                        array1.push("&details[0].user=" + args.data.primaryStorage.smbUsername);
+                        array1.push("&details[1].password=" + todb(args.data.primaryStorage.smbPassword));
+                        array1.push("&details[2].domain=" + args.data.primaryStorage.smbDomain);
                     } else if (args.data.primaryStorage.protocol == "PreSetup") {       
                
                         var path = args.data.primaryStorage.path;
                         if (path.substring(0, 1) != "/")
@@ -4237,12 +4240,18 @@
                     } else if (args.data.secondaryStorage.provider == 'SMB') {
                         var nfs_server = args.data.secondaryStorage.nfsServer;
                         var path = args.data.secondaryStorage.path;
-                        var url = smbURL(nfs_server, path, args.data.secondaryStorage.smbUsername,
args.data.secondaryStorage.smbPassword, args.data.secondaryStorage.smbDomain);
+                        var url = smbURL(nfs_server, path);
 
                         $.extend(data, {
                             provider: args.data.secondaryStorage.provider,
                             zoneid: args.data.returnedZone.id,
-                            url: url
+                            url: url,
+                            'details[0].key': 'user',
+                            'details[0].value': args.data.secondaryStorage.smbUsername,
+                            'details[1].key': 'password',
+                            'details[1].value': args.data.secondaryStorage.smbPassword,
+                            'details[2].key': 'domain',
+                            'details[2].value': args.data.secondaryStorage.smbDomain
                         });
 
                         $.ajax({

http://git-wip-us.apache.org/repos/asf/cloudstack/blob/4961c138/utils/src/com/cloud/utils/UriUtils.java
----------------------------------------------------------------------
diff --git a/utils/src/com/cloud/utils/UriUtils.java b/utils/src/com/cloud/utils/UriUtils.java
index 9261b07..67b86b8 100644
--- a/utils/src/com/cloud/utils/UriUtils.java
+++ b/utils/src/com/cloud/utils/UriUtils.java
@@ -111,17 +111,8 @@ public class UriUtils {
 
     public static String getCifsUriParametersProblems(URI uri) {
         if (!UriUtils.hostAndPathPresent(uri)) {
-            String errMsg = "cifs URI missing host and/or path.  "
-                    + " Make sure it's of the format "
-                    + "cifs://hostname/path?user=<username>&password=<password>";
-            s_logger.warn(errMsg);
-            return errMsg;
-        }
-        if (!UriUtils.cifsCredentialsPresent(uri))
-        {
-            String errMsg = "cifs URI missing user and password details. "
-                    + "Add them as query parameters, e.g. "
-                    + "cifs://example.com/some_share?user=foo&password=bar";
+            String errMsg = "cifs URI missing host and/or path. Make sure it is "
+                    + " of the format cifs://hostname/path";
             s_logger.warn(errMsg);
             return errMsg;
         }
@@ -194,11 +185,13 @@ public class UriUtils {
 
     private static List<NameValuePair> getUserDetails(String query) {
         List<NameValuePair> details = new ArrayList<NameValuePair>();
-        StringTokenizer allParams = new StringTokenizer(query, "&");
-        while (allParams.hasMoreTokens()) {
-            String param = allParams.nextToken();
-            details.add(new BasicNameValuePair(param.substring(0, param.indexOf("=")),
-                    param.substring(param.indexOf("=") + 1)));
+        if (query != null && !query.isEmpty()) {
+            StringTokenizer allParams = new StringTokenizer(query, "&");
+            while (allParams.hasMoreTokens()) {
+                String param = allParams.nextToken();
+                details.add(new BasicNameValuePair(param.substring(0, param.indexOf("=")),
+                        param.substring(param.indexOf("=") + 1)));
+            }
         }
 
         return details;


Mime
View raw message