/** * Sets up callbacks for device hotplug events. */ ULONG HPRegisterForHotplugEvents(void) { struct udev *udev; (void)pthread_mutex_init(&usbNotifierMutex, NULL); if (driverSize <= 0) { Log1(PCSC_LOG_INFO, "No bundle files in pcsc drivers directory: " PCSCLITE_HP_DROPDIR); Log1(PCSC_LOG_INFO, "Disabling USB support for pcscd"); return 0; } /* Create the udev object */ udev = udev_new(); if (!udev) { Log1(PCSC_LOG_ERROR, "udev_new() failed"); return 0; } HPRescanUsbBus(udev); (void)ThreadCreate(&usbNotifyThread, THREAD_ATTR_DETACHED, (PCSCLITE_THREAD_FUNCTION( )) HPEstablishUSBNotifications, udev); return 0; } /* HPRegisterForHotplugEvents */
static LONG MSGCheckHandleAssociation(SCARDHANDLE hCard, SCONTEXT * threadContext) { int list_index = 0; if (0 == threadContext->hContext) { /* the handle is no more valid. After SCardReleaseContext() for * example */ Log1(PCSC_LOG_CRITICAL, "Invalidated handle"); return -1; } (void)pthread_mutex_lock(&threadContext->cardsList_lock); list_index = list_locate(&threadContext->cardsList, &hCard); (void)pthread_mutex_unlock(&threadContext->cardsList_lock); if (list_index >= 0) return 0; /* Must be a rogue client, debug log and sleep a couple of seconds */ Log1(PCSC_LOG_ERROR, "Client failed to authenticate"); (void)SYS_Sleep(2); return -1; }
RESPONSECODE IFDHPowerICC (DWORD Lun, DWORD Action, PUCHAR Atr, PDWORD AtrLength) { switch (Action) { case IFD_POWER_DOWN: if (vicc_poweroff() < 0) { Log1(PCSC_LOG_ERROR, "could not powerdown"); return IFD_COMMUNICATION_ERROR; } /* XXX see bug #312754 on https://alioth.debian.org/projects/pcsclite */ #if 0 *AtrLength = 0; #endif return IFD_SUCCESS; case IFD_POWER_UP: if (vicc_poweron() < 0) { Log1(PCSC_LOG_ERROR, "could not powerup"); return IFD_COMMUNICATION_ERROR; } break; case IFD_RESET: if (vicc_reset() < 0) { Log1(PCSC_LOG_ERROR, "could not reset"); return IFD_COMMUNICATION_ERROR; } break; default: Log2(PCSC_LOG_ERROR, "%0lX not supported", Action); return IFD_NOT_SUPPORTED; } return IFDHGetCapabilities (Lun, TAG_IFD_ATR, AtrLength, Atr); }
static int latch_overlay_get_account_id(latch_overlay_config_data *cfg, char *id, char **account_id) { int search_scope = LDAP_SCOPE_BASE; char *search_base_dn = NULL; char *search_filter = NULL; int rv = ERROR; Log1(LDAP_DEBUG_TRACE, LDAP_LEVEL_DEBUG, ">>> %s\n", __func__); search_base_dn = replace_str(cfg->ldap_search_base_dn, "@@@USER@@@", id); search_filter = replace_str(cfg->ldap_search_filter, "@@@USER@@@", id); if (cfg->ldap_search_scope != NULL) { if (strcmp("onelevel", cfg->ldap_search_scope) == 0) { search_scope = LDAP_SCOPE_ONELEVEL; } else if (strcmp("subtree", cfg->ldap_search_scope) == 0) { search_scope = LDAP_SCOPE_SUBTREE; } } rv = latch_overlay_get_entry_attribute(cfg->ldap_uri, cfg->ldap_bind_dn, cfg->ldap_bind_password, search_base_dn, search_filter, search_scope, cfg->ldap_attribute, cfg->ldap_tls_ca_file, account_id); free(search_base_dn); free(search_filter); Log1(LDAP_DEBUG_TRACE, LDAP_LEVEL_DEBUG, "<<< %s\n", __func__); return rv; }
/** * @brief The Server's Message Queue Listener function. * * An endless loop calls the function \c ProcessEventsServer() to check for * messages sent by clients. * If the message is valid, \c CreateContextThread() is called to serve this * request. */ static void SVCServiceRunLoop(void) { int rsp; LONG rv; uint32_t dwClientID; /* Connection ID used to reference the Client */ while (TRUE) { if (AraKiri) { /* stop the hotpug thread and waits its exit */ #ifdef USE_USB (void)HPStopHotPluggables(); #endif (void)SYS_Sleep(1); /* now stop all the drivers */ RFCleanupReaders(); EHDeinitializeEventStructures(); ContextsDeinitialize(); at_exit(); } switch (rsp = ProcessEventsServer(&dwClientID)) { case 0: Log2(PCSC_LOG_DEBUG, "A new context thread creation is requested: %d", dwClientID); rv = CreateContextThread(&dwClientID); if (rv != SCARD_S_SUCCESS) Log1(PCSC_LOG_ERROR, "Problem during the context thread creation"); break; case 2: /* * timeout in ProcessEventsServer(): do nothing * this is used to catch the Ctrl-C signal at some time when * nothing else happens */ break; case -1: Log1(PCSC_LOG_ERROR, "Error in ProcessEventsServer"); break; case -2: /* Nothing to do in case of a syscall interrupted * It happens when SIGUSR1 (reload) or SIGINT (Ctrl-C) is received * We just try again */ break; default: Log2(PCSC_LOG_ERROR, "ProcessEventsServer unknown retval: %d", rsp); break; } } }
LONG EHDestroyEventHandler(PREADER_CONTEXT rContext) { if (NULL == rContext->readerState) { Log1(PCSC_LOG_ERROR, "Thread never started (reader init failed?)"); return SCARD_S_SUCCESS; } PCSCD::SharedReaderState *rs = PCSCD::SharedReaderState::overlay(rContext->readerState); if ((rContext->pthThread == 0) || !rs || (rs->readerNameLength() == 0)) { Log1(PCSC_LOG_INFO, "Thread already stomped."); return SCARD_S_SUCCESS; } secdebug("pcscd", "EHDestroyEventHandler: pthThread: %p, reader name len: %ld", rContext->pthThread, rs->readerNameLength()); /* * Zero out the public status struct to allow it to be recycled and * used again */ rs->xreaderNameClear(); rs->xcardAtrClear(); rs->xreaderID(0); rs->xreaderState(0); rs->xlockState(0); rs->sharing(0); rs->xcardAtrLength(0); rs->xcardProtocol(SCARD_PROTOCOL_UNSET); // we only set this one to write to memory cache /* * Set the thread to 0 to exit thread */ ReaderContextLock(rContext); Log1(PCSC_LOG_INFO, "Stomping thread."); int ix; for (ix = 0; (ix < 100) && ReaderContextIsLocked(rContext); ++ix) { /* * Wait 0.05 seconds for the child to respond */ SYS_USleep(50000); } secdebug("pcscd", "EHDestroyEventHandler: post-stop dwLockId: %d", rContext->dwLockId); /* Zero the thread */ rContext->pthThread = 0; Log1(PCSC_LOG_INFO, "Thread stomped."); return SCARD_S_SUCCESS; }
static void HPEstablishUSBNotifications(void) { int i, do_polling; /* libusb default is /dev/bus/usb but the devices are not yet visible there * when a hotplug is requested */ setenv("USB_DEVFS_PATH", "/proc/bus/usb", 0); usb_init(); /* scan the USB bus for devices at startup */ HPRescanUsbBus(); /* if at least one driver do not have IFD_GENERATE_HOTPLUG */ do_polling = FALSE; for (i=0; i<driverSize; i++) if (driverTracker[i].libraryPath) if ((driverTracker[i].ifdCapabilities & IFD_GENERATE_HOTPLUG) == 0) { Log2(PCSC_LOG_INFO, "Driver %s does not support IFD_GENERATE_HOTPLUG. Using active polling instead.", driverTracker[i].bundleName); if (HPForceReaderPolling < 1) HPForceReaderPolling = 1; break; } if (HPForceReaderPolling) { Log2(PCSC_LOG_INFO, "Polling forced every %d second(s)", HPForceReaderPolling); do_polling = TRUE; } if (do_polling) { while (!AraKiriHotPlug) { SYS_Sleep(HPForceReaderPolling); HPRescanUsbBus(); } } else { char dummy; pipe(rescan_pipe); while (read(rescan_pipe[0], &dummy, sizeof(dummy)) > 0) { Log1(PCSC_LOG_INFO, "Reload serial configuration"); HPRescanUsbBus(); RFReCheckReaderConf(); Log1(PCSC_LOG_INFO, "End reload serial configuration"); } close(rescan_pipe[0]); rescan_pipe[0] = -1; } }
void StatusBar::draw_marks(Buffer::iterator& cursor) { Log1("Redrawing status bar"); std::vector<std::shared_ptr<Mark>> before_cursor(Brush::MarkColorsTotal); std::vector<std::shared_ptr<Mark>> after_cursor(Brush::MarkColorsTotal); // Initialize before_cursor and after_cursor to 0s. for (int i = 0; i < Brush::MarkColorsTotal; i++) { before_cursor[i] = 0; after_cursor[i] = 0; } Mark c(cursor); for (Mark m : _marks) { Log1("Looking at mark " << m); Log3("Comparing with cursor " << c); if (m < c) { Log2("Mark " << m << " is less then cursor. Setting for color " << m.get_color_index()); before_cursor[m.get_color_index()].reset(new Mark(m)); } else if (m == c) { Log2("Mark " << m << " is equal to cursor."); } else { Log2("Mark " << m << " is greater then cursor. Setting for color " << m.get_color_index()); after_cursor[m.get_color_index()].reset(new Mark(m)); } } for (int i = 0, x = 2; i < Brush::MarkColorsTotal; i++) { std::stringstream ss; if (before_cursor[i] != 0) { s64 n = before_cursor[i]->get_iterator().distance_lines(cursor); Log3("Drawing " << n << " lines before cursor, from " << *before_cursor[i] << " until " << cursor); ss << std::setfill(' ') << std::setw(4) << n; } else { ss << "----"; } ss << "|"; if (after_cursor[i] != 0) { s64 n = after_cursor[i]->get_iterator().distance_lines(cursor); Log3("Drawing " << n << " lines after cursor, from " << *after_cursor[i] << " until " << cursor); ss << std::setfill(' ') << std::setw(4) << std::left << n; } else { ss << "----"; } Log3("Marks line: " << ss.str()); Line l(ss.str()); _brush.draw_text(x, _text_height + 1, l, _brush.marks[i]); x += l.length() + 1; } }
/*@null@*/ static struct _driverTracker *get_driver(struct udev_device *dev, const char *devpath, struct _driverTracker **classdriver) { int i; unsigned int idVendor, idProduct; static struct _driverTracker *driver; const char *str; str = udev_device_get_sysattr_value(dev, "idVendor"); if (!str) { Log1(PCSC_LOG_ERROR, "udev_device_get_sysattr_value() failed"); return NULL; } sscanf(str, "%X", &idVendor); str = udev_device_get_sysattr_value(dev, "idProduct"); if (!str) { Log1(PCSC_LOG_ERROR, "udev_device_get_sysattr_value() failed"); return NULL; } sscanf(str, "%X", &idProduct); Log4(PCSC_LOG_DEBUG, "Looking for a driver for VID: 0x%04X, PID: 0x%04X, path: %s", idVendor, idProduct, devpath); *classdriver = NULL; driver = NULL; /* check if the device is supported by one driver */ for (i=0; i<driverSize; i++) { if (driverTracker[i].libraryPath != NULL && idVendor == driverTracker[i].manuID && idProduct == driverTracker[i].productID) { if ((driverTracker[i].CFBundleName != NULL) && (0 == strcmp(driverTracker[i].CFBundleName, "CCIDCLASSDRIVER"))) *classdriver = &driverTracker[i]; else /* it is not a CCID Class driver */ driver = &driverTracker[i]; } } /* if we found a specific driver */ if (driver) return driver; /* else return the Class driver (if any) */ return *classdriver; }
eFlag Tree::parse(Sit S, DataLine *d) { Log1(S, L1_PARSING, getURI()); double time_was = getMillisecs(); TreeConstructer tc(S); eFlag retval = tc.parseDataLineUsingExpat(S, this, d); if (!retval) { Log1(S, L1_PARSE_DONE, getMillisecsDiff(time_was)); } return retval; }
RESPONSECODE IFDHPowerICC (DWORD Lun, DWORD Action, PUCHAR Atr, PDWORD AtrLength) { size_t slot = Lun & 0xffff; RESPONSECODE r = IFD_COMMUNICATION_ERROR; if (slot >= vicc_max_slots) { goto err; } switch (Action) { case IFD_POWER_DOWN: if (vicc_poweroff(ctx[slot]) < 0) { Log1(PCSC_LOG_ERROR, "could not powerdown"); goto err; } /* XXX see bug #312754 on https://alioth.debian.org/projects/pcsclite */ #if 0 *AtrLength = 0; #endif return IFD_SUCCESS; case IFD_POWER_UP: if (vicc_poweron(ctx[slot]) < 0) { Log1(PCSC_LOG_ERROR, "could not powerup"); goto err; } break; case IFD_RESET: if (vicc_reset(ctx[slot]) < 0) { Log1(PCSC_LOG_ERROR, "could not reset"); goto err; } break; default: Log2(PCSC_LOG_ERROR, "%0lX not supported", Action); r = IFD_NOT_SUPPORTED; goto err; } r = IFD_SUCCESS; err: if (r != IFD_SUCCESS && AtrLength) *AtrLength = 0; else r = IFDHGetCapabilities (Lun, TAG_IFD_ATR, AtrLength, Atr); return r; }
RESPONSECODE IFDHGetCapabilities (DWORD Lun, DWORD Tag, PDWORD Length, PUCHAR Value) { unsigned char *atr = NULL; ssize_t size; if (!Length || !Value) return IFD_COMMUNICATION_ERROR; switch (Tag) { case TAG_IFD_ATR: size = vicc_getatr(&atr); if (size < 0) { Log1(PCSC_LOG_ERROR, "could not get ATR"); return IFD_COMMUNICATION_ERROR; } if (size == 0) { Log1(PCSC_LOG_ERROR, "Virtual ICC removed"); return IFD_ICC_NOT_PRESENT; } Log2(PCSC_LOG_DEBUG, "Got ATR (%d bytes)", size); if (*Length < size) { free(atr); Log1(PCSC_LOG_ERROR, "Not enough memory for ATR"); return IFD_COMMUNICATION_ERROR; } memcpy(Value, atr, size); *Length = size; free(atr); break; case TAG_IFD_SLOTS_NUMBER: if (*Length < 1) { Log1(PCSC_LOG_ERROR, "Invalid input data"); return IFD_COMMUNICATION_ERROR; } *Value = 1; *Length = 1; break; default: Log2(PCSC_LOG_DEBUG, "unknown tag %d", (int)Tag); return IFD_ERROR_TAG; } return IFD_SUCCESS; }
static int RollDice( int count, int sides ) { int accum; int n; accum = 0; while( count-- ) { n = RAND(sides) + 1; Log1( WIDE("Rolled %d..."), n ); accum += n; } Log1( WIDE("Total: %d..."), accum ); return accum; }
/* wrap data, transmit to the device and get answer */ RESPONSECODE sendData(PUCHAR TxBuffer, DWORD TxLength, PUCHAR RxBuffer, PDWORD RxLength, int wait) { RESPONSECODE rc; if (present == 0) { return IFD_COMMUNICATION_ERROR; } unsigned char apdu[TxLength]; unsigned char buffer[2000]; unsigned int i, j, response_length, n = 0; int sLen = TxLength; for (i = 0; i < TxLength; ++i) { apdu[i] = *(TxBuffer + i); } Log2(PCSC_LOG_DEBUG, "preparing to write %d data bytes", TxLength); printf(">> %s \n", hexdump(TxBuffer, TxLength)); int rv; rv = rfid_protocol_transceive(ph, TxBuffer, TxLength, RxBuffer, &response_length, 0, 0); if (rv < 0) { Log2(PCSC_LOG_ERROR, "Error from transceive, returned %d\n", rv); present = 0; rfid_protocol_close(ph); rfid_layer2_close(l2h); rfid_reader_close(rh); return IFD_COMMUNICATION_ERROR; } Log2(PCSC_LOG_DEBUG, "wrote %d data bytes", TxLength); Log2(PCSC_LOG_DEBUG, "got %d response bytes", response_length); if (response_length > 0) { *RxLength = response_length; //for (j = 0; j < response_length; ++j) //{ // *(RxBuffer + j) = buffer[j]; //} rc = IFD_SUCCESS; } else { Log1(PCSC_LOG_ERROR, "no response, meaning eof, reader not usable anymore\n"); present = 0; rfid_protocol_close(ph); rfid_layer2_close(l2h); rfid_reader_close(rh); rc = IFD_COMMUNICATION_ERROR; } return rc; }
RESPONSECODE IFDHSetProtocolParameters ( DWORD Lun, DWORD Protocol, UCHAR Flags, UCHAR PTS1, UCHAR PTS2, UCHAR PTS3) { /* This function should set the PTS of a particular card/slot using the three PTS parameters sent Protocol - 0 .... 14 T=0 .... T=14 Flags - Logical OR of possible values: IFD_NEGOTIATE_PTS1 IFD_NEGOTIATE_PTS2 IFD_NEGOTIATE_PTS3 to determine which PTS values to negotiate. PTS1,PTS2,PTS3 - PTS Values. returns: IFD_SUCCESS IFD_ERROR_PTS_FAILURE IFD_COMMUNICATION_ERROR IFD_PROTOCOL_NOT_SUPPORTED */ Log1(PCSC_LOG_DEBUG, "IFDHSetProtocolParameters"); if (Protocol != SCARD_PROTOCOL_T0 && Protocol != SCARD_PROTOCOL_T1) { return IFD_PROTOCOL_NOT_SUPPORTED; } return IFD_SUCCESS; }
/* * Map a range of virtual memory. Note that the size asked for here * is literally what the upper level has asked for. We need to do * any rounding, etc. here. If mapping fails return 0, otherwise * return the address of the base of the mapped memory. */ void * sysMapMem(size_t requestedSize, size_t *mappedSize) { void *mappedAddr; *mappedSize = roundUpToGrain(requestedSize); #ifdef USE_MALLOC mappedAddr = (void *) sysMalloc(*mappedSize); /* Returns 0 on failure */ #ifdef __linux__ if (mappedAddr) { memset(mappedAddr, 0, *mappedSize); mappedAddr = (void *) roundUpToGrain(mappedAddr); } #endif #else mappedAddr = mapChunk(*mappedSize); /* Returns 0 on failure */ #endif /* USE_MALLOC */ if (mappedAddr) { Log3(2, "sysMapMem: 0x%x bytes at 0x%x (request: 0x%x bytes)\n", *mappedSize, mappedAddr, requestedSize); } else { Log1(2, "sysMapMem failed: (request: 0x%x bytes)\n", requestedSize); } return mappedAddr; }
CORE_PROC(int, RelayInput)( PDATAPATH pdp , PTEXT (CPROC *Datacallback)( PDATAPATH pdp, PTEXT pLine ) ) { extern int gbTrace; if( pdp->pPrior ) { PTEXT p; int moved = 0; if( gbTrace ) xlprintf(LOG_NOISE+1)( WIDE("Relay input from %s to %s..........") , GetText( pdp->pPrior->pName ) , GetText( pdp->pName ) ); do { if( pdp->pPrior->Read ) { pdp->pPrior->Read( pdp->pPrior ); } if( IsQueueEmpty( &pdp->pPrior->Input ) ) break; //Log( WIDE("Has some input to handle...") ); while( ( p = (PTEXT)DequeLink( &pdp->pPrior->Input ) ) ) { if( gbTrace ) lprintf( WIDE("Data is: %s"), GetText( p ) ); if( Datacallback && !( ( p->flags & TF_RELAY ) == TF_RELAY ) ) { //lprintf( WIDE("Data callback...") ); for( p = Datacallback( pdp, p ); p; p = Datacallback( pdp, NULL ) ) { moved++; if( p != (POINTER)1 ) EnqueLink( &pdp->Input, p ); else lprintf( WIDE("Data was consumed by datapath.") ); } } else { PTEXT out = BuildLine( p ); Log1( WIDE("Relay In: %s"), GetText( out ) ); LineRelease( out ); moved++; EnqueLink( &pdp->Input, p ); } } if( gbTrace && !moved && !pdp->pPrior->flags.Closed ) { lprintf( WIDE("Did not result in data, try reading source again, rerelay. %s %s"), GetText( pdp->pName ), GetText( pdp->pPrior->pName ) ); } } while( !moved && !pdp->pPrior->flags.Closed ); // stop relaying closes at datasource points //if( !pdp->pPrior->flags.Data_Source ) pdp->flags.Closed |= pdp->pPrior->flags.Closed; return moved; } return 0; }
static int vernum_db_init( BackendDB *be, ConfigReply *cr) { slap_overinst *on = (slap_overinst *) be->bd_info; vernum_t *vn = NULL; if ( SLAP_ISGLOBALOVERLAY( be ) ) { Log0( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "vernum_db_init: vernum cannot be used as global overlay.\n" ); return 1; } if ( be->be_nsuffix == NULL ) { Log0( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "vernum_db_init: database must have suffix\n" ); return 1; } if ( BER_BVISNULL( &be->be_rootndn ) || BER_BVISEMPTY( &be->be_rootndn ) ) { Log1( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "vernum_db_init: missing rootdn for database DN=\"%s\", YMMV\n", be->be_suffix[ 0 ].bv_val ); } vn = (vernum_t *)ch_calloc( 1, sizeof( vernum_t ) ); on->on_bi.bi_private = (void *)vn; return 0; }
static int vernum_db_open( BackendDB *be, ConfigReply *cr ) { slap_overinst *on = (slap_overinst *)be->bd_info; vernum_t *vn = (vernum_t *)on->on_bi.bi_private; if ( SLAP_SINGLE_SHADOW( be ) ) { Log1( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "vernum incompatible with shadow database \"%s\".\n", be->be_suffix[ 0 ].bv_val ); return 1; } /* default: unicodePwd & msDS-KeyVersionNumber */ if ( vn->vn_attr == NULL ) { const char *text = NULL; int rc; rc = slap_str2ad( "unicodePwd", &vn->vn_attr, &text ); if ( rc != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_ANY, "vernum: unable to find attribute 'unicodePwd' (%d: %s)\n", rc, text, 0 ); return 1; } vn->vn_vernum = ad_msDS_KeyVersionNumber; } return vernum_repair( be ); }
int SrvrMergeSelectedWalls( uint32_t client_id, INDEX iWorld, INDEX iDefinite, PORTHOAREA rect ) { GETWORLD(iWorld ); //PWALL pDefinite = GetWall( iDefinite ); WALLSELECTINFO si; // normal 1 si.r.n[0] = rect->w; si.r.n[1] = rect->h; si.r.n[2] = 0; si.r.o[0] = rect->x; si.r.o[1] = rect->y; si.r.o[2] = 0; si.iWorld = iWorld; si.nwalls = 0; if( !ForAllWalls( world->walls, CheckWallSelect, &si ) ) { Log1( "Found %d walls to merge: %d", si.nwalls ); if( si.nwalls == 2 && ( GetWall( si.walls[0] )->iSector != GetWall( si.walls[1] )->iSector ) ) { SrvrMergeWalls( client_id, iWorld, si.walls[0], si.walls[1] ); } if( si.nwalls == 1 && iDefinite != INVALID_INDEX && si.walls[0] != iDefinite ) { SrvrMergeWalls( client_id, iWorld, iDefinite, si.walls[0] ); } return TRUE; } return FALSE; }
static int pguid_db_init( BackendDB *be, ConfigReply *cr) { if ( SLAP_ISGLOBALOVERLAY( be ) ) { Log0( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "pguid_db_init: pguid cannot be used as global overlay.\n" ); return 1; } if ( be->be_nsuffix == NULL ) { Log0( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "pguid_db_init: database must have suffix\n" ); return 1; } if ( BER_BVISNULL( &be->be_rootndn ) || BER_BVISEMPTY( &be->be_rootndn ) ) { Log1( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "pguid_db_init: missing rootdn for database DN=\"%s\", YMMV\n", be->be_suffix[ 0 ].bv_val ); } return 0; }
int relay_back_db_open( Backend *be, ConfigReply *cr ) { relay_back_info *ri = (relay_back_info *)be->be_private; assert( ri != NULL ); if ( !BER_BVISNULL( &ri->ri_realsuffix ) ) { ri->ri_bd = select_backend( &ri->ri_realsuffix, 1 ); /* must be there: it was during config! */ if ( ri->ri_bd == NULL ) { snprintf( cr->msg, sizeof( cr->msg), "cannot find database " "of relay dn \"%s\" " "in \"olcRelay <dn>\"\n", ri->ri_realsuffix.bv_val ); Log1( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "relay_back_db_open: %s.\n", cr->msg ); return 1; } /* inherit controls */ AC_MEMCPY( be->bd_self->be_ctrls, ri->ri_bd->be_ctrls, sizeof( be->be_ctrls ) ); } else { /* inherit all? */ AC_MEMCPY( be->bd_self->be_ctrls, frontendDB->be_ctrls, sizeof( be->be_ctrls ) ); } return 0; }
static void signal_trap(int sig) { Log2(PCSC_LOG_INFO, "Received signal: %d", sig); /* do not wait if asked to terminate * avoids waiting after the reader(s) in shutdown for example */ if (SIGTERM == sig) { Log1(PCSC_LOG_INFO, "Direct suicide"); at_exit(); } if (SIGALRM == sig) { /* normal exit without error */ ExitValue = EXIT_SUCCESS; } /* the signal handler is called several times for the same Ctrl-C */ if (AraKiri == FALSE) { Log1(PCSC_LOG_INFO, "Preparing for suicide"); AraKiri = TRUE; /* if still in the init/loading phase the AraKiri will not be * seen by the main event loop */ if (Init) { Log1(PCSC_LOG_INFO, "Suicide during init"); at_exit(); } } else { /* if pcscd do not want to die */ static int lives = 2; lives--; /* no live left. Something is blocking the normal death. */ if (0 == lives) { Log1(PCSC_LOG_INFO, "Forced suicide"); at_exit(); } } }
RESPONSECODE IFDHTransmitToICC (DWORD Lun, SCARD_IO_HEADER SendPci, PUCHAR TxBuffer, DWORD TxLength, PUCHAR RxBuffer, PDWORD RxLength, PSCARD_IO_HEADER RecvPci) { unsigned char *rapdu = NULL; ssize_t size; RESPONSECODE r = IFD_COMMUNICATION_ERROR; size_t slot = Lun & 0xffff; if (slot >= vicc_max_slots) { goto err; } if (!RxLength || !RecvPci) { Log1(PCSC_LOG_ERROR, "Invalid input data"); goto err; } size = vicc_transmit(ctx[slot], TxLength, TxBuffer, &rapdu); if (size < 0) { Log1(PCSC_LOG_ERROR, "could not send apdu or receive rapdu"); goto err; } if (*RxLength < size) { Log1(PCSC_LOG_ERROR, "Not enough memory for rapdu"); goto err; } *RxLength = size; memcpy(RxBuffer, rapdu, size); RecvPci->Protocol = 1; r = IFD_SUCCESS; err: if (r != IFD_SUCCESS && RxLength) *RxLength = 0; free(rapdu); return r; }
static int dds_db_open( BackendDB *be, ConfigReply *cr ) { slap_overinst *on = (slap_overinst *)be->bd_info; dds_info_t *di = on->on_bi.bi_private; int rc = 0; void *thrctx = ldap_pvt_thread_pool_context(); if ( slapMode & SLAP_TOOL_MODE ) return 0; if ( DDS_OFF( di ) ) { goto done; } if ( SLAP_SINGLE_SHADOW( be ) ) { Log1( LDAP_DEBUG_ANY, LDAP_LEVEL_ERR, "DDS incompatible with shadow database \"%s\".\n", be->be_suffix[ 0 ].bv_val ); return 1; } if ( di->di_max_ttl == 0 ) { di->di_max_ttl = DDS_RF2589_DEFAULT_TTL; } if ( di->di_min_ttl == 0 ) { di->di_max_ttl = DDS_RF2589_DEFAULT_TTL; } di->di_suffix = be->be_suffix; di->di_nsuffix = be->be_nsuffix; /* count the dynamic objects first */ rc = dds_count( thrctx, be ); if ( rc != LDAP_SUCCESS ) { rc = 1; goto done; } /* start expire task */ ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex ); di->di_expire_task = ldap_pvt_runqueue_insert( &slapd_rq, DDS_INTERVAL( di ), dds_expire_fn, di, "dds_expire_fn", be->be_suffix[ 0 ].bv_val ); ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex ); /* register dinamicSubtrees root DSE info support */ rc = entry_info_register( dds_entry_info, (void *)di ); done:; return rc; }
void signal_trap(int sig) { /* the signal handler is called several times for the same Ctrl-C */ if (AraKiri == 0) { Log1(PCSC_LOG_INFO, "Preparing for suicide"); AraKiri = 1; /* if still in the init/loading phase the AraKiri will not be * seen by the main event loop */ if (Init) { Log1(PCSC_LOG_INFO, "Suicide during init"); at_exit(); } } }
RESPONSECODE IFDHPowerICC ( DWORD Lun, DWORD Action, PUCHAR Atr, PDWORD AtrLength ) { /* This function controls the power and reset signals of the smartcard reader at the particular reader/slot specified by Lun. Action - Action to be taken on the card. IFD_POWER_UP - Power and reset the card if not done so (store the ATR and return it and it's length). IFD_POWER_DOWN - Power down the card if not done already (Atr/AtrLength should be zero'd) IFD_RESET - Perform a quick reset on the card. If the card is not powered power up the card. (Store and return the Atr/Length) Atr - Answer to Reset of the card. The driver is responsible for caching this value in case IFDHGetCapabilities is called requesting the ATR and it's length. This should not exceed MAX_ATR_SIZE. AtrLength - Length of the Atr. This should not exceed MAX_ATR_SIZE. Notes: Memory cards without an ATR should return IFD_SUCCESS on reset but the Atr should be zero'd and the length should be zero Reset errors should return zero for the AtrLength and return IFD_ERROR_POWER_ACTION. returns: IFD_SUCCESS IFD_ERROR_POWER_ACTION IFD_COMMUNICATION_ERROR IFD_NOT_SUPPORTED */ Log1(PCSC_LOG_DEBUG, "IFDHPowerICC"); RESPONSECODE rv; switch (Action) { case IFD_RESET: case IFD_POWER_UP: readUID(AtrLength, Atr); rv = IFD_SUCCESS; break; default: *AtrLength = 0; Atr = 0; rv = IFD_NOT_SUPPORTED; break; } return rv; }
/* * / Load a module (if needed) */ int DYN_LoadLibrary(void **pvLHandle, char *pcLibrary) { CFStringRef bundlePath; CFURLRef bundleURL; CFBundleRef bundle; *pvLHandle = 0; /* * @@@ kCFStringEncodingMacRoman might be wrong on non US systems. */ bundlePath = CFStringCreateWithCString(NULL, pcLibrary, kCFStringEncodingMacRoman); if (bundlePath == NULL) return SCARD_E_NO_MEMORY; bundleURL = CFURLCreateWithFileSystemPath(NULL, bundlePath, kCFURLPOSIXPathStyle, TRUE); CFRelease(bundlePath); if (bundleURL == NULL) return SCARD_E_NO_MEMORY; bundle = CFBundleCreate(NULL, bundleURL); CFRelease(bundleURL); if (bundle == NULL) { Log1(PCSC_LOG_ERROR, "CFBundleCreate"); return SCARD_F_UNKNOWN_ERROR; } if (!CFBundleLoadExecutable(bundle)) { Log1(PCSC_LOG_ERROR, "CFBundleLoadExecutable"); CFRelease(bundle); return SCARD_F_UNKNOWN_ERROR; } *pvLHandle = (void *) bundle; return SCARD_S_SUCCESS; }
RESPONSECODE IFDHCloseChannel (DWORD Lun) { RESPONSECODE r = vicc_eject(); if (vicc_exit() < 0) { Log1(PCSC_LOG_ERROR, "Could not close connection to virtual ICC"); return IFD_COMMUNICATION_ERROR; } return r; }
/** * @brief Acquires a socket passed in from systemd. * * This is called by the server to start listening on an existing socket for * local IPC with the clients. * * @param fd The file descriptor to start listening on. * * @return Error code. * @retval 0 Success * @retval -1 Passed FD is not an UNIX socket. */ INTERNAL int32_t ListenExistingSocket(int fd) { if (!sd_is_socket(fd, AF_UNIX, SOCK_STREAM, -1)) { Log1(PCSC_LOG_CRITICAL, "Passed FD is not an UNIX socket"); return -1; } commonSocket = fd; return 0; }