2 * Unix SMB/Netbios implementation.
4 * Copyright (c) 2019 Andreas Schneider <asn@samba.org>
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.
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.
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/>.
21 #include "hash_inode.h"
23 #include <gnutls/gnutls.h>
24 #include <gnutls/crypto.h>
25 #include "lib/crypto/gnutls_helpers.h"
27 SMB_INO_T
hash_inode(const SMB_STRUCT_STAT
*sbuf
, const char *sname
)
29 gnutls_hash_hd_t hash_hnd
= NULL
;
30 uint8_t digest
[gnutls_hash_get_len(GNUTLS_DIG_SHA1
)];
31 char *upper_sname
= NULL
;
35 DBG_DEBUG("hash_inode called for %ju/%ju [%s]\n",
36 (uintmax_t)sbuf
->st_ex_dev
,
37 (uintmax_t)sbuf
->st_ex_ino
,
40 upper_sname
= talloc_strdup_upper(talloc_tos(), sname
);
41 SMB_ASSERT(upper_sname
!= NULL
);
43 GNUTLS_FIPS140_SET_LAX_MODE();
45 rc
= gnutls_hash_init(&hash_hnd
, GNUTLS_DIG_SHA1
);
50 rc
= gnutls_hash(hash_hnd
,
52 sizeof(sbuf
->st_ex_dev
));
54 gnutls_hash_deinit(hash_hnd
, NULL
);
57 rc
= gnutls_hash(hash_hnd
,
59 sizeof(sbuf
->st_ex_ino
));
61 gnutls_hash_deinit(hash_hnd
, NULL
);
64 rc
= gnutls_hash(hash_hnd
,
66 talloc_get_size(upper_sname
) - 1);
68 gnutls_hash_deinit(hash_hnd
, NULL
);
72 gnutls_hash_deinit(hash_hnd
, digest
);
74 memcpy(&result
, digest
, sizeof(result
));
75 DBG_DEBUG("fruit_inode \"%s\": ino=%ju\n",
76 sname
, (uintmax_t)result
);
79 GNUTLS_FIPS140_SET_STRICT_MODE();
80 TALLOC_FREE(upper_sname
);
82 DBG_DEBUG("hash_inode '%s': ino=%ju\n",