Groups > Novell > NDS Client > Re: NWDSPutFilter returns 0xFEA5 (-347) -- SOLVED




NWDSPutFilter returns 0xFEA5 (-347)

NWDSPutFilter returns 0xFEA5 (-347)
Sat, 20 Aug 2005 17:35:02 GMT
In attempting to search the NDS tree from [Root], NWDSPutFilter
consistently returns -347 (0xFEA5 - ERR_SCHEMA_NAME_TOO_LONG).  

The client is v 4.90 sp2 on a Win2K box. The server is NetWare 6.5.  Below
is the relevant segment of code.  (Sorry for the length.)

All calls to addObjectClassToSearch with the pszClassName parameter set to
one of "Country", "Organization", "Organizational
Unit", and "NDPS
Printer" all return true - successfully created Filter Cursor.

Any call to completeSearch with the pszSubTree parameter set to
"[Root]",
or to an explicit (valid) path, such as .orgunit1.orgname.

Can anyone shed some light on what the error code means and why it is
occurring?  

Thanks, in advance.

Gord

..
  pSearch = prepareSearch (hWndTree, pQueueContext);
  if (pSearch != NULL)
  {
    if (addObjectClassToSearch (hWndTree, pSearch, "Country"))
    {
      if (completeSearch (pSearch, hWndTree, pszStart))
      {
        for (int i = 0; i < pSearch->ndsList.count; i++)
        {
          hti = AddTreeItem (hWndTree, hItem, iLevel, true, false, false,
false, pSearch->ndsList.list[i]);
          AddTreeItem (hWndTree, hti, iLevel + 1, false, false, false,
false, ".");
        }
      }
    }

    cleanupSearch (pSearch);
  }

..

