-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The config file is a list of key/value pairs, separated by whitespace. Signed-off-by: Elly Fong-Jones <ellyjones@chromium.org>
- Loading branch information
elly
committed
Jan 16, 2013
1 parent
99b51df
commit 677a136
Showing
12 changed files
with
502 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# tlsdated example config file | ||
# for boolean options, "yes" enables them, any other value disables them. | ||
# see tlsdated.conf(5) for details about the options | ||
|
||
base-path /var/cache/tlsdated | ||
dry-run no | ||
jitter 0 | ||
max-tries 10 | ||
min-steady-state-interval 86400 | ||
should-load-disk yes | ||
should-netlink yes | ||
should-save-disk yes | ||
should-sync-hwclock yes | ||
steady-state-interval 86400 | ||
subprocess-tries 10 | ||
subprocess-wait-between-tries 3 | ||
verbose yes | ||
wait-between-tries 10 | ||
|
||
# Host configuration. | ||
host www.ptb.de | ||
port 443 | ||
proxy none |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
.\" Process this file with | ||
.\" groff -man -Tascii foo.1 | ||
.\" | ||
.TH TLSDATED 5 "JANUARY 2013" "File Formats and Conversions" | ||
.SH NAME | ||
tlsdated.conf \- tlsdated config file | ||
.SH SYNTAX | ||
\fBtlsdated.conf\fR is the configuration file for the \fBtlsdated(1)\fR daemon. | ||
The config file is formatted as a list of key-value pairs, one per line, | ||
separated by whitespace. Whitespace inside values is preserved, so | ||
.RS | ||
foo bar baz quxx | ||
.RE | ||
represents the key \fBfoo\fR mapping to the value \fBbar baz quxx\fR. Empty | ||
lines and lines beginning with \fB#\fR are ignored; leading whitespace on lines | ||
is stripped. For boolean options, the value \fByes\fR or no value at all | ||
indicates that the option should be switched on, and all other values indicate | ||
that the option should be switched off. \fINote that trailing whitespace is | ||
preserved in values.\fR | ||
.SH OPTIONS | ||
.IP argv (string) | ||
Add an argument to the subprocess's argument vector. Use this option multiple | ||
times for multiple arguments. | ||
.IP base-path (string) | ||
Sets the path to tlsdated's cache directory. | ||
.IP dry-run (bool) | ||
If enabled, don't actually adjust the system time. | ||
.IP jitter (int) | ||
Add or subtract up to this many seconds from the steady-state interval when | ||
checking. This helps prevent correlation between sequential checks and smooth | ||
load on time hosts. | ||
.IP max-tries (int) | ||
How many times to try running the tlsdate subprocess. | ||
.IP min-steady-state-interval (int) | ||
Do not check more than once this many seconds when in steady state. | ||
.IP should-load-disk (bool) | ||
If enabled, try loading the current timestamp out of the cache directory. | ||
.IP should-netlink (bool) | ||
If enabled, use a netlink socket to get network events; otherwise, read network | ||
events from stdin. | ||
.IP should-save-disk (bool) | ||
If enabled, save the current timestamp to the cache directory every so often and | ||
at exit. | ||
.IP should-sync-hwclock (bool) | ||
If enabled, set the hwclock to the fetched time. | ||
.IP steady-state-interval (int) | ||
Check at least once this many seconds when in steady state. | ||
.IP subprocess-tries (int) | ||
How many times to try waiting for the subprocess. | ||
.IP subprocess-wait-between-tries (int) | ||
How many seconds to wait between each attempt to wait for the subprocess. | ||
.IP verbose (bool) | ||
If enabled, tlsdated will be annoyingly verbose in syslog and on stdout. | ||
.IP wait-between-tries (int) | ||
How long to wait between runs of the subprocess. | ||
.SH BUGS | ||
It's likely! Let us know by contacting jacob@appelbaum.net | ||
|
||
Note that | ||
.B tlsdated(1) | ||
is still in Alpha, and may not work as expected. | ||
.SH AUTHOR | ||
Jacob Appelbaum <jacob at appelbaum dot net> | ||
.SH "SEE ALSO" | ||
.B tlsdated(1), |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
/* | ||
* conf-unittest.c - config parser unit tests | ||
* Copyright (c) 2012 The Chromium OS Authors. All rights reserved. | ||
* Use of this source code is governed by a BSD-style license that can be | ||
* found in the LICENSE file. | ||
*/ | ||
|
||
#include <errno.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "conf.h" | ||
#include "test_harness.h" | ||
|
||
FILE *fopenstr(const char *str) { | ||
/* strlen(str) instead of strlen(str) + 1 because files shouldn't appear | ||
* null-terminated. Cast away constness because we're in read mode, but the | ||
* fmemopen prototype has no way to express that. */ | ||
return fmemopen((char *)str, strlen(str), "r"); | ||
} | ||
|
||
TEST(parse_empty) { | ||
/* can't do a truly empty file - fmemopen() combusts */ | ||
FILE *f = fopenstr("\n"); | ||
ASSERT_NE(NULL, f); | ||
struct conf_entry *e = conf_parse(f); | ||
EXPECT_NULL(e); | ||
conf_free(e); | ||
} | ||
|
||
TEST(parse_basic) { | ||
FILE *f = fopenstr("foo bar\nbaz quxx\n"); | ||
ASSERT_NE(NULL, f); | ||
struct conf_entry *e = conf_parse(f); | ||
ASSERT_NE(NULL, e); | ||
EXPECT_STREQ(e->key, "foo"); | ||
EXPECT_STREQ(e->value, "bar"); | ||
ASSERT_NE(NULL, e->next); | ||
EXPECT_STREQ(e->next->key, "baz"); | ||
EXPECT_STREQ(e->next->value, "quxx"); | ||
ASSERT_NULL(e->next->next); | ||
conf_free(e); | ||
} | ||
|
||
TEST(parse_novalue) { | ||
FILE *f = fopenstr("abcdef\n"); | ||
ASSERT_NE(NULL, f); | ||
struct conf_entry *e = conf_parse(f); | ||
ASSERT_NE(NULL, e); | ||
EXPECT_STREQ(e->key, "abcdef"); | ||
EXPECT_NULL(e->value); | ||
EXPECT_NULL(e->next); | ||
conf_free(e); | ||
} | ||
|
||
TEST(parse_whitespace) { | ||
FILE *f = fopenstr(" fribble grotz \n"); | ||
ASSERT_NE(NULL, f); | ||
struct conf_entry *e = conf_parse(f); | ||
ASSERT_NE(NULL, e); | ||
EXPECT_STREQ(e->key, "fribble"); | ||
EXPECT_STREQ(e->value, "grotz "); | ||
EXPECT_NULL(e->next); | ||
conf_free(e); | ||
} | ||
|
||
TEST(parse_comment) { | ||
FILE *f = fopenstr("#foo bar\nbaz quxx\n"); | ||
ASSERT_NE(NULL, f); | ||
struct conf_entry *e = conf_parse(f); | ||
ASSERT_NE(NULL, e); | ||
EXPECT_STREQ(e->key, "baz"); | ||
EXPECT_STREQ(e->value, "quxx"); | ||
EXPECT_NULL(e->next); | ||
conf_free(e); | ||
} | ||
|
||
TEST_HARNESS_MAIN |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* conf.c - config file parser */ | ||
|
||
#define _GNU_SOURCE /* strchrnul */ | ||
#include <ctype.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
#include "conf.h" | ||
|
||
void strip_newlines(char *line) | ||
{ | ||
*strchrnul(line, '\n') = '\0'; | ||
*strchrnul(line, '\r') = '\0'; | ||
} | ||
|
||
char *eat_whitespace(char *line) | ||
{ | ||
while (isspace(*line)) | ||
line++; | ||
return line; | ||
} | ||
|
||
int is_ignored_line(char *line) | ||
{ | ||
return !*line || *line == '#'; | ||
} | ||
|
||
struct conf_entry *conf_parse(FILE *f) | ||
{ | ||
struct conf_entry *head = NULL; | ||
struct conf_entry *tail = NULL; | ||
char buf[CONF_MAX_LINE]; | ||
|
||
while (fgets(buf, sizeof(buf), f)) { | ||
struct conf_entry *e; | ||
char *start = buf; | ||
char *key; | ||
char *val; | ||
|
||
strip_newlines(start); | ||
start = eat_whitespace(start); | ||
if (is_ignored_line(start)) | ||
continue; | ||
|
||
key = strtok(start, " \t"); | ||
val = strtok(NULL, ""); | ||
if (val) | ||
val = eat_whitespace(val); | ||
e = malloc(sizeof *e); | ||
if (!e) | ||
goto fail; | ||
e->next = NULL; | ||
e->key = strdup(key); | ||
e->value = val ? strdup(val) : NULL; | ||
if (!e->key || (val && !e->value)) { | ||
free(e->key); | ||
free(e->value); | ||
goto fail; | ||
} | ||
if (!head) { | ||
head = e; | ||
tail = e; | ||
} else { | ||
tail->next = e; | ||
tail = e; | ||
} | ||
} | ||
|
||
return head; | ||
fail: | ||
conf_free(head); | ||
return NULL; | ||
} | ||
|
||
void conf_free(struct conf_entry *e) | ||
{ | ||
struct conf_entry *n; | ||
while (e) { | ||
n = e->next; | ||
free(e->key); | ||
free(e->value); | ||
free(e); | ||
e = n; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* conf.h - config file parser */ | ||
|
||
#ifndef CONF_H | ||
#define CONF_H | ||
|
||
#include <stdio.h> | ||
|
||
#define CONF_MAX_LINE 16384 | ||
|
||
struct conf_entry { | ||
struct conf_entry *next; | ||
char *key; | ||
char *value; | ||
}; | ||
|
||
struct conf_entry *conf_parse(FILE *f); | ||
void conf_free(struct conf_entry *e); | ||
|
||
#endif /* !CONF_H */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.