예제 #1
0
axis2_char_t* AXIS2_CALL
get_ht_password(rampart_callback_t *rcb,
        const axutil_env_t *env, 
        const axis2_char_t *username, 
        void *param)
{
    axis2_char_t * password = NULL;
    FILE *file = NULL;
    /*The default location is the following. But this will be overridden by the property values set in the msg_ctx*/
    axis2_char_t *filename = "/usr/local/apache2/passwd/passwords";

    if(param){
        filename = (axis2_char_t *)param;
    }else{
       AXIS2_LOG_INFO(env->log, "Using the default password file location %s", filename);
    }

    
    file = fopen ( filename, "r" );
    if ( file != NULL )
    {
       axis2_char_t line [ 128 ]; 
       axis2_char_t ch = 0;
       axis2_char_t *res = NULL;
       axis2_char_t *un = NULL;
       axis2_char_t *pw = NULL;

       while ( fgets ( line, sizeof line, file ) != NULL ) 
       {
          res = axutil_strstr(line, ":");
          ch = res[0];
          res[0] = '\0';
          un = (axis2_char_t *) axutil_strdup(env, line);
          res[0] = ch;
          if(0 == axutil_strcmp(un, username)){
             pw = (axis2_char_t *) axutil_strdup( env, &(res[1]));
             password = axutil_strndup(env, pw, axutil_strlen(pw)-1); /*We need to remove the end of line character*/

             break;
          }
       }
       AXIS2_FREE(env->allocator, un);
       AXIS2_FREE(env->allocator, pw);
       fclose ( file );
    }else
    {
       AXIS2_LOG_INFO(env->log, "Cannot load the password file %s in the callback module", filename);
       perror ( filename ); 
    }
    return password;
 };
