// Print all the data include the entity properties
void EntityManager_PrintFull(FILE *ofp, const char *header, const EntityManager *entityManager) {
  htab *t = NULL;

  if (header != NULL) fprintf(ofp, "%s\n", header); // print the header even for NULL items
  if (entityManager == NULL) {
    snprintf(errStr, sizeof(errStr), "EntityManager_PrintFull: entityManager must not be NULL");
    return;
  }
  t = entityManager->Users->Items;
  if (hfirst(t)) {
    do {
      fullPrintUser(ofp, "", (void *)hstuff(t));
    } while (hnext(t));
  }
  t = entityManager->Groups->Items;
  if (hfirst(t)) {
    do {
      fullPrintGroup(ofp, "", (void *)hstuff(t));
    } while (hnext(t));
  }
  t = entityManager->Resources->Items;
  if (hfirst(t)) {
    do {
      fullPrintResource(ofp, "", (void *)hstuff(t));
    } while (hnext(t));
  }
  fprintf(ofp, "\n");
}
STATIC bool calcHash(const SecureStorageS *storage, unsigned char *hash) {
  int16_t i = 0, len = 0, secretLen = 0;
  htab *t = NULL;
  unsigned char tmpHash[SHA256_LEN], cHash[crypto_auth_BYTES];
  unsigned char *data = NULL;

  if (storage == NULL || hash == NULL) {
    assert(LIB_NAME "Storage structure and hash string must not be NULL" && (false || Storage_TestMode));
    return false;
  }
  t = storage->Data;
  memset(hash, 0, SHA256_LEN);
  if (hfirst(t)) {
    do {
      for (i = 0; i < 2; i++) {
        if (i == 0)
          data = (unsigned char *)hkey(t);
        else
          data = (unsigned char *)hstuff(t);
        if (Utils_GetCharArrayLen(data, &len, KEY_VAL_MIN_STR_LEN, KEY_VAL_MAX_STR_LEN) == false) return false;
        len += UTILS_STR_LEN_SIZE;
        if (Utils_GetCharArrayLen(storage->caSecret, &secretLen, KEY_VAL_MIN_STR_LEN, KEY_VAL_MAX_STR_LEN) == false) {
          return false;
        }
        Crypto_CalcHmac(&(storage->caSecret[UTILS_STR_LEN_SIZE]), secretLen, data, len, cHash);
        memcpy(tmpHash, cHash, SHA256_LEN);
        calcHashXor(hash, tmpHash, crypto_auth_BYTES);
      }
    } while (hnext(t));
  }
  return true;
}
STATIC void printGroup(FILE *ofp, const char *header, const void *u) {
  const groupData *entity = NULL;

  fprintf(ofp, "%s", header);
  if (u == NULL) return;
  entity = (const groupData *)u;
  fprintf(ofp, "***** Group name: '%s'\n", entity->Name);
  fprintf(ofp, "Members: ");
  if (hfirst(entity->Members)) {
    do {
      fprintf(ofp, "'%s', ", (char *)hkey(entity->Members));
    } while (hnext(entity->Members));
  }
  fprintf(ofp, "\n");
}
STATIC bool removeUserFromAllGroups(EntityManager *entityManager, const char *name) {
  htab *t = NULL;
  groupData *g = NULL;

  if (entityManager == NULL || name == NULL) {
    assert(LIB_NAME "EntityManager structure and name string must not be NULL" && (false || Entity_TestMode));
    return false;
  }
  t = entityManager->Groups->Items;
  if (hfirst(t)) {
    do {
      g = (groupData *)hstuff(t);
      EntityManager_RemoveUserFromGroup(entityManager, g->Name, name);
    } while (hnext(t));
  }
  return true;
}
STATIC bool removeUserFromAllResources(EntityManager *entityManager, const char *name) {
  htab *t = NULL;
  resourceData *r = NULL;
  void *a = NULL;

  if (entityManager == NULL || name == NULL) {
    assert(LIB_NAME "EntityManager structure and name string must not be NULL" && (false || Entity_TestMode));
    return false;
  }
  t = entityManager->Resources->Items;
  if (hfirst(t)) {
    do {
      r = (resourceData *)hstuff(t);
      if (EntityManager_GetProperty(entityManager, r->Name, ACL_PROPERTY_NAME, &a) == true) {
        Acl_RemoveEntry(a, name);
      }
    } while (hnext(t));
  }
  return true;
}
// Handling the hash and the random entries:
//   Both are not encrypted and not hex represented in the table therefore,
//   they must be converted to hex representation and
//   are saved with prefix to be destinguest when reading the file
STATIC void writeKeyValue(FILE *fp, const SecureStorageS *storage) {
  htab *t = NULL;

  if (storage == NULL) {
    assert(LIB_NAME "Storage structure must not be NULL" && (false || Storage_TestMode));
    return;
  }
  t = storage->Data;
  fprintf(fp, TOTAL_STR_FMT, (int)hcount(t)); // number of items in the hash
  debug_print("Total number of items to write %d\n", (int16_t)hcount(t));
  if (hfirst(t)) {
    do {
      Utils_WriteCharArray(fp, (unsigned char *)hkey(t));
      Utils_WriteCharArray(fp, (unsigned char *)hstuff(t));
      if (SECURE_DEBUG) {
        printDecryptedData("write:", (unsigned char *)hkey(t), (unsigned char *)hstuff(t), storage->caSecret);
      }
    } while (hnext(t));
  }
}
Exemplo n.º 7
0
int print_rpc_args(json_rpc_t *json_rpc, char *s, size_t n)
{
	int ret;
	size_t rem = n;

	if (hfirst(json_rpc->params_htab)) do
	{
		const char *name;
		json_val_t *val;

		name = (const char *)hkey(json_rpc->params_htab);
		val = hstuff(json_rpc->params_htab);

		ret = print_basic_type(s, rem, name, val);

		s += ret;
		rem -= ret;
	}
	while (hnext(json_rpc->params_htab) && rem > 0);

	return n-rem;
}