Exemplo n.º 1
0
/**********************************************************************
 * NAME							EXPORTED
 *	SmCompleteSession/3
 *
 * DESCRIPTION
 * 	This function is called by an environment subsystem server to
 * 	tell the SM it finished initialization phase and is ready to
 * 	manage processes it registered for (SmConnectApiPort).
 *
 * ARGUMENTS
 * 	hSmApiPort: port handle returned by SmConnectApiPort;
 * 	hSbApiPort: call back API port of the subsystem (handle);
 * 	hApiPort  : API port of the subsystem (handle).
 *
 * RETURN VALUE
 * 	Success status as handed by the SM reply; otherwise a failure
 * 	status code.
 */
NTSTATUS WINAPI
SmCompleteSession (IN HANDLE hSmApiPort,
		   IN HANDLE hSbApiPort,
		   IN HANDLE hApiPort)
{
  NTSTATUS         Status;
  SM_PORT_MESSAGE  SmReqMsg;

  DPRINT("SMLIB: %s called\n", __FUNCTION__);

  /* Marshal Ses in the LPC message */
  SmReqMsg.Request.CompSes.hApiPort   = hApiPort;
  SmReqMsg.Request.CompSes.hSbApiPort = hSbApiPort;

  /* SM API to invoke */
  SmReqMsg.SmHeader.ApiIndex = SM_API_COMPLETE_SESSION;

  /* Port message */
  SmReqMsg.Header.u2.s2.Type = LPC_NEW_MESSAGE;
  SmReqMsg.Header.u1.s1.DataLength    = SM_PORT_DATA_SIZE(SmReqMsg.Request);
  SmReqMsg.Header.u1.s1.TotalLength = SM_PORT_MESSAGE_SIZE;
  Status = NtRequestWaitReplyPort (hSmApiPort, (PPORT_MESSAGE) & SmReqMsg, (PPORT_MESSAGE) & SmReqMsg);
  if (NT_SUCCESS(Status))
  {
    return SmReqMsg.SmHeader.Status;
  }
  DPRINT("SMLIB: %s failed (Status=0x%08lx)\n", __FUNCTION__, Status);
  return Status;
}
Exemplo n.º 2
0
NTSTATUS
SampleClient_Api4(
    IN ULONG Longs[4]
    )
/*++

Routine Name:
 
    SampleClient_Api4
 
Description:
 
    Call server api for corresponding client API.
 
Arguments:
 
    ULONG       - Message passed to server.

Return Values:
 
    NTSTATUS    - STATUS_SUCCESS if successful.

--*/
{
    NTSTATUS Status;
    SAMPLE_SERVER_MESSAGE_DISPATCH MessageDispatch;
    PSAMPLE_MESSAGE_4 Arguments = &MessageDispatch.u.SampleServer_Message4;
    
    RtlMoveMemory(&Arguments->Longs, Longs, 4 * 4);
    
    //
    // Fill out the message dispatch structure.
    //
    
    MessageDispatch.Number = 1;
    MessageDispatch.PortMessage.u1.s1.DataLength = sizeof(*Arguments) + 8;
    MessageDispatch.PortMessage.u1.s1.TotalLength = sizeof(MessageDispatch);
    MessageDispatch.PortMessage.u2.ZeroInit = 0;
    
    //
    // Connect and send the message.
    //
    
    Status = NtRequestWaitReplyPort(SampleClient_PortHandle,
                                    (PPORT_MESSAGE)&MessageDispatch,
                                    (PPORT_MESSAGE)&MessageDispatch
                                    );
                                    
    if(NT_SUCCESS(Status)) {
        Status = MessageDispatch.Status;
    } else {
        printf("Client4: NtRequestWaitReplyPort failed with status: 0x%08lx\n",
               Status);
        ExitProcess(1);
    }
    
    return Status;
    
}
Exemplo n.º 3
0
/**********************************************************************
 * NAME							EXPORTED
 *	SmExecuteProgram/2
 *
 * DESCRIPTION
 *	This function is used to make the SM start an environment
 *	subsystem server process.
 *
 * ARGUMENTS
 * 	hSmApiPort: port handle returned by SmConnectApiPort;
 * 	Pgm       : name of the subsystem (to be used by the SM to
 * 	            lookup the image name from the registry).
 * 	            Valid names are: DEBUG, WINDOWS, POSIX, OS2,
 * 	            and VMS.
 *
 * RETURN VALUE
 * 	Success status as handed by the SM reply; otherwise a failure
 * 	status code.
 */
