mirror of
https://github.com/samba-team/samba.git
synced 2025-01-22 22:04:08 +03:00
messaging4: Change irpc_servers_by_name to NTSTATUS
For me, counted arrays are easier to deal with than NULL-terminated ones. Here we also had a "server_id_is_disconnection" convention, which was not really obvious. Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Mon Jul 21 20:28:53 CEST 2014 on sn-devel-104
This commit is contained in:
parent
53d1bbd20d
commit
1dd64341d8
@ -67,7 +67,8 @@
|
||||
static int ridalloc_poke_rid_manager(struct ldb_module *module)
|
||||
{
|
||||
struct imessaging_context *msg;
|
||||
struct server_id *server;
|
||||
unsigned num_servers;
|
||||
struct server_id *servers;
|
||||
struct ldb_context *ldb = ldb_module_get_ctx(module);
|
||||
struct loadparm_context *lp_ctx =
|
||||
(struct loadparm_context *)ldb_get_opaque(ldb, "loadparm");
|
||||
@ -85,8 +86,9 @@ static int ridalloc_poke_rid_manager(struct ldb_module *module)
|
||||
return LDB_ERR_UNWILLING_TO_PERFORM;
|
||||
}
|
||||
|
||||
server = irpc_servers_byname(msg, msg, "dreplsrv");
|
||||
if (!server) {
|
||||
status = irpc_servers_byname(msg, msg, "dreplsrv",
|
||||
&num_servers, &servers);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
ldb_asprintf_errstring(ldb_module_get_ctx(module),
|
||||
"Failed to send MSG_DREPL_ALLOCATE_RID, "
|
||||
"unable to locate dreplsrv");
|
||||
@ -95,13 +97,13 @@ static int ridalloc_poke_rid_manager(struct ldb_module *module)
|
||||
return LDB_ERR_UNWILLING_TO_PERFORM;
|
||||
}
|
||||
|
||||
status = imessaging_send(msg, server[0], MSG_DREPL_ALLOCATE_RID, NULL);
|
||||
status = imessaging_send(msg, servers[0], MSG_DREPL_ALLOCATE_RID, NULL);
|
||||
|
||||
/* Only error out if an error happened, not on STATUS_MORE_ENTRIES, ie a delayed message */
|
||||
if (NT_STATUS_IS_ERR(status)) {
|
||||
ldb_asprintf_errstring(ldb_module_get_ctx(module),
|
||||
"Failed to send MSG_DREPL_ALLOCATE_RID to dreplsrv at %s: %s",
|
||||
server_id_str(tmp_ctx, server), nt_errstr(status));
|
||||
server_id_str(tmp_ctx, servers), nt_errstr(status));
|
||||
talloc_free(tmp_ctx);
|
||||
return LDB_ERR_UNWILLING_TO_PERFORM;
|
||||
}
|
||||
|
@ -73,7 +73,10 @@ void irpc_binding_handle_add_security_token(struct dcerpc_binding_handle *h,
|
||||
struct security_token *token);
|
||||
|
||||
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);
|
||||
NTSTATUS irpc_servers_byname(struct imessaging_context *msg_ctx,
|
||||
TALLOC_CTX *mem_ctx, const char *name,
|
||||
unsigned *num_servers,
|
||||
struct server_id **servers);
|
||||
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);
|
||||
|
@ -951,32 +951,38 @@ NTSTATUS irpc_add_name(struct imessaging_context *msg_ctx, const char *name)
|
||||
/*
|
||||
return a list of server ids for a server name
|
||||
*/
|
||||
struct server_id *irpc_servers_byname(struct imessaging_context *msg_ctx,
|
||||
TALLOC_CTX *mem_ctx,
|
||||
const char *name)
|
||||
NTSTATUS irpc_servers_byname(struct imessaging_context *msg_ctx,
|
||||
TALLOC_CTX *mem_ctx, const char *name,
|
||||
unsigned *num_servers,
|
||||
struct server_id **servers)
|
||||
{
|
||||
struct tdb_wrap *t = msg_ctx->names_db;
|
||||
TDB_DATA rec;
|
||||
int count, i;
|
||||
unsigned count;
|
||||
struct server_id *ret;
|
||||
|
||||
rec = tdb_fetch_bystring(t->tdb, name);
|
||||
if (rec.dptr == NULL) {
|
||||
return NULL;
|
||||
enum TDB_ERROR err = tdb_error(t->tdb);
|
||||
return map_nt_error_from_tdb(err);
|
||||
}
|
||||
|
||||
count = rec.dsize / sizeof(struct server_id);
|
||||
ret = talloc_array(mem_ctx, struct server_id, count+1);
|
||||
if (count == 0) {
|
||||
return NT_STATUS_NOT_FOUND;
|
||||
}
|
||||
|
||||
ret = talloc_array(mem_ctx, struct server_id, count);
|
||||
if (ret == NULL) {
|
||||
free(rec.dptr);
|
||||
return NULL;
|
||||
return NT_STATUS_NO_MEMORY;
|
||||
}
|
||||
for (i=0;i<count;i++) {
|
||||
ret[i] = ((struct server_id *)rec.dptr)[i];
|
||||
}
|
||||
server_id_set_disconnected(&ret[i]);
|
||||
memcpy(ret, rec.dptr, count * sizeof(struct server_id));
|
||||
free(rec.dptr);
|
||||
|
||||
return ret;
|
||||
*num_servers = count;
|
||||
*servers = ret;
|
||||
return NT_STATUS_OK;
|
||||
}
|
||||
|
||||
static int all_servers_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state)
|
||||
@ -1380,17 +1386,16 @@ struct dcerpc_binding_handle *irpc_binding_handle_by_name(TALLOC_CTX *mem_ctx,
|
||||
const struct ndr_interface_table *table)
|
||||
{
|
||||
struct dcerpc_binding_handle *h;
|
||||
unsigned num_sids;
|
||||
struct server_id *sids;
|
||||
struct server_id sid;
|
||||
NTSTATUS status;
|
||||
|
||||
/* find the server task */
|
||||
sids = irpc_servers_byname(msg_ctx, mem_ctx, dest_task);
|
||||
if (sids == NULL) {
|
||||
errno = EADDRNOTAVAIL;
|
||||
return NULL;
|
||||
}
|
||||
if (server_id_is_disconnected(&sids[0])) {
|
||||
talloc_free(sids);
|
||||
|
||||
status = irpc_servers_byname(msg_ctx, mem_ctx, dest_task,
|
||||
&num_sids, &sids);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
errno = EADDRNOTAVAIL;
|
||||
return NULL;
|
||||
}
|
||||
|
@ -235,10 +235,12 @@ static PyObject *py_irpc_servers_byname(PyObject *self, PyObject *args, PyObject
|
||||
{
|
||||
imessaging_Object *iface = (imessaging_Object *)self;
|
||||
char *server_name;
|
||||
unsigned i, num_ids;
|
||||
struct server_id *ids;
|
||||
PyObject *pylist;
|
||||
int i;
|
||||
TALLOC_CTX *mem_ctx = talloc_new(NULL);
|
||||
NTSTATUS status;
|
||||
|
||||
if (!mem_ctx) {
|
||||
PyErr_NoMemory();
|
||||
return NULL;
|
||||
@ -249,25 +251,21 @@ static PyObject *py_irpc_servers_byname(PyObject *self, PyObject *args, PyObject
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ids = irpc_servers_byname(iface->msg_ctx, mem_ctx, server_name);
|
||||
|
||||
if (ids == NULL) {
|
||||
status = irpc_servers_byname(iface->msg_ctx, mem_ctx, server_name,
|
||||
&num_ids, &ids);
|
||||
if (!NT_STATUS_IS_OK(status)) {
|
||||
TALLOC_FREE(mem_ctx);
|
||||
PyErr_SetString(PyExc_KeyError, "No such name");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
for (i = 0; !server_id_is_disconnected(&ids[i]); i++) {
|
||||
/* Do nothing */
|
||||
}
|
||||
|
||||
pylist = PyList_New(i);
|
||||
pylist = PyList_New(num_ids);
|
||||
if (pylist == NULL) {
|
||||
TALLOC_FREE(mem_ctx);
|
||||
PyErr_NoMemory();
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; !server_id_is_disconnected(&ids[i]); i++) {
|
||||
for (i = 0; i < num_ids; i++) {
|
||||
PyObject *py_server_id;
|
||||
struct server_id *p_server_id = talloc(NULL, struct server_id);
|
||||
if (!p_server_id) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user