@@ -13,7 +13,7 @@ module Msf::Modules::Metadata::Store
13
13
UserMetaDataFile = 'modules_metadata.pstore'
14
14
15
15
#
16
- # Initializes from user store (under ~/.msf4) if it exists. else base file (under $INSTALL_ROOT/db) is copied and loaded.
16
+ # Initializes from user store (under ~/store/ .msf4) if it exists. else base file (under $INSTALL_ROOT/db) is copied and loaded.
17
17
#
18
18
def init_store
19
19
load_metadata
@@ -23,8 +23,12 @@ def init_store
23
23
# Update the module meta cache disk store
24
24
#
25
25
def update_store
26
- @store . transaction do
27
- @store [ :module_metadata ] = @module_metadata_cache
26
+ begin
27
+ @store . transaction do
28
+ @store [ :module_metadata ] = @module_metadata_cache
29
+ end
30
+ rescue Excepion => e
31
+ elog ( "Unable to update metadata store: #{ e . message } " )
28
32
end
29
33
end
30
34
@@ -45,10 +49,12 @@ def load_metadata
45
49
46
50
# Try to handle the scenario where the file is corrupted
47
51
if ( retries < 2 && ::File . exist? ( @path_to_user_metadata ) )
48
- FileUtils . remove ( @path_to_user_metadata , true )
52
+ elog ( 'Possible corrupt user metadata store, attempting restore' )
53
+ FileUtils . remove ( @path_to_user_metadata )
49
54
retry
50
55
else
51
- @console . print_warning ( "Unable to load module metadata: #{ e . message } " )
56
+ @console . print_warning ( 'Unable to load module metadata from disk see error log' )
57
+ elog ( "Unable to load module metadata: #{ e . message } " )
52
58
end
53
59
end
54
60
@@ -69,28 +75,38 @@ def validate_data(copied)
69
75
70
76
def configure_user_store
71
77
copied = false
72
- @path_to_user_metadata = :: File . join ( Msf :: Config . config_directory , UserMetaDataFile )
78
+ @path_to_user_metadata = get_user_store
73
79
path_to_base_metadata = ::File . join ( Msf ::Config . install_root , "db" , BaseMetaDataFile )
80
+ user_file_exists = ::File . exist? ( @path_to_user_metadata )
81
+ base_file_exists = ::File . exist? ( path_to_base_metadata )
74
82
75
- if ( !:: File . exist? ( path_to_base_metadata ) )
83
+ if ( !base_file_exists )
76
84
wlog ( "Missing base module metadata file: #{ path_to_base_metadata } " )
77
- else
78
- if ( !::File . exist? ( @path_to_user_metadata ) )
79
- FileUtils . cp ( path_to_base_metadata , @path_to_user_metadata )
80
- copied = true
81
- dlog ( 'Created user based module store' )
82
-
83
- # Update the user based module store if an updated base file is created/pushed
84
- elsif ( ::File . mtime ( path_to_base_metadata ) . to_i > ::File . mtime ( @path_to_user_metadata ) . to_i )
85
- FileUtils . remove ( @path_to_user_metadata , true )
86
- FileUtils . cp ( path_to_base_metadata , @path_to_user_metadata )
87
- copied = true
88
- dlog ( 'Updated user based module store' )
89
- end
85
+ return copied if !user_file_exists
86
+ end
87
+
88
+ if ( !user_file_exists )
89
+ FileUtils . cp ( path_to_base_metadata , @path_to_user_metadata )
90
+ copied = true
91
+
92
+ dlog ( 'Created user based module store' )
93
+
94
+ # Update the user based module store if an updated base file is created/pushed
95
+ elsif ( ::File . mtime ( path_to_base_metadata ) . to_i > ::File . mtime ( @path_to_user_metadata ) . to_i )
96
+ FileUtils . remove ( @path_to_user_metadata )
97
+ FileUtils . cp ( path_to_base_metadata , @path_to_user_metadata )
98
+ copied = true
99
+ dlog ( 'Updated user based module store' )
90
100
end
91
101
92
102
return copied
93
103
end
94
104
105
+ def get_user_store
106
+ store_dir = ::File . join ( Msf ::Config . config_directory , "store" )
107
+ FileUtils . mkdir ( store_dir ) if !::File . exist? ( store_dir )
108
+ return ::File . join ( store_dir , UserMetaDataFile )
109
+ end
110
+
95
111
end
96
112
0 commit comments