Build configs should not be globally writable (thanks Jeremy)
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -22,3 +22,4 @@ include/systemd/warewulfd.service
|
||||
_dist/
|
||||
config
|
||||
warewulf-*.tar.gz
|
||||
Defaults.mk
|
||||
|
||||
@@ -85,12 +85,12 @@ func Configure(show bool) error {
|
||||
d.Nodes = append(d.Nodes, nodes...)
|
||||
|
||||
if controller.Dhcp.Template == "" {
|
||||
templateFile = path.Join(buildconfig.SYSCONFDIR, "warewulf/dhcp/default-dhcpd.conf")
|
||||
templateFile = path.Join(buildconfig.SYSCONFDIR(), "warewulf/dhcp/default-dhcpd.conf")
|
||||
} else {
|
||||
if strings.HasPrefix(controller.Dhcp.Template, "/") {
|
||||
templateFile = controller.Dhcp.Template
|
||||
} else {
|
||||
templateFile = path.Join(buildconfig.SYSCONFDIR, "warewulf/dhcp/"+controller.Dhcp.Template+"dhcpd.conf")
|
||||
templateFile = path.Join(buildconfig.SYSCONFDIR(), "warewulf/dhcp/"+controller.Dhcp.Template+"dhcpd.conf")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ func CobraRunE(cmd *cobra.Command, args []string) error {
|
||||
func Configure(show bool) error {
|
||||
var replace TemplateStruct
|
||||
|
||||
if !util.IsFile(path.Join(buildconfig.SYSCONFDIR, "warewulf/hosts.tmpl")) {
|
||||
if !util.IsFile(path.Join(buildconfig.SYSCONFDIR(), "warewulf/hosts.tmpl")) {
|
||||
wwlog.Printf(wwlog.WARN, "Template not found, not updating host file\n")
|
||||
return nil
|
||||
}
|
||||
@@ -45,7 +45,7 @@ func Configure(show bool) error {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
tmpl, err := template.ParseFiles(path.Join(buildconfig.SYSCONFDIR, "warewulf/hosts.tmpl"))
|
||||
tmpl, err := template.ParseFiles(path.Join(buildconfig.SYSCONFDIR(), "warewulf/hosts.tmpl"))
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Could not parse hosts template: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
||||
@@ -20,9 +20,9 @@ func Configure(show bool) error {
|
||||
if os.Getuid() == 0 {
|
||||
fmt.Printf("Updating system keys\n")
|
||||
|
||||
wwkeydir := path.Join(buildconfig.SYSCONFDIR, "/etc/warewulf/keys") + "/"
|
||||
wwkeydir := path.Join(buildconfig.SYSCONFDIR(), "/etc/warewulf/keys") + "/"
|
||||
|
||||
err := os.MkdirAll(path.Join(buildconfig.SYSCONFDIR, "warewulf/keys"), 0755)
|
||||
err := os.MkdirAll(path.Join(buildconfig.SYSCONFDIR(), "warewulf/keys"), 0755)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "Could not create base directory: %s\n", err)
|
||||
os.Exit(1)
|
||||
|
||||
@@ -24,35 +24,35 @@ func Configure(show bool) error {
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if buildconfig.TFTPDIR == "" {
|
||||
if buildconfig.TFTPDIR() == "" {
|
||||
wwlog.Printf(wwlog.ERROR, "Tftp root directory is not configured by build\n")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
err = os.MkdirAll(path.Join(buildconfig.TFTPDIR, "warewulf"), 0755)
|
||||
err = os.MkdirAll(path.Join(buildconfig.TFTPDIR(), "warewulf"), 0755)
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
if !show {
|
||||
fmt.Printf("Writing PXE files to: %s\n", path.Join(buildconfig.TFTPDIR, "warewulf"))
|
||||
err = staticfiles.WriteData("files/tftp/x86.efi", path.Join(buildconfig.TFTPDIR, "warewulf/x86.efi"))
|
||||
fmt.Printf("Writing PXE files to: %s\n", path.Join(buildconfig.TFTPDIR(), "warewulf"))
|
||||
err = staticfiles.WriteData("files/tftp/x86.efi", path.Join(buildconfig.TFTPDIR(), "warewulf/x86.efi"))
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
err = staticfiles.WriteData("files/tftp/i386.efi", path.Join(buildconfig.TFTPDIR, "warewulf/i386.efi"))
|
||||
err = staticfiles.WriteData("files/tftp/i386.efi", path.Join(buildconfig.TFTPDIR(), "warewulf/i386.efi"))
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
err = staticfiles.WriteData("files/tftp/i386.kpxe", path.Join(buildconfig.TFTPDIR, "warewulf/i386.kpxe"))
|
||||
err = staticfiles.WriteData("files/tftp/i386.kpxe", path.Join(buildconfig.TFTPDIR(), "warewulf/i386.kpxe"))
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
}
|
||||
err = staticfiles.WriteData("files/tftp/arm64.efi", path.Join(buildconfig.TFTPDIR, "warewulf/arm64.efi"))
|
||||
err = staticfiles.WriteData("files/tftp/arm64.efi", path.Join(buildconfig.TFTPDIR(), "warewulf/arm64.efi"))
|
||||
if err != nil {
|
||||
wwlog.Printf(wwlog.ERROR, "%s\n", err)
|
||||
os.Exit(1)
|
||||
|
||||
@@ -1,16 +1,78 @@
|
||||
package buildconfig
|
||||
|
||||
import "github.com/hpcng/warewulf/internal/pkg/wwlog"
|
||||
|
||||
var (
|
||||
BINDIR string = "UNDEF"
|
||||
SYSCONFDIR string = "UNDEF"
|
||||
LOCALSTATEDIR string = "UNDEF"
|
||||
SRVDIR string = "UNDEF"
|
||||
TFTPDIR string = "UNDEF"
|
||||
FIREWALLDDIR string = "UNDEF"
|
||||
SYSTEMDDIR string = "UNDEF"
|
||||
WWOVERLAYDIR string = "UNDEF"
|
||||
WWCHROOTDIR string = "UNDEF"
|
||||
WWPROVISIONDIR string = "UNDEF"
|
||||
VERSION string = "UNDEF"
|
||||
RELEASE string = "UNDEF"
|
||||
bindir string = "UNDEF"
|
||||
sysconfdir string = "UNDEF"
|
||||
localstatedir string = "UNDEF"
|
||||
srvdir string = "UNDEF"
|
||||
tftpdir string = "UNDEF"
|
||||
firewallddir string = "UNDEF"
|
||||
systemddir string = "UNDEF"
|
||||
wwoverlaydir string = "UNDEF"
|
||||
wwchrootdir string = "UNDEF"
|
||||
wwprovisiondir string = "UNDEF"
|
||||
version string = "UNDEF"
|
||||
release string = "UNDEF"
|
||||
)
|
||||
|
||||
func BINDIR() string {
|
||||
wwlog.Printf(wwlog.DEBUG, "BINDIR = '%s'\n", bindir)
|
||||
return bindir
|
||||
}
|
||||
|
||||
func SYSCONFDIR() string {
|
||||
wwlog.Printf(wwlog.DEBUG, "SYSCONFDIR = '%s'\n", sysconfdir)
|
||||
return sysconfdir
|
||||
}
|
||||
|
||||
func LOCALSTATEDIR() string {
|
||||
wwlog.Printf(wwlog.DEBUG, "LOCALSTATEDIR = '%s'\n", localstatedir)
|
||||
return localstatedir
|
||||
}
|
||||
|
||||
func SRVDIR() string {
|
||||
wwlog.Printf(wwlog.DEBUG, "SRVDIR = '%s'\n", srvdir)
|
||||
return srvdir
|
||||
}
|
||||
|
||||
func TFTPDIR() string {
|
||||
wwlog.Printf(wwlog.DEBUG, "TFTPDIR = '%s'\n", tftpdir)
|
||||
return tftpdir
|
||||
}
|
||||
|
||||
func FIREWALLDDIR() string {
|
||||
wwlog.Printf(wwlog.DEBUG, "FIREWALLDDIR = '%s'\n", firewallddir)
|
||||
return firewallddir
|
||||
}
|
||||
|
||||
func SYSTEMDDIR() string {
|
||||
wwlog.Printf(wwlog.DEBUG, "SYSTEMDDIR = '%s'\n", systemddir)
|
||||
return systemddir
|
||||
}
|
||||
|
||||
func WWOVERLAYDIR() string {
|
||||
wwlog.Printf(wwlog.DEBUG, "WWOVERLAYDIR = '%s'\n", wwoverlaydir)
|
||||
return wwoverlaydir
|
||||
}
|
||||
|
||||
func WWCHROOTDIR() string {
|
||||
wwlog.Printf(wwlog.DEBUG, "WWCHROOTDIR = '%s'\n", wwchrootdir)
|
||||
return wwchrootdir
|
||||
}
|
||||
|
||||
func WWPROVISIONDIR() string {
|
||||
wwlog.Printf(wwlog.DEBUG, "WWPROVISIONDIR = '%s'\n", wwprovisiondir)
|
||||
return wwprovisiondir
|
||||
}
|
||||
|
||||
func VERSION() string {
|
||||
wwlog.Printf(wwlog.DEBUG, "VERSION = '%s'\n", version)
|
||||
return version
|
||||
}
|
||||
|
||||
func RELEASE() string {
|
||||
wwlog.Printf(wwlog.DEBUG, "RELEASE = '%s'\n", release)
|
||||
return release
|
||||
}
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package buildconfig
|
||||
|
||||
func init() {
|
||||
BINDIR = "@BINDIR@"
|
||||
SYSCONFDIR = "@SYSCONFDIR@"
|
||||
LOCALSTATEDIR = "@LOCALSTATEDIR@"
|
||||
SRVDIR = "@SRVDIR@"
|
||||
TFTPDIR = "@TFTPDIR@"
|
||||
FIREWALLDDIR = "@FIREWALLDDIR@"
|
||||
SYSTEMDDIR = "@SYSTEMDDIR@"
|
||||
WWOVERLAYDIR = "@WWOVERLAYDIR@"
|
||||
WWCHROOTDIR = "@WWCHROOTDIR@"
|
||||
WWPROVISIONDIR = "@WWPROVISIONDIR@"
|
||||
VERSION = "@VERSION@"
|
||||
RELEASE = "@RELEASE@"
|
||||
bindir = "@BINDIR@"
|
||||
sysconfdir = "@SYSCONFDIR@"
|
||||
localstatedir = "@LOCALSTATEDIR@"
|
||||
srvdir = "@SRVDIR@"
|
||||
tftpdir = "@TFTPDIR@"
|
||||
firewallddir = "@FIREWALLDDIR@"
|
||||
systemddir = "@SYSTEMDDIR@"
|
||||
wwoverlaydir = "@WWOVERLAYDIR@"
|
||||
wwchrootdir = "@WWCHROOTDIR@"
|
||||
wwprovisiondir = "@WWPROVISIONDIR@"
|
||||
version = "@VERSION@"
|
||||
release = "@RELEASE@"
|
||||
}
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func SourceParentDir() string {
|
||||
return buildconfig.WWCHROOTDIR
|
||||
return buildconfig.WWCHROOTDIR()
|
||||
}
|
||||
|
||||
func SourceDir(name string) string {
|
||||
@@ -19,7 +19,7 @@ func RootFsDir(name string) string {
|
||||
}
|
||||
|
||||
func ImageParentDir() string {
|
||||
return path.Join(buildconfig.WWPROVISIONDIR, "container/")
|
||||
return path.Join(buildconfig.WWPROVISIONDIR(), "container/")
|
||||
}
|
||||
|
||||
func ImageFile(name string) string {
|
||||
|
||||
@@ -27,7 +27,7 @@ var (
|
||||
)
|
||||
|
||||
func KernelImageTopDir() string {
|
||||
return path.Join(buildconfig.WWPROVISIONDIR, "kernel")
|
||||
return path.Join(buildconfig.WWPROVISIONDIR(), "kernel")
|
||||
}
|
||||
|
||||
func KernelImage(kernelName string) string {
|
||||
|
||||
@@ -17,7 +17,7 @@ var ConfigFile string
|
||||
|
||||
func init() {
|
||||
if ConfigFile == "" {
|
||||
ConfigFile = path.Join(buildconfig.SYSCONFDIR, "warewulf/nodes.conf")
|
||||
ConfigFile = path.Join(buildconfig.SYSCONFDIR(), "warewulf/nodes.conf")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import (
|
||||
)
|
||||
|
||||
func OverlaySourceTopDir() string {
|
||||
return buildconfig.WWOVERLAYDIR
|
||||
return buildconfig.WWOVERLAYDIR()
|
||||
}
|
||||
|
||||
func OverlaySourceDir(overlayName string) string {
|
||||
@@ -15,5 +15,5 @@ func OverlaySourceDir(overlayName string) string {
|
||||
}
|
||||
|
||||
func OverlayImage(nodeName string, overlayName string) string {
|
||||
return path.Join(buildconfig.WWPROVISIONDIR, "overlays/", nodeName, overlayName+".img")
|
||||
return path.Join(buildconfig.WWPROVISIONDIR(), "overlays/", nodeName, overlayName+".img")
|
||||
}
|
||||
|
||||
@@ -7,5 +7,5 @@ import (
|
||||
)
|
||||
|
||||
func GetVersion() string {
|
||||
return fmt.Sprintf("%s-%s", buildconfig.VERSION, buildconfig.RELEASE)
|
||||
return fmt.Sprintf("%s-%s", buildconfig.VERSION(), buildconfig.RELEASE())
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@ var ConfigFile string
|
||||
|
||||
func init() {
|
||||
if ConfigFile == "" {
|
||||
ConfigFile = path.Join(buildconfig.SYSCONFDIR, "warewulf/warewulf.conf")
|
||||
ConfigFile = path.Join(buildconfig.SYSCONFDIR(), "warewulf/warewulf.conf")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,7 @@ func IpxeSend(w http.ResponseWriter, req *http.Request) {
|
||||
if unconfiguredNode {
|
||||
daemonLogf("IPXEREQ: %s (unknown/unconfigured node)\n", hwaddr)
|
||||
|
||||
tmpl, err := template.ParseFiles(path.Join(buildconfig.SYSCONFDIR, "/warewulf/ipxe/unconfigured.ipxe"))
|
||||
tmpl, err := template.ParseFiles(path.Join(buildconfig.SYSCONFDIR(), "/warewulf/ipxe/unconfigured.ipxe"))
|
||||
if err != nil {
|
||||
daemonLogf("ERROR: Could not parse unconfigured node IPXE template: %s\n", err)
|
||||
return
|
||||
@@ -121,7 +121,7 @@ func IpxeSend(w http.ResponseWriter, req *http.Request) {
|
||||
|
||||
} else {
|
||||
|
||||
ipxeTemplate := path.Join(buildconfig.SYSCONFDIR, "warewulf/ipxe/"+nodeobj.Ipxe.Get()+".ipxe")
|
||||
ipxeTemplate := path.Join(buildconfig.SYSCONFDIR(), "warewulf/ipxe/"+nodeobj.Ipxe.Get()+".ipxe")
|
||||
|
||||
tmpl, err := template.ParseFiles(ipxeTemplate)
|
||||
if err != nil {
|
||||
|
||||
Reference in New Issue
Block a user