Пример #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;
  }
Пример #2
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;
  }