.. 
prepareSearch (HWND hWnd, LPQUEUE_CONTEXT pQueueContext)
{
..
// code to create context
ndsCode = NWDSCreateContextHandle (&(pQueueContext->context));
if (ndsCode != SUCCESSFUL)
{
  TCHAR szErr[256];

  NWNetTerm (NULL);
  NWCallsTerm (NULL);

  wsprintf (szErr, TEXT ("NWDSCreateContextHandle failed (Error Code:
0x%04lX)"), (DWORD)ndsCode);
  MessageBox (NULL, szErr, TEXT ("..."), MB_OK | MB_ICONHAND);

}

  NWDSGetContext (pQueueContext->context, DCK_FLAGS, &flags);
  flags &= ~DCV_XLATE_STRINGS;  // needed, since this context will be used
                                // in NDPS calls
  flags |= DCV_TYPELESS_NAMES;
  flags &= ~DCV_CANONICALIZE_NAMES;

  NWDSSetContext (pQueueContext->context, DCK_FLAGS, &flags);

..
  return pQueueContext;
}

bool addObjectClassToSearch (HWND hWnd, LPSEARCH_STRUCT pSearch, char
*pszClassName)
{
  NWDSCCODE         ccode;
  nstr8 szTemp[2 * (MAX_DN_CHARS + 1)];
  nuint32 syntaxID;
  char *pszObjectClass = "Object Class";

   /* Allocate space for the search filter - pCur holds the filter
      cursor data.  */
  ccode = NWDSAllocFilter(&(pSearch->pFilterCur)); 
//pSearch->pFilterCur
is pFilter_Cursor_T

  if(ccode)
  {
    TCHAR szMsg[256];

    sprintf(szMsg, "Failed to allocate search filter (NWDSAllocFilter
returned %X)", ccode);
    MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK | MB_ICONWARNING);

    return false;
   }

   toUnicode (pSearch->pQueueContext, pszObjectClass, szTemp, sizeof
(szTemp));

   /* Add a node to the search filter expression tree. pCur is the
      filter cursor, FTOK_ANAME indicates that an attribute name is
      being added, the attribute name "Object Class" is next, and the
      syntax for the attribute, SYN_CLASS_NAME is last */

   ccode = NWDSGetSyntaxID (pSearch->pQueueContext->context, szTemp,
&syntaxID);
   if (ccode)
   {
     TCHAR szMsg[256];
     sprintf(szMsg, "Failed to lookup syntax ID for token name
"%s"
(NWDSGetSyntaxID returned %X)", pszObjectClass, ccode);
     MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK | MB_ICONWARNING);

     NWDSFreeFilter (pSearch->pFilterCur, NULL);
     return false;
   }

   ccode = NWDSAddFilterToken (pSearch->pFilterCur, FTOK_LPAREN, NULL, 0);
   if (ccode)
   {
      TCHAR szMsg[256];

      sprintf(szMsg, "Failed to add token LPAREN to filter buffer
(NWDSAddFilterToken returned %X)", ccode);
      MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK | MB_ICONWARNING);

      NWDSFreeFilter (pSearch->pFilterCur, NULL);
      return false;
   }

   ccode = NWDSAddFilterToken(pSearch->pFilterCur, FTOK_ANAME, szTemp,
syntaxID);//SYN_CLASS_NAME);
   if(ccode)
   {
      TCHAR szMsg[256];

      sprintf(szMsg, "Failed to add token name "%s" to filter
buffer
(NWDSAddFilterToken returned %X)", pszObjectClass, ccode);
      MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK | MB_ICONWARNING);

      NWDSFreeFilter (pSearch->pFilterCur, NULL);
      return false;
   }

   /* Add the equal relational operator next */
   ccode = NWDSAddFilterToken(pSearch->pFilterCur, FTOK_EQ, NULL, 0);
   if(ccode)
   {
     TCHAR szMsg[256];

     sprintf(szMsg, "Failed to add token FTOK_EQ to filter buffer
(NWDSAddFilterToken returned %X)", ccode);
     MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK | MB_ICONWARNING);

     NWDSFreeFilter (pSearch->pFilterCur, NULL);
     return false;
   }

   toUnicode (pSearch->pQueueContext, pszClassName, szTemp, sizeof
(szTemp));
  
  /* USE FTOK_AVAL to indicate that a value token is being placed and
      pass strVal since it contains the class value */
   ccode = NWDSAddFilterToken(pSearch->pFilterCur, FTOK_AVAL, szTemp,
syntaxID);//SYN_CLASS_NAME);
   if(ccode)
   {
     TCHAR szMsg[256];

     sprintf(szMsg, "Failed to add token name "%s" to filter
buffer
(NWDSAddFilterToken returned %X)", pszClassName, ccode);
     MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK | MB_ICONWARNING);

     NWDSFreeFilter (pSearch->pFilterCur, NULL);
     return false;
   }

   ccode = NWDSAddFilterToken (pSearch->pFilterCur, FTOK_RPAREN, NULL, 0);
   if (ccode)
   {
     TCHAR szMsg[256];

     sprintf(szMsg, "Failed to add token RPAREN to filter buffer
(NWDSAddFilterToken returned %X)", ccode);
     MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK | MB_ICONWARNING);

     NWDSFreeFilter (pSearch->pFilterCur, NULL);
     return false;
   }

   /* USE FTOK_END to indicate the end of the expression */
   ccode = NWDSAddFilterToken(pSearch->pFilterCur, FTOK_END, NULL, 0);
   if(ccode)
   {
     TCHAR szMsg[256];

     sprintf(szMsg, "Failed to add token FTOK_END to filter buffer
(NWDSAddFilterToken returned %X)", ccode);
     MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK | MB_ICONWARNING);

     NWDSFreeFilter (pSearch->pFilterCur, NULL);
     return false;
   }

   return true;
}

