Make pkg_install understand and use libftpio instead of its own

copies of the ftp support routines.  Also some cosmetic and minor
bug fixes I've been meaning to incorporate for awhile.
This commit is contained in:
Jordan K. Hubbard
1996-06-20 18:33:55 +00:00
parent d7e74838d6
commit a9ef0b2904
16 changed files with 55 additions and 516 deletions
+2
View File
@@ -10,6 +10,8 @@ LDADD+= -L${.CURDIR}/../lib -linstall
DPADD+= ${.CURDIR}/../lib/libinstall.a DPADD+= ${.CURDIR}/../lib/libinstall.a
.endif .endif
LDADD+= -lftpio
DPADD+= ${LIBFTPIO}
SRCS= main.c perform.c futil.c extract.c SRCS= main.c perform.c futil.c extract.c
+5 -9
View File
@@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static const char *rcsid = "$Id: perform.c,v 1.33 1996/03/12 06:12:37 jkh Exp $"; static const char *rcsid = "$Id: perform.c,v 1.34 1996/06/03 04:40:43 jkh Exp $";
#endif #endif
/* /*
@@ -68,8 +68,6 @@ pkg_do(char *pkg)
int code; int code;
PackingList p; PackingList p;
struct stat sb; struct stat sb;
char *isTMP = NULL;
char *cp;
int inPlace; int inPlace;
code = 0; code = 0;
@@ -212,8 +210,6 @@ pkg_do(char *pkg)
/* See if we're already registered */ /* See if we're already registered */
sprintf(LogDir, "%s/%s", (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR, PkgName); sprintf(LogDir, "%s/%s", (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR, PkgName);
if (isdir(LogDir)) { if (isdir(LogDir)) {
char tmp[FILENAME_MAX];
whinge("Package `%s' already recorded as installed.\n", PkgName); whinge("Package `%s' already recorded as installed.\n", PkgName);
code = 1; code = 1;
goto success; /* close enough for government work */ goto success; /* close enough for government work */
@@ -393,16 +389,17 @@ pkg_do(char *pkg)
else { else {
fprintf(cfile, "%s\n", PkgName); fprintf(cfile, "%s\n", PkgName);
if (fclose(cfile) == EOF) if (fclose(cfile) == EOF)
warn("Cannot properly close file %s", contents); whinge("Cannot properly close file %s", contents);
} }
} }
if (Verbose) if (Verbose)
printf("Package %s registered in %s\n", PkgName, LogDir); printf("Package %s registered in %s\n", PkgName, LogDir);
} }
if (p = find_plist(&Plist, PLIST_DISPLAY)) { if ((p = find_plist(&Plist, PLIST_DISPLAY)) != NULL) {
FILE *fp; FILE *fp;
char buf[BUFSIZ]; char buf[BUFSIZ];
fp = fopen(p->name, "r"); fp = fopen(p->name, "r");
if (fp) { if (fp) {
putc('\n', stdout); putc('\n', stdout);
@@ -411,7 +408,7 @@ pkg_do(char *pkg)
putc('\n', stdout); putc('\n', stdout);
(void) fclose(fp); (void) fclose(fp);
} else } else
warn("Cannot open display file `%s'.", p->name); whinge("Cannot open display file `%s'.", p->name);
} }
goto success; goto success;
@@ -435,7 +432,6 @@ pkg_do(char *pkg)
static int static int
sanity_check(char *pkg) sanity_check(char *pkg)
{ {
PackingList p;
int code = 0; int code = 0;
if (!fexists(CONTENTS_FNAME)) { if (!fexists(CONTENTS_FNAME)) {
+2
View File
@@ -10,6 +10,8 @@ LDADD+= -L${.CURDIR}/../lib -linstall
DPADD+= ${.CURDIR}/../lib/libinstall.a DPADD+= ${.CURDIR}/../lib/libinstall.a
.endif .endif
LDADD+= -lftpio
DPADD+= ${LIBFTPIO}
SRCS= main.c perform.c pl.c SRCS= main.c perform.c pl.c
+3 -2
View File
@@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static const char *rcsid = "$Id: perform.c,v 1.29 1996/02/06 22:49:11 jdp Exp $"; static const char *rcsid = "$Id: perform.c,v 1.30 1996/03/20 19:05:59 jdp Exp $";
#endif #endif
/* /*
@@ -28,6 +28,7 @@ static const char *rcsid = "$Id: perform.c,v 1.29 1996/02/06 22:49:11 jdp Exp $"
#include <errno.h> #include <errno.h>
#include <signal.h> #include <signal.h>
#include <sys/syslimits.h> #include <sys/syslimits.h>
#include <sys/wait.h>
#include <unistd.h> #include <unistd.h>
static void sanity_check(void); static void sanity_check(void);
@@ -184,7 +185,7 @@ make_dist(char *home, char *pkg, char *suffix, Package *plist)
{ {
char tball[FILENAME_MAX]; char tball[FILENAME_MAX];
PackingList p; PackingList p;
int ret, max, len; int ret;
char *args[50]; /* Much more than enough. */ char *args[50]; /* Much more than enough. */
int nargs = 0; int nargs = 0;
int pipefds[2]; int pipefds[2];
+3
View File
@@ -9,6 +9,9 @@ LDADD+= -L${.CURDIR}/../lib -linstall
DPADD+= ${.CURDIR}/../lib/libinstall.a DPADD+= ${.CURDIR}/../lib/libinstall.a
.endif .endif
LDADD+= -lftpio
DPADD+= ${LIBFTPIO}
SRCS= main.c perform.c SRCS= main.c perform.c
.include <bsd.prog.mk> .include <bsd.prog.mk>
+2 -1
View File
@@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static char *rcsid = "$Id: main.c,v 1.3 1994/12/06 00:51:40 jkh Exp $"; static char *rcsid = "$Id: main.c,v 1.4 1995/05/30 03:49:57 rgrimes Exp $";
#endif #endif
/* /*
@@ -25,6 +25,7 @@ static char *rcsid = "$Id: main.c,v 1.3 1994/12/06 00:51:40 jkh Exp $";
#include "lib.h" #include "lib.h"
#include "delete.h" #include "delete.h"
#include <err.h>
static char Options[] = "hvDdnfp:"; static char Options[] = "hvDdnfp:";
+3 -3
View File
@@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static const char *rcsid = "$Id: perform.c,v 1.7.4.1 1995/11/10 06:44:47 jkh Exp $"; static const char *rcsid = "$Id: perform.c,v 1.8 1995/11/12 04:55:30 jkh Exp $";
#endif #endif
/* /*
@@ -123,7 +123,7 @@ pkg_do(char *pkg)
if (!Fake) { if (!Fake) {
/* Some packages aren't packed right, so we need to just ignore delete_package()'s status. Ugh! :-( */ /* Some packages aren't packed right, so we need to just ignore delete_package()'s status. Ugh! :-( */
if (delete_package(FALSE, CleanDirs, &Plist) == FAIL) if (delete_package(FALSE, CleanDirs, &Plist) == FAIL)
warn("Couldn't entirely delete package (perhaps the packing list is\n" whinge("Couldn't entirely delete package (perhaps the packing list is\n"
"incorrectly specified?)\n"); "incorrectly specified?)\n");
if (vsystem("%s -r %s", REMOVE_CMD, LogDir)) { if (vsystem("%s -r %s", REMOVE_CMD, LogDir)) {
whinge("Couldn't remove log entry in %s, de-install failed.", LogDir); whinge("Couldn't remove log entry in %s, de-install failed.", LogDir);
@@ -206,7 +206,7 @@ undepend(PackingList p, char *pkgname)
return; return;
} }
if (rename(ftmp, fname) == -1) if (rename(ftmp, fname) == -1)
warn("Error renaming `%s' to `%s'", ftmp, fname); whinge("Error renaming `%s' to `%s'", ftmp, fname);
remove(ftmp); /* just in case */ remove(ftmp); /* just in case */
return; return;
} }
+3
View File
@@ -9,6 +9,9 @@ LDADD+= -L${.CURDIR}/../lib -linstall
DPADD+= ${.CURDIR}/../lib/libinstall.a DPADD+= ${.CURDIR}/../lib/libinstall.a
.endif .endif
LDADD+= -lftpio
DPADD+= ${LIBFTPIO}
SRCS= main.c perform.c show.c SRCS= main.c perform.c show.c
.include <bsd.prog.mk> .include <bsd.prog.mk>
+2 -3
View File
@@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static const char *rcsid = "$Id: show.c,v 1.6 1995/05/30 03:50:02 rgrimes Exp $"; static const char *rcsid = "$Id: show.c,v 1.7 1995/07/30 01:08:34 ache Exp $";
#endif #endif
/* /*
@@ -38,7 +38,7 @@ show_file(char *title, char *fname)
if (!fp) if (!fp)
printf("ERROR: show_file: Can't open '%s' for reading!\n", fname); printf("ERROR: show_file: Can't open '%s' for reading!\n", fname);
else { else {
while (n = fread(line, 1, 1024, fp)) while ((n = fread(line, 1, 1024, fp)) != 0)
fwrite(line, 1, n, stdout); fwrite(line, 1, n, stdout);
fclose(fp); fclose(fp);
} }
@@ -50,7 +50,6 @@ show_index(char *title, char *fname)
{ {
FILE *fp; FILE *fp;
char line[MAXINDEXSIZE+2]; char line[MAXINDEXSIZE+2];
int i,n;
if (!Quiet) if (!Quiet)
printf("%s%s", InfoPrefix, title); printf("%s%s", InfoPrefix, title);
+1 -1
View File
@@ -1,5 +1,5 @@
LIB= install LIB= install
SRCS= file.c ftp.c msg.c plist.c str.c exec.c global.c pen.c SRCS= file.c msg.c plist.c str.c exec.c global.c pen.c
CFLAGS+= ${DEBUG} CFLAGS+= ${DEBUG}
NOPROFILE= yes NOPROFILE= yes
NOPIC= yes NOPIC= yes
+22 -41
View File
@@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static const char *rcsid = "$Id: file.c,v 1.20 1996/02/19 02:35:56 mpp Exp $"; static const char *rcsid = "$Id: file.c,v 1.21 1996/03/12 06:12:43 jkh Exp $";
#endif #endif
/* /*
@@ -23,9 +23,10 @@ static const char *rcsid = "$Id: file.c,v 1.20 1996/02/19 02:35:56 mpp Exp $";
*/ */
#include "lib.h" #include "lib.h"
#include "ftp.h" #include <ftpio.h>
#include <pwd.h> #include <pwd.h>
#include <time.h> #include <time.h>
#include <sys/wait.h>
/* Quick check to see if a file exists */ /* Quick check to see if a file exists */
Boolean Boolean
@@ -123,7 +124,7 @@ fileURLHost(char *fname, char *where, int max)
/* Don't ever call this on a bad URL! */ /* Don't ever call this on a bad URL! */
fname += strlen("ftp://"); fname += strlen("ftp://");
/* Do we have a place to stick our work? */ /* Do we have a place to stick our work? */
if (ret = where) { if ((ret = where) != NULL) {
while (*fname && *fname != '/' && max--) while (*fname && *fname != '/' && max--)
*where++ = *fname++; *where++ = *fname++;
*where = '\0'; *where = '\0';
@@ -148,7 +149,7 @@ fileURLFilename(char *fname, char *where, int max)
/* Don't ever call this on a bad URL! */ /* Don't ever call this on a bad URL! */
fname += strlen("ftp://"); fname += strlen("ftp://");
/* Do we have a place to stick our work? */ /* Do we have a place to stick our work? */
if (ret = where) { if ((ret = where) != NULL) {
while (*fname && *fname != '/') while (*fname && *fname != '/')
++fname; ++fname;
if (*fname == '/') { if (*fname == '/') {
@@ -172,24 +173,20 @@ fileURLFilename(char *fname, char *where, int max)
char * char *
fileGetURL(char *base, char *spec) fileGetURL(char *base, char *spec)
{ {
char host[HOSTNAME_MAX], file[FILENAME_MAX], dir[FILENAME_MAX]; char host[HOSTNAME_MAX], file[FILENAME_MAX];
char pword[HOSTNAME_MAX + 40], *uname, *cp, *rp, *tmp; char pword[HOSTNAME_MAX + 40], *uname, *cp, *rp;
char fname[FILENAME_MAX]; char fname[FILENAME_MAX];
char pen[FILENAME_MAX]; char pen[FILENAME_MAX];
struct passwd *pw; struct passwd *pw;
FTP_t ftp; FILE *ftp;
pid_t tpid; pid_t tpid;
int fd, fd2, i, len = 0; int i;
char ch;
time_t start, stop;
char *hint; char *hint;
rp = NULL; rp = NULL;
/* Special tip that sysinstall left for us */ /* Special tip that sysinstall left for us */
hint = getenv("PKG_ADD_BASE"); hint = getenv("PKG_ADD_BASE");
if (!isURL(spec)) { if (!isURL(spec)) {
int len;
if (!base && !hint) if (!base && !hint)
return NULL; return NULL;
/* We've been given an existing URL (that's known-good) and now we need /* We've been given an existing URL (that's known-good) and now we need
@@ -219,7 +216,6 @@ fileGetURL(char *base, char *spec)
} }
else else
strcpy(fname, spec); strcpy(fname, spec);
ftp = FtpInit();
cp = fileURLHost(fname, host, HOSTNAME_MAX); cp = fileURLHost(fname, host, HOSTNAME_MAX);
if (!*cp) { if (!*cp) {
whinge("URL `%s' has bad host part!", fname); whinge("URL `%s' has bad host part!", fname);
@@ -241,37 +237,23 @@ fileGetURL(char *base, char *spec)
whinge("Can't get user name for ID %d\n.", getuid()); whinge("Can't get user name for ID %d\n.", getuid());
strcpy(pword, "joe@"); strcpy(pword, "joe@");
} }
else else {
snprintf(pword, HOSTNAME_MAX + 40, "%s@%s", pw->pw_name, host); char me[HOSTNAME_MAX];
if (Verbose) gethostname(me, HOSTNAME_MAX);
printf("Trying to log into %s as %s.\n", host, uname); snprintf(pword, HOSTNAME_MAX + 40, "%s@%s", pw->pw_name, me);
FtpOpen(ftp, host, uname, pword);
if (getenv("FTP_PASSIVE_MODE"))
FtpPassive(ftp, TRUE);
strcpy(dir, file);
for (i = strlen(dir); i && dir[i] != '/'; i--);
dir[i] = '\0';
if (dir[0]) {
if (Verbose) printf("FTP: chdir to %s\n", dir);
FtpChdir(ftp, dir);
} }
FtpBinary(ftp, TRUE); if (Verbose)
if (Verbose) printf("FTP: trying to get %s\n", basename_of(file)); printf("Trying to fetch %s.\n", fname);
tmp = basename_of(file); ftp = ftpGetURL(fname, uname, pword);
if (!strstr(tmp, ".tgz")) if (ftp) {
tmp = strconcat(tmp, ".tgz");
fd = FtpGet(ftp, tmp);
if (fd >= 0) {
pen[0] = '\0'; pen[0] = '\0';
if (rp = make_playpen(pen, 0)) { if ((rp = make_playpen(pen, 0)) != NULL) {
if (Verbose) if (Verbose)
printf("Extracting from FTP connection into %s\n", pen); printf("Extracting from FTP connection into %s\n", pen);
tpid = fork(); tpid = fork();
if (!tpid) { if (!tpid) {
dup2(fd, 0); dup2(fileno(ftp), 0);
i = execl("/usr/bin/tar", "tar", Verbose ? "-xzvf" : "-xzf", "-", 0); i = execl("/usr/bin/tar", "tar", Verbose ? "-xzvf" : "-xzf", "-", 0);
if (Verbose) if (Verbose)
printf("tar command returns %d status\n", i); printf("tar command returns %d status\n", i);
@@ -280,7 +262,7 @@ fileGetURL(char *base, char *spec)
else { else {
int pstat; int pstat;
close(fd); fclose(ftp);
tpid = waitpid(tpid, &pstat, 0); tpid = waitpid(tpid, &pstat, 0);
} }
} }
@@ -288,9 +270,8 @@ fileGetURL(char *base, char *spec)
printf("Error: Unable to construct a new playpen for FTP!\n"); printf("Error: Unable to construct a new playpen for FTP!\n");
} }
else else
printf("Error: FTP Unable to get %s\n", basename_of(file)); printf("Error: FTP Unable to get %s\n", fname);
FtpEOF(ftp); fclose(ftp);
FtpClose(ftp);
return rp; return rp;
} }
-424
View File
@@ -1,424 +0,0 @@
/*
* ----------------------------------------------------------------------------
* "THE BEER-WARE LICENSE" (Revision 42):
* <phk@login.dknet.dk> wrote this file. As long as you retain this notice you
* can do whatever you want with this stuff. If we meet some day, and you think
* this stuff is worth it, you can buy me a beer in return. Poul-Henning Kamp
* ----------------------------------------------------------------------------
*
* $Id: ftp.c,v 1.2 1995/07/31 02:27:58 jkh Exp $
*
* Return values have been sanitized:
* -1 error, but you (still) have a session.
* -2 error, your session is dead.
*
*/
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <netdb.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <ctype.h>
#include "ftp.h"
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
/* Handy global for us to stick the port # */
int FtpPort;
static void
debug(FTP_t ftp, const char *fmt, ...)
{
char p[BUFSIZ];
va_list ap;
va_start(ap, fmt);
strcpy(p,"LIBFTP: ");
(void) vsnprintf(p+strlen(p), sizeof p - strlen(p), fmt, ap);
va_end(ap);
write(ftp->fd_debug,p,strlen(p));
}
static int
writes(int fd, char *s)
{
int i = strlen(s);
if (i != write(fd,s,i))
return -2;
return 0;
}
static __inline char*
get_a_line(FTP_t ftp)
{
static char buf[BUFSIZ];
int i,j;
for(i=0;i<BUFSIZ;) {
j = read(ftp->fd_ctrl,buf+i,1);
if (j != 1)
return 0;
if (buf[i] == '\r' || buf[i] == '\n') {
if (!i)
continue;
buf[i] = '\0';
debug(ftp, "received <%s>\n",buf);
return buf;
}
i++;
}
return buf;
}
static int
get_a_number(FTP_t ftp, char **q)
{
char *p;
int i = -1,j;
while(1) {
p = get_a_line(ftp);
if (!p)
return -2;
if (!(isdigit(p[0]) && isdigit(p[1]) && isdigit(p[2])))
continue;
if (i == -1 && p[3] == '-') {
i = strtol(p, 0, 0);
continue;
}
if (p[3] != ' ' && p[3] != '\t')
continue;
j = strtol(p, 0, 0);
if (i == -1) {
if (q) *q = p+4;
return j;
} else if (j == i) {
if (q) *q = p+4;
return j;
}
}
}
static int
zap(FTP_t ftp)
{
int i;
i = writes(ftp->fd_ctrl,"QUIT\r\n");
debug(ftp, "Zapping ftp connection on %d returns %d\n", ftp->fd_ctrl, i);
close(ftp->fd_ctrl); ftp->fd_ctrl = -1;
close(ftp->fd_xfer); ftp->fd_xfer = -1;
ftp->state = init;
return -2;
}
static int
botch(FTP_t ftp, char *func, char *state)
{
debug(ftp, "Botch: %s called outside state %s\n",func,state);
return -2;
}
static int
cmd(FTP_t ftp, const char *fmt, ...)
{
char p[BUFSIZ];
int i;
va_list ap;
va_start(ap, fmt);
(void) vsnprintf(p, sizeof p, fmt, ap);
va_end(ap);
debug(ftp, "send <%s>\n",p);
strcat(p,"\r\n");
if (writes(ftp->fd_ctrl,p))
return -2;
i = get_a_number(ftp,0);
return i;
}
FTP_t
FtpInit()
{
FTP_t ftp;
ftp = malloc(sizeof *ftp);
if (!ftp)
return ftp;
memset(ftp, 0, sizeof *ftp);
ftp->fd_ctrl = -1;
ftp->fd_xfer = -1;
ftp->fd_debug = -1;
ftp->state = init;
return ftp;
}
void
FtpDebug(FTP_t ftp, int i)
{
ftp->fd_debug = i;
}
int
FtpOpen(FTP_t ftp, char *host, char *user, char *passwd)
{
struct hostent *he = NULL;
struct sockaddr_in sin;
int s;
unsigned long temp;
int i;
if (ftp->state != init)
return botch(ftp,"FtpOpen","init");
if (!user)
user = "ftp";
if (!passwd)
passwd = "??@??(FreeBSD:libftp)"; /* XXX */
debug(ftp, "FtpOpen(ftp, %s, %s, %s)\n", host, user, passwd);
temp = inet_addr(host);
if (temp != INADDR_NONE) {
debug(ftp, "Using dotted IP address `%s'\n", host);
ftp->addrtype = sin.sin_family = AF_INET;
sin.sin_addr.s_addr = temp;
}
else {
debug(ftp, "Trying to resolve `%s'\n", host);
he = gethostbyname(host);
if (!he) {
debug(ftp, "Lookup of `%s' failed!\n", host);
return zap(ftp);
}
ftp->addrtype = sin.sin_family = he->h_addrtype;
bcopy(he->h_addr, (char *)&sin.sin_addr, he->h_length);
}
sin.sin_port = htons(FtpPort ? FtpPort : 21);
if ((s = socket(ftp->addrtype, SOCK_STREAM, 0)) < 0)
{
debug(ftp, "Socket open failed: %s (%i)\n", strerror(errno), errno);
return zap(ftp);
}
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
debug(ftp,"Connection failed: %s (%i)\n", strerror(errno), errno);
(void)close(s);
return zap(ftp);
}
ftp->fd_ctrl = s;
debug(ftp, "open (%d)\n",get_a_number(ftp,0));
i = cmd(ftp,"USER %s",user);
if (i >= 300 && i < 400)
i = cmd(ftp,"PASS %s",passwd);
if (i >= 299 || i < 0) {
close(ftp->fd_ctrl); ftp->fd_ctrl = -1;
return zap(ftp);
}
ftp->state = isopen;
return 0;
}
void
FtpClose(FTP_t ftp)
{
if (ftp->state != init)
return;
if (ftp->state != isopen)
botch(ftp,"FtpClose","open or init");
debug(ftp, "FtpClose(ftp)\n");
zap(ftp);
}
int
FtpChdir(FTP_t ftp, char *dir)
{
int i;
if (ftp->state != isopen)
return botch(ftp,"FtpChdir","open");
i = cmd(ftp,"CWD %s",dir);
if (i < 0)
return i;
else if (i != 250)
return -1;
return 0;
}
int
FtpGet(FTP_t ftp, char *file)
{
int i,s;
char *q;
unsigned char addr[64];
struct sockaddr_in sin;
u_long a;
debug(ftp, "FtpGet(ftp,%s)\n",file);
if (ftp->state != isopen)
return botch(ftp,"FtpGet","open");
if(ftp->binary) {
i = cmd(ftp,"TYPE I");
if (i < 0)
return zap(ftp);
if (i > 299)
return -1;
} else {
return -1;
}
if ((s = socket(ftp->addrtype, SOCK_STREAM, 0)) < 0)
return zap(ftp);
if (ftp->passive) {
debug(ftp, "send <%s>\n","PASV");
if (writes(ftp->fd_ctrl,"PASV\r\n"))
return zap(ftp);
i = get_a_number(ftp,&q);
if (i < 0)
return zap(ftp);
if (i != 227)
return zap(ftp);
while (*q && !isdigit(*q))
q++;
if (!*q)
return zap(ftp);
q--;
for(i=0;i<6;i++) {
q++;
addr[i] = strtol(q,&q,10);
}
sin.sin_family = ftp->addrtype;
bcopy(addr, (char *)&sin.sin_addr, 4);
bcopy(addr+4, (char *)&sin.sin_port, 2);
debug(ftp, "Opening active socket to %s : %u\n", inet_ntoa(sin.sin_addr), htons(sin.sin_port));
debug(ftp, "Connecting to %s:%u\n", inet_ntoa(sin.sin_addr), htons(sin.sin_port));
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
(void)close(s);
debug(ftp, "connect: %s (%d)\n", strerror(errno), errno);
return -1;
}
ftp->fd_xfer = s;
i = cmd(ftp,"RETR %s",file);
if (i < 0) {
close(s);
return zap(ftp);
}
else if (i > 299) {
debug(ftp, "FTP: No such file %s, moving on.\n", file);
close(s);
return -1;
}
ftp->state = xfer;
return s;
} else {
i = sizeof sin;
getsockname(ftp->fd_ctrl,(struct sockaddr *)&sin,&i);
sin.sin_port = 0;
i = sizeof sin;
if (bind(s,(struct sockaddr *)&sin, i) < 0) {
close (s);
debug(ftp,"bind failed %d\n",errno);
return zap(ftp);
}
getsockname(s,(struct sockaddr *)&sin,&i);
if (listen(s,1) < 0) {
close (s);
debug(ftp,"listen failed %d\n",errno);
return zap(ftp);
}
a = ntohl(sin.sin_addr.s_addr);
i = cmd(ftp,"PORT %d,%d,%d,%d,%d,%d",
(a >> 24) & 0xff,
(a >> 16) & 0xff,
(a >> 8) & 0xff,
a & 0xff,
(ntohs(sin.sin_port) >> 8) & 0xff,
ntohs(sin.sin_port) & 0xff);
if (i != 200)
return -1;
i = cmd(ftp,"RETR %s",file);
if (i < 0) {
close(s);
return zap(ftp);
}
else if (i > 299) {
debug(ftp, "FTP: No such file %s, moving on.\n", file);
close(s);
return -1;
}
ftp->fd_xfer = accept(s, 0, 0);
if (ftp->fd_xfer < 0) {
close(s);
return zap(ftp);
}
ftp->state = xfer;
close(s);
return(ftp->fd_xfer);
}
}
int
FtpEOF(FTP_t ftp)
{
int i;
if (ftp->state != xfer)
return botch(ftp,"FtpEOF","xfer");
debug(ftp, "FtpEOF(ftp)\n");
close(ftp->fd_xfer); ftp->fd_xfer = -1;
ftp->state = isopen;
i = get_a_number(ftp,0);
if (i < 0)
return zap(ftp);
else if (i != 250 && i != 226)
return -1;
else
return 0;
}
#ifdef STANDALONE_FTP
/* main.c */
int
main(int argc, char **argv)
{
FTP_t ftp;
int i;
char c;
ftp = FtpInit();
if (!ftp)
err(1, "FtpInit()");
FtpDebug(ftp, 1);
i = FtpOpen(ftp, "freefall.cdrom.com", "ftp", "phk-libftp@");
FtpBinary(ftp, 1);
FtpPassive(ftp, 0);
FtpChdir(ftp, "/pub");
FtpChdir(ftp, "FreeBSD");
i = FtpGet(ftp, "README");
while (1 == read(i, &c, 1))
putchar(c);
FtpEOF(ftp);
return 0;
}
#endif /*STANDALONE_FTP*/
-26
View File
@@ -1,26 +0,0 @@
#ifndef _FTP_H_INCLUDE
#define _FTP_H_INCLUDE
typedef struct {
enum {init, isopen, xfer} state;
int fd_ctrl;
int fd_xfer;
int fd_debug;
int binary;
int passive;
int addrtype;
char *host;
char *file;
} *FTP_t;
FTP_t FtpInit();
int FtpOpen(FTP_t, char *host, char *user, char *passwd);
#define FtpBinary(ftp,bool) { (ftp)->binary = (bool); }
#define FtpPassive(ftp,bool) { (ftp)->passive = (bool); }
int FtpChdir(FTP_t, char *);
int FtpGet(FTP_t, char *);
int FtpEOF(FTP_t);
void FtpClose(FTP_t);
#endif
/* _FTP_H_INCLUDE */
+4 -1
View File
@@ -1,4 +1,4 @@
/* $Id: lib.h,v 1.19 1995/10/25 15:38:34 jkh Exp $ */ /* $Id: lib.h,v 1.20 1996/06/08 00:46:32 alex Exp $ */
/* /*
* FreeBSD install - a package for the installation and maintainance * FreeBSD install - a package for the installation and maintainance
@@ -123,6 +123,8 @@ char *strconcat(char *, char *);
/* File */ /* File */
Boolean fexists(char *); Boolean fexists(char *);
Boolean isdir(char *); Boolean isdir(char *);
Boolean isemptydir(char *fname);
Boolean isemptyfile(char *fname);
Boolean isfile(char *); Boolean isfile(char *);
Boolean isempty(char *); Boolean isempty(char *);
Boolean isURL(char *); Boolean isURL(char *);
@@ -156,6 +158,7 @@ void mark_plist(Package *);
void csum_plist_entry(char *, PackingList); void csum_plist_entry(char *, PackingList);
void add_plist(Package *, plist_t, char *); void add_plist(Package *, plist_t, char *);
void add_plist_top(Package *, plist_t, char *); void add_plist_top(Package *, plist_t, char *);
void delete_plist(Package *pkg, Boolean all, plist_t type, char *name);
void write_plist(Package *, FILE *); void write_plist(Package *, FILE *);
void read_plist(Package *, FILE *); void read_plist(Package *, FILE *);
int plist_cmd(char *, char **); int plist_cmd(char *, char **);
+1 -3
View File
@@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static const char *rcsid = "$Id: pen.c,v 1.20 1996/02/09 12:05:26 jkh Exp $"; static const char *rcsid = "$Id: pen.c,v 1.21 1996/06/08 00:46:33 alex Exp $";
#endif #endif
/* /*
@@ -72,8 +72,6 @@ find_play_pen(char *pen, size_t sz)
char * char *
make_playpen(char *pen, size_t sz) make_playpen(char *pen, size_t sz)
{ {
char *tmp;
if (!find_play_pen(pen, sz)) if (!find_play_pen(pen, sz))
return NULL; return NULL;
+2 -2
View File
@@ -1,5 +1,5 @@
#ifndef lint #ifndef lint
static const char *rcsid = "$Id: plist.c,v 1.14 1995/07/28 01:50:35 ache Exp $"; static const char *rcsid = "$Id: plist.c,v 1.15 1995/11/12 04:55:40 jkh Exp $";
#endif #endif
/* /*
@@ -378,7 +378,7 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg)
sprintf(full_name, "%s/%s", Where, p->name); sprintf(full_name, "%s/%s", Where, p->name);
if (isdir(full_name) && p->type == PLIST_FILE) { if (isdir(full_name) && p->type == PLIST_FILE) {
warn("Attempting to delete directory `%s' as a file\n" whinge("Attempting to delete directory `%s' as a file\n"
"This packing list is incorrect - ignoring delete request.\n", full_name); "This packing list is incorrect - ignoring delete request.\n", full_name);
} }
else { else {