source: trunk/include/sh_utils.h@ 134

Last change on this file since 134 was 132, checked in by rainer, 17 years ago

Make utility functions thread-safe.

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