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 77238 2001-05-26 19:37:15Z 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 * Authenticate
716 */
717static int
718_ftp_authenticate(int cd, struct url *url, struct url *purl)
719{
720 char *user, *pwd, *logname;
721 char pbuf[MAXHOSTNAMELEN + MAXLOGNAME + 1];
722 int e, len;
723
724 /* XXX FTP_AUTH, and maybe .netrc */
725
726 /* send user name and password */
727 user = url->user;
728 if (!user || !*user)
729 user = getenv("FTP_LOGIN");
730 if (!user || !*user)
731 user = FTP_ANONYMOUS_USER;
732 if (purl && url->port == _fetch_default_port(url->scheme))
733 e = _ftp_cmd(cd, "USER %s@%s", user, url->host);
734 else if (purl)
735 e = _ftp_cmd(cd, "USER %s@%s@%d", user, url->host, url->port);
736 else
737 e = _ftp_cmd(cd, "USER %s", user);
738
739 /* did the server request a password? */
740 if (e == FTP_NEED_PASSWORD) {
741 pwd = url->pwd;
742 if (!pwd || !*pwd)
743 pwd = getenv("FTP_PASSWORD");
744 if (!pwd || !*pwd) {
745 if ((logname = getlogin()) == 0)
746 logname = FTP_ANONYMOUS_USER;
747 len = snprintf(pbuf, MAXLOGNAME + 1, "%s@", logname);
748 gethostname(pbuf + len, sizeof pbuf - len);
749 pwd = pbuf;
750 }
751 e = _ftp_cmd(cd, "PASS %s", pwd);
752 }
753
754 return e;
755}
756
757/*
758 * Log on to FTP server
759 */
760static int
761_ftp_connect(struct url *url, struct url *purl, const char *flags)
762{
763 int cd, e, direct, verbose;
764#ifdef INET6
765 int af = AF_UNSPEC;
766#else
767 int af = AF_INET;
768#endif
769
770 direct = CHECK_FLAG('d');
771 verbose = CHECK_FLAG('v');
772 if (CHECK_FLAG('4'))
773 af = AF_INET;
774 else if (CHECK_FLAG('6'))
775 af = AF_INET6;
776

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

791 if (cd == -1) {
792 _fetch_syserr();
793 return NULL;
794 }
795
796 /* expect welcome message */
797 if ((e = _ftp_chkerr(cd)) != FTP_SERVICE_READY)
798 goto fouch;
799
800 /* authenticate */
801 if ((e = _ftp_authenticate(cd, url, purl)) != FTP_LOGGED_IN)
802 goto fouch;
803
804 /* might as well select mode and type at once */
805#ifdef FTP_FORCE_STREAM_MODE
806 if ((e = _ftp_cmd(cd, "MODE S")) != FTP_OK) /* default is S */
807 goto fouch;
808#endif
809 if ((e = _ftp_cmd(cd, "TYPE I")) != FTP_OK) /* default is A */
810 goto fouch;
811

--- 220 unchanged lines hidden ---