// GetEnvList internally calls pam_getenvlist and then uses some very // dangerous code to pull out the returned environment data and mash // it into a map[string]string. This call may be safe, but it hasn't // been tested on enough platforms/architectures/PAM-implementations to // be sure. func (t *Transaction) GetEnvList() map[string]string { env := make(map[string]string) list := (uintptr)(unsafe.Pointer(C.pam_getenvlist(t.handle))) for *(*uintptr)(unsafe.Pointer(list)) != 0 { entry := *(*uintptr)(unsafe.Pointer(list)) nameval := C.GoString((*C.char)(unsafe.Pointer(entry))) chunks := strings.SplitN(nameval, "=", 2) env[chunks[0]] = chunks[1] list += (uintptr)(unsafe.Sizeof(list)) } return env }
// GetEnvList returns a copy of the PAM environment as a map. func (t *Transaction) GetEnvList() (map[string]string, error) { env := make(map[string]string) p := C.pam_getenvlist(t.handle) if p == nil { t.status = C.PAM_BUF_ERR return nil, t } for q := p; *q != nil; q = next(q) { chunks := strings.SplitN(C.GoString(*q), "=", 2) if len(chunks) == 2 { env[chunks[0]] = chunks[1] } C.free(unsafe.Pointer(*q)) } C.free(unsafe.Pointer(p)) return env, nil }