bool completeSearch (LPSEARCH_STRUCT pSearch, HWND hWnd, const char
*pszSubTree)
{
   NWDSCCODE         ccode;
   pBuf_T            pBuf;
   nint32            lIterationHandle;// = NO_MORE_ITERATIONS;
   Object_Info_T     pObjectInfo;
   nuint32           luObjectCount;
   nuint32           luAttrCount;
   nuint   i;
   nstr8 szObjectName[2 * (MAX_DN_CHARS + 1)];
	nstr8 szTemp[2 * (MAX_DN_CHARS + 1)];
   nstr8 szCanonName[2 * (MAX_DN_CHARS + 1)];

	pSearch->ndsList.count = 0;
	pSearch->ndsList.list = NULL;

   /* Allocate the buffer to hold the search filter.  */
   ccode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &(pSearch->pFilterBuf));
   if(ccode)
   {
		TCHAR szMsg[256];

      sprintf(szMsg, "Failed to allocate search filter buffer
(NWDSAllocBuf returned %X)", ccode);
		MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK | MB_ICONWARNING);

		NWDSFreeFilter (pSearch->pFilterCur, NULL);
      return false;
   }

   ccode = NWDSInitBuf(pSearch->pQueueContext->context,
DSV_SEARCH_FILTER,
pSearch->pFilterBuf);
   if(ccode)
   {
		TCHAR szMsg[256];

      sprintf(szMsg, "Failed to initialize search filter buffer
(NWDSInitBuf returned %X)", ccode);
		MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK | MB_ICONWARNING);

		NWDSFreeFilter (pSearch->pFilterCur, NULL);
		return false;
   }

   /* Place finished search filter into the search input buffer */
   ccode = NWDSPutFilter(pSearch->pQueueContext->context,
pSearch->pFilterBuf, pSearch->pFilterCur, NULL);
   if(ccode)
   {
		TCHAR szMsg[256];

      sprintf(szMsg, "Failed to put search filter into search input buffer
(NWDSPutFilter returned %ld - 0x%X)", ccode, ccode);
		MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK | MB_ICONWARNING);

      return false;
   }

   /* Allocate the output buffer.  */
   ccode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &pBuf);
   if(ccode)
   {
		TCHAR szMsg[256];

      sprintf(szMsg, "Failed to allocate result buffer (NWDSAllocBuf
returned %X)", ccode);
		MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK | MB_ICONWARNING);

		return false;
   }

   /* Initialize filter for a DSV_SEARCH_FILTER operation */
   /* Do the search */
	toUnicode (pSearch->pQueueContext, (pnstr8)pszSubTree, szTemp, sizeof
(szTemp));

	ccode = NWDSCanonicalizeName (pSearch->pQueueContext->context, szTemp,
szCanonName);
	if (ccode)
	{
		TCHAR szMsg[256];

      sprintf(szMsg, "NWDSCanonicalizeName returned %X", ccode);
		MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK | MB_ICONWARNING);

		return false;
	}

	//strcpy (strAbbreviatedName, pszSubTree);

	lIterationHandle = NO_MORE_ITERATIONS;

   do
   {
      ccode = NWDSSearch(pSearch->pQueueContext->context,
                    szCanonName,   /* subtree to search      */
                    DS_SEARCH_SUBORDINATES,    /* scope is subtree       */
                    FALSE,                /* deref alias false      */
                    pSearch->pFilterBuf,              /* search filter    
     */
                    DS_ATTRIBUTE_VALUES,  /* info type to return    */
                    FALSE,                /* scope is false         */
                    NULL,                 /* attribute list is NULL */
                    &lIterationHandle,
                    0,
                    0,
                    pBuf);                /* buf for search result  */
      if(ccode)
      {
			TCHAR szMsg[256];

			sprintf(szMsg, "Failed to complete search (NWDSSearch returned %ld
[%X])", ccode, ccode);
			MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK | MB_ICONHAND);

			NWDSFreeBuf(pBuf);
			return false;
      }

      ccode = NWDSGetObjectCount(pSearch->pQueueContext->context, pBuf,
&luObjectCount);
      if(ccode)
      {
			TCHAR szMsg[256];

			sprintf(szMsg, "Failed to retrieve count of objects returned from
search (NWDSGetObjectCount returned %X)", ccode);
			MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK | MB_ICONHAND);

			NWDSFreeBuf(pBuf);
			return false;
      }

      if(0 == luObjectCount)
      {
			break;
      }

		if (pSearch->ndsList.count == 0)
		{
			pSearch->ndsList.list = (char **)calloc (luObjectCount, sizeof (char *));
			//*pppList = (char **)calloc (luObjectCount, sizeof (char *));
		}
		else
		{
			int newCount = pSearch->ndsList.count + (int)luObjectCount;
			char **ppNewList = (char **)calloc (newCount, sizeof (char *));

			memmove (ppNewList, pSearch->ndsList.list, pSearch->ndsList.count *
sizeof (char *));
//			(*pCount) += (int)luObjectCount;

			free (pSearch->ndsList.list);
			pSearch->ndsList.list = ppNewList;
		}

      /* For each object found, extract the name from the buffer */
      for (i = 0; i < luObjectCount; i++)
      {
         ccode = NWDSGetObjectName(pSearch->pQueueContext->context, pBuf,
szObjectName,
                                   &luAttrCount, &pObjectInfo);
         if(ccode)
         {
				TCHAR szMsg[256];

				sprintf(szMsg, "Failed to retrieve returned object name
(NWDSGetObjectName returned %X)", ccode);
				MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK | MB_ICONHAND);

				NWDSFreeBuf(pBuf);
				return false;
         }

			fromUnicode (pSearch->pQueueContext, szObjectName, szTemp, sizeof
(szTemp));

			pSearch->ndsList.list[pSearch->ndsList.count] = strdup (szTemp);
			pSearch->ndsList.count++;
      }

     /* loop back if more data */
   } while(lIterationHandle != NO_MORE_ITERATIONS);

   /* Clean up, normal termination */
   NWDSFreeBuf(pBuf);

   return true;
}

