Ejemplo n.º 1
0
static VOID
uuid_format(
DB_DATA_VALUE   *dv,
UUID		*uuid)
{
    /* Pad or Truncate byte to sizeof(UUID) and align */
    if (dv->db_length != sizeof(UUID))
    {
	if (dv->db_length >= sizeof(UUID))
	{
	    MECOPY_CONST_MACRO((char *)dv->db_data, sizeof(UUID), (char *)uuid);
	}
	else
	{
	    MEcopy((char *)dv->db_data, dv->db_length, (char *)uuid);
	    MEfill(sizeof(UUID) - dv->db_length, '\0', 
		(char *)uuid + dv->db_length);
	}
    }
    else
    {
	/* Alignment */
	MECOPY_CONST_MACRO((char *)dv->db_data, sizeof(UUID), (char *)uuid);
    }
}
Ejemplo n.º 2
0
II_EXTERN II_UINT2
IIapi_getAPILength 
(
    IIAPI_ENVHNDL	*envHndl,
    IIAPI_DT_ID		dataType,
    II_LONG		dataLength,
    char		*buffer
)
{
    II_LONG length;

    switch( abs( dataType ) )
    {
    case IIAPI_LVCH_TYPE :
    case IIAPI_LBYTE_TYPE :
    case IIAPI_LNVCH_TYPE :
	if ( buffer != NULL )
	{
	    II_UINT2	seg_len;

	    MECOPY_CONST_MACRO( buffer, sizeof( seg_len ), (PTR)&seg_len );
	    length = sizeof( seg_len ) + 
		     (IIapi_isUCS2( dataType ) ? seg_len * 2 : seg_len);
	}
	else  if ( IIapi_isEnvHndl( envHndl )  &&
	           (envHndl->en_usrParm.up_mask1 & IIAPI_UP_MAX_SEGMENT_LEN) )
	    length = envHndl->en_usrParm.up_max_seglen;
	else
	    length = IIAPI_MAX_SEGMENT_LEN;
	break;

    case IIAPI_LCLOC_TYPE :
    case IIAPI_LBLOC_TYPE :
    case IIAPI_LNLOC_TYPE :
	length = sizeof( ADP_LOCATOR );
	break;

    default :
    {
	II_UINT2 var_len;

	if ( buffer == NULL  ||  ! IIapi_isVAR( dataType )  ||
	     IIAPI_ISNULL( dataType, dataLength, buffer ) )
	    length = (dataType < 0) ? dataLength - 1 : dataLength;
	else
	{
	    MECOPY_CONST_MACRO( buffer, sizeof( var_len ), (PTR)&var_len );
	    length = sizeof( var_len ) + 
		     (IIapi_isUCS2( dataType ) ? var_len * 2 : var_len);
	}
	break;
    }
    }

    return( (II_UINT2)length );
}
Ejemplo n.º 3
0
II_EXTERN II_VOID
IIapi_cnvtDataValue2GDV
(
    IIAPI_DESCRIPTOR	*descriptor,
    IIAPI_DATAVALUE	*dataValue,
    II_PTR		gcaValue
)
{
    II_UINT2 length;

    if ( descriptor->ds_nullable  &&  dataValue->dv_null )
    {
	length = IIapi_getGCALength( descriptor );
	MEfill( length, '\0', gcaValue );
	IIAPI_SETNULL( length, gcaValue );
        return;
    }

    length = min( descriptor->ds_length, dataValue->dv_length );
    MEcopy( dataValue->dv_value, length, gcaValue );

    if ( length < descriptor->ds_length )
	switch( descriptor->ds_dataType )
	{
	case IIAPI_NCHA_TYPE :
	{
	    u_i2 pad = 0x0020;	/* UCS-2 space */
	    u_i1 *ptr;

	    for( 
		 ptr = (u_i1 *)gcaValue + length; 
		 length < descriptor->ds_length; 
		 length += sizeof(pad), ptr += sizeof(pad) 
	       )
		MECOPY_CONST_MACRO( (PTR)&pad, sizeof(pad), (PTR)ptr );
	    break;
	}
	case IIAPI_CHA_TYPE :
	case IIAPI_CHR_TYPE :
	    MEfill( descriptor->ds_length - length, ' ', 
		    (PTR)((u_i1 *)gcaValue + length) );
	    break;

	default :
	    MEfill( descriptor->ds_length - length, '\0', 
		    (PTR)((u_i1 *)gcaValue + length) );
	    break;
	}

    length = descriptor->ds_length;
    if ( descriptor->ds_nullable )  IIAPI_SETNOTNULL( length + 1, gcaValue );

    return;
}
Ejemplo n.º 4
0
/*{
** Name: adu_cpn_dump	- Dump the value of a coupon
**
** Description:
**      This routine simply dumps the current value of a particular ADP_COUPON
**	structure.  The information is provided as ADF knows it -- tag & length
**	are labelled, the coupon itself is just a bunch of numbers. 
**
** Inputs:
**      adf_scb                         Session Control Block.
**      cpn_dv                          Ptr to DB_DATA_VALUE describing the
**					coupon to be printed
**      res_dv                          Ptr to DB_DATA_VALUE describing the
**					result area.
**
** Outputs:
**      *res_dv->db_data                Filled in.
**
**	Returns:
**	    DB_STATUS
**	Exceptions:
**	    none
**
** Side Effects:
**	    none
**
** History:
**      01-feb-1990 (fred)
**          Created.
[@history_template@]...
*/
DB_STATUS
adu_cpn_dump(
ADF_CB             *adf_scb,
DB_DATA_VALUE      *cpn_dv,
DB_DATA_VALUE      *res_dv)
{
    DB_DT_ID		dtid = abs(cpn_dv->db_datatype);
    ADP_PERIPHERAL	*p = (ADP_PERIPHERAL *) cpn_dv->db_data;
    DB_TEXT_STRING	*result = (DB_TEXT_STRING *) res_dv->db_data;
    ADP_PERIPHERAL	peripheral;
    
    if ((Adf_globs->Adi_dtptrs[dtid]->adi_dtstat_bits & AD_PERIPHERAL) == 0)
    {
	STcopy("<Not a peripheral>", (char *)result->db_t_text);
	result->db_t_count = STlength((char *)result->db_t_text);
    }
    else if (cpn_dv->db_length < sizeof(ADP_PERIPHERAL))
    {
	STcopy("<Too short to be a coupon>", (char *)result->db_t_text);
	result->db_t_count = STlength((char *)result->db_t_text);
    }
    else if (res_dv->db_length < 100)
    {
	STcopy("<Result too short>", (char *)result->db_t_text);
	result->db_t_count = STlength((char *)result->db_t_text);
    }
    else
    {
	MECOPY_CONST_MACRO((PTR)p, sizeof(peripheral), (PTR)&peripheral);
	p = &peripheral;
	TRformat(adu_finish_format, result, result->db_t_text,
			    (res_dv->db_length - sizeof(result->db_t_count)),
		    "Tag: %d., Length: %8x%8x, Cpn: <%#.#{%8x %}>",
		    p->per_tag, p->per_length0, p->per_length1,
			(sizeof(p->per_value.val_coupon) /
			    sizeof(p->per_value.val_coupon.cpn_id[0])),
			sizeof(p->per_value.val_coupon.cpn_id[0]),
			p->per_value.val_coupon.cpn_id, 0);
    }
    
    return(E_DB_OK);
}
Ejemplo n.º 5
0
static II_VOID
checkBLOBSegment
( 
    IIAPI_STMTHNDL	*stmtHndl, 
    IIAPI_DESCRIPTOR	*descriptor,
    IIAPI_MSG_BUFF	*msgBuff 
)
{
    i4  indicator;
    i4  length = sizeof( indicator );

    /*
    ** We only check when we know it is safe to do so.
    ** We must be reading segments, but not purging.
    ** and we require the request to be complete to
    ** avoid scenarios to complicated to explain or
    ** properly handle.
    */
    if ( stmtHndl->sh_flags & IIAPI_SH_MORE_SEGMENTS  &&
         ! ( stmtHndl->sh_flags & IIAPI_SH_PURGE_SEGMENTS )  &&
	 ! stmtHndl->sh_colFetch  &&  msgBuff->length >= length )
    {
	/*
	** Peak at the indicator.
	*/
	MECOPY_CONST_MACRO( msgBuff->data, length, (PTR)&indicator );

	if ( ! indicator )
	{
	    /*
	    ** We have the end-of-segments indicator.
	    ** Only consume it if the (optional) null
	    ** byte is also available (if not nullable,
	    ** the test is redundant).  The null byte
	    ** value is ignored (see description).
	    */
	    if ( descriptor->ds_nullable )  length++;

	    if ( msgBuff->length >= length )
	    {
		IIAPI_TRACE( IIAPI_TR_VERBOSE )
		    ( "checkBLOBSegment: found end-of-segments\n" );

		msgBuff->data += length;
		msgBuff->length -= length;

		/*
		** Since we have now finished the BLOB,
		** advance the column index to the next
		** column (wrap if finished all columns).
		** Since we check for sh_colFetch to be 
		** 0, we assume the gc_rowsReturned is
		** set properly and we are not in the
		** midst of a multi-row fetch.
		*/
		stmtHndl->sh_colInfo[ stmtHndl->sh_colIndex ].ci_flags |=
								IIAPI_CI_AVAIL;
		if ( ++stmtHndl->sh_colIndex >= stmtHndl->sh_colCount )
		{
		    /* SD issue 142188; Bug 123159.
		    ** Decrement the row count when the tuple is
		    ** completed.
		    */
		    if ( stmtHndl->sh_flags & IIAPI_SH_CURSOR )  
			stmtHndl->sh_rowCount--;
		    stmtHndl->sh_colIndex = 0;
		}
		stmtHndl->sh_flags &= ~IIAPI_SH_MORE_SEGMENTS;
	    }
	}
    }

    return;
}
Ejemplo n.º 6
0
static II_BOOL
cnvtBLOB2DataValue 
(
    IIAPI_STMTHNDL	*stmtHndl,
    IIAPI_DESCRIPTOR	*descriptor,
    IIAPI_MSG_BUFF	*msgBuff,
    IIAPI_DATAVALUE	*dataValue
)
{
    u_i2	char_size = IIapi_isUCS2( descriptor->ds_dataType ) ? 2 : 1;
    i4		indicator = 0;
    i4		length;
    u_i2	seg_len;

    /*
    ** The output buffer needs to be initialized with a 
    ** zero length segment.  Subsequent processing then 
    ** only needs to append input segments to the current 
    ** output segment.  The initial output data value 
    ** length is set to 0 (see IIapi_getColumns()) so 
    ** that we can detect when initialization is required.  
    ** Any non-zero value indicates an existing segment.
    */
    if ( ! dataValue->dv_length )
    {
	seg_len = 0;
	dataValue->dv_null = FALSE;
	dataValue->dv_length = sizeof( seg_len );
	MECOPY_CONST_MACRO( (PTR)&seg_len, 
			    sizeof( seg_len ), dataValue->dv_value );
    }

    /*
    ** The MORE_SEGMENTS flag gets set once the BLOB
    ** header is read.  If it is not set, we need to
    ** read the header.
    */
    if ( ! ( stmtHndl->sh_flags & IIAPI_SH_MORE_SEGMENTS ) )
    {
	i4	tag;
	u_i4	len0, len1;
	u_i1	*ptr = msgBuff->data;

	/*
	** BLOB processing assumes that if this is a NULL or
	** zero length BLOB, the entire BLOB is processed with
	** the header information.  In addition to the header,
	** we need to have access to the first segment indicator
	** and possibly the NULL byte.  Note that if the BLOB
	** is nullable but not NULL, the additional byte will
	** come from the segment length of the first segment.
	*/
	length = ADP_HDR_SIZE + sizeof( indicator ) + 
		 (descriptor->ds_nullable ? 1 : 0);

	if ( msgBuff->length < length )
	{
	    IIAPI_TRACE( IIAPI_TR_VERBOSE )
		( "cnvtBLOB2DataValue: need BLOB header for column %d\n",
		  (II_LONG)stmtHndl->sh_colIndex );
	    return( FALSE );
	}

	/*
	** Remove the header from the input buffer.  LOB 
	** column info is available once the header has 
	** been read.  Extract header data as column info.
	*/
	msgBuff->data += ADP_HDR_SIZE;
	msgBuff->length -= ADP_HDR_SIZE;
	stmtHndl->sh_colInfo[ stmtHndl->sh_colIndex ].ci_flags |= 
								IIAPI_CI_AVAIL;
	MECOPY_CONST_MACRO( ptr, sizeof( tag ), (PTR)&tag );

	if ( tag == ADP_P_GCA )
	{
	    ptr += sizeof( tag );
	    MECOPY_CONST_MACRO( ptr, sizeof( len0 ), (PTR)&len0 );
	    ptr += sizeof( len0 );
	    MECOPY_CONST_MACRO( ptr, sizeof( len1 ), (PTR)&len1 );
	    stmtHndl->sh_colInfo[ stmtHndl->sh_colIndex ].ci_flags |=
	    						IIAPI_CI_LOB_LENGTH;
	    stmtHndl->sh_colInfo[ stmtHndl->sh_colIndex ].ci_data.lob_length =
					((u_i8)len0 << 32) | (u_i8)len1;
	}

	IIAPI_TRACE( IIAPI_TR_VERBOSE )
	    ( "cnvtBLOB2DataValue: processed BLOB header for column %d\n",
	      (II_LONG)stmtHndl->sh_colIndex );

	/*
	** At this point we begin processing segments.
	*/
	stmtHndl->sh_flags |= IIAPI_SH_MORE_SEGMENTS;
    }

    /*
    ** Process the segment indicator.
    */
    length = sizeof( indicator );

    if ( msgBuff->length >= length )
    {
	/*
	** To consume the indicator, must have sufficient remaining
	** data to satisfy the request.  There are three cases:
	**
	** Indicator value	Nullable	Bytes Needed
	** ---------------	--------	------------
	**        0		   N		0 
	**        0		   Y		1 (NULL byte)
	**        1		  Y/N		3 (segment length + data)
	*/
	MECOPY_CONST_MACRO( msgBuff->data, length, (PTR)&indicator );
	length += indicator ? sizeof( seg_len ) + char_size
			    : (descriptor->ds_nullable ? 1 : 0);
    }

    if ( msgBuff->length < length )
    {
	IIAPI_TRACE( IIAPI_TR_VERBOSE )
	    ("cnvtBLOB2DataValue: need segment indicator for column %d\n",
	     (II_LONG)stmtHndl->sh_colIndex);
	return( FALSE );
    }

    /*
    ** Remove the indicator from the input buffer.
    */
    msgBuff->data += sizeof( indicator );
    msgBuff->length -= sizeof( indicator );

    /*
    ** If the indicator is 0, this is the end of the
    ** data segments and the BLOB.  Otherwise a
    ** segment follows.
    */
    if ( ! indicator )
    {
	IIAPI_TRACE( IIAPI_TR_VERBOSE )
	    ( "cnvtBLOB2DataValue: found end-of-segments indicator\n" );

	/*
	** During purging we ignore the NULL byte since
	** the data value was initialized when purging
	** started.
	*/
	if ( ! (stmtHndl->sh_flags & IIAPI_SH_PURGE_SEGMENTS) )
	    dataValue->dv_null = 
		descriptor->ds_nullable 
		    ? IIAPI_ISNULL(-descriptor->ds_dataType, 1, msgBuff->data)
		    : FALSE;

	/*
	** Remove NULL byte from input buffer and
	** terminate BLOB segment processing.
	*/
	if ( descriptor->ds_nullable )
	{
	    msgBuff->data++;
	    msgBuff->length--;
	}

	stmtHndl->sh_flags &= ~(IIAPI_SH_MORE_SEGMENTS |
				IIAPI_SH_PURGE_SEGMENTS);
    }
    else
    {
	/*
	** Read the segment length.  Limit the length
	** to what is available in the input buffer.
	*/
	MECOPY_CONST_MACRO( msgBuff->data, sizeof( seg_len ), (PTR)&seg_len );
	msgBuff->data += sizeof( seg_len );
	msgBuff->length -= sizeof( seg_len );
	length = min( seg_len, msgBuff->length / char_size ) * char_size;

	if ( stmtHndl->sh_flags & IIAPI_SH_PURGE_SEGMENTS )
	{
	    /*
	    ** Remove the available portion of
	    ** the segment from the input buffer.
	    */
	    msgBuff->data += length;
	    msgBuff->length -= length;
	    stmtHndl->sh_flags |= IIAPI_SH_LOST_SEGMENTS;

	    IIAPI_TRACE( IIAPI_TR_VERBOSE )
		( "cnvtBLOB2DataValue: discarding segment of %d bytes\n",
		  length );
	}
	else
	{
	    u_i2 new_len;

	    /*
	    ** We further limit the segment length to be
	    ** processed by the space available in the
	    ** output buffer.
	    */
	    length = min(length, descriptor->ds_length - dataValue->dv_length);
	    length -= length % char_size;	/* Whole characters only */

	    /*
	    ** Append input segment data to output segment.
	    */
	    MEcopy( msgBuff->data, length, 
		    (PTR)((char *)dataValue->dv_value + dataValue->dv_length) );
	    msgBuff->data += length;
	    msgBuff->length -= length;
	    dataValue->dv_length += length;

	    /*
	    ** Update the output embedded segment length.
	    */
	    new_len = (dataValue->dv_length - sizeof( new_len )) / char_size;
	    MECOPY_CONST_MACRO( (PTR)&new_len, 
				sizeof( new_len ), dataValue->dv_value );

	    IIAPI_TRACE( IIAPI_TR_VERBOSE )
		( "cnvtBLOB2DataValue: processed segment of %d bytes\n",
		  length );
	}

	/*
	** If the entire input segment was not consumed,
	** patch what remains to be a valid BLOB segment.
	** Create a segment indicator and segment length
	** to represent the remaining data.  There is 
	** room in the input buffer for this info to be 
	** pre-pended to what remains since the same 
	** info was removed from the input buffer above.
	*/
	if ( (length /= char_size) != seg_len )
	{
	    seg_len -= length;				/* Segment length */
	    msgBuff->data -= sizeof( seg_len );
	    msgBuff->length += sizeof( seg_len );
	    MECOPY_CONST_MACRO((PTR)&seg_len, sizeof(seg_len), msgBuff->data);

	    msgBuff->data -= sizeof( indicator );	/* Indicator */
	    msgBuff->length += sizeof( indicator );
	    MECOPY_CONST_MACRO( (PTR)&indicator, 
				sizeof( indicator ), msgBuff->data );

	    IIAPI_TRACE( IIAPI_TR_VERBOSE )
		( "cnvtBLOB2DataValue: split segment, %d bytes remain\n",
		  (II_LONG)seg_len );
	}
    }

    return( TRUE );
}
Ejemplo n.º 7
0
static II_BOOL
cnvtGDV2DataValue
(
    IIAPI_STMTHNDL	*stmtHndl,
    IIAPI_DESCRIPTOR	*descriptor,
    IIAPI_MSG_BUFF	*msgBuff,
    IIAPI_DATAVALUE	*dataValue,
    II_BOOL		compressed
)
{
    i4 data_len, avail_len;

    /*
    ** Check that any minimum required length 
    ** is available and determine GCA data length.
    */
    switch( descriptor->ds_dataType )
    {
    case IIAPI_VCH_TYPE :
    case IIAPI_VBYTE_TYPE :
    case IIAPI_NVCH_TYPE :
    case IIAPI_TXT_TYPE :
    case IIAPI_LTXT_TYPE :
	if ( ! compressed )
	    data_len = descriptor->ds_length;
	else
	{
	    u_i2 len;

	    /*
	    ** The embeded length indicator is required.  It may
	    ** have been already loaded (dv_length > 0) or may
	    ** be available in the input buffer.  Otherwise, wait
	    ** until it is available.
	    */
	    if ( dataValue->dv_length )
		MEcopy( dataValue->dv_value, sizeof( len ), (PTR)&len );
	    else  if ( msgBuff->length >= sizeof( len ) )  
		MEcopy( (PTR)msgBuff->data, sizeof( len ), (PTR)&len );
	    else
	    {
		IIAPI_TRACE( IIAPI_TR_VERBOSE )
		    ( "cnvtGDV2DataValue: need embedded length (%d bytes, %d available)\n",
		      sizeof( len ), msgBuff->length );
		return( FALSE );
	    }

	    /*
	    ** Get the actual length of the compressed column.
	    */
	    data_len = sizeof( len ) + 
		       (IIapi_isUCS2(descriptor->ds_dataType) ? len * 2 : len);
	}
    	break;

    case IIAPI_LCLOC_TYPE :
    case IIAPI_LBLOC_TYPE :
    case IIAPI_LNLOC_TYPE :
    {
	i4	tag;
	u_i4	len0, len1;
	u_i1	*ptr = msgBuff->data;

	/*
	** The ADF PERIPHERAL header must be read along with
	** the ADP locator value.
	*/
	if ( msgBuff->length < (ADP_HDR_SIZE + sizeof(ADP_LOCATOR)) )
	{
	    IIAPI_TRACE( IIAPI_TR_VERBOSE )
		( "cnvtGDV2DataValue: need LOCATOR (%d bytes, %d available)\n",
		  ADP_HDR_SIZE + sizeof(ADP_LOCATOR), msgBuff->length );
	    return( FALSE );
	}

	/*
	** With the full ADP locator object available, read
	** the header and set remaining data length.  Column
	** info is availabe once the header is read.
	*/
	msgBuff->data += ADP_HDR_SIZE;
	msgBuff->length -= ADP_HDR_SIZE;
	stmtHndl->sh_colInfo[ stmtHndl->sh_colIndex ].ci_flags |= 
								IIAPI_CI_AVAIL;
	MECOPY_CONST_MACRO( ptr, sizeof( tag ), (PTR)&tag );

	if ( tag == ADP_P_LOCATOR )
	{
	    ptr += sizeof( tag );
	    MECOPY_CONST_MACRO( ptr, sizeof( len0 ), (PTR)&len0 );
	    ptr += sizeof( len0 );
	    MECOPY_CONST_MACRO( ptr, sizeof( len1 ), (PTR)&len1 );
	    stmtHndl->sh_colInfo[ stmtHndl->sh_colIndex ].ci_flags |=
	    						IIAPI_CI_LOB_LENGTH;
	    stmtHndl->sh_colInfo[ stmtHndl->sh_colIndex ].ci_data.lob_length =
					((u_i8)len0 << 32) | (u_i8)len1;
	}

	data_len = sizeof( ADP_LOCATOR );
    	break;
    }
    default :
	data_len = descriptor->ds_length;
    	break;
    }

    /*
    ** Determine amount of data available to be loaded:
    ** smaller of amount in input buffer and amount not 
    ** yet loaded.
    */
    avail_len = min( msgBuff->length, data_len - dataValue->dv_length );

    IIAPI_TRACE( IIAPI_TR_VERBOSE )
	( "cnvtGDV2DataValue: loading %d of %d bytes (%d loaded)\n",
	  avail_len, data_len, (II_LONG)dataValue->dv_length );

    /*
    ** Load available data in input buffer.
    */
    if ( avail_len )
    {
	MEcopy( (PTR)msgBuff->data, avail_len, 
		(PTR)((char *)dataValue->dv_value + dataValue->dv_length) );
	msgBuff->data += avail_len;
	msgBuff->length -= avail_len;
	dataValue->dv_length += avail_len;
    }

    /*
    ** Check to see if all data has been loaded.
    */
    if ( dataValue->dv_length < data_len )
    {
	IIAPI_TRACE( IIAPI_TR_VERBOSE )
	    ( "cnvtGDV2DataValue: insufficient data: need %d bytes\n",
	      data_len - dataValue->dv_length );
	return( FALSE );
    }

    /*
    ** For nullable columns, check the NULL byte.
    */
    if ( descriptor->ds_nullable )
    {
	/*
	** Check to see if NULL byte is in input buffer.
	*/
	if ( ! msgBuff->length )  
	{
	    IIAPI_TRACE( IIAPI_TR_VERBOSE )
		( "cnvtGDV2DataValue: need NULL byte (1 byte, 0 available\n" );
	    return( FALSE );
	}

	if ( ! (*msgBuff->data & ADF_NVL_BIT) )
	    dataValue->dv_null = FALSE;
	else
	{
	    dataValue->dv_null = TRUE;
	    dataValue->dv_length = 0;	/* Force to 0 since set above */
	}

	msgBuff->data++;	/* Remove NULL byte from input buffer */
	msgBuff->length--;
    }

    if ( IIapi_isVAR( descriptor->ds_dataType )  &&  ! dataValue->dv_null )
    {
	/*
	** Variable length types only return the length of
	** the actual data, not their fully padded length.
	*/
	u_i2 len;

	MEcopy( dataValue->dv_value, sizeof( len ), (PTR)&len );
	dataValue->dv_length = sizeof( len ) +
		    (IIapi_isUCS2( descriptor->ds_dataType ) ? len * 2 : len);
    }

    return( TRUE );
}
Ejemplo n.º 8
0
/*{
** Name: psy_auser - Alter user
**
**  INTERNAL PSF call format: status = psy_auser(&psy_cb, sess_cb);
**
** Description:
**	This procedure alters an iiuser tuple.  If the
**	user does not exist, the statement is aborted.
**	If the user does exist, the associated
**	iiuser tuple is replaced.
**	This procedure is called for SQL language only.
**
** Inputs:
**      psy_cb
**	    .psy_usrq			user list
**	sess_cb				Pointer to session control block
**					(Can be NULL)
**
** Outputs:
**      psy_cb
**	    .psy_error			Filled in if error happens
**	Returns:
**	    E_DB_OK			Function completed normally.
**	    E_DB_WARN			Function completed with warning(s);
**	    E_DB_ERROR			Function failed; non-catastrophic error
**	    E_DB_SEVERE			Function failed; catastrophic error
**	Exceptions:
**	    none
**
** Side Effects:
**	    Replaces tuples in iiuser.
**
** History:
**	04-sep-89 (ralph)
**          written
**      16-jan-90 (ralph)
**          add support for user passwords
**	12-mar-90 (andre)
**	    set rdr_2types_mask to 0.
**      22-may-90 (teg)
**          init rdr_instr to RDF_NO_INSTR
**	08-aug-90 (ralph)
**	    add support for oldpassword (as in ALTER USER OLDPASSWORD = '******')
**	12-apr-95 (forky01)
**	    Apply default privs when only privs specified to allow backward
**	    compatibility to fix Secure 2.0 code.
**	28-jul-2003 (gupsh01)
**	    Added check for case when noprivileges have been added and
**	    nodefault_privileges is not specified, with a profile in alter
**	    user statement. 
*/
DB_STATUS
psy_auser(
	PSY_CB             *psy_cb,
	PSS_SESBLK	   *sess_cb)
{
    DB_STATUS		status, stat;
    RDF_CB		rdf_cb;
    i4		err_code;
    register RDR_RB	*rdf_rb = &rdf_cb.rdf_rb;
    struct
    {
	DU_USER	    ustuple;
	DU_USER	    ustuple2;
    }			usparam;
    register DU_USER	*ustup  = &usparam.ustuple;
    register DU_USER	*ustup2 = &usparam.ustuple2;
    PSY_USR		*psy_usr;
    bool                encrypt;
    bool                encrypt2;
    SCF_CB              scf_cb;
    SCF_CB              scf_cb2;
    DB_DATA_VALUE	db_data;
    DB_DATE	        dateval;

    /* This code is called for SQL only */

    /*
    ** Fill in the part of RDF request block that will be constant.
    */
    pst_rdfcb_init(&rdf_cb, sess_cb);
    rdf_rb->rdr_update_op   = RDR_REPLACE;
    rdf_rb->rdr_status	    = DB_SQL;
    rdf_rb->rdr_types_mask  = RDR_USER;
    rdf_rb->rdr_qrytuple    = (PTR) ustup;
    rdf_rb->rdr_qtuple_count = 1;

    ustup->du_gid	= 0;
    ustup->du_mid	= 0;
    ustup->du_flagsmask  = 0;

    /* User profile */
    if(psy_cb->psy_usflag& PSY_USRPROFILE)
    {
	    MECOPY_CONST_MACRO((PTR)&psy_cb->psy_usprofile, 
		sizeof(psy_cb->psy_usprofile), 
	    	(PTR)&ustup->du_profile);
	   
	    ustup->du_flagsmask|= DU_UHASPROFILE;
    }
    else
    {
	MEfill(sizeof(ustup->du_profile),
	       (u_char)' ',
	       (PTR)&ustup->du_profile);
    }

    if ((psy_cb->psy_usflag& PSY_USRPROFILE) &&
	(psy_cb->psy_usflag& PSY_USRPRIVS) &&
	(psy_cb->psy_usflag& PSY_UNOPRIVS) &&
        !(psy_cb->psy_usflag & PSY_UNODEFPRIV))
    {
  	/* If alter user has PSY_UNOPRIVS specified and
  	** we have provided a profile for this user
  	** but we have not set the nodefault_privileges
  	** specified, We should return an error. profile
  	** may have default_privileges, which will be
  	** inherited by the user with noprivileges.
  	*/
  	  err_code = E_US1968_6504_UNOPRIV_WDEFAULT;
  	  (VOID) psf_error( E_US1968_6504_UNOPRIV_WDEFAULT, 0L,
  	     PSF_USERERR, &err_code, &psy_cb->psy_error, 0);
  	  status = E_DB_ERROR;

	  return(status);
    }

    if(psy_cb->psy_usflag& PSY_USRDEFPRIV)
    {
	ustup->du_defpriv = psy_cb->psy_usdefprivs;
	ustup->du_flagsmask|= DU_UDEFPRIV;
	/* Add default=all indicator */
	if(psy_cb->psy_usflag & PSY_USRDEFALL)
		ustup->du_flagsmask|=DU_UDEFALL;

	/* set value of nodefault_privileges flag */
	if (psy_cb->psy_usflag & PSY_UNODEFPRIV)
	  ustup->du_flagsmask|= DU_UNODEFPRIV;
    }
    else
    {
	/*
	** If no default specified use all privileges
	*/
	if (psy_cb->psy_usflag & PSY_USRPRIVS)
		ustup->du_defpriv = (i4)psy_cb->psy_usprivs;
	else
		ustup->du_defpriv = 0;
    }

    /*
    ** Expiration date, may be empty
    */
    if(psy_cb->psy_usflag& PSY_USREXPDATE)
    {
	/*
	** Date already formatted earlier
	*/
	MECOPY_CONST_MACRO((PTR)&psy_cb->psy_date, sizeof(DB_DATE), 
			(PTR)&ustup->du_expdate);
	ustup->du_flagsmask|= DU_UEXPDATE;
    }
    else
    {
	/*
	** Initialize to the empty date
	*/
	db_data.db_datatype  = DB_DTE_TYPE;
	db_data.db_prec	 = 0;
	db_data.db_length    = DB_DTE_LEN;
	db_data.db_data	 = (PTR)&ustup->du_expdate;
	status = adc_getempty(sess_cb->pss_adfcb, &db_data);
	if(status)
		return status;
    }
    /*
    ** Check if adding, deleting, or setting privileges
    */
    ustup->du_status = (i4) psy_cb->psy_usprivs;

	
    if (psy_cb->psy_usflag & PSY_USRAPRIVS)
	ustup->du_flagsmask |=  DU_UAPRIV;
    else if (psy_cb->psy_usflag & PSY_USRDPRIVS)
	ustup->du_flagsmask |=  DU_UDPRIV;
    else if (psy_cb->psy_usflag & PSY_USRPRIVS)
	ustup->du_flagsmask |=  DU_UPRIV;
    else
	ustup->du_status = 0;
    /*
    ** Check if updating security audit options
    */
    if (psy_cb->psy_usflag & PSY_USRSECAUDIT)
    {
	if(psy_cb->psy_ussecaudit & PSY_USAU_ALL_EVENTS)
		ustup->du_flagsmask |= DU_UALLEVENTS;
	else
		ustup->du_flagsmask |= DU_UDEFEVENTS;
	if (psy_cb->psy_ussecaudit & PSY_USAU_QRYTEXT)
		ustup->du_flagsmask |= DU_UQRYTEXT;
	else
		ustup->du_flagsmask |= DU_UNOQRYTEXT;
    }

    if (psy_cb->psy_usflag & PSY_USRDEFGRP)
    {
	MEcopy((PTR)&psy_cb->psy_usgroup,
	       sizeof(ustup->du_group),
	       (PTR)&ustup->du_group);
	ustup->du_flagsmask|= DU_UGROUP;
    }
    else
    {
	MEfill(sizeof(ustup->du_group),
	       (u_char)' ',
	       (PTR)&ustup->du_group);
    }

    encrypt = (STskipblank((char *)&psy_cb->psy_apass,
                           (i4)sizeof(psy_cb->psy_apass))
                            != NULL);
    if (encrypt)
    {
        scf_cb.scf_length       = sizeof (SCF_CB);
        scf_cb.scf_type		= SCF_CB_TYPE;
        scf_cb.scf_facility     = DB_PSF_ID;
        scf_cb.scf_session      = sess_cb->pss_sessid;
        scf_cb.scf_nbr_union.scf_xpasskey =
            (PTR)&ustup->du_name;
        scf_cb.scf_ptr_union.scf_xpassword =
            (PTR)&ustup->du_pass;
        scf_cb.scf_len_union.scf_xpwdlen =
             sizeof(ustup->du_pass);
    }
    else
        STRUCT_ASSIGN_MACRO(psy_cb->psy_apass, ustup->du_pass);

    if (psy_cb->psy_usflag & PSY_USRPASS)
    {
	ustup->du_flagsmask|= DU_UPASS;
        if (psy_cb->psy_usflag & PSY_USREXTPASS)
	     ustup->du_flagsmask |= DU_UEXTPASS;
    }
    else
    {
	MEfill(sizeof(ustup->du_pass),
	       (u_char)' ',
	       (PTR)&ustup->du_pass);
    }

    encrypt2 = (STskipblank((char *)&psy_cb->psy_bpass,
                           (i4)sizeof(psy_cb->psy_bpass))
                            != NULL);
    if (encrypt2)
    {
        scf_cb2.scf_length      = sizeof (SCF_CB);
        scf_cb2.scf_type	= SCF_CB_TYPE;
        scf_cb2.scf_facility    = DB_PSF_ID;
        scf_cb2.scf_session     = sess_cb->pss_sessid;
        scf_cb2.scf_nbr_union.scf_xpasskey =
            (PTR)&ustup->du_name;
        scf_cb2.scf_ptr_union.scf_xpassword =
            (PTR)&ustup2->du_pass;
        scf_cb2.scf_len_union.scf_xpwdlen =
             sizeof(ustup2->du_pass);
    }
    else
        STRUCT_ASSIGN_MACRO(psy_cb->psy_bpass, ustup2->du_pass);

    if (psy_cb->psy_usflag & PSY_USROLDPASS)
	ustup->du_flagsmask|= DU_UOLDPASS;
    else
    {
	MEfill(sizeof(ustup2->du_pass),
	       (u_char)' ',
	       (PTR)&ustup2->du_pass);
    }

    status = E_DB_OK;

    for (psy_usr  = (PSY_USR *)  psy_cb->psy_usrq.q_next;
	 psy_usr != (PSY_USR *) &psy_cb->psy_usrq;
	 psy_usr  = (PSY_USR *)  psy_usr->queue.q_next
	)
    {
	/* STRUCT_ASSIGN_MACRO(psy_usr->psy_usrnm,
			       ustup->du_name); */
	MEcopy((PTR)&psy_usr->psy_usrnm,
	       sizeof(ustup->du_name),
	       (PTR)&ustup->du_name);

	/* Encrypt the password if nonblank and not already hex value */

        if (encrypt)
        {
            STRUCT_ASSIGN_MACRO(psy_cb->psy_apass, ustup->du_pass);
	    if(!(psy_cb->psy_usflag & PSY_HEXPASS))
	    {
		status = scf_call(SCU_XENCODE, &scf_cb);
		if (status != E_DB_OK)
		{
		    err_code = scf_cb.scf_error.err_code;
		    (VOID) psf_error(E_PS0D43_XENCODE_ERROR, 0L,
			PSF_INTERR, &err_code, &psy_cb->psy_error, 0);
		    status = (status > E_DB_SEVERE) ? status : E_DB_SEVERE;
		    return(status);
		}
            }
        }

        if (encrypt2)
        {
            STRUCT_ASSIGN_MACRO(psy_cb->psy_bpass, ustup2->du_pass);
            status = scf_call(SCU_XENCODE, &scf_cb2);
            if (status != E_DB_OK)
            {
                err_code = scf_cb2.scf_error.err_code;
                (VOID) psf_error(E_PS0D43_XENCODE_ERROR, 0L,
                                PSF_INTERR, &err_code, &psy_cb->psy_error, 0);
                status = (status > E_DB_SEVERE) ? status : E_DB_SEVERE;
                return(status);
            }
        }

	stat = rdf_call(RDF_UPDATE, (PTR) &rdf_cb);
	status = (stat > status) ? stat : status;

	if (DB_FAILURE_MACRO(stat))
	    break;
    }

    if (DB_FAILURE_MACRO(status))
	(VOID) psf_rdf_error(RDF_UPDATE, &rdf_cb.rdf_error, 
	    &psy_cb->psy_error);

    return    (status);
} 
Ejemplo n.º 9
0
/*{
** Name: psy_aprofile - Alter profile
**
** Description:
**	This procedure alters an iiprofile tuple.  If the
**	user does not exist, the statement is aborted.
**	If the user does exist, the associated
**	iiprofile tuple is replaced.
**	This procedure is called for SQL language only.
**
** Inputs:
**      psy_cb
**	    .psy_usrq			user list
**	sess_cb				Pointer to session control block
**					(Can be NULL)
**
** Outputs:
**      psy_cb
**	    .psy_error			Filled in if error happens
**	Returns:
**	    E_DB_OK			Function completed normally.
**	    E_DB_WARN			Function completed with warning(s);
**	    E_DB_ERROR			Function failed; non-catastrophic error
**	    E_DB_SEVERE			Function failed; catastrophic error
**	Exceptions:
**	    none
**
** Side Effects:
**	    Replaces tuples in iiuser.
**
** History:
**	27-aug-93 (robf)
**          Written
*/
static DB_STATUS
psy_aprofile(
	PSY_CB             *psy_cb,
	PSS_SESBLK	   *sess_cb)
{
    DB_STATUS		status, stat;
    RDF_CB		rdf_cb;
    i4		err_code;
    register RDR_RB	*rdf_rb = &rdf_cb.rdf_rb;
    struct
    {
	DU_PROFILE	    protuple;
	DU_PROFILE	    protuple2;
    }			usparam;
    register DU_PROFILE	*protup  = &usparam.protuple;
    register DU_PROFILE	*protup2 = &usparam.protuple2;
    PSY_USR		*psy_usr;
    SCF_CB              scf_cb;
    SCF_CB              scf_cb2;
    DB_DATA_VALUE	db_data;
    DB_DATE	        dateval;

    FUNC_EXTERN DB_STATUS rdf_call();
    FUNC_EXTERN DB_STATUS scf_call();

    /* This code is called for SQL only */

    /*
    ** Fill in the part of RDF request block that will be constant.
    */
    pst_rdfcb_init(&rdf_cb, sess_cb);
    rdf_rb->rdr_update_op   = RDR_REPLACE;
    rdf_rb->rdr_status	    = DB_SQL;
    rdf_rb->rdr_2types_mask = RDR2_PROFILE;
    rdf_rb->rdr_qrytuple    = (PTR) protup;
    rdf_rb->rdr_qtuple_count = 1;

    protup->du_flagsmask  = 0;

    if(psy_cb->psy_usflag& PSY_USRDEFPRIV)
    {
	protup->du_defpriv = psy_cb->psy_usdefprivs;
	protup->du_flagsmask|= DU_UDEFPRIV;
	/* Add default=all indicator */
	if(psy_cb->psy_usflag & PSY_USRDEFALL)
		protup->du_flagsmask|=DU_UDEFALL;

	/* if user has specified nodefault_privileges we
	** store this flag to negotiate the final status
	** of default privileges.
	*/
	if (psy_cb->psy_usflag & PSY_UNODEFPRIV)
  	  protup->du_flagsmask|= DU_UNODEFPRIV;
    }
    else
	protup->du_defpriv = 0;

    /*
    ** Expiration date, may be empty
    */
    if(psy_cb->psy_usflag& PSY_USREXPDATE)
    {
	/*
	** Date already formatted earlier
	*/
	MECOPY_CONST_MACRO((PTR)&psy_cb->psy_date, sizeof(DB_DATE), 
			(PTR)&protup->du_expdate);
	protup->du_flagsmask|= DU_UEXPDATE;
    }
    else
    {
	/*
	** Initialize to the empty date
	*/
	db_data.db_datatype  = DB_DTE_TYPE;
	db_data.db_prec	 = 0;
	db_data.db_length    = DB_DTE_LEN;
	db_data.db_data	 = (PTR)&protup->du_expdate;
	status = adc_getempty(sess_cb->pss_adfcb, &db_data);
	if(status)
		return status;
    }
    /*
    ** Check if adding, deleting, or setting privileges
    */
    protup->du_status = (i4) psy_cb->psy_usprivs;
    if (psy_cb->psy_usflag & PSY_USRAPRIVS)
	protup->du_flagsmask |=  DU_UAPRIV;
    else if (psy_cb->psy_usflag & PSY_USRDPRIVS)
	protup->du_flagsmask |=  DU_UDPRIV;
    else if (psy_cb->psy_usflag & PSY_USRPRIVS)
	protup->du_flagsmask |=  DU_UPRIV;
    else
	protup->du_status = 0;
    /*
    ** Check if updating security audit options
    */
    if (psy_cb->psy_usflag & PSY_USRSECAUDIT)
    {
	if(psy_cb->psy_ussecaudit & PSY_USAU_ALL_EVENTS)
		protup->du_flagsmask |= DU_UALLEVENTS;
	else
		protup->du_flagsmask |= DU_UDEFEVENTS;
	if (psy_cb->psy_ussecaudit & PSY_USAU_QRYTEXT)
		protup->du_flagsmask |= DU_UQRYTEXT;
	else
		protup->du_flagsmask |= DU_UNOQRYTEXT;
    }

    if (psy_cb->psy_usflag & PSY_USRDEFGRP)
    {
	MEcopy((PTR)&psy_cb->psy_usgroup,
	       sizeof(protup->du_group),
	       (PTR)&protup->du_group);
	protup->du_flagsmask|= DU_UGROUP;
    }
    else
    {
	MEfill(sizeof(protup->du_group),
	       (u_char)' ',
	       (PTR)&protup->du_group);
    }



    status = E_DB_OK;

    for (psy_usr  = (PSY_USR *)  psy_cb->psy_usrq.q_next;
	 psy_usr != (PSY_USR *) &psy_cb->psy_usrq;
	 psy_usr  = (PSY_USR *)  psy_usr->queue.q_next
	)
    {
	/* STRUCT_ASSIGN_MACRO(psy_usr->psy_usrnm,
			       protup->du_name); */
	MEcopy((PTR)&psy_usr->psy_usrnm,
	       sizeof(protup->du_name),
	       (PTR)&protup->du_name);

	stat = rdf_call(RDF_UPDATE, (PTR)&rdf_cb);
	status = (stat > status) ? stat : status;

	if (DB_FAILURE_MACRO(stat))
	    break;
    }

    if (DB_FAILURE_MACRO(status))
	(VOID) psf_rdf_error(RDF_UPDATE, &rdf_cb.rdf_error, 
	    &psy_cb->psy_error);

    return    (status);
}