aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@Pirx.gnu.org.ua>2009-04-27 17:23:50 +0300
committerSergey Poznyakoff <gray@Pirx.gnu.org.ua>2009-04-27 17:23:50 +0300
commit4d22b4e8668cc717440d66120b8607be9a273c97 (patch)
tree93b4addac108a1c8e913f0d5c68cb513f5c82c31
parentfe8f5226e8bc39bdc75e40e1c1ea464e9fc60ad3 (diff)
downloadtagr-4d22b4e8668cc717440d66120b8607be9a273c97.tar.gz
tagr-4d22b4e8668cc717440d66120b8607be9a273c97.tar.bz2
Bugfixes.
* src/main.c (change_user): Bugfix (main): Reset user to the value of user_option, if set. Fix (again) log_to_stderr initialization. Switch to user privileges before actually performing any actions that modify the database and other output files. * src/report.c (open_db): Don't exit if unable to open database. Return 1 instead. All callers updated. * src/tagr.h (open_db): Update prototype.
-rw-r--r--src/main.c46
-rw-r--r--src/report.c26
-rw-r--r--src/stat.c6
-rw-r--r--src/tagr.h2
4 files changed, 47 insertions, 33 deletions
diff --git a/src/main.c b/src/main.c
index 9b98ec5..6530ca0 100644
--- a/src/main.c
+++ b/src/main.c
@@ -434,5 +434,5 @@ change_user ()
return;
- if (getuid () == 0)
+ if (getuid ())
{
logmsg (L_NOTICE, _("not a superuser: ignoring the `user' statement"));
@@ -495,13 +495,15 @@ decode_buffer ()
}
- open_db (TAGR_DB_WR);
- for (i = 0; i < reply->n_addr; i++, sp++)
+ if (open_db (TAGR_DB_WR) == 0)
{
- sp->in = ntohl (sp->in);
- sp->out = ntohl (sp->out);
- verbose (1, _("Monitor %s: %lu %lu"), sp->name, sp->in, sp->out);
- report (sp, reply->timestamp);
+ for (i = 0; i < reply->n_addr; i++, sp++)
+ {
+ sp->in = ntohl (sp->in);
+ sp->out = ntohl (sp->out);
+ verbose (1, _("Monitor %s: %lu %lu"), sp->name, sp->in, sp->out);
+ report (sp, reply->timestamp);
+ }
+ close_db ();
}
- close_db ();
if (child)
@@ -532,7 +534,7 @@ read_input (const char *name)
}
- verbose (2, _("Reading `%s'"), name);
-
- open_db (TAGR_DB_WR);
+ if (open_db (TAGR_DB_WR))
+ exit (EX_UNAVAILABLE);
+
while (getline (&buf, &bufsize, fp) > 0)
{
@@ -772,4 +774,6 @@ main (int argc, char **argv)
if (html_template_option)
html_template = html_template_option;
+ if (user_option)
+ user = user_option;
argc -= index;
@@ -791,9 +795,4 @@ main (int argc, char **argv)
}
- if (log_to_stderr == -1)
- log_to_stderr = foreground && isatty (0);
- grecs_log_to_stderr = log_to_stderr;
- init_syslog (program_invocation_short_name);
-
if (test_template_option)
{
@@ -805,4 +804,16 @@ main (int argc, char **argv)
}
+ if (user)
+ change_user ();
+
+ if (log_to_stderr == -1)
+ log_to_stderr = (import_option
+ || read_option
+ || rebuild_option
+ || list_option
+ || foreground) && isatty (0);
+ grecs_log_to_stderr = log_to_stderr;
+ init_syslog (program_invocation_short_name);
+
if (import_option)
{
@@ -839,7 +850,4 @@ main (int argc, char **argv)
}
- if (user_option)
- change_user ();
-
sockfd = socket (listen_sockaddr.sa->sa_family,
SOCK_DGRAM, 0);
diff --git a/src/report.c b/src/report.c
index ed3a81b..398881b 100644
--- a/src/report.c
+++ b/src/report.c
@@ -42,5 +42,5 @@ tagr_db_report (char *str)
}
-void
+int
open_db (int flag)
{
@@ -56,6 +56,7 @@ open_db (int flag)
logmsg (L_ERR, _("cannot open database %s: %s"),
dbname, gdbm_strerror (gdbm_errno));
- exit (1);
+ return 1;
}
+ return 0;
}
@@ -203,5 +204,6 @@ list_db ()
struct monitor *mon;
- open_db (TAGR_DB_RD);
+ if (open_db (TAGR_DB_RD))
+ exit (EX_UNAVAILABLE);
key = gdbm_firstkey (dbf);
while (key.dptr)
@@ -279,14 +281,16 @@ rebuild (int force)
verbose (1, _("rebuild initiated"));
- open_db (TAGR_DB_WR);
- key = gdbm_firstkey (dbf);
- while (key.dptr)
+ if (open_db (TAGR_DB_RD) == 0)
{
- datum nextkey = gdbm_nextkey ( dbf, key );
- update_monitor (key, now, force);
- free (key.dptr);
- key = nextkey;
+ key = gdbm_firstkey (dbf);
+ while (key.dptr)
+ {
+ datum nextkey = gdbm_nextkey ( dbf, key );
+ update_monitor (key, now, force);
+ free (key.dptr);
+ key = nextkey;
+ }
+ close_db ();
}
- close_db ();
verbose (1, _("rebuild finished"));
}
diff --git a/src/stat.c b/src/stat.c
index 85b76d9..813c5cb 100644
--- a/src/stat.c
+++ b/src/stat.c
@@ -427,5 +427,6 @@ import (const char *dirname)
else if (S_ISREG (st.st_mode))
{
- open_db (TAGR_DB_WR);
+ if (open_db (TAGR_DB_WR))
+ exit (EX_UNAVAILABLE);
if (import_log (dirname) == 0)
count++;
@@ -446,5 +447,6 @@ import (const char *dirname)
{
case 0:
- open_db (TAGR_DB_WR);
+ if (open_db (TAGR_DB_WR))
+ exit (EX_UNAVAILABLE);
for (i = 0; i < gl.gl_pathc; i++)
if (import_log (gl.gl_pathv[i]) == 0)
diff --git a/src/tagr.h b/src/tagr.h
index fafd56b..a66837e 100644
--- a/src/tagr.h
+++ b/src/tagr.h
@@ -217,5 +217,5 @@ struct traffic_record
#define TAGR_DB_RD 0
#define TAGR_DB_WR 1
-void open_db (int);
+int open_db (int);
void close_db ();
void read_db (struct monitor *mon, struct traffic_record **tr);

Return to:

Send suggestions and report system problems to the System administrator.