| 1 | /* |
| 2 | * AIDE (Advanced Intrusion Detection Environment) |
| 3 | * |
| 4 | * Copyright (C) 1999-2002, 2004-2006, 2010-2011, 2013, 2016, 2019-2023 |
| 5 | * Rami Lehti, Pablo Virolainen, Mike Markley, |
| 6 | * Richard van den Berg, 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 <stdlib.h> |
| 25 | #include <stdio.h> |
| 26 | #include <string.h> |
| 27 | #include <sys/stat.h> |
| 28 | #include <ctype.h> |
| 29 | #include <syslog.h> |
| 30 | #include <stdbool.h> |
| 31 | #include <pthread.h> |
| 32 | #include <strings.h> |
| 33 | #include <unistd.h> |
| 34 | #include <signal.h> |
| 35 | #include <time.h> |
| 36 | #include "url.h"cxx . . $ `<file>/include/url.h`/ |
| 37 | /*for locale support*/ |
| 38 | #include "locale-aide.h"cxx . . $ `<file>/include/locale-aide.h`/ |
| 39 | /*for locale support*/ |
| 40 | |
| 41 | |
| 42 | #ifndef MAXHOSTNAMELEN |
| 43 | #define MAXHOSTNAMELENcxx . . $ `src/util.c:43:9`! 256 |
| 44 | #endif |
| 45 | |
| 46 | #include "log.h"cxx . . $ `<file>/include/log.h`/ |
| 47 | #include "db_config.h"cxx . . $ `<file>/include/db_config.h`/ |
| 48 | #include "util.h"cxx . . $ `<file>/include/util.h`/ |
| 49 | #include "errorcodes.h"cxx . . $ `<file>/include/errorcodes.h`/ |
| 50 | |
| 51 | #define URL_UNSAFEcxx . . $ `src/util.c:51:9`! " <>\"#%{}|\\^~[]`@:\033'," |
| 52 | #define ISPRINTcxx . . $ `src/util.c:52:9`!(c) (isasciicxx . . $ `<external>/17904084882347303253/ctype.h:225:11`!(c) && isprintcxx . . $ `<external>/17904084882347303253/ctype.h:195:10`!(c)) |
| 53 | |
| 54 | pthread_mutex_tcxx . . $ pthread_mutex_t# stderr_mutexcxx . . $ stderr_mutex. = PTHREAD_MUTEX_INITIALIZERcxx . . $ `<external>/14712363683955484316/pthread.h:90:9`!; |
| 55 | boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! stderr_erase_linecxx . . $ stderr_erase_line. = falsecxx . . $ `<external>/13015445228558014418/stdbool.h:38:9`!; |
| 56 | |
| 57 | void stderr_msgcxx . . $ stderr_msg(326aeb464d16410c).(const char* format, ...) { |
| 58 | pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).(&stderr_mutexcxx . . $ stderr_mutex.); |
| 59 | if (stderr_erase_linecxx . . $ stderr_erase_line.) { |
| 60 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\33[2K"); |
| 61 | } |
| 62 | va_listcxx . . $ va_list# ap; |
| 63 | va_startcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stdarg.h:51:9`!(ap, format); |
| 64 | vfprintfcxx . . $ vfprintf(bded311e54d67f9c).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, format, ap); |
| 65 | va_endcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stdarg.h:53:9`!(ap); |
| 66 | pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).(&stderr_mutexcxx . . $ stderr_mutex.); |
| 67 | } |
| 68 | |
| 69 | void vstderr_prefix_linecxx . . $ vstderr_prefix_line(b6c459c43e1e83c7).(const char* prefix, const char* format, va_listcxx . . $ va_list# ap) { |
| 70 | pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).(&stderr_mutexcxx . . $ stderr_mutex.); |
| 71 | if (stderr_erase_linecxx . . $ stderr_erase_line.) { |
| 72 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\33[2K"); |
| 73 | } |
| 74 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "%s: ", prefix); |
| 75 | vfprintfcxx . . $ vfprintf(bded311e54d67f9c).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, format, ap); |
| 76 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\n"); |
| 77 | pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).(&stderr_mutexcxx . . $ stderr_mutex.); |
| 78 | } |
| 79 | |
| 80 | void stderr_set_line_erasurecxx . . $ stderr_set_line_erasure(b45ddcbc8423892c).(boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! erase_line) { |
| 81 | pthread_mutex_lockcxx . . $ pthread_mutex_lock(d89ae235521888f9).(&stderr_mutexcxx . . $ stderr_mutex.); |
| 82 | if (stderr_erase_linecxx . . $ stderr_erase_line.) { |
| 83 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:159:9`!, "\33[2K"); |
| 84 | } |
| 85 | stderr_erase_linecxx . . $ stderr_erase_line. = erase_line; |
| 86 | pthread_mutex_unlockcxx . . $ pthread_mutex_unlock(d89ae235521888f9).(&stderr_mutexcxx . . $ stderr_mutex.); |
| 87 | } |
| 88 | |
| 89 | const char* btoacxx . . $ btoa(626eec357d49c77e).(boolcxx . . $ `<external>/13015445228558014418/stdbool.h:36:9`! b) { |
| 90 | return b?"true":"false"; |
| 91 | } |
| 92 | |
| 93 | void* checked_malloccxx . . $ checked_malloc(bfcfa4d6b7f7ef64).(size_t size) { |
| 94 | void * p = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(size); |
| 95 | if (p == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 96 | log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "malloc: failed to allocate %lu bytes of memory", (unsigned long) size); |
| 97 | exitcxx . . $ exit(3ca292c338df9bb3).(MEMORY_ALLOCATION_FAILUREcxx . . $ `include/errorcodes.h:33:9`!); |
| 98 | } |
| 99 | return p; |
| 100 | } |
| 101 | void* checked_calloccxx . . $ checked_calloc(63a7bf2941bfcd7a).(size_t nmemb, size_t size) { |
| 102 | void * p = calloccxx . . $ calloc(63a7bf2941bfcd7a).(nmemb, size); |
| 103 | if (p == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 104 | log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "calloc: failed to allocate %lu bytes of memory", (unsigned long) size); |
| 105 | exitcxx . . $ exit(3ca292c338df9bb3).(MEMORY_ALLOCATION_FAILUREcxx . . $ `include/errorcodes.h:33:9`!); |
| 106 | } |
| 107 | return p; |
| 108 | } |
| 109 | void* checked_strdupcxx . . $ checked_strdup(42228c1987407501).(const char *s) { |
| 110 | void * p = strdupcxx . . $ strdup(a8b8e32347182212).(s); |
| 111 | if (p == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 112 | log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "strdup: failed to allocate memory"); |
| 113 | exitcxx . . $ exit(3ca292c338df9bb3).(MEMORY_ALLOCATION_FAILUREcxx . . $ `include/errorcodes.h:33:9`!); |
| 114 | } |
| 115 | return p; |
| 116 | } |
| 117 | void* checked_strndupcxx . . $ checked_strndup(4fa1592a5e6de496).(const char *s, size_t size) { |
| 118 | void * p = strndupcxx . . $ strndup(eabdfdef77619b3d).(s, size); |
| 119 | if (p == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 120 | log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "strndup: failed to allocate memory"); |
| 121 | exitcxx . . $ exit(3ca292c338df9bb3).(MEMORY_ALLOCATION_FAILUREcxx . . $ `include/errorcodes.h:33:9`!); |
| 122 | } |
| 123 | return p; |
| 124 | } |
| 125 | void* checked_realloccxx . . $ checked_realloc(417ab160f6baadc6).(void *ptr, size_t size) { |
| 126 | void * p = realloccxx . . $ realloc(417ab160f6baadc6).(ptr,size); |
| 127 | if (p == NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 128 | log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "realloc: failed to re-allocate %lu bytes of memory", (unsigned long) size); |
| 129 | exitcxx . . $ exit(3ca292c338df9bb3).(MEMORY_ALLOCATION_FAILUREcxx . . $ `include/errorcodes.h:33:9`!); |
| 130 | } |
| 131 | return p; |
| 132 | } |
| 133 | |
| 134 | int cmpurlcxx . . $ cmpurl(4d6c4d40bb1e144a).(url_tcxx . . $ url_t#* u1,url_tcxx . . $ url_t#* u2) |
| 135 | { |
| 136 | if(u1->typecxx . . $ url_t#type.!= u2->typecxx . . $ url_t#type.){ |
| 137 | return RETFAILcxx . . $ `include/db_config.h:46:9`!; |
| 138 | }; |
| 139 | if(strcmpcxx . . $ strcmp(5ae29d726ae57f88).(u1->valuecxx . . $ url_t#value.,u2->valuecxx . . $ url_t#value.)!=0){ |
| 140 | return RETFAILcxx . . $ `include/db_config.h:46:9`!; |
| 141 | } |
| 142 | |
| 143 | return RETOKcxx . . $ `include/db_config.h:45:9`!; |
| 144 | } |
| 145 | |
| 146 | static size_t escape_strcxx . . $ escape_str(8a50657a649b6e15).(const char *unescaped_str, char *str, size_t s) { |
| 147 | size_t n = 0; |
| 148 | size_t i = 0; |
| 149 | char c; |
| 150 | while (i < s && (c = unescaped_str[i])) { |
| 151 | if ((c >= 0 && (c < 0x1f || c == 0x7f)) || |
| 152 | (c == '\\' && isdigitcxx . . $ `<external>/17904084882347303253/ctype.h:192:10`!(unescaped_str[i+1]) |
| 153 | && isdigitcxx . . $ `<external>/17904084882347303253/ctype.h:192:10`!(unescaped_str[i+2]) |
| 154 | && isdigitcxx . . $ `<external>/17904084882347303253/ctype.h:192:10`!(unescaped_str[i+3]) |
| 155 | ) ) { |
| 156 | if (str) { snprintfcxx . . $ snprintf(ea502d73e74c754c).(&str[n], 5, "\\%03o", c); } |
| 157 | n += 4; |
| 158 | } else { |
| 159 | if (str) { str[n] = c; } |
| 160 | n++; |
| 161 | } |
| 162 | i++; |
| 163 | } |
| 164 | if (str) { str[n] = '\0'; } |
| 165 | n++; |
| 166 | return n; |
| 167 | } |
| 168 | |
| 169 | char *strnesccxx . . $ strnesc(eabdfdef77619b3d).(const char *unescaped_str, size_t s) { |
| 170 | int n = escape_strcxx . . $ escape_str(8a50657a649b6e15).(unescaped_str, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!, s); |
| 171 | char *str = checked_malloccxx . . $ checked_malloc(bfcfa4d6b7f7ef64).(n); |
| 172 | escape_strcxx . . $ escape_str(8a50657a649b6e15).(unescaped_str, str, s); |
| 173 | return str; |
| 174 | } |
| 175 | |
| 176 | char *stresccxx . . $ stresc(a8b8e32347182212).(const char *unescaped_str) { |
| 177 | return strnesccxx . . $ strnesc(eabdfdef77619b3d).(unescaped_str, strlencxx . . $ strlen(751346f8406fd082).(unescaped_str)); |
| 178 | } |
| 179 | |
| 180 | /* Returns 1 if the string contains unsafe characters, 0 otherwise. */ |
| 181 | int contains_unsafecxx . . $ contains_unsafe(5c4306d8553b3696). (const char *s) |
| 182 | { |
| 183 | for (; *s; s++) |
| 184 | if (strchrcxx . . $ `<external>/13506128340496143423/string.h:264:11`! (URL_UNSAFEcxx . . $ `src/util.c:51:9`!,(int) *s)||!ISPRINTcxx . . $ `src/util.c:52:9`!((int)*s)) |
| 185 | return 1; |
| 186 | return 0; |
| 187 | } |
| 188 | |
| 189 | /* Decodes the forms %xy in a URL to the character the hexadecimal |
| 190 | code of which is xy. xy are hexadecimal digits from |
| 191 | [0123456789ABCDEF] (case-insensitive). If x or y are not |
| 192 | hex-digits or `%' precedes `\0', the sequence is inserted |
| 193 | literally. */ |
| 194 | |
| 195 | void decode_stringcxx . . $ decode_string(fda57c8427c60377). (char* s) |
| 196 | { |
| 197 | char *p = s; |
| 198 | |
| 199 | for (; *s; s++, p++) |
| 200 | { |
| 201 | if (*s != '%') |
| 202 | *p = *s; |
| 203 | else |
| 204 | { |
| 205 | /* Do nothing if at the end of the string, or if the chars |
| 206 | are not hex-digits. */ |
| 207 | if (!*(s + 1) || !*(s + 2) |
| 208 | || !(ISXDIGITcxx . . $ `include/util.h:38:9`! (*(s + 1)) && ISXDIGITcxx . . $ `include/util.h:38:9`! (*(s + 2)))) |
| 209 | { |
| 210 | *p = *s; |
| 211 | continue; |
| 212 | } |
| 213 | *p = (ASC2HEXDcxx . . $ `include/util.h:35:9`! (*(s + 1)) << 4) + ASC2HEXDcxx . . $ `include/util.h:35:9`! (*(s + 2)); |
| 214 | s += 2; |
| 215 | } |
| 216 | } |
| 217 | *p = '\0'; |
| 218 | } |
| 219 | |
| 220 | /* Encodes the unsafe characters (listed in URL_UNSAFE) in a given |
| 221 | string, returning a malloc-ed %XX encoded string. */ |
| 222 | char* encode_stringcxx . . $ encode_string(a8b8e32347182212). (const char* s) |
| 223 | { |
| 224 | const char *b; |
| 225 | char *p, *res; |
| 226 | int i; |
| 227 | |
| 228 | b = s; |
| 229 | for (i = 0; *s; s++, i++){ |
| 230 | if (strchrcxx . . $ `<external>/13506128340496143423/string.h:264:11`! (URL_UNSAFEcxx . . $ `src/util.c:51:9`!,(int) *s)||!ISPRINTcxx . . $ `src/util.c:52:9`!((int)*s)){ |
| 231 | i += 2; /* Two more characters (hex digits) */ |
| 232 | } |
| 233 | } |
| 234 | |
| 235 | res = (char *)checked_malloccxx . . $ checked_malloc(bfcfa4d6b7f7ef64). (i + 1); |
| 236 | s = b; |
| 237 | for (p = res; *s; s++){ |
| 238 | if (strchrcxx . . $ `<external>/13506128340496143423/string.h:264:11`! (URL_UNSAFEcxx . . $ `src/util.c:51:9`!, *s)||!ISPRINTcxx . . $ `src/util.c:52:9`!((int)*s)) |
| 239 | { |
| 240 | const unsigned char c = *s; |
| 241 | *p++ = '%'; |
| 242 | *p++ = HEXD2ASCcxx . . $ `include/util.h:33:9`! (c >> 4); |
| 243 | *p++ = HEXD2ASCcxx . . $ `include/util.h:33:9`! (c & 0xf); |
| 244 | } |
| 245 | else { |
| 246 | *p++ = *s; |
| 247 | } |
| 248 | } |
| 249 | *p = '\0'; |
| 250 | return res; |
| 251 | } |
| 252 | |
| 253 | char* byte_to_base16cxx . . $ byte_to_base16(422350ec2b3c7f).(const bytecxx . . $ byte#* src, size_t ssize) { |
| 254 | char* str = checked_malloccxx . . $ checked_malloc(bfcfa4d6b7f7ef64).((2*ssize+1) * sizeof (char)); |
| 255 | for(size_t i=0; i < ssize; ++i) { |
| 256 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(&str[2*i], 3, "%02x", src[i]); |
| 257 | } |
| 258 | return str; |
| 259 | } |
| 260 | |
| 261 | char *get_progress_bar_stringcxx . . $ get_progress_bar_string(567eccb82e01d0a1).(const char* state_str, const char* path, long unsigned num_entries, long unsigned num_skipped, int elapsed, int length) { |
| 262 | char *progress_bar = checked_malloccxx . . $ checked_malloc(bfcfa4d6b7f7ef64).(length+1); |
| 263 | int n = 0; |
| 264 | int left = length; |
| 265 | n += snprintfcxx . . $ snprintf(ea502d73e74c754c).(&progress_bar[n], left+1, "[%02d:%02d] %s> %lu %s", elapsed/60, elapsed%60, state_str, num_entries, num_entries == 1?"file":"files"); |
| 266 | left = length-n; |
| 267 | if (num_skipped && left > 0) { |
| 268 | n += snprintfcxx . . $ snprintf(ea502d73e74c754c).(&progress_bar[n], left+1, " (%lu skipped)", num_skipped); |
| 269 | left = length-n; |
| 270 | } |
| 271 | if (path && left > 0) { |
| 272 | const char *ellipsis = "/..."; |
| 273 | const char *last_str = ", last "; |
| 274 | int last_str_len = strlencxx . . $ strlen(751346f8406fd082).(last_str); |
| 275 | int ellipsis_len = 0; |
| 276 | int prefix_len = 0; |
| 277 | |
| 278 | const char *suffix_path = path; |
| 279 | if ((long) strlencxx . . $ strlen(751346f8406fd082).(path) > (left-last_str_len) ) { |
| 280 | const char *first_slash = strchrcxx . . $ `<external>/13506128340496143423/string.h:264:11`!(path+1, '/'); |
| 281 | if (first_slash) { |
| 282 | ellipsis_len = strlencxx . . $ strlen(751346f8406fd082).(ellipsis); |
| 283 | prefix_len = first_slash - path; |
| 284 | |
| 285 | suffix_path = first_slash+1; |
| 286 | |
| 287 | int path_left = left - last_str_len - prefix_len - ellipsis_len; |
| 288 | while ((long) strlencxx . . $ strlen(751346f8406fd082).(suffix_path) > path_left) { |
| 289 | char *slash = strchrcxx . . $ `<external>/13506128340496143423/string.h:264:11`!(suffix_path+1, '/'); |
| 290 | if (slash) { |
| 291 | suffix_path = slash; |
| 292 | } else { |
| 293 | break; |
| 294 | } |
| 295 | } |
| 296 | } |
| 297 | } |
| 298 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(&progress_bar[n], left+1, "%s%.*s%.*s%s", last_str, prefix_len, path, ellipsis_len, ellipsis, suffix_path); |
| 299 | } |
| 300 | return progress_bar; |
| 301 | } |
| 302 | |
| 303 | char* perm_to_charcxx . . $ perm_to_char(f109d7e0a0ca42b3).(mode_tcxx . . $ mode_t# perm) |
| 304 | { |
| 305 | char*pc=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 306 | int i=0; |
| 307 | |
| 308 | pc=(char*)checked_malloccxx . . $ checked_malloc(bfcfa4d6b7f7ef64).(sizeof(char)*11); |
| 309 | for(i=0;i<10;i++){ |
| 310 | pc[i]='-'; |
| 311 | } |
| 312 | pc[10]='\0'; |
| 313 | |
| 314 | if(S_ISDIRcxx . . $ `<external>/531885356569766532/stat.h:125:9`!(perm)) |
| 315 | pc[0]='d'; |
| 316 | #ifdef S_ISFIFOcxx . . $ `<external>/531885356569766532/stat.h:130:10`! |
| 317 | if(S_ISFIFOcxx . . $ `<external>/531885356569766532/stat.h:130:10`!(perm)) |
| 318 | pc[0]='p'; |
| 319 | #endif |
| 320 | if(S_ISLNKcxx . . $ `<external>/531885356569766532/stat.h:133:10`!(perm)) |
| 321 | pc[0]='l'; |
| 322 | if(S_ISBLKcxx . . $ `<external>/531885356569766532/stat.h:127:9`!(perm)) |
| 323 | pc[0]='b'; |
| 324 | if(S_ISCHRcxx . . $ `<external>/531885356569766532/stat.h:126:9`!(perm)) |
| 325 | pc[0]='c'; |
| 326 | #ifdef S_ISDOOR |
| 327 | if(S_ISDOOR(perm)) |
| 328 | pc[0]='|'; |
| 329 | #endif |
| 330 | #ifdef S_ISSOCKcxx . . $ `<external>/531885356569766532/stat.h:142:10`! |
| 331 | if(S_ISSOCKcxx . . $ `<external>/531885356569766532/stat.h:142:10`!(perm)) |
| 332 | pc[0]='s'; |
| 333 | #endif |
| 334 | |
| 335 | if((S_IRUSRcxx . . $ `<external>/531885356569766532/stat.h:168:9`!&perm)==S_IRUSRcxx . . $ `<external>/531885356569766532/stat.h:168:9`!){ |
| 336 | pc[1]='r'; |
| 337 | } |
| 338 | if((S_IWUSRcxx . . $ `<external>/531885356569766532/stat.h:169:9`!&perm)==S_IWUSRcxx . . $ `<external>/531885356569766532/stat.h:169:9`!){ |
| 339 | pc[2]='w'; |
| 340 | } |
| 341 | if((S_IXUSRcxx . . $ `<external>/531885356569766532/stat.h:170:9`!&perm)==S_IXUSRcxx . . $ `<external>/531885356569766532/stat.h:170:9`!){ |
| 342 | pc[3]='x'; |
| 343 | } |
| 344 | if((S_IRGRPcxx . . $ `<external>/531885356569766532/stat.h:180:9`!&perm)==S_IRGRPcxx . . $ `<external>/531885356569766532/stat.h:180:9`!){ |
| 345 | pc[4]='r'; |
| 346 | } |
| 347 | if((S_IWGRPcxx . . $ `<external>/531885356569766532/stat.h:181:9`!&perm)==S_IWGRPcxx . . $ `<external>/531885356569766532/stat.h:181:9`!){ |
| 348 | pc[5]='w'; |
| 349 | } |
| 350 | if((S_IXGRPcxx . . $ `<external>/531885356569766532/stat.h:182:9`!&perm)==S_IXGRPcxx . . $ `<external>/531885356569766532/stat.h:182:9`!){ |
| 351 | pc[6]='x'; |
| 352 | } |
| 353 | if((S_IROTHcxx . . $ `<external>/531885356569766532/stat.h:186:9`!&perm)==S_IROTHcxx . . $ `<external>/531885356569766532/stat.h:186:9`!){ |
| 354 | pc[7]='r'; |
| 355 | } |
| 356 | if((S_IWOTHcxx . . $ `<external>/531885356569766532/stat.h:187:9`!&perm)==S_IWOTHcxx . . $ `<external>/531885356569766532/stat.h:187:9`!){ |
| 357 | pc[8]='w'; |
| 358 | } |
| 359 | if((S_IXOTHcxx . . $ `<external>/531885356569766532/stat.h:188:9`!&perm)==S_IXOTHcxx . . $ `<external>/531885356569766532/stat.h:188:9`!){ |
| 360 | pc[9]='x'; |
| 361 | } |
| 362 | |
| 363 | if((S_ISUIDcxx . . $ `<external>/531885356569766532/stat.h:160:9`!&perm)==S_ISUIDcxx . . $ `<external>/531885356569766532/stat.h:160:9`!){ |
| 364 | if((S_IXUSRcxx . . $ `<external>/531885356569766532/stat.h:170:9`!&perm)==S_IXUSRcxx . . $ `<external>/531885356569766532/stat.h:170:9`!){ |
| 365 | pc[3]='s'; |
| 366 | } else { |
| 367 | pc[3]='S'; |
| 368 | } |
| 369 | } |
| 370 | if((S_ISGIDcxx . . $ `<external>/531885356569766532/stat.h:161:9`!&perm)==S_ISGIDcxx . . $ `<external>/531885356569766532/stat.h:161:9`!){ |
| 371 | if((S_IXGRPcxx . . $ `<external>/531885356569766532/stat.h:182:9`!&perm)==S_IXGRPcxx . . $ `<external>/531885356569766532/stat.h:182:9`!){ |
| 372 | pc[6]='s'; |
| 373 | } else { |
| 374 | pc[6]='l'; |
| 375 | } |
| 376 | } |
| 377 | #if defined (S_ISVTXcxx . . $ `<external>/531885356569766532/stat.h:165:10`!) && defined (S_IXOTHcxx . . $ `<external>/531885356569766532/stat.h:188:9`!) |
| 378 | if((S_ISVTXcxx . . $ `<external>/531885356569766532/stat.h:165:10`!&perm)==S_ISVTXcxx . . $ `<external>/531885356569766532/stat.h:165:10`!){ |
| 379 | if((S_IXOTHcxx . . $ `<external>/531885356569766532/stat.h:188:9`!&perm)==S_IXOTHcxx . . $ `<external>/531885356569766532/stat.h:188:9`!){ |
| 380 | pc[9]='t'; |
| 381 | } else { |
| 382 | pc[9]='T'; |
| 383 | } |
| 384 | } |
| 385 | #endif |
| 386 | |
| 387 | log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_TRACEcxx . . $ LOG_LEVEL_TRACE., "perm_to_char: %i -> %s",perm,pc); |
| 388 | |
| 389 | return pc; |
| 390 | } |
| 391 | |
| 392 | char *expand_tildecxx . . $ expand_tilde(7a9722d75b371431).(char *path) { |
| 393 | char *homedir = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 394 | char *full = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 395 | |
| 396 | if (path != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 397 | if (path[0] == '~') { |
| 398 | if((homedir=getenvcxx . . $ getenv(a8b8e32347182212).("HOME")) != NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!) { |
| 399 | size_t path_len, homedir_len, full_len; |
| 400 | path_len = strlencxx . . $ strlen(751346f8406fd082).(path+sizeof(char)); |
| 401 | homedir_len = strlencxx . . $ strlen(751346f8406fd082).(homedir); |
| 402 | full_len = (homedir_len+path_len+1) * sizeof(char); |
| 403 | full = checked_malloccxx . . $ checked_malloc(bfcfa4d6b7f7ef64).(full_len); |
| 404 | snprintfcxx . . $ snprintf(ea502d73e74c754c).(full, full_len, "%s%s", homedir, path+sizeof(char)); |
| 405 | log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_DEBUGcxx . . $ LOG_LEVEL_DEBUG., "expanded '~' in '%s' to '%s'", path, full); |
| 406 | freecxx . . $ free(5d22bdacc48458e8).(path); |
| 407 | /* Don't free(homedir); because it is not safe on some platforms */ |
| 408 | path = full; |
| 409 | } else { |
| 410 | log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., _cxx . . $ `include/locale-aide.h:33:9`!("Variable name 'HOME' not found in environment. '~' cannot be expanded")); |
| 411 | } |
| 412 | } else if (path[0] == '\\' && path[1] == '~') { |
| 413 | path += sizeof(char); |
| 414 | } |
| 415 | } |
| 416 | return path; |
| 417 | } |
| 418 | |
| 419 | char* pipe2stringcxx . . $ pipe2string(ff224f080444ee45).(int fd) { |
| 420 | int nbytes; |
| 421 | char buffer[1024]; |
| 422 | |
| 423 | char* str = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 424 | while ((nbytes = readcxx . . $ read(7e34d0a36f355389).(fd, buffer, sizeof(buffer))) > 0) { |
| 425 | int str_len = str?strlencxx . . $ strlen(751346f8406fd082).(str):0U; |
| 426 | int len = str_len+nbytes; |
| 427 | str = checked_realloccxx . . $ checked_realloc(417ab160f6baadc6).(str, (len+1)*sizeof(char)); |
| 428 | strncpycxx . . $ strncpy(255158a415b673b0).(str+str_len, buffer, nbytes); |
| 429 | str[len] = '\0'; |
| 430 | } |
| 431 | return str; |
| 432 | } |
| 433 | |
| 434 | char* get_time_stringcxx . . $ get_time_string(4e4bbfda8d4b3d77).(const time_tcxx . . $ time_t# *tm) { |
| 435 | const char time_format[] = "%Y-%m-%d %H:%M:%S %z"; |
| 436 | int time_string_len = strlencxx . . $ strlen(751346f8406fd082).("1979-01-01 01:00:00 +0100")+1; |
| 437 | |
| 438 | char *time = checked_malloccxx . . $ checked_malloc(bfcfa4d6b7f7ef64).(time_string_len * sizeof (char)); |
| 439 | strftimecxx . . $ strftime(98e75925167c4f1b).(time, time_string_len, time_format, localtimecxx . . $ localtime(9477a1348abbbc5).(tm)); |
| 440 | |
| 441 | return time; |
| 442 | } |
| 443 | |
| 444 | void mask_sigcxx . . $ mask_sig(85c52e162fed56f9).(const char* whoami) { |
| 445 | sigset_tcxx . . $ sigset_t# set; |
| 446 | |
| 447 | sigemptysetcxx . . $ sigemptyset(f9c066a8ff75ee9d).(&set); |
| 448 | sigaddsetcxx . . $ sigaddset(4917c6e3ecb7dbd5).(&set, SIGINTcxx . . $ `<external>/11773118241360591791/signum-generic.h:48:9`!); |
| 449 | sigaddsetcxx . . $ sigaddset(4917c6e3ecb7dbd5).(&set, SIGTERMcxx . . $ `<external>/11773118241360591791/signum-generic.h:53:9`!); |
| 450 | sigaddsetcxx . . $ sigaddset(4917c6e3ecb7dbd5).(&set, SIGHUPcxx . . $ `<external>/11773118241360591791/signum-generic.h:56:9`!); |
| 451 | sigaddsetcxx . . $ sigaddset(4917c6e3ecb7dbd5).(&set, SIGUSR1cxx . . $ `<external>/1457673850468744829/signum-arch.h:49:9`!); |
| 452 | sigaddsetcxx . . $ sigaddset(4917c6e3ecb7dbd5).(&set, SIGWINCHcxx . . $ `<external>/1457673850468744829/signum-arch.h:54:9`!); |
| 453 | |
| 454 | if(pthread_sigmaskcxx . . $ pthread_sigmask(7504382baa173b1).(SIG_BLOCKcxx . . $ `<external>/16635209305659446502/sigaction.h:79:9`!, &set, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!)) { |
| 455 | log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_ERRORcxx . . $ LOG_LEVEL_ERROR., "%10s: pthread_sigmask failed to set mask of blocked signals", whoami); |
| 456 | exitcxx . . $ exit(3ca292c338df9bb3).(THREAD_ERRORcxx . . $ `include/errorcodes.h:34:9`!); |
| 457 | } |
| 458 | } |
| 459 | |
| 460 | /* Like strstr but only do search for maximum of n chars. |
| 461 | haystack does not have to be NULL terminated |
| 462 | needle has to be NULL terminated. NULL in needle is not used in compare. |
| 463 | NULLs in haystack are ignored. |
| 464 | */ |
| 465 | #ifndef HAVE_STRNSTR |
| 466 | char* strnstrcxx . . $ strnstr(4b1661a75e253f1d).(char* haystack,char* needle,int n) |
| 467 | { |
| 468 | char* h=haystack; |
| 469 | char* s=needle; |
| 470 | int slen=strlencxx . . $ strlen(751346f8406fd082).(s); |
| 471 | int i=0; |
| 472 | |
| 473 | for(i=0;i<n;i++){ |
| 474 | /* If terminating NULL is reached in needle string |
| 475 | then we have a match */ |
| 476 | if(*s=='\0'){ |
| 477 | return &haystack[i-slen]; |
| 478 | } |
| 479 | if(*s==*h){ |
| 480 | s++; |
| 481 | }else{ |
| 482 | s=needle; |
| 483 | } |
| 484 | h++; |
| 485 | } |
| 486 | /* Handle the special case that we are at the end of haystack |
| 487 | and match is right at the end |
| 488 | */ |
| 489 | if(*s=='\0'){ |
| 490 | return &haystack[i-slen]; |
| 491 | } |
| 492 | |
| 493 | /* If we get this far no match was found so we return NULL */ |
| 494 | return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/16/include/stddef.h:419:9`!; |
| 495 | } |
| 496 | #endif |
| 497 | |
| 498 | #ifndef HAVE_STRNLENcxx . . $ `./include/config.h:98:9`! |
| 499 | size_t strnlen(const char *s, size_t maxlen) |
| 500 | { |
| 501 | size_t l; |
| 502 | l=strlen(s); |
| 503 | if(l>maxlen) |
| 504 | return maxlen; |
| 505 | return l; |
| 506 | } |
| 507 | #endif |
| 508 | |
| 509 | #ifdef HAVE_SYSLOGcxx . . $ `./include/config.h:110:9`! |
| 510 | /* Lookup syslog facilities by name */ |
| 511 | int syslog_facility_lookupcxx . . $ syslog_facility_lookup(1ef8e6ec083aabb9).(char *s) |
| 512 | { |
| 513 | if(!s || strlencxx . . $ strlen(751346f8406fd082).(s)<1) |
| 514 | return(AIDE_SYSLOG_FACILITYcxx . . $ `./include/config.h:20:9`!); |
| 515 | #ifdef LOG_KERNcxx . . $ `<external>/6168640806541382331/syslog.h:93:9`! |
| 516 | if(strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(s,"LOG_KERN")==0) |
| 517 | return(LOG_KERNcxx . . $ `<external>/6168640806541382331/syslog.h:93:9`!); |
| 518 | #endif |
| 519 | #ifdef LOG_USERcxx . . $ `<external>/6168640806541382331/syslog.h:94:9`! |
| 520 | if(strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(s,"LOG_USER")==0) |
| 521 | return(LOG_USERcxx . . $ `<external>/6168640806541382331/syslog.h:94:9`!); |
| 522 | #endif |
| 523 | #ifdef LOG_MAILcxx . . $ `<external>/6168640806541382331/syslog.h:95:9`! |
| 524 | if(strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(s,"LOG_MAIL")==0) |
| 525 | return(LOG_MAILcxx . . $ `<external>/6168640806541382331/syslog.h:95:9`!); |
| 526 | #endif |
| 527 | #ifdef LOG_DAEMONcxx . . $ `<external>/6168640806541382331/syslog.h:96:9`! |
| 528 | if(strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(s,"LOG_DAEMON")==0) |
| 529 | return(LOG_DAEMONcxx . . $ `<external>/6168640806541382331/syslog.h:96:9`!); |
| 530 | #endif |
| 531 | #ifdef LOG_AUTHcxx . . $ `<external>/6168640806541382331/syslog.h:97:9`! |
| 532 | if(strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(s,"LOG_AUTH")==0) |
| 533 | return(LOG_AUTHcxx . . $ `<external>/6168640806541382331/syslog.h:97:9`!); |
| 534 | #endif |
| 535 | #ifdef LOG_SYSLOGcxx . . $ `<external>/6168640806541382331/syslog.h:98:9`! |
| 536 | if(strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(s,"LOG_SYSLOG")==0) |
| 537 | return(LOG_SYSLOGcxx . . $ `<external>/6168640806541382331/syslog.h:98:9`!); |
| 538 | #endif |
| 539 | #ifdef LOG_LPRcxx . . $ `<external>/6168640806541382331/syslog.h:99:9`! |
| 540 | if(strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(s,"LOG_LPR")==0) |
| 541 | return(LOG_LPRcxx . . $ `<external>/6168640806541382331/syslog.h:99:9`!); |
| 542 | #endif |
| 543 | #ifdef LOG_NEWScxx . . $ `<external>/6168640806541382331/syslog.h:100:9`! |
| 544 | if(strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(s,"LOG_NEWS")==0) |
| 545 | return(LOG_NEWScxx . . $ `<external>/6168640806541382331/syslog.h:100:9`!); |
| 546 | #endif |
| 547 | #ifdef LOG_UUCPcxx . . $ `<external>/6168640806541382331/syslog.h:101:9`! |
| 548 | if(strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(s,"LOG_UUCP")==0) |
| 549 | return(LOG_UUCPcxx . . $ `<external>/6168640806541382331/syslog.h:101:9`!); |
| 550 | #endif |
| 551 | #ifdef LOG_CRONcxx . . $ `<external>/6168640806541382331/syslog.h:102:9`! |
| 552 | if(strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(s,"LOG_CRON")==0) |
| 553 | return(LOG_CRONcxx . . $ `<external>/6168640806541382331/syslog.h:102:9`!); |
| 554 | #endif |
| 555 | #ifdef LOG_LOCAL0cxx . . $ `<external>/6168640806541382331/syslog.h:107:9`! |
| 556 | if(strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(s,"LOG_LOCAL0")==0) |
| 557 | return(LOG_LOCAL0cxx . . $ `<external>/6168640806541382331/syslog.h:107:9`!); |
| 558 | #endif |
| 559 | #ifdef LOG_LOCAL1cxx . . $ `<external>/6168640806541382331/syslog.h:108:9`! |
| 560 | if(strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(s,"LOG_LOCAL1")==0) |
| 561 | return(LOG_LOCAL1cxx . . $ `<external>/6168640806541382331/syslog.h:108:9`!); |
| 562 | #endif |
| 563 | #ifdef LOG_LOCAL2cxx . . $ `<external>/6168640806541382331/syslog.h:109:9`! |
| 564 | if(strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(s,"LOG_LOCAL2")==0) |
| 565 | return(LOG_LOCAL2cxx . . $ `<external>/6168640806541382331/syslog.h:109:9`!); |
| 566 | #endif |
| 567 | #ifdef LOG_LOCAL3cxx . . $ `<external>/6168640806541382331/syslog.h:110:9`! |
| 568 | if(strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(s,"LOG_LOCAL3")==0) |
| 569 | return(LOG_LOCAL3cxx . . $ `<external>/6168640806541382331/syslog.h:110:9`!); |
| 570 | #endif |
| 571 | #ifdef LOG_LOCAL4cxx . . $ `<external>/6168640806541382331/syslog.h:111:9`! |
| 572 | if(strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(s,"LOG_LOCAL4")==0) |
| 573 | return(LOG_LOCAL4cxx . . $ `<external>/6168640806541382331/syslog.h:111:9`!); |
| 574 | #endif |
| 575 | #ifdef LOG_LOCAL5cxx . . $ `<external>/6168640806541382331/syslog.h:112:9`! |
| 576 | if(strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(s,"LOG_LOCAL5")==0) |
| 577 | return(LOG_LOCAL5cxx . . $ `<external>/6168640806541382331/syslog.h:112:9`!); |
| 578 | #endif |
| 579 | #ifdef LOG_LOCAL6cxx . . $ `<external>/6168640806541382331/syslog.h:113:9`! |
| 580 | if(strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(s,"LOG_LOCAL6")==0) |
| 581 | return(LOG_LOCAL6cxx . . $ `<external>/6168640806541382331/syslog.h:113:9`!); |
| 582 | #endif |
| 583 | #ifdef LOG_LOCAL7cxx . . $ `<external>/6168640806541382331/syslog.h:114:9`! |
| 584 | if(strcasecmpcxx . . $ strcasecmp(5ae29d726ae57f88).(s,"LOG_LOCAL7")==0) |
| 585 | return(LOG_LOCAL7cxx . . $ `<external>/6168640806541382331/syslog.h:114:9`!); |
| 586 | #endif |
| 587 | |
| 588 | log_msgcxx . . $ log_msg(e585f2b5603b5bf9).(LOG_LEVEL_WARNINGcxx . . $ LOG_LEVEL_WARNING., "Syslog facility \"%s\" is unknown, using default",s); |
| 589 | return(AIDE_SYSLOG_FACILITYcxx . . $ `./include/config.h:20:9`!); |
| 590 | } |
| 591 | #endif |