LWMsgStatus lwmsg_assoc_print_message_alloc( LWMsgAssoc* assoc, LWMsgMessage* message, char** result ) { LWMsgStatus status = LWMSG_STATUS_SUCCESS; LWMsgDataContext* context = NULL; LWMsgTypeSpec* type = NULL; LWMsgBuffer buffer = {0}; const char* tag_name = NULL; unsigned char nul = 0; buffer.wrap = realloc_wrap; buffer.data = (void*) &assoc->context; BAIL_ON_ERROR(status = lwmsg_data_context_new(&assoc->context, &context)); BAIL_ON_ERROR(status = lwmsg_protocol_get_message_name(assoc->prot, message->tag, &tag_name)); BAIL_ON_ERROR(status = lwmsg_protocol_get_message_type(assoc->prot, message->tag, &type)); if (type) { BAIL_ON_ERROR(status = lwmsg_buffer_print(&buffer, "%s: ", tag_name)); BAIL_ON_ERROR(status = lwmsg_data_print_graph( context, type, message->data, 4, &buffer)); BAIL_ON_ERROR(status = lwmsg_buffer_write(&buffer, &nul, 1)); } else { BAIL_ON_ERROR(status = lwmsg_buffer_print(&buffer, "%s", tag_name)); } *result = (char*) buffer.base; cleanup: if (context) { lwmsg_data_context_delete(context); } return status; error: *result = NULL; if (buffer.base) { lwmsg_context_free(&assoc->context, buffer.base); } goto cleanup; }
LWMsgStatus lwmsg_assoc_destroy_message( LWMsgAssoc* assoc, LWMsgMessage* message ) { LWMsgStatus status = LWMSG_STATUS_SUCCESS; LWMsgTypeSpec* type = NULL; LWMsgDataContext* context = NULL; if (message->tag != -1) { BAIL_ON_ERROR(status = lwmsg_protocol_get_message_type(assoc->prot, message->tag, &type)); if (type != NULL) { BAIL_ON_ERROR(status = lwmsg_data_context_new(&assoc->context, &context)); BAIL_ON_ERROR(status = lwmsg_data_free_graph(context, type, message->data)); } message->tag = -1; message->data = NULL; } error: if (context) { lwmsg_data_context_delete(context); } return status; }
static void lwmsg_connection_destruct( LWMsgAssoc* assoc ) { ConnectionPrivate* priv = CONNECTION_PRIVATE(assoc); lwmsg_connection_buffer_destruct(&priv->sendbuffer); lwmsg_connection_buffer_destruct(&priv->recvbuffer); if (priv->fd != -1) { close(priv->fd); priv->fd = -1; } if (priv->endpoint) { free(priv->endpoint); priv->endpoint = NULL; } if (priv->active_session) { lwmsg_session_release(priv->active_session); } if (priv->default_session) { lwmsg_session_release(priv->default_session); } if (priv->marshal_context) { lwmsg_data_context_delete(priv->marshal_context); } }
LWMsgStatus lwmsg_assoc_free_graph( LWMsgAssoc* assoc, LWMsgTag mtype, void* object ) { LWMsgStatus status = LWMSG_STATUS_SUCCESS; LWMsgTypeSpec* type = NULL; LWMsgDataContext* context = NULL; BAIL_ON_ERROR(status = lwmsg_protocol_get_message_type(assoc->prot, mtype, &type)); BAIL_ON_ERROR(status = lwmsg_data_context_new(&assoc->context, &context)); BAIL_ON_ERROR(status = lwmsg_data_free_graph(context, type, object)); error: if (context) { lwmsg_data_context_delete(context); } return status; }
LSASS_API DWORD LsaAdEnumGroupsFromCache( IN HANDLE hLsaConnection, IN OPTIONAL PCSTR pszDomainName, IN PSTR* ppszResume, IN DWORD dwMaxNumGroups, OUT PDWORD pdwGroupsFound, OUT PLSA_SECURITY_OBJECT** pppObjects ) { DWORD dwError = 0; PSTR pszTargetProvider = NULL; DWORD dwOutputBufferSize = 0; PVOID pOutputBuffer = NULL; PVOID pBlob = NULL; size_t BlobSize = 0; LWMsgContext* context = NULL; LWMsgDataContext* pDataContext = NULL; LSA_AD_IPC_ENUM_GROUPS_FROM_CACHE_REQ request; PLSA_AD_IPC_ENUM_GROUPS_FROM_CACHE_RESP response = NULL; memset(&request, 0, sizeof(request)); if (geteuid() != 0) { dwError = LW_ERROR_ACCESS_DENIED; BAIL_ON_LSA_ERROR(dwError); } if (pszDomainName) { dwError = LwAllocateStringPrintf( &pszTargetProvider, "%s:%s", LSA_PROVIDER_TAG_AD, pszDomainName); BAIL_ON_LSA_ERROR(dwError); } // marshal the request request.pszResume = *ppszResume; request.dwMaxNumGroups = dwMaxNumGroups; dwError = MAP_LWMSG_ERROR(lwmsg_context_new(NULL, &context)); BAIL_ON_LSA_ERROR(dwError); dwError = MAP_LWMSG_ERROR(lwmsg_data_context_new(context, &pDataContext)); BAIL_ON_LSA_ERROR(dwError); dwError = MAP_LWMSG_ERROR(lwmsg_data_marshal_flat_alloc( pDataContext, LsaAdIPCGetEnumGroupsFromCacheReqSpec(), &request, &pBlob, &BlobSize)); BAIL_ON_LSA_ERROR(dwError); dwError = LsaProviderIoControl( hLsaConnection, pszTargetProvider ? pszTargetProvider : LSA_PROVIDER_TAG_AD, LSA_AD_IO_ENUMGROUPSCACHE, BlobSize, pBlob, &dwOutputBufferSize, &pOutputBuffer); BAIL_ON_LSA_ERROR(dwError); dwError = MAP_LWMSG_ERROR(lwmsg_data_unmarshal_flat( pDataContext, LsaAdIPCGetEnumGroupsFromCacheRespSpec(), pOutputBuffer, dwOutputBufferSize, (PVOID*)&response)); BAIL_ON_LSA_ERROR(dwError); *pdwGroupsFound = response->dwNumGroups; *pppObjects = response->ppObjects; response->ppObjects = NULL; if ( *ppszResume ) { LwFreeMemory(*ppszResume); *ppszResume = NULL; } *ppszResume = response->pszResume; response->pszResume = NULL; cleanup: if ( response ) { lwmsg_data_free_graph( pDataContext, LsaAdIPCGetEnumGroupsFromCacheRespSpec(), response); } if (pDataContext) { lwmsg_data_context_delete(pDataContext); } if ( context ) { lwmsg_context_delete(context); } if ( pBlob ) { LwFreeMemory(pBlob); } if ( pOutputBuffer ) { LwFreeMemory(pOutputBuffer); } LW_SAFE_FREE_STRING(pszTargetProvider); return dwError; error: if ( *ppszResume ) { LwFreeMemory(*ppszResume); *ppszResume = NULL; } *pdwGroupsFound = 0; *pppObjects = NULL; goto cleanup; }
DWORD AD_IoctlGetMachineAccount( IN HANDLE hProvider, IN DWORD dwInputBufferSize, IN PVOID pInputBuffer, OUT DWORD* pdwOutputBufferSize, OUT PVOID* ppOutputBuffer ) { DWORD dwError = 0; PVOID pOutputBuffer = NULL; size_t outputBufferSize = 0; LWMsgContext* pContext = NULL; LWMsgDataContext* pDataContext = NULL; PSTR pszDnsDomainName = NULL; PLSA_MACHINE_ACCOUNT_INFO_A pAccountInfo = NULL; // // Everyone can call this, so no access check. // // // Do request // dwError = MAP_LWMSG_ERROR(lwmsg_context_new(NULL, &pContext)); BAIL_ON_LSA_ERROR(dwError); LsaAdIPCSetMemoryFunctions(pContext); dwError = MAP_LWMSG_ERROR(lwmsg_data_context_new(pContext, &pDataContext)); BAIL_ON_LSA_ERROR(dwError); dwError = MAP_LWMSG_ERROR(lwmsg_data_unmarshal_flat( pDataContext, LsaAdIPCGetStringSpec(), pInputBuffer, dwInputBufferSize, OUT_PPVOID(&pszDnsDomainName))); BAIL_ON_LSA_ERROR(dwError); dwError = AD_GetMachineAccountInfoA(pszDnsDomainName, &pAccountInfo); BAIL_ON_LSA_ERROR(dwError); dwError = MAP_LWMSG_ERROR(lwmsg_data_marshal_flat_alloc( pDataContext, LsaAdIPCGetMachineAccountInfoSpec(), pAccountInfo, &pOutputBuffer, &outputBufferSize)); BAIL_ON_LSA_ERROR(dwError); error: if (dwError) { if (pOutputBuffer) { LwFreeMemory(pOutputBuffer); } pOutputBuffer = NULL; outputBufferSize = 0; } LW_SAFE_FREE_STRING(pszDnsDomainName); if (pAccountInfo) { LsaSrvFreeMachineAccountInfoA(pAccountInfo); } if (pDataContext) { lwmsg_data_context_delete(pDataContext); } if (pContext) { lwmsg_context_delete(pContext); } *pdwOutputBufferSize = (DWORD) outputBufferSize; *ppOutputBuffer = pOutputBuffer; return dwError; }
DWORD AD_IoctlGetComputerDn( IN HANDLE hProvider, IN DWORD dwInputBufferSize, IN PVOID pInputBuffer, OUT DWORD* pdwOutputBufferSize, OUT PVOID* ppOutputBuffer ) { DWORD dwError = 0; PVOID pOutputBuffer = NULL; size_t outputBufferSize = 0; PAD_PROVIDER_CONTEXT pProviderContext = (PAD_PROVIDER_CONTEXT)hProvider; LWMsgContext* pContext = NULL; LWMsgDataContext* pDataContext = NULL; PSTR pszDnsDomainName = NULL; PSTR pszComputerDn = NULL; // // Do access check // if (pProviderContext->uid) { dwError = LW_ERROR_ACCESS_DENIED; BAIL_ON_LSA_ERROR(dwError); } // // Do request // dwError = MAP_LWMSG_ERROR(lwmsg_context_new(NULL, &pContext)); BAIL_ON_LSA_ERROR(dwError); LsaAdIPCSetMemoryFunctions(pContext); dwError = MAP_LWMSG_ERROR(lwmsg_data_context_new(pContext, &pDataContext)); BAIL_ON_LSA_ERROR(dwError); dwError = MAP_LWMSG_ERROR(lwmsg_data_unmarshal_flat( pDataContext, LsaAdIPCGetStringSpec(), pInputBuffer, dwInputBufferSize, OUT_PPVOID(&pszDnsDomainName))); BAIL_ON_LSA_ERROR(dwError); dwError = AD_GetComputerDn(pszDnsDomainName, &pszComputerDn); BAIL_ON_LSA_ERROR(dwError); dwError = MAP_LWMSG_ERROR(lwmsg_data_marshal_flat_alloc( pDataContext, LsaAdIPCGetStringSpec(), pszComputerDn, &pOutputBuffer, &outputBufferSize)); BAIL_ON_LSA_ERROR(dwError); error: if (dwError) { if (pOutputBuffer) { LwFreeMemory(pOutputBuffer); } pOutputBuffer = NULL; outputBufferSize = 0; } LW_SAFE_FREE_STRING(pszDnsDomainName); LW_SAFE_FREE_STRING(pszComputerDn); if (pDataContext) { lwmsg_data_context_delete(pDataContext); } if (pContext) { lwmsg_context_delete(pContext); } *pdwOutputBufferSize = (DWORD) outputBufferSize; *ppOutputBuffer = pOutputBuffer; return dwError; }
WINERROR NetrSrvUnjoinDomain2( /* [in] */ handle_t hBinding, /* [in] */ PWSTR pwszServerName, /* [in] */ PWSTR pwszAccountName, /* [in] */ PENC_JOIN_PASSWORD_BUFFER pPassword, /* [in] */ DWORD dwUnjoinFlags ) { const DWORD dwRequiredAccessRights = WKSSVC_ACCESS_JOIN_DOMAIN; DWORD dwError = ERROR_SUCCESS; NTSTATUS ntStatus = STATUS_SUCCESS; WKSS_SRV_CONTEXT SrvCtx = {0}; PSECURITY_DESCRIPTOR_ABSOLUTE pSecDesc = gpWkssSecDesc; GENERIC_MAPPING GenericMapping = {0}; DWORD dwAccessGranted = 0; PWSTR pwszPassword = NULL; size_t sPasswordLen = 0; PSTR pszUsername = NULL; PSTR pszPassword = NULL; LSA_AD_IPC_LEAVE_DOMAIN_REQ Request = {0}; HANDLE hServer = NULL; LWMsgDataContext *pDataCtx = NULL; size_t sInputBlobSize = 0; PVOID pInputBlob = NULL; DWORD dwOutputBlobSize = 0; PVOID pOutputBlob = NULL; dwError = WkssSrvInitAuthInfo(hBinding, &SrvCtx); BAIL_ON_LSA_ERROR(dwError); if (!RtlAccessCheck(pSecDesc, SrvCtx.pUserToken, dwRequiredAccessRights, 0, &GenericMapping, &dwAccessGranted, &ntStatus)) { BAIL_ON_NT_STATUS(ntStatus); } dwError = WkssSrvDecryptPasswordBlob(&SrvCtx, pPassword, NULL, 0, &pwszPassword); BAIL_ON_LSA_ERROR(dwError); dwError = LwWc16sLen(pwszPassword, &sPasswordLen); BAIL_ON_LSA_ERROR(dwError); dwError = LwWc16sToMbs(pwszAccountName, &pszUsername); BAIL_ON_LSA_ERROR(dwError); dwError = LwWc16sToMbs(pwszPassword, &pszPassword); BAIL_ON_LSA_ERROR(dwError); Request.pszUsername = pszUsername; Request.pszPassword = pszPassword; if (dwUnjoinFlags & NETSETUP_ACCT_DELETE) { Request.dwFlags |= LSA_NET_LEAVE_DOMAIN_ACCT_DELETE; } dwError = MAP_LWMSG_ERROR(lwmsg_data_context_new(NULL, &pDataCtx)); BAIL_ON_LSA_ERROR(dwError); dwError = MAP_LWMSG_ERROR(lwmsg_data_marshal_flat_alloc( pDataCtx, LsaAdIPCGetLeaveDomainReqSpec(), &Request, &pInputBlob, &sInputBlobSize)); BAIL_ON_LSA_ERROR(dwError); dwError = LsaSrvOpenServer(geteuid(), getegid(), getpid(), &hServer); BAIL_ON_LSA_ERROR(dwError); dwError = LsaSrvProviderIoControl(hServer, LSA_PROVIDER_TAG_AD, LSA_AD_IO_LEAVEDOMAIN, sInputBlobSize, pInputBlob, &dwOutputBlobSize, &pOutputBlob); BAIL_ON_LSA_ERROR(dwError); cleanup: if (hServer) { LsaSrvCloseServer(hServer); } if (pDataCtx) { lwmsg_data_context_delete(pDataCtx); } WkssSrvFreeAuthInfo(&SrvCtx); LW_SECURE_FREE_STRING(pszPassword); LW_SECURE_FREE_WSTRING(pwszPassword); LW_SECURE_FREE_MEMORY(pInputBlob, sInputBlobSize); LW_SAFE_FREE_MEMORY(pszUsername); return (WINERROR)dwError; error: goto cleanup; }