File: subsystem.c

package info (click to toggle)
honeyd 1.5c-7
  • links: PTS
  • area: main
  • in suites: squeeze
  • size: 7,140 kB
  • ctags: 4,512
  • sloc: ansic: 30,010; sh: 12,942; perl: 4,536; python: 4,465; yacc: 1,088; makefile: 330; lex: 173
file content (709 lines) | stat: -rw-r--r-- 17,415 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
/*
 * Copyright (c) 2003, 2004 Niels Provos <provos@citi.umich.edu>
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include <sys/param.h>
#include <sys/types.h>

#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <sys/tree.h>
#include <sys/queue.h>

#include <unistd.h>
#include <err.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <syslog.h>
#include <time.h>
#include <dumbnet.h>
#include <assert.h>

#undef timeout_pending
#undef timeout_initialized

#include <event.h>

#include "honeyd.h"
#include "template.h"
#include "subsystem.h"
#include "util.h"
#include "fdpass.h"

ssize_t atomicio(ssize_t (*)(), int, void *, size_t);


int
templ_container_compare(struct template_container *a,
    struct template_container *b)
{
	return (strcmp(a->tmpl->name, b->tmpl->name));
}

/* Store referencing templates in tree */
SPLAY_GENERATE(subtmpltree, template_container, node, templ_container_compare);

void subsystem_read(int, short, void *);
void subsystem_write(int, short, void *);

struct callback subsystem_cb = {
	subsystem_read, subsystem_write, NULL, NULL
};

/* Determine if the socket information is valid */

#define SOCKET_REMOTE		0
#define SOCKET_LOCAL		1
#define SOCKET_MAYBELOCAL	2

int
subsystem_socket(struct subsystem_command *cmd, int local,
    char *ip, size_t iplen, u_short *port, int *proto)
{
	struct sockaddr_in *si;
	struct addr src;
	socklen_t len;

	si = (struct sockaddr_in *)(local ? &cmd->sockaddr : &cmd->rsockaddr);
	len = local ? cmd->len : cmd->rlen;

	/* Only IPv4 TCP or UDP is allowed.  No raw sockets or such */
	if (si->sin_family != AF_INET || cmd->domain != AF_INET ||
	    !(cmd->type == SOCK_DGRAM || cmd->type == SOCK_STREAM) ||
	    len != sizeof(struct sockaddr_in)) {
		if (local == SOCKET_LOCAL)
			return (-1);
		memset(&cmd->sockaddr, 0, sizeof(cmd->sockaddr));
	}

	addr_pack(&src, ADDR_TYPE_IP, IP_ADDR_BITS, &si->sin_addr.s_addr,
	    IP_ADDR_LEN);
	addr_ntop(&src, ip, iplen);

	*port = ntohs(si->sin_port);
	*proto = cmd->type == SOCK_DGRAM ? IP_PROTO_UDP : IP_PROTO_TCP;

	return (0);
}

struct template *
subsystem_template_find(struct subsystem *sub, char *name)
{
	struct template tmp;
	struct template_container cont, *find;

	tmp.name = name;
	cont.tmpl = &tmp;

	find = SPLAY_FIND(subtmpltree, &sub->root, &cont);
	
	return (find != NULL ? find->tmpl : NULL);
}

void
subsystem_insert_template(struct subsystem *sub, struct template *tmpl)
{
	struct template_container *cont;
	struct addr addr;
	int isipaddr = addr_aton(tmpl->name, &addr) != -1;

	if ((cont = calloc(1, sizeof(struct template_container))) == NULL)
		err(1, "%s: calloc");
	cont->tmpl = template_ref(tmpl);

	TAILQ_INSERT_TAIL(&sub->templates, cont, next);
	if (isipaddr)
		SPLAY_INSERT(subtmpltree, &sub->root, cont);
}

void
subsystem_restart(int fd, short what, void *arg)
{
	struct subsystem *sub = arg;
	struct template_container *cont = TAILQ_FIRST(&sub->templates);
	struct template *tmpl = cont->tmpl;
	template_subsystem_free_ports(sub);
	cmd_free(&sub->cmd);
	syslog(LOG_INFO, "Restarting subsystem \"%s\"", sub->cmdstring);
	template_subsystem_start(tmpl, sub);
}

