const struct connections_data *data,
void *private_data),
void *private_data);
+int connections_forall_read(int (*fn)(const struct connections_key *key,
+ const struct connections_data *data,
+ void *private_data),
+ void *private_data);
bool connections_init(bool rw);
/* The following definitions come from lib/dbwrap_util.c */
return ctx->traverse(ctx, conn_traverse_fn, (void *)&state);
}
+struct conn_traverse_read_state {
+ int (*fn)(const struct connections_key *key,
+ const struct connections_data *data,
+ void *private_data);
+ void *private_data;
+};
+
+static int connections_forall_read_fn(struct db_record *rec,
+ void *private_data)
+{
+ struct conn_traverse_read_state *state =
+ (struct conn_traverse_read_state *)private_data;
+
+ if ((rec->key.dsize != sizeof(struct connections_key))
+ || (rec->value.dsize != sizeof(struct connections_data))) {
+ return 0;
+ }
+ return state->fn((const struct connections_key *)rec->key.dptr,
+ (const struct connections_data *)rec->value.dptr,
+ state->private_data);
+}
+
+int connections_forall_read(int (*fn)(const struct connections_key *key,
+ const struct connections_data *data,
+ void *private_data),
+ void *private_data)
+{
+ struct db_context *ctx;
+ struct conn_traverse_read_state state;
+
+ ctx = connections_db_ctx(false);
+ if (ctx == NULL) {
+ return -1;
+ }
+
+ state.fn = fn;
+ state.private_data = private_data;
+
+ return ctx->traverse_read(ctx, connections_forall_read_fn,
+ (void *)&state);
+}
+
bool connections_init(bool rw)
{
return (connections_db_ctx(rw) != NULL);
a new session setup with VC==0 is ignored.
****************************************************************************/
-static int shutdown_other_smbds(struct db_record *rec,
- const struct connections_key *key,
+static int shutdown_other_smbds(const struct connections_key *key,
const struct connections_data *crec,
void *private_data)
{
invalidate_all_vuids();
#endif
if (lp_reset_on_zero_vc()) {
- connections_forall(shutdown_other_smbds,
+ connections_forall_read(shutdown_other_smbds,
CONST_DISCARD(void *,
client_addr(get_client_fd(),addr,sizeof(addr))));
}
return 0;
}
-static int show_share_parseable(struct db_record *rec,
- const struct connections_key *key,
+static int show_share_parseable(const struct connections_key *key,
const struct connections_data *crec,
void *state)
{
db->traverse_read(db, collect_pid, &ids);
TALLOC_FREE(db);
- connections_forall(show_share_parseable, &ids);
+ connections_forall_read(show_share_parseable, &ids);
SAFE_FREE(ids.entries);
ptrace(PTRACE_DETACH, pid, NULL, NULL);
}
-static int stack_trace_connection(struct db_record *rec,
- const struct connections_key *key,
+static int stack_trace_connection(const struct connections_key *key,
const struct connections_data *crec,
void *priv)
{
*/
print_stack_trace(dest, &count);
} else {
- connections_forall(stack_trace_connection, &count);
+ connections_forall_read(stack_trace_connection, &count);
}
return True;
TALLOC_FREE(share_mode);
}
-static int traverse_fn1(struct db_record *rec,
- const struct connections_key *key,
+static int traverse_fn1(const struct connections_key *key,
const struct connections_data *crec,
void *state)
{
d_printf("\nService pid machine Connected at\n");
d_printf("-------------------------------------------------------\n");
- connections_forall(traverse_fn1, NULL);
+ connections_forall_read(traverse_fn1, NULL);
d_printf("\n");
/* kill off any connections chosen by the user */
-static int traverse_fn1(struct db_record *rec,
- const struct connections_key *key,
+static int traverse_fn1(const struct connections_key *key,
const struct connections_data *crec,
void *private_data)
{
}
/* traversal fn for showing machine connections */
-static int traverse_fn2(struct db_record *rec,
- const struct connections_key *key,
+static int traverse_fn2(const struct connections_key *key,
const struct connections_data *crec,
void *private_data)
{
}
/* traversal fn for showing share connections */
-static int traverse_fn3(struct db_record *rec,
- const struct connections_key *key,
+static int traverse_fn3(const struct connections_key *key,
const struct connections_data *crec,
void *private_data)
{
PID_or_Machine = 0;
}
- connections_forall(traverse_fn1, NULL);
+ connections_forall_read(traverse_fn1, NULL);
initPid2Machine ();
}
printf("</tr>\n");
- connections_forall(traverse_fn2, NULL);
+ connections_forall_read(traverse_fn2, NULL);
printf("</table><p>\n");
printf("<tr><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th><th>%s</th></tr>\n\n",
_("Share"), _("User"), _("Group"), _("PID"), _("Client"), _("Date"));
- connections_forall(traverse_fn3, NULL);
+ connections_forall_read(traverse_fn3, NULL);
printf("</table><p>\n");