61 #include <libhsmdns.h>
62 #include <ldns/ldns.h>
64 #include <libxml/tree.h>
65 #include <libxml/parser.h>
66 #include <libxml/xpointer.h>
67 #include <libxml/xpath.h>
68 #include <libxml/xpathInternals.h>
69 #include <libxml/relaxng.h>
70 #include <libxml/xmlreader.h>
71 #include <libxml/xmlsave.h>
73 #define MAX(a, b) ((a) > (b) ? (a) : (b))
77 #define DURATION_TYPE 1
81 #define ROLLOVER_TYPE 5
82 #define INT_TYPE_NO_FREE 6
85 # define MAXPATHLEN 4096
90 #define DEFAULT_LOG_FACILITY LOG_DAEMON
92 #define DEFAULT_LOG_FACILITY LOG_USER
98 char *
config = (
char *) OPENDNSSEC_CONFIG_FILE;
118 static int all_flag = 0;
119 static int auto_accept_flag = 0;
120 static int ds_flag = 0;
121 static int retire_flag = 1;
122 static int notify_flag = 1;
123 static int verbose_flag = 0;
124 static int xml_flag = 1;
125 static int td_flag = 0;
126 static int force_flag = 0;
127 static int hsm_flag = 1;
128 static int check_repository_flag = 0;
130 static int restart_enforcerd(
void);
137 #if defined(HAVE_SYSLOG_R) && defined(HAVE_OPENLOG_R) && defined(HAVE_CLOSELOG_R)
138 struct syslog_data sdata = SYSLOG_DATA_INIT;
141 #undef HAVE_OPENLOG_R
142 #undef HAVE_CLOSELOG_R
150 " --version aka -V\n");
158 "\tImport config into a database (deletes current contents)\n");
165 " start|stop|notify\n"
166 "\tStart, stop or SIGHUP the ods-enforcerd\n");
177 "\tUpdate database from config\n");
185 "\t--zone <zone> aka -z\n"
186 "\t[--policy <policy>] aka -p\n"
187 "\t[--signerconf <signerconf.xml>] aka -s\n"
188 "\t[--input <input>] aka -i\n"
189 "\t[--in-type <input type>] aka -j\n"
190 "\t[--output <output>] aka -o\n"
191 "\t[--out-type <output type>] aka -q\n"
192 "\t[--no-xml] aka -m\n");
200 "\t--zone <zone> | --all aka -z / -a\n"
201 "\t[--no-xml] aka -m\n");
215 "usage: %s [-c <config> | --config <config>] zone \n\n",
226 " repository list\n");
234 "\t--policy [policy_name] | --all aka -p / -a\n");
262 "usage: %s [-c <config> | --config <config>] \n\n",
276 "\t--zone <zone> | --all aka -z / -a\n"
278 "\t(will appear soon:\n"
279 "\t[--keystate <state>] aka -e\n"
280 "\t[--keytype <type>] aka -t\n"
291 "\t--zone <zone> | --all aka -z / -a\n"
292 "\t[--keystate <state>] aka -e\n"
293 "\t[--keytype <type>] aka -t\n"
294 "\t[--ds] aka -d\n");
302 "\t--cka_id <CKA_ID> aka -k\n"
303 "\t--repository <repository> aka -r\n"
304 "\t--zone <zone> aka -z\n"
305 "\t--bits <size> aka -b\n"
306 "\t--algorithm <algorithm> aka -g\n"
307 "\t--keystate <state> aka -e\n"
308 "\t--keytype <type> aka -t\n"
309 "\t--time <time> aka -w\n"
310 "\t[--check-repository] aka -C\n"
311 "\t[--retire <retire>] aka -y\n");
319 "\t--zone zone aka -z\n"
320 "\t--keytype <type> | --all aka -t / -a\n"
322 "\t--policy policy aka -p\n"
323 "\t--keytype <type> | --all aka -t / -a\n");
331 "\t--zone <zone> aka -z\n"
333 "\t--policy <policy> aka -p\n");
341 "\t--policy <policy> aka -p\n"
342 "\t--interval <interval> aka -n\n"
343 "\t[--zonetotal <total no. of zones>] aka -Z\n"
344 "\t--auto-accept aka -A\n");
352 "\t--zone <zone> aka -z\n"
353 "\t--keytag <keytag> | --cka_id <CKA_ID> aka -x / -k\n");
362 "\t--zone <zone> aka -z\n"
363 "\t--keytag <keytag> | --cka_id <CKA_ID> aka -x / -k\n"
364 "\t[--no-notify|-l] aka -l\n"
365 "\t[--no-retire|-f] aka -f\n");
373 "\t--cka_id <CKA_ID> aka -k\n"
381 "usage: %s [-c <config> | --config <config>] \n\n",
399 "\t--repository <repository> aka -r\n"
401 "\t--repository <repository> aka -r\n"
403 "\t--repository <repository> aka -r\n"
405 "\t--repository <repository> aka -r\n"
407 "\t--repository <repository> aka -r\n"
409 "\t[NOTE: backup done is deprecated]\n");
417 "\t[--zone <zone>]\n");
425 "\t[--output <output>] aka -o\n");
433 " zonelist import\n");
440 "usage: %s [-c <config> | --config <config>] command [options]\n\n",
474 "\n\tAllowed date/time strings are of the form:\n"
476 "\tYYYYMMDD[HH[MM[SS]]] (all numeric)\n"
478 "\tor D-MMM-YYYY[:| ]HH[:MM[:SS]] (alphabetic month)\n"
479 "\tor DD-MMM-YYYY[:| ]HH[:MM[:SS]] (alphabetic month)\n"
480 "\tor YYYY-MMM-DD[:| ]HH[:MM[:SS]] (alphabetic month)\n"
482 "\tD-MM-YYYY[:| ]HH[:MM[:SS]] (numeric month)\n"
483 "\tDD-MM-YYYY[:| ]HH[:MM[:SS]] (numeric month)\n"
484 "\tor YYYY-MM-DD[:| ]HH[:MM[:SS]] (numeric month)\n"
486 "\t... and the distinction between them is given by the location of the\n"
494 "key states: GENERATE|PUBLISH|READY|ACTIVE|RETIRE|DEAD\n");
501 "key types: KSK|ZSK\n");
511 exist_file(
const char* filename) {
513 FILE *file = fopen(filename,
"r");
528 FILE* lock_fd = NULL;
529 char* zone_list_filename;
534 char *dbschema = NULL;
538 char *password = NULL;
543 char* setup_command = NULL;
544 char* lock_filename = NULL;
547 printf(
"*WARNING* This will erase all data in the database; are you sure? [y/N] ");
549 user_certain = getchar();
550 if (user_certain !=
'y' && user_certain !=
'Y') {
551 printf(
"Okay, quitting...\n");
558 status =
get_db_details(&dbschema, &host, &port, &user, &password);
577 lock_fd = fopen(lock_filename,
"w");
580 printf(
"Error getting db lock\n");
581 if (lock_fd != NULL) {
602 if (system(setup_command) != 0)
604 printf(
"Could not call db setup command:\n\t%s\n", setup_command);
620 printf(
"Couldn't fix permissions on file %s\n", dbschema);
621 printf(
"Will coninue with setup, but you may need to manually change ownership\n");
630 printf(
"Failed to connect to database, username too long.\n");
641 if (password != NULL) {
644 printf(
"Failed to connect to database, password too long.\n");
667 if (password != NULL) {
669 StrAppend(&setup_command, quoted_password);
677 if (system(setup_command) != 0)
679 printf(
"Could not call db setup command:\n\t%s\n", setup_command);
692 status =
DbConnect(&dbhandle, dbschema, host, password, user, port);
694 printf(
"Failed to connect to database\n");
717 printf(
"Failed to read conf.xml\n");
728 printf(
"Failed to update repositories\n");
741 printf(
"Failed to update policies\n");
742 printf(
"SETUP FAILED\n");
758 printf(
"Failed to update zones\n");
781 FILE* lock_fd = NULL;
782 char* zone_list_filename = NULL;
783 char* kasp_filename = NULL;
785 int done_something = 0;
790 printf(
"Failed to connect to database\n");
799 if (strncmp(qualifier,
"ZONELIST", 8) == 0 ||
800 strncmp(qualifier,
"KASP", 4) == 0 ||
801 strncmp(qualifier,
"ALL", 3) == 0) {
804 printf(
"Failed to read conf.xml\n");
814 if (strncmp(qualifier,
"CONF", 4) == 0 ||
815 strncmp(qualifier,
"ALL", 3) == 0) {
818 printf(
"Failed to update repositories\n");
820 if (strncmp(qualifier,
"ALL", 3) == 0) {
833 if (strncmp(qualifier,
"KASP", 4) == 0 ||
834 strncmp(qualifier,
"ALL", 3) == 0) {
837 printf(
"Failed to update policies\n");
850 if (strncmp(qualifier,
"ZONELIST", 8) == 0 ||
851 strncmp(qualifier,
"ALL", 3) == 0) {
854 printf(
"Failed to update zones\n");
866 if (done_something == 0) {
867 printf(
"Unrecognised command update %s. Please specify one of:\n", qualifier);
871 if (restart_enforcerd() != 0)
873 fprintf(stderr,
"Could not HUP ods-enforcerd\n");
882 if (kasp_filename != NULL) {
885 if (zone_list_filename != NULL) {
904 FILE* lock_fd = NULL;
905 char* zonelist_filename = NULL;
906 char* backup_filename = NULL;
908 char* sig_conf_name = NULL;
909 char* input_name = NULL;
910 char* output_name = NULL;
911 char* input_type = NULL;
912 char* output_type = NULL;
919 xmlDocPtr doc = NULL;
925 printf(
"Couldn't malloc path: %s\n", strerror(errno));
931 printf(
"Please specify a zone with the --zone option\n");
944 StrAppend(&sig_conf_name, OPENDNSSEC_STATE_DIR);
965 if(strcmp(input_type,
"DNS")==0){
966 StrAppend(&input_name, OPENDNSSEC_CONFIG_DIR);
969 StrAppend(&input_name, OPENDNSSEC_STATE_DIR);
989 if(strcmp(output_type,
"DNS") == 0){
990 StrAppend(&output_name, OPENDNSSEC_CONFIG_DIR);
993 StrAppend(&output_name, OPENDNSSEC_STATE_DIR);
1009 if(!exist_file(input_name)){
1010 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);
1013 if(strcmp(output_type,
"DNS") == 0 && !exist_file(output_name)){
1014 fprintf(stdout,
"WARNING: The output file %s for zone %s does not currently exist. \n",output_name,
o_zone);
1022 printf(
"couldn't read zonelist\n");
1039 printf(
"Failed to connect to database\n");
1053 printf(
"Error, can't find policy : %s\n",
o_policy);
1054 printf(
"Failed to update zones\n");
1064 status =
KsmImportZone(
o_zone, policy_id, 1, &new_zone, sig_conf_name, input_name, output_name, input_type, output_type);
1067 printf(
"Failed to Import zone %s; it already exists\n",
o_zone);
1068 }
else if (status == -3) {
1069 printf(
"Failed to Import zone %s; it already exists both with and without a trailing dot\n",
o_zone);
1071 printf(
"Failed to Import zone\n");
1087 printf(
"Can't retrieve shared-keys parameter for policy\n");
1099 printf(
"Can't retrieve shared-keys parameter for policy\n");
1112 if (data.
value == 1) {
1115 printf(
"Failed to Link Keys to zone\n");
1135 if (xml_flag == 1) {
1138 xmlKeepBlanksDefault(0);
1139 xmlTreeIndentString =
"\t";
1154 StrAppend(&backup_filename, zonelist_filename);
1156 status =
backup_file(zonelist_filename, backup_filename);
1164 status = xmlSaveFormatFile(zonelist_filename, doc, 1);
1169 printf(
"couldn't save zonelist\n");
1177 if (xml_flag == 0) {
1178 printf(
"Imported zone: %s into database only, please run \"ods-ksmutil zonelist export\" to update zonelist.xml\n",
o_zone);
1180 printf(
"Imported zone: %s\n",
o_zone);
1197 char* zonelist_filename = NULL;
1198 char* backup_filename = NULL;
1203 xmlDocPtr doc = NULL;
1210 FILE* lock_fd = NULL;
1213 if (all_flag &&
o_zone != NULL) {
1214 printf(
"can not use --all with --zone\n");
1217 else if (!all_flag &&
o_zone == NULL) {
1218 printf(
"please specify either --zone <zone> or --all\n");
1223 if (all_flag == 1) {
1224 printf(
"*WARNING* This will remove all zones from OpenDNSSEC; are you sure? [y/N] ");
1226 user_certain = getchar();
1227 if (user_certain !=
'y' && user_certain !=
'Y') {
1228 printf(
"Okay, quitting...\n");
1236 printf(
"Failed to connect to database\n");
1249 if (xml_flag == 1) {
1253 printf(
"couldn't read zonelist\n");
1278 StrAppend(&backup_filename, zonelist_filename);
1280 status =
backup_file(zonelist_filename, backup_filename);
1289 status = xmlSaveFormatFile(zonelist_filename, doc, 1);
1293 printf(
"Could not save %s\n", zonelist_filename);
1304 if (all_flag == 0) {
1307 printf(
"Couldn't find zone %s\n",
o_zone);
1316 printf(
"Error: failed to mark keys as dead in database\n");
1325 printf(
"Error: failed to remove zone%s from database\n", (all_flag == 1) ?
"s" :
"");
1331 if (all_flag == 0) {
1332 if (system(SIGNER_CLI_UPDATE) != 0)
1334 printf(
"Could not call signer engine\n");
1341 if (xml_flag == 0) {
1342 printf(
"Deleted zone: %s from database only, please run \"ods-ksmutil zonelist export\" to update zonelist.xml\n",
o_zone);
1356 FILE* lock_fd = NULL;
1358 char* zonelist_filename = NULL;
1361 xmlTextReaderPtr reader = NULL;
1363 char* tag_name = NULL;
1365 int file_zone_count = 0;
1371 char* temp_name = NULL;
1378 printf(
"couldn't read zonelist\n");
1379 if (zonelist_filename != NULL) {
1388 printf(
"Failed to connect to database\n");
1394 reader = xmlNewTextReaderFilename(zonelist_filename);
1395 if (reader != NULL) {
1396 ret = xmlTextReaderRead(reader);
1398 tag_name = (
char*) xmlTextReaderLocalName(reader);
1400 if (strncmp(tag_name,
"Zone", 4) == 0
1401 && strncmp(tag_name,
"ZoneList", 8) != 0
1402 && xmlTextReaderNodeType(reader) == 1) {
1406 ret = xmlTextReaderRead(reader);
1409 xmlFreeTextReader(reader);
1411 printf(
"%s : failed to parse\n", zonelist_filename);
1414 printf(
"Unable to open %s\n", zonelist_filename);
1418 zone_ids =
MemMalloc(file_zone_count *
sizeof(
int));
1424 if (file_zone_count != 0) {
1425 StrAppend(&sql,
"select name from zones where id not in (");
1426 for (j = 0; j < file_zone_count; ++j) {
1430 snprintf(buffer,
sizeof(buffer),
"%d", zone_ids[j]);
1435 StrAppend(&sql,
"select name from zones");
1441 while (status == 0) {
1445 printf(
"Found zone %s in DB but not zonelist.\n", temp_name);
1462 if (file_zone_count == 0) {
1463 printf(
"No zones in DB or zonelist.\n");
1491 int prev_zone_id = -1;
1493 char *case_keytype = NULL;
1494 char *case_keystate = NULL;
1495 char *zone_name = NULL;
1498 hsm_key_t *key = NULL;
1499 ldns_rr *dnskey_rr = NULL;
1500 ldns_rr *ds_sha1_rr = NULL;
1501 ldns_rr *ds_sha256_rr = NULL;
1502 hsm_sign_params_t *sign_params = NULL;
1515 int done_something = 0;
1522 if (strncmp(case_keystate,
"KEYPUBLISH", 10) == 0 || strncmp(
o_keystate,
"10", 2) == 0) {
1525 else if (strncmp(case_keystate,
"GENERATE", 8) == 0 || strncmp(
o_keystate,
"1", 1) == 0) {
1528 else if (strncmp(case_keystate,
"PUBLISH", 7) == 0 || strncmp(
o_keystate,
"2", 1) == 0) {
1531 else if (strncmp(case_keystate,
"READY", 5) == 0 || strncmp(
o_keystate,
"3", 1) == 0) {
1534 else if (strncmp(case_keystate,
"ACTIVE", 6) == 0 || strncmp(
o_keystate,
"4", 1) == 0) {
1537 else if (strncmp(case_keystate,
"RETIRE", 6) == 0 || strncmp(
o_keystate,
"5", 1) == 0) {
1540 else if (strncmp(case_keystate,
"DEAD", 4) == 0 || strncmp(
o_keystate,
"6", 1) == 0) {
1543 else if (strncmp(case_keystate,
"DSSUB", 5) == 0 || strncmp(
o_keystate,
"7", 1) == 0) {
1546 else if (strncmp(case_keystate,
"DSPUBLISH", 9) == 0 || strncmp(
o_keystate,
"8", 1) == 0) {
1549 else if (strncmp(case_keystate,
"DSREADY", 7) == 0 || strncmp(
o_keystate,
"9", 1) == 0) {
1553 printf(
"Error: Unrecognised state %s; should be one of GENERATE, PUBLISH, READY, ACTIVE, RETIRE, DEAD, DSSUB, DSPUBLISH, DSREADY or KEYPUBLISH\n",
o_keystate);
1565 if (strncmp(case_keytype,
"KSK", 3) == 0 || strncmp(
o_keytype,
"257", 3) == 0) {
1568 else if (strncmp(case_keytype,
"ZSK", 3) == 0 || strncmp(
o_keytype,
"256", 3) == 0) {
1572 printf(
"Error: Unrecognised keytype %s; should be one of KSK or ZSK\n",
o_keytype);
1583 printf(
"Failed to connect to database\n");
1595 printf(
"Error: unable to find a zone named \"%s\" in database\n",
o_zone);
1601 status = hsm_open(
config, hsm_prompt_pin);
1603 hsm_print_error(NULL);
1608 if (state_id != -1) {
1611 nchar = snprintf(buffer,
sizeof(buffer),
"(%d, %d, %d, %d, %d, %d)",
1614 if (nchar >=
sizeof(buffer)) {
1623 if (zone_id != -1) {
1631 status =
KsmKey(result, &data);
1632 while (status == 0) {
1634 if (ds_flag == 1 && data.
zone_id != prev_zone_id) {
1636 if (red_seen == 0 && act_seen == 0) {
1637 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");
1638 }
else if (red_seen == 1 && act_seen == 1) {
1639 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");
1653 key = hsm_find_key_by_id(NULL, data.
location);
1656 printf(
"Key %s in DB but not repository\n", data.
location);
1661 sign_params = hsm_sign_params_new();
1663 if (zone_id == -1) {
1666 printf(
"Error: unable to find zone name for id %d\n", zone_id);
1667 hsm_sign_params_free(sign_params);
1671 sign_params->owner = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, zone_name);
1675 sign_params->owner = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME,
o_zone);
1678 sign_params->algorithm = data.
algorithm;
1679 sign_params->flags = LDNS_KEY_ZONE_KEY;
1681 sign_params->flags += LDNS_KEY_SEP_KEY;
1683 dnskey_rr = hsm_get_dnskey(NULL, key, sign_params);
1684 sign_params->keytag = ldns_calc_keytag(dnskey_rr);
1700 ldns_rr_set_ttl(dnskey_rr, rrttl);
1705 ldns_rr_print(stdout, dnskey_rr);
1717 ldns_rr_set_ttl(dnskey_rr, rrttl);
1722 ds_sha1_rr = ldns_key_rr2ds(dnskey_rr, LDNS_SHA1);
1723 ldns_rr_print(stdout, ds_sha1_rr);
1726 ds_sha256_rr = ldns_key_rr2ds(dnskey_rr, LDNS_SHA256);
1727 ldns_rr_print(stdout, ds_sha256_rr);
1732 hsm_sign_params_free(sign_params);
1734 status =
KsmKey(result, &data);
1744 if (ds_flag == 1 && red_seen == 0 && act_seen == 0) {
1745 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");
1746 }
else if (ds_flag == 1 && red_seen == 1 && act_seen == 1) {
1747 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");
1751 if (!done_something) {
1752 if (state_id != -1) {
1755 printf(
"No keys in READY state or higher to export.\n");
1761 if (dnskey_rr != NULL) {
1762 ldns_rr_free(dnskey_rr);
1764 if (ds_sha1_rr != NULL) {
1765 ldns_rr_free(ds_sha1_rr);
1767 if (ds_sha256_rr != NULL) {
1768 ldns_rr_free(ds_sha256_rr);
1788 xmlDocPtr doc = xmlNewDoc((
const xmlChar *)
"1.0");
1795 if (all_flag &&
o_policy != NULL) {
1796 printf(
"can not use --all with --policy\n");
1799 else if (!all_flag &&
o_policy == NULL) {
1800 printf(
"please specify either --policy <policy> or --all\n");
1807 printf(
"Failed to connect to database\n");
1813 if (policy == NULL) {
1814 fprintf(stderr,
"Malloc for policy struct failed\n");
1829 policy->
zone == NULL || policy->
parent == NULL ||
1830 policy->
keys == NULL ||
1831 policy->
ksk == NULL || policy->
zsk == NULL ||
1833 fprintf(stderr,
"Malloc for policy struct failed\n");
1838 xmlKeepBlanksDefault(0);
1839 xmlTreeIndentString =
" ";
1840 root = xmlNewDocNode(doc, NULL, (
const xmlChar *)
"KASP", NULL);
1841 (void) xmlDocSetRootElement(doc, root);
1850 while (status == 0) {
1860 xmlSaveFormatFile(
"-", doc, 1);
1881 xmlDocPtr doc = xmlNewDoc((
const xmlChar *)
"1.0");
1884 int prev_policy_id = -1;
1891 printf(
"Failed to connect to database\n");
1898 fprintf(stderr,
"Malloc for zone struct failed\n");
1903 xmlKeepBlanksDefault(0);
1904 xmlTreeIndentString =
" ";
1905 root = xmlNewDocNode(doc, NULL, (
const xmlChar *)
"ZoneList", NULL);
1906 (void) xmlDocSetRootElement(doc, root);
1912 status =
KsmZone(result, zone);
1914 while (status == 0) {
1915 if (zone->
policy_id != prev_policy_id) {
1919 fprintf(stderr,
"Couldn't get name for policy with ID: %d, exiting...\n", zone->
policy_id);
1926 status =
KsmZone(result, zone);
1931 xmlSaveFormatFile(
"-", doc, 1);
1949 FILE* lock_fd = NULL;
1971 printf(
"Failed to connect to database\n");
1982 printf(
"Error, can't find zone : %s\n",
o_zone);
2002 if (data.
value == 1) {
2003 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] ");
2005 user_certain = getchar();
2006 if (user_certain !=
'y' && user_certain !=
'Y') {
2007 printf(
"Okay, quitting...\n");
2013 status =
keyRoll(zone_id, -1, key_type);
2020 snprintf(logmsg, 256,
"Manual key rollover for key type %s on zone %s initiated" , (
o_keytype == NULL) ?
"all" :
o_keytype,
o_zone);
2021 printf(
"\n%s\n", logmsg);
2024 #ifdef HAVE_OPENLOG_R
2029 #ifdef HAVE_SYSLOG_R
2030 syslog_r(LOG_INFO, &sdata,
"%s", logmsg);
2032 syslog(LOG_INFO,
"%s", logmsg);
2034 #ifdef HAVE_CLOSELOG_R
2044 if (restart_enforcerd() != 0)
2046 fprintf(stderr,
"Could not HUP ods-enforcerd\n");
2062 FILE* lock_fd = NULL;
2066 int zone_count = -1;
2085 printf(
"Failed to connect to database\n");
2092 printf(
"Error, can't find policy : %s\n",
o_policy);
2098 printf(
"*WARNING* This will roll all keys on the policy; are you sure? [y/N] ");
2100 user_certain = getchar();
2101 if (user_certain !=
'y' && user_certain !=
'Y') {
2102 printf(
"Okay, quitting...\n");
2117 if (zone_count == 0) {
2118 printf(
"No zones on policy; nothing to roll\n");
2123 printf(
"Couldn't count zones on policy; quitting...\n");
2128 status =
keyRoll(-1, policy_id, key_type);
2135 snprintf(logmsg, 256,
"Manual key rollover for key type %s on policy %s initiated" , (
o_keytype == NULL) ?
"all" :
o_keytype,
o_policy);
2136 printf(
"%s\n", logmsg);
2139 #ifdef HAVE_OPENLOG_R
2144 #ifdef HAVE_SYSLOG_R
2145 syslog_r(LOG_INFO, &sdata,
"%s", logmsg);
2147 syslog(LOG_INFO,
"%s", logmsg);
2149 #ifdef HAVE_CLOSELOG_R
2159 if (restart_enforcerd() != 0)
2161 fprintf(stderr,
"Could not HUP ods-enforcerd\n");
2182 FILE* lock_fd = NULL;
2187 printf(
"Failed to connect to database\n");
2196 printf(
"Error: unable to find a policy named \"%s\" in database\n",
o_policy);
2210 printf(
"Error: unable to find a zone named \"%s\" in database\n",
o_zone);
2220 printf(
"Error: failed to purge dead keys\n");
2246 FILE* lock_fd = NULL;
2251 if (datetime == NULL) {
2252 printf(
"Couldn't turn \"now\" into a date, quitting...\n");
2257 if ( strncmp(qualifier,
"DONE", 4) == 0 ) {
2258 printf(
"*WARNING* One-step backups are deprecated in favour of a two-step process; see the documentation on key management for the explanation.\n");
2261 if (force_flag == 0) {
2262 printf(
"Do you wish to continue? [y/N] ");
2264 user_certain = getchar();
2265 if (user_certain !=
'y' && user_certain !=
'Y') {
2266 printf(
"Okay, quitting...\n");
2275 printf(
"Failed to connect to database\n");
2285 printf(
"Error: unable to find a repository named \"%s\" in database\n",
o_repository);
2293 if (strncmp(qualifier,
"PREPARE", 7) == 0 ||
2294 strncmp(qualifier,
"DONE", 4) == 0 ) {
2297 printf(
"There were no keys to mark\n");
2299 else if (status != 0) {
2300 printf(
"Error: failed to mark pre_backup as done\n");
2305 if (strncmp(qualifier,
"PREPARE", 7) == 0) {
2307 printf(
"Marked repository %s as pre-backed up at %s\n",
o_repository, datetime);
2309 printf(
"Marked all repositories as pre-backed up at %s\n", datetime);
2316 if (strncmp(qualifier,
"COMMIT", 6) == 0 ||
2317 strncmp(qualifier,
"DONE", 4) == 0 ) {
2320 printf(
"There were no keys to mark\n");
2322 else if (status != 0) {
2323 printf(
"Error: failed to mark backup as done\n");
2329 printf(
"Marked repository %s as backed up at %s\n",
o_repository, datetime);
2331 printf(
"Marked all repositories as backed up at %s\n", datetime);
2337 if (strncmp(qualifier,
"ROLLBACK", 6) == 0 ) {
2340 printf(
"There were no keys to rollback\n");
2342 else if (status != 0) {
2343 printf(
"Error: failed to mark backup as done\n");
2349 printf(
"Rolled back pre-backup of repository %s\n",
o_repository);
2351 printf(
"Rolled back pre-backup of all repositories\n");
2373 int qualifier_id = -1;
2377 FILE* lock_fd = NULL;
2382 printf(
"Failed to connect to database\n");
2395 printf(
"Error: unable to find a zone named \"%s\" in database\n",
o_zone);
2402 printf(
"Rollovers:\n");
2407 printf(
"Error: failed to list rollovers\n");
2416 if (verbose_flag && ds_count > 0) {
2418 status =
ListDS(qualifier_id);
2421 printf(
"Error: failed to list DS records\n");
2442 int qualifier_id = -1;
2446 FILE* lock_fd = NULL;
2451 printf(
"Failed to connect to database\n");
2460 printf(
"Error: unable to find a repository named \"%s\" in database\n",
o_repository);
2466 printf(
"Backups:\n");
2470 printf(
"Error: failed to list backups\n");
2493 FILE* lock_fd = NULL;
2498 printf(
"Failed to connect to database\n");
2503 printf(
"Repositories:\n");
2508 printf(
"Error: failed to list repositories\n");
2509 if (lock_fd != NULL) {
2534 FILE* lock_fd = NULL;
2539 printf(
"Failed to connect to database\n");
2544 printf(
"Policies:\n");
2549 printf(
"Error: failed to list policies\n");
2570 int qualifier_id = -1;
2574 FILE* lock_fd = NULL;
2579 printf(
"Failed to connect to database\n");
2592 printf(
"Error: unable to find a zone named \"%s\" in database\n",
o_zone);
2604 printf(
"Error: failed to list keys\n");
2631 int keytag_int = -1;
2632 int temp_key_state = -1;
2633 int temp_keypair_id = -1;
2634 char* temp_cka_id = NULL;
2639 FILE* lock_fd = NULL;
2644 if (datetime == NULL) {
2645 printf(
"Couldn't turn \"now\" into a date, quitting...\n");
2651 printf(
"*WARNING* This will retire the currently active KSK; are you sure? [y/N] ");
2653 user_certain = getchar();
2654 if (user_certain !=
'y' && user_certain !=
'Y') {
2655 printf(
"Okay, quitting...\n");
2662 printf(
"Failed to connect to database\n");
2676 printf(
"Error: unable to find a zone named \"%s\" in database\n",
o_zone);
2689 printf(
"Error: Unable to convert keytag \"%s\"; to an integer\n",
o_keytag);
2695 printf(
"Error: keytag \"%s\"; should be numeric only\n",
o_keytag);
2705 printf(
"Please provide a zone or details of the key to roll\n");
2714 printf(
"Error: failed to count active keys\n");
2721 if (key_count < 2) {
2722 printf(
"Error: completing this action would leave no active keys on zone, quitting...\n");
2731 printf(
"Error: failed to find policy for zone\n");
2740 printf(
"Old key retired\n");
2742 printf(
"Old key NOT retired\n");
2750 status =
CountKeys(&zone_id, keytag_int,
o_cka_id, &key_count, &temp_cka_id, &temp_key_state, &temp_keypair_id);
2752 printf(
"Error: failed to count keys\n");
2759 if (key_count > 1) {
2760 printf(
"More than one key matched your parameters, please include more information from the above keys\n");
2768 printf(
"No keys in the ACTIVE state matched your parameters, please check the parameters\n");
2776 printf(
"Error: failed to count active keys\n");
2783 if (key_count < 2) {
2784 printf(
"Error: completing this action would leave no active keys on zone, quitting...\n");
2793 printf(
"Error: failed to find policy for zone\n");
2804 printf(
"Key %s retired\n", temp_cka_id);
2831 int retired_count = -1;
2832 int keytag_int = -1;
2833 int temp_key_state = -1;
2834 int temp_keypair_id = -1;
2835 char* temp_cka_id = NULL;
2840 FILE* lock_fd = NULL;
2847 if (datetime == NULL) {
2848 printf(
"Couldn't turn \"now\" into a date, quitting...\n");
2855 printf(
"Please provide a keytag or a CKA_ID for the key (CKA_ID will be used if both are provided\n");
2863 printf(
"*WARNING* This will retire the currently active KSK; are you sure? [y/N] ");
2865 user_certain = getchar();
2866 if (user_certain !=
'y' && user_certain !=
'Y') {
2867 printf(
"Okay, quitting...\n");
2874 printf(
"Failed to connect to database\n");
2885 printf(
"Please specify a zone using the --zone flag\n");
2891 else if (
o_zone != NULL) {
2898 printf(
"Error: unable to find a zone named \"%s\" in database\n",
o_zone);
2905 else if (all_flag) {
2906 printf(
"*WARNING* This will act on every zone where this key is in use; are you sure? [y/N] ");
2908 user_certain = getchar();
2909 if (user_certain !=
'y' && user_certain !=
'Y') {
2910 printf(
"Okay, quitting...\n");
2922 printf(
"Error: Unable to convert keytag \"%s\"; to an integer\n",
o_keytag);
2928 printf(
"Error: keytag \"%s\"; should be numeric only\n",
o_keytag);
2939 status =
CountKeys(&zone_id, keytag_int,
o_cka_id, &key_count, &temp_cka_id, &temp_key_state, &temp_keypair_id);
2941 printf(
"Error: failed to count keys\n");
2948 if (key_count > 1) {
2949 printf(
"More than one key matched your parameters, please include more information from the above keys\n");
2957 printf(
"Key is already active\n");
2964 if (key_count == 0) {
2965 printf(
"No keys in the READY state matched your parameters, please check the parameters\n");
2974 printf(
"Error: failed to find policy for zone\n");
2981 status =
MarkDSSeen(temp_keypair_id, zone_id, policy_id, datetime, temp_key_state);
2985 snprintf(logmsg, 256,
"Key %s made %s", temp_cka_id, (temp_key_state ==
KSM_STATE_READY) ?
"active" :
"into standby");
2986 printf(
"%s\n", logmsg);
2989 #ifdef HAVE_OPENLOG_R
2994 #ifdef HAVE_SYSLOG_R
2995 syslog_r(LOG_INFO, &sdata,
"%s", logmsg);
2997 syslog(LOG_INFO,
"%s", logmsg);
2999 #ifdef HAVE_CLOSELOG_R
3009 if (retire_flag == 1) {
3014 printf(
"Error: failed to count active keys\n");
3021 if (key_count < 2) {
3025 printf(
"Error: failed to count retired keys\n");
3034 if (retired_count != 0) {
3035 printf(
"Error: retiring a key would leave no active keys on zone, skipping...\n");
3040 if (notify_flag == 1) {
3041 if (restart_enforcerd() != 0) {
3042 fprintf(stderr,
"Could not HUP ods-enforcerd\n");
3044 fprintf(stdout,
"Performed a HUP ods-enforcerd\n");
3047 fprintf(stdout,
"No HUP ods-enforcerd was performed as the '--no-notify' flag was specified.\n");
3048 fprintf(stdout,
"Warning: The enforcer must be manually notified or the changes will not take full effect until the next scheduled enforcer run.\n");
3058 printf(
"Old key retired\n");
3060 printf(
"Old key NOT retired\n");
3063 printf(
"Old key NOT retired\n");
3067 if (notify_flag == 1) {
3068 if (restart_enforcerd() != 0) {
3069 fprintf(stderr,
"Could not HUP ods-enforcerd\n");
3071 fprintf(stdout,
"Performed a HUP ods-enforcerd\n");
3074 fprintf(stdout,
"No HUP ods-enforcerd was performed as the '--no-notify' flag was specified.\n");
3075 fprintf(stdout,
"Warning: The enforcer must be manually notified or the changes will not take full effect until the next scheduled enforcer run.\n");
3097 char* case_keytype = NULL;
3098 char* case_algorithm = NULL;
3099 char* case_state = NULL;
3104 int cka_id_exists = -1;
3105 int keytype_id = -1;
3112 DB_ID keypair_id = 0;
3121 FILE* lock_fd = NULL;
3128 hsm_key_t *key = NULL;
3133 printf(
"Error: please specify a CKA_ID with the --cka_id <CKA_ID>\n");
3137 printf(
"Error: please specify a repository with the --repository <repository>\n");
3141 printf(
"Error: please specify a zone with the --zone <zone>\n");
3145 printf(
"Error: please specify the number of bits with the --bits <size>\n");
3149 printf(
"Error: please specify the algorithm with the --algorithm <algorithm>\n");
3153 printf(
"Error: please specify the state with the --keystate <state>\n");
3157 printf(
"Error: please specify a keytype, KSK or ZSK, with the --keytype <type>\n");
3161 printf(
"Error: please specify the time of when the key entered the given state with the --time <time>\n");
3166 status = hsm_open(
config, hsm_prompt_pin);
3168 hsm_print_error(NULL);
3171 key = hsm_find_key_by_id(NULL,
o_cka_id);
3174 if(check_repository_flag){
3175 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);
3178 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);
3187 printf(
"Failed to connect to database\n");
3195 printf(
"Error: unable to find a repository named \"%s\" in database\n",
o_repository);
3207 printf(
"Error: unable to find a zone named \"%s\" in database\n",
o_zone);
3219 if (cka_id_exists == 1) {
3220 printf(
"Error: key with CKA_ID \"%s\" already exists in database\n",
o_cka_id);
3228 if (strncmp(case_keytype,
"KSK", 3) == 0 || strncmp(
o_keytype,
"257", 3) == 0) {
3231 else if (strncmp(case_keytype,
"ZSK", 3) == 0 || strncmp(
o_keytype,
"256", 3) == 0) {
3235 printf(
"Error: Unrecognised keytype %s; should be one of KSK or ZSK\n",
o_keytype);
3247 printf(
"Error: Unable to convert bits \"%s\"; to an integer\n",
o_size);
3252 printf(
"Error: Bits \"%s\"; should be numeric only\n",
o_size);
3270 if (status != 0 || algo_id == 0 || hsm_supported_algorithm(algo_id) != 0) {
3271 printf(
"Error: Key algorithm %s not supported; try one of RSASHA1, RSASHA1-NSEC3-SHA1 or RSASHA256\n",
o_algo);
3279 if (strncmp(case_state,
"GENERATE", 8) == 0 || strncmp(
o_keystate,
"1", 1) == 0) {
3282 else if (strncmp(case_state,
"PUBLISH", 7) == 0 || strncmp(
o_keystate,
"2", 1) == 0) {
3285 else if (strncmp(case_state,
"READY", 5) == 0 || strncmp(
o_keystate,
"3", 1) == 0) {
3288 else if (strncmp(case_state,
"ACTIVE", 6) == 0 || strncmp(
o_keystate,
"4", 1) == 0) {
3291 else if (strncmp(case_state,
"RETIRE", 6) == 0 || strncmp(
o_keystate,
"5", 1) == 0) {
3295 printf(
"Error: Unrecognised state %s; should be one of GENERATE, PUBLISH, READY, ACTIVE or RETIRE\n",
o_keystate);
3306 printf(
"Error: unable to convert \"%s\" into a date\n",
o_time);
3313 snprintf(form_time,
KSM_TIME_LENGTH,
"%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d",
3314 datetime.tm_year + 1900, datetime.tm_mon + 1, datetime.tm_mday,
3315 datetime.tm_hour, datetime.tm_min, datetime.tm_sec);
3321 printf(
"Error: unable to specify retire time for a key in state \"%s\"\n",
o_keystate);
3328 printf(
"Error: unable to convert retire time \"%s\" into a date\n",
o_retire);
3335 snprintf(form_opt_time,
KSM_TIME_LENGTH,
"%4.4d-%2.2d-%2.2d %2.2d:%2.2d:%2.2d",
3336 datetime.tm_year + 1900, datetime.tm_mon + 1, datetime.tm_mday,
3337 datetime.tm_hour, datetime.tm_min, datetime.tm_sec);
3341 form_opt_time[0] =
'\0';
3358 if (data.
value == 1) {
3359 printf(
"*WARNING* This zone shares keys with others, the key will be added to all; are you sure? [y/N] ");
3361 user_certain = getchar();
3362 if (user_certain !=
'y' && user_certain !=
'Y') {
3363 printf(
"Okay, quitting...\n");
3370 status =
KsmImportKeyPair(policy_id,
o_cka_id, repo_id, size_int, algo_id, state_id, form_time, fix_time, &keypair_id);
3372 printf(
"Error: couldn't import key\n");
3382 status =
KsmDnssecKeyCreate(zone_id, (
int) keypair_id, keytype_id, state_id, form_time, form_opt_time, &ignore);
3385 printf(
"Error: couldn't allocate key to zone(s)\n");
3390 printf(
"Key imported into zone(s)\n");
3406 FILE* lock_fd = NULL;
3409 char *dbschema = NULL;
3413 char *password = NULL;
3417 char* backup_filename = NULL;
3418 char* lock_filename;
3420 char *path = getenv(
"PWD");
3423 printf(
"Sorry, currently this utility can only backup a sqlite database file\n");
3428 status =
get_db_details(&dbschema, &host, &port, &user, &password);
3439 lock_filename = NULL;
3443 lock_fd = fopen(lock_filename,
"w");
3446 printf(
"Error getting db lock\n");
3447 if (lock_fd != NULL) {
3497 char* kasp_filename = NULL;
3498 char* zonelist_filename = NULL;
3499 char* backup_filename = NULL;
3502 FILE* lock_fd = NULL;
3511 int zone_count = -1;
3513 xmlDocPtr doc = NULL;
3516 printf(
"*WARNING* This feature is experimental and has not been fully tested; are you sure? [y/N] ");
3518 user_certain = getchar();
3519 if (user_certain !=
'y' && user_certain !=
'Y') {
3520 printf(
"Okay, quitting...\n");
3527 printf(
"Failed to read conf.xml\n");
3533 StrAppend(&backup_filename, kasp_filename);
3535 status =
backup_file(kasp_filename, backup_filename);
3545 if ((test = fopen(kasp_filename,
"ab"))==NULL) {
3546 printf(
"Cannot open kasp.xml for writing: %s\n", strerror(errno));
3557 printf(
"Failed to connect to database\n");
3578 if (policy == NULL) {
3579 printf(
"Malloc for policy struct failed\n");
3588 while (status == 0) {
3598 if (zone_count == 0) {
3599 printf(
"No zones on policy %s; purging...\n", policy->
name);
3601 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);
3605 printf(
"Couldn't construct SQL to kill orphaned keys\n");
3628 printf(
"Key purge failed for policy %s\n", policy->
name);
3637 sql2 =
DdsInit(
"parameters_policies");
3681 status = xmlSaveFormatFile(kasp_filename, doc, 1);
3684 printf(
"Could not save %s\n", kasp_filename);
3694 printf(
"Couldn't count zones on policy; quitting...\n");
3732 char* ods_control_cmd = NULL;
3733 char* ptr = command;
3738 *ptr = tolower((
int) *ptr);
3744 StrAppend(&ods_control_cmd, ODS_EN_CONTROL);
3747 status = system(ods_control_cmd);
3750 fprintf(stderr,
"Couldn't run %s\n", ods_control_cmd);
3766 char* case_command = NULL;
3767 char* case_verb = NULL;
3769 int option_index = 0;
3770 static struct option long_options[] =
3772 {
"all", no_argument, 0,
'a'},
3773 {
"auto-accept", no_argument, 0,
'A'},
3774 {
"bits", required_argument, 0,
'b'},
3775 {
"config", required_argument, 0,
'c'},
3776 {
"check-repository", no_argument, 0,
'C'},
3777 {
"ds", no_argument, 0,
'd'},
3778 {
"keystate", required_argument, 0,
'e'},
3779 {
"no-retire", no_argument, 0,
'f'},
3780 {
"force", no_argument, 0,
'F'},
3781 {
"algorithm", required_argument, 0,
'g'},
3782 {
"help", no_argument, 0,
'h'},
3783 {
"input", required_argument, 0,
'i'},
3784 {
"in-type", required_argument, 0,
'j'},
3785 {
"cka_id", required_argument, 0,
'k'},
3786 {
"no-notify", no_argument, 0,
'l'},
3787 {
"no-xml", no_argument, 0,
'm'},
3788 {
"no-hsm", no_argument, 0,
'M'},
3789 {
"interval", required_argument, 0,
'n'},
3790 {
"output", required_argument, 0,
'o'},
3791 {
"policy", required_argument, 0,
'p'},
3792 {
"out-type", required_argument, 0,
'q'},
3793 {
"repository", required_argument, 0,
'r'},
3794 {
"signerconf", required_argument, 0,
's'},
3795 {
"keytype", required_argument, 0,
't'},
3796 {
"time", required_argument, 0,
'w'},
3797 {
"verbose", no_argument, 0,
'v'},
3798 {
"version", no_argument, 0,
'V'},
3799 {
"keytag", required_argument, 0,
'x'},
3800 {
"retire", required_argument, 0,
'y'},
3801 {
"zone", required_argument, 0,
'z'},
3802 {
"zonetotal", required_argument, 0,
'Z'},
3808 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) {
3814 auto_accept_flag = 1;
3823 check_repository_flag = 1;
3887 printf(
"%s version %s\n", PACKAGE_NAME, PACKAGE_VERSION);
3945 if (!strncmp(case_command,
"SETUP", 5)) {
3949 }
else if (!strncmp(case_command,
"UPDATE", 6)) {
3953 }
else if (!strncmp(case_command,
"START", 5) ||
3954 !strncmp(case_command,
"STOP", 4) ||
3955 !strncmp(case_command,
"NOTIFY", 6)) {
3959 }
else if (!strncmp(case_command,
"ZONE", 4) && strlen(case_command) == 4) {
3964 if (!strncmp(case_verb,
"ADD", 3)) {
3966 }
else if (!strncmp(case_verb,
"DELETE", 6)) {
3968 }
else if (!strncmp(case_verb,
"LIST", 4)) {
3971 printf(
"Unknown command: zone %s\n", case_verb);
3975 }
else if (!strncmp(case_command,
"REPOSITORY", 10)) {
3979 if (!strncmp(case_verb,
"LIST", 4)) {
3982 printf(
"Unknown command: repository %s\n", case_verb);
3986 }
else if (!strncmp(case_command,
"POLICY", 6)) {
3990 if (!strncmp(case_verb,
"EXPORT", 6)) {
3992 }
else if (!strncmp(case_verb,
"IMPORT", 6)) {
3994 }
else if (!strncmp(case_verb,
"LIST", 4)) {
3996 }
else if (!strncmp(case_verb,
"PURGE", 5)) {
3999 printf(
"Unknown command: policy %s\n", case_verb);
4003 }
else if (!strncmp(case_command,
"KEY", 3)) {
4007 if (!strncmp(case_verb,
"LIST", 4)) {
4010 else if (!strncmp(case_verb,
"EXPORT", 6)) {
4013 else if (!strncmp(case_verb,
"IMPORT", 6)) {
4016 else if (!strncmp(case_verb,
"ROLLOVER", 8)) {
4018 if (all_flag == 0 &&
o_keytype == NULL) {
4019 printf(
"Please specify either a keytype, KSK or ZSK, with the --keytype <type> option or use the --all option\n");
4032 printf(
"Please provide either a zone OR a policy to rollover\n");
4038 else if (!strncmp(case_verb,
"PURGE", 5)) {
4044 printf(
"Please provide either a zone OR a policy to key purge\n");
4049 else if (!strncmp(case_verb,
"GENERATE", 8)) {
4052 else if (!strncmp(case_verb,
"KSK-RETIRE", 10)) {
4055 else if (!strncmp(case_verb,
"DS-SEEN", 7)) {
4057 }
else if (!strncmp(case_verb,
"DELETE", 6)) {
4060 printf(
"Unknown command: key %s\n", case_verb);
4064 }
else if (!strncmp(case_command,
"BACKUP", 6)) {
4068 if (!strncmp(case_verb,
"DONE", 4) ||
4069 !strncmp(case_verb,
"PREPARE", 7) ||
4070 !strncmp(case_verb,
"COMMIT", 6) ||
4071 !strncmp(case_verb,
"ROLLBACK", 8)) {
4074 else if (!strncmp(case_verb,
"LIST", 4)) {
4077 printf(
"Unknown command: backup %s\n", case_verb);
4081 }
else if (!strncmp(case_command,
"ROLLOVER", 8)) {
4084 if (!strncmp(case_verb,
"LIST", 4)) {
4087 printf(
"Unknown command: rollover %s\n", case_verb);
4091 }
else if (!strncmp(case_command,
"DATABASE", 8)) {
4095 if (!strncmp(case_verb,
"BACKUP", 6)) {
4098 printf(
"Unknown command: database %s\n", case_verb);
4102 }
else if (!strncmp(case_command,
"ZONELIST", 8)) {
4106 if (!strncmp(case_verb,
"EXPORT", 6)) {
4109 else if (!strncmp(case_verb,
"IMPORT", 6)) {
4112 printf(
"Unknown command: zonelist %s\n", case_verb);
4117 printf(
"Unknown command: %s\n", argv[0]);
4129 xmlCleanupGlobals();
4130 xmlCleanupThreads();
4152 char *dbschema = NULL;
4156 char *password = NULL;
4160 char* backup_filename = NULL;
4161 char* lock_filename;
4164 status =
get_db_details(&dbschema, &host, &port, &user, &password);
4180 if (lock_fd != NULL) {
4181 lock_filename = NULL;
4185 *lock_fd = fopen(lock_filename,
"w");
4188 printf(
"Error getting db lock\n");
4189 if (*lock_fd != NULL) {
4213 if (lock_fd != NULL) {
4228 status =
DbConnect(dbhandle, dbschema, host, password, user, port);
4250 if (lock_fd != NULL) {
4253 printf(
"Error releasing db lock");
4275 if (lock_fd == NULL) {
4276 printf(
"%s could not be opened\n", lock_filename);
4280 memset(&fl, 0,
sizeof(
struct flock));
4281 fl.l_type = F_WRLCK;
4282 fl.l_whence = SEEK_SET;
4283 fl.l_pid = getpid();
4285 while (fcntl(fileno(lock_fd), F_SETLK, &fl) == -1) {
4287 printf(
"couldn't get lock on %s; %s\n", lock_filename, strerror(errno));
4290 if (errno == EACCES || errno == EAGAIN) {
4291 printf(
"%s already locked, sleep\n", lock_filename);
4296 select(0, NULL, NULL, NULL, &tv);
4301 printf(
"couldn't get lock on %s; %s\n", lock_filename, strerror(errno));
4314 if (lock_fd == NULL) {
4318 memset(&fl, 0,
sizeof(
struct flock));
4319 fl.l_type = F_UNLCK;
4320 fl.l_whence = SEEK_SET;
4322 if (fcntl(fileno(lock_fd), F_SETLK, &fl) == -1) {
4335 xmlTextReaderPtr reader = NULL;
4336 xmlDocPtr doc = NULL;
4337 xmlXPathContextPtr xpathCtx = NULL;
4338 xmlXPathObjectPtr xpathObj = NULL;
4340 char* tag_name = NULL;
4341 char* temp_char = NULL;
4343 xmlChar *zonelist_expr = (
unsigned char*)
"//Common/ZoneListFile";
4344 xmlChar *kaspfile_expr = (
unsigned char*)
"//Common/PolicyFile";
4347 reader = xmlNewTextReaderFilename(
config);
4348 if (reader != NULL) {
4349 ret = xmlTextReaderRead(reader);
4351 tag_name = (
char*) xmlTextReaderLocalName(reader);
4353 if (strncmp(tag_name,
"Common", 6) == 0
4354 && xmlTextReaderNodeType(reader) == 1) {
4357 xmlTextReaderExpand(reader);
4358 doc = xmlTextReaderCurrentDoc(reader);
4360 printf(
"Error: can not read Common section\n");
4362 ret = xmlTextReaderRead(reader);
4366 xpathCtx = xmlXPathNewContext(doc);
4367 if(xpathCtx == NULL) {
4368 printf(
"Error: can not create XPath context for Common section\n");
4370 ret = xmlTextReaderRead(reader);
4375 xpathObj = xmlXPathEvalExpression(zonelist_expr, xpathCtx);
4376 if(xpathObj == NULL) {
4377 printf(
"Error: unable to evaluate xpath expression: %s\n", zonelist_expr);
4379 ret = xmlTextReaderRead(reader);
4382 *zone_list_filename = NULL;
4383 temp_char = (
char*) xmlXPathCastToString(xpathObj);
4384 StrAppend(zone_list_filename, temp_char);
4386 xmlXPathFreeObject(xpathObj);
4387 printf(
"zonelist filename set to %s.\n", *zone_list_filename);
4390 xpathObj = xmlXPathEvalExpression(kaspfile_expr, xpathCtx);
4391 xmlXPathFreeContext(xpathCtx);
4392 if(xpathObj == NULL) {
4393 printf(
"Error: unable to evaluate xpath expression: %s\n", kaspfile_expr);
4395 ret = xmlTextReaderRead(reader);
4398 *kasp_filename = NULL;
4399 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
4403 temp_char = (
char*) xmlXPathCastToString(xpathObj);
4411 StrAppend(kasp_filename, OPENDNSSEC_CONFIG_DIR);
4414 printf(
"kasp filename set to %s.\n", *kasp_filename);
4416 xmlXPathFreeObject(xpathObj);
4419 ret = xmlTextReaderRead(reader);
4423 xmlFreeTextReader(reader);
4425 printf(
"%s : failed to parse\n",
config);
4429 printf(
"Unable to open %s\n",
config);
4446 xmlDocPtr doc = NULL;
4447 xmlXPathContextPtr xpathCtx = NULL;
4448 xmlXPathObjectPtr xpathObj = NULL;
4450 char* repo_name = NULL;
4451 char* repo_capacity = NULL;
4452 int require_backup = 0;
4455 xmlChar *node_expr = (
unsigned char*)
"//Configuration/RepositoryList/Repository";
4459 doc = xmlParseFile(
config);
4461 printf(
"Unable to open %s\n",
config);
4466 xpathCtx = xmlXPathNewContext(doc);
4467 if(xpathCtx == NULL) {
4473 xpathObj = xmlXPathEvalExpression(node_expr, xpathCtx);
4474 if(xpathObj == NULL) {
4475 xmlXPathFreeContext(xpathCtx);
4480 if (xpathObj->nodesetval) {
4481 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
4486 curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
4487 repo_name = (
char *) xmlGetProp(xpathObj->nodesetval->nodeTab[i],
4488 (
const xmlChar *)
"name");
4490 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Capacity")) {
4491 repo_capacity = (
char *) xmlNodeGetContent(curNode);
4493 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"RequireBackup")) {
4497 curNode = curNode->next;
4500 if (strlen(repo_name) != 0) {
4502 printf(
"Repository %s found\n", repo_name);
4503 if (strlen(repo_capacity) == 0) {
4504 printf(
"No Maximum Capacity set.\n");
4510 printf(
"Capacity set to %s.\n", repo_capacity);
4516 if (require_backup == 0) {
4517 printf(
"RequireBackup NOT set; please make sure that you know the potential problems of using keys which are not recoverable\n");
4519 printf(
"RequireBackup set.\n");
4523 printf(
"Error Importing Repository %s", repo_name);
4527 printf(
"WARNING: Repository found with NULL name, skipping...\n");
4535 xmlXPathFreeObject(xpathObj);
4538 xmlXPathFreeContext(xpathCtx);
4553 char *policy_name = NULL;
4554 char *policy_description = NULL;
4557 xmlDocPtr doc = NULL;
4558 xmlDocPtr pol_doc = NULL;
4559 xmlDocPtr rngdoc = NULL;
4562 xmlNode *childNode2;
4563 xmlNode *childNode3;
4564 xmlChar *opt_out_flag = (xmlChar *)
"N";
4565 xmlChar *nsec3param_ttl = NULL ;
4566 xmlChar *share_keys_flag = (xmlChar *)
"N";
4567 xmlChar *man_roll_flag = (xmlChar *)
"N";
4568 xmlChar *rfc5011_flag = (xmlChar *)
"N";
4569 int standby_keys_flag = 0;
4570 xmlXPathContextPtr xpathCtx = NULL;
4571 xmlXPathObjectPtr xpathObj = NULL;
4572 xmlRelaxNGParserCtxtPtr rngpctx = NULL;
4573 xmlRelaxNGValidCtxtPtr rngctx = NULL;
4574 xmlRelaxNGPtr schema = NULL;
4577 xmlChar *node_expr = (
unsigned char*)
"//Policy";
4583 int algo_change = 0;
4585 char* changes_made = NULL;
4590 const char* rngfilename = OPENDNSSEC_SCHEMA_DIR
"/kasp.rng";
4591 char* kaspcheck_cmd = NULL;
4592 char* kaspcheck_cmd_version = NULL;
4594 StrAppend(&kaspcheck_cmd, ODS_EN_KASPCHECK);
4598 StrAppend(&kaspcheck_cmd_version, ODS_EN_KASPCHECK);
4599 StrAppend(&kaspcheck_cmd_version,
" --version > /dev/null");
4602 status = system(kaspcheck_cmd_version);
4605 status = system(kaspcheck_cmd);
4608 fprintf(stderr,
"ods-kaspcheck returned an error, please check your policy\n");
4610 StrFree(kaspcheck_cmd_version);
4616 fprintf(stderr,
"Couldn't run ods-kaspcheck, will carry on\n");
4620 StrFree(kaspcheck_cmd_version);
4623 doc = xmlParseFile(kasp_filename);
4625 printf(
"Error: unable to parse file \"%s\"\n", kasp_filename);
4630 rngdoc = xmlParseFile(rngfilename);
4631 if (rngdoc == NULL) {
4632 printf(
"Error: unable to parse file \"%s\"\n", rngfilename);
4637 rngpctx = xmlRelaxNGNewDocParserCtxt(rngdoc);
4638 if (rngpctx == NULL) {
4639 printf(
"Error: unable to create XML RelaxNGs parser context\n");
4644 schema = xmlRelaxNGParse(rngpctx);
4645 if (schema == NULL) {
4646 printf(
"Error: unable to parse a schema definition resource\n");
4651 rngctx = xmlRelaxNGNewValidCtxt(schema);
4652 if (rngctx == NULL) {
4653 printf(
"Error: unable to create RelaxNGs validation context based on the schema\n");
4658 status = xmlRelaxNGValidateDoc(rngctx,doc);
4660 printf(
"Error validating file \"%s\"\n", kasp_filename);
4666 if (policy == NULL) {
4667 printf(
"Malloc for policy struct failed");
4672 xpathCtx = xmlXPathNewContext(doc);
4673 if(xpathCtx == NULL) {
4680 xpathObj = xmlXPathEvalExpression(node_expr, xpathCtx);
4681 if(xpathObj == NULL) {
4682 xmlXPathFreeContext(xpathCtx);
4688 if (xpathObj->nodesetval) {
4694 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
4696 curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
4697 policy_name = (
char *) xmlGetProp(xpathObj->nodesetval->nodeTab[i], (
const xmlChar *)
"name");
4698 if (strlen(policy_name) == 0) {
4700 printf(
"Error extracting policy name from %s\n", kasp_filename);
4713 printf(
"Error: unable to read policy %s; skipping\n", policy_name);
4718 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Keys")) {
4719 childNode = curNode->children;
4721 if (xmlStrEqual(childNode->name, (
const xmlChar *)
"KSK")) {
4722 childNode2 = childNode->children;
4724 if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Algorithm")) {
4727 status =
StrStrtoi((
char *)xmlNodeGetContent(childNode2), &value);
4729 printf(
"Error extracting KSK algorithm for policy %s, exiting...", policy_name);
4735 printf(
"\n\nAlgorithm change attempted... details:\n");
4736 StrAppend(&changes_made,
"Algorithm changes made, details:");
4739 size = snprintf(tmp_change,
KSM_MSG_LENGTH,
"Policy: %s, KSK algorithm changed from %d to %d.", policy_name, policy->
ksk->
algorithm, value);
4742 printf(
"Error constructing log message for policy %s, exiting...", policy_name);
4745 printf(
"%s\n", tmp_change);
4751 childNode2 = childNode2->next;
4756 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"ZSK")) {
4757 childNode2 = childNode->children;
4759 if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Algorithm")) {
4762 status =
StrStrtoi((
char *)xmlNodeGetContent(childNode2), &value);
4764 printf(
"Error extracting ZSK algorithm for policy %s, exiting...", policy_name);
4770 printf(
"\n\nAlgorithm change attempted... details:\n");
4771 StrAppend(&changes_made,
"Algorithm changes made, details:");
4774 size = snprintf(tmp_change,
KSM_MSG_LENGTH,
"Policy: %s, ZSK algorithm changed from %d to %d.", policy_name, policy->
zsk->
algorithm, value);
4777 printf(
"Error constructing log message for policy %s, exiting...", policy_name);
4780 printf(
"%s\n", tmp_change);
4786 childNode2 = childNode2->next;
4791 childNode = childNode->next;
4794 curNode = curNode->next;
4806 if (algo_change == 1 && force_flag == 0) {
4807 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] ");
4809 user_certain = getchar();
4810 if (user_certain !=
'y' && user_certain !=
'Y') {
4811 printf(
"\nOkay, quitting...\n");
4812 xmlXPathFreeContext(xpathCtx);
4825 #ifdef HAVE_OPENLOG_R
4830 #ifdef HAVE_SYSLOG_R
4831 syslog_r(LOG_INFO, &sdata,
"%s", changes_made);
4833 syslog(LOG_INFO,
"%s", changes_made);
4835 #ifdef HAVE_CLOSELOG_R
4846 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
4848 curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
4849 policy_name = (
char *) xmlGetProp(xpathObj->nodesetval->nodeTab[i], (
const xmlChar *)
"name");
4850 if (strlen(policy_name) == 0) {
4852 printf(
"Error extracting policy name from %s\n", kasp_filename);
4856 printf(
"Policy %s found\n", policy_name);
4858 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Description")) {
4859 policy_description = (
char *) xmlNodeGetContent(curNode);
4869 printf(
"Error: unable to read policy %s; skipping\n", policy_name);
4870 curNode = curNode->next;
4878 printf(
"Error: unable to update policy description for %s; skipping\n", policy_name);
4880 curNode = curNode->next;
4889 printf(
"Error: unable to insert policy %s; skipping\n", policy_name);
4891 curNode = curNode->next;
4897 printf(
"Error: unable to get policy id for %s; skipping\n", policy_name);
4898 curNode = curNode->next;
4904 else if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Signatures")) {
4905 childNode = curNode->children;
4907 if (xmlStrEqual(childNode->name, (
const xmlChar *)
"Resign")) {
4910 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"Refresh")) {
4913 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"Validity")) {
4914 childNode2 = childNode->children;
4916 if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Default")) {
4919 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Denial")) {
4922 childNode2 = childNode2->next;
4925 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"Jitter")) {
4928 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"InceptionOffset")) {
4931 childNode = childNode->next;
4934 else if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Denial")) {
4935 opt_out_flag = (xmlChar *)
"N";
4936 childNode = curNode->children;
4938 if (xmlStrEqual(childNode->name, (
const xmlChar *)
"NSEC3")) {
4942 printf(
"Error: unable to insert/update %s for policy\n",
"Denial version");
4944 childNode2 = childNode->children;
4946 if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"OptOut")) {
4947 opt_out_flag = (xmlChar *)
"Y";
4949 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Resalt")) {
4952 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"TTL")) {
4953 nsec3param_ttl = xmlNodeGetContent(childNode2);
4955 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Hash")) {
4956 childNode3 = childNode2->children;
4958 if (xmlStrEqual(childNode3->name, (
const xmlChar *)
"Algorithm")) {
4961 else if (xmlStrEqual(childNode3->name, (
const xmlChar *)
"Iterations")) {
4964 else if (xmlStrEqual(childNode3->name, (
const xmlChar *)
"Salt")) {
4967 childNode3 = childNode3->next;
4971 childNode2 = childNode2->next;
4975 if (nsec3param_ttl == NULL)
4976 nsec3param_ttl = (xmlChar *)
StrStrdup(
"PT0S");
4978 nsec3param_ttl = NULL;
4980 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"NSEC")) {
4983 printf(
"Error: unable to insert/update %s for policy\n",
"Denial version");
4986 childNode = childNode->next;
4989 else if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Keys")) {
4990 share_keys_flag = (xmlChar *)
"N";
4991 childNode = curNode->children;
4993 if (xmlStrEqual(childNode->name, (
const xmlChar *)
"TTL")) {
4996 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"RetireSafety")) {
4999 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"PublishSafety")) {
5002 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"ShareKeys")) {
5003 share_keys_flag = (xmlChar *)
"Y";
5005 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"Purge")) {
5009 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"KSK")) {
5010 man_roll_flag = (xmlChar *)
"N";
5011 rfc5011_flag = (xmlChar *)
"N";
5012 childNode2 = childNode->children;
5014 if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Algorithm")) {
5019 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Lifetime")) {
5022 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Repository")) {
5024 printf(
"Please either add the repository to conf.xml or remove the reference to it from kasp.xml\n");
5026 xmlFreeDoc(pol_doc);
5027 xmlXPathFreeContext(xpathCtx);
5028 xmlRelaxNGFree(schema);
5029 xmlRelaxNGFreeValidCtxt(rngctx);
5030 xmlRelaxNGFreeParserCtxt(rngpctx);
5038 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Standby")) {
5040 standby_keys_flag = 1;
5042 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"ManualRollover")) {
5043 man_roll_flag = (xmlChar *)
"Y";
5045 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"RFC5011")) {
5046 rfc5011_flag = (xmlChar *)
"Y";
5051 childNode2 = childNode2->next;
5056 if (standby_keys_flag == 0) {
5059 standby_keys_flag = 0;
5063 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"ZSK")) {
5064 man_roll_flag = (xmlChar *)
"N";
5065 childNode2 = childNode->children;
5067 if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Algorithm")) {
5072 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Lifetime")) {
5075 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Repository")) {
5077 printf(
"Please either add the repository to conf.xml or remove the reference to it from kasp.xml\n");
5079 xmlFreeDoc(pol_doc);
5080 xmlXPathFreeContext(xpathCtx);
5081 xmlRelaxNGFree(schema);
5082 xmlRelaxNGFreeValidCtxt(rngctx);
5083 xmlRelaxNGFreeParserCtxt(rngpctx);
5091 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Standby")) {
5093 standby_keys_flag = 1;
5095 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"ManualRollover")) {
5096 man_roll_flag = (xmlChar *)
"Y";
5098 childNode2 = childNode2->next;
5104 childNode = childNode->next;
5108 if (standby_keys_flag == 0) {
5111 standby_keys_flag = 0;
5116 else if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Zone")) {
5117 childNode = curNode->children;
5119 if (xmlStrEqual(childNode->name, (
const xmlChar *)
"PropagationDelay")) {
5122 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"SOA")) {
5123 childNode2 = childNode->children;
5125 if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"TTL")) {
5128 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Minimum")) {
5131 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Serial")) {
5134 childNode2 = childNode2->next;
5137 childNode = childNode->next;
5141 else if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Parent")) {
5142 childNode = curNode->children;
5144 if (xmlStrEqual(childNode->name, (
const xmlChar *)
"PropagationDelay")) {
5147 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"DS")) {
5148 childNode2 = childNode->children;
5150 if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"TTL")) {
5153 childNode2 = childNode2->next;
5156 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"SOA")) {
5157 childNode2 = childNode->children;
5159 if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"TTL")) {
5162 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Minimum")) {
5165 childNode2 = childNode2->next;
5168 childNode = childNode->next;
5172 curNode = curNode->next;
5183 xmlXPathFreeContext(xpathCtx);
5184 xmlRelaxNGFree(schema);
5185 xmlRelaxNGFreeValidCtxt(rngctx);
5186 xmlRelaxNGFreeParserCtxt(rngpctx);
5200 xmlDocPtr doc = NULL;
5201 xmlDocPtr rngdoc = NULL;
5204 xmlNode *childNode2;
5205 xmlXPathContextPtr xpathCtx = NULL;
5206 xmlXPathObjectPtr xpathObj = NULL;
5207 xmlRelaxNGParserCtxtPtr rngpctx = NULL;
5208 xmlRelaxNGValidCtxtPtr rngctx = NULL;
5209 xmlRelaxNGPtr schema = NULL;
5211 char* zone_name = NULL;
5212 char* policy_name = NULL;
5213 char* current_policy = NULL;
5214 char* current_signconf = NULL;
5215 char* current_input = NULL;
5216 char* current_output = NULL;
5217 char* current_in_type = NULL;
5218 char* current_out_type = NULL;
5221 int file_zone_count = 0;
5222 int db_zone_count = 0;
5236 xmlChar *node_expr = (
unsigned char*)
"//Zone";
5237 const char* rngfilename = OPENDNSSEC_SCHEMA_DIR
"/zonelist.rng";
5240 doc = xmlParseFile(zone_list_filename);
5242 printf(
"Error: unable to parse file \"%s\"\n", zone_list_filename);
5247 rngdoc = xmlParseFile(rngfilename);
5248 if (rngdoc == NULL) {
5249 printf(
"Error: unable to parse file \"%s\"\n", rngfilename);
5254 rngpctx = xmlRelaxNGNewDocParserCtxt(rngdoc);
5255 if (rngpctx == NULL) {
5256 printf(
"Error: unable to create XML RelaxNGs parser context\n");
5261 schema = xmlRelaxNGParse(rngpctx);
5262 if (schema == NULL) {
5263 printf(
"Error: unable to parse a schema definition resource\n");
5268 rngctx = xmlRelaxNGNewValidCtxt(schema);
5269 if (rngctx == NULL) {
5270 printf(
"Error: unable to create RelaxNGs validation context based on the schema\n");
5275 status = xmlRelaxNGValidateDoc(rngctx,doc);
5277 printf(
"Error validating file \"%s\"\n", zone_list_filename);
5282 xpathCtx = xmlXPathNewContext(doc);
5283 if(xpathCtx == NULL) {
5289 xpathObj = xmlXPathEvalExpression(node_expr, xpathCtx);
5290 if(xpathObj == NULL) {
5291 xmlXPathFreeContext(xpathCtx);
5296 if (xpathObj->nodesetval) {
5297 file_zone_count = xpathObj->nodesetval->nodeNr;
5299 printf(
"Error extracting zone count from %s\n", zone_list_filename);
5300 xmlXPathFreeContext(xpathCtx);
5306 zone_ids =
MemMalloc(file_zone_count *
sizeof(
int));
5308 if (xpathObj->nodesetval) {
5309 for (i = 0; i < file_zone_count; i++) {
5311 curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
5312 zone_name = (
char *) xmlGetProp(xpathObj->nodesetval->nodeTab[i], (
const xmlChar *)
"name");
5313 if (strlen(zone_name) == 0) {
5315 printf(
"Error extracting zone name from %s\n", zone_list_filename);
5328 printf(
"Zone %s found; ", zone_name);
5331 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Policy")) {
5332 current_policy = (
char *) xmlNodeGetContent(curNode);
5334 printf(
"policy set to %s\n", current_policy);
5337 if (policy_name == NULL || strcmp(current_policy, policy_name) != 0) {
5339 StrAppend(&policy_name, current_policy);
5343 printf(
"ERROR, can't find policy %s.\n", policy_name);
5350 else if (xmlStrEqual(curNode->name, (
const xmlChar *)
"SignerConfiguration")) {
5351 current_signconf = (
char *) xmlNodeGetContent(curNode);
5354 else if (xmlStrEqual(curNode->name, (
const xmlChar *)
"Adapters")) {
5355 childNode = curNode->children;
5358 if (xmlStrEqual(childNode->name, (
const xmlChar *)
"Input")) {
5359 childNode2 = childNode->children;
5361 if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Adapter")) {
5362 current_input = (
char *) xmlNodeGetContent(childNode2);
5363 current_in_type = (
char *) xmlGetProp(childNode2, (
const xmlChar *)
"type");
5365 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"File")) {
5366 current_input = (
char *) xmlNodeGetContent(childNode2);
5367 current_in_type = (
char *) childNode2->name;
5369 childNode2 = childNode2->next;
5373 else if (xmlStrEqual(childNode->name, (
const xmlChar *)
"Output")) {
5374 childNode2 = childNode->children;
5376 if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"Adapter")) {
5377 current_output = (
char *) xmlNodeGetContent(childNode2);
5378 current_out_type = (
char *) xmlGetProp(childNode2, (
const xmlChar *)
"type");
5380 else if (xmlStrEqual(childNode2->name, (
const xmlChar *)
"File")) {
5381 current_output = (
char *) xmlNodeGetContent(childNode2);
5382 current_out_type = (
char *) childNode2->name;
5384 childNode2 = childNode2->next;
5387 childNode = childNode->next;
5390 curNode = curNode->next;
5396 status =
KsmImportZone(zone_name, policy_id, 0, &new_zone, current_signconf, current_input, current_output, current_in_type, current_out_type);
5399 printf(
"Error Importing zone %s; it already exists both with and without a trailing dot\n", zone_name);
5401 printf(
"Error Importing Zone %s\n", zone_name);
5407 if (new_zone == 1) {
5408 printf(
"Added zone %s to database\n", zone_name);
5414 printf(
"Error: unable to find a zone named \"%s\" in database\n", zone_name);
5415 printf(
"Error: Possibly two domains differ only by having a trailing dot or not?\n");
5421 zone_ids[i] = temp_id;
5429 xmlXPathFreeContext(xpathCtx);
5430 xmlRelaxNGFree(schema);
5431 xmlRelaxNGFreeValidCtxt(rngctx);
5432 xmlRelaxNGFreeParserCtxt(rngpctx);
5445 if (file_zone_count == db_zone_count) {
5450 else if (file_zone_count > db_zone_count) {
5451 printf(
"Failed to add all zones from zonelist\n");
5467 while (status == 0) {
5468 DbInt(row, 0, &temp_id);
5470 DbInt(row, 2, &policy_id);
5473 for (i = 0; i < db_zone_count; ++i) {
5474 if (temp_id == zone_ids[i]) {
5480 if (seen_zone == 0) {
5483 printf(
"Removing zone %s from database\n", zone_name);
5485 status =
KsmParameterInit(&result2,
"zones_share_keys",
"keys", policy_id);
5511 if ((shared.
value == 1 && temp_count == 1) || shared.
value == 0) {
5514 printf(
"Error: failed to mark keys as dead in database\n");
5549 int SetParamOnPolicy(
const xmlChar* new_value,
const char* name,
const char* category,
int current_value,
int policy_id,
int value_type)
5553 char* temp_char = (
char *)new_value;
5557 if (strlen(temp_char) != 0) {
5560 printf(
"Error: unable to convert interval %s to seconds, error: %i\n", temp_char, status);
5564 else if (status == -1) {
5565 printf(
"Info: converting %s to seconds; M interpreted as 31 days, Y interpreted as 365 days\n", temp_char);
5574 if (strncmp(temp_char,
"Y", 1) == 0) {
5584 printf(
"Error: unable to find repository %s\n", temp_char);
5594 printf(
"Error: unable to find serial type %s\n", temp_char);
5604 printf(
"Error: unable to find rollover scheme %s\n", temp_char);
5613 printf(
"Error: unable to convert %s to int\n", temp_char);
5623 if (value != current_value || current_value == 0) {
5626 printf(
"Error: unable to insert/update %s for policy\n", name);
5627 printf(
"Error: Is your database schema up to date?\n");
5633 if (strncmp(name,
"saltlength", 10) == 0) {
5636 printf(
"Error: unable to insert/update %s for policy\n", name);
5637 printf(
"Error: Is your database schema up to date?\n");
5648 if (policy == NULL) {
5649 printf(
"Error, no policy provided");
5686 policy->
ksk->
sm = 0;
5698 policy->
zsk->
sm = 0;
5735 if((from = fopen( orig_file,
"rb"))==NULL) {
5736 if (errno == ENOENT) {
5737 printf(
"File %s does not exist, nothing to backup\n", orig_file);
5741 printf(
"Cannot open source file.\n");
5747 if((to = fopen(backup_file,
"wb"))==NULL) {
5748 printf(
"Cannot open destination file, will not make backup.\n");
5754 while(!feof(from)) {
5757 printf(
"Error reading source file.\n");
5762 if(!feof(from)) fputc(ch, to);
5764 printf(
"Error writing destination file.\n");
5771 if(fclose(from)==EOF) {
5772 printf(
"Error closing source file.\n");
5777 if(fclose(to)==EOF) {
5778 printf(
"Error closing destination file.\n");
5796 get_db_details(
char** dbschema,
char** host,
char** port,
char** user,
char** password)
5801 xmlXPathContextPtr xpathCtx;
5802 xmlXPathObjectPtr xpathObj;
5803 xmlRelaxNGParserCtxtPtr rngpctx;
5804 xmlRelaxNGValidCtxtPtr rngctx;
5805 xmlRelaxNGPtr schema;
5806 xmlChar *litexpr = (
unsigned char*)
"//Configuration/Enforcer/Datastore/SQLite";
5807 xmlChar *mysql_host = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Host";
5808 xmlChar *mysql_port = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Host/@port";
5809 xmlChar *mysql_db = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Database";
5810 xmlChar *mysql_user = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Username";
5811 xmlChar *mysql_pass = (
unsigned char*)
"//Configuration/Enforcer/Datastore/MySQL/Password";
5815 char* temp_char = NULL;
5818 const char* rngfilename = OPENDNSSEC_SCHEMA_DIR
"/conf.rng";
5821 doc = xmlParseFile(
config);
5823 printf(
"Error: unable to parse file \"%s\"\n",
config);
5828 rngdoc = xmlParseFile(rngfilename);
5829 if (rngdoc == NULL) {
5830 printf(
"Error: unable to parse file \"%s\"\n", rngfilename);
5836 rngpctx = xmlRelaxNGNewDocParserCtxt(rngdoc);
5838 if (rngpctx == NULL) {
5839 printf(
"Error: unable to create XML RelaxNGs parser context\n");
5845 schema = xmlRelaxNGParse(rngpctx);
5846 xmlRelaxNGFreeParserCtxt(rngpctx);
5847 if (schema == NULL) {
5848 printf(
"Error: unable to parse a schema definition resource\n");
5854 rngctx = xmlRelaxNGNewValidCtxt(schema);
5855 if (rngctx == NULL) {
5856 printf(
"Error: unable to create RelaxNGs validation context based on the schema\n");
5857 xmlRelaxNGFree(schema);
5863 status = xmlRelaxNGValidateDoc(rngctx,doc);
5864 xmlRelaxNGFreeValidCtxt(rngctx);
5865 xmlRelaxNGFree(schema);
5867 printf(
"Error validating file \"%s\"\n",
config);
5874 xpathCtx = xmlXPathNewContext(doc);
5875 if(xpathCtx == NULL) {
5876 printf(
"Error: unable to create new XPath context\n");
5882 xpathObj = xmlXPathEvalExpression(litexpr, xpathCtx);
5883 if(xpathObj == NULL) {
5884 printf(
"Error: unable to evaluate xpath expression: %s\n", litexpr);
5885 xmlXPathFreeContext(xpathCtx);
5889 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
5891 temp_char = (
char *)xmlXPathCastToString(xpathObj);
5895 fprintf(stderr,
"SQLite database set to: %s\n", *dbschema);
5898 xmlXPathFreeObject(xpathObj);
5900 if (db_found == 0) {
5905 xpathObj = xmlXPathEvalExpression(mysql_host, xpathCtx);
5906 if(xpathObj == NULL) {
5907 printf(
"Error: unable to evaluate xpath expression: %s\n", mysql_host);
5908 xmlXPathFreeContext(xpathCtx);
5912 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
5913 temp_char = (
char *)xmlXPathCastToString(xpathObj);
5917 fprintf(stderr,
"MySQL database host set to: %s\n", *host);
5920 xmlXPathFreeObject(xpathObj);
5923 xpathObj = xmlXPathEvalExpression(mysql_port, xpathCtx);
5924 if(xpathObj == NULL) {
5925 printf(
"Error: unable to evaluate xpath expression: %s\n", mysql_port);
5926 xmlXPathFreeContext(xpathCtx);
5930 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
5931 temp_char = (
char *)xmlXPathCastToString(xpathObj);
5935 fprintf(stderr,
"MySQL database port set to: %s\n", *port);
5938 xmlXPathFreeObject(xpathObj);
5941 xpathObj = xmlXPathEvalExpression(mysql_db, xpathCtx);
5942 if(xpathObj == NULL) {
5943 printf(
"Error: unable to evaluate xpath expression: %s\n", mysql_db);
5944 xmlXPathFreeContext(xpathCtx);
5948 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
5949 temp_char = (
char *)xmlXPathCastToString(xpathObj);
5953 fprintf(stderr,
"MySQL database schema set to: %s\n", *dbschema);
5958 xmlXPathFreeObject(xpathObj);
5961 xpathObj = xmlXPathEvalExpression(mysql_user, xpathCtx);
5962 if(xpathObj == NULL) {
5963 printf(
"Error: unable to evaluate xpath expression: %s\n", mysql_user);
5964 xmlXPathFreeContext(xpathCtx);
5968 if(xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
5969 temp_char = (
char *)xmlXPathCastToString(xpathObj);
5973 fprintf(stderr,
"MySQL database user set to: %s\n", *user);
5978 xmlXPathFreeObject(xpathObj);
5981 xpathObj = xmlXPathEvalExpression(mysql_pass, xpathCtx);
5982 if(xpathObj == NULL) {
5983 printf(
"Error: unable to evaluate xpath expression: %s\n", mysql_pass);
5984 xmlXPathFreeContext(xpathCtx);
5989 temp_char = (
char *)xmlXPathCastToString(xpathObj);
5992 xmlXPathFreeObject(xpathObj);
5995 fprintf(stderr,
"MySQL database password set\n");
6000 xmlXPathFreeContext(xpathCtx);
6005 printf(
"Error: unable to find complete database connection expression\n");
6011 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");
6025 xmlTextReaderPtr reader = NULL;
6026 xmlDocPtr doc = NULL;
6027 xmlXPathContextPtr xpathCtx = NULL;
6028 xmlXPathObjectPtr xpathObj = NULL;
6030 char* temp_char = NULL;
6031 char* tag_name = NULL;
6033 xmlChar *zonelist_expr = (
unsigned char*)
"//Common/ZoneListFile";
6036 reader = xmlNewTextReaderFilename(
config);
6037 if (reader != NULL) {
6038 ret = xmlTextReaderRead(reader);
6040 tag_name = (
char*) xmlTextReaderLocalName(reader);
6042 if (strncmp(tag_name,
"Common", 6) == 0
6043 && xmlTextReaderNodeType(reader) == 1) {
6046 xmlTextReaderExpand(reader);
6047 doc = xmlTextReaderCurrentDoc(reader);
6049 printf(
"Error: can not read Common section\n");
6051 ret = xmlTextReaderRead(reader);
6055 xpathCtx = xmlXPathNewContext(doc);
6056 if(xpathCtx == NULL) {
6057 printf(
"Error: can not create XPath context for Common section\n");
6059 ret = xmlTextReaderRead(reader);
6064 xpathObj = xmlXPathEvalExpression(zonelist_expr, xpathCtx);
6065 if(xpathObj == NULL) {
6066 printf(
"Error: unable to evaluate xpath expression: %s\n", zonelist_expr);
6068 ret = xmlTextReaderRead(reader);
6071 *zone_list_filename = NULL;
6072 temp_char = (
char *)xmlXPathCastToString(xpathObj);
6073 xmlXPathFreeObject(xpathObj);
6074 StrAppend(zone_list_filename, temp_char);
6076 printf(
"zonelist filename set to %s.\n", *zone_list_filename);
6079 ret = xmlTextReaderRead(reader);
6082 xmlFreeTextReader(reader);
6084 printf(
"%s : failed to parse\n",
config);
6088 printf(
"Unable to open %s\n",
config);
6092 xmlXPathFreeContext(xpathCtx);
6102 const char *zone_name,
6103 const char *policy_name,
6104 const char *sig_conf_name,
6105 const char *input_name,
6106 const char *output_name,
6107 const char *input_type,
6108 const char *output_type)
6112 xmlNodePtr newzonenode;
6113 xmlNodePtr newadaptnode;
6114 xmlNodePtr newinputnode;
6115 xmlNodePtr newinadnode;
6116 xmlNodePtr newoutputnode;
6117 xmlNodePtr newoutadnode;
6118 doc = xmlParseFile(docname);
6120 fprintf(stderr,
"Document not parsed successfully. \n");
6123 cur = xmlDocGetRootElement(doc);
6125 fprintf(stderr,
"empty document\n");
6129 if (xmlStrcmp(cur->name, (
const xmlChar *)
"ZoneList")) {
6130 fprintf(stderr,
"document of the wrong type, root node != %s",
"ZoneList");
6134 newzonenode = xmlNewTextChild(cur, NULL, (
const xmlChar *)
"Zone", NULL);
6135 (void) xmlNewProp(newzonenode, (
const xmlChar *)
"name", (
const xmlChar *)zone_name);
6137 (void) xmlNewTextChild (newzonenode, NULL, (
const xmlChar *)
"Policy", (
const xmlChar *)policy_name);
6139 (void) xmlNewTextChild (newzonenode, NULL, (
const xmlChar *)
"SignerConfiguration", (
const xmlChar *)sig_conf_name);
6141 newadaptnode = xmlNewChild (newzonenode, NULL, (
const xmlChar *)
"Adapters", NULL);
6143 newinputnode = xmlNewChild (newadaptnode, NULL, (
const xmlChar *)
"Input", NULL);
6145 newinadnode = xmlNewTextChild (newinputnode, NULL, (
const xmlChar *)
"Adapter", (
const xmlChar *)input_name);
6146 (void) xmlNewProp(newinadnode, (
const xmlChar *)
"type", (
const xmlChar *)input_type);
6148 newoutputnode = xmlNewChild (newadaptnode, NULL, (
const xmlChar *)
"Output", NULL);
6150 newoutadnode = xmlNewTextChild (newoutputnode, NULL, (
const xmlChar *)
"Adapter", (
const xmlChar *)output_name);
6151 (void) xmlNewProp(newoutadnode, (
const xmlChar *)
"type", (
const xmlChar *)output_type);
6157 const char *zone_name)
6163 doc = xmlParseFile(docname);
6165 fprintf(stderr,
"Document not parsed successfully. \n");
6168 root = xmlDocGetRootElement(doc);
6170 fprintf(stderr,
"empty document\n");
6174 if (xmlStrcmp(root->name, (
const xmlChar *)
"ZoneList")) {
6175 fprintf(stderr,
"document of the wrong type, root node != %s",
"ZoneList");
6181 if (all_flag == 1) {
6182 cur = root->children;
6188 cur = root->children;
6194 for(cur = root->children; cur != NULL; cur = cur->next)
6197 if (xmlStrcmp( xmlGetProp(cur, (xmlChar *)
"name"), (
const xmlChar *) zone_name) == 0)
6201 cur = root->children;
6216 xmlChar *polChar = NULL;
6217 xmlChar *propChar = NULL;
6223 doc = xmlParseFile(docname);
6225 fprintf(stderr,
"Document not parsed successfully. \n");
6228 root = xmlDocGetRootElement(doc);
6230 fprintf(stderr,
"empty document\n");
6234 if (xmlStrcmp(root->name, (
const xmlChar *)
"ZoneList")) {
6235 fprintf(stderr,
"document of the wrong type, root node != %s",
"ZoneList");
6241 for(cur = root->children; cur != NULL; cur = cur->next)
6243 if (xmlStrcmp( cur->name, (
const xmlChar *)
"Zone") == 0) {
6244 propChar = xmlGetProp(cur, (xmlChar *)
"name");
6245 printf(
"Found Zone: %s", propChar);
6251 printf(
" (zone not in database)");
6254 zone_ids[i] = temp_id;
6259 for(pol = cur->children; pol != NULL; pol = pol->next)
6261 if (xmlStrcmp( pol->name, (
const xmlChar *)
"Policy") == 0)
6263 polChar = xmlNodeGetContent(pol);
6264 printf(
"; on policy %s\n", polChar);
6283 xmlNodePtr policy_node;
6284 xmlNodePtr signatures_node;
6285 xmlNodePtr validity_node;
6286 xmlNodePtr denial_node;
6287 xmlNodePtr nsec_node;
6288 xmlNodePtr hash_node;
6289 xmlNodePtr salt_node;
6290 xmlNodePtr keys_node;
6291 xmlNodePtr ksk_node;
6292 xmlNodePtr ksk_alg_node;
6293 xmlNodePtr zsk_node;
6294 xmlNodePtr zsk_alg_node;
6295 xmlNodePtr zone_node;
6296 xmlNodePtr zone_soa_node;
6297 xmlNodePtr parent_node;
6298 xmlNodePtr parent_ds_node;
6299 xmlNodePtr parent_soa_node;
6303 root = xmlDocGetRootElement(doc);
6305 fprintf(stderr,
"empty document\n");
6308 if (xmlStrcmp(root->name, (
const xmlChar *)
"KASP")) {
6309 fprintf(stderr,
"document of the wrong type, root node != %s",
"KASP");
6313 policy_node = xmlNewTextChild(root, NULL, (
const xmlChar *)
"Policy", NULL);
6314 (void) xmlNewProp(policy_node, (
const xmlChar *)
"name", (
const xmlChar *)policy->
name);
6315 (void) xmlNewTextChild(policy_node, NULL, (
const xmlChar *)
"Description", (
const xmlChar *)policy->
description);
6318 signatures_node = xmlNewTextChild(policy_node, NULL, (
const xmlChar *)
"Signatures", NULL);
6320 (void) xmlNewTextChild(signatures_node, NULL, (
const xmlChar *)
"Resign", (
const xmlChar *)temp_time);
6322 (void) xmlNewTextChild(signatures_node, NULL, (
const xmlChar *)
"Refresh", (
const xmlChar *)temp_time);
6323 validity_node = xmlNewTextChild(signatures_node, NULL, (
const xmlChar *)
"Validity", NULL);
6325 (void) xmlNewTextChild(validity_node, NULL, (
const xmlChar *)
"Default", (
const xmlChar *)temp_time);
6327 (void) xmlNewTextChild(validity_node, NULL, (
const xmlChar *)
"Denial", (
const xmlChar *)temp_time);
6328 snprintf(temp_time, 32,
"PT%dS", policy->
signer->
jitter);
6329 (void) xmlNewTextChild(signatures_node, NULL, (
const xmlChar *)
"Jitter", (
const xmlChar *)temp_time);
6331 (void) xmlNewTextChild(signatures_node, NULL, (
const xmlChar *)
"InceptionOffset", (
const xmlChar *)temp_time);
6334 denial_node = xmlNewTextChild(policy_node, NULL, (
const xmlChar *)
"Denial", NULL);
6337 (void) xmlNewTextChild(denial_node, NULL, (
const xmlChar *)
"NSEC", NULL);
6341 nsec_node = xmlNewTextChild(denial_node, NULL, (
const xmlChar *)
"NSEC3", NULL);
6343 snprintf(temp_time, 32,
"PT%dS", policy->
denial->
ttl);
6344 (void) xmlNewTextChild(nsec_node, NULL, (
const xmlChar *)
"TTL", (
const xmlChar *)temp_time);
6348 (void) xmlNewTextChild(nsec_node, NULL, (
const xmlChar *)
"OptOut", NULL);
6350 snprintf(temp_time, 32,
"PT%dS", policy->
denial->
resalt);
6351 (void) xmlNewTextChild(nsec_node, NULL, (
const xmlChar *)
"Resalt", (
const xmlChar *)temp_time);
6352 hash_node = xmlNewTextChild(nsec_node, NULL, (
const xmlChar *)
"Hash", NULL);
6354 (void) xmlNewTextChild(hash_node, NULL, (
const xmlChar *)
"Algorithm", (
const xmlChar *)temp_time);
6356 (void) xmlNewTextChild(hash_node, NULL, (
const xmlChar *)
"Iterations", (
const xmlChar *)temp_time);
6358 salt_node = xmlNewTextChild(hash_node, NULL, (
const xmlChar *)
"Salt", NULL);
6359 (void) xmlNewProp(salt_node, (
const xmlChar *)
"length", (
const xmlChar *)temp_time);
6363 keys_node = xmlNewTextChild(policy_node, NULL, (
const xmlChar *)
"Keys", NULL);
6364 snprintf(temp_time, 32,
"PT%dS", policy->
keys->
ttl);
6365 (void) xmlNewTextChild(keys_node, NULL, (
const xmlChar *)
"TTL", (
const xmlChar *)temp_time);
6367 (void) xmlNewTextChild(keys_node, NULL, (
const xmlChar *)
"RetireSafety", (
const xmlChar *)temp_time);
6369 (void) xmlNewTextChild(keys_node, NULL, (
const xmlChar *)
"PublishSafety", (
const xmlChar *)temp_time);
6372 (void) xmlNewTextChild(keys_node, NULL, (
const xmlChar *)
"ShareKeys", NULL);
6375 snprintf(temp_time, 32,
"PT%dS", policy->
keys->
purge);
6376 (void) xmlNewTextChild(keys_node, NULL, (
const xmlChar *)
"Purge", (
const xmlChar *)temp_time);
6380 ksk_node = xmlNewTextChild(keys_node, NULL, (
const xmlChar *)
"KSK", NULL);
6382 ksk_alg_node = xmlNewTextChild(ksk_node, NULL, (
const xmlChar *)
"Algorithm", (
const xmlChar *)temp_time);
6383 snprintf(temp_time, 32,
"%d", policy->
ksk->
bits);
6384 (void) xmlNewProp(ksk_alg_node, (
const xmlChar *)
"length", (
const xmlChar *)temp_time);
6385 snprintf(temp_time, 32,
"PT%dS", policy->
ksk->
lifetime);
6386 (void) xmlNewTextChild(ksk_node, NULL, (
const xmlChar *)
"Lifetime", (
const xmlChar *)temp_time);
6387 (void) xmlNewTextChild(ksk_node, NULL, (
const xmlChar *)
"Repository", (
const xmlChar *)policy->
ksk->
sm_name);
6389 (void) xmlNewTextChild(ksk_node, NULL, (
const xmlChar *)
"Standby", (
const xmlChar *)temp_time);
6392 (void) xmlNewTextChild(ksk_node, NULL, (
const xmlChar *)
"ManualRollover", NULL);
6396 (void) xmlNewTextChild(ksk_node, NULL, (
const xmlChar *)
"RFC5011", NULL);
6404 zsk_node = xmlNewTextChild(keys_node, NULL, (
const xmlChar *)
"ZSK", NULL);
6406 zsk_alg_node = xmlNewTextChild(zsk_node, NULL, (
const xmlChar *)
"Algorithm", (
const xmlChar *)temp_time);
6407 snprintf(temp_time, 32,
"%d", policy->
zsk->
bits);
6408 (void) xmlNewProp(zsk_alg_node, (
const xmlChar *)
"length", (
const xmlChar *)temp_time);
6409 snprintf(temp_time, 32,
"PT%dS", policy->
zsk->
lifetime);
6410 (void) xmlNewTextChild(zsk_node, NULL, (
const xmlChar *)
"Lifetime", (
const xmlChar *)temp_time);
6411 (void) xmlNewTextChild(zsk_node, NULL, (
const xmlChar *)
"Repository", (
const xmlChar *)policy->
zsk->
sm_name);
6413 (void) xmlNewTextChild(zsk_node, NULL, (
const xmlChar *)
"Standby", (
const xmlChar *)temp_time);
6416 (void) xmlNewTextChild(zsk_node, NULL, (
const xmlChar *)
"ManualRollover", NULL);
6420 zone_node = xmlNewTextChild(policy_node, NULL, (
const xmlChar *)
"Zone", NULL);
6422 (void) xmlNewTextChild(zone_node, NULL, (
const xmlChar *)
"PropagationDelay", (
const xmlChar *)temp_time);
6423 zone_soa_node = xmlNewTextChild(zone_node, NULL, (
const xmlChar *)
"SOA", NULL);
6424 snprintf(temp_time, 32,
"PT%dS", policy->
zone->
soa_ttl);
6425 (void) xmlNewTextChild(zone_soa_node, NULL, (
const xmlChar *)
"TTL", (
const xmlChar *)temp_time);
6426 snprintf(temp_time, 32,
"PT%dS", policy->
zone->
soa_min);
6427 (void) xmlNewTextChild(zone_soa_node, NULL, (
const xmlChar *)
"Minimum", (
const xmlChar *)temp_time);
6431 parent_node = xmlNewTextChild(policy_node, NULL, (
const xmlChar *)
"Parent", NULL);
6433 (void) xmlNewTextChild(parent_node, NULL, (
const xmlChar *)
"PropagationDelay", (
const xmlChar *)temp_time);
6434 parent_ds_node = xmlNewTextChild(parent_node, NULL, (
const xmlChar *)
"DS", NULL);
6435 snprintf(temp_time, 32,
"PT%dS", policy->
parent->
ds_ttl);
6436 (void) xmlNewTextChild(parent_ds_node, NULL, (
const xmlChar *)
"TTL", (
const xmlChar *)temp_time);
6437 parent_soa_node = xmlNewTextChild(parent_node, NULL, (
const xmlChar *)
"SOA", NULL);
6439 (void) xmlNewTextChild(parent_soa_node, NULL, (
const xmlChar *)
"TTL", (
const xmlChar *)temp_time);
6441 (void) xmlNewTextChild(parent_soa_node, NULL, (
const xmlChar *)
"Minimum", (
const xmlChar *)temp_time);
6450 const char *policy_name)
6456 doc = xmlParseFile(docname);
6458 fprintf(stderr,
"Document not parsed successfully. \n");
6461 root = xmlDocGetRootElement(doc);
6463 fprintf(stderr,
"empty document\n");
6467 if (xmlStrcmp(root->name, (
const xmlChar *)
"KASP")) {
6468 fprintf(stderr,
"document of the wrong type, root node != %s",
"KASP");
6475 for(cur = root->children; cur != NULL; cur = cur->next)
6478 if (xmlStrcmp( xmlGetProp(cur, (xmlChar *)
"name"), (
const xmlChar *) policy_name) == 0)
6482 cur = root->children;
6498 fprintf(stdout,
"KSK:");
6502 fprintf(stdout,
"ZSK:");
6504 fprintf(stdout,
" %s Retired\n", key_data->
location);
6516 fprintf(stderr,
"%s\n", format);
6543 char* temp_zone = NULL;
6546 char* temp_ready = NULL;
6547 char* temp_active = NULL;
6548 char* temp_retire = NULL;
6549 char* temp_dead = NULL;
6550 char* temp_loc = NULL;
6551 char* temp_hsm = NULL;
6556 hsm_key_t *key = NULL;
6557 ldns_rr *dnskey_rr = NULL;
6558 hsm_sign_params_t *sign_params = NULL;
6562 status = hsm_open(
config, hsm_prompt_pin);
6564 hsm_print_error(NULL);
6570 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 from securitymodules s, zones z, KEYDATA_VIEW k where z.id = k.zone_id and s.id = k.securitymodule_id and state != 6 and zone_id is not null ");
6571 if (zone_id != -1) {
6584 if (verbose_flag == 1) {
6585 printf(
"Zone: Keytype: State: Date of next transition (to): Size: Algorithm: CKA_ID: Repository: Keytag:\n");
6588 printf(
"Zone: Keytype: State: Date of next transition:\n");
6590 while (status == 0) {
6593 DbInt(row, 1, &temp_type);
6594 DbInt(row, 2, &temp_state);
6601 DbInt(row, 9, &temp_alg);
6602 DbInt(row, 10, &temp_size);
6615 printf(
"(active) ");
6620 printf(
"%-31s %-13s %-9s %-20s", temp_zone, (temp_type ==
KSM_TYPE_KSK) ?
"KSK" :
"ZSK",
KsmKeywordStateValueToName(temp_state), (temp_retire == NULL) ?
"(not scheduled)" : temp_retire);
6622 printf(
"(retire) ");
6641 printf(
"%-31s %-13s %-9s %-20s", temp_zone,
"KSK",
KsmKeywordStateValueToName(temp_state), (temp_ready == NULL) ?
"(not scheduled)" : temp_ready);
6643 printf(
"(dsready) ");
6650 printf(
"(keypub) ");
6655 printf(
"%-31s %-13s %-9s %-20s", temp_zone,
"KSK",
KsmKeywordStateValueToName(temp_state), (temp_active == NULL) ?
"(not scheduled)" : temp_active);
6657 printf(
"(active) ");
6662 if (done_row == 1 && verbose_flag == 1) {
6663 printf(
"%-7d %-12d", temp_size, temp_alg);
6664 key = hsm_find_key_by_id(NULL, temp_loc);
6666 printf(
"%-33s %s NOT IN repository\n", temp_loc, temp_hsm);
6668 sign_params = hsm_sign_params_new();
6669 sign_params->owner = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, temp_zone);
6670 sign_params->algorithm = temp_alg;
6671 sign_params->flags = LDNS_KEY_ZONE_KEY;
6673 sign_params->flags += LDNS_KEY_SEP_KEY;
6675 dnskey_rr = hsm_get_dnskey(NULL, key, sign_params);
6676 sign_params->keytag = ldns_calc_keytag(dnskey_rr);
6678 printf(
"%-33s %-33s %d\n", temp_loc, temp_hsm, sign_params->keytag);
6680 hsm_sign_params_free(sign_params);
6684 else if (done_row == 1) {
6711 if (dnskey_rr != NULL) {
6712 ldns_rr_free(dnskey_rr);
6754 char* temp_loc = NULL;
6757 int done_something = 0;
6760 hsm_key_t *key = NULL;
6762 if ((zone_id == -1 && policy_id == -1) ||
6763 (zone_id != -1 && policy_id != -1)){
6764 printf(
"Please provide either a zone OR a policy to key purge\n");
6770 status = hsm_open(
config, hsm_prompt_pin);
6772 hsm_print_error(NULL);
6777 StrAppend(&sql,
"select distinct id, location from KEYDATA_VIEW where state = 6 ");
6778 if (zone_id != -1) {
6783 if (policy_id != -1) {
6794 while (status == 0) {
6796 DbInt(row, 0, &temp_id);
6856 key = hsm_find_key_by_id(NULL, temp_loc);
6859 printf(
"Key not found: %s\n", temp_loc);
6867 status = hsm_remove_key(NULL, key);
6872 printf(
"Key remove successful: %s\n", temp_loc);
6874 printf(
"Key remove failed: %s\n", temp_loc);
6896 if (done_something == 0) {
6897 printf(
"No keys to purge.\n");
6917 hsm_ctx_t *ctx = NULL;
6922 hsm_key_t *key = NULL;
6923 char *hsm_error_message = NULL;
6925 int ksks_needed = 0;
6926 int zsks_needed = 0;
6927 int ksks_in_queue = 0;
6928 int zsks_in_queue = 0;
6931 unsigned int current_count = 0;
6937 int ksks_created = 0;
6941 FILE* lock_fd = NULL;
6949 printf(
"Failed to connect to database\n");
6955 if (policy == NULL) {
6956 printf(
"Malloc for policy struct failed\n");
6962 printf(
"Please provide a policy name with the --policy option\n");
6968 printf(
"Please provide an interval with the --interval option\n");
6981 printf(
"Error: unable to read policy %s from database\n",
o_policy);
6987 printf(
"Error: policy %s doesn't exist in database\n",
o_policy);
6994 printf(
"Key sharing is On\n");
6996 printf(
"Key sharing is Off\n");
7001 printf(
"Error: unable to convert Interval %s to seconds, error: ",
o_interval);
7004 printf(
"invalid interval-type.\n");
7007 printf(
"unable to translate string.\n");
7010 printf(
"interval too long to be an int. E.g. Maximum is ~68 years on a system with 32-bit integers.\n");
7013 printf(
"invalid pointers or text string NULL.\n");
7016 printf(
"unknown\n");
7022 else if (status == -1) {
7023 printf(
"Info: converting %s to seconds; M interpreted as 31 days, Y interpreted as 365 days\n",
o_interval);
7027 status = hsm_open(
config, hsm_prompt_pin);
7029 hsm_error_message = hsm_get_error(ctx);
7030 if (hsm_error_message) {
7031 printf(
"%s\n", hsm_error_message);
7032 free(hsm_error_message);
7038 printf(
"hsm_open() result: HSM error\n");
7040 case HSM_PIN_INCORRECT:
7041 printf(
"hsm_open() result: incorrect PIN\n");
7043 case HSM_CONFIG_FILE_ERROR:
7044 printf(
"hsm_open() result: config file error\n");
7046 case HSM_REPOSITORY_NOT_FOUND:
7047 printf(
"hsm_open() result: repository not found\n");
7049 case HSM_NO_REPOSITORIES:
7050 printf(
"hsm_open() result: no repositories\n");
7053 printf(
"hsm_open() result: %d", status);
7060 printf(
"HSM opened successfully.\n");
7061 ctx = hsm_create_context();
7066 if (rightnow == NULL) {
7067 printf(
"Couldn't turn \"now\" into a date, quitting...\n");
7088 printf(
"Could not count zones on policy %s\n", policy->
name);
7091 hsm_destroy_context(ctx);
7097 printf(
"Info: %d zone(s) found on policy \"%s\"\n", zone_count, policy->
name);
7106 printf(
"Error: Unable to convert zonetotal \"%s\"; to an integer\n",
o_zonetotal);
7113 printf(
"Error: zonetotal \"%s\"; should be numeric only\n",
o_zonetotal);
7120 if (zone_count < 1) {
7121 printf(
"Error: zonetotal parameter value of %d is invalid - the value must be greater than 0\n", zone_count);
7127 printf(
"Info: Keys will actually be generated for a total of %d zone(s) as specified by zone total parameter\n", zone_count);
7131 if (zone_count == 0) {
7132 printf(
"No zones on policy %s, skipping...\n", policy->
name);
7135 hsm_destroy_context(ctx);
7146 printf(
"Could not predict ksk requirement for next interval for %s\n", policy->
name);
7155 printf(
"Could not count current ksk numbers for policy %s\n", policy->
name);
7163 new_ksks = ksks_needed - ksks_in_queue;
7169 printf(
"Could not predict zsk requirement for next interval for %s\n", policy->
name);
7178 printf(
"Could not count current zsk numbers for policy %s\n", policy->
name);
7189 if (new_ksks >= 0) {
7194 zsks_in_queue -= ksks_needed;
7198 new_zsks = zsks_needed - zsks_in_queue;
7204 if (policy->
ksk->
sm_capacity != 0 && (new_ksks + new_zsks) > 0) {
7205 current_count = hsm_count_keys_repository(ctx, policy->
ksk->
sm_name);
7207 printf(
"Repository %s is full, cannot create more keys for policy %s\n", policy->
ksk->
sm_name, policy->
name);
7211 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);
7214 else if (current_count + new_ksks + new_zsks > policy->
ksk->
sm_capacity) {
7215 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);
7224 current_count = hsm_count_keys_repository(ctx, policy->
ksk->
sm_name);
7226 printf(
"Repository %s is full, cannot create more KSKs for policy %s\n", policy->
ksk->
sm_name, policy->
name);
7230 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);
7237 current_count = hsm_count_keys_repository(ctx, policy->
zsk->
sm_name);
7239 printf(
"Repository %s is full, cannot create more ZSKs for policy %s\n", policy->
zsk->
sm_name, policy->
name);
7243 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);
7250 if (new_ksks <= 0 && new_zsks <= 0) {
7251 printf(
"No keys need to be created, quitting...\n");
7254 hsm_destroy_context(ctx);
7256 status = hsm_close();
7257 printf(
"all done! hsm_close result: %d\n", status);
7264 if (!auto_accept_flag) {
7265 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);
7267 user_certain = getchar();
7268 if (user_certain !=
'y' && user_certain !=
'Y') {
7269 printf(
"Okay, quitting...\n");
7272 hsm_destroy_context(ctx);
7274 status = hsm_close();
7275 printf(
"all done! hsm_close result: %d\n", status);
7283 for (i=new_ksks ; i > 0 ; i--){
7284 if (hsm_supported_algorithm(policy->
ksk->
algorithm) == 0) {
7289 printf(
"Created key in repository %s\n", policy->
ksk->
sm_name);
7292 printf(
"Error creating key in repository %s\n", policy->
ksk->
sm_name);
7293 hsm_error_message = hsm_get_error(ctx);
7294 if (hsm_error_message) {
7295 printf(
"%s\n", hsm_error_message);
7296 free(hsm_error_message);
7303 id = hsm_get_key_id(ctx, key);
7307 printf(
"Error creating key in Database\n");
7308 hsm_error_message = hsm_get_error(ctx);
7309 if (hsm_error_message) {
7310 printf(
"%s\n", hsm_error_message);
7311 free(hsm_error_message);
7318 printf(
"Created KSK size: %i, alg: %i with id: %s in repository: %s and database.\n", policy->
ksk->
bits,
7322 printf(
"Key algorithm %d unsupported by libhsm.\n", policy->
ksk->
algorithm);
7329 ksks_created = new_ksks;
7332 for (i = new_zsks ; i > 0 ; i--) {
7333 if (hsm_supported_algorithm(policy->
zsk->
algorithm) == 0) {
7338 printf(
"Created key in repository %s\n", policy->
zsk->
sm_name);
7341 printf(
"Error creating key in repository %s\n", policy->
zsk->
sm_name);
7342 hsm_error_message = hsm_get_error(ctx);
7343 if (hsm_error_message) {
7344 printf(
"%s\n", hsm_error_message);
7345 free(hsm_error_message);
7352 id = hsm_get_key_id(ctx, key);
7356 printf(
"Error creating key in Database\n");
7357 hsm_error_message = hsm_get_error(ctx);
7358 if (hsm_error_message) {
7359 printf(
"%s\n", hsm_error_message);
7360 free(hsm_error_message);
7367 printf(
"Created ZSK size: %i, alg: %i with id: %s in repository: %s and database.\n", policy->
zsk->
bits,
7371 printf(
"Key algorithm %d unsupported by libhsm.\n", policy->
zsk->
algorithm);
7382 printf(
"NOTE: keys generated in repository %s will not become active until they have been backed up\n", policy->
ksk->
sm_name);
7385 printf(
"NOTE: keys generated in repository %s will not become active until they have been backed up\n", policy->
zsk->
sm_name);
7392 hsm_destroy_context(ctx);
7394 status = hsm_close();
7395 printf(
"all done! hsm_close result: %d\n", status);
7410 int keypair_id = -1;
7414 FILE* lock_fd = NULL;
7419 hsm_key_t *key = NULL;
7423 printf(
"Please provide a CKA_ID for the key to delete\n");
7431 printf(
"Failed to connect to database\n");
7439 if (status != 0 || key_state == -1) {
7440 printf(
"Failed to determine the state of the key\n");
7447 if (force_flag == 1) {
7448 printf(
"*WARNING* This will delete a key that the enforcer believes is in use; are you really sure? [y/N] ");
7450 user_certain = getchar();
7451 if (user_certain !=
'y' && user_certain !=
'Y') {
7452 printf(
"Okay, quitting...\n");
7457 printf(
"The enforcer believes that this key is in use, quitting...\n");
7490 if (hsm_flag == 1) {
7492 status = hsm_open(
config, hsm_prompt_pin);
7494 hsm_print_error(NULL);
7499 key = hsm_find_key_by_id(NULL,
o_cka_id);
7502 printf(
"Key not found in HSM: %s\n",
o_cka_id);
7507 status = hsm_remove_key(NULL, key);
7514 printf(
"Key delete successful: %s\n",
o_cka_id);
7516 printf(
"Key delete failed: %s\n",
o_cka_id);
7527 struct stat stat_ret;
7531 xmlDocPtr doc = NULL;
7532 xmlDocPtr rngdoc = NULL;
7533 xmlXPathContextPtr xpathCtx = NULL;
7534 xmlXPathObjectPtr xpathObj = NULL;
7535 xmlRelaxNGParserCtxtPtr rngpctx = NULL;
7536 xmlRelaxNGValidCtxtPtr rngctx = NULL;
7537 xmlRelaxNGPtr schema = NULL;
7538 xmlChar *user_expr = (
unsigned char*)
"//Configuration/Enforcer/Privileges/User";
7539 xmlChar *group_expr = (
unsigned char*)
"//Configuration/Enforcer/Privileges/Group";
7541 char* filename = OPENDNSSEC_CONFIG_FILE;
7542 char* rngfilename = OPENDNSSEC_SCHEMA_DIR
"/conf.rng";
7543 char* temp_char = NULL;
7550 char *username = NULL;
7551 char *groupname = NULL;
7553 printf(
"fixing permissions on file %s\n", dbschema);
7555 if (geteuid() != 0) {
7560 if (stat(dbschema, &stat_ret) != 0) {
7561 printf(
"cannot stat file %s: %s", dbschema, strerror(errno));
7567 doc = xmlParseFile(filename);
7569 printf(
"Error: unable to parse file \"%s\"", filename);
7574 rngdoc = xmlParseFile(rngfilename);
7575 if (rngdoc == NULL) {
7576 printf(
"Error: unable to parse file \"%s\"", rngfilename);
7581 rngpctx = xmlRelaxNGNewDocParserCtxt(rngdoc);
7582 if (rngpctx == NULL) {
7583 printf(
"Error: unable to create XML RelaxNGs parser context");
7588 schema = xmlRelaxNGParse(rngpctx);
7589 if (schema == NULL) {
7590 printf(
"Error: unable to parse a schema definition resource");
7595 rngctx = xmlRelaxNGNewValidCtxt(schema);
7596 if (rngctx == NULL) {
7597 printf(
"Error: unable to create RelaxNGs validation context based on the schema");
7602 status = xmlRelaxNGValidateDoc(rngctx,doc);
7604 printf(
"Error validating file \"%s\"", filename);
7610 xpathCtx = xmlXPathNewContext(doc);
7611 if(xpathCtx == NULL) {
7612 printf(
"Error: unable to create new XPath context");
7618 xpathObj = xmlXPathEvalExpression(group_expr, xpathCtx);
7619 if(xpathObj == NULL) {
7620 printf(
"Error: unable to evaluate xpath expression: %s", group_expr);
7621 xmlXPathFreeContext(xpathCtx);
7625 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
7626 temp_char = (
char*) xmlXPathCastToString(xpathObj);
7629 xmlXPathFreeObject(xpathObj);
7635 xpathObj = xmlXPathEvalExpression(user_expr, xpathCtx);
7636 if(xpathObj == NULL) {
7637 printf(
"Error: unable to evaluate xpath expression: %s", user_expr);
7638 xmlXPathFreeContext(xpathCtx);
7642 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
7643 temp_char = (
char*) xmlXPathCastToString(xpathObj);
7646 xmlXPathFreeObject(xpathObj);
7652 xmlXPathFreeContext(xpathCtx);
7653 xmlRelaxNGFree(schema);
7654 xmlRelaxNGFreeValidCtxt(rngctx);
7655 xmlRelaxNGFreeParserCtxt(rngpctx);
7660 if (username != NULL) {
7662 if ((pwd = getpwnam(username)) == NULL) {
7663 printf(
"user '%s' does not exist. cannot chown %s...\n", username, dbschema);
7672 if ((grp = getgrnam(groupname)) == NULL) {
7673 printf(
"group '%s' does not exist. cannot chown %s...\n", groupname, dbschema);
7682 if (chown(dbschema, uid, gid) == -1) {
7683 printf(
"cannot chown(%u,%u) %s: %s",
7684 (
unsigned) uid, (
unsigned) gid, dbschema, strerror(errno));
7693 if (chown(temp_char, uid, gid) == -1) {
7694 printf(
"cannot chown(%u,%u) %s: %s",
7695 (
unsigned) uid, (
unsigned) gid, temp_char, strerror(errno));
7737 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)
7750 int temp_zone_id = 0;
7751 char* temp_loc = NULL;
7754 int temp_keypair = 0;
7759 hsm_key_t *key = NULL;
7760 ldns_rr *dnskey_rr = NULL;
7761 hsm_sign_params_t *sign_params = NULL;
7764 status = hsm_open(
config, hsm_prompt_pin);
7766 hsm_print_error(NULL);
7771 nchar = snprintf(buffer,
sizeof(buffer),
"(%d, %d, %d)",
7773 if (nchar >=
sizeof(buffer)) {
7774 printf(
"Error: Overran buffer in CountKeys\n");
7780 StrAppend(&sql,
"select k.zone_id, k.location, k.algorithm, k.state, k.id from KEYDATA_VIEW k where state in ");
7782 StrAppend(&sql,
" and zone_id is not null and k.keytype = 257");
7784 if (*zone_id != -1) {
7789 if (cka_id != NULL) {
7807 while (status == 0) {
7809 DbInt(row, 0, &temp_zone_id);
7811 DbInt(row, 2, &temp_alg);
7812 DbInt(row, 3, &temp_state);
7813 DbInt(row, 4, &temp_keypair);
7817 if (keytag == -1 && cka_id == NULL)
7819 *temp_key_state = temp_state;
7822 key = hsm_find_key_by_id(NULL, temp_loc);
7824 printf(
"cka_id %-33s in DB but NOT IN repository\n", temp_loc);
7825 }
else if (keytag != -1) {
7826 sign_params = hsm_sign_params_new();
7827 sign_params->owner = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME,
"temp_zone");
7828 sign_params->algorithm = temp_alg;
7829 sign_params->flags = LDNS_KEY_ZONE_KEY;
7830 sign_params->flags += LDNS_KEY_SEP_KEY;
7832 dnskey_rr = hsm_get_dnskey(NULL, key, sign_params);
7833 sign_params->keytag = ldns_calc_keytag(dnskey_rr);
7836 if (keytag == sign_params->keytag) {
7839 *temp_cka_id = NULL;
7841 *zone_id = temp_zone_id;
7842 *temp_key_state = temp_state;
7843 *temp_keypair_id = temp_keypair;
7844 printf(
"Found key with CKA_ID %s\n", temp_loc);
7847 hsm_sign_params_free(sign_params);
7849 if (key && cka_id != NULL && strncmp(cka_id, temp_loc, strlen(temp_loc)) == 0) {
7851 if (done_row == 0) {
7853 *temp_cka_id = NULL;
7855 *zone_id = temp_zone_id;
7856 *temp_key_state = temp_state;
7857 *temp_keypair_id = temp_keypair;
7858 printf(
"Found key with CKA_ID %s\n", temp_loc);
7878 *key_count = temp_count;
7885 if (dnskey_rr != NULL) {
7886 ldns_rr_free(dnskey_rr);
7895 int GetKeyState(
const char *cka_id,
int *temp_key_state,
int *temp_keypair_id) {
7903 int temp_keypair = 0;
7905 nchar = snprintf(sql,
sizeof(sql),
"select k.id, k.state from KEYDATA_VIEW k where k.location = '%s'", cka_id);
7906 if (nchar >=
sizeof(sql)) {
7907 printf(
"Error: Overran buffer in CountKeys\n");
7916 while (status == 0) {
7918 DbInt(row, 0, &temp_keypair);
7919 DbInt(row, 1, &temp_state);
7922 if (temp_state == 0) {
7926 *temp_key_state = temp_state;
7927 *temp_keypair_id = temp_keypair;
7969 int MarkDSSeen(
int keypair_id,
int zone_id,
int policy_id,
const char *datetime,
int key_state)
7987 printf(
"Error: failed to read policy\n");
8010 printf(
"DbDateDiff failed\n");
8035 printf(
"DbDateDiff failed\n");
8098 char* where_clause = NULL;
8113 printf(
"Error: failed to read policy\n");
8129 StrAppend(&where_clause,
"select id from KEYDATA_VIEW where state = 4 and keytype = 257 and zone_id = ");
8131 StrAppend(&where_clause,
" and retire = (select min(retire) from KEYDATA_VIEW where state = 4 and keytype = 257 and zone_id = ");
8140 printf(
"Error: failed to find ID of key to retire\n");
8151 printf(
"DbDateDiff failed\n");
8220 if (zone_id != -1) {
8229 printf(
"Error in CountKeysInState\n");
8266 int ChangeKeyState(
int keytype,
const char *cka_id,
int zone_id,
int policy_id,
const char *datetime,
int keystate)
8294 printf(
"Error: failed to read policy\n");
8302 if (zone_id != -1) {
8321 keyids =
MemMalloc(count *
sizeof(
int));
8328 if (zone_id != -1) {
8337 while (status == 0) {
8338 status =
KsmKey(result, &data);
8369 for (j = 0; j < i; ++j) {
8373 snprintf(buffer,
sizeof(buffer),
"%d", keyids[j]);
8398 printf(
"DbDateDiff failed\n");
8410 if (zone_id != -1) {
8430 printf(
"DbDateDiff failed\n");
8442 if (zone_id != -1) {
8455 printf(
"DbDateDiff failed\n");
8467 if (zone_id != -1) {
8503 static int restart_enforcerd()
8507 return system(ODS_EN_NOTIFY);
8519 xmlDocPtr doc = NULL;
8520 xmlXPathContextPtr xpathCtx = NULL;
8521 xmlXPathObjectPtr xpathObj = NULL;
8522 char* temp_char = NULL;
8524 xmlChar *iv_expr = (
unsigned char*)
"//Configuration/Enforcer/Interval";
8525 xmlChar *mk_expr = (
unsigned char*)
"//Configuration/Enforcer/ManualKeyGeneration";
8528 doc = xmlParseFile(
config);
8530 printf(
"Error: unable to parse file \"%s\"\n",
config);
8535 xpathCtx = xmlXPathNewContext(doc);
8536 if(xpathCtx == NULL) {
8537 printf(
"Error: unable to create new XPath context\n");
8543 xpathObj = xmlXPathEvalExpression(iv_expr, xpathCtx);
8544 if(xpathObj == NULL) {
8545 printf(
"Error: unable to evaluate xpath expression: %s", iv_expr);
8546 xmlXPathFreeContext(xpathCtx);
8551 temp_char = (
char *)xmlXPathCastToString(xpathObj);
8554 printf(
"Error: unable to convert Interval %s to seconds, error: %i\n", temp_char, status);
8558 else if (status == -1) {
8559 printf(
"Info: converting %s to seconds; M interpreted as 31 days, Y interpreted as 365 days\n", temp_char);
8563 xmlXPathFreeObject(xpathObj);
8566 xpathObj = xmlXPathEvalExpression(mk_expr, xpathCtx);
8567 if(xpathObj == NULL) {
8568 printf(
"Error: unable to evaluate xpath expression: %s\n", mk_expr);
8569 xmlXPathFreeContext(xpathCtx);
8574 if (xpathObj->nodesetval != NULL && xpathObj->nodesetval->nodeNr > 0) {
8582 xmlXPathFreeObject(xpathObj);
8585 xmlXPathFreeContext(xpathCtx);
8625 int man_key_gen = -1;
8636 printf(
"Failed to Link Keys to zone\n");
8646 if (policy == NULL) {
8647 printf(
"Malloc for policy struct failed\n");
8657 printf(
"Error: unable to read policy %s from database\n",
o_policy);
8662 printf(
"Error: policy %s doesn't exist in database\n",
o_policy);
8670 printf(
"Error allocating zsks to zone %s", zone_name);
8676 printf(
"Error allocating ksks to zone %s", zone_name);
8718 int keys_needed = 0;
8719 int keys_in_queue = 0;
8720 int keys_pending_retirement = 0;
8722 int key_pair_id = 0;
8729 if (datetime == NULL) {
8730 printf(
"Couldn't turn \"now\" into a date, quitting...");
8734 if (policy == NULL) {
8735 printf(
"NULL policy sent to allocateKeysToZone");
8741 printf(
"Unknown keytype: %i in allocateKeysToZone", key_type);
8755 status =
KsmKeyPredict(policy->
id, key_type, 1, interval, &keys_needed, rollover_scheme, 1);
8757 printf(
"Could not predict key requirement for next interval for %s", zone_name);
8765 printf(
"Could not count current key numbers for zone %s", zone_name);
8773 printf(
"Could not count keys which may retire before the next run (for zone %s)", zone_name);
8779 new_keys = keys_needed - (keys_in_queue - keys_pending_retirement);
8784 for (i=0 ; i < new_keys ; i++){
8788 if (status == -1 || key_pair_id == 0) {
8789 if (man_key_gen == 0) {
8790 printf(
"Not enough keys to satisfy ksk policy for zone: %s", zone_name);
8791 printf(
"ods-enforcerd will create some more keys on its next run");
8794 printf(
"Not enough keys to satisfy ksk policy for zone: %s", zone_name);
8795 printf(
"please use \"ods-ksmutil key generate\" to create some more keys.");
8799 else if (status != 0) {
8800 printf(
"Could not get an unallocated ksk for zone: %s", zone_name);
8805 if (status == -1 || key_pair_id == 0) {
8806 if (man_key_gen == 0) {
8807 printf(
"Not enough keys to satisfy zsk policy for zone: %s", zone_name);
8808 printf(
"ods-enforcerd will create some more keys on its next run");
8811 printf(
"Not enough keys to satisfy zsk policy for zone: %s", zone_name);
8812 printf(
"please use \"ods-ksmutil key generate\" to create some more keys.");
8816 else if (status != 0) {
8817 printf(
"Could not get an unallocated zsk for zone: %s", zone_name);
8821 if(key_pair_id > 0) {
8826 printf(
"KsmKeyGetUnallocated returned bad key_id %d for zone: %s; exiting...", key_pair_id, zone_name);
8854 int keyRoll(
int zone_id,
int policy_id,
int key_type)
8867 int temp_zone_id = -1;
8873 char* insql1 = NULL;
8874 char* insql2 = NULL;
8880 if (datetime == NULL) {
8881 printf(
"Couldn't turn \"now\" into a date, quitting...\n");
8889 if (zone_id != -1) {
8892 if (policy_id != -1) {
8896 if (key_type != -1) {
8905 while (status == 0) {
8907 DbInt(row, 0, &temp_id);
8908 DbInt(row, 1, &temp_type);
8912 DusSetInt(&sql1,
"compromisedflag", 1, 1);
8973 size = snprintf(sql2,
KSM_SQL_SIZE,
"select zone_id from dnsseckeys where retire = \"%s\" and keypair_id = %d", datetime, temp_id);
8977 while (status == 0) {
8979 DbInt(row2, 0, &temp_zone_id);
8984 snprintf(buffer,
sizeof(buffer),
"%d", temp_zone_id);
9007 while (status == 0) {
9009 DbInt(row2, 0, &temp_zone_id);
9014 snprintf(buffer,
sizeof(buffer),
"%d", temp_zone_id);
9036 printf(
"Couldn't construct SQL to promote standby key\n");
9107 else if (status == -1) {}
9122 xmlNodePtr zone_node;
9123 xmlNodePtr adapters_node;
9124 xmlNodePtr input_node;
9125 xmlNodePtr in_ad_node;
9126 xmlNodePtr output_node;
9127 xmlNodePtr out_ad_node;
9129 root = xmlDocGetRootElement(doc);
9131 fprintf(stderr,
"empty document\n");
9134 if (xmlStrcmp(root->name, (
const xmlChar *)
"ZoneList")) {
9135 fprintf(stderr,
"document of the wrong type, root node != %s",
"ZoneList");
9139 zone_node = xmlNewTextChild(root, NULL, (
const xmlChar *)
"Zone", NULL);
9140 (void) xmlNewProp(zone_node, (
const xmlChar *)
"name", (
const xmlChar *)zone->
name);
9143 (void) xmlNewTextChild(zone_node, NULL, (
const xmlChar *)
"Policy", (
const xmlChar *)zone->
policy_name);
9146 (void) xmlNewTextChild(zone_node, NULL, (
const xmlChar *)
"SignerConfiguration", (
const xmlChar *)zone->
signconf);
9149 adapters_node = xmlNewTextChild(zone_node, NULL, (
const xmlChar *)
"Adapters", NULL);
9151 input_node = xmlNewTextChild(adapters_node, NULL, (
const xmlChar *)
"Input", NULL);
9152 in_ad_node = xmlNewTextChild (input_node, NULL, (
const xmlChar *)
"Adapter", (
const xmlChar *)zone->
input);
9154 if (zone->
in_type[0] ==
'\0') {
9155 (void) xmlNewProp(in_ad_node, (
const xmlChar *)
"type", (
const xmlChar *)
"File");
9157 (void) xmlNewProp(in_ad_node, (
const xmlChar *)
"type", (
const xmlChar *)zone->
in_type);
9161 output_node = xmlNewTextChild(adapters_node, NULL, (
const xmlChar *)
"Output", NULL);
9162 out_ad_node = xmlNewTextChild (output_node, NULL, (
const xmlChar *)
"Adapter", (
const xmlChar *)zone->
output);
9165 (void) xmlNewProp(out_ad_node, (
const xmlChar *)
"type", (
const xmlChar *)
"File");
9167 (void) xmlNewProp(out_ad_node, (
const xmlChar *)
"type", (
const xmlChar *)zone->
out_type);
9181 len = strlen(
string);
9183 for (i = 0; i < len; ++i) {
9184 if (
string[i] ==
'\'') {
9189 buffer[j++] =
string[i];
9193 return ( (j <= buflen) ? 0 : 1);
9198 char* signconf = NULL;
9199 char* moved_signconf = NULL;
9200 char* zone_name = NULL;
9204 xmlDocPtr doc = NULL;
9206 xmlXPathContextPtr xpathCtx = NULL;
9207 xmlXPathObjectPtr xpathObj = NULL;
9209 xmlChar *node_expr = (
unsigned char*)
"//Zone";
9211 doc = xmlParseFile(zonelist_filename);
9213 printf(
"Error: unable to parse file \"%s\"\n", zonelist_filename);
9217 xpathCtx = xmlXPathNewContext(doc);
9218 if(xpathCtx == NULL) {
9224 xpathObj = xmlXPathEvalExpression(node_expr, xpathCtx);
9225 if(xpathObj == NULL) {
9226 xmlXPathFreeContext(xpathCtx);
9231 if (xpathObj->nodesetval) {
9232 for (i = 0; i < xpathObj->nodesetval->nodeNr; i++) {
9234 curNode = xpathObj->nodesetval->nodeTab[i]->xmlChildrenNode;
9235 zone_name = (
char *) xmlGetProp(xpathObj->nodesetval->nodeTab[i], (
const xmlChar *)
"name");
9237 if (all_flag || (strlen(zone_name) == strlen(o_zone) &&
9238 strncmp(zone_name, o_zone, strlen(zone_name)) == 0)) {
9242 if (xmlStrEqual(curNode->name, (
const xmlChar *)
"SignerConfiguration")) {
9243 StrAppend(&signconf, (
char *) xmlNodeGetContent(curNode));
9245 StrAppend(&moved_signconf,
".ZONE_DELETED");
9247 status = rename(signconf, moved_signconf);
9248 if (status != 0 && errno != ENOENT)
9251 printf(
"Could not rename: %s -> %s", signconf, moved_signconf);
9261 curNode = curNode->next;
9297 char* temp_zone = NULL;
9298 int temp_policy = 0;
9299 char* temp_location = NULL;
9306 hsm_key_t *key = NULL;
9307 ldns_rr *dnskey_rr = NULL;
9308 hsm_sign_params_t *sign_params = NULL;
9312 char* ds_buffer = NULL;
9315 status = hsm_open(
config, hsm_prompt_pin);
9317 hsm_print_error(NULL);
9322 "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 ");
9323 if (zone_id != -1) {
9336 while (status == 0) {
9339 DbInt(row, 1, &temp_policy);
9341 DbInt(row, 3, &temp_algo);
9344 key = hsm_find_key_by_id(NULL, temp_location);
9347 printf(
"Key %s in DB but not repository.", temp_location);
9356 printf(
"\n*** Found DNSKEY RECORD involved with rollover:\n");
9358 sign_params = hsm_sign_params_new();
9359 sign_params->owner = ldns_rdf_new_frm_str(LDNS_RDF_TYPE_DNAME, temp_zone);
9360 sign_params->algorithm = temp_algo;
9361 sign_params->flags = LDNS_KEY_ZONE_KEY;
9362 sign_params->flags += LDNS_KEY_SEP_KEY;
9363 dnskey_rr = hsm_get_dnskey(NULL, key, sign_params);
9368 ldns_rr_set_ttl(dnskey_rr, rrttl);
9371 ds_buffer = ldns_rr2str(dnskey_rr);
9372 ldns_rr_free(dnskey_rr);
9375 for (i = 0; ds_buffer[i]; ++i) {
9376 if (ds_buffer[i] ==
'\t') {
9382 printf(
"%s", ds_buffer);
9383 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);
9389 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)