/[openpgpmdrv]/trunk/OpenPGPminidriver/CardPublicDataOperation.c
ViewVC logotype

Annotation of /trunk/OpenPGPminidriver/CardPublicDataOperation.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 8 - (hide annotations)
Thu Mar 11 20:32:26 2010 UTC (15 years, 1 month ago) by vletoux
File MIME type: text/plain
File size: 12683 byte(s)
improvement of the quality of the project.
More test for the qualification of the driver success but not all ...

1 vletoux 1 /* OpenPGP Smart Card Mini Driver
2     Copyright (C) 2009 Vincent Le Toux
3    
4     This library is Free software; you can redistribute it and/or
5     modify it under the terms of the GNU Lesser General Public
6     License version 2.1 as published by the Free Software Foundation.
7    
8     This library is distributed in the hope that it will be useful,
9     but WITHOUT ANY WARRANTY; without even the implied warranty of
10     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11     Lesser General Public License for more details.
12    
13     You should have received a copy of the GNU Lesser General Public
14     License along with this library; if not, write to the Free Software
15     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16     */
17    
18     #include <windows.h>
19     #include <cardmod.h>
20     #include "Tracing.h"
21     #include "Context.h"
22     #include "PublicDataOperations.h"
23    
24     // 4.3 Public Data Operations
25    
26     /** This function creates a subdirectory from the root in the file system of
27     the card and applies the provided access condition. Directories are generally
28     created for segregating the files that belong to a single application on the card.
29     As an example, the files that belong to the Microsoft cryptographic application
30     are in the “mscp” directory.*/
31    
32     DWORD WINAPI CardCreateDirectory(
33     __in PCARD_DATA pCardData,
34     __in LPSTR pszDirectoryName,
35     __in CARD_DIRECTORY_ACCESS_CONDITION AccessCondition
36     )
37     {
38     Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
39     return SCARD_E_UNSUPPORTED_FEATURE;
40     }
41    
42     /** This function deletes a directory from the card. This operation fails if it violates
43     permissions on the directory or if the directory is not empty. */
44     DWORD WINAPI CardDeleteDirectory(
45     __in CARD_DATA *pCardData,
46     __in LPSTR pszDirectoryName
47     )
48     {
49     Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
50     return SCARD_E_UNSUPPORTED_FEATURE;
51     }
52    
53     /** The CardReadFile function reads the entire file at the specified location into the
54     user-supplied buffer.*/
55     DWORD WINAPI CardReadFile(
56     __in PCARD_DATA pCardData,
57     __in_opt LPSTR pszDirectoryName,
58     __in LPSTR pszFileName,
59     __in DWORD dwFlags,
60     __deref_out_bcount_opt(*pcbData) PBYTE *ppbData,
61     __out PDWORD pcbData
62     )
63     {
64     DWORD dwReturn = 0;
65     PSTR szFiles = NULL;
66    
67     Trace(WINEVENT_LEVEL_VERBOSE, L"Enter %S\\%S",pszDirectoryName,pszFileName);
68     __try
69     {
70     if ( pCardData == NULL )
71     {
72     Trace(WINEVENT_LEVEL_ERROR, L"pCardData == NULL");
73     dwReturn = SCARD_E_INVALID_PARAMETER;
74     __leave;
75     }
76     if ( pszFileName == NULL )
77     {
78     Trace(WINEVENT_LEVEL_ERROR, L"pszFileName == NULL");
79     dwReturn = SCARD_E_INVALID_PARAMETER;
80     __leave;
81     }
82 vletoux 8 if ( *pszFileName == 0 )
83     {
84     Trace(WINEVENT_LEVEL_ERROR, L"pszFileName empty");
85     dwReturn = SCARD_E_INVALID_PARAMETER;
86     __leave;
87     }
88 vletoux 1 if (ppbData == NULL)
89     {
90     Trace(WINEVENT_LEVEL_ERROR, L"ppbData == NULL");
91     dwReturn = SCARD_E_INVALID_PARAMETER;
92     __leave;
93     }
94     if (pcbData == NULL)
95     {
96     Trace(WINEVENT_LEVEL_ERROR, L"pcbData == NULL");
97     dwReturn = SCARD_E_INVALID_PARAMETER;
98     __leave;
99     }
100     if (dwFlags != 0)
101     {
102     dwReturn = SCARD_E_INVALID_PARAMETER;
103     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags = 0x%08X", dwFlags);
104     __leave;
105     }
106     dwReturn = CheckContext(pCardData);
107     if (dwReturn)
108     {
109     __leave;
110     }
111 vletoux 8 dwReturn = OCardReadFile(pCardData, pszDirectoryName, pszFileName, ppbData, pcbData);
112 vletoux 1 }
113     __finally
114     {
115     }
116     Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
117     return dwReturn;
118     }
119    
120     /** The CardCreateFile function creates a file on the card with a specified name and
121     access permission. This function cannot be used to create directories. If the directory
122     that is named by pszDirectoryName does not exist, the function fails with SCARD_E_DIR_NOT_FOUND.*/
123     DWORD WINAPI CardCreateFile(
124     __in PCARD_DATA pCardData,
125     __in_opt LPSTR pszDirectoryName,
126     __in LPSTR pszFileName,
127     __in DWORD cbInitialCreationSize,
128     __in CARD_FILE_ACCESS_CONDITION AccessCondition
129     )
130     {
131     DWORD dwReturn = 0;
132 vletoux 8 POPENPGP_CONTEXT pContext = NULL;
133 vletoux 1 Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
134     __try
135     {
136     if ( pCardData == NULL )
137     {
138     Trace(WINEVENT_LEVEL_ERROR, L"pCardData == NULL");
139     dwReturn = SCARD_E_INVALID_PARAMETER;
140     __leave;
141     }
142     if ( pszFileName == NULL || pszFileName[0] == 0)
143     {
144     Trace(WINEVENT_LEVEL_ERROR, L"pszFileName == NULL or empty");
145     dwReturn = SCARD_E_INVALID_PARAMETER;
146     __leave;
147     }
148     dwReturn = CheckContext(pCardData);
149     if (dwReturn)
150     {
151     __leave;
152     }
153 vletoux 8 pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
154     if (pContext->fIsReadOnly)
155     {
156     dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
157     Trace(WINEVENT_LEVEL_ERROR, L"Readonly card");
158     __leave;
159     }
160     dwReturn = OCardCreateFile(pCardData, pszDirectoryName, pszFileName);
161 vletoux 1 }
162     __finally
163     {
164     }
165     Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
166     return dwReturn;
167     }
168    
169     /** This function retrieves information about a file, specifically its size and ACL information.*/
170    
171     DWORD WINAPI CardGetFileInfo(
172     __in PCARD_DATA pCardData,
173     __in_opt LPSTR pszDirectoryName,
174     __in LPSTR pszFileName,
175     __inout PCARD_FILE_INFO pCardFileInfo
176     )
177     {
178 vletoux 8 DWORD dwReturn = 0, dwVersion;
179 vletoux 1
180     Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
181     __try
182     {
183     if ( pCardData == NULL )
184     {
185     Trace(WINEVENT_LEVEL_ERROR, L"pCardData == NULL");
186     dwReturn = SCARD_E_INVALID_PARAMETER;
187     __leave;
188     }
189     if ( pszFileName == NULL || pszFileName[0] == 0)
190     {
191     Trace(WINEVENT_LEVEL_ERROR, L"pszFileName == NULL or empty");
192     dwReturn = SCARD_E_INVALID_PARAMETER;
193     __leave;
194     }
195     if ( pCardFileInfo == NULL )
196     {
197     Trace(WINEVENT_LEVEL_ERROR, L"pCardFileInfo == NULL");
198     dwReturn = SCARD_E_INVALID_PARAMETER;
199     __leave;
200     }
201 vletoux 8 dwVersion = (pCardFileInfo->dwVersion == 0) ? 1 : pCardFileInfo->dwVersion;
202     if ( dwVersion != CARD_CAPABILITIES_CURRENT_VERSION )
203     {
204     Trace(WINEVENT_LEVEL_ERROR, L"dwVersion %d", dwVersion);
205     dwReturn = ERROR_REVISION_MISMATCH;
206     __leave;
207     }
208 vletoux 1 dwReturn = CheckContext(pCardData);
209     if (dwReturn)
210     {
211     __leave;
212     }
213 vletoux 8 dwReturn = OCardGetFileInfo(pCardData, pszDirectoryName, pszFileName, pCardFileInfo);
214 vletoux 1
215     }
216     __finally
217     {
218     }
219     Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
220     return dwReturn;
221     }
222    
223     /** The CardWriteFile function writes the entire contents of a data buffer to a file.
224     The file contents are replaced, starting at the beginning of the file. The file must
225     exist, or CardWriteFile fails.*/
226    
227     DWORD WINAPI CardWriteFile(
228     __in PCARD_DATA pCardData,
229     __in_opt LPSTR pszDirectoryName,
230     __in LPSTR pszFileName,
231     __in DWORD dwFlags,
232     __in_bcount(cbData) PBYTE pbData,
233     __in DWORD cbData
234     )
235     {
236     DWORD dwReturn = 0;
237 vletoux 8 POPENPGP_CONTEXT pContext = NULL;
238 vletoux 1 Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
239     __try
240     {
241     if ( pCardData == NULL )
242     {
243     Trace(WINEVENT_LEVEL_ERROR, L"pCardData == NULL");
244     dwReturn = SCARD_E_INVALID_PARAMETER;
245     __leave;
246     }
247     if ( pszFileName == NULL || pszFileName[0] == 0)
248     {
249     Trace(WINEVENT_LEVEL_ERROR, L"pszFileName == NULL or empty");
250     dwReturn = SCARD_E_INVALID_PARAMETER;
251     __leave;
252     }
253     if ( pbData == NULL)
254     {
255     Trace(WINEVENT_LEVEL_ERROR, L"pbData == NULL");
256     dwReturn = SCARD_E_INVALID_PARAMETER;
257     __leave;
258     }
259     if ( cbData == 0)
260     {
261     Trace(WINEVENT_LEVEL_ERROR, L"cbData == 0");
262     dwReturn = SCARD_E_INVALID_PARAMETER;
263     __leave;
264     }
265     if (dwFlags)
266     {
267     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == %d", dwFlags);
268     dwReturn = SCARD_E_INVALID_PARAMETER;
269     __leave;
270     }
271     dwReturn = CheckContext(pCardData);
272     if (dwReturn)
273     {
274     __leave;
275     }
276 vletoux 8 pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
277     if (pContext->fIsReadOnly)
278     {
279     dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
280     Trace(WINEVENT_LEVEL_ERROR, L"Readonly card");
281     __leave;
282     }
283     dwReturn = OCardWriteFile(pCardData, pszDirectoryName, pszFileName, pbData, cbData);
284 vletoux 1 }
285     __finally
286     {
287     }
288     Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
289     return dwReturn;
290     }
291    
292     /** The CardDeleteFile function deletes the specified file. If the file does not exist,
293     the returned Status value should indicate that the file did not exist.*/
294    
295     DWORD WINAPI CardDeleteFile(
296     __in PCARD_DATA pCardData,
297     __in_opt LPSTR pszDirectoryName,
298     __in LPSTR pszFileName,
299     __in DWORD dwFlags
300     )
301     {
302     DWORD dwReturn = 0;
303 vletoux 8 POPENPGP_CONTEXT pContext = NULL;
304 vletoux 1 PBYTE pbData = NULL;
305     DWORD dwSize = 0;
306     Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
307     __try
308     {
309     if ( pCardData == NULL )
310     {
311     Trace(WINEVENT_LEVEL_ERROR, L"pCardData == NULL");
312     dwReturn = SCARD_E_INVALID_PARAMETER;
313     __leave;
314     }
315     if ( pszFileName == NULL || pszFileName[0] == 0)
316     {
317     Trace(WINEVENT_LEVEL_ERROR, L"pszFileName == NULL or empty");
318     dwReturn = SCARD_E_INVALID_PARAMETER;
319     __leave;
320     }
321     if (dwFlags)
322     {
323     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
324     dwReturn = SCARD_E_INVALID_PARAMETER;
325     __leave;
326     }
327     dwReturn = CheckContext(pCardData);
328     if (dwReturn)
329     {
330     __leave;
331     }
332 vletoux 8 pContext = (POPENPGP_CONTEXT) pCardData->pvVendorSpecific;
333     if (pContext->fIsReadOnly)
334     {
335     dwReturn = SCARD_E_UNSUPPORTED_FEATURE;
336     Trace(WINEVENT_LEVEL_ERROR, L"Readonly card");
337     __leave;
338     }
339     dwReturn = OCardDeleteFile(pCardData, pszDirectoryName, pszFileName);
340 vletoux 1 }
341     __finally
342     {
343     }
344     Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
345     return dwReturn;
346     }
347    
348     /** The CardEnumFiles function returns name information about available files in a
349     directory as a multistring list.*/
350    
351     DWORD WINAPI CardEnumFiles(
352     __in PCARD_DATA pCardData,
353     __in_opt LPSTR pszDirectoryName,
354     __deref_out_ecount(*pdwcbFileName) LPSTR *pmszFileNames,
355     __out LPDWORD pdwcbFileName,
356     __in DWORD dwFlags
357     )
358     {
359     DWORD dwReturn = 0;
360     PSTR szFiles = NULL;
361     Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
362     __try
363     {
364     if ( pCardData == NULL )
365     {
366     Trace(WINEVENT_LEVEL_ERROR, L"pCardData == NULL");
367     dwReturn = SCARD_E_INVALID_PARAMETER;
368     __leave;
369     }
370     if ( pmszFileNames == NULL )
371     {
372     Trace(WINEVENT_LEVEL_ERROR, L"pmszFileNames == NULL");
373     dwReturn = SCARD_E_INVALID_PARAMETER;
374     __leave;
375     }
376 vletoux 8 if ( pdwcbFileName == NULL )
377 vletoux 1 {
378     Trace(WINEVENT_LEVEL_ERROR, L"pmszFileNames == NULL");
379     dwReturn = SCARD_E_INVALID_PARAMETER;
380     __leave;
381     }
382     if (dwFlags != 0)
383     {
384     dwReturn = SCARD_E_INVALID_PARAMETER;
385     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags = 0x%08X", dwFlags);
386     __leave;
387     }
388     if (pszDirectoryName != NULL)
389     {
390     DWORD dwLen = (DWORD) strlen(pszDirectoryName);
391     if (dwLen > 8 || dwLen == 0)
392     {
393     dwReturn = SCARD_E_INVALID_PARAMETER;
394     Trace(WINEVENT_LEVEL_ERROR, L"Invalid directory %S", pszDirectoryName);
395     __leave;
396     }
397     }
398     dwReturn = CheckContext(pCardData);
399     if (dwReturn)
400     {
401     __leave;
402     }
403 vletoux 8 dwReturn = OCardEnumFile(pCardData, pszDirectoryName, pmszFileNames, pdwcbFileName);
404 vletoux 1 }
405     __finally
406     {
407     }
408     Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
409     return dwReturn;
410     }
411    
412     /** The CardQueryFreeSpace function determines the amount of available card storage space.*/
413     DWORD WINAPI CardQueryFreeSpace(
414     __in PCARD_DATA pCardData,
415     __in DWORD dwFlags,
416     __inout PCARD_FREE_SPACE_INFO pCardFreeSpaceInfo
417     )
418     {
419 vletoux 8 DWORD dwReturn = 0, dwVersion;
420 vletoux 1 Trace(WINEVENT_LEVEL_VERBOSE, L"Enter");
421     __try
422     {
423     if ( pCardData == NULL )
424     {
425     Trace(WINEVENT_LEVEL_ERROR, L"pCardData == NULL");
426     dwReturn = SCARD_E_INVALID_PARAMETER;
427     __leave;
428     }
429     if ( pCardFreeSpaceInfo == NULL)
430     {
431     Trace(WINEVENT_LEVEL_ERROR, L"pCardFreeSpaceInfo == NULL");
432     dwReturn = SCARD_E_INVALID_PARAMETER;
433     __leave;
434     }
435 vletoux 8 dwVersion = (pCardFreeSpaceInfo->dwVersion == 0) ? 1 : pCardFreeSpaceInfo->dwVersion;
436     if ( dwVersion != CARD_FREE_SPACE_INFO_CURRENT_VERSION )
437     {
438     Trace(WINEVENT_LEVEL_ERROR, L"dwVersion %d", dwVersion);
439     dwReturn = ERROR_REVISION_MISMATCH;
440     __leave;
441     }
442 vletoux 1 if (dwFlags)
443     {
444     Trace(WINEVENT_LEVEL_ERROR, L"dwFlags == 0");
445     dwReturn = SCARD_E_INVALID_PARAMETER;
446     __leave;
447     }
448     pCardFreeSpaceInfo->dwVersion = CARD_FREE_SPACE_INFO_CURRENT_VERSION;
449     pCardFreeSpaceInfo->dwMaxKeyContainers = 3;
450     pCardFreeSpaceInfo->dwKeyContainersAvailable = CARD_DATA_VALUE_UNKNOWN;
451     pCardFreeSpaceInfo->dwBytesAvailable = CARD_DATA_VALUE_UNKNOWN;
452     dwReturn = 0;
453     }
454     __finally
455     {
456     }
457     Trace(WINEVENT_LEVEL_VERBOSE, L"dwReturn = 0x%08X",dwReturn);
458     return dwReturn;
459     }
460    

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26