Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CFE-4053: Fixed bug where default:sys.fqhost contained many spaces #5531

Merged
merged 1 commit into from
Jun 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 16 additions & 9 deletions libpromises/expand.c
Original file line number Diff line number Diff line change
Expand Up @@ -945,19 +945,26 @@ static void ResolveControlBody(EvalContext *ctx, GenericAgentConfig *config,
Log(LOG_LEVEL_VERBOSE, "SET domain = %s", VDOMAIN);

EvalContextVariableRemoveSpecial(ctx, SPECIAL_SCOPE_SYS, "domain");
EvalContextVariableRemoveSpecial(ctx, SPECIAL_SCOPE_SYS, "fqhost");

// We don't expect hostname or domain name longer than 255,
// warnings are printed in sysinfo.c.
// Here we support up to 511 bytes, just in case, because we can:
snprintf(VFQNAME, CF_MAXVARSIZE, "%511s.%511s", VUQNAME, VDOMAIN);
EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_SYS, "fqhost",
VFQNAME, CF_DATA_TYPE_STRING,
"inventory,source=agent,attribute_name=Host name");
EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_SYS, "domain",
VDOMAIN, CF_DATA_TYPE_STRING,
"source=agent");
EvalContextClassPutHard(ctx, VDOMAIN, "source=agent");

int ret = snprintf(VFQNAME, CF_MAXVARSIZE, "%s.%s", VUQNAME, VDOMAIN);
Copy link
Member

Choose a reason for hiding this comment

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

@larsewi In this case, the diff is rather big, but the important difference is the change from %511s.%511s to %s.%s. I would've explained this in the commit (as you did in the ticket).

assert(ret >= 0 && ret < CF_MAXVARSIZE);
if (ret < 0 || ret >= CF_MAXVARSIZE)
{
Log(LOG_LEVEL_ERR,
"Failed to update variable default:sys.fqhost to include domain name: "
"Maximum variable size was exceeded (%d >= %d)", ret, CF_MAXVARSIZE);
}
else
{
EvalContextVariableRemoveSpecial(ctx, SPECIAL_SCOPE_SYS, "fqhost");
EvalContextVariablePutSpecial(ctx, SPECIAL_SCOPE_SYS, "fqhost",
VFQNAME, CF_DATA_TYPE_STRING,
"inventory,source=agent,attribute_name=Host name");
}
}

if (strcmp(lval, CFG_CONTROLBODY[COMMON_CONTROL_IGNORE_MISSING_INPUTS].lval) == 0)
Expand Down
33 changes: 33 additions & 0 deletions tests/acceptance/01_vars/01_basic/fqhost_domain.cf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
##############################################################
#
# Test default:sys.fqhost with domain CFE-4053
#
##############################################################

body common control
{
domain => "cfengine.com";
bundlesequence => { "check" };
}

bundle agent __main__
{
methods:
"check";
}

##############################################################

bundle agent check
{
reports:
DEBUG::
"$(sys.fqhost), $(sys.uqhost).cfengine.com";

any::
"$(this.promise_filename) Pass"
if => strcmp( "$(sys.fqhost)", "$(sys.uqhost).cfengine.com" );

"$(this.promise_filename) FAIL"
unless => strcmp( "$(sys.fqhost)", "$(sys.uqhost).cfengine.com" );
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't expect this to work on my machine. And many other machines...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Why is this?

Copy link
Contributor

Choose a reason for hiding this comment

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

Because I don't think my machine has $(sys.uqhost).cfengine.com as its FQDN. Or are we ensuring that somewhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Aren't we doing that with domain => "cfengine.com" in body common control?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh! I guess we are! I didn't see that. Or rather, I didn't even know it was possible. 😅

}
Loading