示例#1
0
  @Override
  protected void doStart() throws Exception {
    String jettyUserEnvVariable = System.getenv("JETTY_USER");
    if (jettyUserEnvVariable != null)
      LOG.warn(
          "JETTY_USER set to: {}. If JETTY_USER is set, starting jetty as root and using "
              + "jetty-setuid to switch user won't work!!!",
          jettyUserEnvVariable);
    if (_umask > -1) {
      LOG.info("Setting umask=0" + Integer.toString(_umask, 8));
      SetUID.setumask(_umask);
    }

    if (_rlimitNoFiles != null) {
      LOG.info("Current " + SetUID.getrlimitnofiles());
      int success = SetUID.setrlimitnofiles(_rlimitNoFiles);
      if (success < 0) LOG.warn("Failed to set rlimit_nofiles, returned status " + success);
      LOG.info("Set " + SetUID.getrlimitnofiles());
    }

    if (_startServerAsPrivileged) {
      super.doStart();
      if (_gid != 0) {
        LOG.info("Setting GID=" + _gid);
        SetUID.setgid(_gid);
      }
      if (_uid != 0) {
        LOG.info("Setting UID=" + _uid);
        SetUID.setuid(_uid);
        Passwd pw = SetUID.getpwuid(_uid);
        System.setProperty("user.name", pw.getPwName());
        System.setProperty("user.home", pw.getPwDir());
      }
    } else {
      Connector[] connectors = getConnectors();
      for (int i = 0; connectors != null && i < connectors.length; i++) {
        connectors[i].start();
      }

      if (_gid != 0) {
        LOG.info("Setting GID=" + _gid);
        SetUID.setgid(_gid);
      }

      if (_uid != 0) {
        LOG.info("Setting UID=" + _uid);
        SetUID.setuid(_uid);
        Passwd pw = SetUID.getpwuid(_uid);
        System.setProperty("user.name", pw.getPwName());
        System.setProperty("user.home", pw.getPwDir());
      }

      super.doStart();
    }
  }
示例#2
0
 public String getUsername() {
   Passwd passwd = SetUID.getpwuid(_uid);
   return passwd.getPwName();
 }
示例#3
0
 public void setUsername(String username) {
   Passwd passwd = SetUID.getpwnam(username);
   _uid = passwd.getPwUid();
 }