Print this page
3165 correct pointer to integer conversion in Privilege.xs
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/perl/contrib/Sun/Solaris/Privilege/Privilege.xs
+++ new/usr/src/cmd/perl/contrib/Sun/Solaris/Privilege/Privilege.xs
1 1 /*
2 2 * Copyright (c) 2004, Oracle and/or its affiliates. All rights reserved.
3 3 */
↓ open down ↓ |
3 lines elided |
↑ open up ↑ |
4 4
5 5 /* Solaris includes. */
6 6 #include <priv.h>
7 7 #include <ctype.h>
8 8
9 9 /* Perl includes. */
10 10 #include "EXTERN.h"
11 11 #include "perl.h"
12 12 #include "XSUB.h"
13 13
14 -#define IVCONST(s, c) newCONSTSUB(s, #c, newSViv((int)c));
14 +#define IVCONST(s, c) newCONSTSUB(s, #c, newSViv((int)(intptr_t)c));
15 15 #define POFF (sizeof ("PRIV_") - 1)
16 16
17 17 #define RETPRIVSET(set) \
18 18 ST(0) = sv_newmortal(); \
19 19 sv_setref_pv(ST(0), "Sun::Solaris::Privilege::PrivsetPtr", \
20 20 (void*)(set)); \
21 21 SvREADONLY_on(SvRV(ST(0)))
22 22
23 23 typedef int sysret;
24 24
25 25 typedef priv_set_t Sun__Solaris__Privilege__Privset;
26 26
27 27 static priv_set_t *
28 28 dupset(const priv_set_t *s)
29 29 {
30 30 priv_set_t *new = priv_allocset();
31 31 if (new == NULL)
32 32 return (NULL);
33 33
34 34 priv_copyset(s, new);
35 35 return (new);
36 36 }
37 37
38 38 /*
39 39 * Automatically derive the #define constant from the constant value.
40 40 * This is the uppercase value of the constant with "PRIV_" prepended.
41 41 * The (name, value) pair computed in that way is stored twice:
42 42 * once as constant subroutine in the module's hash table.
43 43 * once as (key, value) in a hash table.
44 44 */
45 45
46 46 static void
47 47 PRIVconst(HV *sym, HV *var, const char *name)
48 48 {
49 49 char upname[128];
50 50 ssize_t len;
51 51 int i;
52 52
53 53 len = snprintf(upname, sizeof (upname), "PRIV_%s", name);
54 54 if (len >= sizeof (upname))
55 55 return;
56 56
57 57 for (i = POFF; i < len; i++)
58 58 upname[i] = toupper(upname[i]);
59 59 newCONSTSUB(sym, upname, newSVpv(name, len - POFF));
60 60 hv_store(var, upname, len, newSVpv(name, len - POFF), 0);
61 61 }
62 62
63 63 /*
64 64 * The XS code exported to perl is below here. Note that the XS preprocessor
65 65 * has its own commenting syntax, so all comments from this point on are in
66 66 * that form.
67 67 *
68 68 * Inside perl, privilege sets are represented as expanded strings;
69 69 * privileges and privilege sets are only known by name.
70 70 */
71 71
72 72 MODULE = Sun::Solaris::Privilege PACKAGE = Sun::Solaris::Privilege
73 73 PROTOTYPES: ENABLE
74 74
75 75 #
76 76 # Define any constants that need to be exported. By doing it this way we can
77 77 # avoid the overhead of using the DynaLoader package, and in addition constants
78 78 # defined using this mechanism are eligible for inlining by the perl
79 79 # interpreter at compile time.
80 80 #
81 81 BOOT:
82 82 {
83 83 HV *stash;
84 84 HV *privs;
85 85 HV *privsets;
86 86 const char *p;
87 87 int i;
88 88
89 89 stash = gv_stashpv("Sun::Solaris::Privilege", TRUE);
90 90
91 91 /*
92 92 * Global constants
93 93 */
94 94 IVCONST(stash, PRIV_STR_PORT);
95 95 IVCONST(stash, PRIV_STR_LIT);
96 96 IVCONST(stash, PRIV_STR_SHORT);
97 97 IVCONST(stash, PRIV_ALLSETS);
98 98 IVCONST(stash, PRIV_DEBUG);
99 99 IVCONST(stash, PRIV_AWARE);
100 100 IVCONST(stash, PRIV_ON);
101 101 IVCONST(stash, PRIV_OFF);
102 102 IVCONST(stash, PRIV_SET);
103 103
104 104 /*
105 105 * %PRIVILEGES hash and the privilege constants
106 106 */
107 107 privs = perl_get_hv("Sun::Solaris::Privilege::PRIVILEGES", TRUE);
108 108 for (i = 0; (p = priv_getbynum(i++)) != NULL; )
109 109 PRIVconst(stash, privs, p);
110 110
111 111 /*
112 112 * %PRIVSETS hash and the privset constants
113 113 */
114 114 privsets = perl_get_hv("Sun::Solaris::Privilege::PRIVSETS", TRUE);
115 115 for (i = 0; (p = priv_getsetbynum(i++)) != NULL; )
116 116 PRIVconst(stash, privsets, p);
117 117 }
118 118
119 119
120 120 Sun::Solaris::Privilege::Privset *
121 121 getppriv(which)
122 122 const char *which;
123 123 CODE:
124 124 RETVAL = priv_allocset();
125 125 if (getppriv(which, RETVAL) != 0) {
126 126 priv_freeset(RETVAL);
127 127 XSRETURN_UNDEF;
128 128 } else {
129 129 RETPRIVSET(RETVAL);
130 130 }
131 131
132 132 sysret
133 133 setppriv(op, which, set)
134 134 int op;
135 135 const char *which;
136 136 Sun::Solaris::Privilege::Privset *set;
137 137
138 138 Sun::Solaris::Privilege::Privset *
139 139 priv_emptyset()
140 140 CODE:
141 141 RETVAL = priv_allocset();
142 142 if (RETVAL == NULL) {
143 143 XSRETURN_UNDEF;
144 144 }
145 145 priv_emptyset(RETVAL);
146 146 RETPRIVSET(RETVAL);
147 147
148 148 Sun::Solaris::Privilege::Privset *
149 149 priv_fillset()
150 150 CODE:
151 151 RETVAL = priv_allocset();
152 152 if (RETVAL == NULL) {
153 153 XSRETURN_UNDEF;
154 154 }
155 155 priv_fillset(RETVAL);
156 156 RETPRIVSET(RETVAL);
157 157
158 158 boolean_t
159 159 priv_isemptyset(set)
160 160 Sun::Solaris::Privilege::Privset *set;
161 161
162 162 boolean_t
163 163 priv_isfullset(set)
164 164 Sun::Solaris::Privilege::Privset *set;
165 165
166 166 boolean_t
167 167 priv_isequalset(set1, set2)
168 168 Sun::Solaris::Privilege::Privset *set1;
169 169 Sun::Solaris::Privilege::Privset *set2;
170 170
171 171 boolean_t
172 172 priv_issubset(set1, set2)
173 173 Sun::Solaris::Privilege::Privset *set1;
174 174 Sun::Solaris::Privilege::Privset *set2;
175 175
176 176 boolean_t
177 177 priv_ismember(set, priv)
178 178 Sun::Solaris::Privilege::Privset *set;
179 179 const char *priv;
180 180
181 181 boolean_t
182 182 priv_ineffect(priv)
183 183 const char *priv;
184 184
185 185 Sun::Solaris::Privilege::Privset *
186 186 priv_intersect(set1, set2)
187 187 Sun::Solaris::Privilege::Privset *set1;
188 188 Sun::Solaris::Privilege::Privset *set2;
189 189 CODE:
190 190 RETVAL = dupset(set2);
191 191 if (RETVAL == NULL) {
192 192 XSRETURN_UNDEF;
193 193 }
194 194 priv_intersect(set1, RETVAL);
195 195 RETPRIVSET(RETVAL);
196 196
197 197 Sun::Solaris::Privilege::Privset *
198 198 priv_union(set1, set2)
199 199 Sun::Solaris::Privilege::Privset *set1;
200 200 Sun::Solaris::Privilege::Privset *set2;
201 201 CODE:
202 202 RETVAL = dupset(set2);
203 203 if (RETVAL == NULL) {
204 204 XSRETURN_UNDEF;
205 205 }
206 206 priv_union(set1, RETVAL);
207 207 RETPRIVSET(RETVAL);
208 208
209 209 Sun::Solaris::Privilege::Privset *
210 210 priv_inverse(set1)
211 211 Sun::Solaris::Privilege::Privset *set1;
212 212 CODE:
213 213 RETVAL = dupset(set1);
214 214 if (RETVAL == NULL) {
215 215 XSRETURN_UNDEF;
216 216 }
217 217 priv_inverse(RETVAL);
218 218 RETPRIVSET(RETVAL);
219 219
220 220
221 221 sysret
222 222 priv_addset(set, priv)
223 223 Sun::Solaris::Privilege::Privset *set;
224 224 const char *priv;
225 225
226 226 Sun::Solaris::Privilege::Privset *
227 227 priv_copyset(set1)
228 228 Sun::Solaris::Privilege::Privset *set1;
229 229 CODE:
230 230 RETVAL = dupset(set1);
231 231 if (RETVAL == NULL) {
232 232 XSRETURN_UNDEF;
233 233 }
234 234 RETPRIVSET(RETVAL);
235 235
236 236
237 237 sysret
238 238 priv_delset(set, priv)
239 239 Sun::Solaris::Privilege::Privset *set;
240 240 const char *priv;
241 241
242 242 const char *
243 243 priv_getbynum(i)
244 244 int i;
245 245
246 246 const char *
247 247 priv_getsetbynum(i)
248 248 int i;
249 249
250 250 char *
251 251 priv_set_to_str(s, c, f)
252 252 Sun::Solaris::Privilege::Privset *s;
253 253 char c;
254 254 int f;
255 255 CLEANUP:
256 256 free(RETVAL);
257 257
258 258 Sun::Solaris::Privilege::Privset *
259 259 priv_str_to_set(buf, sep);
260 260 const char *buf;
261 261 const char *sep;
262 262 CODE:
263 263 RETVAL = priv_str_to_set(buf, sep, NULL);
264 264 if (RETVAL == NULL) {
265 265 XSRETURN_UNDEF;
266 266 }
267 267 RETPRIVSET(RETVAL);
268 268
269 269 char *
270 270 priv_gettext(priv)
271 271 const char *priv
272 272 CLEANUP:
273 273 free(RETVAL);
274 274
275 275 sysret
276 276 setpflags(flag, val)
277 277 uint_t flag;
278 278 uint_t val;
279 279
280 280 sysret
281 281 getpflags(flag)
282 282 uint_t flag;
283 283
284 284 MODULE = Sun::Solaris::Privilege PACKAGE = Sun::Solaris::Privilege::PrivsetPtr PREFIX = Privilege_
285 285
286 286 void
287 287 Privilege_DESTROY(ps)
288 288 Sun::Solaris::Privilege::Privset *ps;
289 289 CODE:
290 290 priv_freeset(ps);
291 291
↓ open down ↓ |
267 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX