LCOV - code coverage report
Current view: top level - source4/ntvfs - ntvfs_util.c (source / functions) Hit Total Coverage
Test: coverage report for master 2b515b7d Lines: 74 91 81.3 %
Date: 2024-02-28 12:06:22 Functions: 9 9 100.0 %

          Line data    Source code
       1             : /* 
       2             :    Unix SMB/CIFS implementation.
       3             :    NTVFS utility code
       4             :    Copyright (C) Stefan Metzmacher 2004
       5             : 
       6             :    This program is free software; you can redistribute it and/or modify
       7             :    it under the terms of the GNU General Public License as published by
       8             :    the Free Software Foundation; either version 3 of the License, or
       9             :    (at your option) any later version.
      10             :    
      11             :    This program is distributed in the hope that it will be useful,
      12             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      13             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      14             :    GNU General Public License for more details.
      15             :    
      16             :    You should have received a copy of the GNU General Public License
      17             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      18             : */
      19             : /*
      20             :   this implements common utility functions that many NTVFS backends may wish to use
      21             : */
      22             : 
      23             : #include "includes.h"
      24             : #include "../lib/util/dlinklist.h"
      25             : #include "ntvfs/ntvfs.h"
      26             : 
      27             : 
      28      828692 : struct ntvfs_request *ntvfs_request_create(struct ntvfs_context *ctx, TALLOC_CTX *mem_ctx,
      29             :                                                     struct auth_session_info *session_info,
      30             :                                                     uint16_t smbpid,
      31             :                                                     struct timeval request_time,
      32             :                                                     void *private_data,
      33             :                                                     void (*send_fn)(struct ntvfs_request *),
      34             :                                                     uint32_t state)
      35             : {
      36           0 :         struct ntvfs_request *req;
      37           0 :         struct ntvfs_async_state *async;
      38             : 
      39      828692 :         req = talloc(mem_ctx, struct ntvfs_request);
      40      828692 :         if (!req) return NULL;
      41      828692 :         req->ctx                     = ctx;
      42      828692 :         req->async_states            = NULL;
      43      828692 :         req->session_info            = session_info;
      44      828692 :         req->smbpid                  = smbpid;
      45      828692 :         req->client_caps             = ctx->client_caps;
      46      828692 :         req->statistics.request_time = request_time;
      47             : 
      48      828692 :         async = talloc(req, struct ntvfs_async_state);
      49      828692 :         if (!async) goto failed;
      50             : 
      51      828692 :         async->state         = state;
      52      828692 :         async->private_data  = private_data;
      53      828692 :         async->send_fn               = send_fn;
      54      828692 :         async->status                = NT_STATUS_INTERNAL_ERROR;
      55      828692 :         async->ntvfs         = NULL;
      56             : 
      57      828692 :         DLIST_ADD(req->async_states, async);
      58             : 
      59      828692 :         return req;
      60           0 : failed:
      61           0 :         talloc_free(req);
      62           0 :         return NULL;
      63             : }
      64             : 
      65      424380 : NTSTATUS ntvfs_async_state_push(struct ntvfs_module_context *ntvfs,
      66             :                                          struct ntvfs_request *req,
      67             :                                          void *private_data,
      68             :                                          void (*send_fn)(struct ntvfs_request *))
      69             : {
      70           0 :         struct ntvfs_async_state *async;
      71             : 
      72      424380 :         async = talloc(req, struct ntvfs_async_state);
      73      424380 :         NT_STATUS_HAVE_NO_MEMORY(async);
      74             : 
      75      424380 :         async->state         = req->async_states->state;
      76      424380 :         async->private_data  = private_data;
      77      424380 :         async->send_fn               = send_fn;
      78      424380 :         async->status                = NT_STATUS_INTERNAL_ERROR;
      79             : 
      80      424380 :         async->ntvfs         = ntvfs;
      81             : 
      82      424380 :         DLIST_ADD(req->async_states, async);
      83             : 
      84      424380 :         return NT_STATUS_OK;
      85             : }
      86             : 
      87      424380 : void ntvfs_async_state_pop(struct ntvfs_request *req)
      88             : {
      89           0 :         struct ntvfs_async_state *async;
      90             : 
      91      424380 :         async = req->async_states;
      92             : 
      93      424380 :         DLIST_REMOVE(req->async_states, async);
      94             : 
      95      424380 :         req->async_states->state  = async->state;
      96      424380 :         req->async_states->status = async->status;
      97             : 
      98      424380 :         talloc_free(async);
      99      424380 : }
     100             : 
     101      220672 : NTSTATUS ntvfs_handle_new(struct ntvfs_module_context *ntvfs,
     102             :                                    struct ntvfs_request *req,
     103             :                                    struct ntvfs_handle **h)
     104             : {
     105      220672 :         if (!ntvfs->ctx->handles.create_new) {
     106           0 :                 return NT_STATUS_NOT_IMPLEMENTED;
     107             :         }
     108      220672 :         return ntvfs->ctx->handles.create_new(ntvfs->ctx->handles.private_data, req, h);
     109             : }
     110             : 
     111      216105 : NTSTATUS ntvfs_handle_set_backend_data(struct ntvfs_handle *h,
     112             :                                                 struct ntvfs_module_context *ntvfs,
     113             :                                                 TALLOC_CTX *private_data)
     114             : {
     115           0 :         struct ntvfs_handle_data *d;
     116      216105 :         bool first_time = h->backend_data?false:true;
     117             : 
     118      216105 :         for (d=h->backend_data; d; d = d->next) {
     119           0 :                 if (d->owner != ntvfs) continue;
     120           0 :                 d->private_data = talloc_steal(d, private_data);
     121           0 :                 return NT_STATUS_OK;
     122             :         }
     123             : 
     124      216105 :         d = talloc(h, struct ntvfs_handle_data);
     125      216105 :         NT_STATUS_HAVE_NO_MEMORY(d);
     126      216105 :         d->owner = ntvfs;
     127      216105 :         d->private_data = talloc_steal(d, private_data);
     128             : 
     129      216105 :         DLIST_ADD(h->backend_data, d);
     130             : 
     131      216105 :         if (first_time) {
     132           0 :                 NTSTATUS status;
     133      216105 :                 status = h->ctx->handles.make_valid(h->ctx->handles.private_data, h);
     134      216105 :                 NT_STATUS_NOT_OK_RETURN(status);
     135             :         }
     136             : 
     137      216105 :         return NT_STATUS_OK;
     138             : }
     139             : 
     140      396552 : void *ntvfs_handle_get_backend_data(struct ntvfs_handle *h,
     141             :                                              struct ntvfs_module_context *ntvfs)
     142             : {
     143           0 :         struct ntvfs_handle_data *d;
     144             : 
     145      396552 :         for (d=h->backend_data; d; d = d->next) {
     146      396552 :                 if (d->owner != ntvfs) continue;
     147      396552 :                 return d->private_data;
     148             :         }
     149             : 
     150           0 :         return NULL;
     151             : }
     152             : 
     153      207163 : void ntvfs_handle_remove_backend_data(struct ntvfs_handle *h,
     154             :                                                struct ntvfs_module_context *ntvfs)
     155             : {
     156           0 :         struct ntvfs_handle_data *d,*n;
     157             : 
     158      411472 :         for (d=h->backend_data; d; d = n) {
     159      204309 :                 n = d->next;
     160      204309 :                 if (d->owner != ntvfs) continue;
     161      204309 :                 DLIST_REMOVE(h->backend_data, d);
     162      204309 :                 talloc_free(d);
     163      204309 :                 d = NULL;
     164             :         }
     165             : 
     166      207163 :         if (h->backend_data) return;
     167             : 
     168             :         /* if there's no backend_data anymore, destroy the handle */
     169      207163 :         h->ctx->handles.destroy(h->ctx->handles.private_data, h);
     170             : }
     171             : 
     172          42 : struct ntvfs_handle *ntvfs_handle_search_by_wire_key(struct ntvfs_module_context *ntvfs,
     173             :                                                               struct ntvfs_request *req,
     174             :                                                               const DATA_BLOB *key)
     175             : {
     176          42 :         if (!ntvfs->ctx->handles.search_by_wire_key) {
     177           0 :                 return NULL;
     178             :         }
     179          42 :         return ntvfs->ctx->handles.search_by_wire_key(ntvfs->ctx->handles.private_data, req, key);
     180             : }
     181             : 
     182        2558 : NTSTATUS ntvfs_set_handle_callbacks(struct ntvfs_context *ntvfs,
     183             :                                              NTSTATUS (*create_new)(void *private_data, struct ntvfs_request *req, struct ntvfs_handle **h),
     184             :                                              NTSTATUS (*make_valid)(void *private_data, struct ntvfs_handle *h),
     185             :                                              void (*destroy)(void *private_data, struct ntvfs_handle *h),
     186             :                                              struct ntvfs_handle *(*search_by_wire_key)(void *private_data, struct ntvfs_request *req, const DATA_BLOB *key),
     187             :                                              DATA_BLOB (*get_wire_key)(void *private_data, struct ntvfs_handle *handle, TALLOC_CTX *mem_ctx),
     188             :                                              void *private_data)
     189             : {
     190        2558 :         ntvfs->handles.create_new            = create_new;
     191        2558 :         ntvfs->handles.make_valid            = make_valid;
     192        2558 :         ntvfs->handles.destroy                       = destroy;
     193        2558 :         ntvfs->handles.search_by_wire_key    = search_by_wire_key;
     194        2558 :         ntvfs->handles.get_wire_key          = get_wire_key;
     195        2558 :         ntvfs->handles.private_data          = private_data;
     196        2558 :         return NT_STATUS_OK;
     197             : }

Generated by: LCOV version 1.14