aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2009-04-29 18:11:56 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2009-04-29 18:11:56 +0300
commit5a1f674eecba607ffa328484ca34c598690ff8d2 (patch)
tree5dcda78e8352461d2ee7fdc29c64a265024cb219
parent20d7f1d7e051c6b021a3f5d088985a74c3370b29 (diff)
downloadtagr-5a1f674eecba607ffa328484ca34c598690ff8d2.tar.gz
tagr-5a1f674eecba607ffa328484ca34c598690ff8d2.tar.bz2
Fix locking issues. Improve stream interface.
* gnulib.modules: Add c-type, c-strcase, crypto/md5, xgetdomainname, xgethostname. * src/Makefile.am (tagr_SOURCES): Add apop.c, udb.c, xhostname.c * src/graph.c (draw_graph): Rename `now' to `start'. * src/main.c (hostname, rebuild_last_option): New globals. (main): Init hostname. * src/output.c (update_output): Change semantics of the last parameter. * src/readconfig.c (cb_facility): Use c_strcasecmp. (tagr_kw): New keywords: hostname, udb-file, lock-count, lock-timeout, idle-timeout. * src/report.c: Fix locking issues. (update_monitor): Change semantics of the last parameter. (rebuild): Likewise. * src/server.c: Rewrite stream interface. * src/tagr.h (TAGR_ARG_UNUSED, TAGR_PRINTFLIKE): New macros. (lock_retry_count_option, lock_retry_timeout_option) (stream_idle_timeout, hostname): New declarations. (TAGR_UPD_FORCE, TAGR_UPD_LASTTIME): New defines. (trim_crlf, tagr_local_hostnamem tagr_auth_init, tagr_auth) (tagr_udb_name) (udb_get_passwordudb_free_password): New declarations. * TODO: Update
-rw-r--r--TODO9
-rw-r--r--gnulib.modules5
-rw-r--r--src/Makefile.am5
-rw-r--r--src/apop.c84
-rw-r--r--src/graph.c17
-rw-r--r--src/main.c17
-rw-r--r--src/output.c9
-rw-r--r--src/readconfig.c19
-rw-r--r--src/report.c27
-rw-r--r--src/server.c181
-rw-r--r--src/tagr.h41
-rw-r--r--src/udb.c90
-rw-r--r--src/xhostname.c56
13 files changed, 484 insertions, 76 deletions
diff --git a/TODO b/TODO
index b2edd7c..b17d5e1 100644
--- a/TODO
+++ b/TODO
@@ -1,11 +1,16 @@
1Tagr TODO list. 2009-04-28 1Tagr TODO list. 2009-04-29
2Copyright (C) 2009 Sergey Poznyakoff 2Copyright (C) 2009 Sergey Poznyakoff
3 3
4* Stream-based protocol 4* Stream-based protocol
5 5
6S: +OK tagr ready 6Currently implemented are:
7
8S: +OK <msgid>
9C: AUTH name digest
10S: +OK
7C: SAMPLE id 1240903636 12345 3456 11C: SAMPLE id 1240903636 12345 3456
8S: +OK accepted 12S: +OK accepted
13...
9C: QUIT 14C: QUIT
10S: +OK bye 15S: +OK bye
11 16
diff --git a/gnulib.modules b/gnulib.modules
index d4887b3..0a23f34 100644
--- a/gnulib.modules
+++ b/gnulib.modules
@@ -2,6 +2,9 @@
2# A module name per line. Empty lines and comments are ignored. 2# A module name per line. Empty lines and comments are ignored.
3 3
4argp 4argp
5c-ctype
6c-strcase
7crypto/md5
5fprintftime 8fprintftime
6getline 9getline
7gitlog-to-changelog 10gitlog-to-changelog
@@ -17,3 +20,5 @@ realloc
17version-etc 20version-etc
18xalloc 21xalloc
19xalloc-die 22xalloc-die
23xgetdomainname
24xgethostname \ No newline at end of file
diff --git a/src/Makefile.am b/src/Makefile.am
index 0db1eb6..996c541 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,6 +17,7 @@
17sbin_PROGRAMS=tagr 17sbin_PROGRAMS=tagr
18 18
19tagr_SOURCES=\ 19tagr_SOURCES=\
20 apop.c\
20 graph.c\ 21 graph.c\
21 grid.c\ 22 grid.c\
22 html.gram.y\ 23 html.gram.y\
@@ -30,7 +31,9 @@ tagr_SOURCES=\
30 report.h\ 31 report.h\
31 server.c\ 32 server.c\
32 stat.c\ 33 stat.c\
33 tagr.h 34 tagr.h\
35 udb.c\
36 xhostname.c
34 37
35noinst_HEADERS=html.gram.h 38noinst_HEADERS=html.gram.h
36 39
diff --git a/src/apop.c b/src/apop.c
new file mode 100644
index 0000000..ce423a5
--- /dev/null
+++ b/src/apop.c
@@ -0,0 +1,84 @@
1/* This file is part of tagr.
2 Copyright (C) 2009 Sergey Poznyakoff
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3, or (at your option)
7 any later version.
8
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
13
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <http://www.gnu.org/licenses/>. */
16
17#ifdef HAVE_CONFIG_H
18# include <config.h>
19#endif
20
21#include <unistd.h>
22#include <fcntl.h>
23#include <stdlib.h>
24#include <stdio.h>
25#include <string.h>
26#include <tagr.h>
27
28#include <md5.h>
29
30static char *msg_id;
31
32const char *
33tagr_auth_init ()
34{
35 asprintf (&msg_id, "<%lu.%lu@%s>",
36 (unsigned long) getpid (),
37 (unsigned long) time (NULL),
38 hostname);
39 return msg_id;
40}
41
42static int
43verify_apop (const char *password, const char *user_digest)
44{
45 int i;
46 struct md5_ctx md5context;
47 unsigned char md5digest[16];
48 char buf[sizeof (md5digest) * 2 + 1];
49 char *p;
50
51 md5_init_ctx (&md5context);
52 md5_process_bytes (msg_id, strlen (msg_id), &md5context);
53 md5_process_bytes (password, strlen (password), &md5context);
54 md5_finish_ctx (&md5context, md5digest);
55
56 for (i = 0, p = buf; i < 16; i++, p += 2)
57 sprintf (p, "%02x", md5digest[i]);
58 return strcmp (user_digest, buf);
59}
60
61int
62tagr_auth (const char *username, const char *authstr)
63{
64 int rc = 1;
65 char *password;
66
67 rc = udb_get_password (username, &password);
68 if (rc == 1)
69 {
70 logmsg (L_ERR, _("no such user `%s'"), username);
71 }
72 else if (rc == 0)
73 {
74 rc = verify_apop (password, authstr);
75 if (rc)
76 logmsg (L_ERR, _("authentication failed for `%s'"),
77 username);
78 else
79 verbose (1, _("%s authenticated"), username);
80 udb_free_password (password);
81 }
82 return rc;
83}
84
diff --git a/src/graph.c b/src/graph.c
index 1197a7d..02e0586 100644
--- a/src/graph.c
+++ b/src/graph.c
@@ -73,7 +73,7 @@ draw_vtext (gdImagePtr graph, int color, const char *text)
73int 73int
74draw_graph (FILE *fp, 74draw_graph (FILE *fp,
75 struct monitor *mon, 75 struct monitor *mon,
76 queue_t *dataq, const struct avg_acc *avg, time_t now, 76 queue_t *dataq, const struct avg_acc *avg, time_t start,
77 int xstep, unsigned long xmax, 77 int xstep, unsigned long xmax,
78 int growright, 78 int growright,
79 struct grid_class *xgrid, struct grid_class *ygrid) 79 struct grid_class *xgrid, struct grid_class *ygrid)
@@ -90,7 +90,6 @@ draw_graph (FILE *fp,
90 int full_ysize = graph_ysize + graph_v_margin[0] + graph_v_margin[1]; 90 int full_ysize = graph_ysize + graph_v_margin[0] + graph_v_margin[1];
91 grid_t grid; 91 grid_t grid;
92 unsigned long ymax = mon->max_rate; 92 unsigned long ymax = mon->max_rate;
93 time_t start;
94 93
95 yscale = (double) graph_ysize / ymax; 94 yscale = (double) graph_ysize / ymax;
96 xscale = (double) graph_xsize / xmax; 95 xscale = (double) graph_xsize / xmax;
@@ -143,13 +142,13 @@ draw_graph (FILE *fp,
143 n = queue_count (dataq); 142 n = queue_count (dataq);
144 143
145 /* Incoming traffic */ 144 /* Incoming traffic */
146 for (i = n - 1, start = 0; i > 0; i--) 145 for (i = n - 1; i > 0; i--)
147 { 146 {
148 struct traffic_history th, tnext; 147 struct traffic_history th, tnext;
149 148
150 scale_sample (mon, queue_get_ptr (dataq, i), &th); 149 scale_sample (mon, queue_get_ptr (dataq, i), &th);
151 if (start == 0) 150 if (th.time > start)
152 start = th.time; 151 continue;
153 scale_sample (mon, queue_get_ptr (dataq, i - 1), &tnext); 152 scale_sample (mon, queue_get_ptr (dataq, i - 1), &tnext);
154 if (start - tnext.time > xmax) 153 if (start - tnext.time > xmax)
155 break; 154 break;
@@ -172,13 +171,13 @@ draw_graph (FILE *fp,
172 171
173 /* Outgoing traffic */ 172 /* Outgoing traffic */
174 gdImageSetBrush (graph, brush_out); 173 gdImageSetBrush (graph, brush_out);
175 for (i = n - 1, start = 0; i > 0; i--) 174 for (i = n - 1; i > 0; i--)
176 { 175 {
177 struct traffic_history th, tnext; 176 struct traffic_history th, tnext;
178 177
179 scale_sample (mon, queue_get_ptr (dataq, i), &th); 178 scale_sample (mon, queue_get_ptr (dataq, i), &th);
180 if (start == 0) 179 if (th.time > start)
181 start = th.time; 180 continue;
182 scale_sample (mon, queue_get_ptr (dataq, i - 1), &tnext); 181 scale_sample (mon, queue_get_ptr (dataq, i - 1), &tnext);
183 if (start - tnext.time > xmax) 182 if (start - tnext.time > xmax)
184 break; 183 break;
@@ -245,7 +244,7 @@ draw_graph (FILE *fp,
245 grid_destroy (grid); 244 grid_destroy (grid);
246 } 245 }
247 246
248 grid = grid_create (xgrid, dataq, 0, xmax, &now); 247 grid = grid_create (xgrid, dataq, 0, xmax, &start);
249 if (grid) 248 if (grid)
250 { 249 {
251 unsigned long i; 250 unsigned long i;