LCOV - code coverage report
Current view: top level - providers/ad - ad_pac_common.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 19 31 61.3 %
Date: 2016-06-29 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :     SSSD
       3             : 
       4             :     Authors:
       5             :         Sumit Bose <sbose@redhat.com>
       6             : 
       7             :     Copyright (C) 2016 Red Hat
       8             : 
       9             :     This program is free software; you can redistribute it and/or modify
      10             :     it under the terms of the GNU General Public License as published by
      11             :     the Free Software Foundation; either version 3 of the License, or
      12             :     (at your option) any later version.
      13             : 
      14             :     This program 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
      17             :     GNU General Public License for more details.
      18             : 
      19             :     You should have received a copy of the GNU General Public License
      20             :     along with this program.  If not, see <http://www.gnu.org/licenses/>.
      21             : */
      22             : 
      23             : 
      24             : #include "providers/ad/ad_pac.h"
      25             : #include "util/util.h"
      26             : 
      27           3 : errno_t ad_get_data_from_pac(TALLOC_CTX *mem_ctx,
      28             :                              uint8_t *pac_blob, size_t pac_len,
      29             :                              struct PAC_LOGON_INFO **_logon_info)
      30             : {
      31             :     DATA_BLOB blob;
      32             :     struct ndr_pull *ndr_pull;
      33             :     struct PAC_DATA *pac_data;
      34             :     enum ndr_err_code ndr_err;
      35             :     size_t c;
      36             :     int ret;
      37             :     TALLOC_CTX *tmp_ctx;
      38             : 
      39           3 :     tmp_ctx = talloc_new(NULL);
      40           3 :     if (tmp_ctx == NULL) {
      41           0 :         DEBUG(SSSDBG_OP_FAILURE, "talloc_new failed.\n");
      42           0 :         return ENOMEM;
      43             :     }
      44             : 
      45           3 :     blob.data = pac_blob;
      46           3 :     blob.length = pac_len;
      47             : 
      48           3 :     ndr_pull = ndr_pull_init_blob(&blob, tmp_ctx);
      49           3 :     if (ndr_pull == NULL) {
      50           0 :         DEBUG(SSSDBG_OP_FAILURE, "ndr_pull_init_blob failed.\n");
      51           0 :         ret = ENOMEM;
      52           0 :         goto done;
      53             :     }
      54           3 :     ndr_pull->flags |= LIBNDR_FLAG_REF_ALLOC; /* FIXME: is this really needed ? */
      55             : 
      56           3 :     pac_data = talloc_zero(tmp_ctx, struct PAC_DATA);
      57           3 :     if (pac_data == NULL) {
      58           0 :         DEBUG(SSSDBG_OP_FAILURE, "talloc_zero failed.\n");
      59           0 :         ret = ENOMEM;
      60           0 :         goto done;
      61             :     }
      62             : 
      63           3 :     ndr_err = ndr_pull_PAC_DATA(ndr_pull, NDR_SCALARS|NDR_BUFFERS, pac_data);
      64           3 :     if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
      65           0 :         DEBUG(SSSDBG_OP_FAILURE, "ndr_pull_PAC_DATA failed [%d]\n", ndr_err);
      66           0 :         ret =  EBADMSG;
      67           0 :         goto done;
      68             :     }
      69             : 
      70           3 :     for(c = 0; c < pac_data->num_buffers; c++) {
      71           3 :         if (pac_data->buffers[c].type == PAC_TYPE_LOGON_INFO) {
      72           3 :             *_logon_info = talloc_steal(mem_ctx,
      73             :                                     pac_data->buffers[c].info->logon_info.info);
      74             : 
      75           3 :             ret = EOK;
      76           3 :             goto done;
      77             :         }
      78             :     }
      79             : 
      80           0 :     ret = EINVAL;
      81             : 
      82             : done:
      83           3 :     talloc_free(tmp_ctx);
      84             : 
      85           3 :     return ret;
      86             : }

Generated by: LCOV version 1.10