blob: 8611b415549484834200f7ab21674476c0848c2e [file] [log] [blame]
bigbiff bigbiff9c754052013-01-09 09:09:08 -05001/*
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 Adduono6f57f7c2016-03-01 16:01:53 -050016#include <stdlib.h>
bigbiff bigbiff9c754052013-01-09 09:09:08 -050017#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
bigbiff7ba75002020-04-11 20:47:09 -040027#ifdef USE_FSCRYPT
28#include "fscrypt_policy.h"
29#endif
bigbiff bigbiff9c754052013-01-09 09:09:08 -050030
31#ifndef _POSIX_LOGIN_NAME_MAX
32# define _POSIX_LOGIN_NAME_MAX 9
33#endif
34
35
36void
37th_print(TAR *t)
38{
Mohd Faraz15247642023-01-16 16:16:21 +010039 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 Yonkerfefe5912017-09-30 22:22:13 -050052 t->th_buf.version[0], t->th_buf.version[1]);*/
Mohd Faraz15247642023-01-16 16:16:21 +010053 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 bigbiff9c754052013-01-09 09:09:08 -050060 (t->th_buf.gnu_longname ? t->th_buf.gnu_longname : "[NULL]"));
Mohd Faraz15247642023-01-16 16:16:21 +010061 LOG(" gnu_longlink = \"%s\"\n",
bigbiff bigbiff9c754052013-01-09 09:09:08 -050062 (t->th_buf.gnu_longlink ? t->th_buf.gnu_longlink : "[NULL]"));
bigbiffa957f072021-03-07 18:20:29 -050063
bigbiff7ba75002020-04-11 20:47:09 -040064#ifdef USE_FSCRYPT
bigbiff2e344ab2021-05-07 10:41:55 -040065#ifdef USE_FSCRYPT_POLICY_V1
Mohd Faraz15247642023-01-16 16:16:21 +010066 LOG(" fep = \"%s\"\n",
bigbiff2e344ab2021-05-07 10:41:55 -040067 (t->th_buf.fep ? t->th_buf.fep->master_key_descriptor : (uint8_t*) "[NULL]"));
68#else
Mohd Faraz15247642023-01-16 16:16:21 +010069 LOG(" fep = \"%s\"\n",
bigbiffa957f072021-03-07 18:20:29 -050070 (t->th_buf.fep ? t->th_buf.fep->master_key_identifier : (uint8_t*) "[NULL]"));
bigbiff7ba75002020-04-11 20:47:09 -040071#endif
bigbiff2e344ab2021-05-07 10:41:55 -040072#endif
bigbiff bigbiff9c754052013-01-09 09:09:08 -050073}
74
75
76void
77th_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 Adduono6f57f7c2016-03-01 16:01:53 -0500100 if ((t->options & TAR_USE_NUMERIC_ID) || pw == NULL)
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500101 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 Adduono6f57f7c2016-03-01 16:01:53 -0500107 if ((t->options & TAR_USE_NUMERIC_ID) || gr == NULL)
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500108 snprintf(groupname, sizeof(groupname), "%d", gid);
109 else
110 strlcpy(groupname, gr->gr_name, sizeof(groupname));
111
112 strmode(th_get_mode(t), modestring);
Mohd Faraz15247642023-01-16 16:16:21 +0100113 LOG("%.10s %-8.8s %-8.8s ", modestring, username, groupname);
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500114
115 if (TH_ISCHR(t) || TH_ISBLK(t))
Mohd Faraz15247642023-01-16 16:16:21 +0100116 LOG(" %3d, %3d ", (int)th_get_devmajor(t), (int)th_get_devminor(t));
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500117 else
Mohd Faraz15247642023-01-16 16:16:21 +0100118 LOG("%9ld ", (long)th_get_size(t));
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500119
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);
Mohd Faraz15247642023-01-16 16:16:21 +0100124 LOG("%s", timebuf);
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500125#else
Mohd Faraz15247642023-01-16 16:16:21 +0100126 LOG("%.3s %2d %2d:%02d %4d",
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500127 months[mtm->tm_mon],
128 mtm->tm_mday, mtm->tm_hour, mtm->tm_min, mtm->tm_year + 1900);
129#endif
130
Mohd Faraz15247642023-01-16 16:16:21 +0100131 LOG(" %s", th_get_pathname(t));
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500132
133 if (TH_ISSYM(t) || TH_ISLNK(t))
134 {
135 if (TH_ISSYM(t))
Mohd Faraz15247642023-01-16 16:16:21 +0100136 LOG(" -> ");
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500137 else
Mohd Faraz15247642023-01-16 16:16:21 +0100138 LOG(" link to ");
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500139 if ((t->options & TAR_GNU) && t->th_buf.gnu_longlink != NULL)
Mohd Faraz15247642023-01-16 16:16:21 +0100140 LOG("%s", t->th_buf.gnu_longlink);
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500141 else
Mohd Faraz15247642023-01-16 16:16:21 +0100142 LOG("%.100s", t->th_buf.linkname);
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500143 }
144
145 putchar('\n');
146}
147
148