Ejemplo n.º 1
0
void
delayed_ucn(PVOID p)
{
	struct delayed_ucn_param *ucn_param = (struct delayed_ucn_param *)p;

	update_conn_info(ucn_param->devobj, ucn_param->fileobj);
	
	free(ucn_param);
}
Ejemplo n.º 2
0
PyObject *
LDAPConnectIter_iternext(LDAPConnectIter *self) {
	int rc = -1;
	PyObject *val = NULL;
	PyObject *wrapper = NULL;

	/* The connection is already binded. */
	if (self->conn->closed == 0) {
		return PyErr_Format(PyExc_StopIteration, "Connection is already open.");
	}

	if (self->init_finished == 0) {
		rc = LDAP_finish_init(self->async, (void *)self->thread, (void *)self->data, &(self->conn->ld));
		if (rc == -1) return NULL; /* Error is happened. */
		if (rc == 1) {
			/* Initialisation is finished. */
			self->init_finished = 1;
			if (update_conn_info(self->conn->ld, self->info) != 0) return NULL;
		}
	} else {
		/* Init for the LDAP structure is finished, TLS (if it is needed) already set, start binding. */
		val = binding(self);
		if (val == NULL) return NULL;
		if (val != Py_None) {
			if (self->async) {
				/* Raise a StopIteration error to imitate a generator func. */
				/* Need some workaround (Python Issue #23996). */
				PyObject *args = Py_BuildValue("(O)", val);
				wrapper = PyObject_CallObject(PyExc_StopIteration, args);
				Py_DECREF(args);
				if (wrapper == NULL) {
					Py_DECREF(val);
					PyErr_BadInternalCall();
					return NULL;
				}
				/* Embedding StopIterator into StopIterator to
				   avoid *_PyGen_FetchStopIterationValue() crashes */
				((PyStopIterationObject *)wrapper)->value = val;
				PyErr_SetObject(PyExc_StopIteration, wrapper);
				return NULL;
			} else {
				/* Simple return the LDAPConnection object. */
				return val;
			}
		}
	}
	if (self->async) {
		Py_RETURN_NONE;
	} else {
		/* If the connection is not asynchronous, then call next() */
		/* automatically, until an error or the LDAPConnection occurs.  */
		return LDAPConnectIter_iternext(self);
	}
}
Ejemplo n.º 3
0
NTSTATUS
tdi_evconn_accept_complete(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
{
	PIO_STACK_LOCATION irps = IoGetNextIrpStackLocation(Irp);
	struct accept_param *param = (struct accept_param *)Context;
	NTSTATUS status = STATUS_SUCCESS;

	KdPrint(("[tdi_fw] tdi_evconn_accept_complete: status 0x%x\n", Irp->IoStatus.Status));

    if (Irp->IoStatus.Status == STATUS_SUCCESS) {
		set_tcp_conn_state(param->fileobj, TCP_STATE_ESTABLISHED_IN);

	    // query & update connection local_addr
	    update_conn_info(irps->DeviceObject, param->fileobj);

    } else
		del_tcp_conn(param->fileobj, TRUE);		// TRUE because we logged connection in event handler

	// restore routine and context (and even control!)
	irps->CompletionRoutine = param->old_cr;
	irps->Context = param->old_context;
	irps->Control = param->old_control;

	// call original completion (I like this code :-)

	if (param->old_cr != NULL) {
		// call old completion (see the old control)
		BOOLEAN b_call = FALSE;

		if (Irp->Cancel) {
			// cancel
			if (param->old_control & SL_INVOKE_ON_CANCEL)
				b_call = TRUE;
		} else {
			if (Irp->IoStatus.Status >= STATUS_SUCCESS) {
				// success
				if (param->old_control & SL_INVOKE_ON_SUCCESS)
					b_call = TRUE;
			} else {
				// error
				if (param->old_control & SL_INVOKE_ON_ERROR)
					b_call = TRUE;
			}
		}

		if (b_call)
			status = param->old_cr(DeviceObject, Irp, param->old_context);
	}

	free(param);
	return status;
}
Ejemplo n.º 4
0
NTSTATUS
tdi_connect_complete(IN PDEVICE_OBJECT DeviceObject, IN PIRP Irp, IN PVOID Context)
{
	NTSTATUS status;
	struct flt_request *request = (struct flt_request *)Context;
	PIO_STACK_LOCATION irps = IoGetCurrentIrpStackLocation(Irp);

	KdPrint(("[tdi_fw] tdi_connect_complete: status 0x%x\n", Irp->IoStatus.Status));

	if (Irp->IoStatus.Status == STATUS_SUCCESS) {

		if (request != NULL)
			log_request(request);		// log successful connection
		
		// very good! set connection state to "ESTABLISHED"
		status = set_tcp_conn_state(irps->FileObject, TCP_STATE_ESTABLISHED_OUT);
		if (status != STATUS_SUCCESS) {
			KdPrint(("[tdi_fw] tdi_connect_complete: set_tcp_conn_state: 0x%x!\n", status));

			// set fake status
			Irp->IoStatus.Status = STATUS_REMOTE_NOT_LISTENING;
			// TDI client will close connection object and connection will not "hang" (maybe)
			goto done;
		}

		// and update local address for this connection in state table
		update_conn_info(DeviceObject, irps->FileObject);

	} else {

		if (request != NULL) {

			switch (Irp->IoStatus.Status) {		// are status codes correct?
			case STATUS_CONNECTION_REFUSED:
			case STATUS_CONNECTION_RESET:
				request->type = TYPE_CONNECT_RESET;
				break;
			case STATUS_CONNECTION_ABORTED:
			case STATUS_CANCELLED:
				request->type = TYPE_CONNECT_CANCELED;
				break;
			case STATUS_IO_TIMEOUT:
				request->type = TYPE_CONNECT_TIMEOUT;
				break;
			case STATUS_NETWORK_UNREACHABLE:
			case STATUS_HOST_UNREACHABLE:
			case STATUS_PROTOCOL_UNREACHABLE:
			case STATUS_PORT_UNREACHABLE:
				request->type = TYPE_CONNECT_UNREACH;
				break;
			default:
				request->type = TYPE_CONNECT_ERROR;
			}

			// anyway save status
			request->status = Irp->IoStatus.Status;

			log_request(request);
		}

		del_tcp_conn(irps->FileObject, FALSE);
	}

done:
	if (request != NULL) {
		if (request->sid_a != NULL)
			free(request->sid_a);
		free(request);
	}
	return tdi_generic_complete(DeviceObject, Irp, Context);
}