[Pcsclite-cvs-commit] CVS libmusclecard/src

CVS User rousseau ludovic.rousseau@free.fr
Wed, 06 Oct 2004 02:11:50 -0600


Update of /cvsroot/pcsclite/libmusclecard/src
In directory haydn:/tmp/cvs-serv28189/src

Modified Files:
	musclecard.c muscletest.c 
Log Message:
patch from Toni Andjelkovic for the pcsc-lite/libmusclecard separation


--- /cvsroot/pcsclite/libmusclecard/src/musclecard.c	2004/09/17 19:02:56	1.43
+++ /cvsroot/pcsclite/libmusclecard/src/musclecard.c	2004/10/06 08:11:50	1.44
@@ -10,7 +10,7 @@
  * You may not remove this header from this file without 
  * prior permission from the author.
  *
- * $Id: musclecard.c,v 1.43 2004/09/17 19:02:56 corcoran-guest Exp $
+ * $Id: musclecard.c,v 1.44 2004/10/06 08:11:50 rousseau Exp $
  */
 
 #include "config.h"
@@ -18,9 +18,12 @@
 #include <stdlib.h>
 #include <stdio.h>
 
+#include <pcsclite.h>
+#include <winscard.h>
 #include "musclecard.h"
 #include "debuglog.h"
 #include "tokenfactory.h"
+#include "strlcpycat.h"
 
 #ifdef USE_THREAD_SAFETY
 #include "wintypes.h"