NTSTATUS WINAPI
SmExecuteProgram (IN HANDLE          hSmApiPort,
		  IN PUNICODE_STRING Pgm)
{
  NTSTATUS         Status;
  SM_PORT_MESSAGE  SmReqMsg;


  DPRINT("SMLIB: %s(%08lx,'%S') called\n",
	__FUNCTION__, hSmApiPort, Pgm->Buffer);

  /* Check Pgm's length */
  if (Pgm->Length > (sizeof (Pgm->Buffer[0]) * SM_EXEXPGM_MAX_LENGTH))
  {
    return STATUS_INVALID_PARAMETER;
  }
  /* Marshal Pgm in the LPC message */
  RtlZeroMemory (& SmReqMsg, sizeof SmReqMsg);
  SmReqMsg.Request.ExecPgm.NameLength = Pgm->Length;
  RtlCopyMemory (SmReqMsg.Request.ExecPgm.Name,
		 Pgm->Buffer,
		 Pgm->Length);

  /* SM API to invoke */
  SmReqMsg.SmHeader.ApiIndex = SM_API_EXECUTE_PROGRAMME;

  /* LPC message */
  SmReqMsg.Header.u2.s2.Type = LPC_NEW_MESSAGE;
  SmReqMsg.Header.u1.s1.DataLength    = SM_PORT_DATA_SIZE(SmReqMsg.Request);
  SmReqMsg.Header.u1.s1.TotalLength = SM_PORT_MESSAGE_SIZE;

  DPRINT("SMLIB: %s:\n"
	  "  u2.s2.Type = %d\n"
	  "  u1.s1.DataLength    = %d\n"
	  "  u1.s1.TotalLength = %d\n"
	  "  sizeof(PORT_MESSAGE)==%d\n",
	  __FUNCTION__,
	  SmReqMsg.Header.u2.s2.Type,
	  SmReqMsg.Header.u1.s1.DataLength,
	  SmReqMsg.Header.u1.s1.TotalLength,
	  sizeof(PORT_MESSAGE));

  /* Call SM and wait for a reply */
  Status = NtRequestWaitReplyPort (hSmApiPort, (PPORT_MESSAGE) & SmReqMsg, (PPORT_MESSAGE) & SmReqMsg);
  if (NT_SUCCESS(Status))
  {
    return SmReqMsg.SmHeader.Status;
  }
  DPRINT("SMLIB: %s failed (Status=0x%08lx)\n", __FUNCTION__, Status);
  return Status;
}
Exemplo n.º 4
0
VOID
SepClientMakeRemoteCall( VOID )

{
    PORT_MESSAGE ReplyMessage;

    Status = NtRequestWaitReplyPort(
                 TalkPort,
                 &RequestMessage,
                 &ReplyMessage
                 );

    RequestCount += 1;

    return;
}
Exemplo n.º 5
0
NTSTATUS
NTAPI
SmExecPgm(IN HANDLE SmApiPort,
          IN PRTL_USER_PROCESS_INFORMATION ProcessInformation,
          IN BOOLEAN DebugFlag)
{
    NTSTATUS Status;
    SM_API_MSG SmApiMsg;

#if 0 //def _WIN64 // You can take care of this Timo
    /* 64-bit SMSS needs to talk to 32-bit processes so do the LPC conversion */
    if (SmpIsWow64Process())
    {
        return SmpWow64ExecPgm(SmApiPort, ProcessInformation, DebugFlag);
    }
#endif

    /* Initialize the generic LPC header */
    SmApiMsg.h.u2.ZeroInit = 0;
    SmApiMsg.h.u1.s1.DataLength = sizeof(SM_EXEC_PGM_MSG) + 8;
    SmApiMsg.h.u1.s1.TotalLength = sizeof(SmApiMsg);

    /* Initialize this specific API's parameters */
    SmApiMsg.ApiNumber = SmpExecPgmApi;
    RtlCopyMemory(&SmApiMsg.u.ExecPgm.ProcessInformation,
                  ProcessInformation,
                  sizeof(SmApiMsg.u.ExecPgm.ProcessInformation));
    SmApiMsg.u.ExecPgm.DebugFlag = DebugFlag;

    /* Send the message to SMSS */
    Status = NtRequestWaitReplyPort(SmApiPort, &SmApiMsg.h, &SmApiMsg.h);
    if (!NT_SUCCESS(Status))
    {
        DPRINT1("SmExecPgm: NtRequestWaitReply Failed %lx\n", Status);
    }
    else
    {
        /* Upon success, we use the API's return value */
        Status = SmApiMsg.ReturnValue;
    }

    /* Close the handles that the parent passed in and return status */
    NtClose(ProcessInformation->ProcessHandle);
    NtClose(ProcessInformation->ThreadHandle);
    return Status;
}
Exemplo n.º 6
0
NTSTATUS PhSvcpCallServer(
    _Inout_ PPHSVC_API_MSG Message
    )
{
    NTSTATUS status;

    Message->h.u1.s1.DataLength = sizeof(PHSVC_API_MSG) - FIELD_OFFSET(PHSVC_API_MSG, ApiNumber);
    Message->h.u1.s1.TotalLength = sizeof(PHSVC_API_MSG);
    Message->h.u2.ZeroInit = 0;

    status = NtRequestWaitReplyPort(PhSvcClPortHandle, &Message->h, &Message->h);

    if (!NT_SUCCESS(status))
        return status;

    return Message->ReturnStatus;
}
Exemplo n.º 7
0
/*
 * @implemented
 */
