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