Skip to content

Commit cc58c74

Browse files
author
Mike Morris
committed
make file ownership setting platform specific
Windows doesn't support Chown(), or the Stat_t type needed to set ownership on a file.
1 parent b746187 commit cc58c74

File tree

3 files changed

+32
-13
lines changed

3 files changed

+32
-13
lines changed

chown_unix.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// +build !windows
2+
3+
package main
4+
5+
import (
6+
"os"
7+
"syscall"
8+
)
9+
10+
func chown(f string) {
11+
if st, err := os.Stat(f); err == nil {
12+
var uid uint32
13+
switch s := st.Sys().(type) {
14+
case syscall.Stat_t:
15+
uid = s.Uid
16+
case *syscall.Stat_t:
17+
uid = s.Uid
18+
}
19+
20+
if uid > 0 {
21+
os.Chown(cookieFile, int(uid), -1)
22+
}
23+
}
24+
}

chown_windows.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// +build windows
2+
3+
package main
4+
5+
func chown(f string) {
6+
return
7+
}

main.go

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -576,19 +576,7 @@ func samlClientWithReauth() (saml.AwsClient, error) {
576576

577577
// set sane ownership on cookieFile, just in case we're running under sudo
578578
if h, err := os.UserHomeDir(); err == nil {
579-
if st, err := os.Stat(h); err == nil {
580-
var uid uint32
581-
switch s := st.Sys().(type) {
582-
case syscall.Stat_t:
583-
uid = s.Uid
584-
case *syscall.Stat_t:
585-
uid = s.Uid
586-
}
587-
588-
if uid > 0 {
589-
os.Chown(cookieFile, int(uid), -1)
590-
}
591-
}
579+
chown(h)
592580
}
593581

594582
log.Debugf("SAMLResponse:\n%s", s)

0 commit comments

Comments
 (0)