cache

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Aug 3, 2021 License: MIT Imports: 7 Imported by: 1

Documentation

Overview

Package cache contains the types and convenience functions for manipulating caches in memory prior to writing to the disk. All caches act on Entries which may refer to passwd, group, or shadow cache entries.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Int32

func Int32(v int32) nullInt32

Int32 converts the provided int32 into a valid nullInt32 which has more desireable JSON properties.

func UInt32

func UInt32(v uint32) nullUInt32

UInt32 converts the provided uint32 into a valid nullUInt32 which has more desireable JSON properties.

Types

type ACL

type ACL func(e Entry) bool

ACL specifies a function which will return true if the entry is permitted by the ACL. If the entry is not permitted by the ACL it will silently be discarted.

type Cache

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

Cache is an in-memory struct representing the cache to be used by libnss-cache.

func NewCache

func NewCache(opts ...Option) *Cache

NewCache returns a new cache struct initialized with any provided options.

func (*Cache) Add

func (c *Cache) Add(es ...Entry)

Add adds new entries to the cache.

func (*Cache) Index added in v1.1.0

func (c *Cache) Index(col int) bytes.Buffer

Index generates an index for the given cache on a particular column. This is required for caches beyond a libnss-cache defined size in order for them to be read correctly.

func (*Cache) WriteTo

func (c *Cache) WriteTo(w io.Writer) (int64, error)

WriteTo writes the content of the cache to an io.Writer.

type Entry

type Entry interface {
	fmt.Stringer
	io.WriterTo

	Column(int) string
}

Entry specifies a generic entry in an unspecified cache. Specific implementations are provided for passwd, group, and shadow caches.

type GroupEntry

type GroupEntry struct {
	Name   string   `json:"name"`   // Group name
	Passwd string   `json:"passwd"` // Password
	GID    uint32   `json:"gid"`    // Group ID
	Mem    []string `json:"mem"`    // Member list
}

GroupEntry describes an entry of the /etc/group file https://sourceware.org/git/?p=glibc.git;a=blob;f=grp/grp.h;hb=HEAD#l41 https://fossies.org/dox/glibc-2.30/structgroup.html

func (*GroupEntry) Column added in v1.1.0

func (e *GroupEntry) Column(col int) string

Column returns the information from the requested columns or an empty string if no column is known.

func (*GroupEntry) String

func (e *GroupEntry) String() string

func (*GroupEntry) WriteTo

func (e *GroupEntry) WriteTo(w io.Writer) (int64, error)

WriteTo writes the specified entry to the provided writer.

type Option

type Option func(c *Cache)

Option is a type of pre-processing function which can be used to pre-set values on a cache.

func WithACL

func WithACL(a ACL) Option

WithACL is a convenience function to obtain an Option function for the specified ACL function.

type PasswdEntry

type PasswdEntry struct {
	Name   string `json:"name"`   // Username
	Passwd string `json:"passwd"` // Password
	UID    uint32 `json:"uid"`    // User ID
	GID    uint32 `json:"gid"`    // Group ID
	GECOS  string `json:"gecos"`  // Real name
	Dir    string `json:"dir"`    // Home directory
	Shell  string `json:"shell"`  // Shell program
}

PasswdEntry describes an entry of the /etc/passwd file https://sourceware.org/git/?p=glibc.git;a=blob;f=pwd/pwd.h;hb=HEAD#l49 https://fossies.org/dox/glibc-2.30/structpasswd.html

func (*PasswdEntry) Column added in v1.1.0

func (e *PasswdEntry) Column(col int) string

Column returns the information from the requested columns or an empty string if no column is known.

func (*PasswdEntry) String

func (e *PasswdEntry) String() string

func (*PasswdEntry) WriteTo

func (e *PasswdEntry) WriteTo(w io.Writer) (int64, error)

WriteTo writes the specified entry to the provided writer.

type ShadowEntry

type ShadowEntry struct {
	Name   string     `json:"name"`             // Login name
	Passwd string     `json:"passwd"`           // Encrypted password
	Lstchg nullInt32  `json:"lstchg,omitempty"` // Date of last change
	Min    nullInt32  `json:"min,omitempty"`    // Minimum number of days between changes
	Max    nullInt32  `json:"max,omitempty"`    // Maximum number of days between changes
	Warn   nullInt32  `json:"warn,omitempty"`   // Number of days to warn user to change the password
	Inact  nullInt32  `json:"inact,omitempty"`  // Number of days the account may be inactive
	Expire nullInt32  `json:"expire,omitempty"` // Number of days since 1970-01-01 until account expires
	Flag   nullUInt32 `json:"flag,omitempty"`   // Reserved
}

ShadowEntry describes an entry of the /etc/shadow file https://sourceware.org/git/?p=glibc.git;a=blob;f=shadow/shadow.h;hb=HEAD#l39 https://fossies.org/dox/glibc-2.30/structspwd.htmls

func (*ShadowEntry) Column added in v1.1.0

func (e *ShadowEntry) Column(col int) string

Column returns the information from the requested columns or an empty string if no column is known.

func (*ShadowEntry) String

func (e *ShadowEntry) String() string

func (*ShadowEntry) WriteTo

func (e *ShadowEntry) WriteTo(w io.Writer) (int64, error)

WriteTo writes the specified entry to the provided writer.

Jump to

Keyboard shortcuts

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