APU_INTERNAL::APU_INTERNAL() { nes = NULL; ZEROMEMORY( &ch0, sizeof(ch0) ); ZEROMEMORY( &ch1, sizeof(ch1) ); ZEROMEMORY( &ch2, sizeof(ch2) ); ZEROMEMORY( &ch3, sizeof(ch3) ); ZEROMEMORY( &ch4, sizeof(ch4) ); FrameIRQ = 0xC0; FrameCycle = 0; FrameIRQoccur = 0; FrameCount = 0; FrameType = 0; reg4015 = sync_reg4015 = 0; cpu_clock = APU_CLOCK; sampling_rate = 22050; // 仮設定 cycle_rate = (INT)(cpu_clock*65536.0f/22050.0f); }
static void Reset( APU_FDS *pme, FLOAT fClock, INT nRate ) { ZEROMEMORY( &pme->fds, sizeof(pme->fds) ); ZEROMEMORY( &pme->fds_sync, sizeof(pme->fds) ); pme->sampling_rate = nRate; }
PVOID InfpAddFieldToLine(PINFCACHELINE Line, PCWSTR Data) { PINFCACHEFIELD Field; ULONG Size; Size = (ULONG)FIELD_OFFSET(INFCACHEFIELD, Data[strlenW(Data) + 1]); Field = (PINFCACHEFIELD)MALLOC(Size); if (Field == NULL) { DPRINT1("MALLOC() failed\n"); return NULL; } ZEROMEMORY (Field, Size); strcpyW(Field->Data, Data); /* Append key */ if (Line->FirstField == NULL) { Line->FirstField = Field; Line->LastField = Field; } else { Line->LastField->Next = Field; Field->Prev = Line->LastField; Line->LastField = Field; } Line->FieldCount++; return (PVOID)Field; }
void InputInit(void) { int i; ZEROMEMORY(gInput, sizeof(sInput) * INPUT_WORK_NUM); gInput[INP_SYS].exec = TRUE; for(i = 0; i < INPUT_WORK_NUM; ++i) { gInput[i].m_x = MOUSE_MIN_POSITION; gInput[i].m_y = MOUSE_MIN_POSITION; gInput[i].x = MOUSE_MIN_POSITION; gInput[i].y = MOUSE_MIN_POSITION; } record = NULL; glutMouseFunc(mouseBtnCallback); glutMotionFunc(mousePosCallback); glutPassiveMotionFunc(mousePosCallback); glutKeyboardFunc(keyPushCallback); glutKeyboardUpFunc(keyPullCallback); glutSpecialFunc(keyExPushCallback); glutSpecialUpFunc(keyExPullCallback); SYSINFO(".... input initialize"); }
NTSTATUS InfOpenBufferedFile(PHINF InfHandle, PVOID Buffer, ULONG BufferSize, PULONG ErrorLine) { INFSTATUS Status; PINFCACHE Cache; PCHAR FileBuffer; CheckHeap(); *InfHandle = NULL; *ErrorLine = (ULONG)-1; /* Allocate file buffer */ FileBuffer = MALLOC(BufferSize + 1); if (FileBuffer == NULL) { DPRINT1("MALLOC() failed\n"); return(INF_STATUS_INSUFFICIENT_RESOURCES); } MEMCPY(FileBuffer, Buffer, BufferSize); /* Append string terminator */ FileBuffer[BufferSize] = 0; /* Allocate infcache header */ Cache = (PINFCACHE)MALLOC(sizeof(INFCACHE)); if (Cache == NULL) { DPRINT("MALLOC() failed\n"); FREE(FileBuffer); return(INF_STATUS_INSUFFICIENT_RESOURCES); } /* Initialize inicache header */ ZEROMEMORY(Cache, sizeof(INFCACHE)); /* Parse the inf buffer */ Status = InfpParseBuffer (Cache, FileBuffer, FileBuffer + BufferSize, ErrorLine); if (!INF_SUCCESS(Status)) { FREE(Cache); Cache = NULL; } /* Free file buffer */ FREE(FileBuffer); *InfHandle = (HINF)Cache; return(Status); }
void dnssec_inittask(u16 flags, dnssec_task* task) { ZEROMEMORY(task, sizeof (dnssec_task)); task->path.size = -1; task->task_flags = flags; }
void nsec_icmtl_replay_init(nsec_icmtl_replay *replay, zdb_zone *zone) { ZEROMEMORY(replay, sizeof(nsec_icmtl_replay)); replay->nsec_add.compare = treeset_dnsname_compare; replay->nsec_del.compare = treeset_dnsname_compare; replay->zone = zone; }
//============================================================== void MemInit(void) //-------------------------------------------------------------- // メモリ管理の初期化 //-------------------------------------------------------------- // in: なし //-------------------------------------------------------------- // out: なし //============================================================== { void *ptr; size_t size; int i; ZEROMEMORY(&gMem, sizeof(sMemInfo)); // 管理領域を初期化 //---------------------------- // ヒープ領域を作成して初期化 //---------------------------- ptr = OsCreateMemory(MEM_SIZE); // 空きエリアを全てグローバル領域として確保 //------------------------------------------ bsMemoryInit(&gMem.global_mem_hdr, ptr, MEM_SIZE, TRUE); //-------------------- // MEM_APP 以外を確保 //-------------------- for(i = MEM_SYS; i < MEM_APP; ++i) { ptr = bsMalloc(&gMem.global_mem_hdr, memSizeTbl[i], NULL); ASSERT(ptr); bsMemoryInit(&gMem.mem_hdr[i], ptr, memSizeTbl[i], FALSE); gMem.mem_hdr[i].area = i; } //------------------------------------------------------ // グローバル領域の残りをアプリケーション領域として確保 //------------------------------------------------------ size = bsMemoryGetFree(&gMem.global_mem_hdr); ptr = bsMalloc(&gMem.global_mem_hdr, size, NULL); ASSERT(ptr); bsMemoryInit(&gMem.mem_hdr[MEM_APP], ptr, size, FALSE); gMem.mem_hdr[MEM_APP].area = MEM_APP; #ifdef DEBUG //-------------------- // 開発時の領域の確保 //-------------------- ptr = OsCreateMemory(MEM_DEV_SIZE); bsMemoryInit(&gMem.mem_hdr[MEM_DEV], ptr, MEM_DEV_SIZE, TRUE); gMem.mem_hdr[MEM_DEV].area = MEM_DEV; #endif SYSINFO(".... memory initialize"); }
static void clearAppInput(sInput *input) { input->btn_td = 0; input->btn_tu = 0; input->btn_p = 0; input->d_left_count = 0; input->keyBuffer[0].key_push_num = 0; input->keyBuffer[0].key_pull_num = 0; ZEROMEMORY(input->key_press, sizeof(BOOL) * KEY_INPUT_KINDNUM); }
ya_result nsec3_load_init(nsec3_load_context *context, zdb_zone* zone) { ZEROMEMORY(context, sizeof(nsec3_load_context)); ptr_vector_init_ex(&context->nsec3chain, 2); ptr_set_avl_init(&context->postponed_rrsig); context->postponed_rrsig.compare = nsec3_load_postponed_rrsig_node_compare; context->zone = zone; context->opt_out = TRUE; return SUCCESS; }
void nsec3_icmtl_replay_init(nsec3_icmtl_replay *replay, zdb_zone *zone) { ZEROMEMORY(replay, sizeof(nsec3_icmtl_replay)); replay->nsec3_add.compare = treeset_dnsname_compare; replay->nsec3_del.compare = treeset_dnsname_compare; replay->nsec3rrsig_add.compare = treeset_dnsname_compare; replay->nsec3rrsig_del.compare = treeset_dnsname_compare; replay->nsec3_labels.compare = treeset_dnsname_compare; replay->nsec3param_add.compare = treeset_nsec3param_compare; replay->nsec3param_del.compare = treeset_nsec3param_compare; replay->zone = zone; }
static nsec3_load_context_chain* nsec3_load_context_chain_new(nsec3_context_record *r) { nsec3_load_context_chain *chain; const u8 *nsec3param_rdata = nsec3_load_context_record_rdata(r); size_t nsec3param_size = NSEC3PARAM_RDATA_SIZE_FROM_RDATA(nsec3param_rdata); ZALLOC_ARRAY_OR_DIE(nsec3_load_context_chain*, chain, sizeof(nsec3_load_context_chain) + nsec3param_size, N3LCTXCN_TAG); ZEROMEMORY(chain, sizeof(nsec3_load_context_chain)); ptr_vector_init_ex(&chain->nsec3_added, 65536); chain->nsec3param_rdata_size = nsec3param_size; memcpy(chain->nsec3param_rdata, nsec3param_rdata, nsec3param_size); return chain; }
void APU_INTERNAL::Reset( FLOAT fClock, INT nRate ) { ZEROMEMORY( &ch0, sizeof(ch0) ); ZEROMEMORY( &ch1, sizeof(ch1) ); ZEROMEMORY( &ch2, sizeof(ch2) ); ZEROMEMORY( &ch3, sizeof(ch3) ); // ZEROMEMORY( &ch4, sizeof(ch4) ); ZEROMEMORY( bToneTableEnable, sizeof(bToneTableEnable) ); ZEROMEMORY( ToneTable, sizeof(ToneTable) ); ZEROMEMORY( ChannelTone, sizeof(ChannelTone) ); reg4015 = sync_reg4015 = 0; // Sweep complement ch0.complement = 0x00; ch1.complement = 0xFF; // Noise shift register ch3.shift_reg = 0x4000; Setup( fClock, nRate ); // $4011は初期化しない WORD addr; for( addr = 0x4000; addr <= 0x4010; addr++ ) { Write( addr, 0x00 ); SyncWrite( addr, 0x00 ); } // Write( 0x4001, 0x08 ); // Reset時はincモードになる? // Write( 0x4005, 0x08 ); // Reset時はincモードになる? Write( 0x4012, 0x00 ); Write( 0x4013, 0x00 ); Write( 0x4015, 0x00 ); SyncWrite( 0x4012, 0x00 ); SyncWrite( 0x4013, 0x00 ); SyncWrite( 0x4015, 0x00 ); // $4017は書き込みで初期化しない(初期モードが0であるのを期待したソフトがある為) FrameIRQ = 0xC0; FrameCycle = 0; FrameIRQoccur = 0; FrameCount = 0; FrameType = 0; // ToneLoad ToneTableLoad(); }
static void Reset( APU_INTERNAL *pme, FLOAT fClock, INT nRate ) { WORD addr; ZEROMEMORY( &pme->ch0, sizeof(pme->ch0) ); ZEROMEMORY( &pme->ch1, sizeof(pme->ch1) ); ZEROMEMORY( &pme->ch2, sizeof(pme->ch2) ); ZEROMEMORY( &pme->ch3, sizeof(pme->ch3) ); // ZEROMEMORY( &pme->ch4, sizeof(pme->ch4) ); ZEROMEMORY( pme->bToneTableEnable, sizeof(pme->bToneTableEnable) ); ZEROMEMORY( pme->ToneTable, sizeof(pme->ToneTable) ); ZEROMEMORY( pme->ChannelTone, sizeof(pme->ChannelTone) ); pme->reg4015 = pme->sync_reg4015 = 0; // Sweep complement pme->ch0.complement = 0x00; pme->ch1.complement = 0xFF; // Noise shift register pme->ch3.shift_reg = 0x4000; Setup( pme, fClock, nRate ); // $4011は初期化しない for( addr = 0x4000; addr <= 0x4010; addr++ ) { Write( pme, addr, 0x00 ); SyncWrite( pme, addr, 0x00 ); } // Write( pme, 0x4001, 0x08 ); // Reset時はincモードになる? // Write( pme, 0x4005, 0x08 ); // Reset時はincモードになる? Write( pme, 0x4012, 0x00 ); Write( pme, 0x4013, 0x00 ); Write( pme, 0x4015, 0x00 ); SyncWrite( pme, 0x4012, 0x00 ); SyncWrite( pme, 0x4013, 0x00 ); SyncWrite( pme, 0x4015, 0x00 ); // $4017は書き込みで初期化しない(初期モードが0であるのを期待したソフトがある為) pme->FrameIRQ = 0xC0; pme->FrameCycle = 0; pme->FrameIRQoccur = 0; pme->FrameCount = 0; pme->FrameType = 0; // ToneLoad ToneTableLoad(pme); }
void hash_init() { u32 i; if(hash_init_done) { return; } hash_init_done = TRUE; /* It's not big deal if it's done more * than once. I will not use a mutex * for this. */ u32* tmp = (u32*)ZDB_HASH_TABLE_MAP; ZEROMEMORY(tmp, sizeof (ZDB_HASH_TABLE_MAP)); tmp['-'] = 0; for(i = '0'; i <= '9'; i++) { tmp[i] = i - (48 - 1); /* one is taken by '-', '0'=48 */ } for(i = 'A'; i <= 'Z'; i++) { tmp[i] = i - (65 - 11); /* eleven are taken by '-' and '0' .. '9', 'A'=65 */ } for(i = 'a'; i <= 'z'; i++) { tmp[i] = i - (97 - 11); /* eleven are taken by '-' and '0' .. '9', 'a'=97 */ } tmp['*'] = 0; tmp['_'] = 0; hashcode* wild_hashp = (hashcode*) & WILD_HASH; *wild_hashp = hash_dnslabel(WILD_LABEL); }
PINFCACHESECTION InfpAddSection(PINFCACHE Cache, PCWSTR Name) { PINFCACHESECTION Section = NULL; ULONG Size; if (Cache == NULL || Name == NULL) { DPRINT("Invalid parameter\n"); return NULL; } /* Allocate and initialize the new section */ Size = (ULONG)FIELD_OFFSET(INFCACHESECTION, Name[strlenW(Name) + 1]); Section = (PINFCACHESECTION)MALLOC(Size); if (Section == NULL) { DPRINT("MALLOC() failed\n"); return NULL; } ZEROMEMORY (Section, Size); /* Copy section name */ strcpyW(Section->Name, Name); /* Append section */ if (Cache->FirstSection == NULL) { Cache->FirstSection = Section; Cache->LastSection = Section; } else { Cache->LastSection->Next = Section; Section->Prev = Cache->LastSection; Cache->LastSection = Section; } return Section; }
void InputRecordStart(int rec_max) { gInput[INP_CH0].record = TRUE; gInput[INP_CH0].playback = FALSE; gInput[INP_CH0].rec_datamax = FALSE; for(int i = 0; i < INPUT_WORK_NUM; i += 1) { ZEROMEMORY(gInput[i].key_press, sizeof(gInput[i].key_press)); } FreeWork(record); record_num = INPUT_RECORD_SIZE; record_ofs = 0; record_max = rec_max; /* 0:無限 */ record = (sInputRecord *)fsMalloc(sizeof(sInputRecord) * record_num, "record"); record->recNum = 0; }
/** * @fn static ya_result config_section_key_suite_start(struct config_section_descriptor_s *csd) * * @brief * start of a <key-suite> section csd->base will be initialized * * @details * csd->base will be initialized with key_suite * you can not have a start of a 'section' in a 'section' --> ERROR * * @param[in] struct config_section_description_s *csd * * @retval ERROR or SUCCESS * * return ya_result */ static ya_result config_section_key_suite_start(struct config_section_descriptor_s *csd) { #if CONFIG_SETTINGS_DEBUG formatln("config: section: key_suite: start"); #endif if(csd->base != NULL) { return ERROR; } key_suite_desc_s *key_suite; MALLOC_OR_DIE(key_suite_desc_s*, key_suite, sizeof(key_suite_desc_s), KEYSUICF_TAG); ZEROMEMORY(key_suite, sizeof(key_suite_desc_s)); csd->base = key_suite; return SUCCESS; }
void zdb_create(zdb* db) { int i; for(i = HOST_CLASS_IN - 1; i < ZDB_RECORDS_MAX_CLASS; i++) { zdb_zone_label* zone_label; ZALLOC_OR_DIE(zdb_zone_label*, zone_label, zdb_zone_label, ZDB_ZONELABEL_TAG); ZEROMEMORY(zone_label, sizeof (zdb_zone_label)); zone_label->name = dnslabel_dup(ROOT_LABEL); /* . */ dictionary_init(&zone_label->sub); #if ZDB_CACHE_ENABLED!=0 btree_init(&zone_label->global_resource_record_set); #endif db->root[i] = zone_label; } db->alarm_handle = alarm_open((const u8*)"\010database"); }
ya_result config_register_main(s32 priority) { MALLOC_OR_DIE(config_data*, g_config, sizeof(config_data), YGCONFIG_TAG); ZEROMEMORY(g_config, sizeof(config_data)); g_config->gid = getgid(); g_config->uid = getuid(); const char *section_name = "main"; ya_result return_code = config_register_struct(section_name, config_main_desc, g_config, priority); if(ISOK(return_code)) { // hook a new finaliser before the standard one config_section_descriptor_s *section_desc = config_section_get_descriptor(section_name); config_section_descriptor_vtbl_s *vtbl = (config_section_descriptor_vtbl_s*)section_desc->vtbl; vtbl->postprocess = config_main_section_postprocess; } return return_code; }
PINFCACHELINE InfpAddLine(PINFCACHESECTION Section) { PINFCACHELINE Line; if (Section == NULL) { DPRINT("Invalid parameter\n"); return NULL; } Line = (PINFCACHELINE)MALLOC(sizeof(INFCACHELINE)); if (Line == NULL) { DPRINT("MALLOC() failed\n"); return NULL; } ZEROMEMORY(Line, sizeof(INFCACHELINE)); /* Append line */ if (Section->FirstLine == NULL) { Section->FirstLine = Line; Section->LastLine = Line; } else { Section->LastLine->Next = Line; Line->Prev = Section->LastLine; Section->LastLine = Line; } Section->LineCount++; return Line; }
int InfHostOpenFile(PHINF InfHandle, const CHAR *FileName, LANGID LanguageId, ULONG *ErrorLine) { FILE *File; CHAR *FileBuffer; ULONG FileLength; ULONG FileBufferLength; PINFCACHE Cache; INFSTATUS Status = INF_STATUS_SUCCESS; *InfHandle = NULL; *ErrorLine = (ULONG)-1; /* Open the inf file */ File = fopen(FileName, "rb"); if (NULL == File) { DPRINT1("fopen() failed (errno %d)\n", errno); return -1; } DPRINT("fopen() successful\n"); /* Query file size */ if (fseek(File, (size_t)0, SEEK_END)) { DPRINT1("fseek() to EOF failed (errno %d)\n", errno); fclose(File); return -1; } FileLength = (ULONG)ftell(File); if ((ULONG) -1 == FileLength) { DPRINT1("ftell() failed (errno %d)\n", errno); fclose(File); return -1; } DPRINT("File size: %u\n", (UINT)FileLength); /* Rewind */ if (fseek(File, (size_t)0, SEEK_SET)) { DPRINT1("fseek() to BOF failed (errno %d)\n", errno); fclose(File); return -1; } /* Allocate file buffer */ FileBufferLength = FileLength + 2; FileBuffer = MALLOC(FileBufferLength); if (FileBuffer == NULL) { DPRINT1("MALLOC() failed\n"); fclose(File); return -1; } /* Read file */ if (FileLength != fread(FileBuffer, (size_t)1, (size_t)FileLength, File)) { DPRINT1("fread() failed (errno %d)\n", errno); FREE(FileBuffer); fclose(File); return -1; } fclose(File); /* Append string terminator */ FileBuffer[FileLength] = 0; FileBuffer[FileLength + 1] = 0; /* Allocate infcache header */ Cache = (PINFCACHE)MALLOC(sizeof(INFCACHE)); if (Cache == NULL) { DPRINT1("MALLOC() failed\n"); FREE(FileBuffer); return -1; } /* Initialize inicache header */ ZEROMEMORY(Cache, sizeof(INFCACHE)); Cache->LanguageId = LanguageId; /* Parse the inf buffer */ if (!RtlIsTextUnicode(FileBuffer, (INT)FileBufferLength, NULL)) { // static const BYTE utf8_bom[3] = { 0xef, 0xbb, 0xbf }; WCHAR *new_buff; // UINT codepage = CP_ACP; UINT offset = 0; // if (FileLength > sizeof(utf8_bom) && !memcmp(FileBuffer, utf8_bom, sizeof(utf8_bom) )) // { // codepage = CP_UTF8; // offset = sizeof(utf8_bom); // } new_buff = MALLOC(FileBufferLength * sizeof(WCHAR)); if (new_buff != NULL) { ULONG len; Status = RtlMultiByteToUnicodeN(new_buff, FileBufferLength * sizeof(WCHAR), &len, (char *)FileBuffer + offset, FileBufferLength - offset); Status = InfpParseBuffer(Cache, new_buff, new_buff + len / sizeof(WCHAR), ErrorLine); FREE(new_buff); } else Status = INF_STATUS_INSUFFICIENT_RESOURCES; } else { WCHAR *new_buff = (WCHAR *)FileBuffer; /* UCS-16 files should start with the Unicode BOM; we should skip it */ if (*new_buff == 0xfeff) { new_buff++; FileBufferLength -= sizeof(WCHAR); } Status = InfpParseBuffer(Cache, new_buff, (WCHAR*)((char*)new_buff + FileBufferLength), ErrorLine); } if (!INF_SUCCESS(Status)) { FREE(Cache); Cache = NULL; } /* Free file buffer */ FREE(FileBuffer); *InfHandle = (HINF)Cache; return INF_SUCCESS(Status) ? 0 : -1; }
void database_load_zone_desc(zone_desc_s *zone_desc) { yassert(zone_desc != NULL); log_debug1("database_load_zone_desc(%{dnsname}@%p=%i)", zone_desc->origin, zone_desc, zone_desc->rc); s32 err = zone_register(&database_zone_desc, zone_desc); if(ISOK(err)) { log_info("zone: %{dnsname}: %p: config: registered", zone_desc->origin, zone_desc); zone_lock(zone_desc, ZONE_LOCK_LOAD_DESC); zone_set_status(zone_desc, ZONE_STATUS_REGISTERED); zone_clear_status(zone_desc, ZONE_STATUS_DROP_AFTER_RELOAD); zone_unlock(zone_desc, ZONE_LOCK_LOAD_DESC); // newly registered zone // used to be message->origin if(database_service_started()) { database_zone_load(zone_desc->origin); // before this I should set the file name #if HAS_MASTER_SUPPORT if(zone_desc->type == ZT_MASTER) { if(!host_address_empty(zone_desc->slaves)) { log_info("zone: %{dnsname}: %p: config: notifying slaves", zone_desc->origin, zone_desc); host_address *slaves = host_address_copy_list(zone_desc->slaves); notify_host_list(zone_desc, slaves, CLASS_CTRL); } } else #endif { } } } else { switch(err) { case DATABASE_ZONE_MISSING_DOMAIN: { log_err("zone: ?: %p: config: no domain set (not loaded)", zone_desc); if(zone_get_status(zone_desc) & ZONE_STATUS_PROCESSING) { log_err("zone: ?: %p: is processed by %s (releasing)", zone_desc, database_service_operation_get_name(zone_desc->last_processor)); } zone_release(zone_desc); break; } case DATABASE_ZONE_MISSING_MASTER: { log_err("zone: %{dnsname}: %p: config: slave but no master setting (not loaded)", zone_desc->origin, zone_desc); if(zone_get_status(zone_desc) & ZONE_STATUS_PROCESSING) { log_err("zone: ?: %p: is processed by %s (releasing)", zone_desc, database_service_operation_get_name(zone_desc->last_processor)); } zone_release(zone_desc); break; } case DATABASE_ZONE_CONFIG_CLONE: // Exact copy { log_debug("zone: %{dnsname}: %p: config: has already been set (same settings)", zone_desc->origin, zone_desc); zone_desc_s* current = zone_acquirebydnsname(zone_desc->origin); zone_lock(current, ZONE_LOCK_REPLACE_DESC); zone_clear_status(current, ZONE_STATUS_DROP_AFTER_RELOAD); zone_unlock(current, ZONE_LOCK_REPLACE_DESC); zone_release(current); // whatever has been decided above, loading the zone file (if it changed) should be queued database_zone_load(zone_desc->origin); zone_release(zone_desc); break; } case DATABASE_ZONE_CONFIG_DUP: // Not an exact copy { log_debug("zone: %{dnsname}: %p: config: has already been set (different settings)", zone_desc->origin, zone_desc); // basically, most of the changes require a stop, restart of // any task linked to the zone // so let's make this a rule, whatever changed notify_clear(zone_desc->origin); zone_desc_s *current = zone_acquirebydnsname(zone_desc->origin); #if HAS_DYNAMIC_PROVISIONING host_address *notify_slaves_then_delete = NULL; host_address *notify_slaves = NULL; #endif if(current != zone_desc) { zone_lock(current, ZONE_LOCK_REPLACE_DESC); if(zone_get_status(current) & ZONE_STATUS_PROCESSING) { log_err("zone: ?: %p: is processed by %s (overwriting)", zone_desc, database_service_operation_get_name(zone_desc->last_processor)); } // what happens if the change is on : // domain: impossible /// @todo 20131203 edf -- compare before replace // file_name : try to load the new file (will happen anyway) if((current->file_name != NULL) && (zone_desc->file_name != NULL)) { if(strcmp(current->file_name, zone_desc->file_name) != 0) { zone_set_status(current, ZONE_STATUS_MODIFIED); } } else if(current->file_name != zone_desc->file_name) // at least one of them is NULL { zone_set_status(current, ZONE_STATUS_MODIFIED); } free(current->file_name); current->file_name = zone_desc->file_name; zone_desc->file_name = NULL; // masters : log_debug7("updating %p (%u) with %p (%u): masters", current, current->lock_owner, zone_desc, zone_desc->lock_owner); if(host_address_list_equals(current->masters, zone_desc->masters)) { host_address_delete_list(zone_desc->masters); } else { host_address_delete_list(current->masters); current->masters = zone_desc->masters; } zone_desc->masters = NULL; // notifies : log_debug7("updating %p (%u) with %p (%u): notifies", current, current->lock_owner, zone_desc, zone_desc->lock_owner); if(host_address_list_equals(current->notifies, zone_desc->notifies)) { host_address_delete_list(zone_desc->notifies); } else { host_address_delete_list(current->notifies); current->notifies = zone_desc->notifies; } zone_desc->notifies = NULL; #if HAS_DYNAMIC_PROVISIONING log_debug7("updating %p (%u) with %p (%u): slaves", current, current->lock_owner, zone_desc, zone_desc->lock_owner); if(host_address_list_equals(current->slaves, zone_desc->slaves)) { #if HAS_MASTER_SUPPORT if((current->type == ZT_MASTER) || (zone_desc->type == ZT_MASTER)) { notify_slaves_then_delete = zone_desc->slaves; } else #endif { host_address_delete_list(zone_desc->slaves); } } else { #if HAS_MASTER_SUPPORT if(current->type == ZT_MASTER) { notify_slaves_then_delete = current->slaves; } else { host_address_delete_list(current->slaves); } if(zone_desc->type == ZT_MASTER) { notify_slaves = zone_desc->slaves; } #else host_address_delete_list(current->slaves); #endif current->slaves = zone_desc->slaves; } zone_desc->slaves = NULL; #endif // type : ? log_debug7("updating %p (%u) with %p (%u): type", current, current->lock_owner, zone_desc, zone_desc->lock_owner); current->type = zone_desc->type; #if HAS_ACL_SUPPORT // ac : apply the new one, update the zone access log_debug7("updating %p (%u) with %p (%u): ac@%p with ac@%p", current, current->lock_owner, zone_desc, zone_desc->lock_owner, ¤t->ac, &zone_desc->ac); #ifdef DEBUG log_debug7("old@%p:", current); log_debug7(" notify@%p",current->ac.allow_notify.ipv4.items); log_debug7(" query@%p",current->ac.allow_query.ipv4.items); log_debug7(" transfer@%p",current->ac.allow_transfer.ipv4.items); log_debug7(" update@%p",current->ac.allow_update.ipv4.items); log_debug7("forwarding@%p",current->ac.allow_update_forwarding.ipv4.items); log_debug7(" control@%p",current->ac.allow_control.ipv4.items); log_debug7("new@%p:", zone_desc); log_debug7(" notify@%p",zone_desc->ac.allow_notify.ipv4.items); log_debug7(" query@%p",zone_desc->ac.allow_query.ipv4.items); log_debug7(" transfer@%p",zone_desc->ac.allow_transfer.ipv4.items); log_debug7(" update@%p",zone_desc->ac.allow_update.ipv4.items); log_debug7("forwarding@%p",zone_desc->ac.allow_update_forwarding.ipv4.items); log_debug7(" control@%p",zone_desc->ac.allow_control.ipv4.items); #endif acl_unmerge_access_control(¤t->ac, &g_config->ac); acl_empties_access_control(¤t->ac); memcpy(¤t->ac, &zone_desc->ac, sizeof(access_control)); ZEROMEMORY(&zone_desc->ac, sizeof(access_control)); #endif // notify : reset, restart log_debug7("updating %p (%u) with %p (%u): notify", current, current->lock_owner, zone_desc, zone_desc->lock_owner); memcpy(¤t->notify, &zone_desc->notify, sizeof(zone_notify_s)); #if HAS_DNSSEC_SUPPORT #if HAS_RRSIG_MANAGEMENT_SUPPORT // signature : reset, restart log_debug7("updating %p (%u) with %p (%u): signature", current, current->lock_owner, zone_desc, zone_desc->lock_owner); memcpy(¤t->signature, &zone_desc->signature, sizeof(zone_signature_s)); #endif // dnssec_mode : drop everything related to the zone, load the new config log_debug7("updating %p (%u) with %p (%u): dnssec_mode", current, current->lock_owner, zone_desc, zone_desc->lock_owner); current->dnssec_mode = zone_desc->dnssec_mode; #endif // refresh : update the "alarms" log_debug7("updating %p (%u) with %p (%u): refresh", current, current->lock_owner, zone_desc, zone_desc->lock_owner); memcpy(¤t->refresh, &zone_desc->refresh, sizeof(zone_refresh_s)); // dynamic_provisioning : ? log_debug7("updating %p (%u) with %p (%u): dynamic_provisioning", current, current->lock_owner, zone_desc, zone_desc->lock_owner); memcpy(¤t->dynamic_provisioning, &zone_desc->dynamic_provisioning, sizeof(dynamic_provisioning_s)); // slaves : update the list zone_unlock(current, ZONE_LOCK_REPLACE_DESC); } // whatever has been decided above, loading the zone file should be queued database_zone_load(zone_desc->origin); #if HAS_DYNAMIC_PROVISIONING // if asking for a load of the zone_data on a master should trigger a notify of its slaves log_debug7("handling dynamic provisioning"); if(!host_address_empty(notify_slaves_then_delete)) { log_info("zone load desc: %{dnsname}: notifying slaves: %{hostaddrlist}", zone_desc->origin, notify_slaves_then_delete); notify_host_list(current, notify_slaves_then_delete, CLASS_CTRL); notify_slaves_then_delete = NULL; } if(!host_address_empty(notify_slaves)) { log_info("zone load desc: %{dnsname}: notifying slaves: %{hostaddrlist}", zone_desc->origin, notify_slaves); host_address *notify_slaves_copy = host_address_copy_list(notify_slaves); notify_host_list(current, notify_slaves_copy, CLASS_CTRL); notify_slaves = NULL; } #endif #if HAS_MASTER_SUPPORT && HAS_DNSSEC_SUPPORT && HAS_RRSIG_MANAGEMENT_SUPPORT if(current->dnssec_policy != zone_desc->dnssec_policy) { log_info("zone: %{dnsname}: %p: config: dnssec-policy modified", zone_desc->origin, zone_desc); if(zone_desc->dnssec_policy != NULL) { if(current->dnssec_policy != NULL) { log_warn("zone: %{dnsname}: %p: config: changing dnssec-policy at runtime (%s to %s)", zone_desc->origin, zone_desc, current->dnssec_policy->name, zone_desc->dnssec_policy->name); if(current->dnssec_policy->denial != zone_desc->dnssec_policy->denial) { log_warn("zone: %{dnsname}: %p: config: modifications of the dnssec-policy denial setting may be ignored", zone_desc->origin, zone_desc); } dnssec_policy_release(current->dnssec_policy); current->dnssec_policy = dnssec_policy_acquire_from_name(zone_desc->dnssec_policy->name); } else { log_info("zone: %{dnsname}: %p: config: dnssec-policy %s enabled", zone_desc->origin, zone_desc, zone_desc->dnssec_policy->name); current->dnssec_policy = dnssec_policy_acquire_from_name(zone_desc->dnssec_policy->name); } } else { log_warn("zone: %{dnsname}: %p: config: removing policy at runtime", zone_desc->origin, zone_desc); dnssec_policy_release(current->dnssec_policy); current->dnssec_policy = NULL; } } #endif if(current != zone_desc) { log_debug7("destroying temporary zone descriptor @%p", zone_desc); zone_release(zone_desc); } zone_clear_status(zone_desc, ZONE_STATUS_DROP_AFTER_RELOAD); zone_release(current); break; } // DUP default: { log_err("zone: %{dnsname}: %p: failed to register", zone_desc->origin, zone_desc); break; } } // switch } log_debug1("database_load_zone_desc(%p) done", zone_desc); }
ya_result gethostaddr(const char* host, u16 port, struct sockaddr *sa, int familly) { /* ------------------------------------------------------------ */ /* Create a network address structure * from the dotted-quad format ddd.ddd.ddd.ddd into a in_addr_t */ /* If not forced in ipv6 then ... */ struct addrinfo hints; struct addrinfo *info; struct addrinfo *next; int eai_err; ZEROMEMORY(&hints, sizeof(struct addrinfo)); hints.ai_family = familly; ZEROMEMORY(sa, sizeof(struct sockaddr)); // valid use of sizeof(struct sockaddr) /* ------------------------------------------------------------ */ if((eai_err = getaddrinfo(host, NULL, &hints, &info)) != 0) { return EAI_ERROR_CODE(eai_err); // NET_UNABLE_TO_RESOLVE_HOST } next = info; while(next != NULL) { if((familly != AF_INET6) && (next->ai_family == AF_INET)) /* Only process IPv4 addresses */ { struct sockaddr_in *sai = (struct sockaddr_in *)sa; memcpy(sai, next->ai_addr, next->ai_addrlen); sai->sin_port = htons(port); #if HAS_SOCKADDR_IN_SIN_LEN sai->sin_len = sizeof(struct sockaddr_in); #endif break; } if((familly != AF_INET) && (next->ai_family == AF_INET6)) /* Only process IPv4 addresses */ { struct sockaddr_in6 *sai6 = (struct sockaddr_in6 *)sa; memcpy(sai6, next->ai_addr, next->ai_addrlen); sai6->sin6_port = htons(port); #if HAS_SOCKADDR_IN6_SIN6_LEN sai6->sin6_len = sizeof(struct sockaddr_in6); #endif break; } next = next->ai_next; } freeaddrinfo(info); if(next == NULL) /* nothing found for AF_INET */ { return NET_UNABLE_TO_RESOLVE_HOST; } return SUCCESS; }
ya_result xfr_input_stream_init(input_stream* filtering_stream, const u8 *origin, input_stream *xfr_source_stream, message_data *message, u32 current_serial, xfr_copy_flags flags) { yassert(filtering_stream != NULL && origin != NULL && xfr_source_stream != NULL && message != NULL); input_stream *is = xfr_source_stream; packet_unpack_reader_data reader; u8 *buffer; u8 *record; u8 *ptr; #if DNSCORE_HAS_TSIG_SUPPORT const tsig_item *tsig; #endif ya_result record_len; ya_result return_value; u32 origin_len; u32 last_serial = 0; u16 tcplen; u16 qtype; u16 qclass; u16 old_mac_size; bool last_message_had_tsig; bool need_cleanup_tsig = FALSE; #if DNSCORE_HAS_TSIG_SUPPORT u8 old_mac[64]; #endif /* * ensure the stream will be unusable if the initialisation fails */ input_stream_set_void(filtering_stream); /* * Start by reading the first packet, and determine if it's an AXFR or an IXFR (for the name) * note: it's read and converted to the host endianness */ if(!is_fd_input_stream(is)) { // expected file input stream return INVALID_ARGUMENT_ERROR; } //buffer_input_stream_init(is, is, 4096); /* TCP length */ if(FAIL(return_value = input_stream_read_nu16(is, &tcplen))) { return return_value; } if(return_value != 2) { return UNEXPECTED_EOF; } /* if the length is not enough, return the most appropriate error code */ origin_len = dnsname_len(origin); if(tcplen < DNS_HEADER_LENGTH + origin_len + 4) { return_value = UNEXPECTED_EOF; if(tcplen >= DNS_HEADER_LENGTH) { if(ISOK(return_value = input_stream_read_fully(is, message->pool_buffer, DNS_HEADER_LENGTH))) { return_value = MAKE_DNSMSG_ERROR(MESSAGE_RCODE(message->pool_buffer)); } } return return_value; } /* read the whole message */ buffer = &message->buffer[0]; record = &message->pool_buffer[0]; assert(sizeof(message->pool_buffer) >= 255 + 10 + 65535); if(FAIL(return_value = input_stream_read_fully(is, buffer, tcplen))) { return return_value; } #if DEBUG_XFR_INPUT_STREAM log_memdump(g_system_logger, MSG_DEBUG1, &message->buffer[0], tcplen, 32); #endif message->received = return_value; /* check the message makes sense */ const u64 *h64 = (u64*)buffer; u64 m64 = AXFR_MESSAGE_HEADER_MASK; u64 r64 = AXFR_MESSAGE_HEADER_RESULT; if(((*h64&m64) != r64) || (MESSAGE_NS(message->buffer) != 0)) { u8 code = MESSAGE_RCODE(message->buffer); if(code != 0) { return_value = MAKE_DNSMSG_ERROR(code); } else { return_value = UNPROCESSABLE_MESSAGE; } return return_value; } //m64 = AXFR_NEXT_MESSAGE_HEADER_MASK; //r64 = AXFR_NEXT_MESSAGE_HEADER_RESULT; packet_reader_init(&reader, buffer, tcplen); reader.offset = DNS_HEADER_LENGTH; packet_reader_read_fqdn(&reader, record, RDATA_MAX_LENGTH + 1); if(!dnsname_equals(record, origin)) { return INVALID_PROTOCOL; } if(FAIL(return_value = packet_reader_read_u16(&reader, &qtype))) { return return_value; } if(return_value != 2) { return UNEXPECTED_EOF; } /* * check that we are allowed to process this particular kind of transfer * note : this does not determine what is REALLY begin transferred */ switch(qtype) { case TYPE_AXFR: { if((flags & XFR_ALLOW_AXFR) == 0) { return INVALID_PROTOCOL; } break; } case TYPE_IXFR: { if((flags & XFR_ALLOW_IXFR) == 0) { return INVALID_PROTOCOL; } break; } default: { return INVALID_PROTOCOL; } } if(FAIL(return_value = packet_reader_read_u16(&reader, &qclass))) { return return_value; } if(qclass != CLASS_IN) { /** wrong answer */ return INVALID_PROTOCOL; } /* check for TSIG and verify */ u16 ancount = ntohs(MESSAGE_AN(buffer)); #if DNSCORE_HAS_TSIG_SUPPORT if((last_message_had_tsig = ((tsig = message->tsig.tsig) != NULL))) { /* verify the TSIG * * AR > 0 * skip ALL the records until the last AR * it MUST be a TSIG * It's the first TSIG answering to our query * verify it * */ message->tsig.tsig = NULL; old_mac_size = message->tsig.mac_size; memcpy(old_mac, message->tsig.mac, old_mac_size); if(FAIL(return_value = tsig_message_extract(message))) { log_debug("xfr_input_stream: error extracting the signature"); return return_value; } if(return_value == 0) { log_debug("xfr_input_stream: no signature when one was requested"); return TSIG_BADSIG; /* no signature, when one was requested, is a bad signature */ } if(message->tsig.tsig != tsig) { /* This is not the one we started with */ log_debug("xfr_input_stream: signature key does not match"); return TSIG_BADSIG; } /// check that the tsig in the message matches the one that was sent if(FAIL(return_value = tsig_verify_tcp_first_message(message, old_mac, old_mac_size))) { return return_value; } reader.packet_size = message->received; need_cleanup_tsig = TRUE; } #endif log_debug("xfr_input_stream: expecting %5d answer records", ancount); /* * read the SOA (it MUST be an SOA) */ if(FAIL(record_len = packet_reader_read_record(&reader, record, RDATA_MAX_LENGTH + 1))) { return record_len; } if(!dnsname_equals(record, origin)) { return INVALID_PROTOCOL; } ptr = &record[origin_len]; if(GET_U16_AT(*ptr) != TYPE_SOA) { return INVALID_PROTOCOL; } ptr += 8; /* type class ttl */ u16 rdata_size = ntohs(GET_U16_AT(*ptr)); if(rdata_size < 22) { return INVALID_PROTOCOL; } rdata_size -= 16; ptr += 2; /* rdata size */ s32 len = dnsname_len(ptr); if(len >= rdata_size) { return INVALID_PROTOCOL; } rdata_size -= len; ptr += len; len = dnsname_len(ptr); if(len >= rdata_size) { return INVALID_PROTOCOL; } rdata_size -= len; if(rdata_size != 4) { return INVALID_PROTOCOL; } ptr += len; // if the serial of the SOA is the same one as we know, then there is no // need to download the zone last_serial = ntohl(GET_U32_AT(*ptr)); if(last_serial == current_serial) { //args->out_loaded_serial = args->current_serial; return ZONE_ALREADY_UP_TO_DATE; } xfr_input_stream_data *data; ZALLOC_OR_DIE(xfr_input_stream_data*, data, xfr_input_stream_data, XFRISDTA_TAG); ZEROMEMORY(data, sizeof(xfr_input_stream_data)); /* * We have got the first SOA * Next time we find this SOA (second next time for IXFR) the stream, it will be the end of the stream */ /* * The stream can be AXFR or IXFR. * The only way to know this is to look at the records, maybe on many packets. * If there are two SOA (different serial numbers) for the start, then it's an IXFR, else it's an AXFR. * * OPEN A PIPE STREAM "XFRs" * * Save the first SOA */ MALLOC_OR_DIE(u8*, data->first_soa_record, record_len, XFRISSOA_TAG); MEMCOPY(data->first_soa_record, record, record_len); data->first_soa_record_size = record_len; filtering_stream->vtbl = &xfr_input_stream_vtbl; filtering_stream->data = data; pipe_stream_init(&data->pipe_stream_output, &data->pipe_stream_input, 65536); MEMCOPY(&data->reader, &reader, sizeof(packet_unpack_reader_data)); data->origin = origin; data->message = message; data->ancount = ancount - 1; data->record_index++; data->last_serial = last_serial; data->xfr_mode = TYPE_ANY; data->ixfr_mark = FALSE; data->last_message_had_tsig = last_message_had_tsig; data->source_stream = *is; data->need_cleanup_tsig = need_cleanup_tsig; /* * Then we read all records for all packets * If we find an SOA ... * AXFR: it has to be the last serial and it is the end of the stream. * IXFR: if it's not the last serial it has to go from step to step * AND once we have reached the "last serial" once, the next hit is the end of the stream. */ data->eos = FALSE; /* * In order to know what the type is, read the first packet. */ return_value = xfr_input_stream_read_packet(data); if(FAIL(return_value)) { xfr_input_stream_close(filtering_stream); } return return_value; }
int InfHostOpenBufferedFile(PHINF InfHandle, void *Buffer, ULONG BufferSize, LANGID LanguageId, ULONG *ErrorLine) { INFSTATUS Status; PINFCACHE Cache; WCHAR *FileBuffer; ULONG FileBufferSize; *InfHandle = NULL; *ErrorLine = (ULONG)-1; /* Allocate file buffer */ FileBufferSize = BufferSize + 2; FileBuffer = MALLOC(FileBufferSize); if (FileBuffer == NULL) { DPRINT1("MALLOC() failed\n"); return(INF_STATUS_INSUFFICIENT_RESOURCES); } MEMCPY(FileBuffer, Buffer, BufferSize); /* Append string terminator */ FileBuffer[BufferSize] = 0; FileBuffer[BufferSize + 1] = 0; /* Allocate infcache header */ Cache = (PINFCACHE)MALLOC(sizeof(INFCACHE)); if (Cache == NULL) { DPRINT1("MALLOC() failed\n"); FREE(FileBuffer); return(INF_STATUS_INSUFFICIENT_RESOURCES); } /* Initialize inicache header */ ZEROMEMORY(Cache, sizeof(INFCACHE)); Cache->LanguageId = LanguageId; /* Parse the inf buffer */ if (!RtlIsTextUnicode(FileBuffer, (INT)FileBufferSize, NULL)) { // static const BYTE utf8_bom[3] = { 0xef, 0xbb, 0xbf }; WCHAR *new_buff; // UINT codepage = CP_ACP; UINT offset = 0; // if (BufferSize > sizeof(utf8_bom) && !memcmp(FileBuffer, utf8_bom, sizeof(utf8_bom) )) // { // codepage = CP_UTF8; // offset = sizeof(utf8_bom); // } new_buff = MALLOC(FileBufferSize * sizeof(WCHAR)); if (new_buff != NULL) { ULONG len; Status = RtlMultiByteToUnicodeN(new_buff, FileBufferSize * sizeof(WCHAR), &len, (char *)FileBuffer + offset, FileBufferSize - offset); Status = InfpParseBuffer(Cache, new_buff, new_buff + len / sizeof(WCHAR), ErrorLine); FREE(new_buff); } else Status = INF_STATUS_INSUFFICIENT_RESOURCES; } else { WCHAR *new_buff = (WCHAR *)FileBuffer; /* UCS-16 files should start with the Unicode BOM; we should skip it */ if (*new_buff == 0xfeff) { new_buff++; FileBufferSize -= sizeof(WCHAR); } Status = InfpParseBuffer(Cache, new_buff, (WCHAR*)((char*)new_buff + FileBufferSize), ErrorLine); } if (!INF_SUCCESS(Status)) { FREE(Cache); Cache = NULL; } /* Free file buffer */ FREE(FileBuffer); *InfHandle = (HINF)Cache; return INF_SUCCESS(Status) ? 0 : -1; }
// // 全メモリ/レジスタ等の初期化 // void NesSub_MemoryInitial() { INT i; // メモリクリア ZEROMEMORY( RAM, sizeof(RAM) ); ZEROMEMORY( WRAM, sizeof(WRAM) ); ZEROMEMORY( DRAM, sizeof(DRAM) ); ZEROMEMORY( ERAM, sizeof(ERAM) ); ZEROMEMORY( XRAM, sizeof(XRAM) ); ZEROMEMORY( CRAM, sizeof(CRAM) ); ZEROMEMORY( VRAM, sizeof(VRAM) ); ZEROMEMORY( SPRAM, sizeof(SPRAM) ); ZEROMEMORY( BGPAL, sizeof(BGPAL) ); ZEROMEMORY( SPPAL, sizeof(SPPAL) ); ZEROMEMORY( CPUREG, sizeof(CPUREG) ); ZEROMEMORY( PPUREG, sizeof(PPUREG) ); FrameIRQ = 0xC0; PROM = VROM = NULL; // 0 除算防止対策 PROM_8K_SIZE = PROM_16K_SIZE = PROM_32K_SIZE = 1; VROM_1K_SIZE = VROM_2K_SIZE = VROM_4K_SIZE = VROM_8K_SIZE = 1; // デフォルトバンク設定 for( i = 0; i < 8; i++ ) { CPU_MEM_BANK[i] = NULL; CPU_MEM_TYPE[i] = BANKTYPE_ROM; CPU_MEM_PAGE[i] = 0; } // 内臓RAM/WRAM SetPROM_Bank( 0, RAM, BANKTYPE_RAM ); SetPROM_Bank( 3, WRAM, BANKTYPE_RAM ); // ダミー SetPROM_Bank( 1, XRAM, BANKTYPE_ROM ); SetPROM_Bank( 2, XRAM, BANKTYPE_ROM ); for( i = 0; i < 8; i++ ) { CRAM_USED[i] = 0; } // PPU VROMバンク設定 // SetVRAM_Mirror( VRAM_MIRROR4 ); }
RemoteDesktop::DesktopBackground::DesktopBackground(){ ZEROMEMORY(_Wallpaper_Style); ZEROMEMORY(_Wallpaper_Path); }
NTSTATUS InfOpenFile(PHINF InfHandle, PUNICODE_STRING FileName, PULONG ErrorLine) { OBJECT_ATTRIBUTES ObjectAttributes; FILE_STANDARD_INFORMATION FileInfo; IO_STATUS_BLOCK IoStatusBlock; HANDLE FileHandle; NTSTATUS Status; PCHAR FileBuffer; ULONG FileLength; LARGE_INTEGER FileOffset; PINFCACHE Cache; CheckHeap(); *InfHandle = NULL; *ErrorLine = (ULONG)-1; /* Open the inf file */ InitializeObjectAttributes(&ObjectAttributes, FileName, 0, NULL, NULL); Status = NtOpenFile(&FileHandle, GENERIC_READ | SYNCHRONIZE, &ObjectAttributes, &IoStatusBlock, FILE_SHARE_READ, FILE_SYNCHRONOUS_IO_NONALERT | FILE_NON_DIRECTORY_FILE); if (!INF_SUCCESS(Status)) { DPRINT("NtOpenFile() failed (Status %lx)\n", Status); return(Status); } DPRINT("NtOpenFile() successful\n"); /* Query file size */ Status = NtQueryInformationFile(FileHandle, &IoStatusBlock, &FileInfo, sizeof(FILE_STANDARD_INFORMATION), FileStandardInformation); if (!INF_SUCCESS(Status)) { DPRINT("NtQueryInformationFile() failed (Status %lx)\n", Status); NtClose(FileHandle); return(Status); } FileLength = FileInfo.EndOfFile.u.LowPart; DPRINT("File size: %lu\n", FileLength); /* Allocate file buffer */ FileBuffer = MALLOC(FileLength + 1); if (FileBuffer == NULL) { DPRINT1("MALLOC() failed\n"); NtClose(FileHandle); return(INF_STATUS_INSUFFICIENT_RESOURCES); } /* Read file */ FileOffset.QuadPart = 0ULL; Status = NtReadFile(FileHandle, NULL, NULL, NULL, &IoStatusBlock, FileBuffer, FileLength, &FileOffset, NULL); /* Append string terminator */ FileBuffer[FileLength] = 0; NtClose(FileHandle); if (!INF_SUCCESS(Status)) { DPRINT("NtReadFile() failed (Status %lx)\n", Status); FREE(FileBuffer); return(Status); } /* Allocate infcache header */ Cache = (PINFCACHE)MALLOC(sizeof(INFCACHE)); if (Cache == NULL) { DPRINT("MALLOC() failed\n"); FREE(FileBuffer); return(INF_STATUS_INSUFFICIENT_RESOURCES); } /* Initialize inicache header */ ZEROMEMORY(Cache, sizeof(INFCACHE)); /* Parse the inf buffer */ Status = InfpParseBuffer (Cache, FileBuffer, FileBuffer + FileLength, ErrorLine); if (!INF_SUCCESS(Status)) { FREE(Cache); Cache = NULL; } /* Free file buffer */ FREE(FileBuffer); *InfHandle = (HINF)Cache; return(Status); }
ya_result zonefile_read(zone_file* in_file, zonefile_entry* entry) { zassert((in_file != NULL) && (entry != NULL)); input_stream* is = &in_file->bis; ZEROMEMORY(entry, sizeof (zonefile_entry)); if(FAIL(input_stream_read_dnsname(is, entry->name))) { zonefile_entry_freecontent(entry); return ZDB_ERROR_CORRUPTEDDATA; } if(entry->name[0] == 0) { return SUCCESS; } if(FAIL(input_stream_read_nu16(is, &entry->class))) { zonefile_entry_freecontent(entry); return ZDB_ERROR_CORRUPTEDDATA; } if(FAIL(input_stream_read_nu16(is, &entry->type))) { zonefile_entry_freecontent(entry); return ZDB_ERROR_CORRUPTEDDATA; } if(FAIL(input_stream_read_nu32(is, &entry->ttl))) { zonefile_entry_freecontent(entry); return ZDB_ERROR_CORRUPTEDDATA; } /* because the type is stored on 32 bits instead of 16 bits */ if(FAIL(input_stream_read_nu16(is, &entry->rdata_size))) { zonefile_entry_freecontent(entry); return ZDB_ERROR_CORRUPTEDDATA; } if(FAIL(input_stream_read_nu16(is, &entry->rdata_size))) { zonefile_entry_freecontent(entry); return ZDB_ERROR_CORRUPTEDDATA; } MALLOC_OR_DIE(u8*, entry->rdata, entry->rdata_size, ZONEFILE_RDATA_TAG); /* ZALLOC IMPOSSIBLE */ if(FAIL(input_stream_read_fully(is, entry->rdata, entry->rdata_size))) { zonefile_entry_freecontent(entry); return ZDB_ERROR_CORRUPTEDDATA; } return SUCCESS; }