| 1 | /* |
| 2 | * AIDE (Advanced Intrusion Detection Environment) |
| 3 | * |
| 4 | * Copyright (C) 1999-2006, 2010-2011, 2013, 2019-2025 Rami Lehti, |
| 5 | * Pablo Virolainen, Richard van den Berg, Hannes von Haugwitz |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; either version 2 of the |
| 10 | * License, or (at your option) any later version. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License along |
| 18 | * with this program; if not, write to the Free Software Foundation, Inc., |
| 19 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | */ |
| 21 | |
| 22 | #include "aide.h"cxx . . $ `<file>/include/aide.h`/ |
| 23 | #include <stdbool.h> |
| 24 | #include <stdio.h> |
| 25 | #include <string.h> |
| 26 | #include <errno.h> |
| 27 | #include <time.h> |
| 28 | #include "attributes.h"cxx . . $ `<file>/include/attributes.h`/ |
| 29 | #include "config.h"cxx . . $ `<file>/include/config.h`/ |
| 30 | #include "hashsum.h"cxx . . $ `<file>/include/hashsum.h`/ |
| 31 | #include "url.h"cxx . . $ `<file>/include/url.h`/ |
| 32 | #include <stdlib.h> |
| 33 | #include "db.h"cxx . . $ `<file>/include/db.h`/ |
| 34 | #include "db_line.h"cxx . . $ `<file>/include/db_line.h`/ |
| 35 | #include "db_file.h"cxx . . $ `<file>/include/db_file.h`/ |
| 36 | #include "md.h"cxx . . $ `<file>/include/md.h`/ |
| 37 | |
| 38 | #ifdef WITH_CURL |
| 39 | #include "fopen.h" |
| 40 | #endif |
| 41 | |
| 42 | #include "db_config.h"cxx . . $ `<file>/include/db_config.h`/ |
| 43 | #include "log.h"cxx . . $ `<file>/include/log.h`/ |
| 44 | #include "be.h"cxx . . $ `<file>/include/be.h`/ |
| 45 | |
| 46 | #include "base64.h"cxx . . $ `<file>/include/base64.h`/ |
| 47 | #include "util.h"cxx . . $ `<file>/include/util.h`/ |
| 48 | |
| 49 | static long readoctcxx . . $ readoct(ae1f126043d3a24c).(char* s, databasecxx . . $ database#* db, char* field_name){ |
| 50 | long i; |
| 51 | char* e; |
| 52 | i=strtolcxx . . $ strtol(44bbb87609b212fc).(s,&e,8); |
| 53 | if (e[0]!='\0') { |
| 54 | LOG_DB_FORMAT_LINEcxx . . $ `include/db.h:72:9`!(LOG_LEVEL_WARNING, "could not read '%s' from database: strtol (base: 8) failed for '%s'", field_name, s) |
| 55 | } |
| 56 | return i; |
| 57 | } |
| 58 | |
| 59 | static long readlongcxx . . $ readlong(ae1f126043d3a24c).(char* s, databasecxx . . $ database#* db, char* field_name){ |
| 60 | long i; |
| 61 | char* e; |
| 62 | i=strtolcxx . . $ strtol(44bbb87609b212fc).(s,&e,10); |
| 63 | if (e[0]!='\0') { |
| 64 | LOG_DB_FORMAT_LINEcxx . . $ `include/db.h:72:9`!(LOG_LEVEL_WARNING, "could not read '%s' from database: strtol failed for '%s'", field_name, s) |
| 65 | } |
| 66 | return i; |
| 67 | } |
| 68 | |
| 69 | #ifdef HAVE_FSTYPEcxx . . $ `./include/config.h:53:9`! |
| 70 | static unsigned long readunsignedlongcxx . . $ readunsignedlong(cafa27a1a8f1ac80).(char* s, databasecxx . . $ database#* db, char* field_name){ |
| 71 | unsigned long i; |
| 72 | char* e; |
| 73 | i=strtoulcxx . . $ strtoul(31746e8d6ec49860).(s,&e,10); |
| 74 | if (e[0]!='\0') { |
| 75 | LOG_DB_FORMAT_LINEcxx . . $ `include/db.h:72:9`!(LOG_LEVEL_WARNING, "could not read '%s' from database: strtoul failed for '%s'", field_name, s) |
| 76 | return 0; |
| 77 | } |
| 78 | return i; |
| 79 | } |
| 80 | #endif |
| 81 | |
| 82 | static long long readlonglongcxx . . $ readlonglong(d261434f7c8dbfcf).(char* s, databasecxx . . $ database#* db, char* field_name){ |
| 83 | long long int i; |
| 84 | char* e; |
| 85 | i=strtollcxx . . $ strtoll(c50972e7488cbac6).(s,&e,10); |
| 86 | if (e[0]!='\0') { |
| 87 | LOG_DB_FORMAT_LINEcxx . . $ `include/db.h:72:9`!(LOG_LEVEL_WARNING, "could not read '%s' from database: strtoll failed for '%s'", field_name, s) |
| 88 | } |
| 89 | return i; |
| 90 | } |
| 91 | |
| 92 | static time_tcxx . . $ time_t# read_time_tcxx . . $ read_time_t(dec5c78d2a00240).(char *str, databasecxx . . $ database# *db, const char *field_name) { |
| 93 | char *decoded = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 94 | char *time_t_str = str; |
| 95 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(str, "0") == 0) { |
| 96 | return 0; |
| 97 | } |
| 98 | if (*str >= 'M' && *str <= 'O') { |
| 99 | /* handle legacy base64 representation */ |
| 100 | decoded = (char *) decode_base64cxx . . $ decode_base64(923cec5f6a9944d3).(str, strlencxx . . $ strlen(751346f8406fd082).(str), NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 101 | if (decoded == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 102 | /* warning is logged in decode_base64 */ |
| 103 | return 0; |
| 104 | } |
| 105 | time_t_str = decoded; |
| 106 | log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_TRACEcxx . . $ LOG_LEVEL_TRACE., "read_time_t: base64 decoded '%s' to '%s'", str, decoded); |
| 107 | } |
| 108 | char *endp = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 109 | time_tcxx . . $ time_t# t = strtolcxx . . $ strtol(44bbb87609b212fc).(time_t_str, &endp, 10); |
| 110 | if (endp[0] != '\0' || (errnocxx . . $ `<external>/17633486526465735210/errno.h:38:10`! = ERANGEcxx . . $ `<external>/8987895939074593727/errno-base.h:38:9`! && (t == LONG_MAXcxx . . $ `<external>/2419331716647297546/limits.h:131:9`! || t == LONG_MINcxx . . $ `<external>/2419331716647297546/limits.h:129:9`!))) { |
| 111 | LOG_DB_FORMAT_LINEcxx . . $ `include/db.h:72:9`!(LOG_LEVEL_WARNING, "could not read '%s' from database: strtol failed for '%s' (setting '%s' to 0)", field_name, time_t_str, field_name) |
| 112 | t = 0; |
| 113 | } else { |
| 114 | log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_TRACEcxx . . $ LOG_LEVEL_TRACE., "read_time_t: converted '%s' '%s' to %lld ", field_name, time_t_str, (long long)t); |
| 115 | } |
| 116 | |
| 117 | freecxx . . $ free(5d22bdacc48458e8).(decoded); |
| 118 | return t; |
| 119 | } |
| 120 | |
| 121 | static struct md_containercxx . . $ md_container# *init_db_attrscxx . . $ init_db_attrs(18dd12076c835785).(url_tcxx . . $ url_t# *u) { |
| 122 | struct md_containercxx . . $ md_container# *mdc = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 123 | if (confcxx . . $ conf.->db_attrscxx . . $ db_config#db_attrs.) { |
| 124 | switch (u->typecxx . . $ url_t#type.) { |
| 125 | case url_stdincxx . . $ url_stdin.: |
| 126 | case url_stdoutcxx . . $ url_stdout.: |
| 127 | case url_stderrcxx . . $ url_stderr.: |
| 128 | case url_fdcxx . . $ url_fd.: |
| 129 | case url_filecxx . . $ url_file.: |
| 130 | case url_httpcxx . . $ url_http.: |
| 131 | case url_httpscxx . . $ url_https.: |
| 132 | case url_ftpcxx . . $ url_ftp.: { |
| 133 | mdc = checked_malloccxx . . $ checked_malloc(bfcfa4d6b7f7ef64).(sizeof(struct md_containercxx . . $ md_container#)); /* freed in close_db_attrs */ |
| 134 | mdc->todo_attrcxx . . $ md_container#todo_attr. = confcxx . . $ conf.->db_attrscxx . . $ db_config#db_attrs.; |
| 135 | init_mdcxx . . $ init_md(74d27db1f5e1726).(mdc, u->valuecxx . . $ url_t#value., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 136 | |
| 137 | break; |
| 138 | } |
| 139 | /* unsupported database types */ |
| 140 | case url_syslogcxx . . $ url_syslog.: { |
| 141 | /* do nothing */ |
| 142 | break; |
| 143 | } |
| 144 | } |
| 145 | } |
| 146 | return mdc; |
| 147 | } |
| 148 | |
| 149 | static db_linecxx . . $ db_line# *close_db_attrscxx . . $ close_db_attrs(73a30572ed0ad327). (databasecxx . . $ database# *db) { |
| 150 | db_linecxx . . $ db_line# *line = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 151 | if (db->mdccxx . . $ database#mdc. != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 152 | md_hashsumscxx . . $ md_hashsums# hs; |
| 153 | line = checked_malloccxx . . $ checked_malloc(bfcfa4d6b7f7ef64).(sizeof(struct db_linecxx . . $ db_line#)); |
| 154 | line->filenamecxx . . $ db_line#filename. = (db->urlcxx . . $ database#url.)->valuecxx . . $ url_t#value.; |
| 155 | line->permcxx . . $ db_line#perm. = 0; |
| 156 | line->attrcxx . . $ db_line#attr. = confcxx . . $ conf.->db_attrscxx . . $ db_config#db_attrs.; |
| 157 | close_mdcxx . . $ close_md(e2d4d3ac7f8219a9).(db->mdccxx . . $ database#mdc., &hs, line->filenamecxx . . $ db_line#filename., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 158 | hashsums2linecxx . . $ hashsums2line(f5f0f94a1303d470).(&hs, line, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 159 | freecxx . . $ free(5d22bdacc48458e8).(db->mdccxx . . $ database#mdc.); |
| 160 | } |
| 161 | return line; |
| 162 | } |
| 163 | |
| 164 | int db_initcxx . . $ db_init(d8a340524e05b6c1).(databasecxx . . $ database#* db, boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! readonly, boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! gzip) { |
| 165 | void* fp = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 166 | |
| 167 | log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_TRACEcxx . . $ LOG_LEVEL_TRACE.,"db_init(): arguments: db=%p, gzip=%s", (void*) db, btoacxx . . $ btoa(626eec357d49c77e).(gzip)); |
| 168 | |
| 169 | db->mdccxx . . $ database#mdc. = init_db_attrscxx . . $ init_db_attrs(18dd12076c835785).(db->urlcxx . . $ database#url.); |
| 170 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! created = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 171 | fp=be_initcxx . . $ be_init(d7a38dc26e275cb4).(db->urlcxx . . $ database#url., readonly, gzip, falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!, db->linenumbercxx . . $ database#linenumber., db->filenamecxx . . $ database#filename., db->linebufcxx . . $ database#linebuf., &created); |
| 172 | if (created) { db->flagscxx . . $ database#flags. |= DB_FLAG_CREATEDcxx . . $ DB_FLAG_CREATED.; } |
| 173 | if(fp==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 174 | return RETFAILcxx . . $ `include/db_config.h:46:9`!; |
| 175 | } else { |
| 176 | #ifdef WITH_ZLIBcxx . . $ `./include/config.h:266:9`! |
| 177 | if (gzip) { |
| 178 | db->gzpcxx . . $ database#gzp. = fp; |
| 179 | } else { |
| 180 | #endif |
| 181 | db->fpcxx . . $ database#fp. = fp; |
| 182 | #ifdef WITH_ZLIBcxx . . $ `./include/config.h:266:9`! |
| 183 | } |
| 184 | #endif |
| 185 | return RETOKcxx . . $ `include/db_config.h:45:9`!; |
| 186 | } |
| 187 | } |
| 188 | |
| 189 | db_entry_tcxx . . $ db_entry_t# db_readlinecxx . . $ db_readline(9768d9fab7f01dc3).(databasecxx . . $ database#* db, boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! include_limited_entries){ |
| 190 | return db_readline_filecxx . . $ db_readline_file(9768d9fab7f01dc3).(db, include_limited_entries); |
| 191 | } |
| 192 | |
| 193 | bytecxx . . $ byte#* base64tobytecxx . . $ base64tobyte(3ddd0ff516b096d7).(char* src,int len,size_t *ret_len) |
| 194 | { |
| 195 | if(strcmpcxx . . $ strcmp(5ae29d726ae57f88).(src,"0")!=0){ |
| 196 | return decode_base64cxx . . $ decode_base64(923cec5f6a9944d3).(src,len,ret_len); |
| 197 | } |
| 198 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 199 | } |
| 200 | |
| 201 | static char *read_linknamecxx . . $ read_linkname(7a9722d75b371431).(char *s) |
| 202 | { |
| 203 | if (s == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) |
| 204 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 205 | |
| 206 | if (s[0] == '0') |
| 207 | { |
| 208 | if (s[1] == '\0') |
| 209 | return (NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 210 | |
| 211 | if (s[1] == '-') |
| 212 | return (checked_strdupcxx . . $ checked_strdup(42228c1987407501).("")); |
| 213 | |
| 214 | if (s[1] == '0') { |
| 215 | s++; |
| 216 | } |
| 217 | } |
| 218 | |
| 219 | decode_stringcxx . . $ decode_string(fda57c8427c60377).(s); |
| 220 | |
| 221 | return checked_strdupcxx . . $ checked_strdup(42228c1987407501).(s); |
| 222 | } |
| 223 | |
| 224 | |
| 225 | #define CHAR2HASHcxx . . $ `src/db.c:225:9`!(hash) \ |
| 226 | case attr_ ##hash : { \ |
| 227 | line->hashsums[hash_ ##hash]=base64tobyte(ss[db->fields[i]], \ |
| 228 | strlen(ss[db->fields[i]]), NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); \ |
| 229 | log_msg(LOG_LEVEL_TRACE, "%s: copy " #hash " hashsum (%s) to %p", line->filename, ss[db->fields[i]], (void*) line->hashsums[hash_ ##hash]); \ |
| 230 | break; \ |
| 231 | } |
| 232 | |
| 233 | db_linecxx . . $ db_line#* db_char2linecxx . . $ db_char2line(237a20c9d441aa86).(char** ss, databasecxx . . $ database#* db){ |
| 234 | |
| 235 | db_linecxx . . $ db_line#* line=(db_linecxx . . $ db_line#*)checked_malloccxx . . $ checked_malloc(bfcfa4d6b7f7ef64).(sizeof(db_linecxx . . $ db_line#)*1); |
| 236 | |
| 237 | line->permcxx . . $ db_line#perm.=0; |
| 238 | line->uidcxx . . $ db_line#uid.=0; |
| 239 | line->gidcxx . . $ db_line#gid.=0; |
| 240 | line->atimecxx . . $ db_line#atime.=0; |
| 241 | line->ctimecxx . . $ db_line#ctime.=0; |
| 242 | line->mtimecxx . . $ db_line#mtime.=0; |
| 243 | line->inodecxx . . $ db_line#inode.=0; |
| 244 | line->nlinkcxx . . $ db_line#nlink.=0; |
| 245 | line->bcountcxx . . $ db_line#bcount.=0; |
| 246 | line->sizecxx . . $ db_line#size.=0; |
| 247 | line->filenamecxx . . $ db_line#filename.=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 248 | line->fullpathcxx . . $ db_line#fullpath.=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 249 | line->linknamecxx . . $ db_line#linkname.=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 250 | #ifdef WITH_POSIX_ACL |
| 251 | line->acl=NULL; |
| 252 | #endif |
| 253 | #ifdef WITH_XATTR |
| 254 | line->xattrs=NULL; |
| 255 | #endif |
| 256 | line->e2fsattrscxx . . $ db_line#e2fsattrs.=0; |
| 257 | line->cntxcxx . . $ db_line#cntx.=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 258 | line->capabilitiescxx . . $ db_line#capabilities.=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 259 | |
| 260 | for (int i = 0 ; i < num_hashescxx . . $ num_hashes. ; ++i) { |
| 261 | line->hashsumscxx . . $ db_line#hashsums.[i]=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 262 | } |
| 263 | |
| 264 | |
| 265 | line->attrcxx . . $ db_line#attr.=confcxx . . $ conf.->attrcxx . . $ db_config#attr.; /* attributes from @@dbspec */ |
| 266 | |
| 267 | for(int i=0;i<db->num_fieldscxx . . $ database#num_fields.;i++){ |
| 268 | |
| 269 | log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_TRACEcxx . . $ LOG_LEVEL_TRACE., "db_char2line(): %ld[%d]: '%s' (%p)", db->linenocxx . . $ database#lineno., i, ss[i], (void*) ss[i]); |
| 270 | |
| 271 | switch (db->fieldscxx . . $ database#fields.[i]) { |
| 272 | case attr_filenamecxx . . $ attr_filename. : { |
| 273 | if(ss[db->fieldscxx . . $ database#fields.[i]]!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!){ |
| 274 | line->fullpathcxx . . $ db_line#fullpath.=checked_strdupcxx . . $ checked_strdup(42228c1987407501).(ss[db->fieldscxx . . $ database#fields.[i]]); |
| 275 | line->filenamecxx . . $ db_line#filename.=line->fullpathcxx . . $ db_line#fullpath.; |
| 276 | } else { |
| 277 | log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "db_char2line(): error while reading database"); |
| 278 | exitcxx . . $ exit(3ca292c338df9bb3).(EXIT_FAILUREcxx . . $ `<external>/10696550936717951914/stdlib.h:96:9`!); |
| 279 | } |
| 280 | break; |
| 281 | } |
| 282 | case attr_linknamecxx . . $ attr_linkname. : { |
| 283 | line->linknamecxx . . $ db_line#linkname. = read_linknamecxx . . $ read_linkname(7a9722d75b371431).(ss[db->fieldscxx . . $ database#fields.[i]]); |
| 284 | break; |
| 285 | } |
| 286 | case attr_mtimecxx . . $ attr_mtime. : { |
| 287 | line->mtimecxx . . $ db_line#mtime.=read_time_tcxx . . $ read_time_t(dec5c78d2a00240).(ss[db->fieldscxx . . $ database#fields.[i]], db, "mtime"); |
| 288 | break; |
| 289 | } |
| 290 | case attr_bcountcxx . . $ attr_bcount. : { |
| 291 | line->bcountcxx . . $ db_line#bcount.=readlonglongcxx . . $ readlonglong(d261434f7c8dbfcf).(ss[db->fieldscxx . . $ database#fields.[i]], db, "bcount"); |
| 292 | break; |
| 293 | } |
| 294 | case attr_atimecxx . . $ attr_atime. : { |
| 295 | line->atimecxx . . $ db_line#atime.=read_time_tcxx . . $ read_time_t(dec5c78d2a00240).(ss[db->fieldscxx . . $ database#fields.[i]], db, "atime"); |
| 296 | break; |
| 297 | } |
| 298 | case attr_ctimecxx . . $ attr_ctime. : { |
| 299 | line->ctimecxx . . $ db_line#ctime.=read_time_tcxx . . $ read_time_t(dec5c78d2a00240).(ss[db->fieldscxx . . $ database#fields.[i]], db, "ctime"); |
| 300 | break; |
| 301 | } |
| 302 | case attr_inodecxx . . $ attr_inode. : { |
| 303 | line->inodecxx . . $ db_line#inode.=readlongcxx . . $ readlong(ae1f126043d3a24c).(ss[db->fieldscxx . . $ database#fields.[i]], db, "inode"); |
| 304 | break; |
| 305 | } |
| 306 | |
| 307 | case attr_uidcxx . . $ attr_uid. : { |
| 308 | line->uidcxx . . $ db_line#uid.=readlongcxx . . $ readlong(ae1f126043d3a24c).(ss[db->fieldscxx . . $ database#fields.[i]], db, "uid"); |
| 309 | break; |
| 310 | } |
| 311 | case attr_gidcxx . . $ attr_gid. : { |
| 312 | line->gidcxx . . $ db_line#gid.=readlongcxx . . $ readlong(ae1f126043d3a24c).(ss[db->fieldscxx . . $ database#fields.[i]], db, "gid"); |
| 313 | break; |
| 314 | } |
| 315 | case attr_sizecxx . . $ attr_size. : { |
| 316 | line->sizecxx . . $ db_line#size.=readlonglongcxx . . $ readlonglong(d261434f7c8dbfcf).(ss[db->fieldscxx . . $ database#fields.[i]], db, "size"); |
| 317 | break; |
| 318 | } |
| 319 | CHAR2HASHcxx . . $ `src/db.c:225:9`!(md5) |
| 320 | CHAR2HASHcxx . . $ `src/db.c:225:9`!(sha256) |
| 321 | CHAR2HASHcxx . . $ `src/db.c:225:9`!(sha512) |
| 322 | CHAR2HASHcxx . . $ `src/db.c:225:9`!(sha1) |
| 323 | CHAR2HASHcxx . . $ `src/db.c:225:9`!(rmd160) |
| 324 | CHAR2HASHcxx . . $ `src/db.c:225:9`!(tiger) |
| 325 | CHAR2HASHcxx . . $ `src/db.c:225:9`!(crc32) |
| 326 | CHAR2HASHcxx . . $ `src/db.c:225:9`!(crc32b) |
| 327 | CHAR2HASHcxx . . $ `src/db.c:225:9`!(haval) |
| 328 | CHAR2HASHcxx . . $ `src/db.c:225:9`!(whirlpool) |
| 329 | CHAR2HASHcxx . . $ `src/db.c:225:9`!(gostr3411_94) |
| 330 | CHAR2HASHcxx . . $ `src/db.c:225:9`!(stribog256) |
| 331 | CHAR2HASHcxx . . $ `src/db.c:225:9`!(stribog512) |
| 332 | CHAR2HASHcxx . . $ `src/db.c:225:9`!(sha512_256) |
| 333 | CHAR2HASHcxx . . $ `src/db.c:225:9`!(sha3_256) |
| 334 | CHAR2HASHcxx . . $ `src/db.c:225:9`!(sha3_512) |
| 335 | case attr_aclcxx . . $ attr_acl. : { |
| 336 | #ifdef WITH_POSIX_ACL |
| 337 | char *tval = NULL; |
| 338 | |
| 339 | tval = strtok(ss[db->fields[i]], ","); |
| 340 | |
| 341 | line->acl = NULL; |
| 342 | |
| 343 | if (tval[0] == '0') |
| 344 | line->acl = NULL; |
| 345 | else if (!strcmp(tval, "POSIX")) |
| 346 | { |
| 347 | line->acl = checked_malloc(sizeof(acl_type)); |
| 348 | line->acl->acl_a = NULL; |
| 349 | line->acl->acl_d = NULL; |
| 350 | |
| 351 | tval = strtok(NULL, ","); |
| 352 | line->acl->acl_a = (char *)base64tobyte(tval, strlen(tval), NULL); |
| 353 | tval = strtok(NULL, ","); |
| 354 | line->acl->acl_d = (char *)base64tobyte(tval, strlen(tval), NULL); |
| 355 | } |
| 356 | /* else, it's broken... */ |
| 357 | #endif |
| 358 | break; |
| 359 | } |
| 360 | case attr_xattrscxx . . $ attr_xattrs. : { |
| 361 | #ifdef WITH_XATTR |
| 362 | size_t num = 0; |
| 363 | char *tval = NULL; |
| 364 | |
| 365 | tval = strtok(ss[db->fields[i]], ","); |
| 366 | num = readlong(tval, db, "xattrs"); |
| 367 | if (num) |
| 368 | { |
| 369 | line->xattrs = checked_malloc(sizeof(xattrs_type)); |
| 370 | line->xattrs->ents = checked_calloc(sizeof(xattr_node), num); |
| 371 | line->xattrs->sz = num; |
| 372 | line->xattrs->num = num; |
| 373 | num = 0; |
| 374 | while (num < line->xattrs->num) |
| 375 | { |
| 376 | tval = strtok(NULL, ","); |
| 377 | decode_string(tval); |
| 378 | line->xattrs->ents[num].key = checked_strdup(tval); |
| 379 | tval = strtok(NULL, ","); |
| 380 | if (strcmp(tval,"0") != 0) { |
| 381 | line->xattrs->ents[num].val = decode_base64(tval, strlen(tval), &line->xattrs->ents[num].vsz); |
| 382 | } else { |
| 383 | line->xattrs->ents[num].val = checked_strdup(""); |
| 384 | line->xattrs->ents[num].vsz = 0; |
| 385 | } |
| 386 | if (line->xattrs->ents[num].val == NULL) { |
| 387 | LOG_DB_FORMAT_LINE(LOG_LEVEL_WARNING, "error while reading xattrs for '%s' from database (discarding extended attributes)", line->filename) |
| 388 | for (int j = num; j >= 0 ; --j) { |
| 389 | free(line->xattrs->ents[j].key); |
| 390 | line->xattrs->ents[j].key = NULL; |
| 391 | free(line->xattrs->ents[j].val); |
| 392 | line->xattrs->ents[j].val = NULL; |
| 393 | } |
| 394 | line->xattrs->num = 0; |
| 395 | } else { |
| 396 | ++num; |
| 397 | } |
| 398 | } |
| 399 | } |
| 400 | #endif |
| 401 | break; |
| 402 | } |
| 403 | |
| 404 | case attr_selinuxcxx . . $ attr_selinux. : { |
| 405 | bytecxx . . $ byte# *val = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 406 | |
| 407 | val = base64tobytecxx . . $ base64tobyte(3ddd0ff516b096d7).(ss[db->fieldscxx . . $ database#fields.[i]], strlencxx . . $ strlen(751346f8406fd082).(ss[db->fieldscxx . . $ database#fields.[i]]),NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 408 | line->cntxcxx . . $ db_line#cntx. = (char *)val; |
| 409 | break; |
| 410 | } |
| 411 | |
| 412 | case attr_permcxx . . $ attr_perm. : { |
| 413 | line->permcxx . . $ db_line#perm.=readoctcxx . . $ readoct(ae1f126043d3a24c).(ss[db->fieldscxx . . $ database#fields.[i]], db, "permissions"); |
| 414 | break; |
| 415 | } |
| 416 | |
| 417 | case attr_linkcountcxx . . $ attr_linkcount. : { |
| 418 | line->nlinkcxx . . $ db_line#nlink.=readlongcxx . . $ readlong(ae1f126043d3a24c).(ss[db->fieldscxx . . $ database#fields.[i]], db, "nlink"); |
| 419 | break; |
| 420 | } |
| 421 | |
| 422 | case attr_attrcxx . . $ attr_attr. : { |
| 423 | line->attrcxx . . $ db_line#attr.=readlonglongcxx . . $ readlonglong(d261434f7c8dbfcf).(ss[db->fieldscxx . . $ database#fields.[i]], db, "attr"); |
| 424 | break; |
| 425 | } |
| 426 | |
| 427 | case attr_e2fsattrscxx . . $ attr_e2fsattrs. : { |
| 428 | line->e2fsattrscxx . . $ db_line#e2fsattrs.=readlongcxx . . $ readlong(ae1f126043d3a24c).(ss[db->fieldscxx . . $ database#fields.[i]], db, "e2fsattrs"); |
| 429 | break; |
| 430 | } |
| 431 | |
| 432 | case attr_capabilitiescxx . . $ attr_capabilities. : { |
| 433 | bytecxx . . $ byte# *val = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 434 | |
| 435 | val = base64tobytecxx . . $ base64tobyte(3ddd0ff516b096d7).(ss[db->fieldscxx . . $ database#fields.[i]], strlencxx . . $ strlen(751346f8406fd082).(ss[db->fieldscxx . . $ database#fields.[i]]),NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!); |
| 436 | line->capabilitiescxx . . $ db_line#capabilities. = (char *)val; |
| 437 | break; |
| 438 | } |
| 439 | case attr_fs_typecxx . . $ attr_fs_type. : { |
| 440 | #ifdef HAVE_FSTYPEcxx . . $ `./include/config.h:53:9`! |
| 441 | line->fs_typecxx . . $ db_line#fs_type. = readunsignedlongcxx . . $ readunsignedlong(cafa27a1a8f1ac80).(ss[db->fieldscxx . . $ database#fields.[i]], db, attributescxx . . $ attributes.[attr_fs_typecxx . . $ attr_fs_type.].db_namecxx . . $ $anonymous_type_bb8296fff58edf70_1#db_name.); |
| 442 | #endif |
| 443 | break; |
| 444 | } |
| 445 | case attr_bsizecxx . . $ attr_bsize. : |
| 446 | case attr_sizegcxx . . $ attr_sizeg. : |
| 447 | case attr_rdevcxx . . $ attr_rdev. : |
| 448 | case attr_devcxx . . $ attr_dev. : |
| 449 | case attr_ftypecxx . . $ attr_ftype. : |
| 450 | case attr_checkinodecxx . . $ attr_checkinode. : |
| 451 | case attr_allhashsumscxx . . $ attr_allhashsums. : |
| 452 | case attr_growingcxx . . $ attr_growing. : |
| 453 | case attr_compressedcxx . . $ attr_compressed. : |
| 454 | case attr_allownewfilecxx . . $ attr_allownewfile. : |
| 455 | case attr_allowrmfilecxx . . $ attr_allowrmfile. : { |
| 456 | /* no db field */ |
| 457 | break; |
| 458 | } |
| 459 | case attr_unknowncxx . . $ attr_unknown. : { |
| 460 | /* Unknown fields are ignored. */ |
| 461 | break; |
| 462 | } |
| 463 | |
| 464 | } |
| 465 | |
| 466 | } |
| 467 | |
| 468 | return line; |
| 469 | } |
| 470 | |
| 471 | int db_writespeccxx . . $ db_writespec(d87c77e6d45fe0c5).(db_configcxx . . $ db_config#* dbconf) |
| 472 | { |
| 473 | if( |
| 474 | #ifdef WITH_ZLIBcxx . . $ `./include/config.h:266:9`! |
| 475 | (dbconf->gzip_dboutcxx . . $ db_config#gzip_dbout. && dbconf->database_outcxx . . $ db_config#database_out..gzpcxx . . $ database#gzp.) || |
| 476 | #endif |
| 477 | (dbconf->database_outcxx . . $ db_config#database_out..fpcxx . . $ database#fp.!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!)){ |
| 478 | if(db_writespec_filecxx . . $ db_writespec_file(d87c77e6d45fe0c5).(dbconf)==RETOKcxx . . $ `include/db_config.h:45:9`!){ |
| 479 | return RETOKcxx . . $ `include/db_config.h:45:9`!; |
| 480 | } |
| 481 | } |
| 482 | return RETFAILcxx . . $ `include/db_config.h:46:9`!; |
| 483 | } |
| 484 | |
| 485 | int db_writelinecxx . . $ db_writeline(bb1b3cc1d92abff8).(db_linecxx . . $ db_line#* line,db_configcxx . . $ db_config#* dbconf){ |
| 486 | |
| 487 | if (line==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!||dbconf==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) return RETOKcxx . . $ `include/db_config.h:45:9`!; |
| 488 | |
| 489 | if ( |
| 490 | #ifdef WITH_ZLIBcxx . . $ `./include/config.h:266:9`! |
| 491 | (dbconf->gzip_dboutcxx . . $ db_config#gzip_dbout. && dbconf->database_outcxx . . $ db_config#database_out..gzpcxx . . $ database#gzp.) || |
| 492 | #endif |
| 493 | (dbconf->database_outcxx . . $ db_config#database_out..fpcxx . . $ database#fp.!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!)) { |
| 494 | if (db_writeline_filecxx . . $ db_writeline_file(9bfc5d8be61eb86d).(line)==RETOKcxx . . $ `include/db_config.h:45:9`!) { |
| 495 | return RETOKcxx . . $ `include/db_config.h:45:9`!; |
| 496 | } |
| 497 | } |
| 498 | return RETFAILcxx . . $ `include/db_config.h:46:9`!; |
| 499 | } |
| 500 | |
| 501 | void db_closecxx . . $ db_close(49f6e7a06ebc5aa8).(void) { |
| 502 | if (confcxx . . $ conf.->database_outcxx . . $ db_config#database_out..urlcxx . . $ database#url.) { |
| 503 | switch (confcxx . . $ conf.->database_outcxx . . $ db_config#database_out..urlcxx . . $ database#url.->typecxx . . $ url_t#type.) { |
| 504 | case url_stdincxx . . $ url_stdin.: |
| 505 | case url_stdoutcxx . . $ url_stdout.: |
| 506 | case url_stderrcxx . . $ url_stderr.: |
| 507 | case url_fdcxx . . $ url_fd.: |
| 508 | case url_filecxx . . $ url_file.: { |
| 509 | if ( |
| 510 | #ifdef WITH_ZLIBcxx . . $ `./include/config.h:266:9`! |
| 511 | (confcxx . . $ conf.->gzip_dboutcxx . . $ db_config#gzip_dbout. && confcxx . . $ conf.->database_outcxx . . $ db_config#database_out..gzpcxx . . $ database#gzp.) || |
| 512 | #endif |
| 513 | (confcxx . . $ conf.->database_outcxx . . $ db_config#database_out..fpcxx . . $ database#fp.!=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!)) { |
| 514 | db_close_filecxx . . $ db_close_file(d87c77e6d45fe0c5).(confcxx . . $ conf.); |
| 515 | } |
| 516 | break; |
| 517 | } |
| 518 | case url_httpcxx . . $ url_http.: |
| 519 | case url_httpscxx . . $ url_https.: |
| 520 | case url_ftpcxx . . $ url_ftp.: |
| 521 | { |
| 522 | #ifdef WITH_CURL |
| 523 | if (conf->database_out.fp!=NULL) { |
| 524 | url_fclose(conf->database_out.fp); |
| 525 | conf->database_out.fp = NULL; |
| 526 | } |
| 527 | #endif /* WITH CURL */ |
| 528 | break; |
| 529 | } |
| 530 | /* unsupported database types */ |
| 531 | case url_syslogcxx . . $ url_syslog.: { |
| 532 | /* do nothing */ |
| 533 | break; |
| 534 | } |
| 535 | } |
| 536 | } |
| 537 | confcxx . . $ conf.->database_incxx . . $ db_config#database_in..db_linecxx . . $ database#db_line. = close_db_attrscxx . . $ close_db_attrs(73a30572ed0ad327).(&confcxx . . $ conf.->database_incxx . . $ db_config#database_in.); |
| 538 | confcxx . . $ conf.->database_outcxx . . $ db_config#database_out..db_linecxx . . $ database#db_line. = close_db_attrscxx . . $ close_db_attrs(73a30572ed0ad327).(&confcxx . . $ conf.->database_outcxx . . $ db_config#database_out.); |
| 539 | confcxx . . $ conf.->database_newcxx . . $ db_config#database_new..db_linecxx . . $ database#db_line. = close_db_attrscxx . . $ close_db_attrs(73a30572ed0ad327).(&confcxx . . $ conf.->database_newcxx . . $ db_config#database_new.); |
| 540 | } |
| 541 | |
| 542 | void free_db_linecxx . . $ free_db_line(5dc4328f64ce0e3d).(db_linecxx . . $ db_line#* dl) |
| 543 | { |
| 544 | if (dl==NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 545 | return; |
| 546 | } |
| 547 | |
| 548 | #define checked_freecxx . . $ `src/db.c:548:9`!(x) do { free(x); x=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; } while (0) |
| 549 | |
| 550 | for (int i = 0 ; i < num_hashescxx . . $ num_hashes. ; ++i) { |
| 551 | checked_freecxx . . $ `src/db.c:548:9`!(dl->hashsums[i]); |
| 552 | } |
| 553 | |
| 554 | dl->filenamecxx . . $ db_line#filename.=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 555 | checked_freecxx . . $ `src/db.c:548:9`!(dl->fullpath); |
| 556 | checked_freecxx . . $ `src/db.c:548:9`!(dl->linkname); |
| 557 | |
| 558 | #ifdef WITH_ACL |
| 559 | if (dl->acl) |
| 560 | { |
| 561 | free(dl->acl->acl_a); |
| 562 | free(dl->acl->acl_d); |
| 563 | } |
| 564 | checked_free(dl->acl); |
| 565 | #endif |
| 566 | |
| 567 | #ifdef WITH_XATTR |
| 568 | if (dl->xattrs) |
| 569 | free(dl->xattrs->ents); |
| 570 | checked_free(dl->xattrs); |
| 571 | checked_free(dl->cntx); |
| 572 | #endif |
| 573 | } |