/* Send a message to a destination pid. Zero means broadcast smbd. */
-static BOOL send_message(struct messaging_context *msg_ctx,
+static bool send_message(struct messaging_context *msg_ctx,
struct server_id pid, int msg_type,
const void *buf, int len)
{
- BOOL ret;
+ bool ret;
int n_sent = 0;
if (procid_to_pid(&pid) != 0)
return ret;
}
+static void timeout_handler(struct event_context *event_ctx,
+ struct timed_event *te,
+ const struct timeval *now,
+ void *private_data)
+{
+ bool *timed_out = (bool *)private_data;
+ TALLOC_FREE(te);
+ *timed_out = True;
+}
+
/* Wait for one or more reply messages */
static void wait_replies(struct messaging_context *msg_ctx,
- BOOL multiple_replies)
+ bool multiple_replies)
{
- time_t start_time = time(NULL);
-
- /* Wait around a bit. This is pretty disgusting - we have to
- busy-wait here as there is no nicer way to do it. */
+ struct timed_event *te;
+ bool timed_out = False;
+
+ if (!(te = event_add_timed(messaging_event_context(msg_ctx), NULL,
+ timeval_current_ofs(timeout, 0),
+ "smbcontrol_timeout",
+ timeout_handler, (void *)&timed_out))) {
+ DEBUG(0, ("event_add_timed failed\n"));
+ return;
+ }
- do {
+ while (!timed_out) {
message_dispatch(msg_ctx);
- event_loop_once(messaging_event_context(msg_ctx));
if (num_replies > 0 && !multiple_replies)
break;
- sleep(1);
- } while (timeout - (time(NULL) - start_time) > 0);
+ event_loop_once(messaging_event_context(msg_ctx));
+ }
}
/* Message handler callback that displays the PID and a string on stdout */
/* Send no message. Useful for testing. */
-static BOOL do_noop(struct messaging_context *msg_ctx,
+static bool do_noop(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
/* Send a debug string */
-static BOOL do_debug(struct messaging_context *msg_ctx,
+static bool do_debug(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
return 0;
}
-static BOOL do_daemon_stack_trace(struct messaging_context *msg_ctx,
+static bool do_daemon_stack_trace(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
- fprintf(stderr,
- "Daemon stack tracing is not supported on this platform\n");
- return False;
-
pid_t dest;
int count = 0;
#else /* defined(HAVE_LIBUNWIND_PTRACE) && defined(HAVE_LINUX_PTRACE) */
-static BOOL do_daemon_stack_trace(struct messaging_context *msg_ctx,
+static bool do_daemon_stack_trace(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
/* Inject a fault (fatal signal) into a running smbd */
-static BOOL do_inject_fault(struct messaging_context *msg_ctx,
+static bool do_inject_fault(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
/* Force a browser election */
-static BOOL do_election(struct messaging_context *msg_ctx,
+static bool do_election(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
num_replies++;
}
-static BOOL do_ping(struct messaging_context *msg_ctx,
+static bool do_ping(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
/* Set profiling options */
-static BOOL do_profile(struct messaging_context *msg_ctx,
+static bool do_profile(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
send_message(msg_ctx, pid, MSG_PROFILELEVEL, &v, sizeof(int));
}
-static BOOL do_profilelevel(struct messaging_context *msg_ctx,
+static bool do_profilelevel(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
/* Display debug level settings */
-static BOOL do_debuglevel(struct messaging_context *msg_ctx,
+static bool do_debuglevel(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
/* Send a print notify message */
-static BOOL do_printnotify(struct messaging_context *msg_ctx,
+static bool do_printnotify(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
/* Close a share */
-static BOOL do_closeshare(struct messaging_context *msg_ctx,
+static bool do_closeshare(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
/* force a blocking lock retry */
-static BOOL do_lockretry(struct messaging_context *msg_ctx,
+static bool do_lockretry(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
/* force a validation of all brl entries, including re-sends. */
-static BOOL do_brl_revalidate(struct messaging_context *msg_ctx,
+static bool do_brl_revalidate(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
/* Force a SAM synchronisation */
-static BOOL do_samsync(struct messaging_context *msg_ctx,
+static bool do_samsync(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
/* Force a SAM replication */
-static BOOL do_samrepl(struct messaging_context *msg_ctx,
+static bool do_samrepl(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
/* Display talloc pool usage */
-static BOOL do_poolusage(struct messaging_context *msg_ctx,
+static bool do_poolusage(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
/* Perform a dmalloc mark */
-static BOOL do_dmalloc_mark(struct messaging_context *msg_ctx,
+static bool do_dmalloc_mark(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
/* Perform a dmalloc changed */
-static BOOL do_dmalloc_changed(struct messaging_context *msg_ctx,
+static bool do_dmalloc_changed(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
/* Shutdown a server process */
-static BOOL do_shutdown(struct messaging_context *msg_ctx,
+static bool do_shutdown(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
/* Notify a driver upgrade */
-static BOOL do_drvupgrade(struct messaging_context *msg_ctx,
+static bool do_drvupgrade(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
strlen(argv[1]) + 1);
}
-static BOOL do_winbind_online(struct messaging_context *msg_ctx,
+static bool do_winbind_online(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
return send_message(msg_ctx, pid, MSG_WINBIND_ONLINE, NULL, 0);
}
-static BOOL do_winbind_offline(struct messaging_context *msg_ctx,
+static bool do_winbind_offline(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
TDB_CONTEXT *tdb;
- BOOL ret = False;
+ bool ret = False;
int retry = 0;
if (argc != 1) {
return ret;
}
-static BOOL do_winbind_onlinestatus(struct messaging_context *msg_ctx,
+static bool do_winbind_onlinestatus(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
return num_replies;
}
-static BOOL do_dump_event_list(struct messaging_context *msg_ctx,
+static bool do_dump_event_list(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
return send_message(msg_ctx, pid, MSG_DUMP_EVENT_LIST, NULL, 0);
}
+static void winbind_validate_cache_cb(struct messaging_context *msg,
+ void *private_data,
+ uint32_t msg_type,
+ struct server_id pid,
+ DATA_BLOB *data)
+{
+ char *src_string = procid_str(NULL, &pid);
+ printf("Winbindd cache is %svalid. (answer from pid %s)\n",
+ (*(data->data) == 0 ? "" : "NOT "), src_string);
+ TALLOC_FREE(src_string);
+ num_replies++;
+}
+
+static bool do_winbind_validate_cache(struct messaging_context *msg_ctx,
+ const struct server_id pid,
+ const int argc, const char **argv)
+{
+ struct server_id myid = pid_to_procid(sys_getpid());
+
+ if (argc != 1) {
+ fprintf(stderr, "Usage: smbcontrol winbindd validate-cache\n");
+ return False;
+ }
+
+ messaging_register(msg_ctx, NULL, MSG_WINBIND_VALIDATE_CACHE,
+ winbind_validate_cache_cb);
+
+ if (!send_message(msg_ctx, pid, MSG_WINBIND_VALIDATE_CACHE, &myid,
+ sizeof(myid))) {
+ return False;
+ }
+
+ wait_replies(msg_ctx, procid_to_pid(&pid) == 0);
+
+ if (num_replies == 0) {
+ printf("No replies received\n");
+ }
+
+ messaging_deregister(msg_ctx, MSG_WINBIND_VALIDATE_CACHE, NULL);
+
+ return num_replies;
+}
-static BOOL do_reload_config(struct messaging_context *msg_ctx,
+static bool do_reload_config(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
push_ascii(n->scope, global_scope(), 64, STR_TERMINATE);
}
-static BOOL do_nodestatus(struct messaging_context *msg_ctx,
+static bool do_nodestatus(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv)
{
static const struct {
const char *name; /* Option name */
- BOOL (*fn)(struct messaging_context *msg_ctx,
+ bool (*fn)(struct messaging_context *msg_ctx,
const struct server_id pid,
const int argc, const char **argv);
const char *help; /* Short help text */
{ "offline", do_winbind_offline, "Ask winbind to go into offline state"},
{ "onlinestatus", do_winbind_onlinestatus, "Request winbind online status"},
{ "dump-event-list", do_dump_event_list, "Dump event list"},
+ { "validate-cache" , do_winbind_validate_cache,
+ "Validate winbind's credential cache" },
{ "noop", do_noop, "Do nothing" },
{ NULL }
};
/* Zero is a special return value for broadcast smbd */
if (strequal(dest, "smbd")) {
- return interpret_pid("0");
+ return interpret_pid(MSG_BROADCAST_PID_STR);
}
/* Try self - useful for testing */
/* Execute smbcontrol command */
-static BOOL do_command(struct messaging_context *msg_ctx,
+static bool do_command(struct messaging_context *msg_ctx,
int argc, const char **argv)
{
const char *dest = argv[0], *command = argv[1];
POPT_COMMON_SAMBA
POPT_TABLEEND
};
+ TALLOC_CTX *frame = talloc_stackframe();
+ int ret = 0;
load_case_tables();
argv = (const char **)poptGetArgs(pc);
argc = 0;
- while (argv[argc] != NULL) {
- argc++;
+ if (argv != NULL) {
+ while (argv[argc] != NULL) {
+ argc++;
+ }
}
- if (argc == 1)
+ if (argc <= 1)
usage(pc);
lp_load(dyn_CONFIGFILE,False,False,False,True);
if (!(evt_ctx = event_context_init(NULL)) ||
!(msg_ctx = messaging_init(NULL, server_id_self(), evt_ctx))) {
fprintf(stderr, "could not init messaging context\n");
+ TALLOC_FREE(frame);
exit(1);
}
- return !do_command(msg_ctx, argc, argv);
+ ret = !do_command(msg_ctx, argc, argv);
+ TALLOC_FREE(frame);
+ return ret;
}