wStream* rpc_ntlm_http_request(rdpRpc* rpc, SecBuffer* ntlm_token, int content_length, TSG_CHANNEL channel) { wStream* s; char* base64_ntlm_token; HttpContext* http_context; HttpRequest* http_request; http_request = http_request_new(); base64_ntlm_token = crypto_base64_encode(ntlm_token->pvBuffer, ntlm_token->cbBuffer); if (channel == TSG_CHANNEL_IN) { http_context = rpc->NtlmHttpIn->context; http_request_set_method(http_request, "RPC_IN_DATA"); } else if (channel == TSG_CHANNEL_OUT) { http_context = rpc->NtlmHttpOut->context; http_request_set_method(http_request, "RPC_OUT_DATA"); } else { return NULL; } http_request->ContentLength = content_length; http_request_set_uri(http_request, http_context->URI); http_request_set_auth_scheme(http_request, "NTLM"); http_request_set_auth_param(http_request, base64_ntlm_token); s = http_request_write(http_context, http_request); http_request_free(http_request); free(base64_ntlm_token); return s; }
void send_head_request(uv_connect_t *req, int status) { if (status != 0) { printf("on connect failed: %s\n", uv_strerror(status)); return; } uv_read_start(req->handle, on_alloc, on_head_read); task *task = (struct task*)req->handle->data; http_request *request = task->head_request; http_set_on_header_field(request, on_header_field); http_set_on_header_value(request, on_header_value); http_set_on_headers_complete(request, on_headers_complete_close); http_request_set_method(request, HTTP_HEAD); http_send_request(request); uv_fs_t fs; task->fd = uv_fs_open(req->handle->loop, &fs, task->name, O_CREAT | O_RDWR, 0777, NULL); }
static wStream* rdg_build_http_request(rdpRdg* rdg, const char* method, const char* transferEncoding) { wStream* s = NULL; HttpRequest* request = NULL; assert(method != NULL); request = http_request_new(); if (!request) return NULL; http_request_set_method(request, method); http_request_set_uri(request, rdg->http->URI); if (!request->Method || !request->URI) goto out; if (rdg->ntlm) { if (!rdg_set_ntlm_auth_header(rdg->ntlm, request)) goto out; } if (transferEncoding) { http_request_set_transfer_encoding(request, transferEncoding); } s = http_request_write(rdg->http, request); out: http_request_free(request); if (s) Stream_SealLength(s); return s; }
/* * Send a copy of the message, wait for a reply, and return the reply. * * The "reply" should already be initialized. * * This properly handles the calling thread's being canceled. */ int http_xml_send(struct http_client *client, struct in_addr ip, u_int16_t port, int https, const char *urlpath, const char *username, const char *password, const char *ptag, const char *pattrs, const struct structs_type *ptype, const void *payload, int pflags, const char *rtag, char **rattrsp, const char *rattrs_mtype, const struct structs_type *rtype, void *reply, int rflags, structs_xmllog_t *rlogger) { struct http_client_connection *cc; struct http_request *req; struct http_response *resp; int ret = -1; u_int code; FILE *fp; /* Get HTTP connection */ if ((cc = http_client_connect(client, ip, port, https)) == NULL) { alogf(LOG_ERR, "can't %s for %s:%u: %m", "get HTTP client" _ inet_ntoa(ip) _ port); return -1; } /* Push cleanup hook */ pthread_cleanup_push(http_xml_send_cleanup, cc); /* Set up request */ req = http_client_get_request(cc); if (http_request_set_method(req, payload != NULL ? HTTP_METHOD_POST : HTTP_METHOD_GET) == -1) { alogf(LOG_ERR, "can't %s for %s:%u: %m", "set method" _ inet_ntoa(ip) _ port); goto fail; } if (http_request_set_path(req, urlpath) == -1) { alogf(LOG_ERR, "can't %s for %s:%u: %m", "set path" _ inet_ntoa(ip) _ port); goto fail; } if (http_request_set_header(req, 0, "Content-Type", "text/xml") == -1) { alogf(LOG_ERR, "can't %s for %s:%u: %m", "set content-type" _ inet_ntoa(ip) _ port); goto fail; } if (username != NULL && password != NULL) { char *auth; if ((auth = http_request_encode_basic_auth(TYPED_MEM_TEMP, username, password)) == NULL) { alogf(LOG_ERR, "can't %s for %s:%u: %m", "encode authorization" _ inet_ntoa(ip) _ port); goto fail; } if (http_request_set_header(req, 0, "Authorization", "Basic %s", auth) == -1) { alogf(LOG_ERR, "can't %s for %s:%u: %m", "set authorization header" _ inet_ntoa(ip) _ port); FREE(TYPED_MEM_TEMP, auth); goto fail; } FREE(TYPED_MEM_TEMP, auth); } /* Write XML data to HTTP client output stream */ if (payload != NULL) { if ((fp = http_request_get_output(req, 1)) == NULL) { alogf(LOG_ERR, "can't %s for %s:%u: %m", "get output" _ inet_ntoa(ip) _ port); goto fail; } if (structs_xml_output(ptype, ptag, pattrs, payload, fp, NULL, pflags) == -1) { alogf(LOG_ERR, "can't %s for %s:%u: %m", "write XML" _ inet_ntoa(ip) _ port); goto fail; } } /* Get response */ if ((resp = http_client_get_response(cc)) == NULL) { alogf(LOG_ERR, "can't %s for %s:%u: %m", "get response" _ inet_ntoa(ip) _ port); goto fail; } if ((code = http_response_get_code(resp)) != HTTP_STATUS_OK) { alogf(LOG_ERR, "rec'd HTTP error code %d from" "http%s://%s:%u%s: %s", code _ https ? "s" : "" _ inet_ntoa(ip) _ port _ urlpath _ http_response_status_msg(code)); goto fail; } /* Read XML reply from client input stream */ if ((fp = http_response_get_input(resp)) == NULL) { alogf(LOG_ERR, "can't %s for %s:%u: %m", "get input" _ inet_ntoa(ip) _ port); goto fail; } if (structs_xml_input(rtype, rtag, rattrsp, rattrs_mtype, fp, reply, rflags, rlogger) == -1) { alogf(LOG_ERR, "can't %s for %s:%u: %m", "read XML reply" _ inet_ntoa(ip) _ port); goto fail; } /* OK */ ret = 0; fail:; /* Done */ pthread_cleanup_pop(1); return (ret); }