PCSTR SrvPathGetFileName( PCSTR pszPath ) { PCSTR pszCursor = pszPath; size_t sLen = 0; CHAR szBackSlash[] = { '\\', 0 }; CHAR szFwdSlash[] = { '/', 0 }; if (pszPath && (sLen = strlen(pszPath))) { pszCursor = pszPath + sLen - 1; while (!IsNullOrEmptyString(pszCursor) && (pszCursor != pszPath)) { if ((*pszCursor == szBackSlash[0]) || (*pszCursor == szFwdSlash[0])) { pszCursor++; break; } pszCursor--; } } return pszCursor; }
DWORD VmDirSchemaAttrIdMapGetAttrId( PVDIR_SCHEMA_ATTR_ID_MAP pAttrIdMap, PSTR pszAttrName, USHORT* pusAttrId ) { DWORD dwError = 0; uintptr_t pAttrId = 0; if (!pAttrIdMap || IsNullOrEmptyString(pszAttrName)) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMDIR_ERROR(dwError); } dwError = LwRtlHashMapFindKey(pAttrIdMap->pStoredIds, (PVOID*)&pAttrId, pszAttrName); if (dwError) { dwError = LwRtlHashMapFindKey(pAttrIdMap->pNewIds, (PVOID*)&pAttrId, pszAttrName); } BAIL_ON_VMDIR_ERROR(dwError); if (pusAttrId) { *pusAttrId = (USHORT)pAttrId; } error: return dwError; }
static PVDIR_PAGED_SEARCH_RECORD VmDirPagedSearchCacheFind( PCSTR pszCookie ) { DWORD dwError = 0; PLW_HASHTABLE_NODE pNode = NULL; PVDIR_PAGED_SEARCH_RECORD pSearchRecord = NULL; BOOLEAN bInLock = FALSE; if (IsNullOrEmptyString(pszCookie)) { BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_PARAMETER); } VMDIR_LOCK_MUTEX(bInLock, gPagedSearchCache.mutex); dwError = LwRtlHashTableFindKey( gPagedSearchCache.pHashTbl, &pNode, (PVOID)pszCookie); dwError = LwNtStatusToWin32Error(dwError); BAIL_ON_VMDIR_ERROR(dwError); pSearchRecord = LW_STRUCT_FROM_FIELD(pNode, VDIR_PAGED_SEARCH_RECORD, Node); _RefPagedSearchRecord(pSearchRecord); cleanup: VMDIR_UNLOCK_MUTEX(bInLock, gPagedSearchCache.mutex); return pSearchRecord; error: goto cleanup; }
static DWORD ReadPassword( PSTR* ppszPassword ) { DWORD dwError = ERROR_SUCCESS; struct termios orig, nonecho; sigset_t sig, osig; CHAR szPassword[33] = ""; PSTR pszPassword = NULL; fprintf(stdout, "Password: "******"\n")] = '\0'; if (IsNullOrEmptyString(szPassword)) { dwError = ERROR_PASSWORD_RESTRICTION; BAIL_ON_VMAFD_ERROR(dwError); } dwError = VmAfdAllocateStringA(szPassword, &pszPassword); BAIL_ON_VMAFD_ERROR(dwError); *ppszPassword = pszPassword; cleanup: tcsetattr(0, TCSANOW, &orig); sigprocmask(SIG_SETMASK,&osig,NULL); return dwError; error: *ppszPassword = NULL; goto cleanup; }
DWORD VmDirSimpleEntryDeleteAttribute( PCSTR pszDN, PCSTR pszAttr ) { DWORD dwError = 0; size_t dnlen = 0; size_t attrlen = 0; VDIR_OPERATION ldapOp = {0}; if (IsNullOrEmptyString(pszDN) || IsNullOrEmptyString(pszAttr)) { BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_PARAMETER); } dwError = VmDirInitStackOperation( &ldapOp, VDIR_OPERATION_TYPE_INTERNAL, LDAP_REQ_MODIFY, NULL); BAIL_ON_VMDIR_ERROR(dwError); dnlen = VmDirStringLenA(pszDN); attrlen = VmDirStringLenA(pszAttr); ldapOp.pBEIF = VmDirBackendSelect(NULL); ldapOp.reqDn.lberbv_val = (PSTR)pszDN; ldapOp.reqDn.lberbv_len = dnlen; ldapOp.request.modifyReq.dn.lberbv_val = ldapOp.reqDn.lberbv_val; ldapOp.request.modifyReq.dn.lberbv_len = ldapOp.reqDn.lberbv_len; dwError = VmDirAppendAMod( &ldapOp, MOD_OP_DELETE, pszAttr, attrlen, NULL, 0); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirInternalModifyEntry(&ldapOp); BAIL_ON_VMDIR_ERROR(dwError); cleanup: VmDirFreeOperationContent(&ldapOp); return dwError; error: goto cleanup; }
DWORD ADUSMBGetFile( PSTR pszDomainName, PSTR pszSourcePath, PSTR pszDestPath ) { DWORD dwError = MAC_AD_ERROR_SUCCESS; PSTR pszFQSrcPath = NULL; PSTR pszDCHostname = NULL; if (IsNullOrEmptyString(pszDomainName) || IsNullOrEmptyString(pszSourcePath) || IsNullOrEmptyString(pszDestPath)) { dwError = MAC_AD_ERROR_INVALID_PARAMETER; BAIL_ON_MAC_ERROR(dwError); } dwError = GetPreferredDCAddress( pszDomainName, &pszDCHostname); BAIL_ON_MAC_ERROR(dwError); dwError = LwAllocateStringPrintf( &pszFQSrcPath, "//%s/sysvol/%s", pszDCHostname, *pszSourcePath == '/' ? pszSourcePath+1 : pszSourcePath); BAIL_ON_MAC_ERROR(dwError); LOG("Calling ADUCopyFileFromRemote(Src:%s, Dest:%s)", pszFQSrcPath, pszDestPath); dwError = ADUCopyFileFromRemote(pszFQSrcPath, pszDestPath); BAIL_ON_MAC_ERROR(dwError); cleanup: LW_SAFE_FREE_STRING(pszFQSrcPath); LW_SAFE_FREE_STRING(pszDCHostname); return dwError; error: goto cleanup; }
DWORD VmDirGetKrbMasterKey( PSTR pszFQDN, // [in] FQDN PBYTE* ppKeyBlob, DWORD* pSize ) { DWORD dwError = 0; PBYTE pRetMasterKey = NULL; if (IsNullOrEmptyString(pszFQDN) || !ppKeyBlob || !pSize ) { dwError = VMDIR_ERROR_INVALID_PARAMETER; BAIL_ON_VMDIR_ERROR(dwError); } // Currently, we only support single krb realm. // Global cache gVmdirKrbGlobals is initialized during startup stage. if (VmDirStringCompareA( pszFQDN, VDIR_SAFE_STRING(gVmdirKrbGlobals.pszRealm), FALSE) != 0) { dwError = VMDIR_ERROR_INVALID_REALM; BAIL_ON_VMDIR_ERROR(dwError); } dwError = VmDirAllocateMemory( gVmdirKrbGlobals.bervMasterKey.lberbv.bv_len, (PVOID*)&pRetMasterKey ); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirCopyMemory ( pRetMasterKey, gVmdirKrbGlobals.bervMasterKey.lberbv.bv_len, gVmdirKrbGlobals.bervMasterKey.lberbv.bv_val, gVmdirKrbGlobals.bervMasterKey.lberbv.bv_len ); BAIL_ON_VMDIR_ERROR(dwError); *ppKeyBlob = pRetMasterKey; *pSize = (DWORD) gVmdirKrbGlobals.bervMasterKey.lberbv.bv_len; pRetMasterKey = NULL; cleanup: return dwError; error: VMDIR_LOG_ERROR( LDAP_DEBUG_RPC, "VmDirGetKrbMasterKey failed. (%u)(%s)", dwError, VDIR_SAFE_STRING(pszFQDN)); VMDIR_SAFE_FREE_MEMORY(pRetMasterKey); goto cleanup; }
DWORD LWNetDnsGetSrvRecordQuestion( OUT PSTR* ppszQuestion, IN PCSTR pszDomainName, IN OPTIONAL PCSTR pszSiteName, IN DWORD dwDsFlags ) { DWORD dwError = 0; PSTR question = NULL; PCSTR kind = "dc"; PCSTR service = "_ldap"; if (dwDsFlags & DS_PDC_REQUIRED) { kind = "pdc"; service = "_ldap"; } else if (dwDsFlags & DS_GC_SERVER_REQUIRED) { kind = "gc"; service = "_ldap"; } else if (dwDsFlags & DS_KDC_REQUIRED) { kind = "dc"; service = "_kerberos"; } else { kind = "dc"; service = "_ldap"; } if (IsNullOrEmptyString(pszSiteName)) { dwError = LwAllocateStringPrintf(&question, "%s._tcp.%s._msdcs.%s", service, kind, pszDomainName); BAIL_ON_LWNET_ERROR(dwError); } else { dwError = LwAllocateStringPrintf(&question, "%s._tcp.%s._sites.%s._msdcs.%s", service, pszSiteName, kind, pszDomainName); BAIL_ON_LWNET_ERROR(dwError); } error: if (dwError) { LWNET_SAFE_FREE_STRING(question); } *ppszQuestion = question; return dwError; }
DWORD LwCALockDN( PLWCA_POST_HANDLE pHandle, PCSTR pcszDN, PSTR *ppszUuid ) { DWORD dwError = 0; PSTR pszUuid = NULL; ULONG currTime = 0; DWORD dwAttempt = 0; struct timespec ts = {0}; if (IsNullOrEmptyString(pcszDN) || !ppszUuid || !pHandle) { dwError = LWCA_ERROR_INVALID_PARAMETER; BAIL_ON_LWCA_ERROR(dwError); } dwError = LwCAUuidGenerate(&pszUuid); BAIL_ON_LWCA_ERROR(dwError); ts.tv_nsec = LWCA_LOCK_SLEEP_NS; while (dwAttempt < LWCA_LOCK_MAX_ATTEMPT) { dwError = _LwCAGetCurrentTime(&currTime); BAIL_ON_LWCA_ERROR(dwError); dwError = _LwCALockDNImpl(pHandle, pszUuid, currTime, pcszDN); if (dwError == LWCA_LOCK_APPLY_FAILED) { dwAttempt += 1; nanosleep(&ts, NULL); continue; } BAIL_ON_LWCA_ERROR(dwError); break; } if (dwAttempt >= LWCA_LOCK_MAX_ATTEMPT) { dwError = LWCA_LOCK_APPLY_FAILED; BAIL_ON_LWCA_ERROR(dwError); } *ppszUuid = pszUuid; cleanup: return dwError; error: LWCA_SAFE_FREE_STRINGA(pszUuid); if (ppszUuid) { *ppszUuid = NULL; } goto cleanup; }
NTSTATUS SrvGetTreeRelativePath( PWSTR pwszOriginalPath, PWSTR* ppwszSpecificPath ) { NTSTATUS ntStatus = STATUS_SUCCESS; wchar16_t wszBackSlash[] = { '\\', 0 }; wchar16_t wszFwdSlash[] = { '/', 0 }; if ((*pwszOriginalPath != wszBackSlash[0]) && (*pwszOriginalPath != wszFwdSlash[0])) { ntStatus = STATUS_INVALID_PARAMETER; BAIL_ON_NT_STATUS(ntStatus); } pwszOriginalPath++; // Skip the device name while (!IsNullOrEmptyString(pwszOriginalPath) && (*pwszOriginalPath != wszBackSlash[0]) && (*pwszOriginalPath != wszFwdSlash[0])) { pwszOriginalPath++; } if (IsNullOrEmptyString(pwszOriginalPath) || ((*pwszOriginalPath != wszBackSlash[0]) && (*pwszOriginalPath != wszFwdSlash[0]))) { ntStatus = STATUS_INVALID_PARAMETER; BAIL_ON_NT_STATUS(ntStatus); } *ppwszSpecificPath = pwszOriginalPath; cleanup: return ntStatus; error: *ppwszSpecificPath = NULL; goto cleanup; }
static DWORD VmwDeploySetupServerPartner( PVMW_IC_SETUP_PARAMS pParams ) { DWORD dwError = 0; PCSTR ppszServices[]= { VMW_DCERPC_SVC_NAME, VMW_VMDNS_SVC_NAME, VMW_VMAFD_SVC_NAME, VMW_DIR_SVC_NAME, VMW_VMCA_SVC_NAME }; int iSvc = 0; VMW_DEPLOY_LOG_INFO("Setting up system as Infrastructure partner node"); dwError = VmwDeployValidateHostname(pParams->pszHostname); BAIL_ON_DEPLOY_ERROR(dwError); dwError = VmwDeployValidatePartnerCredentials( pParams->pszServer, pParams->pszPassword, pParams->pszDomainName); BAIL_ON_DEPLOY_ERROR(dwError); dwError = VmwDeployValidateSiteName(pParams->pszSite); BAIL_ON_DEPLOY_ERROR(dwError); if (!IsNullOrEmptyString(pParams->pszDNSForwarders)) { dwError = VmwDeployValidateDNSForwarders(pParams->pszDNSForwarders); BAIL_ON_DEPLOY_ERROR(dwError); } for (; iSvc < sizeof(ppszServices)/sizeof(ppszServices[0]); iSvc++) { PCSTR pszService = ppszServices[iSvc]; VMW_DEPLOY_LOG_INFO("Starting service [%s]", pszService); dwError = VmwDeployStartService(pszService); BAIL_ON_DEPLOY_ERROR(dwError); } dwError = VmwDeploySetupServerCommon(pParams); BAIL_ON_DEPLOY_ERROR(dwError); cleanup: return dwError; error: goto cleanup; }
DWORD VmAfWinCfgOpenRootKey( PVMAF_CFG_CONNECTION pConnection, PCSTR pszKeyName, DWORD dwOptions, DWORD dwAccess, PVMAF_CFG_KEY* ppKey ) { DWORD dwError = 0; PVMAF_CFG_KEY pKey = NULL; VMAF_CFG_KEY rootKey = {0}; if (!pConnection || IsNullOrEmptyString(pszKeyName) || !ppKey) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR(dwError); } if (!strcmp(pszKeyName, "HKEY_LOCAL_MACHINE")) { rootKey.hKey = HKEY_LOCAL_MACHINE; } else { dwError = ERROR_NOT_SUPPORTED; BAIL_ON_VMAFD_ERROR(dwError); } dwError = VmAfWinCfgOpenKey( pConnection, &rootKey, NULL, dwOptions, dwAccess, &pKey); BAIL_ON_VMAFD_ERROR(dwError); *ppKey = pKey; cleanup: return dwError; error: if (ppKey) { *ppKey = NULL; } // if (pKey) // { // VmAfWinCfgCloseKey(pKey); // } goto cleanup; }
DWORD DJFixLoginConfigFile( PCSTR pszPath ) { DWORD ceError = ERROR_SUCCESS; PCSTR pszFilePath = NULL; PSTR pszTmpPath = NULL; PSTR pszFinalPath = NULL; BOOLEAN bFileExists = FALSE; FILE* fp = NULL; FILE* fp_new = NULL; DynamicArray lines; PSTR currentSystem = NULL; memset(&lines, 0, sizeof(lines)); if (IsNullOrEmptyString(pszPath)) pszFilePath = LOGIN_CONFIG_PATH; else pszFilePath = pszPath; GCE(ceError = CTGetFileTempPath( pszFilePath, &pszFinalPath, &pszTmpPath)); GCE(ceError = CTCheckFileExists(pszFinalPath, &bFileExists)); if (!bFileExists) goto cleanup; GCE(ceError = CTOpenFile(pszFinalPath, "r", &fp)); GCE(ceError = CTReadLines(fp, &lines)); GCE(ceError = CTSafeCloseFile(&fp)); GCE(ceError = GetAuthType(&lines, ¤tSystem)); if(!strcmp(currentSystem, "PAM_AUTH")) goto cleanup; GCE(ceError = SetAuthType(&lines, "PAM_AUTH")); GCE(ceError = CTOpenFile(pszTmpPath, "w", &fp_new)); GCE(ceError = CTWriteLines(fp_new, &lines)); GCE(ceError = CTSafeCloseFile(&fp_new)); GCE(ceError = CTSafeReplaceFile(pszFilePath, pszTmpPath)); cleanup: CTSafeCloseFile(&fp); CTSafeCloseFile(&fp_new); CT_SAFE_FREE_STRING(currentSystem); CT_SAFE_FREE_STRING(pszTmpPath); CT_SAFE_FREE_STRING(pszFinalPath); CTFreeLines(&lines); return ceError; }
DWORD VmDirIndexCfgAcquire( PCSTR pszAttrName, VDIR_INDEX_USAGE usage, PVDIR_INDEX_CFG* ppIndexCfg ) { DWORD dwError = 0; BOOLEAN bInLock = FALSE; PVDIR_INDEX_CFG pIndexCfg = NULL; PVMDIR_MUTEX pMutex = NULL; if (IsNullOrEmptyString(pszAttrName) || !ppIndexCfg) { dwError = VMDIR_ERROR_INVALID_PARAMETER; BAIL_ON_VMDIR_ERROR(dwError); } *ppIndexCfg = NULL; if (LwRtlHashMapFindKey( gVdirIndexGlobals.pIndexCfgMap, (PVOID*)&pIndexCfg, pszAttrName)) { goto cleanup; } pMutex = pIndexCfg->mutex; VMDIR_LOCK_MUTEX(bInLock, pMutex); if (pIndexCfg->status == VDIR_INDEXING_SCHEDULED) { goto cleanup; } else if (pIndexCfg->status == VDIR_INDEXING_IN_PROGRESS && usage == VDIR_INDEX_READ) { dwError = VMDIR_ERROR_UNWILLING_TO_PERFORM; } else if (pIndexCfg->status == VDIR_INDEXING_DISABLED || pIndexCfg->status == VDIR_INDEXING_DELETED) { goto cleanup; } BAIL_ON_VMDIR_ERROR(dwError); pIndexCfg->usRefCnt++; *ppIndexCfg = pIndexCfg; cleanup: VMDIR_UNLOCK_MUTEX(bInLock, pMutex); return dwError; error: VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "%s failed, error (%d)", __FUNCTION__, dwError ); goto cleanup; }
DWORD VmwDeployValidatePassword( PCSTR pszPassword ) { DWORD dwError = 0; size_t iCh = 0; size_t nUpper = 0; size_t nLower = 0; size_t nDigit = 0; size_t nSpecial = 0; size_t sLen = 0; VMW_DEPLOY_LOG_DEBUG("Validating password"); if (IsNullOrEmptyString(pszPassword) || (sLen = strlen(pszPassword)) < 8) { dwError = ERROR_PASSWORD_RESTRICTION; BAIL_ON_DEPLOY_ERROR(dwError); } // We are looking for at least one upper case, one lower case, one digit and // one special case character. Added illegal chars check for (iCh = 0; iCh < sLen; iCh++) { int ch = pszPassword[iCh]; if (isdigit(ch)) { nDigit++; } else if (islower(ch)) { nLower++; } else if (isupper(ch)) { nUpper++; } else if (ispunct(ch)) { nSpecial++; } } if (!nUpper || !nLower || !nDigit || !nSpecial) { VMW_DEPLOY_LOG_ERROR("Password complexity requirement not satisfied"); dwError = ERROR_PASSWORD_RESTRICTION; BAIL_ON_DEPLOY_ERROR(dwError); } error: return dwError; }
DWORD VmDirMetaDataCreate( USN localUsn, UINT64 version, PCSTR pszOrigInvoId, PCSTR pszOrigTimeStamp, USN origUsn, PVMDIR_ATTRIBUTE_METADATA* ppMetaData ) { DWORD dwError = 0; PVMDIR_ATTRIBUTE_METADATA pMetaData = NULL; if (!ppMetaData || IsNullOrEmptyString(pszOrigInvoId) || IsNullOrEmptyString(pszOrigTimeStamp)) { BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_PARAMETER); } dwError = VmDirAllocateMemory(sizeof(VMDIR_ATTRIBUTE_METADATA), (PVOID*) &pMetaData); BAIL_ON_VMDIR_ERROR(dwError); pMetaData->localUsn = localUsn; pMetaData->version = version; dwError = VmDirAllocateStringA(pszOrigInvoId, &pMetaData->pszOrigInvoId); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirAllocateStringA(pszOrigTimeStamp, &pMetaData->pszOrigTime); BAIL_ON_VMDIR_ERROR(dwError); pMetaData->origUsn = origUsn; *ppMetaData = pMetaData; cleanup: return dwError; error: VmDirFreeMetaData(pMetaData); VMDIR_LOG_ERROR(VMDIR_LOG_MASK_ALL, "failed, error (%d)", dwError); goto cleanup; }
static DWORD VmDirValidateUserCreateParamsW( PVMDIR_USER_CREATE_PARAMS_W pCreateParams ) { DWORD dwError = 0; if (!pCreateParams || IsNullOrEmptyString(pCreateParams->pwszAccount) || IsNullOrEmptyString(pCreateParams->pwszFirstname) || IsNullOrEmptyString(pCreateParams->pwszLastname) || IsNullOrEmptyString(pCreateParams->pwszPassword)) { dwError = ERROR_INVALID_PARAMETER; } return dwError; }
DWORD VmDirConfigSetDefaultSiteandLduGuid( PCSTR pszDefaultSiteGuid, PCSTR pszDefaultLduGuid ) #ifndef _WIN32 { DWORD dwError = 0; if (IsNullOrEmptyString(pszDefaultSiteGuid) || IsNullOrEmptyString(pszDefaultLduGuid)) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMDIR_ERROR(dwError); } dwError = RegUtilSetValue( NULL, HKEY_THIS_MACHINE, VMDIR_CONFIG_PARAMETER_KEY_PATH, NULL, VMDIR_REG_KEY_SITE_GUID, REG_SZ, (PVOID)pszDefaultSiteGuid, VmDirStringLenA(pszDefaultSiteGuid)+1); BAIL_ON_VMDIR_ERROR(dwError); dwError = RegUtilSetValue( NULL, HKEY_THIS_MACHINE, VMDIR_CONFIG_PARAMETER_KEY_PATH, NULL, VMDIR_REG_KEY_LDU_GUID, REG_SZ, (PVOID)pszDefaultLduGuid, VmDirStringLenA(pszDefaultLduGuid)+1); BAIL_ON_VMDIR_ERROR(dwError); cleanup: return dwError; error: VmDirLog(LDAP_DEBUG_ANY, "VmDirConfigSetDefaultSiteandLduGuid failed with error (%u)", dwError); goto cleanup; }
DWORD LWSetConfigValueBySectionName( PCFGSECTION pSectionList, PCSTR pszSectionName, PCSTR pszName, PCSTR pszValue ) { DWORD dwError = 0; PCFGSECTION pSection = NULL; if (IsNullOrEmptyString(pszSectionName) || IsNullOrEmptyString(pszName)) { dwError = MAC_AD_ERROR_INVALID_PARAMETER; BAIL_ON_MAC_ERROR(dwError); } while (pSectionList) { if (!strcmp(pSectionList->pszName, pszSectionName)) { pSection = pSectionList; break; } pSectionList = pSectionList->pNext; } if (!pSection) { dwError = MAC_AD_ERROR_INVALID_RECORD_TYPE; goto error; } dwError = LWSetConfigValueBySection(pSection, pszName, pszValue); BAIL_ON_MAC_ERROR(dwError); cleanup: return dwError; error: goto cleanup; }
DWORD VmDirSchemaAttrIdMapAddNewAttr( PVDIR_SCHEMA_ATTR_ID_MAP pAttrIdMap, PSTR pszAttrName, USHORT usAttrId // optional ) { DWORD dwError = 0; PSTR pszKey = 0; if (!pAttrIdMap || IsNullOrEmptyString(pszAttrName)) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMDIR_ERROR(dwError); } if (VmDirSchemaAttrIdMapGetAttrId(pAttrIdMap, pszAttrName, NULL) == 0) { dwError = ERROR_ALREADY_EXISTS; BAIL_ON_VMDIR_ERROR(dwError); } dwError = VmDirAllocateStringA(pszAttrName, &pszKey); BAIL_ON_VMDIR_ERROR(dwError); if (usAttrId) { dwError = LwRtlHashMapInsert(pAttrIdMap->pNewIds, pszKey, (PVOID)(uintptr_t)usAttrId, NULL); BAIL_ON_VMDIR_ERROR(dwError); if (usAttrId >= pAttrIdMap->usNextId) { pAttrIdMap->usNextId = usAttrId + 1; } } else { dwError = LwRtlHashMapInsert(pAttrIdMap->pNewIds, pszKey, (PVOID)(uintptr_t)pAttrIdMap->usNextId, NULL); BAIL_ON_VMDIR_ERROR(dwError); pAttrIdMap->usNextId++; } cleanup: return dwError; error: VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "%s failed, error (%d)", __FUNCTION__, dwError ); VMDIR_SAFE_FREE_MEMORY(pszKey); goto cleanup; }
int main( int argc, char* argv[] ) { DWORD dwError = 0; handle_t bindingHandle = 0; HANDLE hEventLog = 0; PSTR pszBindingString = NULL; DWORD eventTableCategoryId = (DWORD) -1; PSTR pszFilename = NULL; evt_init_logging_to_file(LOG_LEVEL_VERBOSE, ""); dwError = ParseArgs(argc, argv, &pszFilename, &eventTableCategoryId); BAIL_ON_EVT_ERROR(dwError); if (IsNullOrEmptyString(pszFilename)) { EVT_LOG_ERROR("No path to the file containing events was specified."); ShowUsage(); BAIL_ON_EVT_ERROR((dwError = EINVAL)); } TRY { dwError = LWIOpenEventLog(&bindingHandle, &hEventLog, &pszBindingString, "127.0.0.1", "127.0.0.1"); BAIL_ON_EVT_ERROR(dwError); dwError = ParseAndAddEvents(bindingHandle, hEventLog, pszFilename, eventTableCategoryId, AddEventRecord); BAIL_ON_EVT_ERROR(dwError); } CATCH_ALL { exc_get_status (THIS_CATCH, &dwError); EVT_LOG_ERROR("Unexpected error . Error code [%d]\n", dwError); BAIL_ON_EVT_ERROR(dwError); } ENDTRY; error: if (bindingHandle && hEventLog && pszBindingString) LWICloseEventLog(bindingHandle, hEventLog, pszBindingString); if(dwError != 0) { EVT_LOG_ERROR("Failed to import events. Error code [%d]\n", dwError); } return dwError; }
DWORD CTMatchProgramToPID( PCSTR pszProgramName, pid_t pid ) { DWORD ceError = ERROR_SUCCESS; CHAR szBuf[PATH_MAX+1]; FILE* pFile = NULL; #if defined(__LWI_DARWIN__) || defined(__LWI_FREEBSD__) sprintf(szBuf, "ps -p %d -o command= | grep %s", pid, pszProgramName); #elif defined(__LWI_SOLARIS__) || defined(__LWI_HP_UX__) || defined(__LWI_AIX__) sprintf(szBuf, "PS=ps; [ -x /bin/ps ] && PS=/bin/ps; UNIX95=1 $PS -p %ld -o comm= | grep %s", (long)pid, pszProgramName); #else sprintf(szBuf, "UNIX95=1 ps -p %ld -o cmd= | grep %s", (long)pid, pszProgramName); #endif pFile = popen(szBuf, "r"); if (pFile == NULL) { ceError = LwMapErrnoToLwError(errno); BAIL_ON_CENTERIS_ERROR(ceError); } /* Assume that we won't find the process we are looking for */ ceError = ERROR_PROC_NOT_FOUND; while (TRUE) { if (NULL == fgets(szBuf, PATH_MAX, pFile)) { if (feof(pFile)) { break; } else { ceError = LwMapErrnoToLwError(errno); BAIL_ON_CENTERIS_ERROR(ceError); } } CTStripWhitespace(szBuf); if (!IsNullOrEmptyString(szBuf)) { /* Well what do you know, it was found! */ ceError = ERROR_SUCCESS; break; } } error: if (pFile) pclose(pFile); return ceError; }
DWORD VMCAGetCRLInfoPrivate( PSTR pszFileName, time_t *ptmLastUpdate, time_t *ptmNextUpdate, DWORD *pdwCRLNumber) { DWORD dwError = 0; X509_CRL *pCrl = NULL; ASN1_TIME *pLastUpdate = NULL; ASN1_TIME *pNextUpdate = NULL; ASN1_INTEGER *pCrlNumber = NULL; long nCrlNum = 0; if ( (IsNullOrEmptyString(pszFileName)) || (ptmNextUpdate == NULL) || (ptmLastUpdate == NULL) || (pdwCRLNumber == NULL) ) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_ERROR(dwError); } dwError = VMCAFileToCRL(pszFileName, &pCrl); BAIL_ON_ERROR(dwError); pLastUpdate = X509_CRL_get_lastUpdate(pCrl); pNextUpdate = X509_CRL_get_nextUpdate(pCrl); pCrlNumber = ASN1_INTEGER_new(); if(pCrlNumber == NULL) { dwError = VMCA_OUT_MEMORY_ERR; BAIL_ON_ERROR(dwError); } pCrlNumber = X509_CRL_get_ext_d2i(pCrl, NID_crl_number, 0,0); nCrlNum = ASN1_INTEGER_get(pCrlNumber); *pdwCRLNumber = nCrlNum; dwError = VMCAASN1ToTimeT(pLastUpdate,ptmLastUpdate); BAIL_ON_ERROR(dwError); dwError = VMCAASN1ToTimeT(pNextUpdate,ptmNextUpdate); BAIL_ON_ERROR(dwError); cleanup: if(pCrlNumber){ ASN1_INTEGER_free(pCrlNumber); } VMCACrlFree(pCrl); return dwError; error : goto cleanup; }
DWORD DNSOpen( PCSTR pszNameServer, DWORD dwType, PHANDLE phDNSServer ) { DWORD dwError = 0; HANDLE hDNSServer = (HANDLE)NULL; if (IsNullOrEmptyString(pszNameServer)) { dwError = LWDNS_ERROR_INVALID_PARAMETER; BAIL_ON_LWDNS_ERROR(dwError); } switch (dwType) { case DNS_TCP: dwError = DNSTCPOpen( pszNameServer, &hDNSServer ); break; case DNS_UDP: dwError = DNSUDPOpen( pszNameServer, &hDNSServer ); break; default: dwError = LWDNS_ERROR_INVALID_PARAMETER; } BAIL_ON_LWDNS_ERROR(dwError); *phDNSServer = hDNSServer; cleanup: return dwError; error: *phDNSServer = (HANDLE)NULL; goto cleanup; }
DWORD VmAfdModifyOwner( PVECS_SERV_STORE pStore, PCWSTR pszUserName, PVMAFD_SECURITY_DESCRIPTOR pSecurityDescriptor ) { DWORD dwError = 0; PVM_AFD_SECURITY_CONTEXT pSecurityContext = NULL; PVM_AFD_SECURITY_CONTEXT pSecurityContextToClean = NULL; if (IsNullOrEmptyString (pszUserName) || !pSecurityDescriptor || !pStore ) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMAFD_ERROR (dwError); } dwError = VmAfdAllocateContextFromName ( pszUserName, &pSecurityContext ); BAIL_ON_VMAFD_ERROR (dwError); pSecurityContextToClean = pSecurityContext; dwError = VmAfdCheckOwnerShip ( pStore, pSecurityContext ); if (dwError == 0) { goto cleanup; } dwError = 0; pSecurityContextToClean = pSecurityDescriptor->pOwnerSecurityContext; pSecurityDescriptor->pOwnerSecurityContext = pSecurityContext; cleanup: if (pSecurityContextToClean) { VmAfdFreeSecurityContext (pSecurityContextToClean); } return dwError; error: goto cleanup; }
DWORD VmDnsCacheLoadZoneFromStore( PVMDNS_CACHE_CONTEXT pContext, PCSTR pZoneName ) { DWORD dwError = 0; PVMDNS_RECORD_LIST pList = NULL; PVMDNS_ZONE_OBJECT pZoneObject = NULL; BOOL bLocked = FALSE; PVMDNS_PROPERTY_LIST pPropertyList = NULL; if (IsNullOrEmptyString(pZoneName)) { dwError = ERROR_INVALID_PARAMETER; BAIL_ON_VMDNS_ERROR(dwError); } VmDnsLockWrite(pContext->pLock); bLocked = TRUE; dwError = VmDnsStoreGetProperties(pZoneName, &pPropertyList); if (dwError && dwError != ERROR_NOT_FOUND) { BAIL_ON_VMDNS_ERROR(dwError); } dwError = VmDnsStoreGetRecords(pZoneName, pZoneName, &pList); if (dwError && dwError != ERROR_NOT_FOUND) { BAIL_ON_VMDNS_ERROR(dwError); } dwError = VmDnsZoneCreateFromRecordList(pZoneName, pList, pPropertyList, &pZoneObject); BAIL_ON_VMDNS_ERROR(dwError); VmDnsZoneListAddZone(pContext->pZoneList, pZoneObject); BAIL_ON_VMDNS_ERROR(dwError); cleanup: if (bLocked) { VmDnsUnlockWrite(pContext->pLock); } VmDnsRecordListRelease(pList); VmDnsPropertyListRelease(pPropertyList); VmDnsZoneObjectRelease(pZoneObject); return dwError; error: goto cleanup; }
DWORD DJUnjoinDomain( PCSTR pszUsername, PCSTR pszPassword ) { DWORD dwError = 0; LWException *exc = NULL; JoinProcessOptions options; DJZeroJoinProcessOptions(&options); options.joiningDomain = FALSE; if (!IsNullOrEmptyString(pszUsername)) { LW_CLEANUP_CTERR(&exc, CTStrdup(pszUsername, &options.username)); } if (!IsNullOrEmptyString(pszPassword)) { LW_CLEANUP_CTERR(&exc, CTStrdup(pszPassword, &options.password)); } LW_CLEANUP_CTERR(&exc, DJGetComputerName(&options.computerName)); LW_TRY(&exc, DJInitModuleStates(&options, &LW_EXC)); LW_TRY(&exc, DJRunJoinProcess(&options, &LW_EXC)); cleanup: DJFreeJoinProcessOptions(&options); if (!LW_IS_OK(exc)) { dwError = exc->code; LWHandle(&exc); } return dwError; }
static DWORD _VmDirSimpleEntryCreateInBEWithGuid( PVDIR_BACKEND_INTERFACE pBE, PVDIR_SCHEMA_CTX pSchemaCtx, PSTR* ppszEntryInitializer, PSTR pszDN, ENTRYID ulEntryId, PSTR pszGuid /* Optional */ ) { DWORD dwError = 0; VDIR_OPERATION ldapOp = {0}; dwError = VmDirInitStackOperation( &ldapOp, VDIR_OPERATION_TYPE_INTERNAL, LDAP_REQ_ADD, pSchemaCtx ); BAIL_ON_VMDIR_ERROR(dwError); ldapOp.pBEIF = pBE; assert(ldapOp.pBEIF); ldapOp.reqDn.lberbv.bv_val = pszDN; ldapOp.reqDn.lberbv.bv_len = VmDirStringLenA(pszDN); dwError = AttrListToEntry( pSchemaCtx, pszDN, ppszEntryInitializer, ldapOp.request.addReq.pEntry); BAIL_ON_VMDIR_ERROR(dwError); ldapOp.request.addReq.pEntry->eId = ulEntryId; if (!IsNullOrEmptyString(pszGuid)) { dwError = VmDirAllocateStringA(pszGuid, &ldapOp.request.addReq.pEntry->pszGuid); BAIL_ON_VMDIR_ERROR(dwError); } dwError = VmDirInternalAddEntry(&ldapOp); BAIL_ON_VMDIR_ERROR(dwError); cleanup: VmDirFreeOperationContent(&ldapOp); return dwError; error: goto cleanup; }
DWORD VmwDeployValidateSiteName( PCSTR pszSite ) { DWORD dwError = 0; BOOLEAN bHasSpecialChars = FALSE; VMW_DEPLOY_LOG_DEBUG( "Validating site name [%s]", VMW_DEPLOY_SAFE_LOG_STRING(pszSite)); if (!IsNullOrEmptyString(pszSite)) { PCSTR pszCursor = pszSite; while (*pszCursor && !bHasSpecialChars) { switch (*pszCursor) { case '!': case '@': case '#': case '$': case '%': case '^': case '&': case '*': case '[': case ']': bHasSpecialChars = TRUE; break; default: pszCursor++; break; } } } if (bHasSpecialChars) { VMW_DEPLOY_LOG_ERROR( "Site name [%s] has invalid characters", VMW_DEPLOY_SAFE_LOG_STRING(pszSite)); dwError = ERROR_INVALID_PARAMETER; BAIL_ON_DEPLOY_ERROR(dwError); } error: return dwError; }
uint32_t TDNFGetGPGCheck( PTDNF pTdnf, const char* pszRepo, int* pnGPGCheck, char** ppszUrlGPGKey ) { uint32_t dwError = 0; PTDNF_REPO_DATA pRepo = NULL; int nGPGCheck = 0; char* pszUrlGPGKey = NULL; if(!pTdnf || !ppszUrlGPGKey || IsNullOrEmptyString(pszRepo)) { dwError = ERROR_TDNF_INVALID_PARAMETER; BAIL_ON_TDNF_ERROR(dwError); } if(!pTdnf->pArgs->nNoGPGCheck) { dwError = TDNFGetRepoById(pTdnf, pszRepo, &pRepo); if(dwError == ERROR_TDNF_NO_DATA) { dwError = 0; } BAIL_ON_TDNF_ERROR(dwError); if(pRepo) { nGPGCheck = pRepo->nGPGCheck; if(nGPGCheck) { dwError = TDNFAllocateString( pRepo->pszUrlGPGKey, &pszUrlGPGKey); BAIL_ON_TDNF_ERROR(dwError); } } } *pnGPGCheck = nGPGCheck; *ppszUrlGPGKey = pszUrlGPGKey; cleanup: return dwError; error: if(ppszUrlGPGKey) { *ppszUrlGPGKey = NULL; } TDNF_SAFE_FREE_MEMORY(pszUrlGPGKey); goto cleanup; }