Documentation
¶
Index ¶
- Constants
- Variables
- func CheckFileLimit(c *AppConfig) (bool, int, uint64)
- func NewClient(conn net.Conn, clientID uint64, logger log.Logger, envelope *mail.Pool) *client
- type AppConfig
- type AuthType
- type ClientState
- type Daemon
- func (d *Daemon) AddAuthenticator(authenticator authenticators.AuthenticatorCreator)
- func (d *Daemon) AddProcessor(name string, pc backends.ProcessorConstructor)
- func (d *Daemon) ListenerStatuses() []ListenerStatus
- func (d *Daemon) LoadConfig(path string) (AppConfig, error)
- func (d *Daemon) Log() log.Logger
- func (d *Daemon) Publish(topic Event, args ...interface{})
- func (d *Daemon) ReloadConfig(c AppConfig) error
- func (d *Daemon) ReloadConfigFile(path string) error
- func (d *Daemon) ReopenLogs() error
- func (d *Daemon) SetConfig(c AppConfig) error
- func (d *Daemon) Shutdown()
- func (d *Daemon) Start() (err error)
- func (d *Daemon) Subscribe(topic Event, fn interface{}) error
- func (d *Daemon) Unsubscribe(topic Event, handler interface{}) error
- type Errors
- type Event
- type EventHandler
- type Guerrilla
- type ListenerStatus
- type Pool
- func (p *Pool) Borrow(conn net.Conn, clientID uint64, logger log.Logger, ep *mail.Pool) (Poolable, error)
- func (p *Pool) GetActiveClientsCount() int
- func (p *Pool) IsShuttingDown() bool
- func (p *Pool) Return(c Poolable)
- func (p *Pool) SetTimeout(duration time.Duration)
- func (p *Pool) ShutdownState()
- func (p *Pool) ShutdownWait()
- func (p *Pool) Start()
- type Poolable
- type ServerConfig
- type ServerTLSConfig
Constants ¶
const ( // The client has connected, and is awaiting our first response ClientGreeting = iota // We have responded to the client's connection and are awaiting a command ClientCmd // We have received the sender and recipient information ClientData // We have agreed with the client to secure the connection over TLS ClientStartTLS // Server will shutdown, client to shutdown on next command turn ClientShutdown // We have to read login ClientLogin // We have to read password ClientPassword )
const ( AuthLOGIN = iota AuthCRAMMD5 )
const ( CommandVerbMaxLength = 160 CommandLineMaxLength = 1024 // Number of allowed unrecognized commands before we terminate the connection MaxUnrecognizedCommands = 5 )
const ( // server has just been created ServerStateNew = iota // Server has just been stopped ServerStateStopped // Server has been started and is running ServerStateRunning // Server could not start due to an error ServerStateStartError ServerStateStarting ServerStateStopping )
Variables ¶
var ( LineLimitExceeded = errors.New("maximum line length exceeded") MessageSizeExceeded = errors.New("maximum message size exceeded") )
var ( Version string Commit string BuildTime string StartTime time.Time ConfigLoadTime time.Time )
var (
ErrPoolShuttingDown = errors.New("server pool: shutting down")
)
var TLSCiphers = map[string]uint16{ "TLS_RSA_WITH_3DES_EDE_CBC_SHA": tls.TLS_RSA_WITH_3DES_EDE_CBC_SHA, "TLS_RSA_WITH_AES_128_CBC_SHA": tls.TLS_RSA_WITH_AES_128_CBC_SHA, "TLS_RSA_WITH_AES_256_CBC_SHA": tls.TLS_RSA_WITH_AES_256_CBC_SHA, "TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA": tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, "TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA": tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, "TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, "TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, "TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA": tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, "TLS_RSA_WITH_RC4_128_SHA": tls.TLS_RSA_WITH_RC4_128_SHA, "TLS_RSA_WITH_AES_128_GCM_SHA256": tls.TLS_RSA_WITH_AES_128_GCM_SHA256, "TLS_RSA_WITH_AES_256_GCM_SHA384": tls.TLS_RSA_WITH_AES_256_GCM_SHA384, "TLS_ECDHE_ECDSA_WITH_RC4_128_SHA": tls.TLS_ECDHE_ECDSA_WITH_RC4_128_SHA, "TLS_ECDHE_RSA_WITH_RC4_128_SHA": tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA, "TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256": tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, "TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384": tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, "TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384": tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, }
https://golang.org/pkg/crypto/tls/#pkg-constants Ciphers introduced before Go 1.7 are listed here, ciphers since Go 1.8, see tls_go1.8.go ....... since Go 1.13, see tls_go1.13.go
var TLSClientAuthTypes = map[string]tls.ClientAuthType{ "NoClientCert": tls.NoClientCert, "RequestClientCert": tls.RequestClientCert, "RequireAnyClientCert": tls.RequireAnyClientCert, "VerifyClientCertIfGiven": tls.VerifyClientCertIfGiven, "RequireAndVerifyClientCert": tls.RequireAndVerifyClientCert, }
https://golang.org/pkg/crypto/tls/#ClientAuthType
var TLSCurves = map[string]tls.CurveID{ "P256": tls.CurveP256, "P384": tls.CurveP384, "P521": tls.CurveP521, }
https://golang.org/pkg/crypto/tls/#CurveID
var TLSProtocols = map[string]uint16{ "tls1.0": tls.VersionTLS10, "tls1.1": tls.VersionTLS11, "tls1.2": tls.VersionTLS12, }
Functions ¶
func CheckFileLimit ¶
CheckFileLimit checks the number of files we can open (works on OS'es that support the ulimit command)
Types ¶
type AppConfig ¶
type AppConfig struct {
// Servers can have one or more items.
/// Defaults to 1 server listening on 127.0.0.1:2525
Servers []ServerConfig `json:"servers"`
// AllowedHosts lists which hosts to accept email for. Defaults to os.Hostname
AllowedHosts []string `json:"allowed_hosts"`
// PidFile is the path for writing out the process id. No output if empty
PidFile string `json:"pid_file"`
// LogFile is where the logs go. Use path to file, or "stderr", "stdout"
// or "off". Default "stderr"
LogFile string `json:"log_file,omitempty"`
// LogLevel controls the lowest level we log.
// "info", "debug", "error", "panic". Default "info"
LogLevel string `json:"log_level,omitempty"`
// BackendConfig configures the email envelope processing backend
BackendConfig backends.BackendConfig `json:"backend_config"`
}
AppConfig is the holder of the configuration of the app
func (*AppConfig) EmitChangeEvents ¶
Emits any configuration change events onto the event bus.
func (*AppConfig) EmitLogReopenEvents ¶
EmitLogReopen emits log reopen events using existing config
type ClientState ¶
type ClientState int
ClientState indicates which part of the SMTP transaction a given client is in.
type Daemon ¶
type Daemon struct {
Config *AppConfig
Logger log.Logger
Backend backends.Backend
Authenticator authenticators.AuthenticatorCreator
// contains filtered or unexported fields
}
Daemon provides a convenient API when using go-guerrilla as a package in your Go project. Is's facade for Guerrilla, AppConfig, backends.Backend and log.Logger
func (*Daemon) AddAuthenticator ¶
func (d *Daemon) AddAuthenticator(authenticator authenticators.AuthenticatorCreator)
func (*Daemon) AddProcessor ¶
func (d *Daemon) AddProcessor(name string, pc backends.ProcessorConstructor)
AddProcessor adds a processor constructor to the backend. name is the identifier to be used in the config. See backends docs for more info.
func (*Daemon) ListenerStatuses ¶ added in v1.5.3
func (d *Daemon) ListenerStatuses() []ListenerStatus
ListenerStatuses returns copied observations of listeners created by Start, including listeners created by reload. Before Start it returns an empty list. Lifecycle mutations must be serialized by the daemon owner, as for Start and ReloadConfig; snapshots may be read concurrently with those mutations.
func (*Daemon) LoadConfig ¶
LoadConfig reads in the config from a JSON file. Note: if d.Config is nil, the sets d.Config with the unmarshalled AppConfig which will be returned
func (*Daemon) Log ¶
log returns a logger that implements our log.Logger interface. level is set to "info" by default
func (*Daemon) ReloadConfig ¶
Reload a config using the passed in AppConfig and emit config change events
func (*Daemon) ReloadConfigFile ¶
Reload a config from a file and emit config change events
func (*Daemon) ReopenLogs ¶
ReopenLogs send events to re-opens all log files. Typically, one would call this after rotating logs
func (*Daemon) SetConfig ¶
SetConfig is same as LoadConfig, except you can pass AppConfig directly does not emit any change events, instead use ReloadConfig after daemon has started
func (*Daemon) Shutdown ¶
func (d *Daemon) Shutdown()
Shuts down the daemon, including servers and backend. Do not call Start on it again, use a new server.
func (*Daemon) Start ¶
Starts the daemon, initializing d.Config, d.Logger and d.Backend with defaults can only be called once through the lifetime of the program
func (*Daemon) Unsubscribe ¶
for unsubscribing from config change events
type Event ¶
type Event int
const ( // when a new config was loaded EventConfigNewConfig Event = iota // when allowed_hosts changed EventConfigAllowedHosts // when pid_file changed EventConfigPidFile // when log_file changed EventConfigLogFile // when it's time to reload the main log file EventConfigLogReopen // when log level changed EventConfigLogLevel // when the backend's config changed EventConfigBackendConfig // when a new server was added EventConfigServerNew // when an existing server was removed EventConfigServerRemove // when a new server config was detected (general event) EventConfigServerConfig // when a server was enabled EventConfigServerStart // when a server was disabled EventConfigServerStop // when a server's log file changed EventConfigServerLogFile // when it's time to reload the server's log EventConfigServerLogReopen // when a server's timeout changed EventConfigServerTimeout // when a server's max clients changed EventConfigServerMaxClients // when a server's TLS config changed EventConfigServerTLSConfig )
type EventHandler ¶
func (*EventHandler) Publish ¶
func (h *EventHandler) Publish(topic Event, args ...interface{})
func (*EventHandler) Subscribe ¶
func (h *EventHandler) Subscribe(topic Event, fn interface{}) error
func (*EventHandler) Unsubscribe ¶
func (h *EventHandler) Unsubscribe(topic Event, handler interface{}) error
type Guerrilla ¶
type ListenerStatus ¶ added in v1.5.3
type ListenerStatus struct {
ListenInterface string `json:"listen_interface"`
BoundAddress string `json:"bound_address,omitempty"`
Hostname string `json:"hostname"`
Enabled bool `json:"enabled"`
State string `json:"state"`
ChangedAt time.Time `json:"changed_at"`
ErrorCode string `json:"error_code,omitempty"`
TLSMode string `json:"tls_mode"`
CertificateLoaded bool `json:"certificate_loaded"`
AuthRequired bool `json:"authentication_required"`
AuthTypes []string `json:"authentication_mechanisms"`
}
ListenerStatus describes an owned listener, not a probe of DNS, credentials, delivery, or a port that another process may have bound. It contains no secrets.
type Pool ¶
type Pool struct {
ShutdownChan chan int
// contains filtered or unexported fields
}
Pool holds Clients.
func (*Pool) Borrow ¶
func (p *Pool) Borrow(conn net.Conn, clientID uint64, logger log.Logger, ep *mail.Pool) (Poolable, error)
Borrow a Client from the pool. Will block if len(activeClients) > maxClients
func (*Pool) GetActiveClientsCount ¶
Gets the number of active clients that are currently out of the pool and busy serving
func (*Pool) IsShuttingDown ¶
returns true if the pool is shutting down
func (*Pool) SetTimeout ¶
set a timeout for all lent clients
func (*Pool) ShutdownState ¶
func (p *Pool) ShutdownState()
Lock the pool from borrowing then remove all active clients each active client's timeout is lowered to 1 sec and notified to stop accepting commands
func (*Pool) ShutdownWait ¶
func (p *Pool) ShutdownWait()
type Poolable ¶
type Poolable interface {
// contains filtered or unexported methods
}
a struct can be pooled if it has the following interface
type ServerConfig ¶
type ServerConfig struct {
// TLS Configuration
TLS ServerTLSConfig `json:"tls,omitempty"`
// LogFile is where the logs go. Use path to file, or "stderr", "stdout" or "off".
// defaults to AppConfig.Log file setting
LogFile string `json:"log_file,omitempty"`
// Hostname will be used in the server's reply to HELO/EHLO. If TLS enabled
// make sure that the Hostname matches the cert. Defaults to os.Hostname()
// Hostname will also be used to fill the 'Host' property when the "RCPT TO" address is
// addressed to just <postmaster>
Hostname string `json:"host_name"`
// Listen interface specified in <ip>:<port> - defaults to 127.0.0.1:2525
ListenInterface string `json:"listen_interface"`
// MaxSize is the maximum size of an email that will be accepted for delivery.
// Defaults to 10 Mebibytes
MaxSize int64 `json:"max_size"`
// Timeout specifies the connection timeout in seconds. Defaults to 30
Timeout int `json:"timeout"`
// MaxClients controls how many maximum clients we can handle at once.
// Defaults to defaultMaxClients
MaxClients int `json:"max_clients"`
// IsEnabled set to true to start the server, false will ignore it
IsEnabled bool `json:"is_enabled"`
XClientOn bool `json:"xclient_on,omitempty"`
AuthRequired bool `json:"auth_required,omitempty"`
AuthTypes []string `json:"auth_types,omitempty"`
}
ServerConfig specifies config options for a single server
func (*ServerConfig) IsAuthTypeAllowed ¶
func (sc *ServerConfig) IsAuthTypeAllowed(authType string) bool
Returns value changes between struct a & struct b.
func (*ServerConfig) Validate ¶
func (sc *ServerConfig) Validate() error
Validate validates the server's configuration.
type ServerTLSConfig ¶
type ServerTLSConfig struct {
// TLS Protocols to use. [0] = min, [1]max
// Use Go's default if empty
Protocols []string `json:"protocols,omitempty"`
// TLS Ciphers to use.
// Use Go's default if empty
Ciphers []string `json:"ciphers,omitempty"`
// TLS Curves to use.
// Use Go's default if empty
Curves []string `json:"curves,omitempty"`
// PrivateKeyFile path to cert private key in PEM format.
PrivateKeyFile string `json:"private_key_file"`
// PublicKeyFile path to cert (public key) chain in PEM format.
PublicKeyFile string `json:"public_key_file"`
// TLS Root cert authorities to use. "A PEM encoded CA's certificate file.
// Defaults to system's root CA file if empty
RootCAs string `json:"root_cas_file,omitempty"`
// declares the policy the server will follow for TLS Client Authentication.
// Use Go's default if empty
ClientAuthType string `json:"client_auth_type,omitempty"`
// controls whether the server selects the
// client's most preferred cipher suite
PreferServerCipherSuites bool `json:"prefer_server_cipher_suites,omitempty"`
// StartTLSOn should we offer STARTTLS command. Cert must be valid.
// False by default
StartTLSOn bool `json:"start_tls_on,omitempty"`
// AlwaysOn run this server as a pure TLS server, i.e. SMTPS
AlwaysOn bool `json:"tls_always_on,omitempty"`
// contains filtered or unexported fields
}
Source Files
¶
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
guerrillad
command
|
|
|
iconv
iconv enables using GNU iconv for converting 7bit to UTF-8.
|
iconv enables using GNU iconv for converting 7bit to UTF-8. |
