Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
W
wine-winehq
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-winehq
Commits
4cd377d4
Commit
4cd377d4
authored
May 19, 2006
by
Mike McCormack
Committed by
Alexandre Julliard
May 20, 2006
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
secur32: Cleanup InitializeSecurityContext (reduce indent and duplication).
parent
d243b39c
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
56 additions
and
134 deletions
+56
-134
ntlm.c
dlls/secur32/ntlm.c
+56
-134
No files found.
dlls/secur32/ntlm.c
View file @
4cd377d4
...
...
@@ -395,19 +395,29 @@ static SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextW(
PSecBufferDesc
pOutput
,
ULONG
*
pfContextAttr
,
PTimeStamp
ptsExpiry
)
{
SECURITY_STATUS
ret
;
PNegoHelper
helper
;
ULONG
ctxt_attr
=
0
;
char
*
buffer
;
PBYTE
bin
;
int
buffer_len
,
bin_len
,
max_len
=
NTLM_MAX_BUF
;
TRACE
(
"%p %p %s %ld %ld %ld %p %ld %p %p %p %p
\n
"
,
phCredential
,
phContext
,
debugstr_w
(
pszTargetName
),
fContextReq
,
Reserved1
,
TargetDataRep
,
pInput
,
Reserved1
,
phNewContext
,
pOutput
,
pfContextAttr
,
ptsExpiry
);
if
(
phCredential
){
if
(
!
phCredential
)
return
SEC_E_INVALID_HANDLE
;
/* As the server side of sspi never calls this, make sure that
* the handler is a client handler.
*/
PNegoHelper
helper
=
(
PNegoHelper
)
phCredential
->
dwLower
;
ULONG
ctxt_attr
=
0
;
if
(
helper
->
mode
==
NTLM_CLIENT
)
helper
=
(
PNegoHelper
)
phCredential
->
dwLower
;
if
(
helper
->
mode
!=
NTLM_CLIENT
)
{
TRACE
(
"Helper mode = %d
\n
"
,
helper
->
mode
);
return
SEC_E_INVALID_HANDLE
;
}
/****************************************
* When communicating with the client, there can be the
* following reply packets:
...
...
@@ -418,16 +428,8 @@ static SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextW(
* sent to server with KK prefixed
* BH <char reason> something broke
*/
BOOL
first
=
FALSE
;
/* The squid cache size is 2010 chars, and that's what ntlm_auth uses */
char
*
buffer
=
HeapAlloc
(
GetProcessHeap
(),
0
,
sizeof
(
char
)
*
NTLM_MAX_BUF
);
PBYTE
bin
=
HeapAlloc
(
GetProcessHeap
(),
0
,
sizeof
(
BYTE
)
*
NTLM_MAX_BUF
);
int
buffer_len
,
bin_len
,
max_len
=
NTLM_MAX_BUF
;
if
((
phContext
==
NULL
)
&&
(
pInput
==
NULL
))
first
=
TRUE
;
if
(
pszTargetName
)
{
TRACE
(
"According to a MS whitepaper pszTargetName is ignored.
\n
"
);
...
...
@@ -443,38 +445,28 @@ static SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextW(
ctxt_attr
|=
ISC_RET_CONNECTION
;
}
if
(
fContextReq
&
ISC_REQ_EXTENDED_ERROR
)
{
FIXME
(
"InitializeSecurityContext(): ISC_REQ_EXTENDED_ERROR stub
\n
"
);
}
FIXME
(
"ISC_REQ_EXTENDED_ERROR
\n
"
);
if
(
fContextReq
&
ISC_REQ_INTEGRITY
)
{
FIXME
(
"InitializeSecurityContext(): ISC_REQ_INTEGRITY stub
\n
"
);
}
FIXME
(
"ISC_REQ_INTEGRITY
\n
"
);
if
(
fContextReq
&
ISC_REQ_MUTUAL_AUTH
)
{
FIXME
(
"InitializeSecurityContext(): ISC_REQ_MUTUAL_AUTH stub
\n
"
);
}
FIXME
(
"ISC_REQ_MUTUAL_AUTH
\n
"
);
if
(
fContextReq
&
ISC_REQ_REPLAY_DETECT
)
{
FIXME
(
"InitializeSecurityContext(): ISC_REQ_REPLAY_DETECT stub
\n
"
);
}
FIXME
(
"ISC_REQ_REPLAY_DETECT
\n
"
);
if
(
fContextReq
&
ISC_REQ_SEQUENCE_DETECT
)
{
FIXME
(
"InitializeSecurityContext(): ISC_REQ_SEQUENCE_DETECT stub
\n
"
);
}
FIXME
(
"ISC_REQ_SEQUENCE_DETECT
\n
"
);
if
(
fContextReq
&
ISC_REQ_STREAM
)
{
FIXME
(
"InitializeSecurityContext(): ISC_REQ_STREAM stub
\n
"
);
}
FIXME
(
"ISC_REQ_STREAM
\n
"
);
/* Done with the flags */
if
(
TargetDataRep
==
SECURITY_NETWORK_DREP
){
FIXME
(
"Don't know how to do SECURITY_NETWORK_DREP
\n
"
);
HeapFree
(
GetProcessHeap
(),
0
,
buffer
);
HeapFree
(
GetProcessHeap
(),
0
,
bin
);
return
SEC_E_UNSUPPORTED_FUNCTION
;
}
if
(
first
)
buffer
=
HeapAlloc
(
GetProcessHeap
(),
0
,
sizeof
(
char
)
*
NTLM_MAX_BUF
);
bin
=
HeapAlloc
(
GetProcessHeap
(),
0
,
sizeof
(
BYTE
)
*
NTLM_MAX_BUF
);
if
((
phContext
==
NULL
)
&&
(
pInput
==
NULL
))
{
TRACE
(
"First time in ISC()
\n
"
);
/* Request a challenge request from ntlm_auth */
...
...
@@ -493,83 +485,36 @@ static SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextW(
TRACE
(
"Deleting password!
\n
"
);
memset
(
helper
->
password
,
0
,
helper
->
pwlen
-
2
);
HeapFree
(
GetProcessHeap
(),
0
,
helper
->
password
);
HeapFree
(
GetProcessHeap
(),
0
,
buffer
);
HeapFree
(
GetProcessHeap
(),
0
,
bin
);
return
ret
;
goto
end
;
}
}
TRACE
(
"Sending to helper: %s
\n
"
,
debugstr_a
(
buffer
));
if
((
ret
=
run_helper
(
helper
,
buffer
,
max_len
,
&
buffer_len
))
!=
SEC_E_OK
)
{
HeapFree
(
GetProcessHeap
(),
0
,
buffer
);
HeapFree
(
GetProcessHeap
(),
0
,
bin
);
return
ret
;
}
if
((
ret
=
run_helper
(
helper
,
buffer
,
max_len
,
&
buffer_len
))
!=
SEC_E_OK
)
goto
end
;
TRACE
(
"Helper returned %s
\n
"
,
debugstr_a
(
buffer
));
lstrcpynA
(
buffer
,
"YR"
,
max_len
-
1
);
if
((
ret
=
run_helper
(
helper
,
buffer
,
max_len
,
&
buffer_len
))
!=
SEC_E_OK
)
{
HeapFree
(
GetProcessHeap
(),
0
,
buffer
);
HeapFree
(
GetProcessHeap
(),
0
,
bin
);
return
ret
;
}
if
((
ret
=
run_helper
(
helper
,
buffer
,
max_len
,
&
buffer_len
))
!=
SEC_E_OK
)
goto
end
;
TRACE
(
"%s
\n
"
,
buffer
);
if
(
strncmp
(
buffer
,
"YR "
,
3
)
!=
0
)
{
/* Something borked */
TRACE
(
"Helper returned %c%c
\n
"
,
buffer
[
0
],
buffer
[
1
]);
HeapFree
(
GetProcessHeap
(),
0
,
buffer
);
HeapFree
(
GetProcessHeap
(),
0
,
bin
);
return
SEC_E_INTERNAL_ERROR
;
ret
=
SEC_E_INTERNAL_ERROR
;
goto
end
;
}
if
((
ret
=
decodeBase64
(
buffer
+
3
,
buffer_len
-
3
,
bin
,
max_len
-
1
,
&
bin_len
))
!=
SEC_E_OK
)
{
HeapFree
(
GetProcessHeap
(),
0
,
buffer
);
HeapFree
(
GetProcessHeap
(),
0
,
bin
);
return
ret
;
}
goto
end
;
/* put the decoded client blob into the out buffer */
if
(
fContextReq
&
ISC_REQ_ALLOCATE_MEMORY
)
{
if
(
pOutput
)
{
pOutput
->
cBuffers
=
1
;
pOutput
->
pBuffers
[
0
].
pvBuffer
=
SECUR32_ALLOC
(
bin_len
);
pOutput
->
pBuffers
[
0
].
cbBuffer
=
bin_len
;
}
}
if
(
!
pOutput
||
!
pOutput
->
cBuffers
||
pOutput
->
pBuffers
[
0
].
cbBuffer
<
bin_len
)
{
TRACE
(
"out buffer is NULL or has not enough space
\n
"
);
HeapFree
(
GetProcessHeap
(),
0
,
buffer
);
HeapFree
(
GetProcessHeap
(),
0
,
bin
);
return
SEC_E_BUFFER_TOO_SMALL
;
}
if
(
!
pOutput
->
pBuffers
[
0
].
pvBuffer
)
{
TRACE
(
"out buffer is NULL
\n
"
);
HeapFree
(
GetProcessHeap
(),
0
,
buffer
);
HeapFree
(
GetProcessHeap
(),
0
,
bin
);
return
SEC_E_INTERNAL_ERROR
;
}
pOutput
->
pBuffers
[
0
].
cbBuffer
=
bin_len
;
pOutput
->
pBuffers
[
0
].
BufferType
=
SECBUFFER_DATA
;
memcpy
(
pOutput
->
pBuffers
[
0
].
pvBuffer
,
bin
,
bin_len
);
ret
=
SEC_I_CONTINUE_NEEDED
;
}
else
...
...
@@ -578,25 +523,22 @@ static SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextW(
/* encode server data to base64 */
if
(
!
pInput
||
!
pInput
->
cBuffers
)
{
HeapFree
(
GetProcessHeap
(),
0
,
buffer
);
HeapFree
(
GetProcessHeap
(),
0
,
bin
);
return
SEC_E_INCOMPLETE_MESSAGE
;
ret
=
SEC_E_INCOMPLETE_MESSAGE
;
goto
end
;
}
if
(
!
pInput
->
pBuffers
[
0
].
pvBuffer
)
{
HeapFree
(
GetProcessHeap
(),
0
,
buffer
);
HeapFree
(
GetProcessHeap
(),
0
,
bin
);
return
SEC_E_INTERNAL_ERROR
;
ret
=
SEC_E_INTERNAL_ERROR
;
goto
end
;
}
if
(
pInput
->
pBuffers
[
0
].
cbBuffer
>
max_len
)
{
TRACE
(
"pInput->pBuffers[0].cbBuffer is: %ld
\n
"
,
pInput
->
pBuffers
[
0
].
cbBuffer
);
HeapFree
(
GetProcessHeap
(),
0
,
buffer
);
HeapFree
(
GetProcessHeap
(),
0
,
bin
);
return
SEC_E_INVALID_TOKEN
;
ret
=
SEC_E_INVALID_TOKEN
;
goto
end
;
}
else
bin_len
=
pInput
->
pBuffers
[
0
].
cbBuffer
;
...
...
@@ -607,22 +549,13 @@ static SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextW(
if
((
ret
=
encodeBase64
(
bin
,
bin_len
,
buffer
+
3
,
max_len
-
3
,
&
buffer_len
))
!=
SEC_E_OK
)
{
HeapFree
(
GetProcessHeap
(),
0
,
buffer
);
HeapFree
(
GetProcessHeap
(),
0
,
bin
);
return
ret
;
}
goto
end
;
TRACE
(
"Server sent: %s
\n
"
,
debugstr_a
(
buffer
));
/* send TT base64 blob to ntlm_auth */
if
((
ret
=
run_helper
(
helper
,
buffer
,
max_len
,
&
buffer_len
))
!=
SEC_E_OK
)
{
HeapFree
(
GetProcessHeap
(),
0
,
buffer
);
HeapFree
(
GetProcessHeap
(),
0
,
bin
);
return
ret
;
}
if
((
ret
=
run_helper
(
helper
,
buffer
,
max_len
,
&
buffer_len
))
!=
SEC_E_OK
)
goto
end
;
TRACE
(
"Helper replied: %s
\n
"
,
debugstr_a
(
buffer
));
...
...
@@ -644,6 +577,12 @@ static SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextW(
return
ret
;
}
phNewContext
->
dwUpper
=
ctxt_attr
;
phNewContext
->
dwLower
=
ret
;
ret
=
SEC_E_OK
;
}
/* put the decoded client blob into the out buffer */
if
(
fContextReq
&
ISC_REQ_ALLOCATE_MEMORY
)
...
...
@@ -659,29 +598,21 @@ static SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextW(
if
(
!
pOutput
||
!
pOutput
->
cBuffers
||
pOutput
->
pBuffers
[
0
].
cbBuffer
<
bin_len
)
{
TRACE
(
"out buffer is NULL or has not enough space
\n
"
);
HeapFree
(
GetProcessHeap
(),
0
,
buffer
);
HeapFree
(
GetProcessHeap
(),
0
,
bin
);
return
SEC_E_BUFFER_TOO_SMALL
;
ret
=
SEC_E_BUFFER_TOO_SMALL
;
goto
end
;
}
if
(
!
pOutput
->
pBuffers
[
0
].
pvBuffer
)
{
TRACE
(
"out buffer is NULL
\n
"
);
HeapFree
(
GetProcessHeap
(),
0
,
buffer
);
HeapFree
(
GetProcessHeap
(),
0
,
bin
);
return
SEC_E_INTERNAL_ERROR
;
ret
=
SEC_E_INTERNAL_ERROR
;
goto
end
;
}
pOutput
->
pBuffers
[
0
].
cbBuffer
=
bin_len
;
pOutput
->
pBuffers
[
0
].
BufferType
=
SECBUFFER_DATA
;
memcpy
(
pOutput
->
pBuffers
[
0
].
pvBuffer
,
bin
,
bin_len
);
ret
=
SEC_E_OK
;
phNewContext
->
dwUpper
=
ctxt_attr
;
phNewContext
->
dwLower
=
ret
;
}
HeapFree
(
GetProcessHeap
(),
0
,
buffer
);
HeapFree
(
GetProcessHeap
(),
0
,
bin
);
if
(
ret
!=
SEC_I_CONTINUE_NEEDED
)
{
TRACE
(
"Deleting password!
\n
"
);
...
...
@@ -689,18 +620,9 @@ static SECURITY_STATUS SEC_ENTRY ntlm_InitializeSecurityContextW(
memset
(
helper
->
password
,
0
,
helper
->
pwlen
-
2
);
HeapFree
(
GetProcessHeap
(),
0
,
helper
->
password
);
}
}
else
{
ret
=
SEC_E_INVALID_HANDLE
;
TRACE
(
"Helper mode = %d
\n
"
,
helper
->
mode
);
}
}
else
{
ret
=
SEC_E_INVALID_HANDLE
;
}
end:
HeapFree
(
GetProcessHeap
(),
0
,
buffer
);
HeapFree
(
GetProcessHeap
(),
0
,
bin
);
return
ret
;
}
...
...
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