@@ -106,11 +106,15 @@ public void createAsync(DataStore dataStore, DataObject dataObject, AsyncComplet
106106 if (callback == null ) {
107107 throw new InvalidParameterValueException ("createAsync: callback should not be null" );
108108 }
109+ if (!isValidName (dataObject .getName ())) {
110+ errMsg = "createAsync: Invalid dataObject name [" + dataObject .getName () + "]. It must start with a letter and can only contain letters, digits, and underscores, and be up to 200 characters long." ;
111+ s_logger .error (errMsg );
112+ throw new InvalidParameterValueException (errMsg );
113+ }
109114 try {
110115 s_logger .info ("createAsync: Started for data store name [{}] and data object name [{}] of type [{}]" , dataStore .getName (), dataObject .getName (), dataObject .getType ());
111-
112116 StoragePoolVO storagePool = storagePoolDao .findById (dataStore .getId ());
113- if (storagePool == null ) {
117+ if (storagePool == null ) {
114118 s_logger .error ("createCloudStackVolume : Storage Pool not found for id: " + dataStore .getId ());
115119 throw new CloudRuntimeException ("createCloudStackVolume : Storage Pool not found for id: " + dataStore .getId ());
116120 }
@@ -135,6 +139,16 @@ public void createAsync(DataStore dataStore, DataObject dataObject, AsyncComplet
135139 }
136140 }
137141
142+ public boolean isValidName (String name ) {
143+ // Check for null and length constraint first
144+ if (name == null || name .length () > 200 ) {
145+ return false ;
146+ }
147+ // Regex: Starts with a letter, followed by letters, digits, or underscores
148+ String regex = "^[a-zA-Z][a-zA-Z0-9_]*$" ;
149+ return name .matches (regex );
150+ }
151+
138152 private String createCloudStackVolumeForTypeVolume (DataStore dataStore , VolumeInfo volumeObject ) {
139153 StoragePoolVO storagePool = storagePoolDao .findById (dataStore .getId ());
140154 if (storagePool == null ) {
@@ -248,7 +262,7 @@ public boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore
248262 }
249263 try {
250264 StoragePoolVO storagePool = storagePoolDao .findById (dataStore .getId ());
251- if (storagePool == null ) {
265+ if (storagePool == null ) {
252266 s_logger .error ("grantAccess : Storage Pool not found for id: " + dataStore .getId ());
253267 throw new CloudRuntimeException ("grantAccess : Storage Pool not found for id: " + dataStore .getId ());
254268 }
@@ -259,7 +273,7 @@ public boolean grantAccess(DataObject dataObject, Host host, DataStore dataStore
259273
260274 if (dataObject .getType () == DataObjectType .VOLUME ) {
261275 VolumeVO volumeVO = volumeDao .findById (dataObject .getId ());
262- if (volumeVO == null ) {
276+ if (volumeVO == null ) {
263277 s_logger .error ("grantAccess : Cloud Stack Volume not found for id: " + dataObject .getId ());
264278 throw new CloudRuntimeException ("grantAccess : Cloud Stack Volume not found for id: " + dataObject .getId ());
265279 }
@@ -281,12 +295,12 @@ private void grantAccessForVolume(StoragePoolVO storagePool, VolumeVO volumeVO,
281295 String svmName = details .get (Constants .SVM_NAME );
282296 long scopeId = (storagePool .getScope () == ScopeType .CLUSTER ) ? host .getClusterId () : host .getDataCenterId ();
283297
284- if (ProtocolType .ISCSI .name ().equalsIgnoreCase (details .get (Constants .PROTOCOL ))) {
298+ if (ProtocolType .ISCSI .name ().equalsIgnoreCase (details .get (Constants .PROTOCOL ))) {
285299 String accessGroupName = Utility .getIgroupName (svmName , scopeId );
286300 CloudStackVolume cloudStackVolume = getCloudStackVolumeByName (storageStrategy , svmName , volumeVO .getPath ());
287301 s_logger .info ("grantAccessForVolume: Retrieved LUN [{}] details for volume [{}]" , cloudStackVolume .getLun ().getName (), volumeVO .getName ());
288302 AccessGroup accessGroup = getAccessGroupByName (storageStrategy , svmName , accessGroupName );
289- if (!hostInitiatorFoundInIgroup (host .getStorageUrl (), accessGroup .getIgroup ())) {
303+ if (!hostInitiatorFoundInIgroup (host .getStorageUrl (), accessGroup .getIgroup ())) {
290304 s_logger .error ("grantAccess: initiator [{}] is not present in iGroup [{}]" , host .getStorageUrl (), accessGroupName );
291305 throw new CloudRuntimeException ("grantAccess: initiator [" + host .getStorageUrl () + "] is not present in iGroup [" + accessGroupName + "]" );
292306 }
@@ -326,7 +340,7 @@ public void revokeAccess(DataObject dataObject, Host host, DataStore dataStore)
326340 }
327341 try {
328342 StoragePoolVO storagePool = storagePoolDao .findById (dataStore .getId ());
329- if (storagePool == null ) {
343+ if (storagePool == null ) {
330344 s_logger .error ("revokeAccess : Storage Pool not found for id: " + dataStore .getId ());
331345 throw new CloudRuntimeException ("revokeAccess : Storage Pool not found for id: " + dataStore .getId ());
332346 }
@@ -337,7 +351,7 @@ public void revokeAccess(DataObject dataObject, Host host, DataStore dataStore)
337351
338352 if (dataObject .getType () == DataObjectType .VOLUME ) {
339353 VolumeVO volumeVO = volumeDao .findById (dataObject .getId ());
340- if (volumeVO == null ) {
354+ if (volumeVO == null ) {
341355 s_logger .error ("revokeAccess : Cloud Stack Volume not found for id: " + dataObject .getId ());
342356 throw new CloudRuntimeException ("revokeAccess : Cloud Stack Volume not found for id: " + dataObject .getId ());
343357 }
@@ -358,12 +372,12 @@ private void revokeAccessForVolume(StoragePoolVO storagePool, VolumeVO volumeVO,
358372 String svmName = details .get (Constants .SVM_NAME );
359373 long scopeId = (storagePool .getScope () == ScopeType .CLUSTER ) ? host .getClusterId () : host .getDataCenterId ();
360374
361- if (ProtocolType .ISCSI .name ().equalsIgnoreCase (details .get (Constants .PROTOCOL ))) {
375+ if (ProtocolType .ISCSI .name ().equalsIgnoreCase (details .get (Constants .PROTOCOL ))) {
362376 String accessGroupName = Utility .getIgroupName (svmName , scopeId );
363377 CloudStackVolume cloudStackVolume = getCloudStackVolumeByName (storageStrategy , svmName , volumeVO .getPath ());
364378 AccessGroup accessGroup = getAccessGroupByName (storageStrategy , svmName , accessGroupName );
365379 //TODO check if initiator does exits in igroup, will throw the error ?
366- if (!hostInitiatorFoundInIgroup (host .getStorageUrl (), accessGroup .getIgroup ())) {
380+ if (!hostInitiatorFoundInIgroup (host .getStorageUrl (), accessGroup .getIgroup ())) {
367381 s_logger .error ("revokeAccessForVolume: initiator [{}] is not present in iGroup [{}]" , host .getStorageUrl (), accessGroupName );
368382 return ;
369383 }
@@ -381,7 +395,7 @@ private CloudStackVolume getCloudStackVolumeByName(StorageStrategy storageStrate
381395 getCloudStackVolumeMap .put (Constants .NAME , cloudStackVolumeName );
382396 getCloudStackVolumeMap .put (Constants .SVM_DOT_NAME , svmName );
383397 CloudStackVolume cloudStackVolume = storageStrategy .getCloudStackVolume (getCloudStackVolumeMap );
384- if (cloudStackVolume == null || cloudStackVolume .getLun () == null || cloudStackVolume .getLun ().getName () == null ) {
398+ if (cloudStackVolume == null || cloudStackVolume .getLun () == null || cloudStackVolume .getLun ().getName () == null ) {
385399 s_logger .error ("getCloudStackVolumeByName: Failed to get LUN details [{}]" , cloudStackVolumeName );
386400 throw new CloudRuntimeException ("getCloudStackVolumeByName: Failed to get LUN [" + cloudStackVolumeName + "]" );
387401 }
0 commit comments