pax_global_header00006660000000000000000000000064131345170210014507gustar00rootroot0000000000000052 comment=49d0a950dd1a78e811690a55e12e4e0aa8199d62 go-gecos-1.0/000077500000000000000000000000001313451702100130525ustar00rootroot00000000000000go-gecos-1.0/.gitignore000066400000000000000000000000061313451702100150360ustar00rootroot00000000000000*.swp go-gecos-1.0/LICENSE000066400000000000000000000020741313451702100140620ustar00rootroot00000000000000Copyright (c) 2017, Paul R. Tagliamonte Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. go-gecos-1.0/README.md000066400000000000000000000005331313451702100143320ustar00rootroot00000000000000go-gecos ======== Read the GECOS field on a Linunx machine. The GECOS field is the place in `/etc/passwd` (or other `passwd`-like entry, such as LDAP and friends) that stores the real-name (as exposed in `os/user.User.Name`), Room location, Office Phone, Home Phone, and "other". These entries can be set or changed using the `chfn(1)` command. go-gecos-1.0/cmd/000077500000000000000000000000001313451702100136155ustar00rootroot00000000000000go-gecos-1.0/cmd/gecos/000077500000000000000000000000001313451702100147155ustar00rootroot00000000000000go-gecos-1.0/cmd/gecos/main.go000066400000000000000000000011571313451702100161740ustar00rootroot00000000000000package main import ( "fmt" "os/user" "pault.ag/go/gecos" ) func main() { current, err := user.Current() if err != nil { panic(err) } entry, err := gecos.Lookup(current) if err != nil { panic(err) } fmt.Printf("Uid: %s\n", current.Uid) fmt.Printf("Gid: %s\n", current.Gid) fmt.Printf("Username: %s\n", current.Username) fmt.Printf("Name: %s\n", current.Name) fmt.Printf("Home: %s\n", current.HomeDir) fmt.Printf("Room: %s\n", entry.Room) fmt.Printf("Office: %s\n", entry.OfficePhone) fmt.Printf("Home: %s\n", entry.HomePhone) fmt.Printf("Other: %s\n", entry.Other) } go-gecos-1.0/gecos.go000066400000000000000000000016601313451702100145040ustar00rootroot00000000000000package gecos /* #include #include */ import "C" import ( "fmt" "os/user" "strconv" "strings" ) var ( NoGECOSEntry = fmt.Errorf("No GECOS Entry for this user") ) type GECOS struct { Name string Room string OfficePhone string HomePhone string Other string } func getpwuid(user int) (*GECOS, error) { gecos := C.getpwuid(C.__uid_t(user)) gecosString := C.GoString(gecos.pw_gecos) els := strings.SplitN(gecosString, ",", 5) if len(els) == 1 { return nil, NoGECOSEntry } if len(els) < 4 { return nil, fmt.Errorf("Expected 4 or 5 elements, got %d", len(els)) } ret := GECOS{ Name: els[0], Room: els[1], OfficePhone: els[2], HomePhone: els[3], } if len(els) >= 5 { ret.Other = els[4] } return &ret, nil } func Lookup(user *user.User) (*GECOS, error) { id, err := strconv.Atoi(user.Uid) if err != nil { return nil, err } return getpwuid(id) }