Low: pgsql: change pgsql-status into UNKNOWN when validation is failed on stop

Change pgsql-status into UNKNOWN when validation is failed on stop.
Because pgsql-status remains in HS even though validation failure
means stop succeeded in pgsql RA.
Low: tools/findif: fix comment typos

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Low: tools/findif: make ConvertQuadToInt use netmask_bits fnc

This is not only to simplify ConvertQuadToInt and practice DRY
principle, but also to make it a little bit safer.  Because
of vague data types involved (instead of uint32_t at al.),
this at least adds one assurance and that is that the logic
will not get broken on architecture with 16bit int
(provided that long has still 32bit, which is not guaranteed
either).

Newly, failure of inet_pton (especially, malformed IP address
format) is indicated via -1 return value.  Previously, such
case was not handled safely.

The patch also unifies tab usage (ConvertQuadToInt was the only
function using spaces for indentation).

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Low: tools/findif: split ValidateNetmaskBits (conv.+valid.)

This commits moves conversion logic from ValidateNetmaskBits into
a separate function (ConvertNetmaskBitsToInt).  This way, we can
validate resulting number of netmask's bits, no matter if the original
string specified netmask as IP expression (via ConvertQuadToInt) or
directly as number of its bits (via ConvertNetmaskBitsToInt).

In turn, we are reaching the original goal to remove ill-advised
reuse of the storage with a string obtained by getenv call
(see netmaskbits, its initialization and rewrite using snprintf).

Strictly viewed, pointer to string returned by getenv should rather
not be stored at all (see [1]), but at least, this patch makes
the program conform to "[t]he application shall ensure that it does
not modify the string pointed to by the getenv() function" part
of getent POSIX documentation (per [1], C standard ditto).

[1] https://www.securecoding.cert.org/confluence/pages/viewpage.action?pageId=1703960

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Medium: IPaddr2: use better test for infiniband (bnc#783353)
Low: tools/findif: remove superfluous string termination

The string is already terminated at that position
(see "man fgets strlen").

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Low: tools/findif: sanitize SearchUsingRouteCmd a bit

Not knowing how the input SearchUsingRouteCmd generates and subsequently
processing [*], only the most conservative changes are contained in this
patch.

First, there was a futile assigment that would only be valid if
commented out strsep calls were in effect.  Due to this, the assigment
was also only commented out.

Next, return value used to be taken from the first strtok in sequence,
only to be overwritten by another one.

Finally, if strtok unexpectedly returned NULL (due to input format other
than expected), it was not handled gracefully.

[*] "route -n get <addr>" is not supported in RHEL neither in Fedora

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Med: heartbeat/IPv6addr.c: missing check for socket call

Suggested-by: Pavel Raiskup <praiskup@redhat.com>
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Med: heartbeat/IPv6addr.c: bad check for socket call

Suggested-by: Pavel Raiskup <praiskup@redhat.com>
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Low: tools/sfex_init.c: fix unchecked return value

Suggested-by: Pavel Raiskup <praiskup@redhat.com>
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Low: tools/send_arp.linux.c: clarify fall-through in switch

Reported-by: Pavel Raiskup <praiskup@redhat.com>
Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Medium: Raid1: discover block size for dd (bnc#781137)
Merge pull request #144 from jnpkrn/patches2

Med: heartbeat/IPv6addr.c: bad+missing check for socket call
Low: tools/findif: add test-findif.sh

Basically, this validates previous findif changes.

As can be seen, the patches do not introduce regression (at least in the
tested cases), but additionally fix cases where netmask is specified
in the IP-like but broken form.

Before the changes:

[...]
------ 30) DUMMY_IP+1, explicit *invalid* netmask (missing last item in quad)
OCF_RESKEY_ip=198.51.100.2 OCF_RESKEY_cidr_netmask=255.255.255.
Converted dotted-quad netmask to CIDR as: 6
FAIL exit code: 0 vs 6
[FAIL]
------ 30) DUMMY_IP+1, explicit *invalid* netmask (random string containing dot)
OCF_RESKEY_ip=198.51.100.2 OCF_RESKEY_cidr_netmask=foo.bar
Converted dotted-quad netmask to CIDR as: 6
FAIL exit code: 0 vs 6
[FAIL]
--- TOTAL ---
[FAIL] 2
[...]

After the changes:

[...]
------ 30) DUMMY_IP+1, explicit *invalid* netmask (missing last item in
quad)
OCF_RESKEY_ip=198.51.100.2 OCF_RESKEY_cidr_netmask=255.255.255.
Converted dotted-quad netmask to CIDR as: -1
Invalid netmask specification [255.255.255.]
[ OK ]
------ 30) DUMMY_IP+1, explicit *invalid* netmask (random string
containing dot)
OCF_RESKEY_ip=198.51.100.2 OCF_RESKEY_cidr_netmask=foo.bar
Converted dotted-quad netmask to CIDR as: -1
Invalid netmask specification [foo.bar]
[ OK ]
--- TOTAL ---
[ OK ]
[...]

Signed-off-by: Jan Pokorný <jpokorny@redhat.com>
Merge pull request #143 from jnpkrn/patches

 Low: tools/findif: various cleanups
LVM Agents:  Warn instead of fail if initrd is newer than lvm.conf

There are many reasons why a user may change the lvm.conf file.  They might
change filters or default segment types, etc.  Making the HA LVM scripts
error our every time the lvm.conf file is newer than the initrd, can cause
serious problems.  For example, if a service is running and lvm.conf is
changed, a subsequent fail-over would not work because the HA LVM script
would abort on this condition.

Instead of making things potentially worse, we have the scripts warn the
user (rather than failing) whenever this condition is hit.  That way,
the user isn't suddenly surprised by things not working.

Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
LVM Agents:  Add quotes around expressions used in conditionals

When variables have the possibility of expanding to more than one word,
we must have quotes around them or we will get errors, like:
	"line 46: [: too many arguments"

Signed-off-by: Jonathan Brassow <jbrassow@redhat.com>
Merge pull request #145 from jnpkrn/patches3

Low: tools: little cleanup
Merge pull request #146 from jbrassow/master

Bug fixes for HA LVM resource agents
resource-agents: Fix return code in fslib.sh

Patch from John Ruemker <jruemker@redhat.com>:

When you have an fs resource that depends on an lvm resource in a service,
and that lvm resource fails to start, the subsequent attempt to stop the fs
resource will fail because the device doesn't exist (since the logical
volume was never activated).

Because we're stopping a resource that is not actually running
(the fs isn't mounted), the operation should succeed here. Instead it
fails, preventing recovery.

Resolves: rhbz#853249
Signed-off-by: Ryan McCabe <rmccabe@redhat.com>