diff options
author | Sergey Poznyakoff <gray@Pirx.gnu.org.ua> | 2009-04-27 17:23:50 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@Pirx.gnu.org.ua> | 2009-04-27 17:23:50 +0300 |
commit | 4d22b4e8668cc717440d66120b8607be9a273c97 (patch) | |
tree | 93b4addac108a1c8e913f0d5c68cb513f5c82c31 | |
parent | fe8f5226e8bc39bdc75e40e1c1ea464e9fc60ad3 (diff) | |
download | tagr-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.c | 46 | ||||
-rw-r--r-- | src/report.c | 26 | ||||
-rw-r--r-- | src/stat.c | 6 | ||||
-rw-r--r-- | src/tagr.h | 2 |
4 files changed, 47 insertions, 33 deletions
@@ -435,3 +435,3 @@ change_user () | |||
435 | 435 | ||
436 | if (getuid () == 0) | 436 | if (getuid ()) |
437 | { | 437 | { |
@@ -496,11 +496,13 @@ decode_buffer () | |||
496 | 496 | ||
497 | open_db (TAGR_DB_WR); | 497 | if (open_db (TAGR_DB_WR) == 0) |
498 | for (i = 0; i < reply->n_addr; i++, sp++) | ||
499 | { | 498 | { |
500 | sp->in = ntohl (sp->in); | 499 | for (i = 0; i < reply->n_addr; i++, sp++) |
501 | sp->out = ntohl (sp->out); | 500 | { |
502 | verbose (1, _("Monitor %s: %lu %lu"), sp->name, sp->in, sp->out); | 501 | sp->in = ntohl (sp->in); |
503 | report (sp, reply->timestamp); | 502 | sp->out = ntohl (sp->out); |
503 | verbose (1, _("Monitor %s: %lu %lu"), sp->name, sp->in, sp->out); | ||
504 | report (sp, reply->timestamp); | ||
505 | } | ||
506 | close_db (); | ||
504 | } | 507 | } |
505 | close_db (); | ||
506 | 508 | ||
@@ -533,5 +535,5 @@ read_input (const char *name) | |||
533 | 535 | ||
534 | verbose (2, _("Reading `%s'"), name); | 536 | if (open_db (TAGR_DB_WR)) |
535 | 537 | exit (EX_UNAVAILABLE); | |
536 | open_db (TAGR_DB_WR); | 538 | |
537 | while (getline (&buf, &bufsize, fp) > 0) | 539 | while (getline (&buf, &bufsize, fp) > 0) |
@@ -773,2 +775,4 @@ main (int argc, char **argv) | |||
773 | html_template = html_template_option; | 775 | html_template = html_template_option; |
776 | if (user_option) | ||
777 | user = user_option; | ||
774 | 778 | ||
@@ -792,7 +796,2 @@ main (int argc, char **argv) | |||
792 | 796 | ||
793 | if (log_to_stderr == -1) | ||
794 | log_to_stderr = foreground && isatty (0); | ||
795 | grecs_log_to_stderr = log_to_stderr; | ||
796 | init_syslog (program_invocation_short_name); | ||
797 | |||
798 | if (test_template_option) | 797 | if (test_template_option) |
@@ -806,2 +805,14 @@ main (int argc, char **argv) | |||
806 | 805 | ||
806 | if (user) | ||
807 | change_user (); | ||
808 | |||
809 | if (log_to_stderr == -1) | ||
810 | log_to_stderr = (import_option | ||
811 | || read_option | ||
812 | || rebuild_option | ||
813 | || list_option | ||
814 | || foreground) && isatty (0); | ||
815 | grecs_log_to_stderr = log_to_stderr; | ||
816 | init_syslog (program_invocation_short_name); | ||
817 | |||
807 | if (import_option) | 818 | if (import_option) |
@@ -840,5 +851,2 @@ main (int argc, char **argv) | |||
840 | 851 | ||
841 | if (user_option) | ||
842 | change_user (); | ||
843 | |||
844 | sockfd = socket (listen_sockaddr.sa->sa_family, | 852 | 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) | |||
43 | 43 | ||
44 | void | 44 | int |
45 | open_db (int flag) | 45 | open_db (int flag) |
@@ -57,4 +57,5 @@ open_db (int flag) | |||
57 | dbname, gdbm_strerror (gdbm_errno)); | 57 | dbname, gdbm_strerror (gdbm_errno)); |
58 | exit (1); | 58 | return 1; |
59 | } | 59 | } |
60 | return 0; | ||
60 | } | 61 | } |
@@ -204,3 +205,4 @@ list_db () | |||
204 | 205 | ||
205 | open_db (TAGR_DB_RD); | 206 | if (open_db (TAGR_DB_RD)) |
207 | exit (EX_UNAVAILABLE); | ||
206 | key = gdbm_firstkey (dbf); | 208 | key = gdbm_firstkey (dbf); |
@@ -280,12 +282,14 @@ rebuild (int force) | |||
280 | verbose (1, _("rebuild initiated")); | 282 | verbose (1, _("rebuild initiated")); |
281 | open_db (TAGR_DB_WR); | 283 | if (open_db (TAGR_DB_RD) == 0) |
282 | key = gdbm_firstkey (dbf); | ||
283 | while (key.dptr) | ||
284 | { | 284 | { |
285 | datum nextkey = gdbm_nextkey ( dbf, key ); | 285 | key = gdbm_firstkey (dbf); |
286 | update_monitor (key, now, force); | 286 | while (key.dptr) |
287 | free (key.dptr); | 287 | { |
288 | key = nextkey; | 288 | datum nextkey = gdbm_nextkey ( dbf, key ); |
289 | update_monitor (key, now, force); | ||
290 | free (key.dptr); | ||
291 | key = nextkey; | ||
292 | } | ||
293 | close_db (); | ||
289 | } | 294 | } |
290 | close_db (); | ||
291 | verbose (1, _("rebuild finished")); | 295 | verbose (1, _("rebuild finished")); |
@@ -428,3 +428,4 @@ import (const char *dirname) | |||
428 | { | 428 | { |
429 | open_db (TAGR_DB_WR); | 429 | if (open_db (TAGR_DB_WR)) |
430 | exit (EX_UNAVAILABLE); | ||
430 | if (import_log (dirname) == 0) | 431 | if (import_log (dirname) == 0) |
@@ -447,3 +448,4 @@ import (const char *dirname) | |||
447 | case 0: | 448 | case 0: |
448 | open_db (TAGR_DB_WR); | 449 | if (open_db (TAGR_DB_WR)) |
450 | exit (EX_UNAVAILABLE); | ||
449 | for (i = 0; i < gl.gl_pathc; i++) | 451 | for (i = 0; i < gl.gl_pathc; i++) |
@@ -218,3 +218,3 @@ struct traffic_record | |||
218 | #define TAGR_DB_WR 1 | 218 | #define TAGR_DB_WR 1 |
219 | void open_db (int); | 219 | int open_db (int); |
220 | void close_db (); | 220 | void close_db (); |