93 long result = eDSAuthFailed;
94 tDirReference dsRef = 0;
95 tDataBuffer *tDataBuff;
96 tDirNodeReference nodeRef = 0;
97 long status = eDSNoErr;
101 tDataList *nodeName = NULL;
102 tAttributeEntryPtr pAttrEntry = NULL;
103 tDataList *pRecName = NULL;
104 tDataList *pRecType = NULL;
105 tDataList *pAttrType = NULL;
107 tRecordEntry *pRecEntry = NULL;
108 tAttributeListRef attrListRef = 0;
109 char *pUserLocation = NULL;
110 char *pUserName = NULL;
111 tAttributeValueListRef valueRef = 0;
112 tAttributeValueEntry *pValueEntry = NULL;
113 tDataList *pUserNode = NULL;
114 tDirNodeReference userNodeRef = 0;
115 tDataBuffer *pStepBuff = NULL;
116 tDataNode *pAuthType = NULL;
117 tAttributeValueEntry *pRecordType = NULL;
122 if (!uname || !password)
127 status = dsOpenDirService( &dsRef );
128 if ( status != eDSNoErr )
131 tDataBuff = dsDataBufferAllocate( dsRef, 4096 );
136 status = dsFindDirNodes( dsRef, tDataBuff, NULL, eDSSearchNodeName, &nodeCount, &
context );
137 if (status != eDSNoErr || nodeCount < 1)
140 status = dsGetDirNodeName( dsRef, tDataBuff, 1, &nodeName );
141 if (status != eDSNoErr)
144 status = dsOpenDirNode( dsRef, nodeName, &nodeRef );
145 dsDataListDeallocate( dsRef, nodeName );
148 if (status != eDSNoErr)
151 pRecName = dsBuildListFromStrings( dsRef, uname, NULL );
152 pRecType = dsBuildListFromStrings( dsRef, kDSStdRecordTypeUsers, kDSStdRecordTypeComputers, kDSStdRecordTypeMachines, NULL );
153 pAttrType = dsBuildListFromStrings( dsRef, kDSNAttrMetaNodeLocation, kDSNAttrRecordName, kDSNAttrRecordType, NULL );
156 status = dsGetRecordList( nodeRef, tDataBuff, pRecName, eDSExact, pRecType,
157 pAttrType, 0, &recCount, &
context );
158 if ( status != eDSNoErr || recCount == 0 )
161 status = dsGetRecordEntry( nodeRef, tDataBuff, 1, &attrListRef, &pRecEntry );
162 if ( status != eDSNoErr )
165 for ( attrIndex = 1; (attrIndex <= pRecEntry->fRecordAttributeCount) && (status == eDSNoErr); attrIndex++ )
167 status = dsGetAttributeEntry( nodeRef, tDataBuff, attrListRef, attrIndex, &valueRef, &pAttrEntry );
168 if ( status == eDSNoErr && pAttrEntry != NULL )
170 if ( strcmp( pAttrEntry->fAttributeSignature.fBufferData, kDSNAttrMetaNodeLocation ) == 0 )
172 status = dsGetAttributeValue( nodeRef, tDataBuff, 1, valueRef, &pValueEntry );
173 if ( status == eDSNoErr && pValueEntry != NULL )
175 pUserLocation = talloc_zero_array(request,
char, pValueEntry->fAttributeValueData.fBufferLength + 1);
176 memcpy( pUserLocation, pValueEntry->fAttributeValueData.fBufferData, pValueEntry->fAttributeValueData.fBufferLength );
180 if ( strcmp( pAttrEntry->fAttributeSignature.fBufferData, kDSNAttrRecordName ) == 0 )
182 status = dsGetAttributeValue( nodeRef, tDataBuff, 1, valueRef, &pValueEntry );
183 if ( status == eDSNoErr && pValueEntry != NULL )
185 pUserName = talloc_zero_array(request,
char, pValueEntry->fAttributeValueData.fBufferLength + 1);
186 memcpy( pUserName, pValueEntry->fAttributeValueData.fBufferData, pValueEntry->fAttributeValueData.fBufferLength );
190 if ( strcmp( pAttrEntry->fAttributeSignature.fBufferData, kDSNAttrRecordType ) == 0 )
192 status = dsGetAttributeValue( nodeRef, tDataBuff, 1, valueRef, &pValueEntry );
193 if ( status == eDSNoErr && pValueEntry != NULL )
195 pRecordType = pValueEntry;
200 if ( pValueEntry != NULL ) {
201 dsDeallocAttributeValueEntry( dsRef, pValueEntry );
204 if ( pAttrEntry != NULL ) {
205 dsDeallocAttributeEntry( dsRef, pAttrEntry );
208 dsCloseAttributeValueList( valueRef );
213 pUserNode = dsBuildFromPath( dsRef, pUserLocation,
"/" );
214 status = dsOpenDirNode( dsRef, pUserNode, &userNodeRef );
215 dsDataListDeallocate( dsRef, pUserNode );
218 if ( status != eDSNoErr )
221 pStepBuff = dsDataBufferAllocate( dsRef, 128 );
223 pAuthType = dsDataNodeAllocateString( dsRef, kDSStdAuthNodeNativeClearTextOK );
227 RDEBUG2(
"Failed to find user name");
232 uiLen = (
uint32_t)strlen( pUserName );
233 memcpy( &(tDataBuff->fBufferData[ uiCurr ]), &uiLen,
sizeof(uiLen) );
234 uiCurr += (
uint32_t)
sizeof( uiLen );
235 memcpy( &(tDataBuff->fBufferData[ uiCurr ]), pUserName, uiLen );
239 pwLen = (
uint32_t)strlen( password );
240 memcpy( &(tDataBuff->fBufferData[ uiCurr ]), &pwLen,
sizeof(pwLen) );
241 uiCurr += (
uint32_t)
sizeof( pwLen );
242 memcpy( &(tDataBuff->fBufferData[ uiCurr ]), password, pwLen );
245 tDataBuff->fBufferLength = uiCurr;
247 result = dsDoDirNodeAuthOnRecordType( userNodeRef, pAuthType, 1, tDataBuff, pStepBuff, NULL, &pRecordType->fAttributeValueData );
252 if (pAuthType != NULL) {
253 dsDataNodeDeAllocate( dsRef, pAuthType );
256 if (pRecordType != NULL) {
257 dsDeallocAttributeValueEntry( dsRef, pRecordType );
260 if (tDataBuff != NULL) {
261 bzero( tDataBuff, tDataBuff->fBufferSize );
262 dsDataBufferDeAllocate( dsRef, tDataBuff );
265 if (pStepBuff != NULL) {
266 dsDataBufferDeAllocate( dsRef, pStepBuff );
269 if (pUserLocation != NULL) {
271 pUserLocation = NULL;
273 if (pUserName != NULL) {
277 if (pRecName != NULL) {
278 dsDataListDeallocate( dsRef, pRecName );
282 if (pRecType != NULL) {
283 dsDataListDeallocate( dsRef, pRecType );
287 if (pAttrType != NULL) {
288 dsDataListDeallocate( dsRef, pAttrType );
293 dsCloseDirNode(nodeRef);
297 dsCloseDirService(dsRef);