Debian Codegraph @

src/do_md.c

raw symbols SCIP
1 /*
2 * AIDE (Advanced Intrusion Detection Environment)
3 *
4 * Copyright (C) 1999-2002, 2004-2006, 2009-2011, 2013, 2018-2025 Rami Lehti,
5 * Pablo Virolainen, Mike Markley, Richard van den Berg,
6 * Hannes von Haugwitz
7 *
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License as
10 * published by the Free Software Foundation; either version 2 of the
11 * License, or (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21 */
22
23 #include "config.h"cxx . . $ `<file>/include/config.h`/
24 #include "db_disk.h"cxx . . $ `<file>/include/db_disk.h`/
25 #include <stdbool.h>
26
27 #include <limits.h>
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31 #include <errno.h>
32 #include <sys/stat.h>
33 #include <fcntl.h>
34 #include <unistd.h>
35 #include <sys/mman.h>
36 #include <sys/wait.h>
37
38 #ifdef WITH_ZLIBcxx . . $ `include/config.h:266:9`!
39 #include <zlib.h>
40 #endif
41
42 #ifdef WITH_XATTR
43 #include <sys/xattr.h>
44 #include <attr/attributes.h>
45 #endif
46 #ifdef WITH_SELINUX
47 #include <selinux/selinux.h>
48 #endif
49 #ifdef WITH_POSIX_ACL
50 #include <sys/acl.h>
51 #endif
52 #ifdef WITH_E2FSATTRS
53 #include <e2p/e2p.h>
54 #endif
55 #ifdef HAVE_SYS_PRCTL_Hcxx . . $ `include/config.h:116:9`!
56 #include <sys/prctl.h>
57 #endif
58
59 #ifdef WITH_CAPABILITIES
60 #include <sys/capability.h>
61 #endif
62
63
64 #include "md.h"cxx . . $ `<file>/include/md.h`/
65 #include "do_md.h"cxx . . $ `<file>/include/do_md.h`/
66
67 #include "hashsum.h"cxx . . $ `<file>/include/hashsum.h`/
68 #include "db_line.h"cxx . . $ `<file>/include/db_line.h`/
69 #include "db_config.h"cxx . . $ `<file>/include/db_config.h`/
70 #include "util.h"cxx . . $ `<file>/include/util.h`/
71 #include "log.h"cxx . . $ `<file>/include/log.h`/
72 #include "attributes.h"cxx . . $ `<file>/include/attributes.h`/
73
74 /* This define should be somewhere else */
75 #define READ_BLOCK_SIZEcxx . . $ `src/do_md.c:75:9`! 16777216
76
77 typedef union fdcxx . . $ fd# {
78 int plaincxx . . $ fd#plain.;
79 #ifdef WITH_ZLIBcxx . . $ `./include/config.h:266:9`!
80 gzFilecxx . . $ gzFile# gzipcxx . . $ fd#gzip.;
81 #endif
82 } _fdcxx . . $ _fd#;
83
84 typedef enum compressioncxx . . $ compression# {
85 COMPRESSION_PLAINcxx . . $ COMPRESSION_PLAIN.,
86 #ifdef WITH_ZLIBcxx . . $ `./include/config.h:266:9`!
87 COMPRESSION_GZIPcxx . . $ COMPRESSION_GZIP.,
88 #endif
89 COMPRESSION_ERRORcxx . . $ COMPRESSION_ERROR.
90 } compressioncxx . . $ compression#;
91
92 typedef struct hashsums_filecxx . . $ hashsums_file# {
93 _fdcxx . . $ _fd# fdcxx . . $ hashsums_file#fd.;
94 compressioncxx . . $ compression# compressioncxx . . $ hashsums_file#compression.;
95 } hashsums_filecxx . . $ hashsums_file#;
96
97 int stat_cmpcxx . . $ stat_cmp(5f41c328ced4dd81).(struct statcxx . . $ stat#* f1,struct statcxx . . $ stat#* f2, boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! growing) {
98 if (f1==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`! || f2==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) {
99 return RETFAILcxx . . $ `include/db_config.h:46:9`!;
100 }
101 #define stat_cmp_helpercxx . . $ `src/do_md.c:101:9`!(n,attribute) ((f1->n!=f2->n)*ATTRcxx . . $ `include/attributes.h:28:9`!(attribute))
102
103 #define stat_growing_cmp_helpercxx . . $ `src/do_md.c:103:9`!(n,attribute) ((growing?f1->n<f2->n:f1->n!=f2->n)*ATTRcxx . . $ `include/attributes.h:28:9`!(attribute))
104
105 return (stat_cmp_helpercxx . . $ `src/do_md.c:101:9`!(st_ino,attr_inode)|
106 stat_cmp_helpercxx . . $ `src/do_md.c:101:9`!(st_mode,attr_perm)|
107 stat_cmp_helpercxx . . $ `src/do_md.c:101:9`!(st_nlink,attr_linkcount)|
108 stat_growing_cmp_helpercxx . . $ `src/do_md.c:103:9`!(st_size,attr_size)|
109 stat_growing_cmp_helpercxx . . $ `src/do_md.c:103:9`!(st_mtimecxx . . $ `<external>/16045971866008360577/struct_stat.h:78:11`!,attr_mtime)|
110 stat_growing_cmp_helpercxx . . $ `src/do_md.c:103:9`!(st_ctimecxx . . $ `<external>/16045971866008360577/struct_stat.h:79:11`!,attr_ctime)|
111 stat_growing_cmp_helpercxx . . $ `src/do_md.c:103:9`!(st_blocks,attr_bcount)|
112 stat_cmp_helpercxx . . $ `src/do_md.c:101:9`!(st_blksize,attr_bsize)|
113 stat_cmp_helpercxx . . $ `src/do_md.c:101:9`!(st_rdev,attr_rdev)|
114 stat_cmp_helpercxx . . $ `src/do_md.c:101:9`!(st_gid,attr_gid)|
115 stat_cmp_helpercxx . . $ `src/do_md.c:101:9`!(st_uid,attr_uid)|
116 stat_cmp_helpercxx . . $ `src/do_md.c:101:9`!(st_dev,attr_dev));
117 }
118
119 static hashsums_filecxx . . $ hashsums_file# hashsum_opencxx . . $ hashsum_open(c1d1d95fdf4d963f).(int filedes, char* fullpath, boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! uncompress, const char *whoami) {
120 hashsums_filecxx . . $ hashsums_file# file;
121
122 if (uncompress) {
123 char head[2];
124 char *magic_gzip = "\037\213";
125 ssize_tcxx . . $ ssize_t# magic_length = strlencxx . . $ strlen(751346f8406fd082).(magic_gzip);
126 ssize_tcxx . . $ ssize_t# bytes = readcxx . . $ read(7e34d0a36f355389).(filedes, head, magic_length);
127 if (bytes == magic_length && strncmpcxx . . $ strncmp(fd278af2f295fa2e).(head, magic_gzip, magic_length) == 0) {
128 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_COMPARE, "│ '%s' is gzip compressed", fullpath);
129 lseekcxx . . $ lseek(f1afe674ac17c82e).(filedes, 0, SEEK_SETcxx . . $ `<external>/14710646456994434043/fcntl.h:137:10`!);
130 #ifdef WITH_ZLIBcxx . . $ `./include/config.h:266:9`!
131 int dupfd = dupcxx . . $ dup(7864480464b09eea).(filedes);
132 if (dupfd == -1) {
133 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_NOTICEcxx . . $ LOG_LEVEL_NOTICE., "'%s': failed to duplicate file descriptor: %s", fullpath, strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
134 file.compressioncxx . . $ hashsums_file#compression. = COMPRESSION_ERRORcxx . . $ COMPRESSION_ERROR.;
135 return file;
136 }
137 file.fdcxx . . $ hashsums_file#fd..gzipcxx . . $ fd#gzip. = gzdopencxx . . $ gzdopen(22355c0c2644e5c0).(dupfd, "rb");
138 if (file.fdcxx . . $ hashsums_file#fd..gzipcxx . . $ fd#gzip. == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!){
139 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "hash calculation: gzdopen() failed for %s (uncompressed hashsums could not be calculated)", fullpath);
140 closecxx . . $ close(7864480464b09eea).(dupfd);
141 file.compressioncxx . . $ hashsums_file#compression. = COMPRESSION_ERRORcxx . . $ COMPRESSION_ERROR.;
142 return file;
143 }
144 file.compressioncxx . . $ hashsums_file#compression. = COMPRESSION_GZIPcxx . . $ COMPRESSION_GZIP.;
145 return file;
146 #else
147 log_msg(LOG_LEVEL_WARNING, "'%s': gzip support not compiled in, recompile AIDE with '--with-zlib' (uncompressed hashsums could not be calculated)", fullpath);
148 file.compression = COMPRESSION_ERROR;
149 return file;
150 #endif
151 } else {
152 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_NOTICEcxx . . $ LOG_LEVEL_NOTICE., "'%s': no supported compression algorithm found (uncompressed hashsums could not be calculated)", fullpath);
153 file.compressioncxx . . $ hashsums_file#compression. = COMPRESSION_ERRORcxx . . $ COMPRESSION_ERROR.;
154 return file;
155 }
156 } else {
157 file.fdcxx . . $ hashsums_file#fd..plaincxx . . $ fd#plain. = filedes;
158 file.compressioncxx . . $ hashsums_file#compression. = COMPRESSION_PLAINcxx . . $ COMPRESSION_PLAIN.;
159 return file;
160 }
161 }
162
163 static off_tcxx . . $ off_t# hashsum_readcxx . . $ hashsum_read(ffff35585c90ab7f).(hashsums_filecxx . . $ hashsums_file# file, void *buf, size_tcxx . . $ size_t# count) {
164 off_tcxx . . $ off_t# size = -1;
165 do {
166 switch (file.compressioncxx . . $ hashsums_file#compression.) {
167 case COMPRESSION_PLAINcxx . . $ COMPRESSION_PLAIN.:
168 size = readcxx . . $ read(7e34d0a36f355389).(file.fdcxx . . $ hashsums_file#fd..plaincxx . . $ fd#plain., buf, count);
169 break;
170 #ifdef WITH_ZLIBcxx . . $ `./include/config.h:266:9`!
171 case COMPRESSION_GZIPcxx . . $ COMPRESSION_GZIP.:
172 size = gzreadcxx . . $ gzread(b1e9eeeff73a5af4).(file.fdcxx . . $ hashsums_file#fd..gzipcxx . . $ fd#gzip., buf, count);
173 break;
174 #endif
175 case COMPRESSION_ERRORcxx . . $ COMPRESSION_ERROR.:
176 size = -2;
177 break;
178 }
179 } while (size == -1 && errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! == EINTRcxx . . $ `<external>/8987895939074593727/errno-base.h:8:9`!); /* retry on EINTR */
180 return size;
181 }
182
183 static int hashsum_closecxx . . $ hashsum_close(efa96f0ecd6fdeb6).(hashsums_filecxx . . $ hashsums_file# file) {
184 switch (file.compressioncxx . . $ hashsums_file#compression.) {
185 case COMPRESSION_PLAINcxx . . $ COMPRESSION_PLAIN.:
186 return 0;
187 #ifdef WITH_ZLIBcxx . . $ `./include/config.h:266:9`!
188 case COMPRESSION_GZIPcxx . . $ COMPRESSION_GZIP.:
189 return gzclosecxx . . $ gzclose(4d4947b8d23ad0c4).(file.fdcxx . . $ hashsums_file#fd..gzipcxx . . $ fd#gzip.);
190 #endif
191 case COMPRESSION_ERRORcxx . . $ COMPRESSION_ERROR.:
192 return -1;
193 }
194 return -1;
195 }
196
197 md_hashsumscxx . . $ md_hashsums# calc_hashsumscxx . . $ calc_hashsums(e5558d7452ce5e04).(disk_entrycxx . . $ disk_entry# *entry, DB_ATTR_TYPEcxx . . $ `include/attributes.h:25:9`! attr, ssize_tcxx . . $ ssize_t# limit_size, boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! uncompress, const char *whoami) {
198 md_hashsumscxx . . $ md_hashsums# md_hash;
199 md_hash.attrscxx . . $ md_hashsums#attrs. = 0LU;
200
201 if (lseekcxx . . $ lseek(f1afe674ac17c82e).(entry->fdcxx . . $ disk_entry#fd., 0, SEEK_SETcxx . . $ `<external>/14710646456994434043/fcntl.h:137:10`!) == -1) {
202 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "hash calculation: lseek() failed to failed for '%s': %s (hashsum could not be calculated)", entry->filenamecxx . . $ disk_entry#filename., strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
203 return md_hash;
204 }
205 #ifdef HAVE_POSIX_FADVISEcxx . . $ `./include/config.h:65:9`!
206 if (posix_fadvisecxx . . $ posix_fadvise(649bf24d9437f04).(entry->fdcxx . . $ disk_entry#fd.,0,entry->fscxx . . $ disk_entry#fs..st_sizecxx . . $ stat#st_size.,POSIX_FADV_SEQUENTIALcxx . . $ `<external>/14578502075116107718/fcntl-linux.h:324:10`!)!=0) {
207 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "%s> calc_hashsums: posix_fadvise error: %s", entry->filename, strerror(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
208 }
209 #endif
210 hashsums_filecxx . . $ hashsums_file# file = hashsum_opencxx . . $ hashsum_open(c1d1d95fdf4d963f).(entry->fdcxx . . $ disk_entry#fd., entry->filenamecxx . . $ disk_entry#filename., uncompress, whoami);
211 if (file.compressioncxx . . $ hashsums_file#compression. == COMPRESSION_ERRORcxx . . $ COMPRESSION_ERROR.) {
212 return md_hash;
213 }
214
215 off_tcxx . . $ off_t# r_size=0;
216 off_tcxx . . $ off_t# size=0;
217 char* buf;
218
219 struct md_containercxx . . $ md_container# mdc;
220 mdc.todo_attrcxx . . $ md_container#todo_attr. = attr;
221 if (init_mdcxx . . $ init_md(74d27db1f5e1726).(&mdc, entry->filenamecxx . . $ disk_entry#filename., whoami)==RETOKcxx . . $ `include/db_config.h:45:9`!) {
222 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "%s> calculate hashes", entry->filename);
223 buf=checked_malloccxx . . $ checked_malloc(bfcfa4d6b7f7ef64).(READ_BLOCK_SIZEcxx . . $ `src/do_md.c:75:9`!);
224 #if READ_BLOCK_SIZEcxx . . $ `src/do_md.c:75:9`!>SSIZE_MAXcxx . . $ `<external>/2534844627595019613/posix1_lim.h:169:11`!
225 #error "READ_BLOCK_SIZE" is too large. Max value is SSIZE_MAX, and current is READ_BLOCK_SIZE
226 #endif
227 while ((size = hashsum_readcxx . . $ hashsum_read(ffff35585c90ab7f).(file,buf,READ_BLOCK_SIZEcxx . . $ `src/do_md.c:75:9`!)) > 0) {
228
229 off_tcxx . . $ off_t# update_md_size;
230 if (limit_size > 0 && r_size+size > limit_size) {
231 /* the last read exceeded limited size */
232 update_md_size = limit_size-r_size;
233 } else if(attr&ATTRcxx . . $ `include/attributes.h:28:9`!(attr_growing) && r_size+size > entry->fscxx . . $ disk_entry#fs..st_sizecxx . . $ stat#st_size.) {
234 update_md_size = entry->fscxx . . $ disk_entry#fs..st_sizecxx . . $ stat#st_size.-r_size;
235 } else {
236 update_md_size = size;
237 }
238
239 if (update_mdcxx . . $ update_md(29e99b095fc90fd4).(&mdc,buf,update_md_size)!=RETOKcxx . . $ `include/db_config.h:45:9`!) {
240 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "hash calculation: update_md() failed for '%s' (hashsums could not be calculated)", entry->filenamecxx . . $ disk_entry#filename.);
241 freecxx . . $ free(5d22bdacc48458e8).(buf);
242 hashsum_closecxx . . $ hashsum_close(efa96f0ecd6fdeb6).(file);
243 close_mdcxx . . $ close_md(e2d4d3ac7f8219a9).(&mdc, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, entry->filenamecxx . . $ disk_entry#filename., whoami);
244 return md_hash;
245 }
246 r_size+=update_md_size;
247 if (limit_size > 0 && r_size == limit_size) {
248 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "hash calculation: limited size (%zi) reached for '%s'", limit_size, entry->filename);
249 break;
250 } else if (attr&ATTRcxx . . $ `include/attributes.h:28:9`!(attr_growing) && r_size == entry->fscxx . . $ disk_entry#fs..st_sizecxx . . $ stat#st_size.) {
251 LOG_WHOAMIcxx . . $ `include/log.h:73:9`!(LOG_LEVEL_DEBUG, "hash calculation: stat size (%zi) reached for growing file '%s'", entry->fs.st_size, entry->filename);
252 break;
253 }
254 }
255 freecxx . . $ free(5d22bdacc48458e8).(buf);
256 hashsum_closecxx . . $ hashsum_close(efa96f0ecd6fdeb6).(file);
257 if (size == -1) {
258 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "hash calculation: failed to read file content of '%s': %s (hashsums could not be calculated)", entry->filenamecxx . . $ disk_entry#filename., strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
259 close_mdcxx . . $ close_md(e2d4d3ac7f8219a9).(&mdc, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, entry->filenamecxx . . $ disk_entry#filename., whoami);
260 return md_hash;
261 }
262
263 struct statcxx . . $ stat# new_fs;
264 if (fstatcxx . . $ fstat(a43660ce2f600cb5).(entry->fdcxx . . $ disk_entry#fd.,&new_fs) != 0) {
265 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "hash calculation: fstat() failed for '%s': %s (hashsums could not be calculated)", entry->filenamecxx . . $ disk_entry#filename., strerrorcxx . . $ strerror(ff224f080444ee45).(errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`!));
266 close_mdcxx . . $ close_md(e2d4d3ac7f8219a9).(&mdc, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, entry->filenamecxx . . $ disk_entry#filename., whoami);
267 return md_hash;
268 }
269 if(!(attr&ATTRcxx . . $ `include/attributes.h:28:9`!(attr_rdev))) {
270 new_fs.st_rdevcxx . . $ stat#st_rdev.=0;
271 }
272 int stat_diff;
273 if ((stat_diff = stat_cmpcxx . . $ stat_cmp(5f41c328ced4dd81).(&new_fs, &entry->fscxx . . $ disk_entry#fs., attr&ATTRcxx . . $ `include/attributes.h:28:9`!(attr_growing))) != RETOKcxx . . $ `include/db_config.h:45:9`!) {
274 DB_ATTR_TYPEcxx . . $ `include/attributes.h:25:9`! changed_attribures = 0ULL;
275 for(ATTRIBUTEcxx . . $ ATTRIBUTE# i=0;i<num_attrscxx . . $ num_attrs.;i++) {
276 if (((1LLU<<i)&stat_diff)!=0) {
277 changed_attribures |= 1LLU<<i;
278 }
279 }
280
281 char *attrs_str = diff_attributescxx . . $ diff_attributes(39cd1df6f24d7ad6).(0, changed_attribures);
282 # define WARN_COMMON_FORMATcxx . . $ `src/do_md.c:282:22`! "'%s' has changed (changed fields: %s%s) during hash calculation"
283 if (new_fs.st_sizecxx . . $ stat#st_size. < entry->fscxx . . $ disk_entry#fs..st_sizecxx . . $ stat#st_size.) {
284 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., WARN_COMMON_FORMATcxx . . $ `src/do_md.c:282:22`! ", was file truncated while AIDE was running? (discarding calculated hashsums)", entry->filenamecxx . . $ disk_entry#filename., attrs_str,", decreased size");
285 } else if (new_fs.st_sizecxx . . $ stat#st_size. > entry->fscxx . . $ disk_entry#fs..st_sizecxx . . $ stat#st_size.) {
286 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., WARN_COMMON_FORMATcxx . . $ `src/do_md.c:282:22`! ", was file growing while AIDE was running? (consider adding 'growing' attribute) (discarding calculated hashsums)", entry->filenamecxx . . $ disk_entry#filename., attrs_str, ", increased size");
287 } else {
288 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., WARN_COMMON_FORMATcxx . . $ `src/do_md.c:282:22`! " (discarding calculated hashsums)", entry->filenamecxx . . $ disk_entry#filename., attrs_str, "");
289 }
290 freecxx . . $ free(5d22bdacc48458e8).(attrs_str);
291 close_mdcxx . . $ close_md(e2d4d3ac7f8219a9).(&mdc, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, entry->filenamecxx . . $ disk_entry#filename., whoami);
292 return md_hash;
293 }
294 if (uncompress == falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!) {
295 long long target_size = limit_size > 0?limit_size: entry->fscxx . . $ disk_entry#fs..st_sizecxx . . $ stat#st_size.;
296 if (r_size != target_size) {
297 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "number of bytes read for hash calculation (%lld) mismatches expected %s size (%lld) for '%s' (discarding calculated hashsums)",
298 (long long) r_size,
299 limit_size > 0?"limited":"stat",
300 target_size,
301 entry->filenamecxx . . $ disk_entry#filename.
302 );
303 close_mdcxx . . $ close_md(e2d4d3ac7f8219a9).(&mdc, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, entry->filenamecxx . . $ disk_entry#filename., whoami);
304 return md_hash;
305 }
306 }
307 close_mdcxx . . $ close_md(e2d4d3ac7f8219a9).(&mdc, &md_hash, entry->filenamecxx . . $ disk_entry#filename., whoami);
308 return md_hash;
309 } else {
310 log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "hash calculation: init_md() failed for '%s' (hashsums could not be calculated)", entry->filenamecxx . . $ disk_entry#filename.);
311 hashsum_closecxx . . $ hashsum_close(efa96f0ecd6fdeb6).(file);
312 return md_hash;
313 }
314 }
315
316 void fs2db_linecxx . . $ fs2db_line(42bac3c81d5693f6).(struct statcxx . . $ stat#* fs,db_linecxx . . $ db_line#* line) {
317
318 /* inode is always needed for ignoring changed filename */
319 line->inodecxx . . $ db_line#inode.=fs->st_inocxx . . $ stat#st_ino.;
320
321 if(ATTRcxx . . $ `include/attributes.h:28:9`!(attr_uid)&line->attrcxx . . $ db_line#attr.) {
322 line->uidcxx . . $ db_line#uid.=fs->st_uidcxx . . $ stat#st_uid.;
323 }else {
324 line->uidcxx . . $ db_line#uid.=0;
325 }
326
327 if(ATTRcxx . . $ `include/attributes.h:28:9`!(attr_gid)&line->attrcxx . . $ db_line#attr.){
328 line->gidcxx . . $ db_line#gid.=fs->st_gidcxx . . $ stat#st_gid.;
329 }else{
330 line->gidcxx . . $ db_line#gid.=0;
331 }
332
333 /* permissions are always needed for file type detection */
334 line->permcxx . . $ db_line#perm.=fs->st_modecxx . . $ stat#st_mode.;
335
336 if(ATTRcxx . . $ `include/attributes.h:28:9`!(attr_size)&line->attrcxx . . $ db_line#attr.
337 || ATTRcxx . . $ `include/attributes.h:28:9`!(attr_sizeg)&line->attrcxx . . $ db_line#attr.
338 || (ATTRcxx . . $ `include/attributes.h:28:9`!(attr_growing)&line->attrcxx . . $ db_line#attr. && line->attrcxx . . $ db_line#attr.&get_hashescxx . . $ get_hashes(48b6f722ee11d9bd).(truecxx . . $ `<external>/13015445228558014418/stdbool.h:37:9`!))
339 ){
340 line->sizecxx . . $ db_line#size.=fs->st_sizecxx . . $ stat#st_size.;
341 }else{
342 line->sizecxx . . $ db_line#size.=0;
343 }
344
345 if(ATTRcxx . . $ `include/attributes.h:28:9`!(attr_linkcount)&line->attrcxx . . $ db_line#attr.){
346 line->nlinkcxx . . $ db_line#nlink.=fs->st_nlinkcxx . . $ stat#st_nlink.;
347 }else {
348 line->nlinkcxx . . $ db_line#nlink.=0;
349 }
350
351 if(ATTRcxx . . $ `include/attributes.h:28:9`!(attr_mtime)&line->attrcxx . . $ db_line#attr.){
352 line->mtimecxx . . $ db_line#mtime.=fs->st_mtimecxx . . $ `<external>/16045971866008360577/struct_stat.h:78:11`!;
353 }else{
354 line->mtimecxx . . $ db_line#mtime.=0;
355 }
356
357 if(ATTRcxx . . $ `include/attributes.h:28:9`!(attr_ctime)&line->attrcxx . . $ db_line#attr.){
358 line->ctimecxx . . $ db_line#ctime.=fs->st_ctimecxx . . $ `<external>/16045971866008360577/struct_stat.h:79:11`!;
359 }else{
360 line->ctimecxx . . $ db_line#ctime.=0;
361 }
362
363 if(ATTRcxx . . $ `include/attributes.h:28:9`!(attr_atime)&line->attrcxx . . $ db_line#attr.){
364 line->atimecxx . . $ db_line#atime.=fs->st_atimecxx . . $ `<external>/16045971866008360577/struct_stat.h:77:11`!;
365 }else{
366 line->atimecxx . . $ db_line#atime.=0;
367 }
368
369 if(ATTRcxx . . $ `include/attributes.h:28:9`!(attr_bcount)&line->attrcxx . . $ db_line#attr.){
370 line->bcountcxx . . $ db_line#bcount.=fs->st_blockscxx . . $ stat#st_blocks.;
371 } else {
372 line->bcountcxx . . $ db_line#bcount.=0;
373 }
374
375 }
376
377 #ifdef WITH_ACL
378 void acl2line(db_line* line, int fd, const char *whoami) {
379 acl_type *ret = NULL;
380
381 #ifdef WITH_POSIX_ACL
382 if(ATTR(attr_acl)&line->attr) {
383 acl_t acl_a = NULL;
384 acl_t acl_d = NULL;
385 char *tmp = NULL;
386 #ifdef O_PATH
387 char proc_self_path[256];
388 #endif
389
390 acl_a = acl_get_fd(fd);
391 #ifdef O_PATH
392 int fd_flags = fcntl(fd, F_GETFL);
393 if (acl_a == NULL && errno == EBADF && fd_flags != -1 && fd_flags&O_PATH) {
394 snprintf(proc_self_path, sizeof(proc_self_path), "/proc/self/fd/%d", fd);
395 LOG_WHOAMI(LOG_LEVEL_DEBUG,"%s> acl_get_fd() failed: Bad file descriptor (emulating O_PATH support via '%s')", line->fullpath, proc_self_path);
396 acl_a = acl_get_file(proc_self_path, ACL_TYPE_ACCESS);
397 }
398 #endif
399 if (acl_a == NULL) {
400 switch (errno) {
401 case ENOSYS:
402 case ENOTSUP:
403 LOG_WHOAMI(LOG_LEVEL_DEBUG, "%s> acl_get_fd() failed to get ACL: %s (disabling acl attribute)", line->fullpath, strerror(errno));
404 break;
405 default:
406 log_msg(LOG_LEVEL_WARNING, "acl_get_fd() failed to get ACL for '%s': %s (disabling acl attribute)", line->fullpath, strerror(errno));
407 }
408 line->attr&=(~ATTR(attr_acl));
409 return;
410 }
411 #ifdef O_PATH
412 if (S_ISDIR(line->perm)) {
413 snprintf(proc_self_path, sizeof(proc_self_path), "/proc/self/fd/%d", fd);
414 acl_d = acl_get_file(proc_self_path, ACL_TYPE_DEFAULT);
415 if (acl_d == NULL) {
416 log_msg(LOG_LEVEL_WARNING, "failed to get default ACL for directory '%s': %s (disabling acl attribute)", line->fullpath, strerror(errno));
417 acl_free(acl_a);
418 line->attr&=(~ATTR(attr_acl));
419 return;
420 }
421 }
422 #endif
423
424 ret = checked_malloc(sizeof(acl_type));
425
426 /* use tmp, so free() can be called instead of acl_free() */
427 tmp = acl_to_text(acl_a, NULL);
428 if (!tmp || !*tmp)
429 ret->acl_a = NULL;
430 else
431 ret->acl_a = checked_strdup(tmp);
432 acl_free(tmp);
433
434 if (!acl_d)
435 ret->acl_d = NULL;
436 else
437 {
438 tmp = acl_to_text(acl_d, NULL);
439 if (!tmp || !*tmp)
440 ret->acl_d = NULL;
441 else
442 ret->acl_d = checked_strdup(tmp);
443 acl_free(tmp);
444 }
445
446 acl_free(acl_a);
447 acl_free(acl_d);
448 }
449 line->acl = ret;
450 #endif
451 }
452 #endif
453
454 #ifdef WITH_XATTR
455 static xattrs_type *xattr_new(void) {
456 xattrs_type *ret = NULL;
457
458 ret = checked_malloc(sizeof(xattrs_type));
459 ret->num = 0;
460 ret->sz = 2;
461 ret->ents = checked_malloc(sizeof(xattr_node) * ret->sz);
462
463 return (ret);
464 }
465
466 static void *xzmemdup(const void *ptr, size_t len) {
467 /* always keeps a 0 at the end... */
468 void *ret = NULL;
469
470 ret = checked_malloc(len+1);
471 memcpy(ret, ptr, len);
472 ((char*)ret)[len] = 0;
473
474 return (ret);
475 }
476
477 static void xattr_add(xattrs_type *xattrs, const char *key, const char
478 *val, size_t vsz) {
479 if (xattrs->num >= xattrs->sz) {
480 xattrs->sz <<= 1;
481 xattrs->ents = checked_realloc(xattrs->ents, sizeof(xattr_node) * xattrs->sz);
482 }
483
484 xattrs->ents[xattrs->num].key = checked_strdup(key);
485 xattrs->ents[xattrs->num].val = xzmemdup(val, vsz);
486 xattrs->ents[xattrs->num].vsz = vsz;
487
488 xattrs->num += 1;
489 }
490
491 void xattrs2line(db_line *line, int fd, const char *whoami) {
492 xattrs_type *xattrs = NULL;
493 ssize_t xret = -1;
494
495 if ((ATTR(attr_xattrs)&line->attr)) {
496 ssize_t xsz = 1024;
497 char *xatrs = checked_malloc(xsz);
498 #ifdef O_PATH
499 char proc_self_path[256];
500 #endif
501
502 while (((xret = flistxattr(fd, xatrs, xsz)) == -1) && (errno == ERANGE)) {
503 xsz <<= 1;
504 xatrs = checked_realloc(xatrs, xsz);
505 }
506 #ifdef O_PATH
507 int fd_flags = fcntl(fd, F_GETFL);
508 if (xret == -1 && errno == EBADF && fd_flags != -1 && fd_flags&O_PATH) {
509 snprintf(proc_self_path, sizeof(proc_self_path), "/proc/self/fd/%d", fd);
510 LOG_WHOAMI(LOG_LEVEL_DEBUG,"%s> flistxattr() failed: Bad file descriptor (emulating O_PATH support via '%s')", line->fullpath, proc_self_path);
511 while (((xret = listxattr(proc_self_path, xatrs, xsz)) == -1) && (errno == ERANGE)) {
512 xsz <<= 1;
513 xatrs = checked_realloc(xatrs, xsz);
514 }
515 }
516 #endif
517 if (xret == -1) {
518 switch (errno) {
519 case ENOSYS:
520 case ENOTSUP:
521 LOG_WHOAMI(LOG_LEVEL_DEBUG, "%s> listxattr() failed to get list of extended attribute names: %s (disabling xattr attribute)", line->fullpath, strerror(errno));
522 break;
523 default:
524 log_msg(LOG_LEVEL_WARNING, "listxattr() failed to get list of extended attribute names for '%s': %s (disabling xattr attribute)", line->fullpath, strerror(errno));
525 }
526 line->attr&=(~ATTR(attr_xattrs));
527 } else if (xret > 0) {
528 const char *attr = xatrs;
529 ssize_t asz = 1024;
530
531 char *val = checked_malloc(asz);
532 xattrs = xattr_new();
533 while (xret > 0) {
534 size_t len = strlen(attr);
535 ssize_t aret = 0;
536 if (strncmp(attr, "user.", strlen("user.")) == 0
537 || strncmp(attr, "security.", strlen("security.")) == 0
538 || strncmp(attr, "trusted.", strlen("trusted.")) == 0
539 ) {
540 #ifdef O_PATH
541 if (fd_flags&O_PATH) {
542 while (((aret = getxattr(proc_self_path, attr, val, asz)) == -1) && (errno == ERANGE)) {
543 asz <<= 1;
544 val = checked_realloc (val, asz);
545 }
546 } else {
547 #endif
548 while (((aret = fgetxattr(fd, attr, val, asz)) == -1) && (errno == ERANGE)) {
549 asz <<= 1;
550 val = checked_realloc (val, asz);
551 }
552 #ifdef O_PATH
553 }
554 #endif
555
556 if (aret != -1) {
557 xattr_add(xattrs, attr, val, aret);
558 } else {
559 log_msg(LOG_LEVEL_WARNING, "lgetxattr() failed to get value of extended attribute '%s' for '%s': %s (discarding extended attribute)", attr, line->fullpath, strerror(errno));
560 }
561 }
562 attr += len + 1;
563 xret -= len + 1;
564 }
565 free(val);
566 } else {
567 LOG_WHOAMI(LOG_LEVEL_DEBUG, "%s> llistxattr() returned empty list of extended attribute names", line->fullpath);
568 }
569 free(xatrs);
570 }
571
572 line->xattrs = xattrs;
573 }
574 #endif
575
576 #ifdef WITH_SELINUX
577 void selinux2line(db_line *line, int fd, const char *whoami) {
578 char *cntx = NULL;
579
580 if ((ATTR(attr_selinux)&line->attr)) {
581 if (fgetfilecon_raw(fd, &cntx) == -1) { /* files opened via O_PATH are supported since libselinux 3.4. */
582 switch (errno) {
583 case ENODATA:
584 case ENOTSUP:
585 LOG_WHOAMI(LOG_LEVEL_DEBUG, "%s> fgetfilecon_raw() failed to get SELinux security context: %s (disabling selinux attribute)", line->fullpath, strerror(errno));
586 break;
587 default:
588 log_msg(LOG_LEVEL_WARNING, "fgetfilecon_raw() failed to get SELinux security context for '%s': %s (disabling selinux attribute)", line->fullpath, strerror(errno));
589 }
590 line->attr&=(~ATTR(attr_selinux));
591 line->cntx = NULL;
592 return;
593 } else {
594 line->cntx = checked_strdup(cntx);
595 freecon(cntx);
596 }
597 } else {
598 line->cntx = NULL;
599 }
600 }
601 #endif
602
603 #ifdef WITH_E2FSATTRS
604 void e2fsattrs2line(db_line* line, int fd, const char *whoami) {
605 unsigned long flags;
606 if (ATTR(attr_e2fsattrs)&line->attr) {
607 if (getflags(fd, &flags) == 0) {
608 line->e2fsattrs=flags;
609 } else {
610 switch (errno) {
611 case ENOTTY:
612 case ENOTSUP:
613 LOG_WHOAMI(LOG_LEVEL_DEBUG, "%s> fgetflags() failed to get file attributes: %s (disabling e2fsattrs attribute)", line->fullpath, strerror(errno));
614 break;
615 default:
616 log_msg(LOG_LEVEL_WARNING, "fgetflags() failed to get file attributes for '%s': %s (disabling e2fsattrs attribute)", line->fullpath, strerror(errno));
617 }
618 line->attr&=(~ATTR(attr_e2fsattrs));
619 line->e2fsattrs=0;
620 }
621 } else {
622 line->e2fsattrs=0;
623 }
624 }
625 #endif
626
627 #ifdef WITH_CAPABILITIES
628 void capabilities2line(db_line* line, int fd, const char *whoami) {
629 cap_t caps;
630 char *txt_caps;
631
632 if ((ATTR(attr_capabilities)&line->attr)) {
633 caps = cap_get_fd(fd);
634 #ifdef O_PATH
635 int fd_flags = fcntl(fd, F_GETFL);
636 if (caps == NULL && errno == EBADF && fd_flags != -1 && fd_flags&O_PATH) {
637 char proc_self_path[256];
638 snprintf(proc_self_path, sizeof(proc_self_path), "/proc/self/fd/%d", fd);
639 LOG_WHOAMI(LOG_LEVEL_DEBUG,"%s> cap_get_fd() failed: Bad file descriptor (emulating O_PATH support via '%s')", line->fullpath, proc_self_path);
640 caps = cap_get_file(proc_self_path);
641 }
642 #endif
643 if (caps != NULL) {
644 txt_caps = cap_to_text(caps, NULL);
645 if (txt_caps == NULL) {
646 log_msg(LOG_LEVEL_WARNING, "cap_to_text() failed to get textual representation for capability state of '%s': %s (disabling caps attribute)", line->fullpath, strerror(errno));
647 line->attr&=(~ATTR(attr_capabilities));
648 line->capabilities=NULL;
649 } else {
650 line->capabilities = checked_strdup(txt_caps);
651 cap_free(txt_caps);
652 }
653 cap_free(caps);
654 } else {
655 switch (errno) {
656 case ENOSYS:
657 case ENODATA:
658 case ENOTSUP:
659 LOG_WHOAMI(LOG_LEVEL_DEBUG, "%s> cap_get_fd() failed to get capability state: %s (disabling e2fsattrs attribute)", line->fullpath, strerror(errno));
660 break;
661 default:
662 log_msg(LOG_LEVEL_WARNING, "cap_get_fd() failed to get capability state for '%s': %s (disabling caps attribute)", line->fullpath, strerror(errno));
663 }
664 line->attr&=(~ATTR(attr_capabilities));
665 line->capabilities=NULL;
666 }
667 } else {
668 line->capabilities=NULL;
669 }
670 }
671 #endif