Browse Source

Merge pull request #12916 from shamser/issue22677

HPCC-22677 Extend DFUInfo Service to support IsRestricted

Reviewed-By: Anthony Fishbeck <anthony.fishbeck@lexisnexis.com>
Reviewed-By: Richard Chapman <rchapman@hpccsystems.com>
Richard Chapman 5 years ago
parent
commit
80b88d0fac

+ 9 - 1
dali/base/dadfs.cpp

@@ -2998,7 +2998,15 @@ public:
                 IERRLOG("setProtect - cannot protect %s (no connection in file)",owner?owner:"");
                 IERRLOG("setProtect - cannot protect %s (no connection in file)",owner?owner:"");
         }
         }
     }
     }
-
+    virtual bool isRestrictedAccess() const override
+    {
+        return root->getPropBool("@restricted", false);
+    }
+    virtual void setRestrictedAccess(bool restricted) override
+    {
+        DistributedFilePropertyLock lock(this);
+        root->setPropBool("@restricted", restricted);
+    }
     virtual IDistributedSuperFileIterator *getOwningSuperFiles(IDistributedFileTransaction *_transaction)
     virtual IDistributedSuperFileIterator *getOwningSuperFiles(IDistributedFileTransaction *_transaction)
     {
     {
         CriticalBlock block(sect);
         CriticalBlock block(sect);

+ 2 - 1
dali/base/dadfs.hpp

@@ -394,7 +394,8 @@ interface IDistributedFile: extends IInterface
                                                                                             // sets or clears deletion protection
                                                                                             // sets or clears deletion protection
                                                                                             // returns true if locked (by anyone) after action
                                                                                             // returns true if locked (by anyone) after action
                                                                                             // if callerid NULL and protect=false, clears all
                                                                                             // if callerid NULL and protect=false, clears all
-
+    virtual bool isRestrictedAccess() const = 0;
+    virtual void setRestrictedAccess(bool restricted) = 0;
     virtual unsigned setDefaultTimeout(unsigned timems) = 0;                                // sets default timeout for SDS connections and locking
     virtual unsigned setDefaultTimeout(unsigned timems) = 0;                                // sets default timeout for SDS connections and locking
                                                                                             // returns previous value
                                                                                             // returns previous value
 
 

+ 12 - 2
esp/scm/ws_dfu.ecm

@@ -31,6 +31,14 @@ ESPenum DFUChangeProtection : int
     Unprotect(2, "Unprotect")
     Unprotect(2, "Unprotect")
 };
 };
 
 
+
+ESPenum DFUChangeRestriction : int
+{
+    NoChange(0, "No Change"),
+    Restrict(1, "Restrict"),
+    NotRestricted(2, "Unrestricted")
+};
+
 ESPenum DFUDefFileFormat : string
 ESPenum DFUDefFileFormat : string
 {
 {
     xml("xml"),
     xml("xml"),
@@ -201,6 +209,7 @@ ESPStruct [nil_remove] DFUFileDetail
     [min_ver("1.22")] int64 CompressedFileSize;
     [min_ver("1.22")] int64 CompressedFileSize;
     [min_ver("1.34")] string PercentCompressed;
     [min_ver("1.34")] string PercentCompressed;
     [min_ver("1.22")] bool IsCompressed(false);
     [min_ver("1.22")] bool IsCompressed(false);
+    [min_ver("1.53")] bool IsRestricted(false);
     [min_ver("1.28")] bool BrowseData(true);
     [min_ver("1.28")] bool BrowseData(true);
     [min_ver("1.37"), json_inline(1)] string jsonInfo;
     [min_ver("1.37"), json_inline(1)] string jsonInfo;
     [min_ver("1.37")] binary binInfo;
     [min_ver("1.37")] binary binInfo;
@@ -364,6 +373,7 @@ DFUInfoRequest
     [min_ver("1.37")] bool IncludeJsonTypeInfo(false);
     [min_ver("1.37")] bool IncludeJsonTypeInfo(false);
     [min_ver("1.37")] bool IncludeBinTypeInfo(false);
     [min_ver("1.37")] bool IncludeBinTypeInfo(false);
     [min_ver("1.39")] ESPenum DFUChangeProtection Protect(0);
     [min_ver("1.39")] ESPenum DFUChangeProtection Protect(0);
+    [min_ver("1.53")] ESPenum DFUChangeRestriction Restrict(0);
 };
 };
 
 
 ESPresponse
 ESPresponse
