bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 1 | /* |
| 2 | ** Copyright 1998-2003 University of Illinois Board of Trustees |
| 3 | ** Copyright 1998-2003 Mark D. Roth |
| 4 | ** All rights reserved. |
| 5 | ** |
| 6 | ** output.c - libtar code to print out tar header blocks |
| 7 | ** |
| 8 | ** Mark D. Roth <roth@uiuc.edu> |
| 9 | ** Campus Information Technologies and Educational Services |
| 10 | ** University of Illinois at Urbana-Champaign |
| 11 | */ |
| 12 | |
| 13 | #include <internal.h> |
| 14 | |
| 15 | #include <stdio.h> |
James Christopher Adduono | 6f57f7c | 2016-03-01 16:01:53 -0500 | [diff] [blame] | 16 | #include <stdlib.h> |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 17 | #include <pwd.h> |
| 18 | #include <grp.h> |
| 19 | #include <time.h> |
| 20 | #include <limits.h> |
| 21 | #include <sys/param.h> |
| 22 | |
| 23 | #ifdef STDC_HEADERS |
| 24 | # include <string.h> |
| 25 | #endif |
| 26 | |
bigbiff | 7ba7500 | 2020-04-11 20:47:09 -0400 | [diff] [blame] | 27 | #ifdef USE_FSCRYPT |
| 28 | #include "fscrypt_policy.h" |
| 29 | #endif |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 30 | |
| 31 | #ifndef _POSIX_LOGIN_NAME_MAX |
| 32 | # define _POSIX_LOGIN_NAME_MAX 9 |
| 33 | #endif |
| 34 | |
| 35 | |
| 36 | void |
| 37 | th_print(TAR *t) |
| 38 | { |
Mohd Faraz | 566ef6b | 2023-01-16 16:16:21 +0100 | [diff] [blame] | 39 | LOG("Printing tar header:"); |
| 40 | LOG(" name = \"%.100s\"\n", t->th_buf.name); |
| 41 | LOG(" mode = \"%.8s\"\n", t->th_buf.mode); |
| 42 | LOG(" uid = \"%.8s\"\n", t->th_buf.uid); |
| 43 | LOG(" gid = \"%.8s\"\n", t->th_buf.gid); |
| 44 | LOG(" size = \"%.12s\"\n", t->th_buf.size); |
| 45 | LOG(" mtime = \"%.12s\"\n", t->th_buf.mtime); |
| 46 | LOG(" chksum = \"%.8s\"\n", t->th_buf.chksum); |
| 47 | LOG(" typeflag = \'%c\'\n", t->th_buf.typeflag); |
| 48 | LOG(" linkname = \"%.100s\"\n", t->th_buf.linkname); |
| 49 | LOG(" magic = \"%.6s\"\n", t->th_buf.magic); |
| 50 | /*LOG(" version = \"%.2s\"\n", t->th_buf.version); */ |
| 51 | /*LOG(" version[0] = \'%c\',version[1] = \'%c\'\n", |
Ethan Yonker | fefe591 | 2017-09-30 22:22:13 -0500 | [diff] [blame] | 52 | t->th_buf.version[0], t->th_buf.version[1]);*/ |
Mohd Faraz | 566ef6b | 2023-01-16 16:16:21 +0100 | [diff] [blame] | 53 | LOG(" uname = \"%.32s\"\n", t->th_buf.uname); |
| 54 | LOG(" gname = \"%.32s\"\n", t->th_buf.gname); |
| 55 | LOG(" devmajor = \"%.8s\"\n", t->th_buf.devmajor); |
| 56 | LOG(" devminor = \"%.8s\"\n", t->th_buf.devminor); |
| 57 | LOG(" prefix = \"%.155s\"\n", t->th_buf.prefix); |
| 58 | LOG(" padding = \"%.12s\"\n", t->th_buf.padding); |
| 59 | LOG(" gnu_longname = \"%s\"\n", |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 60 | (t->th_buf.gnu_longname ? t->th_buf.gnu_longname : "[NULL]")); |
Mohd Faraz | 566ef6b | 2023-01-16 16:16:21 +0100 | [diff] [blame] | 61 | LOG(" gnu_longlink = \"%s\"\n", |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 62 | (t->th_buf.gnu_longlink ? t->th_buf.gnu_longlink : "[NULL]")); |
bigbiff | 7ba7500 | 2020-04-11 20:47:09 -0400 | [diff] [blame] | 63 | #ifdef USE_FSCRYPT |
Mohd Faraz | 566ef6b | 2023-01-16 16:16:21 +0100 | [diff] [blame] | 64 | LOG(" fep = \"%s\"\n", |
Mohd Faraz | 97b8499 | 2023-01-07 21:26:56 +0100 | [diff] [blame] | 65 | (t->th_buf.fep ? get_policy_descriptor(t->th_buf.fep) : (uint8_t*) "[NULL]")); |
bigbiff | 2e344ab | 2021-05-07 10:41:55 -0400 | [diff] [blame] | 66 | #endif |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | |
| 70 | void |
| 71 | th_print_long_ls(TAR *t) |
| 72 | { |
| 73 | char modestring[12]; |
| 74 | struct passwd *pw; |
| 75 | struct group *gr; |
| 76 | uid_t uid; |
| 77 | gid_t gid; |
| 78 | char username[_POSIX_LOGIN_NAME_MAX]; |
| 79 | char groupname[_POSIX_LOGIN_NAME_MAX]; |
| 80 | time_t mtime; |
| 81 | struct tm *mtm; |
| 82 | |
| 83 | #ifdef HAVE_STRFTIME |
| 84 | char timebuf[18]; |
| 85 | #else |
| 86 | const char *months[] = { |
| 87 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
| 88 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" |
| 89 | }; |
| 90 | #endif |
| 91 | |
| 92 | uid = th_get_uid(t); |
| 93 | pw = getpwuid(uid); |
James Christopher Adduono | 6f57f7c | 2016-03-01 16:01:53 -0500 | [diff] [blame] | 94 | if ((t->options & TAR_USE_NUMERIC_ID) || pw == NULL) |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 95 | snprintf(username, sizeof(username), "%d", uid); |
| 96 | else |
| 97 | strlcpy(username, pw->pw_name, sizeof(username)); |
| 98 | |
| 99 | gid = th_get_gid(t); |
| 100 | gr = getgrgid(gid); |
James Christopher Adduono | 6f57f7c | 2016-03-01 16:01:53 -0500 | [diff] [blame] | 101 | if ((t->options & TAR_USE_NUMERIC_ID) || gr == NULL) |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 102 | snprintf(groupname, sizeof(groupname), "%d", gid); |
| 103 | else |
| 104 | strlcpy(groupname, gr->gr_name, sizeof(groupname)); |
| 105 | |
| 106 | strmode(th_get_mode(t), modestring); |
Mohd Faraz | 566ef6b | 2023-01-16 16:16:21 +0100 | [diff] [blame] | 107 | LOG("%.10s %-8.8s %-8.8s ", modestring, username, groupname); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 108 | |
| 109 | if (TH_ISCHR(t) || TH_ISBLK(t)) |
Mohd Faraz | 566ef6b | 2023-01-16 16:16:21 +0100 | [diff] [blame] | 110 | LOG(" %3d, %3d ", (int)th_get_devmajor(t), (int)th_get_devminor(t)); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 111 | else |
Mohd Faraz | 566ef6b | 2023-01-16 16:16:21 +0100 | [diff] [blame] | 112 | LOG("%9ld ", (long)th_get_size(t)); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 113 | |
| 114 | mtime = th_get_mtime(t); |
| 115 | mtm = localtime(&mtime); |
| 116 | #ifdef HAVE_STRFTIME |
| 117 | strftime(timebuf, sizeof(timebuf), "%h %e %H:%M %Y", mtm); |
Mohd Faraz | 566ef6b | 2023-01-16 16:16:21 +0100 | [diff] [blame] | 118 | LOG("%s", timebuf); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 119 | #else |
Mohd Faraz | 566ef6b | 2023-01-16 16:16:21 +0100 | [diff] [blame] | 120 | LOG("%.3s %2d %2d:%02d %4d", |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 121 | months[mtm->tm_mon], |
| 122 | mtm->tm_mday, mtm->tm_hour, mtm->tm_min, mtm->tm_year + 1900); |
| 123 | #endif |
| 124 | |
Mohd Faraz | 566ef6b | 2023-01-16 16:16:21 +0100 | [diff] [blame] | 125 | LOG(" %s", th_get_pathname(t)); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 126 | |
| 127 | if (TH_ISSYM(t) || TH_ISLNK(t)) |
| 128 | { |
| 129 | if (TH_ISSYM(t)) |
Mohd Faraz | 566ef6b | 2023-01-16 16:16:21 +0100 | [diff] [blame] | 130 | LOG(" -> "); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 131 | else |
Mohd Faraz | 566ef6b | 2023-01-16 16:16:21 +0100 | [diff] [blame] | 132 | LOG(" link to "); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 133 | if ((t->options & TAR_GNU) && t->th_buf.gnu_longlink != NULL) |
Mohd Faraz | 566ef6b | 2023-01-16 16:16:21 +0100 | [diff] [blame] | 134 | LOG("%s", t->th_buf.gnu_longlink); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 135 | else |
Mohd Faraz | 566ef6b | 2023-01-16 16:16:21 +0100 | [diff] [blame] | 136 | LOG("%.100s", t->th_buf.linkname); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 137 | } |
| 138 | |
| 139 | putchar('\n'); |
| 140 | } |
| 141 | |
| 142 | |