common.c (109960) | common.c (109967) |
---|---|
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 --- 13 unchanged lines hidden (view full) --- 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 29#include <sys/cdefs.h> | 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 --- 13 unchanged lines hidden (view full) --- 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 29#include <sys/cdefs.h> |
30__FBSDID("$FreeBSD: head/lib/libfetch/common.c 109960 2003-01-28 00:33:53Z jwd $"); | 30__FBSDID("$FreeBSD: head/lib/libfetch/common.c 109967 2003-01-28 08:04:40Z des $"); |
31 32#include <sys/param.h> 33#include <sys/socket.h> 34#include <sys/time.h> 35#include <sys/uio.h> 36#include <netinet/in.h> 37 38#include <errno.h> --- 162 unchanged lines hidden (view full) --- 201 * Create a connection for an existing descriptor. 202 */ 203conn_t * 204_fetch_reopen(int sd) 205{ 206 conn_t *conn; 207 208 /* allocate and fill connection structure */ | 31 32#include <sys/param.h> 33#include <sys/socket.h> 34#include <sys/time.h> 35#include <sys/uio.h> 36#include <netinet/in.h> 37 38#include <errno.h> --- 162 unchanged lines hidden (view full) --- 201 * Create a connection for an existing descriptor. 202 */ 203conn_t * 204_fetch_reopen(int sd) 205{ 206 conn_t *conn; 207 208 /* allocate and fill connection structure */ |
209 if ((conn = calloc(1, sizeof *conn)) == NULL) | 209 if ((conn = calloc(1, sizeof(*conn))) == NULL) |
210 return (NULL); 211 conn->sd = sd; 212 ++conn->ref; 213 return (conn); 214} 215 216 217/* --- 329 unchanged lines hidden (view full) --- 547{ 548 struct iovec iov[2]; 549 int ret; 550 551 DEBUG(fprintf(stderr, ">>> %s\n", str)); 552 iov[0].iov_base = __DECONST(char *, str); 553 iov[0].iov_len = len; 554 iov[1].iov_base = __DECONST(char *, ENDL); | 210 return (NULL); 211 conn->sd = sd; 212 ++conn->ref; 213 return (conn); 214} 215 216 217/* --- 329 unchanged lines hidden (view full) --- 547{ 548 struct iovec iov[2]; 549 int ret; 550 551 DEBUG(fprintf(stderr, ">>> %s\n", str)); 552 iov[0].iov_base = __DECONST(char *, str); 553 iov[0].iov_len = len; 554 iov[1].iov_base = __DECONST(char *, ENDL); |
555 iov[1].iov_len = sizeof ENDL; | 555 iov[1].iov_len = sizeof(ENDL); |
556 if (len == 0) 557 ret = _fetch_writev(conn, &iov[1], 1); 558 else 559 ret = _fetch_writev(conn, iov, 2); 560 if (ret == -1) 561 return (-1); 562 return (0); 563} --- 24 unchanged lines hidden (view full) --- 588 struct url_ent *tmp; 589 590 if (*p == NULL) { 591 *size = 0; 592 *len = 0; 593 } 594 595 if (*len >= *size - 1) { | 556 if (len == 0) 557 ret = _fetch_writev(conn, &iov[1], 1); 558 else 559 ret = _fetch_writev(conn, iov, 2); 560 if (ret == -1) 561 return (-1); 562 return (0); 563} --- 24 unchanged lines hidden (view full) --- 588 struct url_ent *tmp; 589 590 if (*p == NULL) { 591 *size = 0; 592 *len = 0; 593 } 594 595 if (*len >= *size - 1) { |
596 tmp = realloc(*p, (*size * 2 + 1) * sizeof **p); | 596 tmp = realloc(*p, (*size * 2 + 1) * sizeof(**p)); |
597 if (tmp == NULL) { 598 errno = ENOMEM; 599 _fetch_syserr(); 600 return (-1); 601 } 602 *size = (*size * 2 + 1); 603 *p = tmp; 604 } 605 606 tmp = *p + *len; 607 snprintf(tmp->name, PATH_MAX, "%s", name); | 597 if (tmp == NULL) { 598 errno = ENOMEM; 599 _fetch_syserr(); 600 return (-1); 601 } 602 *size = (*size * 2 + 1); 603 *p = tmp; 604 } 605 606 tmp = *p + *len; 607 snprintf(tmp->name, PATH_MAX, "%s", name); |
608 bcopy(us, &tmp->stat, sizeof *us); | 608 bcopy(us, &tmp->stat, sizeof(*us)); |
609 610 (*len)++; 611 (++tmp)->name[0] = 0; 612 613 return (0); 614} 615 616 --- 16 unchanged lines hidden (view full) --- 633_fetch_netrc_auth(struct url *url) 634{ 635 char fn[PATH_MAX]; 636 const char *word; 637 char *p; 638 FILE *f; 639 640 if ((p = getenv("NETRC")) != NULL) { | 609 610 (*len)++; 611 (++tmp)->name[0] = 0; 612 613 return (0); 614} 615 616 --- 16 unchanged lines hidden (view full) --- 633_fetch_netrc_auth(struct url *url) 634{ 635 char fn[PATH_MAX]; 636 const char *word; 637 char *p; 638 FILE *f; 639 640 if ((p = getenv("NETRC")) != NULL) { |
641 if (snprintf(fn, sizeof fn, "%s", p) >= (int)sizeof(fn)) { | 641 if (snprintf(fn, sizeof(fn), "%s", p) >= (int)sizeof(fn)) { |
642 _fetch_info("$NETRC specifies a file name " 643 "longer than PATH_MAX"); 644 return (-1); 645 } 646 } else { 647 if ((p = getenv("HOME")) != NULL) { 648 struct passwd *pwd; 649 650 if ((pwd = getpwuid(getuid())) == NULL || 651 (p = pwd->pw_dir) == NULL) 652 return (-1); 653 } | 642 _fetch_info("$NETRC specifies a file name " 643 "longer than PATH_MAX"); 644 return (-1); 645 } 646 } else { 647 if ((p = getenv("HOME")) != NULL) { 648 struct passwd *pwd; 649 650 if ((pwd = getpwuid(getuid())) == NULL || 651 (p = pwd->pw_dir) == NULL) 652 return (-1); 653 } |
654 if (snprintf(fn, sizeof fn, "%s/.netrc", p) >= (int)sizeof(fn)) | 654 if (snprintf(fn, sizeof(fn), "%s/.netrc", p) >= (int)sizeof(fn)) |
655 return (-1); 656 } 657 658 if ((f = fopen(fn, "r")) == NULL) 659 return (-1); 660 while ((word = _fetch_read_word(f)) != NULL) { 661 if (strcmp(word, "default") == 0) { 662 DEBUG(_fetch_info("Using default .netrc settings")); --- 7 unchanged lines hidden (view full) --- 670 } 671 } 672 if (word == NULL) 673 goto ferr; 674 while ((word = _fetch_read_word(f)) != NULL) { 675 if (strcmp(word, "login") == 0) { 676 if ((word = _fetch_read_word(f)) == NULL) 677 goto ferr; | 655 return (-1); 656 } 657 658 if ((f = fopen(fn, "r")) == NULL) 659 return (-1); 660 while ((word = _fetch_read_word(f)) != NULL) { 661 if (strcmp(word, "default") == 0) { 662 DEBUG(_fetch_info("Using default .netrc settings")); --- 7 unchanged lines hidden (view full) --- 670 } 671 } 672 if (word == NULL) 673 goto ferr; 674 while ((word = _fetch_read_word(f)) != NULL) { 675 if (strcmp(word, "login") == 0) { 676 if ((word = _fetch_read_word(f)) == NULL) 677 goto ferr; |
678 if (snprintf(url->user, sizeof url->user, | 678 if (snprintf(url->user, sizeof(url->user), |
679 "%s", word) > (int)sizeof(url->user)) { 680 _fetch_info("login name in .netrc is too long"); 681 url->user[0] = '\0'; 682 } 683 } else if (strcmp(word, "password") == 0) { 684 if ((word = _fetch_read_word(f)) == NULL) 685 goto ferr; | 679 "%s", word) > (int)sizeof(url->user)) { 680 _fetch_info("login name in .netrc is too long"); 681 url->user[0] = '\0'; 682 } 683 } else if (strcmp(word, "password") == 0) { 684 if ((word = _fetch_read_word(f)) == NULL) 685 goto ferr; |
686 if (snprintf(url->pwd, sizeof url->pwd, | 686 if (snprintf(url->pwd, sizeof(url->pwd), |
687 "%s", word) > (int)sizeof(url->pwd)) { 688 _fetch_info("password in .netrc is too long"); 689 url->pwd[0] = '\0'; 690 } 691 } else if (strcmp(word, "account") == 0) { 692 if ((word = _fetch_read_word(f)) == NULL) 693 goto ferr; 694 /* XXX not supported! */ 695 } else { 696 break; 697 } 698 } 699 fclose(f); 700 return (0); 701 ferr: 702 fclose(f); 703 return (-1); 704} | 687 "%s", word) > (int)sizeof(url->pwd)) { 688 _fetch_info("password in .netrc is too long"); 689 url->pwd[0] = '\0'; 690 } 691 } else if (strcmp(word, "account") == 0) { 692 if ((word = _fetch_read_word(f)) == NULL) 693 goto ferr; 694 /* XXX not supported! */ 695 } else { 696 break; 697 } 698 } 699 fclose(f); 700 return (0); 701 ferr: 702 fclose(f); 703 return (-1); 704} |