예제 #2
0
파일: util.c 프로젝트: AdrianRys/wsf
axis2_char_t *
wsclient_get_password (const axutil_env_t *env,
					   const axis2_char_t *username,
					   axis2_char_t *password_file_name)
{
	axis2_char_t *filename = NULL;
    axis2_char_t * password = NULL;
    FILE *file = NULL;

    if(password_file_name)
	{
        filename = password_file_name;
    }else
	{
		AXIS2_LOG_INFO(env->log, "Using the default password file location %s", filename);
    }
    
    file = fopen ( filename, "r" );
    if ( file != NULL )
    {
		axis2_char_t line [ 128 ]; 
		axis2_char_t ch = 0;
		axis2_char_t *res = NULL;
		axis2_char_t *un = NULL;
		axis2_char_t *pw = NULL;

		while ( fgets ( line, sizeof line, file ) != NULL ) 
		{
			res = axutil_strstr(line, ":");
			ch = res[0];
			res[0] = '\0';
			un = (axis2_char_t *) axutil_strdup(env, line);
			res[0] = ch;
			if(0 == axutil_strcmp(un, username)){
				pw = (axis2_char_t *) axutil_strdup(env, &(res[1]));
				password = axutil_strndup(env, pw, axutil_strlen(pw)-1);

				break;
			}
		}
		AXIS2_FREE(env->allocator, un);
		AXIS2_FREE(env->allocator, pw);
		fclose ( file );
    }else
    {
		AXIS2_LOG_INFO(env->log, "Cannot load the password file %s in the callback module", filename);
		perror ( filename ); 
    }
    return password;
}
예제 #3
0
파일: rest_client.c 프로젝트: AdrianRys/wsf
static axis2_char_t*
remote_registry_rest_client_extract_etag_info(const axutil_env_t *env, axis2_char_t *buffer)
{
	axis2_char_t *etag_value = NULL;
	etag_value = axutil_strstr(buffer, REMOTE_REGISTRY_ETAG_HADER_KEY);

	if(etag_value) {
		axis2_char_t *c;
		/* get until the etag start */
		etag_value += sizeof(REMOTE_REGISTRY_ETAG_HADER_KEY) -1;
		/* find the line end */
		for(c = etag_value; *c != '\0'  && *c != '\r'; c ++);
		*c = '\0';
		etag_value = axutil_strdup(env, etag_value);
	}
	return etag_value;
}
예제 #4
0
AXIS2_EXTERN axis2_char_t *AXIS2_CALL
axutil_dll_desc_create_platform_specific_dll_name(
    axutil_dll_desc_t *dll_desc,
    const axutil_env_t *env,
    const axis2_char_t *class_name)
{
    axis2_char_t *temp_name = NULL;

    AXIS2_ENV_CHECK(env, NULL);

    /* allow config to give a literal lib name since it may want a 
     * versioned lib like "libfoo.so.0" */
    if (axutil_strstr(class_name, AXIS2_LIB_SUFFIX)) {
            /* assume the class_name is the literal lib file name */
            dll_desc->dll_name = axutil_strdup(env,class_name);
            return dll_desc->dll_name;
    }

    temp_name = axutil_stracat(env, AXIS2_LIB_PREFIX, class_name);
    dll_desc->dll_name = axutil_stracat(env, temp_name, AXIS2_LIB_SUFFIX);
    AXIS2_FREE(env->allocator, temp_name);
    return dll_desc->dll_name;
}
예제 #5
0
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 = "******",
	            *domain = "mydomain",
	            *password = "******",
	            *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;
}
예제 #6
0
파일: wsf_util.c 프로젝트: harunjuhasz/wsf
void wsf_util_pack_attachments (
    axutil_env_t *env,
    axiom_node_t *node,
    VALUE 		  attach_ht,
    int 		  enable_mtom,
    char 		 *default_cnt_type)
{
    axiom_element_t *node_element = NULL;
    axiom_element_t *child_element = NULL;
    axiom_child_element_iterator_t *child_element_ite = NULL;
    axiom_node_t *child_node = NULL;
    int attachment_done = 0;
    axis2_char_t *element_localname = NULL;
    axiom_namespace_t *element_namespace = NULL;
    axis2_char_t *namespace_uri = NULL;

    if (!node)
        return;

    if (axiom_node_get_node_type(node, env) == AXIOM_ELEMENT)
    {
        node_element = axiom_node_get_data_element(node, env);
        if (node_element)
        {
            child_element_ite = axiom_element_get_child_elements(node_element, env, node);
            if (child_element_ite)
            {
                child_node = axiom_child_element_iterator_next(child_element_ite, env);
                attachment_done = 0;

                while (child_node && !attachment_done)
                {
                    child_element = axiom_node_get_data_element(child_node, env);

                    element_localname = axiom_element_get_localname(child_element, env);
                    if (element_localname && (axutil_strcmp(element_localname, AXIS2_ELEMENT_LN_INCLUDE) == 0))
                    {
                        element_namespace = axiom_element_get_namespace(child_element, env, child_node);
                        if (element_namespace)
                        {
                            namespace_uri = axiom_namespace_get_uri(element_namespace, env);
                            if (namespace_uri && (axutil_strcmp(namespace_uri, AXIS2_NAMESPACE_URI_INCLUDE) == 0))
                            {
                                axis2_char_t *cnt_type = NULL;
                                axis2_char_t *content_type = NULL;
                                axis2_char_t *href = NULL;
                                axis2_char_t* pos = NULL;

                                cnt_type = axiom_element_get_attribute_value_by_name(node_element, env, AXIS2_ELEMENT_ATTR_NAME_CONTENT_TYPE);
                                content_type = !cnt_type ? default_cnt_type : cnt_type;

                                href = axiom_element_get_attribute_value_by_name(child_element, env, AXIS2_ELEMENT_ATTR_NAME_HREF);

                                if ((axutil_strlen(href) > 4) && (pos = axutil_strstr (href, "cid:")))
                                {
                                    axis2_char_t* cid = NULL;
                                    VALUE content_tmp;
                                    void* content = NULL;
                                    unsigned int content_length = 0;

                                    cid = href + 4;

                                    content_tmp = rb_hash_aref(attach_ht, rb_str_new2(cid));
                                    content_length = RSTRING(content_tmp)->len;

                                    content = malloc(sizeof (char) * content_length);
                                    memcpy (content, (const void*)STR2CSTR(content_tmp), content_length);

                                    if (content)
                                    {
                                        void *data_buffer = NULL;
                                        axiom_data_handler_t *data_handler = NULL;
                                        axiom_node_t *text_node = NULL;
                                        axiom_text_t *text = NULL;

                                        data_buffer = AXIS2_MALLOC (env->allocator, sizeof (char) * content_length);
                                        if (data_buffer)
                                        {
                                            memcpy (data_buffer, content, content_length);

                                            data_handler = axiom_data_handler_create (env, NULL, content_type);
                                            if (data_handler)
                                            {
                                                axiom_data_handler_set_binary_data (data_handler, env, (axis2_byte_t *)content, content_length);

                                                text = axiom_text_create_with_data_handler (env, node, data_handler, &text_node);

                                                if (enable_mtom == AXIS2_FALSE)
                                                    axiom_text_set_optimize (text, env, AXIS2_FALSE);

                                                axiom_node_detach (child_node, env);
                                            }
                                        }

                                        attachment_done = 1;
                                    }
                                }
                            }
                        }
                    }

                    child_node = axiom_child_element_iterator_next(child_element_ite, env);
                }
            }
        }
    }

    // Process child nodes
    child_node = axiom_node_get_first_child(node, env);
    while (child_node)
    {
        wsf_util_pack_attachments(env, child_node, attach_ht, enable_mtom, default_cnt_type);

        child_node = axiom_node_get_next_sibling(child_node, env);
    }
}
예제 #7
0
파일: svc.c 프로젝트: Denisss025/wsfcpp
AXIS2_EXTERN axis2_op_t *AXIS2_CALL
axis2_svc_get_op_with_qname(
    const axis2_svc_t * svc,
    const axutil_env_t * env,
    const axutil_qname_t * op_qname)
{
    axis2_op_t *op = NULL;
    axis2_char_t *nc_name = NULL;

    axis2_char_t *nc_tmp = NULL;
    /* This is just for the sake of comparison,
     * and must not be used to change the passed value
     */
    axis2_bool_t is_matched = AXIS2_FALSE;

    AXIS2_PARAM_CHECK(env->error, op_qname, NULL);

    nc_name = axutil_qname_get_localpart(op_qname, env);
    nc_tmp = nc_name;

    op = axutil_hash_get(svc->op_alias_map, nc_tmp, AXIS2_HASH_KEY_STRING);
    if(op)
    {
        return op;
    }
    op = axutil_hash_get(svc->op_action_map, nc_tmp, AXIS2_HASH_KEY_STRING);
    if(op)
    {
        return op;
    }

    if(*nc_tmp && svc->op_action_map)
    {
        axutil_hash_index_t *hi = NULL;
        const void *key = NULL;

        for(hi = axutil_hash_first(svc->op_action_map, env); hi; hi = axutil_hash_next(env, hi))
        {
            axutil_hash_this(hi, &key, NULL, NULL);

            nc_tmp = nc_name;

            if(key)
            {
                axis2_char_t *search = NULL;
                axis2_bool_t match_start = AXIS2_TRUE;
                axis2_char_t *search_tmp = NULL;

                search = (axis2_char_t *)key;

                if(!axutil_strchr(search, '*'))
                {
                    if(axutil_strstr(nc_tmp, search))
                    {
                        axis2_char_t *comp_tmp = NULL;

                        comp_tmp = axutil_strstr(nc_tmp, search);
                        if(strlen(comp_tmp) == strlen(search))
                        {
                            nc_tmp = (axis2_char_t *)key;
                            is_matched = AXIS2_TRUE;
                            break;
                        }
                    }
                    continue;
                }

                if(search[0] == '*')
                {
                    search++;
                    if(!*search)
                    {
                        nc_tmp = (axis2_char_t *)key;
                        is_matched = AXIS2_TRUE;
                        break;
                    }
                    else if(axutil_strchr(search, '*'))
                    {
                        continue;
                    }
                    match_start = AXIS2_FALSE;
                }
                while(search && *search)
                {
                    size_t length = 0;
                    axis2_char_t *loc_tmp = NULL;

                    if(search_tmp)
                    {
                        AXIS2_FREE(env->allocator, search_tmp);
                        search_tmp = NULL;
                    }
                    loc_tmp = axutil_strchr(search, '*');
                    if(loc_tmp && *loc_tmp)
                    {
                        if(!loc_tmp[1])
                        {
                            is_matched = AXIS2_TRUE;
                            break;
                        }
                        length = (size_t)(loc_tmp - search);
                        /* We are sure that the difference lies within the int range */
                        search_tmp = (axis2_char_t *)(AXIS2_MALLOC(env->allocator,
                                                      sizeof(axis2_char_t) * (length + 1)));
                        strncpy(search_tmp, search, length);
                        search_tmp[length] = '\0';
                    }
                    else if(axutil_strstr(nc_tmp, search))
                    {
                        axis2_char_t *comp_tmp = NULL;

                        comp_tmp = axutil_strstr(nc_tmp, search);
                        if(strlen(comp_tmp) == strlen(search))
                        {
                            nc_tmp = (axis2_char_t *)key;
                            is_matched = AXIS2_TRUE;
                            break;
                        }
                        break;
                    }
                    else
                    {
                        break;
                    }
                    if(search_tmp && axutil_strstr(nc_tmp, search_tmp))
                    {
                        if(match_start && !(axutil_strncmp(nc_tmp, search, (int)length) == 0))
                        {
                            break;
                        }
                        else if(!match_start)
                        {
                            match_start = AXIS2_TRUE;
                        }
                    }
                    else
                    {
                        break;
                    }
                    search += axutil_strlen(search_tmp) + 1;
                    nc_tmp = axutil_strstr(nc_tmp, search_tmp) + axutil_strlen(search_tmp);
                }
                if(search_tmp)
                {
                    AXIS2_FREE(env->allocator, search_tmp);
                    search_tmp = NULL;
                }
                if(is_matched || !search || !*search)
                {
                    nc_tmp = (axis2_char_t *)key;
                    is_matched = AXIS2_TRUE;
                    break;
                }
            }
        }
    }
    if(!is_matched)
    {
        nc_tmp = nc_name;
    }

    op = axutil_hash_get(svc->op_alias_map, nc_tmp, AXIS2_HASH_KEY_STRING);
    if(op)
    {
        return op;
    }
    return (axis2_op_t *)axutil_hash_get(svc->op_action_map, nc_tmp, AXIS2_HASH_KEY_STRING);
}
AXIS2_EXTERN axis2_http_request_line_t *AXIS2_CALL
axis2_http_request_line_parse_line(
    const axutil_env_t * env,
    const axis2_char_t * str)
{
    axis2_char_t *req_line = NULL;
    axis2_char_t *method = NULL;
    axis2_char_t *uri = NULL;
    axis2_char_t *http_version = NULL;
    axis2_http_request_line_t *ret = NULL;
    axis2_char_t *tmp = NULL;
    int i = 0;

    AXIS2_PARAM_CHECK(env->error, str, NULL);

    tmp = axutil_strstr(str, AXIS2_HTTP_CRLF);

    if (!tmp)
    {
        AXIS2_HANDLE_ERROR(env,
                           AXIS2_ERROR_INVALID_HTTP_HEADER_START_LINE,
                           AXIS2_FAILURE);
        return NULL;
    }

    i = (int)(tmp - str);
    /* We are sure that the difference lies within the int range */
    req_line = AXIS2_MALLOC(env->allocator, i * sizeof(axis2_char_t) + 1);
    if (!req_line)
    {
        AXIS2_HANDLE_ERROR(env, AXIS2_ERROR_NO_MEMORY, AXIS2_FAILURE);
        return NULL;
    }
    memcpy(req_line, str, i * sizeof(axis2_char_t));
    req_line[i] = AXIS2_ESC_NULL;
    tmp = req_line;

    method = tmp;
    tmp = strchr(tmp, AXIS2_SPACE);
    if (!tmp)
    {
        AXIS2_FREE(env->allocator, req_line);
        AXIS2_HANDLE_ERROR(env,
                           AXIS2_ERROR_INVALID_HTTP_HEADER_START_LINE,
                           AXIS2_FAILURE);
        return NULL;
    }
    *tmp++ = AXIS2_ESC_NULL;
    uri = tmp;
    tmp = strrchr(tmp, AXIS2_SPACE);
    if (!tmp)
    {
        AXIS2_FREE(env->allocator, req_line);
        AXIS2_HANDLE_ERROR(env,
                           AXIS2_ERROR_INVALID_HTTP_HEADER_START_LINE,
                           AXIS2_FAILURE);
        return NULL;
    }
    *tmp++ = AXIS2_ESC_NULL;
    http_version = tmp;
    ret = axis2_http_request_line_create(env, method, uri, http_version);
    AXIS2_FREE(env->allocator, req_line);

    return ret;
}