summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2018-06-07 13:01:27 +0200
committerDaniil Baturin <daniil@baturin.org>2018-06-07 13:01:27 +0200
commite796b6a9dbf8eaa66b746a75c3211d9ea7ac458b (patch)
treec5f2d546a2f3c1fd8c0be19364a5d649d65dab78
parent5a383a1d3c557ca03c0305c69957a45b412a687a (diff)
downloadvyatta-wanloadbalance-e796b6a9dbf8eaa66b746a75c3211d9ea7ac458b.tar.gz
vyatta-wanloadbalance-e796b6a9dbf8eaa66b746a75c3211d9ea7ac458b.zip
T462: run load balancing scripts as vyattacfg GID.
Since it uses the same function for executing everything, need to verify that it has no adverse effect on iptables commands.
-rw-r--r--src/main.cc22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/main.cc b/src/main.cc
index 7994696..2be1edb 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -15,13 +15,13 @@
#include <unistd.h>
#include <iostream>
#include <unistd.h>
+#include <grp.h>
#include "loadbalance.hh"
bool g_check_path = false;
LoadBalance *g_lb = NULL;
pid_t pid_output (const char *path);
-
static void usage()
{
cout << "lb -ftviodh" << endl;
@@ -107,7 +107,7 @@ int main(int argc, char* argv[])
cout << "Configuration file is empty" << endl;
exit(0);
}
-
+
int s = 0;
if (daemon) {
if (fork() != 0) {
@@ -121,7 +121,7 @@ int main(int argc, char* argv[])
}
g_lb = new LoadBalance(debug, output_path);
-
+
bool success = g_lb->set_conf(c_file);
if (success == false) {
syslog(LOG_ERR, "wan_lb: error loading configuration file: %s", c_file.c_str());
@@ -136,9 +136,21 @@ int main(int argc, char* argv[])
cout << "STARTING CYCLE" << endl;
}
+ // Get config owners group GID and set the GID to it to avoid
+ // ruining the permissions of the running config if hooks
+ // execute VyOS configuration commands
+ group* vyattacfg_group = getgrnam("vyattacfg");
+ if (vyattacfg_group == NULL) {
+ syslog(LOG_ERR, "Could not get vyattacfg group ID, exiting");
+ exit(1);
+ }
+ gid_t cfg_gid = vyattacfg_group->gr_gid;
+ setgid(cfg_gid);
+
+
g_lb->init();
-
+
//signal handler here
// sighup...
signal(SIGINT, sig_end);
@@ -193,7 +205,7 @@ pid_output (const char *path)
oldumask = umask(0777 & ~PIDFILE_MASK);
fp = fopen (path, "w");
- if (fp != NULL)
+ if (fp != NULL)
{
fprintf (fp, "%d\n", (int) pid);
fclose (fp);