static int parse_string(char *line, char **result);
static int parse_int(char *line, int *result);
-static int parse_uint32(char *, uint32_t *result);
static int parse_double(char *line, double *result);
static int parse_null(char *line);
/* Configuration variables */
static int restarted = 0;
-static int generate_command_key = 0;
static char *rtc_device;
static int acquisition_port = -1;
static int ntp_port = 123;
static char *keys_file = NULL;
static char *drift_file = NULL;
static char *rtc_file = NULL;
-static uint32_t command_key_id;
static double max_update_skew = 1000.0;
static double correction_time_ratio = 3.0;
static double max_clock_error = 1.0; /* in ppm */
parse_int(p, &cmd_port);
} else if (!strcasecmp(command, "combinelimit")) {
parse_double(p, &combine_limit);
- } else if (!strcasecmp(command, "commandkey")) {
- parse_uint32(p, &command_key_id);
} else if (!strcasecmp(command, "corrtimeratio")) {
parse_double(p, &correction_time_ratio);
} else if (!strcasecmp(command, "deny")) {
do_dump_on_exit = parse_null(p);
} else if (!strcasecmp(command, "fallbackdrift")) {
parse_fallbackdrift(p);
- } else if (!strcasecmp(command, "generatecommandkey")) {
- generate_command_key = parse_null(p);
} else if (!strcasecmp(command, "hwclockfile")) {
parse_string(p, &hwclock_file);
} else if (!strcasecmp(command, "include")) {
parse_leapsecmode(p);
} else if (!strcasecmp(command, "leapsectz")) {
parse_string(p, &leapsec_tz);
- } else if (!strcasecmp(command, "linux_freq_scale")) {
- LOG(LOGS_WARN, LOGF_Configure, "%s directive is no longer supported", command);
- } else if (!strcasecmp(command, "linux_hz")) {
- LOG(LOGS_WARN, LOGF_Configure, "%s directive is no longer supported", command);
} else if (!strcasecmp(command, "local")) {
parse_local(p);
} else if (!strcasecmp(command, "lock_all")) {
parse_tempcomp(p);
} else if (!strcasecmp(command, "user")) {
parse_string(p, &user);
+ } else if (!strcasecmp(command, "commandkey") ||
+ !strcasecmp(command, "generatecommandkey") ||
+ !strcasecmp(command, "linux_freq_scale") ||
+ !strcasecmp(command, "linux_hz")) {
+ LOG(LOGS_WARN, LOGF_Configure, "%s directive is no longer supported", command);
} else {
other_parse_error("Invalid command");
}
/* ================================================== */
-static int
-parse_uint32(char *line, uint32_t *result)
-{
- check_number_of_args(line, 1);
- if (sscanf(line, "%"SCNu32, result) != 1) {
- command_parse_error();
- return 0;
- }
- return 1;
-}
-
-/* ================================================== */
-
static int
parse_double(char *line, double *result)
{
/* ================================================== */
-uint32_t
-CNF_GetCommandKey(void)
-{
- return command_key_id;
-}
-
-/* ================================================== */
-
-int
-CNF_GetGenerateCommandKey(void)
-{
- return generate_command_key;
-}
-
-/* ================================================== */
-
int
CNF_GetDumpOnExit(void)
{
static ARR_Instance keys;
-static int command_key_valid;
-static uint32_t command_key_id;
static int cache_valid;
static uint32_t cache_key_id;
static int cache_key_pos;
/* ================================================== */
-static int
-generate_key(uint32_t key_id)
-{
-#ifdef FEAT_SECHASH
- unsigned char key[20];
- const char *hashname = "SHA1";
-#else
- unsigned char key[16];
- const char *hashname = "MD5";
-#endif
- const char *key_file, *rand_dev = "/dev/urandom";
- FILE *f;
- struct stat st;
- int i;
-
- key_file = CNF_GetKeysFile();
-
- if (!key_file)
- return 0;
-
- f = fopen(rand_dev, "r");
- if (!f || fread(key, sizeof (key), 1, f) != 1) {
- if (f)
- fclose(f);
- LOG_FATAL(LOGF_Keys, "Could not read %s", rand_dev);
- return 0;
- }
- fclose(f);
-
- f = fopen(key_file, "a");
- if (!f) {
- LOG_FATAL(LOGF_Keys, "Could not open keyfile %s for writing", key_file);
- return 0;
- }
-
- /* Make sure the keyfile is not world-readable */
- if (stat(key_file, &st) || chmod(key_file, st.st_mode & 0770)) {
- fclose(f);
- LOG_FATAL(LOGF_Keys, "Could not change permissions of keyfile %s", key_file);
- return 0;
- }
-
- fprintf(f, "\n%"PRIu32" %s HEX:", key_id, hashname);
- for (i = 0; i < sizeof (key); i++)
- fprintf(f, "%02hhX", key[i]);
- fprintf(f, "\n");
- fclose(f);
-
- /* Erase the key from stack */
- memset(key, 0, sizeof (key));
-
- LOG(LOGS_INFO, LOGF_Keys, "Generated key %"PRIu32, key_id);
-
- return 1;
-}
-
-/* ================================================== */
-
static void
free_keys(void)
{
Free(((Key *)ARR_GetElement(keys, i))->val);
ARR_SetSize(keys, 0);
- command_key_valid = 0;
cache_valid = 0;
}
KEY_Initialise(void)
{
keys = ARR_CreateInstance(sizeof (Key));
- command_key_valid = 0;
cache_valid = 0;
KEY_Reload();
-
- if (CNF_GetGenerateCommandKey() && !KEY_KeyKnown(KEY_GetCommandKey())) {
- if (generate_key(KEY_GetCommandKey()))
- KEY_Reload();
- }
}
/* ================================================== */
/* ================================================== */
-uint32_t
-KEY_GetCommandKey(void)
-{
- if (!command_key_valid) {
- command_key_id = CNF_GetCommandKey();
- }
-
- return command_key_id;
-}
-
-/* ================================================== */
-
int
KEY_KeyKnown(uint32_t key_id)
{