source: trunk/src/sh_calls.c@ 299

Last change on this file since 299 was 295, checked in by katerina, 14 years ago

Support for IPv6 (ticket #222).

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