Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Can't get DS to do native authentication



On mendag, dec 2, 2002, at 11:42 Europe/Stockholm, Stephen Brandon wrote:
Does anyone know anything about this issue?

Why, yes... :-/

We needed this for one of our products as well and went through the same
funny loop - the DS samples and API:s aren't perhaps the most clear ones
provided. After someone spent some time looking at it, we actually used a
tech support incident to get it solved instead of wasting time trying to
figure out the API:s (it was that non-intuitive)...

The problem was in the DoNodeNativeAuthentication sample function
(it adds some unnecessary argument to the nice blob of memory which
contains the arguments for authentication...).

I've attached the amended sample function below, it should get you
on the right track...

Joakim

ps it does work with NI authentication, that is what we're using ds

-------------
static int DoNodeNativeAuthentication(const tDirReference inDirRef, const tDirNo
deReference inDirNodeRef, const char *inUserName, const char *inUserPassword)
{
tDataNodePtr anAuthType2Use = NULL;
tDataBufferPtr anAuthDataBuf = NULL;
tDataBufferPtr aAuthRespBuf = NULL;
tDirStatus aDirErr = eDSNoErr;
tContextData aContinueData = NULL;
long aTempLength = 0;
int aResult = 0;
char * ptr;

// First, specify the type of authentication.
anAuthType2Use = dsDataNodeAllocateString(inDirRef, kDSStdAuthNodeNative
ClearTextOK);

aAuthRespBuf = dsDataBufferAllocate(inDirRef, 8192);

anAuthDataBuf = dsDataBufferAllocate(inDirRef, strlen(inUserName) + strl
en(inUserPassword) + 10);

// 4 byte length + username + null byte + 4 byte length + password + nul
l byte

aTempLength = strlen(inUserName) + 1;
ptr = anAuthDataBuf->fBufferData;
memcpy(ptr, &aTempLength, 4);
ptr += 4;
anAuthDataBuf->fBufferLength += 4;

memcpy(ptr, inUserName, aTempLength);
ptr += aTempLength;
anAuthDataBuf->fBufferLength += aTempLength;

aTempLength = strlen( inUserPassword ) + 1;
memcpy(ptr, &aTempLength, 4);
ptr += 4;
anAuthDataBuf->fBufferLength += 4;

memcpy(ptr, inUserPassword, aTempLength);
ptr += aTempLength;
anAuthDataBuf->fBufferLength += aTempLength;

aDirErr = dsDoDirNodeAuth(inDirNodeRef, anAuthType2Use, 1, anAuthDataBuf
, aAuthRespBuf, &aContinueData);

switch(aDirErr)
{
case eDSNoErr:
aResult = 1;
break;
case eDSAuthFailed: // password bad, silent error
aResult = 0;
break;
default:
// If any other error, assume a more critical error that
goes to stderr
fprintf(stderr,"Directory Services Authentication failed
with error [%d]\n",aDirErr);
aResult = 0;
break;
}

// Clean up allocations.

aDirErr = dsDataBufferDeAllocate(inDirRef, anAuthDataBuf);
anAuthDataBuf = NULL;

// Don't need to keep the response.

aDirErr = dsDataBufferDeAllocate(inDirRef, aAuthRespBuf);
aAuthRespBuf = NULL;

// Don't need the authentication type value. Build a new one if needed l
ater.

aDirErr = dsDataNodeDeAllocate(inDirRef, anAuthType2Use);
anAuthType2Use = NULL;

// Return the result of the authentication
return (aResult);
}
--------
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.

References: 
 >Can't get DS to do native authentication (From: Stephen Brandon <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.