void
subsystem_cleanup(struct subsystem *sub)
{
	syslog(LOG_INFO, "Subsystem \"%s\" died", sub->cmdstring);

	if (sub->flags & SUBSYSTEM_RESTART) {
		struct timeval tmp;
		gettimeofday(&tmp, NULL);
		timersub(&tmp, &sub->tv_restart, &tmp);

		/*
		 * Restart the subsystem immediately if we did not restart
		 * it recently.  Otherwise, delay the restart.
		 */
		if (tmp.tv_sec >= SUBSYSTEM_RESTART_INTERVAL) {
			subsystem_restart(-1, EV_TIMEOUT, sub);
		} else {
			struct timeval tv;
			
			timerclear(&tv);
			tv.tv_sec = 2 * SUBSYSTEM_RESTART_INTERVAL;
			event_once(-1, EV_TIMEOUT,
			    subsystem_restart, sub, &tv);
		}
		return;
	}

	/* XXX - do proper cleanup here */
	template_subsystem_free(sub);
}

void
subsystem_readyport(struct port *port, struct subsystem *sub,
    struct template *tmpl)
{
	assert(port->sub == NULL);
	assert(port->subtmpl == NULL);
	port->sub = sub;
	port->subtmpl = tmpl;
	port->sub_fd = -1;

	TAILQ_INSERT_TAIL(&sub->ports, port, next);
}

/*
 * Tries to find an unallocated port in all of the templates that
 * are being shared or just in the single template if no sharing
 * is going on.
 */

int
subsystem_findport(struct subsystem *sub, char *name, int proto)
{
	struct template_container *cont;
	struct template *tmpl;
	struct port *sub_port = NULL;
	u_short port;
	int done = 0;

	while (!done) {
		struct action action;
		memset(&action, 0, sizeof(action));
		action.status = PORT_RESERVED;

		/* 
		 * Try to find the right template or default to the root,
		 * if we need to deal with multiple templates at the same
		 * time.
		 */
		cont = SPLAY_ROOT(&sub->root);
		tmpl = cont->tmpl;
		if (!strcmp(name, "0.0.0.0")) {
			tmpl = subsystem_template_find(sub, name);
			if (tmpl == NULL) {
				cont = SPLAY_ROOT(&sub->root);
				tmpl = cont->tmpl;
			}
		}

		sub_port = port_random(tmpl, proto, &action, 1024, 49151);
		if (sub_port == NULL)
			return (0);

		port = sub_port->number;
		port_free(tmpl, sub_port);

		/* Fast path for single template */
		if (!strcmp(name, "0.0.0.0")) {
			break;
		}

		/* Assume that we succeed */
		done = 1;

		/* Now test this port number for all templates */
		SPLAY_FOREACH(cont, subtmpltree, &sub->root) {
			tmpl = cont->tmpl;
			sub_port = port_insert(tmpl, proto, port, &action);
			if (sub_port == NULL) {
				/* This port is in use already */
				done = 0;
				break;
			}

			/* Free the port and continue with the next template */
			port_free(tmpl, sub_port);
		}
	}

	syslog(LOG_DEBUG, "Subsytem \"%s\" binds %s to port %d",
	    sub->cmdstring, name, port);

	return (port);
}

int
subsystem_bind(int fd, struct template *tmpl, struct subsystem *sub,
    int proto, u_short port)
{
	struct port *sub_port;
	struct action action;

	/* Setup port type */
	memset(&action, 0, sizeof(action));
	action.status = PORT_RESERVED;

	sub_port = port_insert(tmpl, proto, port, &action);
	if (sub_port == NULL)
		return (-1);

	/* Set up necessary port information */
	subsystem_readyport(sub_port, sub, tmpl);

	syslog(LOG_DEBUG, "Subsytem \"%s\" binds %s:%d",
	    sub->cmdstring, tmpl->name, port);

	return (0);
}

