/*{ ** Name: opt_chkprint - Check that text string contains printable ascii. ** ** Description: ** Check that all characters in the text string provided are ascii ** for the length provided, or up to the first '\0' encountered, ** whichever comes first. Return TRUE if all ** characters are ascii, FALSE otherwise. ** ** Inputs: ** buf_to_check Ptr to char string to check ** buflen Maximum length to be checked ** ** Outputs: ** Returns: ** VOID ** Exceptions: ** none ** ** Side Effects: ** none ** ** History: ** 03jul-89 (robin) ** Created. [@history_template@]... */ bool opt_chkprint( char *buf_to_check, i4 buflen) { char wbuf[5]; i4 bytecount; char *bufptr; for ( bytecount = 0; bytecount <= buflen && *buf_to_check != '\0'; CMbyteinc( bytecount, buf_to_check)) { bufptr = &wbuf[0]; CMcpyinc(buf_to_check,bufptr); *bufptr = '\0'; if ( !CMprint(&wbuf[0] )) { return( FALSE ); } } return( TRUE ); }
/*{ ** Name: rms_movestring - moves a string into a DB_DATA_VALUE. ** ** Description: ** Moves a "C" string into a DB_DATA_VALUE padding the DB_DATA_VALUE ** string appropriately. If the DB_DATA_VALUE string has INGRES type c, ** any non-printing characters will be mapped to blanks. If the string ** has INGRES type text, then null characters are converted to blanks. ** ** Inputs: ** source The source "C" string. ** sourcelen The length of the source string. ** dest Ptr to the destination DB_DATA_VALUE. ** .db_datatype Datatype of the DB_DATA_VALUE. ** .db_length Length of the result DB_DATA_VALUE. ** ** Outputs: ** dest Ptr to the destination DB_DATA_VALUE. ** .db_data Ptr to memory where string is moved to. ** Returns: ** E_DB_OK ** ** Exceptions: ** none ** ** Side Effects: ** none ** ** History: ** 12-apr-90 (jrb) ** Created. */ DB_STATUS rms_movestring ( register u_char *source, register i4 sourcelen, register DB_DATA_VALUE *dest ) { DB_STATUS db_stat; char *cptr; u_char *endsource; register u_char *outstring; register i4 outlength; u_char *endout; if (db_stat = rms_straddr(dest, &cptr) != E_DB_OK) return (db_stat); outstring = (u_char *)cptr; switch (dest->db_datatype) { case DB_CHA_TYPE: case DB_CHR_TYPE: case DB_BYTE_TYPE: case DB_LBYTE_TYPE: outlength = dest->db_length; break; case DB_TXT_TYPE: case DB_VCH_TYPE: case DB_VBYTE_TYPE: outlength = dest->db_length - DB_CNTSIZE; break; } endsource = source + sourcelen; endout = outstring + outlength; if (dest->db_datatype == DB_CHR_TYPE) { while (source < endsource && outstring + CMbytecnt(source) <= endout) { /* ** The characters that are allowed as part of a string of type ** c are the printable characters(alpha, numeric, ** punctuation), blanks, IIMAX_CHAR_VALUE, or the pattern matching ** characters. NOTE: other whitespace (tab, etc.) is not ** allowed. */ if (!CMprint(source) && (*source) != ' ' && (*source) != IIMAX_CHAR_VALUE && (*source) != DB_PAT_ANY && (*source) != DB_PAT_ONE && (*source) != DB_PAT_LBRAC && (*source) != DB_PAT_RBRAC) { *outstring++ = ' '; CMnext(source); } else { CMcpyinc(source, outstring); } } } else if (dest->db_datatype == DB_TXT_TYPE) { while (source < endsource && outstring + CMbytecnt(source) <= endout) { /* NULLCHARs get cvt'ed to blank for text */ if (*source == NULLCHAR) { *outstring++ = ' '; CMnext(source); } else { CMcpyinc(source, outstring); } } } else { while (source < endsource && outstring + CMbytecnt(source) <= endout) CMcpyinc(source, outstring); } switch (dest->db_datatype) { case DB_CHA_TYPE: case DB_CHR_TYPE: while (outstring < endout) *outstring++ = ' '; break; case DB_VCH_TYPE: case DB_TXT_TYPE: ((DB_TEXT_STRING *)dest->db_data)->db_t_count = outstring - (u_char *)cptr; break; } return (E_DB_OK); }
/*{ ** Name: psy_print - Format query text to send to user ** ** Description: ** This function decodes query text that comes from the iiqrytext relation ** and formats it to send to the user. It is useful for the "help permit", ** "help integrity", and "help view" commands. ** ** Query text stored in the iiqrytext relation consists of human-readable ** text and special symbols. Some of these special symbols are numbers ** and strings sent from EQUEL or ESQL programs. Others stand for table ** names, range variables, and column numbers. This functio decodes all ** this stuff, and puts the result into a chain of PSY_QTEXT blocks to be ** sent back to the user. ** ** Inputs: ** mstream Memory stream to allocate blocks from ** map map of range var numbers to those ** in rngtab. ** block Current query text block ** text Pointer to the query text ** length Length of the query text ** rngtab The range table (used for decoding the ** special symbol standing for range ** variable numbers, and column numbers). ** The result range variable should stand ** for the table we're getting help on. ** err_blk Filled in if an error happens ** ** Outputs: ** err_blk Filled in if an error happened ** Returns: ** E_DB_OK Success ** E_DB_ERROR Non-catastrophic failure ** E_DB_FATAL Catastrophic failure ** Exceptions: ** none ** ** Side Effects: ** Sends query text to user ** ** History: ** 15-jul-86 (jeff) ** written ** 14-jul-93 (ed) ** replacing <dbms.h> by <gl.h> <sl.h> <iicommon.h> <dbdbms.h> */ DB_STATUS psy_print( PSF_MSTREAM *mstream, i4 map[], PSY_QTEXT **block, u_char *text, i4 length, PSS_USRRANGE *rngtab, DB_ERROR *err_blk) { char buf[1024 + DB_TAB_MAXNAME]; i4 i4align; i2 i2align; f8 f8align; register u_char *p; register i4 j; register i4 i; PSS_RNGTAB *lastvar = (PSS_RNGTAB *) NULL; DB_STATUS status; i4 slength; /* Put out range statements */ for (i = 0; i < PST_NUMVARS; i++) { /* Only look at range vars that are being used */ if (!rngtab->pss_rngtab[i].pss_used || rngtab->pss_rngtab[i].pss_rgno < 0) { continue; } status = psy_put(mstream, (char*) "range of ", (i4) sizeof("range of ") - 1, block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); /* NULL terminate and trim blanks from range variable name */ MEcopy(rngtab->pss_rngtab[i].pss_rgname, DB_TAB_MAXNAME, buf); buf[DB_TAB_MAXNAME] = '\0'; slength = STtrmwhite(buf); status = psy_put(mstream, buf, slength, block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); status = psy_put(mstream, " is ", (i4) sizeof(" is ") - 1, block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); /* NULL terminate and trim blanks from table name */ MEcopy((char *) &rngtab->pss_rngtab[i].pss_tabname, DB_TAB_MAXNAME, buf); buf[DB_TAB_MAXNAME] = '\0'; slength = STtrmwhite(buf); status = psy_put(mstream, buf, slength, block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); /* Newline after every range statement */ status = psy_put(mstream, (char*) "\n", (i4) 1, block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); } for (p = text; p < (u_char*) text + length;) { switch (*p++) { case PSQ_HVSTR: /* String sent from user program */ slength = STlength((char*) p); /* Emit opening quote */ status = psy_put(mstream, (char *) "\"", 1, block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); for (j = slength; j > 0; j--, p++) { if (*p == '"') { /* Escape any quote characters */ status = psy_put(mstream, "\\\"", 2, block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); } else if (!CMprint(p)) { /* Non-printing characters show up as escape sequence */ STprintf(buf, "\\%o", *p); status = psy_put(mstream, buf, (i4) STlength(buf), block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); } else { status = psy_put(mstream, (char*) p, 1, block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); } } break; case PSQ_HVF8: /* f8 sent from user program */ MEcopy((char *) p, sizeof(f8align), (char *) &f8align); STprintf(buf, "%f", f8align); status = psy_put(mstream, buf, (i4) STlength(buf), block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); p += sizeof(f8align); break; case PSQ_HVI4: /* i4 sent from user program */ MEcopy((char *) p, sizeof(i4align), (char *) &i4align); CVla(i4align, buf); status = psy_put(mstream, buf, (i4) STlength(buf), block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); p += sizeof(i4align); break; case PSQ_HVI2: /* i2 sent from user program */ MEcopy((char *) p, sizeof(i2align), (char *) &i2align); CVla((i4) i2align, buf); status = psy_put(mstream, buf, (i4) STlength(buf), block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); p += sizeof(i2align); break; case DB_INTRO_CHAR: /* Intro char for special sequence */ switch (*p++) { case DB_RNG_VAR: /* Put a blank before the table name */ status = psy_put(mstream, " ", 1, block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); /* Get the range variable number */ MEcopy((char *) p, sizeof(i4align), (char *) &i4align); p += sizeof(i4align); i4align = map[i4align]; /* Look up range variable number */ for (j = 0; j < PST_NUMVARS; j++) { if (rngtab->pss_rngtab[j].pss_used && rngtab->pss_rngtab[j].pss_rgno == i4align) { break; } } /* If found, give variable name, otherwise question marks */ if (j < PST_NUMVARS) { /* trim trailing blanks and NULL terminate */ MEcopy(rngtab->pss_rngtab[j].pss_rgname, DB_TAB_MAXNAME, buf); buf[DB_TAB_MAXNAME] = '\0'; slength = STtrmwhite(buf); status = psy_put(mstream, buf, slength, block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); /* Remember the range variable for when we get the colnum */ lastvar = &rngtab->pss_rngtab[j]; } else { lastvar = (PSS_RNGTAB*) 0; /* Put question marks if not found */ status = psy_put(mstream, "???", 3, block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); } break; case DB_COL_NUM: /* Column number for a range var */ /* Get the column number */ MEcopy((char *) p, sizeof(i4align), (char *) &i4align); p += sizeof(i4align); /* If there was no range variable, put question marks */ if (lastvar != (PSS_RNGTAB *) NULL) { status = psy_put(mstream, lastvar->pss_attdesc[i4align]->att_nmstr, lastvar->pss_attdesc[i4align]->att_nmlen, block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); } else { /* Don't know column name, just give question marks */ status = psy_put(mstream, "???", 3, block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); } /* Put a blank after the column name */ status = psy_put(mstream, " ", 1, block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); break; case DB_TBL_NM: /* The table name is in the result slot of the range table */ /* Put a blank before the table name */ status = psy_put(mstream, " ", 1, block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); /* NULL terminate and trim blanks from the table name */ MEcopy((char *) &rngtab->pss_rsrng.pss_tabname, sizeof(DB_TAB_NAME), buf); buf[DB_TAB_MAXNAME] = '\0'; slength = STtrmwhite(buf); status = psy_put(mstream, buf, slength, block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); /* Put a blank after the table name */ status = psy_put(mstream, " ", 1, block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); break; case DB_RES_COL: /* Result column: column in result table */ /* Put a blank before the column name */ status = psy_put(mstream, " ", 1, block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); /* Get the column number for the result column */ MEcopy((char *) p, sizeof(i4align), (char *) &i4align); p += sizeof(i4align); /* Get the column name from the result range variable */ lastvar = &rngtab->pss_rsrng; status = psy_put(mstream, lastvar->pss_attdesc[i4align]->att_nmstr, lastvar->pss_attdesc[i4align]->att_nmlen, block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); /* Put a blank after the column name */ status = psy_put(mstream, " ", 1, block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); break; default: /* Unknown special sequence: just put out as it came in */ status = psy_put(mstream, (char*) p - 1, 2, block, err_blk); if (DB_FAILURE_MACRO(status)) return (status); break; } break; default: /* No special case, just put the char */ status = psy_put(mstream, (char*) p - 1, 1, block, err_blk); break; } } /* Put a newline just after the statement */ status = psy_put(mstream, "\n", 1, block, err_blk); return (status); }
STATUS gcn_recrypt( bool clustered, u_i1 *local_mask, char *gcn_val, bool *v1DecryptErr, bool *writeOutput) { i2 pc; char *pv[ 3 ]; STATUS status = OK; char *p; char pwd[GC_L_PASSWORD]; i2 j; bool printable; *v1DecryptErr = FALSE; pc = gcu_words( gcn_val, NULL, pv, ',', 3 ); if (pc < 2 ) pv[1] = ""; if (pc < 3 ) pv[2] = ""; if (!STcasecmp(pv[2],"V0") || (pc < 3)) status = gcn_decrypt( pv[0], pv[1], pwd ); else status = gcn_decode( pv[0],(u_i1*)local_mask, pv[1], pwd ); if (status != OK) { if (!STcasecmp(pv[2],"V1")) *v1DecryptErr = TRUE; goto end_routine; } if (!STlength(pwd)) { if (!STcasecmp(pv[2],"V1")) *v1DecryptErr = TRUE; status = FAIL; goto end_routine; } p = &pwd[0]; printable = TRUE; for (j = 0; j < STlength(pwd); j++) { if (!CMprint(p)) { printable = FALSE; break; } CMnext(p); } if (!printable) { if (!STcasecmp(pv[2],"V1")) *v1DecryptErr = TRUE; status = FAIL; goto end_routine; } if (clustered) { if (!STncasecmp("V1", pv[2], STlength(pv[2]))) *writeOutput = TRUE; status = gcu_encode( pv[0], pwd, pv[1] ); STpolycat( 5, pv[0], ",", pv[1], ",", "V0", gcn_val ); } else { status = gcn_encode( pv[0],(u_i1*)local_mask, pwd, pv[1] ); STpolycat( 5, pv[0], ",", pv[1], ",", "V1", gcn_val ); } end_routine: return status; }