diff --git a/cf-agent/simulate_mode.c b/cf-agent/simulate_mode.c index 0335781fe6a..ef6faa33aa4 100644 --- a/cf-agent/simulate_mode.c +++ b/cf-agent/simulate_mode.c @@ -1183,6 +1183,16 @@ static JsonElement *ChangedFileAsJson(const char *path) /* The permissions of a symbolic link are meaningless. */ if (S_ISLNK(st.st_mode)) { + char target[PATH_MAX] = {0}; + if (readlink(chrooted_path, target, sizeof(target) - 1) > 0) + { + const char *real_target = target; + if (IsAbsoluteFileName(target)) + { + real_target = ToNormalRoot(target); + } + JsonObjectAppendString(file_info, "target", real_target); + } return file_info; } #endif /* !__MINGW32__ */ diff --git a/tests/acceptance/29_simulate_mode/simulate_json.cf.expected b/tests/acceptance/29_simulate_mode/simulate_json.cf.expected index 14ec57a300b..7a6782c7a93 100644 --- a/tests/acceptance/29_simulate_mode/simulate_json.cf.expected +++ b/tests/acceptance/29_simulate_mode/simulate_json.cf.expected @@ -28,6 +28,7 @@ "change": "created", "gid": GID, "path": "WORKDIR/tmp/link", + "target": "WORKDIR/tmp/modify-me", "type": "symbolic link", "uid": UID }