17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5f1f71133Sbustos * Common Development and Distribution License (the "License"). 6f1f71133Sbustos * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 217c478bd9Sstevel@tonic-gate /* 22*9444c26fSTom Whitten * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 237c478bd9Sstevel@tonic-gate * Use is subject to license terms. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #include <sys/types.h> 287c478bd9Sstevel@tonic-gate 29*9444c26fSTom Whitten #include <errno.h> 30*9444c26fSTom Whitten #include <fcntl.h> 317c478bd9Sstevel@tonic-gate #include <libintl.h> 327c478bd9Sstevel@tonic-gate #include <libuutil.h> 337c478bd9Sstevel@tonic-gate #include <locale.h> 347c478bd9Sstevel@tonic-gate #include <stdio.h> 357c478bd9Sstevel@tonic-gate #include <stdlib.h> 367c478bd9Sstevel@tonic-gate #include <string.h> 37*9444c26fSTom Whitten #include <sys/stat.h> 387c478bd9Sstevel@tonic-gate #include <unistd.h> 397c478bd9Sstevel@tonic-gate 40*9444c26fSTom Whitten #include "manifest_find.h" 417c478bd9Sstevel@tonic-gate #include "manifest_hash.h" 427c478bd9Sstevel@tonic-gate 437c478bd9Sstevel@tonic-gate #define MAX_DEPTH 24 447c478bd9Sstevel@tonic-gate 457c478bd9Sstevel@tonic-gate /* 467c478bd9Sstevel@tonic-gate * mfstscan - service manifest change detection utility 477c478bd9Sstevel@tonic-gate * 487c478bd9Sstevel@tonic-gate * mfstscan walks the given filesystem hierarchies, and reports those manifests 497c478bd9Sstevel@tonic-gate * with changed or absent hash entries. Manifests are expected to end with a 507c478bd9Sstevel@tonic-gate * .xml suffix--other files will be ignored. 517c478bd9Sstevel@tonic-gate */ 527c478bd9Sstevel@tonic-gate 537c478bd9Sstevel@tonic-gate static void 547c478bd9Sstevel@tonic-gate usage() 557c478bd9Sstevel@tonic-gate { 567c478bd9Sstevel@tonic-gate (void) fprintf(stderr, gettext("Usage: %s [-t] path ...\n"), 577c478bd9Sstevel@tonic-gate uu_getpname()); 587c478bd9Sstevel@tonic-gate exit(UU_EXIT_USAGE); 597c478bd9Sstevel@tonic-gate } 607c478bd9Sstevel@tonic-gate 617c478bd9Sstevel@tonic-gate int 627c478bd9Sstevel@tonic-gate main(int argc, char *argv[]) 637c478bd9Sstevel@tonic-gate { 64*9444c26fSTom Whitten manifest_info_t **entry; 65*9444c26fSTom Whitten manifest_info_t **manifests; 667c478bd9Sstevel@tonic-gate int i; 677c478bd9Sstevel@tonic-gate int paths_walked = 0; 687c478bd9Sstevel@tonic-gate struct stat sb; 69*9444c26fSTom Whitten int status; 70*9444c26fSTom Whitten int tflag = 0; 717c478bd9Sstevel@tonic-gate 727c478bd9Sstevel@tonic-gate (void) uu_setpname(argv[0]); 737c478bd9Sstevel@tonic-gate 747c478bd9Sstevel@tonic-gate while ((i = getopt(argc, argv, "t")) != -1) { 757c478bd9Sstevel@tonic-gate switch (i) { 767c478bd9Sstevel@tonic-gate case 't': 777c478bd9Sstevel@tonic-gate tflag = 1; 787c478bd9Sstevel@tonic-gate paths_walked = 1; 797c478bd9Sstevel@tonic-gate break; 807c478bd9Sstevel@tonic-gate case '?': 817c478bd9Sstevel@tonic-gate default: 827c478bd9Sstevel@tonic-gate usage(); 837c478bd9Sstevel@tonic-gate /*NOTREACHED*/ 847c478bd9Sstevel@tonic-gate } 857c478bd9Sstevel@tonic-gate } 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate if (optind >= argc) 887c478bd9Sstevel@tonic-gate usage(); 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate for (i = optind; i < argc; i++) { 917c478bd9Sstevel@tonic-gate if (tflag) { 9270cbfe41SPhilippe Jung char *pname = mhash_filename_to_propname(argv[i], 9370cbfe41SPhilippe Jung B_FALSE); 94f1f71133Sbustos 95f1f71133Sbustos if (pname != NULL) 96f1f71133Sbustos (void) puts(pname); 97f1f71133Sbustos else 98f1f71133Sbustos uu_warn(gettext("cannot resolve pathname " 99f1f71133Sbustos "for %s"), argv[i]); 100f1f71133Sbustos 1017c478bd9Sstevel@tonic-gate continue; 1027c478bd9Sstevel@tonic-gate } 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate if (stat(argv[i], &sb) == -1) { 1057c478bd9Sstevel@tonic-gate uu_warn(gettext("cannot stat %s"), argv[i]); 1067c478bd9Sstevel@tonic-gate continue; 1077c478bd9Sstevel@tonic-gate } 1087c478bd9Sstevel@tonic-gate 109*9444c26fSTom Whitten status = find_manifests(argv[i], &manifests, 110*9444c26fSTom Whitten CHECKHASH|CHECKEXT); 111*9444c26fSTom Whitten if (status < 0) { 1127c478bd9Sstevel@tonic-gate uu_warn(gettext("file tree walk of %s encountered " 113*9444c26fSTom Whitten "error. %s\n"), argv[i], strerror(errno)); 114*9444c26fSTom Whitten } else { 1157c478bd9Sstevel@tonic-gate paths_walked++; 116*9444c26fSTom Whitten if (manifests != NULL) { 117*9444c26fSTom Whitten for (entry = manifests; 118*9444c26fSTom Whitten *entry != NULL; 119*9444c26fSTom Whitten entry++) { 120*9444c26fSTom Whitten (void) printf("%s\n", 121*9444c26fSTom Whitten (*entry)->mi_path); 122*9444c26fSTom Whitten } 123*9444c26fSTom Whitten free_manifest_array(manifests); 124*9444c26fSTom Whitten } 1257c478bd9Sstevel@tonic-gate } 1267c478bd9Sstevel@tonic-gate 127*9444c26fSTom Whitten } 1287c478bd9Sstevel@tonic-gate 1297c478bd9Sstevel@tonic-gate if (!paths_walked) 1307c478bd9Sstevel@tonic-gate uu_die(gettext("no paths walked\n")); 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate return (0); 1337c478bd9Sstevel@tonic-gate } 134