tar.c (76017) | tar.c (76351) |
---|---|
1/*- 2 * Copyright (c) 1992 Keith Muller. 3 * Copyright (c) 1992, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * Keith Muller of the University of California, San Diego. 8 * --- 26 unchanged lines hidden (view full) --- 35 * SUCH DAMAGE. 36 */ 37 38#ifndef lint 39#if 0 40static char sccsid[] = "@(#)tar.c 8.2 (Berkeley) 4/18/94"; 41#endif 42static const char rcsid[] = | 1/*- 2 * Copyright (c) 1992 Keith Muller. 3 * Copyright (c) 1992, 1993 4 * The Regents of the University of California. All rights reserved. 5 * 6 * This code is derived from software contributed to Berkeley by 7 * Keith Muller of the University of California, San Diego. 8 * --- 26 unchanged lines hidden (view full) --- 35 * SUCH DAMAGE. 36 */ 37 38#ifndef lint 39#if 0 40static char sccsid[] = "@(#)tar.c 8.2 (Berkeley) 4/18/94"; 41#endif 42static const char rcsid[] = |
43 "$FreeBSD: head/bin/pax/tar.c 76017 2001-04-26 08:37:00Z kris $"; | 43 "$FreeBSD: head/bin/pax/tar.c 76351 2001-05-08 06:19:06Z kris $"; |
44#endif /* not lint */ 45 46#include <sys/types.h> 47#include <sys/time.h> 48#include <sys/stat.h> 49#include <string.h> 50#include <stdio.h> 51#include <unistd.h> --- 105 unchanged lines hidden (view full) --- 157 return(0); 158 return(1); 159} 160 161/* 162 * ul_oct() 163 * convert an unsigned long to an octal string. many oddball field 164 * termination characters are used by the various versions of tar in the | 44#endif /* not lint */ 45 46#include <sys/types.h> 47#include <sys/time.h> 48#include <sys/stat.h> 49#include <string.h> 50#include <stdio.h> 51#include <unistd.h> --- 105 unchanged lines hidden (view full) --- 157 return(0); 158 return(1); 159} 160 161/* 162 * ul_oct() 163 * convert an unsigned long to an octal string. many oddball field 164 * termination characters are used by the various versions of tar in the |
165 * different fields. term selects which kind to use. str is BLANK padded | 165 * different fields. term selects which kind to use. str is '0' padded |
166 * at the front to len. we are unable to use only one format as many old 167 * tar readers are very cranky about this. 168 * Return: 169 * 0 if the number fit into the string, -1 otherwise 170 */ 171 172#ifdef __STDC__ 173static int --- 36 unchanged lines hidden (view full) --- 210 */ 211 while (pt >= str) { 212 *pt-- = '0' + (char)(val & 0x7); 213 if ((val = val >> 3) == (u_long)0) 214 break; 215 } 216 217 while (pt >= str) | 166 * at the front to len. we are unable to use only one format as many old 167 * tar readers are very cranky about this. 168 * Return: 169 * 0 if the number fit into the string, -1 otherwise 170 */ 171 172#ifdef __STDC__ 173static int --- 36 unchanged lines hidden (view full) --- 210 */ 211 while (pt >= str) { 212 *pt-- = '0' + (char)(val & 0x7); 213 if ((val = val >> 3) == (u_long)0) 214 break; 215 } 216 217 while (pt >= str) |
218 *pt-- = ' '; | 218 *pt-- = '0'; |
219 if (val != (u_long)0) 220 return(-1); 221 return(0); 222} 223 224#ifndef NET2_STAT 225/* 226 * uqd_oct() 227 * convert an u_quad_t to an octal string. one of many oddball field 228 * termination characters are used by the various versions of tar in the | 219 if (val != (u_long)0) 220 return(-1); 221 return(0); 222} 223 224#ifndef NET2_STAT 225/* 226 * uqd_oct() 227 * convert an u_quad_t to an octal string. one of many oddball field 228 * termination characters are used by the various versions of tar in the |
229 * different fields. term selects which kind to use. str is BLANK padded | 229 * different fields. term selects which kind to use. str is '0' padded |
230 * at the front to len. we are unable to use only one format as many old 231 * tar readers are very cranky about this. 232 * Return: 233 * 0 if the number fit into the string, -1 otherwise 234 */ 235 236#ifdef __STDC__ 237static int --- 36 unchanged lines hidden (view full) --- 274 */ 275 while (pt >= str) { 276 *pt-- = '0' + (char)(val & 0x7); 277 if ((val = val >> 3) == 0) 278 break; 279 } 280 281 while (pt >= str) | 230 * at the front to len. we are unable to use only one format as many old 231 * tar readers are very cranky about this. 232 * Return: 233 * 0 if the number fit into the string, -1 otherwise 234 */ 235 236#ifdef __STDC__ 237static int --- 36 unchanged lines hidden (view full) --- 274 */ 275 while (pt >= str) { 276 *pt-- = '0' + (char)(val & 0x7); 277 if ((val = val >> 3) == 0) 278 break; 279 } 280 281 while (pt >= str) |
282 *pt-- = ' '; | 282 *pt-- = '0'; |
283 if (val != (u_quad_t)0) 284 return(-1); 285 return(0); 286} 287#endif 288 289/* 290 * tar_chksm() --- 157 unchanged lines hidden (view full) --- 448 arcn->org_name = arcn->name; 449 arcn->sb.st_nlink = 1; 450 arcn->pat = NULL; 451 452 /* 453 * copy out the name and values in the stat buffer 454 */ 455 hd = (HD_TAR *)buf; | 283 if (val != (u_quad_t)0) 284 return(-1); 285 return(0); 286} 287#endif 288 289/* 290 * tar_chksm() --- 157 unchanged lines hidden (view full) --- 448 arcn->org_name = arcn->name; 449 arcn->sb.st_nlink = 1; 450 arcn->pat = NULL; 451 452 /* 453 * copy out the name and values in the stat buffer 454 */ 455 hd = (HD_TAR *)buf; |
456 arcn->nlen = l_strncpy(arcn->name, hd->name, sizeof(hd->name)); | 456 arcn->nlen = l_strncpy(arcn->name, hd->name, sizeof(arcn->name) - 1); |
457 arcn->name[arcn->nlen] = '\0'; 458 arcn->sb.st_mode = (mode_t)(asc_ul(hd->mode,sizeof(hd->mode),OCT) & 459 0xfff); 460 arcn->sb.st_uid = (uid_t)asc_ul(hd->uid, sizeof(hd->uid), OCT); 461 arcn->sb.st_gid = (gid_t)asc_ul(hd->gid, sizeof(hd->gid), OCT); | 457 arcn->name[arcn->nlen] = '\0'; 458 arcn->sb.st_mode = (mode_t)(asc_ul(hd->mode,sizeof(hd->mode),OCT) & 459 0xfff); 460 arcn->sb.st_uid = (uid_t)asc_ul(hd->uid, sizeof(hd->uid), OCT); 461 arcn->sb.st_gid = (gid_t)asc_ul(hd->gid, sizeof(hd->gid), OCT); |
462 arcn->sb.st_size = (size_t)asc_ul(hd->size, sizeof(hd->size), OCT); | 462#ifdef NET2_STAT 463 arcn->sb.st_size = (off_t)asc_ul(hd->size, sizeof(hd->size), OCT); 464#else 465 arcn->sb.st_size = (off_t)asc_uqd(hd->size, sizeof(hd->size), OCT); 466#endif |
463 arcn->sb.st_mtime = (time_t)asc_ul(hd->mtime, sizeof(hd->mtime), OCT); 464 arcn->sb.st_ctime = arcn->sb.st_atime = arcn->sb.st_mtime; 465 466 /* 467 * have to look at the last character, it may be a '/' and that is used 468 * to encode this as a directory 469 */ 470 pt = &(arcn->name[arcn->nlen - 1]); 471 arcn->pad = 0; 472 arcn->skip = 0; 473 switch(hd->linkflag) { 474 case SYMTYPE: 475 /* 476 * symbolic link, need to get the link name and set the type in 477 * the st_mode so -v printing will look correct. 478 */ 479 arcn->type = PAX_SLK; 480 arcn->ln_nlen = l_strncpy(arcn->ln_name, hd->linkname, | 467 arcn->sb.st_mtime = (time_t)asc_ul(hd->mtime, sizeof(hd->mtime), OCT); 468 arcn->sb.st_ctime = arcn->sb.st_atime = arcn->sb.st_mtime; 469 470 /* 471 * have to look at the last character, it may be a '/' and that is used 472 * to encode this as a directory 473 */ 474 pt = &(arcn->name[arcn->nlen - 1]); 475 arcn->pad = 0; 476 arcn->skip = 0; 477 switch(hd->linkflag) { 478 case SYMTYPE: 479 /* 480 * symbolic link, need to get the link name and set the type in 481 * the st_mode so -v printing will look correct. 482 */ 483 arcn->type = PAX_SLK; 484 arcn->ln_nlen = l_strncpy(arcn->ln_name, hd->linkname, |
481 sizeof(hd->linkname)); | 485 sizeof(arcn->ln_name) - 1); |
482 arcn->ln_name[arcn->ln_nlen] = '\0'; 483 arcn->sb.st_mode |= S_IFLNK; 484 break; 485 case LNKTYPE: 486 /* 487 * hard link, need to get the link name, set the type in the 488 * st_mode and st_nlink so -v printing will look better. 489 */ 490 arcn->type = PAX_HLK; 491 arcn->sb.st_nlink = 2; 492 arcn->ln_nlen = l_strncpy(arcn->ln_name, hd->linkname, | 486 arcn->ln_name[arcn->ln_nlen] = '\0'; 487 arcn->sb.st_mode |= S_IFLNK; 488 break; 489 case LNKTYPE: 490 /* 491 * hard link, need to get the link name, set the type in the 492 * st_mode and st_nlink so -v printing will look better. 493 */ 494 arcn->type = PAX_HLK; 495 arcn->sb.st_nlink = 2; 496 arcn->ln_nlen = l_strncpy(arcn->ln_name, hd->linkname, |
493 sizeof(hd->linkname)); | 497 sizeof(arcn->ln_name) - 1); |
494 arcn->ln_name[arcn->ln_nlen] = '\0'; 495 496 /* 497 * no idea of what type this thing really points at, but 498 * we set something for printing only. 499 */ 500 arcn->sb.st_mode |= S_IFREG; 501 break; | 498 arcn->ln_name[arcn->ln_nlen] = '\0'; 499 500 /* 501 * no idea of what type this thing really points at, but 502 * we set something for printing only. 503 */ 504 arcn->sb.st_mode |= S_IFREG; 505 break; |
506 case DIRTYPE: 507 /* 508 * It is a directory, set the mode for -v printing 509 */ 510 arcn->type = PAX_DIR; 511 arcn->sb.st_mode |= S_IFDIR; 512 arcn->sb.st_nlink = 2; 513 arcn->ln_name[0] = '\0'; 514 arcn->ln_nlen = 0; 515 break; |
|
502 case AREGTYPE: 503 case REGTYPE: 504 default: 505 /* 506 * If we have a trailing / this is a directory and NOT a file. 507 */ 508 arcn->ln_name[0] = '\0'; 509 arcn->ln_nlen = 0; --- 92 unchanged lines hidden (view full) --- 602 } 603 604 /* 605 * check file name len, remember extra char for dirs (the / at the end) 606 */ 607 len = arcn->nlen; 608 if (arcn->type == PAX_DIR) 609 ++len; | 516 case AREGTYPE: 517 case REGTYPE: 518 default: 519 /* 520 * If we have a trailing / this is a directory and NOT a file. 521 */ 522 arcn->ln_name[0] = '\0'; 523 arcn->ln_nlen = 0; --- 92 unchanged lines hidden (view full) --- 616 } 617 618 /* 619 * check file name len, remember extra char for dirs (the / at the end) 620 */ 621 len = arcn->nlen; 622 if (arcn->type == PAX_DIR) 623 ++len; |
610 if (len > sizeof(hd->name)) { | 624 if (len >= sizeof(hd->name)) { |
611 paxwarn(1, "File name too long for tar %s", arcn->name); 612 return(1); 613 } 614 615 /* 616 * copy the data out of the ARCHD into the tar header based on the type 617 * of the file. Remember many tar readers want the unused fields to be 618 * padded with zero. We set the linkflag field (type), the linkname 619 * (or zero if not used),the size, and set the padding (if any) to be 620 * added after the file data (0 for all other types, as they only have 621 * a header) 622 */ 623 hd = (HD_TAR *)hdblk; | 625 paxwarn(1, "File name too long for tar %s", arcn->name); 626 return(1); 627 } 628 629 /* 630 * copy the data out of the ARCHD into the tar header based on the type 631 * of the file. Remember many tar readers want the unused fields to be 632 * padded with zero. We set the linkflag field (type), the linkname 633 * (or zero if not used),the size, and set the padding (if any) to be 634 * added after the file data (0 for all other types, as they only have 635 * a header) 636 */ 637 hd = (HD_TAR *)hdblk; |
624 zf_strncpy(hd->name, arcn->name, sizeof(hd->name)); | 638 l_strncpy(hd->name, arcn->name, sizeof(hd->name) - 1); 639 hd->name[sizeof(hd->name) - 1] = '\0'; |
625 arcn->pad = 0; 626 627 if (arcn->type == PAX_DIR) { 628 /* 629 * directories are the same as files, except have a filename 630 * that ends with a /, we add the slash here. No data follows, 631 * dirs, so no pad. 632 */ 633 hd->linkflag = AREGTYPE; 634 memset(hd->linkname, 0, sizeof(hd->linkname)); 635 hd->name[len-1] = '/'; 636 if (ul_oct((u_long)0L, hd->size, sizeof(hd->size), 1)) 637 goto out; 638 } else if (arcn->type == PAX_SLK) { 639 /* 640 * no data follows this file, so no pad 641 */ 642 hd->linkflag = SYMTYPE; | 640 arcn->pad = 0; 641 642 if (arcn->type == PAX_DIR) { 643 /* 644 * directories are the same as files, except have a filename 645 * that ends with a /, we add the slash here. No data follows, 646 * dirs, so no pad. 647 */ 648 hd->linkflag = AREGTYPE; 649 memset(hd->linkname, 0, sizeof(hd->linkname)); 650 hd->name[len-1] = '/'; 651 if (ul_oct((u_long)0L, hd->size, sizeof(hd->size), 1)) 652 goto out; 653 } else if (arcn->type == PAX_SLK) { 654 /* 655 * no data follows this file, so no pad 656 */ 657 hd->linkflag = SYMTYPE; |
643 zf_strncpy(hd->linkname,arcn->ln_name, sizeof(hd->linkname)); | 658 l_strncpy(hd->linkname,arcn->ln_name, sizeof(hd->linkname) - 1); 659 hd->linkname[sizeof(hd->linkname) - 1] = '\0'; |
644 if (ul_oct((u_long)0L, hd->size, sizeof(hd->size), 1)) 645 goto out; 646 } else if ((arcn->type == PAX_HLK) || (arcn->type == PAX_HRG)) { 647 /* 648 * no data follows this file, so no pad 649 */ 650 hd->linkflag = LNKTYPE; | 660 if (ul_oct((u_long)0L, hd->size, sizeof(hd->size), 1)) 661 goto out; 662 } else if ((arcn->type == PAX_HLK) || (arcn->type == PAX_HRG)) { 663 /* 664 * no data follows this file, so no pad 665 */ 666 hd->linkflag = LNKTYPE; |
651 zf_strncpy(hd->linkname,arcn->ln_name, sizeof(hd->linkname)); | 667 l_strncpy(hd->linkname,arcn->ln_name, sizeof(hd->linkname) - 1); 668 hd->linkname[sizeof(hd->linkname) - 1] = '\0'; |
652 if (ul_oct((u_long)0L, hd->size, sizeof(hd->size), 1)) 653 goto out; 654 } else { 655 /* 656 * data follows this file, so set the pad 657 */ 658 hd->linkflag = AREGTYPE; 659 memset(hd->linkname, 0, sizeof(hd->linkname)); --- 20 unchanged lines hidden (view full) --- 680 goto out; 681 682 /* 683 * calculate and add the checksum, then write the header. A return of 684 * 0 tells the caller to now write the file data, 1 says no data needs 685 * to be written 686 */ 687 if (ul_oct(tar_chksm(hdblk, sizeof(HD_TAR)), hd->chksum, | 669 if (ul_oct((u_long)0L, hd->size, sizeof(hd->size), 1)) 670 goto out; 671 } else { 672 /* 673 * data follows this file, so set the pad 674 */ 675 hd->linkflag = AREGTYPE; 676 memset(hd->linkname, 0, sizeof(hd->linkname)); --- 20 unchanged lines hidden (view full) --- 697 goto out; 698 699 /* 700 * calculate and add the checksum, then write the header. A return of 701 * 0 tells the caller to now write the file data, 1 says no data needs 702 * to be written 703 */ 704 if (ul_oct(tar_chksm(hdblk, sizeof(HD_TAR)), hd->chksum, |
688 sizeof(hd->chksum), 2)) | 705 sizeof(hd->chksum), 3)) |
689 goto out; 690 if (wr_rdbuf(hdblk, sizeof(HD_TAR)) < 0) 691 return(-1); 692 if (wr_skip((off_t)(BLKMULT - sizeof(HD_TAR))) < 0) 693 return(-1); 694 if ((arcn->type == PAX_CTG) || (arcn->type == PAX_REG)) 695 return(0); 696 return(1); --- 116 unchanged lines hidden (view full) --- 813 /* 814 * we only get proper sized buffers 815 */ 816 if (ustar_id(buf, BLKMULT) < 0) 817 return(-1); 818 arcn->org_name = arcn->name; 819 arcn->sb.st_nlink = 1; 820 arcn->pat = NULL; | 706 goto out; 707 if (wr_rdbuf(hdblk, sizeof(HD_TAR)) < 0) 708 return(-1); 709 if (wr_skip((off_t)(BLKMULT - sizeof(HD_TAR))) < 0) 710 return(-1); 711 if ((arcn->type == PAX_CTG) || (arcn->type == PAX_REG)) 712 return(0); 713 return(1); --- 116 unchanged lines hidden (view full) --- 830 /* 831 * we only get proper sized buffers 832 */ 833 if (ustar_id(buf, BLKMULT) < 0) 834 return(-1); 835 arcn->org_name = arcn->name; 836 arcn->sb.st_nlink = 1; 837 arcn->pat = NULL; |
838 arcn->nlen = 0; |
|
821 hd = (HD_USTAR *)buf; 822 823 /* 824 * see if the filename is split into two parts. if, so joint the parts. 825 * we copy the prefix first and add a / between the prefix and name. 826 */ 827 dest = arcn->name; 828 if (*(hd->prefix) != '\0') { | 839 hd = (HD_USTAR *)buf; 840 841 /* 842 * see if the filename is split into two parts. if, so joint the parts. 843 * we copy the prefix first and add a / between the prefix and name. 844 */ 845 dest = arcn->name; 846 if (*(hd->prefix) != '\0') { |
829 cnt = l_strncpy(arcn->name, hd->prefix, sizeof(hd->prefix)); 830 dest = arcn->name + arcn->nlen; | 847 cnt = l_strncpy(dest, hd->prefix, sizeof(arcn->name) - 2); 848 dest += cnt; |
831 *dest++ = '/'; | 849 *dest++ = '/'; |
850 cnt++; |
|
832 } | 851 } |
833 arcn->nlen = l_strncpy(dest, hd->name, sizeof(hd->name)); 834 arcn->nlen += cnt; | 852 arcn->nlen = cnt + l_strncpy(dest, hd->name, sizeof(arcn->name) - cnt); |
835 arcn->name[arcn->nlen] = '\0'; 836 837 /* 838 * follow the spec to the letter. we should only have mode bits, strip 839 * off all other crud we may be passed. 840 */ 841 arcn->sb.st_mode = (mode_t)(asc_ul(hd->mode, sizeof(hd->mode), OCT) & 842 0xfff); | 853 arcn->name[arcn->nlen] = '\0'; 854 855 /* 856 * follow the spec to the letter. we should only have mode bits, strip 857 * off all other crud we may be passed. 858 */ 859 arcn->sb.st_mode = (mode_t)(asc_ul(hd->mode, sizeof(hd->mode), OCT) & 860 0xfff); |
843 arcn->sb.st_size = (size_t)asc_ul(hd->size, sizeof(hd->size), OCT); | 861#ifdef NET2_STAT 862 arcn->sb.st_size = (off_t)asc_ul(hd->size, sizeof(hd->size), OCT); 863#else 864 arcn->sb.st_size = (off_t)asc_uqd(hd->size, sizeof(hd->size), OCT); 865#endif |
844 arcn->sb.st_mtime = (time_t)asc_ul(hd->mtime, sizeof(hd->mtime), OCT); 845 arcn->sb.st_ctime = arcn->sb.st_atime = arcn->sb.st_mtime; 846 847 /* 848 * If we can find the ascii names for gname and uname in the password 849 * and group files we will use the uid's and gid they bind. Otherwise 850 * we use the uid and gid values stored in the header. (This is what 851 * the POSIX spec wants). --- 63 unchanged lines hidden (view full) --- 915 */ 916 arcn->sb.st_mode |= S_IFREG; 917 arcn->sb.st_nlink = 2; 918 } 919 /* 920 * copy the link name 921 */ 922 arcn->ln_nlen = l_strncpy(arcn->ln_name, hd->linkname, | 866 arcn->sb.st_mtime = (time_t)asc_ul(hd->mtime, sizeof(hd->mtime), OCT); 867 arcn->sb.st_ctime = arcn->sb.st_atime = arcn->sb.st_mtime; 868 869 /* 870 * If we can find the ascii names for gname and uname in the password 871 * and group files we will use the uid's and gid they bind. Otherwise 872 * we use the uid and gid values stored in the header. (This is what 873 * the POSIX spec wants). --- 63 unchanged lines hidden (view full) --- 937 */ 938 arcn->sb.st_mode |= S_IFREG; 939 arcn->sb.st_nlink = 2; 940 } 941 /* 942 * copy the link name 943 */ 944 arcn->ln_nlen = l_strncpy(arcn->ln_name, hd->linkname, |
923 sizeof(hd->linkname)); | 945 sizeof(arcn->ln_name) - 1); |
924 arcn->ln_name[arcn->ln_nlen] = '\0'; 925 break; 926 case CONTTYPE: 927 case AREGTYPE: 928 case REGTYPE: 929 default: 930 /* 931 * these types have file data that follows. Set the skip and --- 65 unchanged lines hidden (view full) --- 997 * split the name, or zero out the prefix 998 */ 999 if (pt != arcn->name) { 1000 /* 1001 * name was split, pt points at the / where the split is to 1002 * occur, we remove the / and copy the first part to the prefix 1003 */ 1004 *pt = '\0'; | 946 arcn->ln_name[arcn->ln_nlen] = '\0'; 947 break; 948 case CONTTYPE: 949 case AREGTYPE: 950 case REGTYPE: 951 default: 952 /* 953 * these types have file data that follows. Set the skip and --- 65 unchanged lines hidden (view full) --- 1019 * split the name, or zero out the prefix 1020 */ 1021 if (pt != arcn->name) { 1022 /* 1023 * name was split, pt points at the / where the split is to 1024 * occur, we remove the / and copy the first part to the prefix 1025 */ 1026 *pt = '\0'; |
1005 zf_strncpy(hd->prefix, arcn->name, sizeof(hd->prefix)); | 1027 l_strncpy(hd->prefix, arcn->name, sizeof(hd->prefix) - 1); |
1006 *pt++ = '/'; 1007 } else 1008 memset(hd->prefix, 0, sizeof(hd->prefix)); 1009 1010 /* 1011 * copy the name part. this may be the whole path or the part after 1012 * the prefix 1013 */ | 1028 *pt++ = '/'; 1029 } else 1030 memset(hd->prefix, 0, sizeof(hd->prefix)); 1031 1032 /* 1033 * copy the name part. this may be the whole path or the part after 1034 * the prefix 1035 */ |
1014 zf_strncpy(hd->name, pt, sizeof(hd->name)); | 1036 l_strncpy(hd->name, pt, sizeof(hd->name) - 1); 1037 hd->name[sizeof(hd->name) - 1] = '\0'; |
1015 1016 /* 1017 * set the fields in the header that are type dependent 1018 */ 1019 switch(arcn->type) { 1020 case PAX_DIR: 1021 hd->typeflag = DIRTYPE; 1022 memset(hd->linkname, 0, sizeof(hd->linkname)); --- 26 unchanged lines hidden (view full) --- 1049 break; 1050 case PAX_SLK: 1051 case PAX_HLK: 1052 case PAX_HRG: 1053 if (arcn->type == PAX_SLK) 1054 hd->typeflag = SYMTYPE; 1055 else 1056 hd->typeflag = LNKTYPE; | 1038 1039 /* 1040 * set the fields in the header that are type dependent 1041 */ 1042 switch(arcn->type) { 1043 case PAX_DIR: 1044 hd->typeflag = DIRTYPE; 1045 memset(hd->linkname, 0, sizeof(hd->linkname)); --- 26 unchanged lines hidden (view full) --- 1072 break; 1073 case PAX_SLK: 1074 case PAX_HLK: 1075 case PAX_HRG: 1076 if (arcn->type == PAX_SLK) 1077 hd->typeflag = SYMTYPE; 1078 else 1079 hd->typeflag = LNKTYPE; |
1057 zf_strncpy(hd->linkname,arcn->ln_name, sizeof(hd->linkname)); | 1080 l_strncpy(hd->linkname,arcn->ln_name, sizeof(hd->linkname) - 1); 1081 hd->linkname[sizeof(hd->linkname) - 1] = '\0'; |
1058 memset(hd->devmajor, 0, sizeof(hd->devmajor)); 1059 memset(hd->devminor, 0, sizeof(hd->devminor)); 1060 if (ul_oct((u_long)0L, hd->size, sizeof(hd->size), 3)) 1061 goto out; 1062 break; 1063 case PAX_REG: 1064 case PAX_CTG: 1065 default: --- 16 unchanged lines hidden (view full) --- 1082 sizeof(hd->size), 3)) { 1083# endif 1084 paxwarn(1,"File is too long for ustar %s",arcn->org_name); 1085 return(1); 1086 } 1087 break; 1088 } 1089 | 1082 memset(hd->devmajor, 0, sizeof(hd->devmajor)); 1083 memset(hd->devminor, 0, sizeof(hd->devminor)); 1084 if (ul_oct((u_long)0L, hd->size, sizeof(hd->size), 3)) 1085 goto out; 1086 break; 1087 case PAX_REG: 1088 case PAX_CTG: 1089 default: --- 16 unchanged lines hidden (view full) --- 1106 sizeof(hd->size), 3)) { 1107# endif 1108 paxwarn(1,"File is too long for ustar %s",arcn->org_name); 1109 return(1); 1110 } 1111 break; 1112 } 1113 |
1090 zf_strncpy(hd->magic, TMAGIC, TMAGLEN); 1091 zf_strncpy(hd->version, TVERSION, TVERSLEN); | 1114 l_strncpy(hd->magic, TMAGIC, TMAGLEN); 1115 l_strncpy(hd->version, TVERSION, TVERSLEN); |
1092 1093 /* 1094 * set the remaining fields. Some versions want all 16 bits of mode 1095 * we better humor them (they really do not meet spec though).... 1096 */ 1097 if (ul_oct((u_long)arcn->sb.st_mode, hd->mode, sizeof(hd->mode), 3) || 1098 ul_oct((u_long)arcn->sb.st_uid, hd->uid, sizeof(hd->uid), 3) || 1099 ul_oct((u_long)arcn->sb.st_gid, hd->gid, sizeof(hd->gid), 3) || 1100 ul_oct((u_long)arcn->sb.st_mtime,hd->mtime,sizeof(hd->mtime),3)) 1101 goto out; | 1116 1117 /* 1118 * set the remaining fields. Some versions want all 16 bits of mode 1119 * we better humor them (they really do not meet spec though).... 1120 */ 1121 if (ul_oct((u_long)arcn->sb.st_mode, hd->mode, sizeof(hd->mode), 3) || 1122 ul_oct((u_long)arcn->sb.st_uid, hd->uid, sizeof(hd->uid), 3) || 1123 ul_oct((u_long)arcn->sb.st_gid, hd->gid, sizeof(hd->gid), 3) || 1124 ul_oct((u_long)arcn->sb.st_mtime,hd->mtime,sizeof(hd->mtime),3)) 1125 goto out; |
1102 zf_strncpy(hd->uname,name_uid(arcn->sb.st_uid, 0),sizeof(hd->uname)); 1103 zf_strncpy(hd->gname,name_gid(arcn->sb.st_gid, 0),sizeof(hd->gname)); | 1126 l_strncpy(hd->uname,name_uid(arcn->sb.st_uid, 0),sizeof(hd->uname)); 1127 l_strncpy(hd->gname,name_gid(arcn->sb.st_gid, 0),sizeof(hd->gname)); |
1104 1105 /* 1106 * calculate and store the checksum write the header to the archive 1107 * return 0 tells the caller to now write the file data, 1 says no data 1108 * needs to be written 1109 */ 1110 if (ul_oct(tar_chksm(hdblk, sizeof(HD_USTAR)), hd->chksum, 1111 sizeof(hd->chksum), 3)) --- 37 unchanged lines hidden (view full) --- 1149#endif 1150{ 1151 register char *start; 1152 1153 /* 1154 * check to see if the file name is small enough to fit in the name 1155 * field. if so just return a pointer to the name. 1156 */ | 1128 1129 /* 1130 * calculate and store the checksum write the header to the archive 1131 * return 0 tells the caller to now write the file data, 1 says no data 1132 * needs to be written 1133 */ 1134 if (ul_oct(tar_chksm(hdblk, sizeof(HD_USTAR)), hd->chksum, 1135 sizeof(hd->chksum), 3)) --- 37 unchanged lines hidden (view full) --- 1173#endif 1174{ 1175 register char *start; 1176 1177 /* 1178 * check to see if the file name is small enough to fit in the name 1179 * field. if so just return a pointer to the name. 1180 */ |
1157 if (len <= TNMSZ) | 1181 if (len < TNMSZ) |
1158 return(name); 1159 if (len > (TPFSZ + TNMSZ)) 1160 return(NULL); 1161 1162 /* 1163 * we start looking at the biggest sized piece that fits in the name 1164 * field. We walk forward looking for a slash to split at. The idea is 1165 * to find the biggest piece to fit in the name field (or the smallest --- 28 unchanged lines hidden --- | 1182 return(name); 1183 if (len > (TPFSZ + TNMSZ)) 1184 return(NULL); 1185 1186 /* 1187 * we start looking at the biggest sized piece that fits in the name 1188 * field. We walk forward looking for a slash to split at. The idea is 1189 * to find the biggest piece to fit in the name field (or the smallest --- 28 unchanged lines hidden --- |