commit b63eedc3cfb37df5e27b875d54ad387f7ec52970
parent 53741b97afe48ed34f444754b0bdf55c78ca8bef
Author: Matsuda Kenji <info@mtkn.jp>
Date: Wed, 17 Jan 2024 13:16:20 +0900
check uid in Create
Diffstat:
2 files changed, 20 insertions(+), 13 deletions(-)
diff --git a/diskfs/fs.go b/diskfs/fs.go
@@ -6,6 +6,7 @@ import (
"fmt"
"io/fs"
"os"
+ "os/user"
"path/filepath"
"strings"
@@ -64,9 +65,23 @@ func (fsys *FS) OpenFile(name string, flag int) (lib9p.File, error) {
return &File{fs: fsys, path: name, file: osf}, nil
}
-// TODO: check uid
-// BUG: check uid. it can be a security hole.
func (fsys *FS) Create(name string, uid string, omode lib9p.OpenMode, perm lib9p.FileMode) (lib9p.File, error) {
+ usr, err := user.Current()
+ if err != nil {
+ return nil, &fs.PathError{
+ Op: "create",
+ Path: name,
+ Err: err,
+ }
+ }
+ if usr.Username != uid {
+ return nil, &fs.PathError{
+ Op: "create",
+ Path: name,
+ Err: fmt.Errorf("file creation by a user other than the server's " +
+ "uid is not implemented"),
+ }
+ }
if !fs.ValidPath(name) {
return nil, &fs.PathError{
Op: "create",
@@ -88,17 +103,8 @@ func (fsys *FS) Create(name string, uid string, omode lib9p.OpenMode, perm lib9p
if omode&lib9p.OTRUNC != 0 {
flag |= os.O_TRUNC
}
- if omode&lib9p.ORCLOSE != 0 {
- return nil, &fs.PathError{
- Op: "create",
- Path: name,
- Err: fmt.Errorf("orclose not implemented"),
- }
- }
- var (
- osfile *os.File
- err error
- )
+ // ORCLOSE is handled by the library.
+ var osfile *os.File
if perm&os.ModeDir != 0 {
if err := os.Mkdir(ospath, perm); err != nil {
return nil, &fs.PathError{
diff --git a/testdir/glenda/a b/testdir/glenda/a
@@ -0,0 +1 @@
+a