static NTSTATUS DfsConfigRootAddReferrals( HANDLE hRegistryServer, HKEY hParentKey, PDFS_ROOT_CONTROL_BLOCK pRootCB ) { NTSTATUS ntStatus = STATUS_SUCCESS; HKEY hDfsRootKey = (HKEY)NULL; PDFS_REFERRAL_CONTROL_BLOCK pReferralCB = NULL; PWSTR *ppwszTargets = NULL; DWORD i = 0; DWORD dwIndex = 0; BOOLEAN bFinished = FALSE; DWORD dwValueNameLength = MAX_VALUE_LENGTH; WCHAR pwszValueName[MAX_VALUE_LENGTH] = { 0 }; DWORD dwType = REG_NONE; DWORD dwReserved = 0; BYTE pBuffer[4096] = { 0 }; DWORD dwBufferSize = 0; ntStatus = NtRegOpenKeyExW( hRegistryServer, hParentKey, pRootCB->pwszRootName, 0, KEY_READ, &hDfsRootKey); BAIL_ON_NT_STATUS(ntStatus); for (dwIndex=0; !bFinished; dwIndex++) { dwBufferSize = sizeof(pBuffer); LwRtlZeroMemory(pBuffer, dwBufferSize); ntStatus = NtRegEnumValueW( hRegistryServer, hDfsRootKey, dwIndex, pwszValueName, &dwValueNameLength, &dwReserved, &dwType, pBuffer, &dwBufferSize); if (ntStatus == STATUS_NO_MORE_ENTRIES) { ntStatus = STATUS_SUCCESS; bFinished = TRUE; continue; } BAIL_ON_NT_STATUS(ntStatus); if (dwType != REG_MULTI_SZ) { continue; } ntStatus = NtRegByteArrayToMultiStrsW( pBuffer, dwBufferSize, &ppwszTargets); BAIL_ON_NT_STATUS(ntStatus); ntStatus = DfsAllocateReferralCB(&pReferralCB, pwszValueName); BAIL_ON_NT_STATUS(ntStatus); for (i=0; ppwszTargets[i] != NULL; i++) { ntStatus = DfsReferralParseTarget(pReferralCB, ppwszTargets[i]); BAIL_ON_NT_STATUS(ntStatus); } RegFreeMultiStrsW(ppwszTargets); ppwszTargets = NULL; } cleanup: if (hDfsRootKey) { NtRegCloseKey(hRegistryServer, hDfsRootKey); } return ntStatus; error: goto cleanup; }
static NTSTATUS SrvShareRegWriteToShareInfo( IN REG_DATA_TYPE regDataType, IN PWSTR pwszShareName, IN PBYTE pData, IN ULONG ulDataLen, IN REG_DATA_TYPE regSecDataType, IN PBYTE pSecData, IN ULONG ulSecDataLen, OUT PSRV_SHARE_INFO* ppShareInfo ) { NTSTATUS ntStatus = STATUS_SUCCESS; PSRV_SHARE_INFO pShareInfo = NULL; PWSTR* ppwszValues = NULL; PSTR pszFlags = NULL; ntStatus = SrvAllocateMemory(sizeof(*pShareInfo), (PVOID*)&pShareInfo); BAIL_ON_NT_STATUS(ntStatus); pShareInfo->refcount = 1; pthread_rwlock_init(&pShareInfo->mutex, NULL); pShareInfo->pMutex = &pShareInfo->mutex; ntStatus = SrvAllocateStringW(pwszShareName, &pShareInfo->pwszName); BAIL_ON_NT_STATUS(ntStatus); if (pData) { ULONG iValue = 0; wchar16_t wszCommentPrefix[] = REG_KEY_COMMENT_PREFIX_W; ULONG ulCommentPrefixLen = (sizeof(wszCommentPrefix)/sizeof(wchar16_t)) - 1; wchar16_t wszPathPrefix[] = REG_KEY_PATH_PREFIX_W; ULONG ulPathPrefixLen = (sizeof(wszPathPrefix)/sizeof(wchar16_t)) - 1; wchar16_t wszServicePrefix[] = REG_KEY_SERVICE_PREFIX_W; ULONG ulServicePrefixLen = (sizeof(wszServicePrefix)/sizeof(wchar16_t)) - 1; wchar16_t wszFlagsPrefix[] = REG_KEY_FLAGS_PREFIX_W; ULONG ulFlagsPrefixLen = (sizeof(wszFlagsPrefix)/sizeof(wchar16_t)) - 1; ntStatus = NtRegByteArrayToMultiStrs(pData, ulDataLen, &ppwszValues); BAIL_ON_NT_STATUS(ntStatus); for (; ppwszValues[iValue]; iValue++) { PWSTR pwszValue = &ppwszValues[iValue][0]; if (!wc16sncmp(&wszPathPrefix[0], pwszValue, ulPathPrefixLen)) { SRV_SAFE_FREE_MEMORY(pShareInfo->pwszPath); ntStatus = SrvAllocateStringW( &pwszValue[ulPathPrefixLen], &pShareInfo->pwszPath); BAIL_ON_NT_STATUS(ntStatus); } else if (!wc16sncmp(&wszCommentPrefix[0], pwszValue, ulCommentPrefixLen)) { SRV_SAFE_FREE_MEMORY(pShareInfo->pwszComment); ntStatus = SrvAllocateStringW( &pwszValue[ulCommentPrefixLen], &pShareInfo->pwszComment); BAIL_ON_NT_STATUS(ntStatus); } else if (!wc16sncmp(&wszServicePrefix[0], pwszValue, ulServicePrefixLen)) { ntStatus = SrvShareMapServiceStringToIdW( &pwszValue[ulServicePrefixLen], &pShareInfo->service); BAIL_ON_NT_STATUS(ntStatus); } else if (!wc16sncmp(&wszFlagsPrefix[0], pwszValue, ulFlagsPrefixLen)) { ntStatus = RtlCStringAllocateFromWC16String( &pszFlags, &pwszValue[ulFlagsPrefixLen]); BAIL_ON_NT_STATUS(ntStatus); pShareInfo->ulFlags = strtol(pszFlags, NULL, 16); } else { ntStatus = STATUS_INVALID_PARAMETER_3; BAIL_ON_NT_STATUS(ntStatus); } } } if (!pShareInfo->pwszComment) { wchar16_t wszComment[] = {0}; ntStatus = SrvAllocateStringW( &wszComment[0], &pShareInfo->pwszComment); BAIL_ON_NT_STATUS(ntStatus); } if (ulSecDataLen) { ntStatus = SrvShareSetSecurity( pShareInfo, (PSECURITY_DESCRIPTOR_RELATIVE)pSecData, ulSecDataLen); BAIL_ON_NT_STATUS(ntStatus); } else { ntStatus = SrvShareSetDefaultSecurity(pShareInfo); BAIL_ON_NT_STATUS(ntStatus); } *ppShareInfo = pShareInfo; cleanup: if (ppwszValues) { RegFreeMultiStrsW(ppwszValues); } RTL_FREE(&pszFlags); return ntStatus; error: if (pShareInfo) { SrvShareReleaseInfo(pShareInfo); } goto cleanup; }