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