source: trunk/src/sh_calls.c@ 326

Last change on this file since 326 was 317, checked in by katerina, 14 years ago

Further refinements for lstat in subprocess (ticket #236).

File size: 20.7 KB
RevLine 
[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
60char aud_err_message[64];
61
62typedef struct cht_struct
63{
[170]64 const char * str;
[1]65 unsigned long val;
66} cht_type;
67
68static 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]87int 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]114long 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]139static struct sh_sockaddr bind_addr;
[1]140static int use_bind_addr = 0;
141
[20]142int 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]165long 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]212long 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
[317]244static int sh_enable_use_sub = 0;
245
246#if defined (SH_WITH_CLIENT) || defined (SH_STANDALONE)
247static int sh_use_sub = 1;
248#else
[315]249static int sh_use_sub = 0;
[317]250#endif
[315]251
[317]252void sh_calls_enable_sub()
253{
254 sh_enable_use_sub = 1;
255 return;
256}
257
[315]258int sh_calls_set_sub (const char * str)
259{
[317]260 int ret = sh_util_flagval(str, &sh_use_sub);
261
262 if ((ret == 0) && (!sh_use_sub))
263 {
264 sh_kill_sub();
265 }
266 return ret;
[315]267}
268
[317]269long int retry_lstat_ns(const char * file, int line,
270 const char *file_name, struct stat *buf)
271{
272 int error;
273 long int val_retry = -1;
274 char errbuf[SH_ERRBUF_SIZE];
275
276 SL_ENTER(_("retry_lstat_ns"));
277
278 do {
279 val_retry = /*@-unrecog@*/lstat (file_name, buf)/*@+unrecog@*/;
280 } while (val_retry < 0 && errno == EINTR);
281
282 error = errno;
283 if (val_retry < 0) {
284 (void) sh_error_message(error, aud_err_message, 64);
285 sh_error_handle ((-1), file, line, error, MSG_ERR_LSTAT,
286 sh_error_message(error, errbuf, sizeof(errbuf)),
287 file_name );
288 }
289 errno = error;
290
291 SL_RETURN(val_retry, _("retry_lstat_ns"));
292}
293
[170]294long int retry_lstat(const char * file, int line,
[1]295 const char *file_name, struct stat *buf)
296{
297 int error;
298 long int val_retry = -1;
[132]299 char errbuf[SH_ERRBUF_SIZE];
[1]300
301 SL_ENTER(_("retry_lstat"));
302
[317]303 if (sh_use_sub && sh_enable_use_sub)
[315]304 {
305 val_retry = sh_sub_lstat (file_name, buf);
306 }
307 else
308 {
309 do {
310 val_retry = /*@-unrecog@*/lstat (file_name, buf)/*@+unrecog@*/;
311 } while (val_retry < 0 && errno == EINTR);
312 }
313
[1]314 error = errno;
315 if (val_retry < 0) {
[134]316 (void) sh_error_message(error, aud_err_message, 64);
[1]317 sh_error_handle ((-1), file, line, error, MSG_ERR_LSTAT,
[132]318 sh_error_message(error, errbuf, sizeof(errbuf)),
[1]319 file_name );
320 }
321 errno = error;
[315]322
[1]323 SL_RETURN(val_retry, _("retry_lstat"));
324}
325
[170]326long int retry_stat(const char * file, int line,
[1]327 const char *file_name, struct stat *buf)
328{
329 int error;
330 long int val_retry = -1;
[132]331 char errbuf[SH_ERRBUF_SIZE];
[1]332
333 SL_ENTER(_("retry_stat"));
334
[317]335 if (sh_use_sub && sh_enable_use_sub)
[315]336 {
337 val_retry = sh_sub_stat (file_name, buf);
338 }
339 else
340 {
341 do {
342 val_retry = stat (file_name, buf);
343 } while (val_retry < 0 && errno == EINTR);
344 }
345
[1]346 error = errno;
347 if (val_retry < 0) {
[134]348 (void) sh_error_message(error, aud_err_message, 64);
[1]349 sh_error_handle ((-1), file, line, error, MSG_ERR_STAT,
[132]350 sh_error_message(error, errbuf, sizeof(errbuf)),
[1]351 file_name );
352 }
353 errno = error;
[315]354
[1]355 SL_RETURN(val_retry, _("retry_stat"));
356}
357
[170]358long int retry_fstat(const char * file, int line, int filed, struct stat *buf)
[1]359{
360 int error;
361 long int val_retry = -1;
[132]362 char errbuf[SH_ERRBUF_SIZE];
[1]363
364 SL_ENTER(_("retry_fstat"));
365
366 do {
367 val_retry = fstat (filed, buf);
368 } while (val_retry < 0 && errno == EINTR);
369 error = errno;
370 if (val_retry < 0) {
371 sh_error_handle ((-1), file, line, error, MSG_ERR_FSTAT,
[132]372 sh_error_message(error, errbuf, sizeof(errbuf)),
[1]373 (long) filed );
374 }
375 errno = error;
376 SL_RETURN(val_retry, _("retry_fstat"));
377}
378
[170]379long int retry_fcntl(const char * file, int line, int fd, int cmd, long arg)
[1]380{
381 int error;
382 long int val_retry = -1;
[132]383 char errbuf[SH_ERRBUF_SIZE];
[1]384 errno = 0;
385
386 SL_ENTER(_("retry_fcntl"));
387
388 if (cmd == F_GETFD || cmd == F_GETFL)
389 {
390 do {
391 val_retry = fcntl(fd, cmd);
392 } while (val_retry < 0 && errno == EINTR);
393 }
394 else
395 {
396 do {
397 val_retry = fcntl(fd, cmd, arg);
398 } while (val_retry < 0 && errno == EINTR);
399 }
400 error = errno;
401 if (val_retry < 0) {
402 sh_error_handle ((-1), file, line, error, MSG_ERR_FCNTL,
[132]403 sh_error_message(error, errbuf, sizeof(errbuf)),
[1]404 (long) fd, (long) cmd, arg );
405 }
406 errno = error;
407 SL_RETURN(val_retry, _("retry_fcntl"));
408}
409
410long int retry_msleep (int sec, int millisec)
411{
412 int result = 0;
413#if defined(HAVE_NANOSLEEP)
414 struct timespec req, rem;
415#endif
416
[169]417 SL_ENTER(_("retry_msleep"));
[1]418
419 errno = 0;
420 if (millisec > 999) millisec = 999;
421 if (millisec < 0) millisec = 0;
422 if (sec < 0) sec = 0;
423
424#if defined(HAVE_NANOSLEEP)
425 /*@-usedef@*/
426 req.tv_sec = sec; rem.tv_sec = 0;
427 req.tv_nsec = millisec * 1000000; rem.tv_nsec = 0;
428 /*@+usedef@*/
429 do {
430 result = /*@-unrecog@*/nanosleep(&req, &rem)/*@+unrecog@*/;
431
432 req.tv_sec = rem.tv_sec; rem.tv_sec = 0;
433 req.tv_nsec = rem.tv_nsec; rem.tv_nsec = 0;
434
435 } while ((result == -1) && (errno == EINTR));
436#else
437 if (sec > 0)
438 {
[134]439 sleep (sec); /* nanosleep not available */
[1]440 }
441 else
442 {
443#ifdef HAVE_USLEEP
444 if (millisec > 0)
445 {
446 usleep(1000 * millisec);
447 }
448#else
449 if (millisec > 0)
450 {
451 sleep (1);
452 }
453#endif
454 }
455#endif
456 SL_RETURN(result, _("retry_msleep"));
457}
458
459/***************************************************
460 *
461 * Audit these functions.
462 *
463 ***************************************************/
464
[170]465long int retry_aud_execve (const char * file, int line,
[1]466 const char *dateiname, char * argv[],
467 char * envp[])
468{
469 uid_t a = geteuid();
470 gid_t b = getegid();
471 int i;
472 int error;
[132]473 char errbuf[SH_ERRBUF_SIZE];
[1]474
475 SL_ENTER(_("retry_aud_execve"));
476
477 if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_EXEC) != 0)
478 sh_error_handle ((-1), file, line, 0, MSG_AUD_EXEC,
479 dateiname, (long) a, (long) b );
480 do {
481 i = execve(dateiname, argv, envp);
482 } while (i < 0 && errno == EINTR);
483
484 error = errno;
485 if (i < 0) {
[132]486 sh_error_handle ((-1), file, line, error, MSG_ERR_EXEC,
487 sh_error_message(error, errbuf, sizeof(errbuf)),
[1]488 dateiname, (long) a, (long) b );
489 }
490 errno = error;
491 SL_RETURN(i, _("retry_aud_execve"));
492}
493
494
[170]495long int retry_aud_utime (const char * file, int line,
496 char * path, struct utimbuf *buf)
[1]497{
498 long int val_return;
499 int error;
[132]500 char errbuf[SH_ERRBUF_SIZE];
[1]501 errno = 0;
502
503 SL_ENTER(_("retry_aud_utime"));
504
505 do {
506 val_return = utime (path, buf);
507 } while (val_return < 0 && errno == EINTR);
508
509 error = errno;
510 if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_UTIME) != 0)
511 sh_error_handle ((-1), file, line, 0, MSG_AUD_UTIME,
512 path,
513 (unsigned long) buf->actime,
514 (unsigned long) buf->modtime);
515 if (val_return < 0) {
516 sh_error_handle ((-1), file, line, error, MSG_ERR_UTIME,
[132]517 sh_error_message(error, errbuf, sizeof(errbuf)),
[1]518 path,
519 (unsigned long) buf->actime,
520 (unsigned long) buf->modtime);
521 }
522 errno = error;
523 SL_RETURN(val_return, _("retry_aud_utime"));
524}
525
[170]526long int retry_aud_unlink (const char * file, int line,
[1]527 char * path)
528{
529 long int val_return;
530 int error;
[132]531 char errbuf[SH_ERRBUF_SIZE];
[1]532 errno = 0;
533
534 SL_ENTER(_("retry_aud_unlink"));
535
536 do {
537 val_return = unlink (path);
538 } while (val_return < 0 && errno == EINTR);
539
540 error = errno;
541 if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_UNLINK) != 0)
542 sh_error_handle ((-1), file, line, 0, MSG_AUD_UNLINK,
543 path);
544 if (val_return < 0) {
[132]545 sh_error_handle ((-1), file, line, error, MSG_ERR_UNLINK,
546 sh_error_message(error, errbuf, sizeof(errbuf)),
[1]547 path);
548 }
549 errno = error;
550 SL_RETURN(val_return, _("retry_aud_unlink"));
551}
552
[170]553long int retry_aud_dup2 (const char * file, int line,
[1]554 int fd, int fd2)
555{
556 long int val_return;
557 int error;
[132]558 char errbuf[SH_ERRBUF_SIZE];
[1]559 errno = 0;
560
561 SL_ENTER(_("retry_aud_dup2"));
562
563 do {
564 val_return = dup2 (fd, fd2);
565 } while (val_return < 0 && errno == EINTR);
566
567 error = errno;
568 if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_DUP) != 0)
569 sh_error_handle ((-1), file, line, 0, MSG_AUD_DUP,
570 (long) fd, val_return);
571 if (val_return < 0) {
572 sh_error_handle ((-1), file, line, error, MSG_ERR_DUP,
[132]573 sh_error_message(error, errbuf, sizeof(errbuf)),
[1]574 (long) fd, val_return);
575 }
576 errno = error;
577 SL_RETURN(val_return, _("retry_aud_dup2"));
578}
579
[170]580long int retry_aud_dup (const char * file, int line,
[1]581 int fd)
582{
583 long int val_return;
584 int error;
[132]585 char errbuf[SH_ERRBUF_SIZE];
[1]586 errno = 0;
587
588 SL_ENTER(_("retry_aud_dup"));
589
590 do {
591 val_return = dup (fd);
592 } while (val_return < 0 && errno == EINTR);
593 error = errno;
594 if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_DUP) != 0)
595 sh_error_handle ((-1), file, line, 0, MSG_AUD_DUP,
596 (long) fd, val_return);
597 if (val_return < 0) {
598 sh_error_handle ((-1), file, line, error, MSG_ERR_DUP,
[132]599 sh_error_message(error, errbuf, sizeof(errbuf)),
[1]600 (long) fd, val_return);
601 }
602 errno = error;
603 SL_RETURN(val_return, _("retry_aud_dup"));
604}
605
606
607
[170]608long int retry_aud_chdir (const char * file, int line,
[1]609 const char *path)
610{
611 long int val_return;
612 int error = 0;
[132]613 char errbuf[SH_ERRBUF_SIZE];
[1]614 errno = 0;
615
616 SL_ENTER(_("retry_aud_chdir"));
617
618 do {
619 val_return = chdir (path);
620 } while (val_return < 0 && errno == EINTR);
621
622 error = errno;
623 if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_CHDIR) != 0)
624 sh_error_handle ((-1), file, line, 0, MSG_AUD_CHDIR,
625 path);
626 if (val_return < 0) {
[132]627 sh_error_handle ((-1), file, line, error, MSG_ERR_CHDIR,
628 sh_error_message(error, errbuf, sizeof(errbuf)),
[1]629 path);
630 }
631 errno = error;
632 SL_RETURN(val_return, _("retry_aud_chdir"));
633}
634
635
[170]636long int aud_open_noatime (const char * file, int line, int privs,
[1]637 const char *pathname, int flags, mode_t mode,
638 int * o_noatime)
639{
640 long int val_return;
641 int error;
[132]642 char errbuf[SH_ERRBUF_SIZE];
[1]643
644 SL_ENTER(_("aud_open"));
645
646 val_return = open (pathname, *o_noatime|flags, mode);
647 if ((val_return < 0) && (*o_noatime != 0))
648 {
649 val_return = open (pathname, flags, mode);
650 if (val_return >= 0)
651 *o_noatime = 0;
652 }
653 error = errno;
654 /*@-noeffect@*/
655 (void) privs; /* fix compiler warning */
656 /*@+noeffect@*/
657
658 if (val_return < 0)
659 {
[134]660 (void) sh_error_message(error, aud_err_message, 64);
[1]661 }
662
663 if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_OPEN) != 0)
664 {
665 sh_error_handle ((-1), file, line, 0, MSG_AUD_OPEN,
666 pathname, (long) flags, (long) mode, val_return);
667 }
668 if (val_return < 0) {
669 sh_error_handle ((-1), file, line, error, MSG_ERR_OPEN,
[132]670 sh_error_message(error, errbuf, sizeof(errbuf)),
[1]671 pathname, (long) flags, (long) mode, val_return);
672 }
673 errno = error;
674 SL_RETURN(val_return, _("aud_open"));
675}
676
[170]677long int aud_open (const char * file, int line, int privs,
[1]678 const char *pathname, int flags, mode_t mode)
679{
680 long int val_return;
681 int error;
[132]682 char errbuf[SH_ERRBUF_SIZE];
[1]683
684 SL_ENTER(_("aud_open"));
685
686 val_return = open (pathname, flags, mode);
687 error = errno;
688 /*@-noeffect@*/
689 (void) privs; /* fix compiler warning */
690 /*@+noeffect@*/
691
692 if (val_return < 0)
693 {
[134]694 (void) sh_error_message(error, aud_err_message, 64);
[1]695 }
696
697 if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_OPEN) != 0)
698 {
699 sh_error_handle ((-1), file, line, 0, MSG_AUD_OPEN,
700 pathname, (long) flags, (long) mode, val_return);
701 }
702 if (val_return < 0) {
703 sh_error_handle ((-1), file, line, error, MSG_ERR_OPEN,
[132]704 sh_error_message(error, errbuf, sizeof(errbuf)),
[1]705 pathname, (long) flags, (long) mode, val_return);
706 }
707 errno = error;
708 SL_RETURN(val_return, _("aud_open"));
709}
710
[170]711long int aud_kill (const char * file, int line, pid_t pid, int sig)
[1]712{
713 int myerror;
714 long int val_return = kill (pid, sig);
[132]715 char errbuf[SH_ERRBUF_SIZE];
[1]716 myerror = errno;
717
718 SL_ENTER(_("aud_kill"));
719
720 if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_KILL) != 0)
721 sh_error_handle ((-1), file, line, 0, MSG_AUD_KILL,
722 (long) pid, (long) sig);
723 if (val_return < 0) {
724 sh_error_handle ((-1), file, line, myerror, MSG_ERR_KILL,
[132]725 sh_error_message(myerror, errbuf, sizeof(errbuf)),
[1]726 (long) pid, (long) sig);
727 }
728 errno = myerror;
729 SL_RETURN(val_return, _("aud_kill"));
730}
731
732/*@noreturn@*/
[170]733void aud_exit (const char * file, int line, int fd)
[1]734{
735 if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_EXIT) != 0)
736 sh_error_handle ((-1), file, line, 0, MSG_AUD_EXIT,
737 (long) fd);
738
739 SL_ENTER(_("aud_exit"));
740
741 sh.flag.exit = fd;
742 exit(fd);
743}
744
745/*@noreturn@*/
[170]746void aud__exit (const char * file, int line, int fd)
[1]747{
748 if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_EXIT) != 0)
749 sh_error_handle ((-1), file, line, 0, MSG_AUD_EXIT,
750 (long) fd);
751
752 SL_ENTER(_("aud__exit"));
753
754 sh.flag.exit = fd;
755 _exit(fd);
756}
757
[170]758pid_t aud_fork (const char * file, int line)
[1]759{
760 int error;
761 pid_t i = fork();
[132]762 char errbuf[SH_ERRBUF_SIZE];
[1]763
764 error = errno;
765 SL_ENTER(_("aud_fork"));
766
767 if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_FORK) != 0 && (i > 0))
768 sh_error_handle ((-1), file, line, 0, MSG_AUD_FORK,
769 (long) i);
770 if (i == (pid_t) -1) {
771 sh_error_handle ((-1), file, line, error, MSG_ERR_FORK,
[132]772 sh_error_message(error, errbuf, sizeof(errbuf)),
[1]773 (long) i);
774 }
775 errno = error;
776 SL_RETURN(i, _("aud_fork"));
777}
778
[170]779int aud_setuid (const char * file, int line, uid_t uid)
[1]780{
781 int error = 0;
782 int i = 0;
[132]783 char errbuf[SH_ERRBUF_SIZE];
[1]784
785 SL_ENTER(_("aud_setuid"));
786
787 if (uid != (uid_t) 0) {
788 i = setuid(uid);
789 error = errno;
790 }
791 if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_SETUID) != 0)
792 sh_error_handle ((-1), file, line, 0, MSG_AUD_SETUID,
793 (long) uid);
794 if (uid == (uid_t) 0) {
795 i = setuid(uid);
796 error = errno;
797 }
798 if (i < 0) {
799 sh_error_handle ((-1), file, line, error, MSG_ERR_SETUID,
[132]800 sh_error_message(error, errbuf, sizeof(errbuf)),
[1]801 (long) uid);
802 }
803 errno = error;
804 SL_RETURN(i, _("aud_setuid"));
805}
806
[170]807int aud_setgid (const char * file, int line, gid_t gid)
[1]808{
809 int error = 0;
810 int i = 0;
[132]811 char errbuf[SH_ERRBUF_SIZE];
[1]812
813 SL_ENTER(_("aud_setgid"));
814
815 if (gid != (gid_t) 0) {
816 i = setgid(gid);
817 error = errno;
818 }
819
820 if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_SETGID) != 0)
821 sh_error_handle ((-1), file, line, 0, MSG_AUD_SETGID,
822 (long) gid);
823 if (gid == (gid_t) 0) {
824 i = setgid(gid);
825 error = errno;
826 }
827 if (i < 0) {
828 sh_error_handle ((-1), file, line, error, MSG_ERR_SETGID,
[132]829 sh_error_message(error, errbuf, sizeof(errbuf)),
[1]830 (long) gid);
831 }
832 errno = error;
833 SL_RETURN(i, _("aud_setgid"));
834}
835
[170]836int aud_pipe (const char * file, int line, int * modus)
[1]837{
838 int error;
839 int i = pipe (modus);
[132]840 char errbuf[SH_ERRBUF_SIZE];
[1]841
842 SL_ENTER(_("aud_pipe"));
843
844 error = errno;
845 if (sh.flag.audit != 0 && (sh.flag.aud_mask & AUD_PIPE) != 0)
846 {
847 if (i < 0)
848 sh_error_handle ((-1), file, line, 0, MSG_AUD_PIPE,
849 (long) 0, (long) 0);
850 else
851 sh_error_handle ((-1), file, line, 0, MSG_AUD_PIPE,
852 (long) modus[0], (long) modus[1]);
853 }
854 if (i < 0) {
855 if (i < 0)
856 sh_error_handle ((-1), file, line, error, MSG_ERR_PIPE,
[137]857 sh_error_message(error, errbuf, sizeof(errbuf)),
[1]858 (long) 0, (long) 0);
859 else
860 sh_error_handle ((-1), file, line, error, MSG_ERR_PIPE,
[132]861 sh_error_message(error, errbuf, sizeof(errbuf)),
[1]862 (long) modus[0], (long) modus[1]);
863 }
864 SL_RETURN(i, _("aud_pipe"));
865}
Note: See TracBrowser for help on using the repository browser.