/*{ ** Name: main - print the LG/LK shared memory key ** ** Description: ** Used by build and install tools to clean up the LG/LK shared memory. ** ** Inputs: ** None ** ** Outputs: ** ** Returns: ** OK - success ** !OK - failure (CS*() routine failure, segment not mapped, ...) ** ** History: ** 21-nov-1992 (bryanp) ** Created to solve LG/LK memory cleanup problems. ** 15-may-1995 (thoro01) ** Added NO_OPTIM hp8_us5 to file. ** 10-may-1999 (walro03) ** Remove obsolete version string sqs_u42. ** 28-sep-2002 (devjo01) ** Add CXget_context, so NUMA cluster context can be established. */ int main(int argc, char *argv[]) { key_t key; #if defined(conf_BUILD_ARCH_32_64) && defined(BUILD_ARCH32) { char *lp64enabled; /* ** Try to exec the 64-bit version */ NMgtAt("II_LP64_ENABLED", &lp64enabled); if ( (lp64enabled && *lp64enabled) && ( !(STbcompare(lp64enabled, 0, "ON", 0, TRUE)) || !(STbcompare(lp64enabled, 0, "TRUE", 0, TRUE)))) { PCexeclp64(argc, argv); } } #endif /* hybrid */ if ( OK != CXget_context( &argc, argv, CX_NSC_STD_NUMA, NULL, 0 ) ) PCexit(FAIL); if ((key = ME_getkey("lglkdata.mem")) != (key_t)-1) SIprintf("0x%x\n", (i4)key); PCexit(OK); }
static i4 yylex( FILE *input ) { char *pscan; if( yygetline( input ) != OK ) return( tEOF ); /* Unless the -C flag was specified, blank out all of the comments */ pscan = infile->yytext; while (pass_comments == FALSE && *pscan != EOS) { if (infile->yycomment == TRUE) { /* Look for the 'end comment' identifier */ if (STbcompare(pscan,2,ERx("*/"),2,FALSE) == 0) { /* Blank out the 'end comment' characters */ CMcpychar(ERx(" "), pscan); CMnext(pscan); CMcpychar(ERx(" "), pscan); /* Remember that the comment has ended */ infile->yycomment = FALSE; } /* Blank out non-whitespace characters of the comment */ else if (!CMwhite(pscan)) { CMcpychar(ERx(" "), pscan); } /* Whitespace chars are skipped, this lets \n thru */ } /* Look for the 'begin comment' identifier */ else if (STbcompare(pscan,2,ERx("/*"),2,FALSE) == 0) { /* Blank out the 'begin comment' characters */ CMcpychar(ERx(" "), pscan); CMnext(pscan); CMcpychar(ERx(" "), pscan); infile->yycomment = TRUE; } CMnext(pscan); /* Continue the scan with the next character */ } if( is_history(infile->yytext ) == OK) { return( tHISTORY ); } if( *infile->yytext == '#' ) return( tDIRECTIVE ); return( tSOURCE ); }
static i4 ns_keyword( char *token, KEYWORD_TBL *tbl ) { i4 keyword = INVALID_KEYWORD; for( ; tbl->full != NULL; tbl++ ) if ( ! STbcompare( token, 0, tbl->abbr, STlength(tbl->abbr), TRUE ) && STlength( token ) <= STlength( tbl->full ) && ! STbcompare( token, STlength( token ), tbl->full, 0, TRUE ) ) { keyword = tbl->code; break; } return( keyword ); }
static uchar lookup(char *opname) { i4 opn; uchar rtn = opNONE; /* ** If there's an "=<value>" following the flag, point argval at the value, ** and then replace the "=" with an EOS... */ if (NULL != (argval = STindex(opname, ERx("="), 0))) { *argval = EOS; CMnext(argval); if (*argval == EOS) return opNONE; } /* Look up the flag in the table... */ for (opn = 0; opn < NUM_OPT; opn++) { if (!STbcompare(opname,99,option[opn].op_text,99,FALSE)) { if (rtn == opNONE) /* First candidate we've found? */ rtn = option[opn].op_id; else return opNONE; /* Not unique, apparently. */ } } return rtn; }
static i4 line_get( char *prompt, char *def_line, i4 wild_flag, char *in_line ) { char line[MAXLINE]; char ret = '\n'; char *p; i4 status = EOF; for(;;) { STATUS s; SIprintf(prompt); SIprintf( *def_line ? "(%s): " : ": ", def_line ); /* This is somewhat unusuall but does force the SIflush to work */ SIflush(stdout); s = ocfg_getrec( line, (i4)MAXLINE ); if( s != OK || line[0] == '\033' ) break; if (p = STindex(line, &ret, MAXLINE)) *p = EOS; if( *def_line && !*line ) { STcopy( def_line, in_line ); SIprintf("\t\tDefault value: %s\n",in_line); } else { STcopy(line,in_line); } STzapblank(in_line,in_line); if( !*in_line ) { SIprintf("\t\tValue required, enter <ESC> to exit.\n"); continue; } if(!STbcompare( in_line, 0, "*",0, TRUE ) ) { if( !wild_flag ) { SIprintf("\t\tValue required, enter <ESC> to exit.\n"); continue; } in_line[0] = EOS; } status = OK; break; /* There is valid data */ } /* end of FOR loop */ return status; }
/* ** tcp6_set_version - sets version for TCP. ** ** Check to see if driver being restricted to IPv4 or IPv6 only. ** Default is both IPv4(AF_INET) + IPv6(AF_INET6) ** ** VERSION -> meaning . . . ** ALL or unspecified -> (default) Use both IPv4 and IPv6 addresses ** with new (IPv6-enabled) driver ** 4 -> Use old IPv4-only driver (ie, back off to old driver) ** 46 -> Use only IPv4 addresses with new (IPv6-enabled) driver ** 6 -> Use only IPv6 addresses with new (IPv6-enabled) driver ** */ static int tcp6_set_version() { char *p; if( tcpip_version == -1 ) /* Only do 1st time in for performance */ { TCP_TRACE(2)("tcp6_set_version: entered first time\n"); tcpip_version = 0; NMgtAt( "II_TCPIP_VERSION", &p ); if ( !(p && *p) && PMget("!.tcp_ip.version", &p) != OK ) ip_family = AF_UNSPEC; else if (STbcompare(p, 0, "ALL", 0, TRUE) == 0) ip_family = AF_UNSPEC; else { tcpip_version = atoi(p); /* 4*=IPv4 or 6=IPv6 */ if ((tcpip_version == 4) || (tcpip_version == 46)) ip_family = AF_INET; else if (tcpip_version == 6) ip_family = AF_INET6; else { TCP_TRACE(2)("tcp6_set_version: failed! II_TCPIP_VERSION=%s\n", p); return(FAIL); } } TCP_TRACE(2)("tcp6_set_version: exiting version=%d, family=%d\n", tcpip_version, ip_family); } /* end if first time */ return(OK); }
static bool gcd_cset_id( char *name, u_i4 id ) { if ( ! STbcompare( name, 0, GCD_global.charset, 0, TRUE ) ) { GCD_global.charset_id = id; return( FALSE ); } return( TRUE ); }
/* ** Name: Disp_Form ** ** Decription: ** Disposition: form-data; recevied with no filename. Implies a page ** variable name. ** Extract the variable and store it in the upload structure for use ** later. ** ** Inputs: ** sess ice session structure ** line pointer to the current line ** linelen length of the line ** ** Outputs: ** pos number of characters handled. ** ** Return: ** GSTAT_OK success ** other failure ** ** History: ** 23-Oct-98 (fanra01) ** Created. */ static GSTATUS Disp_Form (WTS_SESSION* sess, char* line, i4 linelen, i4 * pos) { GSTATUS err = GSTAT_OK; PWTS_UPLOAD load= sess->load; char* p = line + *pos; char* varname; i4 remain = linelen - *pos; i4 i = 0; i4 j = 0; if (STbcompare ("name", 4, p, 0, TRUE) == 0) { /* ** Find the first quote after name */ while ((*p != '\"') && (i < remain)) { CMbyteinc(i,p); CMnext(p); } CMbyteinc(i,p); /* skip the quote */ CMnext(p); varname= p; while ((*p != '\"') && (i < remain)) { j+=CMbytecnt(p); CMbyteinc(i,p); CMnext(p); } CMbyteinc(i,p); /* skip the quote */ CMnext(p); /* ** Allocate space for the variable name a '=' character and an EOS */ if ((err = GAlloc (&load->varname, j+2, FALSE)) == GSTAT_OK) { MEfill (j+2, 0, load->varname); MECOPY_VAR_MACRO (varname, j, load->varname); STcat (load->varname, "="); } *pos += i; load->state = US_VAL; } else { HandlerException (sess, line, linelen, pos); } return (err); }
char *FIND_SEPstring(char *token,char *string) { i4 token_len ; i4 string_len ; char *cp = NULL ; char *pp = NULL ; char *tp = NULL ; if (token == NULL || *token == EOS) { if (tracing&TRACE_PARM) SIfprintf(traceptr,ERx("FIND_SEPstring> token is null\n")); return (NULL); } if (string == NULL || *string == EOS) { if (tracing&TRACE_PARM) SIfprintf(traceptr,ERx("FIND_SEPstring> string is null\n")); return (NULL); } string_len = STlength(string); if ((token_len = STlength(token)) < string_len) { if (tracing&TRACE_PARM) SIfprintf(traceptr ,ERx("FIND_SEPstring> token <%s> is too small (%d chars)\n") ,token,token_len); return (NULL); } for (tp = token, cp = NULL, pp = NULL ; (*tp != EOS)&&(cp == NULL)&&(token_len-- >= string_len) ; CMnext(tp)) { if ((STbcompare(tp, string_len, string, string_len, TRUE) == 0) &&((pp == NULL)||CMoper(pp)||CMwhite(pp))) { cp = tp; } pp = tp; } return (cp); }
static STATUS is_history(char *text) { SYMBOL *symptr; i4 len = STlength( text ); /* Try and locate the symbol in the list */ for (symptr = symtab.head; symptr != NULL; symptr = symptr->next ) { if( STbcompare(text, len, symptr->name, 0, FALSE ) == 0 && symptr->hist_flag == TRUE ) return( OK ); } return( FAIL ); }
/* ** Name: scs_gwinfo_subget ** ** Description: ** grab the value part of the gw string of the form ** ** var1=value2,var2='value2',var3='value3',var4=value4 ** ** the input substr is of the form "varN=". We strip out any quotes ** and copy the value to the user buffer. ** ** if there are more than one entry for a var, then take ** the first one. ** ** Inputs: ** substr substring of the variable name ** scb scb with the gw_parm string to scan. ** lbuf length of output buffer ** ** Outputs: ** buf buffer to put extracted value string, less quotes. ** if substr not found, set to empty string. ** ** Returns: ** OK if got string OK, or no string found. ** MO_VALUE_TRUNCATED if value got truncated to lbuf. ** ** History: ** 22-Apr-1994 (daveb) ** documented, changed to "first wins" */ STATUS ascs_gwinfo_subget( char *substr, SCD_SCB *scb, i4 lbuf, char *buf ) { STATUS cl_stat = OK; i4 sublen; i4 outlen; i4 inquote = FALSE; char *str; char *loc; *buf = EOS; if( (str = scb->scb_sscb.sscb_ics.ics_gw_parms) != NULL ) { sublen = STlength( substr ); /* for each potential match, check for full match */ for( ; *str && (loc = STindex( str, substr, 0 )) != NULL ; str++ ) { /* if this is the substring, get the good stuff. */ if( !STbcompare( loc, 0, substr, sublen, FALSE ) ) { loc += sublen; if( *loc == '\'' ) { loc++; inquote = TRUE; } str = loc; while( *loc && (inquote && *loc != '\'') || (!inquote && *loc != ',')) loc++; outlen = loc - str; if( outlen > (lbuf - 1) ) { outlen = lbuf - 1; cl_stat = MO_VALUE_TRUNCATED; } STlcopy( str, buf, outlen ); break; } } } return( cl_stat ); }
static bool proc_install(char *featname, bool only) { PKGBLK *pkg; SCAN_LIST(distPkgList,pkg) { if (!STbcompare(featname, 0, pkg->feature, 0, TRUE)) { pkg->selected = SELECTED; return TRUE; } } IIUGerr(E_ST017A_bad_featname, 0, 1, featname); return FALSE; }
static bool proc_version(char *featname, bool only) { PKGBLK *pkg; SCAN_LIST(instPkgList,pkg) { if (!STbcompare(featname, 0, pkg->feature, 0, TRUE)) { if (!only) /* Don't identify the package if there's only one. */ SIfprintf(batchOutf, ERx("%s "), pkg->feature); SIfprintf(batchOutf, ERx("%s\n"), pkg->version); return TRUE; } } IIUGerr(E_ST017B_not_present, 0, 1, featname); return FALSE; }
/* ** Name: gwsxa_find_attbyname - Returns the attribute id ** for an attribute name. ** ** Description: ** This searches the list of known attributes checking for the ** one required. The list is small, and the search is only rarely ** done (when REGISTER currently) so we do a linear search of the ** table ** ** Returns: ** SXA_ATT_INVALID if none, otherwise the id ** ** History: ** 14-sep-92 (robf) ** Created ** 13-dec-94 (forky01) ** Fix bug #65975 - Use STbcompare instead of STcompare to allow ** case insensitive check on column names used in security audit ** log file. */ SXA_ATT_ID gwsxa_find_attbyname(char *attname) { i4 i; for( i=0; attlist[i].attid!=SXA_ATT_INVALID; i++) { /* ** Case insensitive compare to allow FIPS mode to work */ if ( STbcompare((char *)attlist[i].attname,0,attname, 0,TRUE)==0 ) { /* ** Found so stop looking */ break; } } return attlist[i].attid; }
/* ** Name: GetNSroot ** ** Description: ** Display the home HTML directory for NS ** ** Inputs: ** conf pointer to the NS config structure. ** regkey generated registry key. ** ** Outputs: ** docpath contains the HTML root path ** ** Returns: ** none ** ** History: ** 09-Oct-98 (fanra01) ** Created. ** 20-Nov-1998 (fanra01) ** Add docpath. */ STATUS GetNSroot (PW3CONF conf, char* mc, char** docpath) { STATUS status = FAIL; PW3CONF p = conf+1; char reg[256]; i4 i; errflg = FALSE; for (i=0; (STbcompare (p->id, 2, "NS", 2, TRUE) == 0) && (status == FAIL); i+=1, p+=1) { STprintf (reg, p->reg, mc); status = p->gethtml (p, reg, docpath); } if (status != OK) { SIprintf ("Error : No Netscape servers found\n"); } return (status); }
main( i4 argc, char **argv ) { bool usage = FALSE; STACK_FRAME stack_frame; char *filename = NULL; char buf[ MAX_LOC + 1]; i4 i; stack_frame.prev = NULL; stack_frame.display_mode = TRUE; /* Initialize the Include directory list, make sure the resulting */ /* path is not NULL by calling LOfaddpath with an empty path string */ ihead.next = NULL; ihead.pathloc = &defdir; STcopy(ERx(""), buf); LOfroms(PATH, buf, ihead.pathloc); /* Clear the default path */ /* Process the command line */ for( i = 1; i < argc; i++ ) { char *p; char *v; /* process -C options */ if( STbcompare( argv[ i ], 0, ERx( "-C" ), 0, TRUE ) == 0) { pass_comments = TRUE; continue; } /* process -D options */ if( STbcompare( argv[ i ], 2, ERx( "-D" ), 2, TRUE ) == 0 && STlength( argv[ i ] ) > 2 ) { p = argv[ i ]; CMnext( p ); CMnext( p ); /* Check for a value specified, -Dsymbol=value */ if (NULL == (v = STindex(p, ERx("="), STlength(p)) ) ) v = ERx(""); else CMnext(v); define( p, v, FALSE ); continue; } /* process -H option */ if( STbcompare( argv[ i ], 2, ERx( "-H" ), 2, TRUE ) == 0 && STlength( argv[ i ] ) > 2 ) { p = argv[ i ]; CMnext( p ); CMnext( p ); define( p, ERx(""), TRUE ); continue; } /* process -I option */ if( STbcompare( argv[ i ], 2, ERx( "-I" ), 2, TRUE ) == 0 && STlength( argv[ i ] ) > 2 ) { p = argv[ i ]; CMnext( p ); CMnext( p ); yyadd_path( p ); continue; } if( *argv[ i ] != '-' ) { /* file name must be final argument */ if( i != argc - 1 ) { usage = TRUE; break; } filename = argv[ i ]; } else usage = TRUE; break; } if( usage ) { SIfprintf( stderr, E_YAPP000 ); PCexit( FAIL ); } pp_file( &stack_frame, filename, TRUE ); PCexit( 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; }
static STATUS initialize( i4 argc, char **argv ) { CL_ERR_DESC cl_err; char *instance = ERx("*"); char *env; char name[ 16 ]; i4 i; GCD_global.language = 1; MHsrand( TMsecs() ); for( i = 1; i < argc; i++ ) if ( ! STbcompare( argv[i], 0, ERx("-instance"), 9, TRUE ) ) { if ( argv[i][9] == ERx('=') && argv[i][10] != EOS ) instance = &argv[i][10]; else if ( argv[i][9] == EOS && (i + 1) < argc ) instance = argv[++i]; break; } NMgtAt( ERx("II_INSTALLATION"), &env ); STprintf( name, ERx("II_CHARSET%s"), (env && *env) ? env : "" ); NMgtAt( name, &env ); if ( ! env || ! *env || STlength(env) > CM_MAXATTRNAME) { switch( CMgetDefCS() ) { #if ( !defined(UNIX) && !defined(VMS) ) case CM_IBM : env = "IBMPC850"; break; #endif case CM_DECMULTI : env = "DECMULTI"; break; default : env = "ISO88591"; break; } } GCD_global.charset = STalloc( env ); CVupper( GCD_global.charset ); gcu_read_cset( gcd_cset_id ); if ( CMset_attr( GCD_global.charset, &cl_err) != OK ) { gcu_erlog( 0, GCD_global.language, E_GC0105_GCN_CHAR_INIT, NULL, 0, NULL ); return( E_GC0105_GCN_CHAR_INIT ); } PMinit(); switch( PMload( (LOCATION *)NULL, (PM_ERR_FUNC *)NULL ) ) { case OK: break; case PM_FILE_BAD: gcu_erlog( 0, GCD_global.language, E_GC003D_BAD_PMFILE, NULL, 0, NULL ); return( E_GC003D_BAD_PMFILE ); break; default: gcu_erlog( 0, GCD_global.language, E_GC003E_PMLOAD_ERR, NULL, 0, NULL ); return( E_GC003E_PMLOAD_ERR ); break; } PMsetDefault( 0, SystemCfgPrefix ); PMsetDefault( 1, PMhost() ); PMsetDefault( 2, ERx("gcd") ); PMsetDefault( 3, instance ); gcd_tl_services[0] = &gcd_dmtl_service; gcd_tl_services[1] = &gcd_jctl_service; GCD_global.tl_services = gcd_tl_services; GCD_global.tl_srvc_cnt = ARR_SIZE( gcd_tl_services ); QUinit( &GCD_global.pib_q ); QUinit( &GCD_global.rcb_q ); QUinit( &GCD_global.ccb_q ); QUinit( &GCD_global.ccb_free ); for( i = 0; i < ARR_SIZE( GCD_global.cib_free ); i++ ) QUinit( &GCD_global.cib_free[ i ] ); env = NULL; gcu_get_tracesym( NULL, ERx("!.client_max"), &env ); if ( env && *env ) { i4 count; if ( CVal( env, &count ) == OK && count > 0 ) GCD_global.client_max = count; } env = NULL; gcu_get_tracesym( NULL, ERx("!.client_timeout"), &env ); if ( env && *env ) { i4 timeout; if ( CVal( env, &timeout ) == OK && timeout > 0 ) GCD_global.client_idle_limit = timeout * 60; /* Cnvt to seconds */ } env = NULL; gcu_get_tracesym( NULL, ERx("!.connect_pool_status"), &env ); if ( env && *env ) { if ( ! STbcompare( env, 0, "optional", 0, TRUE ) ) GCD_global.client_pooling = TRUE; if ( GCD_global.client_pooling || ! STbcompare( env, 0, "on", 0, TRUE ) ) { env = NULL; gcu_get_tracesym( NULL, ERx("!.connect_pool_size"), &env ); if ( env && *env ) CVal( env, &GCD_global.pool_max ); env = NULL; gcu_get_tracesym( NULL, ERx("!.connect_pool_expire"), &env ); if ( env && *env ) { i4 limit; if ( CVal( env, &limit ) == OK && limit > 0 ) GCD_global.pool_idle_limit = limit * 60; /* Seconds */ } } } env = NULL; gcu_get_tracesym( "II_GCD_TRACE", ERx("!.gcd_trace_level"), &env ); if ( env && *env ) CVal( env, &GCD_global.gcd_trace_level ); env = NULL; gcu_get_tracesym( "II_GCD_LOG", ERx("!.gcd_trace_log"), &env ); if ( env && *env ) TRset_file( TR_F_OPEN, env, (i4)STlength( env ), &cl_err ); return( OK ); }
static bool checkArgs (char *arg, i4 argc, char **argv, char *altPath, char * drvMgr) { i4 i; for ( i = 1; i < argc; i++ ) { if ( !STbcompare( arg, 0, argv[i], 0, TRUE ) && !STbcompare( arg, 0, "-p", 0, TRUE ) && i < (argc - 1) ) { i++; STcopy( argv[i], altPath ); return TRUE; } if ( !STbcompare( arg, 0, argv[i], 0, TRUE ) && !STbcompare( arg, 0, "-m", 0, TRUE ) && i < (argc - 1) ) { i++; if ( !STbcompare( MGR_STR_UNIX_ODBC, 0, argv[i], 0, TRUE ) ) { STcopy( argv[i], drvMgr ); return TRUE; } else if ( !STbcompare( MGR_STR_CAI_PT, 0, argv[i], 0, TRUE ) ) { STcopy( argv[i], drvMgr ); return TRUE; } else { display_help(); PCexit(FAIL); } } if ( !STbcompare( arg, 0, argv[i], 0, TRUE ) && !STbcompare ( arg, 0, "-r", 0, TRUE ) ) return TRUE; if ( !STbcompare( arg, 0, argv[i], 0, TRUE ) && !STbcompare ( arg, 0, "-rmpkg", 0, TRUE ) ) return TRUE; if ( !STbcompare( arg, 0, argv[i], 0, TRUE ) && !STbcompare ( arg, 0, "-batch", 0, TRUE ) ) return TRUE; if ( !STbcompare( arg, 0, argv[i], 0, TRUE ) && !STbcompare ( arg, 0, "-h", 0, TRUE ) ) return TRUE; if ( !STbcompare( arg, 0, argv[i], 0, TRUE ) && !STbcompare ( arg, 0, "-help", 0, TRUE ) ) return TRUE; } return FALSE; }
/* Name: adu_map_check_validity - checks the validity of a byte sequence against ** the validity table. ** Description: ** This routines, checks a byte value against the validity table to identify ** if the byte value is valid for this code page. Validity data is present ** in form of a statetable in the Mapping files. ** ** Input: ** validitytable pointer to validity table. ** bval pointer to byte values. ** Output: ** E_DB_OK byte is valid ** ** E_DB_ERROR byte is invalid ** ** FIXME: ** There are several states which can be identified ** from the byte sequence, ie, whether it is ** unassigned, incomplete, ambiguous or illegal. ** Fix this routine to return appropriate error for ** each case. ** ** History: ** 23-Jan-2004 (gupsh01) ** Added. ** 04-Feb-2004 (gupsh01) ** Modified strcmp to STbcompare. ** 16-Apr-2004 (loera01) Bug 112162 ** In adu_deletemap, removed redundant MEfree of ** Adf_globs->Adu_maptbl. ** 16-Mar-2005 (fanra01) ** Ensure that the scan through the array inbyte is limited to the bounds ** of the array. */ DB_STATUS adu_map_check_validity( ADU_MAP_STATETABLE *validitytable, u_i4 *bval) { int i = 0; u_i2 inbyte[MAXBYTES]; ADU_MAP_VLDSTATE **currstate; ADU_MAP_VLDSTATE **nextstate; u_i2 property = 0; u_i2 current_byte; ADU_MAP_STATETABLE *ptr; if ((validitytable == NULL) || (bval == NULL)) return (E_DB_ERROR); /* search validity table for first state */ for (ptr=validitytable; ptr != NULL; ptr = ptr->next) { if (STbcompare (ptr->name, 0, "FIRST", 0, 1) == 0) break; } inbyte[0] = (*bval & 0xFFFFFF) >> 16; inbyte[1] = (*bval & 0xFFFF) >> 8; inbyte[2] = (*bval & 0xFF); current_byte = inbyte[i++]; if (!(validitytable && ptr)) { /* ERROR No validity table found */ return (E_DB_ERROR); } else { /* Get to a non zero leading byte */ while ((current_byte == 0) && (i < MAXBYTES)) current_byte = inbyte[i++]; currstate = ptr->state_table; property = ST_UNASSIGNED; nextstate = NULL; if (currstate[current_byte]) { property = currstate[current_byte]->property; // initialize property nextstate = currstate[current_byte]->next; //initialize next state while(nextstate && i<MAXBYTES) { current_byte = inbyte[i++]; currstate = nextstate; if (currstate[current_byte]) { nextstate = currstate[current_byte]->next; property = currstate[current_byte]->property; } else { property = ST_UNASSIGNED; nextstate = NULL; break; } } } if (property & ST_VALID) return (E_DB_OK); else return (E_DB_ERROR); } }
/*{ ** Name: RSstats_init - initialize monitor statistics ** ** Description: ** Initializes the Replicator Server statistics memory segment. ** ** Inputs: ** none ** ** Outputs: ** none ** ** Returns: ** OK Function completed normally. */ STATUS RSstats_init() { STATUS status; char *val; i4 num_targs; SIZE_TYPE pages_alloc; u_i4 stats_size; RS_TARGET_STATS *targ; RS_TARGET_STATS *targ_end; RS_TABLE_STATS *tbl; RS_CONN *conn; RS_TBLDESC *tbl_info; CL_SYS_ERR sys_err; char server_num[4]; PMsetDefault(1, PMhost()); STprintf(server_num, ERx("%d"), (i4)RSserver_no); PMsetDefault(3, server_num); status = PMget(ERx("II.$.REPSERV.$.SHARED_STATISTICS"), &val); if (status == OK && STbcompare(val, 0, ERx("ON"), 0, TRUE) == 0) shared_stats = TRUE; num_targs = RSnum_conns - TARG_BASE; stats_size = sizeof(RS_MONITOR) + sizeof(RS_MONITOR) % sizeof(ALIGN_RESTRICT); targ_size = sizeof(RS_TARGET_STATS) + sizeof(RS_TARGET_STATS) % sizeof(ALIGN_RESTRICT); if (shared_stats) tbl_size = sizeof(RS_TABLE_STATS) + sizeof(RS_TABLE_STATS) % sizeof(ALIGN_RESTRICT); else tbl_size = 0; num_pages = (stats_size + num_targs * (targ_size + RSrdf_svcb.num_tbls * tbl_size)) / ME_MPAGESIZE + 1; if (shared_stats) { STprintf(sm_key, ERx("%s.%03d"), RS_STATS_FILE, RSserver_no); status = MEget_pages(ME_SSHARED_MASK | ME_CREATE_MASK | ME_MZERO_MASK | ME_NOTPERM_MASK, num_pages, sm_key, (PTR *)&mon_stats, &pages_alloc, &sys_err); if (status == ME_ALREADY_EXISTS) { status = MEsmdestroy(sm_key, &sys_err); if (status == OK) status = MEget_pages(ME_SSHARED_MASK | ME_CREATE_MASK | ME_MZERO_MASK | ME_NOTPERM_MASK, num_pages, sm_key, (PTR *)&mon_stats, &pages_alloc, &sys_err); } } else { mon_stats = (RS_MONITOR *)MEreqmem(0, num_pages * ME_MPAGESIZE, TRUE, &status); } if (status != OK) return (status); mon_stats->server_no = RSserver_no; mon_stats->local_db_no = RSlocal_conn.db_no; PCpid(&mon_stats->pid); mon_stats->startup_time = TMsecs(); mon_stats->num_targets = num_targs; mon_stats->num_tables = RSrdf_svcb.num_tbls; STcopy(RSlocal_conn.vnode_name, mon_stats->vnode_name); STcopy(RSlocal_conn.db_name, mon_stats->db_name); mon_stats->target_stats = (RS_TARGET_STATS *)((PTR)mon_stats + stats_size); targ_end = (RS_TARGET_STATS *)((PTR)mon_stats->target_stats + mon_stats->num_targets * (targ_size + tbl_size * mon_stats->num_tables)); for (conn = &RSconns[TARG_BASE], targ = mon_stats->target_stats; targ < targ_end; ++conn, targ = (RS_TARGET_STATS *)((PTR)targ + targ_size + tbl_size * mon_stats->num_tables)) { targ->db_no = conn->db_no; STcopy(conn->vnode_name, targ->vnode_name); STcopy(conn->db_name, targ->db_name); if (shared_stats) { targ->table_stats = (RS_TABLE_STATS *)((PTR)targ + targ_size); for (tbl_info = RSrdf_svcb.tbl_info, tbl = targ->table_stats; tbl < targ->table_stats + mon_stats->num_tables; ++tbl, ++tbl_info) { tbl->table_no = tbl_info->table_no; STcopy(tbl_info->table_owner, tbl->table_owner); STcopy(tbl_info->table_name, tbl->table_name); } } } return (OK); }
/* ** Name: sxapo_init_cnf - Initialize SXAPO configuration from the PM file. ** ** Description: ** This routine initializes the SXAPO configuration from the ** PM configuration file. ** ** Inputs: ** None. ** ** Outputs: ** err_code Error code returned to caller. ** ** Returns: ** DB_STATUS ** ** History: ** 6-jan-94 (stephenb) ** Initial creation. */ static DB_STATUS sxapo_init_cnf( i4 *err_code) { DB_STATUS status = E_DB_OK; STATUS clstat; i4 local_err; char *pmfile; char *pmvalue; *err_code = E_SX0000_OK; for (;;) { /* ** Allow private override on PM file */ NMgtAt("II_SXF_PMFILE", &pmfile); if (pmfile && *pmfile) { LOCATION pmloc; TRdisplay("Loading SXF-PM file '%s'\n",pmfile); LOfroms(PATH & FILENAME, pmfile, &pmloc); if(PMload(&pmloc,NULL)!=OK) TRdisplay("Error loading PMfile '%s'\n",pmfile); } /* ** Get auditing status */ if (PMget(SX_C2_MODE,&pmvalue) == OK) { if (!STbcompare(pmvalue, 0, SX_C2_MODE_ON, 0, TRUE)) { /* ** Auditing on */ Sxapo_cb->sxapo_status=SXAPO_ACTIVE; } else if ((STbcompare(pmvalue, 0, SX_C2_MODE_OFF, 0, TRUE)!=0)) { /* ** Niether ON nor OFF, Invalid mode */ *err_code=E_SX1061_SXAP_BAD_MODE; break; } } else { /* ** No value, this is an error */ *err_code=E_SX1061_SXAP_BAD_MODE; break; } /* ** Get action on error */ if ((PMget("II.*.C2.ON_ERROR",&pmvalue) == OK)) { if (!STcasecmp(pmvalue, "STOPAUDIT" )) { Sxf_svcb->sxf_act_on_err=SXF_ERR_STOPAUDIT; } else if (!STcasecmp(pmvalue, "SHUTDOWN" )) { Sxf_svcb->sxf_act_on_err=SXF_ERR_SHUTDOWN; } else { /* ** Invalid value */ *err_code=E_SX1060_SXAP_BAD_ONERROR; break; } } else { /* ** No value, this is an error */ *err_code=E_SX1060_SXAP_BAD_ONERROR; break; } break; } /* handle errors */ if (*err_code != E_SX0000_OK) { _VOID_ ule_format(*err_code, NULL, ULE_LOG, NULL, NULL, 0L, NULL, &local_err, 0); *err_code = E_SX1020_SXAP_INIT_CNF; status = E_DB_ERROR; } return (status); }
DB_STATUS adi_tyid( ADF_CB *adf_scb, ADI_DT_NAME *adi_dname, DB_DT_ID *adi_did) { i4 s; i4 n; i4 i; i4 cmp; char *c1; char *c2; ADI_DT_NAME dt_name; bool dategiven = FALSE; s = sizeof(adi_dname->adi_dtname); c2 = &adi_dname->adi_dtname[0]; if (c2 && ((*c2 == 'd') || (*c2 == 'D'))) { if (STbcompare (c2, 0, "date", 0, TRUE) == 0) { dategiven = TRUE; if (adf_scb->adf_date_type_alias & AD_DATE_TYPE_ALIAS_INGRES) { /* replace the input string with ingresdate */ MEmove(10, (PTR)"ingresdate", '\0', sizeof(ADI_DT_NAME), (PTR)&dt_name.adi_dtname); dt_name.adi_dtname[10]='\0'; } else if (adf_scb->adf_date_type_alias & AD_DATE_TYPE_ALIAS_ANSI) { /* replace the input string with ansidate */ MEmove(8, (PTR)"ansidate", '\0', sizeof(ADI_DT_NAME), (PTR)&dt_name.adi_dtname); dt_name.adi_dtname[8]='\0'; } else { return (adu_error(adf_scb, E_AD5065_DATE_ALIAS_NOTSET, 0)); } } } for(n=1; n <= ADI_MXDTS; n++) { if (Adf_globs->Adi_datatypes[n].adi_dtid == DB_NODT) break; cmp = 1; c1 = &Adf_globs->Adi_datatypes[n].adi_dtname.adi_dtname[0]; if (dategiven == TRUE) c2 = (PTR)&dt_name.adi_dtname; else c2 = &adi_dname->adi_dtname[0]; i = 0; while ((i++ < s) && (*c1 != 0 || *c2 != 0)) { if (*c1++ != *c2++) { cmp = 0; break; } } if (cmp) { *adi_did = Adf_globs->Adi_datatypes[n].adi_dtid; return(E_DB_OK); } } *adi_did = DB_NODT; return(adu_error(adf_scb, E_AD2003_BAD_DTNAME, 0)); }
static bool pp_eval_boolexp( char **strptr, char *goal ) { bool boolval[2]; i4 notval[2]; i4 oper = OPER_NONE; i4 curval = 0; i4 maxval; i4 goalfound = FALSE; char *parser = *strptr; bool rtn; notval[0] = notval[1] = 0; maxval = (sizeof(boolval) / sizeof(boolval[0])) - 1; while (goalfound == FALSE) { /* Are we through yet? */ if( CMcmpcase( parser, goal ) == 0 ) { goalfound = TRUE; CMnext(parser); } /* If the string is empty then bail out */ else if( STlength( parser ) == 0) break; /* Have we exhausted our parsing capabilities? */ else if (curval > maxval) break; /* If this is white space then just skip over it */ else if( CMwhite( parser )) CMnext( parser ); /* Is this an end to a parenthetical expression? */ /* its not our goal, but it could be someones */ else if( CMcmpcase( parser, ERx(")") ) == 0 && *goal != EOS) { goalfound = TRUE; break; } /* Is this a NOT (!) to reverse the value of next boolean? */ else if( CMcmpcase( parser, ERx("!") ) == 0 ) { /* Use the xor operator to toggle, allows for !(!val) */ notval[curval] ^= 1; CMnext(parser); } /* Is this a parenthetical expression? */ else if( CMcmpcase( parser,ERx("(") ) == 0) { CMnext(parser); boolval[curval++] = pp_eval_boolexp(&parser, ERx(")")); } /* Is this an AND (&&) operator? */ else if( STbcompare( parser, 2, ERx("&&"), 2, 0 ) == 0) { if (oper != OPER_NONE) { SIfprintf( stderr, E_YAPP001 ); SIfprintf( stderr, E_YAPP00F ); yydump(); } oper = OPER_AND; CMnext(parser); CMnext(parser); boolval[curval++] = pp_eval_boolexp(&parser, ERx("\n")); } /* Is this an OR (||) operator? */ else if( STbcompare( parser, 2, ERx("||"), 2, 0 ) == 0) { if (oper != OPER_NONE) { SIfprintf( stderr, E_YAPP001 ); SIfprintf( stderr, E_YAPP011 ); yydump(); } oper = OPER_OR; CMnext(parser); CMnext(parser); boolval[curval++] = pp_eval_boolexp(&parser, ERx("\n")); } /* Is this the defined() preprocessor macro? */ else if( STbcompare( parser, 7, ERx("defined"), 7, 0 ) == 0 ) { char defsym[MAX_SYMLEN + 1]; char *defptr; /* Initialize the symbol name */ STcopy(ERx(""), defsym); /* Try and find the beginning '(' */ while (STlength(parser) > 0 && CMcmpcase(parser, ERx("(") ) != 0) CMnext(parser); /* Skip over the open parenthesis, ( */ if (STlength(parser) != 0) CMnext(parser); /* Skip over any whitespace following '(' */ while (STlength(parser) > 0 && CMwhite(parser)) CMnext(parser); /* Save the name of the symbol to look up */ defptr = defsym; while (STlength(parser) > 0 && CMcmpcase(parser, ERx(")") ) != 0 && !CMwhite(parser)) { CMcpychar(parser, defptr); CMnext(parser); CMnext(defptr); } *defptr = EOS; /* Try and find the ending ')' */ while (STlength(parser) > 0 && CMcmpcase(parser, ERx(")") ) != 0) CMnext(parser); /* Skip over the closed parenthesis, ) */ if (STlength(parser) != 0) CMnext(parser); /* Make sure there was something in the parenthesis */ if (STlength(defsym) == 0) { SIfprintf( stderr, E_YAPP001 ); SIfprintf( stderr, E_YAPP013 ); yydump(); } boolval[curval++] = (is_defined(defsym, NULL) == OK); } /* Thats all we know how to parse, gotta bail out */ else { SIfprintf( stderr, E_YAPP001 ); SIfprintf( stderr, E_YAPP014 ); yydump(); } } /* Did we ultimately fail to evaluate the expression? */ if (*goal == EOS && goalfound == FALSE) { SIfprintf( stderr, E_YAPP001 ); SIfprintf( stderr, E_YAPP015 ); yydump(); } /* Now make sure something was specified in the current expression */ if (curval == 0) { SIfprintf( stderr, E_YAPP001 ); SIfprintf( stderr, E_YAPP016 ); yydump(); } /* If an operator is found make sure it had an object to operate on */ if (oper != OPER_NONE && curval <= maxval) { SIfprintf( stderr, E_YAPP001 ); SIfprintf( stderr, E_YAPP017 ); yydump(); } /* Save the current location in parse string */ *strptr = parser; /* Resolve the highest precedence NOT operators */ if (curval > 0 && notval[0] == 1) boolval[0] = !boolval[0]; if (curval > 1 && notval[1] == 1) boolval[1] = !boolval[1]; /* Resolve the final expression */ switch (oper) { case OPER_OR: rtn = boolval[0] || boolval[1]; break; case OPER_AND: rtn = boolval[0] && boolval[1]; break; default: rtn = boolval[0]; break; } return rtn; }
/* Name: adu_map_append_validity - adds the validity values to validity table. ** Description: ** This routine, appends a validity information into the validity table. ** Input: ** vtabptr pointer to validity table. ** validity pointer to vaidity value to add. ** Output: ** ** None. ** ** History: ** 23-Jan-2004 (gupsh01) ** Added. ** 04-Feb-2004 (gupsh01) ** Modified strcmp to STbcompare. */ static DB_STATUS adu_map_append_validity( ADU_MAP_STATETABLE **vtabptr, ADU_MAP_VALIDITY *validity) { /* default values */ ADU_MAP_STATETABLE *validitytable = *vtabptr; ADU_MAP_STATETABLE *tmp_begin = NULL; ADU_MAP_STATETABLE *tmp_end = NULL; ADU_MAP_STATETABLE *ptr = NULL; u_i2 property = ST_UNASSIGNED; int i = 0; /* FIXME: if *validity is NULL return error */ if (validity == NULL) return (E_DB_ERROR); /* EMPTY_VALIDITY_DATA being added */ /* Based on the end value set next state. */ if (STbcompare (validity->state_next, 0, "VALID", 0, 1) == 0) property = ST_VALID; else if (STbcompare (validity->state_next, 0, "INVALID", 0, 1) ==0) property = ST_INVALID; else if (STbcompare (validity->state_next, 0, "UNASSIGNED", 0, 1) ==0) property = ST_EXP_UNASSIGNED; else { /* Updating the end pointers */ if (validitytable) { for (ptr=validitytable; ptr != NULL; ptr = ptr->next) { if (STbcompare (ptr->name, 0, validity->state_next, 0, 1) == 0) break; } } if (ptr == NULL) { tmp_end = (ADU_MAP_STATETABLE *)MEreqmem(0, sizeof(ADU_MAP_STATETABLE), FALSE, NULL); if (validity) { STcopy(validity->state_next, tmp_end->name); tmp_end->next = NULL; tmp_end->state_table = (ADU_MAP_VLDSTATE **)MEreqmem(0, sizeof(ADU_MAP_VLDSTATE *) * 256, FALSE, NULL); for (i=0;i<256;i++) tmp_end->state_table[i] = NULL; } /* add to the list */ if (validitytable == NULL) *vtabptr = validitytable = tmp_end; else { tmp_end->next = validitytable->next; validitytable->next=tmp_end; } } else tmp_end = ptr; } /* Updating the start pointers */ for (ptr=validitytable; ptr != NULL; ptr = ptr->next) { if (STbcompare (ptr->name, 0, validity->state_type, 0, 1) == 0) break; } if (ptr == NULL) { /* NOT FOUND */ tmp_begin = (ADU_MAP_STATETABLE *)MEreqmem(0, sizeof(ADU_MAP_STATETABLE), FALSE, NULL); ptr = tmp_begin; if (validity) { STcopy(validity->state_type, tmp_begin->name); tmp_begin->next = NULL; tmp_begin->state_table = (ADU_MAP_VLDSTATE **)MEreqmem(0, sizeof(ADU_MAP_VLDSTATE *) * 256, FALSE, NULL); for (i=0;i<256;i++) tmp_begin->state_table[i] = NULL; } /* add this to the validation list */ if (validitytable == NULL) { *vtabptr = validitytable = tmp_begin; } else { tmp_begin->next = validitytable->next; validitytable->next=tmp_begin; } } for (i=validity->state_start; i <= validity->state_end; i++) { ptr->state_table[i] = (ADU_MAP_VLDSTATE *)MEreqmem(0, sizeof(ADU_MAP_VLDSTATE), FALSE, NULL); (ptr->state_table[i])->property = property; if (tmp_end) (ptr->state_table[i])->next = tmp_end->state_table; else (ptr->state_table[i])->next = NULL; } return (E_DB_OK); }
/* Name: adu_readmap - Reads and processes a coercion map table. ** ** Description: ** This routine reads a compiled coercion map table and ** initializes the in memory table structures for the map ** table. ** ** Input: ** chset: character set to read from. ** ** Output: ** E_DB_OK if the maptable is opened and initialized. ** E_DB_ERROR if it fails. ** ** History: ** 23-Jan-2004 (gupsh01) ** Created. ** 18-Feb-2004 (gupsh01) ** Added handling of CM_DEFAULTFILE_LOC, so that ingbuld ** at install time when no characterset info is avaliable ** reads the default mapping file from $II_CONFIG location. ** 22-Oct-2004 (gupsh01) ** Fixed for correctly reading the mapping files. ** 11-May-2009 (kschendel) b122041 ** Compiler warning fixes. ** */ DB_STATUS adu_readmap(char *charset) { CL_ERR_DESC syserr; char *buf = NULL; char *bufptr = NULL; i4 bytes_read = 0; DB_STATUS stat = OK; ADU_MAP_HEADER *header; ADU_MAP_ASSIGNMENT *assignments; char *aptr; ADU_MAP_VALIDITY *validities; char *vptr; i4 buf_rem; i4 val_rem; i4 assn_rem; if (CMopen_col(charset, &syserr, CM_UCHARMAPS_LOC) != OK) { /* If we are opening the default file then check and return ** an ERROR if we are unable to open the file */ if (STbcompare (charset, 0, "default", 0, 1) == 0) { if (CMopen_col(charset, &syserr, CM_DEFAULTFILE_LOC) != OK) return (FAIL); } else return (FAIL); } /* allocate memory for buffer */ buf = MEreqmem(0, COL_BLOCK, TRUE, &stat); if (buf == NULL || stat != OK) { CMclose_col(&syserr, CM_UCHARMAPS_LOC); return (FAIL); } /* First file buffer has header information. */ stat = CMread_col(buf, &syserr); if (stat != OK) { MEfree((char *)buf); CMclose_col(&syserr, CM_UCHARMAPS_LOC); return (FAIL); } bytes_read = COL_BLOCK; header = (ADU_MAP_HEADER *) MEreqmem(0, sizeof(ADU_MAP_HEADER), TRUE, &stat); if (stat != OK) { MEfree((char *)buf); CMclose_col(&syserr, CM_UCHARMAPS_LOC); return FAIL; } MEcopy (buf, sizeof(ADU_MAP_HEADER), header); bufptr = buf + sizeof(ADU_MAP_HEADER); bufptr = ME_ALIGN_MACRO (bufptr, sizeof(PTR)); if (header->validity_size > 0) { validities = (ADU_MAP_VALIDITY *)MEreqmem(0, (u_i4) header->validity_size, FALSE, &stat); if (validities == NULL || stat != OK) { MEfree((char *)buf); CMclose_col(&syserr, CM_UCHARMAPS_LOC); return FAIL; } vptr = (char *) validities; } else { /* ERROR: validity information is required */ CMclose_col(&syserr, CM_UCHARMAPS_LOC); return (FAIL); } if (header->assignment_size > 0) { assignments = (ADU_MAP_ASSIGNMENT *)MEreqmem (0, (u_i4) header->assignment_size , FALSE, &stat); if (assignments == NULL || stat != OK) { MEfree((char *)buf); CMclose_col(&syserr, CM_UCHARMAPS_LOC); return FAIL; } aptr = (char *) assignments; } else { /* ERROR: assignment information is required */ CMclose_col(&syserr, CM_UCHARMAPS_LOC); return (FAIL); } buf_rem = COL_BLOCK - sizeof(ADU_MAP_HEADER); val_rem = header->validity_size; assn_rem = header->assignment_size; for ( ;(bytes_read < (header->validity_size + header->assignment_size + sizeof(ADU_MAP_HEADER))) || (assn_rem > 0); ) { if (val_rem > 0) { if (buf_rem >= val_rem) { /* Validation table was read completely */ MEcopy (bufptr, val_rem, vptr); bufptr += val_rem; bufptr = ME_ALIGN_MACRO (bufptr, sizeof(PTR)); buf_rem -= val_rem; val_rem = 0; if ((assn_rem > 0) && (buf_rem <= assn_rem)) { MEcopy (bufptr, buf_rem, aptr); bufptr = ME_ALIGN_MACRO (bufptr, sizeof(PTR)); bufptr += buf_rem; aptr +=buf_rem; assn_rem -= buf_rem; buf_rem = 0; } else { MEcopy (bufptr, assn_rem, aptr); bufptr += assn_rem; bufptr = ME_ALIGN_MACRO (bufptr, sizeof(PTR)); aptr +=assn_rem; buf_rem -= assn_rem; assn_rem = 0; } } else { /* read more validities before proceeding */ MEcopy (bufptr, buf_rem, vptr); bufptr = ME_ALIGN_MACRO (bufptr, sizeof(PTR)); vptr += buf_rem; val_rem -= buf_rem; buf_rem = 0 ; } } else if (assn_rem > 0) { if (buf_rem <= assn_rem) { MEcopy (bufptr, buf_rem, aptr); aptr += buf_rem; assn_rem -= buf_rem; buf_rem = 0; } else { MEcopy (bufptr, assn_rem, aptr); aptr += assn_rem; buf_rem -= assn_rem; assn_rem = 0; } } /* read next buffer if more data is needed to be read */ if (assn_rem > 0) { stat = CMread_col(buf, &syserr); if (stat != OK) { /* FIXME: either we are have got an error or we have ** found the end of the file in either case ** free the buf and exit. should report ** ERROR condition. */ break; } bufptr = buf; /* initialize bufptr */ bytes_read += COL_BLOCK; buf_rem = COL_BLOCK; } } /* check if we have read the whole file */ if (bytes_read < (header->validity_size + header->assignment_size + sizeof(ADU_MAP_HEADER))) { /* we had to exit for some unknown reason */ MEfree((char *)buf); CMclose_col(&syserr, CM_UCHARMAPS_LOC); return FAIL; } /* done with the file so close it now */ if (CMclose_col(&syserr, CM_UCHARMAPS_LOC) != OK) { MEfree ((char *)buf); /* free the buffer */ return FAIL; } /* set up the pointers in the ADF memory ** from the information obtained from mapfile. */ stat = adu_initmap (header, validities, assignments); if (stat) return (E_DB_ERROR); if (header) MEfree ((char *)header); if (validities) MEfree ((char *)validities); if (assignments) MEfree ((char *)assignments); if (buf) MEfree ((char *)buf); return (E_DB_OK); }
i4 main (int argc, char **argv) { STATUS status=OK; PTR drvH=NULL; char **list=NULL; ATTR_ID **attrList=NULL; char **defAttr=NULL; i4 count=0, attrCount = 0, retcount; i4 i; bool badCmdLine = FALSE, rmPkg = FALSE, has_default = FALSE, has_alt = FALSE, isReadOnly = FALSE, mgrSpecified = FALSE, batch = FALSE, def_or_alt=FALSE; i4 pathType = OCFG_SYS_PATH; char altPath[OCFG_MAX_STRLEN] = "\0"; char drvMgr[OCFG_MAX_STRLEN] = "\0"; char line[MAXLINE],prompt[MAXLINE]; char driverPath[OCFG_MAX_STRLEN]; char *dirPath; char driverName[OCFG_MAX_STRLEN]; char *ii_installation; char *p = NULL; char custName[OCFG_MAX_STRLEN]; char etxt[512]; ATTR_ID driverList[6] = { { DRV_ATTR_DRIVER, "\0" }, { DRV_ATTR_DRIVER_ODBC_VER, DRV_STR_VERSION }, { DRV_ATTR_DRIVER_READONLY, DRV_STR_N }, { DRV_ATTR_DRIVER_TYPE, DRV_STR_INGRES }, { DRV_ATTR_VENDOR, DRV_STR_INGRES_CORP }, { DRV_ATTR_DONT_DLCLOSE, DRV_STR_ONE } }; int drvCount = sizeof(driverList) / sizeof(driverList[0]); ATTR_ID **drvList = (ATTR_ID **)MEreqmem( (u_i2) 0, (u_i4)drvCount, TRUE, (STATUS *) NULL); for (i = 0; i < drvCount; i++) { drvList[i] = (ATTR_ID *)MEreqmem( (u_i2) 0, (u_i4)sizeof(ATTR_ID), TRUE, (STATUS *) NULL); drvList[i]->id = driverList[i].id; drvList[i]->value = (char *)MEreqmem( (u_i2) 0, (u_i4)OCFG_MAX_STRLEN, TRUE, (STATUS *) NULL); STcopy(driverList[i].value, drvList[i]->value); } if ( argc > 7 ) badCmdLine = TRUE; /* ** Parse the command line. Reject invalid arguments. */ if ( !badCmdLine && argc > 1 ) { if (checkArgs("-h", argc, argv, NULL, NULL ) ) { display_help(); PCexit(0); } if (checkArgs("-help", argc, argv, NULL, NULL ) ) { display_help(); PCexit(0); } if ( checkArgs("-batch", argc, argv, NULL, NULL ) ) batch = TRUE; if ( checkArgs("-rmpkg", argc, argv, NULL, NULL ) ) rmPkg = TRUE; if (checkArgs("-r", argc, argv, NULL, NULL ) ) isReadOnly = TRUE; if ( checkArgs("-p", argc, argv, altPath, NULL ) ) pathType = OCFG_ALT_PATH; if ( checkArgs("-m", argc, argv, NULL, drvMgr ) ) mgrSpecified = TRUE; } /* ** Set driver manager according to user input. Default is unixODBC. */ if (mgrSpecified && !STbcompare( drvMgr, 0, MGR_STR_CAI_PT, 0, TRUE ) ) driverManager = MGR_VALUE_CAI_PT; else driverManager = MGR_VALUE_UNIX_ODBC; /* ** If none of the arguments are recognized, flag an error. */ if ( !batch && !rmPkg && !isReadOnly && pathType != OCFG_ALT_PATH && !mgrSpecified && argc > 1) badCmdLine = TRUE; if ( badCmdLine ) { display_help(); PCexit(FAIL); } if ( isReadOnly ) STcopy(DRV_STR_Y, drvList[2]->value); else STcopy(DRV_STR_N, drvList[2]->value); if ( !writeMgrFile( altPath ) ) { SIprintf("Aborting due to error writing %s/files/%s\n", SYSTEM_LOCATION_SUBDIRECTORY, MGR_STR_FILE_NAME); PCexit(FAIL); } defAttr = getDefaultInfo(); if (defAttr == NULL) { SIprintf("Aborting due to error reading %s/install/%s\n", SYSTEM_LOCATION_VARIABLE, INFO_STR_FILE_NAME); PCexit(FAIL); } /* ** Get the path of the driver library and create the path/libname string. */ NMgtAt(SYSTEM_LOCATION_VARIABLE,&dirPath); /* usually II_SYSTEM */ if (dirPath != NULL && *dirPath) STlcopy(dirPath,driverPath,sizeof(driverPath)-20-1); else { SIprintf("Error--%s is not defined\n",SYSTEM_LOCATION_VARIABLE); PCexit(FAIL); } # ifdef VMS STcat(driverPath,"["); STcat(driverPath,SYSTEM_LOCATION_SUBDIRECTORY); /* usually "ingres" */ STcat(driverPath,".library]"); if ( isReadOnly ) STcat(driverPath,defAttr[INFO_ATTR_RONLY_DRV_FNAME]); else STcat(driverPath,defAttr[INFO_ATTR_DRIVER_FILE_NAME]); # else STcat(driverPath,"/"); STcat(driverPath,SYSTEM_LOCATION_SUBDIRECTORY); /* usually "ingres" */ STcat(driverPath,"/lib/"); if ( isReadOnly ) STcat(driverPath,defAttr[INFO_ATTR_RONLY_DRV_FNAME]); else STcat(driverPath,defAttr[INFO_ATTR_DRIVER_FILE_NAME]); # endif /* ifdef VMS */ STcopy(driverPath,drvList[0]->value); /* ** Initialize the cache from the odbcinst.ini file. */ openConfig(NULL, pathType, altPath, &drvH, &status); if (status != OK) { STprintf(etxt,"Could not open from path %s.\n", pathType == OCFG_ALT_PATH ? altPath : "/usr/local/etc"); display_err(etxt,status); PCexit(FAIL); } if (rmPkg) { delConfigEntry( drvH, defAttr[INFO_ATTR_DRIVER_NAME], &status ); delConfigEntry( drvH, defAttr[INFO_ATTR_ALT_DRIVER_NAME], &status ); closeConfig(drvH, &status); PCexit(OK); } /* ** Get the driver count. */ retcount = listConfig( drvH, count, list, &status ); if (status != OK) { STprintf(etxt,"Could not list drivers.\n"); display_err(etxt,status); PCexit(FAIL); } count = retcount; if (count) { /* ** Get the list of recognized drivers. */ list = (char **)MEreqmem( (u_i2) 0, (u_i4)(count * sizeof(char *)), TRUE, (STATUS *) NULL); for (i = 0; i < count; i++) list[i] = (char *)MEreqmem( (u_i2) 0, (u_i4)OCFG_MAX_STRLEN, TRUE, (STATUS *) NULL); listConfig( drvH, count, list, &status ); if (status != OK) { STprintf(etxt,"Could not list drivers.\n"); display_err(etxt,status); PCexit(FAIL); } } for (i = 0; i < count; i++) { def_or_alt = FALSE; if (!has_default) { has_default = STbcompare( list[i], 0, defAttr[INFO_ATTR_DRIVER_NAME], 0, TRUE ) == 0 ? TRUE : FALSE; if (has_default) def_or_alt = TRUE; } if (!has_alt) { has_alt = STbcompare( list[i], 0, defAttr[INFO_ATTR_ALT_DRIVER_NAME], 0, TRUE ) == 0 ? TRUE : FALSE; if (has_alt) def_or_alt = TRUE; } if (def_or_alt) { if ( !batch ) { STprintf(prompt, "\tInstallation has pre-defined version of %s.\n\tOverwrite? (Yes/No)", list[i]); if ( line_get( prompt, "", FALSE, line ) == EOF ) { SIprintf("ODBC driver installation safely aborted\n"); PCexit(OK); } STzapblank(line,line); if ( line[0] != 'y' && line [0] != 'Y' ) { SIprintf( "%s left untouched\n", list[i] ); continue; } } /* if (!batch) */ STcopy(list[i],driverName); setConfigEntry( drvH, driverName, drvCount, drvList, &status ); if (status != OK) { STprintf(etxt,"Could not write driver entry.\n"); display_err(etxt,status); PCexit(FAIL); } } /* if (has_default || has_alt) */ else if ( !batch ) { STprintf(prompt, "\tInstallation has custom version of %s.\n\tDelete? (Yes/No)", list[i]); if ( line_get( prompt, "", FALSE, line ) == EOF ) { SIprintf("ODBC driver installation safely aborted\n"); PCexit(OK); } STzapblank(line,line); if ( line[0] != 'y' && line [0] != 'Y' ) { SIprintf( "%s left untouched\n", list[i] ); continue; } STcopy(list[i],driverName); delConfigEntry( drvH, driverName, &status ); if (status != OK) { STprintf(etxt,"Could not write driver entry.\n"); display_err(etxt,status); PCexit(FAIL); } } /* if (!batch) && !has_default */ } /* for (count... */ if (!has_default) { setConfigEntry( drvH, defAttr[INFO_ATTR_DRIVER_NAME], drvCount, drvList, &status ); if (status != OK) { STprintf(etxt,"Could not write driver entry.\n"); display_err(etxt,status); PCexit(FAIL); } } if (!has_alt) { setConfigEntry( drvH, defAttr[INFO_ATTR_ALT_DRIVER_NAME], drvCount, drvList, &status ); if (status != OK) { STprintf(etxt,"Could not write driver entry.\n"); display_err(etxt,status); PCexit(FAIL); } } closeConfig(drvH, &status); if (status != OK) { STprintf(etxt,"Could not close driver info.\n"); display_err(etxt,status); PCexit(FAIL); } if (count) { for (i = 0; i < count; i++) MEfree((PTR)list[i]); MEfree((PTR)list); } for (i = 0; i < drvCount; i++) { MEfree((PTR)drvList[i]->value); MEfree((PTR)drvList[i]); } MEfree((PTR)drvList); PCexit(OK); }
/* ** 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); } }
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; }
int main( int argc, char **argv ) { EX_CONTEXT context; char name[ GCC_L_PORT + 1 ]; u_i2 apivers; PTR hndl; #ifdef LNX PCsetpgrp(); #endif MEadvise( ME_INGRES_ALLOC ); if ( EXdeclare( GCX_exit_handler, &context ) != OK ) { gcu_erlog( 0, 1, E_GC480F_EXCEPTION, NULL, 0, NULL ); PCexit( OK ); return( 0 ); } GChostname( GCD_global.host, sizeof( GCD_global.host ) ); gcu_erinit( GCD_global.host, GCD_LOG_ID, "" ); if ( initialize( argc, argv ) != OK ) gcd_exit(); gcd_init_mib(); if ( gcd_gca_init( ) != OK ) gcd_exit(); gcu_erinit( GCD_global.host, GCD_LOG_ID, GCD_global.gcd_lcl_id ); if ( gcd_adm_init() != OK ) gcd_exit(); apivers = gcd_msg_version( MSG_DFLT_PROTO ); if ( gcd_get_env( apivers, &hndl ) != OK ) gcd_exit(); if ( gcd_pool_init() != OK ) gcd_exit(); if ( gcd_gcc_init() != OK ) gcd_exit(); /* ** Log Server startup. */ { char server_flavor[256], server_type[32]; char *tmpbuf = PMgetDefault(3); ER_ARGUMENT erlist[2]; SIstd_write(SI_STD_OUT, "PASS\n"); if ( ! STbcompare( tmpbuf, 0, "*", 0, TRUE ) ) STcopy( "(DEFAULT)", server_flavor ); else STcopy( tmpbuf, server_flavor ); STcopy(PMgetDefault(2), server_type); CVupper(server_type); erlist[0].er_value = server_flavor; erlist[0].er_size = STlength(server_flavor); erlist[1].er_value = server_type; erlist[1].er_size = STlength(server_type); gcu_erlog( 0, GCD_global.language, E_GC4802_LOAD_CONFIG, NULL, 2, (PTR)&erlist ); gcu_erlog( 0, GCD_global.language, E_GC4800_STARTUP, NULL, 0, NULL ); } GCexec(); gcd_gcc_term(); gcd_pool_term(); gcd_rel_env(0); gcd_adm_term(); gcd_gca_term(); gcu_erlog( 0, GCD_global.language, E_GC4801_SHUTDOWN, NULL, 0, NULL ); EXdelete(); PCexit( OK ); return( 0 ); }