15c51f124SMoriah Waterland /* 25c51f124SMoriah Waterland * CDDL HEADER START 35c51f124SMoriah Waterland * 45c51f124SMoriah Waterland * The contents of this file are subject to the terms of the 55c51f124SMoriah Waterland * Common Development and Distribution License (the "License"). 65c51f124SMoriah Waterland * You may not use this file except in compliance with the License. 75c51f124SMoriah Waterland * 85c51f124SMoriah Waterland * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 95c51f124SMoriah Waterland * or http://www.opensolaris.org/os/licensing. 105c51f124SMoriah Waterland * See the License for the specific language governing permissions 115c51f124SMoriah Waterland * and limitations under the License. 125c51f124SMoriah Waterland * 135c51f124SMoriah Waterland * When distributing Covered Code, include this CDDL HEADER in each 145c51f124SMoriah Waterland * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 155c51f124SMoriah Waterland * If applicable, add the following below this CDDL HEADER, with the 165c51f124SMoriah Waterland * fields enclosed by brackets "[]" replaced with your own identifying 175c51f124SMoriah Waterland * information: Portions Copyright [yyyy] [name of copyright owner] 185c51f124SMoriah Waterland * 195c51f124SMoriah Waterland * CDDL HEADER END 205c51f124SMoriah Waterland */ 215c51f124SMoriah Waterland 225c51f124SMoriah Waterland /* 235c51f124SMoriah Waterland * Copyright 2009 Sun Microsystems, Inc. All rights reserved. 245c51f124SMoriah Waterland * Use is subject to license terms. 255c51f124SMoriah Waterland */ 265c51f124SMoriah Waterland 275c51f124SMoriah Waterland /* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 285c51f124SMoriah Waterland /* All Rights Reserved */ 295c51f124SMoriah Waterland 305c51f124SMoriah Waterland #ifndef _PKGLIB_H 315c51f124SMoriah Waterland #define _PKGLIB_H 325c51f124SMoriah Waterland 335c51f124SMoriah Waterland 345c51f124SMoriah Waterland #ifdef __cplusplus 355c51f124SMoriah Waterland extern "C" { 365c51f124SMoriah Waterland #endif 375c51f124SMoriah Waterland 385c51f124SMoriah Waterland #include <sys/types.h> 395c51f124SMoriah Waterland #include <limits.h> 405c51f124SMoriah Waterland #include <stdio.h> 415c51f124SMoriah Waterland #include <pkgdev.h> 425c51f124SMoriah Waterland #include <pkgstrct.h> 435c51f124SMoriah Waterland #include <openssl/bio.h> 445c51f124SMoriah Waterland #include <openssl/x509.h> 455c51f124SMoriah Waterland #include <netdb.h> 465c51f124SMoriah Waterland #include <boot_http.h> 475c51f124SMoriah Waterland #include "pkgerr.h" 485c51f124SMoriah Waterland #include "keystore.h" 495c51f124SMoriah Waterland #include "cfext.h" 505c51f124SMoriah Waterland 515c51f124SMoriah Waterland /* 5262224350SCasper H.S. Dik * The contents database file interface. 5362224350SCasper H.S. Dik */ 5462224350SCasper H.S. Dik 5562224350SCasper H.S. Dik typedef struct pkg_server *PKGserver; 5662224350SCasper H.S. Dik 5762224350SCasper H.S. Dik /* Some commands modify the internal database: add them here */ 5862224350SCasper H.S. Dik #define PKG_WRITE_COMMAND(cmd) ((cmd) == PKG_ADDLINES) 5962224350SCasper H.S. Dik 6062224350SCasper H.S. Dik #define PKG_EXIT 0x0 6162224350SCasper H.S. Dik #define PKG_FINDFILE 0x1 6262224350SCasper H.S. Dik #define PKG_DUMP 0x2 6362224350SCasper H.S. Dik #define PKG_PKGSYNC 0x3 6462224350SCasper H.S. Dik #define PKG_FILTER 0x4 6562224350SCasper H.S. Dik #define PKG_ADDLINES 0x5 6662224350SCasper H.S. Dik #define PKG_NOP 0x6 6762224350SCasper H.S. Dik 6862224350SCasper H.S. Dik #define SUNW_PKG_SERVERMODE "SUNW_PKG_SERVERMODE" 6962224350SCasper H.S. Dik 7062224350SCasper H.S. Dik #define PKGSERV_MODE "pkg-server-mode=" 7162224350SCasper H.S. Dik #define PKGSERV_MODE_LEN (sizeof (PKGSERV_MODE) - 1) 7262224350SCasper H.S. Dik 7362224350SCasper H.S. Dik #define MODE_PERMANENT "permanent" 7462224350SCasper H.S. Dik #define MODE_RUN_ONCE "run_once" 7562224350SCasper H.S. Dik #define MODE_TIMEOUT "timeout" 7662224350SCasper H.S. Dik 7762224350SCasper H.S. Dik #define MAXLOGFILESIZE (20 * 1024 * 1024) 7862224350SCasper H.S. Dik 7962224350SCasper H.S. Dik #define PKGLOG "pkglog" 8062224350SCasper H.S. Dik #define PKGDOOR ".door" 8162224350SCasper H.S. Dik 8262224350SCasper H.S. Dik typedef enum { 8362224350SCasper H.S. Dik INVALID, /* Not initialized */ 8462224350SCasper H.S. Dik NEVER, /* Don't start, does check if it is running. */ 8562224350SCasper H.S. Dik FLUSH_LOG, /* Run it once to incorporate the log. */ 8662224350SCasper H.S. Dik RUN_ONCE, /* Run until the current client stops. */ 8762224350SCasper H.S. Dik TIMEOUT, /* Run until a timeout occurs. */ 8862224350SCasper H.S. Dik PERMANENT, /* Run until it is externally terminated. */ 8962224350SCasper H.S. Dik DEFAULTMODE = TIMEOUT /* The default mode, must come last */ 9062224350SCasper H.S. Dik } start_mode_t; 9162224350SCasper H.S. Dik 9262224350SCasper H.S. Dik typedef struct pkgcmd { 9362224350SCasper H.S. Dik int cmd; 9462224350SCasper H.S. Dik char buf[1]; 9562224350SCasper H.S. Dik } pkgcmd_t; 9662224350SCasper H.S. Dik 9762224350SCasper H.S. Dik typedef struct pkgfilter { 9862224350SCasper H.S. Dik int cmd; 9962224350SCasper H.S. Dik int len; 10062224350SCasper H.S. Dik char buf[1]; 10162224350SCasper H.S. Dik } pkgfilter_t; 10262224350SCasper H.S. Dik 10362224350SCasper H.S. Dik /* 1045c51f124SMoriah Waterland * Virtual File Protocol definitions 1055c51f124SMoriah Waterland */ 1065c51f124SMoriah Waterland 1075c51f124SMoriah Waterland /* 1085c51f124SMoriah Waterland * flags associated with virtual file protocol operations; note that these flags 1095c51f124SMoriah Waterland * may only occupy the low order 16 bits of the 32-bit unsigned flag. 1105c51f124SMoriah Waterland */ 1115c51f124SMoriah Waterland 1125c51f124SMoriah Waterland typedef unsigned long VFPFLAGS_T; 1135c51f124SMoriah Waterland 1145c51f124SMoriah Waterland #define VFP_NONE 0x00000000 /* no special flags */ 1155c51f124SMoriah Waterland #define VFP_NEEDNOW 0x00000001 /* need memory now */ 1165c51f124SMoriah Waterland #define VFP_SEQUENTIAL 0x00000002 /* sequential access */ 1175c51f124SMoriah Waterland #define VFP_RANDOM 0x00000004 /* random access */ 1185c51f124SMoriah Waterland #define VFP_NOMMAP 0x00000008 /* do not use mmap to access file */ 1195c51f124SMoriah Waterland #define VFP_NOMALLOC 0x00000010 /* do not use malloc to buffer file */ 1205c51f124SMoriah Waterland 1215c51f124SMoriah Waterland /* virtual file protocol object */ 1225c51f124SMoriah Waterland 1235c51f124SMoriah Waterland typedef struct _vfp VFP_T; 1245c51f124SMoriah Waterland 1255c51f124SMoriah Waterland /* structure behind the virtual file protocol object */ 1265c51f124SMoriah Waterland 1275c51f124SMoriah Waterland struct _vfp { 1285c51f124SMoriah Waterland FILE *_vfpFile; /* -> opened FILE */ 1295c51f124SMoriah Waterland char *_vfpCurr; /* -> current byte to read/write */ 1305c51f124SMoriah Waterland char *_vfpHighWater; /* -> last byte modified */ 1315c51f124SMoriah Waterland char *_vfpEnd; /* -> last data byte */ 1325c51f124SMoriah Waterland char *_vfpPath; /* -> path associated with FILE */ 1335c51f124SMoriah Waterland char *_vfpStart; /* -> first data byte */ 1345c51f124SMoriah Waterland void *_vfpExtra; /* undefined */ 1355c51f124SMoriah Waterland size_t _vfpSize; /* size of mapped/allocated area */ 1365c51f124SMoriah Waterland size_t _vfpMapSize; /* # mapped bytes */ 1375c51f124SMoriah Waterland VFPFLAGS_T _vfpFlags; /* flags associated with vfp/data */ 1385c51f124SMoriah Waterland int _vfpOverflow; /* non-zero if buffer write overflow */ 1395c51f124SMoriah Waterland blkcnt_t _vfpCkStBlocks; /* checkpoint # blocks */ 1405c51f124SMoriah Waterland dev_t _vfpCkDev; /* checkpoint device i.d. */ 1415c51f124SMoriah Waterland ino_t _vfpCkIno; /* checkpoint inode # */ 1425c51f124SMoriah Waterland off_t _vfpCkSize; /* checkpoint size */ 1435c51f124SMoriah Waterland time_t _vfpCkMtime; /* checkpoint modification time */ 1445c51f124SMoriah Waterland }; 1455c51f124SMoriah Waterland 1465c51f124SMoriah Waterland /* 1475c51f124SMoriah Waterland * get highest modified byte (length) contained in vfp 1485c51f124SMoriah Waterland * 1495c51f124SMoriah Waterland * determine number of bytes to write - it will be the highest of: 1505c51f124SMoriah Waterland * -- the current pointer into the file - this is updated whenever 1515c51f124SMoriah Waterland * the location of the file is changed by a single byte 1525c51f124SMoriah Waterland * -- the last "high water mark" - the last known location that 1535c51f124SMoriah Waterland * was written to the file - updated only when the location 1545c51f124SMoriah Waterland * of the file is directly changed - e.g. vfpSetCurrCharPtr, 1555c51f124SMoriah Waterland * vfpTruncate, vfpRewind. 1565c51f124SMoriah Waterland * this reduces the "bookkeeping" that needs to be done to know 1575c51f124SMoriah Waterland * how many bytes to write out to the file - typically a file is 1585c51f124SMoriah Waterland * written sequentially so the current file pointer is sufficient 1595c51f124SMoriah Waterland * to determine how many bytes to write out. 1605c51f124SMoriah Waterland */ 1615c51f124SMoriah Waterland 1625c51f124SMoriah Waterland #define vfpGetModifiedLen(VFP) \ 1635c51f124SMoriah Waterland (size_t)(((VFP)->_vfpHighWater > (VFP)->_vfpCurr) ? \ 1645c51f124SMoriah Waterland (((ptrdiff_t)(VFP)->_vfpHighWater - \ 1655c51f124SMoriah Waterland (ptrdiff_t)(VFP)->_vfpStart)) : \ 1665c51f124SMoriah Waterland (((ptrdiff_t)(VFP)->_vfpCurr - \ 1675c51f124SMoriah Waterland (ptrdiff_t)(VFP)->_vfpStart))) 1685c51f124SMoriah Waterland 1695c51f124SMoriah Waterland /* 1705c51f124SMoriah Waterland * increment current pointer by specified delta 1715c51f124SMoriah Waterland * if the delta exceeds the buffer size, set pointer to buffer end 1725c51f124SMoriah Waterland */ 1735c51f124SMoriah Waterland #define vfpIncCurrPtrBy(VFP, INC) \ 1745c51f124SMoriah Waterland { \ 1755c51f124SMoriah Waterland ((VFP)->_vfpCurr) += (INC); \ 1765c51f124SMoriah Waterland if (((VFP)->_vfpCurr) > ((VFP)->_vfpEnd)) { \ 1775c51f124SMoriah Waterland (VFP)->_vfpCurr = (VFP)->_vfpEnd; \ 1785c51f124SMoriah Waterland (VFP)->_vfpOverflow = 1; \ 1795c51f124SMoriah Waterland } \ 1805c51f124SMoriah Waterland if ((VFP)->_vfpHighWater < (VFP)->_vfpCurr) { \ 1815c51f124SMoriah Waterland (VFP)->_vfpHighWater = (VFP)->_vfpCurr; \ 1825c51f124SMoriah Waterland } \ 1835c51f124SMoriah Waterland } 1845c51f124SMoriah Waterland 1855c51f124SMoriah Waterland /* get the path associated with the vfp */ 1865c51f124SMoriah Waterland #define vfpGetPath(VFP) ((VFP)->_vfpPath) 1875c51f124SMoriah Waterland 1885c51f124SMoriah Waterland /* get a string from the vfp into a fixed size buffer */ 1895c51f124SMoriah Waterland #define vfpGets(VFP, PTR, LEN) \ 1905c51f124SMoriah Waterland { \ 1915c51f124SMoriah Waterland char *XXpXX = (PTR); \ 1925c51f124SMoriah Waterland size_t XXlXX = (LEN); \ 1935c51f124SMoriah Waterland while ((*(VFP)->_vfpCurr != '\0') && \ 1945c51f124SMoriah Waterland (*(VFP)->_vfpCurr != '\n')) { \ 1955c51f124SMoriah Waterland if (XXlXX > 1) { \ 1965c51f124SMoriah Waterland *XXpXX++ = *(VFP)->_vfpCurr; \ 1975c51f124SMoriah Waterland XXlXX--; \ 1985c51f124SMoriah Waterland } \ 1995c51f124SMoriah Waterland (VFP)->_vfpCurr++; \ 2005c51f124SMoriah Waterland } \ 2015c51f124SMoriah Waterland *XXpXX++ = '\0'; \ 2025c51f124SMoriah Waterland if (*(VFP)->_vfpCurr != '\0') { \ 2035c51f124SMoriah Waterland (VFP)->_vfpCurr++; \ 2045c51f124SMoriah Waterland } \ 2055c51f124SMoriah Waterland } 2065c51f124SMoriah Waterland 2075c51f124SMoriah Waterland /* get number of bytes remaining to read */ 2085c51f124SMoriah Waterland #define vfpGetBytesRemaining(VFP) \ 2095c51f124SMoriah Waterland (((((VFP)->_vfpHighWater) <= ((VFP)->_vfpCurr))) ? 0 : \ 2105c51f124SMoriah Waterland ((((ptrdiff_t)(VFP)->_vfpHighWater)-((ptrdiff_t)(VFP)->_vfpCurr)))) 2115c51f124SMoriah Waterland 2125c51f124SMoriah Waterland /* get number of bytes remaining to write */ 2135c51f124SMoriah Waterland #define vfpGetBytesAvailable(VFP) \ 2145c51f124SMoriah Waterland (((((VFP)->_vfpEnd) <= ((VFP)->_vfpCurr))) ? 0 : \ 2155c51f124SMoriah Waterland ((((ptrdiff_t)(VFP)->_vfpEnd)-((ptrdiff_t)(VFP)->_vfpCurr)))) 2165c51f124SMoriah Waterland 2175c51f124SMoriah Waterland /* put current character and increment to next */ 2185c51f124SMoriah Waterland #define vfpPutc(VFP, C) \ 2195c51f124SMoriah Waterland { \ 2205c51f124SMoriah Waterland (*(VFP)->_vfpCurr) = ((char)(C)); \ 2215c51f124SMoriah Waterland vfpIncCurrPtrBy((VFP), 1); \ 2225c51f124SMoriah Waterland } 2235c51f124SMoriah Waterland 2245c51f124SMoriah Waterland /* put integer to current character and increment */ 2255c51f124SMoriah Waterland #define vfpPutInteger(VFP, NUMBER) vfpPutFormat((VFP), "%d", (NUMBER)) 2265c51f124SMoriah Waterland 2275c51f124SMoriah Waterland /* put long to current character and increment */ 2285c51f124SMoriah Waterland #define vfpPutLong(VFP, NUMBER) vfpPutFormat((VFP), "%ld", (NUMBER)) 2295c51f124SMoriah Waterland 2305c51f124SMoriah Waterland /* get current character and increment to next */ 2315c51f124SMoriah Waterland #define vfpGetc(VFP) (*(VFP)->_vfpCurr++) 2325c51f124SMoriah Waterland 2335c51f124SMoriah Waterland /* get current character - do not increment */ 2345c51f124SMoriah Waterland #define vfpGetcNoInc(VFP) (*(VFP)->_vfpCurr) 2355c51f124SMoriah Waterland 2365c51f124SMoriah Waterland /* get pointer to current character */ 2375c51f124SMoriah Waterland #define vfpGetCurrCharPtr(VFP) ((VFP)->_vfpCurr) 2385c51f124SMoriah Waterland 2395c51f124SMoriah Waterland /* increment current character pointer */ 2405c51f124SMoriah Waterland #define vfpIncCurrPtr(VFP) vfpIncCurrPtrBy((VFP), 1) 2415c51f124SMoriah Waterland 2425c51f124SMoriah Waterland /* decrement current character pointer */ 2435c51f124SMoriah Waterland #define vfpDecCurrPtr(VFP) ((VFP)->_vfpCurr--) 2445c51f124SMoriah Waterland 2455c51f124SMoriah Waterland /* get pointer to first data byte in buffer */ 2465c51f124SMoriah Waterland #define vfpGetFirstCharPtr(VFP) ((VFP)->_vfpStart) 2475c51f124SMoriah Waterland 2485c51f124SMoriah Waterland /* get pointer to last data byte in buffer */ 2495c51f124SMoriah Waterland #define vfpGetLastCharPtr(VFP) ((VFP)->_vfpHighWater) 2505c51f124SMoriah Waterland 2515c51f124SMoriah Waterland /* set pointer to current character */ 2525c51f124SMoriah Waterland #define vfpSetCurrCharPtr(VFP, PTR) \ 2535c51f124SMoriah Waterland if ((VFP)->_vfpCurr > (VFP)->_vfpHighWater) { \ 2545c51f124SMoriah Waterland (VFP)->_vfpHighWater = (VFP)->_vfpCurr; \ 2555c51f124SMoriah Waterland } \ 2565c51f124SMoriah Waterland ((VFP)->_vfpCurr = (PTR)) 2575c51f124SMoriah Waterland 2585c51f124SMoriah Waterland /* set pointer to last data byte in buffer */ 2595c51f124SMoriah Waterland #define vfpSetLastCharPtr(VFP, PTR) \ 2605c51f124SMoriah Waterland if ((PTR) >= (VFP)->_vfpStart) { \ 2615c51f124SMoriah Waterland (VFP)->_vfpHighWater = (PTR); \ 2625c51f124SMoriah Waterland if ((VFP)->_vfpCurr > (VFP)->_vfpHighWater) { \ 2635c51f124SMoriah Waterland (VFP)->_vfpCurr = (VFP)->_vfpHighWater; \ 2645c51f124SMoriah Waterland } \ 2655c51f124SMoriah Waterland } 2665c51f124SMoriah Waterland 2675c51f124SMoriah Waterland /* seek to end of file - one past last data byte in file */ 2685c51f124SMoriah Waterland #define vfpSeekToEnd(VFP) ((VFP)->_vfpCurr = ((VFP)->_vfpHighWater)+1) 2695c51f124SMoriah Waterland 2705c51f124SMoriah Waterland /* get number of bytes between current char and specified char */ 2715c51f124SMoriah Waterland #define vfpGetCurrPtrDelta(VFP, P) \ 2725c51f124SMoriah Waterland (((ptrdiff_t)(P))-((ptrdiff_t)(VFP)->_vfpCurr)) 2735c51f124SMoriah Waterland 2745c51f124SMoriah Waterland /* put string to current character and increment */ 2755c51f124SMoriah Waterland #define vfpPuts(VFP, S) \ 2765c51f124SMoriah Waterland { \ 2775c51f124SMoriah Waterland size_t xxLen; \ 2785c51f124SMoriah Waterland size_t xxResult; \ 2795c51f124SMoriah Waterland xxLen = vfpGetBytesAvailable((VFP)); \ 2805c51f124SMoriah Waterland xxResult = strlcpy(((VFP)->_vfpCurr), (S), xxLen); \ 2815c51f124SMoriah Waterland vfpIncCurrPtrBy((VFP), xxResult); \ 2825c51f124SMoriah Waterland } 2835c51f124SMoriah Waterland 2845c51f124SMoriah Waterland /* put fixed number of bytes to current character and increment */ 2855c51f124SMoriah Waterland #define vfpPutBytes(VFP, PTR, LEN) \ 2865c51f124SMoriah Waterland { \ 2875c51f124SMoriah Waterland size_t xxLen; \ 2885c51f124SMoriah Waterland xxLen = vfpGetBytesAvailable((VFP)); \ 2895c51f124SMoriah Waterland if (xxLen > (LEN)) { \ 2905c51f124SMoriah Waterland xxLen = (LEN); \ 2915c51f124SMoriah Waterland } else { \ 2925c51f124SMoriah Waterland (VFP)->_vfpOverflow = 1; \ 2935c51f124SMoriah Waterland } \ 2945c51f124SMoriah Waterland memcpy((VFP)->_vfpCurr, (PTR), (xxLen)); \ 2955c51f124SMoriah Waterland vfpIncCurrPtrBy((VFP), (xxLen)); \ 2965c51f124SMoriah Waterland } 2975c51f124SMoriah Waterland 2985c51f124SMoriah Waterland /* put format one arg to current character and increment */ 2995c51f124SMoriah Waterland #define vfpPutFormat(VFP, FORMAT, ARG) \ 3005c51f124SMoriah Waterland { \ 3015c51f124SMoriah Waterland char xxTeMpXX[256]; \ 3025c51f124SMoriah Waterland (void) snprintf(xxTeMpXX, sizeof (xxTeMpXX), (FORMAT), (ARG)); \ 3035c51f124SMoriah Waterland vfpPuts((VFP), xxTeMpXX); \ 3045c51f124SMoriah Waterland } 3055c51f124SMoriah Waterland 3065c51f124SMoriah Waterland struct dm_buf { 3075c51f124SMoriah Waterland char *text_buffer; /* start of allocated buffer */ 3085c51f124SMoriah Waterland int offset; /* number of bytes into the text_buffer */ 3095c51f124SMoriah Waterland int allocation; /* size of buffer in bytes */ 3105c51f124SMoriah Waterland }; 3115c51f124SMoriah Waterland 3125c51f124SMoriah Waterland /* This structure is used to hold a dynamically growing string */ 3135c51f124SMoriah Waterland 3145c51f124SMoriah Waterland struct dstr { 3155c51f124SMoriah Waterland char *pc; 3165c51f124SMoriah Waterland int len; 3175c51f124SMoriah Waterland int max; 3185c51f124SMoriah Waterland }; 3195c51f124SMoriah Waterland 3205c51f124SMoriah Waterland /* setmapmode() defines */ 3215c51f124SMoriah Waterland #define MAPALL 0 /* resolve all variables */ 3225c51f124SMoriah Waterland #define MAPBUILD 1 /* map only build variables */ 3235c51f124SMoriah Waterland #define MAPINSTALL 2 /* map only install variables */ 3245c51f124SMoriah Waterland #define MAPNONE 3 /* map no variables */ 3255c51f124SMoriah Waterland 3265c51f124SMoriah Waterland #define NON_ABI_NAMELNGTH 33 /* 32 chars for name + 1 for NULL */ 3275c51f124SMoriah Waterland 3285c51f124SMoriah Waterland #define BLK_SIZE 512 /* size of logical block */ 3295c51f124SMoriah Waterland 3305c51f124SMoriah Waterland /* max length for printed attributes */ 3315c51f124SMoriah Waterland #define ATTR_MAX 80 3325c51f124SMoriah Waterland 3335c51f124SMoriah Waterland /* 3345c51f124SMoriah Waterland * These three defines indicate that the prototype file contains a '?' 3355c51f124SMoriah Waterland * meaning do not specify this data in the pkgmap entry. 3365c51f124SMoriah Waterland */ 3375c51f124SMoriah Waterland #define CURMODE BADMODE /* current mode has been specified */ 3385c51f124SMoriah Waterland #define CUROWNER BADOWNER /* ... same for owner ... */ 3395c51f124SMoriah Waterland #define CURGROUP BADGROUP /* ... and group. */ 3405c51f124SMoriah Waterland 3415c51f124SMoriah Waterland #define WILDCARD BADMODE >> 1 3425c51f124SMoriah Waterland #define DB_UNDEFINED_ENTRY "?" 3435c51f124SMoriah Waterland 3445c51f124SMoriah Waterland #define DEFAULT_MODE 0755 3455c51f124SMoriah Waterland #define DEFAULT_MODE_FILE 0644 3465c51f124SMoriah Waterland #define DEFAULT_OWNER "root" 3475c51f124SMoriah Waterland #define DEFAULT_GROUP "other" 3485c51f124SMoriah Waterland 3495c51f124SMoriah Waterland #define INST_RELEASE "var/sadm/system/admin/INST_RELEASE" 3505c51f124SMoriah Waterland 3515c51f124SMoriah Waterland #define RANDOM "/dev/urandom" 3525c51f124SMoriah Waterland #define BLOCK 256 3535c51f124SMoriah Waterland 3545c51f124SMoriah Waterland #define TERM_WIDTH 60 3555c51f124SMoriah Waterland #define SMALL_DIVISOR 4 3565c51f124SMoriah Waterland #define MED_DIVISOR 5 3575c51f124SMoriah Waterland #define LARGE_DIVISOR 10 3585c51f124SMoriah Waterland #define MED_DWNLD (10 * 1024 * 1024) /* 10 MB */ 3595c51f124SMoriah Waterland #define LARGE_DWNLD (5 * MED_DWNLD) /* 50 MB */ 3605c51f124SMoriah Waterland 3615c51f124SMoriah Waterland #define HTTP "http://" 3625c51f124SMoriah Waterland #define HTTPS "https://" 3635c51f124SMoriah Waterland 3645c51f124SMoriah Waterland #define PKGADD "pkgadd" 3655c51f124SMoriah Waterland 3665c51f124SMoriah Waterland /* Settings for network admin defaults */ 3675c51f124SMoriah Waterland 3685c51f124SMoriah Waterland #define NET_TIMEOUT_DEFAULT 60 3695c51f124SMoriah Waterland #define NET_RETRIES_DEFAULT 3 3705c51f124SMoriah Waterland #define NET_TIMEOUT_MIN 1 /* 1 second */ 3715c51f124SMoriah Waterland #define NET_TIMEOUT_MAX (5 * 60) /* 5 minutes */ 3725c51f124SMoriah Waterland #define NET_RETRIES_MIN 1 3735c51f124SMoriah Waterland #define NET_RETRIES_MAX 10 3745c51f124SMoriah Waterland #define AUTH_NOCHECK 0 3755c51f124SMoriah Waterland #define AUTH_QUIT 1 3765c51f124SMoriah Waterland 3775c51f124SMoriah Waterland /* package header magic tokens */ 3785c51f124SMoriah Waterland #define HDR_PREFIX "# PaCkAgE DaTaStReAm" 3795c51f124SMoriah Waterland #define HDR_SUFFIX "# end of header" 3805c51f124SMoriah Waterland 3815c51f124SMoriah Waterland /* name of security files */ 3825c51f124SMoriah Waterland #define PKGSEC "/var/sadm/security" 3835c51f124SMoriah Waterland #define SIGNATURE_FILENAME "signature" 3845c51f124SMoriah Waterland 3855c51f124SMoriah Waterland #define GROUP "/etc/group" 3865c51f124SMoriah Waterland #define PASSWD "/etc/passwd" 3875c51f124SMoriah Waterland 3885c51f124SMoriah Waterland /* 3895c51f124SMoriah Waterland * The next three mean that no mode, owner or group was specified or that the 3905c51f124SMoriah Waterland * one specified is invalid for some reason. Sometimes this is an error in 3915c51f124SMoriah Waterland * which case it is generally converted to CUR* with a warning. Other times 3925c51f124SMoriah Waterland * it means "look it up" by stating the existing file system object pointred 3935c51f124SMoriah Waterland * to in the prototype file. 3945c51f124SMoriah Waterland */ 3955c51f124SMoriah Waterland #define NOMODE (BADMODE-1) 3965c51f124SMoriah Waterland #define NOOWNER "@" 3975c51f124SMoriah Waterland #define NOGROUP "@" 3985c51f124SMoriah Waterland 3995c51f124SMoriah Waterland /* string comparitor abbreviators */ 4005c51f124SMoriah Waterland 4015c51f124SMoriah Waterland #define ci_streq(a, b) (strcasecmp((a), (b)) == 0) 4025c51f124SMoriah Waterland #define ci_strneq(a, b, c) (strncasecmp((a), (b), (c)) == 0) 4035c51f124SMoriah Waterland #define streq(a, b) (strcmp((a), (b)) == 0) 4045c51f124SMoriah Waterland #define strneq(a, b, c) (strncmp((a), (b), (c)) == 0) 4055c51f124SMoriah Waterland 4065c51f124SMoriah Waterland extern FILE *epopen(char *cmd, char *mode); 4075c51f124SMoriah Waterland extern char **gpkglist(char *dir, char **pkg, char **catg); 4085c51f124SMoriah Waterland extern int is_not_valid_length(char **category); 4095c51f124SMoriah Waterland extern int is_not_valid_category(char **category, char *progname); 4105c51f124SMoriah Waterland extern int is_same_CATEGORY(char **category, char *installed_category); 4115c51f124SMoriah Waterland extern char **get_categories(char *catg_arg); 4125c51f124SMoriah Waterland 4135c51f124SMoriah Waterland extern void pkglist_cont(char *keyword); 4145c51f124SMoriah Waterland extern char **pkgalias(char *pkg); 4155c51f124SMoriah Waterland extern char *get_prog_name(void); 4165c51f124SMoriah Waterland extern char *set_prog_name(char *name); 4175c51f124SMoriah Waterland extern int averify(int fix, char *ftype, char *path, struct ainfo *ainfo); 4185c51f124SMoriah Waterland extern int ckparam(char *param, char *value); 4195c51f124SMoriah Waterland extern int ckvolseq(char *dir, int part, int nparts); 4205c51f124SMoriah Waterland extern int cverify(int fix, char *ftype, char *path, struct cinfo *cinfo, 4215c51f124SMoriah Waterland int allow_checksum); 4225c51f124SMoriah Waterland extern unsigned long compute_checksum(int *r_cksumerr, char *a_path); 4235c51f124SMoriah Waterland extern int fverify(int fix, char *ftype, char *path, struct ainfo *ainfo, 4245c51f124SMoriah Waterland struct cinfo *cinfo); 4255c51f124SMoriah Waterland extern char *getErrbufAddr(void); 4265c51f124SMoriah Waterland extern int getErrbufSize(void); 4275c51f124SMoriah Waterland extern char *getErrstr(void); 4285c51f124SMoriah Waterland extern void setErrstr(char *errstr); 4295c51f124SMoriah Waterland extern int devtype(char *alias, struct pkgdev *devp); 4305c51f124SMoriah Waterland extern int ds_totread; /* total number of parts read */ 4315c51f124SMoriah Waterland extern int ds_close(int pkgendflg); 4325c51f124SMoriah Waterland extern int ds_findpkg(char *device, char *pkg); 4335c51f124SMoriah Waterland extern int ds_getinfo(char *string); 4345c51f124SMoriah Waterland extern int ds_getpkg(char *device, int n, char *dstdir); 4355c51f124SMoriah Waterland extern int ds_ginit(char *device); 4365c51f124SMoriah Waterland extern boolean_t ds_fd_open(void); 4375c51f124SMoriah Waterland extern int ds_init(char *device, char **pkg, char *norewind); 4385c51f124SMoriah Waterland extern int BIO_ds_dump_header(PKG_ERR *, BIO *); 4395c51f124SMoriah Waterland extern int BIO_ds_dump(PKG_ERR *, char *, BIO *); 4405c51f124SMoriah Waterland extern int BIO_dump_cmd(char *cmd, BIO *bio); 4415c51f124SMoriah Waterland extern int ds_next(char *, char *); 4425c51f124SMoriah Waterland extern int ds_readbuf(char *device); 4435c51f124SMoriah Waterland extern int epclose(FILE *pp); 4445c51f124SMoriah Waterland extern int esystem(char *cmd, int ifd, int ofd); 4455c51f124SMoriah Waterland extern int e_ExecCmdArray(int *r_status, char **r_results, 4465c51f124SMoriah Waterland char *a_inputFile, char *a_cmd, char **a_args); 4475c51f124SMoriah Waterland extern int e_ExecCmdList(int *r_status, char **r_results, 4485c51f124SMoriah Waterland char *a_inputFile, char *a_cmd, ...); 4495c51f124SMoriah Waterland extern int gpkgmap(struct cfent *ept, FILE *fp); 4505c51f124SMoriah Waterland extern int gpkgmapvfp(struct cfent *ept, VFP_T *fpv); 4515c51f124SMoriah Waterland extern void setmapmode(int mode_no); 4525c51f124SMoriah Waterland extern int isFdRemote(int a_fd); 4535c51f124SMoriah Waterland extern int isFstypeRemote(char *a_fstype); 4545c51f124SMoriah Waterland extern int isPathRemote(char *a_path); 4555c51f124SMoriah Waterland extern int iscpio(char *path, int *iscomp); 4565c51f124SMoriah Waterland extern int isdir(char *path); 4575c51f124SMoriah Waterland extern int isfile(char *dir, char *file); 4585c51f124SMoriah Waterland extern int fmkdir(char *a_path, int a_mode); 4595c51f124SMoriah Waterland extern int pkgexecl(char *filein, char *fileout, char *uname, char *gname, 4605c51f124SMoriah Waterland ...); 4615c51f124SMoriah Waterland extern int pkgexecv(char *filein, char *fileout, char *uname, char *gname, 4625c51f124SMoriah Waterland char *arg[]); 4635c51f124SMoriah Waterland extern int pkghead(char *device); 4645c51f124SMoriah Waterland extern int pkgmount(struct pkgdev *devp, char *pkg, int part, int nparts, 4655c51f124SMoriah Waterland int getvolflg); 4665c51f124SMoriah Waterland extern int pkgtrans(char *device1, char *device2, char **pkg, 4675c51f124SMoriah Waterland int options, keystore_handle_t, char *); 4685c51f124SMoriah Waterland extern int pkgumount(struct pkgdev *devp); 4695c51f124SMoriah Waterland extern int ppkgmap(struct cfent *ept, FILE *fp); 4705c51f124SMoriah Waterland extern int putcfile(struct cfent *ept, FILE *fp); 4715c51f124SMoriah Waterland extern int putcvfpfile(struct cfent *ept, VFP_T *vfp); 4725c51f124SMoriah Waterland extern int rrmdir(char *path); 4735c51f124SMoriah Waterland extern void set_memalloc_failure_func(void (*)(int)); 4745c51f124SMoriah Waterland extern void *xmalloc(size_t size); 4755c51f124SMoriah Waterland extern void *xrealloc(void *ptr, size_t size); 4765c51f124SMoriah Waterland extern char *xstrdup(char *str); 4775c51f124SMoriah Waterland extern void set_passphrase_prompt(char *); 4785c51f124SMoriah Waterland extern void set_passphrase_passarg(char *); 4795c51f124SMoriah Waterland extern int pkg_passphrase_cb(char *, int, int, void *); 4805c51f124SMoriah Waterland 48162224350SCasper H.S. Dik extern int srchcfile(struct cfent *ept, char *path, PKGserver server); 4825c51f124SMoriah Waterland extern struct group *cgrgid(gid_t gid); 4835c51f124SMoriah Waterland extern struct group *cgrnam(char *nam); 4845c51f124SMoriah Waterland extern struct passwd *cpwnam(char *nam); 4855c51f124SMoriah Waterland extern struct passwd *cpwuid(uid_t uid); 4865c51f124SMoriah Waterland extern struct group *clgrgid(gid_t gid); 4875c51f124SMoriah Waterland extern struct group *clgrnam(char *nam); 4885c51f124SMoriah Waterland extern struct passwd *clpwnam(char *nam); 4895c51f124SMoriah Waterland extern struct passwd *clpwuid(uid_t uid); 4905c51f124SMoriah Waterland extern void basepath(char *path, char *basedir, char *ir); 4915c51f124SMoriah Waterland extern void canonize(char *file); 4925c51f124SMoriah Waterland extern void canonize_slashes(char *file); 4935c51f124SMoriah Waterland extern void checksum_off(void); 4945c51f124SMoriah Waterland extern void checksum_on(void); 4955c51f124SMoriah Waterland extern void cvtpath(char *path, char *copy); 4965c51f124SMoriah Waterland extern void ds_order(char *list[]); 497*4656d474SGarrett D'Amore extern void ds_putinfo(char *buf, size_t); 4985c51f124SMoriah Waterland extern void ds_skiptoend(char *device); 4995c51f124SMoriah Waterland extern void ecleanup(void); 5005c51f124SMoriah Waterland /*PRINTFLIKE1*/ 5015c51f124SMoriah Waterland extern void logerr(char *fmt, ...); 5025c51f124SMoriah Waterland extern int mappath(int flag, char *path); 5035c51f124SMoriah Waterland extern int mapvar(int flag, char *varname); 5045c51f124SMoriah Waterland /*PRINTFLIKE1*/ 5055c51f124SMoriah Waterland extern void progerr(char *fmt, ...); 5065c51f124SMoriah Waterland extern void pkgerr(PKG_ERR *); 5075c51f124SMoriah Waterland extern void rpterr(void); 5085c51f124SMoriah Waterland extern void tputcfent(struct cfent *ept, FILE *fp); 5095c51f124SMoriah Waterland extern void set_nonABI_symlinks(void); 5105c51f124SMoriah Waterland extern int nonABI_symlinks(void); 5115c51f124SMoriah Waterland extern void disable_attribute_check(void); 5125c51f124SMoriah Waterland extern int get_disable_attribute_check(void); 5135c51f124SMoriah Waterland 5145c51f124SMoriah Waterland /* security.c */ 5155c51f124SMoriah Waterland extern void sec_init(void); 5165c51f124SMoriah Waterland extern char *get_subject_display_name(X509 *); 5175c51f124SMoriah Waterland extern char *get_issuer_display_name(X509 *); 5185c51f124SMoriah Waterland extern char *get_serial_num(X509 *); 5195c51f124SMoriah Waterland extern char *get_fingerprint(X509 *, const EVP_MD *); 5205c51f124SMoriah Waterland extern int get_cert_chain(PKG_ERR *, X509 *, STACK_OF(X509) *, 5215c51f124SMoriah Waterland STACK_OF(X509) *, STACK_OF(X509) **); 5225c51f124SMoriah Waterland 5235c51f124SMoriah Waterland /* pkgstr.c */ 5245c51f124SMoriah Waterland void pkgstrConvertUllToTimeString_r(unsigned long long a_time, 5255c51f124SMoriah Waterland char *a_buf, int a_bufLen); 5265c51f124SMoriah Waterland char *pkgstrConvertPathToBasename(char *a_path); 5275c51f124SMoriah Waterland char *pkgstrConvertPathToDirname(char *a_path); 5285c51f124SMoriah Waterland char *pkgstrDup(char *a_str); 5295c51f124SMoriah Waterland char *pkgstrLocatePathBasename(char *a_path); 5305c51f124SMoriah Waterland void pkgstrScaleNumericString(char *a_buf, unsigned long long scale); 5315c51f124SMoriah Waterland void pkgstrAddToken(char **a_old, char *a_new, char a_separator); 5325c51f124SMoriah Waterland boolean_t pkgstrContainsToken(char *a_string, char *a_token, 5335c51f124SMoriah Waterland char *a_separators); 5345c51f124SMoriah Waterland void pkgstrExpandTokens(char **a_old, char *a_string, 5355c51f124SMoriah Waterland char a_separator, char *a_separators); 5365c51f124SMoriah Waterland char *pkgstrGetToken(char *r_sep, char *a_string, int a_index, 5375c51f124SMoriah Waterland char *a_separators); 5385c51f124SMoriah Waterland void pkgstrGetToken_r(char *r_sep, char *a_string, int a_index, 5395c51f124SMoriah Waterland char *a_separators, char *a_buf, int a_bufLen); 5405c51f124SMoriah Waterland unsigned long pkgstrNumTokens(char *a_string, char *a_separators); 5415c51f124SMoriah Waterland char *pkgstrPrintf(char *a_format, ...); 5425c51f124SMoriah Waterland void pkgstrPrintf_r(char *a_buf, int a_bufLen, char *a_format, ...); 5435c51f124SMoriah Waterland void pkgstrRemoveToken(char **r_string, char *a_token, 5445c51f124SMoriah Waterland char *a_separators, int a_index); 5455c51f124SMoriah Waterland void pkgstrRemoveLeadingWhitespace(char **a_str); 5465c51f124SMoriah Waterland /* vfpops.c */ 5475c51f124SMoriah Waterland extern int vfpCheckpointFile(VFP_T **r_destVfp, VFP_T **a_vfp, 5485c51f124SMoriah Waterland char *a_path); 5495c51f124SMoriah Waterland extern int vfpCheckpointOpen(VFP_T **a_cvfp, VFP_T **r_vfp, char *a_path, 5505c51f124SMoriah Waterland char *a_mode, VFPFLAGS_T a_flags); 5515c51f124SMoriah Waterland extern int vfpClearModified(VFP_T *a_vfp); 5525c51f124SMoriah Waterland extern int vfpClose(VFP_T **r_vfp); 5535c51f124SMoriah Waterland extern int vfpGetModified(VFP_T *a_vfp); 5545c51f124SMoriah Waterland extern int vfpOpen(VFP_T **r_vfp, char *a_path, char *a_mode, 5555c51f124SMoriah Waterland VFPFLAGS_T a_flags); 5565c51f124SMoriah Waterland extern void vfpRewind(VFP_T *a_vfp); 5575c51f124SMoriah Waterland extern ssize_t vfpSafePwrite(int a_fildes, void *a_buf, 5585c51f124SMoriah Waterland size_t a_nbyte, off_t a_offset); 5595c51f124SMoriah Waterland extern ssize_t vfpSafeWrite(int a_fildes, void *a_buf, size_t a_nbyte); 5605c51f124SMoriah Waterland extern int vfpSetFlags(VFP_T *a_vfp, VFPFLAGS_T a_flags); 5615c51f124SMoriah Waterland extern int vfpSetModified(VFP_T *a_vfp); 5625c51f124SMoriah Waterland extern int vfpSetSize(VFP_T *a_vfp, size_t a_size); 5635c51f124SMoriah Waterland extern void vfpTruncate(VFP_T *a_vfp); 5645c51f124SMoriah Waterland extern int vfpWriteToFile(VFP_T *a_vfp, char *a_path); 5655c51f124SMoriah Waterland 5665c51f124SMoriah Waterland /* handlelocalfs.c */ 5675c51f124SMoriah Waterland boolean_t enable_local_fs(void); 5685c51f124SMoriah Waterland boolean_t restore_local_fs(void); 5695c51f124SMoriah Waterland 57062224350SCasper H.S. Dik /* pkgserv.c */ 57162224350SCasper H.S. Dik extern PKGserver pkgopenserver(const char *, const char *, boolean_t); 57262224350SCasper H.S. Dik extern void pkgcloseserver(PKGserver); 57362224350SCasper H.S. Dik extern int pkgcmd(PKGserver, void *, size_t, char **, size_t *, 57462224350SCasper H.S. Dik int *); 57562224350SCasper H.S. Dik extern boolean_t pkgsync_needed(const char *, const char *, boolean_t); 57662224350SCasper H.S. Dik extern int pkgsync(const char *, const char *, boolean_t); 57762224350SCasper H.S. Dik extern int pkgservercommitfile(VFP_T *, PKGserver); 57862224350SCasper H.S. Dik extern int pkgopenfilter(PKGserver server, const char *pkginst); 57962224350SCasper H.S. Dik extern void pkgclosefilter(PKGserver); 58062224350SCasper H.S. Dik extern char *pkggetentry(PKGserver, int *, int *); 58162224350SCasper H.S. Dik extern char *pkggetentry_named(PKGserver, const char *, int *, 58262224350SCasper H.S. Dik int *); 58362224350SCasper H.S. Dik extern void pkgserversetmode(start_mode_t); 58462224350SCasper H.S. Dik extern start_mode_t pkgservergetmode(void); 58562224350SCasper H.S. Dik extern start_mode_t pkgparsemode(const char *); 58662224350SCasper H.S. Dik extern char *pkgmodeargument(start_mode_t); 58762224350SCasper H.S. Dik 5885c51f124SMoriah Waterland #ifdef __cplusplus 5895c51f124SMoriah Waterland } 5905c51f124SMoriah Waterland #endif 5915c51f124SMoriah Waterland 5925c51f124SMoriah Waterland #endif /* _PKGLIB_H */ 593