:pserver:anonymous@cvs.middle-man.sourceforge.net:/cvsroot/middle-man middleman
[middleman.git] / libntlm / README
1
2 This directory contains sources for a library which provides
3 routines to manipulate the structures used for the client end
4 of Microsoft NTLM authentication.
5
6 This code was taken mostly from the Samba project and was
7 initially intended for use with Microsoft Exchange Server when
8 it is configured to require NTLM authentication for clients of
9 it's IMAP server.
10
11 BUILDING
12
13 If you want the library installed in /usr/local/lib and
14 the header in /usr/local/include, then
15
16  $ make
17  $ make install
18
19 will probably work.  Not much effort has been put into making
20 this portable, and I only know for sure that it works on i386
21 Linux glibc systems -- though there shouldn't be anything all
22 that system-specific anywhere.  System byte order differences
23 should already be taken care of.
24
25 TEST PROGRAM
26
27 The test directory contains sources for a program named
28 "dumper" that will dump out base64 NTLM auth messages in a
29 readable format.  It will also take a challenge and generate a
30 response if provided with a username and password.
31
32 USAGE  
33   
34 The application program must convert these structures to/from
35 base64 which is used to transfer data for IMAP authentication.
36 For example usage see the sources for the mutt MUA or the
37 fetchmail package.
38
39 In general the usage is something like shown below (no, I don't
40 know if this code even compiles, but you get the idea
41 hopefully):
42
43
44 #include <ntlm.h>
45
46 extern char *seqTag;  /* IMAP sequence number */
47
48 int imap_auth_ntlm(char *user, char *domain, char *pass)
49 {
50   tSmbNtlmAuthRequest   request;              
51   tSmbNtlmAuthChallenge challenge;
52   tSmbNtlmAuthResponse  response;
53   char buffer[512];
54   char tmpstr[32];
55   
56   writeToServer("%s AUTHENTICATE NTLM\r\n",seqTag);
57   readFromServer(buffer)
58   
59   /* buffer should be "+", but we won't show code to check */
60
61   /* 
62    * prepare the request, convert to base64, and send it to
63    * the the server.  My server didn't care about domain, and NULL
64    * worked fine.
65    */
66
67   buildSmbNtlmAuthRequest(&request,user,domain);
68   convertToBase64(buffer, &request, SmbLength(&request));
69   writeToServer("%s\r\n",buffer);
70   
71   /* read challange data from server, convert from base64 */
72   
73   readFromServer(buffer);
74   
75   /* buffer should contain the string "+ [base 64 data]" */
76   
77   convertFromBase64(&challenge, buffer+2);
78   
79   /* prepare response, convert to base64, send to server */
80   
81   buildSmbNtlmAuthResponse(&challenge, &response, user, pass);
82   convertToBase64(buffer,&response,SmbLength(&response));
83   writeToServer("%s\r\n",buffer);
84   
85   /* read line from server, it should be "[seq] OK blah blah blah" */
86   
87   readFromServer(buffer);
88   
89   sprintf(tmpstr,"%s OK",seqTag);
90   
91   if (strncmp(buffer,tmpstr,strlen(tmpstr)))
92   {
93     /* login failed */
94     return -1;
95   }
96   
97   return 0;
98 }