diff options
author | Volker Lendecke <vl@samba.org> | 2010-03-01 16:18:23 +0100 |
---|---|---|
committer | Volker Lendecke <vl@samba.org> | 2010-03-01 17:53:22 +0100 |
commit | d6a687250625b62242efc8be0aa50ffc448a503a (patch) | |
tree | 922043b9c9ac87064436d6bb0925e8f3696b4415 /source3/utils | |
parent | c103fbc919d0f5df24fbfefd5153683ab938b779 (diff) | |
download | samba-d6a687250625b62242efc8be0aa50ffc448a503a.tar.gz samba-d6a687250625b62242efc8be0aa50ffc448a503a.tar.bz2 samba-d6a687250625b62242efc8be0aa50ffc448a503a.zip |
s3: Abstract access to sessionid.tdb, similar to conn_tdb.c
Diffstat (limited to 'source3/utils')
-rw-r--r-- | source3/utils/net_status.c | 63 | ||||
-rw-r--r-- | source3/utils/status.c | 50 |
2 files changed, 36 insertions, 77 deletions
diff --git a/source3/utils/net_status.c b/source3/utils/net_status.c index 47860cb584..54ad786436 100644 --- a/source3/utils/net_status.c +++ b/source3/utils/net_status.c @@ -28,30 +28,27 @@ int net_status_usage(struct net_context *c, int argc, const char **argv) return -1; } -static int show_session(struct db_record *rec, void *private_data) +static int show_session(const char *key, struct sessionid *session, + void *private_data) { bool *parseable = (bool *)private_data; - struct sessionid sessionid; - if (rec->value.dsize != sizeof(sessionid)) - return 0; - - memcpy(&sessionid, rec->value.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); + procid_str_static(&session->pid), + 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); + procid_str_static(&session->pid), + uidtoname(session->uid), + gidtoname(session->gid), + session->remote_machine, session->hostname); } return 0; @@ -59,7 +56,6 @@ static int show_session(struct db_record *rec, void *private_data) static int net_status_sessions(struct net_context *c, int argc, const char **argv) { - struct db_context *db; bool parseable; if (c->display_usage) { @@ -88,17 +84,7 @@ static int net_status_sessions(struct net_context *c, int argc, const char **arg "------------------------\n")); } - db = db_open(NULL, lock_path("sessionid.tdb"), 0, - TDB_CLEAR_IF_FIRST, O_RDONLY, 0644); - if (db == NULL) { - d_fprintf(stderr, _("%s not initialised\n"), - lock_path("sessionid.tdb")); - return -1; - } - - db->traverse_read(db, show_session, &parseable); - TALLOC_FREE(db); - + sessionid_traverse_read(show_session, &parseable); return 0; } @@ -127,17 +113,12 @@ struct sessionids { struct sessionid *entries; }; -static int collect_pid(struct db_record *rec, void *private_data) +static int collect_pids(const char *key, struct sessionid *session, + void *private_data) { struct sessionids *ids = (struct sessionids *)private_data; - struct sessionid sessionid; - if (rec->value.dsize != sizeof(sessionid)) - return 0; - - memcpy(&sessionid, rec->value.dptr, sizeof(sessionid)); - - if (!process_exists(sessionid.pid)) + if (!process_exists(session->pid)) return 0; ids->num_entries += 1; @@ -146,7 +127,7 @@ static int collect_pid(struct db_record *rec, void *private_data) ids->num_entries = 0; return 0; } - ids->entries[ids->num_entries-1] = sessionid; + ids->entries[ids->num_entries-1] = *session; return 0; } @@ -188,21 +169,11 @@ static int show_share_parseable(const struct connections_key *key, static int net_status_shares_parseable(struct net_context *c, int argc, const char **argv) { struct sessionids ids; - struct db_context *db; ids.num_entries = 0; ids.entries = NULL; - db = db_open(NULL, lock_path("sessionid.tdb"), 0, - TDB_CLEAR_IF_FIRST, O_RDONLY, 0644); - if (db == NULL) { - d_fprintf(stderr, _("%s not initialised\n"), - lock_path("sessionid.tdb")); - return -1; - } - - db->traverse_read(db, collect_pid, &ids); - TALLOC_FREE(db); + sessionid_traverse_read(collect_pids, &ids); connections_forall_read(show_share_parseable, &ids); diff --git a/source3/utils/status.c b/source3/utils/status.c index 60cad2c28f..d2b10c1810 100644 --- a/source3/utils/status.c +++ b/source3/utils/status.c @@ -251,30 +251,26 @@ static int traverse_fn1(const struct connections_key *key, return 0; } -static int traverse_sessionid(struct db_record *db, void *state) +static int traverse_sessionid(const char *key, struct sessionid *session, + void *private_data) { - struct sessionid sessionid; fstring uid_str, gid_str; - if (db->value.dsize != sizeof(sessionid)) - return 0; - - memcpy(&sessionid, db->value.dptr, sizeof(sessionid)); - - if (!process_exists(sessionid.pid) || !Ucrit_checkUid(sessionid.uid)) { + if (!process_exists(session->pid) + || !Ucrit_checkUid(session->uid)) { return 0; } - Ucrit_addPid( sessionid.pid ); + Ucrit_addPid(session->pid); - fstr_sprintf(uid_str, "%u", (unsigned int)sessionid.uid); - fstr_sprintf(gid_str, "%u", (unsigned int)sessionid.gid); + fstr_sprintf(uid_str, "%u", (unsigned int)session->uid); + fstr_sprintf(gid_str, "%u", (unsigned int)session->gid); d_printf("%-7s %-12s %-12s %-12s (%s)\n", - procid_str_static(&sessionid.pid), - numeric_only ? uid_str : uidtoname(sessionid.uid), - numeric_only ? gid_str : gidtoname(sessionid.gid), - sessionid.remote_machine, sessionid.hostname); + procid_str_static(&session->pid), + numeric_only ? uid_str : uidtoname(session->uid), + numeric_only ? gid_str : gidtoname(session->gid), + session->remote_machine, session->hostname); return 0; } @@ -411,24 +407,16 @@ static int traverse_sessionid(struct db_record *db, void *state) } if ( show_processes ) { - struct db_context *db; - db = db_open(NULL, lock_path("sessionid.tdb"), 0, - TDB_CLEAR_IF_FIRST, O_RDONLY, 0644); - if (!db) { - d_printf("sessionid.tdb not initialised\n"); - } else { - d_printf("\nSamba version %s\n",samba_version_string()); - d_printf("PID Username Group Machine \n"); - d_printf("-------------------------------------------------------------------\n"); - if (lp_security() == SEC_SHARE) { - d_printf(" <processes do not show up in " - "anonymous mode>\n"); - } - - db->traverse_read(db, traverse_sessionid, NULL); - TALLOC_FREE(db); + d_printf("\nSamba version %s\n",samba_version_string()); + d_printf("PID Username Group Machine \n"); + d_printf("-------------------------------------------------------------------\n"); + if (lp_security() == SEC_SHARE) { + d_printf(" <processes do not show up in " + "anonymous mode>\n"); } + sessionid_traverse_read(traverse_sessionid, NULL); + if (processes_only) { goto done; } |