engine

package
v1.11.6 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 17, 2025 License: GPL-3.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AllowOKProtocols

type AllowOKProtocols struct {
	// contains filtered or unexported fields
}

AllowOKProtocols filters for ExpectedOK==true and allowed protocols.

func NewAllowOKProtocols

func NewAllowOKProtocols(protocols []string) *AllowOKProtocols

NewAllowOKProtocols constructs a filter for the provided protocols.

func (*AllowOKProtocols) Allow

func (f *AllowOKProtocols) Allow(r *Record) bool

Allow accepts only records that are expected OK and protocol is in allowed set.

type App

type App struct {
	Source RecordSource
	Filter RecordFilter
	Render Renderer
	Sink   Sink
}

App wires source->filter->renderer->sink and runs the pipeline.

func (*App) Run

func (a *App) Run() (int, error)

Run executes the pipeline until the source is exhausted.

type Argon2Encoder

type Argon2Encoder struct {
	Variant        Argon2Variant // Argon2i or Argon2id
	Time           uint32        // t
	MemoryKiB      uint32        // m in KiB
	Parallelism    uint8         // p
	KeyLen         uint32        // hash length
	OpenLDAPPrefix bool          // if true, prepend {ARGON2}
	SaltLength     int           // default 16 bytes
}

func (*Argon2Encoder) Encode

func (e *Argon2Encoder) Encode(plain string) (string, error)

type Argon2Variant

type Argon2Variant int
const (
	Argon2i Argon2Variant = iota
	Argon2id
)

type CSVSource

type CSVSource struct {
	// contains filtered or unexported fields
}

CSVSource implements RecordSource backed by a CSV file.

func NewCSVSource

func NewCSVSource(cfg Config) (*CSVSource, error)

NewCSVSource opens the CSV and prepares header index mapping.

func (*CSVSource) Close

func (c *CSVSource) Close() error

Close releases file resources.

func (*CSVSource) Next

func (c *CSVSource) Next() (*Record, error)

Next returns the next record; it propagates io.EOF when done.

type Config

type Config struct {
	// Paths
	InCSVPath    string
	TemplatePath string
	OutLDIFPath  string

	// CSV column names
	ColUsername   string
	ColPassword   string
	ColProtocol   string
	ColExpectedOK string

	// Filter knobs
	ExpectTrueValue  string
	AllowedProtocols []string

	// Password formatting
	// PasswordFormat selects how {{ password }} is rendered into the LDIF entry.
	// Supported: "sha", "ssha256", "ssha512", "argon2i", "argon2id".
	PasswordFormat string
	// SSHAEncoding selects payload encoding: "b64" or "hex". Default: b64.
	SSHAEncoding string
	// Argon2 parameters (only used for argon2i/argon2id)
	ArgonTime        uint32 // iterations
	ArgonMemoryKiB   uint32 // memory in KiB
	ArgonParallelism uint8  // threads
	ArgonKeyLen      uint32 // length of derived key in bytes
	// If true, prepend {ARGON2} to the PHC string for OpenLDAP compatibility.
	ArgonOpenLDAPPrefix bool
}

Config carries file paths, CSV column names and filter settings.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig provides sensible defaults rooted in ./client/* as requested.

type LDIFFileSink

type LDIFFileSink struct {
	// contains filtered or unexported fields
}

LDIFFileSink writes LDIF entries to a file using a buffered writer.

func NewLDIFFileSink

func NewLDIFFileSink(outPath string) (*LDIFFileSink, error)

NewLDIFFileSink creates or truncates the output file.

func (*LDIFFileSink) Close

func (s *LDIFFileSink) Close() error

Close flushes and closes the underlying file.

func (*LDIFFileSink) WriteEntry

func (s *LDIFFileSink) WriteEntry(entry string) error

WriteEntry writes a single LDIF entry as-is.

type PasswordEncoder

type PasswordEncoder interface {
	Encode(plain string) (string, error)
}

PasswordEncoder abstracts password formatting for LDIF.

type Record

type Record struct {
	Username   string
	Password   string
	Protocol   string
	ExpectedOK bool
}

Record represents one logical login record parsed from CSV.

type RecordFilter

type RecordFilter interface {
	Allow(r *Record) bool
}

RecordFilter decides whether a record should be processed.

type RecordSource

type RecordSource interface {
	Next() (*Record, error) // returns io.EOF when exhausted
	Close() error
}

RecordSource yields records sequentially and must be closed when done.

type Renderer

type Renderer interface {
	Render(r *Record) (string, error)
}

Renderer produces an LDIF entry text for a record.

type SHAEncoder added in v1.11.3

type SHAEncoder struct {
	// Encoding: "b64" or "hex" (default b64)
	Encoding string
}

SHAEncoder renders passwords as LDAP-style {SHA} digests. It computes SHA-1 over the plain text password without a salt. The payload can be encoded as base64 (default) or hex to match the SSHA encoder behavior when Encoding is set to "hex".

Output format examples: - Base64 (default): {SHA}BASE64(SHA1(password)) - Hex: {SHA.HEX}HEX(SHA1(password))

func (*SHAEncoder) Encode added in v1.11.3

func (e *SHAEncoder) Encode(plain string) (string, error)

type SSHAEncoder

type SSHAEncoder struct {
	// Alg must be "ssha256" or "ssha512"
	Alg string
	// Encoding: "b64" or "hex" (default b64)
	Encoding string
	// SaltLength in bytes (default 8)
	SaltLength int
}

func (*SSHAEncoder) Encode

func (e *SSHAEncoder) Encode(plain string) (string, error)

type Sink

type Sink interface {
	WriteEntry(entry string) error
	Close() error
}

Sink consumes rendered entries.

type TemplateRenderer

type TemplateRenderer struct {
	// contains filtered or unexported fields
}

TemplateRenderer replaces placeholders in a loaded LDIF template. Supported placeholders: {{ uuid4 }}, {{ localpart }}, {{ password }}

func NewTemplateRenderer

func NewTemplateRenderer(templatePath string, enc PasswordEncoder) (*TemplateRenderer, error)

NewTemplateRenderer reads template file into memory and wires a PasswordEncoder.

func (*TemplateRenderer) Render

func (tr *TemplateRenderer) Render(r *Record) (string, error)

Render applies the template to the record with a fresh UUIDv4 per entry.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL