update to make passwd file toggle-able

This commit is contained in:
Michael (Parker) Parker 2023-12-18 14:25:48 -05:00
parent cc0dca4c84
commit 752b779d1f
2 changed files with 12 additions and 9 deletions

View File

@ -169,7 +169,9 @@ type SystemConfiguration struct {
Uid int `yaml:"uid"`
Gid int `yaml:"gid"`
Login bool `yaml:"login"`
// Passwd controls weather a passwd file is mounted in the container
// at /etc/passwd to resolve missing user issues
Passwd bool `json:"mount_passwd" yaml:"mount_passwd" default:"true"`
} `yaml:"user"`
// The amount of time in seconds that can elapse before a server's disk space calculation is
@ -532,13 +534,8 @@ func ConfigureDirectories() error {
if passwd, err := os.Create("/etc/pterodactyl/passwd"); err != nil {
return err
} else {
shell := "/usr/sbin/nologin"
if _config.System.User.Login {
shell = "/bin/sh"
}
// the WriteFile method returns an error if unsuccessful
err := os.WriteFile(passwd.Name(), []byte(fmt.Sprintf("container:x:%d:%d::/home/container:%s", _config.System.User.Uid, _config.System.User.Gid, shell)), 0777)
err := os.WriteFile(passwd.Name(), []byte(fmt.Sprintf("container:x:%d:%d::/home/container:/usr/sbin/nologin", _config.System.User.Uid, _config.System.User.Gid)), 0755)
// handle this error
if err != nil {
// print it out

View File

@ -27,12 +27,18 @@ func (s *Server) Mounts() []environment.Mount {
Source: s.Filesystem().Path(),
ReadOnly: false,
},
{
}
// Mount passwd file if set to true
if config.Get().System.User.Passwd {
passwdMount := environment.Mount{
Default: true,
Target: "/etc/passwd",
Source: "/etc/pterodactyl/passwd",
ReadOnly: true,
},
}
m = append(m, passwdMount)
}
// Also include any of this server's custom mounts when returning them.