#include "fetchmail.h" #include #include #include #include #include #include #include "ntlm.h" #include "smbencrypt.h" #include "smbbyteorder.h" char versionString[] ="libntlm version 0.21"; /* Utility routines that handle NTLM auth structures. */ /* The [IS]VAL macros are to take care of byte order for non-Intel * Machines -- I think this file is OK, but it hasn't been tested. * The other files (the ones stolen from Samba) should be OK. */ /* I am not crazy about these macros -- they seem to have gotten * a bit complex. A new scheme for handling string/buffer fields * in the structures probably needs to be designed */ #define AddBytes(ptr, header, buf, count) \ { \ if (buf != NULL && count != 0) \ { \ SSVAL(&ptr->header.len,0,count); \ SSVAL(&ptr->header.maxlen,0,count); \ SIVAL(&ptr->header.offset,0,((ptr->buffer - ((uint8*)ptr)) + ptr->bufIndex)); \ memcpy(ptr->buffer+ptr->bufIndex, buf, count); \ ptr->bufIndex += count; \ } \ else \ { \ ptr->header.len = \ ptr->header.maxlen = 0; \ SIVAL(&ptr->header.offset,0,ptr->bufIndex); \ } \ } #define AddString(ptr, header, string) \ { \ char *p_ = string; \ int len_ = 0; \ if (p_) len_ = strlen(p_); \ AddBytes(ptr, header, ((unsigned char*)p_), len_); \ } #define AddUnicodeString(ptr, header, string) \ { \ char *p_ = string; \ unsigned char *b_ = NULL; \ int len_ = 0; \ if (p_) \ { \ len_ = strlen(p_); \ b_ = strToUnicode(p_); \ } \ AddBytes(ptr, header, b_, len_*2); \ } #define GetUnicodeString(structPtr, header) \ unicodeToString(((char*)structPtr) + IVAL(&structPtr->header.offset,0) , SVAL(&structPtr->header.len,0)/2) #define GetString(structPtr, header) \ toString((((char *)structPtr) + IVAL(&structPtr->header.offset,0)), SVAL(&structPtr->header.len,0)) #define DumpBuffer(fp, structPtr, header) \ dumpRaw(fp,((unsigned char*)structPtr)+IVAL(&structPtr->header.offset,0),SVAL(&structPtr->header.len,0)) static void dumpRaw(FILE *fp, unsigned char *buf, size_t len) { size_t i; for (i=0; i (bufsiz)) \ { \ (bufsiz) = ((need) < 1024) ? 1024 : (need); \ xfree(buf); \ (buf) = (type)xmalloc(bufsiz); \ } \ } while (0); /* this is a brute-force conversion from UCS-2LE to US-ASCII, discarding * the upper 9 bits */ static char *unicodeToString(char *p, size_t len) { size_t i; static char *buf; static size_t bufsiz; allocbuf(buf, bufsiz, len + 1, char *); for (i=0; iident); fprintf(fp," mType = %ld\n",(long int)IVAL(&request->msgType,0)); fprintf(fp," Flags = %08x\n",IVAL(&request->flags,0)); fprintf(fp," User = %s\n",(char *)GetString(request,user)); fpri