/* Name: adu_csnormalize - Normalizes a platform characterset ** string in the alias table or as obtained ** by CM_getcharset. ** Description: ** ** As per the Unicode technical report UTR22. Ref: ** http://www.unicode.org/reports/tr22/ section 1.4, recommended ** method to compare the alias values in an alias table to a character ** set is to normalize the string in following manner. ** ** 1. Delete all characters except a-z, A-Z, and 0-9. ** 2. Map uppercase A-Z to the corresponding lowercase a-z. ** 3. From left to right, delete each 0 that is not preceded by a digit. ** ** For example, the following names should match: "UTF-8", "utf8", ** "u.t.f-008", but not "utf-80" or "ut8". ** ** Input: ** instring - Unnormalized converter name string. ** ** Output: ** instring - Normalized converter name string. ** ** History: ** 23-Jan-2004 (gupsh01) ** Added. */ void adu_csnormalize( char *instring, i4 inlength, char *outstring) { char *iptr = instring; char *endinput = instring + inlength; char *optr = outstring; char nopreceding = '0'; while (iptr < endinput) { if (CMdigit(iptr) || CMalpha(iptr)) { if (CMalpha(iptr)) nopreceding = *iptr; else nopreceding = '0'; CMtolower(iptr,iptr); if (nopreceding != '0'&& *iptr == '0') { *iptr++; continue; } CMcpyinc(iptr, optr); } else iptr++; } *optr = '\0'; }
STATUS CVaptr( char *str, PTR *ptrp ) { SIZE_TYPE num; /* presumed to be 64 bits on 64 bit machine */ PTR ptr; char a; char tmp_buf[3]; num = 0; /* skip leading blanks */ for (; *str == ' '; str++) ; /* at this point everything should be 0-9 */ while (*str) { CMtolower(str, tmp_buf); if (CMdigit(tmp_buf)) { if ( num > ((SIZE_TYPE)~0/10) ) return(CV_OVERFLOW); num = num * 10 + (*str - '0'); } else { return (CV_SYNTAX); } str++; } /* Done with number, better be EOS or all blanks from here */ while (a = *str++) if (a != ' ') /* syntax error */ return (CV_SYNTAX); *ptrp = (PTR)num; return (OK); }
void FEapply_money_format(ADF_CB *cb, char *money_format) { CMtolower(money_format, money_format); if ((*money_format == 'n') && STlength(money_format) == 4) { if ( ((*(money_format+1) == 'o') || (*(money_format+1) == 'O')) && ((*(money_format+2) == 'n') || (*(money_format+2) == 'N')) && ((*(money_format+3) == 'e') || (*(money_format+3) == 'E')) ) { cb->adf_mfmt.db_mny_lort = DB_NONE_MONY; } else { IIUGerr(E_UG0021_BadMnyFormat, 0, 1, (PTR)money_format); } } else if ((*money_format != 'l' && *money_format != 't' && *money_format != 'n') || *(money_format+1) != ':' /* {l|t}:$$$ */ || STlength(money_format) > DB_MAXMONY + 2 || STlength(money_format) < 3) { IIUGerr(E_UG0021_BadMnyFormat, 0, 1, (PTR)money_format); /* default is "l:$"; leading currency symbol of "$" */ } else { if ( *money_format == 'l') { cb->adf_mfmt.db_mny_lort = DB_LEAD_MONY; } else if ( *money_format == 't' ) { cb->adf_mfmt.db_mny_lort = DB_TRAIL_MONY; } STcopy( money_format + 2, cb->adf_mfmt.db_mny_sym ); } }
STATUS getLocation(char *string,char *newstr,LOCTYPE *typeOfLoc) { STATUS ret_val ; LOCATION aLoc ; LOCATION bLoc ; LOCATION *Locptr1 = NULL ; LOCATION *Locptr2 = NULL ; LOCATION *Locptr3 = NULL ; char *cptr = NULL ; char *cptr2 = NULL ; char *next = NULL ; char *start = NULL ; char *tmpBuf = NULL ; char *tmpBuf2 = NULL ; char *gl_dev = NULL ; char *gl_path [128] ; char *gl_file = NULL ; char *resultPtr = NULL ; char *tmpaLocStr = NULL ; char *tmpbLocStr = NULL ; i4 i ; ret_val = OK; for ( i=0; i<128; i++) gl_path[i] = NULL; tmpaLocStr = SEP_MEalloc(SEP_ME_TAG_GETLOC, MAX_LOC+1, TRUE, (STATUS *)NULL); tmpbLocStr = SEP_MEalloc(SEP_ME_TAG_GETLOC, MAX_LOC+1, TRUE, (STATUS *)NULL); LOfroms(FILENAME & PATH, tmpaLocStr, &aLoc); LOfroms(FILENAME & PATH, tmpbLocStr, &bLoc); if (tracing&TRACE_PARM) { SIfprintf(traceptr, ERx("getLocation00> string = %s\n"), string); SIfprintf(traceptr, ERx("getLocation01> newstr = %s\n"), newstr); } tmpBuf = SEP_MEalloc(SEP_ME_TAG_GETLOC, MAX_LOC+1, TRUE, (STATUS *)NULL); STcopy(string, tmpBuf); if (!(start = STindex(tmpBuf, ERx("("), 0))) { MEtfree(SEP_ME_TAG_GETLOC); return(FAIL); } MEfree(tmpaLocStr); MEfree(tmpbLocStr); aLoc.string = SEP_MEalloc(SEP_ME_TAG_GETLOC, MAX_LOC+1, TRUE, (STATUS *)NULL); bLoc.string = SEP_MEalloc(SEP_ME_TAG_GETLOC, MAX_LOC+1, TRUE, (STATUS *)NULL); next = start; CMnext(next); if (typeOfLoc) *typeOfLoc = NULL; if (CMcmpcase(next, ERx(","))) { /* There's a device specification */ cptr = next; if ((next = STindex(cptr, ERx(","), 0)) == NULL) { if ((next = STindex(cptr, ERx(")"), 0)) == NULL) ret_val = FAIL; else { /* ** This is really a file name in the form, @file(filename.type) */ *next = EOS; gl_file = SEP_MEalloc(SEP_ME_TAG_GETLOC, ((i4)(next-cptr))+2, TRUE, (STATUS *)NULL); STcopy(cptr, gl_file); if (tracing&TRACE_PARM) SIfprintf(traceptr, ERx("getLocation02> file = %s\n"), gl_file); if (typeOfLoc) *typeOfLoc = FILENAME; } } else { *next = EOS; gl_dev = SEP_MEalloc(SEP_ME_TAG_GETLOC, ((i4)(next-cptr))+2, TRUE, (STATUS *)NULL); #ifdef UNIX STpolycat(2,ERx("$"),cptr, gl_dev); cptr2 = gl_dev; SEP_NMgtAt(CMnext(cptr2), &tmpBuf2, SEP_ME_TAG_GETLOC); if ((tmpBuf2 == NULL)||(*tmpBuf2 == EOS)) { switch (i = SEP_CMwhatcase(cptr2)) { case 0: break; case 1: for (cptr2 = gl_dev; *cptr2 != EOS; CMnext(cptr2)) CMtolower(cptr2,cptr2); break; case -1: for (cptr2 = gl_dev; *cptr2 != EOS; CMnext(cptr2)) CMtoupper(cptr2,cptr2); break; } if (i != 0) { cptr2 = gl_dev; SEP_NMgtAt(CMnext(cptr2), &tmpBuf2, SEP_ME_TAG_GETLOC); } } if (tmpBuf2 != NULL) if (*tmpBuf2 != EOS) { MEfree(gl_dev); gl_dev = SEP_MEalloc(SEP_ME_TAG_GETLOC, (STlength(tmpBuf2)*2)+2, TRUE,(STATUS *)NULL); STcopy(tmpBuf2,gl_dev); } #else #ifdef MPE STpolycat(2,ERx("!"),cptr, gl_dev); for (cptr2 = gl_dev; *cptr2 != EOS; CMnext(cptr2)) CMtoupper(cptr2,cptr2); #else /* Probably VMS */ STcopy(cptr, gl_dev); #endif #endif if (tracing&TRACE_PARM) SIfprintf(traceptr, ERx("getLocation03> dev = %s\n"), gl_dev); if (typeOfLoc) *typeOfLoc = PATH; } } cptr = CMnext(next); next = STindex(cptr, ERx(","), 0); for (i = 0; next; ) /* do the paths */ { *next = EOS; gl_path[i] = SEP_MEalloc(SEP_ME_TAG_GETLOC, (int)(next-cptr+2), TRUE, (STATUS *)NULL); STcopy(cptr, gl_path[i]); if (tracing&TRACE_PARM) SIfprintf(traceptr, ERx("getLocation04> path = %s\n"), gl_path[i]); if (typeOfLoc) *typeOfLoc = PATH; cptr = CMnext(next); next = STindex(cptr, ERx(","), 0); i++; } gl_path[i] = NULL; Locptr1 = &aLoc; Locptr2 = &bLoc; #ifndef MPE if (gl_dev || gl_path[0]) { if (tracing&TRACE_PARM) SIfprintf(traceptr, ERx("getLocation05> SEP_LOcompose()\n")); ret_val = SEP_LOcompose(gl_dev, gl_path[0], NULL, NULL, NULL, Locptr1); #ifdef UNIX cptr2 = SEP_CMlastchar(Locptr1->string,0); if (*cptr2 == '/') *cptr2 = EOS; Locptr1->path = Locptr1->string; #endif } for (i=1; (gl_path[i] != NULL)&&(ret_val == OK); i++) { if (tracing&TRACE_PARM) SIfprintf(traceptr, ERx("getLocation06> LOfaddpath()\n")); if ((ret_val = LOfaddpath(Locptr1, gl_path[i], Locptr2)) != OK) continue; Locptr3 = Locptr1; Locptr1 = Locptr2; Locptr2 = Locptr3; } #endif if ((gl_file != NULL)&&(ret_val == OK)) { /* ** This first case catches the instance of: @file(filenane.type). ** This was caught above in looking for a device (gl_dev). */ if (tracing&TRACE_PARM) SIfprintf(traceptr, ERx("getLocation07> LOfroms()\n")); ret_val = LOfroms( FILENAME, gl_file, Locptr1); } else if ((CMcmpcase(cptr, ERx(")")) != 0)&&(ret_val == OK)) { /* There is a filename */ next = STindex(cptr, ERx(")"), 0); *next = EOS; gl_file = SEP_MEalloc(SEP_ME_TAG_GETLOC, (int)(next-cptr+2), TRUE, (STATUS *)NULL); STcopy(cptr, gl_file); if (tracing&TRACE_PARM) SIfprintf(traceptr, ERx("getLocation08> file = %s\n"), gl_file); if (typeOfLoc) *typeOfLoc = PATH & FILENAME; if (gl_dev || gl_path[0]) { #ifdef MPE if (gl_dev) { if (tracing&TRACE_PARM) SIfprintf(traceptr, ERx("getLocation09> MPE's LOfroms ()\n")); char *tmpMPE = NULL ; tmpMPE = SEP_MEalloc(SEP_ME_TAG_GETLOC, (STlength(gl_file)+STlength(gl_dev)+1)*2, TRUE, (STATUS *)NULL); STpolycat(3, gl_file, ERx("."), gl_dev, tmpMPE); LOfroms(FILENAME & PATH, tmpMPE, Locptr1); } #else if (tracing&TRACE_PARM) SIfprintf(traceptr, ERx("getLocation09> LOfstfile()\n")); LOfstfile(gl_file, Locptr1); #endif } else { if (tracing&TRACE_PARM) SIfprintf(traceptr, ERx("getLocation10> LOfroms()\n")); LOfroms( FILENAME, gl_file, Locptr1); } } if (ret_val == OK) { if (tracing&TRACE_PARM) SIfprintf(traceptr, ERx("getLocation11> LOtos()\n")); LOtos(Locptr1, &resultPtr); STcopy(resultPtr, newstr); } MEtfree(SEP_ME_TAG_GETLOC); if (tracing&TRACE_PARM) { if (ret_val != OK) SIfprintf(traceptr,ERx("getLocation12> ret_val = %d\n"),ret_val); else SIfprintf(traceptr,ERx("getLocation13> newstr = %s\n"),newstr); } return(ret_val); }
/*{ ** Name: scu_xencode - encrypt a character string ** ** Description: ** This function uses CI routines to encrypt a character string. ** Since the character string is used to generate the key schedule, ** the encryption is essentially one-way (you'd need to know the ** password to decode the password....) This routine was designed ** to encrypt application_id passwords. ** ** Inputs: ** SCU_XENCODE the opcode to scf_call() ** scf_cb control block in which is specified ** .scf_ptr_union.scf_xpassword ** pointer to buffer to be encrypted ** .scf_nbr_union.scf_xpasskey ** pointer to seed for key schedule ** .scf_len_union.scf_xpwdlen ** length of password and key seed ** ** Outputs: ** scf_cb the same control block ** .error the error control area ** .err_code E_SC_OK or ... ** E_SC0261_XENCODE_BAD_PARM ** E_SC0262_XENCODE_BAD_RESULT ** Returns: ** E_DB_{OK, WARNING, ERROR, FATAL} ** Exceptions: ** none ** ** Side Effects: ** none ** ** History: ** 24-mar-89 (ralph) ** Written for terminator ** 20-may-89 (ralph) ** Changed encryption to use separate key ** 06-jun-89 (ralph) ** Fixed unix compile problems ** 06-may-1993 (ralph) ** DELIM_IDENT: ** Translate key seed to lower case prior to encryption. ** 2-Jul-1993 (daveb) ** prototyped. ** 14-jul-93 (ed) ** replacing <dbms.h> by <gl.h> <sl.h> <iicommon.h> <dbdbms.h> ** 12-Sep-2007 (drivi01) ** Modified scu_xencode function to fix numerous bugs. ** The buffers for password manipulation shouldn't exceed ** the size of scb_xpassword field in SCF control block, ** otherwise the data will be truncated. */ DB_STATUS scu_xencode(SCF_CB *scf_cb, SCD_SCB *scb ) { STATUS status; CI_KS KS; char inbuffer[DB_PASSWORD_LENGTH+1]; char outbuffer[DB_PASSWORD_LENGTH+1]; char keybuffer[DB_PASSWORD_LENGTH]; u_i2 i2_size; i4 longnat_size; i4 nat_size; char *char_ptr; #define PASSINIT "hjodvwHOJHOJhodh498032&*&*#)$&*jpkshghjlg58925fjkdjkpg" status = E_DB_OK; CLRDBERR(&scf_cb->scf_error); /* Ensure input parameter is okay */ if ((scf_cb->scf_len_union.scf_xpwdlen <= 0) || (scf_cb->scf_len_union.scf_xpwdlen >= sizeof(inbuffer)) || (scf_cb->scf_nbr_union.scf_xpasskey == NULL) || (scf_cb->scf_ptr_union.scf_xpassword == NULL)) { sc0ePut(NULL, E_SC0261_XENCODE_BAD_PARM, NULL, 0); SETDBERR(&scf_cb->scf_error, 0, E_SC0261_XENCODE_BAD_PARM); return(E_DB_ERROR); } /* Copy string to input buffer */ MEmove(scf_cb->scf_len_union.scf_xpwdlen, (PTR)scf_cb->scf_ptr_union.scf_xpassword, (char)'\0', sizeof(inbuffer), (PTR)inbuffer); /* Copy key to key buffer */ MEmove(scf_cb->scf_len_union.scf_xpwdlen, (PTR)scf_cb->scf_nbr_union.scf_xpasskey, (char)'?', sizeof(keybuffer), (PTR)keybuffer); /* Fold the key to lower case */ for (nat_size = sizeof(keybuffer), char_ptr = keybuffer; nat_size > 0; nat_size = CMbytedec(nat_size, char_ptr), char_ptr = CMnext(char_ptr)) { CMtolower(char_ptr, char_ptr); } /* Remove white space from input string */ nat_size = STzapblank(inbuffer, outbuffer); /* Check size */ if ((nat_size <= 0) || (nat_size > sizeof(outbuffer)-1)) { sc0ePut(NULL, E_SC0261_XENCODE_BAD_PARM, NULL, 0); SETDBERR(&scf_cb->scf_error, 0, E_SC0261_XENCODE_BAD_PARM); return(E_DB_ERROR); } /* Initialize input buffer to "garbage" */ MEmove(sizeof(PASSINIT), (PTR)PASSINIT, (char)'?', sizeof(inbuffer), (PTR)inbuffer); /* Normalize the string back into input buffer */ MEcopy((PTR)outbuffer, nat_size, (PTR)inbuffer); /* Reset output buffer to blanks */ MEfill(sizeof(outbuffer), (u_char)' ', (PTR)outbuffer); /* ** First, encrypt the key seed using the string to encode. ** Then, encrypt the string using the encrypted seed. ** This is done to prevent two roles with the same password ** from having the same encrypted value. ** Note that this makes the encryption one-way, since ** the password must be provided to decrypt the password! */ /* Generate the key schedule to encrypt the key seed */ (VOID)CIsetkey((PTR)inbuffer, KS); /* Encrypt the key seed */ longnat_size = DB_PASSWORD_LENGTH; (VOID)CIencode((PTR)keybuffer, longnat_size, KS, (PTR)outbuffer); /* Generate the second key schedule */ (VOID)CIsetkey((PTR)keybuffer, KS); /* Encode the string */ longnat_size = DB_PASSWORD_LENGTH; (VOID)CIencode((PTR)inbuffer, longnat_size, KS, (PTR)outbuffer); /* Make sure it was really encoded */ if ((char *)STskipblank(outbuffer, (i4)sizeof(outbuffer)) != NULL) { /* It was; copy result to caller's area */ i2_size = scf_cb->scf_len_union.scf_xpwdlen; MEmove(sizeof(outbuffer), (PTR)outbuffer, (char)' ', i2_size, (PTR)scf_cb->scf_ptr_union.scf_xpassword); } else { /* The encryption did not work; return an error */ sc0ePut(NULL, E_SC0262_XENCODE_BAD_RESULT, NULL, 0); SETDBERR(&scf_cb->scf_error, 0, E_SC0262_XENCODE_BAD_RESULT); status = E_DB_ERROR; } return(status); }
DB_STATUS adu_dbmsinfo( ADF_CB *adf_scb, DB_DATA_VALUE *dv1, DB_DATA_VALUE *rdv) { i4 i = Adf_globs->Adi_num_dbis; i4 found = FALSE; ADF_DBMSINFO *dbi = Adf_globs->Adi_dbi; i4 dbi_size = sizeof(dbi->dbi_reqname); i4 in_size = ((DB_TEXT_STRING *)dv1->db_data)->db_t_count; char *in_str = (char *) ((DB_TEXT_STRING *)dv1->db_data)->db_t_text; register i4 j; register char *c1; register char *c2; char ch_tmp; ALIGN_RESTRICT *tbuf; DB_STATUS db_stat = E_DB_OK; i4 cmp; DB_DATA_VALUE tmp_dv; DB_ERROR err; ADK_MAP *kmap; char localbuf[2004]; bool uselocal = TRUE; if (in_size <= dbi_size) /* No possible match if input is bigger */ { /* Find the request in the dbmsinfo() request table */ while (i--) { cmp = TRUE; c1 = dbi->dbi_reqname; c2 = in_str; j = 0; while (j < in_size && *c1 != 0) { CMtolower(c2, &ch_tmp); if (*c1 != ch_tmp) { cmp = FALSE; break; } c1++; c2++; j++; } if ( cmp && (in_size == dbi_size || (*c1 == 0 && j == in_size)) ) { found = TRUE; break; } dbi++; } } if (!found) { ((DB_TEXT_STRING *)rdv->db_data)->db_t_count = 0; db_stat = E_DB_OK; } else { /* {@fix_me@} ... eventually, we have to handle 1 input, and ** lenspecs that are not FIXED LENGTH */ if (dbi->dbi_num_inputs || dbi->dbi_lenspec.adi_lncompute != ADI_FIXED) return(adu_error(adf_scb, E_AD9999_INTERNAL_ERROR, 0)); tmp_dv.db_datatype = dbi->dbi_dtr; tmp_dv.db_length = dbi->dbi_lenspec.adi_fixedsize; if (tmp_dv.db_length >= 2004) { uselocal = FALSE; tbuf = (ALIGN_RESTRICT *)MEreqmem(0, ((DB_GW4_MAXSTRING + DB_CNTSIZE - 1) / sizeof(ALIGN_RESTRICT)) + 1, FALSE, NULL); tmp_dv.db_data = (PTR)tbuf; } else tmp_dv.db_data = (PTR)&localbuf[0]; /* ** Is request one of the query constants? If so, use adu_dbconst() ** instead of the dbi function found in the dbi table. */ if (dbi == Adf_globs->Adk_bintim_map.adk_dbi) kmap = &Adf_globs->Adk_bintim_map; else if (dbi == Adf_globs->Adk_cpu_ms_map.adk_dbi) kmap = &Adf_globs->Adk_cpu_ms_map; else if (dbi == Adf_globs->Adk_et_sec_map.adk_dbi) kmap = &Adf_globs->Adk_et_sec_map; else if (dbi == Adf_globs->Adk_dio_cnt_map.adk_dbi) kmap = &Adf_globs->Adk_dio_cnt_map; else if (dbi == Adf_globs->Adk_bio_cnt_map.adk_dbi) kmap = &Adf_globs->Adk_bio_cnt_map; else if (dbi == Adf_globs->Adk_pfault_cnt_map.adk_dbi) kmap = &Adf_globs->Adk_pfault_cnt_map; else if (dbi == Adf_globs->Adk_curr_date_map.adk_dbi) kmap = &Adf_globs->Adk_curr_date_map; else if (dbi == Adf_globs->Adk_curr_time_map.adk_dbi) kmap = &Adf_globs->Adk_curr_time_map; else if (dbi == Adf_globs->Adk_curr_tstmp_map.adk_dbi) kmap = &Adf_globs->Adk_curr_tstmp_map; else if (dbi == Adf_globs->Adk_local_time_map.adk_dbi) kmap = &Adf_globs->Adk_local_time_map; else if (dbi == Adf_globs->Adk_local_tstmp_map.adk_dbi) kmap = &Adf_globs->Adk_local_tstmp_map; else kmap = NULL; if (kmap == NULL) db_stat = (*dbi->dbi_func)(dbi, NULL, &tmp_dv, &err); else db_stat = adu_dbconst(adf_scb, kmap, &tmp_dv); if (DB_SUCCESS_MACRO(db_stat)) { db_stat = adu_ascii(adf_scb, &tmp_dv, rdv); } if (!uselocal) MEfree((PTR)tbuf); } return (db_stat); }