Ignore:
Timestamp:
Nov 14, 2012, 12:59:34 PM (13 years ago)
Author:
Silvan Scherrer
Message:

Samba Server: update vendor to 3.6.0

File:
1 edited

Legend:

Unmodified
Added
Removed
  • vendor/current/source3/smbd/notify.c

    r587 r740  
    2121
    2222#include "includes.h"
     23#include "smbd/smbd.h"
    2324#include "smbd/globals.h"
     25#include "../librpc/gen_ndr/ndr_notify.h"
    2426
    2527struct notify_change_request {
     
    4648        struct notify_mid_map *prev, *next;
    4749        struct notify_change_request *req;
    48         uint16 mid;
     50        uint64_t mid;
    4951};
    5052
     
    6365                                uint32 max_offset,
    6466                                struct notify_change *changes,
    65                                 prs_struct *ps)
     67                                DATA_BLOB *final_blob)
    6668{
    6769        int i;
    68         UNISTR uni_name;
    6970
    7071        if (num_changes == -1) {
     
    7273        }
    7374
    74         uni_name.buffer = NULL;
    75 
    7675        for (i=0; i<num_changes; i++) {
     76                enum ndr_err_code ndr_err;
    7777                struct notify_change *c;
    78                 size_t namelen;
    79                 int    rem = 0;
    80                 uint32 u32_tmp; /* Temp arg to prs_uint32 to avoid
    81                                  * signed/unsigned issues */
     78                struct FILE_NOTIFY_INFORMATION m;
     79                DATA_BLOB blob;
    8280
    8381                /* Coalesce any identical records. */
     
    9088                c = &changes[i];
    9189
    92                 if (!convert_string_talloc(talloc_tos(), CH_UNIX, CH_UTF16LE,
    93                         c->name, strlen(c->name)+1, &uni_name.buffer,
    94                         &namelen, True) || (uni_name.buffer == NULL)) {
    95                         goto fail;
    96                 }
    97 
    98                 namelen -= 2;   /* Dump NULL termination */
     90                m.FileName1 = c->name;
     91                m.FileNameLength = strlen_m(c->name)*2;
     92                m.Action = c->action;
     93                m.NextEntryOffset = (i == num_changes-1) ? 0 : ndr_size_FILE_NOTIFY_INFORMATION(&m, 0);
    9994
    10095                /*
     
    10297                 */
    10398
    104                 u32_tmp = (i == num_changes-1) ? 0 : namelen + 12;
    105 
    106                 /* Align on 4-byte boundary according to MS-CIFS 2.2.7.4.2 */
    107                 if ((rem = u32_tmp % 4 ) != 0)
    108                         u32_tmp += 4 - rem;
    109 
    110                 if (!prs_uint32("offset", ps, 1, &u32_tmp)) goto fail;
    111 
    112                 u32_tmp = c->action;
    113                 if (!prs_uint32("action", ps, 1, &u32_tmp)) goto fail;
    114 
    115                 u32_tmp = namelen;
    116                 if (!prs_uint32("namelen", ps, 1, &u32_tmp)) goto fail;
    117 
    118                 if (!prs_unistr("name", ps, 1, &uni_name)) goto fail;
    119 
    120                 /*
    121                  * Not NULL terminated, decrease by the 2 UCS2 \0 chars
    122                  */
    123                 prs_set_offset(ps, prs_offset(ps)-2);
    124 
    125                 if (rem != 0) {
    126                         if (!prs_align_custom(ps, 4)) goto fail;
    127                 }
    128 
    129                 TALLOC_FREE(uni_name.buffer);
    130 
    131                 if (prs_offset(ps) > max_offset) {
     99                ndr_err = ndr_push_struct_blob(&blob, talloc_tos(), &m,
     100                        (ndr_push_flags_fn_t)ndr_push_FILE_NOTIFY_INFORMATION);
     101                if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     102                        return false;
     103                }
     104
     105                if (DEBUGLEVEL >= 10) {
     106                        NDR_PRINT_DEBUG(FILE_NOTIFY_INFORMATION, &m);
     107                }
     108
     109                if (!data_blob_append(talloc_tos(), final_blob,
     110                                      blob.data, blob.length)) {
     111                        data_blob_free(&blob);
     112                        return false;
     113                }
     114
     115                data_blob_free(&blob);
     116
     117                if (final_blob->length > max_offset) {
    132118                        /* Too much data for client. */
    133119                        DEBUG(10, ("Client only wanted %d bytes, trying to "
    134120                                   "marshall %d bytes\n", (int)max_offset,
    135                                    (int)prs_offset(ps)));
     121                                   (int)final_blob->length));
    136122                        return False;
    137123                }
     
    139125
    140126        return True;
    141 
    142  fail:
    143         TALLOC_FREE(uni_name.buffer);
    144         return False;
    145127}
    146128
     
    149131*****************************************************************************/
    150132
    151 void change_notify_reply(connection_struct *conn,
    152                          struct smb_request *req,
     133void change_notify_reply(struct smb_request *req,
    153134                         NTSTATUS error_code,
    154135                         uint32_t max_param,
    155136                         struct notify_change_buf *notify_buf,
    156137                         void (*reply_fn)(struct smb_request *req,
    157                                 NTSTATUS error_code,
    158                                 uint8_t *buf, size_t len))
    159 {
    160         prs_struct ps;
     138                                          NTSTATUS error_code,
     139                                          uint8_t *buf, size_t len))
     140{
     141        DATA_BLOB blob = data_blob_null;
    161142
    162143        if (!NT_STATUS_IS_OK(error_code)) {
     
    170151        }
    171152
    172         prs_init_empty(&ps, NULL, MARSHALL);
    173 
    174153        if (!notify_marshall_changes(notify_buf->num_changes, max_param,
    175                                         notify_buf->changes, &ps)) {
     154                                        notify_buf->changes, &blob)) {
    176155                /*
    177156                 * We exceed what the client is willing to accept. Send
    178157                 * nothing.
    179158                 */
    180                 prs_mem_free(&ps);
    181                 prs_init_empty(&ps, NULL, MARSHALL);
    182         }
    183 
    184         reply_fn(req, NT_STATUS_OK, (uint8_t *)prs_data_p(&ps), prs_offset(&ps));
    185 
    186         prs_mem_free(&ps);
     159                data_blob_free(&blob);
     160        }
     161
     162        reply_fn(req, NT_STATUS_OK, blob.data, blob.length);
     163
     164        data_blob_free(&blob);
    187165
    188166        TALLOC_FREE(notify_buf->changes);
     
    245223        struct notify_change_request *request = NULL;
    246224        struct notify_mid_map *map = NULL;
    247         struct smbd_server_connection *sconn = smbd_server_conn;
     225        struct smbd_server_connection *sconn = req->sconn;
    248226
    249227        DEBUG(10, ("change_notify_add_request: Adding request for %s: "
     
    275253}
    276254
    277 static void change_notify_remove_request(struct notify_change_request *remove_req)
     255static void change_notify_remove_request(struct smbd_server_connection *sconn,
     256                                         struct notify_change_request *remove_req)
    278257{
    279258        files_struct *fsp;
    280259        struct notify_change_request *req;
    281         struct smbd_server_connection *sconn = smbd_server_conn;
    282260
    283261        /*
     
    308286*****************************************************************************/
    309287
    310 void remove_pending_change_notify_requests_by_mid(uint16 mid)
     288void remove_pending_change_notify_requests_by_mid(
     289        struct smbd_server_connection *sconn, uint64_t mid)
    311290{
    312291        struct notify_mid_map *map;
    313         struct smbd_server_connection *sconn = smbd_server_conn;
    314292
    315293        for (map = sconn->smb1.notify_mid_maps; map; map = map->next) {
     
    323301        }
    324302
    325         change_notify_reply(map->req->fsp->conn, map->req->req,
     303        change_notify_reply(map->req->req,
    326304                            NT_STATUS_CANCELLED, 0, NULL, map->req->reply_fn);
    327         change_notify_remove_request(map->req);
    328 }
    329 
    330 void smbd_notify_cancel_by_smbreq(struct smbd_server_connection *sconn,
    331                                   const struct smb_request *smbreq)
    332 {
     305        change_notify_remove_request(sconn, map->req);
     306}
     307
     308void smbd_notify_cancel_by_smbreq(const struct smb_request *smbreq)
     309{
     310        struct smbd_server_connection *sconn = smbreq->sconn;
    333311        struct notify_mid_map *map;
    334312
     
    343321        }
    344322
    345         change_notify_reply(map->req->fsp->conn, map->req->req,
     323        change_notify_reply(map->req->req,
    346324                            NT_STATUS_CANCELLED, 0, NULL, map->req->reply_fn);
    347         change_notify_remove_request(map->req);
     325        change_notify_remove_request(sconn, map->req);
    348326}
    349327
     
    360338
    361339        while (fsp->notify->requests != NULL) {
    362                 change_notify_reply(fsp->conn, fsp->notify->requests->req,
     340                change_notify_reply(fsp->notify->requests->req,
    363341                                    status, 0, NULL,
    364342                                    fsp->notify->requests->reply_fn);
    365                 change_notify_remove_request(fsp->notify->requests);
     343                change_notify_remove_request(fsp->conn->sconn,
     344                                             fsp->notify->requests);
    366345        }
    367346}
     
    428407                fsp->notify->num_changes = -1;
    429408                if (fsp->notify->requests != NULL) {
    430                         change_notify_reply(fsp->conn,
    431                                             fsp->notify->requests->req,
     409                        change_notify_reply(fsp->notify->requests->req,
    432410                                            NT_STATUS_OK,
    433411                                            fsp->notify->requests->max_param,
    434412                                            fsp->notify,
    435413                                            fsp->notify->requests->reply_fn);
    436                         change_notify_remove_request(fsp->notify->requests);
     414                        change_notify_remove_request(fsp->conn->sconn,
     415                                                     fsp->notify->requests);
    437416                }
    438417                return;
     
    489468         */
    490469
    491         change_notify_reply(fsp->conn,
    492                             fsp->notify->requests->req,
     470        change_notify_reply(fsp->notify->requests->req,
    493471                            NT_STATUS_OK,
    494472                            fsp->notify->requests->max_param,
     
    496474                            fsp->notify->requests->reply_fn);
    497475
    498         change_notify_remove_request(fsp->notify->requests);
     476        change_notify_remove_request(fsp->conn->sconn, fsp->notify->requests);
    499477}
    500478
Note: See TracChangeset for help on using the changeset viewer.