Ejemplo n.º 1
0
  protected static char[] getPassword(char[] password) {
    int size = password.length;
    int data = 0;
    boolean bwindows = Util.iswindows();
    for (int i = 0; i < size; i++) {
      if (!bwindows) {
        if (password[i] == '`' || password[i] == '"' || password[i] == '\\') data = data + 1;
      } else {
        if (password[i] == '"') data = data + 1;
        else if (password[i] == ' ') data = data + 2;
      }
    }
    char[] password2 = new char[size + data];
    int size2 = password2.length;
    int j = 0;
    for (int i = 0; i < size2; i++) {
      if (j >= size) break;
      boolean bSpace = false;

      if (!bwindows) {
        if (password[j] == '`' || password[j] == '"' || password[j] == '\\') {
          password2[i] = '\\';
          i = i + 1;
        }
      } else {
        if (password[j] == '"') {
          password2[i] = '\\';
          i = i + 1;
        } else if (password[j] == ' ') {
          password2[i] = '"';
          i = i + 1;
          password2[i] = password[j];
          i = i + 1;
          password2[i] = '"';
          // i=i+1;
          bSpace = true;
        }
      }
      if (!bSpace) password2[i] = password[j];
      j = j + 1;
    }

    return password2;
  }
Ejemplo n.º 2
0
    /**
     * Write the file by writing the values from the labels, and the values list.
     *
     * @param strFile the file to be written.
     * @param aListLabels arraylist of texfields of labels.
     * @param aListValues arraylist of texfields of values.
     */
    protected void writeFile(
        String strUser, String strFile, ArrayList aListLabels, ArrayList aListValues) {
      String strPath = FileUtil.openPath(strFile);
      String strLabel = "";
      String strValue = "";
      StringBuffer sbValues = new StringBuffer();
      JTextField txfLabel = null;
      JTextField txfValue = null;
      boolean bNewFile = false;
      int nFDAMode = Util.getPart11Mode();

      // if it's the part11 pnl and the mode is nonFDA,
      // then don't write the file for this panel
      // the other way is not true.
      if (this instanceof DisplayParentDirectory) {
        if ((isPart11Pnl() && nFDAMode == Util.NONFDA)) {
          return;
        }
      }

      if (strPath == null) {
        strPath = FileUtil.savePath(strFile);
        bNewFile = true;
      }

      if (strPath == null || aListLabels == null) return;

      if (aListValues == null) aListValues = new ArrayList();

      // Get the list of the textfields for values and labels.
      int nLblSize = aListLabels.size();
      int nValueSize = aListValues.size();
      ArrayList<String> labelList = new ArrayList<String>();

      // Get the value from each textfield, and add it to the buffer.
      for (int i = 0; i < nLblSize; i++) {
        txfLabel = (JTextField) aListLabels.get(i);
        txfValue = (i < nValueSize) ? (JTextField) aListValues.get(i) : null;

        strLabel = (txfLabel != null) ? txfLabel.getText() : null;
        strValue = (txfValue != null) ? txfValue.getText() : "";

        // We need to be sure they don't have two data directories with
        // the same labels.  Save the label list if we are writing to
        // the "data" file.
        if (strFile.indexOf("data") != -1) {
          if (labelList.contains(strLabel)) {
            Messages.postError(
                "The Data Directory specifications "
                    + "must not have duplicate Label names. "
                    + "The Label \""
                    + strLabel
                    + "\" is duplicated.  "
                    + "Skipping the second instance.  Please "
                    + "specify a new Label.");
            continue;
          } else labelList.add(strLabel);
        }

        if (strLabel == null || strLabel.trim().length() <= 0 || strValue.equals(INFOSTR)) continue;

        // for user template tab, don't need to parse the value
        if (!(this instanceof DisplayTemplate)) strValue = getValue(strUser, strValue);
        strLabel = strLabel.trim();
        if (strValue != null) strValue = strValue.trim();

        // sbValues.append("\"");
        sbValues.append(strLabel);
        // sbValues.append("\"  ");

        sbValues.append(File.pathSeparator);
        sbValues.append(strValue);
        sbValues.append("\n");
      }

      if (Util.isPart11Sys()) writeAuditTrail(strPath, strUser, sbValues);

      // write the data to the file.
      BufferedWriter writer = WFileUtil.openWriteFile(strPath);
      WFileUtil.writeAndClose(writer, sbValues);

      // if it's a template file, then make it writable for everyone.
      if (bNewFile) {
        String strCmd = "chmod 755 ";
        if (this instanceof DisplayTemplate) strCmd = "chmod 777 ";
        if (Util.iswindows()) strPath = UtilB.windowsPathToUnix(strPath);
        String[] cmd = {WGlobal.SHTOOLCMD, WGlobal.SHTOOLOPTION, strCmd + strPath};
        WUtil.runScriptInThread(cmd);
      }
    }
Ejemplo n.º 3
0
  protected static boolean unixPassword(String strUser, char[] password) {
    password = getPassword(password);
    boolean bSu = true;
    String strSu;
    PrintWriter fout = null;

    if (!Util.iswindows()) {
      String filepath = FileUtil.savePath("USER/PERSISTENCE/passwd");
      if (filepath == null) {
        filepath = FileUtil.savePath("USER/PERSISTENCE/tmp_passwd");
      }
      try {
        fout = new PrintWriter(new FileWriter(filepath));
        if (fout != null) fout.println(String.valueOf(password));
      } catch (IOException er) {
      } finally {
        try {
          if (fout != null) fout.close();
        } catch (Exception e) {
        }
      }

      /**
       * ******** String strPath = new StringBuffer().append(LOGIN).append(" ").append(
       * strUser).append(" \"").append(String.valueOf( password)).append("\"").toString(); ********
       */
      String strPath =
          new StringBuffer()
              .append(LOGIN)
              .append(" ")
              .append(strUser)
              .append(" \"")
              .append(filepath)
              .append("\"")
              .toString();
      String[] cmd = {WGlobal.SHTOOLCMD, WGlobal.SHTOOLOPTION, strPath};
      WMessage objMessage = WUtil.runScript(cmd, false);
      bSu = objMessage.isNoError();
      strSu = objMessage.getMsg();
    } else {
      String strQuotes = "\"\"";
      if (password.length == 0) strQuotes = "\"";
      String cmd =
          new StringBuffer()
              .append(LOGIN_WIN)
              .append(" ")
              .append(strUser)
              .append(" ")
              .append(strQuotes)
              .append(String.valueOf(password))
              .append(strQuotes)
              .toString();
      WMessage objMessage = WUtil.runScript(cmd, false);
      bSu = objMessage.isNoError();
      strSu = objMessage.getMsg();
    }
    if (bSu) {
      if (strSu != null) strSu = strSu.toLowerCase();
      if (strSu == null
          || strSu.trim().equals("")
          || strSu.indexOf("killed") >= 0
          || strSu.indexOf("error") >= 0) bSu = false;
    }

    return bSu;
  }