@@ -229,12 +229,17 @@ static HRESULT _job_setproxy(IBackgroundCopyJob *job) {
229229}
230230
231231
232- static HRESULT _job_setcredentials (IBackgroundCopyJob *job, wchar_t *username, wchar_t *password) {
232+ static HRESULT _job_setcredentials (
233+ IBackgroundCopyJob *job,
234+ BG_AUTH_TARGET target,
235+ wchar_t *username,
236+ wchar_t *password
237+ ) {
233238 IBackgroundCopyJob2 *job2 = NULL ;
234239 HRESULT hr;
235240 BG_AUTH_CREDENTIALS creds = {
236- .Target = BG_AUTH_TARGET_SERVER ,
237- .Scheme = BG_AUTH_SCHEME_BASIC,
241+ .Target = target ,
242+ .Scheme = username ? BG_AUTH_SCHEME_BASIC : BG_AUTH_SCHEME_NEGOTIATE ,
238243 .Credentials = {
239244 .Basic = {
240245 .UserName = username,
@@ -243,10 +248,6 @@ static HRESULT _job_setcredentials(IBackgroundCopyJob *job, wchar_t *username, w
243248 }
244249 };
245250
246- if (!username && !password) {
247- return S_OK;
248- }
249-
250251 if (FAILED (hr = _inject_hr[3 ])
251252 || FAILED (hr = job->QueryInterface (__uuidof (IBackgroundCopyJob2), (void **)&job2))) {
252253 return hr;
@@ -285,7 +286,14 @@ PyObject *bits_begin(PyObject *, PyObject *args, PyObject *kwargs) {
285286 error_from_bits_hr (bcm, hr, " Setting proxy" );
286287 goto done;
287288 }
288- if ((username || password) && FAILED (hr = _job_setcredentials (job, username, password))) {
289+ // Setting proxy credentials to NULL will automatically infer credentials
290+ // if needed. It's a good default (provided users have not configured a
291+ // malicious proxy server, which we can't do anything about here anyway).
292+ if (FAILED (hr = _job_setcredentials (job, BG_AUTH_TARGET_PROXY, NULL , NULL ))) {
293+ error_from_bits_hr (bcm, hr, " Setting proxy credentials" );
294+ goto done;
295+ }
296+ if (FAILED (hr = _job_setcredentials (job, BG_AUTH_TARGET_SERVER, username, password))) {
289297 error_from_bits_hr (bcm, hr, " Adding basic credentials to download job" );
290298 goto done;
291299 }
@@ -387,7 +395,7 @@ PyObject *bits_retry_with_auth(PyObject *, PyObject *args, PyObject *kwargs) {
387395 HRESULT hr;
388396 PyObject *r = NULL ;
389397
390- if (FAILED (hr = _job_setcredentials (job, username, password))) {
398+ if (FAILED (hr = _job_setcredentials (job, BG_AUTH_TARGET_SERVER, username, password))) {
391399 error_from_bits_hr (bcm, hr, " Adding basic credentials to download job" );
392400 goto done;
393401 }
0 commit comments