diff options
author | jkh <jkh@FreeBSD.org> | 1996-06-20 18:33:55 +0000 |
---|---|---|
committer | jkh <jkh@FreeBSD.org> | 1996-06-20 18:33:55 +0000 |
commit | e8d26b1581dab3026009757a94a8134f0fd851ae (patch) | |
tree | dba527c7f22937fd67058464959dfb7d8498f44d | |
parent | 0f52bd5cc8f1e74e89612834f46148b97a43991e (diff) | |
download | FreeBSD-src-e8d26b1581dab3026009757a94a8134f0fd851ae.zip FreeBSD-src-e8d26b1581dab3026009757a94a8134f0fd851ae.tar.gz |
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.
-rw-r--r-- | usr.sbin/pkg_install/add/Makefile | 2 | ||||
-rw-r--r-- | usr.sbin/pkg_install/add/perform.c | 14 | ||||
-rw-r--r-- | usr.sbin/pkg_install/create/Makefile | 2 | ||||
-rw-r--r-- | usr.sbin/pkg_install/create/perform.c | 5 | ||||
-rw-r--r-- | usr.sbin/pkg_install/delete/Makefile | 3 | ||||
-rw-r--r-- | usr.sbin/pkg_install/delete/main.c | 3 | ||||
-rw-r--r-- | usr.sbin/pkg_install/delete/perform.c | 6 | ||||
-rw-r--r-- | usr.sbin/pkg_install/info/Makefile | 3 | ||||
-rw-r--r-- | usr.sbin/pkg_install/info/show.c | 5 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/Makefile | 2 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/file.c | 63 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/ftp.c | 424 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/ftp.h | 26 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/lib.h | 5 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/pen.c | 4 | ||||
-rw-r--r-- | usr.sbin/pkg_install/lib/plist.c | 4 |
16 files changed, 55 insertions, 516 deletions
diff --git a/usr.sbin/pkg_install/add/Makefile b/usr.sbin/pkg_install/add/Makefile index e0fdcff..ade7e57 100644 --- a/usr.sbin/pkg_install/add/Makefile +++ b/usr.sbin/pkg_install/add/Makefile @@ -10,6 +10,8 @@ LDADD+= -L${.CURDIR}/../lib -linstall DPADD+= ${.CURDIR}/../lib/libinstall.a .endif +LDADD+= -lftpio +DPADD+= ${LIBFTPIO} SRCS= main.c perform.c futil.c extract.c diff --git a/usr.sbin/pkg_install/add/perform.c b/usr.sbin/pkg_install/add/perform.c index 004691d..2f044ad 100644 --- a/usr.sbin/pkg_install/add/perform.c +++ b/usr.sbin/pkg_install/add/perform.c @@ -1,5 +1,5 @@ #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 /* @@ -68,8 +68,6 @@ pkg_do(char *pkg) int code; PackingList p; struct stat sb; - char *isTMP = NULL; - char *cp; int inPlace; code = 0; @@ -212,8 +210,6 @@ pkg_do(char *pkg) /* See if we're already registered */ sprintf(LogDir, "%s/%s", (tmp = getenv(PKG_DBDIR)) ? tmp : DEF_LOG_DIR, PkgName); if (isdir(LogDir)) { - char tmp[FILENAME_MAX]; - whinge("Package `%s' already recorded as installed.\n", PkgName); code = 1; goto success; /* close enough for government work */ @@ -393,16 +389,17 @@ pkg_do(char *pkg) else { fprintf(cfile, "%s\n", PkgName); if (fclose(cfile) == EOF) - warn("Cannot properly close file %s", contents); + whinge("Cannot properly close file %s", contents); } } if (Verbose) 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; char buf[BUFSIZ]; + fp = fopen(p->name, "r"); if (fp) { putc('\n', stdout); @@ -411,7 +408,7 @@ pkg_do(char *pkg) putc('\n', stdout); (void) fclose(fp); } else - warn("Cannot open display file `%s'.", p->name); + whinge("Cannot open display file `%s'.", p->name); } goto success; @@ -435,7 +432,6 @@ pkg_do(char *pkg) static int sanity_check(char *pkg) { - PackingList p; int code = 0; if (!fexists(CONTENTS_FNAME)) { diff --git a/usr.sbin/pkg_install/create/Makefile b/usr.sbin/pkg_install/create/Makefile index ff33874..fda22e7 100644 --- a/usr.sbin/pkg_install/create/Makefile +++ b/usr.sbin/pkg_install/create/Makefile @@ -10,6 +10,8 @@ LDADD+= -L${.CURDIR}/../lib -linstall DPADD+= ${.CURDIR}/../lib/libinstall.a .endif +LDADD+= -lftpio +DPADD+= ${LIBFTPIO} SRCS= main.c perform.c pl.c diff --git a/usr.sbin/pkg_install/create/perform.c b/usr.sbin/pkg_install/create/perform.c index c37459f..c3004ee 100644 --- a/usr.sbin/pkg_install/create/perform.c +++ b/usr.sbin/pkg_install/create/perform.c @@ -1,5 +1,5 @@ #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 /* @@ -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 <signal.h> #include <sys/syslimits.h> +#include <sys/wait.h> #include <unistd.h> static void sanity_check(void); @@ -184,7 +185,7 @@ make_dist(char *home, char *pkg, char *suffix, Package *plist) { char tball[FILENAME_MAX]; PackingList p; - int ret, max, len; + int ret; char *args[50]; /* Much more than enough. */ int nargs = 0; int pipefds[2]; diff --git a/usr.sbin/pkg_install/delete/Makefile b/usr.sbin/pkg_install/delete/Makefile index 0c50a2a..38c6802 100644 --- a/usr.sbin/pkg_install/delete/Makefile +++ b/usr.sbin/pkg_install/delete/Makefile @@ -9,6 +9,9 @@ LDADD+= -L${.CURDIR}/../lib -linstall DPADD+= ${.CURDIR}/../lib/libinstall.a .endif +LDADD+= -lftpio +DPADD+= ${LIBFTPIO} + SRCS= main.c perform.c .include <bsd.prog.mk> diff --git a/usr.sbin/pkg_install/delete/main.c b/usr.sbin/pkg_install/delete/main.c index 66a4f8e..10d0c18 100644 --- a/usr.sbin/pkg_install/delete/main.c +++ b/usr.sbin/pkg_install/delete/main.c @@ -1,5 +1,5 @@ #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 /* @@ -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 "delete.h" +#include <err.h> static char Options[] = "hvDdnfp:"; diff --git a/usr.sbin/pkg_install/delete/perform.c b/usr.sbin/pkg_install/delete/perform.c index fefe6e8..dd3810a 100644 --- a/usr.sbin/pkg_install/delete/perform.c +++ b/usr.sbin/pkg_install/delete/perform.c @@ -1,5 +1,5 @@ #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 /* @@ -123,7 +123,7 @@ pkg_do(char *pkg) if (!Fake) { /* Some packages aren't packed right, so we need to just ignore delete_package()'s status. Ugh! :-( */ 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"); if (vsystem("%s -r %s", REMOVE_CMD, LogDir)) { whinge("Couldn't remove log entry in %s, de-install failed.", LogDir); @@ -206,7 +206,7 @@ undepend(PackingList p, char *pkgname) return; } 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 */ return; } diff --git a/usr.sbin/pkg_install/info/Makefile b/usr.sbin/pkg_install/info/Makefile index 3542e8d..8c5098c 100644 --- a/usr.sbin/pkg_install/info/Makefile +++ b/usr.sbin/pkg_install/info/Makefile @@ -9,6 +9,9 @@ LDADD+= -L${.CURDIR}/../lib -linstall DPADD+= ${.CURDIR}/../lib/libinstall.a .endif +LDADD+= -lftpio +DPADD+= ${LIBFTPIO} + SRCS= main.c perform.c show.c .include <bsd.prog.mk> diff --git a/usr.sbin/pkg_install/info/show.c b/usr.sbin/pkg_install/info/show.c index d4d4f3f..f410a6a 100644 --- a/usr.sbin/pkg_install/info/show.c +++ b/usr.sbin/pkg_install/info/show.c @@ -1,5 +1,5 @@ #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 /* @@ -38,7 +38,7 @@ show_file(char *title, char *fname) if (!fp) printf("ERROR: show_file: Can't open '%s' for reading!\n", fname); else { - while (n = fread(line, 1, 1024, fp)) + while ((n = fread(line, 1, 1024, fp)) != 0) fwrite(line, 1, n, stdout); fclose(fp); } @@ -50,7 +50,6 @@ show_index(char *title, char *fname) { FILE *fp; char line[MAXINDEXSIZE+2]; - int i,n; if (!Quiet) printf("%s%s", InfoPrefix, title); diff --git a/usr.sbin/pkg_install/lib/Makefile b/usr.sbin/pkg_install/lib/Makefile index 223a33d..3876b10 100644 --- a/usr.sbin/pkg_install/lib/Makefile +++ b/usr.sbin/pkg_install/lib/Makefile @@ -1,5 +1,5 @@ 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} NOPROFILE= yes NOPIC= yes diff --git a/usr.sbin/pkg_install/lib/file.c b/usr.sbin/pkg_install/lib/file.c index 19ce013..8f69b96 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.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 /* @@ -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 "ftp.h" +#include <ftpio.h> #include <pwd.h> #include <time.h> +#include <sys/wait.h> /* Quick check to see if a file exists */ Boolean @@ -123,7 +124,7 @@ fileURLHost(char *fname, char *where, int max) /* Don't ever call this on a bad URL! */ fname += strlen("ftp://"); /* Do we have a place to stick our work? */ - if (ret = where) { + if ((ret = where) != NULL) { while (*fname && *fname != '/' && max--) *where++ = *fname++; *where = '\0'; @@ -148,7 +149,7 @@ fileURLFilename(char *fname, char *where, int max) /* Don't ever call this on a bad URL! */ fname += strlen("ftp://"); /* Do we have a place to stick our work? */ - if (ret = where) { + if ((ret = where) != NULL) { while (*fname && *fname != '/') ++fname; if (*fname == '/') { @@ -172,24 +173,20 @@ fileURLFilename(char *fname, char *where, int max) char * fileGetURL(char *base, char *spec) { - char host[HOSTNAME_MAX], file[FILENAME_MAX], dir[FILENAME_MAX]; - char pword[HOSTNAME_MAX + 40], *uname, *cp, *rp, *tmp; + char host[HOSTNAME_MAX], file[FILENAME_MAX]; + char pword[HOSTNAME_MAX + 40], *uname, *cp, *rp; char fname[FILENAME_MAX]; char pen[FILENAME_MAX]; struct passwd *pw; - FTP_t ftp; + FILE *ftp; pid_t tpid; - int fd, fd2, i, len = 0; - char ch; - time_t start, stop; + int i; char *hint; rp = NULL; /* Special tip that sysinstall left for us */ hint = getenv("PKG_ADD_BASE"); if (!isURL(spec)) { - int len; - if (!base && !hint) return NULL; /* 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 strcpy(fname, spec); - ftp = FtpInit(); cp = fileURLHost(fname, host, HOSTNAME_MAX); if (!*cp) { 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()); strcpy(pword, "joe@"); } - else - snprintf(pword, HOSTNAME_MAX + 40, "%s@%s", pw->pw_name, host); + else { + char me[HOSTNAME_MAX]; - if (Verbose) - printf("Trying to log into %s as %s.\n", host, uname); - 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); + gethostname(me, HOSTNAME_MAX); + snprintf(pword, HOSTNAME_MAX + 40, "%s@%s", pw->pw_name, me); } - FtpBinary(ftp, TRUE); - if (Verbose) printf("FTP: trying to get %s\n", basename_of(file)); - tmp = basename_of(file); - if (!strstr(tmp, ".tgz")) - tmp = strconcat(tmp, ".tgz"); - fd = FtpGet(ftp, tmp); - if (fd >= 0) { + if (Verbose) + printf("Trying to fetch %s.\n", fname); + ftp = ftpGetURL(fname, uname, pword); + if (ftp) { pen[0] = '\0'; - if (rp = make_playpen(pen, 0)) { + if ((rp = make_playpen(pen, 0)) != NULL) { if (Verbose) printf("Extracting from FTP connection into %s\n", pen); tpid = fork(); if (!tpid) { - dup2(fd, 0); + dup2(fileno(ftp), 0); i = execl("/usr/bin/tar", "tar", Verbose ? "-xzvf" : "-xzf", "-", 0); if (Verbose) printf("tar command returns %d status\n", i); @@ -280,7 +262,7 @@ fileGetURL(char *base, char *spec) else { int pstat; - close(fd); + fclose(ftp); 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"); } else - printf("Error: FTP Unable to get %s\n", basename_of(file)); - FtpEOF(ftp); - FtpClose(ftp); + printf("Error: FTP Unable to get %s\n", fname); + fclose(ftp); return rp; } diff --git a/usr.sbin/pkg_install/lib/ftp.c b/usr.sbin/pkg_install/lib/ftp.c deleted file mode 100644 index 7b78ee4..0000000 --- a/usr.sbin/pkg_install/lib/ftp.c +++ /dev/null @@ -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*/ diff --git a/usr.sbin/pkg_install/lib/ftp.h b/usr.sbin/pkg_install/lib/ftp.h deleted file mode 100644 index 9275dd4..0000000 --- a/usr.sbin/pkg_install/lib/ftp.h +++ /dev/null @@ -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 */ diff --git a/usr.sbin/pkg_install/lib/lib.h b/usr.sbin/pkg_install/lib/lib.h index 2dafbc6..95ac9a1 100644 --- a/usr.sbin/pkg_install/lib/lib.h +++ b/usr.sbin/pkg_install/lib/lib.h @@ -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 @@ -123,6 +123,8 @@ char *strconcat(char *, char *); /* File */ Boolean fexists(char *); Boolean isdir(char *); +Boolean isemptydir(char *fname); +Boolean isemptyfile(char *fname); Boolean isfile(char *); Boolean isempty(char *); Boolean isURL(char *); @@ -156,6 +158,7 @@ void mark_plist(Package *); void csum_plist_entry(char *, PackingList); void add_plist(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 read_plist(Package *, FILE *); int plist_cmd(char *, char **); diff --git a/usr.sbin/pkg_install/lib/pen.c b/usr.sbin/pkg_install/lib/pen.c index 98a7d71..33ace5f 100644 --- a/usr.sbin/pkg_install/lib/pen.c +++ b/usr.sbin/pkg_install/lib/pen.c @@ -1,5 +1,5 @@ #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 /* @@ -72,8 +72,6 @@ find_play_pen(char *pen, size_t sz) char * make_playpen(char *pen, size_t sz) { - char *tmp; - if (!find_play_pen(pen, sz)) return NULL; diff --git a/usr.sbin/pkg_install/lib/plist.c b/usr.sbin/pkg_install/lib/plist.c index 132c6e1..2a5c674 100644 --- a/usr.sbin/pkg_install/lib/plist.c +++ b/usr.sbin/pkg_install/lib/plist.c @@ -1,5 +1,5 @@ #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 /* @@ -378,7 +378,7 @@ delete_package(Boolean ign_err, Boolean nukedirs, Package *pkg) sprintf(full_name, "%s/%s", Where, p->name); 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); } else { |