axis-c-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dami...@apache.org
Subject svn commit: r1129578 - in /axis/axis2/c/core/trunk: samples/client/ntlm/ src/core/transport/http/sender/ntlm/ src/core/transport/http/sender/ntlm/default/ src/core/transport/http/sender/ntlm/heimdal/ src/core/transport/http/sender/ntlm/test/ src/core/t...
Date Tue, 31 May 2011 09:05:26 GMT
Author: damitha
Date: Tue May 31 09:05:26 2011
New Revision: 1129578

URL: http://svn.apache.org/viewvc?rev=1129578&view=rev
Log:
Initial commit of ntlm authentication code

Added:
    axis/axis2/c/core/trunk/samples/client/ntlm/
    axis/axis2/c/core/trunk/samples/client/ntlm/Makefile.am
    axis/axis2/c/core/trunk/samples/client/ntlm/client.c   (with props)
    axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/
    axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/Makefile.am
    axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/README
    axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/default/
    axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/default/Makefile.am
    axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/default/default_ntlm_wrapper.c
    axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/heimdal/
    axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/heimdal/Makefile.am
    axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/heimdal/heimdal_ntlm_wrapper.c
    axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/ntlm.c
    axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/
    axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/Makefile.am
    axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/client.c   (with props)
    axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_client.c   (with props)
    axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_server/
    axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_server/Makefile.am
    axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_server/mock_server.c
    axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_server/run.sh   (with props)
    axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/run.sh   (with props)

Added: axis/axis2/c/core/trunk/samples/client/ntlm/Makefile.am
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/samples/client/ntlm/Makefile.am?rev=1129578&view=auto
==============================================================================
--- axis/axis2/c/core/trunk/samples/client/ntlm/Makefile.am (added)
+++ axis/axis2/c/core/trunk/samples/client/ntlm/Makefile.am Tue May 31 09:05:26 2011
@@ -0,0 +1,33 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+prgbindir=$(prefix)/samples/bin
+prgbin_PROGRAMS = ntlm_client 
+AM_CFLAGS = -g -O2
+ntlm_client_SOURCES = client.c
+
+LINK_FLAGS   = $(LDFLAGS) \
+                -L$(AXIS2C_HOME)/lib \
+					-laxutil \
+                    -laxis2_axiom \
+                    -laxis2_engine \
+                    -laxis2_parser \
+                    -laxis2_http_sender \
+                    -laxis2_http_receiver \
+					-laxis2_ntlm \
+                    $(GUTHTHILA_LIBS)
+
+ntlm_client_LDADD   = $(LINK_FLAGS)
+INCLUDES = @AXIS2INC@
+

