Пример #1
0
/*{
** Name: opx_init	- initialize the AIC and PAINE handlers
**
** Description:
**      This routine will inform SCF of the AIC and PAINE handlers
**
** Inputs:
**	opf_cb				    - ptr to caller's control block
**
** Outputs:
**	Returns:
**	    E_DB_OK
**          E_DB_ERROR - if initialization failed
**	Exceptions:
**	    none
**
** Side Effects:
**	    none
**
** History:
**      31-mar-87 (seputis)
**          initial creation
**      12-dec-88 (seputis)
**	    return E_DB_OK
[@history_template@]...
*/
DB_STATUS
opx_init(
	OPF_CB		*opf_cb)
{
    SCF_CB                 scf_cb;
    DB_STATUS              scf_status;

    scf_cb.scf_length = sizeof(scf_cb);
    scf_cb.scf_type = SCF_CB_TYPE;
    scf_cb.scf_facility = DB_OPF_ID;
    scf_cb.scf_ptr_union.scf_afcn = opx_call;
    scf_cb.scf_session = DB_NOSESSION;
    scf_cb.scf_nbr_union.scf_amask = SCS_PAINE_MASK;
    scf_status = scf_call(SCS_DECLARE, &scf_cb);
# ifdef E_OP0090_PAINE
    if (DB_FAILURE_MACRO(scf_status))
    {
	opx_rverror( opf_cb, scf_status, E_OP0090_PAINE,
	    scf_cb.scf_error.err_code);
	return(E_DB_ERROR);
    }
# endif
    scf_cb.scf_nbr_union.scf_amask = SCS_AIC_MASK;
    scf_status = scf_call(SCS_DECLARE, &scf_cb);
# ifdef E_OP0091_AIC
    if (DB_FAILURE_MACRO(scf_status))
    {
	opx_rverror( opf_cb, scf_status, E_OP0091_AIC,
	    scf_cb.scf_error.err_code);
	return(E_DB_ERROR);
    }
# endif
    return(E_DB_OK);
}
Пример #2
0
/*
** Name: gwsxa_scf_session - Return the session SCF session 
**       identifier.
**
** Returns:
**	E_DB_OK - No error
**	Other   - Something went wrong
**
** History:
**	14-sep-92 (robf)
**	    Created
*/
DB_STATUS 
gwsxa_scf_session(CS_SID *where)
{
        SCF_CB      scf_cb;
        SCF_SCI     sci_list;
        DB_STATUS   status;

        scf_cb.scf_length = sizeof(SCF_CB);
        scf_cb.scf_type = SCF_CB_TYPE;
        scf_cb.scf_facility = DB_SCF_ID; /* Get the SCF session id */
        scf_cb.scf_session = DB_NOSESSION;
        scf_cb.scf_len_union.scf_ilength = 1;
        /* may cause lint message */
        scf_cb.scf_ptr_union.scf_sci = (SCI_LIST*) &sci_list;
        sci_list.sci_code = SCI_SCB;
        sci_list.sci_length = sizeof(where);
        sci_list.sci_aresult = (PTR)where;
        sci_list.sci_rlength = NULL;
        status = scf_call(SCU_INFORMATION, &scf_cb);
        if (status != E_DB_OK)
        {
	    gwf_error(scf_cb.scf_error.err_code, GWF_INTERR, 0);
	    gwf_error(E_GW0302_SCU_INFORMATION_ERROR, GWF_INTERR, 0);
        }
        return(status);
}
Пример #3
0
/*
** sxf_clr_activity - Clear the server activity.
**
** History:
**	11-dec-92 (robf) 
**		Created
** Inputs:
**	None
**
** Outputs:
**	None
**
*/
VOID
sxf_clr_activity(void)
{
	SCF_CB 		scb;
	DB_STATUS 	status;
        i4	    	error;

	scb.scf_len_union.scf_blength=0;
	scb.scf_nbr_union.scf_atype = SCS_A_MAJOR;
	scb.scf_type=SCF_CB_TYPE;
	scb.scf_length=SCF_CB_SIZE;
	scb.scf_session=DB_NOSESSION;
	scb.scf_facility=DB_SXF_ID;

	status=scf_call(SCS_CLR_ACTIVITY, &scb);
	if (status!=E_DB_OK)
	{
		/*
		**	Log something went wrong and continue.
		*/
		_VOID_ ule_format(scb.scf_error.err_code, NULL, ULE_LOG,
			NULL, NULL, 0L, NULL, &error, 0);
		_VOID_ ule_format(E_SX1063_SCF_CLR_ACTIVITY, NULL, ULE_LOG,
			NULL, NULL, 0L, NULL, &error, 0);
	}
}
Пример #4
0
/*{
** Name: opx_sccerror	- report error to user
**
** Description:
**      Report a message to the user
**
** Inputs:
**      status                          status of error
**      msg_buffer                      ptr to message
**      error                           ingres error number
**
** Outputs:
**	Returns:
**	    VOID
**	Exceptions:
**	    none
**
** Side Effects:
**	    fatal status will cause query to be aborted, and previous text sent
**          to user to be flushed
**
** History:
**      15-apr-87 (seputis)
**          initial creation
**	21-may-89 (jrb)
**	    changed interface to this routine to accept generic error
**      28-may-92 (seputis)
**          - dump query for any error which is logged
**	24-oct-92 (andre)
**	    replaced generic error (i4) with sqlstate (DB_SQLSTATE *) in
**	    the interface of opx_sccerror()
**	13-nov-92 (andre)
**	    If sqlstate is not passed into opx_sccerror(), set scf_sqlstate 
**	    to MISC_ING_ERRORS"

[@history_line@]...
[@history_template@]...
*/
static DB_STATUS
opx_sccerror(
	DB_STATUS	   status,
	DB_SQLSTATE	   *sqlstate,
	OPX_ERROR          error,
	char               *msg_buffer,
	i4                msg_length)
{
    SCF_CB                 scf_cb;
    DB_STATUS              scf_status;

    scf_cb.scf_length = sizeof(scf_cb);
    scf_cb.scf_type = SCF_CB_TYPE;
    scf_cb.scf_facility = DB_OPF_ID;
    scf_cb.scf_nbr_union.scf_local_error = error;
    if (sqlstate)
	STRUCT_ASSIGN_MACRO((*sqlstate), scf_cb.scf_aux_union.scf_sqlstate);
    else
	MEcopy((PTR) SS50000_MISC_ERRORS, DB_SQLSTATE_STRING_LEN,
	    (PTR) scf_cb.scf_aux_union.scf_sqlstate.db_sqlstate);
    scf_cb.scf_len_union.scf_blength = msg_length;
    scf_cb.scf_ptr_union.scf_buffer = msg_buffer;
    scf_cb.scf_session = DB_NOSESSION;
    if (DB_SUCCESS_MACRO(status))
	scf_status = scf_call(SCC_TRACE, &scf_cb);
    else
    {
	/* Dump the session that caused this error */
	if ((error % 256) >= 128)
	    scs_avformat();	/* dump info on internal
				** consistency checks only,
				** i.e. do not dump for errors like
				** OP0008 */
	scf_status = scf_call(SCC_ERROR, &scf_cb);
    }
    if (scf_status != E_DB_OK)
    {
	TRdisplay("SCF error displaying OPF message to user\n");
	TRdisplay("OPF message is :%s",msg_buffer);
    }
    return (scf_status);
}
Пример #5
0
DB_STATUS
sca_trace( i4  dispose_mask, i4  length, char *message )
{
    SCF_CB		*scf_cb;
    SCD_SCB		*scb;
    DB_STATUS		scf_status;

    if (    (dispose_mask &
		~(ADD_FRONTEND_MASK | ADD_ERROR_LOG_MASK | ADD_TRACE_FILE_MASK))
	||  !message
	||  (length <= 0)
	||  (length > ER_MAX_LEN))
    {
	return(E_DB_ERROR);
    }
	
    if ((dispose_mask & ADD_FRONTEND_MASK)
		&& (Sc_main_cb->sc_state == SC_OPERATIONAL))
    {
	CSget_scb((CS_SCB **)&scb);

	scf_cb = scb->scb_sscb.sscb_scccb;
	scf_cb->scf_length = sizeof(*scf_cb);
	scf_cb->scf_type = SCF_CB_TYPE;
	scf_cb->scf_facility = DB_PSF_ID;
	scf_cb->scf_len_union.scf_blength = (u_i4) length;
	scf_cb->scf_ptr_union.scf_buffer = message;
	scf_cb->scf_session = (SCF_SESSION)scb;  /* print to current session */

	scf_status = scf_call(SCC_TRACE, scf_cb);

	if (scf_status != E_DB_OK)
	{
	    TRdisplay(
		"SCA_TRACE: SCF error %d. displaying query text to user\n",
		scf_cb->scf_error.err_code);
	}
    }

    if ((dispose_mask & (ADD_TRACE_FILE_MASK | ADD_ERROR_LOG_MASK))
	    == ADD_TRACE_FILE_MASK)
    {
	TRdisplay("%t\n", length, message);
    }

    if (dispose_mask & ADD_ERROR_LOG_MASK)
    {
	sc0ePut(NULL, E_SC0318_SCA_USER_TRACE, 0, 1, length, message);
    }
    return(E_DB_OK);
}
Пример #6
0
/*{
** Name: psf_scctrace	- send output line to front end
**
** Description:
**      Send a formatted output line to the front end. A NL character
**	is added to the end of the message. Buffer to which a pointer
**	is received should have on extra byte for `\n'.
**
** Inputs:
**	arg				place holder
**	msg_len				length of message
**      msg_buffer                      ptr to message
**
** Outputs:
**	Returns:
**	    VOID
**	Exceptions:
**	    none
**
** Side Effects:
**
** History:
**      3-aug-87 (daved)
**          initial creation
**	12-jan-87 (stec)
**	    Added code inserting NL into the buffer.
**	22-feb-88 (stec)
**	    Fix `set printqry' problem. `\n' should not
**	    be preceded by `\0'.
**	21-may-89 (jrb)
**	    renamed scf_enumber to scf_local_error
**	22-may-01 (hayke02)
**	    We now do not add on a newline character ('\n') if we already
**	    have one at the end of the message. This prevents a SIGBUS on
**	    some platforms (i.e. dgi_us5) when we try to add on the nl
**	    to the NULL messages from adu_2prvalue() which do not contain
**	    the extra byte normally needed for the nl. This change fixes
**	    bug 104713.
[@history_template@]...
*/
STATUS
psf_scctrace(
	PTR	    arg1,
	i4	    msg_length,
	char        *msg_buffer)
{
    SCF_CB       scf_cb;
    DB_STATUS    scf_status;
    char	 *p;

    if (msg_length == 0)
	return 0;

    /* Truncate message if necessary */
    if (msg_length > PSF_MAX_TEXT)
	msg_length = PSF_MAX_TEXT;

    /* If last char is null, replace with NL, else add NL */
    p = (msg_buffer + msg_length - 1);
    if (*p != '\n')
    {
	if (*p == '\0')
	    *p = '\n';
	else
	{
	    *(++p) = '\n';
	    msg_length++;
	}
    }

    scf_cb.scf_length = sizeof(scf_cb);
    scf_cb.scf_type = SCF_CB_TYPE;
    scf_cb.scf_facility = DB_PSF_ID;
    scf_cb.scf_nbr_union.scf_local_error = 0; /* this is an ingres error number
					** returned to user, use 0 just in case 
					*/
    scf_cb.scf_len_union.scf_blength = (u_i4)msg_length;
    scf_cb.scf_ptr_union.scf_buffer = msg_buffer;
    scf_cb.scf_session = DB_NOSESSION;	    /* print to current session */

    scf_status = scf_call(SCC_TRACE, &scf_cb);

    if (scf_status != E_DB_OK)
    {
	TRdisplay("SCF error %d displaying a message to user\n",
	    scf_cb.scf_error.err_code);
    }
    return 0;
}
Пример #7
0
/*{
** Name: gwf_def_pool_size  - calculate GWF default memory pool size
**
** Description:
**	This function calculates the default GWF memory pool size. The default
**	size is set to
**
**	    GWF_FACMEM_DEFAULT + (num_users * GWF_SESMEM_DEFAULT)
**
**	where GWF_FACMEM_DEFAULT and GWF_SESMEM_DEFAULT are defined in
**	<gwfint.h> and stand for the default amount of memory for the facility
**	as a whole and for each particular session, respectively.
**
**	Eventually we may also add server startup parameters to allow
**	individual servers more fine-grained control over these values.
**
** Inputs:
**	None
**
** Outputs:
**	None
**
** Returns:
**	pool_size		the default pool size to use for this server
**				0 indicates that we had trouble determining
**				the number of users in this server; this is
**				probably a server-fatal condition.
**
** History:
**	3-apr-90 (bryanp)
**	    Created.
**	8-oct-92 (daveb)
**	    prototyped
**	17-aug-2004 (thaju02)
**	    For now, limit pool size to 2Gig. 
*/
static SIZE_TYPE
gwf_def_pool_size(void)
{
    DB_STATUS	status;
    SIZE_TYPE	pool_size = 0;
    i4		num_users;
    SCF_CB	scf_cb;
    SCF_SCI	sci_list[1];

    /* Get the number of users in this server. */

    scf_cb.scf_type = SCF_CB_TYPE;
    scf_cb.scf_length = sizeof(SCF_CB);
    scf_cb.scf_facility = DB_GWF_ID;
    scf_cb.scf_session = DB_NOSESSION;
    scf_cb.scf_ptr_union.scf_sci = (SCI_LIST *)sci_list;
    scf_cb.scf_len_union.scf_ilength = 1;
    sci_list[0].sci_length = sizeof(i4);
    sci_list[0].sci_code = SCI_NOUSERS;
    sci_list[0].sci_aresult = (PTR)(&num_users);
    sci_list[0].sci_rlength = NULL;

    status = scf_call(SCU_INFORMATION, &scf_cb);

    if (status != E_DB_OK)
    {
	gwf_error(scf_cb.scf_error.err_code, GWF_INTERR, 0);
	gwf_error(E_GW0302_SCU_INFORMATION_ERROR, GWF_INTERR, 0);

	pool_size = 0;	/* indicate error to caller */
    }
    else
    {
	pool_size = GWF_FACMEM_DEFAULT + (num_users * GWF_SESMEM_DEFAULT);
	if (pool_size < 0)
	{
	    TRdisplay("gwf_def_pool_size: overflow, capping to MAXI4\n");
	    pool_size = MAXI4;
	}
    }	

    return(pool_size);
}
Пример #8
0
/*
**
**  Name: gwf_scc_trace - Send a trace to the user via SCF
**
**
**  History:
**      24-sep-92 (robf)
**          Created for C2/Security Audit gateway, cloned from dmf tracing
**/
static VOID
gwf_scc_trace( char *msg_buffer)
{
    SCF_CB                 scf_cb;
    DB_STATUS              scf_status;

    scf_cb.scf_length = sizeof(scf_cb);
    scf_cb.scf_type = SCF_CB_TYPE;
    scf_cb.scf_facility = DB_GWF_ID;
    scf_cb.scf_nbr_union.scf_local_error = 0;
    scf_cb.scf_len_union.scf_blength = (u_i4)STlength(msg_buffer);
    scf_cb.scf_ptr_union.scf_buffer = msg_buffer;
    scf_cb.scf_session = DB_NOSESSION;	    /* print to current session */
    scf_status = scf_call(SCC_TRACE, &scf_cb);
    if (scf_status != E_DB_OK)
    {
	TRdisplay("SCF error %d while attempting to send info from GWF\n",
	    scf_cb.scf_error.err_code);
    }
}
Пример #9
0
/*
** gwsxa_priv_user - Checks whether current user has appropriate priv.
**
** Description:
**	This does an SCF info call to determine the REAL
**	priv status. That is, people with -u (DB_ADMIN) priv
**	can't get fake access to security tables by pretending to
**	be someone else.
**
** Returns:
**	E_DB_OK		No problem, user has privilege
**	E_DB_WARN	User does not have privilege
**	E_DB_ERROR	Something went wrong
**
** History:
**	7-jul-93 (robf)
**	    Created
**      15-sep-93 (smc)
**          Made gwsxa_scf_session pass CS_SID.
*/
DB_STATUS
gwsxa_priv_user(i4 privmask)
{
        SCF_CB      scf_cb;
        SCF_SCI     sci_list;
        DB_STATUS   status;
	i4	    ustat;

        scf_cb.scf_length = sizeof(SCF_CB);
        scf_cb.scf_type = SCF_CB_TYPE;
        scf_cb.scf_facility = DB_GWF_ID;
        scf_cb.scf_session = DB_NOSESSION;
        scf_cb.scf_len_union.scf_ilength = 1;
        /* may cause lint message */
        scf_cb.scf_ptr_union.scf_sci = (SCI_LIST*) &sci_list;
        sci_list.sci_code = SCI_USTAT;
        sci_list.sci_length = sizeof(ustat);
        sci_list.sci_aresult = (PTR) &ustat;
        sci_list.sci_rlength = NULL;
        status = scf_call(SCU_INFORMATION, &scf_cb);
        if (status != E_DB_OK)
        {
	    gwsxa_error((GWX_RCB*)NULL,E_GW4056_SXA_CANT_GET_USER_PRIVS,
			SXA_ERR_INTERNAL,0);
            return(status);
        }
	/*
	**	Now check the SECURITY bit in the status
	*/
	if ( (ustat & privmask)== privmask)
	{
		/*
		**	has all required privs
		*/
		return E_DB_OK;
	}
	else
	{
		return E_DB_WARN;
	}
}
Пример #10
0
/*{
** Name: psy_ckdbpr - Check database privileges for specific values
**
**  INTERNAL PSF call format: status = psy_ckdbpr(dbprmask)
**
** Description:
**	This procedure checks the session's database privileges mask
**	to ensure the specified privileges are allowed.
**
** Inputs:
**	psq_cb				
**	    .psq_error			error code
**	dbprmask			privileges required
**
** Outputs:
**	None.
**	Returns:
**	    E_DB_OK			the session has the required privileges.
**	    E_DB_ERROR			the session lacks one or more of the
**					required privileges.
**	    E_DB_SEVERE			scu_information() failed
**	Exceptions:
**	    none
**
** Side Effects:
**	    None.
**
** History:
**	24-may-89 (ralph)
**          written
*/
DB_STATUS
psy_ckdbpr(
	PSQ_CB		    *psq_cb,
	u_i4	    dbprmask)
{
    u_i4		dbprivs;
    SCF_CB		scf_cb;
    SCF_SCI		sci_list[1];

    /* This code is called for SQL only */

    /* Make sure user is authorized */

    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	= DB_NOSESSION;
    scf_cb.scf_ptr_union.scf_sci     = (SCI_LIST *) sci_list;
    scf_cb.scf_len_union.scf_ilength = 1;
    sci_list[0].sci_length  = sizeof(dbprivs);
    sci_list[0].sci_code    = SCI_DBPRIV;
    sci_list[0].sci_aresult = (char *) &dbprivs;
    sci_list[0].sci_rlength = NULL;

    if (scf_call(SCU_INFORMATION, &scf_cb) != E_DB_OK)
    {
	(VOID) psf_error(E_PS0D13_SCU_INFO_ERR, 0L, PSF_INTERR,
			 &scf_cb.scf_error.err_code, &psq_cb->psq_error, 0);
	return(E_DB_SEVERE);
    }
	
    if (dbprmask != (dbprmask & dbprivs))
	return(E_DB_ERROR);
    else
	return(E_DB_OK);

}
Пример #11
0
/*{
** Name: psy_group  - Dispatch group identifier qrymod routines
**
**  INTERNAL PSF call format: status = psy_group(&psy_cb, sess_cb);
**  EXTERNAL     call format: status = psy_call (PSY_GROUP,&psy_cb, sess_cb);
**
** Description:
**	This procedure checks the psy_grpflag field of the PSY_CB
**	to determine which qrymod processing routine to call:
**		PSY_CGROUP results in call to psy_cgroup()
**		PSY_AGROUP results in call to psy_agroup()
**		PSY_DGROUP results in call to psy_dgroup()
**		PSY_KGROUP results in call to psy_kgroup()
**	This procedure is called for SQL language only.
**
** Inputs:
**      psy_cb
**	    .psy_grpflag		Group identifier operation
**	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:
**	    None.
**
** History:
**	12-mar-89 (ralph)
**          written
**	20-may-89 (ralph)
**	    Allow multiple groups to be specified.
**      29-jul-89 (jennifer)
**          Added auditing of failure to perform operation.
**	30-oct-89 (ralph)
**	    Use pss_ustat for authorization check.
**	10-mar-93 (markg)
**	    Fix bug where audit of failed group operations
**	    was coded incorrectly.
**	17-jun-93 (andre)
**	    changed interface of psy_secaudit() to accept PSS_SESBLK
**	16-aug-93 (stephenb)
**	    Changed call to psy_secaudit() to audit SXF_E_SECURITY instead
**	    of SXF_E_USER, group manipulation is a security event not a 
**	    user event.
**	18-may-1993 (robf)
**	    Replaced SUPERUSER priv.
**	    Add security label to psy_secaudit() call
**	2-nov-93 (robf)
**          Enforce MAINTAIN_USERS priv to access user groups.
*/
DB_STATUS
psy_group(
	PSY_CB             *psy_cb,
	PSS_SESBLK	   *sess_cb)
{
    DB_STATUS		status = E_DB_OK;
    i4		err_code;
    char		dbname[DB_DB_MAXNAME];
    SCF_CB		scf_cb;
    SCF_SCI		sci_list[1];
    bool		leave_loop = TRUE;

    /* This code is called for SQL only */

    /* Make sure user is authorized and connected to iidbdb */

    do
    {
	if (!(sess_cb->pss_ustat & DU_UMAINTAIN_USER))
	{
	    if ( Psf_srvblk->psf_capabilities & PSF_C_C2SECURE )
	    {
		DB_ERROR	    e_error;
		i4		    access = 0;    		        
		i4         msgid;
		PSY_TBL	    *psy_tbl = (PSY_TBL *)psy_cb->psy_tblq.q_next;

		/* Audit that operation rejected. */
		if (psy_cb->psy_grpflag == PSY_CGROUP)
		{	
		    access = SXF_A_FAIL | SXF_A_CREATE;
		    msgid = I_SX2007_GROUP_CREATE;
		}
		else if (psy_cb->psy_grpflag == PSY_AGROUP)
		{
		    access = SXF_A_FAIL | SXF_A_ALTER;
		    msgid = I_SX2008_GROUP_MEM_CREATE;
		}
		else if (psy_cb->psy_grpflag == PSY_DGROUP)
		{
		    access = SXF_A_FAIL | SXF_A_ALTER;
		    msgid = I_SX200A_GROUP_MEM_DROP;
		}
		else if (psy_cb->psy_grpflag == PSY_KGROUP)
		{
		    access = SXF_A_FAIL | SXF_A_DROP;
		    msgid = I_SX2009_GROUP_DROP;
		}
		else
		{
		    err_code = E_PS0D40_INVALID_GRPID_OP;
		    status = E_DB_SEVERE;
		    (VOID) psf_error(E_PS0D40_INVALID_GRPID_OP, 0L,
			PSF_INTERR, &err_code, &psy_cb->psy_error, 0);
		    break;
		}
		
		status = psy_secaudit(FALSE, sess_cb,
		  (char *)&psy_tbl->psy_tabnm,
		  (DB_OWN_NAME *)NULL,
		   sizeof(DB_TAB_NAME), 
		   SXF_E_SECURITY,
		   msgid, access, 
		   &e_error);
	    }

            err_code = E_US18D3_6355_NOT_AUTH;
            (VOID) psf_error(E_US18D3_6355_NOT_AUTH, 0L,
                             PSF_USERERR, &err_code, &psy_cb->psy_error, 1,
                             sizeof("CREATE/ALTER/DROP GROUP")-1,
                             "CREATE/ALTER/DROP GROUP");
	    status   = E_DB_ERROR;
	    break;

	}

	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_ptr_union.scf_sci     = (SCI_LIST *) sci_list;
        scf_cb.scf_len_union.scf_ilength = 1;
        sci_list[0].sci_length  = sizeof(dbname);
        sci_list[0].sci_code    = SCI_DBNAME;
        sci_list[0].sci_aresult = (char *) dbname;
        sci_list[0].sci_rlength = NULL;

        status = scf_call(SCU_INFORMATION, &scf_cb);
        if (status != E_DB_OK)
        {
	    err_code = scf_cb.scf_error.err_code;
	    (VOID) psf_error(E_PS0D13_SCU_INFO_ERR, 0L,
			     PSF_INTERR, &err_code, &psy_cb->psy_error, 0);
	    status = (status > E_DB_SEVERE) ? status : E_DB_SEVERE;
	    break;
        }

	if (MEcmp((PTR)dbname, (PTR)DB_DBDB_NAME, sizeof(dbname)))
	{
	    /* Session not connected to iidbdb */
            err_code = E_US18D4_6356_NOT_DBDB;
            (VOID) psf_error(E_US18D4_6356_NOT_DBDB, 0L,
                             PSF_USERERR, &err_code, &psy_cb->psy_error, 1,
                             sizeof("CREATE/ALTER/DROP GROUP")-1,
                             "CREATE/ALTER/DROP GROUP");
	    status   = E_DB_ERROR;
	    break;
	    

	}

	/* leave_loop has already been set to TRUE */
    } while (!leave_loop);

    /* Select the proper routine to process this request */

    if (status == E_DB_OK)
    switch (psy_cb->psy_grpflag)
    {
	case PSY_CGROUP:
	    status = psy_cgroup(psy_cb, sess_cb);
	    break;

	case PSY_AGROUP:
	    status = psy_agroup(psy_cb, sess_cb);
	    break;

	case PSY_DGROUP:
	    status = psy_dgroup(psy_cb, sess_cb);
	    break;

	case PSY_KGROUP:
	    status = psy_kgroup(psy_cb, sess_cb);
	    break;

	default:
	    err_code = E_PS0D40_INVALID_GRPID_OP;
	    status = E_DB_SEVERE;
	    (VOID) psf_error(E_PS0D40_INVALID_GRPID_OP, 0L,
		    PSF_INTERR, &err_code, &psy_cb->psy_error, 0);
	    break;
    }

    return    (status);
} 
Пример #12
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);
} 
Пример #13
0
/*{
** Name: scd_add_datatypes	- Add new datatypes, functions, and operators
**
** Description:
**      This routine adds new datatypes, functions, and/or operators to the DBMS
**	server.  It does this by
**	    1) Getting the ADD_DEFINITION block from IIudadt_register
**	    2) Ask ADF for the amount of space required to add these new options
**	    3) Allocate that space, and
**	    4) Add the new options to the system.
**
**	Failures are logged but not returned.  The system currently ignores
**	failures in finding new objects.
**
** Inputs:
**	scb				Session control block to use.  0 if not
**					available.
**	adf_svcb			Addr of old server control block.  NOTE:
**					IT IS ASSUMED THAT THIS MEMORY IS
**					SCU_MALLOC'D MEMORY.  IT WILL BE
**					DEALLOCATED IF THE ROUTINE IS
**					SUCCESSFUL AND DEALLOCATION IS
**					INDICATED.
**	adf_size			Size of old server control block.
**	deallocate_flag			Indicates whether the old memory should
**					be deallocated.  The deallocate flag, if
**					set, contains the facility id
**					(DB_??F_ID) of the facility to which the
**					memory is and was charged (which
**					allocated it...)  See note below.
**	error				Addr of error block to fill in.
**	new_svcb			Addr**2 of new server block.  This
**					routine, if successful will place a
**					pointer to the new adf server control
**					block here.
**	new_size			Pointer to i4  to be filled with number
**					of pages used by new_svcb.  Can be zero
**					if caller is not interested.
**
** Outputs:
**	*error				Filled with error if appropos
**	*new_svcb			Filled with pointer to new adf server
**					control block.  This field is always
**					set.  If no change is necessary, then
**					this field is set to the value of
**					adf_svcb.
**	*new_size			Filled with page count if non-zero.
**
**	Returns:
**	    DB_STATUS
**	Exceptions:
**	    none
**
** Side Effects:
**	Sc_main_cb->sc_{major,minor}_adf are set to reflect the user adt major
**	and minor id's.  These are used later to check (sca_compatible())
**	whether the user defined ADT image is compatible with the remainder of
**	the running INGRES installation.
**
**	ADF is updated (assuming correctness) to run with new user defined
**	datatypes.
**
**	If so indicated (by deallocate_flag being non-zero), the old pages are
**	deallocated.
**
** History:
**      31-Jan-1989 (fred)
**          Created.
**      22-Mar-1989 (fred)
**          Added capability to scan IIDBDB for datatypes.
**      19-Apr-1989 (fred)
**	    Removed IIDBDB stuff.  All information now determined by function
**	    calls to the user.  Added support for returning major/minor id for
**	    user defined structure.
**	22-jun-89 (jrb)
**	    Added check to ensure site is licensed to add dts/ops/funcs.
**	09-oct-90 (ralph)
**	    6.3->6.5 merge:
**	    29-mar-90 (alan)
**		Don't require CI_USER_ADT authorization if RMS Gateway.
**	2-Jul-1993 (daveb)
**	    remove unused variable adf_cb.
**	2-Jul-1993 (daveb)
**	    prototyped.
**       6-Jul-1993 (fred)
**          Added more user callable functions to the callback
**          structure. 
**      26-Jul-1993 (fred)
**          Fixed up ADD_CALLBACKS initialization to be type correct.
**          Problem in mechanism for some prototypes due to differences
**          header inclusions...
**      28-aug-1993 (stevet)
**          Added support for INGRES class objects.  The adu_agument()
**          are call twice now, onec for class objects and once for
**          UDT.
**      10-nov-1993 (stevet)
**          deallocate memory the second time not working when loading class
**          library and udt together.
**	03-Nov-2010 (jonj) SIR 124685 Prototype Cleanup
**	    Prototyped, SCD_SCB *scb now void *scbp - called from DMF.
[@history_template@]...
*/
DB_STATUS
sca_add_datatypes(void *scbp,
		  PTR adf_svcb,
		  i4  adf_size,
		  i4  deallocate_flag,
		  DB_ERROR *error,
		  PTR *new_svcb,
		  i4  *new_size )
{
    SCD_SCB		*scb = (SCD_SCB*)scbp;
    ADD_DEFINITION	*add_block;
    PTR                 new_adf_block = (PTR) 0;
    PTR			old_adf_block = (PTR) 0;
    DB_STATUS		status;
    DB_STATUS		int_status;
    i4                  old_size;
    i4                  cur_size;
    i4		size;
    SCF_CB		scf_cb;
    i4			l_ustring;
    i4                  i;
    char		*ustring;
        /*
        **  This structure is made static to protect against
        **  users who keep the pointer to it.  They are told not
        **  to, but...
        */
    static  ADD_CALLBACKS   callbacks = { ADD_T_V2,
					      sca_trace,
					      adu_ome_error,
					      (ADD_LO_HANDLER *)
					     		adu_peripheral,
					      (ADD_INIT_FILTER *)
							adu_0lo_setup_workspace,
					      (ADD_LO_FILTER *) 
							adu_lo_filter};

    status = E_DB_OK;
    CLRDBERR(error);

    *new_svcb = adf_svcb;   /* Start out with no change */
    old_size = adf_size;
    old_adf_block = adf_svcb;
    Sc_main_cb->sc_major_adf = ADD_INGRES_ORIGINAL;
    /* Loop 2 time so that we are load class obj as well as udt */
    for ( i = 0; i < 2; i++)
    {
	add_block = (ADD_DEFINITION *) 0;
	if( i)
	{
	    status = IIudadt_register( &add_block, &callbacks);
	}
	else
	{
	    status = IIclsadt_register( &add_block, &callbacks); 
	}

	if (status)
	{
	    SETDBERR(error, 0, E_SC026A_SCA_REGISTER_ERROR);
	    status = E_DB_ERROR;
	    break;
	}


	if (!add_block)
	{
	    /* No new datatypes for this register, try next */
    	    continue;
	}

	if ((add_block->add_risk_consistency == ADD_INCONSISTENT) &&
    	    (Sc_main_cb->sc_capabilities & (SC_INGRES_SERVER | SC_STAR_SERVER)))
	{
	    sc0ePut(NULL, E_SC0263_SCA_RISK_CONSISTENCY, NULL, 0);
	}

	if (add_block->add_major_id <= 0)
	{
	    sc0ePut(error, E_SC0264_SCA_ILLEGAL_MAJOR, NULL, 1,
			    sizeof(add_block->add_major_id),
			    &add_block->add_major_id);
	    break;
	}
	    
	/* Now, figure out the size necessary for the new ADF block */
	
	size = adg_sz_augment(add_block, error);
	if (error->err_code)
	    break;
	
	scf_cb.scf_type = SCF_CB_TYPE;
	scf_cb.scf_length = sizeof(SCF_CB);
	scf_cb.scf_session = DB_NOSESSION;
	scf_cb.scf_facility = (deallocate_flag ? deallocate_flag : DB_SCF_ID);
	scf_cb.scf_scm.scm_functions = 0;
	scf_cb.scf_scm.scm_in_pages = ((size + SCU_MPAGESIZE - 1)
	    & ~(SCU_MPAGESIZE - 1)) / SCU_MPAGESIZE;

	status = scf_call(SCU_MALLOC, &scf_cb);

	if (status != OK)
	{
	    *error = scf_cb.scf_error;
	    break;
	}
	new_adf_block = (PTR) scf_cb.scf_scm.scm_addr;

	if (	(add_block->add_l_ustring && !add_block->add_ustring)
	   ||	(!add_block->add_l_ustring && add_block->add_ustring))
	{
	    /* This is an error -- note error in block */
	    l_ustring = STlength(ustring = "*** INVALID USER STRING or LENGTH ***");
	}
	else
	{
	    l_ustring = add_block->add_l_ustring;
	    ustring = add_block->add_ustring;
	}
    	if (Sc_main_cb->sc_capabilities & (SC_INGRES_SERVER | SC_STAR_SERVER))
	{
	    sc0ePut(NULL, E_SC0265_SCA_STATE, 0, 3,
				    sizeof(add_block->add_major_id),
				    &add_block->add_major_id,
				    sizeof(add_block->add_minor_id),
				    &add_block->add_minor_id,
				    l_ustring,
				    ustring);

	    sc0ePut(NULL, E_SC024D_SCA_ADDING, 0, 4,
		    sizeof(add_block->add_count),
			&add_block->add_count,
		    sizeof(add_block->add_dt_cnt),
			&add_block->add_dt_cnt,
		    sizeof(add_block->add_fo_cnt),
			&add_block->add_fo_cnt,
		    sizeof(add_block->add_fi_cnt),
			&add_block->add_fi_cnt);
	} /* if ... SC_INGRES_SERVER | SC_STAR_SERVER ... */

	status = adg_augment(add_block, size, new_adf_block, error);
	if (status && (error->err_code))
	    break;

	Sc_main_cb->sc_major_adf = add_block->add_major_id;
	Sc_main_cb->sc_minor_adf = add_block->add_minor_id;
	Sc_main_cb->sc_risk_inconsistency = add_block->add_risk_consistency;
	
	*new_svcb = new_adf_block;
	cur_size = scf_cb.scf_scm.scm_in_pages;
	if (new_size)
	    *new_size = scf_cb.scf_scm.scm_in_pages;

	if (old_adf_block && deallocate_flag)
	{
	    /* Remainder of control block setup above */
	
	    scf_cb.scf_scm.scm_in_pages = old_size;
	    scf_cb.scf_scm.scm_addr = old_adf_block;
	    int_status = scf_call(SCU_MFREE, &scf_cb);
	    if (int_status)
	    {
		sc0ePut(&scf_cb.scf_error, 0, NULL, 0);
		sc0ePut(&scf_cb.scf_error, E_SC024C_SCA_DEALLOCATE, NULL, 0);
	    }
	}
	old_size = cur_size;
	old_adf_block = new_adf_block;
	new_adf_block = 0;
    }

    if (status && error->err_code)
    {
	sc0ePut(error, 0, NULL, 0);
	sc0ePut(error, E_SC024E_SCA_NOT_ADDED, NULL, 0);
    }

    if (new_adf_block)
    {
	int_status = scf_call(SCU_MFREE, &scf_cb);
	if (int_status)
	{
	    sc0ePut(&scf_cb.scf_error, 0, NULL, 0);
	    sc0ePut(NULL, E_SC024C_SCA_DEALLOCATE, NULL, 0);
	}
    }

    if (status && add_block && (add_block->add_trace & ADD_T_FAIL_MASK))
    {
	sc0ePut(NULL, E_SC0266_SCA_USER_SHUTDOWN, NULL, 0);
	status = E_DB_FATAL;
    }
    else
    {
	status = E_DB_OK;
    }
    return(status);
}
Пример #14
0
/*{
** Name: psy_user - Dispatch user qrymod routines
**
**  INTERNAL PSF call format: status = psy_user(&psy_cb, sess_cb);
**  EXTERNAL     call format: status = psy_call (PSY_USER,&psy_cb, sess_cb);
**
** Description:
**	This procedure checks the psy_usflag field of the PSY_CB
**	to determine which qrymod processing routine to call:
**		PSY_CUSER results in call to psy_cuser()
**		PSY_AUSER results in call to psy_auser()
**		PSY_KUSER results in call to psy_kuser()
**
**	This procedure is called for SQL language only.
**
** Inputs:
**      psy_cb
**	    .psy_usflag			user operation
**	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:
**	    None.
**
** History:
**	04-sep-89 (ralph)
**          written
**	30-oct-89 (ralph)
**	    call qeu_audit() only if failure due to authorization check
**      11-apr-90 (jennifer)
**          bug 20746 - Fix initialization of access and msgid.
**	09-dec-1992 (pholman)
**	    C2: change obsolete qeu_audit to be psy_secaudit.
**      06-apr-1993 (smc)
**          Cast parameters to match prototypes.
**	17-jun-93 (andre)
**	    changed interface of psy_secaudit() to accept PSS_SESBLK
**	12-jul-93 (robf)
**	    check if user passwords are allowed
**	2-feb-94 (robf)
**          Don't check for passwords allowed with PROFILE statements,
**          profiles don't have passwords.
**	26-Oct-2004 (schka24)
**	    Restore security check accidently deleted with B1.
*/
DB_STATUS
psy_user(
	PSY_CB             *psy_cb,
	PSS_SESBLK	   *sess_cb)
{
    DB_STATUS		status, local_status;
    DB_ERROR		e_error;
    i4		err_code;
    char		dbname[DB_DB_MAXNAME];
    SCF_CB		scf_cb;
    SCF_SCI		sci_list[1];
    i4			access = 0;    		        
    i4		msgid;
    PSY_USR		*psy_usr = (PSY_USR *)psy_cb->psy_usrq.q_next;
    bool		sensitive = FALSE;
    bool		leave_loop = TRUE;

    /* This code is called for SQL only */

    /* Make sure session is authorized and connected to iidbdb */

    do
    {
	/* Ensure we're authorized to issue CREATE/ALTER/DROP USER */

	if (((psy_cb->psy_usflag & ~(PSY_AUSER | PSY_USRPASS | PSY_USROLDPASS))
	    ||
	    (!(psy_cb->psy_usflag & PSY_USRPASS))
	    ||
	    (psy_cb->psy_usflag & (PSY_USREXPDATE|PSY_USRDEFPRIV))
	    ||
	    (STskipblank
	     ((char *)&psy_cb->psy_apass,sizeof(psy_cb->psy_apass)) == NULL)
	   ) &&  (!(sess_cb->pss_ustat & DU_UMAINTAIN_USER)))
	    sensitive = TRUE;

	/* Now ALTER_AUDIT clauses - SECURITY_AUDIT */
	if((psy_cb->psy_usflag & PSY_USRSECAUDIT) &&
	  !(sess_cb->pss_ustat & DU_UALTER_AUDIT))
	    sensitive = TRUE;

	/* Alter priv with SECURITY, and don't have SECURITY, is sensitive */
	if ( (psy_cb->psy_usflag & (PSY_USRPRIVS|PSY_USRAPRIVS|PSY_USRDPRIVS))
	  && (psy_cb->psy_usprivs & DU_USECURITY)
	  && ! (sess_cb->pss_ustat & DU_USECURITY) )
	    sensitive = TRUE;

	if(((psy_cb->psy_usflag & (PSY_APROFILE|PSY_DPROFILE|PSY_CPROFILE)))
		&& !(sess_cb->pss_ustat & DU_UMAINTAIN_USER))
	{
	    /*
	    ** Creating profiles  is a privileged operation
	    */
	    sensitive=TRUE;
	}
	if (sensitive)
	{
	    /* User is not authorized to perform the requested function */
	    if ( Psf_srvblk->psf_capabilities & PSF_C_C2SECURE )
	    {
		if ((psy_cb->psy_usflag & (PSY_CUSER | PSY_AUSER | PSY_KUSER))
					== PSY_CUSER)
		{	
		    access = SXF_A_FAIL | SXF_A_CREATE;
		    msgid = I_SX200C_USER_CREATE;
		}
		else if ((psy_cb->psy_usflag & (PSY_CUSER | PSY_AUSER | PSY_KUSER))
					== PSY_AUSER)
		{
		    access = SXF_A_FAIL | SXF_A_ALTER;
		    msgid = I_SX2023_USER_ALTER;
		}
		else if ((psy_cb->psy_usflag & (PSY_CUSER | PSY_AUSER | PSY_KUSER))
					== PSY_KUSER)
		{
		    access = SXF_A_FAIL | SXF_A_DROP;
		    msgid = I_SX200D_USER_DROP;
		}
		else if ((psy_cb->psy_usflag & (PSY_CPROFILE | PSY_APROFILE | PSY_DPROFILE))
					== PSY_CPROFILE)
		{	
		    access = SXF_A_FAIL | SXF_A_CREATE;
		    msgid =  I_SX272E_CREATE_PROFILE;
		}
		else if ((psy_cb->psy_usflag & (PSY_CPROFILE | PSY_APROFILE | PSY_DPROFILE))
					== PSY_APROFILE)
		{
		    access = SXF_A_FAIL | SXF_A_ALTER;
		    msgid = I_SX272F_ALTER_PROFILE;
		}
		else if ((psy_cb->psy_usflag & (PSY_CPROFILE | PSY_APROFILE | PSY_DPROFILE))
					== PSY_DPROFILE)
		{
		    access = SXF_A_FAIL | SXF_A_DROP;
		    msgid =  I_SX2730_DROP_PROFILE;
		}

		local_status = psy_secaudit(FALSE, sess_cb,
			    (char *)&psy_usr->psy_usrnm,
			    (DB_OWN_NAME *)NULL,
			    sizeof(DB_OWN_NAME), SXF_E_SECURITY,
			    msgid, access,
			    &e_error);
	    }

	    if (psy_cb->psy_usflag & PSY_AUSER)
	    {
		err_code = E_US18D5_6357_FORM_NOT_AUTH;
		(VOID) psf_error(E_US18D5_6357_FORM_NOT_AUTH, 0L,
			     PSF_USERERR, &err_code, &psy_cb->psy_error, 1,
			     sizeof("ALTER USER/PROFILE")-1,
			     "ALTER USER/PROFILE");
	    }
	    else
	    {
		err_code = E_US18D3_6355_NOT_AUTH;
		(VOID) psf_error(E_US18D3_6355_NOT_AUTH, 0L,
			     PSF_USERERR, &err_code, &psy_cb->psy_error, 1,
			     sizeof("CREATE/DROP USER/PROFILE")-1,
			     "CREATE/DROP USER/PROFILE");
	    }
	    status   = E_DB_ERROR;
	    break;

	}

	/* Ensure we're connected to the iidbdb database */

	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_ptr_union.scf_sci     = (SCI_LIST *) sci_list;
	scf_cb.scf_len_union.scf_ilength = 1;
	sci_list[0].sci_code    = SCI_DBNAME;
	sci_list[0].sci_length  = sizeof(dbname);
	sci_list[0].sci_aresult = (char *) dbname;
	sci_list[0].sci_rlength = NULL;

	status = scf_call(SCU_INFORMATION, &scf_cb);
	if (status != E_DB_OK)
	{
	    err_code = scf_cb.scf_error.err_code;
	    (VOID) psf_error(E_PS0D13_SCU_INFO_ERR, 0L,
			 PSF_INTERR, &err_code, &psy_cb->psy_error, 0);
	    status = (status > E_DB_SEVERE) ? status : E_DB_SEVERE;
	    return(status);
	}

	if (MEcmp((PTR)dbname, (PTR)DB_DBDB_NAME, sizeof(dbname)))
	{
	    /* Session not connected to iidbdb */
	    err_code = E_US18D4_6356_NOT_DBDB;
	    (VOID) psf_error(E_US18D4_6356_NOT_DBDB, 0L,
			     PSF_USERERR, &err_code, &psy_cb->psy_error, 1,
			     sizeof("CREATE/ALTER/DROP USER/PROFILE")-1,
			     "CREATE/ALTER/DROP USER/PROFILE");
	    status   = E_DB_ERROR;
	    break;
	}

	/*
	** Check if passwords are allowed.
	*/
	if((sess_cb->pss_ses_flag & PSS_PASSWORD_NONE)
	   && !(psy_cb->psy_usflag & (
			PSY_KUSER|
			PSY_DPROFILE|PSY_APROFILE|PSY_CPROFILE))
    	   && STskipblank((char *)&psy_cb->psy_apass,
                           (i4)sizeof(psy_cb->psy_apass)) != NULL)
	{
	    err_code=E_US18E7_6375;
            (VOID) psf_error(E_US18E7_6375, 0L,
                             PSF_USERERR, &err_code, &psy_cb->psy_error, 1,
                             sizeof("CREATE/ALTER USER WITH PASSWORD")-1,
                             "CREATE/ALTER USER WITH PASSWORD");
	    status   = E_DB_ERROR;
	    break;
	}
	break;
	/* leave_loop has already been set to TRUE */
    } while (!leave_loop);

    /* Select the proper routine to process this request */

    if (status == E_DB_OK)
    switch (psy_cb->psy_usflag & (PSY_CUSER | PSY_AUSER | PSY_KUSER|
	    		PSY_CPROFILE | PSY_APROFILE | PSY_DPROFILE))
    {
	case PSY_CUSER:
	    status = psy_cuser(psy_cb, sess_cb);
	    break;

	case PSY_AUSER:
	    status = psy_auser(psy_cb, sess_cb);
	    break;

	case PSY_KUSER:
	    status = psy_kuser(psy_cb, sess_cb);
	    break;

	case PSY_CPROFILE:
	    status = psy_cprofile(psy_cb, sess_cb);
	    break;

	case PSY_APROFILE:
	    status = psy_aprofile(psy_cb, sess_cb);
	    break;

	case PSY_DPROFILE:
	    status = psy_kprofile(psy_cb, sess_cb);
	    break;

	default:
	    status = E_DB_SEVERE;
	    err_code = E_PS0D46_INVALID_USER_OP;
	    (VOID) psf_error(E_PS0D46_INVALID_USER_OP, 0L,
		    PSF_INTERR, &err_code, &psy_cb->psy_error, 0);
	    break;
    }

    return    (status);
}
Пример #15
0
/*{
** Name: gwf_term - terminate the gateway facility
**
** Description:
**	This function performs gateway facility termination.  Facility global
**	structures are deallocated, and all active gateway servers are shut
**	down.
**
** Inputs:
**	gw_rcb->		Standard GWF control block
**	    error		error structure for error status
**
** Output:
**	gw_rcb->		Standard GWF control block
**	    error.
**		err_code
**				E_GW0007_GWX_VTERM_ERROR
**
**      Returns:
**          E_DB_OK             Function completed normally. 
**          E_DB_ERROR          Function completed abnormally with 
**                              error.err_code.
** History:
**      21-Apr-1989 (alexh)
**          Created.
**	27-dec-89 (paul)
**	    Added support for calling termination entry with an RCB.  This will
**	    allow termination arguments if needed for future GW's.
**	26-mar-90 (linda)
**	    Added error handling.
**	9-apr-90 (bryanp)
**	    Updated error handling to new GWF scheme.  Changed to take gw_rcb
**	    structure.
**	19-apr-90 (bryanp)
**	    Fix server shutdown bug involving bad arguments to SCU_MFREE.
**	    Fix server shutdown bug involving endless loop deleting TCB's
**	7-oct-92 (daveb)
**	    prototyped.  removed dead variable err.
**      21-sep-92 (schang)
**          free individual gateway specific  server wide memory before
**          server shutdown
*/
DB_STATUS
gwf_term( GW_RCB *gw_rcb )
{
    DB_STATUS	status;
    bool	badstat = FALSE;
    i4		i;
    SCF_CB	scf_cb;
    GWX_RCB	gwx_rcb;
    
    status = E_DB_OK;
    
    /* terminate each initiated gateway by calling its termination entry. */
    for (i=0; i < GW_GW_COUNT; ++i)
    {
	if (Gwf_facility->gwf_gw_info[i].gwf_gw_exist)
	{
            /* schang : terminates individual gateway specific memory */
            gwx_rcb.xrcb_xhandle = Gwf_facility->gwf_gw_info[i].gwf_xhandle;
	    status =
	      (*Gwf_facility->gwf_gw_info[i].gwf_gw_exits[GWX_VTERM])(&gwx_rcb);
	    if (status != E_DB_OK)
	    {
		/* On error report, log and continue shutting down gateways */
		gwf_error(gwx_rcb.xrcb_error.err_code, GWF_INTERR, 0);
		gwf_error(E_GW0201_GWF_TERM_ERROR, GWF_INTERR, 1,
			  sizeof(i), &i);
		badstat = TRUE;
		continue;
	    }
	}
    }

#if 0
    /*
    ** Never mind, we will use a special routine (later) to do this.  For now
    ** the gwu_deltcb() routine needs to get a gw_rcb struct, so that it can
    ** tell whether the database id's match as well as table id's.  Obviously
    ** we don't have a gw_rcb here...and we want to delete for all databases.
    */
    /* free all tcb's */
    while (Gwf_facility->gwf_tcb_list)
    {
	status = gwu_deltcb(&Gwf_facility->gwf_tcb_list->gwt_table.tbl_id,
			    GWU_TCB_MANDATORY, &err);
	if (status != E_DB_OK)
	{
	    gwf_error(err.err_code, GWF_INTERR, 0);
	    badstat = TRUE;
	    break;
	}
    }
#endif

    /* get rid of the memory pool */
    if ((status = ulm_shutdown(&Gwf_facility->gwf_ulm_rcb)) != E_DB_OK)
    {
	gwf_error(Gwf_facility->gwf_ulm_rcb.ulm_error.err_code, GWF_INTERR, 0);
	gwf_error(E_GW0311_ULM_SHUTDOWN_ERROR, GWF_INTERR, 0);
	badstat = TRUE;
    }
    
    /* deallocate Gwf_facility memory */
    scf_cb.scf_type = SCF_CB_TYPE;
    scf_cb.scf_length = sizeof(SCF_CB);
    scf_cb.scf_session = DB_NOSESSION;
    scf_cb.scf_facility = DB_GWF_ID;
    scf_cb.scf_scm.scm_in_pages = (sizeof(GW_FACILITY)/SCU_MPAGESIZE+1);
    scf_cb.scf_scm.scm_addr = (char *)Gwf_facility;
    status = scf_call(SCU_MFREE, &scf_cb);
    if (status != E_DB_OK)
    {
	gwf_error(scf_cb.scf_error.err_code, GWF_INTERR, 0);
	gwf_error(E_GW0301_SCU_MFREE_ERROR, GWF_INTERR, 0);
	badstat = TRUE;
    }

    Gwf_facility = NULL;

    if (badstat == TRUE)
    {
	status = E_DB_ERROR;
	gw_rcb->gwr_error.err_code = E_GW0201_GWF_TERM_ERROR;
    }

    return(status);
}
Пример #16
0
/*{
** Name: gwf_init - initialize the gateway facility
**
** Description:
**	This function performs general gateway initialization.  Facility global
**	structures are allocated and initialized.
**
**	A ULM memory stream is set up for GWF for allocating the various GWF
**	data structures.
**
**	Gateway initialization exits are called to initialize the gateway.  The
**	identity of the initialization exits are obtained from Gwf_itab.
**
** Inputs:
**	gw_rcb->		Standard GWF control block
**	    gwr_dmf_cptr	The address of function "dmf_call()", so that
**				we can call back to DMF for, e.g., extended
**				catalog access.
**
** Output:
**	gw_rcb->		Standard GWF control block
**	    gwr_out_vdata1	Release id of Gateway.
**	    gwr_scfcb_size	size of CB for SCF to allocate per session.
**	    gwr_server		set to the GwF_facility, for SCF to know.
**	error->
**          err_code		One of the following error numbers.
**				E_GW0200_GWF_INIT_ERROR
**				E_GW0600_NO_MEM
**
**      Returns:
**          E_DB_OK             Function completed normally. 
**          E_DB_ERROR          Cannot allocate Gwf_facility.
**	    E_DB_WARN		Success, informational status sent back to DMF
**				in the error.err_code field (either that there
**				is no gateway initialized, or that none of the
**				gateways needs transaction notification).
**
** History:
**      21-Apr-1989 (alexh)
**          Created.
**	14-Dec-1989 (linda)
**	    Extended catalog table names were being filled in incorrectly; see
**	    comments below.
**	23-dec-89 (paul)
**	    Changed memory allocation strategy for the gateway.  See comments
**	    embedded in code.
**	26-mar-90 (linda)
**	    Changed error handling.  Changed to have one return point.
**	5-apr-90 (bryanp)
**	    Added improved calculation of GWF memory pool. Pool size is now
**	    scaled by number of users.
**	9-apr-90 (bryanp)
**	    This function is now called via gwf_call(), and takes a gw_rcb.
**	18-apr-90 (bryanp)
**	    If SCF says not enough memory, return proper error code.
**	27-sep-90 (linda)
**	    Set up pointer to tidp tuple for extended attribute tables, in
**	    support of gateway secondary indexes.
**	5-dec-90 (linda)
**	    Initialize the tcb semaphore.  We were using it for locking the tcb
**	    list -- but it hadn't been initialized so locking was not working.
**	4-nov-91 (rickh)
**	    Return release identifier string at server initialization time.
**	    SCF spits up this string when poked with
**	    "select dbmsinfo( '_version' )"
**	7-oct-92 (daveb)
**	    fill in gwr_scfcb_size and gwr_server at init time so SCF
**	    can treat us as a first class citizen and make the session
**	    init calls.  Prototyped.
**	23-Oct-1992 (daveb)
**	    name semaphore.
**      21-sep-92 (schang)
**          initialize individual gateway specific server wide memory pointer
**	05-mar-97 (toumi01)
**	    initialize the global trace flags array
**      24-jul-97 (stial01)
**          gwf_init() Set gwx_rcb.xrcb_gchdr_size before calling gateway init.
*/
DB_STATUS
gwf_init( GW_RCB *gw_rcb )
{
    i4		i;
    SCF_CB	scf_cb;
    DB_STATUS	status;
    STATUS	cl_status;

    /* zero out the release id descriptor */

    MEfill(sizeof( DM_DATA ), 0, (PTR)&gw_rcb->gwr_out_vdata1 );

    for (;;)	/*  Something to break out of...    */
    {
	/* allocate Gwf_facility */
	scf_cb.scf_type = SCF_CB_TYPE;
	scf_cb.scf_length = sizeof(SCF_CB);
	scf_cb.scf_session = DB_NOSESSION;
	scf_cb.scf_facility = DB_GWF_ID;
	scf_cb.scf_scm.scm_functions = 0;
	scf_cb.scf_scm.scm_in_pages = (sizeof(GW_FACILITY)/SCU_MPAGESIZE+1);
	if ((status = scf_call(SCU_MALLOC, &scf_cb)) != E_DB_OK)
	{
	    gwf_error(scf_cb.scf_error.err_code, GWF_INTERR, 0);
	    gwf_error(E_GW0300_SCU_MALLOC_ERROR, GWF_INTERR, 1,
		      sizeof(scf_cb.scf_scm.scm_in_pages),
		      &scf_cb.scf_scm.scm_in_pages);

	    switch (scf_cb.scf_error.err_code)
	    {
		case E_SC0004_NO_MORE_MEMORY:
		case E_SC0005_LESS_THAN_REQUESTED:
		case E_SC0107_BAD_SIZE_EXPAND:
		    gw_rcb->gwr_error.err_code = E_GW0600_NO_MEM;
		    break;

		default:
		    gw_rcb->gwr_error.err_code = E_GW0200_GWF_INIT_ERROR;
		    break;
	    }
	    break;
	}
	Gwf_facility = (GW_FACILITY *)scf_cb.scf_scm.scm_addr;
	Gwf_facility->gwf_tcb_list = NULL;
	cl_status = CSw_semaphore(&Gwf_facility->gwf_tcb_lock, CS_SEM_SINGLE,
					"GWF TCB sem" );
	if (cl_status != OK)
	{
	    gwf_error(cl_status, GWF_INTERR, 0);
	    gw_rcb->gwr_error.err_code = E_GW0200_GWF_INIT_ERROR;
	    status = E_DB_ERROR;
	    break;
	}

	/*
	** Initialize memory allocation scheme for GWF. We have the following
	** memory allocation scheme.
	**
	**	1. TCB
	**		Allocated directly by SCF. Allocation and deallocation
	**		is controlled directly by GWF. It loks like TCB's are
	**		held until they are no longer valid (due to a DROP or
	**		REGISTER INDEX) or until the server shuts down. It's
	**		not clear this is the best allocation strategy.
	**
	**	2. SCB
	**		The session control block is allocated within its own
	**		ULM memory stream. Since there is no other information
	**		that lives for the entire session, this is the only
	**		information handled by this memory stream. The stream
	**		id is stored in the SCB.
	**
	**	3. RSB
	**		The record control blocks containing information for a
	**		particular access to a gateway table are allocated from
	**		a separate stream initialized at the time the table is
	**		"opened" for access and deleted at the time the table
	**		is "closed".  The stream id is stored in the RSB.
	**
	**	4. Temporary Memory
	**		Memory needed for a single operation such as
	**		registering a table is allocated from a ULF memory
	**		stream. Such srteams must be opened and closed within a
	**		single invocation of the GWF.
	**
	** At this time we initialize the pool from which ULM streams will be
	** allocated.
	*/
	Gwf_facility->gwf_ulm_rcb.ulm_facility = DB_GWF_ID;
	Gwf_facility->gwf_ulm_rcb.ulm_blocksize = SCU_MPAGESIZE;
	Gwf_facility->gwf_ulm_rcb.ulm_sizepool = gwf_def_pool_size();
	status = ulm_startup(&Gwf_facility->gwf_ulm_rcb);
	if (status != E_DB_OK)
	{
	    gwf_error(Gwf_facility->gwf_ulm_rcb.ulm_error.err_code,
		      GWF_INTERR, 0);
	    gwf_error(E_GW0310_ULM_STARTUP_ERROR, GWF_INTERR, 1,
		      sizeof(Gwf_facility->gwf_ulm_rcb.ulm_sizepool),
		      &Gwf_facility->gwf_ulm_rcb.ulm_sizepool);
	    if (Gwf_facility->gwf_ulm_rcb.ulm_error.err_code == E_UL0005_NOMEM)
		gw_rcb->gwr_error.err_code = E_GW0600_NO_MEM;
	    else
		gw_rcb->gwr_error.err_code = E_GW0200_GWF_INIT_ERROR;
	    break;
	}

	Gwf_facility->gwf_gw_active = 0;    /* assume no gateways. */
	Gwf_facility->gwf_gw_xacts  = 0;    /* and no transaction handling */

	/* initialize the global trace flags array */
	MEfill(sizeof(Gwf_facility->gwf_trace), 0,
	    (PTR)Gwf_facility->gwf_trace);

	/* initialize each gateway's exit vector */
	for (i=0; i < GW_GW_COUNT; ++i)
	{
	    GWX_RCB	gwx_rcb;

	    gwx_rcb.xrcb_gwf_version = GWX_VERSION;
	    gwx_rcb.xrcb_exit_table =
		(GWX_VECTOR *)&Gwf_facility->gwf_gw_info[i].gwf_gw_exits[0];
	    gwx_rcb.xrcb_dmf_cptr = gw_rcb->gwr_dmf_cptr;
	    gwx_rcb.xrcb_gca_cb = gw_rcb->gwr_gca_cb;

            /*
            ** schang: init new field xrcb_xhandle, this field passes
            ** individual gateway specific, server wide memory
            ** pointer (sep-21-1992)
            ** initialize xrcb_xbitset (aug-12-93)
            */
            gwx_rcb.xrcb_xhandle = NULL;
            gwx_rcb.xrcb_xbitset = 0;

	    MEfill(sizeof( DM_DATA ), 0, (PTR)&gwx_rcb.xrcb_var_data1 );

	    /* refer to Gwf_itab to decide which initializations are required */
	    if (Gwf_itab[i] == NULL)
	    {
		Gwf_facility->gwf_gw_info[i].gwf_gw_exist = 0;
	    }
	    else if ((status = (*Gwf_itab[i])(&gwx_rcb)) == E_DB_OK)
	    {
               /* schang : new memory pointer initialized */
                Gwf_facility->gwf_gw_info[i].gwf_xhandle =
                                    gwx_rcb.xrcb_xhandle;
                Gwf_facility->gwf_gw_info[i].gwf_xbitset =
                                    gwx_rcb.xrcb_xbitset;
		Gwf_facility->gwf_gw_info[i].gwf_rsb_sz =
				    gwx_rcb.xrcb_exit_cb_size;
		Gwf_facility->gwf_gw_info[i].gwf_xrel_sz =
				    gwx_rcb.xrcb_xrelation_sz;
		Gwf_facility->gwf_gw_info[i].gwf_xatt_sz =
				    gwx_rcb.xrcb_xattribute_sz;
		Gwf_facility->gwf_gw_info[i].gwf_xidx_sz =
				    gwx_rcb.xrcb_xindex_sz;
		Gwf_facility->gwf_gw_info[i].gwf_gw_exist = 1;
		/* initialize extended catalog names */
		STprintf((char *)&Gwf_facility->gwf_gw_info[i].gwf_xrel_tab_name,
			"iigw%02d_relation", i);
		STprintf((char *)&Gwf_facility->gwf_gw_info[i].gwf_xatt_tab_name,
			"iigw%02d_attribute", i);
		STprintf((char *)&Gwf_facility->gwf_gw_info[i].gwf_xidx_tab_name,
			"iigw%02d_index", i);

		/* pass the release identifier up to SCF */

		if ( gwx_rcb.xrcb_var_data1.data_address != 0 )
		{
		    MEcopy( (PTR)&gwx_rcb.xrcb_var_data1, sizeof( DM_DATA ),
			(PTR)&gw_rcb->gwr_out_vdata1 );
		}

		/*
		** Now set up pointer to tidp tuple for this gateway's extended
		** attribute catalog, to support gateway secondary indexes.
		*/
		Gwf_facility->gwf_gw_info[i].gwf_xatt_tidp =
					    gwx_rcb.xrcb_xatt_tidp;
		/*
		** Note, if >1 gateway is initialized, then if any gateway needs
		** transaction notification, DMF will always notify.  Also note,
		** we check error.err_code here even though status is E_DB_OK.
		** Not great, but I can't think of a better way...
		*/
		if (gwx_rcb.xrcb_error.err_code == E_GW0500_GW_TRANSACTIONS)
		    Gwf_facility->gwf_gw_xacts = 1;

		Gwf_facility->gwf_gw_active = 1;
	    }
	    else	/* status != E_DB_OK */
	    {
		gwf_error(gwx_rcb.xrcb_error.err_code, GWF_INTERR, 0);
		gw_rcb->gwr_error.err_code = E_GW0200_GWF_INIT_ERROR;
		break;
	    }
	}

	gw_rcb->gwr_scfcb_size = sizeof(GW_SESSION);
	gw_rcb->gwr_server = (PTR)Gwf_facility;

	if (status != E_DB_OK)
	    break;		/* gateway exit failed */

	/*
	** Now that we're ready to go, assign global Dmf_cptr its value (== the
	** address of function dmf_call()).  We need to do this to remove
	** explicit  calls to the DMF facility, resolving circular references of
	** shareable libraries when building.
	*/
	Dmf_cptr = gw_rcb->gwr_dmf_cptr;

	break;
    }

    if (status != E_DB_OK)
    {
	return(status);
    }
    else
    {
	gw_rcb->gwr_error.err_code = E_DB_OK;
	return(E_DB_OK);
    }
}
Пример #17
0
/*{
** Name: psy_alarm - Dispatch security alarm qrymod routines
**
**  INTERNAL PSF call format: status = psy_alarm(&psy_cb, sess_cb);
**  EXTERNAL     call format: status = psy_call (PSY_ALARM, &psy_cb, sess_cb);
**
** Description:
**	This procedure checks the psy_alflag field of the PSY_CB
**	to determine which qrymod processing routine to call:
**		PSY_CALARM results in call to psy_calarm()
**		PSY_KALARM results in call to psy_kalarm()
**
**	This procedure is called for SQL language only.
**
** Inputs:
**      psy_cb
**	    .psy_alflag			location operation
**	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:
**	    None.
**
** History:
**	21-sep-89 (ralph)
**          written
**	29-nov-93 (robf)
**          Now really call psy_calarm/psy_kalarm()
*/
DB_STATUS
psy_alarm(
	PSY_CB             *psy_cb,
	PSS_SESBLK	   *sess_cb)
{
    DB_STATUS		status=E_DB_OK;
    i4		err_code;
    i4			user_status;
    char		dbname[DB_DB_MAXNAME];
    SCF_CB		scf_cb;
    SCF_SCI		sci_list[2];
    bool		loop=FALSE;
    DB_SECALARM		*alarm= &psy_cb->psy_tuple.psy_alarm;
    DB_STATUS		local_status;
    DB_ERROR		e_error;

    /* This code is called for SQL only */
    /* 
    ** Ensure we're connected to the iidbdb database for database/installation
    ** alarms, and have SECURITY privilege
    */

    if(alarm->dba_objtype==DBOB_DATABASE) 
    do
    {
	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_ptr_union.scf_sci     = (SCI_LIST *) sci_list;
	scf_cb.scf_len_union.scf_ilength = 1;
	sci_list[0].sci_code    = SCI_DBNAME;
	sci_list[0].sci_length  = sizeof(dbname);
	sci_list[0].sci_aresult = (char *) dbname;
	sci_list[0].sci_rlength = NULL;

	status = scf_call(SCU_INFORMATION, &scf_cb);
	if (status != E_DB_OK)
	{
	    err_code = scf_cb.scf_error.err_code;
	    (VOID) psf_error(E_PS0D13_SCU_INFO_ERR, 0L,
			 PSF_INTERR, &err_code, &psy_cb->psy_error, 0);
	    status = (status > E_DB_SEVERE) ? status : E_DB_SEVERE;
	    return(status);
	}
	if (MEcmp((PTR)dbname, (PTR)DB_DBDB_NAME, sizeof(dbname)))
	{
	    /* Session not connected to iidbdb */
	    err_code = E_US18D4_6356_NOT_DBDB;
	    (VOID) psf_error(E_US18D4_6356_NOT_DBDB, 0L,
			     PSF_USERERR, &err_code, &psy_cb->psy_error, 1,
			     sizeof("CREATE/DROP SECURITY_ALARM ON DATABASE")-1,
			     "CREATE/DROP SECURITY_ALARM ON DATABASE");
	    status=E_DB_ERROR;
	    break;
	}
	if( !(sess_cb->pss_ustat & DU_USECURITY))
	{
		err_code = E_US18D5_6357_FORM_NOT_AUTH;
		(VOID) psf_error(E_US18D5_6357_FORM_NOT_AUTH, 0L,
			 PSF_USERERR, &err_code, &psy_cb->psy_error, 1,
			 sizeof("CREATE/DROP SECURITY_ALARM")-1,
			 "CREATE/DROP SECURITY_ALARM");
		status=E_DB_ERROR;
		break;
	}
    } while(loop);

    if (status!=E_DB_OK)
    {
	/*
	** Audit failure
	*/
	if ( Psf_srvblk->psf_capabilities & PSF_C_C2SECURE )
	{
	    SXF_EVENT evtype;
	    i4   msgid;

	    if(alarm->dba_objtype==DBOB_DATABASE) 
		    evtype=SXF_E_DATABASE;
	    else
		    evtype=SXF_E_TABLE;

	    if(psy_cb->psy_alflag&PSY_CALARM)
		    msgid=I_SX202D_ALARM_CREATE;
	    else
		    msgid=I_SX202E_ALARM_DROP;

	    local_status = psy_secaudit(FALSE, sess_cb,
			    (char *)&alarm->dba_objname,
			    (DB_OWN_NAME *)NULL,
			    sizeof(alarm->dba_objname),
			    evtype,
			    msgid,
			    SXF_A_CONTROL|SXF_A_FAIL,
			    &e_error);
	}

       if(psy_cb->psy_alflag&PSY_CALARM)
       {
	    /*
	    ** Destroy query text for CREATE SECURITY_ALARM before
	    ** returning
	    */
	    DB_STATUS loc_status;
	    QSF_RCB	qsf_rb;

	    qsf_rb.qsf_lk_state	= QSO_EXLOCK;
	    qsf_rb.qsf_type	= QSFRB_CB;
	    qsf_rb.qsf_ascii_id	= QSFRB_ASCII_ID;
	    qsf_rb.qsf_length	= sizeof(qsf_rb);
	    qsf_rb.qsf_owner	= (PTR)DB_PSF_ID;
	    qsf_rb.qsf_sid	= sess_cb->pss_sessid;

	    /* Destroy query text - lock it first */
	    STRUCT_ASSIGN_MACRO(psy_cb->psy_qrytext, qsf_rb.qsf_obj_id);
	    loc_status = qsf_call(QSO_LOCK, &qsf_rb);
	    if (loc_status != E_DB_OK)
	    {
		psf_error(E_PS0D18_QSF_LOCK, qsf_rb.qsf_error.err_code,
		  PSF_INTERR, &err_code, &psy_cb->psy_error, 0);
		if (loc_status > status)
		    status = loc_status;
	    }
	    loc_status = qsf_call(QSO_DESTROY, &qsf_rb);
	    if (loc_status != E_DB_OK)
	    {
		psf_error(E_PS0D1A_QSF_DESTROY, qsf_rb.qsf_error.err_code,
		  PSF_INTERR, &err_code, &psy_cb->psy_error, 0);
		if (loc_status > status)
		    status = loc_status;
	    }
	}
	return status;
    }

    /* Select the proper routine to process this request */

    switch (psy_cb->psy_alflag & (PSY_CALARM | PSY_KALARM))
    {
	case PSY_CALARM:
	    status = psy_calarm(psy_cb, sess_cb);
	    break;

	case PSY_KALARM:
	    status = psy_kalarm(psy_cb, sess_cb);
	    break;

	default:
	    status = E_DB_SEVERE;
	    err_code = E_PS0D49_INVALID_ALARM_OP;
	    (VOID) psf_error(E_PS0D49_INVALID_ALARM_OP, 0L,
		    PSF_INTERR, &err_code, &psy_cb->psy_error, 0);
	    break;
    }

    return    (status);
}
Пример #18
0
DB_STATUS
uleFormatFcn(
DB_ERROR    *dberror,
i4	    err_code,
CL_ERR_DESC *clerror,
i4	    flag,
DB_SQLSTATE *sqlstate,
char	    *msg_buffer,  
i4	    msg_buf_length,
i4	    *msg_length,
i4          *uleError,
PTR	    uleFileName,
i4	    uleLineNumber,
i4	    num_parms,
	    ... )
{

#define  NUM_ER_ARGS 12

    struct  {
		ULE_MHDR	hdr;
/*  FIX ME should message size be ER_MAX_LEN - sizeof(ULE_MHDR) */
		char		message[ER_MAX_LEN];
	    }	    buffer;
    i4		    i;
    i4	    	    length = 0;
    i4		    text_length;
    i4	    	    status;
    CL_ERR_DESC	    sys_err;
    i4              language;
    SCF_SESSION	    sid;
    SCF_SCI	    info[10];
    SCF_CB	    scf_cb;
    ER_ARGUMENT     er_args[NUM_ER_ARGS];
    char	    hex_chars[16] = {'0','1','2','3','4','5','6','7',
                                     '8','9','a','b','c','d','e','f'};
    i4		    error_code;
    i4	    	    local_error_code;
    DB_ERROR	    localDBerror, *DBerror;
    PTR		    FileName;
    i4		    LineNumber;
    char	    *qbuf = NULL;
    char	    *prev_qbuf = NULL;
    char	    *psqbuf = NULL;
    i4		    qlen = 0;
    i4		    prev_qlen = 0;
    i4		    psqlen = 0;
    i4		    trace_errno = 0;
    i4		    trace_stack = 0;
    i4		    prlen;
    char	    *prbuf;
    i2		    hdr_size;
    i4		    NumParms;
    va_list	    ap;

    LOCATION	    loc;
    char	    dev[LO_NM_LEN];
    char	    fprefix[LO_NM_LEN];
    char	    fsuffix[LO_NM_LEN];
    char	    version[LO_NM_LEN];
    char	    path[MAX_LOC + 1];
    char	    filebuf[MAX_LOC + 1];
    char	    LineNo[LO_NM_LEN];
    char	    *MessageArea = (char*)&buffer.message;
    char	    SourceInfo[LO_NM_LEN];
    i4		    PrefixLen = sizeof(ULE_MHDR);

    if (Ule_started == 0)
    {
	MEfill(sizeof(ULE_MHDR), (u_char)' ', (PTR)&Ule_mhdr);
	Ule_started = -1;
    }

    /*
    ** If old form (no dberror) or overriding err_code,
    ** use caller's err_code, File, and Line information,
    ** otherwise use what's in "dberror".
    */
    if ( !dberror || err_code )
    {
        DBerror = &localDBerror;
	DBerror->err_file = uleFileName;
	DBerror->err_line = uleLineNumber;
	DBerror->err_code = err_code;
	DBerror->err_data = 0;

	/* Fill caller's dberror with that used */
	if ( dberror )
	    *dberror = *DBerror;
    }
    else
        DBerror = dberror;

    error_code = local_error_code = DBerror->err_code;

    MessageArea = (char*)&buffer.message;


    info[0].sci_code = SCI_SID;
    info[0].sci_length = sizeof(sid);
    info[0].sci_aresult = (char *) &sid;
    info[0].sci_rlength = 0;
    info[1].sci_code = SCI_LANGUAGE;
    info[1].sci_length = sizeof(language);
    info[1].sci_aresult = (char *) &language;
    info[1].sci_rlength = 0;
    scf_cb.scf_length = sizeof(SCF_CB);
    scf_cb.scf_type = SCF_CB_TYPE;
    scf_cb.scf_ascii_id = SCF_ASCII_ID;
    scf_cb.scf_facility = DB_ULF_ID;
    scf_cb.scf_session = DB_NOSESSION;
    scf_cb.scf_len_union.scf_ilength = 2;
    scf_cb.scf_ptr_union.scf_sci = (SCI_LIST *) &info[0];
    /* scf_error is not usually an input parameter */
    if (flag == ULE_LOG || flag == ULE_MESSAGE)
    {
	info[2].sci_code = SCI_QBUF;
	info[2].sci_length = sizeof(qbuf);
	info[2].sci_aresult = (char *) &qbuf;
	info[2].sci_rlength = 0;
	info[3].sci_code = SCI_QLEN;
	info[3].sci_length = sizeof(qlen);
	info[3].sci_aresult = (char *) &qlen;
	info[3].sci_rlength = 0;
	info[4].sci_code = SCI_TRACE_ERRNO;
	info[4].sci_length = sizeof(trace_errno);
	info[4].sci_aresult = (char *) &trace_errno;
	info[4].sci_rlength = 0;
	info[5].sci_code = SCI_PREV_QBUF;
	info[5].sci_length = sizeof(prev_qbuf);
	info[5].sci_aresult = (char *) &prev_qbuf;
	info[5].sci_rlength = 0;
	info[6].sci_code = SCI_PREV_QLEN;
	info[6].sci_length = sizeof(prev_qlen);
	info[6].sci_aresult = (char *) &prev_qlen;
	info[6].sci_rlength = 0;
	info[7].sci_code = SCI_PSQ_QBUF;
	info[7].sci_length = sizeof(psqbuf);
	info[7].sci_aresult = (char *) &psqbuf;
	info[7].sci_rlength = 0;
	info[8].sci_code = SCI_PSQ_QLEN;
	info[8].sci_length = sizeof(psqlen);
	info[8].sci_aresult = (char *) &psqlen;
	info[8].sci_rlength = 0;
	info[9].sci_code = SCI_TRACE_STACK;
	info[9].sci_length = sizeof(trace_stack);
	info[9].sci_aresult = (char *) &trace_stack;
	info[9].sci_rlength = 0;
	scf_cb.scf_len_union.scf_ilength = 10;
    }
    status = scf_call(SCU_INFORMATION, &scf_cb);
    if (status)
    {
	language = 1;
	sid = 0;
    }
    if (!language)
	language = 1;


    /* package up the stack parameters into an ER_ARGUMENT array */

    va_start( ap, num_parms );

    for( NumParms = 0; NumParms < num_parms && NumParms < NUM_ER_ARGS; NumParms++ )
    {
       er_args[NumParms].er_size = (i4) va_arg( ap, i4 );
       er_args[NumParms].er_value = (PTR) va_arg( ap, PTR );
    }

    va_end( ap );

    *uleError = 0;

    if (flag == 0 || flag == ULE_LOG || flag == ULE_LOOKUP)
    {
	/* Get INGRES message text. */

	status = ERslookup( local_error_code,
			    CLERROR(local_error_code)? clerror : (CL_ERR_DESC*) NULL,
			    ER_TIMESTAMP,
			    (sqlstate) ? sqlstate->db_sqlstate : (char *) NULL,
			    MessageArea,
			    (i4) sizeof(buffer.message),
			    (i4) language,
			    &text_length,
			    &sys_err,
			    NumParms,
			    er_args
			  );

	if (status != OK)
	{
	    CL_ERR_DESC    junk;

	    STprintf(MessageArea, "ULE_FORMAT: ");
	    length = STlength(MessageArea);

	    /*
	    ** If uleFormat caller is different than
	    ** error source, identify caller.
	    */
	    if ( flag == ULE_LOG && uleFileName &&
	        (uleFileName != DBerror->err_file ||
	         uleLineNumber != DBerror->err_line) )
	    {
		STcopy(uleFileName, filebuf);

		STprintf(LineNo, ":%d ", uleLineNumber);

		if ( LOfroms(PATH & FILENAME, filebuf, &loc) ||
		     LOdetail(&loc, dev, path, fprefix, fsuffix, version) )
		{
		    STpolycat(2, FileName,
		    		 LineNo,
				 &MessageArea[length]);
		}
		else
		{
		    STpolycat(4, fprefix,
				 ".", fsuffix, 
				 LineNo,
				 &MessageArea[length]);
		}
		length = STlength(MessageArea);
		MessageArea[length++] = ' ';
	    }

	    STprintf(&MessageArea[length],
			"Couldn't look up message %x ",
			local_error_code);
	    length = STlength(MessageArea);

	    STprintf(&MessageArea[length], "(reason: ER error %x)\n",status);
	    length = STlength(MessageArea);
	    status = ERslookup( (i4) status,
				&sys_err,
				(i4) 0,
				(sqlstate) ? sqlstate->db_sqlstate
					   : (char *) NULL,
				&MessageArea[length],
				(i4) (sizeof(buffer.message) - length),
				(i4) language,
				&text_length,
				&junk,
				0,
				(ER_ARGUMENT *) NULL
			     );
	    if (status != OK)
	    {
		STprintf(&MessageArea[length],
		    "... ERslookup failed twice:  status = %x", status);
		length = STlength(MessageArea);
	    }
	    else
	    {
		length += text_length;
	    }

	    *uleError = E_UL0002_BAD_ERROR_LOOKUP;
	}
	else
	{
	    length = text_length;
	}

	/* Get system message text. */

	if (clerror)
	{
	    MessageArea[length++] = '\n';

	    /*
	    ** Extract the distinct clerror source information, filename,
	    ** extension, and line number from CL_ERR_DESC
	    ** and prefix the message text with it.
	    */
	    if ( !CLERROR(error_code) && (FileName = clerror->errfile) )
	    {
		STcopy(FileName, filebuf);

		STprintf(LineNo, ":%d ", clerror->errline);

		if ( LOfroms(PATH & FILENAME, filebuf, &loc) ||
		     LOdetail(&loc, dev, path, fprefix, fsuffix, version) )
		{
		    STpolycat(2, FileName,
		    		 LineNo,
				 &MessageArea[length]);
		}
		else
		{
		    STpolycat(4, fprefix, 
				 ".", fsuffix, 
				 LineNo,
				 &MessageArea[length]);
		}

		length += STlength(&MessageArea[length]);
		MessageArea[length++] = ' ';
	    }

	    status = ERslookup(	(i4) 0,
				clerror,
				(i4) 0,
				(sqlstate) ? sqlstate->db_sqlstate
					   : (char *) NULL,
				&MessageArea[length],
				(i4) (sizeof(buffer.message) - length),
				(i4) language,
				&text_length,
				&sys_err,
				0,
				(ER_ARGUMENT *) NULL
			      );
	    if (status != OK)
	    {
	        CL_ERR_DESC    junk;

		STprintf(&MessageArea[length],
			"ULE_FORMAT: Couldn't look up system error ");
		length = STlength(MessageArea);

	        STprintf(&MessageArea[length],
		    "(reason: ER error %x)\n", status);
	        length = STlength(MessageArea);
	        status = ERslookup( (i4) status,
				    &sys_err,
				    (i4) 0,
				    (sqlstate) ? sqlstate->db_sqlstate
					       : (char *) NULL,
				    &MessageArea[length],
				    (i4) (sizeof(buffer.message) - length),
				    (i4) language,
				    &text_length,
				    &junk,
				    0,
				    (ER_ARGUMENT *) NULL
			         );
	        if (status != OK)
	        {
		    STprintf(&MessageArea[length],
		        "... ERslookup failed twice:  status = %x", status);
		    length = STlength(MessageArea);
	        }
		else
		{
		    length += text_length;
		}
		*uleError = E_UL0001_BAD_SYSTEM_LOOKUP;
	    }
	    else
	    {
		length += text_length;
	    }
	}

	/* Copy into callers buffer if requested. */

	if (msg_buffer && msg_buf_length)
	{
	    if (msg_buf_length < length)
		length = msg_buf_length;
	    MEcopy((PTR)MessageArea, length, (PTR)msg_buffer);
	    *msg_length = length;
	}
    }
    else if (flag == ULE_MESSAGE)
    {
	if (!msg_buffer || !msg_buf_length)
	{
	    *uleError = E_UL0003_BADPARM;
	    return (E_DB_ERROR);
	}
	MEcopy((PTR)msg_buffer, msg_buf_length, (PTR)MessageArea);
	length = msg_buf_length;
    }

    if (flag == ULE_LOG || flag == ULE_MESSAGE)
    {
	SCF_SESSION tmp_sid = sid;

	MEcopy((PTR)&Ule_mhdr, sizeof(ULE_MHDR), (PTR)&buffer.hdr);

        for (i = (sizeof(Ule_mhdr.ule_session)) ; --i >= 0; )
	{
            buffer.hdr.ule_session[i] = hex_chars[(tmp_sid & 0xf)];
            tmp_sid >>= 4;
	}
	
	/*
	** Extract the error source information, filename, extension,
	** and line number from CL_ERR_DESC or DB_ERROR
	** and format it into the ULE_MHDR.
	*/
	if ( CLERROR(DBerror->err_code) && clerror && clerror->errfile )
	{
	    FileName = clerror->errfile;
	    LineNumber = clerror->errline;
	}
	else
	{
	    FileName = DBerror->err_file;
	    LineNumber = DBerror->err_line;
	}

	if ( FileName )
	{

	    STprintf(LineNo, ":%d ", LineNumber);
	    
	    STcopy(FileName, filebuf);
	    if ( LOfroms(PATH & FILENAME, filebuf, &loc) ||
		 LOdetail(&loc, dev, path, fprefix, fsuffix, version) )
	    {
		STpolycat(2, FileName,
			     LineNo,
			     SourceInfo);
	    }
	    else
	    {
		STpolycat(4, fprefix, 
			     ".", fsuffix, 
			     LineNo,
			     SourceInfo);
	    }

	    STmove(SourceInfo, ' ', SourceInfoLen, (PTR)&buffer.hdr.ule_source);
	}

	/* Echo the message to II_DBMS_LOG, if defined */
	TRwrite(NULL, PrefixLen + length, (PTR)&buffer);
	
	status = ERsend(ER_ERROR_MSG, (PTR)&buffer,
		    PrefixLen + length, &sys_err);
    }
Пример #19
0
/*{
** Name: psf_debug	- Standard entry point for debugging PSF.
**
** Description:
**      This function is the standard entry point to PSF for setting and
**	clearing tracepoints.
**
** Inputs:
**      debug_cb                        Pointer to a DB_DEBUG_CB
**        .db_trswitch                    What operation to perform
**	    DB_TR_NOCHANGE		    None
**	    DB_TR_ON			    Turn on a tracepoint
**	    DB_TR_OFF			    Turn off a tracepoint
**	  .db_trace_point		  The number of the tracepoint to be
**					  effected
**	  .db_vals[2]			  Optional values, to be interpreted
**					  differently for each tracepoint
**	  .db_value_count		  The number of values specified in
**					  the above array
**
** Outputs:
**      None
**	Returns:
**	    E_DB_OK			Success
**	    E_DB_WARN			Operation completed with warning(s)
**	    E_DB_ERROR			Function failed; non-catastrophic error
**	    E_DB_FATAL			Function failed; catastrophic error
**	Exceptions:
**	    none
**
** Side Effects:
**	    none
**
** History:
**	17-apr-86 (jeff)
**          written
**	13-feb-90 (andre)
**	    set scf_stype to SCU_EXCLUSIVE before calling scu_swait.
**	14-jul-93 (ed)
**	    replacing <dbms.h> by <gl.h> <sl.h> <iicommon.h> <dbdbms.h>
**	10-aug-93 (andre)
**	   removed declaration of scf_call()
**	08-oct-93 (rblumer)
**	   In order to allow session trace points that take a value,
**	   changed ult_set_macro call to use firstval and secondval
**	   instead of hard-coding zeros for the values.
**	09-Oct-1998 (jenjo02)
**	    Removed SCF semaphore functions, inlining the CS calls instead.
**      04-may-1999 (hanch04)
**          Change TRformat's print function to pass a PTR not an i4.
**      21-Feb-2007 (hanal04) Bug 117736
**          Added trace point PS503 to dump PSF's ULM memory usage to the
**          DBMS log.
*/
DB_STATUS
psf_debug(
	DB_DEBUG_CB        *debug_cb)
{
    i4                  flag;
    i4		firstval;
    i4		secondval;
    PSS_SESBLK		*sess_cb;
    extern PSF_SERVBLK	*Psf_srvblk;

    /* Get the session control block */
    sess_cb = psf_sesscb();

    /* Flags 0 - PSF_TBITS-1 are for the server; all others are for sessions */
    flag = debug_cb->db_trace_point;
    if (flag >= PSF_TBITS)
    {
	flag = flag - PSF_TBITS;
	if (flag >= PSS_TBITS)
	    return (E_DB_ERROR);
    }

    /* There can be UP TO two values, but maybe they weren't given */
    if (debug_cb->db_value_count > 0)
	firstval = debug_cb->db_vals[0];
    else
	firstval = 0L;

    if (debug_cb->db_value_count > 1)
	secondval = debug_cb->db_vals[1];
    else
	secondval = 0L;

    /*
    ** Three possible actions: Turn on flag, turn it off, or do nothing.
    */
    switch (debug_cb->db_trswitch)
    {
    case DB_TR_ON:
	/* First PSF_TBITS flags belong to server, others to session */
	if (debug_cb->db_trace_point < PSF_TBITS)
	{
	    CSp_semaphore(1, &Psf_srvblk->psf_sem); /* exclusive */
	    ult_set_macro(&Psf_srvblk->psf_trace, flag, firstval, secondval);
	    CSv_semaphore(&Psf_srvblk->psf_sem);
	}
	else
	{
	    /* Do nothing if couln't get session control block */
	    if (sess_cb != (PSS_SESBLK *) NULL)
	    {
		if(flag == PSS_ULM_DUMP_POOL)
		{
		    ULM_RCB	ulm_rcb;
		    char	buf[512];
		    SCF_CB	scf_cb;

		    ulm_rcb.ulm_poolid = Psf_srvblk->psf_poolid;
		    ulm_rcb.ulm_facility = DB_PSF_ID;
		    _VOID_ ulm_mappool(&ulm_rcb);
		    ulm_print_pool(&ulm_rcb);
		    STprintf(buf, "ULM Memory Pool Map and ULM Memory Print Pool for PSF has been \nwritten to the DBMS log file.");
		    
		    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 = DB_NOSESSION;
		    scf_cb.scf_nbr_union.scf_local_error = 0;
		    scf_cb.scf_len_union.scf_blength = STlength(buf);
		    scf_cb.scf_ptr_union.scf_buffer = buf;
		    _VOID_ scf_call(SCC_TRACE, &scf_cb);
		}
		else
		{
		    ult_set_macro(&sess_cb->pss_trace, flag, firstval, 
				secondval);

		    /* Yacc debugging requires a special call */
		    if (flag == PSS_YTRACE)
		        psl_trace((PTR) sess_cb->pss_yacc, TRUE);
		}
	    }
	}
	break;

    case DB_TR_OFF:
	/* First PSF_TBITS flags belong to server, others to session */
	if (debug_cb->db_trace_point < PSF_TBITS)
	{
	    CSp_semaphore(1, &Psf_srvblk->psf_sem); /* exclusive */
	    ult_clear_macro(&Psf_srvblk->psf_trace, flag);
	    CSv_semaphore(&Psf_srvblk->psf_sem);
	}
	else
	{
	    /* Do nothing if couldn't get session control block */
	    if (sess_cb != (PSS_SESBLK *) NULL)
	    {
		ult_clear_macro(&sess_cb->pss_trace, flag);
		/* Yacc debugging requires a special call */
		if (flag == PSS_YTRACE)
		    psl_trace((PTR) sess_cb->pss_yacc, FALSE);
	    }
	}
	break;

    case DB_TR_NOCHANGE:
	/* Do nothing */
	break;

    default:
	return (E_DB_ERROR);
    }

    return (E_DB_OK);
}
Пример #20
0
DB_STATUS
dmc_add_db(
DMC_CB    *dmc_cb)
{
    DMC_CB		*dmc = dmc_cb;
    DM_SVCB		*svcb = dmf_svcb;
    DMC_LOC_ENTRY	*location;
    i4		loc_count;
    i4		flags;
    i4		mode;
    i4		dm2mode;
    i4		error,local_error;
    DMM_LOC_LIST	*loc_ptr[4];
    DB_STATUS		status;
    DMP_DCB		*dcb;

    CLRDBERR(&dmc->error);

    for (status = E_DB_ERROR;;)
    {
	/*	Verify control block parameters. */

	if (dmc->dmc_op_type != DMC_DATABASE_OP)
	{
	    SETDBERR(&dmc->error, 0, E_DM000C_BAD_CB_TYPE);
	    break;
	}

	if (dmc->dmc_id != svcb->svcb_id)
	{
	    SETDBERR(&dmc->error, 0, E_DM002D_BAD_SERVER_ID);
	    break;
	}

	flags = 0;
	if (dmc->dmc_flags_mask &
	    ~(DMC_NOJOURNAL | DMC_JOURNAL | DMC_FSTCOMMIT | DMC_SOLECACHE |
              DMC_CNF_LOCKED | DMC_CVCFG | DMC_ADMIN_DB | DMC_DMCM))
	{
	    SETDBERR(&dmc->error, 0, E_DM001A_BAD_FLAG);
	    break;
	}
	if (dmc->dmc_flags_mask & DMC_NOJOURNAL)
	    flags |= DM2D_NOJOURNAL;
	if (dmc->dmc_flags_mask & DMC_JOURNAL)
	    flags |= DM2D_JOURNAL;
	if (dmc->dmc_flags_mask & DMC_FSTCOMMIT)
	    flags |= DM2D_FASTCOMMIT;
	if (dmc->dmc_flags_mask & DMC_SOLECACHE)
	    flags |= DM2D_BMSINGLE;
	if (dmc->dmc_flags_mask & DMC_CVCFG)
	    flags |= DM2D_CVCFG;
        
        /* b97083 - Is the CNF file already locked by caller? */
        if (dmc->dmc_flags_mask & DMC_CNF_LOCKED)
            flags |= DM2D_CNF_LOCKED;

	if (dmc->dmc_s_type & DMC_S_SINGLE)
	    flags |= DM2D_SINGLE;
	if (dmc->dmc_s_type & DMC_S_MULTIPLE)
	    flags |= DM2D_MULTIPLE;

        /*
        ** (ICL phil.p)
        */
        if (dmc->dmc_flags_mask & DMC_DMCM)
            flags |= DM2D_DMCM;

        if (dmc->dmc_flags_mask2 & DMC2_READONLYDB)
            flags |= DM2D_READONLYDB;

	/* No MO objects if so requested */
	if ( dmc->dmc_flags_mask2 & DMC2_NODBMO ||
	     mode == DMC_A_CREATE || mode == DMC_A_DESTROY )
	{
	    flags |= DM2D_NODBMO;
	}

	/*
	** It is an error to specify Fast Commit without specifying to
	** use a single buffer manager.
        ** (ICL phil.p) UNLESS running DMCM, which effectively means
        ** running FastCommit in a Multi-Cache environment.
	*/

        if (!(flags & DM2D_DMCM))
        {
            if ((flags & (DM2D_FASTCOMMIT | DM2D_BMSINGLE)) == DM2D_FASTCOMMIT)
	    {
		SETDBERR(&dmc->error, 0, E_DM0115_FCMULTIPLE);
                break;
	    }
        }

	mode = dmc->dmc_db_access_mode;
	if (mode != DMC_A_READ &&
	    mode != DMC_A_WRITE &&
	    mode != DMC_A_CREATE &&
	    mode != DMC_A_DESTROY)
	{
	    SETDBERR(&dmc->error, 0, E_DM000F_BAD_DB_ACCESS_MODE);
	    break;
	}
	dm2mode = (mode == DMC_A_READ) ? DM2D_A_READ : DM2D_A_WRITE;

	/*  Check that at least one location was passed in. */

	location = (DMC_LOC_ENTRY *)dmc->dmc_db_location.data_address;
	loc_count = dmc->dmc_db_location.data_in_size / sizeof(DMC_LOC_ENTRY);
	if (loc_count == 0)
	{
	    SETDBERR(&dmc->error, 0, E_DM002A_BAD_PARAMETER);
	    break;
	}
	    
	/*  Check if database should be created. */

	if (mode == DMC_A_CREATE)
	{
	    SCF_CB              scf_cb;
	    SCF_SCI             sci_list[2]; 
	    DB_NAME		collation;
	    DB_NAME		ucollation;
	    char		*p;
	    char		ucolname[] = "udefault";
	    i4		dbservice;

	    scf_cb.scf_length = sizeof(SCF_CB);
	    scf_cb.scf_type = SCF_CB_TYPE;
	    scf_cb.scf_facility = DB_DMF_ID;
	    scf_cb.scf_session = (SCF_SESSION)dmc->dmc_session_id;
	    scf_cb.scf_ptr_union.scf_sci = (SCI_LIST *)sci_list;
	    sci_list[0].sci_length = sizeof(dbservice);
	    sci_list[0].sci_code = SCI_DBSERVICE;
	    sci_list[0].sci_aresult = (char *)&dbservice;
	    sci_list[0].sci_rlength = 0;
	    scf_cb.scf_len_union.scf_ilength = 1;

	    status = scf_call(SCU_INFORMATION, &scf_cb);
	    if (status != E_DB_OK)
	    {
		uleFormat(&scf_cb.scf_error, 0, (CL_ERR_DESC *)NULL, 
		    ULE_LOG, NULL, (char *)0, (i4)0, (i4 *)0, 
		    &error, 0);
		SETDBERR(&dmc->error, 0, E_DM002F_BAD_SESSION_ID);
		break;
	    }

	    /*	Collation for iidbdb can only be the default. */

	    MEfill(sizeof(collation.db_name), ' ', collation.db_name);
	    NMgtAt("II_COLLATION", &p);
	    if (p && *p)
		MEmove(STlength(p), p, ' ', sizeof(collation.db_name), 
				collation.db_name);
	    MEmove(STlength(ucolname), ucolname, ' ', 
		   sizeof(ucollation.db_name), ucollation.db_name);

	    loc_ptr[0] = (DMM_LOC_LIST *) &loc_list[0];
	    loc_ptr[1] = (DMM_LOC_LIST *) &loc_list[1];
	    loc_ptr[2] = (DMM_LOC_LIST *) &loc_list[2];
	    loc_ptr[3] = (DMM_LOC_LIST *) &loc_list[3];

	    /* Even though the iidbdb is not "operative" at this stage, we
	    ** will mark it as operative in the config file now (it will not
	    ** be marked operative in the iidatabase catalog until after it
	    ** is fully created).  Although we would like to mark the iidbdb
	    ** "inoperative" in the config file now and update it to operative
	    ** status when creation is successfully completed (as is done for
	    ** all other DBs) the internal procedure "iiqef_alter_db" which
	    ** updates this bit will not work on the iidbdb; see comments in
	    ** createdb regarding this problem.
	    */ 
	    status = dmm_add_create(0, &dmc->dmc_db_name, &dmc->dmc_db_owner,
		 1, dbservice, DU_OPERATIVE, 
		(DB_LOC_NAME *) &dbdb_location, 11, "II_DATABASE", 4, 
		loc_ptr, collation.db_name, ucollation.db_name, &dmc->error);

	    if (status != E_DB_OK)
	    {
		if (dmc->error.err_code > E_DM_INTERNAL)
		{
		    uleFormat( &dmc->error, 0, NULL, ULE_LOG , NULL,
			    (char * )0, 0L, (i4 *)0, &local_error, 0);
		    SETDBERR(&dmc->error, 0, E_DM0084_ERROR_ADDING_DB);
		}
		break;
	    }
	}
	else if (mode == DMC_A_DESTROY)
	{
	    return (E_DB_OK);
	}

	/*  Call the physical layer to construct a DCB for this database. */

	status = dm2d_add_db(flags, &dm2mode, &dmc->dmc_db_name, 
		&dmc->dmc_db_owner, loc_count, (DM2D_LOC_ENTRY *)location, &dcb, 
		(i4 *)dmc->dmc_lock_list, &dmc->error);
	if (status != E_DB_OK)
	{
	    if (dmc->error.err_code > E_DM_INTERNAL)
	    {
		uleFormat( &dmc->error, 0, NULL, ULE_LOG , NULL,
		    (char * )0, 0L, (i4 *)0, &local_error, 0);
		SETDBERR(&dmc->error, 0, E_DM0084_ERROR_ADDING_DB);
	    }
	    break;
	}

	/*  Use the access mode passed back */
	dmc->dmc_db_access_mode = 
		(dm2mode == DM2D_A_READ) ? DMC_A_READ : DMC_A_WRITE;
	dmc->dmc_db_id = (char *)dcb;
	dmc->dmc_dbservice = dcb->dcb_dbservice;
	dmc->dmc_dbcmptlvl = dcb->dcb_dbcmptlvl;
	dmc->dmc_1dbcmptminor = dcb->dcb_1dbcmptminor;
	return (E_DB_OK);
    }

    return (status);
}
Пример #21
0
/*
** Name: qeu_evraise
**
** Description:
**	This routine raises an event, it processes the external request
**	QEU_RAISE_EVENT, typically when raising the event associated with
**	a security alarm.
**
**	Note this *does* do event tracing (SET PRINTEVENTS/LOGEVENTS)
**	but does *not* do security checks/auditing on the operation, this
**	is assumed to be handled at a higher level.
**
** Inputs:
**	qef_rcb.evname   - Event name
**	qef_rcb.evowner  - Event owner
**	qef_rcb.evtext   - Event text 
**	qef_rcb.ev_l_text- Length of text
**
** History:
**	26-nov-93 (robf)
**         Created for secure 2.0
**	12-Jan-1998 (kinpa04/merja01)
**		Remove (i4) casting of session id.  This caused the 
**		session ID to get truncated on axp_osf while raising events.
**	10-Jan-2001 (jenjo02)
**	    We know this session's id; pass it to SCF.
**	30-Dec-2005 (kschendel)
**	    Update call to qef-adf-error.
**
*/
DB_STATUS
qeu_evraise(
	QEF_CB  *qef_cb,
	QEF_RCB *qef_rcb
)
{
    DB_DATA_VALUE tm;					/* Timestamp */
    DB_DATE	tm_date;
    SCF_ALERT	scfa;					
    SCF_CB	scf_cb;				
    SCF_SCI		sci_list[1];
    DB_ALERT_NAME alert;
    i4	err;
    char	*errstr;
    DB_STATUS   status=E_DB_OK;
    i4	tr1 = 0, tr2 = 0;			/* Dummy trace values */

    /*
    ** Build alert name
    */
    STRUCT_ASSIGN_MACRO(*qef_rcb->qef_evname, alert.dba_alert);
    STRUCT_ASSIGN_MACRO(*qef_rcb->qef_evowner, alert.dba_owner);

    scf_cb.scf_length	= sizeof(SCF_CB);
    scf_cb.scf_type	= SCF_CB_TYPE;
    scf_cb.scf_facility	= DB_QEF_ID;
    scf_cb.scf_session	= qef_cb->qef_ses_id;

    /* Get the database name */
    scf_cb.scf_ptr_union.scf_sci   = (SCI_LIST *) sci_list;
    scf_cb.scf_len_union.scf_ilength = 1;
    sci_list[0].sci_length  = sizeof(DB_DB_NAME);
    sci_list[0].sci_code    = SCI_DBNAME;
    sci_list[0].sci_aresult = (char *) &alert.dba_dbname;
    sci_list[0].sci_rlength = NULL;
    status = scf_call(SCU_INFORMATION, &scf_cb);
    if (status != E_DB_OK)
    {
         _VOID_ qef_error(E_QE022F_SCU_INFO_ERROR, 0L, status, &err,
			     &qef_rcb->error, 0);
	return E_DB_ERROR;
    }

    /* Format SCF event request block */
    scf_cb.scf_ptr_union.scf_alert_parms = &scfa;

    scfa.scfa_name = &alert;
    scfa.scfa_text_length = 0;
    scfa.scfa_user_text = NULL;
    scfa.scfa_flags = 0;

    if (qef_rcb->qef_ev_l_text > 0)		/* No need for empty strings */
    {
	if (qef_rcb->qef_ev_l_text > DB_EVDATA_MAX)
	    qef_rcb->qef_ev_l_text = DB_EVDATA_MAX;
	scfa.scfa_text_length = qef_rcb->qef_ev_l_text;
	scfa.scfa_user_text = qef_rcb->qef_evtext;
    }
    tm.db_datatype = DB_DTE_TYPE; 	/* Get time stamp for the event */
    tm.db_prec = 0;
    tm.db_length = sizeof(tm_date);
    tm.db_data = (PTR)&tm_date;
    tm.db_collID = -1;
    status = adu_datenow(qef_cb->qef_adf_cb, &tm);
    if (status != E_DB_OK)
    {
	    if ((status = qef_adf_error(&qef_cb->qef_adf_cb->adf_errcb,
			status, qef_cb, &qef_rcb->error)) != E_DB_OK)
		return (status);
    }
    scfa.scfa_when = &tm_date;

    /* If tracing and/or logging events then display event information */
    if (ult_check_macro(&qef_cb->qef_trace, QEF_T_EVENTS, &tr1, &tr2))
         qea_evtrace(qef_rcb, QEF_T_EVENTS, &alert, &tm, 
			(i4)qef_rcb->qef_ev_l_text,
			(char*)qef_rcb->qef_evtext);

    if (ult_check_macro(&qef_cb->qef_trace, QEF_T_LGEVENTS, &tr1, &tr2))
        qea_evtrace(qef_rcb, QEF_T_LGEVENTS, &alert, &tm, 0, (char *)NULL);

    /*
    ** Raise the event in SCF
    */
    status = scf_call(SCE_RAISE, &scf_cb);
    if (status != E_DB_OK)
    {
	char	*enm, *onm;	/* Event and owner names */

	enm = (char *)&alert.dba_alert;
	onm = (char *)&alert.dba_owner;
	errstr="RAISE";
	switch (scf_cb.scf_error.err_code)
	{
	  case E_SC0270_NO_EVENT_MESSAGE:
	    _VOID_ qef_error(E_QE019A_EVENT_MESSAGE, 0L, status, &err,
			     &qef_rcb->error, 1,
			     (i4)STlength(errstr), errstr);
	    break;
	  case E_SC0280_NO_ALERT_INIT:
	    _VOID_ qef_error(E_QE0200_NO_EVENTS, 0L, status, &err,
			     &qef_rcb->error, 1,
			     (i4)STlength(errstr), errstr);
	    break;
	  default:
	    _VOID_ qef_error(E_QE020F_EVENT_SCF_FAIL, 0L, status, &err,
			     &qef_rcb->error, 4,
			     (i4)STlength(errstr), errstr,
			     (i4)sizeof(i4),
					(PTR)&scf_cb.scf_error.err_code,
			     qec_trimwhite(DB_OWN_MAXNAME, onm), onm,
			     qec_trimwhite(DB_EVENT_MAXNAME, enm), enm);
	    break;
	}
	qef_rcb->error.err_code = E_QE0025_USER_ERROR;
	status = E_DB_ERROR;
    } /* If SCF not ok */
    return status;
}
Пример #22
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);
}