Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-cw
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wine
wine-cw
Commits
70c6a8ac
Commit
70c6a8ac
authored
Aug 26, 2008
by
Hans Leidekker
Committed by
Alexandre Julliard
Aug 27, 2008
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
winhttp: Implement WinHttpSetCredentials.
Only supports the basic authentication scheme.
parent
3f85f455
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
134 additions
and
1 deletion
+134
-1
request.c
dlls/winhttp/request.c
+133
-0
winhttp.spec
dlls/winhttp/winhttp.spec
+1
-1
No files found.
dlls/winhttp/request.c
View file @
70c6a8ac
...
...
@@ -1232,3 +1232,136 @@ BOOL WINAPI WinHttpQueryAuthSchemes( HINTERNET hrequest, LPDWORD supported, LPDW
release_object
(
&
request
->
hdr
);
return
ret
;
}
static
UINT
encode_base64
(
const
char
*
bin
,
unsigned
int
len
,
WCHAR
*
base64
)
{
UINT
n
=
0
,
x
;
static
const
char
base64enc
[]
=
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"
;
while
(
len
>
0
)
{
/* first 6 bits, all from bin[0] */
base64
[
n
++
]
=
base64enc
[(
bin
[
0
]
&
0xfc
)
>>
2
];
x
=
(
bin
[
0
]
&
3
)
<<
4
;
/* next 6 bits, 2 from bin[0] and 4 from bin[1] */
if
(
len
==
1
)
{
base64
[
n
++
]
=
base64enc
[
x
];
base64
[
n
++
]
=
'='
;
base64
[
n
++
]
=
'='
;
break
;
}
base64
[
n
++
]
=
base64enc
[
x
|
((
bin
[
1
]
&
0xf0
)
>>
4
)];
x
=
(
bin
[
1
]
&
0x0f
)
<<
2
;
/* next 6 bits 4 from bin[1] and 2 from bin[2] */
if
(
len
==
2
)
{
base64
[
n
++
]
=
base64enc
[
x
];
base64
[
n
++
]
=
'='
;
break
;
}
base64
[
n
++
]
=
base64enc
[
x
|
((
bin
[
2
]
&
0xc0
)
>>
6
)];
/* last 6 bits, all from bin [2] */
base64
[
n
++
]
=
base64enc
[
bin
[
2
]
&
0x3f
];
bin
+=
3
;
len
-=
3
;
}
base64
[
n
]
=
0
;
return
n
;
}
static
BOOL
set_credentials
(
request_t
*
request
,
DWORD
target
,
DWORD
scheme
,
LPCWSTR
username
,
LPCWSTR
password
)
{
static
const
WCHAR
basic
[]
=
{
'B'
,
'a'
,
's'
,
'i'
,
'c'
,
' '
,
0
};
const
WCHAR
*
auth_scheme
,
*
auth_target
;
WCHAR
*
auth_header
;
DWORD
len
,
auth_data_len
;
char
*
auth_data
;
BOOL
ret
;
switch
(
target
)
{
case
WINHTTP_AUTH_TARGET_SERVER
:
auth_target
=
attr_authorization
;
break
;
case
WINHTTP_AUTH_TARGET_PROXY
:
auth_target
=
attr_proxy_authorization
;
break
;
default:
WARN
(
"unknown target %x
\n
"
,
target
);
return
FALSE
;
}
switch
(
scheme
)
{
case
WINHTTP_AUTH_SCHEME_BASIC
:
{
int
userlen
=
WideCharToMultiByte
(
CP_UTF8
,
0
,
username
,
strlenW
(
username
),
NULL
,
0
,
NULL
,
NULL
);
int
passlen
=
WideCharToMultiByte
(
CP_UTF8
,
0
,
password
,
strlenW
(
password
),
NULL
,
0
,
NULL
,
NULL
);
TRACE
(
"basic authentication
\n
"
);
auth_scheme
=
basic
;
auth_data_len
=
userlen
+
1
+
passlen
;
if
(
!
(
auth_data
=
heap_alloc
(
auth_data_len
)))
return
FALSE
;
WideCharToMultiByte
(
CP_UTF8
,
0
,
username
,
-
1
,
auth_data
,
userlen
,
NULL
,
NULL
);
auth_data
[
userlen
]
=
':'
;
WideCharToMultiByte
(
CP_UTF8
,
0
,
password
,
-
1
,
auth_data
+
userlen
+
1
,
passlen
,
NULL
,
NULL
);
break
;
}
case
WINHTTP_AUTH_SCHEME_NTLM
:
case
WINHTTP_AUTH_SCHEME_PASSPORT
:
case
WINHTTP_AUTH_SCHEME_DIGEST
:
case
WINHTTP_AUTH_SCHEME_NEGOTIATE
:
FIXME
(
"unimplemented authentication scheme %x
\n
"
,
scheme
);
return
FALSE
;
default:
WARN
(
"unknown authentication scheme %x
\n
"
,
scheme
);
return
FALSE
;
}
len
=
strlenW
(
auth_scheme
)
+
((
auth_data_len
+
2
)
*
4
)
/
3
;
if
(
!
(
auth_header
=
heap_alloc
(
(
len
+
1
)
*
sizeof
(
WCHAR
)
)))
{
heap_free
(
auth_data
);
return
FALSE
;
}
strcpyW
(
auth_header
,
auth_scheme
);
encode_base64
(
auth_data
,
auth_data_len
,
auth_header
+
strlenW
(
auth_header
)
);
ret
=
process_header
(
request
,
auth_target
,
auth_header
,
WINHTTP_ADDREQ_FLAG_ADD
|
WINHTTP_ADDREQ_FLAG_REPLACE
,
TRUE
);
heap_free
(
auth_data
);
heap_free
(
auth_header
);
return
ret
;
}
/***********************************************************************
* WinHttpSetCredentials (winhttp.@)
*/
BOOL
WINAPI
WinHttpSetCredentials
(
HINTERNET
hrequest
,
DWORD
target
,
DWORD
scheme
,
LPCWSTR
username
,
LPCWSTR
password
,
LPVOID
params
)
{
BOOL
ret
;
request_t
*
request
;
TRACE
(
"%p, %x, 0x%08x, %s, %p, %p
\n
"
,
hrequest
,
target
,
scheme
,
debugstr_w
(
username
),
password
,
params
);
if
(
!
(
request
=
(
request_t
*
)
grab_object
(
hrequest
)))
{
set_last_error
(
ERROR_INVALID_HANDLE
);
return
FALSE
;
}
if
(
request
->
hdr
.
type
!=
WINHTTP_HANDLE_TYPE_REQUEST
)
{
release_object
(
&
request
->
hdr
);
set_last_error
(
ERROR_WINHTTP_INCORRECT_HANDLE_TYPE
);
return
FALSE
;
}
ret
=
set_credentials
(
request
,
target
,
scheme
,
username
,
password
);
release_object
(
&
request
->
hdr
);
return
ret
;
}
dlls/winhttp/winhttp.spec
View file @
70c6a8ac
...
...
@@ -21,7 +21,7 @@
@ stdcall WinHttpReadData(ptr ptr long ptr)
@ stdcall WinHttpReceiveResponse(ptr ptr)
@ stdcall WinHttpSendRequest(ptr wstr long ptr long long ptr)
@ st
ub WinHttpSetCredentials
@ st
dcall WinHttpSetCredentials(ptr long long wstr ptr ptr)
@ stdcall WinHttpSetDefaultProxyConfiguration(ptr)
@ stdcall WinHttpSetOption(ptr long ptr long)
@ stdcall WinHttpSetStatusCallback(ptr ptr long ptr)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment