Ignore:
Timestamp:
Nov 24, 2016, 1:14:11 PM (9 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to version 4.4.3

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  
    2929#include "param/param.h"
    3030
     31NTSTATUS server_service_web_init(void);
     32
    3133/* don't allow connections to hang around forever */
    3234#define HTTP_TIMEOUT 120
     
    4850                           struct timeval t, void *private_data)
    4951{
    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);
    5153        struct stream_connection *conn = web->conn;
    5254        web->conn = NULL;
     
    9294}
    9395
    94 void websrv_output(struct websrv_context *web, void *data, size_t length)
     96void websrv_output(struct websrv_context *web, const void *data, size_t length)
    9597{
    9698        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);
    99101        web->output.output_pending = true;
    100102}
     
    141143{
    142144        struct web_server_data *wdata;
    143         struct websrv_context *web = talloc_get_type(conn->private_data,
    144                                                      struct websrv_context);
     145        struct websrv_context *web = talloc_get_type_abort(conn->private_data,
     146                                                           struct websrv_context);
    145147        NTSTATUS status;
    146148        uint8_t buf[1024];
     
    188190                        web->input.partial.data[web->input.content_length] = 0;
    189191                }
    190                 EVENT_FD_NOT_READABLE(web->conn->event.fde);
     192                TEVENT_FD_NOT_READABLE(web->conn->event.fde);
    191193
    192194                /* the reference/unlink code here is quite subtle. It
     
    198200                 rendering process when we handle the timeout. */
    199201                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);
    201203                if (wdata == NULL) goto failed;
    202204                wdata->http_process_input(wdata, web);
     
    216218static void websrv_send(struct stream_connection *conn, uint16_t flags)
    217219{
    218         struct websrv_context *web = talloc_get_type(conn->private_data,
    219                                                      struct websrv_context);
     220        struct websrv_context *web = talloc_get_type_abort(conn->private_data,
     221                                                           struct websrv_context);
    220222        NTSTATUS status;
    221223        size_t nsent;
     
    247249static void websrv_accept(struct stream_connection *conn)
    248250{
    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);
    251253        struct websrv_context *web;
    252254        struct socket_context *tls_socket;
     
    255257        if (web == NULL) goto failed;
    256258
    257         web->task = task;
     259        web->task = wdata->task;
    258260        web->conn = conn;
    259261        conn->private_data = web;
    260262        talloc_set_destructor(web, websrv_destructor);
    261263
    262         event_add_timed(conn->event.ctx, web,
     264        tevent_add_timer(conn->event.ctx, web,
    263265                        timeval_current_ofs(HTTP_TIMEOUT, 0),
    264266                        websrv_timeout, web);
     
    311313        if (wdata == NULL) goto failed;
    312314
     315        wdata->task = task;
    313316        task->private_data = wdata;
    314317
     
    318321                struct interface *ifaces;
    319322
    320                 load_interfaces(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);
    323326                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);
    325328                        status = stream_setup_socket(task,
    326329                                                     task->event_ctx,
    327330                                                     task->lp_ctx, model_ops,
    328331                                                     &web_stream_ops,
    329                                                      "ipv4", address,
     332                                                     "ip", address,
    330333                                                     &port, lpcfg_socket_options(task->lp_ctx),
    331334                                                     task);
     
    335338                talloc_free(ifaces);
    336339        } 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);
    344357        }
    345358
  • vendor/current/source4/web_server/web_server.h

    r740 r988  
    3030                                   struct websrv_context *web);
    3131        void *private_data;
     32        struct task_server *task;
    3233};
    3334
     
    6768void http_error(struct websrv_context *web, const char *status, const char *info);
    6869void 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);
     70void websrv_output(struct websrv_context *web, const void *data, size_t length);
    7071NTSTATUS http_parse_header(struct websrv_context *web, const char *line);
    7172
  • vendor/current/source4/web_server/wscript_build

    r740 r988  
    66                pyext=True,
    77                deps='talloc LIBTSOCKET',
     8                enabled=bld.AD_DC_BUILD_IS_ENABLED()
    89                )
    910
     
    1617                pyembed=True,
    1718                internal_module=False,
     19                enabled=bld.AD_DC_BUILD_IS_ENABLED()
    1820                )
  • vendor/current/source4/web_server/wsgi.c

    r740 r988  
    2727#include "lib/tls/tls.h"
    2828#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"
    3730
    3831typedef struct {
     
    135128        }
    136129
    137         DEBUG(0, ("WSGI App: %s", str));
     130        DEBUG(0, ("%s", str));
    138131
    139132        Py_RETURN_NONE;
     
    148141                return NULL;
    149142        }
    150        
     143
    151144        while ((item = PyIter_Next(seq))) {
    152145                char *str = PyString_AsString(item);
    153146
    154                 DEBUG(0, ("WSGI App: %s", str));
     147                DEBUG(0, ("%s", str));
    155148        }
    156149
     
    261254}
    262255
     256static 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
    263299static 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)
    264300{
    265301        PyObject *env;
    266         PyObject *errorstream;
    267302        PyObject *py_scheme;
     303        PyObject *py_val;
    268304        struct http_header *hdr;
    269305        char *questionmark;
    270        
     306
    271307        env = PyDict_New();
    272308        if (env == NULL) {
     
    274310        }
    275311
    276         errorstream = Py_ErrorHttpStream();
    277         if (errorstream == NULL) {
    278                 Py_DECREF(env);
    279                 Py_DECREF(inputstream);
    280                 return NULL;
    281         }
    282 
    283312        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);
    286323        PyDict_SetItemString(env, "wsgi.multithread", Py_False);
    287         PyDict_SetItemString(env, "wsgi.multiprocess", Py_True);
     324        PyDict_SetItemString(env, "wsgi.multiprocess", Py_False);
    288325        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);
    290330        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);
    295347        questionmark = strchr(request_string, '?');
    296348        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);
    298353        } 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
    305373        for (hdr = headers; hdr; hdr = hdr->next) {
    306374                char *name;
    307375                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 {
    310380                        if (asprintf(&name, "HTTP_%s", hdr->name) < 0) {
    311                                 Py_DECREF(env);
    312                                 Py_DECREF(inputstream);
    313381                                PyErr_NoMemory();
    314                                 return NULL;
     382                                goto error;
    315383                        }
    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);
    317387                        free(name);
    318388                }
     
    324394                py_scheme = PyString_FromString("http");
    325395        }
     396        if (py_scheme == NULL) goto error;
    326397        PyDict_SetItemString(env, "wsgi.url_scheme", py_scheme);
     398        Py_DECREF(py_scheme);
    327399
    328400        return env;
     401error:
     402        Py_DECREF(env);
     403        return NULL;
     404}
     405
     406static 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        }
    329420}
    330421
     
    337428        const char *addr = "0.0.0.0";
    338429        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        }
    340438        py_web->web = web;
    341439
     
    343441                addr = tsocket_address_inet_addr_string(my_address, wdata);
    344442                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;
    345449        }
    346450
     
    351455                                    addr,
    352456                                    port,
    353                                     Py_InputHttpStream(web),
     457                                    py_input_stream,
    354458                                    web->input.url
    355459                                    );
     460
     461        Py_DECREF(py_input_stream);
     462
    356463        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);
    358466                return;
    359467        }
     
    363471
    364472        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);
    366475                return;
    367476        }
     
    369478        iter = PyObject_GetIter(result);
    370479        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        }
    371486
    372487        /* Now, iter over all the data returned */
     
    401516        py_web_server = PyImport_ImportModule("samba.web_server");
    402517        if (py_web_server == NULL) {
    403                 DEBUG(0, ("Unable to find web server\n"));
     518                DEBUG_Print_PyError(0, "Unable to find web server");
    404519                return false;
    405520        }
Note: See TracChangeset for help on using the changeset viewer.