88 long result = eDSAuthFailed;
89 tDirReference dsRef = 0;
90 tDataBuffer *tDataBuff;
91 tDirNodeReference nodeRef = 0;
92 long status = eDSNoErr;
96 tDataList *nodeName = NULL;
97 tAttributeEntryPtr pAttrEntry = NULL;
98 tDataList *pRecName = NULL;
99 tDataList *pRecType = NULL;
100 tDataList *pAttrType = NULL;
102 tRecordEntry *pRecEntry = NULL;
103 tAttributeListRef attrListRef = 0;
104 char *pUserLocation = NULL;
105 char *pUserName = NULL;
106 tAttributeValueListRef valueRef = 0;
107 tAttributeValueEntry *pValueEntry = NULL;
108 tDataList *pUserNode = NULL;
109 tDirNodeReference userNodeRef = 0;
110 tDataBuffer *pStepBuff = NULL;
111 tDataNode *pAuthType = NULL;
112 tAttributeValueEntry *pRecordType = NULL;
117 if (!uname || !password)
122 status = dsOpenDirService( &dsRef );
123 if ( status != eDSNoErr )
126 tDataBuff = dsDataBufferAllocate( dsRef, 4096 );
131 status = dsFindDirNodes( dsRef, tDataBuff, NULL, eDSSearchNodeName, &nodeCount, &
context );
132 if (status != eDSNoErr || nodeCount < 1)
135 status = dsGetDirNodeName( dsRef, tDataBuff, 1, &nodeName );
136 if (status != eDSNoErr)
139 status = dsOpenDirNode( dsRef, nodeName, &nodeRef );
140 dsDataListDeallocate( dsRef, nodeName );
143 if (status != eDSNoErr)
146 pRecName = dsBuildListFromStrings( dsRef, uname, NULL );
147 pRecType = dsBuildListFromStrings( dsRef, kDSStdRecordTypeUsers, kDSStdRecordTypeComputers, kDSStdRecordTypeMachines, NULL );
148 pAttrType = dsBuildListFromStrings( dsRef, kDSNAttrMetaNodeLocation, kDSNAttrRecordName, kDSNAttrRecordType, NULL );
151 status = dsGetRecordList( nodeRef, tDataBuff, pRecName, eDSExact, pRecType,
152 pAttrType, 0, &recCount, &
context );
153 if ( status != eDSNoErr || recCount == 0 )
156 status = dsGetRecordEntry( nodeRef, tDataBuff, 1, &attrListRef, &pRecEntry );
157 if ( status != eDSNoErr )
160 for ( attrIndex = 1; (attrIndex <= pRecEntry->fRecordAttributeCount) && (status == eDSNoErr); attrIndex++ )
162 status = dsGetAttributeEntry( nodeRef, tDataBuff, attrListRef, attrIndex, &valueRef, &pAttrEntry );
163 if ( status == eDSNoErr && pAttrEntry != NULL )
165 if ( strcmp( pAttrEntry->fAttributeSignature.fBufferData, kDSNAttrMetaNodeLocation ) == 0 )
167 status = dsGetAttributeValue( nodeRef, tDataBuff, 1, valueRef, &pValueEntry );
168 if ( status == eDSNoErr && pValueEntry != NULL )
170 pUserLocation = talloc_zero_array(request,
char, pValueEntry->fAttributeValueData.fBufferLength + 1);
171 memcpy( pUserLocation, pValueEntry->fAttributeValueData.fBufferData, pValueEntry->fAttributeValueData.fBufferLength );
175 if ( strcmp( pAttrEntry->fAttributeSignature.fBufferData, kDSNAttrRecordName ) == 0 )
177 status = dsGetAttributeValue( nodeRef, tDataBuff, 1, valueRef, &pValueEntry );
178 if ( status == eDSNoErr && pValueEntry != NULL )
180 pUserName = talloc_zero_array(request,
char, pValueEntry->fAttributeValueData.fBufferLength + 1);
181 memcpy( pUserName, pValueEntry->fAttributeValueData.fBufferData, pValueEntry->fAttributeValueData.fBufferLength );
185 if ( strcmp( pAttrEntry->fAttributeSignature.fBufferData, kDSNAttrRecordType ) == 0 )
187 status = dsGetAttributeValue( nodeRef, tDataBuff, 1, valueRef, &pValueEntry );
188 if ( status == eDSNoErr && pValueEntry != NULL )
190 pRecordType = pValueEntry;
195 if ( pValueEntry != NULL ) {
196 dsDeallocAttributeValueEntry( dsRef, pValueEntry );
199 if ( pAttrEntry != NULL ) {
200 dsDeallocAttributeEntry( dsRef, pAttrEntry );
203 dsCloseAttributeValueList( valueRef );
208 pUserNode = dsBuildFromPath( dsRef, pUserLocation,
"/" );
209 status = dsOpenDirNode( dsRef, pUserNode, &userNodeRef );
210 dsDataListDeallocate( dsRef, pUserNode );
213 if ( status != eDSNoErr )
216 pStepBuff = dsDataBufferAllocate( dsRef, 128 );
218 pAuthType = dsDataNodeAllocateString( dsRef, kDSStdAuthNodeNativeClearTextOK );
222 RDEBUG2(
"Failed to find user name");
227 uiLen = (
uint32_t)strlen( pUserName );
228 memcpy( &(tDataBuff->fBufferData[ uiCurr ]), &uiLen,
sizeof(uiLen) );
229 uiCurr += (
uint32_t)
sizeof( uiLen );
230 memcpy( &(tDataBuff->fBufferData[ uiCurr ]), pUserName, uiLen );
234 pwLen = (
uint32_t)strlen( password );
235 memcpy( &(tDataBuff->fBufferData[ uiCurr ]), &pwLen,
sizeof(pwLen) );
236 uiCurr += (
uint32_t)
sizeof( pwLen );
237 memcpy( &(tDataBuff->fBufferData[ uiCurr ]), password, pwLen );
240 tDataBuff->fBufferLength = uiCurr;
242 result = dsDoDirNodeAuthOnRecordType( userNodeRef, pAuthType, 1, tDataBuff, pStepBuff, NULL, &pRecordType->fAttributeValueData );
247 if (pAuthType != NULL) {
248 dsDataNodeDeAllocate( dsRef, pAuthType );
251 if (pRecordType != NULL) {
252 dsDeallocAttributeValueEntry( dsRef, pRecordType );
255 if (tDataBuff != NULL) {
256 bzero( tDataBuff, tDataBuff->fBufferSize );
257 dsDataBufferDeAllocate( dsRef, tDataBuff );
260 if (pStepBuff != NULL) {
261 dsDataBufferDeAllocate( dsRef, pStepBuff );
264 if (pUserLocation != NULL) {
266 pUserLocation = NULL;
268 if (pUserName != NULL) {
272 if (pRecName != NULL) {
273 dsDataListDeallocate( dsRef, pRecName );
277 if (pRecType != NULL) {
278 dsDataListDeallocate( dsRef, pRecType );
282 if (pAttrType != NULL) {
283 dsDataListDeallocate( dsRef, pAttrType );
288 dsCloseDirNode(nodeRef);
292 dsCloseDirService(dsRef);