diff options
author | jbj <devnull@localhost> | 1999-11-18 18:07:46 +0000 |
---|---|---|
committer | jbj <devnull@localhost> | 1999-11-18 18:07:46 +0000 |
commit | 1f6614e61efc520d2da0c09604d4ee1c06117073 (patch) | |
tree | ed7066a82ca608c08be5fbe194611486349eb1a5 /lib | |
parent | 3a6118d4194d9672b24cd7b357e6191f4eb47fde (diff) | |
download | rpm-1f6614e61efc520d2da0c09604d4ee1c06117073.tar.gz rpm-1f6614e61efc520d2da0c09604d4ee1c06117073.tar.bz2 rpm-1f6614e61efc520d2da0c09604d4ee1c06117073.zip |
The death of lib/ftp.c, merged into lib/rpmio.c.
Start composting the rpmio API.
Preliminary (not working) support for HTTP PUT.
build.c: Check fd for NULL and use Ferror() for Fopen return.
build/parseSpec.c: ditto
build/pack.c: Use fdGetFP() rather than fpio->ffileno().
build/parseSpec.c: ditto
build/pack.c: Use Stat/Mkdir wrappers.
build/pack.c: Do Fflush before fdDup so that writes can remain buffered.
lib/install.c: ditto
build/parsePrep.c: Skip over URL leadin when writing %prep scriptlet.
lib/misc.c: Rewrite to use simpler urlPath(). Restore checks on local fs.
lib/rpmchecksig.c: Open with "r+" rather than "w" to avoid truncation.
lib/url.c: Do lazy malloc of u->buf in rpmio.c checkResponse().
lib/rpmio.c: Make persist/contentLength per-fd rather than per-url.
lib/rpmio.c: Add wr_chunked method for HTTP PUT (still broken).
lib/rpmio.c: ftpAbort() should use timedRead.
lib/rpmio.c: Add Fflush().
lib/url.c: urlPath() should return something ("/") on url = NULL (paranoia).
lib/url.c: urlSplit() should return something ("/") on url w/o path.
CVS patchset: 3429
CVS date: 1999/11/18 18:07:46
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Makefile.am | 2 | ||||
-rw-r--r-- | lib/ftp.c | 663 | ||||
-rw-r--r-- | lib/install.c | 5 | ||||
-rw-r--r-- | lib/misc.c | 74 | ||||
-rw-r--r-- | lib/rpmchecksig.c | 2 | ||||
-rw-r--r-- | lib/rpmio.h | 31 | ||||
-rw-r--r-- | lib/rpmurl.h | 30 | ||||
-rw-r--r-- | lib/url.c | 24 |
8 files changed, 82 insertions, 749 deletions
diff --git a/lib/Makefile.am b/lib/Makefile.am index 5b3049db5..a8bd2de21 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -25,7 +25,7 @@ mylibs= $(top_builddir)/lib/.libs/librpm.a \ lib_LTLIBRARIES = librpm.la librpm_la_SOURCES = \ cpio.c dbindex.c depends.c falloc.c \ - formats.c fprint.c fs.c ftp.c hash.c header.c install.c \ + formats.c fprint.c fs.c hash.c header.c install.c \ lookup.c macro.c md5.c md5sum.c \ messages.c misc.c oldheader.c package.c problems.c query.c \ rebuilddb.c rpmchecksig.c rpmdb.c rpmerr.c rpminstall.c \ diff --git a/lib/ftp.c b/lib/ftp.c deleted file mode 100644 index da60d2cf8..000000000 --- a/lib/ftp.c +++ /dev/null @@ -1,663 +0,0 @@ -#include "system.h" - -#include <assert.h> - -#if !defined(HAVE_CONFIG_H) -#define HAVE_MACHINE_TYPES_H 1 -#define HAVE_ALLOCA_H 1 -#define HAVE_NETINET_IN_SYSTM_H 1 -#define HAVE_SYS_SOCKET_H 1 -#endif - -#if ! HAVE_HERRNO -extern int h_errno; -#endif - -#include <stdarg.h> - -#ifdef __LCLINT__ -#define ntohl(_x) (_x) -#define ntohs(_x) (_x) -#define htonl(_x) (_x) -#define htons(_x) (_x) -typedef unsigned int uint32_t; -#define INADDR_ANY ((uint32_t) 0x00000000) -#define IPPROTO_IP 0 -extern int h_errno; - -#else /* __LCLINT__ */ - -#if HAVE_MACHINE_TYPES_H -# include <machine/types.h> -#endif - -#if HAVE_NETINET_IN_SYSTM_H -# include <sys/types.h> -# include <netinet/in_systm.h> -#endif - -#include <netinet/in.h> -#include <netinet/ip.h> -#include <arpa/inet.h> -#include <arpa/telnet.h> -#endif /* __LCLINT__ */ - -#include <rpmlib.h> - -#if !defined(HAVE_INET_ATON) -int inet_aton(const char *cp, struct in_addr *inp); -#endif - -#if defined(USE_ALT_DNS) && USE_ALT_DNS -#include "dns.h" -#endif - -#include <rpmurl.h> -/*@access urlinfo@*/ - -#ifdef __MINT__ -# ifndef EAGAIN -# define EAGAIN EWOULDBLOCK -# endif -# ifndef O_NONBLOCK -# define O_NONBLOCK O_NDELAY -# endif -#endif - -int _ftp_debug = 0; -#define DBG(_f, _x) if ((_ftp_debug | (_f))) fprintf _x - -static int checkResponse(urlinfo u, /*@out@*/ int *ecp, /*@out@*/ char ** str) -{ - char *buf; - size_t bufAlloced; - int bufLength = 0; - const char *s; - char *se; - int ec = 0; - int moretodo = 1; - char errorCode[4]; - - URLSANE(u); - buf = u->buf; - bufAlloced = u->bufAlloced; - *buf = '\0'; - - errorCode[0] = '\0'; - - do { - int rc; - - /* - * Read next line from server. - */ - se = buf + bufLength; - *se = '\0'; - rc = fdRdline(u->ctrl, se, (bufAlloced - bufLength)); - if (rc < 0) { - ec = FTPERR_BAD_SERVER_RESPONSE; - continue; - } else if (rc == 0 || fdWritable(u->ctrl, 0) < 1) - moretodo = 0; - - /* - * Process next line from server. - */ - for (s = se; *s != '\0'; s = se) { - const char *e; - - while (*se && *se != '\n') se++; - - if (se > s && se[-1] == '\r') - se[-1] = '\0'; - if (*se == '\0') - break; - - DBG(0, (stderr, "<- %s\n", s)); - - /* HTTP: header termination on empty line */ - if (*s == '\0') { - moretodo = 0; - break; - } - *se++ = '\0'; - - /* HTTP: look for "HTTP/1.1 123 ..." */ - if (!strncmp(s, "HTTP", sizeof("HTTP")-1)) { - u->httpContentLength = -1; - if ((e = strchr(s, '.')) != NULL) { - e++; - u->httpVersion = *e - '0'; - if (u->httpVersion < 1 || u->httpVersion > 2) - u->httpPersist = u->httpVersion = 0; - else - u->httpPersist = 1; - } - if ((e = strchr(s, ' ')) != NULL) { - e++; - if (strchr("0123456789", *e)) - strncpy(errorCode, e, 3); - errorCode[3] = '\0'; - } - continue; - } - - /* HTTP: look for "token: ..." */ - for (e = s; *e && !(*e == ' ' || *e == ':'); e++) - ; - if (e > s && *e++ == ':') { - size_t ne = (e - s); - while (*e && *e == ' ') e++; -#if 0 - if (!strncmp(s, "Date:", ne)) { - } else - if (!strncmp(s, "Server:", ne)) { - } else - if (!strncmp(s, "Last-Modified:", ne)) { - } else - if (!strncmp(s, "ETag:", ne)) { - } else -#endif - if (!strncmp(s, "Accept-Ranges:", ne)) { - if (!strcmp(e, "bytes")) - u->httpHasRange = 1; - if (!strcmp(e, "none")) - u->httpHasRange = 0; - } else - if (!strncmp(s, "Content-Length:", ne)) { - if (strchr("0123456789", *e)) - u->httpContentLength = atoi(e); - } else - if (!strncmp(s, "Connection:", ne)) { - if (!strcmp(e, "close")) - u->httpPersist = 0; - } else -#if 0 - if (!strncmp(s, "Content-Type:", ne)) { - } else - if (!strncmp(s, "Transfer-Encoding:", ne)) { - } else - if (!strncmp(s, "Allow:", ne)) { - } else -#endif - ; - continue; - } - - /* HTTP: look for "<TITLE>501 ... </TITLE>" */ - if (!strncmp(s, "<TITLE>", sizeof("<TITLE>")-1)) - s += sizeof("<TITLE>") - 1; - - /* FTP: look for "123-" and/or "123 " */ - if (strchr("0123456789", *s)) { - if (errorCode[0]) { - if (!strncmp(s, errorCode, sizeof("123")-1) && s[3] == ' ') - moretodo = 0; - } else { - strncpy(errorCode, s, sizeof("123")-1); - errorCode[3] = '\0'; - if (s[3] != '-') - moretodo = 0; - } - } - } - - if (moretodo && se > s) { - bufLength = se - s - 1; - if (s != buf) - memcpy(buf, s, bufLength); - } else { - bufLength = 0; - } - } while (moretodo && ec == 0); - - if (str) *str = buf; - if (ecp) *ecp = atoi(errorCode); - - return ec; -} - -int ftpCheckResponse(urlinfo u, /*@out@*/ char ** str) -{ - int ec = 0; - int rc; - - URLSANE(u); - rc = checkResponse(u, &ec, str); - - switch (ec) { - case 550: - return FTPERR_FILE_NOT_FOUND; - /*@notreached@*/ break; - case 552: - return FTPERR_NIC_ABORT_IN_PROGRESS; - /*@notreached@*/ break; - default: - if (ec >= 400 && ec <= 599) - return FTPERR_BAD_SERVER_RESPONSE; - break; - } - return rc; -} - -int ftpCommand(urlinfo u, ...) -{ - va_list ap; - int len = 0; - const char * s, * t; - char * te; - int rc; - - URLSANE(u); - va_start(ap, u); - while ((s = va_arg(ap, const char *)) != NULL) { - if (len) len++; - len += strlen(s); - } - len += sizeof("\r\n")-1; - va_end(ap); - - t = te = alloca(len + 1); - - va_start(ap, u); - while ((s = va_arg(ap, const char *)) != NULL) { - if (te > t) *te++ = ' '; - te = stpcpy(te, s); - } - te = stpcpy(te, "\r\n"); - va_end(ap); - - DBG(0, (stderr, "-> %s", t)); - if (fdio->write(u->ctrl, t, (te-t)) != (te-t)) - return FTPERR_SERVER_IO_ERROR; - - rc = ftpCheckResponse(u, NULL); - return rc; -} - -#if !defined(USE_ALT_DNS) || !USE_ALT_DNS -static int mygethostbyname(const char * host, struct in_addr * address) -{ - struct hostent * hostinfo; - - hostinfo = /*@-unrecog@*/ gethostbyname(host) /*@=unrecog@*/; - if (!hostinfo) return 1; - - memcpy(address, hostinfo->h_addr_list[0], sizeof(*address)); - return 0; -} -#endif - -static int getHostAddress(const char * host, struct in_addr * address) -{ - if (isdigit(host[0])) { - if (! /*@-unrecog@*/ inet_aton(host, address) /*@=unrecog@*/ ) { - return FTPERR_BAD_HOST_ADDR; - } - } else { - if (mygethostbyname(host, address)) { - errno = h_errno; - return FTPERR_BAD_HOSTNAME; - } - } - - return 0; -} - -static int tcpConnect(FD_t ctrl, const char *host, int port) -{ - struct sockaddr_in sin; - int fdno = -1; - int rc; - - sin.sin_family = AF_INET; - sin.sin_port = htons(port); - sin.sin_addr.s_addr = INADDR_ANY; - - do { - if ((rc = getHostAddress(host, &sin.sin_addr)) < 0) - break; - - if ((fdno = socket(sin.sin_family, SOCK_STREAM, IPPROTO_IP)) < 0) { - rc = FTPERR_FAILED_CONNECT; - break; - } - - if (connect(fdno, (struct sockaddr *) &sin, sizeof(sin))) { - rc = FTPERR_FAILED_CONNECT; - break; - } - } while (0); - - if (rc < 0) - goto errxit; - - DBG(0, (stderr,"++ connect %s:%d on fdno %d\n", - /*@-unrecog@*/ inet_ntoa(sin.sin_addr) /*@=unrecog@*/ , - ntohs(sin.sin_port), fdno)); - - return fdno; - -errxit: - fdSetSyserrno(ctrl, errno, ftpStrerror(rc)); - if (fdno >= 0) - close(fdno); - return rc; -} - -int httpOpen(urlinfo u, FD_t ctrl, const char *httpcmd) -{ - const char *host; - const char *path; - int port; - int rc; - char *req; - size_t len; - int retrying = 0; - - URLSANE(u); - assert(ctrl != NULL); - - if (((host = (u->proxyh ? u->proxyh : u->host)) == NULL)) - return FTPERR_BAD_HOSTNAME; - - if ((port = (u->proxyp > 0 ? u->proxyp : u->port)) < 0) port = 80; - path = (u->proxyh || u->proxyp > 0) ? u->url : u->path; - -reopen: - if (fdio->fileno(ctrl) >= 0 && (rc = fdWritable(ctrl, 0)) < 1) { -if (_ftp_debug) -fprintf(stderr, "*** httpOpen closing ctrl fdno %d rc %d\n", fdio->fileno(ctrl), rc); - fdio->close(ctrl); - } - - if (fdio->fileno(ctrl) < 0) { - rc = tcpConnect(ctrl, host, port); - fdSetFdno(ctrl, (rc >= 0 ? rc : -1)); - if (rc < 0) - goto errxit2; - - ctrl = fdLink(ctrl, "open ctrl (httpOpen)"); - } - - len = sizeof("\ -req x HTTP/1.0\r\n\ -User-Agent: rpm/3.0.4\r\n\ -Host: y:z\r\n\ -Accept: text/plain\r\n\ -\r\n\ -") + strlen(httpcmd) + strlen(path) + sizeof(VERSION) + strlen(host) + 20; - - req = alloca(len); - *req = '\0'; - - sprintf(req, "\ -%s %s HTTP/1.%d\r\n\ -User-Agent: rpm/%s\r\n\ -Host: %s:%d\r\n\ -Accept: text/plain\r\n\ -\r\n\ -", httpcmd, path, (u->httpVersion ? 1 : 0), VERSION, host, port); - - DBG(0, (stderr, "-> %s", req)); - - if (fdio->write(ctrl, req, len) != len) { - rc = FTPERR_SERVER_IO_ERROR; - goto errxit; - } - - { int ec = 0; - rc = checkResponse(u, &ec, NULL); - -if (_ftp_debug && !(rc == 0 && ec == 200)) -fprintf(stderr, "*** httpOpen: rc %d ec %d\n", rc, ec); - - switch (rc) { - case 0: - if (ec == 200) - break; - /*@fallthrough@*/ - default: - if (!retrying) { /* not HTTP_OK */ -if (_ftp_debug) -fprintf(stderr, "*** httpOpen ctrl %p reopening ...\n", ctrl); - retrying = 1; - fdio->close(ctrl); - goto reopen; - } - rc = FTPERR_FILE_NOT_FOUND; - goto errxit; - /*@notreached@*/ break; - } - } - - ctrl = fdLink(ctrl, "open data (httpOpen)"); - return fdio->fileno(ctrl); - -errxit: - fdSetSyserrno(ctrl, errno, ftpStrerror(rc)); -errxit2: - if (fdio->fileno(ctrl) >= 0) - fdio->close(ctrl); - return rc; -} - -int ftpOpen(urlinfo u) -{ - const char * host; - const char * user; - const char * password; - int port; - int rc; - - URLSANE(u); - if (((host = (u->proxyh ? u->proxyh : u->host)) == NULL)) { - rc = FTPERR_BAD_HOSTNAME; - goto errxit; - } - - if ((port = (u->proxyp > 0 ? u->proxyp : u->port)) < 0) port = IPPORT_FTP; - - if ((user = (u->proxyu ? u->proxyu : u->user)) == NULL) - user = "anonymous"; - - if ((password = u->password) == NULL) { - if (getuid()) { - struct passwd * pw = getpwuid(getuid()); - char *myp = alloca(strlen(pw->pw_name) + sizeof("@")); - strcpy(myp, pw->pw_name); - strcat(myp, "@"); - password = myp; - } else { - password = "root@"; - } - } - - if (fdio->fileno(u->ctrl) >= 0 && fdWritable(u->ctrl, 0) < 1) - fdio->close(u->ctrl); - - if (fdio->fileno(u->ctrl) < 0) { - rc = tcpConnect(u->ctrl, host, port); - fdSetFdno(u->ctrl, (rc >= 0 ? rc : -1)); - if (rc < 0) - goto errxit2; - } - - if ((rc = ftpCheckResponse(u, NULL))) - goto errxit; - - if ((rc = ftpCommand(u, "USER", user, NULL))) - goto errxit; - - if ((rc = ftpCommand(u, "PASS", password, NULL))) - goto errxit; - - if ((rc = ftpCommand(u, "TYPE", "I", NULL))) - goto errxit; - - u->ctrl = fdLink(u->ctrl, "open ctrl"); - return fdio->fileno(u->ctrl); - -errxit: - fdSetSyserrno(u->ctrl, errno, ftpStrerror(rc)); -errxit2: - if (fdio->fileno(u->ctrl) >= 0) - fdio->close(u->ctrl); - return rc; -} - -int ftpFileDone(urlinfo u, FD_t data) -{ - int rc = 0; - int ftpFileDoneNeeded; - - URLSANE(u); - ftpFileDoneNeeded = fdGetFtpFileDoneNeeded(data); - assert(ftpFileDoneNeeded); - - if (ftpFileDoneNeeded) { - fdSetFtpFileDoneNeeded(data, 0); - u->ctrl = fdFree(u->ctrl, "open data (ftpFileDone)"); - u->ctrl = fdFree(u->ctrl, "grab data (ftpFileDone)"); - rc = ftpCheckResponse(u, NULL); - } - return rc; -} - -int ftpFileDesc(urlinfo u, const char *cmd, FD_t data) -{ - struct sockaddr_in dataAddress; - int cmdlen; - char * passReply; - char * chptr; - int rc; - int ftpFileDoneNeeded; - - URLSANE(u); - if (cmd == NULL) - return FTPERR_UNKNOWN; /* XXX W2DO? */ - - cmdlen = strlen(cmd); - -/* - * XXX When ftpFileDesc() is called, there may be a lurking - * XXX transfer complete message (if ftpFileDone() was not - * XXX called to clear that message). Detect that condition now. - */ - ftpFileDoneNeeded = fdGetFtpFileDoneNeeded(data); - assert(ftpFileDoneNeeded == 0); - -/* - * Get the ftp version of the Content-Length. - */ - if (!strncmp(cmd, "RETR", 4)) { - char * req = strcpy(alloca(cmdlen + 1), cmd); - unsigned cl; - - memcpy(req, "SIZE", 4); - DBG(0, (stderr, "-> %s", req)); - if (fdio->write(u->ctrl, req, cmdlen) != cmdlen) { - rc = FTPERR_SERVER_IO_ERROR; - goto errxit; - } - if ((rc = ftpCheckResponse(u, &passReply))) - goto errxit; - if (sscanf(passReply, "%d %u", &rc, &cl) != 2) { - rc = FTPERR_BAD_SERVER_RESPONSE; - goto errxit; - } - rc = 0; - u->httpContentLength = cl; - } - - DBG(0, (stderr, "-> PASV\n")); - if (fdio->write(u->ctrl, "PASV\r\n", 6) != 6) { - rc = FTPERR_SERVER_IO_ERROR; - goto errxit; - } - - if ((rc = ftpCheckResponse(u, &passReply))) { - rc = FTPERR_PASSIVE_ERROR; - goto errxit; - } - - chptr = passReply; - while (*chptr && *chptr != '(') chptr++; - if (*chptr != '(') return FTPERR_PASSIVE_ERROR; - chptr++; - passReply = chptr; - while (*chptr && *chptr != ')') chptr++; - if (*chptr != ')') return FTPERR_PASSIVE_ERROR; - *chptr-- = '\0'; - - while (*chptr && *chptr != ',') chptr--; - if (*chptr != ',') return FTPERR_PASSIVE_ERROR; - chptr--; - while (*chptr && *chptr != ',') chptr--; - if (*chptr != ',') return FTPERR_PASSIVE_ERROR; - *chptr++ = '\0'; - - /* now passReply points to the IP portion, and chptr points to the - port number portion */ - - { int i, j; - dataAddress.sin_family = AF_INET; - if (sscanf(chptr, "%d,%d", &i, &j) != 2) { - rc = FTPERR_PASSIVE_ERROR; - goto errxit; - } - dataAddress.sin_port = htons((((unsigned)i) << 8) + j); - } - - chptr = passReply; - while (*chptr++) { - if (*chptr == ',') *chptr = '.'; - } - - if (!inet_aton(passReply, &dataAddress.sin_addr)) { - rc = FTPERR_PASSIVE_ERROR; - goto errxit; - } - - rc = socket(AF_INET, SOCK_STREAM, IPPROTO_IP); - fdSetFdno(data, (rc >= 0 ? rc : -1)); - if (rc < 0) { - rc = FTPERR_FAILED_CONNECT; - goto errxit; - } - data = fdLink(data, "open data (ftpFileDesc)"); - - /* XXX setsockopt SO_LINGER */ - /* XXX setsockopt SO_KEEPALIVE */ - /* XXX setsockopt SO_TOS IPTOS_THROUGHPUT */ - - while (connect(fdio->fileno(data), (struct sockaddr *) &dataAddress, - sizeof(dataAddress)) < 0) { - if (errno == EINTR) - continue; - rc = FTPERR_FAILED_DATA_CONNECT; - goto errxit; - } - - DBG(0, (stderr, "-> %s", cmd)); - if (fdio->write(u->ctrl, cmd, cmdlen) != cmdlen) { - rc = FTPERR_SERVER_IO_ERROR; - goto errxit; - } - - if ((rc = ftpCheckResponse(u, NULL))) { - goto errxit; - } - - fdSetFtpFileDoneNeeded(data, 1); - u->ctrl = fdLink(u->ctrl, "grab data (ftpFileDesc)"); - u->ctrl = fdLink(u->ctrl, "open data (ftpFileDesc)"); - return 0; - -errxit: - fdSetSyserrno(u->ctrl, errno, ftpStrerror(rc)); -errxit2: - if (fdio->fileno(data) >= 0) - fdio->close(data); - return rc; -} diff --git a/lib/install.c b/lib/install.c index a51346219..1089e4d06 100644 --- a/lib/install.c +++ b/lib/install.c @@ -348,7 +348,12 @@ static int installArchive(FD_t fd, struct fileInfo * files, (void)notify(h, RPMCALLBACK_INST_PROGRESS, 0, archiveSize, pkgKey, notifyData); + (void) Fflush(fd); +#ifndef DYING + cfd = Fdopen(fdDup(Fileno(fd)), "r.gzdio"); +#else cfd = Fdopen(fd, "r.gzdio"); +#endif rc = cpioInstallArchive(cfd, map, mappedFiles, ((notify && archiveSize) || specFile) ? callback : NULL, &info, &failedFile); diff --git a/lib/misc.c b/lib/misc.c index 6238f3732..7b3c8a125 100644 --- a/lib/misc.c +++ b/lib/misc.c @@ -355,10 +355,11 @@ char * gidToGname(gid_t gid) { } int makeTempFile(const char * prefix, const char ** fnptr, FD_t * fdptr) { + const char * tempfn; const char * tfn; + int temput; FD_t fd; int ran; - struct stat sb, sb2; if (!prefix) prefix = ""; @@ -372,35 +373,24 @@ int makeTempFile(const char * prefix, const char ** fnptr, FD_t * fdptr) { do { char tfnbuf[64]; - const char * tempfn; #ifndef NOTYET sprintf(tfnbuf, "rpm-tmp.%d", ran++); if (tfn) xfree(tfn); - tfn = tempfn = rpmGetPath("%{_tmppath}/", tfnbuf, NULL); + tempfn = rpmGenPath(prefix, "%{_tmppath}/", tfnbuf); #else strcpy(tfnbuf, "rpm-tmp.XXXXXX"); if (tfn) xfree(tfn); - tfn = tempfn = rpmGetPath("%{_tmppath}/", mktemp(tfnbuf), NULL); + tempfn = rpmGenPath(prefix, "%{_tmppath}/", mktemp(tfnbuf)); #endif - switch (urlIsURL(tempfn)) { - case URL_IS_PATH: - tfn += sizeof("file://") - 1; - tfn = strchr(tfn, '/'); - /*@fallthrough@*/ - case URL_IS_UNKNOWN: - if (prefix && prefix[strlen(prefix) - 1] == '/') - while (*tfn == '/') tfn++; - tfn = rpmGetPath( (prefix ? prefix : ""), tfn, NULL); - xfree(tempfn); - break; - case URL_IS_FTP: + temput = urlPath(tempfn, &tfn); + switch (temput) { case URL_IS_HTTP: case URL_IS_DASH: + goto errxit; + /*@notreached@*/ break; default: - xfree(tempfn); - return 1; - /*@notreached@*/ + break; } /* XXX FIXME: build/build.c Fdopen assertion failure, makeTempFile uses fdio */ @@ -411,38 +401,42 @@ int makeTempFile(const char * prefix, const char ** fnptr, FD_t * fdptr) { #endif } while ((fd == NULL || Ferror(fd)) && errno == EEXIST); - if (!Stat(tfn, &sb) && S_ISLNK(sb.st_mode)) { - rpmError(RPMERR_SCRIPT, _("error creating temporary file %s"), tfn); - xfree(tfn); - return 1; - } - - if (sb.st_nlink != 1) { - rpmError(RPMERR_SCRIPT, _("error creating temporary file %s"), tfn); - xfree(tfn); - return 1; - } + switch(temput) { + struct stat sb, sb2; + case URL_IS_PATH: + case URL_IS_UNKNOWN: + if (!stat(tfn, &sb) && S_ISLNK(sb.st_mode)) { + rpmError(RPMERR_SCRIPT, _("error creating temporary file %s"), tfn); + goto errxit; + } -#ifndef NOTYET - if (fstat(Fileno(fd), &sb2) == 0) -#else - if (Stat(tfn, &sb2) == 0) -#endif - { - if (sb2.st_ino != sb.st_ino || sb2.st_dev != sb.st_dev) { + if (sb.st_nlink != 1) { rpmError(RPMERR_SCRIPT, _("error creating temporary file %s"), tfn); - xfree(tfn); - return 1; + goto errxit; + } + + if (fstat(Fileno(fd), &sb2) == 0) { + if (sb2.st_ino != sb.st_ino || sb2.st_dev != sb.st_dev) { + rpmError(RPMERR_SCRIPT, _("error creating temporary file %s"), tfn); + goto errxit; + } } + break; + default: + break; } if (fnptr) *fnptr = tfn; else - xfree(tfn); + xfree(tempfn); *fdptr = fd; return 0; + +errxit: + xfree(tempfn); + return 1; } char * currentDirectory(void) { diff --git a/lib/rpmchecksig.c b/lib/rpmchecksig.c index 258f5e47d..ecd22e3bb 100644 --- a/lib/rpmchecksig.c +++ b/lib/rpmchecksig.c @@ -26,7 +26,7 @@ static int manageFile(FD_t *fdp, const char **fnp, int flags, int rc) /* open a file and set *fdp */ if (*fdp == NULL && fnp && *fnp) { - fd = Fopen(*fnp, ((flags & O_RDONLY) ? "r.ufdio" : "w.ufdio")); + fd = Fopen(*fnp, ((flags & O_RDONLY) ? "r.ufdio" : "r+.ufdio")); if (fd == NULL || Ferror(fd)) { fprintf(stderr, _("%s: open failed: %s\n"), *fnp, Fstrerror(fd)); diff --git a/lib/rpmio.h b/lib/rpmio.h index 72b6fb86e..ddb5289fc 100644 --- a/lib/rpmio.h +++ b/lib/rpmio.h @@ -70,6 +70,7 @@ int Fclose ( /*@killref@*/ FD_t fd); FD_t Fdopen (FD_t fd, const char * fmode); FD_t Fopen (const char * path, const char * fmode); +int Fflush (FD_t fd); int Ferror (FD_t fd); int Fileno (FD_t fd); @@ -102,9 +103,6 @@ void fdSetIo (FD_t fd, FDIO_t io); int fdGetRdTimeoutSecs(FD_t fd); -int fdGetFtpFileDoneNeeded(FD_t fd); -void fdSetFtpFileDoneNeeded(FD_t fd, int ftpFileDoneNeeded); - long int fdGetCpioPos(FD_t fd); void fdSetCpioPos(FD_t fd, long int cpioPos); @@ -129,12 +127,35 @@ extern /*@null@*/ FILE *fdFdopen( /*@only@*/ void * cookie, const char * mode); #define fdOpen fdio->open #endif +int fdWritable(FD_t fd, int secs); +int fdReadable(FD_t fd, int secs); + /*@observer@*/ extern FDIO_t fdio; /*@observer@*/ extern FDIO_t fpio; /* * Support for FTP and HTTP I/O. */ +#ifndef IPPORT_FTP +#define IPPORT_FTP 21 +#endif +#ifndef IPPORT_HTTP +#define IPPORT_HTTP 80 +#endif + +#define FTPERR_BAD_SERVER_RESPONSE -1 +#define FTPERR_SERVER_IO_ERROR -2 +#define FTPERR_SERVER_TIMEOUT -3 +#define FTPERR_BAD_HOST_ADDR -4 +#define FTPERR_BAD_HOSTNAME -5 +#define FTPERR_FAILED_CONNECT -6 +#define FTPERR_FILE_IO_ERROR -7 +#define FTPERR_PASSIVE_ERROR -8 +#define FTPERR_FAILED_DATA_CONNECT -9 +#define FTPERR_FILE_NOT_FOUND -10 +#define FTPERR_NIC_ABORT_IN_PROGRESS -11 +#define FTPERR_UNKNOWN -100 + /*@dependent@*/ /*@null@*/ void * ufdGetUrlinfo(FD_t fd); /*@observer@*/ const char * urlStrerror(const char * url); @@ -162,10 +183,6 @@ const char *const ftpStrerror(int errorNumber); #define ufdUnlink ufdio->unlink #endif -int fdWritable(FD_t fd, int secs); -int fdReadable(FD_t fd, int secs); -int fdRdline(FD_t fd, /*@out@*/ char * buf, size_t len); - int timedRead(FD_t fd, /*@out@*/ void * bufptr, int length); #define timedRead ufdio->read diff --git a/lib/rpmurl.h b/lib/rpmurl.h index d75c6346d..f3e7708ca 100644 --- a/lib/rpmurl.h +++ b/lib/rpmurl.h @@ -3,26 +3,6 @@ #include <assert.h> -#ifndef IPPORT_FTP -#define IPPORT_FTP 21 -#endif -#ifndef IPPORT_HTTP -#define IPPORT_HTTP 80 -#endif - -#define FTPERR_BAD_SERVER_RESPONSE -1 -#define FTPERR_SERVER_IO_ERROR -2 -#define FTPERR_SERVER_TIMEOUT -3 -#define FTPERR_BAD_HOST_ADDR -4 -#define FTPERR_BAD_HOSTNAME -5 -#define FTPERR_FAILED_CONNECT -6 -#define FTPERR_FILE_IO_ERROR -7 -#define FTPERR_PASSIVE_ERROR -8 -#define FTPERR_FAILED_DATA_CONNECT -9 -#define FTPERR_FILE_NOT_FOUND -10 -#define FTPERR_NIC_ABORT_IN_PROGRESS -11 -#define FTPERR_UNKNOWN -100 - typedef enum { URL_IS_UNKNOWN = 0, URL_IS_DASH = 1, @@ -54,8 +34,6 @@ typedef /*@abstract@*/ /*@refcounted@*/ struct urlinfo { int openError; /* Type of open failure */ int httpVersion; int httpHasRange; - int httpContentLength; - int httpPersist; int magic; } *urlinfo; @@ -63,13 +41,7 @@ typedef /*@abstract@*/ /*@refcounted@*/ struct urlinfo { extern "C" { #endif -int ftpCheckResponse(urlinfo u, /*@out@*/ char ** str); -int ftpCommand(urlinfo u, ...); - -int httpOpen(urlinfo u, FD_t ctrl, const char * httpcmd); -int ftpOpen(urlinfo u); -int ftpFileDone(urlinfo u, FD_t data); -int ftpFileDesc(urlinfo u, const char * cmd, FD_t data); +extern int url_iobuf_size; urlinfo urlLink(urlinfo u, const char * msg); urlinfo XurlLink(urlinfo u, const char * msg, const char * file, unsigned line); @@ -16,6 +16,7 @@ /*@access urlinfo@*/ #define URL_IOBUF_SIZE 4096 +int url_iobuf_size = URL_IOBUF_SIZE; #define RPMURL_DEBUG_IO 0x40000000 #define RPMURL_DEBUG_REFS 0x20000000 @@ -50,8 +51,7 @@ urlinfo XurlNew(const char *msg, const char *file, unsigned line) u->bufAlloced = 0; u->buf = NULL; u->httpHasRange = 1; - u->httpContentLength = 0; - u->httpPersist = u->httpVersion = 0; + u->httpVersion = 0; u->nrefs = 0; u->magic = URLMAGIC; return XurlLink(u, msg, file, line); @@ -190,8 +190,6 @@ static void urlFind(urlinfo *uret, int mustAsk) uCache = xmalloc(sizeof(*uCache)); } uCache[i] = urlLink(u, "uCache (miss)"); - u->bufAlloced = URL_IOBUF_SIZE; - u->buf = xcalloc(u->bufAlloced, sizeof(char)); u = urlFree(u, "urlSplit (urlFind miss)"); } else { /* XXX Swap original url and path into the cached structure */ @@ -313,9 +311,17 @@ urltype urlIsURL(const char * url) { int urlPath(const char * url, const char ** pathp) { - const char *path = url; - int urltype = urlIsURL(url); + const char *path; + int urltype; + if (url == NULL) { /* XXX paranoia */ + if (pathp) + *pathp = xstrdup("/"); + return URL_IS_UNKNOWN; + } + + path = url; + urltype = urlIsURL(url); switch (urltype) { case URL_IS_FTP: path += sizeof("ftp://") - 1; @@ -364,14 +370,16 @@ int urlSplit(const char * url, urlinfo *uret) while (1) { /* Point to end of next item */ while (*se && *se != '/') se++; +#ifdef DYING if (*se == '\0') { /* XXX can't find path */ if (myurl) free(myurl); u = urlFree(u, "urlSplit (error #2)"); return -1; } +#endif /* Item was service. Save service and go for the rest ...*/ - if ((se != s) && se[-1] == ':' && se[0] == '/' && se[1] == '/') { + if (*se && (se != s) && se[-1] == ':' && se[0] == '/' && se[1] == '/') { se[-1] = '\0'; u->service = xstrdup(s); se += 2; /* skip over "//" */ @@ -380,7 +388,7 @@ int urlSplit(const char * url, urlinfo *uret) } /* Item was everything-but-path. Save path and continue parse on rest */ - u->path = xstrdup(se); + u->path = xstrdup((*se ? se : "/")); *se = '\0'; break; } |