You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@trafodion.apache.org by li...@apache.org on 2016/12/08 00:45:38 UTC
[11/38] incubator-trafodion git commit: convert trafci project into
maven project
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/main/java/org/trafodion/ci/help/sql_common.help
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/help/sql_common.help b/core/conn/trafci/src/main/java/org/trafodion/ci/help/sql_common.help
new file mode 100644
index 0000000..be2e14c
--- /dev/null
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/help/sql_common.help
@@ -0,0 +1,376 @@
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+
+ @@@@@HELP
+
+ The command interface supports these commands:
+
+ @ LOG SET TIMING
+ ALIAS OBEY SHOW ALIAS
+ CLEAR QUIT SHOW ALIASES
+ CONNECT RECONNECT SHOW COLSEP
+ DELAY REPEAT SHOW ERRORCODE
+ DISCONNECT RESET LASTERROR SHOW HISTOPT
+ ENV SAVEHIST SHOW IDLETIMEOUT
+ EXIT SESSION (SHOW SESSION) SHOW LASTERROR
+ SET COLSEP SHOW MARKUP
+ FC SET CONNECTOPT ROLE SHOW ROLE
+ GOTO SET HISTOPT SHOW SESSION
+ HELP SET IDLETIMEOUT SHOW TIME
+ HISTORY SET MARKUP SHOW TIMING
+ IF...THEN SET PROMPT SPOOL
+ LABEL SET TIME VERSION
+ LOCALHOST
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SET
+
+ The command interface supports these SET commands:
+
+ SET COLSEP SET IDLETIMEOUT SET TIME
+ SET CONNECTOPT ROLE SET MARKUP SET TIMING
+ SET HISTOPT SET PROMPT
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SHOW
+
+ The command interface supports these SHOW commands:
+
+ SHOW ALIAS SHOW IDLETIMEOUT SHOW SESSION
+ SHOW ALIASES SHOW LASTERROR SHOW TIME
+ SHOW COLSEP SHOW MARKUP SHOW TIMING
+ SHOW ERRORCODE SHOW ROLE
+ SHOW HISTOPT
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@HELP
+
+ These interface commands can be run only in SQL mode, which
+ is the default mode in TRAFCI:
+
+ / SET PARAM SHOW PROCEDURES
+ GET STATISTICS SET SQLPROMPT SHOW RECCOUNT
+ PRUN SET SQLTERMINATOR SHOW SCHEMA
+ RESET PARAM SET STATISTICS SHOW SCHEMAS
+ RUN SHOW ACTIVITYCOUNT SHOW SQLPROMPT
+ SET FETCHSIZE SHOW FETCHSIZE SHOW SQLTERMINATOR
+ SET LIST_COUNT SHOW LIST_COUNT SHOW SYNONYMS
+ SHOW MVGROUPS SHOW TABLE
+ SHOW MVS SHOW TABLES
+ SHOW PARAM SHOW VIEWS
+ SHOW PREPARED
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ SQL mode also supports SQL statements. For descriptions of
+ the SQL statements, see the SQL Reference Manual.
+
+ @@@@@SET
+
+ SQL mode supports these SET commands:
+
+ SET FETCHSIZE SET PARAM SET SQLTERMINATOR
+ SET LIST_COUNT SET SQLPROMPT SET STATISTICS
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SHOW
+
+ SQL mode supports these SHOW commands:
+
+ SHOW ACTIVITYCOUNT SHOW PARAM SHOW SQLTERMINATOR
+ SHOW FETCHSIZE SHOW PREPARED SHOW STATISTICS
+ SHOW INDEXES SHOW PROCEDURES SHOW SYNONYMS
+ SHOW LIST_COUNT SHOW RECCOUNT SHOW TABLE
+ SHOW MVGROUPS SHOW SCHEMA SHOW TABLES
+ SHOW MVS SHOW SCHEMAS SHOW VIEWS
+ SHOW SQLPROMPT
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@/
+
+ The / command executes the previously executed SQL statement. This command
+ does not repeat an interface command.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+
+ @@@@@GET STATISTICS
+
+ The GET STATISTICS command returns formatted statistics for the last
+ executed SQL statement.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@PRUN
+
+ The PRUN command runs script files in parallel.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@RESET PARAM
+
+ The RESET PARAM command clears all parameter values or a specified
+ parameter value in the current session.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@RUN
+
+ The RUN command executes the previously executed SQL statement. This
+ command does not repeat an interface command.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SET FETCHSIZE
+
+ The SET FETCHSIZE command allows you to change the default fetchsize used
+ by JDBC. Setting the value to 0 sets the fetchsize to the default value
+ used in JDBC.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SET LIST_COUNT
+
+ The SET LIST_COUNT command sets the maximum number of rows to be returned
+ by SELECT statements that are executed after this command. The default is
+ zero, which means that all rows are returned.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SET PARAM
+
+ The SET PARAM command associates a parameter name with a parameter value
+ in the current session.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SET SQLPROMPT
+
+ The SET SQLPROMPT command sets the SQL prompt of the current session to a
+ specified string. The default is SQL>.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SET SQLTERMINATOR
+
+ The SET SQLTERMINATOR command sets the SQL statement terminator of the
+ current session. The default is a semicolon (;).
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SET STATISTICS
+
+ The SET STATISTICS command automatically retrieves the statistics
+ information for a query being executed. The results returned are the same
+ as would have been returned if the GET STATISTICS command was executed.
+ The default is OFF which means the statistics information is not
+ automatically printed for any queries.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+
+ @@@@@SHOW ACTIVITYCOUNT
+
+ The SHOW ACTIVITYCOUNT command provides an alias for SHOW RECCOUNT.
+ ACTIVITYCOUNT is an alias for RECCOUNT.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SHOW FETCHSIZE
+
+ The SHOW FETCHSIZE command displays the fetch size value for the current
+ Command Interface session.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SHOW INDEXES
+
+ The SHOW INDEXES command displays all indexes on all tables and
+ materialized views in the current schema of the Command Interface
+ session.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SHOW LIST_COUNT
+
+ The SHOW LIST_COUNT command displays the maximum number of rows to be
+ returned by SELECT statements in the current Command Interface session.
+ The default is zero, which means that all rows are returned.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SHOW MVGROUPS
+
+ The SHOW MVGROUPS command displays all or a set of the materialized view
+ groups in the current schema of the Command Interface session.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SHOW MVS
+
+ The SHOW MVS command displays all or a set of the materialized views in
+ the current schema of the Command Interface session.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SHOW PARAM
+
+ The SHOW PARAM command displays the parameters that are set in the current
+ Command Interface session.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SHOW PREPARED
+
+ The SHOW PREPARED command displays the prepared statements in the current
+ Command Interface session. If a pattern is specified, all prepared
+ statements matching the prepared statement name pattern are displayed. By
+ default, all prepared statements in the current session are displayed.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SHOW PROCEDURES
+
+ The SHOW PROCEDURES command displays the procedures (Stored Procedures in
+ Java) in the current schema of the Command Interface session. If a
+ pattern is specified, all procedures matching the pattern are displayed.
+ By default, all procedures in the current schema of the Command Interface
+ session are displayed.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SHOW RECCOUNT
+
+ The SHOW RECCOUNT command displays the record count of the previously
+ executed SQL statement. If the previously executed command was an
+ interface command, the Command Interface returns zero. Otherwise, the
+ Command Interface returns the count of the previously executed SQL
+ statement. For commands that invoke the catalog APIs-SHOW TABLES, VIEWS,
+ SYNONYMS, MVS, and so on-SHOW RECCOUNT returns the count of the database
+ objects.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SHOW SCHEMA
+
+ The SHOW SCHEMA command displays the current schema of the Command
+ Interface session.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SHOW SCHEMAS
+
+ The SHOW SCHEMAS command displays all or a set of the schemas that exist
+ in the default catalog of the current Command Interface session.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SHOW SQLPROMPT
+
+ The SHOW SQLPROMPT command displays the value of the SQL prompt for the
+ current Command Interface session.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SHOW SQLTERMINATOR
+
+ The SHOW SQLTERMINATOR command displays the SQL statement terminator of
+ the current Command Interface session.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SHOW STATISTICS
+
+ The SHOW STATISTICS command displays if statistics has been enabled or
+ disabled for the current session.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SHOW SYNONYMS
+
+ The SHOW SYNONYMS command displays all or a set of the synonyms in the
+ current schema of the Command Interface session.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SHOW TABLE
+
+ The SHOW TABLE command displays information about the indexes,
+ materialized views, synonyms, or triggers associated with a
+ specified table or materialized view.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SHOW TABLES
+
+ The SHOW TABLES command displays all or a set of the tables that exist in
+ the current schema of the Command Interface session.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
+ @@@@@SHOW VIEWS
+
+ The SHOW VIEWS command displays all or a set of the views that exist in
+ the current schema of the Command Interface session.
+
+ For more information, see the Trafodion Command Interface
+ (TRAFCI) Guide.
+
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/ArgMap.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/ArgMap.java b/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/ArgMap.java
new file mode 100644
index 0000000..3112771
--- /dev/null
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/ArgMap.java
@@ -0,0 +1,61 @@
+/**********************************************************************
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+**********************************************************************/
+package org.trafodion.ci.pwdencrypt;
+
+import java.util.HashMap;
+/**
+ * The map of valid arguments.
+ *
+ */
+public class ArgMap {
+
+ /**
+ * Map of valid arguments.
+ */
+ public static final HashMap<Character, ArgsDef> ARGMAP = argMapBuilder();
+
+ /**
+ * Constructor.
+ * @return ArgMap
+ */
+ private static HashMap<Character, ArgsDef> argMapBuilder() {
+ HashMap<Character, ArgsDef> constructmap =
+ new HashMap<Character, ArgsDef>();
+ constructmap.put('o', new ArgsDef(
+ "option", true, 'o',
+ "either \"install\", \"add\", or \"del\""));
+ constructmap.put('u', new ArgsDef(
+ "username", true, 'u',
+ "username valid only for \"add\" and \"del\""));
+ constructmap.put('p', new ArgsDef(
+ "password", true, 'p',
+ "password valid only for \"add\""));
+ constructmap.put('l', new ArgsDef(
+ "logdir", true, 'l', "Specify log file directory"));
+ constructmap.put('f', new ArgsDef(
+ "logfile", true, 'f', "Specify log file name"));
+ constructmap.put('h', new ArgsDef(
+ "help", false, 'h', "Display this message"));
+ return constructmap;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/ArgsDef.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/ArgsDef.java b/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/ArgsDef.java
new file mode 100644
index 0000000..0ef9581
--- /dev/null
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/ArgsDef.java
@@ -0,0 +1,74 @@
+/**********************************************************************
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+**********************************************************************/
+package org.trafodion.ci.pwdencrypt;
+
+public class ArgsDef {
+
+
+ private String name;
+ private boolean argrequired;
+ private char ident;
+ private String error;
+
+ /**
+ * Constructor.
+ * @param name name of option rule
+ * @param argrequired is option required
+ * @param ident char that coralates command to arg
+ */
+ public ArgsDef(String name, boolean argrequired, char ident, String error) {
+ this.name = name;
+ this.argrequired = argrequired;
+ this.ident = ident;
+ this.error = error;
+ }
+
+ /**
+ * Returns ident char.
+ * @return the ident
+ */
+ public final char getIdent() {
+ return ident;
+ }
+
+ /**
+ * @return the name
+ */
+ public final String getName() {
+ return name;
+ }
+
+ /**
+ * @return the required
+ */
+ public final boolean isArgRequired() {
+ return argrequired;
+ }
+
+ /**
+ * @return the error
+ */
+ public final String getError() {
+ return error;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/EncryptUtil.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/EncryptUtil.java b/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/EncryptUtil.java
new file mode 100644
index 0000000..6df66e4
--- /dev/null
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/EncryptUtil.java
@@ -0,0 +1,249 @@
+/**********************************************************************
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+**********************************************************************/
+/**
+ *
+ */
+package org.trafodion.ci.pwdencrypt;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+
+public class EncryptUtil {
+
+ /**
+ * Java Cryptor.
+ */
+ private static JCE j = new JCE();
+ static boolean doTrace = Boolean.getBoolean("trafci.enableTrace");
+
+
+ /**
+ * Main method.
+ * @param args arguments from command line
+ */
+ public static void main(final String[] args) {
+ PasswordOpts settings = new PasswordOpts();
+ settings.parseCommandLine(args);
+ try {
+ if (settings.getWktype().equalsIgnoreCase(WorkTypes.ADD)) {
+ add(settings.getRef(), settings.getText());
+ // System.out.println("Decrypting the password::");
+ //j.initSiteEncryptionService();
+ // read encrypt file
+ ArrayList<String> refs = readLines();
+ if (!refs.isEmpty()) {
+ for (int i=0; i < refs.size(); i++) {
+ // System.out.println("refs["+i+"]" + refs.get(i));
+ RefLookup.resolve(refs.get(i));
+ /*System.out.println("ref stri = " + ss.substring(3, ss.length()-1));
+ System.out.println("Pw::" + ss);*/
+ }
+ }
+
+ //System.out.println((j.decrypt("{DES}44SnpMxWui2uqvrrVzJwZA==")).toString());
+ } else if (settings.getWktype().equalsIgnoreCase(WorkTypes.DEL)) {
+ del(settings.getRef());
+ } else if (settings.getWktype()
+ .equalsIgnoreCase(WorkTypes.INSTALL)) {
+ j.setupSiteEncryptionService();
+ }
+ } catch (Exception e) {
+ StringBuffer msg = new StringBuffer();
+ msg.append("\n\tError Message: ").append(e.getMessage());
+ if (doTrace) {
+ e.printStackTrace();
+ }
+ System.exit(1);
+ }
+ }
+
+ /**
+ * Adds a encryption map to the secfile.
+ * @param ref reference test
+ * @param tw text word
+ * @throws DBTransporterException on error
+ */
+ private static void add(final String ref, final String tw)
+ throws Exception {
+ //init encryptor
+ j.initSiteEncryptionService();
+ final String en =
+ j.encrypt(j.sitePair.encryptor, tw);
+
+ //read encrypt file
+ ArrayList<String> refs = readLines();
+
+ //remove existing entry
+ for (int i=0; i< refs.size(); i++) {
+ if (ref != null){
+ if (0 == refs.get(i).indexOf(ref + " = {DES}")) {
+ refs.remove(refs.get(i));
+ break;
+ //System.exit(0);
+ }
+ }
+ }
+ //add the new entry
+ refs.add(ref + " = {DES}" + en);
+ writelines(refs);
+ }
+
+ /**
+ * Deletes encryption reference.
+ * @param ref reference name
+ */
+ private static void del(final String ref) {
+ //read in encrypt file
+ ArrayList<String> refs = readLines();
+ //locate by ref and delete
+ //For on-platform, clear the encrypted file when option is del
+ for (int i=0; i< refs.size(); i++) {
+ if (ref != null){
+ if (0 == refs.get(i).indexOf(ref + " = {DES}")) {
+ refs.remove(refs.get(i));
+ break;
+ //System.exit(0);
+ }
+ }
+ }
+ if (refs != null){
+ //refs.clear();
+ writelines(refs);
+ }
+ //if(doTrace)
+ //System.out.println("Failed in del:: " + ref);
+
+ }
+
+ /**
+ * Reads encctlprops file.
+ * @return ArrayList of the reference maps.
+ */
+ public static ArrayList<String> readLines() {
+ ArrayList<String> refs = new ArrayList<String>();
+
+ try {
+ //get file in stream
+
+
+
+
+
+
+ StringBuilder buff = new StringBuilder();
+ StringBuilder ref = new StringBuilder();
+
+ File secfile = new File(j.getSecDir() + JCE.encfilename);
+ FileInputStream fis = new FileInputStream(secfile);
+ InputStreamReader converter = new InputStreamReader(fis);
+ BufferedReader in = new BufferedReader(converter);
+ String tmpStr="";
+ String prevStr=null, nextStr=null;
+
+ //This loop will read the complete reference string even if it
+ //spans to multiple lines. This way the partial delete or addition
+ //to the reference is avoided.
+ prevStr = in.readLine();
+ while(prevStr != null ){
+ nextStr = in.readLine();
+
+ if (prevStr.contains(" = {DES}")){
+ if( nextStr == null || (nextStr!= null && nextStr.contains(" = {DES}"))){
+ buff.append(prevStr);
+ buff.append('\n');
+ }
+ else {
+ tmpStr = prevStr;
+ }
+ }
+ else{
+ tmpStr = tmpStr + prevStr;
+ if (nextStr == null || nextStr.contains(" = {DES}")){
+ buff.append(tmpStr);
+ buff.append('\n');
+ }
+ }
+ prevStr = nextStr;
+
+ }
+
+ // read and assign to refs list
+ char c;
+ for(int i =0; i< buff.length(); i++){
+ if((c = buff.charAt(i)) != '\n' ){
+ ref.append(c);
+ }
+ else{
+ refs.add(ref.toString());
+ ref = new StringBuilder();
+ }
+ }
+
+ //close stream
+ fis.close();
+
+ } catch (IOException e) {
+ StringBuffer msg = new StringBuffer();
+ msg.append("\n\tError Message: ").append(e.getMessage());
+ if (doTrace) { // log stack trace
+
+ e.printStackTrace();
+ }
+
+ }
+ return refs;
+ }
+
+ /**
+ * Writes encctlprops using list provided by add or del.
+ * @param refs list provided by add or del
+ */
+ private static void writelines(final ArrayList<String> refs) {
+ StringBuilder buff = new StringBuilder();
+
+ for (String ref : refs) {
+ buff.append(ref + '\n');
+ }
+
+ try {
+ String pathName = j.getSecDir() + JCE.encfilename;
+ File secfile = new File(pathName);
+ FileOutputStream fos = new FileOutputStream(secfile);
+ fos.write(buff.toString().getBytes());
+ fos.flush();
+ fos.close();
+ Runtime.getRuntime().exec("chmod 600 " + pathName);
+ } catch (IOException e) {
+ StringBuffer msg = new StringBuffer();
+ msg.append("\n\tError Message: ").append(e.getMessage());
+ if (doTrace) { // log stack trace
+ e.printStackTrace();
+ }
+
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/JCE.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/JCE.java b/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/JCE.java
new file mode 100644
index 0000000..fb03403
--- /dev/null
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/JCE.java
@@ -0,0 +1,414 @@
+/**********************************************************************
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+**********************************************************************/
+package org.trafodion.ci.pwdencrypt;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.security.InvalidAlgorithmParameterException;
+import java.security.InvalidKeyException;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.security.spec.AlgorithmParameterSpec;
+import java.security.spec.InvalidKeySpecException;
+import java.security.spec.KeySpec;
+import java.util.Arrays;
+import java.util.Properties;
+
+import javax.crypto.BadPaddingException;
+import javax.crypto.Cipher;
+import javax.crypto.IllegalBlockSizeException;
+import javax.crypto.KeyGenerator;
+import javax.crypto.NoSuchPaddingException;
+import javax.crypto.SecretKey;
+import javax.crypto.SecretKeyFactory;
+import javax.crypto.spec.DESKeySpec;
+import javax.crypto.spec.PBEKeySpec;
+import javax.crypto.spec.PBEParameterSpec;
+
+
+public class JCE {
+ public static final String SECRETKEY_ALGORITHM = "PBEWithMD5AndDES";
+ public static final String SYMMETRICKEY_ALGORITHM = "DES";
+ public static final String DIGEST_ALGORITHM = "MD5";
+
+ private static final byte[] salt = { (byte)0xFF, (byte)0x20, (byte)0xDF,
+ (byte)0xA6, (byte)0x5D, (byte)0x0D, (byte)0x34, (byte)0xD2 };
+
+ private static final char[] pass = { '\u00FF','\u0010','\u00EF', '\u00F6',
+ '\u004B', '\u0004', '\u0056', '\u0088' };
+
+ protected static final String encfilename = "/encprops.txt";
+ private static final int count = 20;
+
+ private String ciHome;
+
+ private String secDir;
+
+ private String secFile;
+
+ private static final String securityDir = ".ciconf";
+
+ private static final String securityFile = "security.props";
+
+ CipherPair basePair;
+
+ CipherPair sitePair;
+
+ MessageDigest md5;
+
+
+ /**
+ *
+ */
+ public JCE() {
+ this.ciHome = System.getenv("USERHOME"); //System.getProperty("user.dir");
+ if (ciHome ==null){
+ System.out.println("USERHOME set failed, Please check trafci/bin/ciencr.sh");
+ }
+ this.secDir = this.ciHome + '/' + securityDir; // "/sql/scripts/" + securityDir;
+ this.secFile = this.secDir + '/' + securityFile;
+
+ try {
+ md5 = initDigest();
+ basePair = initCiphers(pass, salt, count);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+
+ public void setupSiteEncryptionService() throws Exception {
+ try {
+ makeSecurityDir();
+
+ KeyGenerator keyGen = KeyGenerator.getInstance("DES");
+
+ SecretKey sKey = keyGen.generateKey();
+ byte[] encKey = sKey.getEncoded();
+ // We write two files, a digest of the key and the
+ // encrypted key itself
+ md5.reset();
+ byte[] digest = md5.digest(encKey);
+ sun.misc.BASE64Encoder ben = new sun.misc.BASE64Encoder();
+ String d = ben.encode(digest);
+ // Now encrypt the generated key with DBT cipher
+ byte[] enc = basePair.getEncryptor().doFinal(encKey);
+ String k = ben.encode(enc);
+ Properties props = new Properties();
+ props.put("d", d);
+ props.put("k", k);
+ File theSecFile = new File(secFile);
+ FileOutputStream fos = new FileOutputStream(theSecFile);
+ props.store(fos, "TRAFCI Security Initialization File");
+ fos.flush();
+ fos.close();
+ Runtime.getRuntime().exec("chmod 600 " + secFile);
+ } catch (IllegalBlockSizeException ibse) {
+ throw (Exception) new Exception("Invalid cipher block size")
+ .initCause(ibse);
+ } catch (BadPaddingException bpe) {
+ throw (Exception) new Exception("Incorrect cipher padding")
+ .initCause(bpe);
+ } catch (FileNotFoundException fnfe) {
+ throw (Exception) new Exception("Encryption utility not installed under current NVTHOME")
+ .initCause(fnfe);
+
+ } catch (NoSuchAlgorithmException nsae) {
+ throw (Exception) new Exception("Invalid cipher algorithm")
+ .initCause(nsae);
+ } catch (IOException ioe) {
+ throw (Exception) new Exception("IO Exception")
+ .initCause(ioe);
+ }
+ }
+
+ public void initSiteEncryptionService() throws Exception {
+ try {
+ FileInputStream fis = new FileInputStream(secFile);
+ Properties props = new Properties();
+ props.load(fis);
+ String k = props.getProperty("k");
+ String d = props.getProperty("d");
+ sun.misc.BASE64Decoder bde = new sun.misc.BASE64Decoder();
+ // Decrypt the key
+ byte[] key = decrypt(basePair.getDecryptor(), k);
+ byte[] digest = bde.decodeBuffer(d);
+ md5.reset();
+ byte[] d2 = md5.digest(key);
+ if (!Arrays.equals(digest, d2)) {
+ throw (Exception) new Exception("FATAL -- Tampered key");
+ }
+ sitePair = initCiphers(key);
+
+ // Get rid of the base pair
+
+ basePair.setEncryptor(null);
+ basePair.setDecryptor(null);
+ basePair = null;
+ } catch (FileNotFoundException fnfe) {
+ throw (Exception) new Exception("Encryption utility not installed under current TRAFCIHOME")
+ .initCause(fnfe);
+
+ } catch (IOException ioe) {
+ throw (Exception) new Exception("IO Exception")
+ .initCause(ioe);
+ }
+ }
+
+ private void makeSecurityDir() throws Exception {
+ final File dir = new File(secDir);
+
+ if (!dir.exists()) {
+ dir.mkdirs();
+ }
+ final File encfile = new File(
+ secDir + '/' + "encprops.txt");
+
+ try{
+ if (!encfile.exists()) {
+ encfile.createNewFile();
+ Runtime.getRuntime().exec("chmod 600 " + secDir + '/' + "encprops.txt");
+ }
+
+ } catch (IOException e) {
+ throw (Exception) new Exception("IO Exception")
+ .initCause(e);
+ }
+
+
+
+
+ }
+
+ public MessageDigest initDigest() throws Exception {
+ try {
+ MessageDigest md5 = MessageDigest.getInstance(DIGEST_ALGORITHM);
+ return md5;
+ } catch (NoSuchAlgorithmException nsae) {
+ throw (Exception) new Exception("Unknown digest")
+ .initCause(nsae);
+ }
+ }
+
+ public CipherPair initCiphers(byte[] keyData) throws Exception {
+ try {
+
+ DESKeySpec dspec = new DESKeySpec(keyData);
+
+ SecretKeyFactory skf = SecretKeyFactory.getInstance(SYMMETRICKEY_ALGORITHM);
+ SecretKey sKey = skf.generateSecret(dspec);
+
+ Cipher encryptor = Cipher.getInstance(SYMMETRICKEY_ALGORITHM);
+ Cipher decryptor = Cipher.getInstance(SYMMETRICKEY_ALGORITHM);
+ encryptor.init(Cipher.ENCRYPT_MODE, sKey);
+ decryptor.init(Cipher.DECRYPT_MODE, sKey);
+ return new CipherPair(encryptor, decryptor);
+
+ } catch (InvalidKeySpecException ikse) {
+ throw (Exception) new Exception("Invalid Key specification")
+ .initCause(ikse);
+ } catch (InvalidKeyException ikse) {
+ throw (Exception) new Exception("Invalid Key")
+ .initCause(ikse);
+ } catch (NoSuchAlgorithmException nsae) {
+ throw (Exception) new Exception("No such algorithm")
+ .initCause(nsae);
+ } catch (NoSuchPaddingException nsae) {
+ throw (Exception) new Exception("No such padding")
+ .initCause(nsae);
+ }
+ }
+
+ public CipherPair initCiphers(SecretKey key, byte[] salt, int count)
+ throws Exception {
+ try {
+ Cipher encryptor = Cipher.getInstance(SECRETKEY_ALGORITHM);
+
+ Cipher decryptor = Cipher.getInstance(SECRETKEY_ALGORITHM);
+
+ AlgorithmParameterSpec paramSpec = new PBEParameterSpec(salt, count);
+
+ encryptor.init(Cipher.ENCRYPT_MODE, key, paramSpec);
+
+ decryptor.init(Cipher.DECRYPT_MODE, key, paramSpec);
+
+ return new CipherPair(encryptor, decryptor);
+ } catch (NoSuchAlgorithmException nsae) {
+ throw (Exception) new Exception("Invalid cipher algorithm")
+ .initCause(nsae);
+ } catch (InvalidAlgorithmParameterException iape) {
+ throw (Exception) new Exception("Invalid algorithm parameter")
+ .initCause(iape);
+ } catch (InvalidKeyException ike) {
+ throw (Exception) new Exception("Invalid Key").initCause(ike);
+ } catch (NoSuchPaddingException nspe) {
+ throw (Exception) new Exception("Unknown padding")
+ .initCause(nspe);
+ }
+
+ }
+
+
+ private char[] getPass(char ePass[]) {
+ int len = ePass.length;
+ byte p[] = new byte[len];
+ char ret[] = new char[len];
+
+ Arrays.fill(p, (byte)0);
+ for (int row = 0; row < len; ++row) {
+ for (int col = 0; col < len; ++col) {
+ int bit = (int)((ePass[row] >>> ( len - 1 - col)) & 0x1);
+ p[col] |= (int)(bit << (len - 1 - row));
+ }
+ }
+
+ for (int i = 0; i < len; ++i) {
+ ret[i] = (char) (~p[i] & 0xFF);
+ }
+ return ret;
+ }
+
+ public CipherPair initCiphers(char[] pass, byte[] salt, int count)
+ throws Exception {
+ try {
+
+ KeySpec keySpec = new PBEKeySpec(getPass(pass), salt, count);
+
+ SecretKey key = SecretKeyFactory.getInstance(SECRETKEY_ALGORITHM)
+ .generateSecret(keySpec);
+
+ return initCiphers(key, salt, count);
+
+ } catch (NoSuchAlgorithmException nsae) {
+ throw (Exception) new Exception("Invalid cipher algorithm")
+ .initCause(nsae);
+ } catch (InvalidKeySpecException ike) {
+ throw (Exception) new Exception("Invalid Key specification")
+ .initCause(ike);
+ }
+ }
+
+ public String encrypt(Cipher encryptor, String msg) throws Exception {
+
+ byte[] bytes;
+
+ bytes = msg.getBytes();
+ byte[] enc = null;
+ try {
+ enc = encryptor.doFinal(bytes);
+ } catch (IllegalBlockSizeException ibse) {
+ throw (Exception) new Exception("Invalid cipher block size")
+ .initCause(ibse);
+ } catch (BadPaddingException bpe) {
+ throw (Exception) new Exception("Incorrect cipher padding")
+ .initCause(bpe);
+ }
+ String encrypted = new sun.misc.BASE64Encoder().encode(enc);
+
+ if (encrypted.contains("\n")){
+ encrypted.replaceAll("\r\n", "");
+ }
+ return encrypted;
+ }
+
+ /**
+ * This calls the other version of encrypt which requires access to this
+ * class' package protected sitePair. Allows callers outside of this
+ * package to encrypt strings.
+ * @param msg the string to be encrypted
+ * @return the encrypted string
+ * @throws DBTransporterException when encryption fails
+ */
+ public String encrypt(String msg) throws Exception {
+ return encrypt(sitePair.encryptor, msg);
+ }
+
+ public byte[] decrypt(Cipher decryptor, String enc) throws Exception {
+ byte[] bytes = null;
+ try {
+ byte[] dec = new sun.misc.BASE64Decoder().decodeBuffer(enc);
+ bytes = decryptor.doFinal(dec);
+ } catch (java.io.IOException ioe) {
+ throw (Exception) new Exception("Decoding exception")
+ .initCause(ioe);
+ } catch (IllegalBlockSizeException ibse) {
+ throw (Exception) new Exception("Invalid cipher block size")
+ .initCause(ibse);
+ } catch (BadPaddingException bpe) {
+ throw (Exception) new Exception("Incorrect cipher padding")
+ .initCause(bpe);
+ }
+ return bytes;
+ }
+
+ /**
+ * This calls the other version of decrypt which requires access to this
+ * class' package protected sitePair. Allows callers outside of this
+ * package to decrypt strings.
+ * @param msg the string to be decrypted
+ * @return the decrypted string
+ * @throws DBTransporterException when decryption fails
+ */
+ public byte[] decrypt(String msg) throws Exception {
+ return decrypt(sitePair.decryptor, msg);
+ }
+
+ public class CipherPair {
+ Cipher encryptor;
+
+ Cipher decryptor;
+
+ private CipherPair() {
+ }
+
+ private CipherPair(Cipher encryptor, Cipher decryptor) {
+ this.encryptor = encryptor;
+ this.decryptor = decryptor;
+ }
+
+ private Cipher getDecryptor() {
+ return decryptor;
+ }
+
+ private void setDecryptor(Cipher decryptor) {
+ this.decryptor = decryptor;
+ }
+
+ private Cipher getEncryptor() {
+ return encryptor;
+ }
+
+ private void setEncryptor(Cipher encryptor) {
+ this.encryptor = encryptor;
+ }
+ }
+
+ /**
+ * @return the secDir
+ */
+ public String getSecDir() {
+ return secDir;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/PasswordOpts.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/PasswordOpts.java b/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/PasswordOpts.java
new file mode 100644
index 0000000..16eac9a
--- /dev/null
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/PasswordOpts.java
@@ -0,0 +1,292 @@
+/**********************************************************************
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+**********************************************************************/
+/**
+ *
+ */
+package org.trafodion.ci.pwdencrypt;
+import java.util.Arrays;
+import java.util.Vector;
+
+public class PasswordOpts {
+
+ /**
+ * Max length of encryptable text.
+ */
+ private final int maxtextlen = 128;
+
+ /**
+ * referencename.
+ */
+ private String ref;
+ /**
+ * text to be add/deleted.
+ */
+ private String text;
+ /**
+ * directory of the log file.
+ */
+ private String dir;
+ /**
+ * file name of the log file.
+ */
+ private String file;
+ /**
+ * work type to be done.
+ */
+ private String wktype;
+
+ static boolean doTrace = Boolean.getBoolean("trafci.enableTrace");
+
+
+
+ public static final Vector<String> OPTIONTYPES = new Vector<String>(
+ Arrays.asList("option", "username", "password", "logdir","logfile","help"));
+
+ /**
+ * @param optsMap
+ */
+ public PasswordOpts() {
+ ref = null;
+ text = null;
+ dir = null;
+ file = null;
+ wktype = null;
+
+ }
+
+ /**
+ * Display help.
+ *
+ */
+ private void displayHelp() {
+ System.out.println("Usage: \n" +
+ " ciencr.sh -o [options] [args...] \n"+
+ "where options include:\n"+
+ " add add username and password\n"+
+ " del del username and password\n"+
+ "where args include:\n"+
+ " -u specify username\n"+
+ " -p specify password\n\n" +
+ "Example to ecnrypt a user's password \n\n"+
+ " ciencr.sh -o add -u <user name> -p <password>\n\n"+
+ "Example to remove a user's password \n\n"+
+ " ciencr.sh -o del -u <user name>\n\n");
+ /*System.out.println("-o/--option "
+ + "either add or del");
+ System.out.println("-u/--username "
+ + "username valid only for add and del");
+ System.out.println("-p/--password "
+ + "password valid only for add");
+ System.out.println("-l/--logdir "
+ + "Specify log file directory");
+ System.out.println("-f/--logfile "
+ + "Specify log file name");
+ System.out.println("-h/--help "
+ + "Display this message");*/
+
+ }
+
+ /**
+ * Parse Commandline Args.
+ * @param args The command to parsed
+ */
+ public final void parseCommandLine(final String[] args) {
+
+
+ if (args.length < 2 ) {
+ displayHelp();
+ if(!(args.length > 0 &&
+ (args[0].contains("h") ||
+ args[0].equalsIgnoreCase("help")))){
+ System.exit(6);
+ }
+ System.exit(0);
+ }
+
+ char flag;
+// Matcher matcher = null;
+
+ boolean hasO = false;
+ for (int i = 0; i < args.length; i++) {
+ flag = '?';
+ try {
+ flag = args[i].charAt(1)=='-'? args[i].charAt(2): args[i].charAt(1);
+ if(args[i].length()> 2 && !(OPTIONTYPES.contains(args[i].substring(1).toLowerCase()))){
+ if (doTrace)
+ System.out.println("Invalid option");
+ displayHelp();
+ System.exit(5);
+ }
+ } catch (Exception e) {
+ StringBuffer msg = new StringBuffer("\n\tError message: ");
+ msg.append(e.getMessage());
+ if (doTrace) {
+ e.printStackTrace();
+ }
+ System.exit(5);
+ }
+ switch (flag) {
+ case 'o':
+ if (ArgMap.ARGMAP.get('o').isArgRequired()) {
+ i++;
+ if (WorkTypes.WORKTYPES.contains(args[i].toLowerCase())) {
+ wktype = args[i];
+ }else{
+ if (doTrace)
+ System.out.println("Option '"+args[i]+"' is not valid.");
+ displayHelp();
+ System.exit(5);
+ }
+ }
+ if(wktype == null){
+ if (doTrace)
+ System.out.println("Option is required.");
+ displayHelp();
+ System.exit(5);
+ }
+ hasO = true;
+ break;
+
+ case 'u':
+ if (ArgMap.ARGMAP.get('u').isArgRequired()) {
+ i++;
+ ref = args[i];
+ if(ref.charAt(0)=='-' || ref == null){ if (doTrace)
+ System.out.println("Arg is u");
+ displayHelp();
+ System.exit(5);
+ }
+ }
+ break;
+
+ case 'p':
+ if (ArgMap.ARGMAP.get('p').isArgRequired()) {
+ i++;
+ if (i>=args.length){
+ displayHelp();
+ System.exit(5);
+ }
+ text = args[i];
+ if (text == null || text.length() > maxtextlen) {
+ if (doTrace)
+ System.out.println("Arg is p");
+ displayHelp();
+ System.exit(5);
+ }
+ }
+ break;
+
+ case 'l':
+ if (ArgMap.ARGMAP.get('l').isArgRequired()) {
+ i++;
+ dir = args[i];
+ }
+ break;
+ case 'f':
+ if (ArgMap.ARGMAP.get('f').isArgRequired()) {
+ i++;
+ file = args[i];
+ }
+ break;
+ case 'h':
+ displayHelp();
+ System.exit(0);
+ break;
+ default:
+ if (doTrace) {
+ System.out.println("Default arg");
+ displayHelp();
+ }
+
+ break;
+ }
+
+ }
+ if (!hasO) {
+ if (doTrace)
+ System.out
+ .println("Error: '-o' is required");
+ displayHelp();
+ System.exit(0);
+ }
+ checkArgs();
+ }
+
+ /**
+ * Checks the required args for add and del worktypes.
+ *
+ */
+ private void checkArgs() {
+
+ if (wktype.equalsIgnoreCase(WorkTypes.ADD)) {
+ if (ref == null || text == null) {
+ if (doTrace)
+ System.out.println("Errors in ADD WrkType ");
+ displayHelp();
+ System.exit(5);
+ }
+ }
+ else if (wktype.equalsIgnoreCase(WorkTypes.DEL)) {
+ /*if (ref == null) {
+ if (doTrace)
+ System.out.println("Errors in del WrkType ");
+ System.exit(5);
+ }*/
+ }
+ }
+
+ /**
+ * @return the dir
+ */
+ public final String getDir() {
+ return dir;
+ }
+
+ /**
+ * @return the file
+ */
+ public final String getFile() {
+ return file;
+ }
+
+ /**
+ * @return the ref
+ */
+ public final String getRef() {
+ return ref;
+ }
+
+ /**
+ * @return the text
+ */
+ public final String getText() {
+ return text;
+ }
+
+ /**
+ * @return the wktype
+ */
+ public final String getWktype() {
+ return wktype;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/RefLookup.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/RefLookup.java b/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/RefLookup.java
new file mode 100644
index 0000000..a2a9a75
--- /dev/null
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/RefLookup.java
@@ -0,0 +1,127 @@
+/**********************************************************************
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+**********************************************************************/
+package org.trafodion.ci.pwdencrypt;
+
+import java.io.FileInputStream;
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+
+import java.io.IOException;
+import java.io.File;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+public class RefLookup {
+ /** This pattern describes something like
+ * 'password = {DES}B/+8B2OcDkKWCFaCfwSwgQ==$'.
+ * Or more specifically, the word "password" (case insensitive),
+ * followed by any number of spaces, followed by an equal sign and any
+ * number of spaces. Then with or without quotes is any word or non-word
+ * characters . The reference String is identified as group 1 and encrypted
+ * strinf * is identified as group 4 in the pattern "refPattern"
+ */
+ private static Pattern refPattern = Pattern.compile(
+ "([^\\-]([^=](\\w*))*)((\\s*=\\s*\"*)([\\W*\\w*])*(\"*))",
+ Pattern.CASE_INSENSITIVE);
+
+ public static String resolve(final String ref) {
+ if (ref == null || ref.length() == 0) {
+ return ref;
+ }
+ try {
+ //if (ref.charAt(0) == '$') {
+ JCE j = new JCE();
+
+ // if (ref.charAt(1) == 'E') {
+ try{
+ if(! new File(j.getSecDir()).exists()){
+ System.out.println("File exists !!!");
+ }
+ // System.out.println("File being read from ...encprops" + j.getSecDir());
+ FileInputStream fis = new FileInputStream(j.getSecDir() + "/encprops.txt");
+ j.initSiteEncryptionService();
+ String userName = ref.substring(0, ref.indexOf("=")-1);
+ // System.out.println("ref stri = " + userName);
+ return new String(j.decrypt(j.sitePair.decryptor, findRef(fis, userName))); //ref.substring(0, ref.length()))));
+ }catch (IOException e) {
+
+ e.printStackTrace();
+ }
+
+ /* }else {
+ try{
+ FileInputStream fis = new FileInputStream(j.getSecDir() + "/ctlprops.txt");
+ return findRef(fis, ref.substring(2,ref.length()-1));
+ } catch (IOException e) {
+ e.printStackTrace();
+ }
+
+ }
+ } */
+
+ } catch (Exception e) {
+ StringBuffer msg = new StringBuffer();
+ msg.append("\n\tError Message: ").append(e.getMessage());
+ e.printStackTrace();
+
+
+ }
+ return ref;
+ }
+
+ private static String findRef(FileInputStream fis, String ref) throws IOException{
+
+ String strLine;
+// String str[] = null;
+ boolean match = false;
+ String enc = null;
+ String refStr=null;
+ //Fixed the password reference matching logic , so now the partial reference inputs
+ //will not be accepted and reports error in that case
+
+ BufferedReader br = new BufferedReader(new InputStreamReader(fis));
+
+ while ((strLine = br.readLine()) != null) {
+ Matcher matcher = refPattern.matcher(strLine);
+ if(matcher.find()) {
+ refStr = matcher.group(1).trim(); //group(1) gives the reference String
+ // System.out.println("strLine1=" + refStr);
+ if( refStr.equals(ref)){
+ // The password to be encrypted
+ enc = matcher.group(4).trim(); //group(4) gives the encrypted value
+ match = true;
+ // System.out.println("strLine2=" + enc);
+ }
+ if(match)
+ break;
+ }
+ }
+ if(!match){
+ System.out.println("Match failed!!");
+ System.exit(0);
+ }
+
+ //Trims lead " = {DES}" if present. Would be present when Encrypted.
+ return enc.replaceFirst("=", "").trim().replace("{DES}", "");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/WorkTypes.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/WorkTypes.java b/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/WorkTypes.java
new file mode 100644
index 0000000..9bd34e1
--- /dev/null
+++ b/core/conn/trafci/src/main/java/org/trafodion/ci/pwdencrypt/WorkTypes.java
@@ -0,0 +1,55 @@
+/**********************************************************************
+// @@@ START COPYRIGHT @@@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements. See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership. The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied. See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+// @@@ END COPYRIGHT @@@
+**********************************************************************/
+package org.trafodion.ci.pwdencrypt;
+import java.util.Arrays;
+import java.util.Vector;
+
+/**
+ * Defines the valid options for the -o arg.
+ *
+ */
+public class WorkTypes {
+
+ /**
+ * Install type.
+ */
+ public static final String INSTALL = "install";
+ /**
+ * Add text work type.
+ */
+ public static final String ADD = "add";
+ /**
+ * Delete text work type.
+ */
+ public static final String DEL = "del";
+ /**
+ * Unknown work type.
+ */
+ public static final String UNKNOWN = "unknown";
+
+ /**
+ * Valid set of worktypes.
+ */
+ public static final Vector<String> WORKTYPES = new Vector<String>(
+ Arrays.asList(INSTALL, ADD, DEL, UNKNOWN));
+}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/main/resources/install_jar.xml
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/main/resources/install_jar.xml b/core/conn/trafci/src/main/resources/install_jar.xml
new file mode 100644
index 0000000..a79fdd5
--- /dev/null
+++ b/core/conn/trafci/src/main/resources/install_jar.xml
@@ -0,0 +1,49 @@
+<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
+ <id>install_jar</id>
+ <formats>
+ <format>jar</format>
+ </formats>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <fileSets>
+ <fileSet>
+ <directory>${basedir}/utils/</directory>
+ <includes>
+ <include>ciencr.sh</include>
+ <include>trafci</include>
+ <include>trafci-perl.pl</include>
+ <include>trafci.cmd</include>
+ <include>trafci.sh</include>
+ <include>trafci-python.py</include>
+ <include>trafci.pl</include>
+ <include>trafci.py</include>
+ </includes>
+ <outputDirectory>/bin</outputDirectory>
+ </fileSet>
+ <fileSet>
+ <directory>${basedir}/lib</directory>
+ <outputDirectory>/lib</outputDirectory>
+ </fileSet>
+ <fileSet>
+ <directory>${basedir}/samples</directory>
+ <outputDirectory>/samples</outputDirectory>
+ </fileSet>
+ <fileSet>
+ <directory>${basedir}/target/installer-classes</directory>
+ <outputDirectory>/</outputDirectory>
+ </fileSet>
+ </fileSets>
+ <!-- <files>
+ <file>
+ <source>${basedir}/utils/trafci.cmd</source>
+ <outputDirectory>/bin</outputDirectory>
+ <destName>trafci.cmd</destName>
+ </file>
+ <file>
+ <source>${basedir}/utils/trafci.sh</source>
+ <outputDirectory>/bin</outputDirectory>
+ <destName>trafci.sh</destName>
+ </file>
+ </files> -->
+</assembly>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/main/resources/install_tar.xml
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/main/resources/install_tar.xml b/core/conn/trafci/src/main/resources/install_tar.xml
new file mode 100644
index 0000000..391e74b
--- /dev/null
+++ b/core/conn/trafci/src/main/resources/install_tar.xml
@@ -0,0 +1,29 @@
+<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
+ <id>install_tar</id>
+ <formats>
+ <format>tar</format>
+ </formats>
+ <includeBaseDirectory>false</includeBaseDirectory>
+ <fileSets>
+ <fileSet>
+ <directory>${basedir}/utils/</directory>
+ <outputDirectory>/</outputDirectory>
+ <includes><include>README</include>
+ </includes>
+ </fileSet>
+ <fileSet>
+ <directory>target</directory>
+ <includes><include>trafciInstaller.jar</include></includes>
+ <outputDirectory>/</outputDirectory>
+ </fileSet>
+ </fileSets>
+ <!-- <files>
+ <file>
+ <source>target/trafciInstaller.tar</source>
+ <outputDirectory>/</outputDirectory>
+ <destName>trafci.tar</destName>
+ </file>
+ </files> -->
+</assembly>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/org/trafodion/ci/AWTExceptionHandler.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/org/trafodion/ci/AWTExceptionHandler.java b/core/conn/trafci/src/org/trafodion/ci/AWTExceptionHandler.java
deleted file mode 100644
index eceaada..0000000
--- a/core/conn/trafci/src/org/trafodion/ci/AWTExceptionHandler.java
+++ /dev/null
@@ -1,36 +0,0 @@
-// @@@ START COPYRIGHT @@@
-//
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-// @@@ END COPYRIGHT @@@
-package org.trafodion.ci;
-
-public class AWTExceptionHandler{
-
- public AWTExceptionHandler(){
- }
-
- public void handle(Throwable t)
- {
- if(Boolean.getBoolean("trafci.enableTrace"))
- {
- System.out.println("TrafCI Captured AWT Stack Trace:");
- t.printStackTrace();
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/org/trafodion/ci/CSVDisplay.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/org/trafodion/ci/CSVDisplay.java b/core/conn/trafci/src/org/trafodion/ci/CSVDisplay.java
deleted file mode 100644
index 2db7575..0000000
--- a/core/conn/trafci/src/org/trafodion/ci/CSVDisplay.java
+++ /dev/null
@@ -1,90 +0,0 @@
-// @@@ START COPYRIGHT @@@
-//
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-// @@@ END COPYRIGHT @@@
-
-package org.trafodion.ci;
-
-import java.io.IOException;
-import java.util.ArrayList;
-
-public class CSVDisplay implements IDisplay {
-
- private Query qryObj;
- private Writer writer=null;
- private Session sessObj=null;
- private int colCount=1;
-
- public CSVDisplay(Session sessObj)
- {
- if (sessObj != null)
- {
- this.sessObj = sessObj;
- this.writer=sessObj.getWriter();
- this.qryObj=sessObj.getQuery();
- }
- }
-
- public void output(OutputContents contents) throws IOException {
- // TODO Auto-generated method stub
- if(contents!=null)
- {
- this.writer=sessObj.getWriter();
- this.qryObj=sessObj.getQuery();
- //display contents
- ArrayList<OutputColumnAttribute> columns = contents.getColumns();
- ArrayList<ArrayList<String>> alRows = contents.getRows();
- qryObj.setColCount(String.valueOf(columns.size()));
-
- if(alRows!=null && alRows.size()>0)
- {
- for(int i=0;i<alRows.size();i++)
- {
- ArrayList<String> alRow = alRows.get(i);
- if(alRow!=null && alRow.size()>0)
- {
- for(int j=0;j<alRow.size();j++)
- {
- writer.write(alRow.get(j));
- if (qryObj.getColCount() != null)
- {
- if (colCount == Integer.parseInt(qryObj.getColCount()))
- {
- writer.write(SessionDefaults.lineSeperator);
- colCount=1;
- break;
- }
- }
- colCount++;
- if (sessObj.getStrDisplayFormat().equalsIgnoreCase("COLSEP"))
- writer.write(sessObj.getSessionColSep());
- else
- writer.write(",");
- //wrong code
-// break;
- }
- }
-
- }
-
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/org/trafodion/ci/Column.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/org/trafodion/ci/Column.java b/core/conn/trafci/src/org/trafodion/ci/Column.java
deleted file mode 100644
index ac506a1..0000000
--- a/core/conn/trafci/src/org/trafodion/ci/Column.java
+++ /dev/null
@@ -1,131 +0,0 @@
-// @@@ START COPYRIGHT @@@
-//
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-// @@@ END COPYRIGHT @@@
-package org.trafodion.ci;
-
-public class Column
-{
-
- Column()
- {
- }
-
- int maxColSize = 0;
- int actualColValSize = 0;
- int maxDisplayColSize = 0;
- int currentIndexPos = 0;
- String columnName = null;
-
- boolean isColWrap = false;
- boolean isLeftAligned = true;
- boolean isDone = false;
- boolean isTrim=false;
- boolean isHeader = false;
-
- String colVal = null;
- String fillerStr = null;
- char fillChar = ' ';
-
- // This method set the length for each column
- public void setLength (int maxColSize, int maxDisplayColSize)
- {
- this.maxColSize = maxColSize;
- this.maxDisplayColSize = maxDisplayColSize;
- //Set columns wrapped to true if metadata colsize is greater than display colsize
- this.isColWrap = this.maxColSize > this.maxDisplayColSize?true:false;
- //If columns are wrapped then, set the maximum display size to be that set by the session object
- if (!isColWrap)
- this.maxDisplayColSize = this.maxColSize;
-
- //this.maxDisplayColSize = this.isColWrap?this.maxDisplayColSize:this.maxColSize;
- }
-
- // This method sets the filler character of space for each column based on the data for each column
- public void setFillChar(char fillChar)
- {
- StringBuffer fillBuf = new StringBuffer();
-
- for (int i = 0; i < this.maxDisplayColSize; i++)
- {
- fillBuf.append(fillChar);
- }
-
- this.fillerStr = fillBuf.toString();
- fillBuf = null;
- }
-
- // This method set the column value
- public void setColValue(String colVal)
- {
- if (this.isTrim)
- {
- colVal= colVal.trim(); //Remove the extra blanks
- }
- this.actualColValSize = colVal.length();
- //if column data length is greater than meta data legth then substring it to metadata length
- this.colVal = this.actualColValSize > this.maxColSize?colVal.substring(0, this.maxColSize):colVal;
- this.currentIndexPos = 0;
- this.isDone = false;
- this.isHeader =false;
- }
-
- public String getColValue()
- {
-
- if (isDone)
- return this.fillerStr;
-
- if (!this.isColWrap)
- {
- isDone = true;
-
- if (this.isLeftAligned || this.isHeader)
- return this.colVal.substring(this.currentIndexPos)+this.fillerStr.substring(this.colVal.substring(this.currentIndexPos).length(),this.maxDisplayColSize);
- else
- return this.fillerStr.substring(this.colVal.substring(this.currentIndexPos).length(),this.maxDisplayColSize)+this.colVal.substring(this.currentIndexPos);
- }
-
- if (currentIndexPos + this.maxDisplayColSize <= this.actualColValSize)
- {
- this.currentIndexPos += this.maxDisplayColSize;
- return this.colVal.substring(this.currentIndexPos - this.maxDisplayColSize,this.currentIndexPos);
- }
- isDone = true;
- if (this.isLeftAligned || this.isHeader)
- return this.colVal.substring(this.currentIndexPos)+this.fillerStr.substring(this.colVal.substring(this.currentIndexPos).length(),this.maxDisplayColSize);
- else
- return this.fillerStr.substring(this.colVal.substring(this.currentIndexPos).length(),this.maxDisplayColSize)+this.colVal.substring(this.currentIndexPos);
- }
-
- public void setLeftAligned(boolean isLeftAligned)
- {
- this.isLeftAligned = isLeftAligned;
- }
-
- public boolean isDone()
- {
- return this.isDone;
- }
-
- public void setTrim(boolean isTrim)
- {
- this.isTrim=isTrim;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/org/trafodion/ci/ConditionalQuery.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/org/trafodion/ci/ConditionalQuery.java b/core/conn/trafci/src/org/trafodion/ci/ConditionalQuery.java
deleted file mode 100644
index fba85ba..0000000
--- a/core/conn/trafci/src/org/trafodion/ci/ConditionalQuery.java
+++ /dev/null
@@ -1,435 +0,0 @@
-// @@@ START COPYRIGHT @@@
-//
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-// @@@ END COPYRIGHT @@@
-
-package org.trafodion.ci;
-
-import java.io.IOException;
-import java.util.HashMap;
-import java.util.regex.Pattern;
-
-public class ConditionalQuery extends QueryWrapper implements SessionDefaults{
-
- private HashMap<String, String> cqKeyMap = null;
- private String gotoLabel = ""; // the label we are waiting to see
- private int variableType = -1;
- private int valueType = -1;
- private String strPendingAction = null;
-
- /* types of values passed to conditional statements */
- private static final int VARIABLE = 0;
- private static final int STRING = 1;
- private static final int INTEGER = 2;
- /* enums not available in 1.4 :( */
-
-
- /* Constructor */
- public ConditionalQuery(){}
-
- public ConditionalQuery(Session sessObj){
- super(sessObj);
- cqKeyMap = new HashMap<String, String>();
- loadCqKeyWordMap();
- }
-
- public void execute() throws ConditionalQueryException, UserInterruption, IOException
- {
- // reset error
- cqe.setError(null);
-
- String label = null;
- init();
- isMultiLine = sessObj.getQuery().isMultiLine();
- blankLiner = false;
- readQuery();
- blankLiner = true;
-
- // get the QueryId and directly process that command
- switch (sessObj.getQuery().getQueryId())
- {
- case IF_THEN:
- if(!getGotoLabel().equals(""))
- break;
-
- // reset types
- valueType = -1;
- variableType = -1;
-
- String variable = parser.getConditionalVariable(this.queryStr);
- String operator = parser.getConditionalOperator(this.queryStr);
- String value = parser.getConditionalValue(this.queryStr);
- String action = parser.getConditionalAction(this.queryStr);
-
- if(variable == null || operator == null || value == null || action == null){
- throw cqe;
- }
-
- /* strip begin/end quotes and beginning % from variable */
- variable = format(variable, true);
-
- if(variableType != STRING)
- {
- Object tmpObj = getValue(variable);
-
- if(tmpObj == null)
- {
- if(isInteger(variable))
- {
- variableType = INTEGER;
- }
- else
- {
- /* not a valid integer, must have been an unresolved variable */
- ErrorObject varNotFound = new ErrorObject(SessionError.VARIABLE_NOT_FOUND.errorCode(),
- SessionError.VARIABLE_NOT_FOUND.errorMessage() + "'" + variable + "'.");
- cqe.setError(varNotFound);
- throw cqe;
- }
- }
- else
- {
- variable = tmpObj.toString();
- variableType = VARIABLE;
- }
-
- }
-
- /* strip begin/end quotes and beginning % from value */
- value = format(value, false);
-
- if(valueType != STRING)
- {
- Object tmpObj = getValue(value);
-
- if(tmpObj == null)
- {
- if(isInteger(value))
- valueType = INTEGER;
- else
- {
- /* not a valid integer, must have been an unresolved variable */
- ErrorObject varNotFound = new ErrorObject(SessionError.VARIABLE_NOT_FOUND.errorCode(),
- SessionError.VARIABLE_NOT_FOUND.errorMessage() + "'" + value + "'.");
- cqe.setError(varNotFound);
- throw cqe;
- }
- }
- else
- {
- value = tmpObj.toString();
- valueType = VARIABLE;
- }
- }
-
- if(compare(variable, operator, value))
- {
- /* condition passed, set pending action */
- strPendingAction = action + sessObj.getSessionSQLTerminator();
- }
- else
- {
- /* condition failed, do not set a pending action */
- strPendingAction = null;
- }
- break;
-
- case GOTO:
- if(!getGotoLabel().equals(""))
- break;
-
- parser.getNextKeyToken(); // skip first token
- label = parser.getNextValueToken();
-
- if(parser.hasMoreTokens())
- writeSyntaxError(this.queryStr,parser.getRemainderStr());
- else
- {
- if(label != null){
- setGotoLabel(label);
- writer.writeln();
-
- ErrorObject goto_msg = new ErrorObject(SessionError.GOTO_MESSAGE.errorCode(),
- SessionError.GOTO_MESSAGE.errorMessage() + label + "'command is encountered.",SessionError.GOTO_MESSAGE.errorType);
- writer.writeError(sessObj, goto_msg);
-
- }else
- writeSyntaxError(this.queryStr,parser.getRemainderStr());
- }
-
- break;
-
- case LABEL:
- parser.getNextKeyToken(); // skip first token
- label = parser.getNextValueToken();
-
- if(parser.hasMoreTokens())
- writeSyntaxError(this.queryStr,parser.getRemainderStr());
- else
- {
- if(label != null)
- {
- if(label.equals(getGotoLabel())){
- writer.writeln();
- writer.writeError(sessObj, SessionError.MATCHING_LABEL);
- setGotoLabel("");
- }
- }else if(getGotoLabel().equals(""))
- writeSyntaxError(this.queryStr,parser.getRemainderStr());
- else
- {
- /* give a warning */
- ErrorObject labelWarning = new ErrorObject(SessionError.LABEL_WARNING.errorCode(),
- SessionError.LABEL_WARNING.errorMessage(),'W');
- cqe.setError(labelWarning);
- throw cqe;
- }
- }
-
- break;
- }
- }
-
- // change throws UserInterruption to custom error
- public Object getValue(String variable) throws ConditionalQueryException
- {
- /* get the variable's value */
- Object variableValue = null;
-
- if(variable.startsWith("?"))
- {
- variableValue = sessObj.getSessParams(variable.substring(1));
- if(variableValue == null)
- {
- ErrorObject paramNotFound = new ErrorObject(SessionError.PARAM_NOT_FOUND.errorCode(),
- SessionError.PARAM_NOT_FOUND.errorMessage() + variable + " was not found");
- cqe.setError(paramNotFound);
- throw cqe;
- }
- }
- else
- {
- variableValue = sessObj.getEnv(variable);
- }
-
- return variableValue;
- }
- public boolean compare(String variable, String operator, String value) throws ConditionalQueryException
- {
- int compareType = -1;
-
- if(valueType != variableType)
- {
- if(valueType == VARIABLE)
- compareType = variableType;
- else if(variableType == VARIABLE)
- compareType = valueType;
- else if(variableType == INTEGER && valueType == STRING ||
- variableType == STRING && valueType == INTEGER)
- {
- if(variableType == STRING)
- cqe.setError(SessionError.STR_INT_COMPARISON);
- else
- cqe.setError(SessionError.INT_STR_COMPARISON);
-
- throw cqe;
- }
- }
- else{
- /* if both are variables, see if both are integers,
- * otherwise treat them as strings
- */
- if(valueType == VARIABLE)
- {
- if(isInteger(variable) && isInteger(value))
- valueType = INTEGER;
- else
- valueType = STRING;
- }
- compareType = valueType;
- }
-
- switch(compareType){
- case STRING:
- if(operator.equals("=") || operator.equals("=="))
- {
- return variable.equals(value);
- }
- else if(operator.equals("<>") || operator.equals("!=") ||
- operator.equals("~=") || operator.equals("^="))
- {
- return !variable.equals(value);
- }
- else
- {
-
- if(operator.equals("<") || operator.equals(">") || operator.equals("<=") || operator.equals(">="))
- {
- ErrorObject invalidStrComp = new ErrorObject(SessionError.INVALID_STRING_COMPARE.errorCode(),
- SessionError.INVALID_STRING_COMPARE.errorMessage() + "'" + operator + "'.");
-
- cqe.setError(invalidStrComp);
- }
-
- // invalid operator exception
- throw cqe;
- }
- /* break not necessary, this is unreachable */
- case INTEGER:
- try
- {
- if(!(isInteger(variable) && isInteger(value)))
- {
- if(isInteger(value))
- cqe.setError(SessionError.STR_INT_COMPARISON);
- else
- cqe.setError(SessionError.INT_STR_COMPARISON);
-
- throw cqe;
- }
- else
- {
-
- int variableInt = Integer.parseInt(variable);
- int valueInt = Integer.parseInt(value);
-
- if(operator.equals("=") || operator.equals("=="))
- {
- return variableInt == valueInt;
- }
- else if(operator.equals("<>") || operator.equals("!=") ||
- operator.equals("~=") || operator.equals("^="))
- {
- return variableInt != valueInt;
- }
- else if(operator.equals("<"))
- {
- return variableInt < valueInt;
- }
- else if(operator.equals(">"))
- {
- return variableInt > valueInt;
- }
- else if(operator.equals("<="))
- {
- return variableInt <= valueInt;
- }
- else if(operator.equals(">="))
- {
- return variableInt >= valueInt;
- }
- else
- {
- // invalid operator exception
- throw cqe;
- }
- }
- }
- catch(NumberFormatException nfe)
- {
- // TODO: FIX ERROR
- nfe.printStackTrace();
- }
- /* break not necessary, this is unreachable */
- }
-
- return false;
- }
-
- /* strip out beginning % and quotes */
- private String format(String var, boolean isVariable)
- {
- String temp = var;
-
- if(var.startsWith("%"))
- temp = var.substring(1, var.length());
-
-
- if(temp.startsWith("\"") && temp.endsWith("\""))
- {
- if(temp.length() > 2)
- temp = temp.substring(1, temp.length()-1);
- else
- temp = "";
-
- if(isVariable)
- variableType = STRING;
- else
- valueType = STRING;
- }
-
- return temp;
- }
-
- private void loadCqKeyWordMap()
- {
- cqKeyMap.put("IF", ""+IF_THEN);
- cqKeyMap.put("LABEL", ""+LABEL);
- cqKeyMap.put("GOTO", ""+GOTO);
- }
-
- public boolean isInteger(String str)
- {
- return Pattern.matches("^-?\\d+$",str);
- }
-
-
- /*
- * repeated code from interface query, perhaps move out of IQ and make public somewhere else?
- */
- private void writeSyntaxError(String queryStr, String remainderStr) throws IOException
- {
- sessObj.getQuery().setStatusCode(-1); // update the error code to -1
-
- if(sessObj.getDisplayFormat() != SessionDefaults.XML_FORMAT)
- writer.writeln();
-
- writer.writeSyntaxError(sessObj, this.queryStr,remainderStr);
- }
-
- /* Getter/Setter Methods ****/
-
- private void setGotoLabel(String label){
- this.gotoLabel = label;
- }
-
- public String getGotoLabel(){
- return this.gotoLabel;
- }
-
- public String getPendingAction(){
- String tmpAction = strPendingAction;
- strPendingAction = null;
- return tmpAction;
- }
-
- public boolean isPendingAction()
- {
- return strPendingAction != null;
- }
-
- public void setQueryString(String q){
- this.queryStr = q;
- }
-
- public String getQueryString(){
- return this.queryStr;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/org/trafodion/ci/ConditionalQueryException.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/org/trafodion/ci/ConditionalQueryException.java b/core/conn/trafci/src/org/trafodion/ci/ConditionalQueryException.java
deleted file mode 100644
index bbce043..0000000
--- a/core/conn/trafci/src/org/trafodion/ci/ConditionalQueryException.java
+++ /dev/null
@@ -1,43 +0,0 @@
-// @@@ START COPYRIGHT @@@
-//
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-// @@@ END COPYRIGHT @@@
-package org.trafodion.ci;
-
-public class ConditionalQueryException extends Exception{
-
- /**
- *
- */
- ErrorObject errMsg = null;
- private static final long serialVersionUID = 1L;
-
- ConditionalQueryException()
- {
- super();
- }
-
- public ErrorObject getErrorMsg(){
- return this.errMsg;
- }
-
- public void setError(ErrorObject err){
- this.errMsg = err;
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-trafodion/blob/de7e7d4e/core/conn/trafci/src/org/trafodion/ci/ConditionalSyntaxError.java
----------------------------------------------------------------------
diff --git a/core/conn/trafci/src/org/trafodion/ci/ConditionalSyntaxError.java b/core/conn/trafci/src/org/trafodion/ci/ConditionalSyntaxError.java
deleted file mode 100644
index b8d09e7..0000000
--- a/core/conn/trafci/src/org/trafodion/ci/ConditionalSyntaxError.java
+++ /dev/null
@@ -1,123 +0,0 @@
-// @@@ START COPYRIGHT @@@
-//
-// Licensed to the Apache Software Foundation (ASF) under one
-// or more contributor license agreements. See the NOTICE file
-// distributed with this work for additional information
-// regarding copyright ownership. The ASF licenses this file
-// to you under the Apache License, Version 2.0 (the
-// "License"); you may not use this file except in compliance
-// with the License. You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing,
-// software distributed under the License is distributed on an
-// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
-// KIND, either express or implied. See the License for the
-// specific language governing permissions and limitations
-// under the License.
-//
-// @@@ END COPYRIGHT @@@
-package org.trafodion.ci;
-
-import java.util.regex.Pattern;
-import java.util.regex.Matcher;
-
-public class ConditionalSyntaxError {
-
-
- private StringBuffer errMesg=null;
- private String errPrefix= "";
-
- Pattern patVariable = Pattern.compile("^((?i:IF)(\\s|\\n)+((\"(\"(?=\")|\\\\(?=\")|.)*?\")|[^(\\n|\\s|!=|<>|>=|<=|>|<|=|==)]+)?)(.+)?\\z", Pattern.DOTALL);
- Pattern patOperator = Pattern.compile("^((?i:IF)(\\s|\\n)+((\"(\"(?=\")|\\\\(?=\")|.)*?\")|[^(\\n|\\s|!=|<>|>=|<=|>|<|=|==)]+)(\\s|\\n)*(!=|<>|>=|<=|>|<|==|=)?)(.*)\\z", Pattern.DOTALL);
- Pattern patValue = Pattern.compile("^((?i:IF)(\\s|\\n)+((\"(\"(?=\")|\\\\(?=\")|.)*?\")|[^(\\n|\\s|!=|<>|>=|<=|>|<|=|==)]+)(\\s|\\n)*(!=|<>|>=|<=|>|<|==|=)(\\s|\\n)*((\"(\"(?=\")|\\\\(?=\")|.)*?\")|[^(\\s|\\n|!=|<>|>=|<=|>|<|=|==)]+)?)(.+)\\z", Pattern.DOTALL);
-
- ConditionalSyntaxError()
- {
-
- }
-
- public String testVariable(String qryString){
- Matcher m = patVariable.matcher(qryString);
- if(m.find())
- return m.group(m.groupCount());
-
- return null;
- }
-
- public String testOperator(String qryString){
- Matcher m = patOperator.matcher(qryString);
- if(m.find())
- return m.group(m.groupCount());
-
- return null;
- }
-
- public String testValue(String qryString){
- Matcher m = patValue.matcher(qryString);
- if(m.find())
- return m.group(m.groupCount()).trim();
-
- return null;
- }
-
- public void setSyntaxError(String qryString, String errLoc)
- {
- if(errMesg == null)
- {
- errMesg=new StringBuffer();
- }
-
- this.errMesg.delete(0,errMesg.length());
-
- this.errMesg.append(errPrefix);
- this.errMesg.append("\n");
- this.errMesg.append(qryString);
- this.errMesg.append("\n");
-
- for(int i=0; i < qryString.length()-errLoc.length();i++)
- this.errMesg.append(" ");
-
- this.errMesg.append("^");
- }
-
- public ErrorObject getSyntaxError(String qryString)
- {
-
- if(qryString != null)
- {
- qryString=qryString.replaceAll("\\n"," ").trim();
- }
-
- String testVar = testVariable(qryString);
- String testOp = testOperator(qryString);
- String testVal = testValue(qryString);
-
- String errLoc = "";
-
- if(testVal != null)
- {
- errPrefix = "A conditional syntax error occurred at or before:";
- errLoc = testVal;
- }
- else if(testOp != null)
- {
- errPrefix = "A conditional operator syntax error occurred at or before:";
- errLoc = testOp;
- }
- else
- {
- errPrefix = "A conditional variable syntax error occurred at or before:";
- if(testVar == null)
- testVar = qryString.charAt(qryString.length()-1)+"";
-
- errLoc = testVar;
- }
-
- setSyntaxError(qryString, errLoc);
- return new ErrorObject(SessionError.GENERIC_SYNTAX_ERROR_CODE, errMesg.toString());
- }
-
-
-}