From 3d4047c6957a005dab1e3268450f3363de9c47ca Mon Sep 17 00:00:00 2001 From: Nadezhda Ivanova Date: Wed, 30 Oct 2013 19:40:14 +0200 Subject: [PATCH] instancetype overlay initial implementation. --- contrib/slapd-modules/samba4/Makefile | 9 +- contrib/slapd-modules/samba4/instancetype.c | 115 ++++++++++++++++++++ 2 files changed, 122 insertions(+), 2 deletions(-) create mode 100644 contrib/slapd-modules/samba4/instancetype.c diff --git a/contrib/slapd-modules/samba4/Makefile b/contrib/slapd-modules/samba4/Makefile index 529c0e986e..a7cf7cbc32 100644 --- a/contrib/slapd-modules/samba4/Makefile +++ b/contrib/slapd-modules/samba4/Makefile @@ -23,11 +23,12 @@ CC = gcc OPT = -g -O2 -Wall DEFS = -DSLAPD_OVER_RDNVAL=SLAPD_MOD_DYNAMIC \ -DSLAPD_OVER_PGUID=SLAPD_MOD_DYNAMIC \ - -DSLAPD_OVER_VERNUM=SLAPD_MOD_DYNAMIC + -DSLAPD_OVER_VERNUM=SLAPD_MOD_DYNAMIC \ + -DSLAPD_OVER_INSTANCETYPE=SLAPD_MOD_DYNAMIC INCS = $(LDAP_INC) LIBS = $(LDAP_LIB) -PROGRAMS = pguid.la rdnval.la vernum.la +PROGRAMS = pguid.la rdnval.la vernum.la instancetype.la LTVER = 0:0:0 prefix=/usr/local @@ -57,6 +58,10 @@ vernum.la: vernum.lo $(LIBTOOL) --mode=link $(CC) $(OPT) -version-info $(LTVER) \ -rpath $(moduledir) -module -o $@ $? $(LIBS) +instancetype.la: instancetype.lo + $(LIBTOOL) --mode=link $(CC) $(OPT) -version-info $(LTVER) \ + -rpath $(moduledir) -module -o $@ $? $(LIBS) + clean: rm -rf *.o *.lo *.la .libs diff --git a/contrib/slapd-modules/samba4/instancetype.c b/contrib/slapd-modules/samba4/instancetype.c new file mode 100644 index 0000000000..5793c58cb7 --- /dev/null +++ b/contrib/slapd-modules/samba4/instancetype.c @@ -0,0 +1,115 @@ +/* $OpenLDAP$ */ +/* This work is part of OpenLDAP Software . + * + * Copyright 1998-2013 The OpenLDAP Foundation. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted only as authorized by the OpenLDAP + * Public License. + * + * A copy of this license is available in the file LICENSE in the + * top-level directory of the distribution or, alternatively, at + * . + */ + +/* This is a simple overlay to make sure all newly created objects + have the correct instanceType */ + +#include "portable.h" + +#ifdef SLAPD_OVER_INSTANCETYPE + +#include + +#include "ac/string.h" +#include "ac/socket.h" + +#include "slap.h" +#include "config.h" + +#include "lutil.h" +#include "ldap_rq.h" + + +/* instanceType flags */ +#define INSTANCE_TYPE_IS_NC_HEAD 0x00000001 +#define INSTANCE_TYPE_UNINSTANT 0x00000002 +#define INSTANCE_TYPE_WRITE 0x00000004 +#define INSTANCE_TYPE_NC_ABOVE 0x00000008 +#define INSTANCE_TYPE_NC_COMING 0x00000010 +#define INSTANCE_TYPE_NC_GOING 0x00000020 + + +static slap_overinst instance_type; + + +static int instancetype_op_add( Operation *op, SlapReply *rs ) +{ + Attribute *instance_attribute; + AttributeDescription *instancetype_descr; + int rc; + const char *text = NULL; + Debug(LDAP_DEBUG_ANY, "instancetype_op_add\n",0,0,0); + rc = slap_str2ad( "instanceType", &instancetype_descr, &text ); + if ( rc != LDAP_SUCCESS ) { + Debug( LDAP_DEBUG_ANY, "instancetype: unable to find attribute 'instanceType' (%d: %s, %d)\n", + rc, text, 0); + return LDAP_NO_SUCH_ATTRIBUTE; + } + instance_attribute = attr_find( op->ora_e->e_attrs, instancetype_descr); + if ( instance_attribute == NULL ) { + int instance_flags = INSTANCE_TYPE_WRITE; + char itflags_buf[ LDAP_PVT_INTTYPE_CHARS( unsigned long ) ]; + int itflags_len = sprintf(itflags_buf, "%0X", instance_flags); + struct berval it_val; + + if (itflags_len <= 0) { + // todo actually handle error here + return SLAP_CB_CONTINUE; + } + it_val.bv_len = itflags_len; + it_val.bv_val = ber_bvstr(itflags_buf); + attr_merge_one(op->ora_e, instancetype_descr, &it_val, NULL); + return SLAP_CB_CONTINUE; + + } + else { + if (instance_attribute->a_numvals != 1) { + // todo how to set error string? + return LDAP_UNWILLING_TO_PERFORM; + } + int flags_val = (int)strtol(instance_attribute->a_vals[0].bv_val,0,0); + if (flags_val & INSTANCE_TYPE_IS_NC_HEAD) { + if (!(flags_val & INSTANCE_TYPE_WRITE)) { + return LDAP_UNWILLING_TO_PERFORM; + } + } + // only 0 and INSTANCE_TYPE_WRITE allowed + else if ((flags_val !=0) && (flags_val != INSTANCE_TYPE_WRITE)) { + return LDAP_UNWILLING_TO_PERFORM; + } + // todo relax checks for dbcheck control? + return SLAP_CB_CONTINUE; + } + + return SLAP_CB_CONTINUE; +} + +int instancetype_initialize(void) +{ + instance_type.on_bi.bi_type = "instancetype"; + instance_type.on_bi.bi_op_add = instancetype_op_add; + Debug(LDAP_DEBUG_TRACE, "instancetype_initialize\n",0,0,0); + return overlay_register(&instance_type); +} + + +#if SLAPD_OVER_INSTANCETYPE == SLAPD_MOD_DYNAMIC +int init_module( int argc, char *argv[] ) +{ + return instancetype_initialize(); +} +#endif /* SLAPD_OVER_INSTANCETYPE == SLAPD_MOD_DYNAMIC */ + +#endif /*SLAPD_OVER_INSTANCETYPE*/ -- 2.34.1