NTSTATUS
NTAPI
LsaEnumerateLogonSessions(
    PULONG LogonSessionCount,
    PLUID *LogonSessionList)
{
    LSA_API_MSG ApiMessage;
    NTSTATUS Status;

    TRACE("LsaEnumerateLogonSessions(%p %p)\n", LogonSessionCount, LogonSessionList);

    Status = LsapOpenLsaPort();
    if (!NT_SUCCESS(Status))
        return Status;

    ApiMessage.ApiNumber = LSASS_REQUEST_ENUM_LOGON_SESSIONS;
    ApiMessage.h.u1.s1.DataLength = LSA_PORT_DATA_SIZE(ApiMessage.EnumLogonSessions);
    ApiMessage.h.u1.s1.TotalLength = LSA_PORT_MESSAGE_SIZE;
    ApiMessage.h.u2.ZeroInit = 0;

    Status = NtRequestWaitReplyPort(LsaPortHandle,
                                    (PPORT_MESSAGE)&ApiMessage,
                                    (PPORT_MESSAGE)&ApiMessage);
    if (!NT_SUCCESS(Status))
    {
        ERR("NtRequestWaitReplyPort() failed (Status 0x%08lx)\n", Status);
        return Status;
    }

    if (!NT_SUCCESS(ApiMessage.Status))
    {
        ERR("NtRequestWaitReplyPort() failed (ApiMessage.Status 0x%08lx)\n", ApiMessage.Status);
        return ApiMessage.Status;
    }

    *LogonSessionCount = ApiMessage.EnumLogonSessions.Reply.LogonSessionCount;
    *LogonSessionList = ApiMessage.EnumLogonSessions.Reply.LogonSessionBuffer;

    return Status;
}
Exemplo n.º 8
0
Arquivo: srm.c Projeto: GYGit/reactos
NTSTATUS
LsapRmDeleteLogonSession(
    PLUID LogonId)
{
    SEP_RM_API_MESSAGE RequestMessage;
    SEP_RM_API_MESSAGE ReplyMessage;
    NTSTATUS Status;

    TRACE("LsapRmDeleteLogonSession(%p)\n", LogonId);

    RequestMessage.Header.u2.ZeroInit = 0;
    RequestMessage.Header.u1.s1.TotalLength =
        (CSHORT)(sizeof(PORT_MESSAGE) + sizeof(ULONG) + sizeof(LUID));
    RequestMessage.Header.u1.s1.DataLength =
        RequestMessage.Header.u1.s1.TotalLength -
        (CSHORT)sizeof(PORT_MESSAGE);

    RequestMessage.ApiNumber = (ULONG)RmDeleteLogonSession;
    RtlCopyLuid(&RequestMessage.u.LogonLuid, LogonId);

    ReplyMessage.Header.u2.ZeroInit = 0;
    ReplyMessage.Header.u1.s1.TotalLength =
        (CSHORT)(sizeof(PORT_MESSAGE) + sizeof(ULONG) + sizeof(NTSTATUS));
    ReplyMessage.Header.u1.s1.DataLength =
        ReplyMessage.Header.u1.s1.TotalLength -
        (CSHORT)sizeof(PORT_MESSAGE);

    ReplyMessage.u.ResultStatus = STATUS_SUCCESS;

    Status = NtRequestWaitReplyPort(SeRmCommandPort,
                                    (PPORT_MESSAGE)&RequestMessage,
                                    (PPORT_MESSAGE)&ReplyMessage);
    if (NT_SUCCESS(Status))
    {
        Status = ReplyMessage.u.ResultStatus;
    }

    return Status;
}
Exemplo n.º 9
0
NTSTATUS
NTAPI
SmSessionComplete(IN HANDLE SmApiPort,
                  IN ULONG SessionId,
                  IN NTSTATUS SessionStatus)
{
    NTSTATUS Status;
    SM_API_MSG ApiMessage;
    PSM_SESSION_COMPLETE_MSG SessionComplete = &ApiMessage.u.SessionComplete;

    /* Set the message data */
    SessionComplete->SessionId = SessionId;
    SessionComplete->SessionStatus = SessionStatus;

    /* Set the API Message Port Message header */
    ApiMessage.ApiNumber = SmpSessionCompleteApi;
    ApiMessage.h.u1.s1.DataLength = sizeof(SM_SESSION_COMPLETE_MSG) + 8;
    ApiMessage.h.u1.s1.TotalLength = sizeof(SM_API_MSG);
    ApiMessage.h.u2.ZeroInit = 0;

    /* Sent the message and wait for a reply */
    Status = NtRequestWaitReplyPort(SmApiPort,
                                    &ApiMessage.h,
                                    &ApiMessage.h);
    if (NT_SUCCESS(Status))
    {
        /* Return the real status */
        Status = ApiMessage.ReturnValue;
    }
    else
    {
        DPRINT1("SmCompleteSession: NtRequestWaitReply failed\n");
    }

    /* Return status */
    return Status;
}
Exemplo n.º 10
0
NTSTATUS SendLpcMessage(PLPC_PORT ClientPort, BYTE *request, WORD requestLength, BYTE *reply, WORD *replyLength)
{
    LPC_MESSAGE reqMsg, repMsg;
    NTSTATUS    status = 0;
    

    memset(&reqMsg, 0, sizeof(reqMsg));
    reqMsg.header.TotalLength = sizeof(reqMsg.header);
    status = NtRequestWaitReplyPort(ClientPort->hPort, (PLPC_MESSAGE_HEADER) &reqMsg, (PLPC_MESSAGE_HEADER) &repMsg);
    log("NtRequest status: %x\n", status);

    /*
    memset(&reqMsg, 0, sizeof(reqMsg));
    reqMsg.header.DataLength = requestLength;
    reqMsg.header.TotalLength = sizeof(reqMsg.header) + requestLength;
    memcpy(reqMsg.data, request, requestLength);

    status = NtRequestWaitReplyPort(ClientPort->hPort, (PLPC_MESSAGE_HEADER) &reqMsg, (PLPC_MESSAGE_HEADER) &repMsg);
    log("NtRequestWaitReplyPort: %x\n", status);
    memcpy(reply, repMsg.data, repMsg.header.DataLength);
    *replyLength = repMsg.header.DataLength;
    */
    return status;
}
Exemplo n.º 11
0
NTSTATUS
DbgUiWaitStateChange (
    OUT PDBGUI_WAIT_STATE_CHANGE StateChange,
    IN PLARGE_INTEGER Timeout OPTIONAL
    )

