Deleted Added
full compact
setmode.c (71579) setmode.c (90045)
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)
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";
38static 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 */
39#endif /* LIBC_SCCS and not lint */
40#include <sys/cdefs.h>
41__FBSDID("$FreeBSD: head/lib/libc/gen/setmode.c 90045 2002-02-01 01:32:19Z obrien $");
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
42
43#include "namespace.h"
44#include <sys/types.h>
45#include <sys/stat.h>
46
47#include <ctype.h>
48#include <signal.h>
49#include <stddef.h>

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

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

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

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

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

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

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

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

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

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

--- 35 unchanged lines hidden ---