Skip to content

Commit

Permalink
Make server parameter optional when redirect is set
Browse files Browse the repository at this point in the history
According to the documentation, the server parameter is optional if a
redirection is configured. This patch makes the server parameter
optional. It includes a check to make sure at least one of the
parameters is defined. The manpage xinetd.conf(5) defines the precedence
rule if both parameters are defined, so that is not an error.
  • Loading branch information
smoeding authored and eputnam committed Oct 2, 2017
1 parent f45cd0b commit 171d9cd
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 34 deletions.
17 changes: 15 additions & 2 deletions README.md
Expand Up @@ -57,7 +57,8 @@ page.

### Parameters:

* `server` - required - determines the program to execute for this service
* `server` - optional - determines the program to execute for this service (either this or `redirect` is required)
* `redirect` - optional - ip or hostname and port of the target service (either this or `server` is required)
* `port` - optional - determines the service port (required if service is not listed in `/etc/services`)
* `cps` - optional
* `flags` - optional
Expand All @@ -72,7 +73,8 @@ page.
* `wait` - optional - based on $protocol will default to "yes" for udp and "no" for tcp
* `service_type` - optional - type setting in xinetd
* `nice` - optional - integer between -20 and 19, inclusive.
* `redirect` - optional - ip or hostname and port of the target service

Either the `server` or the `redirect` parameter must be set.

### Sample Usage

Expand All @@ -89,6 +91,17 @@ xinetd::service { 'tftp':
}
```

```puppet
xinetd::service { 'ssh-tunnel-host.example.com':
port => '2222',
redirect => 'host.example.com 22',
flags => 'REUSE',
service_type => 'UNLISTED',
bind => "${::ipaddress_eth1}",
only_from => '10.130.50.174',
}
```

## Supported OSes

Supports Debian, FreeBSD, Suse, RedHat, and Amazon Linux OS Families.
Expand Down
64 changes: 34 additions & 30 deletions manifests/service.pp
Expand Up @@ -22,7 +22,7 @@
# $flags - optional
# $per_source - optional
# $port - optional - determines the service port (required if service is not listed in /etc/services)
# $server - required - determines the program to execute for this service
# $server - optional - determines the program to execute for this service
# $server_args - optional
# $disable - optional - defaults to "no"
# $socket_type - optional - defaults to "stream"
Expand All @@ -45,7 +45,7 @@
# setups up a xinetd service by creating a file in /etc/xinetd.d/
#
# Requires:
# $server must be set
# $server or $redirect must be set
# $port must be set
#
# Sample Usage:
Expand All @@ -63,40 +63,44 @@
# } # xinetd::service
#
define xinetd::service (
$server,
$port = undef,
$ensure = present,
$log_on_success = undef,
$log_on_success_operator = '+=',
$log_on_failure = undef,
$log_on_failure_operator = '+=',
$service_type = undef,
$service_name = $title,
$cps = undef,
$disable = 'no',
$flags = undef,
$group = undef,
$groups = 'yes',
$instances = 'UNLIMITED',
$per_source = undef,
$server = undef,
$port = undef,
$ensure = present,
$log_on_success = undef,
$log_on_success_operator = '+=',
$log_on_failure = undef,
$log_on_failure_operator = '+=',
$service_type = undef,
$service_name = $title,
$cps = undef,
$disable = 'no',
$flags = undef,
$group = undef,
$groups = 'yes',
$instances = 'UNLIMITED',
$per_source = undef,
Enum['tcp', 'udp'] $protocol = 'tcp',
$server_args = undef,
$socket_type = 'stream',
$user = undef,
$only_from = undef,
$wait = undef,
$xtype = undef,
$no_access = undef,
$access_times = undef,
$log_type = undef,
$bind = undef,
$server_args = undef,
$socket_type = 'stream',
$user = undef,
$only_from = undef,
$wait = undef,
$xtype = undef,
$no_access = undef,
$access_times = undef,
$log_type = undef,
$bind = undef,
Optional[Integer[-20, 19]] $nice = undef,
$env = undef,
$redirect = undef,
$env = undef,
$redirect = undef,
) {

include ::xinetd

unless ($server or $redirect) {
fail('xinetd::service needs either of server or redirect')
}

if $user {
$_user = $user
} else {
Expand Down
18 changes: 16 additions & 2 deletions spec/defines/xinetd_service_spec.rb
Expand Up @@ -129,13 +129,27 @@

describe 'with redirect' do
let :params do
default_params.merge({
{
:port => '80',
:redirect => 'somehost.somewhere 65535',
})
}
end
it {
should contain_file('/etc/xinetd.d/httpd').with_content(
/redirect\s*\=\s*somehost.somewhere 65535/)
}
end

describe 'without redirect and server' do
let :params do
{
:port => '80',
}
end
it 'should fail' do
expect {
should contain_class('xinetd')
}.to raise_error(Puppet::Error)
end
end
end
2 changes: 2 additions & 0 deletions templates/service.erb
Expand Up @@ -13,7 +13,9 @@ service <%= @service_name %>
user = <%= @_user %>
group = <%= @_group %>
groups = <%= @groups %>
<% if @server -%>
server = <%= @server %>
<% end -%>
<% if @bind -%>
bind = <%= @bind %>
<% end -%>
Expand Down

0 comments on commit 171d9cd

Please sign in to comment.