Example #1
0
STATUS
NMpathIng(
char	**name)
{
	static	char	t_Pathname[255] = "";
		char	*t_PathPtr;
		STATUS	status = OK;

	if ((t_PathPtr = NMgetenv(SystemLocationVariable)) == NULL)
	{
		status = NM_INGUSR;
	}
	else
	{
	    /* If the path is a rooted logical, overwrite the last ']' */
	    size_t l = STlength(t_PathPtr);
	    if (t_PathPtr[l - 2] == '.' && t_PathPtr[l - 1] == ']')
	    {
		t_PathPtr[l - 1] = EOS;
		STpolycat(3, t_PathPtr, SystemLocationSubdirectory, "]",
		    t_Pathname);
	    }
	    else
	    {
		t_PathPtr  = STpolycat(4, t_PathPtr, "[", 
				SystemLocationSubdirectory, "]",  t_Pathname);
	    }
	}

	*name = t_Pathname;

	return(status);
}
Example #2
0
static char *
ns_login( API_PARSE *parse, i4 buflen, char *buffer )
{
    char	*user, *pwd, *value;
    i4		usrlen, pwdlen, len;
    STATUS	status;

    if ( parse->opcode == API_KW_ADD )
    {
	/*
	** Password required and must be sent encrypted.
	*/
	user = ns_resolve_param( parse, API_FIELD_PARM, FALSE );
	usrlen = STlength( user );
	pwd  = ns_resolve_param( parse, API_FIELD_PARM + 1, FALSE );
	pwdlen = (STlength( pwd ) + 8) * 2;	/* estimate encrypted length */
    }
    else
    {
	/*
	** Use GCN wild card format for password.
	*/
	user = ns_resolve_param( parse, API_FIELD_PARM, TRUE );
	usrlen = STlength( user );
	pwd = empty;
	pwdlen = 0;
    }

    /* Allow room for EOS and separating ',' */
    len = usrlen + pwdlen + 2;

    /*
    ** Allocate storage for the final value
    ** and build it from the parameters
    ** retrieved above.
    */
    value = (len <= buflen) ? buffer
    			    : (char *)MEreqmem( 0, len, FALSE, &status );
    if ( ! value )
    {
	IIAPI_TRACE( IIAPI_TR_FATAL )
	    ( "ns_login: can't allocate value buffer\n" );
	return( NULL );
    }

    if ( parse->opcode != API_KW_ADD )
	STpolycat( 3, user, ",", pwd, value );
    else
    {
	/*
	** Encrypt password directly into formatted output.
	*/
	STpolycat( 2, user, ",", value );
	gcu_encode( user, pwd, &value[ usrlen + 1 ] );
    }

    return( value );
}
Example #3
0
STATUS
append_line(char *aline,i4 newline)
{
    char                   buffer [TEST_LINE+5] ;
    char                  *cp = aline ;

    /*
	line is printed long enough to accomodate SCR output
    */

/*
	This loop breaks up long lines and puts the continuation character
	at the TEST_LINE+2 position.
*/

    while (STlength(cp) > TEST_LINE+3)
    {
	STprintf(buffer, ERx("%.*s%s\n"), TEST_LINE+2, cp, cont_char);
	SIputrec(buffer,logptr);
	cp += TEST_LINE+2;
    }

    if (newline)
    {
	STpolycat(2,cp,ERx("\n"),buffer);
	return(SIputrec(buffer,logptr));
    }
    else
	return(SIputrec(cp,logptr));

}
Example #4
0
bool
ask_for_conditional(WINDOW *askW,char edCAns)
{
    char                   cond_exp ;

    cond_exp  = EOS;
    if (conditional_str == NULL)
	conditional_str = SEP_MEalloc(SEP_ME_TAG_NODEL, TEST_LINE+1, TRUE,
				      (STATUS *) NULL);
    if (conditional_old == NULL)
	conditional_old = SEP_MEalloc(SEP_ME_TAG_NODEL, TEST_LINE+1, TRUE,
				      (STATUS *) NULL);
    if (conditional_prompt == NULL)
	conditional_prompt = SEP_MEalloc(SEP_ME_TAG_NODEL, TEST_LINE+1, TRUE,
					 (STATUS *) NULL);

    if ((*conditional_str == EOS) && (SEP_IF_EXPRESSION != NULL) &&
        (*SEP_IF_EXPRESSION != EOS))
	STcopy(SEP_IF_EXPRESSION, conditional_str);

    STcopy(conditional_str, conditional_old);
#ifdef NT_GENERIC
    STprintf(conditional_prompt,ERx(" IF (%s) >"),conditional_str);
#else
    STprintf(conditional_prompt,ERx("%s%s%s%s%s IF (%s) >%s"),REG_CHAR,
	     ATTR_OFF, PROMPT_POS, DEL_EOL, REV_VIDEO, conditional_str,
	     ATTR_OFF);
#endif

    if (edCAns == EOS)
	get_string(askW, conditional_prompt, conditional_str);

    if ((conditional_str == NULL) || (*conditional_str == EOS))
    {
	if (*conditional_old == EOS)
	{
	    if (edCAns == EOS)
		put_message(askW,
			    ERx("No conditional expression for this Canon."));
	    return (FALSE);
	}
	else
	{
	    STcopy(conditional_old, conditional_str);
	}
    }
    else if (STskipblank(conditional_str, STlength(conditional_str)) == NULL)
    {
	*conditional_str = EOS;
	*conditional_old = EOS;
	if (edCAns == EOS)
	    put_message(askW, ERx("No conditional expression for this Canon."));
	return (FALSE);
    }

    STpolycat(3, ERx(" IF ("), conditional_str, ERx(") "), conditional_prompt);
    return (TRUE);
}
Example #5
0
/*
** Name: read_fm_command
**
** History:
**	17-Oct-2008 (wanfr01)
**	    Bug 121090
**	    Added new parameter to get_commmand
*/
STATUS
read_fm_command(FILE *aFile)
{
    STATUS                 ioerr ;
    STATUS                 ret_status = OK ;

    ioerr = get_command(aFile, NULL,FALSE);
    if ((ioerr == FAIL)||(ioerr == ENDFILE))
    {
        if (ioerr == FAIL)
        {
            STpolycat(3,ErrF,ERx("reading"),comment,msg);
        }
        else
        {
            STpolycat(3,ErrF,ERx("reading (EOF)"),comment,msg);
        }
        disp_line(msg,0,0);
        ret_status = FAIL;
    }
    return (ret_status);
}
Example #6
0
bool
Eval_If(char *commands[])
{

    STATUS                 eval_err ;
    char                   buffer [128] ;
    char                  *tokptr [12] ;
    register i4            tok_ctr = 0 ;
    i4                     answer = TRUE ;


    for (tok_ctr=0; tok_ctr<12; tok_ctr++) tokptr[tok_ctr] = 0;

    *buffer = EOS;
    for (tok_ctr=2; commands[tok_ctr]; tok_ctr++)
	STcat(buffer, commands[tok_ctr]);	/* Condense the expression. */


    *msg = EOS;

    answer = SEP_Eval_If( buffer, &eval_err, msg);

    if (eval_err != OK)
    {
	testGrade = FAIL;
	if (*msg == EOS)
	{
	    disp_line(STpolycat(4,ErrC,ERx("Evaluate Expresion <"),buffer,
				ERx(">"),msg),0,0);
	}
	else
	{
	    disp_line(msg,0,0);
	}
	append_line(msg,1);
        return(FAIL);
    }

    if (answer == TRUE)
    {
	return (TRUE);
    }
    else
    {
	return (FALSE);
    }

}
Example #7
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 #8
0
VOID
qee_d1_qid(
    QEE_DSH		*v_dsh_p)
{
    QEE_DDB_CB	    *qee_p = v_dsh_p->dsh_ddb_cb;
    DB_CURSOR_ID    *csr_p;
    SYSTIME	    tm_now;
    char	    hi_ascii[QEK_015_LEN],
                lo_ascii[QEK_015_LEN],
                pid_ascii[QEK_015_LEN],
                temp[QEK_050_LEN + DB_CURSOR_MAXNAME];
    PID		    pid;		/* an i4 */


    PCpid(& pid);			/* get process (server) id */
    CVla(pid, pid_ascii);		/* convert to ascii */

    TMnow(& tm_now);

    csr_p = & qee_p->qee_d4_given_qid;
    csr_p->db_cursor_id[0] = tm_now.TM_secs;
    csr_p->db_cursor_id[1] = tm_now.TM_msecs;
    CVla(tm_now.TM_secs, hi_ascii);
    CVla(tm_now.TM_msecs, lo_ascii);
    STpolycat((i4) 4,			/* 4 constituent pieces */
              "dd", lo_ascii, hi_ascii, pid_ascii, temp);
    MEmove(STlength(temp), temp, ' ',
           DB_CURSOR_MAXNAME, csr_p->db_cur_name);

    csr_p = & qee_p->qee_d5_local_qid;
    csr_p->db_cursor_id[0] = 0;
    csr_p->db_cursor_id[1] = 0;
    MEfill(DB_CURSOR_MAXNAME, ' ', (PTR) csr_p->db_cur_name);

    return;
}
Example #9
0
STATUS
open_log(char *testPrefix,char *testSufix,char *username,char *errbuff)
{
    SYSTIME                atime ;
    char                   uname [20] ;
    char                   logFileName [MAX_LOC+1] ;
    char                   timestr [TEST_LINE] ;
    char                   buffer [MAX_LOC+1] ;
    char                  *dot = NULL ;
    char                  *cptr = NULL ;
	char				   year[5];

    if (shellMode)
        STpolycat(3, testPrefix, ERx("."), testSufix, logFileName);
    else if (updateMode)
            STpolycat(2, testPrefix, ERx(".upd"), logFileName);
         else
            STpolycat(2, testPrefix, ERx(".log"), logFileName);

    if (outputDir)
    {
	if (outputDir_type == PATH)
	{
	    STcopy(outputDir, buffer);
	    LOfroms(PATH, buffer, &logloc);
	    LOfstfile(logFileName, &logloc);
	    LOtos(&logloc, &cptr);
	}
	else
	{
	    LOtos(&outLoc,&cptr);
	}
	STcopy(cptr, logname);
    }
    else
        STcopy(logFileName, logname);
    
    
    if (LOfroms(FILENAME & PATH, logname, &logloc) != OK)
    {
	STprintf(errbuff,ERx("ERROR: could not get location for log file"));
	return(FAIL);
    }
    if (SIopen(&logloc,ERx("w"),&logptr) != OK)
    {
	STprintf(errbuff,ERx("ERROR: could not open log file"));
	return(FAIL);
    }

    if (!updateMode)
    {
	append_line(ERx("/*"),1);

	copyright_year(&year[0]);
	STprintf(buffer, ERx("Copyright (c) %s Ingres Corporation"), &year);
	append_line(buffer, 1);
	append_line(ERx(" "), 1);

	STprintf(buffer,ERx("\tTest Name: %s.%s"), testPrefix, testSufix);
	append_line(buffer,1);
	TMnow(&atime);
	TMstr(&atime,timestr);
	STprintf(buffer,ERx("\tTime: %s"),timestr);
	append_line(buffer,1);
	dot = uname;
	if (username == NULL || *username == '\0')
	    IDname(&dot);
	else
	    STcopy(username,uname);
	STprintf(buffer,ERx("\tUser Name: %s"),uname);
	append_line(buffer,1);
	STprintf(buffer, ERx("\tTerminal type: %s"), terminalType);
	append_line(buffer,1);
	append_line(ERx(" "),1);
    }

    return(OK);
}
Example #10
0
/*{
** Name: NMwritesyms - write the symbol table list to file.
**
** Description:
**    Write the symbol table list back out to the file.
**
**    This duplicates the function in ingunset.c, but shouldn't be in 
**    compatlib because no one else has any business writing the file.
**
** Inputs:
**	none.
**
** Output:
**	none.
**
**      Returns:
**          OK                         	    Function completed normally. 
**          FAIL                            Function completed abnormally.
**
** History:
**      20-jul-87 (mmm)
**          Updated to meet jupiter standards.
**	14-apr-89 (arana)
**	    When LOlast was added to update symbol table mod time,
**	    return value was saved off but not returned.
**	15-jul-93 (ed)
**	    adding <gl.h> after <compat.h>
**      29-sep-94 (cwaldman)
**          Changed check of NMopensyms return value to compare against
**          (FILE *)NULL (was NULL).
**          Changed write routine to write into a temporary file first,
**          check whether this file has been written OK, and rename
**          temporary file to symbol.tbl if it is alright. This is part
**          of the fix for bug 44445 (symbol.tbl disappears). There is
**          still a slight chance of something going wrong during the
**          rename, but in that case variables are at least preserved
**          in symbol.tmp.
**      19-oct-94 (abowler)
**          Minor correction to change above. Cal to SIopen should be
**          passed address of location structure. (Didn't show up as
**          a bug on su4_u42 !)
**      28-feb-95 (cwaldman)
**          Amendment to change on 29 Sep. Part of the check whether
**          the temporary symbol table had been written OK was to check
**          the file size. The check would return the file size if
**          check was OK and 0 otherwise. If a 0 was returned, the old
**          symbol.tbl would not be replaced. This made it impossible
**          to 'ingunset' the last variable in a symbol.tbl. Changed
**          'OK-check' to use -1 as error indicator.
**	02-jul-1996 (sweeney)
**	    Apply umask fix (bug #71890) from ingres63p
**	07-apr-2004 (somsa01)
**	    Added backup of symbol.tbl logic.
*/
STATUS
NMwritesyms()
{
    register SYM	*sp;
    FILE		*fp, *tfp = NULL;
    register i4 	status = OK;
    register i4 	closestat;
    char		buf[ MAXLINE + NULL_NL_NULL ];
    char		tbuf[ MAXLINE + NULL_NL_NULL ];
    i4			flagword, size, symcount = 0, bksymcount;
    STATUS		retval;
    LOCATION		t_loc;
    LOINFORMATION	loinfo;
    bool		perform_backup = TRUE;
    OFFSET_TYPE		bk_size;

    /*
    ** ensure sensible umask for symbol.tmp, as it will become symbol.tbl
    */
    PEsave();
    PEumask("rw-r--");
 
    if ((FILE *)NULL == (fp = NMopensyms( "r" )))
    {
	PEreset();
	return (NM_STOPN);
    }
    SIclose(fp);
 
    LOcopy(&NMSymloc, tbuf, &t_loc);
    if ( OK != LOfstfile("symbol.tmp", &t_loc) ||
         OK != SIopen(&t_loc, "w", &tfp))
    {
	return (NM_STOPN);
    }

    for ( sp = s_list; sp != NULL; sp = sp->s_next )
    {
	(VOID) STpolycat( 3, sp->s_sym, "\t", sp->s_val, buf );
	STmove( buf, ' ', MAXLINE, buf );

	buf[ MAXLINE - 1 ] = '\n';
	buf[ MAXLINE ] = '\0';
 
	if ( OK != (status = SIputrec(buf, tfp)))
	    break;

	symcount++;
    }
 
    /* Very interested in close status of file being written */
 
    closestat = SIclose( tfp );
    flagword = (LO_I_SIZE);
    size = (OK == LOinfo(&t_loc,&flagword,&loinfo) ? loinfo.li_size : -1);
 
    retval=(status != OK || closestat != OK || size == -1 ? NM_STAPP : OK);

    /* if file written ok update modification time */
    if(retval == OK)
    {
	LOrename(&t_loc, &NMSymloc);
	LOlast(&NMSymloc, &NMtime);
 
#if defined(su4_cmw)
	/* Now reset the old MAC label if any */
	if (NM_got_label)
	{
	    (void)setcmwlabel(NM_path, &NM_saved_label, SETCL_ALL);
	    NM_got_label=0;
	}
#endif

	/*
	** If we have no backup to check against, just do it. Otherwise,
	** make sure our new symbol table differs from the backup by at most
	** one symbol before performing a backup.
	*/
	if (LOexist(&NMBakSymloc) == OK)
	{
	    LOsize(&NMBakSymloc, &bk_size);
	    bksymcount = (i4)(bk_size / (MAXLINE + 1));
	    if (bksymcount != symcount && bksymcount != symcount - 1 &&
		bksymcount != symcount + 1)
	    {
		perform_backup = FALSE;
	    }
	}

	if (perform_backup)
	{
	    if (SIopen(&NMBakSymloc, "w", &tfp) == OK)
	    {
		for (sp = s_list; sp != NULL; sp = sp->s_next)
		{
		    STpolycat(3, sp->s_sym, "\t", sp->s_val, buf);
		    STmove(buf, ' ', MAXLINE, buf);

		    buf[MAXLINE - 1] = '\n';
		    buf[MAXLINE] = '\0';
 
               	    if ((status = SIputrec(buf, tfp)) != OK)
			break;
		}
 
		SIclose(tfp);
	    }
	} 
    }

    PEreset();
    return (retval);
}
Example #11
0
static STATUS
transform_login( char *ibuff, char *obuff )
{
    char	*pv[ 2 ];
    char	pbuff[ 128 ], tbuff[ 128 ];
    char	*pwd, *tmp;
    i4		len;
    STATUS	status;

    /*
    ** Isolate user ID and encrypted password.
    ** Ensure output buffer is large enough.
    ** Decrypt the password.
    */
    if ( gcu_words( ibuff, NULL, pv, ',', 2 ) < 2 )  pv[1] = "";

    len = STlength( pv[1] );
    pwd = (len < sizeof( pbuff )) 
          ? pbuff : (char *)MEreqmem( 0, len + 1, FALSE, NULL );

    if ( ! pwd )
    	status = E_GC0121_GCN_NOMEM;
    else
	status = gcn_login( GCN_VLP_CLIENT, 0, FALSE, pv[0], pv[1], pwd );

    /*
    ** Re-encrypt password for storage
    */
    if ( status == OK )
    {
	/*
	** Ensure temp buffer is large enough.
	*/
	len = (STlength( pwd ) + 8) * 2;

	tmp = (len < sizeof( tbuff )) 
	      ? tbuff : (char *)MEreqmem( 0, len + 1, FALSE, NULL );

	if ( ! tmp )
	    status = E_GC0121_GCN_NOMEM;
	else
	    status = gcn_login( GCN_VLP_LOGIN, 
	    			IIGCn_static.pwd_enc_vers, 
				TRUE, pv[0], pwd, tmp );
    }

    /*
    ** Rebuild the login tuple value.
    */
    if ( status == OK )
    {
	char vers[ 32 ];

	STprintf( vers, "V%d", IIGCn_static.pwd_enc_vers );
	STpolycat( 5, pv[0], ",", tmp, ",", vers, obuff );
    }

    if ( pwd != pbuff )  MEfree( (PTR)pwd );
    if ( tmp != tbuff )  MEfree( (PTR)tmp );
    return( status );
}
Example #12
0
DB_STATUS
qee_d2_tmp(
    QEF_RCB		*qef_rcb,
    QEE_DSH		*dsh,
    ULM_RCB		*ulm)
{
    DB_STATUS	    status = E_DB_OK;
    QEF_QP_CB	    *qp_p = dsh->dsh_qp_ptr;
    QEQ_DDQ_CB	    *ddq_p = & qp_p->qp_ddq_cb;
    QEE_DDB_CB	    *qee_p = dsh->dsh_ddb_cb;
    DB_CURSOR_ID    *csr_p;


    if (ddq_p->qeq_d3_elt_cnt > 0)
    {
        SYSTIME	    tm_now,
                    tm_last;
        char	    hi_ascii[QEK_015_LEN],
                    lo_ascii[QEK_015_LEN],
                    /*
                    		    pid_ascii[QEK_015_LEN],
                    */
                    temp[QEK_050_LEN+DB_MAXNAME];/* must be > DB_MAXNAME */
        DD_TAB_NAME    *name_p;
        i4	    *long_p;
        /*
        	PID	    pid;		** an i4 **
        */
        i4	    m, n;
        char	    *p, *q;
        u_i2	    hi_len,
                    /*
                    		    lo_len,
                    */
                    tmp_len;

#define	QEE_10SQL_NAME_LEN    10


        /* allocate space for array of temporary-table names and
        ** generate their names */

        /* 1.  allocate array for DD_TAB_NAMEs */

        ulm->ulm_psize = ddq_p->qeq_d3_elt_cnt * sizeof(DD_TAB_NAME);
        if (status = qec_malloc(ulm))
        {
            qef_rcb->error.err_code = ulm->ulm_error.err_code;
            qed_u10_trap();
            return(status);
        }

        qee_p->qee_d1_tmp_p = (DD_TAB_NAME *) ulm->ulm_pptr;
        /* ptr to array of DD_TAB_NAMEs */
        /* 2.  allocate array for i4 status */

        ulm->ulm_psize = ddq_p->qeq_d3_elt_cnt * sizeof(i4);
        if (status = qec_malloc(ulm))
        {
            qef_rcb->error.err_code = ulm->ulm_error.err_code;
            qed_u10_trap();
            return(status);
        }

        qee_p->qee_d2_sts_p = (i4 *)
                              ulm->ulm_pptr; 	/* ptr to array of i4s */

        /* initialize both allocated arrays */

        name_p = qee_p->qee_d1_tmp_p;
        long_p = qee_p->qee_d2_sts_p;

        tm_last.TM_secs = 0;
        tm_last.TM_msecs = 0;
        /*
        	PCpid(& pid);		** get process (server) id **
        	CVla(pid, pid_ascii);	** convert to ascii **
        */
        for (n = 0; n < ddq_p->qeq_d3_elt_cnt; n++)
        {
            /* 3.  generate temporary table name */

            TMnow(& tm_now);

            if (tm_now.TM_secs == tm_last.TM_secs)
            {
                if (tm_now.TM_msecs <= tm_last.TM_msecs)
                    tm_now.TM_msecs = tm_last.TM_msecs + 1;
            }
            CVla(tm_now.TM_secs, hi_ascii);
            CVla(tm_now.TM_msecs, lo_ascii);

            hi_len = STlength(hi_ascii);

            /* transpose the hi_ascii string to get lower digits */

            p = hi_ascii;
            q = hi_ascii + hi_len - 1;		/* backup past EOS */
            for (m = 0; m < (i4) hi_len - 1; m++)	/* do length - 1 characters */
            {
                *p = *q;
                p++;
                q--;
            }

            STpolycat((i4) 3,	/* 3 constituent pieces */
                      "z", lo_ascii, hi_ascii, temp);

            tmp_len = STlength(temp);

            /* use at most 10 characters */

            if (tmp_len > QEE_10SQL_NAME_LEN)
                tmp_len = QEE_10SQL_NAME_LEN;

            MEmove(tmp_len, temp, ' ', sizeof(DD_TAB_NAME),
                   (char *)name_p);

            STRUCT_ASSIGN_MACRO(tm_now, tm_last);
            /* save for comparison */
            name_p++;		/* pt to next slot */

            /* 4.  initialize status word for this table */

            *long_p = QEE_00M_NIL;
            long_p++;		/* pt to next status word */
        } /* for */
    }
    else
    {
        qee_p->qee_d1_tmp_p = (DD_TAB_NAME *) NULL;
        qee_p->qee_d2_sts_p = (i4 *) NULL;
    }

    /* 5.  initialize */

    qee_p->qee_d3_status = QEE_00Q_NIL;

    if (! (qp_p->qp_status & QEQP_RPT))
    {
        /* initialize if not repeat query */

        csr_p = & qee_p->qee_d4_given_qid;
        csr_p->db_cursor_id[0] = 0;
        csr_p->db_cursor_id[1] = 0;
        MEfill(DB_CURSOR_MAXNAME, ' ', (PTR) csr_p->db_cur_name);
    }

    csr_p = & qee_p->qee_d5_local_qid;
    csr_p->db_cursor_id[0] = 0;
    csr_p->db_cursor_id[1] = 0;
    MEfill(DB_CURSOR_MAXNAME, ' ', (PTR) csr_p->db_cur_name);

    return(status);
}
Example #13
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 #14
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 #15
0
STATUS
LOingpath(
char		*area,		/* "device" that the database is on */
char		*dbname,	/* ingres data base name */
char		*what,		/* path to db, ckp, jnl, or sort */
LOCATION	*fullpath)	/* set to full path of database */
{
	static	char	buffer[255];
	register char       *dbptr = dbname;
 	char 	*strptr = buffer;
	SIZE_TYPE try_raw = FALSE;
	STATUS	ret_val = OK;

	/* Only check for RAW if requested by dbname==LO_RAW */
	if ( (try_raw = (SIZE_TYPE)dbptr && STequal( dbptr, LO_RAW)) )
            dbptr = NULL;
	


	/* check for legal arguments */

	if ((area == NULL) || (*area == NULL) || 
             (what == NULL) || (*what == NULL))
		ret_val = LO_NULL_ARG;
	/* set up location */
	fullpath->string = buffer;

	/* create location */
	STcopy(area, strptr);
        strptr += STlength(strptr);

	/* add colon if not there */
	if(*(strptr - 1) != *COLON)
		*strptr++ = *COLON;

	STcopy("[INGRES.", strptr);
        strptr += STlength(strptr);

	/* add 'what' to path */
	STcopy(what, strptr);
        strptr += STlength(strptr);

	/*
        ** Raw locations are identified by the existence of the
        ** file "iirawdevice" (LO_RAW).
        */
        if ( try_raw )
               ret_val = OK;

	if ( !ret_val )
	{
	   /* if dbname exists then insert it */
	   if(dbptr != NULL && *dbptr != EOS)
		STpolycat(3, DOT, dbname, CBRK, strptr);
	   else		
	   {
		*strptr++ = *CBRK;	
		*strptr = NULL;
	   }
	   LOfroms(PATH, fullpath->string, fullpath);
	}
	return(ret_val);

}
Example #16
0
DB_STATUS
uleFormatFcn(
DB_ERROR    *dberror,
i4	    err_code,
CL_ERR_DESC *clerror,
i4	    flag,
DB_SQLSTATE *sqlstate,
char	    *msg_buffer,  
i4	    msg_buf_length,
i4	    *msg_length,
i4          *uleError,
PTR	    uleFileName,
i4	    uleLineNumber,
i4	    num_parms,
	    ... )
{

#define  NUM_ER_ARGS 12

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

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

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

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

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

    error_code = local_error_code = DBerror->err_code;

    MessageArea = (char*)&buffer.message;


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


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

    va_start( ap, num_parms );

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

    va_end( ap );

    *uleError = 0;

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

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

	if (status != OK)
	{
	    CL_ERR_DESC    junk;

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

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

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

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

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

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

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

	/* Get system message text. */

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

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

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

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

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

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

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

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

	/* Copy into callers buffer if requested. */

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

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

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

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

	if ( FileName )
	{

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

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

	/* Echo the message to II_DBMS_LOG, if defined */
	TRwrite(NULL, PrefixLen + length, (PTR)&buffer);
	
	status = ERsend(ER_ERROR_MSG, (PTR)&buffer,
		    PrefixLen + length, &sys_err);
    }
Example #17
0
STATUS
ME_alloc_shared(i4          flag,
                SIZE_TYPE   pages,
                char        *key,
                PTR         *memory,
                SIZE_TYPE   *allocated_pages,
                CL_ERR_DESC *err_code)
{
	STATUS          status;
	SIZE_TYPE       memsize;
#ifdef LP64
	LARGE_INTEGER	numbytes;
#endif
	HANDLE          name;
	HANDLE          map;
	PTR             temp;
	char            map_key[MAX_LOC+1];
	char            *install_code;
	char		*ObjectPrefix;

    SECURITY_ATTRIBUTES sa;
    
	CLEAR_ERR(err_code);
	GVshobj(&ObjectPrefix);

	if (key == NULL || *key == '\0') {
		return (ME_BAD_PARAM);
	}
	memsize = pages * ME_MPAGESIZE;
        /*
        **  Moved ME_makekey to be called each time ME_alloc_shared is called
        **  as this obtains a handle to the file which will be required later
        **  if this is an attach to shared memory.
        **  This file handle is closed during an MEshared_free.
        */
        if ((name = ME_makekey(key)) == (HANDLE) -1)
        {
            status = GetLastError();
            SETWIN32ERR(err_code, status, ER_alloc);
            return (FAIL);
        }

	/* 
	**  The file mapping key used to be the name of the file.
	**  This caused problems when Jasmine and Ingres were installed
	**  on the same machine.  Create a unique key name, and use
	**  that for File Mapping instead.
	*/

	NMgtAt("II_INSTALLATION", &install_code);
    STpolycat(4, ObjectPrefix, SystemVarPrefix, install_code,
		      key, map_key);

	if (flag & ME_CREATE_MASK) {
	        iimksecdacl( &sa );
		FlushFileBuffers(name);
#ifdef LP64
		numbytes.QuadPart = Int32x32To64(pages, ME_MPAGESIZE);
		map = CreateFileMapping(name,
		                        &sa,
		                        PAGE_READWRITE,
		                        numbytes.HighPart,
		                        numbytes.LowPart,
		                        map_key);
#else
		map = CreateFileMapping(name,
		                        &sa,
		                        PAGE_READWRITE,
		                        0,
		                        memsize,
		                        map_key);
#endif  /* LP64 */

		if (map == NULL) {
			status = GetLastError();
			SETWIN32ERR(err_code, status, ER_alloc);
			FlushFileBuffers(name);
			CloseHandle(name);
			switch (status) {
			case ERROR_ALREADY_EXISTS:
				return ME_ALREADY_EXISTS;
			case ERROR_NOT_ENOUGH_MEMORY:
				return ME_OUT_OF_MEM;
			default:
				return FAIL;
			}
		}

		if (map != NULL && GetLastError() == ERROR_ALREADY_EXISTS) {
			FlushFileBuffers(name);
			CloseHandle(map);
			CloseHandle(name);
			return (ME_ALREADY_EXISTS);
		}
	} else {
		map = OpenFileMapping(FILE_MAP_READ | FILE_MAP_WRITE,
		                      FALSE,
		                      map_key);

		if (map == NULL) {
			status = GetLastError();
			SETWIN32ERR(err_code, status, ER_alloc);
			FlushFileBuffers(name);
			CloseHandle(name);
			switch (status) {
			case ERROR_FILE_NOT_FOUND:
				return ME_NO_SUCH_SEGMENT;
			case ERROR_NOT_ENOUGH_MEMORY:
				return ME_OUT_OF_MEM;
			default:
				return FAIL;
			}
		}
	}

	/*
	 * Finally.  Now get a memory address for the sucker.
	 * 
	 * If ME_ADDR_SPEC is set, we'll attempt to hardwire the address; else
	 * we'll take whatever the system gives us.
	 */

	if (flag & ME_ADDR_SPEC) {
		temp = MapViewOfFileEx(map,
		                       FILE_MAP_WRITE | FILE_MAP_READ,
		                       0,
		                       0,
		                       0,
		                       *memory);
		if ((temp == NULL) || (temp != *memory)) {
			status = GetLastError();
			SETWIN32ERR(err_code, status, ER_alloc);
			return (FAIL);
		}
	} else {
		*memory = MapViewOfFile(map,
		                        FILE_MAP_WRITE | FILE_MAP_READ,
		                        0,
		                        0,
		                        0);
		if (*memory == NULL) {
			status = GetLastError();
			SETWIN32ERR(err_code, status, ER_alloc);
			return (FAIL);
		}
	}

        /*
        **  If this is not an attach to shared memory assume that pages value
        **  is valid.
        */
        if ((flag & ME_CREATE_MASK) ||
            !(flag & (ME_SSHARED_MASK | ME_MSHARED_MASK)))
        {
	    pages = (SIZE_TYPE)(memsize / ME_MPAGESIZE);
        }
        else
        {
        BY_HANDLE_FILE_INFORMATION sFileInfo;

            /*
            **  If attaching to shared memory ignore the page argument and
            **  calculate size of shared segment in pages from file size.
            **  Assume that a single shared memory file will not exceed 4G.
            */

            if (GetFileInformationByHandle (name, &sFileInfo) == 0)
            {
                status = GetLastError();
                SETWIN32ERR(err_code, status, ER_alloc);
                return (FAIL);
            }
            else
            {
                pages = sFileInfo.nFileSizeLow / ME_MPAGESIZE;
            }
        }


	if (allocated_pages)
		*allocated_pages = pages;

        /*
        **  if this is an attach where pages is 0 ME_reg_seg will register
        **  pages calculated from the size of the file.
        */
	if (ME_reg_seg(*memory,
	               pages,
	               map,
	               name) != OK) {
		UnmapViewOfFile(memory);
		*memory = (PTR) NULL;
		return (FAIL);
	}

	return (OK);
}
Example #18
0
STATUS
disp_prompt(char *buffer,char *achar,char *range)
{
    STATUS                 ret_val = OK ;
    char                   caracter ;
    char                  *legal = NULL ;
    char                   termBuffer [255] ;
#ifdef NT_GENERIC
    COORD		   coordinate;
    int			   numchars, i;
    char		   tempchar [80];
#endif

    if (achar == NULL)
    {
#ifndef NT_GENERIC
	STprintf(termBuffer,ERx("%s%s%s%s%s"),REG_CHAR,ATTR_OFF,
	    PROMPT_POS,DEL_EOL,buffer);

	TEwrite(termBuffer,STlength(termBuffer));
	TEflush();
#else
	SetConsoleActiveScreenBuffer(hTEconsole);
	coordinate.X=0;
	coordinate.Y=22;
	SetConsoleCursorPosition(hTEconsole, coordinate);
	WriteConsole(hTEconsole, buffer, strlen(buffer), &numchars, NULL);
	coordinate.X=strlen(buffer);
	coordinate.Y=22;
	SetConsoleCursorPosition(hTEconsole, coordinate);
	strcpy (tempchar, " ");
	for (i=2; i<=(80-strlen(buffer)); i++)
	  strcat (tempchar, " ");
	WriteConsole(hTEconsole, tempchar, strlen(tempchar), &numchars, NULL);
#endif
    }
    else
    {
#ifndef NT_GENERIC
	STprintf(termBuffer,ERx("%s%s%s%s%s[ %s ]%s "),REG_CHAR,ATTR_OFF,
	    PROMPT_POS,DEL_EOL,REV_VIDEO,buffer,ATTR_OFF);

	TEwrite(termBuffer,STlength(termBuffer));
	TEflush();
#else
	SetConsoleActiveScreenBuffer(hTEconsole);
	coordinate.X=0;
	coordinate.Y=22;
	SetConsoleCursorPosition(hTEconsole, coordinate);
	SetConsoleTextAttribute(hTEconsole, FOREGROUND_BLUE|BACKGROUND_RED|BACKGROUND_GREEN|BACKGROUND_BLUE|BACKGROUND_INTENSITY);
	STpolycat(3, ERx("[ "), buffer, ERx(" ]"), &termBuffer);
	WriteConsole(hTEconsole, termBuffer, strlen(termBuffer), &numchars, NULL);
	coordinate.X=strlen(termBuffer);
	coordinate.Y=22;
	SetConsoleCursorPosition(hTEconsole, coordinate);
	strcpy (tempchar, " ");
	for (i=2; i<=(80-strlen(termBuffer)); i++)
	  strcat (tempchar, " ");
	SetConsoleTextAttribute(hTEconsole, FOREGROUND_RED|FOREGROUND_GREEN|FOREGROUND_BLUE|FOREGROUND_INTENSITY|BACKGROUND_BLUE);
	WriteConsole(hTEconsole, tempchar, strlen(tempchar), &numchars, NULL);
#endif
	TEinflush();

	for (;;)
	{
	    EXinterrupt(EX_OFF);
#ifdef VMS
	    sys$setast(0);
#endif
	    caracter = TEget(0);
	    EXinterrupt(EX_ON);
#ifdef VMS
	    sys$setast(1);
#endif
	    if (range == NULL || (legal = STindex(range,&caracter,0)) != NULL)
		break;
	    else
	    {
		TEput(BELL);
		TEflush();
	    }		    
	}
	*achar = caracter;
    }
    return (ret_val);
}
Example #19
0
STATUS gcn_recrypt( bool clustered, u_i1 *local_mask, char *gcn_val, 
    bool *v1DecryptErr, bool *writeOutput)
{
    i2 pc;
    char *pv[ 3 ];
    STATUS status = OK;
    char *p;
    char pwd[GC_L_PASSWORD];
    i2 j;
    bool printable;

    *v1DecryptErr = FALSE;

    pc = gcu_words( gcn_val, NULL, pv, ',', 3 );
    if (pc < 2 )  
        pv[1] = "";
    if (pc < 3 )  
        pv[2] = "";

    if (!STcasecmp(pv[2],"V0") || (pc < 3))
        status = gcn_decrypt( pv[0], pv[1], pwd );
    else
        status = gcn_decode( pv[0],(u_i1*)local_mask, pv[1], pwd );
    
    if (status != OK)
    {
        if (!STcasecmp(pv[2],"V1"))
            *v1DecryptErr = TRUE;
        goto end_routine;      
    }
    if (!STlength(pwd))
    {
        if (!STcasecmp(pv[2],"V1"))
            *v1DecryptErr = TRUE;
        status = FAIL;
        goto end_routine;
    }
    p = &pwd[0];
    printable = TRUE;
    for (j = 0; j < STlength(pwd); j++)
    {
        if (!CMprint(p))
        {
            printable = FALSE;
            break;
        }
        CMnext(p);
    }
    if (!printable)
    {
         if (!STcasecmp(pv[2],"V1"))
             *v1DecryptErr = TRUE;
         status = FAIL;
         goto end_routine;
    }

    if (clustered)
    {
        if (!STncasecmp("V1", pv[2], STlength(pv[2])))
            *writeOutput = TRUE;
        status = gcu_encode( pv[0], pwd, pv[1] );
        STpolycat( 5, pv[0], ",", pv[1], ",", "V0", gcn_val );
    }
    else
    {
        status = gcn_encode( pv[0],(u_i1*)local_mask, pwd, pv[1] );
        STpolycat( 5, pv[0], ",", pv[1], ",", "V1", gcn_val );
    }

end_routine:
     return status;
}
Example #20
0
STATUS
getLocation(char *string,char *newstr,LOCTYPE *typeOfLoc)
{
    STATUS                 ret_val ;
    LOCATION               aLoc ;
    LOCATION               bLoc ;

    LOCATION              *Locptr1 = NULL ;
    LOCATION              *Locptr2 = NULL ;
    LOCATION              *Locptr3 = NULL ;

    char                  *cptr    = NULL ;
    char                  *cptr2   = NULL ;
    char                  *next    = NULL ;
    char                  *start   = NULL ;
    char                  *tmpBuf  = NULL ;
    char                  *tmpBuf2 = NULL ;
    char                  *gl_dev  = NULL ;
    char                  *gl_path [128] ;
    char                  *gl_file = NULL ;
    char                  *resultPtr = NULL ;
    char                  *tmpaLocStr = NULL ;
    char                  *tmpbLocStr = NULL ;

    i4                     i ;

    ret_val = OK;
    for ( i=0; i<128; i++)
	gl_path[i] = NULL;

    tmpaLocStr = SEP_MEalloc(SEP_ME_TAG_GETLOC, MAX_LOC+1, TRUE, (STATUS *)NULL);
    tmpbLocStr = SEP_MEalloc(SEP_ME_TAG_GETLOC, MAX_LOC+1, TRUE, (STATUS *)NULL);

    LOfroms(FILENAME & PATH, tmpaLocStr, &aLoc);
    LOfroms(FILENAME & PATH, tmpbLocStr, &bLoc);

    if (tracing&TRACE_PARM)
    {
	SIfprintf(traceptr, ERx("getLocation00> string = %s\n"), string);
	SIfprintf(traceptr, ERx("getLocation01> newstr = %s\n"), newstr);
    }

    tmpBuf   = SEP_MEalloc(SEP_ME_TAG_GETLOC, MAX_LOC+1, TRUE, (STATUS *)NULL);
    STcopy(string, tmpBuf);

    if (!(start = STindex(tmpBuf, ERx("("), 0)))
    {
	MEtfree(SEP_ME_TAG_GETLOC);
	return(FAIL);
    }

    MEfree(tmpaLocStr);
    MEfree(tmpbLocStr);

    aLoc.string = SEP_MEalloc(SEP_ME_TAG_GETLOC, MAX_LOC+1, TRUE, (STATUS *)NULL);
    bLoc.string = SEP_MEalloc(SEP_ME_TAG_GETLOC, MAX_LOC+1, TRUE, (STATUS *)NULL);

    next = start;
    CMnext(next);
    if (typeOfLoc)
	*typeOfLoc = NULL;

    if (CMcmpcase(next, ERx(",")))
    {
	/* There's a device specification */

	cptr = next;
	if ((next = STindex(cptr, ERx(","), 0)) == NULL)
	{
	    if ((next = STindex(cptr, ERx(")"), 0)) == NULL)
		ret_val = FAIL;
	    else
	    {	/*
		** This is really a file name in the form, @file(filename.type)
		*/
		*next = EOS;
		gl_file = SEP_MEalloc(SEP_ME_TAG_GETLOC, ((i4)(next-cptr))+2,
				      TRUE, (STATUS *)NULL);
		STcopy(cptr, gl_file);

		if (tracing&TRACE_PARM)
		    SIfprintf(traceptr, ERx("getLocation02> file = %s\n"),
			      gl_file);
		if (typeOfLoc)
		    *typeOfLoc = FILENAME;
	    }
	}
	else
	{
	    *next = EOS;
	    gl_dev = SEP_MEalloc(SEP_ME_TAG_GETLOC, ((i4)(next-cptr))+2, TRUE,
				 (STATUS *)NULL);
#ifdef UNIX
	    STpolycat(2,ERx("$"),cptr, gl_dev);

	    cptr2 = gl_dev;
	    SEP_NMgtAt(CMnext(cptr2), &tmpBuf2, SEP_ME_TAG_GETLOC);
	    if ((tmpBuf2 == NULL)||(*tmpBuf2 == EOS))
	    {
		switch (i = SEP_CMwhatcase(cptr2))
		{
		   case  0: break;
		   case  1: for (cptr2 = gl_dev; *cptr2 != EOS; CMnext(cptr2))
				CMtolower(cptr2,cptr2);
			    break;
		   case -1: for (cptr2 = gl_dev; *cptr2 != EOS; CMnext(cptr2))
				CMtoupper(cptr2,cptr2);
			    break;
		}
		if (i != 0)
		{
		    cptr2 = gl_dev;
		    SEP_NMgtAt(CMnext(cptr2), &tmpBuf2, SEP_ME_TAG_GETLOC);
		}
	    }

	    if (tmpBuf2 != NULL)
		if (*tmpBuf2 != EOS)
		{
		    MEfree(gl_dev);
		    gl_dev = SEP_MEalloc(SEP_ME_TAG_GETLOC,
					 (STlength(tmpBuf2)*2)+2,
					 TRUE,(STATUS *)NULL);
		    STcopy(tmpBuf2,gl_dev);
		}
#else
#ifdef MPE
            STpolycat(2,ERx("!"),cptr, gl_dev);
            for (cptr2 = gl_dev; *cptr2 != EOS; CMnext(cptr2))
                CMtoupper(cptr2,cptr2);
#else
	    /* Probably VMS */

	    STcopy(cptr, gl_dev);
#endif
#endif
	    if (tracing&TRACE_PARM)
		SIfprintf(traceptr, ERx("getLocation03> dev = %s\n"), gl_dev);
	    if (typeOfLoc)
		*typeOfLoc = PATH;
	}

    }

    cptr = CMnext(next);
    next = STindex(cptr, ERx(","), 0);

    for (i = 0; next; ) /* do the paths */
    {
	*next = EOS;
	gl_path[i] = SEP_MEalloc(SEP_ME_TAG_GETLOC, (int)(next-cptr+2), TRUE,
				 (STATUS *)NULL);
	STcopy(cptr, gl_path[i]);
	if (tracing&TRACE_PARM)
	    SIfprintf(traceptr, ERx("getLocation04> path = %s\n"), gl_path[i]);

	if (typeOfLoc)
	    *typeOfLoc = PATH;

	cptr = CMnext(next);
	next = STindex(cptr, ERx(","), 0);
	i++;
    }
    gl_path[i] = NULL;

    Locptr1 = &aLoc;
    Locptr2 = &bLoc;


#ifndef MPE
    if (gl_dev || gl_path[0])
    {
	if (tracing&TRACE_PARM)
	    SIfprintf(traceptr, ERx("getLocation05> SEP_LOcompose()\n"));

	ret_val = SEP_LOcompose(gl_dev, gl_path[0], NULL, NULL, NULL, Locptr1);
#ifdef UNIX
	cptr2 = SEP_CMlastchar(Locptr1->string,0);
	if (*cptr2 == '/') *cptr2 = EOS;
	Locptr1->path = Locptr1->string;
#endif
    }

    for (i=1; (gl_path[i] != NULL)&&(ret_val == OK); i++)
    {
	if (tracing&TRACE_PARM)
	    SIfprintf(traceptr, ERx("getLocation06> LOfaddpath()\n"));

	if ((ret_val = LOfaddpath(Locptr1, gl_path[i], Locptr2)) != OK)
	    continue;

	Locptr3 = Locptr1;
	Locptr1 = Locptr2;
	Locptr2 = Locptr3;
    }
#endif

    if ((gl_file != NULL)&&(ret_val == OK))
    {
	/*
	** This first case catches the instance of: @file(filenane.type).
	** This was caught above in looking for a device (gl_dev).
	*/
	if (tracing&TRACE_PARM)
	    SIfprintf(traceptr, ERx("getLocation07> LOfroms()\n"));

	ret_val = LOfroms( FILENAME, gl_file, Locptr1);
    }
    else
    if ((CMcmpcase(cptr, ERx(")")) != 0)&&(ret_val == OK))
    {
	/* There is a filename */

	next = STindex(cptr, ERx(")"), 0);

	*next = EOS;
	gl_file = SEP_MEalloc(SEP_ME_TAG_GETLOC, (int)(next-cptr+2), TRUE,
			      (STATUS *)NULL);
	STcopy(cptr, gl_file);
	if (tracing&TRACE_PARM)
	    SIfprintf(traceptr, ERx("getLocation08> file = %s\n"), gl_file);
	if (typeOfLoc)
	    *typeOfLoc = PATH & FILENAME;
	if (gl_dev || gl_path[0])
	{
#ifdef MPE
	    if (gl_dev)
	    {
		if (tracing&TRACE_PARM)
		    SIfprintf(traceptr, ERx("getLocation09> MPE's LOfroms ()\n"));

	        char *tmpMPE = NULL ;

		tmpMPE = SEP_MEalloc(SEP_ME_TAG_GETLOC,
				     (STlength(gl_file)+STlength(gl_dev)+1)*2,
				     TRUE, (STATUS *)NULL);

		STpolycat(3, gl_file, ERx("."), gl_dev, tmpMPE);
		LOfroms(FILENAME & PATH, tmpMPE, Locptr1);
	    }
#else
	    if (tracing&TRACE_PARM)
		SIfprintf(traceptr, ERx("getLocation09> LOfstfile()\n"));

	    LOfstfile(gl_file, Locptr1);
#endif
	}
	else
	{
	    if (tracing&TRACE_PARM)
		SIfprintf(traceptr, ERx("getLocation10> LOfroms()\n"));

	    LOfroms( FILENAME, gl_file, Locptr1);
	}
    }

    if (ret_val == OK)
    {
	if (tracing&TRACE_PARM)
	    SIfprintf(traceptr, ERx("getLocation11> LOtos()\n"));

	LOtos(Locptr1, &resultPtr);
	STcopy(resultPtr, newstr);
    }
    MEtfree(SEP_ME_TAG_GETLOC);

    if (tracing&TRACE_PARM)
    {
	if (ret_val != OK)
	    SIfprintf(traceptr,ERx("getLocation12> ret_val = %d\n"),ret_val);
	else
	    SIfprintf(traceptr,ERx("getLocation13> newstr = %s\n"),newstr);
    }

    return(ret_val);
}
Example #21
0
main(int argc, char **argv)
{
    STATUS status = OK;
    VMS_STATUS vStatus;
    char srcbuf[NAME_FILE_SIZE];
    char dstbuf[NAME_FILE_SIZE];
    char delFile[NAME_FILE_SIZE];
    struct dsc$descriptor_s filename_d = 
        { sizeof (delFile) - 1,
            DSC$K_DTYPE_T,
            DSC$K_CLASS_S,
            delFile
        };
    FILE *srcFile = NULL;
    FILE *dstFile = NULL;
    FILE *nameFile = NULL;
    LOCATION loc;
    bool clusterArg = FALSE;
    bool unclusterArg = FALSE;
    bool writeOutput = FALSE;
    bool validSyntax;
    bool clustered = FALSE;
    bool v1DecryptErr = FALSE;
    bool rewrite = FALSE;
    bool isLogin = FALSE;
    i4   total_recs = 0;
    char local_host[MAX_LOC+CM_MAXATTRNAME];
    char config_host[MAX_LOC+CM_MAXATTRNAME];
    i2 i,j;
    i4 active_rec;
    i4 offset;
    char *onOff = NULL;
    bool srcOpened=FALSE;
    bool dstOpened=FALSE;
    bool printable = TRUE;
    GCN_QUEUE *gcn_q;
    GCN_QUEUE *merge_q;
    i4 rec_len = 0;
    QUEUE *q;
    u_i1  local_mask[ 8 ];        /* Must be 8 bytes */
    char name[MAX_LOC+CM_MAXATTRNAME];
    i4 count;
    char *p = NULL;
    i4 dcryptFail = 0;
    i2 pc;
    char *pv[ 3 ];
    GCN_DB_REC0 tmp_rec;
    SYSTIME timestamp;

    MEadvise(ME_INGRES_ALLOC);
    SIeqinit();
    GChostname( local_host, sizeof(local_host));
    STcopy (PMhost(), config_host);
    if (argc == 1)
       validSyntax = TRUE;
    /*
    ** Parse input arguments.
    */    
    for (i = 1; i < argc; i++)
    {
        validSyntax = FALSE;
        for (j = 0; j < argLen; j++)
        {
            if (!STncasecmp(arg[j],argv[i], STlength(argv[i])))
            {
                switch(j)
                {
                    case HELP1:
                    case HELP2:
                    case HELP3:
                    case HELP4:
                       usage();
                       break;

                    case VERBOSE:
                       validSyntax = TRUE;
                       verboseArg = TRUE;
                       break;

                    case CLUSTER:
                       validSyntax = TRUE;
                       clusterArg = TRUE;
                       writeOutput = TRUE;
                       break;

                    case UNCLUSTER:
                       validSyntax = TRUE;
                       unclusterArg = TRUE;
                       writeOutput = TRUE;
                       break;
                }
            } /* if (!STncasecmp(arg[j],argv[i], STlength(argv[i]))) */
            if (validSyntax)
                break;
        } /* for (j = 0; j < argLen; j++) */
        if (!validSyntax)
            break;
    } /* for (i = 1; i < argc; i++) */

    if (!validSyntax)
    {
        usage();
        PCexit(1);
    }

    if (clusterArg && unclusterArg)
    {
        SIprintf("Cannot specify both -c and -u\n\n");
            usage();
        PCexit(1);
    }

    if (verboseArg)
        SIprintf("Local host is %s\n", local_host);

    /*
    ** Generate key seeds for encoding and decoding.
    */
    STpolycat( 2, GCN_LOGIN_PREFIX, local_host, name );
    gcn_init_mask( name, sizeof( local_mask ), local_mask );

    QUinit(&gcn_qhead);
    QUinit(&merge_qhead);
    PMinit();

    /*
    ** See if this is a clustered installation.  If it is, 
    ** the node, login, and attribute files have no file extension.
    */
    if ( PMload( (LOCATION *)NULL, (PM_ERR_FUNC *)NULL ) != OK )
    {
        SIprintf("Error reading config.dat, exiting\n");
        goto cvt_exit;      
    }

    PMsetDefault( 0, SystemCfgPrefix );
    PMsetDefault( 1, config_host );
    PMsetDefault( 2, ERx("gcn") );

    status = PMget( ERx("!.cluster_mode"), &onOff);
    if (onOff && *onOff)
        ;
    else
        onOff = "OFF";

    if (verboseArg)
        SIprintf("Cluster mode is %s\n", onOff);

    if (!clusterArg && !unclusterArg)
        clustered = !STncasecmp(onOff, "ON", STlength(onOff));

    /*
    ** Rewrite the named GCN files.  For clustered installations, the
    ** node, login and attribute files have no hostname extension.
    */
    for ( i = 0; i < NBR_NAMED_FILES; i++ )
    {  
        /*
        ** Ticket files are simply deleted.
        */
        if (i == IILTICKET || i == IIRTICKET)
        {
            STprintf(delFile, "II_SYSTEM:[INGRES.FILES.NAME]II%s*;*", 
                named_file[i].file);
            if (verboseArg)
                SIprintf("Deleting %s\n", delFile);
            filename_d.dsc$w_length = STlength(delFile);
            vStatus = lib$delete_file(&filename_d,0,0,0,0,0,0,0,0,0);
            if (!vStatus & STS$M_SUCCESS)
                SIprintf("delete of %s failed, status is 0x%d\n", delFile,
                    vStatus);
            continue;
        }    
 
        rewrite = FALSE;
        if (!clusterArg && !unclusterArg)
            writeOutput = FALSE;
        if ( ( status = NMloc( FILES, PATH & FILENAME, 
            (char *)NULL, &loc ) ) != OK )
        {
            SIprintf("iicvtgcn: Could not find II_SYSTEM:[ingres.files]\n");
            goto cvt_exit;
        }
     
        LOfaddpath( &loc, "name", &loc );

        if (clustered || unclusterArg)
        {
            if (named_file[i].add_cluster_node)
                STprintf( srcbuf, "II%s_%s", named_file[i].file,config_host);
            else
                STprintf(srcbuf, "II%s", named_file[i].file);
        }
        else 
            STprintf( srcbuf, "II%s_%s", named_file[i].file,config_host);

        if (verboseArg)
            SIprintf("Opening %s for input\n", srcbuf);

        LOfstfile( srcbuf, &loc );

        /*
        ** Ignore non-existent files.
        */
        if ( LOexist( &loc ) != OK )
        {
            if (verboseArg)
                SIprintf("%s does not exist\n", srcbuf);
            continue;
        }
        /*
        ** Open the existing file as "regular" RACC.
        */
        status = SIfopen( &loc, "r", (i4)SI_RACC, sizeof( GCN_DB_REC0 ), 
            &srcFile );
        /*
        ** If the file exists but can't be opened, it's already optimized.
        */
        if (status == E_CL1904_SI_CANT_OPEN && ( LOexist( &loc ) == OK ) )
        {
            /*
            ** Open the existing file as "optimized" RACC.
            */
            status = SIfopen( &loc, "r", (i4)GCN_RACC_FILE, 
                sizeof( GCN_DB_REC0 ), &srcFile );
            if (status != OK)
            {
                SIprintf( "iicvtgcn: Error opening %s, status is %x\n",
                    srcbuf, status );
                continue;
            }
            if (verboseArg)
                SIprintf("%s is already optimized\n", srcbuf);
        }
        else if (status != OK)
        {
            SIprintf( "iicvtgcn: Error opening %s, status is %x\n",
                srcbuf, status );
            continue;
        }

        /*
        ** A successful open as SI_RACC means the file is not optimized.
        ** This file needs a rewrite.
        */
        else
        {
            if (verboseArg)
                SIprintf("Rewriting %s as optimized\n", srcbuf);
            writeOutput = TRUE;    
        }

        srcOpened = TRUE;

        while ( status == OK )
        {
            /*
            ** Read the source data and store in a queue for analysis.
            */
            status = SIread( srcFile, sizeof( GCN_DB_REC0 ),
                &count, (PTR)&tmp_rec );
            if ( status == ENDFILE )
                break;

            if ( status != OK )
            {
                SIprintf("iicvtgcn: Error reading %s, status is %x\n",
                    srcbuf, status);
                goto cvt_exit;
            }
            else if (tmp_rec.gcn_invalid && tmp_rec.gcn_tup_id != -1)
                continue;
            else
            {
                gcn_q = (GCN_QUEUE *)MEreqmem(0, sizeof(GCN_QUEUE),0,NULL);
                if (!gcn_q)
                {
                    SIprintf("iicvtgcn: Cannot allocate memory, exiting\n");
                    goto cvt_exit;
                }
                MEcopy((PTR)&tmp_rec, sizeof(GCN_DB_REC0), (PTR)&gcn_q->buf);
                QUinsert(&gcn_q->q, &gcn_qhead);
                /*
                ** EOF record found.
                */
                if (gcn_q->buf.gcn_tup_id == -1)
                {
                    gcn_q->buf.gcn_l_uid = 0;
                    gcn_q->buf.gcn_uid[0] = '\0';
                    gcn_q->buf.gcn_l_obj = 0;
                    gcn_q->buf.gcn_obj[0] = '\0';
                    gcn_q->buf.gcn_l_val = 0;
                    gcn_q->buf.gcn_val[0] = '\0';
                    gcn_q->buf.gcn_invalid = TRUE;
                    break;
                }
            }
        } /* while ( status == OK ) */

        /*
        ** Decrypt passwords for IILOGIN files.  If any V1 records are found, 
        ** the IILOGIN file will need to be rewritten.
        */
        isLogin = FALSE;
        for (q = gcn_qhead.q_prev; q != &gcn_qhead; q = q->q_prev)
        {
            gcn_q = (GCN_QUEUE *)q;

            /*
            ** EOF record found.
            */
            if (gcn_q->buf.gcn_tup_id == -1)
            {
                gcn_q->buf.gcn_invalid = TRUE;
                break;
            }

            if (i == IILOGIN)
            {
                isLogin = TRUE;
                MEcopy((PTR)&gcn_q->buf, sizeof(GCN_DB_REC0), (PTR)&tmp_rec);
                if (verboseArg)
                     SIprintf("\tEncoding vnode %s\n", gcn_q->buf.gcn_obj);

                if (unclusterArg)
                    status = gcn_recrypt( FALSE, local_mask, 
                        gcn_q->buf.gcn_val, &v1DecryptErr, &writeOutput);
                else if (clusterArg)
                    status = gcn_recrypt( TRUE, local_mask, 
                    gcn_q->buf.gcn_val, &v1DecryptErr, &writeOutput);
                else
                    status = gcn_recrypt( clustered, local_mask, 
                    gcn_q->buf.gcn_val, &v1DecryptErr, &writeOutput);

                if (status != OK)
                {
                    if (verboseArg)
                        SIprintf("Cannot decrypt password from " \
                            "vnode %s status %x\n", gcn_q->buf.gcn_obj,
                            status);
                    dcryptFail++;
                    MEcopy((PTR)&tmp_rec, sizeof(GCN_DB_REC0), 
                        (PTR)&gcn_q->buf);
                    continue;                
                }
                if (v1DecryptErr)
                {
                    if (verboseArg)
                        SIprintf("Cannot decrypt password from " \
                            "vnode %s\n", gcn_q->buf.gcn_obj);
                    dcryptFail++;
                    MEcopy((PTR)&tmp_rec, sizeof(GCN_DB_REC0), 
                        (PTR)&gcn_q->buf);
                    continue;
                }
            }  /* if (LOGIN) */

        } /* for (q = gcn_qhead.q_prev; q != &gcn_qhead; q = q->q_prev) */
        
        if (dcryptFail && verboseArg && isLogin)
        {
            if (clustered || unclusterArg )
                SIprintf("\n%d vnode(s) could not be decrypted.\n" \
                    "Probably some login entries were created on " \
                    "another node.\nTry executing iicvtgcn on another " \
                    "node to merge the other node's entries.\n\n", dcryptFail);
            else
                SIprintf("\n%d vnode(s) could not be decrypted.\n" \
                    "Probably the login file was created on " \
                    "another host.\nTry executing iicvtgcn on " \
                    "a different host.\n\n", dcryptFail);
        }

        if (!writeOutput)
        {
            if (srcOpened)
                SIclose(srcFile);
            srcOpened = FALSE;
            cleanup_queues();
            continue;
        }
   
        /*
        ** Open the destination file with special GCN_RACC_FILE flag, for 
        ** optimized writes.
        */
        if (clustered || clusterArg) 
        {
            if (named_file[i].add_cluster_node)
                STprintf( dstbuf, "II%s_%s", named_file[i].file, local_host);
            else
                STprintf(dstbuf, "II%s", named_file[i].file);
        }
        else
            STprintf( dstbuf, "II%s_%s", named_file[i].file, local_host);

        if (clusterArg && !named_file[i].add_cluster_node)
            rewrite = TRUE;

        LOfstfile( dstbuf, &loc );

        if (rewrite)
        {
            status = SIfopen( &loc, "rw", (i4)GCN_RACC_FILE, 
                sizeof( GCN_DB_REC0 ), &dstFile );
            if ( status != OK )
            {
                status = SIfopen( &loc, "w", (i4)GCN_RACC_FILE, 
                    sizeof( GCN_DB_REC0 ), &dstFile );
                if (status == OK)
                {
                    SIclose( dstFile);
                    status = SIfopen( &loc, "rw", (i4)GCN_RACC_FILE, 
                        sizeof( GCN_DB_REC0 ), &dstFile );
                }
            }
        }
        else
            status = SIfopen( &loc, "w", (i4)GCN_RACC_FILE, 
                sizeof( GCN_DB_REC0 ), &dstFile );

        if ( status != OK )
        {
            SIprintf( "iicvtgcn: Error opening %s, status is %x\n",dstbuf,
                status );
            goto cvt_exit;
        }

        dstOpened = TRUE;

        if (verboseArg)
            SIprintf("%s %s\n", rewrite ? "Rewriting " : "Writing ", dstbuf);

        /*
        ** If this is a merge operation (-c), login, attribute or
        ** node files may change the location of EOF, since the
        ** file to be merged may have different records than
        ** the destination file. 
        ** Before merging, the output file is read and fed into a queue.
        ** Then each merge record is compared to each output record.
        ** If the entire records match, nothing is done. 
        ** If a global login record matches only the vnode name
        ** global or private records will be added if not present;
        ** otherwise, nothing is done.
        ** Node or attribute records may be added if only one field
        ** fails to match.
        */
        status = SIfseek(dstFile, (i4)0, SI_P_START);
        if (rewrite)
        {
            while ( status == OK )
            {
                /*
                ** Read the source data and store in a queue for analysis.
                */
                status = SIread( dstFile, sizeof( GCN_DB_REC0 ),
                    &count, (PTR)&tmp_rec );
                if ( status == ENDFILE )
                    break;

                if ( status != OK )
                {
                    SIprintf("iicvtgcn: Error reading %s, status is %x\n",
                        dstbuf, status);
                    goto cvt_exit;
                }
                else if (tmp_rec.gcn_invalid && tmp_rec.gcn_tup_id != -1)
                    continue;
                else
                {
                    merge_q = (GCN_QUEUE *)MEreqmem(0, sizeof(GCN_QUEUE),0,NULL);
                    if (!merge_q)
                    {
                        SIprintf("iicvtgcn: Cannot allocate memory, exiting\n");
                        goto cvt_exit;
                    }
                    MEcopy((PTR)&tmp_rec, sizeof(GCN_DB_REC0), 
                        (PTR)&merge_q->buf);
                    QUinsert(&merge_q->q, &merge_qhead);
    
                    /*
                    ** EOF record found.
                    */
                    if (merge_q->buf.gcn_tup_id == -1)
                        break;
                }
                if ( status == ENDFILE )
                    break;

            } /* while ( status == OK ) */

            /*
            ** Go through the input queue.  Compare each record with
            ** the output (merge) queue.  If the record is invalid
            ** or doesn't match, it's ignored.
            */
            dcryptFail = 0;
            total_recs = 0;
            for (q = gcn_qhead.q_prev; q != &gcn_qhead; q = q->q_prev)
            {
                SYSTIME     timestamp;

                gcn_q = (GCN_QUEUE *)q;
                if (gcn_q->buf.gcn_tup_id == -1)
                    break;
                if ( !gcn_merge_rec( gcn_q, isLogin ) )
                    continue;
                if (isLogin)
                {
                    /*
                    ** Login passwords get encrypted as V0 in a cluster
                    ** environment.
                    */
                    MEcopy((PTR)&gcn_q->buf, sizeof(GCN_DB_REC0), 
                        (PTR)&tmp_rec);
                    status = gcn_recrypt( TRUE, local_mask, 
                        gcn_q->buf.gcn_val, &v1DecryptErr, &writeOutput);

                    if (status != OK)
                    {
                        if (verboseArg)
                            SIprintf("Cannot decrypt password from " \
                                "vnode %s status %x\n", gcn_q->buf.gcn_obj,
                                status);
                        dcryptFail++;
                        MEcopy((PTR)&tmp_rec, sizeof(GCN_DB_REC0), 
                            (PTR)&gcn_q->buf);
                        continue;                
                    }
                    if (v1DecryptErr)
                    {
                        if (verboseArg)
                            SIprintf("Cannot decrypt password from " \
                                "vnode %s\n", gcn_q->buf.gcn_obj);
                        dcryptFail++;
                        MEcopy((PTR)&tmp_rec, sizeof(GCN_DB_REC0), 
                            (PTR)&gcn_q->buf);
                        continue;
                    }
                }
                merge_q = (GCN_QUEUE *)MEreqmem(0, sizeof(GCN_QUEUE),0,NULL);
                if (!merge_q)
                {
                    SIprintf("iicvtgcn: Cannot allocate memory, exiting\n");
                    goto cvt_exit;
                }

                MEcopy((PTR)&gcn_q->buf, sizeof(GCN_DB_REC0), 
                    (PTR)&merge_q->buf);
                total_recs++;
              
                QUinsert(&merge_q->q, &merge_qhead);
            }

            if (dcryptFail && verboseArg && isLogin)
            {
                if (clustered || unclusterArg )
                    SIprintf("\n%d vnode(s) could not be decrypted.\n" \
                        "Probably some login entries were created on " \
                        "another node.\nTry executing iicvtgcn on another " \
                        "node to merge the other node's entries.\n\n", 
                        dcryptFail);
                    else
                        SIprintf("\n%d vnode(s) could not be decrypted.\n" \
                            "Probably the login file was created on " \
                            "another host.\nTry executing iicvtgcn on " \
                            "a different host.\n\n", dcryptFail);
            }
            if (verboseArg)
                SIprintf("Total records merged: %d\n", total_recs);

            /*
            ** If no records to merge, clean up and continue.
            */
            if (!total_recs)
            {
                cleanup_queues();
                continue;
            }

            status = SIfseek(dstFile, (i4)0, SI_P_START);
            active_rec = 0;
            for (q = merge_qhead.q_prev; q != &merge_qhead; q = q->q_prev)
            {
                merge_q = (GCN_QUEUE *)q;
                if (verboseArg)
                   SIprintf("Rewriting %s record vnode %s val %s\n", 
                       !STcasecmp("*", merge_q->buf.gcn_uid) ? "global" : 
                       "private", merge_q->buf.gcn_obj, merge_q->buf.gcn_val);
                if (merge_q->buf.gcn_tup_id == -1)
                    continue;
                status = SIwrite(sizeof( GCN_DB_REC0 ), 
                    (char *)&merge_q->buf, &count, dstFile );
                if ( status != OK)
                {
                    SIprintf( "iicvtgcn: Failed to write file %s, " \
                        "status is %x\n", srcbuf, status );
                    goto cvt_exit;
                }
                active_rec++;
            }
            /*
            ** Write new EOF record.
            */
            tmp_rec.gcn_tup_id = -1;
            tmp_rec.gcn_l_uid = 0;
            tmp_rec.gcn_uid[0] = '\0';
            tmp_rec.gcn_l_obj = 0;
            tmp_rec.gcn_obj[0] = '\0';
            tmp_rec.gcn_l_val = 0;
            tmp_rec.gcn_val[0] = '\0';
            tmp_rec.gcn_invalid = TRUE;
            offset = active_rec * sizeof(GCN_DB_REC0);
            status = SIfseek(dstFile, (i4)offset, SI_P_START);
            status = SIwrite(sizeof( GCN_DB_REC0 ), (PTR)&tmp_rec, 
                &count, dstFile );
        }
        else
        {
            for (q = gcn_qhead.q_prev; q != &gcn_qhead; q = q->q_prev)
            {
                gcn_q = (GCN_QUEUE *)q;
                gcn_q->buf.gcn_l_val = STlength(gcn_q->buf.gcn_val);
                if (verboseArg)
                   SIprintf("Writing %s record vnode %s val %s\n", 
                       !STcasecmp("*", gcn_q->buf.gcn_uid) ? "global" : 
                       "private", gcn_q->buf.gcn_obj, gcn_q->buf.gcn_val);
                status = SIwrite(sizeof( GCN_DB_REC0 ), (char *)&gcn_q->buf, 
                    &count, dstFile );
                if ( status != OK)
                {
                    SIprintf( "iicvtgcn: Failed to write file %s, " \
                        "status is %x\n", srcbuf, status );
                    goto cvt_exit;
                }
            }
        }  /* if (rewrite) */


        cleanup_queues();

        SIclose( srcFile );
        srcOpened = FALSE;
        SIclose( dstFile );
        dstOpened = FALSE;

    } /* for (i = 0; i < NBR_NAMED_FILES; i++ ) */

cvt_exit:

    cleanup_queues();

    if (srcOpened)
        SIclose(srcFile);
    if (dstOpened)
        SIclose(dstFile);
    PCexit( OK );
}
Example #22
0
/******************************************************************************
** Name: MEshow_pages()	- show system's allocated shared memory segments.
**
** Description:
**	This routine is used by clients of the shared memory allocation
**	routines to show what shared memory segments are currently allocated
**	by the system.
**
**	The routine takes a function parameter - 'func' - that will be
**	called once for each existing shared memory segment allocated
**	by Ingres in the current installation.
**
**      The client specified function must have the following call format:
**(
**          STATUS
**          func(arg_list, key, err_code)
**          i4         *arg_list;       Pointer to argument list.
**          char       *key;		Shared segment key.
**          CL_SYS_ERR *err_code;       Pointer to operating system
**                                      error codes (if applicable).
**)
**
**	The following return values from the routine 'func' have special
**	meaning to MEshow_pages:
**
**	    OK (zero)	- If zero is returned from 'func' then MEshow_pages
**			  will continue normally, calling 'func' with the
**			  next shared memory segment.
**	    ENDFILE	- If ENDFILE is returned from 'func' then MEshow_pages
**			  will stop processing and return OK to the caller.
**
**	If 'func' returns any other value, MEshow_pages will stop processing
**	and return that STATUS value to its caller.  Additionally, the system
**	specific 'err_code' value returned by 'func' will be returned to the
**	MEshow_pages caller.
**
** Inputs:
**	func			Function to call with each shared segment.
**	arg_list		Optional pointer to argument list to pass
**				to function.
**
** Outputs:
**	err_code 		System specific error information.
**
**	Returns:
**	    OK
**	    ME_NO_PERM		No permission to show shared memory segment.
**	    ME_BAD_PARAM	Bad function argument.
**	    ME_NO_SHARED	No shared memory in this CL.
**
**	Exceptions:
**	    none
**
** Side Effects:
**	    none
**
******************************************************************************/
STATUS
//MEshow_pages(STATUS		(*func) (PTR, const char *, CL_SYS_ERR *),
MEshow_pages(STATUS		(*func) (),
             PTR        *arg_list,
             CL_SYS_ERR *err_code)
{
	LOCATION        locptr;
	LO_DIR_CONTEXT  lo_dir;
	STATUS          status;
	char            fname[LO_FILENAME_MAX + 1];
	char		dev[LO_DEVNAME_MAX + 1];
	char		path[LO_PATH_MAX + 1];
	char		fprefix[LO_FPREFIX_MAX + 1];
	char		fsuffix[LO_FSUFFIX_MAX + 1];
	char		version[LO_FVERSION_MAX + 1];

	/*
	 * Get location ptr to directory to search for memory segment names.
	 */

# ifdef MCT
	gen_Psem(&NM_loc_sem);
# endif /* MCT */
	if ((status = NMloc(FILES,
	                    PATH,
	                    (char *) NULL,
	                    &locptr)) == OK) {
		LOfaddpath(&locptr,
		           ME_SHMEM_DIR,
		           &locptr);
	} else {
# ifdef MCT
		gen_Vsem(&NM_loc_sem);
# endif /* MCT */
		return (status);
	}
# ifdef MCT
	gen_Vsem(&NM_loc_sem);
# endif /* MCT */

	/*
	 * For each file in the memory location, call the user supplied
	 * function with the filename.  Shared memory keys are built from
	 * these filenames.
	 */

	status = LOwcard(&locptr,
	                 (char *) NULL,
	                 (char *) NULL,
	                 (char *) NULL,
	                 &lo_dir);

	if (status != OK) {
		LOwend(&lo_dir);
		return (ME_NO_SHARED);
	}

	while (status == OK) {
		LOdetail(&locptr, dev, path, fprefix, fsuffix, version);
		(VOID) STpolycat(3, fprefix, ".", fsuffix, fname);
		if (~lo_dir.find_buffer.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
			status = (*func) (arg_list,
			                  fname,
			                  err_code);
			if (status != OK) {
				break;
			}
		}
		status = LOwnext(&lo_dir, &locptr);
	}

	LOwend(&lo_dir);

	if (status == ENDFILE) {
		return (OK);
	}

	return (status);
}
Example #23
0
/*
**	form_comment
*/
STATUS
form_comment(FILE *aFile)
{
    STATUS                 ret_status ;
    FILE                  *comPtr  = NULL ;

    /*
    ** Find beginning of commment.
    */

    do
    {
        ret_status = read_fm_command(aFile);

    } while ((ret_status == OK)&&
             ((sep_state & BLANK_LINE_STATE)||(sep_state & IN_ENDING_STATE)));

    if (ret_status == OK)
    {
        if ((sep_state & IN_COMMENT_STATE) == 0)
        {
            fromLastRec = 1;
            STcopy(buffer_1, holdBuf);
            ret_status = FAIL;
        }
    }

    /*
    ** create comments file
    */

    if (ret_status == OK)
    {
        if ((ret_status = bld_cmtName(msg)) != OK)
        {
            disp_line(msg,0,0);
        }
        else if ((ret_status = SIfopen(cmtLoc, ERx("w"), SI_TXT, TERM_LINE,
                                       &comPtr)) != OK)
        {
            disp_line(STpolycat(2,ErrOpn,cfile,msg),0,0);
        }
    }

    /*
    ** read in comments
    */

    if (ret_status == OK)
    {
        if ((ret_status = read_in_comments(aFile, comPtr)) == OK)
        {
            /*
            ** close comments file
            */

            if (SIclose(comPtr)!= OK)
            {
                STpolycat(3,ErrC,ERx("close"),cfile,msg);
                disp_line(msg,0,0);
                ret_status = FAIL;
            }
        }
    }

    return(ret_status);

} /* end of form_comment */