@@ -123,7 +123,7 @@ import Ouroboros.Network.Subscription (DnsSubscriptionTarget (..),
123
123
124
124
import Control.Concurrent (killThread , mkWeakThreadId , myThreadId , getNumCapabilities )
125
125
import Control.Concurrent.Class.MonadSTM.Strict
126
- import Control.Exception (try , IOException )
126
+ import Control.Exception (try , Exception , IOException )
127
127
import qualified Control.Exception as Exception
128
128
import Control.Monad (forM , forM_ , unless , void , when )
129
129
import Control.Monad.Class.MonadThrow (MonadThrow (.. ))
@@ -185,34 +185,24 @@ runNode cmdPc = do
185
185
186
186
putStrLn $ " Node configuration: " <> show nc
187
187
188
- case shelleyVRFFile $ ncProtocolFiles nc of
189
- Just vrfFp -> do vrf <- runExceptT $ checkVRFFilePermissions (File vrfFp)
190
- case vrf of
191
- Left err -> Exception. throwIO err
192
- Right () ->
193
- pure ()
194
- Nothing -> pure ()
195
-
196
- eitherSomeProtocol <- runExceptT $ mkConsensusProtocol
197
- (ncProtocolConfig nc)
198
- -- TODO: Convert ncProtocolFiles to Maybe as relay nodes
199
- -- don't need these.
200
- (Just $ ncProtocolFiles nc)
201
-
202
- p :: SomeConsensusProtocol <-
203
- case eitherSomeProtocol of
204
- Left err -> Exception. throwIO err
205
- Right p -> pure p
206
-
207
- let networkMagic :: Api. NetworkMagic =
208
- case p of
209
- SomeConsensusProtocol _ runP ->
210
- let ProtocolInfo { pInfoConfig } = fst $ Api. protocolInfo @ IO runP
211
- in getNetworkMagic $ Consensus. configBlock pInfoConfig
212
-
213
- case p of
214
- SomeConsensusProtocol blockType runP ->
215
- handleNodeWithTracers cmdPc nc p networkMagic blockType runP
188
+ case ncProtocolFiles nc of
189
+ ProtocolFilepaths {shelleyVRFFile= Just vrfFp, isGroupPermissionChecked} ->
190
+ runThrowExceptT $
191
+ checkVRFFilePermissions isGroupPermissionChecked (File vrfFp)
192
+ _ -> pure ()
193
+
194
+ consensusProtocol <-
195
+ runThrowExceptT $
196
+ mkConsensusProtocol
197
+ (ncProtocolConfig nc)
198
+ -- TODO: Convert ncProtocolFiles to Maybe as relay nodes
199
+ -- don't need these.
200
+ (Just $ ncProtocolFiles nc)
201
+
202
+ handleNodeWithTracers cmdPc nc consensusProtocol
203
+
204
+ runThrowExceptT :: Exception e => ExceptT e IO a -> IO a
205
+ runThrowExceptT act = runExceptT act >>= either Exception. throwIO pure
216
206
217
207
-- | Workaround to ensure that the main thread throws an async exception on
218
208
-- receiving a SIGTERM signal.
@@ -233,17 +223,13 @@ installSigTermHandler = do
233
223
return ()
234
224
235
225
handleNodeWithTracers
236
- :: ( TraceConstraints blk
237
- , Api. Protocol IO blk
238
- )
239
- => PartialNodeConfiguration
226
+ :: PartialNodeConfiguration
240
227
-> NodeConfiguration
241
228
-> SomeConsensusProtocol
242
- -> Api. NetworkMagic
243
- -> Api. BlockType blk
244
- -> Api. ProtocolInfoArgs blk
245
229
-> IO ()
246
- handleNodeWithTracers cmdPc nc0 p networkMagic blockType runP = do
230
+ handleNodeWithTracers cmdPc nc0 p@ (SomeConsensusProtocol blockType runP) = do
231
+ let ProtocolInfo {pInfoConfig} = fst $ Api. protocolInfo @ IO runP
232
+ networkMagic :: Api. NetworkMagic = getNetworkMagic $ Consensus. configBlock pInfoConfig
247
233
-- This IORef contains node kernel structure which holds node kernel.
248
234
-- Used for ledger queries and peer connection status.
249
235
nodeKernelData <- mkNodeKernelData
@@ -913,17 +899,18 @@ canonDbPath NodeConfiguration{ncDatabaseFile = nodeDatabaseFps} =
913
899
914
900
-- | Make sure the VRF private key file is readable only
915
901
-- by the current process owner the node is running under.
916
- checkVRFFilePermissions :: File content direction -> ExceptT VRFPrivateKeyFilePermissionError IO ()
902
+ checkVRFFilePermissions :: IsGroupPermissionChecked -> File content direction -> ExceptT VRFPrivateKeyFilePermissionError IO ()
917
903
#ifdef UNIX
918
- checkVRFFilePermissions (File vrfPrivKey) = do
904
+ checkVRFFilePermissions isGroupPermissionChecked (File vrfPrivKey) = do
919
905
fs <- liftIO $ getFileStatus vrfPrivKey
920
906
let fm = fileMode fs
921
907
-- Check the the VRF private key file does not give read/write/exec permissions to others.
922
- when (hasOtherPermissions fm)
923
- ( left $ OtherPermissionsExist vrfPrivKey)
908
+ when (hasOtherPermissions fm) $
909
+ left $ OtherPermissionsExist vrfPrivKey
924
910
-- Check the the VRF private key file does not give read/write/exec permissions to any group.
925
- when (hasGroupPermissions fm)
926
- (left $ GroupPermissionsExist vrfPrivKey)
911
+ when (isGroupPermissionChecked == CheckFileGroupPermission ) $
912
+ when (hasGroupPermissions fm) $
913
+ left $ GroupPermissionsExist vrfPrivKey
927
914
where
928
915
hasPermission :: FileMode -> FileMode -> Bool
929
916
hasPermission fModeA fModeB = fModeA `intersectFileModes` fModeB /= nullFileMode
@@ -934,7 +921,7 @@ checkVRFFilePermissions (File vrfPrivKey) = do
934
921
hasGroupPermissions :: FileMode -> Bool
935
922
hasGroupPermissions fm' = fm' `hasPermission` groupModes
936
923
#else
937
- checkVRFFilePermissions (File vrfPrivKey) = do
924
+ checkVRFFilePermissions _ (File vrfPrivKey) = do
938
925
attribs <- liftIO $ getFileAttributes vrfPrivKey
939
926
-- https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea
940
927
-- https://docs.microsoft.com/en-us/windows/win32/fileio/file-access-rights-constants
0 commit comments