Documentation ¶
Index ¶
- type Fstab
- type FstabEntry
- type FstabOpt
- type Host
- type Hosts
- type Narcissus
- func (n *Narcissus) Autoload(ref reflect.Value) (err error)
- func (n *Narcissus) NewFstab() (f *Fstab, err error)
- func (n *Narcissus) NewHosts() (h *Hosts, err error)
- func (n *Narcissus) NewPasswd() (p *Passwd, err error)
- func (n *Narcissus) NewPasswdUser(user string) (p *PasswdUser, err error)
- func (n *Narcissus) NewService(name string, protocol string) (s *Service, err error)
- func (n *Narcissus) NewServices() (s *Services, err error)
- func (n *Narcissus) Parse(val interface{}) error
- func (n *Narcissus) Write(val interface{}) error
- type Passwd
- type PasswdUser
- type Service
- type Services
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Fstab ¶
type Fstab struct { Comments []struct { Comment string `narcissus:"."` } `narcissus:"#comment"` Entries []FstabEntry `narcissus:"seq"` // contains filtered or unexported fields }
Fstab maps a /etc/fstab file
type FstabEntry ¶
type FstabEntry struct { Spec string `narcissus:"spec"` File string `narcissus:"file"` Vfstype string `narcissus:"vfstype"` Opt map[string]FstabOpt `narcissus:"opt"` Dump int `narcissus:"dump"` Passno int `narcissus:"passno"` // contains filtered or unexported fields }
FstabEntry maps an Fstab entry
type FstabOpt ¶
type FstabOpt struct {
Value string `narcissus:"value"`
}
FstabOpt is an FstabEntry opt
type Host ¶
type Host struct { IPAddress string `narcissus:"ipaddr"` Canonical string `narcissus:"canonical"` Aliases []string `narcissus:"alias"` Comment string `narcissus:"#comment"` // contains filtered or unexported fields }
Host maps an Hosts entry
type Hosts ¶
type Hosts struct { Comments []struct { Comment string `narcissus:"."` } `narcissus:"#comment"` Hosts []Host `narcissus:"seq"` // contains filtered or unexported fields }
Hosts maps a /etc/hosts file
type Narcissus ¶
Narcissus is a Narcissus handler
func (*Narcissus) NewFstab ¶
NewFstab returns a new Fstab structure
Example ¶
aug, err := augeas.New(fakeroot, "", augeas.None) if err != nil { log.Fatal("Failed to create Augeas handler") } n := New(&aug) fstab, err := n.NewFstab() if err != nil { log.Fatalf("Expected no error, got %v", err) } fmt.Printf("File=%v", fstab.Entries[0].File)
Output: File=/
func (*Narcissus) NewHosts ¶
NewHosts returns a new Hosts structure
Example ¶
aug, err := augeas.New(fakeroot, "", augeas.None) if err != nil { log.Fatal("Failed to create Augeas handler") } n := New(&aug) hosts, err := n.NewHosts() if err != nil { log.Fatalf("Expected no error, got %v", err) } fmt.Printf("IP=%v", hosts.Hosts[0].IPAddress)
Output: IP=127.0.0.1
func (*Narcissus) NewPasswd ¶
NewPasswd returns a new Passwd structure
Example ¶
aug, err := augeas.New("/", "", augeas.None) if err != nil { log.Fatal("Failed to create Augeas handler") } n := New(&aug) passwd, err := n.NewPasswd() if err != nil { log.Fatalf("Failed to parse passwd: %v", err) } fmt.Printf("UID=%v", passwd.Users["root"].UID)
Output: UID=0
func (*Narcissus) NewPasswdUser ¶
func (n *Narcissus) NewPasswdUser(user string) (p *PasswdUser, err error)
NewPasswdUser returns a new PasswdUser structure for given user
Example ¶
aug, err := augeas.New("/", "", augeas.None) if err != nil { log.Fatal("Failed to create Augeas handler") } n := New(&aug) user, err := n.NewPasswdUser("root") if err != nil { log.Fatalf("Failed to parse user: %v", err) } fmt.Printf("UID=%v", user.UID)
Output: UID=0
Example (Write) ¶
aug, err := augeas.New(fakeroot, "", augeas.SaveNewFile) if err != nil { log.Fatal("Failed to create Augeas handler") } n := New(&aug) passwd, err := n.NewPasswd() if err != nil { log.Fatalf("Failed to parse passwd: %v", err) } // Retrieves user if exists, empty user otherwise user, err := n.NewPasswdUser("foo") user.UID = 314 user.GID = 314 user.Name = "Foo Bar" user.Home = "/home/foo" user.Shell = "/bin/sh" user.Password = "XXX" passwd.Users["foo"] = *user err = n.Write(passwd) if err != nil { log.Fatalf("Failed to write passwd: %v", err) } fmt.Printf("UID=%v", passwd.Users["foo"].UID)
Output: UID=314
func (*Narcissus) NewService ¶
NewService returns a new Service structure
Example ¶
aug, err := augeas.New("/", "", augeas.None) if err != nil { log.Fatal("Failed to create Augeas handler") } n := New(&aug) service, err := n.NewService("ssh", "tcp") if err != nil { log.Fatalf("Expected no error, got %v", err) } fmt.Printf("Port=%v", service.Port)
Output: Port=22
func (*Narcissus) NewServices ¶
NewServices returns a new Services structure
Example ¶
aug, err := augeas.New("/", "", augeas.None) if err != nil { log.Fatal("Failed to create Augeas handler") } n := New(&aug) services, err := n.NewServices() if err != nil { log.Fatalf("Expected no error, got %v", err) } fmt.Printf("Port=%v", services.Services[0].Port)
Output: Port=1
func (*Narcissus) Parse ¶
Parse parses a structure pointer and feeds its fields with Augeas data
Example ¶
type group struct { augeasPath string Name string `path:"." value-from:"label"` Password string `path:"password"` GID int `path:"gid"` Users []string `path:"user"` } aug, err := augeas.New("/", "", augeas.None) if err != nil { log.Fatal("Failed to create Augeas handler") } n := New(&aug) g := &group{ augeasPath: "/files/etc/group/adm", } err = n.Parse(g) if err != nil { log.Fatalf("Expected no error, got %v", err) } fmt.Printf("GID=%v", g.GID)
Output: GID=4
func (*Narcissus) Write ¶
Write writes a structure pointer to the Augeas tree
Example ¶
aug, err := augeas.New(fakeroot, "", augeas.SaveNewFile) if err != nil { log.Fatal("Failed to create Augeas handler") } n := New(&aug) passwd, err := n.NewPasswd() err = n.Parse(passwd) if err != nil { log.Fatalf("Failed to parse passwd: %v", err) } user := passwd.Users["root"] fmt.Printf("Shell=%v\n", user.Shell) user.Shell = "/bin/zsh" passwd.Users["root"] = user err = n.Write(passwd) if err != nil { log.Fatalf("Failed to write passwd: %v", err) } cmd := exec.Command("grep", "^root", fakeroot+"/etc/passwd.augnew") var out bytes.Buffer cmd.Stdout = &out err = cmd.Run() if err != nil { log.Fatalf("Failed to run grep: %v", err) } fmt.Println(out.String())
Output: Shell=/bin/bash root:x:0:0:root:/root:/bin/zsh
type Passwd ¶
type Passwd struct { Users map[string]PasswdUser `narcissus:"*,key-from-label"` // contains filtered or unexported fields }
Passwd maps /etc/passwd
type PasswdUser ¶
type PasswdUser struct { Account string `narcissus:".,value-from-label"` Password string `narcissus:"password"` UID int `narcissus:"uid"` GID int `narcissus:"gid"` Name string `narcissus:"name"` Home string `narcissus:"home"` Shell string `narcissus:"shell"` // contains filtered or unexported fields }
PasswdUser maps a Passwd user
Source Files ¶
Click to show internal directories.
Click to hide internal directories.