LCOV - code coverage report
Current view: top level - source3/torture - test_authinfo_structs.c (source / functions) Hit Total Coverage
Test: coverage report for abartlet/fix-coverage dd10fb34 Lines: 100 121 82.6 %
Date: 2021-09-23 10:06:22 Functions: 3 4 75.0 %

          Line data    Source code
       1             : /*
       2             :    Unix SMB/CIFS implementation.
       3             :    Test conversion form struct lsa_TrustDomainInfoAuthInfo to
       4             :    struct trustAuthInOutBlob and back
       5             :    Copyright (C) Sumit Bose 2011
       6             : 
       7             :    This program is free software; you can redistribute it and/or modify
       8             :    it under the terms of the GNU General Public License as published by
       9             :    the Free Software Foundation; either version 3 of the License, or
      10             :    (at your option) any later version.
      11             : 
      12             :    This program is distributed in the hope that it will be useful,
      13             :    but WITHOUT ANY WARRANTY; without even the implied warranty of
      14             :    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      15             :    GNU General Public License for more details.
      16             : 
      17             :    You should have received a copy of the GNU General Public License
      18             :    along with this program.  If not, see <http://www.gnu.org/licenses/>.
      19             : */
      20             : 
      21             : #include "includes.h"
      22             : #include "torture/proto.h"
      23             : #include "librpc/gen_ndr/lsa.h"
      24             : #include "libcli/lsarpc/util_lsarpc.h"
      25             : 
      26           0 : static bool cmp_TrustDomainInfoBuffer(struct lsa_TrustDomainInfoBuffer a,
      27             :                                       struct lsa_TrustDomainInfoBuffer b)
      28             : {
      29          12 :         if (a.last_update_time != b. last_update_time ||
      30          12 :             a.AuthType != b.AuthType ||
      31          12 :             a.data.size != b.data.size ||
      32          12 :             memcmp(a.data.data, b.data.data, a.data.size) !=0) {
      33           0 :                 return false;
      34             :         }
      35             : 
      36           0 :         return true;
      37             : }
      38             : 
      39           5 : static bool cmp_auth_info(struct lsa_TrustDomainInfoAuthInfo *a,
      40             :                           struct lsa_TrustDomainInfoAuthInfo *b)
      41             : {
      42             :         size_t c;
      43             : 
      44          10 :         if (a->incoming_count != b->incoming_count ||
      45           5 :             a->outgoing_count != b->outgoing_count) {
      46           0 :                 return false;
      47             :         }
      48             : 
      49           3 :         for (c = 0; c < a->incoming_count; c++) {
      50           6 :                 if (!cmp_TrustDomainInfoBuffer(a->incoming_current_auth_info[c],
      51           3 :                                                b->incoming_current_auth_info[c])) {
      52           0 :                         return false;
      53             :                 }
      54             : 
      55           4 :                 if (a->incoming_previous_auth_info != NULL &&
      56           1 :                     b->incoming_previous_auth_info != NULL) {
      57           1 :                         if (!cmp_TrustDomainInfoBuffer(a->incoming_previous_auth_info[c],
      58           1 :                                                        b->incoming_previous_auth_info[c])) {
      59           0 :                                 return false;
      60             :                         }
      61           4 :                 } else if (a->incoming_previous_auth_info == NULL &&
      62           2 :                            b->incoming_previous_auth_info == NULL) {
      63           2 :                         continue;
      64             :                 } else {
      65           0 :                         return false;
      66             :                 }
      67             :         }
      68             : 
      69           6 :         for (c = 0; c < a->outgoing_count; c++) {
      70          12 :                 if (!cmp_TrustDomainInfoBuffer(a->outgoing_current_auth_info[c],
      71           6 :                                                b->outgoing_current_auth_info[c])) {
      72           0 :                         return false;
      73             :                 }
      74             : 
      75           8 :                 if (a->outgoing_previous_auth_info != NULL &&
      76           2 :                     b->outgoing_previous_auth_info != NULL) {
      77           2 :                         if (!cmp_TrustDomainInfoBuffer(a->outgoing_previous_auth_info[c],
      78           2 :                                                        b->outgoing_previous_auth_info[c])) {
      79           0 :                                 return false;
      80             :                         }
      81           8 :                 } else if (a->outgoing_previous_auth_info == NULL &&
      82           4 :                            b->outgoing_previous_auth_info == NULL) {
      83           4 :                         continue;
      84             :                 } else {
      85           0 :                         return false;
      86             :                 }
      87             :         }
      88             : 
      89           0 :         return true;
      90             : }
      91             : 
      92           5 : static bool covert_and_compare(struct lsa_TrustDomainInfoAuthInfo *auth_info)
      93             : {
      94             :         NTSTATUS status;
      95             :         TALLOC_CTX *tmp_ctx;
      96             :         DATA_BLOB incoming;
      97             :         DATA_BLOB outgoing;
      98             :         struct lsa_TrustDomainInfoAuthInfo auth_info_out;
      99           5 :         bool result = false;
     100             : 
     101           5 :         tmp_ctx = talloc_new(NULL);
     102           5 :         if (tmp_ctx == NULL) {
     103           0 :                 return false;
     104             :         }
     105             : 
     106           5 :         status = auth_info_2_auth_blob(tmp_ctx, auth_info, &incoming, &outgoing);
     107           5 :         if (!NT_STATUS_IS_OK(status)) {
     108           0 :                 talloc_free(tmp_ctx);
     109           0 :                 return false;
     110             :         }
     111             : 
     112           5 :         status = auth_blob_2_auth_info(tmp_ctx, incoming, outgoing,
     113             :                                        &auth_info_out);
     114           5 :         if (!NT_STATUS_IS_OK(status)) {
     115           0 :                 talloc_free(tmp_ctx);
     116           0 :                 return false;
     117             :         }
     118             : 
     119           5 :         result = cmp_auth_info(auth_info, &auth_info_out);
     120           5 :         talloc_free(tmp_ctx);
     121             : 
     122           5 :         return result;
     123             : }
     124             : 
     125           1 : bool run_local_conv_auth_info(int dummy)
     126             : {
     127             :         struct lsa_TrustDomainInfoAuthInfo auth_info;
     128             :         struct lsa_TrustDomainInfoBuffer ic[1];
     129             :         struct lsa_TrustDomainInfoBuffer ip[1];
     130             :         struct lsa_TrustDomainInfoBuffer oc[2];
     131             :         struct lsa_TrustDomainInfoBuffer op[2];
     132           1 :         uint32_t version = 3;
     133             : 
     134           1 :         ic[0].last_update_time = 12345;
     135           1 :         ic[0].AuthType = TRUST_AUTH_TYPE_CLEAR;
     136           1 :         ic[0].data.size = strlen("iPaSsWoRd");
     137           1 :         ic[0].data.data = discard_const_p(uint8_t, "iPaSsWoRd");
     138             : 
     139           1 :         ip[0].last_update_time = 67890;
     140           1 :         ip[0].AuthType = TRUST_AUTH_TYPE_CLEAR;
     141           1 :         ip[0].data.size = strlen("OlDiPaSsWoRd");
     142           1 :         ip[0].data.data = discard_const_p(uint8_t, "OlDiPaSsWoRd");
     143             : 
     144           1 :         oc[0].last_update_time = 24580;
     145           1 :         oc[0].AuthType = TRUST_AUTH_TYPE_CLEAR;
     146           1 :         oc[0].data.size = strlen("oPaSsWoRd");
     147           1 :         oc[0].data.data = discard_const_p(uint8_t, "oPaSsWoRd");
     148           1 :         oc[1].last_update_time = 24580;
     149           1 :         oc[1].AuthType = TRUST_AUTH_TYPE_VERSION;
     150           1 :         oc[1].data.size = 4;
     151           1 :         oc[1].data.data = (uint8_t *) &version;
     152             : 
     153           1 :         op[0].last_update_time = 13579;
     154           1 :         op[0].AuthType = TRUST_AUTH_TYPE_CLEAR;
     155           1 :         op[0].data.size = strlen("OlDoPaSsWoRd");
     156           1 :         op[0].data.data = discard_const_p(uint8_t, "OlDoPaSsWoRd");
     157           1 :         op[1].last_update_time = 24580;
     158           1 :         op[1].AuthType = TRUST_AUTH_TYPE_VERSION;
     159           1 :         op[1].data.size = 4;
     160           1 :         op[1].data.data = (uint8_t *) &version;
     161             : 
     162           1 :         auth_info.incoming_count = 0;
     163           1 :         auth_info.incoming_current_auth_info = NULL;
     164           1 :         auth_info.incoming_previous_auth_info = NULL;
     165           1 :         auth_info.outgoing_count = 0;
     166           1 :         auth_info.outgoing_current_auth_info = NULL;
     167           1 :         auth_info.outgoing_previous_auth_info = NULL;
     168             : 
     169           1 :         if (!covert_and_compare(&auth_info)) {
     170           0 :                 return false;
     171             :         }
     172             : 
     173           1 :         auth_info.incoming_count = 1;
     174           1 :         auth_info.incoming_current_auth_info = ic;
     175           1 :         auth_info.incoming_previous_auth_info = NULL;
     176           1 :         auth_info.outgoing_count = 0;
     177           1 :         auth_info.outgoing_current_auth_info = NULL;
     178           1 :         auth_info.outgoing_previous_auth_info = NULL;
     179             : 
     180           1 :         if (!covert_and_compare(&auth_info)) {
     181           0 :                 return false;
     182             :         }
     183             : 
     184           1 :         auth_info.incoming_count = 0;
     185           1 :         auth_info.incoming_current_auth_info = NULL;
     186           1 :         auth_info.incoming_previous_auth_info = NULL;
     187           1 :         auth_info.outgoing_count = 2;
     188           1 :         auth_info.outgoing_current_auth_info = oc;
     189           1 :         auth_info.outgoing_previous_auth_info = NULL;
     190             : 
     191           1 :         if (!covert_and_compare(&auth_info)) {
     192           0 :                 return false;
     193             :         }
     194             : 
     195           1 :         auth_info.incoming_count = 1;
     196           1 :         auth_info.incoming_current_auth_info = ic;
     197           1 :         auth_info.incoming_previous_auth_info = NULL;
     198           1 :         auth_info.outgoing_count = 2;
     199           1 :         auth_info.outgoing_current_auth_info = oc;
     200           1 :         auth_info.outgoing_previous_auth_info = NULL;
     201             : 
     202           1 :         if (!covert_and_compare(&auth_info)) {
     203           0 :                 return false;
     204             :         }
     205             : 
     206           1 :         auth_info.incoming_count = 1;
     207           1 :         auth_info.incoming_current_auth_info = ic;
     208           1 :         auth_info.incoming_previous_auth_info = ip;
     209           1 :         auth_info.outgoing_count = 2;
     210           1 :         auth_info.outgoing_current_auth_info = oc;
     211           1 :         auth_info.outgoing_previous_auth_info = op;
     212             : 
     213           1 :         if (!covert_and_compare(&auth_info)) {
     214           0 :                 return false;
     215             :         }
     216             : 
     217           1 :         return true;
     218             : }

Generated by: LCOV version 1.13