Skip to content

Commit

Permalink
clean opc ua
Browse files Browse the repository at this point in the history
  • Loading branch information
RicYaben committed Nov 13, 2024
1 parent dac963c commit 26d07d7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
4 changes: 2 additions & 2 deletions modules/opcua/browse.go
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ func (b *browser) getChildren(refType uint32, n *opcua.Node, path string, level
for _, rn := range refs {
children, err := b.browse(rn, path, level+1)
if err != nil {
return nil, fmt.Errorf("failed to browse children: %w", err)
return nodes, fmt.Errorf("failed to browse children: %w", err)
}
nodes = append(nodes, children...)
}
Expand All @@ -219,7 +219,7 @@ func (b *browser) browse(n *opcua.Node, path string, level int) ([]*NodeDef, err
for _, refType := range []uint32{id.HasComponent, id.Organizes, id.HasProperty} {
nChilds, err := b.getChildren(refType, n, def.Path, level)
if err != nil {
return nil, err
return nodes, err
}
nodes = append(nodes, nChilds...)
}
Expand Down
14 changes: 8 additions & 6 deletions modules/opcua/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ func (s *scan) Grab() *zgrab2.ScanError {

// Authenticate to each endpoints
for _, r := range resEps {
s.authAndBrowse(r)
if err := s.authAndBrowse(r); err != nil {
return zgrab2.NewScanError(zgrab2.SCAN_APPLICATION_ERROR, err)
}
}
return nil
}
Expand All @@ -182,7 +184,7 @@ func (s *scan) clientOptions(ep *ua.EndpointDescription, auth string) []opcua.Op
}
}

func (s *scan) authAndBrowse(r *EndpointResult) {
func (s *scan) authAndBrowse(r *EndpointResult) error {
ep := r.EndpointDescription

var authedClient *opcua.Client
Expand All @@ -207,18 +209,18 @@ func (s *scan) authAndBrowse(r *EndpointResult) {
if authedClient != nil {
select {
case <-s.ctx.Done():
return
return nil
default:
r.Namespaces = authedClient.Namespaces()
id, _ := ua.ParseNodeID("i=84")
nodes, err := s.browser.browse(authedClient.Node(id), "", 0)
r.Nodes = nodes
if err != nil {
log.Errorf("failed to browse nodes: %v", err)
return
return fmt.Errorf("failed to browse nodes: %w", err)
}
r.Nodes = nodes
}
}
return nil
}

func (s *Scanner) newOPCUAscan(ep string) *scan {
Expand Down

0 comments on commit 26d07d7

Please sign in to comment.