along with this program. If not, see <http://www.gnu.org/licenses/>. */
#include "includes.h"
+#include "lib/util/server_id.h"
#include "utils/net.h"
+#include "session.h"
+#include "messages.h"
+#include "lib/conn_tdb.h"
int net_status_usage(struct net_context *c, int argc, const char **argv)
{
- d_printf(" net status sessions [parseable] "
- "Show list of open sessions\n");
- d_printf(" net status shares [parseable] "
- "Show list of open shares\n");
+ d_printf(_(" net status sessions [parseable] "
+ "Show list of open sessions\n"));
+ d_printf(_(" net status shares [parseable] "
+ "Show list of open shares\n"));
return -1;
}
-static int show_session(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf,
- void *state)
+static int show_session(const char *key, struct sessionid *session,
+ void *private_data)
{
- bool *parseable = (bool *)state;
- struct sessionid sessionid;
+ struct server_id_buf tmp;
+ bool *parseable = (bool *)private_data;
- if (dbuf.dsize != sizeof(sessionid))
- return 0;
-
- memcpy(&sessionid, dbuf.dptr, sizeof(sessionid));
-
- if (!process_exists(sessionid.pid)) {
+ if (!process_exists(session->pid)) {
return 0;
}
if (*parseable) {
d_printf("%s\\%s\\%s\\%s\\%s\n",
- procid_str_static(&sessionid.pid), uidtoname(sessionid.uid),
- gidtoname(sessionid.gid),
- sessionid.remote_machine, sessionid.hostname);
+ server_id_str_buf(session->pid, &tmp),
+ uidtoname(session->uid),
+ gidtoname(session->gid),
+ session->remote_machine, session->hostname);
} else {
d_printf("%7s %-12s %-12s %-12s (%s)\n",
- procid_str_static(&sessionid.pid), uidtoname(sessionid.uid),
- gidtoname(sessionid.gid),
- sessionid.remote_machine, sessionid.hostname);
+ server_id_str_buf(session->pid, &tmp),
+ uidtoname(session->uid),
+ gidtoname(session->gid),
+ session->remote_machine, session->hostname);
}
return 0;
static int net_status_sessions(struct net_context *c, int argc, const char **argv)
{
- TDB_CONTEXT *tdb;
bool parseable;
if (c->display_usage) {
- d_printf("Usage:\n"
- "net status sessions [parseable]\n"
- " Display open user sessions.\n"
- " If parseable is specified, output is machine-"
- "readable.\n");
+ d_printf( "%s\n"
+ "net status sessions [parseable]\n"
+ " %s\n",
+ _("Usage:"),
+ _("Display open user sessions.\n"
+ " If parseable is specified, output is machine-"
+ "readable."));
return 0;
}
}
if (!parseable) {
- d_printf("PID Username Group Machine"
- " \n");
- d_printf("-------------------------------------------"
- "------------------------\n");
- }
-
- tdb = tdb_open_log(lock_path("sessionid.tdb"), 0,
- TDB_DEFAULT, O_RDONLY, 0);
-
- if (tdb == NULL) {
- d_fprintf(stderr, "%s not initialised\n", lock_path("sessionid.tdb"));
- return -1;
+ d_printf(_("PID Username Group Machine"
+ " \n"
+ "-------------------------------------------"
+ "------------------------\n"));
}
- tdb_traverse(tdb, show_session, &parseable);
- tdb_close(tdb);
-
+ sessionid_traverse_read(show_session, &parseable);
return 0;
}
-static int show_share(struct db_record *rec,
- const struct connections_key *key,
+static int show_share(const struct connections_key *key,
const struct connections_data *crec,
void *state)
{
- if (crec->cnum == -1)
+ struct server_id_buf tmp;
+
+ if (crec->cnum == TID_FIELD_INVALID)
return 0;
if (!process_exists(crec->pid)) {
}
d_printf("%-10.10s %s %-12s %s",
- crec->servicename, procid_str_static(&crec->pid),
+ crec->servicename, server_id_str_buf(crec->pid, &tmp),
crec->machine,
time_to_asc(crec->start));
struct sessionid *entries;
};
-static int collect_pid(TDB_CONTEXT *tdb, TDB_DATA kbuf, TDB_DATA dbuf,
- void *state)
+static int collect_pids(const char *key, struct sessionid *session,
+ void *private_data)
{
- struct sessionids *ids = (struct sessionids *)state;
- struct sessionid sessionid;
-
- if (dbuf.dsize != sizeof(sessionid))
- return 0;
-
- memcpy(&sessionid, dbuf.dptr, sizeof(sessionid));
+ struct sessionids *ids = (struct sessionids *)private_data;
- if (!process_exists(sessionid.pid))
+ if (!process_exists(session->pid))
return 0;
ids->num_entries += 1;
ids->num_entries = 0;
return 0;
}
- ids->entries[ids->num_entries-1] = sessionid;
+ ids->entries[ids->num_entries-1] = *session;
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)
{
struct sessionids *ids = (struct sessionids *)state;
+ struct server_id_buf tmp;
int i;
bool guest = true;
- if (crec->cnum == -1)
+ if (crec->cnum == TID_FIELD_INVALID)
return 0;
if (!process_exists(crec->pid)) {
for (i=0; i<ids->num_entries; i++) {
struct server_id id = ids->entries[i].pid;
- if (procid_equal(&id, &crec->pid)) {
+ if (serverid_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, server_id_str_buf(crec->pid, &tmp),
guest ? "" : uidtoname(ids->entries[i].uid),
guest ? "" : gidtoname(ids->entries[i].gid),
crec->machine,
static int net_status_shares_parseable(struct net_context *c, int argc, const char **argv)
{
struct sessionids ids;
- TDB_CONTEXT *tdb;
ids.num_entries = 0;
ids.entries = NULL;
- tdb = tdb_open_log(lock_path("sessionid.tdb"), 0,
- TDB_DEFAULT, O_RDONLY, 0);
-
- if (tdb == NULL) {
- d_fprintf(stderr, "%s not initialised\n", lock_path("sessionid.tdb"));
- return -1;
- }
-
- tdb_traverse(tdb, collect_pid, &ids);
- tdb_close(tdb);
+ sessionid_traverse_read(collect_pids, &ids);
- connections_forall(show_share_parseable, &ids);
+ connections_forall_read(show_share_parseable, &ids);
SAFE_FREE(ids.entries);
static int net_status_shares(struct net_context *c, int argc, const char **argv)
{
if (c->display_usage) {
- d_printf("Usage:\n"
- "net status shares [parseable]\n"
- " Display open user shares.\n"
- " If parseable is specified, output is machine-"
- "readable.\n");
+ d_printf( "%s\n"
+ "net status shares [parseable]\n"
+ " %s\n",
+ _("Usage:"),
+ _("Display open user shares.\n"
+ " If parseable is specified, output is machine-"
+ "readable."));
return 0;
}
if (argc == 0) {
- d_printf("\nService pid machine "
- "Connected at\n");
- d_printf("-------------------------------------"
- "------------------\n");
+ d_printf(_("\nService pid machine "
+ "Connected at\n"
+ "-------------------------------------"
+ "------------------\n"));
- connections_forall(show_share, NULL);
+ connections_forall_read(show_share, NULL);
return 0;
}
"sessions",
net_status_sessions,
NET_TRANSPORT_LOCAL,
- "Show list of open sessions",
- "net status sessions [parseable]\n"
- " If parseable is specified, output is presented "
- "in a machine-parseable fashion."
+ N_("Show list of open sessions"),
+ N_("net status sessions [parseable]\n"
+ " If parseable is specified, output is presented "
+ "in a machine-parseable fashion.")
},
{
"shares",
net_status_shares,
NET_TRANSPORT_LOCAL,
- "Show list of open shares",
- "net status shares [parseable]\n"
- " If parseable is specified, output is presented "
- "in a machine-parseable fashion."
+ N_("Show list of open shares"),
+ N_("net status shares [parseable]\n"
+ " If parseable is specified, output is presented "
+ "in a machine-parseable fashion.")
},
{NULL, NULL, 0, NULL, NULL}
};