60 #include <libhsmdns.h>
61 #include <ldns/ldns.h>
63 #include <libxml/tree.h>
64 #include <libxml/parser.h>
65 #include <libxml/xpointer.h>
66 #include <libxml/xpath.h>
67 #include <libxml/xpathInternals.h>
68 #include <libxml/relaxng.h>
69 #include <libxml/xmlreader.h>
70 #include <libxml/xmlsave.h>
72 #define MAX(a, b) ((a) > (b) ? (a) : (b))
76 #define DURATION_TYPE 1
80 #define ROLLOVER_TYPE 5
81 #define INT_TYPE_NO_FREE 6
84 # define MAXPATHLEN 4096
89 #define DEFAULT_LOG_FACILITY LOG_DAEMON
91 #define DEFAULT_LOG_FACILITY LOG_USER
97 char *
config = (
char *) OPENDNSSEC_CONFIG_FILE;
117 static int all_flag = 0;
118 static int auto_accept_flag = 0;
119 static int ds_flag = 0;
120 static int retire_flag = 1;
121 static int notify_flag = 1;
122 static int verbose_flag = 0;
123 static int xml_flag = 1;
124 static int td_flag = 0;
125 static int force_flag = 0;
126 static int hsm_flag = 1;
127 static int check_repository_flag = 0;
129 static int restart_enforcerd(
void);
136 #if defined(HAVE_SYSLOG_R) && defined(HAVE_OPENLOG_R) && defined(HAVE_CLOSELOG_R)
137 struct syslog_data sdata = SYSLOG_DATA_INIT;
140 #undef HAVE_OPENLOG_R
141 #undef HAVE_CLOSELOG_R
149 " --version aka -V\n");
157 "\tImport config into a database (deletes current contents)\n");
164 " start|stop|notify\n"
165 "\tStart, stop or SIGHUP the ods-enforcerd\n");
176 "\tUpdate database from config\n");
184 "\t--zone <zone> aka -z\n"
185 "\t[--policy <policy>] aka -p\n"
186 "\t[--signerconf <signerconf.xml>] aka -s\n"
187 "\t[--input <input>] aka -i\n"
188 "\t[--in-type <input type>] aka -j\n"
189 "\t[--output <output>] aka -o\n"
190 "\t[--out-type <output type>] aka -q\n"
191 "\t[--no-xml] aka -m\n");
199 "\t--zone <zone> | --all aka -z / -a\n"
200 "\t[--no-xml] aka -m\n");
214 "usage: %s [-c <config> | --config <config>] zone \n\n",
225 " repository list\n");
233 "\t--policy [policy_name] | --all aka -p / -a\n");
261 "usage: %s [-c <config> | --config <config>] \n\n",
274 "\t[--verbose] aka -v\n"
275 "\t[--zone <zone>] aka -z\n"
276 "\t[--keystate <state>| --all] aka -e / -a\n"
277 "\t[--keytype <type>] aka -t\n"
286 "\t--zone <zone> | --all aka -z / -a\n"
287 "\t[--keystate <state>] aka -e\n"
288 "\t[--keytype <type>] aka -t\n"
289 "\t[--ds] aka -d\n");
297 "\t--cka_id <CKA_ID> aka -k\n"
298 "\t--repository <repository> aka -r\n"
299 "\t--zone <zone> aka -z\n"
300 "\t--bits <size> aka -b\n"
301 "\t--algorithm <algorithm> aka -g\n"
302 "\t--keystate <state> aka -e\n"
303 "\t--keytype <type> aka -t\n"
304 "\t--time <time> aka -w\n"
305 "\t[--check-repository] aka -C\n"
306 "\t[--retire <retire>] aka -y\n");
314 "\t--zone zone aka -z\n"
315 "\t--keytype <type> | --all aka -t / -a\n"
317 "\t--policy policy aka -p\n"
318 "\t--keytype <type> | --all aka -t / -a\n");
326 "\t--zone <zone> aka -z\n"
328 "\t--policy <policy> aka -p\n");
336 "\t--policy <policy> aka -p\n"
337 "\t--interval <interval> aka -n\n"
338 "\t[--zonetotal <total no. of zones>] aka -Z\n"
339 "\t--auto-accept aka -A\n");
347 "\t--zone <zone> aka -z\n"
348 "\t--keytag <keytag> | --cka_id <CKA_ID> aka -x / -k\n");
357 "\t--zone <zone> aka -z\n"
358 "\t--keytag <keytag> | --cka_id <CKA_ID> aka -x / -k\n"
359 "\t[--no-notify|-l] aka -l\n"
360 "\t[--no-retire|-f] aka -f\n");
368 "\t--cka_id <CKA_ID> aka -k\n"
376 "usage: %s [-c <config> | --config <config>] \n\n",
394 "\t--repository <repository> aka -r\n"
396 "\t--repository <repository> aka -r\n"
398 "\t--repository <repository> aka -r\n"
400 "\t--repository <repository> aka -r\n"
402 "\t--repository <repository> aka -r\n"
404 "\t[NOTE: backup done is deprecated]\n");
412 "\t[--zone <zone>]\n");
420 "\t[--output <output>] aka -o\n");
428 " zonelist import\n");
435 "usage: %s [-c <config> | --config <config>] command [options]\n\n",
470 "\n\tAllowed date/time strings are of the form:\n"
472 "\tYYYYMMDD[HH[MM[SS]]] (all numeric)\n"
474 "\tor D-MMM-YYYY[:| ]HH[:MM[:SS]] (alphabetic month)\n"
475 "\tor DD-MMM-YYYY[:| ]HH[:MM[:SS]] (alphabetic month)\n"
476 "\tor YYYY-MMM-DD[:| ]HH[:MM[:SS]] (alphabetic month)\n"
478 "\tD-MM-YYYY[:| ]HH[:MM[:SS]] (numeric month)\n"
479 "\tDD-MM-YYYY[:| ]HH[:MM[:SS]] (numeric month)\n"
480 "\tor YYYY-MM-DD[:| ]HH[:MM[:SS]] (numeric month)\n"
482 "\t... and the distinction between them is given by the location of the\n"
490 "key states: GENERATE|PUBLISH|READY|ACTIVE|RETIRE|DEAD\n");
497 "key types: KSK|ZSK\n");
507 exist_file(
const char* filename) {
509 FILE *file = fopen(filename,
"r");
524 FILE* lock_fd = NULL;
525 char* zone_list_filename;
530 char *dbschema = NULL;
534 char *password = NULL;
539 char* setup_command = NULL;
540 char* lock_filename = NULL;
543 printf(
"*WARNING* This will erase all data in the database; are you sure? [y/N] ");
545 user_certain = getchar();
546 if (user_certain !=
'y' && user_certain !=
'Y') {
547 printf(
"Okay, quitting...\n");
554 status =
get_db_details(&dbschema, &host, &port, &user, &password);
573 lock_fd = fopen(lock_filename,
"w");
576 printf(
"Error getting db lock\n");
577 if (lock_fd != NULL) {
598 if (system(setup_command) != 0)
600 printf(
"Could not call db setup command:\n\t%s\n", setup_command);
616 printf(
"Couldn't fix permissions on file %s\n", dbschema);
617 printf(
"Will coninue with setup, but you may need to manually change ownership\n");
626 printf(
"Failed to connect to database, username too long.\n");
637 if (password != NULL) {
640 printf(
"Failed to connect to database, password too long.\n");
663 if (password != NULL) {
665 StrAppend(&setup_command, quoted_password);
673 if (system(setup_command) != 0)
675 printf(
"Could not call db setup command:\n\t%s\n", setup_command);
688 status =
DbConnect(&dbhandle, dbschema, host, password, user, port);
690 printf(
"Failed to connect to database\n");
713 printf(
"Failed to read conf.xml\n");
724 printf(
"Failed to update repositories\n");
737 printf(
"Failed to update policies\n");
738 printf(
"SETUP FAILED\n");
754 printf(
"Failed to update zones\n");
777 FILE* lock_fd = NULL;
778 char* zone_list_filename = NULL;
779 char* kasp_filename = NULL;
781 int done_something = 0;
786 printf(
"Failed to connect to database\n");
795 if (strncmp(qualifier,
"ZONELIST", 8) == 0 ||
796 strncmp(qualifier,
"KASP", 4) == 0 ||
797 strncmp(qualifier,
"ALL", 3) == 0) {
800 printf(
"Failed to read conf.xml\n");
810 if (strncmp(qualifier,
"CONF", 4) == 0 ||
811 strncmp(qualifier,
"ALL", 3) == 0) {
814 printf(
"Failed to update repositories\n");
816 if (strncmp(qualifier,
"ALL", 3) == 0) {
829 if (strncmp(qualifier,
"KASP", 4) == 0 ||
830 strncmp(qualifier,
"ALL", 3) == 0) {
833 printf(
"Failed to update policies\n");
846 if (strncmp(qualifier,
"ZONELIST", 8) == 0 ||
847 strncmp(qualifier,
"ALL", 3) == 0) {
850 printf(
"Failed to update zones\n");
862 if (done_something == 0) {
863 printf(
"Unrecognised command update %s. Please specify one of:\n", qualifier);
867 if (restart_enforcerd() != 0)
869 fprintf(stderr,
"Could not HUP ods-enforcerd\n");
878 if (kasp_filename != NULL) {
881 if (zone_list_filename != NULL) {
900 FILE* lock_fd = NULL;
901 char* zonelist_filename = NULL;
902 char* backup_filename = NULL;
904 char* sig_conf_name = NULL;
905 char* input_name = NULL;
906 char* output_name = NULL;
907 char* input_type = NULL;
908 char* output_type = NULL;
915 xmlDocPtr doc = NULL;
921 printf(
"Couldn't malloc path: %s\n", strerror(errno));
927 printf(
"Please specify a zone with the --zone option\n");
940 StrAppend(&sig_conf_name, OPENDNSSEC_STATE_DIR);
959 printf(
"Error: Unrecognised in-type %s; should be one of DNS or File\n",
o_in_type);
964 if(strcmp(input_type,
"DNS")==0){
965 StrAppend(&input_name, OPENDNSSEC_CONFIG_DIR);
968 StrAppend(&input_name, OPENDNSSEC_STATE_DIR);
986 printf(
"Error: Unrecognised out-type %s; should be one of DNS or File\n",
o_out_type);
991 if(strcmp(output_type,
"DNS") == 0){
992 StrAppend(&output_name, OPENDNSSEC_CONFIG_DIR);
995 StrAppend(&output_name, OPENDNSSEC_STATE_DIR);
1011 if(!exist_file(input_name)){
1012 fprintf(stdout,
"WARNING: The input file %s for zone %s does not currently exist. The zone will been added to the database anyway. \n",input_name,
o_zone);
1015 if(strcmp(output_type,
"DNS") == 0 && !exist_file(output_name)){
1016 fprintf(stdout,
"WARNING: The output file %s for zone %s does not currently exist. \n",output_name,
o_zone);
1024 printf(
"couldn't read zonelist\n");
1041 printf(
"Failed to connect to database\n");
1055 printf(
"Error, can't find policy : %s\n",
o_policy);
1056 printf(
"Failed to update zones\n");
1066 status =
KsmImportZone(
o_zone, policy_id, 1, &new_zone, sig_conf_name, input_name, output_name, input_type, output_type);
1069 printf(
"Failed to Import zone %s; it already exists\n",
o_zone);
1070 }
else if (status == -3) {
1071 printf(
"Failed to Import zone %s; it already exists both with and without a trailing dot\n",
o_zone);
1073 printf(
"Failed to Import zone\n");
1089 printf(
"Can't retrieve shared-keys parameter for policy\n");
1101 printf(
"Can't retrieve shared-keys parameter for policy\n");
1114 if (data.
value == 1) {
1117 printf(
"Failed to Link Keys to zone\n");
1137 if (xml_flag == 1) {
1140 xmlKeepBlanksDefault(0);
1141 xmlTreeIndentString =
"\t";
1156 StrAppend(&backup_filename, zonelist_filename);
1158 status =
backup_file(zonelist_filename, backup_filename);
1166 status = xmlSaveFormatFile(zonelist_filename, doc, 1);
1171 printf(
"couldn't save zonelist\n");
1179 if (xml_flag == 0) {
1180 printf(
"Imported zone: %s into database only, please run \"ods-ksmutil zonelist export\" to update zonelist.xml\n",
o_zone);
1182 printf(
"Imported zone: %s\n",
o_zone);
1199 char* zonelist_filename = NULL;
1200 char* backup_filename = NULL;
1205 xmlDocPtr doc = NULL;
1212 FILE* lock_fd = NULL;
1215 if (all_flag &&
o_zone != NULL) {
1216 printf(
"can not use --all with --zone\n");
1219 else if (!all_flag &&
o_zone == NULL) {
1220 printf(
"please specify either --zone <zone> or --all\n");
1225 if (all_flag == 1) {
1226 printf(
"*WARNING* This will remove all zones from OpenDNSSEC; are you sure? [y/N] ");
1228 user_certain = getchar();
1229 if (user_certain !=
'y' && user_certain !=
'Y') {
1230 printf(
"Okay, quitting...\n");
1238 printf(
"Failed to connect to database\n");
1251 if (xml_flag == 1) {
1255 printf(
"couldn't read zonelist\n");
1280 StrAppend(&backup_filename, zonelist_filename);
1282 status =
backup_file(zonelist_filename, backup_filename);
1291 status = xmlSaveFormatFile(zonelist_filename, doc, 1);
1295 printf(
"Could not save %s\n", zonelist_filename);
1306 if (all_flag == 0) {
1309 printf(
"Couldn't find zone %s\n",
o_zone);
1318 printf(
"Error: failed to mark keys as dead in database\n");
1327 printf(
"Error: failed to remove zone%s from database\n", (all_flag == 1) ?
"s" :
"");
1333 if (all_flag == 0) {
1334 if (system(SIGNER_CLI_UPDATE) != 0)
1336 printf(
"Could not call signer engine\n");
1343 if (xml_flag == 0) {
1344 printf(
"Deleted zone: %s from database only, please run \"ods-ksmutil zonelist export\" to update zonelist.xml\n",
o_zone);
1358 FILE* lock_fd = NULL;
1360 char* zonelist_filename = NULL;
1363 xmlTextReaderPtr reader = NULL;
1365 char* tag_name = NULL;
1367 int file_zone_count = 0;
1373 char* temp_name = NULL;
1380 printf(
"couldn't read zonelist\n");
1381 if (zonelist_filename != NULL) {
1390 printf(
"Failed to connect to database\n");
1396 reader = xmlNewTextReaderFilename(zonelist_filename);
1397 if (reader != NULL) {
1398 ret = xmlTextReaderRead(reader);
1400 tag_name = (
char*) xmlTextReaderLocalName(reader);
1402 if (strncmp(tag_name,
"Zone", 4) == 0
1403 && strncmp(tag_name,
"ZoneList", 8) != 0
1404 && xmlTextReaderNodeType(reader) == 1) {
1408 ret = xmlTextReaderRead(reader);
1411 xmlFreeTextReader(reader);
1413 printf(
"%s : failed to parse\n", zonelist_filename);
1416 printf(
"Unable to open %s\n", zonelist_filename);
1420 zone_ids =
MemMalloc(file_zone_count *
sizeof(
int));
1426 if (file_zone_count != 0) {
1427 StrAppend(&sql,
"select name from zones where id not in (");
1428 for (j = 0; j < file_zone_count; ++j) {
1432 snprintf(buffer,
sizeof(buffer),
"%d", zone_ids[j]);
1437 StrAppend(&sql,
"select name from zones");
1443 while (status == 0) {
1447 printf(
"Found zone %s in DB but not zonelist.\n", temp_name);
1464 if (file_zone_count == 0) {
1465 printf(
"No zones in DB or zonelist.\n");
1493 int prev_zone_id = -1;
1495 char *case_keytype = NULL;
1496 char *case_keystate = NULL;
1497 char *zone_name = NULL;
1500 hsm_key_t *key = NULL;
1501 ldns_rr *dnskey_rr = NULL;
1502 ldns_rr *ds_sha1_rr = NULL;
1503 ldns_rr *ds_sha256_rr = NULL;
1504 hsm_sign_params_t *sign_params = NULL;
1517 int done_something = 0;
1524 if (strncmp(case_keystate,
"KEYPUBLISH", 10) == 0 || strncmp(
o_keystate,
"10", 2) == 0) {
1527 else if (strncmp(case_keystate,
"GENERATE", 8) == 0 || strncmp(
o_keystate,
"1", 1) == 0) {
1530 else if (strncmp(case_keystate,
"PUBLISH", 7) == 0 || strncmp(
o_keystate,
"2", 1) == 0) {
1533 else if (strncmp(case_keystate,
"READY", 5) == 0 || strncmp(
o_keystate,
"3", 1) == 0) {
1536 else if (strncmp(case_keystate,
"ACTIVE", 6) == 0 || strncmp(
o_keystate,
"4", 1) == 0) {
1539 else if (strncmp(case_keystate,
"RETIRE", 6) == 0 || strncmp(
o_keystate,
"5", 1) == 0) {
1542 else if (strncmp(case_keystate,
"DEAD", 4) == 0 || strncmp(
o_keystate,
"6", 1) == 0) {
1545 else if (strncmp(case_keystate,
"DSSUB", 5) == 0 || strncmp(
o_keystate,
"7", 1) == 0) {
1548 else if (strncmp(case_keystate,
"DSPUBLISH", 9) == 0 || strncmp(
o_keystate,
"8", 1) == 0) {
1551 else if (strncmp(case_keystate,
"DSREADY", 7) == 0 || strncmp(
o_keystate,
"9", 1) == 0) {
1555 printf(
"Error: Unrecognised state %s; should be one of GENERATE, PUBLISH, READY, ACTIVE, RETIRE, DEAD, DSSUB, DSPUBLISH, DSREADY or KEYPUBLISH\n",
o_keystate);
1567 if (strncmp(case_keytype,
"KSK", 3) == 0 || strncmp(
o_keytype,
"257", 3) == 0) {
1570 else if (strncmp(case_keytype,
"ZSK", 3) == 0 || strncmp(
o_keytype,
"256", 3) == 0) {
1574 printf(
"Error: Unrecognised keytype %s; should be one of KSK or ZSK\n",
o_keytype);
1585 printf(
"Failed to connect to database\n");
1597 printf(
"Error: unable to find a zone named \"%s\" in database\n",
o_zone);
1603 status = hsm_open(
config, hsm_prompt_pin);
1605 hsm_print_error(NULL);
1610 if (state_id != -1) {
1613 nchar = snprintf(buffer,
sizeof(buffer),
"(%d, %d, %d, %d, %d, %d)",
1616 if (nchar >=
sizeof(buffer)) {
1625 if (zone_id != -1) {
1633 status =
KsmKey(result, &data);
1634 while (status == 0) {
1636 if (ds_flag == 1 && data.
zone_id != prev_zone_id) {
1638 if (red_seen == 0 && act_seen == 0) {
1639 printf(
"\nWARNING: No active or ready keys seen for this zone. Do not load any DS records to the parent unless you understand the possible consequences.\n");
1640 }
else if (red_seen == 1 && act_seen == 1) {
1641 printf(
"\nWARNING: BOTH ready and active keys seen for this zone. Probably a key rollover is happening and you may only want the ready key to be submitted.\n");
1655 key = hsm_find_key_by_id(NULL, data.
location);
1658 printf(
"Key %s in DB but not repository\n", data.
location);
1663 sign_params = hsm_sign_params_new();
1665 if (zone_id == -1) {
1668 printf(
"Error: unable to find zone name for id %d\n", zone_id);
1669 hsm_sign_params_free(sign_params);
1673 sign_params->owner = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, zone_name);
1677 sign_params->owner = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME,
o_zone);
1680 sign_params->algorithm = data.
algorithm;
1681 sign_params->flags = LDNS_KEY_ZONE_KEY;
1683 sign_params->flags += LDNS_KEY_SEP_KEY;
1685 dnskey_rr = hsm_get_dnskey(NULL, key, sign_params);
1686 sign_params->keytag = ldns_calc_keytag(dnskey_rr);
1702 ldns_rr_set_ttl(dnskey_rr, rrttl);
1707 ldns_rr_print(stdout, dnskey_rr);
1719 ldns_rr_set_ttl(dnskey_rr, rrttl);
1724 ds_sha1_rr = ldns_key_rr2ds(dnskey_rr, LDNS_SHA1);
1725 ldns_rr_print(stdout, ds_sha1_rr);
1728 ds_sha256_rr = ldns_key_rr2ds(dnskey_rr, LDNS_SHA256);
1729 ldns_rr_print(stdout, ds_sha256_rr);
1734 hsm_sign_params_free(sign_params);
1736 status =
KsmKey(result, &data);
1746 if (ds_flag == 1 && red_seen == 0 && act_seen == 0) {
1747 printf(
"\nWARNING: No active or ready keys seen for this zone. Do not load any DS records to the parent unless you understand the possible consequences.\n");
1748 }
else if (ds_flag == 1 && red_seen == 1 && act_seen == 1) {
1749 printf(
"\nWARNING: BOTH ready and active keys seen for this zone. Probably a key rollover is happening and you may only want the ready key to be submitted.\n");
1753 if (!done_something) {
1754 if (state_id != -1) {
1757 printf(
"No keys in READY state or higher to export.\n");
1763 if (dnskey_rr != NULL) {
1764 ldns_rr_free(dnskey_rr);
1766 if (ds_sha1_rr != NULL) {
1767 ldns_rr_free(ds_sha1_rr);
1769 if (ds_sha256_rr != NULL) {
1770 ldns_rr_free(ds_sha256_rr);
1790 xmlDocPtr doc = xmlNewDoc((
const xmlChar *)
"1.0");
1797 if (all_flag &&
o_policy != NULL) {
1798 printf(
"can not use --all with --policy\n");
1801 else if (!all_flag &&
o_policy == NULL) {
1802 printf(
"please specify either --policy <policy> or --all\n");
1809 printf(
"Failed to connect to database\n");
1815 if (policy == NULL) {
1816 fprintf(stderr,
"Malloc for policy struct failed\n");
1831 policy->
zone == NULL || policy->
parent == NULL ||
1832 policy->
keys == NULL ||
1833 policy->
ksk == NULL || policy->
zsk == NULL ||
1835 fprintf(stderr,
"Malloc for policy struct failed\n");
1840 xmlKeepBlanksDefault(0);
1841 xmlTreeIndentString =
" ";
1842 root = xmlNewDocNode(doc, NULL, (
const xmlChar *)
"KASP", NULL);
1843 (void) xmlDocSetRootElement(doc, root);
1852 while (status == 0) {
1862 xmlSaveFormatFile(
"-", doc, 1);
1883 xmlDocPtr doc = xmlNewDoc((
const xmlChar *)
"1.0");
1886 int prev_policy_id = -1;
1893 printf(
"Failed to connect to database\n");
1900 fprintf(stderr,
"Malloc for zone struct failed\n");
1905 xmlKeepBlanksDefault(0);
1906 xmlTreeIndentString =
" ";
1907 root = xmlNewDocNode(doc, NULL, (
const xmlChar *)
"ZoneList", NULL);
1908 (void) xmlDocSetRootElement(doc, root);
1914 status =
KsmZone(result, zone);
1916 while (status == 0) {
1917 if (zone->
policy_id != prev_policy_id) {
1921 fprintf(stderr,
"Couldn't get name for policy with ID: %d, exiting...\n", zone->
policy_id);
1928 status =
KsmZone(result, zone);
1933 xmlSaveFormatFile(
"-", doc, 1);
1951 FILE* lock_fd = NULL;
1973 printf(
"Failed to connect to database\n");
1984 printf(
"Error, can't find zone : %s\n",
o_zone);
2004 if (data.
value == 1) {
2005 printf(
"*WARNING* This zone shares keys with others, all instances of the active key on this zone will be retired; are you sure? [y/N] ");
2007 user_certain = getchar();
2008 if (user_certain !=
'y' && user_certain !=
'Y') {
2009 printf(
"Okay, quitting...\n");
2015 status =
keyRoll(zone_id, -1, key_type);
2022 snprintf(logmsg, 256,
"Manual key rollover for key type %s on zone %s initiated" , (
o_keytype == NULL) ?
"all" :
o_keytype,
o_zone);
2023 printf(
"\n%s\n", logmsg);
2026 #ifdef HAVE_OPENLOG_R
2031 #ifdef HAVE_SYSLOG_R
2032 syslog_r(LOG_INFO, &sdata,
"%s", logmsg);
2034 syslog(LOG_INFO,
"%s", logmsg);
2036 #ifdef HAVE_CLOSELOG_R
2046 if (restart_enforcerd() != 0)
2048 fprintf(stderr,
"Could not HUP ods-enforcerd\n");
2064 FILE* lock_fd = NULL;
2068 int zone_count = -1;
2087 printf(
"Failed to connect to database\n");
2094 printf(
"Error, can't find policy : %s\n",
o_policy);
2100 printf(
"*WARNING* This will roll all keys on the policy; are you sure? [y/N] ");
2102 user_certain = getchar();
2103 if (user_certain !=
'y' && user_certain !=
'Y') {
2104 printf(
"Okay, quitting...\n");
2119 if (zone_count == 0) {
2120 printf(
"No zones on policy; nothing to roll\n");
2125 printf(
"Couldn't count zones on policy; quitting...\n");
2130 status =
keyRoll(-1, policy_id, key_type);
2137 snprintf(logmsg, 256,
"Manual key rollover for key type %s on policy %s initiated" , (
o_keytype == NULL) ?
"all" :
o_keytype,
o_policy);
2138 printf(
"%s\n", logmsg);
2141 #ifdef HAVE_OPENLOG_R
2146 #ifdef HAVE_SYSLOG_R
2147 syslog_r(LOG_INFO, &sdata,
"%s", logmsg);
2149 syslog(LOG_INFO,
"%s", logmsg);
2151 #ifdef HAVE_CLOSELOG_R
2161 if (restart_enforcerd() != 0)
2163 fprintf(stderr,
"Could not HUP ods-enforcerd\n");
2184 FILE* lock_fd = NULL;
2189 printf(
"Failed to connect to database\n");
2198 printf(
"Error: unable to find a policy named \"%s\" in database\n",
o_policy);
2212 printf(
"Error: unable to find a zone named \"%s\" in database\n",
o_zone);
2222 printf(
"Error: failed to purge dead keys\n");
2248 FILE* lock_fd = NULL;
2253 if (datetime == NULL) {
2254 printf(
"Couldn't turn \"now\" into a date, quitting...\n");
2259 if ( strncmp(qualifier,
"DONE", 4) == 0 ) {
2260 printf(
"*WARNING* One-step backups are deprecated in favour of a two-step process; see the documentation on key management for the explanation.\n");
2263 if (force_flag == 0) {
2264 printf(
"Do you wish to continue? [y/N] ");
2266 user_certain = getchar();
2267 if (user_certain !=
'y' && user_certain !=
'Y') {
2268 printf(
"Okay, quitting...\n");
2277 printf(
"Failed to connect to database\n");
2287 printf(
"Error: unable to find a repository named \"%s\" in database\n",
o_repository);
2295 if (strncmp(qualifier,
"PREPARE", 7) == 0 ||
2296 strncmp(qualifier,
"DONE", 4) == 0 ) {
2299 printf(
"There were no keys to mark\n");
2301 else if (status != 0) {
2302 printf(
"Error: failed to mark pre_backup as done\n");
2307 if (strncmp(qualifier,
"PREPARE", 7) == 0) {
2309 printf(
"Marked repository %s as pre-backed up at %s\n",
o_repository, datetime);
2311 printf(
"Marked all repositories as pre-backed up at %s\n", datetime);
2318 if (strncmp(qualifier,
"COMMIT", 6) == 0 ||
2319 strncmp(qualifier,
"DONE", 4) == 0 ) {
2322 printf(
"There were no keys to mark\n");
2324 else if (status != 0) {
2325 printf(
"Error: failed to mark backup as done\n");
2331 printf(
"Marked repository %s as backed up at %s\n",
o_repository, datetime);
2333 printf(
"Marked all repositories as backed up at %s\n", datetime);
2339 if (strncmp(qualifier,
"ROLLBACK", 6) == 0 ) {
2342 printf(
"There were no keys to rollback\n");
2344 else if (status != 0) {
2345 printf(
"Error: failed to mark backup as done\n");
2351 printf(
"Rolled back pre-backup of repository %s\n",
o_repository);
2353 printf(
"Rolled back pre-backup of all repositories\n");
2375 int qualifier_id = -1;
2379 FILE* lock_fd = NULL;
2384 printf(
"Failed to connect to database\n");
2397 printf(
"Error: unable to find a zone named \"%s\" in database\n",
o_zone);
2404 printf(
"Rollovers:\n");
2409 printf(
"Error: failed to list rollovers\n");
2418 if (verbose_flag && ds_count > 0) {
2420 status =
ListDS(qualifier_id);
2423 printf(
"Error: failed to list DS records\n");
2444 int qualifier_id = -1;
2448 FILE* lock_fd = NULL;
2453 printf(
"Failed to connect to database\n");
2462 printf(
"Error: unable to find a repository named \"%s\" in database\n",
o_repository);
2468 printf(
"Backups:\n");
2472 printf(
"Error: failed to list backups\n");
2495 FILE* lock_fd = NULL;
2500 printf(
"Failed to connect to database\n");
2505 printf(
"Repositories:\n");
2510 printf(
"Error: failed to list repositories\n");
2511 if (lock_fd != NULL) {
2536 FILE* lock_fd = NULL;
2541 printf(
"Failed to connect to database\n");
2546 printf(
"Policies:\n");
2551 printf(
"Error: failed to list policies\n");
2572 int qualifier_id = -1;
2576 FILE* lock_fd = NULL;
2581 printf(
"Failed to connect to database\n");
2594 printf(
"Error: unable to find a zone named \"%s\" in database\n",
o_zone);
2606 printf(
"Error: failed to list keys\n");
2633 int keytag_int = -1;
2634 int temp_key_state = -1;
2635 int temp_keypair_id = -1;
2636 char* temp_cka_id = NULL;
2641 FILE* lock_fd = NULL;
2646 if (datetime == NULL) {
2647 printf(
"Couldn't turn \"now\" into a date, quitting...\n");
2653 printf(
"*WARNING* This will retire the currently active KSK; are you sure? [y/N] ");
2655 user_certain = getchar();
2656 if (user_certain !=
'y' && user_certain !=
'Y') {
2657 printf(
"Okay, quitting...\n");
2664 printf(
"Failed to connect to database\n");
2678 printf(
"Error: unable to find a zone named \"%s\" in database\n",
o_zone);
2691 printf(
"Error: Unable to convert keytag \"%s\"; to an integer\n",
o_keytag);
2697 printf(
"Error: keytag \"%s\"; should be numeric only\n",
o_keytag);
2707 printf(
"Please provide a zone or details of the key to roll\n");
2716 printf(
"Error: failed to count active keys\n");
2723 if (key_count < 2) {
2724 printf(
"Error: completing this action would leave no active keys on zone, quitting...\n");
2733 printf(
"Error: failed to find policy for zone\n");
2742 printf(
"Old key retired\n");
2744 printf(
"Old key NOT retired\n");
2752 status =
CountKeys(&zone_id, keytag_int,
o_cka_id, &key_count, &temp_cka_id, &temp_key_state, &temp_keypair_id);
2754 printf(
"Error: failed to count keys\n");
2761 if (key_count > 1) {
2762 printf(
"More than one key matched your parameters, please include more information from the above keys\n");
2770 printf(
"No keys in the ACTIVE state matched your parameters, please check the parameters\n");
2778 printf(
"Error: failed to count active keys\n");
2785 if (key_count < 2) {
2786 printf(
"Error: completing this action would leave no active keys on zone, quitting...\n");
2795 printf(
"Error: failed to find policy for zone\n");
2806 printf(
"Key %s retired\n", temp_cka_id);
2833 int retired_count = -1;
2834 int keytag_int = -1;
2835 int temp_key_state = -1;
2836 int temp_keypair_id = -1;
2837 char* temp_cka_id = NULL;
2842 FILE* lock_fd = NULL;
2849 if (datetime == NULL) {
2850 printf(
"Couldn't turn \"now\" into a date, quitting...\n");
2857 printf(
"Please provide a keytag or a CKA_ID for the key (CKA_ID will be used if both are provided\n");
2865 printf(
"*WARNING* This will retire the currently active KSK; are you sure? [y/N] ");
2867 user_certain = getchar();
2868 if (user_certain !=
'y' && user_certain !=
'Y') {
2869 printf(
"Okay, quitting...\n");
2876 printf(
"Failed to connect to database\n");
2887 printf(
"Please specify a zone using the --zone flag\n");
2893 else if (
o_zone != NULL) {
2900 printf(
"Error: unable to find a zone named \"%s\" in database\n",
o_zone);
2907 else if (all_flag) {
2908 printf(
"*WARNING* This will act on every zone where this key is in use; are you sure? [y/N] ");
2910 user_certain = getchar();
2911 if (user_certain !=
'y' && user_certain !=
'Y') {
2912 printf(
"Okay, quitting...\n");
2924 printf(
"Error: Unable to convert keytag \"%s\"; to an integer\n",
o_keytag);
2930 printf(
"Error: keytag \"%s\"; should be numeric only\n",
o_keytag);
2941 status =
CountKeys(&zone_id, keytag_int,
o_cka_id, &key_count, &temp_cka_id, &temp_key_state, &temp_keypair_id);
2943 printf(
"Error: failed to count keys\n");
2950 if (key_count > 1) {
2951 printf(
"More than one key matched your parameters, please include more information from the above keys\n");
2959 printf(
"Key is already active\n");
2966 if (key_count == 0) {
2967 printf(
"No keys in the READY state matched your parameters, please check the parameters\n");
2976 printf(
"Error: failed to find policy for zone\n");
2983 status =
MarkDSSeen(temp_keypair_id, zone_id, policy_id, datetime, temp_key_state);
2987 snprintf(logmsg, 256,
"Key %s made %s", temp_cka_id, (temp_key_state ==
KSM_STATE_READY) ?
"active" :
"into standby");
2988 printf(
"%s\n", logmsg);
2991 #ifdef HAVE_OPENLOG_R
2996 #ifdef HAVE_SYSLOG_R
2997 syslog_r(LOG_INFO, &sdata,
"%s", logmsg);
2999 syslog(LOG_INFO,
"%s", logmsg);
3001 #ifdef HAVE_CLOSELOG_R
3011 if (retire_flag == 1) {
3016 printf(
"Error: failed to count active keys\n");
3023 if (key_count < 2) {
3027 printf(
"Error: failed to count retired keys\n");
3036 if (retired_count != 0) {
3037 printf(
"Error: retiring a key would leave no active keys on zone, skipping...\n");
3042 if (notify_flag == 1) {
3043 if (restart_enforcerd() != 0) {
3044 fprintf(stderr,
"Could not HUP ods-enforcerd\n");
3046 fprintf(stdout,
"Performed a HUP ods-enforcerd\n");
3049 fprintf(stdout,
"No HUP ods-enforcerd was performed as the '--no-notify' flag was specified.\n");
3050 fprintf(stdout,
"Warning: The enforcer must be manually notified or the changes will not take full effect until the next scheduled enforcer run.\n");
3060 printf(
"Old key retired\n");
3062 printf(
"Old key NOT retired\n");
3065 printf(
"Old key NOT retired\n");
3069 if (notify_flag == 1) {
3070 if (restart_enforcerd() != 0) {
3071 fprintf(stderr,
"Could not HUP ods-enforcerd\n");
3073 fprintf(stdout,
"Performed a HUP ods-enforcerd\n");
3076 fprintf(stdout,
"No HUP ods-enforcerd was performed as the '--no-notify' flag was specified.\n");
3077 fprintf(stdout,
"Warning: The enforcer must be manually notified or the changes will not take full effect until the next scheduled enforcer run.\n");
3099 char* case_keytype = NULL;
3100 char* case_algorithm = NULL;
3101 char* case_state = NULL;
3106 int cka_id_exists = -1;
3107 int keytype_id = -1;
3114 DB_ID keypair_id = 0;
3123 FILE* lock_fd = NULL;
3130 hsm_key_t *key = NULL;
3135 printf(
"Error: please specify a CKA_ID with the --cka_id <CKA_ID>\n");
3139 printf(
"Error: please specify a repository with the --repository <repository>\n");
3143 printf(
"Error: please specify a zone with the --zone <zone>\n");
3147 printf(
"Error: please specify the number of bits with the --bits <size>\n");
3151 printf(
"Error: please specify the algorithm with the --algorithm <algorithm>\n");
3155 printf(
"Error: please specify the state with the --keystate <state>\n");
3159 printf(
"Error: please specify a keytype, KSK or ZSK, with the --keytype <type>\n");
3163 printf(
"Error: please specify the time of when the key entered the given state with the --time <time>\n");
3168 status = hsm_open(
config, hsm_prompt_pin);
3170 hsm_print_error(NULL);
3173 key = hsm_find_key_by_id(NULL,
o_cka_id);
3176 if(check_repository_flag){
3177 fprintf(stderr,
"Error: No key with the CKA_ID %-33s exists in the repository %s. When the option [--check-repository] is used the key MUST exist in the repository for the key to be imported. \n",
o_cka_id,
o_repository);
3180 fprintf(stdout,
"Warning: No key with the CKA_ID %-33s exists in the repository %s. The key will be imported into the database anyway. \n",
o_cka_id,
o_repository);
3189 printf(
"Failed to connect to database\n");
3197 printf(
"Error: unable to find a repository named \"%s\" in database\n",
o_repository);
3209 printf(
"Error: unable to find a zone named \"%s\" in database\n",
o_zone);
3221 if (cka_id_exists == 1) {
3222 printf(
"Error: key with CKA_ID \"%s\" already exists in database\n",
o_cka_id);
3230 if (strncmp(case_keytype,
"KSK", 3) == 0 || strncmp(
o_keytype,
"257", 3) == 0) {
3233 else if (strncmp(case_keytype,
"ZSK", 3) == 0 || strncmp(
o_keytype,
"256", 3) == 0) {
3237 printf(
"Error: Unrecognised keytype %s; should be one of KSK or ZSK\n",
o_keytype);
3249 printf(
"Error: Unable to convert bits \"%s\"; to an integer\n",
o_size);
3254 printf(
"Error: Bits \"%s\"; should be numeric only\n",
o_size);
3272 if (status != 0 || algo_id == 0 || hsm_supported_algorithm(algo_id) != 0) {
3273 printf(
"Error: Key algorithm %s not supported; try one of RSASHA1, RSASHA1-NSEC3-SHA1 or RSASHA256\n",
o_algo);
3281 if (strncmp(case_state,
"GENERATE", 8) == 0 || strncmp(
o_keystate,
"1", 1) == 0) {
3284 else if (strncmp(case_state,
"PUBLISH", 7) == 0 || strncmp(
o_keystate,
"2", 1) == 0) {
3287 else if (strncmp(case_state,
"READY", 5) == 0 || strncmp(
o_keystate,
"3", 1) == 0) {
3290 else if (strncmp(case_state,
"ACTIVE", 6) == 0 || strncmp(
o_keystate,
"4", 1) == 0) {
3293 else if (strncmp(case_state,
"RETIRE", 6) == 0 || strncmp(
o_keystate,
"5", 1) == 0) {
3297 printf(
"Error: Unrecognised state %s; should be one of GENERATE, PUBLISH, READY, ACTIVE or RETIRE\n",
o_keystate);
3308 printf(
"Error: unable to convert \"%s\" into a date\n",
o_time);
3315 snprintf(form_time,
KSM_TIME_LENGTH,
"%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d",
3316 datetime.tm_year + 1900, datetime.tm_mon + 1, datetime.tm_mday,
3317 datetime.tm_hour, datetime.tm_min, datetime.tm_sec);
3318 printf(
"Converted time is %s\n", form_time);
3324 printf(
"Error: unable to specify retire time for a key in state \"%s\"\n",
o_keystate);
3331 printf(
"Error: unable to convert retire time \"%s\" into a date\n",
o_retire);
3338 snprintf(form_opt_time,
KSM_TIME_LENGTH,
"%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d",
3339 datetime.tm_year + 1900, datetime.tm_mon + 1, datetime.tm_mday,
3340 datetime.tm_hour, datetime.tm_min, datetime.tm_sec);
3344 form_opt_time[0] =
'\0';
3361 if (data.
value == 1) {
3362 printf(
"*WARNING* This zone shares keys with others, the key will be added to all; are you sure? [y/N] ");
3364 user_certain = getchar();
3365 if (user_certain !=
'y' && user_certain !=
'Y') {
3366 printf(
"Okay, quitting...\n");
3373 status =
KsmImportKeyPair(policy_id,
o_cka_id, repo_id, size_int, algo_id, state_id, form_time, fix_time, &keypair_id);
3375 printf(
"Error: couldn't import key\n");
3385 status =
KsmDnssecKeyCreate(zone_id, (
int) keypair_id, keytype_id, state_id, form_time, form_opt_time, &ignore);
3388 printf(
"Error: couldn't allocate key to zone(s)\n");
3393 printf(
"Key imported into zone(s)\n");
3409 FILE* lock_fd = NULL;
3412 char *dbschema = NULL;
3416 char *password = NULL;
3420 char* backup_filename = NULL;
3421 char* lock_filename;
3423 char *path = getenv(
"PWD");
3426 printf(
"Sorry, currently this utility can only backup a sqlite database file\n");
3431 status =
get_db_details(&dbschema, &host, &port, &user, &password);
3442 lock_filename = NULL;
3446 lock_fd = fopen(lock_filename,
"w");
3449 printf(
"Error getting db lock\n");
3450 if (lock_fd != NULL) {
3500 char* kasp_filename = NULL;
3501 char* zonelist_filename = NULL;
3502 char* backup_filename = NULL;
3505 FILE* lock_fd = NULL;
3514 int zone_count = -1;
3516 xmlDocPtr doc = NULL;
3519 printf(
"*WARNING* This feature is experimental and has not been fully tested; are you sure? [y/N] ");
3521 user_certain = getchar();
3522 if (user_certain !=
'y' && user_certain !=
'Y') {
3523 printf(
"Okay, quitting...\n");
3530 printf(
"Failed to read conf.xml\n");
3536 StrAppend(&backup_filename, kasp_filename);
3538 status =
backup_file(kasp_filename, backup_filename);
3548 if ((test = fopen(kasp_filename,
"ab"))==NULL) {
3549 printf(
"Cannot open kasp.xml for writing: %s\n", strerror(errno));
3560 printf(
"Failed to connect to database\n");
3581 if (policy == NULL) {
3582 printf(
"Malloc for policy struct failed\n");
3591 while (status == 0) {
3601 if (zone_count == 0) {
3602 printf(
"No zones on policy %s; purging...\n", policy->
name);
3604 size = snprintf(sql,
KSM_SQL_SIZE,
"update dnsseckeys set state = %d where keypair_id in (select id from keypairs where policy_id = %d)",
KSM_STATE_DEAD, policy->
id);
3608 printf(
"Couldn't construct SQL to kill orphaned keys\n");
3631 printf(
"Key purge failed for policy %s\n", policy->
name);
3640 sql2 =
DdsInit(
"parameters_policies");
3684 status = xmlSaveFormatFile(kasp_filename, doc, 1);
3687 printf(
"Could not save %s\n", kasp_filename);
3697 printf(
"Couldn't count zones on policy; quitting...\n");
3735 char* ods_control_cmd = NULL;
3736 char* ptr = command;
3741 *ptr = tolower((
int) *ptr);
3747 StrAppend(&ods_control_cmd, ODS_EN_CONTROL);
3750 status = system(ods_control_cmd);
3753 fprintf(stderr,
"Couldn't run %s\n", ods_control_cmd);
3769 char* case_command = NULL;
3770 char* case_verb = NULL;
3772 int option_index = 0;
3773 static struct option long_options[] =
3775 {
"all", no_argument, 0,
'a'},
3776 {
"auto-accept", no_argument, 0,
'A'},
3777 {
"bits", required_argument, 0,
'b'},
3778 {
"config", required_argument, 0,
'c'},
3779 {
"check-repository", no_argument, 0,
'C'},
3780 {
"ds", no_argument, 0,
'd'},
3781 {
"keystate", required_argument, 0,
'e'},
3782 {
"no-retire", no_argument, 0,
'f'},
3783 {
"force", no_argument, 0,
'F'},
3784 {
"algorithm", required_argument, 0,
'g'},
3785 {
"help", no_argument, 0,
'h'},
3786 {
"input", required_argument, 0,
'i'},
3787 {
"in-type", required_argument, 0,
'j'},
3788 {
"cka_id", required_argument, 0,
'k'},
3789 {
"no-notify", no_argument, 0,
'l'},
3790 {
"no-xml", no_argument, 0,
'm'},
3791 {
"no-hsm", no_argument, 0,
'M'},
3792 {
"interval", required_argument, 0,
'n'},
3793 {
"output", required_argument, 0,
'o'},
3794 {
"policy", required_argument, 0,
'p'},
3795 {
"out-type", required_argument, 0,
'q'},
3796 {
"repository", required_argument, 0,
'r'},
3797 {
"signerconf", required_argument, 0,
's'},
3798 {
"keytype", required_argument, 0,
't'},
3799 {
"time", required_argument, 0,
'w'},
3800 {
"verbose", no_argument, 0,
'v'},
3801 {
"version", no_argument, 0,
'V'},
3802 {
"keytag", required_argument, 0,
'x'},
3803 {
"retire", required_argument, 0,
'y'},
3804 {
"zone", required_argument, 0,
'z'},
3805 {
"zonetotal", required_argument, 0,
'Z'},
3811 while ((ch = getopt_long(argc, argv,
"aAb:Cc:de:fFg:hi:j:k:mMln:o:p:q:r:s:t:vVw:x:y:z:Z:", long_options, &option_index)) != -1) {
3817 auto_accept_flag = 1;
3826 check_repository_flag = 1;
3890 printf(
"%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION);
3948 if (!strncmp(case_command,
"SETUP", 5)) {
3952 }
else if (!strncmp(case_command,
"UPDATE", 6)) {
3956 }
else if (!strncmp(case_command,
"START", 5) ||
3957 !strncmp(case_command,
"STOP", 4) ||
3958 !strncmp(case_command,
"NOTIFY", 6)) {
3962 }
else if (!strncmp(case_command,
"ZONE", 4) && strlen(case_command) == 4) {
3967 if (!strncmp(case_verb,
"ADD", 3)) {
3969 }
else if (!strncmp(case_verb,
"DELETE", 6)) {
3971 }
else if (!strncmp(case_verb,
"LIST", 4)) {
3974 printf(
"Unknown command: zone %s\n", case_verb);
3978 }
else if (!strncmp(case_command,
"REPOSITORY", 10)) {
3982 if (!strncmp(case_verb,
"LIST", 4)) {
3985 printf(
"Unknown command: repository %s\n", case_verb);
3989 }
else if (!strncmp(case_command,
"POLICY", 6)) {
3993 if (!strncmp(case_verb,
"EXPORT", 6)) {
3995 }
else if (!strncmp(case_verb,
"IMPORT", 6)) {
3997 }
else if (!strncmp(case_verb,
"LIST", 4)) {
3999 }
else if (!strncmp(case_verb,
"PURGE", 5)) {
4002 printf(
"Unknown command: policy %s\n", case_verb);
4006 }
else if (!strncmp(case_command,
"KEY", 3)) {
4010 if (!strncmp(case_verb,
"LIST", 4)) {
4013 else if (!strncmp(case_verb,
"EXPORT", 6)) {
4016 else if (!strncmp(case_verb,
"IMPORT", 6)) {
4019 else if (!strncmp(case_verb,
"ROLLOVER", 8)) {
4021 if (all_flag == 0 &&
o_keytype == NULL) {
4022 printf(
"Please specify either a keytype, KSK or ZSK, with the --keytype <type> option or use the --all option\n");
4035 printf(
"Please provide either a zone OR a policy to rollover\n");
4041 else if (!strncmp(case_verb,
"PURGE", 5)) {
4047 printf(
"Please provide either a zone OR a policy to key purge\n");
4052 else if (!strncmp(case_verb,
"GENERATE", 8)) {
4055 else if (!strncmp(case_verb,
"KSK-RETIRE", 10)) {
4058 else if (!strncmp(case_verb,
"DS-SEEN", 7)) {
4060 }
else if (!strncmp(case_verb,
"DELETE", 6)) {
4063 printf(
"Unknown command: key %s\n", case_verb);
4067 }
else if (!strncmp(case_command,
"BACKUP", 6)) {
4071 if (!strncmp(case_verb,
"DONE", 4) ||
4072 !strncmp(case_verb,
"PREPARE", 7) ||
4073 !strncmp(case_verb,
"COMMIT", 6) ||
4074 !strncmp(case_verb,
"ROLLBACK", 8)) {
4077 else if (!strncmp(case_verb,
"LIST", 4)) {
4080 printf(
"Unknown command: backup %s\n", case_verb);
4084 }
else if (!strncmp(case_command,
"ROLLOVER", 8)) {
4087 if (!strncmp(case_verb,
"LIST", 4)) {
4090 printf(
"Unknown command: rollover %s\n", case_verb);
4094 }
else if (!strncmp(case_command,
"DATABASE", 8)) {
4098 if (!strncmp(case_verb,
"BACKUP", 6)) {
4101 printf(
"Unknown command: database %s\n", case_verb);
4105 }
else if (!strncmp(case_command,
"ZONELIST", 8)) {
4109 if (!strncmp(case_verb,
"EXPORT", 6)) {
4112 else if (!strncmp(case_verb,
"IMPORT", 6)) {
4115 printf(
"Unknown command: zonelist %s\n", case_verb);
4120 printf(
"Unknown command: %s\n", argv[0]);
4132 xmlCleanupGlobals();
4133 xmlCleanupThreads();
4155 char *dbschema = NULL;
4159 char *password = NULL;
4163 char* backup_filename = NULL;
4164 char* lock_filename;
4167 status =
get_db_details(&dbschema, &host, &port, &user, &password);
4183 if (lock_fd != NULL) {
4184 lock_filename = NULL;
4188 *lock_fd = fopen(lock_filename,
"w");
4191 printf(
"Error getting db lock\n");
4192 if (*lock_fd != NULL) {
4216 if (lock_fd != NULL) {
4231 status =
DbConnect(dbhandle, dbschema, host, password, user, port);
4253 if (lock_fd != NULL) {
4256 printf(
"Error releasing db lock");
4278 if (lock_fd == NULL) {
4279 printf(
"%s could not be opened\n", lock_filename);
4283 memset(&fl, 0,
sizeof(
struct flock));
4284 fl.l_type = F_WRLCK;
4285 fl.l_whence = SEEK_SET;
4286 fl.l_pid = getpid();
4288 while (fcntl(fileno(lock_fd), F_SETLK, &fl) == -1) {
4290 printf(
"couldn't get lock on %s; %s\n", lock_filename, strerror(errno));
4293 if (errno == EACCES || errno == EAGAIN) {
4294 printf(
"%s already locked, sleep\n", lock_filename);
4299 select(0, NULL, NULL, NULL, &tv);
4304 printf(
"couldn't get lock on %s; %s\n", lock_filename, strerror(errno));
4317 if (lock_fd == NULL) {
4321 memset(&fl, 0,
sizeof(
struct flock));
4322 fl.l_type = F_UNLCK;
4323 fl.l_whence = SEEK_SET;
4325 if (fcntl(fileno(lock_fd), F_SETLK, &fl) == -1) {
4338 xmlTextReaderPtr reader = NULL;
4339 xmlDocPtr doc = NULL;
4340 xmlXPathContextPtr xpathCtx = NULL;
4341 xmlXPathObjectPtr xpathObj = NULL;
4343 char* tag_name = NULL;
4344 char* temp_char = NULL;
4346 xmlChar *zonelist_expr = (
unsigned char*)
"//Common/ZoneListFile";
4347 xmlChar *kaspfile_expr = (
unsigned char*)
"//Common/PolicyFile";
4350 reader = xmlNewTextReaderFilename(
config);
4351 if (reader != NULL) {
4352 ret = xmlTextReaderRead(reader);
4354 tag_name = (
char*) xmlTextReaderLocalName(reader);
4356 if (strncmp(tag_name,
"Common", 6) == 0
4357 && xmlTextReaderNodeType(reader) == 1) {
4360 xmlTextReaderExpand(reader);
4361 doc = xmlTextReaderCurrentDoc(reader);
4363 printf(
"Error: can not read Common section\n");
4365 ret = xmlTextReaderRead(reader);
4369 xpathCtx = xmlXPathNewContext(doc);
4370 if(xpathCtx == NULL) {
4371 printf(
"Error: can not create XPath context for Common section\n");
4373 ret = xmlTextReaderRead(reader);
4378 xpathObj = xmlXPathEvalExpression(zonelist_expr, xpathCtx);
4379 if(xpathObj == NULL) {
4380 printf(
"Error: unable to evaluate xpath expression: %s\n", zonelist_expr);
4382 ret = xmlTextReaderRead(reader);
4385 *zone_list_filename = NULL;
4386 temp_char = (
char*) xmlXPathCastToString(xpathObj);
4387 StrAppend(zone_list_filename, temp_char);
4389 xmlXPathFreeObject(xpathObj);
4390 printf(
"zonelist filename set to %s.\n", *zone_list_filename);
4393 xpathObj = xmlXPathEvalExpression(kaspfile_expr, xpathCtx);
4394 xmlXPathFreeContext(xpathCtx);
4395 if(xpathObj == NULL) {
4396 printf(
"Error: unable to evaluate xpath expression: %s\n", kaspfile_expr);
4398 ret = xmlTextReaderRead(reader);
4401 *kasp_filename = NULL;
4402 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
4406 temp_char = (
char*) xmlXPathCastToString(xpathObj);
4414 StrAppend(kasp_filename, OPENDNSSEC_CONFIG_DIR);
4417 printf(
"kasp filename set to %s.\n", *kasp_filename);
4419 xmlXPathFreeObject(xpathObj);
4422 ret = xmlTextReaderRead(reader);
4426 xmlFreeTextReader(reader);
4428 printf(
"%s : failed to parse\n",
config);
4432 printf(
"Unable to open %s\n",
config);
4449 xmlDocPtr doc = NULL;
4450 xmlXPathContextPtr xpathCtx = NULL;
4451 xmlXPathObjectPtr xpathObj = NULL;
4453 char* repo_name = NULL;
4454 char* repo_capacity = NULL;
4455 int require_backup = 0;
4458 xmlChar *node_expr = (
unsigned char*)
"//Configuration/RepositoryList/Repository";
4462 doc = xmlParseFile(
config);
4464 printf(
"Unable to open %s\n",
config);
4469 xpathCtx = xmlXPathNewContext(doc);
4470 if(xpathCtx == NULL) {
4476 xpathObj = xmlXPathEvalExpression(node_expr, xpathCtx);
4477 if(xpathObj == NULL) {
4478 xmlXPathFreeContext(xpathCtx);
4483 if (xpathObj->nodesetval) {
4484 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
4489 curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
4490 repo_name = (
char *) xmlGetProp(xpathObj->nodesetval->nodeTab[i],
4491 (
const xmlChar *)
"name");
4493 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Capacity")) {
4494 repo_capacity = (
char *) xmlNodeGetContent(curNode);
4496 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"RequireBackup")) {
4500 curNode = curNode->next;
4503 if (strlen(repo_name) != 0) {
4505 printf(
"Repository %s found\n", repo_name);
4506 if (strlen(repo_capacity) == 0) {
4507 printf(
"No Maximum Capacity set.\n");
4513 printf(
"Capacity set to %s.\n", repo_capacity);
4519 if (require_backup == 0) {
4520 printf(
"RequireBackup NOT set; please make sure that you know the potential problems of using keys which are not recoverable\n");
4522 printf(
"RequireBackup set.\n");
4526 printf(
"Error Importing Repository %s", repo_name);
4530 printf(
"WARNING: Repository found with NULL name, skipping...\n");
4538 xmlXPathFreeObject(xpathObj);
4541 xmlXPathFreeContext(xpathCtx);
4556 char *policy_name = NULL;
4557 char *policy_description = NULL;
4560 xmlDocPtr doc = NULL;
4561 xmlDocPtr pol_doc = NULL;
4562 xmlDocPtr rngdoc = NULL;
4565 xmlNode *childNode2;
4566 xmlNode *childNode3;
4567 xmlChar *opt_out_flag = (xmlChar *)
"N";
4568 xmlChar *nsec3param_ttl = NULL ;
4569 xmlChar *share_keys_flag = (xmlChar *)
"N";
4570 xmlChar *man_roll_flag = (xmlChar *)
"N";
4571 xmlChar *rfc5011_flag = (xmlChar *)
"N";
4572 int standby_keys_flag = 0;
4573 xmlXPathContextPtr xpathCtx = NULL;
4574 xmlXPathObjectPtr xpathObj = NULL;
4575 xmlRelaxNGParserCtxtPtr rngpctx = NULL;
4576 xmlRelaxNGValidCtxtPtr rngctx = NULL;
4577 xmlRelaxNGPtr schema = NULL;
4580 xmlChar *node_expr = (
unsigned char*)
"//Policy";
4586 int algo_change = 0;
4588 char* changes_made = NULL;
4593 const char* rngfilename = OPENDNSSEC_SCHEMA_DIR
"/kasp.rng";
4594 char* kaspcheck_cmd = NULL;
4595 char* kaspcheck_cmd_version = NULL;
4597 StrAppend(&kaspcheck_cmd, ODS_EN_KASPCHECK);
4601 StrAppend(&kaspcheck_cmd_version, ODS_EN_KASPCHECK);
4602 StrAppend(&kaspcheck_cmd_version,
" --version > /dev/null");
4605 status = system(kaspcheck_cmd_version);
4608 status = system(kaspcheck_cmd);
4611 fprintf(stderr,
"ods-kaspcheck returned an error, please check your policy\n");
4613 StrFree(kaspcheck_cmd_version);
4619 fprintf(stderr,
"Couldn't run ods-kaspcheck, will carry on\n");
4623 StrFree(kaspcheck_cmd_version);
4626 doc = xmlParseFile(kasp_filename);
4628 printf(
"Error: unable to parse file \"%s\"\n", kasp_filename);
4633 rngdoc = xmlParseFile(rngfilename);
4634 if (rngdoc == NULL) {
4635 printf(
"Error: unable to parse file \"%s\"\n", rngfilename);
4640 rngpctx = xmlRelaxNGNewDocParserCtxt(rngdoc);
4641 if (rngpctx == NULL) {
4642 printf(
"Error: unable to create XML RelaxNGs parser context\n");
4647 schema = xmlRelaxNGParse(rngpctx);
4648 if (schema == NULL) {
4649 printf(
"Error: unable to parse a schema definition resource\n");
4654 rngctx = xmlRelaxNGNewValidCtxt(schema);
4655 if (rngctx == NULL) {
4656 printf(
"Error: unable to create RelaxNGs validation context based on the schema\n");
4661 status = xmlRelaxNGValidateDoc(rngctx,doc);
4663 printf(
"Error validating file \"%s\"\n", kasp_filename);
4669 if (policy == NULL) {
4670 printf(
"Malloc for policy struct failed");
4675 xpathCtx = xmlXPathNewContext(doc);
4676 if(xpathCtx == NULL) {
4683 xpathObj = xmlXPathEvalExpression(node_expr, xpathCtx);
4684 if(xpathObj == NULL) {
4685 xmlXPathFreeContext(xpathCtx);
4691 if (xpathObj->nodesetval) {
4697 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
4699 curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
4700 policy_name = (
char *) xmlGetProp(xpathObj->nodesetval->nodeTab[i], (
const xmlChar *)
"name");
4701 if (strlen(policy_name) == 0) {
4703 printf(
"Error extracting policy name from %s\n", kasp_filename);
4716 printf(
"Error: unable to read policy %s; skipping\n", policy_name);
4721 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Keys")) {
4722 childNode = curNode->children;
4724 if (xmlStrEqual(childNode->name, (
const xmlChar *)
"KSK")) {
4725 childNode2 = childNode->children;
4727 if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Algorithm")) {
4730 status =
StrStrtoi((
char *)xmlNodeGetContent(childNode2), &value);
4732 printf(
"Error extracting KSK algorithm for policy %s, exiting...", policy_name);
4738 printf(
"\n\nAlgorithm change attempted... details:\n");
4739 StrAppend(&changes_made,
"Algorithm changes made, details:");
4742 size = snprintf(tmp_change,
KSM_MSG_LENGTH,
"Policy: %s, KSK algorithm changed from %d to %d.", policy_name, policy->
ksk->
algorithm, value);
4745 printf(
"Error constructing log message for policy %s, exiting...", policy_name);
4748 printf(
"%s\n", tmp_change);
4754 childNode2 = childNode2->next;
4759 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"ZSK")) {
4760 childNode2 = childNode->children;
4762 if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Algorithm")) {
4765 status =
StrStrtoi((
char *)xmlNodeGetContent(childNode2), &value);
4767 printf(
"Error extracting ZSK algorithm for policy %s, exiting...", policy_name);
4773 printf(
"\n\nAlgorithm change attempted... details:\n");
4774 StrAppend(&changes_made,
"Algorithm changes made, details:");
4777 size = snprintf(tmp_change,
KSM_MSG_LENGTH,
"Policy: %s, ZSK algorithm changed from %d to %d.", policy_name, policy->
zsk->
algorithm, value);
4780 printf(
"Error constructing log message for policy %s, exiting...", policy_name);
4783 printf(
"%s\n", tmp_change);
4789 childNode2 = childNode2->next;
4794 childNode = childNode->next;
4797 curNode = curNode->next;
4809 if (algo_change == 1 && force_flag == 0) {
4810 printf(
"*WARNING* This will change the algorithms used as noted above. Algorithm rollover is _not_ supported by OpenDNSSEC and zones may break. Are you sure? [y/N] ");
4812 user_certain = getchar();
4813 if (user_certain !=
'y' && user_certain !=
'Y') {
4814 printf(
"\nOkay, quitting...\n");
4815 xmlXPathFreeContext(xpathCtx);
4828 #ifdef HAVE_OPENLOG_R
4833 #ifdef HAVE_SYSLOG_R
4834 syslog_r(LOG_INFO, &sdata,
"%s", changes_made);
4836 syslog(LOG_INFO,
"%s", changes_made);
4838 #ifdef HAVE_CLOSELOG_R
4849 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
4851 curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
4852 policy_name = (
char *) xmlGetProp(xpathObj->nodesetval->nodeTab[i], (
const xmlChar *)
"name");
4853 if (strlen(policy_name) == 0) {
4855 printf(
"Error extracting policy name from %s\n", kasp_filename);
4859 printf(
"Policy %s found\n", policy_name);
4861 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Description")) {
4862 policy_description = (
char *) xmlNodeGetContent(curNode);
4872 printf(
"Error: unable to read policy %s; skipping\n", policy_name);
4873 curNode = curNode->next;
4881 printf(
"Error: unable to update policy description for %s; skipping\n", policy_name);
4883 curNode = curNode->next;
4892 printf(
"Error: unable to insert policy %s; skipping\n", policy_name);
4894 curNode = curNode->next;
4900 printf(
"Error: unable to get policy id for %s; skipping\n", policy_name);
4901 curNode = curNode->next;
4907 else if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Signatures")) {
4908 childNode = curNode->children;
4910 if (xmlStrEqual(childNode->name, (
const xmlChar *)
"Resign")) {
4913 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"Refresh")) {
4916 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"Validity")) {
4917 childNode2 = childNode->children;
4919 if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Default")) {
4922 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Denial")) {
4925 childNode2 = childNode2->next;
4928 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"Jitter")) {
4931 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"InceptionOffset")) {
4934 childNode = childNode->next;
4937 else if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Denial")) {
4938 opt_out_flag = (xmlChar *)
"N";
4939 childNode = curNode->children;
4941 if (xmlStrEqual(childNode->name, (
const xmlChar *)
"NSEC3")) {
4945 printf(
"Error: unable to insert/update %s for policy\n",
"Denial version");
4947 childNode2 = childNode->children;
4949 if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"OptOut")) {
4950 opt_out_flag = (xmlChar *)
"Y";
4952 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Resalt")) {
4955 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"TTL")) {
4956 nsec3param_ttl = xmlNodeGetContent(childNode2);
4958 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Hash")) {
4959 childNode3 = childNode2->children;
4961 if (xmlStrEqual(childNode3->name, (
const xmlChar *)
"Algorithm")) {
4964 else if (xmlStrEqual(childNode3->name, (
const xmlChar *)
"Iterations")) {
4967 else if (xmlStrEqual(childNode3->name, (
const xmlChar *)
"Salt")) {
4970 childNode3 = childNode3->next;
4974 childNode2 = childNode2->next;
4978 if (nsec3param_ttl == NULL)
4979 nsec3param_ttl = (xmlChar *)
StrStrdup(
"PT0S");
4981 nsec3param_ttl = NULL;
4983 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"NSEC")) {
4986 printf(
"Error: unable to insert/update %s for policy\n",
"Denial version");
4989 childNode = childNode->next;
4992 else if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Keys")) {
4993 share_keys_flag = (xmlChar *)
"N";
4994 childNode = curNode->children;
4996 if (xmlStrEqual(childNode->name, (
const xmlChar *)
"TTL")) {
4999 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"RetireSafety")) {
5002 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"PublishSafety")) {
5005 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"ShareKeys")) {
5006 share_keys_flag = (xmlChar *)
"Y";
5008 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"Purge")) {
5012 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"KSK")) {
5013 man_roll_flag = (xmlChar *)
"N";
5014 rfc5011_flag = (xmlChar *)
"N";
5015 childNode2 = childNode->children;
5017 if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Algorithm")) {
5022 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Lifetime")) {
5025 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Repository")) {
5027 printf(
"Please either add the repository to conf.xml or remove the reference to it from kasp.xml\n");
5029 xmlFreeDoc(pol_doc);
5030 xmlXPathFreeContext(xpathCtx);
5031 xmlRelaxNGFree(schema);
5032 xmlRelaxNGFreeValidCtxt(rngctx);
5033 xmlRelaxNGFreeParserCtxt(rngpctx);
5041 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Standby")) {
5043 standby_keys_flag = 1;
5045 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"ManualRollover")) {
5046 man_roll_flag = (xmlChar *)
"Y";
5048 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"RFC5011")) {
5049 rfc5011_flag = (xmlChar *)
"Y";
5054 childNode2 = childNode2->next;
5059 if (standby_keys_flag == 0) {
5062 standby_keys_flag = 0;
5066 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"ZSK")) {
5067 man_roll_flag = (xmlChar *)
"N";
5068 childNode2 = childNode->children;
5070 if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Algorithm")) {
5075 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Lifetime")) {
5078 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Repository")) {
5080 printf(
"Please either add the repository to conf.xml or remove the reference to it from kasp.xml\n");
5082 xmlFreeDoc(pol_doc);
5083 xmlXPathFreeContext(xpathCtx);
5084 xmlRelaxNGFree(schema);
5085 xmlRelaxNGFreeValidCtxt(rngctx);
5086 xmlRelaxNGFreeParserCtxt(rngpctx);
5094 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Standby")) {
5096 standby_keys_flag = 1;
5098 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"ManualRollover")) {
5099 man_roll_flag = (xmlChar *)
"Y";
5101 childNode2 = childNode2->next;
5107 childNode = childNode->next;
5111 if (standby_keys_flag == 0) {
5114 standby_keys_flag = 0;
5119 else if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Zone")) {
5120 childNode = curNode->children;
5122 if (xmlStrEqual(childNode->name, (
const xmlChar *)
"PropagationDelay")) {
5125 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"SOA")) {
5126 childNode2 = childNode->children;
5128 if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"TTL")) {
5131 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Minimum")) {
5134 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Serial")) {
5137 childNode2 = childNode2->next;
5140 childNode = childNode->next;
5144 else if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Parent")) {
5145 childNode = curNode->children;
5147 if (xmlStrEqual(childNode->name, (
const xmlChar *)
"PropagationDelay")) {
5150 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"DS")) {
5151 childNode2 = childNode->children;
5153 if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"TTL")) {
5156 childNode2 = childNode2->next;
5159 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"SOA")) {
5160 childNode2 = childNode->children;
5162 if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"TTL")) {
5165 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Minimum")) {
5168 childNode2 = childNode2->next;
5171 childNode = childNode->next;
5175 curNode = curNode->next;
5186 xmlXPathFreeContext(xpathCtx);
5187 xmlRelaxNGFree(schema);
5188 xmlRelaxNGFreeValidCtxt(rngctx);
5189 xmlRelaxNGFreeParserCtxt(rngpctx);
5203 xmlDocPtr doc = NULL;
5204 xmlDocPtr rngdoc = NULL;
5207 xmlNode *childNode2;
5208 xmlXPathContextPtr xpathCtx = NULL;
5209 xmlXPathObjectPtr xpathObj = NULL;
5210 xmlRelaxNGParserCtxtPtr rngpctx = NULL;
5211 xmlRelaxNGValidCtxtPtr rngctx = NULL;
5212 xmlRelaxNGPtr schema = NULL;
5214 char* zone_name = NULL;
5215 char* policy_name = NULL;
5216 char* current_policy = NULL;
5217 char* current_signconf = NULL;
5218 char* current_input = NULL;
5219 char* current_output = NULL;
5220 char* current_in_type = NULL;
5221 char* current_out_type = NULL;
5224 int file_zone_count = 0;
5225 int db_zone_count = 0;
5239 xmlChar *node_expr = (
unsigned char*)
"//Zone";
5240 const char* rngfilename = OPENDNSSEC_SCHEMA_DIR
"/zonelist.rng";
5243 doc = xmlParseFile(zone_list_filename);
5245 printf(
"Error: unable to parse file \"%s\"\n", zone_list_filename);
5250 rngdoc = xmlParseFile(rngfilename);
5251 if (rngdoc == NULL) {
5252 printf(
"Error: unable to parse file \"%s\"\n", rngfilename);
5257 rngpctx = xmlRelaxNGNewDocParserCtxt(rngdoc);
5258 if (rngpctx == NULL) {
5259 printf(
"Error: unable to create XML RelaxNGs parser context\n");
5264 schema = xmlRelaxNGParse(rngpctx);
5265 if (schema == NULL) {
5266 printf(
"Error: unable to parse a schema definition resource\n");
5271 rngctx = xmlRelaxNGNewValidCtxt(schema);
5272 if (rngctx == NULL) {
5273 printf(
"Error: unable to create RelaxNGs validation context based on the schema\n");
5278 status = xmlRelaxNGValidateDoc(rngctx,doc);
5280 printf(
"Error validating file \"%s\"\n", zone_list_filename);
5285 xpathCtx = xmlXPathNewContext(doc);
5286 if(xpathCtx == NULL) {
5292 xpathObj = xmlXPathEvalExpression(node_expr, xpathCtx);
5293 if(xpathObj == NULL) {
5294 xmlXPathFreeContext(xpathCtx);
5299 if (xpathObj->nodesetval) {
5300 file_zone_count = xpathObj->nodesetval->nodeNr;
5302 printf(
"Error extracting zone count from %s\n", zone_list_filename);
5303 xmlXPathFreeContext(xpathCtx);
5309 zone_ids =
MemMalloc(file_zone_count *
sizeof(
int));
5311 if (xpathObj->nodesetval) {
5312 for (i = 0; i < file_zone_count; i++) {
5314 curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
5315 zone_name = (
char *) xmlGetProp(xpathObj->nodesetval->nodeTab[i], (
const xmlChar *)
"name");
5316 if (strlen(zone_name) == 0) {
5318 printf(
"Error extracting zone name from %s\n", zone_list_filename);
5331 printf(
"Zone %s found; ", zone_name);
5334 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Policy")) {
5335 current_policy = (
char *) xmlNodeGetContent(curNode);
5337 printf(
"policy set to %s\n", current_policy);
5340 if (policy_name == NULL || strcmp(current_policy, policy_name) != 0) {
5342 StrAppend(&policy_name, current_policy);
5346 printf(
"ERROR, can't find policy %s.\n", policy_name);
5353 else if (xmlStrEqual(curNode->name, (
const xmlChar *)
"SignerConfiguration")) {
5354 current_signconf = (
char *) xmlNodeGetContent(curNode);
5357 else if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Adapters")) {
5358 childNode = curNode->children;
5361 if (xmlStrEqual(childNode->name, (
const xmlChar *)
"Input")) {
5362 childNode2 = childNode->children;
5364 if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Adapter")) {
5365 current_input = (
char *) xmlNodeGetContent(childNode2);
5366 current_in_type = (
char *) xmlGetProp(childNode2, (
const xmlChar *)
"type");
5368 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"File")) {
5369 current_input = (
char *) xmlNodeGetContent(childNode2);
5370 current_in_type = (
char *) childNode2->name;
5372 childNode2 = childNode2->next;
5376 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"Output")) {
5377 childNode2 = childNode->children;
5379 if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Adapter")) {
5380 current_output = (
char *) xmlNodeGetContent(childNode2);
5381 current_out_type = (
char *) xmlGetProp(childNode2, (
const xmlChar *)
"type");
5383 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"File")) {
5384 current_output = (
char *) xmlNodeGetContent(childNode2);
5385 current_out_type = (
char *) childNode2->name;
5387 childNode2 = childNode2->next;
5390 childNode = childNode->next;
5393 curNode = curNode->next;
5399 status =
KsmImportZone(zone_name, policy_id, 0, &new_zone, current_signconf, current_input, current_output, current_in_type, current_out_type);
5402 printf(
"Error Importing zone %s; it already exists both with and without a trailing dot\n", zone_name);
5404 printf(
"Error Importing Zone %s\n", zone_name);
5410 if (new_zone == 1) {
5411 printf(
"Added zone %s to database\n", zone_name);
5417 printf(
"Error: unable to find a zone named \"%s\" in database\n", zone_name);
5418 printf(
"Error: Possibly two domains differ only by having a trailing dot or not?\n");
5424 zone_ids[i] = temp_id;
5432 xmlXPathFreeContext(xpathCtx);
5433 xmlRelaxNGFree(schema);
5434 xmlRelaxNGFreeValidCtxt(rngctx);
5435 xmlRelaxNGFreeParserCtxt(rngpctx);
5448 if (file_zone_count == db_zone_count) {
5453 else if (file_zone_count > db_zone_count) {
5454 printf(
"Failed to add all zones from zonelist\n");
5470 while (status == 0) {
5471 DbInt(row, 0, &temp_id);
5473 DbInt(row, 2, &policy_id);
5476 for (i = 0; i < db_zone_count; ++i) {
5477 if (temp_id == zone_ids[i]) {
5483 if (seen_zone == 0) {
5486 printf(
"Removing zone %s from database\n", zone_name);
5488 status =
KsmParameterInit(&result2,
"zones_share_keys",
"keys", policy_id);
5514 if ((shared.
value == 1 && temp_count == 1) || shared.
value == 0) {
5517 printf(
"Error: failed to mark keys as dead in database\n");
5552 int SetParamOnPolicy(
const xmlChar* new_value,
const char* name,
const char* category,
int current_value,
int policy_id,
int value_type)
5556 char* temp_char = (
char *)new_value;
5560 if (strlen(temp_char) != 0) {
5563 printf(
"Error: unable to convert interval %s to seconds, error: %i\n", temp_char, status);
5567 else if (status == -1) {
5568 printf(
"Info: converting %s to seconds; M interpreted as 31 days, Y interpreted as 365 days\n", temp_char);
5577 if (strncmp(temp_char,
"Y", 1) == 0) {
5587 printf(
"Error: unable to find repository %s\n", temp_char);
5597 printf(
"Error: unable to find serial type %s\n", temp_char);
5607 printf(
"Error: unable to find rollover scheme %s\n", temp_char);
5616 printf(
"Error: unable to convert %s to int\n", temp_char);
5626 if (value != current_value || current_value == 0) {
5629 printf(
"Error: unable to insert/update %s for policy\n", name);
5630 printf(
"Error: Is your database schema up to date?\n");
5636 if (strncmp(name,
"saltlength", 10) == 0) {
5639 printf(
"Error: unable to insert/update %s for policy\n", name);
5640 printf(
"Error: Is your database schema up to date?\n");
5651 if (policy == NULL) {
5652 printf(
"Error, no policy provided");
5689 policy->
ksk->
sm = 0;
5701 policy->
zsk->
sm = 0;
5738 if((from = fopen( orig_file,
"rb"))==NULL) {
5739 if (errno == ENOENT) {
5740 printf(
"File %s does not exist, nothing to backup\n", orig_file);
5744 printf(
"Cannot open source file.\n");
5750 if((to = fopen(backup_file,
"wb"))==NULL) {
5751 printf(
"Cannot open destination file, will not make backup.\n");
5757 while(!feof(from)) {
5760 printf(
"Error reading source file.\n");
5765 if(!feof(from)) fputc(ch, to);
5767 printf(
"Error writing destination file.\n");
5774 if(fclose(from)==EOF) {
5775 printf(
"Error closing source file.\n");
5780 if(fclose(to)==EOF) {
5781 printf(
"Error closing destination file.\n");
5799 get_db_details(
char** dbschema,
char** host,
char** port,
char** user,
char** password)
5804 xmlXPathContextPtr xpathCtx;
5805 xmlXPathObjectPtr xpathObj;
5806 xmlRelaxNGParserCtxtPtr rngpctx;
5807 xmlRelaxNGValidCtxtPtr rngctx;
5808 xmlRelaxNGPtr schema;
5809 xmlChar *litexpr = (
unsigned char*)
"//Configuration/Enforcer/Datastore/SQLite";
5810 xmlChar *mysql_host = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Host";
5811 xmlChar *mysql_port = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Host/@port";
5812 xmlChar *mysql_db = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Database";
5813 xmlChar *mysql_user = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Username";
5814 xmlChar *mysql_pass = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Password";
5818 char* temp_char = NULL;
5821 const char* rngfilename = OPENDNSSEC_SCHEMA_DIR
"/conf.rng";
5824 doc = xmlParseFile(
config);
5826 printf(
"Error: unable to parse file \"%s\"\n",
config);
5831 rngdoc = xmlParseFile(rngfilename);
5832 if (rngdoc == NULL) {
5833 printf(
"Error: unable to parse file \"%s\"\n", rngfilename);
5839 rngpctx = xmlRelaxNGNewDocParserCtxt(rngdoc);
5841 if (rngpctx == NULL) {
5842 printf(
"Error: unable to create XML RelaxNGs parser context\n");
5848 schema = xmlRelaxNGParse(rngpctx);
5849 xmlRelaxNGFreeParserCtxt(rngpctx);
5850 if (schema == NULL) {
5851 printf(
"Error: unable to parse a schema definition resource\n");
5857 rngctx = xmlRelaxNGNewValidCtxt(schema);
5858 if (rngctx == NULL) {
5859 printf(
"Error: unable to create RelaxNGs validation context based on the schema\n");
5860 xmlRelaxNGFree(schema);
5866 status = xmlRelaxNGValidateDoc(rngctx,doc);
5867 xmlRelaxNGFreeValidCtxt(rngctx);
5868 xmlRelaxNGFree(schema);
5870 printf(
"Error validating file \"%s\"\n",
config);
5877 xpathCtx = xmlXPathNewContext(doc);
5878 if(xpathCtx == NULL) {
5879 printf(
"Error: unable to create new XPath context\n");
5885 xpathObj = xmlXPathEvalExpression(litexpr, xpathCtx);
5886 if(xpathObj == NULL) {
5887 printf(
"Error: unable to evaluate xpath expression: %s\n", litexpr);
5888 xmlXPathFreeContext(xpathCtx);
5892 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
5894 temp_char = (
char *)xmlXPathCastToString(xpathObj);
5898 fprintf(stderr,
"SQLite database set to: %s\n", *dbschema);
5901 xmlXPathFreeObject(xpathObj);
5903 if (db_found == 0) {
5908 xpathObj = xmlXPathEvalExpression(mysql_host, xpathCtx);
5909 if(xpathObj == NULL) {
5910 printf(
"Error: unable to evaluate xpath expression: %s\n", mysql_host);
5911 xmlXPathFreeContext(xpathCtx);
5915 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
5916 temp_char = (
char *)xmlXPathCastToString(xpathObj);
5920 fprintf(stderr,
"MySQL database host set to: %s\n", *host);
5923 xmlXPathFreeObject(xpathObj);
5926 xpathObj = xmlXPathEvalExpression(mysql_port, xpathCtx);
5927 if(xpathObj == NULL) {
5928 printf(
"Error: unable to evaluate xpath expression: %s\n", mysql_port);
5929 xmlXPathFreeContext(xpathCtx);
5933 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
5934 temp_char = (
char *)xmlXPathCastToString(xpathObj);
5938 fprintf(stderr,
"MySQL database port set to: %s\n", *port);
5941 xmlXPathFreeObject(xpathObj);
5944 xpathObj = xmlXPathEvalExpression(mysql_db, xpathCtx);
5945 if(xpathObj == NULL) {
5946 printf(
"Error: unable to evaluate xpath expression: %s\n", mysql_db);
5947 xmlXPathFreeContext(xpathCtx);
5951 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
5952 temp_char = (
char *)xmlXPathCastToString(xpathObj);
5956 fprintf(stderr,
"MySQL database schema set to: %s\n", *dbschema);
5961 xmlXPathFreeObject(xpathObj);
5964 xpathObj = xmlXPathEvalExpression(mysql_user, xpathCtx);
5965 if(xpathObj == NULL) {
5966 printf(
"Error: unable to evaluate xpath expression: %s\n", mysql_user);
5967 xmlXPathFreeContext(xpathCtx);
5971 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
5972 temp_char = (
char *)xmlXPathCastToString(xpathObj);
5976 fprintf(stderr,
"MySQL database user set to: %s\n", *user);
5981 xmlXPathFreeObject(xpathObj);
5984 xpathObj = xmlXPathEvalExpression(mysql_pass, xpathCtx);
5985 if(xpathObj == NULL) {
5986 printf(
"Error: unable to evaluate xpath expression: %s\n", mysql_pass);
5987 xmlXPathFreeContext(xpathCtx);
5992 temp_char = (
char *)xmlXPathCastToString(xpathObj);
5995 xmlXPathFreeObject(xpathObj);
5998 fprintf(stderr,
"MySQL database password set\n");
6003 xmlXPathFreeContext(xpathCtx);
6008 printf(
"Error: unable to find complete database connection expression\n");
6014 printf(
"Error: Config file %s specifies database type %s but system is compiled to use %s\n",
config, (db_found==1) ?
"MySQL" :
"sqlite3", (db_found==2) ?
"MySQL" :
"sqlite3");
6028 xmlTextReaderPtr reader = NULL;
6029 xmlDocPtr doc = NULL;
6030 xmlXPathContextPtr xpathCtx = NULL;
6031 xmlXPathObjectPtr xpathObj = NULL;
6033 char* temp_char = NULL;
6034 char* tag_name = NULL;
6036 xmlChar *zonelist_expr = (
unsigned char*)
"//Common/ZoneListFile";
6039 reader = xmlNewTextReaderFilename(
config);
6040 if (reader != NULL) {
6041 ret = xmlTextReaderRead(reader);
6043 tag_name = (
char*) xmlTextReaderLocalName(reader);
6045 if (strncmp(tag_name,
"Common", 6) == 0
6046 && xmlTextReaderNodeType(reader) == 1) {
6049 xmlTextReaderExpand(reader);
6050 doc = xmlTextReaderCurrentDoc(reader);
6052 printf(
"Error: can not read Common section\n");
6054 ret = xmlTextReaderRead(reader);
6058 xpathCtx = xmlXPathNewContext(doc);
6059 if(xpathCtx == NULL) {
6060 printf(
"Error: can not create XPath context for Common section\n");
6062 ret = xmlTextReaderRead(reader);
6067 xpathObj = xmlXPathEvalExpression(zonelist_expr, xpathCtx);
6068 if(xpathObj == NULL) {
6069 printf(
"Error: unable to evaluate xpath expression: %s\n", zonelist_expr);
6071 ret = xmlTextReaderRead(reader);
6074 *zone_list_filename = NULL;
6075 temp_char = (
char *)xmlXPathCastToString(xpathObj);
6076 xmlXPathFreeObject(xpathObj);
6077 StrAppend(zone_list_filename, temp_char);
6079 printf(
"zonelist filename set to %s.\n", *zone_list_filename);
6082 ret = xmlTextReaderRead(reader);
6085 xmlFreeTextReader(reader);
6087 printf(
"%s : failed to parse\n",
config);
6091 printf(
"Unable to open %s\n",
config);
6095 xmlXPathFreeContext(xpathCtx);
6105 const char *zone_name,
6106 const char *policy_name,
6107 const char *sig_conf_name,
6108 const char *input_name,
6109 const char *output_name,
6110 const char *input_type,
6111 const char *output_type)
6115 xmlNodePtr newzonenode;
6116 xmlNodePtr newadaptnode;
6117 xmlNodePtr newinputnode;
6118 xmlNodePtr newinadnode;
6119 xmlNodePtr newoutputnode;
6120 xmlNodePtr newoutadnode;
6121 doc = xmlParseFile(docname);
6123 fprintf(stderr,
"Document not parsed successfully. \n");
6126 cur = xmlDocGetRootElement(doc);
6128 fprintf(stderr,
"empty document\n");
6132 if (xmlStrcmp(cur->name, (
const xmlChar *)
"ZoneList")) {
6133 fprintf(stderr,
"document of the wrong type, root node != %s",
"ZoneList");
6137 newzonenode = xmlNewTextChild(cur, NULL, (
const xmlChar *)
"Zone", NULL);
6138 (void) xmlNewProp(newzonenode, (
const xmlChar *)
"name", (
const xmlChar *)zone_name);
6140 (void) xmlNewTextChild (newzonenode, NULL, (
const xmlChar *)
"Policy", (
const xmlChar *)policy_name);
6142 (void) xmlNewTextChild (newzonenode, NULL, (
const xmlChar *)
"SignerConfiguration", (
const xmlChar *)sig_conf_name);
6144 newadaptnode = xmlNewChild (newzonenode, NULL, (
const xmlChar *)
"Adapters", NULL);
6146 newinputnode = xmlNewChild (newadaptnode, NULL, (
const xmlChar *)
"Input", NULL);
6148 newinadnode = xmlNewTextChild (newinputnode, NULL, (
const xmlChar *)
"Adapter", (
const xmlChar *)input_name);
6149 (void) xmlNewProp(newinadnode, (
const xmlChar *)
"type", (
const xmlChar *)input_type);
6151 newoutputnode = xmlNewChild (newadaptnode, NULL, (
const xmlChar *)
"Output", NULL);
6153 newoutadnode = xmlNewTextChild (newoutputnode, NULL, (
const xmlChar *)
"Adapter", (
const xmlChar *)output_name);
6154 (void) xmlNewProp(newoutadnode, (
const xmlChar *)
"type", (
const xmlChar *)output_type);
6160 const char *zone_name)
6166 doc = xmlParseFile(docname);
6168 fprintf(stderr,
"Document not parsed successfully. \n");
6171 root = xmlDocGetRootElement(doc);
6173 fprintf(stderr,
"empty document\n");
6177 if (xmlStrcmp(root->name, (
const xmlChar *)
"ZoneList")) {
6178 fprintf(stderr,
"document of the wrong type, root node != %s",
"ZoneList");
6184 if (all_flag == 1) {
6185 cur = root->children;
6191 cur = root->children;
6197 for(cur = root->children; cur != NULL; cur = cur->next)
6200 if (xmlStrcmp( xmlGetProp(cur, (xmlChar *)
"name"), (
const xmlChar *) zone_name) == 0)
6204 cur = root->children;
6219 xmlChar *polChar = NULL;
6220 xmlChar *propChar = NULL;
6226 doc = xmlParseFile(docname);
6228 fprintf(stderr,
"Document not parsed successfully. \n");
6231 root = xmlDocGetRootElement(doc);
6233 fprintf(stderr,
"empty document\n");
6237 if (xmlStrcmp(root->name, (
const xmlChar *)
"ZoneList")) {
6238 fprintf(stderr,
"document of the wrong type, root node != %s",
"ZoneList");
6244 for(cur = root->children; cur != NULL; cur = cur->next)
6246 if (xmlStrcmp( cur->name, (
const xmlChar *)
"Zone") == 0) {
6247 propChar = xmlGetProp(cur, (xmlChar *)
"name");
6248 printf(
"Found Zone: %s", propChar);
6254 printf(
" (zone not in database)");
6257 zone_ids[i] = temp_id;
6262 for(pol = cur->children; pol != NULL; pol = pol->next)
6264 if (xmlStrcmp( pol->name, (
const xmlChar *)
"Policy") == 0)
6266 polChar = xmlNodeGetContent(pol);
6267 printf(
"; on policy %s\n", polChar);
6286 xmlNodePtr policy_node;
6287 xmlNodePtr signatures_node;
6288 xmlNodePtr validity_node;
6289 xmlNodePtr denial_node;
6290 xmlNodePtr nsec_node;
6291 xmlNodePtr hash_node;
6292 xmlNodePtr salt_node;
6293 xmlNodePtr keys_node;
6294 xmlNodePtr ksk_node;
6295 xmlNodePtr ksk_alg_node;
6296 xmlNodePtr zsk_node;
6297 xmlNodePtr zsk_alg_node;
6298 xmlNodePtr zone_node;
6299 xmlNodePtr zone_soa_node;
6300 xmlNodePtr parent_node;
6301 xmlNodePtr parent_ds_node;
6302 xmlNodePtr parent_soa_node;
6306 root = xmlDocGetRootElement(doc);
6308 fprintf(stderr,
"empty document\n");
6311 if (xmlStrcmp(root->name, (
const xmlChar *)
"KASP")) {
6312 fprintf(stderr,
"document of the wrong type, root node != %s",
"KASP");
6316 policy_node = xmlNewTextChild(root, NULL, (
const xmlChar *)
"Policy", NULL);
6317 (void) xmlNewProp(policy_node, (
const xmlChar *)
"name", (
const xmlChar *)policy->
name);
6318 (void) xmlNewTextChild(policy_node, NULL, (
const xmlChar *)
"Description", (
const xmlChar *)policy->
description);
6321 signatures_node = xmlNewTextChild(policy_node, NULL, (
const xmlChar *)
"Signatures", NULL);
6323 (void) xmlNewTextChild(signatures_node, NULL, (
const xmlChar *)
"Resign", (
const xmlChar *)temp_time);
6325 (void) xmlNewTextChild(signatures_node, NULL, (
const xmlChar *)
"Refresh", (
const xmlChar *)temp_time);
6326 validity_node = xmlNewTextChild(signatures_node, NULL, (
const xmlChar *)
"Validity", NULL);
6328 (void) xmlNewTextChild(validity_node, NULL, (
const xmlChar *)
"Default", (
const xmlChar *)temp_time);
6330 (void) xmlNewTextChild(validity_node, NULL, (
const xmlChar *)
"Denial", (
const xmlChar *)temp_time);
6331 snprintf(temp_time, 32,
"PT%dS", policy->
signer->
jitter);
6332 (void) xmlNewTextChild(signatures_node, NULL, (
const xmlChar *)
"Jitter", (
const xmlChar *)temp_time);
6334 (void) xmlNewTextChild(signatures_node, NULL, (
const xmlChar *)
"InceptionOffset", (
const xmlChar *)temp_time);
6337 denial_node = xmlNewTextChild(policy_node, NULL, (
const xmlChar *)
"Denial", NULL);
6340 (void) xmlNewTextChild(denial_node, NULL, (
const xmlChar *)
"NSEC", NULL);
6344 nsec_node = xmlNewTextChild(denial_node, NULL, (
const xmlChar *)
"NSEC3", NULL);
6346 snprintf(temp_time, 32,
"PT%dS", policy->
denial->
ttl);
6347 (void) xmlNewTextChild(nsec_node, NULL, (
const xmlChar *)
"TTL", (
const xmlChar *)temp_time);
6351 (void) xmlNewTextChild(nsec_node, NULL, (
const xmlChar *)
"OptOut", NULL);
6353 snprintf(temp_time, 32,
"PT%dS", policy->
denial->
resalt);
6354 (void) xmlNewTextChild(nsec_node, NULL, (
const xmlChar *)
"Resalt", (
const xmlChar *)temp_time);
6355 hash_node = xmlNewTextChild(nsec_node, NULL, (
const xmlChar *)
"Hash", NULL);
6357 (void) xmlNewTextChild(hash_node, NULL, (
const xmlChar *)
"Algorithm", (
const xmlChar *)temp_time);
6359 (void) xmlNewTextChild(hash_node, NULL, (
const xmlChar *)
"Iterations", (
const xmlChar *)temp_time);
6361 salt_node = xmlNewTextChild(hash_node, NULL, (
const xmlChar *)
"Salt", NULL);
6362 (void) xmlNewProp(salt_node, (
const xmlChar *)
"length", (
const xmlChar *)temp_time);
6366 keys_node = xmlNewTextChild(policy_node, NULL, (
const xmlChar *)
"Keys", NULL);
6367 snprintf(temp_time, 32,
"PT%dS", policy->
keys->
ttl);
6368 (void) xmlNewTextChild(keys_node, NULL, (
const xmlChar *)
"TTL", (
const xmlChar *)temp_time);
6370 (void) xmlNewTextChild(keys_node, NULL, (
const xmlChar *)
"RetireSafety", (
const xmlChar *)temp_time);
6372 (void) xmlNewTextChild(keys_node, NULL, (
const xmlChar *)
"PublishSafety", (
const xmlChar *)temp_time);
6375 (void) xmlNewTextChild(keys_node, NULL, (
const xmlChar *)
"ShareKeys", NULL);
6378 snprintf(temp_time, 32,
"PT%dS", policy->
keys->
purge);
6379 (void) xmlNewTextChild(keys_node, NULL, (
const xmlChar *)
"Purge", (
const xmlChar *)temp_time);
6383 ksk_node = xmlNewTextChild(keys_node, NULL, (
const xmlChar *)
"KSK", NULL);
6385 ksk_alg_node = xmlNewTextChild(ksk_node, NULL, (
const xmlChar *)
"Algorithm", (
const xmlChar *)temp_time);
6386 snprintf(temp_time, 32,
"%d", policy->
ksk->
bits);
6387 (void) xmlNewProp(ksk_alg_node, (
const xmlChar *)
"length", (
const xmlChar *)temp_time);
6388 snprintf(temp_time, 32,
"PT%dS", policy->
ksk->
lifetime);
6389 (void) xmlNewTextChild(ksk_node, NULL, (
const xmlChar *)
"Lifetime", (
const xmlChar *)temp_time);
6390 (void) xmlNewTextChild(ksk_node, NULL, (
const xmlChar *)
"Repository", (
const xmlChar *)policy->
ksk->
sm_name);
6392 (void) xmlNewTextChild(ksk_node, NULL, (
const xmlChar *)
"Standby", (
const xmlChar *)temp_time);
6395 (void) xmlNewTextChild(ksk_node, NULL, (
const xmlChar *)
"ManualRollover", NULL);
6399 (void) xmlNewTextChild(ksk_node, NULL, (
const xmlChar *)
"RFC5011", NULL);
6407 zsk_node = xmlNewTextChild(keys_node, NULL, (
const xmlChar *)
"ZSK", NULL);
6409 zsk_alg_node = xmlNewTextChild(zsk_node, NULL, (
const xmlChar *)
"Algorithm", (
const xmlChar *)temp_time);
6410 snprintf(temp_time, 32,
"%d", policy->
zsk->
bits);
6411 (void) xmlNewProp(zsk_alg_node, (
const xmlChar *)
"length", (
const xmlChar *)temp_time);
6412 snprintf(temp_time, 32,
"PT%dS", policy->
zsk->
lifetime);
6413 (void) xmlNewTextChild(zsk_node, NULL, (
const xmlChar *)
"Lifetime", (
const xmlChar *)temp_time);
6414 (void) xmlNewTextChild(zsk_node, NULL, (
const xmlChar *)
"Repository", (
const xmlChar *)policy->
zsk->
sm_name);
6416 (void) xmlNewTextChild(zsk_node, NULL, (
const xmlChar *)
"Standby", (
const xmlChar *)temp_time);
6419 (void) xmlNewTextChild(zsk_node, NULL, (
const xmlChar *)
"ManualRollover", NULL);
6423 zone_node = xmlNewTextChild(policy_node, NULL, (
const xmlChar *)
"Zone", NULL);
6425 (void) xmlNewTextChild(zone_node, NULL, (
const xmlChar *)
"PropagationDelay", (
const xmlChar *)temp_time);
6426 zone_soa_node = xmlNewTextChild(zone_node, NULL, (
const xmlChar *)
"SOA", NULL);
6427 snprintf(temp_time, 32,
"PT%dS", policy->
zone->
soa_ttl);
6428 (void) xmlNewTextChild(zone_soa_node, NULL, (
const xmlChar *)
"TTL", (
const xmlChar *)temp_time);
6429 snprintf(temp_time, 32,
"PT%dS", policy->
zone->
soa_min);
6430 (void) xmlNewTextChild(zone_soa_node, NULL, (
const xmlChar *)
"Minimum", (
const xmlChar *)temp_time);
6434 parent_node = xmlNewTextChild(policy_node, NULL, (
const xmlChar *)
"Parent", NULL);
6436 (void) xmlNewTextChild(parent_node, NULL, (
const xmlChar *)
"PropagationDelay", (
const xmlChar *)temp_time);
6437 parent_ds_node = xmlNewTextChild(parent_node, NULL, (
const xmlChar *)
"DS", NULL);
6438 snprintf(temp_time, 32,
"PT%dS", policy->
parent->
ds_ttl);
6439 (void) xmlNewTextChild(parent_ds_node, NULL, (
const xmlChar *)
"TTL", (
const xmlChar *)temp_time);
6440 parent_soa_node = xmlNewTextChild(parent_node, NULL, (
const xmlChar *)
"SOA", NULL);
6442 (void) xmlNewTextChild(parent_soa_node, NULL, (
const xmlChar *)
"TTL", (
const xmlChar *)temp_time);
6444 (void) xmlNewTextChild(parent_soa_node, NULL, (
const xmlChar *)
"Minimum", (
const xmlChar *)temp_time);
6453 const char *policy_name)
6459 doc = xmlParseFile(docname);
6461 fprintf(stderr,
"Document not parsed successfully. \n");
6464 root = xmlDocGetRootElement(doc);
6466 fprintf(stderr,
"empty document\n");
6470 if (xmlStrcmp(root->name, (
const xmlChar *)
"KASP")) {
6471 fprintf(stderr,
"document of the wrong type, root node != %s",
"KASP");
6478 for(cur = root->children; cur != NULL; cur = cur->next)
6481 if (xmlStrcmp( xmlGetProp(cur, (xmlChar *)
"name"), (
const xmlChar *) policy_name) == 0)
6485 cur = root->children;
6501 fprintf(stdout,
"KSK:");
6505 fprintf(stdout,
"ZSK:");
6507 fprintf(stdout,
" %s Retired\n", key_data->
location);
6519 fprintf(stderr,
"%s\n", format);
6546 char* temp_zone = NULL;
6549 char* temp_publish = NULL;
6550 char* temp_ready = NULL;
6551 char* temp_active = NULL;
6552 char* temp_retire = NULL;
6553 char* temp_dead = NULL;
6554 char* temp_loc = NULL;
6555 char* temp_hsm = NULL;
6559 bool bool_temp_zone =
false;
6562 char *case_keystate = NULL;
6563 char *case_keytype = NULL;
6566 hsm_key_t *key = NULL;
6567 ldns_rr *dnskey_rr = NULL;
6568 hsm_sign_params_t *sign_params = NULL;
6572 status = hsm_open(
config, hsm_prompt_pin);
6574 hsm_print_error(NULL);
6581 printf(
"Error: --keystate and --all option cannot be given together\n");
6586 StrAppend(&sql,
"select z.name, k.keytype, k.state, k.ready, k.active, k.retire, k.dead, k.location, s.name, k.algorithm, k.size, k.publish from securitymodules s, KEYDATA_VIEW k left join zones z on k.zone_id = z.id where s.id = k.securitymodule_id ");
6587 if (zone_id != -1) {
6597 if (strncmp(case_keystate,
"GENERATE", 8) == 0 || strncmp(
o_keystate,
"1", 1) == 0) {
6600 else if (strncmp(case_keystate,
"KEYPUBLISH", 10) == 0 || strncmp(
o_keystate,
"10", 2) == 0) {
6603 else if (strncmp(case_keystate,
"PUBLISH", 7) == 0 || strncmp(
o_keystate,
"2", 1) == 0) {
6606 else if (strncmp(case_keystate,
"READY", 5) == 0 || strncmp(
o_keystate,
"3", 1) == 0) {
6609 else if (strncmp(case_keystate,
"ACTIVE", 6) == 0 || strncmp(
o_keystate,
"4", 1) == 0) {
6612 else if (strncmp(case_keystate,
"RETIRE", 6) == 0 || strncmp(
o_keystate,
"5", 1) == 0) {
6615 else if (strncmp(case_keystate,
"DEAD", 4) == 0 || strncmp(
o_keystate,
"6", 1) == 0) {
6618 else if (strncmp(case_keystate,
"DSSUB", 5) == 0 || strncmp(
o_keystate,
"7", 1) == 0) {
6621 else if (strncmp(case_keystate,
"DSPUBLISH", 9) == 0 || strncmp(
o_keystate,
"8", 1) == 0) {
6624 else if (strncmp(case_keystate,
"DSREADY", 7) == 0 || strncmp(
o_keystate,
"9", 1) == 0) {
6628 printf(
"Error: Unrecognised state %s; should be one of GENERATE, PUBLISH, READY, ACTIVE, RETIRE, DEAD, DSSUB, DSPUBLISH, DSREADY or KEYPUBLISH\n",
o_keystate);
6634 if (state_id != -1){
6653 if (strncmp(case_keytype,
"KSK", 3) == 0 || strncmp(
o_keytype,
"257", 3) == 0) {
6656 else if (strncmp(case_keytype,
"ZSK", 3) == 0 || strncmp(
o_keytype,
"256", 3) == 0) {
6660 printf(
"Error: Unrecognised keytype %s; should be one of KSK or ZSK\n",
o_keytype);
6675 if (verbose_flag == 1) {
6676 printf(
"Zone: Keytype: State: Date of next transition (to): Size: Algorithm: CKA_ID: Repository: Keytag:\n");
6679 printf(
"Zone: Keytype: State: Date of next transition:\n");
6681 while (status == 0) {
6684 DbInt(row, 1, &temp_type);
6685 DbInt(row, 2, &temp_state);
6692 DbInt(row, 9, &temp_alg);
6693 DbInt(row, 10, &temp_size);
6695 if (temp_zone == NULL){
6696 bool_temp_zone =
true;
6697 temp_zone =
"NOT ALLOCATED";
6699 bool_temp_zone =
false;
6705 printf(
"%-31s %-13s %-9s %-20s", temp_zone,
"",
"generate",
"(not scheduled)");
6707 printf(
"(publish) ");
6714 printf(
"%-31s %-13s %-9s %-20s", temp_zone, (temp_type ==
KSM_TYPE_KSK) ?
"KSK" :
"ZSK",
KsmKeywordStateValueToName(temp_state), (temp_publish== NULL) ?
"(not scheduled)" : temp_publish);
6716 printf(
"(publish) ");
6731 printf(
"(active) ");
6736 printf(
"%-31s %-13s %-9s %-20s", temp_zone, (temp_type ==
KSM_TYPE_KSK) ?
"KSK" :
"ZSK",
KsmKeywordStateValueToName(temp_state), (temp_retire == NULL) ?
"(not scheduled)" : temp_retire);
6738 printf(
"(retire) ");
6753 printf(
"(deleted) ");
6766 printf(
"%-31s %-13s %-9s %-20s", temp_zone,
"KSK",
KsmKeywordStateValueToName(temp_state), (temp_ready == NULL) ?
"(not scheduled)" : temp_ready);
6768 printf(
"(dsready) ");
6775 printf(
"(keypub) ");
6780 printf(
"%-31s %-13s %-9s %-20s", temp_zone,
"KSK",
KsmKeywordStateValueToName(temp_state), (temp_active == NULL) ?
"(not scheduled)" : temp_active);
6782 printf(
"(active) ");
6787 if (done_row == 1 && verbose_flag == 1) {
6788 printf(
"%-7d %-12d", temp_size, temp_alg);
6789 key = hsm_find_key_by_id(NULL, temp_loc);
6791 printf(
"%-33s %s NOT IN repository\n", temp_loc, temp_hsm);
6792 }
else if (bool_temp_zone ==
true){
6793 printf(
"%-33s %s\n",temp_loc,temp_hsm);
6795 sign_params = hsm_sign_params_new();
6796 sign_params->owner = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, temp_zone);
6797 sign_params->algorithm = temp_alg;
6798 sign_params->flags = LDNS_KEY_ZONE_KEY;
6800 sign_params->flags += LDNS_KEY_SEP_KEY;
6802 dnskey_rr = hsm_get_dnskey(NULL, key, sign_params);
6803 sign_params->keytag = ldns_calc_keytag(dnskey_rr);
6805 printf(
"%-33s %-33s %d\n", temp_loc, temp_hsm, sign_params->keytag);
6807 hsm_sign_params_free(sign_params);
6811 else if (done_row == 1) {
6829 if (bool_temp_zone ==
false){
6839 if (dnskey_rr != NULL) {
6840 ldns_rr_free(dnskey_rr);
6882 char* temp_loc = NULL;
6885 int done_something = 0;
6888 hsm_key_t *key = NULL;
6890 if ((zone_id == -1 && policy_id == -1) ||
6891 (zone_id != -1 && policy_id != -1)){
6892 printf(
"Please provide either a zone OR a policy to key purge\n");
6898 status = hsm_open(
config, hsm_prompt_pin);
6900 hsm_print_error(NULL);
6905 StrAppend(&sql,
"select distinct id, location from KEYDATA_VIEW where state = 6 ");
6906 if (zone_id != -1) {
6911 if (policy_id != -1) {
6922 while (status == 0) {
6924 DbInt(row, 0, &temp_id);
6984 key = hsm_find_key_by_id(NULL, temp_loc);
6987 printf(
"Key not found: %s\n", temp_loc);
6995 status = hsm_remove_key(NULL, key);
7000 printf(
"Key remove successful: %s\n", temp_loc);
7002 printf(
"Key remove failed: %s\n", temp_loc);
7024 if (done_something == 0) {
7025 printf(
"No keys to purge.\n");
7045 hsm_ctx_t *ctx = NULL;
7050 hsm_key_t *key = NULL;
7051 char *hsm_error_message = NULL;
7053 int ksks_needed = 0;
7054 int zsks_needed = 0;
7055 int ksks_in_queue = 0;
7056 int zsks_in_queue = 0;
7059 unsigned int current_count = 0;
7065 int ksks_created = 0;
7069 FILE* lock_fd = NULL;
7077 printf(
"Failed to connect to database\n");
7083 if (policy == NULL) {
7084 printf(
"Malloc for policy struct failed\n");
7090 printf(
"Please provide a policy name with the --policy option\n");
7096 printf(
"Please provide an interval with the --interval option\n");
7109 printf(
"Error: unable to read policy %s from database\n",
o_policy);
7115 printf(
"Error: policy %s doesn't exist in database\n",
o_policy);
7122 printf(
"Key sharing is On\n");
7124 printf(
"Key sharing is Off\n");
7129 printf(
"Error: unable to convert Interval %s to seconds, error: ",
o_interval);
7132 printf(
"invalid interval-type.\n");
7135 printf(
"unable to translate string.\n");
7138 printf(
"interval too long to be an int. E.g. Maximum is ~68 years on a system with 32-bit integers.\n");
7141 printf(
"invalid pointers or text string NULL.\n");
7144 printf(
"unknown\n");
7150 else if (status == -1) {
7151 printf(
"Info: converting %s to seconds; M interpreted as 31 days, Y interpreted as 365 days\n",
o_interval);
7155 status = hsm_open(
config, hsm_prompt_pin);
7157 hsm_error_message = hsm_get_error(ctx);
7158 if (hsm_error_message) {
7159 printf(
"%s\n", hsm_error_message);
7160 free(hsm_error_message);
7166 printf(
"hsm_open() result: HSM error\n");
7168 case HSM_PIN_INCORRECT:
7169 printf(
"hsm_open() result: incorrect PIN\n");
7171 case HSM_CONFIG_FILE_ERROR:
7172 printf(
"hsm_open() result: config file error\n");
7174 case HSM_REPOSITORY_NOT_FOUND:
7175 printf(
"hsm_open() result: repository not found\n");
7177 case HSM_NO_REPOSITORIES:
7178 printf(
"hsm_open() result: no repositories\n");
7181 printf(
"hsm_open() result: %d", status);
7188 printf(
"HSM opened successfully.\n");
7189 ctx = hsm_create_context();
7194 if (rightnow == NULL) {
7195 printf(
"Couldn't turn \"now\" into a date, quitting...\n");
7216 printf(
"Could not count zones on policy %s\n", policy->
name);
7219 hsm_destroy_context(ctx);
7225 printf(
"Info: %d zone(s) found on policy \"%s\"\n", zone_count, policy->
name);
7234 printf(
"Error: Unable to convert zonetotal \"%s\"; to an integer\n",
o_zonetotal);
7241 printf(
"Error: zonetotal \"%s\"; should be numeric only\n",
o_zonetotal);
7248 if (zone_count < 1) {
7249 printf(
"Error: zonetotal parameter value of %d is invalid - the value must be greater than 0\n", zone_count);
7255 printf(
"Info: Keys will actually be generated for a total of %d zone(s) as specified by zone total parameter\n", zone_count);
7259 if (zone_count == 0) {
7260 printf(
"No zones on policy %s, skipping...\n", policy->
name);
7263 hsm_destroy_context(ctx);
7274 printf(
"Could not predict ksk requirement for next interval for %s\n", policy->
name);
7283 printf(
"Could not count current ksk numbers for policy %s\n", policy->
name);
7291 new_ksks = ksks_needed - ksks_in_queue;
7292 printf(
"%d new KSK(s) (%d bits) need to be created for policy %s: keys_to_generate(%d) = keys_needed(%d) - keys_available(%d).\n", new_ksks, policy->
ksk->
bits, policy->
name, new_ksks, ksks_needed, ksks_in_queue);
7298 printf(
"Could not predict zsk requirement for next interval for %s\n", policy->
name);
7307 printf(
"Could not count current zsk numbers for policy %s\n", policy->
name);
7318 if (new_ksks >= 0) {
7323 zsks_in_queue -= ksks_needed;
7327 new_zsks = zsks_needed - zsks_in_queue;
7328 printf(
"%d new ZSK(s) (%d bits) need to be created for policy %s: keys_to_generate(%d) = keys_needed(%d) - keys_available(%d).\n", new_zsks, policy->
zsk->
bits, policy->
name, new_zsks, zsks_needed, zsks_in_queue);
7334 if (policy->
ksk->
sm_capacity != 0 && (new_ksks + new_zsks) > 0) {
7335 current_count = hsm_count_keys_repository(ctx, policy->
ksk->
sm_name);
7337 printf(
"Repository %s is full, cannot create more keys for policy %s\n", policy->
ksk->
sm_name, policy->
name);
7341 printf(
"Repository %s is nearly full, will create %lu KSKs for policy %s (reduced from %d)\n", policy->
ksk->
sm_name, policy->
ksk->
sm_capacity - current_count, policy->
name, new_ksks);
7344 else if (current_count + new_ksks + new_zsks > policy->
ksk->
sm_capacity) {
7345 printf(
"Repository %s is nearly full, will create %lu ZSKs for policy %s (reduced from %d)\n", policy->
ksk->
sm_name, policy->
ksk->
sm_capacity - current_count, policy->
name, new_ksks);
7354 current_count = hsm_count_keys_repository(ctx, policy->
ksk->
sm_name);
7356 printf(
"Repository %s is full, cannot create more KSKs for policy %s\n", policy->
ksk->
sm_name, policy->
name);
7360 printf(
"Repository %s is nearly full, will create %lu KSKs for policy %s (reduced from %d)\n", policy->
ksk->
sm_name, policy->
ksk->
sm_capacity - current_count, policy->
name, new_ksks);
7367 current_count = hsm_count_keys_repository(ctx, policy->
zsk->
sm_name);
7369 printf(
"Repository %s is full, cannot create more ZSKs for policy %s\n", policy->
zsk->
sm_name, policy->
name);
7373 printf(
"Repository %s is nearly full, will create %lu ZSKs for policy %s (reduced from %d)\n", policy->
zsk->
sm_name, policy->
zsk->
sm_capacity - current_count, policy->
name, new_zsks);
7380 if (new_ksks <= 0 && new_zsks <= 0) {
7381 printf(
"No keys need to be created, quitting...\n");
7384 hsm_destroy_context(ctx);
7386 status = hsm_close();
7387 printf(
"all done! hsm_close result: %d\n", status);
7394 if (!auto_accept_flag) {
7395 printf(
"*WARNING* This will create %d KSKs (%d bits) and %d ZSKs (%d bits)\nAre you sure? [y/N] \n", new_ksks >= 0 ? new_ksks : 0, policy->
ksk->
bits, new_zsks >= 0 ? new_zsks : 0, policy->
zsk->
bits);
7397 user_certain = getchar();
7398 if (user_certain !=
'y' && user_certain !=
'Y') {
7399 printf(
"Okay, quitting...\n");
7402 hsm_destroy_context(ctx);
7404 status = hsm_close();
7405 printf(
"all done! hsm_close result: %d\n", status);
7413 for (i=new_ksks ; i > 0 ; i--){
7414 if (hsm_supported_algorithm(policy->
ksk->
algorithm) == 0) {
7419 printf(
"Created key in repository %s\n", policy->
ksk->
sm_name);
7422 printf(
"Error creating key in repository %s\n", policy->
ksk->
sm_name);
7423 hsm_error_message = hsm_get_error(ctx);
7424 if (hsm_error_message) {
7425 printf(
"%s\n", hsm_error_message);
7426 free(hsm_error_message);
7433 id = hsm_get_key_id(ctx, key);
7437 printf(
"Error creating key in Database\n");
7438 hsm_error_message = hsm_get_error(ctx);
7439 if (hsm_error_message) {
7440 printf(
"%s\n", hsm_error_message);
7441 free(hsm_error_message);
7448 printf(
"Created KSK size: %i, alg: %i with id: %s in repository: %s and database.\n", policy->
ksk->
bits,
7452 printf(
"Key algorithm %d unsupported by libhsm.\n", policy->
ksk->
algorithm);
7459 ksks_created = new_ksks;
7462 for (i = new_zsks ; i > 0 ; i--) {
7463 if (hsm_supported_algorithm(policy->
zsk->
algorithm) == 0) {
7468 printf(
"Created key in repository %s\n", policy->
zsk->
sm_name);
7471 printf(
"Error creating key in repository %s\n", policy->
zsk->
sm_name);
7472 hsm_error_message = hsm_get_error(ctx);
7473 if (hsm_error_message) {
7474 printf(
"%s\n", hsm_error_message);
7475 free(hsm_error_message);
7482 id = hsm_get_key_id(ctx, key);
7486 printf(
"Error creating key in Database\n");
7487 hsm_error_message = hsm_get_error(ctx);
7488 if (hsm_error_message) {
7489 printf(
"%s\n", hsm_error_message);
7490 free(hsm_error_message);
7497 printf(
"Created ZSK size: %i, alg: %i with id: %s in repository: %s and database.\n", policy->
zsk->
bits,
7501 printf(
"Key algorithm %d unsupported by libhsm.\n", policy->
zsk->
algorithm);
7512 printf(
"NOTE: keys generated in repository %s will not become active until they have been backed up\n", policy->
ksk->
sm_name);
7515 printf(
"NOTE: keys generated in repository %s will not become active until they have been backed up\n", policy->
zsk->
sm_name);
7522 hsm_destroy_context(ctx);
7524 status = hsm_close();
7525 printf(
"all done! hsm_close result: %d\n", status);
7540 int keypair_id = -1;
7544 FILE* lock_fd = NULL;
7549 hsm_key_t *key = NULL;
7553 printf(
"Please provide a CKA_ID for the key to delete\n");
7561 printf(
"Failed to connect to database\n");
7569 if (status != 0 || key_state == -1) {
7570 printf(
"Failed to determine the state of the key\n");
7577 if (force_flag == 1) {
7578 printf(
"*WARNING* This will delete a key that the enforcer believes is in use; are you really sure? [y/N] ");
7580 user_certain = getchar();
7581 if (user_certain !=
'y' && user_certain !=
'Y') {
7582 printf(
"Okay, quitting...\n");
7587 printf(
"The enforcer believes that this key is in use, quitting...\n");
7620 if (hsm_flag == 1) {
7622 status = hsm_open(
config, hsm_prompt_pin);
7624 hsm_print_error(NULL);
7629 key = hsm_find_key_by_id(NULL,
o_cka_id);
7632 printf(
"Key not found in HSM: %s\n",
o_cka_id);
7637 status = hsm_remove_key(NULL, key);
7644 printf(
"Key delete successful: %s\n",
o_cka_id);
7646 printf(
"Key delete failed: %s\n",
o_cka_id);
7657 struct stat stat_ret;
7661 xmlDocPtr doc = NULL;
7662 xmlDocPtr rngdoc = NULL;
7663 xmlXPathContextPtr xpathCtx = NULL;
7664 xmlXPathObjectPtr xpathObj = NULL;
7665 xmlRelaxNGParserCtxtPtr rngpctx = NULL;
7666 xmlRelaxNGValidCtxtPtr rngctx = NULL;
7667 xmlRelaxNGPtr schema = NULL;
7668 xmlChar *user_expr = (
unsigned char*)
"//Configuration/Enforcer/Privileges/User";
7669 xmlChar *group_expr = (
unsigned char*)
"//Configuration/Enforcer/Privileges/Group";
7671 char* filename = OPENDNSSEC_CONFIG_FILE;
7672 char* rngfilename = OPENDNSSEC_SCHEMA_DIR
"/conf.rng";
7673 char* temp_char = NULL;
7680 char *username = NULL;
7681 char *groupname = NULL;
7683 printf(
"fixing permissions on file %s\n", dbschema);
7685 if (geteuid() != 0) {
7690 if (stat(dbschema, &stat_ret) != 0) {
7691 printf(
"cannot stat file %s: %s", dbschema, strerror(errno));
7697 doc = xmlParseFile(filename);
7699 printf(
"Error: unable to parse file \"%s\"", filename);
7704 rngdoc = xmlParseFile(rngfilename);
7705 if (rngdoc == NULL) {
7706 printf(
"Error: unable to parse file \"%s\"", rngfilename);
7711 rngpctx = xmlRelaxNGNewDocParserCtxt(rngdoc);
7712 if (rngpctx == NULL) {
7713 printf(
"Error: unable to create XML RelaxNGs parser context");
7718 schema = xmlRelaxNGParse(rngpctx);
7719 if (schema == NULL) {
7720 printf(
"Error: unable to parse a schema definition resource");
7725 rngctx = xmlRelaxNGNewValidCtxt(schema);
7726 if (rngctx == NULL) {
7727 printf(
"Error: unable to create RelaxNGs validation context based on the schema");
7732 status = xmlRelaxNGValidateDoc(rngctx,doc);
7734 printf(
"Error validating file \"%s\"", filename);
7740 xpathCtx = xmlXPathNewContext(doc);
7741 if(xpathCtx == NULL) {
7742 printf(
"Error: unable to create new XPath context");
7748 xpathObj = xmlXPathEvalExpression(group_expr, xpathCtx);
7749 if(xpathObj == NULL) {
7750 printf(
"Error: unable to evaluate xpath expression: %s", group_expr);
7751 xmlXPathFreeContext(xpathCtx);
7755 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
7756 temp_char = (
char*) xmlXPathCastToString(xpathObj);
7759 xmlXPathFreeObject(xpathObj);
7765 xpathObj = xmlXPathEvalExpression(user_expr, xpathCtx);
7766 if(xpathObj == NULL) {
7767 printf(
"Error: unable to evaluate xpath expression: %s", user_expr);
7768 xmlXPathFreeContext(xpathCtx);
7772 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
7773 temp_char = (
char*) xmlXPathCastToString(xpathObj);
7776 xmlXPathFreeObject(xpathObj);
7782 xmlXPathFreeContext(xpathCtx);
7783 xmlRelaxNGFree(schema);
7784 xmlRelaxNGFreeValidCtxt(rngctx);
7785 xmlRelaxNGFreeParserCtxt(rngpctx);
7790 if (username != NULL) {
7792 if ((pwd = getpwnam(username)) == NULL) {
7793 printf(
"user '%s' does not exist. cannot chown %s...\n", username, dbschema);
7802 if ((grp = getgrnam(groupname)) == NULL) {
7803 printf(
"group '%s' does not exist. cannot chown %s...\n", groupname, dbschema);
7812 if (chown(dbschema, uid, gid) == -1) {
7813 printf(
"cannot chown(%u,%u) %s: %s",
7814 (
unsigned) uid, (
unsigned) gid, dbschema, strerror(errno));
7823 if (chown(temp_char, uid, gid) == -1) {
7824 printf(
"cannot chown(%u,%u) %s: %s",
7825 (
unsigned) uid, (
unsigned) gid, temp_char, strerror(errno));
7867 int CountKeys(
int *zone_id,
int keytag,
const char *cka_id,
int *key_count,
char **temp_cka_id,
int *temp_key_state,
int *temp_keypair_id)
7880 int temp_zone_id = 0;
7881 char* temp_loc = NULL;
7884 int temp_keypair = 0;
7889 hsm_key_t *key = NULL;
7890 ldns_rr *dnskey_rr = NULL;
7891 hsm_sign_params_t *sign_params = NULL;
7894 status = hsm_open(
config, hsm_prompt_pin);
7896 hsm_print_error(NULL);
7901 nchar = snprintf(buffer,
sizeof(buffer),
"(%d, %d, %d)",
7903 if (nchar >=
sizeof(buffer)) {
7904 printf(
"Error: Overran buffer in CountKeys\n");
7910 StrAppend(&sql,
"select k.zone_id, k.location, k.algorithm, k.state, k.id from KEYDATA_VIEW k where state in ");
7912 StrAppend(&sql,
" and zone_id is not null and k.keytype = 257");
7914 if (*zone_id != -1) {
7919 if (cka_id != NULL) {
7937 while (status == 0) {
7939 DbInt(row, 0, &temp_zone_id);
7941 DbInt(row, 2, &temp_alg);
7942 DbInt(row, 3, &temp_state);
7943 DbInt(row, 4, &temp_keypair);
7947 if (keytag == -1 && cka_id == NULL)
7949 *temp_key_state = temp_state;
7952 key = hsm_find_key_by_id(NULL, temp_loc);
7954 printf(
"cka_id %-33s in DB but NOT IN repository\n", temp_loc);
7955 }
else if (keytag != -1) {
7956 sign_params = hsm_sign_params_new();
7957 sign_params->owner = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME,
"temp_zone");
7958 sign_params->algorithm = temp_alg;
7959 sign_params->flags = LDNS_KEY_ZONE_KEY;
7960 sign_params->flags += LDNS_KEY_SEP_KEY;
7962 dnskey_rr = hsm_get_dnskey(NULL, key, sign_params);
7963 sign_params->keytag = ldns_calc_keytag(dnskey_rr);
7966 if (keytag == sign_params->keytag) {
7969 *temp_cka_id = NULL;
7971 *zone_id = temp_zone_id;
7972 *temp_key_state = temp_state;
7973 *temp_keypair_id = temp_keypair;
7974 printf(
"Found key with CKA_ID %s\n", temp_loc);
7977 hsm_sign_params_free(sign_params);
7979 if (key && cka_id != NULL && strncmp(cka_id, temp_loc, strlen(temp_loc)) == 0) {
7981 if (done_row == 0) {
7983 *temp_cka_id = NULL;
7985 *zone_id = temp_zone_id;
7986 *temp_key_state = temp_state;
7987 *temp_keypair_id = temp_keypair;
7988 printf(
"Found key with CKA_ID %s\n", temp_loc);
8008 *key_count = temp_count;
8015 if (dnskey_rr != NULL) {
8016 ldns_rr_free(dnskey_rr);
8025 int GetKeyState(
const char *cka_id,
int *temp_key_state,
int *temp_keypair_id) {
8033 int temp_keypair = 0;
8035 nchar = snprintf(sql,
sizeof(sql),
"select k.id, k.state from KEYDATA_VIEW k where k.location = '%s'", cka_id);
8036 if (nchar >=
sizeof(sql)) {
8037 printf(
"Error: Overran buffer in CountKeys\n");
8046 while (status == 0) {
8048 DbInt(row, 0, &temp_keypair);
8049 DbInt(row, 1, &temp_state);
8052 if (temp_state == 0) {
8056 *temp_key_state = temp_state;
8057 *temp_keypair_id = temp_keypair;
8099 int MarkDSSeen(
int keypair_id,
int zone_id,
int policy_id,
const char *datetime,
int key_state)
8117 printf(
"Error: failed to read policy\n");
8140 printf(
"DbDateDiff failed\n");
8165 printf(
"DbDateDiff failed\n");
8228 char* where_clause = NULL;
8243 printf(
"Error: failed to read policy\n");
8259 StrAppend(&where_clause,
"select id from KEYDATA_VIEW where state = 4 and keytype = 257 and zone_id = ");
8261 StrAppend(&where_clause,
" and retire = (select min(retire) from KEYDATA_VIEW where state = 4 and keytype = 257 and zone_id = ");
8270 printf(
"Error: failed to find ID of key to retire\n");
8281 printf(
"DbDateDiff failed\n");
8350 if (zone_id != -1) {
8359 printf(
"Error in CountKeysInState\n");
8396 int ChangeKeyState(
int keytype,
const char *cka_id,
int zone_id,
int policy_id,
const char *datetime,
int keystate)
8424 printf(
"Error: failed to read policy\n");
8432 if (zone_id != -1) {
8451 keyids =
MemMalloc(count *
sizeof(
int));
8458 if (zone_id != -1) {
8467 while (status == 0) {
8468 status =
KsmKey(result, &data);
8499 for (j = 0; j < i; ++j) {
8503 snprintf(buffer,
sizeof(buffer),
"%d", keyids[j]);
8528 printf(
"DbDateDiff failed\n");
8540 if (zone_id != -1) {
8560 printf(
"DbDateDiff failed\n");
8572 if (zone_id != -1) {
8585 printf(
"DbDateDiff failed\n");
8597 if (zone_id != -1) {
8633 static int restart_enforcerd()
8637 return system(ODS_EN_NOTIFY);
8649 xmlDocPtr doc = NULL;
8650 xmlXPathContextPtr xpathCtx = NULL;
8651 xmlXPathObjectPtr xpathObj = NULL;
8652 char* temp_char = NULL;
8654 xmlChar *iv_expr = (
unsigned char*)
"//Configuration/Enforcer/Interval";
8655 xmlChar *mk_expr = (
unsigned char*)
"//Configuration/Enforcer/ManualKeyGeneration";
8658 doc = xmlParseFile(
config);
8660 printf(
"Error: unable to parse file \"%s\"\n",
config);
8665 xpathCtx = xmlXPathNewContext(doc);
8666 if(xpathCtx == NULL) {
8667 printf(
"Error: unable to create new XPath context\n");
8673 xpathObj = xmlXPathEvalExpression(iv_expr, xpathCtx);
8674 if(xpathObj == NULL) {
8675 printf(
"Error: unable to evaluate xpath expression: %s", iv_expr);
8676 xmlXPathFreeContext(xpathCtx);
8681 temp_char = (
char *)xmlXPathCastToString(xpathObj);
8684 printf(
"Error: unable to convert Interval %s to seconds, error: %i\n", temp_char, status);
8688 else if (status == -1) {
8689 printf(
"Info: converting %s to seconds; M interpreted as 31 days, Y interpreted as 365 days\n", temp_char);
8693 xmlXPathFreeObject(xpathObj);
8696 xpathObj = xmlXPathEvalExpression(mk_expr, xpathCtx);
8697 if(xpathObj == NULL) {
8698 printf(
"Error: unable to evaluate xpath expression: %s\n", mk_expr);
8699 xmlXPathFreeContext(xpathCtx);
8704 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
8712 xmlXPathFreeObject(xpathObj);
8715 xmlXPathFreeContext(xpathCtx);
8755 int man_key_gen = -1;
8766 printf(
"Failed to Link Keys to zone\n");
8776 if (policy == NULL) {
8777 printf(
"Malloc for policy struct failed\n");
8787 printf(
"Error: unable to read policy %s from database\n",
o_policy);
8792 printf(
"Error: policy %s doesn't exist in database\n",
o_policy);
8800 printf(
"Error allocating zsks to zone %s", zone_name);
8806 printf(
"Error allocating ksks to zone %s", zone_name);
8848 int keys_needed = 0;
8849 int keys_in_queue = 0;
8850 int keys_pending_retirement = 0;
8852 int key_pair_id = 0;
8859 if (datetime == NULL) {
8860 printf(
"Couldn't turn \"now\" into a date, quitting...");
8864 if (policy == NULL) {
8865 printf(
"NULL policy sent to allocateKeysToZone");
8871 printf(
"Unknown keytype: %i in allocateKeysToZone", key_type);
8885 status =
KsmKeyPredict(policy->
id, key_type, 1, interval, &keys_needed, rollover_scheme, 1);
8887 printf(
"Could not predict key requirement for next interval for %s", zone_name);
8895 printf(
"Could not count current key numbers for zone %s", zone_name);
8903 printf(
"Could not count keys which may retire before the next run (for zone %s)", zone_name);
8909 new_keys = keys_needed - (keys_in_queue - keys_pending_retirement);
8915 for (i=0 ; i < new_keys ; i++){
8919 if (status == -1 || key_pair_id == 0) {
8920 if (man_key_gen == 0) {
8921 printf(
"Not enough keys to satisfy ksk policy for zone: %s. keys_to_allocate(%d) = keys_needed(%d) - (keys_available(%d) - keys_pending_retirement(%d))\n", zone_name, new_keys, keys_needed, keys_in_queue, keys_pending_retirement);
8922 printf(
"Tried to allocate %d keys, failed on allocating key number %d", new_keys, i+1);
8923 printf(
"ods-enforcerd will create some more keys on its next run");
8926 printf(
"Not enough keys to satisfy ksk policy for zone: %s. keys_to_allocate(%d) = keys_needed(%d) - (keys_available(%d) - keys_pending_retirement(%d))\n", zone_name, new_keys, keys_needed, keys_in_queue, keys_pending_retirement);
8927 printf(
"Tried to allocate %d keys, failed on allocating key number %d", new_keys, i+1);
8928 printf(
"please use \"ods-ksmutil key generate\" to create some more keys.");
8932 else if (status != 0) {
8933 printf(
"Could not get an unallocated ksk for zone: %s", zone_name);
8938 if (status == -1 || key_pair_id == 0) {
8939 if (man_key_gen == 0) {
8940 printf(
"Not enough keys to satisfy zsk policy for zone: %s. keys_to_allocate(%d) = keys_needed(%d) - (keys_available(%d) - keys_pending_retirement(%d))\n", zone_name, new_keys, keys_needed, keys_in_queue, keys_pending_retirement);
8941 printf(
"Tried to allocate %d keys, failed on allocating key number %d", new_keys, i+1);
8942 printf(
"ods-enforcerd will create some more keys on its next run");
8945 printf(
"Not enough keys to satisfy zsk policy for zone: %s. keys_to_allocate(%d) = keys_needed(%d) - (keys_available(%d) - keys_pending_retirement(%d))\n", zone_name, new_keys, keys_needed, keys_in_queue, keys_pending_retirement);
8946 printf(
"Tried to allocate %d keys, failed on allocating key number %d", new_keys, i+1);
8947 printf(
"please use \"ods-ksmutil key generate\" to create some more keys.");
8951 else if (status != 0) {
8952 printf(
"Could not get an unallocated zsk for zone: %s", zone_name);
8956 if(key_pair_id > 0) {
8961 printf(
"KsmKeyGetUnallocated returned bad key_id %d for zone: %s; exiting...", key_pair_id, zone_name);
8965 printf(
"%s key allocation for zone %s: %d key(s) allocated\n", key_type ==
KSM_TYPE_KSK ?
"KSK" :
"ZSK", zone_name, new_keys);
8989 int keyRoll(
int zone_id,
int policy_id,
int key_type)
9002 int temp_zone_id = -1;
9008 char* insql1 = NULL;
9009 char* insql2 = NULL;
9015 if (datetime == NULL) {
9016 printf(
"Couldn't turn \"now\" into a date, quitting...\n");
9024 if (zone_id != -1) {
9027 if (policy_id != -1) {
9031 if (key_type != -1) {
9040 while (status == 0) {
9042 DbInt(row, 0, &temp_id);
9043 DbInt(row, 1, &temp_type);
9047 DusSetInt(&sql1,
"compromisedflag", 1, 1);
9108 size = snprintf(sql2,
KSM_SQL_SIZE,
"select zone_id from dnsseckeys where retire = \"%s\" and keypair_id = %d", datetime, temp_id);
9112 while (status == 0) {
9114 DbInt(row2, 0, &temp_zone_id);
9119 snprintf(buffer,
sizeof(buffer),
"%d", temp_zone_id);
9142 while (status == 0) {
9144 DbInt(row2, 0, &temp_zone_id);
9149 snprintf(buffer,
sizeof(buffer),
"%d", temp_zone_id);
9171 printf(
"Couldn't construct SQL to promote standby key\n");
9242 else if (status == -1) {}
9257 xmlNodePtr zone_node;
9258 xmlNodePtr adapters_node;
9259 xmlNodePtr input_node;
9260 xmlNodePtr in_ad_node;
9261 xmlNodePtr output_node;
9262 xmlNodePtr out_ad_node;
9264 root = xmlDocGetRootElement(doc);
9266 fprintf(stderr,
"empty document\n");
9269 if (xmlStrcmp(root->name, (
const xmlChar *)
"ZoneList")) {
9270 fprintf(stderr,
"document of the wrong type, root node != %s",
"ZoneList");
9274 zone_node = xmlNewTextChild(root, NULL, (
const xmlChar *)
"Zone", NULL);
9275 (void) xmlNewProp(zone_node, (
const xmlChar *)
"name", (
const xmlChar *)zone->
name);
9278 (void) xmlNewTextChild(zone_node, NULL, (
const xmlChar *)
"Policy", (
const xmlChar *)zone->
policy_name);
9281 (void) xmlNewTextChild(zone_node, NULL, (
const xmlChar *)
"SignerConfiguration", (
const xmlChar *)zone->
signconf);
9284 adapters_node = xmlNewTextChild(zone_node, NULL, (
const xmlChar *)
"Adapters", NULL);
9286 input_node = xmlNewTextChild(adapters_node, NULL, (
const xmlChar *)
"Input", NULL);
9287 in_ad_node = xmlNewTextChild (input_node, NULL, (
const xmlChar *)
"Adapter", (
const xmlChar *)zone->
input);
9289 if (zone->
in_type[0] ==
'\0') {
9290 (void) xmlNewProp(in_ad_node, (
const xmlChar *)
"type", (
const xmlChar *)
"File");
9292 (void) xmlNewProp(in_ad_node, (
const xmlChar *)
"type", (
const xmlChar *)zone->
in_type);
9296 output_node = xmlNewTextChild(adapters_node, NULL, (
const xmlChar *)
"Output", NULL);
9297 out_ad_node = xmlNewTextChild (output_node, NULL, (
const xmlChar *)
"Adapter", (
const xmlChar *)zone->
output);
9300 (void) xmlNewProp(out_ad_node, (
const xmlChar *)
"type", (
const xmlChar *)
"File");
9302 (void) xmlNewProp(out_ad_node, (
const xmlChar *)
"type", (
const xmlChar *)zone->
out_type);
9316 len = strlen(
string);
9318 for (i = 0; i < len; ++i) {
9319 if (
string[i] ==
'\'') {
9324 buffer[j++] =
string[i];
9328 return ( (j <= buflen) ? 0 : 1);
9333 char* signconf = NULL;
9334 char* moved_signconf = NULL;
9335 char* zone_name = NULL;
9339 xmlDocPtr doc = NULL;
9341 xmlXPathContextPtr xpathCtx = NULL;
9342 xmlXPathObjectPtr xpathObj = NULL;
9344 xmlChar *node_expr = (
unsigned char*)
"//Zone";
9346 doc = xmlParseFile(zonelist_filename);
9348 printf(
"Error: unable to parse file \"%s\"\n", zonelist_filename);
9352 xpathCtx = xmlXPathNewContext(doc);
9353 if(xpathCtx == NULL) {
9359 xpathObj = xmlXPathEvalExpression(node_expr, xpathCtx);
9360 if(xpathObj == NULL) {
9361 xmlXPathFreeContext(xpathCtx);
9366 if (xpathObj->nodesetval) {
9367 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
9369 curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
9370 zone_name = (
char *) xmlGetProp(xpathObj->nodesetval->nodeTab[i], (
const xmlChar *)
"name");
9372 if (all_flag || (strlen(zone_name) == strlen(o_zone) &&
9373 strncmp(zone_name, o_zone, strlen(zone_name)) == 0)) {
9377 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"SignerConfiguration")) {
9378 StrAppend(&signconf, (
char *) xmlNodeGetContent(curNode));
9380 StrAppend(&moved_signconf,
".ZONE_DELETED");
9382 status = rename(signconf, moved_signconf);
9383 if (status != 0 && errno != ENOENT)
9386 printf(
"Could not rename: %s -> %s", signconf, moved_signconf);
9396 curNode = curNode->next;
9432 char* temp_zone = NULL;
9433 int temp_policy = 0;
9434 char* temp_location = NULL;
9441 hsm_key_t *key = NULL;
9442 ldns_rr *dnskey_rr = NULL;
9443 hsm_sign_params_t *sign_params = NULL;
9447 char* ds_buffer = NULL;
9450 status = hsm_open(
config, hsm_prompt_pin);
9452 hsm_print_error(NULL);
9457 "select name, kv.policy_id, location, algorithm from KEYDATA_VIEW kv, zones z where keytype = 257 and state in (3,7) and zone_id = z.id ");
9458 if (zone_id != -1) {
9471 while (status == 0) {
9474 DbInt(row, 1, &temp_policy);
9476 DbInt(row, 3, &temp_algo);
9479 key = hsm_find_key_by_id(NULL, temp_location);
9482 printf(
"Key %s in DB but not repository.", temp_location);
9491 printf(
"\n*** Found DNSKEY RECORD involved with rollover:\n");
9493 sign_params = hsm_sign_params_new();
9494 sign_params->owner = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, temp_zone);
9495 sign_params->algorithm = temp_algo;
9496 sign_params->flags = LDNS_KEY_ZONE_KEY;
9497 sign_params->flags += LDNS_KEY_SEP_KEY;
9498 dnskey_rr = hsm_get_dnskey(NULL, key, sign_params);
9503 ldns_rr_set_ttl(dnskey_rr, rrttl);
9506 ds_buffer = ldns_rr2str(dnskey_rr);
9507 ldns_rr_free(dnskey_rr);
9510 for (i = 0; ds_buffer[i]; ++i) {
9511 if (ds_buffer[i] ==
'\t') {
9517 printf(
"%s", ds_buffer);
9518 printf(
"\nOnce the DS record for this DNSKEY is seen in DNS you can issue the ds-seen command for zone %s with the cka_id %s\n", temp_zone, temp_location);
9524 hsm_sign_params_free(sign_params);
void DbFreeResult(DB_RESULT result)
int KsmCheckHSMkeyID(int repo_id, const char *cka_id, int *exists)
int LinkKeys(const char *zone_name, int policy_id)
int KsmPolicyInit(DB_RESULT *handle, const char *name)
char name[KSM_NAME_LENGTH]
unsigned long sm_capacity
int update_policies(char *kasp_filename)
void db_disconnect(FILE *lock_fd)
char name[KSM_ZONE_NAME_LENGTH]
int release_lite_lock(FILE *lock_fd)
int KsmZoneIdAndPolicyFromName(const char *zone_name, int *policy_id, int *zone_id)
int StrIsDigits(const char *string)
void DusConditionKeyword(char **query, const char *field, DQS_COMPARISON compare, const char *value, int clause)
xmlDocPtr add_zone_node(const char *docname, const char *zone_name, const char *policy_name, const char *sig_conf_name, const char *input_name, const char *output_name, const char *input_type, const char *output_type)
char signconf[KSM_PATH_LENGTH]
int DbFetchRow(DB_RESULT result, DB_ROW *row)
void SetPolicyDefaults(KSM_POLICY *policy, char *name)
int KsmPolicy(DB_RESULT handle, KSM_POLICY *data)
char * DqsSpecifyInit(const char *table, const char *fields)
char location[KSM_NAME_LENGTH]
int KsmKeywordTypeNameToValue(const char *name)
void usage_policyimport()
int KsmMarkPreBackup(int repo_id, const char *datetime)
int KsmKeyCountQueue(int keytype, int *count, int zone_id)
KSM_POLICY * KsmPolicyAlloc()
#define KSM_PAR_ZSKTTL_CAT
int KsmParameter(DB_RESULT result, KSM_PARAMETER *data)
KSM_COMMON_KEY_POLICY * keys
int ShellQuoteString(const char *string, char *buffer, size_t buflen)
int KsmZoneInit(DB_RESULT *handle, int policy_id)
int ListKeys(int zone_id)
int KsmParameterCollection(KSM_PARCOLL *data, int policy_id)
int KsmSerialIdFromName(const char *name, int *id)
int main(int argc, char *argv[])
char retire[KSM_TIME_LENGTH]
int KsmPolicySetIdFromName(KSM_POLICY *policy)
int get_db_details(char **dbschema, char **host, char **port, char **user, char **password)
xmlDocPtr del_zone_node(const char *docname, const char *zone_name)
void DqsConditionKeyword(char **query, const char *field, DQS_COMPARISON compare, const char *value, int index)
int get_policy_name_from_id(KSM_ZONE *zone)
int KsmKeyPairCreate(int policy_id, const char *HSMKeyID, int smID, int size, int alg, const char *generate, DB_ID *id)
int KsmImportZone(const char *zone_name, int policy_id, int fail_if_exists, int *new_zone, const char *signconf, const char *input, const char *output, const char *input_type, const char *output_type)
int KsmZone(DB_RESULT handle, KSM_ZONE *data)
int KsmKeywordRollNameToValue(const char *name)
void list_zone_node(const char *docname, int *zone_ids)
void DqsOrderBy(char **query, const char *field)
int KsmZoneCount(DB_RESULT handle, int *count)
char sm_name[KSM_NAME_LENGTH]
int MsgLog(int status,...)
int get_conf_key_info(int *interval, int *man_key_gen)
int KsmRollbackMarkPreBackup(int repo_id)
int KsmPolicyRead(KSM_POLICY *policy)
int cmd_control(char *command)
void usage_policyexport()
void DusSetInt(char **sql, const char *field, int data, int clause)
int append_policy(xmlDocPtr doc, KSM_POLICY *policy)
void DqsFree(char *query)
int keyRoll(int zone_id, int policy_id, int key_type)
#define KSM_STATE_KEYPUBLISH
void DdsFree(char *query)
void DusConditionInt(char **query, const char *field, DQS_COMPARISON compare, int value, int clause)
const char * KsmKeywordStateValueToName(int value)
char * DqsCountInit(const char *table)
int KsmPolicyIdFromName(const char *name, int *id)
int DbString(DB_ROW row, int field_index, char **result)
#define KSM_PAR_DSTTL_CAT
int KsmSmIdFromName(const char *name, int *id)
char * StrStrdup(const char *string)
void DqsConditionInt(char **query, const char *field, DQS_COMPARISON compare, int value, int index)
void DdsConditionInt(char **query, const char *field, DQS_COMPARISON compare, int value, int index)
#define KSM_PAR_ZSKTTL_STRING
int KsmPolicyIdFromZoneId(int zone_id, int *policy_id)
int SetParamOnPolicy(const xmlChar *new_value, const char *name, const char *category, int current_value, int policy_id, int value_type)
char * DdsInit(const char *table)
int DtGeneral(const char *string, struct tm *datetime)
char * DtParseDateTimeString(const char *string)
#define KSM_STATE_DSPUBLISH
KSM_PARENT_POLICY * parent
char output[KSM_PATH_LENGTH]
void ksm_log_msg(const char *format)
KSM_DENIAL_POLICY * denial
int backup_file(const char *orig_file, const char *backup_file)
int printKey(void *context, KSM_KEYDATA *key_data)
int KsmZoneIdFromName(const char *zone_name, int *zone_id)
int KsmListRollovers(int zone_id, int *ds_count)
int KsmParameterValue(const char *name, const char *category, int *value, int policy_id, int *parameter_id)
int KsmKeyInitSql(DB_RESULT *result, const char *sql)
int GetKeyState(const char *cka_id, int *temp_key_state, int *temp_keypair_id)
int KsmCollectionInit(KSM_PARCOLL *data)
int update_repositories()
#define DB_KEYDATA_FIELDS
const char * DbErrmsg(DB_HANDLE handle)
int KsmImportPolicy(const char *policy_name, const char *policy_description)
char policy_name[KSM_NAME_LENGTH]
void KsmPolicyFree(KSM_POLICY *policy)
void DbFreeRow(DB_ROW row)
int KsmKey(DB_RESULT result, KSM_KEYDATA *data)
void MsgRegister(int min, int max, const char **message, MSG_OUTPUT_FUNCTION output)
KSM_SIGNER_POLICY * signer
size_t StrToLower(char *text)
int cmd_update(const char *qualifier)
char input[KSM_PATH_LENGTH]
int DbDisconnect(DB_HANDLE dbhandle)
int KsmPolicyUpdateDesc(int policy_id, const char *policy_description)
int KsmKeyPredict(int policy_id, int keytype, int shared_keys, int interval, int *count, int rollover_scheme, int zone_count)
int KsmMarkKeysAsDead(int zone_id)
int read_zonelist_filename(char **zone_list_filename)
const char * KsmKeywordSerialValueToName(int value)
int KsmDnssecKeyCreate(int zone_id, int keypair_id, int keytype, int state, const char *time, const char *retTime, DB_ID *id)
int KsmPolicyNullSaltStamp(int policy_id)
int DbExecuteSql(DB_HANDLE handle, const char *stmt_str, DB_RESULT *result)
#define KSM_POLICY_DESC_LENGTH
int DbStringBuffer(DB_ROW row, int field_index, char *buffer, size_t buflen)
int PurgeKeys(int zone_id, int policy_id)
void StrAppend(char **str1, const char *str2)
int StrStrtoi(const char *string, int *value)
int ChangeKeyState(int keytype, const char *cka_id, int zone_id, int policy_id, const char *datetime, int keystate)
int DbIntQuery(DB_HANDLE handle, int *value, const char *query)
void usage_keykskretire()
#define KSM_PAR_KSKTTL_CAT
#define KSM_STATE_PUBLISH
int DbDateDiff(const char *start, int delta, int sign, char *buffer, size_t buflen)
#define KSM_PAR_DSTTL_STRING
int KsmDeleteZone(int zone_id)
int allocateKeysToZone(KSM_POLICY *policy, int key_type, int zone_id, uint16_t interval, const char *zone_name, int man_key_gen, int rollover_scheme)
int KsmZoneNameFromId(int zone_id, char **zone_name)
char * DusInit(const char *table)
#define DEFAULT_LOG_FACILITY
int read_filenames(char **zone_list_filename, char **kasp_filename)
int CountKeysInState(int keytype, int keystate, int *count, int zone_id)
void KsmParameterEnd(DB_RESULT result)
int KsmImportKeyPair(int policy_id, const char *HSMKeyID, int smID, int size, int alg, int state, const char *time, int fixDate, DB_ID *id)
int cmd_backup(const char *qualifier)
int RetireOldKey(int zone_id, int policy_id, const char *datetime)
int KsmKeyGetUnallocated(int policy_id, int sm, int bits, int algorithm, int zone_id, int share_keys, int *keypair_id)
int db_connect(DB_HANDLE *dbhandle, FILE **lock_fd, int backup)
int append_zone(xmlDocPtr doc, KSM_ZONE *zone)
int KsmParameterInit(DB_RESULT *result, const char *name, const char *category, int policy_id)
xmlDocPtr del_policy_node(const char *docname, const char *policy_name)
int KsmPolicyExists(const char *name)
int fix_file_perms(const char *dbschema)
#define KSM_PAR_KSKTTL_STRING
int rename_signconf(const char *zonelist_filename, const char *o_zone)
int KsmRequestPendingRetireCount(int keytype, const char *datetime, KSM_PARCOLL *parameters, int *count, int zone_id, int interval)
int KsmZoneCountInit(DB_RESULT *handle, int id)
void DdsEnd(char **query)
int KsmParameterSet(const char *name, const char *category, int value, int policy_id)
KSM_ENFORCER_POLICY * enforcer
int KsmImportRepository(const char *repo_name, const char *repo_capacity, int require_backup)
int KsmKeywordAlgorithmNameToValue(const char *name)
char in_type[KSM_ADAPTER_NAME_LENGTH]
int DbInt(DB_ROW row, int field_index, int *value)
void * MemMalloc(size_t size)
char out_type[KSM_ADAPTER_NAME_LENGTH]
int KsmListBackups(int repo_id, int verbose_flag)
#define KSM_STATE_DSREADY
int DtXMLIntervalSeconds(const char *text, int *interval)
size_t StrToUpper(char *text)
void KsmKeyEnd(DB_RESULT result)
int get_lite_lock(char *lock_filename, FILE *lock_fd)
int KsmMarkBackup(int repo_id, const char *datetime)
#define KSM_STATE_GENERATE
void DusSetString(char **sql, const char *field, const char *data, int clause)
int MarkDSSeen(int keypair_id, int zone_id, int policy_id, const char *datetime, int key_state)
void DqsEnd(char **query)
int DbBeginTransaction(void)
int DbExecuteSqlNoResult(DB_HANDLE handle, const char *stmt_str)
void DqsConditionString(char **query, const char *field, DQS_COMPARISON compare, const char *value, int index)
int KsmKeyCountStillGood(int policy_id, int sm, int bits, int algorithm, int interval, const char *datetime, int *count, int keytype)
int update_zones(char *zone_list_filename)
int CountKeys(int *zone_id, int keytag, const char *cka_id, int *key_count, char **temp_cka_id, int *temp_key_state, int *temp_keypair_id)
KSM_SIGNATURE_POLICY * signature
int DbConnect(DB_HANDLE *dbhandle, const char *database,...)
void DbStringFree(char *string)