forked from AmgdGocha/velociraptor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtools.go
82 lines (67 loc) · 2.08 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
package api
import (
context "golang.org/x/net/context"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
"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, err
}
permissions := acls.READ_RESULTS
perm, err := acls.CheckAccess(org_config_obj, user_record.Name, permissions)
if !perm || err != nil {
return nil, status.Error(codes.PermissionDenied,
"User is not allowed to view tools.")
}
inventory, err := services.GetInventory(org_config_obj)
if err != nil {
return nil, err
}
if in.Materialize {
return inventory.GetToolInfo(ctx, org_config_obj, in.Name)
}
return inventory.ProbeToolInfo(in.Name)
}
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, 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 := acls.CheckAccess(org_config_obj, user_record.Name, permissions)
if !perm || err != nil {
return nil, status.Error(codes.PermissionDenied,
"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, err
}
err = inventory.AddTool(org_config_obj, in,
services.ToolOptions{
AdminOverride: true,
})
if err != nil {
return nil, 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)
}
return in, nil
}