void heap_init(void) { int z; LTRACE_ENTRY; // set the heap range in normal zone theheap[ZONE_NORMAL].base = (void *)HEAP_START; theheap[ZONE_NORMAL].len = HEAP_LEN; #ifdef WITH_DMA_ZONE theheap[ZONE_DMA].base = (void *)DMA_START; theheap[ZONE_DMA].len = DMA_LEN; #endif for (z = 0; z < MAX_ZONES; z++) { LTRACEF("base %p size %zd bytes (%s)\n", theheap[z].base, theheap[z].len, zone_name(z)); // initialize the free list list_initialize(&theheap[z].free_list); // create an initial free chunk heap_insert_free_chunk(z, heap_create_free_chunk(theheap[z].base, theheap[z].len)); } // dump heap info // heap_dump(); // dprintf(INFO, "running heap tests\n"); // heap_test(); }
static void printcompatkey(int sockfd, zone_t* zone, key_data_t* key, char*tchange, hsm_key_t* hsmkey) { (void)hsmkey; client_printf(sockfd, "%-31s %-8s %-9s %s\n", zone_name(zone), key_data_role_text(key), map_keystate(key), tchange); }
static void printverboseparsablekey(int sockfd, zone_t* zone, key_data_t* key, char* tchange, hsm_key_t* hsmkey) { client_printf(sockfd, "%s;%s;%s;%s;%d;%d;%s;%s;%d\n", zone_name(zone), key_data_role_text(key), map_keystate(key), tchange, hsm_key_bits(hsmkey), hsm_key_algorithm(hsmkey), hsm_key_locator(hsmkey), hsm_key_repository(hsmkey), key_data_keytag(key)); }
static void heap_dump(void) { int z; for (z = 0; z < MAX_ZONES; z++) { dprintf(INFO, "\nHeap dump (%s):\n", zone_name(z)); dprintf(INFO, "\tbase %p, len 0x%zx\n", theheap[z].base, theheap[z].len); dprintf(INFO, "\tfree list:\n"); struct free_heap_chunk *chunk; list_for_every_entry(&theheap[z].free_list, chunk, struct free_heap_chunk, node) { dump_free_chunk(chunk); } } }
static void print_zone(int sockfd, const char* fmt, const zone_t* zone) { key_data_list_t *keylist; const key_data_t *key; keylist = zone_get_keys(zone); while ((key = key_data_list_next(keylist))) { char *tchange = map_keytime(zone, key); client_printf(sockfd, fmt, zone_name(zone), key_data_role_text(key), tchange); free(tchange); } key_data_list_free(keylist); }
static void printdebugparsablekey(int sockfd, zone_t* zone, key_data_t* key, char* tchange, hsm_key_t* hsmkey) { (void)tchange; client_printf(sockfd, "%s;%s;%s;%s;%s;%s;%d;%d;%s\n", zone_name(zone), key_data_role_text(key), key_state_state_text(key_data_cached_ds(key)), key_state_state_text(key_data_cached_dnskey(key)), key_state_state_text(key_data_cached_rrsigdnskey(key)), key_state_state_text(key_data_cached_rrsig(key)), key_data_publish(key), key_data_active_ksk(key) | key_data_active_zsk(key), hsm_key_locator(hsmkey)); }
static void printverbosekey(int sockfd, zone_t* zone, key_data_t* key, char* tchange, hsm_key_t* hsmkey) { (void)tchange; client_printf(sockfd, "%-31s %-8s %-9s %-24s %-5d %-10d %-32s %-11s %d\n", zone_name(zone), key_data_role_text(key), map_keystate(key), tchange, hsm_key_bits(hsmkey), hsm_key_algorithm(hsmkey), hsm_key_locator(hsmkey), hsm_key_repository(hsmkey), key_data_keytag(key)); }
// =-=-=-=-=-=-=- /// @brief function which determines if a collection is created at the root level irods::error validate_collection_path( const std::string& _path ) { // =-=-=-=-=-=-=- // set up a default error structure std::stringstream msg; msg << "a valid zone name does not appear at the root of the collection path ["; msg << _path; msg << "]"; irods::error ret_val = ERROR( SYS_INVALID_INPUT_PARAM, msg.str() ); // =-=-=-=-=-=-=- // loop over the ZoneInfo linked list and see if the path // has a root collection which matches any zone zoneInfo_t* zone_info = ZoneInfoHead; while ( zone_info ) { // =-=-=-=-=-=-=- // build a root zone name std::string zone_name( "/" ); zone_name += zone_info->zoneName; // =-=-=-=-=-=-=- // if the zone name appears at the root // then this is a good path size_t pos = _path.find( zone_name ); if ( 0 == pos ) { ret_val = SUCCESS(); zone_info = 0; } else { zone_info = zone_info->next; } } // while return ret_val; } // validate_collection_path
static time_t perform_enforce(int sockfd, engine_type *engine, int bForceUpdate, task_type* task, db_connection_t *dbconn) { zone_list_t *zonelist = NULL; zone_t *zone, *firstzone = NULL; policy_t *policy; key_data_list_t *keylist; const key_data_t *key; time_t t_next, t_now = time_now(), t_reschedule = -1; /* Flags that indicate tasks to be scheduled after zones have been * enforced. */ int bSignerConfNeedsWriting = 0; int bSubmitToParent = 0; int bRetractFromParent = 0; int zone_updated; if (!(zonelist = zone_list_new(dbconn)) /*|| zone_list_associated_fetch(zonelist)*/ || zone_list_get(zonelist)) { zone_list_free(zonelist); zonelist = NULL; } if (!zonelist) { /* TODO: log error */ ods_log_error("[%s] zonelist NULL", module_str); /* TODO: backoff? */ return t_reschedule; } for (zone = zone_list_get_next(zonelist); zone; zone_free(zone), zone = zone_list_get_next(zonelist)) { if (engine->need_to_reload || engine->need_to_exit) break; if (!bForceUpdate && (zone_next_change(zone) == -1)) { continue; } else if (zone_next_change(zone) > t_now && !bForceUpdate) { /* This zone needs no update, however it might be the first * for future updates */ if (zone_next_change(zone) < t_reschedule || !firstzone) { t_reschedule = zone_next_change(zone); if (firstzone) { zone_free(firstzone); } firstzone = zone; zone = NULL; /* keeps firstzone from being freed. */ } continue; } if (!(policy = zone_get_policy(zone))) { client_printf(sockfd, "Next update for zone %s NOT scheduled " "because policy is missing !\n", zone_name(zone)); if (zone_next_change(zone) != -1 && (zone_set_next_change(zone, -1) || zone_update(zone))) { /* TODO: Log error */ } continue; } if (policy_passthrough(policy)) { ods_log_info("Passing through zone %s.\n", zone_name(zone)); zone_set_signconf_needs_writing(zone, 1); zone_update(zone); bSignerConfNeedsWriting = 1; policy_free(policy); continue; } zone_updated = 0; t_next = update(engine, dbconn, zone, policy, t_now, &zone_updated); policy_free(policy); bSignerConfNeedsWriting |= zone_signconf_needs_writing(zone); keylist = zone_get_keys(zone); while ((key = key_data_list_next(keylist))) { if (key_data_ds_at_parent(key) == KEY_DATA_DS_AT_PARENT_SUBMIT) { ods_log_warning("[%s] please submit DS " "with keytag %d for zone %s", module_str, key_data_keytag(key)&0xFFFF, zone_name(zone)); bSubmitToParent = 1; } else if (key_data_ds_at_parent(key) == KEY_DATA_DS_AT_PARENT_RETRACT) { ods_log_warning("[%s] please retract DS " "with keytag %d for zone %s", module_str, key_data_keytag(key)&0xFFFF, zone_name(zone)); bRetractFromParent = 1; } } key_data_list_free(keylist); if (t_next == -1) { client_printf(sockfd, "Next update for zone %s NOT scheduled " "by enforcer !\n", zone_name(zone)); ods_log_debug("Next update for zone %s NOT scheduled " "by enforcer !\n", zone_name(zone)); } else { /* Invalid schedule time then skip the zone.*/ char tbuf[32] = "date/time invalid\n"; /* at least 26 bytes */ ctime_r(&t_next, tbuf); /* note that ctime_r inserts \n */ client_printf(sockfd, "Next update for zone %s scheduled at %s", zone_name(zone), tbuf); ods_log_debug("Next update for zone %s scheduled at %s", zone_name(zone), tbuf); } if (zone_next_change(zone) != t_next) { zone_set_next_change(zone, t_next); zone_updated = 1; } /* * Commit the changes to the zone if there where any. */ if (zone_updated) { if (zone_update(zone)) { ods_log_debug("[%s] error zone_update(%s)", module_str, zone_name(zone)); } } /* * Find out when to schedule the next change. */ if (zone_next_change(zone) != -1 && (zone_next_change(zone) < t_reschedule || !firstzone)) { t_reschedule = zone_next_change(zone); if (firstzone) { zone_free(firstzone); } firstzone = zone; zone = NULL; } } zone_list_free(zonelist); /* * Schedule the next change if needed. */ if (firstzone) { reschedule_enforce(task, t_reschedule, zone_name(firstzone)); zone_free(firstzone); } /* Launch signer configuration writer task when one of the * zones indicated that it needs to be written. * TODO: unschedule it first! */ if (bSignerConfNeedsWriting) { task_type *signconf = signconf_task(dbconn, "signconf", "signer configurations"); enf_schedule_task(sockfd,engine,signconf,"signconf"); } else { ods_log_info("[%s] No changes to any signconf file required", module_str); } /* Launch ds-submit task when one of the updated key states has the * DS_SUBMIT flag set. */ if (bSubmitToParent) { task_type *submit = keystate_ds_submit_task(engine); enf_schedule_task(sockfd, engine, submit, "ds-submit"); } /* Launch ds-retract task when one of the updated key states has the * DS_RETRACT flag set. */ if (bRetractFromParent) { task_type *retract = keystate_ds_retract_task(engine); enf_schedule_task(sockfd, engine, retract, "ds-retract"); } return t_reschedule; }
size_t strftime(char *string, size_t max, const char *format, const struct tm *tm) { enum padding pad; /* Type of padding to apply. */ size_t length = 0; /* Characters put in STRING so far. */ for (; *format && length < max; ++format) { if (*format != '%') add_char(*format); else { ++format; /* Modifiers: */ if (*format == '-') { pad = none; ++format; } else if (*format == '_') { pad = blank; ++format; } else pad = zero; switch (*format) { /* Literal character fields: */ case 0: case '%': add_char('%'); break; case 'n': add_char('\n'); break; case 't': add_char('\t'); break; default: add_char(*format); break; /* Time fields: */ case 'H': case 'k': length += add_num2(&string[length], tm->tm_hour, max - length, *format == 'H' ? pad : blank); break; case 'I': case 'l': { int hour12; if (tm->tm_hour == 0) hour12 = 12; else if (tm->tm_hour > 12) hour12 = tm->tm_hour - 12; else hour12 = tm->tm_hour; length += add_num2(&string[length], hour12, max - length, *format == 'I' ? pad : blank); } break; case 'M': length += add_num2(&string[length], tm->tm_min, max - length, pad); break; case 'p': if (tm->tm_hour < 12) add_char('A'); else add_char('P'); add_char('M'); break; case 'r': length += strftime(&string[length], max - length, "%I:%M:%S %p", tm); break; case 'R': length += strftime(&string[length], max - length, "%H:%M", tm); break; case 's': { struct tm writable_tm; writable_tm = *tm; length += add_num_time_t(&string[length], max - length, mktime (&writable_tm)); } break; case 'S': length += add_num2(&string[length], tm->tm_sec, max - length, pad); break; case 'T': length += strftime(&string[length], max - length, "%H:%M:%S", tm); break; case 'X': length += strftime(&string[length], max - length, "%H:%M:%S", tm); break; case 'Z': #ifdef HAVE_TM_ZONE length += add_str(&string[length], tm->tm_zone, max - length); #else #ifdef HAVE_TZNAME if (tm->tm_isdst && tzname[1] && *tzname[1]) length += add_str(&string[length], tzname[1], max - length); else length += add_str(&string[length], tzname[0], max - length); #else length += add_str(&string[length], zone_name(tm), max - length); #endif #endif break; /* Date fields: */ case 'a': add_char(days[tm->tm_wday][0]); add_char(days[tm->tm_wday][1]); add_char(days[tm->tm_wday][2]); break; case 'A': length += add_str(&string[length], days[tm->tm_wday], max - length); break; case 'b': case 'h': add_char(months[tm->tm_mon][0]); add_char(months[tm->tm_mon][1]); add_char(months[tm->tm_mon][2]); break; case 'B': length += add_str(&string[length], months[tm->tm_mon], max - length); break; case 'c': length += strftime(&string[length], max - length, "%a %b %d %H:%M:%S %Z %Y", tm); break; case 'C': length += add_num2(&string[length], (tm->tm_year + 1900) / 100, max - length, pad); break; case 'd': length += add_num2(&string[length], tm->tm_mday, max - length, pad); break; case 'e': length += add_num2(&string[length], tm->tm_mday, max - length, blank); break; case 'D': length += strftime(&string[length], max - length, "%m/%d/%y", tm); break; case 'j': length += add_num3(&string[length], tm->tm_yday + 1, max - length, pad); break; case 'm': length += add_num2(&string[length], tm->tm_mon + 1, max - length, pad); break; case 'U': length += add_num2(&string[length], sun_week(tm), max - length, pad); break; case 'w': add_char(tm->tm_wday + '0'); break; case 'W': length += add_num2(&string[length], mon_week(tm), max - length, pad); break; case 'x': length += strftime(&string[length], max - length, "%m/%d/%y", tm); break; case 'y': length += add_num2(&string[length], tm->tm_year % 100, max - length, pad); break; case 'Y': add_char((tm->tm_year + 1900) / 1000 + '0'); length += add_num3(&string[length], (1900 + tm->tm_year) % 1000, max - length, zero); break; } } } add_char(0); return length - 1; }
static int perform_keystate_list(int sockfd, db_connection_t *dbconn, const char* filterZone, char** filterKeytype, char** filterKeystate, void (printheader)(int sockfd), void (printkey)(int sockfd, zone_t* zone, key_data_t* key, char*tchange, hsm_key_t* hsmKey)) { key_data_list_t* key_list; key_data_t* key; zone_t *zone = NULL; char* tchange; hsm_key_t *hsmkey; int cmp; int i, skipPrintKey; if (!(key_list = key_data_list_new_get(dbconn))) { client_printf_err(sockfd, "Unable to get list of keys, memory " "allocation or database error!\n"); return 1; } if (printheader) { (*printheader)(sockfd); } while ((key = key_data_list_get_next(key_list))) { /* only refetches zone if different from previous */ if (zone && (db_value_cmp(zone_id(zone), key_data_zone_id(key), &cmp) || cmp)) { zone_free(zone); zone = NULL; } if (!zone) { zone = key_data_get_zone(key); } hsmkey = key_data_get_hsm_key(key); key_data_cache_key_states(key); tchange = map_keytime(zone, key); /* allocs */ skipPrintKey = 0; if(printkey == NULL) skipPrintKey = 1; if(filterZone != NULL && strcmp(zone_name(zone), filterZone)) skipPrintKey = 1; for(i=0; filterKeytype && filterKeytype[i]; i++) if(!strcasecmp(filterKeytype[i],key_data_role_text(key))) break; if(filterKeytype && filterKeytype[i] == NULL) skipPrintKey = 1; for(i=0; filterKeystate && filterKeystate[i]; i++) if(!strcasecmp(filterKeystate[i],map_keystate(key))) break; if(filterKeystate && filterKeystate[i] == NULL) skipPrintKey = 1; if (!skipPrintKey) { (*printkey)(sockfd, zone, key, tchange, hsmkey); } free(tchange); hsm_key_free(hsmkey); key_data_free(key); } zone_free(zone); key_data_list_free(key_list); return 0; }