summaryrefslogtreecommitdiffstats
path: root/usr.sbin/pkg_install/lib/file.c
diff options
context:
space:
mode:
authorjkh <jkh@FreeBSD.org>1995-07-30 09:33:31 +0000
committerjkh <jkh@FreeBSD.org>1995-07-30 09:33:31 +0000
commit782b43871131b7fd0a0f0d61e0259ba53abdc148 (patch)
tree9b729bf55edeb4c5048aa69b7ef53bbc088bbb51 /usr.sbin/pkg_install/lib/file.c
parente01c747916f2222da20856e1a7ff37577fa76eb9 (diff)
downloadFreeBSD-src-782b43871131b7fd0a0f0d61e0259ba53abdc148.zip
FreeBSD-src-782b43871131b7fd0a0f0d61e0259ba53abdc148.tar.gz
Totally eliminate the dependency on libftp (which will be removed from the
FreeBSD source tree) and switch to the internal ftp routines developed by Poul-Henning and used in sysinstall.
Diffstat (limited to 'usr.sbin/pkg_install/lib/file.c')
-rw-r--r--usr.sbin/pkg_install/lib/file.c86
1 files changed, 36 insertions, 50 deletions
diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c
index 55ba9d5..c8f4988 100644
--- a/usr.sbin/pkg_install/lib/file.c
+++ b/usr.sbin/pkg_install/lib/file.c
@@ -1,5 +1,5 @@
#ifndef lint
-static const char *rcsid = "$Id: file.c,v 1.11 1995/06/24 10:12:59 asami Exp $";
+static const char *rcsid = "$Id: file.c,v 1.12 1995/07/30 01:44:44 ache Exp $";
#endif
/*
@@ -23,7 +23,7 @@ static const char *rcsid = "$Id: file.c,v 1.11 1995/06/24 10:12:59 asami Exp $";
*/
#include "lib.h"
-#include <FtpLibrary.h>
+#include "ftp.h"
#include <pwd.h>
/* Quick check to see if a file exists */
@@ -161,52 +161,26 @@ fileURLFilename(char *fname, char *where, int max)
return fname;
}
-/*
- * Callback functions for fileGetURL - GetIO is called on I/O requests
- * and GetAbort when the transfer aborts.
- */
-
-/* Something they can use to keep track of the action */
-Boolean connectionAborted = FALSE;
-
-static int
-_fileGetIO(FTP *ftp, int n, char *s )
-{
- printf("In IO: %s\n", s);
- return 0;
-}
-
-static int
-_fileGetAbort(FTP *ftp, int n, char *s )
-{
- /* No access or not found, exclude network or host unreachable */
- if (abs(n) == 550 && FtpBadReply550(s)) {
- connectionAborted = TRUE;
- return 1;
- }
- return 0;
-}
-
#define HOSTNAME_MAX 64
-
/*
- * Try and fetch a file by URL, returning the name of the local
- * copy if fetched successfully.
+ * Try and fetch a file by URL, returning the fd of open
+ * file if fetched successfully.
*/
char *
fileGetURL(char *fname)
{
- static char out[FILENAME_MAX];
- char *cp;
char host[HOSTNAME_MAX], file[FILENAME_MAX], dir[FILENAME_MAX];
- char pword[HOSTNAME_MAX + 40], *uname;
+ char pword[HOSTNAME_MAX + 40], *uname, *cp;
+ static char tmpl[40];
struct passwd *pw;
- FTP *ftp;
- int i;
+ FTP_t ftp;
+ int fd, fd2, i;
+ char ch;
if (!isURL(fname))
return NULL;
+ ftp = FtpInit();
cp = fileURLHost(fname, host, HOSTNAME_MAX);
if (!*cp) {
whinge("URL `%s' has bad host part!", fname);
@@ -219,10 +193,6 @@ fileGetURL(char *fname)
return NULL;
}
- FtpSetErrorHandler(&FtpInit, _fileGetAbort);
- FtpSetFlag(&FtpInit, FTP_REST);
- FtpSetTimeout(&FtpInit, 60); /* XXX this may be too short */
-
/* Maybe change to ftp if this doesn't work */
uname = "anonymous";
@@ -237,7 +207,10 @@ fileGetURL(char *fname)
if (Verbose)
printf("Trying to fetch %s from %s.\n", file, host);
- FtpLogin(&ftp, host, uname, pword, NULL);
+ FtpOpen(ftp, host, uname, pword);
+ /* XXX - Currently undocumented - XXX */
+ if (getenv("FTP_PASSIVE"))
+ FtpPassive(ftp, TRUE);
strcpy(dir, file);
for (i = strlen(dir); i && dir[i] != '/'; i--);
@@ -245,18 +218,31 @@ fileGetURL(char *fname)
if (dir[0])
FtpChdir(ftp, dir);
- FtpBinary(ftp);
-
+ FtpBinary(ftp, TRUE);
+ fd = FtpGet(ftp, basename_of(file));
+ if (fd < 0) {
+ whinge("Unable to get `%s' over ftp!", file);
+ return NULL;
+ }
if ((cp = getenv("PKG_TMPDIR")) != NULL)
- sprintf(out, "%s/instpkg-XXXXXX.tgz", cp);
+ sprintf(tmpl, "%s/instpkg-XXXXXX.tgz", cp);
else
- strcpy(out, "/var/tmp/instpkg-XXXXXX.tgz");
-
- FtpGet(ftp, basename_of(file), out);
- FtpBye(ftp);
- if (connectionAborted)
+ strcpy(tmpl, "/var/tmp/instpkg-XXXXXX.tgz");
+ cp = mktemp(tmpl);
+ if (!cp) {
+ whinge("Unable to make temporary filename from template: %s!", tmpl);
return NULL;
- return out;
+ }
+ fd2 = open(cp, O_CREAT | O_WRONLY);
+ if (fd2 < 0) {
+ whinge("Unable to create a temporary file for ftp: %s", tmpl);
+ return NULL;
+ }
+ while (read(fd, &ch, 1) == 1)
+ write(fd, &ch, 1);
+ FtpEof(ftp);
+ FtpClose(ftp);
+ return tmpl;
}
char *
OpenPOWER on IntegriCloud