First major cleanup, mostly finished.

This commit is contained in:
leif%netscape.com 2000-01-14 22:25:29 +00:00
parent 485633e020
commit c81ab876a3
5 changed files with 166 additions and 282 deletions

View File

@ -1,5 +1,5 @@
###############################################################################
# $Id: Makefile,v 1.2 2000/01/12 06:26:59 leif%netscape.com Exp $
# $Id: Makefile,v 1.3 2000/01/14 22:25:14 leif%netscape.com Exp $
#
# The contents of this file are subject to the Mozilla Public License
# Version 1.1 (the "License"); you may not use this file except in
@ -28,7 +28,7 @@
###############################################################################
# Build configuration is done here!
#
DS = /opt/suitespot/plugins/slapd/slapi
#DS = /opt/suitespot/plugins/slapd/slapi
DS = /server/server4/plugins/slapd/slapi
ETAGS = etags
@ -66,10 +66,9 @@ INCLUDE = -I. -I$(DS)/include
CFLAGS = $(FLAGS) $(OPT) $(INCLUDE) $(SH_OPTS)
LDFLAGS = $(LD_OPTS)
TARGETS = rex_filt.so url_filt.so comb_filt.so quick_auth.so \
uid_auth.so
TARGETS = rex_filt.so url_filt.so
INCFILES = lulu.h
CFILES = rex_filt.c url_filt.c lulu.c quick_auth.c uid_auth.c
CFILES = rex_filt.c url_filt.c lulu.c
MISCFILES = Makefile
@ -87,15 +86,6 @@ rex_filt.so: rex_filt.o lulu.o lulu.h
url_filt.so: url_filt.o lulu.o lulu.h
$(LD) $(LDFLAGS) -o $@ url_filt.o lulu.o
comb_filt.so: rex_filt.o url_filt.o lulu.o lulu.h
$(LD) $(LDFLAGS) -o $@ rex_filt.o url_filt.o lulu.o
quick_auth.so: quick_auth.o lulu.o lulu.h
$(LD) $(LDFLAGS) -o $@ quick_auth.o lulu.o
uid_auth.so: uid_auth.o lulu.o lulu.h
$(LD) $(LDFLAGS) -o $@ uid_auth.o lulu.o
###############################################################################
# Misc targets

View File

