summaryrefslogtreecommitdiffstats
path: root/ntlm
diff options
context:
space:
mode:
authorPawel Salek <pawsa@damage.localdomain>2010-03-04 22:21:56 +0100
committerPawel Salek <pawsa@damage.localdomain>2010-03-04 22:21:56 +0100
commitaf79dfa2d055053c1027e20cf08f0549dc2e9ada (patch)
treec1fbf971ebdf7913e0325313b701e7f2d2fa9c17 /ntlm
downloadlibesmtp-af79dfa2d055053c1027e20cf08f0549dc2e9ada.tar.gz
libesmtp-af79dfa2d055053c1027e20cf08f0549dc2e9ada.tar.xz
libesmtp-af79dfa2d055053c1027e20cf08f0549dc2e9ada.zip
Initial Commit
Diffstat (limited to 'ntlm')
-rw-r--r--ntlm/Makefile.am11
-rw-r--r--ntlm/Makefile.in478
-rw-r--r--ntlm/client-ntlm.c149
-rw-r--r--ntlm/ntlm.h52
-rw-r--r--ntlm/ntlmdes.c157
-rw-r--r--ntlm/ntlmstruct.c331
6 files changed, 1178 insertions, 0 deletions
diff --git a/ntlm/Makefile.am b/ntlm/Makefile.am
new file mode 100644
index 0000000..a636e50
--- /dev/null
+++ b/ntlm/Makefile.am
@@ -0,0 +1,11 @@
+## Process this file with automake to produce Makefile.in
+
+libdir = @plugindir@
+
+INCLUDES = -I@srcdir@
+AM_CFLAGS = @CFLAGS@ @EXTRA_CFLAGS@
+
+lib_LTLIBRARIES = sasl-ntlm.la
+
+sasl_ntlm_la_SOURCES = client-ntlm.c ntlmdes.c ntlmstruct.c ntlm.h
+sasl_ntlm_la_LDFLAGS = -module -avoid-version @NTLM_LIBS@
diff --git a/ntlm/Makefile.in b/ntlm/Makefile.in
new file mode 100644
index 0000000..c7f5e6a
--- /dev/null
+++ b/ntlm/Makefile.in
@@ -0,0 +1,478 @@
+# Makefile.in generated by automake 1.9.5 from Makefile.am.
+# @configure_input@
+
+# Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
+# 2003, 2004, 2005 Free Software Foundation, Inc.
+# This Makefile.in is free software; the Free Software Foundation
+# gives unlimited permission to copy and/or distribute it,
+# with or without modifications, as long as this notice is preserved.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY, to the extent permitted by law; without
+# even the implied warranty of MERCHANTABILITY or FITNESS FOR A
+# PARTICULAR PURPOSE.
+
+@SET_MAKE@
+
+SOURCES = $(sasl_ntlm_la_SOURCES)
+
+srcdir = @srcdir@
+top_srcdir = @top_srcdir@
+VPATH = @srcdir@
+pkgdatadir = $(datadir)/@PACKAGE@
+pkglibdir = $(libdir)/@PACKAGE@
+pkgincludedir = $(includedir)/@PACKAGE@
+top_builddir = ..
+am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd
+INSTALL = @INSTALL@
+install_sh_DATA = $(install_sh) -c -m 644
+install_sh_PROGRAM = $(install_sh) -c
+install_sh_SCRIPT = $(install_sh) -c
+INSTALL_HEADER = $(INSTALL_DATA)
+transform = $(program_transform_name)
+NORMAL_INSTALL = :
+PRE_INSTALL = :
+POST_INSTALL = :
+NORMAL_UNINSTALL = :
+PRE_UNINSTALL = :
+POST_UNINSTALL = :
+build_triplet = @build@
+host_triplet = @host@
+subdir = ntlm
+DIST_COMMON = $(srcdir)/Makefile.am $(srcdir)/Makefile.in
+ACLOCAL_M4 = $(top_srcdir)/aclocal.m4
+am__aclocal_m4_deps = $(top_srcdir)/acinclude.m4 \
+ $(top_srcdir)/configure.in
+am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \
+ $(ACLOCAL_M4)
+mkinstalldirs = $(install_sh) -d
+CONFIG_HEADER = $(top_builddir)/config.h
+CONFIG_CLEAN_FILES =
+am__vpath_adj_setup = srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`;
+am__vpath_adj = case $$p in \
+ $(srcdir)/*) f=`echo "$$p" | sed "s|^$$srcdirstrip/||"`;; \
+ *) f=$$p;; \
+ esac;
+am__strip_dir = `echo $$p | sed -e 's|^.*/||'`;
+am__installdirs = "$(DESTDIR)$(libdir)"
+libLTLIBRARIES_INSTALL = $(INSTALL)
+LTLIBRARIES = $(lib_LTLIBRARIES)
+sasl_ntlm_la_LIBADD =
+am_sasl_ntlm_la_OBJECTS = client-ntlm.lo ntlmdes.lo ntlmstruct.lo
+sasl_ntlm_la_OBJECTS = $(am_sasl_ntlm_la_OBJECTS)
+DEFAULT_INCLUDES = -I. -I$(srcdir) -I$(top_builddir)
+depcomp = $(SHELL) $(top_srcdir)/depcomp
+am__depfiles_maybe = depfiles
+COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \
+ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS)
+LTCOMPILE = $(LIBTOOL) --tag=CC --mode=compile $(CC) $(DEFS) \
+ $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \
+ $(AM_CFLAGS) $(CFLAGS)
+CCLD = $(CC)
+LINK = $(LIBTOOL) --tag=CC --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \
+ $(AM_LDFLAGS) $(LDFLAGS) -o $@
+SOURCES = $(sasl_ntlm_la_SOURCES)
+DIST_SOURCES = $(sasl_ntlm_la_SOURCES)
+ETAGS = etags
+CTAGS = ctags
+DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST)
+ACLOCAL = @ACLOCAL@
+AMDEP_FALSE = @AMDEP_FALSE@
+AMDEP_TRUE = @AMDEP_TRUE@
+AMTAR = @AMTAR@
+AR = @AR@
+AUTOCONF = @AUTOCONF@
+AUTOHEADER = @AUTOHEADER@
+AUTOMAKE = @AUTOMAKE@
+AWK = @AWK@
+CC = @CC@
+CCDEPMODE = @CCDEPMODE@
+CFLAGS = @CFLAGS@
+CPP = @CPP@
+CPPFLAGS = @CPPFLAGS@
+CRAMMD5_LIBS = @CRAMMD5_LIBS@
+CRAMMD5_LTLIBOBJS = @CRAMMD5_LTLIBOBJS@
+CXX = @CXX@
+CXXCPP = @CXXCPP@
+CXXDEPMODE = @CXXDEPMODE@
+CXXFLAGS = @CXXFLAGS@
+CYGPATH_W = @CYGPATH_W@
+DEFS = @DEFS@
+DEPDIR = @DEPDIR@
+DIST_PLUGINS = @DIST_PLUGINS@
+ECHO = @ECHO@
+ECHO_C = @ECHO_C@
+ECHO_N = @ECHO_N@
+ECHO_T = @ECHO_T@
+EGREP = @EGREP@
+EXEEXT = @EXEEXT@
+EXTRA_CFLAGS = @EXTRA_CFLAGS@
+F77 = @F77@
+FFLAGS = @FFLAGS@
+INSTALL_DATA = @INSTALL_DATA@
+INSTALL_PROGRAM = @INSTALL_PROGRAM@
+INSTALL_SCRIPT = @INSTALL_SCRIPT@
+INSTALL_STRIP_PROGRAM = @INSTALL_STRIP_PROGRAM@
+LDFLAGS = @LDFLAGS@
+LIBESMTP_VERSION = @LIBESMTP_VERSION@
+LIBOBJS = @LIBOBJS@
+LIBS = @LIBS@
+LIBTOOL = @LIBTOOL@
+LIBTOOL_DEPS = @LIBTOOL_DEPS@
+LIB_AGE = @LIB_AGE@
+LIB_CURRENT = @LIB_CURRENT@
+LIB_REVISION = @LIB_REVISION@
+LN_S = @LN_S@
+LTALLOCA = @LTALLOCA@
+LTLIBOBJS = @LTLIBOBJS@
+MAKEINFO = @MAKEINFO@
+NTLM_LIBS = @NTLM_LIBS@
+OBJEXT = @OBJEXT@
+PACKAGE = @PACKAGE@
+PACKAGE_BUGREPORT = @PACKAGE_BUGREPORT@
+PACKAGE_NAME = @PACKAGE_NAME@
+PACKAGE_STRING = @PACKAGE_STRING@
+PACKAGE_TARNAME = @PACKAGE_TARNAME@
+PACKAGE_VERSION = @PACKAGE_VERSION@
+PATH_SEPARATOR = @PATH_SEPARATOR@
+PTHREAD_CC = @PTHREAD_CC@
+PTHREAD_CFLAGS = @PTHREAD_CFLAGS@
+PTHREAD_LDFLAGS = @PTHREAD_LDFLAGS@
+PTHREAD_LIBS = @PTHREAD_LIBS@
+RANLIB = @RANLIB@
+RPM_BUILDREQUIRES = @RPM_BUILDREQUIRES@
+RPM_OPENSSL = @RPM_OPENSSL@
+RPM_OPENSSLDEVEL = @RPM_OPENSSLDEVEL@
+RPM_REQUIRES = @RPM_REQUIRES@
+SASL_PLUGINS = @SASL_PLUGINS@
+SET_MAKE = @SET_MAKE@
+SHELL = @SHELL@
+STRIP = @STRIP@
+VERSION = @VERSION@
+ac_ct_AR = @ac_ct_AR@
+ac_ct_CC = @ac_ct_CC@
+ac_ct_CXX = @ac_ct_CXX@
+ac_ct_F77 = @ac_ct_F77@
+ac_ct_RANLIB = @ac_ct_RANLIB@
+ac_ct_STRIP = @ac_ct_STRIP@
+am__fastdepCC_FALSE = @am__fastdepCC_FALSE@
+am__fastdepCC_TRUE = @am__fastdepCC_TRUE@
+am__fastdepCXX_FALSE = @am__fastdepCXX_FALSE@
+am__fastdepCXX_TRUE = @am__fastdepCXX_TRUE@
+am__include = @am__include@
+am__leading_dot = @am__leading_dot@
+am__quote = @am__quote@
+am__tar = @am__tar@
+am__untar = @am__untar@
+bindir = @bindir@
+build = @build@
+build_alias = @build_alias@
+build_cpu = @build_cpu@
+build_os = @build_os@
+build_vendor = @build_vendor@
+datadir = @datadir@
+exec_prefix = @exec_prefix@
+host = @host@
+host_alias = @host_alias@
+host_cpu = @host_cpu@
+host_os = @host_os@
+host_vendor = @host_vendor@
+includedir = @includedir@
+infodir = @infodir@
+install_sh = @install_sh@
+libdir = @plugindir@
+libexecdir = @libexecdir@
+localstatedir = @localstatedir@
+mandir = @mandir@
+mkdir_p = @mkdir_p@
+oldincludedir = @oldincludedir@
+plugindir = @plugindir@
+prefix = @prefix@
+program_transform_name = @program_transform_name@
+sbindir = @sbindir@
+sharedstatedir = @sharedstatedir@
+subdirs = @subdirs@
+sysconfdir = @sysconfdir@
+target_alias = @target_alias@
+INCLUDES = -I@srcdir@
+AM_CFLAGS = @CFLAGS@ @EXTRA_CFLAGS@
+lib_LTLIBRARIES = sasl-ntlm.la
+sasl_ntlm_la_SOURCES = client-ntlm.c ntlmdes.c ntlmstruct.c ntlm.h
+sasl_ntlm_la_LDFLAGS = -module -avoid-version @NTLM_LIBS@
+all: all-am
+
+.SUFFIXES:
+.SUFFIXES: .c .lo .o .obj
+$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps)
+ @for dep in $?; do \
+ case '$(am__configure_deps)' in \
+ *$$dep*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh \
+ && exit 0; \
+ exit 1;; \
+ esac; \
+ done; \
+ echo ' cd $(top_srcdir) && $(AUTOMAKE) --gnu ntlm/Makefile'; \
+ cd $(top_srcdir) && \
+ $(AUTOMAKE) --gnu ntlm/Makefile
+.PRECIOUS: Makefile
+Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status
+ @case '$?' in \
+ *config.status*) \
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \
+ *) \
+ echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe)'; \
+ cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__depfiles_maybe);; \
+ esac;
+
+$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+
+$(top_srcdir)/configure: $(am__configure_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+$(ACLOCAL_M4): $(am__aclocal_m4_deps)
+ cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh
+install-libLTLIBRARIES: $(lib_LTLIBRARIES)
+ @$(NORMAL_INSTALL)
+ test -z "$(libdir)" || $(mkdir_p) "$(DESTDIR)$(libdir)"
+ @list='$(lib_LTLIBRARIES)'; for p in $$list; do \
+ if test -f $$p; then \
+ f=$(am__strip_dir) \
+ echo " $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) '$$p' '$(DESTDIR)$(libdir)/$$f'"; \
+ $(LIBTOOL) --mode=install $(libLTLIBRARIES_INSTALL) $(INSTALL_STRIP_FLAG) "$$p" "$(DESTDIR)$(libdir)/$$f"; \
+ else :; fi; \
+ done
+
+uninstall-libLTLIBRARIES:
+ @$(NORMAL_UNINSTALL)
+ @set -x; list='$(lib_LTLIBRARIES)'; for p in $$list; do \
+ p=$(am__strip_dir) \
+ echo " $(LIBTOOL) --mode=uninstall rm -f '$(DESTDIR)$(libdir)/$$p'"; \
+ $(LIBTOOL) --mode=uninstall rm -f "$(DESTDIR)$(libdir)/$$p"; \
+ done
+
+clean-libLTLIBRARIES:
+ -test -z "$(lib_LTLIBRARIES)" || rm -f $(lib_LTLIBRARIES)
+ @list='$(lib_LTLIBRARIES)'; for p in $$list; do \
+ dir="`echo $$p | sed -e 's|/[^/]*$$||'`"; \
+ test "$$dir" != "$$p" || dir=.; \
+ echo "rm -f \"$${dir}/so_locations\""; \
+ rm -f "$${dir}/so_locations"; \
+ done
+sasl-ntlm.la: $(sasl_ntlm_la_OBJECTS) $(sasl_ntlm_la_DEPENDENCIES)
+ $(LINK) -rpath $(libdir) $(sasl_ntlm_la_LDFLAGS) $(sasl_ntlm_la_OBJECTS) $(sasl_ntlm_la_LIBADD) $(LIBS)
+
+mostlyclean-compile:
+ -rm -f *.$(OBJEXT)
+
+distclean-compile:
+ -rm -f *.tab.c
+
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/client-ntlm.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntlmdes.Plo@am__quote@
+@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ntlmstruct.Plo@am__quote@
+
+.c.o:
+@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c $<
+
+.c.obj:
+@am__fastdepCC_TRUE@ if $(COMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ `$(CYGPATH_W) '$<'`; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Po"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=no @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(COMPILE) -c `$(CYGPATH_W) '$<'`
+
+.c.lo:
+@am__fastdepCC_TRUE@ if $(LTCOMPILE) -MT $@ -MD -MP -MF "$(DEPDIR)/$*.Tpo" -c -o $@ $<; \
+@am__fastdepCC_TRUE@ then mv -f "$(DEPDIR)/$*.Tpo" "$(DEPDIR)/$*.Plo"; else rm -f "$(DEPDIR)/$*.Tpo"; exit 1; fi
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ source='$<' object='$@' libtool=yes @AMDEPBACKSLASH@
+@AMDEP_TRUE@@am__fastdepCC_FALSE@ DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) @AMDEPBACKSLASH@
+@am__fastdepCC_FALSE@ $(LTCOMPILE) -c -o $@ $<
+
+mostlyclean-libtool:
+ -rm -f *.lo
+
+clean-libtool:
+ -rm -rf .libs _libs
+
+distclean-libtool:
+ -rm -f libtool
+uninstall-info-am:
+
+ID: $(HEADERS) $(SOURCES) $(LISP) $(TAGS_FILES)
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ mkid -fID $$unique
+tags: TAGS
+
+TAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ if test -z "$(ETAGS_ARGS)$$tags$$unique"; then :; else \
+ test -n "$$unique" || unique=$$empty_fix; \
+ $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \
+ $$tags $$unique; \
+ fi
+ctags: CTAGS
+CTAGS: $(HEADERS) $(SOURCES) $(TAGS_DEPENDENCIES) \
+ $(TAGS_FILES) $(LISP)
+ tags=; \
+ here=`pwd`; \
+ list='$(SOURCES) $(HEADERS) $(LISP) $(TAGS_FILES)'; \
+ unique=`for i in $$list; do \
+ if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \
+ done | \
+ $(AWK) ' { files[$$0] = 1; } \
+ END { for (i in files) print i; }'`; \
+ test -z "$(CTAGS_ARGS)$$tags$$unique" \
+ || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \
+ $$tags $$unique
+
+GTAGS:
+ here=`$(am__cd) $(top_builddir) && pwd` \
+ && cd $(top_srcdir) \
+ && gtags -i $(GTAGS_ARGS) $$here
+
+distclean-tags:
+ -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags
+
+distdir: $(DISTFILES)
+ @srcdirstrip=`echo "$(srcdir)" | sed 's|.|.|g'`; \
+ topsrcdirstrip=`echo "$(top_srcdir)" | sed 's|.|.|g'`; \
+ list='$(DISTFILES)'; for file in $$list; do \
+ case $$file in \
+ $(srcdir)/*) file=`echo "$$file" | sed "s|^$$srcdirstrip/||"`;; \
+ $(top_srcdir)/*) file=`echo "$$file" | sed "s|^$$topsrcdirstrip/|$(top_builddir)/|"`;; \
+ esac; \
+ if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \
+ dir=`echo "$$file" | sed -e 's,/[^/]*$$,,'`; \
+ if test "$$dir" != "$$file" && test "$$dir" != "."; then \
+ dir="/$$dir"; \
+ $(mkdir_p) "$(distdir)$$dir"; \
+ else \
+ dir=''; \
+ fi; \
+ if test -d $$d/$$file; then \
+ if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \
+ cp -pR $(srcdir)/$$file $(distdir)$$dir || exit 1; \
+ fi; \
+ cp -pR $$d/$$file $(distdir)$$dir || exit 1; \
+ else \
+ test -f $(distdir)/$$file \
+ || cp -p $$d/$$file $(distdir)/$$file \
+ || exit 1; \
+ fi; \
+ done
+check-am: all-am
+check: check-am
+all-am: Makefile $(LTLIBRARIES)
+installdirs:
+ for dir in "$(DESTDIR)$(libdir)"; do \
+ test -z "$$dir" || $(mkdir_p) "$$dir"; \
+ done
+install: install-am
+install-exec: install-exec-am
+install-data: install-data-am
+uninstall: uninstall-am
+
+install-am: all-am
+ @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am
+
+installcheck: installcheck-am
+install-strip:
+ $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \
+ install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \
+ `test -z '$(STRIP)' || \
+ echo "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'"` install
+mostlyclean-generic:
+
+clean-generic:
+
+distclean-generic:
+ -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES)
+
+maintainer-clean-generic:
+ @echo "This command is intended for maintainers to use"
+ @echo "it deletes files that may require special tools to rebuild."
+clean: clean-am
+
+clean-am: clean-generic clean-libLTLIBRARIES clean-libtool \
+ mostlyclean-am
+
+distclean: distclean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+distclean-am: clean-am distclean-compile distclean-generic \
+ distclean-libtool distclean-tags
+
+dvi: dvi-am
+
+dvi-am:
+
+html: html-am
+
+info: info-am
+
+info-am:
+
+install-data-am:
+
+install-exec-am: install-libLTLIBRARIES
+
+install-info: install-info-am
+
+install-man:
+
+installcheck-am:
+
+maintainer-clean: maintainer-clean-am
+ -rm -rf ./$(DEPDIR)
+ -rm -f Makefile
+maintainer-clean-am: distclean-am maintainer-clean-generic
+
+mostlyclean: mostlyclean-am
+
+mostlyclean-am: mostlyclean-compile mostlyclean-generic \
+ mostlyclean-libtool
+
+pdf: pdf-am
+
+pdf-am:
+
+ps: ps-am
+
+ps-am:
+
+uninstall-am: uninstall-info-am uninstall-libLTLIBRARIES
+
+.PHONY: CTAGS GTAGS all all-am check check-am clean clean-generic \
+ clean-libLTLIBRARIES clean-libtool ctags distclean \
+ distclean-compile distclean-generic distclean-libtool \
+ distclean-tags distdir dvi dvi-am html html-am info info-am \
+ install install-am install-data install-data-am install-exec \
+ install-exec-am install-info install-info-am \
+ install-libLTLIBRARIES install-man install-strip installcheck \
+ installcheck-am installdirs maintainer-clean \
+ maintainer-clean-generic mostlyclean mostlyclean-compile \
+ mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \
+ tags uninstall uninstall-am uninstall-info-am \
+ uninstall-libLTLIBRARIES
+
+# Tell versions [3.59,3.63) of GNU make to not export all variables.
+# Otherwise a system limit (for SysV at least) may be exceeded.
+.NOEXPORT:
diff --git a/ntlm/client-ntlm.c b/ntlm/client-ntlm.c
new file mode 100644
index 0000000..3067f85
--- /dev/null
+++ b/ntlm/client-ntlm.c
@@ -0,0 +1,149 @@
+/*
+ * Authentication module for the Micr$oft NTLM mechanism.
+ *
+ * This file is part of libESMTP, a library for submission of RFC 2822
+ * formatted electronic mail messages using the SMTP protocol described
+ * in RFC 2821.
+ *
+ * Copyright (C) 2002 Brian Stafford <brian@stafford.uklinux.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#define _XOPEN_SOURCE 500
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
+
+#include <string.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+#include <sys/types.h>
+#include "ntlm.h"
+#include "auth-client.h"
+#include "auth-plugin.h"
+
+#if 0
+/* This is handy for changing te value of the flags in the debugger. */
+unsigned int t1flags = TYPE1_FLAGS;
+#undef TYPE1_FLAGS
+#define TYPE1_FLAGS t1flags
+#endif
+
+#define NELT(x) (sizeof x / sizeof x[0])
+
+static int ntlm_init (void *pctx);
+static void ntlm_destroy (void *ctx);
+static const char *ntlm_response (void *ctx,
+ const char *challenge, int *len,
+ auth_interact_t interact, void *arg);
+
+const struct auth_client_plugin sasl_client =
+ {
+ /* Plugin information */
+ "NTLM",
+ "NTLM Authentication Mechanism (Microsoft)",
+ /* Plugin instance */
+ ntlm_init,
+ ntlm_destroy,
+ /* Authentication */
+ ntlm_response,
+ 0,
+ /* Security Layer */
+ 0,
+ NULL,
+ NULL,
+ };
+
+static const struct auth_client_request client_request[] =
+ {
+ { "domain", AUTH_CLEARTEXT | AUTH_REALM, "Domain", 0, },
+ { "user", AUTH_CLEARTEXT | AUTH_USER, "User Name", 0, },
+ { "passphrase", AUTH_PASS, "Pass Phrase", 0, },
+ };
+
+struct ntlm_context
+ {
+ int state;
+ char *result[NELT (client_request)];
+ char host[64];
+ char buf[256];
+ };
+
+static int
+ntlm_init (void *pctx)
+{
+ struct ntlm_context *context;
+
+ context = malloc (sizeof (struct ntlm_context));
+ memset (context, 0, sizeof (struct ntlm_context));
+
+ *(void **) pctx = context;
+ return 1;
+}
+
+static void
+ntlm_destroy (void *ctx)
+{
+ struct ntlm_context *context = ctx;
+
+ memset (context, 0, sizeof (struct ntlm_context));
+ free (context);
+}
+
+static const char *
+ntlm_response (void *ctx, const char *challenge, int *len,
+ auth_interact_t interact, void *arg)
+{
+ struct ntlm_context *context = ctx;
+ unsigned char nonce[8];
+ unsigned char lm_resp[24], nt_resp[24];
+ unsigned int flags;
+ char *domain = NULL;
+ char *p;
+
+ switch (context->state)
+ {
+ case 0: /* build the authentication request */
+ context->state = 1;
+ if (!(*interact) (client_request, context->result, NELT (client_request),
+ arg))
+ break;
+ gethostname (context->host, sizeof context->host);
+ if ((p = strchr (context->host, '.')) != NULL)
+ *p = '\0';
+ *len = ntlm_build_type_1 (context->buf, sizeof context->buf, TYPE1_FLAGS,
+ context->result[0], context->host);
+ return context->buf;
+
+ case 1: /* compute a response based om the challenge */
+ context->state = 2;
+ if (!ntlm_parse_type_2 (challenge, *len, &flags, nonce, &domain))
+ break;
+ ntlm_responses (lm_resp, nt_resp, nonce, context->result[2]);
+ *len = ntlm_build_type_3 (context->buf, sizeof context->buf,
+ flags, lm_resp, nt_resp,
+ context->result[0], context->result[1],
+ context->host);
+ if (domain != NULL)
+ free (domain);
+ return context->buf;
+ }
+ *len = 0;
+ return NULL;
+}
+
diff --git a/ntlm/ntlm.h b/ntlm/ntlm.h
new file mode 100644
index 0000000..50a49d6
--- /dev/null
+++ b/ntlm/ntlm.h
@@ -0,0 +1,52 @@
+#ifndef _ntlm_h
+#define _ntlm_h
+/*
+ * Authentication module for the Micr$oft NTLM mechanism.
+ *
+ * This file is part of libESMTP, a library for submission of RFC 2822
+ * formatted electronic mail messages using the SMTP protocol described
+ * in RFC 2821.
+ *
+ * Copyright (C) 2002 Brian Stafford <brian@stafford.uklinux.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+char *lm_uccpy (char *dst, size_t dstlen, const char *src);
+unsigned char *nt_unicode (const char *string, size_t len);
+
+void lm_hash_password (unsigned char *hash, const char *pass);
+void nt_hash_password (unsigned char *hash, const char *pass);
+
+void ntlm_responses (unsigned char *lm_resp, unsigned char *nt_resp,
+ const unsigned char *challenge, const char *secret);
+
+size_t ntlm_build_type_1 (char *buf, size_t buflen, unsigned int flags,
+ const char *domain, const char *workstation);
+size_t ntlm_build_type_2 (char *buf, size_t buflen, unsigned int flags,
+ const unsigned char *nonce, const char *domain);
+size_t ntlm_build_type_3 (char *buf, size_t buflen,
+ unsigned int flags,
+ const unsigned char *lm_resp,
+ const unsigned char *nt_resp,
+ const char *domain, const char *user,
+ const char *workstation);
+
+size_t ntlm_parse_type_2 (const char *buf, size_t buflen, unsigned int *flags,
+ unsigned char *nonce, char **domain);
+
+#define TYPE1_FLAGS 0x8202u
+
+#endif
diff --git a/ntlm/ntlmdes.c b/ntlm/ntlmdes.c
new file mode 100644
index 0000000..57a39d1
--- /dev/null
+++ b/ntlm/ntlmdes.c
@@ -0,0 +1,157 @@
+/*
+ * Authentication module for the Micr$oft NTLM mechanism.
+ *
+ * This file is part of libESMTP, a library for submission of RFC 2822
+ * formatted electronic mail messages using the SMTP protocol described
+ * in RFC 2821.
+ *
+ * Copyright (C) 2002 Brian Stafford <brian@stafford.uklinux.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#include <stdlib.h>
+#include <string.h>
+#include <ctype.h>
+#include <openssl/des.h>
+#include <openssl/md4.h>
+
+#include "ntlm.h"
+
+static void
+lm_deshash (void *result, const_des_cblock *iv, const void *secret)
+{
+ des_cblock key;
+ des_key_schedule ks;
+ unsigned char key_56[8];
+ size_t len;
+
+ /* copy and pad the secret */
+ len = strlen (secret);
+ if (len > sizeof key_56)
+ len = sizeof key_56;
+ memcpy (key_56, secret, len);
+ if (sizeof key_56 - len > 0)
+ memset (key_56 + len, 0, sizeof key_56 - len);
+
+ /* convert 56 bit key to the 64 bit */
+ key[0] = key_56[0];
+ key[1] = (key_56[0] << 7) | (key_56[1] >> 1);
+ key[2] = (key_56[1] << 6) | (key_56[2] >> 2);
+ key[3] = (key_56[2] << 5) | (key_56[3] >> 3);
+ key[4] = (key_56[3] << 4) | (key_56[4] >> 4);
+ key[5] = (key_56[4] << 3) | (key_56[5] >> 5);
+ key[6] = (key_56[5] << 2) | (key_56[6] >> 6);
+ key[7] = (key_56[6] << 1);
+
+ des_set_odd_parity (&key);
+ des_set_key (&key, ks);
+ des_ecb_encrypt (iv, result, ks, DES_ENCRYPT);
+
+ /* paranoia */
+ memset (key, 0, sizeof key);
+ memset (&ks, 0, sizeof ks);
+}
+
+/* Copy and convert to upper case. If supplied string is shorter than the
+ destination, zero pad the remainder. */
+char *
+lm_uccpy (char *dst, size_t dstlen, const char *src)
+{
+ char *p;
+ size_t len;
+
+ if ((len = strlen (src)) > dstlen)
+ len = dstlen;
+ for (p = dst; len > 0; p++, src++, len--)
+ *p = toupper (*src);
+ if (p < dst + dstlen)
+ memset (p, 0, dst + dstlen - p);
+ return dst;
+}
+
+/* create LanManager hashed password */
+void
+lm_hash_password (unsigned char *hash, const char *pass)
+{
+ static const_des_cblock iv = { 0x4B, 0x47, 0x53, 0x21,
+ 0x40, 0x23, 0x24, 0x25 };
+ char lmpass[14];
+
+ lm_uccpy (lmpass, sizeof lmpass, pass);
+ lm_deshash (hash, &iv, lmpass);
+ lm_deshash (hash + 8, &iv, lmpass + 7);
+ memset (lmpass, 0, sizeof lmpass);
+}
+
+/* convert to unicode */
+unsigned char *
+nt_unicode (const char *string, size_t len)
+{
+ unsigned char *uni, *pp;
+
+ uni = malloc (len * 2);
+ if ((pp = uni) != NULL)
+ while (len-- > 0)
+ {
+ *pp++ = (unsigned char) *string++;
+ *pp++ = 0;
+ }
+ return uni;
+}
+
+void
+nt_hash_password (unsigned char *hash, const char *pass)
+{
+ int len;
+ unsigned char *nt_pw;
+ MD4_CTX context;
+
+ len = strlen (pass);
+ if ((nt_pw = nt_unicode (pass, len)) == NULL)
+ return;
+
+ MD4_Init (&context);
+ MD4_Update (&context, nt_pw, 2 * len);
+ MD4_Final (hash, &context);
+ memset (&context, 0, sizeof context);
+ memset (nt_pw, 0, 2 * len);
+ free (nt_pw);
+}
+
+/* Use the server's 8 octet nonce and the secret to create the 24 octet
+ LanManager and NT responses. */
+void
+ntlm_responses (unsigned char *lm_resp, unsigned char *nt_resp,
+ const unsigned char *challenge, const char *secret)
+{
+ unsigned char hash[21];
+ des_cblock nonce;
+
+ memcpy (&nonce, challenge, sizeof nonce);
+
+ lm_hash_password (hash, secret);
+ memset (hash + 16, 0, 5);
+ lm_deshash (lm_resp, &nonce, hash);
+ lm_deshash (lm_resp + 8, &nonce, hash + 7);
+ lm_deshash (lm_resp + 16, &nonce, hash + 14);
+
+ nt_hash_password (hash, secret);
+ memset (hash + 16, 0, 5);
+ lm_deshash (nt_resp, &nonce, hash);
+ lm_deshash (nt_resp + 8, &nonce, hash + 7);
+ lm_deshash (nt_resp + 16, &nonce, hash + 14);
+ memset (hash, 0, sizeof hash);
+}
+
diff --git a/ntlm/ntlmstruct.c b/ntlm/ntlmstruct.c
new file mode 100644
index 0000000..dfb80de
--- /dev/null
+++ b/ntlm/ntlmstruct.c
@@ -0,0 +1,331 @@
+/*
+ * Authentication module for the Micr$oft NTLM mechanism.
+ *
+ * This file is part of libESMTP, a library for submission of RFC 2822
+ * formatted electronic mail messages using the SMTP protocol described
+ * in RFC 2821.
+ *
+ * Copyright (C) 2002 Brian Stafford <brian@stafford.uklinux.net>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+#if HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <string.h>
+#include <assert.h>
+
+#include "ntlm.h"
+
+/* Must have at least 32 bits in an int (at least pending a more thorough
+ code review - this module is still experimental) */
+#if SIZEOF_UNSIGNED_INT < 32 / 8
+# error "unsigned int is less than 32 bits wide"
+#endif
+
+#if SIZEOF_UNSIGNED_SHORT == 16 / 8
+typedef unsigned short unsigned16_t;
+#else
+#include <sys/types.h>
+typedef uint16 unsigned16_t;
+#endif
+
+#if SIZEOF_UNSIGNED_INT == 32 / 8
+typedef unsigned int unsigned32_t;
+#elif SIZEOF_UNSIGNED_LONG == 32 / 8
+typedef unsigned long unsigned32_t;
+#else
+#include <sys/types.h>
+typedef uint32 unsigned32_t;
+#endif
+
+#ifdef WORDS_BIGENDIAN
+/* Everything in NTLM is little endian binary, therefore byte swapping
+ is needed on big endian platforms. For simplicity, always provide
+ byte swapping functions rather than trying to detect the local
+ platform's support. These functions make no effort to be efficient
+ since this code doesn't require efficient byte swapping. */
+
+#define SWAP(a,b) do { unsigned char s = u.swap[(a)]; \
+ u.swap[(a)] = u.swap[(b)]; \
+ u.swap[(b)] = s; } while (0)
+
+static unsigned16_t
+bswap_16 (unsigned16_t value)
+{
+ union { unsigned16_t val; unsigned char swap[2]; } u;
+
+ u.val = value;
+ SWAP(0,1);
+ return u.val;
+}
+
+static unsigned32_t
+bswap_32 (unsigned32_t value)
+{
+ union u32 { unsigned32_t val; unsigned char swap[4]; } u;
+
+ u.val = value;
+ SWAP(0,3);
+ SWAP(1,2);
+ return u.val;
+}
+
+#undef SWAP
+#endif
+
+static void
+write_uint16 (char *buf, size_t offset, unsigned int value)
+{
+ unsigned16_t i16 = value;
+
+ assert (sizeof i16 == 2);
+#ifdef WORDS_BIGENDIAN
+ i16 = bswap_16 (i16);
+#endif
+ memcpy (buf + offset, &i16, sizeof i16);
+}
+
+static inline void
+write_uint32 (char *buf, size_t offset, unsigned int value)
+{
+ unsigned32_t i32 = value;
+
+ assert (sizeof i32 == 4);
+#ifdef WORDS_BIGENDIAN
+ i32 = bswap_32 (i32);
+#endif
+ memcpy (buf + offset, &i32, sizeof i32);
+}
+
+static inline unsigned int
+read_uint16 (const char *buf, size_t offset)
+{
+ unsigned16_t i16;
+
+ assert (sizeof i16 == 2);
+ memcpy (&i16, buf + offset, sizeof i16);
+#ifdef WORDS_BIGENDIAN
+ i16 = bswap_16 (i16);
+#endif
+ return i16;
+}
+
+static inline unsigned int
+read_uint32 (const char *buf, size_t offset)
+{
+ unsigned32_t i32;
+
+ assert (sizeof i32 == 4);
+ memcpy (&i32, buf + offset, sizeof i32);
+#ifdef WORDS_BIGENDIAN
+ i32 = bswap_32 (i32);
+#endif
+ return i32;
+}
+
+static inline void
+write_string (char *buf, size_t offset, size_t *str_offset,
+ const void *data, size_t len)
+{
+ if (data == NULL)
+ len = 0;
+ write_uint16 (buf, offset, len);
+ write_uint16 (buf, offset + 2, len);
+ write_uint32 (buf, offset + 4, *str_offset);
+ if (len > 0)
+ memcpy (buf + *str_offset, data, len);
+ *str_offset += len;
+}
+
+/* Offsets into on-the-wire NTLM structures */
+#define PROTOCOL 0 /* "NTLMSSP" */
+#define MSGTYPE 8 /* 1..3 */
+/* Type 1 fields */
+#define T1FLAGS 12 /* 0xb203 */
+#define T1DOMAIN 16 /* domain to authenticate in */
+#define T1WKSTN 24 /* client workstation name */
+#define T1SIZE 32
+/* Type 2 fields */
+#define T2AUTHTARGET 12 /* domain/server */
+#define T2FLAGS 20 /* 0x8201 */
+#define T2NONCE 24 /* server challenge */
+#define T2RESERVED 32
+#define T2SIZE 40
+/* Type 3 fields */
+#define T3LMRESPONSE 12 /* lanmanager hash */
+#define T3NTRESPONSE 20 /* nt hash */
+#define T3DOMAIN 28 /* domain to authenticate against */
+#define T3USER 36 /* user name */
+#define T3WKSTN 44 /* client workstation name */
+#define T3SESSIONKEY 52 /* client workstation name */
+#define T3FLAGS 60 /* 0xb203 */
+#define T3SIZE 64
+
+static const char NTLMSSP[] = "NTLMSSP";
+
+/* Build a NTLM type 1 structure in the buffer.
+ domain - the NT domain the workstation belongs to
+ workstation - the NT (netbios) name of the workstation */
+size_t
+ntlm_build_type_1 (char *buf, size_t buflen, unsigned int flags,
+ const char *domain, const char *workstation)
+{
+ size_t offset = T1SIZE;
+ size_t len;
+ unsigned char *up;
+ char string[256];
+
+ if (buflen < offset)
+ return 0;
+ memcpy (buf, NTLMSSP, 8);
+ write_uint32 (buf, MSGTYPE, 1);
+ write_uint32 (buf, T1FLAGS, flags);
+ up = NULL;
+ len = 0;
+ if (domain != NULL)
+ {
+ len = strlen (domain);
+ if (offset + len > buflen)
+ return 0;
+ lm_uccpy (string, len, domain);
+ }
+ write_string (buf, T1DOMAIN, &offset, string, len);
+ up = NULL;
+ len = 0;
+ if (workstation != NULL)
+ {
+ len = strlen (workstation);
+ if (offset + len > buflen)
+ return 0;
+ lm_uccpy (string, len, workstation);
+ }
+ write_string (buf, T1WKSTN, &offset, string, len);
+ return offset;
+}
+
+/* Build a NTLM type 2 structure in the buffer */
+size_t
+ntlm_build_type_2 (char *buf, size_t buflen, unsigned int flags,
+ const unsigned char *nonce, const char *domain)
+{
+ size_t offset = T2SIZE;
+ size_t len;
+ char string[256];
+ unsigned char *up;
+
+ if (buflen < offset)
+ return 0;
+ memcpy (buf, NTLMSSP, 8);
+ write_uint32 (buf, MSGTYPE, 2);
+ up = NULL;
+ len = 0;
+ if (domain != NULL)
+ {
+ len = strlen (domain);
+ if (offset + 2 * len > buflen)
+ return 0;
+ up = nt_unicode (lm_uccpy (string, len, domain), 2 * len);
+ }
+ write_string (buf, T2AUTHTARGET, &offset, up, len);
+ if (up != NULL)
+ free (up);
+ write_uint32 (buf, T2FLAGS, flags);
+ memcpy (buf + T2NONCE, nonce, 8);
+ memset (buf + T2RESERVED, 0, 8);
+ return offset;
+}
+
+/* Build a NTLM type 3 structure in the buffer */
+size_t
+ntlm_build_type_3 (char *buf, size_t buflen, unsigned int flags,
+ const unsigned char *lm_resp, const unsigned char *nt_resp,
+ const char *domain, const char *user, const char *workstation)
+{
+ size_t offset = T3SIZE;
+ size_t len;
+ char string[256];
+ unsigned char *up;
+
+ if (buflen + 24 + 24 < offset)
+ return 0;
+ memcpy (buf, NTLMSSP, 8);
+ write_uint32 (buf, MSGTYPE, 3);
+ write_string (buf, T3LMRESPONSE, &offset, lm_resp, 24);
+ write_string (buf, T3NTRESPONSE, &offset, nt_resp, 24);
+ up = NULL;
+ len = 0;
+ if (domain != NULL)
+ {
+ len = strlen (domain);
+ if (offset + 2 * len > buflen)
+ return 0;
+ up = nt_unicode (lm_uccpy (string, len, domain), 2 * len);
+ }
+ write_string (buf, T3DOMAIN, &offset, up, 2 * len);
+ if (up != NULL)
+ free (up);
+ up = NULL;
+ len = 0;
+ if (user != NULL)
+ {
+ len = strlen (user);
+ if (offset + 2 * len > buflen)
+ return 0;
+ up = nt_unicode (lm_uccpy (string, len, user), 2 * len);
+ }
+ write_string (buf, T3USER, &offset, up, 2 * len);
+ if (up != NULL)
+ free (up);
+ up = NULL;
+ len = 0;
+ if (workstation != NULL)
+ {
+ len = strlen (workstation);
+ if (offset + 2 * len > buflen)
+ return 0;
+ up = nt_unicode (lm_uccpy (string, len, workstation), 2 * len);
+ }
+ write_string (buf, T3WKSTN, &offset, up, 2 * len);
+ if (up != NULL)
+ free (up);
+ write_string (buf, T3SESSIONKEY, &offset, NULL, 0);
+ write_uint32 (buf, T3FLAGS, flags);
+ return offset;
+}
+
+/****/
+
+/* Parse a NTLM type 2 structure in the buffer (partial implementation).
+ Verify that the packet is a type 2 structure and copy the nonce to the
+ supplied buffer (which must be eight bytes long) */
+size_t
+ntlm_parse_type_2 (const char *buf, size_t buflen, unsigned int *flags,
+ unsigned char *nonce, char **domain)
+{
+ if (buflen < T2SIZE)
+ return 0;
+ if (memcmp (buf, NTLMSSP, 8) != 0)
+ return 0;
+ if (read_uint32 (buf, MSGTYPE) != 2)
+ return 0;
+ *flags = read_uint32 (buf, T2FLAGS);
+ *domain = NULL;
+ memcpy (nonce, buf + T2NONCE, 8);
+ return 1;
+}
+