コード例 #1
0
ファイル: smb2.c プロジェクト: FarazShaikh/LikewiseSMB2
NTSTATUS
RdrSmb2EncodeSessionSetupRequest(
    PSMB_PACKET pPacket,
    PBYTE* ppCursor,
    PULONG pulRemaining,
    BOOLEAN bSigningEnabled,
    BOOLEAN bSigningRequired,
    BOOLEAN bDfsEnabled,
    PBYTE pBlob,
    ULONG ulBlobLength
    )
{
    NTSTATUS status = STATUS_SUCCESS;
    PRDR_SMB2_SESSION_SETUP_REQUEST_HEADER pHeader = NULL;

    pHeader = (PRDR_SMB2_SESSION_SETUP_REQUEST_HEADER) *ppCursor;
    /* Advance cursor past header to ensure buffer space */
    status = Advance(ppCursor, pulRemaining, sizeof(*pHeader));
    BAIL_ON_NT_STATUS(status);

    pHeader->usLength = SMB_HTOL16(sizeof(*pHeader) | 0x1);
    pHeader->ucVcNumber = 0;
    pHeader->ucSecurityMode =
        (bSigningEnabled ? RDR_SMB2_SECMODE_SIGNING_ENABLED : 0) |
        (bSigningRequired ? RDR_SMB2_SECMODE_SIGNING_REQUIRED : 0);
    pHeader->ulCapabilities = bDfsEnabled ? RDR_SMB2_CAP_DFS : 0;
    pHeader->ulChannel = SMB_HTOL32(0);
    pHeader->usBlobLength = SMB_HTOL16((USHORT) ulBlobLength);
    pHeader->ullPrevSessionId = SMB_HTOL32(0);

    /* Fill in offset field */
    pHeader->usBlobOffset = SMB_HTOL16((USHORT) PACKET_HEADER_OFFSET(pPacket, *ppCursor));

    /* Fill in blob */
    status = MarshalData(ppCursor, pulRemaining, pBlob, ulBlobLength);
    BAIL_ON_NT_STATUS(status);

cleanup:

    return status;

error:

    goto cleanup;
}
コード例 #2
0
ファイル: ioc.c プロジェクト: jamjr/Helios-NG
PUBLIC Object *
Create(
       Object *	object,
       string	name,
       word	type,
       word	size,
       byte *	data )
{
	word rc = Err_Null;
	Object *obj = Null(Object);
	MCB *mcb;
	IOCReply1 *rep;
	word oblen;
	Port reply;

#ifdef SYSDEB
	SysDebug(ioc)("Create(%O,%N,%T,%d,%P)",object,name,type,size,data);
#endif

	if ( CheckObject(object,C_Locate) != Err_Null )
	  {
	    return NULL;
	  }

	reply = NewPort();

	mcb = NewMsgBuf(0);
	rep = (IOCReply1 *)mcb->Control;
	
	InitMCB(mcb,MsgHdr_Flags_preserve,
		MyTask->IOCPort,reply,FC_GSP|FG_Create|object->FnMod);

	MarshalCommon(mcb,object,name);

	MarshalWord(mcb,type);
	MarshalWord(mcb,size);
	MarshalOffset(mcb);
	MarshalData(mcb,size,data);

	mcb->Timeout = object->Timeout;
	
	/* IOdebug( "Create: sending message" ); */
	
	if ( (rc = IOCMsg(mcb, NULL)) < Err_Null )
	  {
	    /* IOdebug( "Create: message send failed" ); */
	    
	    goto Done;
	  }
	
	/* IOdebug( "Create: message sent" ); */
	
	oblen = sizeof(Object) + (word)strlen(mcb->Data+rep->Pathname) + SafetyMargin;

	obj = (Object *)Malloc(oblen);
	
	if ( obj == NULL )
	  {
	    rc = EC_Error|SS_SysLib|EG_NoMemory|EO_Object;
		
	    goto Done;
	  }	
	else memclr( (void *)obj, (int)oblen );

	obj->Type    = rep->Type;
	obj->Flags   = rep->Flags;
	obj->Access  = rep->Access;
	obj->Reply   = reply;
	obj->FnMod   = rc & SS_Mask;
	obj->Timeout = IOCTimeout;
	
	strcpy(obj->Name,mcb->Data+rep->Pathname);

	AddObject( obj );

	rc = Err_Null;

    Done:
#ifdef SYSDEB
	SysDebug(ioc)("Create: %E object: %O",rc,obj);
	if( mcb->MsgHdr.Reply != NullPort ) SysDebug(error)("Create: Non-Null Reply port %x",mcb->MsgHdr.Reply);
#endif
	if( mcb->MsgHdr.Reply != NullPort ) FreePort(mcb->MsgHdr.Reply);

	FreeMsgBuf(mcb);

	if( rc < Err_Null ) FreePort(reply);

	object->Result2 = rc;
	
	return obj;	
}
コード例 #3
0
ファイル: setinfo.c プロジェクト: bhanug/likewise-open
static
NTSTATUS
RdrTransceiveSetPathInfo(
    PRDR_OP_CONTEXT pContext,
    PRDR_CCB pFile,
    SMB_INFO_LEVEL infoLevel,
    PVOID pInfo,
    ULONG ulInfoLength
    )
{
    NTSTATUS status = STATUS_SUCCESS;
    TRANSACTION_REQUEST_HEADER *pHeader = NULL;
    USHORT usSetup = SMB_SUB_COMMAND_TRANS2_SET_PATH_INFORMATION;
    SMB_SET_PATH_INFO_HEADER setHeader = {0};
    PBYTE pRequestParameters = NULL;
    PBYTE pRequestData = NULL;
    USHORT usRequestDataCount = 0;
    PBYTE pCursor = NULL;
    ULONG ulRemainingSpace = 0;
    PBYTE pByteCount = NULL;
    PWSTR pwszPath = infoLevel != SMB_SET_FILE_RENAME_INFO ? RDR_CCB_PATH(pFile) : pFile->pwszPath;
    PBYTE pFileName = NULL;

    status = RdrAllocateContextPacket(pContext, 1024*64);
    BAIL_ON_NT_STATUS(status);

    status = SMBPacketMarshallHeader(
        pContext->Packet.pRawBuffer,
        pContext->Packet.bufferLen,
        COM_TRANSACTION2,
        0,
        0,
        pFile->pTree->tid,
        gRdrRuntime.SysPid,
        pFile->pTree->pSession->uid,
        0,
        TRUE,
        &pContext->Packet);
    BAIL_ON_NT_STATUS(status);

    /* Don't use DFS paths for FILE_RENAME_INFO -- it doesn't work */
    if (RDR_CCB_IS_DFS(pFile) && infoLevel != SMB_SET_FILE_RENAME_INFO)
    {
        pContext->Packet.pSMBHeader->flags2 |= FLAG2_DFS;
    }

    pContext->Packet.pData = pContext->Packet.pParams + sizeof(TRANSACTION_REQUEST_HEADER);

    pCursor = pContext->Packet.pParams;
    ulRemainingSpace = pContext->Packet.bufferLen - (pCursor - pContext->Packet.pRawBuffer);

    status = WireMarshalTrans2RequestSetup(
        pContext->Packet.pSMBHeader,
        &pCursor,
        &ulRemainingSpace,
        &usSetup,
        1,
        &pHeader,
        &pByteCount);
    BAIL_ON_NT_STATUS(status);

    pRequestParameters = pCursor;

    setHeader.infoLevel = SMB_HTOL16(infoLevel);
    setHeader.reserved = 0;

    status = MarshalData(&pCursor, &ulRemainingSpace, (PBYTE) &setHeader, sizeof(setHeader));
    BAIL_ON_NT_STATUS(status);

    status = Align((PBYTE) pContext->Packet.pSMBHeader, &pCursor, &ulRemainingSpace, sizeof(WCHAR));
    BAIL_ON_NT_STATUS(status);

    pFileName = pCursor;

    status = Advance(&pCursor, &ulRemainingSpace, (LwRtlWC16StringNumChars(pwszPath) + 1) * sizeof(WCHAR));
    BAIL_ON_NT_STATUS(status);

    SMB_HTOLWSTR(
        pFileName,
        pwszPath,
        LwRtlWC16StringNumChars(pwszPath) + 1);

    pRequestData = pCursor;

    status = RdrMarshalFileInfo(
        pContext->Packet.pSMBHeader,
        &pCursor,
        &ulRemainingSpace,
        infoLevel,
        pInfo,
        ulInfoLength);
    BAIL_ON_NT_STATUS(status);

    usRequestDataCount = pCursor - pRequestData;

    pHeader->totalParameterCount = SMB_HTOL16(pRequestData - pRequestParameters);
    pHeader->totalDataCount      = SMB_HTOL16(usRequestDataCount);
    pHeader->maxParameterCount   = SMB_HTOL16(sizeof(setHeader));
    pHeader->maxDataCount        = SMB_HTOL16(0);
    pHeader->maxSetupCount       = SMB_HTOL16(0);
    pHeader->flags               = SMB_HTOL16(0);
    pHeader->timeout             = SMB_HTOL16(0);
    pHeader->parameterCount      = SMB_HTOL16(pRequestData - pRequestParameters);
    pHeader->parameterOffset     = SMB_HTOL16(pRequestParameters - (PBYTE) pContext->Packet.pSMBHeader);
    pHeader->dataCount           = SMB_HTOL16(usRequestDataCount);
    pHeader->dataOffset          = SMB_HTOL16(pRequestData - (PBYTE) pContext->Packet.pSMBHeader);
    pHeader->setupCount          = SMB_HTOL8(1);

    /* Update byte count */
    status = MarshalUshort(&pByteCount, NULL, (pCursor - pByteCount) - 2);

    /* Update used length */
    pContext->Packet.bufferUsed += (pCursor - pContext->Packet.pParams);

    status = SMBPacketMarshallFooter(&pContext->Packet);
    BAIL_ON_NT_STATUS(status);

    status = RdrSocketTransceive(pFile->pTree->pSession->pSocket, pContext);
    BAIL_ON_NT_STATUS(status);

cleanup:

    return status;

error:

    goto cleanup;
}
コード例 #4
0
ファイル: setinfo.c プロジェクト: bhanug/likewise-open
static
NTSTATUS
RdrTransceiveSetFileInfo(
    PRDR_OP_CONTEXT pContext,
    PRDR_CCB pFile,
    SMB_INFO_LEVEL infoLevel,
    PVOID pInfo,
    ULONG ulInfoLength
    )
{
    NTSTATUS status = STATUS_SUCCESS;
    TRANSACTION_REQUEST_HEADER *pHeader = NULL;
    USHORT usSetup = SMB_SUB_COMMAND_TRANS2_SET_FILE_INFORMATION;
    SMB_SET_FILE_INFO_HEADER setHeader = {0};
    PBYTE pRequestParameters = NULL;
    PBYTE pRequestData = NULL;
    USHORT usRequestDataCount = 0;
    PBYTE pCursor = NULL;
    ULONG ulRemainingSpace = 0;
    PBYTE pByteCount = NULL;

    status = RdrAllocateContextPacket(pContext, 1024*64);
    BAIL_ON_NT_STATUS(status);

    status = SMBPacketMarshallHeader(
        pContext->Packet.pRawBuffer,
        pContext->Packet.bufferLen,
        COM_TRANSACTION2,
        0,
        0,
        pFile->pTree->tid,
        gRdrRuntime.SysPid,
        pFile->pTree->pSession->uid,
        0,
        TRUE,
        &pContext->Packet);
    BAIL_ON_NT_STATUS(status);

    pContext->Packet.pData = pContext->Packet.pParams + sizeof(TRANSACTION_REQUEST_HEADER);

    pCursor = pContext->Packet.pParams;
    ulRemainingSpace = pContext->Packet.bufferLen - (pCursor - pContext->Packet.pRawBuffer);

    status = WireMarshalTrans2RequestSetup(
        pContext->Packet.pSMBHeader,
        &pCursor,
        &ulRemainingSpace,
        &usSetup,
        1,
        &pHeader,
        &pByteCount);
    BAIL_ON_NT_STATUS(status);

    pRequestParameters = pCursor;

    setHeader.usFid = pFile->fid;
    setHeader.infoLevel = infoLevel;

    status = MarshalData(&pCursor, &ulRemainingSpace, (PBYTE) &setHeader, sizeof(setHeader));
    BAIL_ON_NT_STATUS(status);

    pRequestData = pCursor;

    status = RdrMarshalFileInfo(
        pContext->Packet.pSMBHeader,
        &pCursor,
        &ulRemainingSpace,
        infoLevel,
        pInfo,
        ulInfoLength);
    BAIL_ON_NT_STATUS(status);

    usRequestDataCount = pCursor - pRequestData;

    pHeader->totalParameterCount = SMB_HTOL16(sizeof(setHeader));
    pHeader->totalDataCount      = SMB_HTOL16(usRequestDataCount);
    pHeader->maxParameterCount   = SMB_HTOL16(sizeof(setHeader));
    pHeader->maxDataCount        = SMB_HTOL16(0);
    pHeader->maxSetupCount       = SMB_HTOL16(0);
    pHeader->flags               = SMB_HTOL16(0);
    pHeader->timeout             = SMB_HTOL16(0);
    pHeader->parameterCount      = SMB_HTOL16(sizeof(setHeader));
    pHeader->parameterOffset     = SMB_HTOL16(pRequestParameters - (PBYTE) pContext->Packet.pSMBHeader);
    pHeader->dataCount           = SMB_HTOL16(usRequestDataCount);
    pHeader->dataOffset          = SMB_HTOL16(pRequestData - (PBYTE) pContext->Packet.pSMBHeader);
    pHeader->setupCount          = SMB_HTOL8(1);

    /* Update byte count */
    status = MarshalUshort(&pByteCount, NULL, (pCursor - pByteCount) - 2);

    /* Update used length */
    pContext->Packet.bufferUsed += (pCursor - pContext->Packet.pParams);

    status = SMBPacketMarshallFooter(&pContext->Packet);
    BAIL_ON_NT_STATUS(status);

    status = RdrSocketTransceive(pFile->pTree->pSession->pSocket, pContext);
    BAIL_ON_NT_STATUS(status);

cleanup:

    return status;

error:

    goto cleanup;
}