aboutsummaryrefslogtreecommitdiff
path: root/hotline/transaction_handlers.go
diff options
context:
space:
mode:
authorJeff Halter <868228+jhalter@users.noreply.github.com>2024-04-04 15:37:28 -0700
committerJeff Halter <868228+jhalter@users.noreply.github.com>2024-04-04 15:47:18 -0700
commit2e1aec0fcfd412cff22cc4fc996973e403589ad8 (patch)
tree6be4564a21229eb9c15602ffdc8e2370b7f72242 /hotline/transaction_handlers.go
parentdd81e2cf8030aaea778677270d2a1b6ed218d6b8 (diff)
Add support for Mac Roman character encoding.
https://en.wikipedia.org/wiki/Mac_OS_Roman
Diffstat (limited to 'hotline/transaction_handlers.go')
-rw-r--r--hotline/transaction_handlers.go22
1 files changed, 15 insertions, 7 deletions
diff --git a/hotline/transaction_handlers.go b/hotline/transaction_handlers.go
index ee95cc0..931340e 100644
--- a/hotline/transaction_handlers.go
+++ b/hotline/transaction_handlers.go
@@ -385,8 +385,13 @@ func HandleGetFileInfo(cc *ClientConn, t *Transaction) (res []Transaction, err e
return res, err
}
+ encodedName, err := txtEncoder.String(fw.name)
+ if err != nil {
+ return res, fmt.Errorf("invalid filepath encoding: %w", err)
+ }
+
res = append(res, cc.NewReply(t,
- NewField(FieldFileName, []byte(fw.name)),
+ NewField(FieldFileName, []byte(encodedName)),
NewField(FieldFileTypeString, fw.ffo.FlatFileInformationFork.friendlyType()),
NewField(FieldFileCreatorString, fw.ffo.FlatFileInformationFork.friendlyCreator()),
NewField(FieldFileComment, fw.ffo.FlatFileInformationFork.Comment),
@@ -478,7 +483,11 @@ func HandleSetFileInfo(cc *ClientConn, t *Transaction) (res []Transaction, err e
if err != nil {
return nil, err
}
- hlFile.name = string(fileNewName)
+ hlFile.name, err = txtDecoder.String(string(fileNewName))
+ if err != nil {
+ return res, fmt.Errorf("invalid filepath encoding: %w", err)
+ }
+
err = hlFile.move(fileDir)
if os.IsNotExist(err) {
res = append(res, cc.NewErrReply(t, "Cannot rename file "+string(fileName)+" because it does not exist or cannot be found."))
@@ -566,9 +575,6 @@ func HandleMoveFile(cc *ClientConn, t *Transaction) (res []Transaction, err erro
res = append(res, cc.NewErrReply(t, "Cannot delete file "+fileName+" because it does not exist or cannot be found."))
return res, err
}
- if err != nil {
- return res, err
- }
switch mode := fi.Mode(); {
case mode.IsDir():
if !cc.Authorize(accessMoveFolder) {
@@ -614,6 +620,10 @@ func HandleNewFolder(cc *ClientConn, t *Transaction) (res []Transaction, err err
}
}
newFolderPath := path.Join(cc.Server.Config.FileRoot, subPath, folderName)
+ newFolderPath, err = txtDecoder.String(newFolderPath)
+ if err != nil {
+ return res, fmt.Errorf("invalid filepath encoding: %w", err)
+ }
// TODO: check path and folder name lengths
@@ -622,8 +632,6 @@ func HandleNewFolder(cc *ClientConn, t *Transaction) (res []Transaction, err err
return []Transaction{cc.NewErrReply(t, msg)}, nil
}
- // TODO: check for disallowed characters to maintain compatibility for original client
-
if err := cc.Server.FS.Mkdir(newFolderPath, 0777); err != nil {
msg := fmt.Sprintf("Cannot create folder \"%s\" because an error occurred.", folderName)
return []Transaction{cc.NewErrReply(t, msg)}, nil