Skip to content

Commit d1e9796

Browse files
committed
Added argument to NOOP OverrideImmutable functions
Ticket: ENT-10961, CFE-1840 Signed-off-by: Lars Erik Wik <lars.erik.wik@northern.tech>
1 parent a04ecb4 commit d1e9796

File tree

2 files changed

+37
-6
lines changed

2 files changed

+37
-6
lines changed

libpromises/override_fsattrs.c

Lines changed: 28 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,23 @@
77
#include <cf3.defs.h>
88
#include <string_lib.h>
99

10-
bool OverrideImmutableBegin(const char *orig, char *copy, size_t copy_len)
10+
bool OverrideImmutableBegin(
11+
const char *orig, char *copy, size_t copy_len, bool override)
1112
{
13+
if (!override)
14+
{
15+
size_t ret = strlcpy(copy, orig, copy_len);
16+
if (ret >= copy_len)
17+
{
18+
Log(LOG_LEVEL_ERR,
19+
"Failed to copy filename '%s': Filename too long (%zu >= %zu)",
20+
ret,
21+
copy_len);
22+
return false;
23+
}
24+
return true;
25+
}
26+
1227
srand(time(NULL)); /* Seed random number generator */
1328
int rand_number = rand() % 999999;
1429
assert(rand_number >= 0);
@@ -38,8 +53,13 @@ bool OverrideImmutableBegin(const char *orig, char *copy, size_t copy_len)
3853
return true;
3954
}
4055

41-
bool OverrideImmutableCommit(const char *orig, const char *copy)
56+
bool OverrideImmutableCommit(const char *orig, const char *copy, bool override)
4257
{
58+
if (!override)
59+
{
60+
return true;
61+
}
62+
4363
struct stat sb;
4464
if (lstat(orig, &sb) == -1)
4565
{
@@ -133,8 +153,13 @@ bool OverrideImmutableCommit(const char *orig, const char *copy)
133153
return true;
134154
}
135155

136-
bool OverrideImmutableAbort(ARG_UNUSED const char *orig, const char *copy)
156+
bool OverrideImmutableAbort(
157+
ARG_UNUSED const char *orig, const char *copy, bool override)
137158
{
138159
assert(copy != NULL);
160+
if (!override)
161+
{
162+
return true;
163+
}
139164
return unlink(copy) == 0;
140165
}

libpromises/override_fsattrs.h

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,26 +33,32 @@
3333
* @param orig The original file (may be immutable)
3434
* @param copy Updated to contain the filename of the mutable copy
3535
* @param copy_len The size of the buffer to store the filename of the copy
36+
* @param override Whether to actually do override (original filename is
37+
* copied to copy buffer if false)
3638
* @return false in case of failure
3739
*/
38-
bool OverrideImmutableBegin(const char *orig, char *copy, size_t copy_len);
40+
bool OverrideImmutableBegin(
41+
const char *orig, char *copy, size_t copy_len, bool override);
3942

4043
/**
4144
* @brief Temporarily clears the immutable bit of the original file and
4245
* replaces it with the mutated copy
4346
* @param orig The original file (may be immutable)
4447
* @param copy The mutated copy to replace the original
48+
* @param override Whether to actually do override
4549
* @return false in case of failure
4650
* @note The immutable bit is reset to it's original state
4751
*/
48-
bool OverrideImmutableCommit(const char *orig, const char *copy);
52+
bool OverrideImmutableCommit(
53+
const char *orig, const char *copy, bool override);
4954

5055
/**
5156
* @brief Simply unlinks the mutable copy
5257
* @param orig Not used (reserved in for future use)
5358
* @param copy The mutated copy to unlink
59+
* @param override NOOP if override is false
5460
* @return false in case of failure (but you probably don't care)
5561
*/
56-
bool OverrideImmutableAbort(const char *orig, const char *copy);
62+
bool OverrideImmutableAbort(const char *orig, const char *copy, bool override);
5763

5864
#endif /* CFENGINE_OVERRIDE_FSATTRS_H */

0 commit comments

Comments
 (0)