1 /***************************************************************************
2 * Copyright (C) 2001 by Ludovic LANGE *
3 * ludovic.lange@free.fr *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
9 ***************************************************************************/
12 * (c) 2001 Ludovic LANGE,
13 * except SockOpen, (c) Unknown ? from socket.c / socket.h
20 #define MIN(a,b) ((a)<(b)?(a):(b))
23 #include <sys/types.h>
26 #include <sys/types.h>
27 #include <sys/socket.h>
28 #include <netinet/in.h>
29 #include <arpa/inet.h>
38 #include "little_endian.h"
47 * Push parameter information to the buffer
49 * DWORD parameter values must be 4 byte little-endian
50 * WORD parameter values must be 2 byte little-endian
51 * WCHAR parameter values must be 2-byte UNICODE (is it endian stuff on these too?)
53 static void pushParameter(RAPIHandleP rhnd,long size, void * parameterData, size_t parameterSize, int pushValue)
57 pushLong( (rhnd->buffer), size, 1 );
58 pushLong( (rhnd->buffer), size, parameterSize);
60 if (pushValue) /* pushValue is boolean */
65 pushLong( (rhnd->buffer), size, 1 ); /* data follows */
67 old_length = _getbufferlen((rhnd->buffer));
68 new_length = old_length + parameterSize;
70 if (new_length < size)
72 memcpy(((unsigned char*)&((rhnd->buffer)->data)) + old_length, parameterData, parameterSize);
73 _setbufferlen((rhnd->buffer), new_length);
77 DBG_printf( "rapibuffer too small, this will fail\n");
82 pushLong( (rhnd->buffer), size, 0 ); /* no data follows */
87 pushLong( (rhnd->buffer), size, 0 ); /* no parameter info */
92 * Push parameter information to the buffer, omitting size information (needed for CeRecordWriteProps
94 static void pushParameter_no_size(RAPIHandleP rhnd,long size, void * parameterData, size_t parameterSize)
101 pushLong( (rhnd->buffer), size, 1 ); /* data follows */
103 old_length = _getbufferlen((rhnd->buffer));
104 new_length = old_length + parameterSize;
106 if (new_length < size)
108 memcpy(((unsigned char*)&((rhnd->buffer)->data)) + old_length, parameterData, parameterSize);
109 _setbufferlen((rhnd->buffer), new_length);
113 DBG_printf( "rapibuffer too small, this will fail\n");
118 pushLong( (rhnd->buffer), size, 0 ); /* no data follows */
126 * Convert parameter to little endian before call to pushParameter
128 #define pushParameterInt16(rhnd,size, parameterData, pushValue) \
129 if (pushValue && parameterData) \
130 { *(u_int16_t*)parameterData = htole16(*(u_int16_t*)parameterData); } \
131 pushParameter(rhnd,size, parameterData, sizeof(u_int16_t), pushValue);
133 #define pushParameterInt32(rhnd,size, parameterData, pushValue) \
134 if (pushValue && parameterData) \
135 { *(u_int32_t*)parameterData = htole32(*(u_int32_t*)parameterData); } \
136 pushParameter(rhnd,size, parameterData, sizeof(u_int32_t), pushValue)
140 * Pop parameter info from the buffer
142 static void popParameter(RAPIHandleP rhnd,long* size, void * parameterData, size_t parameterMaxSize)
146 lng = getLong((rhnd->sock), size); /* parameter info available? */
150 size_t parameterRealSize = getLong((rhnd->sock), size); /* parameter value size in buffer */
152 lng = getLong((rhnd->sock), size); /* parameter value available? */
160 /* read directly to buffer */
161 getbufferchunk((rhnd->sock), size, parameterData, MIN(parameterRealSize, parameterMaxSize));
162 overflow = parameterRealSize - parameterMaxSize;
166 /* throw it all away */
167 overflow = parameterRealSize;
173 DBG_printf("Overflow by %i bytes. Parameter size is %i bytes but max %i bytes was expected. (%i bytes remaining)\n",
174 overflow, parameterRealSize, parameterMaxSize , *size);
177 /* read overflowed buffer */
178 void* tmp = malloc(overflow);
179 getbufferchunk((rhnd->sock), size, tmp, overflow);
187 DBG_printf("popParameter (a): Expected 0 or 1 but got %i=0x%x (%i bytes remaining)\n", lng, lng, *size);
192 DBG_printf("popParameter (b): Expected 0 or 1 but got %i=0x%x (%i bytes remaining)\n", lng, lng, *size);
197 * Convert parameter data from little endian after call to popParameter
199 #define popParameterInt16(rhnd,size, parameterData) \
200 popParameter(rhnd,size, parameterData, sizeof(u_int16_t)); \
202 { *(u_int16_t*)parameterData = letoh16(*(u_int16_t*)parameterData); }
204 #define popParameterInt32(rhnd,size, parameterData) \
205 popParameter(rhnd,size, parameterData, sizeof(u_int32_t)); \
207 { *(u_int32_t*)parameterData = letoh32(*(u_int32_t*)parameterData); }
209 void checkpassword(RAPIHandleP rhnd)
212 /* Is the device protected ? */
213 /* ------------------------- */
214 if( (rhnd->lockbuffersize) != 0 )
216 safe_write( (rhnd->sock), (rhnd->lockbuffer), (rhnd->lockbuffersize) );
217 read( (rhnd->sock), buf, 1 );
220 /*=================================================================================================================*
221 *=================================================================================================================*
223 *=================================================================================================================*
224 *=================================================================================================================*/
226 STDAPI_( DWORD ) CeGetSpecialFolderPath(RAPIHandleP rhnd, int nFolder, DWORD nBufferLength, LPWSTR lpBuffer )
234 initBuf( (rhnd->buffer), size );
235 pushLong( (rhnd->buffer), size, 0x44 ); /* Command */
236 pushLong( (rhnd->buffer), size, nFolder ); /* Parameter1 : the folder */
237 pushLong( (rhnd->buffer), size, nBufferLength ); /* Parameter2 : Buffer size that'll get the string */
238 DBG_printbuf( (rhnd->buffer) );
239 sendbuffer( (rhnd->sock), (rhnd->buffer) );
241 size = getbufferlen( (rhnd->sock) );
243 lng = getLong( (rhnd->sock), &size );
244 DBG_printf( "long 1 : %ld (0x%08lx)\n", lng, lng );
245 lng = getLong( (rhnd->sock), &size );
246 DBG_printf( "long 2 : %ld (0x%08lx)\n", lng, lng );
247 lng = getLong( (rhnd->sock), &size );
248 DBG_printf( "string size : %ld (0x%08lx)\n", lng, lng );
249 str = getString( (rhnd->sock), &size, lng+1 );
250 DBG_printf( "string1 : %s\n", str );
253 memcpy( lpBuffer, str, MIN( ((lng+1)*sizeof(WCHAR) ), nBufferLength*sizeof(WCHAR) ) );
259 /* ================================================================================================================= */
260 /* ================================================================================================================= */
261 /* RAPI - Registry */
262 /* ================================================================================================================= */
263 /* ================================================================================================================= */
266 STDAPI_(LONG) CeRegDeleteKey( HKEY, LPCWSTR );
267 STDAPI_(LONG) CeRegDeleteValue( HKEY, LPCWSTR );
268 STDAPI_(LONG) CeRegQueryValueEx( HKEY, LPCWSTR, LPDWORD, LPDWORD, LPBYTE, LPDWORD );
269 STDAPI_(LONG) CeRegSetValueEx( HKEY, LPCWSTR, DWORD, DWORD, LPBYTE, DWORD );
272 STDAPI_( LONG ) CeRegCreateKeyEx(RAPIHandleP rhnd, HKEY hKey, LPCWSTR lpszSubKey, DWORD Reserved, LPWSTR lpszClass, DWORD ulOptions, REGSAM samDesired, LPSECURITY_ATTRIBUTES lpSecurityAttributes, PHKEY phkResult, LPDWORD lpdwDisposition )
277 LONG result = ERROR_SUCCESS; /* May be result is really errcode. */
279 DBG_printf( "CeRegCreatKeyEx( hKey = 0x%08X, lpszSubKey = 0x%08X, Reserved = 0x%08X, lpszClass = 0x%08X, ulOptions = 0x%08X, samDesired = 0x%08X, lpSecurityAttributes = 0x%08X, phkResult = 0x%08X, lpdwDisposition = 0x%08X )\n",
280 hKey, lpszSubKey, Reserved, lpszClass, ulOptions, samDesired, lpSecurityAttributes, phkResult, lpdwDisposition );
282 initBuf( (rhnd->buffer), size );
283 pushLong( (rhnd->buffer), size, 0x20 ); /* Command */
284 pushLong( (rhnd->buffer), size, hKey ); /* Parameter1 : */
285 pushLong( (rhnd->buffer), size, 0x01 ); /* Parameter2 : */
286 pushLong( (rhnd->buffer), size, 1 + wcslen( lpszSubKey ) ); /* Parameter3 : */
287 pushString( (rhnd->buffer), size, lpszSubKey ); /* Parameter4 : the path */
288 pushLong( (rhnd->buffer), size, 0x01 ); /* Parameter5 : */
289 pushLong( (rhnd->buffer), size, 0x01 ); /* Parameter6 : */
290 pushShort( (rhnd->buffer), size, 0x00 ); /* Parameter7 : */
292 DBG_printbuf( (rhnd->buffer) );
293 sendbuffer( (rhnd->sock), (rhnd->buffer) );
295 size = getbufferlen( (rhnd->sock) );
297 errcode = getLong( (rhnd->sock), &size );
298 DBG_printf( "errpresent : %ld (0x%08lx)\n", errcode, errcode );
301 errcode = getLong( (rhnd->sock), &size );
302 DBG_printf( "errcode : %ld (0x%08lx)\n", errcode, errcode );
306 lng = getLong( (rhnd->sock), &size );
307 DBG_printf( "long 1 : %ld (0x%08lx)\n", lng, lng );
308 lng = getLong( (rhnd->sock), &size );
309 DBG_printf( "long 2 : %ld (0x%08lx)\n", lng, lng );
310 *phkResult = ( HKEY ) getLong( (rhnd->sock), &size );
311 DBG_printf( "pHkey : %ld (0x%08lx)\n", *phkResult, *phkResult );
312 *lpdwDisposition = ( DWORD ) getLong( (rhnd->sock), &size );
313 DBG_printf( "lpdwDisposition : %ld (0x%08lx)\n", *lpdwDisposition, *lpdwDisposition );
318 STDAPI_( LONG ) CeRegOpenKeyEx(RAPIHandleP rhnd, HKEY hKey, LPCWSTR lpszSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult )
323 DBG_printf( "CeRegOpenKeyEx( hKey = 0x%08X, lpszSubKey = 0x%08X, ulOptions = 0x%08X, samDesired = 0x%08X, phkResult = 0x%08X )\n",
324 hKey, lpszSubKey, ulOptions, samDesired, phkResult );
326 initBuf( (rhnd->buffer), size );
327 pushLong( (rhnd->buffer), size, 0x1E ); /* Command */
328 pushLong( (rhnd->buffer), size, hKey ); /* Parameter1 : */
330 pushLong( (rhnd->buffer), size, 0x01 ); /* Parameter2 : */
331 pushLong( (rhnd->buffer), size, 1 + wcslen( lpszSubKey ) ); /* Parameter3 : */
332 pushString( (rhnd->buffer), size, lpszSubKey ); /* Parameter4 : the path */
334 pushParameter(rhnd,size, lpszSubKey, lpszSubKey ? (wcslen(lpszSubKey) + 1) * sizeof(WCHAR) : 0, 1);
335 pushLong( (rhnd->buffer), size, ulOptions);
336 pushLong( (rhnd->buffer), size, samDesired);
337 pushParameterInt32(rhnd,size, phkResult, 0);
339 DBG_printbuf( (rhnd->buffer) );
340 sendbuffer( (rhnd->sock), (rhnd->buffer) );
342 size = getbufferlen( (rhnd->sock) );
344 errcode = getLong( (rhnd->sock), &size );
345 DBG_printf( "errcode : %ld (0x%08lx)\n", errcode, errcode );
347 errcode = getLong( (rhnd->sock), &size );
348 DBG_printf( "errpresent : %ld (0x%08lx)\n", errcode, errcode );
349 (rhnd->_lasterror) = getLong( (rhnd->sock), &size );
350 DBG_printf( "long : %ld (0x%08lx)\n", (rhnd->_lasterror), (rhnd->_lasterror) );
353 *phkResult = ( HKEY ) getLong( (rhnd->sock), &size );
354 DBG_printf( "pHkey : %ld (0x%08lx)\n", *phkResult, *phkResult );
359 STDAPI_( LONG ) CeRegCloseKey( RAPIHandleP rhnd,HKEY hKey )
365 DBG_printf( "CeRegCloseKey( hKey = 0x%08X )\n",
368 initBuf( (rhnd->buffer), size );
369 pushLong( (rhnd->buffer), size, 0x21 ); /* Command */
370 pushLong( (rhnd->buffer), size, hKey ); /* Parameter1 : */
372 DBG_printbuf( (rhnd->buffer) );
373 sendbuffer( (rhnd->sock), (rhnd->buffer) );
374 size = getbufferlen( (rhnd->sock) );
376 result = getLong( (rhnd->sock), &size );
377 DBG_printf( "result : %ld (0x%08lx)\n", result, result );
378 lng = getLong( (rhnd->sock), &size );
379 DBG_printf( "long 2 : %ld (0x%08lx)\n", lng, lng );
380 lng = getLong( (rhnd->sock), &size );
381 DBG_printf( "long 3 : %ld (0x%08lx)\n", lng, lng );
385 STDAPI_( LONG ) CeRegQueryInfoKey(RAPIHandleP rhnd, HKEY hKey, LPWSTR lpClass, LPDWORD lpcbClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcbMaxSubKeyLen, LPDWORD lpcbMaxClassLen, LPDWORD lpcValues, LPDWORD lpcbMaxValueNameLen, LPDWORD lpcbMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime )
389 LONG result = ERROR_SUCCESS;
392 DBG_printf( "CeRegQueryInfoKey( hKey = 0x%08X, lpClass = 0x%08X, lpcbClass = 0x%08X, lpReserved = 0x%08X, lpcSubKeys = 0x%08X, lpcbMaxSubKeyLen = 0x%08X, lpcbMaxClassLen = 0x%08X, lpcValues = 0x%08X, lpcbMaxValueNameLen = 0x%08X, lpcbMaxValueLen = 0x%08X, lpcbSecurityDescriptor = 0x%08X, lpftLastWriteTime = 0x%08X )\n",
393 hKey, lpClass, lpcbClass, lpReserved, lpcSubKeys, lpcbMaxSubKeyLen, lpcbMaxClassLen, lpcValues, lpcbMaxValueNameLen, lpcbMaxValueLen, lpcbSecurityDescriptor, lpftLastWriteTime );
396 initBuf( (rhnd->buffer), size );
397 pushLong( (rhnd->buffer), size, 0x25 ); /* Command */
398 pushLong( (rhnd->buffer), size, hKey ); /* hKey */
400 pushParameter(rhnd,size, lpClass, lpcbClass ? *lpcbClass * sizeof(WCHAR): 0, 0);
401 pushParameterInt32(rhnd,size, lpcbClass, 1);
402 pushParameterInt32(rhnd,size, lpReserved, 0);
403 pushParameterInt32(rhnd,size, lpcSubKeys, 0);
404 pushParameterInt32(rhnd,size, lpcbMaxSubKeyLen, 0);
405 pushParameterInt32(rhnd,size, lpcbMaxClassLen, 0);
406 pushParameterInt32(rhnd,size, lpcValues, 0);
407 pushParameterInt32(rhnd,size, lpcbMaxValueNameLen, 0);
408 pushParameterInt32(rhnd,size, lpcbMaxValueLen, 0);
409 pushParameterInt32(rhnd,size, lpcbSecurityDescriptor, 1);
410 if (lpftLastWriteTime)
412 lpftLastWriteTime->dwLowDateTime = (DWORD)htole32(lpftLastWriteTime->dwLowDateTime);
413 lpftLastWriteTime->dwHighDateTime = (DWORD)htole32(lpftLastWriteTime->dwHighDateTime);
415 pushParameter(rhnd,size, lpftLastWriteTime, sizeof(FILETIME), 0);
417 /* DBG_printbuf( (rhnd->buffer) );*/
418 sendbuffer( (rhnd->sock), (rhnd->buffer) );
420 size = getbufferlen( (rhnd->sock) );
422 result = lng = getLong( (rhnd->sock), &size );
423 (rhnd->_lasterror) = lng = getLong( (rhnd->sock), &size );
425 if (ERROR_SUCCESS == result)
427 popParameter(rhnd,&size, lpClass, lpcbClass ? *lpcbClass: 0);
428 popParameterInt32(rhnd,&size, lpcbClass);
429 popParameterInt32(rhnd,&size, lpReserved);
430 popParameterInt32(rhnd,&size, lpcSubKeys);
431 popParameterInt32(rhnd,&size, lpcbMaxSubKeyLen);
432 popParameterInt32(rhnd,&size, lpcbMaxClassLen);
433 popParameterInt32(rhnd,&size, lpcValues);
434 popParameterInt32(rhnd,&size, lpcbMaxValueNameLen);
435 popParameterInt32(rhnd,&size, lpcbMaxValueLen);
436 popParameterInt32(rhnd,&size, lpcbSecurityDescriptor);
437 popParameter(rhnd,&size, lpftLastWriteTime, sizeof(FILETIME));
438 if (lpftLastWriteTime)
440 lpftLastWriteTime->dwLowDateTime = (DWORD)letoh32(lpftLastWriteTime->dwLowDateTime);
441 lpftLastWriteTime->dwHighDateTime = (DWORD)letoh32(lpftLastWriteTime->dwHighDateTime);
447 DBG_printf( "size : %d\n", size );
448 /* flushbuffer( (rhnd->sock) );*/
453 STDAPI_( LONG ) CeRegEnumValue(RAPIHandleP rhnd, HKEY hKey, DWORD dwIndex, LPWSTR lpszValueName, LPDWORD lpcbValueName, LPDWORD lpReserved, LPDWORD lpType, LPBYTE lpData, LPDWORD lpcbData )
455 LONG result = ERROR_SUCCESS;
459 DBG_printf( "CeRegEnumValue( hKey = 0x%08X, dwIndex = 0x%08X, lpszValueName = 0x%08X, lpcbValueName = 0x%08X, lpReserved = 0x%08X, lpType = 0x%08X, lpData = 0x%08X, lpcbData = 0x%08X )\n",
460 hKey, dwIndex, lpszValueName, ( *lpcbValueName ), lpReserved, ( *lpType ), ( *lpData ), ( *lpcbData ) );
463 /* maybe check more parameters */
464 if (!lpcbValueName || lpReserved)
465 return 87; /* ERROR_INVALID_PARAMETER */
467 initBuf( (rhnd->buffer), size );
468 pushLong( (rhnd->buffer), size, 0x23 ); /* Command */
469 pushLong( (rhnd->buffer), size, hKey ); /* Parameter1 : */
470 pushLong( (rhnd->buffer), size, dwIndex ); /* Parameter2 : */
472 pushParameter(rhnd,size, lpszValueName, lpcbValueName ? *lpcbValueName * sizeof(WCHAR): 0, 0);
473 pushParameterInt32(rhnd,size, lpcbValueName, 1);
474 pushParameterInt32(rhnd,size, lpReserved, 1);
475 pushParameterInt32(rhnd,size, lpType, 1);
476 pushParameter(rhnd,size, lpData, lpcbData ? *lpcbData : 0, 0);
477 pushParameterInt32(rhnd,size, lpcbData, 1);
479 /* DBG_printbuf( (rhnd->buffer) );*/
480 sendbuffer( (rhnd->sock), (rhnd->buffer) );
482 size = getbufferlen( (rhnd->sock) );
484 result = getLong( (rhnd->sock), &size );
485 (rhnd->_lasterror) = getLong( (rhnd->sock), &size );
487 if (ERROR_SUCCESS == result)
489 /* here comes a result again! */
490 result = getLong( (rhnd->sock), &size );
493 if (ERROR_SUCCESS == result)
495 popParameter(rhnd,&size, lpszValueName, lpcbValueName ? *lpcbValueName : 0);
496 popParameterInt32(rhnd,&size, lpcbValueName);
497 popParameterInt32(rhnd,&size, lpType);
498 popParameter(rhnd,&size, lpData, lpcbData ? *lpcbData : 0);
499 popParameterInt32(rhnd,&size, lpcbData);
504 DBG_printf( "size : %d\n", size );
505 /* flushbuffer( (rhnd->sock) );*/
510 STDAPI_( LONG ) CeRegEnumKeyEx(RAPIHandleP rhnd, HKEY hKey, DWORD dwIndex, LPWSTR lpName, LPDWORD lpcbName, LPDWORD lpReserved, LPWSTR lpClass, LPDWORD lpcbClass, PFILETIME lpftLastWriteTime )
520 DBG_printf( "CeRegEnumKeyEx( hKey = 0x%08X, dwIndex = 0x%08X, lpcbName = 0x%08X, lpReserved = 0x%08X, lpClass = 0x%08X, lpcbClass = 0x%08X, lpftLastWriteTime = 0x%08X )\n",
521 hKey, dwIndex, lpName, lpcbName ? ( (void*)*lpcbName ) : lpcbName, lpReserved, lpClass, lpcbClass ? ( (void*)*lpcbClass ) : lpcbClass, lpftLastWriteTime );
523 initBuf( (rhnd->buffer), size );
524 pushLong( (rhnd->buffer), size, 0x1F ); /* Command */
525 pushLong( (rhnd->buffer), size, hKey ); /* Parameter1 : */
526 pushLong( (rhnd->buffer), size, dwIndex ); /* Parameter2 : */
527 pushLong( (rhnd->buffer), size, 0x01 ); /* Parameter3 : */
528 pushLong( (rhnd->buffer), size, 0x0202 ); /* Parameter4 : */
529 pushLong( (rhnd->buffer), size, 0x00 ); /* Parameter5 : */
530 pushLong( (rhnd->buffer), size, 0x01 ); /* Parameter6 : */
531 pushLong( (rhnd->buffer), size, 0x04 ); /* Parameter7 : */
532 pushLong( (rhnd->buffer), size, 0x01 ); /* Parameter8 : */
533 pushLong( (rhnd->buffer), size, lpcbName ? ( *lpcbName ) : 0 ); /* Parameter9 : */
534 pushLong( (rhnd->buffer), size, 0x00 ); /* Parameter10 : */
535 pushLong( (rhnd->buffer), size, 0x00 ); /* Parameter11 : */
536 pushLong( (rhnd->buffer), size, 0x00 ); /* Parameter12 : */
537 pushLong( (rhnd->buffer), size, 0x00 ); /* Parameter13 : */
538 DBG_printbuf( (rhnd->buffer) );
539 sendbuffer( (rhnd->sock), (rhnd->buffer) );
541 size = getbufferlen( (rhnd->sock) );
542 lng = getLong( (rhnd->sock), &size );
543 DBG_printf( "long : %ld (0x%08lx)\n", lng, lng );
544 (rhnd->_lasterror) = getLong( (rhnd->sock), &size );
545 DBG_printf( "long : %ld (0x%08lx)\n", (rhnd->_lasterror), (rhnd->_lasterror) );
546 errcode = getLong( (rhnd->sock), &size );
547 DBG_printf( "errcode : %ld (0x%08lx)\n", errcode, errcode );
548 lng = getLong( (rhnd->sock), &size );
549 DBG_printf( "long : %ld (0x%08lx)\n", lng, lng );
552 strsz = getLong( (rhnd->sock), &size );
553 DBG_printf( "long : %ld (0x%08lx)\n", strsz, strsz );
555 if ( lpcbName != NULL )
557 maxsz = ( *lpcbName );
558 ( *lpcbName ) = strsz - 1;
560 lng = getLong( (rhnd->sock), &size );
561 DBG_printf( "long : %ld (0x%08lx)\n", lng, lng );
562 str = getString( (rhnd->sock), &size, strsz >> 1 );
563 DBG_printf( "string1 : %s\n", str );
564 if ( ( lpName != NULL ) )
566 memcpy( lpName, str, MIN( strsz, maxsz ) );
569 for ( i = 0; i < 7; i++ )
571 lng = getLong( (rhnd->sock), &size );
572 DBG_printf( "long %d : %ld (0x%08lx)\n", i, lng, lng );
579 /* ================================================================================================================= */
580 /* ================================================================================================================= */
582 /* ================================================================================================================= */
583 /* ================================================================================================================= */
593 initBuf( (rhnd->buffer), size );
594 pushLong( (rhnd->buffer), size, 0x27 ); /* Command */
595 pushLong( (rhnd->buffer), size, 0x80000002 ); /* Parameter1 : */
596 pushLong( (rhnd->buffer), size, 0x01 ); /* Parameter2 : */
597 pushLong( (rhnd->buffer), size, 0x20 ); /* Parameter3 : */
598 pushString( (rhnd->buffer), size, "Comm\\SecurityProviders\\SCHANNEL" ); /* Parameter4 : the path */
599 pushLong( (rhnd->buffer), size, 0x01 ); /* Parameter2 : */
600 pushLong( (rhnd->buffer), size, 0x01 ); /* Parameter2 : */
601 pushShort( (rhnd->buffer), size, 0x00 ); /* Parameter2 : */
603 DBG_printbuf( (rhnd->buffer) );
604 sendbuffer( (rhnd->sock), (rhnd->buffer) );
605 result = readbuffer( (rhnd->sock), (rhnd->buffer), size );
606 DBG_printbuf( (rhnd->buffer) );
618 initBuf( (rhnd->buffer), size );
619 pushLong( (rhnd->buffer), size, 0x1E ); /* Command */
620 pushLong( (rhnd->buffer), size, 0x80000000 ); /* Parameter1 : */
621 pushLong( (rhnd->buffer), size, 0x01 ); /* Parameter2 : */
622 pushLong( (rhnd->buffer), size, 0x27 ); /* Parameter3 : */
623 pushString( (rhnd->buffer), size, "{000214A0-0000-0000-C000-000000000046}" ); /* Parameter3 : the path */
625 DBG_printbuf( (rhnd->buffer) );
626 sendbuffer( (rhnd->sock), (rhnd->buffer) );
627 result = readbuffer( (rhnd->sock), (rhnd->buffer), size );
628 DBG_printbuf( (rhnd->buffer) );
634 /* ================================================================================================================= */
635 /* ================================================================================================================= */
637 /* ================================================================================================================= */
638 /* ================================================================================================================= */
640 STDAPI_( BOOL ) CeFindAllFiles(RAPIHandleP rhnd, LPCWSTR szPath, DWORD dwFlags, LPDWORD lpdwFoundCount, LPLPCE_FIND_DATA ppFindDataArray )
649 DBG_printf( "CeFindAllFiles : szPath = 0x%08X, dwFlags = 0x%08X, lpdwFoundCount = 0x%08X, ppFindDataArray = 0x%08X\n", szPath, dwFlags, lpdwFoundCount, ppFindDataArray );
653 initBuf( (rhnd->buffer), size );
654 pushLong( (rhnd->buffer), size, 0x09 ); /* Command */
655 pushLong( (rhnd->buffer), size, 0x01 ); /* Parameter1 : */
656 pushLong( (rhnd->buffer), size, 1 + wcslen( szPath ) ); /* Parameter2 : */
657 pushString( (rhnd->buffer), size, szPath ); /* Parameter3 : the path */
658 pushLong( (rhnd->buffer), size, dwFlags ); /* Parameter4 : Flags ? */
659 DBG_printbuf( (rhnd->buffer) );
660 sendbuffer( (rhnd->sock), (rhnd->buffer) );
662 size = getbufferlen( (rhnd->sock) );
663 lng = getLong( (rhnd->sock), &size );
664 DBG_printf( "long 1 : %ld (0x%08lx)\n", lng, lng );
665 lng = getLong( (rhnd->sock), &size );
666 DBG_printf( "long 2 (nb answer) : %ld (0x%08lx)\n", lng, lng );
667 if ( lpdwFoundCount )
669 *lpdwFoundCount = lng;
671 if ( ppFindDataArray )
673 DBG_printf( "Before allocation\n" );
674 *ppFindDataArray = ( LPCE_FIND_DATA ) calloc( lng, sizeof( CE_FIND_DATA ) );
675 DBG_printf( "After allocation : *ppFindDataArray = %08X\n", *ppFindDataArray );
676 if ( ( *ppFindDataArray ) )
678 for ( i = 0; i < lng; i++ )
680 ptr = &( ( *ppFindDataArray ) [ i ] );
681 DBG_printf( "i=%d : ptr=%08X\n", i, ptr );
682 if ( dwFlags & FAF_NAME )
684 stlen = getLong( (rhnd->sock), &size );
685 DBG_printf( "string size : %ld (0x%08lx)\n", stlen, stlen );
687 if ( dwFlags & FAF_ATTRIBUTES )
689 ptr->dwFileAttributes = getLong( (rhnd->sock), &size );
690 DBG_printf( "ptr->dwFileAttributes : %ld (0x%08lx)\n", ptr->dwFileAttributes, ptr->dwFileAttributes );
692 if ( dwFlags & FAF_CREATION_TIME )
694 ptr->ftCreationTime.dwLowDateTime = getLong( (rhnd->sock), &size );
695 DBG_printf( "ptr->ftCreationTime.dwLowDateTime : %ld (0x%08lx)\n", ptr->ftCreationTime.dwLowDateTime, ptr->ftCreationTime.dwLowDateTime );
696 ptr->ftCreationTime.dwHighDateTime = getLong( (rhnd->sock), &size );
697 DBG_printf( "ptr->ftCreationTime.dwHighDateTime : %ld (0x%08lx)\n", ptr->ftCreationTime.dwHighDateTime, ptr->ftCreationTime.dwHighDateTime );
699 if ( dwFlags & FAF_LASTACCESS_TIME )
701 ptr->ftLastAccessTime.dwLowDateTime = getLong( (rhnd->sock), &size );
702 DBG_printf( "ptr->ftLastAccessTime.dwLowDateTime : %ld (0x%08lx)\n", ptr->ftLastAccessTime.dwLowDateTime, ptr->ftLastAccessTime.dwLowDateTime );
703 ptr->ftLastAccessTime.dwHighDateTime = getLong( (rhnd->sock), &size );
704 DBG_printf( "ptr->ftLastAccessTime.dwHighDateTime : %ld (0x%08lx)\n", ptr->ftLastAccessTime.dwHighDateTime, ptr->ftLastAccessTime.dwHighDateTime );
706 if ( dwFlags & FAF_LASTWRITE_TIME )
708 ptr->ftLastWriteTime.dwLowDateTime = getLong( (rhnd->sock), &size );
709 DBG_printf( "ptr->ftLastWriteTime.dwLowDateTime : %ld (0x%08lx)\n", ptr->ftLastWriteTime.dwLowDateTime, ptr->ftLastWriteTime.dwLowDateTime );
710 ptr->ftLastWriteTime.dwHighDateTime = getLong( (rhnd->sock), &size );
711 DBG_printf( "ptr->ftLastWriteTime.dwHighDateTime : %ld (0x%08lx)\n", ptr->ftLastWriteTime.dwHighDateTime, ptr->ftLastWriteTime.dwHighDateTime );
713 if ( dwFlags & FAF_SIZE_HIGH )
715 ptr->nFileSizeHigh = getLong( (rhnd->sock), &size );
716 DBG_printf( "ptr->nFileSizeHigh : %ld (0x%08lx)\n", ptr->nFileSizeHigh, ptr->nFileSizeHigh );
718 if ( dwFlags & FAF_SIZE_LOW )
720 ptr->nFileSizeLow = getLong( (rhnd->sock), &size );
721 DBG_printf( "ptr->nFileSizeLow : %ld (0x%08lx)\n", ptr->nFileSizeLow, ptr->nFileSizeLow );
723 if ( dwFlags & FAF_OID )
725 ptr->dwOID = getLong( (rhnd->sock), &size );
726 DBG_printf( "ptr->dwOID : %ld (0x%08lx)\n", ptr->dwOID, ptr->dwOID );
728 if ( dwFlags & FAF_NAME )
730 str = getString( (rhnd->sock), &size, stlen );
731 memcpy( ptr->cFileName, str, MAX_PATH );
732 DBG_printf( "ptr->cFileName : %s\n", ptr->cFileName );
741 STDAPI_( HANDLE ) CeFindFirstFile(RAPIHandleP rhnd, LPCWSTR lpFileName, LPCE_FIND_DATA lpFileFindData )
747 /* CEDB_FIND_DATA *ptr; */
749 DBG_printf( "CeFindFirstFile( lpFileName = 0x%08X, lpFileFindData = 0x%08X )\n",
750 lpFileName, lpFileFindData );
752 initBuf( (rhnd->buffer), size );
753 DBG_printf(" line : %d\n", __LINE__ );
754 pushLong( (rhnd->buffer), size, 0x00 ); /* Command */
755 DBG_printf(" line : %d\n", __LINE__ );
756 pushLong( (rhnd->buffer), size, 0x01 ); /* Parameter1 : */
757 DBG_printf(" line : %d\n", __LINE__ );
760 stlen = wcslen( lpFileName );
766 DBG_printf( "size : %d\n", stlen );
767 pushLong( (rhnd->buffer), size, 1 + stlen ); /* Parameter2 : Flags ? */
768 pushString( (rhnd->buffer), size, lpFileName ); /* Parameter3 : the path */
769 DBG_printbuf( (rhnd->buffer) );
770 sendbuffer( (rhnd->sock), (rhnd->buffer) );
772 size = getbufferlen( (rhnd->sock) );
774 lng = getLong( (rhnd->sock), &size );
775 DBG_printf( "long 1 : %ld (0x%08lx)\n", lng, lng );
776 (rhnd->_lasterror) = getLong( (rhnd->sock), &size );
777 DBG_printf( "long 2 (errorcode?): %ld (0x%08lx)\n", (rhnd->_lasterror), (rhnd->_lasterror) );
778 result = ( HANDLE ) getLong( (rhnd->sock), &size );
779 DBG_printf( "long 3 : (size=%d) HANDLE %ld (0x%08lx)\n", size, result, result );
780 lng = getLong( (rhnd->sock), &size );
781 DBG_printf( "long 4 : %ld (0x%08lx)\n", lng, lng );
782 if ( lpFileFindData )
784 lpFileFindData->dwFileAttributes = getLong( (rhnd->sock), &size );
785 getbufferchunk( (rhnd->sock), &size, &( lpFileFindData->ftCreationTime ), sizeof( FILETIME ) );
786 getbufferchunk( (rhnd->sock), &size, &( lpFileFindData->ftLastAccessTime ), sizeof( FILETIME ) );
787 getbufferchunk( (rhnd->sock), &size, &( lpFileFindData->ftLastWriteTime ), sizeof( FILETIME ) );
788 lpFileFindData->nFileSizeHigh = getLong( (rhnd->sock), &size );
789 lpFileFindData->nFileSizeLow = getLong( (rhnd->sock), &size );
790 lpFileFindData->dwOID = getLong( (rhnd->sock), &size );
791 memset( &( lpFileFindData->cFileName ), 0, MAX_PATH );
792 getbufferchunk( (rhnd->sock), &size, &( lpFileFindData->cFileName ), size );
795 DBG_printf( "size : %d\n", size );
798 flushbuffer( (rhnd->sock) );
800 DBG_printf( "long 5 : %ld (0x%08lx)\n", lpFileFindData->dwFileAttributes, lpFileFindData->dwFileAttributes );
804 STDAPI_( BOOL ) CeFindNextFile(RAPIHandleP rhnd, HANDLE hFindFile, /*LPWIN32_FIND_DATA ?*/LPCE_FIND_DATA lpFileFindData )
809 /* CEDB_FIND_DATA *ptr; */
811 DBG_printf( "CeFindNextFile( hFindFile = 0x%08X, lpFileFindData = 0x%08X )\n",
812 hFindFile, lpFileFindData );
814 initBuf( (rhnd->buffer), size );
815 pushLong( (rhnd->buffer), size, 0x01 ); /* Command */
816 pushLong( (rhnd->buffer), size, ( long ) hFindFile ); /* Parameter1 : */
817 DBG_printbuf( (rhnd->buffer) );
818 sendbuffer( (rhnd->sock), (rhnd->buffer) );
820 size = getbufferlen( (rhnd->sock) );
822 lng = getLong( (rhnd->sock), &size );
823 DBG_printf( "long 1 : %ld (0x%08lx)\n", lng, lng );
824 (rhnd->_lasterror) = getLong( (rhnd->sock), &size );
825 DBG_printf( "long 2 (errorcode?): %ld (0x%08lx)\n", (rhnd->_lasterror), (rhnd->_lasterror) );
826 lng = getLong( (rhnd->sock), &size );
827 DBG_printf( "long 3 (size=%d): %ld (0x%08lx)\n", size, lng, lng );
828 lng = getLong( (rhnd->sock), &size );
829 DBG_printf( "long 4 : %ld (0x%08lx)\n", lng, lng );
830 if ( lpFileFindData )
832 lpFileFindData->dwFileAttributes = getLong( (rhnd->sock), &size );
833 getbufferchunk( (rhnd->sock), &size, &( lpFileFindData->ftCreationTime ), sizeof( FILETIME ) );
834 getbufferchunk( (rhnd->sock), &size, &( lpFileFindData->ftLastAccessTime ), sizeof( FILETIME ) );
835 getbufferchunk( (rhnd->sock), &size, &( lpFileFindData->ftLastWriteTime ), sizeof( FILETIME ) );
836 lpFileFindData->nFileSizeHigh = getLong( (rhnd->sock), &size );
837 lpFileFindData->nFileSizeLow = getLong( (rhnd->sock), &size );
838 lpFileFindData->dwOID = getLong( (rhnd->sock), &size );
839 memset( &( lpFileFindData->cFileName ), 0, MAX_PATH );
840 getbufferchunk( (rhnd->sock), &size, &( lpFileFindData->cFileName ), size );
842 DBG_printf( "size : %d\n", size );
846 flushbuffer( (rhnd->sock) );
848 result = ( (rhnd->_lasterror) == 0 );
852 STDAPI_( BOOL ) CeFindClose(RAPIHandleP rhnd, HANDLE hFindFile )
857 DBG_printf( "CeFindClose()\n" );
859 initBuf( (rhnd->buffer), size );
860 pushLong( (rhnd->buffer), size, 0x02 ); /* Command */
861 pushLong( (rhnd->buffer), size, ( long ) hFindFile ); /* Parameter1 : */
862 DBG_printbuf( (rhnd->buffer) );
863 sendbuffer( (rhnd->sock), (rhnd->buffer) );
865 size = getbufferlen( (rhnd->sock) );
866 lng = getLong( (rhnd->sock), &size );
867 DBG_printf( "long 1 : %ld (0x%08lx)\n", lng, lng );
868 (rhnd->_lasterror) = getLong( (rhnd->sock), &size );
869 DBG_printf( "long 2 (lasterror): %ld (0x%08lx)\n", (rhnd->_lasterror), (rhnd->_lasterror) );
870 lng = getLong( (rhnd->sock), &size );
871 DBG_printf( "long 3 : %ld (0x%08lx)\n", lng, lng );
875 DBG_printf( "size : %d\n", size );
876 flushbuffer( (rhnd->sock) );
882 STDAPI_( HANDLE ) CeCreateFile(RAPIHandleP rhnd, LPCWSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, LPSECURITY_ATTRIBUTES lpSecurityAttributes, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile )
889 DBG_printf( "CeCreateFile( lpFileName = 0x%08X, dwDesiredAccess = 0x%08X, dwShareMode = 0x%08X )\n",
890 lpFileName, dwDesiredAccess, dwShareMode );
894 initBuf( (rhnd->buffer), size );
895 pushLong( (rhnd->buffer), size, 0x05 ); /* Command */
896 pushLong( (rhnd->buffer), size, dwDesiredAccess ); /* Parameter1 */
897 pushLong( (rhnd->buffer), size, dwShareMode ); /* Parameter2 */
898 pushLong( (rhnd->buffer), size, dwCreationDisposition ); /* Parameter3 */
899 pushLong( (rhnd->buffer), size, dwFlagsAndAttributes ); /* Parameter4 */
900 pushLong( (rhnd->buffer), size, ( long ) hTemplateFile ); /* Parameter5 */
901 pushLong( (rhnd->buffer), size, 1 ); /* Parameter6 */
902 stlen = wcslen( lpFileName );
903 pushLong( (rhnd->buffer), size, 1 + stlen ); /* Parameter7 */
904 pushString( (rhnd->buffer), size, lpFileName ); /* Parameter8 */
905 DBG_printbuf( (rhnd->buffer) );
906 sendbuffer( (rhnd->sock), (rhnd->buffer) );
908 size = getbufferlen( (rhnd->sock) );
910 lng = getLong( (rhnd->sock), &size );
911 DBG_printf( "long 1 : %ld (0x%08lx)\n", lng, lng );
912 (rhnd->_lasterror) = getLong( (rhnd->sock), &size );
913 DBG_printf( "long 2 (errorcode?): %ld (0x%08lx)\n", (rhnd->_lasterror), (rhnd->_lasterror) );
914 result = ( HANDLE ) getLong( (rhnd->sock), &size );
915 DBG_printf( "long 3 (HANDLE): %ld (0x%08lx)\n", result, result );
919 flushbuffer( (rhnd->sock) );
925 STDAPI_( BOOL ) CeReadFile(RAPIHandleP rhnd, HANDLE hFile, LPVOID lpBuffer, DWORD nNumberOfBytesToRead, LPDWORD lpNumberOfBytesRead, LPOVERLAPPED lpOverlapped )
930 /* CEDB_FIND_DATA *ptr; */
932 DBG_printf( "CeReadFile( hFile = 0x%08X, nNumberOfBytesToRead = 0x%08X )\n",
933 hFile, nNumberOfBytesToRead );
935 initBuf( (rhnd->buffer), size );
936 pushLong( (rhnd->buffer), size, 0x06 ); /* Command */
937 pushLong( (rhnd->buffer), size, ( long ) hFile ); /* Parameter1 */
938 pushLong( (rhnd->buffer), size, 0x01 ); /* Parameter2 */
939 pushLong( (rhnd->buffer), size, nNumberOfBytesToRead ); /* Parameter3 */
940 pushLong( (rhnd->buffer), size, 0x00 ); /* Parameter4 */
941 DBG_printbuf( (rhnd->buffer) );
942 sendbuffer( (rhnd->sock), (rhnd->buffer) );
944 size = getbufferlen( (rhnd->sock) );
946 lng = getLong( (rhnd->sock), &size );
947 DBG_printf( "long 1 : %ld (0x%08lx)\n", lng, lng );
948 (rhnd->_lasterror) = getLong( (rhnd->sock), &size );
949 DBG_printf( "long 2 (errorcode?): %ld (0x%08lx)\n", (rhnd->_lasterror), (rhnd->_lasterror) );
950 result = ( BOOL ) getLong( (rhnd->sock), &size );
951 DBG_printf( "long 3 (BOOL): %ld (0x%08lx)\n", result, result );
952 lng = getLong( (rhnd->sock), &size );
953 DBG_printf( "long 4 (size): %ld (0x%08lx)\n", lng, lng );
955 if ( lpNumberOfBytesRead )
957 *lpNumberOfBytesRead = lng;
959 if ( ( lpBuffer ) && ( lng > 0 ) )
961 getbufferchunk( (rhnd->sock), &size, lpBuffer, lng );
966 DBG_printf( "Size != 0 : size=%d\n", size );
967 flushbuffer( (rhnd->sock) );
973 STDAPI_( BOOL ) CeWriteFile(RAPIHandleP rhnd, HANDLE hFile, LPVOID lpBuffer,
974 DWORD nNumberOfBytesToWrite,
975 LPDWORD lpNumberOfBytesWritten,
976 LPOVERLAPPED lpOverlapped )
981 unsigned long buflen;
984 /* CEDB_FIND_DATA *ptr; */
986 DBG_printf( "CeWriteFile( hFile = 0x%08X, nNumberOfBytesToWrite = 0x%08X )\n",
987 hFile, nNumberOfBytesToWrite );
989 initBuf( (rhnd->buffer), size );
990 pushLong( (rhnd->buffer), size, 0x07 ); /* Command */
991 pushLong( (rhnd->buffer), size, ( long ) hFile ); /* Parameter1 */
992 pushLong( (rhnd->buffer), size, 0x01 ); /* Parameter2 */
993 pushLong( (rhnd->buffer), size, nNumberOfBytesToWrite ); /* Parameter3 */
995 buflen=_getbufferlen((rhnd->buffer));
996 _setbufferlen( (rhnd->buffer), buflen + nNumberOfBytesToWrite + 4);
998 (void) safe_write((rhnd->sock), (void *) (rhnd->buffer), buflen + 4);
1000 (void) safe_write((rhnd->sock), lpBuffer, nNumberOfBytesToWrite);
1002 (void) safe_write((rhnd->sock), (void *) &lng, sizeof(lng)); /* ??? continue ??? */
1004 size = getbufferlen( (rhnd->sock) );
1006 lng = getLong( (rhnd->sock), &size );
1007 DBG_printf( "long 1 : %ld (0x%08lx)\n", lng, lng );
1008 (rhnd->_lasterror) = getLong( (rhnd->sock), &size );
1009 DBG_printf( "long 2 (errorcode?): %ld (0x%08lx)\n", (rhnd->_lasterror), (rhnd->_lasterror) );
1011 result = ( BOOL ) getLong( (rhnd->sock), &size );
1012 DBG_printf( "long 3 (BOOL): %ld (0x%08lx)\n", result, result );
1013 lng = getLong( (rhnd->sock), &size );
1014 DBG_printf( "long 4 (size): %ld (0x%08lx)\n", lng, lng );
1016 if ( lpNumberOfBytesWritten )
1018 *lpNumberOfBytesWritten = lng;
1022 flushbuffer( (rhnd->sock) );
1028 /* ================================================================================================================= */
1029 /* ================================================================================================================= */
1030 /* RAPI - Databases */
1031 /* ================================================================================================================= */
1032 /* ================================================================================================================= */
1035 STDAPI_( BOOL ) CeFindAllDatabases(RAPIHandleP rhnd, DWORD dwDbaseType, WORD wFlags, LPWORD cFindData, LPLPCEDB_FIND_DATA ppFindData )
1037 long size = BUFSIZE;
1043 CEDB_FIND_DATA *ptr;
1047 DBG_printf( "CeFindAllDatabases( dwDbaseType = 0x%08X, wFlags = 0x%04X, cFindData = 0x%08X, ppFindData = 0x%08X )\n",
1048 dwDbaseType, wFlags, cFindData, ppFindData );
1050 initBuf( (rhnd->buffer), size );
1051 pushLong( (rhnd->buffer), size, 0x2C ); /* Command */
1052 pushLong( (rhnd->buffer), size, dwDbaseType ); /* Parameter1 : */
1053 pushShort( (rhnd->buffer), size, wFlags ); /* Parameter2 : Flags ? */
1054 DBG_printbuf( (rhnd->buffer) );
1055 sendbuffer( (rhnd->sock), (rhnd->buffer) );
1057 size = getbufferlen( (rhnd->sock) );
1058 lng = getLong( (rhnd->sock), &size );
1059 DBG_printf( "long 1 (errorcode?): %ld (0x%08lx)\n", lng, lng );
1060 wrd = getShort( (rhnd->sock), &size );
1061 DBG_printf( "word 1 : %d (0x%08lx)\n", wrd, wrd );
1066 if ( ppFindData && ( wrd > 0 ) )
1068 DBG_printf( "Before allocation\n" );
1069 *ppFindData = ( LPCEDB_FIND_DATA ) calloc( wrd, sizeof( CEDB_FIND_DATA ) );
1070 DBG_printf( "After allocation : *ppFindData = %08X\n", *ppFindData );
1071 if ( ( *ppFindData ) )
1073 for ( i = 0; i < wrd; i++ )
1075 ptr = &( ( *ppFindData ) [ i ] );
1076 DBG_printf( "i=%d : ptr=%08X\n", i, ptr );
1077 if ( wFlags & FAD_OID )
1079 ptr->OidDb = getLong( (rhnd->sock), &size );
1080 DBG_printf( "OidDb : %ld (0x%08lx)\n", ptr->OidDb, ptr->OidDb );
1082 if ( wFlags & FAD_NAME )
1084 stlen = getLong( (rhnd->sock), &size );
1085 DBG_printf( "string size : %ld (0x%08lx)\n", stlen, stlen );
1087 if ( wFlags & FAD_FLAGS )
1089 ptr->DbInfo.dwFlags = getLong( (rhnd->sock), &size );
1090 DBG_printf( "dwFlags : %ld (0x%08lx)\n", ptr->DbInfo.dwFlags, ptr->DbInfo.dwFlags );
1092 if ( wFlags & FAD_NAME )
1094 str = getString( (rhnd->sock), &size, stlen );
1095 memcpy( ptr->DbInfo.szDbaseName, str, sizeof( WCHAR ) * ( CEDB_MAXDBASENAMELEN > ( stlen ) ? CEDB_MAXDBASENAMELEN : ( stlen ) ) );
1096 DBG_printf( "ptr->DbInfo.szDbaseName : %s\n", ptr->DbInfo.szDbaseName );
1099 if ( wFlags & FAD_TYPE )
1101 ptr->DbInfo.dwDbaseType = getLong( (rhnd->sock), &size );
1102 DBG_printf( "dwDbaseType : %ld (0x%08lx)\n", ptr->DbInfo.dwDbaseType, ptr->DbInfo.dwDbaseType );
1104 if ( wFlags & FAD_NUM_RECORDS )
1106 ptr->DbInfo.wNumRecords = getShort( (rhnd->sock), &size );
1107 DBG_printf( "wNumRecords : %ld (0x%08lx)\n", ptr->DbInfo.wNumRecords, ptr->DbInfo.wNumRecords );
1109 if ( wFlags & FAD_NUM_SORT_ORDER )
1111 ptr->DbInfo.wNumSortOrder = getShort( (rhnd->sock), &size );
1112 DBG_printf( "wNumSortOrder : %ld (0x%08lx)\n", ptr->DbInfo.wNumSortOrder, ptr->DbInfo.wNumSortOrder );
1114 if ( wFlags & FAD_SIZE )
1116 ptr->DbInfo.dwSize = getLong( (rhnd->sock), &size );
1117 DBG_printf( "dwSize : %ld (0x%08lx)\n", ptr->DbInfo.dwSize, ptr->DbInfo.dwSize );
1119 if ( wFlags & FAD_LAST_MODIFIED )
1121 getFileTime( (rhnd->sock), &size, &( ptr->DbInfo.ftLastModified ) );
1122 DBG_printf( "ftLastModified : %ld (0x%08lx)\n", ptr->DbInfo.ftLastModified, ptr->DbInfo.ftLastModified );
1124 if ( wFlags & FAD_SORT_SPECS )
1126 for ( j = 0; j < CEDB_MAXSORTORDER; j++ )
1128 getbufferchunk( (rhnd->sock), &size, &( ( ptr->DbInfo.rgSortSpecs ) [ j ] ), sizeof( SORTORDERSPEC ) );
1129 DBG_printf( "sortOrder[%d] : %ld (0x%08lx)\n", j, ( ptr->DbInfo.rgSortSpecs ) [ j ].propid, ( ptr->DbInfo.rgSortSpecs ) [ j ].propid );
1130 DBG_printf( "sortOrder[%d] : %ld (0x%08lx)\n", j, ( ptr->DbInfo.rgSortSpecs ) [ j ].dwFlags, ( ptr->DbInfo.rgSortSpecs ) [ j ].dwFlags );
1139 STDAPI_( HANDLE ) CeOpenDatabase(RAPIHandleP rhnd, PCEOID poid, LPWSTR lpszName, CEPROPID propid, DWORD dwFlags, HWND hwndNotify )
1141 long size = BUFSIZE;
1145 DBG_printf( "CeOpenDatabase( poid = 0x%08X, lpszName = 0x%08X, propid = 0x%08X, dwFlags = 0x%08X, hwndNotify = 0x%08X )\n",
1146 poid ? ( (void*)*poid ) : NULL, lpszName, propid, dwFlags, hwndNotify );
1148 initBuf( (rhnd->buffer), size );
1149 pushLong( (rhnd->buffer), size, 0x0E ); /* Command */
1150 pushLong( (rhnd->buffer), size, poid ? ( ( long ) ( *poid ) ) : ( ( long ) NULL ) ); /* Parameter1 : */
1151 pushLong( (rhnd->buffer), size, propid ); /* Parameter2 : */
1152 pushLong( (rhnd->buffer), size, dwFlags ); /* Parameter3 : */
1153 DBG_printbuf( (rhnd->buffer) );
1154 sendbuffer( (rhnd->sock), (rhnd->buffer) );
1156 size = getbufferlen( (rhnd->sock) );
1157 lng = getLong( (rhnd->sock), &size );
1158 DBG_printf( "long 1 (errorcode?): %ld (0x%08lx)\n", lng, lng );
1159 lng = getLong( (rhnd->sock), &size );
1160 DBG_printf( "long 2 (errorcode?): %ld (0x%08lx)\n", lng, lng );
1161 (rhnd->_lasterror) = lng;
1162 result = ( HANDLE ) getLong( (rhnd->sock), &size );
1163 DBG_printf( "long 3 (errorcode?): %ld (0x%08lx)\n", result, result );
1168 STDAPI_( CEOID ) CeReadRecordProps(RAPIHandleP rhnd, HANDLE hDbase, DWORD dwFlags, LPWORD lpcPropID, CEPROPID* rgPropID, LPBYTE* lplpBuffer, LPDWORD lpcbBuffer )
1170 long size = BUFSIZE;
1179 DBG_printf( "CeReadRecordProps( hDbase = 0x%08X, dwFlags = 0x%08X, lpcPropID = 0x%08X, rgPropID = 0x%08X, lplpBuffer = 0x%08X, lpcbBuffer = 0x%08X )\n",
1180 hDbase, dwFlags, lpcPropID, rgPropID, lplpBuffer, lpcbBuffer );
1182 initBuf( (rhnd->buffer), size );
1183 pushLong( (rhnd->buffer), size, 0x10 ); /* Command */
1184 pushLong( (rhnd->buffer), size, ( long ) hDbase ); /* Parameter1 : */
1185 pushLong( (rhnd->buffer), size, dwFlags ); /* Parameter2 : Flags ? */
1186 pushLong( (rhnd->buffer), size, 0 ); /* Parameter3 */
1187 pushLong( (rhnd->buffer), size, 0 ); /* Parameter4 */
1188 pushShort( (rhnd->buffer), size, 0 ); /* Parameter5 */
1189 DBG_printbuf( (rhnd->buffer) );
1190 sendbuffer( (rhnd->sock), (rhnd->buffer) );
1192 size = getbufferlen( (rhnd->sock) );
1193 lng = getLong( (rhnd->sock), &size );
1194 DBG_printf( "long 1 (errorcode?): %ld (0x%08lx)\n", lng, lng );
1195 (rhnd->_lasterror) = getLong( (rhnd->sock), &size );
1196 DBG_printf( "long 2: lasterror %ld (0x%08lx)\n", (rhnd->_lasterror), (rhnd->_lasterror) );
1197 result = getLong( (rhnd->sock), &size );
1198 DBG_printf( "long 3: CEOID %ld (0x%08lx)\n", result, result );
1199 lng = getLong( (rhnd->sock), &size );
1200 DBG_printf( "long 4: (taille buffer) %ld (0x%08lx)\n", lng, lng );
1201 if ( lpcbBuffer && ( ( *lpcbBuffer ) == 0 ) )
1205 wrd = getShort( (rhnd->sock), &size );
1206 DBG_printf( "word 1: (nbprops) %ld (0x%08lx)\n", wrd, wrd );
1219 if ( lplpBuffer && ( wrd > 0 ) )
1221 if ( *lplpBuffer == NULL )
1223 DBG_printf( "Before allocation\n" );
1224 *lplpBuffer = ( LPBYTE ) calloc( 1, lng );
1225 DBG_printf( "After allocation : *ppFindData = %08X\n", *lplpBuffer );
1227 ptr = ( CEPROPVAL * ) ( *lplpBuffer );
1228 for ( i = 0; i < wrd; i++ )
1230 DBG_printf( "i=%d : ptr=%08X\n", i, ptr );
1231 getbufferchunk( (rhnd->sock), &size, &( ptr[ i ] ), sizeof( CEPROPVAL ) );
1232 DBG_printf( "propval: propid %ld (0x%08lx) \n", ptr[ i ].propid, ptr[ i ].propid );
1233 DBG_printf( "propval: wLenData %d (0x%04x) \n", ptr[ i ].wLenData, ptr[ i ].wLenData );
1234 DBG_printf( "propval: wFlags %d (0x%04x) \n", ptr[ i ].wFlags, ptr[ i ].wFlags );
1235 switch ( ( ptr[ i ].propid ) & 0xFFFF )
1238 ptr[ i ].val.blob.lpb = ( LPBYTE ) ( ( DWORD ) ptr + ( DWORD ) ptr[ i ].val.blob.lpb );
1239 DBG_printf( "propval: BLOB (size : %d, ptr %-8X)\n", ptr[ i ].val.blob.dwCount, ptr[ i ].val.blob.lpb );
1242 ptr[ i ].val.lpwstr = ( LPWSTR ) ( ( DWORD ) ptr + ( DWORD ) ptr[ i ].val.lpwstr );
1243 DBG_printf( "propval: LPWSTR %ld (0x%08lx) \n", ptr[ i ].val.lpwstr, ptr[ i ].val.lpwstr );
1246 DBG_printf( "propval: I2 %d (0x%04x) \n", ptr[ i ].val.iVal, ptr[ i ].val.iVal );
1249 DBG_printf( "propval: UI2 %d (0x%04x) \n", ptr[ i ].val.uiVal, ptr[ i ].val.uiVal );
1252 DBG_printf( "propval: I4 %ld (0x%08lx) \n", ptr[ i ].val.lVal, ptr[ i ].val.lVal );
1255 DBG_printf( "propval: UI4 %ld (0x%08lx) \n", ptr[ i ].val.ulVal, ptr[ i ].val.ulVal );
1258 DBG_printf( "propval: BOOL %s\n", ptr[ i ].val.boolVal ? "true" : "false" );
1261 DBG_printf( "propval: FILETIME 0x%-8x\n", ptr[ i ].val.filetime );
1264 DBG_printf( "propval: R8 %d ", ptr[ i ].val.dblVal );
1269 /* DBG_printf( "propval: sz:%d %ld (0x%08lx) \n", sizeof(CEVALUNION), valunion, valunion ); */
1272 ptrbyte = ( LPBYTE ) & ( ptr[ wrd ] );
1273 index = ( long ) ( lng - ( ptrbyte - ( *lplpBuffer ) ) );
1274 DBG_printf( " getchunk : index = %d, size = %d\n", index, size );
1275 getbufferchunk( (rhnd->sock), &size, ptrbyte, ( ( long ) ptrbyte > index ) ? index : ( long ) ptrbyte );
1280 STDAPI_(CEOID) CeWriteRecordProps(RAPIHandleP rhnd, HANDLE hDbase, CEOID oidRecord, WORD cPropID, CEPROPVAL* rgPropVal)
1282 long size = BUFSIZE;
1284 long datalen, buflen;
1288 DBG_printf( "CeWriteRecordProps( hDbase = 0x%08X, oidRecord = 0x%08X, cPropID = 0x%08X, rgPropVal = 0x%08X )\n",
1289 hDbase, oidRecord, cPropID, rgPropVal );
1292 * Format of the CeWriteRecordProps packet - primitives are encoded in the CEPROPVAL structures, lpwstr and blob properties are
1293 * attached to the end of the buffer and referenced by offset pointers
1295 * long hDBase | long oidRecord | long cPropID | long datalen (of following data) | n * CEPROPVAL | char[] data
1297 * Because CEPROPVAL is a union, the format is different for every type of prop:
1299 * long or short (iVal, uiVal, lVal, ulVal, boolVal): long propid | short wFlags | short wLenData (unused, set to 0) | short iVal or boolVal | short uiVal | long lVal or ulVal
1301 * FILETIME or double: long propid | short wFlags | short wLenData (unused) | DWORD FILETIME or double
1303 * lpwstr: long propid | short wFlags | short wLenData (unused) | long offset ( points to string data in data buffer, counted from beginning of CEPROPVALs)
1305 * blob: long propid | short wFlags | short wLenData (unused) | long blobsize | long offset (same as lpwstr)
1309 initBuf( (rhnd->buffer), size );
1310 pushLong( (rhnd->buffer), size, 0x11 ); /* Command */
1311 pushLong( (rhnd->buffer), size, ( long ) hDbase ); /* Parameter1 : */
1312 pushLong( (rhnd->buffer), size, oidRecord ); /* Parameter2 : Flags ? */
1313 pushShort( (rhnd->buffer), size, cPropID ); /* Parameter3 */
1317 * we have to go through the rgPropVals array three times:
1318 * 1. to determine the size of the whole buffer, including data
1319 * 2. to write out the CEPROPVAL array
1320 * 3. to write the data segment
1323 /* calculate the length of the whole buffer, including the data segment at the end */
1325 buflen = cPropID * sizeof( CEPROPVAL ); /* length of all cepropvals */
1327 for ( i = 0; i < cPropID; i++ )
1329 switch ( ( rgPropVal[i].propid ) & 0xFFFF )
1332 buflen += rgPropVal[i].val.blob.dwCount;
1335 buflen += 2* ( wcslen( rgPropVal[i].val.lpwstr ) + 1 );
1342 pushLong( (rhnd->buffer), size, buflen);
1345 second time: write n * CEPROPVAL. Can't do it in one block, as we have to adjust the buffer offsets
1348 datalen = cPropID * sizeof( CEPROPVAL ); /* holds the offset to the end of the data buffer */
1350 for ( i = 0; i < cPropID; i++ )
1352 pushLong( (rhnd->buffer), size, rgPropVal[i].propid );
1353 pushShort( (rhnd->buffer), size, rgPropVal[i].wLenData );
1354 pushShort( (rhnd->buffer), size, rgPropVal[i].wFlags );
1356 switch ( ( rgPropVal[i].propid ) & 0xFFFF )
1359 pushLong( (rhnd->buffer), size, rgPropVal[i].val.blob.dwCount );
1360 datalen += rgPropVal[i].val.blob.dwCount;
1361 pushLong( (rhnd->buffer), size, datalen );
1364 datalen += 2* ( wcslen( rgPropVal[i].val.lpwstr ) + 1 );
1365 pushLong( (rhnd->buffer), size, datalen );
1366 pushLong( (rhnd->buffer), size, 0 );
1372 pushShort( (rhnd->buffer), size, rgPropVal[i].val.iVal );
1373 pushShort( (rhnd->buffer), size, rgPropVal[i].val.uiVal );
1374 pushLong( (rhnd->buffer), size, rgPropVal[i].val.lVal );
1377 pushShort( (rhnd->buffer), size, rgPropVal[i].val.boolVal );
1378 pushShort( (rhnd->buffer), size, 0 );
1379 pushLong( (rhnd->buffer), size, 0 );
1382 /* this assumes that the FILETIME is already in ole32 format! Is this a problem? */
1383 pushLong( (rhnd->buffer), size, rgPropVal[i].val.filetime.dwLowDateTime );
1384 pushLong( (rhnd->buffer), size, rgPropVal[i].val.filetime.dwHighDateTime );
1387 pushParameter(rhnd, size, &(rgPropVal[i].val.dblVal), 4, 1 );
1394 /* 3. write the data segment */
1396 for ( i = 0; i < cPropID; i++ )
1398 switch ( ( rgPropVal[i].propid ) & 0xFFFF )
1401 pushParameter_no_size(rhnd, size, rgPropVal[i].val.blob.lpb, rgPropVal[i].val.blob.dwCount );
1404 pushParameter_no_size(rhnd, size, rgPropVal[i].val.lpwstr, 2* ( wcslen( rgPropVal[i].val.lpwstr ) + 1) );
1411 DBG_printbuf( (rhnd->buffer) );
1412 sendbuffer( (rhnd->sock), (rhnd->buffer) );
1414 size = getbufferlen( (rhnd->sock) );
1416 lng = getLong( (rhnd->sock), &size );
1417 DBG_printf( "long 1 : %ld (0x%08lx)\n", lng, lng );
1418 (rhnd->_lasterror) = getLong( (rhnd->sock), &size );
1419 DBG_printf( "long 2 (errorcode?): %ld (0x%08lx)\n", (rhnd->_lasterror), (rhnd->_lasterror) );
1420 result = ( HANDLE ) getLong( (rhnd->sock), &size );
1421 DBG_printf( "long 3 (HANDLE): %ld (0x%08lx)\n", result, result );
1425 flushbuffer( (rhnd->sock) );
1432 /* ================================================================================================================= */
1433 /* ================================================================================================================= */
1434 /* RAPI - Processes */
1435 /* ================================================================================================================= */
1436 /* ================================================================================================================= */
1438 STDAPI_( BOOL ) CeCreateProcess(RAPIHandleP rhnd, LPCWSTR lpApplicationName,
1439 LPCWSTR lpCommandLine,
1440 LPSECURITY_ATTRIBUTES lpProcessAttributes,
1441 LPSECURITY_ATTRIBUTES lpThreadAttributes,
1442 BOOL bInheritHandles,
1443 DWORD dwCreationFlags,
1444 LPVOID lpEnvironment,
1445 LPWSTR lpCurrentDirectory,
1446 LPSTARTUPINFO lpStartupInfo,
1447 LPPROCESS_INFORMATION lpProcessInformation )
1449 long size = BUFSIZE;
1452 BOOL result = FALSE;
1454 DBG_printf( "CeCreateProcess( lpApplication = 0x%08X, lpCommandLine = 0x%08X )\n",
1455 lpApplicationName, lpCommandLine );
1457 initBuf( (rhnd->buffer), size );
1458 pushLong( (rhnd->buffer), size, 0x19 ); /* Command */
1459 if(lpApplicationName!=NULL)
1461 pushLong( (rhnd->buffer), size, 0x01 );
1462 stlen = wcslen( lpApplicationName );
1463 pushLong( (rhnd->buffer), size, (stlen+1)*2 );
1464 pushLong( (rhnd->buffer), size, 0x01 );
1465 pushString( (rhnd->buffer), size, lpApplicationName );
1469 pushLong( (rhnd->buffer), size, 0x00 );
1471 if(lpCommandLine!=NULL)
1473 pushLong( (rhnd->buffer), size, 0x01 );
1474 stlen = wcslen( lpCommandLine );
1475 pushLong( (rhnd->buffer), size, (stlen+1)*2 );
1476 pushLong( (rhnd->buffer), size, 0x01 );
1477 pushString( (rhnd->buffer), size, lpCommandLine );
1481 pushLong( (rhnd->buffer), size, 0x00 );
1484 pushLong( (rhnd->buffer), size, 0x00 ); /* Parameter3 : lpProcessAttibutes ? */
1485 pushLong( (rhnd->buffer), size, 0x00 ); /* Parameter4 : lpThreadAttributes ? */
1486 pushLong( (rhnd->buffer), size, 0x00 ); /* Parameter5 : bInheritHandles ? */
1487 pushLong( (rhnd->buffer), size, dwCreationFlags );
1488 pushLong( (rhnd->buffer), size, 0x00 ); /* Parameter7 : lpEnvironment ? */
1489 pushLong( (rhnd->buffer), size, 0x00 ); /* Parameter8 : lpCurrentDirectory ? */
1490 pushLong( (rhnd->buffer), size, 0x00 ); /* Parameter9 : lpStartupInfo ? */
1491 pushLong( (rhnd->buffer), size, 0x00 ); /* Parametera : lpProcessInformation ? */
1493 DBG_printbuf( (rhnd->buffer) );
1495 sendbuffer( (rhnd->sock), (rhnd->buffer) );
1497 size = getbufferlen( (rhnd->sock) );
1498 lng = getLong( (rhnd->sock), &size );
1499 DBG_printf( "long 1 (errorcode?): %ld (0x%08lx)\n", lng, lng );
1500 (rhnd->_lasterror) = getLong( (rhnd->sock), &size );
1501 DBG_printf( "long 2: lasterror %ld (0x%08lx)\n", (rhnd->_lasterror), (rhnd->_lasterror) );
1503 result = getLong( (rhnd->sock), &size );
1504 DBG_printf( "long 3: %ld (0x%08lx)\n", result, result );
1507 lng = getLong( (rhnd->sock), &size );
1508 DBG_printf( "long 4: %ld (0x%08lx)\n", lng, lng );
1509 lng = getLong( (rhnd->sock), &size );
1510 DBG_printf( "long 5: %ld (0x%08lx)\n", lng, lng );
1511 lng = getLong( (rhnd->sock), &size );
1512 DBG_printf( "long 6: %ld (0x%08lx)\n", lng, lng );
1513 lng = getLong( (rhnd->sock), &size );
1514 DBG_printf( "long 7: %ld (0x%08lx)\n", lng, lng );
1515 lng = getLong( (rhnd->sock), &size );
1516 DBG_printf( "long 8: %ld (0x%08lx)\n", lng, lng );
1517 lng = getLong( (rhnd->sock), &size );
1518 DBG_printf( "long 9: %ld (0x%08lx)\n", lng, lng );
1519 lng = getLong( (rhnd->sock), &size );
1520 DBG_printf( "long a: %ld (0x%08lx)\n", lng, lng );
1524 lng = getLong( (rhnd->sock), &size );
1525 DBG_printf( "long 4: %ld (0x%08lx)\n", lng, lng );
1530 flushbuffer( (rhnd->sock) );
1536 /* ================================================================================================================= */
1537 /* ================================================================================================================= */
1538 /* RAPI - General */
1539 /* ================================================================================================================= */
1540 /* ================================================================================================================= */
1542 STDAPI_( BOOL ) CeCloseHandle(RAPIHandleP rhnd, HANDLE hObject )
1544 long size = BUFSIZE;
1547 DBG_printf( "CeCloseHandle()\n" );
1549 initBuf( (rhnd->buffer), size );
1550 pushLong( (rhnd->buffer), size, 0x08 ); /* Command */
1551 pushLong( (rhnd->buffer), size, ( long ) hObject ); /* Parameter1 : */
1552 DBG_printbuf( (rhnd->buffer) );
1553 sendbuffer( (rhnd->sock), (rhnd->buffer) );
1555 size = getbufferlen( (rhnd->sock) );
1556 lng = getLong( (rhnd->sock), &size );
1557 DBG_printf( "long 1 : %ld (0x%08lx)\n", lng, lng );
1558 (rhnd->_lasterror) = getLong( (rhnd->sock), &size );
1559 DBG_printf( "long 2 (lasterror): %ld (0x%08lx)\n", (rhnd->_lasterror), (rhnd->_lasterror) );
1560 lng = getLong( (rhnd->sock), &size );
1561 DBG_printf( "long 3 : %ld (0x%08lx)\n", lng, lng );
1566 STDAPI_( DWORD ) CeGetLastError(RAPIHandleP rhnd)
1568 return (rhnd->_lasterror);
1571 /* ================================================================================================================= */
1572 /* ================================================================================================================= */
1573 /* RAPI - Library */
1574 /* ================================================================================================================= */
1575 /* ================================================================================================================= */
1577 void findquotes( char * *ptrstart, char * *ptrstop )
1579 /* Go to the first double quote */
1580 /* ---------------------------- */
1581 while( ( *(*ptrstart) != 0 ) && ( *(*ptrstart) != '"' ) )
1585 if( *(*ptrstart) != 0 )
1588 *ptrstop = *ptrstart;
1589 /* Reach the next double quote */
1590 /* --------------------------- */
1591 while( ( *(*ptrstop) != 0 ) && ( *(*ptrstop) != '"' ) )
1598 int parseinfofile( RAPIHandleP rhnd );
1600 int parseinfofile( RAPIHandleP rhnd )
1602 BOOL result = FALSE;
1612 devicefound = FALSE;
1614 DBG_printf( "Before stat...\n" );
1615 res = stat( INFOFILE, &st );
1616 DBG_printf( "stat(), result = %d...\n", res );
1619 f = fopen( INFOFILE, "r" );
1620 DBG_printf( "fopen(), result = 0x%08X...\n", f );
1623 while ( ( !feof( f ) ) && ( result == FALSE ) )
1626 if ( fgets( line, 1024, f ) != NULL )
1628 DBG_printf( "fscanf(), line = '%s'...\n", line );
1629 if ( line[ 0 ] != '#' )
1631 /* Beginning of block : device <IP> { */
1632 /* ---------------------------------- */
1633 if( ((rhnd->hostname)==NULL) && ( ( ptrstart = strstr( line, "device" ) ) != NULL ) )
1637 for ( ptrstop = ptrstart; ( ( *ptrstop ) != 0 ) && ( ( *ptrstop ) != '{' ); ptrstop++ );
1639 (rhnd->hostname) = strdup( ptrstart );
1640 DBG_printf( "strdup(), hostname = '%s'...\n", (rhnd->hostname) );
1646 /* End of block : } */
1647 /* ---------------- */
1648 if( strstr( line, "}" ) != NULL )
1651 devicefound = FALSE;
1656 /* let's check for the passphrase */
1657 /* ------------------------------ */
1658 if( ( ((rhnd->lockbuffersize)!=0) || ((rhnd->lockbuffer)==NULL)) && ( ( ptrstart = strstr( line, "passphrase" ) ) != NULL ) )
1660 DBG_printf( "found string passphrase = %s\n", line );
1661 findquotes( &ptrstart, &ptrstop );
1663 if( (*ptrstart) != 0 )
1666 if( NULL != strstr( line, "size" ) )
1668 DBG_printf( "found string passphrase-size = %s\n", ptrstart );
1669 if( 1 == sscanf( ptrstart, "%d", &(rhnd->lockbuffersize) ) )
1671 DBG_printf( "found passphrase-size = %d\n", (rhnd->lockbuffersize) );
1672 (rhnd->lockbuffer) = (unsigned char *) malloc( 1+ (rhnd->lockbuffersize) );
1675 for( i=0; i<(rhnd->lockbuffersize); i++ )
1677 sscanf( ptrstart + (3*i), "%02X", (unsigned int *)&((rhnd->lockbuffer)[i]) );
1678 DBG_printf("%02X ", (rhnd->lockbuffer)[i] );
1680 DBG_printf( "\nfound passphrase-data = %s\n", ptrstart );
1695 STDAPI_( HRESULT ) CeRapiInit(RAPIHandleP rhnd)
1697 if ( (rhnd->sock) == 0 )
1699 parseinfofile(rhnd);
1700 if ( (rhnd->hostname) )
1702 DBG_printf( "CeRapiInit(%s)\n", (rhnd->hostname) );
1703 (rhnd->sock) = SockOpen( (rhnd->hostname), 990 );
1704 if ( (rhnd->sock) > 0 )
1706 DBG_printf( "CeRapiInit(%s) ok\n", (rhnd->hostname) );
1707 free( (rhnd->hostname) );
1708 (rhnd->buffer) = (rapibuffer *)malloc( 4 + BUFSIZE );
1710 checkpassword(rhnd);
1716 DBG_printf( "CeRapiInit(%s) Nok\n", (rhnd->hostname) );
1717 free( (rhnd->hostname) );
1720 free( (rhnd->hostname) );
1724 DBG_printf( "No CE Device found !?!\n" );
1730 DBG_printf( "CeRapiInit() already done\n" );
1731 return CERAPI_E_ALREADYINITIALIZED;
1734 /* STDAPI CeRapiInitEx (RAPIINIT*); */
1736 STDAPI_( HRESULT ) CeRapiUninit(RAPIHandleP rhnd)
1738 HRESULT result = FALSE;
1739 if( (rhnd->buffer) )
1741 free( (rhnd->buffer) );
1742 (rhnd->buffer) = NULL;
1744 if ( (rhnd->sock) > 0 )
1746 result = (close( (rhnd->sock) )==0) ? TRUE : FALSE;
1747 DBG_printf( "CeRapiUninit() %s\n", (result ? "ok" : "failed") );
1749 /* the following is needed to make subsequent init/uninit calls to RAPI
1750 * (e.g. device disconnect/reconnect) */
1754 (rhnd->hostname) = NULL;
1760 DBG_printf( "CeRapiUninit() no need\n" );
1765 STDAPI_( HRESULT ) CeRapiFreeBuffer(RAPIHandleP rhnd, LPVOID Buffer )
1771 return ( HRESULT ) NULL;
1774 STDAPI_(BOOL) CeGetVersionEx(RAPIHandleP rhnd,LPCEOSVERSIONINFO lpVersion)
1776 BOOL result = FALSE;
1777 long size = BUFSIZE;
1782 initBuf((rhnd->buffer), size);
1784 pushLong((rhnd->buffer), size, 0x3B); /* Command */
1785 pushParameter(rhnd,size, lpVersion, lpVersion->dwOSVersionInfoSize, 0);
1787 sendbuffer( (rhnd->sock), (rhnd->buffer) );
1788 size = getbufferlen( (rhnd->sock) );
1791 * The return package looks like this
1797 * 0c 4 n = real size of buffer
1798 * 10 n first n bytes of struct
1801 lng = getLong((rhnd->sock), &size);
1802 (rhnd->_lasterror) = getLong((rhnd->sock), &size);
1806 result = getLong((rhnd->sock), &size);
1809 long real_length = getLong((rhnd->sock), &size);
1810 getbufferchunk((rhnd->sock), &size, lpVersion, real_length);
1815 DBG_printf("Warning: expected 0 but got %i=0x%x\n", lng, lng);
1820 DBG_printf( "size : %d\n", size );
1821 flushbuffer( (rhnd->sock) );
1827 STDAPI_(BOOL) CeCreateDirectory(RAPIHandleP rhnd,LPCWSTR lpDirName, LPSECURITY_ATTRIBUTES lpSecAttr)
1829 BOOL result = FALSE;
1830 long size = BUFSIZE;
1833 initBuf((rhnd->buffer), size);
1835 pushLong((rhnd->buffer), size, 0x17); /* Command */
1836 pushParameter(rhnd,size, (void*)lpDirName, (wcslen(lpDirName) + 1) * sizeof(WCHAR), 1);
1837 pushLong((rhnd->buffer), size, 0); /* lpSecAttr not used */
1839 /*DBG_printbuf( (rhnd->buffer) );*/
1840 sendbuffer( (rhnd->sock), (rhnd->buffer) );
1841 size = getbufferlen( (rhnd->sock) );
1844 * The return package looks like this
1848 * 04 4 error code if the value below is 0
1852 lng = getLong((rhnd->sock), &size);
1853 (rhnd->_lasterror) = getLong((rhnd->sock), &size);
1857 result = getLong((rhnd->sock), &size);
1861 DBG_printf("Warning: expected 0 but got %i=0x%x\n", lng, lng);
1866 DBG_printf( "size : %d\n", size );
1867 flushbuffer( (rhnd->sock) );
1873 STDAPI_(BOOL) CeRemoveDirectory(RAPIHandleP rhnd,LPCWSTR lpPathName)
1875 BOOL result = FALSE;
1876 long size = BUFSIZE;
1879 initBuf((rhnd->buffer), size);
1881 pushLong((rhnd->buffer), size, 0x18); /* Command */
1882 pushParameter(rhnd,size, (void*)lpPathName, (wcslen(lpPathName) + 1) * sizeof(WCHAR), 1);
1884 /*DBG_printbuf( (rhnd->buffer) );*/
1885 sendbuffer( (rhnd->sock), (rhnd->buffer) );
1886 size = getbufferlen( (rhnd->sock) );
1889 * The return package looks like this
1893 * 04 4 error code if the value below is 0
1897 lng = getLong((rhnd->sock), &size);
1898 (rhnd->_lasterror) = getLong((rhnd->sock), &size);
1902 result = getLong((rhnd->sock), &size);
1906 DBG_printf("Warning: expected 0 but got %i=0x%x\n", lng, lng);
1911 DBG_printf( "size : %d\n", size );
1912 flushbuffer( (rhnd->sock) );
1918 STDAPI_(BOOL) CeDeleteFile(RAPIHandleP rhnd,LPCWSTR lpFileName)
1920 BOOL result = FALSE;
1921 long size = BUFSIZE;
1924 initBuf((rhnd->buffer), size);
1926 pushLong((rhnd->buffer), size, 0x1c); /* Command */
1927 pushParameter(rhnd,size, (void*)lpFileName, (wcslen(lpFileName) + 1) * sizeof(WCHAR), 1);
1929 /*DBG_printbuf( (rhnd->buffer) );*/
1930 sendbuffer( (rhnd->sock), (rhnd->buffer) );
1931 size = getbufferlen( (rhnd->sock) );
1934 * The return package looks like this
1938 * 04 4 error code if the value below is 0
1942 lng = getLong((rhnd->sock), &size);
1943 DBG_printf("long 1 : %ld (0x%08lx)\n", lng, lng);
1944 (rhnd->_lasterror) = getLong((rhnd->sock), &size);
1945 DBG_printf("long 2 : %ld (0x%08lx)\n", (rhnd->_lasterror), (rhnd->_lasterror));
1949 result = getLong((rhnd->sock), &size);
1950 DBG_printf("long 3 : %ld (0x%08lx)\n", result, result);
1954 DBG_printf("Warning: expected 0 but got %i=0x%x\n", lng, lng);
1959 DBG_printf( "size : %d\n", size );
1960 flushbuffer( (rhnd->sock) );
1966 STDAPI_( BOOL ) CeMoveFile(RAPIHandleP rhnd, LPCWSTR lpExistingFileName, LPCWSTR lpNewFileName )
1968 BOOL result = FALSE;
1969 long size = BUFSIZE;
1972 initBuf((rhnd->buffer), size);
1974 pushLong((rhnd->buffer), size, 0x1a); /* Command */
1975 pushParameter(rhnd,size, (void*)lpExistingFileName, (wcslen(lpExistingFileName) + 1) * sizeof(WCHAR), 1);
1976 pushParameter(rhnd,size, (void*)lpNewFileName, (wcslen(lpNewFileName) + 1) * sizeof(WCHAR), 1);
1978 /*DBG_printbuf( (rhnd->buffer) );*/
1979 sendbuffer( (rhnd->sock), (rhnd->buffer) );
1980 size = getbufferlen( (rhnd->sock) );
1983 * The return package looks like this
1987 * 04 4 error code if the value below is 0
1991 lng = getLong((rhnd->sock), &size);
1992 DBG_printf("long 1 : %ld (0x%08lx)\n", lng, lng);
1993 (rhnd->_lasterror) = getLong((rhnd->sock), &size);
1994 DBG_printf("long 2 : %ld (0x%08lx)\n", (rhnd->_lasterror), (rhnd->_lasterror));
1998 result = getLong((rhnd->sock), &size);
1999 DBG_printf("long 3 : %ld (0x%08lx)\n", result, result);
2003 DBG_printf("Warning: expected 0 but got %i=0x%x\n", lng, lng);
2008 DBG_printf( "size : %d\n", size );
2009 flushbuffer( (rhnd->sock) );
2015 void CeGetSystemInfo(RAPIHandleP rhnd,LPSYSTEM_INFO lpSystemInfo)
2017 BOOL result = FALSE;
2018 long size = BUFSIZE;
2021 initBuf((rhnd->buffer), size);
2023 pushLong((rhnd->buffer), size, 0x2f); /* Command */
2024 pushParameter(rhnd,size, lpSystemInfo, sizeof(SYSTEM_INFO), 0);
2026 sendbuffer( (rhnd->sock), (rhnd->buffer) );
2027 size = getbufferlen( (rhnd->sock) );
2030 * The return package looks like this
2036 * 0c 4 n = real size of buffer
2037 * 10 n first n bytes of struct
2040 lng = getLong((rhnd->sock), &size);
2041 (rhnd->_lasterror) = getLong((rhnd->sock), &size);
2044 * Note: On my system, 36 bytes are returned but sizeof(SYSTEM_INFO) is only 32!
2046 * "Overflow by 4 bytes. Parameter size is 36 bytes but max 32 bytes was expected."
2051 popParameter(rhnd,&size, lpSystemInfo, sizeof(SYSTEM_INFO));
2055 DBG_printf("Warning: expected 0 but got %i=0x%x\n", lng, lng);
2060 DBG_printf( "size : %d\n", size );
2061 flushbuffer( (rhnd->sock) );