]> git.saurik.com Git - apple/libc.git/blob - gen/FreeBSD/setmode.c.patch
Libc-763.12.tar.gz
[apple/libc.git] / gen / FreeBSD / setmode.c.patch
1 --- setmode.c.orig 2009-11-08 14:13:46.000000000 -0800
2 +++ setmode.c 2009-11-08 14:13:39.000000000 -0800
3 @@ -66,12 +66,15 @@ typedef struct bitcmd {
4 #define CMD2_OBITS 0x08
5 #define CMD2_UBITS 0x10
6
7 +#define compress_mode _sm_compress_mode
8 +
9 static BITCMD *addcmd(BITCMD *, int, int, int, u_int);
10 -static void compress_mode(BITCMD *);
11 +__private_extern__ void compress_mode(BITCMD *);
12 #ifdef SETMODE_DEBUG
13 static void dumpmode(BITCMD *);
14 #endif
15
16 +#ifndef BUILDING_VARIANT
17 /*
18 * Given the old mode and an array of bitcmd structures, apply the operations
19 * described in the bitcmd structures to the old mode, and return the new mode.
20 @@ -145,6 +148,7 @@ common: if (set->cmd2 & CMD2_CLR) {
21 return (newmode);
22 }
23 }
24 +#endif /* BUILDING_VARIANT */
25
26 #define ADDCMD(a, b, c, d) \
27 if (set >= endset) { \
28 @@ -163,7 +167,11 @@ common: if (set->cmd2 & CMD2_CLR) {
29 } \
30 set = addcmd(set, (a), (b), (c), (d))
31
32 +#ifndef VARIANT_LEGACY
33 +#define STANDARD_BITS (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO|S_ISTXT)
34 +#else /* VARIANT_LEGACY */
35 #define STANDARD_BITS (S_ISUID|S_ISGID|S_IRWXU|S_IRWXG|S_IRWXO)
36 +#endif /* !VARIANT_LEGACY */
37
38 void *
39 setmode(const char *p)
40 @@ -204,12 +212,21 @@ setmode(const char *p)
41 */
42 if (isdigit((unsigned char)*p)) {
43 perml = strtol(p, &ep, 8);
44 - if (*ep || perml < 0 || perml & ~(STANDARD_BITS|S_ISTXT)) {
45 +#ifndef VARIANT_LEGACY
46 + if (*ep || perml < 0 || perml & ~STANDARD_BITS)
47 +#else /* VARIANT_LEGACY */
48 + if (*ep || perml < 0 || perml & ~(STANDARD_BITS|S_ISTXT))
49 +#endif /* !VARIANT_LEGACY */
50 + {
51 free(saveset);
52 return (NULL);
53 }
54 perm = (mode_t)perml;
55 +#ifndef VARIANT_LEGACY
56 + ADDCMD('=', STANDARD_BITS, perm, mask);
57 +#else /* VARIANT_LEGACY */
58 ADDCMD('=', (STANDARD_BITS|S_ISTXT), perm, mask);
59 +#endif /* !VARIANT_LEGACY */
60 set->cmd = 0;
61 return (saveset);
62 }
63 @@ -246,7 +263,9 @@ getop: if ((op = *p++) != '+' && op !=
64 if (op == '=')
65 equalopdone = 0;
66
67 +#ifdef VARIANT_LEGACY
68 who &= ~S_ISTXT;
69 +#endif /* VARIANT_LEGACY */
70 for (perm = 0, permXbits = 0;; ++p) {
71 switch (*p) {
72 case 'r':
73 @@ -260,7 +279,9 @@ getop: if ((op = *p++) != '+' && op !=
74 case 't':
75 /* If only "other" bits ignore sticky. */
76 if (!who || who & ~S_IRWXO) {
77 +#ifdef VARIANT_LEGACY
78 who |= S_ISTXT;
79 +#endif /* VARIANT_LEGACY */
80 perm |= S_ISTXT;
81 }
82 break;
83 @@ -390,13 +411,14 @@ dumpmode(BITCMD *set)
84 }
85 #endif
86
87 +#ifndef BUILDING_VARIANT
88 /*
89 * Given an array of bitcmd structures, compress by compacting consecutive
90 * '+', '-' and 'X' commands into at most 3 commands, one of each. The 'u',
91 * 'g' and 'o' commands continue to be separate. They could probably be
92 * compacted, but it's not worth the effort.
93 */
94 -static void
95 +__private_extern__ void
96 compress_mode(BITCMD *set)
97 {
98 BITCMD *nset;
99 @@ -444,3 +466,4 @@ compress_mode(BITCMD *set)
100 }
101 }
102 }
103 +#endif /* BUILDING_VARIANT */