summaryrefslogtreecommitdiff
path: root/source3/utils
diff options
context:
space:
mode:
Diffstat (limited to 'source3/utils')
-rw-r--r--source3/utils/net_status.c72
-rw-r--r--source3/utils/smbcontrol.c40
-rw-r--r--source3/utils/status.c47
3 files changed, 43 insertions, 116 deletions
diff --git a/source3/utils/net_status.c b/source3/utils/net_status.c
index af6952389c..88c1789f71 100644
--- a/source3/utils/net_status.c
+++ b/source3/utils/net_status.c
@@ -84,27 +84,22 @@ static int net_status_sessions(int argc, const char **argv)
return 0;
}
-static int show_share(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf,
+static int show_share(TDB_CONTEXT *tdb,
+ const struct connections_key *key,
+ const struct connections_data *crec,
void *state)
{
- struct connections_data crec;
-
- if (dbuf.dsize != sizeof(crec))
+ if (crec->cnum == -1)
return 0;
- memcpy(&crec, dbuf.dptr, sizeof(crec));
-
- if (crec.cnum == -1)
- return 0;
-
- if (!process_exists(crec.pid)) {
+ if (!process_exists(crec->pid)) {
return 0;
}
d_printf("%-10.10s %s %-12s %s",
- crec.servicename, procid_str_static(&crec.pid),
- crec.machine,
- time_to_asc(crec.start));
+ crec->servicename, procid_str_static(&crec->pid),
+ crec->machine,
+ time_to_asc(crec->start));
return 0;
}
@@ -139,41 +134,37 @@ static int collect_pid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf,
return 0;
}
-static int show_share_parseable(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf,
+static int show_share_parseable(TDB_CONTEXT *tdb,
+ const struct connections_key *key,
+ const struct connections_data *crec,
void *state)
{
struct sessionids *ids = (struct sessionids *)state;
- struct connections_data crec;
int i;
BOOL guest = True;
- if (dbuf.dsize != sizeof(crec))
- return 0;
-
- memcpy(&crec, dbuf.dptr, sizeof(crec));
-
- if (crec.cnum == -1)
+ if (crec->cnum == -1)
return 0;
- if (!process_exists(crec.pid)) {
+ if (!process_exists(crec->pid)) {
return 0;
}
for (i=0; i<ids->num_entries; i++) {
struct server_id id = ids->entries[i].pid;
- if (procid_equal(&id, &crec.pid)) {
+ if (procid_equal(&id, &crec->pid)) {
guest = False;
break;
}
}
d_printf("%s\\%s\\%s\\%s\\%s\\%s\\%s",
- crec.servicename,procid_str_static(&crec.pid),
+ crec->servicename,procid_str_static(&crec->pid),
guest ? "" : uidtoname(ids->entries[i].uid),
guest ? "" : gidtoname(ids->entries[i].gid),
- crec.machine,
+ crec->machine,
guest ? "" : ids->entries[i].hostname,
- time_to_asc(crec.start));
+ time_to_asc(crec->start));
return 0;
}
@@ -197,18 +188,7 @@ static int net_status_shares_parseable(int argc, const char **argv)
tdb_traverse(tdb, collect_pid, &ids);
tdb_close(tdb);
- tdb = tdb_open_log(lock_path("connections.tdb"), 0,
- TDB_DEFAULT, O_RDONLY, 0);
-
- if (tdb == NULL) {
- d_fprintf(stderr, "%s not initialised\n", lock_path("connections.tdb"));
- d_fprintf(stderr, "This is normal if no SMB client has ever "
- "connected to your server.\n");
- return -1;
- }
-
- tdb_traverse(tdb, show_share_parseable, &ids);
- tdb_close(tdb);
+ connections_forall(show_share_parseable, &ids);
SAFE_FREE(ids.entries);
@@ -217,8 +197,6 @@ static int net_status_shares_parseable(int argc, const char **argv)
static int net_status_shares(int argc, const char **argv)
{
- TDB_CONTEXT *tdb;
-
if (argc == 0) {
d_printf("\nService pid machine "
@@ -226,19 +204,7 @@ static int net_status_shares(int argc, const char **argv)
d_printf("-------------------------------------"
"------------------\n");
- tdb = tdb_open_log(lock_path("connections.tdb"), 0,
- TDB_DEFAULT, O_RDONLY, 0);
-
- if (tdb == NULL) {
- d_fprintf(stderr, "%s not initialised\n",
- lock_path("connections.tdb"));
- d_fprintf(stderr, "This is normal if no SMB client has "
- "ever connected to your server.\n");
- return -1;
- }
-
- tdb_traverse(tdb, show_share, NULL);
- tdb_close(tdb);
+ connections_forall(show_share, NULL);
return 0;
}
diff --git a/source3/utils/smbcontrol.c b/source3/utils/smbcontrol.c
index d9eb5b78ea..ab46cbce65 100644
--- a/source3/utils/smbcontrol.c
+++ b/source3/utils/smbcontrol.c
@@ -51,7 +51,6 @@ static BOOL send_message(struct server_id pid, int msg_type,
const void *buf, int len,
BOOL duplicates)
{
- TDB_CONTEXT *tdb;
BOOL ret;
int n_sent = 0;
@@ -62,21 +61,11 @@ static BOOL send_message(struct server_id pid, int msg_type,
return NT_STATUS_IS_OK(message_send_pid(pid, msg_type, buf, len,
duplicates));
- tdb = tdb_open_log(lock_path("connections.tdb"), 0,
- TDB_DEFAULT, O_RDWR, 0);
- if (!tdb) {
- fprintf(stderr,"Failed to open connections database"
- ": %s\n", strerror(errno));
- return False;
- }
-
- ret = message_send_all(tdb,msg_type, buf, len, duplicates,
+ ret = message_send_all(msg_type, buf, len, duplicates,
&n_sent);
DEBUG(10,("smbcontrol/send_message: broadcast message to "
"%d processes\n", n_sent));
- tdb_close(tdb);
-
return ret;
}
@@ -247,16 +236,11 @@ cleanup:
ptrace(PTRACE_DETACH, pid, NULL, NULL);
}
-static int stack_trace_connection(TDB_CONTEXT * tdb, TDB_DATA key,
- TDB_DATA data, void * priv)
+static int stack_trace_connection(TDB_CONTEXT * tdb,
+ const struct connections_key *key,
+ const struct connections_data *conn,
{
- struct connections_data conn;
-
- if (data.dsize != sizeof(conn))
- return 0;
-
- memcpy(&conn, data.dptr, sizeof(conn));
- print_stack_trace(procid_to_pid(&conn.pid), (int *)priv);
+ print_stack_trace(procid_to_pid(&conn->pid), (int *)priv);
return 0;
}
@@ -286,19 +270,7 @@ static BOOL do_daemon_stack_trace(const struct server_id pid,
*/
print_stack_trace(dest, &count);
} else {
- TDB_CONTEXT * tdb;
-
- tdb = tdb_open_log(lock_path("connections.tdb"), 0,
- TDB_DEFAULT, O_RDONLY, 0);
- if (!tdb) {
- fprintf(stderr,
- "Failed to open connections database: %s\n",
- strerror(errno));
- return False;
- }
-
- tdb_traverse(tdb, stack_trace_connection, &count);
- tdb_close(tdb);
+ connections_traverse(stack_trace_connection, &count);
}
return True;
diff --git a/source3/utils/status.c b/source3/utils/status.c
index d3bb79dd01..aa014c8410 100644
--- a/source3/utils/status.c
+++ b/source3/utils/status.c
@@ -188,26 +188,22 @@ static void print_brl(SMB_DEV_T dev,
(double)start, (double)size);
}
-static int traverse_fn1(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
+static int traverse_fn1(TDB_CONTEXT *tdb,
+ const struct connections_key *key,
+ const struct connections_data *crec,
+ void *state)
{
- struct connections_data crec;
-
- if (dbuf.dsize != sizeof(crec))
- return 0;
-
- memcpy(&crec, dbuf.dptr, sizeof(crec));
-
- if (crec.cnum == -1)
+ if (crec->cnum == -1)
return 0;
- if (!process_exists(crec.pid) || !Ucrit_checkUid(crec.uid)) {
+ if (!process_exists(crec->pid) || !Ucrit_checkUid(crec->uid)) {
return 0;
}
d_printf("%-10s %s %-12s %s",
- crec.servicename,procid_str_static(&crec.pid),
- crec.machine,
- time_to_asc(crec.start));
+ crec->servicename,procid_str_static(&crec->pid),
+ crec->machine,
+ time_to_asc(crec->start));
return 0;
}
@@ -339,26 +335,19 @@ static int traverse_sessionid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf, vo
}
if ( show_shares ) {
- tdb = tdb_open_log(lock_path("connections.tdb"), 0, TDB_DEFAULT, O_RDONLY, 0);
- if (!tdb) {
- d_printf("%s not initialised\n", lock_path("connections.tdb"));
- d_printf("This is normal if an SMB client has never connected to your server.\n");
- } else {
- if (verbose) {
- d_printf("Opened %s\n", lock_path("connections.tdb"));
- }
+ if (verbose) {
+ d_printf("Opened %s\n", lock_path("connections.tdb"));
+ }
- if (brief)
- exit(0);
+ if (brief)
+ exit(0);
- d_printf("\nService pid machine Connected at\n");
- d_printf("-------------------------------------------------------\n");
+ d_printf("\nService pid machine Connected at\n");
+ d_printf("-------------------------------------------------------\n");
- tdb_traverse(tdb, traverse_fn1, NULL);
- tdb_close(tdb);
+ connections_forall(traverse_fn1, NULL);
- d_printf("\n");
- }
+ d_printf("\n");
if ( shares_only )
exit(0);