blob: 68c3e5f27421e81f785366669418eee3dc3c51cc [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
Ethan Yonkerfefe5912017-09-30 22:22:13 -050027#ifdef HAVE_EXT4_CRYPT
bigbiff7ba75002020-04-11 20:47:09 -040028#include "ext4crypt_tar.h"
Ethan Yonkerfefe5912017-09-30 22:22:13 -050029#endif
30
bigbiff7ba75002020-04-11 20:47:09 -040031#ifdef USE_FSCRYPT
32#include "fscrypt_policy.h"
33#endif
bigbiff bigbiff9c754052013-01-09 09:09:08 -050034
35#ifndef _POSIX_LOGIN_NAME_MAX
36# define _POSIX_LOGIN_NAME_MAX 9
37#endif
38
39
40void
41th_print(TAR *t)
42{
43 puts("\nPrinting tar header:");
44 printf(" name = \"%.100s\"\n", t->th_buf.name);
45 printf(" mode = \"%.8s\"\n", t->th_buf.mode);
46 printf(" uid = \"%.8s\"\n", t->th_buf.uid);
47 printf(" gid = \"%.8s\"\n", t->th_buf.gid);
48 printf(" size = \"%.12s\"\n", t->th_buf.size);
49 printf(" mtime = \"%.12s\"\n", t->th_buf.mtime);
50 printf(" chksum = \"%.8s\"\n", t->th_buf.chksum);
51 printf(" typeflag = \'%c\'\n", t->th_buf.typeflag);
52 printf(" linkname = \"%.100s\"\n", t->th_buf.linkname);
53 printf(" magic = \"%.6s\"\n", t->th_buf.magic);
54 /*printf(" version = \"%.2s\"\n", t->th_buf.version); */
Ethan Yonkerfefe5912017-09-30 22:22:13 -050055 /*printf(" version[0] = \'%c\',version[1] = \'%c\'\n",
56 t->th_buf.version[0], t->th_buf.version[1]);*/
bigbiff bigbiff9c754052013-01-09 09:09:08 -050057 printf(" uname = \"%.32s\"\n", t->th_buf.uname);
58 printf(" gname = \"%.32s\"\n", t->th_buf.gname);
59 printf(" devmajor = \"%.8s\"\n", t->th_buf.devmajor);
60 printf(" devminor = \"%.8s\"\n", t->th_buf.devminor);
61 printf(" prefix = \"%.155s\"\n", t->th_buf.prefix);
62 printf(" padding = \"%.12s\"\n", t->th_buf.padding);
63 printf(" gnu_longname = \"%s\"\n",
64 (t->th_buf.gnu_longname ? t->th_buf.gnu_longname : "[NULL]"));
65 printf(" gnu_longlink = \"%s\"\n",
66 (t->th_buf.gnu_longlink ? t->th_buf.gnu_longlink : "[NULL]"));
Ethan Yonkerfefe5912017-09-30 22:22:13 -050067#ifdef HAVE_EXT4_CRYPT
68 printf(" eep = \"%s\"\n",
69 (t->th_buf.eep ? t->th_buf.eep->master_key_descriptor : "[NULL]"));
70#endif
bigbiff7ba75002020-04-11 20:47:09 -040071#ifdef USE_FSCRYPT
72 printf(" fep = \"%s\"\n",
73 (t->th_buf.fep ? t->th_buf.fep->master_key_descriptor : (uint8_t*) "[NULL]"));
74#endif
bigbiff bigbiff9c754052013-01-09 09:09:08 -050075}
76
77
78void
79th_print_long_ls(TAR *t)
80{
81 char modestring[12];
82 struct passwd *pw;
83 struct group *gr;
84 uid_t uid;
85 gid_t gid;
86 char username[_POSIX_LOGIN_NAME_MAX];
87 char groupname[_POSIX_LOGIN_NAME_MAX];
88 time_t mtime;
89 struct tm *mtm;
90
91#ifdef HAVE_STRFTIME
92 char timebuf[18];
93#else
94 const char *months[] = {
95 "Jan", "Feb", "Mar", "Apr", "May", "Jun",
96 "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
97 };
98#endif
99
100 uid = th_get_uid(t);
101 pw = getpwuid(uid);
James Christopher Adduono6f57f7c2016-03-01 16:01:53 -0500102 if ((t->options & TAR_USE_NUMERIC_ID) || pw == NULL)
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500103 snprintf(username, sizeof(username), "%d", uid);
104 else
105 strlcpy(username, pw->pw_name, sizeof(username));
106
107 gid = th_get_gid(t);
108 gr = getgrgid(gid);
James Christopher Adduono6f57f7c2016-03-01 16:01:53 -0500109 if ((t->options & TAR_USE_NUMERIC_ID) || gr == NULL)
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500110 snprintf(groupname, sizeof(groupname), "%d", gid);
111 else
112 strlcpy(groupname, gr->gr_name, sizeof(groupname));
113
114 strmode(th_get_mode(t), modestring);
115 printf("%.10s %-8.8s %-8.8s ", modestring, username, groupname);
116
117 if (TH_ISCHR(t) || TH_ISBLK(t))
James Christopher Adduono6f57f7c2016-03-01 16:01:53 -0500118 printf(" %3d, %3d ", (int)th_get_devmajor(t), (int)th_get_devminor(t));
bigbiff bigbiff9c754052013-01-09 09:09:08 -0500119 else
120 printf("%9ld ", (long)th_get_size(t));
121
122 mtime = th_get_mtime(t);
123 mtm = localtime(&mtime);
124#ifdef HAVE_STRFTIME
125 strftime(timebuf, sizeof(timebuf), "%h %e %H:%M %Y", mtm);
126 printf("%s", timebuf);
127#else
128 printf("%.3s %2d %2d:%02d %4d",
129 months[mtm->tm_mon],
130 mtm->tm_mday, mtm->tm_hour, mtm->tm_min, mtm->tm_year + 1900);
131#endif
132
133 printf(" %s", th_get_pathname(t));
134
135 if (TH_ISSYM(t) || TH_ISLNK(t))
136 {
137 if (TH_ISSYM(t))
138 printf(" -> ");
139 else
140 printf(" link to ");
141 if ((t->options & TAR_GNU) && t->th_buf.gnu_longlink != NULL)
142 printf("%s", t->th_buf.gnu_longlink);
143 else
144 printf("%.100s", t->th_buf.linkname);
145 }
146
147 putchar('\n');
148}
149
150