DWORD VdcGetUsersPassword( PCOMMAND_LINE_PARAMETER_STATE pParameters, PSTR pszPasswordBuf, DWORD dwBufferSize ) { DWORD dwError = 0; if (pParameters->pszPasswordFile != NULL) { dwError = VmDirReadStringFromFile(pParameters->pszPasswordFile, pszPasswordBuf, sizeof(pszPasswordBuf)); BAIL_ON_VMDIR_ERROR(dwError); } else if (pParameters->pszPassword) { // // VmDirStringCpyA expects the buffer size to *not* include the terminating null. // dwError = VmDirStringCpyA(pszPasswordBuf, dwBufferSize - 1, pParameters->pszPassword); BAIL_ON_VMDIR_ERROR(dwError); } else { // // VmDirReadString expects the buffer size to include the terminating null. // VmDirReadString("password: ", pszPasswordBuf, dwBufferSize, FALSE); } cleanup: return dwError; error: goto cleanup; }
DWORD VmDirPagedSearchCacheInsert( PVDIR_OPERATION pOperation, DWORD dwCandidatesProcessed ) { DWORD dwError = 0; PVDIR_PAGED_SEARCH_RECORD pSearchRecord = NULL; if (*pOperation->showPagedResultsCtrl->value.pagedResultCtrlVal.cookie == '\0') { dwError = VmDirPagedSearchCacheNodeAllocate( &pSearchRecord, pOperation, dwCandidatesProcessed); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirStringCpyA( pOperation->showPagedResultsCtrl->value.pagedResultCtrlVal.cookie, VMDIR_ARRAY_SIZE(pOperation->showPagedResultsCtrl->value.pagedResultCtrlVal.cookie), pSearchRecord->pszGuid ); BAIL_ON_VMDIR_ERROR(dwError); } cleanup: return dwError; error: VmDirPagedSearchCacheRecordFree(pSearchRecord); goto cleanup; }
DWORD VmDirGetVmDirLogPath( PSTR pszPath, PCSTR pszLogFile) { DWORD dwError = 0; #ifndef _WIN32 //BUGBUG, should NOT hard code path dwError = VmDirStringCpyA(pszPath, MAX_PATH, "/var/log/vmware/vmdir/"); BAIL_ON_VMDIR_ERROR(dwError); #else _TCHAR* programDataPath = NULL; if ((dwError = VmDirGetRegKeyValue( VMDIR_CONFIG_SOFTWARE_KEY_PATH, VMDIR_REG_KEY_LOG_PATH, pszPath, MAX_PATH )) != 0) { dwError = VmDirGetProgramDataEnvVar((_TCHAR *)"PROGRAMDATA", &programDataPath); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirStringPrintFA(pszPath, MAX_PATH, "%s%s", programDataPath, "\\vmware\\cis\\logs\\vmdird\\"); BAIL_ON_VMDIR_ERROR(dwError); } #endif dwError = VmDirStringCatA(pszPath, MAX_PATH, pszLogFile); BAIL_ON_VMDIR_ERROR(dwError); cleanup: #ifdef _WIN32 VMDIR_SAFE_FREE_MEMORY(programDataPath); #endif return dwError; error: VmDirLog(LDAP_DEBUG_ERROR, "VmDirGetVmDirLogPath failed with error (%u)\n", dwError); goto cleanup; }
int VmDirSendSearchEntry( PVDIR_OPERATION pOperation, PVDIR_ENTRY pSrEntry ) { int retVal = LDAP_SUCCESS; BerElementBuffer berbuf; BerElement * ber = (BerElement *) &berbuf; BOOLEAN bFreeBer = FALSE; ber_len_t iBlobSize = 0; BerValue lberBervEntryBlob = {0}; int nAttrs = 0; int nVals = 0; BOOLEAN attrMetaDataReqd = FALSE; SearchReq * sr = &(pOperation->request.searchReq); int i = 0; BOOLEAN nonTrivialAttrsInReplScope = FALSE; uint32_t iSearchReqSpecialChars = 0; PATTRIBUTE_META_DATA_NODE pAttrMetaData = NULL; int numAttrMetaData = 0; PVDIR_ATTRIBUTE pAttr = NULL; USN usnChanged = 0; PSTR pszLocalErrorMsg = NULL; if ( !pOperation || !pSrEntry ) { retVal = ERROR_INVALID_PARAMETER; BAIL_ON_VMDIR_ERROR(retVal); } pSrEntry->bSearchEntrySent = FALSE; // see if client request has "*" and/or "+" ("-" for userpassword internal to vmdir) // WEI TODO: when we have attribute level ACL check, this information will be useful // return result will depend on ACL each on each attribute client is asking before // generating a final result to send back SetSpecialReturnChar(&pOperation->request.searchReq, &iSearchReqSpecialChars); if ( pSrEntry->eId == DSE_ROOT_ENTRY_ID && pOperation->request.searchReq.attrs == NULL ) { // For ADSI, if no specific attributes requested of DSE ROOT search, // return ALL (include operational) attributes. iSearchReqSpecialChars |= LDAP_SEARCH_REQUEST_CHAR_OP; } // ACL check before processing/sending the current srEntry back retVal = VmDirSrvAccessCheck( pOperation, &pOperation->conn->AccessInfo, pSrEntry, VMDIR_RIGHT_DS_READ_PROP ); BAIL_ON_VMDIR_ERROR( retVal ); if ( pOperation->opType == VDIR_OPERATION_TYPE_INTERNAL ) { ; // no op in INTERNAL case } else { // If not replication, and showDeletedObjectsCtrl not present, => don't send back Deleted objects (tombstones). if (pOperation->syncReqCtrl == NULL && pOperation->showDeletedObjectsCtrl == NULL) { pAttr = VmDirEntryFindAttribute(ATTR_IS_DELETED, pSrEntry); if (pAttr) { if (VmDirStringCompareA((PSTR)pAttr->vals[0].lberbv.bv_val, VMDIR_IS_DELETED_TRUE_STR, FALSE) == 0) { goto cleanup; // Don't send this entry } } } // In case of replication request, skip certain updates if (pOperation->syncReqCtrl != NULL) { PVDIR_ATTRIBUTE pAttrUsnCreated = NULL; USN usnCreated = 0; USN limitUsn = 0; VMDIR_REPLICATION_AGREEMENT * replAgr = NULL; pAttr = VmDirEntryFindAttribute(ATTR_USN_CHANGED, pSrEntry); assert( pAttr != NULL ); usnChanged = VmDirStringToLA( pAttr->vals[0].lberbv.bv_val, NULL, 10); // Check if usnChanged is beyond successful replication update state limitUsn = VmDirdGetLimitLocalUsnToBeSupplied(); if (limitUsn != 0 && usnChanged >= limitUsn) { VMDIR_LOG_INFO(VMDIR_LOG_MASK_ALL, "SendSearchEntry: bug# 863244 RACE CONDITION encountered., " "usnChanged = %ld, limitLocalUsnToBeSupplied = %ld, skipping entry: %s", usnChanged, limitUsn, pSrEntry->dn.lberbv.bv_val ); goto cleanup; // Don't send this entry } // Check if usnChanged is beyond lowestPendingUncommittedUsn recorded at the beginning of replication search if (pOperation->lowestPendingUncommittedUsn != 0 && usnChanged >= pOperation->lowestPendingUncommittedUsn) { VMDIR_LOG_INFO( LDAP_DEBUG_REPL, "SendSearchEntry: usnChanged = %ld, lowestPendingUncommittedUsn = %ld, " "skipping entry: %s", usnChanged, pOperation->lowestPendingUncommittedUsn, pSrEntry->dn.lberbv.bv_val ); goto cleanup; // Don't send this entry } // Don't send (skip) modifications to my server object, and my RAs pAttrUsnCreated = VmDirEntryFindAttribute(ATTR_USN_CREATED, pSrEntry); assert( pAttrUsnCreated != NULL ); usnCreated = VmDirStringToLA( pAttrUsnCreated->vals[0].lberbv.bv_val, NULL, 10); // Only send back creation of certain objects, and not their modifications. // Check if consumer has already seen the creation. If yes, we are dealing with mods, which should be skipped // for my server object, and my RAs // Note: Skipping mods for RAs and Server Objects will cause inconsistencies with replicas. But these // two types only have local scope regarding functional effects. But if we are looking up / processing // information for these two types of objects on a replica, we need to watch out for potential // inconsistencies against the original source. if (pOperation->syncReqCtrl->value.syncReqCtrlVal.intLastLocalUsnProcessed > usnCreated) { if (strcmp(pSrEntry->dn.bvnorm_val, gVmdirServerGlobals.serverObjDN.bvnorm_val) == 0) { VMDIR_LOG_INFO( LDAP_DEBUG_REPL, "SendSearchEntry: Not sending modifications to my server object, DN: %s", gVmdirServerGlobals.serverObjDN.lberbv.bv_val ); goto cleanup; // Don't send this entry } for (replAgr = gVmdirReplAgrs; replAgr != NULL; replAgr = replAgr->next ) { if (strcmp(pSrEntry->dn.bvnorm_val, replAgr->dn.bvnorm_val) == 0) { VMDIR_LOG_INFO( LDAP_DEBUG_REPL, "SendSearchEntry: Not sending modifications to my RA object, DN: %s", replAgr->dn.bvnorm_val ); goto cleanup; // Don't send this entry } } } // do not replicate DSE Root entry, because it is a "local" entry. if (pSrEntry->eId == DSE_ROOT_ENTRY_ID) { VMDIR_LOG_INFO( LDAP_DEBUG_REPL, "SendSearchEntry: Not sending modifications to DSE Root entry, DN: %s", pSrEntry->dn.bvnorm_val ); goto cleanup; // Don't send this entry } } // Approximate calculation for the required ber size, because apart from lengths and strings, ber also includes // tags. if ( VmDirComputeEncodedEntrySize(pSrEntry, &nAttrs, &nVals, &iBlobSize) != 0 || VmDirAllocateMemory(iBlobSize, (PVOID*)&lberBervEntryBlob.bv_val) != 0 ) { retVal = LDAP_OPERATIONS_ERROR; BAIL_ON_VMDIR_ERROR_WITH_MSG( retVal, (pszLocalErrorMsg), "no memory"); } lberBervEntryBlob.bv_len = iBlobSize; ber_init2( ber, &lberBervEntryBlob, LBER_USE_DER ); // ber takes over lberBervEntryBlob.lberbv.bv_val ownership bFreeBer = TRUE; if ( ber_printf( ber, "{it{O{", pOperation->msgId, LDAP_RES_SEARCH_ENTRY, &pSrEntry->dn ) == -1) { VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "SendSearchEntry: ber_printf (to print msgId ...) failed" ); retVal = LDAP_OTHER; BAIL_ON_VMDIR_ERROR_WITH_MSG( retVal, (pszLocalErrorMsg), "Encoding msgId, RES_SEARCH_ENTRY, DN failed"); } // Determine if we need to send back the attribute metaData if ( pOperation->syncReqCtrl != NULL ) // Replication { attrMetaDataReqd = TRUE; } else // check if attrMetaData attribute has been requested explicitly. { if (sr->attrs != NULL) { for (i = 0; sr->attrs[i].lberbv.bv_val != NULL; i++) { if (VmDirStringCompareA( sr->attrs[i].lberbv.bv_val, ATTR_ATTR_META_DATA, FALSE) == 0) { attrMetaDataReqd = TRUE; break; } } } } if (attrMetaDataReqd) { if ((pOperation->pBEIF->pfnBEGetAllAttrsMetaData( pOperation->pBECtx, pSrEntry->eId, &pAttrMetaData, &numAttrMetaData )) != 0) { VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "SendSearchEntry: pfnBEGetAllAttrsMetaData failed for entryId: %ld", pSrEntry->eId); retVal = LDAP_OPERATIONS_ERROR; BAIL_ON_VMDIR_ERROR_WITH_MSG( retVal, (pszLocalErrorMsg), "pfnBEGetAllAttrsMetaData failed."); } // SJ-TBD: Following double for loop to be optimized // Copy attrMetaData to corresponding attributes for (i=0; i<numAttrMetaData; i++) { for ( pAttr = pSrEntry->attrs; pAttr != NULL; pAttr = pAttr->next) { if (pAttr->pATDesc->usAttrID == pAttrMetaData[i].attrID) { VmDirStringCpyA( pAttr->metaData, VMDIR_MAX_ATTR_META_DATA_LEN, pAttrMetaData[i].metaData ); pAttrMetaData[i].metaData[0] = '\0'; } } } } retVal = WriteAttributes( pOperation, pSrEntry, iSearchReqSpecialChars , ber, &pszLocalErrorMsg ); BAIL_ON_VMDIR_ERROR( retVal ); if (attrMetaDataReqd) { retVal = WriteMetaDataAttribute( pOperation, pSrEntry->attrs, numAttrMetaData, pAttrMetaData, ber, &nonTrivialAttrsInReplScope, &pszLocalErrorMsg ); BAIL_ON_VMDIR_ERROR( retVal ); } if (ber_printf( ber, "N}N}" ) == -1) { VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "ber_printf (to terminate the entry and the complete search result entry message ...) failed" ); retVal = LDAP_OTHER; BAIL_ON_VMDIR_ERROR_WITH_MSG( retVal, (pszLocalErrorMsg), "Encoding terminating the entry failed."); } if ( pOperation->syncReqCtrl != NULL ) // Replication, => write Sync State Control { retVal = WriteSyncStateControl( pOperation, pSrEntry->attrs, ber, &pszLocalErrorMsg ); BAIL_ON_VMDIR_ERROR( retVal ); } if (ber_printf( ber, "N}" ) == -1) { VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "ber_printf (to terminate the entry and the complete search result entry message ...) failed" );; retVal = LDAP_OTHER; BAIL_ON_VMDIR_ERROR_WITH_MSG( retVal, (pszLocalErrorMsg), "Encoding terminating the entry failed."); } if ((pOperation->syncReqCtrl == NULL) || (pOperation->syncReqCtrl != NULL && nonTrivialAttrsInReplScope )) { if (WriteBerOnSocket( pOperation->conn, ber ) != 0) { VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "SendSearchEntry: WriteBerOnSocket failed." ); retVal = LDAP_UNAVAILABLE; BAIL_ON_VMDIR_ERROR( retVal ); } pSrEntry->bSearchEntrySent = TRUE; sr->iNumEntrySent++; VMDIR_LOG_INFO( LDAP_DEBUG_REPL, "SendSearchEntry: Send entry: %s", pSrEntry->dn.lberbv.bv_val); } else { VMDIR_LOG_INFO( LDAP_DEBUG_REPL, "SendSearchEntry: NOT Sending entry: %s %p %d", pSrEntry->dn.lberbv.bv_val, pOperation->syncReqCtrl, nonTrivialAttrsInReplScope); } // record max local usnChanged in syncControlDone if (pOperation->syncReqCtrl != NULL) { if (usnChanged > pOperation->syncDoneCtrl->value.syncDoneCtrlVal.intLastLocalUsnProcessed) { pOperation->syncDoneCtrl->value.syncDoneCtrlVal.intLastLocalUsnProcessed = usnChanged; } } retVal = LDAP_SUCCESS; } cleanup: if (bFreeBer) { ber_free_buf( ber ); } VMDIR_SAFE_FREE_MEMORY( pAttrMetaData ); VMDIR_SAFE_FREE_MEMORY(pszLocalErrorMsg); return( retVal ); error: VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "SendSearchEntry failed DN=(%s), (%u)(%s)", (pSrEntry && pSrEntry->dn.lberbv.bv_val) ? pSrEntry->dn.lberbv.bv_val : "", retVal, VDIR_SAFE_STRING( pszLocalErrorMsg)); if ( !pOperation->ldapResult.pszErrMsg && pszLocalErrorMsg ) { pOperation->ldapResult.pszErrMsg = pszLocalErrorMsg; pszLocalErrorMsg = NULL; } goto cleanup; }
int VmDirMain(int argc, char* argv[]) { DWORD dwError = 0; PSTR pszUserName = NULL; PSTR pszPartnerHost = NULL; PSTR pszPassword = NULL; PSTR pszPasswordBuf = NULL; CHAR pszPath[MAX_PATH]; CHAR pszLocalHostName[VMDIR_MAX_HOSTNAME_LEN] = {0}; #ifndef _WIN32 setlocale(LC_ALL,""); #endif dwError = VmDirGetVmDirLogPath(pszPath, "vdcresetMachineActCred.log"); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirLogInitialize(pszPath, FALSE, NULL, VMDIR_LOG_INFO, VMDIR_LOG_MASK_ALL ); BAIL_ON_VMDIR_ERROR(dwError); //get commandline parameters dwError = VmDirParseArgs(argc, argv, &pszUserName, &pszPartnerHost, &pszPassword); if ( dwError ) { ShowUsage(); goto cleanup; } dwError = VmDirAllocateMemory(VMDIR_MAX_PWD_LEN+1, (PVOID *)&pszPasswordBuf); BAIL_ON_VMDIR_ERROR(dwError); if ( pszPassword != NULL ) { dwError = VmDirStringCpyA(pszPasswordBuf, VMDIR_MAX_PWD_LEN, pszPassword); BAIL_ON_VMDIR_ERROR(dwError); } else //no password, read password from stdin { VmDirReadString("password: "******"vdcresetMachineActCred completed.\n"); VMDIR_LOG_INFO( VMDIR_LOG_MASK_ALL, "vdcresetMachineActCred completed."); cleanup: VMDIR_SAFE_FREE_MEMORY(pszPasswordBuf); VmDirLogTerminate(); return dwError; error: printf("vdcresetMachineActCred failed. Error[%d]\n", dwError); goto cleanup; }
static DWORD _PopulateOperationModAttributes( LDAP *pLd, LDAPMessage *pEntry, PVDIR_OPERATION pLdapOp ) { DWORD dwError = 0; struct berval** ppValues = NULL; PLW_HASHMAP pHashMap = NULL; PSTR pszBuf = NULL; PSTR pszAttrName = NULL; PSTR pszAttrMetaData = NULL; PSTR pszAttrUsnlessMetaData = NULL; PSTR pszAttrNewMetaData = NULL; PSTR pszKey = NULL; PSTR pszValue = NULL; USN localUsn = 0; PVDIR_BERVALUE pBerValue = NULL; size_t iBerValueSize = 0; DWORD i = 0, j = 0; dwError = LwRtlCreateHashMap( &pHashMap, LwRtlHashDigestPstrCaseless, LwRtlHashEqualPstrCaseless, NULL ); BAIL_ON_VMDIR_ERROR(dwError); dwError = pLdapOp->pBEIF->pfnBEGetNextUSN(pLdapOp->pBECtx, &localUsn); BAIL_ON_VMDIR_ERROR(dwError); if (!(ppValues = ldap_get_values_len(pLd, pEntry, ATTR_ATTR_META_DATA))) { dwError = VMDIR_ERROR_SCHEMA_BAD_METADATA; BAIL_ON_VMDIR_ERROR(dwError); } for (i = 0; ppValues[i] != NULL; i++) { dwError = VmDirAllocateStringA(ppValues[i]->bv_val, &pszBuf); BAIL_ON_VMDIR_ERROR(dwError); pszAttrName = VmDirStringTokA(pszBuf, ":", &pszAttrMetaData); VmDirStringTokA(pszAttrMetaData, ":", &pszAttrUsnlessMetaData); dwError = VmDirAllocateStringPrintf( &pszAttrNewMetaData, "%ld:%s", localUsn, pszAttrUsnlessMetaData); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirAllocateStringA(pszAttrName, &pszKey); BAIL_ON_VMDIR_ERROR(dwError); dwError = LwRtlHashMapInsert(pHashMap, pszKey, pszAttrNewMetaData, NULL); BAIL_ON_VMDIR_ERROR(dwError); VMDIR_SAFE_FREE_MEMORY(pszBuf); } ldap_value_free_len(ppValues); ppValues = NULL; for (i = 0; ppszSchemaEntryAttrs[i] != NULL; i++) { if (VmDirStringCompareA(ppszSchemaEntryAttrs[i], ATTR_ATTR_META_DATA, FALSE) != 0) { ppValues = ldap_get_values_len(pLd, pEntry, ppszSchemaEntryAttrs[i]); if (ppValues) { iBerValueSize = ldap_count_values_len(ppValues); dwError = VmDirAllocateMemory( sizeof(VDIR_BERVALUE) * iBerValueSize, (PVOID*)&pBerValue); BAIL_ON_VMDIR_ERROR(dwError); if (VmDirStringCompareA(ppszSchemaEntryAttrs[i], ATTR_USN_CHANGED, FALSE) == 0) { assert(iBerValueSize == 1); dwError = VmDirAllocateStringPrintf(&pBerValue[0].lberbv_val, "%ld", localUsn); BAIL_ON_VMDIR_ERROR(dwError); pBerValue[0].lberbv_len = VmDirStringLenA(pBerValue[0].lberbv_val); pBerValue[0].bOwnBvVal = TRUE; } else { for (j = 0; j < iBerValueSize; j++) { dwError = VmDirAllocateStringA(ppValues[j]->bv_val, &pBerValue[j].lberbv_val); BAIL_ON_VMDIR_ERROR(dwError); pBerValue[j].lberbv_len = ppValues[j]->bv_len; pBerValue[j].bOwnBvVal = TRUE; } } dwError = VmDirOperationAddModReq( pLdapOp, MOD_OP_REPLACE, ppszSchemaEntryAttrs[i], pBerValue, iBerValueSize); BAIL_ON_VMDIR_ERROR(dwError); dwError = LwRtlHashMapFindKey( pHashMap, (PVOID*)&pszValue, ppszSchemaEntryAttrs[i]); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirStringCpyA( pLdapOp->request.modifyReq.mods->attr.metaData, VMDIR_MAX_ATTR_META_DATA_LEN, pszValue); BAIL_ON_VMDIR_ERROR(dwError); ldap_value_free_len(ppValues); ppValues = NULL; for (j = 0; j < iBerValueSize; j++) { VmDirFreeBervalContent(&pBerValue[j]); } VMDIR_SAFE_FREE_MEMORY(pBerValue); } } } cleanup: LwRtlHashMapClear(pHashMap, _FreeStringPair, NULL); LwRtlFreeHashMap(&pHashMap); return dwError; error: VMDIR_LOG_ERROR( VMDIR_LOG_MASK_ALL, "%s,%d failed, error(%d)", __FUNCTION__, __LINE__, dwError ); VMDIR_SAFE_FREE_MEMORY(pszBuf); VMDIR_SAFE_FREE_MEMORY(pszAttrNewMetaData); if (ppValues) { ldap_value_free_len(ppValues); } for (j = 0; j < iBerValueSize; j++) { VmDirFreeBervalContent(&pBerValue[j]); } VMDIR_SAFE_FREE_MEMORY(pBerValue); goto cleanup; }
DWORD VmDirReplAgrEntryToInMemory( PVDIR_ENTRY pEntry, PVMDIR_REPLICATION_AGREEMENT * ppReplAgr ) { DWORD dwError = 0; PVMDIR_REPLICATION_AGREEMENT pReplAgr; PVDIR_ATTRIBUTE pAttr = NULL; VDIR_BERVALUE bv = VDIR_BERVALUE_INIT; if (!ppReplAgr) { BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_PARAMETER); } dwError = VmDirAllocateMemory( sizeof(VMDIR_REPLICATION_AGREEMENT), (PVOID*)&pReplAgr); BAIL_ON_VMDIR_ERROR(dwError); for (pAttr = pEntry->attrs; pAttr; pAttr = pAttr->next) { if (VmDirStringCompareA(pAttr->pATDesc->pszName, ATTR_LABELED_URI, FALSE) == 0) { dwError = VmDirStringCpyA( pReplAgr->ldapURI, VMDIR_MAX_LDAP_URI_LEN, pAttr->vals[0].lberbv.bv_val); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirLdapURI2Host( pReplAgr->ldapURI, &pReplAgr->pszHostname); BAIL_ON_VMDIR_ERROR(dwError); } else if (VmDirStringCompareA(pAttr->pATDesc->pszName, ATTR_LAST_LOCAL_USN_PROCESSED, FALSE) == 0) { dwError = VmDirBervalContentDup( &pAttr->vals[0], &pReplAgr->lastLocalUsnProcessed); BAIL_ON_VMDIR_ERROR(dwError); } else if (VmDirStringCompareA(pAttr->pATDesc->pszName, ATTR_DN, FALSE) == 0) { dwError = VmDirBervalContentDup(&pAttr->vals[0], &pReplAgr->dn); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirNormalizeDN(&pReplAgr->dn, pEntry->pSchemaCtx); BAIL_ON_VMDIR_ERROR(dwError); } } if (pReplAgr->lastLocalUsnProcessed.lberbv.bv_val == NULL) // Since ATTR_LAST_LOCAL_USN_PROCESSED is an optional attribute. { bv.lberbv.bv_val = VMDIR_DEFAULT_REPL_LAST_USN_PROCESSED; bv.lberbv.bv_len = VMDIR_DEFAULT_REPL_LAST_USN_PROCESSED_LEN; dwError = VmDirBervalContentDup(&bv, &pReplAgr->lastLocalUsnProcessed); BAIL_ON_VMDIR_ERROR(dwError); } dwError = _VmDirReplDCConnectInit(pReplAgr); BAIL_ON_VMDIR_ERROR(dwError); VMDIR_LOG_INFO( VMDIR_LOG_MASK_ALL, "Replication partner: (%s) lastLocalUsnProcessed: (%s)", pReplAgr->ldapURI, pReplAgr->lastLocalUsnProcessed.lberbv_val); *ppReplAgr = pReplAgr; cleanup: return dwError; error: VmDirFreeReplicationAgreement(pReplAgr); goto cleanup; }
DWORD VmDirConstructReplAgr( PVDIR_SCHEMA_CTX pSchemaCtx, PCSTR pszReplURI, PCSTR pszLastLocalUsnProcessed, PCSTR pszReplAgrDN, PVMDIR_REPLICATION_AGREEMENT * ppReplAgr ) { DWORD dwError = 0; VDIR_BERVALUE bv = VDIR_BERVALUE_INIT; PVMDIR_REPLICATION_AGREEMENT pReplAgr = NULL; if (!pSchemaCtx || IsNullOrEmptyString(pszReplURI) || IsNullOrEmptyString(pszLastLocalUsnProcessed) || IsNullOrEmptyString(pszReplAgrDN) || !ppReplAgr) { BAIL_WITH_VMDIR_ERROR(dwError, VMDIR_ERROR_INVALID_PARAMETER); } dwError = VmDirAllocateMemory( sizeof(VMDIR_REPLICATION_AGREEMENT), (PVOID*)&pReplAgr); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirStringCpyA(pReplAgr->ldapURI, VMDIR_MAX_LDAP_URI_LEN, pszReplURI); BAIL_ON_VMDIR_ERROR(dwError); dwError = VmDirLdapURI2Host(pReplAgr->ldapURI, &pReplAgr->pszHostname); BAIL_ON_VMDIR_ERROR(dwError); bv.lberbv.bv_val = (PSTR)pszLastLocalUsnProcessed; bv.lberbv.bv_len = VmDirStringLenA(bv.lberbv.bv_val); dwError = VmDirBervalContentDup(&bv, &pReplAgr->lastLocalUsnProcessed); BAIL_ON_VMDIR_ERROR(dwError); bv.lberbv.bv_val = (PSTR)pszReplAgrDN; bv.lberbv.bv_len = VmDirStringLenA(bv.lberbv.bv_val); dwError = VmDirBervalContentDup(&bv, &pReplAgr->dn); BAIL_ON_VMDIR_ERROR(dwError); if (pReplAgr->dn.bvnorm_val == NULL) { dwError = VmDirNormalizeDN(&pReplAgr->dn, pSchemaCtx); BAIL_ON_VMDIR_ERROR(dwError); } dwError = _VmDirReplDCConnectInit(pReplAgr); BAIL_ON_VMDIR_ERROR(dwError); *ppReplAgr = pReplAgr; cleanup: return dwError; error: VmDirFreeReplicationAgreement(pReplAgr); goto cleanup; }