4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28 /* All Rights Reserved */
36 #include <sys/types.h>
48 extern int Lflag
, lflag
, aflag
, cflag
, fflag
, qflag
, nflag
, xflag
, vflag
;
49 extern char *basedir
, *device
, pkgspool
[];
51 #define NXTENTRY(P, VFP) (gpkgmapvfp((P), (VFP)))
53 #define ERR_SPOOLED "ERROR: unable to locate spooled object <%s>"
54 #define MSG_NET_OBJ "It is remote and may be available from the network."
55 #define ERR_RMHIDDEN "unable to remove hidden file"
56 #define ERR_HIDDEN "ERROR: hidden file in exclusive directory"
58 static char *findspool(struct cfent
*ept
);
59 static int xdir(int maptyp
, VFP_T
*vfp
, PKGserver server
, char *dirname
);
62 ckentry(int envflag
, int maptyp
, struct cfent
*ept
, VFP_T
*vfp
,
68 char *ir
= get_inst_root();
70 if (ept
->ftype
!= 'i') {
72 mappath(2, ept
->path
);
74 basepath(ept
->path
, maptyp
? NULL
: basedir
, ir
);
77 if (strchr("sl", ept
->ftype
)) {
78 if (envflag
) /* -e option */
79 mappath(2, ept
->ainfo
.local
);
80 if (!RELATIVE(ept
->ainfo
.local
)) { /* Absolute Path */
82 if (ept
->ftype
== 'l') /* Hard Link */
83 basepath(ept
->ainfo
.local
, NULL
, ir
);
86 if (!RELATIVE(ept
->ainfo
.local
)) /* Absolute Path */
87 canonize(ept
->ainfo
.local
);
90 if (!strchr("isl", ept
->ftype
)) {
91 mapvar(2, ept
->ainfo
.owner
);
92 mapvar(2, ept
->ainfo
.group
);
97 tputcfent(ept
, stdout
);
100 return (putcfile(ept
, stdout
));
104 if (strchr("dxslcbp", ept
->ftype
))
106 if ((path
= findspool(ept
)) == NULL
) {
107 logerr(gettext(ERR_SPOOLED
), ept
->path
);
112 * If the package file attributes are to be sync'd up with
113 * the pkgmap, we fix the attributes here.
117 /* Clear dangerous bits. */
118 ept
->ainfo
.mode
= (ept
->ainfo
.mode
& S_IAMB
);
120 * Make sure the file is readable by the world and
123 ept
->ainfo
.mode
|= 0644;
124 if (!strchr("in", ept
->ftype
)) {
125 /* Set the safe attributes. */
126 if (a_err
= averify(fflag
, &ept
->ftype
,
127 path
, &ept
->ainfo
)) {
129 if (!qflag
|| (a_err
!= VE_EXIST
)) {
130 logerr(gettext("ERROR: %s"),
132 logerr(getErrbufAddr());
134 if (a_err
== VE_EXIST
)
139 /* Report invalid modtimes by passing cverify a -1 */
140 c_err
= cverify((!fflag
? (-1) : fflag
), &ept
->ftype
, path
,
143 logerr(gettext("ERROR: %s"), path
);
144 logerr(getErrbufAddr());
149 if (aflag
&& !strchr("in", ept
->ftype
)) {
150 /* validate attributes */
151 if (a_err
= averify(fflag
, &ept
->ftype
, ept
->path
,
154 if (!qflag
|| (a_err
!= VE_EXIST
)) {
155 logerr(gettext("ERROR: %s"),
157 logerr(getErrbufAddr());
158 if (maptyp
&& ept
->pinfo
->status
==
160 logerr(gettext(MSG_NET_OBJ
));
162 if (a_err
== VE_EXIST
)
166 if (cflag
&& strchr("fev", ept
->ftype
) &&
167 (!nflag
|| ept
->ftype
!= 'v') && /* bug # 1082144 */
168 (!nflag
|| ept
->ftype
!= 'e')) {
169 /* validate contents */
170 /* Report invalid modtimes by passing cverify a -1 */
171 if (c_err
= cverify((!fflag
? (-1) : fflag
),
172 &ept
->ftype
, ept
->path
, &ept
->cinfo
, 1)) {
174 if (!qflag
|| (c_err
!= VE_EXIST
)) {
176 logerr(gettext("ERROR: %s"),
178 logerr(getErrbufAddr());
179 if (maptyp
&& ept
->pinfo
->status
==
181 logerr(gettext(MSG_NET_OBJ
));
183 if (c_err
== VE_EXIST
)
187 if (xflag
&& (ept
->ftype
== 'x')) {
188 /* must do verbose here since ept->path will change */
189 path
= strdup(ept
->path
);
190 if (xdir(maptyp
, vfp
, server
, path
))
192 (void) strcpy(ept
->path
, path
);
197 (void) fprintf(stderr
, "%s\n", ept
->path
);
202 xdir(int maptyp
, VFP_T
*vfp
, PKGserver server
, char *dirname
)
205 char badpath
[PATH_MAX
];
216 pos
= vfpGetCurrCharPtr(vfp
); /* get current position in file */
218 if ((dirfp
= opendir(dirname
)) == NULL
) {
219 progerr(gettext("unable to open directory <%s>"), dirname
);
222 len
= strlen(dirname
);
225 (void) memset((char *)&mine
, '\0', sizeof (struct cfent
));
226 while ((drp
= readdir(dirfp
)) != NULL
) {
227 if (strcmp(drp
->d_name
, ".") == NULL
||
228 strcmp(drp
->d_name
, "..") == NULL
)
230 (void) snprintf(badpath
, sizeof (badpath
), "%s/%s",
231 dirname
, drp
->d_name
);
234 while ((n
= NXTENTRY(&mine
, vfp
)) != 0) {
236 char *errstr
= getErrstr();
237 logerr(gettext("ERROR: garbled entry"));
238 logerr(gettext("pathname: %s"),
239 (mine
.path
&& *mine
.path
) ?
240 mine
.path
: "Unknown");
241 logerr(gettext("problem: %s"),
242 (errstr
&& *errstr
) ? errstr
:
246 if (strncmp(mine
.path
, dirname
, len
) ||
247 (mine
.path
[len
] != '/'))
249 if (strcmp(drp
->d_name
, &mine
.path
[len
+1]) ==
256 vfpGetCurrCharPtr(vfp
) = pos
;
261 if (srchcfile(&mine
, badpath
, server
) == 1) {
262 while ((pinfo
= mine
.pinfo
) != NULL
) {
263 mine
.pinfo
= pinfo
->next
;
271 if (unlink(badpath
)) {
273 logerr(gettext("ERROR: %s"), badpath
);
274 logerr(gettext(ERR_RMHIDDEN
));
278 logerr(gettext("ERROR: %s"), badpath
);
279 logerr(gettext(ERR_HIDDEN
));
283 (void) closedir(dirfp
);
288 findspool(struct cfent
*ept
)
290 static char path
[2*PATH_MAX
+1];
291 char host
[PATH_MAX
+1];
293 (void) strcpy(host
, pkgspool
);
294 if (ept
->ftype
== 'i') {
295 if (strcmp(ept
->path
, "pkginfo"))
296 (void) strcat(host
, "/install");
297 } else if (ept
->path
[0] == '/') {
298 (void) strcat(host
, "/root");
300 (void) strcat(host
, "/reloc");
303 (void) snprintf(path
, sizeof (path
), "%s/%s", host
,
304 ept
->path
+ (ept
->path
[0] == '/'));
306 if (access(path
, 0) == 0) {
310 if ((ept
->ftype
!= 'i') && (ept
->volno
> 0)) {
311 (void) snprintf(path
, sizeof (path
),
312 "%s.%d/%s", host
, ept
->volno
,
313 ept
->path
+ (ept
->path
[0] == '/'));
314 if (access(path
, 0) == 0) {