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 /* 23*62224350SCasper H.S. Dik * 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 315c51f124SMoriah Waterland #include <stdio.h> 325c51f124SMoriah Waterland #include <errno.h> 335c51f124SMoriah Waterland #include <string.h> 345c51f124SMoriah Waterland #include <limits.h> 355c51f124SMoriah Waterland #include <stdlib.h> 365c51f124SMoriah Waterland #include <unistd.h> 375c51f124SMoriah Waterland #include <sys/types.h> 385c51f124SMoriah Waterland #include <pkgstrct.h> 395c51f124SMoriah Waterland #include <locale.h> 405c51f124SMoriah Waterland #include <libintl.h> 415c51f124SMoriah Waterland #include <pkglib.h> 425c51f124SMoriah Waterland #include "install.h" 435c51f124SMoriah Waterland #include "libinst.h" 445c51f124SMoriah Waterland #include "libadm.h" 455c51f124SMoriah Waterland 465c51f124SMoriah Waterland extern struct cfextra **extlist; 475c51f124SMoriah Waterland extern struct cfent **eptlist; 485c51f124SMoriah Waterland 495c51f124SMoriah Waterland extern char *pkginst; 505c51f124SMoriah Waterland 515c51f124SMoriah Waterland #define ERR_WRITE "write of intermediate contents file failed" 525c51f124SMoriah Waterland 535c51f124SMoriah Waterland static char *check_db_entry(VFP_T *, struct cfextra *, int, char *, int *); 545c51f124SMoriah Waterland 555c51f124SMoriah Waterland /*ARGSUSED*/ 565c51f124SMoriah Waterland int 57*62224350SCasper H.S. Dik dofinal(PKGserver server, VFP_T *vfpo, int rmflag, char *myclass, char *prog) 585c51f124SMoriah Waterland { 595c51f124SMoriah Waterland struct cfextra entry; 605c51f124SMoriah Waterland int n, indx, dbchg; 615c51f124SMoriah Waterland char *save_path = NULL; 625c51f124SMoriah Waterland 635c51f124SMoriah Waterland entry.cf_ent.pinfo = NULL; 645c51f124SMoriah Waterland entry.fsys_value = BADFSYS; 655c51f124SMoriah Waterland entry.fsys_base = BADFSYS; 665c51f124SMoriah Waterland indx = 0; 675c51f124SMoriah Waterland 685c51f124SMoriah Waterland while (extlist && extlist[indx] && (extlist[indx]->cf_ent.ftype == 'i')) 695c51f124SMoriah Waterland indx++; 705c51f124SMoriah Waterland 715c51f124SMoriah Waterland dbchg = 0; 725c51f124SMoriah Waterland 73*62224350SCasper H.S. Dik if (pkgopenfilter(server, pkginst) != 0) 74*62224350SCasper H.S. Dik quit(99); 75*62224350SCasper H.S. Dik 76*62224350SCasper H.S. Dik while (n = srchcfile(&(entry.cf_ent), "*", server)) { 775c51f124SMoriah Waterland if (n < 0) { 785c51f124SMoriah Waterland char *errstr = getErrstr(); 79*62224350SCasper H.S. Dik progerr(gettext("bad entry read in contents file")); 805c51f124SMoriah Waterland logerr(gettext("pathname=%s"), 81*62224350SCasper H.S. Dik (entry.cf_ent.path && *(entry.cf_ent.path)) ? 825c51f124SMoriah Waterland entry.cf_ent.path : "Unknown"); 835c51f124SMoriah Waterland logerr(gettext("problem=%s"), 84*62224350SCasper H.S. Dik (errstr && *errstr) ? errstr : "Unknown"); 855c51f124SMoriah Waterland quit(99); 865c51f124SMoriah Waterland } 87*62224350SCasper H.S. Dik save_path = check_db_entry(vfpo, &entry, rmflag, myclass, 88*62224350SCasper H.S. Dik &dbchg); 895c51f124SMoriah Waterland 905c51f124SMoriah Waterland /* Restore original server-relative path, if needed */ 915c51f124SMoriah Waterland if (save_path != NULL) { 925c51f124SMoriah Waterland entry.cf_ent.path = save_path; 935c51f124SMoriah Waterland save_path = NULL; 945c51f124SMoriah Waterland } 955c51f124SMoriah Waterland } 965c51f124SMoriah Waterland 97*62224350SCasper H.S. Dik pkgclosefilter(server); 98*62224350SCasper H.S. Dik 995c51f124SMoriah Waterland return (dbchg); 1005c51f124SMoriah Waterland } 1015c51f124SMoriah Waterland 1025c51f124SMoriah Waterland static char * 1035c51f124SMoriah Waterland check_db_entry(VFP_T *vfpo, struct cfextra *entry, int rmflag, char *myclass, 1045c51f124SMoriah Waterland int *dbchg) 1055c51f124SMoriah Waterland { 1065c51f124SMoriah Waterland struct pinfo *pinfo; 1075c51f124SMoriah Waterland int fs_entry; 1085c51f124SMoriah Waterland char *save_path = NULL; 1095c51f124SMoriah Waterland char *tp; 1105c51f124SMoriah Waterland 1115c51f124SMoriah Waterland if (myclass && strcmp(myclass, entry->cf_ent.pkg_class)) { 112*62224350SCasper H.S. Dik /* 113*62224350SCasper H.S. Dik * We already have it in the database we don't want 114*62224350SCasper H.S. Dik * to modify it. 115*62224350SCasper H.S. Dik */ 1165c51f124SMoriah Waterland return (NULL); 1175c51f124SMoriah Waterland } 1185c51f124SMoriah Waterland 1195c51f124SMoriah Waterland /* 1205c51f124SMoriah Waterland * Now scan each package instance holding this file or 1215c51f124SMoriah Waterland * directory and see if it matches the package we are 1225c51f124SMoriah Waterland * updating here. 1235c51f124SMoriah Waterland */ 1245c51f124SMoriah Waterland pinfo = entry->cf_ent.pinfo; 1255c51f124SMoriah Waterland while (pinfo) { 1265c51f124SMoriah Waterland if (strcmp(pkginst, pinfo->pkg) == 0) 1275c51f124SMoriah Waterland break; 1285c51f124SMoriah Waterland pinfo = pinfo->next; 1295c51f124SMoriah Waterland } 1305c51f124SMoriah Waterland 1315c51f124SMoriah Waterland /* 1325c51f124SMoriah Waterland * If pinfo == NULL at this point, then this file or 1335c51f124SMoriah Waterland * directory isn't part of the package of interest. 134*62224350SCasper H.S. Dik * So the code below executes only on files in the package 1355c51f124SMoriah Waterland * of interest. 1365c51f124SMoriah Waterland */ 1375c51f124SMoriah Waterland 138*62224350SCasper H.S. Dik if (pinfo == NULL) 139*62224350SCasper H.S. Dik return (NULL); 1405c51f124SMoriah Waterland 1415c51f124SMoriah Waterland if (rmflag && (pinfo->status == RM_RDY)) { 1425c51f124SMoriah Waterland *dbchg = 1; 1435c51f124SMoriah Waterland 1445c51f124SMoriah Waterland (void) eptstat(&(entry->cf_ent), pkginst, '@'); 1455c51f124SMoriah Waterland 1465c51f124SMoriah Waterland if (entry->cf_ent.npkgs) { 1475c51f124SMoriah Waterland if (putcvfpfile(&(entry->cf_ent), vfpo)) { 1485c51f124SMoriah Waterland progerr(gettext(ERR_WRITE)); 1495c51f124SMoriah Waterland quit(99); 1505c51f124SMoriah Waterland } 151*62224350SCasper H.S. Dik } else if (entry->cf_ent.path != NULL) { 152*62224350SCasper H.S. Dik (void) vfpSetModified(vfpo); 153*62224350SCasper H.S. Dik /* add "-<path>" to the file */ 154*62224350SCasper H.S. Dik vfpPutc(vfpo, '-'); 155*62224350SCasper H.S. Dik vfpPuts(vfpo, entry->cf_ent.path); 156*62224350SCasper H.S. Dik vfpPutc(vfpo, '\n'); 1575c51f124SMoriah Waterland } 1585c51f124SMoriah Waterland return (NULL); 1595c51f124SMoriah Waterland 1605c51f124SMoriah Waterland } else if (!rmflag && (pinfo->status == INST_RDY)) { 1615c51f124SMoriah Waterland *dbchg = 1; 1625c51f124SMoriah Waterland 1635c51f124SMoriah Waterland /* tp is the server-relative path */ 1645c51f124SMoriah Waterland tp = fixpath(entry->cf_ent.path); 1655c51f124SMoriah Waterland /* save_path is the cmd line path */ 1665c51f124SMoriah Waterland save_path = entry->cf_ent.path; 1675c51f124SMoriah Waterland /* entry has the server-relative path */ 1685c51f124SMoriah Waterland entry->cf_ent.path = tp; 1695c51f124SMoriah Waterland 1705c51f124SMoriah Waterland /* 1715c51f124SMoriah Waterland * The next if statement figures out how 1725c51f124SMoriah Waterland * the contents file entry should be 1735c51f124SMoriah Waterland * annotated. 1745c51f124SMoriah Waterland * 1755c51f124SMoriah Waterland * Don't install or verify objects for 1765c51f124SMoriah Waterland * remote, read-only filesystems. We 1775c51f124SMoriah Waterland * need only verify their presence and 1785c51f124SMoriah Waterland * flag them appropriately from some 1795c51f124SMoriah Waterland * server. Otherwise, ok to do final 1805c51f124SMoriah Waterland * check. 1815c51f124SMoriah Waterland */ 1825c51f124SMoriah Waterland fs_entry = fsys(entry->cf_ent.path); 1835c51f124SMoriah Waterland 184*62224350SCasper H.S. Dik if (is_remote_fs_n(fs_entry) && !is_fs_writeable_n(fs_entry)) { 1855c51f124SMoriah Waterland /* 1865c51f124SMoriah Waterland * Mark it shared whether it's present 1875c51f124SMoriah Waterland * or not. life's too funny for me 1885c51f124SMoriah Waterland * to explain. 1895c51f124SMoriah Waterland */ 1905c51f124SMoriah Waterland pinfo->status = SERVED_FILE; 1915c51f124SMoriah Waterland 1925c51f124SMoriah Waterland /* 1935c51f124SMoriah Waterland * restore for now. This may 1945c51f124SMoriah Waterland * chg soon. 1955c51f124SMoriah Waterland */ 1965c51f124SMoriah Waterland entry->cf_ent.path = save_path; 1975c51f124SMoriah Waterland } else { 1985c51f124SMoriah Waterland /* 1995c51f124SMoriah Waterland * If the object is accessible, check 2005c51f124SMoriah Waterland * the new entry for existence and 2015c51f124SMoriah Waterland * attributes. If there's a problem, 2025c51f124SMoriah Waterland * mark it NOT_FND; otherwise, 2035c51f124SMoriah Waterland * ENTRY_OK. 2045c51f124SMoriah Waterland */ 2055c51f124SMoriah Waterland if (is_mounted_n(fs_entry)) { 2065c51f124SMoriah Waterland int n; 2075c51f124SMoriah Waterland 208*62224350SCasper H.S. Dik n = finalck((&entry->cf_ent), 1, 1, B_FALSE); 2095c51f124SMoriah Waterland 2105c51f124SMoriah Waterland pinfo->status = ENTRY_OK; 2115c51f124SMoriah Waterland if (n != 0) { 2125c51f124SMoriah Waterland pinfo->status = NOT_FND; 2135c51f124SMoriah Waterland } 2145c51f124SMoriah Waterland } 2155c51f124SMoriah Waterland 2165c51f124SMoriah Waterland /* 2175c51f124SMoriah Waterland * It's not remote, read-only but it 2185c51f124SMoriah Waterland * may look that way to the client. 2195c51f124SMoriah Waterland * If it does, overwrite the above 2205c51f124SMoriah Waterland * result - mark it shared. 2215c51f124SMoriah Waterland */ 2225c51f124SMoriah Waterland if (is_served_n(fs_entry)) 2235c51f124SMoriah Waterland pinfo->status = SERVED_FILE; 2245c51f124SMoriah Waterland 2255c51f124SMoriah Waterland /* restore original path */ 2265c51f124SMoriah Waterland entry->cf_ent.path = save_path; 2275c51f124SMoriah Waterland /* and clear save_path */ 2285c51f124SMoriah Waterland save_path = NULL; 2295c51f124SMoriah Waterland } 2305c51f124SMoriah Waterland } 2315c51f124SMoriah Waterland 2325c51f124SMoriah Waterland /* Output entry to contents file. */ 2335c51f124SMoriah Waterland if (putcvfpfile(&(entry->cf_ent), vfpo)) { 2345c51f124SMoriah Waterland progerr(gettext(ERR_WRITE)); 2355c51f124SMoriah Waterland quit(99); 2365c51f124SMoriah Waterland } 2375c51f124SMoriah Waterland 2385c51f124SMoriah Waterland return (save_path); 2395c51f124SMoriah Waterland } 240