pnstr8 toUnicode (NWDSContextHandle context, pnstr8 strToXlate, pnstr8
unicodeXlateBuffer, nuint bufSize)
{
	nuint len;
	nint flags;

	NWDSGetContext (context, DCK_FLAGS, &flags);
	if (flags & DCV_XLATE_STRINGS)
	{
		strcpy (unicodeXlateBuffer, strToXlate);
	}
	else
	{
		NWLocalToUnicode (NWDPLocalToUnicodeHandleMac
(pQueueContext->accessorRef),
								(unicode *)unicodeXlateBuffer, 
								bufSize,
								(pnuint8)strToXlate, 0, &len);
	}

	return unicodeXlateBuffer;
}

pnstr8 fromUnicode (NWDSContextHandle context, pnstr8 unicodeStrToXlate,
pnstr8 xlateBuffer, nuint bufSize)
{
	nuint len;
	nint flags;

	NWDSGetContext (context, DCK_FLAGS, &flags);
	if (flags & DCV_XLATE_STRINGS)
	{
		strcpy (xlateBuffer, unicodeStrToXlate);
	}
	else
	{
		NWUnicodeToLocal (NWDPUnicodeToLocalHandleMac
(pQueueContext->accessorRef), (pnuint8)xlateBuffer, bufSize,
								(unicode *)unicodeStrToXlate, 0, &len);
	}

	return xlateBuffer;
}


Post Reply
Re: NWDSPutFilter returns 0xFEA5 (-347) -- SOLVED
Sat, 20 Aug 2005 18:24:30 GMT
gord32 wrote:

> In attempting to search the NDS tree from [Root], NWDSPutFilter
> consistently returns -347 (0xFEA5 - ERR_SCHEMA_NAME_TOO_LONG).  

> The client is v 4.90 sp2 on a Win2K box. The server is NetWare 6.5.  Below
> is the relevant segment of code.  (Sorry for the length.)

> All calls to addObjectClassToSearch with the pszClassName parameter set to
> one of "Country", "Organization", "Organizational
Unit", and "NDPS
> Printer" all return true - successfully created Filter Cursor.

> Any call to completeSearch with the pszSubTree parameter set to
"[Root]",
> or to an explicit (valid) path, such as .orgunit1.orgname.

