You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
fw-daemon/sgfw/const.go

152 lines
3.8 KiB

8 years ago
package sgfw
import (
"strings"
)
8 years ago
// Static strings for various usage
8 years ago
const (
STR_REDACTED = "[redacted]"
8 years ago
STR_UNKNOWN = "[uknown]"
8 years ago
)
8 years ago
//RuleAction is the action to apply to a rule
8 years ago
type RuleAction uint16
7 years ago
8 years ago
const (
RULE_ACTION_DENY RuleAction = iota
RULE_ACTION_ALLOW
RULE_ACTION_ALLOW_TLSONLY
8 years ago
)
7 years ago
8 years ago
// RuleActionString is used to get a string from an action id
8 years ago
var RuleActionString = map[RuleAction]string{
7 years ago
RULE_ACTION_DENY: "DENY",
RULE_ACTION_ALLOW: "ALLOW",
RULE_ACTION_ALLOW_TLSONLY: "ALLOW_TLSONLY",
8 years ago
}
7 years ago
8 years ago
// RuleActionValue is used to get an action id using the action string
8 years ago
var RuleActionValue = map[string]RuleAction{
7 years ago
RuleActionString[RULE_ACTION_DENY]: RULE_ACTION_DENY,
RuleActionString[RULE_ACTION_ALLOW]: RULE_ACTION_ALLOW,
RuleActionString[RULE_ACTION_ALLOW_TLSONLY]: RULE_ACTION_ALLOW_TLSONLY,
8 years ago
}
8 years ago
//RuleMode contains the time scope of a rule
8 years ago
type RuleMode uint16
7 years ago
8 years ago
const (
RULE_MODE_SESSION RuleMode = iota
RULE_MODE_PROCESS
8 years ago
RULE_MODE_PERMANENT
RULE_MODE_SYSTEM
)
7 years ago
8 years ago
// RuleModeString is used to get a rule mode string from its id
8 years ago
var RuleModeString = map[RuleMode]string{
RULE_MODE_SESSION: "SESSION",
RULE_MODE_PROCESS: "PROCESS",
8 years ago
RULE_MODE_PERMANENT: "PERMANENT",
8 years ago
RULE_MODE_SYSTEM: "SYSTEM",
8 years ago
}
7 years ago
8 years ago
// RuleModeValue converts a mode string to its id
8 years ago
var RuleModeValue = map[string]RuleMode{
8 years ago
RuleModeString[RULE_MODE_SESSION]: RULE_MODE_SESSION,
RuleModeString[RULE_MODE_PROCESS]: RULE_MODE_PROCESS,
8 years ago
RuleModeString[RULE_MODE_PERMANENT]: RULE_MODE_PERMANENT,
RuleModeString[RULE_MODE_SYSTEM]: RULE_MODE_SYSTEM,
8 years ago
}
8 years ago
//FilterScope contains a filter's time scope
8 years ago
type FilterScope uint16
7 years ago
8 years ago
const (
APPLY_ONCE FilterScope = iota
APPLY_SESSION
APPLY_PROCESS
8 years ago
APPLY_FOREVER
)
7 years ago
8 years ago
// FilterScopeString converts a filter scope ID to its string
8 years ago
var FilterScopeString = map[FilterScope]string{
APPLY_ONCE: "ONCE",
8 years ago
APPLY_SESSION: "SESSION",
APPLY_PROCESS: "PROCESS",
8 years ago
APPLY_FOREVER: "FOREVER",
}
7 years ago
8 years ago
// FilterScopeString converts a filter scope string to its ID
8 years ago
var FilterScopeValue = map[string]FilterScope{
8 years ago
FilterScopeString[APPLY_ONCE]: APPLY_ONCE,
FilterScopeString[APPLY_SESSION]: APPLY_SESSION,
FilterScopeString[APPLY_PROCESS]: APPLY_PROCESS,
8 years ago
FilterScopeString[APPLY_FOREVER]: APPLY_FOREVER,
8 years ago
}
7 years ago
8 years ago
// GetFilterScopeString is used to safely return a filter scope string
8 years ago
func GetFilterScopeString(scope FilterScope) string {
if val, ok := FilterScopeString[scope]; ok {
return val
}
return FilterScopeString[APPLY_SESSION]
}
7 years ago
8 years ago
// GetFilterScopeValue is used to safely return a filter scope ID
8 years ago
func GetFilterScopeValue(scope string) FilterScope {
scope = strings.ToUpper(scope)
if val, ok := FilterScopeValue[scope]; ok {
return val
}
return APPLY_SESSION
}
8 years ago
//FilterResult contains the filtering resulting action
8 years ago
type FilterResult uint16
7 years ago
8 years ago
const (
FILTER_DENY FilterResult = iota
FILTER_ALLOW
FILTER_PROMPT
FILTER_ALLOW_TLSONLY
8 years ago
)
7 years ago
8 years ago
// FilterResultString converts a filter value ID to its string
8 years ago
var FilterResultString = map[FilterResult]string{
7 years ago
FILTER_DENY: "DENY",
FILTER_ALLOW: "ALLOW",
FILTER_PROMPT: "PROMPT",
FILTER_ALLOW_TLSONLY: "ALLOW_TLSONLY",
8 years ago
}
7 years ago
8 years ago
// FilterResultValue converts a filter value string to its ID
8 years ago
var FilterResultValue = map[string]FilterResult{
7 years ago
FilterResultString[FILTER_DENY]: FILTER_DENY,
FilterResultString[FILTER_ALLOW]: FILTER_ALLOW,
FilterResultString[FILTER_PROMPT]: FILTER_PROMPT,
FilterResultString[FILTER_ALLOW_TLSONLY]: FILTER_ALLOW_TLSONLY,
8 years ago
}
8 years ago
// DbusRule struct of the rule passed to the dbus interface
8 years ago
type DbusRule struct {
ID uint32
Net string
Origin string
Proto string
Pid uint32
Privs string
App string
Path string
Verb uint16
Target string
Mode uint16
Sandbox string
8 years ago
}
/*const (
OZ_FWRULE_WHITELIST = iota
OZ_FWRULE_BLACKLIST
OZ_FWRULE_NONE
) */