diff options
author | Richard Lowe <richlowe@richlowe.net> | 2018-01-24 20:09:53 +0000 |
---|---|---|
committer | Richard Lowe <richlowe@richlowe.net> | 2018-01-27 21:42:10 +0000 |
commit | 498924fdb0b10437ef130a81beee94e710d55a5b (patch) | |
tree | c95f522bf42326b290a8624b181053b23bc22940 | |
parent | 5c60adfb7915647f372e2ddb0c4b967d3d03f779 (diff) | |
download | illumos-joyent-498924fdb0b10437ef130a81beee94e710d55a5b.tar.gz |
8991 pmodes is useless and can be deleted
Reviewed by: Toomas Soome <tsoome@me.com>
Reviewed by: Peter Tribble <peter.tribble@gmail.com>
Reviewed by: Andy Fiddaman <omnios@citrus-it.co.uk>
Approved by: Dan McDonald <danmcd@joyent.com>
-rw-r--r-- | usr/src/pkg/manifests/developer-build-onbld.mf | 1 | ||||
-rw-r--r-- | usr/src/tools/Makefile | 1 | ||||
-rw-r--r-- | usr/src/tools/README.tools | 4 | ||||
-rw-r--r-- | usr/src/tools/pmodes/Makefile | 53 | ||||
-rw-r--r-- | usr/src/tools/pmodes/README.pmodes | 119 | ||||
-rw-r--r-- | usr/src/tools/pmodes/binsearch.c | 159 | ||||
-rw-r--r-- | usr/src/tools/pmodes/binsearch.h | 37 | ||||
-rw-r--r-- | usr/src/tools/pmodes/pmodes.c | 690 |
8 files changed, 0 insertions, 1064 deletions
diff --git a/usr/src/pkg/manifests/developer-build-onbld.mf b/usr/src/pkg/manifests/developer-build-onbld.mf index ed7db1bb3e..4aa075aaf9 100644 --- a/usr/src/pkg/manifests/developer-build-onbld.mf +++ b/usr/src/pkg/manifests/developer-build-onbld.mf @@ -81,7 +81,6 @@ file path=opt/onbld/bin/$(ARCH)/make mode=0555 $(i386_ONLY)file path=opt/onbld/bin/$(ARCH)/mbh_patch mode=0555 file path=opt/onbld/bin/$(ARCH)/ndrgen mode=0555 file path=opt/onbld/bin/$(ARCH)/ndrgen1 mode=0555 -file path=opt/onbld/bin/$(ARCH)/pmodes mode=0555 file path=opt/onbld/bin/$(ARCH)/protocmp mode=0555 file path=opt/onbld/bin/$(ARCH)/protolist mode=0555 $(sparc_ONLY)file path=opt/onbld/bin/$(ARCH)/stabs mode=0555 diff --git a/usr/src/tools/Makefile b/usr/src/tools/Makefile index faa8aa4705..1b726bd8bb 100644 --- a/usr/src/tools/Makefile +++ b/usr/src/tools/Makefile @@ -47,7 +47,6 @@ COMMON_SUBDIRS= \ make \ ndrgen \ onbld \ - pmodes \ protocmp \ protolist \ scripts diff --git a/usr/src/tools/README.tools b/usr/src/tools/README.tools index 4980bf0d2d..fe7f09a5f5 100644 --- a/usr/src/tools/README.tools +++ b/usr/src/tools/README.tools @@ -217,10 +217,6 @@ nightly env/developer and env/gatekeeper for sample, hopefully well-commented env files. -pmodes - enforces proper file ownership and permissions in pkgmap and package - prototype* files. converts files if necessary - protocmp compares proto lists and the package definitions. Used by nightly to determine if the proto area matches the packages, and to detect diff --git a/usr/src/tools/pmodes/Makefile b/usr/src/tools/pmodes/Makefile deleted file mode 100644 index 7f669bb433..0000000000 --- a/usr/src/tools/pmodes/Makefile +++ /dev/null @@ -1,53 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END - -# Copyright 2009 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# -# fastfs also lives in cmd/backup, but it's copied here since the backup -# hierarchy can still build some hsm packages, and the code doesn't change - -PROG= pmodes -OBJS= $(PROG).o binsearch.o -SRCS= $(OBJS:%.o=%.c) -CLEANFILES += $(OBJS) - -include ../Makefile.tools - -CFLAGS += $(CCVERBOSE) -CERRWARN += -_gcc=-Wno-parentheses -CERRWARN += -_gcc=-Wno-uninitialized - -.KEEP_STATE: - -all: $(PROG) - -$(PROG): $(OBJS) - $(LINK.c) -o $@ $(OBJS) $(LDLIBS) - $(POST_PROCESS) - -install: all .WAIT $(ROOTONBLDMACHPROG) - -lint: lint_SRCS - -clean: - $(RM) $(CLEANFILES) - -include ../Makefile.targ diff --git a/usr/src/tools/pmodes/README.pmodes b/usr/src/tools/pmodes/README.pmodes deleted file mode 100644 index da8152f1da..0000000000 --- a/usr/src/tools/pmodes/README.pmodes +++ /dev/null @@ -1,119 +0,0 @@ -# -# CDDL HEADER START -# -# The contents of this file are subject to the terms of the -# Common Development and Distribution License (the "License"). -# You may not use this file except in compliance with the License. -# -# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE -# or http://www.opensolaris.org/os/licensing. -# See the License for the specific language governing permissions -# and limitations under the License. -# -# When distributing Covered Code, include this CDDL HEADER in each -# file and include the License file at usr/src/OPENSOLARIS.LICENSE. -# If applicable, add the following below this CDDL HEADER, with the -# fields enclosed by brackets "[]" replaced with your own identifying -# information: Portions Copyright [yyyy] [name of copyright owner] -# -# CDDL HEADER END -# - -# -# Copyright 2010 Sun Microsystems, Inc. All rights reserved. -# Use is subject to license terms. -# - -Pmodes is a program that updates pkgmap files or pkg prototype files. - - - -Applicability: - -Use of pmodes has been deprecated in onnv-gate; instead, see -validate_pkg, as delivered by developer/build/onbld, and -exception_lists/pmodes. - -Other OSNet users (ie on10 patch gates and earlier) should use pmodes -from their own workspace. - -The information here is suitable for pmodes users in other -consolidations, using tools from onnv-tools. - - - -Usage: pmodes [-somwDeNndvqP] [-r file] directory .. proto/pkgmap file.... - - - -Options that modify what is changed: - - -s Strip read and write permissions from setgid/setuid executables. - -o Do not change ownership to root - -m Do not change file permissions (modes) - -w Do not strip owner write permissions from non-root owned - binaries - -e Do not change 'e' or 'v' (editable or volatile) files - (they are only affected when owned by bin) - -D Limit changes to directories only. - -Options that modify the output: - -n Create a <file>.new file - -N Overwrite the original pkgmap/proto file with the new file; - old pkgmap/proto file saved as file.old - -d Produce "diff-style" output - -P Ignore pkgmap files in directories. - -q Do not produce error messages about directories w/ pkginfo* - files - -v Preceed the output caused by each processed file by a - shortened version of the filename. - - -r file Restrict the test to the pathnames listed in "file" - - -In default mode of operation, pmodes processes each argument. -If an argument is a directory, it will first look for a pkginfo or -pkginfo.tmpl file n order to learn the BASEDIR; it will than process -the directory converting either the pkgmap file or, if the pkgmap file -doesn't exist or the -P option is specified, the prototype_* files -Names that contain .old or .new will be ignored. If an argument is a file, -the pkginfo* file in the same directory is used to learn the BASEDIR. - -Pmodes outputs a line for each change made: - -e m 0664 -> 0644 /var/adm/wtmpx -d m 0775 -> 0755 /usr/lib -d o bin -> root /usr/include/sys [755] -f o bin -> root /usr/include/sys/cg6reg.h [0644] -f o bin -> root /usr/include/sys/cg6var.h [0644] - -The first field is the "pkgmap" file type; the second field is the type -of modification (m for mode, o for ownership). This is followed by the -change mode and the pathname. - -When ownership is changed, the file permissions are printed in square -brackets. - -Multiple lines of output can be produced for a single file. - -With the -d option, output looks like: - -< d 0775 root sys /usr -> d 0755 root sys /usr -< d 0775 root bin /usr/include -> d 0755 root bin /usr/include -< d 1777 bin bin /var/preserve -> d 1777 root bin /var/preserve -< e 0664 root sys /etc/vfstab -> e 0644 root sys /etc/vfstab - -And only one line per file is produced. - - - -Exceptions - -If pmodes insists on flagging errors that you believe must be -integrated as-is, you may update the inline initializers for either -exceptions or exempt_pkgs in pmodes.c. If you do this, make sure that -the bug report and your RTI include a justification for the exception. diff --git a/usr/src/tools/pmodes/binsearch.c b/usr/src/tools/pmodes/binsearch.c deleted file mode 100644 index 4b704e594b..0000000000 --- a/usr/src/tools/pmodes/binsearch.c +++ /dev/null @@ -1,159 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright (c) 2000-2001 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -/* - * String list maintenance and binary search routines - */ - - -#include <stdlib.h> -#include <stdio.h> -#include <string.h> - -#define ALLOCCHUNK 128 - -struct itemlist { - char **items; - int nallocated; - int nused; - int sorted; -}; - -#include "binsearch.h" - -itemlist -new_itemlist(void) -{ - itemlist x = malloc(sizeof (struct itemlist)); - - x->nallocated = x->nused = 0; - x->sorted = 1; - x->items = 0; - - return (x); -} - -void -item_add(itemlist l, char *s) -{ - if (l->nallocated < 0) { - char **new; - l->nallocated = l->nused + ALLOCCHUNK; - new = malloc(sizeof (char *) * l->nused); - memcpy(new, l->items, l->nused * sizeof (char *)); - l->items = new; - } else if (l->nallocated == l->nused) { - if (l->nallocated) - l->nallocated *= 2; - else - l->nallocated = ALLOCCHUNK; - l->items = realloc(l->items, sizeof (char *) * l->nallocated); - } - l->items[l->nused++] = s; - l->sorted = l->nused <= 1; -} - -void -item_add_list(itemlist l, char **s, int n, int alloc) -{ - if (l->nallocated == 0) { - l->items = s; - l->nallocated = alloc ? n : -1; - l->nused = n; - l->sorted = 0; - } else { - int i; - - for (i = 0; i < n; i++) - item_add(l, s[i]); - - if (alloc) - free(s); - } -} - -int -item_addfile(itemlist l, const char *fname) -{ - FILE *f = fopen(fname, "r"); - char buf[10240]; - - if (f == NULL) - return (-1); - - while (fgets(buf, sizeof (buf), f) != NULL) { - if (buf[0] == '#' || buf[0] == '\n') - continue; - - buf[strlen(buf)-1] = '\0'; - item_add(l, strdup(buf)); - } - fclose(f); - - return (0); -} - -static int -xcmp(const void *s1, const void *s2) -{ - return (strcmp(*(char **)s1, *(char **)s2)); -} - -int -item_search(itemlist l, const char *s) -{ - int lo = 0; - int hi = l->nused - 1; - - if (!l->sorted) { - qsort(l->items, l->nused, sizeof (char *), xcmp); - l->sorted = 1; - } - - while (lo <= hi) { - int mid = (lo + hi) / 2; - int res = strcmp(s, l->items[mid]); - - if (res == 0) - return (mid); - else if (res < 0) - hi = mid - 1; - else - lo = mid + 1; - } - return (-1); -} - -char -*item_get(itemlist l, int i) -{ - if (i >= l->nused || i < 0) - return (NULL); - else - return (l->items[i]); -} diff --git a/usr/src/tools/pmodes/binsearch.h b/usr/src/tools/pmodes/binsearch.h deleted file mode 100644 index 691efe47f3..0000000000 --- a/usr/src/tools/pmodes/binsearch.h +++ /dev/null @@ -1,37 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License, Version 1.0 only - * (the "License"). You may not use this file except in compliance - * with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ -/* - * Copyright (c) 2000-2001 by Sun Microsystems, Inc. - * All rights reserved. - */ - -#pragma ident "%Z%%M% %I% %E% SMI" - -typedef struct itemlist *itemlist; - -itemlist new_itemlist(void); - -void item_add_list(itemlist, char **, int, int); -void item_add(itemlist, char *); -int item_addfile(itemlist, const char *); -int item_search(itemlist, const char *); -char *item_get(itemlist, int); diff --git a/usr/src/tools/pmodes/pmodes.c b/usr/src/tools/pmodes/pmodes.c deleted file mode 100644 index 6a83865f40..0000000000 --- a/usr/src/tools/pmodes/pmodes.c +++ /dev/null @@ -1,690 +0,0 @@ -/* - * CDDL HEADER START - * - * The contents of this file are subject to the terms of the - * Common Development and Distribution License (the "License"). - * You may not use this file except in compliance with the License. - * - * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE - * or http://www.opensolaris.org/os/licensing. - * See the License for the specific language governing permissions - * and limitations under the License. - * - * When distributing Covered Code, include this CDDL HEADER in each - * file and include the License file at usr/src/OPENSOLARIS.LICENSE. - * If applicable, add the following below this CDDL HEADER, with the - * fields enclosed by brackets "[]" replaced with your own identifying - * information: Portions Copyright [yyyy] [name of copyright owner] - * - * CDDL HEADER END - */ - -/* - * Copyright 2010 Sun Microsystems, Inc. All rights reserved. - * Use is subject to license terms. - * - * $Id: pmodes.c,v 1.23 1999/03/22 14:51:16 casper Exp $ - * - * - * Program to list files from packages with modes that are to - * permissive. Usage: - * - * pmodes [options] pkgdir ... - * - * Pmodes currently has 4 types of modes that are changed: - * - * m remove group/other write permissions of all files, - * except those in the exceptions list. - * w remove user write permission for executables that - * are not root owned. - * s remove g/o read permission for set-uid/set-gid executables - * o change the owner of files/directories that can be safely - * chowned to root. - * - * Any combination of changes can be switched of by specifying -X - * - * The -n option will create a "FILE.new" file for all changed - * pkgmap/prototype files. - * The -D option will limit changes to directories only. - * - * output: - * - * d m oldmode -> newmode pathname - * | ^ whether the file/dir is group writable or even world writable - * > type of file. - * d o owner -> newowner pathname [mode] - * - * - * Casper Dik (Casper.Dik@Holland.Sun.COM) - */ - -#include <stdio.h> -#include <unistd.h> -#include <string.h> -#include <ctype.h> -#include <dirent.h> -#include <stdlib.h> -#include <errno.h> -#include <sys/param.h> -#include <sys/stat.h> -#include "binsearch.h" - -static char *exceptions[] = { - "/etc/lp", - "/var/cache/cups", -}; - -static char *exempt_pkgs[] = { - "SUNWSMSdf", /* "data files" package for SMS */ - "SUNWSMSr", /* "root" package for SMS */ - "SUNWSMSsu", /* "user" package for SMS */ - "SUNWnethackr", /* "root" package for nethack */ -}; - -#define NEXEMPT (sizeof (exempt_pkgs) / sizeof (char *)) - -#define PROTO "prototype_" - -#define DEFAULT_SU 0 -#define DEFAULT_OWNER 1 -#define DEFAULT_MODES 1 -#define DEFAULT_USERWRITE 1 -#define DEFAULT_DIRSONLY 0 -#define DEFAULT_EDITABLE 1 - -static int nexceptions = sizeof (exceptions)/sizeof (char *); -static int dosu = DEFAULT_SU; -static int doowner = DEFAULT_OWNER; -static int domodes = DEFAULT_MODES; -static int douserwrite = DEFAULT_USERWRITE; -static int dirsonly = DEFAULT_DIRSONLY; -static int editable = DEFAULT_EDITABLE; -static int makenew = 0; -static int installnew = 0; -static int diffout = 0; -static int proto = 0; -static int verbose = 0; -static int quiet = 0; -static int errors = 0; - -static void update_map(char *, char *, int); - -static char *program; - -itemlist restrictto = NULL; - -static void -usage(void) { - (void) fprintf(stderr, - "Usage: %s [-DowsnNmdePvq] [-r file] pkgdir ...\n", program); - exit(1); -} - -int -main(int argc, char **argv) -{ - char buf[8192]; - int c; - extern int optind, opterr; - - opterr = 0; - - program = argv[0]; - - while ((c = getopt(argc, argv, "eDowsnNmdPvqr:")) != EOF) { - switch (c) { - case 's': dosu = !DEFAULT_SU; break; - case 'o': doowner = !DEFAULT_OWNER; break; - case 'm': domodes = !DEFAULT_MODES; break; - case 'w': douserwrite = !DEFAULT_USERWRITE; break; - case 'D': dirsonly = !DEFAULT_DIRSONLY; break; - case 'e': editable = !DEFAULT_EDITABLE; break; - case 'N': installnew = 1; /* FALLTHROUGH */ - case 'n': makenew = 1; break; - case 'd': diffout = 1; break; - case 'P': proto = 1; break; - case 'v': verbose = 1; break; - case 'q': quiet = 1; break; - case 'r': - if (restrictto == NULL) - restrictto = new_itemlist(); - if (item_addfile(restrictto, optarg) != 0) { - perror(optarg); - exit(1); - } - break; - default: - case '?': usage(); break; - } - } - argc -= optind; - argv += optind; - - if (argc < 1) - usage(); - - for (; *argv; argv++) { - FILE *info; - char name[MAXPATHLEN]; - char basedir[MAXPATHLEN] = "/"; - int basedir_len; - struct stat stb; - int isfile = 0; - boolean_t exempt = B_FALSE; - - /* - * If a plain file is passed on the command line, we assume - * it's a prototype or pkgmap file and try to find the matching - * pkginfo file - */ - if (lstat(*argv, &stb) == 0 && S_ISREG(stb.st_mode)) { - char *lastslash = strrchr(*argv, '/'); - - if (lastslash != NULL) - *lastslash = '\0'; - (void) sprintf(name, "%s/pkginfo", *argv); - if (lastslash != NULL) - *lastslash = '/'; - isfile = 1; - } else - (void) sprintf(name, "%s/pkginfo", *argv); - - /* if there's no pkginfo file, it could be a prototype area */ - - if (access(name, R_OK) != 0) - (void) strcat(name, ".tmpl"); - - info = fopen(name, "r"); - if (info == 0) { - if (!quiet) - (void) fprintf(stderr, - "Can't open pkginfo file %s\n", name); - continue; - } - - while (fgets(buf, sizeof (buf), info) != NULL && !exempt) { - if (strncmp(buf, "BASEDIR=", 8) == 0) { - (void) strcpy(basedir, buf+8); - basedir[strlen(basedir)-1] = '\0'; - } else if (strncmp(buf, "PKG=", 4) == 0) { - int i; - char *str; - - str = buf + sizeof ("PKG=") - 1; - str[strlen(str)-1] = '\0'; - if (str[0] == '"') - str++; - if (str[strlen(str)-1] == '"') - str[strlen(str)-1] = '\0'; - for (i = 0; i < NEXEMPT; i++) { - if (strcmp(exempt_pkgs[i], str) == 0) { - exempt = B_TRUE; - break; - } - } - } - } - - (void) fclose(info); - - /* exempt package */ - if (exempt) - continue; - - basedir_len = strlen(basedir); - if (basedir_len != 1) - basedir[basedir_len++] = '/'; - - (void) sprintf(name, "%s/pkgmap", *argv); - if (isfile) - update_map(*argv, basedir, basedir_len); - else if (!proto && access(name, R_OK) == 0) - update_map(name, basedir, basedir_len); - else { - DIR *d = opendir(*argv); - struct dirent *de; - - if (d == NULL) { - (void) fprintf(stderr, - "Can't read directory \"%s\"\n", *argv); - continue; - } - while (de = readdir(d)) { - /* Skip files with .old or .new suffix */ - if (strstr(de->d_name, PROTO) != NULL && - strncmp(de->d_name, ".del-", 5) != 0 && - strstr(de->d_name, ".old") == NULL && - strstr(de->d_name, ".new") == NULL) { - (void) sprintf(name, "%s/%s", *argv, - de->d_name); - update_map(name, basedir, basedir_len); - } - } - (void) closedir(d); - } - } - return (errors != 0); -} - -#define NEXTWORD(tmp, end, warnme) \ - do { \ - tmp = strpbrk(tmp, "\t ");\ - if (!tmp) {\ - if (warnme)\ - warn(name, lineno);\ - return (LINE_IGNORE);\ - }\ - end = tmp++;\ - while (*tmp && isspace(*tmp)) tmp++;\ - } while (0) - -static void -warn(const char *file, int line) -{ - (void) fprintf(stderr, "pmodes: %s, line %d: unexpected format\n", - file, line); -} - -struct parsed_line { - char *start; /* buffer start */ - char *rest; /* buffer after owner */ - char *owner; /* same size as ut_user */ - char *old_owner; /* same size as ut_user */ - char group[16]; /* whatever */ - int modelen; /* number of mode bytes (3 or 4); */ - int mode; /* the complete file mode */ - char path[MAXPATHLEN]; /* NUL terminated pathname */ - char type; /* */ - char realtype; /* */ -}; - -#define LINE_OK 0 -#define LINE_IGNORE 1 -#define LINE_ERROR 2 - -static void -put_line(FILE *f, struct parsed_line *line) -{ - if (f != NULL) - if (line->rest) - (void) fprintf(f, "%s%.*o %s %s", line->start, - line->modelen, line->mode, line->owner, line->rest); - else - (void) fputs(line->start, f); -} - -/* - * the first field is the path, the second the type, the - * third the class, the fourth the mode, when appropriate. - * We're interested in - * f (file) - * e (edited file) - * v (volatile file) - * d (directory) - * c (character devices) - * b (block devices) - */ - -static int -parse_line(struct parsed_line *parse, char *buf, const char *name, int lineno) -{ - char *tmp; - char *p = buf; - char *end, *q; - - parse->start = buf; - parse->rest = 0; /* makes put_line work */ - - /* Trim trailing spaces */ - end = buf + strlen(buf); - while (end > buf+1 && isspace(end[-2])) { - end -= 1; - end[-1] = end[0]; - end[0] = '\0'; - } - - while (*p && isspace(*p)) - p++; - - if (*p == '#' || *p == ':' || *p == '\0') - return (LINE_IGNORE); - - /* - * Special directives; we really should follow the include - * directives but we certainly need to look at default - */ - if (*p == '!') { - p++; - while (*p && isspace(*p)) - p++; - - if (!*p || *p == '\n') - return (LINE_IGNORE); - - if (strncmp(p, "default", 7) == 0) { - NEXTWORD(p, end, 1); - parse->type = 'f'; - parse->realtype = 'D'; - strcpy(parse->path, "(default)"); - tmp = p; - NEXTWORD(p, end, 1); - goto domode; - } else if (strncmp(p, "include", 7) == 0) { - NEXTWORD(p, end, 1); - if (strstr(p, PROTO) == NULL) - fprintf(stderr, "including file %s", p); - } - return (LINE_IGNORE); - } - - /* - * Parse the pkgmap line: - * [<number>] <type> <class> <path> [<major> <minor>] - * [ <mode> <owner> <group> .... ] - */ - - /* Skip first column for non-prototype (i.e., pkgmap) files */ - if (isdigit(*p)) - NEXTWORD(p, end, 1); - - parse->realtype = parse->type = *p; - - switch (parse->type) { - case 'i': case 's': case 'l': - return (LINE_IGNORE); - } - - NEXTWORD(p, end, 1); - - /* skip class */ - NEXTWORD(p, end, 1); - - /* - * p now points to pathname - * At this point, we could have no mode because we are - * using a default. - */ - tmp = p; - NEXTWORD(p, end, 0); - - /* end points to space after name */ - (void) strncpy(parse->path, tmp, end - tmp); - parse->path[end - tmp] = '\0'; - - switch (parse->type) { - case 'e': - case 'v': - /* type 'e' and 'v' are files, just like 'f', use 'f' in out */ - parse->type = 'f'; - /* FALLTHROUGH */ - case 'f': - case 'd': - case 'p': /* FIFO - assume mode is sensible, don't treat as file */ - break; - - case 'x': /* Exclusive directory */ - parse->type = 'd'; - break; - - /* device files have class major minor, skip */ - case 'c': - case 'b': - NEXTWORD(p, end, 1); NEXTWORD(p, end, 1); - break; - - default: - (void) fprintf(stderr, "Unknown type '%c', %s:%d\n", - parse->type, name, lineno); - return (LINE_ERROR); - } - tmp = p; - NEXTWORD(p, end, 1); - -domode: - /* - * the mode is either a 4 digit number (file is sticky/set-uid or - * set-gid or the mode has a leading 0) or a three digit number - * mode has all the mode bits, mode points to the three least - * significant bit so fthe mode - */ - parse->mode = 0; - for (q = tmp; q < end; q++) { - if (!isdigit(*q) || *q > '7') { - (void) fprintf(stderr, - "Warning: Unparseble mode \"%.*s\" at %s:%d\n", - end-tmp, tmp, name, lineno); - return (LINE_IGNORE); - } - parse->mode <<= 3; - parse->mode += *q - '0'; - } - parse->modelen = end - tmp; - tmp[0] = '\0'; - - parse->old_owner = parse->owner = p; - - NEXTWORD(p, end, 1); - - parse->rest = end+1; - *end = '\0'; - - (void) memset(parse->group, 0, sizeof (parse->group)); - (void) strncpy(parse->group, end+1, strcspn(end+1, " \t\n")); - - return (LINE_OK); -} - -static void -update_map(char *name, char *basedir, int basedir_len) -{ - char buf[8192]; - int i; - FILE *map, *newmap; - char newname[MAXPATHLEN]; - int nchanges = 0; - unsigned int lineno = 0; - struct parsed_line line; - char *fname; - - map = fopen(name, "r"); - if (map == 0) { - (void) fprintf(stderr, "Can't open \"%s\"\n", name); - return; - } - (void) strcpy(newname, name); - (void) strcat(newname, ".new"); - if (makenew) { - newmap = fopen(newname, "w"); - if (newmap == 0) - (void) fprintf(stderr, "Can't open %s for writing\n", - name); - } else - newmap = 0; - - /* Get last one or two components non-trivial of pathname */ - if (verbose) { - char *tmp = name + strlen(name); - int cnt = 0, first = 0; - - while (--tmp > name && cnt < 2) { - if (*tmp == '/') { - if (++cnt == 1) - first = tmp - name; - else { - fname = tmp + 1; - /* Triviality check */ - if (tmp - name > first - 4) - cnt--; - } - } - } - if (cnt < 2) - fname = name; - } - - nchanges = 0; - - for (; fgets(buf, sizeof (buf), map) != 0; put_line(newmap, &line)) { - - int root_owner, mode_diff = 0; - int changed = 0; - - lineno ++; - - switch (parse_line(&line, buf, name, lineno)) { - case LINE_IGNORE: - continue; - case LINE_ERROR: - errors++; - continue; - } - - if (restrictto) { - char nbuf[MAXPATHLEN]; - snprintf(nbuf, sizeof (nbuf), "%.*s%s", basedir_len, - basedir, line.path); - - if (item_search(restrictto, nbuf) == -1) - continue; - } - - if (dirsonly && line.type != 'd') - continue; - - root_owner = strcmp(line.owner, "root") == 0; - if (dosu && line.type == 'f' && (line.mode & (S_ISUID|S_ISGID))) - mode_diff = line.mode & (S_IRGRP|S_IROTH); - - /* - * The following heuristics are used to determine whether a file - * can be safely chown'ed to root: - * - it's not set-uid. - * and one of the following applies: - * - it's not writable by the current owner and is - * group/world readable - * - it's world executable and a file - * - owner, group and world permissions are identical - * - it's a bin owned directory or a "non-volatile" - * file (any owner) for which group and other r-x - * permissions are identical, or it's a bin owned - * executable or it's a /etc/security/dev/ device - */ - - if (doowner && !(line.mode & S_ISUID) && - !root_owner && - ((!(line.mode & S_IWUSR) && - (line.mode&(S_IRGRP|S_IROTH)) == (S_IRGRP|S_IROTH)) || - (line.type == 'f' && (line.mode & S_IXOTH)) || - ((line.mode & 07) == ((line.mode>>3) & 07) && - (line.mode & 07) == ((line.mode>>6) & 07) && - strcmp(line.owner, "uucp") != 0) || - ((line.type == 'd' && strcmp(line.owner, "bin") == 0 || - (editable && strcmp(line.owner, "bin") == 0 ? - line.type : line.realtype) == 'f') && - ((line.mode & 05) == ((line.mode>>3) & 05) || - (line.mode & 0100) && - strcmp(line.owner, "bin") == 0) && - ((line.mode & 0105) != 0 || - basedir_len < 18 && - strncmp(basedir, "/etc/security/dev/", - basedir_len) == 0 && - strncmp(line.path, "/etc/security/dev/" - + basedir_len, 18 - basedir_len) == 0)))) { - if (!diffout) { - if (!changed && verbose && !nchanges) - (void) printf("%s:\n", fname); - (void) printf("%c o %s -> root %s%s [%.*o]\n", - line.realtype, line.owner, basedir, - line.path, line.modelen, line.mode); - } - line.owner = "root"; - root_owner = 1; - changed = 1; - } - /* - * Strip user write bit if owner != root and executable by user. - * root can write even if no write bits set - * Could prevent executables from being overwritten. - */ - if (douserwrite && line.type == 'f' && !root_owner && - (line.mode & (S_IWUSR|S_IXUSR)) == (S_IWUSR|S_IXUSR)) - mode_diff |= S_IWUSR; - - - if (domodes && (line.mode & (S_IWGRP|S_IWOTH)) != 0 && - (line.mode & S_ISVTX) == 0) { - if (basedir_len <= 1) { /* root dir */ - for (i = 0; i < nexceptions; i++) { - if (strcmp(line.path, - exceptions[i]+basedir_len) == 0) - break; - } - } else { - for (i = 0; i < nexceptions; i++) { - if (strncmp(basedir, exceptions[i], - basedir_len) == 0 && - strcmp(line.path, - exceptions[i]+basedir_len) == 0) - break; - } - } - if (i == nexceptions) - mode_diff |= line.mode & (S_IWGRP|S_IWOTH); - } - - if (mode_diff) { - int oldmode = line.mode; - - line.mode &= ~mode_diff; - - if (line.mode != oldmode) { - if (!diffout) { - if (!changed && verbose && !nchanges) - (void) printf("%s:\n", fname); - printf("%c %c %04o -> %04o %s%s\n", - line.realtype, - (mode_diff & (S_IRGRP|S_IROTH)) ? - 's' : 'm', - oldmode, line.mode, basedir, - line.path); - } - changed = 1; - } - } - nchanges += changed; - if (diffout && changed) { - if (nchanges == 1 && verbose) - (void) printf("%s:\n", fname); - - (void) printf("< %c %04o %s %s %s%s\n", line.realtype, - line.mode | mode_diff, line.old_owner, line.group, - basedir, line.path); - (void) printf("> %c %04o %s %s %s%s\n", line.realtype, - line.mode, line.owner, line.group, basedir, - line.path); - } - } - (void) fclose(map); - - if (newmap != NULL) { - (void) fflush(newmap); - if (ferror(newmap)) { - (void) fprintf(stderr, "Error writing %s\n", name); - return; - } - (void) fclose(newmap); - if (nchanges == 0) - (void) unlink(newname); - else if (installnew) { - char oldname[MAXPATHLEN]; - - (void) strcpy(oldname, name); - (void) strcat(oldname, ".old"); - if (rename(name, oldname) == -1 || - rename(newname, name) == -1) - (void) fprintf(stderr, - "Couldn't install %s: %s\n", - newname, strerror(errno)); - } - } -} |