sql

package
v0.0.0-...-1867bb8 Latest Latest
Warning

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

Go to latest
Published: Jul 11, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func InitDb

func InitDb(c common.Config) (*gorm.DB, error)

Init database and return handle

func InsertGroup

func InsertGroup(db *gorm.DB, conf common.Config, group Group) error

Insert group in database

func InsertHost

func InsertHost(db *gorm.DB, conf common.Config, host Host) error

Insert new host in database

func InsertShadow

func InsertShadow(db *gorm.DB, conf common.Config, shadow Shadow, uid int32) error

Insert new shadow in database If uid >= 0 it will be used otherwise shadow.Username will be used

func InsertUser

func InsertUser(db *gorm.DB, conf common.Config, user Password) error

Insert user in database

Types

type Group

type Group struct {
	ID            uint32
	Groupname     string `gorm:"unique" form:"groupname"`
	GroupPassword string `gorm:"default:'x'" form:"password"`
	GID           int32  `gorm:"unique" form:"gid"`
	Users         string `form:"-"`
}

Represent group file

func GetGroup

func GetGroup(db *gorm.DB, name string, gid int32, search bool) []Group

Gets group, group specified with either groupname or uid. If both are provided gid will be used, gid must be a negative value to not be used. Search will return groups starting with searched string. If search is provided with gid it will be ignored. If name is empty string, gid is negative and search is true then all groups are returned.

func GetUserGroups

func GetUserGroups(db *gorm.DB, name string, uid int32) []Group

Gets users group, users specified with either username or uid. If both are provided uid will be used, uid must be a negative value to not be used. First value in returned slice is the primary group.

type Host

type Host struct {
	ID        uint32
	IPv4      string `form:"ipv4"`
	IPv6      string `form:"ipv6"`
	Hostnames string `gorm:"not null" form:"hostnames"`
}

Represent host file

func GetHost

func GetHost(db *gorm.DB, name string, ipv4 string, ipv6 string, search bool) []Host

Gets host, specified with either hostname, ipv4 or ipv6. If more then one is provided hostname will be used. Search will return hosts starting with searched hostname. If search is provided with any other argument, it will be ignored. If name, ipv4 and ipv6 are empty string and search is true then all hosts are returned.

type Password

type Password struct {
	ID       uint32
	Username string `gorm:"unique" form:"username"`
	Password string `gorm:"default:'x'" form:"-"`
	UID      int32  `gorm:"unique" form:"uid"`
	GID      int32  `form:"gid"`
	Gecos    string `form:"gecos"`
	Home     string `form:"home"`
	Shell    string `form:"shell"`
}

Represents the passwd file.

func GetUser

func GetUser(db *gorm.DB, name string, uid int32, search bool) []Password

Returns users with specified name. If user is empty string and uid is a negative value all users are returned. If uid is a positive value specified user is returned. If name and search is soecified all users starting with name is returned. If only name is specified user with exactly that name is returned.

type Shadow

type Shadow struct {
	ID             uint32
	Username       string `gorm:"unique" form:"username"`
	Password       string `form:"password"`
	LastChange     uint32 `form:"last_change"`
	MinPasswordAge uint32 `gorm:"default:0" form:"min_password_age"`
	MaxPasswordAge uint32 `gorm:"default:99999" form:"max_password_age"`
	WarningPeriod  uint32 `gorm:"default:7" form:"warning_period"`
	InactivePeriod uint32 `form:"inactive_period"`
	ExpireDate     string `form:"expire_date"`
}

Represent shadow file

func GetShadow

func GetShadow(db *gorm.DB, user string, uid int32, search bool) []Shadow

Gets shadow fields, specified with either username or uid. If both are provided uid will be used, uid must be a negative value to not be used. Search will return shadow fields starting with searched username. If search is provided with uid it will be ignored. If user is empty string, uid is negative and search is true then all shadow records are returned.

Jump to

Keyboard shortcuts

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