// // load the SSAGv2 or SSAGv4 DLL based on the SSAG driver version and load the addresses of the imported functions // static bool LoadSSAGIFDll() { bool ok = false; try { unsigned int driverVersion = GetSSAGDriverVersion(); LPCWSTR libname; if (driverVersion == 2) libname = _T("SSAGIFv2.dll"); else if (driverVersion == 4) libname = _T("SSAGIFv4.dll"); else throw ERROR_INFO("unexpected SSAG driver version!"); wxASSERT(s_dllinst == NULL); Debug.AddLine(wxString::Format("Loading SSAG dll %s", libname)); s_dllinst = LoadLibrary(libname); if (s_dllinst == NULL) throw ERROR_INFO("SSAG LoadLibrary failed"); if (!InitProcs(s_dllinst)) throw ERROR_INFO("SSAG failed to load required symbols"); ok = true; } catch (const wxString& msg) { POSSIBLY_UNUSED(msg); if (s_dllinst != NULL) { FreeLibrary(s_dllinst); s_dllinst = NULL; } } return ok; }
int Connect(char* user, char* password, char* host, int port, SftpServerAccountInfo* allServers, int currentServerId) { // are we connected ? if (PsftpWrapper[currentServerId].hDll != NULL) { // we allready have a connection running return SFTP_SUCCESS; } int real_port = 22; char real_host[MAX_CMD_BUFFER]; char real_port_string[MAX_CMD_BUFFER]; SftpServerAccountInfo* current_server = &allServers[currentServerId]; PsftpWrapperType *currect_psftp = &PsftpWrapper[currentServerId]; real_host[0] = '\0'; // ok lets load the DLL and connect to the sftp server InitPsftpWrapperStruct(currentServerId); char dll_2_load[MAX_CMD_BUFFER]; char dll_2_copy[MAX_CMD_BUFFER]; char dll_with_server_id[100]; sprintf(dll_with_server_id, "psftp_%i.dll", currentServerId); GetTempPath(MAX_CMD_BUFFER, dll_2_load); strcat(dll_2_load, dll_with_server_id); GetPsftpDllPath(dll_2_copy); if (!FileExists(dll_2_copy)) { char msg[MAX_CMD_BUFFER]; sprintf(msg, "%s not exists", dll_2_copy); dbg(msg); return SFTP_FAILED; } int fcret = FileCopy(dll_2_copy, dll_2_load); #ifdef _DEBUG currect_psftp->hDll = LoadLibrary(dll_2_copy); #else currect_psftp->hDll = LoadLibrary(dll_2_load); #endif HMODULE dll = currect_psftp->hDll; if (dll == NULL) { char msg[MAX_CMD_BUFFER]; sprintf(msg, "Can't load \"%s\" (code %d)", dll_2_load, fcret); dbg(msg); return SFTP_FAILED; // DLL couldn't be loaded, write a warn message }; currect_psftp->Connect = (PsftpConnectProcType) GetProcAddress(dll, "__map__wcplg_open_sftp_session"); currect_psftp->Disconnect = GetProcAddress(dll, "__map__wcplg_close_sftp_session"); currect_psftp->DoSftp = (PsftpDoSftpProcType) GetProcAddress(dll, "__map__wcplg_do_sftp"); currect_psftp->GetCurrentDirStruct = (PsftpGetCurrentDirStructProcType) GetProcAddress(dll, "__map__wcplg_get_current_dir_struct"); currect_psftp->GetLastErrorMessage = (PsftpGetLastErrorMessageProcType) GetProcAddress(dll, "__map__wcplg_get_last_error_msg"); currect_psftp->InitProgressProc = (PsftpInitProcsProcType) GetProcAddress(dll, "__map__init_Procs"); currect_psftp->SFTP_DLL_FNCT_psftp_memory_hole__stopfen = GetProcAddress(dll, "__map__psftp_memory_hole__stopfen"); currect_psftp->SetSftpServerAccountInfo = (PsftpSetSftpServerAccountInfoProcType) GetProcAddress(dll, "__map__set_Server_config_Struct"); currect_psftp->SetTransferMode = (PsftpSetTransferModeProcType) GetProcAddress(dll, "__map__setTransferMode"); currect_psftp->Disconnected = (PsftpDisconnectedProcType) GetProcAddress(dll, "__map__disconnected"); if (currect_psftp->Connect == NULL || currect_psftp->Disconnect == NULL || currect_psftp->DoSftp == NULL || currect_psftp->GetCurrentDirStruct == NULL || currect_psftp->GetLastErrorMessage == NULL || currect_psftp->InitProgressProc == NULL || currect_psftp->SFTP_DLL_FNCT_psftp_memory_hole__stopfen == NULL || currect_psftp->SetSftpServerAccountInfo == NULL || currect_psftp->SetTransferMode == NULL || currect_psftp->Disconnected == NULL ) { // DLL loaded successfuly, but not all functions could be imported dbg("Can't load all of PSFTP.DLL's functions!"); UnloadPsftpDll(currentServerId); return SFTP_FAILED; } /* DLL-loading and functionsimport successed, now try to connect to server */ InitProcs(gRequestProc, gProgressProc, gPluginNumber, currentServerId); if ((current_server->keyfilename[0]) & (!current_server->dont_ask4_passphrase)) //get passphrase for private key { gRequestProc( gPluginNumber, RT_Password, "Secure FTP: Passphrase for your key", "", current_server->passphrase, MAX_CMD_BUFFER); } currect_psftp->SetSftpServerAccountInfo(*current_server); // Logging char buf_log[MAX_CMD_BUFFER]; strcpy(real_host, host); strcpy(real_port_string, host); trim_host_from_hoststring(real_host); trim_port_from_hoststring(real_port_string); if (strlen(real_port_string) < 1) { real_port = port; } else { real_port = atoi(real_port_string); if (real_port == 0) real_port = port; } if (real_port == 0) real_port = 22; //last check if port set 2 a valid number sprintf(buf_log, "CONNECT \\"); if (gAlreadyConnected) LogProc_(MSGTYPE_DETAILS, buf_log); else { LogProc_(MSGTYPE_CONNECT, buf_log); gAlreadyConnected = true; } sprintf( buf_log, "[%s] (connecting to %s@%s:%i using %s)", current_server->title, user, real_host, real_port, current_server->use_key_auth ? "public key authentication" : "password authentication"); LogProc_(MSGTYPE_DETAILS, buf_log); currect_psftp->SetTransferMode(gDefaultTransferMode); if (currect_psftp->Connect(user, password, real_host, real_port) == 1) { char sftp_cmd[MAX_CMD_BUFFER]; sprintf(sftp_cmd, "pwd"); if (ExecuteCommand(sftp_cmd, current_server->base_dir, currentServerId) != SFTP_SUCCESS) { strcpy(current_server->base_dir, current_server->home_dir); } if (current_server->home_dir != NULL) { if ((strlen(current_server->home_dir) > 0) && (strcmp(current_server->home_dir, ".") != 0)) { sprintf(sftp_cmd, "cd \"%s\"", current_server->home_dir); convert_slash_windows_to_unix(sftp_cmd); if (ExecuteCommand(sftp_cmd, NULL, currentServerId) == SFTP_SUCCESS) { strcpy(current_server->base_dir, current_server->home_dir); } else { sprintf(buf_log, "WARNING: couldn't change to home directory!"); current_server->home_dir[0] = 0; LogProc_(MSGTYPE_DETAILS, buf_log); } } } LogProc_(MSGTYPE_CONNECTCOMPLETE, ""); return SFTP_SUCCESS; } strcpy(buf_log, currect_psftp->GetLastErrorMessage()); if (strcmp(buf_log, "") != 0) LogProc_(MSGTYPE_IMPORTANTERROR, buf_log); //lets look if this is a imported session && use_key_auth=1 - and if this case then change //use_key_auth=0 that the user can give a password if (current_server->is_imported_from_any_datasrc == 1 && current_server->use_key_auth == 1) { current_server->use_key_auth = 0; } UnloadPsftpDll(currentServerId); return SFTP_FAILED; }
int main(int argc, char **argv) { char *whoami = argv[0]; char *dbNamePtr = 0; struct afsconf_cell cellinfo; time_t currentTime; afs_int32 code = 0; afs_uint32 host = ntohl(INADDR_ANY); char clones[MAXHOSTSPERCELL]; struct rx_service *tservice; struct rx_securityClass **securityClasses; afs_int32 numClasses; extern int rx_stackSize; #ifdef AFS_NT40_ENV /* initialize winsock */ if (afs_winsockInit() < 0) { ReportErrorEventAlt(AFSEVT_SVR_WINSOCK_INIT_FAILED, 0, argv[0], 0); fprintf(stderr, "%s: Couldn't initialize winsock.\n", whoami); exit(1); } #endif #ifdef AFS_AIX32_ENV /* * The following signal action for AIX is necessary so that in case of a * crash (i.e. core is generated) we can include the user's data section * in the core dump. Unfortunately, by default, only a partial core is * generated which, in many cases, isn't too useful. */ struct sigaction nsa; sigemptyset(&nsa.sa_mask); nsa.sa_handler = SIG_DFL; nsa.sa_flags = SA_FULLDUMP; sigaction(SIGSEGV, &nsa, NULL); sigaction(SIGABRT, &nsa, NULL); #endif osi_audit_init(); osi_audit(BUDB_StartEvent, 0, AUD_END); initialize_BUDB_error_table(); initializeArgHandler(); /* Initialize dirpaths */ if (!(initAFSDirPath() & AFSDIR_SERVER_PATHS_OK)) { #ifdef AFS_NT40_ENV ReportErrorEventAlt(AFSEVT_SVR_NO_INSTALL_DIR, 0, argv[0], 0); #endif afs_com_err(whoami, errno, "; Unable to obtain AFS server directory."); exit(2); } memset(globalConfPtr, 0, sizeof(*globalConfPtr)); /* set default configuration values */ strcpy(dbDir, AFSDIR_SERVER_DB_DIRPATH); strcat(dbDir, "/"); globalConfPtr->databaseDirectory = dbDir; globalConfPtr->databaseName = DEFAULT_DBPREFIX; strcpy(cellConfDir, AFSDIR_SERVER_ETC_DIRPATH); globalConfPtr->cellConfigdir = cellConfDir; /* open the log file */ /* globalConfPtr->log = fopen(DEFAULT_LOGNAME,"a"); if ( globalConfPtr->log == NULL ) { printf("Can't open log file %s - aborting\n", DEFAULT_LOGNAME); BUDB_EXIT(-1); } */ srandom(1); #ifdef AFS_PTHREAD_ENV SetLogThreadNumProgram( rx_GetThreadNum ); #endif /* process the user supplied args */ helpOption = 1; code = cmd_Dispatch(argc, argv); if (code) ERROR(code); /* exit if there was a help option */ if (helpOption) BUDB_EXIT(0); /* open the log file */ globalConfPtr->log = fopen(AFSDIR_SERVER_BUDBLOG_FILEPATH, "a"); if (globalConfPtr->log == NULL) { printf("Can't open log file %s - aborting\n", AFSDIR_SERVER_BUDBLOG_FILEPATH); BUDB_EXIT(-1); } /* keep log closed so can remove it */ fclose(globalConfPtr->log); /* open the cell's configuration directory */ LogDebug(4, "opening %s\n", globalConfPtr->cellConfigdir); BU_conf = afsconf_Open(globalConfPtr->cellConfigdir); if (BU_conf == 0) { LogError(code, "Failed getting cell info\n"); afs_com_err(whoami, code, "Failed getting cell info"); ERROR(BUDB_NOCELLS); } code = afsconf_GetLocalCell(BU_conf, lcell, sizeof(lcell)); if (code) { LogError(0, "** Can't determine local cell name!\n"); ERROR(code); } if (globalConfPtr->myHost == 0) { /* if user hasn't supplied a list of servers, extract server * list from the cell's database */ LogDebug(1, "Using server list from %s cell database.\n", lcell); code = afsconf_GetExtendedCellInfo (BU_conf, lcell, 0, &cellinfo, clones); code = convert_cell_to_ubik(&cellinfo, &globalConfPtr->myHost, globalConfPtr->serverList); if (code) ERROR(code); } /* initialize audit user check */ osi_audit_set_user_check(BU_conf, BU_IsLocalRealmMatch); /* initialize ubik */ ubik_SetClientSecurityProcs(afsconf_ClientAuth, afsconf_UpToDate, BU_conf); ubik_SetServerSecurityProcs(afsconf_BuildServerSecurityObjects, afsconf_CheckAuth, BU_conf); if (ubik_nBuffers == 0) ubik_nBuffers = 400; LogError(0, "Will allocate %d ubik buffers\n", ubik_nBuffers); asprintf(&dbNamePtr, "%s%s", globalConfPtr->databaseDirectory, globalConfPtr->databaseName); if (dbNamePtr == 0) ERROR(-1); rx_SetRxDeadTime(60); /* 60 seconds inactive before timeout */ if (rxBind) { afs_int32 ccode; if (AFSDIR_SERVER_NETRESTRICT_FILEPATH || AFSDIR_SERVER_NETINFO_FILEPATH) { char reason[1024]; ccode = afsconf_ParseNetFiles(SHostAddrs, NULL, NULL, ADDRSPERSITE, reason, AFSDIR_SERVER_NETINFO_FILEPATH, AFSDIR_SERVER_NETRESTRICT_FILEPATH); } else { ccode = rx_getAllAddr(SHostAddrs, ADDRSPERSITE); } if (ccode == 1) { host = SHostAddrs[0]; rx_InitHost(host, htons(AFSCONF_BUDBPORT)); } } /* Disable jumbograms */ rx_SetNoJumbo(); code = ubik_ServerInitByInfo (globalConfPtr->myHost, htons(AFSCONF_BUDBPORT), &cellinfo, clones, dbNamePtr, /* name prefix */ &BU_dbase); if (code) { LogError(code, "Ubik init failed\n"); afs_com_err(whoami, code, "Ubik init failed"); ERROR(code); } afsconf_BuildServerSecurityObjects(BU_conf, &securityClasses, &numClasses); tservice = rx_NewServiceHost(host, 0, BUDB_SERVICE, "BackupDatabase", securityClasses, numClasses, BUDB_ExecuteRequest); if (tservice == (struct rx_service *)0) { LogError(0, "Could not create backup database rx service\n"); printf("Could not create backup database rx service\n"); BUDB_EXIT(3); } rx_SetMinProcs(tservice, 1); rx_SetMaxProcs(tservice, lwps); rx_SetStackSize(tservice, 10000); /* allow super users to manage RX statistics */ rx_SetRxStatUserOk(BU_rxstat_userok); /* misc. initialization */ /* database dump synchronization */ memset(dumpSyncPtr, 0, sizeof(*dumpSyncPtr)); Lock_Init(&dumpSyncPtr->ds_lock); rx_StartServer(0); /* start handling requests */ code = InitProcs(); if (code) ERROR(code); currentTime = time(0); LogError(0, "Ready to process requests at %s\n", ctime(¤tTime)); rx_ServerProc(NULL); /* donate this LWP */ error_exit: osi_audit(BUDB_FinishEvent, code, AUD_END); return (code); }
K3D_VK_BEGIN SwapChain::SwapChain(Device::Ptr pDevice) : DeviceChild(pDevice), m_ReserveBackBufferCount(0) { InitProcs(); }