Function: ntlm-build-auth-request

ntlm-build-auth-request is an interactive and byte-compiled function defined in ntlm.el.gz.

Signature

(ntlm-build-auth-request USER &optional DOMAIN)

Documentation

Return the NTLM authentication request string for USER and DOMAIN.

USER is a string representing a user name to be authenticated and DOMAIN is a NT domain. USER can include a NT domain part as in user@domain where the string after @ is used as the domain if DOMAIN is not given.

Key Bindings

Source Code

;; Defined in /usr/src/emacs/lisp/net/ntlm.el.gz
;;;
;;; NTLM authentication interface functions

(defun ntlm-build-auth-request (user &optional domain)
  "Return the NTLM authentication request string for USER and DOMAIN.
USER is a string representing a user name to be authenticated and
DOMAIN is a NT domain.  USER can include a NT domain part as in
user@domain where the string after @ is used as the domain if DOMAIN
is not given."
  (interactive)
  (let ((request-ident (concat "NTLMSSP" (make-string 1 0)))
	(request-msgType (concat (make-string 1 1) (make-string 3 0)))
					;0x01 0x00 0x00 0x00
	(request-flags (unibyte-string #x07 #x82 #x08 #x00))
	)
    (when (and user (string-match "@" user))
      (unless domain
	(setq domain (substring user (1+ (match-beginning 0)))))
      (setq user (substring user 0 (match-beginning 0))))
    (when (and (stringp domain) (> (length domain) 0))
      ;; set "negotiate domain supplied" bit
      (aset request-flags 1 (logior (aref request-flags 1) ?\x10)))
    ;; set fields offsets within the request struct
    (let* ((lu (length user))
           (ld (length domain))
           (off-u 32)           ;offset to the string 'user
           (off-d (+ 32 lu)))   ;offset to the string 'domain
    ;; pack the request struct in a string
    (concat request-ident			;8 bytes
	    request-msgType			;4 bytes
	    request-flags			;4 bytes
	    (md4-pack-int16 lu)			;user field, count field
	    (md4-pack-int16 lu)			;user field, max count field
	    (md4-pack-int32 (cons 0 off-u))	;user field, offset field
	    (md4-pack-int16 ld)			;domain field, count field
	    (md4-pack-int16 ld)			;domain field, max count field
	    (md4-pack-int32 (cons 0 off-d))	;domain field, offset field
	    user				;buffer field
	    domain				;buffer field
	    ))))