1*5c51f124SMoriah Waterland /* 2*5c51f124SMoriah Waterland * CDDL HEADER START 3*5c51f124SMoriah Waterland * 4*5c51f124SMoriah Waterland * The contents of this file are subject to the terms of the 5*5c51f124SMoriah Waterland * Common Development and Distribution License (the "License"). 6*5c51f124SMoriah Waterland * You may not use this file except in compliance with the License. 7*5c51f124SMoriah Waterland * 8*5c51f124SMoriah Waterland * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9*5c51f124SMoriah Waterland * or http://www.opensolaris.org/os/licensing. 10*5c51f124SMoriah Waterland * See the License for the specific language governing permissions 11*5c51f124SMoriah Waterland * and limitations under the License. 12*5c51f124SMoriah Waterland * 13*5c51f124SMoriah Waterland * When distributing Covered Code, include this CDDL HEADER in each 14*5c51f124SMoriah Waterland * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15*5c51f124SMoriah Waterland * If applicable, add the following below this CDDL HEADER, with the 16*5c51f124SMoriah Waterland * fields enclosed by brackets "[]" replaced with your own identifying 17*5c51f124SMoriah Waterland * information: Portions Copyright [yyyy] [name of copyright owner] 18*5c51f124SMoriah Waterland * 19*5c51f124SMoriah Waterland * CDDL HEADER END 20*5c51f124SMoriah Waterland */ 21*5c51f124SMoriah Waterland 22*5c51f124SMoriah Waterland /* 23*5c51f124SMoriah Waterland * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 24*5c51f124SMoriah Waterland * Use is subject to license terms. 25*5c51f124SMoriah Waterland */ 26*5c51f124SMoriah Waterland 27*5c51f124SMoriah Waterland /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 28*5c51f124SMoriah Waterland /* All Rights Reserved */ 29*5c51f124SMoriah Waterland 30*5c51f124SMoriah Waterland #ifndef _PKGLIB_H 31*5c51f124SMoriah Waterland #define _PKGLIB_H 32*5c51f124SMoriah Waterland 33*5c51f124SMoriah Waterland 34*5c51f124SMoriah Waterland #ifdef __cplusplus 35*5c51f124SMoriah Waterland extern "C" { 36*5c51f124SMoriah Waterland #endif 37*5c51f124SMoriah Waterland 38*5c51f124SMoriah Waterland #include <sys/types.h> 39*5c51f124SMoriah Waterland #include <limits.h> 40*5c51f124SMoriah Waterland #include <stdio.h> 41*5c51f124SMoriah Waterland #include <pkgdev.h> 42*5c51f124SMoriah Waterland #include <pkgstrct.h> 43*5c51f124SMoriah Waterland #include <openssl/bio.h> 44*5c51f124SMoriah Waterland #include <openssl/x509.h> 45*5c51f124SMoriah Waterland #include <netdb.h> 46*5c51f124SMoriah Waterland #include <boot_http.h> 47*5c51f124SMoriah Waterland #include "pkgerr.h" 48*5c51f124SMoriah Waterland #include "keystore.h" 49*5c51f124SMoriah Waterland #include "cfext.h" 50*5c51f124SMoriah Waterland 51*5c51f124SMoriah Waterland /* 52*5c51f124SMoriah Waterland * Virtual File Protocol definitions 53*5c51f124SMoriah Waterland */ 54*5c51f124SMoriah Waterland 55*5c51f124SMoriah Waterland /* 56*5c51f124SMoriah Waterland * flags associated with virtual file protocol operations; note that these flags 57*5c51f124SMoriah Waterland * may only occupy the low order 16 bits of the 32-bit unsigned flag. 58*5c51f124SMoriah Waterland */ 59*5c51f124SMoriah Waterland 60*5c51f124SMoriah Waterland typedef unsigned long VFPFLAGS_T; 61*5c51f124SMoriah Waterland 62*5c51f124SMoriah Waterland #define VFP_NONE 0x00000000 /* no special flags */ 63*5c51f124SMoriah Waterland #define VFP_NEEDNOW 0x00000001 /* need memory now */ 64*5c51f124SMoriah Waterland #define VFP_SEQUENTIAL 0x00000002 /* sequential access */ 65*5c51f124SMoriah Waterland #define VFP_RANDOM 0x00000004 /* random access */ 66*5c51f124SMoriah Waterland #define VFP_NOMMAP 0x00000008 /* do not use mmap to access file */ 67*5c51f124SMoriah Waterland #define VFP_NOMALLOC 0x00000010 /* do not use malloc to buffer file */ 68*5c51f124SMoriah Waterland 69*5c51f124SMoriah Waterland /* virtual file protocol object */ 70*5c51f124SMoriah Waterland 71*5c51f124SMoriah Waterland typedef struct _vfp VFP_T; 72*5c51f124SMoriah Waterland 73*5c51f124SMoriah Waterland /* structure behind the virtual file protocol object */ 74*5c51f124SMoriah Waterland 75*5c51f124SMoriah Waterland struct _vfp { 76*5c51f124SMoriah Waterland FILE *_vfpFile; /* -> opened FILE */ 77*5c51f124SMoriah Waterland char *_vfpCurr; /* -> current byte to read/write */ 78*5c51f124SMoriah Waterland char *_vfpHighWater; /* -> last byte modified */ 79*5c51f124SMoriah Waterland char *_vfpEnd; /* -> last data byte */ 80*5c51f124SMoriah Waterland char *_vfpPath; /* -> path associated with FILE */ 81*5c51f124SMoriah Waterland char *_vfpStart; /* -> first data byte */ 82*5c51f124SMoriah Waterland void *_vfpExtra; /* undefined */ 83*5c51f124SMoriah Waterland size_t _vfpSize; /* size of mapped/allocated area */ 84*5c51f124SMoriah Waterland size_t _vfpMapSize; /* # mapped bytes */ 85*5c51f124SMoriah Waterland VFPFLAGS_T _vfpFlags; /* flags associated with vfp/data */ 86*5c51f124SMoriah Waterland int _vfpOverflow; /* non-zero if buffer write overflow */ 87*5c51f124SMoriah Waterland blkcnt_t _vfpCkStBlocks; /* checkpoint # blocks */ 88*5c51f124SMoriah Waterland dev_t _vfpCkDev; /* checkpoint device i.d. */ 89*5c51f124SMoriah Waterland ino_t _vfpCkIno; /* checkpoint inode # */ 90*5c51f124SMoriah Waterland off_t _vfpCkSize; /* checkpoint size */ 91*5c51f124SMoriah Waterland time_t _vfpCkMtime; /* checkpoint modification time */ 92*5c51f124SMoriah Waterland }; 93*5c51f124SMoriah Waterland 94*5c51f124SMoriah Waterland /* 95*5c51f124SMoriah Waterland * get highest modified byte (length) contained in vfp 96*5c51f124SMoriah Waterland * 97*5c51f124SMoriah Waterland * determine number of bytes to write - it will be the highest of: 98*5c51f124SMoriah Waterland * -- the current pointer into the file - this is updated whenever 99*5c51f124SMoriah Waterland * the location of the file is changed by a single byte 100*5c51f124SMoriah Waterland * -- the last "high water mark" - the last known location that 101*5c51f124SMoriah Waterland * was written to the file - updated only when the location 102*5c51f124SMoriah Waterland * of the file is directly changed - e.g. vfpSetCurrCharPtr, 103*5c51f124SMoriah Waterland * vfpTruncate, vfpRewind. 104*5c51f124SMoriah Waterland * this reduces the "bookkeeping" that needs to be done to know 105*5c51f124SMoriah Waterland * how many bytes to write out to the file - typically a file is 106*5c51f124SMoriah Waterland * written sequentially so the current file pointer is sufficient 107*5c51f124SMoriah Waterland * to determine how many bytes to write out. 108*5c51f124SMoriah Waterland */ 109*5c51f124SMoriah Waterland 110*5c51f124SMoriah Waterland #define vfpGetModifiedLen(VFP) \ 111*5c51f124SMoriah Waterland (size_t)(((VFP)->_vfpHighWater > (VFP)->_vfpCurr) ? \ 112*5c51f124SMoriah Waterland (((ptrdiff_t)(VFP)->_vfpHighWater - \ 113*5c51f124SMoriah Waterland (ptrdiff_t)(VFP)->_vfpStart)) : \ 114*5c51f124SMoriah Waterland (((ptrdiff_t)(VFP)->_vfpCurr - \ 115*5c51f124SMoriah Waterland (ptrdiff_t)(VFP)->_vfpStart))) 116*5c51f124SMoriah Waterland 117*5c51f124SMoriah Waterland /* 118*5c51f124SMoriah Waterland * increment current pointer by specified delta 119*5c51f124SMoriah Waterland * if the delta exceeds the buffer size, set pointer to buffer end 120*5c51f124SMoriah Waterland */ 121*5c51f124SMoriah Waterland #define vfpIncCurrPtrBy(VFP, INC) \ 122*5c51f124SMoriah Waterland { \ 123*5c51f124SMoriah Waterland ((VFP)->_vfpCurr) += (INC); \ 124*5c51f124SMoriah Waterland if (((VFP)->_vfpCurr) > ((VFP)->_vfpEnd)) { \ 125*5c51f124SMoriah Waterland (VFP)->_vfpCurr = (VFP)->_vfpEnd; \ 126*5c51f124SMoriah Waterland (VFP)->_vfpOverflow = 1; \ 127*5c51f124SMoriah Waterland } \ 128*5c51f124SMoriah Waterland if ((VFP)->_vfpHighWater < (VFP)->_vfpCurr) { \ 129*5c51f124SMoriah Waterland (VFP)->_vfpHighWater = (VFP)->_vfpCurr; \ 130*5c51f124SMoriah Waterland } \ 131*5c51f124SMoriah Waterland } 132*5c51f124SMoriah Waterland 133*5c51f124SMoriah Waterland /* get the path associated with the vfp */ 134*5c51f124SMoriah Waterland #define vfpGetPath(VFP) ((VFP)->_vfpPath) 135*5c51f124SMoriah Waterland 136*5c51f124SMoriah Waterland /* get a string from the vfp into a fixed size buffer */ 137*5c51f124SMoriah Waterland #define vfpGets(VFP, PTR, LEN) \ 138*5c51f124SMoriah Waterland { \ 139*5c51f124SMoriah Waterland char *XXpXX = (PTR); \ 140*5c51f124SMoriah Waterland size_t XXlXX = (LEN); \ 141*5c51f124SMoriah Waterland while ((*(VFP)->_vfpCurr != '\0') && \ 142*5c51f124SMoriah Waterland (*(VFP)->_vfpCurr != '\n')) { \ 143*5c51f124SMoriah Waterland if (XXlXX > 1) { \ 144*5c51f124SMoriah Waterland *XXpXX++ = *(VFP)->_vfpCurr; \ 145*5c51f124SMoriah Waterland XXlXX--; \ 146*5c51f124SMoriah Waterland } \ 147*5c51f124SMoriah Waterland (VFP)->_vfpCurr++; \ 148*5c51f124SMoriah Waterland } \ 149*5c51f124SMoriah Waterland *XXpXX++ = '\0'; \ 150*5c51f124SMoriah Waterland if (*(VFP)->_vfpCurr != '\0') { \ 151*5c51f124SMoriah Waterland (VFP)->_vfpCurr++; \ 152*5c51f124SMoriah Waterland } \ 153*5c51f124SMoriah Waterland } 154*5c51f124SMoriah Waterland 155*5c51f124SMoriah Waterland /* get number of bytes remaining to read */ 156*5c51f124SMoriah Waterland #define vfpGetBytesRemaining(VFP) \ 157*5c51f124SMoriah Waterland (((((VFP)->_vfpHighWater) <= ((VFP)->_vfpCurr))) ? 0 : \ 158*5c51f124SMoriah Waterland ((((ptrdiff_t)(VFP)->_vfpHighWater)-((ptrdiff_t)(VFP)->_vfpCurr)))) 159*5c51f124SMoriah Waterland 160*5c51f124SMoriah Waterland /* get number of bytes remaining to write */ 161*5c51f124SMoriah Waterland #define vfpGetBytesAvailable(VFP) \ 162*5c51f124SMoriah Waterland (((((VFP)->_vfpEnd) <= ((VFP)->_vfpCurr))) ? 0 : \ 163*5c51f124SMoriah Waterland ((((ptrdiff_t)(VFP)->_vfpEnd)-((ptrdiff_t)(VFP)->_vfpCurr)))) 164*5c51f124SMoriah Waterland 165*5c51f124SMoriah Waterland /* put current character and increment to next */ 166*5c51f124SMoriah Waterland #define vfpPutc(VFP, C) \ 167*5c51f124SMoriah Waterland { \ 168*5c51f124SMoriah Waterland (*(VFP)->_vfpCurr) = ((char)(C)); \ 169*5c51f124SMoriah Waterland vfpIncCurrPtrBy((VFP), 1); \ 170*5c51f124SMoriah Waterland } 171*5c51f124SMoriah Waterland 172*5c51f124SMoriah Waterland /* put integer to current character and increment */ 173*5c51f124SMoriah Waterland #define vfpPutInteger(VFP, NUMBER) vfpPutFormat((VFP), "%d", (NUMBER)) 174*5c51f124SMoriah Waterland 175*5c51f124SMoriah Waterland /* put long to current character and increment */ 176*5c51f124SMoriah Waterland #define vfpPutLong(VFP, NUMBER) vfpPutFormat((VFP), "%ld", (NUMBER)) 177*5c51f124SMoriah Waterland 178*5c51f124SMoriah Waterland /* get current character and increment to next */ 179*5c51f124SMoriah Waterland #define vfpGetc(VFP) (*(VFP)->_vfpCurr++) 180*5c51f124SMoriah Waterland 181*5c51f124SMoriah Waterland /* get current character - do not increment */ 182*5c51f124SMoriah Waterland #define vfpGetcNoInc(VFP) (*(VFP)->_vfpCurr) 183*5c51f124SMoriah Waterland 184*5c51f124SMoriah Waterland /* get pointer to current character */ 185*5c51f124SMoriah Waterland #define vfpGetCurrCharPtr(VFP) ((VFP)->_vfpCurr) 186*5c51f124SMoriah Waterland 187*5c51f124SMoriah Waterland /* increment current character pointer */ 188*5c51f124SMoriah Waterland #define vfpIncCurrPtr(VFP) vfpIncCurrPtrBy((VFP), 1) 189*5c51f124SMoriah Waterland 190*5c51f124SMoriah Waterland /* decrement current character pointer */ 191*5c51f124SMoriah Waterland #define vfpDecCurrPtr(VFP) ((VFP)->_vfpCurr--) 192*5c51f124SMoriah Waterland 193*5c51f124SMoriah Waterland /* get pointer to first data byte in buffer */ 194*5c51f124SMoriah Waterland #define vfpGetFirstCharPtr(VFP) ((VFP)->_vfpStart) 195*5c51f124SMoriah Waterland 196*5c51f124SMoriah Waterland /* get pointer to last data byte in buffer */ 197*5c51f124SMoriah Waterland #define vfpGetLastCharPtr(VFP) ((VFP)->_vfpHighWater) 198*5c51f124SMoriah Waterland 199*5c51f124SMoriah Waterland /* set pointer to current character */ 200*5c51f124SMoriah Waterland #define vfpSetCurrCharPtr(VFP, PTR) \ 201*5c51f124SMoriah Waterland if ((VFP)->_vfpCurr > (VFP)->_vfpHighWater) { \ 202*5c51f124SMoriah Waterland (VFP)->_vfpHighWater = (VFP)->_vfpCurr; \ 203*5c51f124SMoriah Waterland } \ 204*5c51f124SMoriah Waterland ((VFP)->_vfpCurr = (PTR)) 205*5c51f124SMoriah Waterland 206*5c51f124SMoriah Waterland /* set pointer to last data byte in buffer */ 207*5c51f124SMoriah Waterland #define vfpSetLastCharPtr(VFP, PTR) \ 208*5c51f124SMoriah Waterland if ((PTR) >= (VFP)->_vfpStart) { \ 209*5c51f124SMoriah Waterland (VFP)->_vfpHighWater = (PTR); \ 210*5c51f124SMoriah Waterland if ((VFP)->_vfpCurr > (VFP)->_vfpHighWater) { \ 211*5c51f124SMoriah Waterland (VFP)->_vfpCurr = (VFP)->_vfpHighWater; \ 212*5c51f124SMoriah Waterland } \ 213*5c51f124SMoriah Waterland } 214*5c51f124SMoriah Waterland 215*5c51f124SMoriah Waterland /* seek to end of file - one past last data byte in file */ 216*5c51f124SMoriah Waterland #define vfpSeekToEnd(VFP) ((VFP)->_vfpCurr = ((VFP)->_vfpHighWater)+1) 217*5c51f124SMoriah Waterland 218*5c51f124SMoriah Waterland /* get number of bytes between current char and specified char */ 219*5c51f124SMoriah Waterland #define vfpGetCurrPtrDelta(VFP, P) \ 220*5c51f124SMoriah Waterland (((ptrdiff_t)(P))-((ptrdiff_t)(VFP)->_vfpCurr)) 221*5c51f124SMoriah Waterland 222*5c51f124SMoriah Waterland /* put string to current character and increment */ 223*5c51f124SMoriah Waterland #define vfpPuts(VFP, S) \ 224*5c51f124SMoriah Waterland { \ 225*5c51f124SMoriah Waterland size_t xxLen; \ 226*5c51f124SMoriah Waterland size_t xxResult; \ 227*5c51f124SMoriah Waterland xxLen = vfpGetBytesAvailable((VFP)); \ 228*5c51f124SMoriah Waterland xxResult = strlcpy(((VFP)->_vfpCurr), (S), xxLen); \ 229*5c51f124SMoriah Waterland vfpIncCurrPtrBy((VFP), xxResult); \ 230*5c51f124SMoriah Waterland } 231*5c51f124SMoriah Waterland 232*5c51f124SMoriah Waterland /* put fixed number of bytes to current character and increment */ 233*5c51f124SMoriah Waterland #define vfpPutBytes(VFP, PTR, LEN) \ 234*5c51f124SMoriah Waterland { \ 235*5c51f124SMoriah Waterland size_t xxLen; \ 236*5c51f124SMoriah Waterland xxLen = vfpGetBytesAvailable((VFP)); \ 237*5c51f124SMoriah Waterland if (xxLen > (LEN)) { \ 238*5c51f124SMoriah Waterland xxLen = (LEN); \ 239*5c51f124SMoriah Waterland } else { \ 240*5c51f124SMoriah Waterland (VFP)->_vfpOverflow = 1; \ 241*5c51f124SMoriah Waterland } \ 242*5c51f124SMoriah Waterland memcpy((VFP)->_vfpCurr, (PTR), (xxLen)); \ 243*5c51f124SMoriah Waterland vfpIncCurrPtrBy((VFP), (xxLen)); \ 244*5c51f124SMoriah Waterland } 245*5c51f124SMoriah Waterland 246*5c51f124SMoriah Waterland /* put format one arg to current character and increment */ 247*5c51f124SMoriah Waterland #define vfpPutFormat(VFP, FORMAT, ARG) \ 248*5c51f124SMoriah Waterland { \ 249*5c51f124SMoriah Waterland char xxTeMpXX[256]; \ 250*5c51f124SMoriah Waterland (void) snprintf(xxTeMpXX, sizeof (xxTeMpXX), (FORMAT), (ARG)); \ 251*5c51f124SMoriah Waterland vfpPuts((VFP), xxTeMpXX); \ 252*5c51f124SMoriah Waterland } 253*5c51f124SMoriah Waterland 254*5c51f124SMoriah Waterland struct dm_buf { 255*5c51f124SMoriah Waterland char *text_buffer; /* start of allocated buffer */ 256*5c51f124SMoriah Waterland int offset; /* number of bytes into the text_buffer */ 257*5c51f124SMoriah Waterland int allocation; /* size of buffer in bytes */ 258*5c51f124SMoriah Waterland }; 259*5c51f124SMoriah Waterland 260*5c51f124SMoriah Waterland /* This structure is used to hold a dynamically growing string */ 261*5c51f124SMoriah Waterland 262*5c51f124SMoriah Waterland struct dstr { 263*5c51f124SMoriah Waterland char *pc; 264*5c51f124SMoriah Waterland int len; 265*5c51f124SMoriah Waterland int max; 266*5c51f124SMoriah Waterland }; 267*5c51f124SMoriah Waterland 268*5c51f124SMoriah Waterland /* setmapmode() defines */ 269*5c51f124SMoriah Waterland #define MAPALL 0 /* resolve all variables */ 270*5c51f124SMoriah Waterland #define MAPBUILD 1 /* map only build variables */ 271*5c51f124SMoriah Waterland #define MAPINSTALL 2 /* map only install variables */ 272*5c51f124SMoriah Waterland #define MAPNONE 3 /* map no variables */ 273*5c51f124SMoriah Waterland 274*5c51f124SMoriah Waterland #define NON_ABI_NAMELNGTH 33 /* 32 chars for name + 1 for NULL */ 275*5c51f124SMoriah Waterland 276*5c51f124SMoriah Waterland #define BLK_SIZE 512 /* size of logical block */ 277*5c51f124SMoriah Waterland 278*5c51f124SMoriah Waterland /* max length for printed attributes */ 279*5c51f124SMoriah Waterland #define ATTR_MAX 80 280*5c51f124SMoriah Waterland 281*5c51f124SMoriah Waterland /* 282*5c51f124SMoriah Waterland * These three defines indicate that the prototype file contains a '?' 283*5c51f124SMoriah Waterland * meaning do not specify this data in the pkgmap entry. 284*5c51f124SMoriah Waterland */ 285*5c51f124SMoriah Waterland #define CURMODE BADMODE /* current mode has been specified */ 286*5c51f124SMoriah Waterland #define CUROWNER BADOWNER /* ... same for owner ... */ 287*5c51f124SMoriah Waterland #define CURGROUP BADGROUP /* ... and group. */ 288*5c51f124SMoriah Waterland 289*5c51f124SMoriah Waterland #define WILDCARD BADMODE >> 1 290*5c51f124SMoriah Waterland #define DB_UNDEFINED_ENTRY "?" 291*5c51f124SMoriah Waterland 292*5c51f124SMoriah Waterland #define DEFAULT_MODE 0755 293*5c51f124SMoriah Waterland #define DEFAULT_MODE_FILE 0644 294*5c51f124SMoriah Waterland #define DEFAULT_OWNER "root" 295*5c51f124SMoriah Waterland #define DEFAULT_GROUP "other" 296*5c51f124SMoriah Waterland 297*5c51f124SMoriah Waterland #define INST_RELEASE "var/sadm/system/admin/INST_RELEASE" 298*5c51f124SMoriah Waterland 299*5c51f124SMoriah Waterland #define RANDOM "/dev/urandom" 300*5c51f124SMoriah Waterland #define BLOCK 256 301*5c51f124SMoriah Waterland 302*5c51f124SMoriah Waterland #define TERM_WIDTH 60 303*5c51f124SMoriah Waterland #define SMALL_DIVISOR 4 304*5c51f124SMoriah Waterland #define MED_DIVISOR 5 305*5c51f124SMoriah Waterland #define LARGE_DIVISOR 10 306*5c51f124SMoriah Waterland #define MED_DWNLD (10 * 1024 * 1024) /* 10 MB */ 307*5c51f124SMoriah Waterland #define LARGE_DWNLD (5 * MED_DWNLD) /* 50 MB */ 308*5c51f124SMoriah Waterland 309*5c51f124SMoriah Waterland #define HTTP "http://" 310*5c51f124SMoriah Waterland #define HTTPS "https://" 311*5c51f124SMoriah Waterland 312*5c51f124SMoriah Waterland #define PKGADD "pkgadd" 313*5c51f124SMoriah Waterland 314*5c51f124SMoriah Waterland /* Settings for network admin defaults */ 315*5c51f124SMoriah Waterland 316*5c51f124SMoriah Waterland #define NET_TIMEOUT_DEFAULT 60 317*5c51f124SMoriah Waterland #define NET_RETRIES_DEFAULT 3 318*5c51f124SMoriah Waterland #define NET_TIMEOUT_MIN 1 /* 1 second */ 319*5c51f124SMoriah Waterland #define NET_TIMEOUT_MAX (5 * 60) /* 5 minutes */ 320*5c51f124SMoriah Waterland #define NET_RETRIES_MIN 1 321*5c51f124SMoriah Waterland #define NET_RETRIES_MAX 10 322*5c51f124SMoriah Waterland #define AUTH_NOCHECK 0 323*5c51f124SMoriah Waterland #define AUTH_QUIT 1 324*5c51f124SMoriah Waterland 325*5c51f124SMoriah Waterland /* package header magic tokens */ 326*5c51f124SMoriah Waterland #define HDR_PREFIX "# PaCkAgE DaTaStReAm" 327*5c51f124SMoriah Waterland #define HDR_SUFFIX "# end of header" 328*5c51f124SMoriah Waterland 329*5c51f124SMoriah Waterland /* name of security files */ 330*5c51f124SMoriah Waterland #define PKGSEC "/var/sadm/security" 331*5c51f124SMoriah Waterland #define SIGNATURE_FILENAME "signature" 332*5c51f124SMoriah Waterland 333*5c51f124SMoriah Waterland #define GROUP "/etc/group" 334*5c51f124SMoriah Waterland #define PASSWD "/etc/passwd" 335*5c51f124SMoriah Waterland 336*5c51f124SMoriah Waterland /* 337*5c51f124SMoriah Waterland * The next three mean that no mode, owner or group was specified or that the 338*5c51f124SMoriah Waterland * one specified is invalid for some reason. Sometimes this is an error in 339*5c51f124SMoriah Waterland * which case it is generally converted to CUR* with a warning. Other times 340*5c51f124SMoriah Waterland * it means "look it up" by stating the existing file system object pointred 341*5c51f124SMoriah Waterland * to in the prototype file. 342*5c51f124SMoriah Waterland */ 343*5c51f124SMoriah Waterland #define NOMODE (BADMODE-1) 344*5c51f124SMoriah Waterland #define NOOWNER "@" 345*5c51f124SMoriah Waterland #define NOGROUP "@" 346*5c51f124SMoriah Waterland 347*5c51f124SMoriah Waterland /* string comparitor abbreviators */ 348*5c51f124SMoriah Waterland 349*5c51f124SMoriah Waterland #define ci_streq(a, b) (strcasecmp((a), (b)) == 0) 350*5c51f124SMoriah Waterland #define ci_strneq(a, b, c) (strncasecmp((a), (b), (c)) == 0) 351*5c51f124SMoriah Waterland #define streq(a, b) (strcmp((a), (b)) == 0) 352*5c51f124SMoriah Waterland #define strneq(a, b, c) (strncmp((a), (b), (c)) == 0) 353*5c51f124SMoriah Waterland 354*5c51f124SMoriah Waterland #ifdef __STDC__ 355*5c51f124SMoriah Waterland 356*5c51f124SMoriah Waterland extern FILE *epopen(char *cmd, char *mode); 357*5c51f124SMoriah Waterland extern char **gpkglist(char *dir, char **pkg, char **catg); 358*5c51f124SMoriah Waterland extern int is_not_valid_length(char **category); 359*5c51f124SMoriah Waterland extern int is_not_valid_category(char **category, char *progname); 360*5c51f124SMoriah Waterland extern int is_same_CATEGORY(char **category, char *installed_category); 361*5c51f124SMoriah Waterland extern char **get_categories(char *catg_arg); 362*5c51f124SMoriah Waterland 363*5c51f124SMoriah Waterland extern void pkglist_cont(char *keyword); 364*5c51f124SMoriah Waterland extern char **pkgalias(char *pkg); 365*5c51f124SMoriah Waterland extern char *get_prog_name(void); 366*5c51f124SMoriah Waterland extern char *set_prog_name(char *name); 367*5c51f124SMoriah Waterland extern int averify(int fix, char *ftype, char *path, struct ainfo *ainfo); 368*5c51f124SMoriah Waterland extern int ckparam(char *param, char *value); 369*5c51f124SMoriah Waterland extern int ckvolseq(char *dir, int part, int nparts); 370*5c51f124SMoriah Waterland extern int cverify(int fix, char *ftype, char *path, struct cinfo *cinfo, 371*5c51f124SMoriah Waterland int allow_checksum); 372*5c51f124SMoriah Waterland extern unsigned long compute_checksum(int *r_cksumerr, char *a_path); 373*5c51f124SMoriah Waterland extern int fverify(int fix, char *ftype, char *path, struct ainfo *ainfo, 374*5c51f124SMoriah Waterland struct cinfo *cinfo); 375*5c51f124SMoriah Waterland extern char *getErrbufAddr(void); 376*5c51f124SMoriah Waterland extern int getErrbufSize(void); 377*5c51f124SMoriah Waterland extern char *getErrstr(void); 378*5c51f124SMoriah Waterland extern void setErrstr(char *errstr); 379*5c51f124SMoriah Waterland extern int devtype(char *alias, struct pkgdev *devp); 380*5c51f124SMoriah Waterland extern int ds_totread; /* total number of parts read */ 381*5c51f124SMoriah Waterland extern int ds_close(int pkgendflg); 382*5c51f124SMoriah Waterland extern int ds_findpkg(char *device, char *pkg); 383*5c51f124SMoriah Waterland extern int ds_getinfo(char *string); 384*5c51f124SMoriah Waterland extern int ds_getpkg(char *device, int n, char *dstdir); 385*5c51f124SMoriah Waterland extern int ds_ginit(char *device); 386*5c51f124SMoriah Waterland extern boolean_t ds_fd_open(void); 387*5c51f124SMoriah Waterland extern int ds_init(char *device, char **pkg, char *norewind); 388*5c51f124SMoriah Waterland extern int BIO_ds_dump_header(PKG_ERR *, BIO *); 389*5c51f124SMoriah Waterland extern int BIO_ds_dump(PKG_ERR *, char *, BIO *); 390*5c51f124SMoriah Waterland extern int BIO_dump_cmd(char *cmd, BIO *bio); 391*5c51f124SMoriah Waterland extern int ds_next(char *, char *); 392*5c51f124SMoriah Waterland extern int ds_readbuf(char *device); 393*5c51f124SMoriah Waterland extern int epclose(FILE *pp); 394*5c51f124SMoriah Waterland extern int esystem(char *cmd, int ifd, int ofd); 395*5c51f124SMoriah Waterland extern int e_ExecCmdArray(int *r_status, char **r_results, 396*5c51f124SMoriah Waterland char *a_inputFile, char *a_cmd, char **a_args); 397*5c51f124SMoriah Waterland extern int e_ExecCmdList(int *r_status, char **r_results, 398*5c51f124SMoriah Waterland char *a_inputFile, char *a_cmd, ...); 399*5c51f124SMoriah Waterland extern int gpkgmap(struct cfent *ept, FILE *fp); 400*5c51f124SMoriah Waterland extern int gpkgmapvfp(struct cfent *ept, VFP_T *fpv); 401*5c51f124SMoriah Waterland extern void setmapmode(int mode_no); 402*5c51f124SMoriah Waterland extern int isFdRemote(int a_fd); 403*5c51f124SMoriah Waterland extern int isFstypeRemote(char *a_fstype); 404*5c51f124SMoriah Waterland extern int isPathRemote(char *a_path); 405*5c51f124SMoriah Waterland extern int iscpio(char *path, int *iscomp); 406*5c51f124SMoriah Waterland extern int isdir(char *path); 407*5c51f124SMoriah Waterland extern int isfile(char *dir, char *file); 408*5c51f124SMoriah Waterland extern int fmkdir(char *a_path, int a_mode); 409*5c51f124SMoriah Waterland extern int pkgexecl(char *filein, char *fileout, char *uname, char *gname, 410*5c51f124SMoriah Waterland ...); 411*5c51f124SMoriah Waterland extern int pkgexecv(char *filein, char *fileout, char *uname, char *gname, 412*5c51f124SMoriah Waterland char *arg[]); 413*5c51f124SMoriah Waterland extern int pkghead(char *device); 414*5c51f124SMoriah Waterland extern int pkgmount(struct pkgdev *devp, char *pkg, int part, int nparts, 415*5c51f124SMoriah Waterland int getvolflg); 416*5c51f124SMoriah Waterland extern int pkgtrans(char *device1, char *device2, char **pkg, 417*5c51f124SMoriah Waterland int options, keystore_handle_t, char *); 418*5c51f124SMoriah Waterland extern int pkgumount(struct pkgdev *devp); 419*5c51f124SMoriah Waterland extern int ppkgmap(struct cfent *ept, FILE *fp); 420*5c51f124SMoriah Waterland extern int putcfile(struct cfent *ept, FILE *fp); 421*5c51f124SMoriah Waterland extern int putcvfpfile(struct cfent *ept, VFP_T *vfp); 422*5c51f124SMoriah Waterland extern int rrmdir(char *path); 423*5c51f124SMoriah Waterland extern void set_memalloc_failure_func(void (*)(int)); 424*5c51f124SMoriah Waterland extern void *xmalloc(size_t size); 425*5c51f124SMoriah Waterland extern void *xrealloc(void *ptr, size_t size); 426*5c51f124SMoriah Waterland extern char *xstrdup(char *str); 427*5c51f124SMoriah Waterland extern void set_passphrase_prompt(char *); 428*5c51f124SMoriah Waterland extern void set_passphrase_passarg(char *); 429*5c51f124SMoriah Waterland extern int pkg_passphrase_cb(char *, int, int, void *); 430*5c51f124SMoriah Waterland 431*5c51f124SMoriah Waterland extern int srchcfile(struct cfent *ept, char *path, VFP_T *vfp, 432*5c51f124SMoriah Waterland VFP_T *vfpout); 433*5c51f124SMoriah Waterland extern struct group *cgrgid(gid_t gid); 434*5c51f124SMoriah Waterland extern struct group *cgrnam(char *nam); 435*5c51f124SMoriah Waterland extern struct passwd *cpwnam(char *nam); 436*5c51f124SMoriah Waterland extern struct passwd *cpwuid(uid_t uid); 437*5c51f124SMoriah Waterland extern struct group *clgrgid(gid_t gid); 438*5c51f124SMoriah Waterland extern struct group *clgrnam(char *nam); 439*5c51f124SMoriah Waterland extern struct passwd *clpwnam(char *nam); 440*5c51f124SMoriah Waterland extern struct passwd *clpwuid(uid_t uid); 441*5c51f124SMoriah Waterland extern void basepath(char *path, char *basedir, char *ir); 442*5c51f124SMoriah Waterland extern void canonize(char *file); 443*5c51f124SMoriah Waterland extern void canonize_slashes(char *file); 444*5c51f124SMoriah Waterland extern void checksum_off(void); 445*5c51f124SMoriah Waterland extern void checksum_on(void); 446*5c51f124SMoriah Waterland extern void cvtpath(char *path, char *copy); 447*5c51f124SMoriah Waterland extern void ds_order(char *list[]); 448*5c51f124SMoriah Waterland extern void ds_putinfo(char *buf); 449*5c51f124SMoriah Waterland extern void ds_skiptoend(char *device); 450*5c51f124SMoriah Waterland extern void ecleanup(void); 451*5c51f124SMoriah Waterland /*PRINTFLIKE1*/ 452*5c51f124SMoriah Waterland extern void logerr(char *fmt, ...); 453*5c51f124SMoriah Waterland extern int mappath(int flag, char *path); 454*5c51f124SMoriah Waterland extern int mapvar(int flag, char *varname); 455*5c51f124SMoriah Waterland /*PRINTFLIKE1*/ 456*5c51f124SMoriah Waterland extern void progerr(char *fmt, ...); 457*5c51f124SMoriah Waterland extern void pkgerr(PKG_ERR *); 458*5c51f124SMoriah Waterland extern void rpterr(void); 459*5c51f124SMoriah Waterland extern void tputcfent(struct cfent *ept, FILE *fp); 460*5c51f124SMoriah Waterland extern void set_nonABI_symlinks(void); 461*5c51f124SMoriah Waterland extern int nonABI_symlinks(void); 462*5c51f124SMoriah Waterland extern void disable_attribute_check(void); 463*5c51f124SMoriah Waterland extern int get_disable_attribute_check(void); 464*5c51f124SMoriah Waterland 465*5c51f124SMoriah Waterland /* security.c */ 466*5c51f124SMoriah Waterland extern void sec_init(void); 467*5c51f124SMoriah Waterland extern char *get_subject_display_name(X509 *); 468*5c51f124SMoriah Waterland extern char *get_issuer_display_name(X509 *); 469*5c51f124SMoriah Waterland extern char *get_serial_num(X509 *); 470*5c51f124SMoriah Waterland extern char *get_fingerprint(X509 *, const EVP_MD *); 471*5c51f124SMoriah Waterland extern int get_cert_chain(PKG_ERR *, X509 *, STACK_OF(X509) *, 472*5c51f124SMoriah Waterland STACK_OF(X509) *, STACK_OF(X509) **); 473*5c51f124SMoriah Waterland 474*5c51f124SMoriah Waterland /* pkgstr.c */ 475*5c51f124SMoriah Waterland void pkgstrConvertUllToTimeString_r(unsigned long long a_time, 476*5c51f124SMoriah Waterland char *a_buf, int a_bufLen); 477*5c51f124SMoriah Waterland char *pkgstrConvertPathToBasename(char *a_path); 478*5c51f124SMoriah Waterland char *pkgstrConvertPathToDirname(char *a_path); 479*5c51f124SMoriah Waterland char *pkgstrDup(char *a_str); 480*5c51f124SMoriah Waterland char *pkgstrLocatePathBasename(char *a_path); 481*5c51f124SMoriah Waterland void pkgstrScaleNumericString(char *a_buf, unsigned long long scale); 482*5c51f124SMoriah Waterland void pkgstrAddToken(char **a_old, char *a_new, char a_separator); 483*5c51f124SMoriah Waterland boolean_t pkgstrContainsToken(char *a_string, char *a_token, 484*5c51f124SMoriah Waterland char *a_separators); 485*5c51f124SMoriah Waterland void pkgstrExpandTokens(char **a_old, char *a_string, 486*5c51f124SMoriah Waterland char a_separator, char *a_separators); 487*5c51f124SMoriah Waterland char *pkgstrGetToken(char *r_sep, char *a_string, int a_index, 488*5c51f124SMoriah Waterland char *a_separators); 489*5c51f124SMoriah Waterland void pkgstrGetToken_r(char *r_sep, char *a_string, int a_index, 490*5c51f124SMoriah Waterland char *a_separators, char *a_buf, int a_bufLen); 491*5c51f124SMoriah Waterland unsigned long pkgstrNumTokens(char *a_string, char *a_separators); 492*5c51f124SMoriah Waterland char *pkgstrPrintf(char *a_format, ...); 493*5c51f124SMoriah Waterland void pkgstrPrintf_r(char *a_buf, int a_bufLen, char *a_format, ...); 494*5c51f124SMoriah Waterland void pkgstrRemoveToken(char **r_string, char *a_token, 495*5c51f124SMoriah Waterland char *a_separators, int a_index); 496*5c51f124SMoriah Waterland void pkgstrRemoveLeadingWhitespace(char **a_str); 497*5c51f124SMoriah Waterland /* vfpops.c */ 498*5c51f124SMoriah Waterland extern int vfpCheckpointFile(VFP_T **r_destVfp, VFP_T **a_vfp, 499*5c51f124SMoriah Waterland char *a_path); 500*5c51f124SMoriah Waterland extern int vfpCheckpointOpen(VFP_T **a_cvfp, VFP_T **r_vfp, char *a_path, 501*5c51f124SMoriah Waterland char *a_mode, VFPFLAGS_T a_flags); 502*5c51f124SMoriah Waterland extern int vfpClearModified(VFP_T *a_vfp); 503*5c51f124SMoriah Waterland extern int vfpClose(VFP_T **r_vfp); 504*5c51f124SMoriah Waterland extern int vfpGetModified(VFP_T *a_vfp); 505*5c51f124SMoriah Waterland extern int vfpOpen(VFP_T **r_vfp, char *a_path, char *a_mode, 506*5c51f124SMoriah Waterland VFPFLAGS_T a_flags); 507*5c51f124SMoriah Waterland extern void vfpRewind(VFP_T *a_vfp); 508*5c51f124SMoriah Waterland extern ssize_t vfpSafePwrite(int a_fildes, void *a_buf, 509*5c51f124SMoriah Waterland size_t a_nbyte, off_t a_offset); 510*5c51f124SMoriah Waterland extern ssize_t vfpSafeWrite(int a_fildes, void *a_buf, size_t a_nbyte); 511*5c51f124SMoriah Waterland extern int vfpSetFlags(VFP_T *a_vfp, VFPFLAGS_T a_flags); 512*5c51f124SMoriah Waterland extern int vfpSetModified(VFP_T *a_vfp); 513*5c51f124SMoriah Waterland extern int vfpSetSize(VFP_T *a_vfp, size_t a_size); 514*5c51f124SMoriah Waterland extern void vfpTruncate(VFP_T *a_vfp); 515*5c51f124SMoriah Waterland extern int vfpWriteToFile(VFP_T *a_vfp, char *a_path); 516*5c51f124SMoriah Waterland 517*5c51f124SMoriah Waterland /* handlelocalfs.c */ 518*5c51f124SMoriah Waterland boolean_t enable_local_fs(void); 519*5c51f124SMoriah Waterland boolean_t restore_local_fs(void); 520*5c51f124SMoriah Waterland 521*5c51f124SMoriah Waterland #else /* __STDC__ */ 522*5c51f124SMoriah Waterland 523*5c51f124SMoriah Waterland extern FILE *epopen(); 524*5c51f124SMoriah Waterland extern void pkglist_cont(); 525*5c51f124SMoriah Waterland extern char **gpkglist(); 526*5c51f124SMoriah Waterland extern char **pkgalias(); 527*5c51f124SMoriah Waterland extern char *get_prog_name(); 528*5c51f124SMoriah Waterland extern char *set_prog_name(); 529*5c51f124SMoriah Waterland extern int averify(); 530*5c51f124SMoriah Waterland extern int ckparam(); 531*5c51f124SMoriah Waterland extern int ckvolseq(); 532*5c51f124SMoriah Waterland extern int cverify(); 533*5c51f124SMoriah Waterland extern unsigned long compute_checksum(); 534*5c51f124SMoriah Waterland extern int fverify(); 535*5c51f124SMoriah Waterland extern char *getErrbufAddr(); 536*5c51f124SMoriah Waterland extern int getErrbufSize(); 537*5c51f124SMoriah Waterland extern char *getErrstr(); 538*5c51f124SMoriah Waterland extern void setErrstr(); 539*5c51f124SMoriah Waterland extern int devtype(); 540*5c51f124SMoriah Waterland extern int ds_close(); 541*5c51f124SMoriah Waterland extern int ds_findpkg(); 542*5c51f124SMoriah Waterland extern int ds_getinfo(); 543*5c51f124SMoriah Waterland extern int ds_getpkg(); 544*5c51f124SMoriah Waterland extern int ds_ginit(); 545*5c51f124SMoriah Waterland extern boolean_t ds_fd_open(); 546*5c51f124SMoriah Waterland extern int ds_init(); 547*5c51f124SMoriah Waterland extern int ds_next(); 548*5c51f124SMoriah Waterland extern int ds_readbuf(); 549*5c51f124SMoriah Waterland extern int epclose(); 550*5c51f124SMoriah Waterland extern int esystem(); 551*5c51f124SMoriah Waterland extern int e_ExecCmdArray(); 552*5c51f124SMoriah Waterland extern int e_ExecCmdList(); 553*5c51f124SMoriah Waterland extern int gpkgmap(); 554*5c51f124SMoriah Waterland extern int isFdRemote(); 555*5c51f124SMoriah Waterland extern int isFstypeRemote(); 556*5c51f124SMoriah Waterland extern int isPathRemote(); 557*5c51f124SMoriah Waterland extern int iscpio(); 558*5c51f124SMoriah Waterland extern int isdir(); 559*5c51f124SMoriah Waterland extern int isfile(); 560*5c51f124SMoriah Waterland extern int pkgexecl(); 561*5c51f124SMoriah Waterland extern int pkgexecv(); 562*5c51f124SMoriah Waterland extern int pkghead(); 563*5c51f124SMoriah Waterland extern int pkgmount(); 564*5c51f124SMoriah Waterland extern int pkgtrans(); 565*5c51f124SMoriah Waterland extern int pkgumount(); 566*5c51f124SMoriah Waterland extern int ppkgmap(); 567*5c51f124SMoriah Waterland extern int putcfile(); 568*5c51f124SMoriah Waterland extern int putcvfpfile(); 569*5c51f124SMoriah Waterland extern int rrmdir(); 570*5c51f124SMoriah Waterland extern int srchcfile(); 571*5c51f124SMoriah Waterland extern struct group *cgrgid(); 572*5c51f124SMoriah Waterland extern struct group *cgrnam(); 573*5c51f124SMoriah Waterland extern struct passwd *cpwnam(); 574*5c51f124SMoriah Waterland extern struct passwd *cpwuid(); 575*5c51f124SMoriah Waterland extern void basepath(); 576*5c51f124SMoriah Waterland extern void canonize(); 577*5c51f124SMoriah Waterland extern void canonize_slashes(); 578*5c51f124SMoriah Waterland extern void checksum_off(); 579*5c51f124SMoriah Waterland extern void checksum_on(); 580*5c51f124SMoriah Waterland extern void cvtpath(); 581*5c51f124SMoriah Waterland extern void ds_order(); 582*5c51f124SMoriah Waterland extern void ds_putinfo(); 583*5c51f124SMoriah Waterland extern void ds_skiptoend(); 584*5c51f124SMoriah Waterland extern void ecleanup(); 585*5c51f124SMoriah Waterland extern void logerr(); 586*5c51f124SMoriah Waterland extern int mappath(); 587*5c51f124SMoriah Waterland extern int mapvar(); 588*5c51f124SMoriah Waterland extern void progerr(); 589*5c51f124SMoriah Waterland extern void rpterr(); 590*5c51f124SMoriah Waterland extern void tputcfent(); 591*5c51f124SMoriah Waterland extern void set_nonABI_symlinks(); 592*5c51f124SMoriah Waterland extern int nonABI_symlinks(); 593*5c51f124SMoriah Waterland extern void disable_attribute_check(); 594*5c51f124SMoriah Waterland extern int get_disable_attribute_check(); 595*5c51f124SMoriah Waterland /* vfpops.c */ 596*5c51f124SMoriah Waterland extern int vfpCheckpointFile(); 597*5c51f124SMoriah Waterland extern int vfpCheckpointOpen(); 598*5c51f124SMoriah Waterland extern int vfpClearModified(); 599*5c51f124SMoriah Waterland extern int vfpClose(); 600*5c51f124SMoriah Waterland extern int vfpGetModified(); 601*5c51f124SMoriah Waterland extern int vfpOpen(); 602*5c51f124SMoriah Waterland extern void vfpRewind(); 603*5c51f124SMoriah Waterland extern int vfpSetFlags(); 604*5c51f124SMoriah Waterland extern int vfpSetModified(); 605*5c51f124SMoriah Waterland extern int vfpSetSize(); 606*5c51f124SMoriah Waterland extern void vfpTruncate(); 607*5c51f124SMoriah Waterland extern int vfpWriteToFile(); 608*5c51f124SMoriah Waterland 609*5c51f124SMoriah Waterland /* handlelocalfs.c */ 610*5c51f124SMoriah Waterland boolean_t enable_local_fs(); 611*5c51f124SMoriah Waterland boolean_t restore_local_fs(); 612*5c51f124SMoriah Waterland 613*5c51f124SMoriah Waterland /* gpkgmap.c */ 614*5c51f124SMoriah Waterland int getmapmode(void); 615*5c51f124SMoriah Waterland 616*5c51f124SMoriah Waterland #endif /* __STDC__ */ 617*5c51f124SMoriah Waterland 618*5c51f124SMoriah Waterland #ifdef __cplusplus 619*5c51f124SMoriah Waterland } 620*5c51f124SMoriah Waterland #endif 621*5c51f124SMoriah Waterland 622*5c51f124SMoriah Waterland #endif /* _PKGLIB_H */ 623