Skip to content

Commit 681c6fa

Browse files
WIP: revert old logic
1 parent 7a57fbc commit 681c6fa

File tree

4 files changed

+100
-35
lines changed

4 files changed

+100
-35
lines changed

.vscode/settings.json

+66-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,71 @@
1212
// Use JSON with comments
1313
"files.associations": {
1414
"*.json": "jsonc",
15-
"string": "cpp"
15+
"string": "cpp",
16+
"any": "cpp",
17+
"array": "cpp",
18+
"atomic": "cpp",
19+
"bit": "cpp",
20+
"*.tcc": "cpp",
21+
"bitset": "cpp",
22+
"cctype": "cpp",
23+
"chrono": "cpp",
24+
"cinttypes": "cpp",
25+
"clocale": "cpp",
26+
"cmath": "cpp",
27+
"compare": "cpp",
28+
"concepts": "cpp",
29+
"condition_variable": "cpp",
30+
"csetjmp": "cpp",
31+
"csignal": "cpp",
32+
"cstdarg": "cpp",
33+
"cstddef": "cpp",
34+
"cstdint": "cpp",
35+
"cstdio": "cpp",
36+
"cstdlib": "cpp",
37+
"cstring": "cpp",
38+
"ctime": "cpp",
39+
"cwchar": "cpp",
40+
"cwctype": "cpp",
41+
"deque": "cpp",
42+
"list": "cpp",
43+
"map": "cpp",
44+
"set": "cpp",
45+
"unordered_map": "cpp",
46+
"vector": "cpp",
47+
"exception": "cpp",
48+
"algorithm": "cpp",
49+
"functional": "cpp",
50+
"iterator": "cpp",
51+
"memory": "cpp",
52+
"memory_resource": "cpp",
53+
"numeric": "cpp",
54+
"optional": "cpp",
55+
"random": "cpp",
56+
"ratio": "cpp",
57+
"regex": "cpp",
58+
"string_view": "cpp",
59+
"system_error": "cpp",
60+
"tuple": "cpp",
61+
"type_traits": "cpp",
62+
"utility": "cpp",
63+
"fstream": "cpp",
64+
"initializer_list": "cpp",
65+
"iomanip": "cpp",
66+
"iosfwd": "cpp",
67+
"iostream": "cpp",
68+
"istream": "cpp",
69+
"limits": "cpp",
70+
"mutex": "cpp",
71+
"new": "cpp",
72+
"ostream": "cpp",
73+
"ranges": "cpp",
74+
"sstream": "cpp",
75+
"stdexcept": "cpp",
76+
"stop_token": "cpp",
77+
"streambuf": "cpp",
78+
"thread": "cpp",
79+
"typeinfo": "cpp",
80+
"variant": "cpp"
1681
}
1782
}

src/modules/compliance/src/lib/ComplianceInterface.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ int ComplianceMmiSet(MMI_HANDLE clientSession, const char* componentName, const
158158
{
159159
char* tmp = json_serialize_to_string(object.get());
160160
realPayload = tmp;
161-
// json_free_serialized_string(tmp);
161+
json_free_serialized_string(tmp);
162162
}
163-
auto result = engine.mmiSet(objectName, realPayload);
163+
auto result = engine.mmiSet(objectName, std::move(realPayload));
164164
if (!result.has_value())
165165
{
166166
OsConfigLogError(engine.log(), "ComplianceMmiSet failed: %s", result.error().message.c_str());

src/modules/compliance/src/lib/procedures/ensureFilePermissions.cpp

+31-31
Original file line numberDiff line numberDiff line change
@@ -77,35 +77,36 @@ AUDIT_FN(ensureFilePermissions)
7777
}
7878
}
7979