Added: axis/axis2/c/core/trunk/samples/client/ntlm/client.c
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/samples/client/ntlm/client.c?rev=1129578&view=auto
==============================================================================
--- axis/axis2/c/core/trunk/samples/client/ntlm/client.c (added)
+++ axis/axis2/c/core/trunk/samples/client/ntlm/client.c Tue May 31 09:05:26 2011
@@ -0,0 +1,279 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <stdio.h>
+#include <axiom.h>
+#include <axis2_util.h>
+#include <axiom_soap.h>
+#include <axis2_client.h>
+#include <axis2_http_transport.h>
+
+axiom_node_t *build_om_payload_for_echo_svc(
+    const axutil_env_t * env);
+
+int
+main(
+    int argc,
+    char **argv)
+{
+    const axutil_env_t *env = NULL;
+    const axis2_char_t *address = NULL;
+    axis2_endpoint_ref_t *endpoint_ref = NULL;
+    axis2_options_t *options = NULL;
+    const axis2_char_t *client_home = NULL;
+    axis2_svc_client_t *svc_client = NULL;
+    axiom_node_t *payload = NULL;
+    axiom_node_t *ret_node = NULL;
+    const axis2_char_t *un = NULL;
+    const axis2_char_t *pw = NULL;
+    const axis2_char_t *flags = NULL;
+    const int fg = 0;
+    const axis2_char_t *domain = NULL;
+    const axis2_char_t *workstation = NULL;
+    axis2_bool_t http_auth_required = AXIS2_FALSE;
+    axis2_bool_t proxy_auth_required = AXIS2_FALSE;
+    axutil_string_t *soap_action = NULL;
+
+    /* Set up the environment */
+    env = axutil_env_create_all("ntlm_auth_client.log", AXIS2_LOG_LEVEL_TRACE);
+
+    /* Set end point reference of echo service */
+    address = "http://172.16.176.132:80/myservice/Service1.asmx";
+    if (argc > 1)
+    {
+        if (axutil_strcmp(argv[1], "-h") == 0)
+        {
+            printf("Usage : %s [endpoint_url] (-n [username] [password] [flags] [domain] [workstation])\n",
+                   argv[0]);
+            printf("use -n option for NTLM HTTP Authentication\n");
+            printf("use -h for help\n");
+            return 0;
+        }
+        else if (axutil_strcmp(argv[1], "-n") == 0)
+        {
+            if (argc > 3)
+            {
+                un = argv[2];
+                pw = argv[3];
+                flags = argv[4];
+                domain = argv[5];
+                workstation = argv[6];
+            }
+        }
+        else
+        {
+            address = argv[1];
+        }
+
+        if (argc > 4)
+        {
+            if (axutil_strcmp(argv[2], "-n") == 0)
+            {
+                un = argv[3];
+                pw = argv[4];
+                flags = argv[5];
+                domain = argv[6];
+                workstation = argv[7];
+            }
+        }
+    }
+    printf("Using endpoint : %s\n", address);
+
+    /* Create EPR with given address */
+    endpoint_ref = axis2_endpoint_ref_create(env, address);
+
+    /* Setup options */
+    options = axis2_options_create(env);
+    axis2_options_set_to(options, env, endpoint_ref);
+    soap_action =
+        axutil_string_create(env, "http://tempuri.org/HelloWorld");
+    axis2_options_set_soap_action(options, env, soap_action);
+    axutil_string_free(soap_action, env);
+
+    /* Set up deploy folder. It is from the deploy folder, the configuration is picked up
+     * using the axis2.xml file.
+     * In this sample client_home points to the Axis2/C default deploy folder. The client_home can 
+     * be different from this folder on your system. For example, you may have a different folder 
+     * (say, my_client_folder) with its own axis2.xml file. my_client_folder/modules will have the 
+     * modules that the client uses
+     */
+    client_home = AXIS2_GETENV("AXIS2C_HOME");
+    if (!client_home || !strcmp(client_home, ""))
+        client_home = "../..";
+
+    /* Create service client */
+    svc_client = axis2_svc_client_create(env, client_home);
+    if (!svc_client)
+    {
+        printf
+            ("Error creating service client, Please check AXIS2C_HOME again\n");
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+                        "Stub invoke FAILED: Error code:" " %d :: %s",
+                        env->error->error_number,
+                        AXIS2_ERROR_GET_MESSAGE(env->error));
+        return -1;
+    }
+
+    /* Enabling REST for HTTP HEAD Request */
+    axis2_options_set_enable_rest(options, env, AXIS2_TRUE);
+
+    /* Setting Request as HTTP HEAD Request */
+    axis2_options_set_http_method(options, env, AXIS2_HTTP_HEAD);
+
+    /* Sending dummy authentication info */
+    if (un && pw)
+    {
+        axis2_options_set_ntlm_proxy_auth_info(options, env, "", "", NULL, NULL, NULL, NULL);
+    }
+    if(flags)
+    {
+        fg = atoi(flags);
+    }
+    else
+    {
+        fg = 0;
+    }
+
+    /* Force authentication tests */
+    axis2_options_set_test_http_auth(options, env, AXIS2_TRUE);
+    axis2_options_set_test_proxy_auth(options, env, AXIS2_TRUE);
+
+    /* Set service client options */
+    axis2_svc_client_set_options(svc_client, env, options);
+
+    /* un-comment line below to setup proxy from code*/
+    /*axis2_svc_client_set_proxy_with_auth(svc_client, env, "127.0.0.1", "3128", NULL, NULL);*/
+
+    /* Sending robust authentication test message */
+    axis2_svc_client_send_robust(svc_client, env, NULL);
+
+    /* Checking whether authentication is required */
+    if (axis2_svc_client_get_proxy_auth_required(svc_client, env))
+    {
+        proxy_auth_required = AXIS2_TRUE;
+
+        /* Set proxy-auth information */
+        if (un && pw)
+        {
+            axis2_options_set_ntlm_proxy_auth_info(options, env, un, pw, &fg, domain, workstation,
+                                              axis2_svc_client_get_auth_type(svc_client, env));
+        }
+
+        /* Sending robust authentication test message */
+        axis2_svc_client_send_robust(svc_client, env, NULL);
+    }
+    if (axis2_svc_client_get_http_auth_required(svc_client, env))
+    {
+        http_auth_required = AXIS2_TRUE;
+        /* Set http-auth information */
+        if (un && pw)
+        {
+            axis2_options_set_ntlm_http_auth_info(options, env, un, pw, &fg, domain, workstation,
+                                             axis2_svc_client_get_auth_type(svc_client, env));
+        }
+    }
+
+    /* Cancel authentication tests */
+    axis2_options_set_test_http_auth(options, env, AXIS2_FALSE);
+    axis2_options_set_test_proxy_auth(options, env, AXIS2_FALSE);
+
+    /* Print whether authentication was required */
+    if (http_auth_required)
+    {
+        printf("\nHTTP Authentication info required.\n");
+    }
+    if (proxy_auth_required)
+    {
+        printf("\nProxy Authentication info required.\n");
+    }
+
+    /* Disabling REST for SOAP Request */
+    axis2_options_set_enable_rest(options, env, AXIS2_FALSE);
+
+    /* Setting Request as HTTP POST Request */
+    axis2_options_set_http_method(options, env, AXIS2_HTTP_POST);
+
+    int i = 0;
+    for(i = 0; i < 1; i++)
+    {
+        /* Build the SOAP request message payload using OM API. */
+        payload = build_om_payload_for_echo_svc(env);
+
+        /*axis2_svc_client_send_robust(svc_client, env, payload);*/
+        /* Send request */
+        ret_node = axis2_svc_client_send_receive(svc_client, env, payload);
+
+        if (ret_node)
+        {
+            axis2_char_t *om_str = NULL;
+            om_str = axiom_node_to_string(ret_node, env);
+            if (om_str)
+                printf("\nReceived OM : %s\n", om_str);
+            printf("\necho client invoke SUCCESSFUL!\n");
+
+            AXIS2_FREE(env->allocator, om_str);
+            ret_node = NULL;
+        }
+        else
+        {
+            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI,
+                            "Stub invoke FAILED: Error code:" " %d :: %s",
+                            env->error->error_number,
+                            AXIS2_ERROR_GET_MESSAGE(env->error));
+            printf("echo client invoke FAILED!\n");
+        }
+    }
+    if (svc_client)
+    {
+        axis2_svc_client_free(svc_client, env);
+        svc_client = NULL;
+    }
+
+    if (env)
+    {
+        axutil_env_free((axutil_env_t *) env);
+        env = NULL;
+    }
+
+    return 0;
+}
+
+/* build SOAP request message content using OM */
+axiom_node_t *
+build_om_payload_for_echo_svc(
+    const axutil_env_t * env)
+{
+    axiom_node_t *echo_om_node = NULL;
+    axiom_element_t *echo_om_ele = NULL;
+    axiom_namespace_t *ns1 = NULL;
+    axis2_char_t *om_str = NULL;
+
+    ns1 = axiom_namespace_create(env, "http://tempuri.org", "ns1");
+    echo_om_ele = axiom_element_create(env, NULL, "HelloWorld", ns1, &echo_om_node);
+    axiom_element_set_text(echo_om_ele, env, "Hello World!", echo_om_node);
+	axiom_namespace_free(ns1, env);
+
+    om_str = axiom_node_to_string(echo_om_node, env);
+    if (om_str)
+	{
+        printf("\nSending OM : %s\n", om_str);
+    	AXIS2_FREE(env->allocator, om_str);
+	}
+
+    return echo_om_node;
+}
+

Propchange: axis/axis2/c/core/trunk/samples/client/ntlm/client.c
------------------------------------------------------------------------------
    svn:executable = *

Added: axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/Makefile.am
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/Makefile.am?rev=1129578&view=auto
==============================================================================
--- axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/Makefile.am (added)
+++ axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/Makefile.am Tue May 31 09:05:26 2011
@@ -0,0 +1,15 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+SUBDIRS = $(NTLM_WRAPPER_DIR)

Added: axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/README
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/README?rev=1129578&view=auto
==============================================================================
    (empty)

