forked from Velocidex/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.go
87 lines (71 loc) · 2.34 KB
/
tools.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package api
import (
context "golang.org/x/net/context"
"www.velocidex.com/golang/velociraptor/acls"
artifacts_proto "www.velocidex.com/golang/velociraptor/artifacts/proto"
"www.velocidex.com/golang/velociraptor/services"
)
func (self *ApiServer) GetToolInfo(ctx context.Context,
in *artifacts_proto.Tool) (*artifacts_proto.Tool, error) {
users := services.GetUserManager()
user_record, org_config_obj, err := users.GetUserFromContext(ctx)
if err != nil {
return nil, Status(self.verbose, err)
}
permissions := acls.READ_RESULTS
perm, err := services.CheckAccess(org_config_obj, user_record.Name, permissions)
if !perm || err != nil {
return nil, PermissionDenied(err,
"User is not allowed to view tools.")
}
inventory, err := services.GetInventory(org_config_obj)
if err != nil {
return nil, Status(self.verbose, err)
}
if in.Materialize {
return inventory.GetToolInfo(ctx, org_config_obj, in.Name, in.Version)
}
tool, err := inventory.ProbeToolInfo(ctx, org_config_obj, in.Name, in.Version)
return tool, Status(self.verbose, err)
}
func (self *ApiServer) SetToolInfo(ctx context.Context,
in *artifacts_proto.Tool) (*artifacts_proto.Tool, error) {
users := services.GetUserManager()
user_record, org_config_obj, err := users.GetUserFromContext(ctx)
if err != nil {
return nil, Status(self.verbose, err)
}
// Minimum permission required. If the user can write
// artifacts they can already autoload tools by uploading an
// artifact definition.
permissions := acls.ARTIFACT_WRITER
perm, err := services.CheckAccess(org_config_obj, user_record.Name, permissions)
if !perm || err != nil {
return nil, PermissionDenied(err,
"User is not allowed to update tool definitions.")
}
materialize := in.Materialize
in.Materialize = false
inventory, err := services.GetInventory(org_config_obj)
if err != nil {
return nil, Status(self.verbose, err)
}
// Clear internally managed fields the user should not be allowed
// to set.
in.Versions = nil
in.ServeUrl = ""
in.InvalidHash = ""
err = inventory.AddTool(ctx, org_config_obj, in,
services.ToolOptions{
AdminOverride: true,
})
if err != nil {
return nil, Status(self.verbose, err)
}
// If materialized we re-fetch the tool and send back the full
// record.
if materialize {
return inventory.GetToolInfo(ctx, org_config_obj, in.Name, in.Version)
}
return in, nil
}