Changeset 85e24a3 in rtems for c/src/libnetworking/rtems_servers/ftpd.c
- Timestamp:
- 04/02/99 14:39:19 (24 years ago)
- Branches:
- 4.10, 4.11, 4.8, 4.9, 5, master
- Children:
- bea606a
- Parents:
- 5345873
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
c/src/libnetworking/rtems_servers/ftpd.c
r5345873 r85e24a3 1 /* 2 * FTP Server Daemon 1 /* FIXME: 1. Parse command is a hack. We can do better. 2 * 2. chdir is a hack. We can do better. 3 * 3. PWD doesn't work. 4 * 4. Some sort of access control? 5 * 6 * FTP Server Daemon 3 7 * 4 8 * Submitted by: Jake Janovetz <janovetz@tempest.ece.uiuc.edu> … … 7 11 */ 8 12 9 /*10 * Current state:11 * To untar, put as "untar"12 * CWD uses chdir13 * This is bad due to global setting of chdir.14 *15 * Stored files come into RAM and are saved later. This is an artifact16 * of a previous implementation (no filesystem -- had to do stuff with17 * the "files" later). This can be eliminated once all of Jake's stuff18 * is moved to devices/filesystems.19 *20 * CLOSE(S) doesn't seem to work. This causes problems in21 * several areas. It lets too many file descriptors pile up22 * and it doesn't seem to flush the stream.23 *24 * Is 'recv' what I want to use to get commands from the control port?25 *26 */27 28 13 /************************************************************************** 29 14 * ftpd.c * … … 32 17 * * 33 18 * This file contains the daemon which services requests that appear * 34 * on the 'FTP' port. This server is compatible with FTP, but it * 35 * also provides services specific to the Erithacus system. * 36 * This server is started at boot-time and runs forever. * 19 * on the FTP port. This server is compatible with FTP, but it * 20 * also provides 'hooks' to make it usable in situations where files * 21 * are not used/necessary. Once the server is started, it runs * 22 * forever. * 23 * * 37 24 * * 38 25 * Organization: * … … 44 31 * is complete, the session task deletes itself. The daemon still * 45 32 * runs, however. * 46 * *47 * Implementation Notes: *48 * *49 * The 'current working directory' implementation utilizes the *50 * RTEMS filesystem cwd. This is no good since other processes *51 * inherit the same cwd. *52 33 * * 53 34 * * … … 71 52 * * 72 53 * * 73 * *74 54 * The public routines contained in this file are: * 75 55 * * 76 * FTPD_Start - Starts the server daemon, then returns to its caller. * 56 * rtems_initialize_ftpd_start - Starts the server daemon, then * 57 * returns to its caller. * 77 58 * * 78 59 * * 79 60 * The private routines contained in this file are: * 80 61 * * 81 * FTPD_SendReply - Sends a reply code and text through the control*82 * port.*83 * FTPD_CommandStore - Performs the "STOR" command.*84 * FTPD_CommandList - Performs the "LIST" command.*85 * FTPD_CommandPort - Opens a data port (the "PORT" command).*86 * FTPD_ParseCommand - Parses an incoming command.*87 * FTPD_Session - Begins a service session.*88 * FTPD_Daemon - Listens on the FTP port for service requests.*89 * 90 * 62 * rtems_ftpd_send_reply - Sends a reply code and text through the * 63 * control port. * 64 * rtems_ftpd_command_retrieve - Performs to "RETR" command. * 65 * rtems_ftpd_command_store - Performs the "STOR" command. * 66 * rtems_ftpd_command_list - Performs the "LIST" command. * 67 * rtems_ftpd_command_port - Opens a data port (the "PORT" command). * 68 * rtems_ftpd_parse_command - Parses an incoming command. * 69 * rtmes_ftpd_session - Begins a service session. * 70 * rtems_ftpd_daemon - Listens on the FTP port for service * 71 * requests. * 91 72 *------------------------------------------------------------------------* 92 * *93 73 * Jake Janovetz * 94 74 * University of Illinois * 95 75 * 1406 West Green Street * 96 76 * Urbana IL 61801 * 97 * *98 77 ************************************************************************** 99 78 * Change History: * 100 79 * 12/01/97 - Creation (JWJ) * 101 80 *************************************************************************/ 102 103 /* Revision Control Information:104 *105 * $Source$106 * $Id$107 * $Log$108 * Revision 1.3 1998/05/19 21:28:17 erithacus109 * Update control socket to file I/O.110 *111 * Revision 1.2 1998/05/19 20:13:50 erithacus112 * Remodeled to be entirely reentrant.113 *114 *115 */116 117 81 118 82 #include <stdio.h> … … 134 98 135 99 #include "ftpd.h" 136 #include "untar.h" 137 100 101 102 extern struct rtems_ftpd_configuration rtems_ftpd_configuration; 138 103 139 104 /************************************************************************** … … 165 130 166 131 /************************************************************************** 167 * Maximum buffer size for use by the transfer protocol.168 * This will be eliminated when the filesystem is complete enough that169 * we don't have to store the received data until we have something to170 * do with it.171 *************************************************************************/172 #define FTPD_MAX_RECEIVESIZE (512*1024)173 174 /**************************************************************************175 132 * SessionInfo structure. 176 133 * … … 181 138 { 182 139 struct sockaddr_in data_addr; /* Data address for PORT commands */ 183 int ctrl_sock; /* Control connection socker*/140 FILE *ctrl_fp; /* File pointer for control connection */ 184 141 char cwd[255]; /* Current working directory */ 185 142 /* Login -- future use -- */ … … 188 145 189 146 147 #define FTPD_SERVER_MESSAGE "RTEMS FTP server (Version 1.0-JWJ) ready." 190 148 #define FTPD_WELCOME_MESSAGE \ 191 149 "Welcome to the RTEMS FTP server.\n" \ … … 195 153 196 154 /************************************************************************** 197 * Function: FTPD_SendReply*155 * Function: rtems_ftpd_send_reply * 198 156 ************************************************************************** 199 157 * Description: * … … 217 175 *************************************************************************/ 218 176 static void 219 FTPD_SendReply(int code, char *text)177 rtems_ftpd_send_reply(int code, char *text) 220 178 { 221 179 rtems_status_code sc; … … 242 200 { 243 201 sprintf(str, "%d %.70s\r\n", code, text); 202 fprintf(info->ctrl_fp, "%d %.70s\r\n", code, text); 244 203 } 245 204 else 246 205 { 247 206 sprintf(str, "%d\r\n", code); 248 } 249 send(info->ctrl_sock, str, strlen(str), 0); 207 fprintf(info->ctrl_fp, "%d\r\n", code); 208 } 209 fflush(info->ctrl_fp); 250 210 } 251 211 252 212 253 213 /************************************************************************** 254 * Function: FTPD_CommandRetrieve*214 * Function: rtems_ftpd_command_retrieve * 255 215 ************************************************************************** 256 216 * Description: * … … 275 235 *************************************************************************/ 276 236 static int 277 FTPD_CommandRetrieve(char *filename)237 rtems_ftpd_command_retrieve(char *filename) 278 238 { 279 239 int s; 280 240 int n; 281 282 FILE *fp; 241 int fd; 283 242 unsigned char *bufr; 284 243 rtems_status_code sc; … … 289 248 (rtems_unsigned32 *)&info); 290 249 291 292 if ((fp = fopen(filename, "r")) == NULL) 293 { 294 FTPD_SendReply(450, "Error opening file."); 250 if ((fd = open(filename, O_RDONLY)) == -1) 251 { 252 rtems_ftpd_send_reply(450, "Error opening file."); 295 253 return(0); 296 254 } … … 299 257 if (bufr == NULL) 300 258 { 301 FTPD_SendReply(440, "Server error - malloc fail.");302 fclose(fp);259 rtems_ftpd_send_reply(440, "Server error - malloc fail."); 260 close(fd); 303 261 return(0); 304 262 } … … 307 265 * Connect to the data connection (PORT made in an earlier PORT call). 308 266 **********************************************************************/ 309 FTPD_SendReply(150, "BINARY data connection.");267 rtems_ftpd_send_reply(150, "BINARY data connection."); 310 268 s = socket(AF_INET, SOCK_STREAM, 0); 311 269 if (connect(s, (struct sockaddr *)&info->data_addr, 312 270 sizeof(struct sockaddr)) < 0) 313 271 { 314 FTPD_SendReply(420, "Server error - could not connect socket.");272 rtems_ftpd_send_reply(420, "Server error - could not connect socket."); 315 273 free(bufr); 316 fclose(fp);274 close(fd); 317 275 close(s); 318 276 return(1); … … 322 280 * Send the data over the ether. 323 281 **********************************************************************/ 324 while ((n = fread(bufr, 1, BUFSIZ, fp)) !=0)282 while ((n = read(fd, bufr, BUFSIZ)) > 0) 325 283 { 326 284 send(s, bufr, n, 0); 327 } 328 329 if (feof(fp)) 330 { 331 FTPD_SendReply(210, "File sent successfully."); 285 bufr[n-1] = '\0'; 286 } 287 288 if (n == 0) 289 { 290 rtems_ftpd_send_reply(210, "File sent successfully."); 332 291 } 333 292 else 334 293 { 335 FTPD_SendReply(450, "Retrieve failed.");294 rtems_ftpd_send_reply(450, "Retrieve failed."); 336 295 } 337 296 … … 342 301 343 302 free(bufr); 344 fclose(fp);303 close(fd); 345 304 return(0); 346 305 } … … 348 307 349 308 /************************************************************************** 350 * Function: FTPD_CommandStore*309 * Function: rtems_ftpd_command_store * 351 310 ************************************************************************** 352 311 * Description: * … … 371 330 *************************************************************************/ 372 331 static int 373 FTPD_CommandStore(char *filename)332 rtems_ftpd_command_store(char *filename) 374 333 { 375 char *bufr;376 char *bigBufr;377 int s;378 int n;379 unsigned long size = 0;380 rtems_status_code sc;381 FTPD_SessionInfo_t *info= NULL;334 char *bufr; 335 int s; 336 int n; 337 unsigned long size = 0; 338 rtems_status_code sc; 339 FTPD_SessionInfo_t *info = NULL; 340 struct rtems_ftpd_hook *usehook = NULL; 382 341 383 342 … … 388 347 if (bufr == NULL) 389 348 { 390 FTPD_SendReply(440, "Server error - malloc fail.");349 rtems_ftpd_send_reply(440, "Server error - malloc fail."); 391 350 return(1); 392 351 } 393 352 394 bigBufr = (char *)malloc(FTPD_MAX_RECEIVESIZE * sizeof(char)); 395 if (bigBufr == NULL) 396 { 397 FTPD_SendReply(440, "Server error - malloc fail."); 398 free(bufr); 399 return(1); 400 } 401 402 FTPD_SendReply(150, "BINARY data connection."); 353 rtems_ftpd_send_reply(150, "BINARY data connection."); 403 354 404 355 s = socket(AF_INET, SOCK_STREAM, 0); … … 407 358 { 408 359 free(bufr); 409 free(bigBufr);410 360 close(s); 411 361 return(1); … … 415 365 /*********************************************************************** 416 366 * File: "/dev/null" just throws the data away. 367 * Otherwise, search our list of hooks to see if we need to do something 368 * special. 417 369 **********************************************************************/ 418 370 if (!strncmp("/dev/null", filename, 9)) … … 420 372 while ((n = read(s, bufr, BUFSIZ)) > 0); 421 373 } 422 else 423 { 374 else if (rtems_ftpd_configuration.hooks != NULL) 375 { 376 struct rtems_ftpd_hook *hook; 377 int i; 378 379 i = 0; 380 hook = &rtems_ftpd_configuration.hooks[i++]; 381 while (hook->filename != NULL) 382 { 383 if (!strcmp(hook->filename, filename)) 384 { 385 usehook = hook; 386 break; 387 } 388 hook = &rtems_ftpd_configuration.hooks[i++]; 389 } 390 } 391 392 if (usehook != NULL) 393 { 394 char *bigBufr; 395 396 /*********************************************************************** 397 * Allocate space for our "file". 398 **********************************************************************/ 399 bigBufr = (char *)malloc( 400 rtems_ftpd_configuration.max_hook_filesize * sizeof(char)); 401 if (bigBufr == NULL) 402 { 403 rtems_ftpd_send_reply(440, "Server error - malloc fail."); 404 free(bufr); 405 return(1); 406 } 407 424 408 /*********************************************************************** 425 409 * Retrieve the file into our buffer space. … … 428 412 while ((n = read(s, bufr, BUFSIZ)) > 0) 429 413 { 430 if (size + n > FTPD_MAX_RECEIVESIZE) 414 if (size + n > 415 rtems_ftpd_configuration.max_hook_filesize * sizeof(char)) 431 416 { 432 FTPD_SendReply(440, "Server error - Buffer size exceeded.");417 rtems_ftpd_send_reply(440, "Server error - Buffer size exceeded."); 433 418 free(bufr); 434 419 free(bigBufr); … … 439 424 size += n; 440 425 } 441 } 426 close(s); 427 428 /*********************************************************************** 429 * Call our hook. 430 **********************************************************************/ 431 if ((usehook->hook_function)(bigBufr, size) == 0) 432 { 433 rtems_ftpd_send_reply(210, "File transferred successfully."); 434 } 435 else 436 { 437 rtems_ftpd_send_reply(440, "File transfer failed."); 438 } 439 free(bigBufr); 440 } 441 else 442 { 443 int fd; 444 size_t written; 445 446 fd = creat(filename, S_IRUSR | S_IWUSR | 447 S_IRGRP | S_IWGRP | 448 S_IROTH | S_IWOTH); 449 if (fd == -1) 450 { 451 rtems_ftpd_send_reply(450, "Could not open file."); 452 close(s); 453 free(bufr); 454 return(1); 455 } 456 while ((n = read(s, bufr, BUFSIZ)) > 0) 457 { 458 written = write(fd, bufr, n); 459 if (written == -1) 460 { 461 rtems_ftpd_send_reply(450, "Error during write."); 462 close(fd); 463 close(s); 464 free(bufr); 465 return(1); 466 } 467 } 468 close(fd); 469 close(s); 470 rtems_ftpd_send_reply(226, "Transfer complete."); 471 } 472 442 473 free(bufr); 443 close(s);444 445 446 /***********************************************************************447 * Figure out what to do with the data we just received.448 **********************************************************************/449 if (!strncmp("untar", filename, 5))450 {451 Untar_FromMemory(bigBufr, size);452 FTPD_SendReply(210, "Untar successful.");453 }454 else455 {456 FILE *fp;457 size_t len;458 size_t written;459 460 fp = fopen(filename, "w");461 if (fp == NULL)462 {463 FTPD_SendReply(440, "Could not open file.");464 free(bigBufr);465 return(1);466 }467 468 n = 0;469 written = 0;470 while (n<size)471 {472 len = ((size-n>BUFSIZ)?(BUFSIZ):(size-n));473 written = fwrite(&bigBufr[n], 1, len, fp);474 n += written;475 if (written != len)476 {477 break;478 }479 }480 fclose(fp);481 482 if (n == size)483 {484 FTPD_SendReply(226, "Transfer complete.");485 }486 else487 {488 FTPD_SendReply(440, "Error during write.");489 free(bigBufr);490 return(1);491 }492 }493 494 free(bigBufr);495 474 return(0); 496 475 } … … 498 477 499 478 /************************************************************************** 500 * Function: FTPD_CommandList*479 * Function: rtems_ftpd_command_list * 501 480 ************************************************************************** 502 481 * Description: * … … 519 498 *************************************************************************/ 520 499 static void 521 FTPD_CommandList(char *fname)500 rtems_ftpd_command_list(char *fname) 522 501 { 523 502 int s; … … 533 512 (rtems_unsigned32 *)&info); 534 513 535 FTPD_SendReply(150, "ASCII data connection for LIST.");514 rtems_ftpd_send_reply(150, "ASCII data connection for LIST."); 536 515 537 516 s = socket(AF_INET, SOCK_STREAM, 0); … … 549 528 send(s, dirline, strlen(dirline), 0); 550 529 close(s); 551 FTPD_SendReply(226, "Transfer complete.");530 rtems_ftpd_send_reply(226, "Transfer complete."); 552 531 return; 553 532 } … … 579 558 580 559 close(s); 581 FTPD_SendReply(226, "Transfer complete.");560 rtems_ftpd_send_reply(226, "Transfer complete."); 582 561 } 583 562 … … 587 566 */ 588 567 static void 589 FTPD_CWD(char *dir)568 rtems_ftpd_CWD(char *dir) 590 569 { 591 570 rtems_status_code sc; … … 598 577 if (chdir(dir) == 0) 599 578 { 600 FTPD_SendReply(250, "CWD command successful.");579 rtems_ftpd_send_reply(250, "CWD command successful."); 601 580 } 602 581 else 603 582 { 604 FTPD_SendReply(550, "CWD command failed.");583 rtems_ftpd_send_reply(550, "CWD command failed."); 605 584 } 606 585 } … … 608 587 609 588 /************************************************************************** 610 * Function: FTPD_CommandPort*589 * Function: rtems_ftpd_command_port * 611 590 ************************************************************************** 612 591 * Description: * … … 631 610 *************************************************************************/ 632 611 static void 633 FTPD_CommandPort(char *bufr)612 rtems_ftpd_command_port(char *bufr) 634 613 { 635 614 char *ip; … … 657 636 658 637 /************************************************************************** 659 * Function: FTPD_ParseCommand*638 * Function: rtems_ftpd_parse_command * 660 639 ************************************************************************** 661 640 * Description: * … … 664 643 * connection. * 665 644 * * 645 * FIXME: This section is somewhat of a hack. We should have a better * 646 * way to parse commands. * 666 647 * * 667 648 * Inputs: * … … 679 660 *************************************************************************/ 680 661 static void 681 FTPD_ParseCommand(char *bufr)662 rtems_ftpd_parse_command(char *bufr) 682 663 { 683 664 char fname[255]; … … 691 672 if (!strncmp("PORT", bufr, 4)) 692 673 { 693 FTPD_SendReply(200, "PORT command successful.");694 FTPD_CommandPort(&bufr[5]);674 rtems_ftpd_send_reply(200, "PORT command successful."); 675 rtems_ftpd_command_port(&bufr[5]); 695 676 } 696 677 else if (!strncmp("RETR", bufr, 4)) 697 678 { 698 679 sscanf(&bufr[5], "%254s", fname); 699 FTPD_CommandRetrieve(fname);680 rtems_ftpd_command_retrieve(fname); 700 681 } 701 682 else if (!strncmp("STOR", bufr, 4)) 702 683 { 703 684 sscanf(&bufr[5], "%254s", fname); 704 FTPD_CommandStore(fname);685 rtems_ftpd_command_store(fname); 705 686 } 706 687 else if (!strncmp("LIST", bufr, 4)) … … 708 689 if (bufr[5] == '\n') 709 690 { 710 FTPD_CommandList(".");691 rtems_ftpd_command_list("."); 711 692 } 712 693 else 713 694 { 714 695 sscanf(&bufr[5], "%254s", fname); 715 FTPD_CommandList(fname);696 rtems_ftpd_command_list(fname); 716 697 } 717 698 } 718 699 else if (!strncmp("USER", bufr, 4)) 719 700 { 720 FTPD_SendReply(230, "User logged in.");701 rtems_ftpd_send_reply(230, "User logged in."); 721 702 } 722 703 else if (!strncmp("SYST", bufr, 4)) 723 704 { 724 FTPD_SendReply(240, "RTEMS");705 rtems_ftpd_send_reply(240, "RTEMS"); 725 706 } 726 707 else if (!strncmp("TYPE", bufr, 4)) … … 729 710 { 730 711 info->xfer_mode = TYPE_I; 731 FTPD_SendReply(200, "Type set to I.");712 rtems_ftpd_send_reply(200, "Type set to I."); 732 713 } 733 714 else if (bufr[5] == 'A') 734 715 { 735 716 info->xfer_mode = TYPE_A; 736 FTPD_SendReply(200, "Type set to A.");717 rtems_ftpd_send_reply(200, "Type set to A."); 737 718 } 738 719 else 739 720 { 740 721 info->xfer_mode = TYPE_I; 741 FTPD_SendReply(504, "Type not implemented. Set to I.");722 rtems_ftpd_send_reply(504, "Type not implemented. Set to I."); 742 723 } 743 724 } 744 725 else if (!strncmp("PASS", bufr, 4)) 745 726 { 746 FTPD_SendReply(230, "User logged in.");727 rtems_ftpd_send_reply(230, "User logged in."); 747 728 } 748 729 else if (!strncmp("DELE", bufr, 4)) … … 751 732 if (unlink(fname) == 0) 752 733 { 753 FTPD_SendReply(257, "DELE successful.");734 rtems_ftpd_send_reply(257, "DELE successful."); 754 735 } 755 736 else 756 737 { 757 FTPD_SendReply(550, "DELE failed.");738 rtems_ftpd_send_reply(550, "DELE failed."); 758 739 } 759 740 } … … 765 746 if (chmod(fname, (mode_t)mask) == 0) 766 747 { 767 FTPD_SendReply(257, "CHMOD successful.");748 rtems_ftpd_send_reply(257, "CHMOD successful."); 768 749 } 769 750 else 770 751 { 771 FTPD_SendReply(550, "CHMOD failed.");752 rtems_ftpd_send_reply(550, "CHMOD failed."); 772 753 } 773 754 } … … 777 758 if (rmdir(fname) == 0) 778 759 { 779 FTPD_SendReply(257, "RMD successful.");760 rtems_ftpd_send_reply(257, "RMD successful."); 780 761 } 781 762 else 782 763 { 783 FTPD_SendReply(550, "RMD failed.");764 rtems_ftpd_send_reply(550, "RMD failed."); 784 765 } 785 766 } … … 789 770 if (mkdir(fname, S_IRWXU | S_IRWXG | S_IRWXO) == 0) 790 771 { 791 FTPD_SendReply(257, "MKD successful.");772 rtems_ftpd_send_reply(257, "MKD successful."); 792 773 } 793 774 else 794 775 { 795 FTPD_SendReply(550, "MKD failed.");776 rtems_ftpd_send_reply(550, "MKD failed."); 796 777 } 797 778 } … … 799 780 { 800 781 sscanf(&bufr[4], "%254s", fname); 801 FTPD_CWD(fname);782 rtems_ftpd_CWD(fname); 802 783 } 803 784 else if (!strncmp("PWD", bufr, 3)) … … 805 786 char *cwd = getcwd(0, 0); 806 787 sprintf(bufr, "\"%s\" is the current directory.", cwd); 807 FTPD_SendReply(250, bufr);788 rtems_ftpd_send_reply(250, bufr); 808 789 free(cwd); 809 790 } 810 791 else 811 792 { 812 FTPD_SendReply(500, "Unrecognized/unsupported command.");793 rtems_ftpd_send_reply(500, "Unrecognized/unsupported command."); 813 794 } 814 795 } 815 796 816 /************************************************************************** 817 * Function: FTPD_Session * 797 798 /************************************************************************** 799 * Function: rtems_ftpd_session * 818 800 ************************************************************************** 819 801 * Description: * … … 828 810 * Inputs: * 829 811 * * 830 * rtems_task_argument arg - The FTPD_Daemon task passes the socket*812 * rtems_task_argument arg - The daemon task passes the socket * 831 813 * which serves as the control connection. * 832 814 * * … … 840 822 *************************************************************************/ 841 823 static void 842 FTPD_Session(rtems_task_argument arg)824 rtems_ftpd_session(rtems_task_argument arg) 843 825 { 844 826 char cmd[256]; … … 850 832 (rtems_unsigned32 *)&info); 851 833 852 FTPD_SendReply(220, "Erithacus FTP server (Version 1.0) ready.");834 rtems_ftpd_send_reply(220, FTPD_SERVER_MESSAGE); 853 835 854 836 /*********************************************************************** … … 859 841 while (1) 860 842 { 861 if ( recv(info->ctrl_sock, cmd, 256, 0) == -1)843 if (fgets(cmd, 256, info->ctrl_fp) == NULL) 862 844 { 863 845 syslog(LOG_INFO, "ftpd: Connection aborted."); … … 867 849 if (!strncmp("QUIT", cmd, 4)) 868 850 { 869 FTPD_SendReply(221, "Goodbye.");851 rtems_ftpd_send_reply(221, "Goodbye."); 870 852 break; 871 853 } 872 854 else 873 855 { 874 FTPD_ParseCommand(cmd);875 } 876 } 877 878 if ( close(info->ctrl_sock) <0)856 rtems_ftpd_parse_command(cmd); 857 } 858 } 859 860 if (fclose(info->ctrl_fp) != 0) 879 861 { 880 862 syslog(LOG_ERR, "ftpd: Could not close session."); … … 896 878 897 879 /************************************************************************** 898 * Function: FTPD_Daemon*880 * Function: rtems_ftpd_daemon * 899 881 ************************************************************************** 900 882 * Description: * … … 919 901 *************************************************************************/ 920 902 static void 921 FTPD_Daemon()903 rtems_ftpd_daemon() 922 904 { 923 905 int s; … … 942 924 943 925 localAddr.sin_family = AF_INET; 944 localAddr.sin_port = FTPD_CONTROL_PORT;926 localAddr.sin_port = htons(rtems_ftpd_configuration.port); 945 927 localAddr.sin_addr.s_addr = INADDR_ANY; 946 928 memset(localAddr.sin_zero, '\0', sizeof(localAddr.sin_zero)); … … 1003 985 * Send the socket on to the new session. 1004 986 *******************************************************************/ 1005 info->ctrl_sock = s1; 1006 sc = rtems_task_set_note(tid, RTEMS_NOTEPAD_0, 1007 (rtems_unsigned32)info); 1008 sc = rtems_task_start(tid, FTPD_Session, 0); 1009 if (sc != RTEMS_SUCCESSFUL) 1010 { 1011 syslog(LOG_ERR, "ftpd: Could not start FTPD session: %s", 1012 rtems_status_text(sc)); 987 if ((info->ctrl_fp = fdopen(s1, "r+")) == NULL) 988 { 989 syslog(LOG_ERR, "ftpd: fdopen() on socket failed."); 990 close(s1); 991 } 992 else 993 { 994 sc = rtems_task_set_note(tid, RTEMS_NOTEPAD_0, 995 (rtems_unsigned32)info); 996 sc = rtems_task_start(tid, rtems_ftpd_session, 0); 997 if (sc != RTEMS_SUCCESSFUL) 998 { 999 syslog(LOG_ERR, "ftpd: Could not start FTPD session: %s", 1000 rtems_status_text(sc)); 1001 } 1013 1002 } 1014 1003 } … … 1017 1006 1018 1007 /************************************************************************** 1019 * Function: FTPD_Start*1008 * Function: rtems_ftpd_start * 1020 1009 ************************************************************************** 1021 1010 * Description: * … … 1032 1021 * Output: * 1033 1022 * * 1034 * none*1023 * int - RTEMS_SUCCESSFUL on successful start of the daemon. * 1035 1024 * * 1036 1025 ************************************************************************** … … 1038 1027 * 12/01/97 - Creation (JWJ) * 1039 1028 *************************************************************************/ 1040 void 1041 FTPD_Start(rtems_task_priority priority)1029 int 1030 rtems_initialize_ftpd() 1042 1031 { 1043 1032 rtems_status_code sc; … … 1045 1034 1046 1035 1036 if (rtems_ftpd_configuration.port == 0) 1037 { 1038 rtems_ftpd_configuration.port = FTPD_CONTROL_PORT; 1039 } 1040 1041 /*********************************************************************** 1042 * Default FTPD priority. 1043 **********************************************************************/ 1044 if (rtems_ftpd_configuration.priority == 0) 1045 { 1046 rtems_ftpd_configuration.priority = 40; 1047 } 1047 1048 sc = rtems_task_create(rtems_build_name('F', 'T', 'P', 'D'), 1048 priority, 8*1024,1049 rtems_ftpd_configuration.priority, 8*1024, 1049 1050 RTEMS_PREEMPT | RTEMS_NO_TIMESLICE | RTEMS_NO_ASR | 1050 1051 RTEMS_INTERRUPT_LEVEL(0), … … 1055 1056 syslog(LOG_ERR, "ftpd: Could not create FTP daemon: %s", 1056 1057 rtems_status_text(sc)); 1057 } 1058 1059 sc = rtems_task_start(tid, FTPD_Daemon, 0); 1058 return(RTEMS_UNSATISFIED); 1059 } 1060 1061 sc = rtems_task_start(tid, rtems_ftpd_daemon, 0); 1060 1062 if (sc != RTEMS_SUCCESSFUL) 1061 1063 { 1062 1064 syslog(LOG_ERR, "ftpd: Could not start FTP daemon: %s", 1063 1065 rtems_status_text(sc)); 1066 return(RTEMS_UNSATISFIED); 1064 1067 } 1065 1068 1066 1069 syslog(LOG_INFO, "ftpd: FTP daemon started."); 1070 return(RTEMS_SUCCESSFUL); 1067 1071 } 1072
Note: See TracChangeset
for help on using the changeset viewer.