Changeset 740 for vendor/current/source4/lib/messaging
- Timestamp:
- Nov 14, 2012, 12:59:34 PM (13 years ago)
- Location:
- vendor/current/source4/lib/messaging
- Files:
-
- 1 added
- 2 deleted
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
vendor/current/source4/lib/messaging/irpc.h
r414 r740 25 25 #include "lib/messaging/messaging.h" 26 26 #include "librpc/gen_ndr/irpc.h" 27 #include "librpc/gen_ndr/server_id.h"28 27 29 28 /* … … 36 35 struct ndr_pull *ndr; 37 36 bool defer_reply; 37 bool no_reply; 38 38 struct messaging_context *msg_ctx; 39 39 struct irpc_list *irpc; … … 43 43 44 44 /* don't allow calls to take too long */ 45 #define IRPC_CALL_TIMEOUT 10 45 #define IRPC_CALL_TIMEOUT 10 46 /* wait for the calls as long as it takes */ 47 #define IRPC_CALL_TIMEOUT_INF 0 46 48 47 49 … … 55 57 (irpc_function_t)function, private_data) 56 58 57 /* make a irpc call */ 58 #define IRPC_CALL(msg_ctx, server_id, pipename, funcname, ptr, ctx) \ 59 irpc_call(msg_ctx, server_id, &ndr_table_ ## pipename, NDR_ ## funcname, ptr, ctx) 60 61 #define IRPC_CALL_SEND(msg_ctx, server_id, pipename, funcname, ptr, ctx) \ 62 irpc_call_send(msg_ctx, server_id, &ndr_table_ ## pipename, NDR_ ## funcname, ptr, ctx) 63 64 65 /* 66 a pending irpc call 67 */ 68 struct irpc_request { 69 struct messaging_context *msg_ctx; 70 const struct ndr_interface_table *table; 71 int callnum; 72 int callid; 73 void *r; 74 NTSTATUS status; 75 bool done; 76 bool reject_free; 77 TALLOC_CTX *mem_ctx; 78 struct { 79 void (*fn)(struct irpc_request *); 80 void *private_data; 81 } async; 82 }; 83 84 struct loadparm_context; 85 86 typedef void (*msg_callback_t)(struct messaging_context *msg, void *private_data, 87 uint32_t msg_type, 88 struct server_id server_id, DATA_BLOB *data); 89 90 NTSTATUS messaging_send(struct messaging_context *msg, struct server_id server, 91 uint32_t msg_type, DATA_BLOB *data); 92 NTSTATUS messaging_register(struct messaging_context *msg, void *private_data, 93 uint32_t msg_type, 94 msg_callback_t fn); 95 NTSTATUS messaging_register_tmp(struct messaging_context *msg, void *private_data, 96 msg_callback_t fn, uint32_t *msg_type); 97 struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, 98 const char *dir, 99 struct server_id server_id, 100 struct smb_iconv_convenience *iconv_convenience, 101 struct tevent_context *ev); 102 struct messaging_context *messaging_client_init(TALLOC_CTX *mem_ctx, 103 const char *dir, 104 struct smb_iconv_convenience *iconv_convenience, 105 struct tevent_context *ev); 106 NTSTATUS messaging_send_ptr(struct messaging_context *msg, struct server_id server, 107 uint32_t msg_type, void *ptr); 108 void messaging_deregister(struct messaging_context *msg, uint32_t msg_type, void *private_data); 109 110 111 59 struct ndr_interface_table; 112 60 113 61 NTSTATUS irpc_register(struct messaging_context *msg_ctx, 114 62 const struct ndr_interface_table *table, 115 63 int call, irpc_function_t fn, void *private_data); 116 struct irpc_request *irpc_call_send(struct messaging_context *msg_ctx, 117 struct server_id server_id, 118 const struct ndr_interface_table *table, 119 int callnum, void *r, TALLOC_CTX *ctx); 120 NTSTATUS irpc_call_recv(struct irpc_request *irpc); 121 NTSTATUS irpc_call(struct messaging_context *msg_ctx, 122 struct server_id server_id, 123 const struct ndr_interface_table *table, 124 int callnum, void *r, TALLOC_CTX *ctx); 64 65 struct dcerpc_binding_handle *irpc_binding_handle(TALLOC_CTX *mem_ctx, 66 struct messaging_context *msg_ctx, 67 struct server_id server_id, 68 const struct ndr_interface_table *table); 69 struct dcerpc_binding_handle *irpc_binding_handle_by_name(TALLOC_CTX *mem_ctx, 70 struct messaging_context *msg_ctx, 71 const char *dest_task, 72 const struct ndr_interface_table *table); 73 void irpc_binding_handle_add_security_token(struct dcerpc_binding_handle *h, 74 struct security_token *token); 125 75 126 76 NTSTATUS irpc_add_name(struct messaging_context *msg_ctx, const char *name); … … 128 78 void irpc_remove_name(struct messaging_context *msg_ctx, const char *name); 129 79 NTSTATUS irpc_send_reply(struct irpc_message *m, NTSTATUS status); 130 struct server_id messaging_get_server_id(struct messaging_context *msg_ctx);131 80 132 81 #endif -
vendor/current/source4/lib/messaging/messaging.c
r414 r740 28 28 #include "librpc/gen_ndr/ndr_irpc.h" 29 29 #include "lib/messaging/irpc.h" 30 #include " tdb_wrap.h"30 #include "lib/util/tdb_wrap.h" 31 31 #include "../lib/util/unix_privs.h" 32 32 #include "librpc/rpc/dcerpc.h" 33 #include "../tdb/include/tdb.h"33 #include <tdb.h> 34 34 #include "../lib/util/util_tdb.h" 35 35 #include "cluster/cluster.h" 36 #include "../lib/util/tevent_ntstatus.h" 36 37 37 38 /* change the message version with any incompatible changes in the protocol */ 38 39 #define MESSAGING_VERSION 1 40 41 /* 42 a pending irpc call 43 */ 44 struct irpc_request { 45 struct messaging_context *msg_ctx; 46 int callid; 47 struct { 48 void (*handler)(struct irpc_request *irpc, struct irpc_message *m); 49 void *private_data; 50 } incoming; 51 }; 39 52 40 53 struct messaging_context { … … 48 61 struct messaging_rec *pending; 49 62 struct messaging_rec *retry_queue; 50 struct smb_iconv_convenience *iconv_convenience;51 63 struct irpc_list *irpc; 52 64 struct idr_context *idr; … … 99 111 { 100 112 DEBUG(1,("INFO: Received PING message from server %u.%u [%.*s]\n", 101 (u int_t)src.node, (uint_t)src.id, (int)data->length,113 (unsigned int)src.node, (unsigned int)src.id, (int)data->length, 102 114 data->data?(const char *)data->data:"")); 103 115 messaging_send(msg, src, MSG_PONG, data); … … 120 132 static char *messaging_path(struct messaging_context *msg, struct server_id server_id) 121 133 { 122 return talloc_asprintf(msg, "%s/msg.%s", msg->base_path, 123 cluster_id_string(msg, server_id)); 134 TALLOC_CTX *tmp_ctx = talloc_new(msg); 135 const char *id = cluster_id_string(tmp_ctx, server_id); 136 char *s; 137 if (id == NULL) { 138 return NULL; 139 } 140 s = talloc_asprintf(msg, "%s/msg.%s", msg->base_path, id); 141 talloc_steal(s, tmp_ctx); 142 return s; 124 143 } 125 144 … … 262 281 rec->retries = 0; 263 282 if (!NT_STATUS_IS_OK(status)) { 283 TALLOC_CTX *tmp_ctx = talloc_new(msg); 264 284 DEBUG(1,("messaging: Lost message from %s to %s of type %u - %s\n", 265 cluster_id_string( debug_ctx(), rec->header->from),266 cluster_id_string( debug_ctx(), rec->header->to),285 cluster_id_string(tmp_ctx, rec->header->from), 286 cluster_id_string(tmp_ctx, rec->header->to), 267 287 rec->header->msg_type, 268 288 nt_errstr(status))); 289 talloc_free(tmp_ctx); 269 290 } 270 291 DLIST_REMOVE(msg->pending, rec); … … 441 462 */ 442 463 NTSTATUS messaging_send(struct messaging_context *msg, struct server_id server, 443 uint32_t msg_type, DATA_BLOB *data)464 uint32_t msg_type, const DATA_BLOB *data) 444 465 { 445 466 struct messaging_rec *rec; … … 536 557 const char *dir, 537 558 struct server_id server_id, 538 struct smb_iconv_convenience *iconv_convenience,539 559 struct tevent_context *ev) 540 560 { … … 565 585 msg->path = messaging_path(msg, server_id); 566 586 msg->server_id = server_id; 567 msg->iconv_convenience = iconv_convenience;568 587 msg->idr = idr_init(msg); 569 588 msg->dispatch_tree = idr_init(msg); … … 600 619 msg->event.fde = event_add_fd(ev, msg, socket_get_fd(msg->sock), 601 620 EVENT_FD_READ, messaging_handler, msg); 621 tevent_fd_set_auto_close(msg->event.fde); 602 622 603 623 talloc_set_destructor(msg, messaging_destructor); … … 615 635 struct messaging_context *messaging_client_init(TALLOC_CTX *mem_ctx, 616 636 const char *dir, 617 struct smb_iconv_convenience *iconv_convenience,618 637 struct tevent_context *ev) 619 638 { … … 621 640 ZERO_STRUCT(id); 622 641 id.id = random() % 0x10000000; 623 return messaging_init(mem_ctx, dir, id, iconv_convenience,ev);642 return messaging_init(mem_ctx, dir, id, ev); 624 643 } 625 644 /* … … 673 692 { 674 693 struct irpc_request *irpc; 675 enum ndr_err_code ndr_err;676 694 677 695 irpc = (struct irpc_request *)idr_find(msg_ctx->idr, m->header.callid); 678 696 if (irpc == NULL) return; 679 697 680 /* parse the reply data */ 681 ndr_err = irpc->table->calls[irpc->callnum].ndr_pull(m->ndr, NDR_OUT, irpc->r); 682 if (NDR_ERR_CODE_IS_SUCCESS(ndr_err)) { 683 irpc->status = m->header.status; 684 talloc_steal(irpc->mem_ctx, m); 685 } else { 686 irpc->status = ndr_map_error2ntstatus(ndr_err); 687 talloc_steal(irpc, m); 688 } 689 irpc->done = true; 690 if (irpc->async.fn) { 691 irpc->async.fn(irpc); 692 } 698 irpc->incoming.handler(irpc, m); 693 699 } 694 700 … … 705 711 706 712 /* setup the reply */ 707 push = ndr_push_init_ctx(m->ndr , m->msg_ctx->iconv_convenience);713 push = ndr_push_init_ctx(m->ndr); 708 714 if (push == NULL) { 709 715 status = NT_STATUS_NO_MEMORY; … … 712 718 713 719 m->header.flags |= IRPC_FLAG_REPLY; 720 m->header.creds.token= NULL; 714 721 715 722 /* construct the packet */ … … 764 771 if (r == NULL) goto failed; 765 772 773 m->ndr->flags |= LIBNDR_FLAG_REF_ALLOC; 774 766 775 /* parse the request data */ 767 776 ndr_err = i->table->calls[i->callnum].ndr_pull(m->ndr, NDR_IN, r); … … 771 780 m->private_data= i->private_data; 772 781 m->defer_reply = false; 782 m->no_reply = false; 773 783 m->msg_ctx = msg_ctx; 774 784 m->irpc = i; … … 778 788 m->header.status = i->fn(m, r); 779 789 790 if (m->no_reply) { 791 /* the server function won't ever be replying to this request */ 792 talloc_free(m); 793 return; 794 } 795 780 796 if (m->defer_reply) { 781 797 /* the server function has asked to defer the reply to later */ … … 805 821 m->from = src; 806 822 807 m->ndr = ndr_pull_init_blob(packet, m , msg_ctx->iconv_convenience);823 m->ndr = ndr_pull_init_blob(packet, m); 808 824 if (m->ndr == NULL) goto failed; 809 825 … … 835 851 } 836 852 837 if (irpc->reject_free) {838 return -1;839 }840 853 return 0; 841 }842 843 /*844 timeout a irpc request845 */846 static void irpc_timeout(struct tevent_context *ev, struct tevent_timer *te,847 struct timeval t, void *private_data)848 {849 struct irpc_request *irpc = talloc_get_type(private_data, struct irpc_request);850 irpc->status = NT_STATUS_IO_TIMEOUT;851 irpc->done = true;852 if (irpc->async.fn) {853 irpc->async.fn(irpc);854 }855 }856 857 858 /*859 make a irpc call - async send860 */861 struct irpc_request *irpc_call_send(struct messaging_context *msg_ctx,862 struct server_id server_id,863 const struct ndr_interface_table *table,864 int callnum, void *r, TALLOC_CTX *ctx)865 {866 struct irpc_header header;867 struct ndr_push *ndr;868 NTSTATUS status;869 DATA_BLOB packet;870 struct irpc_request *irpc;871 enum ndr_err_code ndr_err;872 873 irpc = talloc(msg_ctx, struct irpc_request);874 if (irpc == NULL) goto failed;875 876 irpc->msg_ctx = msg_ctx;877 irpc->table = table;878 irpc->callnum = callnum;879 irpc->callid = idr_get_new(msg_ctx->idr, irpc, UINT16_MAX);880 if (irpc->callid == -1) goto failed;881 irpc->r = r;882 irpc->done = false;883 irpc->async.fn = NULL;884 irpc->mem_ctx = ctx;885 irpc->reject_free = false;886 887 talloc_set_destructor(irpc, irpc_destructor);888 889 /* setup the header */890 header.uuid = table->syntax_id.uuid;891 892 header.if_version = table->syntax_id.if_version;893 header.callid = irpc->callid;894 header.callnum = callnum;895 header.flags = 0;896 header.status = NT_STATUS_OK;897 898 /* construct the irpc packet */899 ndr = ndr_push_init_ctx(irpc, msg_ctx->iconv_convenience);900 if (ndr == NULL) goto failed;901 902 ndr_err = ndr_push_irpc_header(ndr, NDR_SCALARS|NDR_BUFFERS, &header);903 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) goto failed;904 905 ndr_err = table->calls[callnum].ndr_push(ndr, NDR_IN, r);906 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err)) goto failed;907 908 /* and send it */909 packet = ndr_push_blob(ndr);910 status = messaging_send(msg_ctx, server_id, MSG_IRPC, &packet);911 if (!NT_STATUS_IS_OK(status)) goto failed;912 913 event_add_timed(msg_ctx->event.ev, irpc,914 timeval_current_ofs(IRPC_CALL_TIMEOUT, 0),915 irpc_timeout, irpc);916 917 talloc_free(ndr);918 return irpc;919 920 failed:921 talloc_free(irpc);922 return NULL;923 }924 925 /*926 wait for a irpc reply927 */928 NTSTATUS irpc_call_recv(struct irpc_request *irpc)929 {930 NTSTATUS status;931 932 NT_STATUS_HAVE_NO_MEMORY(irpc);933 934 irpc->reject_free = true;935 936 while (!irpc->done) {937 if (event_loop_once(irpc->msg_ctx->event.ev) != 0) {938 return NT_STATUS_CONNECTION_DISCONNECTED;939 }940 }941 942 irpc->reject_free = false;943 944 status = irpc->status;945 talloc_free(irpc);946 return status;947 }948 949 /*950 perform a synchronous irpc request951 */952 NTSTATUS irpc_call(struct messaging_context *msg_ctx,953 struct server_id server_id,954 const struct ndr_interface_table *table,955 int callnum, void *r,956 TALLOC_CTX *mem_ctx)957 {958 struct irpc_request *irpc = irpc_call_send(msg_ctx, server_id,959 table, callnum, r, mem_ctx);960 return irpc_call_recv(irpc);961 854 } 962 855 … … 1117 1010 return msg_ctx->server_id; 1118 1011 } 1012 1013 struct irpc_bh_state { 1014 struct messaging_context *msg_ctx; 1015 struct server_id server_id; 1016 const struct ndr_interface_table *table; 1017 uint32_t timeout; 1018 struct security_token *token; 1019 }; 1020 1021 static bool irpc_bh_is_connected(struct dcerpc_binding_handle *h) 1022 { 1023 struct irpc_bh_state *hs = dcerpc_binding_handle_data(h, 1024 struct irpc_bh_state); 1025 1026 if (!hs->msg_ctx) { 1027 return false; 1028 } 1029 1030 return true; 1031 } 1032 1033 static uint32_t irpc_bh_set_timeout(struct dcerpc_binding_handle *h, 1034 uint32_t timeout) 1035 { 1036 struct irpc_bh_state *hs = dcerpc_binding_handle_data(h, 1037 struct irpc_bh_state); 1038 uint32_t old = hs->timeout; 1039 1040 hs->timeout = timeout; 1041 1042 return old; 1043 } 1044 1045 struct irpc_bh_raw_call_state { 1046 struct irpc_request *irpc; 1047 uint32_t opnum; 1048 DATA_BLOB in_data; 1049 DATA_BLOB in_packet; 1050 DATA_BLOB out_data; 1051 }; 1052 1053 static void irpc_bh_raw_call_incoming_handler(struct irpc_request *irpc, 1054 struct irpc_message *m); 1055 1056 static struct tevent_req *irpc_bh_raw_call_send(TALLOC_CTX *mem_ctx, 1057 struct tevent_context *ev, 1058 struct dcerpc_binding_handle *h, 1059 const struct GUID *object, 1060 uint32_t opnum, 1061 uint32_t in_flags, 1062 const uint8_t *in_data, 1063 size_t in_length) 1064 { 1065 struct irpc_bh_state *hs = 1066 dcerpc_binding_handle_data(h, 1067 struct irpc_bh_state); 1068 struct tevent_req *req; 1069 struct irpc_bh_raw_call_state *state; 1070 bool ok; 1071 struct irpc_header header; 1072 struct ndr_push *ndr; 1073 NTSTATUS status; 1074 enum ndr_err_code ndr_err; 1075 1076 req = tevent_req_create(mem_ctx, &state, 1077 struct irpc_bh_raw_call_state); 1078 if (req == NULL) { 1079 return NULL; 1080 } 1081 state->opnum = opnum; 1082 state->in_data.data = discard_const_p(uint8_t, in_data); 1083 state->in_data.length = in_length; 1084 1085 ok = irpc_bh_is_connected(h); 1086 if (!ok) { 1087 tevent_req_nterror(req, NT_STATUS_INVALID_CONNECTION); 1088 return tevent_req_post(req, ev); 1089 } 1090 1091 state->irpc = talloc_zero(state, struct irpc_request); 1092 if (tevent_req_nomem(state->irpc, req)) { 1093 return tevent_req_post(req, ev); 1094 } 1095 1096 state->irpc->msg_ctx = hs->msg_ctx; 1097 state->irpc->callid = idr_get_new(hs->msg_ctx->idr, 1098 state->irpc, UINT16_MAX); 1099 if (state->irpc->callid == -1) { 1100 tevent_req_nterror(req, NT_STATUS_INSUFFICIENT_RESOURCES); 1101 return tevent_req_post(req, ev); 1102 } 1103 state->irpc->incoming.handler = irpc_bh_raw_call_incoming_handler; 1104 state->irpc->incoming.private_data = req; 1105 1106 talloc_set_destructor(state->irpc, irpc_destructor); 1107 1108 /* setup the header */ 1109 header.uuid = hs->table->syntax_id.uuid; 1110 1111 header.if_version = hs->table->syntax_id.if_version; 1112 header.callid = state->irpc->callid; 1113 header.callnum = state->opnum; 1114 header.flags = 0; 1115 header.status = NT_STATUS_OK; 1116 header.creds.token= hs->token; 1117 1118 /* construct the irpc packet */ 1119 ndr = ndr_push_init_ctx(state->irpc); 1120 if (tevent_req_nomem(ndr, req)) { 1121 return tevent_req_post(req, ev); 1122 } 1123 1124 ndr_err = ndr_push_irpc_header(ndr, NDR_SCALARS|NDR_BUFFERS, &header); 1125 status = ndr_map_error2ntstatus(ndr_err); 1126 if (!NT_STATUS_IS_OK(status)) { 1127 tevent_req_nterror(req, status); 1128 return tevent_req_post(req, ev); 1129 } 1130 1131 ndr_err = ndr_push_bytes(ndr, in_data, in_length); 1132 status = ndr_map_error2ntstatus(ndr_err); 1133 if (!NT_STATUS_IS_OK(status)) { 1134 tevent_req_nterror(req, status); 1135 return tevent_req_post(req, ev); 1136 } 1137 1138 /* and send it */ 1139 state->in_packet = ndr_push_blob(ndr); 1140 status = messaging_send(hs->msg_ctx, hs->server_id, 1141 MSG_IRPC, &state->in_packet); 1142 if (!NT_STATUS_IS_OK(status)) { 1143 tevent_req_nterror(req, status); 1144 return tevent_req_post(req, ev); 1145 } 1146 1147 if (hs->timeout != IRPC_CALL_TIMEOUT_INF) { 1148 /* set timeout-callback in case caller wants that */ 1149 ok = tevent_req_set_endtime(req, ev, timeval_current_ofs(hs->timeout, 0)); 1150 if (!ok) { 1151 return tevent_req_post(req, ev); 1152 } 1153 } 1154 1155 return req; 1156 } 1157 1158 static void irpc_bh_raw_call_incoming_handler(struct irpc_request *irpc, 1159 struct irpc_message *m) 1160 { 1161 struct tevent_req *req = 1162 talloc_get_type_abort(irpc->incoming.private_data, 1163 struct tevent_req); 1164 struct irpc_bh_raw_call_state *state = 1165 tevent_req_data(req, 1166 struct irpc_bh_raw_call_state); 1167 1168 talloc_steal(state, m); 1169 1170 if (!NT_STATUS_IS_OK(m->header.status)) { 1171 tevent_req_nterror(req, m->header.status); 1172 return; 1173 } 1174 1175 state->out_data = data_blob_talloc(state, 1176 m->ndr->data + m->ndr->offset, 1177 m->ndr->data_size - m->ndr->offset); 1178 if ((m->ndr->data_size - m->ndr->offset) > 0 && !state->out_data.data) { 1179 tevent_req_nomem(NULL, req); 1180 return; 1181 } 1182 1183 tevent_req_done(req); 1184 } 1185 1186 static NTSTATUS irpc_bh_raw_call_recv(struct tevent_req *req, 1187 TALLOC_CTX *mem_ctx, 1188 uint8_t **out_data, 1189 size_t *out_length, 1190 uint32_t *out_flags) 1191 { 1192 struct irpc_bh_raw_call_state *state = 1193 tevent_req_data(req, 1194 struct irpc_bh_raw_call_state); 1195 NTSTATUS status; 1196 1197 if (tevent_req_is_nterror(req, &status)) { 1198 tevent_req_received(req); 1199 return status; 1200 } 1201 1202 *out_data = talloc_move(mem_ctx, &state->out_data.data); 1203 *out_length = state->out_data.length; 1204 *out_flags = 0; 1205 tevent_req_received(req); 1206 return NT_STATUS_OK; 1207 } 1208 1209 struct irpc_bh_disconnect_state { 1210 uint8_t _dummy; 1211 }; 1212 1213 static struct tevent_req *irpc_bh_disconnect_send(TALLOC_CTX *mem_ctx, 1214 struct tevent_context *ev, 1215 struct dcerpc_binding_handle *h) 1216 { 1217 struct irpc_bh_state *hs = dcerpc_binding_handle_data(h, 1218 struct irpc_bh_state); 1219 struct tevent_req *req; 1220 struct irpc_bh_disconnect_state *state; 1221 bool ok; 1222 1223 req = tevent_req_create(mem_ctx, &state, 1224 struct irpc_bh_disconnect_state); 1225 if (req == NULL) { 1226 return NULL; 1227 } 1228 1229 ok = irpc_bh_is_connected(h); 1230 if (!ok) { 1231 tevent_req_nterror(req, NT_STATUS_INVALID_CONNECTION); 1232 return tevent_req_post(req, ev); 1233 } 1234 1235 hs->msg_ctx = NULL; 1236 1237 tevent_req_done(req); 1238 return tevent_req_post(req, ev); 1239 } 1240 1241 static NTSTATUS irpc_bh_disconnect_recv(struct tevent_req *req) 1242 { 1243 NTSTATUS status; 1244 1245 if (tevent_req_is_nterror(req, &status)) { 1246 tevent_req_received(req); 1247 return status; 1248 } 1249 1250 tevent_req_received(req); 1251 return NT_STATUS_OK; 1252 } 1253 1254 static bool irpc_bh_ref_alloc(struct dcerpc_binding_handle *h) 1255 { 1256 return true; 1257 } 1258 1259 static const struct dcerpc_binding_handle_ops irpc_bh_ops = { 1260 .name = "wbint", 1261 .is_connected = irpc_bh_is_connected, 1262 .set_timeout = irpc_bh_set_timeout, 1263 .raw_call_send = irpc_bh_raw_call_send, 1264 .raw_call_recv = irpc_bh_raw_call_recv, 1265 .disconnect_send = irpc_bh_disconnect_send, 1266 .disconnect_recv = irpc_bh_disconnect_recv, 1267 1268 .ref_alloc = irpc_bh_ref_alloc, 1269 }; 1270 1271 /* initialise a irpc binding handle */ 1272 struct dcerpc_binding_handle *irpc_binding_handle(TALLOC_CTX *mem_ctx, 1273 struct messaging_context *msg_ctx, 1274 struct server_id server_id, 1275 const struct ndr_interface_table *table) 1276 { 1277 struct dcerpc_binding_handle *h; 1278 struct irpc_bh_state *hs; 1279 1280 h = dcerpc_binding_handle_create(mem_ctx, 1281 &irpc_bh_ops, 1282 NULL, 1283 table, 1284 &hs, 1285 struct irpc_bh_state, 1286 __location__); 1287 if (h == NULL) { 1288 return NULL; 1289 } 1290 hs->msg_ctx = msg_ctx; 1291 hs->server_id = server_id; 1292 hs->table = table; 1293 hs->timeout = IRPC_CALL_TIMEOUT; 1294 1295 dcerpc_binding_handle_set_sync_ev(h, msg_ctx->event.ev); 1296 1297 return h; 1298 } 1299 1300 struct dcerpc_binding_handle *irpc_binding_handle_by_name(TALLOC_CTX *mem_ctx, 1301 struct messaging_context *msg_ctx, 1302 const char *dest_task, 1303 const struct ndr_interface_table *table) 1304 { 1305 struct dcerpc_binding_handle *h; 1306 struct server_id *sids; 1307 struct server_id sid; 1308 1309 /* find the server task */ 1310 sids = irpc_servers_byname(msg_ctx, mem_ctx, dest_task); 1311 if (sids == NULL) { 1312 errno = EADDRNOTAVAIL; 1313 return NULL; 1314 } 1315 if (sids[0].id == 0) { 1316 talloc_free(sids); 1317 errno = EADDRNOTAVAIL; 1318 return NULL; 1319 } 1320 sid = sids[0]; 1321 talloc_free(sids); 1322 1323 h = irpc_binding_handle(mem_ctx, msg_ctx, 1324 sid, table); 1325 if (h == NULL) { 1326 return NULL; 1327 } 1328 1329 return h; 1330 } 1331 1332 void irpc_binding_handle_add_security_token(struct dcerpc_binding_handle *h, 1333 struct security_token *token) 1334 { 1335 struct irpc_bh_state *hs = 1336 dcerpc_binding_handle_data(h, 1337 struct irpc_bh_state); 1338 1339 hs->token = token; 1340 } -
vendor/current/source4/lib/messaging/messaging.h
r414 r740 22 22 #define _MESSAGES_H_ 23 23 24 #include "librpc/gen_ndr/server_id4.h" 25 24 26 struct messaging_context; 25 27 … … 33 35 #define MSG_PVFS_NOTIFY 7 34 36 #define MSG_NTVFS_OPLOCK_BREAK 8 37 #define MSG_DREPL_ALLOCATE_RID 9 35 38 36 39 /* temporary messaging endpoints are allocated above this line */ … … 40 43 #define SAMBA_PARENT_TASKID 0 41 44 45 typedef void (*msg_callback_t)(struct messaging_context *msg, void *private_data, 46 uint32_t msg_type, 47 struct server_id server_id, DATA_BLOB *data); 48 49 NTSTATUS messaging_send(struct messaging_context *msg, struct server_id server, 50 uint32_t msg_type, const DATA_BLOB *data); 51 NTSTATUS messaging_register(struct messaging_context *msg, void *private_data, 52 uint32_t msg_type, 53 msg_callback_t fn); 54 NTSTATUS messaging_register_tmp(struct messaging_context *msg, void *private_data, 55 msg_callback_t fn, uint32_t *msg_type); 56 struct messaging_context *messaging_init(TALLOC_CTX *mem_ctx, 57 const char *dir, 58 struct server_id server_id, 59 struct tevent_context *ev); 60 struct messaging_context *messaging_client_init(TALLOC_CTX *mem_ctx, 61 const char *dir, 62 struct tevent_context *ev); 63 NTSTATUS messaging_send_ptr(struct messaging_context *msg, struct server_id server, 64 uint32_t msg_type, void *ptr); 65 void messaging_deregister(struct messaging_context *msg, uint32_t msg_type, void *private_data); 66 struct server_id messaging_get_server_id(struct messaging_context *msg_ctx); 67 42 68 #endif -
vendor/current/source4/lib/messaging/pymessaging.c
r414 r740 20 20 */ 21 21 22 #include <Python.h> 22 23 #include "includes.h" 23 #include <Python.h>24 24 #include "scripting/python/modules.h" 25 25 #include "libcli/util/pyerrors.h" 26 #include "librpc/rpc/pyrpc .h"27 #include "lib /messaging/irpc.h"26 #include "librpc/rpc/pyrpc_util.h" 27 #include "librpc/ndr/libndr.h" 28 28 #include "lib/messaging/messaging.h" 29 29 #include "lib/events/events.h" … … 31 31 #include "param/param.h" 32 32 #include "param/pyparam.h" 33 34 #ifndef Py_RETURN_NONE 35 #define Py_RETURN_NONE return Py_INCREF(Py_None), Py_None 36 #endif 37 38 PyAPI_DATA(PyTypeObject) messaging_Type; 39 PyAPI_DATA(PyTypeObject) irpc_ClientConnectionType; 40 41 /* FIXME: This prototype should be in py_irpc.h, or shared otherwise */ 42 extern const struct PyNdrRpcMethodDef py_ndr_irpc_methods[]; 33 #include "librpc/rpc/dcerpc.h" 34 #include "librpc/gen_ndr/server_id4.h" 35 36 void initmessaging(void); 37 38 extern PyTypeObject messaging_Type; 43 39 44 40 static bool server_id_from_py(PyObject *object, struct server_id *server_id) … … 66 62 } messaging_Object; 67 63 68 PyObject *py_messaging_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs)64 static PyObject *py_messaging_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs) 69 65 { 70 66 struct tevent_context *ev; … … 88 84 89 85 if (messaging_path == NULL) { 90 messaging_path = lp _messaging_path(ret->mem_ctx,86 messaging_path = lpcfg_messaging_path(ret->mem_ctx, 91 87 py_default_loadparm_context(ret->mem_ctx)); 92 88 } else { … … 103 99 messaging_path, 104 100 server_id, 105 py_iconv_convenience(ret->mem_ctx),106 101 ev); 107 102 } else { 108 103 ret->msg_ctx = messaging_client_init(ret->mem_ctx, 109 104 messaging_path, 110 py_iconv_convenience(ret->mem_ctx),111 105 ev); 112 106 } … … 125 119 messaging_Object *iface = (messaging_Object *)self; 126 120 talloc_free(iface->msg_ctx); 127 PyObject_Del(self);121 self->ob_type->tp_free(self); 128 122 } 129 123 … … 139 133 int length; 140 134 141 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Ois# |:send",135 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "Ois#:send", 142 136 discard_const_p(char *, kwnames), &target, &msg_type, &data.data, &length)) { 137 143 138 return NULL; 144 139 } … … 146 141 data.length = length; 147 142 148 if (!server_id_from_py(target, &server)) 143 if (!server_id_from_py(target, &server)) 149 144 return NULL; 150 145 … … 177 172 const char *kwnames[] = { "callback", "msg_type", NULL }; 178 173 179 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|i: send",174 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|i:register", 180 175 discard_const_p(char *, kwnames), &callback, &msg_type)) { 181 176 return NULL; … … 208 203 const char *kwnames[] = { "callback", "msg_type", NULL }; 209 204 210 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|i: send",205 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|i:deregister", 211 206 discard_const_p(char *, kwnames), &callback, &msg_type)) { 212 207 return NULL; … … 216 211 217 212 Py_DECREF(callback); 218 219 Py_RETURN_NONE;220 }221 222 static PyObject *py_messaging_add_name(PyObject *self, PyObject *args, PyObject *kwargs)223 {224 messaging_Object *iface = (messaging_Object *)self;225 NTSTATUS status;226 char *name;227 const char *kwnames[] = { "name", NULL };228 229 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|:send",230 discard_const_p(char *, kwnames), &name)) {231 return NULL;232 }233 234 status = irpc_add_name(iface->msg_ctx, name);235 if (NT_STATUS_IS_ERR(status)) {236 PyErr_SetNTSTATUS(status);237 return NULL;238 }239 240 Py_RETURN_NONE;241 }242 243 244 static PyObject *py_messaging_remove_name(PyObject *self, PyObject *args, PyObject *kwargs)245 {246 messaging_Object *iface = (messaging_Object *)self;247 char *name;248 const char *kwnames[] = { "name", NULL };249 250 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|:send",251 discard_const_p(char *, kwnames), &name)) {252 return NULL;253 }254 255 irpc_remove_name(iface->msg_ctx, name);256 213 257 214 Py_RETURN_NONE; … … 265 222 { "deregister", (PyCFunction)py_messaging_deregister, METH_VARARGS|METH_KEYWORDS, 266 223 "S.deregister(callback, msg_type) -> None\nDeregister a message handler" }, 267 { "add_name", (PyCFunction)py_messaging_add_name, METH_VARARGS|METH_KEYWORDS, "S.add_name(name) -> None\nListen on another name" },268 { "remove_name", (PyCFunction)py_messaging_remove_name, METH_VARARGS|METH_KEYWORDS, "S.remove_name(name) -> None\nStop listening on a name" },269 224 { NULL, NULL, 0, NULL } 270 225 }; … … 288 243 PyTypeObject messaging_Type = { 289 244 PyObject_HEAD_INIT(NULL) 0, 290 .tp_name = " irpc.Messaging",245 .tp_name = "messaging.Messaging", 291 246 .tp_basicsize = sizeof(messaging_Object), 292 247 .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE, … … 300 255 }; 301 256 302 303 /*304 state of a irpc 'connection'305 */306 typedef struct {307 PyObject_HEAD308 const char *server_name;309 struct server_id *dest_ids;310 struct messaging_context *msg_ctx;311 TALLOC_CTX *mem_ctx;312 } irpc_ClientConnectionObject;313 314 /*315 setup a context for talking to a irpc server316 example:317 status = irpc.connect("smb_server");318 */319 320 PyObject *py_irpc_connect(PyTypeObject *self, PyObject *args, PyObject *kwargs)321 {322 struct tevent_context *ev;323 const char *kwnames[] = { "server", "own_id", "messaging_path", NULL };324 char *server;325 const char *messaging_path = NULL;326 PyObject *own_id = Py_None;327 irpc_ClientConnectionObject *ret;328 329 if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s|Oz:connect",330 discard_const_p(char *, kwnames), &server, &own_id, &messaging_path)) {331 return NULL;332 }333 334 ret = PyObject_New(irpc_ClientConnectionObject, &irpc_ClientConnectionType);335 if (ret == NULL)336 return NULL;337 338 ret->mem_ctx = talloc_new(NULL);339 340 ret->server_name = server;341 342 ev = s4_event_context_init(ret->mem_ctx);343 344 if (messaging_path == NULL) {345 messaging_path = lp_messaging_path(ret->mem_ctx,346 py_default_loadparm_context(ret->mem_ctx));347 } else {348 messaging_path = talloc_strdup(ret->mem_ctx, messaging_path);349 }350 351 if (own_id != Py_None) {352 struct server_id server_id;353 354 if (!server_id_from_py(own_id, &server_id))355 return NULL;356 357 ret->msg_ctx = messaging_init(ret->mem_ctx,358 messaging_path,359 server_id,360 py_iconv_convenience(ret->mem_ctx),361 ev);362 } else {363 ret->msg_ctx = messaging_client_init(ret->mem_ctx,364 messaging_path,365 py_iconv_convenience(ret->mem_ctx),366 ev);367 }368 369 if (ret->msg_ctx == NULL) {370 PyErr_SetString(PyExc_RuntimeError, "irpc_connect unable to create a messaging context");371 talloc_free(ret->mem_ctx);372 return NULL;373 }374 375 ret->dest_ids = irpc_servers_byname(ret->msg_ctx, ret->mem_ctx, ret->server_name);376 if (ret->dest_ids == NULL || ret->dest_ids[0].id == 0) {377 talloc_free(ret->mem_ctx);378 PyErr_SetNTSTATUS(NT_STATUS_OBJECT_NAME_NOT_FOUND);379 return NULL;380 } else {381 return (PyObject *)ret;382 }383 }384 385 typedef struct {386 PyObject_HEAD387 struct irpc_request **reqs;388 int count;389 int current;390 TALLOC_CTX *mem_ctx;391 py_data_unpack_fn unpack_fn;392 } irpc_ResultObject;393 394 395 static PyObject *irpc_result_next(irpc_ResultObject *iterator)396 {397 NTSTATUS status;398 399 if (iterator->current >= iterator->count) {400 PyErr_SetString(PyExc_StopIteration, "No more results");401 return NULL;402 }403 404 status = irpc_call_recv(iterator->reqs[iterator->current]);405 iterator->current++;406 if (!NT_STATUS_IS_OK(status)) {407 PyErr_SetNTSTATUS(status);408 return NULL;409 }410 411 return iterator->unpack_fn(iterator->reqs[iterator->current-1]->r);412 }413 414 static PyObject *irpc_result_len(irpc_ResultObject *self)415 {416 return PyLong_FromLong(self->count);417 }418 419 static PyMethodDef irpc_result_methods[] = {420 { "__len__", (PyCFunction)irpc_result_len, METH_NOARGS,421 "Number of elements returned"},422 { NULL }423 };424 425 static void irpc_result_dealloc(PyObject *self)426 {427 talloc_free(((irpc_ResultObject *)self)->mem_ctx);428 PyObject_Del(self);429 }430 431 PyTypeObject irpc_ResultIteratorType = {432 PyObject_HEAD_INIT(NULL) 0,433 .tp_name = "irpc.ResultIterator",434 .tp_basicsize = sizeof(irpc_ResultObject),435 .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,436 .tp_iternext = (iternextfunc)irpc_result_next,437 .tp_iter = PyObject_SelfIter,438 .tp_methods = irpc_result_methods,439 .tp_dealloc = irpc_result_dealloc,440 };441 442 static PyObject *py_irpc_call(irpc_ClientConnectionObject *p, struct PyNdrRpcMethodDef *method_def, PyObject *args, PyObject *kwargs)443 {444 void *ptr;445 struct irpc_request **reqs;446 int i, count;447 NTSTATUS status;448 TALLOC_CTX *mem_ctx = talloc_new(NULL);449 irpc_ResultObject *ret;450 451 /* allocate the C structure */452 ptr = talloc_zero_size(mem_ctx, method_def->table->calls[method_def->opnum].struct_size);453 if (ptr == NULL) {454 status = NT_STATUS_NO_MEMORY;455 goto done;456 }457 458 /* convert the mpr object into a C structure */459 if (!method_def->pack_in_data(args, kwargs, ptr)) {460 talloc_free(mem_ctx);461 return NULL;462 }463 464 for (count=0;p->dest_ids[count].id;count++) /* noop */ ;465 466 /* we need to make a call per server */467 reqs = talloc_array(mem_ctx, struct irpc_request *, count);468 if (reqs == NULL) {469 status = NT_STATUS_NO_MEMORY;470 goto done;471 }472 473 /* make the actual calls */474 for (i=0;i<count;i++) {475 reqs[i] = irpc_call_send(p->msg_ctx, p->dest_ids[i],476 method_def->table, method_def->opnum, ptr, ptr);477 if (reqs[i] == NULL) {478 status = NT_STATUS_NO_MEMORY;479 goto done;480 }481 talloc_steal(reqs, reqs[i]);482 }483 484 ret = PyObject_New(irpc_ResultObject, &irpc_ResultIteratorType);485 ret->mem_ctx = mem_ctx;486 ret->reqs = reqs;487 ret->count = count;488 ret->current = 0;489 ret->unpack_fn = method_def->unpack_out_data;490 491 return (PyObject *)ret;492 done:493 talloc_free(mem_ctx);494 PyErr_SetNTSTATUS(status);495 return NULL;496 }497 498 static PyObject *py_irpc_call_wrapper(PyObject *self, PyObject *args, void *wrapped, PyObject *kwargs)499 {500 irpc_ClientConnectionObject *iface = (irpc_ClientConnectionObject *)self;501 struct PyNdrRpcMethodDef *md = wrapped;502 503 return py_irpc_call(iface, md, args, kwargs);504 }505 506 static void py_irpc_dealloc(PyObject *self)507 {508 irpc_ClientConnectionObject *iface = (irpc_ClientConnectionObject *)self;509 talloc_free(iface->mem_ctx);510 PyObject_Del(self);511 }512 513 PyTypeObject irpc_ClientConnectionType = {514 PyObject_HEAD_INIT(NULL) 0,515 .tp_name = "irpc.ClientConnection",516 .tp_basicsize = sizeof(irpc_ClientConnectionObject),517 .tp_flags = Py_TPFLAGS_DEFAULT|Py_TPFLAGS_BASETYPE,518 .tp_new = py_irpc_connect,519 .tp_dealloc = py_irpc_dealloc,520 .tp_doc = "ClientConnection(server, own_id=None, messaging_path=None)\n" \521 "Create a new IRPC client connection to communicate with the servers in the specified path.\n" \522 "If no path is specified, the default path from smb.conf will be used."523 };524 525 static bool irpc_AddNdrRpcMethods(PyTypeObject *ifacetype, const struct PyNdrRpcMethodDef *mds)526 {527 int i;528 for (i = 0; mds[i].name; i++) {529 PyObject *ret;530 struct wrapperbase *wb = calloc(sizeof(struct wrapperbase), 1);531 532 wb->name = discard_const_p(char, mds[i].name);533 wb->flags = PyWrapperFlag_KEYWORDS;534 wb->wrapper = (wrapperfunc)py_irpc_call_wrapper;535 wb->doc = discard_const_p(char, mds[i].doc);536 537 ret = PyDescr_NewWrapper(ifacetype, wb, discard_const_p(void, &mds[i]));538 539 PyDict_SetItemString(ifacetype->tp_dict, mds[i].name,540 (PyObject *)ret);541 }542 543 return true;544 }545 546 257 void initmessaging(void) 547 258 { 548 259 PyObject *mod; 549 PyObject *dep_irpc;550 551 dep_irpc = PyImport_ImportModule("samba.dcerpc.irpc");552 if (dep_irpc == NULL)553 return;554 555 if (PyType_Ready(&irpc_ClientConnectionType) < 0)556 return;557 260 558 261 if (PyType_Ready(&messaging_Type) < 0) 559 return;560 561 if (PyType_Ready(&irpc_ResultIteratorType) < 0)562 return;563 564 if (!irpc_AddNdrRpcMethods(&irpc_ClientConnectionType, py_ndr_irpc_methods))565 262 return; 566 263 … … 569 266 return; 570 267 571 Py_INCREF((PyObject *)&irpc_ClientConnectionType);572 PyModule_AddObject(mod, "ClientConnection", (PyObject *)&irpc_ClientConnectionType);573 574 268 Py_INCREF((PyObject *)&messaging_Type); 575 269 PyModule_AddObject(mod, "Messaging", (PyObject *)&messaging_Type); -
vendor/current/source4/lib/messaging/tests/irpc.c
r414 r740 24 24 #include "lib/messaging/irpc.h" 25 25 #include "librpc/gen_ndr/ndr_echo.h" 26 #include "librpc/gen_ndr/ndr_echo_c.h" 26 27 #include "torture/torture.h" 27 28 #include "cluster/cluster.h" … … 58 59 { 59 60 struct irpc_message *irpc = talloc_get_type(private_data, struct irpc_message); 60 struct echo_EchoData *r = irpc->data;61 r->out.out_data = talloc_memdup(r, r->in.in_data, r->in.len);61 struct echo_EchoData *r = (struct echo_EchoData *)irpc->data; 62 r->out.out_data = (uint8_t *)talloc_memdup(r, r->in.in_data, r->in.len); 62 63 if (r->out.out_data == NULL) { 63 64 irpc_send_reply(irpc, NT_STATUS_NO_MEMORY); … … 89 90 const struct irpc_test_data *data = (const struct irpc_test_data *)_data; 90 91 uint32_t value = *(const uint32_t *)_value; 92 struct dcerpc_binding_handle *irpc_handle; 93 94 irpc_handle = irpc_binding_handle(test, data->msg_ctx1, 95 cluster_id(0, MSG_ID2), 96 &ndr_table_rpcecho); 97 torture_assert(test, irpc_handle, "no memory"); 91 98 92 99 /* make the call */ … … 94 101 95 102 test_debug = true; 96 status = IRPC_CALL(data->msg_ctx1, cluster_id(0, MSG_ID2), 97 rpcecho, ECHO_ADDONE, &r, test); 103 status = dcerpc_echo_AddOne_r(irpc_handle, test, &r); 98 104 test_debug = false; 99 105 torture_assert_ntstatus_ok(test, status, "AddOne failed"); … … 118 124 const struct irpc_test_data *data = (const struct irpc_test_data *)tcase_data; 119 125 TALLOC_CTX *mem_ctx = tctx; 126 struct dcerpc_binding_handle *irpc_handle; 127 128 irpc_handle = irpc_binding_handle(mem_ctx, data->msg_ctx1, 129 cluster_id(0, MSG_ID2), 130 &ndr_table_rpcecho); 131 torture_assert(tctx, irpc_handle, "no memory"); 120 132 121 133 /* make the call */ … … 123 135 r.in.len = strlen((char *)r.in.in_data); 124 136 125 status = IRPC_CALL(data->msg_ctx1, cluster_id(0, MSG_ID2), 126 rpcecho, ECHO_ECHODATA, &r, 127 mem_ctx); 137 status = dcerpc_echo_EchoData_r(irpc_handle, mem_ctx, &r); 128 138 torture_assert_ntstatus_ok(tctx, status, "EchoData failed"); 129 139 … … 142 152 } 143 153 144 145 static void irpc_callback(struct irpc_request *irpc) 146 { 147 struct echo_AddOne *r = (struct echo_AddOne *)irpc->r; 148 int *pong_count = (int *)irpc->async.private_data; 149 NTSTATUS status = irpc_call_recv(irpc); 154 struct irpc_callback_state { 155 struct echo_AddOne r; 156 int *pong_count; 157 }; 158 159 static void irpc_callback(struct tevent_req *subreq) 160 { 161 struct irpc_callback_state *s = 162 tevent_req_callback_data(subreq, 163 struct irpc_callback_state); 164 NTSTATUS status; 165 166 status = dcerpc_echo_AddOne_r_recv(subreq, s); 167 TALLOC_FREE(subreq); 150 168 if (!NT_STATUS_IS_OK(status)) { 151 169 printf("irpc call failed - %s\n", nt_errstr(status)); 152 170 } 153 if (* r->out.out_data != r->in.in_data + 1) {171 if (*s->r.out.out_data != s->r.in.in_data + 1) { 154 172 printf("AddOne wrong answer - %u + 1 = %u should be %u\n", 155 r->in.in_data, *r->out.out_data, r->in.in_data+1);156 } 157 (* pong_count)++;173 s->r.in.in_data, *s->r.out.out_data, s->r.in.in_data+1); 174 } 175 (*s->pong_count)++; 158 176 } 159 177 … … 169 187 const struct irpc_test_data *data = (const struct irpc_test_data *)tcase_data; 170 188 struct timeval tv; 171 struct echo_AddOne r;172 189 TALLOC_CTX *mem_ctx = tctx; 173 190 int timelimit = torture_setting_int(tctx, "timelimit", 10); 191 struct dcerpc_binding_handle *irpc_handle; 192 193 irpc_handle = irpc_binding_handle(mem_ctx, data->msg_ctx1, 194 cluster_id(0, MSG_ID2), 195 &ndr_table_rpcecho); 196 torture_assert(tctx, irpc_handle, "no memory"); 174 197 175 198 tv = timeval_current(); 176 177 r.in.in_data = 0;178 199 179 200 torture_comment(tctx, "Sending echo for %d seconds\n", timelimit); 180 201 while (timeval_elapsed(&tv) < timelimit) { 181 struct irpc_request *irpc; 182 183 irpc = IRPC_CALL_SEND(data->msg_ctx1, cluster_id(0, MSG_ID2), 184 rpcecho, ECHO_ADDONE, 185 &r, mem_ctx); 186 torture_assert(tctx, irpc != NULL, "AddOne send failed"); 187 188 irpc->async.fn = irpc_callback; 189 irpc->async.private_data = &pong_count; 202 struct tevent_req *subreq; 203 struct irpc_callback_state *s; 204 205 s = talloc_zero(mem_ctx, struct irpc_callback_state); 206 torture_assert(tctx, s != NULL, "no mem"); 207 208 s->pong_count = &pong_count; 209 210 subreq = dcerpc_echo_AddOne_r_send(mem_ctx, 211 tctx->ev, 212 irpc_handle, 213 &s->r); 214 torture_assert(tctx, subreq != NULL, "AddOne send failed"); 215 216 tevent_req_set_callback(subreq, irpc_callback, s); 190 217 191 218 ping_count++; … … 216 243 *_data = data = talloc(tctx, struct irpc_test_data); 217 244 218 lp _set_cmdline(tctx->lp_ctx, "pid directory", "piddir.tmp");245 lpcfg_set_cmdline(tctx->lp_ctx, "pid directory", "piddir.tmp"); 219 246 220 247 data->ev = tctx->ev; 221 248 torture_assert(tctx, data->msg_ctx1 = 222 249 messaging_init(tctx, 223 lp _messaging_path(tctx, tctx->lp_ctx),250 lpcfg_messaging_path(tctx, tctx->lp_ctx), 224 251 cluster_id(0, MSG_ID1), 225 lp_iconv_convenience(tctx->lp_ctx),226 252 data->ev), 227 253 "Failed to init first messaging context"); … … 229 255 torture_assert(tctx, data->msg_ctx2 = 230 256 messaging_init(tctx, 231 lp _messaging_path(tctx, tctx->lp_ctx),257 lpcfg_messaging_path(tctx, tctx->lp_ctx), 232 258 cluster_id(0, MSG_ID2), 233 lp_iconv_convenience(tctx->lp_ctx),234 259 data->ev), 235 260 "Failed to init second messaging context"); … … 247 272 struct torture_suite *torture_local_irpc(TALLOC_CTX *mem_ctx) 248 273 { 249 struct torture_suite *suite = torture_suite_create(mem_ctx, " IRPC");274 struct torture_suite *suite = torture_suite_create(mem_ctx, "irpc"); 250 275 struct torture_tcase *tcase = torture_suite_add_tcase(suite, "irpc"); 251 276 int i; -
vendor/current/source4/lib/messaging/tests/messaging.c
r414 r740 68 68 uint32_t msg_ping, msg_exit; 69 69 70 lp _set_cmdline(tctx->lp_ctx, "pid directory", "piddir.tmp");70 lpcfg_set_cmdline(tctx->lp_ctx, "pid directory", "piddir.tmp"); 71 71 72 72 ev = tctx->ev; 73 73 74 74 msg_server_ctx = messaging_init(tctx, 75 lp_messaging_path(tctx, tctx->lp_ctx), 76 cluster_id(0, 1), 77 lp_iconv_convenience(tctx->lp_ctx), 75 lpcfg_messaging_path(tctx, tctx->lp_ctx), cluster_id(0, 1), 78 76 ev); 79 77 … … 84 82 85 83 msg_client_ctx = messaging_init(tctx, 86 lp _messaging_path(tctx, tctx->lp_ctx),84 lpcfg_messaging_path(tctx, tctx->lp_ctx), 87 85 cluster_id(0, 2), 88 lp_iconv_convenience(tctx->lp_ctx),89 86 ev); 90 87 … … 140 137 struct torture_suite *torture_local_messaging(TALLOC_CTX *mem_ctx) 141 138 { 142 struct torture_suite *s = torture_suite_create(mem_ctx, " MESSAGING");139 struct torture_suite *s = torture_suite_create(mem_ctx, "messaging"); 143 140 torture_suite_add_simple_test(s, "ping_speed", test_ping_speed); 144 141 return s;
Note:
See TracChangeset
for help on using the changeset viewer.