summaryrefslogtreecommitdiff
path: root/session.c
diff options
context:
space:
mode:
Diffstat (limited to 'session.c')
-rw-r--r--session.c49
1 files changed, 49 insertions, 0 deletions
diff --git a/session.c b/session.c
index d5faf4cf3..a537efdd4 100644
--- a/session.c
+++ b/session.c
@@ -41,6 +41,12 @@ RCSID("$OpenBSD: session.c,v 1.35 2000/09/04 19:07:21 markus Exp $");
41# include <siad.h> 41# include <siad.h>
42#endif 42#endif
43 43
44#ifdef HAVE_CYGWIN
45#include <windows.h>
46#include <sys/cygwin.h>
47#define is_winnt (GetVersion() < 0x80000000)
48#endif
49
44/* AIX limits */ 50/* AIX limits */
45#if defined(HAVE_GETUSERATTR) && !defined(S_UFSIZE_HARD) && defined(S_UFSIZE) 51#if defined(HAVE_GETUSERATTR) && !defined(S_UFSIZE_HARD) && defined(S_UFSIZE)
46# define S_UFSIZE_HARD S_UFSIZE "_hard" 52# define S_UFSIZE_HARD S_UFSIZE "_hard"
@@ -503,6 +509,10 @@ do_exec_no_pty(Session *s, const char *command, struct passwd * pw)
503 do_child(command, pw, NULL, s->display, s->auth_proto, s->auth_data, NULL); 509 do_child(command, pw, NULL, s->display, s->auth_proto, s->auth_data, NULL);
504 /* NOTREACHED */ 510 /* NOTREACHED */
505 } 511 }
512#ifdef HAVE_CYGWIN
513 if (is_winnt)
514 cygwin_set_impersonation_token(INVALID_HANDLE_VALUE);
515#endif
506 if (pid < 0) 516 if (pid < 0)
507 packet_disconnect("fork failed: %.100s", strerror(errno)); 517 packet_disconnect("fork failed: %.100s", strerror(errno));
508 s->pid = pid; 518 s->pid = pid;
@@ -594,6 +604,10 @@ do_exec_pty(Session *s, const char *command, struct passwd * pw)
594 s->auth_data, s->tty); 604 s->auth_data, s->tty);
595 /* NOTREACHED */ 605 /* NOTREACHED */
596 } 606 }
607#ifdef HAVE_CYGWIN
608 if (is_winnt)
609 cygwin_set_impersonation_token(INVALID_HANDLE_VALUE);
610#endif
597 if (pid < 0) 611 if (pid < 0)
598 packet_disconnect("fork failed: %.100s", strerror(errno)); 612 packet_disconnect("fork failed: %.100s", strerror(errno));
599 s->pid = pid; 613 s->pid = pid;
@@ -973,7 +987,11 @@ do_child(const char *command, struct passwd * pw, const char *term,
973 exit(1); 987 exit(1);
974 } 988 }
975#else /* HAVE_OSF_SIA */ 989#else /* HAVE_OSF_SIA */
990#ifdef HAVE_CYGWIN
991 if (is_winnt) {
992#else
976 if (getuid() == 0 || geteuid() == 0) { 993 if (getuid() == 0 || geteuid() == 0) {
994#endif
977# ifdef HAVE_GETUSERATTR 995# ifdef HAVE_GETUSERATTR
978 set_limits_from_userattr(pw->pw_name); 996 set_limits_from_userattr(pw->pw_name);
979# endif /* HAVE_GETUSERATTR */ 997# endif /* HAVE_GETUSERATTR */
@@ -1018,6 +1036,9 @@ do_child(const char *command, struct passwd * pw, const char *term,
1018 } 1036 }
1019#endif /* HAVE_OSF_SIA */ 1037#endif /* HAVE_OSF_SIA */
1020 1038
1039#ifdef HAVE_CYGWIN
1040 if (is_winnt)
1041#endif
1021 if (getuid() != pw->pw_uid || geteuid() != pw->pw_uid) 1042 if (getuid() != pw->pw_uid || geteuid() != pw->pw_uid)
1022 fatal("Failed to set uids to %u.", (u_int) pw->pw_uid); 1043 fatal("Failed to set uids to %u.", (u_int) pw->pw_uid);
1023 } 1044 }
@@ -1047,6 +1068,22 @@ do_child(const char *command, struct passwd * pw, const char *term,
1047 env = xmalloc(envsize * sizeof(char *)); 1068 env = xmalloc(envsize * sizeof(char *));
1048 env[0] = NULL; 1069 env[0] = NULL;
1049 1070
1071#ifdef HAVE_CYGWIN
1072 /*
1073 * The Windows environment contains some setting which are
1074 * important for a running system. They must not be dropped.
1075 */
1076 {
1077 char **ep;
1078 for (ep = environ; *ep; ++ep) {
1079 char *esp = strchr(*ep, '=');
1080 *esp = '\0';
1081 child_set_env(&env, &envsize, *ep, esp + 1);
1082 *esp = '=';
1083 }
1084 }
1085#endif
1086
1050 if (!options.use_login) { 1087 if (!options.use_login) {
1051 /* Set basic environment. */ 1088 /* Set basic environment. */
1052 child_set_env(&env, &envsize, "USER", pw->pw_name); 1089 child_set_env(&env, &envsize, "USER", pw->pw_name);
@@ -1056,8 +1093,16 @@ do_child(const char *command, struct passwd * pw, const char *term,
1056 (void) setusercontext(lc, pw, pw->pw_uid, LOGIN_SETPATH); 1093 (void) setusercontext(lc, pw, pw->pw_uid, LOGIN_SETPATH);
1057 child_set_env(&env, &envsize, "PATH", getenv("PATH")); 1094 child_set_env(&env, &envsize, "PATH", getenv("PATH"));
1058#else 1095#else
1096#ifndef HAVE_CYGWIN
1097 /*
1098 * There's no standard path on Windows. The path contains
1099 * important components pointing to the system directories,
1100 * needed for loading shared libraries. So the path better
1101 * remains intact here.
1102 */
1059 child_set_env(&env, &envsize, "PATH", _PATH_STDPATH); 1103 child_set_env(&env, &envsize, "PATH", _PATH_STDPATH);
1060#endif 1104#endif
1105#endif
1061 1106
1062 snprintf(buf, sizeof buf, "%.200s/%.50s", 1107 snprintf(buf, sizeof buf, "%.200s/%.50s",
1063 _PATH_MAILDIR, pw->pw_name); 1108 _PATH_MAILDIR, pw->pw_name);
@@ -1234,11 +1279,13 @@ do_child(const char *command, struct passwd * pw, const char *term,
1234 "Running %.100s add %.100s %.100s %.100s\n", 1279 "Running %.100s add %.100s %.100s %.100s\n",
1235 options.xauth_location, display, 1280 options.xauth_location, display,
1236 auth_proto, auth_data); 1281 auth_proto, auth_data);
1282#ifndef HAVE_CYGWIN
1237 if (screen != NULL) 1283 if (screen != NULL)
1238 fprintf(stderr, 1284 fprintf(stderr,
1239 "Adding %.*s/unix%s %s %s\n", 1285 "Adding %.*s/unix%s %s %s\n",
1240 (int)(screen-display), display, 1286 (int)(screen-display), display,
1241 screen, auth_proto, auth_data); 1287 screen, auth_proto, auth_data);
1288#endif
1242 } 1289 }
1243 snprintf(cmd, sizeof cmd, "%s -q -", 1290 snprintf(cmd, sizeof cmd, "%s -q -",
1244 options.xauth_location); 1291 options.xauth_location);
@@ -1246,10 +1293,12 @@ do_child(const char *command, struct passwd * pw, const char *term,
1246 if (f) { 1293 if (f) {
1247 fprintf(f, "add %s %s %s\n", display, 1294 fprintf(f, "add %s %s %s\n", display,
1248 auth_proto, auth_data); 1295 auth_proto, auth_data);
1296#ifndef HAVE_CYGWIN
1249 if (screen != NULL) 1297 if (screen != NULL)
1250 fprintf(f, "add %.*s/unix%s %s %s\n", 1298 fprintf(f, "add %.*s/unix%s %s %s\n",
1251 (int)(screen-display), display, 1299 (int)(screen-display), display,
1252 screen, auth_proto, auth_data); 1300 screen, auth_proto, auth_data);
1301#endif
1253 pclose(f); 1302 pclose(f);
1254 } else { 1303 } else {
1255 fprintf(stderr, "Could not run %s\n", 1304 fprintf(stderr, "Could not run %s\n",