static int hashHash(const byte* data, word32 len, byte* hash, word32 algo, word32 hsize) { int ret = 0; #ifdef WOLFSSL_SMALL_STACK wolfssl_TI_Hash* hash_desc; #else wolfssl_TI_Hash hash_desc[1]; #endif #ifdef WOLFSSL_SMALL_STACK hash_desc = (wolfssl_TI_Hash*)XMALLOC(sizeof(wolfssl_TI_Hash), NULL, DYNAMIC_TYPE_TMP_BUFFER); if (hash_desc == NULL) return MEMORY_E; #endif if ((ret = hashInit(hash_desc)) != 0) { WOLFSSL_MSG("Hash Init failed"); } else { hashUpdate(hash_desc, data, len); hashFinal(hash_desc, hash, algo, hsize); } #ifdef WOLFSSL_SMALL_STACK XFREE(hash_desc, NULL, DYNAMIC_TYPE_TMP_BUFFER); #endif return ret; }
void addEnvExtra(struct hash *hash, char *nameVal) /* parse and add one of the environment extra entries */ { char *eq = strchr(nameVal, '='); if (eq == NULL) errAbort("invalid -env argument, expected -env=name=value, got -env=%s", nameVal); *eq = '\0'; hashUpdate(hash, nameVal, eq+1); *eq = '='; }
void updatePath(struct hash *hash, char *userPath, char *homeDir, char *sysPath) /* Prepend userPath and system path to existing path. * Add homeDir in front of all elements of user path. */ { struct dyString *dy = newDyString(1024); char *s, *e; char *oldPath; /* Go through user path - which is colon separated * and prepend homeDir to it. */ userPath = cloneString(userPath); s = userPath; for (;;) { if (s == NULL || s[0] == 0) break; e = strchr(s, ':'); if (e != NULL) *e++ = 0; dyStringAppend(dy, homeDir); dyStringAppend(dy, "/"); dyStringAppend(dy, s); dyStringAppend(dy, ":"); s = e; } /* Add system path next. */ if (sysPath != NULL && sysPath[0] != 0) { dyStringAppend(dy, sysPath); if (lastChar(sysPath) != ':') dyStringAppend(dy, ":"); } /* Add paths we inherited from root. */ oldPath = hashFindVal(hash, "PATH"); if (oldPath == NULL || oldPath[0] == 0) oldPath = "/bin:/usr/bin"; dyStringAppend(dy, oldPath); hashUpdate(hash, "PATH", dy->string); freez(&userPath); dyStringFree(&dy); }
void execProc(char *managingHost, char *jobIdString, char *reserved, char *user, char *dir, char *in, char *out, char *err, long long memLimit, char *exe, char **params) /* This routine is the child process of doExec. * It spawns a grandchild that actually does the * work and waits on it. It sends message to the * main message loop here when done. */ { if ((grandChildId = forkOrDie()) == 0) { char *homeDir = ""; /* Change to given user (if root) */ changeUid(user, &homeDir); /* create output files just after becoming user so that errors in the rest * of this proc will go to the err file and be available via para * problems */ setupProcStdio(in, out, err); if (chdir(dir) < 0) errnoAbort("can't chdir to %s", dir); setsid(); // setpgid(0,0); umask(umaskVal); struct rlimit rlim; rlim.rlim_cur = rlim.rlim_max = memLimit; if(setrlimit(RLIMIT_CORE, &rlim) < 0) perror("setrlimit"); /* Update environment. */ { struct hash *hash = environToHash(environ); hashUpdate(hash, "JOB_ID", jobIdString); hashUpdate(hash, "USER", user); hashUpdate(hash, "HOME", homeDir); hashUpdate(hash, "HOST", hostName); hashUpdate(hash, "PARASOL", "7"); updatePath(hash, userPath, homeDir, sysPath); addEnvExtras(hash); environ = hashToEnviron(hash); freeHashAndVals(&hash); } randomSleep(); /* Sleep a random bit before executing this thing * to help spread out i/o when a big batch of jobs * hit idle cluster */ execvp(exe, params); errnoAbort("execvp'ing %s", exe); } else { /* Wait on executed job and send jobID and status back to * main process. */ int status = -1; int cid; struct paraMessage pm; struct rudp *ru = NULL; struct tms tms; unsigned long uTime = 0; unsigned long sTime = 0; if (grandChildId >= 0) { signal(SIGTERM, termHandler); cid = waitpid(grandChildId, &status, 0); if (cid < 0) errnoAbort("wait on grandchild failed"); times(&tms); uTime = ticksToHundreths*tms.tms_cutime; sTime = ticksToHundreths*tms.tms_cstime; } ru = rudpOpen(); if (ru != NULL) { ru->maxRetries = 20; pmInit(&pm, localIp, paraNodePort); pmPrintf(&pm, "jobDone %s %s %d %lu %lu", managingHost, jobIdString, status, uTime, sTime); pmSend(&pm, ru); rudpClose(&ru); } } }
WOLFSSL_API int wc_Sha256Update(Sha256* sha256, const byte* data, word32 len) { return hashUpdate((wolfssl_TI_Hash *)sha256, data, len) ; }
WOLFSSL_API void wc_Md5Update(Md5* md5, const byte* data, word32 len) { hashUpdate((wolfssl_TI_Hash *)md5, data, len) ; }