LCOV - code coverage report
Current view: top level - sss_client/libwbclient - wbc_util_common.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 36 0.0 %
Date: 2016-06-29 Functions: 0 2 0.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    Winbind client asynchronous API, utility functions
       5             : 
       6             :    Copyright (C) Gerald (Jerry) Carter 2007-2008
       7             : 
       8             : 
       9             :    This library is free software; you can redistribute it and/or
      10             :    modify it under the terms of the GNU Lesser General Public
      11             :    License as published by the Free Software Foundation; either
      12             :    version 3 of the License, or (at your option) any later version.
      13             : 
      14             :    This library is distributed in the hope that it will be useful,
      15             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      16             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
      17             :    Library General Public License for more details.
      18             : 
      19             :    You should have received a copy of the GNU Lesser General Public License
      20             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      21             : */
      22             : 
      23             : /* Required Headers */
      24             : 
      25             : #include "libwbclient.h"
      26             : 
      27             : #include "util/util.h"
      28             : 
      29           0 : static void wbcNamedBlobDestructor(void *ptr)
      30             : {
      31           0 :     struct wbcNamedBlob *b = (struct wbcNamedBlob *)ptr;
      32             : 
      33           0 :     while (b->name != NULL) {
      34           0 :         free(discard_const_p(char, b->name));
      35           0 :         free(b->blob.data);
      36           0 :         b += 1;
      37             :     }
      38           0 : }
      39             : 
      40             : /* Initialize a named blob and add to list of blobs */
      41           0 : wbcErr wbcAddNamedBlob(size_t *num_blobs,
      42             :                struct wbcNamedBlob **pblobs,
      43             :                const char *name,
      44             :                uint32_t flags,
      45             :                uint8_t *data,
      46             :                size_t length)
      47             : {
      48           0 :     wbcErr wbc_status = WBC_ERR_UNKNOWN_FAILURE;
      49             :     struct wbcNamedBlob *blobs, *blob;
      50             : 
      51           0 :     if (name == NULL) {
      52           0 :         return WBC_ERR_INVALID_PARAM;
      53             :     }
      54             : 
      55             :     /*
      56             :      * Overallocate the b->name==NULL terminator for
      57             :      * wbcNamedBlobDestructor
      58             :      */
      59           0 :     blobs = (struct wbcNamedBlob *)wbcAllocateMemory(
      60           0 :         *num_blobs + 2, sizeof(struct wbcNamedBlob),
      61             :         wbcNamedBlobDestructor);
      62             : 
      63           0 :     if (blobs == NULL) {
      64           0 :         return WBC_ERR_NO_MEMORY;
      65             :     }
      66             : 
      67           0 :     if (*pblobs != NULL) {
      68           0 :         struct wbcNamedBlob *old = *pblobs;
      69           0 :         memcpy(blobs, old, sizeof(struct wbcNamedBlob) * (*num_blobs));
      70           0 :         if (*num_blobs != 0) {
      71             :             /* end indicator for wbcNamedBlobDestructor */
      72           0 :             old[0].name = NULL;
      73             :         }
      74           0 :         wbcFreeMemory(old);
      75             :     }
      76           0 :     *pblobs = blobs;
      77             : 
      78           0 :     blob = &blobs[*num_blobs];
      79             : 
      80           0 :     blob->name = strdup(name);
      81           0 :     BAIL_ON_PTR_ERROR(blob->name, wbc_status);
      82           0 :     blob->flags = flags;
      83             : 
      84           0 :     blob->blob.length = length;
      85           0 :     blob->blob.data    = (uint8_t *)malloc(length);
      86           0 :     BAIL_ON_PTR_ERROR(blob->blob.data, wbc_status);
      87           0 :     memcpy(blob->blob.data, data, length);
      88             : 
      89           0 :     *num_blobs += 1;
      90           0 :     *pblobs = blobs;
      91           0 :     blobs = NULL;
      92             : 
      93           0 :     wbc_status = WBC_ERR_SUCCESS;
      94             : done:
      95           0 :     wbcFreeMemory(blobs);
      96           0 :     return wbc_status;
      97             : }

Generated by: LCOV version 1.10