Skip to content

Commit

Permalink
adjusted to support NTLM for proxies
Browse files Browse the repository at this point in the history
  • Loading branch information
bagder committed Jul 21, 2003
1 parent 56014e7 commit 1a192c4
Showing 1 changed file with 39 additions and 18 deletions.
57 changes: 39 additions & 18 deletions lib/http_ntlm.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
#include "strequal.h"
#include "base64.h"
#include "http_ntlm.h"
#include "url.h"

#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
Expand Down Expand Up @@ -269,7 +270,8 @@ static void mkhash(char *password,
(((x) >>16)&0xff), ((x)>>24)

/* this is for creating ntlm header output */
CURLcode Curl_output_ntlm(struct connectdata *conn)
CURLcode Curl_output_ntlm(struct connectdata *conn,
bool proxy)
{
const char *domain=""; /* empty */
const char *host=""; /* empty */
Expand All @@ -279,8 +281,27 @@ CURLcode Curl_output_ntlm(struct connectdata *conn)
int domoff; /* domain name offset */
int size;
char *base64=NULL;

unsigned char ntlm[256]; /* enough, unless the host/domain is very long */

/* point to the address of the pointer that holds the string to sent to the
server, which is for a plain host or for a HTTP proxy */
char **allocuserpwd;

/* point to the name and password for this */
char *userp;
char *passwdp;

if(proxy) {
allocuserpwd = &conn->allocptr.proxyuserpwd;
userp = conn->proxyuser;
passwdp = conn->proxypasswd;
}
else {
allocuserpwd = &conn->allocptr.userpwd;
userp = conn->user;
passwdp = conn->passwd;
}

switch(conn->ntlm.state) {
case NTLMSTATE_TYPE1:
default: /* for the weird cases we (re)start here */
Expand Down Expand Up @@ -338,10 +359,10 @@ CURLcode Curl_output_ntlm(struct connectdata *conn)
size = Curl_base64_encode(ntlm, size, &base64);

if(size >0 ) {
if(conn->allocptr.userpwd)
free(conn->allocptr.userpwd);
conn->allocptr.userpwd = aprintf("Authorization: NTLM %s\r\n",
base64);
Curl_safefree(*allocuserpwd);
*allocuserpwd = aprintf("%sAuthorization: NTLM %s\r\n",
proxy?"Proxy-":"",
base64);
free(base64);
}
else
Expand Down Expand Up @@ -378,20 +399,20 @@ CURLcode Curl_output_ntlm(struct connectdata *conn)
const char *user;
int userlen;

user = strchr(conn->user, '\\');
user = strchr(userp, '\\');
if(!user)
user = strchr(conn->user, '/');
user = strchr(userp, '/');

if (user) {
domain = conn->user;
domain = userp;
domlen = user - domain;
user++;
}
else
user = conn->user;
user = userp;
userlen = strlen(user);

mkhash(conn->passwd, &conn->ntlm.nonce[0], lmresp
mkhash(passwdp, &conn->ntlm.nonce[0], lmresp
#ifdef USE_NTRESPONSES
, ntresp
#endif
Expand Down Expand Up @@ -511,10 +532,10 @@ CURLcode Curl_output_ntlm(struct connectdata *conn)
size = Curl_base64_encode(ntlm, size, &base64);

if(size >0 ) {
if(conn->allocptr.userpwd)
free(conn->allocptr.userpwd);
conn->allocptr.userpwd = aprintf("Authorization: NTLM %s\r\n",
base64);
Curl_safefree(*allocuserpwd);
*allocuserpwd = aprintf("%sAuthorization: NTLM %s\r\n",
proxy?"Proxy-":"",
base64);
free(base64);
}
else
Expand All @@ -528,9 +549,9 @@ CURLcode Curl_output_ntlm(struct connectdata *conn)
case NTLMSTATE_TYPE3:
/* connection is already authenticated,
* don't send a header in future requests */
if(conn->allocptr.userpwd) {
free(conn->allocptr.userpwd);
conn->allocptr.userpwd=NULL;
if(*allocuserpwd) {
free(*allocuserpwd);
*allocuserpwd=NULL;
}
break;
}
Expand Down

0 comments on commit 1a192c4

Please sign in to comment.