/*++

Routine Description:

    This function causes the calling user interface to wait for a
    state change to occur in one of it's application threads. The
    wait is ALERTABLE.

Arguments:

    StateChange - Supplies the address of state change record that
        will contain the state change information.

Return Value:

    TBD

--*/

{
    NTSTATUS st;
    DBGUI_APIMSG ApiMsg;
    PDBGUI_WAIT_STATE_CHANGE args;


    //
    // Wait for a StateChange to occur
    //

top:
    st = NtWaitForSingleObject(DbgStateChangeSemaphore,TRUE,Timeout);
    if ( st != STATUS_SUCCESS ) {
        return st;
    }

    //
    // Pick up the state change
    //

    args = &ApiMsg.u.WaitStateChange;

    DBGUI_FORMAT_API_MSG(ApiMsg,DbgUiWaitStateChangeApi,sizeof(*args));
    st = NtRequestWaitReplyPort(
            DbgUiApiPort,
            (PPORT_MESSAGE) &ApiMsg,
            (PPORT_MESSAGE) &ApiMsg
            );

    if ( NT_SUCCESS(st) ) {
        if ( ApiMsg.ReturnedStatus == DBG_NO_STATE_CHANGE ) {
            DbgPrint("DBGUISTB: Waring No State Change\n");
            goto top;
        }
        *StateChange = *args;
        return ApiMsg.ReturnedStatus;
    } else {
        DbgPrint("NTDLL: DbgUiWaitStateChange failing with status %x\n", st);
        return st;
    }
}
Exemplo n.º 12
0
NTSTATUS
DbgUiContinue (
    IN PCLIENT_ID AppClientId,
    IN NTSTATUS ContinueStatus
    )

/*++

Routine Description:

    This function continues an application thread whose state change was
    previously reported through DbgUiWaitStateChange.

Arguments:

    AppClientId - Supplies the address of the ClientId of the
        application thread being continued.  This must be an application
        thread that previously notified the caller through
        DbgUiWaitStateChange but has not yet been continued.

    ContinueStatus - Supplies the continuation status to the thread
        being continued.  valid values for this are:

        DBG_EXCEPTION_HANDLED
        DBG_EXCEPTION_NOT_HANDLED
        DBG_TERMINATE_THREAD
        DBG_TERMINATE_PROCESS
        DBG_CONTINUE

Return Value:

    STATUS_SUCCESS - Successful call to DbgUiContinue

    STATUS_INVALID_CID - An invalid ClientId was specified for the
        AppClientId, or the specified Application was not waiting
        for a continue.

    STATUS_INVALID_PARAMETER - An invalid continue status was specified.

--*/

{
    NTSTATUS st;
    DBGUI_APIMSG ApiMsg;
    PDBGUI_CONTINUE args;


    args = &ApiMsg.u.Continue;
    args->AppClientId = *AppClientId;
    args->ContinueStatus = ContinueStatus;

    DBGUI_FORMAT_API_MSG(ApiMsg,DbgUiContinueApi,sizeof(*args));

    st = NtRequestWaitReplyPort(
            DbgUiApiPort,
            (PPORT_MESSAGE) &ApiMsg,
            (PPORT_MESSAGE) &ApiMsg
            );

    if ( NT_SUCCESS(st) ) {
        if ( !(NT_SUCCESS(ApiMsg.ReturnedStatus))) {
            DbgPrint("NTDLL: DbgUiContinue success with status %x\n", ApiMsg.ReturnedStatus);
        }
        return ApiMsg.ReturnedStatus;
    } else {
        DbgPrint("NTDLL: DbgUiContinue failing with status %x\n", st);
        return st;
    }
}
Exemplo n.º 13
0
/**********************************************************************
 * NAME							EXPORTED
 *	SmQueryInformation/5
 *
 * DESCRIPTION
 *	Ask the SM to collect some data from its internal data
 *	structures and send it back.
 *
 * ARGUMENTS
 *	hSmApiPort: handle returned by SmConnectApiPort;
 *	SmInformationClass: an SM information class ID:
 *		SM_BASIC_INFORMATION: the number of registered subsystems
 *	Data: pointer to storage for the information to request;
 *	DataLength: length in bytes of the Data buffer; it must be
 *		set and must match the SmInformationClass info size;
 *	ReturnedDataLength: optional pointer to storage to receive
 *		the size of the returnede data.
 *
 * RETURN VALUE
 * 	STATUS_SUCCESS: OK you get what you asked for;
 * 	STATUS_INFO_LENGTH_MISMATCH: you set DataLength to 0 or to a
 * 		value that does not match whet the SmInformationClass
 * 		requires;
 * 	STATUS_INVALID_PARAMETER_2: bad information class;
 * 	A port error.
 *
 */
