/* Read some data from a client connection */
-static NTSTATUS child_read_request(int sock, struct winbindd_request *wreq)
+static NTSTATUS child_read_request(TALLOC_CTX *mem_ctx, int sock,
+ struct winbindd_request **wreq_out)
{
NTSTATUS status;
+ struct winbindd_request *wreq;
+
+ wreq = talloc(mem_ctx, struct winbindd_request);
+ if (wreq == NULL) {
+ status = NT_STATUS_NO_MEMORY;
+ goto err_out;
+ }
status = read_data(sock, (char *)wreq, sizeof(*wreq));
if (!NT_STATUS_IS_OK(status)) {
DEBUG(3, ("child_read_request: read_data failed: %s\n",
nt_errstr(status)));
- return status;
+ goto err_wreq_free;
}
if (wreq->extra_len == 0) {
wreq->extra_data.data = NULL;
- return NT_STATUS_OK;
+ goto done;
}
DEBUG(10, ("Need to read %d extra bytes\n", (int)wreq->extra_len));
- wreq->extra_data.data = SMB_MALLOC_ARRAY(char, wreq->extra_len + 1);
+ wreq->extra_data.data = talloc_array(wreq, char, wreq->extra_len + 1);
if (wreq->extra_data.data == NULL) {
- DEBUG(0, ("malloc failed\n"));
- return NT_STATUS_NO_MEMORY;
+ status = NT_STATUS_NO_MEMORY;
+ goto err_wreq_free;
}
/* Ensure null termination */
if (!NT_STATUS_IS_OK(status)) {
DEBUG(0, ("Could not read extra data: %s\n",
nt_errstr(status)));
+ goto err_wreq_free;
}
+done:
+ wreq->null_term = '\0';
+ *wreq_out = wreq;
+ return NT_STATUS_OK;
+
+err_wreq_free:
+ talloc_free(wreq);
+err_out:
return status;
}
{
int fdpair[2];
struct winbindd_cli_state state;
- struct winbindd_request request;
- struct winbindd_response response;
struct winbindd_domain *primary_domain = NULL;
NTSTATUS status;
ssize_t nwritten;
ZERO_STRUCT(state);
state.pid = getpid();
- state.request = &request;
- state.response = &response;
child->pid = fork();
_exit(1);
}
- /* fetch a request from the main daemon */
- status = child_read_request(state.sock, state.request);
-
+ /* alloc and fetch a request from the main daemon */
+ status = child_read_request(mem_ctx, state.sock,
+ &state.request);
if (!NT_STATUS_IS_OK(status)) {
/* we lost contact with our parent */
_exit(0);
DEBUG(4,("child daemon request %d\n", (int)state.request->cmd));
- ZERO_STRUCTP(state.response);
- state.request->null_term = '\0';
+ state.response = talloc_zero(mem_ctx, struct winbindd_response);
+ if (state.response == NULL) {
+ _exit(1);
+ }
+
state.mem_ctx = mem_ctx;
child_process_request(child, &state);
DEBUG(4, ("Finished processing child request %d\n",
(int)state.request->cmd));
- SAFE_FREE(state.request->extra_data.data);
-
status = child_write_response(state.sock, state.response);
if (!NT_STATUS_IS_OK(status)) {
_exit(1);