From 18e0bcb7dea29a9031e921e782c8d52c7149836c Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 13 Dec 2018 05:44:46 -0800 Subject: [PATCH] Add MS AD persistent search ctrl --- clients/tools/ldapsearch.c | 42 +++++++++++++++++++++++++++++++++++++- include/ldap.h | 8 ++++++++ libraries/libldap/msctrl.c | 18 ++++++++++++++++ 3 files changed, 67 insertions(+), 1 deletion(-) diff --git a/clients/tools/ldapsearch.c b/clients/tools/ldapsearch.c index 7d8ab86b02..96cc505a4e 100644 --- a/clients/tools/ldapsearch.c +++ b/clients/tools/ldapsearch.c @@ -148,6 +148,9 @@ usage( void ) #endif #ifdef LDAP_CONTROL_X_SHOW_DELETED fprintf( stderr, _(" [!]showDeleted (MS AD Show Deleted)\n")); +#endif +#ifdef LDAP_CONTROL_X_SERVER_NOTIFICATION + fprintf( stderr, _(" [!]serverNotif (MS AD Server Notification)\n")); #endif fprintf( stderr, _(" [!][=:] (generic control; no response handling)\n")); fprintf( stderr, _(" -f file read operations from `file'\n")); @@ -271,6 +274,10 @@ static int extendedDnFlag; static int showDeleted; #endif +#ifdef LDAP_CONTROL_X_SERVER_NOTIFICATION +static int serverNotif; +#endif + static int ctrl_add( void ) { @@ -698,7 +705,7 @@ handle_private_option( int i ) } *cookiep = '\0'; } - num = sscanf( cvalue, "%d", &tmp ); + num = sscanf( cvalue, "%i", &tmp ); if ( num != 1 ) { fprintf( stderr, _("Invalid value for dirSync, %s.\n"), @@ -760,6 +767,23 @@ handle_private_option( int i ) showDeleted = 1 + crit; #endif /* LDAP_CONTROL_X_SHOW_DELETED */ +#ifdef LDAP_CONTROL_X_SERVER_NOTIFICATION + } else if ( strcasecmp( control, "serverNotif" ) == 0 ) { + int num, tmp; + if( serverNotif ) { + fprintf( stderr, + _("serverNotif control previously specified\n")); + exit( EXIT_FAILURE ); + } + if ( cvalue != NULL ) { + fprintf( stderr, + _("serverNotif: no control value expected\n") ); + usage(); + } + + serverNotif = 1 + crit; +#endif /* LDAP_CONTROL_X_SERVER_NOTIFICATION */ + } else if ( tool_is_oid( control ) ) { if ( c != NULL ) { int i; @@ -1067,6 +1091,9 @@ getNextPage: #endif #ifdef LDAP_CONTROL_X_SHOW_DELETED || showDeleted +#endif +#ifdef LDAP_CONTROL_X_SERVER_NOTIFICATION + || serverNotif #endif || domainScope || pagedResults @@ -1313,6 +1340,19 @@ getNextPage: c[i].ldctl_iscritical = showDeleted > 1; i++; } +#endif +#ifdef LDAP_CONTROL_X_SERVER_NOTIFICATION + if ( serverNotif ) { + if ( ctrl_add() ) { + tool_exit( ld, EXIT_FAILURE ); + } + + c[i].ldctl_oid = LDAP_CONTROL_X_SERVER_NOTIFICATION; + c[i].ldctl_value.bv_val = NULL; + c[i].ldctl_value.bv_len = 0; + c[i].ldctl_iscritical = serverNotif > 1; + i++; + } #endif } diff --git a/include/ldap.h b/include/ldap.h index c58c576d3a..d32207f7f9 100644 --- a/include/ldap.h +++ b/include/ldap.h @@ -346,6 +346,7 @@ typedef struct ldapcontrol { #define LDAP_CONTROL_X_TREE_DELETE "1.2.840.113556.1.4.805" /* MS Active Directory controls - not implemented in slapd(8) */ +#define LDAP_CONTROL_X_SERVER_NOTIFICATION "1.2.840.113556.1.4.528" #define LDAP_CONTROL_X_EXTENDED_DN "1.2.840.113556.1.4.529" #define LDAP_CONTROL_X_SHOW_DELETED "1.2.840.113556.1.4.417" #define LDAP_CONTROL_X_DIRSYNC "1.2.840.113556.1.4.841" @@ -2604,6 +2605,13 @@ ldap_create_show_deleted_control LDAP_P(( LDAPControl **ctrlp )); #endif /* LDAP_CONTROL_X_SHOW_DELETED */ +#ifdef LDAP_CONTROL_X_SERVER_NOTIFICATION +LDAP_F( int ) +ldap_create_server_notification_control LDAP_P(( + LDAP *ld, + LDAPControl **ctrlp )); +#endif /* LDAP_CONTROL_X_SERVER_NOTIFICATION */ + /* * in assertion.c */ diff --git a/libraries/libldap/msctrl.c b/libraries/libldap/msctrl.c index 2137cc9628..aa6a39c4cb 100644 --- a/libraries/libldap/msctrl.c +++ b/libraries/libldap/msctrl.c @@ -260,3 +260,21 @@ ldap_create_extended_dn_control( } #endif /* LDAP_CONTROL_X_EXTENDED_DN */ + +#ifdef LDAP_CONTROL_X_SERVER_NOTIFICATION + +int +ldap_create_sever_notification_control( LDAP *ld, + LDAPControl **ctrlp ) +{ + assert( ld != NULL ); + assert( LDAP_VALID( ld ) ); + assert( ctrlp != NULL ); + + ld->ld_errno = ldap_control_create( LDAP_CONTROL_X_SERVER_NOTIFICATION, + 0, NULL, 0, ctrlp ); + + return ld->ld_errno; +} + +#endif /* LDAP_CONTROL_X_SERVER_NOTIFICATION */