Changeset 28 in code for trunk/partage.go
- Timestamp:
- Oct 19, 2021, 7:42:00 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/partage.go
r27 r28 8 8 "net/http" 9 9 "os" 10 "os/user" 10 11 "time" 11 12 "path" 12 13 "syscall" 14 "strconv" 13 15 "path/filepath" 14 16 "html/template" … … 33 35 var conf struct { 34 36 bind string 37 user string 38 group string 35 39 baseuri string 36 40 filepath string … … 219 223 func main() { 220 224 flag.StringVar(&conf.bind, "bind", "0.0.0.0:8080", "Address to bind to (default: 0.0.0.0:8080)") 225 flag.StringVar(&conf.user, "user", "", "User to drop privileges to on startup (default: current user)") 226 flag.StringVar(&conf.group, "group", "", "Group to drop privileges to on startup (default: user's group)") 221 227 flag.StringVar(&conf.baseuri, "baseuri", "http://127.0.0.1:8080", "Base URI to use for links (default: http://127.0.0.1:8080)") 222 228 flag.StringVar(&conf.filepath, "filepath", "./files", "Path to save files to (default: ./files)") … … 236 242 } 237 243 244 if conf.user != "" { 245 u, err := user.Lookup(conf.user) 246 if err != nil { 247 fmt.Println(err) 248 return 249 } 250 251 uid, _ := strconv.Atoi(u.Uid) 252 gid, _ := strconv.Atoi(u.Gid) 253 254 if conf.group != "" { 255 g, err := user.LookupGroup(conf.group) 256 if err != nil { 257 fmt.Println(err) 258 return 259 } 260 gid, _ = strconv.Atoi(g.Gid) 261 } 262 263 syscall.Setuid(uid) 264 syscall.Setgid(gid) 265 } 266 238 267 http.HandleFunc("/", uploader) 239 268 http.Handle(conf.filectx, http.StripPrefix(conf.filectx, http.FileServer(http.Dir(conf.filepath))))
Note:
See TracChangeset
for help on using the changeset viewer.