void ConnectionRegistry::killOperationsOnAllConnections( bool withPrompt ) const { Prompter prompter( "do you want to kill the current op(s) on the server?" ); mongo::mutex::scoped_lock lk( _mutex ); for( map<string,set<string> >::const_iterator i = _connectionUris.begin(); i != _connectionUris.end(); ++i ) { string errmsg; ConnectionString cs = ConnectionString::parse( i->first, errmsg ); if ( !cs.isValid() ) { continue; } boost::scoped_ptr<DBClientWithCommands> conn( cs.connect( errmsg ) ); if ( !conn ) { continue; } const set<string>& uris = i->second; BSONObj inprog = conn->findOne( "admin.$cmd.sys.inprog", Query() )[ "inprog" ] .embeddedObject().getOwned(); BSONForEach( op, inprog ) { if ( uris.count( op[ "client" ].String() ) ) { if ( !withPrompt || prompter.confirm() ) { conn->findOne( "admin.$cmd.sys.killop", QUERY( "op"<< op[ "opid" ] ) ); } else { return; } } } } }
NS_IMETHODIMP nsDownload::OnStatusChange(nsIWebProgress *aWebProgress, nsIRequest *aRequest, nsresult aStatus, const PRUnichar *aMessage) { if (NS_FAILED(aStatus)) { mDownloadState = FAILED; nsCAutoString path; nsresult rv = GetFilePathUTF8(mTarget, path); if (NS_SUCCEEDED(rv)) mDownloadManager->DownloadEnded(path, aMessage); } if (mDownloadManager->MustUpdateUI()) { nsCOMPtr<nsIDownloadProgressListener> internalListener; mDownloadManager->GetInternalListener(getter_AddRefs(internalListener)); if (internalListener) internalListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage, this); } if (mDialogListener) mDialogListener->OnStatusChange(aWebProgress, aRequest, aStatus, aMessage, this); else { // Need to display error alert ourselves, if an error occurred. if (NS_FAILED(aStatus)) { // Get title for alert. nsXPIDLString title; nsresult rv; nsCOMPtr<nsIStringBundleService> bundleService = do_GetService(NS_STRINGBUNDLE_CONTRACTID, &rv); nsCOMPtr<nsIStringBundle> bundle; if (bundleService) rv = bundleService->CreateBundle(DOWNLOAD_MANAGER_BUNDLE, getter_AddRefs(bundle)); if (bundle) bundle->GetStringFromName(NS_LITERAL_STRING("alertTitle").get(), getter_Copies(title)); // Get Download Manager window, to be parent of alert. nsCOMPtr<nsIWindowMediator> wm = do_GetService(NS_WINDOWMEDIATOR_CONTRACTID, &rv); nsCOMPtr<nsIDOMWindowInternal> dmWindow; if (wm) wm->GetMostRecentWindow(NS_LITERAL_STRING("Download:Manager").get(), getter_AddRefs(dmWindow)); // Show alert. nsCOMPtr<nsIPromptService> prompter(do_GetService(NS_PROMPTSERVICE_CONTRACTID)); if (prompter) prompter->Alert(dmWindow, title, aMessage); } } return NS_OK; }
void ConnectionRegistry::killOperationsOnAllConnections(bool withPrompt) const { Prompter prompter("do you want to kill the current op(s) on the server?"); stdx::lock_guard<stdx::mutex> lk(_mutex); for (map<string, set<string>>::const_iterator i = _connectionUris.begin(); i != _connectionUris.end(); ++i) { auto status = ConnectionString::parse(i->first); if (!status.isOK()) { continue; } const ConnectionString cs(status.getValue()); string errmsg; std::unique_ptr<DBClientWithCommands> conn(cs.connect(errmsg)); if (!conn) { continue; } const set<string>& uris = i->second; BSONObj currentOpRes; conn->runPseudoCommand("admin", "currentOp", "$cmd.sys.inprog", {}, currentOpRes); auto inprog = currentOpRes["inprog"].embeddedObject(); BSONForEach(op, inprog) { if (uris.count(op["client"].String())) { if (!withPrompt || prompter.confirm()) { BSONObjBuilder cmdBob; BSONObj info; cmdBob.append("op", op["opid"]); auto cmdArgs = cmdBob.done(); conn->runPseudoCommand("admin", "killOp", "$cmd.sys.killop", cmdArgs, info); } else { return; } } } } }
int shell(int argc, char *argv[]) { tok_t tok_special_indexes[MAXTOKS]; fprintf(stdout, "Welcome to Shelley v1.0\n...\n"); tok_t *t; /* tokens parsed from input */ int fundex = -1, tok_num = 0, bg = 0; pid_t pid = getpid(), /* get current processes PID */ ppid = getppid(), /* get parents PID */ cpid, tcpid, cpgid; init_shell(); PATH = getToks(getenv("PATH"), &tok_num, tok_special_indexes, &bg); do { t = getToks(s, &tok_num, tok_special_indexes, &bg); /* break the line into tokens */ if (t != NULL) { fundex = lookup(t[0]); /* Is first token a shell literal */ if (fundex >= 0) cmd_table[fundex].fun(&t[1]); else { create_process(t, tok_num, tok_special_indexes, bg); freeToks(t); } } prompter(); } while ((s = freadln(stdin))); return cmd_table[lookup("quit")].fun(&t[1]); }
nsresult nsScriptLoader::ProcessScriptElement(nsIScriptElement *aElement) { // We need a document to evaluate scripts. NS_ENSURE_TRUE(mDocument, NS_ERROR_FAILURE); // Check to see if scripts has been turned off. if (!mEnabled || !mDocument->IsScriptEnabled()) { return NS_ERROR_NOT_AVAILABLE; } NS_ASSERTION(!aElement->IsMalformed(), "Executing malformed script"); // Check that the script is not an eventhandler if (IsScriptEventHandler(aElement)) { return NS_CONTENT_SCRIPT_IS_EVENTHANDLER; } // Script evaluation can also be disabled in the current script // context even though it's enabled in the document. // XXX - still hard-coded for JS here, even though another language // may be specified. Should this check be made *after* we examine // the attributes to locate the script-type? // For now though, if JS is disabled we assume every language is // disabled. // XXX is this different from the mDocument->IsScriptEnabled() call? nsIScriptGlobalObject *globalObject = mDocument->GetScriptGlobalObject(); if (!globalObject) { return NS_ERROR_NOT_AVAILABLE; } nsIScriptContext *context = globalObject->GetScriptContext( nsIProgrammingLanguage::JAVASCRIPT); // If scripts aren't enabled in the current context, there's no // point in going on. if (!context || !context->GetScriptsEnabled()) { return NS_ERROR_NOT_AVAILABLE; } // Default script language is whatever the root content specifies // (which may come from a header or http-meta tag), or if there // is no root content, from the script global object. nsCOMPtr<nsIContent> rootContent = mDocument->GetRootContent(); PRUint32 typeID = rootContent ? rootContent->GetScriptTypeID() : context->GetScriptTypeID(); PRUint32 version = 0; nsAutoString language, type, src; nsresult rv = NS_OK; // Check the type attribute to determine language and version. // If type exists, it trumps the deprecated 'language=' aElement->GetScriptType(type); if (!type.IsEmpty()) { nsCOMPtr<nsIMIMEHeaderParam> mimeHdrParser = do_GetService("@mozilla.org/network/mime-hdrparam;1"); NS_ENSURE_TRUE(mimeHdrParser, NS_ERROR_FAILURE); NS_ConvertUTF16toUTF8 typeAndParams(type); nsAutoString mimeType; rv = mimeHdrParser->GetParameter(typeAndParams, nsnull, EmptyCString(), PR_FALSE, nsnull, mimeType); NS_ENSURE_SUCCESS(rv, rv); // Javascript keeps the fast path, optimized for most-likely type // Table ordered from most to least likely JS MIME types. // See bug 62485, feel free to add <script type="..."> survey data to it, // or to a new bug once 62485 is closed. static const char *jsTypes[] = { "text/javascript", "text/ecmascript", "application/javascript", "application/ecmascript", "application/x-javascript", nsnull }; PRBool isJavaScript = PR_FALSE; for (PRInt32 i = 0; jsTypes[i]; i++) { if (mimeType.LowerCaseEqualsASCII(jsTypes[i])) { isJavaScript = PR_TRUE; break; } } if (isJavaScript) typeID = nsIProgrammingLanguage::JAVASCRIPT; else { // Use the object factory to locate a matching language. nsCOMPtr<nsIScriptRuntime> runtime; rv = NS_GetScriptRuntime(mimeType, getter_AddRefs(runtime)); if (NS_FAILED(rv) || runtime == nsnull) { // Failed to get the explicitly specified language NS_WARNING("Failed to find a scripting language"); typeID = nsIProgrammingLanguage::UNKNOWN; } else typeID = runtime->GetScriptTypeID(); } if (typeID != nsIProgrammingLanguage::UNKNOWN) { // Get the version string, and ensure the language supports it. nsAutoString versionName; rv = mimeHdrParser->GetParameter(typeAndParams, "version", EmptyCString(), PR_FALSE, nsnull, versionName); if (NS_FAILED(rv)) { // no version attribute - version remains 0. if (rv != NS_ERROR_INVALID_ARG) return rv; } else { nsCOMPtr<nsIScriptRuntime> runtime; rv = NS_GetScriptRuntimeByID(typeID, getter_AddRefs(runtime)); if (NS_FAILED(rv)) { NS_ERROR("Failed to locate the language with this ID"); return rv; } rv = runtime->ParseVersion(versionName, &version); if (NS_FAILED(rv)) { NS_WARNING("This script language version is not supported - ignored"); typeID = nsIProgrammingLanguage::UNKNOWN; } } } // Some js specifics yet to be abstracted. if (typeID == nsIProgrammingLanguage::JAVASCRIPT) { nsAutoString value; rv = mimeHdrParser->GetParameter(typeAndParams, "e4x", EmptyCString(), PR_FALSE, nsnull, value); if (NS_FAILED(rv)) { if (rv != NS_ERROR_INVALID_ARG) return rv; } else { if (value.Length() == 1 && value[0] == '1') // This means that we need to set JSOPTION_XML in the JS options. // We re-use our knowledge of the implementation to reuse // JSVERSION_HAS_XML as a safe version flag. // If version has JSVERSION_UNKNOWN (-1), then this is still OK. version |= JSVERSION_HAS_XML; } } } else { // no 'type=' element // "language" is a deprecated attribute of HTML, so we check it only for // HTML script elements. nsCOMPtr<nsIDOMHTMLScriptElement> htmlScriptElement = do_QueryInterface(aElement); if (htmlScriptElement) { htmlScriptElement->GetAttribute(NS_LITERAL_STRING("language"), language); if (!language.IsEmpty()) { if (nsParserUtils::IsJavaScriptLanguage(language, &version)) typeID = nsIProgrammingLanguage::JAVASCRIPT; else typeID = nsIProgrammingLanguage::UNKNOWN; // IE, Opera, etc. do not respect language version, so neither should // we at this late date in the browser wars saga. Note that this change // affects HTML but not XUL or SVG (but note also that XUL has its own // code to check nsParserUtils::IsJavaScriptLanguage -- that's probably // a separate bug, one we may not be able to fix short of XUL2). See // bug 255895 (https://bugzilla.mozilla.org/show_bug.cgi?id=255895). NS_ASSERTION(JSVERSION_DEFAULT == 0, "We rely on all languages having 0 as a version default"); version = 0; } } } // If we don't know the language, we don't know how to evaluate if (typeID == nsIProgrammingLanguage::UNKNOWN) { return NS_ERROR_NOT_AVAILABLE; } // If not from a chrome document (which is always trusted), we need some way // of checking the language is "safe". Currently the only other language // impl is Python, and that is *not* safe in untrusted code - so fixing // this isn't a priority.! // See also similar code in nsXULContentSink.cpp if (typeID != nsIProgrammingLanguage::JAVASCRIPT && !nsContentUtils::IsChromeDoc(mDocument)) { NS_WARNING("Untrusted language called from non-chrome - ignored"); return NS_ERROR_NOT_AVAILABLE; } nsCOMPtr<nsIContent> eltContent(do_QueryInterface(aElement)); eltContent->SetScriptTypeID(typeID); // Create a request object for this script nsRefPtr<nsScriptLoadRequest> request = new nsScriptLoadRequest(aElement, version); NS_ENSURE_TRUE(request, NS_ERROR_OUT_OF_MEMORY); // First check to see if this is an external script nsCOMPtr<nsIURI> scriptURI = aElement->GetScriptURI(); if (scriptURI) { // Check that the containing page is allowed to load this URI. rv = nsContentUtils::GetSecurityManager()-> CheckLoadURIWithPrincipal(mDocument->NodePrincipal(), scriptURI, nsIScriptSecurityManager::ALLOW_CHROME); NS_ENSURE_SUCCESS(rv, rv); // After the security manager, the content-policy stuff gets a veto PRInt16 shouldLoad = nsIContentPolicy::ACCEPT; rv = NS_CheckContentLoadPolicy(nsIContentPolicy::TYPE_SCRIPT, scriptURI, mDocument->NodePrincipal(), aElement, NS_LossyConvertUTF16toASCII(type), nsnull, //extra &shouldLoad, nsContentUtils::GetContentPolicy(), nsContentUtils::GetSecurityManager()); if (NS_FAILED(rv) || NS_CP_REJECTED(shouldLoad)) { if (NS_FAILED(rv) || shouldLoad != nsIContentPolicy::REJECT_TYPE) { return NS_ERROR_CONTENT_BLOCKED; } return NS_ERROR_CONTENT_BLOCKED_SHOW_ALT; } request->mURI = scriptURI; request->mIsInline = PR_FALSE; request->mLoading = PR_TRUE; nsCOMPtr<nsILoadGroup> loadGroup = mDocument->GetDocumentLoadGroup(); nsCOMPtr<nsIStreamLoader> loader; nsCOMPtr<nsPIDOMWindow> window(do_QueryInterface(globalObject)); nsIDocShell *docshell = window->GetDocShell(); nsCOMPtr<nsIInterfaceRequestor> prompter(do_QueryInterface(docshell)); nsCOMPtr<nsIChannel> channel; rv = NS_NewChannel(getter_AddRefs(channel), scriptURI, nsnull, loadGroup, prompter, nsIRequest::LOAD_NORMAL); NS_ENSURE_SUCCESS(rv, rv); nsCOMPtr<nsIHttpChannel> httpChannel(do_QueryInterface(channel)); if (httpChannel) { // HTTP content negotation has little value in this context. httpChannel->SetRequestHeader(NS_LITERAL_CSTRING("Accept"), NS_LITERAL_CSTRING("*/*"), PR_FALSE); httpChannel->SetReferrer(mDocument->GetDocumentURI()); } rv = NS_NewStreamLoader(getter_AddRefs(loader), this); NS_ENSURE_SUCCESS(rv, rv); rv = channel->AsyncOpen(loader, request); NS_ENSURE_SUCCESS(rv, rv); } else { request->mLoading = PR_FALSE; request->mIsInline = PR_TRUE; request->mURI = mDocument->GetDocumentURI(); request->mLineNo = aElement->GetScriptLineNumber(); // If we've got existing pending requests, add ourselves // to this list. if (mPendingRequests.Count() == 0 && ReadyToExecuteScripts() && nsContentUtils::IsSafeToRunScript()) { return ProcessRequest(request); } } // Add the request to our pending requests list NS_ENSURE_TRUE(mPendingRequests.AppendObject(request), NS_ERROR_OUT_OF_MEMORY); // If there weren't any pending requests before, and this one is // ready to execute, do that as soon as it's safe. if (mPendingRequests.Count() == 1 && !request->mLoading && ReadyToExecuteScripts()) { nsContentUtils::AddScriptRunner(new nsRunnableMethod<nsScriptLoader>(this, &nsScriptLoader::ProcessPendingRequests)); } // Added as pending request, now we can send blocking back return NS_ERROR_HTMLPARSER_BLOCK; }
void ConnectionRegistry::killOperationsOnAllConnections(bool withPrompt) const { Prompter prompter("do you want to kill the current op(s) on the server?"); stdx::lock_guard<stdx::mutex> lk(_mutex); for (map<string, set<string>>::const_iterator i = _connectionUris.begin(); i != _connectionUris.end(); ++i) { auto status = ConnectionString::parse(i->first); if (!status.isOK()) { continue; } const ConnectionString cs(status.getValue()); string errmsg; std::unique_ptr<DBClientWithCommands> conn(cs.connect("MongoDB Shell", errmsg)); if (!conn) { continue; } const set<string>& uris = i->second; BSONObj currentOpRes; conn->runPseudoCommand("admin", "currentOp", "$cmd.sys.inprog", {}, currentOpRes); if (!currentOpRes["inprog"].isABSONObj()) { // We don't have permissions (or the call didn't succeed) - go to the next connection. continue; } auto inprog = currentOpRes["inprog"].embeddedObject(); for (const auto op : inprog) { // For sharded clusters, `client_s` is used instead and `client` is not present. string client; if (auto elem = op["client"]) { // mongod currentOp client if (elem.type() != String) { warning() << "Ignoring operation " << op["opid"].toString(false) << "; expected 'client' field in currentOp response to have type " "string, but found " << typeName(elem.type()); continue; } client = elem.str(); } else if (auto elem = op["client_s"]) { // mongos currentOp client if (elem.type() != String) { warning() << "Ignoring operation " << op["opid"].toString(false) << "; expected 'client_s' field in currentOp response to have type " "string, but found " << typeName(elem.type()); continue; } client = elem.str(); } else { // Internal operation, like TTL index. continue; } if (uris.count(client)) { if (!withPrompt || prompter.confirm()) { BSONObjBuilder cmdBob; BSONObj info; cmdBob.appendAs(op["opid"], "op"); auto cmdArgs = cmdBob.done(); conn->runPseudoCommand("admin", "killOp", "$cmd.sys.killop", cmdArgs, info); } else { return; } } } } }