/* vim:set ts=4 sw=2 et cindent: */ /* This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
nsAuthSambaNTLM::~nsAuthSambaNTLM() { // ntlm_auth reads from stdin regularly so closing our file handles // should cause it to exit.
Shutdown();
PR_Free(mInitialMessage);
}
while (length > 0) {
ssize_t result; do {
result = write(aFD.get(), s, length);
} while (result == -1 && errno == EINTR); if (result <= 0) returnfalse;
s += result;
length -= result;
} returntrue;
}
staticbool ReadLine(const mozilla::UniqueFileHandle& aFD,
nsACString& aString) { // ntlm_auth is defined to only send one line in response to each of our // input lines. So this simple unbuffered strategy works as long as we // read the response immediately after sending one request.
aString.Truncate(); for (;;) { char buf[1024];
ssize_t result; do {
result = read(aFD.get(), buf, sizeof(buf));
} while (result == -1 && errno == EINTR); if (result <= 0) returnfalse;
aString.Append(buf, result); if (buf[result - 1] == '\n') {
LOG(("Read from ntlm_auth: %s", nsPromiseFlatCString(aString).get())); returntrue;
}
}
}
/** * Returns a heap-allocated array of PRUint8s, and stores the length in aLen. * Returns nullptr if there's an error of any kind.
*/ static uint8_t* ExtractMessage(const nsACString& aLine, uint32_t* aLen) { // ntlm_auth sends blobs to us as base64-encoded strings after the "xx " // preamble on the response line.
int32_t length = aLine.Length(); // The caller should verify there is a valid "xx " prefix and the line // is terminated with a \n
NS_ASSERTION(length >= 4, "Line too short..."); constchar* line = aLine.BeginReading(); constchar* s = line + 3;
length -= 4; // lose first 3 chars plus trailing \n
NS_ASSERTION(s[length] == '\n', "aLine not newline-terminated");
if (length & 3) { // The base64 encoded block must be multiple of 4. If not, something // screwed up.
NS_WARNING("Base64 encoded block should be a multiple of 4 chars"); return nullptr;
}
// Calculate the exact length. I wonder why there isn't a function for this // in plbase64.
int32_t numEquals; for (numEquals = 0; numEquals < length; ++numEquals) { if (s[length - 1 - numEquals] != '=') break;
}
*aLen = (length / 4) * 3 - numEquals; returnreinterpret_cast<uint8_t*>(PL_Base64Decode(s, length, nullptr));
}
// Use base::LaunchApp to run the child process. This code is posix-only, as // this will not be used on Windows.
{
mozilla::UniqueFileHandle toChildPipeRead;
mozilla::UniqueFileHandle toChildPipeWrite; if (!CreatePipe(&toChildPipeRead, &toChildPipeWrite)) { return NS_ERROR_FAILURE;
}
if (!WriteString(mToChildFD, "YR\n"_ns)) return NS_ERROR_FAILURE;
nsCString line; if (!ReadLine(mFromChildFD, line)) return NS_ERROR_FAILURE; if (!StringBeginsWith(line, "YR "_ns)) { // Something went wrong. Perhaps no credentials are accessible. return NS_ERROR_FAILURE;
}
// It gave us an initial client-to-server request packet. Save that // because we'll need it later.
mInitialMessage = ExtractMessage(line, &mInitialMessageLen); if (!mInitialMessage) return NS_ERROR_FAILURE; return NS_OK;
}
/* inToken must be a type 2 message. Get ntlm_auth to generate our response */ char* encoded =
PL_Base64Encode(static_cast<constchar*>(inToken), inTokenLen, nullptr); if (!encoded) return NS_ERROR_OUT_OF_MEMORY;
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.