comparison svr-session.c @ 641:2b1bb792cd4d dropbear-tfm

- Update tfm changes to current default tip
author Matt Johnston <matt@ucc.asn.au>
date Mon, 21 Nov 2011 19:52:28 +0800
parents b5cc8878d5ec
children 0ad95abf8d3c
comparison
equal deleted inserted replaced
640:76097ec1a29a 641:2b1bb792cd4d
72 &svr_chan_tcpdirect, 72 &svr_chan_tcpdirect,
73 #endif 73 #endif
74 NULL /* Null termination is mandatory. */ 74 NULL /* Null termination is mandatory. */
75 }; 75 };
76 76
77 void svr_session(int sock, int childpipe, 77 void svr_session(int sock, int childpipe) {
78 char* remotehost, char *addrstring) { 78 char *host, *port;
79 79 size_t len;
80 reseedrandom(); 80 reseedrandom();
81 81
82 crypto_init(); 82 crypto_init();
83 common_session_init(sock, sock, remotehost); 83 common_session_init(sock, sock);
84 84
85 /* Initialise server specific parts of the session */ 85 /* Initialise server specific parts of the session */
86 svr_ses.childpipe = childpipe; 86 svr_ses.childpipe = childpipe;
87 svr_ses.addrstring = addrstring; 87 #ifdef __uClinux__
88 svr_ses.server_pid = getpid();
89 #endif
88 svr_authinitialise(); 90 svr_authinitialise();
89 chaninitialise(svr_chantypes); 91 chaninitialise(svr_chantypes);
90 svr_chansessinitialise(); 92 svr_chansessinitialise();
91 93
92 ses.connect_time = time(NULL); 94 ses.connect_time = time(NULL);
93 95
96 /* for logging the remote address */
97 get_socket_address(ses.sock_in, NULL, NULL, &host, &port, 0);
98 len = strlen(host) + strlen(port) + 2;
99 svr_ses.addrstring = m_malloc(len);
100 snprintf(svr_ses.addrstring, len, "%s:%s", host, port);
101 m_free(host);
102 m_free(port);
103
104 get_socket_address(ses.sock_in, NULL, NULL,
105 &svr_ses.remotehost, NULL, 1);
106
94 /* set up messages etc */ 107 /* set up messages etc */
95 ses.remoteclosed = svr_remoteclosed; 108 ses.remoteclosed = svr_remoteclosed;
96 109
97 /* packet handlers */ 110 /* packet handlers */
98 ses.packettypes = svr_packettypes; 111 ses.packettypes = svr_packettypes;
123 char fmtbuf[300]; 136 char fmtbuf[300];
124 137
125 if (!sessinitdone) { 138 if (!sessinitdone) {
126 /* before session init */ 139 /* before session init */
127 snprintf(fmtbuf, sizeof(fmtbuf), 140 snprintf(fmtbuf, sizeof(fmtbuf),
128 "premature exit: %s", format); 141 "Premature exit: %s", format);
129 } else if (ses.authstate.authdone) { 142 } else if (ses.authstate.authdone) {
130 /* user has authenticated */ 143 /* user has authenticated */
131 snprintf(fmtbuf, sizeof(fmtbuf), 144 snprintf(fmtbuf, sizeof(fmtbuf),
132 "exit after auth (%s): %s", 145 "Exit (%s): %s",
133 ses.authstate.pw_name, format); 146 ses.authstate.pw_name, format);
134 } else if (ses.authstate.pw_name) { 147 } else if (ses.authstate.pw_name) {
135 /* we have a potential user */ 148 /* we have a potential user */
136 snprintf(fmtbuf, sizeof(fmtbuf), 149 snprintf(fmtbuf, sizeof(fmtbuf),
137 "exit before auth (user '%s', %d fails): %s", 150 "Exit before auth (user '%s', %d fails): %s",
138 ses.authstate.pw_name, ses.authstate.failcount, format); 151 ses.authstate.pw_name, ses.authstate.failcount, format);
139 } else { 152 } else {
140 /* before userauth */ 153 /* before userauth */
141 snprintf(fmtbuf, sizeof(fmtbuf), 154 snprintf(fmtbuf, sizeof(fmtbuf),
142 "exit before auth: %s", format); 155 "Exit before auth: %s", format);
143 } 156 }
144 157
145 _dropbear_log(LOG_INFO, fmtbuf, param); 158 _dropbear_log(LOG_INFO, fmtbuf, param);
146 159
147 /* free potential public key options */ 160 #ifdef __uClinux__
148 svr_pubkey_options_cleanup(); 161 /* only the main server process should cleanup - we don't want
149 162 * forked children doing that */
150 /* must be after we've done with username etc */ 163 if (svr_ses.server_pid == getpid())
151 common_session_cleanup(); 164 #else
165 if (1)
166 #endif
167 {
168 /* free potential public key options */
169 svr_pubkey_options_cleanup();
170
171 /* must be after we've done with username etc */
172 common_session_cleanup();
173 }
152 174
153 exit(exitcode); 175 exit(exitcode);
154 176
155 } 177 }
156 178
181 struct tm * local_tm = NULL; 203 struct tm * local_tm = NULL;
182 timesec = time(NULL); 204 timesec = time(NULL);
183 local_tm = localtime(&timesec); 205 local_tm = localtime(&timesec);
184 if (local_tm == NULL 206 if (local_tm == NULL
185 || strftime(datestr, sizeof(datestr), "%b %d %H:%M:%S", 207 || strftime(datestr, sizeof(datestr), "%b %d %H:%M:%S",
186 localtime(&timesec)) == 0) 208 local_tm) == 0)
187 { 209 {
188 /* upon failure, just print the epoch-seconds time. */ 210 /* upon failure, just print the epoch-seconds time. */
189 snprintf(datestr, sizeof(datestr), "%d", (int)timesec); 211 snprintf(datestr, sizeof(datestr), "%d", (int)timesec);
190 } 212 }
191 fprintf(stderr, "[%d] %s %s\n", getpid(), datestr, printbuf); 213 fprintf(stderr, "[%d] %s %s\n", getpid(), datestr, printbuf);