@@ -976,8 +986,8 @@ ESPresponse [exceptions_inline, nil_remove] DFUFilePublishResponse
 //  ===========================================================================
 //  ===========================================================================
 ESPservice [
 ESPservice [
     auth_feature("DEFERRED"),
     auth_feature("DEFERRED"),
-    version("1.52"),
-    default_client_version("1.52"),
+    version("1.53"),
+    default_client_version("1.53"),
     noforms,
     noforms,
     exceptions_inline("./smc_xslt/exceptions.xslt")] WsDfu
     exceptions_inline("./smc_xslt/exceptions.xslt")] WsDfu
 {
 {

+ 11 - 5
esp/services/ws_dfu/ws_dfuService.cpp

@@ -371,15 +371,15 @@ bool CWsDfuEx::onDFUInfo(IEspContext &context, IEspDFUInfoRequest &req, IEspDFUI
             double version = context.getClientVersion();
             double version = context.getClientVersion();
             if (version < 1.38)
             if (version < 1.38)
                 doGetFileDetails(context, userdesc.get(), req.getFileName(), req.getCluster(), req.getQuerySet(), req.getQuery(), req.getFileDesc(),
                 doGetFileDetails(context, userdesc.get(), req.getFileName(), req.getCluster(), req.getQuerySet(), req.getQuery(), req.getFileDesc(),
-                    req.getIncludeJsonTypeInfo(), req.getIncludeBinTypeInfo(), req.getProtect(), resp.updateFileDetail());
+                    req.getIncludeJsonTypeInfo(), req.getIncludeBinTypeInfo(), req.getProtect(), req.getRestrict(), resp.updateFileDetail());
             else
             else
                 doGetFileDetails(context, userdesc.get(), req.getName(), req.getCluster(), req.getQuerySet(), req.getQuery(), req.getFileDesc(),
                 doGetFileDetails(context, userdesc.get(), req.getName(), req.getCluster(), req.getQuerySet(), req.getQuery(), req.getFileDesc(),
-                    req.getIncludeJsonTypeInfo(), req.getIncludeBinTypeInfo(), req.getProtect(), resp.updateFileDetail());
+                    req.getIncludeJsonTypeInfo(), req.getIncludeBinTypeInfo(), req.getProtect(), req.getRestrict(), resp.updateFileDetail());
         }
         }
         else
         else
         {
         {
             doGetFileDetails(context, userdesc.get(), req.getName(), req.getCluster(), req.getQuerySet(), req.getQuery(), NULL,
             doGetFileDetails(context, userdesc.get(), req.getName(), req.getCluster(), req.getQuerySet(), req.getQuery(), NULL,
-                    req.getIncludeJsonTypeInfo(), req.getIncludeBinTypeInfo(), req.getProtect(), resp.updateFileDetail());
+                    req.getIncludeJsonTypeInfo(), req.getIncludeBinTypeInfo(), req.getProtect(), req.getRestrict(), resp.updateFileDetail());
         }
         }
     }
     }
     catch(IException* e)
     catch(IException* e)
