int umSetUserPassword(char_t *user, char_t *pass) { int row, nRet; char_t *password; a_assert(user && *user); a_assert(pass && *pass); trace(3, T("UM: Attempting to change the password for user <%s>\n"), user); /* * Find the row of the user */ if ((row = dbSearchStr(didUM, UM_USER_TABLENAME, UM_NAME, user, 0)) < 0) { return UM_ERR_NOT_FOUND; } password = bstrdup(B_L, pass); umEncryptString(password); nRet = dbWriteStr(didUM, UM_USER_TABLENAME, UM_PASS, row, password); bfree(B_L, password); return nRet; }
int umSetAccessLimitMethod(char_t *url, accessMeth_t am) { int row; a_assert(url && *url); row = dbSearchStr(didUM, UM_ACCESS_TABLENAME, UM_NAME, url, 0); if (row >= 0) { return dbWriteInt(didUM, UM_ACCESS_TABLENAME, UM_METHOD, row, (int) am); } else { return UM_ERR_NOT_FOUND; } }
int umSetGroupAccessMethod(char_t *group, accessMeth_t am) { int row; a_assert(group && *group); row = dbSearchStr(didUM, UM_GROUP_TABLENAME, UM_NAME, group, 0); if (row >= 0) { return dbWriteInt(didUM, UM_GROUP_TABLENAME, UM_METHOD, row, (int) am); } else { return UM_ERR_NOT_FOUND; } }
char_t *ejEvalBlock(int eid, char_t *script, char_t **emsg) { char_t* returnVal; int vid; a_assert(script); vid = ejOpenBlock(eid); returnVal = ejEval(eid, script, emsg); ejCloseBlock(eid, vid); return returnVal; }
int dbGetTableNrow(int did, char_t *tablename) { int tid; a_assert(tablename); tid = dbGetTableId(did, tablename); if ((tid >= 0) && (tid < dbMaxTables) && (dbListTables[tid] != NULL)) { return (dbListTables[tid])->nRows; } else { return -1; } }
static int calcPrime(int size) { int count; a_assert(size > 0); for (count = size; count > 0; count--) { if (isPrime(count)) { return count; } } return 1; }
void websPageClose(webs_t wp) { a_assert(websValid(wp)); #ifdef WEBS_PAGE_ROM websRomPageClose(wp->docfd); #else if (wp->docfd >= 0) { close(wp->docfd); wp->docfd = -1; } #endif }
int umSetAccessLimitGroup(char_t *url, char_t *group) { int row; a_assert(url && *url); row = dbSearchStr(didUM, UM_ACCESS_TABLENAME, UM_NAME, url, 0); if (row >= 0) { return dbWriteStr(didUM, UM_ACCESS_TABLENAME, UM_GROUP, row, group); } else { return UM_ERR_NOT_FOUND; } }
static void formAddAccessLimit(webs_t wp, char_t *path, char_t *query) { char_t *url, *method, *group, *secure, *ok; int nCheck; accessMeth_t am; short nSecure; a_assert(wp); url = websGetVar(wp, T("url"), T("")); group = websGetVar(wp, T("group"), T("")); method = websGetVar(wp, T("method"), T("")); secure = websGetVar(wp, T("secure"), T("")); ok = websGetVar(wp, T("ok"), T("")); websHeader(wp); websMsgStart(wp); if (gstricmp(ok, T("ok")) != 0) { websWrite(wp, T("Add Access Limit Cancelled.")); } else if ((url == NULL) || (*url == 0)) { websWrite(wp, T("ERROR: No URL was entered.")); } else if (umAccessLimitExists(url)) { websWrite(wp, T("ERROR: An Access Limit for [%s] already exists."), url); } else { if (method && *method) { am = (accessMeth_t) gatoi(method); } else { am = AM_FULL; } if (secure && *secure) { nSecure = (short) gatoi(secure); } else { nSecure = 0; } nCheck = umAddAccessLimit(url, am, nSecure, group); if (nCheck != 0) { websWrite(wp, T("Unable to add Access Limit for [%s]"), url); } else { websWrite(wp, T("Access limit for [%s], was successfully added."), url); } } websMsgEnd(wp); websFooter(wp); websDone(wp, 200); }
int ejLexOpenScript(ej_t* ep, char_t *script) { ejinput_t *ip; a_assert(ep); a_assert(script); if ((ep->input = balloc(B_L, sizeof(ejinput_t))) == NULL) { return -1; } ip = ep->input; memset(ip, 0, sizeof(*ip)); a_assert(ip); a_assert(ip->putBackToken == NULL); a_assert(ip->putBackTokenId == 0); /* * Create the parse token buffer and script buffer */ if (ringqOpen(&ip->tokbuf, EJ_INC, -1) < 0) { return -1; } if (ringqOpen(&ip->script, EJ_SCRIPT_INC, -1) < 0) { return -1; } /* * Put the Ejscript into a ring queue for easy parsing */ ringqPutStr(&ip->script, script); ip->lineNumber = 1; ip->lineLength = 0; ip->lineColumn = 0; ip->line = NULL; return 0; }
char_t *websCalcNonce(webs_t wp) { char_t *nonce, *prenonce; struct tm *newtime; time_t longTime; a_assert(wp); /* * Get time as long integer. */ time(&longTime); /* * Convert to local time. */ newtime = localtime(&longTime); /* * Create prenonce string. */ prenonce = NULL; #ifdef DIGEST_ACCESS_SUPPORT fmtAlloc(&prenonce, 256, T("%s:%s:%s"), RANDOMKEY, gasctime(newtime), wp->realm); #else fmtAlloc(&prenonce, 256, T("%s:%s:%s"), RANDOMKEY, gasctime(newtime), RANDOMKEY); #endif a_assert(prenonce); /* * Create the nonce */ nonce = websMD5(prenonce); /* * Cleanup */ bfreeSafe(B_L, prenonce); return nonce; }
int websUrlHandlerDefine(char_t *urlPrefix, char_t *webDir, int arg, int (*handler)(webs_t wp, char_t *urlPrefix, char_t *webdir, int arg, char_t *url, char_t *path, char_t *query), int flags) { websUrlHandlerType *sp; int len; a_assert(urlPrefix); a_assert(handler); /* * Grow the URL handler array to create a new slot */ len = (websUrlHandlerMax + 1) * sizeof(websUrlHandlerType); if ((websUrlHandler = brealloc(B_L, websUrlHandler, len)) == NULL) { return -1; } sp = &websUrlHandler[websUrlHandlerMax++]; memset(sp, 0, sizeof(websUrlHandlerType)); sp->urlPrefix = bstrdup(B_L, urlPrefix); sp->len = gstrlen(sp->urlPrefix); if (webDir) { sp->webDir = bstrdup(B_L, webDir); } else { sp->webDir = bstrdup(B_L, T("")); } sp->handler = handler; sp->arg = arg; sp->flags = flags; /* * Sort in decreasing URL length order observing the flags for first and last */ qsort(websUrlHandler, websUrlHandlerMax, sizeof(websUrlHandlerType), websUrlHandlerSort); return 0; }
sym_fd_t symOpen(int hash_size) { sym_fd_t sd; sym_tabent_t *tp; a_assert(hash_size > 2); /* * Create a new handle for this symbol table */ if ((sd = hAlloc((void***) &sym)) < 0) { return -1; } /* * Create a new symbol table structure and zero */ if ((tp = (sym_tabent_t*) balloc(B_L, sizeof(sym_tabent_t))) == NULL) { symMax = hFree((void***) &sym, sd); return -1; } memset(tp, 0, sizeof(sym_tabent_t)); if (sd >= symMax) { symMax = sd + 1; } a_assert(0 <= sd && sd < symMax); sym[sd] = tp; /* * Now create the hash table for fast indexing. */ tp->hash_size = calcPrime(hash_size); tp->hash_table = (sym_t**) balloc(B_L, tp->hash_size * sizeof(sym_t*)); a_assert(tp->hash_table); memset(tp->hash_table, 0, tp->hash_size * sizeof(sym_t*)); return sd; }
static char_t *umGetNextRowData(char_t *tableName, char_t *columnName, char_t *keyLast) { char_t *key; int row; int check; a_assert(tableName && *tableName); a_assert(columnName && *columnName); a_assert(keyLast && *keyLast); /* * Position row counter to row where the given key value was found */ row = 0; key = NULL; while ((((check = dbReadStr(didUM, tableName, columnName, row++, &key)) == 0) || (check == DB_ERR_ROW_DELETED)) && ((key == NULL) || (gstrcmp(key, keyLast) != 0))) { } /* * If the last key value was not found, return NULL */ if (!key || gstrcmp(key, keyLast) != 0) { return NULL; } /* * Move through table until we retrieve the next row with a non-null key */ while (((check = dbReadStr(didUM, tableName, columnName, row++, &key)) == 0) || (check == DB_ERR_ROW_DELETED)) { if (key && *key && (gstrcmp(key, keyLast) != 0)) { return key; } } return NULL; }
bool_t umGetGroupProtected(char_t *group) { int protect, row; a_assert(group && *group); protect = 0; row = dbSearchStr(didUM, UM_GROUP_TABLENAME, UM_NAME, group, 0); if (row >= 0) { dbReadInt(didUM, UM_GROUP_TABLENAME, UM_PROT, row, &protect); } return (bool_t) protect; }
int umSetGroupEnabled(char_t *group, bool_t enabled) { int row; a_assert(group && *group); row = dbSearchStr(didUM, UM_GROUP_TABLENAME, UM_NAME, group, 0); if (row >= 0) { return dbWriteInt(didUM, UM_GROUP_TABLENAME, UM_DISABLE, row, (int) !enabled); } else { return UM_ERR_NOT_FOUND; } }
bool_t umGetGroupEnabled(char_t *group) { int disabled, row; a_assert(group && *group); row = dbSearchStr(didUM, UM_GROUP_TABLENAME, UM_NAME, group, 0); disabled = 1; if (row >= 0) { dbReadInt(didUM, UM_GROUP_TABLENAME, UM_DISABLE, row, &disabled); } return (bool_t) !disabled; }
int umSetGroupPrivilege(char_t *group, short privilege) { int row; a_assert(group && *group); row = dbSearchStr(didUM, UM_GROUP_TABLENAME, UM_NAME, group, 0); if (row >= 0) { return dbWriteInt(didUM, UM_GROUP_TABLENAME, UM_PRIVILEGE, row, (int)privilege); } else { return UM_ERR_NOT_FOUND; } }
short umGetGroupPrivilege(char_t *group) { int privilege, row; a_assert(group && *group); privilege = -1; row = dbSearchStr(didUM, UM_GROUP_TABLENAME, UM_NAME, group, 0); if (row >= 0) { dbReadInt(didUM, UM_GROUP_TABLENAME, UM_PRIVILEGE, row, &privilege); } return (short) privilege; }
static int aspGeneratePrivilegeList( int eid, webs_t wp, int argc, char_t** argv ) { int nBytes; a_assert( wp ); nBytes = websWrite( wp, T( "<SELECT NAME=\"privilege\" SIZE=\"3\" " ) ); nBytes += websWrite( wp, T( "MULTIPLE TITLE=\"Choose Privileges\">" ) ); nBytes += websWrite( wp, T( "<OPTION VALUE=\"%d\">READ\n" ), PRIV_READ ); nBytes += websWrite( wp, T( "<OPTION VALUE=\"%d\">EXECUTE\n" ), PRIV_WRITE ); nBytes += websWrite( wp, T( "<OPTION VALUE=\"%d\">ADMINISTRATE\n" ), PRIV_ADMIN ); nBytes += websWrite( wp, T( "</SELECT>" ) ); return nBytes; }
int umSetAccessLimitSecure(char_t *url, short secure) { int row; a_assert(url && *url); row = dbSearchStr(didUM, UM_ACCESS_TABLENAME, UM_NAME, url, 0); if (row >= 0) { return dbWriteInt(didUM, UM_ACCESS_TABLENAME, UM_SECURE, row, (int)secure); } else { return UM_ERR_NOT_FOUND; } }
short umGetAccessLimitSecure(char_t *url) { int secure, row; a_assert(url && *url); secure = -1; row = dbSearchStr(didUM, UM_ACCESS_TABLENAME, UM_NAME, url, 0); if (row >= 0) { dbReadInt(didUM, UM_ACCESS_TABLENAME, UM_SECURE, row, &secure); } return (short)secure; }
static int isPrime(int n) { int i, max; a_assert(n > 0); max = n / 2; for (i = 2; i <= max; i++) { if (n % i == 0) { return 0; } } return 1; }
static void inputPutback(ej_t* ep, int c) { ejinput_t *ip; a_assert(ep); ip = ep->input; ringqInsertc(&ip->script, (char_t) c); /* Fix by Fred Sauer, 2002/12/23 */ if (ip->lineColumn > 0) { ip->lineColumn-- ; } ip->line[ip->lineColumn] = '\0'; }
int socketSetBlock(int sid, int on) { socket_t *sp; unsigned long flag; int iflag; int oldBlock; flag = iflag = !on; if ((sp = socketPtr(sid)) == NULL) { a_assert(0); return 0; } oldBlock = (sp->flags & SOCKET_BLOCK); sp->flags &= ~(SOCKET_BLOCK); if (on) { sp->flags |= SOCKET_BLOCK; } /* * Put the socket into block / non-blocking mode */ if (sp->flags & SOCKET_BLOCK) { #if (defined (CE) || defined (WIN)) ioctlsocket(sp->sock, FIONBIO, &flag); #elif (defined (ECOS)) int off; off = 0; ioctl(sp->sock, FIONBIO, &off); #elif (defined (VXWORKS) || defined (NW)) ioctl(sp->sock, FIONBIO, (int)&iflag); #else fcntl(sp->sock, F_SETFL, fcntl(sp->sock, F_GETFL) & ~O_NONBLOCK); #endif } else { #if (defined (CE) || defined (WIN)) ioctlsocket(sp->sock, FIONBIO, &flag); #elif (defined (ECOS)) int on; on = 1; ioctl(sp->sock, FIONBIO, &on); #elif (defined (VXWORKS) || defined (NW)) ioctl(sp->sock, FIONBIO, (int)&iflag); #else fcntl(sp->sock, F_SETFL, fcntl(sp->sock, F_GETFL) | O_NONBLOCK); #endif } return oldBlock; }
int umSetGroupProtected(char_t *group, bool_t protect) { int row; a_assert(group && *group); row = dbSearchStr(didUM, UM_GROUP_TABLENAME, UM_NAME, group, 0); if (row >= 0) { return dbWriteInt(didUM, UM_GROUP_TABLENAME, UM_PROT, row, (int) protect); } else { return UM_ERR_NOT_FOUND; } }
int hAllocEntry(void ***list, int *max, int size) #endif { char_t *cp; int id; a_assert(list); a_assert(max); #ifdef B_STATS if ((id = HALLOC(B_ARGS, (void***) list)) < 0) { #else if ((id = hAlloc((void***) list)) < 0) { #endif return -1; } if (size > 0) { #ifdef B_STATS if ((cp = balloc(B_ARGS, size)) == NULL) { #else if ((cp = balloc(B_L, size)) == NULL) { #endif hFree(list, id); return -1; } a_assert(cp); memset(cp, 0, size); (*list)[id] = (void*) cp; } if (id >= *max) { *max = id + 1; } return id; }
static void centerWindowOnDisplay( HWND hwndCenter ) { int xLeft, yTop, cxDisp, cyDisp; RECT rcDlg; a_assert( IsWindow( hwndCenter ) ); /* * Get Window Size */ GetWindowRect( hwndCenter, &rcDlg ); /* * Get monitor width and height */ cxDisp = GetSystemMetrics( SM_CXFULLSCREEN ); cyDisp = GetSystemMetrics( SM_CYFULLSCREEN ); /* * Find dialog's upper left based on screen size */ xLeft = cxDisp / 2 - RCWIDTH( rcDlg ) / 2; yTop = cyDisp / 2 - RCHEIGHT( rcDlg ) / 2; /* * If the dialog is outside the screen, move it inside */ if ( xLeft < 0 ) { xLeft = 0; } else if ( xLeft + RCWIDTH( rcDlg ) > cxDisp ) { xLeft = cxDisp - RCWIDTH( rcDlg ); } if ( yTop < 0 ) { yTop = 0; } else if ( yTop + RCHEIGHT( rcDlg ) > cyDisp ) { yTop = cyDisp - RCHEIGHT( rcDlg ); } /* * Move the window */ SetWindowPos( hwndCenter, HWND_TOP, xLeft, yTop, -1, -1, SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE ); }
accessMeth_t umGetGroupAccessMethod(char_t *group) { int am, row; a_assert(group && *group); row = dbSearchStr(didUM, UM_GROUP_TABLENAME, UM_NAME, group, 0); if (row >= 0) { dbReadInt(didUM, UM_GROUP_TABLENAME, UM_METHOD, row, (int *)&am); } else { am = AM_INVALID; } return (accessMeth_t) am; }
static int evalCond(ej_t *ep, char_t *lhs, int rel, char_t *rhs) { char_t buf[16]; int l, r, lval; a_assert(lhs); a_assert(rhs); a_assert(rel > 0); lval = 0; if (gisdigit((int)*lhs) && gisdigit((int)*rhs)) { l = gatoi(lhs); r = gatoi(rhs); switch (rel) { case COND_AND: lval = l && r; break; case COND_OR: lval = l || r; break; default: ejError(ep, T("Bad operator %d"), rel); return -1; } } else { if (!gisdigit((int)*lhs)) { ejError(ep, T("Conditional must be numeric"), lhs); } else { ejError(ep, T("Conditional must be numeric"), rhs); } } stritoa(lval, buf, sizeof(buf)); setString(B_L, &ep->result, buf); return 0; }