NTLM authentication problem

Bharat Lalcheta bharatlalcheta at gmail.com
Thu May 3 02:04:02 EDT 2012


Hii,

I am trying to connect with microsoft exchange server for calendar
information using neon library.

I am using ubuntu 11.10 and neon 0.29.6.

I am using NE_AUTH_NTLM currently and when trying to authenticate, i am
getting following messages.

ah_post_send (#0), code is 401 (want 401), WWW-Authenticate is Negotiate,
NTLM
auth: Got challenge (code 401).
auth: Got 'Negotiate' challenge.
auth: Trying Negotiate challenge...
auth: No challenges accepted.

When i dispatch request, i am getting following error.

An error occurred
Could not authenticate to server: ignored NTLM challenge

If i use NE_AUTH_NEGOTIATE, i am getting following error on dispatch
request.

An error occurred
Could not authenticate to server: ignored NTLM challenge, GSSAPI
authentication error: Unspecified GSS failure.  Minor code may provide more
information: Credentials cache file '/tmp/krb5cc_1000' not found


==================================================================
*Following is my code.*

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include </usr/include/neon/ne_private.h>
#include </usr/include/neon/ne_socket.h>
#include </usr/include/neon/ne_session.h>
#include </usr/include/neon/ne_request.h>
#include </usr/include/neon/ne_auth.h>

enum xml_op {
        XML_OP_FIND = 100,
        XML_OP_GET,
        XML_OP_CREATE,
};



typedef struct
{
const int challenge_issued;
} user_data;

/*
* Response reader callback function
*
*/
void my_response_reader(void *userdata, const char *buf, size_t len)
{
    printf("Received: %s\n", buf);
}

/*
* Authentication callback
*/

static int my_auth(void *userdata, const char *realm, int attempts, char
*username, char *password)
{
    strncpy(username, "myusername", NE_ABUFSIZ);
    strncpy(password, "mypassword", NE_ABUFSIZ);
    user_data* data = (user_data*)userdata;
    return attempts;
}

static int ssl_verify(void *userdata, int failures, const
ne_ssl_certificate *cert)
{
        if (failures & NE_SSL_UNTRUSTED) {
                printf("Untrusted SSL certificate \n");
                return 0;
        }
        return 1;       /* NE_SSL_NOTYETVALID, NE_SSL_EXPIRED,
NE_SSL_IDMISMATCH */
}

static const char *get_soap_action(enum xml_op op)
{
        switch (op) {
        case XML_OP_FIND:
                return "\"
http://schemas.microsoft.com/exchange/services/2006/messages/FindItem\"";
        case XML_OP_GET:
                return "\"
http://schemas.microsoft.com/exchange/services/2006/messages/GetItem\"";
        case XML_OP_CREATE:
                return "\"
http://schemas.microsoft.com/exchange/services/2006/messages/CreateItem\"";
        }

        return "";
}



int main(int argc, char* argv[])
{
    user_data data;
    int success = ne_sock_init();
    char dropbuf[4096];
    char buf[4096];
    struct xml_context *ctx;
    if (success != 0) {
        printf("Cannot initialize Neon library");
        exit(1);
    }

    ne_session* session = ne_session_create("https",
"www.mydomain.com<http://ex1.domain.com>",
443);
    ne_add_server_auth(session, NE_AUTH_NTLM, my_auth, (void*)&data);

    ne_ssl_trust_default_ca(session);
    ne_ssl_set_verify(session, ssl_verify,(void*)&data);

    ne_request *req = ne_request_create(session, "POST",
"/EWS/Exchange.asmx");
    ne_add_request_header(req, "Content-Type", "text/xml; charset=utf-8");
    ne_add_request_header(req, "SOAPAction", "\"
http://schemas.microsoft.com/exchange/services/2006/messages/FindItem\"");

    strcpy(buf,"<SOAP-ENV:Envelope xmlns:SOAP-ENV=\"
http://schemas.xmlsoap.org/soap/envelope/\""
        "xmlns:ns1=\"
http://schemas.microsoft.com/exchange/services/2006/types\""
                "xmlns:ns1=\"
http://schemas.microsoft.com/exchange/services/2006/types\" "
                "xmlns:ns2=\"
http://schemas.microsoft.com/exchange/services/2006/messages\">"
                        "<SOAP-ENV:Body>"
                                "<ns2:FindItem Traversal=\"Shallow\">"
                                        "<ns2:ItemShape>"

"<ns1:BaseShape>IdOnly</ns1:BaseShape>"
                                        "</ns2:ItemShape>"
                                        "<ns2:CalendarView
StartDate=\"2012-05-03T05:00:52Z\" EndDate=\"2012-05-03T06:00:52Z\"/>"
                                        "<ns2:ParentFolderIds>"
                                                "<ns1:DistinguishedFolderId
Id=\"calendar\"/>"
                                        "</ns2:ParentFolderIds>"
                                "</ns2:FindItem>"
                        "</SOAP-ENV:Body>"
                "</SOAP-ENV:Envelope>");



    ne_set_request_body_buffer(req, buf, strlen(buf));

    ne_debug_init(stdout, NE_DBG_HTTPAUTH);

    if (ne_request_dispatch(req))
    {
        printf("An error occurred\n");
        const char* error = ne_get_error(session);
        printf("%s\n", error);
        exit(1);
    }
    else
    {
        printf("Response status code was %d\n", ne_get_status(req)->code);
        ne_request_destroy(req);
    }

    ne_close_connection(session);
    ne_session_destroy(session);
    return 0;
}

==================================================================

Please help me out for the problem

Thanks in advance.

Regards,

Bharat Lalcheta
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.manyfish.co.uk/pipermail/neon/attachments/20120503/f9ac7f75/attachment.html 


More information about the neon mailing list