Esempio n. 1
0
func TestAccess(t *testing.T) {
	if os.Geteuid() == 0 {
		t.Log("Skipping TestAccess() as root.")
		return
	}
	tc := NewTestCase(t)
	defer tc.Cleanup()

	contents := []byte{1, 2, 3}
	err := ioutil.WriteFile(tc.origFile, []byte(contents), 0700)
	if err != nil {
		t.Fatalf("WriteFile failed: %v", err)
	}
	err = os.Chmod(tc.origFile, 0)
	if err != nil {
		t.Fatalf("Chmod failed: %v", err)
	}
	// Ugh - copied from unistd.h
	const W_OK uint32 = 2

	errCode := syscall.Access(tc.mountFile, W_OK)
	if errCode != syscall.EACCES {
		t.Errorf("Expected EACCES for non-writable, %v %v", errCode, syscall.EACCES)
	}
	err = os.Chmod(tc.origFile, 0222)
	if err != nil {
		t.Fatalf("Chmod failed: %v", err)
	}
	errCode = syscall.Access(tc.mountFile, W_OK)
	if errCode != nil {
		t.Errorf("Expected no error code for writable. %v", errCode)
	}
}
Esempio n. 2
0
func TestAccess(t *testing.T) {
	if os.Geteuid() == 0 {
		t.Log("Skipping TestAccess() as root.")
		return
	}
	me := NewTestCase(t)
	defer me.Cleanup()

	err := ioutil.WriteFile(me.origFile, []byte(contents), 0700)
	CheckSuccess(err)
	err = os.Chmod(me.origFile, 0)
	CheckSuccess(err)
	// Ugh - copied from unistd.h
	const W_OK uint32 = 2

	errCode := syscall.Access(me.mountFile, W_OK)
	if errCode != syscall.EACCES {
		t.Errorf("Expected EACCES for non-writable, %v %v", errCode, syscall.EACCES)
	}
	err = os.Chmod(me.origFile, 0222)
	CheckSuccess(err)
	errCode = syscall.Access(me.mountFile, W_OK)
	if errCode != nil {
		t.Errorf("Expected no error code for writable. %v", errCode)
	}
}
Esempio n. 3
0
//初始化文件缓存,配置参数如下
//
// filecache_dir 缓存文件目录
//
// filecache_suffix 缓存文件后缀(.cache)
//
// filecache_level 目录层级(2)
//
// filecache_expire 过期时间(3600秒)
func InitFilecache() (cache.Cache, error) {
	if beego.BConfig.RunMode == "dev" {
		beego.Info("initiating file cache")
	}

	filecache_dir := beego.AppConfig.DefaultString("filecache_dir", "")
	filecache_suffix := beego.AppConfig.DefaultString("filecache_suffix", ".cache")
	filecache_level := beego.AppConfig.DefaultInt("filecache_level", 2)
	filecache_expire := beego.AppConfig.DefaultInt("filecache_expire", 3600)
	if filecache_dir == "" {
		panic("filecache_dir is not set")
	}
	info, err := os.Stat(filecache_dir)
	if err != nil && !os.IsExist(err) {
		if err := os.MkdirAll(filecache_dir, 777); err != nil {
			panic(fmt.Sprintf("%s not exist and can not be created\n%v", filecache_dir, err))
		}
	}
	if !info.IsDir() {
		panic(fmt.Sprintf("%s is not a directory", filecache_dir))
	}
	if err := syscall.Access(filecache_dir, syscall.O_RDWR); err != nil {
		panic(fmt.Sprintf("%s is not accessable\n%v", filecache_dir, err))
	}
	return cache.NewCache("file", fmt.Sprintf(`{"CachePath":"%s","FileSuffix":"%s","DirectoryLevel":%d,"EmbedExpiry":%d}`, filecache_suffix, filecache_suffix, filecache_level, filecache_expire))
}
Esempio n. 4
0
File: fnc.go Progetto: essiene/efene
func checkArgs() {
	flag.Parse()

	if *showHelp {
		flag.Usage()
		os.Exit(0)
	}

	if flag.NArg() == 0 {
		showErrorAndQuit("No input files", -1)
	}

	// check that args end with the efene suffix and that the files exist
	args := flag.Args()
	for i := 0; i < flag.NArg(); i++ {
		file := args[i]
		if *outputType == "erl2ast" {
			if !strings.HasSuffix(file, ".erl") {
				showErrorAndQuit("Invalid input filename. '"+file+"'", -1)
			}

		} else if !strings.HasSuffix(file, fnSuffix) {
			showErrorAndQuit("Invalid input filename '"+file+"'", -1)
		}

		fmt.Printf("")

		if syscall.Access(file, syscall.O_RDONLY) != 0 {
			showErrorAndQuit("Can't read file '"+file+"'", -1)
		}
	}
}
Esempio n. 5
0
func isFileExist(path string) bool {
	if path == "" {
		return false
	}

	return syscall.Access(path, syscall.F_OK) == nil
}
Esempio n. 6
0
func access(u U, a []uint64) uint64 {
	// TODO: portability
	path, _ := u.Mem().ReadStrAt(a[0])
	amode := uint32(a[1])
	err := syscall.Access(path, amode)
	return errno(err)
}
Esempio n. 7
0
File: fnc.go Progetto: essiene/efene
func getProgramPath() (string, os.Error) {
	program := os.Args[0]
	dir, _ := path.Split(program)

	if dir == "" {
		binPath, pathError := exec.LookPath(program)

		if pathError != nil {
			if syscall.Access(program, syscall.O_RDONLY) != 0 {
				return "", os.NewError("Path to " + program + " couldn't be found")
			}

			cwd, cwdError := os.Getwd()

			if cwdError != nil {
				return "", cwdError
			}

			return cwd, nil
		}

		binPath, _ = path.Split(binPath)
		return binPath, nil
	}

	dir, _ = abspath(dir)
	return dir, nil
}
Esempio n. 8
0
// Init initialises the srvlog package. if either consoleLog or fileLog
// is true it will start the logger in another gorutine ready to log
func Init(consolLog, fileLog bool, maxLogDays int, pathToLogDir string) {
	logToConsol = consolLog
	logToFile = fileLog
	logDir = pathToLogDir
	maxDays = maxLogDays

	if logToFile {
		// make sure log directory exists
		info, err := os.Stat(logDir)
		if err != nil {
			if os.IsNotExist(err) {
				log.Fatalln("The directory specified to serverlog does not exist.")
			}
			log.Fatalln(err)
		}
		if !info.IsDir() {
			log.Fatalln("The path specified to serverlog is not a directory.")
		}

		// make sure have premissions to log directory
		err = syscall.Access(logDir, syscall.O_RDWR)
		if err != nil {
			log.Fatalln("Serverlog needs read and write premissions to the specified directory.")
		}

		// manage logfile names and number of logfiles at any one time
		// only needed if logging to files
		go logFileOverseer()
	}

	go listen()
}
Esempio n. 9
0
// Checks whether the file can be considered a match according to given options
// Existing option requires the file to exist
// Symlink option allows the file to be a symlink
func fileOkay(path string, options *Options) (bool, error) {
	var fi syscall.Stat_t
	err := syscall.Lstat(path, &fi)

	if err != nil && err != syscall.ENOENT {
		return false, err
	}

	if options.Existing && (err == syscall.ENOENT) {
		return false, nil
	} // Drop dead files...

	if options.Accessable { // FIXME(utkan): No R_OK(=4) in syscall package!
		err = syscall.Access(path, 4)
		if err != nil {
			return false, nil
		}
	}

	issym := fi.Mode&syscall.S_IFLNK == syscall.S_IFLNK
	if options.Symlink == false && issym {
		return false, nil
	} // ...and symlinks, if necessary.
	return true, nil
}
Esempio n. 10
0
func (constor *Constor) Access(input *fuse.AccessIn) (code fuse.Status) {
	constor.log("%d", input.NodeId)
	// FIXME: oops fix this
	path, err := constor.getPath(input.NodeId)
	if err != nil {
		return fuse.ToStatus(err)
	}
	return fuse.ToStatus(syscall.Access(path, input.Mask))
}
Esempio n. 11
0
// IsExist check if target is exist in fs or not
func IsExist(path string) bool {
	if path == "" {
		return false
	}

	path = PATH.Clean(path)

	return syscall.Access(path, syscall.F_OK) == nil
}
Esempio n. 12
0
func (fs *FS) Access(path string, mode uint32, context *fuse.Context) (code fuse.Status) {
	if fs.isFiltered(path) {
		return fuse.EPERM
	}
	cPath, err := fs.getBackingPath(path)
	if err != nil {
		return fuse.ToStatus(err)
	}
	return fuse.ToStatus(syscall.Access(cPath, mode))
}
Esempio n. 13
0
File: util.go Progetto: safeie/nfss
// 判断一个文件或目录是否有写入权限
func IsWritable(path string) (bool, error) {
	err := syscall.Access(path, syscall.O_RDWR)
	if err == nil {
		return true, nil
	}
	// Check if error is "no such file or directory"
	if _, ok := err.(*os.PathError); ok {
		return false, nil
	}
	return false, err
}
Esempio n. 14
0
// Which find full path to some app
func Which(name string) string {
	paths := Get().Path()

	for _, path := range paths {
		if syscall.Access(path+"/"+name, syscall.F_OK) == nil {
			return path + "/" + name
		}
	}

	return ""
}
Esempio n. 15
0
func (me *testCase) testAccess() {
	me.writeOrigFile()
	err := os.Chmod(me.origFile, 0)
	CheckSuccess(err)
	// Ugh - copied from unistd.h
	const W_OK uint32 = 2

	errCode := syscall.Access(me.mountFile, W_OK)
	if errCode != syscall.EACCES {
		me.tester.Errorf("Expected EACCES for non-writable, %v %v", errCode, syscall.EACCES)
	}
	err = os.Chmod(me.origFile, 0222)
	CheckSuccess(err)
	errCode = syscall.Access(me.mountFile, W_OK)
	if errCode != 0 {
		me.tester.Errorf("Expected no error code for writable. %v", errCode)
	}
	me.removeMountFile()
	me.removeMountFile()
}
Esempio n. 16
0
// Access - FUSE call
func (rfs *ReverseFS) Access(relPath string, mode uint32, context *fuse.Context) fuse.Status {
	if rfs.isTranslatedConfig(relPath) {
		return fuse.OK
	}
	if rfs.isDirIV(relPath) {
		return fuse.OK
	}
	absPath, err := rfs.abs(rfs.decryptPath(relPath))
	if err != nil {
		return fuse.ToStatus(err)
	}
	return fuse.ToStatus(syscall.Access(absPath, mode))
}
Esempio n. 17
0
func findSafeTempDir() {
	var candidates []string

	err := processLines("/proc/mounts", func(line string) error {
		fields := strings.Fields(line)
		if len(fields) < 1 {
			return nil
		}
		path := fields[1]
		filesystem := fields[2]
		if filesystem == "tmpfs" &&
			syscall.Access(path, 7 /* rwx ok */) == nil {
			candidates = append(candidates, path)
		}

		return nil
	})

	if err == nil && len(candidates) == 0 {
		err = errors.New("no writable tmpfs directories found")
	}

	if err != nil {
		safeTempDirErr = errors.New("system: while checking /proc/mounts: " + err.Error())
		return
	}

	suggested := os.TempDir()
	preferred := []string{suggested}
	var otherOptions []string
	if dir := os.Getenv("XDG_RUNTIME_DIR"); len(dir) > 0 {
		otherOptions = append(otherOptions, dir)
	}
	otherOptions = append(otherOptions, "/tmp", "/var/tmp")
	for _, d := range otherOptions {
		if suggested != d {
			preferred = append(preferred, d)
		}
	}

	for _, d := range preferred {
		for _, candidate := range candidates {
			if candidate == d {
				safeTempDir = candidate
				return
			}
		}
	}

	safeTempDir = candidates[0]
}
Esempio n. 18
0
func TestUnionFsWriteAccess(t *testing.T) {
	wd, clean := setupUfs(t)
	defer clean()

	fn := wd + "/ro/file"
	// No write perms.
	err := ioutil.WriteFile(fn, []byte("foo"), 0444)
	CheckSuccess(err)
	freezeRo(wd + "/ro")

	err = syscall.Access(wd+"/mnt/file", fuse.W_OK)
	if err != nil {
		CheckSuccess(err)
	}
}
Esempio n. 19
0
func findSafeTempDir() {
	var candidates []string

	err := processMountOutput(func(line string) error {
		fields := strings.Fields(line)
		if len(fields) < 1 {
			return nil
		}
		path := fields[2]
		filesystem := fields[4]
		if filesystem == "tmpfs" &&
			syscall.Access(path, 2 /* write ok */) == nil {
			candidates = append(candidates, path)
		}

		return nil
	})

	if err == nil && len(candidates) == 0 {
		err = errors.New("system: no writable tmpfs directories found")
	}

	if err != nil {
		safeTempDirErr = errors.New("system: while checking mount output: " + err.Error())
		return
	}

	suggested := os.TempDir()
	preferred := []string{suggested}
	var otherOptions []string
	otherOptions = append(otherOptions, "/tmp")
	for _, d := range otherOptions {
		if suggested != d {
			preferred = append(preferred, d)
		}
	}

	for _, d := range preferred {
		for _, candidate := range candidates {
			if candidate == d {
				safeTempDir = candidate
				return
			}
		}
	}

	safeTempDir = candidates[0]
}
Esempio n. 20
0
func TestWriteAccess(t *testing.T) {
	t.Log("TestWriteAccess")
	wd, clean := setupUfs(t)
	defer clean()

	fn := wd + "/ro/file"
	// No write perms.
	err := ioutil.WriteFile(fn, []byte("foo"), 0444)
	CheckSuccess(err)

	errno := syscall.Access(wd+"/mount/file", fuse.W_OK)
	if errno != 0 {
		err = os.Errno(errno)
		CheckSuccess(err)
	}
}
Esempio n. 21
0
func findSafeTempDir() {
	var candidates []string

	err := processFilesystems(func(fstype, path string) error {
		if fstype == "tmpfs" &&
			syscall.Access(path, 7 /* write ok */) == nil {
			candidates = append(candidates, path)
		}

		return nil
	})

	if err == nil && len(candidates) == 0 {
		err = errors.New("no writable tmpfs directories found")
	}

	if err != nil {
		safeTempDirErr = errors.New("system: while checking filesystems: " + err.Error())
		return
	}

	suggested := os.TempDir()
	preferred := []string{suggested}
	var otherOptions []string
	if dir := os.Getenv("XDG_RUNTIME_DIR"); len(dir) > 0 {
		otherOptions = append(otherOptions, dir)
	}
	otherOptions = append(otherOptions, "/tmp", "/var/tmp")
	for _, d := range otherOptions {
		if suggested != d {
			preferred = append(preferred, d)
		}
	}

	for _, d := range preferred {
		for _, candidate := range candidates {
			if candidate == d {
				safeTempDir = candidate
				return
			}
		}
	}

	safeTempDir = candidates[0]
}
Esempio n. 22
0
File: main.go Progetto: k3nju/tarbu
func (config *backupConfig) isDstWritable() error {
	var err error
	fi, err := os.Stat(config.Dst)
	if err != nil {
		return err
	}

	if !fi.IsDir() {
		return fmt.Errorf("config.Dst is not directory. dir=%s", config.Dst)
	}

	err = syscall.Access(config.Dst, _W_OK)
	if err != nil {
		return err
	}

	return nil
}
Esempio n. 23
0
func TestUnionFsWriteAccess(t *testing.T) {
	wd, clean := setupUfs(t)
	defer clean()

	fn := wd + "/ro/file"
	// No write perms.
	err := ioutil.WriteFile(fn, []byte("foo"), 0444)
	if err != nil {
		t.Fatalf("WriteFile failed: %v", err)
	}
	setRecursiveWritable(t, wd+"/ro", false)

	err = syscall.Access(wd+"/mnt/file", raw.W_OK)
	if err != nil {
		if err != nil {
			t.Fatalf("Access failed: %v", err)
		}
	}
}
Esempio n. 24
0
// NewDB reads filenames in given databases and stores the union in a newly created DB.
// If everything goes fine, new DB is returned.
func NewDB(dbFilenames []string, options *Options) (db *DB, err error) {
	db = &DB{dbFilenames: dbFilenames}
	db.options = *options

	db.options.Root = filepath.Clean(db.options.Root)
	if db.options.Root == "" {
		db.options.Root = "/"
	}

	// BUG(utkan): Accessable option should not require RO access to _all_ DB files.
	if db.options.Accessable { // FIXME(utkan): No R_OK(=4) in syscall package!
		for _, dbFilename := range dbFilenames {
			if syscall.Access(dbFilename, 4) != nil {
				db.options.Accessable = false
				break
			}
		}
	}

	err = db.readDBs()
	if err != nil {
		return nil, err
	}

	if db.options.HashMap {
		err = db.bakeBasenames()
		if err != nil {
			return db, err
		}
		/*go func() {
			err = db.bakeBasenames()
			if err != nil {
				db.options.HashMap = false
			}
		}()*/
	}

	return db, nil
}
Esempio n. 25
0
func InitContainer() error {
	var err error

	err = os.MkdirAll(runc_root, 0700)
	if err != nil {
		return err
	}
	err = syscall.Access(runc_root, 0x7)
	if err != nil {
		return err
	}

	factory, err = createFactory()
	if err != nil {
		return err
	}

	master_config, err = loadConfig(fconf)
	if err != nil {
		return err
	}
	use_container = true
	return nil
}
Esempio n. 26
0
func (fs *LoopbackFileSystem) Access(name string, mode uint32, context *Context) (code Status) {
	return ToStatus(syscall.Access(fs.GetPath(name), mode))
}
Esempio n. 27
0
func isExecutable(path string) bool {
	return syscall.Access(path, X_OK) == nil
}
Esempio n. 28
0
func (fs *loopbackFileSystem) Access(name string, mode uint32, context *fuse.Context) (code fuse.Status) {
	return fuse.ToStatus(syscall.Access(fs.GetPath(name), mode))
}
Esempio n. 29
0
func IsWritableDir(dir string) bool {
	return syscall.Access(dir, unix.W_OK) == nil
}
Esempio n. 30
0
func isWritable(path string) bool {
	return syscall.Access(path, 2) == nil
}