> Can anyone shed some light on what the error code means and why it is
> occurring?  

> Thanks, in advance.

> Gord

> ...
>   pSearch = prepareSearch (hWndTree, pQueueContext);
>   if (pSearch != NULL)
>   {
>     if (addObjectClassToSearch (hWndTree, pSearch, "Country"))
>     {
>       if (completeSearch (pSearch, hWndTree, pszStart))
>       {
>         for (int i = 0; i < pSearch->ndsList.count; i++)
>         {
>           hti = AddTreeItem (hWndTree, hItem, iLevel, true, false, false,
> false, pSearch->ndsList.list[i]);
>           AddTreeItem (hWndTree, hti, iLevel + 1, false, false, false,
> false, ".");
>         }
>       }
>     }

>     cleanupSearch (pSearch);
>   }

> ...

> ... 
> prepareSearch (HWND hWnd, LPQUEUE_CONTEXT pQueueContext)
> {
> ...
> // code to create context
> ndsCode = NWDSCreateContextHandle (&(pQueueContext->context));
> if (ndsCode != SUCCESSFUL)
> {
>   TCHAR szErr[256];

>   NWNetTerm (NULL);
>   NWCallsTerm (NULL);

>   wsprintf (szErr, TEXT ("NWDSCreateContextHandle failed (Error Code:
> 0x%04lX)"), (DWORD)ndsCode);
>   MessageBox (NULL, szErr, TEXT ("..."), MB_OK | MB_ICONHAND);

> }

>   NWDSGetContext (pQueueContext->context, DCK_FLAGS, &flags);
>   flags &= ~DCV_XLATE_STRINGS;  // needed, since this context will be
used
>                                 // in NDPS calls
>   flags |= DCV_TYPELESS_NAMES;
>   flags &= ~DCV_CANONICALIZE_NAMES;

>   NWDSSetContext (pQueueContext->context, DCK_FLAGS, &flags);

> ...
>   return pQueueContext;
> }

> bool addObjectClassToSearch (HWND hWnd, LPSEARCH_STRUCT pSearch, char
> *pszClassName)
> {
>   NWDSCCODE         ccode;
>   nstr8 szTemp[2 * (MAX_DN_CHARS + 1)];
>   nuint32 syntaxID;
>   char *pszObjectClass = "Object Class";

>    /* Allocate space for the search filter - pCur holds the filter
>       cursor data.  */
>   ccode = NWDSAllocFilter(&(pSearch->pFilterCur)); 
//pSearch->pFilterCur
> is pFilter_Cursor_T

>   if(ccode)
>   {
>     TCHAR szMsg[256];

>     sprintf(szMsg, "Failed to allocate search filter (NWDSAllocFilter
> returned %X)", ccode);
>     MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK |
MB_ICONWARNING);

>     return false;
>    }

>    toUnicode (pSearch->pQueueContext, pszObjectClass, szTemp, sizeof
> (szTemp));

>    /* Add a node to the search filter expression tree. pCur is the
>       filter cursor, FTOK_ANAME indicates that an attribute name is
>       being added, the attribute name "Object Class" is next, and
the
>       syntax for the attribute, SYN_CLASS_NAME is last */

>    ccode = NWDSGetSyntaxID (pSearch->pQueueContext->context, szTemp,
> &syntaxID);
>    if (ccode)
>    {
>      TCHAR szMsg[256];
>      sprintf(szMsg, "Failed to lookup syntax ID for token name
"%s"
> (NWDSGetSyntaxID returned %X)", pszObjectClass, ccode);
>      MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK |
MB_ICONWARNING);

>      NWDSFreeFilter (pSearch->pFilterCur, NULL);
>      return false;
>    }

>    ccode = NWDSAddFilterToken (pSearch->pFilterCur, FTOK_LPAREN, NULL,
0);
>    if (ccode)
>    {
>       TCHAR szMsg[256];

>       sprintf(szMsg, "Failed to add token LPAREN to filter buffer
> (NWDSAddFilterToken returned %X)", ccode);
>       MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK |
MB_ICONWARNING);

>       NWDSFreeFilter (pSearch->pFilterCur, NULL);
>       return false;
>    }

>    ccode = NWDSAddFilterToken(pSearch->pFilterCur, FTOK_ANAME, szTemp,
> syntaxID);//SYN_CLASS_NAME);
>    if(ccode)
>    {
>       TCHAR szMsg[256];

>       sprintf(szMsg, "Failed to add token name "%s" to
filter buffer
> (NWDSAddFilterToken returned %X)", pszObjectClass, ccode);
>       MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK |
MB_ICONWARNING);

>       NWDSFreeFilter (pSearch->pFilterCur, NULL);
>       return false;
>    }

>    /* Add the equal relational operator next */
>    ccode = NWDSAddFilterToken(pSearch->pFilterCur, FTOK_EQ, NULL, 0);
>    if(ccode)
>    {
>      TCHAR szMsg[256];

>      sprintf(szMsg, "Failed to add token FTOK_EQ to filter buffer
> (NWDSAddFilterToken returned %X)", ccode);
>      MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK |
MB_ICONWARNING);

>      NWDSFreeFilter (pSearch->pFilterCur, NULL);
>      return false;
>    }

>    toUnicode (pSearch->pQueueContext, pszClassName, szTemp, sizeof
> (szTemp));

>   /* USE FTOK_AVAL to indicate that a value token is being placed and
>       pass strVal since it contains the class value */
>    ccode = NWDSAddFilterToken(pSearch->pFilterCur, FTOK_AVAL, szTemp,
> syntaxID);//SYN_CLASS_NAME);
>    if(ccode)
>    {
>      TCHAR szMsg[256];

>      sprintf(szMsg, "Failed to add token name "%s" to filter
buffer
> (NWDSAddFilterToken returned %X)", pszClassName, ccode);
>      MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK |
MB_ICONWARNING);

>      NWDSFreeFilter (pSearch->pFilterCur, NULL);
>      return false;
>    }

>    ccode = NWDSAddFilterToken (pSearch->pFilterCur, FTOK_RPAREN, NULL,
0);
>    if (ccode)
>    {
>      TCHAR szMsg[256];

>      sprintf(szMsg, "Failed to add token RPAREN to filter buffer
> (NWDSAddFilterToken returned %X)", ccode);
>      MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK |
MB_ICONWARNING);

>      NWDSFreeFilter (pSearch->pFilterCur, NULL);
>      return false;
>    }

>    /* USE FTOK_END to indicate the end of the expression */
>    ccode = NWDSAddFilterToken(pSearch->pFilterCur, FTOK_END, NULL, 0);
>    if(ccode)
>    {
>      TCHAR szMsg[256];

>      sprintf(szMsg, "Failed to add token FTOK_END to filter buffer
> (NWDSAddFilterToken returned %X)", ccode);
>      MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK |
MB_ICONWARNING);

>      NWDSFreeFilter (pSearch->pFilterCur, NULL);
>      return false;
>    }

>    return true;
> }

