summaryrefslogtreecommitdiff
path: root/session.c
diff options
context:
space:
mode:
authorBen Lindstrom <mouring@eviladmin.org>2001-03-17 00:32:57 +0000
committerBen Lindstrom <mouring@eviladmin.org>2001-03-17 00:32:57 +0000
commit86fe8686b920b7da020b96aaf2303a7b596c36a4 (patch)
tree1576d713b9c1d1b8e5847198865fbd9662092422 /session.c
parenta4c57666b97433050287ebfca31735085c8ca0c1 (diff)
- markus@cvs.openbsd.org 2001/03/15 22:07:08
[session.c] pass Session to do_child + KNF
Diffstat (limited to 'session.c')
-rw-r--r--session.c120
1 files changed, 60 insertions, 60 deletions
diff --git a/session.c b/session.c
index 3c53f5cc1..5e6926b56 100644
--- a/session.c
+++ b/session.c
@@ -33,7 +33,7 @@
33 */ 33 */
34 34
35#include "includes.h" 35#include "includes.h"
36RCSID("$OpenBSD: session.c,v 1.59 2001/03/04 01:46:30 djm Exp $"); 36RCSID("$OpenBSD: session.c,v 1.60 2001/03/15 22:07:08 markus Exp $");
37 37
38#include "ssh.h" 38#include "ssh.h"
39#include "ssh1.h" 39#include "ssh1.h"
@@ -127,11 +127,7 @@ void session_proctitle(Session *s);
127void do_exec_pty(Session *s, const char *command, struct passwd * pw); 127void do_exec_pty(Session *s, const char *command, struct passwd * pw);
128void do_exec_no_pty(Session *s, const char *command, struct passwd * pw); 128void do_exec_no_pty(Session *s, const char *command, struct passwd * pw);
129void do_login(Session *s, const char *command); 129void do_login(Session *s, const char *command);
130 130void do_child(Session *s, const char *command);
131void
132do_child(const char *command, struct passwd * pw, const char *term,
133 const char *display, const char *auth_proto,
134 const char *auth_data, const char *ttyname);
135 131
136/* import */ 132/* import */
137extern ServerOptions options; 133extern ServerOptions options;
@@ -547,7 +543,7 @@ do_exec_no_pty(Session *s, const char *command, struct passwd * pw)
547#endif /* USE_PIPES */ 543#endif /* USE_PIPES */
548 544
549 /* Do processing for the child (exec command etc). */ 545 /* Do processing for the child (exec command etc). */
550 do_child(command, pw, NULL, s->display, s->auth_proto, s->auth_data, NULL); 546 do_child(s, command);
551 /* NOTREACHED */ 547 /* NOTREACHED */
552 } 548 }
553#ifdef HAVE_CYGWIN 549#ifdef HAVE_CYGWIN
@@ -645,8 +641,7 @@ do_exec_pty(Session *s, const char *command, struct passwd * pw)
645 do_login(s, command); 641 do_login(s, command);
646 642
647 /* Do common processing for the child, such as execing the command. */ 643 /* Do common processing for the child, such as execing the command. */
648 do_child(command, pw, s->term, s->display, s->auth_proto, 644 do_child(s, command);
649 s->auth_data, s->tty);
650 /* NOTREACHED */ 645 /* NOTREACHED */
651 } 646 }
652#ifdef HAVE_CYGWIN 647#ifdef HAVE_CYGWIN
@@ -1012,11 +1007,10 @@ void set_limits_from_userattr(char *user)
1012 * ids, and executing the command or shell. 1007 * ids, and executing the command or shell.
1013 */ 1008 */
1014void 1009void
1015do_child(const char *command, struct passwd * pw, const char *term, 1010do_child(Session *s, const char *command)
1016 const char *display, const char *auth_proto,
1017 const char *auth_data, const char *ttyname)
1018{ 1011{
1019 const char *shell, *hostname = NULL, *cp = NULL; 1012 const char *shell, *hostname = NULL, *cp = NULL;
1013 struct passwd * pw = s->pw;
1020 char buf[256]; 1014 char buf[256];
1021 char cmd[1024]; 1015 char cmd[1024];
1022 FILE *f = NULL; 1016 FILE *f = NULL;
@@ -1025,6 +1019,7 @@ do_child(const char *command, struct passwd * pw, const char *term,
1025 extern char **environ; 1019 extern char **environ;
1026 struct stat st; 1020 struct stat st;
1027 char *argv[10]; 1021 char *argv[10];
1022 int do_xauth = s->auth_proto != NULL && s->auth_data != NULL;
1028#ifdef WITH_IRIX_PROJECT 1023#ifdef WITH_IRIX_PROJECT
1029 prid_t projid; 1024 prid_t projid;
1030#endif /* WITH_IRIX_PROJECT */ 1025#endif /* WITH_IRIX_PROJECT */
@@ -1252,12 +1247,12 @@ do_child(const char *command, struct passwd * pw, const char *term,
1252 get_remote_ipaddr(), get_remote_port(), get_local_port()); 1247 get_remote_ipaddr(), get_remote_port(), get_local_port());
1253 child_set_env(&env, &envsize, "SSH_CLIENT", buf); 1248 child_set_env(&env, &envsize, "SSH_CLIENT", buf);
1254 1249
1255 if (ttyname) 1250 if (s->ttyfd != -1)
1256 child_set_env(&env, &envsize, "SSH_TTY", ttyname); 1251 child_set_env(&env, &envsize, "SSH_TTY", s->tty);
1257 if (term) 1252 if (s->term)
1258 child_set_env(&env, &envsize, "TERM", term); 1253 child_set_env(&env, &envsize, "TERM", s->term);
1259 if (display) 1254 if (s->display)
1260 child_set_env(&env, &envsize, "DISPLAY", display); 1255 child_set_env(&env, &envsize, "DISPLAY", s->display);
1261 if (original_command) 1256 if (original_command)
1262 child_set_env(&env, &envsize, "SSH_ORIGINAL_COMMAND", 1257 child_set_env(&env, &envsize, "SSH_ORIGINAL_COMMAND",
1263 original_command); 1258 original_command);
@@ -1363,60 +1358,64 @@ do_child(const char *command, struct passwd * pw, const char *term,
1363 if (!options.use_login) { 1358 if (!options.use_login) {
1364 if (stat(_PATH_SSH_USER_RC, &st) >= 0) { 1359 if (stat(_PATH_SSH_USER_RC, &st) >= 0) {
1365 if (debug_flag) 1360 if (debug_flag)
1366 fprintf(stderr, "Running %s %s\n", _PATH_BSHELL, _PATH_SSH_USER_RC); 1361 fprintf(stderr, "Running %s %s\n", _PATH_BSHELL,
1367 1362 _PATH_SSH_USER_RC);
1368 f = popen(_PATH_BSHELL " " _PATH_SSH_USER_RC, "w"); 1363 f = popen(_PATH_BSHELL " " _PATH_SSH_USER_RC, "w");
1369 if (f) { 1364 if (f) {
1370 if (auth_proto != NULL && auth_data != NULL) 1365 if (do_xauth)
1371 fprintf(f, "%s %s\n", auth_proto, auth_data); 1366 fprintf(f, "%s %s\n", s->auth_proto,
1367 s->auth_data);
1372 pclose(f); 1368 pclose(f);
1373 } else 1369 } else
1374 fprintf(stderr, "Could not run %s\n", _PATH_SSH_USER_RC); 1370 fprintf(stderr, "Could not run %s\n",
1371 _PATH_SSH_USER_RC);
1375 } else if (stat(_PATH_SSH_SYSTEM_RC, &st) >= 0) { 1372 } else if (stat(_PATH_SSH_SYSTEM_RC, &st) >= 0) {
1376 if (debug_flag) 1373 if (debug_flag)
1377 fprintf(stderr, "Running %s %s\n", _PATH_BSHELL, _PATH_SSH_SYSTEM_RC); 1374 fprintf(stderr, "Running %s %s\n", _PATH_BSHELL,
1375 _PATH_SSH_SYSTEM_RC);
1378 1376
1379 f = popen(_PATH_BSHELL " " _PATH_SSH_SYSTEM_RC, "w"); 1377 f = popen(_PATH_BSHELL " " _PATH_SSH_SYSTEM_RC, "w");
1380 if (f) { 1378 if (f) {
1381 if (auth_proto != NULL && auth_data != NULL) 1379 if (do_xauth)
1382 fprintf(f, "%s %s\n", auth_proto, auth_data); 1380 fprintf(f, "%s %s\n", s->auth_proto,
1381 s->auth_data);
1383 pclose(f); 1382 pclose(f);
1384 } else 1383 } else
1385 fprintf(stderr, "Could not run %s\n", _PATH_SSH_SYSTEM_RC); 1384 fprintf(stderr, "Could not run %s\n",
1386 } else if (options.xauth_location != NULL) { 1385 _PATH_SSH_SYSTEM_RC);
1386 } else if (do_xauth && options.xauth_location != NULL) {
1387 /* Add authority data to .Xauthority if appropriate. */ 1387 /* Add authority data to .Xauthority if appropriate. */
1388 if (auth_proto != NULL && auth_data != NULL) { 1388 char *screen = strchr(s->display, ':');
1389 char *screen = strchr(display, ':'); 1389
1390 if (debug_flag) { 1390 if (debug_flag) {
1391 fprintf(stderr,
1392 "Running %.100s add "
1393 "%.100s %.100s %.100s\n",
1394 options.xauth_location, s->display,
1395 s->auth_proto, s->auth_data);
1396 if (screen != NULL)
1391 fprintf(stderr, 1397 fprintf(stderr,
1392 "Running %.100s add %.100s %.100s %.100s\n", 1398 "Adding %.*s/unix%s %s %s\n",
1393 options.xauth_location, display, 1399 (int)(screen - s->display),
1394 auth_proto, auth_data); 1400 s->display, screen,
1395#ifndef NO_X11_UNIX_SOCKETS 1401 s->auth_proto, s->auth_data);
1396 if (screen != NULL) 1402 }
1397 fprintf(stderr, 1403 snprintf(cmd, sizeof cmd, "%s -q -",
1398 "Adding %.*s/unix%s %s %s\n", 1404 options.xauth_location);
1399 (int)(screen-display), display, 1405 f = popen(cmd, "w");
1400 screen, auth_proto, auth_data); 1406 if (f) {
1401#endif /* NO_X11_UNIX_SOCKETS */ 1407 fprintf(f, "add %s %s %s\n", s->display,
1402 } 1408 s->auth_proto, s->auth_data);
1403 snprintf(cmd, sizeof cmd, "%s -q -", 1409 if (screen != NULL)
1404 options.xauth_location); 1410 fprintf(f, "add %.*s/unix%s %s %s\n",
1405 f = popen(cmd, "w"); 1411 (int)(screen - s->display),
1406 if (f) { 1412 s->display, screen,
1407 fprintf(f, "add %s %s %s\n", display, 1413 s->auth_proto,
1408 auth_proto, auth_data); 1414 s->auth_data);
1409#ifndef NO_X11_UNIX_SOCKETS 1415 pclose(f);
1410 if (screen != NULL) 1416 } else {
1411 fprintf(f, "add %.*s/unix%s %s %s\n", 1417 fprintf(stderr, "Could not run %s\n",
1412 (int)(screen-display), display, 1418 cmd);
1413 screen, auth_proto, auth_data);
1414#endif /* NO_X11_UNIX_SOCKETS */
1415 pclose(f);
1416 } else {
1417 fprintf(stderr, "Could not run %s\n",
1418 cmd);
1419 }
1420 } 1419 }
1421 } 1420 }
1422 /* Get the last component of the shell name. */ 1421 /* Get the last component of the shell name. */
@@ -1439,9 +1438,10 @@ do_child(const char *command, struct passwd * pw, const char *term,
1439 * Check for mail if we have a tty and it was enabled 1438 * Check for mail if we have a tty and it was enabled
1440 * in server options. 1439 * in server options.
1441 */ 1440 */
1442 if (ttyname && options.check_mail) { 1441 if (s->ttyfd != -1 && options.check_mail) {
1443 char *mailbox; 1442 char *mailbox;
1444 struct stat mailstat; 1443 struct stat mailstat;
1444
1445 mailbox = getenv("MAIL"); 1445 mailbox = getenv("MAIL");
1446 if (mailbox != NULL) { 1446 if (mailbox != NULL) {
1447 if (stat(mailbox, &mailstat) != 0 || 1447 if (stat(mailbox, &mailstat) != 0 ||