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