func main() { var err error var l *p.Logger flag.Parse() rsrv.user = p.OsUsers.Uid2User(os.Geteuid()) rsrv.group = p.OsUsers.Gid2Group(os.Getegid()) rsrv.blksz = *blksize rsrv.blkchan = make(chan []byte, 2048) rsrv.zero = make([]byte, rsrv.blksz) root := new(RFile) err = root.Add(nil, "/", rsrv.user, nil, p.DMDIR|0777, root) if err != nil { goto error } l = p.NewLogger(*logsz) rsrv.srv = srv.NewFileSrv(&root.File) rsrv.srv.Dotu = true rsrv.srv.Debuglevel = *debug rsrv.srv.Start(rsrv.srv) rsrv.srv.Id = "ramfs" rsrv.srv.Log = l err = rsrv.srv.StartNetListener("tcp", *addr) if err != nil { goto error } return error: log.Println(fmt.Sprintf("Error: %s", err)) }
func serve9p() { var cl *Clone var err error var sf *StatsFile root, err = mkroot() if err != nil { goto error } cl = new(Clone) err = cl.Add(root, "clone", p.OsUsers.Uid2User(os.Geteuid()), nil, 0444, cl) if err != nil { goto error } sf = new(StatsFile) err = sf.Add(root, "stats", p.OsUsers.Uid2User(os.Geteuid()), nil, 0444, sf) if err != nil { goto error } fs = srv.NewFileSrv(root) fs.Dotu = true fs.Start(fs) err = fs.StartNetListener("tcp", *laddr) if err != nil { goto error } return error: log.Fatalf("Error serving 9p: %s\n", err) }
func serveStats() { var addrslice []string var err error var saddr string var sf *StatsFile var s *srv.Fsrv root, err := mkroot() if err != nil { goto error } sf = new(StatsFile) err = sf.Add(root, "stats", p.OsUsers.Uid2User(os.Geteuid()), nil, 0444, sf) if err != nil { goto error } s = srv.NewFileSrv(root) s.Dotu = true addrslice = strings.Split(*laddr, ":") saddr = fmt.Sprintf("%s:%d", addrslice[0], *sport) s.Start(s) err = s.StartNetListener("tcp", saddr) if err != nil { goto error } error: log.Printf("Error: %s\n", err) }
func main() { var err error var tm *Time var ntm *InfTime var s *srv.Fsrv var p9c net.Conn var ch chan bool var usr *user.User flag.Parse() root := new(srv.File) usr, err = user.Current() if err != nil { goto error } // log.Println("running as User: "******"/", UserNone(usr.Uid), nil, p.DMDIR|0555, nil) if err != nil { goto error } tm = new(Time) err = tm.Add(root, "time", UserNone(usr.Uid), nil, 0444, tm) if err != nil { goto error } ntm = new(InfTime) err = ntm.Add(root, "inftime", UserNone(usr.Uid), nil, 0444, ntm) if err != nil { goto error } s = srv.NewFileSrv(root) s.Dotu = false s.Upool = NoneUsers{} if *debug { s.Debuglevel = 1 } if *debugall { s.Debuglevel = 2 } log.Println("starting tree") s.Start(s) p9c, err = NewSrvConn(*addr) if err != nil { goto error } log.Println("starting") s.NewConn(p9c) <-ch return error: log.Println(fmt.Sprintf("Error: %s", err)) }
func main() { var err error var s *srv.Fsrv flag.Parse() useragent = *aflag timeout = *tflag root = new(srv.File) err = root.Add(nil, "/", user, user, p.DMDIR|0666, root) if err != nil { goto error } cl = new(Clone) if err = cl.Add(root, "clone", user, user, 0666, cl); err != nil { goto error } ctl = new(RootCtl) if err = ctl.Add(root, "ctl", user, user, 0666, ctl); err != nil { goto error } s = srv.NewFileSrv(root) s.Debuglevel = *debug s.Start(s) s.Id = "webfs" err = s.StartNetListener("tcp", *addr) if err != nil { goto error } /* webfs := new(Webfs) webfs.useragent = "hjdicks" webfs.timeout = 10000 webfs.Id = "webfs" webfs.Debuglevel = 1 webfs.Start(webfs) err := webfs.StartNetListener("tcp", ":5640") if err != nil { goto error }*/ return error: log.Println(fmt.Sprintf("Error: %s", err)) }
func main() { var err error flag.Parse() rsrv.user = p.OsUsers.Uid2User(os.Geteuid()) rsrv.group = p.OsUsers.Gid2Group(os.Getegid()) rsrv.blksz = *blksize rsrv.blkchan = make(chan []byte, 2048) rsrv.zero = make([]byte, rsrv.blksz) root := new(RFile) err = root.Add(nil, "/", rsrv.user, nil, p.DMDIR|0777, root) if err != nil { log.Println(fmt.Sprintf("Error: %s", err)) return } l := p.NewLogger(*logsz) rsrv.srv = srv.NewFileSrv(&root.File) rsrv.srv.Dotu = true rsrv.srv.Debuglevel = *debug rsrv.srv.Start(rsrv.srv) rsrv.srv.Id = "ramfs" rsrv.srv.Log = l cert := make([]tls.Certificate, 1) cert[0].Certificate = [][]byte{testCertificate} cert[0].PrivateKey = testPrivateKey ls, oerr := tls.Listen("tcp", *addr, &tls.Config{ Rand: rand.Reader, Certificates: cert, CipherSuites: []uint16{tls.TLS_ECDHE_RSA_WITH_RC4_128_SHA}, InsecureSkipVerify: true, }) if oerr != nil { log.Println("can't listen:", oerr) return } err = rsrv.srv.StartListener(ls) if err != nil { log.Println(fmt.Sprintf("Error: %s", err)) return } return }
func main() { var err error var tm *Time var ntm *InfTime var s *srv.Fsrv flag.Parse() user := p.OsUsers.Uid2User(os.Geteuid()) root := new(srv.File) err = root.Add(nil, "/", user, nil, p.DMDIR|0555, nil) if err != nil { goto error } tm = new(Time) err = tm.Add(root, "time", p.OsUsers.Uid2User(os.Geteuid()), nil, 0444, tm) if err != nil { goto error } ntm = new(InfTime) err = ntm.Add(root, "inftime", p.OsUsers.Uid2User(os.Geteuid()), nil, 0444, ntm) if err != nil { goto error } s = srv.NewFileSrv(root) s.Dotu = true if *debug { s.Debuglevel = 1 } if *debugall { s.Debuglevel = 2 } s.Start(s) err = s.StartNetListener("tcp", *addr) if err != nil { goto error } return error: log.Println(fmt.Sprintf("Error: %s", err)) }
// Serve a previously opened serial device via 9P. // `addr' shoud be of form "host:port", where host // may be missing. func Serve9P(addr string, dev Port) (err error) { user := user.Current() root := new(srv.File) err = root.Add(nil, "/", user, nil, p.DMDIR|0555, nil) if err != nil { return } c := new(ctl) c.dev = dev err = c.Add(root, "ctl", user, nil, 0666, c) if err != nil { return } d := new(data) d.dev = dev d.rch = ioutil.ChannelizeReader(dev, nil) d.unblockch = make(chan bool) c.dataUnblockch = d.unblockch err = d.Add(root, "data", user, nil, 0666, d) if err != nil { return } s := srv.NewFileSrv(root) s.Dotu = true switch { case Debugall: s.Debuglevel = 2 case Debug: s.Debuglevel = 1 } s.Start(s) err = s.StartNetListener("tcp", addr) return }
func main() { var err error var cl *Clone var s *srv.Fsrv flag.Parse() user := p.OsUsers.Uid2User(os.Geteuid()) root = new(srv.File) err = root.Add(nil, "/", user, nil, p.DMDIR|0777, nil) if err != nil { goto error } cl = new(Clone) err = cl.Add(root, "clone", p.OsUsers.Uid2User(os.Geteuid()), nil, 0444, cl) if err != nil { goto error } s = srv.NewFileSrv(root) s.Dotu = true if *debug { s.Debuglevel = 1 } s.Start(s) err = s.StartNetListener("tcp", *addr) if err != nil { goto error } return error: log.Println(fmt.Sprintf("Error: %s", err)) }
func main() { var err error flag.Parse() // root directory err = root.Add(nil, "/", user, nil, p.DMDIR|0655, root) if err != nil { log.Println(fmt.Sprintf("Error: %s", err)) return } // chans directory err = chans.Add(root, "chans", user, nil, p.DMDIR|0655, chans) if err != nil { log.Println(fmt.Sprintf("Error: %s", err)) return } if _, err := os.Stat("chans"); os.IsNotExist(err) { err = os.Mkdir("chans", os.ModeDir|0777) if err != nil { log.Println(fmt.Sprintf("Error: %s", err)) return } } files, _ := ioutil.ReadDir("chans") for _, file := range files { chat := new(Chat) err := chat.Add(&chans.File, file.Name(), user, nil, 0666, chat) if err != nil { log.Println(fmt.Sprintf("Error: %s", err)) return } chat.path = string(append([]byte("chans/"), chat.Name...)) createifnotexist(chat.file, chat.path) } // public chat file public := new(Chat) err = public.Add(root, "public", user, nil, 0666, public) if err != nil { log.Println(fmt.Sprintf("Error: %s", err)) return } public.path = public.Name createifnotexist(public.file, public.path) // private chat file private := new(Chat) err = private.Add(root, "private", user, nil, 0222, private) if err != nil { log.Println(fmt.Sprintf("Error: %s", err)) return } private.path = private.Name createifnotexist(private.file, private.path) // status file status := new(Status) err = status.Add(root, "status", user, nil, 0666, status) if err != nil { log.Println(fmt.Sprintf("Error: %s", err)) return } createifnotexist(status.file, status.Name) s = srv.NewFileSrv(root) s.Dotu = true if *debug { s.Debuglevel = 1 } if *debugall { s.Debuglevel = 2 } /*certpool := x509.NewCertPool() pem, err := ioutil.ReadFile("ca.crt.pem") success := certpool.AppendCertsFromPEM(pem) if ! success { log.Println("can't parse cert pool") return } cert, err := tls.LoadX509KeyPair("server.crt.pem", "server.key.pem") if err != nil { log.Println(fmt.Sprintf("Error: %s", err)) return } ls, oerr := tls.Listen("tcp", *addr, &tls.Config{ //Rand: rand.Reader, Certificates: []tls.Certificate{cert}, //CipherSuites: []uint16{tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA}, CipherSuites: []uint16{tls.TLS_RSA_WITH_AES_256_CBC_SHA}, //ClientAuth: tls.RequireAndVerifyClientCert, ClientCAs: certpool, InsecureSkipVerify: false, //PreferServerCipherSuites: true, }) if oerr != nil { log.Println("can't listen:", oerr) return } err = s.StartListener(ls)*/ s.Start(s) err = s.StartNetListener("tcp", *addr) if err != nil { log.Println(fmt.Sprintf("Error: %s", err)) return } return }