CVE-2022-2031 s4:kdc: Reject tickets during the last two minutes of their life
[Samba.git] / lib / util / debug_s3.c
blob151227c34196ce38546e45f0f494282013bb8f0c
1 /*
2 Unix SMB/CIFS implementation.
3 Samba utility functions
4 Copyright (C) Andrew Bartlett 2011
5 Copyright (C) Andrew Tridgell 1992-2002
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "includes.h"
22 #include "lib/util/server_id.h"
23 #include "librpc/gen_ndr/messaging.h"
24 #include "messages.h"
25 #include "lib/util/memory.h"
27 /* This is the Samba3-specific implementation of reopen_logs(), which
28 * calls out to the s3 loadparm code, and means that we don't depend
29 * on loadparm directly. */
31 bool reopen_logs(void)
33 if (lp_loaded()) {
34 struct debug_settings settings = {
35 .max_log_size = lp_max_log_size(),
36 .timestamp_logs = lp_timestamp_logs(),
37 .debug_prefix_timestamp = lp_debug_prefix_timestamp(),
38 .debug_hires_timestamp = lp_debug_hires_timestamp(),
39 .debug_pid = lp_debug_pid(),
40 .debug_uid = lp_debug_uid(),
41 .debug_class = lp_debug_class(),
43 const struct loadparm_substitution *lp_sub =
44 loadparm_s3_global_substitution();
46 debug_set_logfile(lp_logfile(talloc_tos(), lp_sub));
47 debug_parse_levels(lp_log_level(talloc_tos(), lp_sub));
48 debug_set_settings(&settings,
49 lp_logging(talloc_tos(), lp_sub),
50 lp_syslog(),
51 lp_syslog_only());
52 } else {
54 * Parameters are not yet loaded - configure debugging with
55 * reasonable defaults to enable logging for early
56 * startup failures.
58 struct debug_settings settings = {
59 .max_log_size = 5000,
60 .timestamp_logs = true,
61 .debug_prefix_timestamp = false,
62 .debug_hires_timestamp = true,
63 .debug_pid = false,
64 .debug_uid = false,
65 .debug_class = false,
67 debug_set_settings(&settings,
68 "file",
70 false);
72 return reopen_logs_internal();
75 /****************************************************************************
76 Receive a "set debug level" message.
77 ****************************************************************************/
79 void debug_message(struct messaging_context *msg_ctx,
80 void *private_data,
81 uint32_t msg_type,
82 struct server_id src,
83 DATA_BLOB *data)
85 const char *params_str = (const char *)data->data;
87 /* Check, it's a proper string! */
88 if (params_str[(data->length)-1] != '\0') {
89 DEBUG(1, ("Invalid debug message from pid %u to pid %u\n",
90 (unsigned int)procid_to_pid(&src),
91 (unsigned int)getpid()));
92 return;
95 DEBUG(3, ("INFO: Remote set of debug to `%s' (pid %u from pid %u)\n",
96 params_str, (unsigned int)getpid(),
97 (unsigned int)procid_to_pid(&src)));
99 debug_parse_levels(params_str);
102 /****************************************************************************
103 Return current debug level.
104 ****************************************************************************/
106 static void debuglevel_message(struct messaging_context *msg_ctx,
107 void *private_data,
108 uint32_t msg_type,
109 struct server_id src,
110 DATA_BLOB *data)
112 char *message = debug_list_class_names_and_levels();
113 struct server_id_buf tmp;
115 if (!message) {
116 DEBUG(0,("debuglevel_message - debug_list_class_names_and_levels returned NULL\n"));
117 return;
120 DEBUG(1, ("INFO: Received REQ_DEBUGLEVEL message from PID %s\n",
121 server_id_str_buf(src, &tmp)));
122 messaging_send_buf(msg_ctx, src, MSG_DEBUGLEVEL,
123 (uint8_t *)message, strlen(message) + 1);
125 TALLOC_FREE(message);
128 static void debug_ringbuf_log(struct messaging_context *msg_ctx,
129 void *private_data,
130 uint32_t msg_type,
131 struct server_id src,
132 DATA_BLOB *data)
134 char *log = debug_get_ringbuf();
135 size_t logsize = debug_get_ringbuf_size();
137 if (log == NULL) {
138 log = discard_const_p(char, "*disabled*\n");
139 logsize = strlen(log) + 1;
142 messaging_send_buf(msg_ctx, src, MSG_RINGBUF_LOG, (uint8_t *)log,
143 logsize);
146 void debug_register_msgs(struct messaging_context *msg_ctx)
148 messaging_register(msg_ctx, NULL, MSG_DEBUG, debug_message);
149 messaging_register(msg_ctx, NULL, MSG_REQ_DEBUGLEVEL,
150 debuglevel_message);
151 messaging_register(msg_ctx, NULL, MSG_REQ_RINGBUF_LOG,
152 debug_ringbuf_log);