2020-09-11 00:11:47 +08:00
|
|
|
// +build !windows,!plan9
|
2017-02-25 12:06:51 +08:00
|
|
|
|
|
|
|
|
package sftp
|
|
|
|
|
|
2017-03-02 11:51:32 +08:00
|
|
|
import (
|
2021-04-24 20:28:08 +08:00
|
|
|
"fmt"
|
2017-03-02 11:51:32 +08:00
|
|
|
"syscall"
|
2017-02-25 12:06:51 +08:00
|
|
|
|
2021-04-24 20:28:08 +08:00
|
|
|
sshfx "github.com/pkg/sftp/internal/encoding/ssh/filexfer"
|
|
|
|
|
)
|
2017-03-02 11:51:32 +08:00
|
|
|
|
|
|
|
|
func testOsSys(sys interface{}) error {
|
2021-04-24 20:28:08 +08:00
|
|
|
switch sys := sys.(type) {
|
|
|
|
|
case *syscall.Stat_t:
|
|
|
|
|
if sys.Uid != 65534 {
|
|
|
|
|
return fmt.Errorf("UID failed to match: %d", sys.Uid)
|
|
|
|
|
}
|
|
|
|
|
if sys.Gid != 65534 {
|
|
|
|
|
return fmt.Errorf("GID failed to match: %d", sys.Gid)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case *sshfx.Attributes:
|
|
|
|
|
uid, gid, ok := sys.GetUIDGID()
|
|
|
|
|
if !ok {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
if uid != 65534 {
|
|
|
|
|
return fmt.Errorf("UID failed to match: %d", uid)
|
|
|
|
|
}
|
|
|
|
|
if gid != 65534 {
|
|
|
|
|
return fmt.Errorf("GID failed to match: %d", gid)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
case *FileStat:
|
|
|
|
|
if sys.UID != 65534 {
|
|
|
|
|
return fmt.Errorf("UID failed to match: %d", sys.UID)
|
|
|
|
|
}
|
|
|
|
|
if sys.GID != 65534 {
|
|
|
|
|
return fmt.Errorf("GID failed to match: %d", sys.GID)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return fmt.Errorf("unexpected FileInfo.Sys() type: %T", sys)
|
2017-03-02 11:51:32 +08:00
|
|
|
}
|
2021-04-24 20:28:08 +08:00
|
|
|
|
2017-03-02 11:51:32 +08:00
|
|
|
return nil
|
|
|
|
|
}
|