1
0
mirror of https://github.com/directorz/mailfull-go.git synced 2025-12-17 09:37:02 +00:00

Set permission/owner/group when creating files or directories #3

This commit is contained in:
teru
2016-08-11 16:04:25 +09:00
parent a12ba9d8cc
commit d3b125132b
7 changed files with 49 additions and 13 deletions

View File

@@ -116,26 +116,38 @@ func (r *Repository) DomainCreate(domain *Domain) error {
domainDirPath := filepath.Join(r.DirMailDataPath, domain.Name())
if err := os.Mkdir(domainDirPath, 0777); err != nil {
if err := os.Mkdir(domainDirPath, 0700); err != nil {
return err
}
if err := os.Chown(domainDirPath, r.uid, r.gid); err != nil {
return err
}
usersPasswordFile, err := os.Create(filepath.Join(domainDirPath, FileNameUsersPassword))
usersPasswordFile, err := os.OpenFile(filepath.Join(domainDirPath, FileNameUsersPassword), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return err
}
if err := usersPasswordFile.Chown(r.uid, r.gid); err != nil {
return err
}
usersPasswordFile.Close()
aliasUsersFile, err := os.Create(filepath.Join(domainDirPath, FileNameAliasUsers))
aliasUsersFile, err := os.OpenFile(filepath.Join(domainDirPath, FileNameAliasUsers), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return err
}
if err := aliasUsersFile.Chown(r.uid, r.gid); err != nil {
return err
}
aliasUsersFile.Close()
catchAllUserFile, err := os.Create(filepath.Join(domainDirPath, FileNameCatchAllUser))
catchAllUserFile, err := os.OpenFile(filepath.Join(domainDirPath, FileNameCatchAllUser), os.O_RDWR|os.O_CREATE|os.O_TRUNC, 0600)
if err != nil {
return err
}
if err := catchAllUserFile.Chown(r.uid, r.gid); err != nil {
return err
}
catchAllUserFile.Close()
return nil