]>
src.bluestatic.org Git - armadillo.git/blob - src/paths.go
2 // Armadillo File Manager
3 // Copyright (c) 2010, Robert Sesek <http://www.bluestatic.org>
5 // This program is free software: you can redistribute it and/or modify it under
6 // the terms of the GNU General Public License as published by the Free Software
7 // Foundation, either version 3 of the License, or any later version.
22 func SetConfig(aConfig
*config
.Configuration
) {
23 gJailRoot
= aConfig
.JailRoot
26 func canonicalizePath(raw_path
string) string {
27 raw_path
= path
.Join(gJailRoot
, raw_path
)
28 return path
.Clean(raw_path
)
31 func checkInJail(the_path
string) bool {
32 if len(the_path
) < len(gJailRoot
) {
35 if the_path
[0:len(gJailRoot
)] != gJailRoot
{
38 if strings
.Index(the_path
, "../") != -1 {
44 func List(the_path
string) (files vector
.StringVector
, err os
.Error
) {
45 full_path
:= canonicalizePath(the_path
)
46 if !checkInJail(full_path
) {
47 return nil, os
.NewError("Path outside of jail")
50 fd
, file_error
:= os
.Open(full_path
, os
.O_RDONLY
, 0)
51 if file_error
!= nil {
52 return nil, file_error
55 fileinfos
, read_err
:= fd
.Readdir(-1)
60 for _
, info
:= range fileinfos
{
62 if info
.IsDirectory() {
70 func Remove(the_path
string) os
.Error
{
71 full_path
:= canonicalizePath(the_path
)
72 if !checkInJail(full_path
) {
73 return os
.NewError("Path outside of jail")
75 return os
.RemoveAll(full_path
)
78 func Move(source
string, target
string) os
.Error
{
79 source
= canonicalizePath(source
)
80 target
= canonicalizePath(target
)
81 if !checkInJail(source
) {
82 return os
.NewError("Source outside of jail")
84 if !checkInJail(target
) {
85 return os
.NewError("Target outside of jail")
87 return os
.Rename(source
, target
)