[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 | #include "config_xor.h"
|
---|
| 21 |
|
---|
| 22 | #ifdef HOST_IS_HPUX
|
---|
| 23 | #define _XOPEN_SOURCE_EXTENDED
|
---|
| 24 | #endif
|
---|
| 25 |
|
---|
| 26 | #include <stdlib.h>
|
---|
| 27 | #include <string.h>
|
---|
| 28 | #include <errno.h>
|
---|
| 29 |
|
---|
| 30 | #include <sys/types.h>
|
---|
| 31 | #include <unistd.h>
|
---|
| 32 | #include <sys/stat.h>
|
---|
| 33 | #include <fcntl.h>
|
---|
| 34 | #include <signal.h>
|
---|
| 35 | #include <sys/socket.h>
|
---|
| 36 | #include <netinet/in.h>
|
---|
| 37 |
|
---|
| 38 | #ifndef S_SPLINT_S
|
---|
| 39 | #include <arpa/inet.h>
|
---|
| 40 | #else
|
---|
| 41 | #define AF_INET 2
|
---|
| 42 | #endif
|
---|
| 43 |
|
---|
| 44 | #include <time.h>
|
---|
| 45 |
|
---|
| 46 | #ifndef HAVE_LSTAT
|
---|
| 47 | #define lstat stat
|
---|
| 48 | #endif
|
---|
| 49 |
|
---|
| 50 | #include "samhain.h"
|
---|
| 51 | #include "sh_error.h"
|
---|
| 52 | #include "sh_calls.h"
|
---|
[295] | 53 | #include "sh_ipvx.h"
|
---|
[315] | 54 | #include "sh_sub.h"
|
---|
| 55 | #include "sh_utils.h"
|
---|
[1] | 56 |
|
---|
| 57 | #undef FIL__
|
---|
| 58 | #define FIL__ _("sh_calls.c")
|
---|
| 59 |
|
---|
| 60 | char aud_err_message[64];
|
---|
| 61 |
|
---|
| 62 | typedef struct cht_struct
|
---|
| 63 | {
|
---|
[170] | 64 | const char * str;
|
---|
[1] | 65 | unsigned long val;
|
---|
| 66 | } cht_type;
|
---|
| 67 |
|
---|
| 68 | static cht_type aud_tab[] =
|
---|
| 69 | {
|
---|
| 70 | { N_("execve"), AUD_EXEC },
|
---|
| 71 | { N_("utime"), AUD_UTIME },
|
---|
| 72 | { N_("unlink"), AUD_UNLINK },
|
---|
| 73 | { N_("dup"), AUD_DUP },
|
---|
| 74 | { N_("chdir"), AUD_CHDIR },
|
---|
| 75 | { N_("open"), AUD_OPEN },
|
---|
| 76 | { N_("kill"), AUD_KILL },
|
---|
| 77 | { N_("exit"), AUD_EXIT },
|
---|
| 78 | { N_("fork"), AUD_FORK },
|
---|
| 79 | { N_("setuid"), AUD_SETUID },
|
---|
| 80 | { N_("setgid"), AUD_SETGID },
|
---|
| 81 | { N_("pipe"), AUD_PIPE },
|
---|
| 82 | { NULL, 0 }
|
---|
| 83 | };
|
---|
| 84 |
|
---|
| 85 | /* Set aud functions
|
---|
| 86 | */
|
---|
[22] | 87 | int sh_aud_set_functions(const char * str_s)
|
---|
[1] | 88 | {
|
---|
| 89 | int i = 0;
|
---|
| 90 |
|
---|
| 91 | SL_ENTER(_("sh_aud_set_functions"));
|
---|
| 92 |
|
---|
| 93 | if (str_s == NULL)
|
---|
| 94 | return -1;
|
---|
| 95 |
|
---|
| 96 | while (aud_tab[i].str != NULL)
|
---|
| 97 | {
|
---|
| 98 | if (NULL != sl_strstr (str_s, _(aud_tab[i].str)))
|
---|
| 99 | {
|
---|
| 100 | sh.flag.audit = 1;
|
---|
| 101 | sh.flag.aud_mask |= aud_tab[i].val;
|
---|
| 102 | }
|
---|
| 103 | ++i;
|
---|
| 104 | }
|
---|
| 105 |
|
---|
| 106 | SL_RETURN(0,_("sh_aud_set_functions"));
|
---|
| 107 | }
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 |
|
---|
| 112 | /* Need to catch EINTR for these functions.
|
---|
| 113 | */
|
---|
[170] | 114 | long int retry_sigaction(const char * file, int line,
|
---|
[1] | 115 | int signum, const struct sigaction *act,
|
---|
| 116 | struct sigaction *oldact)
|
---|
| 117 | {
|
---|
| 118 | int error;
|
---|
| 119 | long int val_retry = -1;
|
---|
[132] | 120 | char errbuf[SH_ERRBUF_SIZE];
|
---|
[1] | 121 | errno = 0;
|
---|
| 122 |
|
---|
| 123 | SL_ENTER(_("retry_sigaction"));
|
---|
| 124 |
|
---|
| 125 | do {
|
---|
| 126 | val_retry = sigaction(signum, act, oldact);
|
---|
| 127 | } while (val_retry < 0 && errno == EINTR);
|
---|
| 128 |
|
---|
| 129 | error = errno;
|
---|
| 130 | if (val_retry < 0) {
|
---|
| 131 | sh_error_handle ((-1), file, line, error, MSG_ERR_SIGACT,
|
---|
[132] | 132 | sh_error_message(error, errbuf, sizeof(errbuf)),
|
---|
[1] | 133 | (long) signum );
|
---|
| 134 | }
|
---|
| 135 | errno = error;
|
---|
| 136 | SL_RETURN(val_retry, _("retry_sigaction"));
|
---|
| 137 | }
|
---|
| 138 |
|
---|
[295] | 139 | static struct sh_sockaddr bind_addr;
|
---|
[1] | 140 | static int use_bind_addr = 0;
|
---|
| 141 |
|
---|
[20] | 142 | int sh_calls_set_bind_addr (const char * str)
|
---|
[1] | 143 | {
|
---|
[3] | 144 | static int reject = 0;
|
---|
| 145 |
|
---|
| 146 | if (reject == 1)
|
---|
| 147 | return (0);
|
---|
| 148 |
|
---|
| 149 | if (sh.flag.opts == S_TRUE)
|
---|
| 150 | reject = 1;
|
---|
| 151 |
|
---|
[295] | 152 | #if defined(USE_IPVX)
|
---|
| 153 | if (0 == sh_ipvx_aton(str, &bind_addr))
|
---|
| 154 | return -1;
|
---|
| 155 | #else
|
---|
| 156 | if (0 == inet_aton(str, &(bind_addr.sin.sin_addr)))
|
---|
| 157 | return -1;
|
---|
| 158 | #endif
|
---|
| 159 |
|
---|
[1] | 160 | use_bind_addr = 1;
|
---|
| 161 | return 0;
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 |
|
---|
[170] | 165 | long int retry_connect(const char * file, int line, int sockfd,
|
---|
[1] | 166 | struct sockaddr *serv_addr, int addrlen)
|
---|
| 167 | {
|
---|
| 168 | int error;
|
---|
| 169 | long int val_retry = 0;
|
---|
[132] | 170 | char errbuf[SH_ERRBUF_SIZE];
|
---|
[1] | 171 |
|
---|
| 172 | SL_ENTER(_("retry_connect"));
|
---|
| 173 |
|
---|
| 174 | errno = 0;
|
---|
| 175 |
|
---|
| 176 | if (0 != use_bind_addr)
|
---|
| 177 | {
|
---|
[295] | 178 | int slen = SH_SS_LEN(bind_addr);
|
---|
| 179 |
|
---|
| 180 | val_retry = bind(sockfd, sh_ipvx_sockaddr_cast(&bind_addr), slen);
|
---|
[1] | 181 | }
|
---|
| 182 |
|
---|
| 183 | if (val_retry == 0)
|
---|
| 184 | {
|
---|
| 185 | do {
|
---|
[295] | 186 | val_retry = connect(sockfd, serv_addr, addrlen);
|
---|
[171] | 187 | } while (val_retry < 0 && (errno == EINTR || errno == EINPROGRESS));
|
---|
[1] | 188 | }
|
---|
| 189 |
|
---|
| 190 | error = errno;
|
---|
| 191 | if (val_retry != 0) {
|
---|
[295] | 192 | long eport;
|
---|
| 193 | char eaddr[SH_IP_BUF];
|
---|
| 194 |
|
---|
| 195 | struct sh_sockaddr ss;
|
---|
| 196 | sh_ipvx_save(&ss, serv_addr->sa_family, serv_addr);
|
---|
| 197 | sh_ipvx_ntoa(eaddr, sizeof(eaddr), &ss);
|
---|
| 198 |
|
---|
| 199 | if (serv_addr->sa_family == AF_INET)
|
---|
| 200 | eport = (long) ntohs(((struct sockaddr_in *)serv_addr)->sin_port);
|
---|
| 201 | else
|
---|
| 202 | eport = (long) ntohs(((struct sockaddr_in6 *)serv_addr)->sin6_port);
|
---|
| 203 |
|
---|
[1] | 204 | sh_error_handle ((-1), file, line, error, MSG_ERR_CONNECT,
|
---|
[132] | 205 | sh_error_message(error, errbuf, sizeof(errbuf)),
|
---|
[295] | 206 | (long) sockfd, eport, eaddr);
|
---|
[1] | 207 | }
|
---|
| 208 | errno = error;
|
---|
| 209 | SL_RETURN(val_retry, _("retry_connect"));
|
---|
| 210 | }
|
---|
| 211 |
|
---|
[170] | 212 | long int retry_accept(const char * file, int line, int fd,
|
---|
[295] | 213 | struct sh_sockaddr *serv_addr, int * addrlen)
|
---|
[1] | 214 | {
|
---|
| 215 | int error;
|
---|
| 216 | long int val_retry = -1;
|
---|
[132] | 217 | char errbuf[SH_ERRBUF_SIZE];
|
---|
[295] | 218 | struct sockaddr_storage ss;
|
---|
[132] | 219 |
|
---|
[295] | 220 | ACCEPT_TYPE_ARG3 my_addrlen = sizeof(ss);
|
---|
[1] | 221 |
|
---|
| 222 | errno = 0;
|
---|
| 223 |
|
---|
| 224 | SL_ENTER(_("retry_accept"));
|
---|
| 225 |
|
---|
| 226 | do {
|
---|
[295] | 227 | val_retry = accept(fd, (struct sockaddr *)&ss, &my_addrlen);
|
---|
[1] | 228 | } while (val_retry < 0 && errno == EINTR);
|
---|
[295] | 229 |
|
---|
[1] | 230 | error = errno;
|
---|
| 231 | if (val_retry < 0) {
|
---|
| 232 | sh_error_handle ((-1), file, line, error, MSG_ERR_ACCEPT,
|
---|
[132] | 233 | sh_error_message(error, errbuf, sizeof(errbuf)),
|
---|
[1] | 234 | (long) fd );
|
---|
| 235 | }
|
---|
[295] | 236 | errno = error;
|
---|
| 237 |
|
---|
| 238 | sh_ipvx_save(serv_addr, ss.ss_family, (struct sockaddr *) &ss);
|
---|
| 239 |
|
---|
[307] | 240 | *addrlen = (int) my_addrlen;
|
---|
[1] | 241 | SL_RETURN(val_retry, _("retry_accept"));
|
---|
| 242 | }
|
---|
| 243 |
|
---|
[315] | 244 | static int sh_use_sub = 0;
|
---|
| 245 |
|
---|
| 246 | int sh_calls_set_sub (const char * str)
|
---|
| 247 | {
|
---|
| 248 | return sh_util_flagval(str, &sh_use_sub);
|
---|
| 249 | }
|
---|
| 250 |
|
---|
[170] | 251 | long int retry_lstat(const char * file, int line,
|
---|
[1] | 252 | const char *file_name, struct stat *buf)
|
---|
| 253 | {
|
---|
| 254 | int error;
|
---|
| 255 | long int val_retry = -1;
|
---|
[132] | 256 | char errbuf[SH_ERRBUF_SIZE];
|
---|
[1] | 257 |
|
---|
| 258 | SL_ENTER(_("retry_lstat"));
|
---|
| 259 |
|
---|
[315] | 260 | if (sh_use_sub)
|
---|
| 261 | {
|
---|
| 262 | val_retry = sh_sub_lstat (file_name, buf);
|
---|
| 263 | }
|
---|
| 264 | else
|
---|
| 265 | {
|
---|
| 266 | do {
|
---|
| 267 | val_retry = /*@-unrecog@*/lstat (file_name, buf)/*@+unrecog@*/;
|
---|
| 268 | } while (val_retry < 0 && errno == EINTR);
|
---|
| 269 | }
|
---|
| 270 |
|
---|
[1] | 271 | error = errno;
|
---|
| 272 | if (val_retry < 0) {
|
---|
[134] | 273 | (void) sh_error_message(error, aud_err_message, 64);
|
---|
[1] | 274 | sh_error_handle ((-1), file, line, error, MSG_ERR_LSTAT,
|
---|
[132] | 275 | sh_error_message(error, errbuf, sizeof(errbuf)),
|
---|
[1] | 276 | file_name );
|
---|
| 277 | }
|
---|
| 278 | errno = error;
|
---|
[315] | 279 |
|
---|
[1] | 280 | SL_RETURN(val_retry, _("retry_lstat"));
|
---|
| 281 | }
|
---|
| 282 |
|
---|
[170] | 283 | long int retry_stat(const char * file, int line,
|
---|
[1] | 284 | const char *file_name, struct stat *buf)
|
---|
| 285 | {
|
---|
| 286 | int error;
|
---|
| 287 | long int val_retry = -1;
|
---|
[132] | 288 | char errbuf[SH_ERRBUF_SIZE];
|
---|
[1] | 289 |
|
---|
| 290 | SL_ENTER(_("retry_stat"));
|
---|
| 291 |
|
---|
[315] | 292 | if (sh_use_sub)
|
---|
| 293 | {
|
---|
| 294 | val_retry = sh_sub_stat (file_name, buf);
|
---|
| 295 | }
|
---|
| 296 | else
|
---|
| 297 | {
|
---|
| 298 | do {
|
---|
| 299 | val_retry = stat (file_name, buf);
|
---|
| 300 | } while (val_retry < 0 && errno == EINTR);
|
---|
| 301 | }
|
---|
| 302 |
|
---|
[1] | 303 | error = errno;
|
---|
| 304 | if (val_retry < 0) {
|
---|
[134] | 305 | (void) sh_error_message(error, aud_err_message, 64);
|
---|
[1] | 306 | sh_error_handle ((-1), file, line, error, MSG_ERR_STAT,
|
---|
[132] | 307 | sh_error_message(error, errbuf, sizeof(errbuf)),
|
---|
[1] | 308 | file_name );
|
---|
| 309 | }
|
---|
| 310 | errno = error;
|
---|
[315] | 311 |
|
---|
[1] | 312 | SL_RETURN(val_retry, _("retry_stat"));
|
---|
| 313 | }
|
---|
| 314 |
|
---|
[170] | 315 | long int retry_fstat(const char * file, int line, int filed, struct stat *buf)
|
---|
[1] | 316 | {
|
---|
| 317 | int error;
|
---|
| 318 | long int val_retry = -1;
|
---|
[132] | 319 | char errbuf[SH_ERRBUF_SIZE];
|
---|
[1] | 320 |
|
---|
| 321 | SL_ENTER(_("retry_fstat"));
|
---|
| 322 |
|
---|
| 323 | do {
|
---|
| 324 | val_retry = fstat (filed, buf);
|
---|
| 325 | } while (val_retry < 0 && errno == EINTR);
|
---|
| 326 | error = errno;
|
---|
| 327 | if (val_retry < 0) {
|
---|
| 328 | sh_error_handle ((-1), file, line, error, MSG_ERR_FSTAT,
|
---|
[132] | 329 | sh_error_message(error, errbuf, sizeof(errbuf)),
|
---|
[1] | 330 | (long) filed );
|
---|
| 331 | }
|
---|
| 332 | errno = error;
|
---|
| 333 | SL_RETURN(val_retry, _("retry_fstat"));
|
---|
| 334 | }
|
---|
| 335 |
|
---|
[170] | 336 | long int retry_fcntl(const char * file, int line, int fd, int cmd, long arg)
|
---|
[1] | 337 | {
|
---|
| 338 | int error;
|
---|
| 339 | long int val_retry = -1;
|
---|
[132] | 340 | char errbuf[SH_ERRBUF_SIZE];
|
---|
[1] | 341 | errno = 0;
|
---|
| 342 |
|
---|
| 343 | SL_ENTER(_("retry_fcntl"));
|
---|
| 344 |
|
---|
| 345 | if (cmd == F_GETFD || cmd == F_GETFL)
|
---|
| 346 | {
|
---|
| 347 | do {
|
---|
| 348 | val_retry = fcntl(fd, cmd);
|
---|
| 349 | } while (val_retry < 0 && errno == EINTR);
|
---|
| 350 | }
|
---|
| 351 | else
|
---|
| 352 | {
|
---|
| 353 | do {
|
---|
| 354 | val_retry = fcntl(fd, cmd, arg);
|
---|
| 355 | } while (val_retry < 0 && errno == EINTR);
|
---|
| 356 | }
|
---|
| 357 | error = errno;
|
---|
| 358 | if (val_retry < 0) {
|
---|
| 359 | sh_error_handle ((-1), file, line, error, MSG_ERR_FCNTL,
|
---|
[132] | 360 | sh_error_message(error, errbuf, sizeof(errbuf)),
|
---|
[1] | 361 | (long) fd, (long) cmd, arg );
|
---|
| 362 | }
|
---|
| 363 | errno = error;
|
---|
| 364 | SL_RETURN(val_retry, _("retry_fcntl"));
|
---|
| 365 | }
|
---|
| 366 |
|
---|
| 367 | long int retry_msleep (int sec, int millisec)
|
---|
| 368 | {
|
---|
| 369 | int result = 0;
|
---|
| 370 | #if defined(HAVE_NANOSLEEP)
|
---|
| 371 | struct timespec req, rem;
|
---|
| 372 | #endif
|
---|
| 373 |
|
---|
[169] | 374 | SL_ENTER(_("retry_msleep"));
|
---|
[1] | 375 |
|
---|
| 376 | errno = 0;
|
---|
| 377 | if (millisec > 999) millisec = 999;
|
---|
| 378 | if (millisec < 0) millisec = 0;
|
---|
| 379 | if (sec < 0) sec = 0;
|
---|
| 380 |
|
---|
| 381 | #if defined(HAVE_NANOSLEEP)
|
---|
| 382 | /*@-usedef@*/
|
---|
| 383 | req.tv_sec = sec; rem.tv_sec = 0;
|
---|
| 384 | req.tv_nsec = millisec * 1000000; rem.tv_nsec = 0;
|
---|
| 385 | /*@+usedef@*/
|
---|
| 386 | do {
|
---|
| 387 | result = /*@-unrecog@*/nanosleep(&req, &rem)/*@+unrecog@*/;
|
---|
| 388 |
|
---|
| 389 | req.tv_sec = rem.tv_sec; rem.tv_sec = 0;
|
---|
| 390 | req.tv_nsec = rem.tv_nsec; rem.tv_nsec = 0;
|
---|
| 391 |
|
---|
| 392 | } while ((result == -1) && (errno == EINTR));
|
---|
| 393 | #else
|
---|
| 394 | if (sec > 0)
|
---|
| 395 | {
|
---|
[134] | 396 | sleep (sec); /* nanosleep not available */
|
---|
[1] | 397 | }
|
---|
| 398 | else
|
---|
| 399 | {
|
---|
| 400 | #ifdef HAVE_USLEEP
|
---|
| 401 | if (millisec > 0)
|
---|
| 402 | {
|
---|
| 403 | usleep(1000 * millisec);
|
---|
| 404 | }
|
---|
| 405 | #else
|
---|
| 406 | if (millisec > 0)
|
---|
| 407 | {
|
---|
| 408 | sleep (1);
|
---|
| 409 | }
|
---|
| 410 | #endif
|
---|
| 411 | }
|
---|
| 412 | #endif
|
---|
| 413 | SL_RETURN(result, _("retry_msleep"));
|
---|
| 414 | }
|
---|
| 415 |
|
---|
| 416 | /***************************************************
|
---|
| 417 | *
|
---|
| 418 | * Audit these functions.
|
---|
| 419 | *
|
---|
| 420 | ***************************************************/
|
---|
| 421 |
|
---|
[170] | 422 | long int retry_aud_execve (const char * file, int line,
|
---|
[1] | 423 | const char *dateiname, char * argv[],
|
---|
| 424 | char * envp[])
|
---|
| 425 | {
|
---|
| 426 | uid_t a = geteuid();
|
---|
| 427 | gid_t b = getegid();
|
---|
| 428 | int i;
|
---|
| 429 | int error;
|
---|
[132] | 430 | char errbuf[SH_ERRBUF_SIZE];
|
---|
[1] | 431 |
|
---|
| 432 | SL_ENTER(_("retry_aud_execve"));
|
---|
| 433 |
|
---|
| 434 | if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_EXEC) != 0)
|
---|
| 435 | sh_error_handle ((-1), file, line, 0, MSG_AUD_EXEC,
|
---|
| 436 | dateiname, (long) a, (long) b );
|
---|
| 437 | do {
|
---|
| 438 | i = execve(dateiname, argv, envp);
|
---|
| 439 | } while (i < 0 && errno == EINTR);
|
---|
| 440 |
|
---|
| 441 | error = errno;
|
---|
| 442 | if (i < 0) {
|
---|
[132] | 443 | sh_error_handle ((-1), file, line, error, MSG_ERR_EXEC,
|
---|
| 444 | sh_error_message(error, errbuf, sizeof(errbuf)),
|
---|
[1] | 445 | dateiname, (long) a, (long) b );
|
---|
| 446 | }
|
---|
| 447 | errno = error;
|
---|
| 448 | SL_RETURN(i, _("retry_aud_execve"));
|
---|
| 449 | }
|
---|
| 450 |
|
---|
| 451 |
|
---|
[170] | 452 | long int retry_aud_utime (const char * file, int line,
|
---|
| 453 | char * path, struct utimbuf *buf)
|
---|
[1] | 454 | {
|
---|
| 455 | long int val_return;
|
---|
| 456 | int error;
|
---|
[132] | 457 | char errbuf[SH_ERRBUF_SIZE];
|
---|
[1] | 458 | errno = 0;
|
---|
| 459 |
|
---|
| 460 | SL_ENTER(_("retry_aud_utime"));
|
---|
| 461 |
|
---|
| 462 | do {
|
---|
| 463 | val_return = utime (path, buf);
|
---|
| 464 | } while (val_return < 0 && errno == EINTR);
|
---|
| 465 |
|
---|
| 466 | error = errno;
|
---|
| 467 | if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_UTIME) != 0)
|
---|
| 468 | sh_error_handle ((-1), file, line, 0, MSG_AUD_UTIME,
|
---|
| 469 | path,
|
---|
| 470 | (unsigned long) buf->actime,
|
---|
| 471 | (unsigned long) buf->modtime);
|
---|
| 472 | if (val_return < 0) {
|
---|
| 473 | sh_error_handle ((-1), file, line, error, MSG_ERR_UTIME,
|
---|
[132] | 474 | sh_error_message(error, errbuf, sizeof(errbuf)),
|
---|
[1] | 475 | path,
|
---|
| 476 | (unsigned long) buf->actime,
|
---|
| 477 | (unsigned long) buf->modtime);
|
---|
| 478 | }
|
---|
| 479 | errno = error;
|
---|
| 480 | SL_RETURN(val_return, _("retry_aud_utime"));
|
---|
| 481 | }
|
---|
| 482 |
|
---|
[170] | 483 | long int retry_aud_unlink (const char * file, int line,
|
---|
[1] | 484 | char * path)
|
---|
| 485 | {
|
---|
| 486 | long int val_return;
|
---|
| 487 | int error;
|
---|
[132] | 488 | char errbuf[SH_ERRBUF_SIZE];
|
---|
[1] | 489 | errno = 0;
|
---|
| 490 |
|
---|
| 491 | SL_ENTER(_("retry_aud_unlink"));
|
---|
| 492 |
|
---|
| 493 | do {
|
---|
| 494 | val_return = unlink (path);
|
---|
| 495 | } while (val_return < 0 && errno == EINTR);
|
---|
| 496 |
|
---|
| 497 | error = errno;
|
---|
| 498 | if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_UNLINK) != 0)
|
---|
| 499 | sh_error_handle ((-1), file, line, 0, MSG_AUD_UNLINK,
|
---|
| 500 | path);
|
---|
| 501 | if (val_return < 0) {
|
---|
[132] | 502 | sh_error_handle ((-1), file, line, error, MSG_ERR_UNLINK,
|
---|
| 503 | sh_error_message(error, errbuf, sizeof(errbuf)),
|
---|
[1] | 504 | path);
|
---|
| 505 | }
|
---|
| 506 | errno = error;
|
---|
| 507 | SL_RETURN(val_return, _("retry_aud_unlink"));
|
---|
| 508 | }
|
---|
| 509 |
|
---|
[170] | 510 | long int retry_aud_dup2 (const char * file, int line,
|
---|
[1] | 511 | int fd, int fd2)
|
---|
| 512 | {
|
---|
| 513 | long int val_return;
|
---|
| 514 | int error;
|
---|
[132] | 515 | char errbuf[SH_ERRBUF_SIZE];
|
---|
[1] | 516 | errno = 0;
|
---|
| 517 |
|
---|
| 518 | SL_ENTER(_("retry_aud_dup2"));
|
---|
| 519 |
|
---|
| 520 | do {
|
---|
| 521 | val_return = dup2 (fd, fd2);
|
---|
| 522 | } while (val_return < 0 && errno == EINTR);
|
---|
| 523 |
|
---|
| 524 | error = errno;
|
---|
| 525 | if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_DUP) != 0)
|
---|
| 526 | sh_error_handle ((-1), file, line, 0, MSG_AUD_DUP,
|
---|
| 527 | (long) fd, val_return);
|
---|
| 528 | if (val_return < 0) {
|
---|
| 529 | sh_error_handle ((-1), file, line, error, MSG_ERR_DUP,
|
---|
[132] | 530 | sh_error_message(error, errbuf, sizeof(errbuf)),
|
---|
[1] | 531 | (long) fd, val_return);
|
---|
| 532 | }
|
---|
| 533 | errno = error;
|
---|
| 534 | SL_RETURN(val_return, _("retry_aud_dup2"));
|
---|
| 535 | }
|
---|
| 536 |
|
---|
[170] | 537 | long int retry_aud_dup (const char * file, int line,
|
---|
[1] | 538 | int fd)
|
---|
| 539 | {
|
---|
| 540 | long int val_return;
|
---|
| 541 | int error;
|
---|
[132] | 542 | char errbuf[SH_ERRBUF_SIZE];
|
---|
[1] | 543 | errno = 0;
|
---|
| 544 |
|
---|
| 545 | SL_ENTER(_("retry_aud_dup"));
|
---|
| 546 |
|
---|
| 547 | do {
|
---|
| 548 | val_return = dup (fd);
|
---|
| 549 | } while (val_return < 0 && errno == EINTR);
|
---|
| 550 | error = errno;
|
---|
| 551 | if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_DUP) != 0)
|
---|
| 552 | sh_error_handle ((-1), file, line, 0, MSG_AUD_DUP,
|
---|
| 553 | (long) fd, val_return);
|
---|
| 554 | if (val_return < 0) {
|
---|
| 555 | sh_error_handle ((-1), file, line, error, MSG_ERR_DUP,
|
---|
[132] | 556 | sh_error_message(error, errbuf, sizeof(errbuf)),
|
---|
[1] | 557 | (long) fd, val_return);
|
---|
| 558 | }
|
---|
| 559 | errno = error;
|
---|
| 560 | SL_RETURN(val_return, _("retry_aud_dup"));
|
---|
| 561 | }
|
---|
| 562 |
|
---|
| 563 |
|
---|
| 564 |
|
---|
[170] | 565 | long int retry_aud_chdir (const char * file, int line,
|
---|
[1] | 566 | const char *path)
|
---|
| 567 | {
|
---|
| 568 | long int val_return;
|
---|
| 569 | int error = 0;
|
---|
[132] | 570 | char errbuf[SH_ERRBUF_SIZE];
|
---|
[1] | 571 | errno = 0;
|
---|
| 572 |
|
---|
| 573 | SL_ENTER(_("retry_aud_chdir"));
|
---|
| 574 |
|
---|
| 575 | do {
|
---|
| 576 | val_return = chdir (path);
|
---|
| 577 | } while (val_return < 0 && errno == EINTR);
|
---|
| 578 |
|
---|
| 579 | error = errno;
|
---|
| 580 | if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_CHDIR) != 0)
|
---|
| 581 | sh_error_handle ((-1), file, line, 0, MSG_AUD_CHDIR,
|
---|
| 582 | path);
|
---|
| 583 | if (val_return < 0) {
|
---|
[132] | 584 | sh_error_handle ((-1), file, line, error, MSG_ERR_CHDIR,
|
---|
| 585 | sh_error_message(error, errbuf, sizeof(errbuf)),
|
---|
[1] | 586 | path);
|
---|
| 587 | }
|
---|
| 588 | errno = error;
|
---|
| 589 | SL_RETURN(val_return, _("retry_aud_chdir"));
|
---|
| 590 | }
|
---|
| 591 |
|
---|
| 592 |
|
---|
[170] | 593 | long int aud_open_noatime (const char * file, int line, int privs,
|
---|
[1] | 594 | const char *pathname, int flags, mode_t mode,
|
---|
| 595 | int * o_noatime)
|
---|
| 596 | {
|
---|
| 597 | long int val_return;
|
---|
| 598 | int error;
|
---|
[132] | 599 | char errbuf[SH_ERRBUF_SIZE];
|
---|
[1] | 600 |
|
---|
| 601 | SL_ENTER(_("aud_open"));
|
---|
| 602 |
|
---|
| 603 | val_return = open (pathname, *o_noatime|flags, mode);
|
---|
| 604 | if ((val_return < 0) && (*o_noatime != 0))
|
---|
| 605 | {
|
---|
| 606 | val_return = open (pathname, flags, mode);
|
---|
| 607 | if (val_return >= 0)
|
---|
| 608 | *o_noatime = 0;
|
---|
| 609 | }
|
---|
| 610 | error = errno;
|
---|
| 611 | /*@-noeffect@*/
|
---|
| 612 | (void) privs; /* fix compiler warning */
|
---|
| 613 | /*@+noeffect@*/
|
---|
| 614 |
|
---|
| 615 | if (val_return < 0)
|
---|
| 616 | {
|
---|
[134] | 617 | (void) sh_error_message(error, aud_err_message, 64);
|
---|
[1] | 618 | }
|
---|
| 619 |
|
---|
| 620 | if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_OPEN) != 0)
|
---|
| 621 | {
|
---|
| 622 | sh_error_handle ((-1), file, line, 0, MSG_AUD_OPEN,
|
---|
| 623 | pathname, (long) flags, (long) mode, val_return);
|
---|
| 624 | }
|
---|
| 625 | if (val_return < 0) {
|
---|
| 626 | sh_error_handle ((-1), file, line, error, MSG_ERR_OPEN,
|
---|
[132] | 627 | sh_error_message(error, errbuf, sizeof(errbuf)),
|
---|
[1] | 628 | pathname, (long) flags, (long) mode, val_return);
|
---|
| 629 | }
|
---|
| 630 | errno = error;
|
---|
| 631 | SL_RETURN(val_return, _("aud_open"));
|
---|
| 632 | }
|
---|
| 633 |
|
---|
[170] | 634 | long int aud_open (const char * file, int line, int privs,
|
---|
[1] | 635 | const char *pathname, int flags, mode_t mode)
|
---|
| 636 | {
|
---|
| 637 | long int val_return;
|
---|
| 638 | int error;
|
---|
[132] | 639 | char errbuf[SH_ERRBUF_SIZE];
|
---|
[1] | 640 |
|
---|
| 641 | SL_ENTER(_("aud_open"));
|
---|
| 642 |
|
---|
| 643 | val_return = open (pathname, flags, mode);
|
---|
| 644 | error = errno;
|
---|
| 645 | /*@-noeffect@*/
|
---|
| 646 | (void) privs; /* fix compiler warning */
|
---|
| 647 | /*@+noeffect@*/
|
---|
| 648 |
|
---|
| 649 | if (val_return < 0)
|
---|
| 650 | {
|
---|
[134] | 651 | (void) sh_error_message(error, aud_err_message, 64);
|
---|
[1] | 652 | }
|
---|
| 653 |
|
---|
| 654 | if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_OPEN) != 0)
|
---|
| 655 | {
|
---|
| 656 | sh_error_handle ((-1), file, line, 0, MSG_AUD_OPEN,
|
---|
| 657 | pathname, (long) flags, (long) mode, val_return);
|
---|
| 658 | }
|
---|
| 659 | if (val_return < 0) {
|
---|
| 660 | sh_error_handle ((-1), file, line, error, MSG_ERR_OPEN,
|
---|
[132] | 661 | sh_error_message(error, errbuf, sizeof(errbuf)),
|
---|
[1] | 662 | pathname, (long) flags, (long) mode, val_return);
|
---|
| 663 | }
|
---|
| 664 | errno = error;
|
---|
| 665 | SL_RETURN(val_return, _("aud_open"));
|
---|
| 666 | }
|
---|
| 667 |
|
---|
[170] | 668 | long int aud_kill (const char * file, int line, pid_t pid, int sig)
|
---|
[1] | 669 | {
|
---|
| 670 | int myerror;
|
---|
| 671 | long int val_return = kill (pid, sig);
|
---|
[132] | 672 | char errbuf[SH_ERRBUF_SIZE];
|
---|
[1] | 673 | myerror = errno;
|
---|
| 674 |
|
---|
| 675 | SL_ENTER(_("aud_kill"));
|
---|
| 676 |
|
---|
| 677 | if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_KILL) != 0)
|
---|
| 678 | sh_error_handle ((-1), file, line, 0, MSG_AUD_KILL,
|
---|
| 679 | (long) pid, (long) sig);
|
---|
| 680 | if (val_return < 0) {
|
---|
| 681 | sh_error_handle ((-1), file, line, myerror, MSG_ERR_KILL,
|
---|
[132] | 682 | sh_error_message(myerror, errbuf, sizeof(errbuf)),
|
---|
[1] | 683 | (long) pid, (long) sig);
|
---|
| 684 | }
|
---|
| 685 | errno = myerror;
|
---|
| 686 | SL_RETURN(val_return, _("aud_kill"));
|
---|
| 687 | }
|
---|
| 688 |
|
---|
| 689 | /*@noreturn@*/
|
---|
[170] | 690 | void aud_exit (const char * file, int line, int fd)
|
---|
[1] | 691 | {
|
---|
| 692 | if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_EXIT) != 0)
|
---|
| 693 | sh_error_handle ((-1), file, line, 0, MSG_AUD_EXIT,
|
---|
| 694 | (long) fd);
|
---|
| 695 |
|
---|
| 696 | SL_ENTER(_("aud_exit"));
|
---|
| 697 |
|
---|
| 698 | sh.flag.exit = fd;
|
---|
| 699 | exit(fd);
|
---|
| 700 | }
|
---|
| 701 |
|
---|
| 702 | /*@noreturn@*/
|
---|
[170] | 703 | void aud__exit (const char * file, int line, int fd)
|
---|
[1] | 704 | {
|
---|
| 705 | if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_EXIT) != 0)
|
---|
| 706 | sh_error_handle ((-1), file, line, 0, MSG_AUD_EXIT,
|
---|
| 707 | (long) fd);
|
---|
| 708 |
|
---|
| 709 | SL_ENTER(_("aud__exit"));
|
---|
| 710 |
|
---|
| 711 | sh.flag.exit = fd;
|
---|
| 712 | _exit(fd);
|
---|
| 713 | }
|
---|
| 714 |
|
---|
[170] | 715 | pid_t aud_fork (const char * file, int line)
|
---|
[1] | 716 | {
|
---|
| 717 | int error;
|
---|
| 718 | pid_t i = fork();
|
---|
[132] | 719 | char errbuf[SH_ERRBUF_SIZE];
|
---|
[1] | 720 |
|
---|
| 721 | error = errno;
|
---|
| 722 | SL_ENTER(_("aud_fork"));
|
---|
| 723 |
|
---|
| 724 | if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_FORK) != 0 && (i > 0))
|
---|
| 725 | sh_error_handle ((-1), file, line, 0, MSG_AUD_FORK,
|
---|
| 726 | (long) i);
|
---|
| 727 | if (i == (pid_t) -1) {
|
---|
| 728 | sh_error_handle ((-1), file, line, error, MSG_ERR_FORK,
|
---|
[132] | 729 | sh_error_message(error, errbuf, sizeof(errbuf)),
|
---|
[1] | 730 | (long) i);
|
---|
| 731 | }
|
---|
| 732 | errno = error;
|
---|
| 733 | SL_RETURN(i, _("aud_fork"));
|
---|
| 734 | }
|
---|
| 735 |
|
---|
[170] | 736 | int aud_setuid (const char * file, int line, uid_t uid)
|
---|
[1] | 737 | {
|
---|
| 738 | int error = 0;
|
---|
| 739 | int i = 0;
|
---|
[132] | 740 | char errbuf[SH_ERRBUF_SIZE];
|
---|
[1] | 741 |
|
---|
| 742 | SL_ENTER(_("aud_setuid"));
|
---|
| 743 |
|
---|
| 744 | if (uid != (uid_t) 0) {
|
---|
| 745 | i = setuid(uid);
|
---|
| 746 | error = errno;
|
---|
| 747 | }
|
---|
| 748 | if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_SETUID) != 0)
|
---|
| 749 | sh_error_handle ((-1), file, line, 0, MSG_AUD_SETUID,
|
---|
| 750 | (long) uid);
|
---|
| 751 | if (uid == (uid_t) 0) {
|
---|
| 752 | i = setuid(uid);
|
---|
| 753 | error = errno;
|
---|
| 754 | }
|
---|
| 755 | if (i < 0) {
|
---|
| 756 | sh_error_handle ((-1), file, line, error, MSG_ERR_SETUID,
|
---|
[132] | 757 | sh_error_message(error, errbuf, sizeof(errbuf)),
|
---|
[1] | 758 | (long) uid);
|
---|
| 759 | }
|
---|
| 760 | errno = error;
|
---|
| 761 | SL_RETURN(i, _("aud_setuid"));
|
---|
| 762 | }
|
---|
| 763 |
|
---|
[170] | 764 | int aud_setgid (const char * file, int line, gid_t gid)
|
---|
[1] | 765 | {
|
---|
| 766 | int error = 0;
|
---|
| 767 | int i = 0;
|
---|
[132] | 768 | char errbuf[SH_ERRBUF_SIZE];
|
---|
[1] | 769 |
|
---|
| 770 | SL_ENTER(_("aud_setgid"));
|
---|
| 771 |
|
---|
| 772 | if (gid != (gid_t) 0) {
|
---|
| 773 | i = setgid(gid);
|
---|
| 774 | error = errno;
|
---|
| 775 | }
|
---|
| 776 |
|
---|
| 777 | if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_SETGID) != 0)
|
---|
| 778 | sh_error_handle ((-1), file, line, 0, MSG_AUD_SETGID,
|
---|
| 779 | (long) gid);
|
---|
| 780 | if (gid == (gid_t) 0) {
|
---|
| 781 | i = setgid(gid);
|
---|
| 782 | error = errno;
|
---|
| 783 | }
|
---|
| 784 | if (i < 0) {
|
---|
| 785 | sh_error_handle ((-1), file, line, error, MSG_ERR_SETGID,
|
---|
[132] | 786 | sh_error_message(error, errbuf, sizeof(errbuf)),
|
---|
[1] | 787 | (long) gid);
|
---|
| 788 | }
|
---|
| 789 | errno = error;
|
---|
| 790 | SL_RETURN(i, _("aud_setgid"));
|
---|
| 791 | }
|
---|
| 792 |
|
---|
[170] | 793 | int aud_pipe (const char * file, int line, int * modus)
|
---|
[1] | 794 | {
|
---|
| 795 | int error;
|
---|
| 796 | int i = pipe (modus);
|
---|
[132] | 797 | char errbuf[SH_ERRBUF_SIZE];
|
---|
[1] | 798 |
|
---|
| 799 | SL_ENTER(_("aud_pipe"));
|
---|
| 800 |
|
---|
| 801 | error = errno;
|
---|
| 802 | if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_PIPE) != 0)
|
---|
| 803 | {
|
---|
| 804 | if (i < 0)
|
---|
| 805 | sh_error_handle ((-1), file, line, 0, MSG_AUD_PIPE,
|
---|
| 806 | (long) 0, (long) 0);
|
---|
| 807 | else
|
---|
| 808 | sh_error_handle ((-1), file, line, 0, MSG_AUD_PIPE,
|
---|
| 809 | (long) modus[0], (long) modus[1]);
|
---|
| 810 | }
|
---|
| 811 | if (i < 0) {
|
---|
| 812 | if (i < 0)
|
---|
| 813 | sh_error_handle ((-1), file, line, error, MSG_ERR_PIPE,
|
---|
[137] | 814 | sh_error_message(error, errbuf, sizeof(errbuf)),
|
---|
[1] | 815 | (long) 0, (long) 0);
|
---|
| 816 | else
|
---|
| 817 | sh_error_handle ((-1), file, line, error, MSG_ERR_PIPE,
|
---|
[132] | 818 | sh_error_message(error, errbuf, sizeof(errbuf)),
|
---|
[1] | 819 | (long) modus[0], (long) modus[1]);
|
---|
| 820 | }
|
---|
| 821 | SL_RETURN(i, _("aud_pipe"));
|
---|
| 822 | }
|
---|