[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;
|
---|
[214] | 42 | char *data_str;
|
---|
[1] | 43 | } st_format;
|
---|
| 44 |
|
---|
[132] | 45 | /* returns allocated string
|
---|
| 46 | */
|
---|
[1] | 47 | char * sh_util_formatted (const char * fmt, st_format * ftab);
|
---|
| 48 |
|
---|
| 49 | typedef struct sh_timeout_struct {
|
---|
| 50 | UINT64 time_last;
|
---|
| 51 | UINT64 time_dist;
|
---|
| 52 | int flag_ok;
|
---|
| 53 | } SH_TIMEOUT;
|
---|
| 54 |
|
---|
| 55 | int sh_util_timeout_check (SH_TIMEOUT * sh_timer);
|
---|
| 56 |
|
---|
| 57 | /* This is a maximally equidistributed combined Tausworthe
|
---|
| 58 | * generator.
|
---|
| 59 | */
|
---|
[170] | 60 | UINT32 taus_get (void);
|
---|
[1] | 61 | double taus_get_double (void *vstate); /* fast */
|
---|
| 62 | int taus_seed (void);
|
---|
| 63 |
|
---|
[132] | 64 | /* returns allocated memory
|
---|
| 65 | */
|
---|
[149] | 66 | char * sh_util_strdup (const char * str) SH_GNUC_MALLOC;
|
---|
[132] | 67 |
|
---|
| 68 | /* returns allocated memory
|
---|
| 69 | */
|
---|
[149] | 70 | char * sh_util_strdup_l (const char * str, size_t len) SH_GNUC_MALLOC;
|
---|
[132] | 71 |
|
---|
| 72 | /* returns pointer within str
|
---|
| 73 | */
|
---|
[1] | 74 | char * sh_util_strsep (char **str, const char *delim);
|
---|
| 75 |
|
---|
[132] | 76 | /* compactify verbose acl text, returns allocated memory
|
---|
[68] | 77 | */
|
---|
| 78 | char * sh_util_acl_compact (char * buf, ssize_t len);
|
---|
| 79 |
|
---|
[1] | 80 | /* set signature type HASH-TIGER/HMAC-TIGER
|
---|
| 81 | */
|
---|
[22] | 82 | int sh_util_sigtype (const char * c);
|
---|
[1] | 83 |
|
---|
| 84 | /* compute a signature
|
---|
| 85 | */
|
---|
| 86 | char * sh_util_siggen (char * hexkey,
|
---|
[138] | 87 | char * text, size_t textlen,
|
---|
| 88 | char * sigbuf, size_t sigbuflen);
|
---|
[1] | 89 |
|
---|
| 90 | /* eval boolean input
|
---|
| 91 | */
|
---|
[20] | 92 | int sh_util_flagval(const char * c, int * fval);
|
---|
[1] | 93 |
|
---|
| 94 | /* ask if a file should be updated (returns S_TRUE/S_FALSE)
|
---|
| 95 | */
|
---|
[305] | 96 | int sh_util_ask_update(const char * path);
|
---|
[20] | 97 | int sh_util_set_interactive(const char * str);
|
---|
[355] | 98 | int sh_util_update_file (const char * str);
|
---|
[1] | 99 |
|
---|
| 100 | /* don't log output files
|
---|
| 101 | */
|
---|
[22] | 102 | int sh_util_hidesetup(const char * c);
|
---|
[1] | 103 |
|
---|
[68] | 104 | /* valif utf-8 string
|
---|
| 105 | */
|
---|
| 106 | int sh_util_valid_utf8 (const unsigned char * str);
|
---|
| 107 |
|
---|
| 108 | /* filenames are utf8
|
---|
| 109 | */
|
---|
| 110 | int sh_util_obscure_utf8 (const char * c);
|
---|
| 111 |
|
---|
[1] | 112 | /* exceptions to obscure name check
|
---|
| 113 | */
|
---|
[22] | 114 | int sh_util_obscure_ok (const char * str);
|
---|
[1] | 115 |
|
---|
[138] | 116 | /* output a hexchar[2]; i2h must be char[2]
|
---|
[1] | 117 | */
|
---|
[138] | 118 | char * sh_util_charhex( unsigned char c, char * i2h );
|
---|
[93] | 119 |
|
---|
| 120 | /* read a hexchar, return int value (0-15)
|
---|
| 121 | */
|
---|
[149] | 122 | int sh_util_hexchar( char c ) SH_GNUC_CONST;
|
---|
[1] | 123 |
|
---|
| 124 | /* change verifier
|
---|
| 125 | */
|
---|
[20] | 126 | int sh_util_set_newkey (const char * str);
|
---|
[1] | 127 |
|
---|
| 128 | /* server mode
|
---|
| 129 | */
|
---|
[20] | 130 | int sh_util_setserver (const char * dummy);
|
---|
[1] | 131 |
|
---|
| 132 | /* a simple compressor
|
---|
| 133 | */
|
---|
[214] | 134 | size_t sh_util_compress (char * dest, char * src, size_t dest_size);
|
---|
[1] | 135 |
|
---|
| 136 | /* an even simpler en-/decoder
|
---|
| 137 | */
|
---|
| 138 | void sh_util_encode (char * data, char * salt, int mode, char fill);
|
---|
| 139 |
|
---|
| 140 | /* copy len ( < 4) bytes from (char *) (long src) to (char *) dest,
|
---|
| 141 | * determine the four LSB's and use them (independent of sizeof(long))
|
---|
| 142 | */
|
---|
| 143 | void sh_util_cpylong (char * dest, const char * src, int len );
|
---|
| 144 |
|
---|
| 145 | /* set timer for main loop
|
---|
| 146 | */
|
---|
[20] | 147 | int sh_util_setlooptime (const char * str);
|
---|
[1] | 148 |
|
---|
| 149 | /* whether init or check the database
|
---|
| 150 | */
|
---|
[20] | 151 | int sh_util_setchecksum (const char * str);
|
---|
[1] | 152 |
|
---|
| 153 | /* compare an in_string against a regular expression regex_str
|
---|
| 154 | return GOOD on successful match
|
---|
| 155 | */
|
---|
| 156 | int sh_util_regcmp (char * regex_str, char * in_str);
|
---|
| 157 |
|
---|
| 158 |
|
---|
| 159 | /* returns freshly allocated memory, return value should be free'd.
|
---|
[132] | 160 | * Argument list must be NULL terminated.
|
---|
[1] | 161 | */
|
---|
[149] | 162 | char * sh_util_strconcat (const char * arg1, ...) SH_GNUC_MALLOC SH_GNUC_SENTINEL;
|
---|
[1] | 163 |
|
---|
| 164 | /* check if string is numeric only
|
---|
| 165 | */
|
---|
[149] | 166 | int sh_util_isnum (const char *str) SH_GNUC_PURE;
|
---|
[1] | 167 |
|
---|
| 168 | /* init a key w/random string
|
---|
| 169 | */
|
---|
| 170 | int sh_util_keyinit (char * buf, long size);
|
---|
| 171 |
|
---|
| 172 |
|
---|
| 173 | /* returns freshly allocated memory, return value should be free'd
|
---|
| 174 | */
|
---|
[34] | 175 | char * sh_util_dirname(const char * fullpath);
|
---|
[1] | 176 |
|
---|
| 177 | /* returns freshly allocated memory, return value should be free'd
|
---|
| 178 | */
|
---|
[149] | 179 | char * sh_util_safe_name (const char * name) SH_GNUC_MALLOC SH_GNUC_PURE;
|
---|
[1] | 180 |
|
---|
[185] | 181 | char * sh_util_safe_name_keepspace (const char * name) SH_GNUC_MALLOC SH_GNUC_PURE;
|
---|
| 182 |
|
---|
[1] | 183 | /* check max size of printf result string
|
---|
| 184 | */
|
---|
| 185 | int sh_util_printf_maxlength (const char * fmt, va_list vl);
|
---|
| 186 |
|
---|
| 187 | /* check for obscure filenames
|
---|
| 188 | */
|
---|
[373] | 189 | int sh_util_obscurename (ShErrLevel level, const char * name, int flag);
|
---|
[1] | 190 |
|
---|
| 191 | /* returns freshly allocated memory, return value should be free'd
|
---|
| 192 | */
|
---|
[34] | 193 | char * sh_util_basename(const char * fullpath);
|
---|
[1] | 194 |
|
---|
[167] | 195 | /* required size (including terminating NULL) for string of strlen l
|
---|
| 196 | */
|
---|
| 197 | #define SH_B64_SIZ(l) (1 + ((((l) + 2) / 3) * 4))
|
---|
| 198 |
|
---|
| 199 | /* return len of encoded string
|
---|
| 200 | */
|
---|
| 201 | size_t sh_util_base64_enc (unsigned char * out, const unsigned char * instr,
|
---|
| 202 | size_t lin);
|
---|
| 203 |
|
---|
| 204 | /* return allocated encoded string in out, return its len
|
---|
| 205 | */
|
---|
| 206 | size_t sh_util_base64_enc_alloc (char **out, const char *in, size_t inlen);
|
---|
| 207 |
|
---|
| 208 | /* return len of decoded string
|
---|
| 209 | */
|
---|
| 210 | size_t sh_util_base64_dec (unsigned char *out, const unsigned char *in, size_t lin);
|
---|
| 211 |
|
---|
| 212 | /* return allocated decoded string in out, return its len
|
---|
| 213 | */
|
---|
| 214 | size_t sh_util_base64_dec_alloc (unsigned char **out, const unsigned char *in, size_t lin);
|
---|
| 215 |
|
---|
[1] | 216 | #endif
|
---|