[Pcsclite-cvs-commit] r3287 - in /trunk/PCSC/src: utils.c utils.h
rousseau at users.alioth.debian.org
rousseau at users.alioth.debian.org
Tue Jan 20 15:16:55 UTC 2009
Author: rousseau
Date: Tue Jan 20 15:16:55 2009
New Revision: 3287
URL: http://svn.debian.org/wsvn/pcsclite/?sc=1&rev=3287
Log:
add StatSynchronizeContext() to send an asynchronous event to a specific
context
This function can be used from libpcsclite. Using StatSynchronize() does
not work since the directory pcscd.events/ is not readable by group and
other for security reasons
Modified:
trunk/PCSC/src/utils.c
trunk/PCSC/src/utils.h
Modified: trunk/PCSC/src/utils.c
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/utils.c?rev=3287&op=diff
==============================================================================
--- trunk/PCSC/src/utils.c (original)
+++ trunk/PCSC/src/utils.c Tue Jan 20 15:16:55 2009
@@ -152,6 +152,45 @@
/**
+ * Sends an asynchronous event to any waiting client
+ *
+ * Just write 1 byte to any fifo in PCSCLITE_EVENTS_DIR and remove the file
+ *
+ * This function must be secured since the files are created by the library
+ * or any non privileged process. We must not follow symlinks for example
+ */
+int StatSynchronizeContext(SCARDCONTEXT hContext)
+{
+ char filename[FILENAME_MAX];
+ int fd;
+ char buf[] = { '\0' };
+ struct stat fstat_buf;
+
+ (void)snprintf(filename, sizeof(filename), "%s/event.%d.%ld",
+ PCSCLITE_EVENTS_DIR, SYS_GetPID(), hContext);
+ (void)mkfifo(filename, 0644);
+ fd = SYS_OpenFile(filename, O_WRONLY, 0);
+
+ if (fstat(fd, &fstat_buf))
+ {
+ Log3(PCSC_LOG_ERROR, "Can't fstat %s: %s", filename, strerror(errno));
+ }
+ else
+ {
+ /* check that the file is a FIFO */
+ if (!(fstat_buf.st_mode & S_IFIFO))
+ Log2(PCSC_LOG_ERROR, "%s is not a fifo", filename);
+ else
+ (void)SYS_WriteFile(fd, buf, sizeof(buf));
+ }
+
+ (void)SYS_CloseFile(fd);
+
+ return 0;
+} /* StatSynchronize */
+
+
+/**
* Check is OpenCT is running and display a critical message if it is
*
* The first cause of pcsc-lite failure is that OpenCT is installed and running
Modified: trunk/PCSC/src/utils.h
URL: http://svn.debian.org/wsvn/pcsclite/trunk/PCSC/src/utils.h?rev=3287&op=diff
==============================================================================
--- trunk/PCSC/src/utils.h (original)
+++ trunk/PCSC/src/utils.h Tue Jan 20 15:16:55 2009
@@ -22,6 +22,7 @@
LONG SCardCheckDaemonAvailability(void);
int StatSynchronize(/*@null@*/ struct pubReaderStatesList *readerState);
+int StatSynchronizeContext(SCARDCONTEXT hContext);
int CheckForOpenCT(void);
More information about the Pcsclite-cvs-commit
mailing list