NULL parameter for user authentication

Oct 10, 2011 at 8:01 PM

Hi

First of all, thank you very much xidar for this great wrapper!
This was exactly was I was looking for.

As many of you, I've also wrote a Windows Service for BITS download jobs. And I had also problems with authentication under the Windows Service.
I read the BITS/net use documentation, there is explained; if a computer is a member of an ActiveDirectory, you can pass the username and password with null.
In this case the "authentication" uses the computer domain membership.

So I changed this little part of the BitsJob2.cs

                if (job2 != null && credentials != null)   // only supported from IBackgroundCopyJob2 and above
                {
                    BG_AUTH_CREDENTIALS bgCredentials = new BG_AUTH_CREDENTIALS();
                    bgCredentials.Scheme = (BG_AUTH_SCHEME)credentials.AuthenticationScheme;
                    bgCredentials.Target = (BG_AUTH_TARGET)credentials.AuthenticationTarget;
                    if (credentials.Password == null)
                    {
                        bgCredentials.Credentials.Basic.Password = null;
                    }
                    else
                    {
                        bgCredentials.Credentials.Basic.Password = credentials.Password.ToString();
                    }

                    if (credentials.UserName == null)
                    {
                        bgCredentials.Credentials.Basic.UserName = null;
                    }
                    else
                    {
                        bgCredentials.Credentials.Basic.UserName = credentials.UserName.ToString();
                    }
                    job2.SetCredentials(ref bgCredentials);
                }
                else
                {
                    throw new NotSupportedException("IBackgroundCopyJob2");
                }

 

This addition worked very well for me. As I'm not a programmer, I hope this is a proper implementation.
If this is not well, please feel free to correct me.

 Cheers