Ejemplo n.º 1
0
/*
** Name: check_path_chars   - test path characters are supported.
**
** Description:
**  Test that the characters in the path are permitted.
**
** Inputs:
**  loc                 Pointer to location structure containing path.
**
** Outputs:
**  status              More detailed error code for failure.
**
** Returns:
**  result      OK      No invalid characters found.
**              FAIL    Invalid characters found in path.
**
** History:
**      14-Feb-2005 (fanra01)
**          Create to replace call to LOisvalid.
**	03-Jun-2005 (drivi01)
**	    Replaced Window's portion of check_path_chars
**	    with LOisvalid.
**  11-Jul-2005 (fanra01)
**      Add status output.
*/
static i4
check_path_chars( LOCATION* loc, STATUS* status )
{
    i4 result = OK;
    char	dev[MAX_LOC];
    char	path[MAX_LOC];
    char	file[MAX_LOC];
    char	ext[MAX_LOC];
    char	vers[MAX_LOC];
    char	*p;

# if defined(NT_GENERIC)

    if (!LOisvalid( loc, &result ))
    {
        if (status != NULL)
        {
            *status = result;
        }
        return FAIL;
    }

# else  /* NT_GENERIC */
    if (LOdetail( loc, dev, path, file, ext, vers ) != OK)
        return FAIL;
    for (p = path; *p != EOS; CMnext(p))
    {
	if (!(CMalpha(p) || CMdigit(p) || CMcmpnocase(p, PATH_SEPARATOR) ||
        '_' || *p == ' '))
	    return FAIL;
    }
    for (p = file; *p != EOS; CMnext(p))
    {
	if (!(CMalpha(p) || CMdigit(p) || *p == '_' || *p == ' '))
	    return FAIL;
    }
    for (p = ext; *p != EOS; CMnext(p))
    {
	if (!(CMalpha(p) || CMdigit(p) || *p == '_' || *p == ' '))
	    return FAIL;
    }
# endif /* NT_GENERIC */
    
    return(result);
}
Ejemplo n.º 2
0
/*
**  Name: CFBackupConf
**
**  Description:
**      Save the current configuration as a .bak file.
**
** Inputs:
**      loc                 Current location
**
** Outputs:
**      none
**
** Returns:
**      OK      success
**      FAIL    failure
**
** History:
**      11-Feb-2000 (fanra01)
**          Created.
*/
STATUS
CFBackupConf( LOCATION* loc, PRL begin )
{
    STATUS status;
    char buffer[MAX_LOC + 1];
    char device[MAX_LOC + 1];
    char path[MAX_LOC + 1];
    char filename[MAX_LOC + 1];
    char extension[MAX_LOC + 1];
    char version[MAX_LOC + 1];
    LOCATION backup;

    LOcopy( loc, buffer, &backup );
    LOdetail( loc, device, path, filename, extension, version );
    LOcompose( device, path, filename, ERx( "bak" ), version, &backup );
    status = CFWriteConf( &backup, begin );
    return (status);
}
Ejemplo n.º 3
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);
}
Ejemplo n.º 4
0
/*
** pp_open() -- open a file for reading.  The use of the include path list
**      is used to resolve files that may not be in the current default
**      location.  
*/
static STATUS
pp_open( FILE **input, char *filepath, bool def_dir )
{
	LOCATION loc;
	LOCATION loctest;
	char buf[ MAX_LOC + 1 ];
	char bufdev[ MAX_LOC + 1 ];
	char bufpath[ MAX_LOC + 1 ];
	char bufsave[ MAX_LOC + 1 ];
	char buftest[ MAX_LOC + 1 ];
	STATUS sts;
	IPATH *ipath;
	bool found = FALSE;
	bool file_has_path, dir_has_path;

	/* 
	** Check to see if we should first look in the default directory,
	** this directory will be the first entry in the Include list.
	*/
	if (def_dir == TRUE) 
		ipath = &ihead;
	else
		ipath = ihead.next;

	/* Convert the filename to open to a LOCATION */
	STcopy(filepath, bufsave);
	if (OK != (sts = LOfroms( PATH & FILENAME, bufsave, &loc )) )
		return (sts);

	/*
	** Search for the file in each directory in the include list.
	** No expansion possible if there are no include directories.
	*/
	while (ipath != NULL && found == FALSE) 
	{
		/* Initialize loctest so LOaddpath will work */
		LOcopy(&loc, buftest, &loctest);
			
		/* Is there a device (VMS) and/or a path for the directory? */
		STcopy(ERx(""), bufdev);
		STcopy(ERx(""), bufpath);
		sts = LOdetail(ipath->pathloc, bufdev, bufpath, buf, buf, buf);
		if (sts != OK)
			break;
		if (STlength(bufdev) + STlength(bufpath) > 0 )
			dir_has_path = TRUE;
		else
			dir_has_path = FALSE;

		/* Don't mess with the filename if it was an absolute path */
		/* or if this include directory path is empty */
		if (LOisfull(&loctest) == FALSE && dir_has_path == TRUE )
		{
			/* Is there a path for the file? */
			sts = LOdetail(&loctest, 
				buf, bufpath, buf, buf, buf);
			if (sts != OK)
				break;
			file_has_path = (STlength(bufpath) > 0 ? TRUE : FALSE);

			/*
			** If there's no path component then copy in the 
			** next prefix, else append it.
			** If LOaddpath succeeds, the result will also have 
			** the original filename.  If it fails then drop out.
			** LOaddpath can fail if loctest is an absolute path,
			** but we already checked for that.
			*/
			if ( file_has_path )
			{
				sts =LOaddpath(ipath->pathloc, &loc, &loctest);
			}
			else
			{
				LOcopy(ipath->pathloc, buftest, &loctest);

				/*
				** If we can't set the filename from loc, 
				** then something is wrong, and will continue 
				** to be wrong.  Get out of the loop.
				*/
				sts = LOstfile(&loc, &loctest);
			}
		}

		/*
		** If all of the filename manipulations have succeeded
		** then check for the file's existance.  
		*/
		if (sts == OK && LOexist(&loctest) == OK) {
			found = TRUE;
			LOcopy(&loctest, buf, &loc);
		}

		/* Prepare for the next path in the include list */
		ipath = ipath->next;
	}

	/* 
	** If the file existed then return back the result from the open,
	** otherwise all of our efforts were a bust, return back a failure.
	*/ 
	if (found)
		return ( SIfopen(&loc, ERx("r"), SI_TXT, MAX_LINE, input) );
	else
		return (FAIL);
}
Ejemplo n.º 5
0
void 
main(int argc, char *argv[])
{
#define 	MAXBUF	4095
#define 	MAX_NAME  32	

	char 		buf[ MAXBUF+1 ];
	char 		repbuf[ MAXBUF+1 ];
	int		iarg, ibuf, ichr;
	char		*database = NULL;
	char 		username[MAX_NAME] = {""};
	LOCATION	tloc;
	LOCATION        loc_out;
	LOCATION        loc_in;
	char            loc_buf[MAX_LOC + 1];
	char            tmp_buf[MAX_LOC + 1];
	char			otmp_buf[MAX_LOC + 1];
	char		dev[MAX_LOC + 1];
	char		path[MAX_LOC + 1];
	char		fprefix[MAX_LOC + 1];
	char		fsuffix[MAX_LOC + 1];
	char		version[MAX_LOC + 1];
	char            odev[MAX_LOC + 1];
	char            opath[MAX_LOC + 1];
	char            ofprefix[MAX_LOC + 1];
	char            ofsuffix[MAX_LOC + 1];
	char            oversion[MAX_LOC + 1];
	char            *new_filename;
	char		*temploc;
	CL_ERR_DESC 	err_code;
	char 		*p1 = NULL;
	bool		usergiven = FALSE;
	bool		Repmod = FALSE;
	bool		nowait = TRUE;
	char	 	waitflag[3];
	
	
	if (argc < 2) 
	{
		usage();
	    PCexit(FAIL);
	}
	
	/* Get the temporary path location */	
	NMloc(TEMP, PATH, NULL, &tloc);		
	LOcopy(&tloc, tmp_buf, &loc_in);
	LOtos(&tloc, &temploc);
	LOcopy(&tloc, otmp_buf, &loc_out);
	     	
	/* Get the new filename for path location */	
	LOuniq(ERx("usrmod"), ERx("sql"), &loc_in);	
	LOtos(&loc_in, &new_filename);
	
	LOuniq(ERx("usrmod"), ERx("out"), &loc_out);

	/* Get just the filename for copydb code   */	
	LOdetail(&loc_in, dev, path, fprefix, fsuffix, version); 
	if ( *fsuffix !=  '\0' )
	{
	    STcat(fprefix, ".");
	    STcat(fprefix, fsuffix);
	}
       /* Get just the filename for copydb code   */
         LOdetail(&loc_out, odev, opath, ofprefix, ofsuffix,oversion);
		STcat(ofprefix, ".");
		STcat(ofprefix, ofsuffix);
	

	STprintf(buf, 
        ERx("copydb -with_modify -nodependency_check -with_index -with_comments -no_persist -parallel -no_repmod -group_tab_idx -no_warn -d\"%s\" -infile=\"%s\" -outfile=\"%s\""
	), temploc, fprefix,ofprefix);
	ibuf = STlength(buf); 

	for (iarg = 1; (iarg < argc) && (ibuf < MAXBUF); iarg++) 
	{

	    if( STscompare( argv[ iarg ], 1, ERx( "-" ), 1 ) == 0 )
		{
			p1 = argv[ iarg ]; 
			(void) CMnext( p1 );

			if ( (STlength(p1) == 0) || 
			  !(((STscompare( p1, 1, ERx( "u" ), 1 ) == 0 ) ||
			  (STscompare( p1, 5, ERx( "noint" ), 5 ) == 0 ) || 
			  (STscompare( p1, 6, ERx( "repmod" ), 6 ) == 0 ) || 
			  (STscompare( p1, 1, ERx( "w" ), 6 ) == 0 ) ||
			  (STscompare( p1, 6, ERx( "online"), 6 ) == 0 )) &&
			  ( argc > 2 ) ))
			{
				usage(); 
				PCexit(FAIL);
			}
			/*
			** Get the username if the -u flag is passed in
			** with the input
			*/
			
			if (STscompare( p1, 1, ERx( "u" ), 1 ) == 0 )
			{
				STcopy(&argv[iarg][2] , (char *)&username);
				usergiven = TRUE;
			}
			else if (STscompare( p1, 1, ERx( "r" ), 1 ) == 0 )
			{ 	
				Repmod = TRUE;
				continue;
			}
			else if (STscompare( p1, 1, ERx( "w"), 1 ) == 0)	
			{	
				nowait = TRUE;
				continue;
			}	
                }              	
		
        if( STscompare( argv[ iarg ], 1, ERx( "+" ), 1 ) == 0 )
		{
			p1 = argv[ iarg ];
			(void) CMnext( p1 );
			if (STscompare( p1, 1, ERx( "w" ), 1 ) == 0 )
			{
				nowait = FALSE;	
				continue;
			}
			else
			{
				usage();
				PCexit(FAIL); 
			}
		}

        if((database == NULL) &&
           (STscompare( argv[ iarg ], 1, ERx( "+" ), 1 ) != 0) &&
           (STscompare( argv[ iarg ], 1, ERx( "-" ), 1 ) != 0))
        {
            database =  argv[ iarg ];
        }

	buf[ibuf++] = ' ';
		for (ichr = 0; (argv[iarg][ichr] != '\0') && (ibuf < MAXBUF); 
			ichr++, ibuf++)
		{
			buf[ibuf] = argv[iarg][ichr];
		}
		buf[ibuf] = '\0';
	}

	/*
	**	Execute the command.
	*/

	if( PCcmdline((LOCATION *) NULL, buf, PC_WAIT, 
			(LOCATION *) NULL, &err_code) != OK )
	    PCexit(FAIL);

	/*
	**	we should run the sql script 
	**	  sql dbname < new_filename
	**	if -u flag given then run:
	**	  sql -uusername dbname < new_filename	
	*/

	if (usergiven)
	  STprintf(buf, ERx( "sql -u%s -s %s <%s" ),
			username, database, new_filename );
	else
	  STprintf(buf, ERx( "sql -s %s <%s" ),
				database, new_filename );

	/*
	**	Execute the command.
	*/

        if( PCcmdline((LOCATION *) NULL, buf, PC_WAIT, 
                        (LOCATION *) NULL, &err_code) != OK )
        {
            STprintf(buf, ERx(" Warning: Non-persistent objects associated with the base table\n in the failed query may have been lost. Please refer to\n %s\n to determine whether any corrective action is required.\n"), new_filename);
            SIfprintf(stdout, buf);
	    PCexit(FAIL);
        }

	/* Now execute the repmod command if the replicator 
	** modify is also required by the user (-repmod)
	*/
	
	if (Repmod)
	{
		
	  if (nowait)
	    STcopy("-w", waitflag) ;
	  else
	    STcopy("+w", waitflag) ;
		
	  if (usergiven)
	    STprintf(repbuf, ERx( "repmod -u%s %s %s" ), 
		username, database, waitflag );
	  else
	    STprintf(repbuf, ERx( "repmod %s %s" ), 
		database, waitflag );
            	
	
	  if( PCcmdline((LOCATION *) NULL, repbuf, PC_WAIT,
                 (LOCATION *) NULL, &err_code) != OK )
     	    PCexit(FAIL);

	}	
	/*
	**	Delete the location
	*/
	LOdelete(&loc_in); 
	LOdelete(&loc_out);
	PCexit(OK);
}
Ejemplo n.º 6
0
/*
** Name: check_path
**
** Description:
**      Function to test the specified path for:
**          1. Valid characters.
**          2. An existing or valid parent directory.
**          3. Write permissions for 2.
**
** Inputs:
**      chkpath     pointer to the path string for validation.
**      eflags      flags specifying the actions to be taken.
**
** Outputs:
**      None.
**
** Returns:
**      OK          Path validation successful.
**      !OK         Path validation failed.
**
** History:
**      27-Jun-2005 (fanra01)
**          Created.
**      11-Jul-2005 (fanra01)
**          Return a more specific status code.
*/
static STATUS
check_path( char* chkpath, int eflags )
{
    STATUS          status = II_SUCCESSFUL;
    STATUS          rc;
    int             retcode = FAIL;
    LOCATION        tloc;                      /* target location */
    LOCATION        wloc;                      /* working location */
    LOCATION        cloc;                      /* working location */
    LOINFORMATION   linfo;
    i4              info;
    char*           temp = NULL;
    char*           path = NULL;
    char*           work = NULL;
    char*           curr = NULL;
    char*	        d;
    char*           p;
    char*           f;
    char*           e;
    char*           v;
    
    char*           s;

    while(TRUE)
    {
        /*
        ** Allocate working area up front.  Saves declaring arrays on the
        ** stack.
        */
        if ((temp = MEreqmem( 0, (MAX_LOC+1) * 8, TRUE, &status )) == NULL)
        {
            break;
        }
        
        /*
        ** Initialize working pointers with memory
        */
        path = temp;
        work = temp + MAX_LOC + 1;
        curr = work + MAX_LOC + 1;
        d = curr + MAX_LOC + 1;
        p = d + MAX_LOC + 1;
        f = p + MAX_LOC + 1;
        e = f + MAX_LOC + 1;
        v = e + MAX_LOC + 1;

        /*
        ** Initialize a location structure with the specified path
        ** string.
        */
        if ((eflags & (II_CHK_PATHCHAR | II_CHK_PATHDIR | II_CHK_PATHPERM)) &&
            (LOfroms( PATH, chkpath, &tloc ) != OK))
        {
            status = II_BAD_PATH;
            break;
        }

        /*
        ** Perform an illegal characters check, for all path tests.
        */
        if ((eflags & (II_CHK_PATHCHAR | II_CHK_PATHDIR | II_CHK_PATHPERM)) &&
            (check_path_chars( &tloc, &rc )))
        {
            switch(rc)
            {
                case LO_BAD_DEVICE:
                    status = II_BAD_PATH;
                    break;
                case LO_NOT_PATH:
                case LO_NOT_FILE:
                default:
                    status = II_INVAL_CHARS_IN_PATH;
                    break;
            }
            break;
        }

        /*
        ** Duplicate the specified path location into a work location.
        */
        LOcopy( &tloc, work, &wloc );
        
        /*
        ** Create an empty location for the current working device,
        ** split the target path into components and
        ** create a location of the target device.
        */
        if ((eflags & (II_CHK_PATHDIR | II_CHK_PATHPERM)) &&
            ((status = LOfroms( PATH, curr, &cloc )) == OK) &&
            ((status = LOdetail( &wloc, d, p, f, e, v )) == OK) &&
            ((status = LOcompose( d, CURR_DIR, NULL, NULL, NULL,
            &cloc )) == OK))
        {
            /*
            ** Save the current working directory
            */
            LOsave();
            
            /*
            ** Change working path to the target device
            */
            status = LOchange( &cloc );
        
            /*
            ** Starting with the whole path work backwards looking for
            ** a valid directory
            */
            for (s=work, info=0;
                (status == OK) && (retcode != OK) && (s != NULL);
                )
            {
                if ((status = LOfroms( PATH, p, &wloc )) != OK)
                {
                    status = II_BAD_PATH;
                    break;
                }
                /*
                ** Reset requested information flags for each iteration.
                */
                info = (LO_I_TYPE | LO_I_PERMS);

                switch(retcode = LOinfo( &wloc, &info, &linfo ))
                {
                    case OK:
                        /*
                        ** If the path or permission test is requested and
                        ** type info is returned test for directory flag. 
                        */
                        if ((eflags & (II_CHK_PATHDIR | II_CHK_PATHPERM)) &&
                            ((info & LO_I_TYPE) == LO_I_TYPE))
                            status = (linfo.li_type == LO_IS_DIR) ? OK : II_PATH_NOT_DIR;

                        /*
                        ** If the permission test is requested and
                        ** permissions are returned test the flags for read
                        ** and write.
                        */
                        if ((status == OK) && (eflags & II_CHK_PATHPERM))
                        {
                            if (((info & LO_I_PERMS) == LO_I_PERMS) &&
                                (linfo.li_perms & (LO_P_READ|LO_P_WRITE))
                                == (LO_P_READ|LO_P_WRITE))
                            {
                                /*
                                ** Read and write permission
                                */
                                break;
                            }
                            else
                            {
                                /*
                                ** missing a permission
                                */
                                status = II_PATH_CANNOT_WRITE;
                            }
                        }
                        else
                        {
                            break;
                        }
                    case LO_NO_SUCH:
                        /*
                        ** Look backwards for the next path separator
                        */
                        if((s = STrindex( p, PATH_SEPARATOR, 0 )) != NULL)
                        {
                            /*
                            ** If separator found truncate the path
                            ** otherwise the start of the path has
                            ** been reached, update string to test the
                            ** root directory.
                            */
                            if (s != p)
                            {
                                *s = '\0';
                            }
                            else
                            {
                                *(s+1) = '\0';
                            }
                        }
                        else
                        {
                            /*
                            ** A root path character was included in the
                            ** path that has been reached and still no
                            ** installable area found.
                            */                                
                            if (p && *p && *p == SLASH)
                            {
                                status = II_BAD_PATH;
                            }
                            else
                            {
                                /*
                                ** A relative path was specified and no
                                ** installable area has been found.
                                ** Test the current working directory of the
                                ** target device.
                                */
                                if ((status = LOgt( p, &wloc )) == OK)
                                {
                                    /*
                                    ** Reset temporary pointer to a work
                                    ** area to satisfy the loop condition.
                                    */
                                    s = work;
                                }
                            }
                        }
                        break;
                    default:
                        status = II_BAD_PATH;
                        break;
                }
            }
            break;
        }
        else
        {
            if (status != II_SUCCESSFUL)
            {
                status = II_BAD_PATH;
            }
            break;
        }
    }
    /*
    ** Free the working area
    */
    if (temp != NULL)
    {
        MEfree( temp );
    }
    return(status);
}
Ejemplo n.º 7
0
STATUS
Run_SED_on_file(SEPFILE **Sep_file,LOCATION *Sep_Loc)
{
    STATUS                 ret_val ;
    CL_ERR_DESC            cl_err;

    LOCATION              *sedtmploc = NULL ;
    LOCATION              *filtmploc = NULL ;

    char                  *SEDbuffer = NULL ;
    char                  *sedtmp = NULL ;
    char                  *filtmp = NULL ;
    char                  *cmd_line = NULL ;
    char                  *sed_dev = NULL ;
    char                  *sed_path = NULL ;
    char                  *sed_name = NULL ;
    char                  *sed_type = NULL ;
    char                  *sed_vers = NULL ;
    char                  *fptr1 = NULL ;
    char                  *fptr2 = NULL ;

    FILE                  *SEDfptr = NULL ;
    FILE                  *fptr = NULL ;

    bool                   Sep_file_empty ;

    sed_dev  = SEP_MEalloc(SEP_ME_TAG_SED, LO_DEVNAME_MAX+1,  TRUE, NULL);
    sed_path = SEP_MEalloc(SEP_ME_TAG_SED, LO_PATH_MAX+1,     TRUE, NULL);
    sed_name = SEP_MEalloc(SEP_ME_TAG_SED, LO_FPREFIX_MAX+1,  TRUE, NULL);
    sed_type = SEP_MEalloc(SEP_ME_TAG_SED, LO_FSUFFIX_MAX+1,  TRUE, NULL);
    sed_vers = SEP_MEalloc(SEP_ME_TAG_SED, LO_FVERSION_MAX+1, TRUE, NULL);

    SEDbuffer = SEP_MEalloc(SEP_ME_TAG_SED, SCR_LINE+1, TRUE, NULL);

    /*
    ** Create Sed output file names.
    */
    sedtmploc = (LOCATION *)SEP_MEalloc(SEP_ME_TAG_SED, sizeof(LOCATION),
					TRUE, NULL);
    filtmploc = (LOCATION *)SEP_MEalloc(SEP_ME_TAG_SED, sizeof(LOCATION),
					TRUE, NULL);
    sedtmp    = SEP_MEalloc(SEP_ME_TAG_TOKEN, MAX_LOC+1, TRUE, NULL);
    filtmp    = SEP_MEalloc(SEP_ME_TAG_TOKEN, MAX_LOC+1, TRUE, NULL);

    LOtos(Sep_Loc, &fptr2);
    STcopy(fptr2, sedtmp);
    STcopy(fptr2, filtmp);
    LOfroms(FILENAME & PATH, sedtmp, sedtmploc);
    LOfroms(FILENAME & PATH, filtmp, filtmploc);
    LOdetail(sedtmploc, sed_dev, sed_path, sed_name, sed_type, sed_vers);
    STcopy(ERx("sed"),sed_type);
    SEP_LOcompose(sed_dev, sed_path, sed_name, sed_type, sed_vers, sedtmploc);
    STcopy(ERx("sdr"),sed_type);
    SEP_LOcompose(sed_dev, sed_path, sed_name, sed_type, sed_vers, filtmploc);

    /*
    ** Copy Sep SI_RACC file to a SI_TXT file.
    */
    SEPrewind(*Sep_file, FALSE);
    if ((ret_val = SIfopen(filtmploc,ERx("w"), SI_TXT, SCR_LINE, &fptr))
	!= OK)
	return(ret_val);

    for (Sep_file_empty = TRUE;
	 (ret_val = SEPgetrec(SEDbuffer, *Sep_file)) == OK;
	 SIputrec(SEDbuffer, fptr))
	if (Sep_file_empty)
	    Sep_file_empty = FALSE;

    SIclose(fptr);

    if (Sep_file_empty == FALSE)
    {   /*
	** Create command line for sed command.
	*/
	LOtos(SED_loc, &fptr1);
	LOtos(filtmploc, &fptr2);
	cmd_line = SEP_MEalloc(SEP_ME_TAG_TOKEN, MAX_LOC+1, TRUE, NULL);
	IISTprintf(cmd_line, "sed -f %s %s", fptr1, fptr2);

	/*
	** Close Sep file and run the SED.
	*/
	SEPclose(*Sep_file);
	ret_val = PCcmdline(NULL, cmd_line, PC_WAIT, sedtmploc, &cl_err);
	if(ret_val != OK)
	{
	    SEPopen(Sep_Loc, SCR_LINE, Sep_file);
	    del_floc(sedtmploc);
	    del_floc(filtmploc);
	    MEtfree(SEP_ME_TAG_SED);
	    return(1);
	}

	/*
	** Recreate Sep file.
	*/
#ifdef NT_GENERIC
	LOdelete(Sep_Loc);
#else
	del_floc(Sep_Loc);
#endif
	if ((ret_val = SIfopen(Sep_Loc, ERx("w"), SI_RACC, SCR_LINE, &fptr))
	    != OK)
	    return(ret_val);
	SIclose(fptr);
	SEPopen(Sep_Loc, SCR_LINE, Sep_file);

	/*
	** Open Sed output file.
	*/
	if ((ret_val = SIfopen(sedtmploc, ERx("r"), SI_TXT, SCR_LINE, &SEDfptr))
	    != OK)
	    return(ret_val);

	/*
	** Copy the Sed output file to the Sep file.
	*/
	while((ret_val = SIgetrec(SEDbuffer, SCR_LINE, SEDfptr)) == OK)
	    SEPputrec(SEDbuffer, *Sep_file);

	SEPclose(*Sep_file);
	SIclose(SEDfptr);

	/*
	** Reopen the sep file.
	*/
	SEPopen(Sep_Loc, SCR_LINE, Sep_file);

	/*
	** Clean up.
	*/
	del_floc(sedtmploc);
    }
    del_floc(filtmploc);
    MEtfree(SEP_ME_TAG_SED);
    return(OK);
}
Ejemplo n.º 8
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);
    }