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 | { |
| 39 | puts("\nPrinting tar header:"); |
| 40 | printf(" name = \"%.100s\"\n", t->th_buf.name); |
| 41 | printf(" mode = \"%.8s\"\n", t->th_buf.mode); |
| 42 | printf(" uid = \"%.8s\"\n", t->th_buf.uid); |
| 43 | printf(" gid = \"%.8s\"\n", t->th_buf.gid); |
| 44 | printf(" size = \"%.12s\"\n", t->th_buf.size); |
| 45 | printf(" mtime = \"%.12s\"\n", t->th_buf.mtime); |
| 46 | printf(" chksum = \"%.8s\"\n", t->th_buf.chksum); |
| 47 | printf(" typeflag = \'%c\'\n", t->th_buf.typeflag); |
| 48 | printf(" linkname = \"%.100s\"\n", t->th_buf.linkname); |
| 49 | printf(" magic = \"%.6s\"\n", t->th_buf.magic); |
| 50 | /*printf(" version = \"%.2s\"\n", t->th_buf.version); */ |
Ethan Yonker | fefe591 | 2017-09-30 22:22:13 -0500 | [diff] [blame] | 51 | /*printf(" version[0] = \'%c\',version[1] = \'%c\'\n", |
| 52 | t->th_buf.version[0], t->th_buf.version[1]);*/ |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 53 | printf(" uname = \"%.32s\"\n", t->th_buf.uname); |
| 54 | printf(" gname = \"%.32s\"\n", t->th_buf.gname); |
| 55 | printf(" devmajor = \"%.8s\"\n", t->th_buf.devmajor); |
| 56 | printf(" devminor = \"%.8s\"\n", t->th_buf.devminor); |
| 57 | printf(" prefix = \"%.155s\"\n", t->th_buf.prefix); |
| 58 | printf(" padding = \"%.12s\"\n", t->th_buf.padding); |
| 59 | printf(" gnu_longname = \"%s\"\n", |
| 60 | (t->th_buf.gnu_longname ? t->th_buf.gnu_longname : "[NULL]")); |
| 61 | printf(" gnu_longlink = \"%s\"\n", |
| 62 | (t->th_buf.gnu_longlink ? t->th_buf.gnu_longlink : "[NULL]")); |
bigbiff | a957f07 | 2021-03-07 18:20:29 -0500 | [diff] [blame] | 63 | |
bigbiff | 7ba7500 | 2020-04-11 20:47:09 -0400 | [diff] [blame] | 64 | #ifdef USE_FSCRYPT |
bigbiff | 2e344ab | 2021-05-07 10:41:55 -0400 | [diff] [blame] | 65 | #ifdef USE_FSCRYPT_POLICY_V1 |
| 66 | printf(" fep = \"%s\"\n", |
| 67 | (t->th_buf.fep ? t->th_buf.fep->master_key_descriptor : (uint8_t*) "[NULL]")); |
| 68 | #else |
bigbiff | 7ba7500 | 2020-04-11 20:47:09 -0400 | [diff] [blame] | 69 | printf(" fep = \"%s\"\n", |
bigbiff | a957f07 | 2021-03-07 18:20:29 -0500 | [diff] [blame] | 70 | (t->th_buf.fep ? t->th_buf.fep->master_key_identifier : (uint8_t*) "[NULL]")); |
bigbiff | 7ba7500 | 2020-04-11 20:47:09 -0400 | [diff] [blame] | 71 | #endif |
bigbiff | 2e344ab | 2021-05-07 10:41:55 -0400 | [diff] [blame] | 72 | #endif |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | |
| 76 | void |
| 77 | th_print_long_ls(TAR *t) |
| 78 | { |
| 79 | char modestring[12]; |
| 80 | struct passwd *pw; |
| 81 | struct group *gr; |
| 82 | uid_t uid; |
| 83 | gid_t gid; |
| 84 | char username[_POSIX_LOGIN_NAME_MAX]; |
| 85 | char groupname[_POSIX_LOGIN_NAME_MAX]; |
| 86 | time_t mtime; |
| 87 | struct tm *mtm; |
| 88 | |
| 89 | #ifdef HAVE_STRFTIME |
| 90 | char timebuf[18]; |
| 91 | #else |
| 92 | const char *months[] = { |
| 93 | "Jan", "Feb", "Mar", "Apr", "May", "Jun", |
| 94 | "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" |
| 95 | }; |
| 96 | #endif |
| 97 | |
| 98 | uid = th_get_uid(t); |
| 99 | pw = getpwuid(uid); |
James Christopher Adduono | 6f57f7c | 2016-03-01 16:01:53 -0500 | [diff] [blame] | 100 | if ((t->options & TAR_USE_NUMERIC_ID) || pw == NULL) |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 101 | snprintf(username, sizeof(username), "%d", uid); |
| 102 | else |
| 103 | strlcpy(username, pw->pw_name, sizeof(username)); |
| 104 | |
| 105 | gid = th_get_gid(t); |
| 106 | gr = getgrgid(gid); |
James Christopher Adduono | 6f57f7c | 2016-03-01 16:01:53 -0500 | [diff] [blame] | 107 | if ((t->options & TAR_USE_NUMERIC_ID) || gr == NULL) |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 108 | snprintf(groupname, sizeof(groupname), "%d", gid); |
| 109 | else |
| 110 | strlcpy(groupname, gr->gr_name, sizeof(groupname)); |
| 111 | |
| 112 | strmode(th_get_mode(t), modestring); |
| 113 | printf("%.10s %-8.8s %-8.8s ", modestring, username, groupname); |
| 114 | |
| 115 | if (TH_ISCHR(t) || TH_ISBLK(t)) |
James Christopher Adduono | 6f57f7c | 2016-03-01 16:01:53 -0500 | [diff] [blame] | 116 | printf(" %3d, %3d ", (int)th_get_devmajor(t), (int)th_get_devminor(t)); |
bigbiff bigbiff | 9c75405 | 2013-01-09 09:09:08 -0500 | [diff] [blame] | 117 | else |
| 118 | printf("%9ld ", (long)th_get_size(t)); |
| 119 | |
| 120 | mtime = th_get_mtime(t); |
| 121 | mtm = localtime(&mtime); |
| 122 | #ifdef HAVE_STRFTIME |
| 123 | strftime(timebuf, sizeof(timebuf), "%h %e %H:%M %Y", mtm); |
| 124 | printf("%s", timebuf); |
| 125 | #else |
| 126 | printf("%.3s %2d %2d:%02d %4d", |
| 127 | months[mtm->tm_mon], |
| 128 | mtm->tm_mday, mtm->tm_hour, mtm->tm_min, mtm->tm_year + 1900); |
| 129 | #endif |
| 130 | |
| 131 | printf(" %s", th_get_pathname(t)); |
| 132 | |
| 133 | if (TH_ISSYM(t) || TH_ISLNK(t)) |
| 134 | { |
| 135 | if (TH_ISSYM(t)) |
| 136 | printf(" -> "); |
| 137 | else |
| 138 | printf(" link to "); |
| 139 | if ((t->options & TAR_GNU) && t->th_buf.gnu_longlink != NULL) |
| 140 | printf("%s", t->th_buf.gnu_longlink); |
| 141 | else |
| 142 | printf("%.100s", t->th_buf.linkname); |
| 143 | } |
| 144 | |
| 145 | putchar('\n'); |
| 146 | } |
| 147 | |
| 148 | |