| 1 | /*
|
|---|
| 2 | Unix SMB/CIFS implementation.
|
|---|
| 3 | Samba utility functions
|
|---|
| 4 | Copyright (C) Andrew Bartlett 2011
|
|---|
| 5 | Copyright (C) Andrew Tridgell 1992-2002
|
|---|
| 6 |
|
|---|
| 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.
|
|---|
| 11 |
|
|---|
| 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.
|
|---|
| 16 |
|
|---|
| 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/>.
|
|---|
| 19 | */
|
|---|
| 20 |
|
|---|
| 21 | #include "includes.h"
|
|---|
| 22 | #include "librpc/gen_ndr/messaging.h"
|
|---|
| 23 | #include "messages.h"
|
|---|
| 24 |
|
|---|
| 25 | /* This is the Samba3-specific implementation of reopen_logs(), which
|
|---|
| 26 | * calls out to the s3 loadparm code, and means that we don't depend
|
|---|
| 27 | * on loadparm directly. */
|
|---|
| 28 |
|
|---|
| 29 | bool reopen_logs(void)
|
|---|
| 30 | {
|
|---|
| 31 | if (lp_loaded()) {
|
|---|
| 32 | struct debug_settings settings;
|
|---|
| 33 | debug_set_logfile(lp_logfile());
|
|---|
| 34 |
|
|---|
| 35 | ZERO_STRUCT(settings);
|
|---|
| 36 | settings.max_log_size = lp_max_log_size();
|
|---|
| 37 | settings.syslog = lp_syslog();
|
|---|
| 38 | settings.syslog_only = lp_syslog_only();
|
|---|
| 39 | settings.timestamp_logs = lp_timestamp_logs();
|
|---|
| 40 | settings.debug_prefix_timestamp = lp_debug_prefix_timestamp();
|
|---|
| 41 | settings.debug_hires_timestamp = lp_debug_hires_timestamp();
|
|---|
| 42 | settings.debug_pid = lp_debug_pid();
|
|---|
| 43 | settings.debug_uid = lp_debug_uid();
|
|---|
| 44 | settings.debug_class = lp_debug_class();
|
|---|
| 45 | debug_set_settings(&settings);
|
|---|
| 46 | }
|
|---|
| 47 | return reopen_logs_internal();
|
|---|
| 48 | }
|
|---|
| 49 |
|
|---|
| 50 | /****************************************************************************
|
|---|
| 51 | Receive a "set debug level" message.
|
|---|
| 52 | ****************************************************************************/
|
|---|
| 53 |
|
|---|
| 54 | void debug_message(struct messaging_context *msg_ctx,
|
|---|
| 55 | void *private_data,
|
|---|
| 56 | uint32_t msg_type,
|
|---|
| 57 | struct server_id src,
|
|---|
| 58 | DATA_BLOB *data)
|
|---|
| 59 | {
|
|---|
| 60 | const char *params_str = (const char *)data->data;
|
|---|
| 61 |
|
|---|
| 62 | /* Check, it's a proper string! */
|
|---|
| 63 | if (params_str[(data->length)-1] != '\0') {
|
|---|
| 64 | DEBUG(1, ("Invalid debug message from pid %u to pid %u\n",
|
|---|
| 65 | (unsigned int)procid_to_pid(&src),
|
|---|
| 66 | (unsigned int)getpid()));
|
|---|
| 67 | return;
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|
| 70 | DEBUG(3, ("INFO: Remote set of debug to `%s' (pid %u from pid %u)\n",
|
|---|
| 71 | params_str, (unsigned int)getpid(),
|
|---|
| 72 | (unsigned int)procid_to_pid(&src)));
|
|---|
| 73 |
|
|---|
| 74 | debug_parse_levels(params_str);
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 | /****************************************************************************
|
|---|
| 78 | Return current debug level.
|
|---|
| 79 | ****************************************************************************/
|
|---|
| 80 |
|
|---|
| 81 | static void debuglevel_message(struct messaging_context *msg_ctx,
|
|---|
| 82 | void *private_data,
|
|---|
| 83 | uint32_t msg_type,
|
|---|
| 84 | struct server_id src,
|
|---|
| 85 | DATA_BLOB *data)
|
|---|
| 86 | {
|
|---|
| 87 | char *message = debug_list_class_names_and_levels();
|
|---|
| 88 |
|
|---|
| 89 | if (!message) {
|
|---|
| 90 | DEBUG(0,("debuglevel_message - debug_list_class_names_and_levels returned NULL\n"));
|
|---|
| 91 | return;
|
|---|
| 92 | }
|
|---|
| 93 |
|
|---|
| 94 | DEBUG(1,("INFO: Received REQ_DEBUGLEVEL message from PID %s\n",
|
|---|
| 95 | procid_str_static(&src)));
|
|---|
| 96 | messaging_send_buf(msg_ctx, src, MSG_DEBUGLEVEL,
|
|---|
| 97 | (uint8 *)message, strlen(message) + 1);
|
|---|
| 98 |
|
|---|
| 99 | TALLOC_FREE(message);
|
|---|
| 100 | }
|
|---|
| 101 | void debug_register_msgs(struct messaging_context *msg_ctx)
|
|---|
| 102 | {
|
|---|
| 103 | messaging_register(msg_ctx, NULL, MSG_DEBUG, debug_message);
|
|---|
| 104 | messaging_register(msg_ctx, NULL, MSG_REQ_DEBUGLEVEL,
|
|---|
| 105 | debuglevel_message);
|
|---|
| 106 | }
|
|---|