예제 #1
0
void const* TRI_LookupByElementAssociativeSynced (TRI_associative_synced_t* array,
                                                  void const* element) {
  void const* result;

  // compute the hash
  uint64_t const hash = array->hashElement(array, element);

  // search the table
  TRI_ReadLockReadWriteLock(&array->_lock);
  uint64_t const n = array->_nrAlloc;
  uint64_t i, k;

  i = k = hash % n;

  for (; i < n && array->_table[i] != nullptr && ! array->isEqualElementElement(array, element, array->_table[i]); ++i);

  if (i == n) {
    for (i = 0; i < k && array->_table[i] != nullptr && ! array->isEqualElementElement(array, element, array->_table[i]); ++i);
  }

  result = array->_table[i];

  TRI_ReadUnlockReadWriteLock(&array->_lock);

  // return whatever we found
  return result;
}
예제 #2
0
void const* TRI_LookupByElementAssociativeSynced (TRI_associative_synced_t* array,
                                                  void const* element) {
  uint64_t hash;
  uint64_t i;
  void const* result;

  // compute the hash
  hash = array->hashElement(array, element);
  i = hash % array->_nrAlloc;

#ifdef TRI_INTERNAL_STATS
  // update statistics
  array->_nrFinds++;
#endif

  // search the table
  TRI_ReadLockReadWriteLock(&array->_lock);

  while (array->_table[i] != NULL && ! array->isEqualElementElement(array, element, array->_table[i])) {
    i = (i + 1) % array->_nrAlloc;
#ifdef TRI_INTERNAL_STATS
    array->_nrProbesF++;
#endif
  }

  result = array->_table[i];

  TRI_ReadUnlockReadWriteLock(&array->_lock);

  // return whatever we found
  return result;
}
예제 #3
0
void const* TRI_LookupByKeyAssociativeSynced (TRI_associative_synced_t* array, void const* key) {
  uint64_t hash;
  uint64_t i;
  void const* result;

  // compute the hash
  hash = array->hashKey(array, key);
  i = hash % array->_nrAlloc;

  // update statistics
  array->_nrFinds++;

  // search the table
  TRI_ReadLockReadWriteLock(&array->_lock);

  while (array->_table[i] != NULL && ! array->isEqualKeyElement(array, key, array->_table[i])) {
    i = (i + 1) % array->_nrAlloc;
    array->_nrProbesF++;
  }

  result = array->_table[i];

  TRI_ReadUnlockReadWriteLock(&array->_lock);

  // return whatever we found
  return result;
}
예제 #4
0
size_t TRI_GetLengthAssociativeSynced (TRI_associative_synced_t* const array) {
  uint32_t result;

  TRI_ReadLockReadWriteLock(&array->_lock);
  result = array->_nrUsed;
  TRI_ReadUnlockReadWriteLock(&array->_lock);

  return (size_t) result;
}
예제 #5
0
TRI_json_t* TRI_JsonReplicationApplier (TRI_replication_applier_t* applier) {
  TRI_replication_applier_state_t state;
  TRI_replication_applier_configuration_t config;
  TRI_json_t* server;
  TRI_json_t* json;
  int res;

  res = TRI_StateReplicationApplier(applier, &state);

  if (res != TRI_ERROR_NO_ERROR) {
    return NULL;
  }
    
  json = TRI_CreateArrayJson(TRI_CORE_MEM_ZONE);

  if (json == NULL) {
    TRI_DestroyStateReplicationApplier(&state);

    return NULL;
  }
  
  TRI_Insert3ArrayJson(TRI_CORE_MEM_ZONE, json, "state", JsonState(&state));
    
  // add server info
  server = TRI_CreateArrayJson(TRI_CORE_MEM_ZONE);

  if (server != NULL) {
    TRI_server_id_t serverId;

    TRI_Insert3ArrayJson(TRI_CORE_MEM_ZONE, server, "version", TRI_CreateStringCopyJson(TRI_CORE_MEM_ZONE, TRI_VERSION));

    serverId = TRI_GetIdServer();  
    TRI_Insert3ArrayJson(TRI_CORE_MEM_ZONE, server, "serverId", TRI_CreateStringJson(TRI_CORE_MEM_ZONE, TRI_StringUInt64(serverId)));

    TRI_Insert3ArrayJson(TRI_CORE_MEM_ZONE, json, "server", server);
  }
   
  TRI_InitConfigurationReplicationApplier(&config);

  TRI_ReadLockReadWriteLock(&applier->_statusLock);
  TRI_CopyConfigurationReplicationApplier(&applier->_configuration, &config);
  TRI_ReadUnlockReadWriteLock(&applier->_statusLock);

  if (config._endpoint != NULL) {
    TRI_Insert3ArrayJson(TRI_CORE_MEM_ZONE, json, "endpoint", TRI_CreateStringCopyJson(TRI_CORE_MEM_ZONE, config._endpoint));
  }
  
  if (config._database != NULL) {
    TRI_Insert3ArrayJson(TRI_CORE_MEM_ZONE, json, "database", TRI_CreateStringCopyJson(TRI_CORE_MEM_ZONE, config._database));
  }

  TRI_DestroyConfigurationReplicationApplier(&config);
  TRI_DestroyStateReplicationApplier(&state);

  return json;
}
예제 #6
0
파일: auth.c 프로젝트: aboleab/ArangoDB
bool TRI_FlushAuthenticationAuthInfo () {
  bool res;

  TRI_ReadLockReadWriteLock(&DefaultAuthInfo->_authInfoLock);
  res = DefaultAuthInfo->_authInfoFlush;
  TRI_ReadUnlockReadWriteLock(&DefaultAuthInfo->_authInfoLock);

  if (res) {
    TRI_WriteLockReadWriteLock(&DefaultAuthInfo->_authInfoLock);
    DefaultAuthInfo->_authInfoFlush = false;
    TRI_WriteUnlockReadWriteLock(&DefaultAuthInfo->_authInfoLock);
  }

  return res;
}
예제 #7
0
int TRI_StateReplicationApplier (TRI_replication_applier_t* applier,
                                 TRI_replication_applier_state_t* state) {
  TRI_InitStateReplicationApplier(state);

  TRI_ReadLockReadWriteLock(&applier->_statusLock);
  
  state->_active                      = applier->_state._active;
  state->_lastAppliedContinuousTick   = applier->_state._lastAppliedContinuousTick;
  state->_lastProcessedContinuousTick = applier->_state._lastProcessedContinuousTick;
  state->_lastAvailableContinuousTick = applier->_state._lastAvailableContinuousTick;
  state->_serverId                    = applier->_state._serverId;
  state->_lastError._code             = applier->_state._lastError._code;
  state->_failedConnects              = applier->_state._failedConnects;
  state->_totalRequests               = applier->_state._totalRequests;
  state->_totalFailedConnects         = applier->_state._totalFailedConnects;
  state->_totalEvents                 = applier->_state._totalEvents;
  memcpy(&state->_lastError._time, &applier->_state._lastError._time, sizeof(state->_lastError._time));

  if (applier->_state._progressMsg != NULL) {
    state->_progressMsg = TRI_DuplicateStringZ(TRI_CORE_MEM_ZONE, applier->_state._progressMsg);
  }
  else {
    state->_progressMsg = NULL;
  }

  memcpy(&state->_progressTime, &applier->_state._progressTime, sizeof(state->_progressTime));
  
  if (applier->_state._lastError._msg != NULL) {
    state->_lastError._msg          = TRI_DuplicateStringZ(TRI_CORE_MEM_ZONE, applier->_state._lastError._msg);
  }
  else {
    state->_lastError._msg          = NULL;
  }

  TRI_ReadUnlockReadWriteLock(&applier->_statusLock);

  return TRI_ERROR_NO_ERROR;
} 
예제 #8
0
파일: auth.c 프로젝트: aboleab/ArangoDB
bool TRI_CheckAuthenticationAuthInfo (char const* username,
                                      char const* password) {
  TRI_vocbase_auth_t* auth;
  bool res;
  char* hex;
  char* sha256;
  size_t hexLen;
  size_t len;
  size_t sha256Len;

  assert(DefaultAuthInfo);

  // look up username
  TRI_ReadLockReadWriteLock(&DefaultAuthInfo->_authInfoLock);
  auth = TRI_LookupByKeyAssociativePointer(&DefaultAuthInfo->_authInfo, username);

  if (auth == NULL || ! auth->_active) {
    TRI_ReadUnlockReadWriteLock(&DefaultAuthInfo->_authInfoLock);
    return false;
  }

  // convert password
  res = false;

  if (TRI_IsPrefixString(auth->_password, "$1$")) {
    if (strlen(auth->_password) < 12 || auth->_password[11] != '$') {
      LOG_WARNING("found corrupted password for user '%s'", username);
    }
    else {
      char* salted;

      len = 8 + strlen(password);
      salted = TRI_Allocate(TRI_CORE_MEM_ZONE, len + 1, false);
      memcpy(salted, auth->_password + 3, 8);
      memcpy(salted + 8, password, len - 8);
      salted[len] = '\0';

      sha256 = TRI_SHA256String(salted, len, &sha256Len);
      TRI_FreeString(TRI_CORE_MEM_ZONE, salted);

      hex = TRI_EncodeHexString(sha256, sha256Len, &hexLen);
      TRI_FreeString(TRI_CORE_MEM_ZONE, sha256);

      LOG_DEBUG("found active user '%s', expecting password '%s', got '%s'",
                username,
                auth->_password + 12,
                hex);

      res = TRI_EqualString(auth->_password + 12, hex);
      TRI_FreeString(TRI_CORE_MEM_ZONE, hex);
    }
  }
  else {
    len = strlen(password);
    sha256 = TRI_SHA256String(password, len, &sha256Len);

    hex = TRI_EncodeHexString(sha256, sha256Len, &hexLen);
    TRI_FreeString(TRI_CORE_MEM_ZONE, sha256);

    LOG_DEBUG("found active user '%s', expecting password '%s', got '%s'",
              username,
              auth->_password + 12,
              hex);

    res = TRI_EqualString(auth->_password, hex);
    TRI_FreeString(TRI_CORE_MEM_ZONE, hex);
  }

  TRI_ReadUnlockReadWriteLock(&DefaultAuthInfo->_authInfoLock);

  return res;
}