check for modifcation of passwd/group after exec
This commit is contained in:
committed by
Christian Goll
parent
1afa58ae57
commit
5fb10130f3
@@ -9,6 +9,7 @@ import (
|
||||
"os/exec"
|
||||
"path"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/hpcng/warewulf/internal/pkg/container"
|
||||
"github.com/hpcng/warewulf/internal/pkg/util"
|
||||
@@ -48,6 +49,18 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
allargs = append(allargs, "--bind", b)
|
||||
}
|
||||
allargs = append(allargs, args...)
|
||||
containerPath := container.RootFsDir(containerName)
|
||||
|
||||
passwdTime := time.Now()
|
||||
fileStat, _ := os.Stat(path.Join(containerPath, "/etc/passwd"))
|
||||
unixStat := fileStat.Sys().(*syscall.Stat_t)
|
||||
passwdTime = time.Unix(int64(unixStat.Ctim.Sec), int64(unixStat.Ctim.Nsec))
|
||||
groupTime := time.Now()
|
||||
fileStat, _ = os.Stat(path.Join(containerPath, "/etc/group"))
|
||||
unixStat = fileStat.Sys().(*syscall.Stat_t)
|
||||
groupTime = time.Unix(int64(unixStat.Ctim.Sec), int64(unixStat.Ctim.Nsec))
|
||||
wwlog.Printf(wwlog.DEBUG, "passwd: %v\n", passwdTime)
|
||||
wwlog.Printf(wwlog.DEBUG, "group: %v\n", groupTime)
|
||||
|
||||
err := runContainedCmd(allargs)
|
||||
if err != nil {
|
||||
@@ -63,6 +76,18 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
fileStat, _ = os.Stat(path.Join(containerPath, "/etc/passwd"))
|
||||
unixStat = fileStat.Sys().(*syscall.Stat_t)
|
||||
if passwdTime.Before(time.Unix(int64(unixStat.Ctim.Sec), int64(unixStat.Ctim.Nsec))) {
|
||||
wwlog.Printf(wwlog.WARN, "/etc/passwd has been modified, maybe you want to run syncuser\n")
|
||||
}
|
||||
wwlog.Printf(wwlog.DEBUG, "passwd: %v\n", time.Unix(int64(unixStat.Ctim.Sec), int64(unixStat.Ctim.Nsec)))
|
||||
fileStat, _ = os.Stat(path.Join(containerPath, "/etc/group"))
|
||||
unixStat = fileStat.Sys().(*syscall.Stat_t)
|
||||
if groupTime.Before(time.Unix(int64(unixStat.Ctim.Sec), int64(unixStat.Ctim.Nsec))) {
|
||||
wwlog.Printf(wwlog.WARN, "/etc/group has been modified, maybe you want to run syncuser\n")
|
||||
}
|
||||
wwlog.Printf(wwlog.DEBUG, "group: %v\n", time.Unix(int64(unixStat.Ctim.Sec), int64(unixStat.Ctim.Nsec)))
|
||||
|
||||
fmt.Printf("Rebuilding container...\n")
|
||||
err = container.Build(containerName, false)
|
||||
|
||||
Reference in New Issue
Block a user