> bool completeSearch (LPSEARCH_STRUCT pSearch, HWND hWnd, const char
> *pszSubTree)
> {
>    NWDSCCODE         ccode;
>    pBuf_T            pBuf;
>    nint32            lIterationHandle;// = NO_MORE_ITERATIONS;
>    Object_Info_T     pObjectInfo;
>    nuint32           luObjectCount;
>    nuint32           luAttrCount;
>    nuint   i;
>    nstr8 szObjectName[2 * (MAX_DN_CHARS + 1)];
> 	nstr8 szTemp[2 * (MAX_DN_CHARS + 1)];
>    nstr8 szCanonName[2 * (MAX_DN_CHARS + 1)];

> 	pSearch->ndsList.count = 0;
> 	pSearch->ndsList.list = NULL;

>    /* Allocate the buffer to hold the search filter.  */
>    ccode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN,
&(pSearch->pFilterBuf));
>    if(ccode)
>    {
> 		TCHAR szMsg[256];

>       sprintf(szMsg, "Failed to allocate search filter buffer
> (NWDSAllocBuf returned %X)", ccode);
> 		MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK |
MB_ICONWARNING);

> 		NWDSFreeFilter (pSearch->pFilterCur, NULL);
>       return false;
>    }

>    ccode = NWDSInitBuf(pSearch->pQueueContext->context,
DSV_SEARCH_FILTER,
> pSearch->pFilterBuf);
>    if(ccode)
>    {
> 		TCHAR szMsg[256];

>       sprintf(szMsg, "Failed to initialize search filter buffer
> (NWDSInitBuf returned %X)", ccode);
> 		MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK |
MB_ICONWARNING);

> 		NWDSFreeFilter (pSearch->pFilterCur, NULL);
> 		return false;
>    }

