diff options
author | Andrew Bartlett <abartlet@samba.org> | 2012-10-29 15:32:21 +1100 |
---|---|---|
committer | Andrew Bartlett <abartlet@samba.org> | 2012-10-31 08:13:56 +1100 |
commit | 3b4ef03097293f758d8f11cbe434063ed1dc6b91 (patch) | |
tree | 3f4cff477eca62c6fe37dfc20488d5923d581edd | |
parent | 39e58d6845ee4dab0e9ae1537fccaed837ead728 (diff) | |
download | samba-3b4ef03097293f758d8f11cbe434063ed1dc6b91.tar.gz samba-3b4ef03097293f758d8f11cbe434063ed1dc6b91.tar.bz2 samba-3b4ef03097293f758d8f11cbe434063ed1dc6b91.zip |
imessaging: Add irpc_all_servers() to list all available servers
This is implemented with a tdb_traverse_read(), and will allow a tool
to disover the name and server_id of all Samba processes, as each
process registers itself to recieve messages.
Andrew Bartlett
-rw-r--r-- | source4/lib/messaging/irpc.h | 2 | ||||
-rw-r--r-- | source4/lib/messaging/messaging.c | 71 | ||||
-rw-r--r-- | source4/librpc/idl/irpc.idl | 13 |
3 files changed, 85 insertions, 1 deletions
diff --git a/source4/lib/messaging/irpc.h b/source4/lib/messaging/irpc.h index 15f8259e51..456d1906e0 100644 --- a/source4/lib/messaging/irpc.h +++ b/source4/lib/messaging/irpc.h @@ -75,6 +75,8 @@ void irpc_binding_handle_add_security_token(struct dcerpc_binding_handle *h, NTSTATUS irpc_add_name(struct imessaging_context *msg_ctx, const char *name); struct server_id *irpc_servers_byname(struct imessaging_context *msg_ctx, TALLOC_CTX *mem_ctx, const char *name); +struct irpc_name_records *irpc_all_servers(struct imessaging_context *msg_ctx, + TALLOC_CTX *mem_ctx); void irpc_remove_name(struct imessaging_context *msg_ctx, const char *name); NTSTATUS irpc_send_reply(struct irpc_message *m, NTSTATUS status); diff --git a/source4/lib/messaging/messaging.c b/source4/lib/messaging/messaging.c index 4d69b9424b..66188971f3 100644 --- a/source4/lib/messaging/messaging.c +++ b/source4/lib/messaging/messaging.c @@ -985,6 +985,77 @@ struct server_id *irpc_servers_byname(struct imessaging_context *msg_ctx, return ret; } +static int all_servers_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state) +{ + struct irpc_name_records *name_records = talloc_get_type(state, struct irpc_name_records); + struct irpc_name_record *name_record; + int i; + + name_records->names + = talloc_realloc(name_records, name_records->names, + struct irpc_name_record *, name_records->num_records+1); + if (!name_records->names) { + return -1; + } + + name_records->names[name_records->num_records] = name_record + = talloc(name_records->names, + struct irpc_name_record); + if (!name_record) { + return -1; + } + + name_records->num_records++; + + name_record->name + = talloc_strndup(name_record, + (const char *)key.dptr, key.dsize); + if (!name_record->name) { + return -1; + } + + name_record->count = data.dsize / sizeof(struct server_id); + name_record->ids = talloc_array(name_record, + struct server_id, + name_record->count); + if (name_record->ids == NULL) { + return -1; + } + for (i=0;i<name_record->count;i++) { + name_record->ids[i] = ((struct server_id *)data.dptr)[i]; + } + return 0; +} + +/* + return a list of server ids for a server name +*/ +struct irpc_name_records *irpc_all_servers(struct imessaging_context *msg_ctx, + TALLOC_CTX *mem_ctx) +{ + struct tdb_wrap *t; + int ret; + struct irpc_name_records *name_records = talloc_zero(mem_ctx, struct irpc_name_records); + if (name_records == NULL) { + return NULL; + } + + t = irpc_namedb_open(msg_ctx); + if (t == NULL) { + return NULL; + } + + ret = tdb_traverse_read(t->tdb, all_servers_func, name_records); + if (ret == -1) { + talloc_free(t); + return NULL; + } + + talloc_free(t); + + return name_records; +} + /* remove a name from a messaging context */ diff --git a/source4/librpc/idl/irpc.idl b/source4/librpc/idl/irpc.idl index ed331c7fdb..6a55eef953 100644 --- a/source4/librpc/idl/irpc.idl +++ b/source4/librpc/idl/irpc.idl @@ -1,6 +1,6 @@ #include "idl_types.h" -import "misc.idl", "security.idl", "nbt.idl", "netlogon.idl"; +import "misc.idl", "security.idl", "nbt.idl", "netlogon.idl", "server_id.idl"; /* definitions for irpc primitives @@ -29,6 +29,17 @@ import "misc.idl", "security.idl", "nbt.idl", "netlogon.idl"; [flag(NDR_ALIGN8)] DATA_BLOB _pad; } irpc_header; + typedef [public] struct { + utf8string name; + uint32 count; + [size_is(count)] server_id ids[*]; + } irpc_name_record; + + typedef [public] struct { + [size_is(num_records)] irpc_name_record *names[*]; + uint32 num_records; + } irpc_name_records; + /****************************************************** uptime call - supported by all messaging servers *******************************************************/ |