@@ -36,24 +36,24 @@ int sspi_client_init(
36
36
TimeStamp timestamp ;
37
37
38
38
if (username ) {
39
- SEC_WINNT_AUTH_IDENTITY auth_identity ;
40
-
41
- #ifdef _UNICODE
42
- auth_identity .Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE ;
43
- #else
44
- auth_identity .Flags = SEC_WINNT_AUTH_IDENTITY_ANSI ;
45
- #endif
46
- auth_identity .User = (LPSTR ) username ;
47
- auth_identity .UserLength = strlen (username );
48
- auth_identity .Password = NULL ;
49
- auth_identity .PasswordLength = 0 ;
50
39
if (password ) {
40
+ SEC_WINNT_AUTH_IDENTITY auth_identity ;
41
+
42
+ #ifdef _UNICODE
43
+ auth_identity .Flags = SEC_WINNT_AUTH_IDENTITY_UNICODE ;
44
+ #else
45
+ auth_identity .Flags = SEC_WINNT_AUTH_IDENTITY_ANSI ;
46
+ #endif
47
+ auth_identity .User = (LPSTR ) username ;
48
+ auth_identity .UserLength = strlen (username );
51
49
auth_identity .Password = (LPSTR ) password ;
52
50
auth_identity .PasswordLength = strlen (password );
51
+ auth_identity .Domain = NULL ;
52
+ auth_identity .DomainLength = 0 ;
53
+ client -> status = sspi_functions -> AcquireCredentialsHandle (NULL , SSPI_PACKAGE_NAME , SECPKG_CRED_OUTBOUND , NULL , & auth_identity , NULL , NULL , & client -> cred , & timestamp );
54
+ } else {
55
+ client -> status = sspi_functions -> AcquireCredentialsHandle (username , SSPI_PACKAGE_NAME , SECPKG_CRED_OUTBOUND , NULL , NULL , NULL , NULL , & client -> cred , & timestamp );
53
56
}
54
- auth_identity .Domain = NULL ;
55
- auth_identity .DomainLength = 0 ;
56
- client -> status = sspi_functions -> AcquireCredentialsHandle (NULL , SSPI_PACKAGE_NAME , SECPKG_CRED_OUTBOUND , NULL , & auth_identity , NULL , NULL , & client -> cred , & timestamp );
57
57
} else {
58
58
client -> status = sspi_functions -> AcquireCredentialsHandle (NULL , SSPI_PACKAGE_NAME , SECPKG_CRED_OUTBOUND , NULL , NULL , NULL , NULL , & client -> cred , & timestamp );
59
59
}
@@ -65,20 +65,7 @@ int sspi_client_init(
65
65
return SSPI_OK ;
66
66
}
67
67
68
- int sspi_client_destroy (
69
- sspi_client_state * client
70
- )
71
- {
72
- if (client -> has_ctx > 0 ) {
73
- sspi_functions -> DeleteSecurityContext (& client -> ctx );
74
- }
75
-
76
- sspi_functions -> FreeCredentialsHandle (& client -> cred );
77
-
78
- return SSPI_OK ;
79
- }
80
-
81
- int sspi_client_get_username (
68
+ int sspi_client_username (
82
69
sspi_client_state * client ,
83
70
char * * username
84
71
)
@@ -94,17 +81,78 @@ int sspi_client_get_username(
94
81
* username = malloc (len );
95
82
memcpy (* username , names .sUserName , len );
96
83
97
- client -> status = sspi_functions -> FreeContextBuffer (names .sUserName );
98
- if (client -> status != SEC_E_OK ) {
84
+ sspi_functions -> FreeContextBuffer (names .sUserName );
85
+
86
+ return SSPI_OK ;
87
+ }
88
+
89
+ int sspi_client_negotiate (
90
+ sspi_client_state * client ,
91
+ char * spn ,
92
+ PVOID input ,
93
+ ULONG input_length ,
94
+ PVOID * output ,
95
+ ULONG * output_length
96
+ )
97
+ {
98
+ SecBufferDesc inbuf ;
99
+ SecBuffer in_bufs [1 ];
100
+ SecBufferDesc outbuf ;
101
+ SecBuffer out_bufs [1 ];
102
+
103
+ if (client -> has_ctx > 0 ) {
104
+ inbuf .ulVersion = SECBUFFER_VERSION ;
105
+ inbuf .cBuffers = 1 ;
106
+ inbuf .pBuffers = in_bufs ;
107
+ in_bufs [0 ].pvBuffer = input ;
108
+ in_bufs [0 ].cbBuffer = input_length ;
109
+ in_bufs [0 ].BufferType = SECBUFFER_TOKEN ;
110
+ }
111
+
112
+ outbuf .ulVersion = SECBUFFER_VERSION ;
113
+ outbuf .cBuffers = 1 ;
114
+ outbuf .pBuffers = out_bufs ;
115
+ out_bufs [0 ].pvBuffer = NULL ;
116
+ out_bufs [0 ].cbBuffer = 0 ;
117
+ out_bufs [0 ].BufferType = SECBUFFER_TOKEN ;
118
+
119
+ ULONG context_attr = 0 ;
120
+
121
+ client -> status = sspi_functions -> InitializeSecurityContext (
122
+ & client -> cred ,
123
+ client -> has_ctx > 0 ? & client -> ctx : NULL ,
124
+ (LPSTR ) spn ,
125
+ ISC_REQ_ALLOCATE_MEMORY | ISC_REQ_MUTUAL_AUTH ,
126
+ 0 ,
127
+ SECURITY_NETWORK_DREP ,
128
+ client -> has_ctx > 0 ? & inbuf : NULL ,
129
+ 0 ,
130
+ & client -> ctx ,
131
+ & outbuf ,
132
+ & context_attr ,
133
+ NULL );
134
+
135
+ if (client -> status != SEC_E_OK && client -> status != SEC_I_CONTINUE_NEEDED ) {
99
136
return SSPI_ERROR ;
100
137
}
101
138
139
+ client -> has_ctx = 1 ;
140
+
141
+ * output = malloc (out_bufs [0 ].cbBuffer );
142
+ * output_length = out_bufs [0 ].cbBuffer ;
143
+ memcpy (* output , out_bufs [0 ].pvBuffer , * output_length );
144
+ sspi_functions -> FreeContextBuffer (out_bufs [0 ].pvBuffer );
145
+
146
+ if (client -> status == SEC_I_CONTINUE_NEEDED ) {
147
+ return SSPI_CONTINUE ;
148
+ }
149
+
102
150
return SSPI_OK ;
103
151
}
104
152
105
153
int sspi_client_wrap_msg (
106
154
sspi_client_state * client ,
107
- PVOID * input ,
155
+ PVOID input ,
108
156
ULONG input_length ,
109
157
PVOID * output ,
110
158
ULONG * output_length
@@ -156,62 +204,15 @@ int sspi_client_wrap_msg(
156
204
return SSPI_OK ;
157
205
}
158
206
159
- int sspi_init_sec_context (
160
- sspi_client_state * client ,
161
- char * spn ,
162
- PVOID input ,
163
- ULONG input_length ,
164
- PVOID * output ,
165
- ULONG * output_length
207
+ int sspi_client_destroy (
208
+ sspi_client_state * client
166
209
)
167
210
{
168
- SecBufferDesc inbuf ;
169
- SecBuffer in_bufs [1 ];
170
- SecBufferDesc outbuf ;
171
- SecBuffer out_bufs [1 ];
172
-
173
- if (client -> has_ctx > 0 ) {
174
- inbuf .ulVersion = SECBUFFER_VERSION ;
175
- inbuf .cBuffers = 1 ;
176
- inbuf .pBuffers = in_bufs ;
177
- in_bufs [0 ].pvBuffer = input ;
178
- in_bufs [0 ].cbBuffer = input_length ;
179
- in_bufs [0 ].BufferType = SECBUFFER_TOKEN ;
180
- }
181
-
182
- outbuf .ulVersion = SECBUFFER_VERSION ;
183
- outbuf .cBuffers = 1 ;
184
- outbuf .pBuffers = out_bufs ;
185
- out_bufs [0 ].pvBuffer = NULL ;
186
- out_bufs [0 ].cbBuffer = 0 ;
187
- out_bufs [0 ].BufferType = SECBUFFER_TOKEN ;
188
-
189
- ULONG context_attr = 0 ;
190
-
191
- client -> status = sspi_functions -> InitializeSecurityContext (
192
- & client -> cred ,
193
- client -> has_ctx > 0 ? & client -> ctx : NULL ,
194
- (LPSTR ) spn ,
195
- ISC_REQ_ALLOCATE_MEMORY | ISC_REQ_MUTUAL_AUTH ,
196
- 0 ,
197
- SECURITY_NETWORK_DREP ,
198
- client -> has_ctx > 0 ? & inbuf : NULL ,
199
- 0 ,
200
- & client -> ctx ,
201
- & outbuf ,
202
- & context_attr ,
203
- NULL );
204
-
205
- * output = malloc (out_bufs [0 ].cbBuffer );
206
- * output_length = out_bufs [0 ].cbBuffer ;
207
- memcpy (* output , out_bufs [0 ].pvBuffer , * output_length );
208
- client -> has_ctx = 1 ;
209
-
210
- if (client -> status == SEC_I_CONTINUE_NEEDED || client -> status == SEC_I_COMPLETE_AND_CONTINUE ) {
211
- return SSPI_CONTINUE ;
212
- } else if (client -> status == SEC_E_OK ) {
213
- return SSPI_OK ;
211
+ if (client -> has_ctx > 0 ) {
212
+ sspi_functions -> DeleteSecurityContext (& client -> ctx );
214
213
}
215
214
216
- return SSPI_ERROR ;
217
- }
215
+ sspi_functions -> FreeCredentialsHandle (& client -> cred );
216
+
217
+ return SSPI_OK ;
218
+ }
0 commit comments