Example #1
0
bool
gcn_can_auth( GCN_RESOLVE_CB *grcb )
{
    /*
    ** If the installation password has already
    ** been processed, just use it.  Otherwise,
    ** check if there is an installation password.
    ** (check for reserved internal login).
    */
    if ( grcb->flags & GCN_RSLV_IP )
    {
	grcb->pwd = grcb->ip;
	grcb->flags &= ~GCN_RSLV_PWD_ENC;
    }
    else  if ( *grcb->vnode  &&  ! STcompare( grcb->usr, GCN_NOUSER )  &&
	       STcompare( grcb->pwd, GCN_NOPASS ) )
    {
	/*
	** Save installation password.  Flag the fact that 
	** the installation password has been decoded in 
	** case we come through here again.
	*/
	if ( grcb->ip )  MEfree( (PTR)grcb->ip );	/* Should not happen */
	grcb->ip = STalloc( grcb->pwd );
	grcb->pwd = grcb->ip;
	grcb->flags |= GCN_RSLV_IP;
    }

    return( ((grcb->flags & GCN_RSLV_IP) != 0) );
}
Example #2
0
STATUS
gcn_pwd_auth( char *user, char *passwd )
{
    STATUS	status = FAIL;

    /*
    ** The reserved internal login is accepted.
    ** An installation password is rejected.
    ** If the password appears to be a ticket,
    ** it must match an existing ticket.  Other-
    ** wise, the caller must validate the login.
    */
    if ( ! STcompare( user, GCN_NOUSER ) )
    {
	if ( ! STcompare(passwd, GCN_NOPASS) )  
	    status = OK;
	else
	    status = E_GC0145_GCN_INPW_NOT_ALLOWED;
    }
    else  if ( ! MEcmp( passwd, GCN_AUTH_TICKET_MAG, GCN_L_AUTH_TICKET_MAG ) )
    {
	u_i1	lticket[ GCN_L_TICKET ];
	i4	len;

	CItobin( (PTR)(passwd + GCN_L_AUTH_TICKET_MAG), &len, lticket );
	status = gcn_use_lticket( user, lticket, len );
    }

    return( status );
}
Example #3
0
/*
** Name psl_lm2_setlockkey() - perform semantic action for SETLOCKKEY production
**
** Description:
**	perform semantic action for SETLOCKKEY production in QUEL and SQL
**	grammars
**
** Input:
**	sess_cb		    PSF session CB
**	    pss_distrib	    DB_3_DDB_SESS if distributed thread
**	    pss_stmt_flags  PSS_SET_LOCKMODE_SESS if SET LOCKMODE SESSION
**			    (distributed thread only)
**	char_name	    name of a characteristic
**
** Output:
**	char_type	    a number corresponding to this characteristic type
**	err_blk		    filled in if an error occurred
**
** Returns:
**	E_DB_{OK, ERROR}
**
** Side effects:
**	none
**
**  History:
**	07-mar-91 (andre)
**	    plagiarized from SETLOCKKEY production
**	20-apr-92 (barbara)
**	    Updated for Sybil.  Added session cb to interface.  For the
**	    distributed thread, TIMEOUT is the only option supported on a
**	    SESSION basis.
**	06-oct-93 (barbara)
**	    Fixed bug 53492.  Star now supports all set lockmode session
**	    statements.
**      04-apr-1995 (dilma04) 
**          Add support for READLOCK=READ_COMMITTED/REPEATABLE_READ.
**      14-oct-97 (stial01)
**          psl_lm2_setlockkey() Isolation levels are not valid readlock values.
**	    
*/
DB_STATUS
psl_lm2_setlockkey(
	PSS_SESBLK  *sess_cb,
	char	    *char_name,
	i4	    *char_type,
	DB_ERROR    *err_blk)
{
    i4                err_code;

    /* Decode "set lockmode" parameter.  Error if unknown. */
    if (!STcompare(char_name, "level"))
    {
	*char_type = LOCKLEVEL;
    }
    else if (!STcompare(char_name, "readlock"))
    {
	*char_type = READLOCK;
    }
    else if (!STcompare(char_name, "maxlocks"))
    {
	*char_type = MAXLOCKS;
    }
    else if (!STcompare(char_name, "timeout"))
    {
    	*char_type = TIMEOUT;
    }
    else
    {
	(VOID) psf_error(5928L, 0L, PSF_USERERR, &err_code,
	    err_blk, 1, (i4) STlength(char_name), char_name);
	return (E_DB_ERROR);    /* non-zero return means error */
    }

    return(E_DB_OK);
}
Example #4
0
/*
** Name: SAclose - close an operating system audit trail
**
** Description:
**	This rouitne closes an operating system audit trail previously opened
**	by SAopen(). The routine should check that the given trail has been
**	opened before attempting to close it, it will also call SAflush()
**	to flush all outstanding audit records to the audit trail.
**
** Inputs:
**	aud_trail_d	descriptor that identifies this audit trail
**
** Outputs:
**	err_code	pointer to a variable used to return OS errors
**
** Returns:
**	OK              if operation succeeded
**	SA_NOOPEN       the audit trail decsribed by this descriptor has not
**			been opened
**	SA_BADPARAM     bad parameter values were passed to the routine
**	SA_NOSUPP       the operation is not supported by this implimentation of
**			SA.
**	FAIL            the operation failed
**
** History:
**	7-jan-94 (stephenb)
**	    Initial creation as a stub
**	28-feb-94 (stephenb)
**	    Updated to current SA spec.
*/
STATUS
SAclose(PTR             *aud_trail_d,
	CL_ERR_DESC     *err_code)
{
    STATUS	cl_stat;

    /*
    ** Check that the audit trail is open, this is just a dummy check
    ** that the stub routine SAopen() has been called.
    */
    if (STcompare(((SA_DESC*)*aud_trail_d)->sa_desc, "OS"))
	return (SA_NOOPEN);
    /*
    ** Call SAflush() to flush outstanding records
    */
    cl_stat = SAflush(aud_trail_d, err_code);
    if (cl_stat != OK)
	return (cl_stat);

    /*
    ** Re-claim memory
    */
    cl_stat = MEfree(*aud_trail_d);
    if (cl_stat != OK)
	return (SA_MFREE);
    else
	return (OK);
}
Example #5
0
static STATUS
gcn_nq_fopen( char *name, char *mode, FILE **file )
{
    LOCATION	loc;
    STATUS	status;

#ifndef hp9_mpe
    if ( ( status = NMloc( ADMIN, PATH, (char *)NULL, &loc ) ) != OK )
        goto error;

    LOfaddpath( &loc, "name", &loc );
    LOfstfile( name, &loc );
#else
    if ( (status = NMloc( FILES, FILENAME, name, &loc )) != OK )
        goto error;
#endif

    if ( ! STcompare( mode, "r" )  &&  (status = LOexist( &loc )) != OK )
        goto error;

#ifdef VMS
    status = SIfopen( &loc, mode, SI_RACC, sizeof(GCN_DB_RECORD), file );

    if (status == E_CL1904_SI_CANT_OPEN && ( LOexist( &loc ) == OK ) )
        status = SIfopen( &loc, mode, GCN_RACC_FILE, sizeof (GCN_DB_RECORD),
                          file );
#else
    status = SIfopen( &loc, mode, SI_RACC, sizeof (GCN_DB_RECORD), file );
#endif

error:

    if ( status != OK )  *file = NULL;
    return( status );
}
Example #6
0
i4
MO_instance_compare( const char *aptr, const char *bptr )
{
    MO_INSTANCE *a = (MO_INSTANCE *)aptr;
    MO_INSTANCE *b = (MO_INSTANCE *)bptr;

    register i4  res;

    res = *(char *)a->classdef->node.key - *(char *)b->classdef->node.key;
    if( res == 0 )
    {
	{
	    res = STcompare( a->classdef->node.key, b->classdef->node.key );
	    if( res == 0 )
	    {
		if( a->instance == NULL )
		{
		    res = b->instance == NULL? 0 : 1;
		}
		else if( b->instance == NULL )
		{
		    res = 1;
		}
		else
		{
		    res = a->instance[0] - b->instance[0];
		    if( res == 0 )
			res = STcompare( a->instance, b->instance );
		}
	    }
	}
    }

# ifdef xDEBUG
    SIprintf("compare %s:%s %s:%s -> %d\n",
	 a->classdef->node.key,
	 a->instance ? a->instance : "<nil>",
	 b->classdef->node.key,
	 b->instance ? b->instance : "<nil>",
	 res );
# endif

    return( res );
}
Example #7
0
static char *
ns_resolve_param( API_PARSE *parse, i4  fld, bool wild )
{
    char *str = empty;

    if ( fld < parse->field_count  &&  parse->fields[ fld ][ 0 ] )
	str = parse->fields[ fld ];

    if ( wild  &&  ! STcompare( str, wild_card ) )  str = empty;

    return( str );
}
Example #8
0
/*
** Name: main
**
** Description:
**      Program entry point handles processing of command line arguments.
**
** Inputs:
**      argc            Count of number of parameters
**      argv            List of parameters.
**
** Outputs:
**      None.
**
** Returns:
**      OK                          Completed successfully
**      !OK                         Failed.
**
** History:
**      23-May-2001 (fanra01)
**          Created.
*/
ICE_STATUS
main(int argc, II_CHAR** argv)
{
    ICE_STATUS  status = OK;
    II_INT4      opt = 1;

    if (argc == 1)
    {
        IIUGerr( E_WU0024_ICEVAR_USAGE, UG_ERR_ERROR, 0, NULL, NULL,
            NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL );
        return(FAIL);
    }
    switch(argc)
    {
        case 6:
            progparms.value = argv[5];
        case 5:
            progparms.variable = argv[4];
            progparms.scope = argv[3];
            if (STcompare(argv[2], IC_STR_RET) == 0)
            {
                progparms.action = IC_VAR_RET;
            }
            else if (STcompare(argv[2], IC_STR_SET) == 0)
            {
                progparms.action = IC_VAR_SET;
            }
            progparms.cookie = argv[1];
            progparms.name = argv[0];       /* setup for use in messages */
            status = icevar( &progparms );
            break;

        default:
            IIUGerr( E_WU0024_ICEVAR_USAGE, UG_ERR_ERROR, 0, NULL, NULL,
                NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL );
            status = FAIL;
            break;
    }
    return(status);
}
Example #9
0
bool check_uuid_mac()
{
	char *uuid_mac=NULL;
	NMgtAt("II_UUID_MAC", &uuid_mac);
	if ((uuid_mac != (char *)NULL && *uuid_mac != EOS) && 
        (STcompare(uuid_mac,"TRUE") == 0))
        {
		return TRUE;        
	}
	else
	{
		return FALSE;
	}
}
Example #10
0
static VOID
AddMutex( CS_SEMAPHORE *CsSem,
	  i4 		thread_type )
{
    u_i4 	hashnum,
    		hashstart;
    char	*hashname;
    MUTEXES	*hashtable = CsSamplerBlkPtr->Mutex;
    
    ++CsSamplerBlkPtr->nummutexsamples;	/* count the total number */

    if (CsSem->cs_sem_name[0] != '\0')
    {	/* A "named" semaphore */
    	hashnum = ElfHash(CsSem->cs_sem_name) % MAXMUTEXES;
	hashname = CsSem->cs_sem_name;
    }
    else
    {   /* All "unnamed" semaphores use the last slot */
    	hashnum = MAXMUTEXES;
	hashname = "<unnamed>";
    }

    hashstart = hashnum;
    do 
    {
	if (hashtable[hashnum].name[0] == '\0')
	{   /* Slot available: add semaphore entry to the table */
	    STcopy(hashname, hashtable[hashnum].name);
	    hashtable[hashnum].id = (char *) CsSem;
	    hashtable[hashnum].count[thread_type] = 1;
	    break;
	}
	if (STcompare(hashname, hashtable[hashnum].name) == 0)
	{   /* Found the correct semaphore entry...increment the count. */
	    ++hashtable[hashnum].count[thread_type];
	    hashtable[hashnum].id = (char *) CsSem;
	    break;
	}
	/* This is a hash collision...see if the next slot is available. */
	/* If past the end of the table, wrap around to beginning.	 */
	++hashnum;
	if (hashnum >= MAXMUTEXES)		
	    hashnum = 0;		
    } while (hashnum != hashstart);
    /*
    ** If we fall out of the 'do' loop without finding a slot (the table is
    ** full), just ignore this semaphore.
    */
} /* AddMutex() */
Example #11
0
static 
SERVER_ENTRY *
LookUpServer( char *name )
{
	SERVER_ENTRY	*cur = server_list;
	int i = 0;
	
	while ( i++ < nServers)
	{
		if( !STcompare( name, cur->name ) )
			return cur;
		cur = cur->next;
	}
	return NULL; /* no match */
}	
Example #12
0
/*
** Name - SAwrite - write a record to the operating system audit trail
**
** Description:
**	This routine writes an audit record to the operating system audit trail.
**	It is preffereable though not compulsory for this routine to return 
**	asynchronously, a subsequent call to SAflush() will hand all 
**	outstanding audits to the operating system for auditing, if SAwrite() 
**	is synchronous then SAflush() will be a no-op routine. SAwrite() may 
**	buffer a number of audit records for performance before writing, if 
**	the caller wishes to guarantee writes a subsequent call to SAflush() 
**	must be used. SAwrite() should attempt, if possible, to write an
**	additional field, other than those passed in SA_AUD_REC, to the 
**	operating system audit trail, that will uniquely identify the record 
**	as an Ingres audit record. The audit trail will be identified by it's 
**	descriptior passed back	from SAopen().
**	
** Inputs:
**	aud_trail_d     a descriptor that identifies this audit trail
**	aud_rec         the audit record to be written
**
** Outputs:
**	err_code        pointer to a variable used to return OS errors.
**
** Returns:
**	OK              if operation succeeded
**	SA_NOOPEN       the audit trail decsribed by this descriptor has not
**			been opened
**	SA_NOWRITE      this audit trail may not be written to
**	SA_BADPARAM     bad parameter values were passed to the routine
**	SA_NOSUPP       the operation is not supported by this implimentation of
**			SA.
**	FAIL            the operation failed
**
** History:
**	7-jan-94 (stephenb)
**	    Initial creation using TRdisplay for testing.
**	28-feb-94 (stephenb)
**	    Updated to current SA spec.
*/
STATUS
SAwrite(PTR             *aud_trail_d,
	SA_AUD_REC      *aud_rec,
	CL_ERR_DESC     *err_code)
{
    /*
    ** This is a "quick and dirty routine" which just re-formats
    ** the audit record and TRdisplay's it
    */
    SYSTIME	stime;
    struct	TMhuman	time;
    char	*date;

    /*
    ** Check that the audit trail is open, this is just a dummy check
    ** that the stub routine SAopen() has been called.
    */
    if (STcompare(((SA_DESC*)*aud_trail_d)->sa_desc, "OS"))
	return (SA_NOOPEN);

    /*
    ** Get a human readable date string
    */
    TMnow(&stime);
    _VOID_ TMbreak(&stime, &time);
    _VOID_ STpolycat(7, time.wday, time.day, time.month, time.year,
	time.hour, time.mins, time.sec, &date);
    /*
    ** add null terminators to blank filled strings  (this will fail
    ** if the string already uses all 32 charaters).
    */
     _VOID_ SAtrim(aud_rec->sa_ruserid, GL_MAXNAME);
     _VOID_ SAtrim(aud_rec->sa_euserid, GL_MAXNAME);
     _VOID_ SAtrim(aud_rec->sa_dbname, GL_MAXNAME);
     _VOID_ SAtrim(aud_rec->sa_userpriv, GL_MAXNAME);
     _VOID_ SAtrim(aud_rec->sa_objpriv, GL_MAXNAME);
     _VOID_ SAtrim(aud_rec->sa_objowner, GL_MAXNAME);
     _VOID_ SAtrim(aud_rec->sa_objname, GL_MAXNAME);
    /*
    ** Send the lot to TRdisplay, not all fields are displayed, just
    ** enough to get the idea
    */
    TRdisplay("%s | %s | %s | %s | %s | %s\n", &date,
	aud_rec->sa_accesstype, aud_rec->sa_eventtype, aud_rec->sa_objname, 
	aud_rec->sa_ruserid, aud_rec->sa_dbname);
    
    return (OK);
}
Example #13
0
/*
** Name: SAflush - flush buffered audit records to the OS audit trail
**
** Description:
**	This routine ensures that all buffered audits for a specific audit 
**	trail are handed to the operating system for audit, the routine should 
**	wait for all system audit calls to be completed before returning. If 
**	SAwrite() returns synchronously then this routine will be a no-op since
**	there is never anything to do. The audit trail will be identified by 
**	it's descriptor passed back from SAopen().
**
** Inputs:
**	aud_trail_d	a descriptor that identifies this audit trail
**
** Outputs:
**	err_code	pointer to a variable used to return OS errors
**
** Returns:
**	        OK              if the operation succeeded
**		SA_NOOPEN       the audit trail decsribed by this descriptor 
**				has not been opened
**		SA_BADPARAM     bad parameter values were passed to the routine
**		SA_NOSUPP       the operation is not supported by this 
**				implimentation of SA.
**		FAIL            the operation failed
**
** History:
**	11-jan-94 (stephenb)
**	    Initial creation as a stub.
**	28-feb-94 (stephenb)
**	    Updated to current SA spec.
*/
STATUS
SAflush(PTR             *aud_trail_d,
	CL_ERR_DESC     *err_code)
{
    /*
    ** Since SAwrite() just uses TRdisplay() currently, this routine
    ** has no function
    */
    /*
    ** Check that the audit trail is open, this is just a dummy check
    ** that the stub routine SAopen() has been called.
    */
    if (STcompare(((SA_DESC*)*aud_trail_d)->sa_desc, "OS"))
	return (SA_NOOPEN);

    return (OK);
}
Example #14
0
TBSTRUCT *
IItfind(RUNFRM *runf, const char *tname)
{
	register TBSTRUCT	*tb;

	if (tname == NULL)
	{
		return (NULL);
	}
	
	for (tb = runf->fdruntb; tb != NULL; tb = tb->tb_nxttb)
	{
		if (STcompare(tname, tb->tb_name) == 0)
			break;
	}
	return ((TBSTRUCT *) tb);
}		
Example #15
0
STATUS
MO_oidmap_set(i4 offset,
	   i4  luserbuf,
	   char *userbuf,
	   i4  objsize,
	   PTR object )
{
    FILE	*fp;
    STATUS	cl_stat;
    STATUS	set_stat;
    LOCATION	loc;
    char	loc_buf[ MAX_LOC ];
    char	line[ SI_MAX_TXT_REC ];
    char	*words[ 2 ];
    i4		wordcount;
    SYSTIME	new_time;
    
    NMloc( FILES, FILENAME, userbuf, &loc );
    LOcopy( &loc, loc_buf, &loc );
    cl_stat = LOlast( &loc, &new_time );

    /* If it's a new file, or old one has changed, read it */

    if( OK == cl_stat && (STcompare( userbuf, MO_oid_map ) ||
			  new_time.TM_secs > MO_map_time.TM_secs ))
    {
	STcopy( userbuf, MO_oid_map );
	MO_map_time = new_time;
	    
	cl_stat = SIfopen( &loc , ERx( "r" ), SI_TXT, (i4) SI_MAX_TXT_REC, &fp );
	if( cl_stat == OK )
	{
	    while( SIgetrec( line, (i4) SI_MAX_TXT_REC, fp ) == OK ) 
	    {
		wordcount = 2;
		STgetwords( line, &wordcount, words );
		if( words[0][0] != '#' && wordcount >= 2 )
		    cl_stat = MOset( ~0, MO_META_OID_CLASS, words[0], words[1] );

	    }
	    SIclose( fp );
	}
    }
    return( cl_stat );
}
Example #16
0
int
main( int argc, char **argv )
{
    CL_ERR_DESC err;
    PTR handle;
    PTR handle1;
    PTR handle2;
    PTR addr;
    STATUS status;
    int (*int_fcn)();
    char *(*str_fcn)();
    int int_ret;
    char *cp_ret;
    LOCATION srcfile;
    char srcbuf[MAX_LOC+1];
    LOCATION objfile;
    char objbuf[MAX_LOC+1];
    bool pristine;
    LOCATION modloc;
    char modbuf[MAX_LOC+1];
    LOCATION dlloc;
    char dlbuf[MAX_LOC+1];
    LOCATION errloc;
    char errbuf[MAX_LOC+1];
    LOCATION nameloc;
    char namebuf[MAX_LOC+1];
    char *nameptr;
    char *parms[2];
    i4  flags;
    STATUS mod2status = OK;
    
    /* find the working directory */
    NMgtAt( "IIDLDIR", &cp_ret );
    if ( cp_ret == NULL || *cp_ret == EOS )
    {
	SIprintf( "%sDLDIR not set\n", SystemVarPrefix );
	PCexit( 1 );
    }

    /* save the directory name into a larger buffer for LO */
    STcopy( cp_ret, srcbuf );

    /* initialize a LOCATION with the directory */
    LOfroms( PATH, srcbuf, &srcfile );

    /* initialize the object file LOCATION with same directory */
    LOcopy( &srcfile, objbuf, &objfile );
    LOcopy( &srcfile, modbuf, &modloc );
    LOcopy( &srcfile, dlbuf, &dlloc );
    LOcopy( &srcfile, errbuf, &errloc );
    
    /* add filenames to LOCATION */
    LOfstfile( srcs[0], &srcfile );
    LOfstfile( objs[0], &objfile );
    LOfstfile( erroutput, &errloc );
    
    /* compile with error */
#ifdef NT_GENERIC
    parms[0] = "-g";
#else NT_GENERIC
    parms[0] = "-Zi";
#endif NT_GENERIC
    parms[1] = NULL;
    status = UTcompile_ex( &srcfile, &objfile, &errloc, parms, FALSE, &pristine, &err );
    if ( status != OK )
    {
        SIprintf( "Compile error test returns: " );
        if ( status == UT_CO_FILE )
            SIprintf( 
		"\n  utcom.def file not found or II_COMPILE_DEF not set\n" );
        else if ( status == UT_CO_IN_NOT )
            SIprintf( "source file not found.\n" );
        else
            SIprintf( "%d\n", status );
        SIprintf( "Contents of error file:\n" );
        SIprintf( "------------------------------------------------------\n" );
        SIcat( &errloc, stdout );
        SIprintf( "------------------------------------------------------\n" );
        SIprintf( "\n" );
    }
    else
    {
        SIprintf( "Test of compile error returned OK.\n" );
        SIprintf( "Contents of error file:\n" );
        SIprintf( "------------------------------------------------------\n" );
        SIcat( &errloc, stdout );
        SIprintf( "------------------------------------------------------\n" );
        SIprintf( "\n" );
    }

    /* add filenames to LOCATION */
    LOfstfile( srcs[0], &srcfile );
    LOfstfile( objs[0], &objfile );

    /* do a good compile */
#ifdef NT_GENERIC
    parms[0] = "-Zi";
#else NT_GENERIC
    parms[0] = "-g";
#endif NT_GENERIC
    status = UTcompile_ex( &srcfile, &objfile, NULL, parms, FALSE, &pristine, &err );
    if ( status != OK )
    {
	SIprintf( "Error compiling module: %d\n", status );
	PCexit( 1 );
    }

    LOfstfile( srcs1[0], &srcfile );
    LOfstfile( objs1[0], &objfile );

    status = UTcompile( &srcfile, &objfile, NULL, &pristine, &err );
    if ( status != OK )
    {
	SIprintf( "Error compiling module1\n" );
	PCexit( 1 );
    }

    LOfstfile( srcs2[0], &srcfile );
    LOfstfile( objs2[0], &objfile );

    mod2status = UTcompile( &srcfile, &objfile, NULL, &pristine, &err );
    if ( mod2status != OK )
    {
	SIprintf( "Error compiling module2\n" );
	SIprintf( "This is not an error if C++ is not installed.\n" );
	SIprintf( "Skipping further processing of this module\n\n" );
    }

    /* link first module into shared library */
    if ( DLcreate( NULL, NULL, module, objs, NULL, lookups, &err) != OK )
    {
	SIprintf( "Error creating module\n" );
	PCexit( 1 );
    }

    if ( DLcreate_loc( NULL, NULL, module1, objs1, NULL, lookups1, 
		       &dlloc, NULL, &errloc, FALSE, NULL, &err) != OK )
    {
	SIprintf( "Error creating module1\n" );
	PCexit( 1 );
    }
    SIprintf( "Contents of DLcreate_loc() error file for module1:\n" );
    SIprintf( "------------------------------------------------------\n" );
    SIcat( &errloc, stdout );
    SIprintf( "------------------------------------------------------\n" );
    SIprintf( "\n" );

    if ( mod2status == OK )
    {
        if ( DLcreate_loc( NULL, NULL, module2, objs2, NULL, lookups2, 
		           &dlloc, NULL, &errloc, FALSE, "C++", &err) != OK )
        {
	    SIprintf( "Error creating module2\n" );
	    PCexit( 1 );
        }
        SIprintf( "Contents of DLcreate_loc() error file for module2:\n" );
        SIprintf( "------------------------------------------------------\n" );
        SIcat( &errloc, stdout );
        SIprintf( "------------------------------------------------------\n" );
        SIprintf( "\n" );
    }

    STcopy( module1, namebuf );
    LOfroms( FILENAME, namebuf, &nameloc );
    DLconstructloc( &nameloc, namebuf, &nameloc, &err );
    LOtos( &nameloc, &nameptr );
    SIprintf( "Full path for %s is \"%s\"\n", module1, nameptr );

    LOcopy( &dlloc, namebuf, &nameloc );
    LOfstfile( module, &nameloc );
    DLconstructloc( &nameloc, namebuf, &nameloc, &err);
    LOtos( &nameloc, &nameptr );
    SIprintf( "Full path for %s is \"%s\"\n", module, nameptr );

    /* test an error */
    SIprintf( "Testing DLprepare of non-existant module.\n" );
    if ( DLprepare((char *)NULL, "XXX", lookups, &handle, &err) == OK )
    {
	SIprintf( "Error:  returned success, should be failure.\n" );
	PCexit( 1 );
    }

    /* load the modules into the executable */
    SIprintf( "Now loading the real modules.\n" );
    if ( DLprepare((char *)NULL, module, lookups, &handle, &err) != OK )
    {
	SIprintf( "Error loading module\n" );
	PCexit( 1 );
    }
    if ( mod2status == OK &&
         DLprepare((char *)NULL, module2, lookups2, &handle2, &err) != OK )
    {
	SIprintf( "Error loading module2\n" );
	PCexit( 1 );
    }
    putenv( "IIDLDIR=XXX" );
    flags=0;
    if ( DLprepare_loc((char *)NULL, module1, lookups1, &dlloc, flags,
                       &handle1, &err) != OK )
    {
	SIprintf( "Error loading module1\n" );
	PCexit( 1 );
    }

    /* get the address of a function and test it */
    if ( DLbind(handle1, "returns_onehundred", &addr, &err) != OK )
    {
	/* "returns_onehundred" function isn't there */
	DLunload( handle, &err );
	PCexit( 1 );
    }
    int_fcn = (int (*)()) addr;
    int_ret = (*int_fcn)();
    SIprintf( "\"returns_onehundred\" returns %d\n", int_ret );
    if ( int_ret != 100 )
    {
	/* function didn't correctly return 100 */
	PCexit( 1 );
    }

    if ( mod2status == OK )
    {
        if ( DLbind(handle2, "returns_ninetynine", &addr, &err) != OK )
        {
	    SIprintf( "Error binding \"returns_ninetynine\"\n" );

	    /* "returns_ninetynine" function isn't there */
	    DLunload( handle2, &err );
	    PCexit( 1 );
        }
        int_fcn = (int (*)()) addr;
        int_ret = (*int_fcn)();
        SIprintf( "\"returns_ninetynine\" returns %d\n", int_ret );
        if ( int_ret != 99 )
        {
	    /* function didn't correctly return 99 */
	    PCexit( 1 );
        }
    }

    if ( DLbind(handle, "returns_one", &addr, &err) != OK )
    {
	/* "returns_one" function isn't there */
	DLunload( handle, &err );
	PCexit( 1 );
    }
    int_fcn = (int (*)()) addr;
    int_ret = (*int_fcn)();
    SIprintf( "\"returns_one\" returns %d\n", int_ret );
    if ( int_ret != 1 )
    {
	/* function didn't correctly return 1 */
	PCexit( 1 );
    }

    if ( DLbind(handle, "returns_zero", &addr, &err) != OK )
    {
	/* "returns_zero" function isn't there */
	DLunload( handle, &err );
	PCexit( 1 );
    }
    int_fcn = (int (*)()) addr;
    int_ret = (*int_fcn)();
    SIprintf( "\"returns_zero\" returns %d\n", int_ret );
    if ( int_ret != 0 )
    {
	/* function didn't correctly return 0 */
	PCexit( 1 );
    }

    if ( DLbind(handle, "returns_minus_one", &addr, &err) != OK )
    {
	/* "returns_minus_one" function isn't there */
	DLunload( handle, &err );
	PCexit( 1 );
    }
    int_fcn = (int (*)()) addr;
    int_ret = (*int_fcn)();
    SIprintf( "\"returns_minus_one\" returns %d\n", int_ret );
    if ( int_ret != -1 )
    {
	/* function didn't correctly return -1 */
	PCexit( 1 );
    }

    if ( DLbind(handle, "returns_string", &addr, &err) != OK )
    {
	/* "returns_string" function isn't there */
	DLunload( handle, &err );
	PCexit( 1 );
    }
    str_fcn = (char *(*)()) addr;
    cp_ret = (*str_fcn)();
    SIprintf( "\"returns_string\" returns \"%s\"\n", cp_ret );
    if ( STcompare(cp_ret, "String") != OK )
    {
	/* function didn't correctly return "String" */
	PCexit( 1 );
    }

    /* functions were called successfully, now unload the modules */
    if ( DLunload( handle, &err ) != OK )
    {
	SIprintf( "Error unloading module.\n" );
	PCexit( 1 );
    }
    if ( DLunload( handle1, &err ) != OK )
    {
	SIprintf( "Error unloading module.\n" );
	PCexit( 1 );
    }
    if ( mod2status == OK && 
         DLunload( handle2, &err ) != OK )
    {
	SIprintf( "Error unloading module2.\n" );
	PCexit( 1 );
    }

    if ( DLdelete_loc( module1, &dlloc, &err ) != OK )
    {
	SIprintf( "Error deleting module1.\n" );
	PCexit( 1 );
    }

    SIprintf( "Successfully executed.\n" );
    PCexit( 0 );
}
Example #17
0
/*{
** Name: dmfinfo	- Database information display.
**
** Description:
**
** Inputs:
**      journal_context			Pointer to DMF_JSX
**	dcb				Pointer to DCB.
**
** Outputs:
**      err_code                        Reason for error return status.
**	Returns:
**	    E_DB_OK
**	    E_DB_ERROR
**	Exceptions:
**	    none
**
** Side Effects:
**	    none
**
** History:
**      01-nov-1986 (Derek)
**          Created for Jupiter.
**	03-feb-1989 (EdHsu)
**	    Updated for online backup.
**	09-apr-1990 (Sandyh)
**	    Added inconsistency reason.
**	17-may-90 (bryanp)
**	    Display the new DUMP_DIR_EXISTS status in the database descriptor.
**      25-feb-1991 (rogerk)
**          Added check for JOURNAL_DISABLED status.  Also added some
**          comment messages for some database states.  These were added
**          for the Archiver Stability project.
**      25-mar-1991 (rogerk)
**          Added checks for NOLOGGING status and nologging inconsistency types.
**      30-apr-1991 (bryanp)
**          Support trace processing ("#x").
**      8-nov-1992 (ed)
**          remove DB_MAXNAME dependency
**	04-nov-92 (jrb)
**	    Changed "SORT" to "WORK" for multi-location sorts project.
**	30-nov-92 (robf)
**	     Add C2 security auditing.
**	14-dec-1992 (rogerk)
**	    Reduced Logging Project: Changed database inconsistent codes.
**	18-jan-1993 (rogerk)
**	    Fixed problem with reporting inconsistency codes added in last
**	    integration.  Shifted TRdisplay vector over one to get correct
**	    output.
**	24-may-1993 (jnash)
**	    Show last journaled log address in <%d:%d:%d> format.
**	20-sep-1993 (bryanp)
**	    Fix TRdisplay calls to line up properly with DB_MAX_NAME=32.
**	20-sep-1993 (jnash)
**	    Fix problem where dump information not presented.  Also include
**	    version information in infodb output.
**	14-oct-93 (jrb)
**	    Added informational line to say when the db is NOT journaled.
**	22-nov-1993 (jnash)
**	    B53797.  Apply Walt's 6.4 VMS fix where if a database never 
**	    checkpointed, INFODB AVs.  Use CL_OFFSETOF rather than zero-pointer
**          construction in TRdisplay statement.  Bug caused by compiler
**          bug when dmfinfo.c containing original expression was compiled
**          with /opt.
**      15-feb-1994 (andyw)
**          Modified dmfinfo to check for checkpoint sequence number of
**          journals and dumps instead of using DSC_CKP_INPROGRESS.
**      15-feb-1994 (andyw)
**          Modified the dump log address incorporating the standard
**          address format <a:b:c> bug reference 58553.
**	25-apr-1994 (bryanp) B62023
**	    Used CL_OFFSETOF to format and display the components of the
**		checkpoint history and dump history. The old technique using
**		casts of null pointers doesn't work on the Alpha.
**      13-Dec-1994 (liibi01)
**          Cross integration from 6.4 (Bug 56364).
**          Added new inconsistency class instance RFP_FAIL as
**          side effect of fix to bug 56364.
**      24-jan-1995 (stial01)
**          BUG 66473: display if checkpoint is table checkpoint
**      12-sep-1995 (thaju02)
**          Added routine output_tbllist().  Implementation of 
**          sending to output the contents of the checkpoint table list
**          file.
**	 6-feb-1996 (nick)
**	    Call to output_tbllist() was missing the err_code param - this
**	    caused an access violation if output_tbllist() tried to set it.
**	    Moved call to output_tbllist() to a) ensure we security audit
**	    the operation, b) ensure the checkpoint in question exists and
**	    c) the output format looks like normal 'infodb'.
**	12-mar-96 (nick)
**	    'Next table id' is actually the last one.
**	29-mar-96 (nick)
**	    Change CKP_INPROGRESS back to CKP.
**	17-may-96 (nick)
**	    Move RFP_FAIL in the TRformat().
**	28-feb-1997 (angusm)
**	    Output collation sequence defined for database. (SIR 72251)
**	07-aug-2000 (somsa01)
**	    When printing out the table list, we were incorrectly passing
**	    an argument to TRformat().
**	12-apr-2005 (gupsh01)
**	    Added support for unicode information.
[@history_template@]...
*/
DB_STATUS
dmfinfo(
DMF_JSX		    *jsx,
DMP_DCB		    *dcb,
DB_STATUS	    *err_code)
{
    DM0C_CNF		*config;
    DM0C_CNF		*cnf;
    i4		i;
    i4		length;
    DB_STATUS		status;
    DB_STATUS		local_status;
    STATUS		cl_status;
    bool                jnode_info = FALSE;
    bool		dnode_info = FALSE;
    char		line_buffer[132];
    CL_ERR_DESC         sys_err;
    SXF_ACCESS		access;
    LG_HEADER		log_hdr;


    if (jsx->jsx_status & JSX_TRACE) 
	TRset_file(TR_F_OPEN, "infodb.dbg", 10, &sys_err);

    /*	Pretend the database is exclusive. */

    dcb->dcb_status |= DCB_S_EXCLUSIVE;

    /*	Lock the database. */

    status = dm0c_open(dcb, 0, dmf_svcb->svcb_lock_list, &config,
	err_code);
    /*
    **	Make sure access is security audited.
    */
    if ( dmf_svcb->svcb_status & SVCB_C2SECURE )
    {
	access = SXF_A_SELECT;
	if (status)
	    access |= SXF_A_FAIL;
	else
	    access |= SXF_A_SUCCESS;
	
	local_status = dma_write_audit( SXF_E_DATABASE,
		    access,
		    dcb->dcb_name.db_db_name, /* Object name (database) */
		    sizeof(dcb->dcb_name.db_db_name), /* Object name (database) */
		    &dcb->dcb_db_owner, /* Object owner */
		    I_SX2711_INFODB,   /*  Message */
		    TRUE,		    /* Force */
		    err_code, NULL);

	if (local_status != E_DB_OK)
	    status=local_status;
    }

    if (status != E_DB_OK)
	return (status);
    cnf = config;

    TRformat(dmf_put_line, 0, line_buffer, sizeof(line_buffer),
	"%18*=%@ Database Information%17*=\n\n");
    if (STcompare("                                ",
		  cnf->cnf_dsc->dsc_collation)==0)
	STcopy("default", cnf->cnf_dsc->dsc_collation);
    TRformat(dmf_put_line, 0, line_buffer, sizeof(line_buffer),
	"    Database : (%~t,%~t)  ID : 0x%x  Default collation : %~t\n",
	sizeof(cnf->cnf_dsc->dsc_name), &cnf->cnf_dsc->dsc_name,
	sizeof(cnf->cnf_dsc->dsc_owner), &cnf->cnf_dsc->dsc_owner,
        cnf->cnf_dsc->dsc_dbid,
	sizeof(cnf->cnf_dsc->dsc_collation) ,&cnf->cnf_dsc->dsc_collation);

    /* Provide Unicode support information here */
    TRformat(dmf_put_line, 0, line_buffer, sizeof(line_buffer),
	"    Unicode enabled : %s\n",
	cnf->cnf_dsc->dsc_dbservice & DU_UTYPES_ALLOWED ? "Yes" : "No");

    if (cnf->cnf_dsc->dsc_dbservice & DU_UTYPES_ALLOWED)
    {	
      TRformat(dmf_put_line, 0, line_buffer, sizeof(line_buffer),
      "    Default unicode collation : %~t \t Unicode normalization : %s\n", 
	sizeof(cnf->cnf_dsc->dsc_ucollation) ,&cnf->cnf_dsc->dsc_ucollation,
        (cnf->cnf_dsc->dsc_dbservice & DU_UNICODE_NFC) ? "NFC" : "NFD");
    }

    if (jsx->jsx_status1 & JSX1_OUT_FILE)
    {
        status = output_tbllist(jsx, dcb, cnf, err_code);
    	(void)dm0c_close(cnf, 0, err_code);
        return(status);
    }

    TRformat(dmf_put_line, 0, line_buffer, sizeof(line_buffer),
	"    Extents  : %d    Last Table Id : %d\n",
	cnf->cnf_dsc->dsc_ext_count, cnf->cnf_dsc->dsc_last_table_id);
    TRformat(dmf_put_line, 0, line_buffer, sizeof(line_buffer),
	"    Config File Version Id : 0x%x   Database Version Id : %d\n", 
	cnf->cnf_dsc->dsc_cnf_version, cnf->cnf_dsc->dsc_c_version);

    /*
    ** Show mode of operation: production on | off 
    **                         online checkpoint enabled | disabled
    */
    TRformat(dmf_put_line, 0, line_buffer, sizeof(line_buffer),
	"    Mode     : DDL %s, ONLINE CHECKPOINT %s\n",
	cnf->cnf_dsc->dsc_dbaccess & DU_PRODUCTION ? "DISALLOWED" : "ALLOWED",
	cnf->cnf_dsc->dsc_dbaccess & DU_NOBACKUP ? "DISABLED" : "ENABLED");

    /*
    ** The flag is 'DSC_DUMP_DIR_EXISTS', but we report it as 'CFG_BACKUP',
    ** since its current use is to enable config file auto-backup.
    */
    TRformat(dmf_put_line, 0, line_buffer, sizeof(line_buffer),
        "    Status   : %v\n\n",
        "VALID,JOURNAL,CKP,DUMP,ROLL_FORWARD,SMINC,PART,,PRE,CFG_BACKUP,\
	JOURNAL_DISABLED,NOLOGGING",
		cnf->cnf_dsc->dsc_status);

    /*
    ** Print database status information comments.
    */

    if (!(cnf->cnf_dsc->dsc_status & DSC_VALID))
    {
        TRformat(dmf_put_line, 0, line_buffer, sizeof(line_buffer),
            "%15* The Database is Inconsistent.\n");
        TRformat(dmf_put_line, 0, line_buffer, sizeof(line_buffer),
            "%19* Cause of Inconsistency:  %w\n",
            ",REC_OPEN_FAILURE,RECOVER_ERROR,REDO_ERROR,UNDO_ERROR,OPEN_COUNT,,\
WILL_COMMIT_ERR,NOLOGGING_ERROR,NOLOGGING_OPENDB,,RFP_FAIL",
            cnf->cnf_dsc->dsc_inconst_code);  
    }
Example #18
0
STATUS
gca_ns_resolve( char *target, char *user, char *password,
		char *rem_user, char *rem_pass, GCA_RQCB *rqcb )
{
#ifdef GCF_EMBEDDED_GCN

    GCA_RQNS		*ns = &rqcb->ns;
    GCN_RESOLVE_CB	*grcb;
    char		uid[ GC_USERNAME_MAX + 1 ];
    char		*puid = uid;
    char		empty[ 1 ] = { '\0' };
    STATUS		status;
    i4			i;

    /*
    ** Allocate the embedded Name Server interface control block
    ** and save it in the request control block to provide storage
    ** for the resolved values.
    */
    if ( ! rqcb->grcb  &&  ! (rqcb->grcb = gca_alloc(sizeof(GCN_RESOLVE_CB))) )
	return( E_GC0013_ASSFL_MEM );

    grcb = (GCN_RESOLVE_CB *)rqcb->grcb;

    /*
    ** Default local username and password if required.
    ** Only use the provided info if both a username and
    ** password are provided.
    */
    IDname( &puid );
    STzapblank( uid, uid );

    if ( ! user )  user = empty;
    if ( ! password )  password = empty;

    if ( ! user[0]  ||  ! password[ 0 ] )
    {
	user = uid;
	password = empty;
    }

    /*
    ** Validate username and password if attempt is
    ** made to change the user's ID.  This would
    ** normally be done in the Name Server GCA_LISTEN.
    */
    if ( user != uid  &&  STcompare( user, uid ) )
    {
	CL_ERR_DESC sys_err;
	status = GCusrpwd( user, password, &sys_err );
	if ( status != OK )  return( status );
    }

    /*
    ** Setup input parameters to Name Database interface.
    */
    STcopy( target, grcb->target );
    STcopy( user, grcb->user );

    if ( rem_user  &&  rem_pass )
    {
	/*
	** Use the requested remote username and password.
	*/
	grcb->gca_message_type = GCN_NS_2_RESOLVE;
	STcopy( rem_user, grcb->user_in ); 
	STcopy( rem_pass, grcb->passwd_in );
    }
    else
    {
	/*
	** Use the local username and password.
	*/
	grcb->gca_message_type = GCN_NS_RESOLVE;
	STcopy( user, grcb->user_in ); 
	STcopy( password, grcb->passwd_in );
    }

    /*
    ** Call embedded Name Server to resolve the target.
    */
    if ( 
	 (status = gcn_rslv_parse( grcb ))  == OK  &&
         (status = gcn_rslv_server( grcb )) == OK  &&
         (status = gcn_rslv_node( grcb ))   == OK  &&
         (status = gcn_rslv_login( grcb ))  == OK 
       )
    {

#ifdef WIN16
   	gcpasswd_prompt(grcb->user_out, grcb->passwd_out, grcb->vnode);
#endif /* WIN16 */

	/*
	** Return resolved info.  The new partner ID should
	** have the vnode removed, but still retain the server
	** class.  We use the grcb as static storage to rebuild
	** the partner ID from the dbname and class components.
	*/
	ns->svr_class = grcb->class ? grcb->class : "";
	ns->username = grcb->user_out ? grcb->user_out : "";
	ns->password = grcb->passwd_out ? grcb->passwd_out : "";
	ns->rmt_dbname = grcb->target;

	STprintf( grcb->target, "%s%s%s", 
		  grcb->dbname ? grcb->dbname : "", 
		  ns->svr_class[0] ? "/" : "", ns->svr_class );

	for( i = 0, ns->lcl_count = grcb->catl.tupc; i < ns->lcl_count; i++ )
	    ns->lcl_addr[ i ] = grcb->catl.tupv[ i ];

	for( i = 0, ns->rmt_count = grcb->catr.tupc; i < ns->rmt_count; i++ )
	{
	    char *pv[3];

	    gcu_words( grcb->catr.tupv[ i ], NULL, pv, ',', 3 );

	    ns->node[ i ] = pv[ 0 ];
	    ns->protocol[ i ] = pv[ 1 ];
	    ns->port[ i ] = pv[ 2 ];
	}
	
	if ( ! ns->lcl_count )  status = E_GC0021_NO_PARTNER;
    }
Example #19
0
bool
rFqur_set()
{
	/* internal declarations */

	i4		sequence;		/* current seq in QUR array */
	register QUR	*qur;			/* fast ptr to QUR array */
	i4		rfq_parse_state;	/*
						** Scanning state for where
						** clause.
						*/
	i4		type;			/* Token type returned	*/
	bool		rfq_error;		/* TRUE if parse error occurs*/
	i4		ord;			/* ordinal of attribute */
	COPT		*copt;			/* Copt structure */
	char 		*qual;			/* Pointer to qualification */
	char 		*n_qual;		/*
						** Pointer to qualification
						** after skip to any parens
						** for JoinDef
						*/
	char		chk_char;		/*
						** Hold current char to check
						** for comments.
						*/
	char		rvar[FE_UNRML_MAXNAME+1];
						/* Range Var name in where */
	char		attname[FE_UNRML_MAXNAME+1];
						/* Attribute name in where */
	char		ColName[FE_MAXNAME+1];	/* RBF Internal column name */
	FE_RSLV_NAME	rfq_ferslv;		/*
						** Work struct to decompose
						** compound identifiers.
						*/


	/* start of routine */

#	ifdef	xRTR1
	if (TRgettrace(200,0))
	{
		SIprintf(ERx("rFqur_set: entry.\r\n"));
	}
#	endif


	qual = NULL;
	for (sequence = 1,qur = Ptr_qur_arr; sequence <= En_qcount;
	     qur++,sequence++)
	{	
		CVlower(qur->qur_section);
		if (STcompare(qur->qur_section,NAM_WHERE) == 0)
		{	
			_VOID_ rfNextQueryLine(&qual, qur->qur_text);
		}
	}


	/*
	** If we are here when creating a new report, we don't have 
	** any selection criteria to look for.
	*/
	if  (qual == NULL)
	{
		return(TRUE);
	}
	if  (*qual == EOS)
	{
		_VOID_ MEfree((PTR)qual);
		return(TRUE);
	}

	/*
	** If the source of data is a JoinDef, we need to skip over 
	** the part of the qualification that defines the join.  So, find
	** any open parenthesis - if none, then no selection criteria exist.
	** Otherwise, reset the qual pointer to the open parens.
	*/
	n_qual = qual;
	if  ((En_SrcTyp == JDRepSrc) &&
	     ((n_qual = STindex(qual,ERx("("),0)) == NULL))
	{
		return(TRUE);
	}

	r_g_set(n_qual);
	rfq_error = FALSE;
	rfq_parse_state = FIND_OPAREN;
	/*
	** Note that the parse state won't change until we first see
	** an open parens.
	*/
	while ((!rfq_error) && ((type = r_g_skip()) != TK_ENDSTRING))
	{
		switch(type)
		{
		case(TK_ALPHA):
		case(TK_QUOTE):
			if  (type == TK_QUOTE)
			{
				/*
				** Check for QUEL string constant first,
				** then check for disallowed delimited
				** identifier.
				*/
				if  (En_qlang == FEDMLQUEL)
				{
					_VOID_ MEfree((PTR)r_g_string(
								TK_QUOTE));
					break;
				}
				else if (!Rbf_xns_given)
				{
					rfq_error = TRUE;
					break;
				}
			}
			rfq_ferslv.name = r_g_ident(TRUE);
			/*
			** Handle the relation operator 'LIKE' if
			** that's what we're looking for.  Note that
			** for it to be a valid identifier, it would have
			** to be in quotes!
			*/
			if ((rfq_parse_state == FIND_GREATER) &&
			    (STbcompare(rfq_ferslv.name,
				       STlength(rfq_ferslv.name),
				       ERx("like"),
				       STlength(ERx("like")),TRUE) == 0))
			{
				rfq_parse_state = FIND_OPAREN;
				_VOID_ MEfree((PTR)rfq_ferslv.name);
				break;
			}
			/*
			** Handle the start of the UNION SELECT clause - 
			** it means that we're all done.  However, unless the
			** state is FIND_OPAREN, then we have an error which
			** the subsequent identifier check will catch (failed
			** for the identifier being a reserved word).  Note
			** that for it to be a valid identifier, it would have
			** to be in quotes!
			*/
			if ((rfq_parse_state == FIND_OPAREN) &&
			    (STbcompare(rfq_ferslv.name,
				       STlength(rfq_ferslv.name),
				       ERx("union"),
				       STlength(ERx("union")),TRUE) == 0))
			{
				_VOID_ MEfree((PTR)rfq_ferslv.name);
				_VOID_ MEfree((PTR)qual);
				return(TRUE);
			}
			/*
			** Keep skipping unless we're looking for an
			** identifier.  This will handle LOGICALS like
			** AND, OR, etc., as well as right side expressions.
			*/
			if  (rfq_parse_state != FIND_IDENT)
			{
				_VOID_ MEfree((PTR)rfq_ferslv.name);
				break;
			}
			rfq_ferslv.name_dest = &attname[0];
			rfq_ferslv.owner_dest = &rvar[0];
			rfq_ferslv.is_nrml = FALSE;
			FE_decompose(&rfq_ferslv);
			if  ((IIUGdlm_ChkdlmBEobject(rfq_ferslv.name_dest,
						     rfq_ferslv.name_dest,
						     rfq_ferslv.is_nrml)
					 == UI_BOGUS_ID) ||
			     ((rfq_ferslv.owner_spec) &&
			      (IIUGdlm_ChkdlmBEobject(rfq_ferslv.owner_dest,
						      rfq_ferslv.owner_dest,
						      rfq_ferslv.is_nrml)
					 == UI_BOGUS_ID)))
			{
				rfq_error = TRUE;
				_VOID_ MEfree((PTR)rfq_ferslv.name);
				break;
			}
			if (En_SrcTyp == JDRepSrc)
			{
			    if (!r_JDMaintAttrList(JD_ATT_GET_ATTR_NAME,
						   &rvar[0],&attname[0],
						   &ColName[0]))
			    {
				/*
				** Why doesn't this result in the fatal error
				** that a parse failure would?  The 6.4 version
				** would actually fail here if a UNION SELECT
				** was present and return - rFdisplay() does
				** not check the return code.  Since we now
				** handle the end of the WHERE clause in a more
				** sane manner, maybe this should be a fatal
				** error ...
				*/
				_VOID_ MEfree((PTR)rfq_ferslv.name);
				_VOID_ MEfree((PTR)qual);
				return(FALSE);
			    }
			    STcopy(&ColName[0],&attname[0]);
			}
			ord = r_mtch_att(&attname[0]);
			if (ord < 0)
			{
			    /* Bad attribute name */
			    IIUGerr(E_RF003A_rFqur_set__Bad_attrib, 
				    UG_ERR_FATAL,1,&attname[0]);
			}
			/*
			** Set the column options of the attribute.  We assume
			** its a value until/unless we find a range indicator.
			*/
			copt = rFgt_copt(ord);
			copt->copt_select = 'v';
			rfq_parse_state = FIND_GREATER;
			_VOID_ MEfree((PTR)rfq_ferslv.name);
			break;

		case(TK_OPAREN):
			CMnext(Tokchar);        /* Skip the paren	*/
			if  (rfq_parse_state == FIND_OPAREN)
			{
				rfq_parse_state = FIND_IDENT;
				break;
			}
			/*
			** Ignore open parens unless we're specifically
			** looking for them.  This handles instances of
			** min(), max(), etc.
			*/
			break;

		case(TK_CPAREN):
			CMnext(Tokchar);        /* Skip the paren	*/
			if ((rfq_parse_state == FIND_CPAREN) &&
			    (copt != (COPT *)NULL) &&
			    (copt->copt_select == 'r'))
			{
				rfq_parse_state = FIND_2CPAREN;
			    	copt = (COPT *)NULL;
				break;
			}
			if  (rfq_parse_state == FIND_2CPAREN)
			{
				rfq_parse_state = FIND_OPAREN;
				break;
			}
			/*
			** Ignore closing parens unless we're specifically
			** looking for them.  This also handles instances of
			** min(), max(), etc.
			*/
			break;

		case(TK_EQUALS):
		case(TK_RELOP):
			CMnext(Tokchar);        /* Skip the relation operator */
			/*
			** Handle '!=', '>=', '<=' compound operators
			*/
			if  (*Tokchar == '=')
			{
				CMnext(Tokchar);
			}
			if  (rfq_parse_state == FIND_GREATER)
			{
				if  (type == TK_RELOP)
				{
					/* Must be a range of values */
					copt->copt_select = 'r';
					rfq_parse_state = FIND_CPAREN;
				}
				else
				{
					rfq_parse_state = FIND_OPAREN;
				}
			}
			break;

		case(TK_SQUOTE):
			CMnext(Tokchar);
			/*
			** Handle single quoted string values atomically so
			** we don't get confused by their containing parens,
			** etc.
			*/
			_VOID_ MEfree((PTR)r_g_string(TK_SQUOTE));
			break;

		case(TK_DOLLAR):
			CMnext(Tokchar);
			/*
			** Handle variables independently from identifiers so
			** we don't get confused by something like '$like'.
			** Additionally, allow compound constructs so we don't
			** get confused by something like "$abc.columnname".
			** Note that this compound construct should only result
			** from user modifications, and is detrimental only
			** when the state is FIND_IDENT - we won't assign any
			** ColumnOptions to columnname.
			*/
			_VOID_ MEfree((PTR)r_g_ident(TRUE));
			break;

		default:
			/*
			** We should only really be here if we see the start
			** of a comment ...
			*/
			chk_char = *Tokchar;
			CMnext(Tokchar);
			if  ((chk_char == '/') && (*Tokchar == '*'))
			{
				/*
				** Note the implication that a comment may not
				** "interrupt" the WHERE clause.  If we
				** allowed one to, then we'd have to add
				** comment recognition to the entire parse
				** loop to avoid being confused!
				*/
				_VOID_ MEfree((PTR)qual);
				return(TRUE);
			}
			break;
		}
	}


	if ((rfq_error) || (rfq_parse_state != FIND_OPAREN))
	{
	    IIUGerr(E_RF003B_rFqur_set__Bad_where_,UG_ERR_FATAL,0);
	}

	_VOID_ MEfree((PTR)qual);

	return(TRUE);
}
Example #20
0
int 
main(int argc, char* argv[])
{
	time_t ltime;
	time_t tm_0, tm_1;
	char szIIdate[64];
	char szCommandLineString[1024];
	int i;
	double dtime;

	time( &tm_0 );

	g_pLoadData = (LOADDATA*)malloc (sizeof(LOADDATA));
	memset (g_pLoadData, 0, sizeof(LOADDATA));
	memset (&g_ReadSizeEvent, 0, sizeof(g_ReadSizeEvent));
	memset (&g_dataLoaderStruct, 0, sizeof (g_dataLoaderStruct));
	g_dataLoaderStruct.nArraySize = 5;
	g_dataLoaderStruct.arrayFiles = (INFILES*)malloc (g_dataLoaderStruct.nArraySize * sizeof(INFILES));
	memset (&g_mutexWrite2Log, 0, sizeof (g_mutexWrite2Log));
	szIIdate[0] = '\0';
	if (!IsInputDateCompatible(szIIdate))
	{
		if (szIIdate[0])
			DTSTRUCT_SetDateFormat(&g_dataLoaderStruct, szIIdate);
	}
	CreateDTLMutex(&g_mutexWrite2Log);

	/*
	** Construct the command line string from the argv[]
	*/
	szCommandLineString[0] = '\0';
	for (i=1; i<argc; i++)
	{
		if (i>1)
			STcat (szCommandLineString, " ");
		STcat (szCommandLineString, argv[i]);
	}
	/*
	** Parse the command line string and update the 
	** Data Loader structure:
	*/
	memset (&g_cmd, 0, sizeof (g_cmd));
	if (szCommandLineString[0])
	{
		STATUS st;
		LOCATION lf;
		char* strFle = NULL;
		int nOk = ParseCommandLine (szCommandLineString, &g_cmd);
		if (nOk == 0)
		{
			free (g_pLoadData);
			/*
			** Command line syntax error:
			*/
			SIprintf("Command line syntax error !!!\n");
			return 1;
		}
		else
		{
			/*
			** Check the MANDATORY command line:
			*/
			char* strItem = CMD_GetVnode(&g_cmd);
			if (strItem && !strItem[0])
			{
				free (g_pLoadData);
				SIprintf("Command line option missing: the connection string <vnode> is mandatory.\n");
				return 1;
			}
			strItem = CMD_GetControlFile(&g_cmd);
			if (strItem && !strItem[0])
			{
				free (g_pLoadData);
				SIprintf("Command line option missing: the control file is mandatory.\n");
				return 1;
			}
		}
		if (CMD_GetReadSize(&g_cmd) > 0)
			g_lReadSize = CMD_GetReadSize(&g_cmd);
		/*
		** Create the log file if needed:
		*/
		strFle = CMD_GetLogFile(&g_cmd);
		if (!strFle || !strFle[0])
		{
			char szBuff[1024];
			char* pFound;
			STcopy (CMD_GetControlFile(&g_cmd), szBuff);
			pFound = STrindex (szBuff, ".ctl", -1);
			if (pFound && (STlength (pFound) == 4) && STcompare(pFound, ".ctl") == 0)
			{
				pFound[0] = '\0';
				STcat (szBuff, ".log");
				CMD_SetLogFile(&g_cmd, szBuff);
			}
		}
		else
		{
			char szBuff[1024];
			char* pFound;
			STcopy (CMD_GetLogFile(&g_cmd), szBuff);
			pFound = STrindex (szBuff, ".", -1);
			if (!pFound) /* if logfile has no extension then add a .log extension */
			{
				STcopy (strFle, szBuff);
				STcat  (szBuff, ".log");
				CMD_SetLogFile(&g_cmd, szBuff);
			}
		}

		LOfroms (PATH&FILENAME, strFle, &lf);
		st = SIfopen (&lf, "w", SI_TXT, DT_SI_MAX_TXT_REC, &g_fLogFile);
		if (st != OK)
		{
			g_fLogFile = NULL;
			SIprintf ("Failed to create log file\n");
		}

		time( &ltime );
		WRITE2LOG3("%s: Release %s - Production on %s\n\n", INGRES_DATA_LOADER, g_sVersion, ctime(&ltime));
		WRITE2LOG0("Copyright (C) 2005-2006 Ingres Corporation. All Rights Reserved.\n\n");
		WRITE2LOG1("Control File:\t%s\n", CMD_GetControlFile(&g_cmd));
		if (!g_mutexWrite2Log.nCreated)
		{
			E_WRITE2LOG1("%s: Failed to create the Mutex 'g_mutexWrite2Log' for writing log file\n", INGRES_DATA_LOADER);
			CleanVariables();
			return 1;
		}
		nOk = ParseControlFile(&g_dataLoaderStruct, &g_cmd);
		if (nOk == 0)
		{
			E_WRITE2LOG1("%s: Syntax error in the control file.\n", INGRES_DATA_LOADER);
			CleanVariables();
			return 1;
		}
		else
		if (nOk == -1)
		{
			E_WRITE2LOG1("%s: Cannot open control file.\n", INGRES_DATA_LOADER);
			CleanVariables();
			return 1;
		}
		else
		{
			int i;
			int nErrorAccesInfile=0;
			int nAllwithPosition=1;
			int nWithPosition = 0;
			int nPosError = 0;
			int nMax=0;
			int nWrongSep = 0;
			FIELDSTRUCT* pField = &(g_dataLoaderStruct.fields);
			FIELD* listField = pField->listField;
			int* aSet = GetControlFileMandatoryOptionSet();
			if (aSet[0] == 0)
			{
				E_WRITE2LOG1("%s: LOAD DATA is mandatory at the begining of the control file.\n", INGRES_DATA_LOADER);
				CleanVariables();
				return 1;
			}

			if (aSet[1] == 0 || !DTSTRUCT_GetInfile(&g_dataLoaderStruct, 0))
			{
				E_WRITE2LOG1("%s: INFILE is mandatory in the control file.\n", INGRES_DATA_LOADER);
				CleanVariables();
				return 1;
			}
			for (i=0; i<g_dataLoaderStruct.nFileCount; i++)
			{
				strFle = DTSTRUCT_GetInfile(&g_dataLoaderStruct, i);
				if (access(strFle, 0) == -1)
				{
					nErrorAccesInfile = 1;
					E_WRITE2LOG2("%s: INFILE '%s' cannot be accessed.\n", INGRES_DATA_LOADER, strFle);
				}
			}
			if (nErrorAccesInfile == 1)
			{
				CleanVariables();
				return 1;
			}

			if (aSet[5] == 0 || STlength (DTSTRUCT_GetTable(&g_dataLoaderStruct)) == 0)
			{
				E_WRITE2LOG1("%s: INTO TABLE <table>, a table name is mandatory in the control file.\n", INGRES_DATA_LOADER);
				CleanVariables();
				return 1;
			}

			if (aSet[6] == 0)
			{
				E_WRITE2LOG1("%s: APPEND key word is mandatory in the control file.\n", INGRES_DATA_LOADER);
				CleanVariables();
				return 1;
			}

			if (aSet[8] == 0)
			{
				E_WRITE2LOG1("%s: The table columns must be specified in the control file.\n", INGRES_DATA_LOADER);
				CleanVariables();
				return 1;
			}
			if (g_dataLoaderStruct.fields.szTerminator[0] && g_dataLoaderStruct.fields.szTerminator[0] == '\n')
				nWrongSep = 1;
			if (listField)
			{
				int p1 = 0, p2 = 0;
				while (listField)
				{
					if (listField->szTerminator[0] && strcmp (listField->szTerminator, "\\n") == 0)
						nWrongSep = 1;
					if (listField->pos1 <= p2)
						nPosError = 1;
					p1 = listField->pos1;
					p2 = listField->pos2;
					if (listField->pos1 <= 0 || listField->pos2 <= 0)
						nPosError = 1;
					if (listField->pos1 > listField->pos2 )
						nPosError = 1;
					if (listField->pos2 > nMax)
						nMax = listField->pos2;
					if (listField->pos1 == 0 && listField->pos2 == 0)
					{
						listField = listField->next;
						nAllwithPosition = 0;
						continue;
					}

					nWithPosition = 1;
					listField = listField->next;
				}
			}
			if (nWrongSep == 1)
			{
				E_WRITE2LOG1("%s: You should not use the '\\n' as field separator.\n", INGRES_DATA_LOADER);
				CleanVariables();
				return 1;
			}
			for (i=0; i<g_dataLoaderStruct.nFileCount; i++)
			{
				int j;
				if ((i>0) && (DTSTRUCT_GetFixLength(&g_dataLoaderStruct, 0) != DTSTRUCT_GetFixLength(&g_dataLoaderStruct, i)))
				{
					E_WRITE2LOG1("%s: FIX n, fixed record length must be the same for all INFILE clauses.\n", INGRES_DATA_LOADER);
					CleanVariables();
					return 1;
				}
				/*
				** Check if there are multiple bad files with the same name:
				*/
				for (j=i+1; j<g_dataLoaderStruct.nFileCount;j++)
				{
					if (stricmp (g_dataLoaderStruct.arrayFiles[i].badfile, g_dataLoaderStruct.arrayFiles[j].badfile)==0)
					{
						E_WRITE2LOG1("%s: Multiple bad files with the same name. You should specify different BADFILE for each INFILE.\n", INGRES_DATA_LOADER);
						CleanVariables();
						return 1;
					}
				}
			}
			if (DTSTRUCT_GetFixLength(&g_dataLoaderStruct, 0) > 0)
			{
				if (nWithPosition && !nAllwithPosition)
				{
					E_WRITE2LOG1("%s: FIX n, fixed record length is specified, if you use POSITION (n, p) then all columns must use the POSITION.\n", INGRES_DATA_LOADER);
					CleanVariables();
					return 1;
				}
				if (nPosError == 1)
				{
					E_WRITE2LOG1("%s: If you use POSITION (n, p) then n, p should be > 0.\n", INGRES_DATA_LOADER);
					CleanVariables();
					return 1;
				}

				if (nMax > DTSTRUCT_GetFixLength(&g_dataLoaderStruct, 0))
				{
					E_WRITE2LOG1("%s: In the last POSITION (n, p), p should be <= FIX value.\n", INGRES_DATA_LOADER);
					CleanVariables();
					return 1;
				}
			}
			else
			{
				if (nWithPosition == 1)
				{
					E_WRITE2LOG1("%s: If you use POSITION (n, p) then you should also specify FIX value.\n", INGRES_DATA_LOADER);
					CleanVariables();
					return 1;
				}
			}

			if (FIELDSTRUCT_GetColumnCount (pField) <= 0)
			{
				E_WRITE2LOG1("%s: The list of columns should be specified.\n", INGRES_DATA_LOADER);
				CleanVariables();
				return 1;
			}
		}

		for (i=0; i<g_dataLoaderStruct.nFileCount; i++)
		{
			WRITE2LOG1("Data File:\t%s\n", DTSTRUCT_GetInfile(&g_dataLoaderStruct, i));
			if (DTSTRUCT_GetFixLength(&g_dataLoaderStruct, i) > 0)
				WRITE2LOG1("  File processing option string: \"fix %d\"\n", DTSTRUCT_GetFixLength(&g_dataLoaderStruct, i));
			WRITE2LOG1("  Bad File:\t%s\n", DTSTRUCT_GetBadfile(&g_dataLoaderStruct, i));
			if (DTSTRUCT_GetDiscardFile(&g_dataLoaderStruct, i))
				WRITE2LOG1("  Discard File:\t%s\n", DTSTRUCT_GetDiscardFile(&g_dataLoaderStruct, i));
			}
		WRITE2LOG1(" (Allow %d discards)\n", DTSTRUCT_GetDiscardMax(&g_dataLoaderStruct));

		WRITE2LOG0("\n\n");
		WRITE2LOG1("Table %s\n", DTSTRUCT_GetTable(&g_dataLoaderStruct));
		WRITE2LOG0("Insert option in effect for this table: APPEND\n");
		
		/*
		WRITE2LOG1("Load to Table:\t%s\n", DTSTRUCT_GetTable(&g_dataLoaderStruct));
		WRITE2LOG1("Read Size:\t%d\n", g_lReadSize);
		WRITE2LOG1("Parallel:\t%c\n", (CMD_GetParallel(&g_cmd) == 1)? 'Y': 'N');
		*/
		if (!CheckForKnownDateFormat())
			E_WRITE2LOG1("%s: The setting value of II_DATE_FORMAT is unknown.\n", INGRES_DATA_LOADER);

		memset (&g_mutexLoadData, 0, sizeof (DTLMUTEX));
		if (!CreateDTLMutex(&g_mutexLoadData))
		{
			E_WRITE2LOG1("%s: Failed to create the Mutex 'g_mutexLoadData'\n", INGRES_DATA_LOADER);
			CleanVariables();
			return 1;
		}
		if (!CreateReadsizeEvent(&g_ReadSizeEvent))
		{
			E_WRITE2LOG1 ("%s: Failed to create the Readsize Condition 'g_ReadSizeEvent'\n", INGRES_DATA_LOADER);
			CleanVariables();
			return 1;
		}

		/*
		** Create the session:
		*/
		nOk = INGRESII_llConnectSession(CMD_GetVnode(&g_cmd));
		if (nOk == 0) /* SQL Error */
		{
			char* strError = INGRESII_llGetLastSQLError();
			if (strError && strError[0])
				/* Error while connecting to the DBMS:*/
				WRITE2LOG0(strError);
			CleanVariables();
			return 1;
		}

		for (i=0; i<g_dataLoaderStruct.nFileCount; i++)
		{
			/*
			** Start the thread that reads the input data file and
			** puts the data in the FIFO queue:
			*/
			StartInputReaderThread(&g_dataLoaderStruct);

			/*
			** The main thread begins a loop reading the data
			** from the FIFO queue, transfer the data to the DBMS by
			** using the COPY INTO callback program:
			*/
			nOk = StartTransferDataThread(&g_dataLoaderStruct);
			if (nOk == 0) /* SQL Error */
			{
				char* strError = INGRESII_llGetLastSQLError();
				if (strError && strError[0])
					WRITE2LOG0 (strError);
			}
			g_dataLoaderStruct.nCurrent++;
			memset (g_pLoadData, 0, sizeof(LOADDATA));
		}
		nOk = INGRESII_llDisconnectSession(1, 1);
		if (nOk == 0) /* SQL Error */
		{
			char* strError = INGRESII_llGetLastSQLError();
			if (strError && strError[0])
				WRITE2LOG0 (strError);
		}
	}
	else
	{
		SIprintf("Usage: \tdataldr [vnode::]dbname[/serverclass] control=controlfile\n");
		SIprintf("\t[log=logfile][parallel=y] [direct=y] [readsize=value]");
	}

	time( &tm_1 );
	dtime = difftime (tm_1, tm_0);

	WRITE2LOG0("\n\n");
	WRITE2LOG1("Run began on %s",   ctime(&tm_0));
	WRITE2LOG1("Run ended on %s\n", ctime(&tm_1));
	WRITE2LOG0("\n\n");

	Time2Chars(dtime, szIIdate);
	WRITE2LOG1("Elapsed time was:    %s\n", szIIdate);
	STcopy ("00:00:00", szIIdate);
	if ((g_lCpuEnded - g_lCpuStarted) >= 0)
	{
		double ds = 0.0, d1;
		int lms = g_lCpuEnded - g_lCpuStarted;
		while (lms >=1000)
		{
			lms -= 1000;
			ds += 1.0;
		}
		d1 = (double)lms / 10.0; /* 1/100 s == 10 ms */
		d1 = d1 / 100.0;         /* into the seconds */
		ds += d1;
		Time2Chars(ds, szIIdate);
	}
	WRITE2LOG1("CPU time was:        %s\n", szIIdate);

	/*
	** Free the structure before exiting:
	*/
	CleanVariables();
	return 0;
}
Example #21
0
/*
** Name: GClanman_async_thread
** Description:
**	This thread handles all the asynchronous I/O for a protocol driver.
** 	It will be woken up when GClanman() places a request on it's input
**	Q.  Then, this thread will move the request from the input Q to its
**	processing Q and continue to process the request until complete.
**	When complete, the request is finally moved to the completion
**	Q.
** History:
**	04-Nov-93 (edg)
**	    Written.
**	29-jun-2000 (somsa01)
**	    Use GCc_listen_port for the server ncb_name. Also, make sure
**	    that we update GCc_client_name if we need a unique one.
**      06-Aug-2009 (Bruce Lunsford) Sir 122426
**	    Since _beginthreadex() is now used to start this thread,
**	    use _endthreadex() to end it.
*/
VOID
GClanman_async_thread( VOID * parms)
{
	int             status = OK;
	char            callname[NCBNAMSZ+1];
	DWORD		wait_stat;
	HANDLE		hSave;
	int		processing_requests = 0;
	int		pending_requests = 0;
	QUEUE		*q;
	SECURITY_ATTRIBUTES sa;

	iimksec (&sa);

	GCTRACE(4)("LMAN THREAD: started.\n");
top:
	/*
	** Wait for a request to come in from the primary gcc thread....
	*/

	GCTRACE(4)("LMAN THREAD: waiting for event ... \n");

	wait_stat = WaitForSingleObject( hEventThreadInQ, INFINITE );

	GCTRACE(3)("LMAN THREAD: wait returned %d, handle = %d\n", 
		    wait_stat, hEventThreadInQ );

	/*
	** If wait failed, chances are it's a major hosure.  Continue on any
	** way -- there's a possibility that something useful may get done.
	*/
	if (wait_stat == WAIT_FAILED)
	{
	    GCTRACE(1)("LMAN THREAD: wait failed %d\n", 
	    		GetLastError() );
	}

	/*
	** Now get get the incoming requests and add up how many requests
	** we're processing.
	*/
	processing_requests = GCget_incoming_reqs( Tptr, hMutexThreadInQ );

	GCTRACE(2)("LMAN THREAD: Got %d new requests to process\n",
		    processing_requests);

	/*
	** Loop until there's no more requests being processed.
	*/
	while( processing_requests )
	{
            pending_requests = 0;
	    /*
	    ** Now loop thru the inprocess request list.
	    */
	    for ( q = Tptr->process_head.q_next;
	    	  q != &Tptr->process_head;
		  q = q->q_next )
	    {
	        REQUEST_Q *rq = (REQUEST_Q *)q;
		GCC_P_PLIST *parm_list = rq->plist;
		PCB *pcb = (PCB *)parm_list->pcb;

		parm_list->generic_status = OK;
		CLEAR_ERR(&parm_list->system_status);

		switch (parm_list->function_invoked) 
		{

		    /******************************************************
		    ** Handle CONNECT
		    *******************************************************/
		    case GCC_CONNECT:

		    GCTRACE(4)("LMAN THREAD: process CONNECT\n");
		    if ( pcb == NULL || pcb->state.conn == INITIAL )
		    {
		        GCTRACE(3)("LMAN THREAD: initial CONNECT\n");
		        /*
			** Allocate the protocol control block.
			*/
		  	pcb = (PCB *) malloc( sizeof(PCB) );
		    	parm_list->pcb = (char *)pcb;
			if (pcb == NULL) 
			{
			    status = errno;
			    SETWIN32ERR(&parm_list->system_status, status, ER_alloc);
			    pcb->state.conn = COMPLETED;
			    parm_list->generic_status = GC_CONNECT_FAIL;
			    break;
		   	}
			memset( pcb, 0, sizeof( *pcb ) );
		        GCTRACE(3)("LMAN THREAD: CONNECT allocated pcb\n");
			/*
			** Create send/recv event handles for ncb.
			*/
    			if ((pcb->s_ncb.ncb_event = 
				CreateEvent( &sa, TRUE, FALSE, NULL ))== NULL)
    			{
        		    status = GetLastError();
			    pcb->state.conn = COMPLETED;
			    SETWIN32ERR(&parm_list->system_status, status, ER_create);
			    parm_list->generic_status = GC_CONNECT_FAIL;
			    break;
    		        }
       		 	if ((pcb->r_ncb.ncb_event = 
				CreateEvent( &sa, TRUE, FALSE, NULL ))== NULL)
    			{
        		    status = GetLastError();
			    CloseHandle( pcb->s_ncb.ncb_event );
			    pcb->state.conn = COMPLETED;
			    SETWIN32ERR(&parm_list->system_status, status, ER_create);
			    parm_list->generic_status = GC_CONNECT_FAIL;
			    break;
    			}
		        GCTRACE(3)("LMAN THREAD: CONNECT created events\n");

			pcb->state.conn = INITIAL;

		    } /* end if pcb NULL */

		    /*
		    ** If the PCB state is not INITIAL, just break because
		    ** we're just waiting for connect to complete.
		    */
		    if ( pcb->state.conn != INITIAL )
		        break;

		    /*
		    ** Use the send ncb in pcb for the connect -- add name.
		    */
		    pcb->s_ncb.ncb_command = NCBADDNAME;
		    pcb->s_ncb.ncb_buffer = Dummy_Buf;
		    pcb->s_ncb.ncb_length = sizeof(Dummy_Buf);
		    pcb->s_ncb.ncb_lana_num = lana_num;

		    for (;;)
		    {
			STprintf( GCc_client_name, "%s%-d", 
				  MyName, GCc_client_count++ );
			STcopy( GCc_client_name, pcb->s_ncb.ncb_name );

			GCTRACE(3)("LMAN THREAD: CONNECT doing ADDNAME %s\n",
				   pcb->s_ncb.ncb_name );

			/*
			** Copy to local NCB struct -- Netbios seems to fark
			** up if we don't.
			*/
			memcpy( &Name_Ncb, &pcb->s_ncb, sizeof( Name_Ncb ) );

			Netbios( &Name_Ncb );

			if (Name_Ncb.ncb_retcode == NRC_GOODRET)
			    break;
			else if (Name_Ncb.ncb_retcode == NRC_DUPNAME)
			    continue;
			else
			{
			    status = (STATUS)Name_Ncb.ncb_retcode;
			    CloseHandle( Name_Ncb.ncb_event );
			    pcb->s_ncb.ncb_event = NULL;
			    CloseHandle( pcb->r_ncb.ncb_event );
			    pcb->r_ncb.ncb_event = NULL;
			    pcb->state.conn = COMPLETED;
			    SETWIN32ERR(&parm_list->system_status, status,
					ER_netbios);
			    parm_list->generic_status = GC_CONNECT_FAIL;
			    break;
			}
		    }

		    if (parm_list->generic_status == GC_CONNECT_FAIL)
			break;

		    /*
		    ** just in case ...
		    */
		    ResetEvent( pcb->s_ncb.ncb_event );

		    /*
		    ** OK, now make the call
		    */
		    hSave = pcb->s_ncb.ncb_event;    /* save handle */
		    memset( &pcb->s_ncb, 0, sizeof(NCB) );
		    pcb->s_ncb.ncb_event = hSave;    /* restore handle */
		    pcb->s_ncb.ncb_buffer = parm_list->buffer_ptr;    
		    pcb->s_ncb.ncb_length = (WORD)parm_list->buffer_lng;    
		    pcb->s_ncb.ncb_command = NCBCALL | ASYNCH;
		    pcb->s_ncb.ncb_lana_num = lana_num;
		    STcopy( GCc_client_name, pcb->s_ncb.ncb_name );
		    STpolycat( 3, parm_list->function_parms.connect.node_id,
		    	       "_", parm_list->function_parms.connect.port_id,
			       callname );
		    CVupper( callname );

		    
		    /*
		    ** Loopback check to prevent mangling the name (?)
		    */
		    if ( STcompare( parm_list->function_parms.connect.port_id,
		    		    GCc_listen_port ) == 0 )
		    {
		        STcopy( GCc_listen_port, pcb->s_ncb.ncb_callname );
		    }
		    else
		    {
		        STcopy( callname, pcb->s_ncb.ncb_callname );
		    }

		    GCTRACE(3)("LMAN THREAD: CONNECT doing CALL to %s\n",
		    		pcb->s_ncb.ncb_callname );

		    if ( Netbios( &pcb->s_ncb ) != NRC_GOODRET )
		    {
		        status = (STATUS)pcb->s_ncb.ncb_retcode;
			CloseHandle( pcb->s_ncb.ncb_event );
			pcb->s_ncb.ncb_event = NULL;
			CloseHandle( pcb->r_ncb.ncb_event );
			pcb->r_ncb.ncb_event = NULL;
			pcb->state.conn = COMPLETED;
			SETWIN32ERR(&parm_list->system_status, status, ER_netbios);
			parm_list->generic_status = GC_CONNECT_FAIL;
			break;
		    }

		    GCTRACE(3)("LMAN THREAD: Async CALL OK\n" );

		    pcb->state.conn = COMPLETING;

		    break;


		    /*******************************************************
		    ** Handle SEND
		    *******************************************************/
		    case GCC_SEND:

		    GCTRACE(4)("LMAN THREAD: process SEND\n");

		    if ( pcb->state.send != INITIAL )
		    {
		        break;
		    }
		    pcb->s_ncb.ncb_buffer = parm_list->buffer_ptr;    
		    pcb->s_ncb.ncb_length = (WORD)parm_list->buffer_lng;    
		    pcb->s_ncb.ncb_lana_num = lana_num;
		    pcb->s_ncb.ncb_command = NCBSEND | ASYNCH;
		    if ( Netbios( &pcb->s_ncb ) != NRC_GOODRET )
		    {
		        status = (STATUS)pcb->s_ncb.ncb_retcode;
			pcb->state.send = COMPLETED;
			SETWIN32ERR(&parm_list->system_status, status, ER_netbios);
			parm_list->generic_status = GC_SEND_FAIL;
		    }

		    pcb->state.send = COMPLETING;

		    break;


		    /*******************************************************
		    ** Handle RECEIVE
		    *******************************************************/
		    case GCC_RECEIVE:

		    GCTRACE(4)("LMAN THREAD: process RECEIVE\n");

		    if ( pcb->state.recv != INITIAL )
		    {
                        pending_requests++;
		        break;
		    }
		    pcb->r_ncb.ncb_buffer = parm_list->buffer_ptr;    
		    pcb->r_ncb.ncb_length = (WORD)parm_list->buffer_lng;    
		    pcb->r_ncb.ncb_lana_num = lana_num;
		    pcb->r_ncb.ncb_command = NCBRECV | ASYNCH;

		    if ( Netbios( &pcb->r_ncb ) != NRC_GOODRET )
		    {
		        status = (STATUS)pcb->r_ncb.ncb_retcode;
			pcb->state.recv = COMPLETED;
			SETWIN32ERR(&parm_list->system_status, status, ER_netbios);
			parm_list->generic_status = GC_RECEIVE_FAIL;
		    }

		    pcb->state.recv = COMPLETING;

		    break;

		    /*******************************************************
		    ** Handle DISCONNECT
		    *******************************************************/
		    case GCC_DISCONNECT:

		    GCTRACE(4)("LMAN THREAD: process DISCONNECT\n");

		    if ( pcb && pcb->state.disc == INITIAL ) 
		    {
		        pcb->s_ncb.ncb_buffer = parm_list->buffer_ptr;    
		        pcb->s_ncb.ncb_length = (WORD)parm_list->buffer_lng;    
		        pcb->s_ncb.ncb_command = NCBHANGUP | ASYNCH;
		    	pcb->s_ncb.ncb_lana_num = lana_num;
			if ( pcb->s_ncb.ncb_lsn == 0 )
			    pcb->s_ncb.ncb_lsn = pcb->r_ncb.ncb_lsn;
		        if ( Netbios( &pcb->s_ncb ) != NRC_GOODRET )
		        {
		            status = (STATUS)pcb->s_ncb.ncb_retcode;
		    	    pcb->state.disc = COMPLETED;
			    SETWIN32ERR(&parm_list->system_status, status, ER_netbios);
			    parm_list->generic_status = GC_DISCONNECT_FAIL;
			    break;
		        }
		        pcb->state.disc = COMPLETING;
		    }

		    break;

		} /* end switch */

	    } /* end for process q loop */

	    /*
	    ** Now go thru the inprocess Q and look for any requests that
	    ** have been completed.  This will be indicated by one of:
	    ** parm_list->pcb == NULL (bad connect or after disconnect) or
	    ** pcb->state == COMPLETED, or WaitForSingleObject indicates
	    ** completion.
	    */

	    GCTRACE(4)("LMAN THREAD: processing completed. . . \n");

	    q = Tptr->process_head.q_next;
	    while( q != &Tptr->process_head )
	    {
	        REQUEST_Q *rq = (REQUEST_Q *)q;
	        GCC_P_PLIST *pl = rq->plist;
		PCB *pcb = (PCB *)pl->pcb;
		bool completed = FALSE;

		switch ( pl->function_invoked )
		{
		    case GCC_CONNECT:
		        if ( pcb == NULL || pcb->state.conn == COMPLETED || 
			     WaitForSingleObject( pcb->s_ncb.ncb_event, 0) ==
			         WAIT_OBJECT_0 )
			{
			    if (pcb) 
			    {
			        ResetEvent( pcb->s_ncb.ncb_event );
			        pcb->r_ncb.ncb_lsn = pcb->s_ncb.ncb_lsn;
				if ( pcb->s_ncb.ncb_lsn == 0 ||
				     pcb->s_ncb.ncb_retcode != NRC_GOODRET )
				{
				    pl->generic_status = GC_CONNECT_FAIL;
				    status = (STATUS)pcb->s_ncb.ncb_retcode;
				    SETWIN32ERR( &pl->system_status, status , ER_revent);
				    CloseHandle( pcb->s_ncb.ncb_event );
				    CloseHandle( pcb->r_ncb.ncb_event );
				    free( pcb );
				    pl->pcb = NULL;
				}
			    }

			    completed = TRUE;
			}
		        break;
		    case GCC_SEND:
		        if ( pcb == NULL || pcb->state.send == COMPLETED || 
			     WaitForSingleObject( pcb->s_ncb.ncb_event, 0) ==
			         WAIT_OBJECT_0 )
			{
			    ResetEvent( pcb->s_ncb.ncb_event );
			    if ( pcb->s_ncb.ncb_lsn == 0 ||
			         pcb->s_ncb.ncb_retcode != NRC_GOODRET )
			    {
				    pl->generic_status = GC_SEND_FAIL;
				    status = (STATUS)pcb->s_ncb.ncb_retcode;
				    SETWIN32ERR( &pl->system_status, status , ER_revent);
			    }
			    else
			    {
			        GCTRACE(2)(
				"LMAN THREAD: Send COMP pl len %d pcb len %d\n",
			            pl->buffer_lng, pcb->s_ncb.ncb_length);
					
			        pl->buffer_lng = pcb->s_ncb.ncb_length;
			    }
			    completed = TRUE;
			}
		        break;
		    case GCC_RECEIVE:
		        if ( pcb == NULL || pcb->state.recv == COMPLETED || 
			     WaitForSingleObject( pcb->r_ncb.ncb_event, 0) ==
			         WAIT_OBJECT_0 )
			{
			    ResetEvent( pcb->r_ncb.ncb_event );
			    if ( pcb->s_ncb.ncb_lsn == 0 ||
			         pcb->r_ncb.ncb_retcode != NRC_GOODRET )
			    {
				    pl->generic_status = GC_RECEIVE_FAIL;
				    status = (STATUS)pcb->r_ncb.ncb_retcode;
				    SETWIN32ERR( &pl->system_status, status , ER_revent);
			    }
			    else
			    {
			        pl->buffer_lng = pcb->r_ncb.ncb_length;
			    }
			    completed = TRUE;
			}
		        break;
		    case GCC_DISCONNECT:
		        if ( pcb == NULL || pcb->state.disc == COMPLETED || 
			     WaitForSingleObject( pcb->s_ncb.ncb_event, 0) ==
			         WAIT_OBJECT_0 )
			{
			    if (pcb) 
			    {
				if ( pcb->s_ncb.ncb_lsn == 0 ||
				     pcb->s_ncb.ncb_retcode != NRC_GOODRET )
				{
				    pl->generic_status = GC_DISCONNECT_FAIL;
				    status = (STATUS)pcb->s_ncb.ncb_retcode;
				    SETWIN32ERR( &pl->system_status, status , ER_revent);
				}
				pcb->s_ncb.ncb_command = NCBDELNAME;
				Netbios( &pcb->s_ncb );
				CloseHandle( pcb->s_ncb.ncb_event );
				CloseHandle( pcb->r_ncb.ncb_event );
				free( pcb );
				pl->pcb = NULL;
			    }
			    completed = TRUE;
			}
		        break;
		} /* end switch */

		if ( completed )
		{
		    QUEUE *nq = q->q_next;

	    	    GCTRACE(3)("LMAN THREAD:  Complete! PCB = %x PARM = %x \n",
		    		pcb, pl);

		    GCcomplete_request( q );

		    q = nq;
		    processing_requests--;

	    	    GCTRACE(3)("LMAN THREAD: processed completed \n");
	    	    GCTRACE(3)("                 : total now = %d \n",
		    		processing_requests);

		} /* end if req completed */
		else
		{
		    q = q->q_next;
		}

	    } /* end for -- look for complete req */

	    /*
	    ** Do a quick, non-blocking check to see if any new requests
	    ** came in during processing.
	    */
	    GCTRACE(4)("LMAN THREAD: quick look for new reqs \n");
	    if ( WaitForSingleObject( hEventThreadInQ, 0 ) == WAIT_OBJECT_0 )
	    {
		processing_requests += GCget_incoming_reqs( Tptr, 
					   hMutexThreadInQ );
	    }
	    GCTRACE(4)("LMAN THREAD: process reqs now = %d\n",
	    		processing_requests);

            if (processing_requests && pending_requests == processing_requests)
            {
                i4 Sleeptime = 1;
                Sleep(Sleeptime);
            }

	} /* end while processing requests */

	if (In_Shutdown)
	{
		_endthreadex(0);
		return;
	}

	/*
	** we're done for now, go back to the top and sleep.
	*/
	GCTRACE(3)("LMAN THREAD: No more reqs, going back to top\n" );
	goto top;
}
Example #22
0
/*
** Name: GClanman_init
** Description:
**	LANMAN inititialization function.  This routine is called from
**	GCpinit() -- the routine GCC calls to initialize protocol drivers.
**
**	This function does initialization specific to the protocol:
**	    Creates Events and Mutex's for the protocol
**	    Finds and saves a pointer to it's input event Q.
**	    Fires up the thread which will do asynch I/O
** History:
**	11-Nov-93 (edg)
**	    created.
**      15-jul-95 (emmag)
**          Use a NULL Discretionary Access Control List (DACL) for
**          security, to give implicit access to everyone.
**	23-Feb-1998 (thaal01)
**	    Make space for port_id, stops gcc crashing on startup, sometimes.
**	13-may-2004 (somsa01)
**	    Updated config.dat string used to retrieve port information such
**	    that we do not rely specifically on the GCC port.
**	06-Aug-2009 (Bruce Lunsford)  Sir 122426
**	    Change arglist pointer in _beginthreadex for async_thread from
**	    uninitialized "dummy" to NULL to eliminate compiler warning
**	    and possible startup problem.
*/
STATUS
GClanman_init(GCC_PCE * pptr)
{

	char            *ptr, *host, *server_id, *port_id;
	char		config_string[256];
	char            buffer[MAX_COMPUTERNAME_LENGTH + 1];
	int 		real_name_size = MAX_COMPUTERNAME_LENGTH + 1;
	i4		i;
	int		tid;
	HANDLE		hThread;
	int		status;
	SECURITY_ATTRIBUTES sa;
	char		port_id_buf[8];

	port_id = port_id_buf;

	iimksec (&sa);

	/*
	** Look for trace variable.
	*/
	NMgtAt( "II_LANMAN_TRACE", &ptr );
	if ( !(ptr && *ptr) && PMget("!.lanman_trace_level", &ptr) != OK )
	{
	    GCLANMAN_trace = 0;
	}
	else
	{
	    GCLANMAN_trace = atoi( ptr );
	}

	/*
	** Create MUTEX and EVENT for the input queue of this protocol
	** driver.
	*/
	if ( ( hMutexThreadInQ = CreateMutex(&sa, FALSE, NULL) ) == NULL )
	{
	    return FAIL;
	}

	GCTRACE(3)( "GClanman_init: MutexInQ Handle = %d\n", hMutexThreadInQ );

	if ( ( hEventThreadInQ = CreateEvent(&sa, FALSE, FALSE, NULL)) == NULL )
	{
	    CloseHandle( hMutexThreadInQ );
	    return FAIL;
	}

	GCTRACE(3)( "GClanman_init: EventInQ Handle = %d\n", hEventThreadInQ );
	

	GCTRACE(4)( "Start GClanman_init\n" );

        /*
        ** Get set up for the PMget call.
        */
        PMinit();
        if( PMload( NULL, (PM_ERR_FUNC *)NULL ) != OK )
                PCexit( FAIL );

	/*
	** Construct the network port identifier. 
	*/

        host = PMhost();
	server_id = PMgetDefault(3);
 	if (!server_id)
 		server_id = "*" ;
        STprintf( config_string, ERx("!.lanman.port"),
                  SystemCfgPrefix, host, server_id);

	/*
	** Search config.dat for a match on the string we just built.
	** If we don't find it, then use the value for II_INSTALLATION 
	** failing that, default to II.
	*/
        PMget( config_string, &port_id );
	if (port_id == NULL )
	{
		NMgtAt("II_INSTALLATION", &ptr);
		if (ptr != NULL && *ptr != '\0')
		{
			STcopy(ptr, port_id);
		}
		else 
		{ 
			STcopy(SystemVarPrefix, port_id);
		}
	}

	NMgtAt( "II_NETBIOS_NODE", &ptr );
	if ( !ptr || !*ptr  )
	{
	    /*
	    ** Get Computer Name into buffer.
	    */
	    *buffer = (char)NULL;
	    GetComputerName( buffer, &real_name_size );
	    if ( !*buffer )
	        STcopy( "NONAME", buffer );
	    ptr = buffer;
	}
	/*
	** MyName holds ID for outgoing connections.
	*/
	STpolycat( 2, ptr, "_", MyName );
	/*
	** Create listen port ID.
	*/
	STpolycat( 3, ptr, "_", port_id, GCc_listen_port );
	CVupper( MyName );
	CVupper( GCc_listen_port );
	STcopy( GCc_listen_port, pptr->pce_port );

	GCTRACE(2)("GClanman_init: port = %s\n", pptr->pce_port );

	/*
	** Go thru the the protocol threads event list and find the index
	** of the lanman thread.  Set the Global Tptr for easy reference
	** to the event q's for this protocols thread.
	*/
	for ( i = 0; i < IIGCc_proto_threads.no_threads; i++ )
	{
	     THREAD_EVENTS *p = &IIGCc_proto_threads.thread[i];

	     if ( !STcompare( LANMAN_ID, p->thread_name ) )
	     {
	         Tptr = p;
	         break;
	     }
	}
	if ( Tptr == NULL )
	{
	    CloseHandle( hEventThreadInQ );
	    CloseHandle( hMutexThreadInQ );
	    return FAIL;
	}

	/*
	** Finally we start the asynchronous I/O thread
	*/

	hThread = (HANDLE)_beginthreadex(&sa,
		       GC_STACK_SIZE,
		       (LPTHREAD_START_ROUTINE) GClanman_async_thread,
		       NULL,
		       (unsigned long)NULL,
		       &tid);
	if (hThread) 
	{
		CloseHandle(hThread);
	}
	else
	{
	    status = errno;
	    GCTRACE(1)("GClanman_init: Couldn't create thread errno = %d '%s'\n",
	    		status, strerror(status) );
	    return FAIL;
	}

	return OK;
}
Example #23
0
/*
** Name: psl_lm3_setlockparm_name() - perform semantic action for SETLOCKPARM
**				      production when the characteristic value
**				      has been specified as a string
**
** Input: 
**	sess_cb		    PSF session CB
**	    pss_distrib	    DB_3_DDB_SESS if distributed thread
**	    pss_stmt_flags  PSS_SET_LOCKMODE_SESS if SET LOCKMODE SESSION
**			    (distributed thread only)
**	    pss_object	    pointer to the root of a QSF object
**			    (of type (DMC_CB *) or (QEF_RCB *)).
**	char_type	    characteristic type
**	char_val	    value as specified by the user
**
** Output:
**	err_blk		    filled in if an error occurred
**	sess_cb		    PSF session CB
**	    pss_object	    characteristics of SETLOCKPARM filled in.
**
** Returns:
**	E_DB_{OK, ERROR, SEVERE}
**
** Side effects:
**	None
**
**  History:
**	07-mar-91 (andre)
**	    plagiarized from SETLOCKPARM production
**	21-apr-92 (barbara)
**	    Added support for Sybil.  For distributed thread, on
**	    SET LOCKMODE SESSION .. TIMEOUT we set timeout value
**	    specifically for QEF; all other options are passed to QEF
**	    in textual representation (see psl_lm5_setlockmode_distr) and
**	    are ignored in this function.
**      22-nov-1996 (dilma04)
**          Row-level locking project:
**          Add support for LEVEL=ROW.
**      24-jan-97 (dilma04)
**          Fix bug 80115: report an error if trying to specify row locking
**          for a system catalog or a table with 2k page size. 
**      12-feb-97 (dilma04)
**          Set Lockmode Cleanup:
**          Change readlock values according to new definitions.
**	25-feb-99 (hayke02)
**	    When setting row level locking in STAR, we now do not check
**	    if the lockmode scope is table. This was causing a SIGSEGV
**	    because dmc_cb had not been set. This change fixes bug 95490.
**	31-May-2006 (kschendel)
**	    Allow level=row for catalogs, no reason to exclude it.
**	15-Jan-2010 (stial01)
**	    SIR 121619 MVCC: Add lock level MVCC
*/
DB_STATUS
psl_lm3_setlockparm_name(
	i4	    char_type,
	char	    *char_val,
	PSS_SESBLK  *sess_cb,
	DB_ERROR    *err_blk)
{
    i4		err_code, err_no = 0L;
    DMC_CHAR_ENTRY	*chr;
    DM_DATA	    	*char_array;
    DMC_CB		*dmc_cb; 
    bool		not_distr = ~sess_cb->pss_distrib & DB_3_DDB_SESS;
    i4		*val, dummy;

    if (not_distr)
    {
    	char_array = &((DMC_CB *)sess_cb->pss_object)->dmc_char_array;
        dmc_cb = (DMC_CB *) sess_cb->pss_object;

    	if (char_array->data_in_size / sizeof (DMC_CHAR_ENTRY) ==
	    MAX_LOCKMODE_CHARS)
    	{
	    (VOID) psf_error(5931L, 0L, PSF_USERERR, &err_code, err_blk, 0);
	    return (E_DB_ERROR);	/* non-zero return means error */
    	}   

    	chr = (DMC_CHAR_ENTRY *)
	    ((char *) char_array->data_address + char_array->data_in_size);
	val = &chr->char_value;
    }
    else
    {
	val = &dummy;	
    }

    switch (char_type)
    {
	case LOCKLEVEL:
	    /*
	    ** Acceptable values for locklevel are "row", "page", "table",
	    ** "session", "system", "mvcc".
	    */
	    if (not_distr)
		chr->char_id = DMC_C_LLEVEL;

	    if (!STcompare(char_val, "page"))
	    {
		*val = DMC_C_PAGE;
	    }
	    else if (!STcompare(char_val, "session"))
	    {
		*val = DMC_C_SESSION;
	    }
	    else if (!STcompare(char_val, "system"))
	    {
		*val = DMC_C_SYSTEM;
	    }
	    else if (!STcompare(char_val, "table"))
	    {
		*val = DMC_C_TABLE;
	    }
            else if (!STcompare(char_val, "row")
		    || !STcompare(char_val, "mvcc"))
            {
                if (not_distr && (dmc_cb->dmc_sl_scope == DMC_SL_TABLE))
                {
                    DB_TAB_ID       *tabid = &dmc_cb->dmc_table_id;
                    PSS_RNGTAB      *tbl = &sess_cb->pss_auxrng.pss_rsrng;
 
		    if (tbl->pss_tabdesc->tbl_pg_type == DB_PG_V1)
                    {
                        (VOID) psf_error(E_PS03B0_ILLEGAL_ROW_LOCKING, 0L,
                            PSF_USERERR, &err_code, err_blk, 2,
			    STlength(char_val), char_val,
                            psf_trmwhite(sizeof(tbl->pss_tabname),
                                     (char *) &tbl->pss_tabname),
                            &tbl->pss_tabname);
                        return (E_DB_ERROR);
                    }
                }
  
		if (*char_val == 'r')
		    *val = DMC_C_ROW;
		else
		    *val = DMC_C_MVCC;
            }
	    else
	    {
		err_no = 5924L;
	    }
	    break;

	case READLOCK:
	    /*
	    ** Acceptable values for readlock are "nolock", "shared",
            ** "exclusive", "session", "system".
	    */
	    if (not_distr)
		chr->char_id = DMC_C_LREADLOCK;

	    if (!STcompare(char_val, "nolock"))
	    {
		*val = DMC_C_READ_NOLOCK; 
	    }
	    else if (!STcompare(char_val, "shared"))
	    {
                *val = DMC_C_READ_SHARE;
	    }
	    else if (!STcompare(char_val, "exclusive"))
	    {
		*val = DMC_C_READ_EXCLUSIVE; 
	    }
	    else if (!STcompare(char_val, "session"))
	    {
		*val = DMC_C_SESSION;
	    }
	    else if (!STcompare(char_val, "system"))
	    {
		*val = DMC_C_SYSTEM;
	    }
	    else
	    {
		err_no = 5925L;
	    }
	    break;

	case MAXLOCKS:
	    /*
	    ** Acceptable values for maxlocks are "session", "system".
	    */
	    if (not_distr)
		chr->char_id = DMC_C_LMAXLOCKS;

	    if (!STcompare(char_val, "session"))
	    {
		*val = DMC_C_SESSION;
	    }
	    else if (!STcompare(char_val, "system"))
	    {
		*val = DMC_C_SYSTEM;
	    }
	    else
	    {
		err_no = 5926L;
	    }
	    break;

	case TIMEOUT:
	    /*
	    ** Acceptable values for timeout are "session" , "system",
	    ** and "nowait".
	    */
	    if (not_distr)
	    {
		chr->char_id = DMC_C_LTIMEOUT;
	    }
	    else if (sess_cb->pss_stmt_flags & PSS_SET_LOCKMODE_SESS)
	    {
		/*
		** The distributed server is interested in the value from 
		** the SETLOCKKEY production when the SETLOCKSCOPE value
		** is session.
		*/
		val =
	&((QEF_RCB *)sess_cb->pss_object)->qef_r3_ddb_req.qer_d14_ses_timeout;
	    }

	    if (!STcompare(char_val, "session"))
	    {
		*val = DMC_C_SESSION;
	    }
	    else if (!STcompare(char_val, "system"))
	    {
		*val = DMC_C_SYSTEM;
	    }
	    else if (!STcompare(char_val, "nowait"))
	    {
		*val = DMC_C_NOWAIT;
	    }
	    else
	    {
		err_no = 5927L;
	    }
	    break;

	default:
	    /* Unknown "set lockmode" parameter */
	    (VOID) psf_error(E_PS0351_UNKNOWN_LOCKPARM, 0L, PSF_INTERR, 
		&err_code, err_blk, 1,
		(i4) sizeof(char_type), &char_type);
	    return (E_DB_SEVERE);    /* non-zero return means error */
    }

    if (err_no != 0L)
    {
	(VOID) psf_error(err_no, 0L, PSF_USERERR, &err_code, err_blk, 1,
	    (i4) STlength(char_val), char_val);
	return (E_DB_ERROR);	/* non-zero return means error */
    }
    else
    {
	if (not_distr)
	    char_array->data_in_size += sizeof (DMC_CHAR_ENTRY);
    }

    return(E_DB_OK);
}
Example #24
0
tDirStatus
FindUsersAuthInfo(
    tDirReference       dirRef,
    tDirNodeReference   nodeRef,
    const char *        username,
    tDataListPtr *      pathListToAuthNodePtr
)
{
    tDirStatus          err;
    tDirStatus          junk;
    tDataBufferPtr      buf;
    tDataListPtr        recordType;
    tDataListPtr        recordName;
    tDataListPtr        requestedAttributes;
    unsigned long       recordCount;
    tAttributeListRef   foundRecAttrList;
    tContextData        context;
    tRecordEntryPtr     foundRecEntry;
    tDataListPtr        pathListToAuthNode;

    if (!( (dirRef != NULL) || (nodeRef != NULL) || (username != NULL) ||
            ( pathListToAuthNodePtr != NULL) || (*pathListToAuthNodePtr == NULL) ) )
        return(eDSBadParam);

    recordType = NULL;
    recordName = NULL;
    requestedAttributes = NULL;
    foundRecAttrList = NULL;
    context = NULL;
    foundRecEntry = NULL;
    pathListToAuthNode = NULL;

    /*
    ** Allocate a buffer for the record results.  We'll grow this
    ** buffer if it proves to be too small.
    */

    err = eDSNoErr;
    buf = dsDataBufferAllocate(dirRef, kDefaultDSBufferSize);
    if (buf == NULL)
        err = eDSAllocationFailed;

    /*
    ** Create the information needed for the search.  We're searching for
    ** a record of type kDSStdRecordTypeUsers whose name is "username".
    ** We want to get back the kDSNAttrMetaNodeLocation and kDSNAttrRecordName
    ** attributes.
    */

    if (err == eDSNoErr)
    {
        recordType = dsBuildListFromStrings(dirRef, kDSStdRecordTypeUsers, NULL);
        recordName = dsBuildListFromStrings(dirRef, username, NULL);
        requestedAttributes = dsBuildListFromStrings(dirRef,
                              kDSNAttrMetaNodeLocation, kDSNAttrRecordName, NULL);

        if ( (recordType == NULL) || (recordName == NULL) ||
                (requestedAttributes == NULL) )
            err = eDSAllocationFailed;
    }

    /* Search for a matching record. */

    if (err == eDSNoErr) {
        recordCount = 1;            /* we only want one match (the first) */

        err = dsGetRecordListQ(
                  dirRef,
                  nodeRef,
                  &buf,
                  recordName,
                  eDSExact,
                  recordType,
                  requestedAttributes,
                  false,
                  &recordCount,
                  &context
              );
    }

    if ( (err == eDSNoErr) && (recordCount < 1) )
        err = eDSRecordNotFound;

    /*
    ** Get the first record from the search.  Then enumerate the attributes for
    ** that record.  For each attribute, extract the first value (remember that
    ** attributes can by multi-value).  Then see if the attribute is one that
    ** we care about.  If it is, remember the value for later processing.
    */
    if (err == eDSNoErr)
        err = dsGetRecordEntry(nodeRef, buf, 1, &foundRecAttrList,
                               &foundRecEntry);

    if (err == eDSNoErr)
    {
        unsigned long attrIndex;

        /* Iterate over the attributes. */

        for (attrIndex = 1;
                attrIndex <= foundRecEntry->fRecordAttributeCount;
                attrIndex++)
        {
            tAttributeValueListRef  thisValue;
            tAttributeEntryPtr      thisAttrEntry;
            tAttributeValueEntryPtr thisValueEntry;
            const char *            thisAttrName;

            thisValue = NULL;
            thisAttrEntry = NULL;
            thisValueEntry = NULL;

            /* Get the information for this attribute. */

            err = dsGetAttributeEntry(nodeRef, buf, foundRecAttrList, attrIndex,
                                      &thisValue, &thisAttrEntry);

            if (err == eDSNoErr)
            {
                thisAttrName = thisAttrEntry->fAttributeSignature.fBufferData;

                /* We only care about attributes that have values. */

                if (thisAttrEntry->fAttributeValueCount > 0)
                {
                    /*
                    ** Get the first value for this attribute.  This is common
                    ** code for the two potential attribute values listed below,
                    ** so we do it first.
                    */

                    err = dsGetAttributeValue(nodeRef, buf, 1, thisValue,
                                              &thisValueEntry);

                    if (err == eDSNoErr)
                    {
                        const char *    thisValueDataPtr;
                        unsigned long   thisValueDataLen;

                        thisValueDataPtr = thisValueEntry->fAttributeValueData.fBufferData;
                        thisValueDataLen = thisValueEntry->fAttributeValueData.fBufferLength;

                        /*
                                    ** Handle each of the two attributes we care about;
                        ** ignore any others.
                        */

                        if ( STcompare(thisAttrName,
                                       kDSNAttrMetaNodeLocation) == 0 )
                        {

                            /*
                                        ** This is the kDSNAttrMetaNodeLocation attribute,
                            ** which contains a path to the node used for
                            ** authenticating this record; convert its value
                            ** into a path list.
                            */

                            pathListToAuthNode = dsBuildFromPath(
                                                     dirRef,
                                                     thisValueDataPtr,
                                                     "/"
                                                 );
                            if (pathListToAuthNode == NULL)
                                err = eDSAllocationFailed;

                        }
                    }
                    else
                    {
                        fprintf(stderr, "FindUsersAuthInfo: Unexpected no-value attribute '%s'.", thisAttrName);
                    }
                }

                /* Clean up. */

                if (thisValueEntry != NULL)
                    dsDeallocAttributeValueEntry(dirRef, thisValueEntry);
                if (thisValue != NULL)
                    dsCloseAttributeValueList(thisValue);
                if (thisAttrEntry != NULL)
                    dsDeallocAttributeEntry(dirRef, thisAttrEntry);

                if (err != eDSNoErr)
                    break;
            }
        } /* Check attr loop */
    }

    /* Copy results out to caller. */

    if (err == eDSNoErr)
    {
        if (pathListToAuthNode != NULL)
        {
            /* Copy out results. */

            *pathListToAuthNodePtr = pathListToAuthNode;

            /* NULL out locals so that we don't dispose them. */

            pathListToAuthNode = NULL;
        }
        else
            err = eDSAttributeNotFound;
    }

    /* Clean up. */

    if (pathListToAuthNode != NULL)
        dsDataListAndHeaderDeallocate(dirRef, pathListToAuthNode);
    if (foundRecAttrList != NULL)
        dsCloseAttributeList(foundRecAttrList);
    if (context != NULL)
        dsReleaseContinueData(dirRef, context);
    if (foundRecAttrList != NULL)
        dsDeallocRecordEntry(dirRef, foundRecEntry);
    if (requestedAttributes != NULL)
        dsDataListAndHeaderDeallocate(dirRef, requestedAttributes);
    if (recordName != NULL)
        dsDataListAndHeaderDeallocate(dirRef, recordName);
    if (recordType != NULL)
        dsDataListAndHeaderDeallocate(dirRef, recordType);
    if (buf != NULL)
        dsDataBufferDeAllocate(dirRef, buf);

    return err;
}
Example #25
0
i4
Trace_Token_List(char *list_label,i4 l_nr,i4 num_of_tokens,FILE_TOKENS **tokarray)
{
    i4                     i, j, k ;
    char                  *toktype  = NULL ;
    char                  *otoktype = NULL ;
    bool                   skip_it  = FALSE ;
    char                  *ARRY_LINE_FMT
			   = ERx(" %5d   %-40s   %5d    A_%-10s\n") ;
    char                  *ARRY_BANNER
			   = ERx("-------------------------------------------------------------------------\n") ;

    SIfprintf(traceptr,ERx("\n                       %6s #%d,  %d Tokens.\n\n"),
	      list_label, l_nr, num_of_tokens );

    if (num_of_tokens == 0) return (OK);

    SIputrec(ARRY_BANNER,traceptr);
    SIputrec(ERx(" Token |            First 40 Chars  "), traceptr);
    SIputrec(ERx("              |  Line  |    Token\n"),  traceptr);
    SIputrec(ERx("  Nr   |              of Token "), traceptr);
    SIputrec(ERx("           |   Nr   |    Type\n"), traceptr);
    SIputrec(ARRY_BANNER,traceptr);

    for (i=1, j=0; i <= num_of_tokens; i++)
    {
	if ((j == 0)||(tokarray[i]->tokenID != A_UNKNOWN)||
	    (STcompare(tokarray[i]->token,tokarray[j]->token) != 0))
	{
	    if (skip_it == TRUE)
	    {
		if ((k = tokarray[i]->token_no - tokarray[j]->token_no) == 2)
		{
		    SIfprintf(traceptr, ARRY_LINE_FMT, tokarray[j]->token_no,
				        tokarray[j]->token, tokarray[j]->lineno,
			                otoktype );
		}
		else
		{
		    SIfprintf(traceptr, ERx("\t\t - (%d) duplicate tokens -\n"),
					k-1);
		}

		skip_it = FALSE;
	    }

	    j = i;
	}
	else
	{
	    otoktype = toktype;
	    skip_it = TRUE;
	    continue;
	}

	switch (tokarray[i]->tokenID)
	{
	    case A_NUMBER:	toktype = ERx("NUMBER");	break;
	    case A_OCTAL:	toktype = ERx("OCTAL");		break;
	    case A_HEXA:	toktype = ERx("HEXA");		break;
	    case A_FLOAT:	toktype = ERx("FLOAT");		break;
	    case A_WORD:	toktype = ERx("WORD");		break;
	    case A_DBLWORD:     toktype = ERx("DBLWORD");       break;
	    case A_DATE:	toktype = ERx("DATE");		break;
	    case A_TIME:	toktype = ERx("TIME");		break;
	    case A_DELIMITER:	toktype = ERx("DELIMITER");	break;
	    case A_CONTROL:	toktype = ERx("CONTROL");	break;
	    case A_UNKNOWN:	toktype = ERx("UNKNOWN");	break;
	    case A_RETCOLUMN:	toktype = ERx("RETCOLUMN");	break;
	    case A_DIRECTORY:	toktype = ERx("DIRECTORY");	break;
	    case A_BANNER:	toktype = ERx("BANNER");	break;
	    case A_PRODUCT:	toktype = ERx("PRODUCT");	break;
	    case A_VERSION:	toktype = ERx("VERSION");	break;
	    case A_ALARMID:	toktype = ERx("ALARMID");	break;
	    case A_COMPNAME:	toktype = ERx("COMPNAME");	break;
	    case A_COPYRIGHT:	toktype = ERx("COPYRIGHT");	break;
	    case A_DBNAME:	toktype = ERx("DBNAME");	break;
	    case A_DESTROY:     toktype = ERx("DESTROY");       break;
	    case A_DROP:        toktype = ERx("DROP");          break;
	    case A_RULE:        toktype = ERx("RULE");          break;
	    case A_PROCEDURE:   toktype = ERx("PROCEDURE");     break;
	    case A_SPACE:	toktype = ERx("SPACE");		break;
	    case A_DATABSID:	toktype = ERx("DATABSID"); 	break;
	    case A_TRANID: 	toktype = ERx("TRANID"); 	break;
	    case A_SERVERID:	toktype = ERx("SERVERID"); 	break;
	    case A_TABLE:       toktype = ERx("TABLE");         break;
	    case A_OWNER:       toktype = ERx("OWNER");         break;
          case A_USER:        toktype = ERx("USER");          break;
	    case A_COLUMN:      toktype = ERx("COLUMN");        break;
	    case A_GROUP:       toktype = ERx("GROUP");         break;
	    case A_COMPILE:     toktype = ERx("COMPILE");       break;
	    default:		toktype = ERx("(error)");	break;
	}
	SIfprintf(traceptr, ARRY_LINE_FMT, tokarray[i]->token_no,
			    tokarray[i]->token, tokarray[i]->lineno, toktype );
    }
    SIfprintf(traceptr, ERx("(%5d)\n"), num_of_tokens);
    return (OK);
}
Example #26
0
/* Name: adu_getconverter - Obtains the name of converter mapping file
**			    to use for unicode coercion. 
** Description:
**
** To obtain the mapping file to be used for carrying out unicode-local
** character conversion. The following mechanism is followed:
**
** 1. Check symbol table for user defined converter setting
**    II_UNICODE_CONVERTER. If set then return this setting 
** 2. If the variable is not set then 
**	2.a Get the platform character set
**	2.b Read the aliasmaptbl file. 
** 	2.c Search the alias file for platform charset.
** 3. If still not found then find the II_CHARSETxx value
**    for ingres installation and search the alias file for 
**    this value. 
** 4. If none of these attempts succeed then return default 
**    with a warning to the errorlog if this happens 
** 
** Input:
**	converter -	Place holder for the output string, 
**			It is assumed that the area is at least MAX_LOC
**			chars in size.
** Output:
**	converter -	Pointer to string where the output
**			converter name is stored.
** History:
**
**	22-jan-2004 (gupsh01)
**	    Added.
**	14-Jun-2004 (schka24)
**	    Safe charset name handling.
*/
STATUS
adu_getconverter(
    char	*converter)
{
    STATUS		stat;
    char		*tptr;
    char		*env = 0;
    char		chset[CM_MAXATTRNAME+1];
    char		pcs[CM_MAXLOCALE+1]; /* platform character set */
    char		norm_pcs[CM_MAXLOCALE+1];
    CL_ERR_DESC         syserr;
    char                *alias_buffer = NULL;
    char                *bufptr = NULL;
    char                *buf = NULL;
    ADU_ALIAS_MAPPING   *aliasmapping;
    ADU_ALIAS_DATA	*aliasdata;	
    char 		*datasize;
    SIZE_TYPE		filesize = 0;
    SIZE_TYPE		sizemap = 0;
    SIZE_TYPE		sizedata = 0;
    i4			bytes_read;
    char		*abufptr;
    i4			i = 0;
    i4			index = 0;


/* STEP 1 */
    NMgtAt(ERx("II_UNICODE_CONVERTER"), &env);
    if (env && *env)
    {
        STlcopy(env, converter, MAX_LOC-1);
	return OK;
    }

/* STEP 2 */
    stat = CM_getcharset(pcs);
    
    if (CMopen_col("aliasmaptbl", &syserr, CM_UCHARMAPS_LOC) != OK)
    {
      /* return an ERROR if we are unable to open the file */
      return FAIL;
    }

    /* initialize buf to help read from the aliasmaptbl file */
    buf = MEreqmem(0, COL_BLOCK, TRUE, &stat);
    if (buf == NULL || stat != OK)
    {
       CMclose_col(&syserr, CM_UCHARMAPS_LOC);
       return (FAIL);
    }

    /* First file buffer has size information. */
    stat = CMread_col(buf, &syserr);
    if (stat != OK)
    {
        MEfree((char *)buf);
        CMclose_col(&syserr, CM_UCHARMAPS_LOC);
       return (FAIL);
    }

    tptr = buf;
    bytes_read = COL_BLOCK;

    /* filesize is the first entry of the map file */
    filesize = *(SIZE_TYPE *) buf;
    tptr += sizeof(SIZE_TYPE);
    tptr = ME_ALIGN_MACRO(tptr, sizeof(PTR));

    /* allocate working space for the data */
    alias_buffer = (char *)MEreqmem(0, filesize, TRUE, &stat);
    if (alias_buffer == NULL || stat != OK)
    {
       CMclose_col(&syserr, CM_UCHARMAPS_LOC);
       return (FAIL);
    }
    abufptr = alias_buffer;
    MEcopy (buf, COL_BLOCK, abufptr);
    abufptr += COL_BLOCK;

    /* Read the file till it is read completely */
    for ( ;bytes_read < filesize;)
    {
        stat = CMread_col(buf, &syserr);
        if (stat != OK)
        {
          MEfree((char *)buf);
          MEfree((char *)alias_buffer);
          CMclose_col(&syserr, CM_UCHARMAPS_LOC);
          return (FAIL);
	}
	bytes_read += COL_BLOCK;
        MEcopy (buf, COL_BLOCK, abufptr);
        abufptr += COL_BLOCK;
    }

    if (bytes_read < filesize)
    {
      /* we had to exit for some unknown reason */
      MEfree((char *)buf);
      MEfree((char *)alias_buffer);
      CMclose_col(&syserr, CM_UCHARMAPS_LOC);
      return (FAIL);
    }
    tptr = alias_buffer;
    tptr += sizeof(SIZE_TYPE);
    tptr = ME_ALIGN_MACRO(tptr, sizeof(PTR));

    /* Read the size of the MappingArray nodes */
    sizemap = *(SIZE_TYPE *) tptr;
    tptr += sizeof(SIZE_TYPE);
    tptr = ME_ALIGN_MACRO(tptr, sizeof(PTR));

    /* initialize buffer for ADU_ALIAS_MAPPING buffer */
    aliasmapping = (ADU_ALIAS_MAPPING *) MEreqmem(0, sizemap, TRUE, &stat);
    if (aliasmapping == NULL)
    {
      MEfree((char *)buf);
      MEfree((char *)alias_buffer);
      CMclose_col(&syserr, CM_UCHARMAPS_LOC);
      return (FAIL);
    }

    /* Copy data for ADU_ALIAS_MAPPING array */
    MEcopy(tptr, sizemap, aliasmapping);
    tptr += sizemap;
    tptr = ME_ALIGN_MACRO(tptr, sizeof(PTR));

    /* Get size for the aliasdata */
    sizedata = *(SIZE_TYPE *) tptr;
    tptr += sizeof(SIZE_TYPE);
    tptr = ME_ALIGN_MACRO(tptr, sizeof(PTR));

     /* Initialize buffer for ADU_ALIAS_MAPPING buffer */
    aliasdata = (ADU_ALIAS_DATA *) MEreqmem(0, sizedata, TRUE, &stat);
    if (aliasdata == NULL)
    {
      MEfree((char *)buf);
      MEfree((char *)alias_buffer);
      MEfree((char *)aliasmapping);
      CMclose_col(&syserr, CM_UCHARMAPS_LOC);
      return (FAIL);
    }

    /* Copy the ADU_ALIAS_DATA array */
    MEcopy(tptr, sizedata, aliasdata);
    tptr += sizedata;
    tptr = ME_ALIGN_MACRO(tptr, sizeof(PTR));

    /* Close the "aliasmaptbl" file */
    CMclose_col(&syserr, CM_UCHARMAPS_LOC);

    /* Normalize pcs */

    adu_csnormalize (pcs, STlength(pcs), norm_pcs);

    /* Retrieve the pcs value */
    for (i=0; i < sizedata/sizeof(ADU_ALIAS_DATA); i++)
    {
      if ((STcompare (aliasdata[i].aliasNameNorm, norm_pcs)) == 0)
      {
	index = aliasdata[i].aliasMapId; 
	/* found */
	STcopy (aliasmapping[index].mapping_id, 
		  converter);

        /* cleanup */
        MEfree((char *)buf);
        MEfree((char *)alias_buffer);
        MEfree((char *)aliasmapping);
        MEfree((char *)aliasdata);

        return (OK);
      } 
    }

/* STEP 3 */
    /* Obtain Ingres characterset */
    STcopy("default", converter);
    CMget_charset_name(&chset[0]);
    if (STcasecmp(chset, "UTF8") != 0)
    { 
	    /* search maptable for env  */ 
	for (i=0; i < sizedata/sizeof(ADU_ALIAS_DATA); i++)
	{
	    if ((STcompare (aliasdata[i].aliasNameNorm, norm_pcs)) == 0)
	    {
		index = aliasdata[i].aliasMapId; 
		/* found */
		STcopy (aliasmapping[index].mapping_id, converter);
		break;
	    }
	}
    }

    /* cleanup */
    MEfree((char *)buf);
    MEfree((char *)alias_buffer);
    MEfree((char *)aliasmapping);
    MEfree((char *)aliasdata);

    /* FIXME warning or error if still "default" ? */

    return (OK);
}
Example #27
0
/*
** Name: PCexec_suid - Execute a command as the ingres user.
**
** Description:
**	This procedure works with the Ingres service to run the given
**	command as the ingres user. It mimicks the "setuid" bit in UNIX.
**
** Inputs:
**	cmdbuf - command to execute as the ingres user
**
** Outputs:
**	none
**
** Returns:
**	OK
**	FAIL
**
** Side Effects:
**	none
**
** History:
**	08-jan-1998 (somsa01)
**	    Created.
**	19-feb-1998 (somsa01)
**	    We need to pass to the service the current working directory
**	    as well.  (Bug #89006)
**	25-feb-1998 (somsa01)
**	    We now have an input file for the process' stdin which
**	    runs through the OpenIngres service.
**	19-jun-1998 (somsa01)
**	    Use SYSTEM_PRODUCT_NAME for the name of the service.
**	10-jul-1998 (kitch01)
**		Bug 91362. If user is 'system' run through OpenIngres service
**		despite having access to server shared memory 'system' does not
**		have required privilege to access semaphores/mutexes.
**	11-jun-1999 (somsa01)
**	    If the command is a startup command, then it is always run through
**	    the Ingres service.
**	03-nov-1999 (somsa01)
**	    A failure from ControlService() should be treated as a severe
**	    error which should not let us continue.
** 	22-jan-2000 (somsa01)
**	    Return the exit code of the spawned process. Also, if the
**	    files exist, truncate them. The service name is now keyed off
**	    of II_INSTALLATION.
**	05-jun-2000 (somsa01)
**	    The Ingres installation may be started as the SYSTEM account,
**	    in which the 'ingres' user will not automatically have access
**	    to the shared memory segments. Therefore, even if the real
**	    user is 'ingres', check to see if he has access.
**	24-oct-2000 (somsa01)
**	    Removed the check on shared memory access. Access to the shared
**	    memory segment does not necessarily mean that the user running
**	    the process does not need to run the specified process as the
**	    Ingres owner. Also, generalized the check of the user with
**	    IDname_service().
**	18-dec-2000 (somsa01)
**	    Modified the cases to run the command "as is" without the Ingres
**	    service.
**	20-mar-2002 (somsa01)
**	    If all is well, return the exit code of the child process that
**	    was executed.
**	29-mar-2002 (somsa01)
**	    Properly return the child process exit code.
**	11-apr-2003 (somsa01)
**	    While waiting for "pending" to not be set, give some CPU back
**	    to the OS.
**      29-Jul-2005 (drivi01)
**	    Allow user to run the command if he/she owns a shared
**	    segment and ingres is not running as a service.
**	06-Dec-2006 (drivi01)
**	    Adding support for Vista, Vista requires "Global\" prefix for
**	    shared objects as well.  Replacing calls to GVosvers with 
**	    GVshobj which returns the prefix to shared objects.
**	    Added PCadjust_SeDebugPrivilege to allow quering of 
**	    System processes.
**	25-Jul-2007 (drivi01)
**		On Vista, PCexec_suid is unable to use SE_DEBUG Privilege
**	    to query process status and retireve its exit code.
**		The routine for monitoring a process and retrieving 
**	    its exit code has been moved to Ingres Service.
**	05-Nov-2009 (wanfr01) b122847
**	    Don't do a PCsleep unless you are waiting for more input
*/
STATUS
PCexec_suid(char *cmdbuf)
{
    EX_CONTEXT		context;
    SERVICE_STATUS	ssServiceStatus;
    LPSERVICE_STATUS	lpssServiceStatus = &ssServiceStatus;
    struct SETUID	setuid;
    DWORD		ProcID;
    HANDLE		SaveStdout;
    SECURITY_ATTRIBUTES	sa;
    CHAR		szRealUserID[25] = "";
    CHAR		*pszRealUserID = szRealUserID;
    CHAR		szServiceUserID[25] = "";
    CHAR		*pszServiceUserID = szServiceUserID;
    DWORD		BytesWritten, BytesRead = 0;
    CHAR		*inst_id;
    CHAR		SetuidShmName[64];
    CHAR		*temp_loc;
    CHAR		InBuf[256], OutBuf[256];
    static CHAR		SetuidPipeName[32];
    CL_ERR_DESC		err_code;
    CHAR		ServiceName[255];
    DWORD		ExitCode = 0;
    CHAR		tchII_INSTALLATION[3];
    BOOL		SetuidDbCmd = FALSE, ServiceCommand = FALSE;
    int			i, cmdlen;
    char		*ObjectPrefix;
	u_i4		drType;
    SC_HANDLE		schSCManager, OpIngSvcHandle;
    BOOL		bServiceStarted = FALSE;

    if (EXdeclare(ex_handler, &context) != OK)
    {
	EXdelete();
	PCexit(FAIL);
    }
    NMgtAt("II_INSTALLATION", &inst_id);
    STcopy(inst_id, tchII_INSTALLATION);

    /*
    ** See if this is a command that MUST be run through the Ingres
    ** service.
    */
    cmdlen = (i4)STlength(cmdbuf);
    for (i = 0; ServiceCommands[i] ; i++)
    {
	if (STbcompare( cmdbuf, cmdlen, ServiceCommands[i],
			(i4)STlength(ServiceCommands[i]), FALSE ) == 0)
	{
	    ServiceCommand = TRUE;
	    break;
	}
    }

    /*
    ** If the user is the same as the user who started the Ingres
    ** service, just spawn the command.
    */
    if (!ServiceCommand)
    {
	IDname(&pszRealUserID);
	if (!IDname_service(&pszServiceUserID) &&
	    STcompare(pszServiceUserID, pszRealUserID) == 0 && 
		PCisAdmin())
	{
	    /*
	    ** Attempt to just execute the command.
	    */
	    return( PCcmdline( (LOCATION *) NULL, cmdbuf, PC_WAIT,
		    (LOCATION *) NULL, &err_code) );
	}
	else
	{
	    /*
	    ** If current user is not the same as service user and ingres is not
	    ** running as a service, check if shared memory segment is owned
	    ** by current user, if user has access to shared segment allow him
	    ** to run the command.
	    */
	    PTR	shmem;
	    SIZE_TYPE	allocated_pages=0;
	    STATUS status;

	    if((status = MEget_pages(ME_MSHARED_MASK, 1, "lglkdata.mem",
	                 &shmem, &allocated_pages, &err_code)) == OK)
	    {
	        STprintf(ServiceName, "%s_Database_%s", SYSTEM_SERVICE_NAME, 
		tchII_INSTALLATION);
	        if ((schSCManager = OpenSCManager(NULL, NULL, 
					SC_MANAGER_CONNECT)) != NULL)
	        {
		    if ((OpIngSvcHandle = OpenService(schSCManager, ServiceName,
					SERVICE_QUERY_STATUS)) != NULL)
		    {
		       if (QueryServiceStatus(OpIngSvcHandle,lpssServiceStatus))
		       {
		    	if (ssServiceStatus.dwCurrentState != SERVICE_STOPPED)
			     bServiceStarted = TRUE;
		        }
		    }
	        }	
	        if (!bServiceStarted)
		    return(PCcmdline( (LOCATION *) NULL, cmdbuf, PC_WAIT,
			(LOCATION *) NULL, &err_code) );
	    }

	}

	/*
	** See if this command is an Ingres command which needs to interact
	** with at least one database.
	*/
	for (i = 0; validSetuidDbCmds[i] ; i++)
	{
	    if (STbcompare( cmdbuf, cmdlen, validSetuidDbCmds[i],
			    (i4)STlength(validSetuidDbCmds[i]), FALSE ) == 0)
	    {
		SetuidDbCmd = TRUE;
		break;
	    }
	}

	/*
	** If the user has access to the Ingres shared memory segment,
	** just spawn the command provided that it is not in the
	** validSetuidDbCmds list.
	*/
	if (!SetuidDbCmd)
	{
	    PTR	shmem;
	    SIZE_TYPE	allocated_pages=0;
	    STATUS	status;

	    if (((status = MEget_pages(ME_MSHARED_MASK, 1, "lglkdata.mem",
		&shmem,
		&allocated_pages, &err_code)) == OK) ||
		(status == ME_NO_SUCH_SEGMENT))
	    {
		if (status != ME_NO_SUCH_SEGMENT)
		    MEfree_pages(shmem, allocated_pages, &err_code);
		
		return( PCcmdline( (LOCATION *) NULL, cmdbuf, PC_WAIT,
			(LOCATION *) NULL, &err_code) );
	    }
	}
    }

    /*
    ** We must run the command through the Ingres service.
    */

    if ( STstrindex(cmdbuf, "-silent", 0, FALSE ) )
	SilentMode = TRUE;

    iimksec(&sa);


	GVshobj(&ObjectPrefix);
	STprintf(SetuidShmName, "%s%sSetuidShm", ObjectPrefix, tchII_INSTALLATION);

    if ( (SetuidShmHandle = OpenFileMapping(FILE_MAP_READ | FILE_MAP_WRITE,
					    FALSE,
					    SetuidShmName)) == NULL )
    {
	error_exit(GetLastError());
	return(FAIL);
    }
    if ( (SetuidShmPtr = MapViewOfFile(SetuidShmHandle,
				       FILE_MAP_WRITE | FILE_MAP_READ,
				       0,
				       0,
				       sizeof(struct SETUID_SHM))) == NULL )
    {
	error_exit(GetLastError());
	return(FAIL);
    }

    /* Set up the information to send to the service. */
    STcopy(cmdbuf, setuid.cmdline);
    GetCurrentDirectory(sizeof(setuid.WorkingDirectory),
			setuid.WorkingDirectory);
	NMgtAt("II_TEMPORARY", &temp_loc);
	drType = GetDriveType(NULL);
	if (drType == DRIVE_REMOTE)
	{
		STcopy(temp_loc, setuid.WorkingDirectory);
	}
    SaveStdout = GetStdHandle(STD_OUTPUT_HANDLE);
    CVla(GetCurrentProcessId(), setuid.ClientProcID);
    STprintf(SetuidPipeName, "\\\\.\\PIPE\\INGRES\\%s\\SETUID", inst_id);

    /* Set up the stdout file for the command. */
    STprintf(OutfileName, "%s\\%sstdout.tmp", temp_loc, setuid.ClientProcID);
    if ( (OutFile = CreateFile(OutfileName,
			       GENERIC_READ | GENERIC_WRITE,
			       FILE_SHARE_READ | FILE_SHARE_WRITE,
			       &sa,
			       CREATE_ALWAYS,
			       FILE_ATTRIBUTE_NORMAL,
			       NULL)) == INVALID_HANDLE_VALUE )
    {
	error_exit(GetLastError());
	return(FAIL);
    }

    /* Set up the stdin file for the command. */
    STprintf(InfileName, "%s\\%sstdin.tmp", temp_loc, setuid.ClientProcID);
    if ( (InFile = CreateFile(InfileName,
			      GENERIC_READ | GENERIC_WRITE,
			      FILE_SHARE_READ | FILE_SHARE_WRITE,
			      &sa,
			      CREATE_ALWAYS,
			      FILE_FLAG_WRITE_THROUGH,
			      NULL)) == INVALID_HANDLE_VALUE )
    {
	error_exit(GetLastError());
	return(FAIL);
    }

    /* Wait until the service is ready to process our request. */
    while (SetuidShmPtr->pending == TRUE)
	PCsleep(100);
    SetuidShmPtr->pending = TRUE;

    /* Trigger the "setuid" event of the service. */
    if ( (schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT)) == NULL)
    {
	error_exit(GetLastError());
	return(FAIL);
    }

    STprintf(ServiceName, "%s_Database_%s", SYSTEM_SERVICE_NAME,
	     tchII_INSTALLATION );
	OpIngSvcHandle = OpenService(schSCManager, ServiceName,
						SERVICE_USER_DEFINED_CONTROL);
	if (OpIngSvcHandle == NULL)
	{
		STprintf(ServiceName, "%s_DBATools_%s", SYSTEM_SERVICE_NAME,
	     tchII_INSTALLATION );
		OpIngSvcHandle = OpenService(schSCManager, ServiceName,
						SERVICE_USER_DEFINED_CONTROL);
	}
    if ( OpIngSvcHandle == NULL)
    {
	error_exit(GetLastError());
	return(FAIL);
    }
    if (!ControlService(OpIngSvcHandle, RUN_COMMAND_AS_INGRES,
			lpssServiceStatus))
    {
	error_exit(GetLastError());
	CloseServiceHandle(schSCManager);
	return(FAIL);
    }

    WaitNamedPipe(SetuidPipeName, NMPWAIT_WAIT_FOREVER);

    /* Send the information to the service. */
    if ( (Setuid_Handle = CreateFile(SetuidPipeName,
				     GENERIC_READ|GENERIC_WRITE,
				     FILE_SHARE_READ|FILE_SHARE_WRITE,
				     &sa,
				     OPEN_EXISTING,
				     FILE_ATTRIBUTE_NORMAL,
				     NULL)) == INVALID_HANDLE_VALUE )
    {
	error_exit(GetLastError());
	return(FAIL);
    }
    if (!WriteFile(Setuid_Handle, &setuid, sizeof(struct SETUID),
		   &BytesWritten, NULL))
    {
	error_exit(GetLastError());
	return(FAIL);
    }

    /*
    ** Retrieve information back from the service, and then
    ** disconnect from the pipe.
    */
    if (!ReadFile(Setuid_Handle, &setuid, sizeof(struct SETUID),
		  &BytesRead, NULL))
    {
	error_exit(GetLastError());
	return(FAIL);
    }

    ProcID = setuid.CreatedProcID;
    SetuidShmPtr->pending = FALSE;

    UnmapViewOfFile(SetuidShmPtr);
    SetuidShmPtr = NULL;
    CloseHandle(SetuidShmHandle);

    if ( (ProcID != -1) && (ProcID != -2) )
    {
	/*
	** Wait for the "spawned" process to exit, reading its output
	** from the stdout file.
	*/
	for (;;)
	{
	    if ( ((!ReadFile(OutFile, OutBuf, sizeof(OutBuf), &BytesRead, NULL)
		  || (BytesRead == 0)) && setuid.ExitCode != STILL_ACTIVE ))
		break;

	    if ( BytesRead &&
		 (!WriteFile(SaveStdout, OutBuf, BytesRead, &BytesWritten,
		  NULL)) && setuid.ExitCode != STILL_ACTIVE)
		break;
	    else if (BytesRead < sizeof(OutBuf))
		PCsleep(200);

	    /*
	    ** Currently, the only DBA program which can require
	    ** user input is verifydb. Therefore, when it spits out
	    ** the appropriate messages asking for user input, get
	    ** it from the end user and pass it along to the spawned
	    ** process.
	    */
	    if ( (STrstrindex(OutBuf, "S_DU04FF_CONTINUE_PROMPT", 0, FALSE)
			!= NULL) ||
		 (STrstrindex(OutBuf, "S_DU0300_PROMPT", 0, FALSE) != NULL) )
	    {
		SIflush(stdout);
		MEfill(sizeof(OutBuf), ' ', &OutBuf);
		MEfill(sizeof(InBuf), ' ', &InBuf);
		SIgetrec(InBuf, 255, 0);
		WriteFile(InFile, InBuf, sizeof(OutBuf), &BytesWritten, NULL);
	    }
	}

	ExitCode = setuid.ExitCode;
	CloseHandle(Setuid_Handle);
	CloseHandle(InFile);
	DeleteFile(InfileName);
	CloseHandle(OutFile);
	DeleteFile(OutfileName);
	CloseServiceHandle(OpIngSvcHandle);
	CloseServiceHandle(schSCManager);
        return(ExitCode);
    }
    else
    {
	error_exit(GetLastError());
	return(FAIL);
    }
}
Example #28
0
main(int argc, char **argv)
{
	char 			*value = NULL; 
	char			*host, *server_type, *command_line; 
	char 			*server_location, *env, *arguments;
	u_i4 			command_line_length;
	char 			config_string[256];
	char 			iidbms[256];
	STARTUPINFO 		si;
	PROCESS_INFORMATION 	ProcessInfo;
	BOOL 			Status;
	SECURITY_ATTRIBUTES     sa;
	HANDLE			hRead, hWrite;
	HANDLE			hStdout;
	char			buffer[512];
	DWORD			bufferl = sizeof(buffer);
	DWORD			pipe_size = 0;	/* Use default buffer size */
	DWORD			datal = 0;
	bool			havequote, failed = FALSE;


	MEadvise( ME_INGRES_ALLOC );

	switch (argc)
	{

	case 1:
		server_type = ERx("dbms");
		server_location = ERx("*");
		break;

	case 2:
		server_type = argv[1];
		server_location = ERx("*");
		break;

	default:
		server_type = argv[1];
    		if (STcompare(server_type, "recovery") == 0)
			server_location = ERx("*");
		else
			server_location = argv[2];
		break;

	}
	
	get_sys_dependencies();

	/*
	**	Get the host name, formally used iipmhost.
	*/
	host = PMhost();

	/*
	**	Build the string we will search for in the config.dat file.
	*/
	STprintf( config_string,
		  ERx("%s.%s.%s.%s.image_name"),
		  SystemCfgPrefix, host, server_type, server_location );

	/*
	**	Get set up for the PMget call.
	*/
	PMinit();
	if( PMload( NULL, (PM_ERR_FUNC *)NULL ) != OK )
		PCexit( FAIL );

	/*
	**	Go search config.dat for a match on the string we just built.
	*/
	PMget( config_string, &value );

	if ( value == NULL )
	{
		NMgtAt( SystemLocationVariable, &env );
		if (STcompare(server_type, "recovery") == 0)
		{
		    STprintf(iidbms, ERx("%s\\%s\\bin\\%sdbms"),
			     env, SystemLocationSubdirectory, SystemCfgPrefix);
		}
		else
		{
		    STprintf(iidbms, ERx("%s\\%s\\bin\\%s%s"),
			     env, SystemLocationSubdirectory, SystemCfgPrefix,
			     server_type);
		}
	}
	else if ( *value == '/' || 
		  *value == '\\' ||
		  (*(value+1) == ':' && *(value+2) == '\\') )
	{
		/* Must be a qualified path name */
		STcopy( value, iidbms );
	}
	else 
	{
		NMgtAt( SystemLocationVariable, &env );
		STprintf( iidbms, ERx("%s\\%s\\bin\\%s"),
			  env, SystemLocationSubdirectory, value );
	}
	
	/*
 	** 	Initialize the startinfo structure.	
	*/
	ZeroMemory(&si, sizeof(si));
	si.cb = sizeof(si);

	/*
	**	Get the original command line.
	*/
	arguments = GetCommandLine();
        havequote = FALSE;
        while (*arguments != '\0' && *arguments != '\n')
        {
            if ( *arguments == '"' )
                havequote = (havequote) ? FALSE : TRUE;
            if ( CMwhite(arguments) && havequote == FALSE )
                break;
            arguments++;
        }
	/*
	** 	Put together a command line to create a process with.
	**      - 4 blank separators, quotes, null termination 
	*/
	command_line_length = STlength(arguments) + STlength(iidbms) + 
				STlength(iirun) + 6 + 1; 
	if((command_line = (char *)
		MEreqmem(0, command_line_length, TRUE, NULL)) == NULL)
	{
		error(ERx("Request for memory failed"),NULL);
	}

	STprintf( command_line, "%s \"%s\" %s", iirun, iidbms, arguments );

	/*
	**	Save standard out's handle, to be restored later.
	*/
	hStdout = GetStdHandle(STD_OUTPUT_HANDLE);

 	/*
	**      Initialize the security attributes structure that will
	**      be used to make the pipe handles inheritable.
	*/
	sa.nLength = sizeof(sa);
	sa.lpSecurityDescriptor = NULL;
	sa.bInheritHandle = TRUE;       /* Make object inheritable */

	/*
	**	Define a anonymous pipe to catch the server's startup message.
	*/
	if((Status = CreatePipe(&hRead,&hWrite,&sa,pipe_size)) != TRUE)
	{
		error(ERx("CreatePipe failed"),ERx("error code = "));
	}

	SetStdHandle(STD_OUTPUT_HANDLE,hWrite);

 	/*
	**      Initialize the security attributes structure that will
	**      be used to make the pipe handles inheritable.
	*/
	sa.nLength = sizeof(sa);
	sa.lpSecurityDescriptor = NULL;
	sa.bInheritHandle = TRUE;       /* Make object inheritable */

	/*
	**	Initialize the startup information structure.
	*/
	ZeroMemory(&si, sizeof(si));
	si.cb = sizeof(si);
	/* 
	**	Start it up.
	*/
	/*
	**	Start iirun which will start the server.
	*/
	if ((Status = CreateProcess(NULL,command_line,&sa,NULL,TRUE,
		HIGH_PRIORITY_CLASS, NULL,
	     NULL,&si,&ProcessInfo)) != TRUE)
	{
		DWORD dwError = GetLastError();
		switch(dwError)
		{
		     case ERROR_ACCESS_DENIED:
			error(ERROR_REQ_PRIVILEGE, ERx(""));
			break;
		     case ERROR_ELEVATION_REQUIRED:
			error(ERROR_DENIED_PRIVILEGE, ERROR_REQ_ELEVATION);
			break;
		     default:				
			error(ERx("CreateProcess failed"),ERx("error code = "));
			break;
		}
	}

	SetStdHandle(STD_OUTPUT_HANDLE,hStdout);

	for (;;)
	{
	    char	*tmpptr;

	    if((Status = ReadFile(hRead,&buffer,bufferl,&datal,NULL)) != TRUE)
	    {
		error(ERx("ReadFile failed"),ERx("error code = "));
	    }

	    buffer[datal] = '\0';	 		
	    if ((tmpptr = STstrindex(buffer, "PASS\n", 0, FALSE)))
	    {
		*tmpptr = '\0';
		if (STlength(buffer))
		    SIfprintf(stdout, "%s", buffer);

		break;
	    }

	    SIfprintf(stdout, "%s", buffer);

	    if ((tmpptr = STstrindex(buffer, bad_msg, 0, FALSE)))
	    {
		*tmpptr = '\0';
		if (STlength(buffer))
		    SIfprintf(stdout, "%s", buffer);

		failed = TRUE;
		break;
	    }
	}

	/*
	**	Close handles since we don't need them anymore.
	*/
	CloseHandle(ProcessInfo.hThread);
	CloseHandle(ProcessInfo.hProcess);
	CloseHandle(hRead);
	CloseHandle(hWrite);

	if (failed &&
	    STscompare(server_type, STlength(server_type), "gcb", 3) != 0 &&
	    STscompare(server_type, STlength(server_type), "gcc", 3) != 0 &&
	    STscompare(server_type, STlength(server_type), "jdbc", 4) != 0)
	{
		SIfprintf( stderr,"\n%s: server would not start.\n",
			   iirundbms );

		SIfprintf(stderr,
		" %s must be set in your environment.\n", 
		    SystemLocationVariable );

		SIfprintf(stderr,
		" Has the csinstall program been run?\n");

		SIfprintf(stderr,
		" %s_DATABASE, %s_CHECKPOINT, %s_JOURNAL and %s_DUMP\n",
		    SystemVarPrefix,
		    SystemVarPrefix,
		    SystemVarPrefix,
		    SystemVarPrefix );

		SIfprintf(stderr,
		" must also be set. See %s_CONFIG\\symbol.tbl.\n",
		    SystemVarPrefix );

		SIfprintf(stderr,
		" Check the file '%%%s%%\\%s\\files\\errlog.log'\n",
		    SystemLocationVariable, SystemLocationSubdirectory );

		SIfprintf(stderr,
		" for more details concerning internal errors.\n");

		SIfprintf(stderr,
		" See your Installation and Operation Guide for more\n");

		SIfprintf(stderr,
		" information concerning server startup.\n");

		PCexit(FAIL);
	}
	else
	{
		PCexit(OK);
	}
}
Example #29
0
void
rf_att_dflt(i4 NumRels, char *RelList[])
{

    FE_ATT_QBLK        qblk;
    FE_ATT_INFO        attinfo;
    FE_REL_INFO        relinfo;
    register ATTRIB      id;
    i4         	       i = 0;
    bool               RepeatedField;
    char 	       ColName [FE_MAXNAME + 1];
    i4		       ins = 0;
    FE_RSLV_NAME	*rfa_ferslv[MQ_MAXRELS];
    RFCOLDESC		*coldesc;
    ATT			*attptr;
    char		*cname;
    ATTRIB		did;
    i4			real_cols;
    char		dsply_name[(FE_UNRML_MAXNAME + 1)];


    /*
    **  If the user went through the choose columns path, we will
    **  use that information to create the structures since we
    **  alredy have all the needed information.
    */
    if (IIRFcccount != 0)
    {
	En_n_attribs = IIRFcccount;
	real_cols = IIRFcccount - IIRFcdcount;

	/* Allocate memory for the ATT array. */
	if ((Ptr_att_top = (ATT *)FEreqmem((u_i4)Rst4_tag,
		(u_i4)(IIRFcccount*(sizeof(ATT))), TRUE, 
		(STATUS *)NULL)) == NULL)
	{
		IIUGbmaBadMemoryAllocation(ERx("rf_att_dflt - Ptr_att_top"));
	}

	/*
	**  Step through the set of column names.  Deleted ones are
	**  placed at the end of the array.  We need to keep them
	**  around so that the user can add them back in the layout
	**  frame.
	*/
	for (i = 0, id = 0, did = real_cols, coldesc = IIRFcollist;
		i < IIRFcccount; i++, coldesc++)
	{
		if (coldesc->deleted)
		{
			attptr = &(Ptr_att_top[did++]);
			attptr->pre_deleted = TRUE;
		}
		else
		{
			attptr = &(Ptr_att_top[id++]);
		}
		cname = coldesc->name;
		attptr->att_name = FEtsalloc(Rst4_tag, cname);

		/* check if attribute name is a keyword */

		if (!St_silent && (r_gt_pcode(cname) != PC_ERROR ||
			r_gt_wcode(cname) != A_ERROR ||
			r_gt_vcode(cname) != VC_NONE ||
			r_gt_cagg(cname) ||
			STcompare(cname, NAM_REPORT) == 0 ||
			STcompare(cname, NAM_PAGE) == 0 ||
			STcompare(cname, NAM_DETAIL) == 0))
		{
			IIUGmsg(ERget(S_RF0047_Column_name_keyword), 
				(bool) FALSE, 1, cname);
		}

		/* set up the data type field */
		attptr->att_value.db_datatype = coldesc->datatype;
		attptr->att_prev_val.db_datatype = coldesc->datatype;
		attptr->att_value.db_length = coldesc->length;
		attptr->att_prev_val.db_length = coldesc->length;
		attptr->att_value.db_prec = coldesc->prec;
		attptr->att_prev_val.db_prec = coldesc->prec;
    
		/*
		** Do not allocate value buffers for un-supported datatypes.
		** We already let the user know that they're being ignored
		** when we passed through ChooseColumns, so don't do it again!
		*/
		if  (!IIAFfedatatype(&attptr->att_value))
		{
			attptr->att_value.db_data = (PTR)NULL;
			attptr->att_prev_val.db_data = (PTR)NULL;
		}
		else
		{
			if ((attptr->att_value.db_data =
				(PTR)FEreqmem((u_i4)Rst4_tag,
				(u_i4)(attptr->att_value.db_length),
				TRUE, (STATUS *)NULL)) == NULL)
			{
				IIUGbmaBadMemoryAllocation(ERx("rf_att_dflt - db_data"));
			}
			if ((attptr->att_prev_val.db_data = 
				(PTR)FEreqmem((u_i4)Rst4_tag,
				(u_i4)(attptr->att_prev_val.db_length),
				TRUE, (STATUS *)NULL)) == NULL)
			{
				IIUGbmaBadMemoryAllocation(ERx("rf_att_dflt - prev db_data"));
			}
		}

		/* flag to indicate when done */
		attptr->att_position = 0;
		attptr->att_lac = NULL;
	}

	return;
    }


    /* 
    ** determine number of attributes in base table: 
    */
    for (i = 0; i < NumRels; i ++)
    {
	/*
	** Decompose any owner.tablename, validate the components,
	** and normalize them for later use.
	*/
	if  ((rfa_ferslv[i] = (FE_RSLV_NAME *)MEreqmem((u_i4)0,
		(u_i4)sizeof(FE_RSLV_NAME),TRUE,
		(STATUS *)NULL)) == (FE_RSLV_NAME *)NULL)
	{
		IIUGbmaBadMemoryAllocation(ERx("rf_att_dflt - rfa_ferslv"));
	}
	if  ((rfa_ferslv[i]->name_dest = (char *)MEreqmem((u_i4)0,
		(u_i4)(FE_UNRML_MAXNAME+1),TRUE,(STATUS *)NULL)) == NULL)
	{
		IIUGbmaBadMemoryAllocation(ERx("rf_att_dflt - name_dest"));
	}

	if  ((rfa_ferslv[i]->owner_dest = (char *)MEreqmem((u_i4)0,
		(u_i4)(FE_UNRML_MAXNAME+1),TRUE,(STATUS *)NULL)) == NULL)
	{
		IIUGbmaBadMemoryAllocation(ERx("rf_att_dflt - owner_dest"));
	}
	rfa_ferslv[i]->name = RelList[i];
	rfa_ferslv[i]->is_nrml = FALSE;
	FE_decompose(rfa_ferslv[i]);
	if  ((rfa_ferslv[i]->owner_spec) &&
	     (((STcompare(IIUIcsl_CommonSQLLevel(),UI_LEVEL_65) < 0)
	     && (IIUIdcd_dist() == FALSE)
	     || IIUIdcd_dist() == TRUE && (STcompare(IIUIcsl_CommonSQLLevel(), 
	     UI_LEVEL_61) < 0))))
	{
		continue;
	}
	if  ((IIUGdlm_ChkdlmBEobject(rfa_ferslv[i]->name_dest,
				    rfa_ferslv[i]->name_dest,
				    rfa_ferslv[i]->is_nrml) == UI_BOGUS_ID) ||
	     ((rfa_ferslv[i]->owner_spec) &&
	      ((IIUGdlm_ChkdlmBEobject(rfa_ferslv[i]->owner_dest,
				      rfa_ferslv[i]->owner_dest,
				      rfa_ferslv[i]->is_nrml) == UI_BOGUS_ID) &&
	      STcompare(rfa_ferslv[i]->owner_dest, UI_FE_CAT_ID_65))))
	{
		continue;
	}
	if  (FE_resolve(rfa_ferslv[i],rfa_ferslv[i]->name_dest,
			rfa_ferslv[i]->owner_dest))
	{
		En_n_attribs += FEnumatts(rfa_ferslv[i]->name_dest,
					  rfa_ferslv[i]->owner_dest);
	}
    }

    /* 
    ** Allocate array of ATT structures:
    */
    if ((Ptr_att_top = (ATT *)FEreqmem((u_i4)Rst4_tag,
        (u_i4)(En_n_attribs*(sizeof(ATT))), TRUE, 
        (STATUS *)NULL)) == NULL)
    {
        IIUGbmaBadMemoryAllocation(ERx("rf_att_dflt - Ptr_att_top"));
    }

    /*
    ** For each relation fill out the ATT structures:
    */
    id = 0;

    if (En_SrcTyp == JDRepSrc)
	_VOID_ r_JDMaintTabList(JD_TAB_INIT_INS_CNT, NULL, NULL, NULL, NULL);

    for (i = 0; i < NumRels; i ++)
    {
        /* 
        ** open access to base table 
        */

	/* 
	** Fill out relinfo with table information, including table owner.
	*/
	FErel_ffetch(rfa_ferslv[i]->name_dest,rfa_ferslv[i]->owner_dest,
		     &relinfo);
	MEfree((PTR)rfa_ferslv[i]->name_dest);
	MEfree((PTR)rfa_ferslv[i]->owner_dest);
	MEfree((PTR)rfa_ferslv[i]);
       	FEatt_fopen(&qblk, &relinfo);

    	if (En_SrcTyp == JDRepSrc)
	    _VOID_ r_JDMaintTabList(JD_TAB_TAB_ADV_INS_CNT, NULL, 
			relinfo.name, relinfo.owner, &ins);

        /* 
        ** For each attribute in table, fill ATT structure 
        ** (make sure no DB access will take place in this loop!) 
        */
        while (FEatt_fetch(&qblk, &attinfo) == OK)
        {
            register ATT    *r_att;
            register ATTRIB chk_id;
            register char    *attname;

            attname = attinfo.column_name;

            /*
            ** Check for duplicate column names. If found one, and 
	    ** the source of data is not a JoinDef we have a problem,
	    ** Bug #5952:
            */
            RepeatedField = FALSE;
	    chk_id = id - 1;
	    while ((--chk_id >= 0) && (!RepeatedField))
	    {
                register ATT *chk_p = &(Ptr_att_top[chk_id]);
                if (STcompare(chk_p->att_name, attname) == 0)
                    RepeatedField = TRUE;
            }

            if ((RepeatedField) && (En_SrcTyp == TabRepSrc))
	    {
            	r_error(0x2C8, FATAL, attname, NULL);
	    }

	    /*
	    ** Make sure that if the source of data is a JoinDef 
	    ** the attribute is being used, and if it's being used 
	    ** in more than one table get the constructed name for 
	    ** it.  Be sure and include the owner in the table look-up!
	    */
	    if (En_SrcTyp == JDRepSrc)
	    {
		i4 cnt = 0;

		/*
		** If we can't find the field then it's not being used so 
		** skip it:
		*/
		if (!r_JDMaintAttrList(JD_ATT_GET_FIELD_CNT,
			r_JDTabNameToRv(relinfo.name, relinfo.owner, ins),
			attname, &cnt))
		   continue;

		
		if (cnt > 1)
		{
		  _VOID_ r_JDMaintAttrList(JD_ATT_GET_ATTR_NAME,
			r_JDTabNameToRv(relinfo.name, relinfo.owner, ins),
			attname, &ColName [0]);
		  attname = ColName;
		}
	    }

            r_att = &(Ptr_att_top[id++]);
            r_att->att_name = FEtsalloc(Rst4_tag, attname);
    
            /* check if attribute name is a keyword */
    
            if (!St_silent && (r_gt_pcode(attname) != PC_ERROR ||
                      r_gt_wcode(attname) != A_ERROR ||
                      r_gt_vcode(attname) != VC_NONE ||
                      r_gt_cagg(attname) ||
                      STcompare(attname, NAM_REPORT) == 0 ||
                      STcompare(attname, NAM_PAGE) == 0 ||
                      STcompare(attname, NAM_DETAIL) == 0))
            {
                IIUGmsg(ERget(S_RF0047_Column_name_keyword), 
                    (bool) FALSE, 1, attname);
            }

            /* set up the data type field */
            r_att->att_value.db_datatype = attinfo.adf_type;
            r_att->att_prev_val.db_datatype = attinfo.adf_type;
            r_att->att_value.db_length = attinfo.intern_length;
            r_att->att_prev_val.db_length = attinfo.intern_length;
            r_att->att_value.db_prec = attinfo.intern_prec;
            r_att->att_prev_val.db_prec = attinfo.intern_prec;
    
	    /*
	    ** Do not allocate value buffers for un-supported datatypes.
	    ** Let the user know that they're being ignored.
	    */
	    if  (!IIAFfedatatype(&r_att->att_value))
	    {
		_VOID_ IIUGxri_id(&attinfo.column_name[0],
				  &dsply_name[0]);
		IIUGerr(E_RW1414_ignored_attrib,
			UG_ERR_ERROR,1,&dsply_name[0]);
		r_att->att_value.db_data = (PTR)NULL;
		r_att->att_prev_val.db_data = (PTR)NULL;
	    }
	    else
	    {
		if ((r_att->att_value.db_data =
				(PTR)FEreqmem((u_i4)Rst4_tag,
					(u_i4)(r_att->att_value.db_length),
					 TRUE, (STATUS *)NULL)) == NULL)
		{
		    IIUGbmaBadMemoryAllocation(ERx("rf_att_dflt - db_data"));
		}
		if ((r_att->att_prev_val.db_data = 
				(PTR)FEreqmem((u_i4)Rst4_tag,
					(u_i4)(r_att->att_prev_val.db_length),
					TRUE, (STATUS *)NULL)) == NULL)
		{
		    IIUGbmaBadMemoryAllocation(ERx("rf_att_dflt - prev db_data"));
		}
	    }

            r_att->att_position = 0;    /* flag to indicate when done */
            r_att->att_lac = NULL;
        }
        FEatt_close(&qblk);

    } /* for */

    /*
    ** Just in case if we have skipped any attributes, 
    ** we're leaking memory though:  Note that unsupported
    ** datatypes will not be reflected as skipped as far as the
    ** id count is concerned!
    */
    En_n_attribs = id;

    return;

}
Example #30
0
VOID
do_crack_cmd(i4 argc, char **argv)
{
	i4	i;
	i4	argc_remain;
	i4	obj_params;
	bool	rn_params;
	bool	bogus_param;
	bool	all_param;
	OOID	del_obj_type;
	STATUS	c;
	char	*with_ptr;
	char	*user_flag;
	char	*group_flag;
	char	*pwd_flag;
	char	*tmp_ptr;
	FE_DEL	*fd;
	FE_DEL	*prev_fd;
	char	pr_buf[256];		/* Holds any current prompt */


	/*
	** Default to no wildcard expansion and no specified object type.
	** Indicate no names seen yet on command line, and no bogus
	** parameters.  Indicate no object type specifications (there
	** should never be more than one).
	** Track remaining command line parameters.
	*/
	Dobj_wildcard = FALSE;
	del_obj_type = OC_UNDEFINED;
	obj_params = 0;
	rn_params = FALSE;
	bogus_param = FALSE;
	all_param = FALSE;
	argc_remain = argc - 1;	/* Bypass argv[0] - the program name!	*/
	Dobj_database = NULL;   /* assume no database name b66456       */

	i = 1;			/* First pull out any flags	*/
	while (i < argc)
	{
		if  (*(argv[i]) == '-')	/* Flag found. Set and clear out */
		{
			switch(*(argv[i] + 1))
			{
			case('r'):
			case('R'):
				CVlower((argv[i] + 1));
				if  (STcompare((argv[i] + 1),DO_RPT_FLAG) == 0)
				{
					del_obj_type = OC_REPORT;
					Dobj_pr_str = ERget(F_DE0008_Rep);
					obj_params++;
				}
				else
				{
					bogus_param = TRUE;
				}
				break;
			case('f'):
			case('F'):
				CVlower((argv[i] + 1));
				if  (STcompare((argv[i] + 1),DO_FORM_FLAG) == 0)
				{
					del_obj_type = OC_FORM;
					Dobj_pr_str = ERget(F_DE0004_Form);
					obj_params++;
				}
				else
				{
					bogus_param = TRUE;
				}
				break;
			case('j'):
			case('J'):
				CVlower((argv[i] + 1));
				if  (STcompare((argv[i] + 1),DO_JD_FLAG) == 0)
				{
					del_obj_type = OC_JOINDEF;
					Dobj_pr_str = ERget(F_DE0006_Jdef);
					obj_params++;
				}
				else
				{
					bogus_param = TRUE;
				}
				break;
			case('g'):
			case('G'):
				tmp_ptr = STalloc(argv[i]);
				CVlower((tmp_ptr + 1));
				if  (STcompare((tmp_ptr + 1),DO_GRAF_FLAG) == 0)
				{
					del_obj_type = OC_GRAPH;
					Dobj_pr_str = ERget(F_DE0005_Graph);
					obj_params++;
				}
				else if (*(argv[i] + 1) == 'G')
				{
					Dobj_gidflag = argv[i];	
				}
				else
				{
					bogus_param = TRUE;
				}
				MEfree((PTR)tmp_ptr);
				break;
			case('a'):
			case('A'):
				CVlower((argv[i] + 1));
				if  (STcompare((argv[i] + 1),DO_APPL_FLAG) == 0)
				{
					del_obj_type = OC_APPL;
					Dobj_pr_str = ERget(F_DE0003_App);
					obj_params++;
				}
				else if  (STcompare((argv[i] + 1),
						    DO_ALL_FLAG) == 0)
				{
					del_obj_type = OC_OBJECT;
					/*
					** No prompt string for -all
					*/
					Dobj_pr_str = ERget(F_DE0009_Dobj_O);
					all_param = TRUE;
				}
				else
				{
					bogus_param = TRUE;
				}
				break;
			case('q'):
			case('Q'):
				CVlower((argv[i] + 1));
				if  (STcompare((argv[i] + 1),DO_QBF_FLAG) == 0)
				{
					del_obj_type = OC_QBFNAME;
					Dobj_pr_str = ERget(F_DE0007_Qbfnm);
					obj_params++;
				}
				else
				{
					bogus_param = TRUE;
				}
				break;
			case('i'):
			case('I'):
				CVlower((argv[i] + 1));
				if  (STcompare((argv[i] + 1),DO_INCL_FLAG) == 0)
				{
					/*
					** Clear out the flag so we don't see
					** it when we look for DB and FE object
					** names.
					*/
					argv[i] = NULL;
					i++;
					if  (i >= argc)
					{
						IIUGerr(E_DE000B_Dobj_no_file,
							UG_ERR_ERROR,0);
						FEexits(ERx(""));
						PCexit(FAIL);
						break;
					}
					Dobj_dfile = argv[i];
				}
				else
				{
					bogus_param = TRUE;
				}
				break;
			case('s'):
			case('S'):
				CVlower((argv[i] + 1));
				if  (STcompare((argv[i] + 1),DO_QT_FLAG) == 0)
				{
					Dobj_silent = TRUE;
				}
				else
				{
					bogus_param = TRUE;
				}
				break;
			case('u'):
			case('U'):
				Dobj_uflag = argv[i];
				break;
			case('w'):
			case('W'):
				CVlower((argv[i] + 1));
				if  (STcompare((argv[i] + 1),DO_WILD_FLAG) == 0)
				{
					Dobj_wildcard = TRUE;
				}
				else
				{
					bogus_param = TRUE;
				}
				break;
			case('P'):	/* -P (password) flag set	*/
				Dobj_passflag = argv[i];	
				break;
			default:
				bogus_param = TRUE;
				break;
			}
			if  (bogus_param)
			{
				IIUGerr(E_DE000A_Dobj_bad_flag,
					UG_ERR_ERROR,2,argv[i],
					ERget(E_DE0014_Dobj_syntax));
				FEexits(ERx(""));
				PCexit(FAIL);
			}
			/*
			** Clear out the flag so we don't see it when
			** we look for DB and FE object names.
			*/
			argv[i] = NULL;
			argc_remain--;
		}
		i++;
	}


# ifdef DGC_AOS
	with_ptr = STalloc(ERx("dgc_mode='reading'");
	IIUIswc_SetWithClause(with_ptr);
# else
	with_ptr = ERx("");
# endif

	/*
	** If -all was specified, then we can't have -wildcard, -include,
	** object type specifications, or objects names as well.  argc_remain
	** should at most reflect a database name.
	*/
	if  ((all_param) &&
	     ((Dobj_wildcard) || (Dobj_dfile != NULL) ||
	      (obj_params > 0) || (argc_remain > 1)))
	{
		IIUGerr(E_DE0012_Dobj_badall,UG_ERR_ERROR,1,
			ERget(E_DE0014_Dobj_syntax));
		FEexits(ERx(""));
		PCexit(FAIL);
	}

	/*
	** If multiple object types were specified, then abort!
	*/
	if  (obj_params > 1)
	{
		IIUGerr(E_DE0015_Dobj_multype,UG_ERR_ERROR,1,
			ERget(E_DE0014_Dobj_syntax));
		FEexits(ERx(""));
		PCexit(FAIL);
	}
	/*
	** If no object type was specified, then abort!
	*/
	if  (del_obj_type == OC_UNDEFINED)
	{
		IIUGerr(E_DE0013_Dobj_notype,UG_ERR_ERROR,1,
			ERget(E_DE0014_Dobj_syntax));
		FEexits(ERx(""));
		PCexit(FAIL);
	}

	/*
	** Check to see that the database name was specified.
	** If so, it will be the first non-flag parameter.
	** If not, ask for one:
	*/
	i = 1;
	while (i < argc)
	{
		if  (argv[i] == NULL)
		{
		/*
		** If we reached a used option,
		**   then the database name is missing.  b66456
		*/
			break;
			/* i++; */
			/* continue; */
		}

		/*
		** If we reached an option then, no dbname  b66456
		*/
		if (*argv[i] == '-')
		  break;

		Dobj_database = argv[i++];
		break;
	}

	if  (Dobj_database == NULL)
	{
		c = FEprompt(ERget(FE_Database),TRUE,(sizeof(pr_buf) - 1),
			     &pr_buf[0]);
		Dobj_database = STalloc(&pr_buf[0]);
	}

	/*
	** If the '-P' flag has been set, prompt for the password
	*/
	if  (Dobj_passflag != NULL)
	{
		/*
		** If there is something wrong with the '-P' flag, such as the
		** user has specified the password on the command line,
		** IIUIpassword() will return NULL.  In such cases bail out.
		*/
		if  ((Dobj_passflag = IIUIpassword(Dobj_passflag)) == NULL)
		{
			IIUGerr(E_DE000A_Dobj_bad_flag,UG_ERR_ERROR,2,
				ERx("-P"),ERget(E_DE0014_Dobj_syntax));
			FEexits(ERx(""));
			PCexit(FAIL);
		}
	}

	/*
	** Open the database, will abort on FAIL.  We do it here because we
	** need to establish the invoking user name before we process the FE
	** object names.  We use "user" since owners of FE objects are always
	** stored in the FE catalogs as lower case.  This will have to change
	** to suser when we fully support authorization identifiers as
	** delimited identifiers, which can be other than lower case
	** (specifically FIPS which is UI_MIXED_CASE).
	*/
	user_flag = ERx("");
	group_flag = ERx("");
	pwd_flag = ERx("");
	if  (Dobj_uflag != NULL)
	{
		user_flag = Dobj_uflag;
	}
	if  (Dobj_gidflag != NULL)
	{
		group_flag = Dobj_gidflag;
	}
	if  (Dobj_passflag != NULL)
	{
		pwd_flag = Dobj_passflag;
	}
	if  (FEingres(Dobj_database,user_flag,group_flag,pwd_flag,NULL) != OK)
	{
		IIUGerr(E_DE0004_NoOpen,UG_ERR_ERROR,0);
		FEexits(ERx(""));
		PCexit(FAIL);
	}

	/*
	** If -all was specified, force a wildcard expansion of "%".
	** do_expand_name() will recognize del_obj_type == OC_OBJECT
	** as being special.
	*/
	if  (del_obj_type == OC_OBJECT)
	{
		Dobj_wildcard = TRUE;
		fd = (FE_DEL *)MEreqmem(0,sizeof(FE_DEL),TRUE,NULL);
		Ptr_fd_top = fd;
		prev_fd = (FE_DEL *)NULL;
		Cact_fd = fd;
		Cact_fd->fd_name_info = (FE_RSLV_NAME *)MEreqmem(0,
						sizeof(FE_RSLV_NAME),TRUE,NULL);
		Cact_fd->fd_name_info->name = STalloc(ERx("%"));
		Cact_fd->fd_below = (FE_DEL *)NULL;
		Cact_fd = do_expand_name(Cact_fd,&prev_fd,del_obj_type);
		return;
	}

	/*
	** The rest of the parameters will be FE object names.
	*/
	while (i < argc)
	{
		if  (argv[i] == NULL)
		{
			i++;
			continue;
		}
		rn_params = TRUE;
		fd = (FE_DEL *)MEreqmem(0,sizeof(FE_DEL),TRUE,NULL);
		if  (Ptr_fd_top == (FE_DEL *)NULL)
		{
			Ptr_fd_top = fd;
			prev_fd = (FE_DEL *)NULL;
		}
		else
		{
			Cact_fd->fd_below = fd;
			prev_fd = Cact_fd;
		}
		Cact_fd = fd;
		Cact_fd->fd_name_info = (FE_RSLV_NAME *)MEreqmem(0,
						sizeof(FE_RSLV_NAME),TRUE,NULL);
		Cact_fd->fd_name_info->name = STalloc(argv[i]);
		Cact_fd->fd_below = (FE_DEL *)NULL;
		Cact_fd = do_expand_name(Cact_fd,&prev_fd,del_obj_type);
		/*
		** Returns ptr to current end of FE_DEL chain, which may be
		** NULL if (still) 1st and no match.  If no match, the FE_DEL
		** and its name will have been de-allocated, and prev_fd and
		** Ptr_fd_top will have been be altered as required.
		*/
		i++;
	}

	if  (Dobj_dfile != NULL)
	{
		do_ifile_parse(Dobj_dfile,del_obj_type);
	}	

	/*
	** If we found anything, then we're all done
	*/
	if  (Ptr_fd_top != (FE_DEL *)NULL)
	{
		return;
	}

	/*
	** If we had FE object names either on the command line or in a
	** file but they all failed expansion/resolution, then don't prompt
	** for any names!
	*/
	if  ((rn_params) || (Dobj_dfile != NULL))
	{
		IIUGerr(E_DE000C_Dobj_no_input,UG_ERR_ERROR,1,
			Dobj_pr_str);
		FEexits(ERx(""));
		PCexit(FAIL);
	}

	/*
	** Prompt for no FE object name - either on
	** the command line or in a -list file.  Note that
	** we ignore any Dobj_silent in this instance.
	*/
	while (TRUE)
	{
		c = FEprompt(Dobj_pr_str,FALSE,(sizeof(pr_buf) - 1),&pr_buf[0]);
		if  ((c != OK) || (STtrmwhite(&pr_buf[0]) == 0))
		{
			/*
			** When NULL string entered (or error), all done
			*/
			break;
		}
		fd = (FE_DEL *)MEreqmem(0,sizeof(FE_DEL),TRUE,NULL);
		if  (Ptr_fd_top == (FE_DEL *)NULL)
		{
			Ptr_fd_top = fd;
			prev_fd = (FE_DEL *)NULL;
		}
		else
		{
			Cact_fd->fd_below = fd;
			prev_fd = Cact_fd;
		}
		Cact_fd = fd;
		Cact_fd->fd_name_info = (FE_RSLV_NAME *)MEreqmem(0,
						sizeof(FE_RSLV_NAME),TRUE,NULL);
		Cact_fd->fd_name_info->name = STalloc(&pr_buf[0]);
		Cact_fd->fd_below = (FE_DEL *)NULL;
		Cact_fd = do_expand_name(Cact_fd,&prev_fd,del_obj_type);
	}

	if  (Ptr_fd_top == (FE_DEL *)NULL)
	{
		IIUGerr(E_DE000C_Dobj_no_input,UG_ERR_ERROR,1,Dobj_pr_str);
		FEexits(ERx(""));
		PCexit(FAIL);
	}

	return;
}