1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2009 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
#include <stdio.h>
#include <limits.h>
#include <string.h>
#include <stdlib.h>
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
#include <utmpx.h>
#include <dirent.h>
#include <sys/types.h>
#include <locale.h>
#include <libintl.h>
#include <pkgstrct.h>
#include <pkglocs.h>
#include <assert.h>
#include <pkglib.h>
#include <install.h>
#include <libinst.h>
#include <libadm.h>
#include <messages.h>
#include <instzones_api.h>
extern int npkgs; /* the number of packages yet to be installed */
/*
* ckquit is a global that controls 'ckyorn' (defined in libadm)
* If ckquit is non-zero, then "quit" is allowed as an answer when
* ckyorn is called. If is it zero, then "quit" is not an allowed answer.
*/
extern int ckquit;
extern struct admin adm;
/*
* each one of these represents a single kind of dependency check
*/
static depckError_t er_depsonme = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_prenci = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_prereq = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_rckdepend = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_rckpriv = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_rckrunlevel = {0, (depckErrorRecord_t *)NULL};
static depckError_t er_runlevel = {0, (depckErrorRecord_t *)NULL};
/*
* each one of these represents a localized message for a single kind
* of dependency check
*/
static char *IMSG_PKGRMCHK_CKRUNLVL = (char *)NULL;
static char *IMSG_PKGRMCHK_DEPEND = (char *)NULL;
static char *IMSG_PKGRMCHK_DEPSONME = (char *)NULL;
static char *IMSG_PKGRMCHK_PRENCI = (char *)NULL;
static char *IMSG_PKGRMCHK_PREREQ = (char *)NULL;
static char *IMSG_PKGRMCHK_PRIV = (char *)NULL;
static char *IMSG_PKGRMCHK_RUNLEVEL = (char *)NULL;
/*
* each one of these represents a function to handle a single kind of
* dependency check
*/
static int rckdepend(char *a_msg, char *a_pkg);
static int rckdepsonme(char *a_msg, char *a_pkg);
static int rckprenci(char *a_msg, char *a_pkg);
static int rckprereq(char *a_msg, char *a_pkg);
static int rckpriv(char *a_msg, char *a_pkg);
static int rckrunlevel(char *a_msg, char *a_pkg);
static depckl_t DEPCKL[] = {
/*
* Message hierarchy:
* -- runlevel=%s
* --- rckrunlevel=%d
* --- rckpriv=%d ****
* -- incompat=%s
* -- prerequisite-incomplete=%s
* -- dependonme=%s
* -- dependsonme=%s:%s
* -- prerequisite-installed=%s
* ---rckdepend=%d ****
*/
/* name, ignore_values, err_msg, depcklFunc, recrd */
/*
* package and zone information is collected in the "record" object for
* each occurance - then a message is constructed for each zone that
* reported the condition - the message includes that portion of the
* check past the "=" - then the specified "depcklFunc" is called to
* process each message.
* Message format:
* %s %s <%s> %s <%s>
* Message arguments:
* value, "package", package-name, "zone/zones", zone-name
*/
{ "dependsonme=", NULL, &IMSG_PKGRMCHK_DEPSONME,
&rckdepsonme, &er_depsonme
},
{ "dependonme=", NULL, &IMSG_PKGRMCHK_DEPSONME,
&rckdepsonme, &er_depsonme
},
{ "prerequisite-incomplete=", NULL, &IMSG_PKGRMCHK_PRENCI,
&rckprenci, &er_prenci
},
{ "prerequisite-installed=", NULL, &IMSG_PKGRMCHK_PREREQ,
&rckprereq, &er_prereq
},
{ "runlevel=", NULL, &IMSG_PKGRMCHK_RUNLEVEL,
NULL, &er_runlevel
},
/*
* these checks are ignored if they return one of the listed values
* if they do NOT return one of the listed values, then the package
* and zone information is collected in the "record" object for each
* occurance - then a single unified message is constructed for all
* zones that report the same condition; then the specified "depcklFunc"
* is called to process the resulting combined message.
* Message format:
* %s <%s> %s <%s>
* Message arguments:
* "package", package-name, "zone/zones", zone-name(s)
*/
{ "rckdepend=", "0", &IMSG_PKGRMCHK_DEPEND,
&rckdepend, &er_rckdepend
},
{ "rckpriv=", "0", &IMSG_PKGRMCHK_PRIV,
&rckpriv, &er_rckpriv
},
{ "rckrunlevel=", "0", &IMSG_PKGRMCHK_CKRUNLVL,
&rckrunlevel, &er_rckrunlevel
},
/*
* same as above BUT no check to ignore is done; message always reported
*/
{ NULL, NULL, NULL,
NULL, NULL
}
};
/*
* Name: preremove_verify
* Description: verify results of preremoval dependency checking
* Arguments: a_pkglist - pointer to array of strings representing the names
* of all the packages that have been checked
* a_zlst - list of zones that dependencies were checked on
* a_zoneTempDir - pointer to string representing the path where
* the files containing the preremoval dependency
* check data are located
* Returns: int
* == 0 - continue processing
* != 0 - do not continue processing
*/
int
preremove_verify(char **a_pkglist, zoneList_t a_zlst, char *a_zoneTempDir)
{
char *pkginst;
int i;
int savenpkgs = npkgs;
/*
* entry assertions
*/
assert(a_pkglist != (char **)NULL);
assert(a_zlst != (zoneList_t)NULL);
assert(a_zoneTempDir != (char *)NULL);
/*
* entry debugging info
*/
echoDebug(DBG_PRERVFY_ENTRY);
/*
* localize messages
*/
IMSG_PKGRMCHK_DEPSONME = MSG_PKGRMCHK_DEPSONME;
IMSG_PKGRMCHK_PRENCI = MSG_PKGRMCHK_PRENCI;
IMSG_PKGRMCHK_PREREQ = MSG_PKGRMCHK_PREREQ;
IMSG_PKGRMCHK_RUNLEVEL = MSG_PKGRMCHK_RUNLEVEL;
IMSG_PKGRMCHK_DEPEND = MSG_PKGRMCHK_DEPEND;
IMSG_PKGRMCHK_PRIV = MSG_PKGRMCHK_PRIV;
IMSG_PKGRMCHK_CKRUNLVL = MSG_PKGRMCHK_CKRUNLVL;
/*
* outer loop - process each package first
*/
for (i = 0; (pkginst = a_pkglist[i]) != NULL; i++) {
char *zoneName;
int zoneIndex;
/*
* inner loop - for each package process each zone second
*/
if (pkgIsPkgInGzOnly(get_inst_root(), pkginst) == B_TRUE) {
continue;
}
for (zoneIndex = 0;
(zoneName = z_zlist_get_zonename(a_zlst, zoneIndex)) !=
(char *)NULL; zoneIndex++) {
FILE *fp;
char line[PATH_MAX+1];
char preremovecheckPath[PATH_MAX+1];
int len;
/* skip the zone if it is NOT bootable */
if (z_zlist_is_zone_runnable(a_zlst,
zoneIndex) == B_FALSE) {
continue;
}
/* create path to this packages preremove check data */
len = snprintf(preremovecheckPath,
sizeof (preremovecheckPath),
"%s/%s.%s.preremovecheck.txt",
a_zoneTempDir, pkginst,
z_zlist_get_scratch(a_zlst, zoneIndex));
if (len > sizeof (preremovecheckPath)) {
progerr(ERR_CREATE_PATH_3, a_zoneTempDir,
pkginst, zoneName);
continue;
}
/* error if preremove check data path is not a file */
if (isfile((char *)NULL, preremovecheckPath) != 0) {
echoDebug(DBG_PRERVFY_NOFILE, pkginst, zoneName,
preremovecheckPath, strerror(errno));
progerr(ERR_PRERVFY_NOFILE, pkginst, zoneName);
continue;
}
/* open the preremove check data file */
fp = fopen(preremovecheckPath, "r");
if (fp == (FILE *)NULL) {
progerr(ERR_PRERVFY_OPEN_FILE,
preremovecheckPath, pkginst, zoneName,
strerror(errno));
continue;
}
/* read and process each preremove check data line */
while (fgets(line, sizeof (line), fp) != (char *)NULL) {
int len;
int j;
/* remove all new-lines from end of line */
len = strlen(line);
while ((len > 0) && (line[len-1] == '\n')) {
line[--len] = '\0';
}
/* ignore comment lines */
if (line[0] == '#') {
continue;
}
/* ignore empty lines */
if (line[0] == '\0') {
continue;
}
/* scan dependency list for this item */
for (j = 0;
DEPCKL[j].name != (char *)NULL; j++) {
len = strlen(DEPCKL[j].name);
if (strncmp(line, DEPCKL[j].name,
len) == 0) {
break;
}
}
echoDebug(DBG_PRERVFY_SCAN, line, pkginst,
zoneName);
/* ignore line if not found */
if (DEPCKL[j].name == (char *)NULL) {
progerr(ERR_PRERVFY_UNKNOWN_LINE, line,
pkginst, zoneName);
continue;
}
if ((DEPCKL[j].ignore_values != (char *)NULL) &&
(*(DEPCKL[j].ignore_values) != '\0') &&
(strchr(DEPCKL[j].ignore_values,
line[len]) != (char *)NULL)) {
continue;
}
/* found match - record this dependency issue */
depchkRecordError(DEPCKL[j].record, pkginst,
zoneName, &line[len]);
}
/* close preremove check data file */
(void) fclose(fp);
}
}
/*
* all dependency issues have been recorded; report results
*/
i = depchkReportErrors(DEPCKL);
/* restore "npkgs" */
npkgs = savenpkgs;
/* return continue/dont dontinue results */
return (i);
}
/*
* Name: getyorn
* Description: Deliver dependency check reason; ask question; return response
* Arguments: a_msg - pointer to string representing the message to output
* such as 'The package <..> contains <...>'
* a_pkg - pointer to string representing the package for which
* the question is being asked
* a_nocheck - should the message be output?
* == 0 - do not output the message
* != 0 - output the message
* a_quit - should the question NOT be asked?
* == 0 - ask the question
* != 0 - do not ask the question - return "no"
* a_helpMsg - pointer to string representing help message to be
* made available if the question is asked
* == NULL - no help message is available
* a_adminMsg - pointer to string representing the dependency check
* failure 'reason' - such as "Privilege checking failed."
* == NULL - no failure reason is available
* Returns: int - results of question/response actions
* 0 - success
* 1 - end of file
* 2 - undefined error
* 3 - answer was not "y"/was "q"
* 4 - quit action taken
* 5 - interactive mode required
*/
static int
getyorn(char *a_msg, char *a_pkg, int a_nocheck, int a_quit,
char *a_helpMsg, char *a_adminMsg)
{
char ans[MAX_INPUT];
char ask_cont[MSG_MAX];
int n;
int saveCkquit;
/*
* entry assertions
*/
assert(a_pkg != (char *)NULL);
assert(*a_pkg != '\0');
/*
* entry debugging info
*/
echoDebug(DBG_PRERVFY_GETYORN_ARGS, a_pkg, a_nocheck, a_quit, a_msg,
a_adminMsg ? a_adminMsg : "");
/* return success (0) if "nocheck" is non-zero */
if (a_nocheck != 0) {
echoDebug(DBG_PRERVFY_GETYORN_NOCHECK, a_pkg);
return (0);
}
/* output reason for this particular failure */
if ((a_msg != (char *)NULL) && (*a_msg != '\0')) {
ptext(stderr, "%s", a_msg);
}
/* return "4 (administration)" if "quit" is non-zero */
if (a_quit != 0) {
/* output failure "admin reason" if available */
if ((a_adminMsg != (char *)NULL) && (*a_adminMsg != '\0')) {
ptext(stderr, a_adminMsg);
}
echoDebug(DBG_PRERVFY_GETYORN_QUIT, a_pkg);
return (4);
}
/* return "5 (administration interaction required)" if -n */
if (echoGetFlag() == B_FALSE) {
ptext(stderr, MSG_PRERVFY_GETYORN_SUSP, a_pkg);
echoDebug(DBG_PRERVFY_GETYORN_QUIT_USER, a_pkg);
return (5);
}
/* prepare question to ask "continue with removal of pkg <xxx>?" */
(void) snprintf(ask_cont, sizeof (ask_cont), gettext(ASK_PKGRMCHK_CONT),
a_pkg);
/* ask question */
saveCkquit = ckquit;
ckquit = 0;
n = ckyorn(ans, NULL, NULL, a_helpMsg, ask_cont);
ckquit = saveCkquit;
if (n != 0) {
ptext(stderr, MSG_PRERVFY_GETYORN_TERM, a_pkg);
echoDebug(DBG_PRERVFY_GETYORN_CKYORN, a_pkg, n);
return (n);
}
/* return "3 (interruption) if not "y" or "Y" */
if (strchr("yY", *ans) == NULL) {
ptext(stderr, MSG_PRERVFY_GETYORN_TERM_USER, a_pkg);
echoDebug(DBG_PRERVFY_GETYORN_NOT_Y, a_pkg, ans);
return (3);
}
/* return "0 - success" */
echoDebug(DBG_PRERVFY_GETYORN_SUCCESS, a_pkg);
return (0);
}
/*
* Trigger: dependsonme=<<package>>
* Sequence: - one or more: dependsonme=<<package>>
* - one: rckdepend=<<n>>
* Actions: Output message if "rdepend!=nocheck"
* Return 0
* Terminate when 'rckdepend' processed
*/
static int
rckdepsonme(char *a_msg, char *a_pkg)
{
echoDebug(DBG_PRERVFY_RCKDEPSONME, a_pkg, a_msg);
if (!(ADM(rdepend, "nocheck"))) {
ptext(stderr, "%s", a_msg);
}
return (0);
}
/*
* Trigger: prerequisite-incomplete=<<package>>
* Sequence: - one or more: prerequisite-incomplete=<<package>>
* - one: rckdepend=<<n>>
* Actions: Output message if "rdepend!=nocheck"
* Return 0
* Terminate when 'rckdepend' processed
*/
static int
rckprenci(char *a_msg, char *a_pkg)
{
echoDebug(DBG_PRERVFY_RCKPRENCI, a_pkg, a_msg);
if (!(ADM(rdepend, "nocheck"))) {
ptext(stderr, "%s", a_msg);
}
return (0);
}
/*
* Trigger: prerequisite-installed=<<package>>
* Sequence: - one or more: prerequisite-installed=<<package>>
* - one: rckdepend=<<n>>
* Actions: Output message if "rdepend!=nocheck"
* Return 0
* Terminate when 'rckdepend' processed
*/
static int
rckprereq(char *a_msg, char *a_pkg)
{
echoDebug(DBG_PRERVFY_RCKPREREQ, a_pkg, a_msg);
if (!(ADM(rdepend, "nocheck"))) {
ptext(stderr, "%s", a_msg);
}
return (0);
}
/*
* Return value: int
* 0 - success
* 1 - end of file
* 2 - undefined error
* 3 - answer was not "y"/was "q"
* 4 - quit action taken
* 5 - interactive mode required
* 99 - fatal error
*/
static int
rckrunlevel(char *a_msg, char *a_pkg)
{
echoDebug(DBG_PRERVFY_RCKRUNLEVEL, a_pkg, a_msg);
/*
* For now, we are ignoring runlevel removal issues within
* non-global zones. This is questionable, but the RSTATES
* feature is rarely used and known uses within Solaris are
* effectively no-ops as of this time
*/
return (0);
}
/*
* Trigger: rckdepend=<<n>>
* Sequence: - one or more of:
* -- incompat=<<package>>
* -- prerequisite-incomplete=<<package>>
* -- prerequisite-installed=<<package>>
* -- dependson=<<package>>
* -- dependsonme=<<package>>
* - one: ckpdepend=<<n>>
* Actions: process according to settings
* Return value: int
* 0 - success
* 1 - end of file
* 2 - undefined error
* 3 - answer was not "y"/was "q"
* 4 - quit action taken
* 5 - interactive mode required
*/
static int
rckdepend(char *a_msg, char *a_pkg)
{
echoDebug(DBG_PRERVFY_RCKDEPEND, a_pkg, a_msg);
return (getyorn(a_msg, a_pkg, ADM(rdepend, "nocheck"),
ADM(rdepend, "quit"), HLP_PKGRMCHK_DEPEND,
ERR_PKGRMCHK_DEPFAILED));
}
/*
* Trigger: rckpriv=<<n>>
* Sequence: - one: rckpriv=<<n>>
* Actions: process according to settings
* Return value: int
* 0 - success
* 1 - end of file
* 2 - undefined error
* 3 - answer was not "y"/was "q"
* 4 - quit action taken
* 5 - interactive mode required
*/
static int
rckpriv(char *a_msg, char *a_pkg)
{
echoDebug(DBG_PRERVFY_RCKPRIV, a_pkg, a_msg);
return (getyorn(a_msg, a_pkg, ADM(action, "nocheck"),
ADM(action, "quit"), HLP_PKGRMCHK_PRIV,
ERR_PKGRMCHK_PRIVFAILED));
}
|