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 2007 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
28*9781SMoriah.Waterland@Sun.COM /*
29*9781SMoriah.Waterland@Sun.COM * System includes
30*9781SMoriah.Waterland@Sun.COM */
31*9781SMoriah.Waterland@Sun.COM
32*9781SMoriah.Waterland@Sun.COM #include <stdio.h>
33*9781SMoriah.Waterland@Sun.COM #include <time.h>
34*9781SMoriah.Waterland@Sun.COM #include <wait.h>
35*9781SMoriah.Waterland@Sun.COM #include <stdlib.h>
36*9781SMoriah.Waterland@Sun.COM #include <unistd.h>
37*9781SMoriah.Waterland@Sun.COM #include <ulimit.h>
38*9781SMoriah.Waterland@Sun.COM #include <sys/stat.h>
39*9781SMoriah.Waterland@Sun.COM #include <sys/statvfs.h>
40*9781SMoriah.Waterland@Sun.COM #include <assert.h>
41*9781SMoriah.Waterland@Sun.COM #include <fcntl.h>
42*9781SMoriah.Waterland@Sun.COM #include <errno.h>
43*9781SMoriah.Waterland@Sun.COM #include <ctype.h>
44*9781SMoriah.Waterland@Sun.COM #include <dirent.h>
45*9781SMoriah.Waterland@Sun.COM #include <string.h>
46*9781SMoriah.Waterland@Sun.COM #include <signal.h>
47*9781SMoriah.Waterland@Sun.COM #include <locale.h>
48*9781SMoriah.Waterland@Sun.COM #include <libintl.h>
49*9781SMoriah.Waterland@Sun.COM #include <pkgstrct.h>
50*9781SMoriah.Waterland@Sun.COM #include <pkginfo.h>
51*9781SMoriah.Waterland@Sun.COM #include <pkgdev.h>
52*9781SMoriah.Waterland@Sun.COM #include <pkglocs.h>
53*9781SMoriah.Waterland@Sun.COM #include <pwd.h>
54*9781SMoriah.Waterland@Sun.COM
55*9781SMoriah.Waterland@Sun.COM
56*9781SMoriah.Waterland@Sun.COM /*
57*9781SMoriah.Waterland@Sun.COM * consolidation pkg command library includes
58*9781SMoriah.Waterland@Sun.COM */
59*9781SMoriah.Waterland@Sun.COM
60*9781SMoriah.Waterland@Sun.COM #include <pkglib.h>
61*9781SMoriah.Waterland@Sun.COM
62*9781SMoriah.Waterland@Sun.COM /*
63*9781SMoriah.Waterland@Sun.COM * local pkg command library includes
64*9781SMoriah.Waterland@Sun.COM */
65*9781SMoriah.Waterland@Sun.COM
66*9781SMoriah.Waterland@Sun.COM #include "libinst.h"
67*9781SMoriah.Waterland@Sun.COM #include "libadm.h"
68*9781SMoriah.Waterland@Sun.COM #include "messages.h"
69*9781SMoriah.Waterland@Sun.COM
70*9781SMoriah.Waterland@Sun.COM /*
71*9781SMoriah.Waterland@Sun.COM * Name: unpack_package_from_stream
72*9781SMoriah.Waterland@Sun.COM * Description: unpack a package from a stream into a temporary directory
73*9781SMoriah.Waterland@Sun.COM * Arguments: a_idsName - pointer to string representing the input data
74*9781SMoriah.Waterland@Sun.COM * stream containing the package to unpack
75*9781SMoriah.Waterland@Sun.COM * a_pkginst - pointer to string representing the name of
76*9781SMoriah.Waterland@Sun.COM * the package to unpack from the specified stream
77*9781SMoriah.Waterland@Sun.COM * a_tempDir - pointer to string representing the path to a
78*9781SMoriah.Waterland@Sun.COM * directory into which the package will be unpacked
79*9781SMoriah.Waterland@Sun.COM * Returns: boolean_t
80*9781SMoriah.Waterland@Sun.COM * == B_TRUE - package successfully unpacked from stream
81*9781SMoriah.Waterland@Sun.COM * == B_FALSE - failed to unpack package from stream
82*9781SMoriah.Waterland@Sun.COM */
83*9781SMoriah.Waterland@Sun.COM
84*9781SMoriah.Waterland@Sun.COM boolean_t
unpack_package_from_stream(char * a_idsName,char * a_pkginst,char * a_tempDir)85*9781SMoriah.Waterland@Sun.COM unpack_package_from_stream(char *a_idsName, char *a_pkginst, char *a_tempDir)
86*9781SMoriah.Waterland@Sun.COM {
87*9781SMoriah.Waterland@Sun.COM int dparts;
88*9781SMoriah.Waterland@Sun.COM char instdir[PATH_MAX];
89*9781SMoriah.Waterland@Sun.COM
90*9781SMoriah.Waterland@Sun.COM /* entry assertions */
91*9781SMoriah.Waterland@Sun.COM
92*9781SMoriah.Waterland@Sun.COM assert(a_idsName != (char *)NULL);
93*9781SMoriah.Waterland@Sun.COM assert(a_pkginst != (char *)NULL);
94*9781SMoriah.Waterland@Sun.COM assert(a_tempDir != (char *)NULL);
95*9781SMoriah.Waterland@Sun.COM
96*9781SMoriah.Waterland@Sun.COM /* entry debug information */
97*9781SMoriah.Waterland@Sun.COM
98*9781SMoriah.Waterland@Sun.COM echoDebug(DBG_UNPACKSTRM_ENTRY);
99*9781SMoriah.Waterland@Sun.COM echoDebug(DBG_UNPACKSTRM_ARGS, a_pkginst, a_idsName, a_tempDir);
100*9781SMoriah.Waterland@Sun.COM
101*9781SMoriah.Waterland@Sun.COM /* find the specified package in the datastream */
102*9781SMoriah.Waterland@Sun.COM
103*9781SMoriah.Waterland@Sun.COM dparts = ds_findpkg(a_idsName, a_pkginst);
104*9781SMoriah.Waterland@Sun.COM if (dparts < 1) {
105*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_DSARCH), a_pkginst);
106*9781SMoriah.Waterland@Sun.COM return (B_FALSE);
107*9781SMoriah.Waterland@Sun.COM /*NOTREACHED*/
108*9781SMoriah.Waterland@Sun.COM }
109*9781SMoriah.Waterland@Sun.COM
110*9781SMoriah.Waterland@Sun.COM /*
111*9781SMoriah.Waterland@Sun.COM * read in next part from stream, even if we decide
112*9781SMoriah.Waterland@Sun.COM * later that we don't need it
113*9781SMoriah.Waterland@Sun.COM */
114*9781SMoriah.Waterland@Sun.COM
115*9781SMoriah.Waterland@Sun.COM /* create directory to hold this package instance */
116*9781SMoriah.Waterland@Sun.COM
117*9781SMoriah.Waterland@Sun.COM if (snprintf(instdir, sizeof (instdir), "%s/%s", a_tempDir, a_pkginst)
118*9781SMoriah.Waterland@Sun.COM >= PATH_MAX) {
119*9781SMoriah.Waterland@Sun.COM progerr(ERR_CREATE_PATH_2, a_tempDir, a_pkginst);
120*9781SMoriah.Waterland@Sun.COM return (B_FALSE);
121*9781SMoriah.Waterland@Sun.COM }
122*9781SMoriah.Waterland@Sun.COM
123*9781SMoriah.Waterland@Sun.COM switch (fmkdir(instdir, 0755)) {
124*9781SMoriah.Waterland@Sun.COM case 0: /* directory created */
125*9781SMoriah.Waterland@Sun.COM break;
126*9781SMoriah.Waterland@Sun.COM case 1: /* could not remove existing non-directory node */
127*9781SMoriah.Waterland@Sun.COM progerr(ERR_REMOVE, instdir, strerror(errno));
128*9781SMoriah.Waterland@Sun.COM return (B_FALSE);
129*9781SMoriah.Waterland@Sun.COM case 2: /* could not create specified new directory */
130*9781SMoriah.Waterland@Sun.COM default:
131*9781SMoriah.Waterland@Sun.COM progerr(ERR_UNPACK_FMKDIR, instdir, strerror(errno));
132*9781SMoriah.Waterland@Sun.COM return (B_FALSE);
133*9781SMoriah.Waterland@Sun.COM }
134*9781SMoriah.Waterland@Sun.COM
135*9781SMoriah.Waterland@Sun.COM /* unpack package instance from stream to dir created */
136*9781SMoriah.Waterland@Sun.COM
137*9781SMoriah.Waterland@Sun.COM echoDebug(DBG_UNPACKSTRM_UNPACKING, a_pkginst, a_idsName, instdir);
138*9781SMoriah.Waterland@Sun.COM
139*9781SMoriah.Waterland@Sun.COM if (chdir(instdir)) {
140*9781SMoriah.Waterland@Sun.COM progerr(ERR_CHDIR, instdir);
141*9781SMoriah.Waterland@Sun.COM return (B_FALSE);
142*9781SMoriah.Waterland@Sun.COM }
143*9781SMoriah.Waterland@Sun.COM
144*9781SMoriah.Waterland@Sun.COM while (dparts--) {
145*9781SMoriah.Waterland@Sun.COM if (ds_next(a_idsName, instdir)) {
146*9781SMoriah.Waterland@Sun.COM progerr(ERR_UNPACK_DSREAD, dparts+1, a_idsName, instdir,
147*9781SMoriah.Waterland@Sun.COM a_pkginst);
148*9781SMoriah.Waterland@Sun.COM return (B_FALSE);
149*9781SMoriah.Waterland@Sun.COM }
150*9781SMoriah.Waterland@Sun.COM }
151*9781SMoriah.Waterland@Sun.COM
152*9781SMoriah.Waterland@Sun.COM if (chdir(get_PKGADM())) {
153*9781SMoriah.Waterland@Sun.COM progerr(gettext(ERR_CHDIR), get_PKGADM());
154*9781SMoriah.Waterland@Sun.COM return (B_FALSE);
155*9781SMoriah.Waterland@Sun.COM }
156*9781SMoriah.Waterland@Sun.COM
157*9781SMoriah.Waterland@Sun.COM return (B_TRUE);
158*9781SMoriah.Waterland@Sun.COM }
159