MCPcopy Create free account
hub / github.com/wavetermdev/waveterm / ParseEnvironmentConfFile

Function ParseEnvironmentConfFile

pkg/util/pamparse/pamparse.go:41–72  ·  view source on GitHub ↗

Parses a file in the format of /etc/security/pam_env.conf or ~/.pam_environment. Accepts a path to the file and returns a map of environment variables.

(path string, opts *PamParseOpts)

Source from the content-addressed store, hash-verified

39
40// Parses a file in the format of /etc/security/pam_env.conf or ~/.pam_environment. Accepts a path to the file and returns a map of environment variables.
41func ParseEnvironmentConfFile(path string, opts *PamParseOpts) (map[string]string, error) {
42 rtn := make(map[string]string)
43 file, err := os.Open(path)
44 if err != nil {
45 return nil, err
46 }
47 defer file.Close()
48 if opts == nil {
49 opts, err = ParsePasswd()
50 if err != nil {
51 return nil, err
52 }
53 }
54 if err != nil {
55 return nil, err
56 }
57 scanner := bufio.NewScanner(file)
58 for scanner.Scan() {
59 line := scanner.Text()
60 key, val := parseEnvironmentConfLine(line)
61
62 // Fall back to ParseEnvironmentLine if ParseEnvironmentConfLine fails
63 if key == "" {
64 key, val = parseEnvironmentLine(line)
65 if key == "" {
66 continue
67 }
68 }
69 rtn[key] = replaceHomeAndShell(val, opts.Home, opts.Shell)
70 }
71 return rtn, nil
72}
73
74// Gets the home directory and shell from /etc/passwd for the current user.
75func ParsePasswd() (*PamParseOpts, error) {

Callers 2

tryGetPamEnvVarsFunction · 0.92

Calls 7

ParsePasswdFunction · 0.85
parseEnvironmentConfLineFunction · 0.85
parseEnvironmentLineFunction · 0.85
replaceHomeAndShellFunction · 0.85
OpenMethod · 0.80
ScanMethod · 0.80
CloseMethod · 0.65

Tested by 1