Deleted Added
sdiff udiff text old ( 71579 ) new ( 90045 )
full compact
1/*
2 * Copyright (c) 1989, 1993, 1994
3 * The Regents of the University of California. All rights reserved.
4 *
5 * This code is derived from software contributed to Berkeley by
6 * Dave Borman at Cray Research, Inc.
7 *
8 * Redistribution and use in source and binary forms, with or without

--- 21 unchanged lines hidden (view full) ---

30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * SUCH DAMAGE.
35 */
36
37#if defined(LIBC_SCCS) && !defined(lint)
38#if 0
39static char sccsid[] = "@(#)setmode.c 8.2 (Berkeley) 3/25/94";
40#endif
41static const char rcsid[] =
42 "$FreeBSD: head/lib/libc/gen/setmode.c 71579 2001-01-24 13:01:12Z deischen $";
43#endif /* LIBC_SCCS and not lint */
44
45#include "namespace.h"
46#include <sys/types.h>
47#include <sys/stat.h>
48
49#include <ctype.h>
50#include <signal.h>
51#include <stddef.h>

--- 14 unchanged lines hidden (view full) ---

66} BITCMD;
67
68#define CMD2_CLR 0x01
69#define CMD2_SET 0x02
70#define CMD2_GBITS 0x04
71#define CMD2_OBITS 0x08
72#define CMD2_UBITS 0x10
73
74static BITCMD *addcmd __P((BITCMD *, int, int, int, u_int));
75static void compress_mode __P((BITCMD *));
76#ifdef SETMODE_DEBUG
77static void dumpmode __P((BITCMD *));
78#endif
79
80/*
81 * Given the old mode and an array of bitcmd structures, apply the operations
82 * described in the bitcmd structures to the old mode, and return the new mode.
83 * Note that there is no '=' command; a strict assignment is just a '-' (clear
84 * bits) followed by a '+' (set bits).
85 */
86mode_t
87getmode(bbox, omode)
88 void *bbox;
89 mode_t omode;
90{
91 register BITCMD *set;
92 register mode_t clrval, newmode, value;
93
94 set = (BITCMD *)bbox;
95 newmode = omode;
96 for (value = 0;; set++)
97 switch(set->cmd) {
98 /*
99 * When copying the user, group or other bits around, we "know"
100 * where the bits are in the mode so that we can do shifts to

--- 49 unchanged lines hidden (view full) ---

150 (void)printf("getmode:%04o -> %04o\n", omode, newmode);
151#endif
152 return (newmode);
153 }
154}
155
156#define ADDCMD(a, b, c, d) \
157 if (set >= endset) { \
158 register BITCMD *newset; \
159 setlen += SET_LEN_INCR; \
160 newset = realloc(saveset, sizeof(BITCMD) * setlen); \
161 if (!saveset) \
162 return (NULL); \
163 set = newset + (set - saveset); \
164 saveset = newset; \
165 endset = newset + (setlen - 2); \
166 } \
167 set = addcmd(set, (a), (b), (c), (d))
168
169#define STANDARD_BITS (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
170
171void *
172setmode(p)
173 register char *p;
174{
175 register int perm, who;
176 register char op;
177 BITCMD *set, *saveset, *endset;
178 sigset_t sigset, sigoset;
179 mode_t mask;
180 int equalopdone=0, permXbits, setlen;
181
182 if (!*p)
183 return (NULL);
184

--- 151 unchanged lines hidden (view full) ---

336 dumpmode(saveset);
337#endif
338 return (saveset);
339}
340
341static BITCMD *
342addcmd(set, op, who, oparg, mask)
343 BITCMD *set;
344 register int oparg, who;
345 register int op;
346 u_int mask;
347{
348 switch (op) {
349 case '=':
350 set->cmd = '-';
351 set->bits = who ? who : STANDARD_BITS;
352 set++;
353

--- 29 unchanged lines hidden (view full) ---

383 break;
384 }
385 return (set + 1);
386}
387
388#ifdef SETMODE_DEBUG
389static void
390dumpmode(set)
391 register BITCMD *set;
392{
393 for (; set->cmd; ++set)
394 (void)printf("cmd: '%c' bits %04o%s%s%s%s%s%s\n",
395 set->cmd, set->bits, set->cmd2 ? " cmd2:" : "",
396 set->cmd2 & CMD2_CLR ? " CLR" : "",
397 set->cmd2 & CMD2_SET ? " SET" : "",
398 set->cmd2 & CMD2_UBITS ? " UBITS" : "",
399 set->cmd2 & CMD2_GBITS ? " GBITS" : "",

--- 4 unchanged lines hidden (view full) ---

404/*
405 * Given an array of bitcmd structures, compress by compacting consecutive
406 * '+', '-' and 'X' commands into at most 3 commands, one of each. The 'u',
407 * 'g' and 'o' commands continue to be separate. They could probably be
408 * compacted, but it's not worth the effort.
409 */
410static void
411compress_mode(set)
412 register BITCMD *set;
413{
414 register BITCMD *nset;
415 register int setbits, clrbits, Xbits, op;
416
417 for (nset = set;;) {
418 /* Copy over any 'u', 'g' and 'o' commands. */
419 while ((op = nset->cmd) != '+' && op != '-' && op != 'X') {
420 *set++ = *nset++;
421 if (!op)
422 return;
423 }

--- 35 unchanged lines hidden ---