void setnames(const char *fname, const char *cname = 0) { if(!cname) cname = fname; string name, pakname, mapname, cfgname; s_strncpy(name, cname, 100); char *slash = strpbrk(name, "/\\"); if(slash) { s_strncpy(pakname, name, slash-name+1); s_strcpy(cfgname, slash+1); } else { s_strcpy(pakname, "base"); s_strcpy(cfgname, name); }; if(strpbrk(fname, "/\\")) s_strcpy(mapname, fname); else s_sprintf(mapname)("base/%s", fname); s_sprintf(cgzname)("packages/%s.tmf", mapname); if(savebak==1) s_sprintf(bakname)("packages/%s.BAK", mapname); else s_sprintf(bakname)("packages/%s_%d.BAK", mapname, lastmillis); s_sprintf(pcfname)("packages/%s/package.cfg", pakname); s_sprintf(mcfname)("packages/%s/%s.cfg", pakname, cfgname); path(cgzname); path(bakname); };
/* * Perform an string compare as part of a diagnostic test */ NVM_BOOL diag_check_str(const struct diagnostic *p_diagnostic, const NVM_UINT32 indicator, const char *actual, char *expected) { COMMON_LOG_ENTRY(); NVM_BOOL result = 0; // is check excluded by caller if (p_diagnostic->excludes & indicator) { result = 1; } else { // is threshold value specified by caller? for (int i = 0; i < p_diagnostic->overrides_len; i++) { if (p_diagnostic->p_overrides[i].type == indicator) { s_strcpy(expected, p_diagnostic->p_overrides[i].threshold_str, NVM_THRESHOLD_STR_LEN); break; } } // perform check result = (strncmp(expected, actual, NVM_THRESHOLD_STR_LEN) == 0); } return result; }
static char* filterPosTag(const char *posTagStr, s_erc *error) { S_CLR_ERR(error); char *filteredPosTagStr = malloc(sizeof(char) * 10); s_strcpy( filteredPosTagStr, posTagStr, error); s_bool end = FALSE; s_bool firstUpper = FALSE; int i=0; while( !end ) { if( !firstUpper ) { if( isASCIIUpper(filteredPosTagStr[i]) ) firstUpper = TRUE; } else { if( !isASCIIUpper(filteredPosTagStr[i]) ) { filteredPosTagStr[i] = '\0'; end = TRUE; } } i++; if( filteredPosTagStr[i] == '\0' ) end = TRUE; } return filteredPosTagStr; }
bool_t pack_fill_filename(resentry_t *re) { s_strcpy(&(re->filename), re->name); if (re->filename == NULL) return FALSE; return TRUE; }
int s_snprintf(char *str, size_t size, const char *format, ...) { va_list ap; char *formatted = NULL; int formatted_len; errno = 0; va_start(ap, format); formatted = make_message(&formatted_len, format, ap); va_end(ap); if (NULL == formatted) { return (-1); } s_strcpy(str, formatted, size); free(formatted); formatted = NULL; if (formatted_len >= size) { errno = EINVAL; } return (formatted_len); }
CStringBuffer CConsoleClipboard::GetClipboardText() { CStringBuffer tmp; #ifdef OK_SYS_WINDOWS if (!IsClipboardFormatAvailable(_CLIPBOARDTEXTFORMAT)) return tmp; HWND hwnd = GetConsoleWindow(); if ( !hwnd ) return tmp; if (!OpenClipboard(hwnd)) return tmp; HGLOBAL hglb = GetClipboardData(_CLIPBOARDTEXTFORMAT); if (hglb != NULL) { LPTSTR lptstr = (LPTSTR)GlobalLock(hglb); if (lptstr != NULL) { dword tlen = s_strlen(lptstr, INT_MAX); tmp.SetSize(__FILE__LINE__ tlen + 1); s_strcpy(CastMutable(CPointer, tmp.GetString()), tlen + 1, lptstr); GlobalUnlock(hglb); } } CloseClipboard(); #endif #ifdef OK_SYS_UNIX tmp = _clipboardtext; #endif return tmp; }
void mmodel(char *name, int *tex) { mapmodelinfo &mmi = mapmodels.add(); s_strcpy(mmi.name, name); mmi.tex = *tex; mmi.m = NULL; };
bool_t grp_fill_name(resentry_t *re) { s_strcpy(&(re->name), re->filename); s_strupper(re->name); if (is_dos_filename(re->name) == FALSE) { fprintf(stderr, "grp_fill_name: \"%s\" is not DOS filename.\n", re->name); return FALSE; } return TRUE; }
bool_t gob_fill_name(resentry_t *re) { s_strcpy(&(re->name), re->filename); s_strupper(re->name); if (strlen(re->name) + 1 > GOB_ENTRY_NAME_SIZE) { fprintf(stderr, "gob_fill_name: Too long name \"%s\".\n", re->name); return FALSE; } return TRUE; }
bool_t pack_fill_name(resentry_t *re) { s_strcpy(&(re->name), re->filename); if (strlen(re->name) > PACK_ENTRY_NAME_SIZE) { fprintf(stderr, "pack_fill_name: Too long name \"%s\".\n", re->name); return FALSE; } if (re->name == NULL) return FALSE; return TRUE; }
/* Ищет в таблице такой-же путь и если находит, то возвращает его номер, * а если не находит, то добавляет и возвращает номер добавленного пути. * В случае неудачи добавления возвращает -1. */ int32_t dat_add_path(dat_t *dat, const char *path) { uint32_t i; for(i = 0; i < dat->numpaths; i++) { if (strcmp(dat->paths[i].name, path) == 0) return i; } if (dat_set_numpaths(dat, dat->numpaths + 1) == FALSE) return -1; s_strcpy(&(dat->paths[dat->numpaths - 1].name), path); return dat->numpaths - 1; }
void NvmLibrary::examineDeviceFw(const std::string &deviceUid, const std::string path, std::string imageVersion) { LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__); int rc; NVM_UID lib_deviceUid; core::Helper::stringToUid(deviceUid, lib_deviceUid); char lib_path[path.size()]; s_strcpy(lib_path, path.c_str(), path.size()); char lib_imageVersion[imageVersion.size()]; s_strcpy(lib_imageVersion, imageVersion.c_str(), imageVersion.size()); rc = m_lib.examineDeviceFw(lib_deviceUid, lib_path, path.size(), lib_imageVersion, imageVersion.size()); if (rc < 0) { throw core::LibraryException(rc); } }
void NvmLibrary::setPassphrase(const std::string &deviceUid, const std::string oldPassphrase, const std::string newPassphrase) { LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__); int rc; NVM_UID lib_deviceUid; core::Helper::stringToUid(deviceUid, lib_deviceUid); char lib_oldPassphrase[oldPassphrase.size()]; s_strcpy(lib_oldPassphrase, oldPassphrase.c_str(), oldPassphrase.size()); char lib_newPassphrase[newPassphrase.size()]; s_strcpy(lib_newPassphrase, newPassphrase.c_str(), newPassphrase.size()); rc = m_lib.setPassphrase(lib_deviceUid, lib_oldPassphrase, oldPassphrase.size(), lib_newPassphrase, newPassphrase.size()); if (rc < 0) { throw core::LibraryException(rc); } }
void NvmLibrary::saveState(const std::string name) { LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__); int rc; char lib_name[name.size()]; s_strcpy(lib_name, name.c_str(), name.size()); rc = m_lib.saveState(lib_name, name.size()); if (rc < 0) { throw core::LibraryException(rc); } }
void NvmLibrary::gatherSupport(const std::string supportFile) { LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__); int rc; char lib_supportFile[supportFile.size()]; s_strcpy(lib_supportFile, supportFile.c_str(), supportFile.size()); rc = m_lib.gatherSupport(lib_supportFile, supportFile.size()); if (rc < 0) { throw core::LibraryException(rc); } }
void NvmLibrary::addSimulator(const std::string simulator) { LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__); int rc; char lib_simulator[simulator.size()]; s_strcpy(lib_simulator, simulator.c_str(), simulator.size()); rc = m_lib.addSimulator(lib_simulator, simulator.size()); if (rc < 0) { throw core::LibraryException(rc); } }
bool_t dat_fill_name(resentry_t *re) { char *s; s_strcpy(&(re->name), re->filename); if (re->name == NULL) return FALSE; s = re->name; while (*s != '\0') { if (*s == SYS_PATH_DELIM) *s = DAT_PATH_DELIM; s++; } /*strupper(re->name);*/ return TRUE; }
/* * This gets called from int main() when the SCM is starting the service */ bool serviceInit(std::string serviceName) { s_strcpy(g_serviceName, serviceName.c_str(), MAX_SERVICE_NAME); bool result = true; SERVICE_TABLE_ENTRY service_table[] = { {g_serviceName, (LPSERVICE_MAIN_FUNCTION) ServiceMain}, {NULL, NULL} }; if (StartServiceCtrlDispatcher(service_table) == 0) { logStartError("StartServiceCtrlDispatcher start failed."); result = false; } return result; }
void NvmLibrary::loadConfig(const std::string &deviceUid, const std::string file) { LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__); int rc; NVM_UID lib_deviceUid; core::Helper::stringToUid(deviceUid, lib_deviceUid); char lib_file[file.size()]; s_strcpy(lib_file, file.c_str(), file.size()); rc = m_lib.loadConfig(lib_deviceUid, lib_file, file.size()); if (rc < 0) { throw core::LibraryException(rc); } }
void NvmLibrary::unlockDevice(const std::string &deviceUid, const std::string passphrase) { LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__); int rc; NVM_UID lib_deviceUid; core::Helper::stringToUid(deviceUid, lib_deviceUid); char lib_passphrase[passphrase.size()]; s_strcpy(lib_passphrase, passphrase.c_str(), passphrase.size()); rc = m_lib.unlockDevice(lib_deviceUid, lib_passphrase, passphrase.size()); if (rc < 0) { throw core::LibraryException(rc); } }
void NvmLibrary::updateDeviceFw(const std::string &deviceUid, const std::string path, const bool activate, const bool force) { LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__); int rc; NVM_UID lib_deviceUid; core::Helper::stringToUid(deviceUid, lib_deviceUid); char lib_path[path.size()]; s_strcpy(lib_path, path.c_str(), path.size()); rc = m_lib.updateDeviceFw(lib_deviceUid, lib_path, path.size(), activate, force); if (rc < 0) { throw core::LibraryException(rc); } }
bool_t dat_extract_resource(restable_t *rt, uint32_t i) { char *filename; filename = NULL; s_strcpy(&filename, rt->basepath); s_strcat(&filename, rt->entries[i].filename); fseek(rt->file, rt->entries[i].offset, SEEK_SET); if (c_fextract(filename, rt->file, rt->entries[i].size, rt->entries[i].compression == 0x40 ? rt->entries[i].compressed : 0, &comdec_dat) == FALSE) { fprintf(stderr, "dat_unpack_files: Can't extract entry #%u.\n", i); s_free(&filename); return FALSE; } s_free(&filename); return TRUE; }
bool_t dat_to_rt(restable_t *rt, dat_t *dat) { uint32_t i; if (rt_set_number(rt, dat->numfiles) == FALSE) return FALSE; for(i = 0; i < dat->numfiles; i++) { s_strcpy(&(rt->entries[i].name), dat->paths[dat->files[i].path].name); s_strcat(&(rt->entries[i].name), DAT_PATH_SDELIM); s_strcat(&(rt->entries[i].name), dat->files[i].name); rt->entries[i].compression = dat->files[i].compression; rt->entries[i].offset = dat->files[i].offset; rt->entries[i].size = dat->files[i].size; rt->entries[i].compressed = dat->files[i].compressed; if (rt->entries[i].compression == 0x20) rt->entries[i].compressed = rt->entries[i].size; } return TRUE; }
/* * Retrieve the operating system version as a string. */ int get_os_version(char *os_version, const COMMON_SIZE os_version_len) { int rc = COMMON_SUCCESS; if (os_version == NULL || os_version_len == 0) { rc = COMMON_ERR_INVALIDPARAMETER; } else { // get the OS info struct utsname name; if (uname(&name) == -1) { rc = COMMON_ERR_UNKNOWN; } else { s_strcpy(os_version, name.release, os_version_len); } } return rc; }
bool_t dat_add_resource(restable_t *rt, uint32_t i) { char *filename; filename = NULL; rt->entries[i].offset = ftell(rt->file); s_strcpy(&filename, rt->basepath); s_strcat(&filename, rt->entries[i].filename); if (c_fadd(rt->file, filename, &(rt->entries[i].size), &(rt->entries[i].compressed), &comdec_dat, 9) == FALSE) { fprintf(stderr, "dat_add_resource: Can't add entry #%u.\n", i); s_free(&filename); return FALSE; } if (rt->entries[i].compressed != 0) rt->entries[i].compression = 0x40; else rt->entries[i].compression = 0x20; s_free(&filename); return TRUE; }
bool_t dat_from_rt(restable_t *rt, dat_t *dat) { uint32_t i; int32_t j; char *path; if (dat_set_numfiles(dat, rt->number) == FALSE) return FALSE; path = NULL; for(i = 0; i < rt->number; i++) { /* Добавление пути */ s_path(&path, rt->entries[i].name, DAT_PATH_DELIM); s_cut_suffix(&path, path, DAT_PATH_SDELIM); if (strlen(path) == 0) s_strcpy(&path, "."); j = dat_add_path(dat, path); s_free(&path); if (j == -1) return FALSE; dat->paths[j].numfiles++; /* Добавление файла */ s_nameext(&(dat->files[i].name), rt->entries[i].name, DAT_PATH_DELIM); dat->files[i].path = j; dat->files[i].compression = rt->entries[i].compression; dat->files[i].offset = rt->entries[i].offset; dat->files[i].size = rt->entries[i].size; if (dat->files[i].compression == 0x40) dat->files[i].compressed = rt->entries[i].compressed; else dat->files[i].compressed = 0; } return TRUE; }
int ns__getClientUpdate(struct soap *soap, struct clientUpdateInfoRequest sClientUpdateInfo, struct clientUpdateResponse* lpsResponse) { unsigned int er = erSuccess; ClientVersion sCurrentVersion = {0}; ClientVersion sLatestVersion; unsigned int ulLicenseResponse = 0; unsigned char *lpLicenseResponse = NULL; ECLicenseClient *lpLicenseClient = NULL; std::string strClientMSIName; std::string strPath; FILE *fd = NULL; int res; unsigned int ulUserID = 0; ECSession *lpecSession = NULL; ECDatabase *lpDatabase = NULL; std::string strCurVersion; std::string strLatestVersion; std::string strQuery; time_t tNow = 0; char *lpszClientUpdatePath = g_lpConfig->GetSetting("client_update_path"); unsigned int ulLogLevel = atoui(g_lpConfig->GetSetting("client_update_log_level")); if (!parseBool(g_lpConfig->GetSetting("client_update_enabled"))) { // do not set on high loglevel, since by default the client updater is installed, and this will be quite often in your log g_lpLogger->Log(EC_LOGLEVEL_NOTICE, "Client update: trackid: 0x%08X, Config option 'client_update_enabled' has disabled this feature.", sClientUpdateInfo.ulTrackId); er = ZARAFA_E_NO_SUPPORT; goto exit; } // setup soap soap_set_imode(soap, SOAP_IO_KEEPALIVE | SOAP_C_UTFSTRING | SOAP_ENC_ZLIB | SOAP_ENC_MTOM); soap_set_omode(soap, SOAP_IO_KEEPALIVE | SOAP_C_UTFSTRING | SOAP_ENC_ZLIB | SOAP_ENC_MTOM | SOAP_IO_CHUNK); if (!lpszClientUpdatePath || lpszClientUpdatePath[0] == 0) { g_lpLogger->Log(EC_LOGLEVEL_ERROR, "Client update: trackid: 0x%08X, The configuration field 'client_update_path' is empty.", sClientUpdateInfo.ulTrackId); er = ZARAFA_E_NO_ACCESS; goto exit; } er = g_lpSessionManager->CreateSessionInternal(&lpecSession); if(er != erSuccess) goto exit; // Lock the session lpecSession->Lock(); er = lpecSession->GetDatabase(&lpDatabase); if (er != erSuccess) goto exit; //@TODO change loglevel? g_lpLogger->Log(EC_LOGLEVEL_ERROR, "Client update: trackid: 0x%08X, computername: %s, username: %s, clientversion: %s, windowsversion: %s, iplist: %s, soapip: %s", sClientUpdateInfo.ulTrackId, (sClientUpdateInfo.szComputerName) ? sClientUpdateInfo.szComputerName : "-", (sClientUpdateInfo.szUsername) ? sClientUpdateInfo.szUsername : "******", (sClientUpdateInfo.szClientVersion) ? sClientUpdateInfo.szClientVersion : "-", (sClientUpdateInfo.szWindowsVersion) ? sClientUpdateInfo.szWindowsVersion : "-", (sClientUpdateInfo.szClientIPList) ? sClientUpdateInfo.szClientIPList : "-", PrettyIP(soap->ip).c_str() ); if (!sClientUpdateInfo.szComputerName) sClientUpdateInfo.szComputerName = ""; //Client has no name? if(!sClientUpdateInfo.szUsername) { er = ZARAFA_E_NO_ACCESS; g_lpLogger->Log(EC_LOGLEVEL_ERROR, "Client update: trackid: 0x%08X, Client did not send a username", sClientUpdateInfo.ulTrackId); } // validate user name er = lpecSession->GetUserManagement()->SearchObjectAndSync(sClientUpdateInfo.szUsername, 0x01/*EMS_AB_ADDRESS_LOOKUP*/, &ulUserID); if (er != erSuccess) { er = ZARAFA_E_NO_ACCESS; g_lpLogger->Log(EC_LOGLEVEL_ERROR, "Client update: trackid: 0x%08X, unknown username '%s'", sClientUpdateInfo.ulTrackId, sClientUpdateInfo.szUsername); } if(lpecSession->GetUserManagement()->IsInternalObject(ulUserID)) { er = ZARAFA_E_NO_ACCESS; g_lpLogger->Log(EC_LOGLEVEL_ERROR, "Client update: trackid: 0x%08X, Wrong user data. User name '%s' is a reserved user", sClientUpdateInfo.ulTrackId, sClientUpdateInfo.szUsername); goto exit; } // Check if the user connect to the right server, else redirect if (lpecSession->GetSessionManager()->IsDistributedSupported() ) { objectdetails_t sUserDetails; er = lpecSession->GetUserManagement()->GetObjectDetails(ulUserID, &sUserDetails); if (er != erSuccess) goto exit; /* Check if this is the correct server */ string strServerName = sUserDetails.GetPropString(OB_PROP_S_SERVERNAME); if (strServerName.empty()) { g_lpLogger->Log(EC_LOGLEVEL_ERROR, "Client update: trackid: 0x%08X, User '%s' has no default server", sClientUpdateInfo.ulTrackId, sClientUpdateInfo.szUsername); er = ZARAFA_E_NO_ACCESS; goto exit; } if (stricmp(strServerName.c_str(), g_lpSessionManager->GetConfig()->GetSetting("server_name")) != 0) { string strServerPath; er = GetBestServerPath(soap, lpecSession, strServerName, &strServerPath); if (er != erSuccess) goto exit; lpsResponse->lpszServerPath = s_strcpy(soap, strServerPath.c_str());// Server Path must always utf8 (also in 6.40.x) g_lpSessionManager->GetLogger()->Log(EC_LOGLEVEL_INFO, "Client update: trackid: 0x%08X, User '%s' is redirected to '%s'", sClientUpdateInfo.ulTrackId, sClientUpdateInfo.szUsername, lpsResponse->lpszServerPath); g_lpStatsCollector->Increment(SCN_REDIRECT_COUNT, 1); er = ZARAFA_E_UNABLE_TO_COMPLETE; goto exit; } } lpLicenseClient = new ECLicenseClient(g_lpConfig->GetSetting("license_socket"), atoui(g_lpConfig->GetSetting("license_timeout"))); er = lpLicenseClient->Auth(sClientUpdateInfo.sLicenseReq.__ptr, sClientUpdateInfo.sLicenseReq.__size, &lpLicenseResponse, &ulLicenseResponse); if (er != erSuccess) { g_lpLogger->Log(EC_LOGLEVEL_ERROR, "Client update: trackid: 0x%08X, Invalid license request, error: 0x%08X.", sClientUpdateInfo.ulTrackId, er); goto exit; } if (sClientUpdateInfo.szClientVersion == NULL || sClientUpdateInfo.szClientVersion[0] == '\0') { g_lpLogger->Log(EC_LOGLEVEL_INFO, "Client update: trackid: 0x%08X, The client did not sent the current version number.", sClientUpdateInfo.ulTrackId); } else if (!GetVersionFromString(sClientUpdateInfo.szClientVersion, &sCurrentVersion)) { g_lpLogger->Log(EC_LOGLEVEL_ERROR, "Client update: trackid: 0x%08X, Failed in getting version from input data.", sClientUpdateInfo.ulTrackId); goto exit; //@fixme can we give the latest? } if (!GetLatestVersionAtServer(lpszClientUpdatePath, sClientUpdateInfo.ulTrackId, &sLatestVersion)) { g_lpLogger->Log(EC_LOGLEVEL_ERROR, "Client update: trackid: 0x%08X, No updates found on server.", sClientUpdateInfo.ulTrackId); er = ZARAFA_E_NO_ACCESS; goto exit; } res = CompareVersions(sCurrentVersion, sLatestVersion); if (res == 0) { g_lpLogger->Log(EC_LOGLEVEL_INFO, "Client update: trackid: 0x%08X, Client already has the latest version.", sClientUpdateInfo.ulTrackId); goto ok; } else if (res > 0) { g_lpLogger->Log(EC_LOGLEVEL_INFO, "Client update: trackid: 0x%08X, Client has newer version than server.", sClientUpdateInfo.ulTrackId); goto ok; } if (!GetClientMSINameFromVersion(sLatestVersion, &strClientMSIName)) { g_lpLogger->Log(EC_LOGLEVEL_INFO, "Client update: trackid: 0x%08X, No suitable version available.", sClientUpdateInfo.ulTrackId); er = ZARAFA_E_NO_ACCESS; goto exit; } if (ConvertAndValidatePath(lpszClientUpdatePath, strClientMSIName, &strPath) != true) { g_lpLogger->Log(EC_LOGLEVEL_ERROR, "Client update: trackid: 0x%08X, Error in path conversion and validation.", sClientUpdateInfo.ulTrackId); er = ZARAFA_E_NO_ACCESS; goto exit; } fd = fopen(strPath.c_str(), "rb"); if (!fd) { g_lpLogger->Log(EC_LOGLEVEL_ERROR, "Client update: trackid: 0x%08X, Path not found %s.", sClientUpdateInfo.ulTrackId, strPath.c_str()); er = ZARAFA_E_NO_ACCESS; goto exit; } // Update auto update client status VersionToString(sCurrentVersion, &strCurVersion); VersionToString(sLatestVersion, &strLatestVersion); tNow = time(NULL); // Get current time strQuery = "REPLACE INTO clientupdatestatus(userid, trackid, updatetime, currentversion, latestversion, computername, status) VALUES ("+ stringify(ulUserID)+", "+stringify(sClientUpdateInfo.ulTrackId)+", FROM_UNIXTIME("+ stringify(tNow) + "), \"" + strCurVersion + "\", \"" + strLatestVersion + "\", \"" + lpDatabase->Escape(sClientUpdateInfo.szComputerName).c_str()+"\", "+ stringify(UPDATE_STATUS_PENDING) + ")"; // ignore error in database tracking, SQL error logged in server, still send new client lpDatabase->DoUpdate(strQuery); soap->fmimereadopen = &mime_file_read_open; soap->fmimeread = &mime_file_read; soap->fmimereadclose = &mime_file_read_close; // Setup the MTOM Attachments lpsResponse->sStreamData.xop__Include.__ptr = (unsigned char*)fd; lpsResponse->sStreamData.xop__Include.__size = 0; lpsResponse->sStreamData.xop__Include.type = s_strcpy(soap, "application/binary"); lpsResponse->sStreamData.xop__Include.id = s_strcpy(soap, "zarafaclient"); g_lpLogger->Log(EC_LOGLEVEL_ERROR, "Client update: trackid: 0x%08X, Sending new installer %s", sClientUpdateInfo.ulTrackId, strClientMSIName.c_str()); ok: // Client is already up to date lpsResponse->sLicenseResponse.__size = ulLicenseResponse; lpsResponse->sLicenseResponse.__ptr = (unsigned char *)s_memcpy(soap, (const char *)lpLicenseResponse, ulLicenseResponse); lpsResponse->ulLogLevel = ulLogLevel; // 0 = none, 1 = on errors, 2 = always exit: if(lpecSession) { lpecSession->Unlock(); g_lpSessionManager->RemoveSessionInternal(lpecSession); } lpsResponse->er = er; if (lpLicenseResponse) delete [] lpLicenseResponse; if (lpLicenseClient) delete lpLicenseClient; if (er && fd) fclose(fd); return SOAP_OK; }
/* * Check for namespace health transitions */ void monitor::EventMonitor::monitorNamespaces(PersistentStore *pStore) { LogEnterExit logging(__FUNCTION__, __FILE__, __LINE__); if (pStore) { // get namespaces int nsCount = nvm_get_namespace_count(); if (nsCount < 0) { COMMON_LOG_ERROR_F("nvm_get_namespace_count failed with error %d", nsCount); } else if (nsCount > 0) { struct namespace_discovery namespaces[nsCount]; memset(namespaces, 0, sizeof (struct namespace_discovery) * nsCount); nsCount = nvm_get_namespaces(namespaces, nsCount); if (nsCount < 0) { COMMON_LOG_ERROR_F("nvm_get_namespaces failed with error %d", nsCount); } else if (nsCount > 0) { // for each namespace for (int i = 0; i < nsCount; i++) { struct namespace_details details; memset(&details, 0, sizeof (details)); NVM_UID uidStr; uid_copy(namespaces[i].namespace_uid, uidStr); int rc = nvm_get_namespace_details(namespaces[i].namespace_uid, &details); if (rc != NVM_SUCCESS) { COMMON_LOG_ERROR_F("nvm_get_namespace_details for namespace %s failed with error %d", uidStr, rc); } else { // get the stored state for this namespace bool storedStateChanged = false; struct db_namespace_state storedState; memset(&storedState, 0, sizeof (storedState)); if (db_get_namespace_state_by_namespace_uid(pStore, uidStr, &storedState) != DB_SUCCESS) { // initial state, just store current state s_strcpy(storedState.namespace_uid, uidStr, NAMESPACE_STATE_NAMESPACE_UID_LEN); storedState.health_state = details.health; storedStateChanged = true; } // log health transition event else if (details.health != storedState.health_state) { enum event_severity severity = EVENT_SEVERITY_INFO; bool actionRequired = false; // namespace is failed if (details.health == NAMESPACE_HEALTH_CRITICAL || details.health == NAMESPACE_HEALTH_BROKENMIRROR) { severity = EVENT_SEVERITY_CRITICAL; actionRequired = true; } // namespace is not failed else { // auto-acknowledge any old namespace health failed events acknowledgeEvent(EVENT_CODE_HEALTH_NAMESPACE_HEALTH_STATE_CHANGED, namespaces[i].namespace_uid); } std::string oldState = namespaceHealthToStr( (enum namespace_health)storedState.health_state); std::string newState = namespaceHealthToStr(details.health); store_event_by_parts( EVENT_TYPE_HEALTH, severity, EVENT_CODE_HEALTH_NAMESPACE_HEALTH_STATE_CHANGED, namespaces[i].namespace_uid, actionRequired, uidStr, oldState.c_str(), newState.c_str(), DIAGNOSTIC_RESULT_UNKNOWN); storedStateChanged = true; storedState.health_state = details.health; if (db_delete_namespace_state_by_namespace_uid(pStore, uidStr) != DB_SUCCESS) { COMMON_LOG_ERROR_F( "Failed to clean up the stored health state for namespace %s", uidStr); } } if (storedStateChanged) { if (db_add_namespace_state(pStore, &storedState) != DB_SUCCESS) { COMMON_LOG_ERROR_F( "Failed to update the stored health state for namespace %s", uidStr); } } } // end nvm_get_namespace_details } // end for each namespace } // end nvm_get_namespaces } // end nvm_get_namespace_count } // end get peristent store }
ECRESULT ECUserStoreTable::QueryRowData(ECGenericObjectTable *lpThis, struct soap *soap, ECSession *lpSession, ECObjectTableList* lpRowList, struct propTagArray *lpsPropTagArray, void* lpObjectData, struct rowSet **lppRowSet, bool bCacheTableData, bool bTableLimit) { ECRESULT er = erSuccess; ECUserStoreTable *pThis = dynamic_cast<ECUserStoreTable*>(lpThis); struct rowSet *lpsRowSet = NULL; ECObjectTableList::iterator iterRowList; int i, k; GUID sZeroGuid = {0}; if (!lpThis) { er = ZARAFA_E_INVALID_PARAMETER; goto exit; } lpsRowSet = s_alloc<rowSet>(soap); lpsRowSet->__size = 0; lpsRowSet->__ptr = NULL; if(lpRowList->empty()) { *lppRowSet = lpsRowSet; goto exit; // success } // We return a square array with all the values lpsRowSet->__size = lpRowList->size(); lpsRowSet->__ptr = s_alloc<propValArray>(soap, lpsRowSet->__size); memset(lpsRowSet->__ptr, 0, sizeof(propValArray) * lpsRowSet->__size); // Allocate memory for all rows for (i = 0; i < lpsRowSet->__size; i++) { lpsRowSet->__ptr[i].__size = lpsPropTagArray->__size; lpsRowSet->__ptr[i].__ptr = s_alloc<propVal>(soap, lpsPropTagArray->__size); memset(lpsRowSet->__ptr[i].__ptr, 0, sizeof(propVal) * lpsPropTagArray->__size); } for (i = 0, iterRowList = lpRowList->begin(); iterRowList != lpRowList->end(); iterRowList++, i++) { for (k = 0; k < lpsPropTagArray->__size; k++) { lpsRowSet->__ptr[i].__ptr[k].ulPropTag = PROP_TAG(PT_ERROR, lpsPropTagArray->__ptr[k]); lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_ul; lpsRowSet->__ptr[i].__ptr[k].Value.ul = ZARAFA_E_NOT_FOUND; switch (PROP_ID(lpsPropTagArray->__ptr[k])) { case PROP_ID(PR_INSTANCE_KEY): // generate key lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_bin; lpsRowSet->__ptr[i].__ptr[k].ulPropTag = PR_INSTANCE_KEY; lpsRowSet->__ptr[i].__ptr[k].Value.bin = s_alloc<xsd__base64Binary>(soap); lpsRowSet->__ptr[i].__ptr[k].Value.bin->__size = sizeof(sObjectTableKey); lpsRowSet->__ptr[i].__ptr[k].Value.bin->__ptr = s_alloc<unsigned char>(soap, sizeof(sObjectTableKey)); memcpy(lpsRowSet->__ptr[i].__ptr[k].Value.bin->__ptr, (void*)&(*iterRowList), sizeof(sObjectTableKey)); break; case PROP_ID(PR_EC_USERNAME): if (!pThis->m_mapUserStoreData[iterRowList->ulObjId].strUsername.empty()) { lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k]; lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_lpszA; lpsRowSet->__ptr[i].__ptr[k].Value.lpszA = s_strcpy(soap, (char*)pThis->m_mapUserStoreData[iterRowList->ulObjId].strUsername.c_str()); } break; case PROP_ID(PR_DISPLAY_NAME): if (!pThis->m_mapUserStoreData[iterRowList->ulObjId].strGuessname.empty()) { lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k]; lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_lpszA; lpsRowSet->__ptr[i].__ptr[k].Value.lpszA = s_strcpy(soap, (char*)pThis->m_mapUserStoreData[iterRowList->ulObjId].strGuessname.c_str()); } break; case PROP_ID(PR_EC_STOREGUID): if (pThis->m_mapUserStoreData[iterRowList->ulObjId].sGuid != sZeroGuid) { lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k]; lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_bin; lpsRowSet->__ptr[i].__ptr[k].Value.bin = s_alloc<xsd__base64Binary>(soap); lpsRowSet->__ptr[i].__ptr[k].Value.bin->__size = sizeof(GUID); lpsRowSet->__ptr[i].__ptr[k].Value.bin->__ptr = s_alloc<unsigned char>(soap, sizeof(GUID)); memcpy(lpsRowSet->__ptr[i].__ptr[k].Value.bin->__ptr, (unsigned char*)&pThis->m_mapUserStoreData[iterRowList->ulObjId].sGuid, sizeof(GUID)); } break; case PROP_ID(PR_EC_STORETYPE): lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k]; lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_ul; lpsRowSet->__ptr[i].__ptr[k].Value.ul = pThis->m_mapUserStoreData[iterRowList->ulObjId].ulStoreType; break; case PROP_ID(PR_EC_COMPANYID): if (pThis->m_mapUserStoreData[iterRowList->ulObjId].ulCompanyId != 0) { lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k]; lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_ul; lpsRowSet->__ptr[i].__ptr[k].Value.ul = pThis->m_mapUserStoreData[iterRowList->ulObjId].ulCompanyId; } break; case PROP_ID(PR_EC_COMPANY_NAME): if (!pThis->m_mapUserStoreData[iterRowList->ulObjId].strCompanyName.empty()) { lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k]; lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_lpszA; lpsRowSet->__ptr[i].__ptr[k].Value.lpszA = s_strcpy(soap, (char*)pThis->m_mapUserStoreData[iterRowList->ulObjId].strCompanyName.c_str()); } break; case PROP_ID(PR_STORE_ENTRYID): // ignore errors ECGenProps::GetPropComputedUncached(soap, NULL ,lpSession, PR_STORE_ENTRYID, pThis->m_mapUserStoreData[iterRowList->ulObjId].ulObjId, 0, pThis->m_mapUserStoreData[iterRowList->ulObjId].ulObjId, 0, MAPI_STORE, &lpsRowSet->__ptr[i].__ptr[k]); break; case PROP_ID(PR_LAST_MODIFICATION_TIME): if (pThis->m_mapUserStoreData[iterRowList->ulObjId].tModTime != 0) { FILETIME ftTmp; UnixTimeToFileTime(pThis->m_mapUserStoreData[iterRowList->ulObjId].tModTime, &ftTmp); lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k]; lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_hilo; lpsRowSet->__ptr[i].__ptr[k].Value.hilo = s_alloc<struct hiloLong>(soap); lpsRowSet->__ptr[i].__ptr[k].Value.hilo->hi = ftTmp.dwHighDateTime; lpsRowSet->__ptr[i].__ptr[k].Value.hilo->lo = ftTmp.dwLowDateTime; } break; case PROP_ID(PR_MESSAGE_SIZE_EXTENDED): lpsRowSet->__ptr[i].__ptr[k].ulPropTag = lpsPropTagArray->__ptr[k]; lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_li; lpsRowSet->__ptr[i].__ptr[k].Value.li = pThis->m_mapUserStoreData[iterRowList->ulObjId].ullStoreSize; break; default: lpsRowSet->__ptr[i].__ptr[k].ulPropTag = PROP_TAG(PT_ERROR, lpsPropTagArray->__ptr[k]); lpsRowSet->__ptr[i].__ptr[k].__union = SOAP_UNION_propValData_ul; lpsRowSet->__ptr[i].__ptr[k].Value.ul = ZARAFA_E_NOT_FOUND; break; }; } } *lppRowSet = lpsRowSet; exit: return er; }
/* wrapper for dlopen */ S_API void *s_win32_dll_open(const char *filename, s_erc *error) { HMODULE dso_handle; UINT em; DWORD last_error; char errstr[65535]; char buf[S_MAX_PATH_LENGTH]; char *p; S_CLR_ERR(error); em = SetErrorMode(SEM_FAILCRITICALERRORS); SetLastError(0); if (filename == NULL) { dso_handle = GetModuleHandle( NULL ); if (dso_handle == NULL) { last_error = GetLastError(); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, last_error, 0, errstr, sizeof(errstr), NULL); S_CTX_ERR(error, S_FAILURE, "s_win32_dll_open", "Failed to open dso \"NULL\". Reported error \"%s\"", errstr); SetLastError(0); SetErrorMode(em); return NULL; } SetLastError(0); SetErrorMode(em); return dso_handle; } s_strcpy(buf, filename, error); if (S_CHK_ERR(error, S_CONTERR, "s_win32_dll_open", "Call to \"s_strcpy\" failed")) { SetLastError(0); SetErrorMode(em); return NULL; } for (p = buf; *p != '\0'; p++) { if (*p == '/') { *p = '\\'; } } dso_handle = LoadLibraryEx((LPSTR)buf, NULL, LOAD_WITH_ALTERED_SEARCH_PATH); if (dso_handle == NULL) { last_error = GetLastError(); FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, last_error, 0, errstr, sizeof(errstr), NULL); S_CTX_ERR(error, S_FAILURE, "s_win32_dll_open", "Failed to open dso at \'%s\'. Reported error \"%s\"", filename, errstr); } SetLastError(0); SetErrorMode(em); return (void*)dso_handle; }