/* 
 *	Copyright Luke Kenneth Casson Leighton 1997  Paul Ashton 1997.
 *
 *	This file is freely distributable with absolutely no warranty
 *	as to its fitness for purpose or otherwise.  Please have your
 *	lawyers _not_ contact the authors regarding this file.  Thank you.
 *
 *	Copyright acknowledgment is hereby explicity requested, even in
 *	the United States.
 *
 *	This file contains SMB packet sub-structures, described in
 *	http://mailhost.cb1.com/~lkcl/cifsntdomain.txt v0.001, section 2.2.
 */

/* 32 bit time (sec) since 01jan1970 - cifs6.txt, section 3.5, page 30 */
typedef uint32 UTIME;

/* 64 bit time (100usec) since ????? - cifs6.txt, section 3.5, page 30 */
typedef struct nttime
{
  uint32 low;
  uint32 high;

} NTTIME;
 

/* Domain controller authentication protocol info */
struct dcinfo
{
  uint32 chal[2]; /* Initial challenge received from client */
  uint32 svrchal[2]; /* Initial server challenge */
  uint32 cred[2]; /* Last client credential */
  uint32 svrcred[2]; /* Last server credential */
  uint32 sesskey[2]; /* Session key */
  uchar md4pw[16]; /* md4(machine password) */
};

/* DOM_SID - security id */
typedef struct sid_info
{
  uint8  sid_no;                  /* SID revision number */
  uint8  num_auths;               /* number of sub-authorities */
  uint8  id_auth[6];              /* Identifier Authority */
  uint16 sub_auths[MAXSUBAUTHS]; /* pointer to sub-authorities. */

} DOM_SID;

/* UNIHDR - unicode string header */
typedef struct unihdr_info
{
  uint16 uni_max_len;
  uint16 uni_str_len;
  uint32 undoc; /* usually has a value of 4 */

} UNIHDR;

/* UNIHDR2 - unicode string header and undocumented buffer */
typedef struct unihdr2_info
{
  UNIHDR unihdr;
  uint32 undoc_buffer; /* undocumented 32 bit buffer pointer */

} UNIHDR2;

/* clueless as to what maximum length should be */
#define MAX_UNISTRLEN 1024

/* UNISTR - unicode string size and buffer */
typedef struct unistr_info
{
  uint16 buffer[MAX_UNISTRLEN]; /* unicode characters. ***MUST*** be null-terminated */

} UNISTR;

/* UNISTR2 - unicode string size and buffer */
typedef struct unistr2_info
{
  uint32 uni_max_len;
  uint32 undoc;
  uint32 uni_str_len;
  uint16 buffer[MAX_UNISTRLEN]; /* unicode characters. **NOT** necessarily null-terminated */

} UNISTR2;

/* DOM_SID2 - domain SID structure - SIDs stored in unicode */
typedef struct domsid2_info
{
  uint32 type; /* value is 5 */
  uint32 undoc; /* value is 0 */
  UNIHDR2 hdr; /* XXXX conflict between hdr and str for length */
  UNISTR  str; /* XXXX conflict between hdr and str for length */

} DOM_SID2;

/* DOM_RID2 - domain RID structure */
typedef struct domrid2_info
{
  uint32 type; /* value is 5 */
  uint32 undoc; /* value is 5 */
  uint32 rid;
  uint32 rid_idx; /* don't know what this is */

} DOM_RID2;

/* DOM_LOG_INFO - login info */
typedef struct log_info
{
  uint32  undoc_buffer; /* undocumented 32 bit buffer pointer */
  UNISTR2 uni_logon_srv; /* logon server name */
  UNISTR2 uni_acct_name; /* account name */
  uint16  sec_chan;      /* secure channel type */
  UNISTR2 uni_comp_name; /* client machine name */

} DOM_LOG_INFO;

/* DOM_CREDs - client or server credentials */
typedef struct cred_info
{
  uint8 data[8]; /* credentials */
  UTIME timestamp;    /* credential time-stamp */

} DOM_CRED;

/* DOM_CLNT_INFO - client info */
typedef struct clnt_info
{
  DOM_LOG_INFO login;
  DOM_CRED     cred;

} DOM_CLNT_INFO;

/* DOM_LOGON_ID - logon id */
typedef struct logon_info
{
  uint32 low;
  uint32 high;

} DOM_LOGON_ID;

/* RC4_OWF */
typedef struct rc4_owf_info
{
  uint8 data[16];

} RC4_OWF;


/* DOM_ID_INFO_1 */
typedef struct id_info_1
{
  UNIHDR            hdr_domain_name;     /* domain name unicode header */
  uint32            param;               /* param control */
  DOM_LOGON_ID      logon_id;            /* logon ID */
  UNIHDR            hdr_user_name;       /* user name unicode header */
  UNIHDR            hdr_workgroup_name;  /* workgroup name unicode header */
  RC4_OWF           rc4_lm_owf;          /* rc4 LM OWF Password */
  RC4_OWF           rc4_nt_owf;          /* rc4 NT OWF Password */
  UNISTR2           uni_domain_name;     /* domain name unicode string */
  UNISTR2           uni_user_name;       /* user name unicode string */
  UNISTR2           uni_workgroup_name;  /* workgroup name unicode string */

} DOM_ID_INFO_1;

/* SAM_INFO - sam logon/off id structure */
typedef struct sam_info
{
  DOM_CLNT_INFO client;
  DOM_CRED      rtn_cred; /* return credentials */
  uint16        logon_level;
  uint32        auth_level; /* undocumented */
  
  union
  {
    DOM_ID_INFO_1 id1; /* auth-level 1 */

  } auth;
  
} DOM_SAM_INFO;

/* DOM_GID - group id + user attributes */
typedef struct gid_info
{
  uint32 gid;  /* group id */
  uint32 attr;

} DOM_GID;


