MCPcopy Create free account
hub / github.com/Icinga/icinga2 / CreateStage

Method CreateStage

lib/remote/configpackageutility.cpp:74–119  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

72}
73
74String ConfigPackageUtility::CreateStage(const String& packageName, const Dictionary::Ptr& files)
75{
76 String stageName = Utility::NewUniqueID();
77
78 String path = GetPackageDir() + "/" + packageName;
79
80 if (!Utility::PathExists(path))
81 BOOST_THROW_EXCEPTION(std::invalid_argument("Package does not exist."));
82
83 path += "/" + stageName;
84
85 Utility::MkDirP(path, 0700);
86 Utility::MkDirP(path + "/conf.d", 0700);
87 Utility::MkDirP(path + "/zones.d", 0700);
88 WriteStageConfig(packageName, stageName);
89
90 bool foundDotDot = false;
91
92 if (files) {
93 ObjectLock olock(files);
94 for (const Dictionary::Pair& kv : files) {
95 if (ContainsDotDot(kv.first)) {
96 foundDotDot = true;
97 break;
98 }
99
100 String filePath = path + "/" + kv.first;
101
102 Log(LogInformation, "ConfigPackageUtility")
103 << "Updating configuration file: " << filePath;
104
105 // Pass the directory and generate a dir tree, if it does not already exist
106 Utility::MkDirP(Utility::DirName(filePath), 0750);
107 std::ofstream fp(filePath.CStr(), std::ofstream::out | std::ostream::binary | std::ostream::trunc);
108 fp << kv.second;
109 fp.close();
110 }
111 }
112
113 if (foundDotDot) {
114 Utility::RemoveDirRecursive(path);
115 BOOST_THROW_EXCEPTION(std::invalid_argument("Path must not contain '..'."));
116 }
117
118 return stageName;
119}
120
121void ConfigPackageUtility::WritePackageConfig(const String& packageName)
122{

Callers

nothing calls this directly

Calls 6

PathExistsFunction · 0.85
MkDirPFunction · 0.85
LogClass · 0.85
DirNameFunction · 0.85
CStrMethod · 0.80
closeMethod · 0.80

Tested by

no test coverage detected