/** list contents of NSD.DB file */ static void list_file(char* fname) { udb_base* udb; udb_ptr ztree; log_init("udb-inspect"); udb = udb_base_create_read(fname, &namedb_walkfunc, NULL); if(!udb) { printf("cannot open udb %s\n", fname); exit(1); } udb_ptr_new(&ztree, udb, udb_base_get_userdata(udb)); if(udb_ptr_is_null(&ztree)) { printf("file is not inited\n"); exit(1); } /* print header info */ printf("%s: %llu zones, %llu bytes\n", fname, ULL RADTREE(&ztree)->count, ULL udb->alloc->disk->nextgrow); if(udb_base_get_userflags(udb)) { printf("file is corrupted! (%u)\n", (unsigned)udb_base_get_userflags(udb)); } /* print detail info */ list_zones(udb, &ztree); udb_ptr_unlink(&ztree, udb); udb_base_free(udb); }
int main(int argc, char *argv[]) { dnsa_comm_line_s *cm; dnsa_config_s *dc; char *domain = NULL; int retval; cm = cmdb_malloc(sizeof(dnsa_comm_line_s), "cm in main"); dnsa_init_comm_line_struct(cm); if ((retval = parse_dnsa_command_line(argc, argv, cm)) != 0) { cmdb_free(cm, sizeof(dnsa_comm_line_s)); display_command_line_error(retval, argv[0]); } dc = cmdb_malloc(sizeof(dnsa_config_s), "dc in main"); dnsa_init_config_values(dc); if ((retval = parse_dnsa_config_file(dc, cm->config)) != 0) { parse_dnsa_config_error(retval); goto cleanup; } domain = cmdb_malloc(CONF_S, "domain in main"); if (!(strncpy(domain, cm->domain, CONF_S - 1))) goto cleanup; if (cm->type == FORWARD_ZONE) { if (cm->action == LIST_ZONES) { list_zones(dc); retval = 0; } else if (cm->action == DISPLAY_ZONE) { display_zone(domain, dc); retval = 0; } else if (cm->action == COMMIT_ZONES) { retval = commit_fwd_zones(dc, domain); } else if (cm->action == ADD_HOST) { retval = add_host(dc, cm); } else if (cm->action == ADD_ZONE) { retval = add_fwd_zone(dc, cm); } else if (cm->action == DELETE_RECORD) { retval = delete_record(dc, cm); } else if (cm->action == DELETE_ZONE) { retval = delete_fwd_zone(dc, cm); } else if (cm->action == ADD_CNAME_ON_ROOT) { retval = add_cname_to_root_domain(dc, cm); } else { printf("Action code %d not implemented\n", cm->action); } } else if (cm->type == REVERSE_ZONE) { if (cm->action == LIST_ZONES) { list_rev_zones(dc); retval = 0; } else if (cm->action == DISPLAY_ZONE) { display_rev_zone(domain, dc); retval = 0; } else if (cm->action == COMMIT_ZONES) { retval = commit_rev_zones(dc, domain); } else if (cm->action == ADD_ZONE) { retval = add_rev_zone(dc, cm); } else if (cm->action == MULTIPLE_A) { retval = display_multi_a_records(dc, cm); } else if (cm->action == ADD_PREFER_A) { retval = mark_preferred_a_record(dc, cm); } else if (cm->action == BUILD_REV) { retval = build_reverse_zone(dc, cm); } else if (cm->action == DELETE_PREFERRED) { retval = delete_preferred_a(dc, cm); } else if (cm->action == DELETE_ZONE) { retval = delete_reverse_zone(dc, cm); } else { printf("Action code %d not implemented\n", cm->action); } } else if (cm->type == GLUE_ZONE) { if (cm->action == ADD_ZONE) retval = add_glue_zone(dc, cm); else if (cm->action == LIST_ZONES) list_glue_zones(dc); else if (cm->action == DELETE_ZONE) delete_glue_zone(dc, cm); else printf("Action code %d not implemented\n", cm->action); } cleanup: if (domain) cmdb_free(domain, CONF_S); cmdb_free(cm, sizeof(dnsa_comm_line_s)); cmdb_free(dc, sizeof(dnsa_config_s)); exit(retval); }
void run_ui(void){ ui_flag = 0; int i; char line[30]; char name[30] = ""; switch(ui_mode){ case UI_MODE_MAIN: if(fgets(line, sizeof line - 1, stdin) == NULL){ _NOP();//ui_mode = UI_MODE_BUILD_LINE; } printf("\n"); if(sscanf(line, "%02d", &i)){ i = i+10; if(i > 10 && i <= 14){ ui_mode = i; ui_flag = 1; } else { ui_end(); } } else { ui_end(); } break; case UI_MODE_END: setup_ui(); break; case UI_MODE_BUILD_LINE: printf("\n%s\n", line); ui_mode = UI_MODE_MAIN; break; case UI_MODE_DISPLAY_TIME: display_time(); ui_end(); break; case UI_MODE_TZ: if(fgets(line, sizeof line - 1, stdin) == NULL){ _NOP();//ui_mode = UI_MODE_BUILD_LINE; } if(sscanf(line, "%29s", name)){ printf("%s\n", name); if(name[0] == '!'){ ui_end(); } else if(name[0] == 'l'){ list_zones(); printf(">"); } else if(strlen(name)>3){ if(tz_update(name)){ printf("Set %s\n", name); ui_end(); } } else{ printf("\nPlease Enter a Timezone\nl - to list\n! - to exit\n>"); } } break; case UI_MODE_TEST: ds3231_debug(); ui_end(); break; } }