int arms_dump_state(arms_context_t *res, char *state, size_t size) { struct arms_dumped_state *newstate; MD5_CTX md5ctx; int i; /* check size */ if (size < arms_size_of_state()) return ARMS_ESIZE; newstate = CALLOC(1, sizeof(struct arms_dumped_state)); if (newstate == NULL) return ARMS_EFATAL; /* create new state array */ memset(newstate, 0, sizeof(*newstate)); newstate->state_version = ARMS_STATE_VERSION; DUMP(rs_endpoint); DUMP(rs_preshared_key); /* acmi (RS list) */ for (i = 0; i < 5; i++) { char *cert; acmi_get_url_idx(res->acmi, ACMI_CONFIG_CONFSOL, newstate->rsinfo[i].url, URL_MAX_LEN + 1, i); cert = acmi_get_cert_idx(res->acmi, ACMI_CONFIG_CONFSOL, i); if ((cert != NULL) && (strlen(cert) < sizeof(newstate->rsinfo[i].cert)) ) { strncpy(newstate->rsinfo[i].cert, cert, sizeof(newstate->rsinfo[i].cert)); } } newstate->current_server = acmi_get_current_server(res->acmi, ACMI_CONFIG_CONFSOL); newstate->retry_max = acmi_get_rmax(res->acmi, ACMI_CONFIG_CONFSOL); newstate->retry_int = acmi_get_rint(res->acmi, ACMI_CONFIG_CONFSOL); newstate->lltimeout = acmi_get_lltimeout(res->acmi, ACMI_CONFIG_CONFSOL); newstate->result = res->result; newstate->num_line = acmi_get_lines(res->acmi, ACMI_CONFIG_CONFSOL, newstate->line_defs); newstate->last_line = res->last_line; #if 0 /* compare with previus state array */ if (!memcmp(&newstate, state, sizeof(*newstate))) return ARMS_ENOCHANGE; #endif MD5_Init(&md5ctx); MD5_Update(&md5ctx, newstate, sizeof(*newstate) - sizeof(newstate->digest)); MD5_Final(newstate->digest, &md5ctx); /* copy new array to specified address */ memcpy(state, newstate, sizeof(*newstate)); FREE(newstate); return 0; }
static int rspull_judgement(tr_ctx_t *tr_ctx) { rspull_context_t *ctx = tr_ctx->arg; arms_context_t *res = arms_get_context(); char *desc; int rcode, err; /* Get result code */ err = axp_refer(ctx->parse, ARMS_TAG_RCODE, &rcode); if (err < 0) { libarms_log(ARMS_LOG_ERS_ACCESS_FAIL, NULL); return TR_WANT_RETRY; } err = axp_refer(ctx->parse, ARMS_TAG_RDESC, &desc); if (err < 0) { /* description is optional */ } else { if (desc) { } } /* * Check Result code from RS. */ tr_ctx->res_result = rcode; if (rcode >= 100 && rcode < 200) { /* 100 - 199 */ int i, a; const char *sa_cert = NULL; const char *sa_key = NULL; const char *ca_cert = NULL; axp_refer(ctx->parse, ARMS_TAG_SA_CERTIFICATE, &sa_cert); axp_refer(ctx->parse, ARMS_TAG_SA_PRIVATE_KEY, &sa_key); ca_cert = acmi_get_cert_idx(res->acmi, ACMI_CONFIG_CONFSOL, 0); if (sa_cert == NULL) { libarms_log(ARMS_LOG_ECERTIFICATE, "SA certificate is not received from RS"); memset(res->sa_cert, 0, ARMS_MAX_PEM_LEN); } else { strlcpy(res->sa_cert, sa_cert, ARMS_MAX_PEM_LEN); } if (sa_key == NULL) { libarms_log(ARMS_LOG_ECERTIFICATE, "SA private key is not received from RS"); memset(res->sa_key, 0, ARMS_MAX_PEM_LEN); } else { strlcpy(res->sa_key, sa_key, ARMS_MAX_PEM_LEN); } if (ca_cert == NULL) { /* * connected to RS, then call this function. * --> ca_cert != NULL. * this check is PARANOIA. */ libarms_log(ARMS_LOG_ECERTIFICATE, "RS CA certificate is not received from RS"); } if (arms_ssl_register_cert(sa_cert, sa_key) != 0) { libarms_log(ARMS_LOG_ECERTIFICATE, "Failed to register SA certificate and private key."); return TR_WANT_RETRY; } if (arms_ssl_register_cacert(ca_cert) != 0) { libarms_log(ARMS_LOG_ECERTIFICATE, "Failed to register RS CA certificate."); return TR_WANT_RETRY; } /* copy hbt_info to res */ res->num_of_hbt = ctx->num_of_hbt; for (i = 0; i < ctx->num_of_hbt; i++) { arms_hbt_info_t *dst = &res->hbt_info[i]; arms_hbt_info_t *hbp = &ctx->hbt_info[i]; /* at first, verity data. */ if (hbp->host == NULL || hbp->passphrase == NULL) { /* invalid. */ return TR_WANT_RETRY; } for (a = 0; a < hbp->numalg; a++) { if (hbp->algorithm[a] == NULL) { libarms_log(ARMS_LOG_EHB_NO_ALGORITHM, "Heartbeat info: no algorithm."); /* invalid. */ return TR_WANT_RETRY; } } /* and copy. */ dst->host = STRDUP(hbp->host); dst->port = hbp->port; dst->passphrase = STRDUP(hbp->passphrase); dst->interval = hbp->interval; dst->numalg = hbp->numalg; for (a = 0; a < hbp->numalg; a++) { dst->algorithm[a] = STRDUP(hbp->algorithm[a]); } } libarms_log(ARMS_LOG_IRS_ACCESS_END, NULL); return TR_READ_DONE; } libarms_log(ARMS_LOG_ERS_ACCESS_FAIL, NULL); return TR_WANT_RETRY; }