Added: axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/default/Makefile.am
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/default/Makefile.am?rev=1129578&view=auto
==============================================================================
--- axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/default/Makefile.am (added)
+++ axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/default/Makefile.am Tue May 31 09:05:26 2011
@@ -0,0 +1,24 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+lib_LTLIBRARIES = libaxis2_ntlm.la
+
+
+libaxis2_ntlm_la_SOURCES = ../ntlm.c \
+							default_ntlm_wrapper.c
+
+libaxis2_ntlm_la_LIBADD =  $(top_builddir)/util/src/libaxutil.la
+
+INCLUDES = -I$(top_builddir)/include \
+            -I$(top_builddir)/util/include

Added: axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/default/default_ntlm_wrapper.c
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/default/default_ntlm_wrapper.c?rev=1129578&view=auto
==============================================================================
--- axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/default/default_ntlm_wrapper.c (added)
+++ axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/default/default_ntlm_wrapper.c Tue May 31 09:05:26 2011
@@ -0,0 +1,137 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <axis2_ntlm.h>
+#include <axutil_utils_defines.h>
+#include <axutil_utils.h>
+#include <string.h>
+#include <axutil_string.h>
+
+void AXIS2_CALL
+default_ntlm_wrapper_free(
+    axis2_ntlm_t * ntlm,
+    const axutil_env_t * env);
+
+axis2_status_t AXIS2_CALL
+default_ntlm_wrapper_create_type1_message(
+    axis2_ntlm_t * ntlm,
+    const axutil_env_t * env,
+    axis2_char_t **encoded_message,
+    int *encoded_len,
+    const axis2_char_t *uname,
+    const axis2_char_t *passwd,
+    const int flags,
+    const axis2_char_t *domain,
+    const axis2_char_t *workstation);
+
+axis2_status_t AXIS2_CALL
+default_ntlm_wrapper_create_type3_message(
+    axis2_ntlm_t * ntlm,
+    const axutil_env_t * env,
+    axis2_char_t *header_value,
+    axis2_char_t **encoded_message,
+    int *encoded_len,
+    const axis2_char_t *uname,
+    const axis2_char_t *passwd,
+    const int flags,
+    const axis2_char_t *domain,
+    const axis2_char_t *workstation);
+
+typedef struct default_ntlm_wrapper_impl_t
+{
+    axis2_ntlm_t ntlm;
+
+    /*xmlTextReaderPtr reader;*/
+
+} default_ntlm_wrapper_impl_t;
+
+#define AXIS2_INTF_TO_IMPL(p) ((default_ntlm_wrapper_impl_t*)p)
+#define AXIS2_IMPL_TO_INTF(p) &(p->ntlm)
+
+static const axis2_ntlm_ops_t axis2_ntlm_ops_var = {
+    default_ntlm_wrapper_free,
+    default_ntlm_wrapper_create_type1_message,
+    default_ntlm_wrapper_create_type3_message };
+
+AXIS2_EXTERN axis2_ntlm_t *AXIS2_CALL
+axis2_ntlm_create(
+    const axutil_env_t *env)
+{
+    default_ntlm_wrapper_impl_t *wrapper_impl = NULL;
+    wrapper_impl = (default_ntlm_wrapper_impl_t *)AXIS2_MALLOC(env->allocator,
+        sizeof(default_ntlm_wrapper_impl_t));
+
+    if(!wrapper_impl)
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create default ntlm wrapper");
+        return NULL;
+    }
+    memset(wrapper_impl, 0, sizeof(default_ntlm_wrapper_impl_t));
+    /*wrapper_impl->x=NULL;*/
+    wrapper_impl->ntlm.ops = &axis2_ntlm_ops_var;
+    return &(wrapper_impl->ntlm);
+}
+
+/**
+ */
+void AXIS2_CALL
+default_ntlm_wrapper_free(
+    axis2_ntlm_t * ntlm,
+    const axutil_env_t * env)
+{
+    default_ntlm_wrapper_impl_t *ntlm_impl = NULL;
+    ntlm_impl = AXIS2_INTF_TO_IMPL(ntlm);
+
+    AXIS2_FREE(env->allocator, AXIS2_INTF_TO_IMPL(ntlm));
+    return;
+}
+
+axis2_status_t AXIS2_CALL
+default_ntlm_wrapper_create_type1_message(
+    axis2_ntlm_t * ntlm,
+    const axutil_env_t * env,
+    axis2_char_t **encoded_message,
+    int *encoded_len,
+    const axis2_char_t *user,
+    const axis2_char_t *password,
+    const int flags,
+    const axis2_char_t *domain,
+    const axis2_char_t *workstation)
+{
+    axis2_status_t status = AXIS2_FAILURE;
+    return status;
+}
+
+axis2_status_t AXIS2_CALL
+default_ntlm_wrapper_create_type3_message(
+    axis2_ntlm_t * ntlm,
+    const axutil_env_t * env,
+    axis2_char_t *header_value,
+    axis2_char_t **encoded_message,
+    int *encoded_len,
+    const axis2_char_t *user,
+    const axis2_char_t *password,
+    const int flags,
+    const axis2_char_t *domain,
+    const axis2_char_t *workstation)
+{
+    axis2_status_t status = AXIS2_FAILURE;
+    return status;
+}
+
+

Added: axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/heimdal/Makefile.am
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/heimdal/Makefile.am?rev=1129578&view=auto
==============================================================================
--- axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/heimdal/Makefile.am (added)
+++ axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/heimdal/Makefile.am Tue May 31 09:05:26 2011
@@ -0,0 +1,29 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+lib_LTLIBRARIES = libaxis2_ntlm.la
+
+
+libaxis2_ntlm_la_SOURCES = ../ntlm.c \
+							heimdal_ntlm_wrapper.c
+
+libaxis2_ntlm_la_LIBADD = @NTLM_LDFLAGS@ \
+							$(top_builddir)/util/src/libaxutil.la
+
+#libaxis2_ntlm_la_LDFLAGS = -version-info $(VERSION_NO)
+
+
+INCLUDES = -I$(top_builddir)/include \
+            -I$(top_builddir)/util/include \
+			@NTLM_CFLAGS@

