Deleted Added
sdiff udiff text old ( 77234 ) new ( 77238 )
full compact
1/*-
2 * Copyright (c) 1998 Dag-Erling Co�dan Sm�rgrav
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 11 unchanged lines hidden (view full) ---

20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * $FreeBSD: head/lib/libfetch/ftp.c 77234 2001-05-26 17:23:38Z des $
29 */
30
31/*
32 * Portions of this code were taken from or based on ftpio.c:
33 *
34 * ----------------------------------------------------------------------------
35 * "THE BEER-WARE LICENSE" (Revision 42):
36 * <phk@login.dknet.dk> wrote this file. As long as you retain this notice you

--- 670 unchanged lines hidden (view full) ---

707 if (e != -1)
708 _ftp_seterr(e);
709 if (sd >= 0)
710 close(sd);
711 return NULL;
712}
713
714/*
715 * Log on to FTP server
716 */
717static int
718_ftp_connect(struct url *url, struct url *purl, const char *flags)
719{
720 int cd, e, direct, verbose;
721#ifdef INET6
722 int af = AF_UNSPEC;
723#else
724 int af = AF_INET;
725#endif
726 const char *logname;
727 const char *user;
728 const char *pwd;
729 char localhost[MAXHOSTNAMELEN];
730 char pbuf[MAXHOSTNAMELEN + MAXLOGNAME + 1];
731
732 direct = CHECK_FLAG('d');
733 verbose = CHECK_FLAG('v');
734 if (CHECK_FLAG('4'))
735 af = AF_INET;
736 else if (CHECK_FLAG('6'))
737 af = AF_INET6;
738

--- 14 unchanged lines hidden (view full) ---

753 if (cd == -1) {
754 _fetch_syserr();
755 return NULL;
756 }
757
758 /* expect welcome message */
759 if ((e = _ftp_chkerr(cd)) != FTP_SERVICE_READY)
760 goto fouch;
761
762 /* XXX FTP_AUTH, and maybe .netrc */
763
764 /* send user name and password */
765 user = url->user;
766 if (!user || !*user)
767 user = getenv("FTP_LOGIN");
768 if (!user || !*user)
769 user = FTP_ANONYMOUS_USER;
770 if (purl && url->port == _fetch_default_port(url->scheme))
771 e = _ftp_cmd(cd, "USER %s@%s", user, url->host);
772 else if (purl)
773 e = _ftp_cmd(cd, "USER %s@%s@%d", user, url->host, url->port);
774 else
775 e = _ftp_cmd(cd, "USER %s", user);
776
777 /* did the server request a password? */
778 if (e == FTP_NEED_PASSWORD) {
779 pwd = url->pwd;
780 if (!pwd || !*pwd)
781 pwd = getenv("FTP_PASSWORD");
782 if (!pwd || !*pwd) {
783 if ((logname = getlogin()) == 0)
784 logname = FTP_ANONYMOUS_USER;
785 gethostname(localhost, sizeof localhost);
786 snprintf(pbuf, sizeof pbuf, "%s@%s", logname, localhost);
787 pwd = pbuf;
788 }
789 e = _ftp_cmd(cd, "PASS %s", pwd);
790 }
791
792 /* did the server request an account? */
793 if (e == FTP_NEED_ACCOUNT)
794 goto fouch;
795
796 /* we should be done by now */
797 if (e != FTP_LOGGED_IN)
798 goto fouch;
799
800 /* might as well select mode and type at once */
801#ifdef FTP_FORCE_STREAM_MODE
802 if ((e = _ftp_cmd(cd, "MODE S")) != FTP_OK) /* default is S */
803 goto fouch;
804#endif
805 if ((e = _ftp_cmd(cd, "TYPE I")) != FTP_OK) /* default is A */
806 goto fouch;
807

--- 220 unchanged lines hidden ---