Example #1
0
/*
** Name: LOmkingpath	- make INGRES location's area path
**
** Description:
**	Makes missing subdirectories in a location's area path.
**
** Inputs:
**	area	"device" that the location is on
**	what	path to db, ckp, dmp, work, jnl
**	loc	set to full path of location
**	
** Outputs:
**	none
**
** Returns:
**	LO_NULL_ARG	area or what were NULL or empty
**	LO_NO_SUCH	required path component does not exist
**
** History:
**	03-dec-2003 (abbjo03)
**	    Created.
*/
STATUS
LOmkingpath(
char		*area,		/* "device" that the database is on */
char		*what,		/* path to db, ckp, dmp, work, or jnl */
LOCATION	*loc)		/* set to full path of location */
{
    STATUS	status;
    char	path[MAX_LOC+1];
    i4		flags;
    LOINFORMATION	info;

    /* check for legal arguments */
    if (area == NULL || *area == EOS || STtrmwhite(area) == 0 ||
		what == NULL || *what == EOS)
	return LO_NULL_ARG;

    LOdev_to_root(area, path);
    if ((status = LOfroms(PATH, path, loc)) != OK)
	return status;
    flags = LO_I_TYPE;
    if (LOinfo(loc, &flags, &info))
	return LO_NO_SUCH;
    if ((flags & LO_I_TYPE) == 0 || info.li_type != LO_IS_DIR)
	return LO_NO_SUCH;

    LOfaddpath(loc, SystemLocationSubdirectory, loc);
    if ((status = LOfroms(PATH, path, loc)) != OK)
	return status;
    flags = LO_I_TYPE;
    if (LOinfo(loc, &flags, &info))
    {
	if ((status = LOcreate(loc)) != OK)
	    return status;
    }
    /* Set protections */
    if (setperms(loc, PROT_SRWE_ORWE_G_WRE) != OK)
	return FAIL;
	
    LOfaddpath(loc, what, loc);
    if ((status = LOfroms(PATH, path, loc)) != OK)
	return status;
    flags = LO_I_TYPE;
    if (LOinfo(loc, &flags, &info))
    {
	if ((status = LOcreate(loc)) != OK)
	    return status;
    }
    if (setperms(loc, PROT_SRWE_ORWE_G_WRE) != OK)
	return FAIL;

    flags = LO_I_PERMS;
    if ((status = LOinfo(loc, &flags, &info)) == OK &&
		(info.li_perms & LO_P_WRITE) == 0)
	status = LO_NO_PERM;

    return status;
}
Example #2
0
static STATUS
gcn_nq_fopen( char *name, char *mode, FILE **file )
{
    LOCATION	loc;
    STATUS	status;

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

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

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

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

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

error:

    if ( status != OK )  *file = NULL;
    return( status );
}
Example #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);
}
Example #4
0
/*{
** Name: CS_des_installation()  - destroy shared resources of an installation.
**
** Description:
**      Destroy the system shared memory segment, the logging/locking
**      shared memory segment, and the system semaphores associated with the
**      current installtion.  This is called from the logging code as a
**      result of "rcpconfig /shutdown".
**
**      It assumes that all the shared memory segments have already been
**      initialized by the appropriate routines.  The order of destruction
**      is important as a reverse may cause access violations on some
**      implementation of shared memory (where the segment disappears as
**      soon as it destroyed).
**
**      Any subsequent logging/locking or event routines called after this
**      routine will likely fail, so the caller should exit soon after this
**      call.
**
** Inputs:
**      none.
**
** Outputs:
**      none.
**
**
** History:
**      08-sep-88 (anton)
**          use LOcations for segments and destroy server segments
**      09-jun-88 (mmm)
**          written.
**      12-jun-89 (rogerk)
**          Change MEsmdestroy calls to take character string key instead
**          of LOCATION pointer.
**      22-dec-92 (mikem)
**          Changed a for(;;) to a do..while(FALSE) to shut up stupid acc
**          warning.
**      02-feb-92 (sweeney)
**          remove orphaned call to MEsmdestroy() on lockseg.
**      26-jul-1993 (bryanp)
**          Remove no-longer-needed system semaphores (css_semid sems).
**      03-jun-1996 (canor01)
**          Clean up semaphores for operating system threads.
**      16-sep-2002 (somsa01)
**          Make sure we run the appropriate "cscleanup" in the case of
**          ADD_ON64.
**	22-Jun-2009 (kschendel) SIR 122138
**	    VMS doesn't do hybrids, but update the conditional anyway.
*/
STATUS
CS_des_installation(void)
{
    STATUS      status;
    LOCATION    loc;
    char        *string;
    PID         pid;
    char        *argv[1];
    CL_ERR_DESC err_code;
    i4          i;
    char        segname[48];

    /* stop all servers that are still active, forcing them to exit if
    ** they have not already exited.
    */

    /* call the cscleanup code to clean up all the server slots still out
    ** there.
    */

    if ((NMloc(SUBDIR, PATH, "utility", &loc) == OK)    &&
#if defined(conf_BUILD_ARCH_32_64) && defined(BUILD_ARCH64)
        (LOfaddpath(&loc, "lp64", &loc) == OK) &&
#endif
        (LOfstfile("cscleanup", &loc) == OK))
    {
        /* if everything is successful try and run the cleanup program,
        ** else just do the rest and make user run "cscleanup" by themselves.
        */

        LOtos(&loc, &string);

        argv[0] = string;
        PCspawn(1, argv, TRUE, (LOCATION *) NULL, (LOCATION *) NULL, &pid);
    }

    do
    {
        /* destroy any left over server segements */

        for (i = 0; i < MAXSERVERS; i++)
        {

            STcopy("server.", segname);
            CVna(i, segname+STlength(segname));
#ifdef xCL_NEED_SEM_CLEANUP
                CS_cp_sem_cleanup(segname, &err_code);
#endif
            (VOID) MEsmdestroy(segname, &err_code);
        }
        /*                      FIX ME                        */
        /* kill off slave processes here or in cscleanup code */

        /* destroy the system shared memory segment */

#ifdef xCL_NEED_SEM_CLEANUP
        CS_cp_sem_cleanup("sysseg.mem", &err_code);
#endif
        status = MEsmdestroy("sysseg.mem", &err_code);
        if (status)
           break;

    } while (FALSE);

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

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

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

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

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

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

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

	LOwend(&lo_dir);

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

	return (status);
}
Example #6
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);
}
Example #7
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);
}
Example #8
0
ADF_CB *
FEadfcb ()
{
    if (!done)
    {
	char		*cp;
	DB_STATUS	rval;
	PTR		srv_cb_ptr;
	SIZE_TYPE	srv_size;
	SIZE_TYPE	dbinfo_size;
	PTR		dbinfoptr;
        STATUS          tmtz_status;
        STATUS          date_status;
	char		date_type_alias[100];
        char            col[] = "udefault";
    	STATUS          status = OK;
    	CL_ERR_DESC     sys_err;
	ADUUCETAB	*ucode_ctbl; /* unicode collation information */
        PTR         	ucode_cvtbl;


	
    	done = TRUE;

	/* first, get the size of the ADF's server control block */
	srv_size = adg_srv_size();

	/* allocate enough memory for it */
	if ((srv_cb_ptr = MEreqmem(0, srv_size, FALSE, (STATUS *)NULL)) == NULL)
	{
    	    EXsignal(EXFEBUG, 1, ERx("FEadfcb(alloc)"));
	}

	/*
	**  Fix up code so that "now" works properly for frontends.
	**  Only allocating enough for one (1) dbmsinfo() request.
	*/
	dbinfo_size = sizeof(ADF_TAB_DBMSINFO);
	if ((dbinfoptr = MEreqmem(0, dbinfo_size, TRUE, (STATUS*)NULL)) == NULL)
	{
		IIUGbmaBadMemoryAllocation(ERx("FEadfcb"));
	}

	dbinfo = (ADF_TAB_DBMSINFO *) dbinfoptr;

	dbinfo->tdbi_next = NULL;
	dbinfo->tdbi_prev = NULL;
	dbinfo->tdbi_length = dbinfo_size;
	dbinfo->tdbi_type = ADTDBI_TYPE;
	dbinfo->tdbi_s_reserved = -1;
	dbinfo->tdbi_l_reserved = (PTR)-1;
	dbinfo->tdbi_owner = (PTR)-1;
	dbinfo->tdbi_ascii_id = ADTDBI_ASCII_ID;
	dbinfo->tdbi_numreqs = 1;

	/*
	**  Now define request.
	*/
	dbinfo->tdbi_reqs[0].dbi_func = IIUGnfNowFunc;
	dbinfo->tdbi_reqs[0].dbi_num_inputs = 0;
	dbinfo->tdbi_reqs[0].dbi_lenspec.adi_lncompute = ADI_FIXED;
	STcopy("_BINTIM", dbinfo->tdbi_reqs[0].dbi_reqname);
	dbinfo->tdbi_reqs[0].dbi_reqcode = 1;
	dbinfo->tdbi_reqs[0].dbi_lenspec.adi_fixedsize = 4;
	dbinfo->tdbi_reqs[0].dbi_dtr = DB_INT_TYPE;

	/*
	** set timezone in ADF cb  - Any errors must be reported
        ** after adg_init() called.
	*/

	if ( (tmtz_status = TMtz_init(&cb.adf_tzcb)) == OK)
        {
	   tmtz_status = TMtz_year_cutoff(&cb.adf_year_cutoff);
        }

	/* Always use INGRESDATE by default, and check 
	** 'ii.<node>.config.date_alias' (kibro01) b118702
	*/
	cb.adf_date_type_alias = AD_DATE_TYPE_ALIAS_INGRES;
	STprintf(date_type_alias,ERx("ii.%s.config.date_alias"),PMhost());
	date_status = PMget(date_type_alias, &cp);
	if (date_status == OK && cp != NULL && STlength(cp))
	{
	    if (STbcompare(cp, 0, ERx("ansidate"), 0, 1) == 0)
		cb.adf_date_type_alias = AD_DATE_TYPE_ALIAS_ANSI;
	    else if (STbcompare(cp, 0, ERx("ingresdate"), 0, 1) == 0)
		cb.adf_date_type_alias = AD_DATE_TYPE_ALIAS_INGRES;
	    else
		cb.adf_date_type_alias = AD_DATE_TYPE_ALIAS_NONE;
	}

	/* set timezone table to NULL in ADF cb, adg_init() will fill it */
	/* cb.adf_tz_table = NULL; - not needed, done in declaration above */

	/* Start up ADF */
    	rval = adg_startup(srv_cb_ptr, srv_size, dbinfo, 0);
	if (DB_FAILURE_MACRO(rval))
	{
	    /*
	    ** Before bailing out, try to be helpful. Since the environment
	    ** is likely not set up correctly, write hard coded messages
	    ** since error message fetch will likely fail in this situation.
	    */
	    char	*tempchar;
	    i4		dummy;
	    LOCATION	temploc;
	    NMgtAt("II_SYSTEM", &tempchar);
	    if (tempchar && *tempchar)
	    {
		LOfroms(PATH, tempchar, &temploc);
		if (LOexist(&temploc))
		{
		    tempchar = ERx("FEadfcb: II_SYSTEM DOES NOT EXIST\n");
		    SIwrite(STlength(tempchar), tempchar, &dummy, stderr);
		}
		else
		{
		    NMloc(ADMIN, FILENAME, ERx("config.dat"), &temploc);
		    if (LOexist(&temploc))
		    {
			tempchar = ERx("FEadfcb: II_SYSTEM IS NOT SET CORRECTLY\n");
			SIwrite(STlength(tempchar), tempchar, &dummy, stderr);
		    }
		}
	    }
	    else
	    {
		tempchar = ERx("FEadfcb: II_SYSTEM IS NOT SET\n");
		SIwrite(STlength(tempchar), tempchar, &dummy, stderr);
	    }
    	    EXsignal(EXFEBUG, 1, ERx("FEadfcb(start)"));
	}

	/* put the pointer to ADF's server control block in the ADF_CB */
	cb.adf_srv_cb = srv_cb_ptr;

	/* set up the error message buffer */
    	cb.adf_errcb.ad_ebuflen = DB_ERR_SIZE;
    	cb.adf_errcb.ad_errmsgp = ebuffer;

	/* initialize the ADF_CB */
    	rval = adg_init(&cb);
	if (DB_FAILURE_MACRO(rval))
	{
    	    EXsignal(EXFEBUG, 1, ERx("FEadfcb(init)"));
	}

	/* find out which natural language we should speak */
	cb.adf_slang = iiuglcd_langcode();

	/* Always QUEL; for SQL explictly change this with 'IIAFdsDmlSet()'. */
	cb.adf_qlang = DB_QUEL;

	/* lets get the multinational info */

	/* 
	** Defaults for all of these are initially set statically, above.
	*/
	NMgtAt(ERx("II_DATE_FORMAT"), &cp);
    	if ( cp != NULL && *cp != EOS )
    	{
	    FEapply_date_format(&cb,cp);
    	}

	NMgtAt(ERx("II_MONEY_FORMAT"), &cp);
    	if ( cp != NULL && *cp != EOS )
    	{
	    FEapply_money_format(&cb,cp);
    	}

	NMgtAt(ERx("II_MONEY_PREC"), &cp);
    	if ( cp != NULL && *cp != EOS )
    	{
	    FEapply_money_prec(&cb,cp);
    	}

	NMgtAt(ERx("II_DECIMAL"), &cp);
    	if ( cp != NULL && *cp != EOS )
    	{
	    FEapply_decimal(&cb,cp);
    	}

	NMgtAt(ERx("II_UNICODE_SUBS"), &cp);
	if ( !cp )
	{
	    cb.adf_unisub_status = AD_UNISUB_OFF;
	}
	else
	{
	    /* As with SET unicode_substitution take the first char */
	    cb.adf_unisub_status = AD_UNISUB_ON;
	    *cb.adf_unisub_char = cp[0];
	}

	NMgtAt(ERx("II_NULL_STRING"), &cp);
	if ( cp != NULL && *cp != EOS )
	{
	    FEapply_null(&cb,cp);
	}

	/* If there was a Timezone error other than the expected ingbuild
	** error TM_PMFILE_OPNERR, then lets report it now. */

        if (tmtz_status && (tmtz_status != TM_PMFILE_OPNERR))
        {
	    LOCATION    loc_root;
	    STATUS status = OK;
	    status = NMloc(FILES, PATH, ERx("zoneinfo"), &loc_root);
#if defined(conf_BUILD_ARCH_32_64) && defined(BUILD_ARCH64)
            status = LOfaddpath(&loc_root, ERx("lp64"), &loc_root);
#endif
#if defined(conf_BUILD_ARCH_64_32) && defined(BUILD_ARCH32)
    {
        /*
        ** Reverse hybrid support must be available in ALL
        ** 32bit binaries
        */
        char    *rhbsup;
        NMgtAt("II_LP32_ENABLED", &rhbsup);
        if ( (rhbsup && *rhbsup) &&
       ( !(STbcompare(rhbsup, 0, "ON", 0, TRUE)) ||
         !(STbcompare(rhbsup, 0, "TRUE", 0, TRUE))))
            status = LOfaddpath(&loc_root, "lp32", &loc_root);
    }
#endif /* ! LP64 */

            if ( status == OK )
            {
		status = LOexist(&loc_root);
            }
            if ( status == OK )
	    {
                   IIUGerr(tmtz_status, 0, 0);

                   /* As this may disappear from the screen quickly,
                   ** let's pause to allow the users to reflect on the
                   ** fact that the timezone info is (probably) wrong.
                   */
                   if (!IIugefa_err_function) PCsleep(5000);
	    }
        }

	/* Initialize unicode collation for UTF8 installations */
	if (CMischarset_utf8())
	{
          if (status = aduucolinit(col, MEreqmem, 
			&ucode_ctbl, &ucode_cvtbl, &sys_err))
          {
    	    EXsignal(EXFEBUG, 1, ERx("FEadfcb(alloc)"));
          }

          cb.adf_ucollation = (PTR) ucode_ctbl;

	  /* Set unicode normalization to NFC just in case 
	  ** Front end will need it.
	  */
          if ((status = adg_setnfc(&cb)) != E_DB_OK)
    	    EXsignal(EXFEBUG, 1, ERx("FEadfcb(alloc)"));
	}
	/* lets not do this again! */
    }

    return &cb;
}
Example #9
0
STATUS
getLocation(char *string,char *newstr,LOCTYPE *typeOfLoc)
{
    STATUS                 ret_val ;
    LOCATION               aLoc ;
    LOCATION               bLoc ;

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

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

    i4                     i ;

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

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

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

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

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

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

    MEfree(tmpaLocStr);
    MEfree(tmpbLocStr);

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

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

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

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

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

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

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

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

    }

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

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

	if (typeOfLoc)
	    *typeOfLoc = PATH;

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

    Locptr1 = &aLoc;
    Locptr2 = &bLoc;


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

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

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

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

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

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

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

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

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

	        char *tmpMPE = NULL ;

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

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

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

	    LOfroms( FILENAME, gl_file, Locptr1);
	}
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        LOfstfile( srcbuf, &loc );

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

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

        srcOpened = TRUE;

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

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

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

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

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

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

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

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

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

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

        LOfstfile( dstbuf, &loc );

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

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

        dstOpened = TRUE;

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

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

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

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

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

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

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

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

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

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

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


        cleanup_queues();

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

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

