Provide ability to listen on unix sockets
git-svn-id: file:///srv/svn/repo/marisa/trunk@38 d6811dac-2434-b64a-9ddc-f563ab233461
This commit is contained in:
parent
c57883653e
commit
45a43103fb
22
partage.go
22
partage.go
@ -8,6 +8,7 @@ import (
|
|||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"os/user"
|
"os/user"
|
||||||
@ -286,7 +287,9 @@ func usergroupids(username string, groupname string) (int, int, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
var err error
|
||||||
var configfile string
|
var configfile string
|
||||||
|
var listener net.Listener
|
||||||
|
|
||||||
/* default values */
|
/* default values */
|
||||||
conf.bind = "0.0.0.0:8080"
|
conf.bind = "0.0.0.0:8080"
|
||||||
@ -318,6 +321,18 @@ func main() {
|
|||||||
syscall.Chroot(conf.chroot)
|
syscall.Chroot(conf.chroot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if conf.bind[0] == '/' {
|
||||||
|
listener, err = net.Listen("unix", conf.bind)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
listener, err = net.Listen("tcp", conf.bind)
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if conf.user != "" {
|
if conf.user != "" {
|
||||||
if verbose {
|
if verbose {
|
||||||
log.Printf("Dropping privileges to %s", conf.user)
|
log.Printf("Dropping privileges to %s", conf.user)
|
||||||
@ -326,6 +341,11 @@ func main() {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if listener.Addr().Network() == "unix" {
|
||||||
|
os.Chown(conf.bind, uid, gid)
|
||||||
|
}
|
||||||
|
|
||||||
syscall.Setuid(uid)
|
syscall.Setuid(uid)
|
||||||
syscall.Setgid(gid)
|
syscall.Setgid(gid)
|
||||||
}
|
}
|
||||||
@ -337,5 +357,5 @@ func main() {
|
|||||||
log.Printf("Listening on %s", conf.bind)
|
log.Printf("Listening on %s", conf.bind)
|
||||||
}
|
}
|
||||||
|
|
||||||
http.ListenAndServe(conf.bind, nil)
|
http.Serve(listener, nil)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user