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

Fixes #5890: add windows support for motd technique #590

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
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#####################################################################################
# Copyright 2011-2013 Normation SAS
#####################################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#####################################################################################

##############################################################################
# This Technique configures a machine MOTD. See metadata.xml for more details.
##############################################################################

bundle agent rudder_motd
{
vars:
"rudder_motd_service_name" string => "MOTD";

# Prefix for all the defined classes
"rudder_motd_class_prefix" string => "rudder_motd";

"rudder_motd_config[payload]" string => "&MOTD&";

"rudder_motd_config[location]" string => "&MOTD_LOCATION&";

"rudder_motd_config[file_empty]" string => "&MOTD_EMPTY&";

"rudder_motd_config[trackingkey]" string => "&TRACKINGKEY&";

methods:
# Note:
# The reporting is made on separate bundles to abstract the complexity
# inherent to the normal ordering.
"any" usebundle => rudder_motd_configuration("${rudder_motd_class_prefix}", "${rudder_motd_service_name}", "${rudder_motd_config[trackingkey]}", "rudder_motd.rudder_motd_config");
"any" usebundle => rudder_motd_configuration_reporting("${rudder_motd_class_prefix}", "${rudder_motd_service_name}", "${rudder_motd_config[trackingkey]}");
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#####################################################################################
# Copyright 2011-2013 Normation SAS
#####################################################################################
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, Version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#####################################################################################

##############################################################
# Sets the MOTD according to the value given in the Directive.
##############################################################

bundle agent rudder_motd_configuration(class_prefix, service_name, trackingkey, params)
{
vars:
"rudder_motd_payload" string => "${${params}[payload]}";
"rudder_motd_location" string => "${${params}[location]}";
"rudder_motd_empty" string => "${${params}[file_empty]}";

debian::
"rudder_motd_file" slist => { "/etc/motd", "/etc/motd.tail" };
!debian::
"rudder_motd_file" slist => { "/etc/motd" };

aix::
"rudder_motd_group" string => "bin";
!aix::
"rudder_motd_group" string => "root";

classes:
"rudder_motd_absent" not => fileexists("/etc/motd");

files:
# Set every MOTD file to the wanted value
!windows::
"${rudder_motd_file}"
create => "true",
edit_defaults => rudder_empty_select("${rudder_motd_empty}"),
perms => mog("644", "root", "${rudder_motd_group}"),
edit_line => rudder_line_insertion("${rudder_motd_payload}", "${rudder_motd_location}"),
classes => rudder_common_classes("${class_prefix}_file_edition");

&if(NOVA)&

databases:
windows::
"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
database_operation => "create",
database_rows => { "legalnoticecaption,REG_SZ,Notice"},
database_type => "ms_registry",
comment => "Editing the windows registry";

"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Winlogon"
database_operation => "create",
database_rows => { "legalnoticetext,REG_SZ,${rudder_motd_payload}"},
database_type => "ms_registry",
comment => "Editing the windows registry",
classes => rudder_common_classes("${class_prefix}_file_edition");
&endif&

methods:
# Here, we will define reports for elements which only have a local visibility (like the MOTD file presence detection).
!windows.rudder_motd_absent::
"any"
usebundle => rudder_common_report("${service_name}", "log_repaired", "${trackingkey}", "MOTD Configuration", "None", "The ${service_name} file was absent, it will be created");

}

# The reporting is made on separate bundles to abstract the complexity
# inherent to the normal ordering.
bundle agent rudder_motd_configuration_reporting(class_prefix, service_name, trackingkey)
{
methods:
"any" usebundle => rudder_common_reports_generic("${service_name}", "${class_prefix}_file_edition", "${trackingkey}", "MOTD Configuration", "None", "The ${service_name} file");
windows::
"any"
usebundle => rudder_common_report("${service_name}", "result_error", "${trackingkey}", "MOTD Configuration", "None", "This is a Windows machine. This Technique currently incompatible with it");
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<!--
Copyright 2011 Normation SAS

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, Version 3.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<!--
This is the MOTD configuration PT.
Compatibility : UNIX like

It is intended to check if the required motd is installed.
-->
<TECHNIQUE name="MOTD configuration">
<DESCRIPTION>This technique will check if the required Message Of The Day is present on the system.</DESCRIPTION>
<COMPATIBLE>
<OS version="System V and related, Windows">UNIX, Windows</OS>
<AGENT version=">= 3.5.3">cfengine-community</AGENT>
<AGENT version=">= 3.6.0">cfengine-enterprise</AGENT>
</COMPATIBLE>

<MULTIINSTANCE>false</MULTIINSTANCE>

<BUNDLES>
<NAME>rudder_motd</NAME>
</BUNDLES>

<SYSTEMVARS>
<NAME>NOVA</NAME>
</SYSTEMVARS>

<TMLS>
<TML name="config"/>
<TML name="main"/>
</TMLS>

<SECTIONS>
<SECTION name="MOTD Configuration" component="true">
<INPUT>
<NAME>MOTD</NAME>
<DESCRIPTION>Message of the day (MOTD) to display</DESCRIPTION>
<CONSTRAINT>
<TYPE>textarea</TYPE>
</CONSTRAINT>
</INPUT>
<SELECT1>
<NAME>MOTD_LOCATION</NAME>
<DESCRIPTION>Where should this text be added in the MOTD</DESCRIPTION>
<LONGDESCRIPTION>This option defines if the content specified before should be appended or prepended to the file. It is irrelevant if you enforce the file content (option below), or on Windows</LONGDESCRIPTION>
<ITEM>
<LABEL>At the beginning</LABEL>
<VALUE>before</VALUE>
</ITEM>
<ITEM>
<LABEL>At the end</LABEL>
<VALUE>after</VALUE>
</ITEM>
<CONSTRAINT>
<DEFAULT>after</DEFAULT>
</CONSTRAINT>
</SELECT1>
<SELECT1>
<NAME>MOTD_EMPTY</NAME>
<DESCRIPTION>Enforce this MOTD only</DESCRIPTION>
<LONGDESCRIPTION>This option will remove any existing messages in the motd file and replace them with the text provided above. On Windows, the provided text will always remove any existing message</LONGDESCRIPTION>
<ITEM>
<LABEL>Yes</LABEL>
<VALUE>true</VALUE>
</ITEM>
<ITEM>
<LABEL>No</LABEL>
<VALUE>false</VALUE>
</ITEM>
<CONSTRAINT>
<DEFAULT>false</DEFAULT>
</CONSTRAINT>
</SELECT1>
</SECTION>
</SECTIONS>

</TECHNIQUE>