cvt_exit:

    cleanup_queues();

    if (srcOpened)
        SIclose(srcFile);
    if (dstOpened)
        SIclose(dstFile);
    PCexit( OK );
}
Example #11
0
i4
main(
i4	argc,
char *	argv[])
{
    char      c='\0';
    char      *tz_file=NULL;
    char      *tz_name=NULL;
    char      *tz_def;
    char      tzname[TM_MAX_TZNAME+1];
    char      tzfile[MAX_LOC+1];
    char      ioptarg[MAX_LOC + 1];
    char      tz_pmvalue[MAX_LOC + 1];
    char      tz_pmname[MAX_LOC + 1];
    char      *p, *ip, *pm_value;
    char      *tm_tztype;
    char      chr='/';
    char      *out_file;
    i4        ioptind=1, i;
    char      *tm_tztime;
    i4        timecnt, tempi, temptype, temptz;
    char      buf[sizeof(TM_TZ_CB)+TM_MAX_TIMECNT*(sizeof(i4)+1)];
    FILE      *fid;
    LOCATION  loc_root, tmp_loc;
    STATUS    status=OK;
    TM_TZ_CB  *tm_tz_cb;
    struct timevect time_v;

    appname = argv[0];

    if( TMtz_getopt(argc, argv, "n:name:f:file", &ioptind, ioptarg, &c) == OK)
    {
	switch (c) 
	{
	  case 'f':
	    tz_file = ioptarg;
	    break;
	  case 'n':
	    tz_name = ioptarg;
	    break;
	  default:
	    break;
	}
    }
    else
    {
	TMtz_usage();
	PCexit(FAIL);
    }

    if( tz_file == NULL)
    {
	if( tz_name == NULL)
	{
	    /* Get II_TIMEZONE_NAME value */
	    NMgtAt(ERx("II_TIMEZONE_NAME"), &tz_def);
	    if (!tz_def || !(*tz_def))
	    {
		SIprintf("%s: %s_TIMEZONE_NAME is not set\n", 
				appname, SystemVarPrefix);
		PCexit(FAIL);
	    }
	    STncpy(tzname, tz_def, TM_MAX_TZNAME);
	    tzname[ TM_MAX_TZNAME ] = EOS;
	}
	else
	{
	    STncpy(tzname, tz_name, TM_MAX_TZNAME);
	    tzname[ TM_MAX_TZNAME ] = EOS;
	}
	PMinit();	
	if( PMload( NULL, (PM_ERR_FUNC *)NULL) != OK)
	{
	    SIprintf("%s: Error loading PM %s_CONFIG/config.dat file\n", 
			appname, SystemVarPrefix);
	    PCexit(FAIL);	    
	}
	/* Get timezone file name */
	STprintf( tz_pmname, ERx("%s.*.tz.%s"), SystemCfgPrefix, tzname);
	if( PMget( tz_pmname, &pm_value) != OK)
	{
	    SIprintf("%s: Error locating %s in PM config.dat file\n",
		     appname, tz_pmname);
    	    PCexit(FAIL);	    
	}
	do
	{
	    if((status = NMloc(FILES, PATH, ERx("zoneinfo"), &loc_root)) != OK)
		break;
#if defined(conf_BUILD_ARCH_32_64) && defined(BUILD_ARCH64)
	    if((status = LOfaddpath(&loc_root, ERx("lp64"), &loc_root)) != OK)
	        break;
#endif
#if defined(conf_BUILD_ARCH_64_32) && defined(BUILD_ARCH32)
	    {
	        /*
	        ** Reverse hybrid support must be available in ALL
	        ** 32bit binaries
	        */
	        char    *rhbsup;
	        NMgtAt("II_LP32_ENABLED", &rhbsup);
	        if ( (rhbsup && *rhbsup) &&
	       ( !(STbcompare(rhbsup, 0, "ON", 0, TRUE)) ||
	         !(STbcompare(rhbsup, 0, "TRUE", 0, TRUE))))
	            status = LOfaddpath(&loc_root, "lp32", &loc_root);
	    }
#endif /* reverse hybrid */

	    STcopy( pm_value, tz_pmvalue);

	    /*
	     ** Compose the directory path 
	     */
	    for( p = tz_pmvalue, ip = tz_pmvalue; 
		(p = STchr(ip, chr)) != NULL;)
	    {
		*p = EOS;
		if((status = LOfaddpath(&loc_root, ip, &loc_root)) != OK)
		    break;
		ip = CMnext(p);
	    }
	   
	    /* 
	    ** Add file name to the directory path
	    */
	    if((status = LOfroms(FILENAME, ip, &tmp_loc)) != OK)
		break;
	    status = LOstfile( &tmp_loc, &loc_root);
	} while( FALSE);

	if( status != OK)
	{
	    SIprintf("%s: Error composing timezone file name for %s\n",
		     appname, tz_pmvalue);
	    PCexit(FAIL);
	}
    }
    else
    {
	STcopy("<unknown>", tzname);
	STncpy( tzfile, tz_file, MAX_LOC);
	tzfile[ MAX_LOC ] = EOS;
	if( LOfroms(FILENAME&PATH, tzfile, &loc_root) != OK)
	{
	    SIprintf("%s: Error composing timezone file name for %s\n",
		     appname, tz_pmvalue);
	    PCexit(FAIL);
	}
    }

    /*
    ** Now open the timezone information file
    */
    do
    {
	if((status = SIfopen( &loc_root, ERx("r"), SI_VAR, sizeof buf, &fid)) 
	             != OK)
	    break;
	status = SIread(fid, sizeof buf, &i, buf);
	status = SIclose(fid);
    } while(FALSE);

    if( status != OK)
    {
	LOtos( &loc_root, &out_file);
	SIprintf("%s: Error opening %s for timezone %s\n", 
		 appname, out_file, tzname);
	PCexit(FAIL);
    }

    tm_tz_cb = (TM_TZ_CB *)&buf;
    I4ASSIGN_MACRO( tm_tz_cb->timecnt, timecnt);

    /* Make sure the input file has correct file size */
    if( timecnt > TM_MAX_TIMECNT || timecnt < 0
        || i != sizeof(TM_TZ_CB) + timecnt*(sizeof(i4)+1))
    {
	LOtos( &loc_root, &out_file);
	SIprintf(
	  "%s: Invalid file format for timezone file %s for timezone %s\n",
          appname, out_file, tzname);
	SIprintf(
	  "         File size: %d, Expected file size: %d, time periods: %d\n",
	  i, sizeof(TM_TZ_CB) + timecnt*(sizeof(i4)+1), 
	  timecnt);
	PCexit(FAIL);
    }

    /* Now we are all set to display the content of timezone information file */
    LOtos( &loc_root, &out_file);    
    SIprintf("\n\n");
    SIprintf("timezone name:     %s\n", tzname);
    SIprintf("timezone file:     %s\n", out_file);    
    SIprintf("-------------------------------------");
    SIprintf("-------------------------------------\n");

    if(timecnt == 0)
    {
	I4ASSIGN_MACRO( tm_tz_cb->tzinfo[0].gmtoff, tempi);
	SIprintf("     Fixed GMT offset (secs): %d\n", tempi);      
    }
    else
    {
	SIprintf("\tPeriod Begin");
	SIprintf("\t\tGMT offset\n");
	SIprintf("\t(YYYY_MM_DD HH:MM)");
	SIprintf("\t(Minute)\n\n");
	tm_tztype = buf + sizeof(TM_TZ_CB);
	tm_tztime = tm_tztype + timecnt;
	i=0;
	while( i < timecnt)
	{
	    I4ASSIGN_MACRO( *tm_tztime, tempi);
	    /* Adjust for timezone */
	    if( i == 0)
		temptype = (i4)tm_tztype[i+1];
	    else
		temptype = (i4)tm_tztype[i-1];

	    I4ASSIGN_MACRO( tm_tz_cb->tzinfo[temptype].gmtoff, temptz);
	    /* Get real timezone */
	    tempi += temptz;
	    temptype = (i4)tm_tztype[i];
	    I4ASSIGN_MACRO( tm_tz_cb->tzinfo[temptype].gmtoff, temptz);
	    TMtz_cvtime( tempi, &time_v);
	    SIprintf("\t%04d_%02d_%02d %02d:%02d\t%d\t%s\n", 
		     time_v.tm_year+1900,
		     time_v.tm_mon+1, 
		     time_v.tm_mday,
		     time_v.tm_hour,
		     time_v.tm_min,
		     temptz/60,
		     tm_tz_cb->tzlabel + tm_tz_cb->tzinfo[temptype].abbrind);  
	    tm_tztime += sizeof(i4);
	    i++;
	}
    }
    PCexit(OK);
}