@@ -1958,7 +1958,7 @@ void CWsDfuEx::queryFieldNames(IEspContext &context, const char *fileName, const
 
 
 void CWsDfuEx::doGetFileDetails(IEspContext &context, IUserDescriptor *udesc, const char *name, const char *cluster,
 void CWsDfuEx::doGetFileDetails(IEspContext &context, IUserDescriptor *udesc, const char *name, const char *cluster,
     const char *querySet, const char *query, const char *description, bool includeJsonTypeInfo, bool includeBinTypeInfo,
     const char *querySet, const char *query, const char *description, bool includeJsonTypeInfo, bool includeBinTypeInfo,
-    CDFUChangeProtection protect, IEspDFUFileDetail &FileDetails)
+    CDFUChangeProtection protect, CDFUChangeRestriction changeRestriction, IEspDFUFileDetail &FileDetails)
 {
 {
     if (!name || !*name)
     if (!name || !*name)
         throw MakeStringException(ECLWATCH_MISSING_PARAMS, "File name required");
         throw MakeStringException(ECLWATCH_MISSING_PARAMS, "File name required");
@@ -1988,6 +1988,11 @@ void CWsDfuEx::doGetFileDetails(IEspContext &context, IUserDescriptor *udesc, co
             protectBy.set("hpcc");
             protectBy.set("hpcc");
         df->setProtect(protectBy.str(), protect == CDFUChangeProtection_Protect ? true : false);
         df->setProtect(protectBy.str(), protect == CDFUChangeProtection_Protect ? true : false);
     }
     }
+    if (changeRestriction != CDFUChangeRestriction_NoChange)
+    {
+        context.ensureFeatureAccess("DFURestrictedAccess", SecAccess_Write, ECLWATCH_DFU_ACCESS_DENIED, "DFURestrictedAccess: Permission denied.");
+        df->setRestrictedAccess(changeRestriction==CDFUChangeRestriction_Restrict);
+    }
 
 
     offset_t size=queryDistributedFileSystem().getSize(df), recordSize=df->queryAttributes().getPropInt64("@recordSize",0);
     offset_t size=queryDistributedFileSystem().getSize(df), recordSize=df->queryAttributes().getPropInt64("@recordSize",0);
 
 
@@ -2075,7 +2080,8 @@ void CWsDfuEx::doGetFileDetails(IEspContext &context, IUserDescriptor *udesc, co
             }
             }
         }
         }
     }
     }
-
+    if (version >= 1.53)
+        FileDetails.setIsRestricted(df->isRestrictedAccess());
     if (version >= 1.38)
     if (version >= 1.38)
         FileDetails.setRecordSizeInt64(recordSize);
         FileDetails.setRecordSizeInt64(recordSize);
     comma c2(recordSize);
     comma c2(recordSize);

+ 1 - 1
esp/services/ws_dfu/ws_dfuService.hpp

@@ -197,7 +197,7 @@ private:
     bool doLogicalFileSearch(IEspContext &context, IUserDescriptor* udesc, IEspDFUQueryRequest & req, IEspDFUQueryResponse & resp);
     bool doLogicalFileSearch(IEspContext &context, IUserDescriptor* udesc, IEspDFUQueryRequest & req, IEspDFUQueryResponse & resp);
     void doGetFileDetails(IEspContext &context, IUserDescriptor* udesc, const char *name,const char *cluster,
     void doGetFileDetails(IEspContext &context, IUserDescriptor* udesc, const char *name,const char *cluster,
         const char *querySet, const char *query, const char *description, bool includeJsonTypeInfo, bool includeBinTypeInfo,
         const char *querySet, const char *query, const char *description, bool includeJsonTypeInfo, bool includeBinTypeInfo,
-        CDFUChangeProtection protect, IEspDFUFileDetail& FileDetails);
+        CDFUChangeProtection protect, CDFUChangeRestriction changeRestriction, IEspDFUFileDetail& FileDetails);
     bool createSpaceItemsByDate(IArrayOf<IEspSpaceItem>& SpaceItems, const char * interval, unsigned& yearFrom,
     bool createSpaceItemsByDate(IArrayOf<IEspSpaceItem>& SpaceItems, const char * interval, unsigned& yearFrom,
         unsigned& monthFrom, unsigned& dayFrom, unsigned& yearTo, unsigned& monthTo, unsigned& dayTo);
         unsigned& monthFrom, unsigned& dayFrom, unsigned& yearTo, unsigned& monthTo, unsigned& dayTo);
     bool setSpaceItemByScope(IArrayOf<IEspSpaceItem>& SpaceItems64, const char*scopeName, const char*logicalName, __int64 size);
     bool setSpaceItemByScope(IArrayOf<IEspSpaceItem>& SpaceItems64, const char*scopeName, const char*logicalName, __int64 size);