diff options
author | Michael Shalayeff <mickey@cvs.openbsd.org> | 2000-07-19 19:42:32 +0000 |
---|---|---|
committer | Michael Shalayeff <mickey@cvs.openbsd.org> | 2000-07-19 19:42:32 +0000 |
commit | 223860911bdaec08dc45b31c6efdd13689e487b0 (patch) | |
tree | f9c8df7ec6ad992561660bf7d42fad531cd58d47 /bin/chmod | |
parent | 5c663300c636c3cdd3eab7cf719fc9dc3cb594b1 (diff) |
merge chflags(1) into chmod.
also, use new strtofflags, avoid ls/stat_flags.c usage.
millert@ ok
Diffstat (limited to 'bin/chmod')
-rw-r--r-- | bin/chmod/Makefile | 5 | ||||
-rw-r--r-- | bin/chmod/chflags.1 | 159 | ||||
-rw-r--r-- | bin/chmod/chmod.c | 55 |
3 files changed, 206 insertions, 13 deletions
diff --git a/bin/chmod/Makefile b/bin/chmod/Makefile index 3f84da3861e..193e47d658b 100644 --- a/bin/chmod/Makefile +++ b/bin/chmod/Makefile @@ -1,8 +1,8 @@ -# $OpenBSD: Makefile,v 1.5 2000/06/10 20:51:53 deraadt Exp $ +# $OpenBSD: Makefile,v 1.6 2000/07/19 19:42:31 mickey Exp $ PROG= chmod CFLAGS+=-DSUPPORT_DOT -MAN= chmod.1 chgrp.1 chown.8 +MAN= chmod.1 chgrp.1 chown.8 chflags.1 LINKS= ${BINDIR}/chmod ${BINDIR}/chgrp \ ${BINDIR}/chmod /sbin/chown @@ -10,5 +10,6 @@ LINKS= ${BINDIR}/chmod ${BINDIR}/chgrp \ afterinstall: ln -fs /sbin/chown ${DESTDIR}/usr/sbin/chown ln -fs ${BINDIR}/chgrp ${DESTDIR}/usr/sbin/chgrp + ln -fs ${BINDIR}/chmod ${DESTDIR}/usr/bin/chflags .include <bsd.prog.mk> diff --git a/bin/chmod/chflags.1 b/bin/chmod/chflags.1 new file mode 100644 index 00000000000..89e27dea94a --- /dev/null +++ b/bin/chmod/chflags.1 @@ -0,0 +1,159 @@ +.\" $OpenBSD: chflags.1,v 1.1 2000/07/19 19:42:31 mickey Exp $ +.\" $NetBSD: chflags.1,v 1.4 1995/08/31 22:50:22 jtc Exp $ +.\" +.\" Copyright (c) 1989, 1990, 1993, 1994 +.\" The Regents of the University of California. All rights reserved. +.\" +.\" This code is derived from software contributed to Berkeley by +.\" the Institute of Electrical and Electronics Engineers, Inc. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by the University of +.\" California, Berkeley and its contributors. +.\" 4. Neither the name of the University nor the names of its contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" @(#)chflags.1 8.4 (Berkeley) 5/2/95 +.\" +.Dd May 2, 1995 +.Dt CHFLAGS 1 +.Os +.Sh NAME +.Nm chflags +.Nd change file flags +.Sh SYNOPSIS +.Nm chflags +.Oo +.Fl R +.Op Fl H | Fl L | Fl P +.Oc +.Ar flags +.Ar file Op Ar ... +.Sh DESCRIPTION +The +.Nm +utility modifies the file flags of the listed files +as specified by the +.Ar flags +operand. +The +.Ar flags +of a file dictate special restrictions beyond those enforced by its +mode/permissions. +.Pp +The options are as follows: +.Bl -tag -width Ds +.It Fl R +Recursively descend through any specified directory arguments. +Change the flags of the file hierarchies rooted +in the files instead of just the files themselves. +.It Fl H +If the +.Fl R +option is also specified, symbolic links on the command line are followed. +(Symbolic links encountered in the tree traversal are not followed.) +.It Fl L +If the +.Fl R +option is also specified, all symbolic links are followed. +.It Fl P +If the +.Fl R +option is also specified, no symbolic links are followed. +.El +.Pp +Flags are a comma separated list of keywords. +The following keywords are currently defined: +.Bd -literal -offset indent compact +arch set the archived flag +opaque set the opaque flag (owner or superuser only) +nodump set the nodump flag (owner or superuser only) +sappnd set the system append-only flag (superuser only) +schg set the system immutable flag (superuser only) +uappnd set the user append-only flag (owner or superuser only) +uchg set the user immutable flag (owner or superuser only) +.Ed +.Pp +An immutable file may not be changed, moved, or deleted. +An append-only file is immutable except that data may be appended to it. +.Pp +Putting the letters +.Dq no +before a flag name causes the flag to be turned off. +For example: +.Bd -literal -offset indent compact +nouchg the immutable bit should be cleared +.Ed +.Pp +The +superuser-settable +.Dq sappnd +and +.Dq schg +flags can be set at any time, but may only be cleared when the system is +running at security level 0 or -1 (insecure or permanently insecure mode, +respectively). +The securelevel is normally set to 0, for example, when +running in single-user mode. +.Pp +Symbolic links do not have flags, so unless the +.Fl H +or +.Fl L +option is set, +.Nm +on a symbolic link always succeeds and has no effect. +The +.Fl H , +.Fl L +and +.Fl P +options are ignored unless the +.Fl R +option is specified. +In addition, these options override each other and the +command's actions are determined by the last one specified. +.Pp +Only the superuser can change the user flags on block and +character devices. +.Pp +You can use +.Ic ls -lo +to see the flags of existing files. +.Pp +The +.Nm +utility exits 0 on success or >0 if an error occurred. +.Sh SEE ALSO +.Xr ls 1 , +.Xr chflags 2 , +.Xr stat 2 , +.Xr fts 3 , +.Xr symlink 7 +.Sh HISTORY +The +.Nm +command first appeared in +.Bx 4.4 . diff --git a/bin/chmod/chmod.c b/bin/chmod/chmod.c index 7b0031cd8f7..310657e0c55 100644 --- a/bin/chmod/chmod.c +++ b/bin/chmod/chmod.c @@ -1,4 +1,4 @@ -/* $OpenBSD: chmod.c,v 1.10 2000/06/30 16:00:03 millert Exp $ */ +/* $OpenBSD: chmod.c,v 1.11 2000/07/19 19:42:31 mickey Exp $ */ /* $NetBSD: chmod.c,v 1.12 1995/03/21 09:02:09 cgd Exp $ */ /* @@ -44,7 +44,7 @@ static char copyright[] = #if 0 static char sccsid[] = "@(#)chmod.c 8.8 (Berkeley) 4/1/94"; #else -static char rcsid[] = "$OpenBSD: chmod.c,v 1.10 2000/06/30 16:00:03 millert Exp $"; +static char rcsid[] = "$OpenBSD: chmod.c,v 1.11 2000/07/19 19:42:31 mickey Exp $"; #endif #endif /* not lint */ @@ -63,7 +63,7 @@ static char rcsid[] = "$OpenBSD: chmod.c,v 1.10 2000/06/30 16:00:03 millert Exp #include <limits.h> #include <locale.h> -int ischown, ischgrp, ischmod; +int ischflags, ischown, ischgrp, ischmod; extern char *__progname; gid_t a_gid __P((const char *)); @@ -83,7 +83,8 @@ main(argc, argv) int Hflag, Lflag, Pflag, Rflag, ch, fflag, fts_options, hflag, rval; uid_t uid; gid_t gid; - char *ep, *mode, *cp; + u_int32_t fclear, fset; + char *ep, *mode, *cp, *flags; #ifdef lint set = NULL; oct = omode = 0; @@ -94,6 +95,7 @@ main(argc, argv) ischown = __progname[2] == 'o'; ischgrp = __progname[2] == 'g'; ischmod = __progname[2] == 'm'; + ischflags = __progname[2] == 'f'; uid = -1; gid = -1; @@ -165,7 +167,26 @@ done: argv += optind; } } - if (ischmod) { + if (ischflags) { + flags = *argv; + if (*flags >= '0' && *flags <= '7') { + errno = 0; + val = strtoul(flags, &ep, 8); + if (val > UINT_MAX) + errno = ERANGE; + if (errno) + err(1, "invalid flags: %s", flags); + if (*ep) + errx(1, "invalid flags: %s", flags); + fset = val; + oct = 1; + } else { + if (strtofflags(&flags, &fset, &fclear)) + errx(1, "invalid flag: %s", flags); + fclear = ~fclear; + oct = 0; + } + } else if (ischmod) { mode = *argv; if (*mode >= '0' && *mode <= '7') { errno = 0; @@ -230,16 +251,28 @@ done: argv += optind; * don't point to anything and ones that we found * doing a physical walk. */ - if (ischmod || !hflag) + if (ischflags || ischmod || !hflag) continue; default: break; } - if (ischmod && chmod(p->fts_accpath, oct ? omode : + if (ischflags) { + if (oct) { + if (!chflags(p->fts_accpath, fset)) + continue; + } else { + p->fts_statp->st_flags |= fset; + p->fts_statp->st_flags &= fclear; + if (!chflags(p->fts_accpath, p->fts_statp->st_flags)) + continue; + } + warn("%s", p->fts_path); + rval = 1; + } else if (ischmod && chmod(p->fts_accpath, oct ? omode : getmode(set, p->fts_statp->st_mode)) && !fflag) { warn("%s", p->fts_path); rval = 1; - } else if (!ischmod && + } else if (!ischmod && !ischflags && (hflag ? lchown(p->fts_accpath, uid, gid) : chown(p->fts_accpath, uid, gid)) && !fflag) { warn("%s", p->fts_path); @@ -298,10 +331,10 @@ a_gid(s) void usage() { - if (ischmod) + if (ischmod || ischflags) fprintf(stderr, - "usage: %s [-R [-H | -L | -P]] mode file ...\n", - __progname); + "usage: %s [-R [-H | -L | -P]] %s file ...\n", + __progname, (ischmod? "mode" : "flags")); else fprintf(stderr, "usage: %s [-R [-H | -L | -P]] [-f] [-h] %s file ...\n", |