CVE-2023-3347: CI: add a test for server-side mandatory signing
[Samba.git] / source3 / profile / profile_read.c
blob45a1980773f6aab16497175429f6cdd5ccba5197
1 /*
2 * Unix SMB/CIFS implementation.
3 * store smbd profiling information in shared memory
4 * Copyright (C) Andrew Tridgell 1999
5 * Copyright (C) James Peach 2006
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.
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.
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/>.
21 #include "replace.h"
22 #include <tdb.h>
23 #include <gnutls/gnutls.h>
24 #include <gnutls/crypto.h>
25 #include "lib/crypto/gnutls_helpers.h"
26 #include "lib/util/byteorder.h"
27 #include "source3/include/smbprofile.h"
29 void smbprofile_stats_accumulate(struct profile_stats *acc,
30 const struct profile_stats *add)
32 #define SMBPROFILE_STATS_START
33 #define SMBPROFILE_STATS_SECTION_START(name, display)
34 #define SMBPROFILE_STATS_COUNT(name) \
35 do { \
36 acc->values.name##_stats.count += \
37 add->values.name##_stats.count; \
38 } while (0);
39 #define SMBPROFILE_STATS_TIME(name) \
40 do { \
41 acc->values.name##_stats.time += \
42 add->values.name##_stats.time; \
43 } while (0);
44 #define SMBPROFILE_STATS_BASIC(name) \
45 do { \
46 acc->values.name##_stats.count += \
47 add->values.name##_stats.count; \
48 acc->values.name##_stats.time += \
49 add->values.name##_stats.time; \
50 } while (0);
51 #define SMBPROFILE_STATS_BYTES(name) \
52 do { \
53 acc->values.name##_stats.count += \
54 add->values.name##_stats.count; \
55 acc->values.name##_stats.time += \
56 add->values.name##_stats.time; \
57 acc->values.name##_stats.idle += \
58 add->values.name##_stats.idle; \
59 acc->values.name##_stats.bytes += \
60 add->values.name##_stats.bytes; \
61 } while (0);
62 #define SMBPROFILE_STATS_IOBYTES(name) \
63 do { \
64 acc->values.name##_stats.count += \
65 add->values.name##_stats.count; \
66 acc->values.name##_stats.time += \
67 add->values.name##_stats.time; \
68 acc->values.name##_stats.idle += \
69 add->values.name##_stats.idle; \
70 acc->values.name##_stats.inbytes += \
71 add->values.name##_stats.inbytes; \
72 acc->values.name##_stats.outbytes += \
73 add->values.name##_stats.outbytes; \
74 } while (0);
75 #define SMBPROFILE_STATS_SECTION_END
76 #define SMBPROFILE_STATS_END
77 SMBPROFILE_STATS_ALL_SECTIONS
78 #undef SMBPROFILE_STATS_START
79 #undef SMBPROFILE_STATS_SECTION_START
80 #undef SMBPROFILE_STATS_COUNT
81 #undef SMBPROFILE_STATS_TIME
82 #undef SMBPROFILE_STATS_BASIC
83 #undef SMBPROFILE_STATS_BYTES
84 #undef SMBPROFILE_STATS_IOBYTES
85 #undef SMBPROFILE_STATS_SECTION_END
86 #undef SMBPROFILE_STATS_END
89 int smbprofile_magic(const struct profile_stats *stats, uint64_t *_magic)
91 uint8_t digest[gnutls_hash_get_len(GNUTLS_DIG_SHA1)];
92 gnutls_hash_hd_t hash_hnd = NULL;
93 int rc;
95 GNUTLS_FIPS140_SET_LAX_MODE();
97 rc = gnutls_hash_init(&hash_hnd, GNUTLS_DIG_SHA1);
98 if (rc < 0) {
99 goto out;
101 rc = gnutls_hash(hash_hnd, stats, sizeof(*stats));
103 #define __UPDATE(str) \
104 do { \
105 rc |= gnutls_hash(hash_hnd, str, strlen(str)); \
106 } while (0)
107 #define SMBPROFILE_STATS_START
108 #define SMBPROFILE_STATS_SECTION_START(name, display) \
109 do { \
110 __UPDATE(#name "+" #display); \
111 } while (0);
112 #define SMBPROFILE_STATS_COUNT(name) \
113 do { \
114 __UPDATE(#name "+count"); \
115 } while (0);
116 #define SMBPROFILE_STATS_TIME(name) \
117 do { \
118 __UPDATE(#name "+time"); \
119 } while (0);
120 #define SMBPROFILE_STATS_BASIC(name) \
121 do { \
122 __UPDATE(#name "+count"); \
123 __UPDATE(#name "+time"); \
124 } while (0);
125 #define SMBPROFILE_STATS_BYTES(name) \
126 do { \
127 __UPDATE(#name "+count"); \
128 __UPDATE(#name "+time"); \
129 __UPDATE(#name "+idle"); \
130 __UPDATE(#name "+bytes"); \
131 } while (0);
132 #define SMBPROFILE_STATS_IOBYTES(name) \
133 do { \
134 __UPDATE(#name "+count"); \
135 __UPDATE(#name "+time"); \
136 __UPDATE(#name "+idle"); \
137 __UPDATE(#name "+inbytes"); \
138 __UPDATE(#name "+outbytes"); \
139 } while (0);
140 #define SMBPROFILE_STATS_SECTION_END
141 #define SMBPROFILE_STATS_END
142 SMBPROFILE_STATS_ALL_SECTIONS
143 #undef __UPDATE
144 #undef SMBPROFILE_STATS_START
145 #undef SMBPROFILE_STATS_SECTION_START
146 #undef SMBPROFILE_STATS_COUNT
147 #undef SMBPROFILE_STATS_TIME
148 #undef SMBPROFILE_STATS_BASIC
149 #undef SMBPROFILE_STATS_BYTES
150 #undef SMBPROFILE_STATS_IOBYTES
151 #undef SMBPROFILE_STATS_SECTION_END
152 #undef SMBPROFILE_STATS_END
153 if (rc != 0) {
154 gnutls_hash_deinit(hash_hnd, NULL);
155 goto out;
158 gnutls_hash_deinit(hash_hnd, digest);
159 out:
160 GNUTLS_FIPS140_SET_STRICT_MODE();
162 if (rc == 0) {
163 uint64_t magic = PULL_LE_U64(digest, 0);
164 if (magic == 0) {
165 magic = PULL_LE_U64(digest, 0);
167 *_magic = magic;
170 return rc;
173 static int smbprofile_collect_fn(struct tdb_context *tdb,
174 TDB_DATA key,
175 TDB_DATA value,
176 void *private_data)
178 struct profile_stats *acc = (struct profile_stats *)private_data;
179 const struct profile_stats *v;
181 if (value.dsize != sizeof(struct profile_stats)) {
182 return 0;
185 v = (const struct profile_stats *)value.dptr;
187 if (v->magic != acc->magic) {
188 return 0;
191 smbprofile_stats_accumulate(acc, v);
192 return 0;
195 void smbprofile_collect_tdb(struct tdb_context *tdb,
196 uint64_t magic,
197 struct profile_stats *stats)
199 *stats = (struct profile_stats){.magic = magic};
201 tdb_traverse_read(tdb, smbprofile_collect_fn, stats);