[1] | 1 | /* SAMHAIN file system integrity testing */
|
---|
| 2 | /* Copyright (C) 1999 Rainer Wichmann */
|
---|
| 3 | /* */
|
---|
| 4 | /* This program is free software; you can redistribute it */
|
---|
| 5 | /* and/or modify */
|
---|
| 6 | /* it under the terms of the GNU General Public License as */
|
---|
| 7 | /* published by */
|
---|
| 8 | /* the Free Software Foundation; either version 2 of the License, or */
|
---|
| 9 | /* (at your option) any later version. */
|
---|
| 10 | /* */
|
---|
| 11 | /* This program is distributed in the hope that it will be useful, */
|
---|
| 12 | /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
---|
| 13 | /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
---|
| 14 | /* GNU General Public License for more details. */
|
---|
| 15 | /* */
|
---|
| 16 | /* You should have received a copy of the GNU General Public License */
|
---|
| 17 | /* along with this program; if not, write to the Free Software */
|
---|
| 18 | /* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
|
---|
| 19 |
|
---|
| 20 |
|
---|
| 21 | #ifndef SH_UTILS_H
|
---|
| 22 | #define SH_UTILS_H
|
---|
| 23 |
|
---|
| 24 | #include <stdarg.h>
|
---|
| 25 |
|
---|
| 26 | #include "slib.h"
|
---|
| 27 |
|
---|
| 28 | #include "sh_error.h"
|
---|
| 29 | #include "sh_unix.h"
|
---|
| 30 |
|
---|
| 31 | #define S_FMT_STRING 1
|
---|
| 32 | #define S_FMT_ULONG 2
|
---|
| 33 | #define S_FMT_TIME 3
|
---|
| 34 | #define S_FMT_LONG 4
|
---|
| 35 |
|
---|
| 36 |
|
---|
| 37 | typedef struct ft_struc {
|
---|
| 38 | char fchar;
|
---|
| 39 | int type;
|
---|
| 40 | unsigned long data_ulong;
|
---|
| 41 | long data_long;
|
---|
| 42 | /*@null@*/char *data_str;
|
---|
| 43 | } st_format;
|
---|
| 44 |
|
---|
| 45 | char * sh_util_formatted (const char * fmt, st_format * ftab);
|
---|
| 46 |
|
---|
| 47 | typedef struct sh_timeout_struct {
|
---|
| 48 | UINT64 time_last;
|
---|
| 49 | UINT64 time_dist;
|
---|
| 50 | int flag_ok;
|
---|
| 51 | } SH_TIMEOUT;
|
---|
| 52 |
|
---|
| 53 | int sh_util_timeout_check (SH_TIMEOUT * sh_timer);
|
---|
| 54 |
|
---|
| 55 | /* This is a maximally equidistributed combined Tausworthe
|
---|
| 56 | * generator.
|
---|
| 57 | */
|
---|
| 58 | UINT32 taus_get (void *state1, void *state2, void *state3);
|
---|
| 59 | double taus_get_double (void *vstate); /* fast */
|
---|
| 60 | int taus_seed (void);
|
---|
| 61 |
|
---|
| 62 | char * sh_util_strdup (const char * str);
|
---|
| 63 | char * sh_util_strsep (char **str, const char *delim);
|
---|
| 64 |
|
---|
| 65 | /* set signature type HASH-TIGER/HMAC-TIGER
|
---|
| 66 | */
|
---|
[22] | 67 | int sh_util_sigtype (const char * c);
|
---|
[1] | 68 |
|
---|
| 69 | /* compute a signature
|
---|
| 70 | */
|
---|
| 71 | char * sh_util_siggen (char * hexkey,
|
---|
| 72 | char * text, size_t textlen);
|
---|
| 73 |
|
---|
| 74 | /* eval boolean input
|
---|
| 75 | */
|
---|
[20] | 76 | int sh_util_flagval(const char * c, int * fval);
|
---|
[1] | 77 |
|
---|
| 78 | /* ask if a file should be updated (returns S_TRUE/S_FALSE)
|
---|
| 79 | */
|
---|
| 80 | int sh_util_ask_update(char * path);
|
---|
[20] | 81 | int sh_util_set_interactive(const char * str);
|
---|
[1] | 82 |
|
---|
| 83 | /* don't log output files
|
---|
| 84 | */
|
---|
[22] | 85 | int sh_util_hidesetup(const char * c);
|
---|
[1] | 86 |
|
---|
| 87 | /* exceptions to obscure name check
|
---|
| 88 | */
|
---|
[22] | 89 | int sh_util_obscure_ok (const char * str);
|
---|
[1] | 90 |
|
---|
| 91 | /* read a hexchar
|
---|
| 92 | */
|
---|
| 93 | int sh_util_hexchar( char c );
|
---|
| 94 |
|
---|
| 95 | /* change verifier
|
---|
| 96 | */
|
---|
[20] | 97 | int sh_util_set_newkey (const char * str);
|
---|
[1] | 98 |
|
---|
| 99 | /* server mode
|
---|
| 100 | */
|
---|
[20] | 101 | int sh_util_setserver (const char * dummy);
|
---|
[1] | 102 |
|
---|
| 103 | /* a simple compressor
|
---|
| 104 | */
|
---|
| 105 | long sh_util_compress (char * dest, char * src, size_t dest_size);
|
---|
| 106 |
|
---|
| 107 | /* an even simpler en-/decoder
|
---|
| 108 | */
|
---|
| 109 | void sh_util_encode (char * data, char * salt, int mode, char fill);
|
---|
| 110 |
|
---|
| 111 | /* copy len ( < 4) bytes from (char *) (long src) to (char *) dest,
|
---|
| 112 | * determine the four LSB's and use them (independent of sizeof(long))
|
---|
| 113 | */
|
---|
| 114 | void sh_util_cpylong (char * dest, const char * src, int len );
|
---|
| 115 |
|
---|
| 116 | /* set timer for main loop
|
---|
| 117 | */
|
---|
[20] | 118 | int sh_util_setlooptime (const char * str);
|
---|
[1] | 119 |
|
---|
| 120 | /* whether init or check the database
|
---|
| 121 | */
|
---|
[20] | 122 | int sh_util_setchecksum (const char * str);
|
---|
[1] | 123 |
|
---|
| 124 | /* compare an in_string against a regular expression regex_str
|
---|
| 125 | return GOOD on successful match
|
---|
| 126 | */
|
---|
| 127 | int sh_util_regcmp (char * regex_str, char * in_str);
|
---|
| 128 |
|
---|
| 129 |
|
---|
| 130 | /* returns freshly allocated memory, return value should be free'd.
|
---|
| 131 | * Arhument list must be NULL terminated.
|
---|
| 132 | */
|
---|
| 133 | char * sh_util_strconcat (const char * arg1, ...);
|
---|
| 134 |
|
---|
| 135 | /* check if string is numeric only
|
---|
| 136 | */
|
---|
| 137 | int sh_util_isnum (char *str);
|
---|
| 138 |
|
---|
| 139 | /* init a key w/random string
|
---|
| 140 | */
|
---|
| 141 | int sh_util_keyinit (char * buf, long size);
|
---|
| 142 |
|
---|
| 143 |
|
---|
| 144 | /* returns freshly allocated memory, return value should be free'd
|
---|
| 145 | */
|
---|
[34] | 146 | char * sh_util_dirname(const char * fullpath);
|
---|
[1] | 147 |
|
---|
| 148 | /* returns freshly allocated memory, return value should be free'd
|
---|
| 149 | */
|
---|
| 150 | char * sh_util_safe_name (const char * name);
|
---|
| 151 |
|
---|
| 152 | /* check max size of printf result string
|
---|
| 153 | */
|
---|
| 154 | int sh_util_printf_maxlength (const char * fmt, va_list vl);
|
---|
| 155 |
|
---|
| 156 | /* check for obscure filenames
|
---|
| 157 | */
|
---|
| 158 | int sh_util_obscurename (ShErrLevel level, char * name, int flag);
|
---|
| 159 |
|
---|
| 160 | /* returns freshly allocated memory, return value should be free'd
|
---|
| 161 | */
|
---|
[34] | 162 | char * sh_util_basename(const char * fullpath);
|
---|
[1] | 163 |
|
---|
| 164 | #endif
|
---|