-
Notifications
You must be signed in to change notification settings - Fork 380
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ability for server to receive file permissions for Open and Mkdir requests #546
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,9 @@ import ( | |
const ( | ||
// SftpServerWorkerCount defines the number of workers for the SFTP server | ||
SftpServerWorkerCount = 8 | ||
|
||
defaultFileMode = 0o644 | ||
defaultDirMode = 0o755 | ||
) | ||
|
||
// Server is an SSH File Transfer Protocol (sftp) server. | ||
|
@@ -218,8 +221,15 @@ func handlePacket(s *Server, p orderedRequest) error { | |
rpkt = statusFromError(p.ID, err) | ||
} | ||
case *sshFxpMkdirPacket: | ||
// TODO FIXME: ignore flags field | ||
err := os.Mkdir(s.toLocalPath(p.Path), 0o755) | ||
var mode os.FileMode = defaultDirMode | ||
if p.Attrs != nil { | ||
attrs, _ := unmarshalFileStat(p.Flags, p.Attrs.([]byte)) | ||
Comment on lines
+225
to
+226
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Either It should be sufficient to use:
(I can’t speak to the legacy code doing differently. If I were redoing the FXP_SET_STAT packets, I’d do it quite a bit differently… I mean, I already did it’s in |
||
if p.Flags&sshFileXferAttrPermissions != 0 { | ||
mode = toFileMode(attrs.Mode) | ||
} | ||
} | ||
|
||
err := os.Mkdir(s.toLocalPath(p.Path), mode) | ||
rpkt = statusFromError(p.ID, err) | ||
case *sshFxpRmdirPacket: | ||
err := os.Remove(s.toLocalPath(p.Path)) | ||
|
@@ -458,7 +468,15 @@ func (p *sshFxpOpenPacket) respond(svr *Server) responsePacket { | |
osFlags |= os.O_EXCL | ||
} | ||
|
||
f, err := os.OpenFile(svr.toLocalPath(p.Path), osFlags, 0o644) | ||
var mode os.FileMode = defaultFileMode | ||
if p.Attrs != nil { | ||
attrs, _ := unmarshalFileStat(p.Flags, p.Attrs.([]byte)) | ||
if p.Flags&sshFileXferAttrPermissions != 0 { | ||
mode = toFileMode(attrs.Mode) | ||
} | ||
} | ||
|
||
f, err := os.OpenFile(svr.toLocalPath(p.Path), osFlags, mode) | ||
if err != nil { | ||
return statusFromError(p.ID, err) | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These constants should be grouped individually in their own
const
so that a block-level documentation can cover them both.Prefer to also have them be typed constants, so that we can simply use
mode := defaultDirMode
.