Back to index

lightning-sunbird  0.9+nobinonly
Classes | Defines | Functions | Variables
nsAuthSSPI.cpp File Reference
#include "nsAuthSSPI.h"
#include "nsIServiceManager.h"
#include "nsIDNSService.h"
#include "nsIDNSRecord.h"
#include "nsNetCID.h"
#include "nsCOMPtr.h"

Go to the source code of this file.


class  secBuffers


#define SEC_SUCCESS(Status)   ((Status) >= 0)
#define KERB_WRAP_NO_ENCRYPT   0x80000001
#define MapErrorCode(_rc)   ""


static nsresult InitSSPI ()
static nsresult MakeSN (const char *principal, nsCString &result)


static const char *const pTypeName []
static HINSTANCE sspi_lib
static PSecurityFunctionTable sspi

Define Documentation

#define KERB_WRAP_NO_ENCRYPT   0x80000001

Definition at line 58 of file nsAuthSSPI.cpp.

#define MapErrorCode (   _rc)    ""

Definition at line 100 of file nsAuthSSPI.cpp.

#define SEC_SUCCESS (   Status)    ((Status) >= 0)

Definition at line 55 of file nsAuthSSPI.cpp.

Definition at line 62 of file nsAuthSSPI.cpp.

Definition at line 66 of file nsAuthSSPI.cpp.

Function Documentation

static nsresult InitSSPI ( ) [static]

Definition at line 109 of file nsAuthSSPI.cpp.

    PSecurityFunctionTable (*initFun)(void);

    LOG(("  InitSSPI\n"));

    sspi_lib = LoadLibrary("secur32.dll");
    if (!sspi_lib) {
        sspi_lib = LoadLibrary("security.dll");
        if (!sspi_lib) {
            LOG(("SSPI library not found"));
            return NS_ERROR_UNEXPECTED;

    initFun = (PSecurityFunctionTable (*)(void))
            GetProcAddress(sspi_lib, "InitSecurityInterfaceA");
    if (!initFun) {
        LOG(("InitSecurityInterfaceA not found"));
        return NS_ERROR_UNEXPECTED;

    sspi = initFun();
    if (!sspi) {
        LOG(("InitSecurityInterfaceA failed"));
        return NS_ERROR_UNEXPECTED;

    return NS_OK;
static nsresult MakeSN ( const char *  principal,
nsCString result 
) [static]

Definition at line 143 of file nsAuthSSPI.cpp.

    nsresult rv;

    nsCAutoString buf(principal);

    // The service name looks like "protocol@hostname", we need to map
    // this to a value that SSPI expects.  To be consistent with IE, we
    // need to map '@' to '/' and canonicalize the hostname.
    PRInt32 index = buf.FindChar('@');
    if (index == kNotFound)
        return NS_ERROR_UNEXPECTED;
    nsCOMPtr<nsIDNSService> dns = do_GetService(NS_DNSSERVICE_CONTRACTID, &rv);
    if (NS_FAILED(rv))
        return rv;

    // This could be expensive if our DNS cache cannot satisfy the request.
    // However, we should have at least hit the OS resolver once prior to
    // reaching this code, so provided the OS resolver has this information
    // cached, we should not have to worry about blocking on this function call
    // for very long.  NOTE: because we ask for the canonical hostname, we
    // might end up requiring extra network activity in cases where the OS
    // resolver might not have enough information to satisfy the request from
    // its cache.  This is not an issue in versions of Windows up to WinXP.
    nsCOMPtr<nsIDNSRecord> record;
    rv = dns->Resolve(Substring(buf, index + 1),
    if (NS_FAILED(rv))
        return rv;

    nsCAutoString cname;
    rv = record->GetCanonicalName(cname);
    if (NS_SUCCEEDED(rv)) {
        result = StringHead(buf, index) + NS_LITERAL_CSTRING("/") + cname;
        LOG(("Using SPN of [%s]\n", result.get()));
    return rv;

Here is the call graph for this function:

Variable Documentation

const char* const pTypeName[] [static]
Initial value:

Definition at line 71 of file nsAuthSSPI.cpp.

PSecurityFunctionTable sspi [static]

Definition at line 106 of file nsAuthSSPI.cpp.

HINSTANCE sspi_lib [static]

Definition at line 105 of file nsAuthSSPI.cpp.