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