Exemplo n.º 1
0
void
yyinit( void )
{
	char *name, *value, *map_path;

	/* zero the line counter */
	yylineno = 0;

	if( rulemap_path == NULL )
	{
		NMloc( FILES, FILENAME, ERx( "default.rfm" ), &loc );
		LOcopy( &loc, file_name, &loc );	
		LOtos( &loc, &map_path );
	}
	else
	{
		STcopy( rulemap_path, file_name );
		LOfroms( FILENAME, file_name, &loc );
		map_path = rulemap_path;
	}

	(void) PMmInit( &rulemap );
	if( PMmLoad( rulemap, &loc, PMerror ) != OK )
		PCexit( FAIL );

	/* initiate scan of rule map */
	if( PMmScan( rulemap, ERx( ".*" ), &rfm_scan, NULL, &name, &value )
		!= OK )
	{
		F_ERROR( "Rule file map %s is empty.", map_path );
	}

	/* set up LOCATION of first rule file */
	STcopy( value, file_name );
	NMloc( FILES, FILENAME, file_name, &loc );
	LOcopy( &loc, file_name, &loc );	

	/* initialize input pointer */
	yyp = &dummy;

	/* open rule file */
	if( SIfopen( &loc, ERx( "r" ), SI_TXT, SI_MAX_TXT_REC, &yyin )
		!= OK && yywrap() )
	{
		ERROR( "No configuration rule files were found." );
	}
}
Exemplo n.º 2
0
char *
xfaddpath(char *filename, i4  in_or_out)
{
    auto char	*wholename;

    if (filename == NULL)
    {
	wholename = NULL;
    }
    else if (in_or_out == XF_INTOFILE && Xf_into_path != NULL)
    {
	STcopy(Xf_into_path, Whole_name);

# ifdef UNIX
	if (Whole_name[STlength(Whole_name)-1] != '/')
	    STcat(Whole_name, ERx("/"));
# else 
# ifdef DESKTOP
	if (Whole_name[STlength(Whole_name)] != '\\')
	    STcat(Whole_name, ERx("\\"));
# endif /* DESKTOP */
# endif

	wholename = STcat(Whole_name, filename);
    }
    else if (in_or_out == XF_FROMFILE && Xf_from_path != NULL)
    {
	STcopy(Xf_from_path, Whole_name);

# ifdef UNIX
	if (Whole_name[STlength(Whole_name)-1] != '/') 
	    STcat(Whole_name, ERx("/"));
# else
# ifdef DESKTOP
	if (Whole_name[STlength(Whole_name)] != '\\')
	    STcat(Whole_name, ERx("\\"));
# endif /* DESKTOP */
# endif
	wholename = STcat(Whole_name, filename);
    }
    else
    {
	LOcopy(&Xf_dir, Tmppath_buf, &Tmppath);

	/* add the file name to location */
	LOfstfile(filename, &Tmppath);

	LOtos(&Tmppath, &wholename);
    }
# ifdef NT_GENERIC
    xlate_backslash(wholename);
# endif /* NT_GENERIC */
    return (wholename);
}
Exemplo n.º 3
0
/******************************************************************************
** Name: MEsmdestroy()	- Destroy a shared memory segment
**
** Description:
**	Remove the shared memory segment specified by shared memory identifier
**	"key" from the system and destroy any system data structure associated
**	with it.
**
**	Note: The shared memory pages are not necessarily removed from
**	processes which have the segment mapped.  It is up to the clients to
**	detach the segment via MEfree_pages prior to destroying it.
**
**	Protection Note: The caller of this routine must have protection to
**	destroy the shared memory segment.  Protections are enforced by the
**	underlying Operating System.  In general, this routine can only be
**	guaranteed to work when executed by a user running with the same
**	effective privledges as the user who created the shared memory segment.
**
** Inputs:
**	user_key			identifier which was previosly
**				      used in a successful MEget_pages() call
**				      (not necessarily a call in this process)
**
** Outputs:
**	err_code 		System specific error information.
**
**	Returns:
**	    OK
**	    ME_NO_PERM		    No permission to destroy shared memory
**				            segment.
**	    ME_NO_SUCH_SEGMENT	indicated shared memory segment does not
**				            exist.
**	    ME_NO_SHARED	    No shared memory in this CL.
**	    ME_BAD_ADVICE	    call was made during ME_USER_ALLOC
**
**	Exceptions:
**	    none
**
** Side Effects:
**	    none
**
******************************************************************************/
STATUS
MEsmdestroy(char        *user_key,
            CL_ERR_DESC *err_code)
{
	LOCATION        location;
	LOCATION        temp_loc;
	char            loc_buf[MAX_LOC + 1];
	STATUS          ret_val = OK;

	CLEAR_ERR(err_code);

	/*
	 * Get location of ME files for shared memory segments.
	 */

# ifdef MCT
	gen_Psem(&NM_loc_sem);
# endif /* MCT */
	ret_val = NMloc(FILES,
	                PATH,
	                (char *) NULL,
	                &temp_loc);
	if (!ret_val)
	{
		LOcopy(&temp_loc,
		       loc_buf,
		       &location);
		LOfaddpath(&location,
		           ME_SHMEM_DIR,
		           &location);
		LOfstfile(user_key,
		          &location);

		if (LOexist(&location) != OK)
			ret_val = FAIL;
		else {
			ret_val = LOdelete(&location);
			switch (ret_val) {
			case OK:
			case ME_NO_PERM:
				break;;

			default:
				ret_val = ME_NO_SUCH_SEGMENT;
				break;;
			}
		}
	}
# ifdef MCT
	gen_Vsem(&NM_loc_sem);
# endif /* MCT */
	return (ret_val);
}
Exemplo n.º 4
0
static bool
yywrap( void )
{
	char *name, *value;

	/* initialize the line counter */
	yylineno = -1;

	while( TRUE )
	{
		/* get the name of next rule specification to be loaded */
		if( PMmScan( rulemap, NULL, &rfm_scan, NULL, &name,
			&value ) != OK )
		{
			if( yyin != (FILE *) NULL )
				(void) SIclose( yyin );
			return( TRUE ); /* no more files */
		}

		/* set up LOCATION of rule file */
		STcopy( value, file_name );
		NMloc( FILES, FILENAME, file_name, &loc );
		LOcopy( &loc, file_name, &loc );	

		if( yyin != (FILE *) NULL )
		{
			(void) SIclose( yyin );
			yyin = (FILE *) NULL;
		}

		/* try to open rule file */
		if( SIfopen( &loc, ERx( "r" ), SI_TXT, SI_MAX_TXT_REC, &yyin )
			== OK && SIgetrec( yybuf, sizeof( yybuf ), yyin )
			== OK )
		{
			break;	
		}
	}

	/* initialize input pointer */
	yyp = &dummy;

	/* another file was opened - so we're not done yet */
	return( FALSE );
}
Exemplo n.º 5
0
STATUS
MO_oidmap_set(i4 offset,
	   i4  luserbuf,
	   char *userbuf,
	   i4  objsize,
	   PTR object )
{
    FILE	*fp;
    STATUS	cl_stat;
    STATUS	set_stat;
    LOCATION	loc;
    char	loc_buf[ MAX_LOC ];
    char	line[ SI_MAX_TXT_REC ];
    char	*words[ 2 ];
    i4		wordcount;
    SYSTIME	new_time;
    
    NMloc( FILES, FILENAME, userbuf, &loc );
    LOcopy( &loc, loc_buf, &loc );
    cl_stat = LOlast( &loc, &new_time );

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

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

	    }
	    SIclose( fp );
	}
    }
    return( cl_stat );
}
Exemplo n.º 6
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);
}
Exemplo n.º 7
0
STATUS
xfsetdirs(char *dir, char *frompath, char *intopath)
{
    auto i2	dirflag;
    auto char 	*s;
    char	*locbuf;
    STATUS	status;

    locbuf = XF_REQMEM(MAX_LOC + 1, FALSE);

    if (dir == NULL || *dir == EOS)	
    {
	/* Default to current directory. */
	status = LOgt(locbuf, &Xf_dir);
        if(status != OK)
        {
#ifdef UNIX                 
            status = LOfakepwd(locbuf, &Xf_dir);
#endif
            if(status != OK)
            {
                IIUGerr(E_XF0061_Can_Not_Determine_Dir, UG_ERR_ERROR, 0);
                return(FAIL);
            }
        }
	dir = NULL;
    }
    else
    {
	STlcopy(dir, locbuf, MAX_LOC);
	if (LOfroms(PATH, locbuf, &Xf_dir) != OK)
	{
	    IIUGerr(E_XF0006_Invalid_directory_pat, UG_ERR_ERROR, 1, dir);
	    return (FAIL);
	}

	if (!LOisfull(&Xf_dir))
	{
	    auto LOCATION	xloc;
	    char		xbuf[MAX_LOC + 1];

	    /* 
	    ** path spec. is a relative specification -- we must expand it 
	    ** to a full pathname. 
	    */
	    LOcopy(&Xf_dir, xbuf, &xloc);
	    status = LOgt(locbuf, &Xf_dir);
            if(status != OK)
            {
                IIUGerr(E_XF0061_Can_Not_Determine_Dir, UG_ERR_ERROR, 0);
                return(FAIL);
            }
	    LOaddpath(&Xf_dir, &xloc, &Xf_dir);
	}

	/* LOisdir and LOexist are archaic and should be replaced by LOinfo. */
	LOisdir(&Xf_dir, &dirflag);
	if (dirflag != ISDIR || LOexist(&Xf_dir) != OK)
	{
	    IIUGerr(E_XF0006_Invalid_directory_pat, UG_ERR_ERROR, 1, dir);
	    return (FAIL);
	}
    }
    LOtos(&Xf_dir, &s);

    /* the COPY FROM path doesn't have to exist. */
    if (frompath != NULL && *frompath != EOS)
	Xf_from_path = saveloc(frompath);

    /* the COPY INTO path doesn't have to exist. */
    if (intopath != NULL && *intopath != EOS)
	Xf_into_path = saveloc(intopath);

    IIUGmsg(ERget(S_XF0064_Unload_Directory_is), FALSE, 1, 
		(PTR)(Xf_into_path == NULL ? s : Xf_into_path));
    IIUGmsg(ERget(S_XF0065_Reload_Directory_is), FALSE, 1, 
		(PTR)(Xf_from_path == NULL ? s : Xf_from_path));

    return (OK);
}
Exemplo n.º 8
0
/*****************************************************************************
** Name: ME_makekey()	- Make WIN32 file for mapping
**                        shared memory from user key.
**
** Description:
**	Create a file to identify a shared memory segment.  The file's inode
**	will be used as a shared memory key.  The file's existence will be
**	used to track shared segments on the system.
**
** Inputs:
**	key			character key identifying shared segment.
**
** Outputs:
**	return value
**
**	Returns:
**	    HANDLE  to opened file, or
**	    -1      file could not be created.
**
**	Exceptions:
**	    none
**
** Side Effects:
**	    File created in installation's memory directory.
**
*****************************************************************************/
HANDLE
ME_makekey(char *user_key)
{
	LOCATION location;
	LOCATION temp_loc;
	char     loc_buf[MAX_LOC + 1];
	char	 *shmemname;

	STATUS   ret_val;
	HANDLE   handle;

	/*
	 * Build location to file in MEMORY directory. Get location of ME
	 * files for shared memory segments.
	 */

# ifdef MCT
	gen_Psem(&NM_loc_sem);
# endif /* MCT */
	ret_val = NMloc(FILES,
	                PATH,
	                (char *) NULL,
	                &temp_loc);
	if (ret_val)
	{
# ifdef MCT
		gen_Vsem(&NM_loc_sem);
# endif /* MCT */
		return (HANDLE) -1;
	}

	LOcopy(&temp_loc,
	       loc_buf,
	       &location);
# ifdef MCT
	gen_Vsem(&NM_loc_sem);
# endif /* MCT */
	LOfaddpath(&location,
	           ME_SHMEM_DIR,
	           &location);
	LOfstfile(user_key,
	          &location);

	/*
	 * Create file to identify the shared segment. This will also allow
	 * MEshow_pages to tell what shared segments have been created.
	 */

	LOtos(&location,
	      &shmemname);
	handle = CreateFile(shmemname,
	                    GENERIC_READ | GENERIC_WRITE,
	                    FILE_SHARE_READ | FILE_SHARE_WRITE,
	                    NULL,
	                    OPEN_ALWAYS,
	                    FILE_ATTRIBUTE_NORMAL,
	                    NULL);

	if (handle == INVALID_HANDLE_VALUE) {
		handle = (HANDLE) -1;
	}

	return (handle);
}
Exemplo n.º 9
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);
}
Exemplo n.º 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);
}
Exemplo n.º 11
0
VOID
gca_save( GCA_SVC_PARMS *svc_parms )
{
    GCA_ACB		*acb = svc_parms->acb;
    GCA_SV_PARMS        *sv_parms = (GCA_SV_PARMS *)svc_parms->parameter_list;
    GCA_SAVE_DATA	save_data;
    PTR			user_buf = sv_parms->gca_ptr_user_data;
    i4			user_size = sv_parms->gca_length_user_data;
    char		cl_buf[ GCA_MAX_CL_SAVE_SIZE ];
    i4			cl_size;
    LOCATION		file_loc;
    LOCATION		tmp_loc;
    char		loc_buf[ MAX_LOC ];
    FILE		*save_file;
    char		*save_ptr;
    char		file_id[ MAX_LOC ];
    i4			j;

    /* Initialize status in service invoker's parameter list  */

    sv_parms->gca_status = E_GCFFFF_IN_PROCESS;

    /* Get CL save info */

    svc_parms->gc_parms.svc_buffer = (PTR)cl_buf;
    svc_parms->gc_parms.reqd_amount = sizeof( cl_buf );
    GCsave( &svc_parms->gc_parms );

    if ( svc_parms->gc_parms.status != OK )
	goto complete;

    cl_size = svc_parms->gc_parms.rcv_data_length;

    /* Format GCA_SAVE_DATA structure */

    save_data.save_level_major = GCA_SAVE_LEVEL_MAJOR;
    save_data.save_level_minor = GCA_SAVE_LEVEL_MINOR;
    save_data.cl_save_size = cl_size;
    save_data.user_save_size = user_size;
    save_data.assoc_id = acb->assoc_id;
    save_data.size_advise = acb->size_advise;
    save_data.heterogeneous = acb->flags.heterogeneous;

    /* Create the save file name.  */

    file_id[0] = '\0';

    (VOID) LOfroms(PATH & FILENAME, file_id, &tmp_loc);
    (VOID) LOuniq("IIGC", "TMP", &tmp_loc);
    (VOID) NMloc(TEMP, FILENAME, file_id, &tmp_loc);
    (VOID) LOcopy( &tmp_loc, loc_buf, &file_loc );
    (VOID) LOtos( &file_loc, &save_ptr );
    (VOID) STcopy( save_ptr, sv_parms->gca_save_name );

    /* Open save file. */

    if( SIfopen( &file_loc, "w", SI_VAR, 0, &save_file ) != OK )
    {
	GCA_DEBUG_MACRO(1)( "gca_send bad file open\n" );
	svc_parms->gc_parms.status = E_GC0014_SAVE_FAIL;
	goto complete;
    }

    /* Write GCA, CL, and user data to save file. */

    if( SIwrite( sizeof( save_data ), (PTR)&save_data, &j, save_file ) != OK 
     || cl_size && SIwrite( cl_size, (PTR)cl_buf, &j, save_file ) != OK 
     || user_size && SIwrite( user_size, user_buf, &j, save_file ) != OK
     || SIclose( save_file ) != OK )
    {
	GCA_DEBUG_MACRO(1)( "gca_send bad file write/close\n" );
	(VOID) SIclose( save_file );
	(VOID) LOdelete( &file_loc );
	svc_parms->gc_parms.status = E_GC0014_SAVE_FAIL;
    }

complete:

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    SIprintf( "Successfully executed.\n" );
    PCexit( 0 );
}
Exemplo n.º 13
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);
}
Exemplo n.º 14
0
int
main(int argc, char *argv[])
{
#define 	MAXBUF	4095

	char 	buf[ MAXBUF+1 ];
	int	iarg, ibuf, ichr;
	bool	debug = FALSE;
        CL_ERR_DESC     err_code;
        char		*p1 = NULL;
        char		pid[MAXBUF];
        char    	*database = ERx("");
        char    	*user = ERx("");
        char    	*xmlfile = ERx("");
        char    	sql_fname[LO_NM_LEN + 1];
        char    	*work_dir = NULL;
        char    	directory[MAX_LOC + 1]; 
        char    	*tmp_dir = NULL;
        char		tmp_buf[MAX_LOC + 1];
        char		subdir_buf[MAX_LOC + 1];
        char		sql_loc_buf[MAX_LOC + 1];
	char		*progname; 
        LOCATION    tmp_dir_loc;
        LOCATION    tmp_subdir_loc;
        LOCATION    tmp_buff_loc;
        LOCATION    curr_loc;
        LOCATION    sql_file_loc;
	char        *password = ERx("");
	char        *groupid = ERx("");
	ARGRET  rarg;
        i4      pos;
	LOCATION    xmlfile_loc;
	FILE	    *xmlfile_read;
	STATUS	    stat = FAIL;
	char	    dbuf[256];
	char	    encode[32];
        u_i4        tmppid;
        TM_STAMP    tm_stamp;


	/* Tell EX this is an ingres tool. */
   	(void) EXsetclient(EX_INGRES_TOOL);

	/* Call IIUGinit to initialize character set attribute table */
	if ( IIUGinit() != OK)
	    PCexit(FAIL);

	progname = ERget(F_XM0006_IMPXML);
	FEcopyright(progname, ERx("2001")); 

	/*
	** Get arguments from command line
	*/

	/* required parameters */

	if (FEutaopen(argc, argv, ERx("xmlimport")) != OK)
          PCexit(FAIL);

	/* database name is required */
	if (FEutaget(ERx("database"), 0, FARG_PROMPT, &rarg, &pos) != OK)
          PCexit(FAIL);
	database = rarg.dat.name;

        if (FEutaget(ERx("xmlfile"), 0, FARG_PROMPT, &rarg, &pos) != OK)
            PCexit(FAIL);
        xmlfile = rarg.dat.name;

        if (FEutaget(ERx("user"), 0, FARG_FAIL, &rarg, &pos) == OK)
            user = rarg.dat.name;

        if (FEutaget(ERx("password"), 0, FARG_FAIL, &rarg, &pos) == OK)
        {
            char *IIUIpassword();

            if ((password = IIUIpassword(ERx("-P"))) == NULL)
            {
                FEutaerr(BADARG, 1, ERx(""));
                PCexit(FAIL);
            }
        }

        if (FEutaget(ERx("groupid"), 0, FARG_FAIL, &rarg, &pos) == OK)
          groupid = rarg.dat.name;

        if (FEutaget(ERx("debug"), 0, FARG_FAIL, &rarg, &pos) == OK)
	  debug = TRUE;

        ibuf = STlength(buf); 

        /* b121678: pid is no longer based on process id, but it's
        ** a random number instead.
        */
        PCpid(&tmppid);
        TMget_stamp(&tm_stamp);
        MHsrand2(tmppid * tm_stamp.tms_usec);
        STprintf(pid, "%x", MHrand2());

#ifdef xDEBUG
        SIprintf(" the pid is: %s \n", pid);
#endif

        /* create the sql file */
	/* Avoid a name like "foo.xml.sql" on VMS, use pid.sql instead */
        STcopy(pid, sql_fname); 
        STcat(sql_fname, ".sql");

        /* 
        ** create in the temp location a directory 
        ** with the name pid. set this directory 
        ** as the working directory for impxml
        */

      NMloc (TEMP, PATH, NULL, &tmp_dir_loc);	
      /* make a location for TMP loc */
      /* print location name */
      LOcopy (&tmp_dir_loc, tmp_buf, &tmp_buff_loc);
      LOtos (&tmp_buff_loc, &tmp_dir);

#ifdef xDEBUG
      SIprintf ("temploc: %s \n", tmp_dir);
#endif

      /* make a subdir location with filename, pid */
      STcopy (pid, subdir_buf);				
      /* Initialize result loc so that everyone is happy */
      LOcopy (&tmp_dir_loc, sql_loc_buf, &sql_file_loc); 
      /* Generate location for temp subdirectory */
      if (LOfaddpath (&tmp_dir_loc, subdir_buf, &sql_file_loc) != OK)
      {
	 IIUGerr(E_XM0007_Locname_Failed, UG_ERR_FATAL, 2, tmp_dir, subdir_buf);
	 /* NOTREACHED */
      }

      /* print the location name */
      LOcopy (&sql_file_loc, tmp_buf, &tmp_buff_loc);    
      LOtos (&tmp_buff_loc, &work_dir);

#ifdef xDEBUG
	SIprintf ("work dir loc: %s \n", work_dir);
#endif

      /* create the subdir */
      if (LOcreate (&sql_file_loc) != OK) {
	 IIUGerr(E_XM0008_Create_Temp_Dir, UG_ERR_ERROR, 1, work_dir);
	 PCexit(FAIL);
      }

      STcopy(work_dir, directory);

#ifdef xDEBUG
      SIprintf ("sql file name: %s \n", sql_fname);
      SIprintf ("xml file name: %s \n", xmlfile);
#endif

      /* Execute the command impxml */	
      STprintf (buf, ERx( "impxml -d=\"%s\" -o=\"%s\" " ),  directory, sql_fname);

      /* encoding? */
      if ( (LOfroms(PATH & FILENAME, xmlfile, &xmlfile_loc) != OK)
          ||
	  (SIopen(&xmlfile_loc, "r", &xmlfile_read) != OK)
	  ||
	  (xmlfile_read == NULL)
	 )
      {
	  IIUGerr(E_XM0009_Cannot_Open_File, UG_ERR_ERROR, 1, xmlfile);
          PCexit(FAIL);
      }

      /* scan XML declaration for encoding, if any */
      if (stat = SIgetrec(dbuf, sizeof(dbuf) - 1, xmlfile_read) == OK)
      {
	  char 	*d = dbuf;
	  i4	i = 0;

	  for (d = dbuf; d != (dbuf + sizeof(dbuf)); d++)
	  {
	      if (MEcmp(d, ERx("encoding="), sizeof(ERx("encoding=")) - 1) == 0)
	      {
		  d += sizeof(ERx("encoding="));
		  while (MEcmp (d, "\'", sizeof(char)) && MEcmp(d, "\"", sizeof(char)))
		      MEcopy(d++, sizeof(char), &encode[i++]);
		  encode[i++] = MIN_CHAR;
		  encode[i] = EOS;
		  STcat(buf, ERx("-x="));
		  STcat(buf, encode);
		  break;
	      }
	  }
      }
      else if (stat != ENDFILE)
      {
          /* unable to read file, report error */
	  IIUGerr(E_XM000A_Cannot_Read_File, UG_ERR_ERROR, 1, xmlfile);
	  PCexit(FAIL);
      }

      stat = SIclose(xmlfile_read);

      STcat(buf, xmlfile);

#ifdef xDEBUG
      SIprintf ( " query send: %s \n", buf);
#endif

      /* 	Execute the command.  
      */

      if( PCcmdline((LOCATION *) NULL, buf, PC_WAIT, 
  		(LOCATION *)NULL, &err_code) != OK )
      {
	if (!debug)
	    LOdelete(&sql_file_loc);
	PCexit(FAIL);
      }

      /*
      **	we should run the sql script 
      **	sql dbname < new_filename
      */
      
      /* save the current location */
      LOcopy(&sql_file_loc, tmp_buf, &curr_loc);

      /* make a full location path to the location first */
      LOfroms(FILENAME, sql_fname, &tmp_buff_loc);
      LOstfile(&tmp_buff_loc, &curr_loc);
      LOcopy (&curr_loc, tmp_buf, &tmp_buff_loc);
      LOtos (&tmp_buff_loc, &tmp_dir);

#ifdef xDEBUG
      SIprintf ("sql file is: %s \n", tmp_dir);
#endif

      /* No space between < and input file for VMS */
      STprintf(buf, ERx( "sql -s %s %s %s %s <%s" ),
			database, user, password, groupid, tmp_dir);
#ifdef xDEBUG
      SIprintf (" query send: %s \n", buf);
#endif

      /*
      **	Execute the command.
      */

      if( PCcmdline((LOCATION *) NULL, buf, PC_WAIT, 
              (LOCATION *)NULL, &err_code) != OK )
      {
	if (!debug)
	    LOdelete(&sql_file_loc);
        PCexit(FAIL); 
      }

      /*
      **    Delete the location
      */
      if (!debug)
	LOdelete(&sql_file_loc);

      PCexit(OK);
}
Exemplo n.º 15
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);
}
Exemplo n.º 16
0
edit()
{
	register char		*p;
	LOCATION		t_loc,
				loc;
	FILE			*fp;
	char			errbuf[ER_MAX_LEN + 1];
	char			input[MAX_LOC + 1];
	char			*editfile;
	char			*ingedit;
	i4			rflag;
	STATUS			status;
	i4			c;
#ifdef CMS
	i4			Notempty = 1;
#endif /* CMS */

	GLOBALREF	char	*IIMOildInitLnDraw;

	FUNC_EXTERN 	char		*getfilenm();
	FUNC_EXTERN 	char		*macro();


	if (!Newline)
	{
		q_putc(Qryiop, '\n');
		Newline = TRUE;
	}

	Autoclear	= 0;
	editfile	= getfilenm();
	rflag		= 0;

	if (*editfile == '\0')
	{
		rflag	 = 1;
		input[0] = EOS;


		if ((status = NMloc( TEMP, PATH, (char *)NULL, &t_loc)) ||
		    (status = LOuniq( ERx( "query" ), ERx( "edt" ), &t_loc)))
		{
			STcopy( ERx( "queryXXX" ), input );
		}
		else
		{
			LOcopy( &t_loc, input, &loc );
		}

		status = SIfopen( &loc, ERx( "w" ), (i4)SI_TXT,
				  (i4)SI_MAX_TXT_REC, &fp );
	}
	else
	{
		/* use the path and file name the user gave you */

		STcopy(editfile, input);

		if (!(status = LOfroms(PATH & FILENAME, input, &loc)))
			status = SIfopen( &loc, ERx("w"), (i4)SI_TXT,
					  (i4)SI_MAX_TXT_REC, &fp );
	}

	if (status)
	{
		if (status == FAIL)
			errbuf[0] = '\0';
		else
			ERreport(status, errbuf);

		putprintf(ERget(F_MO000C_Cant_create_qry_file),
				input, errbuf);

		cgprompt();
		return(0);
	}

	if (q_ropen(Qryiop, 'r') == (struct qbuf *)NULL)
		/* edit: q_ropen 1 */
		ipanic(E_MO0044_1500400);

	while ((c = (i4)q_getc(Qryiop)) > 0)
		SIputc((char)c, fp);

	SIclose(fp);

	if (Nodayfile >= 0)
	{
		putprintf(ERget(F_MO000D_editor_prompt));
		SIflush(stdout);
	}

	/*
	**	macro returns NULL if undefined, UTedit uses
	**		default editor if passed NULL.
	*/

	/* Bug 4875	-	Use editor defined by environment variable
		ING_EDIT. If that is not set then use the macro(editor). 
	*/

	NMgtAt((ERx("ING_EDIT")), &ingedit);
	if ( ingedit != NULL && *ingedit != EOS )
		p = ingedit;
	else

		p = macro(ERx("{editor}"));

	if (status = UTedit(p, &loc))
	{
		ERreport(status, errbuf);
		putprintf(ERget(F_MO000E_Can_t_start_up_editor), errbuf);

		cgprompt();
		return(0);
	}

	if (!rflag)
	{
		if (q_ropen(Qryiop, 'a') == (struct qbuf *)NULL)
			/* edit: q_ropen 2 */
			ipanic(E_MO0045_1500401);
	}
	else
	{
		if (q_ropen(Qryiop, 'w') == (struct qbuf *)NULL)
			/* edit: q_ropen 3 */
			ipanic(E_MO0046_1500402);

		if (status = SIfopen( &loc, ERx("r"), (i4)SI_TXT,
				      (i4)SI_MAX_TXT_REC, &fp ))
#ifdef CMS
		{
			Notempty = 0;
		}
#else
		{
			ERreport(status, errbuf);
			/* can't reopen editfile %s: %s\n */
			ipanic(E_MO0047_1500403,
				editfile, errbuf);
		}
#endif /* CMS */

#ifdef CMS
		if (Notempty)
		{
#endif /* CMS */
		Notnull = 0;

		while ((c = SIgetc(fp)) != EOF)
		{
			if (status)
			{
				ERreport(status, errbuf);
				/* Error reading edit file: %s\n */
				ipanic(E_MO0048_1500404, errbuf);
			}

			Notnull = 1;

			q_putc(Qryiop, (char)c);
		}

		SIclose(fp);


		if (status = LOpurge(&loc, 0))
		{
			ERreport(status, errbuf);
			putprintf(ERget(F_MO000F_Cant_delete_file), editfile, errbuf);
		}
#ifdef CMS
		} /* endif Notempty */
#endif /* CMS */
	}

#ifndef FT3270
	/* Re-Initialize IT line drawing */
	{
	    if (Outisterm && IIMOildInitLnDraw != NULL)
		SIprintf(ERx("%s"), IIMOildInitLnDraw);
	}
#endif

	cgprompt();

	return(0);
}