/* Lookup an SA by name, case-independent, and phase. */ struct sa * sa_lookup_by_name(char *name, int phase) { struct name_phase_arg arg; arg.name = name; arg.phase = phase; return sa_find(sa_check_name_phase, &arg); }
/* * Find an ISAKMP SA with a "name" of DST & SPI. */ struct sa * sa_lookup_isakmp_sa(struct sockaddr *dst, u_int8_t *spi) { struct dst_isakmpspi_arg arg; arg.dst = dst; arg.spi = spi; return sa_find(isakmp_sa_check, &arg); }
/* Lookup a ready ISAKMP SA given its peer address. */ struct sa * sa_isakmp_lookup_by_peer(struct sockaddr *dst, socklen_t dstlen) { struct addr_arg arg; arg.addr = dst; arg.len = dstlen; arg.phase = 1; return sa_find(sa_check_peer, &arg); }
static void daemon_shutdown(void) { /* Perform a (protocol-wise) clean shutdown of the daemon. */ struct sa *sa; if (sigtermed == 1) { log_print("isakmpd: shutting down..."); if (delete_sas && strncmp("no", conf_get_str("General", "Delete-SAs"), 2)) { /* * Delete all active SAs. First IPsec SAs, then * ISAKMPD. Each DELETE is another (outgoing) message. */ while ((sa = sa_find(phase2_sa_check, NULL))) sa_delete(sa, 1); while ((sa = sa_find(phase1_sa_check, NULL))) sa_delete(sa, 1); } /* We only want to do this once. */ sigtermed++; } if (transport_prio_sendqs_empty()) { /* * When the prioritized transport sendq:s are empty, i.e all * the DELETE notifications have been sent, we can shutdown. */ log_packet_stop(); log_print("isakmpd: exit"); exit(0); } }
int main(int argc, char *argv[]) { SUFARY *ary; SUF_RESULT sr; ary = sa_open(argv[2], NULL); if (ary == NULL) exit(1); sa_set_debug_mode(1); sr = sa_find(ary, 0, sa_get_array_size(ary) - 1, argv[1], strlen(argv[1]), 0); printf("%ld %ld\n", sr.left, sr.right); if (sr.stat == SUCCESS) { SA_INDEX tmp; for (tmp = sr.left; tmp <= sr.right; tmp++) { /* '<=' に注意 */ SA_INDEX pos = sa_aryidx2txtidx(ary, tmp); char *txt_ptr; printf("★テキストファイルの %ld 文字目からマッチ\n", pos); printf("★先頭二文字表示(1)\n%.*s\n", 2, sa_aryidx2txtptr(ary, tmp)); txt_ptr = sa_get_string(ary, pos, 2); printf("★先頭二文字表示(2)\n%s\n", txt_ptr); free(txt_ptr); txt_ptr = sa_get_line(ary, pos); printf("★一行表示\n%s\n", txt_ptr); free(txt_ptr); txt_ptr = sa_get_lines(ary, pos, 1, 1); printf("★前後の一行も表示\n%s\n", txt_ptr); free(txt_ptr); txt_ptr = sa_get_block(ary, pos, "<DOC>", "</DOC>"); printf("★DOC タグに囲まれた領域を表示\n%s\n", txt_ptr); free(txt_ptr); } } sa_close(ary); return 0; }
static void daemon_shutdown (void) { /* Perform a (protocol-wise) clean shutdown of the daemon. */ struct sa *sa; if (sigtermed == 1) { log_print ("isakmpd: shutting down..."); /* Delete all active phase 2 SAs. */ while ((sa = sa_find (phase2_sa_check, NULL))) { /* Each DELETE is another (outgoing) message. */ sa_delete (sa, 1); } sigtermed++; } if (transport_prio_sendqs_empty ()) { /* * When the prioritized transport sendq:s are empty, i.e all * the DELETE notifications have been sent, we can shutdown. */ #ifdef USE_DEBUG log_packet_stop (); #endif /* Remove FIFO and pid files. */ unlink (ui_fifo); unlink (pid_file); log_print ("isakmpd: exit"); exit (0); } }
/* Lookup an ISAKMP SA out of just the initiator cookie. */ struct sa * sa_lookup_from_icookie(u_int8_t *cookie) { return sa_find(sa_check_icookie, cookie); }
/* * Find a keyword and print regions. */ static void search_for_the_given_pattern(const SUFARY *ary, const char *key, const char *fname) { if (strlen(key) == 0) return; if (regex_mode || ignore_case_mode) { SA_RESULT_LIST *ll, *tmp; if (ignore_case_mode) tmp = sa_ignore_case(ary, 0, ary->arraysize - 1, key, strlen(key)); else tmp = sa_regex(ary, 0, ary->arraysize - 1, key, strlen(key)); size_of_rgnary = 0; if (count_only_mode) { for (ll = tmp; ll != NULL; ll = ll->next) size_of_rgnary++; if (fname != NULL) printf("%s:", fname); printf("%ld\n", (long)size_of_rgnary); return; } if (sort_mode) { int i = 0; for (ll = tmp; ll != NULL; ll = ll->next) size_of_rgnary++; rgnary = sa_malloc(sizeof(SA_INDEX) * size_of_rgnary); assert(rgnary != NULL && "too many results!"); for (ll = tmp; ll != NULL; ll = ll->next) rgnary[i++] = ll->value; } else { for (ll = tmp; ll != NULL; ll = ll->next) { long pos = ll->value; SA_STRING sstr; sstr = get_one_region(ary, pos); print_one_region(ary, sstr, pos, fname, ll->len); } } sa_free_result_list(tmp); } else { SUF_RESULT sr; sr = sa_find(ary, 0, ary->arraysize - 1, (char *)key, strlen(key), 0); if (sr.stat == SUCCESS) { SA_INDEX ai; if (count_only_mode) { if (fname != NULL) printf("%s:", fname); printf("%ld\n", (long)(sr.right - sr.left + 1)); return; } if (sort_mode) { size_of_rgnary = sr.right - sr.left + 1; rgnary = sa_malloc(sizeof(SA_INDEX) * size_of_rgnary); assert(rgnary != NULL && "too many results!"); for (ai = sr.left; ai <= sr.right; ai++) rgnary[ai - sr.left] = sa_aryidx2txtidx(ary, ai); } else { for (ai = sr.left; ai <= sr.right; ai++) { SA_INDEX pos = sa_aryidx2txtidx(ary, ai); SA_STRING sstr; sstr = get_one_region(ary, pos); print_one_region(ary, sstr, pos, fname, strlen(key)); } } } else { if (count_only_mode) { if (fname != NULL) printf("%s:", fname); printf("0\n"); return; } } } if (sort_mode && rgnary) { print_sorted_result(ary, fname); rgnary_idx = 0; sa_free(rgnary); } }