@ -1,6 +1,6 @@
/* -*- Mode: C; eval: (c-set-style "GNU") -*-
******************************************************************************
* $Id: lulu.c,v 1.2 2000/01/12 06:26:59 leif%netscape.com Exp $
* $Id: lulu.c,v 1.3 2000/01/14 22:25:17 leif%netscape.com Exp $
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
@ -30,16 +30,13 @@
/******************************************************************************
* Free the list of attributes, in case something went south...
*/
PUBLIC BOOL
freeAttributes(PluginAttrs *attrs)
PUBLIC int
free_attributes(Plugin_Attrs *attrs)
{
PluginAttrs *cur;
Plugin_Attrs *cur;
if (!attrs)
return FALSE;
if (attrs->type)
slapi_ch_free((void **)&(attrs->type));
return 0;
while (attrs)
{
@ -48,7 +45,7 @@ freeAttributes(PluginAttrs *attrs)
slapi_ch_free((void **)&cur);
}
return TRUE;
return 1;
}
@ -58,48 +55,43 @@ freeAttributes(PluginAttrs *attrs)
*
* parseAttributes("cn,uid,mail");
*/
PUBLIC PluginAttrs *
parseAttributes(char *str)
PUBLIC Plugin_Attrs *
parse_attributes(char *str)
{
char *list, *tmp;
PluginAttrs *cur, *ret;
char *tmp;
Plugin_Attrs *cur, *ret;
/* Allocate space for the attributes and the regex string */
if (!str || !(list = slapi_ch_strdup(str)))
return (PluginAttrs *)NULL;
if (!str)
return (Plugin_Attrs *)NULL;
tmp = list;
tmp = str;
while (*tmp)
{
*tmp = tolower((int)*tmp);
tmp++;
}
if (!(ret = (Plugin_Attrs *)slapi_ch_malloc(sizeof(Plugin_Attrs))))
return (Plugin_Attrs *)NULL;
/* Parse through attributes, one by one. Note that this doesn't handle
weird input like "," or "phone,". */
if (!(ret = (PluginAttrs *)slapi_ch_malloc(sizeof(PluginAttrs))))
return (PluginAttrs *)NULL;
cur = ret;
tmp = strtok(list, ATTR_SEPARATOR);
tmp = strtok(str, ",");
while (tmp)
{
if (!cur)
{
/* This shouldn't happen, but if it does let's be clean. */
freeAttributes(ret);
return (PluginAttrs *)NULL;
free_attributes(ret);
return (Plugin_Attrs *)NULL;
}
cur->type = tmp;
cur->first = *tmp;
cur->len = strlen(tmp);
if ((tmp = strtok(NULLCP, ATTR_SEPARATOR)))
cur->next = (PluginAttrs *)slapi_ch_malloc(sizeof(PluginAttrs));
if ((tmp = strtok(NULL, ",")))
cur->next = (Plugin_Attrs *)
slapi_ch_malloc(sizeof(Plugin_Attrs));
else
cur->next = (PluginAttrs *)NULL;
cur->next = (Plugin_Attrs *)NULL;
cur = cur->next;
}
@ -112,26 +104,25 @@ parseAttributes(char *str)
* Check if a particular attribute type is in a Plugin Attribute list. This
* can be used to decide if a plugin/filter should be applied for instance.
*/
PUBLIC INLINE BOOL
listHasAttribute(PluginAttrs *attrs, char *type)
PUBLIC INLINE int
list_has_attribute(Plugin_Attrs *attrs, char *type)
{
int len;
if (!attrs || !type)
return FALSE;
return 0;
len = strlen(type);
while (attrs)
{
if ((attrs->first == *type) &&
(attrs->len == len) &&
(!strcmp(attrs->type, type)))
return TRUE;
(attrs->len == len) && (!strcmp(attrs->type, type)))
return 1;
attrs = attrs->next;
}
return FALSE;
return 0;
}
@ -139,13 +130,13 @@ listHasAttribute(PluginAttrs *attrs, char *type)
* Send a constraint violation error back to the client, with a more
* descriptive error message.
*/
PUBLIC BOOL
sendConstraintErr(Slapi_PBlock *pb, char *str)
PUBLIC int
send_constraint_err(Slapi_PBlock *pb, char *str)
{
slapi_send_ldap_result(pb, LDAP_CONSTRAINT_VIOLATION, NULLCP, str, 0,
(BerVal **)NULL);
return TRUE;
return 1;
}
@ -153,13 +144,13 @@ sendConstraintErr(Slapi_PBlock *pb, char *str)
* Send a constraint violation error back to the client, with a more
* descriptive error message.
*/
PUBLIC BOOL
sendOperationsErr(Slapi_PBlock *pb, char *str)
PUBLIC int
send_operations_err(Slapi_PBlock *pb, char *str)
{
slapi_send_ldap_result(pb, LDAP_OPERATIONS_ERROR, NULLCP, str, 0,
(BerVal **)NULL);
return TRUE;
return 1;
}
@ -167,11 +158,11 @@ sendOperationsErr(Slapi_PBlock *pb, char *str)
* Get the ADD entry, and if it fails we send an error, and return FALSE. As
* a side effect the "entry" argument (a handle) is set to the structure.
*/
PUBLIC INLINE BOOL
getAddEntry(Slapi_PBlock *pb, Slapi_Entry **entry, char *name)
PUBLIC INLINE int
get_add_entry(Slapi_PBlock *pb, Slapi_Entry **entry, char *name)
{
if (!entry)
return FALSE;
return 0;
if (slapi_pblock_get(pb, SLAPI_ADD_ENTRY, entry) || !*entry)
{
@ -179,10 +170,10 @@ getAddEntry(Slapi_PBlock *pb, Slapi_Entry **entry, char *name)
slapi_send_ldap_result(pb, LDAP_NO_MEMORY, NULLCP, ERR_NOENTRY, 0,
(BerVal **)NULL);
return FALSE;
return 0;
}
return TRUE;
return 1;
}
@ -191,11 +182,11 @@ getAddEntry(Slapi_PBlock *pb, Slapi_Entry **entry, char *name)
* and return FALSE. As a side effect, we set the "mods" argument (a handle)
* to the modifications structure.
*/
PUBLIC INLINE BOOL
getModifyMods(Slapi_PBlock *pb, LDAPMod ***mods, char *name)
PUBLIC INLINE int
get_modify_mods(Slapi_PBlock *pb, LDAPMod ***mods, char *name)
{
if (!mods)
return FALSE;
return 0;
if (slapi_pblock_get(pb, SLAPI_MODIFY_MODS, mods) || !*mods)
{
@ -203,18 +194,18 @@ getModifyMods(Slapi_PBlock *pb, LDAPMod ***mods, char *name)
slapi_send_ldap_result(pb, LDAP_NO_MEMORY, NULLCP, ERR_NOMODS, 0,
(BerVal **)NULL);
return FALSE;
return 0;
}
return TRUE;
return 1;
}
/******************************************************************************
* Get the "command line arguments", and return TRUE if successful.
*/
PUBLIC BOOL
getSlapiArgs(Slapi_PBlock *pb, int *argc, char ***argv, int exp, char *name)
PUBLIC int
get_slapi_args(Slapi_PBlock *pb, int *argc, char ***argv, int exp, char *name)
{
if (slapi_pblock_get(pb, SLAPI_PLUGIN_ARGC, argc) ||
slapi_pblock_get(pb, SLAPI_PLUGIN_ARGV, argv) ||
@ -222,10 +213,10 @@ getSlapiArgs(Slapi_PBlock *pb, int *argc, char ***argv, int exp, char *name)
{
slapi_log_error(LOG_FACILITY, name, ERR_ARGS);
return FALSE;
return 0;
}
return TRUE;
return 1;
}
@ -234,7 +225,7 @@ getSlapiArgs(Slapi_PBlock *pb, int *argc, char ***argv, int exp, char *name)
* actually work.
*/
PUBLIC int
setSimpleAuthInfo(Slapi_PBlock *pb, char *dn, char *auth, char *name)
set_simple_auth_info(Slapi_PBlock *pb, char *dn, char *auth, char *name)
{
char *setDN;

View File

@ -1,6 +1,6 @@
/* -*- Mode: C; eval: (c-set-style "GNU") -*-
******************************************************************************
* $Id: lulu.h,v 1.2 2000/01/12 06:27:00 leif%netscape.com Exp $
* $Id: lulu.h,v 1.3 2000/01/14 22:25:23 leif%netscape.com Exp $
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
@ -35,7 +35,6 @@
* Configurations, you might want to look at these...
*/
#define LOG_FACILITY SLAPI_LOG_PLUGIN
#define THE_AUTHOR "IS-Architorture"
/******************************************************************************
@ -59,7 +58,6 @@
#define STATIC static
#define NULLCP (char *)NULL
#define ATTR_SEPARATOR ","
@ -76,17 +74,13 @@
/******************************************************************************
* Typedefs and structures.
*/
typedef int BOOL;
#define TRUE (1)
#define FALSE (0)
typedef struct _PluginAttrs
typedef struct _Plugin_Attrs
{
char *type; /* Name/type of the attribute, all lower case. */
char first; /* First character in the attribute name. */
int len; /* Length of the name/string. */
struct _PluginAttrs *next;
} PluginAttrs;
struct _Plugin_Attrs *next;
} Plugin_Attrs;
typedef struct berval BerVal;
@ -94,12 +88,12 @@ typedef struct berval BerVal;
/******************************************************************************
* Public functions.
*/
PUBLIC PluginAttrs *parseAttributes(char *);
PUBLIC BOOL listHasAttribute(PluginAttrs *, char *);
PUBLIC BOOL freeAttributes(PluginAttrs *);
PUBLIC BOOL sendConstraintErr(Slapi_PBlock *, char *);
PUBLIC BOOL sendOperationsErr(Slapi_PBlock *, char *);
PUBLIC BOOL getAddEntry(Slapi_PBlock *, Slapi_Entry **, char *);
PUBLIC BOOL getModifyMods(Slapi_PBlock *, LDAPMod ***, char *);
PUBLIC BOOL getSlapiArgs(Slapi_PBlock *, int *, char ***, int, char *);
PUBLIC int setSimpleAuthInfo(Slapi_PBlock *, char *, char *, char *);
PUBLIC Plugin_Attrs *parse_attributes(char *);
PUBLIC int list_has_attribute(Plugin_Attrs *, char *);
PUBLIC int free_attributes(Plugin_Attrs *);
PUBLIC int send_constraint_err(Slapi_PBlock *, char *);
PUBLIC int send_operations_err(Slapi_PBlock *, char *);
PUBLIC int get_add_entry(Slapi_PBlock *, Slapi_Entry **, char *);
PUBLIC int get_modify_mods(Slapi_PBlock *, LDAPMod ***, char *);
PUBLIC int get_slapi_args(Slapi_PBlock *, int *, char ***, int, char *);
PUBLIC int set_simple_auth_info(Slapi_PBlock *, char *, char *, char *);

View File

@ -1,7 +1,6 @@
/* -*- Mode: C; eval: (c-set-style "GNU") -*-
*/
******************************************************************************
* $Id: rex_filt.c,v 1.2 2000/01/12 06:27:00 leif%netscape.com Exp $
* $Id: rex_filt.c,v 1.3 2000/01/14 22:25:27 leif%netscape.com Exp $
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
@ -33,139 +32,47 @@
* * Support the /.../i syntax, for case insensitive regexps.
*
*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <sys/types.h>
#include <slapi-plugin.h>
#include <regex.h>
#define LOG_FACILITY SLAPI_LOG_PLUGIN
#include <stdio.h>
#include <regex.h>
#include "lulu.h"
/******************************************************************************
* Defines, for this particular plugin only.
*/
#define PLUGIN_NAME "rex_filter"
#define PLUGIN_VERS "1.1"
#define ERR_NOMATCH "An attribute does not match a server regex rule.\n"
#define ERR_MATCH "An attribute matches a server regex rule.\n"
#define ERR_MALLOC "Can't allocate memory, which is a Bad Thing(tm).\n"
#define ERR_NOMODS "Could not get the modifications.\n"
#define ERR_NOENTRY "Could not get entry.\n"
#ifdef __GNUC__
# define INLINE inline
#else /* not __GNUC__ */
# define INLINE
#endif /* __GNUC__ */
typedef struct berval BerVal;
typedef struct _Rex_Filter_Attrs
{
char *type;
char first;
int len;
struct _Rex_Filter_Attrs *next;
} Rex_Filter_Attrs;
/******************************************************************************
* Typedefs and structures. Note that some of the members of this structure
* are for performance reason, e.g. the "len" fields.
*/
typedef struct _Rex_Filter
{
char *string;
char *attributes;
regex_t *regex;
int match;
Rex_Filter_Attrs *attrs;
Plugin_Attrs *attrs;
struct _Rex_Filter *next;
} Rex_Filter;
/******************************************************************************
* Globals, "private" to this module.
*/
static int rex_num_filters = 0;
static Rex_Filter *rex_filter_list = NULL;
static Slapi_PluginDesc rex_descript = { PLUGIN_NAME,
"Leif Hedstrom",
"1.0",
PLUGIN_VERS,
"Regex filter plugin" };
static int
free_attributes(Rex_Filter_Attrs *attrs)
{
Rex_Filter_Attrs *cur;
if (!attrs)
return 0;
while (attrs)
{
cur = attrs;
attrs = cur->next;
slapi_ch_free((void **)&cur);
}
return 1;
}
static Rex_Filter_Attrs *
parse_attributes(char *str)
{
char *tmp;
Rex_Filter_Attrs *cur, *ret;
if (!str)
return (Rex_Filter_Attrs *)NULL;
tmp = str;
while (*tmp)
{
*tmp = tolower((int)*tmp);
tmp++;
}
if (!(ret = (Rex_Filter_Attrs *)slapi_ch_malloc(sizeof(Rex_Filter_Attrs))))
return (Rex_Filter_Attrs *)NULL;
cur = ret;
tmp = strtok(str, ",");
while (tmp)
{
if (!cur)
{
free_attributes(ret);
return (Rex_Filter_Attrs *)NULL;
}
cur->type = tmp;
cur->first = *tmp;
cur->len = strlen(tmp);
if ((tmp = strtok(NULL, ",")))
cur->next = (Rex_Filter_Attrs *)
slapi_ch_malloc(sizeof(Rex_Filter_Attrs));
else
cur->next = (Rex_Filter_Attrs *)NULL;
cur = cur->next;
}
return ret;
}
static INLINE int
list_has_attribute(Rex_Filter_Attrs *attrs, char *type)
{
int len;
if (!attrs || !type)
return 0;
len = strlen(type);
while (attrs)
{
if ((attrs->first == *type) &&
(attrs->len == len) && (!strcmp(attrs->type, type)))
return 1;
attrs = attrs->next;
}
return 0;
}
static int
create_filter(Rex_Filter *filter, char *attributes, char *string)
@ -230,7 +137,7 @@ int
eval_add_filter(Slapi_PBlock *pb)
{
Rex_Filter *filter;
Rex_Filter_Attrs *attrs;
Plugin_Attrs *attrs;
Slapi_Entry *entry;
Slapi_Attr *att;
BerVal **bvals;
@ -331,7 +238,7 @@ rex_filter_init(Slapi_PBlock *pb)
}
new->next = (Rex_Filter *)NULL;
new->attrs = (Rex_Filter_Attrs *)NULL;
new->attrs = (Plugin_Attrs *)NULL;
new->match = (*(argv[1]) == '0' ? 0 : 1);
if (!create_filter(new, argv[0], argv[2]) || !new->attrs)
{

View File

@ -1,6 +1,6 @@
/* -*- Mode: C; eval: (c-set-style "GNU") -*-
******************************************************************************
* $Id: url_filt.c,v 1.1 2000/01/12 06:15:45 leif%netscape.com Exp $
* $Id: url_filt.c,v 1.2 2000/01/14 22:25:29 leif%netscape.com Exp $
*
* The contents of this file are subject to the Mozilla Public License
* Version 1.1 (the "License"); you may not use this file except in
@ -45,7 +45,7 @@
* Defines, for this particular plugin only.
*/
#define PLUGIN_NAME "url_filt"
#define PLUGIN_VERS "1.0"
#define PLUGIN_VERS "1.1"
#define ERR_NOMATCH "An entry does not match a server LDAP URL rule.\n"
#define ERR_MATCH "An entry already matches a server LDAP URL rule.\n"
@ -55,28 +55,30 @@
* Typedefs and structures. Note that some of the members of this structure
* are for performance reason, e.g. the "len" fields.
*/
typedef struct _UrlFilter
typedef struct _URL_Filter
{
char *string; /* Original LDAP URL string, not used. */
BOOL match; /* Should we pass if URL matches (yes/no)? */
int match; /* Should we pass if URL matches (yes/no)? */
LDAPURLDesc *url; /* The components of the URL, parsed. */
char *dn; /* The DN component. */
int dnLen; /* Length of the DN component. */
int dn_len; /* Length of the DN component. */
char *search; /* The LDAP filter/search component. */
int searchLen; /* Length of the filter component. */
int numDNSubs; /* The number of $$'s in the Base-DN */
int numSearchSubs; /* The number of $$'s in the search filter. */
PluginAttrs *attrs; /* Attributes to apply this filter to. */
struct _UrlFilter *next;
} UrlFilter;
int search_len; /* Length of the filter component. */
int num_dn_subs; /* The number of $$'s in the Base-DN */
int num_search_subs; /* The number of $$'s in the search filter. */
Plugin_Attrs *attrs; /* Attributes to apply this filter to. */
struct _URL_Filter *next;
} URL_Filter;
/******************************************************************************
* Globals, "private" to this module.
*/
PRIVATE int urlNumFilters = 0; /* Number of filters we have. */
PRIVATE UrlFilter *urlFilters = NULL; /* Pointer to first filter. */
PRIVATE Slapi_PluginDesc urlDesc = { PLUGIN_NAME, THE_AUTHOR, PLUGIN_VERS,
PRIVATE int url_num_filters = 0; /* Number of filters. */
PRIVATE URL_Filter *url_filter_list = NULL; /* List of filters. */
PRIVATE Slapi_PluginDesc urlDesc = { PLUGIN_NAME,
"Leif Hedstrom",
PLUGIN_VERS,
"LDAP URL filter plugin" };
PRIVATE char *urlAttrs[2] = { "dn", NULLCP };
@ -85,7 +87,7 @@ PRIVATE char *urlAttrs[2] = { "dn", NULLCP };
* Count the number of $$'s in a string, if any.
*/
PRIVATE int
urlCountSubs(char *str)
count_subs(char *str)
{
int count = 0;
@ -103,7 +105,7 @@ urlCountSubs(char *str)
* of doing this (remember, the $$ can occur more than once)...
*/
PRIVATE INLINE char *
urlDoSubs(char *str, int len, char *val, int valLen)
do_subs(char *str, int len, char *val, int valLen)
{
char *sub, *tmp;
@ -137,52 +139,52 @@ urlDoSubs(char *str, int len, char *val, int valLen)
* Setup a filter structure, used when parsing the plugin arguments from the
* registration routien.
*/
PRIVATE BOOL
urlCreateFilter(UrlFilter *filter, char *attributes, char *string)
PRIVATE int
create_filter(URL_Filter *filter, char *attributes, char *string)
{
int res;
if (!filter || filter->attrs || !attributes || !string)
return FALSE;
return 0;
if (!(filter->string = slapi_ch_strdup(string)))
return FALSE;
return 0;
if (!(filter->attrs = parseAttributes(attributes)))
if (!(filter->attrs = parse_attributes(attributes)))
{
slapi_ch_free((void **)&(filter->string));
return FALSE;
return 0;
}
/* Parse the URL, and make sure it's of proper syntax. */
if ((res = ldap_url_parse(filter->string, &(filter->url))))
{
/* Produce a proper Error Message... */
freeAttributes(filter->attrs);
free_attributes(filter->attrs);
return FALSE;
return 0;
}
/* Let's fill in some more stuff about the filter. */
filter->dn = filter->url->lud_dn;
filter->search = filter->url->lud_filter;
filter->dnLen = strlen(filter->dn);
filter->searchLen = strlen(filter->search);
filter->numDNSubs = urlCountSubs(filter->dn);
filter->numSearchSubs = urlCountSubs(filter->search);
filter->dn_len = strlen(filter->dn);
filter->search_len = strlen(filter->search);
filter->num_dn_subs = count_subs(filter->dn);
filter->num_search_subs = count_subs(filter->search);
return TRUE;
return 1;
}
/******************************************************************************
* Perform the URL LDAP test, and set the return code properly if we do have
* have a violation. Return TRUE if we did run trigger a rule.
* have a violation. Return 1 if we did run trigger a rule.
*/
PRIVATE INLINE BOOL
urlTestFilter(Slapi_PBlock *pb, UrlFilter *filter, char *type, char *value,
PRIVATE INLINE int
test_filter(Slapi_PBlock *pb, URL_Filter *filter, char *type, char *value,
int len)
{
Slapi_PBlock *resPB;
@ -191,22 +193,22 @@ urlTestFilter(Slapi_PBlock *pb, UrlFilter *filter, char *type, char *value,
int res, retval;
/* Let's first do the appropriate substitutions, on DN and Filters. */
if (filter->numDNSubs)
if (filter->num_dn_subs)
{
if (!(tmpDN = urlDoSubs(filter->dn, filter->dnLen +
filter->numDNSubs * len, value, len)))
return FALSE;
if (!(tmpDN = do_subs(filter->dn, filter->dn_len +
filter->num_dn_subs * len, value, len)))
return 0;
}
else
tmpDN = filter->dn;
if (filter->numSearchSubs)
if (filter->num_search_subs)
{
if (!(tmpSearch = urlDoSubs(filter->search, filter->searchLen +
filter->numSearchSubs * len, value, len)))
if (!(tmpSearch = do_subs(filter->search, filter->search_len +
filter->num_search_subs * len, value, len)))
{
slapi_ch_free((void **)&tmpDN);
return FALSE;
return 0;
}
}
else
@ -237,37 +239,37 @@ urlTestFilter(Slapi_PBlock *pb, UrlFilter *filter, char *type, char *value,
else
res = LDAP_OPERATIONS_ERROR;
retval = FALSE;
retval = 0;
if ((!res && !filter->match) || (res && filter->match))
{
slapi_log_error(LOG_FACILITY, PLUGIN_NAME,
"Violation: %s on '%s: %s'\n",
filter->string, type, value);
sendConstraintErr(pb, filter->match ? ERR_NOMATCH : ERR_MATCH);
send_constraint_err(pb, filter->match ? ERR_NOMATCH : ERR_MATCH);
retval = TRUE;
retval = 1;
}
if (filter->numDNSubs)
if (filter->num_dn_subs)
slapi_ch_free((void **)&tmpDN);
if (filter->numSearchSubs)
if (filter->num_search_subs)
slapi_ch_free((void **)&tmpSearch);
return retval;
}
PRIVATE INLINE BOOL
urlLoopBValues(Slapi_PBlock *pb, UrlFilter *filter, BerVal **bvals, char *type)
PRIVATE INLINE int
loop_ber_values(Slapi_PBlock *pb, URL_Filter *filter, BerVal **bvals, char *type)
{
while (*bvals)
{
if (urlTestFilter(pb, filter, type, (*bvals)->bv_val, (*bvals)->bv_len))
return TRUE;
if (test_filter(pb, filter, type, (*bvals)->bv_val, (*bvals)->bv_len))
return 1;
bvals++;
}
return FALSE;
return 0;
}
@ -275,18 +277,18 @@ urlLoopBValues(Slapi_PBlock *pb, UrlFilter *filter, BerVal **bvals, char *type)
* Handle ADD operations.
*/
PUBLIC int
urlAddFilter(Slapi_PBlock *pb)
eval_add_filter(Slapi_PBlock *pb)
{
UrlFilter *filter;
PluginAttrs *attrs;
URL_Filter *filter;
Plugin_Attrs *attrs;
Slapi_Entry *entry;
Slapi_Attr *att;
BerVal **bvals;
if (!getAddEntry(pb, &entry, PLUGIN_NAME))
if (!get_add_entry(pb, &entry, PLUGIN_NAME))
return (-1);
filter = urlFilters;
filter = url_filter_list;
while (filter)
{
attrs = filter->attrs;
@ -295,7 +297,7 @@ urlAddFilter(Slapi_PBlock *pb)
if (!slapi_entry_attr_find(entry, attrs->type, &att))
{
slapi_attr_get_values(att, &bvals);
if (urlLoopBValues(pb, filter, bvals, attrs->type))
if (loop_ber_values(pb, filter, bvals, attrs->type))
return (-1);
}
attrs = attrs->next;
@ -311,23 +313,23 @@ urlAddFilter(Slapi_PBlock *pb)
* Handle MOD operations.
*/
PUBLIC int
urlModFilter(Slapi_PBlock *pb)
eval_mod_filter(Slapi_PBlock *pb)
{
UrlFilter *filter;
URL_Filter *filter;
LDAPMod **mods, *mod;
if (!getModifyMods(pb, &mods, PLUGIN_NAME))
if (!get_modify_mods(pb, &mods, PLUGIN_NAME))
return (-1);
while ((mod = *mods))
{
if (!(mod->mod_op & LDAP_MOD_DELETE))
{
filter = urlFilters;
filter = url_filter_list;
while (filter)
{
if (listHasAttribute(filter->attrs, mod->mod_type) &&
urlLoopBValues(pb, filter, mod->mod_bvalues, mod->mod_type))
if (list_has_attribute(filter->attrs, mod->mod_type) &&
loop_ber_values(pb, filter, mod->mod_bvalues, mod->mod_type))
return (-1);
filter = filter->next;
@ -344,17 +346,17 @@ urlModFilter(Slapi_PBlock *pb)
* Register the pre-op functions.
*/
PUBLIC int
urlPlugInit(Slapi_PBlock *pb)
url_filter_init(Slapi_PBlock *pb)
{
char **argv;
int argc;
UrlFilter *new, *last;
URL_Filter *new, *last;
if (!getSlapiArgs(pb, &argc, &argv, 3, PLUGIN_NAME))
if (!get_slapi_args(pb, &argc, &argv, 3, PLUGIN_NAME))
return (-1);
/* Allocate memory for the new Filter rule. */
if (!(new = (UrlFilter *)slapi_ch_malloc(sizeof(UrlFilter))))
if (!(new = (URL_Filter *)slapi_ch_malloc(sizeof(URL_Filter))))
{
slapi_log_error(LOG_FACILITY, PLUGIN_NAME, ERR_MALLOC);
@ -362,10 +364,10 @@ urlPlugInit(Slapi_PBlock *pb)
}
/* Create the new filter, using the filter options in argv. */
new->next = (UrlFilter *)NULL;
new->attrs = (PluginAttrs *)NULL;
new->match = (*(argv[1]) == '0' ? FALSE : TRUE);
if (!urlCreateFilter(new, argv[0], argv[2]) || !new || !new->attrs)
new->next = (URL_Filter *)NULL;
new->attrs = (Plugin_Attrs *)NULL;
new->match = (*(argv[1]) == '0' ? 0 : 1);
if (!create_filter(new, argv[0], argv[2]) || !new || !new->attrs)
{
slapi_ch_free((void **)&new);
slapi_log_error(LOG_FACILITY, PLUGIN_NAME, ERR_SYNTAX);
@ -374,7 +376,7 @@ urlPlugInit(Slapi_PBlock *pb)
}
/* Find the last filter in the chain of filters, and link in the new. */
if ((last = urlFilters))
if ((last = url_filter_list))
{
while (last && last->next)
last = last->next;
@ -382,18 +384,18 @@ urlPlugInit(Slapi_PBlock *pb)
last->next = new;
}
else
urlFilters = new;
urlNumFilters++;
url_filter_list = new;
url_num_filters++;
/* Ok, everything looks grovy, so let's register the filter, but
only if we haven't done so already... */
if (urlNumFilters > 1)
if (url_num_filters > 1)
return 0;
if (slapi_pblock_set(pb, SLAPI_PLUGIN_VERSION, SLAPI_PLUGIN_VERSION_01) ||
slapi_pblock_set(pb, SLAPI_PLUGIN_DESCRIPTION, &urlDesc) ||
slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_MODIFY_FN, (void *)&urlModFilter) ||
slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_ADD_FN, (void *)&urlAddFilter))
slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_MODIFY_FN, (void *)&eval_mod_filter) ||
slapi_pblock_set(pb, SLAPI_PLUGIN_PRE_ADD_FN, (void *)&eval_add_filter))
{
slapi_log_error(LOG_FACILITY, PLUGIN_NAME, ERR_REG);