LCOV - code coverage report
Current view: top level - librpc/ndr - ndr_ntlmssp.c (source / functions) Hit Total Coverage
Test: coverage report for master 2f515e9b Lines: 69 100 69.0 %
Date: 2024-04-21 15:09:00 Functions: 6 8 75.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             : 
       4             :    routines for marshalling/unmarshalling special ntlmssp structures
       5             : 
       6             :    Copyright (C) Guenther Deschner 2009
       7             : 
       8             :    This program is free software; you can redistribute it and/or modify
       9             :    it under the terms of the GNU General Public License as published by
      10             :    the Free Software Foundation; either version 3 of the License, or
      11             :    (at your option) any later version.
      12             : 
      13             :    This program is distributed in the hope that it will be useful,
      14             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      15             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      16             :    GNU General Public License for more details.
      17             : 
      18             :    You should have received a copy of the GNU General Public License
      19             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      20             : */
      21             : 
      22             : #include "includes.h"
      23             : #include "../librpc/gen_ndr/ndr_ntlmssp.h"
      24             : 
      25          18 : _PUBLIC_ size_t ndr_ntlmssp_string_length(uint32_t negotiate_flags, const char *s)
      26             : {
      27          18 :         if (!s) {
      28           0 :                 return 0;
      29             :         }
      30             : 
      31          12 :         if (negotiate_flags & NTLMSSP_NEGOTIATE_UNICODE) {
      32           8 :                 return strlen(s) * 2;
      33             :         }
      34             : 
      35           4 :         return strlen(s);
      36             : }
      37             : 
      38     1672674 : _PUBLIC_ libndr_flags ndr_ntlmssp_negotiated_string_flags(uint32_t negotiate_flags)
      39             : {
      40     1672674 :         libndr_flags flags = LIBNDR_FLAG_STR_NOTERM |
      41             :                              LIBNDR_FLAG_STR_CHARLEN |
      42             :                              LIBNDR_FLAG_REMAINING;
      43             : 
      44     1672674 :         if (!(negotiate_flags & NTLMSSP_NEGOTIATE_UNICODE)) {
      45          94 :                 flags |= LIBNDR_FLAG_STR_ASCII;
      46             :         }
      47             : 
      48     1672674 :         return flags;
      49             : }
      50             : 
      51       74131 : _PUBLIC_ enum ndr_err_code ndr_push_AV_PAIR_LIST(struct ndr_push *ndr, ndr_flags_type ndr_flags, const struct AV_PAIR_LIST *r)
      52             : {
      53         296 :         uint32_t cntr_pair_0;
      54       74131 :         if (ndr_flags & NDR_SCALARS) {
      55       74131 :                 NDR_CHECK(ndr_push_align(ndr, 4));
      56      659633 :                 for (cntr_pair_0 = 0; cntr_pair_0 < r->count; cntr_pair_0++) {
      57      585502 :                         NDR_CHECK(ndr_push_AV_PAIR(ndr, NDR_SCALARS, &r->pair[cntr_pair_0]));
      58             :                 }
      59             :         }
      60       74131 :         if (ndr_flags & NDR_BUFFERS) {
      61      659633 :                 for (cntr_pair_0 = 0; cntr_pair_0 < r->count; cntr_pair_0++) {
      62      585502 :                         NDR_CHECK(ndr_push_AV_PAIR(ndr, NDR_BUFFERS, &r->pair[cntr_pair_0]));
      63             :                 }
      64             :         }
      65       73835 :         return NDR_ERR_SUCCESS;
      66             : }
      67             : 
      68       81146 : _PUBLIC_ enum ndr_err_code ndr_pull_AV_PAIR_LIST(struct ndr_pull *ndr, ndr_flags_type ndr_flags, struct AV_PAIR_LIST *r)
      69             : {
      70        1436 :         uint32_t cntr_pair_0;
      71        1436 :         TALLOC_CTX *_mem_save_pair_0;
      72       81146 :         if (ndr_flags & NDR_SCALARS) {
      73       81146 :                 uint32_t offset = 0;
      74       81146 :                 NDR_CHECK(ndr_pull_align(ndr, 4));
      75       81146 :                 r->count = 0;
      76       81146 :                 if (ndr->data_size > 0) {
      77       81146 :                         NDR_PULL_NEED_BYTES(ndr, 4);
      78             :                 }
      79      599808 :                 while (offset + 4 <= ndr->data_size) {
      80        5688 :                         uint16_t length;
      81        5688 :                         uint16_t type;
      82      599796 :                         type = SVAL(ndr->data + offset, 0);
      83      599796 :                         if (type == MsvAvEOL) {
      84       81134 :                                 r->count++;
      85       81134 :                                 break;
      86             :                         }
      87      518662 :                         length = SVAL(ndr->data + offset, 2);
      88      518662 :                         offset += length + 4;
      89      518662 :                         r->count++;
      90             :                 }
      91       81146 :                 NDR_PULL_ALLOC_N(ndr, r->pair, r->count);
      92       81146 :                 _mem_save_pair_0 = NDR_PULL_GET_MEM_CTX(ndr);
      93       81146 :                 NDR_PULL_SET_MEM_CTX(ndr, r->pair, 0);
      94      680930 :                 for (cntr_pair_0 = 0; cntr_pair_0 < r->count; cntr_pair_0++) {
      95      599796 :                         NDR_CHECK(ndr_pull_AV_PAIR(ndr, NDR_SCALARS, &r->pair[cntr_pair_0]));
      96             :                 }
      97       81134 :                 NDR_PULL_SET_MEM_CTX(ndr, _mem_save_pair_0, 0);
      98             :         }
      99       81134 :         if (ndr_flags & NDR_BUFFERS) {
     100       81134 :                 _mem_save_pair_0 = NDR_PULL_GET_MEM_CTX(ndr);
     101       81134 :                 NDR_PULL_SET_MEM_CTX(ndr, r->pair, 0);
     102      680918 :                 for (cntr_pair_0 = 0; cntr_pair_0 < r->count; cntr_pair_0++) {
     103      599784 :                         NDR_CHECK(ndr_pull_AV_PAIR(ndr, NDR_BUFFERS, &r->pair[cntr_pair_0]));
     104             :                 }
     105       81134 :                 NDR_PULL_SET_MEM_CTX(ndr, _mem_save_pair_0, 0);
     106             :         }
     107       79700 :         return NDR_ERR_SUCCESS;
     108             : }
     109             : 
     110           0 : _PUBLIC_ void ndr_print_ntlmssp_nt_response(TALLOC_CTX *mem_ctx,
     111             :                                             const DATA_BLOB *nt_response,
     112             :                                             bool ntlmv2)
     113             : {
     114           0 :         enum ndr_err_code ndr_err;
     115             : 
     116           0 :         if (ntlmv2) {
     117           0 :                 struct NTLMv2_RESPONSE nt;
     118           0 :                 if (nt_response->length > 24) {
     119           0 :                         ndr_err = ndr_pull_struct_blob(nt_response, mem_ctx, &nt,
     120             :                                         (ndr_pull_flags_fn_t)ndr_pull_NTLMv2_RESPONSE);
     121           0 :                         if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     122           0 :                                 NDR_PRINT_DEBUG(NTLMv2_RESPONSE, &nt);
     123             :                         }
     124             :                 }
     125             :         } else {
     126           0 :                 struct NTLM_RESPONSE nt;
     127           0 :                 if (nt_response->length == 24) {
     128           0 :                         ndr_err = ndr_pull_struct_blob(nt_response, mem_ctx, &nt,
     129             :                                         (ndr_pull_flags_fn_t)ndr_pull_NTLM_RESPONSE);
     130           0 :                         if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     131           0 :                                 NDR_PRINT_DEBUG(NTLM_RESPONSE, &nt);
     132             :                         }
     133             :                 }
     134             :         }
     135           0 : }
     136             : 
     137           0 : _PUBLIC_ void ndr_print_ntlmssp_lm_response(TALLOC_CTX *mem_ctx,
     138             :                                             const DATA_BLOB *lm_response,
     139             :                                             bool ntlmv2)
     140             : {
     141           0 :         enum ndr_err_code ndr_err;
     142             : 
     143           0 :         if (ntlmv2) {
     144           0 :                 struct LMv2_RESPONSE lm;
     145           0 :                 if (lm_response->length == 24) {
     146           0 :                         ndr_err = ndr_pull_struct_blob(lm_response, mem_ctx, &lm,
     147             :                                         (ndr_pull_flags_fn_t)ndr_pull_LMv2_RESPONSE);
     148           0 :                         if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     149           0 :                                 NDR_PRINT_DEBUG(LMv2_RESPONSE, &lm);
     150             :                         }
     151             :                 }
     152             :         } else {
     153           0 :                 struct LM_RESPONSE lm;
     154           0 :                 if (lm_response->length == 24) {
     155           0 :                         ndr_err = ndr_pull_struct_blob(lm_response, mem_ctx, &lm,
     156             :                                         (ndr_pull_flags_fn_t)ndr_pull_LM_RESPONSE);
     157           0 :                         if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) {
     158           0 :                                 NDR_PRINT_DEBUG(LM_RESPONSE, &lm);
     159             :                         }
     160             :                 }
     161             :         }
     162           0 : }
     163             : 
     164          20 : _PUBLIC_ void ndr_print_ntlmssp_Version(struct ndr_print *ndr, const char *name, const union ntlmssp_Version *r)
     165             : {
     166          14 :         int level;
     167          20 :         level = ndr_print_steal_switch_value(ndr, r);
     168          20 :         switch (level) {
     169          18 :                 case NTLMSSP_NEGOTIATE_VERSION:
     170          18 :                         ndr_print_ntlmssp_VERSION(ndr, name, &r->version);
     171          18 :                 break;
     172             : 
     173           0 :                 default:
     174           0 :                 break;
     175             : 
     176             :         }
     177          20 : }
     178             : 
     179      365519 : _PUBLIC_ struct AV_PAIR *ndr_ntlmssp_find_av(const struct AV_PAIR_LIST *av_list,
     180             :                                              enum ntlmssp_AvId AvId)
     181             : {
     182      365519 :         struct AV_PAIR *res = NULL;
     183      365519 :         uint32_t i = 0;
     184             : 
     185     1756792 :         for (i = 0; i < av_list->count; i++) {
     186     1718792 :                 if (av_list->pair[i].AvId != AvId) {
     187     1391273 :                         continue;
     188             :                 }
     189             : 
     190      325123 :                 res = discard_const_p(struct AV_PAIR, &av_list->pair[i]);
     191      325123 :                 break;
     192             :         }
     193             : 
     194      365519 :         return res;
     195             : }

Generated by: LCOV version 1.14