/*
* 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
* 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 2004 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
/* Copyright (c) 1983, 1984, 1985, 1986, 1987, 1988, 1989 AT&T */
/* All Rights Reserved */
/*
* Portions of this source code were derived from Berkeley 4.3 BSD
* under license from the Regents of the University of California.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
/*
* Use of this object by a utility (so far chmod, mkdir and mkfifo use
* it) requires that the utility implement an error-processing routine
* named errmsg(), with a prototype as specified below.
*
* This is necessary because the mode-parsing code here makes use of such
* a routine, located in chmod.c. The error-reporting style of the
* utilities sharing this code differs enough that it is difficult to
* implement a common version of this routine to be used by all.
*/
/*
* Note that many convolutions are necessary
* due to the re-use of bits between locking
* and setgid
*/
#include <ctype.h>
#include <stdio.h>
#include <dirent.h>
#include <locale.h>
#include <string.h> /* strerror() */
#include <stdarg.h>
#define WHO_EMPTY 0
static char *msp;
extern void
static int
what(void);
static mode_t
who(void);
/*
* Wrapper for newmode_common. This function is called by mkdir and
* mkfifo.
*/
{
}
/*
* We are parsing a comma-separated list of mode expressions of the form:
*
* [<who>] <op> [<perms>]
*/
/* ARGSUSED */
{
/*
* new_mode contains the mode value constructed by parsing the
* expression pointed to by ms
* old_mode contains the mode provided by the caller
* oper contains +|-|= information
* perms_msk contains rwx(slt) information
* umsk contains the umask value to be assumed.
* who_empty is non-zero if the <who> clause did not appear.
* who_msk contains USER|GROUP|OTHER information
*/
int lcheck;
int scheck;
int xcheck;
int goon;
int operand_empty = 0;
int who_empty;
*group_clear_bits = 0;
*group_set_bits = 0;
do {
/*
* When <who> is empty, and <oper> == `=`, the umask is
* obeyed. So we need to make note of it here, for use
* later.
*/
who_empty = 1;
} else {
who_empty = 0;
}
/*
* this section processes permissions
*/
perms_msk = 0;
goon = 0;
switch (*msp) {
case 'u':
goto dup;
case 'g':
goto dup;
case 'o':
dup:
(perms_msk << 6);
msp++;
goon = 1;
}
while (goon == 0) {
switch (*msp++) {
case 'r':
continue;
case 'w':
continue;
case 'x':
xcheck = 1;
continue;
case 'X':
xcheck = 1;
}
continue;
case 'l':
lcheck = 1;
continue;
case 's':
scheck = 1;
continue;
case 't':
continue;
default:
msp--;
goon = 1;
}
}
switch (oper) {
case '+':
if (who_empty) {
}
/* is group execution requested? */
if (xcheck == 1 &&
/* not locking, too! */
gettext("Group execution "
"and locking not permitted "
"together\n"));
}
/*
* not if the file is already
* lockable.
*/
errmsg(2, 0,
gettext("%s: Group "
"execution not permitted "
"on a lockable file\n"),
path);
return (old_mode);
}
}
/* is setgid on execution requested? */
/* not locking, too! */
if (lcheck == 1 &&
gettext("Set-group-ID and "
"locking not permitted "
"together\n"));
}
/*
* not if the file is already
* lockable
*/
errmsg(2, 0,
gettext("%s: Set-group-ID "
"not permitted on a "
"lockable file\n"), path);
return (old_mode);
}
}
/* is setid on execution requested? */
if ((scheck == 1) &&
/*
* the corresponding execution must
* be requested or already set
*/
errmsg(2, 0,
gettext("%s: Execute "
"permission required "
"for set-ID on "
"execution \n"),
path);
return (old_mode);
}
}
/* is locking requested? */
if (lcheck == 1) {
/*
* not if the file has group execution
* set.
* NOTE: this also covers files with
* setgid
*/
errmsg(2, 0,
gettext("%s: Locking not "
"permitted on "
"a group executable "
"file\n"),
path);
return (old_mode);
}
}
!= 0) {
*group_clear_bits &= ~grp_change;
*group_set_bits |= grp_change;
}
/* create new mode */
break;
case '-':
if (who_empty) {
}
/* don't turn off locking, unless it's on */
LOCK) {
}
/* don't turn off setgid, unless it's on */
if (scheck == 1 &&
lcheck == 0 &&
LOCK) {
}
/*
* if execution is being turned off and the
* corresponding setid is not, turn setid off,
* too & warn the user
*/
errmsg(2, 0,
gettext("%s: Corresponding set-ID "
"also disabled on file since "
"set-ID requires execute "
"permission\n"),
path);
}
}
}
!= 0) {
*group_set_bits &= ~grp_change;
}
/* create new mode */
break;
case '=':
if (who_empty) {
}
/* is locking requested? */
if (lcheck == 1) {
/* not group execution, too! */
gettext("Group execution "
"and locking not "
"permitted together\n"));
}
/*
* if the file has group execution set,
* turn it off!
*/
}
}
/*
* is setid on execution requested? the
* corresponding execution must be requested,
* too!
*/
if (scheck == 1 &&
gettext("Execute permission "
"required for set-ID on "
"execution\n"));
}
/*
* The ISGID bit on directories will not be
* changed when the mode argument is a string
* with "=".
*/
/*
* create new mode:
* clear the who_msk bits
* set the perms_mks bits (which have
* been trimmed to fit the who_msk.
*/
!= 0) {
}
break;
}
}
} while (*msp++ == ',');
if (*--msp || operand_empty == 0) {
}
return (new_mode);
}
{
int c;
mode_t i;
if (*msp)
/*
* The ISGID bit on directories will not be changed when the mode argument is
* octal numeric. Only "g+s" and "g-s" arguments can change ISGID bit when
* applied to directories.
*/
return (i);
}
static mode_t
who(void)
{
mode_t m;
m = WHO_EMPTY;
for (; ; msp++) {
switch (*msp) {
case 'u':
m |= USER;
continue;
case 'g':
m |= GROUP;
continue;
case 'o':
m |= OTHER;
continue;
case 'a':
m |= ALL;
continue;
default:
return (m);
}
}
}
static int
what(void)
{
switch (*msp) {
case '+':
case '-':
case '=':
return (*msp++);
}
return (0);
}