Ejemplo n.º 1
0
        public Channel launchChannel(String[] cmd, OutputStream err, FilePath _workDir, Map<String,String> envOverrides) throws IOException, InterruptedException {
            printCommandLine(cmd, _workDir);

            Pipe out = Pipe.createRemoteToLocal();
            final String workDir = _workDir==null ? null : _workDir.getRemote();

            OutputStream os = getChannel().call(new RemoteChannelLaunchCallable(cmd, out, err, workDir, envOverrides));

            return new Channel("remotely launched channel on "+channel,
                Computer.threadPoolForRemoting, out.getIn(), new BufferedOutputStream(os));
        }
Ejemplo n.º 2
0
        public OutputStream call() throws IOException {
            Process p = Runtime.getRuntime().exec(cmd,
                Util.mapToEnv(inherit(envOverrides)),
                workDir == null ? null : new File(workDir));

            List<String> cmdLines = Arrays.asList(cmd);
            new StreamCopyThread("stdin copier for remote agent on "+cmdLines,
                p.getInputStream(), out.getOut()).start();
            new StreamCopyThread("stderr copier for remote agent on "+cmdLines,
                p.getErrorStream(), err).start();

            // TODO: don't we need to join?

            return new RemoteOutputStream(p.getOutputStream());
        }
Ejemplo n.º 3
0
  /**
   * Authenticate ourselves against the server.
   *
   * @return identity of the server represented as a public key.
   */
  public PublicKey authenticate(Iterable<KeyPair> privateKeys)
      throws IOException, GeneralSecurityException {
    Pipe c2s = Pipe.createLocalToRemote();
    Pipe s2c = Pipe.createRemoteToLocal();
    entryPoint.authenticate("ssh", c2s, s2c);
    Connection c = new Connection(s2c.getIn(), c2s.getOut());

    try {
      byte[] sharedSecret = c.diffieHellman(false).generateSecret();
      PublicKey serverIdentity = c.verifyIdentity(sharedSecret);

      // try all the public keys
      for (KeyPair key : privateKeys) {
        c.proveIdentity(sharedSecret, key);
        if (c.readBoolean()) return serverIdentity; // succeeded
      }
      if (privateKeys.iterator().hasNext())
        throw new GeneralSecurityException("Authentication failed. No private key accepted.");
      else
        throw new GeneralSecurityException("No private key is available for use in authentication");
    } finally {
      c.close();
    }
  }
Ejemplo n.º 4
0
  public EstablishResult invoke(File workspace, VirtualChannel channel) throws IOException {

    out = listener.getLogger();

    logger = Logger.getLogger();

    StreamAppender app = null;
    if (pipe != null) {
      PrintStream toMaster = new PrintStream(pipe.getOut());
      app = new StreamAppender(toMaster);
      app.lockToCurrentThread();
      Logger.addAppender(app);
      app.setSettings(loggerSetting);
    } else if (pstream != null) {
      app = new StreamAppender(pstream);
      app.lockToCurrentThread();
      Logger.addAppender(app);
      app.setSettings(loggerSetting);
    }

    logger.debug("Starting remote deliver");

    this.workspace = workspace;

    /* Create the baseline object */
    Baseline baseline = null;
    try {
      baseline = Baseline.get(this.baseline).load();
    } catch (Exception e) {
      Logger.removeAppender(app);
      throw new IOException("Could not create Baseline object: " + e.getMessage(), e);
    }

    logger.debug(baseline + " created");

    /* Create the development stream object */
    /* Append vob to dev stream */

    Stream destinationStream = null;
    try {
      destinationStream = Stream.get(this.destinationstream).load();
    } catch (Exception e) {
      Logger.removeAppender(app);
      throw new IOException("Could not create destination Stream object: " + e.getMessage(), e);
    }

    logger.debug(destinationStream + " created");

    /* Make deliver view */
    try {
      snapview = makeDeliverView(destinationStream, workspace);
    } catch (Exception e) {
      Logger.removeAppender(app);
      throw new IOException("Could not create deliver view: " + e.getMessage(), e);
    }

    logger.debug("View: " + workspace);

    String diff = "";
    ClearCaseChangeset changeset = new ClearCaseChangeset();

    try {
      List<Activity> bldiff =
          Version.getBaselineDiff(destinationStream, baseline, true, snapview.getViewRoot());
      out.print(
          "["
              + Config.nameShort
              + "] Found "
              + bldiff.size()
              + " activit"
              + (bldiff.size() == 1 ? "y" : "ies")
              + ". ");

      int c = 0;
      for (Activity a : bldiff) {
        c += a.changeset.versions.size();
        for (Version version : a.changeset.versions) {
          changeset.addChange(version.getFullyQualifiedName(), version.getUser());
        }
      }
      out.println(c + " version" + (c == 1 ? "" : "s") + " involved");
      diff = Util.createChangelog(bldiff, baseline);
    } catch (Exception e1) {
      out.println("[" + Config.nameShort + "] Unable to create change log: " + e1.getMessage());
    }

    logger.debug("Changeset created");

    EstablishResult er = new EstablishResult(viewtag);
    er.setView(snapview);
    er.setMessage(diff);
    er.setChangeset(changeset);

    /* Make the deliver. Inline manipulation of er */
    deliver(baseline, destinationStream, er, forceDeliver, 2);

    /* End of deliver */
    Logger.removeAppender(app);
    return er;
  }