void kill_thread_cmd(int argc, char **args, int call_type) { uint32_t pid; uint32_t tid; switch (call_type) { case CALL_TYPE_HELP: puts("KILL A RUNNING THREAD\n"); return; case CALL_TYPE_DESC: puts("pid=PID tid=TID\n"); puts("\tPID\tTHE PROCESS ID OF THE THREAD'S PROCESS\n"); puts("\tTID\tTHE THREAD ID OF THE THREAD\n"); return; } pid = tid = -1; while (argc--) { if (startswith(*args, "pid=")) { pid = atoui(*args + 4); } else if (startswith(*args, "tid=")) { tid = atoui(*args + 4); } args++; } if (pid != -1 && tid != -1) kill_th(pid, tid); else puts("Invalid parameters.\n"); }
/* * Called after getopt() processing is finished if there is a non-empty * match list. Prepares the matching code for use. * * exit: * Returns True (1) if no errors are encountered. Writes an * error string to stderr and returns False (0) otherwise. */ static int match_prepare(char *argv0, uint_t flags) { match_rec_t *list; const char *str; int minus_p = (flags & FLG_SHOW_PHDR) != 0; atoui_type_t atoui_type; /* * Flag ambiguous attempt to use match option with both -p and * and one or more section SHOW options. In this case, we * can't tell what type of item we're supposed to match against. */ if (minus_p && (flags & FLG_MASK_SHOW_SHDR)) { (void) fprintf(stderr, MSG_INTL(MSG_ERR_AMBIG_MATCH), basename(argv0)); return (0); } /* Set the match type, based on the presence of the -p option */ if (minus_p) { match_state.item_type = MATCH_ITEM_PT; atoui_type = ATOUI_PT; } else { match_state.item_type = MATCH_ITEM_SHT; atoui_type = ATOUI_SHT; } /* * Scan match list and perform any necessary fixups: * * MATCH_OPT_NAME: If -p is specified, convert MATCH_OPT_NAME (-N) * requests into MATCH_OPT_TYPE (-T). * * MATCH_OPT_TYPE: Now that we know item type we are matching * against, we can convert the string saved in the name * field during getopt() processing into an integer and * write it into the type field. */ for (list = match_state.list; list; list = list->next) { if ((list->opt_type == MATCH_OPT_NAME) && minus_p) list->opt_type = MATCH_OPT_TYPE; if (list->opt_type != MATCH_OPT_TYPE) continue; str = list->value.name; if (atoui(str, atoui_type, &list->value.type) == 0) { const char *fmt = minus_p ? MSG_INTL(MSG_ERR_BAD_T_PT) : MSG_INTL(MSG_ERR_BAD_T_SHT); (void) fprintf(stderr, fmt, basename(argv0), str); return (0); } } return (1); }
/* Data handler */ static void data(void * d, const char * data, int l) { struct PortMapping * pm; struct PortMappingParserData * pdata = (struct PortMappingParserData *)d; pm = pdata->head.lh_first; if(!pm) return; if(l > 63) l = 63; switch(pdata->curelt) { case NewRemoteHost: memcpy(pm->remoteHost, data, l); pm->remoteHost[l] = '\0'; break; case NewExternalPort: pm->externalPort = (unsigned short)atoui(data, l); break; case NewProtocol: if(l > 3) l = 3; memcpy(pm->protocol, data, l); pm->protocol[l] = '\0'; break; case NewInternalPort: pm->internalPort = (unsigned short)atoui(data, l); break; case NewInternalClient: memcpy(pm->internalClient, data, l); pm->internalClient[l] = '\0'; break; case NewEnabled: pm->enabled = (unsigned char)atoui(data, l); break; case NewDescription: memcpy(pm->description, data, l); pm->description[l] = '\0'; break; case NewLeaseTime: pm->leaseTime = atoui(data, l); break; default: break; } }
/* skip whitespace and compute the following unsigned int, * returns true if one is found and false if not */ static bool get_xpm_file_next_unsigned_int(xpmData *data, unsigned int *ui_return) { char buf[BUFSIZ]; int l; l = get_xpm_file_next_word(data, buf, BUFSIZ); return atoui(buf, l, ui_return); }
static void convert_args(int argc, cmd_args *argv) { int i; for (i = 0; i < argc; i++) { argv[i].u = atoui(argv[i].str); argv[i].i = atoi(argv[i].str); } }
/* * skip whitespace and compute the following unsigned int, * returns 1 if one is found and 0 if not */ int xpmNextUI(xpmData *mdata, unsigned int *ui_return) { char buf[BUFSIZ]; int l; l = xpmNextWord(mdata, buf, BUFSIZ); return atoui(buf, l, ui_return); }
/* * readDatum * * Given a string representation of a constant, recreate the appropriate * Datum. The string representation embeds length info, but not byValue, * so we must be told that. */ static Datum readDatum(bool typbyval) { Size length, i; int tokenLength; char *token; Datum res; char *s; /* * read the actual length of the value */ token = pg_strtok(&tokenLength); length = atoui(token); token = pg_strtok(&tokenLength); /* read the '[' */ if (token == NULL || token[0] != '[') elog(ERROR, "expected \"[\" to start datum, but got \"%s\"; length = %lu", token ? (const char *) token : "[NULL]", (unsigned long) length); if (typbyval) { if (length > (Size) sizeof(Datum)) elog(ERROR, "byval datum but length = %lu", (unsigned long) length); res = (Datum) 0; s = (char *) (&res); for (i = 0; i < (Size) sizeof(Datum); i++) { token = pg_strtok(&tokenLength); s[i] = (char) atoi(token); } } else if (length <= 0) res = (Datum) NULL; else { s = (char *) palloc(length); for (i = 0; i < length; i++) { token = pg_strtok(&tokenLength); s[i] = (char) atoi(token); } res = PointerGetDatum(s); } token = pg_strtok(&tokenLength); /* read the ']' */ if (token == NULL || token[0] != ']') elog(ERROR, "expected \"]\" to end datum, but got \"%s\"; length = %lu", token ? (const char *) token : "[NULL]", (unsigned long) length); return res; }
static void convert_args(int argc, cmd_args *argv) { int i; for (i = 0; i < argc; i++) { argv[i].u = atoui(argv[i].str); argv[i].i = atoi(argv[i].str); if (!strcmp(argv[i].str, "true") || !strcmp(argv[i].str, "on")) { argv[i].b = true; } else if (!strcmp(argv[i].str, "false") || !strcmp(argv[i].str, "off")) { argv[i].b = false; } else { argv[i].b = (argv[i].u == 0) ? false : true; } } }
/* * Handles the HTTP GET command from soap, only the client update install may be downloaded. * * This function can only be called when client_update_enabled is set to yes. * * @note This function is only use for backward compatibility */ int HandleClientUpdate(struct soap *soap) { std::string strPath; int nRet = 404; // default return file not found to soap char *szClientUpdatePath = NULL; char *szCurrentVersion = NULL; char *szReq = NULL; char *szReqEnd = NULL; std::string strLicenseRequest; std::string strLicenseResponse; ECLicenseClient *lpLicenseClient = NULL; unsigned int ulLicenseResponse = 0; unsigned char *lpLicenseResponse = NULL; ECRESULT er = erSuccess; ClientVersion currentVersion = {0}; ClientVersion latestVersion = {0}; std::string strClientMSIName; FILE *fd = NULL; // Get the server.cfg setting szClientUpdatePath = g_lpConfig->GetSetting("client_update_path"); if (!szClientUpdatePath || szClientUpdatePath[0] == 0) { g_lpLogger->Log(EC_LOGLEVEL_ERROR, "Client update: The configuration field 'client_update_path' is empty."); goto exit; } // if the version comes as "/autoupdate/6.20.1.1234?licreq", we need to pass the license request szReq = strrchr(soap->path, '?'); if (szReq != NULL) { // since we have the ?, that's good enough szReq = strstr(soap->buf, "X-License: "); if (szReq == NULL) { g_lpLogger->Log(EC_LOGLEVEL_DEBUG, "Client update: Invalid license request, header not found."); goto exit; } szReq += strlen("X-License: "); szReqEnd = strstr(szReq, "\r\n"); // TODO: can be be split over multiple lines? if (szReqEnd == NULL) { g_lpLogger->Log(EC_LOGLEVEL_DEBUG, "Client update: Invalid license request, end of header not found."); goto exit; } strLicenseRequest = base64_decode(std::string(szReq, szReqEnd - szReq)); lpLicenseClient = new ECLicenseClient(g_lpConfig->GetSetting("license_socket"), atoui(g_lpConfig->GetSetting("license_timeout"))); er = lpLicenseClient->Auth((unsigned char*)strLicenseRequest.c_str(), strLicenseRequest.length(), &lpLicenseResponse, &ulLicenseResponse); if (er != erSuccess) { g_lpLogger->Log(EC_LOGLEVEL_DEBUG, "Client update: Invalid license request, error: 0x%08X.", er); goto exit; } strLicenseResponse = base64_encode(lpLicenseResponse, ulLicenseResponse); soap->http_content = "binary"; soap_response(soap, SOAP_FILE); nRet = soap_send_raw(soap, strLicenseResponse.c_str(), strLicenseResponse.length()); g_lpLogger->Log(EC_LOGLEVEL_DEBUG, "Client update: Processing license request."); goto exit; } // the version comes as "/autoupdate/6.20.1.1234", convert it to "6.20.1.1234" szCurrentVersion = soap->path + strlen("/autoupdate"); if (szCurrentVersion[0] == '/') szCurrentVersion++; if (szCurrentVersion[0] != '\0') { g_lpLogger->Log(EC_LOGLEVEL_INFO, "Client update: The current client version is %s.", szCurrentVersion); if (!GetVersionFromString(szCurrentVersion, ¤tVersion)) { g_lpLogger->Log(EC_LOGLEVEL_INFO, "Client update: Failed in getting version from input data."); goto exit; } } if (!GetLatestVersionAtServer(szClientUpdatePath, 0, &latestVersion)) { g_lpLogger->Log(EC_LOGLEVEL_INFO, "Client update: No updates found on server."); goto exit; } if (szCurrentVersion[0] != '\0') { int res = CompareVersions(currentVersion, latestVersion); if (res == 0) { g_lpLogger->Log(EC_LOGLEVEL_DEBUG, "Client update: Client already has latest version."); goto exit; } else if (res > 0) { g_lpLogger->Log(EC_LOGLEVEL_DEBUG, "Client update: Client has newer version than server."); goto exit; } } if (!GetClientMSINameFromVersion(latestVersion, &strClientMSIName)) { g_lpLogger->Log(EC_LOGLEVEL_INFO, "Client update: No suitable version available."); goto exit; } if (ConvertAndValidatePath(szClientUpdatePath, strClientMSIName, &strPath) != true) { g_lpLogger->Log(EC_LOGLEVEL_INFO, "Client update: Error in path conversion and validation."); goto exit; } fd = fopen(strPath.c_str(), "rb"); if (!fd) { g_lpLogger->Log(EC_LOGLEVEL_ERROR, "Client update: Path not found %s.", strPath.c_str()); goto exit; } g_lpLogger->Log(EC_LOGLEVEL_ERROR, "Client update: Sending client %s new installer %s", PrettyIP(soap->ip).c_str(), strClientMSIName.c_str()); // application/msi-installer ? soap->http_content = "binary"; soap_response(soap, SOAP_FILE); while (true) { // FIXME: tmpbuf is only 1K, good enough? size_t nSize = fread(soap->tmpbuf, 1, sizeof(soap->tmpbuf), fd); if (!nSize) break; if (soap_send_raw(soap, soap->tmpbuf, nSize)) { g_lpLogger->Log(EC_LOGLEVEL_FATAL, "Client update: Error while sending client new installer"); goto exit; } } nRet = SOAP_OK; exit: if (lpLicenseResponse) delete [] lpLicenseResponse; if (lpLicenseClient) delete lpLicenseClient; if (fd) fclose(fd); return nRet; }
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; }
/*++ * Function: IMAP_Line_Read * * Purpose: Line-oriented buffered reads from the imap server * * Parameters: ptr to a IMAPTransactionDescriptor structure * * Returns: Number of bytes on success * -1 on error * * Authors: Dave McMurtrie <*****@*****.**> * * Notes: caller must be certain that the IMAPTransactionDescriptor * is initialized to zero on the first call. * * * Callers must check RemainingLiteralBytes after calling this * function. If this is set and a caller ignores it, it will * play havoc... Actually, it will exit() and kill the entire * process. *-- */ extern int IMAP_Line_Read( ITD_Struct *ITD ) { char *CP; int Status; unsigned int i, j; int rc; char *fn = "IMAP_Line_Read()"; char *EndOfBuffer; /* * Sanity check. This function should never be called if there are * literal bytes remaining to be processed. */ if ( ITD->LiteralBytesRemaining ) { syslog(LOG_ERR, "%s: Sanity check failed! Literal bytestream has not been fully processed (%d bytes remain) and line-oriented read function was called again. Exiting!", fn, ITD->LiteralBytesRemaining); exit(1); } /* Point End to the end of our buffer */ EndOfBuffer = &ITD->ReadBuf[sizeof ITD->ReadBuf - 1]; /* * Shift the contents of our buffer. This will erase any previous * line that we already gave to a caller. */ for ( i = ITD->ReadBytesProcessed, j = 0; i <= ITD->BytesInReadBuffer; i++, j++ ) { ITD->ReadBuf[j] = ITD->ReadBuf[i]; } ITD->BytesInReadBuffer -= ITD->ReadBytesProcessed; ITD->ReadBytesProcessed = 0; for (;;) { /* * If we've been called before, we may already have another line * in the buffer that we can return to the caller. */ CP = (char *)memchr( ITD->ReadBuf, '\n', ITD->BytesInReadBuffer ); if ( CP ) { /* * found a '\n'. Check to see if it's preceded by a '\r' * but make sure we catch the case where '\n' is the first * character sent. If we find this, it could be the result * of a "more data" scenerio. */ if ( CP != ITD->ReadBuf ) { /* reset the moredata flag */ ITD->MoreData = 0; if ( *(CP - 1) == '\r' ) { /* * Set ReadBytesProcessed to the length of the line * we just found. Just subtract the address of the * beginning of the buffer from the address of our * "/n" in the buffer. Always need to add one. */ ITD->ReadBytesProcessed = ( CP - ITD->ReadBuf + 1); /* * As if this isn't already ugly enough, now we have * to check whether this is a line that indicates a * string literal is coming next. How do we know? * If it is, the line will end with {bytecount}. */ if ( ((CP - ITD->ReadBuf + 1) > 2 ) && ( *(CP - 2) == '}' )) { char *LiteralEnd; char *LiteralStart; LiteralStart = NULL; /* * Found a '}' as the last character on the line. * Save it's place and then look for the * beginning '{'. */ LiteralEnd = CP - 2; CP -= 2; for ( ; CP >= ITD->ReadBuf; CP-- ) { if ( *CP == '{' ) { LiteralStart = CP; break; } } if ( LiteralStart ) { /* * We found an opening and closing { } pair. The * thing in between should be a number specifying * a byte count. That would be as much as we needed * to know if it wasn't for the fact that RFC 2088 * allows for a + sign in the literal specification * that has a different meaning when a client is * sending a literal to a server. */ if ( *(LiteralEnd - 1) == '+' ) { ITD->NonSyncLiteral = 1; } else if ( *(LiteralEnd - 1) == '{' ) { /* * This is a {}. No clue why any client * would ever send this, but just pretend * we never saw it. */ return( ITD->ReadBytesProcessed ); } else { ITD->NonSyncLiteral = 0; } /* To grab the number, bump our * starting char pointer forward a byte and temporarily * turn the closing '}' into a NULL. Don't worry about * the potential '+' sign, atoui won't care. */ LiteralStart++; *LiteralEnd = '\0'; rc = atoui( LiteralStart, &ITD->LiteralBytesRemaining ); if ( rc == -1 ) { syslog(LOG_WARNING, "%s: atoui() failed on string '%s'", fn, LiteralStart ); *LiteralEnd = '}'; return(0); } *LiteralEnd = '}'; } } /* * This looks redundant, huh? */ return( ITD->ReadBytesProcessed ); } else { /* * found a '\n' that's not preceded by a '\r'. */ syslog(LOG_WARNING, "%s: Protocol error. Line terminated by LF, not CRLF", fn); return(-1); } } else { /* * We just processed a line that has '\n' as the first * character. This may or may not be a problem. */ if ( ITD->MoreData ) { /* * When we set the MoreData flag, we return 20 bytes fewer * than what's in our buffer. It's possible for that * to send the CR but not the LF back to the caller, * leaving it as the first thing in the buffer now. * we can't be sure that this is the case, but the client * and the server can fight it out if it's not. */ ITD->ReadBytesProcessed = 1; return( ITD->ReadBytesProcessed ); } else { syslog(LOG_WARNING, "%s: Protocol error. Line begins with LF.", fn); return(-1); } } } /* * There weren't any "lines" in our buffer. We need to get more data * from the server. Ultimately, we'll want to call IMAP_Read and * add on to the end of the existing buffer. * * Before we go off and wildly start calling IMAP_Read() we should * really make sure that we have space left in our buffer. If not, * set the "more to come" flag and return what we have to the caller. */ if ( ( sizeof ITD->ReadBuf - ITD->BytesInReadBuffer ) < 1 ) { /* * less than one byte of storage left in our buffer. Return what * we have, but get a little bit tricky -- don't return everything * that we have. The reason for this is because the last thing * in our buffer right now could just happen to be {80 (the * beginning of a string literal specifier). If we just return * this and come back to start reading more, we'll completely miss * the fact that a literal is coming next. If we return all but 20 * bytes of the current buffer, we completely negate that potential * problem. */ ITD->MoreData = 1; CP = EndOfBuffer - 20; /* * Set ReadBytesProcessed to the length of the line * we're gonna return. */ ITD->ReadBytesProcessed = ( CP - ITD->ReadBuf + 1); return( ITD->ReadBytesProcessed ); } Status = IMAP_Read(ITD->conn, &ITD->ReadBuf[ITD->BytesInReadBuffer], (sizeof ITD->ReadBuf - ITD->BytesInReadBuffer ) ); if ( Status == 0 ) { syslog(LOG_WARNING, "%s: connection closed prematurely.", fn); return(-1); } else if ( Status == -1 ) { syslog(LOG_ERR, "%s: IMAP_Read() failed: %s", fn, strerror(errno) ); return(-1); } /* * update the buffer count and head back to the top of the * for loop. */ ITD->BytesInReadBuffer += Status; } }
void moboot_init(const struct app_descriptor *app) { int rv, keys_pressed; unsigned act; menu_entry_t *real_entries[32]; char *ptr; int rc; char path[256]; char *newpath; char *newtitle; char *newname; unsigned xoff, yoff; unsigned ramdisk_mounted, ramdisk_start, ramdisk_size; unsigned i, j; unsigned default_menu_entry = 0; unsigned next_menu_entry = 0; char default_image[256]; char next_image[256]; unsigned default_timeout; unsigned counted_images; unsigned use_next; ssize_t splash_sz; void *splash_ptr = NULL; ssize_t background_sz; void *background_ptr; ssize_t tile_sz; void *tile_ptr; char splash_path[256]; unsigned boot_flags; ssize_t rdmsgsz; char *rdmsg; keys_pressed = 0; display_surface = NULL; entries = real_entries; gfx_trans = 0; gfxconsole_clear(); gfxconsole_setpos(0,0); ramdisk_mounted = 0; atags_get_ramdisk(&ramdisk_start, &ramdisk_size); if (ramdisk_size && ramdisk_start) { ramdisk_init((void*)ramdisk_start, ramdisk_size); if (fs_mount("/ramdisk", "/dev/ramdisk")) { printf("Ramdisk start=%08x size=%08x\n", ramdisk_start, ramdisk_size); printf("Unable to mount /ramdisk\n"); printf("Press SELECT to continue\n"); gpiokeys_wait_select(); } else { ramdisk_mounted = 1; } } if (fs_mount("/boot", "/dev/mmcblk0p13")) { printf("\nUnable to mount /boot, exiting.\n"); while (1) { thread_sleep(20); } } default_timeout = 5; if ((rv = fs_load_file("/boot/moboot.timeout", &default_image, 256)) > 0) { default_image[rv] = 0; if (default_image[rv - 1] == '\n') default_image[rv - 1] = 0; default_timeout = atoui(default_image); } default_image[0] = 0; rv = fs_load_file("/boot/moboot.default", &default_image, 256); if (rv > 0) { default_image[rv] = 0; if (default_image[rv - 1] == '\n') default_image[rv - 1] = 0; } use_next = 0; next_image[0] = 0; rv = fs_load_file("/boot/moboot.next", &next_image, 256); if (rv > 0) { next_image[rv] = 0; if (next_image[rv - 1] == '\n') next_image[rv - 1] = 0; } tile_sz = fs_load_file_mem("/boot/moboot.background.tga", &tile_ptr); background_surface = NULL; tile_surface = NULL; if (tile_sz > 0) { tile_surface = tga_decode(tile_ptr, tile_sz, GFX_FORMAT_RGB_x888); struct display_info disp_info; if (!display_surface) { display_get_info(&disp_info); display_surface = gfx_create_surface_from_display(&disp_info); } background_surface = gfx_create_surface(NULL, display_surface->width, display_surface->height, display_surface->stride, display_surface->format); for (i = 0; i < display_surface->width; i += tile_surface->width) { for (j = 0; j < display_surface->height; j += tile_surface->height) { gfx_surface_blend(background_surface, tile_surface, i, j); } } } num_menu_entries = 0; i = 0; counted_images = 0; while ((rc = fs_dirent("/boot", i, &ptr)) > 0) { sprintf(path, "/boot/%s", ptr); if (strncmp("uImage.", ptr, 7) == 0) { if (strncmp("uImage.moboot", ptr, 13) != 0) { newtitle = malloc(strlen(ptr) - 7 + 5 + 1); sprintf(newtitle, "boot %s", ptr + 7); newpath = malloc(strlen(ptr) + 6 + 1); sprintf(newpath, "/boot/%s", ptr); newname = malloc(strlen(ptr) - 7 + 1); sprintf(newname, "%s", ptr + 7); if (strcmp(default_image, ptr + 7) == 0) { default_menu_entry = num_menu_entries; } if (strcmp(next_image, ptr + 7) == 0) { next_menu_entry = num_menu_entries; use_next = 1; } set_menu_entry(newtitle, BOOT_FS, newpath, newname); counted_images++; } } free(ptr); i++; } if (rc < 0) { dprintf(SPEW, "/boot dirList ERROR rc = %d\n", rc); } i = 0; while ((rc = fs_dirent("/ramdisk/boot", i, &ptr)) > 0) { sprintf(path, "/ramdisk/boot/%s", ptr); if (strncmp("uImage.", ptr, 7) == 0) { if (strncmp("uImage.moboot", ptr, 13) != 0) { newtitle = malloc(strlen(ptr) - 7 + 5 + 1); sprintf(newtitle, "boot %s", ptr + 7); newpath = malloc(strlen(ptr) + 14 + 1); sprintf(newpath, "/ramdisk/boot/%s", ptr); newname = malloc(strlen(ptr) - 7 + 1); sprintf(newname, "%s", ptr + 7); if (strcmp(default_image, ptr + 7) == 0) { default_menu_entry = num_menu_entries; } if (strcmp(next_image, ptr + 7) == 0) { next_menu_entry = num_menu_entries; use_next = 1; } set_menu_entry(newtitle, BOOT_FS, newpath, newname); counted_images++; } } free(ptr); i++; } if (rc < 0) { dprintf(SPEW, "/ramdisk/boot dirList ERROR rc = %d\n", rc); } if (counted_images == 0) { set_menu_entry("boot", BOOT_FS, "/boot/uImage-2.6.35-palm-tenderloin", "default"); } if (gpiokeys_poll(KEY_ALL)) { keys_pressed = 1; printf("\nPlease release key(s)..."); while (1) { thread_sleep(20); if (!gpiokeys_poll(KEY_ALL)) { break; } } } gfx_trans = 0; if (tile_surface) { gfx_trans = 1; } set_menu_entry("boot webOS Recovery", BOOT_RECOVER, "", "recover"); set_menu_entry("reboot", BOOT_REBOOT, "", "reboot"); // set_menu_entry("DFU", BOOT_DFU, "", ""); set_menu_entry("shutdown", BOOT_SHUTDOWN, "", "shutdown"); xoff = (gfxconsole_getwidth() - 16 ) / 2; if (num_menu_entries < 10) { yoff = (gfxconsole_getheight() - 12) / 2; } else { yoff = (gfxconsole_getheight() - (num_menu_entries + 4)) / 2; } #if 0 tgasz = fs_load_file_mem("/boot/moboot.tga", &tgaptr); tga_surface = NULL; if (tgasz > 0) { tga_surface = tga_decode(tgaptr, tgasz, GFX_FORMAT_RGB_x888); struct display_info disp_info; if (!display_surface) { display_get_info(&disp_info); display_surface = gfx_create_surface_from_display(&disp_info); } } #endif while (1) { gfxconsole_clear(); show_background(); if (background_surface) { gfxconsole_setbackground(background_surface); } gfxconsole_settrans(gfx_trans); gfxconsole_setpos(xoff,yoff); if (gfx_trans) { gfxconsole_set_colors(0xffffffff, 0x00000000); printf("moboot %s", MOBOOT_VERSION); gfxconsole_setpos(xoff,yoff); gfxconsole_set_colors(0x00000000, 0x00000000); } else { gfxconsole_set_colors(0x00000000, 0xffffffff); printf("moboot %s", MOBOOT_VERSION); gfxconsole_set_colors(0x00000000, 0x000000ff); } if (!use_next || keys_pressed) { act = moboot_menu(xoff, yoff + 2, entries, default_menu_entry, num_menu_entries, keys_pressed ? 0 : default_timeout); } else { act = next_menu_entry; use_next = 0; } keys_pressed = 1; gfxconsole_setpos(xoff, yoff + 2 + num_menu_entries + 2); boot_flags = BOOTLINUX_NOFLAGS; switch (entries[act]->type) { case BOOT_RECOVER: reboot_device(RESTART_REASON_RECOVER); break; case BOOT_REBOOT: reboot_device(RESTART_REASON_REBOOT); break; case BOOT_DFU: reboot_device(RESTART_REASON_DFU); break; case BOOT_SHUTDOWN: reboot_device(RESTART_REASON_SHUTDOWN); break; case BOOT_FS: gfxconsole_clear(); gfxconsole_settrans(gfx_trans); show_background(); gfxconsole_setpos(0,0); if (gfx_trans) { gfxconsole_set_colors(0x00000000, 0x00000000); } else { gfxconsole_set_colors(0x00000000, 0x000000ff); } printf("Selected: '%s'\n\n", entries[act]->title); printf("Loading '%s'... ", entries[act]->arg); if ((rv = fs_load_file(entries[act]->arg, (void *)SCRATCH_ADDR, SCRATCH_SIZE * 1024 * 1024)) < 0) { printf("FAILED\n"); } else { printf("OK\n"); /* check for verbose boot */ sprintf(splash_path, "/boot/moboot.verbose.%s", entries[act]->name); splash_sz = fs_load_file_mem(splash_path, &splash_ptr); if (splash_sz > 0) { if (strncmp(splash_ptr, "yes", 3) == 0) { boot_flags |= BOOTLINUX_VERBOSE; } } /* check for sercon boot */ sprintf(splash_path, "/boot/moboot.sercon.%s", entries[act]->name); splash_sz = fs_load_file_mem(splash_path, &splash_ptr); if (splash_sz > 0) { if (strncmp(splash_ptr, "yes", 3) == 0) { boot_flags |= BOOTLINUX_SERCON; } } if (splash_ptr) free(splash_ptr); /* check for splash image */ sprintf(splash_path, "/boot/moboot.splash.%s.tga", entries[act]->name); splash_sz = fs_load_file_mem(splash_path, &splash_ptr); splash_surface = NULL; if (splash_sz > 0) { splash_surface = tga_decode(splash_ptr, splash_sz, GFX_FORMAT_RGB_x888); struct display_info disp_info; if (!display_surface) { display_get_info(&disp_info); display_surface = gfx_create_surface_from_display( &disp_info); } } /* do it to it! */ bootlinux_uimage_mem((void *)SCRATCH_ADDR, rv, boot_splash, boot_flags); } gfxconsole_set_colors(0x00000000, 0x00ff0000); printf("\n\nBOOT FAILED!\n\nPress SELECT to continue\n"); gfxconsole_set_colors(0x00000000, 0x000000ff); gpiokeys_wait_select(); break; } } }
void vga_use(const int func) { if (func == 1) { print_raw("Character: "); char * character = scanf(); uint8_t character_i = atoui(character); print_raw("Color: "); char * color = scanf(); uint8_t color_i = atoui(color); print_raw("Position: "); char * position = scanf(); uint8_t position_i = atoui(position); print_raw("Line: "); char * line = scanf(); uint8_t line_i = atoui(line); vga_api.pfunc[0].func_v_8_8_8_8 (character_i, color_i, line_i, position_i); free(character); free(color); free(position); free(line); } else if (func == 2) { print_raw("Character: "); char * character = scanf(); uint8_t character_i = atoui(character); print_raw("Color: "); char * color = scanf(); uint8_t color_i = atoui(color); print_raw("Position: "); char * position = scanf(); uint8_t position_i = atoui(position); print_raw("Line: "); char * line = scanf(); uint8_t line_i = atoui(line); vga_api.pfunc[1].func_v_8_8_8_8 (character_i, color_i, line_i, position_i); free(character); free(color); free(position); free(line); } else if (func == 3) { print_raw("Input output: "); char * text = scanf(); vga_api.pfunc[2].func_v_cp (text); free(text); } else if (func == 4) { print_raw("Input normal output: "); char * text = scanf(); vga_api.pfunc[3].func_v_cp (text); free(text); } else if (func == 5) { print_raw("Input highlighted output: "); char * text = scanf(); vga_api.pfunc[4].func_v_cp (text); free(text); } else if (func == 6) { printf("Clear screen"); vga_api.pfunc[5].func_v (); } else if (func == 7) { printf("Scroll lines"); vga_api.pfunc[6].func_v (); } else if (func == 8) { print_raw("Row number: "); int i = vga_api.pfunc[7].func_i (); printf(itoa(i)); } else if (func == 9) { print_raw("Print line position: "); int i = vga_api.pfunc[8].func_i (); printf(itoa(i)); } else if (func == 10) { print_raw("Position: "); char * position = scanf(); uint8_t position_i = atoui(position); print_raw("Line: "); char * line = scanf(); uint8_t line_i = atoui(line); vga_api.pfunc[9].func_v_i_i (line_i, position_i); free(position); free(line); } else if (func == 11) { printf("Set cursor"); vga_api.pfunc[10].func_v (); } else if (func == 12) { print_raw("Position of cursor: "); char * position = scanf(); uint8_t position_i = atoui(position); print_raw("Line of cursor: "); char * line = scanf(); uint8_t line_i = atoui(line); vga_api.pfunc[11].func_v_i_i (line_i, position_i); free(position); } else if (func == 13) { printf("Enable cursor"); vga_api.pfunc[12].func_v (); } else if (func == 14) { printf("Disable cursor"); vga_api.pfunc[13].func_v (); } }
int main(int argc, char **argv, char **envp) { Elf *elf; int var, fd, wfd = 0; char *wname = NULL; uint_t flags = 0; match_rec_t match_data; int ret; uchar_t osabi; /* * If we're on a 64-bit kernel, try to exec a full 64-bit version of * the binary. If successful, conv_check_native() won't return. */ (void) conv_check_native(argv, envp); /* * Establish locale. */ (void) setlocale(LC_MESSAGES, MSG_ORIG(MSG_STR_EMPTY)); (void) textdomain(MSG_ORIG(MSG_SUNW_OST_SGS)); (void) setvbuf(stdout, NULL, _IOLBF, 0); (void) setvbuf(stderr, NULL, _IOLBF, 0); opterr = 0; while ((var = getopt(argc, argv, MSG_ORIG(MSG_STR_OPTIONS))) != EOF) { switch (var) { case 'C': flags |= FLG_CTL_DEMANGLE; break; case 'c': flags |= FLG_SHOW_SHDR; break; case 'd': flags |= FLG_SHOW_DYNAMIC; break; case 'e': flags |= FLG_SHOW_EHDR; break; case 'G': flags |= FLG_SHOW_GOT; break; case 'g': flags |= FLG_SHOW_GROUP; break; case 'H': flags |= FLG_SHOW_CAP; break; case 'h': flags |= FLG_SHOW_HASH; break; case 'I': if (!process_index_opt(optarg, &match_data)) goto usage_brief; if (!add_match_record(argv[0], &match_data)) return (1); flags |= FLG_CTL_MATCH; break; case 'i': flags |= FLG_SHOW_INTERP; break; case 'k': flags |= FLG_CALC_CHECKSUM; break; case 'l': flags |= FLG_CTL_LONGNAME; break; case 'm': flags |= FLG_SHOW_MOVE; break; case 'N': match_data.opt_type = MATCH_OPT_NAME; match_data.value.name = optarg; if (!add_match_record(argv[0], &match_data)) return (1); flags |= FLG_CTL_MATCH; break; case 'n': flags |= FLG_SHOW_NOTE; break; case 'O': { uint32_t val; /* * osabi is a uchar_t in the ELF header. * Don't accept any value that exceeds * that range. */ if ((atoui(optarg, ATOUI_OSABI, &val) == 0) || (val > 255)) { (void) fprintf(stderr, MSG_INTL(MSG_ERR_BAD_T_OSABI), basename(argv[0]), optarg); return (1); } osabi = val; } flags |= FLG_CTL_OSABI; break; case 'P': flags |= FLG_CTL_FAKESHDR; break; case 'p': flags |= FLG_SHOW_PHDR; break; case 'r': flags |= FLG_SHOW_RELOC; break; case 'S': flags |= FLG_SHOW_SORT; break; case 's': flags |= FLG_SHOW_SYMBOLS; break; case 'T': /* * We can't evaluate the value yet, because * we need to know if -p is used or not in * order to tell if we're seeing section header * or program header types. So, we save the * string in the name field, and then convert * it to a type integer in a following pass. */ match_data.opt_type = MATCH_OPT_TYPE; match_data.value.name = optarg; if (!add_match_record(argv[0], &match_data)) return (1); flags |= FLG_CTL_MATCH; break; case 'u': flags |= FLG_SHOW_UNWIND; break; case 'v': flags |= FLG_SHOW_VERSIONS; break; case 'w': wname = optarg; break; case 'y': flags |= FLG_SHOW_SYMINFO; break; case '?': (void) fprintf(stderr, MSG_INTL(MSG_USAGE_BRIEF), basename(argv[0])); detail_usage(); return (1); default: break; } } /* -p and -w are mutually exclusive. -w only works with sections */ if (((flags & FLG_SHOW_PHDR) != 0) && (wname != NULL)) goto usage_brief; /* If a match argument is present, prepare the match state */ if ((match_state.list != NULL) && (match_prepare(argv[0], flags) == 0)) return (1); /* * Decide what to do if no options specifying something to * show or do are present. * * If there is no -w and no match options, then we will set all * the show flags, causing a full display of everything in the * file that we know how to handle. * * Otherwise, if there is no match list, we generate a usage * error and quit. * * In the case where there is a match list, we go ahead and call * regular() anyway, leaving it to decide what to do. If -w is * present, regular() will use the match list to handle it. * In addition, in the absence of explicit show/calc flags, regular() * will compare the section headers to the match list and use * that to generate the FLG_ bits that will display the information * specified by the match list. */ if ((flags & ~FLG_MASK_CTL) == 0) { if (!wname && (match_state.list == NULL)) flags |= FLG_MASK_SHOW; else if (match_state.list == NULL) goto usage_brief; } /* There needs to be at least 1 filename left following the options */ if ((var = argc - optind) == 0) goto usage_brief; /* * If the -l/-C option is specified, set up the liblddbg.so. */ if (flags & FLG_CTL_LONGNAME) dbg_desc->d_extra |= DBG_E_LONG; if (flags & FLG_CTL_DEMANGLE) dbg_desc->d_extra |= DBG_E_DEMANGLE; /* * If the -w option has indicated an output file open it. It's * arguable whether this option has much use when multiple files are * being processed. * * If wname is non-NULL, we know that -p was not specified, due * to the test above. */ if (wname) { if ((wfd = open(wname, (O_RDWR | O_CREAT | O_TRUNC), 0666)) < 0) { int err = errno; (void) fprintf(stderr, MSG_INTL(MSG_ERR_OPEN), wname, strerror(err)); return (1); } } /* * Open the input file, initialize the elf interface, and * process it. */ ret = 0; for (; (optind < argc) && (ret == 0); optind++) { const char *file = argv[optind]; if ((fd = open(argv[optind], O_RDONLY)) == -1) { int err = errno; (void) fprintf(stderr, MSG_INTL(MSG_ERR_OPEN), file, strerror(err)); continue; } (void) elf_version(EV_CURRENT); if ((elf = elf_begin(fd, ELF_C_READ, NULL)) == NULL) { failure(file, MSG_ORIG(MSG_ELF_BEGIN)); (void) close(fd); continue; } if (var > 1) dbg_print(0, MSG_ORIG(MSG_FMT_NLSTRNL), file); switch (elf_kind(elf)) { case ELF_K_AR: ret = archive(file, fd, elf, flags, wname, wfd, osabi); break; case ELF_K_ELF: ret = decide(file, fd, elf, flags, wname, wfd, osabi); break; default: (void) fprintf(stderr, MSG_INTL(MSG_ERR_BADFILE), file); break; } (void) close(fd); (void) elf_end(elf); } if (wfd) (void) close(wfd); return (ret); usage_brief: /* Control comes here for a simple usage message and exit */ (void) fprintf(stderr, MSG_INTL(MSG_USAGE_BRIEF), basename(argv[0])); return (1); }
ECRESULT ECUserStoreTable::Load() { ECRESULT er = erSuccess; ECListIntIterator i; ECDatabase *lpDatabase = NULL; DB_RESULT lpDBResult = NULL; DB_ROW lpDBRow = NULL; DB_LENGTHS lpDBLength = NULL; std::string strQuery; std::list<unsigned int> lstObjIds; ECUserStore sUserStore; int iRowId; ECUserManagement *lpUserManagement = lpSession->GetUserManagement(); ECSecurity *lpSecurity = lpSession->GetSecurity(); objectdetails_t sUserDetails; GUID sZeroGuid = {0}; objectclass_t objclass; objectdetails_t sDetails; enum cols { USERID = 0, EXTERNID, OBJCLASS, UCOMPANY, STOREGUID, STORETYPE, USERNAME, SCOMPANY, HIERARCHYID, STORESIZE, MODTIME_HI, MODTIME_LO }; er = lpSession->GetDatabase(&lpDatabase); if (er != erSuccess) goto exit; Clear(); /* * The next query will first get the list of all users with their primary store details or NULL if * no primary store was found. Secondly it will get the list of all stores with their owner or NULL * if they're detached. * The most important difference id that the first query will return no store for users without a * primary store, even if they do have an archive store attached, while the second query will * return all stores types. */ strQuery = " SELECT u.id, u.externid, u.objectclass, u.company, s.guid, s.type, s.user_name, s.company, s.hierarchy_id, p.val_longint, m.val_hi, m.val_lo FROM users AS u" " LEFT JOIN stores AS s ON s.user_id=u.id AND s.type=" + stringify(ECSTORE_TYPE_PRIVATE) + " LEFT JOIN hierarchy AS h ON h.id=s.hierarchy_id" " LEFT JOIN properties AS p ON p.hierarchyid=s.hierarchy_id and p.tag=0x0E08 and p.type=0x14" " LEFT JOIN properties AS m ON m.hierarchyid=s.hierarchy_id and m.tag=0x66A2 and m.type=0x40" " UNION" " SELECT u.id, u.externid, u.objectclass, u.company, s.guid, s.type, s.user_name, s.company, s.hierarchy_id, p.val_longint, m.val_hi, m.val_lo FROM users AS u" " RIGHT JOIN stores AS s ON s.user_id=u.id LEFT JOIN hierarchy AS h ON h.id=s.hierarchy_id" " LEFT JOIN properties AS p ON p.hierarchyid=s.hierarchy_id and p.tag=0x0E08 and p.type=0x14" " LEFT JOIN properties AS m ON m.hierarchyid=s.hierarchy_id and m.tag=0x66A2 and m.type=0x40"; er = lpDatabase->DoSelect(strQuery, &lpDBResult); if(er != erSuccess) goto exit; iRowId = 0; while(1) { lpDBRow = lpDatabase->FetchRow(lpDBResult); if(lpDBRow == NULL) break; lpDBLength = lpDatabase->FetchRowLengths(lpDBResult); if (lpDBRow[OBJCLASS]) { objclass = (objectclass_t)atoi(lpDBRow[OBJCLASS]); if (objclass != ACTIVE_USER && objclass != NONACTIVE_USER && objclass != NONACTIVE_ROOM && objclass != NONACTIVE_EQUIPMENT) continue; } if (lpDBRow[USERID]) { sUserStore.ulUserId = atoi(lpDBRow[USERID]); if (sUserStore.ulUserId == ZARAFA_UID_SYSTEM) // everyone already filtered by object type continue; } else { sUserStore.ulUserId = -1; } sUserStore.ulCompanyId = 0; if (lpDBRow[UCOMPANY]) sUserStore.ulCompanyId = atoi(lpDBRow[UCOMPANY]); if (lpDBRow[SCOMPANY]) sUserStore.ulCompanyId = atoi(lpDBRow[SCOMPANY]); // might override from user.company // check if we're admin over this company if (lpSecurity->IsAdminOverUserObject(sUserStore.ulCompanyId) != erSuccess) continue; if (lpDBRow[EXTERNID]) { sUserStore.sExternId.id.assign(lpDBRow[EXTERNID], lpDBLength[EXTERNID]); sUserStore.sExternId.objclass = objclass; } else { sUserStore.sExternId.id.clear(); sUserStore.sExternId.objclass = OBJECTCLASS_UNKNOWN; } sUserStore.strUsername.clear(); // find and override real username if possible if (sUserStore.ulUserId != -1 && lpUserManagement->GetObjectDetails(sUserStore.ulUserId, &sUserDetails) == erSuccess) { if (lpSession->GetSessionManager()->IsDistributedSupported()) { if (sUserDetails.GetPropString(OB_PROP_S_SERVERNAME).compare(lpSession->GetSessionManager()->GetConfig()->GetSetting("server_name")) != 0) continue; // user not on this server } sUserStore.strUsername = sUserDetails.GetPropString(OB_PROP_S_LOGIN); } sUserStore.sGuid = sZeroGuid; if (lpDBRow[STOREGUID]) memcpy(&sUserStore.sGuid, lpDBRow[STOREGUID], lpDBLength[STOREGUID]); if (lpDBRow[STORETYPE]) sUserStore.ulStoreType = atoi(lpDBRow[STORETYPE]); else sUserStore.ulStoreType = ECSTORE_TYPE_PRIVATE; // or invalid value? if (lpDBRow[USERNAME]) sUserStore.strGuessname = lpDBRow[USERNAME]; else sUserStore.strGuessname.clear(); if (sUserStore.ulCompanyId > 0 && lpUserManagement->GetObjectDetails(sUserStore.ulCompanyId, &sDetails) == erSuccess) { sUserStore.strCompanyName = sDetails.GetPropString(OB_PROP_S_LOGIN); } if(lpDBRow[HIERARCHYID]) sUserStore.ulObjId = atoui(lpDBRow[HIERARCHYID]); else sUserStore.ulObjId = 0; sUserStore.tModTime = 0; if(lpDBRow[MODTIME_HI] && lpDBRow[MODTIME_LO]) { FILETIME ft; ft.dwHighDateTime = atoui(lpDBRow[MODTIME_HI]); ft.dwLowDateTime = atoui(lpDBRow[MODTIME_LO]); sUserStore.tModTime = 0; FileTimeToUnixTime(ft, &sUserStore.tModTime); } if(lpDBRow[STORESIZE]) sUserStore.ullStoreSize = atoll(lpDBRow[STORESIZE]); else sUserStore.ullStoreSize = 0; // add to table lstObjIds.push_back(iRowId); // remember details m_mapUserStoreData.insert(std::pair<unsigned int, ECUserStore>(iRowId++, sUserStore)); } LoadRows(&lstObjIds, 0); exit: if (lpDBResult) { lpDatabase->FreeResult(lpDBResult); lpDBResult = NULL; } return er; }
/* * a somewhat fugly pci config space examine/modify command. this should probably * be broken up a bit. */ static int pci_config(int argc, const cmd_args *argv) { pci_location_t loc; pci_config_t config; uint32_t offset; unsigned int i; int ret; if (argc < 5) { return -1; } if (!strcmp(argv[2].str, "dump")) { loc.bus = atoui(argv[3].str); loc.dev_fn = atoui(argv[4].str); for (i=0; i < sizeof(pci_config_t); i++) { ret = pci_read_config_byte(&loc, i, (uint8_t *) &config + i); if (ret != _PCI_SUCCESSFUL) goto error; } printf("Device at %02x:%02x vendor id=%04x device id=%04x\n", loc.bus, loc.dev_fn, config.vendor_id, config.device_id); printf("command=%04x status=%04x pi=%02x sub cls=%02x base cls=%02x\n", config.command, config.status, config.program_interface, config.sub_class, config.base_class); for (i=0; i < 6; i+=2) { printf("bar%d=%08x bar%d=%08x\n", i, config.base_addresses[i], i+1, config.base_addresses[i+1]); } } else if (!strcmp(argv[2].str, "rb") || !strcmp(argv[2].str, "rh") || !strcmp(argv[2].str, "rw")) { if (argc != 6) { return -1; } loc.bus = atoui(argv[3].str); loc.dev_fn = atoui(argv[4].str); offset = atoui(argv[5].str); switch (argv[2].str[1]) { case 'b': { uint8_t value; ret = pci_read_config_byte(&loc, offset, &value); if (ret != _PCI_SUCCESSFUL) goto error; printf("byte at device %02x:%02x config offset %04x: %02x\n", loc.bus, loc.dev_fn, offset, value); } break; case 'h': { uint16_t value; ret = pci_read_config_half(&loc, offset, &value); if (ret != _PCI_SUCCESSFUL) goto error; printf("half at device %02x:%02x config offset %04x: %04x\n", loc.bus, loc.dev_fn, offset, value); } break; case 'w': { uint32_t value; ret = pci_read_config_word(&loc, offset, &value); if (ret != _PCI_SUCCESSFUL) goto error; printf("word at device %02x:%02x config offset %04x: %08x\n", loc.bus, loc.dev_fn, offset, value); } break; } } else if (!strcmp(argv[2].str, "mb") || !strcmp(argv[2].str, "mh") || !strcmp(argv[2].str, "mw")) { if (argc != 7) { return -1; } loc.bus = atoui(argv[3].str); loc.dev_fn = atoui(argv[4].str); offset = atoui(argv[5].str); switch (argv[2].str[1]) { case 'b': { uint8_t value = atoui(argv[6].str); ret = pci_write_config_byte(&loc, offset, value); if (ret != _PCI_SUCCESSFUL) goto error; printf("byte to device %02x:%02x config offset %04x: %02x\n", loc.bus, loc.dev_fn, offset, value); } break; case 'h': { uint16_t value = atoui(argv[6].str); ret = pci_write_config_half(&loc, offset, value); if (ret != _PCI_SUCCESSFUL) goto error; printf("half to device %02x:%02x config offset %04x: %04x\n", loc.bus, loc.dev_fn, offset, value); } break; case 'w': { uint32_t value = atoui(argv[6].str); ret = pci_write_config_word(&loc, offset, value); if (ret != _PCI_SUCCESSFUL) goto error; printf("word to device %02x:%02x config offset %04x: %08x\n", loc.bus, loc.dev_fn, offset, value); } break; } } else { return -1; } return 0; error: printf("Error while reading PCI config space: %02x\n", ret); return -2; }