| 
				
			 | 
			
			
				
				@@ -35,6 +35,7 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL ); 
			 | 
		
		
	
		
			
			| 
				35
			 | 
			
				35
			 | 
			
			
				
				 #include <ipxe/uri.h> 
			 | 
		
		
	
		
			
			| 
				36
			 | 
			
				36
			 | 
			
			
				
				 #include <ipxe/base64.h> 
			 | 
		
		
	
		
			
			| 
				37
			 | 
			
				37
			 | 
			
			
				
				 #include <ipxe/ntlm.h> 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				38
			 | 
			
			
				
				+#include <ipxe/netbios.h> 
			 | 
		
		
	
		
			
			| 
				38
			 | 
			
				39
			 | 
			
			
				
				 #include <ipxe/http.h> 
			 | 
		
		
	
		
			
			| 
				39
			 | 
			
				40
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				40
			 | 
			
				41
			 | 
			
			
				
				 struct http_authentication http_ntlm_auth __http_authentication; 
			 | 
		
		
	
	
		
			
			| 
				
			 | 
			
			
				
				@@ -113,6 +114,8 @@ static int http_ntlm_authenticate ( struct http_transaction *http ) { 
			 | 
		
		
	
		
			
			| 
				113
			 | 
			
				114
			 | 
			
			
				
				 	struct http_request_auth_ntlm *req = &http->request.auth.ntlm; 
			 | 
		
		
	
		
			
			| 
				114
			 | 
			
				115
			 | 
			
			
				
				 	struct http_response_auth_ntlm *rsp = &http->response.auth.ntlm; 
			 | 
		
		
	
		
			
			| 
				115
			 | 
			
				116
			 | 
			
			
				
				 	struct ntlm_key key; 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				117
			 | 
			
			
				
				+	const char *domain; 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				118
			 | 
			
			
				
				+	char *username; 
			 | 
		
		
	
		
			
			| 
				116
			 | 
			
				119
			 | 
			
			
				
				 	const char *password; 
			 | 
		
		
	
		
			
			| 
				117
			 | 
			
				120
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				118
			 | 
			
				121
			 | 
			
			
				
				 	/* If we have no challenge yet, then just send a Negotiate message */ 
			 | 
		
		
	
	
		
			
			| 
				
			 | 
			
			
				
				@@ -130,16 +133,23 @@ static int http_ntlm_authenticate ( struct http_transaction *http ) { 
			 | 
		
		
	
		
			
			| 
				130
			 | 
			
				133
			 | 
			
			
				
				 	req->username = http->uri->user; 
			 | 
		
		
	
		
			
			| 
				131
			 | 
			
				134
			 | 
			
			
				
				 	password = ( http->uri->password ? http->uri->password : "" ); 
			 | 
		
		
	
		
			
			| 
				132
			 | 
			
				135
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				136
			 | 
			
			
				
				+	/* Split NetBIOS [domain\]username */ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				137
			 | 
			
			
				
				+	username = ( ( char * ) req->username ); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				138
			 | 
			
			
				
				+	domain = netbios_domain ( &username ); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				139
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				133
			 | 
			
				140
			 | 
			
			
				
				 	/* Generate key */ 
			 | 
		
		
	
		
			
			| 
				134
			 | 
			
				
			 | 
			
			
				
				-	ntlm_key ( NULL, req->username, password, &key ); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				141
			 | 
			
			
				
				+	ntlm_key ( domain, username, password, &key ); 
			 | 
		
		
	
		
			
			| 
				135
			 | 
			
				142
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				136
			 | 
			
				143
			 | 
			
			
				
				 	/* Generate responses */ 
			 | 
		
		
	
		
			
			| 
				137
			 | 
			
				144
			 | 
			
			
				
				 	ntlm_response ( &rsp->info, &key, NULL, &req->lm, &req->nt ); 
			 | 
		
		
	
		
			
			| 
				138
			 | 
			
				145
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				139
			 | 
			
				146
			 | 
			
			
				
				 	/* Calculate Authenticate message length */ 
			 | 
		
		
	
		
			
			| 
				140
			 | 
			
				
			 | 
			
			
				
				-	req->len = ntlm_authenticate_len ( &rsp->info, NULL, req->username, 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				147
			 | 
			
			
				
				+	req->len = ntlm_authenticate_len ( &rsp->info, domain, username, 
			 | 
		
		
	
		
			
			| 
				141
			 | 
			
				148
			 | 
			
			
				
				 					   http_ntlm_workstation ); 
			 | 
		
		
	
		
			
			| 
				142
			 | 
			
				149
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				150
			 | 
			
			
				
				+	/* Restore NetBIOS [domain\]username */ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				151
			 | 
			
			
				
				+	netbios_domain_undo ( domain, username ); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				152
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				143
			 | 
			
				153
			 | 
			
			
				
				 	return 0; 
			 | 
		
		
	
		
			
			| 
				144
			 | 
			
				154
			 | 
			
			
				
				 } 
			 | 
		
		
	
		
			
			| 
				145
			 | 
			
				155
			 | 
			
			
				
				  
			 | 
		
		
	
	
		
			
			| 
				
			 | 
			
			
				
				@@ -156,6 +166,8 @@ static int http_format_ntlm_auth ( struct http_transaction *http, 
			 | 
		
		
	
		
			
			| 
				156
			 | 
			
				166
			 | 
			
			
				
				 	struct http_request_auth_ntlm *req = &http->request.auth.ntlm; 
			 | 
		
		
	
		
			
			| 
				157
			 | 
			
				167
			 | 
			
			
				
				 	struct http_response_auth_ntlm *rsp = &http->response.auth.ntlm; 
			 | 
		
		
	
		
			
			| 
				158
			 | 
			
				168
			 | 
			
			
				
				 	struct ntlm_authenticate *auth; 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				169
			 | 
			
			
				
				+	const char *domain; 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				170
			 | 
			
			
				
				+	char *username; 
			 | 
		
		
	
		
			
			| 
				159
			 | 
			
				171
			 | 
			
			
				
				 	size_t check; 
			 | 
		
		
	
		
			
			| 
				160
			 | 
			
				172
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				161
			 | 
			
				173
			 | 
			
			
				
				 	/* If we have no challenge yet, then just send a Negotiate message */ 
			 | 
		
		
	
	
		
			
			| 
				
			 | 
			
			
				
				@@ -173,12 +185,19 @@ static int http_format_ntlm_auth ( struct http_transaction *http, 
			 | 
		
		
	
		
			
			| 
				173
			 | 
			
				185
			 | 
			
			
				
				 	if ( ! auth ) 
			 | 
		
		
	
		
			
			| 
				174
			 | 
			
				186
			 | 
			
			
				
				 		return -ENOMEM; 
			 | 
		
		
	
		
			
			| 
				175
			 | 
			
				187
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				188
			 | 
			
			
				
				+	/* Split NetBIOS [domain\]username */ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				189
			 | 
			
			
				
				+	username = ( ( char * ) req->username ); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				190
			 | 
			
			
				
				+	domain = netbios_domain ( &username ); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				191
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				176
			 | 
			
				192
			 | 
			
			
				
				 	/* Construct raw Authenticate message */ 
			 | 
		
		
	
		
			
			| 
				177
			 | 
			
				
			 | 
			
			
				
				-	check = ntlm_authenticate ( &rsp->info, NULL, req->username, 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				193
			 | 
			
			
				
				+	check = ntlm_authenticate ( &rsp->info, domain, username, 
			 | 
		
		
	
		
			
			| 
				178
			 | 
			
				194
			 | 
			
			
				
				 				    http_ntlm_workstation, &req->lm, 
			 | 
		
		
	
		
			
			| 
				179
			 | 
			
				195
			 | 
			
			
				
				 				    &req->nt, auth ); 
			 | 
		
		
	
		
			
			| 
				180
			 | 
			
				196
			 | 
			
			
				
				 	assert ( check == req->len ); 
			 | 
		
		
	
		
			
			| 
				181
			 | 
			
				197
			 | 
			
			
				
				  
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				198
			 | 
			
			
				
				+	/* Restore NetBIOS [domain\]username */ 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				199
			 | 
			
			
				
				+	netbios_domain_undo ( domain, username ); 
			 | 
		
		
	
		
			
			| 
				
			 | 
			
				200
			 | 
			
			
				
				+ 
			 | 
		
		
	
		
			
			| 
				182
			 | 
			
				201
			 | 
			
			
				
				 	/* Base64-encode Authenticate message */ 
			 | 
		
		
	
		
			
			| 
				183
			 | 
			
				202
			 | 
			
			
				
				 	len = base64_encode ( auth, req->len, buf, len ); 
			 | 
		
		
	
		
			
			| 
				184
			 | 
			
				203
			 | 
			
			
				
				  
			 |