NTSTATUS WINAPI
SmQueryInformation (IN      HANDLE                hSmApiPort,
		    IN      SM_INFORMATION_CLASS  SmInformationClass,
		    IN OUT  PVOID                 Data,
		    IN      ULONG                 DataLength,
		    IN OUT  PULONG                ReturnedDataLength OPTIONAL)
{
	NTSTATUS         Status = STATUS_SUCCESS;
	SM_PORT_MESSAGE  SmReqMsg;


	if(0 == DataLength)
	{
		return STATUS_INFO_LENGTH_MISMATCH;
	}
	/* Marshal data in the port message */
	switch (SmInformationClass)
	{
		case SmBasicInformation:
			if(DataLength != sizeof (SM_BASIC_INFORMATION))
			{
				return STATUS_INFO_LENGTH_MISMATCH;
			}
			SmReqMsg.Request.QryInfo.SmInformationClass = SmBasicInformation;
			SmReqMsg.Request.QryInfo.DataLength = DataLength;
			SmReqMsg.Request.QryInfo.BasicInformation.SubSystemCount = 0;
			break;
		case SmSubSystemInformation:
			if(DataLength != sizeof (SM_SUBSYSTEM_INFORMATION))
			{
				return STATUS_INFO_LENGTH_MISMATCH;
			}
			SmReqMsg.Request.QryInfo.SmInformationClass = SmSubSystemInformation;
			SmReqMsg.Request.QryInfo.DataLength = DataLength;
			SmReqMsg.Request.QryInfo.SubSystemInformation.SubSystemId =
				((PSM_SUBSYSTEM_INFORMATION)Data)->SubSystemId;
			break;
		default:
			return STATUS_INVALID_PARAMETER_2;
	}
	/* SM API to invoke */
	SmReqMsg.SmHeader.ApiIndex = SM_API_QUERY_INFORMATION;

	/* Prepare the port request message */
	SmReqMsg.Header.u2.s2.Type = LPC_NEW_MESSAGE;
	SmReqMsg.Header.u1.s1.DataLength    = SM_PORT_DATA_SIZE(SmReqMsg.Request);
	SmReqMsg.Header.u1.s1.TotalLength = SM_PORT_MESSAGE_SIZE;
	Status = NtRequestWaitReplyPort (hSmApiPort, (PPORT_MESSAGE) & SmReqMsg, (PPORT_MESSAGE) & SmReqMsg);
	if (NT_SUCCESS(Status))
	{
		/* Unmarshal data */
		RtlCopyMemory (Data, & SmReqMsg.Reply.QryInfo.BasicInformation, SmReqMsg.Reply.QryInfo.DataLength);
		/* Use caller provided storage to store data size */
		if(NULL != ReturnedDataLength)
		{
			*ReturnedDataLength = SmReqMsg.Reply.QryInfo.DataLength;
		}
		return SmReqMsg.SmHeader.Status;
	}
	DPRINT("SMLIB: %s failed (Status=0x%08lx)\n", __FUNCTION__, Status);
	return Status;
}
Exemplo n.º 14
0
NTSTATUS
CsrClientCallServer(
    IN OUT PCSR_API_MSG m,
    IN OUT PCSR_CAPTURE_HEADER CaptureBuffer OPTIONAL,
    IN CSR_API_NUMBER ApiNumber,
    IN ULONG ArgLength
    )

/*++

Routine Description:

    This function sends an API request to the Windows Emulation Subsystem
    Server and waits for a reply.

Arguments:

    m - Pointer to the API request message to send.

    CaptureBuffer - Optional pointer to a capture buffer located in the
        Port Memory section that contains additional data being sent
        to the server.  Since Port Memory is also visible to the server,
        no data needs to be copied, but pointers to locations within the
        capture buffer need to be converted into pointers valid in the
        server's process context, since the server's view of the Port Memory
        is not at the same virtual address as the client's view.

    ApiNumber - Small integer that is the number of the API being called.

    ArgLength - Length, in bytes, of the argument portion located at the
        end of the request message.  Used to calculate the length of the
        request message.

Return Value:

    Status Code from either client or server

--*/

