41 #include <string.h>
42 #include <locale.h>
43 #include <sys/param.h>
44 #include <priv.h>
45 #include <alloca.h>
46 #include <locale.h>
47 #include "libc.h"
48 #include "../i18n/_loc_path.h"
49 #include "priv_private.h"
50
51 priv_set_t *
52 priv_basic(void)
53 {
54 priv_data_t *d;
55
56 LOADPRIVDATA(d);
57
58 return (d->pd_basicset);
59 }
60
61 /*
62 * Name: priv_str_to_set()
63 *
64 * Description: Given a buffer with privilege strings, the
65 * equivalent privilege set is returned.
66 *
67 * Special tokens recognized: all, none, basic and "".
68 *
69 * On failure, this function returns NULL.
70 * *endptr == NULL and errno set: resource error.
71 * *endptr != NULL: parse error.
72 */
73 priv_set_t *
74 priv_str_to_set(const char *priv_names,
75 const char *separators,
76 const char **endptr)
77 {
78
79 char *base;
80 char *offset;
81 char *last;
82 priv_set_t *pset = NULL;
83 priv_set_t *zone;
84 priv_set_t *basic;
85
86 if (endptr != NULL)
87 *endptr = NULL;
88
89 if ((base = libc_strdup(priv_names)) == NULL ||
90 (pset = priv_allocset()) == NULL) {
91 /* Whether base is NULL or allocated, this works */
92 libc_free(base);
93 return (NULL);
94 }
95
96 priv_emptyset(pset);
97 basic = priv_basic();
98 zone = privdata->pd_zoneset;
99
100 /* This is how to use strtok_r nicely in a while loop ... */
101 last = base;
102
103 while ((offset = strtok_r(NULL, separators, &last)) != NULL) {
104 /*
105 * Search for these special case strings.
106 */
107 if (basic != NULL && strcasecmp(offset, "basic") == 0) {
108 priv_union(basic, pset);
109 } else if (strcasecmp(offset, "none") == 0) {
110 priv_emptyset(pset);
111 } else if (strcasecmp(offset, "all") == 0) {
112 priv_fillset(pset);
113 } else if (strcasecmp(offset, "zone") == 0) {
114 priv_union(zone, pset);
115 } else {
116 boolean_t neg = (*offset == '-' || *offset == '!');
117 int privid;
118 int slen;
119
120 privid = priv_getbyname(offset +
121 ((neg || *offset == '+') ? 1 : 0));
122 if (privid < 0) {
123 slen = offset - base;
124 libc_free(base);
125 priv_freeset(pset);
126 if (endptr != NULL)
127 *endptr = priv_names + slen;
128 errno = EINVAL;
|
41 #include <string.h>
42 #include <locale.h>
43 #include <sys/param.h>
44 #include <priv.h>
45 #include <alloca.h>
46 #include <locale.h>
47 #include "libc.h"
48 #include "../i18n/_loc_path.h"
49 #include "priv_private.h"
50
51 priv_set_t *
52 priv_basic(void)
53 {
54 priv_data_t *d;
55
56 LOADPRIVDATA(d);
57
58 return (d->pd_basicset);
59 }
60
61 priv_set_t *
62 priv_default(void)
63 {
64 priv_data_t *d;
65
66 LOADPRIVDATA(d);
67
68 return (d->pd_defaultset);
69 }
70
71 /*
72 * Name: priv_str_to_set()
73 *
74 * Description: Given a buffer with privilege strings, the
75 * equivalent privilege set is returned.
76 *
77 * Special tokens recognized: all, none, basic and "".
78 *
79 * On failure, this function returns NULL.
80 * *endptr == NULL and errno set: resource error.
81 * *endptr != NULL: parse error.
82 */
83 priv_set_t *
84 priv_str_to_set(const char *priv_names,
85 const char *separators,
86 const char **endptr)
87 {
88
89 char *base;
90 char *offset;
91 char *last;
92 priv_set_t *pset = NULL;
93 priv_set_t *zone = NULL;
94 priv_set_t *basic = NULL;
95 priv_set_t *deflt = NULL;
96
97 if (endptr != NULL)
98 *endptr = NULL;
99
100 if ((base = libc_strdup(priv_names)) == NULL ||
101 (pset = priv_allocset()) == NULL) {
102 /* Whether base is NULL or allocated, this works */
103 libc_free(base);
104 return (NULL);
105 }
106
107 priv_emptyset(pset);
108 basic = priv_basic();
109 deflt = priv_default();
110 zone = privdata->pd_zoneset;
111
112 /* This is how to use strtok_r nicely in a while loop ... */
113 last = base;
114
115 while ((offset = strtok_r(NULL, separators, &last)) != NULL) {
116 /*
117 * Search for these special case strings.
118 */
119 if (basic != NULL && strcasecmp(offset, "basic") == 0) {
120 priv_union(basic, pset);
121 } else if (deflt != NULL && strcasecmp(offset,
122 "default") == 0) {
123 priv_union(deflt, pset);
124 } else if (strcasecmp(offset, "none") == 0) {
125 priv_emptyset(pset);
126 } else if (strcasecmp(offset, "all") == 0) {
127 priv_fillset(pset);
128 } else if (strcasecmp(offset, "zone") == 0) {
129 priv_union(zone, pset);
130 } else {
131 boolean_t neg = (*offset == '-' || *offset == '!');
132 int privid;
133 int slen;
134
135 privid = priv_getbyname(offset +
136 ((neg || *offset == '+') ? 1 : 0));
137 if (privid < 0) {
138 slen = offset - base;
139 libc_free(base);
140 priv_freeset(pset);
141 if (endptr != NULL)
142 *endptr = priv_names + slen;
143 errno = EINVAL;
|