Download this file
| 1 | //go:build !unix |
| 2 | |
| 3 | package activator |
| 4 | |
| 5 | import ( |
| 6 | "os" |
| 7 | ) |
| 8 | |
| 9 | // openOwnEnvNoFollow is the unix helper's stand-in where there is no |
| 10 | // O_NOFOLLOW or O_NONBLOCK (windows). The agent only runs on Linux; this |
| 11 | // keeps the cross-compiled builds working and still refuses a link it can |
| 12 | // see, by the same Lstat check EnsureAdminToken makes, and a non-file once |
| 13 | // it has opened it. It is check-then-open, so it is weaker than the unix |
| 14 | // open, which is the one that matters. |
| 15 | func openOwnEnvNoFollow(path string, flag int, perm os.FileMode) (*os.File, error) { |
| 16 | if fi, err := os.Lstat(path); err == nil && fi.Mode()&os.ModeSymlink != 0 { |
| 17 | return nil, errOwnEnvSymlink |
| 18 | } |
| 19 | f, err := os.OpenFile(path, flag, perm) |
| 20 | if err != nil { |
| 21 | return nil, err |
| 22 | } |
| 23 | st, err := f.Stat() |
| 24 | if err != nil { |
| 25 | f.Close() |
| 26 | return nil, err |
| 27 | } |
| 28 | if !st.Mode().IsRegular() { |
| 29 | f.Close() |
| 30 | return nil, errOwnEnvNotRegular |
| 31 | } |
| 32 | return f, nil |
| 33 | } |
| 34 | |