>    /* Place finished search filter into the search input buffer */
>    ccode = NWDSPutFilter(pSearch->pQueueContext->context,
> pSearch->pFilterBuf, pSearch->pFilterCur, NULL);
>    if(ccode)
>    {
> 		TCHAR szMsg[256];

>       sprintf(szMsg, "Failed to put search filter into search input
buffer
> (NWDSPutFilter returned %ld - 0x%X)", ccode, ccode);
> 		MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK |
MB_ICONWARNING);

>       return false;
>    }

>    /* Allocate the output buffer.  */
>    ccode = NWDSAllocBuf(DEFAULT_MESSAGE_LEN, &pBuf);
>    if(ccode)
>    {
> 		TCHAR szMsg[256];

>       sprintf(szMsg, "Failed to allocate result buffer (NWDSAllocBuf
> returned %X)", ccode);
> 		MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK |
MB_ICONWARNING);

> 		return false;
>    }

>    /* Initialize filter for a DSV_SEARCH_FILTER operation */
>    /* Do the search */
> 	toUnicode (pSearch->pQueueContext, (pnstr8)pszSubTree, szTemp, sizeof
> (szTemp));

> 	ccode = NWDSCanonicalizeName (pSearch->pQueueContext->context,
szTemp,
> szCanonName);
> 	if (ccode)
> 	{
> 		TCHAR szMsg[256];

>       sprintf(szMsg, "NWDSCanonicalizeName returned %X", ccode);
> 		MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK |
MB_ICONWARNING);

> 		return false;
> 	}

> 	//strcpy (strAbbreviatedName, pszSubTree);

> 	lIterationHandle = NO_MORE_ITERATIONS;

>    do
>    {
>       ccode = NWDSSearch(pSearch->pQueueContext->context,
>                     szCanonName,   /* subtree to search      */
>                     DS_SEARCH_SUBORDINATES,    /* scope is subtree      
*/
>                     FALSE,                /* deref alias false      */
>                     pSearch->pFilterBuf,              /* search filter  
 
>      */
>                     DS_ATTRIBUTE_VALUES,  /* info type to return    */
>                     FALSE,                /* scope is false         */
>                     NULL,                 /* attribute list is NULL */
>                     &lIterationHandle,
>                     0,
>                     0,
>                     pBuf);                /* buf for search result  */
>       if(ccode)
>       {
> 			TCHAR szMsg[256];

> 			sprintf(szMsg, "Failed to complete search (NWDSSearch returned %ld
> [%X])", ccode, ccode);
> 			MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK | MB_ICONHAND);

> 			NWDSFreeBuf(pBuf);
> 			return false;
>       }

>       ccode = NWDSGetObjectCount(pSearch->pQueueContext->context,
pBuf,
> &luObjectCount);
>       if(ccode)
>       {
> 			TCHAR szMsg[256];

> 			sprintf(szMsg, "Failed to retrieve count of objects returned from
> search (NWDSGetObjectCount returned %X)", ccode);
> 			MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK | MB_ICONHAND);

> 			NWDSFreeBuf(pBuf);
> 			return false;
>       }