int
subsystem_listen(struct port *sub_port, char *ip, int nfd)
{
	syslog(LOG_DEBUG, "Listen: %s:%d -> fd %d", 
	    ip, sub_port->number, nfd);

	/* We use this fd to notify the other side */
	TRACE(nfd, sub_port->sub_fd = fdshare_dup(nfd));
	if (sub_port->sub_fd == -1)
		return (-1);
	sub_port->sub_islisten = 1;
			
	/* Enable this port */
	sub_port->action.status = PORT_SUBSYSTEM;

	return (0);
}

int
subsystem_cmd_listen(int fd,
    struct subsystem *sub, struct subsystem_command *cmd)
{
	struct template_container *cont;
	struct template *tmpl;
	struct port *sub_port = NULL;
	char asrc[24];
	u_short port;
	int proto;
	int nfd;
	int res = -1;

	/* Check address family */
	if (subsystem_socket(cmd, SOCKET_LOCAL, asrc, sizeof(asrc),
		&port, &proto) == -1) {
		syslog(LOG_WARNING, "%s: listen bad socket", __func__);
		return (-1);
	}

	if (strcmp(asrc, "0.0.0.0") != 0) {
		tmpl = subsystem_template_find(sub, asrc);
	} else {
		cont = SPLAY_ROOT(&sub->root);
		tmpl = cont->tmpl;
	}
	if (tmpl != NULL)
		sub_port = port_find(tmpl, proto, port);
	if (sub_port == NULL) {
		syslog(LOG_WARNING, "%s: proto %d port %d not bound",
		    __func__, proto, port);
		return (-1);
	}

	res = 0;
	TRACE(fd, atomicio(write, fd, &res, 1));
	res = -1;

	/* Repeat until we get a result */
	while ((nfd = receive_fd(fd, NULL, NULL)) == -1) {
		if (errno != EAGAIN)
			break;
	}

	if (nfd == -1) {
		syslog(LOG_WARNING, "%s: no file descriptor",__func__);
		return (-1);
	}

	TRACE(nfd, res = fdshare_dup(nfd));
	if (res == -1) {
		syslog(LOG_WARNING, "%s: out of memory", __func__);
		TRACE_RESET(nfd, close(nfd));
		return (-1);
	}

	if (strcmp(asrc, "0.0.0.0") != 0) {
		TRACE(nfd, subsystem_listen(sub_port, asrc, nfd));
	} else {
		/* 
		 * Subsystem sharing means that we need to
		 * listen to all templates
		 */
		int success = 0;
		SPLAY_FOREACH(cont, subtmpltree, &sub->root) {
			tmpl = cont->tmpl;
			sub_port = port_find(tmpl, proto, port);
			if (sub_port == NULL)
				errx(1, "%s: no proto %d port %d",
				    __func__, proto, port);
			if (sub_port->sub == NULL) {
				syslog(LOG_DEBUG,
				    "Subsystem %s fails to listen on %s:%d",
				    sub->cmdstring, tmpl->name, port);
			} else {
				int ok;
				TRACE(nfd, ok = subsystem_listen(sub_port,
					  asrc, nfd));
				if (ok != -1)
					success = 1;
			}
		}
		if (!success)
			res = -1;
	}

	/* Close this file descriptor */
	TRACE(nfd, fdshare_close(nfd));
		
	return (res);
}

