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