/*
** Copyright (C) 2001-2025 Zabbix SIA
**
** This program is free software: you can redistribute it and/or modify it under the terms of
** the GNU Affero General Public License as published by the Free Software Foundation, version 3.
**
** This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
** without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
** See the GNU Affero General Public License for more details.
**
** You should have received a copy of the GNU Affero General Public License along with this program.
** If not, see <https://www.gnu.org/licenses/>.
**/
package agent
import (
"bytes"
"errors"
"fmt"
"io"
"net"
"net/url"
"os"
"slices"
"strings"
"unicode"
"unicode/utf8"
"golang.zabbix.com/agent2/pkg/tls"
"golang.zabbix.com/sdk/conf"
"golang.zabbix.com/sdk/errs"
"golang.zabbix.com/sdk/log"
"golang.zabbix.com/sdk/plugin"
"golang.zabbix.com/sdk/zbxnet"
)
var Options AgentOptions
const (
HostNameLen = 128
hostNameListLen = 2048
HostMetadataLen = 65535 // UTF-8 characters, not bytes
HostInterfaceLen = 255 // UTF-8 characters, not bytes
Variant = 2
)
var (
errInvalidTLSConnect = errors.New("invalid TLSConnect configuration parameter")
errInvalidTLSAccept = errors.New("invalid TLSAccept configuration parameter")
errCipherCertAndAll = errors.New(`TLSCipherCert configuration parameter cannot be used when the combined list` +
` of certificate and PSK ciphersuites are used. Use TLSCipherAll to configure certificate ciphers`)
errCipherCert13AndAll = errors.New(`TLSCipherCert13 configuration parameter cannot be used when the combined` +
` list of certificate and PSK ciphersuites are used. Use TLSCipherAll13 to configure certificate ciphers`)
errCipherAllRedundant = errors.New(`parameter "TLSCipherAll" cannot be applied: the combined list of certificate` +
` and PSK ciphersuites is not used. Most likely parameters "TLSCipherCert" and/or "TLSCipherPSK"` +
` are sufficient`)
errCipherAll13Redundant = errors.New(`parameter "TLSCipherAll13" cannot be applied: the combined list of` +
` certificate and PSK ciphersuites is not used. Most likely parameters "TLSCipherCert13" and/or` +
` "TLSCipherPSK13" are sufficient`)
errMissingTLSPskIdentity = errors.New("missing TLSPSKIdentity configuration parameter")
errMissingTLSPskFile = errors.New("missing TLSPSKFile configuration parameter")
errTLSPSKIdentityWithoutPsk = errors.New("TLSPSKIdentity configuration parameter set without PSK being used")
errTLSPSKFileWithoutPsk = errors.New("TLSPSKFile configuration parameter set without PSK being used")
errTLSCipherPSKWithoutPsk = errors.New("TLSCipherPSK configuration parameter set without PSK being used")
errTLSCipherPSK13WithoutPsk = errors.New("TLSCipherPSK13 configuration parameter set without PSK being used")
errMissingTLSCAFile = errors.New("missing TLSCAFile configuration parameter")
errMissingTLSCertFile = errors.New("missing TLSCertFile configuration parameter")
errMissingTLSKeyFile = errors.New("missing TLSKeyFile configuration parameter")
errTLSCAFileWithoutCert = errors.New("TLSCAFile configuration parameter set without certificates being" +
" used")
errTLSCertFileWithoutCert = errors.New("TLSCertFile configuration parameter set without certificates" +
" being used")
errTLSKeyFileWithoutCert = errors.New("TLSKeyFile configuration parameter set without certificates" +
" being used")
errTLSServerCertIssuerWithoutCert = errors.New("TLSServerCertIssuer configuration parameter set without" +
" certificates being used")
errTLSServerCertSubjectWithoutCert = errors.New("TLSServerCertSubject configuration parameter set without" +
" certificates being used")
errTLSCRLFileWithoutCert = errors.New("TLSCRLFile configuration parameter set without certificates being used")
errCipherCertWithoutCert = errors.New("TLSCipherCert configuration parameter set without certificates being used")
errCipherCert13WithoutCert = errors.New("TLSCipherCert13 configuration parameter set without certificates being" +
" used")
errInvalidTLSPSKFile = errors.New("invalid TLSPSKFile configuration parameter")
errServerActive = errors.New(`invalid "ServerActive" configuration parameter`)
)
// PluginSystemOptions collection of system options for all plugins, map key are plugin names.
type PluginSystemOptions map[string]SystemOptions