/src/sudo/plugins/sudoers/parser_warnx.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * SPDX-License-Identifier: ISC |
3 | | * |
4 | | * Copyright (c) 2022-2023 Todd C. Miller <Todd.Miller@sudo.ws> |
5 | | * |
6 | | * Permission to use, copy, modify, and distribute this software for any |
7 | | * purpose with or without fee is hereby granted, provided that the above |
8 | | * copyright notice and this permission notice appear in all copies. |
9 | | * |
10 | | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
11 | | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
12 | | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
13 | | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
14 | | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
15 | | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
16 | | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
17 | | */ |
18 | | |
19 | | /* |
20 | | * This is an open source non-commercial project. Dear PVS-Studio, please check it. |
21 | | * PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com |
22 | | */ |
23 | | |
24 | | #include <config.h> |
25 | | |
26 | | #include <stdarg.h> |
27 | | #include <stdio.h> |
28 | | #include <stdlib.h> |
29 | | |
30 | | #include <sudoers.h> |
31 | | |
32 | | bool |
33 | | parser_vwarnx(const struct sudoers_context *ctx, const char *file, int line, |
34 | | int column, bool strict, bool quiet, const char * restrict fmt, va_list ap) |
35 | 0 | { |
36 | 0 | bool ret = true; |
37 | 0 | debug_decl(parser_warnx, SUDOERS_DEBUG_DEFAULTS); |
38 | |
|
39 | 0 | if (strict && sudoers_error_hook != NULL) { |
40 | 0 | va_list ap2; |
41 | |
|
42 | 0 | va_copy(ap2, ap); |
43 | 0 | ret = sudoers_error_hook(ctx, file, line, column, fmt, ap2); |
44 | 0 | va_end(ap2); |
45 | 0 | } |
46 | |
|
47 | 0 | if (!quiet) { |
48 | 0 | int oldlocale; |
49 | 0 | char *errstr; |
50 | |
|
51 | 0 | sudoers_setlocale(SUDOERS_LOCALE_USER, &oldlocale); |
52 | 0 | if (vasprintf(&errstr, _(fmt), ap) == -1) { |
53 | 0 | errstr = NULL; |
54 | 0 | ret = false; |
55 | 0 | } else if (line > 0) { |
56 | 0 | sudo_printf(SUDO_CONV_ERROR_MSG, _("%s:%d:%d: %s\n"), file, |
57 | 0 | line, column, errstr); |
58 | 0 | } else { |
59 | 0 | sudo_printf(SUDO_CONV_ERROR_MSG, _("%s: %s\n"), file, errstr); |
60 | 0 | } |
61 | 0 | sudoers_setlocale(oldlocale, NULL); |
62 | |
|
63 | 0 | free(errstr); |
64 | 0 | } |
65 | |
|
66 | 0 | debug_return_bool(ret); |
67 | 0 | } |
68 | | |
69 | | bool |
70 | | parser_warnx(const struct sudoers_context *ctx, const char *file, int line, |
71 | | int column, bool strict, bool quiet, const char * restrict fmt, ...) |
72 | 0 | { |
73 | 0 | va_list ap; |
74 | 0 | bool ret; |
75 | 0 | debug_decl(parser_warnx, SUDOERS_DEBUG_DEFAULTS); |
76 | |
|
77 | 0 | va_start(ap, fmt); |
78 | 0 | ret = parser_vwarnx(ctx, file, line, column, strict, quiet, fmt, ap); |
79 | 0 | va_end(ap); |
80 | |
|
81 | 0 | debug_return_bool(ret); |
82 | 0 | } |