int main(int argc, char **argv) { for (int x=1; x<argc && fcnt<MAXF; x++) { if (strcmp(argv[x], "-a") == 0 || strcmp(argv[x], "--a") == 0) { append = true; } else if (strcmp(argv[x], "?") == 0 || strcmp(argv[x], "-?") == 0 || strcmp(argv[x], "--help") == 0) { fputs("tee.exe [-a] binary-files ...", stderr); return 1; } else { files[fcnt] = CreateFile(argv[x], GENERIC_WRITE, FILE_SHARE_READ, NULL, append ? OPEN_ALWAYS : CREATE_ALWAYS, 0, NULL); if (append && ISVALID(files[fcnt])) SetFilePointer(files[fcnt], 0, NULL, FILE_END); fcnt++; } } if (fcnt < MAXF) { files[fcnt] = GetStdHandle(STD_OUTPUT_HANDLE); fcnt++; } HANDLE hIn = GetStdHandle(STD_INPUT_HANDLE); DWORD cbRead = 0; while (ReadFile(hIn, buff, sizeof(buff), &cbRead, NULL)) { for (int i=0; i<fcnt; i++) { DWORD cbWritten = 0; if (ISVALID(files[i])) WriteFile(files[i], buff, cbRead, &cbWritten, NULL); } } for (int i=0; i<fcnt; i++) if (ISVALID(files[i])) CloseHandle(files[i]); return 0; }
static am_status_t set_header_in_request(am_request_t *rq, const char *key, const char *value) { request_rec *r = (request_rec *) (rq != NULL ? rq->ctx : NULL); if (r == NULL || !ISVALID(key)) return AM_EINVAL; /* remove all instances of the header first */ apr_table_unset(r->headers_in, key); if (ISVALID(value)) { apr_table_set(r->headers_in, key, value); } return AM_SUCCESS; }
static int mips_next_event(unsigned long delta, struct clock_event_device *evt) { unsigned long flags; unsigned int mtflags; unsigned long timestamp, reference, previous; unsigned long nextcomp = 0L; int vpe = current_cpu_data.vpe_id; int cpu = smp_processor_id(); local_irq_save(flags); mtflags = dmt(); /* * Maintain the per-TC virtual timer * and program the per-VPE shared Count register * as appropriate here... */ reference = (unsigned long)read_c0_count(); timestamp = MAKEVALID(reference + delta); /* * To really model the clock, we have to catch the case * where the current next-in-VPE timestamp is the old * timestamp for the calling CPE, but the new value is * in fact later. In that case, we have to do a full * scan and discover the new next-in-VPE CPU id and * timestamp. */ previous = smtc_nexttime[vpe][cpu]; if (cpu == smtc_nextinvpe[vpe] && ISVALID(previous) && IS_SOONER(previous, timestamp, reference)) { int i; int soonest = cpu; /* * Update timestamp array here, so that new * value gets considered along with those of * other virtual CPUs on the VPE. */ smtc_nexttime[vpe][cpu] = timestamp; for_each_online_cpu(i) { if (ISVALID(smtc_nexttime[vpe][i]) && IS_SOONER(smtc_nexttime[vpe][i], smtc_nexttime[vpe][soonest], reference)) { soonest = i; } } smtc_nextinvpe[vpe] = soonest; nextcomp = smtc_nexttime[vpe][soonest]; /* * Otherwise, we don't have to process the whole array rank, * we just have to see if the event horizon has gotten closer. */ } else {
static uint32_t nmi_get_tick(void) { uint32_t __time = 0; if(ISVALID(poem->os.gettick)) __time = poem->os.gettick(); return __time; }
static am_status_t set_request_body(am_request_t *rq) { const char *thisfunc = "set_request_body():"; request_rec *r = (request_rec *) (rq != NULL ? rq->ctx : NULL); am_status_t status = AM_EINVAL; if (r == NULL || rq == NULL) { return status; } apr_table_unset(r->notes, amagent_post_filter_name); if (ISVALID(rq->post_data) && rq->post_data_sz > 0) { size_t data_sz = rq->post_data_sz; char *encoded = base64_encode(rq->post_data, &data_sz); if (encoded != NULL) { apr_table_set(r->notes, amagent_post_filter_name, encoded); am_log_debug(rq->instance_id, "%s preserved %d bytes", thisfunc, rq->post_data_sz); /* restore the content length so that we have a * match with a re-played data in the agent filter */ r->clength = rq->post_data_sz; apr_table_set(r->headers_in, "Content-Length", apr_psprintf(r->pool, "%ld", rq->post_data_sz)); free(encoded); } } return AM_SUCCESS; }
static char get_method_num(request_rec *r, unsigned long instance_id) { const char *thisfunc = "get_method_num():"; char method_num = AM_REQUEST_UNKNOWN; const char *mthd = ap_method_name_of(r->pool, r->method_number); am_log_debug(instance_id, "%s method %s (%s, %d)", thisfunc, LOGEMPTY(r->method), LOGEMPTY(mthd), r->method_number); if (r->method_number == M_GET && r->header_only > 0) { method_num = AM_REQUEST_HEAD; } else { method_num = am_method_str_to_num(mthd); } am_log_debug(instance_id, "%s number corresponds to %s method", thisfunc, am_method_num_to_str(method_num)); /* check if method number and method string correspond */ if (method_num == AM_REQUEST_UNKNOWN) { /* if method string is not null, set the correct method number */ if (r->method != NULL && *(r->method) != '\0') { method_num = am_method_str_to_num(r->method); r->method_number = ap_method_number_of(r->method); am_log_debug(instance_id, "%s set method number to correspond to %s method (%d)", thisfunc, r->method, r->method_number); } } else if (ISVALID(r->method) && strcasecmp(r->method, am_method_num_to_str(method_num)) && (method_num != AM_REQUEST_INVALID)) { /* in case the method number and the method string do not match, * correct the method string. But if the method number is invalid * the method string needs to be preserved in case Apache is * used as a proxy (in front of Exchange Server for instance) */ r->method = am_method_num_to_str(method_num); am_log_debug(instance_id, "%s set method to %s", thisfunc, LOGEMPTY(r->method)); } return method_num; }
static int isvalid( const char *n ) { while(*n) { if(!ISVALID((int)(*n))) return 0; n++; } return 1; }
void am_config_free(am_config_t **cp) { if (cp != NULL && *cp != NULL) { am_config_t *c = *cp; if (ISVALID(c->pass) && c->pass_sz > 0) { am_secure_zero_memory(c->pass, c->pass_sz); } if (ISVALID(c->cert_key_pass) && c->cert_key_pass_sz > 0) { am_secure_zero_memory(c->cert_key_pass, c->cert_key_pass_sz); } AM_FREE(c->token, c->config, c->pdp_dir, c->realm, c->user, c->pass, c->key, c->debug_file, c->audit_file, c->cert_key_file, c->cert_key_pass, c->cert_file, c->cert_ca_file, c->ciphers, c->tls_opts, c->valid_default_url, c->agenturi, c->cookie_name, c->notif_url, c->userid_param, c->userid_param_type, c->access_denied_url, c->fqdn_default, c->pdp_lb_cookie, c->cookie_prefix, c->logout_redirect_url, c->password_replay_key, c->url_redirect_param, c->client_ip_header, c->client_hostname_header, c->url_check_regex, c->multi_attr_separator, c->pdp_sess_mode, c->pdp_sess_value, c->pdp_uri_prefix, c->logout_url_regex, c->audit_file_remote, c->audit_file_disposition, c->unauthenticated_user); AM_CONF_FREE(c->naming_url_sz, c->naming_url); AM_CONF_FREE(c->hostmap_sz, c->hostmap); AM_CONF_MAP_FREE(c->login_url_sz, c->login_url); AM_CONF_MAP_FREE(c->profile_attr_map_sz, c->profile_attr_map); AM_CONF_MAP_FREE(c->session_attr_map_sz, c->session_attr_map); AM_CONF_MAP_FREE(c->response_attr_map_sz, c->response_attr_map); AM_CONF_MAP_FREE(c->fqdn_map_sz, c->fqdn_map); AM_CONF_MAP_FREE(c->cookie_reset_map_sz, c->cookie_reset_map); AM_CONF_MAP_FREE(c->not_enforced_map_sz, c->not_enforced_map); AM_CONF_MAP_FREE(c->not_enforced_ext_map_sz, c->not_enforced_ext_map); AM_CONF_MAP_FREE(c->not_enforced_ip_map_sz, c->not_enforced_ip_map); AM_CONF_MAP_FREE(c->cdsso_login_map_sz, c->cdsso_login_map); AM_CONF_MAP_FREE(c->cdsso_cookie_domain_map_sz, c->cdsso_cookie_domain_map); AM_CONF_MAP_FREE(c->logout_cookie_reset_map_sz, c->logout_cookie_reset_map); AM_CONF_MAP_FREE(c->logout_map_sz, c->logout_map); AM_CONF_MAP_FREE(c->openam_logout_map_sz, c->openam_logout_map); AM_CONF_MAP_FREE(c->cond_login_url_sz, c->cond_login_url); AM_CONF_MAP_FREE(c->json_url_map_sz, c->json_url_map); free(c); c = NULL; } }
static am_status_t add_header_in_response(am_request_t *rq, const char *key, const char *value) { am_status_t status = AM_ERROR; request_rec *r = (request_rec *) (rq != NULL ? rq->ctx : NULL); if (r == NULL || !ISVALID(key)) return AM_EINVAL; if (!ISVALID(value)) { /*value is empty, sdk is setting a cookie in response*/ status = set_cookie(rq, key); } else { /* Apache HTTPD keeps two separate server response header tables in the request * record — one for normal response headers and one for error headers. * The difference between them is the error headers are sent to * the client even (not only) on an error response (REDIRECT is one of them) */ apr_table_add(r->err_headers_out, key, value); status = AM_SUCCESS; } return status; }
static void nmi_log(char *str) { #ifdef FEATURE_SKY_ISDBT ISDBT_MSG_SHARP_BB("%s", str); #else if(ISVALID(poem->prnt)) poem->prnt(str); #endif }
static am_status_t set_custom_response(am_request_t *rq, const char *text, const char *cont_type) { request_rec *r = (request_rec *) (rq != NULL ? rq->ctx : NULL); if (r == NULL || !ISVALID(text)) return AM_EINVAL; if (rq->status == AM_INTERNAL_REDIRECT) { ap_internal_redirect(text, r); rq->status = AM_DONE; } else if (rq->status == AM_REDIRECT) { apr_table_add(r->headers_out, "Location", text); ap_custom_response(r, HTTP_MOVED_TEMPORARILY, text); } else { if (rq->status == AM_PDP_DONE) { request_rec *sr = ap_sub_req_method_uri(am_method_num_to_str(rq->method), rq->post_data_url, r, NULL); sr->headers_in = r->headers_in; sr->notes = r->notes; am_log_debug(rq->instance_id, "set_custom_response(): issuing sub-request %s to %s", sr->method, rq->post_data_url); ap_run_sub_req(sr); ap_destroy_sub_req(sr); rq->status = AM_DONE; } else { size_t tl = strlen(text); if (ISVALID(cont_type)) { ap_set_content_type(r, cont_type); } ap_set_content_length(r, tl); ap_rwrite(text, (int) tl, r); ap_custom_response(r, am_status_value(rq->status == AM_SUCCESS || rq->status == AM_DONE ? AM_SUCCESS : rq->status), text); ap_rflush(r); } } am_log_info(rq->instance_id, "set_custom_response(): status: %s", am_strerror(rq->status)); return AM_SUCCESS; }
static am_status_t set_cookie(am_request_t *rq, const char *header) { request_rec *r = (request_rec *) (rq != NULL ? rq->ctx : NULL); const char *c; if (r == NULL || !ISVALID(header)) return AM_EINVAL; apr_table_add(r->err_headers_out, "Set-Cookie", header); c = apr_table_get(r->headers_in, "Cookie"); if (c == NULL) { apr_table_add(r->headers_in, "Cookie", header); } else { apr_table_set(r->headers_in, "Cookie", apr_pstrcat(r->pool, header, ";", c, NULL)); } return AM_SUCCESS; }
/* * turn a vms spec into a path */ static Node* vmsextendpath(Node *np, char *name) { np = extendpath(np, s_copy(name)); if(!ISVALID(np)){ np->d->qid.type = QTDIR; np->d->atime = time(0); np->d->mtime = np->d->atime; strcpy(np->d->uid, "who"); strcpy(np->d->gid, "cares"); np->d->mode = DMDIR|0777; np->d->length = 0; if(changedir(np) >= 0) VALID(np); } return np; }
static void character_data(void *userData, const char *val, int len) { char *tmp; am_xml_parser_ctx_t *ctx = (am_xml_parser_ctx_t *) userData; if (!ISVALID(ctx->current_name) || ctx->setting_value == 0 || len <= 0 || strncmp(val, "[]=", len) == 0 || strncmp(val, "[0]=", len) == 0) return; tmp = realloc(ctx->data, ctx->data_sz + len + 1); if (tmp == NULL) { am_free(ctx->data); ctx->data = NULL; ctx->data_sz = 0; ctx->status = AM_ENOMEM; return; } ctx->data = tmp; memcpy(ctx->data + ctx->data_sz, val, len); ctx->data_sz += len; ctx->data[ctx->data_sz] = 0; }
bool CREAMClient::getJobDesc(const std::string& jobid, std::string& desc) { logger.msg(VERBOSE, "Creating and sending a status request"); action = "JobInfo"; PayloadSOAP req(cream_ns); XMLNode xjobId = req.NewChild("types:" + action + "Request").NewChild("types:jobId"); xjobId.NewChild("types:id") = jobid; xjobId.NewChild("types:creamURL") = client->GetURL().str(); XMLNode response; if (!process(req, response)) return false; if (ISVALID(response["result"]["jobInfo"]["JDL"])) { desc = (std::string)response["result"]["jobInfo"]["JDL"]; return true; } return false; }
static Node* vmsdir(char *name) { char *cp; Node *np; char *oname; np = remroot; cp = strchr(name, '['); if(cp) strcpy(cp, cp+1); cp = strchr(name, ']'); if(cp) *cp = 0; oname = name = strdup(name); if(name == 0) return 0; while(cp = strchr(name, '.')){ *cp = 0; np = vmsextendpath(np, name); name = cp+1; } np = vmsextendpath(np, name); /* * walk back to first accessible directory */ for(; np->parent != np; np = np->parent) if(ISVALID(np)){ CACHED(np->parent); break; } free(oname); return np; }
bool GobangGame::checkForWin(int row, int col) { static int xoffset[] = { 1, 1, 0, -1, -1, -1, 0, 1 }; static int yoffset[] = { 0, 1, 1, 1, 0, -1, -1, -1 }; uint8 c = board[row][col]; int sum[4]; memset(sum, 0, sizeof(sum)); for (int k = 0; k < 8; k++) { int i = row + yoffset[k]; int j = col + xoffset[k]; while (ISVALID(i, j) && board[i][j] == c) { if (++sum[k & 3] >= 4) return true; i += yoffset[k]; j += xoffset[k]; } } return false; }
static void character_data(void *userData, const char *val, int len) { am_xml_parser_ctx_t *ctx = (am_xml_parser_ctx_t *) userData; if (!ISVALID(ctx->current_name) || ctx->setting_value == 0 || len <= 0 || strncmp(val, "[]=", len) == 0 || strncmp(val, "[0]=", len) == 0) return; /* bootstrap options */ PARSE_NUMBER(ctx, AM_AGENTS_CONFIG_LOCAL, ctx->conf->local, val, len); PARSE_STRING(ctx, AM_AGENTS_CONFIG_POSTDATA_PRESERVE_DIR, ctx->conf->pdp_dir, val, len); PARSE_STRING_LIST(ctx, AM_AGENTS_CONFIG_NAMING_URL, ctx->conf->naming_url_sz, ctx->conf->naming_url, val, len); PARSE_STRING(ctx, AM_AGENTS_CONFIG_REALM, ctx->conf->realm, val, len); PARSE_STRING(ctx, AM_AGENTS_CONFIG_USER, ctx->conf->user, val, len); PARSE_STRING(ctx, AM_AGENTS_CONFIG_PASSWORD, ctx->conf->pass, val, len); PARSE_STRING(ctx, AM_AGENTS_CONFIG_KEY, ctx->conf->key, val, len); PARSE_STRING(ctx, AM_AGENTS_CONFIG_DEBUG_FILE, ctx->conf->debug_file, val, len); PARSE_DEBUG_LOG_LEVEL(ctx, AM_AGENTS_CONFIG_DEBUG_LEVEL, ctx->conf->debug_level, val, len); PARSE_NUMBER(ctx, AM_AGENTS_CONFIG_DEBUG_OPT, ctx->conf->debug, val, len); PARSE_STRING(ctx, AM_AGENTS_CONFIG_AUDIT_FILE, ctx->conf->audit_file, val, len); PARSE_AUDIT_LOG_LEVEL(ctx, AM_AGENTS_CONFIG_AUDIT_LEVEL, ctx->conf->audit_level, val, len); PARSE_NUMBER(ctx, AM_AGENTS_CONFIG_AUDIT_OPT, ctx->conf->audit, val, len); PARSE_STRING(ctx, AM_AGENTS_CONFIG_CERT_KEY_FILE, ctx->conf->cert_key_file, val, len); PARSE_STRING(ctx, AM_AGENTS_CONFIG_CERT_KEY_PASSWORD, ctx->conf->cert_key_pass, val, len); PARSE_STRING(ctx, AM_AGENTS_CONFIG_CERT_FILE, ctx->conf->cert_file, val, len); PARSE_STRING(ctx, AM_AGENTS_CONFIG_CA_FILE, ctx->conf->cert_ca_file, val, len); PARSE_STRING(ctx, AM_AGENTS_CONFIG_CIPHERS, ctx->conf->ciphers, val, len); PARSE_NUMBER(ctx, AM_AGENTS_CONFIG_TRUST_CERT, ctx->conf->cert_trust, val, len); PARSE_STRING(ctx, AM_AGENTS_CONFIG_TLS_OPT, ctx->conf->tls_opts, val, len); PARSE_NUMBER(ctx, AM_AGENTS_CONFIG_NET_TIMEOUT, ctx->conf->net_timeout, val, len); PARSE_NUMBER(ctx, AM_AGENTS_CONFIG_URL_VALIDATE_LEVEL, ctx->conf->valid_level, val, len); PARSE_NUMBER(ctx, AM_AGENTS_CONFIG_URL_VALIDATE_PING_INTERVAL, ctx->conf->valid_ping, val, len); PARSE_NUMBER(ctx, AM_AGENTS_CONFIG_URL_VALIDATE_PING_MISS, ctx->conf->valid_ping_miss, val, len); PARSE_NUMBER(ctx, AM_AGENTS_CONFIG_URL_VALIDATE_PING_OK, ctx->conf->valid_ping_ok, val, len); PARSE_NUMBER_LIST(ctx, AM_AGENTS_CONFIG_URL_VALIDATE_DEFAULT_SET, ctx->conf->valid_default_url_sz, ctx->conf->valid_default_url, val, len); PARSE_STRING_LIST(ctx, AM_AGENTS_CONFIG_HOST_MAP, ctx->conf->hostmap_sz, ctx->conf->hostmap, val, len); PARSE_NUMBER(ctx, AM_AGENTS_CONFIG_RETRY_MAX, ctx->conf->retry_max, val, len); PARSE_NUMBER(ctx, AM_AGENTS_CONFIG_RETRY_WAIT, ctx->conf->retry_wait, val, len); /* other options */ if (strcmp(ctx->current_name, "com.sun.identity.agents.config.freeformproperties") == 0) { /*handler for old freeformproperties*/ char *t, k[AM_URI_SIZE]; char *v = strndup(val, len); if (v != NULL) { /* make up parser's current_name to handle freeformproperties: * instead of a property key being supplied as an <attribute name="...">, * it is sent as a part of <value> element, for example: * <value>com.forgerock.agents.conditional.login.url[0]=signin.example.com|http...</value> */ memset(&k[0], 0, sizeof (k)); if ((t = strchr(v, '[')) != NULL) { memcpy(k, v, t - v); } else if ((t = strchr(v, '=')) != NULL) { memcpy(k, v, t - v); trim(k, ' '); t++; /*move past the '='*/ } if (ISVALID(k) && t != NULL) { am_xml_parser_ctx_t f; size_t l = strlen(t); f.conf = ctx->conf; f.depth = ctx->depth; f.setting_value = ctx->setting_value; f.rgx = ctx->rgx; f.parser = ctx->parser; f.log_enable = ctx->log_enable; memcpy(f.current_name, k, sizeof (k)); parse_other_options(&f, t, (int) l); } free(v); } } else { parse_other_options(ctx, val, len); } }
static int send_policychange_request(am_net_t *conn, char **token, const char *notifyurl) { static const char *thisfunc = "send_policychange_request():"; size_t post_sz, post_data_sz; char *post = NULL, *post_data = NULL; int status = AM_ERROR; struct request_data *req_data; if (conn == NULL || conn->data == NULL || token == NULL || !ISVALID(*token)) return AM_EINVAL; req_data = (struct request_data *) conn->data; post_data_sz = am_asprintf(&post_data, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<RequestSet vers=\"1.0\" svcid=\"Policy\" reqid=\"1\">" "<Request><![CDATA[" "<PolicyService version=\"1.0\">" "<PolicyRequest requestId=\"1\" appSSOToken=\"%s\">" "<RemovePolicyListener notificationURL=\"%s\" serviceName=\"iPlanetAMWebAgentService\"/>" "</PolicyRequest>" "</PolicyService>]]>" "</Request>" "<Request><![CDATA[" "<PolicyService version=\"1.0\">" "<PolicyRequest requestId=\"2\" appSSOToken=\"%s\">" "<AddPolicyListener notificationURL=\"%s\" serviceName=\"iPlanetAMWebAgentService\"/>" "</PolicyRequest>" "</PolicyService>]]>" "</Request>" "</RequestSet>", *token, NOTNULL(notifyurl), *token, NOTNULL(notifyurl)); if (post_data == NULL) return AM_ENOMEM; post_sz = am_asprintf(&post, "POST %s/policyservice HTTP/1.1\r\n" "Host: %s:%d\r\n" "User-Agent: "MODINFO"\r\n" "Accept: text/xml\r\n" "Connection: Close\r\n" "Content-Type: text/xml; charset=UTF-8\r\n" "%s" "Content-Length: %d\r\n\r\n" "%s", conn->uv.path, conn->uv.host, conn->uv.port, NOTNULL(conn->req_headers), post_data_sz, post_data); if (post == NULL) { free(post_data); return AM_ENOMEM; } #ifdef DEBUG AM_LOG_DEBUG(conn->instance_id, "%s sending %d bytes:\n%s", thisfunc, post_sz, post); #else AM_LOG_DEBUG(conn->instance_id, "%s sending %d bytes", thisfunc, post_sz); #endif if (conn->log != NULL) { #ifdef DEBUG conn->log("%s sending %d bytes:\n%s", thisfunc, post_sz, post); #else conn->log("%s sending %d bytes", thisfunc, post_sz); #endif } status = am_net_write(conn, post, post_sz); free(post_data); free(post); if (status == AM_SUCCESS) { wait_for_event(req_data->event, 0); } AM_LOG_DEBUG(conn->instance_id, "%s authenticate response status code: %d\n%s", thisfunc, conn->http_status, LOGEMPTY(req_data->data)); if (conn->log != NULL) { conn->log("%s authenticate response status code: %d\n%s", thisfunc, conn->http_status, LOGEMPTY(req_data->data)); } AM_LOG_DEBUG(conn->instance_id, "%s status: %s", thisfunc, am_strerror(status)); am_free(req_data->data); req_data->data = NULL; return status; }
int am_agent_login(unsigned long instance_id, const char *openam, const char *notifyurl, const char *user, const char *pass, const char *realm, int is_local, int lb_enable, struct am_ssl_options *info, char **agent_token, char **pxml, size_t *pxsz, struct am_namevalue **session_list, void(*log)(const char *, ...)) { static const char *thisfunc = "am_agent_login():"; am_net_t conn; int status = AM_ERROR; struct request_data req_data; if (!ISVALID(realm) || !ISVALID(user) || !ISVALID(pass) || !ISVALID(openam)) { return AM_EINVAL; } memset(&req_data, 0, sizeof(struct request_data)); memset(&conn, 0, sizeof(am_net_t)); conn.log = log; conn.instance_id = instance_id; conn.timeout = AM_NET_CONNECT_TIMEOUT; conn.url = openam; if (info != NULL) { memcpy(&conn.ssl.info, info, sizeof(struct am_ssl_options)); } if (lb_enable) { conn.req_headers = strdup("Cookie: amlbcookie="); } req_data.event = create_event(); if (req_data.event == NULL) return AM_ENOMEM; conn.data = &req_data; conn.on_connected = on_connected_cb; conn.on_close = on_close_cb; conn.on_data = on_agent_request_data_cb; conn.on_complete = on_complete_cb; if (am_net_connect(&conn) == 0) { do { /* authenticate with agent profile/password and module Application (PLL endpoint) */ status = send_authcontext_request(&conn, realm, agent_token); if (status != AM_SUCCESS) break; status = send_login_request(&conn, agent_token, user, pass); if (status != AM_SUCCESS) break; if (!is_local) { /* send agent attribute request (/identity/xml/read REST endpoint); * no interest in a remote profile in case of a local-only configuration */ status = send_attribute_request(&conn, agent_token, pxml, pxsz, user, realm); if (status != AM_SUCCESS) break; } /* send session request (PLL endpoint) */ status = send_session_request(&conn, agent_token, notifyurl, session_list); if (status != AM_SUCCESS) break; /* subscribe to a policy change notification (PLL endpoint) */ status = send_policychange_request(&conn, agent_token, notifyurl); } while (0); if (status != AM_SUCCESS) { AM_LOG_DEBUG(instance_id, "%s disconnecting", thisfunc); if (log != NULL) { log("%s disconnecting", thisfunc); } am_net_diconnect(&conn); } } am_net_close(&conn); close_event(req_data.event); am_free(req_data.data); return status; }
int am_agent_logout(unsigned long instance_id, const char *openam, const char *token, const char *server_id, struct am_ssl_options *info, void(*log)(const char *, ...)) { static const char *thisfunc = "am_agent_logout():"; am_net_t conn; int status = AM_ERROR; size_t post_sz, post_data_sz; char *post = NULL, *post_data = NULL; struct request_data req_data; if (!ISVALID(token) || !ISVALID(openam)) return AM_EINVAL; memset(&req_data, 0, sizeof(struct request_data)); memset(&conn, 0, sizeof(am_net_t)); conn.log = log; conn.instance_id = instance_id; conn.timeout = AM_NET_CONNECT_TIMEOUT; conn.url = openam; if (info != NULL) { memcpy(&conn.ssl.info, info, sizeof(struct am_ssl_options)); } if (ISVALID(server_id)) { am_asprintf(&conn.req_headers, "Cookie: amlbcookie=%s\r\n", server_id); } req_data.event = create_event(); if (req_data.event == NULL) return AM_ENOMEM; conn.data = &req_data; conn.on_connected = on_connected_cb; conn.on_close = on_close_cb; conn.on_data = on_agent_request_data_cb; conn.on_complete = on_complete_cb; if (am_net_connect(&conn) == 0) { post_data_sz = am_asprintf(&post_data, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<RequestSet vers=\"1.0\" svcid=\"auth\" reqid=\"0\">" "<Request><![CDATA[" "<?xml version=\"1.0\" encoding=\"UTF-8\"?><AuthContext version=\"1.0\">" "<Request authIdentifier=\"%s\">" "<Logout/></Request></AuthContext>]]>" "</Request></RequestSet>", token); if (post_data != NULL) { post_sz = am_asprintf(&post, "POST %s/authservice HTTP/1.1\r\n" "Host: %s:%d\r\n" "User-Agent: "MODINFO"\r\n" "Accept: text/xml\r\n" "Connection: Close\r\n" "Content-Type: text/xml; charset=UTF-8\r\n" "%s" "Content-Length: %d\r\n\r\n" "%s", conn.uv.path, conn.uv.host, conn.uv.port, NOTNULL(conn.req_headers), post_data_sz, post_data); if (post != NULL) { AM_LOG_DEBUG(instance_id, "%s sending request:\n%s", thisfunc, post); if (log != NULL) { log("%s sending request:\n%s", thisfunc, post); } status = am_net_write(&conn, post, post_sz); free(post); } free(post_data); } } if (status == AM_SUCCESS) { wait_for_event(req_data.event, 0); } else { AM_LOG_DEBUG(instance_id, "%s disconnecting", thisfunc); if (log != NULL) { log("%s disconnecting", thisfunc); } am_net_diconnect(&conn); } AM_LOG_DEBUG(instance_id, "%s response status code: %d", thisfunc, conn.http_status); if (log != NULL) { log("%s response status code: %d", thisfunc, conn.http_status); } am_net_close(&conn); close_event(req_data.event); am_free(req_data.data); return status; }
static int send_authcontext_request(am_net_t *conn, const char *realm, char **token) { static const char *thisfunc = "send_authcontext_request():"; size_t post_sz, post_data_sz; char *post = NULL, *post_data = NULL; int status = AM_ERROR; struct request_data *req_data; if (conn == NULL || conn->data == NULL || token == NULL || !ISVALID(realm)) return AM_EINVAL; req_data = (struct request_data *) conn->data; post_data_sz = am_asprintf(&post_data, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<RequestSet vers=\"1.0\" svcid=\"auth\" reqid=\"0\">" "<Request><![CDATA[" "<?xml version=\"1.0\" encoding=\"UTF-8\"?><AuthContext version=\"1.0\">" "<Request authIdentifier=\"0\">" "<NewAuthContext orgName=\"%s\"/></Request></AuthContext>]]>" "</Request></RequestSet>", realm); if (post_data == NULL) return AM_ENOMEM; post_sz = am_asprintf(&post, "POST %s/authservice HTTP/1.1\r\n" "Host: %s:%d\r\n" "User-Agent: "MODINFO"\r\n" "Accept: text/xml\r\n" "Connection: Keep-Alive\r\n" "Content-Type: text/xml; charset=UTF-8\r\n" "Content-Length: %d\r\n\r\n" "%s", conn->uv.path, conn->uv.host, conn->uv.port, post_data_sz, post_data); if (post == NULL) { free(post_data); return AM_ENOMEM; } #ifdef DEBUG AM_LOG_DEBUG(conn->instance_id, "%s sending %d bytes:\n%s", thisfunc, post_sz, post); #else AM_LOG_DEBUG(conn->instance_id, "%s sending %d bytes", thisfunc, post_sz); #endif if (conn->log != NULL) { #ifdef DEBUG conn->log("%s sending %d bytes:\n%s", thisfunc, post_sz, post); #else conn->log("%s sending %d bytes", thisfunc, post_sz); #endif } status = am_net_write(conn, post, post_sz); free(post_data); free(post); if (status == AM_SUCCESS) { wait_for_event(req_data->event, 0); } AM_LOG_DEBUG(conn->instance_id, "%s response status code: %d\n%s", thisfunc, conn->http_status, LOGEMPTY(req_data->data)); if (conn->log != NULL) { conn->log("%s response status code: %d\n%s", thisfunc, conn->http_status, LOGEMPTY(req_data->data)); } if (status == AM_SUCCESS && conn->http_status == 200 && ISVALID(req_data->data)) { char *begin = strstr(req_data->data, "Response authIdentifier=\""); if (begin != NULL) { char *end = strstr(begin + 25, "\""); if (end != NULL) { *token = strndup(begin + 25, end - begin - 25); } } if (ISINVALID(*token)) { status = AM_NOT_FOUND; } if (status == AM_SUCCESS && ISVALID(conn->req_headers)) { am_request_t req_temp; int decode_status; memset(&req_temp, 0, sizeof(am_request_t)); req_temp.token = strdup(*token); decode_status = am_session_decode(&req_temp); if (decode_status == AM_SUCCESS && req_temp.session_info.error == AM_SUCCESS) { if (ISVALID(req_temp.session_info.si)) { am_asprintf(&conn->req_headers, "%s%s\r\n", conn->req_headers, req_temp.session_info.si); } else { am_free(conn->req_headers); conn->req_headers = NULL; } AM_LOG_DEBUG(conn->instance_id, "%s app token SI: %s, S1: %s", thisfunc, LOGEMPTY(req_temp.session_info.si), LOGEMPTY(req_temp.session_info.s1)); } am_request_free(&req_temp); } } AM_LOG_DEBUG(conn->instance_id, "%s status: %s", thisfunc, am_strerror(status)); am_free(req_data->data); req_data->data = NULL; return status; }
int am_agent_naming_request(unsigned long instance_id, const char *openam, const char *token) { char *post = NULL, *post_data = NULL; am_net_t n; size_t post_sz; int status = AM_ERROR; struct request_data ld; if (!ISVALID(token) || !ISVALID(openam)) return AM_EINVAL; memset(&ld, 0, sizeof(struct request_data)); memset(&n, 0, sizeof(am_net_t)); n.instance_id = instance_id; n.timeout = AM_NET_CONNECT_TIMEOUT; n.url = openam; ld.event = create_event(); if (ld.event == NULL) return AM_ENOMEM; n.data = &ld; n.on_connected = on_connected_cb; n.on_close = on_close_cb; n.on_data = on_agent_request_data_cb; n.on_complete = on_complete_cb; if (am_net_connect(&n) == 0) { size_t post_data_sz = am_asprintf(&post_data, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<RequestSet vers=\"1.0\" svcid=\"com.iplanet.am.naming\" reqid=\"0\">" "<Request><![CDATA[" "<NamingRequest vers=\"3.0\" reqid=\"1\" sessid=\"%s\">" "<GetNamingProfile>" "</GetNamingProfile>" "</NamingRequest>]]>" "</Request>" "</RequestSet>", token); if (post_data != NULL) { post_sz = am_asprintf(&post, "POST %s/namingservice HTTP/1.1\r\n" "Host: %s:%d\r\n" "User-Agent: "MODINFO"\r\n" "Accept: text/xml\r\n" "Connection: close\r\n" "Content-Type: text/xml; charset=UTF-8\r\n" "Content-Length: %d\r\n\r\n" "%s", n.uv.path, n.uv.host, n.uv.port, post_data_sz, post_data); if (post != NULL) { status = am_net_write(&n, post, post_sz); free(post); post = NULL; } free(post_data); post_data = NULL; } } if (status == AM_SUCCESS) { wait_for_event(ld.event, 0); } else { am_net_diconnect(&n); } am_net_close(&n); close_event(ld.event); am_free(ld.data); return status; }
static void env_init(void) #endif /* CFG_FLASH_ENV_ADDR */ { #ifdef CONFIG_NVRAM_ENV if (crc32(0, (char *)environment, env_size) != *(ulong *)CFG_NVRAM_VAR_CRC_ADDR) { int i; #if 0 /* still some problems with this printf - don't know why */ printf ("*** Warning - Environment CRC mismatch, using defaults\n\n"); #endif for (i=0; i<env_size; i++) environment[i] = 0x00; memcpy (environment, default_environment, sizeof(default_environment)); *(ulong *)CFG_NVRAM_VAR_CRC_ADDR = crc32(0, (char *)environment, env_size); } #else /* ! CONFIG_NVRAM_ENV */ #if defined(CFG_FLASH_ENV_ADDR) /* * check if monitor has been relocated yet */ if (environment == rom_addr) { /* * the monitor is still running from ROM. if the flash copy * is valid, use that, otherwise use the default environment * * NOTE: can't printf here, because getenv() is called from * serial_init() (and maybe before that) - hence the serial * port is not ready - we can yell later that we are using * the default environment... see below. */ if (ISVALID(flash_addr)) return (flash_addr); else return (default_environment); } /* * the monitor has been relocated - environment will now * refer to the "in-memory" copy. If it isn't valid, copy it * from the flash, or the default environment, if that isn't * valid either. */ if (!ISVALID(environment)) { /* * "in-memory" copy must be initialised */ if (!ISVALID(flash_addr)) { /* flash isn't valid either - use default */ printf ("\n*** Warning - no Environment," " using defaults\n\n"); memcpy(environment, default_environment, sizeof (default_environment)); MAKEVALID(environment, env_size); } else /* copy flash environment into RAM */ memcpy(environment, flash_addr, env_size); } return (environment); #else /* !CFG_FLASH_ENV_ADDR */ if (environment[0] == 0xFF) { printf ("*** Warning - no Environment, using defaults\n\n"); memcpy (environment, default_environment, sizeof(default_environment)); } #endif /* CFG_FLASH_ENV_ADDR */ #endif /* CONFIG_NVRAM_ENV */ }
int am_agent_session_request(unsigned long instance_id, const char *openam, const char *token, const char *user_token, const char *notif_url) { char *post = NULL, *post_data = NULL; am_net_t n; size_t post_sz; int status = AM_ERROR; struct request_data ld; if (!ISVALID(token) || !ISVALID(user_token) || !ISVALID(openam) || !ISVALID(notif_url)) return AM_EINVAL; memset(&ld, 0, sizeof(struct request_data)); memset(&n, 0, sizeof(am_net_t)); n.instance_id = instance_id; n.timeout = AM_NET_CONNECT_TIMEOUT; n.url = openam; ld.event = create_event(); if (ld.event == NULL) return AM_ENOMEM; n.data = &ld; n.on_connected = on_connected_cb; n.on_close = on_close_cb; n.on_data = on_agent_request_data_cb; n.on_complete = on_complete_cb; if (am_net_connect(&n) == 0) { char *token_in = NULL; size_t token_sz = am_asprintf(&token_in, "token:%s", token); char *token_b64 = base64_encode(token_in, &token_sz); size_t post_data_sz = am_asprintf(&post_data, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<RequestSet vers=\"1.0\" svcid=\"Session\" reqid=\"0\">" "<Request><![CDATA[" "<SessionRequest vers=\"1.0\" reqid=\"1\" requester=\"%s\">" "<GetSession reset=\"true\">" "<SessionID>%s</SessionID>" "</GetSession>" "</SessionRequest>]]>" "</Request>" "<Request><![CDATA[" "<SessionRequest vers=\"1.0\" reqid=\"2\" requester=\"%s\">" "<AddSessionListener>" "<URL>%s</URL>" "<SessionID>%s</SessionID>" "</AddSessionListener>" "</SessionRequest>]]>" "</Request>" "</RequestSet>", NOTNULL(token_b64), user_token, NOTNULL(token_b64), notif_url, user_token); AM_FREE(token_in, token_b64); if (post_data != NULL) { post_sz = am_asprintf(&post, "POST %s/sessionservice HTTP/1.1\r\n" "Host: %s:%d\r\n" "User-Agent: "MODINFO"\r\n" "Accept: text/xml\r\n" "Connection: close\r\n" "Content-Type: text/xml; charset=UTF-8\r\n" "Content-Length: %d\r\n\r\n" "%s", n.uv.path, n.uv.host, n.uv.port, post_data_sz, post_data); if (post != NULL) { status = am_net_write(&n, post, post_sz); free(post); post = NULL; } free(post_data); post_data = NULL; } } if (status == AM_SUCCESS) { wait_for_event(ld.event, 0); } else { am_net_diconnect(&n); } am_net_close(&n); close_event(ld.event); am_free(ld.data); return status; }
char * variable_subst( char *value, int line ) { char *subvalue, *newvalue; char *dollar, *start, *end; char terminator, oldend; int length; int withquotes = 0; int escape = 0; while(1) { /* Find a non-escaped dollar */ for( dollar=value; *dollar; dollar++ ) { if(escape) { escape = 0; } else { if(*dollar=='\\') { escape = 1; } else if(*dollar=='$') { break; } } } /* If we didn't find it, stop. */ if(!*dollar) return value; /* Is the variable name bracketed? */ if( *(dollar+1)=='{' ) { start = dollar+2; terminator = '}'; } else if( *(dollar+1)=='(' ) { start = dollar+2; terminator = ')'; } else { start = dollar+1; terminator = 0; } if(terminator) { end = strchr(start,terminator); } else { for(end=start;ISVALID(*end);end++) { /* nothing */ } } if(terminator && !end) { ftsh_error(FTSH_ERROR_FAILURE,line,"variable reference began with %c but didn't end",*(dollar+1)); return 0; } if((end-start)<1) { ftsh_error(FTSH_ERROR_FAILURE,line,"empty variable reference"); return 0; } withquotes = (dollar>value && *(dollar-1)=='\"') && (*end) && (terminator ? *(end+1)=='\"' : *end=='\"' ); oldend = *end; *end = 0; subvalue = variable_get(start,line,withquotes); *end = oldend; if(!subvalue) { subvalue = xxstrdup(""); } length = strlen(value) - (end-dollar) + strlen(subvalue) + 1; newvalue = malloc(length); if(!newvalue) { free(subvalue); free(value); return 0; } *dollar = 0; strcpy(newvalue,value); strcat(newvalue,subvalue); if(terminator && *end) { strcat(newvalue,end+1); } else { strcat(newvalue,end); } free(subvalue); free(value); value = newvalue; } }
int am_agent_policy_request(unsigned long instance_id, const char *openam, const char *token, const char *user_token, const char *req_url, const char *notif_url, const char *scope, const char *cip, const char *pattr, const char *server_id, struct am_ssl_options *info, struct am_namevalue **session_list, struct am_policy_result **policy_list) { static const char *thisfunc = "am_agent_policy_request():"; char *post = NULL, *post_data = NULL; am_net_t n; size_t post_sz; int status = AM_ERROR; int session_status = AM_SUCCESS; struct request_data req_data; if (!ISVALID(token) || !ISVALID(user_token) || !ISVALID(notif_url) || !ISVALID(scope) || !ISVALID(req_url) || !ISVALID(openam) || !ISVALID(cip)) { return AM_EINVAL; } memset(&req_data, 0, sizeof(struct request_data)); memset(&n, 0, sizeof(am_net_t)); n.instance_id = instance_id; n.timeout = AM_NET_CONNECT_TIMEOUT; n.url = openam; if (info != NULL) { memcpy(&n.ssl.info, info, sizeof(struct am_ssl_options)); } if (ISVALID(server_id)) { am_asprintf(&n.req_headers, "Cookie: amlbcookie=%s\r\n", server_id); } req_data.event = create_event(); if (req_data.event == NULL) { return AM_ENOMEM; } n.data = &req_data; n.on_connected = on_connected_cb; n.on_close = on_close_cb; n.on_data = on_agent_request_data_cb; n.on_complete = on_complete_cb; if (am_net_connect(&n) == 0) { char *token_in = NULL; size_t token_sz = am_asprintf(&token_in, "token:%s", token); char *token_b64 = base64_encode(token_in, &token_sz); size_t post_data_sz = am_asprintf(&post_data, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<RequestSet vers=\"1.0\" svcid=\"Session\" reqid=\"0\">" "<Request><![CDATA[" "<SessionRequest vers=\"1.0\" reqid=\"1\" requester=\"%s\">" "<GetSession reset=\"true\">" /* reset the idle timeout */ "<SessionID>%s</SessionID>" "</GetSession>" "</SessionRequest>]]>" "</Request>" "<Request><![CDATA[" "<SessionRequest vers=\"1.0\" reqid=\"2\" requester=\"%s\">" "<AddSessionListener>" "<URL>%s</URL>" "<SessionID>%s</SessionID>" "</AddSessionListener>" "</SessionRequest>]]>" "</Request>" "</RequestSet>", NOTNULL(token_b64), user_token, NOTNULL(token_b64), notif_url, user_token); AM_FREE(token_in, token_b64); if (post_data != NULL) { post_sz = am_asprintf(&post, "POST %s/sessionservice HTTP/1.1\r\n" "Host: %s:%d\r\n" "User-Agent: "MODINFO"\r\n" "Accept: text/xml\r\n" "Connection: Keep-Alive\r\n" "Content-Type: text/xml; charset=UTF-8\r\n" "%s" "Content-Length: %d\r\n\r\n" "%s", n.uv.path, n.uv.host, n.uv.port, NOTNULL(n.req_headers), post_data_sz, post_data); if (post != NULL) { AM_LOG_DEBUG(instance_id, "%s sending request:\n%s", thisfunc, post); status = am_net_write(&n, post, post_sz); free(post); post = NULL; } free(post_data); post_data = NULL; } if (status == AM_SUCCESS) { wait_for_event(req_data.event, 0); } AM_LOG_DEBUG(instance_id, "%s response status code: %d", thisfunc, n.http_status); if (status == AM_SUCCESS && n.http_status == 200 && ISVALID(req_data.data)) { size_t req_url_sz = strlen(req_url); char *req_url_escaped = malloc(req_url_sz * 6 + 1); /* worst case */ if (req_url_escaped != NULL) { memcpy(req_url_escaped, req_url, req_url_sz); xml_entity_escape(req_url_escaped, req_url_sz); } AM_LOG_DEBUG(instance_id, "%s response:\n%s", thisfunc, req_data.data); if (strstr(req_data.data, "<Exception>") != NULL && strstr(req_data.data, "Invalid session ID") != NULL) { session_status = AM_INVALID_SESSION; } if (strstr(req_data.data, "<Exception>") != NULL && strstr(req_data.data, "Application token passed in") != NULL) { session_status = AM_INVALID_AGENT_SESSION; } if (session_status == AM_SUCCESS && session_list != NULL) { *session_list = am_parse_session_xml(instance_id, req_data.data, req_data.data_size); } req_data.data_size = 0; free(req_data.data); req_data.data = NULL; /* TODO: * <AttributeValuePair><Attribute name=\"requestDnsName\"/><Value>%s</Value></AttributeValuePair> */ post_data_sz = am_asprintf(&post_data, "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" "<RequestSet vers=\"1.0\" svcid=\"Policy\" reqid=\"3\">" "<Request><![CDATA[<PolicyService version=\"1.0\">" "<PolicyRequest requestId=\"4\" appSSOToken=\"%s\">" "<GetResourceResults userSSOToken=\"%s\" serviceName=\"iPlanetAMWebAgentService\" resourceName=\"%s\" resourceScope=\"%s\">" "<EnvParameters><AttributeValuePair><Attribute name=\"requestIp\"/><Value>%s</Value></AttributeValuePair></EnvParameters>" "<GetResponseDecisions>" "%s" "</GetResponseDecisions>" "</GetResourceResults>" "</PolicyRequest>" "</PolicyService>]]>" "</Request>" "</RequestSet>", token, user_token, NOTNULL(req_url_escaped), scope, cip, NOTNULL(pattr)); am_free(req_url_escaped); post_sz = am_asprintf(&post, "POST %s/policyservice HTTP/1.1\r\n" "Host: %s:%d\r\n" "User-Agent: "MODINFO"\r\n" "Accept: text/xml\r\n" "Content-Type: text/xml; charset=UTF-8\r\n" "Content-Length: %d\r\n" "%s" "Connection: close\r\n\r\n" "%s", n.uv.path, n.uv.host, n.uv.port, post_data_sz, NOTNULL(n.req_headers), post_data); if (post != NULL) { AM_LOG_DEBUG(instance_id, "%s sending request:\n%s", thisfunc, post); status = am_net_write(&n, post, post_sz); free(post); } } else { status = n.error != AM_SUCCESS ? n.error : AM_ERROR; } } if (status == AM_SUCCESS) { wait_for_event(req_data.event, 0); } else { AM_LOG_DEBUG(instance_id, "%s disconnecting", thisfunc); am_net_diconnect(&n); } AM_LOG_DEBUG(instance_id, "%s response status code: %d", thisfunc, n.http_status); if (status == AM_SUCCESS && n.http_status == 200 && ISVALID(req_data.data)) { AM_LOG_DEBUG(instance_id, "%s response:\n%s", thisfunc, req_data.data); if (strstr(req_data.data, "<Exception>") != NULL) { if (strstr(req_data.data, "SSO token is invalid") != NULL) { session_status = AM_INVALID_SESSION; } else if (strstr(req_data.data, "Application sso token is invalid") != NULL) { session_status = AM_INVALID_AGENT_SESSION; } } if (session_status == AM_SUCCESS && policy_list != NULL) { *policy_list = am_parse_policy_xml(instance_id, req_data.data, req_data.data_size, am_scope_to_num(scope)); } } am_net_close(&n); close_event(req_data.event); am_free(req_data.data); return session_status != AM_SUCCESS ? session_status : status; }
bool CREAMClient::stat(const std::string& jobid, Job& job) { logger.msg(VERBOSE, "Creating and sending a status request"); action = "JobInfo"; PayloadSOAP req(cream_ns); XMLNode xjobId = req.NewChild("types:" + action + "Request").NewChild("types:jobId"); xjobId.NewChild("types:id") = jobid; xjobId.NewChild("types:creamURL") = client->GetURL().str(); XMLNode response; if (!process(req, response)) return false; XMLNode jobInfoNode; jobInfoNode = response["result"]["jobInfo"]; XMLNode lastStatusNode = jobInfoNode.Path("status").back(); if (lastStatusNode["name"]) { job.State = JobStateCREAM((std::string)lastStatusNode["name"]); } if (lastStatusNode["failureReason"]) { job.Error.push_back((std::string)lastStatusNode["failureReason"]); } if (!job.State) { logger.msg(VERBOSE, "Unable to retrieve job status."); return false; } if (ISVALID(jobInfoNode["jobId"]["id"])) { job.IDFromEndpoint = (std::string)jobInfoNode["jobId"]["id"]; } if (ISVALID(jobInfoNode["type"])) job.Type = (std::string)jobInfoNode["type"]; if (ISVALID(jobInfoNode["JDL"])) { job.JobDescription = "egee:jdl"; job.JobDescriptionDocument = (std::string)jobInfoNode["JDL"]; std::list<JobDescription> jds; if (JobDescription::Parse(job.JobDescriptionDocument, jds) && !jds.empty()) { if (!jds.front().Application.Input.empty()) job.StdIn = jds.front().Application.Input; if (!jds.front().Application.Output.empty()) job.StdOut = jds.front().Application.Output; if (!jds.front().Application.Error.empty()) job.StdErr = jds.front().Application.Error; if (!jds.front().Resources.QueueName.empty()) { job.Queue = jds.front().Resources.QueueName; } } } if (ISVALID(lastStatusNode["exitCode"])) job.ExitCode = stringtoi((std::string)lastStatusNode["exitCode"]); if (ISVALID(jobInfoNode["delegationProxyInfo"])) { /* Format of delegationProxyInfo node. [ isRFC="<true|false>"; valid from="<mon>/<date>/<yy> <hour>:<min> <AM|PM> (<timezone>)"; valid to="<mon>/<date>/<yy> <hour>:<min> <AM|PM> (<timezone>)"; holder DN="<DN>"; holder AC issuer="<DN>"; VO="<VO-name>"; AC issuer="<DN>"; VOMS attributes=<VOMS-Attributes> ] */ std::string delegationProxy = (std::string)jobInfoNode["delegationProxyInfo"]; std::size_t lBracketPos = delegationProxy.find('['), rBracketPos = delegationProxy.rfind(']'); if (lBracketPos != std::string::npos && rBracketPos != std::string::npos) { delegationProxy = trim(delegationProxy.substr(lBracketPos, rBracketPos - lBracketPos)); } std::list<std::string> tDelegInfo; tokenize(delegationProxy, tDelegInfo, ";"); for (std::list<std::string>::iterator it = tDelegInfo.begin(); it != tDelegInfo.end(); ++it) { std::list<std::string> keyValuePair; tokenize(*it, keyValuePair, "=", "\"", "\""); if (keyValuePair.size() != 2) continue; if (lower(trim(keyValuePair.front())) == "holder dn") job.Owner = trim(keyValuePair.back(), " \""); if (lower(trim(keyValuePair.front())) == "valid to") stringtoTime(trim(keyValuePair.back(), " \""), job.ProxyExpirationTime); } } if (ISVALID(jobInfoNode["localUser"])) job.LocalOwner = (std::string)jobInfoNode["localUser"]; if (ISVALID(jobInfoNode["lastCommand"])) { int job_register_id_first = -1; int job_register_id_last = -1; int job_start_id_first = -1; int job_start_id_last = -1; int local_id = 0; while (true) { if (!jobInfoNode["lastCommand"][local_id]) break; if ((std::string)jobInfoNode["lastCommand"][local_id]["name"] == "JOB_REGISTER") { if (job_register_id_first == -1 && job_register_id_last == -1) { job_register_id_first = local_id; job_register_id_last = local_id; } else if (job_register_id_last > -1) job_register_id_last = local_id; } //end of the JOB_REGISTER if ((std::string)jobInfoNode["lastCommand"][local_id]["name"] == "JOB_START") { if (job_start_id_first == -1 && job_start_id_last == -1) { job_start_id_first = local_id; job_start_id_last = local_id; } else if (job_start_id_last > -1) job_start_id_last = local_id; } //end of the JOB_START local_id++; } //dependent on JOB_REGISTER if (job_register_id_first > -1) if (ISVALID(jobInfoNode["lastCommand"][job_register_id_first]["creationTime"])) { Time time((std::string)jobInfoNode["lastCommand"][job_register_id_first]["creationTime"]); if (time.GetTime() != -1) job.SubmissionTime = time; } if (job_register_id_last > -1) if (ISVALID(jobInfoNode["lastCommand"][job_register_id_last]["creationTime"])) { Time time((std::string)jobInfoNode["lastCommand"][job_register_id_last]["creationTime"]); if (time.GetTime() != -1) job.CreationTime = time; } //end of the JOB_REGISTER //dependent on JOB_START if (job_start_id_first > -1) { if (ISVALID(jobInfoNode["lastCommand"][job_start_id_first]["startSchedulingTime"])) { Time time((std::string)jobInfoNode["lastCommand"][job_start_id_first]["startSchedulingTime"]); if (time.GetTime() != -1) job.ComputingManagerSubmissionTime = time; } if (ISVALID(jobInfoNode["lastCommand"][job_start_id_first]["startProcessingTime"])) { Time time((std::string)jobInfoNode["lastCommand"][job_start_id_first]["startProcessingTime"]); if (time.GetTime() != -1) job.StartTime = time; } } if (job_start_id_last > -1) if (ISVALID(jobInfoNode["lastCommand"][job_start_id_last]["executionCompletedTime"])) { Time time((std::string)jobInfoNode["lastCommand"][job_start_id_last]["executionCompletedTime"]); if (time.GetTime() != -1) job.ComputingManagerEndTime = time; } //end of the JOB_START } //end of the LastCommand if (ISVALID(lastStatusNode["timestamp"]) && (job.State() == "DONE-OK" || job.State() == "DONE-FAILED")) { Time time((std::string)lastStatusNode["timestamp"]); if (time.GetTime() != -1) job.EndTime = time; } return true; }
static int amagent_auth_handler(request_rec *r) { const char *thisfunc = "amagent_auth_handler():"; int rv; am_request_t d; am_config_t *boot = NULL; amagent_config_t *c = ap_get_module_config(r->server->module_config, &amagent_module); if (c == NULL || !c->enabled || c->error != AM_SUCCESS) { /* amagent module is not enabled for this * server/virtualhost - we are not handling this request **/ return DECLINED; } if (c->error != AM_SUCCESS) { LOG_R(APLOG_ERR, r, "%s is not configured to handle the request " "to %s (unable to load bootstrap configuration from %s, error: %s)", DESCRIPTION, r->uri, c->config, am_strerror(c->error)); return HTTP_FORBIDDEN; } LOG_R(APLOG_DEBUG, r, "amagent_auth_handler(): [%s] [%ld]", c->config, c->config_id); /* register and update instance logger configuration (for already registered * instances - update logging level only */ am_log_register_instance(c->config_id, c->debug_file, c->debug_level, c->audit_file, c->audit_level); am_log_debug(c->config_id, "%s begin", thisfunc); /* fetch agent configuration instance (from cache if available) */ rv = am_get_agent_config(c->config_id, c->config, &boot); if (boot == NULL || rv != AM_SUCCESS) { LOG_R(APLOG_ERR, r, "%s is not configured to handle the request " "to %s (unable to get agent configuration instance, configuration: %s, error: %s)", DESCRIPTION, r->uri, c->config, am_strerror(rv)); am_log_error(c->config_id, "amagent_auth_handler(): failed to get agent configuration instance, error: %s", am_strerror(rv)); return HTTP_FORBIDDEN; } /* set up request processor data structure */ memset(&d, 0, sizeof (am_request_t)); d.conf = boot; d.status = AM_ERROR; d.instance_id = c->config_id; d.ctx = r; d.method = get_method_num(r, c->config_id); d.content_type = apr_table_get(r->headers_in, "Content-Type"); d.cookies = apr_table_get(r->headers_in, "Cookie"); if (ISVALID(d.conf->client_ip_header)) { d.client_ip = (char *) apr_table_get(r->headers_in, d.conf->client_ip_header); } if (!ISVALID(d.client_ip)) { #ifdef APACHE24 d.client_ip = (char *) r->connection->client_ip; #else d.client_ip = (char *) r->connection->remote_ip; #endif } if (ISVALID(d.conf->client_hostname_header)) { d.client_host = (char *) apr_table_get(r->headers_in, d.conf->client_hostname_header); } d.am_get_request_url_f = get_request_url; d.am_get_post_data_f = get_request_body; d.am_set_post_data_f = set_request_body; d.am_set_user_f = set_user; d.am_set_header_in_request_f = set_header_in_request; d.am_add_header_in_response_f = add_header_in_response; d.am_set_cookie_f = set_cookie; d.am_set_custom_response_f = set_custom_response; d.am_set_method_f = set_method; am_process_request(&d); rv = am_status_value(d.status); am_log_debug(c->config_id, "amagent_auth_handler(): exit status: %s (%d)", am_strerror(d.status), d.status); am_config_free(&d.conf); am_request_free(&d); LOG_R(APLOG_DEBUG, r, "amagent_auth_handler(): return status: %d", rv); return rv; }
static void *parse_value(const char *line, const char *name, int value_type, const char *mvsep) { char set = 0, map = 0, *token = NULL, *key = NULL, *key_val = NULL; void *value = NULL; size_t token_sz, name_sz = strlen(name); char *orig, *tn, *tmp = strdup(line); size_t line_sz; int *value_int; if (tmp == NULL) { return NULL; } orig = tmp; line_sz = strlen(tmp); tn = strchr(tmp, '='); if (tn != NULL && ((size_t) (tn - tmp)) < line_sz) { token = tn + 1; /* move past the '=' */ *tn = 0; /* terminate token key and reset the pointer */ tn = tmp; trim(tn, ' '); trim(token, ' '); /* check if the key is what we're looking for */ if (strncmp(tn, name, name_sz) == 0) { map = 0; if ((token_sz = strlen(tn)) != name_sz) { /* get map value key */ key = strstr(tn, "["); if (key != NULL) { key++; /* move past the '[' */ if (*key != ']') { tn[token_sz - 1] = 0; key_val = strdup(key); if (key_val != NULL) { map = 1; } } } } set = 1; } if (set != 1 || !ISVALID(token)) { AM_FREE(key_val, orig); return NULL; } switch (value_type) { case CONF_NUMBER: value = malloc(sizeof (int)); if (value == NULL) { break; } value_int = (int *) value; if (strcasecmp(token, "on") == 0 || strcasecmp(token, "true") == 0 || strcasecmp(token, "local") == 0) { *value_int = 1; break; } if (strcasecmp(token, "off") == 0 || strcasecmp(token, "false") == 0 || strcasecmp(token, "centralized") == 0) { *value_int = 0; break; } *value_int = strtol(token, NULL, AM_BASE_TEN); break; case CONF_DEBUG_LEVEL: value = malloc(sizeof (int)); if (value == NULL) { break; } value_int = (int *) value; if (strncasecmp(token, "all", 3) == 0 || strcasecmp(token, "debug") == 0) { *value_int = AM_LOG_LEVEL_DEBUG; break; } if (strcasecmp(token, "error") == 0) { *value_int = AM_LOG_LEVEL_ERROR; break; } if (strcasecmp(token, "info") == 0) { *value_int = AM_LOG_LEVEL_INFO; break; } if (strcasecmp(token, "message") == 0) { *value_int = AM_LOG_LEVEL_WARNING; break; } if (strcasecmp(token, "warning") == 0) { *value_int = AM_LOG_LEVEL_WARNING; break; } *value_int = AM_LOG_LEVEL_NONE; break; case CONF_ATTR_MODE: value = malloc(sizeof (int)); if (value == NULL) { break; } value_int = (int *) value; if (strcasecmp(token, "HTTP_HEADER") == 0) { *value_int = AM_SET_ATTRS_AS_HEADER; break; } if (strcasecmp(token, "HTTP_COOKIE") == 0) { *value_int = AM_SET_ATTRS_AS_COOKIE; break; } *value_int = AM_SET_ATTRS_NONE; break; case CONF_AUDIT_LEVEL: value = calloc(1, sizeof (int)); if (value == NULL) { break; } value_int = (int *) value; if (strcasecmp(token, "LOG_ALLOW") == 0) { *value_int |= AM_LOG_LEVEL_AUDIT_ALLOW; break; } if (strcasecmp(token, "LOG_BOTH") == 0) { *value_int |= AM_LOG_LEVEL_AUDIT_ALLOW; *value_int |= AM_LOG_LEVEL_AUDIT_DENY; break; } if (strcasecmp(token, "LOG_DENY") == 0) { *value_int |= AM_LOG_LEVEL_AUDIT_DENY; break; } break; case CONF_STRING: { if (map == 1) { size_t val_sz = strlen(token); size_t key_sz = strlen(key_val); /* value is stored as: * key\0value\0 */ value = malloc(val_sz + key_sz + 2); if (value == NULL) { break; } memcpy(value, key_val, key_sz); ((char *) value)[key_sz] = 0; memcpy((char *) value + key_sz + 1, token, val_sz); ((char *) value)[val_sz + key_sz + 1] = 0; free(key_val); key_val = NULL; break; } value = strdup(token); } break; case CONF_STRING_LIST: { struct val_string_list *ret = NULL; char *sl_token = NULL, *o, *sl_tmp = strdup(token); char **vl = NULL; int i = 0, vl_sz = 0; if (sl_tmp == NULL) { break; } o = sl_tmp; while ((sl_token = am_strsep(&sl_tmp, mvsep)) != NULL) { trim(sl_token, ' '); if (!sl_token || sl_token[0] == '\0') { continue; } vl_sz++; } free(o); if (vl_sz == 0) { break; } sl_tmp = strdup(token); if (sl_tmp == NULL) { break; } o = sl_tmp; vl = malloc(sizeof (char *) * vl_sz); if (vl == NULL) { free(sl_tmp); break; } while ((sl_token = am_strsep(&sl_tmp, mvsep)) != NULL) { trim(sl_token, ' '); if (!sl_token || sl_token[0] == '\0') { continue; } vl[i] = strdup(sl_token); if (vl[i] == NULL) { break; } i++; } free(o); ret = malloc(sizeof (struct val_string_list)); if (ret == NULL) { for (i = 0; i < vl_sz; i++) { am_free(vl[i]); } free(vl); break; } ret->size = vl_sz; ret->list = vl; value = ret; } break; case CONF_NUMBER_LIST: { struct val_number_list *ret = NULL; char *sl_token = NULL, *o, *sl_tmp = strdup(token); int *vl = NULL; int i = 0, vl_sz = 0; if (sl_tmp == NULL) { break; } o = sl_tmp; while ((sl_token = am_strsep(&sl_tmp, mvsep)) != NULL) { trim(sl_token, ' '); if (!sl_token || sl_token[0] == '\0') { continue; } vl_sz++; } free(o); if (vl_sz == 0) { break; } sl_tmp = strdup(token); if (sl_tmp == NULL) { break; } o = sl_tmp; vl = malloc(sizeof (int) * vl_sz); if (vl == NULL) { free(sl_tmp); break; } while ((sl_token = am_strsep(&sl_tmp, mvsep)) != NULL) { trim(sl_token, ' '); if (!sl_token || sl_token[0] == '\0') { continue; } vl[i] = strtol(sl_token, NULL, AM_BASE_TEN); i++; } free(o); ret = malloc(sizeof (struct val_number_list)); if (ret == NULL) { free(vl); break; } ret->size = vl_sz; ret->list = vl; value = ret; } break; } am_free(key_val); } am_free(orig); return value; }