@@ -33,10 +33,10 @@ type Manager struct {
33
33
// are available for use. This map will start out not including any of
34
34
// lnd's sub-server permissions. Only when the LND build tags are
35
35
// obtained and OnLNDBuildTags is called will this map include the
36
- // available LND sub-server permissions. This map must only be accessed
37
- // once the permsMu mutex is held.
38
- perms map [ string ][]bakery. Op
39
- permsMu sync.RWMutex
36
+ // available LND sub-server permissions.
37
+ perms map [ string ][]bakery. Op
38
+
39
+ mu sync.RWMutex
40
40
}
41
41
42
42
// NewManager constructs a new Manager instance and collects any of the
@@ -105,8 +105,8 @@ func NewManager(withAllSubServers bool) (*Manager, error) {
105
105
// that it does not require a macaroon for validation. A URL is considered
106
106
// white-listed if it has no operations associated with a URL.
107
107
func (pm * Manager ) IsWhiteListedURL (url string ) bool {
108
- pm .permsMu .Lock ()
109
- defer pm .permsMu .Unlock ()
108
+ pm .mu .Lock ()
109
+ defer pm .mu .Unlock ()
110
110
111
111
ops , ok := pm .perms [url ]
112
112
@@ -118,8 +118,8 @@ func (pm *Manager) IsWhiteListedURL(url string) bool {
118
118
func (pm * Manager ) RegisterSubServer (name string ,
119
119
permissions map [string ][]bakery.Op , whiteListURLs map [string ]struct {}) {
120
120
121
- pm .permsMu .Lock ()
122
- defer pm .permsMu .Unlock ()
121
+ pm .mu .Lock ()
122
+ defer pm .mu .Unlock ()
123
123
124
124
pm .fixedPerms [name ] = permissions
125
125
@@ -142,8 +142,8 @@ func (pm *Manager) RegisterSubServer(name string,
142
142
// permissions to add to the main permissions list. This method should only
143
143
// be called once.
144
144
func (pm * Manager ) OnLNDBuildTags (lndBuildTags []string ) {
145
- pm .permsMu .Lock ()
146
- defer pm .permsMu .Unlock ()
145
+ pm .mu .Lock ()
146
+ defer pm .mu .Unlock ()
147
147
148
148
tagLookup := make (map [string ]bool )
149
149
for _ , t := range lndBuildTags {
@@ -170,8 +170,8 @@ func (pm *Manager) OnLNDBuildTags(lndBuildTags []string) {
170
170
// the uri is known to the manager. The second return parameter will be false
171
171
// if the URI is unknown to the manager.
172
172
func (pm * Manager ) URIPermissions (uri string ) ([]bakery.Op , bool ) {
173
- pm .permsMu .RLock ()
174
- defer pm .permsMu .RUnlock ()
173
+ pm .mu .RLock ()
174
+ defer pm .mu .RUnlock ()
175
175
176
176
ops , ok := pm .perms [uri ]
177
177
return ops , ok
@@ -182,8 +182,8 @@ func (pm *Manager) URIPermissions(uri string) ([]bakery.Op, bool) {
182
182
// are a list of URIs that match the regex and the boolean represents whether
183
183
// the given uri is in fact a regex.
184
184
func (pm * Manager ) MatchRegexURI (uriRegex string ) ([]string , bool ) {
185
- pm .permsMu .RLock ()
186
- defer pm .permsMu .RUnlock ()
185
+ pm .mu .RLock ()
186
+ defer pm .mu .RUnlock ()
187
187
188
188
// If the given uri string is one of our permissions, then it is not
189
189
// a regex.
@@ -215,8 +215,8 @@ func (pm *Manager) MatchRegexURI(uriRegex string) ([]string, bool) {
215
215
// manager is aware of. Optionally, readOnly can be set to true if only the
216
216
// read-only permissions should be returned.
217
217
func (pm * Manager ) ActivePermissions (readOnly bool ) []bakery.Op {
218
- pm .permsMu .RLock ()
219
- defer pm .permsMu .RUnlock ()
218
+ pm .mu .RLock ()
219
+ defer pm .mu .RUnlock ()
220
220
221
221
// De-dup the permissions and optionally apply the read-only filter.
222
222
dedupMap := make (map [string ]map [string ]bool )
@@ -256,6 +256,9 @@ func (pm *Manager) ActivePermissions(readOnly bool) []bakery.Op {
256
256
// _except_ for any LND permissions. In other words, this returns permissions
257
257
// for which the external validator of Lit is responsible.
258
258
func (pm * Manager ) GetLitPerms () map [string ][]bakery.Op {
259
+ pm .mu .Lock ()
260
+ defer pm .mu .Unlock ()
261
+
259
262
result := make (map [string ][]bakery.Op )
260
263
for subserver , ops := range pm .fixedPerms {
261
264
if subserver == lndPerms {
@@ -271,6 +274,9 @@ func (pm *Manager) GetLitPerms() map[string][]bakery.Op {
271
274
272
275
// IsSubServerURI if the given URI belongs to the RPC of the given server.
273
276
func (pm * Manager ) IsSubServerURI (name string , uri string ) bool {
277
+ pm .mu .Lock ()
278
+ defer pm .mu .Unlock ()
279
+
274
280
if name == lndPerms {
275
281
return pm .isLndURI (uri )
276
282
}
0 commit comments