>       if(0 == luObjectCount)
>       {
> 			break;
>       }

> 		if (pSearch->ndsList.count == 0)
> 		{
> 			pSearch->ndsList.list = (char **)calloc (luObjectCount, sizeof (char
*));
> 			//*pppList = (char **)calloc (luObjectCount, sizeof (char *));
> 		}
> 		else
> 		{
> 			int newCount = pSearch->ndsList.count + (int)luObjectCount;
> 			char **ppNewList = (char **)calloc (newCount, sizeof (char *));

> 			memmove (ppNewList, pSearch->ndsList.list, pSearch->ndsList.count
*
> sizeof (char *));
> //			(*pCount) += (int)luObjectCount;

> 			free (pSearch->ndsList.list);
> 			pSearch->ndsList.list = ppNewList;
> 		}

>       /* For each object found, extract the name from the buffer */
>       for (i = 0; i < luObjectCount; i++)
>       {
>          ccode = NWDSGetObjectName(pSearch->pQueueContext->context,
pBuf,
> szObjectName,
>                                    &luAttrCount, &pObjectInfo);
>          if(ccode)
>          {
> 				TCHAR szMsg[256];

> 				sprintf(szMsg, "Failed to retrieve returned object name
> (NWDSGetObjectName returned %X)", ccode);
> 				MessageBox (hWnd, szMsg, TEXT ("..."), MB_OK | MB_ICONHAND);

> 				NWDSFreeBuf(pBuf);
> 				return false;
>          }

> 			fromUnicode (pSearch->pQueueContext, szObjectName, szTemp, sizeof
> (szTemp));

> 			pSearch->ndsList.list[pSearch->ndsList.count] = strdup (szTemp);
> 			pSearch->ndsList.count++;
>       }

>      /* loop back if more data */
>    } while(lIterationHandle != NO_MORE_ITERATIONS);

>    /* Clean up, normal termination */
>    NWDSFreeBuf(pBuf);

>    return true;
> }

> pnstr8 toUnicode (NWDSContextHandle context, pnstr8 strToXlate, pnstr8
> unicodeXlateBuffer, nuint bufSize)
> {
> 	nuint len;
> 	nint flags;

> 	NWDSGetContext (context, DCK_FLAGS, &flags);
> 	if (flags & DCV_XLATE_STRINGS)
> 	{
> 		strcpy (unicodeXlateBuffer, strToXlate);
> 	}
> 	else
> 	{
> 		NWLocalToUnicode (NWDPLocalToUnicodeHandleMac
> (pQueueContext->accessorRef),
> 								(unicode *)unicodeXlateBuffer, 
> 								bufSize,
> 								(pnuint8)strToXlate, 0, &len);
> 	}

> 	return unicodeXlateBuffer;
> }

> pnstr8 fromUnicode (NWDSContextHandle context, pnstr8 unicodeStrToXlate,
> pnstr8 xlateBuffer, nuint bufSize)
> {
> 	nuint len;
> 	nint flags;

> 	NWDSGetContext (context, DCK_FLAGS, &flags);
> 	if (flags & DCV_XLATE_STRINGS)
> 	{
> 		strcpy (xlateBuffer, unicodeStrToXlate);
> 	}
> 	else
> 	{
> 		NWUnicodeToLocal (NWDPUnicodeToLocalHandleMac
> (pQueueContext->accessorRef), (pnuint8)xlateBuffer, bufSize,
> 								(unicode *)unicodeStrToXlate, 0, &len);
> 	}

> 	return xlateBuffer;
> }

It turns out that when adding FTOK_ANAME or FTOK_AVAL, you need to use
separate buffers for the attribute name and value (the NWDSAddFilterToken
simply copies the pointer) that are not local to the function, if one
function prepares the search and another to execute the search.

For some reason, I was under the impression that the NWDSAddFilterToken
copied the contents of the ANAME or AVAL pointers -- my bad.

Thanks anyway.

Gord


Post Reply
about | contact