Mercurial > dropbear
comparison svr-chansession.c @ 7:425ed5c20157
Chantype handling is sorted
author | Matt Johnston <matt@ucc.asn.au> |
---|---|
date | Wed, 02 Jun 2004 04:59:49 +0000 |
parents | ab00ef513e97 |
children | 7f77962de998 |
comparison
equal
deleted
inserted
replaced
6:ab00ef513e97 | 7:425ed5c20157 |
---|---|
54 static void chansessionrequest(struct Channel *channel); | 54 static void chansessionrequest(struct Channel *channel); |
55 | 55 |
56 static void send_exitsignalstatus(struct Channel *channel); | 56 static void send_exitsignalstatus(struct Channel *channel); |
57 static int sesscheckclose(struct Channel *channel); | 57 static int sesscheckclose(struct Channel *channel); |
58 | 58 |
59 const struct ChanType svrchansess = { | |
60 0, /* sepfds */ | |
61 "session", /* name */ | |
62 newchansess, /* inithandler */ | |
63 sesscheckclose, /* checkclosehandler */ | |
64 chansessionrequest, /* reqhandler */ | |
65 closechansess, /* closehandler */ | |
66 }; | |
67 | |
68 | |
69 | 59 |
70 /* required to clear environment */ | 60 /* required to clear environment */ |
71 extern char** environ; | 61 extern char** environ; |
72 | 62 |
73 static int sesscheckclose(struct Channel *channel) { | 63 static int sesscheckclose(struct Channel *channel) { |
74 struct ChanSess *chansess = (struct ChanSess*)channel->typedata; | 64 struct ChanSess *chansess = (struct ChanSess*)channel->typedata; |
75 return chansess->exited; | 65 return chansess->exited; |
76 } | |
77 | |
78 /* Set up the general chansession environment, in particular child-exit | |
79 * handling */ | |
80 void svr_chansessinitialise() { | |
81 | |
82 struct sigaction sa_chld; | |
83 | |
84 /* single child process intially */ | |
85 svr_ses.childpids = (struct ChildPid*)m_malloc(sizeof(struct ChildPid)); | |
86 svr_ses.childpids[0].pid = -1; /* unused */ | |
87 svr_ses.childpids[0].chansess = NULL; | |
88 svr_ses.childpidsize = 1; | |
89 sa_chld.sa_handler = sesssigchild_handler; | |
90 sa_chld.sa_flags = SA_NOCLDSTOP; | |
91 if (sigaction(SIGCHLD, &sa_chld, NULL) < 0) { | |
92 dropbear_exit("signal() error"); | |
93 } | |
94 | |
95 } | 66 } |
96 | 67 |
97 /* handler for childs exiting, store the state for return to the client */ | 68 /* handler for childs exiting, store the state for return to the client */ |
98 static void sesssigchild_handler(int dummy) { | 69 static void sesssigchild_handler(int dummy) { |
99 | 70 |
252 unsigned int i; | 223 unsigned int i; |
253 struct logininfo *li; | 224 struct logininfo *li; |
254 | 225 |
255 chansess = (struct ChanSess*)channel->typedata; | 226 chansess = (struct ChanSess*)channel->typedata; |
256 | 227 |
257 send_exitsignalstatus(chansess); | 228 send_exitsignalstatus(channel); |
258 | 229 |
259 TRACE(("enter closechansess")); | 230 TRACE(("enter closechansess")); |
260 if (chansess == NULL) { | 231 if (chansess == NULL) { |
261 TRACE(("leave closechansess: chansess == NULL")); | 232 TRACE(("leave closechansess: chansess == NULL")); |
262 return; | 233 return; |
909 | 880 |
910 /* only reached on error */ | 881 /* only reached on error */ |
911 dropbear_exit("child failed"); | 882 dropbear_exit("child failed"); |
912 } | 883 } |
913 | 884 |
885 const struct ChanType svrchansess = { | |
886 0, /* sepfds */ | |
887 "session", /* name */ | |
888 newchansess, /* inithandler */ | |
889 sesscheckclose, /* checkclosehandler */ | |
890 chansessionrequest, /* reqhandler */ | |
891 closechansess, /* closehandler */ | |
892 }; | |
893 | |
894 | |
895 /* Set up the general chansession environment, in particular child-exit | |
896 * handling */ | |
897 void svr_chansessinitialise() { | |
898 | |
899 struct sigaction sa_chld; | |
900 | |
901 /* single child process intially */ | |
902 svr_ses.childpids = (struct ChildPid*)m_malloc(sizeof(struct ChildPid)); | |
903 svr_ses.childpids[0].pid = -1; /* unused */ | |
904 svr_ses.childpids[0].chansess = NULL; | |
905 svr_ses.childpidsize = 1; | |
906 sa_chld.sa_handler = sesssigchild_handler; | |
907 sa_chld.sa_flags = SA_NOCLDSTOP; | |
908 if (sigaction(SIGCHLD, &sa_chld, NULL) < 0) { | |
909 dropbear_exit("signal() error"); | |
910 } | |
911 | |
912 } | |
913 | |
914 /* add a new environment variable, allocating space for the entry */ | 914 /* add a new environment variable, allocating space for the entry */ |
915 void addnewvar(const char* param, const char* var) { | 915 void addnewvar(const char* param, const char* var) { |
916 | 916 |
917 char* newvar; | 917 char* newvar; |
918 int plen, vlen; | 918 int plen, vlen; |