[Nagios-devel] [PATCH 1/2] nagios: Check execution permission on

Support forum for Nagios Core, Nagios Plugins, NCPA, NRPE, NSCA, NDOUtils and more. Engage with the community of users including those using the open source solutions.
Locked
Guest

[Nagios-devel] [PATCH 1/2] nagios: Check execution permission on

Post by Guest »

=46rom: Ricardo Maraschini

Moved check for execution permission on nagios binary to after
drop daemon's privileges once workers only start to run as
configurated nagios user, while nagios itself may start as root.

Signed-off-by: Ricardo Maraschini

---
base/nagios.c | 21 ++++++++++++---------
1 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/base/nagios.c b/base/nagios.c
index a5603bc..bbc5a2f 100644
--- a/base/nagios.c
+++ b/base/nagios.c
@@ -435,17 +435,10 @@ int main(int argc, char **argv, char **env) {
* it absolute so we can launch our workers.
* If not, we needn't bother, as we're using execvp()
*/
- if (strchr(argv[0], '/')) {
+ if (strchr(argv[0], '/'))
nagios_binary_path =3D nspath_absolute(argv[0], NULL);
- if (access(nagios_binary_path, X_OK) < 0) {
- logit(NSLOG_RUNTIME_ERROR, TRUE, "Error: failed to access() %s: %s\n",=
nagios_binary_path, strerror(errno));
- logit(NSLOG_RUNTIME_ERROR, TRUE, "Error: Spawning workers will be impo=
ssible. Aborting.\n");
- exit(EXIT_FAILURE);
- }
- }
- else {
+ else
nagios_binary_path =3D strdup(argv[0]);
- }
=20
nagios_iobs =3D iobroker_create();
=20
@@ -481,6 +474,16 @@ int main(int argc, char **argv, char **env) {
exit(EXIT_FAILURE);
}
=20
+ /*
+ * in order to spawn workers, we need to have
+ * exec permission as nagios_user on
+ * nagios_binary_path file.
+ */
+ if (access(nagios_binary_path, X_OK) < 0) {
+ logit(NSLOG_RUNTIME_ERROR, TRUE, "Error: failed to access() %s: %s\n",=
nagios_binary_path, strerror(errno));
+ logit(NSLOG_RUNTIME_ERROR, TRUE, "Error: Spawning workers will be impo=
ssible. Aborting.\n");
+ exit(EXIT_FAILURE);
+ }
#ifdef USE_EVENT_BROKER
/* initialize modules */
neb_init_modules();
--=20
1.7.4.1







This post was automatically imported from historical nagios-devel mailing list archives
Original poster: ricardo.maraschini@opservices.com.br
Locked