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 bool updateData(const SecureStorageS *storage, const unsigned char *key, const unsigned char *val) {
  int16_t kLen = 0, vLen = 0;
  unsigned char *keyStr = NULL, *valStr = NULL;
  htab *t = NULL;

  if (storage == NULL || key == NULL || val == NULL) {
    assert(LIB_NAME "Storage structure and key, value strings must not be NULL" && (false || Storage_TestMode));
    return false;
  }
  t = storage->Data;
  clearKey(storage, key);
  if (Utils_GetCharArrayLen(key, &kLen, KEY_VAL_MIN_STR_LEN, KEY_VAL_MAX_STR_LEN) == false ||
      Utils_GetCharArrayLen(val, &vLen, KEY_VAL_MIN_STR_LEN, KEY_VAL_MAX_STR_LEN) == false)
    return false;
  if (hadd(t, key, kLen + UTILS_STR_LEN_SIZE, val)) {
    Utils_CreateAndCopyUcString(&keyStr, key, kLen + UTILS_STR_LEN_SIZE);
    hkey(t) = keyStr;
    Utils_CreateAndCopyUcString(&valStr, val, vLen + UTILS_STR_LEN_SIZE);
    hstuff(t) = valStr;
  } else {
    printf("Internal error: item: %s must be free\n", key);
    return false;
  }
  return true;
}
static OperatorData*
GetOperatorData(const nsString& aOperator, nsOperatorFlags aForm)
{
  nsAutoString key(aOperator);
  key.AppendInt(aForm);
  nsStringKey hkey(key);
  return (OperatorData*)gOperatorTable->Get(&hkey);
}
STATIC void freeData(htab *t) {
  if (t == NULL) return;
  while (hcount(t)) {
    Utils_Free(hkey(t));
    Utils_Free(hstuff(t));
    hdel(t);
  }
  hdestroy(t);
}
void KasmiMassonHill::calcAll(){

	// init and fill height list:
	heightTable_ = HashTable<scalar>( a_ / resolution() + 1);
	for(label i = 0; i < heightTable_.size(); i++){
		scalar d = i * resolution();
		heightTable_.set(hkey(d), calcHeight(d, 0., a_));
	}

}
// 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));
  }
}
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");
}
Beispiel #8
0
void ConsoleTools::setLinkSource(const String &str){
  InputSource *linkSource = null;
  DocumentBuilder docbuilder;
  Document *linkSourceTree = null;
  try{
    linkSource = InputSource::newInstance(&str);
    linkSourceTree = docbuilder.parse(linkSource);
  }catch(Exception &e){
    docbuilder.free(linkSourceTree);
    throw e;
  }

  Node *elem = linkSourceTree->getDocumentElement();

  if (*elem->getNodeName() != "doclinks"){
    throw Exception(DString("Bad doclinks data file structure"));
  }

  elem = elem->getFirstChild();
  while(elem != null){
    if (elem->getNodeType() == Node::ELEMENT_NODE && *elem->getNodeName() == "links"){
      const String *url = ((Element*)elem)->getAttribute(DString("url"));
      const String *scheme = ((Element*)elem)->getAttribute(DString("scheme"));
      Node *eachLink = elem->getFirstChild();
      while(eachLink != null){
        if (*eachLink->getNodeName() == "link"){
          const String *l_url = ((Element*)eachLink)->getAttribute(DString("url"));
          const String *l_scheme = ((Element*)eachLink)->getAttribute(DString("scheme"));
          const String *token = ((Element*)eachLink)->getAttribute(DString("token"));
          StringBuffer fullURL;
          if (url != null) fullURL.append(url);
          if (l_url != null) fullURL.append(l_url);
          if (l_scheme == null) l_scheme = scheme;
          if (token == null) continue;
          StringBuffer hkey(token);
          if (l_scheme != null && l_scheme->length() > 0){
            hkey.append(DString("--")).append(l_scheme);
          }
          docLinkHash->put(&hkey, new SString(&fullURL));
        }
        eachLink = eachLink->getNextSibling();
      }
    }
    elem = elem->getNextSibling();
  }
  delete linkSource;
  docbuilder.free(linkSourceTree);
}
Beispiel #9
0
int
LogDestroyClassAd::Play(void *data_structure)
{
	ClassAdHashTable *table = (ClassAdHashTable *)data_structure;
	HashKey hkey(key);
	ClassAd *ad;

	if (table->lookup(hkey, ad) < 0) {
		return -1;
	}

#if defined(HAVE_DLOPEN)
	ClassAdLogPluginManager::DestroyClassAd(key);
#endif

	delete ad;
	return table->remove(hkey);
}
STATIC bool clearKey(const SecureStorageS *storage, const unsigned char *key) {
  int16_t len = 0;
  htab *t = NULL;

  if (storage == NULL || key == NULL) {
    assert(LIB_NAME "Storage structure and key string must not be NULL" && (false || Storage_TestMode));
    return false;
  }
  t = storage->Data;
  if (Utils_GetCharArrayLen(key, &len, KEY_VAL_MIN_STR_LEN, KEY_VAL_MAX_STR_LEN) == false) return false;
  if (key != NULL && hfind(t, key, len + UTILS_STR_LEN_SIZE) == true) { // override existing item
    Utils_Free(hkey(t));
    Utils_Free(hstuff(t));
    hdel(t);
    return true;
  }
  return false;
}
scalar KasmiMassonHill::height(scalar dist) const{

	// simple cases:
	if(dist >= a_) return 0.;
	if(dist < resolution()) return maxHeight_;

	// chop to resolution():
	label hi     = dist / resolution();
	scalar hdist = hi * resolution();

	// check if already calculated, calc otherwise:
	word k = hkey(hdist);
	if(!heightTable_.found(k)){
		heightTable_.set(k,calcHeight(hdist, 0., a_));
	}

	return heightTable_[k];

}
Beispiel #12
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;
}
Beispiel #13
0
bool
ClassAdLog::AdExistsInTableOrTransaction(const char *key)
{
	bool adexists = false;

		// first see if it exists in the "commited" hashtable
	HashKey hkey(key);
	ClassAd *ad = NULL;
	table.lookup(hkey, ad);
	if ( ad ) {
		adexists = true;
	}

		// if there is no pending transaction, we're done
	if (!active_transaction) {
		return adexists;
	}

		// see what is going on in any current transaction
	for (LogRecord *log = active_transaction->FirstEntry(key); log; 
		 log = active_transaction->NextEntry()) 
	{
		switch (log->get_op_type()) {
		case CondorLogOp_NewClassAd: {
			adexists = true;
			break;
		}
		case CondorLogOp_DestroyClassAd: {
			adexists = false;
			break;
		}
		default:
			break;
		}
	}

	return adexists;
}
PRBool
nsMathMLOperators::LookupOperator(const nsString&       aOperator,
                                  const nsOperatorFlags aForm,
                                  nsOperatorFlags*      aFlags,
                                  float*                aLeftSpace,
                                  float*                aRightSpace)
{
  if (!gInitialized) {
    InitGlobals();
  }
  if (gOperatorTable) {
    NS_ASSERTION(aFlags && aLeftSpace && aRightSpace, "bad usage");
    NS_ASSERTION(aForm>=0 && aForm<4, "*** invalid call ***");

    OperatorData* found;
    PRInt32 form = NS_MATHML_OPERATOR_GET_FORM(aForm);
    gOperatorFound[NS_MATHML_OPERATOR_FORM_INFIX] = nsnull;
    gOperatorFound[NS_MATHML_OPERATOR_FORM_POSTFIX] = nsnull;
    gOperatorFound[NS_MATHML_OPERATOR_FORM_PREFIX] = nsnull;

    nsAutoString key(aOperator);
    key.AppendInt(form, 10);
    nsStringKey hkey(key);
    gOperatorFound[form] = found = (OperatorData*)gOperatorTable->Get(&hkey);

    // If not found, check if the operator exists perhaps in a different form,
    // in the order of preference: infix, postfix, prefix
    if (!found) {
      if (form != NS_MATHML_OPERATOR_FORM_INFIX) {
        form = NS_MATHML_OPERATOR_FORM_INFIX;
        key.Assign(aOperator);
        key.AppendInt(form, 10);
        nsStringKey hashkey(key);
        gOperatorFound[form] = found = (OperatorData*)gOperatorTable->Get(&hashkey);
      }
      if (!found) {
        if (form != NS_MATHML_OPERATOR_FORM_POSTFIX) {
          form = NS_MATHML_OPERATOR_FORM_POSTFIX;
          key.Assign(aOperator);
          key.AppendInt(form, 10);
          nsStringKey hashkey(key);
          gOperatorFound[form] = found = (OperatorData*)gOperatorTable->Get(&hashkey);
        }
        if (!found) {
          if (form != NS_MATHML_OPERATOR_FORM_PREFIX) {
            form = NS_MATHML_OPERATOR_FORM_PREFIX;
            key.Assign(aOperator);
            key.AppendInt(form, 10);
            nsStringKey hashkey(key);
            gOperatorFound[form] = found = (OperatorData*)gOperatorTable->Get(&hashkey);
          }
        }
      }
    }
    if (found) {
      NS_ASSERTION(found->mStr.Equals(aOperator), "bad setup");
      *aLeftSpace = found->mLeftSpace;
      *aRightSpace = found->mRightSpace;
      *aFlags &= ~NS_MATHML_OPERATOR_FORM; // clear the form bits
      *aFlags |= found->mFlags; // just add bits without overwriting
      return PR_TRUE;
    }
  }
  return PR_FALSE;
}
Beispiel #15
0
// Display a pop-up window and page it for the user.  If altmodeline is true, display buffer name and filename (only) on bottom
// mode line.  If endprompt is true, wait for user to press a key before returning (regardless of page size).  Current bindings
// (if any) for backPage, forwPage, backLine, and forwLine commands are recognized as well as 'b' (backward page), 'f' or space
// (forward page), 'u' (backward half page), 'd' (forward half page), 'g' (goto first page), 'G' (goto last page), ESC or 'q'
// (exit), and '?' (help).  Any non-navigation key gets pushed back into the input stream to be interpeted later as a command. 
// Return status.
int bpop(Buffer *bufp,bool altmodeline,bool endprompt) {
	Line *lnp1,*lnp,*lpmax;
	int crow;		// Current screen row number.
	int disprows;		// Total number of display rows.
	int halfpage;		// Rows in a half page.
	int n;			// Rows to move.
	ushort ek;		// Input extended key.
	char *strp,*strpz;	// Line text pointers.
	char *hprompt = NULL;	// Help prompt;
	bool firstpass = true;

	// Display special mode line if requested.
	if(altmodeline) {

		// Find last window on screen and rewrite its mode line.
		wupd_modeline(wnextis(NULL),bufp);
		}

	// Set up and display a pop-up "window".
	disprows = term.t_nrow - 2;

	// Check if buffer will fit on one page and if not, set lpmax to first line of last page.
	lpmax = NULL;
	n = 0;
	for(lnp = lforw(bufp->b_hdrlnp); lnp != bufp->b_hdrlnp; lnp = lforw(lnp)) {
		if(++n > disprows) {

			// Find beginning of last page.
			lpmax = bufp->b_hdrlnp;
			n = disprows;
			do {
				lpmax = lback(lpmax);
				} while(--n > 0);
			break;
			}
		}

	// Begin at the beginning.
	lnp1 = lforw(bufp->b_hdrlnp);
	halfpage = disprows / 2;
	n = 0;

	// Display a page (beginning at line lnp1 + n) and prompt for a naviagtion command.  Loop until exit key entered or
	// endprompt is false and buffer fits on one page (lpmax is NULL).
	for(;;) {
		lnp = lnp1;

		// Moving backward?
		if(n < 0) {
			do {
				// At beginning of buffer?
				if(lpmax == NULL || lnp1 == lforw(bufp->b_hdrlnp))
					break;

				// No, back up one line.
				lnp1 = lback(lnp1);
				} while(++n < 0);
			}

		// Moving forward?
		else if(n > 0) {
			do {
				// At end of buffer or max line?
				if(lpmax == NULL || lnp1 == bufp->b_hdrlnp || lnp1 == lpmax)
					break;

				// No, move forward one line.
				lnp1 = lforw(lnp1);
				} while(--n > 0);
			}

		// Illegal command?
		if(n != 0 && lnp1 == lnp)

			// Yes, ignore it.
			n = 0;
		else {
			// Found first row ... display page.
			lnp = lnp1;
			crow = 0;
			do {
				// At end of buffer?
				if(lnp == bufp->b_hdrlnp) {

					// Yes, erase remaining lines on physical screen.
					while(crow < disprows) {
						vtmove(crow,0);
						vteeol();
#if COLOR
						vscreen[crow]->v_rfcolor = gfcolor;
						vscreen[crow]->v_rbcolor = gbcolor;
#endif
						vscreen[crow]->v_left = FARRIGHT;
						vscreen[crow]->v_right = 0;
#if COLOR
						vscreen[crow++]->v_flags |= VFCHGD | VFCOLOR;
#else
						vscreen[crow++]->v_flags |= VFCHGD;
#endif
						}
					break;
					}

				// Update the virtual screen image for this line.  Characters past right edge of screen won't be
				// displayed, so ignore those.
				vtmove(crow,0);
				strpz = (strp = ltext(lnp)) + (lused(lnp) <= (int) term.t_ncol ? lused(lnp) : term.t_ncol);
				while(strp < strpz)
					vtputc(*strp++);
				vteeol();
#if COLOR
				vscreen[crow]->v_rfcolor = gfcolor;
				vscreen[crow]->v_rbcolor = gbcolor;
#endif
				vscreen[crow]->v_left = FARRIGHT;
				vscreen[crow]->v_right = 0;
#if COLOR
				vscreen[crow++]->v_flags |= VFCHGD | VFCOLOR;
#else
				vscreen[crow++]->v_flags |= VFCHGD;
#endif
				// On to the next line.
				lnp = lforw(lnp);
				} while(crow < disprows);

			// Screen is full.  Copy the virtual screen to the physical screen.
			if(pupd_all(false) != SUCCESS)
				return rc.status;

			// Bail out if called from terminp() and one-page buffer.
			if(firstpass && !endprompt && lpmax == NULL)
				goto uexit;
			firstpass = false;
			}

		// Display prompt.
		mlputs(MLHOME | MLFORCE,hprompt != NULL ? hprompt : lpmax == NULL || lnp1 == lpmax ? text201 : ": ");
													// "End: "
		if(TTflush() != SUCCESS)
			return rc.status;

		// Get response.
		for(;;) {
			// Get a keystroke and decode it.
			if(getkey(&ek) != SUCCESS)
				return rc.status;

			// Exit?
			if(ek == (CTRL | '[') || ek == 'q')
				goto uexit;

			// Forward whole page?
			if(ek == ' ' || ek == 'f' || iscmd(ek,forwPage)) {
				n = disprows - overlap;
				break;
				}

			// Forward half page?
			if(ek == 'd') {
				n = halfpage;
				break;
				}

			// Backward whole page?
			if(ek == 'b' || iscmd(ek,backPage)) {
				n = overlap - disprows;
				break;
				}

			// Backward half page?
			if(ek == 'u') {
				n = -halfpage;
				break;
				}

			// Forward a line?
			if(iscmd(ek,forwLine)) {
				n = 1;
				break;
				}

			// Backward a line?
			if(iscmd(ek,backLine)) {
				n = -1;
				break;
				}

			// First page?
			if(ek == 'g') {
				if(lpmax == NULL || lnp1 == lforw(bufp->b_hdrlnp))
					n = -1;			// Force beep.
				else {
					lnp1 = lforw(bufp->b_hdrlnp);
					n = 0;
					}
				break;
				}

			// Last page?
			if(ek == 'G') {
				if(lpmax == NULL || lnp1 == lpmax)
					n = 1;			// Force beep.
				else {
					lnp1 = lpmax;
					n = 0;
					}
				break;
				}

			// Help?
			if(ek == '?') {
				StrList msg;

				// Get string list...
				if(vopen(&msg,NULL,false) != 0)
					return vrcset();

				// build prompt...
				if(vputs(text202,&msg) != 0)
						// "(<SPC>,f"
					return vrcset();
				if(hkey(&msg,forwPage,0) != SUCCESS)
					return rc.status;
				if(vputs(text203,&msg) != 0)
						// ") +page (b"
					return vrcset();
				if(hkey(&msg,backPage,0) != SUCCESS)
					return rc.status;
				if(vputs(text204,&msg) != 0)
						// ") -page (d) +half (u) -half"
					return vrcset();
				if(hkey(&msg,forwLine,'+') != SUCCESS || hkey(&msg,backLine,'-') != SUCCESS)
					return rc.status;
				if(vputs(text206,&msg) != 0)
						// " (g) first (G) last (ESC,q) quit (?) help: "
					return vrcset();

				// and display it.
				if(vclose(&msg) != 0)
					return vrcset();
				mlputs(MLHOME | MLFORCE,msg.sl_vp->v_strp);
				}
			else {
				// Other key.  "Unget" the key for reprocessing and return.
				tungetc(ek);
				goto uexit;
				}
			}
		}
uexit:
	uphard();
	if(endprompt)
		mlerase(MLFORCE);

	return rc.status;
	}