if (result != ISC_R_SUCCESS) goto cleanup; \
} while (0)
+#define TCHECK(op) \
+ do { tresult = (op); \
+ if (tresult != ISC_R_SUCCESS) { \
+ isc_buffer_clear(text); \
+ goto cleanup; \
+ } \
+ } while (0)
+
#define CHECKM(op, msg) \
do { result = (op); \
if (result != ISC_R_SUCCESS) { \
static isc_result_t
putstr(isc_buffer_t *b, const char *str);
+static isc_result_t
+putnull(isc_buffer_t *b);
+
isc_result_t
add_comment(FILE *fp, const char *viewname);
isc_result_t tresult;
tresult = putstr(text, problem);
- if (tresult == ISC_R_SUCCESS &&
- isc_buffer_availablelength(text) > 0U)
- isc_buffer_putuint8(text, 0);
+ if (tresult == ISC_R_SUCCESS)
+ putnull(text);
}
cleanup:
* Act on an "addzone" command from the command channel.
*/
isc_result_t
-ns_server_add_zone(ns_server_t *server, char *args) {
- isc_result_t result;
+ns_server_add_zone(ns_server_t *server, char *args, isc_buffer_t *text) {
+ isc_result_t result, tresult;
isc_buffer_t argbuf;
size_t arglen;
cfg_parser_t *parser = NULL;
const char *argp;
const char *viewname = NULL;
dns_rdataclass_t rdclass;
- dns_view_t *view = 0;
+ dns_view_t *view = NULL;
isc_buffer_t buf;
dns_fixedname_t fname;
dns_name_t *dnsname;
}
/* Open save file for write configuration */
- CHECK(isc_stdio_open(view->new_zone_file, "a", &fp));
+ result = isc_stdio_open(view->new_zone_file, "a", &fp);
+ if (result != ISC_R_SUCCESS) {
+ TCHECK(putstr(text, "unable to open '"));
+ TCHECK(putstr(text, view->new_zone_file));
+ TCHECK(putstr(text, "': "));
+ TCHECK(putstr(text, isc_result_totext(result)));
+ goto cleanup;
+ }
CHECK(isc_stdio_tell(fp, &offset));
if (offset == 0)
CHECK(add_comment(fp, view->name));
server->mctx, view, cfg->actx, ISC_FALSE);
dns_view_freeze(view);
isc_task_endexclusive(server->task);
- if (result != ISC_R_SUCCESS)
+ if (result != ISC_R_SUCCESS) {
+ TCHECK(putstr(text, "configure_zone failed: "));
+ TCHECK(putstr(text, isc_result_totext(result)));
goto cleanup;
+ }
/* Is it there yet? */
CHECK(dns_zt_find(view->zonetable, dnsname, 0, NULL, &zone));
if (result != ISC_R_SUCCESS) {
dns_db_t *dbp = NULL;
+ TCHECK(putstr(text, "dns_zone_loadnew failed: "));
+ TCHECK(putstr(text, isc_result_totext(result)));
+
isc_log_write(ns_g_lctx, NS_LOGCATEGORY_GENERAL,
NS_LOGMODULE_SERVER, ISC_LOG_INFO,
"addzone failed; reverting.");
/* Emit the zone name, quoted and escaped */
isc_buffer_init(&buf, namebuf, sizeof(namebuf));
CHECK(dns_name_totext(dnsname, ISC_TRUE, &buf));
- isc_buffer_putuint8(&buf, 0);
+ putnull(&buf);
CHECK(isc_stdio_write("zone \"", 6, 1, fp, NULL));
CHECK(isc_stdio_write(namebuf, strlen(namebuf), 1, fp, NULL));
CHECK(isc_stdio_write("\" ", 2, 1, fp, NULL));
result = ISC_R_SUCCESS;
cleanup:
+ if (isc_buffer_usedlength(text) > 0)
+ putnull(text);
if (fp != NULL)
isc_stdio_close(fp);
if (parser != NULL) {
result = ISC_R_SUCCESS;
cleanup:
+ if (isc_buffer_usedlength(text) > 0)
+ putnull(text);
if (ifp != NULL)
isc_stdio_close(ifp);
if (ofp != NULL) {
isc_buffer_putmem(b, (const unsigned char *)str, l);
return (ISC_R_SUCCESS);
}
+
+static isc_result_t
+putnull(isc_buffer_t *b) {
+ if (isc_buffer_availablelength(b) == 0)
+ return (ISC_R_NOSPACE);
+
+ isc_buffer_putuint8(b, 0);
+ return (ISC_R_SUCCESS);
+}