int main(int argc,char **argv) { /* File data */ unsigned char * file_data; #ifdef POCKETBEE /* Register the handler for SIGTERM */ signal (SIGTERM, sig_handler); /* Register exit function */ atexit (proper_exit); #endif /* POCKETBEE */ /* Make a 'toolbar' app */ pgInit(argc,argv); wApp = pgRegisterApp(PG_APP_TOOLBAR,"Keyboard",0); wCanvas = pgNewWidget(PG_WIDGET_CANVAS, PG_DERIVE_INSIDE, wApp); pgSetWidget (PGDEFAULT, PG_WP_SIDE, PG_S_ALL, 0); wDisabled = pgNewWidget (PG_WIDGET_CANVAS, PG_DERIVE_AFTER, wCanvas); pgSetWidget (PGDEFAULT, PG_WP_SIDE, PG_S_ALL, 0); drawDisabledKeyboard (); if (!argv[1] || argv[2]) { printf("usage:\n %s <keyboard file>\n",argv[0]); return 1; } /* Load patterns */ fpat = fopen(argv[1],"r"); if (!fpat) { pgMessageDialog(*argv,"Error loading keyboard file",0); return 1; } file_data = kb_validate (fpat, &mpat); fclose (fpat); if (file_data == NULL) { pgMessageDialog(*argv,"Invalid keyboard file [kb_validate()]",0); return 1; } if (kb_loadpatterns(file_data)) { free (file_data); pgMessageDialog(*argv,"Invalid keyboard file [kb_loadpatterns()]",0); return 1; } free (file_data); /* Resize app widget */ pgSetWidget(wApp, PG_WP_NAME,pgNewString(PG_KEYBOARD_APPNAME), PG_WP_SIDE,mpat->app_side, #ifdef POCKETBEE /* Start the keyboard hidden */ PG_WP_SIZE,0, #else /* POCKETBEE */ PG_WP_SIZE,mpat->app_size, #endif /* POCKETBEE */ PG_WP_SIZEMODE,mpat->app_sizemode, PG_WP_TRANSPARENT,1, 0); #ifdef POCKETBEE # ifdef USE_PM DPRINTF ("about to tell PM we are ready\n"); /* Signal the PM of a proper start */ if (pm_ready () == -1) { DPRINTF ("cannot signal PM (error during pm_ready)\n"); } # endif /* USE_PM */ /* Find the public box in the finder */ { pghandle box; int i = 0; while ( !(box = pgFindWidget ("FinderKbdBox")) && i < 5 ) { DPRINTF ("Finder public box not found, waiting ...\n"); sleep (1); i++; } if (box) { /* Create a button in this box */ pgNewWidget (PG_WIDGET_BUTTON, PG_DERIVE_INSIDE, box); pgSetWidget (PGDEFAULT, PG_WP_TEXT, pgNewString ("Kbd"), 0); /* Attach a handler to it */ pgBind (PGDEFAULT, PG_WE_ACTIVATE, &kbd_btn_handler, NULL); } } #endif /* POCKETBEE */ initKbdCanvas (); /* Set up an event handler for the received messages */ pgBind (wApp, PG_WE_APPMSG, &evtMessage, NULL); pgEventLoop(); return 0; }
JNIEXPORT void JNICALL Java_com_ratusapparatus_passssh_PassSSH_InsertPass(JNIEnv *env, jobject obj, jstring, jstring) { DPRINTF( "%s\n", __FUNCTION__ ); PassSSH *passSSH = ptr<PassSSH>(env, obj); }
static uint64_t stellaris_enet_read(void *opaque, hwaddr offset, unsigned size) { stellaris_enet_state *s = (stellaris_enet_state *)opaque; uint32_t val; switch (offset) { case 0x00: /* RIS */ DPRINTF("IRQ status %02x\n", s->ris); return s->ris; case 0x04: /* IM */ return s->im; case 0x08: /* RCTL */ return s->rctl; case 0x0c: /* TCTL */ return s->tctl; case 0x10: /* DATA */ if (s->rx_fifo_len == 0) { if (s->np == 0) { BADF("RX underflow\n"); return 0; } s->rx_fifo_len = s->rx[s->next_packet].len; s->rx_fifo = s->rx[s->next_packet].data; DPRINTF("RX FIFO start packet len=%d\n", s->rx_fifo_len); } val = s->rx_fifo[0] | (s->rx_fifo[1] << 8) | (s->rx_fifo[2] << 16) | (s->rx_fifo[3] << 24); s->rx_fifo += 4; s->rx_fifo_len -= 4; if (s->rx_fifo_len <= 0) { s->rx_fifo_len = 0; s->next_packet++; if (s->next_packet >= 31) s->next_packet = 0; s->np--; DPRINTF("RX done np=%d\n", s->np); } return val; case 0x14: /* IA0 */ return s->conf.macaddr.a[0] | (s->conf.macaddr.a[1] << 8) | (s->conf.macaddr.a[2] << 16) | (s->conf.macaddr.a[3] << 24); case 0x18: /* IA1 */ return s->conf.macaddr.a[4] | (s->conf.macaddr.a[5] << 8); case 0x1c: /* THR */ return s->thr; case 0x20: /* MCTL */ return s->mctl; case 0x24: /* MDV */ return s->mdv; case 0x28: /* MADD */ return 0; case 0x2c: /* MTXD */ return s->mtxd; case 0x30: /* MRXD */ return s->mrxd; case 0x34: /* NP */ return s->np; case 0x38: /* TR */ return 0; case 0x3c: /* Undocuented: Timestamp? */ return 0; default: hw_error("stellaris_enet_read: Bad offset %x\n", (int)offset); return 0; } }
int main(int argc, char ** v) { MWCOORD x, y, z; int b; int result; int mouse = -1; DPRINTF("Opening touch panel...\n"); if((result=PD_Open(0)) < 0) DPRINTF("Error %d, result %d opening touch-panel\n", errno, result); /* This stuff below can be used to set some of the parameters of the * driver from the command line before going in to the test loop. * Could this have been done better? Yup. */ if(argc > 1) { ioctl(result,1,atoi(v[1])); DPRINTF("Setting pressure to %d\n",atoi(v[1])); } if(argc > 2) { ioctl(result,2,atoi(v[2])); DPRINTF("Setting updelay to %d\n",atoi(v[2])); } if(argc > 3) { ioctl(result,3,atoi(v[3])); DPRINTF("Setting raw x to %d\n",atoi(v[3])); } if(argc > 4) { ioctl(result,4,atoi(v[4])); DPRINTF("Setting raw y to %d\n",atoi(v[4])); } if(argc > 5) { ioctl(result,5,atoi(v[5])); DPRINTF("Setting res x to %d\n",atoi(v[5])); } if(argc > 6) { ioctl(result,6,atoi(v[6])); DPRINTF("Setting res y to %d\n",atoi(v[6])); } if(argc > 7) { ioctl(result,7,atoi(v[7])); DPRINTF("Setting fudge x to %d\n",atoi(v[7])); } if(argc > 8) { ioctl(result,8,atoi(v[8])); DPRINTF("Setting fudge y to %d\n",atoi(v[8])); } if(argc > 9) { ioctl(result,9,atoi(v[9])); DPRINTF("Setting average sample to %d\n",atoi(v[9])); } if(argc > 10) { ioctl(result,10,atoi(v[10])); DPRINTF("Setting raw min x to %d\n",atoi(v[10])); } if(argc > 11) { ioctl(result,11,atoi(v[11])); DPRINTF("Setting raw min y to %d\n",atoi(v[11])); } DPRINTF("Reading touch panel...\n"); while(1) { result = PD_Read(&x, &y, &z, &b); if( result > 0) { if(mouse != b) { mouse = b; if(mouse) DPRINTF("Pen Down\n"); else DPRINTF("Pen Up\n"); } DPRINTF("%d,%d,%d,%d,%d\n", result, x, y, z, b); } } }
//////////////////////////////////////////////////////////////////////////// /////////////// // 函数名: // 编写者: // 参考资料: // 功 能: // 输入参数: // 输出参数: // 备 注: //////////////////////////////////////////////////////////////////////////// /////////////// void Init_EPROM() { BYTE buf,retrycount=3; _SYSINFO tmpsysinfo;//={0,0}; WORD sum; BOOL eepok; extern BYTE Jdispidx; DelayXms(300); Jiulist.idx=0-1; for(buf=0;buf<MAX_JIULST;buf++ )Jiulist.Jvol[buf]=0xffff; return; #ifndef NVRAM_USE_EEP24CXX do { FLASH_Read(&buf,(FLADDR)EEPROM_ID,1); FLASH_Read((BYTE*)&tmpsysinfo,(FLADDR)(EEP_SYS_TBLSTART),EEP_SYS_LENTH) ; sum= CalChkSum((BYTE*)&tmpsysinfo, EEP_SYS_LENTH); if((buf==BOARD_ID_VER)&&(sum==tmpsysinfo.chksum)){eepok=1;break;} DelayXms(300); }while(retrycount--) ; if(eepok) #endif { //read from flash FLASH_Read((BYTE*)&SysInfo,(FLADDR)(EEP_SYS_TBLSTART),EEP_SYS_LENTH) ; FLASH_Read((BYTE*)&Jiulist,(FLADDR)(EEP_JIULST_TBLSTART),EEP_JIULST_LENTH) ; } #ifndef NVRAM_USE_EEP24CXX else { DisplayCont=DISPLAY_ERR0;Display_All(); //显示初始错误 //初始数据 SysInfo.TRANCODE=0x5555; SysInfo.ADJUST=0; SysInfo.VA=(WORD)((DWORD)DEFAULT_NOCOAL_VA*1024/STANDARD_REF_VOLT); //校准 SysInfo.VB=(WORD)((DWORD )DEFAULT_NOCOAL_VB*1024/STANDARD_REF_VOLT); //校准 SysInfo.VC=(WORD)((DWORD)DEFALT_130PPM_VC*1024/STANDARD_REF_VOLT); //130PPM SysInfo.chksum=CalChkSum((BYTE*)&SysInfo, EEP_SYS_LENTH); FLASH_Update((FLADDR)EEP_SYS_TBLSTART,(BYTE*)&SysInfo,EEP_SYS_LENTH); DPRINTF(printf("-----InitEPROM-----...\r\n")) ; FLASH_Update((FLADDR)EEP_JIULST_TBLSTART,(BYTE*)&Jiulist,EEP_JIULST_LENTH); buf= BOARD_ID_VER; FLASH_Update((FLADDR)EEPROM_ID,(BYTE *)&buf,1) ; } #endif //初始化变量 { if(Jiulist.idx>=MAX_JIULST)Jiulist.idx=0-1; Jdispidx=Jiulist.idx; } }
/* We got some data on the BrlAPI socket */ static void baum_chr_read(void *opaque) { BaumDriverState *baum = opaque; brlapi_keyCode_t code; int ret; if (!baum->brlapi) return; while ((ret = brlapi__readKey(baum->brlapi, 0, &code)) == 1) { DPRINTF("got key %"BRLAPI_PRIxKEYCODE"\n", code); /* Emulate */ switch (code & BRLAPI_KEY_TYPE_MASK) { case BRLAPI_KEY_TYPE_CMD: switch (code & BRLAPI_KEY_CMD_BLK_MASK) { case BRLAPI_KEY_CMD_ROUTE: baum_send_key(baum, BAUM_RSP_RoutingKey, (code & BRLAPI_KEY_CMD_ARG_MASK)+1); baum_send_key(baum, BAUM_RSP_RoutingKey, 0); break; case 0: switch (code & BRLAPI_KEY_CMD_ARG_MASK) { case BRLAPI_KEY_CMD_FWINLT: baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2); baum_send_key(baum, BAUM_RSP_TopKeys, 0); break; case BRLAPI_KEY_CMD_FWINRT: baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TR2); baum_send_key(baum, BAUM_RSP_TopKeys, 0); break; case BRLAPI_KEY_CMD_LNUP: baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TR1); baum_send_key(baum, BAUM_RSP_TopKeys, 0); break; case BRLAPI_KEY_CMD_LNDN: baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TR3); baum_send_key(baum, BAUM_RSP_TopKeys, 0); break; case BRLAPI_KEY_CMD_TOP: baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL1|BAUM_TR1); baum_send_key(baum, BAUM_RSP_TopKeys, 0); break; case BRLAPI_KEY_CMD_BOT: baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL3|BAUM_TR3); baum_send_key(baum, BAUM_RSP_TopKeys, 0); break; case BRLAPI_KEY_CMD_TOP_LEFT: baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2|BAUM_TR1); baum_send_key(baum, BAUM_RSP_TopKeys, 0); break; case BRLAPI_KEY_CMD_BOT_LEFT: baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2|BAUM_TR3); baum_send_key(baum, BAUM_RSP_TopKeys, 0); break; case BRLAPI_KEY_CMD_HOME: baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL2|BAUM_TR1|BAUM_TR3); baum_send_key(baum, BAUM_RSP_TopKeys, 0); break; case BRLAPI_KEY_CMD_PREFMENU: baum_send_key(baum, BAUM_RSP_TopKeys, BAUM_TL1|BAUM_TL3|BAUM_TR1); baum_send_key(baum, BAUM_RSP_TopKeys, 0); break; } } break; case BRLAPI_KEY_TYPE_SYM: break; } } if (ret == -1 && (brlapi_errno != BRLAPI_ERROR_LIBCERR || errno != EINTR)) { brlapi_perror("baum: brlapi_readKey"); brlapi__closeConnection(baum->brlapi); g_free(baum->brlapi); baum->brlapi = NULL; } }
int urlphy_service(struct mii_softc *sc, struct mii_data *mii, int cmd) { struct ifmedia_entry *ife = mii->mii_media.ifm_cur; int reg; DPRINTF(("%s: %s: enter\n", sc->mii_dev.dv_xname, __FUNCTION__)); if ((sc->mii_dev.dv_flags & DVF_ACTIVE) == 0) return (ENXIO); switch (cmd) { case MII_POLLSTAT: /* * If we're not polling our PHY instance, just return. */ if (IFM_INST(ife->ifm_media) != sc->mii_inst) return (0); break; case MII_MEDIACHG: /* * If we're not currently selected, just return. */ if (IFM_INST(ife->ifm_media) != sc->mii_inst) return (0); /* If the interface is not up, don't do anything. */ if ((mii->mii_ifp->if_flags & IFF_UP) == 0) break; mii_phy_setmedia(sc); break; case MII_TICK: /* * If we're not currently selected, just return. */ if (IFM_INST(ife->ifm_media) != sc->mii_inst) return (0); /* Just bail now if the interface is down. */ if ((mii->mii_ifp->if_flags & IFF_UP) == 0) return (0); /* * If we're not doing autonegotiation, we don't need to do * any extra work here. However, we need to check the link * status so we can generate an announcement if the status * changes. */ if (IFM_SUBTYPE(ife->ifm_media) != IFM_AUTO) return (0); /* Read the status register twice; MSR_LINK is latch-low. */ reg = PHY_READ(sc, URLPHY_MSR) | PHY_READ(sc, URLPHY_MSR); if (reg & URLPHY_MSR_LINK) return (0); /* * Only retry autonegotiation every N seconds. */ KASSERT(sc->mii_anegticks != 0); if (++sc->mii_ticks != sc->mii_anegticks) return (0); sc->mii_ticks = 0; PHY_RESET(sc); if (mii_phy_auto(sc, 0) == EJUSTRETURN) return (0); break; case MII_DOWN: mii_phy_down(sc); return (0); } /* Update the media status. */ mii_phy_status(sc); /* Callback if something changed. */ mii_phy_update(sc, cmd); return (0); }
static int do_connect() { const char *server; const char *userid; const char *password; const char *database; const char *server_socket=0; unsigned int server_port=0; unsigned int server_opt=0; const char *p; const char *sslkey; const char *sslcert; const char *sslcacert; const char *sslcapath; const char *sslcipher; unsigned int use_ssl=0; /* ** Periodically detect dead connections. */ if (mysql) { static time_t last_time=0; time_t t_check; time(&t_check); if (t_check < last_time) last_time=t_check; /* System clock changed */ if (t_check < last_time + 60) return (0); last_time=t_check; if (mysql_ping(mysql) == 0) return (0); DPRINTF("authmysqllib: mysql_ping failed, connection lost"); mysql_close(mysql); mysql=0; } server=read_env("MYSQL_SERVER"); userid=read_env("MYSQL_USERNAME"); password=read_env("MYSQL_PASSWORD"); database=read_env("MYSQL_DATABASE"); #if MYSQL_VERSION_ID >= 32200 sslkey=read_env("MYSQL_SSL_KEY"); sslcert=read_env("MYSQL_SSL_CERT"); sslcacert=read_env("MYSQL_SSL_CACERT"); sslcapath=read_env("MYSQL_SSL_CAPATH"); sslcipher=read_env("MYSQL_SSL_CIPHER"); if ((sslcert != NULL) && ((sslcacert != NULL) || (sslcapath != NULL))) { use_ssl=1; } #endif server_socket=(char *) read_env("MYSQL_SOCKET"); if ((p=read_env("MYSQL_PORT")) != 0) { server_port=(unsigned int) atoi(p); } if ((p=read_env("MYSQL_OPT")) != 0) { server_opt=(unsigned int) atol(p); } if (!server && !server_socket) { err("authmysql: MYSQL_SERVER nor MYSQL_SOCKET set in" AUTHMYSQLRC "."); return (-1); } if (!userid) { err("authmysql: MYSQL_USERNAME not set in " AUTHMYSQLRC "."); return (-1); } if (!database) { err("authmysql: MYSQL_DATABASE not set in " AUTHMYSQLRC "."); return (-1); } #if MYSQL_VERSION_ID >= 32200 mysql_init(&mysql_buf); if (use_ssl) { mysql_ssl_set(&mysql_buf, sslkey, sslcert, sslcacert, sslcapath, sslcipher); } mysql=mysql_real_connect(&mysql_buf, server, userid, password, NULL, server_port, server_socket, server_opt); #else mysql=mysql_connect(&mysql_buf, server, userid, password); #endif if (!mysql) { err("failed to connect to mysql server (server=%s, userid=%s): %s", server ? server : "<null>", userid ? userid : "<null>", mysql_error(&mysql_buf)); return (-1); } if (mysql_select_db(mysql, database)) { err("authmysql: mysql_select_db(%s) error: %s", database, mysql_error(mysql)); mysql_close(mysql); mysql=0; return (-1); } DPRINTF("authmysqllib: connected. Versions: " "header %lu, " "client %lu, " "server %lu", (long)MYSQL_VERSION_ID, mysql_get_client_version(), mysql_get_server_version(mysql)); set_session_options(); return (0); }
struct authmysqluserinfo *auth_mysql_getuserinfo(const char *username, const char *service) { const char *defdomain =NULL; char *querybuf; MYSQL_ROW row; MYSQL_RES *result; int num_fields; char *endp; const char *select_clause; /* [email protected] */ #define DEFAULT_SELECT_QUERY "SELECT %s, %s, %s, %s, %s, %s, %s, %s, %s, %s FROM %s WHERE %s = '%s%s%s' %s%s%s", \ login_field, crypt_field, clear_field, uid_field,\ gid_field, home_field, maildir_field, quota_field,\ name_field, options_field, user_table, login_field,\ username_escaped,\ has_domain || !*defdomain ? "":"@", has_domain ? "":defdomain, \ *where_clause ? " AND (":"", where_clause,\ *where_clause ? ")":"" if (do_connect()) return (0); initui(); select_clause=read_env("MYSQL_SELECT_CLAUSE"); defdomain=read_env("DEFAULT_DOMAIN"); if (!defdomain) defdomain=""; if (!select_clause) /* [email protected] */ { const char *user_table, *crypt_field, *clear_field, *name_field, *uid_field, *gid_field, *login_field, *home_field, *maildir_field, *quota_field, *options_field, *where_clause; char *username_escaped; size_t query_size; char dummy_buf[1]; int has_domain; user_table=read_env("MYSQL_USER_TABLE"); if (!user_table) { err("authmysql: MYSQL_USER_TABLE not set in " AUTHMYSQLRC "."); return (0); } crypt_field=read_env("MYSQL_CRYPT_PWFIELD"); clear_field=read_env("MYSQL_CLEAR_PWFIELD"); name_field=read_env("MYSQL_NAME_FIELD"); if (!crypt_field && !clear_field) { err("authmysql: MYSQL_CRYPT_PWFIELD and " "MYSQL_CLEAR_PWFIELD not set in " AUTHMYSQLRC "."); return (0); } if (!crypt_field) crypt_field="\"\""; if (!clear_field) clear_field="\"\""; if (!name_field) name_field="\"\""; uid_field = read_env("MYSQL_UID_FIELD"); if (!uid_field) uid_field = "uid"; gid_field = read_env("MYSQL_GID_FIELD"); if (!gid_field) gid_field = "gid"; login_field = read_env("MYSQL_LOGIN_FIELD"); if (!login_field) login_field = "id"; home_field = read_env("MYSQL_HOME_FIELD"); if (!home_field) home_field = "home"; maildir_field=read_env(service && strcmp(service, "courier")==0 ? "MYSQL_DEFAULTDELIVERY" : "MYSQL_MAILDIR_FIELD"); if (!maildir_field) maildir_field="\"\""; quota_field=read_env("MYSQL_QUOTA_FIELD"); if (!quota_field) quota_field="\"\""; options_field=read_env("MYSQL_AUXOPTIONS_FIELD"); if (!options_field) options_field="\"\""; where_clause=read_env("MYSQL_WHERE_CLAUSE"); if (!where_clause) where_clause = ""; username_escaped=malloc(strlen(username)*2+1); if (!username_escaped) { perror("malloc"); return (0); } mysql_real_escape_string(mysql, username_escaped, username, strlen(username)); has_domain=strchr(username, '@') != NULL; query_size=snprintf(dummy_buf, 1, DEFAULT_SELECT_QUERY); querybuf=malloc(query_size+1); if (!querybuf) { free(username_escaped); perror("malloc"); return(0); } snprintf(querybuf, query_size+1, DEFAULT_SELECT_QUERY); free(username_escaped); } else { /* [email protected] */ querybuf=parse_select_clause (select_clause, username, defdomain, service); if (!querybuf) { DPRINTF("parse_select_clause failed (DEFAULT_DOMAIN not set?)"); return 0; } } DPRINTF("SQL query: %s", querybuf); if (mysql_query (mysql, querybuf)) { /* <*****@*****.**> */ DPRINTF("mysql_query failed, reconnecting: %s", mysql_error(mysql)); auth_mysql_cleanup(); if (do_connect()) { free(querybuf); return (0); } if (mysql_query (mysql, querybuf)) { DPRINTF("mysql_query failed second time, giving up: %s", mysql_error(mysql)); free(querybuf); auth_mysql_cleanup(); /* Server went down, that's OK, ** try again next time. */ return (0); } } free(querybuf); result = mysql_store_result (mysql); if (result) { if (mysql_num_rows(result)) { row = mysql_fetch_row (result); num_fields = mysql_num_fields (result); if (num_fields < 6) { DPRINTF("incomplete row, only %d fields returned", num_fields); mysql_free_result(result); return(0); } if (row[0] && row[0][0]) ui.username=strdup(row[0]); if (row[1] && row[1][0]) ui.cryptpw=strdup(row[1]); if (row[2] && row[2][0]) ui.clearpw=strdup(row[2]); /* perhaps authmysql needs a glob_uid/glob_gid feature like authldap? */ if (!row[3] || !row[3][0] || (ui.uid=strtol(row[3], &endp, 10), endp[0] != '\0')) { DPRINTF("invalid value for uid: '%s'", row[3] ? row[3] : "<null>"); mysql_free_result(result); return 0; } if (!row[4] || !row[4][0] || (ui.gid=strtol(row[4], &endp, 10), endp[0] != '\0')) { DPRINTF("invalid value for gid: '%s'", row[4] ? row[4] : "<null>"); mysql_free_result(result); return 0; } if (row[5] && row[5][0]) ui.home=strdup(row[5]); else { DPRINTF("required value for 'home' (column 6) is missing"); mysql_free_result(result); return(0); } if (num_fields > 6 && row[6] && row[6][0]) ui.maildir=strdup(row[6]); if (num_fields > 7 && row[7] && row[7][0]) ui.quota=strdup(row[7]); if (num_fields > 8 && row[8] && row[8][0]) ui.fullname=strdup(row[8]); if (num_fields > 9 && row[9] && row[9][0]) ui.options=strdup(row[9]); } else { DPRINTF("zero rows returned"); mysql_free_result(result); return (&ui); /* User not found */ } } else { DPRINTF("mysql_store_result failed"); return (0); } mysql_free_result(result); return (&ui); }
/*------------------------------------------------------------------------* * usb_proc_msignal * * This function will queue one of the passed USB process messages on * the USB process queue. The first message that is not already queued * will get queued. If both messages are already queued the one queued * last will be removed from the queue and queued in the end. The USB * process mutex must be locked when calling this function. This * function exploits the fact that a process can only do one callback * at a time. The message that was queued is returned. *------------------------------------------------------------------------*/ void * usb_proc_msignal(struct usb_process *up, void *_pm0, void *_pm1) { struct usb_proc_msg *pm0 = _pm0; struct usb_proc_msg *pm1 = _pm1; struct usb_proc_msg *pm2; usb_size_t d; uint8_t t; /* check if gone or in polling mode, return dummy value */ if (up->up_gone != 0 || USB_IN_POLLING_MODE_FUNC() != 0) return (_pm0); USB_MTX_ASSERT(up->up_mtx, MA_OWNED); t = 0; if (pm0->pm_qentry.tqe_prev) { t |= 1; } if (pm1->pm_qentry.tqe_prev) { t |= 2; } if (t == 0) { /* * No entries are queued. Queue "pm0" and use the existing * message number. */ pm2 = pm0; } else if (t == 1) { /* Check if we need to increment the message number. */ if (pm0->pm_num == up->up_msg_num) { up->up_msg_num++; } pm2 = pm1; } else if (t == 2) { /* Check if we need to increment the message number. */ if (pm1->pm_num == up->up_msg_num) { up->up_msg_num++; } pm2 = pm0; } else if (t == 3) { /* * Both entries are queued. Re-queue the entry closest to * the end. */ d = (pm1->pm_num - pm0->pm_num); /* Check sign after subtraction */ if (d & 0x80000000) { pm2 = pm0; } else { pm2 = pm1; } TAILQ_REMOVE(&up->up_qhead, pm2, pm_qentry); } else { pm2 = NULL; /* panic - should not happen */ } DPRINTF(" t=%u, num=%u\n", t, up->up_msg_num); /* Put message last on queue */ pm2->pm_num = up->up_msg_num; TAILQ_INSERT_TAIL(&up->up_qhead, pm2, pm_qentry); /* Check if we need to wakeup the USB process. */ if (up->up_msleep) { up->up_msleep = 0; /* save "cv_signal()" calls */ cv_signal(&up->up_cv); } return (pm2); }
void auth_mysql_enumerate( void(*cb_func)(const char *name, uid_t uid, gid_t gid, const char *homedir, const char *maildir, const char *options, void *void_arg), void *void_arg) { const char *defdomain, *select_clause; char *querybuf; MYSQL_ROW row; MYSQL_RES *result; if (do_connect()) return; initui(); select_clause=read_env("MYSQL_ENUMERATE_CLAUSE"); defdomain=read_env("DEFAULT_DOMAIN"); if (!defdomain || !defdomain[0]) defdomain="*"; /* otherwise parse_select_clause fails */ if (!select_clause) { const char *user_table, *uid_field, *gid_field, *login_field, *home_field, *maildir_field, *options_field, *where_clause; char dummy_buf[1]; size_t query_len; user_table=read_env("MYSQL_USER_TABLE"); if (!user_table) { err("authmysql: MYSQL_USER_TABLE not set in " AUTHMYSQLRC "."); return; } uid_field = read_env("MYSQL_UID_FIELD"); if (!uid_field) uid_field = "uid"; gid_field = read_env("MYSQL_GID_FIELD"); if (!gid_field) gid_field = "gid"; login_field = read_env("MYSQL_LOGIN_FIELD"); if (!login_field) login_field = "id"; home_field = read_env("MYSQL_HOME_FIELD"); if (!home_field) home_field = "home"; maildir_field=read_env("MYSQL_MAILDIR_FIELD"); if (!maildir_field) maildir_field="\"\""; options_field=read_env("MYSQL_AUXOPTIONS_FIELD"); if (!options_field) options_field="\"\""; where_clause=read_env("MYSQL_WHERE_CLAUSE"); if (!where_clause) where_clause = ""; #define DEFAULT_ENUMERATE_QUERY \ "SELECT %s, %s, %s, %s, %s, %s FROM %s %s%s",\ login_field, uid_field, gid_field, \ home_field, maildir_field, \ options_field, user_table, \ *where_clause ? " WHERE ":"", \ where_clause query_len=snprintf(dummy_buf, 1, DEFAULT_ENUMERATE_QUERY); querybuf=malloc(query_len+1); if (!querybuf) { perror("malloc"); return; } snprintf(querybuf, query_len+1, DEFAULT_ENUMERATE_QUERY); } else { /* [email protected] */ querybuf=parse_select_clause (select_clause, "*", defdomain, "enumerate"); if (!querybuf) { DPRINTF("authmysql: parse_select_clause failed"); return; } } DPRINTF("authmysql: enumerate query: %s", querybuf); if (mysql_query (mysql, querybuf)) { DPRINTF("mysql_query failed, reconnecting: %s", mysql_error(mysql)); /* <*****@*****.**> */ auth_mysql_cleanup(); if (do_connect()) { free(querybuf); return; } if (mysql_query (mysql, querybuf)) { DPRINTF("mysql_query failed second time, giving up: %s", mysql_error(mysql)); free(querybuf); auth_mysql_cleanup(); return; } } free(querybuf); result = mysql_use_result (mysql); if (result) { const char *username; uid_t uid; gid_t gid; const char *homedir; const char *maildir; const char *options; while ((row = mysql_fetch_row (result)) != NULL) { if(!row[0] || !row[0][0] || !row[1] || !row[1][0] || !row[2] || !row[2][0] || !row[3] || !row[3][0]) { continue; } username=row[0]; uid=atol(row[1]); /* FIXME use strtol to validate */ gid=atol(row[2]); homedir=row[3]; maildir=row[4]; options=row[5]; if (maildir && !*maildir) maildir=NULL; (*cb_func)(username, uid, gid, homedir, maildir, options, void_arg); } } /* NULL row could indicate end of result or an error */ if (mysql_errno(mysql)) { DPRINTF("mysql error during enumeration: %s", mysql_error(mysql)); } else (*cb_func)(NULL, 0, 0, NULL, NULL, NULL, void_arg); if (result) mysql_free_result(result); }
/*------------------------------------------------------------------------* * usb_process * * This function is the USB process dispatcher. *------------------------------------------------------------------------*/ static void usb_process(void *arg) { struct usb_process *up = arg; struct usb_proc_msg *pm; struct thread *td; /* in case of attach error, check for suspended */ USB_THREAD_SUSPEND_CHECK(); /* adjust priority */ td = curthread; thread_lock(td); sched_prio(td, up->up_prio); thread_unlock(td); USB_MTX_LOCK(up->up_mtx); up->up_curtd = td; while (1) { if (up->up_gone) break; /* * NOTE to reimplementors: dequeueing a command from the * "used" queue and executing it must be atomic, with regard * to the "up_mtx" mutex. That means any attempt to queue a * command by another thread must be blocked until either: * * 1) the command sleeps * * 2) the command returns * * Here is a practical example that shows how this helps * solving a problem: * * Assume that you want to set the baud rate on a USB serial * device. During the programming of the device you don't * want to receive nor transmit any data, because it will be * garbage most likely anyway. The programming of our USB * device takes 20 milliseconds and it needs to call * functions that sleep. * * Non-working solution: Before we queue the programming * command, we stop transmission and reception of data. Then * we queue a programming command. At the end of the * programming command we enable transmission and reception * of data. * * Problem: If a second programming command is queued while the * first one is sleeping, we end up enabling transmission * and reception of data too early. * * Working solution: Before we queue the programming command, * we stop transmission and reception of data. Then we queue * a programming command. Then we queue a second command * that only enables transmission and reception of data. * * Why it works: If a second programming command is queued * while the first one is sleeping, then the queueing of a * second command to enable the data transfers, will cause * the previous one, which is still on the queue, to be * removed from the queue, and re-inserted after the last * baud rate programming command, which then gives the * desired result. */ pm = TAILQ_FIRST(&up->up_qhead); if (pm) { DPRINTF("Message pm=%p, cb=%p (enter)\n", pm, pm->pm_callback); (pm->pm_callback) (pm); if (pm == TAILQ_FIRST(&up->up_qhead)) { /* nothing changed */ TAILQ_REMOVE(&up->up_qhead, pm, pm_qentry); pm->pm_qentry.tqe_prev = NULL; } DPRINTF("Message pm=%p (leave)\n", pm); continue; } /* end if messages - check if anyone is waiting for sync */ if (up->up_dsleep) { up->up_dsleep = 0; cv_broadcast(&up->up_drain); } up->up_msleep = 1; cv_wait(&up->up_cv, up->up_mtx); } up->up_ptr = NULL; cv_signal(&up->up_cv); USB_MTX_UNLOCK(up->up_mtx); #if (__FreeBSD_version >= 800000) /* Clear the proc pointer if this is the last thread. */ if (--usb_pcount == 0) usbproc = NULL; #endif USB_THREAD_EXIT(0); }
int nandfs_vblock_alloc(struct nandfs_device *nandfsdev, nandfs_daddr_t *vblock) { struct nandfs_node *dat; struct nandfs_mdt *mdt; struct nandfs_alloc_request req; struct nandfs_dat_entry *dat_entry; uint64_t start; uint32_t entry; int locked, error; dat = nandfsdev->nd_dat_node; mdt = &nandfsdev->nd_dat_mdt; start = nandfsdev->nd_last_cno + 1; locked = NANDFS_VOP_ISLOCKED(NTOV(dat)); if (!locked) VOP_LOCK(NTOV(dat), LK_EXCLUSIVE); req.entrynum = 0; /* Alloc vblock number */ error = nandfs_find_free_entry(mdt, dat, &req); if (error) { nandfs_error("%s: cannot find free vblk entry\n", __func__); if (!locked) VOP_UNLOCK(NTOV(dat), 0); return (error); } /* Read/create buffer */ error = nandfs_get_entry_block(mdt, dat, &req, &entry, 1); if (error) { nandfs_error("%s: cannot get free vblk entry\n", __func__); nandfs_abort_entry(&req); if (!locked) VOP_UNLOCK(NTOV(dat), 0); return (error); } /* Fill out vblock data */ dat_entry = (struct nandfs_dat_entry *) req.bp_entry->b_data; dat_entry[entry].de_start = start; dat_entry[entry].de_end = UINTMAX_MAX; dat_entry[entry].de_blocknr = 0; /* Commit allocation */ error = nandfs_alloc_entry(mdt, &req); if (error) { nandfs_error("%s: cannot get free vblk entry\n", __func__); if (!locked) VOP_UNLOCK(NTOV(dat), 0); return (error); } /* Return allocated vblock */ *vblock = req.entrynum; DPRINTF(DAT, ("%s: allocated vblock %#jx\n", __func__, (uintmax_t)*vblock)); if (!locked) VOP_UNLOCK(NTOV(dat), 0); return (error); }
MigrationState *unix_start_outgoing_migration(Monitor *mon, const char *path, int64_t bandwidth_limit, int detach, int blk, int inc) { FdMigrationState *s; struct sockaddr_un addr; int ret; addr.sun_family = AF_UNIX; snprintf(addr.sun_path, sizeof(addr.sun_path), "%s", path); s = qemu_mallocz(sizeof(*s)); s->get_error = unix_errno; s->write = unix_write; s->close = unix_close; s->mig_state.cancel = migrate_fd_cancel; s->mig_state.get_status = migrate_fd_get_status; s->mig_state.release = migrate_fd_release; s->mig_state.blk = blk; s->mig_state.shared = inc; s->state = MIG_STATE_ACTIVE; s->mon = NULL; s->bandwidth_limit = bandwidth_limit; s->fd = qemu_socket(PF_UNIX, SOCK_STREAM, 0); if (s->fd < 0) { DPRINTF("Unable to open socket"); goto err_after_alloc; } socket_set_nonblock(s->fd); do { ret = connect(s->fd, (struct sockaddr *)&addr, sizeof(addr)); if (ret == -1) ret = -(s->get_error(s)); if (ret == -EINPROGRESS || ret == -EWOULDBLOCK) qemu_set_fd_handler2(s->fd, NULL, NULL, unix_wait_for_connect, s); } while (ret == -EINTR); if (ret < 0 && ret != -EINPROGRESS && ret != -EWOULDBLOCK) { DPRINTF("connect failed\n"); goto err_after_open; } if (!detach) { migrate_fd_monitor_suspend(s, mon); } if (ret >= 0) migrate_fd_connect(s); return &s->mig_state; err_after_open: close(s->fd); err_after_alloc: qemu_free(s); return NULL; }
/* Try to interpret a whole incoming packet */ static int baum_eat_packet(BaumDriverState *baum, const uint8_t *buf, int len) { const uint8_t *cur = buf; uint8_t req = 0; if (!len--) return 0; if (*cur++ != ESC) { while (*cur != ESC) { if (!len--) return 0; cur++; } DPRINTF("Dropped %d bytes!\n", cur - buf); } #define EAT(c) do {\ if (!len--) \ return 0; \ if ((c = *cur++) == ESC) { \ if (!len--) \ return 0; \ if (*cur++ != ESC) { \ DPRINTF("Broken packet %#2x, tossing\n", req); \ if (timer_pending(baum->cellCount_timer)) { \ timer_del(baum->cellCount_timer); \ baum_cellCount_timer_cb(baum); \ } \ return (cur - 2 - buf); \ } \ } \ } while (0) EAT(req); switch (req) { case BAUM_REQ_DisplayData: { uint8_t cells[baum->x * baum->y], c; uint8_t text[baum->x * baum->y]; uint8_t zero[baum->x * baum->y]; int cursor = BRLAPI_CURSOR_OFF; int i; /* Allow 100ms to complete the DisplayData packet */ timer_mod(baum->cellCount_timer, qemu_clock_get_ns(QEMU_CLOCK_VIRTUAL) + get_ticks_per_sec() / 10); for (i = 0; i < baum->x * baum->y ; i++) { EAT(c); cells[i] = c; if ((c & (BRLAPI_DOT7|BRLAPI_DOT8)) == (BRLAPI_DOT7|BRLAPI_DOT8)) { cursor = i + 1; c &= ~(BRLAPI_DOT7|BRLAPI_DOT8); } if (!(c = nabcc_translation[c])) c = '?'; text[i] = c; } timer_del(baum->cellCount_timer); memset(zero, 0, sizeof(zero)); brlapi_writeArguments_t wa = { .displayNumber = BRLAPI_DISPLAY_DEFAULT, .regionBegin = 1, .regionSize = baum->x * baum->y, .text = (char *)text, .textSize = baum->x * baum->y, .andMask = zero, .orMask = cells, .cursor = cursor, .charset = (char *)"ISO-8859-1", }; if (brlapi__write(baum->brlapi, &wa) == -1) brlapi_perror("baum brlapi_write"); break; } case BAUM_REQ_SetMode: { uint8_t mode, setting; DPRINTF("SetMode\n"); EAT(mode); EAT(setting); /* ignore */ break; } case BAUM_REQ_SetProtocol: { uint8_t protocol; DPRINTF("SetProtocol\n"); EAT(protocol); /* ignore */ break; } case BAUM_REQ_GetDeviceIdentity: { uint8_t identity[17] = { BAUM_RSP_DeviceIdentity, 'B','a','u','m',' ','V','a','r','i','o' }; DPRINTF("GetDeviceIdentity\n"); identity[11] = '0' + baum->x / 10; identity[12] = '0' + baum->x % 10; baum_write_packet(baum, identity, sizeof(identity)); break; } case BAUM_REQ_GetVersionNumber: { uint8_t version[] = { BAUM_RSP_VersionNumber, 1 }; /* ? */ DPRINTF("GetVersionNumber\n"); baum_write_packet(baum, version, sizeof(version)); break; } case BAUM_REQ_GetSerialNumber: { uint8_t serial[] = { BAUM_RSP_SerialNumber, '0','0','0','0','0','0','0','0' }; DPRINTF("GetSerialNumber\n"); baum_write_packet(baum, serial, sizeof(serial)); break; } case BAUM_REQ_GetKeys: { DPRINTF("Get%0#2x\n", req); /* ignore */ break; } default: DPRINTF("unrecognized request %0#2x\n", req); do if (!len--) return 0; while (*cur++ != ESC); cur--; break; } return cur - buf; } /* The other end is writing some data. Store it and try to interpret */ static int baum_write(CharDriverState *chr, const uint8_t *buf, int len) { BaumDriverState *baum = chr->opaque; int tocopy, cur, eaten, orig_len = len; if (!len) return 0; if (!baum->brlapi) return len; while (len) { /* Complete our buffer as much as possible */ tocopy = len; if (tocopy > BUF_SIZE - baum->in_buf_used) tocopy = BUF_SIZE - baum->in_buf_used; memcpy(baum->in_buf + baum->in_buf_used, buf, tocopy); baum->in_buf_used += tocopy; buf += tocopy; len -= tocopy; /* Interpret it as much as possible */ cur = 0; while (cur < baum->in_buf_used && (eaten = baum_eat_packet(baum, baum->in_buf + cur, baum->in_buf_used - cur))) cur += eaten; /* Shift the remainder */ if (cur) { memmove(baum->in_buf, baum->in_buf + cur, baum->in_buf_used - cur); baum->in_buf_used -= cur; } /* And continue if any data left */ } return orig_len; }
int auth_mysql_setpass(const char *user, const char *pass, const char *oldpass) { char *newpass_crypt; char *sql_buf; int rc=0; char *clear_escaped; char *crypt_escaped; const char *clear_field =NULL, *crypt_field =NULL, *defdomain =NULL, *where_clause =NULL, *user_table =NULL, *login_field =NULL, *chpass_clause =NULL; /* [email protected] */ if (do_connect()) return (-1); if (!(newpass_crypt=authcryptpasswd(pass, oldpass))) return (-1); clear_escaped=malloc(strlen(pass)*2+1); if (!clear_escaped) { perror("malloc"); free(newpass_crypt); return -1; } crypt_escaped=malloc(strlen(newpass_crypt)*2+1); if (!crypt_escaped) { perror("malloc"); free(clear_escaped); free(newpass_crypt); return -1; } mysql_real_escape_string(mysql, clear_escaped, pass, strlen(pass)); mysql_real_escape_string(mysql, crypt_escaped, newpass_crypt, strlen(newpass_crypt)); /* [email protected] */ chpass_clause=read_env("MYSQL_CHPASS_CLAUSE"); defdomain=read_env("DEFAULT_DOMAIN"); user_table=read_env("MYSQL_USER_TABLE"); if (!chpass_clause) { int has_domain=strchr(user, '@') != NULL; char *username_escaped; char dummy_buf[1]; size_t sql_buf_size; username_escaped=malloc(strlen(user)*2+1); if (!username_escaped) { perror("malloc"); free(clear_escaped); free(crypt_escaped); free(newpass_crypt); return -1; } mysql_real_escape_string(mysql, username_escaped, user, strlen(user)); login_field = read_env("MYSQL_LOGIN_FIELD"); if (!login_field) login_field = "id"; crypt_field=read_env("MYSQL_CRYPT_PWFIELD"); clear_field=read_env("MYSQL_CLEAR_PWFIELD"); where_clause=read_env("MYSQL_WHERE_CLAUSE"); if (!where_clause) where_clause=""; if (!crypt_field) crypt_field=""; if (!clear_field) clear_field=""; if (!defdomain) defdomain=""; #define DEFAULT_SETPASS_UPDATE \ "UPDATE %s SET %s%s%s%s %s %s%s%s%s WHERE %s='%s%s%s' %s%s%s", \ user_table, \ *clear_field ? clear_field:"", \ *clear_field ? "='":"", \ *clear_field ? clear_escaped:"", \ *clear_field ? "'":"", \ \ *clear_field && *crypt_field ? ",":"", \ \ *crypt_field ? crypt_field:"", \ *crypt_field ? "='":"", \ *crypt_field ? crypt_escaped:"", \ *crypt_field ? "'":"", \ login_field, \ username_escaped, \ has_domain || !*defdomain ? "":"@", \ has_domain ? "":defdomain, \ *where_clause ? " AND (":"", where_clause, \ *where_clause ? ")":"" sql_buf_size=snprintf(dummy_buf, 1, DEFAULT_SETPASS_UPDATE); sql_buf=malloc(sql_buf_size+1); if (sql_buf) snprintf(sql_buf, sql_buf_size+1, DEFAULT_SETPASS_UPDATE); free(username_escaped); } else { sql_buf=parse_chpass_clause(chpass_clause, user, defdomain, clear_escaped, crypt_escaped); } free(clear_escaped); free(crypt_escaped); free(newpass_crypt); if (courier_authdebug_login_level >= 2) { DPRINTF("setpass SQL: %s", sql_buf); } if (mysql_query (mysql, sql_buf)) { DPRINTF("setpass SQL failed"); rc= -1; auth_mysql_cleanup(); } free(sql_buf); return (rc); }
/* Send the key code to the other end */ static void baum_send_key(BaumDriverState *baum, uint8_t type, uint8_t value) { uint8_t packet[] = { type, value }; DPRINTF("writing key %x %x\n", type, value); baum_write_packet(baum, packet, sizeof(packet)); }
/* * esp_init() is called when an SPI is being set up. */ static int esp_init(struct secasvar *sav, struct xformsw *xsp) { const struct enc_xform *txform; struct cryptoini cria, crie; int keylen; int error; txform = enc_algorithm_lookup(sav->alg_enc); if (txform == NULL) { DPRINTF(("%s: unsupported encryption algorithm %d\n", __func__, sav->alg_enc)); return EINVAL; } if (sav->key_enc == NULL) { DPRINTF(("%s: no encoding key for %s algorithm\n", __func__, txform->name)); return EINVAL; } if ((sav->flags & (SADB_X_EXT_OLD | SADB_X_EXT_IV4B)) == SADB_X_EXT_IV4B) { DPRINTF(("%s: 4-byte IV not supported with protocol\n", __func__)); return EINVAL; } /* subtract off the salt, RFC4106, 8.1 and RFC3686, 5.1 */ keylen = _KEYLEN(sav->key_enc) - SAV_ISCTRORGCM(sav) * 4; if (txform->minkey > keylen || keylen > txform->maxkey) { DPRINTF(("%s: invalid key length %u, must be in the range " "[%u..%u] for algorithm %s\n", __func__, keylen, txform->minkey, txform->maxkey, txform->name)); return EINVAL; } if (SAV_ISCTRORGCM(sav)) sav->ivlen = 8; /* RFC4106 3.1 and RFC3686 3.1 */ else sav->ivlen = txform->ivsize; /* * Setup AH-related state. */ if (sav->alg_auth != 0) { error = ah_init0(sav, xsp, &cria); if (error) return error; } /* NB: override anything set in ah_init0 */ sav->tdb_xform = xsp; sav->tdb_encalgxform = txform; /* * Whenever AES-GCM is used for encryption, one * of the AES authentication algorithms is chosen * as well, based on the key size. */ if (sav->alg_enc == SADB_X_EALG_AESGCM16) { switch (keylen) { case AES_128_GMAC_KEY_LEN: sav->alg_auth = SADB_X_AALG_AES128GMAC; sav->tdb_authalgxform = &auth_hash_nist_gmac_aes_128; break; case AES_192_GMAC_KEY_LEN: sav->alg_auth = SADB_X_AALG_AES192GMAC; sav->tdb_authalgxform = &auth_hash_nist_gmac_aes_192; break; case AES_256_GMAC_KEY_LEN: sav->alg_auth = SADB_X_AALG_AES256GMAC; sav->tdb_authalgxform = &auth_hash_nist_gmac_aes_256; break; default: DPRINTF(("%s: invalid key length %u" "for algorithm %s\n", __func__, keylen, txform->name)); return EINVAL; } bzero(&cria, sizeof(cria)); cria.cri_alg = sav->tdb_authalgxform->type; cria.cri_key = sav->key_enc->key_data; cria.cri_klen = _KEYBITS(sav->key_enc) - SAV_ISGCM(sav) * 32; } /* Initialize crypto session. */ bzero(&crie, sizeof(crie)); crie.cri_alg = sav->tdb_encalgxform->type; crie.cri_key = sav->key_enc->key_data; crie.cri_klen = _KEYBITS(sav->key_enc) - SAV_ISCTRORGCM(sav) * 32; if (sav->tdb_authalgxform && sav->tdb_encalgxform) { /* init both auth & enc */ crie.cri_next = &cria; error = crypto_newsession(&sav->tdb_cryptoid, &crie, V_crypto_support); } else if (sav->tdb_encalgxform) { error = crypto_newsession(&sav->tdb_cryptoid, &crie, V_crypto_support); } else if (sav->tdb_authalgxform) { error = crypto_newsession(&sav->tdb_cryptoid, &cria, V_crypto_support); } else { /* XXX cannot happen? */ DPRINTF(("%s: no encoding OR authentication xform!\n", __func__)); error = EINVAL; } return error; }
void dnsproxy_query(PNATState pData, struct socket *so, struct mbuf *m, int iphlen) #endif { #ifndef VBOX char buf[MAX_BUFSPACE]; unsigned int fromlen = sizeof(fromaddr); struct timeval tv; #else struct ip *ip; char *buf; int retransmit; struct udphdr *udp; #endif struct sockaddr_in addr; struct request *req = NULL; #ifndef VBOX struct sockaddr_in fromaddr; #else struct sockaddr_in fromaddr = { 0, }; #endif int byte = 0; ++all_queries; #ifndef VBOX /* Reschedule event */ event_add((struct event *)arg, NULL); /* read packet from socket */ if ((byte = recvfrom(fd, buf, sizeof(buf), 0, (struct sockaddr *)&fromaddr, &fromlen)) == -1) { LogRel(("recvfrom failed: %s\n", strerror(errno))); ++dropped_queries; return; } /* check for minimum dns packet length */ if (byte < 12) { LogRel(("query too short from %s\n", inet_ntoa(fromaddr.sin_addr))); ++dropped_queries; return; } /* allocate new request */ if ((req = calloc(1, sizeof(struct request))) == NULL) { LogRel(("calloc failed\n")); ++dropped_queries; return; } req->id = QUERYID; memcpy(&req->client, &fromaddr, sizeof(struct sockaddr_in)); memcpy(&req->clientid, &buf[0], 2); /* where is this query coming from? */ if (is_internal(pData, fromaddr.sin_addr)) { req->recursion = RD(buf); DPRINTF(("Internal query RD=%d\n", req->recursion)); } else { /* no recursion for foreigners */ req->recursion = 0; DPRINTF(("External query RD=%d\n", RD(buf))); } /* insert it into the hash table */ hash_add_request(pData, req); /* overwrite the original query id */ memcpy(&buf[0], &req->id, 2); if (req->recursion) { /* recursive queries timeout in 90s */ event_set(&req->timeout, -1, 0, timeout, req); tv.tv_sec=recursive_timeout; tv.tv_usec=0; event_add(&req->timeout, &tv); /* send it to our recursive server */ if ((byte = sendto(sock_answer, buf, (unsigned int)byte, 0, (struct sockaddr *)&recursive_addr, sizeof(struct sockaddr_in))) == -1) { LogRel(("sendto failed: %s\n", strerror(errno))); ++dropped_queries; return; } ++recursive_queries; } else { /* authoritative queries timeout in 10s */ event_set(&req->timeout, -1, 0, timeout, req); tv.tv_sec=authoritative_timeout; tv.tv_usec=0; event_add(&req->timeout, &tv); /* send it to our authoritative server */ if ((byte = sendto(sock_answer, buf, (unsigned int)byte, 0, (struct sockaddr *)&authoritative_addr, sizeof(struct sockaddr_in))) == -1) { LogRel(("sendto failed: %s\n", strerror(errno))); ++dropped_queries; return; } ++authoritative_queries; } #else /* VBOX */ AssertPtr(pData); /* m->m_data points to IP header */ #if 0 /* XXX: for some reason it make gdb ill, * it good to have this assert here with assumption above. */ M_ASSERTPKTHDR(m); #endif ip = mtod(m, struct ip *); udp = (struct udphdr *)(m->m_data + iphlen); fromaddr.sin_addr.s_addr = ip->ip_src.s_addr; fromaddr.sin_port = udp->uh_sport; fromaddr.sin_family = AF_INET; /* iphlen equals to lenght of ip header */ Assert(iphlen == sizeof(struct ip)); iphlen += sizeof (struct udphdr); byte = m->m_len - iphlen; buf = m->m_data + iphlen; /* check for minimum dns packet length */ if (byte < 12) { LogRel(("NAT: Query too short from %RTnaipv4\n", fromaddr.sin_addr)); ++dropped_queries; return; } req = so->so_timeout_arg; if (!req) { Assert(!so->so_timeout_arg); if ((req = RTMemAllocZ(sizeof(struct request) + byte)) == NULL) { LogRel(("NAT: calloc failed\n")); ++dropped_queries; return; } req->id = QUERYID; memcpy(&req->client, &fromaddr, sizeof(struct sockaddr_in)); memcpy(&req->clientid, &buf[0], 2); req->dns_server = TAILQ_LAST(&pData->pDnsList, dns_list_head); req->dnsgen = pData->dnsgen; if (req->dns_server == NULL) { RTMemFree(req); return; } retransmit = 0; so->so_timeout = timeout; so->so_timeout_arg = req; req->nbyte = byte; memcpy(req->byte, buf, byte); /* copying original request */ } else { if (req->dnsgen != pData->dnsgen) { /* XXX: Log2 */ LogRel(("NAT: dnsproxy: query: req %p dnsgen %u != %u on %R[natsock]\n", req, req->dnsgen, pData->dnsgen, so)); /* * XXX: TODO: this probably requires more cleanup. * Cf. XXX comment for sendto() failure below, but that * error leg is probably untested since ~never taken. */ ++dropped_queries; return; } retransmit = 1; } req->recursion = 0; DPRINTF(("External query RD=%d\n", RD(buf))); if (retransmit == 0) hash_add_request(pData, req); /* overwrite the original query id */ memcpy(&buf[0], &req->id, 2); /* let's slirp to care about expiration */ so->so_expire = curtime + recursive_timeout * 1000; memset(&addr, 0, sizeof(struct sockaddr_in)); addr.sin_family = AF_INET; if (req->dns_server->de_addr.s_addr == (pData->special_addr.s_addr | RT_H2N_U32_C(CTL_ALIAS))) { /* undo loopback remapping done in get_dns_addr_domain() */ addr.sin_addr.s_addr = RT_N2H_U32_C(INADDR_LOOPBACK); } else { addr.sin_addr.s_addr = req->dns_server->de_addr.s_addr; } addr.sin_port = htons(53); /* send it to our authoritative server */ Log2(("NAT: request will be %ssent to %RTnaipv4 on %R[natsock]\n", retransmit ? "re" : "", addr.sin_addr, so)); byte = sendto(so->s, buf, (unsigned int)byte, 0, (struct sockaddr *)&addr, sizeof(struct sockaddr_in)); if (byte == -1) { /* XXX: is it really enough? */ LogRel(("NAT: sendto failed: %s\n", strerror(errno))); ++dropped_queries; return; } so->so_state = SS_ISFCONNECTED; /* now it's selected */ Log2(("NAT: request was %ssent to %RTnaipv4 on %R[natsock]\n", retransmit ? "re" : "", addr.sin_addr, so)); ++authoritative_queries; # if 0 /* XXX: this stuff for _debugging_ only, * first enforce guest to send next request * and second for faster getting timeout callback * other option is adding couple entries in resolv.conf with * invalid nameservers. * * For testing purposes could be used * namebench -S -q 10000 -m random or -m chunk */ /* RTThreadSleep(3000); */ /* curtime += 300; */ # endif #endif /* VBOX */ }
/* * ESP input processing, called (eventually) through the protocol switch. */ static int esp_input(struct mbuf *m, struct secasvar *sav, int skip, int protoff) { IPSEC_DEBUG_DECLARE(char buf[128]); const struct auth_hash *esph; const struct enc_xform *espx; struct xform_data *xd; struct cryptodesc *crde; struct cryptop *crp; struct newesp *esp; uint8_t *ivp; uint64_t cryptoid; int alen, error, hlen, plen; IPSEC_ASSERT(sav != NULL, ("null SA")); IPSEC_ASSERT(sav->tdb_encalgxform != NULL, ("null encoding xform")); error = EINVAL; /* Valid IP Packet length ? */ if ( (skip&3) || (m->m_pkthdr.len&3) ){ DPRINTF(("%s: misaligned packet, skip %u pkt len %u", __func__, skip, m->m_pkthdr.len)); ESPSTAT_INC(esps_badilen); goto bad; } /* XXX don't pullup, just copy header */ IP6_EXTHDR_GET(esp, struct newesp *, m, skip, sizeof (struct newesp)); esph = sav->tdb_authalgxform; espx = sav->tdb_encalgxform; /* Determine the ESP header and auth length */ if (sav->flags & SADB_X_EXT_OLD) hlen = sizeof (struct esp) + sav->ivlen; else hlen = sizeof (struct newesp) + sav->ivlen; alen = xform_ah_authsize(esph); /* * Verify payload length is multiple of encryption algorithm * block size. * * NB: This works for the null algorithm because the blocksize * is 4 and all packets must be 4-byte aligned regardless * of the algorithm. */ plen = m->m_pkthdr.len - (skip + hlen + alen); if ((plen & (espx->blocksize - 1)) || (plen <= 0)) { DPRINTF(("%s: payload of %d octets not a multiple of %d octets," " SA %s/%08lx\n", __func__, plen, espx->blocksize, ipsec_address(&sav->sah->saidx.dst, buf, sizeof(buf)), (u_long)ntohl(sav->spi))); ESPSTAT_INC(esps_badilen); goto bad; } /* * Check sequence number. */ SECASVAR_LOCK(sav); if (esph != NULL && sav->replay != NULL && sav->replay->wsize != 0) { if (ipsec_chkreplay(ntohl(esp->esp_seq), sav) == 0) { SECASVAR_UNLOCK(sav); DPRINTF(("%s: packet replay check for %s\n", __func__, ipsec_sa2str(sav, buf, sizeof(buf)))); ESPSTAT_INC(esps_replay); error = EACCES; goto bad; } } cryptoid = sav->tdb_cryptoid; SECASVAR_UNLOCK(sav); /* Update the counters */ ESPSTAT_ADD(esps_ibytes, m->m_pkthdr.len - (skip + hlen + alen)); /* Get crypto descriptors */ crp = crypto_getreq(esph && espx ? 2 : 1); if (crp == NULL) { DPRINTF(("%s: failed to acquire crypto descriptors\n", __func__)); ESPSTAT_INC(esps_crypto); error = ENOBUFS; goto bad; } /* Get IPsec-specific opaque pointer */ xd = malloc(sizeof(*xd) + alen, M_XDATA, M_NOWAIT | M_ZERO); if (xd == NULL) { DPRINTF(("%s: failed to allocate xform_data\n", __func__)); ESPSTAT_INC(esps_crypto); crypto_freereq(crp); error = ENOBUFS; goto bad; } if (esph != NULL) { struct cryptodesc *crda = crp->crp_desc; IPSEC_ASSERT(crda != NULL, ("null ah crypto descriptor")); /* Authentication descriptor */ crda->crd_skip = skip; if (SAV_ISGCM(sav)) crda->crd_len = 8; /* RFC4106 5, SPI + SN */ else crda->crd_len = m->m_pkthdr.len - (skip + alen); crda->crd_inject = m->m_pkthdr.len - alen; crda->crd_alg = esph->type; /* Copy the authenticator */ m_copydata(m, m->m_pkthdr.len - alen, alen, (caddr_t) (xd + 1)); /* Chain authentication request */ crde = crda->crd_next; } else { crde = crp->crp_desc; } /* Crypto operation descriptor */ crp->crp_ilen = m->m_pkthdr.len; /* Total input length */ crp->crp_flags = CRYPTO_F_IMBUF | CRYPTO_F_CBIFSYNC; crp->crp_buf = (caddr_t) m; crp->crp_callback = esp_input_cb; crp->crp_sid = cryptoid; crp->crp_opaque = (caddr_t) xd; /* These are passed as-is to the callback */ xd->sav = sav; xd->protoff = protoff; xd->skip = skip; xd->cryptoid = cryptoid; /* Decryption descriptor */ IPSEC_ASSERT(crde != NULL, ("null esp crypto descriptor")); crde->crd_skip = skip + hlen; crde->crd_len = m->m_pkthdr.len - (skip + hlen + alen); crde->crd_inject = skip + hlen - sav->ivlen; if (SAV_ISCTRORGCM(sav)) { ivp = &crde->crd_iv[0]; /* GCM IV Format: RFC4106 4 */ /* CTR IV Format: RFC3686 4 */ /* Salt is last four bytes of key, RFC4106 8.1 */ /* Nonce is last four bytes of key, RFC3686 5.1 */ memcpy(ivp, sav->key_enc->key_data + _KEYLEN(sav->key_enc) - 4, 4); if (SAV_ISCTR(sav)) { /* Initial block counter is 1, RFC3686 4 */ be32enc(&ivp[sav->ivlen + 4], 1); } m_copydata(m, skip + hlen - sav->ivlen, sav->ivlen, &ivp[4]); crde->crd_flags |= CRD_F_IV_EXPLICIT; } crde->crd_alg = espx->type; return (crypto_dispatch(crp)); bad: m_freem(m); key_freesav(&sav); return (error); }
static struct xc_interface_core *xc_interface_open_common(xentoollog_logger *logger, xentoollog_logger *dombuild_logger, unsigned open_flags, enum xc_osdep_type type) { struct xc_interface_core xch_buf, *xch = &xch_buf; xch->type = type; xch->flags = open_flags; xch->dombuild_logger_file = 0; xc_clear_last_error(xch); xch->error_handler = logger; xch->error_handler_tofree = 0; xch->dombuild_logger = dombuild_logger; xch->dombuild_logger_tofree = 0; xch->hypercall_buffer_cache_nr = 0; xch->hypercall_buffer_total_allocations = 0; xch->hypercall_buffer_total_releases = 0; xch->hypercall_buffer_current_allocations = 0; xch->hypercall_buffer_maximum_allocations = 0; xch->hypercall_buffer_cache_hits = 0; xch->hypercall_buffer_cache_misses = 0; xch->hypercall_buffer_cache_toobig = 0; xch->ops_handle = XC_OSDEP_OPEN_ERROR; xch->ops = NULL; if (!xch->error_handler) { xch->error_handler = xch->error_handler_tofree = (xentoollog_logger*) xtl_createlogger_stdiostream(stderr, XTL_PROGRESS, 0); if (!xch->error_handler) goto err; } xch = malloc(sizeof(*xch)); if (!xch) { xch = &xch_buf; PERROR("Could not allocate new xc_interface struct"); goto err; } *xch = xch_buf; if (!(open_flags & XC_OPENFLAG_DUMMY)) { if ( xc_osdep_get_info(xch, &xch->osdep) < 0 ) goto err; xch->ops = xch->osdep.init(xch, type); if ( xch->ops == NULL ) { DPRINTF("OSDEP: interface %d (%s) not supported on this platform", type, xc_osdep_type_name(type)); goto err_put_iface; } xch->ops_handle = xch->ops->open(xch); if (xch->ops_handle == XC_OSDEP_OPEN_ERROR) goto err_put_iface; } return xch; err_put_iface: xc_osdep_put(&xch->osdep); err: xtl_logger_destroy(xch->error_handler_tofree); if (xch != &xch_buf) free(xch); return NULL; }
/* * ESP input callback from the crypto driver. */ static int esp_input_cb(struct cryptop *crp) { IPSEC_DEBUG_DECLARE(char buf[128]); u_int8_t lastthree[3], aalg[AH_HMAC_MAXHASHLEN]; const struct auth_hash *esph; const struct enc_xform *espx; struct mbuf *m; struct cryptodesc *crd; struct xform_data *xd; struct secasvar *sav; struct secasindex *saidx; caddr_t ptr; uint64_t cryptoid; int hlen, skip, protoff, error, alen; crd = crp->crp_desc; IPSEC_ASSERT(crd != NULL, ("null crypto descriptor!")); m = (struct mbuf *) crp->crp_buf; xd = (struct xform_data *) crp->crp_opaque; sav = xd->sav; skip = xd->skip; protoff = xd->protoff; cryptoid = xd->cryptoid; saidx = &sav->sah->saidx; esph = sav->tdb_authalgxform; espx = sav->tdb_encalgxform; /* Check for crypto errors */ if (crp->crp_etype) { if (crp->crp_etype == EAGAIN) { /* Reset the session ID */ if (ipsec_updateid(sav, &crp->crp_sid, &cryptoid) != 0) crypto_freesession(cryptoid); xd->cryptoid = crp->crp_sid; return (crypto_dispatch(crp)); } ESPSTAT_INC(esps_noxform); DPRINTF(("%s: crypto error %d\n", __func__, crp->crp_etype)); error = crp->crp_etype; goto bad; } /* Shouldn't happen... */ if (m == NULL) { ESPSTAT_INC(esps_crypto); DPRINTF(("%s: bogus returned buffer from crypto\n", __func__)); error = EINVAL; goto bad; } ESPSTAT_INC(esps_hist[sav->alg_enc]); /* If authentication was performed, check now. */ if (esph != NULL) { alen = xform_ah_authsize(esph); AHSTAT_INC(ahs_hist[sav->alg_auth]); /* Copy the authenticator from the packet */ m_copydata(m, m->m_pkthdr.len - alen, alen, aalg); ptr = (caddr_t) (xd + 1); /* Verify authenticator */ if (timingsafe_bcmp(ptr, aalg, alen) != 0) { DPRINTF(("%s: authentication hash mismatch for " "packet in SA %s/%08lx\n", __func__, ipsec_address(&saidx->dst, buf, sizeof(buf)), (u_long) ntohl(sav->spi))); ESPSTAT_INC(esps_badauth); error = EACCES; goto bad; } m->m_flags |= M_AUTHIPDGM; /* Remove trailing authenticator */ m_adj(m, -alen); } /* Release the crypto descriptors */ free(xd, M_XDATA), xd = NULL; crypto_freereq(crp), crp = NULL; /* * Packet is now decrypted. */ m->m_flags |= M_DECRYPTED; /* * Update replay sequence number, if appropriate. */ if (sav->replay) { u_int32_t seq; m_copydata(m, skip + offsetof(struct newesp, esp_seq), sizeof (seq), (caddr_t) &seq); SECASVAR_LOCK(sav); if (ipsec_updatereplay(ntohl(seq), sav)) { SECASVAR_UNLOCK(sav); DPRINTF(("%s: packet replay check for %s\n", __func__, ipsec_sa2str(sav, buf, sizeof(buf)))); ESPSTAT_INC(esps_replay); error = EACCES; goto bad; } SECASVAR_UNLOCK(sav); }
//////////////////////////////////////////////////////////////////////////// /////////////// // 函数名: // 编写者: // 参考资料: // 功 能: // 输入参数: // 输出参数: // 备 注: //////////////////////////////////////////////////////////////////////////// /////////////// void main (void) { PCA0MD &= ~0x40; // Disable Watchdog timer Init_VAR(); Init_Device(); Init_patch(); BUZZY_OFF(); Init_sensor(); P1MDOUT&=~0x06; //p11 p12 非推挽 LCD时钟数据和加密 P1MDOUT&=~0x40; //p16 非推挽 LCD选通 P1MDOUT&=~0x80; //p17 非推挽 LCD电源总开开关 P1MDOUT&=~0x20; //p15 非推挽 LCD选通 #ifdef SECURE_SPI P0MDOUT&=~0x80; //p07 非推挽 //加密MCLK P07=1; #endif P0MDOUT&=~0x20; //充满检测 ,高:充满或未冲 低:充电 P1|=0x46; //srb clk data PO_LCD_POWER(P_LCD_ON); Init_LCD(); Init_EPROM(); #ifdef SECURE_SPI {extern void InitSPICom(void) ; extern char TEST_SPI(char CMD_a); BYTE tryc=3; InitSPICom() ; F_demo=1; do { if(1==TEST_SPI(CMD_RD_ID)) { F_demo=0; break; } DelayXms(300); }while(tryc--) ; if(1==F_demo) { DisplayCont=DISPLAY_DEMO; Display_All(); //显示初始错误 } } #endif DPRINTF(printf("MAIN Program\n" )) ; #if 0 if(PI_ADJUST_DET()) { DelayXms(100); if(PI_ADJUST_DET()) NEW_KEY= KEY_ADJUST; } #endif #if 1 if(PWR_G2==0) { diaplay_std (); DelayXms(3000); } #endif while(1) { { //WORD i ;extern BYTE StateSensor ; // if(StateSensor==-1) // LEDIO=!LEDIO; } if(F_5ms) { F_5ms=0; if(PWR_G1==0) {StateSensor=0;} {extern void TestACHOL(); TestACHOL(); } } // if(F_10ms) // { // F_10ms=0; // } if(F_50ms) { F_50ms=0; Task_50ms(); } if(F_100ms) { F_100ms=0; /* {extern void TestACHOL(); TestACHOL(); } */ { extern WORD CountHeat; if(CountHeat<=350) { CountHeat++; } } DO_Key_Action() ; Display_All(); { extern void SendCycbuf(void); SendCycbuf(); } } if(F_200ms) { F_200ms=0; } if(F_500ms) { F_500ms=0; } if(F_1000ms) { // DPRINTF(printf("time=%bd \n" ,sys_time.Time_1_sec)) ; Task_500ms(); } } }
/* * Read disk label from the device. */ int wdgetdisklabel(struct wd_softc *wd) { char *msg; int sector; size_t rsize; struct disklabel *lp; uint8_t buf[DEV_BSIZE]; uint16_t magic; wdgetdefaultlabel(wd, &wd->sc_label); /* * Find NetBSD Partition in DOS partition table. */ sector = 0; if (wdstrategy(wd, F_READ, MBR_BBSECTOR, DEV_BSIZE, buf, &rsize)) return EOFFSET; memcpy(&magic, &buf[MBR_MAGIC_OFFSET], sizeof(magic)); if (magic == MBR_MAGIC) { int i; struct mbr_partition *mp; /* * Lookup NetBSD slice. If there is none, go ahead * and try to read the disklabel off sector #0. */ mp = (struct mbr_partition *)&buf[MBR_PART_OFFSET]; for (i = 0; i < MBR_PART_COUNT; i++) { if (mp[i].mbrp_type == MBR_PTYPE_NETBSD) { sector = mp[i].mbrp_start; break; } } } if (wdstrategy(wd, F_READ, sector + LABELSECTOR, DEV_BSIZE, buf, &rsize)) return EOFFSET; if ((msg = getdisklabel(buf + LABELOFFSET, &wd->sc_label))) printf("wd%d: getdisklabel: %s\n", wd->sc_unit, msg); lp = &wd->sc_label; /* check partition */ if ((wd->sc_part >= lp->d_npartitions) || (lp->d_partitions[wd->sc_part].p_fstype == FS_UNUSED)) { DPRINTF(("illegal partition\n")); return EPART; } DPRINTF(("label info: d_secsize %d, d_nsectors %d, d_ncylinders %d," " d_ntracks %d, d_secpercyl %d\n", wd->sc_label.d_secsize, wd->sc_label.d_nsectors, wd->sc_label.d_ncylinders, wd->sc_label.d_ntracks, wd->sc_label.d_secpercyl)); return 0; }
JNIEXPORT jlong JNICALL Java_com_ratusapparatus_passssh_PassSSH_Create(JNIEnv *, jobject) { DPRINTF( "%s\n", __FUNCTION__ ); return (uintptr_t)new PassSSH(); }
void ulpt_attach(struct device *parent, struct device *self, void *aux) { struct ulpt_softc *sc = (struct ulpt_softc *)self; struct usb_attach_arg *uaa = aux; usbd_device_handle dev = uaa->device; usbd_interface_handle iface = uaa->iface; usb_interface_descriptor_t *ifcd = usbd_get_interface_descriptor(iface); usb_interface_descriptor_t *id, *iend; usb_config_descriptor_t *cdesc; usbd_status err; usb_endpoint_descriptor_t *ed; u_int8_t epcount; int i, altno; DPRINTFN(10,("ulpt_attach: sc=%p\n", sc)); //printf("%s: iclass %d/%d\n", sc->sc_dev.dv_xname, // ifcd->bInterfaceClass, ifcd->bInterfaceSubClass); /* XXX * Stepping through the alternate settings needs to be abstracted out. */ cdesc = usbd_get_config_descriptor(dev); if (cdesc == NULL) { printf("%s: failed to get configuration descriptor\n", sc->sc_dev.dv_xname); return; } iend = (usb_interface_descriptor_t *) ((char *)cdesc + UGETW(cdesc->wTotalLength)); #ifdef DIAGNOSTIC if (ifcd < (usb_interface_descriptor_t *)cdesc || ifcd >= iend) panic("ulpt: iface desc out of range"); #endif /* Step through all the descriptors looking for bidir mode */ for (id = ifcd, altno = 0; id < iend; id = (void *)((char *)id + id->bLength)) { if (id->bDescriptorType == UDESC_INTERFACE && id->bInterfaceNumber == ifcd->bInterfaceNumber) { if (id->bInterfaceClass == UICLASS_PRINTER && id->bInterfaceSubClass == UISUBCLASS_PRINTER && (id->bInterfaceProtocol == UIPROTO_PRINTER_BI /*|| id->bInterfaceProtocol == UIPROTO_PRINTER_1284*/)) goto found; altno++; } } id = ifcd; /* not found, use original */ found: if (id != ifcd) { /* Found a new bidir setting */ DPRINTF(("ulpt_attach: set altno = %d\n", altno)); err = usbd_set_interface(iface, altno); if (err) { printf("%s: setting alternate interface failed\n", sc->sc_dev.dv_xname); sc->sc_dying = 1; return; } } epcount = 0; (void)usbd_endpoint_count(iface, &epcount); sc->sc_in = -1; sc->sc_out = -1; for (i = 0; i < epcount; i++) { ed = usbd_interface2endpoint_descriptor(iface, i); if (ed == NULL) { printf("%s: couldn't get ep %d\n", sc->sc_dev.dv_xname, i); return; } if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN && UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { sc->sc_in = ed->bEndpointAddress; } else if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_OUT && UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) { sc->sc_out = ed->bEndpointAddress; } } if (sc->sc_out == -1) { printf("%s: could not find bulk out endpoint\n", sc->sc_dev.dv_xname); sc->sc_dying = 1; return; } if (usbd_get_quirks(dev)->uq_flags & UQ_BROKEN_BIDIR) { /* This device doesn't handle reading properly. */ sc->sc_in = -1; } printf("%s: using %s-directional mode\n", sc->sc_dev.dv_xname, sc->sc_in >= 0 ? "bi" : "uni"); DPRINTFN(10, ("ulpt_attach: bulk=%d\n", sc->sc_out)); sc->sc_iface = iface; sc->sc_ifaceno = id->bInterfaceNumber; sc->sc_udev = dev; #if 0 /* * This code is disabled because for some mysterious reason it causes * printing not to work. But only sometimes, and mostly with * UHCI and less often with OHCI. *sigh* */ { usb_config_descriptor_t *cd = usbd_get_config_descriptor(dev); usb_device_request_t req; int len, alen; req.bmRequestType = UT_READ_CLASS_INTERFACE; req.bRequest = UR_GET_DEVICE_ID; USETW(req.wValue, cd->bConfigurationValue); USETW2(req.wIndex, id->bInterfaceNumber, id->bAlternateSetting); USETW(req.wLength, DEVINFOSIZE - 1); err = usbd_do_request_flags(dev, &req, devinfop, USBD_SHORT_XFER_OK, &alen, USBD_DEFAULT_TIMEOUT); if (err) { printf("%s: cannot get device id\n", sc->sc_dev.dv_xname); } else if (alen <= 2) { printf("%s: empty device id, no printer connected?\n", sc->sc_dev.dv_xname); } else { /* devinfop now contains an IEEE-1284 device ID */ len = ((devinfop[0] & 0xff) << 8) | (devinfop[1] & 0xff); if (len > DEVINFOSIZE - 3) len = DEVINFOSIZE - 3; devinfo[len] = 0; printf("%s: device id <", sc->sc_dev.dv_xname); ieee1284_print_id(devinfop+2); printf(">\n"); } } #endif usbd_add_drv_event(USB_EVENT_DRIVER_ATTACH, sc->sc_udev, &sc->sc_dev); }
JNIEXPORT void JNICALL Java_com_ratusapparatus_passssh_PassSSH_GeneratePass(JNIEnv *env, jobject obj, jstring, jboolean, jint) { DPRINTF( "%s\n", __FUNCTION__ ); PassSSH *passSSH = ptr<PassSSH>(env, obj); }
/* * Reset the printer, then wait until it's selected and not busy. */ int ulptopen(dev_t dev, int flag, int mode, struct proc *p) { u_char flags = ULPTFLAGS(dev); struct ulpt_softc *sc; usbd_status err; int spin, error; if (ULPTUNIT(dev) >= ulpt_cd.cd_ndevs) return (ENXIO); sc = ulpt_cd.cd_devs[ULPTUNIT(dev)]; if (sc == NULL) return (ENXIO); if (sc == NULL || sc->sc_iface == NULL || sc->sc_dying) return (ENXIO); if (sc->sc_state) return (EBUSY); sc->sc_state = ULPT_INIT; sc->sc_flags = flags; DPRINTF(("ulptopen: flags=0x%x\n", (unsigned)flags)); error = 0; sc->sc_refcnt++; if ((flags & ULPT_NOPRIME) == 0) ulpt_reset(sc); for (spin = 0; (ulpt_status(sc) & LPS_SELECT) == 0; spin += STEP) { DPRINTF(("ulpt_open: waiting a while\n")); if (spin >= TIMEOUT) { error = EBUSY; sc->sc_state = 0; goto done; } /* wait 1/4 second, give up if we get a signal */ error = tsleep((caddr_t)sc, LPTPRI | PCATCH, "ulptop", STEP); if (error != EWOULDBLOCK) { sc->sc_state = 0; goto done; } if (sc->sc_dying) { error = ENXIO; sc->sc_state = 0; goto done; } } err = usbd_open_pipe(sc->sc_iface, sc->sc_out, 0, &sc->sc_out_pipe); if (err) { sc->sc_state = 0; error = EIO; goto done; } if (ulptusein && sc->sc_in != -1) { DPRINTF(("ulpt_open: open input pipe\n")); err = usbd_open_pipe(sc->sc_iface, sc->sc_in,0,&sc->sc_in_pipe); if (err) { error = EIO; usbd_close_pipe(sc->sc_out_pipe); sc->sc_out_pipe = NULL; sc->sc_state = 0; goto done; } sc->sc_in_xfer1 = usbd_alloc_xfer(sc->sc_udev); sc->sc_in_xfer2 = usbd_alloc_xfer(sc->sc_udev); if (sc->sc_in_xfer1 == NULL || sc->sc_in_xfer2 == NULL) { error = ENOMEM; if (sc->sc_in_xfer1 != NULL) { usbd_free_xfer(sc->sc_in_xfer1); sc->sc_in_xfer1 = NULL; } if (sc->sc_in_xfer2 != NULL) { usbd_free_xfer(sc->sc_in_xfer2); sc->sc_in_xfer2 = NULL; } usbd_close_pipe(sc->sc_out_pipe); sc->sc_out_pipe = NULL; usbd_close_pipe(sc->sc_in_pipe); sc->sc_in_pipe = NULL; sc->sc_state = 0; goto done; } usbd_setup_xfer(sc->sc_in_xfer1, sc->sc_in_pipe, sc, sc->sc_junk, sizeof sc->sc_junk, USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, ulpt_input); usbd_setup_xfer(sc->sc_in_xfer2, sc->sc_in_pipe, sc, sc->sc_junk, sizeof sc->sc_junk, USBD_SHORT_XFER_OK, USBD_NO_TIMEOUT, ulpt_input); usbd_transfer(sc->sc_in_xfer1); /* ignore failed start */ } sc->sc_state = ULPT_OPEN; done: if (--sc->sc_refcnt < 0) usb_detach_wakeup(&sc->sc_dev); DPRINTF(("ulptopen: done, error=%d\n", error)); return (error); }
struct msdosfsmount * msdosfs_mount(struct vnode *devvp, int flags) { struct msdosfsmount *pmp = NULL; struct buf *bp; union bootsector *bsp; struct byte_bpb33 *b33; struct byte_bpb50 *b50; struct byte_bpb710 *b710; uint8_t SecPerClust; int ronly = 0, error, tmp; int bsize; struct msdos_options *m = devvp->fs->fs_specific; uint64_t psize = m->create_size; unsigned secsize = 512; DPRINTF(("%s(bread 0)\n", __func__)); if ((error = bread(devvp, 0, secsize, NULL, 0, &bp)) != 0) goto error_exit; bsp = (union bootsector *)bp->b_data; b33 = (struct byte_bpb33 *)bsp->bs33.bsBPB; b50 = (struct byte_bpb50 *)bsp->bs50.bsBPB; b710 = (struct byte_bpb710 *)bsp->bs710.bsBPB; if (!(flags & MSDOSFSMNT_GEMDOSFS)) { if (bsp->bs50.bsBootSectSig0 != BOOTSIG0 || bsp->bs50.bsBootSectSig1 != BOOTSIG1) { DPRINTF(("bootsig0 %d bootsig1 %d\n", bsp->bs50.bsBootSectSig0, bsp->bs50.bsBootSectSig1)); error = EINVAL; goto error_exit; } bsize = 0; } else bsize = 512; pmp = ecalloc(1, sizeof *pmp); /* * Compute several useful quantities from the bpb in the * bootsector. Copy in the dos 5 variant of the bpb then fix up * the fields that are different between dos 5 and dos 3.3. */ SecPerClust = b50->bpbSecPerClust; pmp->pm_BytesPerSec = getushort(b50->bpbBytesPerSec); pmp->pm_ResSectors = getushort(b50->bpbResSectors); pmp->pm_FATs = b50->bpbFATs; pmp->pm_RootDirEnts = getushort(b50->bpbRootDirEnts); pmp->pm_Sectors = getushort(b50->bpbSectors); pmp->pm_FATsecs = getushort(b50->bpbFATsecs); pmp->pm_SecPerTrack = getushort(b50->bpbSecPerTrack); pmp->pm_Heads = getushort(b50->bpbHeads); pmp->pm_Media = b50->bpbMedia; DPRINTF(("%s(BytesPerSec=%u, ResSectors=%u, FATs=%d, RootDirEnts=%u, " "Sectors=%u, FATsecs=%lu, SecPerTrack=%u, Heads=%u, Media=%u)\n", __func__, pmp->pm_BytesPerSec, pmp->pm_ResSectors, pmp->pm_FATs, pmp->pm_RootDirEnts, pmp->pm_Sectors, pmp->pm_FATsecs, pmp->pm_SecPerTrack, pmp->pm_Heads, pmp->pm_Media)); if (!(flags & MSDOSFSMNT_GEMDOSFS)) { /* XXX - We should probably check more values here */ if (!pmp->pm_BytesPerSec || !SecPerClust || pmp->pm_SecPerTrack > 63) { DPRINTF(("bytespersec %d secperclust %d " "secpertrack %d\n", pmp->pm_BytesPerSec, SecPerClust, pmp->pm_SecPerTrack)); error = EINVAL; goto error_exit; } } if (pmp->pm_Sectors == 0) { pmp->pm_HiddenSects = getulong(b50->bpbHiddenSecs); pmp->pm_HugeSectors = getulong(b50->bpbHugeSectors); } else { pmp->pm_HiddenSects = getushort(b33->bpbHiddenSecs); pmp->pm_HugeSectors = pmp->pm_Sectors; } if (pmp->pm_RootDirEnts == 0) { unsigned short vers = getushort(b710->bpbFSVers); /* * Some say that bsBootSectSig[23] must be zero, but * Windows does not require this and some digital cameras * do not set these to zero. Therefore, do not insist. */ if (pmp->pm_Sectors || pmp->pm_FATsecs || vers) { DPRINTF(("sectors %d fatsecs %lu vers %d\n", pmp->pm_Sectors, pmp->pm_FATsecs, vers)); error = EINVAL; goto error_exit; } pmp->pm_fatmask = FAT32_MASK; pmp->pm_fatmult = 4; pmp->pm_fatdiv = 1; pmp->pm_FATsecs = getulong(b710->bpbBigFATsecs); /* mirrorring is enabled if the FATMIRROR bit is not set */ if ((getushort(b710->bpbExtFlags) & FATMIRROR) == 0) pmp->pm_flags |= MSDOSFS_FATMIRROR; else pmp->pm_curfat = getushort(b710->bpbExtFlags) & FATNUM; } else pmp->pm_flags |= MSDOSFS_FATMIRROR; if (flags & MSDOSFSMNT_GEMDOSFS) { if (FAT32(pmp)) { DPRINTF(("FAT32 for GEMDOS\n")); /* * GEMDOS doesn't know FAT32. */ error = EINVAL; goto error_exit; } /* * Check a few values (could do some more): * - logical sector size: power of 2, >= block size * - sectors per cluster: power of 2, >= 1 * - number of sectors: >= 1, <= size of partition */ if ( (SecPerClust == 0) || (SecPerClust & (SecPerClust - 1)) || (pmp->pm_BytesPerSec < bsize) || (pmp->pm_BytesPerSec & (pmp->pm_BytesPerSec - 1)) || (pmp->pm_HugeSectors == 0) || (pmp->pm_HugeSectors * (pmp->pm_BytesPerSec / bsize) > psize)) { DPRINTF(("consistency checks for GEMDOS\n")); error = EINVAL; goto error_exit; } /* * XXX - Many parts of the msdosfs driver seem to assume that * the number of bytes per logical sector (BytesPerSec) will * always be the same as the number of bytes per disk block * Let's pretend it is. */ tmp = pmp->pm_BytesPerSec / bsize; pmp->pm_BytesPerSec = bsize; pmp->pm_HugeSectors *= tmp; pmp->pm_HiddenSects *= tmp; pmp->pm_ResSectors *= tmp; pmp->pm_Sectors *= tmp; pmp->pm_FATsecs *= tmp; SecPerClust *= tmp; } /* Check that fs has nonzero FAT size */ if (pmp->pm_FATsecs == 0) { DPRINTF(("FATsecs is 0\n")); error = EINVAL; goto error_exit; } pmp->pm_fatblk = pmp->pm_ResSectors; if (FAT32(pmp)) { pmp->pm_rootdirblk = getulong(b710->bpbRootClust); pmp->pm_firstcluster = pmp->pm_fatblk + (pmp->pm_FATs * pmp->pm_FATsecs); pmp->pm_fsinfo = getushort(b710->bpbFSInfo); } else { pmp->pm_rootdirblk = pmp->pm_fatblk + (pmp->pm_FATs * pmp->pm_FATsecs); pmp->pm_rootdirsize = (pmp->pm_RootDirEnts * sizeof(struct direntry) + pmp->pm_BytesPerSec - 1) / pmp->pm_BytesPerSec;/* in sectors */ pmp->pm_firstcluster = pmp->pm_rootdirblk + pmp->pm_rootdirsize; } pmp->pm_nmbrofclusters = (pmp->pm_HugeSectors - pmp->pm_firstcluster) / SecPerClust; pmp->pm_maxcluster = pmp->pm_nmbrofclusters + 1; pmp->pm_fatsize = pmp->pm_FATsecs * pmp->pm_BytesPerSec; if (flags & MSDOSFSMNT_GEMDOSFS) { if (pmp->pm_nmbrofclusters <= (0xff0 - 2)) { pmp->pm_fatmask = FAT12_MASK; pmp->pm_fatmult = 3; pmp->pm_fatdiv = 2; } else { pmp->pm_fatmask = FAT16_MASK; pmp->pm_fatmult = 2; pmp->pm_fatdiv = 1; } } else if (pmp->pm_fatmask == 0) { if (pmp->pm_maxcluster <= ((CLUST_RSRVD - CLUST_FIRST) & FAT12_MASK)) { /* * This will usually be a floppy disk. This size makes * sure that one FAT entry will not be split across * multiple blocks. */ pmp->pm_fatmask = FAT12_MASK; pmp->pm_fatmult = 3; pmp->pm_fatdiv = 2; } else { pmp->pm_fatmask = FAT16_MASK; pmp->pm_fatmult = 2; pmp->pm_fatdiv = 1; } } if (FAT12(pmp)) pmp->pm_fatblocksize = 3 * pmp->pm_BytesPerSec; else pmp->pm_fatblocksize = MAXBSIZE; pmp->pm_fatblocksec = pmp->pm_fatblocksize / pmp->pm_BytesPerSec; pmp->pm_bnshift = ffs(pmp->pm_BytesPerSec) - 1; /* * Compute mask and shift value for isolating cluster relative byte * offsets and cluster numbers from a file offset. */ pmp->pm_bpcluster = SecPerClust * pmp->pm_BytesPerSec; pmp->pm_crbomask = pmp->pm_bpcluster - 1; pmp->pm_cnshift = ffs(pmp->pm_bpcluster) - 1; DPRINTF(("%s(fatmask=%lu, fatmult=%u, fatdiv=%u, fatblocksize=%lu, " "fatblocksec=%lu, bnshift=%lu, pbcluster=%lu, crbomask=%lu, " "cnshift=%lu)\n", __func__, pmp->pm_fatmask, pmp->pm_fatmult, pmp->pm_fatdiv, pmp->pm_fatblocksize, pmp->pm_fatblocksec, pmp->pm_bnshift, pmp->pm_bpcluster, pmp->pm_crbomask, pmp->pm_cnshift)); /* * Check for valid cluster size * must be a power of 2 */ if (pmp->pm_bpcluster ^ (1 << pmp->pm_cnshift)) { DPRINTF(("bpcluster %lu cnshift %lu\n", pmp->pm_bpcluster, pmp->pm_cnshift)); error = EINVAL; goto error_exit; } /* * Release the bootsector buffer. */ brelse(bp, BC_AGE); bp = NULL; /* * Check FSInfo. */ if (pmp->pm_fsinfo) { struct fsinfo *fp; /* * XXX If the fsinfo block is stored on media with * 2KB or larger sectors, is the fsinfo structure * padded at the end or in the middle? */ DPRINTF(("%s(bread %lu)\n", __func__, (unsigned long)de_bn2kb(pmp, pmp->pm_fsinfo))); if ((error = bread(devvp, de_bn2kb(pmp, pmp->pm_fsinfo), pmp->pm_BytesPerSec, NULL, 0, &bp)) != 0) goto error_exit; fp = (struct fsinfo *)bp->b_data; if (!memcmp(fp->fsisig1, "RRaA", 4) && !memcmp(fp->fsisig2, "rrAa", 4) && !memcmp(fp->fsisig3, "\0\0\125\252", 4) && !memcmp(fp->fsisig4, "\0\0\125\252", 4)) pmp->pm_nxtfree = getulong(fp->fsinxtfree); else pmp->pm_fsinfo = 0; brelse(bp, 0); bp = NULL; } /* * Check and validate (or perhaps invalidate?) the fsinfo structure? * XXX */ if (pmp->pm_fsinfo) { if ((pmp->pm_nxtfree == 0xffffffffUL) || (pmp->pm_nxtfree > pmp->pm_maxcluster)) pmp->pm_fsinfo = 0; } /* * Allocate memory for the bitmap of allocated clusters, and then * fill it in. */ pmp->pm_inusemap = ecalloc(sizeof(*pmp->pm_inusemap), ((pmp->pm_maxcluster + N_INUSEBITS) / N_INUSEBITS)); /* * fillinusemap() needs pm_devvp. */ pmp->pm_dev = 0; pmp->pm_devvp = devvp; /* * Have the inuse map filled in. */ if ((error = fillinusemap(pmp)) != 0) { DPRINTF(("fillinusemap %d\n", error)); goto error_exit; } /* * Finish up. */ if (ronly) pmp->pm_flags |= MSDOSFSMNT_RONLY; else pmp->pm_fmod = 1; /* * If we ever do quotas for DOS filesystems this would be a place * to fill in the info in the msdosfsmount structure. You dolt, * quotas on dos filesystems make no sense because files have no * owners on dos filesystems. of course there is some empty space * in the directory entry where we could put uid's and gid's. */ return pmp; error_exit: if (bp) brelse(bp, BC_AGE); if (pmp) { if (pmp->pm_inusemap) free(pmp->pm_inusemap); free(pmp); } errno = error; return pmp; }
/* * Handler for messages sent to the keyboard */ int evtMessage (struct pgEvent * evt) { /* Received command */ struct keyboard_command * cmd; switch (evt->type) { case PG_WE_APPMSG: cmd = (struct keyboard_command *) evt->e.data.pointer; /* Command structure is in network byte order */ cmd->type = ntohs(cmd->type); DPRINTF ("received command: %d\n", cmd->type); if (blocked) { if (cmd->type == PG_KEYBOARD_RELEASE) { blocked = 0; } } else { /* Keyboard's new size */ int newSize = -1; switch (cmd->type) { case PG_KEYBOARD_SHOW: newSize = mpat->app_size; break; case PG_KEYBOARD_HIDE: newSize = 0; break; case PG_KEYBOARD_TOGGLE: newSize = mpat->app_size - pgGetWidget (wApp, PG_WP_SIZE); break; case PG_KEYBOARD_ENABLE: enableKbdCanvas (); enable_status = 1; break; case PG_KEYBOARD_DISABLE: disableKbdCanvas (); enable_status = 0; break; case PG_KEYBOARD_TOGGLE_DISPLAY: enable_status = !enable_status; enable_status ? enableKbdCanvas () : disableKbdCanvas (); break; case PG_KEYBOARD_SELECT_PATTERN: selectPattern (ntohs (cmd->data.pattern)); break; case PG_KEYBOARD_PUSH_CONTEXT: pushKeyboardContext (); break; case PG_KEYBOARD_POP_CONTEXT: popKeyboardContext (); break; case PG_KEYBOARD_BLOCK: blocked = 1; break; case PG_KEYBOARD_RELEASE: /* Nothing */ break; default: DPRINTF ("Unknown command: %d\n", cmd->type); break; } if (newSize >= 0) { pgSetWidget(wApp, PG_WP_SIZE, newSize, 0); } } break; default: /* Ignore */ break; } return 1; }