예제 #1
0
func ensureGPGHomeDirectory() (string, error) {
	real, err := osutil.RealUser()
	if err != nil {
		return "", err
	}

	uid, err := strconv.Atoi(real.Uid)
	if err != nil {
		return "", err
	}

	gid, err := strconv.Atoi(real.Gid)
	if err != nil {
		return "", err
	}

	homedir := os.Getenv("SNAP_GNUPG_HOME")
	if homedir == "" {
		homedir = filepath.Join(real.HomeDir, ".snap", "gnupg")
	}

	if err := osutil.MkdirAllChown(homedir, 0700, uid, gid); err != nil {
		return "", err
	}
	return homedir, nil
}
예제 #2
0
파일: login.go 프로젝트: niemeyer/snapd
// writeAuthData saves authentication details for later reuse through ReadAuthData
func writeAuthData(user User) error {
	real, err := osutil.RealUser()
	if err != nil {
		return err
	}

	uid, err := strconv.Atoi(real.Uid)
	if err != nil {
		return err
	}

	gid, err := strconv.Atoi(real.Gid)
	if err != nil {
		return err
	}

	targetFile := storeAuthDataFilename(real.HomeDir)

	if err := osutil.MkdirAllChown(filepath.Dir(targetFile), 0700, uid, gid); err != nil {
		return err
	}

	outStr, err := json.Marshal(user)
	if err != nil {
		return nil
	}

	return osutil.AtomicWriteFileChown(targetFile, []byte(outStr), 0600, 0, uid, gid)
}