summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorAndrew Bartlett <abartlet@samba.org>2012-10-29 15:32:21 +1100
committerAndrew Bartlett <abartlet@samba.org>2012-10-31 08:13:56 +1100
commit3b4ef03097293f758d8f11cbe434063ed1dc6b91 (patch)
tree3f4cff477eca62c6fe37dfc20488d5923d581edd /source4/lib
parent39e58d6845ee4dab0e9ae1537fccaed837ead728 (diff)
downloadsamba-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
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/messaging/irpc.h2
-rw-r--r--source4/lib/messaging/messaging.c71
2 files changed, 73 insertions, 0 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
*/