mirror of
https://github.com/directorz/mailfull-go.git
synced 2025-12-20 11:07:02 +00:00
Use current user instead of default parameter
This commit is contained in:
@@ -3,7 +3,9 @@ package mailfull
|
|||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
|
"os/user"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strconv"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"github.com/BurntSushi/toml"
|
"github.com/BurntSushi/toml"
|
||||||
@@ -73,7 +75,7 @@ func DefaultRepositoryConfig() *RepositoryConfig {
|
|||||||
c := &RepositoryConfig{
|
c := &RepositoryConfig{
|
||||||
DirDatabasePath: "./etc",
|
DirDatabasePath: "./etc",
|
||||||
DirMailDataPath: "./domains",
|
DirMailDataPath: "./domains",
|
||||||
Username: "mailfull",
|
Username: "",
|
||||||
CmdPostalias: "postalias",
|
CmdPostalias: "postalias",
|
||||||
CmdPostmap: "postmap",
|
CmdPostmap: "postmap",
|
||||||
}
|
}
|
||||||
@@ -84,12 +86,31 @@ func DefaultRepositoryConfig() *RepositoryConfig {
|
|||||||
// Repository represents a Repository.
|
// Repository represents a Repository.
|
||||||
type Repository struct {
|
type Repository struct {
|
||||||
*RepositoryConfig
|
*RepositoryConfig
|
||||||
|
|
||||||
|
uid int
|
||||||
|
gid int
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewRepository creates a new Repository instance.
|
// NewRepository creates a new Repository instance.
|
||||||
func NewRepository(c *RepositoryConfig) (*Repository, error) {
|
func NewRepository(c *RepositoryConfig) (*Repository, error) {
|
||||||
|
u, err := user.Lookup(c.Username)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
uid, err := strconv.Atoi(u.Uid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
gid, err := strconv.Atoi(u.Gid)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
r := &Repository{
|
r := &Repository{
|
||||||
RepositoryConfig: c,
|
RepositoryConfig: c,
|
||||||
|
|
||||||
|
uid: uid,
|
||||||
|
gid: gid,
|
||||||
}
|
}
|
||||||
|
|
||||||
return r, nil
|
return r, nil
|
||||||
@@ -201,7 +222,13 @@ func InitRepository(rootPath string) error {
|
|||||||
}
|
}
|
||||||
defer configFile.Close()
|
defer configFile.Close()
|
||||||
|
|
||||||
|
u, err := user.Current()
|
||||||
|
if err != nil {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
c := DefaultRepositoryConfig()
|
c := DefaultRepositoryConfig()
|
||||||
|
c.Username = u.Username
|
||||||
|
|
||||||
enc := toml.NewEncoder(configFile)
|
enc := toml.NewEncoder(configFile)
|
||||||
if err := enc.Encode(c); err != nil {
|
if err := enc.Encode(c); err != nil {
|
||||||
|
|||||||
Reference in New Issue
Block a user