Added: axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/heimdal/heimdal_ntlm_wrapper.c
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/heimdal/heimdal_ntlm_wrapper.c?rev=1129578&view=auto
==============================================================================
--- axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/heimdal/heimdal_ntlm_wrapper.c (added)
+++ axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/heimdal/heimdal_ntlm_wrapper.c Tue May 31 09:05:26 2011
@@ -0,0 +1,378 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <axis2_ntlm.h>
+#include <axutil_utils_defines.h>
+#include <axutil_utils.h>
+#include <string.h>
+#include <axutil_string.h>
+
+#include <roken.h>
+#include <krb5-types.h> /* or <inttypes.h> */
+#include <heimntlm.h>
+
+void AXIS2_CALL
+heimdal_ntlm_wrapper_free(
+    axis2_ntlm_t * ntlm,
+    const axutil_env_t * env);
+
+axis2_status_t AXIS2_CALL
+heimdal_ntlm_wrapper_create_type1_message(
+    axis2_ntlm_t * ntlm,
+    const axutil_env_t * env,
+    axis2_char_t **encoded_message,
+    int *encoded_len,
+    const axis2_char_t *uname,
+    const axis2_char_t *passwd,
+    const int flags,
+    const axis2_char_t *domain);
+
+axis2_status_t AXIS2_CALL
+heimdal_ntlm_wrapper_create_type3_message(
+    axis2_ntlm_t * ntlm,
+    const axutil_env_t * env,
+    axis2_char_t *header_value,
+    axis2_char_t **encoded_message,
+    int *encoded_len,
+    const axis2_char_t *uname,
+    const axis2_char_t *passwd,
+    const axis2_char_t *domain,
+    const axis2_char_t *workstation);
+
+typedef struct heimdal_ntlm_wrapper_impl_t
+{
+    axis2_ntlm_t ntlm;
+} heimdal_ntlm_wrapper_impl_t;
+
+#define AXIS2_INTF_TO_IMPL(p) ((heimdal_ntlm_wrapper_impl_t*)p)
+#define AXIS2_IMPL_TO_INTF(p) &(p->ntlm)
+
+static const axis2_ntlm_ops_t axis2_ntlm_ops_var = {
+    heimdal_ntlm_wrapper_free,
+    heimdal_ntlm_wrapper_create_type1_message,
+    heimdal_ntlm_wrapper_create_type3_message };
+
+AXIS2_EXTERN axis2_ntlm_t *AXIS2_CALL
+axis2_ntlm_create(
+    const axutil_env_t *env)
+{
+    heimdal_ntlm_wrapper_impl_t *wrapper_impl = NULL;
+    wrapper_impl = (heimdal_ntlm_wrapper_impl_t *)AXIS2_MALLOC(env->allocator,
+        sizeof(heimdal_ntlm_wrapper_impl_t));
+
+    if(!wrapper_impl)
+    {
+        AXIS2_ERROR_SET(env->error, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, "No memory. Cannot create heimdal ntlm wrapper");
+        return NULL;
+    }
+    memset(wrapper_impl, 0, sizeof(heimdal_ntlm_wrapper_impl_t));
+    wrapper_impl->ntlm.ops = &axis2_ntlm_ops_var;
+    return &(wrapper_impl->ntlm);
+}
+
+/**
+ */
+void AXIS2_CALL
+heimdal_ntlm_wrapper_free(
+    axis2_ntlm_t * ntlm,
+    const axutil_env_t * env)
+{
+    heimdal_ntlm_wrapper_impl_t *ntlm_impl = NULL;
+    ntlm_impl = AXIS2_INTF_TO_IMPL(ntlm);
+
+    AXIS2_FREE(env->allocator, AXIS2_INTF_TO_IMPL(ntlm));
+    return;
+}
+
+axis2_status_t AXIS2_CALL
+heimdal_ntlm_wrapper_create_type1_message(
+    axis2_ntlm_t * ntlm,
+    const axutil_env_t * env,
+    axis2_char_t **encoded_message,
+    int *encoded_len,
+    const axis2_char_t *user,
+    const axis2_char_t *password,
+    const int flags,
+    const axis2_char_t *domain)
+{
+    heimdal_ntlm_wrapper_impl_t *ntlm_impl = NULL;
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    ntlm_impl = AXIS2_INTF_TO_IMPL(ntlm);
+
+    struct ntlm_type1 type1;
+    struct ntlm_buf data;
+    int ret;
+    memset(&type1, 0, sizeof(type1));
+
+    if(flags != 0)
+    {
+        type1.flags = NTLM_NEG_UNICODE|NTLM_NEG_TARGET|NTLM_NEG_NTLM|flags;
+    }
+    else
+    {
+        type1.flags = NTLM_NEG_UNICODE|NTLM_NEG_TARGET|NTLM_NEG_NTLM;
+    }
+    if(domain)
+    {
+        type1.domain = rk_UNCONST(domain);
+    }
+    else
+    {
+        type1.domain = NULL;
+    }
+    type1.hostname = NULL;
+    type1.os[0] = 0;
+    type1.os[1] = 0;
+
+    ret = heim_ntlm_encode_type1(&type1, &data);
+    if (ret)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                "[heimdal_wrapper] heim_ntlm_encode_type1 call failed");
+        return AXIS2_FAILURE;
+    }
+
+    *encoded_message = AXIS2_MALLOC(env->allocator, (2 * data.length));
+    if(!*encoded_message)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                "[heimdal_wrapper] Memory allocation for encoded message failed");
+        return AXIS2_FAILURE;
+    }
+    *encoded_len = axutil_base64_encode_binary(*encoded_message, data.data, data.length);
+
+    if(data.data)
+    {
+        free(data.data);
+    }
+
+    return AXIS2_SUCCESS;
+}
+
+axis2_status_t AXIS2_CALL
+heimdal_ntlm_wrapper_create_type3_message(
+    axis2_ntlm_t * ntlm,
+    const axutil_env_t * env,
+    axis2_char_t *header_value,
+    axis2_char_t **encoded_message,
+    int *encoded_len,
+    const axis2_char_t *user,
+    const axis2_char_t *password,
+    const axis2_char_t *domain,
+    const axis2_char_t *workstation)
+{
+    heimdal_ntlm_wrapper_impl_t *ntlm_impl = NULL;
+    AXIS2_ENV_CHECK(env, AXIS2_FAILURE);
+    ntlm_impl = AXIS2_INTF_TO_IMPL(ntlm);
+
+    struct ntlm_type3 type3;
+    struct ntlm_type2 type2;
+    struct ntlm_buf data;
+    int ret;
+    
+    memset(&type2, 0, sizeof(type2));
+
+    int len = axutil_strlen(header_value);
+    len = 2 * len + 1;
+    char temp_value[len];
+    data.data = temp_value;
+    data.length = axutil_base64_decode_binary(data.data, header_value);
+    ret = heim_ntlm_decode_type2(&data, &type2);
+    data.data = NULL;
+    if (ret)
+    {
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                "[heimdal_wrapper] heim_ntlm_decode_type2 call failed");
+        return AXIS2_FAILURE;
+    }
+
+    memset(&type3, 0, sizeof(type3));
+
+    type3.flags = type2.flags;
+    type3.username = rk_UNCONST(user);
+    type3.targetname = rk_UNCONST(type2.targetname);
+    if(workstation)
+    {
+        type3.ws = rk_UNCONST(workstation);
+    }
+    else
+    {
+        type3.ws = NULL;
+    }
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "type3.flags:***%d***", type3.flags);
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "type3.username:***%s***", type3.username);
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "type3.targetname:***%s***", type3.targetname);
+    AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "type3.ws:***%s***", type3.ws);
+
+    {
+        struct ntlm_buf key;
+        heim_ntlm_nt_key(password, &key);
+        
+         /* NTLM Version 1 if no targetinfo buffer.*/
+         
+        if (1 || type2.targetinfo.length == 0) 
+        {
+
+            if (type2.flags & NTLM_NEG_NTLM2_SESSION) 
+            {
+                AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[heimdal_wrapper] ntlm2 session");
+                unsigned char nonce[8];
+
+                if (RAND_bytes(nonce, sizeof(nonce)) != 1) 
+                {
+                    AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                        "[heimdal_wrapper] RAND_bytes function call failed");
+                    return AXIS2_FAILURE;
+                }
+
+                AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[heimdal_wrapper] calculate_ntlm2_sess");
+                ret = heim_ntlm_calculate_ntlm2_sess(nonce,
+                                 type2.challange,
+                                 key.data,
+                                 &type3.lm,
+                                 &type3.ntlm);
+            } 
+            else 
+            {
+                AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[heimdal_wrapper] calculate_ntlm1");
+                ret = heim_ntlm_calculate_ntlm1(key.data,
+                        key.length,
+                        type2.challange,
+                        &type3.ntlm);
+
+            }
+            if (ret) 
+            {
+                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                    "[heimdal_wrapper] heim_ntlm_calculate_ntlm1 function call failed");
+                return AXIS2_FAILURE;
+            }
+
+            if (type2.flags & NTLM_NEG_KEYEX)
+            {
+                struct ntlm_buf sessionkey;
+
+                AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[heimdal_wrapper] build_ntlm1_master");
+                ret = heim_ntlm_build_ntlm1_master(key.data,
+                               key.length,
+                               &sessionkey,
+                               &type3.sessionkey);
+                if (ret) 
+                {
+                    if (type3.lm.data)
+                    {
+                        free(type3.lm.data);
+                    }
+                    AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                        "[heimdal_wrapper] heim_ntlm_build_ntlm1_master function call failed");
+                    return AXIS2_FAILURE;
+                }
+
+                free(sessionkey.data);
+            }
+
+        } 
+        else 
+        {
+            unsigned char ntlmv2[16];
+            struct ntlm_targetinfo ti;
+
+            /* verify infotarget */
+
+            ret = heim_ntlm_decode_targetinfo(&type2.targetinfo, 1, &ti);
+            if(ret) 
+            {
+                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                    "[heimdal_wrapper] heim_ntlm_decode_targetinfo function call failed");
+                return AXIS2_FAILURE;
+            }
+
+            if (ti.domainname && domain && strcmp(ti.domainname, domain) != 0) 
+            {
+                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                    "[heimdal_wrapper] heim_ntlm_decode_targetinfo function returned wrong data");
+                return AXIS2_FAILURE;
+            }
+
+            AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[heimdal_wrapper] calculate_ntlm2");
+            ret = heim_ntlm_calculate_ntlm2(key.data,
+                            key.length,
+                            user,
+                            domain,
+                            type2.challange,
+                            &type2.targetinfo,
+                            ntlmv2,
+                            &type3.ntlm);
+            if (ret) 
+            {
+                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                    "[heimdal_wrapper] heim_ntlm_calculate_ntlm2 function call failed");
+                return AXIS2_FAILURE;
+            }
+
+            if (type2.flags & NTLM_NEG_KEYEX)
+            {
+                struct ntlm_buf sessionkey;
+                AXIS2_LOG_DEBUG(env->log, AXIS2_LOG_SI, "[heimdal_wrapper] build_ntlm1_master");
+                ret = heim_ntlm_build_ntlm1_master(ntlmv2, sizeof(ntlmv2),
+                                   &sessionkey,
+                                   &type3.sessionkey);
+                memset(ntlmv2, 0, sizeof(ntlmv2));
+                if (ret) 
+                {
+                    AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                        "[heimdal_wrapper] heim_ntlm_build_ntlm1_master function call failed");
+                    return AXIS2_FAILURE;
+                }
+
+                free(sessionkey.data);
+            }
+        }
+       
+        if(key.data)
+        {
+            free(key.data);
+        }
+    }
+
+    ret = heim_ntlm_encode_type3(&type3, &data);
+    if (ret)
+    {
+        heim_ntlm_free_type2(&type2);
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                "[heimdal_wrapper] heim_ntlm_encode_type3 call failed");
+        return AXIS2_FAILURE;
+    }
+
+    *encoded_message = AXIS2_MALLOC(env->allocator, (2 * data.length));
+    if(!*encoded_message)
+    {
+        heim_ntlm_free_type2(&type2);
+        free(type3.ntlm.data);
+        AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                "[heimdal_wrapper] Memory allocation for encoded message failed");
+        return AXIS2_FAILURE;
+    }
+    *encoded_len = axutil_base64_encode_binary(*encoded_message, data.data, data.length);
+    heim_ntlm_free_type2(&type2);
+    free(type3.ntlm.data);
+
+    return AXIS2_SUCCESS;
+}
+
+

