- Timestamp:
- 03/26/10 03:50:38 (2 years ago)
- Location:
- trunk
- Files:
-
- 2 modified
-
.anjuta_sym_db.db (modified) (previous)
-
src/ddtelnetd/ddtelnetd.c (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/ddtelnetd/ddtelnetd.c
r145 r151 76 76 } 77 77 78 int ignore = FALSE;78 int send_iac(unsigned char command, int option); 79 79 80 80 int 81 81 remove_iacs(unsigned char *in, int len, unsigned char* out, int* out_count) { 82 82 83 unsigned char *end = in + len; 83 84 unsigned char* orig_in = in; 84 85 static int ignore = FALSE; 86 85 87 while (in < end) { 86 88 if (*in != IAC) { … … 89 91 *out_count = *out_count + 1; 90 92 } 93 else { 94 in++; 95 } 91 96 } 92 97 else { … … 95 100 return 1; 96 101 } 102 103 if(ignore && *(in+1) != SE) { 104 send_iac(*(in+1), -1); 105 in += 2; 106 continue; 107 } 108 109 syslog(LOG_INFO, "got real IAC, %d, %d", *(in+1), *(in+2)); 97 110 switch(*(in+1)) { 98 111 case IAC: … … 114 127 case SB: 115 128 ignore = TRUE; 129 syslog(LOG_INFO, "Negotiation began"); 130 in += 2; 116 131 break; 117 132 case SE: 118 133 ignore = FALSE; 119 134 syslog(LOG_INFO, "Negotiation completed"); 135 in += 2; 120 136 break; 121 137 case NOP: … … 128 144 in += 2; 129 145 break; 146 case EC: 147 in += 2; 148 *out = '\b'; 149 ++out; 150 *out_count = *out_count + 1; 151 break; 130 152 default: 131 153 syslog(LOG_INFO, "Unknown IAC arg: %d", *(in+1)); 154 in += 2; 132 155 break; 133 156 } … … 141 164 int send_iac(unsigned char command, int option) 142 165 { 143 char buf[ 4];166 char buf[3]; 144 167 int w; 145 sprintf(buf, "%c%c%c", (char) IAC, (char) command, (char) option); 146 w = write(OUTFD, buf, 3); 168 169 buf[0] = IAC; 170 buf[1] = command; 171 buf[2] = option; 172 173 w = write(OUTFD, buf, option == -1 ? 2 : 3); 174 147 175 return w; 148 176 } … … 197 225 198 226 /// Michael Griffin Get Host Address 199 /// From Remote Connection .227 /// From Remote Connection, Pass Like in.telnetd does. 200 228 201 229 fromlen = sizeof (from); … … 238 266 exit(1); 239 267 } 240 if(send_iac(DONT, TELOPT_NAWS) < 0) { 268 if(send_iac(WONT, TELOPT_NAWS) < 0) { 269 exit(1); 270 } 271 if(send_iac(WILL, TELOPT_BINARY) < 0) { 241 272 exit(1); 242 273 } … … 258 289 } 259 290 else if(pid == -1) { 260 closelog();261 exit(1);291 closelog(); 292 exit(1); 262 293 } 263 294 else { 264 shell_pid = pid;295 shell_pid = pid; 265 296 } 266 297 … … 274 305 275 306 selret = select(ptyfd + 1, &rdfdset, NULL, 0, 0); 276 277 if (selret < 0)307 308 if (selret <= 0) 278 309 break; 279 310 280 311 if (FD_ISSET(ptyfd, &rdfdset)) { 281 unsigned char* ptr1, *ptr2; 312 unsigned char* ptr1, *ptr2; 282 313 int iacs = 0; 283 int r;284 285 r = read(ptyfd, tmpbuf, BUFSIZE / 2);286 287 if ( (r < 0 && errno != EINTR)) {314 int r; 315 316 r = read(ptyfd, tmpbuf, BUFSIZE / 2); 317 318 if (r <= 0) { 288 319 break; 289 320 } … … 303 334 } 304 335 } 305 306 if(write(OUTFD, buf, r + iacs) < 0) {336 337 if(write(OUTFD, buf, r + iacs) != (r + iacs)) { 307 338 break; 308 339 } … … 314 345 315 346 r = read(INFD, buf + new_offset, BUFSIZE - new_offset); 316 317 if (r == 0 || (r < 0 && errno != EINTR)) {347 348 if (r <= 0) { 318 349 break; 319 350 } 320 351 321 352 new_offset = remove_iacs(buf, r + new_offset, tmpbuf, &out_count); 322 if(write(ptyfd, tmpbuf, out_count) < 0) { 353 354 if(write(ptyfd, tmpbuf, out_count) != out_count) { 323 355 break; 324 356 } … … 327 359 } while (1); 328 360 329 /* We will tell daydream to terminate probably (carrier lost) */330 kill(shell_pid, SIGTERM);331 wait4(shell_pid, NULL, 0, NULL);332 361 close(ptyfd); 362 363 syslog(LOG_INFO, "Closed connection"); 333 364 closelog(); 334 335 syslog(LOG_INFO, "Closed connection");336 365 366 _exit(0); 367 337 368 return 1; 338 369 }
Enthral BBS Software for *nix/bsd/osx