@@ -175,23 +178,23 @@
 					if (rgReaderStates.dwEventState & SCARD_STATE_EMPTY)
 					{
 						currentToken->tokenType |= MSC_TOKEN_TYPE_REMOVED;
-						strncpy(currentToken->tokenName,
+						strlcpy(currentToken->tokenName,
 							MSC_TOKEN_EMPTY_STR, MSC_MAXSIZE_TOKENAME);
 					}
 					else if (rv == 0)
 					{
 						currentToken->tokenType |= MSC_TOKEN_TYPE_KNOWN;
-						strncpy(currentToken->tokenName,
+						strlcpy(currentToken->tokenName,
 							tokenInfo.tokenName, MSC_MAXSIZE_TOKENAME);
 					}
 					else
 					{
 						currentToken->tokenType |= MSC_TOKEN_TYPE_UNKNOWN;
-						strncpy(currentToken->tokenName,
+						strlcpy(currentToken->tokenName,
 							MSC_TOKEN_UNKNOWN_STR, MSC_MAXSIZE_TOKENAME);
 					}
 
-					strncpy(currentToken->slotName,
+					strlcpy(currentToken->slotName,
 						rgReaderStates.szReader, MAX_READERNAME);
 
 					if (rgReaderStates.dwEventState & SCARD_STATE_PRESENT)
@@ -200,11 +203,14 @@
 							rgReaderStates.rgbAtr, rgReaderStates.cbAtr);
 						currentToken->tokenIdLength = rgReaderStates.cbAtr;
 
-       						memcpy(currentToken->tokenApp,
-                					tokenInfo.tokenApp, tokenInfo.tokenAppLen);
-        					currentToken->tokenAppLen = tokenInfo.tokenAppLen;
-        
-					        strncpy(currentToken->svProvider,
+						if (rv != -1) {
+       							memcpy(currentToken->tokenApp,
+                						tokenInfo.tokenApp,
+								tokenInfo.tokenAppLen);
+        						currentToken->tokenAppLen =
+								tokenInfo.tokenAppLen;
+						}
+					        strlcpy(currentToken->svProvider,
                 					tokenInfo.svProvider, MSC_MAXSIZE_SVCPROV);
 					}
 					else
@@ -412,9 +418,9 @@
 
 	memcpy(pConnection->tokenInfo.tokenId, tokenId, tokenIdLength);
 	pConnection->tokenInfo.tokenIdLength = tokenIdLength;
-	strncpy(pConnection->tokenInfo.slotName, tokenStruct->slotName,
+	strlcpy(pConnection->tokenInfo.slotName, tokenStruct->slotName,
 		MAX_READERNAME);
-	strncpy(pConnection->tokenInfo.tokenName, tokenStruct->tokenName,
+	strlcpy(pConnection->tokenInfo.tokenName, tokenStruct->tokenName,
 		MSC_MAXSIZE_TOKENAME);
 
 	/*
@@ -683,7 +689,7 @@
 				memset(tokenArray[i].tokenId, 0x00, MAX_ATR_SIZE);
 				tokenArray[i].tokenIdLength = 0;
 				tokenArray[i].tokenType = MSC_TOKEN_TYPE_REMOVED;
-				strncpy(tokenArray[i].tokenName, MSC_TOKEN_EMPTY_STR,
+				strlcpy(tokenArray[i].tokenName, MSC_TOKEN_EMPTY_STR,
 					MSC_MAXSIZE_TOKENAME);
 			}
 			else if (tokenArray[i].tokenState & MSC_STATE_PRESENT)
@@ -700,13 +706,13 @@
 				if (rt == 0)
 				{
 					tokenArray[i].tokenType = MSC_TOKEN_TYPE_KNOWN;
-					strncpy(tokenArray[i].tokenName, tokenInfo.tokenName,
+					strlcpy(tokenArray[i].tokenName, tokenInfo.tokenName,
 						MSC_MAXSIZE_TOKENAME);
 				}
 				else
 				{
 					tokenArray[i].tokenType = MSC_TOKEN_TYPE_UNKNOWN;
-					strncpy(tokenArray[i].tokenName, MSC_TOKEN_UNKNOWN_STR,
+					strlcpy(tokenArray[i].tokenName, MSC_TOKEN_UNKNOWN_STR,
 						MSC_MAXSIZE_TOKENAME);
 				}
 			}
@@ -1736,7 +1742,7 @@
 			objInfo.objectACL.writePermission;
 		pObjectInfo->objectACL.deletePermission =
 			objInfo.objectACL.deletePermission;
-		strncpy(pObjectInfo->objectID, objectID, MSC_MAXSIZE_OBJID);
+		strlcpy(pObjectInfo->objectID, objectID, MSC_MAXSIZE_OBJID);
 		return MSC_SUCCESS;
 	}
 
@@ -1760,7 +1766,7 @@
 		objInfo.objectACL.writePermission;
 	pObjectInfo->objectACL.deletePermission =
 		objInfo.objectACL.deletePermission;
-	strncpy(pObjectInfo->objectID, objectID, MSC_MAXSIZE_OBJID);
+	strlcpy(pObjectInfo->objectID, objectID, MSC_MAXSIZE_OBJID);
 
 	return MSC_SUCCESS;
 }
@@ -1861,94 +1867,94 @@
 	switch (errorCode)
 	{
 		case MSC_SUCCESS:
-			strncpy(message, "Successful", sizeof(message));
+			strlcpy(message, "Successful", sizeof(message));
 			break;
 		case MSC_NO_MEMORY_LEFT:
-			strncpy(message, "No more memory", sizeof(message));
+			strlcpy(message, "No more memory", sizeof(message));
 			break;
 		case MSC_AUTH_FAILED:
-			strncpy(message, "Authentication failed", sizeof(message));
+			strlcpy(message, "Authentication failed", sizeof(message));
 			break;
 		case MSC_OPERATION_NOT_ALLOWED:
-			strncpy(message, "Operation not allowed", sizeof(message));
+			strlcpy(message, "Operation not allowed", sizeof(message));
 			break;
 		case MSC_INCONSISTENT_STATUS:
-			strncpy(message, "Inconsistent status", sizeof(message));
+			strlcpy(message, "Inconsistent status", sizeof(message));
 			break;
 		case MSC_UNSUPPORTED_FEATURE:
-			strncpy(message, "Feature unsupported", sizeof(message));
+			strlcpy(message, "Feature unsupported", sizeof(message));
 			break;
 		case MSC_UNAUTHORIZED:
-			strncpy(message, "Unauthorized usage", sizeof(message));
+			strlcpy(message, "Unauthorized usage", sizeof(message));
 			break;
 		case MSC_OBJECT_NOT_FOUND:
-			strncpy(message, "Object not found", sizeof(message));
+			strlcpy(message, "Object not found", sizeof(message));
 			break;
 		case MSC_OBJECT_EXISTS:
-			strncpy(message, "Object already exists", sizeof(message));
+			strlcpy(message, "Object already exists", sizeof(message));
 			break;
 		case MSC_INCORRECT_ALG:
-			strncpy(message, "Incorrect algorithm", sizeof(message));
+			strlcpy(message, "Incorrect algorithm", sizeof(message));
 			break;
 		case MSC_SIGNATURE_INVALID:
-			strncpy(message, "Invalid signature", sizeof(message));
+			strlcpy(message, "Invalid signature", sizeof(message));
 			break;
 		case MSC_IDENTITY_BLOCKED:
-			strncpy(message, "Identity is blocked", sizeof(message));
+			strlcpy(message, "Identity is blocked", sizeof(message));
 			break;
 		case MSC_UNSPECIFIED_ERROR:
-			strncpy(message, "Unspecified error", sizeof(message));
+			strlcpy(message, "Unspecified error", sizeof(message));
 			break;
 		case MSC_TRANSPORT_ERROR:
-			strncpy(message, "Transport error", sizeof(message));
+			strlcpy(message, "Transport error", sizeof(message));
 			break;
 		case MSC_INVALID_PARAMETER:
-			strncpy(message, "Invalid parameter", sizeof(message));
+			strlcpy(message, "Invalid parameter", sizeof(message));
 			break;
 		case MSC_INCORRECT_P1:
-			strncpy(message, "Incorrect P1 parameter", sizeof(message));
+			strlcpy(message, "Incorrect P1 parameter", sizeof(message));
 			break;
 		case MSC_INCORRECT_P2:
-			strncpy(message, "Incorrect P2 parameter", sizeof(message));
+			strlcpy(message, "Incorrect P2 parameter", sizeof(message));
 			break;
 		case MSC_SEQUENCE_END:
-			strncpy(message, "End of sequence", sizeof(message));
+			strlcpy(message, "End of sequence", sizeof(message));
 			break;
 		case MSC_INTERNAL_ERROR:
-			strncpy(message, "Internal Error", sizeof(message));
+			strlcpy(message, "Internal Error", sizeof(message));
 			break;
 		case MSC_CANCELLED:
-			strncpy(message, "Operation Cancelled", sizeof(message));
+			strlcpy(message, "Operation Cancelled", sizeof(message));
 			break;
 		case MSC_INSUFFICIENT_BUFFER:
-			strncpy(message, "Buffer is too small", sizeof(message));
+			strlcpy(message, "Buffer is too small", sizeof(message));
 			break;
 		case MSC_UNRECOGNIZED_TOKEN:
-			strncpy(message, "Token is unsupported", sizeof(message));
+			strlcpy(message, "Token is unsupported", sizeof(message));
 			break;
 		case MSC_SERVICE_UNRESPONSIVE:
-			strncpy(message, "Service is not running", sizeof(message));
+			strlcpy(message, "Service is not running", sizeof(message));
 			break;
 		case MSC_TIMEOUT_OCCURRED:
-			strncpy(message, "Timeout has occurred", sizeof(message));
+			strlcpy(message, "Timeout has occurred", sizeof(message));
 			break;
 		case MSC_TOKEN_REMOVED:
-			strncpy(message, "Token was removed", sizeof(message));
+			strlcpy(message, "Token was removed", sizeof(message));
 			break;
 		case MSC_TOKEN_RESET:
-			strncpy(message, "Token was reset", sizeof(message));
+			strlcpy(message, "Token was reset", sizeof(message));
 			break;
 		case MSC_TOKEN_INSERTED:
-			strncpy(message, "Token was inserted", sizeof(message));
+			strlcpy(message, "Token was inserted", sizeof(message));
 			break;
 		case MSC_TOKEN_UNRESPONSIVE:
-			strncpy(message, "Token is unresponsive", sizeof(message));
+			strlcpy(message, "Token is unresponsive", sizeof(message));
 			break;
 		case MSC_INVALID_HANDLE:
-			strncpy(message, "Handle is invalid", sizeof(message));
+			strlcpy(message, "Handle is invalid", sizeof(message));
 			break;
 		case MSC_SHARING_VIOLATION:
-			strncpy(message, "Sharing violation", sizeof(message));
+			strlcpy(message, "Sharing violation", sizeof(message));
 			break;
 
 		default:
--- /cvsroot/pcsclite/libmusclecard/src/muscletest.c	2004/09/14 06:38:44	1.15
+++ /cvsroot/pcsclite/libmusclecard/src/muscletest.c	2004/10/06 08:11:50	1.16
@@ -6,7 +6,7 @@
  * Copyright (C) 2001
  *  David Corcoran <corcoran@linuxnet.com>
  *
- * $Id: muscletest.c,v 1.15 2004/09/14 06:38:44 rousseau Exp $
+ * $Id: muscletest.c,v 1.16 2004/10/06 08:11:50 rousseau Exp $
  */
 
 #include <stdio.h>
@@ -120,7 +120,7 @@
 			printf("token reset ");
 		printf("\n\n");
 
-		if (tokenList[i].tokenState & SCARD_STATE_PRESENT)
+		if (tokenList[i].tokenState & MSC_STATE_PRESENT)
 			reader_to_use = i;
 	}
 
@@ -245,10 +245,10 @@
 	rv = MSCGetStatus(&pConnection, &statusInf);
 	printf("Currently logged identities : %04X\n", statusInf.loggedID);
 
-	rv = MSCEndTransaction(&pConnection, SCARD_LEAVE_CARD);
+	rv = MSCEndTransaction(&pConnection, MSC_LEAVE_TOKEN);
 	printf("EndTransaction returns      : %s\n", msc_error(rv));
 
-	MSCReleaseConnection(&pConnection, SCARD_LEAVE_CARD);
+	MSCReleaseConnection(&pConnection, MSC_LEAVE_TOKEN);
 	printf("ReleaseConn returns         : %s\n", msc_error(rv));
 
 	return 0;