Added: axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/ntlm.c
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/ntlm.c?rev=1129578&view=auto
==============================================================================
--- axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/ntlm.c (added)
+++ axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/ntlm.c Tue May 31 09:05:26 2011
@@ -0,0 +1,58 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <axis2_ntlm.h>
+
+AXIS2_EXTERN void AXIS2_CALL
+axis2_ntlm_free(
+    axis2_ntlm_t * ntlm,
+    const axutil_env_t * env)
+{
+    (ntlm)->ops->free(ntlm, env);
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+axis2_ntlm_auth_create_type1_message(
+    axis2_ntlm_t * ntlm,
+    const axutil_env_t * env,
+    axis2_char_t **encoded_message,
+    int *encoded_len,
+    const axis2_char_t *uname,
+    const axis2_char_t *passwd,
+    const int flags,
+    const axis2_char_t *domain)
+{
+    return (ntlm)->ops->create_type1_message(ntlm, env, encoded_message, encoded_len, uname, 
+            passwd, flags, domain);
+}
+
+AXIS2_EXTERN axis2_status_t AXIS2_CALL
+axis2_ntlm_auth_create_type3_message(
+    axis2_ntlm_t * ntlm,
+    const axutil_env_t * env,
+    axis2_char_t *header_value,
+    axis2_char_t **encoded_message,
+    int *encoded_len,
+    const axis2_char_t *uname,
+    const axis2_char_t *passwd,
+    const axis2_char_t *domain,
+    const axis2_char_t *workstation)
+{
+    return (ntlm)->ops->create_type3_message(ntlm, env, header_value, encoded_message, encoded_len, 
+            uname, passwd, domain, workstation);
+}
+

Added: axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/Makefile.am
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/Makefile.am?rev=1129578&view=auto
==============================================================================
--- axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/Makefile.am (added)
+++ axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/Makefile.am Tue May 31 09:05:26 2011
@@ -0,0 +1,30 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+TESTS =
+SUBDIRS = mock_server
+noinst_PROGRAMS = test_ntlm mock_client
+check_PROGRAMS = test_ntlm mock_client
+SUBDIRS =
+AM_CFLAGS = -g -O2
+test_ntlm_SOURCES = client.c
+mock_client_SOURCES = mock_client.c
+
+LINK_FLAGS   =	../$(NTLM_WRAPPER_DIR)/libaxis2_ntlm.la \
+					$(top_builddir)/util/src/libaxutil.la
+
+test_ntlm_LDADD   =	$(LINK_FLAGS)
+mock_client_LDADD   =	$(LINK_FLAGS)
+INCLUDES = -I$(top_builddir)/include \
+            -I$(top_builddir)/util/include

Added: axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/client.c
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/client.c?rev=1129578&view=auto
==============================================================================
--- axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/client.c (added)
+++ axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/client.c Tue May 31 09:05:26 2011
@@ -0,0 +1,82 @@
+/* tcpclient.c */
+
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <axutil_base64.h>
+#include <axutil_string.h>
+#include <axis2_util.h>
+
+#include <stdio.h>
+#include <axis2_ntlm.h>
+
+#define NTLM_NEG_NTLM           0x00000200
+#define NTLM_NEG_UNICODE        0x00000001
+#define NTLM_TARGET_DOMAIN      0x00010000
+
+int main()
+{
+    axis2_status_t status = AXIS2_FAILURE;
+    const axutil_env_t *env = NULL;
+    env = axutil_env_create_all("ntlm_test_client.log", AXIS2_LOG_LEVEL_TRACE);
+    /*int flags = NTLM_NEG_UNICODE | NTLM_NEG_NTLM | NTLM_TARGET_DOMAIN;*/
+
+    {
+        axis2_char_t *encoded = NULL;
+        int elen = 0;
+        int flags = 0;
+        axis2_ntlm_t *ntlm = NULL;
+        ntlm = axis2_ntlm_create(env);
+        status = axis2_ntlm_auth_create_type1_message(ntlm, env, &encoded, &elen, "foo", 
+                "digestpassword", flags, "mydomain");
+        if(AXIS2_SUCCESS != status)
+        {
+            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                    "axis2_ntlm_auth_create_type1_message call failed");
+            printf("axis2_ntlm_auth_create_type1_message call failed\n");
+            return 1;
+        }
+        if(0 == axutil_strcmp(encoded, "TlRMTVNTUAABAAAABRIAAAgACAAYAAAAbXlkb21haW4=") && elen == 45)
+        {
+            printf("creating type1 message test passed\n");
+        }
+        else
+        {
+            printf("creating type1 message test failed!!!\n");
+        }
+    }
+    {
+        int elen = 0;
+        axis2_char_t *encoded = NULL;
+        axis2_char_t *header_value = 
+            "TlRMTVNTUAACAAAAHgAeADgAAAAFAoICZAg+4lbcT0AAAAAAAAAAAJgAmABWAAAABgGxHQAAAA9XAEkATgAtADcAMQBNAEUAUABIADQANgBOAFEAMwACAB4AVwBJAE4ALQA3ADEATQBFAFAASAA0ADYATgBRADMAAQAeAFcASQBOAC0ANwAxAE0ARQBQAEgANAA2AE4AUQAzAAQAHgBXAEkATgAtADcAMQBNAEUAUABIADQANgBOAFEAMwADAB4AVwBJAE4ALQA3ADEATQBFAFAASAA0ADYATgBRADMABwAIAHIX52u6HcwBAAAAAA==";
+        axis2_ntlm_t *ntlm = NULL;
+        ntlm = axis2_ntlm_create(env);
+        status = axis2_ntlm_auth_create_type3_message(ntlm, env, header_value, &encoded, 
+                &elen, "nandika", "nandika", "mydomain", "workstation");
+        if(AXIS2_SUCCESS != status)
+        {
+            AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                    "axis2_ntlm_auth_create_type3_message call failed");
+            printf("axis2_ntlm_auth_create_type3_message call failed\n");
+            return 1;
+        }
+        if(0 == axutil_strcmp(encoded, "TlRMTVNTUAADAAAAAAAAADQAAAAYABgANAAAAB4AHgBMAAAADgAOAGoAAAAWABYAeAAAACkOCQbnz6muRsRit954E//a+AQM6Dk8g1cASQBOAC0ANwAxAE0ARQBQAEgANAA2AE4AUQAzAG4AYQBuAGQAaQBrAGEAdwBvAHIAawBzAHQAYQB0AGkAbwBuAA==") && elen == 193)
+        {
+            printf("creating type3 message test passed\n");
+        }
+        else
+        {
+            printf("creating type3 message test failed!!!\n");
+        }
+    }
+    
+    return 0;
+}
+

