/* ** Name: CFReadConf ** ** Description: ** Read the configuration file a line at a time and build a list. ** ** Inputs: ** path path of file to read ** filename filename of file to read ** ** Outputs: ** loc Location to update with path and filename ** begin Starting line of the confiuration ** end Last line of the configuration ** ** Returns: ** OK success ** FAIL failure ** ** History: ** 11-Feb-2000 (fanra01) ** Created. */ STATUS CFReadConf( char* path, char* filename, LOCATION* loc, PRL* begin ) { STATUS status; char* locpath; FILE* fptr; PRL newline; PRL end; /* ** Get the location path */ LOtos( loc, &locpath ); STRCOPY( path, locpath ); if ((status = LOfroms( PATH, locpath, loc )) == OK) { LOfstfile( filename, loc ); if ((status = SIfopen( loc, "r", SI_TXT, 0, &fptr )) == OK) { do { status = SIgetrec( readbuf, SI_MAX_TXT_REC, fptr ); if (status != ENDFILE) { HALLOC( newline, RL, 1, &status ); if (newline != NULL) { newline->text = STRALLOC( readbuf ); if (*begin == NULL) { *begin = newline; newline->prev = newline; } else { end = (*begin)->prev; end->next = newline; newline->prev = end; (*begin)->prev = newline; } } } }while (status == OK); status = ((status == ENDFILE) || (status == OK)) ? OK : status; SIclose( fptr ); } else { PRINTF( "Error: %d - Unable to open file %s in %s.\n", status, filename, path ); } } return (status); }
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 ); }
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 ); }
STATUS append_file(char *filename) { LOCATION fileloc ; FILE *fileptr = NULL ; char buffer [SCR_LINE] ; if (LOfroms(FILENAME & PATH,filename,&fileloc) == OK && SEP_LOexists(&fileloc) && SIopen(&fileloc,ERx("r"),&fileptr) == OK) { while (SIgetrec(buffer,SCR_LINE,fileptr) == OK) append_line(buffer,0); return(SIclose(fileptr)); } else return(FAIL); }
void main(int argc, char *argv[]) { char buf[ MAXBUF+1 ]; int ibuf, ichr; /* ** Set the set command. */ STprintf(buf, ERx( "@set " )); switch(argc) { /* ** Construct the rest of the command from the ** command line argument and standard input. */ case 2: ibuf = sizeof(ERx("@set ")) - 1; for ( ichr = 0 ;(ibuf < MAXBUF) && argv[1][ichr]; ) { buf[ibuf++] = argv[1][ichr++]; } buf[ibuf++] = '='; /* ** Set EOS in case there is nothing from standard input. */ buf[ibuf] = '\0'; SIgetrec(&buf[ibuf], MAXBUF-ibuf, stdin); break; default: SIprintf(stderr,"echo Usage: ipsetp variable_name"); break; } /* ** Print out the set command. */ SIprintf("%s\n",buf); }
int main(int c, char **v) { i4 msg_id; i4 cnt = 0; char mbuf[ER_MAX_LEN]; i4 ret_len = 0; char msgbuf[101]; CL_ERR_DESC clerror; CL_ERR_DESC err_code; STATUS stat; i4 flag = 0; bool testsysdep = FALSE; bool logoper = FALSE; MEadvise(ME_INGRES_ALLOC); for (++v, --c; c > 0; ++v, --c) { char *w = *v; if (w[0] == '-') { switch (w[1]) { case 't': flag |= ER_TIMESTAMP; break; case 'n': flag |= ER_NOPARAM; break; case 's': testsysdep = TRUE; break; case 'o': logoper = TRUE; break; default: SIfprintf(stderr, "only valid options are -t, -s, -n and -o\n"); PCexit(FAIL); } } else SIfprintf(stderr, "ignoring invalid argument \"%s\"\n", v); } if (testsysdep) /* test system dependent error reporting */ { extern int errno; errno = 13; /* EACCES */ SETCLERR(&clerror, 0x10911, /* ER_INTERR_TESTMSG */ ER_open); STcopy("II_MSGDIR/erclf.msg", clerror.moreinfo[0].data.string); clerror.moreinfo[0].size = STlength(clerror.moreinfo[0].data.string); } while ((cnt++) < MAX_NUM_OF_LOOKUPS) { msg_id = -1; SIfprintf(stderr, "msg id, in hex, no 0x%s: ", testsysdep? " (try 10904) " : ""); if( OK != SIgetrec(msgbuf, 100, stdin) ) break; #if defined(any_aix) && defined(BUILD_ARCH64) (VOID) STscanf(msgbuf, "%x", &msg_id); #else (VOID) STscanf(msgbuf, "%p", &msg_id); #endif if (msg_id == -1) break; if ((stat = ERslookup(msg_id, testsysdep? &clerror : NULL, flag, (char *) NULL, mbuf, ER_MAX_LEN, -1, &ret_len, &err_code, 5, er_arg)) != OK) { SIfprintf(stderr, "ERslookup error. msg id is 0x%x, status is 0x%x\n", msg_id, stat); } else { SIfprintf(stderr, "*** ERslookup:\n%s\n", mbuf); SIfprintf(stderr, "*** ERget:\n%s\n", ERget(msg_id)); } if (testsysdep) { if ((stat = ERslookup(0, &clerror, flag, (char *) NULL, mbuf, ER_MAX_LEN, -1, &ret_len, &err_code, 5, er_arg)) != OK) { SIfprintf(stderr, "ERslookup error on CL_ERR_DESC. Status is 0x%x\n", stat); } else SIfprintf(stderr, "*** ERslookup (CL error):\n%s\n",mbuf); } if (logoper) { ERsend( ER_ERROR_MSG|ER_OPER_MSG, mbuf, ret_len, &err_code ); } } PCexit(OK); }
static STATUS yygetline( FILE *input ) { char *read_buf = infile->yytext, *p, *psave; i4 linelen = 0; STATUS rtn; bool still_reading = TRUE; /* ** If a line exists in the "unget" cache, just return success. */ if( infile->yyline_cache ) { infile->yyline_cache = FALSE; return( OK ); } /* ** Read lines from the input file until a non-continuation line is hit ** or the EOF is reached. */ else while (still_reading == TRUE) { /* Assume the line is not a continuation and read a line */ still_reading = FALSE; rtn = SIgetrec(read_buf, (i4)(MAX_LINE - linelen), input); /* Check for a continuation line */ if (rtn == OK) { ++infile->yylineno; /* Increment files line counter */ linelen = STlength(read_buf); /* Was the last character a continuation indicator? */ p = STrchr(read_buf, '\\'); if (p != NULL) { psave = p; CMnext(p); #ifdef VMS if (*p == EOS || CMcmpcase(p, ERx("\n")) == 0) #else if (CMcmpcase(p, ERx("\n")) == 0) #endif { /* At this point we determined the */ /* line is continued. */ still_reading = TRUE; read_buf = psave; STcopy(ERx(""), psave); } } } } /* Special condition exception: If the EOF was hit after an some */ /* data has already been read and we were still looking for */ /* non-continuation lines, just return back the data we have. */ if (OK != rtn && linelen > 0) return (OK); else return (rtn); }
/* ** Name: PCexec_suid - Execute a command as the ingres user. ** ** Description: ** This procedure works with the Ingres service to run the given ** command as the ingres user. It mimicks the "setuid" bit in UNIX. ** ** Inputs: ** cmdbuf - command to execute as the ingres user ** ** Outputs: ** none ** ** Returns: ** OK ** FAIL ** ** Side Effects: ** none ** ** History: ** 08-jan-1998 (somsa01) ** Created. ** 19-feb-1998 (somsa01) ** We need to pass to the service the current working directory ** as well. (Bug #89006) ** 25-feb-1998 (somsa01) ** We now have an input file for the process' stdin which ** runs through the OpenIngres service. ** 19-jun-1998 (somsa01) ** Use SYSTEM_PRODUCT_NAME for the name of the service. ** 10-jul-1998 (kitch01) ** Bug 91362. If user is 'system' run through OpenIngres service ** despite having access to server shared memory 'system' does not ** have required privilege to access semaphores/mutexes. ** 11-jun-1999 (somsa01) ** If the command is a startup command, then it is always run through ** the Ingres service. ** 03-nov-1999 (somsa01) ** A failure from ControlService() should be treated as a severe ** error which should not let us continue. ** 22-jan-2000 (somsa01) ** Return the exit code of the spawned process. Also, if the ** files exist, truncate them. The service name is now keyed off ** of II_INSTALLATION. ** 05-jun-2000 (somsa01) ** The Ingres installation may be started as the SYSTEM account, ** in which the 'ingres' user will not automatically have access ** to the shared memory segments. Therefore, even if the real ** user is 'ingres', check to see if he has access. ** 24-oct-2000 (somsa01) ** Removed the check on shared memory access. Access to the shared ** memory segment does not necessarily mean that the user running ** the process does not need to run the specified process as the ** Ingres owner. Also, generalized the check of the user with ** IDname_service(). ** 18-dec-2000 (somsa01) ** Modified the cases to run the command "as is" without the Ingres ** service. ** 20-mar-2002 (somsa01) ** If all is well, return the exit code of the child process that ** was executed. ** 29-mar-2002 (somsa01) ** Properly return the child process exit code. ** 11-apr-2003 (somsa01) ** While waiting for "pending" to not be set, give some CPU back ** to the OS. ** 29-Jul-2005 (drivi01) ** Allow user to run the command if he/she owns a shared ** segment and ingres is not running as a service. ** 06-Dec-2006 (drivi01) ** Adding support for Vista, Vista requires "Global\" prefix for ** shared objects as well. Replacing calls to GVosvers with ** GVshobj which returns the prefix to shared objects. ** Added PCadjust_SeDebugPrivilege to allow quering of ** System processes. ** 25-Jul-2007 (drivi01) ** On Vista, PCexec_suid is unable to use SE_DEBUG Privilege ** to query process status and retireve its exit code. ** The routine for monitoring a process and retrieving ** its exit code has been moved to Ingres Service. ** 05-Nov-2009 (wanfr01) b122847 ** Don't do a PCsleep unless you are waiting for more input */ STATUS PCexec_suid(char *cmdbuf) { EX_CONTEXT context; SERVICE_STATUS ssServiceStatus; LPSERVICE_STATUS lpssServiceStatus = &ssServiceStatus; struct SETUID setuid; DWORD ProcID; HANDLE SaveStdout; SECURITY_ATTRIBUTES sa; CHAR szRealUserID[25] = ""; CHAR *pszRealUserID = szRealUserID; CHAR szServiceUserID[25] = ""; CHAR *pszServiceUserID = szServiceUserID; DWORD BytesWritten, BytesRead = 0; CHAR *inst_id; CHAR SetuidShmName[64]; CHAR *temp_loc; CHAR InBuf[256], OutBuf[256]; static CHAR SetuidPipeName[32]; CL_ERR_DESC err_code; CHAR ServiceName[255]; DWORD ExitCode = 0; CHAR tchII_INSTALLATION[3]; BOOL SetuidDbCmd = FALSE, ServiceCommand = FALSE; int i, cmdlen; char *ObjectPrefix; u_i4 drType; SC_HANDLE schSCManager, OpIngSvcHandle; BOOL bServiceStarted = FALSE; if (EXdeclare(ex_handler, &context) != OK) { EXdelete(); PCexit(FAIL); } NMgtAt("II_INSTALLATION", &inst_id); STcopy(inst_id, tchII_INSTALLATION); /* ** See if this is a command that MUST be run through the Ingres ** service. */ cmdlen = (i4)STlength(cmdbuf); for (i = 0; ServiceCommands[i] ; i++) { if (STbcompare( cmdbuf, cmdlen, ServiceCommands[i], (i4)STlength(ServiceCommands[i]), FALSE ) == 0) { ServiceCommand = TRUE; break; } } /* ** If the user is the same as the user who started the Ingres ** service, just spawn the command. */ if (!ServiceCommand) { IDname(&pszRealUserID); if (!IDname_service(&pszServiceUserID) && STcompare(pszServiceUserID, pszRealUserID) == 0 && PCisAdmin()) { /* ** Attempt to just execute the command. */ return( PCcmdline( (LOCATION *) NULL, cmdbuf, PC_WAIT, (LOCATION *) NULL, &err_code) ); } else { /* ** If current user is not the same as service user and ingres is not ** running as a service, check if shared memory segment is owned ** by current user, if user has access to shared segment allow him ** to run the command. */ PTR shmem; SIZE_TYPE allocated_pages=0; STATUS status; if((status = MEget_pages(ME_MSHARED_MASK, 1, "lglkdata.mem", &shmem, &allocated_pages, &err_code)) == OK) { STprintf(ServiceName, "%s_Database_%s", SYSTEM_SERVICE_NAME, tchII_INSTALLATION); if ((schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT)) != NULL) { if ((OpIngSvcHandle = OpenService(schSCManager, ServiceName, SERVICE_QUERY_STATUS)) != NULL) { if (QueryServiceStatus(OpIngSvcHandle,lpssServiceStatus)) { if (ssServiceStatus.dwCurrentState != SERVICE_STOPPED) bServiceStarted = TRUE; } } } if (!bServiceStarted) return(PCcmdline( (LOCATION *) NULL, cmdbuf, PC_WAIT, (LOCATION *) NULL, &err_code) ); } } /* ** See if this command is an Ingres command which needs to interact ** with at least one database. */ for (i = 0; validSetuidDbCmds[i] ; i++) { if (STbcompare( cmdbuf, cmdlen, validSetuidDbCmds[i], (i4)STlength(validSetuidDbCmds[i]), FALSE ) == 0) { SetuidDbCmd = TRUE; break; } } /* ** If the user has access to the Ingres shared memory segment, ** just spawn the command provided that it is not in the ** validSetuidDbCmds list. */ if (!SetuidDbCmd) { PTR shmem; SIZE_TYPE allocated_pages=0; STATUS status; if (((status = MEget_pages(ME_MSHARED_MASK, 1, "lglkdata.mem", &shmem, &allocated_pages, &err_code)) == OK) || (status == ME_NO_SUCH_SEGMENT)) { if (status != ME_NO_SUCH_SEGMENT) MEfree_pages(shmem, allocated_pages, &err_code); return( PCcmdline( (LOCATION *) NULL, cmdbuf, PC_WAIT, (LOCATION *) NULL, &err_code) ); } } } /* ** We must run the command through the Ingres service. */ if ( STstrindex(cmdbuf, "-silent", 0, FALSE ) ) SilentMode = TRUE; iimksec(&sa); GVshobj(&ObjectPrefix); STprintf(SetuidShmName, "%s%sSetuidShm", ObjectPrefix, tchII_INSTALLATION); if ( (SetuidShmHandle = OpenFileMapping(FILE_MAP_READ | FILE_MAP_WRITE, FALSE, SetuidShmName)) == NULL ) { error_exit(GetLastError()); return(FAIL); } if ( (SetuidShmPtr = MapViewOfFile(SetuidShmHandle, FILE_MAP_WRITE | FILE_MAP_READ, 0, 0, sizeof(struct SETUID_SHM))) == NULL ) { error_exit(GetLastError()); return(FAIL); } /* Set up the information to send to the service. */ STcopy(cmdbuf, setuid.cmdline); GetCurrentDirectory(sizeof(setuid.WorkingDirectory), setuid.WorkingDirectory); NMgtAt("II_TEMPORARY", &temp_loc); drType = GetDriveType(NULL); if (drType == DRIVE_REMOTE) { STcopy(temp_loc, setuid.WorkingDirectory); } SaveStdout = GetStdHandle(STD_OUTPUT_HANDLE); CVla(GetCurrentProcessId(), setuid.ClientProcID); STprintf(SetuidPipeName, "\\\\.\\PIPE\\INGRES\\%s\\SETUID", inst_id); /* Set up the stdout file for the command. */ STprintf(OutfileName, "%s\\%sstdout.tmp", temp_loc, setuid.ClientProcID); if ( (OutFile = CreateFile(OutfileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, &sa, CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE ) { error_exit(GetLastError()); return(FAIL); } /* Set up the stdin file for the command. */ STprintf(InfileName, "%s\\%sstdin.tmp", temp_loc, setuid.ClientProcID); if ( (InFile = CreateFile(InfileName, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, &sa, CREATE_ALWAYS, FILE_FLAG_WRITE_THROUGH, NULL)) == INVALID_HANDLE_VALUE ) { error_exit(GetLastError()); return(FAIL); } /* Wait until the service is ready to process our request. */ while (SetuidShmPtr->pending == TRUE) PCsleep(100); SetuidShmPtr->pending = TRUE; /* Trigger the "setuid" event of the service. */ if ( (schSCManager = OpenSCManager(NULL, NULL, SC_MANAGER_CONNECT)) == NULL) { error_exit(GetLastError()); return(FAIL); } STprintf(ServiceName, "%s_Database_%s", SYSTEM_SERVICE_NAME, tchII_INSTALLATION ); OpIngSvcHandle = OpenService(schSCManager, ServiceName, SERVICE_USER_DEFINED_CONTROL); if (OpIngSvcHandle == NULL) { STprintf(ServiceName, "%s_DBATools_%s", SYSTEM_SERVICE_NAME, tchII_INSTALLATION ); OpIngSvcHandle = OpenService(schSCManager, ServiceName, SERVICE_USER_DEFINED_CONTROL); } if ( OpIngSvcHandle == NULL) { error_exit(GetLastError()); return(FAIL); } if (!ControlService(OpIngSvcHandle, RUN_COMMAND_AS_INGRES, lpssServiceStatus)) { error_exit(GetLastError()); CloseServiceHandle(schSCManager); return(FAIL); } WaitNamedPipe(SetuidPipeName, NMPWAIT_WAIT_FOREVER); /* Send the information to the service. */ if ( (Setuid_Handle = CreateFile(SetuidPipeName, GENERIC_READ|GENERIC_WRITE, FILE_SHARE_READ|FILE_SHARE_WRITE, &sa, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)) == INVALID_HANDLE_VALUE ) { error_exit(GetLastError()); return(FAIL); } if (!WriteFile(Setuid_Handle, &setuid, sizeof(struct SETUID), &BytesWritten, NULL)) { error_exit(GetLastError()); return(FAIL); } /* ** Retrieve information back from the service, and then ** disconnect from the pipe. */ if (!ReadFile(Setuid_Handle, &setuid, sizeof(struct SETUID), &BytesRead, NULL)) { error_exit(GetLastError()); return(FAIL); } ProcID = setuid.CreatedProcID; SetuidShmPtr->pending = FALSE; UnmapViewOfFile(SetuidShmPtr); SetuidShmPtr = NULL; CloseHandle(SetuidShmHandle); if ( (ProcID != -1) && (ProcID != -2) ) { /* ** Wait for the "spawned" process to exit, reading its output ** from the stdout file. */ for (;;) { if ( ((!ReadFile(OutFile, OutBuf, sizeof(OutBuf), &BytesRead, NULL) || (BytesRead == 0)) && setuid.ExitCode != STILL_ACTIVE )) break; if ( BytesRead && (!WriteFile(SaveStdout, OutBuf, BytesRead, &BytesWritten, NULL)) && setuid.ExitCode != STILL_ACTIVE) break; else if (BytesRead < sizeof(OutBuf)) PCsleep(200); /* ** Currently, the only DBA program which can require ** user input is verifydb. Therefore, when it spits out ** the appropriate messages asking for user input, get ** it from the end user and pass it along to the spawned ** process. */ if ( (STrstrindex(OutBuf, "S_DU04FF_CONTINUE_PROMPT", 0, FALSE) != NULL) || (STrstrindex(OutBuf, "S_DU0300_PROMPT", 0, FALSE) != NULL) ) { SIflush(stdout); MEfill(sizeof(OutBuf), ' ', &OutBuf); MEfill(sizeof(InBuf), ' ', &InBuf); SIgetrec(InBuf, 255, 0); WriteFile(InFile, InBuf, sizeof(OutBuf), &BytesWritten, NULL); } } ExitCode = setuid.ExitCode; CloseHandle(Setuid_Handle); CloseHandle(InFile); DeleteFile(InfileName); CloseHandle(OutFile); DeleteFile(OutfileName); CloseServiceHandle(OpIngSvcHandle); CloseServiceHandle(schSCManager); return(ExitCode); } else { error_exit(GetLastError()); return(FAIL); } }
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); }
/* ** Name: makeutable - make unicode collation element table ** ** Descrription: ** Reads input collation element text file and compiles a table. ** also reads the Unicode character database and adds attributes for ** each character found. Currently we only take note of canonical ** decomposition for normalization. ** ** Inputs: ** desfile - collation element description file ** ** Outputs: ** None ** ** Returns: ** utbl - collation element table ** ** History: ** 14-mar-2001 (stephenb) ** Created ** 5-apr-2001 (stephenb) ** Add code to read unciode character database. ** 17-may-2001 (stephenb) ** Read in combining class from character database. ** 24-dec-2001 (somsa01) ** Modified such that the varsize which is placed in the Unicode ** table is now a SIZE_TYPE rather than an i4. ** 12-dec-2001 (devjo01) ** Make sure 1st overflow entry is properly aligned. ** Add messages to report if files cannot be opened. ** 17-jul-2001 (gupsh01) ** Modified the placing of the decomposition enty to ** decomp structure in the file, to be the first entry. ** 04-Mar-2005 (hanje04) ** Add support for reverse hybrid builds, i.e. 64bit exe needs to ** call 32bit version. ** 17-May-2007 (gupsh01) ** Added support for reverse sorting of the accented characters. ** This is done to support @backwards tag in custom collation file. ** 08-Aug-2007 (kiria01) b118917 ** Detect lines relating to conditional special caseing and ignore them. ** 08-Aug-2007 (gupsh01) ** Fixed the typo for CASE_IGNORABLE setting. Also fixed the ** handling of Final_Sigma in the special_casing.txt. ** 08-Aug-2007 (gupsh01) ** Fixed the decomposition mapping which were not being set for ** composite characters. ** 24-Nov-2008 (gupsh01) ** When alloating the memory for recombination table make sure ** we initialize the buffer. */ static ADUUCETAB * makeutable( char *desfile) { char buf[MAX_UCOL_REC]; FILE *fp; FILE *dfp; LOCATION loc; char table_vers[MAX_UVERS] = ""; i4 lno = 0; char *recptr; char *separator; ADUUCETAB *tab = &w.utab; i4 num_rvals = 0; ADUUCETAB *epointer = (ADUUCETAB *)w.buff; /* entries first */ /* then instructions */ char *ipointer; SIZE_TYPE *varsize; char *tptr; ADU_UCEFILE *rrec = NULL; ADU_UCEFILE *cerec = NULL; char csval[7]; char svalue[21]; char *ceptr; char *comment; u_i4 cval; i4 numce; bool combent; i4 i; /* Stuff to track the size of the recomb_tbl entries */ u_i2 **recomb_def2d; u_i2 *recomb_def1d; char *recombtbl; char *tracker; SIZE_TYPE *recomb_tbl_size; i4 tr = 0; i4 j = 0; STATUS stat; i4 rcbufsz; char *tempbuf; i4 current_bytes; char *upperval; char *lowerval; char *titleval; char *endval; i4 bts = 0; i4 lcnt = 0; i4 tcnt = 0; i4 ucnt = 0; i4 row = 0; i4 col = 0; bool backward_set = FALSE; /* open file */ STcopy(desfile, buf); LOfroms(FILENAME, buf, &loc); if (SIopen(&loc, "r", &fp) != OK) { SIprintf("aducompile: Unable to open input file \"%s\".\n", loc.string ); return NULL; } varsize = (SIZE_TYPE *)(w.buff + ENTRY_SIZE); recomb_tbl_size = (SIZE_TYPE *)(varsize + 1); ipointer = (char*)(recomb_tbl_size + 1); ipointer = ME_ALIGN_MACRO(ipointer, sizeof(PTR)); /* this is a sparse table, make sure we initialize it */ MEfill(INSTRUCTION_SIZE + ENTRY_SIZE, 0, w.buff); *varsize = 0; /* read data */ while (SIgetrec(buf, sizeof(buf), fp) != ENDFILE) { lno++; if (buf[0] == '#') /* comment line */ continue; (VOID)STtrmwhite(buf); if (STcompare(buf, "") == 0) /* blank line */ continue; /* should first find version */ if (table_vers[0] == EOS) { if (STbcompare(buf, 8, "@version", 8, TRUE) == 0) { /* we don't parse the version string, maybe we should */ STlcopy(buf+9, table_vers, MAX_UVERS); continue; } else { SIprintf("Syntax error on line %d, version line must be first \ non-comment line in the file, ignored\n", lno); continue; } } /* then alternate weights (optional), currently un-supported */ if (STbcompare(buf, 10, "@alternate", 10, TRUE) == 0) { SIprintf("Syntax error on line %d, alternate weights are not \ currently supported, ignored\n", lno); continue; } /* now backwards lines (also not currently supported) */ if (STbcompare(buf, 10, "@backwards", 10, TRUE) == 0) { backward_set = TRUE; continue; } /* and rearrange lines */ if (STbcompare(buf, 10, "@rearrange", 10, TRUE) == 0) { bool strend = FALSE; u_i4 rval; for (recptr = buf + 10;;) { /* skip blanks */ if ((recptr = STskipblank(recptr, STlength(recptr))) == NULL) { /* blank string, ignore */ SIprintf("Syntax error on line %d, no characters in \ rearrange list, ignoring\n", lno); strend = TRUE; break; } /* find next comma separator */ if ((separator = STindex(recptr, ",", 0)) == NULL) { strend = TRUE; separator = recptr + 4; } if (separator - recptr != 4) { SIprintf("Syntax error on line %d, characters in a rearrange\ line must be a comma separated list of 4 digit hex values, ABORTING\n", lno); tab = NULL; break; }
STATUS Run_SED_on_file(SEPFILE **Sep_file,LOCATION *Sep_Loc) { STATUS ret_val ; CL_ERR_DESC cl_err; LOCATION *sedtmploc = NULL ; LOCATION *filtmploc = NULL ; char *SEDbuffer = NULL ; char *sedtmp = NULL ; char *filtmp = NULL ; char *cmd_line = NULL ; char *sed_dev = NULL ; char *sed_path = NULL ; char *sed_name = NULL ; char *sed_type = NULL ; char *sed_vers = NULL ; char *fptr1 = NULL ; char *fptr2 = NULL ; FILE *SEDfptr = NULL ; FILE *fptr = NULL ; bool Sep_file_empty ; sed_dev = SEP_MEalloc(SEP_ME_TAG_SED, LO_DEVNAME_MAX+1, TRUE, NULL); sed_path = SEP_MEalloc(SEP_ME_TAG_SED, LO_PATH_MAX+1, TRUE, NULL); sed_name = SEP_MEalloc(SEP_ME_TAG_SED, LO_FPREFIX_MAX+1, TRUE, NULL); sed_type = SEP_MEalloc(SEP_ME_TAG_SED, LO_FSUFFIX_MAX+1, TRUE, NULL); sed_vers = SEP_MEalloc(SEP_ME_TAG_SED, LO_FVERSION_MAX+1, TRUE, NULL); SEDbuffer = SEP_MEalloc(SEP_ME_TAG_SED, SCR_LINE+1, TRUE, NULL); /* ** Create Sed output file names. */ sedtmploc = (LOCATION *)SEP_MEalloc(SEP_ME_TAG_SED, sizeof(LOCATION), TRUE, NULL); filtmploc = (LOCATION *)SEP_MEalloc(SEP_ME_TAG_SED, sizeof(LOCATION), TRUE, NULL); sedtmp = SEP_MEalloc(SEP_ME_TAG_TOKEN, MAX_LOC+1, TRUE, NULL); filtmp = SEP_MEalloc(SEP_ME_TAG_TOKEN, MAX_LOC+1, TRUE, NULL); LOtos(Sep_Loc, &fptr2); STcopy(fptr2, sedtmp); STcopy(fptr2, filtmp); LOfroms(FILENAME & PATH, sedtmp, sedtmploc); LOfroms(FILENAME & PATH, filtmp, filtmploc); LOdetail(sedtmploc, sed_dev, sed_path, sed_name, sed_type, sed_vers); STcopy(ERx("sed"),sed_type); SEP_LOcompose(sed_dev, sed_path, sed_name, sed_type, sed_vers, sedtmploc); STcopy(ERx("sdr"),sed_type); SEP_LOcompose(sed_dev, sed_path, sed_name, sed_type, sed_vers, filtmploc); /* ** Copy Sep SI_RACC file to a SI_TXT file. */ SEPrewind(*Sep_file, FALSE); if ((ret_val = SIfopen(filtmploc,ERx("w"), SI_TXT, SCR_LINE, &fptr)) != OK) return(ret_val); for (Sep_file_empty = TRUE; (ret_val = SEPgetrec(SEDbuffer, *Sep_file)) == OK; SIputrec(SEDbuffer, fptr)) if (Sep_file_empty) Sep_file_empty = FALSE; SIclose(fptr); if (Sep_file_empty == FALSE) { /* ** Create command line for sed command. */ LOtos(SED_loc, &fptr1); LOtos(filtmploc, &fptr2); cmd_line = SEP_MEalloc(SEP_ME_TAG_TOKEN, MAX_LOC+1, TRUE, NULL); IISTprintf(cmd_line, "sed -f %s %s", fptr1, fptr2); /* ** Close Sep file and run the SED. */ SEPclose(*Sep_file); ret_val = PCcmdline(NULL, cmd_line, PC_WAIT, sedtmploc, &cl_err); if(ret_val != OK) { SEPopen(Sep_Loc, SCR_LINE, Sep_file); del_floc(sedtmploc); del_floc(filtmploc); MEtfree(SEP_ME_TAG_SED); return(1); } /* ** Recreate Sep file. */ #ifdef NT_GENERIC LOdelete(Sep_Loc); #else del_floc(Sep_Loc); #endif if ((ret_val = SIfopen(Sep_Loc, ERx("w"), SI_RACC, SCR_LINE, &fptr)) != OK) return(ret_val); SIclose(fptr); SEPopen(Sep_Loc, SCR_LINE, Sep_file); /* ** Open Sed output file. */ if ((ret_val = SIfopen(sedtmploc, ERx("r"), SI_TXT, SCR_LINE, &SEDfptr)) != OK) return(ret_val); /* ** Copy the Sed output file to the Sep file. */ while((ret_val = SIgetrec(SEDbuffer, SCR_LINE, SEDfptr)) == OK) SEPputrec(SEDbuffer, *Sep_file); SEPclose(*Sep_file); SIclose(SEDfptr); /* ** Reopen the sep file. */ SEPopen(Sep_Loc, SCR_LINE, Sep_file); /* ** Clean up. */ del_floc(sedtmploc); } del_floc(filtmploc); MEtfree(SEP_ME_TAG_SED); return(OK); }
STATUS ip_batch(i4 argc, char *argv[]) { i4 argvx; PKGBLK *pkg; uchar opid; uchar option = opNONE; LOCATION outloc; char line[ MAX_MANIFEST_LINE + 1 ]; LISTELE *lp; /* no command line arguments except mkresponse ** or exresponse allowed for ingbuild in form mode */ if ((argc < 2) || ((argc ==2) && ((pmode == TRUE) || (mkresponse == TRUE) || (exresponse == TRUE))) || ((argc ==3) && (((mkresponse == TRUE) || (exresponse == TRUE)) && (respfilename != NULL)))) /* No command-line args? */ return OK; /* Fine, must be forms mode; return without setting flag. */ batchMode = TRUE; /* We're in command-line mode. */ batchOutf = stdout; /* For now, we'll direct output to the terminal. */ /* Top of loop through the non-positional arguments on the command line. */ for (argvx = 1; argvx < argc; argvx++) { if (argv[argvx][0] != '-') /* Not a switch? Time for positional arg. */ break; /* Get the option code for the current flag and deal with it... */ switch (opid = lookup(&argv[argvx][1])) { /* instruct ingbuild to skip set up */ case opNOSETUP: noSetup = TRUE; break; case opEXPRESS: eXpress = TRUE; break; case opPATCH: continue; /* -install=<list of features> */ case opINSTALL: if (option != opNONE || argval == NULL) USAGE; option = opid; featlist = argval; if( !STbcompare("ice", 3, featlist, STlength(featlist), TRUE) || !STbcompare("ice64", 5, featlist, STlength(featlist), TRUE) ) Install_Ice = TRUE; break; /* ** -version, -products, -all, -describe ** (All the options that don't require values.) */ case opVERSION: case opPACKAGES: case opDESCRIBE: case opALL: if (option == opNONE) { featlist = argval; option = opid; break; } case opIGNORE: ignoreChecksum = TRUE; break; case opEXRESPONSE: exresponse = TRUE; break; case opRESPFILE: break; /* -acceptlicense is still accepted for forward compatibility */ case opACCEPTLIC: #if LICENSE_PROMPT acceptLicense = TRUE; #endif break; /* Fall through */ default: USAGE; } } /* ** When we break from the flags loop, we must have a maximum of one ** remaining argument... */ if (argvx < (argc - 1)) /* Too many non-flags at the end of the line. */ USAGE; if (exresponse && (option == opNONE)) { char *def_file="ingrsp.rsp"; char *filename; FILE *respfile; if (respfilename != NULL) filename = respfilename; else filename = def_file; if (OK == ip_open_response (ERx(""), filename, &respfile, ERx( "r" )) ) { bool found = FALSE; char line[MAX_MANIFEST_LINE + 1]; char *pkg_set = ERx("_set=YES"); char *setp, *realloc; i4 pkglen; i4 buflen = MAX_MANIFEST_LINE + 1; i4 space = buflen; while (SIgetrec((char *)&line, MAX_MANIFEST_LINE, respfile) == OK ) { /* Check for _set=YES */ setp = STstrindex(line, pkg_set, 0, 1); if(setp != NULL) { if(found == FALSE) { featlist = ip_alloc_blk( buflen ); } *setp = NULLCHAR; pkglen = STlength(line); if(found == TRUE) { if(space < (pkglen + 1)) { buflen += MAX_MANIFEST_LINE; realloc = ip_alloc_blk( buflen ); STcopy(featlist, realloc); MEfree(featlist); featlist = realloc; } STcat(featlist, ","); space--; } else { found = TRUE; } STcat(featlist, line); space = space - pkglen; } } /* end read loop */ ip_close_response(respfile); if( found == TRUE) { /* Need to test this does not override any other options that ** may be valid */ option = opINSTALL; } } else { PCexit ( FAIL ); } } /* ** If we have no positionals, no distribution device was provided on ** the command line. That might or might not be ok... */ if (argvx == argc) { switch (option) { case opPATCH: case opVERSION: case opPACKAGES: case opDESCRIBE: break; /* ...yes. */ default: USAGE; /* ...no. */ } } else /* We got a positional, so copy it into the global field. */ { STcopy(argv[argvx], distribDev); if( !IPCLsetDevice( distribDev ) ) USAGE; } if (option == opNONE) /* No option? Default to "all". */ option = opALL; if ( option == opALL ); batch_opALL = TRUE; /* ** First processing pass. If the option doesn't involve doing actual ** installation, just do whatever needs to be done, and return. ** If it's an installation option, mark all requested packages ** as selected, and continue. */ switch (option) { case opPACKAGES: SIfprintf(batchOutf,ERget(S_ST0179_pkg_list_header)); for( lp = distPkgList.head; lp != NULL; lp = lp->cdr ) { pkg = (PKGBLK *) lp->car; if( ip_is_visible( pkg ) || ip_is_visiblepkg( pkg ) ) { SIfprintf( batchOutf, ERx("\t%-16s %-30s\n"), pkg->feature,pkg->name ); } } return OK; case opVERSION: if (instRelID == NULL) { IIUGerr(E_ST017B_not_present,0,1,SystemProductName); return FAIL; } if (featlist == NULL) { SIfprintf(batchOutf, ERx("%s\n"), instRelID); return OK; } if (!apply_list(proc_version)) return FAIL; return OK; case opINSTALL: SCAN_LIST(distPkgList, pkg) { pkg->selected = NOT_SELECTED; } if (!apply_list(proc_install)) return FAIL; break; case opDESCRIBE: _VOID_ apply_list(proc_describe); return OK; default: for( lp = distPkgList.head; lp != NULL; lp = lp->cdr ) { pkg = (PKGBLK *) lp->car; switch (option) { case opALL: if ( ip_is_visible(pkg) || ip_is_visiblepkg( pkg ) ) pkg->selected = SELECTED; break; } } } /* ** If we haven't left yet, that must mean we have an install-class ** option, i.e. one that's going to cause us to actually install ** something. First of all, let's make sure that the user has ** defined II_AUTH_STRING and has selected something to install... */ #ifndef INGRESII if( !authStringEnv ) { IIUGerr( E_ST0117_license_required, 0, 0 ); return( FAIL ); } #endif /* INGRESII */ SCAN_LIST(distPkgList, pkg) { if (pkg->selected == SELECTED) break; } if (pkg == NULL) /* Got all the way through the list? Nothing selected! */ USAGE; /* If Ingres is up, no go; otherwise, do the installation... */ switch (option) { case opALL: case opINSTALL: if (ip_sysstat() == IP_SYSUP) { IIUGerr(E_ST0178_installation_is_up, 0, 2, SystemProductName, installDir); return FAIL; } #if LICENSE_PROMPT if( !acceptLicense ) license_prompt(); #endif ip_install(NULL); break; } return OK; }
i4 yylex() { bool pattern; bool component; bool keyword; char *keyhead; char yytext[ SI_MAX_TXT_REC + 1 ]; i4 yyleng; /* skip whitespace and comments */ while( CMwhite( yyp ) || *yyp == EOS || *yyp == '-' ) { /* check for comment */ if( *yyp == '-' ) { if( STbcompare( yyp, 2, ERx( "--" ), 2, FALSE ) == 0 ) { while( *yyp != EOS ) CMnext( yyp ); } else break; } if( *yyp == EOS ) { if( SIgetrec( yybuf, sizeof( yybuf ), yyin ) != OK && yywrap() ) { return( 0 ); } else { yyp = yybuf; ++yylineno; } } else CMnext( yyp ); } /* check for a SYMBOL, PATTERN or keyword */ yyleng = 0; pattern = FALSE; keyword = TRUE; keyhead = yyp; while( CMalpha( yyp ) || *yyp == '%' || *yyp == '$' || *yyp == '*' ) { /* check for component of legal SYMBOL or PATTERN */ component = FALSE; /* check for single-character component */ switch( *yyp ) { case '%': pattern = TRUE; case '*': case '$': component = TRUE; ++yyleng; CMnext( yyp ); if( *yyp == '.' ) { ++yyleng; CMnext( yyp ); keyword = FALSE; continue; } else if( CMalpha( yyp ) ) yyerror(); continue; } while( CMalpha( yyp ) || CMdigit( yyp ) || *yyp == '_' || *yyp == '-' ) { ++yyleng; CMnext( yyp ); component = TRUE; } if( component ) { if( *yyp == '.' ) { ++yyleng; CMnext( yyp ); keyword = FALSE; continue; } continue; } } /* check for uneaten '.' */ if( *yyp == '.' ) yyerror(); if( yyleng > 0 ) { /* A keyword, SYMBOL or PATTERN was scanned */ char *p; i4 i; /* put NULL-terminated copy in yytext */ STlcopy( keyhead, yytext, yyleng ); for( p = yytext, i = 0; i <= yyleng; CMnext( p ), i++ ); *p = EOS; /* check for keywords */ if( CMalpha( keyhead) && keyword ) { if( STequal( ERx( "IF" ), yytext ) != 0 ) return( IF ); if( STequal( ERx( "ELSE" ), yytext ) != 0 ) return( ELSE ); if( STequal( ERx( "ELSEIF" ), yytext ) != 0 ) return( ELSEIF ); if( STequal( ERx( "ENDIF" ), yytext ) != 0 ) return( ENDIF ); if( STequal( ERx( "MIN" ), yytext ) != 0 ) return( MIN ); if( STequal( ERx( "MAX" ), yytext ) != 0 ) return( MAX ); if( STequal( ERx( "VALID" ), yytext ) != 0 ) return( VALID ); if( STequal( ERx( "PRIME" ), yytext ) != 0 ) return( PRIME ); if( STequal( ERx( "SIGNED_INT" ), yytext ) != 0 ) return( SIGNED_INT ); if( STequal( ERx( "DECIMAL" ), yytext ) != 0 ) return( DECIMAL ); if( STequal( ERx( "SIZETYPE" ), yytext ) != 0 ) return( SIZETYPE ); if( STequal( ERx( "POWER2" ), yytext ) != 0 ) return( POWER2 ); if( STequal( ERx( "REQUIRES" ), yytext ) != 0 ) return( REQUIRES ); if( STequal( ERx( "UNDEFINED" ), yytext ) != 0 ) return( UNDEFINED ); if( STequal( ERx( "SUM" ), yytext ) != 0 ) { yylval.integer = SUM; return( SUM ); } if( STequal( ERx( "ON" ), yytext ) != 0 ) { yylval.real = 1; return( BOOL_CON ); } if( STequal( ERx( "OFF" ), yytext ) != 0 ) { yylval.real = 0; return( BOOL_CON ); } if( STequal( ERx( "IS" ), yytext ) != 0 ) { yylval.string = STalloc( yytext ); return( COMPARE_OP ); } if( STequal( ERx( "DIRECTORY" ), yytext ) != 0 ) return( DIRECTORY ); if( STequal( ERx( "FILE" ), yytext ) != 0 ) return( FILESPEC ); } /* valid SYMBOL or PATTERN */ yylval.string = STalloc( yytext ); if( pattern ) return( PATTERN ); /* don't accept a single '*' as SYMBOL */ if( yyleng != 1 || *yytext != '*' ) return( SYMBOL ); /* push '*' back onto the input stream */ CMprev( yyp, yybuf ); } /* check for EXEC_TEXT, STR_CON, or EXEC_TEXT_STR */ if( *yyp == '`' || *yyp == '"' ) { int exec_str = 0; char *initstr = yyp; char *p = yyp, *text, *yyprev; if ( *yyp == '"' ) { CMnext( yyp ); if ( *yyp == '`' ) { CMnext( p ); exec_str = 1; } else yyp = p; } for( yyleng = 0, CMnext( yyp ), yyprev = ERx( "" ); *yyp != *p || *yyprev == '\\'; yyprev = ( *yyprev == EOS ) ? yyp : CMnext( yyprev ), CMnext( yyp ), ++yyleng ) { if( *yyp == *p && *yyprev == '\\' ) { /* remove escape character */ char *p1, *p2; for( p1 = p2 = yyprev, CMprev( p1, p ); p1 >= p; CMprev( p1, p ), CMprev( p2, p ) ) { CMcpychar( p1, p2 ); } --yyleng; CMnext( p ); } if( *yyp == EOS ) yyerror(); } CMnext( yyp ); if ( exec_str ) { if ( *yyp == '"' ) CMnext( yyp ); else { /* keep scanning to final '"' */ p = initstr; exec_str = 0; yyleng++; for( ; *yyp != *p || *yyprev == '\\'; yyprev = ( *yyprev == EOS ) ? yyp : CMnext( yyprev ), CMnext( yyp ), ++yyleng ) { if( *yyp == EOS ) yyerror(); } } } text = p; CMnext( text ); STlcopy( text, yytext, yyleng ); yytext[ yyleng ] = EOS; yylval.string = STalloc( yytext ); if( *p == '`' ) { if ( exec_str ) return( EXEC_TEXT_STR ); return( EXEC_TEXT ); } return( STR_CON ); } /* check for NUM_CON */ yyleng = 0; if( *yyp == '-' || CMdigit( yyp ) ) { f8 factor; char *p = yyp; if( *yyp == '-' ) { ++yyleng; factor = -1; CMnext( yyp ); } else factor = 1; if( !CMdigit( yyp ) ) CMprev( yyp, yybuf ); else { if( *yyp == '-' ) { CMnext( yyp ); } else factor = 1; while( CMdigit( yyp ) ) { ++yyleng; CMnext( yyp ); } if( *yyp == '.' ) { ++yyleng; CMnext( yyp ); if( !CMdigit( yyp ) ) yyerror(); while( CMdigit( yyp ) ) { ++yyleng; CMnext( yyp ); } } else if( *yyp == 'K' || *yyp == 'M' ) { ++yyleng; CMnext( yyp ); } STlcopy( p, yytext, yyleng ); yytext[ yyleng ] = EOS; if( yytext[ yyleng - 1 ] == 'K' ) { factor = 1024; yytext[ yyleng - 1 ] = EOS; } else if( yytext[ yyleng - 1 ] == 'M' ) { factor = 1048576; yytext[ yyleng - 1 ] = EOS; } CVaf( yytext, ERx( '.' ), &yylval.real ); yylval.real *= factor; return( NUM_CON ); } } if( STbcompare( yyp, 2, ERx( ">=" ), 2, FALSE ) == 0 ) { yylval.string = STalloc( ERx( ">=" ) ); CMnext( yyp ); CMnext( yyp ); return( COMPARE_OP ); } if( STbcompare( yyp, 2, ERx( "<=" ), 2, FALSE ) == 0 ) { yylval.string = STalloc( ERx( "<=" ) ); CMnext( yyp ); CMnext( yyp ); return( COMPARE_OP ); } /* check for COMPARE_OP */ if( STbcompare( yyp, 1, ERx( "<" ), 1, FALSE ) == 0 ) { yylval.string = STalloc( ERx( "<" ) ); CMnext( yyp ); return( COMPARE_OP ); } if( STbcompare( yyp, 1, ERx( ">" ), 1, FALSE ) == 0 ) { yylval.string = STalloc( ERx( ">" ) ); CMnext( yyp ); return( COMPARE_OP ); } if( STbcompare( yyp, 2, ERx( "==" ), 2, FALSE ) == 0 ) { yylval.string = STalloc( ERx( "==" ) ); CMnext( yyp ); CMnext( yyp ); return( COMPARE_OP ); } /* check for characters which get passed directly */ switch( *yyp ) { char *p; case '(': case ')': case '[': case ']': case '{': case '}': case ':': case ';': case ',': case '=': p = yyp; CMnext( yyp ); return( *p ); case '+': yylval.string = STalloc( ERx( "+" ) ); CMnext( yyp ); return( *yylval.string ); case '-': yylval.string = STalloc( ERx( "-" ) ); CMnext( yyp ); return( *yylval.string ); case '*': yylval.string = STalloc( ERx( "*" ) ); CMnext( yyp ); return( *yylval.string ); case '/': yylval.string = STalloc( ERx( "/" ) ); CMnext( yyp ); return( *yylval.string ); } /* check for LOGIC_OP */ if( STbcompare( yyp, 3, ERx( "&&" ), 3, FALSE ) == 0 ) { yylval.string = STalloc( ERx( "&&" ) ); CMnext( yyp ); CMnext( yyp ); return( LOGIC_OP ); } if( STbcompare( yyp, 3, ERx( "||" ), 3, FALSE ) == 0 ) { yylval.string = STalloc( ERx( "||" ) ); CMnext( yyp ); CMnext( yyp ); return( LOGIC_OP ); } /* anything else is an error */ yyerror(); }
/*{ ** Name: CK_subst - build a CK command from template and requirements ** ** Description: ** This function will search a CK command template file for ** a line meeting the requirements of the inputs and will substitute ** various esacpe sequences with other strings such as file names. ** ** Based on a II_subst of the 5.0 UNIX CL. ** ** Inputs: ** comlen length of cline space ** oper operation - one of 'B'egin, 'E'nd, 'W'ork ** dev device type - one of 'T'ape, 'D'isk ** dir direction - one of 'S'ave, 'R'estore ** type type (device type) 0 for disk, 1 for tape ** locnum location number (sequence or quantity) ** di_l_path length of di path string ** di_path di path string ** ckp_l_path length of checkpoint path string ** ckp_path checkpoint path string ** ckp_l_file length of checkpoint file string ** ckp_file checkpoint file string ** ** Outputs: ** cline space for generated command ** ** Returns: ** CK_FILENOTFOUND template file can't be found ** E_DB_OK ** ** Exceptions: ** none ** ** Side Effects: ** none ** ** History: ** 27-oct-88 (anton) ** Created. ** 16-may-90 (walt) ** Return CK_FILENOTFOUND if the template file (cktmpl.def) can't ** be opened. ** 23-may-1994 (bryanp) ** Modified Walt's 16-may-90 fix to use CK_TEMPLATE_MISSING, rather ** than CK_FILENOTFOUND, since CK_TEMPLATE_MISSING is a more ** specific, and therefore hopefully more useful, error message. ** 03-jan-1995 (dougb) ** Cross-integrate Unix change 415365: ** 02-dec-1994 (andyw) ** Check on granularity for partial backup */ STATUS CK_subst( char *cline, i4 comlen, char oper, char dev, char dir, u_i4 type, u_i4 locnum, u_i4 di_l_path, char *di_path, u_i4 ckp_l_path, char *ckp_path, u_i4 ckp_l_file, char *ckp_file) { STATUS ret_val = OK; auto LOCATION loc; auto char *s; auto FILE *fp; auto char *cp; char *command; command = MEreqmem(0, comlen, TRUE, &ret_val); if (!ret_val) { NMgtAt("II_CKTMPL_FILE", &s); if (s == NULL || *s == EOS) { ret_val = NMf_open("r", "cktmpl.def", &fp); } else { LOfroms( PATH & FILENAME, s, &loc ); ret_val = SIopen( &loc, "r", &fp); } if (ret_val) { ret_val = CK_TEMPLATE_MISSING; } } /* find command line - skip comments and blank lines */ if (!ret_val) { while ((ret_val = SIgetrec(command, comlen, fp)) == OK) { if (*command == '\n') { continue; } if (command[0] == oper && (command[1] == dir || command[1] == 'E') && (command[2] == dev || command[2] == 'E') && (command[3] == 'D' || command[3] == 'E') && command[4] == ':') { break; } } } _VOID_ SIclose(fp); if (!ret_val) { /* found the line - do the substitution */ s = command + 5; cp = cline; while (*s != '\n') { if (*s == '%') { switch (*++s) { case '%': *cp++ = '%'; break; case 'D': CK_lfill(&cp, di_l_path, di_path); break; case 'C': CK_lfill(&cp, ckp_l_path, ckp_path); break; case 'F': CK_lfill(&cp, ckp_l_file, ckp_file); break; case 'A': CK_lfill(&cp, ckp_l_path, ckp_path); # ifdef UNIX *cp++ = '/'; # endif CK_lfill(&cp, ckp_l_file, ckp_file); break; case 'T': *cp++ = type ? '1' : '0'; break; case 'N': CVna(locnum, cp); while (*cp) cp++; break; default: *cp++ = '%'; *cp++ = *s; } ++s; } else { *cp++ = *s++; } } *cp = EOS; } # ifdef xDEBUG TRdisplay("CK_subst %c %c %c: %s\n", oper, dir, dev, cline); # endif return(ret_val); }
static i4 ocfg_getrec( char *buf, i4 len ) { return SIgetrec( buf, (i4)len, stdin ); }
/*{ ** Name: xffileinput - get input files ** ** Description: ** This routine will make input from the command line, transparent ** from input from a file name. This will be done by reading ** the input file and building an argv,argc parameter from the ** file specification. ** ** ** Inputs: ** paramfile Name of the parameter file ** which is passed in ** to this routine. ** argv ptr to command line parameters ** which may point to a file name ** containing input specifications ** argc ptr to number of command line parameters ** ** Outputs: ** argv ptr to command line parameters ** which may have been created from ** an input file specification ** argc ptr to number of command line parameters ** ** Returns: ** OK : if successful. ** FAIL: if failed ** Exceptions: ** none ** ** Side Effects: ** none ** ** History: ** 31-oct-01 (gupsh01) ** Created.(Based on fileinput:opqutils.sc.) ** */ STATUS xffileinput( char *paramfile, char ***argv, i4 *argc) { FILE *inf; STATUS stat = FAIL; LOCATION inf_loc; /* create argv and argc to simulate a "long" command input line */ /* open the file containing the specifications */ inf = NULL; if ( ((stat =LOfroms(PATH & FILENAME, paramfile, &inf_loc)) != OK) || ((stat = SIopen(&inf_loc, "r", &inf)) != OK) || (inf == NULL) ) { /* report error dereferencing or opening file */ char buf[ER_MAX_LEN]; if ((ERreport(stat, buf)) != OK) buf[0] = '\0'; IIUGerr(E_XF0007_Cannot_open_param, UG_ERR_ERROR, 1, paramfile); return (FAIL); } { char buf[XF_MAXBUFLEN]; /* buffer used to read lines ** from the command file */ /* ptr to current parameter to be copied from temp buffer */ char **targv=(char **)NULL; i4 targc ;/* number of parameters ** which have been copied */ SIZE_TYPE len; /* size of dyn.mem. to be allocated. */ i4 argcount = XF_MAXARGLEN; /* get room for maxarglen args */ len = XF_MAXARGLEN * sizeof(char *); targv = (char **)NULL; targv = (char **)XF_REQMEM(len, FALSE); targc = 1; buf[XF_MAXBUFLEN-1]= 0; while ((stat = SIgetrec((PTR)&buf[0], (i4)(XF_MAXBUFLEN-1), inf)) == OK) { char *cp = &buf[0]; do { if (targc >= argcount) { i4 i; char **targv1 = NULL; /* Allocate another vector, ** twice the size of the prev. */ targv = (char **)XF_REQMEM((i4) (argcount * 2 * sizeof(char *)), FALSE); /* Copy previous into current. */ for (i = 0; i < argcount; i++) targv1[i] = targv[i]; targv = targv1; argcount += argcount; } { char *tp = (char *) NULL; i4 arglen = STlength(cp); tp = (char *)XF_REQMEM (arglen, FALSE); targv[targc++] = tp; { i4 len = STlength(cp); cp[len - 1] = EOS; STskipblank(cp,(len -1)); STtrmwhite(cp); STcopy(cp, tp); cp = &cp[len - 1]; } } } while (*cp); } if (stat != ENDFILE) { /* report error unable to read line from the file */ char buf[ER_MAX_LEN]; if ((ERreport(stat, buf)) != OK) buf[0] = '\0'; IIUGerr(E_XF0008_Cannot_read_param, UG_ERR_ERROR, 1, paramfile); return (FAIL); } *argv = targv; *argc = targc; } /* Close input file */ stat = SIclose(inf); if (stat != OK) { /* report error closing file */ char buf[ER_MAX_LEN]; if ((ERreport(stat, buf)) != OK) buf[0] = '\0'; IIUGerr(E_XF0025_Cannot_close_param, UG_ERR_ERROR, 1, paramfile); return (FAIL); } return OK; }
/*{ ** Name: maketable - compile a collation description ** ** Description: ** Read a collation description file and create a collation table. ** The table is a modified TRIE structure with a complete map ** at the top level and sparse maps below. ** ** Inputs: ** desfile collation description filename ** ** Outputs: ** none ** ** Returns: ** pointer to collation table on success ** NULL on failure ** ** Exceptions: ** none ** ** Side Effects: ** none ** ** History: ** 03-may-89 (anton) ** Created. ** 17-Jun-89 (anton) ** Moved to ADU from CL ** 17-Jul-89 (anton) ** replace 16 with COL_MULTI and use adulstrinit not aducolinit ** 21-jun-93 (geri) ** Added 2 bugfixes which were in the the 6.4 version: ** 31892: better syntax checking and sane delimiter ** handling; 31993: multiple character pattern match ** rules were not handled correctly. ** 1-oct-04 (toumi01) ** On file-not-found error, make that clear rather than just issuing ** a bogus and misleading syntax error message. ** 1-May-2008 (kibro01) b120307 ** When we find a "+", just check the next character isn't also a "+", ** since it ought to be possible to set the collation relative to "+" ** by having a line "++1:<". */ static ADULTABLE * maketable( char *desfile) { FILE *fp; i4 n; char buf[MAX_LOC]; u_char *s; register i4 lno = 0; register i4 errcnt = 0; i2 *sp, v, t, tt; struct ADUL_tstate *ts; LOCATION loc; ADULcstate cs; STcopy(desfile, buf); LOfroms(FILENAME, buf, &loc); if (SIopen(&loc, "r", &fp) != OK) { SIprintf("aducompile: Unable to open input file \"%s\".\n", loc.string ); return NULL; } w.tab.magic = ADUL_MAGIC; w.tab.nstate = 0; for (n = 0; n < 256; n++) w.tab.firstchar[n] = n * COL_MULTI; while (SIgetrec(buf, sizeof buf, fp) != ENDFILE) { lno++; if (*buf == ':') { /* line is a comment */ continue; } adulstrinit(&w.tab, (u_char*)buf, &cs); v = 0; sp = NULL; while ((t = *(s = adulptr(&cs))) != ':') { /* If this is '+', just confirm that the next character isn't, ** since the construction "++1:<" would be fine, setting < as the ** character 1 place beyond + (kibro01) b120307 */ if (t == '+' && (*(s+1) != '+')) { if (*++s == '*') { v = ADUL_SKVAL; while (*++s != ':' && *s != '\n') continue; if (*s == '\n') { /* syntax error: report line and line number */ SIprintf("Syntax error on line %d: %s", lno, buf); errcnt++; s = NULL; } break; } tt = 0; while ((t = *s - '0') <= 9 && t >= 0) { tt = tt * 10 + t; s++; } adulstrinit(&w.tab, s, &cs); if (sp == NULL) sp = &v; *sp += tt; continue; } if (t == '\n') { /* syntax error - line has no ':' */ SIprintf("Syntax error on line %d: %s", lno, buf); errcnt++; s = NULL; break; } t = adultrans(&cs); adulnext(&cs); if (sp == NULL) { v = t; sp = &v; } else { ts = &w.tab.statetab[w.tab.nstate]; ts->match = *sp; ts->flags = ADUL_LMULT; *sp = w.tab.nstate++ | ADUL_TMULT; ts->nomatch = t; sp = &ts->nomatch; } } if (s == NULL) { /* syntax error occurred */ continue; /* to the next line */ } sp = &w.tab.firstchar[255 & *++s]; ts = NULL; if (*s == '\n') { SIprintf("Syntax error on line %d (no substitution string): %s", lno, buf); continue; } while (*++s != '\n') { while (*sp & ADUL_TMULT) { ts = &w.tab.statetab[*sp & ADUL_TDATA]; if (ts->testchr == *s) { sp = &ts->match; if (*++s == '\n') { goto done; } } else { sp = &ts->nomatch; } } ts = &w.tab.statetab[w.tab.nstate]; ts->match = ts->nomatch = *sp; *sp = ADUL_TMULT | w.tab.nstate++; sp = &ts->match; ts->testchr = *s; ts->flags = ADUL_FINAL; } done: if (ts) ts->flags ^= ADUL_FINAL; *sp = v; } if (errcnt == 0) return &w.tab; return NULL; }