summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@Pirx.gnu.org.ua>2009-04-27 14:23:50 (GMT)
committer Sergey Poznyakoff <gray@Pirx.gnu.org.ua>2009-04-27 14:23:50 (GMT)
commit4d22b4e8668cc717440d66120b8607be9a273c97 (patch) (side-by-side diff)
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.
Diffstat (more/less context) (ignore whitespace changes)
-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
@@ -435,3 +435,3 @@ change_user ()
- if (getuid () == 0)
+ if (getuid ())
{
@@ -496,11 +496,13 @@ 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 ();
@@ -533,5 +535,5 @@ 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)
@@ -773,2 +775,4 @@ main (int argc, char **argv)
html_template = html_template_option;
+ if (user_option)
+ user = user_option;
@@ -792,7 +796,2 @@ 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)
@@ -806,2 +805,14 @@ 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)
@@ -840,5 +851,2 @@ main (int argc, char **argv)
- if (user_option)
- change_user ();
-
sockfd = socket (listen_sockaddr.sa->sa_family,
diff --git a/src/report.c b/src/report.c
index ed3a81b..398881b 100644
--- a/src/report.c
+++ b/src/report.c
@@ -43,3 +43,3 @@ tagr_db_report (char *str)
-void
+int
open_db (int flag)
@@ -57,4 +57,5 @@ open_db (int flag)
dbname, gdbm_strerror (gdbm_errno));
- exit (1);
+ return 1;
}
+ return 0;
}
@@ -204,3 +205,4 @@ list_db ()
- open_db (TAGR_DB_RD);
+ if (open_db (TAGR_DB_RD))
+ exit (EX_UNAVAILABLE);
key = gdbm_firstkey (dbf);
@@ -280,12 +282,14 @@ 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
@@ -428,3 +428,4 @@ import (const char *dirname)
{
- open_db (TAGR_DB_WR);
+ if (open_db (TAGR_DB_WR))
+ exit (EX_UNAVAILABLE);
if (import_log (dirname) == 0)
@@ -447,3 +448,4 @@ 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++)
diff --git a/src/tagr.h b/src/tagr.h
index fafd56b..a66837e 100644
--- a/src/tagr.h
+++ b/src/tagr.h
@@ -218,3 +218,3 @@ struct traffic_record
#define TAGR_DB_WR 1
-void open_db (int);
+int open_db (int);
void close_db ();

Return to:

Send suggestions and report system problems to the System administrator.