-/******************************************************************************
+/* $OpenLDAP$ */
+/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
*
- * Copyright (C) 2000 Pierangelo Masarati, <ando@sys-net.it>
+ * Copyright 2000-2007 The OpenLDAP Foundation.
* All rights reserved.
*
- * Permission is granted to anyone to use this software for any purpose
- * on any computer system, and to alter it and redistribute it, subject
- * to the following restrictions:
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted only as authorized by the OpenLDAP
+ * Public License.
*
- * 1. The author is not responsible for the consequences of use of this
- * software, no matter how awful, even if they arise from flaws in it.
- *
- * 2. The origin of this software must not be misrepresented, either by
- * explicit claim or by omission. Since few users ever read sources,
- * credits should appear in the documentation.
- *
- * 3. Altered versions must be plainly marked as such, and must not be
- * misrepresented as being the original software. Since few users
- * ever read sources, credits should appear in the documentation.
- *
- * 4. This notice may not be removed or altered.
- *
- ******************************************************************************/
+ * A copy of this license is available in the file LICENSE in the
+ * top-level directory of the distribution or, alternatively, at
+ * <http://www.OpenLDAP.org/license.html>.
+ */
+/* ACKNOWLEDGEMENT:
+ * This work was initially developed by Pierangelo Masarati for
+ * inclusion in OpenLDAP Software.
+ */
#ifndef REWRITE_INT_H
#define REWRITE_INT_H
* These are required by every file of the library, so they're included here
*/
#include <ac/stdlib.h>
+#include <ac/string.h>
#include <ac/syslog.h>
#include <ac/regex.h>
#include <ac/socket.h>
#include <lber.h>
#include <ldap.h>
#include "../libldap/ldap-int.h"
-
+#include <lutil.h>
#include <avl.h>
#include <rewrite.h>
/*
* Submatch escape char
*/
-//#define REWRITE_SUBMATCH_ESCAPE '\\'
-#define REWRITE_SUBMATCH_ESCAPE '%'
+/* the '\' conflicts with slapd.conf parsing */
+/* #define REWRITE_SUBMATCH_ESCAPE '\\' */
+#define REWRITE_SUBMATCH_ESCAPE_ORIG '%'
+#define REWRITE_SUBMATCH_ESCAPE '$'
+#define IS_REWRITE_SUBMATCH_ESCAPE(c) \
+ ((c) == REWRITE_SUBMATCH_ESCAPE || (c) == REWRITE_SUBMATCH_ESCAPE_ORIG)
/*
* REGEX flags
#define REWRITE_FLAG_STOP '@'
#define REWRITE_FLAG_UNWILLING '#'
#define REWRITE_FLAG_GOTO 'G' /* requires an arg */
+#define REWRITE_FLAG_USER 'U' /* requires an arg */
+#define REWRITE_FLAG_MAX_PASSES 'M' /* requires an arg */
#define REWRITE_FLAG_IGNORE_ERR 'I'
/*
#define REWRITE_ACTION_UNWILLING 0x0002
#define REWRITE_ACTION_GOTO 0x0003
#define REWRITE_ACTION_IGNORE_ERR 0x0004
+#define REWRITE_ACTION_USER 0x0005
int la_type;
void *la_args;
};
* Builtin maps
*/
struct rewrite_builtin_map {
-#define REWRITE_BUILTIN_MAP_LDAP 0x0201
+#define REWRITE_BUILTIN_MAP 0x0200
int lb_type;
char *lb_name;
void *lb_private;
+ const rewrite_mapper *lb_mapper;
#ifdef USE_REWRITE_LDAP_PVT_THREADS
ldap_pvt_thread_mutex_t lb_mutex;
*/
struct rewrite_subst {
size_t lt_subs_len;
- struct berval **lt_subs;
+ struct berval *lt_subs;
int lt_num_submatch;
- struct rewrite_submatch **lt_submatch;
+ struct rewrite_submatch *lt_submatch;
};
/*
char *lr_pattern;
char *lr_subststring;
char *lr_flagstring;
- regex_t lr_regex;
+ regex_t lr_regex;
/*
* I was thinking about some kind of per-rule mutex, but there's
#define REWRITE_RECURSE 0x0001
#define REWRITE_EXEC_ONCE 0x0002
int lr_mode;
+ int lr_max_passes;
struct rewrite_action *lr_action;
};
Avlnode *ls_vars;
#ifdef USE_REWRITE_LDAP_PVT_THREADS
ldap_pvt_thread_rdwr_t ls_vars_mutex;
+ ldap_pvt_thread_mutex_t ls_mutex;
#endif /* USE_REWRITE_LDAP_PVT_THREADS */
+ int ls_count;
};
/*
*/
struct rewrite_var {
char *lv_name;
+ int lv_flags;
struct berval lv_value;
};
struct rewrite_op {
int lo_num_passes;
int lo_depth;
+#if 0 /* FIXME: not used anywhere! (debug? then, why strdup?) */
char *lo_string;
+#endif
char *lo_result;
Avlnode *lo_vars;
const void *lo_cookie;
*/
#define REWRITE_MAXPASSES 100
int li_max_passes;
+ int li_max_passes_per_rule;
/*
* Behavior in case a NULL or non-existent context is required
* PRIVATE *
***********/
+LDAP_REWRITE_V (struct rewrite_context*) rewrite_int_curr_context;
/*
* Maps
/*
* Parses a map (also in legacy 'x' version)
*/
-extern struct rewrite_map *
+LDAP_REWRITE_F (struct rewrite_map *)
rewrite_map_parse(
struct rewrite_info *info,
const char *s,
const char **end
);
-extern struct rewrite_map *
+LDAP_REWRITE_F (struct rewrite_map *)
rewrite_xmap_parse(
struct rewrite_info *info,
const char *s,
/*
* Resolves key in val by means of map (also in legacy 'x' version)
*/
-extern int
+LDAP_REWRITE_F (int)
rewrite_map_apply(
struct rewrite_info *info,
struct rewrite_op *op,
struct berval *val
);
-extern int
+LDAP_REWRITE_F (int)
rewrite_xmap_apply(
struct rewrite_info *info,
struct rewrite_op *op,
struct berval *val
);
+LDAP_REWRITE_F (int)
+rewrite_map_destroy(
+ struct rewrite_map **map
+);
+LDAP_REWRITE_F (int)
+rewrite_xmap_destroy(
+ struct rewrite_map **map
+);
+
+LDAP_REWRITE_F (void)
+rewrite_builtin_map_free(
+ void *map
+);
/*
* Submatch substitution
*/
/*
* Compiles a substitution pattern
*/
-extern struct rewrite_subst *
+LDAP_REWRITE_F (struct rewrite_subst *)
rewrite_subst_compile(
struct rewrite_info *info,
const char *result
* Substitutes a portion of rewritten string according to substitution
* pattern using submatches
*/
-extern int
+LDAP_REWRITE_F (int)
rewrite_subst_apply(
struct rewrite_info *info,
struct rewrite_op *op,
struct berval *val
);
+LDAP_REWRITE_F (int)
+rewrite_subst_destroy(
+ struct rewrite_subst **subst
+);
+
/*
* Rules
/*
* Compiles the rule and appends it at the running context
*/
-extern int
+LDAP_REWRITE_F (int)
rewrite_rule_compile(
struct rewrite_info *info,
struct rewrite_context *context,
* REWRITE_REGEXEC_UNWILL: rule matched; force 'unwilling to perform'
* REWRITE_REGEXEC_ERR: an error occurred
*/
-extern int
+LDAP_REWRITE_F (int)
rewrite_rule_apply(
struct rewrite_info *info,
struct rewrite_op *op,
char **result
);
+LDAP_REWRITE_F (int)
+rewrite_rule_destroy(
+ struct rewrite_rule **rule
+);
+
/*
* Sessions
*/
/*
* Fetches a struct rewrite_session
*/
-extern struct rewrite_session *
+LDAP_REWRITE_F (struct rewrite_session *)
rewrite_session_find(
struct rewrite_info *info,
const void *cookie
/*
* Defines and inits a variable with session scope
*/
-extern int
-rewrite_session_var_set(
+LDAP_REWRITE_F (int)
+rewrite_session_var_set_f(
struct rewrite_info *info,
const void *cookie,
const char *name,
- const char *value
+ const char *value,
+ int flags
);
/*
* Gets a var with session scope
*/
-extern int
+LDAP_REWRITE_F (int)
rewrite_session_var_get(
struct rewrite_info *info,
const void *cookie,
/*
* Deletes a session
*/
-extern int
+LDAP_REWRITE_F (int)
rewrite_session_delete(
struct rewrite_info *info,
const void *cookie
/*
* Destroys the cookie tree
*/
-extern int
+LDAP_REWRITE_F (int)
rewrite_session_destroy(
struct rewrite_info *info
);
/*
* Finds a var
*/
-extern struct rewrite_var *
+LDAP_REWRITE_F (struct rewrite_var *)
rewrite_var_find(
Avlnode *tree,
const char *name
);
+/*
+ * Replaces the value of a variable
+ */
+LDAP_REWRITE_F (int)
+rewrite_var_replace(
+ struct rewrite_var *var,
+ const char *value,
+ int flags
+);
+
/*
* Inserts a newly created var
*/
-extern struct rewrite_var *
-rewrite_var_insert(
+LDAP_REWRITE_F (struct rewrite_var *)
+rewrite_var_insert_f(
Avlnode **tree,
const char *name,
- const char *value
+ const char *value,
+ int flags
);
+#define rewrite_var_insert(tree, name, value) \
+ rewrite_var_insert_f((tree), (name), (value), \
+ REWRITE_VAR_UPDATE|REWRITE_VAR_COPY_NAME|REWRITE_VAR_COPY_VALUE)
+
/*
* Sets/inserts a var
*/
-extern struct rewrite_var *
-rewrite_var_set(
+LDAP_REWRITE_F (struct rewrite_var *)
+rewrite_var_set_f(
Avlnode **tree,
const char *name,
const char *value,
- int insert
+ int flags
);
+#define rewrite_var_set(tree, name, value, insert) \
+ rewrite_var_set_f((tree), (name), (value), \
+ REWRITE_VAR_UPDATE|REWRITE_VAR_COPY_NAME|REWRITE_VAR_COPY_VALUE|((insert)? REWRITE_VAR_INSERT : 0))
+
/*
* Deletes a var tree
*/
-extern int
+LDAP_REWRITE_F (int)
rewrite_var_delete(
Avlnode *tree
);
/*
* Finds the context named rewriteContext in the context tree
*/
-extern struct rewrite_context *
+LDAP_REWRITE_F (struct rewrite_context *)
rewrite_context_find(
struct rewrite_info *info,
const char *rewriteContext
/*
* Creates a new context called rewriteContext and stores in into the tree
*/
-extern struct rewrite_context *
+LDAP_REWRITE_F (struct rewrite_context *)
rewrite_context_create(
struct rewrite_info *info,
const char *rewriteContext
* STOP: fine, rule matched; stop processing following rules
* UNWILL: rule matched; force 'unwilling to perform'
*/
-extern int
+LDAP_REWRITE_F (int)
rewrite_context_apply(
struct rewrite_info *info,
struct rewrite_op *op,
char **result
);
+LDAP_REWRITE_F (int)
+rewrite_context_destroy(
+ struct rewrite_context **context
+);
+
+LDAP_REWRITE_F (void)
+rewrite_context_free(
+ void *tmp
+);
+
#endif /* REWRITE_INT_H */