source: trunk/src/sh_calls.c@ 173

Last change on this file since 173 was 171, checked in by katerina, 16 years ago

Include dnmalloc (ticket #108) and fix bugs #106 (EINPROGRESS) and #107 (compressBound).

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