{
    NTSTATUS Status;
    PULONG_PTR PointerOffsets;
    ULONG CountPointers;
    ULONG_PTR Pointer;

    //
    // Initialize the header of the message.
    //

    if ((LONG)ArgLength < 0) {
        ArgLength = (ULONG)(-(LONG)ArgLength);
        m->h.u2.s2.Type = 0;
        }
    else {
        m->h.u2.ZeroInit = 0;
        }

    ArgLength |= (ArgLength << 16);
    ArgLength +=     ((sizeof( CSR_API_MSG ) - sizeof( m->u )) << 16) |
                     (FIELD_OFFSET( CSR_API_MSG, u ) - sizeof( m->h ));
    m->h.u1.Length = ArgLength;
    m->CaptureBuffer = NULL;
    m->ApiNumber = ApiNumber;

    //
    // if the caller is within the server process, do the API call directly
    // and skip the capture buffer fixups and LPC call.
    //

    if (CsrServerProcess == FALSE) {

        //
        // If the CaptureBuffer argument is present, then there is data located
        // in the Port Memory section that is being passed to the server.  All
        // Port Memory pointers need to be converted so they are valid in the
        // Server's view of the Port Memory.
        //

        if (ARGUMENT_PRESENT( CaptureBuffer )) {
            //
            // Store a pointer to the capture buffer in the message that is valid
            // in the server process's context.
            //

            m->CaptureBuffer = (PCSR_CAPTURE_HEADER)
                ((PCHAR)CaptureBuffer + CsrPortMemoryRemoteDelta);

            //
            // Mark the fact that we are done allocating space from the end of
            // the capture buffer.
            //

            CaptureBuffer->FreeSpace = NULL;

            //
            // Loop over all of the pointers to Port Memory within the message
            // itself and convert them into server pointers.  Also, convert
            // the pointers to pointers into offsets.
            //

            PointerOffsets = CaptureBuffer->MessagePointerOffsets;
            CountPointers = CaptureBuffer->CountMessagePointers;
            while (CountPointers--) {
                Pointer = *PointerOffsets++;
                if (Pointer != 0) {
                    *(PULONG_PTR)Pointer += CsrPortMemoryRemoteDelta;
                    PointerOffsets[ -1 ] = Pointer - (ULONG_PTR)m;
                    }
                }
            }

        //
        // Send the request to the server and wait for a reply.  The wait is
        // NOT alertable, because ? FIX,FIX
        //

        Status = NtRequestWaitReplyPort( CsrPortHandle,
                                         (PPORT_MESSAGE)m,
                                         (PPORT_MESSAGE)m
                                       );
        //
        // If the CaptureBuffer argument is present then reverse what we did
        // to the pointers above so that the client side code can use them
        // again.
        //

        if (ARGUMENT_PRESENT( CaptureBuffer )) {
            //
            // Convert the capture buffer pointer back to a client pointer.
            //

            m->CaptureBuffer = (PCSR_CAPTURE_HEADER)
                ((PCHAR)m->CaptureBuffer - CsrPortMemoryRemoteDelta);

            //
            // Loop over all of the pointers to Port Memory within the message
            // itself and convert them into client pointers.  Also, convert
            // the offsets pointers to pointers into back into pointers
            //

            PointerOffsets = CaptureBuffer->MessagePointerOffsets;
            CountPointers = CaptureBuffer->CountMessagePointers;
            while (CountPointers--) {
                Pointer = *PointerOffsets++;
                if (Pointer != 0) {
                    Pointer += (ULONG_PTR)m;
                    PointerOffsets[ -1 ] = Pointer;
                    *(PULONG_PTR)Pointer -= CsrPortMemoryRemoteDelta;
                    }
                }
            }

        //
        // Check for failed status and do something.
        //
        if (!NT_SUCCESS( Status )) {
            IF_DEBUG {
                if (Status != STATUS_PORT_DISCONNECTED &&
                    Status != STATUS_INVALID_HANDLE
                   ) {
                    DbgPrint( "CSRDLL: NtRequestWaitReplyPort failed - Status == %X\n",
                              Status
                            );
                    }
                }

            m->ReturnValue = Status;
            }
        }
Exemplo n.º 15
0
/*
 * @unimplemented
 */
NTSTATUS
NTAPI
LsaGetLogonSessionData(
    PLUID LogonId,
    PSECURITY_LOGON_SESSION_DATA *ppLogonSessionData)
{
    LSA_API_MSG ApiMessage;
    PSECURITY_LOGON_SESSION_DATA SessionData;
    NTSTATUS Status;

    TRACE("LsaGetLogonSessionData(%p %p)\n", LogonId, ppLogonSessionData);

    Status = LsapOpenLsaPort();
    if (!NT_SUCCESS(Status))
        return Status;

    ApiMessage.ApiNumber = LSASS_REQUEST_GET_LOGON_SESSION_DATA;
    ApiMessage.h.u1.s1.DataLength = LSA_PORT_DATA_SIZE(ApiMessage.GetLogonSessionData);
    ApiMessage.h.u1.s1.TotalLength = LSA_PORT_MESSAGE_SIZE;
    ApiMessage.h.u2.ZeroInit = 0;

    RtlCopyLuid(&ApiMessage.GetLogonSessionData.Request.LogonId,
                LogonId);

    Status = NtRequestWaitReplyPort(LsaPortHandle,
                                    (PPORT_MESSAGE)&ApiMessage,
                                    (PPORT_MESSAGE)&ApiMessage);
    if (!NT_SUCCESS(Status))
    {
        ERR("NtRequestWaitReplyPort() failed (Status 0x%08lx)\n", Status);
        return Status;
    }

    if (!NT_SUCCESS(ApiMessage.Status))
    {
        ERR("NtRequestWaitReplyPort() failed (ApiMessage.Status 0x%08lx)\n", ApiMessage.Status);
        return ApiMessage.Status;
    }

    SessionData = ApiMessage.GetLogonSessionData.Reply.SessionDataBuffer;

    TRACE("UserName: %p\n", SessionData->UserName.Buffer);
    if (SessionData->UserName.Buffer != NULL)
        SessionData->UserName.Buffer = (LPWSTR)((ULONG_PTR)SessionData + (ULONG_PTR)SessionData->UserName.Buffer);

    TRACE("LogonDomain: %p\n", SessionData->LogonDomain.Buffer);
    if (SessionData->LogonDomain.Buffer != NULL)
        SessionData->LogonDomain.Buffer = (LPWSTR)((ULONG_PTR)SessionData + (ULONG_PTR)SessionData->LogonDomain.Buffer);

    TRACE("AuthenticationPackage: %p\n", SessionData->AuthenticationPackage.Buffer);
    if (SessionData->AuthenticationPackage.Buffer != NULL)
        SessionData->AuthenticationPackage.Buffer = (LPWSTR)((ULONG_PTR)SessionData + (ULONG_PTR)SessionData->AuthenticationPackage.Buffer);

    TRACE("Sid: %p\n", SessionData->Sid);
    if (SessionData->Sid != NULL)
        SessionData->Sid = (LPWSTR)((ULONG_PTR)SessionData + (ULONG_PTR)SessionData->Sid);

    TRACE("LogonServer: %p\n", SessionData->LogonServer.Buffer);
    if (SessionData->LogonServer.Buffer != NULL)
        SessionData->LogonServer.Buffer = (LPWSTR)((ULONG_PTR)SessionData + (ULONG_PTR)SessionData->LogonServer.Buffer);

    TRACE("DnsDomainName: %p\n", SessionData->DnsDomainName.Buffer);
    if (SessionData->DnsDomainName.Buffer != NULL)
        SessionData->DnsDomainName.Buffer = (LPWSTR)((ULONG_PTR)SessionData + (ULONG_PTR)SessionData->DnsDomainName.Buffer);

    TRACE("Upn: %p\n", SessionData->Upn.Buffer);
    if (SessionData->Upn.Buffer != NULL)
        SessionData->Upn.Buffer = (LPWSTR)((ULONG_PTR)SessionData + (ULONG_PTR)SessionData->Upn.Buffer);

    *ppLogonSessionData = SessionData;

    return Status;
}
Exemplo n.º 16
0
NTSTATUS
NTAPI
SmpSbCreateSession(IN PVOID Reserved,
                   IN PSMP_SUBSYSTEM OtherSubsystem,
                   IN PRTL_USER_PROCESS_INFORMATION ProcessInformation,
                   IN ULONG MuSessionId,
                   IN PCLIENT_ID DbgClientId)
{
    NTSTATUS Status;
    PSMP_SUBSYSTEM KnownSubsys;
    SB_API_MSG SbApiMsg;
    ULONG SessionId;
    PSB_CREATE_SESSION_MSG CreateSessionMsg;

    /* Write out the create session message including its initial process */
    CreateSessionMsg = &SbApiMsg.CreateSession;
    CreateSessionMsg->ProcessInfo = *ProcessInformation;
    CreateSessionMsg->MuSessionId = MuSessionId;
    if (DbgClientId)
    {
        CreateSessionMsg->ClientId = *DbgClientId;
    }
    else
    {
        CreateSessionMsg->ClientId.UniqueThread = NULL;
        CreateSessionMsg->ClientId.UniqueProcess = NULL;
    }

    /* Find a subsystem responsible for this session */
    SmpGetProcessMuSessionId(ProcessInformation->ProcessHandle, &MuSessionId);
    if (!SmpCheckDuplicateMuSessionId(MuSessionId))
    {
        NtClose(ProcessInformation->ProcessHandle);
        NtClose(ProcessInformation->ThreadHandle);
        DPRINT1("SMSS: CreateSession status=%x\n", STATUS_OBJECT_NAME_NOT_FOUND);
        return STATUS_OBJECT_NAME_NOT_FOUND;
    }

    /* Find the subsystem we have for this initial process */
    KnownSubsys = SmpLocateKnownSubSysByType(MuSessionId,
                                             ProcessInformation->
                                             ImageInformation.SubSystemType);
    if (KnownSubsys)
    {
        /* Duplicate the process handle into the message */
        Status = NtDuplicateObject(NtCurrentProcess(),
                                   ProcessInformation->ProcessHandle,
                                   KnownSubsys->ProcessHandle,
                                   &CreateSessionMsg->ProcessInfo.ProcessHandle,
                                   PROCESS_ALL_ACCESS,
                                   0,
                                   0);
        if (NT_SUCCESS(Status))
        {
            /* Duplicate the thread handle into the message */
            Status = NtDuplicateObject(NtCurrentProcess(),
                                       ProcessInformation->ThreadHandle,
                                       KnownSubsys->ProcessHandle,
                                       &CreateSessionMsg->ProcessInfo.ThreadHandle,
                                       THREAD_ALL_ACCESS,
                                       0,
                                       0);
            if (!NT_SUCCESS(Status))
            {
                /* Close everything on failure */
                NtClose(ProcessInformation->ProcessHandle);
                NtClose(ProcessInformation->ThreadHandle);
                SmpDereferenceSubsystem(KnownSubsys);
                DbgPrint("SmpSbCreateSession: NtDuplicateObject (Thread) Failed %lx\n", Status);
                return Status;
            }

            /* Close the original handles as they are no longer needed */
            NtClose(ProcessInformation->ProcessHandle);
            NtClose(ProcessInformation->ThreadHandle);

            /* Finally, allocate a new SMSS session ID for this session */
            SessionId = SmpAllocateSessionId(KnownSubsys, OtherSubsystem);
            CreateSessionMsg->SessionId = SessionId;

            /* Fill out the LPC message header and send it to the client! */
            SbApiMsg.ApiNumber = SbpCreateSession;
            SbApiMsg.h.u2.ZeroInit = 0;
            SbApiMsg.h.u1.s1.DataLength = sizeof(SB_CREATE_SESSION_MSG) + 8;
            SbApiMsg.h.u1.s1.TotalLength = sizeof(SbApiMsg);
            Status = NtRequestWaitReplyPort(KnownSubsys->SbApiPort,
                                            &SbApiMsg.h,
                                            &SbApiMsg.h);
            if (!NT_SUCCESS(Status))
            {
                /* Bail out */
                DPRINT1("SmpSbCreateSession: NtRequestWaitReply Failed %lx\n", Status);
            }
            else
            {
                /* If the API succeeded, get the result value from the LPC */
                Status = SbApiMsg.ReturnValue;
            }

            /* Delete the session on any kind of failure */
            if (!NT_SUCCESS(Status)) SmpDeleteSession(SessionId);
        }
        else
        {
            /* Close the handles on failure */
            DPRINT1("SmpSbCreateSession: NtDuplicateObject (Process) Failed %lx\n", Status);
            NtClose(ProcessInformation->ProcessHandle);
            NtClose(ProcessInformation->ThreadHandle);
        }

        /* Dereference the subsystem and return the status of the LPC call */
        SmpDereferenceSubsystem(KnownSubsys);
        return Status;
    }

    /* If we don't yet have a subsystem, only native images can be launched */
    if (ProcessInformation->ImageInformation.SubSystemType != IMAGE_SUBSYSTEM_NATIVE)
    {
        /* Fail */
        DPRINT1("SMSS: %s SubSystem has not been started.\n",
                SmpSubSystemNames[ProcessInformation->ImageInformation.SubSystemType]);
        Status = STATUS_UNSUCCESSFUL;
        NtClose(ProcessInformation->ProcessHandle);
        NtClose(ProcessInformation->ThreadHandle);
        return Status;
    }

#if 0
    /* This code handles debug applications, but it seems vestigial... */
    if ((*(ULONGLONG)&CreateSessionMsg.ClientId) && (SmpDbgSsLoaded))
    {
        Process = RtlAllocateHeap(SmpHeap, SmBaseTag, sizeof(SMP_PROCESS));
        if (!Process)
        {
            DPRINT1("Unable to initialize debugging for Native App %lx.%lx -- out of memory\n",
                    ProcessInformation->ClientId.UniqueProcess,
                    ProcessInformation->ClientId.UniqueThread);
            NtClose(ProcessInformation->ProcessHandle);
            NtClose(ProcessInformation->ThreadHandle);
            return STATUS_NO_MEMORY;
        }

        Process->DbgClientId = CreateSessionMsg->ClientId;
        Process->ClientId = ProcessInformation->ClientId;
        InsertHeadList(&NativeProcessList, &Process->Entry);
        DPRINT1("Native Debug App %lx.%lx\n", Process->ClientId.UniqueProcess, Process->ClientId.UniqueThread);

        Status = NtSetInformationProcess(ProcessInformation->ProcessHandle, 7, &SmpDebugPort, 4);
        ASSERT(NT_SUCCESS(Status));
    }
#endif

    /* This is a native application being started as the initial command */
    DPRINT1("Subsystem active, starting thread\n");
    NtClose(ProcessInformation->ProcessHandle);
    NtResumeThread(ProcessInformation->ThreadHandle, NULL);
    NtClose(ProcessInformation->ThreadHandle);
    return STATUS_SUCCESS;
}