1*5c51f124SMoriah Waterland /*
2*5c51f124SMoriah Waterland * CDDL HEADER START
3*5c51f124SMoriah Waterland *
4*5c51f124SMoriah Waterland * The contents of this file are subject to the terms of the
5*5c51f124SMoriah Waterland * Common Development and Distribution License (the "License").
6*5c51f124SMoriah Waterland * You may not use this file except in compliance with the License.
7*5c51f124SMoriah Waterland *
8*5c51f124SMoriah Waterland * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9*5c51f124SMoriah Waterland * or http://www.opensolaris.org/os/licensing.
10*5c51f124SMoriah Waterland * See the License for the specific language governing permissions
11*5c51f124SMoriah Waterland * and limitations under the License.
12*5c51f124SMoriah Waterland *
13*5c51f124SMoriah Waterland * When distributing Covered Code, include this CDDL HEADER in each
14*5c51f124SMoriah Waterland * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15*5c51f124SMoriah Waterland * If applicable, add the following below this CDDL HEADER, with the
16*5c51f124SMoriah Waterland * fields enclosed by brackets "[]" replaced with your own identifying
17*5c51f124SMoriah Waterland * information: Portions Copyright [yyyy] [name of copyright owner]
18*5c51f124SMoriah Waterland *
19*5c51f124SMoriah Waterland * CDDL HEADER END
20*5c51f124SMoriah Waterland */
21*5c51f124SMoriah Waterland
22*5c51f124SMoriah Waterland /*
23*5c51f124SMoriah Waterland * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24*5c51f124SMoriah Waterland * Use is subject to license terms.
25*5c51f124SMoriah Waterland */
26*5c51f124SMoriah Waterland
27*5c51f124SMoriah Waterland /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */
28*5c51f124SMoriah Waterland /* All Rights Reserved */
29*5c51f124SMoriah Waterland
30*5c51f124SMoriah Waterland
31*5c51f124SMoriah Waterland
32*5c51f124SMoriah Waterland #include <stdio.h>
33*5c51f124SMoriah Waterland #include <string.h>
34*5c51f124SMoriah Waterland #include <limits.h>
35*5c51f124SMoriah Waterland #include <sys/types.h>
36*5c51f124SMoriah Waterland #include <pkgstrct.h>
37*5c51f124SMoriah Waterland #include <locale.h>
38*5c51f124SMoriah Waterland #include <libintl.h>
39*5c51f124SMoriah Waterland
40*5c51f124SMoriah Waterland /*
41*5c51f124SMoriah Waterland * consolidation pkg command library includes
42*5c51f124SMoriah Waterland */
43*5c51f124SMoriah Waterland
44*5c51f124SMoriah Waterland #include <pkglib.h>
45*5c51f124SMoriah Waterland
46*5c51f124SMoriah Waterland /*
47*5c51f124SMoriah Waterland * local pkg command library includes
48*5c51f124SMoriah Waterland */
49*5c51f124SMoriah Waterland
50*5c51f124SMoriah Waterland #include "install.h"
51*5c51f124SMoriah Waterland #include "libinst.h"
52*5c51f124SMoriah Waterland #include "libadm.h"
53*5c51f124SMoriah Waterland #include "messages.h"
54*5c51f124SMoriah Waterland
55*5c51f124SMoriah Waterland extern int warnflag;
56*5c51f124SMoriah Waterland
57*5c51f124SMoriah Waterland /*
58*5c51f124SMoriah Waterland * forward declarations
59*5c51f124SMoriah Waterland */
60*5c51f124SMoriah Waterland
61*5c51f124SMoriah Waterland static int finalck_warning(struct cfent *ept, int attrchg, int contchg);
62*5c51f124SMoriah Waterland static int finalck_error(struct cfent *ept, int attrchg, int contchg);
63*5c51f124SMoriah Waterland
64*5c51f124SMoriah Waterland int
finalck(struct cfent * ept,int attrchg,int contchg,boolean_t a_warning)65*5c51f124SMoriah Waterland finalck(struct cfent *ept, int attrchg, int contchg, boolean_t a_warning)
66*5c51f124SMoriah Waterland {
67*5c51f124SMoriah Waterland int errflg;
68*5c51f124SMoriah Waterland
69*5c51f124SMoriah Waterland /*
70*5c51f124SMoriah Waterland * invoke the correct finalck based on whether warnings or errors
71*5c51f124SMoriah Waterland * should be generated
72*5c51f124SMoriah Waterland */
73*5c51f124SMoriah Waterland
74*5c51f124SMoriah Waterland if (a_warning) {
75*5c51f124SMoriah Waterland errflg = finalck_warning(ept, attrchg, contchg);
76*5c51f124SMoriah Waterland } else {
77*5c51f124SMoriah Waterland errflg = finalck_error(ept, attrchg, contchg);
78*5c51f124SMoriah Waterland }
79*5c51f124SMoriah Waterland
80*5c51f124SMoriah Waterland /* exit debug output */
81*5c51f124SMoriah Waterland
82*5c51f124SMoriah Waterland echoDebug(DBG_FINALCK_EXIT, errflg, ept->ftype,
83*5c51f124SMoriah Waterland ept->path ? ept->path : "");
84*5c51f124SMoriah Waterland
85*5c51f124SMoriah Waterland /* return results of the finalck_xxx call */
86*5c51f124SMoriah Waterland
87*5c51f124SMoriah Waterland return (errflg);
88*5c51f124SMoriah Waterland }
89*5c51f124SMoriah Waterland
90*5c51f124SMoriah Waterland /*
91*5c51f124SMoriah Waterland * this finalck generates errors on failure
92*5c51f124SMoriah Waterland */
93*5c51f124SMoriah Waterland
94*5c51f124SMoriah Waterland static int
finalck_error(struct cfent * ept,int attrchg,int contchg)95*5c51f124SMoriah Waterland finalck_error(struct cfent *ept, int attrchg, int contchg)
96*5c51f124SMoriah Waterland {
97*5c51f124SMoriah Waterland int errflg = 0;
98*5c51f124SMoriah Waterland
99*5c51f124SMoriah Waterland /* entry debug info */
100*5c51f124SMoriah Waterland
101*5c51f124SMoriah Waterland echoDebug(DBG_FINALCK_ERROR, attrchg, contchg, ept->ftype,
102*5c51f124SMoriah Waterland ept->path ? ept->path : "");
103*5c51f124SMoriah Waterland
104*5c51f124SMoriah Waterland /* on attribute or content change, verify attributes */
105*5c51f124SMoriah Waterland
106*5c51f124SMoriah Waterland if (attrchg || contchg) {
107*5c51f124SMoriah Waterland int n;
108*5c51f124SMoriah Waterland
109*5c51f124SMoriah Waterland /* verify change, or fix if possible */
110*5c51f124SMoriah Waterland n = averify(1, &ept->ftype, ept->path, &ept->ainfo);
111*5c51f124SMoriah Waterland echoDebug(DBG_FINALCK_ERROR_AVERIFY, n);
112*5c51f124SMoriah Waterland if (n != 0) {
113*5c51f124SMoriah Waterland logerr(ERR_FINALCK_ATTR, ept->path);
114*5c51f124SMoriah Waterland logerr(getErrbufAddr());
115*5c51f124SMoriah Waterland errflg++;
116*5c51f124SMoriah Waterland warnflag++;
117*5c51f124SMoriah Waterland if (n == VE_EXIST)
118*5c51f124SMoriah Waterland return (1); /* no need to check contents */
119*5c51f124SMoriah Waterland }
120*5c51f124SMoriah Waterland }
121*5c51f124SMoriah Waterland
122*5c51f124SMoriah Waterland /* on content change of "f/e/v" type, verify contents */
123*5c51f124SMoriah Waterland
124*5c51f124SMoriah Waterland if (contchg && strchr("fev", ept->ftype)) {
125*5c51f124SMoriah Waterland int n;
126*5c51f124SMoriah Waterland
127*5c51f124SMoriah Waterland /* verify change was executed properly */
128*5c51f124SMoriah Waterland
129*5c51f124SMoriah Waterland if (contchg < 0) {
130*5c51f124SMoriah Waterland ept->cinfo.modtime = BADCONT;
131*5c51f124SMoriah Waterland ept->cinfo.size = BADCONT;
132*5c51f124SMoriah Waterland ept->cinfo.cksum = BADCONT;
133*5c51f124SMoriah Waterland }
134*5c51f124SMoriah Waterland
135*5c51f124SMoriah Waterland n = cverify(1, &ept->ftype, ept->path, &ept->cinfo, 1);
136*5c51f124SMoriah Waterland echoDebug(DBG_FINALCK_ERROR_CVERIFY, n);
137*5c51f124SMoriah Waterland if (n != 0) {
138*5c51f124SMoriah Waterland logerr(ERR_FINALCK_CONT, ept->path);
139*5c51f124SMoriah Waterland logerr(getErrbufAddr());
140*5c51f124SMoriah Waterland errflg++;
141*5c51f124SMoriah Waterland warnflag++;
142*5c51f124SMoriah Waterland }
143*5c51f124SMoriah Waterland }
144*5c51f124SMoriah Waterland
145*5c51f124SMoriah Waterland return (errflg);
146*5c51f124SMoriah Waterland }
147*5c51f124SMoriah Waterland
148*5c51f124SMoriah Waterland /*
149*5c51f124SMoriah Waterland * this finalck generates warnings on failure
150*5c51f124SMoriah Waterland */
151*5c51f124SMoriah Waterland
152*5c51f124SMoriah Waterland static int
finalck_warning(struct cfent * ept,int attrchg,int contchg)153*5c51f124SMoriah Waterland finalck_warning(struct cfent *ept, int attrchg, int contchg)
154*5c51f124SMoriah Waterland {
155*5c51f124SMoriah Waterland int errflg = 0;
156*5c51f124SMoriah Waterland
157*5c51f124SMoriah Waterland /* entry debug info */
158*5c51f124SMoriah Waterland
159*5c51f124SMoriah Waterland echoDebug(DBG_FINALCK_WARNING, attrchg, contchg, ept->ftype,
160*5c51f124SMoriah Waterland ept->path ? ept->path : "");
161*5c51f124SMoriah Waterland
162*5c51f124SMoriah Waterland
163*5c51f124SMoriah Waterland /* on attribute or content change, verify attributes */
164*5c51f124SMoriah Waterland
165*5c51f124SMoriah Waterland if (attrchg || contchg) {
166*5c51f124SMoriah Waterland int n;
167*5c51f124SMoriah Waterland
168*5c51f124SMoriah Waterland /* verify change, or fix if possible */
169*5c51f124SMoriah Waterland
170*5c51f124SMoriah Waterland n = averify(1, &ept->ftype, ept->path, &ept->ainfo);
171*5c51f124SMoriah Waterland echoDebug(DBG_FINALCK_WARNING_AVERIFY, n);
172*5c51f124SMoriah Waterland if (n != 0) {
173*5c51f124SMoriah Waterland logerr(WRN_FINALCK_ATTR, ept->path);
174*5c51f124SMoriah Waterland logerr(getErrbufAddr());
175*5c51f124SMoriah Waterland errflg++;
176*5c51f124SMoriah Waterland if (n == VE_EXIST) {
177*5c51f124SMoriah Waterland return (1); /* no need to check contents */
178*5c51f124SMoriah Waterland }
179*5c51f124SMoriah Waterland }
180*5c51f124SMoriah Waterland }
181*5c51f124SMoriah Waterland
182*5c51f124SMoriah Waterland /* on content change of "f/e/v" type, verify contents */
183*5c51f124SMoriah Waterland
184*5c51f124SMoriah Waterland if (contchg && strchr("fev", ept->ftype)) {
185*5c51f124SMoriah Waterland int n;
186*5c51f124SMoriah Waterland
187*5c51f124SMoriah Waterland /* verify change was executed properly */
188*5c51f124SMoriah Waterland
189*5c51f124SMoriah Waterland if (contchg < 0) {
190*5c51f124SMoriah Waterland ept->cinfo.modtime = BADCONT;
191*5c51f124SMoriah Waterland ept->cinfo.size = BADCONT;
192*5c51f124SMoriah Waterland ept->cinfo.cksum = BADCONT;
193*5c51f124SMoriah Waterland }
194*5c51f124SMoriah Waterland
195*5c51f124SMoriah Waterland n = cverify(1, &ept->ftype, ept->path, &ept->cinfo, 1);
196*5c51f124SMoriah Waterland echoDebug(DBG_FINALCK_WARNING_CVERIFY, n);
197*5c51f124SMoriah Waterland if (n != 0) {
198*5c51f124SMoriah Waterland logerr(WRN_FINALCK_CONT, ept->path);
199*5c51f124SMoriah Waterland logerr(getErrbufAddr());
200*5c51f124SMoriah Waterland }
201*5c51f124SMoriah Waterland errflg++;
202*5c51f124SMoriah Waterland }
203*5c51f124SMoriah Waterland
204*5c51f124SMoriah Waterland return (errflg);
205*5c51f124SMoriah Waterland }
206