void
subsystem_read(int fd, short what, void *arg)
{
	struct subsystem *sub = arg;
	struct subsystem_command cmd;
	struct sockaddr_in *si = (struct sockaddr_in *)&cmd.sockaddr;
	char asrc[24], adst[24];
	u_short port, local_port;
	int proto, n;
	char res = -1;

	TRACE(fd, n = atomicio(read, fd, &cmd, sizeof(cmd)));
	if (n != sizeof(cmd)) {
		subsystem_cleanup(sub);
		return;
	}

	switch (cmd.command) {
	case SUB_BIND: {
		struct template_container *cont;
		struct template *tmpl;
	
		/* Check address family */
		if (subsystem_socket(&cmd, SOCKET_LOCAL, asrc, sizeof(asrc),
			&port, &proto) == -1)
			goto out;

		if (port == 0) {
			/* Try to find a port that is free everywhere */
			port = subsystem_findport(sub, asrc, proto);
			if (port == 0)
				goto out;
		}

		/* See if it tries to bind an address that we know */
		if (si->sin_addr.s_addr == IP_ADDR_ANY) {
			int ret;
			res = -1;
			/* Bind to all associated templates */
			SPLAY_FOREACH(cont, subtmpltree, &sub->root) {
				tmpl = cont->tmpl;
				TRACE(fd, ret = subsystem_bind(fd, tmpl,
					  sub,proto,port));
				/* One success is good enough for us */
				if (ret != -1) {
					res = 0;
				} else {
					syslog(LOG_DEBUG,
					    "Subsystem %s fails to bind to "
					    "port %d on %s",
					    sub->cmdstring, port, tmpl->name);
				}
			}
		} else {
			/* See if we can find a good template */
			tmpl = subsystem_template_find(sub, asrc);
			if (tmpl == NULL) {
				cont = SPLAY_ROOT(&sub->root);
				tmpl = cont->tmpl;
				syslog(LOG_WARNING,
				    "Subsystem %s on %s attempts "
				    "illegal bind %s:%d",
				    sub->cmdstring, tmpl->name, asrc, port);
				goto out;
			}

			TRACE(fd,
			    res = subsystem_bind(fd, tmpl, sub, proto, port));
		}

		/* Confirm success or failure of this phase */
		TRACE(fd, atomicio(write, fd, &res, 1));
			
		/* On success, we also communicate the port back */
		if (res != -1) {
			TRACE(fd, atomicio(write, fd, &port, sizeof(port)));
		}
		goto reschedule;
	}

	case SUB_LISTEN:
		TRACE(fd, res = subsystem_cmd_listen(fd, sub, &cmd));
		break;

	case SUB_CLOSE: {
		struct template_container *cont;
		struct template *tmpl = NULL;
		struct port *sub_port;

		/* Check address family */
		if (subsystem_socket(&cmd, SOCKET_LOCAL, asrc, sizeof(asrc),
			&port, &proto) == -1)
			goto out;

		syslog(LOG_DEBUG, "Close: %s:%d", asrc, port);
		if (strcmp(asrc, "0.0.0.0") != 0) {
			tmpl = subsystem_template_find(sub, asrc);
			if (tmpl == NULL)
				goto out;
			sub_port = port_find(tmpl, proto, port);
			if (sub_port == NULL || sub_port->sub != sub)
				goto out;
			
			port_free(tmpl, sub_port);
		} else {
			SPLAY_FOREACH(cont, subtmpltree, &sub->root) {
				tmpl = cont->tmpl;
				/* XXX - only bound port */
				sub_port = port_find(tmpl, proto, port);
				if (sub_port == NULL || sub_port->sub != sub)
					continue;
				
				port_free(tmpl, sub_port);
			}
		}
		break;
	}

	case SUB_CONNECT: {
		struct template_container *cont;
		struct template *tmpl;
		struct port *sub_port;
		struct action action;
		struct addr src, dst;
		struct ip_hdr ip;

		/* Check remote address family */
		if (subsystem_socket(&cmd, SOCKET_MAYBELOCAL,
			asrc, sizeof(asrc), &local_port, &proto) == -1)
			goto out;
		if (subsystem_socket(&cmd, SOCKET_REMOTE, adst, sizeof(adst),
			&port, &proto) == -1)
			goto out;
		
		/* Find appropriate template */
		if (strcmp(asrc, "0.0.0.0") != 0) {
			tmpl = subsystem_template_find(sub, asrc);
			if (tmpl == NULL)
				errx(1, "%s: source address %s not found",
				    __func__, asrc);
		} else {
			cont = SPLAY_ROOT(&sub->root);
			tmpl = cont->tmpl;
		}

		syslog(LOG_DEBUG, "Connect: %s %s:%d -> %s:%d",
		    proto == IP_PROTO_UDP ? "udp" : "tcp",
		    tmpl->name, local_port, adst, port);

		if (addr_aton(tmpl->name, &src) == -1)
			goto out;
		if (addr_aton(adst, &dst) == -1)
			goto out;

		memset(&action, 0, sizeof(action));
		action.status = PORT_RESERVED;

		if (local_port == 0) {
			sub_port = port_random(tmpl, proto, &action,
			    1024, 49151);
			if (sub_port != NULL)
				subsystem_readyport(sub_port, sub, tmpl);
		} else {
			/*
			 * If the port is bound already, then we need to use
			 * that port number.
			 */
			sub_port = port_find(tmpl, proto, local_port);
		}
		if (sub_port == NULL)
			goto out;
		
		/* Verify that we have the correct binding */
		assert(sub_port->sub == sub);

		syslog(LOG_DEBUG, "Connect: allocated port %d",
		    sub_port->number);

		/* The remote side is the source */
		ip.ip_src = dst.addr_ip;
		ip.ip_dst = src.addr_ip;

		/* Try to setup a TCP connection */
		if (proto == IP_PROTO_TCP) {
			struct tcp_con *con;
			struct tcp_hdr tcp;
			int nfd;

			tcp.th_sport = htons(port);
			tcp.th_dport = htons(sub_port->number);

			if ((con = tcp_new(&ip, &tcp, 1)) == NULL)
				goto out;
			con->tmpl = template_ref(tmpl);

			/* Cross notify */
			con->port = sub_port;
			sub_port->sub_conport = &con->port;

			/* Confirm success of this phase */
			res = 0;
			TRACE(fd, atomicio(write, fd, &res, 1));
			
			/* Now get the control fd */
			while ((nfd = receive_fd(fd, NULL, NULL)) == -1) {
				if (errno != EAGAIN) {
					tcp_free(con);
					goto out;
				}
			}
			TRACE(nfd, sub_port->sub_fd = fdshare_dup(nfd));

			/* Confirm success again */
			res = 0;
			TRACE(nfd, atomicio(write, nfd, &res, 1));
			
			/* Send out the SYN packet */
			con->state = TCP_STATE_SYN_SENT;
			tcp_send(con, TH_SYN, NULL, 0);
			con->snd_una++;

			con->retrans_time = 1;
			generic_timeout(&con->retrans_timeout, con->retrans_time);
			goto reschedule;
		} else if (proto == IP_PROTO_UDP) {
			struct udp_con *con;
			struct udp_hdr udp;
			int nfd;

			/* The remote side is the source */
			udp.uh_sport = htons(port);
			udp.uh_dport = htons(sub_port->number);

			if ((con = udp_new(&ip, &udp, 1)) == NULL)
				goto out;
			con->tmpl = template_ref(tmpl);
			
			/* Cross notify */
			con->port = sub_port;
			sub_port->sub_conport = &con->port;

			/* Confirm success of this phase */
			res = 0;
			TRACE(fd, atomicio(write, fd, &res, 1));

			/* Now get the control fd */
			while ((nfd = receive_fd(fd, NULL, NULL)) == -1) {
				if (errno != EAGAIN) {
					udp_free(con);
					goto out;
				}
			}
			TRACE(nfd, sub_port->sub_fd = fdshare_dup(nfd));

			/* Confirm success again */
			res = 0;
			TRACE(nfd, atomicio(write, nfd, &res, 1));
                       
			/* Connect our system to the subsystem */
			cmd_subsystem_localconnect(&con->conhdr, &con->cmd,
			    sub_port, con);
			goto reschedule;
		}
	}
	default:
		break;
	}

 out:
	TRACE(fd, atomicio(write, fd, &res, 1));
 reschedule:
	/* Reschedule read */
	TRACE(sub->cmd.pread.ev_fd, event_add(&sub->cmd.pread, NULL));
}

void
subsystem_write(int fd, short what, void *arg)
{
	/* Nothing */
}

void
subsystem_print(struct evbuffer *buffer, struct subsystem *sub)
{
	time_t restart_secs = sub->tv_restart.tv_sec;

	evbuffer_add_printf(buffer, "subsystem %s:\n", sub->cmdstring);
	evbuffer_add_printf(buffer, "  pid: %d %s%s\n",
	    sub->cmd.pid,
	    sub->flags & SUBSYSTEM_SHARED ? "shared " : "",
	    sub->flags & SUBSYSTEM_RESTART ? "restart " : "");
	evbuffer_add_printf(buffer, "  running since: %s",
	    ctime(&restart_secs));
	    
}