Propchange: axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/client.c
------------------------------------------------------------------------------
    svn:executable = *

Added: axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_client.c
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_client.c?rev=1129578&view=auto
==============================================================================
--- axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_client.c (added)
+++ axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_client.c Tue May 31 09:05:26 2011
@@ -0,0 +1,196 @@
+/* tcpclient.c */
+
+#include <sys/socket.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <axutil_base64.h>
+#include <axutil_string.h>
+#include <axis2_util.h>
+#include <axis2_ntlm.h>
+
+
+/*axis2_char_t *hostname = "172.16.176.132";*/
+axis2_char_t *hostname = "localhost";
+int port = 8080;
+static char *
+create_type1_header(const axutil_env_t *env, axis2_char_t *encoded)
+{
+    char *type1_header = NULL;
+    char *header1 = NULL;
+
+    type1_header = axutil_strcat(env, "Authorization: NTLM " ,encoded, NULL);
+
+    header1 = "HEAD /myservice/Service1.asmx HTTP/1.1\n"\
+            "Host: 172.16.176.132:8080\n"\
+            "User-Agent: Axis2C/1.7.0\n";
+    header1 = axutil_strcat(env, header1, type1_header, "\n\n", NULL);
+    AXIS2_FREE(env->allocator, type1_header);
+
+    return header1;
+}
+
+static axis2_char_t *
+create_type3_header(const axutil_env_t *env, 
+        char *encoded)
+{
+    char *header3 = NULL;
+
+    char *temp_header = strdup("GET /myservice/Service1.asmx?WSDL HTTP/1.1\n"\
+            "Host: 172.16.176.132:8080\n"\
+            "User-Agent: Axis2C/1.7.0\n"\
+            "Authorization: NTLM ");
+
+    int len1 = axutil_strlen(encoded);
+    int len2 = axutil_strlen(temp_header);
+    header3 = AXIS2_MALLOC(env->allocator, (len1 + len2 + 5));
+    memset(header3, 0, sizeof(header3));
+    strcat(header3, temp_header);
+    strcat(header3, encoded);
+    strcat(header3, "\n\n");
+
+    return header3;
+
+}
+
+int main()
+{
+    int sock, bytes_recieved;  
+    char recv_data[10024];
+    struct hostent *host;
+    struct sockaddr_in server_addr;
+    const axis2_char_t *header = NULL;
+    axis2_char_t *header_value = NULL;
+    char *type3_header = NULL;
+    char *type1_header = NULL;
+    const char *user = "nandika",
+	            *domain = "mydomain",
+	            *password = "nandika",
+	            *workstation = "workstation";
+    axis2_status_t status = AXIS2_FAILURE;
+    const axutil_env_t *env = NULL;
+    env = axutil_env_create_all("mock_client.log", AXIS2_LOG_LEVEL_TRACE);
+
+    host = gethostbyname(hostname);
+
+    if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
+        perror("Socket");
+        exit(1);
+    }
+
+    server_addr.sin_family = AF_INET;     
+    server_addr.sin_port = htons(port);   
+    server_addr.sin_addr = *((struct in_addr *)host->h_addr);
+    bzero(&(server_addr.sin_zero),8); 
+  
+    /* Create a normal message */
+    char *init_send = axutil_strdup(env, "HEAD /myservice/Service1.asmx HTTP/1.1\n"\
+                        "Host: 172.16.176.132:8080\n"\
+                        "User-Agent: Axis2C/1.7.0\n\n");
+
+    if (connect(sock, (struct sockaddr *)&server_addr,
+                sizeof(struct sockaddr)) == -1) 
+    {
+        perror("Connect");
+        exit(1);
+    }
+    /* Send a normal message */
+    send(sock, init_send, strlen(init_send), 0); 
+
+    while(1)
+    {
+        bytes_recieved=recv(sock,recv_data,10024,0);
+        recv_data[bytes_recieved] = '\0';
+        header = axutil_strstr(recv_data, "WWW-Authenticate: NTLM ");
+        
+        /* Process the challange */
+        if(header)
+        {
+            int i = 22;
+            while(header[i] && isspace((unsigned char) header[i]))
+            {
+                i++;
+            }
+            if (header[i] != '\0') 
+            {
+                int len = axutil_strlen(&header[i]);
+                if (len == 0)
+                {
+                    printf("invalid Negotiate token\n");
+                }
+                else
+                {
+                    header_value = axutil_strdup(env, &header[i]);
+                }
+            }
+            if(header_value)
+            {
+                axis2_char_t *temp = strstr(header_value, "==");
+                temp = temp + 3;
+                *temp = '\0';
+                header_value = axutil_strdup(env, header_value);
+            }
+        }
+        if(!header_value) /* printf("unauth_header:\n%s\n", unauth_header); */
+        {
+            axis2_char_t *encoded = NULL;
+            int elen = 0;
+            int flags = 0;
+            axis2_ntlm_t *ntlm = NULL;
+            ntlm = axis2_ntlm_create(env);
+            status = axis2_ntlm_auth_create_type1_message(ntlm, env, &encoded, &elen, user, 
+                    password, flags, domain);
+            if(AXIS2_SUCCESS != status)
+            {
+                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                        "axis2_ntlm_auth_create_type1_message call failed");
+                printf("axis2_ntlm_auth_create_type1_message call failed\n");
+                return 1;
+            }
+
+            /* Ceate type 1(negotiation) header  message from the recieved header */
+            type1_header = create_type1_header(env, encoded);
+            /* Send netotiation message */
+            send(sock, type1_header,strlen(type1_header), 0);
+            printf("sent:\n%s\n", type1_header);
+            free(type1_header);
+            continue;
+        }
+        if(header_value)
+        {
+            /*printf("header_value:\n***%s***\n", header_value);*/
+            int elen = 0;
+            axis2_char_t *encoded = NULL;
+            axis2_char_t *header_value = NULL;
+            axis2_ntlm_t *ntlm = NULL;
+            ntlm = axis2_ntlm_create(env);
+            status = axis2_ntlm_auth_create_type3_message(ntlm, env, header_value, &encoded, 
+                    &elen, user, password, domain, workstation);
+            if(AXIS2_SUCCESS != status)
+            {
+                AXIS2_LOG_ERROR(env->log, AXIS2_LOG_SI, 
+                        "axis2_ntlm_auth_create_type3_message call failed");
+                printf("axis2_ntlm_auth_create_type3_message call failed\n");
+                return 1;
+            }
+
+            /* Create Type3 (authentication) header */
+            type3_header = create_type3_header(env, encoded);
+            break;
+        }
+    }
+    /* Send Type3(authentication) message */
+    send(sock, type3_header, strlen(type3_header), 0); 
+    bytes_recieved=recv(sock,recv_data,10024,0);
+    recv_data[bytes_recieved] = '\0';
+    printf("\nRecieved data:\n%s \n" , recv_data);
+    close(sock);
+    
+    return 0;
+}
+

