func Get() map[string]User { once.Do(func() { x, e := ioutil.ReadFile("/etc/passwd") if e == nil { gomakefile.AddDep("/etc/passwd") pwent := "([^:\n]+):([^:]+):([0-9]+):([0-9]+):([^:]*):([^:]+):([^:]+)\n" matches := regexp.MustCompile(pwent).FindAllSubmatch(x, -1) for _, match := range matches { username := string(match[1]) passwr := string(match[2]) uid, e := strconv.Atoi(string(match[3])) if e != nil { fmt.Println("Error reading uid of", username, string(match[3])) continue } gid, e := strconv.Atoi(string(match[4])) if e != nil { fmt.Println("Error reading gid of", username, string(match[4])) continue } comment := string(match[5]) home := string(match[6]) shell := string(match[7]) passwd[username] = User{username, passwr, uid, gid, comment, home, shell} } x, e = ioutil.ReadFile("/etc/shadow") if e == nil { gomakefile.AddDep("/etc/shadow") pwent := "([^:\n]+):([^:]+):[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*:[^:]*\n" matches := regexp.MustCompile(pwent).FindAllSubmatch(x, -1) for _, match := range matches { username := string(match[1]) passwr := string(match[2]) if us, ok := passwd[username]; ok { us.Passwd = passwr // update the password! passwd[username] = us } } havepasswords = true } else { fmt.Fprintln(os.Stderr, "Unable to read /etc/shadow.") } } }) return passwd }
func Stat(n string) (f StatData, e os.Error) { f.Name = n stat, e := os.Lstat(f.Name) if e != nil { return } if stat.IsRegular() { f.Mode = IsFile } else if stat.IsDirectory() { f.Mode = IsDirectory } else if stat.IsSymlink() { f.Mode = IsSymlink } else { f.Mode = IsOther } f.Perms = stat.Permission() f.Uid = stat.Uid f.Gid = stat.Gid gomakefile.AddDep(f.Name) return }
func Get() map[string]Entry { once.Do(func () { x, e := ioutil.ReadFile("/etc/hosts") if e == nil { gomakefile.AddDep("/etc/hosts") matchhosts := regexp.MustCompile("(^|\n)([^#\n\t ]+)[\t ]+([^\n\t ]+)[\t ]*([^\n]*)\n") matchaliases := regexp.MustCompile("[^\t ]+") matches := matchhosts.FindAllSubmatch(x, -1) for _,match := range matches { as := matchaliases.FindAllString(string(match[4]),-1) ent := Entry{ string(match[2]), string(match[3]), as } byip[ent.IpAddress] = ent myhosts[ent.CanonicalName] = ent myhosts[ent.IpAddress] = ent for _,a := range ent.Aliases { myhosts[a] = ent } } } }) return myhosts }