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 2003 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 #include <stdio.h> 32 #include <stdlib.h> 33 #include <unistd.h> 34 #include <string.h> 35 #include <utmpx.h> 36 #include <dirent.h> 37 #include <sys/types.h> 38 #include <pkgstrct.h> 39 #include <locale.h> 40 #include <libintl.h> 41 #include "install.h" 42 #include <pkglib.h> 43 #include "libadm.h" 44 #include "libinst.h" 45 #include "messages.h" 46 47 extern struct admin adm; 48 49 extern char pkgloc[], *pkginst, *msgtext; 50 51 static boolean_t preremoveCheck = B_FALSE; 52 static char *zoneName = (char *)NULL; 53 54 55 void 56 rcksetPreremoveCheck(boolean_t a_preremoveCheck) 57 { 58 preremoveCheck = a_preremoveCheck; 59 } 60 61 void 62 rcksetZoneName(char *a_zoneName) 63 { 64 zoneName = a_zoneName; 65 } 66 67 int 68 rckrunlevel(void) 69 { 70 struct utmpx utmpx; 71 struct utmpx *putmpx; 72 char ans[MAX_INPUT]; 73 char *pt; 74 char *rstates; 75 int n; 76 char *uxstate; 77 78 if (ADM(runlevel, "nocheck")) { 79 return (0); 80 } 81 82 pt = getenv("RSTATES"); 83 if (pt == NULL) { 84 return (0); 85 } 86 87 utmpx.ut_type = RUN_LVL; 88 putmpx = getutxid(&utmpx); 89 if (putmpx == NULL) { 90 progerr(ERR_RUNSTATE); 91 return (99); 92 } 93 uxstate = strtok(&putmpx->ut_line[10], " \t\n"); 94 95 rstates = qstrdup(pt); 96 if ((pt = strtok(pt, " \t\n, ")) == NULL) 97 return (0); /* no list is no list */ 98 do { 99 if (strcmp(pt, uxstate) == NULL) { 100 free(rstates); 101 return (0); 102 } 103 } while (pt = strtok(NULL, " \t\n, ")); 104 105 if (preremoveCheck == B_FALSE) { 106 msgtext = MSG_PKGREMOVE_RUNLEVEL; 107 ptext(stderr, msgtext, uxstate); 108 } else { 109 (void) fprintf(stdout, "runlevel=%s", uxstate); 110 } 111 112 pt = strtok(rstates, " \t\n, "); 113 do { 114 if (preremoveCheck == B_FALSE) { 115 ptext(stderr, "\\t%s", pt); 116 } else { 117 (void) fprintf(stdout, ":%s", pt); 118 } 119 } while (pt = strtok(NULL, " \t\n, ")); 120 121 if (preremoveCheck == B_TRUE) { 122 (void) fprintf(stdout, "\n"); 123 } 124 125 free(rstates); 126 127 if (ADM(runlevel, "quit")) { 128 return (4); 129 } 130 131 if (echoGetFlag() == B_FALSE) { 132 return (5); 133 } 134 135 msgtext = NULL; 136 137 n = ckyorn(ans, NULL, NULL, HLP_PKGREMOVE_RUNLEVEL, 138 ASK_PKGREMOVE_CONTINUE); 139 140 if (n != 0) { 141 return (n); 142 } 143 144 if (strchr("yY", *ans) == NULL) { 145 return (3); 146 } 147 148 return (0); 149 } 150 151 int 152 rckdepend(void) 153 { 154 int n; 155 char ans[MAX_INPUT]; 156 char **id, **name; 157 158 if (ADM(rdepend, "nocheck")) { 159 return (0); 160 } 161 162 if (zoneName == (char *)NULL) { 163 echo(MSG_CHECKREMOVE_PKG_IN_GZ, pkginst); 164 } else { 165 echo(MSG_CHECKREMOVE_PKG_IN_ZONE, pkginst, zoneName); 166 } 167 168 if (dockdeps(pkginst, 1, preremoveCheck)) { 169 msgtext = MSG_PKGREMOVE_DEPEND; 170 171 if (preremoveCheck == B_FALSE) { 172 echo(msgtext); 173 } 174 175 if (ADM(rdepend, "quit")) { 176 return (4); 177 } 178 179 if (echoGetFlag() == B_FALSE) { 180 return (5); 181 } 182 183 msgtext = NULL; 184 185 n = ckyorn(ans, NULL, NULL, HLP_PKGREMOVE_DEPEND, 186 ASK_PKGREMOVE_CONTINUE); 187 188 if (n != 0) { 189 return (n); 190 } 191 192 if (strchr("yY", *ans) == NULL) { 193 return (3); 194 } 195 } 196 197 return (0); 198 } 199 200 int 201 rckpriv(void) 202 { 203 struct dirent *dp; 204 DIR *dirfp; 205 int n; 206 char found; 207 char ans[MAX_INPUT]; 208 char path[PATH_MAX]; 209 210 if (ADM(action, "nocheck")) { 211 return (0); 212 } 213 214 (void) snprintf(path, sizeof (path), "%s/install", pkgloc); 215 if ((dirfp = opendir(path)) == NULL) 216 return (0); 217 218 found = 0; 219 while ((dp = readdir(dirfp)) != NULL) { 220 if ((strcmp(dp->d_name, "preremove") == NULL) || 221 (strcmp(dp->d_name, "postremove") == NULL) || 222 (strncmp(dp->d_name, "r.", 2) == NULL)) { 223 found++; 224 break; 225 } 226 } 227 (void) closedir(dirfp); 228 229 if (found) { 230 if (preremoveCheck == B_FALSE) { 231 ptext(stderr, MSG_PKGREMOVE_PRIV); 232 } 233 msgtext = MSG_PKGSCRIPTS_FOUND; 234 235 if (ADM(action, "quit")) { 236 return (4); 237 } 238 239 if (echoGetFlag() == B_FALSE) { 240 return (5); 241 } 242 243 msgtext = NULL; 244 245 n = ckyorn(ans, NULL, NULL, HLP_PKGREMOVE_PRIV, 246 ASK_PKGREMOVE_CONTINUE); 247 248 if (n != 0) { 249 return (n); 250 } 251 252 if (strchr("yY", *ans) == NULL) { 253 return (3); 254 } 255 } 256 257 return (0); 258 } 259