80-
const mode_t supportedMask = 0x1FF;
80+
mode_t perms = 0x0;
81+
mode_t mask = 0x1FF;
82+
bool has_perms_or_mask = false;
8183
if (args.find("permissions") != args.end())
8284
{
8385
char* endptr;
84-
mode_t perms = strtol(args["permissions"].c_str(), &endptr, 8);
86+
perms = strtol(args["permissions"].c_str(), &endptr, 8);
8587
if (('\0' != *endptr) || ((perms & supportedMask) != perms))
8688
{
8789
return Error("Invalid permissions parameter");
8890
}
89-
if (perms != (statbuf.st_mode & supportedMask))
90-
{
91-
logstream << "Invalid permissions - are " << std::oct << (statbuf.st_mode & supportedMask) << " should be " << std::oct << perms << std::dec;
92-
return false;
93-
}
91+
has_perms_or_mask = true;
9492
}
93+
9594
if (args.find("mask") != args.end())
9695
{
9796
char* endptr;
98-
mode_t mask = strtol(args["mask"].c_str(), &endptr, 8);
97+
mask = strtol(args["mask"].c_str(), &endptr, 8);
9998
if (('\0' != *endptr) || ((mask & supportedMask) != mask))
10099
{
101100
return Error("Invalid mask parameter");
102101
}
103-
if (((statbuf.st_mode & supportedMask) & mask) != 0)
104-
{
105-
logstream << "Invalid permissions - are " << std::oct << (statbuf.st_mode & supportedMask) << " should be " << std::oct
106-
<< ((statbuf.st_mode & supportedMask) & (~mask)) << " with mask " << std::oct << mask << std::dec;
107-
return false;
108-
}
102+
mask &= supportedMask;
103+
has_perms_or_mask = true;
104+
}
105+
if (has_perms_or_mask && ((perms & mask) != (statbuf.st_mode & mask)))
106+
{
107+
logstream << "Invalid permissions - are " << std::oct << (statbuf.st_mode & supportedMask) << " should be " << std::oct << perms
108+
<< " with mask " << std::oct << mask << std::dec;
109+
return false;
109110
}
110111

111112
return true;
@@ -189,43 +190,42 @@ REMEDIATE_FN(ensureFilePermissions)
189190
}
190191
}
191192

193+
mode_t perms = 0x1FF;
194+
mode_t mask = 0x1FF;
195+
bool has_perms_or_mask = false;
192196
if (args.find("permissions") != args.end())
193197
{
194198
char* endptr;
195-
const mode_t perms = strtol(args["permissions"].c_str(), &endptr, 8);
199+
perms = strtol(args["permissions"].c_str(), &endptr, 8);
196200
if (('\0' != *endptr) || ((perms & supportedMask) != perms))
197201
{
198202
logstream << "ERROR: Invalid permissions: " << args["permissions"];
199203
return Error("Invalid permissions: " + args["permissions"]);
200204
}
201-
if (perms != (statbuf.st_mode & supportedMask))
202-
{
203-
if (chmod(args["filename"].c_str(), perms) < 0)
204-
{
205-
logstream << "ERROR: Chmod error " << strerror(errno);
206-
return false;
207-
}
208-
}
205+
has_perms_or_mask = true;
209206
}
210207
if (args.find("mask") != args.end())
211208
{
212209
char* endptr;
213-
const mode_t mask = strtol(args["mask"].c_str(), &endptr, 8);
210+
mask = strtol(args["mask"].c_str(), &endptr, 8);
214211
if (('\0' != *endptr) || ((mask & supportedMask) != mask))
215212
{
216213
logstream << "ERROR: Invalid permissions mask: " << args["mask"];
217214
return Error("Invalid permissions mask: " + args["mask"]);
218215
}
219-
if (((statbuf.st_mode & supportedMask) & mask) != 0)
216+
has_perms_or_mask = true;
217+
}
218+
219+
unsigned short new_perms = (statbuf.st_mode & ~mask) | (perms & mask);
220+
OsConfigLogInfo(NULL, "Setting permissions to %o, current: %o, perms: %o, mask: %o", new_perms, statbuf.st_mode, perms, mask);
221+
if (has_perms_or_mask && (new_perms != statbuf.st_mode))
222+
{
223+
if (chmod(args["filename"].c_str(), new_perms) < 0)
220224
{
221-
if (chmod(args["filename"].c_str(), statbuf.st_mode & (~mask)) < 0)
222-
{
223-
logstream << "ERROR: Chmod error " << strerror(errno);
224-
return false;
225-
}
225+
logstream << "ERROR: Chmod error";
226+
return Error("Chmod error");
226227
}
227228
}
228-
229229
return true;
230230
}
231231
} // namespace compliance

src/modules/test/recipes/compliance/EnsureFilePermissions.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
"ObjectType": "Reported",
8484
"ComponentName": "Compliance",
8585
"ObjectName": "auditTest",
86-
"Payload": "{ ensureFilePermissions: ensureFilePermissions for '\/tmp/testfile' Invalid permissions - are 777 should be 644 } == FALSE"
86+
"Payload": "{ ensureFilePermissions: ensureFilePermissions for '\/tmp/testfile' Invalid permissions - are 777 should be 644 with mask 777 } == FALSE"
8787
},
8888
{
8989
"ObjectType": "Desired",

0 commit comments

Comments
 (0)