Propchange: axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_client.c
------------------------------------------------------------------------------
    svn:executable = *

Added: axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_server/Makefile.am
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_server/Makefile.am?rev=1129578&view=auto
==============================================================================
--- axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_server/Makefile.am (added)
+++ axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_server/Makefile.am Tue May 31 09:05:26 2011
@@ -0,0 +1,25 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements.  See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License.  You may obtain a copy of the License at
+# 
+#   http://www.apache.org/licenses/LICENSE-2.0
+# 
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+TESTS =
+noinst_PROGRAMS = mock_server
+check_PROGRAMS = mock_server
+SUBDIRS =
+AM_CFLAGS = -g -O2
+mock_server_SOURCES = mock_server.c
+
+mock_server_LDADD   = $(top_builddir)/util/src/libaxutil.la
+
+INCLUDES = -I$(top_builddir)/include \
+            -I$(top_builddir)/util/include

Added: axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_server/mock_server.c
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_server/mock_server.c?rev=1129578&view=auto
==============================================================================
--- axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_server/mock_server.c (added)
+++ axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_server/mock_server.c Tue May 31 09:05:26 2011
@@ -0,0 +1,128 @@
+/* tcpserver.c */
+
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <unistd.h>
+#include <errno.h>
+#include <string.h>
+#include <axutil_string.h>
+#include <axis2_util.h>
+
+int main()
+{
+    int port = 8080;
+    int sock, connected, bytes_recieved , true = 1;  
+    char recv_data[10024];       
+    char *send_data = NULL;
+    const axutil_env_t *env = NULL;
+    int flip = 0;
+
+    env = axutil_env_create_all("mock_server.log", AXIS2_LOG_LEVEL_TRACE);
+    struct sockaddr_in server_addr,client_addr;    
+    unsigned int sin_size;
+    
+    if ((sock = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
+        perror("Socket");
+        exit(1);
+    }
+
+    if (setsockopt(sock,SOL_SOCKET,SO_REUSEADDR,&true,sizeof(int)) == -1) {
+        perror("Setsockopt");
+        exit(1);
+    }
+    
+    server_addr.sin_family = AF_INET;         
+    server_addr.sin_port = htons(port);     
+    server_addr.sin_addr.s_addr = INADDR_ANY; 
+    bzero(&(server_addr.sin_zero),8); 
+
+    if (bind(sock, (struct sockaddr *)&server_addr, sizeof(struct sockaddr))
+                                                                   == -1) {
+        perror("Unable to bind");
+        exit(1);
+    }
+
+    if (listen(sock, 5) == -1) {
+        perror("Listen");
+        exit(1);
+    }
+        
+    printf("\nTCPServer Waiting for client on port %d \n", port);
+        fflush(stdout);
+
+
+    while(1)
+    {  
+        sin_size = sizeof(struct sockaddr_in);
+
+        connected = accept(sock, (struct sockaddr *)&client_addr, &sin_size);
+
+        printf("\nGot a connection from (%s , %d) \n",
+               inet_ntoa(client_addr.sin_addr),ntohs(client_addr.sin_port));
+
+        while (1)
+        {
+            int mark = 0;
+            bytes_recieved = recv(connected,recv_data,10024,0);
+            recv_data[bytes_recieved] = '\0';
+            if(strstr(recv_data, "GET")) 
+            {
+                mark = 1;
+            }
+            if( mark == 1 && strstr(recv_data, "Authorization: NTLM "))
+            {
+                if(flip == 0)
+                {
+                    send_data = "HTTP/1.1 401 Unauthorized\n"\
+                        "Content-Type: text/html; charset=us-ascii\n"\
+                        "Server: Microsoft-HTTPAPI/2.0\n"\
+                        "WWW-Authenticate: NTLM TlRMTVNTUAACAAAADAAMADAAAAABAgEAf39/f39/f38AAAAAAAAAAAAAAAA8AAAARABPAE0AQQBJAE4A\n"\
+                        "Date: Thu, 31 Mar 2011 17:41:03 GMT\n"\
+                        "Content-Length: 341\n\n";
+                    flip = 1;
+                }
+                else if(flip == 1) 
+                {
+                    send_data = "HTTP/1.1 200 OK\n"\
+                        "Cache-Control: private, max-age=0\n"\
+                        "Content-Type: text/xml; charset=utf-8\n"\
+                        "Server: Microsoft-IIS/7.5\n"\
+                        "X-AspNet-Version: 2.0.50727\n"\
+                        "Persistent-Auth: true\n"\
+                        "X-Powered-By: ASP.NET\n"\
+                        "Date: Thu, 31 Mar 2011 17:41:04 GMT\n"\
+                        "Content-Length: 2827\n\n";
+                    flip = 0;
+                }
+                printf("sent:%s\n", send_data);
+                fflush(stdout);
+                send(connected, send_data,strlen(send_data), 0);  
+            }
+            else if(mark == 1)
+            {
+                send_data = "HTTP/1.1 401 Unauthorized\n"\
+                    "Content-Type: text/html\n"\
+                    "Server: Microsoft-IIS/7.5\n"\
+                    "WWW-Authenticate: NTLM\n"\
+                    "X-Powered-By: ASP.NET\n"\
+                    "Date: Thu, 31 Mar 2011 17:41:03 GMT\n"\
+                    "Content-Length: 1293\n\n";
+                printf("sent:%s\n", send_data);
+                fflush(stdout);
+                send(connected, send_data,strlen(send_data), 0);  
+            }
+            else 
+            {
+                break;
+            }
+        }
+    }       
+
+      close(sock);
+      return 0;
+} 
+

Added: axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_server/run.sh
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_server/run.sh?rev=1129578&view=auto
==============================================================================
--- axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_server/run.sh (added)
+++ axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_server/run.sh Tue May 31 09:05:26 2011
@@ -0,0 +1,2 @@
+export LD_LIBRARY_PATH=/tmp/heimdal/lib:/axis2c/deploy/lib
+./mock_server

Propchange: axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/mock_server/run.sh
------------------------------------------------------------------------------
    svn:executable = *

Added: axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/run.sh
URL: http://svn.apache.org/viewvc/axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/run.sh?rev=1129578&view=auto
==============================================================================
--- axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/run.sh (added)
+++ axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/run.sh Tue May 31 09:05:26 2011
@@ -0,0 +1,2 @@
+rm ntlm_test_client.log 
+./test_ntlm

Propchange: axis/axis2/c/core/trunk/src/core/transport/http/sender/ntlm/test/run.sh
------------------------------------------------------------------------------
    svn:executable = *



Mime
View raw message