3 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
5 * Openvision retains the copyright to derivative works of
6 * this source code. Do *NOT* create a derivative of this
7 * source code before consulting with your legal department.
8 * Do *NOT* integrate *ANY* of this source code into another
9 * product before consulting with your legal department.
11 * For further information, read the top-level Openvision
12 * copyright which is contained in the top-level MIT Kerberos
15 * WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING
21 * Copyright 1993 OpenVision Technologies, Inc., All Rights Reserved
26 static char *rcsid
= "$Header$";
29 #if defined(HAVE_COMPILE) && defined(HAVE_STEP)
30 #define SOLARIS_REGEXPS
31 #elif defined(HAVE_REGCOMP) && defined(HAVE_REGEXEC)
33 #elif defined(HAVE_RE_COMP) && defined(HAVE_RE_EXEC)
36 #error I cannot find any regexp functions
39 #include <sys/types.h>
41 #include "server_internal.h"
42 #include <kadm5/admin.h>
43 #ifdef SOLARIS_REGEXPS
55 int n_names
, sz_names
;
56 unsigned int malloc_failed
;
58 #ifdef SOLARIS_REGEXPS
67 * Function: glob_to_regexp
71 * glob (r) the shell-style glob (?*[]) to convert
72 * realm (r) the default realm to append, or NULL
73 * regexp (w) the ed-style regexp created from glob
77 * regexp is filled in with allocated memory contained a regular
78 * expression to be used with re_comp/compile that matches what the
79 * shell-style glob would match. If glob does not contain an "@"
80 * character and realm is not NULL, "@*" is appended to the regexp.
82 * Conversion algorithm:
84 * quoted characters are copied quoted
86 * * is converted to .*
87 * active characters are quoted: ^, $, .
88 * [ and ] are active but supported and have the same meaning, so
90 * other characters are copied
91 * regexp is anchored with ^ and $
93 static kadm5_ret_t
glob_to_regexp(char *glob
, char *realm
, char **regexp
)
98 /* validate the glob */
99 if (glob
[strlen(glob
)-1] == '\\')
102 /* A character of glob can turn into two in regexp, plus ^ and $ */
103 /* and trailing null. If glob has no @, also allocate space for */
105 append_realm
= (realm
!= NULL
) && (strchr(glob
, '@') == NULL
);
106 p
= (char *) malloc(strlen(glob
)*2+ 3 + (append_realm
? 2 : 0));
148 static void get_either_iter(struct iter_data
*data
, char *name
)
151 #ifdef SOLARIS_REGEXPS
152 match
= (step(name
, data
->expbuf
) != 0);
155 match
= (regexec(&data
->preg
, name
, 0, NULL
, 0) == 0);
158 match
= (re_exec(name
) != 0);
161 if (data
->n_names
== data
->sz_names
) {
162 int new_sz
= data
->sz_names
* 2;
163 char **new_names
= reallocarray(data
->names
, new_sz
,
166 data
->names
= new_names
;
167 data
->sz_names
= new_sz
;
169 data
->malloc_failed
= 1;
174 data
->names
[data
->n_names
++] = name
;
179 static void get_pols_iter(void *data
, osa_policy_ent_t entry
)
183 if ((name
= strdup(entry
->name
)) == NULL
)
185 get_either_iter(data
, name
);
188 static void get_princs_iter(void *data
, krb5_principal princ
)
190 struct iter_data
*id
= (struct iter_data
*) data
;
193 if (krb5_unparse_name(id
->context
, princ
, &name
) != 0)
195 get_either_iter(data
, name
);
198 static kadm5_ret_t
kadm5_get_either(int princ
,
204 struct iter_data data
;
210 kadm5_server_handle_t handle
= server_handle
;
216 CHECK_HANDLE(server_handle
);
218 if ((ret
= glob_to_regexp(exp
, princ
? handle
->params
.realm
: NULL
,
219 ®exp
)) != KADM5_OK
)
223 #ifdef SOLARIS_REGEXPS
224 ((data
.expbuf
= compile(regexp
, NULL
, NULL
)) == NULL
)
227 ((regcomp(&data
.preg
, regexp
, REG_NOSUB
)) != 0)
230 ((msg
= (char *) re_comp(regexp
)) != NULL
)
234 /* XXX syslog msg or regerr(regerrno) */
241 data
.malloc_failed
= 0;
242 data
.names
= malloc(sizeof(char *) * data
.sz_names
);
243 if (data
.names
== NULL
) {
249 data
.context
= handle
->context
;
250 ret
= kdb_iter_entry(handle
, exp
, get_princs_iter
, (void *) &data
);
252 ret
= krb5_db_iter_policy(handle
->context
, exp
, get_pols_iter
, (void *)&data
);
259 if ( !ret
&& data
.malloc_failed
)
262 for (i
= 0; i
< data
.n_names
; i
++)
268 *princs
= data
.names
;
269 *count
= data
.n_names
;
273 kadm5_ret_t
kadm5_get_principals(void *server_handle
,
278 return kadm5_get_either(1, server_handle
, exp
, princs
, count
);
281 kadm5_ret_t
kadm5_get_policies(void *server_handle
,
286 return kadm5_get_either(0, server_handle
, exp
, pols
, count
);