Changeset 988 for vendor/current/source4/web_server
- Timestamp:
- Nov 24, 2016, 1:14:11 PM (9 years ago)
- Location:
- vendor/current/source4/web_server
- Files:
-
- 1 deleted
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source4/web_server/web_server.c
r740 r988 29 29 #include "param/param.h" 30 30 31 NTSTATUS server_service_web_init(void); 32 31 33 /* don't allow connections to hang around forever */ 32 34 #define HTTP_TIMEOUT 120 … … 48 50 struct timeval t, void *private_data) 49 51 { 50 struct websrv_context *web = talloc_get_type (private_data, struct websrv_context);52 struct websrv_context *web = talloc_get_type_abort(private_data, struct websrv_context); 51 53 struct stream_connection *conn = web->conn; 52 54 web->conn = NULL; … … 92 94 } 93 95 94 void websrv_output(struct websrv_context *web, void *data, size_t length)96 void websrv_output(struct websrv_context *web, const void *data, size_t length) 95 97 { 96 98 data_blob_append(web, &web->output.content, data, length); 97 EVENT_FD_NOT_READABLE(web->conn->event.fde);98 EVENT_FD_WRITEABLE(web->conn->event.fde);99 TEVENT_FD_NOT_READABLE(web->conn->event.fde); 100 TEVENT_FD_WRITEABLE(web->conn->event.fde); 99 101 web->output.output_pending = true; 100 102 } … … 141 143 { 142 144 struct web_server_data *wdata; 143 struct websrv_context *web = talloc_get_type (conn->private_data,144 145 struct websrv_context *web = talloc_get_type_abort(conn->private_data, 146 struct websrv_context); 145 147 NTSTATUS status; 146 148 uint8_t buf[1024]; … … 188 190 web->input.partial.data[web->input.content_length] = 0; 189 191 } 190 EVENT_FD_NOT_READABLE(web->conn->event.fde);192 TEVENT_FD_NOT_READABLE(web->conn->event.fde); 191 193 192 194 /* the reference/unlink code here is quite subtle. It … … 198 200 rendering process when we handle the timeout. */ 199 201 if (!talloc_reference(web->task, web)) goto failed; 200 wdata = talloc_get_type (web->task->private_data, struct web_server_data);202 wdata = talloc_get_type_abort(web->task->private_data, struct web_server_data); 201 203 if (wdata == NULL) goto failed; 202 204 wdata->http_process_input(wdata, web); … … 216 218 static void websrv_send(struct stream_connection *conn, uint16_t flags) 217 219 { 218 struct websrv_context *web = talloc_get_type (conn->private_data,219 220 struct websrv_context *web = talloc_get_type_abort(conn->private_data, 221 struct websrv_context); 220 222 NTSTATUS status; 221 223 size_t nsent; … … 247 249 static void websrv_accept(struct stream_connection *conn) 248 250 { 249 struct task_server *task = talloc_get_type (conn->private_data, struct task_server);250 struct web_server_data *wdata = talloc_get_type (task->private_data, struct web_server_data);251 struct task_server *task = talloc_get_type_abort(conn->private_data, struct task_server); 252 struct web_server_data *wdata = talloc_get_type_abort(task->private_data, struct web_server_data); 251 253 struct websrv_context *web; 252 254 struct socket_context *tls_socket; … … 255 257 if (web == NULL) goto failed; 256 258 257 web->task = task;259 web->task = wdata->task; 258 260 web->conn = conn; 259 261 conn->private_data = web; 260 262 talloc_set_destructor(web, websrv_destructor); 261 263 262 event_add_timed(conn->event.ctx, web,264 tevent_add_timer(conn->event.ctx, web, 263 265 timeval_current_ofs(HTTP_TIMEOUT, 0), 264 266 websrv_timeout, web); … … 311 313 if (wdata == NULL) goto failed; 312 314 315 wdata->task = task; 313 316 task->private_data = wdata; 314 317 … … 318 321 struct interface *ifaces; 319 322 320 load_interface s(NULL, lpcfg_interfaces(task->lp_ctx), &ifaces);321 322 num_interfaces = iface_ count(ifaces);323 load_interface_list(NULL, task->lp_ctx, &ifaces); 324 325 num_interfaces = iface_list_count(ifaces); 323 326 for(i = 0; i < num_interfaces; i++) { 324 const char *address = iface_ n_ip(ifaces, i);327 const char *address = iface_list_n_ip(ifaces, i); 325 328 status = stream_setup_socket(task, 326 329 task->event_ctx, 327 330 task->lp_ctx, model_ops, 328 331 &web_stream_ops, 329 "ip v4", address,332 "ip", address, 330 333 &port, lpcfg_socket_options(task->lp_ctx), 331 334 task); … … 335 338 talloc_free(ifaces); 336 339 } else { 337 status = stream_setup_socket(task, task->event_ctx, 338 task->lp_ctx, model_ops, 339 &web_stream_ops, 340 "ipv4", lpcfg_socket_address(task->lp_ctx), 341 &port, lpcfg_socket_options(task->lp_ctx), 342 task); 343 if (!NT_STATUS_IS_OK(status)) goto failed; 340 char **wcard; 341 int i; 342 wcard = iface_list_wildcard(task); 343 if (wcard == NULL) { 344 DEBUG(0,("No wildcard addresses available\n")); 345 goto failed; 346 } 347 for (i=0; wcard[i]; i++) { 348 status = stream_setup_socket(task, task->event_ctx, 349 task->lp_ctx, model_ops, 350 &web_stream_ops, 351 "ip", wcard[i], 352 &port, lpcfg_socket_options(task->lp_ctx), 353 wdata); 354 if (!NT_STATUS_IS_OK(status)) goto failed; 355 } 356 talloc_free(wcard); 344 357 } 345 358 -
vendor/current/source4/web_server/web_server.h
r740 r988 30 30 struct websrv_context *web); 31 31 void *private_data; 32 struct task_server *task; 32 33 }; 33 34 … … 67 68 void http_error(struct websrv_context *web, const char *status, const char *info); 68 69 void websrv_output_headers(struct websrv_context *web, const char *status, struct http_header *headers); 69 void websrv_output(struct websrv_context *web, void *data, size_t length);70 void websrv_output(struct websrv_context *web, const void *data, size_t length); 70 71 NTSTATUS http_parse_header(struct websrv_context *web, const char *line); 71 72 -
vendor/current/source4/web_server/wscript_build
r740 r988 6 6 pyext=True, 7 7 deps='talloc LIBTSOCKET', 8 enabled=bld.AD_DC_BUILD_IS_ENABLED() 8 9 ) 9 10 … … 16 17 pyembed=True, 17 18 internal_module=False, 19 enabled=bld.AD_DC_BUILD_IS_ENABLED() 18 20 ) -
vendor/current/source4/web_server/wsgi.c
r740 r988 27 27 #include "lib/tls/tls.h" 28 28 #include "lib/tsocket/tsocket.h" 29 #include "scripting/python/modules.h" 30 31 /* There's no Py_ssize_t in 2.4, apparently */ 32 #if PY_MAJOR_VERSION == 2 && PY_MINOR_VERSION < 5 33 typedef int Py_ssize_t; 34 typedef inquiry lenfunc; 35 typedef intargfunc ssizeargfunc; 36 #endif 29 #include "python/modules.h" 37 30 38 31 typedef struct { … … 135 128 } 136 129 137 DEBUG(0, (" WSGI App:%s", str));130 DEBUG(0, ("%s", str)); 138 131 139 132 Py_RETURN_NONE; … … 148 141 return NULL; 149 142 } 150 143 151 144 while ((item = PyIter_Next(seq))) { 152 145 char *str = PyString_AsString(item); 153 146 154 DEBUG(0, (" WSGI App:%s", str));147 DEBUG(0, ("%s", str)); 155 148 } 156 149 … … 261 254 } 262 255 256 static void DEBUG_Print_PyError(int level, const char *message) 257 { 258 PyObject *old_stderr, *new_stderr; 259 PyObject *sys_module; 260 PyObject *ptype, *pvalue, *ptb; 261 262 PyErr_Fetch(&ptype, &pvalue, &ptb); 263 264 DEBUG(0, ("WSGI: Server exception occurred: %s\n", message)); 265 266 sys_module = PyImport_ImportModule("sys"); 267 if (sys_module == NULL) { 268 DEBUG(0, ("Unable to obtain sys module while printing error")); 269 return; 270 } 271 272 old_stderr = PyObject_GetAttrString(sys_module, "stderr"); 273 if (old_stderr == NULL) { 274 DEBUG(0, ("Unable to obtain old stderr")); 275 Py_DECREF(sys_module); 276 return; 277 } 278 279 new_stderr = Py_ErrorHttpStream(); 280 if (new_stderr == NULL) { 281 DEBUG(0, ("Unable to create error stream")); 282 Py_DECREF(sys_module); 283 Py_DECREF(old_stderr); 284 return; 285 } 286 287 PyObject_SetAttrString(sys_module, "stderr", new_stderr); 288 Py_DECREF(new_stderr); 289 290 PyErr_Restore(ptype, pvalue, ptb); 291 PyErr_Print(); 292 293 PyObject_SetAttrString(sys_module, "stderr", old_stderr); 294 Py_DECREF(old_stderr); 295 296 Py_DECREF(sys_module); 297 } 298 263 299 static PyObject *create_environ(bool tls, int content_length, struct http_header *headers, const char *request_method, const char *servername, int serverport, PyObject *inputstream, const char *request_string) 264 300 { 265 301 PyObject *env; 266 PyObject *errorstream;267 302 PyObject *py_scheme; 303 PyObject *py_val; 268 304 struct http_header *hdr; 269 305 char *questionmark; 270 306 271 307 env = PyDict_New(); 272 308 if (env == NULL) { … … 274 310 } 275 311 276 errorstream = Py_ErrorHttpStream();277 if (errorstream == NULL) {278 Py_DECREF(env);279 Py_DECREF(inputstream);280 return NULL;281 }282 283 312 PyDict_SetItemString(env, "wsgi.input", inputstream); 284 PyDict_SetItemString(env, "wsgi.errors", errorstream); 285 PyDict_SetItemString(env, "wsgi.version", Py_BuildValue("(i,i)", 1, 0)); 313 314 py_val = Py_ErrorHttpStream(); 315 if (py_val == NULL) goto error; 316 PyDict_SetItemString(env, "wsgi.errors", py_val); 317 Py_DECREF(py_val); 318 319 py_val = Py_BuildValue("(i,i)", 1, 0); 320 if (py_val == NULL) goto error; 321 PyDict_SetItemString(env, "wsgi.version", py_val); 322 Py_DECREF(py_val); 286 323 PyDict_SetItemString(env, "wsgi.multithread", Py_False); 287 PyDict_SetItemString(env, "wsgi.multiprocess", Py_ True);324 PyDict_SetItemString(env, "wsgi.multiprocess", Py_False); 288 325 PyDict_SetItemString(env, "wsgi.run_once", Py_False); 289 PyDict_SetItemString(env, "SERVER_PROTOCOL", PyString_FromString("HTTP/1.0")); 326 py_val = PyString_FromString("HTTP/1.0"); 327 if (py_val == NULL) goto error; 328 PyDict_SetItemString(env, "SERVER_PROTOCOL", py_val); 329 Py_DECREF(py_val); 290 330 if (content_length > 0) { 291 PyDict_SetItemString(env, "CONTENT_LENGTH", PyLong_FromLong(content_length)); 292 } 293 PyDict_SetItemString(env, "REQUEST_METHOD", PyString_FromString(request_method)); 294 331 py_val = PyLong_FromLong(content_length); 332 if (py_val == NULL) goto error; 333 PyDict_SetItemString(env, "CONTENT_LENGTH", py_val); 334 Py_DECREF(py_val); 335 } 336 py_val = PyString_FromString(request_method); 337 if (py_val == NULL) goto error; 338 PyDict_SetItemString(env, "REQUEST_METHOD", py_val); 339 Py_DECREF(py_val); 340 341 /* There is always a single wsgi app to which all requests are redirected, 342 * so SCRIPT_NAME will be / */ 343 py_val = PyString_FromString("/"); 344 if (py_val == NULL) goto error; 345 PyDict_SetItemString(env, "SCRIPT_NAME", py_val); 346 Py_DECREF(py_val); 295 347 questionmark = strchr(request_string, '?'); 296 348 if (questionmark == NULL) { 297 PyDict_SetItemString(env, "SCRIPT_NAME", PyString_FromString(request_string)); 349 py_val = PyString_FromString(request_string); 350 if (py_val == NULL) goto error; 351 PyDict_SetItemString(env, "PATH_INFO", py_val); 352 Py_DECREF(py_val); 298 353 } else { 299 PyDict_SetItemString(env, "QUERY_STRING", PyString_FromString(questionmark+1)); 300 PyDict_SetItemString(env, "SCRIPT_NAME", PyString_FromStringAndSize(request_string, questionmark-request_string)); 301 } 302 303 PyDict_SetItemString(env, "SERVER_NAME", PyString_FromString(servername)); 304 PyDict_SetItemString(env, "SERVER_PORT", PyInt_FromLong(serverport)); 354 py_val = PyString_FromString(questionmark+1); 355 if (py_val == NULL) goto error; 356 PyDict_SetItemString(env, "QUERY_STRING", py_val); 357 Py_DECREF(py_val); 358 py_val = PyString_FromStringAndSize(request_string, questionmark-request_string); 359 if (py_val == NULL) goto error; 360 PyDict_SetItemString(env, "PATH_INFO", py_val); 361 Py_DECREF(py_val); 362 } 363 364 py_val = PyString_FromString(servername); 365 if (py_val == NULL) goto error; 366 PyDict_SetItemString(env, "SERVER_NAME", py_val); 367 Py_DECREF(py_val); 368 py_val = PyString_FromFormat("%d", serverport); 369 if (py_val == NULL) goto error; 370 PyDict_SetItemString(env, "SERVER_PORT", py_val); 371 Py_DECREF(py_val); 372 305 373 for (hdr = headers; hdr; hdr = hdr->next) { 306 374 char *name; 307 375 if (!strcasecmp(hdr->name, "Content-Type")) { 308 PyDict_SetItemString(env, "CONTENT_TYPE", PyString_FromString(hdr->value)); 309 } else { 376 py_val = PyString_FromString(hdr->value); 377 PyDict_SetItemString(env, "CONTENT_TYPE", py_val); 378 Py_DECREF(py_val); 379 } else { 310 380 if (asprintf(&name, "HTTP_%s", hdr->name) < 0) { 311 Py_DECREF(env);312 Py_DECREF(inputstream);313 381 PyErr_NoMemory(); 314 return NULL;382 goto error; 315 383 } 316 PyDict_SetItemString(env, name, PyString_FromString(hdr->value)); 384 py_val = PyString_FromString(hdr->value); 385 PyDict_SetItemString(env, name, py_val); 386 Py_DECREF(py_val); 317 387 free(name); 318 388 } … … 324 394 py_scheme = PyString_FromString("http"); 325 395 } 396 if (py_scheme == NULL) goto error; 326 397 PyDict_SetItemString(env, "wsgi.url_scheme", py_scheme); 398 Py_DECREF(py_scheme); 327 399 328 400 return env; 401 error: 402 Py_DECREF(env); 403 return NULL; 404 } 405 406 static void wsgi_serve_500(struct websrv_context *web) 407 { 408 struct http_header *headers = NULL; 409 const char *contents[] = { 410 "An internal server error occurred while handling this request. ", 411 "Please refer to the server logs for more details. ", 412 NULL 413 }; 414 int i; 415 416 websrv_output_headers(web, "500 Internal Server Error", headers); 417 for (i = 0; contents[i]; i++) { 418 websrv_output(web, contents[i], strlen(contents[i])); 419 } 329 420 } 330 421 … … 337 428 const char *addr = "0.0.0.0"; 338 429 uint16_t port = 0; 339 web_request_Object *py_web = PyObject_New(web_request_Object, &web_request_Type); 430 web_request_Object *py_web; 431 PyObject *py_input_stream; 432 433 py_web = PyObject_New(web_request_Object, &web_request_Type); 434 if (py_web == NULL) { 435 DEBUG_Print_PyError(0, "Unable to allocate web request"); 436 return; 437 } 340 438 py_web->web = web; 341 439 … … 343 441 addr = tsocket_address_inet_addr_string(my_address, wdata); 344 442 port = tsocket_address_inet_port(my_address); 443 } 444 445 py_input_stream = Py_InputHttpStream(web); 446 if (py_input_stream == NULL) { 447 DEBUG_Print_PyError(0, "unable to create python input stream"); 448 return; 345 449 } 346 450 … … 351 455 addr, 352 456 port, 353 Py_InputHttpStream(web),457 py_input_stream, 354 458 web->input.url 355 459 ); 460 461 Py_DECREF(py_input_stream); 462 356 463 if (py_environ == NULL) { 357 DEBUG(0, ("Unable to create WSGI environment object\n")); 464 DEBUG_Print_PyError(0, "Unable to create WSGI environment object"); 465 wsgi_serve_500(web); 358 466 return; 359 467 } … … 363 471 364 472 if (result == NULL) { 365 DEBUG(0, ("error while running WSGI code\n")); 473 DEBUG_Print_PyError(0, "error while handling request"); 474 wsgi_serve_500(web); 366 475 return; 367 476 } … … 369 478 iter = PyObject_GetIter(result); 370 479 Py_DECREF(result); 480 481 if (iter == NULL) { 482 DEBUG_Print_PyError(0, "application did not return iterable"); 483 wsgi_serve_500(web); 484 return; 485 } 371 486 372 487 /* Now, iter over all the data returned */ … … 401 516 py_web_server = PyImport_ImportModule("samba.web_server"); 402 517 if (py_web_server == NULL) { 403 DEBUG (0, ("Unable to find web server\n"));518 DEBUG_Print_PyError(0, "Unable to find web server"); 404 519 return false; 405 520 }
Note:
See TracChangeset
for help on using the changeset viewer.