-#endif /* USE_PAM */
-
- /* Set login name, uid, gid, and groups. */
- /* Login(1) does this as well, and it needs uid 0 for the "-h"
- switch, so we let login(1) to this for us. */
- if (!options.use_login) {
-#ifdef HAVE_OSF_SIA
- session_setup_sia(pw->pw_name, s->ttyfd == -1 ? NULL : s->tty);
-#else /* HAVE_OSF_SIA */
-#ifdef HAVE_CYGWIN
- if (is_winnt) {
-#else
- if (getuid() == 0 || geteuid() == 0) {
-#endif
-# ifdef HAVE_GETUSERATTR
- set_limits_from_userattr(pw->pw_name);
-# endif /* HAVE_GETUSERATTR */
-# ifdef HAVE_LOGIN_CAP
- if (setusercontext(lc, pw, pw->pw_uid,
- (LOGIN_SETALL & ~LOGIN_SETPATH)) < 0) {
- perror("unable to set user context");
- exit(1);
- }
-#ifdef BSD_AUTH
- if (auth_approval(NULL, lc, pw->pw_name, "ssh") <= 0) {
- error("approval failure for %s", pw->pw_name);
- fprintf(stderr, "Approval failure");
- exit(1);
- }
-#endif
-# else /* HAVE_LOGIN_CAP */
-#if defined(HAVE_GETLUID) && defined(HAVE_SETLUID)
- /* Sets login uid for accounting */
- if (getluid() == -1 && setluid(pw->pw_uid) == -1)
- error("setluid: %s", strerror(errno));
-#endif /* defined(HAVE_GETLUID) && defined(HAVE_SETLUID) */
-
- if (setlogin(pw->pw_name) < 0)
- error("setlogin failed: %s", strerror(errno));
- if (setgid(pw->pw_gid) < 0) {
- perror("setgid");
- exit(1);
- }
- /* Initialize the group list. */
- if (initgroups(pw->pw_name, pw->pw_gid) < 0) {
- perror("initgroups");
- exit(1);
- }
- endgrent();
-# ifdef USE_PAM
- /*
- * PAM credentials may take the form of
- * supplementary groups. These will have been
- * wiped by the above initgroups() call.
- * Reestablish them here.
- */
- do_pam_setcred(0);
-# endif /* USE_PAM */
-# ifdef WITH_IRIX_JOBS
- jid = jlimit_startjob(pw->pw_name, pw->pw_uid, "interactive");
- if (jid == -1) {
- fatal("Failed to create job container: %.100s",
- strerror(errno));
- }
-# endif /* WITH_IRIX_JOBS */
-# ifdef WITH_IRIX_ARRAY
- /* initialize array session */
- if (jid == 0) {
- if (newarraysess() != 0)
- fatal("Failed to set up new array session: %.100s",
- strerror(errno));
- }
-# endif /* WITH_IRIX_ARRAY */
-# ifdef WITH_IRIX_PROJECT
- /* initialize irix project info */
- if ((projid = getdfltprojuser(pw->pw_name)) == -1) {
- debug("Failed to get project id, using projid 0");
- projid = 0;
- }
- if (setprid(projid))
- fatal("Failed to initialize project %d for %s: %.100s",
- (int)projid, pw->pw_name, strerror(errno));
-# endif /* WITH_IRIX_PROJECT */
-#ifdef WITH_IRIX_AUDIT
- if (sysconf(_SC_AUDIT)) {
- debug("Setting sat id to %d", (int) pw->pw_uid);
- if (satsetid(pw->pw_uid))
- debug("error setting satid: %.100s", strerror(errno));
- }
-#endif /* WITH_IRIX_AUDIT */
-
-#ifdef _AIX
- /*
- * AIX has a "usrinfo" area where logname and
- * other stuff is stored - a few applications
- * actually use this and die if it's not set
- */
- if (s->ttyfd == -1)
- s->tty[0] = '\0';
- cp = xmalloc(22 + strlen(s->tty) +
- 2 * strlen(pw->pw_name));
- i = sprintf(cp, "LOGNAME=%s%cNAME=%s%cTTY=%s%c%c",
- pw->pw_name, 0, pw->pw_name, 0, s->tty, 0, 0);
- if (usrinfo(SETUINFO, cp, i) == -1)
- fatal("Couldn't set usrinfo: %s",
- strerror(errno));
- debug3("AIX/UsrInfo: set len %d", i);
- xfree(cp);
-#endif