Ejemplo n.º 1
0
static int
nullsuffix_search( Slapi_PBlock *pb )
{
	char			*dn_base, **attrs, *newStr;
	int				scope, sizelimit, timelimit, deref, attrsonly;
	Slapi_Filter	*filter;
	Slapi_DN		*sdn_base;
	int				ldaperr = LDAP_SUCCESS;	/* optimistic */
	int				nentries = 0;	/* entry count */
	int				i;
	Slapi_Operation	*op;
	Slapi_Entry		*e;

	const char *entrystr =
		"dn:cn=Joe Smith,o=Example\n"
		"objectClass: top\n"
		"objectClass: person\n"
		"objectClass: organizationalPerson\n"
		"objectClass: inetOrgPerson\n"
		"cn:Joe Smith\n"
		"sn:Smith\n"
		"uid:jsmith\n"
		"mail:[email protected]\n";
	
	slapi_log_error( SLAPI_LOG_PLUGIN, PLUGIN_NAME, "nullsuffix_search\n" );
	if( slapi_op_reserved(pb) ){
		return PLUGIN_OPERATION_IGNORED;
	}

	/* get essential search parameters */
	if ( slapi_pblock_get( pb, SLAPI_SEARCH_TARGET, &dn_base ) != 0 ||
			slapi_pblock_get( pb, SLAPI_SEARCH_SCOPE, &scope ) != 0 ) {
		slapi_log_error( SLAPI_LOG_PLUGIN, PLUGIN_NAME,
				"could not get base DN and scope search parameters\n" );
	}
	if ( dn_base == NULL ) {
		dn_base = "";
	}
	sdn_base = slapi_sdn_new_dn_byval( dn_base );
	slapi_pblock_get(pb, SLAPI_OPERATION, &op);

	/* get remaining search parameters */
	if ( slapi_pblock_get( pb, SLAPI_SEARCH_DEREF, &deref ) != 0 ||
			slapi_pblock_get( pb, SLAPI_SEARCH_SIZELIMIT, &sizelimit ) != 0 ||
			slapi_pblock_get( pb, SLAPI_SEARCH_TIMELIMIT, &timelimit ) != 0 ||
			slapi_pblock_get( pb, SLAPI_SEARCH_FILTER, &filter ) != 0 ||
			slapi_pblock_get( pb, SLAPI_SEARCH_ATTRS, &attrs ) != 0 ||
			slapi_pblock_get( pb, SLAPI_SEARCH_ATTRSONLY, &attrsonly ) != 0 ) {
		slapi_log_error( SLAPI_LOG_PLUGIN, PLUGIN_NAME,
				"could not get remaining search parameters\n" );
	}

	if ( slapi_pblock_get( pb, SLAPI_OPERATION, &op ) != 0 ) {
		slapi_log_error( SLAPI_LOG_PLUGIN, PLUGIN_NAME,
				"could not get operation\n" );
	} else {
		 slapi_operation_set_flag(op, SLAPI_OP_FLAG_NO_ACCESS_CHECK  );
	}

	/* create a fake entry and send it along */
	newStr = slapi_ch_strdup( entrystr );
	if ( NULL == ( e = slapi_str2entry( newStr,
				SLAPI_STR2ENTRY_ADDRDNVALS
				| SLAPI_STR2ENTRY_EXPAND_OBJECTCLASSES ))) {
		slapi_log_error( SLAPI_LOG_PLUGIN, PLUGIN_NAME,
				"nullsuffix_search: slapi_str2entry() failed\n" );
	} else {
		slapi_send_ldap_search_entry( pb, e, NULL /* controls */,
				attrs, attrsonly );
		++nentries;
		slapi_entry_free( e );
	}

	slapi_send_ldap_result( pb, ldaperr, NULL, "kilroy was here",
			nentries, NULL );
	slapi_log_error( SLAPI_LOG_PLUGIN, PLUGIN_NAME, "nullsuffix_search:"
			" handled search based at %s with scope %d; ldaperr=%d\n",
			dn_base, scope, ldaperr );

	slapi_ch_free_string(&newStr);
	slapi_sdn_free(&sdn_base);

	return PLUGIN_OPERATION_HANDLED;
}
Ejemplo n.º 2
0
int sync_srch_refresh_pre_search(Slapi_PBlock *pb)
{

	LDAPControl **requestcontrols;
	struct berval	*psbvp;
	Sync_Cookie *client_cookie = NULL;
	Sync_Cookie *session_cookie = NULL;
	int 	rc = 0;
	int sync_persist = 0;
	PRThread *tid = NULL;
	int entries_sent = 0;

	slapi_pblock_get (pb, SLAPI_REQCONTROLS, &requestcontrols);
	if ( slapi_control_present( requestcontrols, LDAP_CONTROL_SYNC, &psbvp, NULL )){
		char *cookie = NULL;
		int mode = 1;
		int refresh = 0;

		if ( sync_parse_control_value( psbvp, &mode,
									 &refresh, &cookie ) != LDAP_SUCCESS )
		{
			rc = 1;
			goto error_return;
		} else {
			/* control is valid, check if usere is allowed to perform sync searches */
			rc = sync_feature_allowed(pb);
			if (rc) {
				sync_result_err(pb,rc,NULL);
				goto error_return;
			}
		}

		if ( mode == 1 || mode == 3 )
		{

			/* we need to return a cookie in the result message
			 * indicating a state to be used in future sessions
			 * as starting point - create it now
			 */
			session_cookie = sync_cookie_create(pb);
			/*
			 *  if mode is persist we need to setup the persit handler
			 * to catch the mods while the refresh is done 
			 */
			if ( mode == 3 )
			{
				tid = sync_persist_add(pb);
				if ( tid ) 
					sync_persist = 1;
				else {
					rc = LDAP_UNWILLING_TO_PERFORM;
					sync_result_err(pb,rc,"Too many active synchronization sessions");
					goto error_return;
				}
			}
			/* 
			 * now handl the refresh request
			 * there are two scenarios
			 * 1. no cookie is provided this means send all entries matching the search request
			 * 2. a cookie is provided: send all entries changed since the cookie was issued
			 * 	-- return an error if the cookie is invalid
			 * 	-- return e-syncRefreshRequired if the data referenced in the cookie are no
			 * 		longer in the history
			*/
			if (cookie) {
				if ((client_cookie = sync_cookie_parse (cookie)) &&
				    sync_cookie_isvalid(client_cookie, session_cookie))
				{
					rc = sync_refresh_update_content(pb, client_cookie, session_cookie);
					if (rc == 0) 
						entries_sent = 1;
					if (sync_persist)
						rc = sync_intermediate_msg(pb, LDAP_TAG_SYNC_REFRESH_DELETE, session_cookie, NULL);
					else
						rc = sync_result_msg(pb, session_cookie);
				} else {
					rc = E_SYNC_REFRESH_REQUIRED;
					sync_result_err(pb,rc, "Invalid session cookie");
				}
			} else {
				rc = sync_refresh_initial_content (pb, sync_persist,  tid, session_cookie);
				if (rc == 0 && !sync_persist)
					/* maintained in postop code */
					session_cookie = NULL;
					/* if persis it will be handed over to persist code */
			}
			
			if ( rc ) {
				if (sync_persist)
					sync_persist_terminate (tid);
				goto error_return;
			} else if (sync_persist){
				Slapi_Operation *operation;

				slapi_pblock_get(pb, SLAPI_OPERATION, &operation);
				if (client_cookie) {
					rc = sync_persist_startup(tid, session_cookie);
				}
				if (rc == 0) {
					session_cookie = NULL; /* maintained in persist code */
					slapi_operation_set_flag(operation, OP_FLAG_SYNC_PERSIST);
				}
			}
			

		} else {
			/* unknown mode, return an error */
			rc = 1;
		}
error_return:
	sync_cookie_free(&client_cookie);
	sync_cookie_free(&session_cookie);
	slapi_ch_free((void **)&cookie);
	}

	/* if we sent the entries
	 * return "error" to abort normal search
	 */ 
	if (  entries_sent > 0 ) {
		return(1);
	} else {
		return(rc);
	}
}