Skip to content

Commit

Permalink
Fixed bug in hunts paths.
Browse files Browse the repository at this point in the history
The aff4 prefix is just confusing - we need to drop it everywhere.
  • Loading branch information
scudette committed Jul 15, 2019
1 parent e0c30f5 commit a1e3824
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 21 deletions.
20 changes: 10 additions & 10 deletions bin/inspect.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,16 @@ import (
)

var classifiers = map[string]proto.Message{
"aff4:/clients/C.[^/]+$": &actions_proto.ClientInfo{},
"aff4:/clients/C.[^/]+/ping$": &actions_proto.ClientInfo{},
"aff4:/clients/C.[^/]+/key$": &crypto_proto.PublicKey{},
"aff4:/clients/C.[^/]+/vfs/.+": &actions_proto.VQLResponse{},
"aff4:/clients/C.[^/]+/flows/F\\.[^/]+$": &flows_proto.AFF4FlowObject{},
"aff4:/clients/C.[^/]+/flows/F\\.[^/]+/results/.+$": &crypto_proto.GrrMessage{},
"aff4:/clients/C.[^/]+/tasks/[^/]+$": &crypto_proto.GrrMessage{},
constants.HUNTS_URN + "H.[^/]+$": &api_proto.Hunt{},
"aff4:/users/[^/]+$": &api_proto.VelociraptorUser{},
"aff4:/users/[^/]+/notifications/.+$": &api_proto.UserNotification{},
"/clients/C.[^/]+$": &actions_proto.ClientInfo{},
"/clients/C.[^/]+/ping$": &actions_proto.ClientInfo{},
"/clients/C.[^/]+/key$": &crypto_proto.PublicKey{},
"/clients/C.[^/]+/vfs/.+": &actions_proto.VQLResponse{},
"/clients/C.[^/]+/flows/F\\.[^/]+$": &flows_proto.AFF4FlowObject{},
"/clients/C.[^/]+/flows/F\\.[^/]+/results/.+$": &crypto_proto.GrrMessage{},
"/clients/C.[^/]+/tasks/[^/]+$": &crypto_proto.GrrMessage{},
constants.HUNTS_URN + "H.[^/]+$": &api_proto.Hunt{},
"/users/[^/]+$": &api_proto.VelociraptorUser{},
"/users/[^/]+/notifications/.+$": &api_proto.UserNotification{},
}

var (
Expand Down
9 changes: 4 additions & 5 deletions constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ const (

FLOW_PREFIX = "F."
FOREMAN_WELL_KNOWN_FLOW = "aff4:/flows/E.Foreman"
HUNTS_URN = "aff4:/hunts/"
HUNT_PREFIX = "H."

// The GUI uses this as the client index.
CLIENT_INDEX_URN = "aff4:/client_index/"
CLIENT_INDEX_URN = "/client_index/"

USER_URN = "aff4:/users/"
USER_URN = "/users/"

// Well known flows - Request ID:
LOG_SINK uint64 = 980
Expand All @@ -57,8 +56,8 @@ const (

// These store configuration for the server and client
// monitoring artifacts.
ServerMonitoringFlowURN = "aff4:/config/server_monitoring.json"
ClientMonitoringFlowURN = "aff4:/config/client_monitoring.json"
ServerMonitoringFlowURN = "/config/server_monitoring.json"
ClientMonitoringFlowURN = "/config/client_monitoring.json"
)

var (
Expand Down
13 changes: 13 additions & 0 deletions constants/paths.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package constants

const (
HUNTS_URN = "/hunts/"
)

func GetHuntURN(hunt_id string) string {
return HUNTS_URN + hunt_id
}

func GetHuntStatsPath(hunt_id string) string {
return HUNTS_URN + hunt_id + "/stats"
}
4 changes: 2 additions & 2 deletions flows/hunts.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func CreateHunt(
})
}

err = db.SetSubject(config_obj, constants.HUNTS_URN+hunt.HuntId, hunt)
err = db.SetSubject(config_obj, constants.GetHuntURN(hunt.HuntId), hunt)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -233,7 +233,7 @@ func ModifyHunt(config_obj *api_proto.Config, hunt_modification *api_proto.Hunt)

err = db.SetSubject(
config_obj,
constants.HUNTS_URN+hunt.HuntId, hunt)
constants.GetHuntURN(hunt.HuntId), hunt)
if err != nil {
return err
}
Expand Down
6 changes: 3 additions & 3 deletions services/hunt_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ func (self *HuntDispatcher) _flush_stats() error {
for _, hunt_obj := range self.hunts {
err = db.SetSubject(
self.config_obj,
constants.HUNTS_URN+hunt_obj.HuntId+"/stats", hunt_obj.Stats)
constants.GetHuntStatsPath(hunt_obj.HuntId), hunt_obj.Stats)
if err != nil {
logger := logging.GetLogger(self.config_obj, &logging.FrontendComponent)
logger.Error("Flushing %s to disk: %v", hunt_obj.HuntId, err)
Expand Down Expand Up @@ -203,15 +203,15 @@ func (self *HuntDispatcher) Refresh() error {
hunt_obj := &api_proto.Hunt{}
err = db.GetSubject(
self.config_obj,
constants.HUNTS_URN+hunt_id, hunt_obj)
constants.GetHuntURN(hunt_id), hunt_obj)
if err != nil {
continue
}

// Re-read the stats into the hunt object.
hunt_stats := &api_proto.HuntStats{}
err := db.GetSubject(self.config_obj,
constants.HUNTS_URN+hunt_id+"/stats", hunt_stats)
constants.GetHuntStatsPath(hunt_id), hunt_stats)
if err == nil {
hunt_obj.Stats = hunt_stats
}
Expand Down
2 changes: 1 addition & 1 deletion services/hunt_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (self *HuntManager) ProcessRow(
// Hold references to all the writers for the life of
// the manager.
fd, err := file_store_factory.WriteFile(
constants.HUNTS_URN + participation_row.HuntId + ".csv")
constants.GetHuntURN(participation_row.HuntId) + ".csv")
if err != nil {
return
}
Expand Down

0 comments on commit a1e3824

Please sign in to comment.