diff options
author | cvsadm <cvsadm> | 2005-01-21 00:44:34 +0000 |
---|---|---|
committer | cvsadm <cvsadm> | 2005-01-21 00:44:34 +0000 |
commit | b2093e3016027d6b5cf06b3f91f30769bfc099e2 (patch) | |
tree | cf58939393a9032182c4fbc4441164a9456e82f8 /ldap/servers/slapd/ava.c | |
download | ds-b2093e3016027d6b5cf06b3f91f30769bfc099e2.tar.gz ds-b2093e3016027d6b5cf06b3f91f30769bfc099e2.tar.xz ds-b2093e3016027d6b5cf06b3f91f30769bfc099e2.zip |
Moving NSCP Directory Server from DirectoryBranch to TRUNK, initial drop. (foxworth)ldapserver7x
Diffstat (limited to 'ldap/servers/slapd/ava.c')
-rw-r--r-- | ldap/servers/slapd/ava.c | 129 |
1 files changed, 129 insertions, 0 deletions
diff --git a/ldap/servers/slapd/ava.c b/ldap/servers/slapd/ava.c new file mode 100644 index 00000000..9831315c --- /dev/null +++ b/ldap/servers/slapd/ava.c @@ -0,0 +1,129 @@ +/** BEGIN COPYRIGHT BLOCK + * Copyright 2001 Sun Microsystems, Inc. + * Portions copyright 1999, 2001-2003 Netscape Communications Corporation. + * All rights reserved. + * END COPYRIGHT BLOCK **/ +/* ava.c - routines for dealing with attribute value assertions */ + +#include <stdio.h> +#include <string.h> +#include <sys/types.h> +#ifndef _WIN32 +#include <sys/socket.h> +#endif +#include "slap.h" + +static void strcpy_special_undo(); + +int +get_ava( + BerElement *ber, + struct ava *ava +) +{ + char *type; + + if ( ber_scanf( ber, "{ao}", &type, &ava->ava_value ) + == LBER_ERROR ) { + LDAPDebug( LDAP_DEBUG_ANY, " get_ava ber_scanf\n", 0, 0, 0 ); + return( LDAP_PROTOCOL_ERROR ); + } + ava->ava_type = slapi_attr_syntax_normalize(type); + free( type ); + + return( 0 ); +} + +void +ava_done( + struct ava *ava +) +{ + slapi_ch_free( (void**)&(ava->ava_type) ); + slapi_ch_free( (void**)&(ava->ava_value.bv_val) ); +} + +int +rdn2ava( + char *rdn, + struct ava *ava +) +{ + char *s; + + if ( (s = strchr( rdn, '=' )) == NULL ) { + return( -1 ); + } + *s++ = '\0'; + + ava->ava_type = rdn; + strcpy_special_undo( s, s ); + ava->ava_value.bv_val = s; + ava->ava_value.bv_len = strlen( s ); + + return( 0 ); +} + +/* +** This function takes a quoted attribute value of the form "abc", +** and strips off the enclosing quotes. It also deals with quoted +** characters by removing the preceeding '\' character. +** +*/ +static void +strcpy_special_undo( char *d, const char *s ) +{ + const char *end = s + strlen(s); + for ( ; *s; s++ ) + { + switch ( *s ) + { + case '"': + break; + case '\\': + { + /* + * The '\' could be escaping a single character, ie \" + * or could be escaping a hex byte, ie \01 + */ + int singlecharacter= 1; + if ( s+2 < end ) + { + int n = hexchar2int( s[1] ); + if ( n >= 0 ) + { + int n2 = hexchar2int( s[2] ); + if ( n2 >= 0 ) + { + singlecharacter= 0; + n = (n << 4) + n2; + if (n == 0) + { + /* don't change \00 */ + *d++ = *++s; + *d++ = *++s; + } + else + { + /* change \xx to a single char */ + ++s; + *(unsigned char*)(s+1) = n; + } + } + } + } + if(singlecharacter) + { + s++; + *d++ = *s; + } + break; + } + default: + *d++ = *s; + break; + } + } + *d = '\0'; +} + |