LCOV - code coverage report
Current view: top level - source3/modules - hash_inode.c (source / functions) Hit Total Coverage
Test: coverage report for fix-15632 9995c5c2 Lines: 29 36 80.6 %
Date: 2024-04-13 12:30:31 Functions: 1 1 100.0 %

          Line data    Source code
       1             : /*
       2             :  * Unix SMB/Netbios implementation.
       3             :  *
       4             :  * Copyright (c) 2019      Andreas Schneider <asn@samba.org>
       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             : #include "includes.h"
      21             : #include "hash_inode.h"
      22             : 
      23             : #include <gnutls/gnutls.h>
      24             : #include <gnutls/crypto.h>
      25             : #include "lib/crypto/gnutls_helpers.h"
      26             : 
      27        7686 : SMB_INO_T hash_inode(const SMB_STRUCT_STAT *sbuf, const char *sname)
      28        7686 : {
      29        7686 :         gnutls_hash_hd_t hash_hnd = NULL;
      30        7686 :         uint8_t digest[gnutls_hash_get_len(GNUTLS_DIG_SHA1)];
      31        7686 :         char *upper_sname = NULL;
      32        7686 :         SMB_INO_T result = 0;
      33             :         int rc;
      34             : 
      35        7686 :         DBG_DEBUG("hash_inode called for %ju/%ju [%s]\n",
      36             :                   (uintmax_t)sbuf->st_ex_dev,
      37             :                   (uintmax_t)sbuf->st_ex_ino,
      38             :                   sname);
      39             : 
      40        7686 :         upper_sname = talloc_strdup_upper(talloc_tos(), sname);
      41        7686 :         SMB_ASSERT(upper_sname != NULL);
      42             : 
      43        7686 :         GNUTLS_FIPS140_SET_LAX_MODE();
      44             : 
      45        7686 :         rc = gnutls_hash_init(&hash_hnd, GNUTLS_DIG_SHA1);
      46        7686 :         if (rc < 0) {
      47           0 :                 goto out;
      48             :         }
      49             : 
      50        7686 :         rc = gnutls_hash(hash_hnd,
      51        7686 :                          &(sbuf->st_ex_dev),
      52             :                          sizeof(sbuf->st_ex_dev));
      53        7686 :         if (rc < 0) {
      54           0 :                 gnutls_hash_deinit(hash_hnd, NULL);
      55           0 :                 goto out;
      56             :         }
      57        7686 :         rc = gnutls_hash(hash_hnd,
      58        7686 :                          &(sbuf->st_ex_ino),
      59             :                          sizeof(sbuf->st_ex_ino));
      60        7686 :         if (rc < 0) {
      61           0 :                 gnutls_hash_deinit(hash_hnd, NULL);
      62           0 :                 goto out;
      63             :         }
      64        7686 :         rc = gnutls_hash(hash_hnd,
      65             :                          upper_sname,
      66        7686 :                          talloc_get_size(upper_sname) - 1);
      67        7686 :         if (rc < 0) {
      68           0 :                 gnutls_hash_deinit(hash_hnd, NULL);
      69           0 :                 goto out;
      70             :         }
      71             : 
      72        7686 :         gnutls_hash_deinit(hash_hnd, digest);
      73             : 
      74        7686 :         memcpy(&result, digest, sizeof(result));
      75        7686 :         DBG_DEBUG("fruit_inode \"%s\": ino=%ju\n",
      76             :                   sname, (uintmax_t)result);
      77             : 
      78        7686 : out:
      79        7686 :         GNUTLS_FIPS140_SET_STRICT_MODE();
      80        7686 :         TALLOC_FREE(upper_sname);
      81             : 
      82        7686 :         DBG_DEBUG("hash_inode '%s': ino=%ju\n",
      83             :                   sname,
      84             :                   (uintmax_t)result);
      85             : 
      86        7686 :         return result;
      87             : }

Generated by: LCOV version 1.14