Skip to content

Fixed --simulate=diff to report permission and ownership changes - #6436

Merged
larsewi merged 1 commit into
cfengine:masterfrom
nickanderson:ENT-14694/master
Oct 26, 2026
Merged

larsewi merged 1 commit into
cfengine:masterfrom
nickanderson:ENT-14694/master

Conversation

@nickanderson

@nickanderson nickanderson commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

With --simulate=diff, a file whose mode, owner or group changed without its contents was listed in the report with nothing under it, because only diff -u on the contents was shown. The report now prints the permission, owner and group changes before the content diff, e.g.:

'/tmp/perms' changed permissions from 0600 to 0000
'/tmp/chown-me' changed owner from 0/root to 2/bin
'/tmp/chown-me' changed group from 0/root to 2/bin

Ticket: ENT-14694

@nickanderson

Copy link
Copy Markdown
Member Author

@cf-bottom jenkins

@cf-bottom

Copy link
Copy Markdown

@nickanderson

Copy link
Copy Markdown
Member Author

@cf-bottom jenkins

@cf-bottom

Copy link
Copy Markdown

Comment thread cf-agent/simulate_mode.c Outdated
char name[CF_SMALLBUF];
if (GetUserName(uid, name, sizeof(name), LOG_LEVEL_VERBOSE))
{
snprintf(buf, buf_size, "%ju/%s", (uintmax_t) uid, name);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would be nice to handle truncation

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lmk if your happy with the change.

The diff report only ran 'diff -u' on file contents, so a file whose
mode, owner or group changed without its contents was listed with
nothing under it. Permission, owner and group changes are now printed
before the content diff.

Ticket: ENT-14694
Changelog: Title
@nickanderson

Copy link
Copy Markdown
Member Author

Done. FormatUser() and FormatGroup() now check the snprintf() result with an assert, like the rest of cf-agent does. It can't actually truncate: the buffers are CF_BUFSIZE, and the output is at most a 20-digit id, a / and a name that fits in CF_SMALLBUF.

@larsewi
larsewi merged commit dcc4e17 into cfengine:master Oct 26, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants