Merge of new 2.2 code into HEAD (Gerald I hate you :-) :-). Allows new SAMR
authorJeremy Allison <jra@samba.org>
Sun, 11 Mar 2001 00:32:10 +0000 (00:32 +0000)
committerJeremy Allison <jra@samba.org>
Sun, 11 Mar 2001 00:32:10 +0000 (00:32 +0000)
RPC code to merge with new passdb code.
Currently rpcclient doesn't compile. I'm working on it...
Jeremy.

86 files changed:
source/Makefile.in
source/include/ntdomain.h
source/include/proto.h
source/include/rpc_client_proto.h
source/include/rpc_lsa.h
source/include/rpc_samr.h
source/include/rpc_srvsvc.h
source/lib/bitmap.c
source/lib/charcnv.c
source/lib/debug.c
source/lib/messages.c
source/lib/msrpc_use.c
source/lib/slprintf.c
source/lib/util.c
source/libsmb/cli_samr.c
source/locking/brlock.c
source/locking/locking.c
source/passdb/passdb.c
source/printing/load.c
source/printing/nt_printing.c
source/printing/printfsp.c
source/printing/printing.c
source/rpc_client/cli_samr.c
source/rpc_parse/parse_dfs.c
source/rpc_parse/parse_lsa.c
source/rpc_parse/parse_net.c
source/rpc_parse/parse_samr.c
source/rpc_parse/parse_spoolss.c
source/rpc_parse/parse_srv.c
source/rpc_server/srv_lsa.c
source/rpc_server/srv_lsa_hnd.c
source/rpc_server/srv_lsa_nt.c
source/rpc_server/srv_netlog.c
source/rpc_server/srv_netlog_nt.c
source/rpc_server/srv_pipe.c
source/rpc_server/srv_pipe_hnd.c
source/rpc_server/srv_reg.c
source/rpc_server/srv_reg_nt.c
source/rpc_server/srv_samr.c
source/rpc_server/srv_samr_nt.c
source/rpc_server/srv_spoolss.c
source/rpc_server/srv_spoolss_nt.c
source/rpc_server/srv_srvsvc.c
source/rpc_server/srv_srvsvc_nt.c
source/rpc_server/srv_util.c
source/rpc_server/srv_wkssvc.c
source/rpc_server/srv_wkssvc_nt.c
source/rpcclient/cmd_samr.c
source/smbd/blocking.c
source/smbd/chgpasswd.c
source/smbd/close.c
source/smbd/conn.c
source/smbd/dir.c
source/smbd/dosmode.c
source/smbd/error.c
source/smbd/fileio.c
source/smbd/filename.c
source/smbd/files.c
source/smbd/ipc.c
source/smbd/lanman.c
source/smbd/message.c
source/smbd/negprot.c
source/smbd/notify.c
source/smbd/notify_hash.c
source/smbd/notify_kernel.c
source/smbd/nttrans.c
source/smbd/open.c
source/smbd/oplock.c
source/smbd/oplock_irix.c
source/smbd/oplock_linux.c
source/smbd/password.c
source/smbd/pipes.c
source/smbd/posix_acls.c
source/smbd/process.c
source/smbd/reply.c
source/smbd/sec_ctx.c
source/smbd/server.c
source/smbd/service.c
source/smbd/trans2.c
source/smbd/uid.c
source/smbd/vfs-wrap.c
source/smbd/vfs.c
source/utils/smbpasswd.c
source/utils/status.c
source/web/cgi.c
source/web/swat.c

index a6e8dd32d9d358f5eb1b232a8c7527809a51e79c..c088602baa7cc1ae724ee43366353bc7d7094808 100644 (file)
@@ -129,12 +129,12 @@ LIBMSRPC_OBJ = libsmb/cli_lsarpc.o libsmb/cli_samr.o libsmb/cli_spoolss.o \
                rpc_client/cli_pipe.o
 
 RPC_SERVER_OBJ = rpc_server/srv_lsa.o rpc_server/srv_lsa_nt.o \
-                 rpc_server/srv_lsa_hnd.o rpc_server/srv_netlog.o \
+                 rpc_server/srv_lsa_hnd.o rpc_server/srv_netlog.o rpc_server/srv_netlog_nt.o \
                  rpc_server/srv_pipe_hnd.o rpc_server/srv_reg.o rpc_server/srv_reg_nt.o \
-                 rpc_server/srv_samr.o rpc_server/srv_srvsvc.o rpc_server/srv_srvsvc_nt.o \
+                 rpc_server/srv_samr.o rpc_server/srv_samr_nt.o rpc_server/srv_srvsvc.o rpc_server/srv_srvsvc_nt.o \
                  rpc_server/srv_util.o rpc_server/srv_wkssvc.o rpc_server/srv_wkssvc_nt.o \
                  rpc_server/srv_pipe.o rpc_server/srv_dfs.o rpc_server/srv_dfs_nt.o \
-                rpc_server/srv_spoolss.o rpc_server/srv_spoolss_nt.o
+                 rpc_server/srv_spoolss.o rpc_server/srv_spoolss_nt.o
 
 # this includes only the low level parse code, not stuff
 # that requires knowledge of security contexts
@@ -150,7 +150,7 @@ RPC_PARSE_OBJ = rpc_parse/parse_lsa.o rpc_parse/parse_net.o \
 
 RPC_PARSE_NEW_OBJ = rpc_parse/parse_lsa.o rpc_parse/parse_net.o \
                 rpc_parse/parse_reg.o rpc_parse/parse_rpc.o \
-                rpc_parse/parse_srv.o rpc_parse/parse_samr_new.o \
+                rpc_parse/parse_srv.o \
                 rpc_parse/parse_wks.o \
                rpc_parse/parse_spoolss.o rpc_parse/parse_dfs.o \
                rpc_parse/parse_creds.o
index 0ae48169fbd5c2c8fb3bd4d012febdc1b71763db..a3fd51948ddc220b2f987056312bf4664c2b9480 100644 (file)
@@ -152,6 +152,27 @@ struct msrpc_state
     uint32 pid;
 };
 
+/*
+ * Handle database - stored per pipe.
+ */
+
+struct policy
+{
+    struct policy *next, *prev;
+    struct pipes_struct *p;
+
+    POLICY_HND pol_hnd;
+
+    void *data_ptr;
+    void (*free_fn)(void *);
+
+};
+
+struct handle_list {
+       struct policy *Policy;
+       size_t count;
+};
+
 typedef struct pipes_struct
 {
        struct pipes_struct *next, *prev;
@@ -224,6 +245,10 @@ typedef struct pipes_struct
 
        /* talloc context to use when allocating memory on this pipe. */
        TALLOC_CTX *mem_ctx;
+
+       /* handle database to use on this pipe. */
+       struct handle_list pipe_handles;
+
 } pipes_struct;
 
 struct api_struct
@@ -265,11 +290,7 @@ struct acct_info
 #include "rpc_lsa.h"
 #include "rpc_netlogon.h"
 #include "rpc_reg.h"
-#if OLD_NTDOMAIN
-#include "rpc_samr_old.h"
-#else
 #include "rpc_samr.h"
-#endif
 #include "rpc_srvsvc.h"
 #include "rpc_wkssvc.h"
 #include "rpc_spoolss.h"
index 3a889ef7e9d9fb56fcaddf324396bc5609793721..6f37f8ffc9880f0ecc5b930a04dc2b8d74c9e4fe 100644 (file)
@@ -26,6 +26,7 @@ BOOL check_access(int sock, char *allow_list, char *deny_list);
 /*The following definitions come from  lib/bitmap.c  */
 
 struct bitmap *bitmap_allocate(int n);
+void bitmap_free(struct bitmap *bm);
 BOOL bitmap_set(struct bitmap *bm, unsigned i);
 BOOL bitmap_clear(struct bitmap *bm, unsigned i);
 BOOL bitmap_query(struct bitmap *bm, unsigned i);
@@ -178,7 +179,6 @@ BOOL msrpc_establish_connection(struct msrpc_state *msrpc,
 
 /*The following definitions come from  lib/msrpc_use.c  */
 
-#if OLD_NTDOMAIN
 void init_msrpc_use(void);
 void free_msrpc_use(void);
 struct msrpc_state *msrpc_use_add(const char* pipe_name,
@@ -190,7 +190,6 @@ BOOL msrpc_use_del(const char* pipe_name,
                                BOOL force_close,
                                BOOL *connection_closed);
 void msrpc_net_use_enum(uint32 *num_cons, struct use_info ***use);
-#endif
 
 /*The following definitions come from  lib/pidfile.c  */
 
@@ -218,870 +217,868 @@ void CatchChildLeaveStatus(void);
 
 int vslprintf(char *str, int n, char *format, va_list ap);
 
-/*The following definitions come from  libsmb/cliconnect.c  */
+/*The following definitions come from  lib/smbrun.c  */
 
-BOOL cli_session_setup(struct cli_state *cli, 
-                      char *user, 
-                      char *pass, int passlen,
-                      char *ntpass, int ntpasslen,
-                      char *workgroup);
-BOOL cli_ulogoff(struct cli_state *cli);
-BOOL cli_send_tconX(struct cli_state *cli, 
-                   char *share, char *dev, char *pass, int passlen);
-BOOL cli_tdis(struct cli_state *cli);
-void cli_negprot_send(struct cli_state *cli);
-BOOL cli_negprot(struct cli_state *cli);
-BOOL cli_session_request(struct cli_state *cli,
-                        struct nmb_name *calling, struct nmb_name *called);
-BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip);
-BOOL cli_reestablish_connection(struct cli_state *cli);
-BOOL cli_establish_connection(struct cli_state *cli, 
-                               char *dest_host, struct in_addr *dest_ip,
-                               struct nmb_name *calling, struct nmb_name *called,
-                               char *service, char *service_type,
-                               BOOL do_shutdown, BOOL do_tcon);
-BOOL attempt_netbios_session_request(struct cli_state *cli, char *srchost, char *desthost,
-                                     struct in_addr *pdest_ip);
+int smbrun(char *cmd,char *outfile,BOOL shared);
 
-/*The following definitions come from  libsmb/clidgram.c  */
+/*The following definitions come from  lib/snprintf.c  */
 
-int cli_send_mailslot(int dgram_sock, BOOL unique, char *mailslot, 
-                     char *buf, int len,
-                     const char *srcname, int src_type, 
-                     const char *dstname, int dest_type,
-                     struct in_addr dest_ip, struct in_addr src_ip,
-                     int dest_port, int src_port);
-int cli_get_response(int dgram_sock, BOOL unique, char *mailslot, char *buf, int bufsiz);
-int cli_get_backup_list(const char *myname, const char *send_to_name);
-int cli_get_backup_server(char *my_name, char *target, char *servername, int namesize);
 
-/*The following definitions come from  libsmb/clientgen.c  */
+/*The following definitions come from  lib/substitute.c  */
 
-int cli_set_port(struct cli_state *cli, int port);
-BOOL cli_receive_smb(struct cli_state *cli);
-BOOL cli_send_smb(struct cli_state *cli);
-void cli_setup_packet(struct cli_state *cli);
-void cli_setup_bcc(struct cli_state *cli, void *p);
-void cli_init_creds(struct cli_state *cli, const struct ntuser_creds *usr);
-struct cli_state *cli_initialise(struct cli_state *cli);
-void cli_shutdown(struct cli_state *cli);
-void cli_sockopt(struct cli_state *cli, char *options);
-uint16 cli_setpid(struct cli_state *cli, uint16 pid);
+void standard_sub_basic(char *str);
+void standard_sub_advanced(int snum, char *user, char *connectpath, gid_t gid, char *str);
+void standard_sub_conn(connection_struct *conn, char *str);
+void standard_sub_snum(int snum, char *str);
+void standard_sub_vuser(char *str, user_struct *vuser);
+void standard_sub_vsnum(char *str, user_struct *vuser, int snum);
 
-/*The following definitions come from  libsmb/clierror.c  */
+/*The following definitions come from  lib/sysacls.c  */
 
-char *cli_errstr(struct cli_state *cli);
-int cli_error(struct cli_state *cli, uint8 *eclass, uint32 *num, uint32 *nt_rpc_error);
+int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
+int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
+int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
+void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d);
+SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type);
+SMB_ACL_T sys_acl_get_fd(int fd);
+int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
+int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
+int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
+char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen);
+SMB_ACL_T sys_acl_init( int count);
+int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
+int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
+int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual);
+int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
+int sys_acl_valid( SMB_ACL_T theacl );
+int sys_acl_set_file( char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
+int sys_acl_set_fd( int fd, SMB_ACL_T theacl);
+int sys_acl_free_text(char *text);
+int sys_acl_free_acl(SMB_ACL_T the_acl) ;
+int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p);
+int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p);
+int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
+void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
+SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
+SMB_ACL_T sys_acl_get_fd(int fd);
+int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d);
+int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm);
+int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm);
+char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p);
+SMB_ACL_T sys_acl_init(int count);
+int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p);
+int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type);
+int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p);
+int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d);
+int sys_acl_valid(SMB_ACL_T acl_d);
+int sys_acl_set_file(char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d);
+int sys_acl_set_fd(int fd, SMB_ACL_T acl_d);
+int sys_acl_free_text(char *text);
+int sys_acl_free_acl(SMB_ACL_T acl_d) ;
+int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p);
+int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p);
+int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
+void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
+SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
+SMB_ACL_T sys_acl_get_fd(int fd);
+int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d);
+int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm);
+int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm);
+char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p);
+SMB_ACL_T sys_acl_init(int count);
+int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p);
+int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type);
+int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p);
+int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d);
+int sys_acl_valid(SMB_ACL_T acl_d);
+int sys_acl_set_file(char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d);
+int sys_acl_set_fd(int fd, SMB_ACL_T acl_d);
+int sys_acl_free_text(char *text);
+int sys_acl_free_acl(SMB_ACL_T acl_d) ;
+int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
+int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
+int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
+void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d);
+SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type);
+SMB_ACL_T sys_acl_get_fd(int fd);
+int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
+int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
+int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
+char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen);
+int sys_acl_free_text(char *text);
+SMB_ACL_T sys_acl_init( int count);
+int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
+int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
+int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual);
+int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
+int sys_acl_valid( SMB_ACL_T theacl );
+int sys_acl_set_file( char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
+int sys_acl_set_fd( int fd, SMB_ACL_T theacl);
+int sys_acl_free_acl(SMB_ACL_T the_acl) ;
 
-/*The following definitions come from  libsmb/clifile.c  */
+/*The following definitions come from  lib/system.c  */
 
-BOOL cli_rename(struct cli_state *cli, char *fname_src, char *fname_dst);
-BOOL cli_unlink(struct cli_state *cli, char *fname);
-BOOL cli_mkdir(struct cli_state *cli, char *dname);
-BOOL cli_rmdir(struct cli_state *cli, char *dname);
-int cli_nt_create(struct cli_state *cli, char *fname, uint32 DesiredAccess);
-int cli_open(struct cli_state *cli, char *fname, int flags, int share_mode);
-BOOL cli_close(struct cli_state *cli, int fnum);
-BOOL cli_lock(struct cli_state *cli, int fnum, 
-             uint32 offset, uint32 len, int timeout, enum brl_type lock_type);
-BOOL cli_unlock(struct cli_state *cli, int fnum, uint32 offset, uint32 len);
-BOOL cli_lock64(struct cli_state *cli, int fnum, 
-               SMB_BIG_UINT offset, SMB_BIG_UINT len, int timeout, enum brl_type lock_type);
-BOOL cli_unlock64(struct cli_state *cli, int fnum, SMB_BIG_UINT offset, SMB_BIG_UINT len);
-BOOL cli_getattrE(struct cli_state *cli, int fd, 
-                 uint16 *attr, size_t *size, 
-                 time_t *c_time, time_t *a_time, time_t *m_time);
-BOOL cli_getatr(struct cli_state *cli, char *fname, 
-               uint16 *attr, size_t *size, time_t *t);
-BOOL cli_setatr(struct cli_state *cli, char *fname, uint16 attr, time_t t);
-BOOL cli_chkpath(struct cli_state *cli, char *path);
-BOOL cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail);
+int sys_usleep(long usecs);
+int sys_stat(const char *fname,SMB_STRUCT_STAT *sbuf);
+int sys_fstat(int fd,SMB_STRUCT_STAT *sbuf);
+int sys_lstat(const char *fname,SMB_STRUCT_STAT *sbuf);
+int sys_ftruncate(int fd, SMB_OFF_T offset);
+SMB_OFF_T sys_lseek(int fd, SMB_OFF_T offset, int whence);
+int sys_fseek(FILE *fp, SMB_OFF_T offset, int whence);
+SMB_OFF_T sys_ftell(FILE *fp);
+int sys_creat(const char *path, mode_t mode);
+int sys_open(const char *path, int oflag, mode_t mode);
+FILE *sys_fopen(const char *path, const char *type);
+SMB_STRUCT_DIRENT *sys_readdir(DIR *dirp);
+int sys_waitpid(pid_t pid,int *status,int options);
+char *sys_getwd(char *s);
+int sys_chown(const char *fname,uid_t uid,gid_t gid);
+int sys_chroot(const char *dname);
+struct hostent *sys_gethostbyname(const char *name);
+void oplock_set_capability(BOOL this_process, BOOL inherit);
+long sys_random(void);
+void sys_srandom(unsigned int seed);
+int groups_max(void);
+int sys_getgroups(int setlen, gid_t *gidset);
+int sys_setgroups(int setlen, gid_t *gidset);
+void sys_setpwent(void);
+struct passwd *sys_getpwent(void);
+void sys_endpwent(void);
+struct passwd *sys_getpwnam(const char *name);
+struct passwd *sys_getpwuid(uid_t uid);
+int wsys_stat(const smb_ucs2_t *wfname,SMB_STRUCT_STAT *sbuf);
+int wsys_lstat(const smb_ucs2_t *wfname,SMB_STRUCT_STAT *sbuf);
+int wsys_creat(const smb_ucs2_t *wfname, mode_t mode);
+int wsys_open(const smb_ucs2_t *wfname, int oflag, mode_t mode);
+FILE *wsys_fopen(const smb_ucs2_t *wfname, const char *type);
+DIR *wsys_opendir(const smb_ucs2_t *wfname);
+smb_ucs2_t *wsys_getwd(smb_ucs2_t *s);
+int wsys_chown(const smb_ucs2_t *wfname, uid_t uid, gid_t gid);
+int wsys_chroot(const smb_ucs2_t *wfname);
+pid_t sys_fork(void);
+pid_t sys_getpid(void);
+int sys_popen(const char *command);
+int sys_pclose(int fd);
 
-/*The following definitions come from  libsmb/clilist.c  */
+/*The following definitions come from  lib/talloc.c  */
 
-int cli_list_new(struct cli_state *cli,const char *Mask,uint16 attribute, 
-                void (*fn)(file_info *, const char *, void *), void *state);
-int cli_list_old(struct cli_state *cli,const char *Mask,uint16 attribute, 
-                void (*fn)(file_info *, const char *, void *), void *state);
-int cli_list(struct cli_state *cli,const char *Mask,uint16 attribute, 
-            void (*fn)(file_info *, const char *, void *), void *state);
+TALLOC_CTX *talloc_init(void);
+void *talloc(TALLOC_CTX *t, size_t size);
+void talloc_destroy_pool(TALLOC_CTX *t);
+void talloc_destroy(TALLOC_CTX *t);
+size_t talloc_pool_size(TALLOC_CTX *t);
+void *talloc_zero(TALLOC_CTX *t, size_t size);
+void *talloc_memdup(TALLOC_CTX *t, void *p, size_t size);
 
-/*The following definitions come from  libsmb/cli_lsarpc.c  */
+/*The following definitions come from  lib/time.c  */
 
-struct cli_state *cli_lsa_initialise(struct cli_state *cli, char *system_name,
-                                    struct ntuser_creds *creds);
-void cli_lsa_shutdown(struct cli_state *cli);
-uint32 cli_lsa_open_policy(struct cli_state *cli, BOOL sec_qos, 
-                          uint32 des_access, POLICY_HND *pol);
-uint32 cli_lsa_close(struct cli_state *cli, POLICY_HND *pol);
-uint32 cli_lsa_lookup_sids(struct cli_state *cli, POLICY_HND *pol,
-                          int num_sids, DOM_SID *sids, char ***names, 
-                          uint32 **types, int *num_names);
-uint32 cli_lsa_lookup_names(struct cli_state *cli, POLICY_HND *pol,
-                           int num_names, char **names, DOM_SID **sids,
-                           uint32 **types, int *num_sids);
-uint32 cli_lsa_query_info_policy(struct cli_state *cli, POLICY_HND *pol, 
-                                uint16 info_class, fstring domain_name, 
-                                DOM_SID * domain_sid);
-uint32 cli_lsa_enum_trust_dom(struct cli_state *cli, POLICY_HND *pol, 
-                             uint32 *enum_ctx, uint32 *num_domains,
-                             char ***domain_names, DOM_SID **domain_sids);
+void GetTimeOfDay(struct timeval *tval);
+void TimeInit(void);
+int TimeDiff(time_t t);
+struct tm *LocalTime(time_t *t);
+time_t nt_time_to_unix(NTTIME *nt);
+time_t interpret_long_date(char *p);
+void unix_to_nt_time(NTTIME *nt, time_t t);
+void put_long_date(char *p,time_t t);
+BOOL null_mtime(time_t mtime);
+void put_dos_date(char *buf,int offset,time_t unixdate);
+void put_dos_date2(char *buf,int offset,time_t unixdate);
+void put_dos_date3(char *buf,int offset,time_t unixdate);
+time_t make_unix_date(void *date_ptr);
+time_t make_unix_date2(void *date_ptr);
+time_t make_unix_date3(void *date_ptr);
+char *http_timestring(time_t t);
+char *timestring(BOOL hires);
+time_t get_create_time(SMB_STRUCT_STAT *st,BOOL fake_dirs);
 
-/*The following definitions come from  libsmb/climessage.c  */
-
-BOOL cli_message_start(struct cli_state *cli, char *host, char *username, 
-                             int *grp);
-BOOL cli_message_text(struct cli_state *cli, char *msg, int len, int grp);
-BOOL cli_message_end(struct cli_state *cli, int grp);
-
-/*The following definitions come from  libsmb/cliprint.c  */
+/*The following definitions come from  lib/ufc.c  */
 
-int cli_print_queue(struct cli_state *cli, 
-                   void (*fn)(struct print_job_info *));
-int cli_printjob_del(struct cli_state *cli, int job);
+char *ufc_crypt(char *key,char *salt);
 
-/*The following definitions come from  libsmb/clirap.c  */
+/*The following definitions come from  lib/username.c  */
 
-BOOL cli_api_pipe(struct cli_state *cli, char *pipe_name, 
-                  uint16 *setup, uint32 setup_count, uint32 max_setup_count,
-                  char *params, uint32 param_count, uint32 max_param_count,
-                  char *data, uint32 data_count, uint32 max_data_count,
-                  char **rparam, uint32 *rparam_count,
-                  char **rdata, uint32 *rdata_count);
-BOOL cli_api(struct cli_state *cli,
-            char *param, int prcnt, int mprcnt,
-            char *data, int drcnt, int mdrcnt,
-            char **rparam, int *rprcnt,
-            char **rdata, int *rdrcnt);
-BOOL cli_NetWkstaUserLogon(struct cli_state *cli,char *user, char *workstation);
-int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32, const char *, void *), void *state);
-BOOL cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
-                      void (*fn)(const char *, uint32, const char *, void *),
-                      void *state);
-BOOL cli_oem_change_password(struct cli_state *cli, const char *user, const char *new_password,
-                             const char *old_password);
-BOOL cli_qpathinfo(struct cli_state *cli, const char *fname, 
-                  time_t *c_time, time_t *a_time, time_t *m_time, 
-                  size_t *size, uint16 *mode);
-BOOL cli_qpathinfo2(struct cli_state *cli, const char *fname, 
-                   time_t *c_time, time_t *a_time, time_t *m_time, 
-                   time_t *w_time, size_t *size, uint16 *mode,
-                   SMB_INO_T *ino);
-BOOL cli_qfileinfo(struct cli_state *cli, int fnum, 
-                  uint16 *mode, size_t *size,
-                  time_t *c_time, time_t *a_time, time_t *m_time, 
-                  time_t *w_time, SMB_INO_T *ino);
+char *get_user_home_dir(char *user);
+BOOL map_username(char *user);
+struct passwd *Get_Pwnam(char *user,BOOL allow_change);
+BOOL user_in_group_list(char *user,char *gname);
+BOOL user_in_list(char *user,char *list);
+struct passwd *smb_getpwnam(char *user, BOOL allow_change);
 
-/*The following definitions come from  libsmb/clireadwrite.c  */
+/*The following definitions come from  lib/util.c  */
 
-size_t cli_read(struct cli_state *cli, int fnum, char *buf, off_t offset, size_t size);
-ssize_t cli_write(struct cli_state *cli,
-                 int fnum, uint16 write_mode,
-                 char *buf, off_t offset, size_t size);
-ssize_t cli_smbwrite(struct cli_state *cli,
-                    int fnum, char *buf, off_t offset, size_t size1);
+char *tmpdir(void);
+BOOL in_group(gid_t group, gid_t current_gid, int ngroups, gid_t *groups);
+char *Atoic(char *p, int *n, char *c);
+char *get_numlist(char *p, uint32 **num, int *count);
+BOOL file_exist(char *fname,SMB_STRUCT_STAT *sbuf);
+int file_rename(char *from, char *to);
+time_t file_modtime(char *fname);
+BOOL directory_exist(char *dname,SMB_STRUCT_STAT *st);
+SMB_OFF_T get_file_size(char *file_name);
+char *attrib_string(uint16 mode);
+void show_msg(char *buf);
+void smb_setlen(char *buf,int len);
+int set_message(char *buf,int num_words,int num_bytes,BOOL zero);
+void set_message_bcc(char *buf,int num_bytes);
+void set_message_end(void *outbuf,void *end_ptr);
+void dos_clean_name(char *s);
+void unix_clean_name(char *s);
+void make_dir_struct(char *buf,char *mask,char *fname,SMB_OFF_T size,int mode,time_t date);
+void close_low_fds(void);
+int set_blocking(int fd, BOOL set);
+SMB_OFF_T transfer_file(int infd,int outfd,SMB_OFF_T n,char *header,int headlen,int align);
+void msleep(int t);
+void become_daemon(void);
+BOOL yesno(char *p);
+void *Realloc(void *p,size_t size);
+void safe_free(void *p);
+BOOL get_myname(char *my_name);
+int interpret_protocol(char *str,int def);
+BOOL is_ipaddress(const char *str);
+uint32 interpret_addr(char *str);
+struct in_addr *interpret_addr2(char *str);
+BOOL zero_ip(struct in_addr ip);
+BOOL same_net(struct in_addr ip1,struct in_addr ip2,struct in_addr mask);
+struct hostent *Get_Hostbyname(const char *name);
+BOOL process_exists(pid_t pid);
+char *uidtoname(uid_t uid);
+char *gidtoname(gid_t gid);
+uid_t nametouid(char *name);
+gid_t nametogid(char *name);
+void smb_panic(char *why);
+char *readdirname(DIR *p);
+BOOL is_in_path(char *name, name_compare_entry *namelist);
+void set_namearray(name_compare_entry **ppname_array, char *namelist);
+void free_namearray(name_compare_entry *name_array);
+BOOL fcntl_lock(int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type);
+BOOL is_myname(char *s);
+void set_remote_arch(enum remote_arch_types type);
+enum remote_arch_types get_remote_arch(void);
+void out_ascii(FILE *f, unsigned char *buf,int len);
+void out_data(FILE *f,char *buf1,int len, int per_line);
+void print_asc(int level, unsigned char *buf,int len);
+void dump_data(int level,char *buf1,int len);
+char *tab_depth(int depth);
+int str_checksum(const char *s);
+void zero_free(void *p, size_t size);
+int set_maxfiles(int requested_max);
+BOOL reg_split_key(char *full_keyname, uint32 *reg_type, char *key_name);
+char *smbd_mktemp(char *template);
+void *memdup(void *p, size_t size);
+char *myhostname(void);
+char *lock_path(char *name);
+char *parent_dirname(const char *path);
+BOOL ms_has_wild(char *s);
+BOOL mask_match(char *string, char *pattern, BOOL is_case_sensitive);
+int _Insure_trap_error(int a1, int a2, int a3, int a4, int a5, int a6);
 
-/*The following definitions come from  libsmb/cli_samr.c  */
+/*The following definitions come from  lib/util_array.c  */
 
-#if NEW_NTDOMAIN
-struct cli_state *cli_samr_initialise(struct cli_state *cli, char *system_name,
-                                     struct ntuser_creds *creds);
-void cli_samr_shutdown(struct cli_state *cli);
-uint32 cli_samr_connect(struct cli_state *cli, char *srv_name,
-                       uint32 access_mask, POLICY_HND *connect_pol);
-uint32 cli_samr_close(struct cli_state *cli, POLICY_HND *connect_pol);
-uint32 cli_samr_open_domain(struct cli_state *cli, POLICY_HND *connect_pol,
-                           uint32 access_mask, DOM_SID *domain_sid,
-                           POLICY_HND *domain_pol);
-uint32 cli_samr_open_user(struct cli_state *cli, POLICY_HND *domain_pol,
-                         uint32 access_mask, uint32 user_rid,
-                         POLICY_HND *user_pol);
-uint32 cli_samr_open_group(struct cli_state *cli, POLICY_HND *domain_pol,
-                         uint32 access_mask, uint32 group_rid,
-                         POLICY_HND *group_pol);
-uint32 cli_samr_query_userinfo(struct cli_state *cli, POLICY_HND *user_pol, 
-                              uint16 switch_value, SAM_USERINFO_CTR *ctr);
-uint32 cli_samr_query_groupinfo(struct cli_state *cli, POLICY_HND *group_pol,
-                               uint32 info_level, GROUP_INFO_CTR *ctr);
-uint32 cli_samr_query_usergroups(struct cli_state *cli, POLICY_HND *user_pol,
-                                uint32 *num_groups, DOM_GID **gid);
-uint32 cli_samr_query_groupmem(struct cli_state *cli, POLICY_HND *group_pol,
-                              uint32 *num_mem, uint32 **rid, uint32 **attr);
-#endif
+void free_void_array(uint32 num_entries, void **entries,
+               void(free_item)(void*));
+void* add_copy_to_array(uint32 *len, void ***array, const void *item,
+       void*(item_dup)(const void*), BOOL alloc_anyway);
+void* add_item_to_array(uint32 *len, void ***array, void *item);
+void free_use_info_array(uint32 num_entries, struct use_info **entries);
+struct use_info* add_use_info_to_array(uint32 *len, struct use_info ***array,
+                               const struct use_info *name);
+void free_char_array(uint32 num_entries, char **entries);
+char* add_chars_to_array(uint32 *len, char ***array, const char *name);
+void free_uint32_array(uint32 num_entries, uint32 **entries);
+uint32* add_uint32s_to_array(uint32 *len, uint32 ***array, const uint32 *name);
+void free_sid_array(uint32 num_entries, DOM_SID **entries);
+DOM_SID* add_sid_to_array(uint32 *len, DOM_SID ***array, const DOM_SID *sid);
 
-/*The following definitions come from  libsmb/clisecdesc.c  */
+/*The following definitions come from  lib/util_file.c  */
 
-SEC_DESC *cli_query_secdesc(struct cli_state *cli,int fd);
-BOOL cli_set_secdesc(struct cli_state *cli,int fd, SEC_DESC *sd);
+BOOL do_file_lock(int fd, int waitsecs, int type);
+BOOL file_lock(int fd, int type, int secs, int *plock_depth);
+BOOL file_unlock(int fd, int *plock_depth);
+void *startfilepwent(char *pfile, char *s_readbuf, int bufsize,
+                               int *file_lock_depth, BOOL update);
+void endfilepwent(void *vp, int *file_lock_depth);
+SMB_BIG_UINT getfilepwpos(void *vp);
+BOOL setfilepwpos(void *vp, SMB_BIG_UINT tok);
+int getfileline(void *vp, char *linebuf, int linebuf_size);
+char *fgets_slash(char *s2,int maxlen,FILE *f);
+char *file_pload(char *syscmd, size_t *size);
+char *file_load(char *fname, size_t *size);
+char **file_lines_load(char *fname, int *numlines, BOOL convert);
+char **file_lines_pload(char *syscmd, int *numlines, BOOL convert);
+void file_lines_free(char **lines);
+void file_lines_slashcont(char **lines);
 
-/*The following definitions come from  libsmb/cli_spoolss.c  */
+/*The following definitions come from  lib/util_list.c  */
 
-struct cli_state *cli_spoolss_initialise(struct cli_state *cli, 
-                                        char *system_name,
-                                        struct ntuser_creds *creds);
-void cli_spoolss_shutdown(struct cli_state *cli);
-uint32 cli_spoolss_open_printer_ex(struct cli_state *cli, char *printername,
-                                  char *datatype, uint32 access_required,
-                                  char *station, char *username,
-                                  POLICY_HND *pol);
-uint32 cli_spoolss_closeprinter(struct cli_state *cli, POLICY_HND *pol);
-uint32 cli_spoolss_enum_printers(struct cli_state *cli, uint32 flags,
-                                uint32 level, int *returned, 
-                                PRINTER_INFO_CTR *ctr);
-uint32 cli_spoolss_enum_ports(struct cli_state *cli, uint32 level, 
-                             int *returned, PORT_INFO_CTR *ctr);
-uint32 cli_spoolss_getprinter(struct cli_state *cli, POLICY_HND *pol,
-                             uint32 level, PRINTER_INFO_CTR *ctr);
+BOOL copy_policy_hnd (POLICY_HND *dest, const POLICY_HND *src);
+BOOL compare_rpc_hnd_node(const RPC_HND_NODE *x, 
+                         const RPC_HND_NODE *y);
+BOOL RpcHndList_set_connection(const POLICY_HND *hnd, 
+                              struct cli_connection *con);
+BOOL RpcHndList_del_connection(const POLICY_HND *hnd);
+struct cli_connection* RpcHndList_get_connection(const POLICY_HND *hnd);
 
-/*The following definitions come from  libsmb/clistr.c  */
+/*The following definitions come from  lib/util_seaccess.c  */
 
-int clistr_push(struct cli_state *cli, void *dest, const char *src, int dest_len, int flags);
-int clistr_push_size(struct cli_state *cli, const void *dest, const char *src, int dest_len, int flags);
-int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len, int src_len, int flags);
-int clistr_pull_size(struct cli_state *cli, const void *src, int src_len);
-int clistr_align(struct cli_state *cli, int offset);
+void se_map_generic(uint32 *access_mask, struct generic_mapping *mapping);
+BOOL se_access_check(SEC_DESC *sd, struct current_user *user,
+                    uint32 acc_desired, uint32 *acc_granted, uint32 *status);
+SEC_DESC_BUF *se_create_child_secdesc(TALLOC_CTX *ctx, SEC_DESC *parent_ctr, 
+                                     BOOL child_container);
 
-/*The following definitions come from  libsmb/clitrans.c  */
+/*The following definitions come from  lib/util_sec.c  */
 
-BOOL cli_send_trans(struct cli_state *cli, int trans, 
-                   char *pipe_name, 
-                   int fid, int flags,
-                   uint16 *setup, int lsetup, int msetup,
-                   char *param, int lparam, int mparam,
-                   char *data, int ldata, int mdata);
-BOOL cli_receive_trans(struct cli_state *cli,int trans,
-                              char **param, int *param_len,
-                              char **data, int *data_len);
-BOOL cli_send_nt_trans(struct cli_state *cli, 
-                      int function, 
-                      int flags,
-                      uint16 *setup, int lsetup, int msetup,
-                      char *param, int lparam, int mparam,
-                      char *data, int ldata, int mdata);
-BOOL cli_receive_nt_trans(struct cli_state *cli,
-                         char **param, int *param_len,
-                         char **data, int *data_len);
+void gain_root_privilege(void);
+void gain_root_group_privilege(void);
+void set_effective_uid(uid_t uid);
+void set_effective_gid(gid_t gid);
+void save_re_uid(void);
+void restore_re_uid(void);
+int set_re_uid(void);
+void become_user_permanently(uid_t uid, gid_t gid);
 
-/*The following definitions come from  libsmb/credentials.c  */
+/*The following definitions come from  lib/util_sid.c  */
 
-char *credstr(uchar *cred);
-void cred_session_key(DOM_CHAL *clnt_chal, DOM_CHAL *srv_chal, char *pass, 
-                     uchar session_key[8]);
-void cred_create(uchar session_key[8], DOM_CHAL *stor_cred, UTIME timestamp, 
-                DOM_CHAL *cred);
-int cred_assert(DOM_CHAL *cred, uchar session_key[8], DOM_CHAL *stored_cred,
-               UTIME timestamp);
-BOOL clnt_deal_with_creds(uchar sess_key[8],
-                         DOM_CRED *sto_clnt_cred, DOM_CRED *rcv_srv_cred);
-BOOL deal_with_creds(uchar sess_key[8],
-                    DOM_CRED *sto_clnt_cred, 
-                    DOM_CRED *rcv_clnt_cred, DOM_CRED *rtn_srv_cred);
-
-/*The following definitions come from  libsmb/namequery.c  */
-
-struct node_status *name_status_query(int fd,struct nmb_name *name,
-                                     struct in_addr to_ip, int *num_names);
-BOOL name_status_find(int type, struct in_addr to_ip, char *name);
-BOOL name_register(int fd, const char *name, int name_type,
-                  struct in_addr name_ip, int opcode,
-                  BOOL bcast, 
-                  struct in_addr to_ip, int *count);
-struct in_addr *name_query(int fd,const char *name,int name_type, 
-                          BOOL bcast,BOOL recurse,
-                          struct in_addr to_ip, int *count);
-FILE *startlmhosts(char *fname);
-BOOL getlmhostsent( FILE *fp, pstring name, int *name_type, struct in_addr *ipaddr);
-void endlmhosts(FILE *fp);
-BOOL name_register_wins(const char *name, int name_type);
-BOOL name_resolve_bcast(const char *name, int name_type,
-                       struct in_addr **return_ip_list, int *return_count);
-BOOL resolve_name(const char *name, struct in_addr *return_ip, int name_type);
-BOOL resolve_srv_name(const char* srv_name, fstring dest_host,
-                                struct in_addr *ip);
-BOOL find_master_ip(char *group, struct in_addr *master_ip);
-BOOL lookup_pdc_name(const char *srcname, const char *domain, struct in_addr *pdc_ip, char *ret_name);
-BOOL get_dc_list(BOOL pdc_only, char *group, struct in_addr **ip_list, int *count);
-
-/*The following definitions come from  libsmb/nmblib.c  */
-
-void debug_nmb_packet(struct packet_struct *p);
-char *nmb_namestr(struct nmb_name *n);
-struct packet_struct *copy_packet(struct packet_struct *packet);
-void free_packet(struct packet_struct *packet);
-struct packet_struct *parse_packet(char *buf,int length,
-                                  enum packet_type packet_type);
-struct packet_struct *read_packet(int fd,enum packet_type packet_type);
-void make_nmb_name( struct nmb_name *n, const char *name, int type);
-BOOL nmb_name_equal(struct nmb_name *n1, struct nmb_name *n2);
-int build_packet(char *buf, struct packet_struct *p);
-BOOL send_packet(struct packet_struct *p);
-struct packet_struct *receive_packet(int fd,enum packet_type type,int t);
-struct packet_struct *receive_nmb_packet(int fd, int t, int trn_id);
-struct packet_struct *receive_dgram_packet(int fd, int t, char *mailslot_name);
-BOOL match_mailslot_name(struct packet_struct *p, char *mailslot_name);
-void sort_query_replies(char *data, int n, struct in_addr ip);
-char *dns_to_netbios_name(char *dns_name);
-int name_mangle( char *In, char *Out, char name_type );
-int name_extract(char *buf,int ofs,char *name);
-int name_len(char *s1);
+void generate_wellknown_sids(void);
+BOOL map_domain_sid_to_name(DOM_SID *sid, char *nt_domain);
+BOOL lookup_known_rid(DOM_SID *sid, uint32 rid, char *name, enum SID_NAME_USE *psid_name_use);
+BOOL map_domain_name_to_sid(DOM_SID *sid, char *nt_domain);
+void split_domain_name(const char *fullname, char *domain, char *name);
+char *sid_to_string(fstring sidstr_out, DOM_SID *sid);
+BOOL string_to_sid(DOM_SID *sidout, char *sidstr);
+BOOL sid_append_rid(DOM_SID *sid, uint32 rid);
+BOOL sid_split_rid(DOM_SID *sid, uint32 *rid);
+void sid_copy(DOM_SID *dst, const DOM_SID *src);
+DOM_SID *sid_dup(DOM_SID *src);
+BOOL sid_linearize(char *outbuf, size_t len, DOM_SID *sid);
+int sid_compare(const DOM_SID *sid1, const DOM_SID *sid2);
+BOOL sid_equal(const DOM_SID *sid1, const DOM_SID *sid2);
+size_t sid_size(DOM_SID *sid);
 
-/*The following definitions come from  libsmb/nterr.c  */
+/*The following definitions come from  lib/util_sock.c  */
 
-BOOL get_safe_nt_error_msg(uint32 nt_code,char *msg, size_t len);
-char *get_nt_error_msg(uint32 nt_code);
+BOOL is_a_socket(int fd);
+void set_socket_options(int fd, char *options);
+ssize_t read_udp_socket(int fd,char *buf,size_t len);
+ssize_t read_with_timeout(int fd,char *buf,size_t mincnt,size_t maxcnt,unsigned int time_out);
+BOOL send_keepalive(int client);
+ssize_t read_data(int fd,char *buffer,size_t N);
+ssize_t write_data(int fd,char *buffer,size_t N);
+ssize_t write_socket_data(int fd,char *buffer,size_t N);
+ssize_t write_socket(int fd,char *buf,size_t len);
+ssize_t read_smb_length(int fd,char *inbuf,unsigned int timeout);
+BOOL receive_smb(int fd,char *buffer, unsigned int timeout);
+BOOL client_receive_smb(int fd,char *buffer, unsigned int timeout);
+BOOL send_null_session_msg(int fd);
+BOOL send_smb(int fd,char *buffer);
+BOOL send_one_packet(char *buf,int len,struct in_addr ip,int port,int type);
+int open_socket_in(int type, int port, int dlevel,uint32 socket_addr, BOOL rebind);
+int open_socket_out(int type, struct in_addr *addr, int port ,int timeout);
+void reset_globals_after_fork(void);
+void client_setfd(int fd);
+char *client_name(void);
+char *client_addr(void);
+char *get_socket_name(int fd);
+char *get_socket_addr(int fd);
+int open_pipe_sock(char *path);
+int create_pipe_socket(char *dir, int dir_perms,
+                               char *path, int path_perms);
 
-/*The following definitions come from  libsmb/passchange.c  */
+/*The following definitions come from  lib/util_str.c  */
 
-BOOL remote_password_change(const char *remote_machine, const char *user_name, 
-                           const char *old_passwd, const char *new_passwd,
-                           char *err_str, size_t err_str_len);
+void set_first_token(char *ptr);
+BOOL next_token(char **ptr,char *buff,char *sep, size_t bufsize);
+char **toktocliplist(int *ctok, char *sep);
+int StrCaseCmp(const char *s, const char *t);
+int StrnCaseCmp(const char *s, const char *t, size_t n);
+BOOL strequal(const char *s1, const char *s2);
+BOOL strnequal(const char *s1,const char *s2,size_t n);
+BOOL strcsequal(const char *s1,const char *s2);
+int strwicmp(char *psz1, char *psz2);
+void strlower(char *s);
+void strupper(char *s);
+void strnorm(char *s);
+BOOL strisnormal(char *s);
+void string_replace(char *s,char oldc,char newc);
+char *skip_string(char *buf,size_t n);
+size_t str_charnum(const char *s);
+BOOL trim_string(char *s,const char *front,const char *back);
+BOOL strhasupper(const char *s);
+BOOL strhaslower(const char *s);
+size_t count_chars(const char *s,char c);
+BOOL str_is_all(const char *s,char c);
+char *safe_strcpy(char *dest,const char *src, size_t maxlength);
+char *safe_strcat(char *dest, const char *src, size_t maxlength);
+char *alpha_strcpy(char *dest, const char *src, size_t maxlength);
+char *StrnCpy(char *dest,const char *src,size_t n);
+char *strncpyn(char *dest, const char *src,size_t n, char c);
+size_t strhex_to_str(char *p, size_t len, const char *strhex);
+BOOL in_list(char *s,char *list,BOOL casesensitive);
+void string_free(char **s);
+BOOL string_set(char **dest,const char *src);
+void string_sub(char *s,const char *pattern,const char *insert, size_t len);
+void fstring_sub(char *s,const char *pattern,const char *insert);
+void pstring_sub(char *s,const char *pattern,const char *insert);
+void all_string_sub(char *s,const char *pattern,const char *insert, size_t len);
+void split_at_last_component(char *path, char *front, char sep, char *back);
+char *octal_string(int i);
+char *string_truncate(char *s, int length);
+void parse_domain_user(char *domuser, fstring domain, fstring user);
 
-/*The following definitions come from  libsmb/pwd_cache.c  */
+/*The following definitions come from  lib/util_unistr.c  */
 
-void pwd_init(struct pwd_info *pwd);
-BOOL pwd_is_nullpwd(const struct pwd_info *pwd);
-BOOL pwd_compare(struct pwd_info *pwd1, struct pwd_info *pwd2);
-void pwd_read(struct pwd_info *pwd, char *passwd_report, BOOL do_encrypt);
-void pwd_set_nullpwd(struct pwd_info *pwd);
-void pwd_set_cleartext(struct pwd_info *pwd, char *clr);
-void pwd_get_cleartext(struct pwd_info *pwd, char *clr);
-void pwd_set_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16]);
-void pwd_get_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16]);
-void pwd_make_lm_nt_16(struct pwd_info *pwd, char *clr);
-void pwd_make_lm_nt_owf(struct pwd_info *pwd, uchar cryptkey[8]);
-void pwd_get_lm_nt_owf(struct pwd_info *pwd, uchar lm_owf[24], uchar nt_owf[24]);
+size_t dos_PutUniCode(char *dst,const char *src, ssize_t len, BOOL null_terminate);
+void unistr_to_dos(char *dest, const char *src, size_t len);
+char *skip_unibuf(char *src, size_t len);
+char *dos_unistrn2(uint16 *src, int len);
+char *dos_unistr2(uint16 *src);
+char *dos_unistr2_to_str(UNISTR2 *str);
+void ascii_to_unistr(uint16 *dest, const char *src, int maxlen);
+void unistr_to_ascii(char *dest, const uint16 *src, int len);
+void unistr2_to_ascii(char *dest, const UNISTR2 *str, size_t maxlen);
+uint32 buffer2_to_uint32(BUFFER2 *str);
+char *dos_buffer2_to_str(BUFFER2 *str);
+char *dos_buffer2_to_multistr(BUFFER2 *str);
+size_t dos_struni2(char *dst, const char *src, size_t max_len);
+char *dos_unistr(char *buf);
+int unistrcpy(char *dst, char *src);
+void default_unicode_map(smb_ucs2_t **pp_cp_to_ucs2, uint16 **pp_ucs2_to_cp);
+BOOL load_unicode_map(const char *codepage, smb_ucs2_t **pp_cp_to_ucs2, uint16 **pp_ucs2_to_cp);
+BOOL load_dos_unicode_map(int codepage);
+BOOL load_unix_unicode_map(const char *unix_char_set);
+smb_ucs2_t *multibyte_to_unicode(smb_ucs2_t *dst, const char *src,
+                                 size_t dst_len, smb_ucs2_t *cp_to_ucs2);
+char *unicode_to_unix(char *dst, const smb_ucs2_t *src, size_t dst_len);
+smb_ucs2_t *unix_to_unicode(smb_ucs2_t *dst, const char *src, size_t dst_len);
+char *unicode_to_dos(char *dst, const smb_ucs2_t *src, size_t dst_len);
+size_t unicode_to_dos_char(char *dst, const smb_ucs2_t src);
+smb_ucs2_t *dos_to_unicode(smb_ucs2_t *dst, const char *src, size_t dst_len);
+size_t strlen_w(const smb_ucs2_t *src);
+smb_ucs2_t *safe_strcpy_w(smb_ucs2_t *dest,const smb_ucs2_t *src, size_t maxlength);
+smb_ucs2_t *safe_strcat_w(smb_ucs2_t *dest, const smb_ucs2_t *src, size_t maxlength);
+int strcmp_w(const smb_ucs2_t *s1, const smb_ucs2_t *s2);
+int strncmp_w(const smb_ucs2_t *s1, const smb_ucs2_t *s2, size_t len);
+smb_ucs2_t *strstr_w(const smb_ucs2_t *s1, const smb_ucs2_t *s2);
+smb_ucs2_t *strchr_w(const smb_ucs2_t *s, smb_ucs2_t c);
+smb_ucs2_t *strrchr_w(const smb_ucs2_t *s, smb_ucs2_t c);
+smb_ucs2_t *strtok_w(smb_ucs2_t *s1, const smb_ucs2_t *s2);
+smb_ucs2_t *strdup_w(const smb_ucs2_t *s);
+int isupper_w( smb_ucs2_t val);
+int islower_w( smb_ucs2_t val);
+int isdigit_w( smb_ucs2_t val);
+int isxdigit_w( smb_ucs2_t val);
+int isspace_w( smb_ucs2_t val);
+smb_ucs2_t toupper_w( smb_ucs2_t val );
+smb_ucs2_t tolower_w( smb_ucs2_t val );
+void set_first_token_w(smb_ucs2_t *ptr);
+BOOL next_token_w(smb_ucs2_t **ptr, smb_ucs2_t *buff, smb_ucs2_t *sep, size_t bufsize);
+smb_ucs2_t **toktocliplist_w(int *ctok, smb_ucs2_t *sep);
+int StrCaseCmp_w(const smb_ucs2_t *s, const smb_ucs2_t *t);
+int StrnCaseCmp_w(const smb_ucs2_t *s, const smb_ucs2_t *t, size_t n);
+BOOL strequal_w(const smb_ucs2_t *s1, const smb_ucs2_t *s2);
+BOOL strnequal_w(const smb_ucs2_t *s1,const smb_ucs2_t *s2,size_t n);
+BOOL strcsequal_w(const smb_ucs2_t *s1,const smb_ucs2_t *s2);
+void strlower_w(smb_ucs2_t *s);
+void strupper_w(smb_ucs2_t *s);
+void strnorm_w(smb_ucs2_t *s);
+BOOL strisnormal_w(smb_ucs2_t *s);
+void string_replace_w(smb_ucs2_t *s, smb_ucs2_t oldc, smb_ucs2_t newc);
+smb_ucs2_t *skip_string_w(smb_ucs2_t *buf,size_t n);
+size_t str_charnum_w(const smb_ucs2_t *s);
+BOOL trim_string_w(smb_ucs2_t *s,const smb_ucs2_t *front,const smb_ucs2_t *back);
+BOOL strhasupper_w(const smb_ucs2_t *s);
+BOOL strhaslower_w(const smb_ucs2_t *s);
+size_t count_chars_w(const smb_ucs2_t *s,smb_ucs2_t c);
+BOOL str_is_all_w(const smb_ucs2_t *s,smb_ucs2_t c);
+smb_ucs2_t *alpha_strcpy_w(smb_ucs2_t *dest, const smb_ucs2_t *src, size_t maxlength);
+smb_ucs2_t *StrnCpy_w(smb_ucs2_t *dest,const smb_ucs2_t *src,size_t n);
+smb_ucs2_t *strncpyn_w(smb_ucs2_t *dest, const smb_ucs2_t *src,size_t n, smb_ucs2_t c);
+size_t strhex_to_str_w(char *p, size_t len, const smb_ucs2_t *strhex);
+BOOL in_list_w(smb_ucs2_t *s,smb_ucs2_t *list,BOOL casesensitive);
+BOOL string_init_w(smb_ucs2_t **dest,const smb_ucs2_t *src);
+void string_free_w(smb_ucs2_t **s);
+BOOL string_set_w(smb_ucs2_t **dest,const smb_ucs2_t *src);
+void string_sub_w(smb_ucs2_t *s,const smb_ucs2_t *pattern,const smb_ucs2_t *insert, size_t len);
+void fstring_sub_w(smb_ucs2_t *s,const smb_ucs2_t *pattern,const smb_ucs2_t *insert);
+void pstring_sub_w(smb_ucs2_t *s,const smb_ucs2_t *pattern,smb_ucs2_t *insert);
+void all_string_sub_w(smb_ucs2_t *s,const smb_ucs2_t *pattern,const smb_ucs2_t *insert, size_t len);
+void split_at_last_component_w(smb_ucs2_t *path, smb_ucs2_t *front, smb_ucs2_t sep, smb_ucs2_t *back);
+smb_ucs2_t *octal_string_w(int i);
+smb_ucs2_t *string_truncate_w(smb_ucs2_t *s, size_t length);
+smb_ucs2_t doscp2ucs2(int w);
+int ucs2doscp(smb_ucs2_t w);
 
-/*The following definitions come from  lib/smbrun.c  */
+/*The following definitions come from  lib/wins_srv.c  */
 
-int smbrun(char *cmd,char *outfile,BOOL shared);
+BOOL wins_srv_load_list( char *src );
+struct in_addr wins_srv_ip( void );
+void wins_srv_died( struct in_addr boothill_ip );
+unsigned long wins_srv_count( void );
 
-/*The following definitions come from  libsmb/smbdes.c  */
+/*The following definitions come from  libsmb/cli_lsarpc.c  */
 
-void E_P16(unsigned char *p14,unsigned char *p16);
-void E_P24(unsigned char *p21, unsigned char *c8, unsigned char *p24);
-void D_P16(unsigned char *p14, unsigned char *in, unsigned char *out);
-void E_old_pw_hash( unsigned char *p14, unsigned char *in, unsigned char *out);
-void cred_hash1(unsigned char *out,unsigned char *in,unsigned char *key);
-void cred_hash2(unsigned char *out,unsigned char *in,unsigned char *key);
-void cred_hash3(unsigned char *out,unsigned char *in,unsigned char *key, int forw);
-void SamOEMhash( unsigned char *data, unsigned char *key, int val);
+struct cli_state *cli_lsa_initialise(struct cli_state *cli, char *system_name,
+                                    struct ntuser_creds *creds);
+void cli_lsa_shutdown(struct cli_state *cli);
+uint32 cli_lsa_open_policy(struct cli_state *cli, BOOL sec_qos, 
+                          uint32 des_access, POLICY_HND *pol);
+uint32 cli_lsa_close(struct cli_state *cli, POLICY_HND *pol);
+uint32 cli_lsa_lookup_sids(struct cli_state *cli, POLICY_HND *pol,
+                          int num_sids, DOM_SID *sids, char ***names, 
+                          uint32 **types, int *num_names);
+uint32 cli_lsa_lookup_names(struct cli_state *cli, POLICY_HND *pol,
+                           int num_names, char **names, DOM_SID **sids,
+                           uint32 **types, int *num_sids);
+uint32 cli_lsa_query_info_policy(struct cli_state *cli, POLICY_HND *pol, 
+                                uint16 info_class, fstring domain_name, 
+                                DOM_SID * domain_sid);
+uint32 cli_lsa_enum_trust_dom(struct cli_state *cli, POLICY_HND *pol, 
+                             uint32 *enum_ctx, uint32 *num_domains,
+                             char ***domain_names, DOM_SID **domain_sids);
 
-/*The following definitions come from  libsmb/smbencrypt.c  */
+/*The following definitions come from  libsmb/cli_samr.c  */
 
-void SMBencrypt(uchar *passwd, uchar *c8, uchar *p24);
-void E_md4hash(uchar *passwd, uchar *p16);
-void nt_lm_owf_gen(char *pwd, uchar nt_p16[16], uchar p16[16]);
-void SMBOWFencrypt(uchar passwd[16], uchar *c8, uchar p24[24]);
-void NTLMSSPOWFencrypt(uchar passwd[8], uchar *ntlmchalresp, uchar p24[24]);
-void SMBNTencrypt(uchar *passwd, uchar *c8, uchar *p24);
-BOOL make_oem_passwd_hash(char data[516], const char *passwd, uchar old_pw_hash[16], BOOL unicode);
-BOOL decode_pw_buffer(char buffer[516], char *new_pwrd,
-                     int new_pwrd_size, uint32 *new_pw_len);
+struct cli_state *cli_samr_initialise(struct cli_state *cli, char *system_name,
+                                     struct ntuser_creds *creds);
+void cli_samr_shutdown(struct cli_state *cli);
+uint32 cli_samr_connect(struct cli_state *cli, char *srv_name,
+                       uint32 access_mask, POLICY_HND *connect_pol);
+uint32 cli_samr_close(struct cli_state *cli, POLICY_HND *connect_pol);
+uint32 cli_samr_open_domain(struct cli_state *cli, POLICY_HND *connect_pol,
+                           uint32 access_mask, DOM_SID *domain_sid,
+                           POLICY_HND *domain_pol);
+uint32 cli_samr_open_user(struct cli_state *cli, POLICY_HND *domain_pol,
+                         uint32 access_mask, uint32 user_rid,
+                         POLICY_HND *user_pol);
+uint32 cli_samr_open_group(struct cli_state *cli, POLICY_HND *domain_pol,
+                         uint32 access_mask, uint32 group_rid,
+                         POLICY_HND *group_pol);
+uint32 cli_samr_query_userinfo(struct cli_state *cli, POLICY_HND *user_pol, 
+                              uint16 switch_value, SAM_USERINFO_CTR *ctr);
+uint32 cli_samr_query_groupinfo(struct cli_state *cli, POLICY_HND *group_pol,
+                               uint32 info_level, GROUP_INFO_CTR *ctr);
+uint32 cli_samr_query_usergroups(struct cli_state *cli, POLICY_HND *user_pol,
+                                uint32 *num_groups, DOM_GID **gid);
+uint32 cli_samr_query_groupmem(struct cli_state *cli, POLICY_HND *group_pol,
+                              uint32 *num_mem, uint32 **rid, uint32 **attr);
 
-/*The following definitions come from  libsmb/smberr.c  */
+/*The following definitions come from  libsmb/cli_spoolss.c  */
 
-char *smb_errstr(char *inbuf);
+struct cli_state *cli_spoolss_initialise(struct cli_state *cli, 
+                                        char *system_name,
+                                        struct ntuser_creds *creds);
+void cli_spoolss_shutdown(struct cli_state *cli);
+uint32 cli_spoolss_open_printer_ex(struct cli_state *cli, char *printername,
+                                  char *datatype, uint32 access_required,
+                                  char *station, char *username,
+                                  POLICY_HND *pol);
+uint32 cli_spoolss_closeprinter(struct cli_state *cli, POLICY_HND *pol);
+uint32 cli_spoolss_enum_printers(struct cli_state *cli, uint32 flags,
+                                uint32 level, int *returned, 
+                                PRINTER_INFO_CTR *ctr);
+uint32 cli_spoolss_enum_ports(struct cli_state *cli, uint32 level, 
+                             int *returned, PORT_INFO_CTR *ctr);
+uint32 cli_spoolss_getprinter(struct cli_state *cli, POLICY_HND *pol,
+                             uint32 level, PRINTER_INFO_CTR *ctr);
 
-/*The following definitions come from  libsmb/unexpected.c  */
+/*The following definitions come from  libsmb/cliconnect.c  */
 
-void unexpected_packet(struct packet_struct *p);
-void clear_unexpected(time_t t);
-struct packet_struct *receive_unexpected(enum packet_type packet_type, int id, 
-                                        char *mailslot_name);
+BOOL cli_session_setup(struct cli_state *cli, 
+                      char *user, 
+                      char *pass, int passlen,
+                      char *ntpass, int ntpasslen,
+                      char *workgroup);
+BOOL cli_ulogoff(struct cli_state *cli);
+BOOL cli_send_tconX(struct cli_state *cli, 
+                   char *share, char *dev, char *pass, int passlen);
+BOOL cli_tdis(struct cli_state *cli);
+void cli_negprot_send(struct cli_state *cli);
+BOOL cli_negprot(struct cli_state *cli);
+BOOL cli_session_request(struct cli_state *cli,
+                        struct nmb_name *calling, struct nmb_name *called);
+BOOL cli_connect(struct cli_state *cli, const char *host, struct in_addr *ip);
+BOOL cli_reestablish_connection(struct cli_state *cli);
+BOOL cli_establish_connection(struct cli_state *cli, 
+                               char *dest_host, struct in_addr *dest_ip,
+                               struct nmb_name *calling, struct nmb_name *called,
+                               char *service, char *service_type,
+                               BOOL do_shutdown, BOOL do_tcon);
+BOOL attempt_netbios_session_request(struct cli_state *cli, char *srchost, char *desthost,
+                                     struct in_addr *pdest_ip);
 
-/*The following definitions come from  lib/snprintf.c  */
+/*The following definitions come from  libsmb/clidgram.c  */
 
+int cli_send_mailslot(int dgram_sock, BOOL unique, char *mailslot, 
+                     char *buf, int len,
+                     const char *srcname, int src_type, 
+                     const char *dstname, int dest_type,
+                     struct in_addr dest_ip, struct in_addr src_ip,
+                     int dest_port, int src_port);
+int cli_get_response(int dgram_sock, BOOL unique, char *mailslot, char *buf, int bufsiz);
+int cli_get_backup_list(const char *myname, const char *send_to_name);
+int cli_get_backup_server(char *my_name, char *target, char *servername, int namesize);
 
-/*The following definitions come from  lib/substitute.c  */
+/*The following definitions come from  libsmb/clientgen.c  */
 
-void standard_sub_basic(char *str);
-void standard_sub_advanced(int snum, char *user, char *connectpath, gid_t gid, char *str);
-void standard_sub_conn(connection_struct *conn, char *str);
-void standard_sub_snum(int snum, char *str);
-void standard_sub_vuser(char *str, user_struct *vuser);
-void standard_sub_vsnum(char *str, user_struct *vuser, int snum);
+int cli_set_port(struct cli_state *cli, int port);
+BOOL cli_receive_smb(struct cli_state *cli);
+BOOL cli_send_smb(struct cli_state *cli);
+void cli_setup_packet(struct cli_state *cli);
+void cli_setup_bcc(struct cli_state *cli, void *p);
+void cli_init_creds(struct cli_state *cli, const struct ntuser_creds *usr);
+struct cli_state *cli_initialise(struct cli_state *cli);
+void cli_shutdown(struct cli_state *cli);
+void cli_sockopt(struct cli_state *cli, char *options);
+uint16 cli_setpid(struct cli_state *cli, uint16 pid);
 
-/*The following definitions come from  lib/sysacls.c  */
+/*The following definitions come from  libsmb/clierror.c  */
 
-int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
-int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
-int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
-void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d);
-SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type);
-SMB_ACL_T sys_acl_get_fd(int fd);
-int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
-int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
-int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
-char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen);
-SMB_ACL_T sys_acl_init( int count);
-int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
-int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
-int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual);
-int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
-int sys_acl_valid( SMB_ACL_T theacl );
-int sys_acl_set_file( char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
-int sys_acl_set_fd( int fd, SMB_ACL_T theacl);
-int sys_acl_free_text(char *text);
-int sys_acl_free_acl(SMB_ACL_T the_acl) ;
-int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p);
-int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p);
-int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
-void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
-SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
-SMB_ACL_T sys_acl_get_fd(int fd);
-int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d);
-int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm);
-int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm);
-char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p);
-SMB_ACL_T sys_acl_init(int count);
-int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p);
-int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type);
-int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p);
-int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d);
-int sys_acl_valid(SMB_ACL_T acl_d);
-int sys_acl_set_file(char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d);
-int sys_acl_set_fd(int fd, SMB_ACL_T acl_d);
-int sys_acl_free_text(char *text);
-int sys_acl_free_acl(SMB_ACL_T acl_d) ;
-int sys_acl_get_entry(SMB_ACL_T acl_d, int entry_id, SMB_ACL_ENTRY_T *entry_p);
-int sys_acl_get_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *type_p);
-int sys_acl_get_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
-void *sys_acl_get_qualifier(SMB_ACL_ENTRY_T entry_d);
-SMB_ACL_T sys_acl_get_file(const char *path_p, SMB_ACL_TYPE_T type);
-SMB_ACL_T sys_acl_get_fd(int fd);
-int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset_d);
-int sys_acl_add_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm);
-int sys_acl_get_perm(SMB_ACL_PERMSET_T permset_d, SMB_ACL_PERM_T perm);
-char *sys_acl_to_text(SMB_ACL_T acl_d, ssize_t *len_p);
-SMB_ACL_T sys_acl_init(int count);
-int sys_acl_create_entry(SMB_ACL_T *acl_p, SMB_ACL_ENTRY_T *entry_p);
-int sys_acl_set_tag_type(SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T tag_type);
-int sys_acl_set_qualifier(SMB_ACL_ENTRY_T entry_d, void *qual_p);
-int sys_acl_set_permset(SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T permset_d);
-int sys_acl_valid(SMB_ACL_T acl_d);
-int sys_acl_set_file(char *name, SMB_ACL_TYPE_T type, SMB_ACL_T acl_d);
-int sys_acl_set_fd(int fd, SMB_ACL_T acl_d);
-int sys_acl_free_text(char *text);
-int sys_acl_free_acl(SMB_ACL_T acl_d) ;
-int sys_acl_get_entry( SMB_ACL_T the_acl, int entry_id, SMB_ACL_ENTRY_T *entry_p);
-int sys_acl_get_tag_type( SMB_ACL_ENTRY_T entry_d, SMB_ACL_TAG_T *tag_type_p);
-int sys_acl_get_permset( SMB_ACL_ENTRY_T entry_d, SMB_ACL_PERMSET_T *permset_p);
-void *sys_acl_get_qualifier( SMB_ACL_ENTRY_T entry_d);
-SMB_ACL_T sys_acl_get_file( const char *path_p, SMB_ACL_TYPE_T type);
-SMB_ACL_T sys_acl_get_fd(int fd);
-int sys_acl_clear_perms(SMB_ACL_PERMSET_T permset);
-int sys_acl_add_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
-int sys_acl_get_perm( SMB_ACL_PERMSET_T permset, SMB_ACL_PERM_T perm);
-char *sys_acl_to_text( SMB_ACL_T the_acl, ssize_t *plen);
-int sys_acl_free_text(char *text);
-SMB_ACL_T sys_acl_init( int count);
-int sys_acl_create_entry( SMB_ACL_T *pacl, SMB_ACL_ENTRY_T *pentry);
-int sys_acl_set_tag_type( SMB_ACL_ENTRY_T entry, SMB_ACL_TAG_T tagtype);
-int sys_acl_set_qualifier( SMB_ACL_ENTRY_T entry, void *qual);
-int sys_acl_set_permset( SMB_ACL_ENTRY_T entry, SMB_ACL_PERMSET_T permset);
-int sys_acl_valid( SMB_ACL_T theacl );
-int sys_acl_set_file( char *name, SMB_ACL_TYPE_T acltype, SMB_ACL_T theacl);
-int sys_acl_set_fd( int fd, SMB_ACL_T theacl);
-int sys_acl_free_acl(SMB_ACL_T the_acl) ;
+char *cli_errstr(struct cli_state *cli);
+int cli_error(struct cli_state *cli, uint8 *eclass, uint32 *num, uint32 *nt_rpc_error);
 
-/*The following definitions come from  lib/system.c  */
+/*The following definitions come from  libsmb/clifile.c  */
 
-int sys_usleep(long usecs);
-int sys_stat(const char *fname,SMB_STRUCT_STAT *sbuf);
-int sys_fstat(int fd,SMB_STRUCT_STAT *sbuf);
-int sys_lstat(const char *fname,SMB_STRUCT_STAT *sbuf);
-int sys_ftruncate(int fd, SMB_OFF_T offset);
-SMB_OFF_T sys_lseek(int fd, SMB_OFF_T offset, int whence);
-int sys_fseek(FILE *fp, SMB_OFF_T offset, int whence);
-SMB_OFF_T sys_ftell(FILE *fp);
-int sys_creat(const char *path, mode_t mode);
-int sys_open(const char *path, int oflag, mode_t mode);
-FILE *sys_fopen(const char *path, const char *type);
-SMB_STRUCT_DIRENT *sys_readdir(DIR *dirp);
-int sys_waitpid(pid_t pid,int *status,int options);
-char *sys_getwd(char *s);
-int sys_chown(const char *fname,uid_t uid,gid_t gid);
-int sys_chroot(const char *dname);
-struct hostent *sys_gethostbyname(const char *name);
-void oplock_set_capability(BOOL this_process, BOOL inherit);
-long sys_random(void);
-void sys_srandom(unsigned int seed);
-int groups_max(void);
-int sys_getgroups(int setlen, gid_t *gidset);
-int sys_setgroups(int setlen, gid_t *gidset);
-void sys_setpwent(void);
-struct passwd *sys_getpwent(void);
-void sys_endpwent(void);
-struct passwd *sys_getpwnam(const char *name);
-struct passwd *sys_getpwuid(uid_t uid);
-int wsys_stat(const smb_ucs2_t *wfname,SMB_STRUCT_STAT *sbuf);
-int wsys_lstat(const smb_ucs2_t *wfname,SMB_STRUCT_STAT *sbuf);
-int wsys_creat(const smb_ucs2_t *wfname, mode_t mode);
-int wsys_open(const smb_ucs2_t *wfname, int oflag, mode_t mode);
-FILE *wsys_fopen(const smb_ucs2_t *wfname, const char *type);
-DIR *wsys_opendir(const smb_ucs2_t *wfname);
-smb_ucs2_t *wsys_getwd(smb_ucs2_t *s);
-int wsys_chown(const smb_ucs2_t *wfname, uid_t uid, gid_t gid);
-int wsys_chroot(const smb_ucs2_t *wfname);
-pid_t sys_fork(void);
-pid_t sys_getpid(void);
-int sys_popen(const char *command);
-int sys_pclose(int fd);
+BOOL cli_rename(struct cli_state *cli, char *fname_src, char *fname_dst);
+BOOL cli_unlink(struct cli_state *cli, char *fname);
+BOOL cli_mkdir(struct cli_state *cli, char *dname);
+BOOL cli_rmdir(struct cli_state *cli, char *dname);
+int cli_nt_create(struct cli_state *cli, char *fname, uint32 DesiredAccess);
+int cli_open(struct cli_state *cli, char *fname, int flags, int share_mode);
+BOOL cli_close(struct cli_state *cli, int fnum);
+BOOL cli_lock(struct cli_state *cli, int fnum, 
+             uint32 offset, uint32 len, int timeout, enum brl_type lock_type);
+BOOL cli_unlock(struct cli_state *cli, int fnum, uint32 offset, uint32 len);
+BOOL cli_lock64(struct cli_state *cli, int fnum, 
+               SMB_BIG_UINT offset, SMB_BIG_UINT len, int timeout, enum brl_type lock_type);
+BOOL cli_unlock64(struct cli_state *cli, int fnum, SMB_BIG_UINT offset, SMB_BIG_UINT len);
+BOOL cli_getattrE(struct cli_state *cli, int fd, 
+                 uint16 *attr, size_t *size, 
+                 time_t *c_time, time_t *a_time, time_t *m_time);
+BOOL cli_getatr(struct cli_state *cli, char *fname, 
+               uint16 *attr, size_t *size, time_t *t);
+BOOL cli_setatr(struct cli_state *cli, char *fname, uint16 attr, time_t t);
+BOOL cli_chkpath(struct cli_state *cli, char *path);
+BOOL cli_dskattr(struct cli_state *cli, int *bsize, int *total, int *avail);
 
-/*The following definitions come from  lib/talloc.c  */
+/*The following definitions come from  libsmb/clilist.c  */
 
-TALLOC_CTX *talloc_init(void);
-void *talloc(TALLOC_CTX *t, size_t size);
-void talloc_destroy_pool(TALLOC_CTX *t);
-void talloc_destroy(TALLOC_CTX *t);
-size_t talloc_pool_size(TALLOC_CTX *t);
-void *talloc_zero(TALLOC_CTX *t, size_t size);
-void *talloc_memdup(TALLOC_CTX *t, void *p, size_t size);
+int cli_list_new(struct cli_state *cli,const char *Mask,uint16 attribute, 
+                void (*fn)(file_info *, const char *, void *), void *state);
+int cli_list_old(struct cli_state *cli,const char *Mask,uint16 attribute, 
+                void (*fn)(file_info *, const char *, void *), void *state);
+int cli_list(struct cli_state *cli,const char *Mask,uint16 attribute, 
+            void (*fn)(file_info *, const char *, void *), void *state);
 
-/*The following definitions come from  lib/time.c  */
+/*The following definitions come from  libsmb/climessage.c  */
 
-void GetTimeOfDay(struct timeval *tval);
-void TimeInit(void);
-int TimeDiff(time_t t);
-struct tm *LocalTime(time_t *t);
-time_t nt_time_to_unix(NTTIME *nt);
-time_t interpret_long_date(char *p);
-void unix_to_nt_time(NTTIME *nt, time_t t);
-void put_long_date(char *p,time_t t);
-BOOL null_mtime(time_t mtime);
-void put_dos_date(char *buf,int offset,time_t unixdate);
-void put_dos_date2(char *buf,int offset,time_t unixdate);
-void put_dos_date3(char *buf,int offset,time_t unixdate);
-time_t make_unix_date(void *date_ptr);
-time_t make_unix_date2(void *date_ptr);
-time_t make_unix_date3(void *date_ptr);
-char *http_timestring(time_t t);
-char *timestring(BOOL hires);
-time_t get_create_time(SMB_STRUCT_STAT *st,BOOL fake_dirs);
+BOOL cli_message_start(struct cli_state *cli, char *host, char *username, 
+                             int *grp);
+BOOL cli_message_text(struct cli_state *cli, char *msg, int len, int grp);
+BOOL cli_message_end(struct cli_state *cli, int grp);
 
-/*The following definitions come from  lib/ufc.c  */
+/*The following definitions come from  libsmb/cliprint.c  */
 
-char *ufc_crypt(char *key,char *salt);
+int cli_print_queue(struct cli_state *cli, 
+                   void (*fn)(struct print_job_info *));
+int cli_printjob_del(struct cli_state *cli, int job);
 
-/*The following definitions come from  lib/username.c  */
+/*The following definitions come from  libsmb/clirap.c  */
 
-char *get_user_home_dir(char *user);
-BOOL map_username(char *user);
-struct passwd *Get_Pwnam(char *user,BOOL allow_change);
-BOOL user_in_group_list(char *user,char *gname);
-BOOL user_in_list(char *user,char *list);
-struct passwd *smb_getpwnam(char *user, BOOL allow_change);
+BOOL cli_api_pipe(struct cli_state *cli, char *pipe_name, 
+                  uint16 *setup, uint32 setup_count, uint32 max_setup_count,
+                  char *params, uint32 param_count, uint32 max_param_count,
+                  char *data, uint32 data_count, uint32 max_data_count,
+                  char **rparam, uint32 *rparam_count,
+                  char **rdata, uint32 *rdata_count);
+BOOL cli_api(struct cli_state *cli,
+            char *param, int prcnt, int mprcnt,
+            char *data, int drcnt, int mdrcnt,
+            char **rparam, int *rprcnt,
+            char **rdata, int *rdrcnt);
+BOOL cli_NetWkstaUserLogon(struct cli_state *cli,char *user, char *workstation);
+int cli_RNetShareEnum(struct cli_state *cli, void (*fn)(const char *, uint32, const char *, void *), void *state);
+BOOL cli_NetServerEnum(struct cli_state *cli, char *workgroup, uint32 stype,
+                      void (*fn)(const char *, uint32, const char *, void *),
+                      void *state);
+BOOL cli_oem_change_password(struct cli_state *cli, const char *user, const char *new_password,
+                             const char *old_password);
+BOOL cli_qpathinfo(struct cli_state *cli, const char *fname, 
+                  time_t *c_time, time_t *a_time, time_t *m_time, 
+                  size_t *size, uint16 *mode);
+BOOL cli_qpathinfo2(struct cli_state *cli, const char *fname, 
+                   time_t *c_time, time_t *a_time, time_t *m_time, 
+                   time_t *w_time, size_t *size, uint16 *mode,
+                   SMB_INO_T *ino);
+BOOL cli_qfileinfo(struct cli_state *cli, int fnum, 
+                  uint16 *mode, size_t *size,
+                  time_t *c_time, time_t *a_time, time_t *m_time, 
+                  time_t *w_time, SMB_INO_T *ino);
 
-/*The following definitions come from  lib/util_array.c  */
+/*The following definitions come from  libsmb/clireadwrite.c  */
 
-void free_void_array(uint32 num_entries, void **entries,
-               void(free_item)(void*));
-void* add_copy_to_array(uint32 *len, void ***array, const void *item,
-       void*(item_dup)(const void*), BOOL alloc_anyway);
-void* add_item_to_array(uint32 *len, void ***array, void *item);
-void free_use_info_array(uint32 num_entries, struct use_info **entries);
-struct use_info* add_use_info_to_array(uint32 *len, struct use_info ***array,
-                               const struct use_info *name);
-void free_char_array(uint32 num_entries, char **entries);
-char* add_chars_to_array(uint32 *len, char ***array, const char *name);
-void free_uint32_array(uint32 num_entries, uint32 **entries);
-uint32* add_uint32s_to_array(uint32 *len, uint32 ***array, const uint32 *name);
-void free_sid_array(uint32 num_entries, DOM_SID **entries);
-DOM_SID* add_sid_to_array(uint32 *len, DOM_SID ***array, const DOM_SID *sid);
+size_t cli_read(struct cli_state *cli, int fnum, char *buf, off_t offset, size_t size);
+ssize_t cli_write(struct cli_state *cli,
+                 int fnum, uint16 write_mode,
+                 char *buf, off_t offset, size_t size);
+ssize_t cli_smbwrite(struct cli_state *cli,
+                    int fnum, char *buf, off_t offset, size_t size1);
 
-/*The following definitions come from  lib/util.c  */
+/*The following definitions come from  libsmb/clisecdesc.c  */
 
-char *tmpdir(void);
-BOOL in_group(gid_t group, gid_t current_gid, int ngroups, gid_t *groups);
-char *Atoic(char *p, int *n, char *c);
-char *get_numlist(char *p, uint32 **num, int *count);
-BOOL file_exist(char *fname,SMB_STRUCT_STAT *sbuf);
-int file_rename(char *from, char *to);
-time_t file_modtime(char *fname);
-BOOL directory_exist(char *dname,SMB_STRUCT_STAT *st);
-SMB_OFF_T get_file_size(char *file_name);
-char *attrib_string(uint16 mode);
-void show_msg(char *buf);
-void smb_setlen(char *buf,int len);
-int set_message(char *buf,int num_words,int num_bytes,BOOL zero);
-void set_message_bcc(char *buf,int num_bytes);
-void set_message_end(void *outbuf,void *end_ptr);
-void dos_clean_name(char *s);
-void unix_clean_name(char *s);
-void make_dir_struct(char *buf,char *mask,char *fname,SMB_OFF_T size,int mode,time_t date);
-void close_low_fds(void);
-int set_blocking(int fd, BOOL set);
-SMB_OFF_T transfer_file(int infd,int outfd,SMB_OFF_T n,char *header,int headlen,int align);
-void msleep(int t);
-void become_daemon(void);
-BOOL yesno(char *p);
-void *Realloc(void *p,size_t size);
-void safe_free(void *p);
-BOOL get_myname(char *my_name);
-int interpret_protocol(char *str,int def);
-BOOL is_ipaddress(const char *str);
-uint32 interpret_addr(char *str);
-struct in_addr *interpret_addr2(char *str);
-BOOL zero_ip(struct in_addr ip);
-BOOL same_net(struct in_addr ip1,struct in_addr ip2,struct in_addr mask);
-struct hostent *Get_Hostbyname(const char *name);
-BOOL process_exists(pid_t pid);
-char *uidtoname(uid_t uid);
-char *gidtoname(gid_t gid);
-uid_t nametouid(char *name);
-gid_t nametogid(char *name);
-void smb_panic(char *why);
-char *readdirname(DIR *p);
-BOOL is_in_path(char *name, name_compare_entry *namelist);
-void set_namearray(name_compare_entry **ppname_array, char *namelist);
-void free_namearray(name_compare_entry *name_array);
-BOOL fcntl_lock(int fd, int op, SMB_OFF_T offset, SMB_OFF_T count, int type);
-BOOL is_myname(char *s);
-void set_remote_arch(enum remote_arch_types type);
-enum remote_arch_types get_remote_arch(void);
-void out_ascii(FILE *f, unsigned char *buf,int len);
-void out_data(FILE *f,char *buf1,int len, int per_line);
-void print_asc(int level, unsigned char *buf,int len);
-void dump_data(int level,char *buf1,int len);
-char *tab_depth(int depth);
-int str_checksum(const char *s);
-void zero_free(void *p, size_t size);
-int set_maxfiles(int requested_max);
-BOOL reg_split_key(char *full_keyname, uint32 *reg_type, char *key_name);
-char *smbd_mktemp(char *template);
-void *memdup(void *p, size_t size);
-char *myhostname(void);
-char *lock_path(char *name);
-char *parent_dirname(const char *path);
-BOOL ms_has_wild(char *s);
-BOOL mask_match(char *string, char *pattern, BOOL is_case_sensitive);
-int _Insure_trap_error(int a1, int a2, int a3, int a4, int a5, int a6);
+SEC_DESC *cli_query_secdesc(struct cli_state *cli,int fd);
+BOOL cli_set_secdesc(struct cli_state *cli,int fd, SEC_DESC *sd);
 
-/*The following definitions come from  lib/util_file.c  */
+/*The following definitions come from  libsmb/clistr.c  */
 
-BOOL do_file_lock(int fd, int waitsecs, int type);
-BOOL file_lock(int fd, int type, int secs, int *plock_depth);
-BOOL file_unlock(int fd, int *plock_depth);
-void *startfilepwent(char *pfile, char *s_readbuf, int bufsize,
-                               int *file_lock_depth, BOOL update);
-void endfilepwent(void *vp, int *file_lock_depth);
-SMB_BIG_UINT getfilepwpos(void *vp);
-BOOL setfilepwpos(void *vp, SMB_BIG_UINT tok);
-int getfileline(void *vp, char *linebuf, int linebuf_size);
-char *fgets_slash(char *s2,int maxlen,FILE *f);
-char *file_pload(char *syscmd, size_t *size);
-char *file_load(char *fname, size_t *size);
-char **file_lines_load(char *fname, int *numlines, BOOL convert);
-char **file_lines_pload(char *syscmd, int *numlines, BOOL convert);
-void file_lines_free(char **lines);
-void file_lines_slashcont(char **lines);
+int clistr_push(struct cli_state *cli, void *dest, const char *src, int dest_len, int flags);
+int clistr_push_size(struct cli_state *cli, const void *dest, const char *src, int dest_len, int flags);
+int clistr_pull(struct cli_state *cli, char *dest, const void *src, int dest_len, int src_len, int flags);
+int clistr_pull_size(struct cli_state *cli, const void *src, int src_len);
+int clistr_align(struct cli_state *cli, int offset);
 
-/*The following definitions come from  lib/util_list.c  */
+/*The following definitions come from  libsmb/clitrans.c  */
 
-BOOL copy_policy_hnd (POLICY_HND *dest, const POLICY_HND *src);
-BOOL compare_rpc_hnd_node(const RPC_HND_NODE *x, 
-                         const RPC_HND_NODE *y);
-BOOL RpcHndList_set_connection(const POLICY_HND *hnd, 
-                              struct cli_connection *con);
-BOOL RpcHndList_del_connection(const POLICY_HND *hnd);
-struct cli_connection* RpcHndList_get_connection(const POLICY_HND *hnd);
+BOOL cli_send_trans(struct cli_state *cli, int trans, 
+                   char *pipe_name, 
+                   int fid, int flags,
+                   uint16 *setup, int lsetup, int msetup,
+                   char *param, int lparam, int mparam,
+                   char *data, int ldata, int mdata);
+BOOL cli_receive_trans(struct cli_state *cli,int trans,
+                              char **param, int *param_len,
+                              char **data, int *data_len);
+BOOL cli_send_nt_trans(struct cli_state *cli, 
+                      int function, 
+                      int flags,
+                      uint16 *setup, int lsetup, int msetup,
+                      char *param, int lparam, int mparam,
+                      char *data, int ldata, int mdata);
+BOOL cli_receive_nt_trans(struct cli_state *cli,
+                         char **param, int *param_len,
+                         char **data, int *data_len);
+
+/*The following definitions come from  libsmb/credentials.c  */
+
+char *credstr(uchar *cred);
+void cred_session_key(DOM_CHAL *clnt_chal, DOM_CHAL *srv_chal, char *pass, 
+                     uchar session_key[8]);
+void cred_create(uchar session_key[8], DOM_CHAL *stor_cred, UTIME timestamp, 
+                DOM_CHAL *cred);
+int cred_assert(DOM_CHAL *cred, uchar session_key[8], DOM_CHAL *stored_cred,
+               UTIME timestamp);
+BOOL clnt_deal_with_creds(uchar sess_key[8],
+                         DOM_CRED *sto_clnt_cred, DOM_CRED *rcv_srv_cred);
+BOOL deal_with_creds(uchar sess_key[8],
+                    DOM_CRED *sto_clnt_cred, 
+                    DOM_CRED *rcv_clnt_cred, DOM_CRED *rtn_srv_cred);
+
+/*The following definitions come from  libsmb/namequery.c  */
 
-/*The following definitions come from  lib/util_seaccess.c  */
+struct node_status *name_status_query(int fd,struct nmb_name *name,
+                                     struct in_addr to_ip, int *num_names);
+BOOL name_status_find(int type, struct in_addr to_ip, char *name);
+BOOL name_register(int fd, const char *name, int name_type,
+                  struct in_addr name_ip, int opcode,
+                  BOOL bcast, 
+                  struct in_addr to_ip, int *count);
+struct in_addr *name_query(int fd,const char *name,int name_type, 
+                          BOOL bcast,BOOL recurse,
+                          struct in_addr to_ip, int *count);
+FILE *startlmhosts(char *fname);
+BOOL getlmhostsent( FILE *fp, pstring name, int *name_type, struct in_addr *ipaddr);
+void endlmhosts(FILE *fp);
+BOOL name_register_wins(const char *name, int name_type);
+BOOL name_resolve_bcast(const char *name, int name_type,
+                       struct in_addr **return_ip_list, int *return_count);
+BOOL resolve_name(const char *name, struct in_addr *return_ip, int name_type);
+BOOL resolve_srv_name(const char* srv_name, fstring dest_host,
+                                struct in_addr *ip);
+BOOL find_master_ip(char *group, struct in_addr *master_ip);
+BOOL lookup_pdc_name(const char *srcname, const char *domain, struct in_addr *pdc_ip, char *ret_name);
+BOOL get_dc_list(BOOL pdc_only, char *group, struct in_addr **ip_list, int *count);
 
-void se_map_generic(uint32 *access_mask, struct generic_mapping *mapping);
-BOOL se_access_check(SEC_DESC *sd, struct current_user *user,
-                    uint32 acc_desired, uint32 *acc_granted, uint32 *status);
-SEC_DESC_BUF *se_create_child_secdesc(TALLOC_CTX *ctx, SEC_DESC *parent_ctr, 
-                                     BOOL child_container);
+/*The following definitions come from  libsmb/nmblib.c  */
 
-/*The following definitions come from  lib/util_sec.c  */
+void debug_nmb_packet(struct packet_struct *p);
+char *nmb_namestr(struct nmb_name *n);
+struct packet_struct *copy_packet(struct packet_struct *packet);
+void free_packet(struct packet_struct *packet);
+struct packet_struct *parse_packet(char *buf,int length,
+                                  enum packet_type packet_type);
+struct packet_struct *read_packet(int fd,enum packet_type packet_type);
+void make_nmb_name( struct nmb_name *n, const char *name, int type);
+BOOL nmb_name_equal(struct nmb_name *n1, struct nmb_name *n2);
+int build_packet(char *buf, struct packet_struct *p);
+BOOL send_packet(struct packet_struct *p);
+struct packet_struct *receive_packet(int fd,enum packet_type type,int t);
+struct packet_struct *receive_nmb_packet(int fd, int t, int trn_id);
+struct packet_struct *receive_dgram_packet(int fd, int t, char *mailslot_name);
+BOOL match_mailslot_name(struct packet_struct *p, char *mailslot_name);
+void sort_query_replies(char *data, int n, struct in_addr ip);
+char *dns_to_netbios_name(char *dns_name);
+int name_mangle( char *In, char *Out, char name_type );
+int name_extract(char *buf,int ofs,char *name);
+int name_len(char *s1);
 
-void gain_root_privilege(void);
-void gain_root_group_privilege(void);
-void set_effective_uid(uid_t uid);
-void set_effective_gid(gid_t gid);
-void save_re_uid(void);
-void restore_re_uid(void);
-int set_re_uid(void);
-void become_user_permanently(uid_t uid, gid_t gid);
+/*The following definitions come from  libsmb/nterr.c  */
 
-/*The following definitions come from  lib/util_sid.c  */
+BOOL get_safe_nt_error_msg(uint32 nt_code,char *msg, size_t len);
+char *get_nt_error_msg(uint32 nt_code);
 
-void generate_wellknown_sids(void);
-BOOL map_domain_sid_to_name(DOM_SID *sid, char *nt_domain);
-BOOL lookup_known_rid(DOM_SID *sid, uint32 rid, char *name, enum SID_NAME_USE *psid_name_use);
-BOOL map_domain_name_to_sid(DOM_SID *sid, char *nt_domain);
-void split_domain_name(const char *fullname, char *domain, char *name);
-char *sid_to_string(fstring sidstr_out, DOM_SID *sid);
-BOOL string_to_sid(DOM_SID *sidout, char *sidstr);
-BOOL sid_append_rid(DOM_SID *sid, uint32 rid);
-BOOL sid_split_rid(DOM_SID *sid, uint32 *rid);
-void sid_copy(DOM_SID *dst, const DOM_SID *src);
-DOM_SID *sid_dup(DOM_SID *src);
-BOOL sid_linearize(char *outbuf, size_t len, DOM_SID *sid);
-int sid_compare(const DOM_SID *sid1, const DOM_SID *sid2);
-BOOL sid_equal(const DOM_SID *sid1, const DOM_SID *sid2);
-size_t sid_size(DOM_SID *sid);
+/*The following definitions come from  libsmb/passchange.c  */
 
-/*The following definitions come from  lib/util_sock.c  */
+BOOL remote_password_change(const char *remote_machine, const char *user_name, 
+                           const char *old_passwd, const char *new_passwd,
+                           char *err_str, size_t err_str_len);
 
-BOOL is_a_socket(int fd);
-void set_socket_options(int fd, char *options);
-ssize_t read_udp_socket(int fd,char *buf,size_t len);
-ssize_t read_with_timeout(int fd,char *buf,size_t mincnt,size_t maxcnt,unsigned int time_out);
-BOOL send_keepalive(int client);
-ssize_t read_data(int fd,char *buffer,size_t N);
-ssize_t write_data(int fd,char *buffer,size_t N);
-ssize_t write_socket_data(int fd,char *buffer,size_t N);
-ssize_t write_socket(int fd,char *buf,size_t len);
-ssize_t read_smb_length(int fd,char *inbuf,unsigned int timeout);
-BOOL receive_smb(int fd,char *buffer, unsigned int timeout);
-BOOL client_receive_smb(int fd,char *buffer, unsigned int timeout);
-BOOL send_null_session_msg(int fd);
-BOOL send_smb(int fd,char *buffer);
-BOOL send_one_packet(char *buf,int len,struct in_addr ip,int port,int type);
-int open_socket_in(int type, int port, int dlevel,uint32 socket_addr, BOOL rebind);
-int open_socket_out(int type, struct in_addr *addr, int port ,int timeout);
-void reset_globals_after_fork(void);
-void client_setfd(int fd);
-char *client_name(void);
-char *client_addr(void);
-char *get_socket_name(int fd);
-char *get_socket_addr(int fd);
-int open_pipe_sock(char *path);
-int create_pipe_socket(char *dir, int dir_perms,
-                               char *path, int path_perms);
+/*The following definitions come from  libsmb/pwd_cache.c  */
 
-/*The following definitions come from  lib/util_str.c  */
+void pwd_init(struct pwd_info *pwd);
+BOOL pwd_is_nullpwd(const struct pwd_info *pwd);
+BOOL pwd_compare(struct pwd_info *pwd1, struct pwd_info *pwd2);
+void pwd_read(struct pwd_info *pwd, char *passwd_report, BOOL do_encrypt);
+void pwd_set_nullpwd(struct pwd_info *pwd);
+void pwd_set_cleartext(struct pwd_info *pwd, char *clr);
+void pwd_get_cleartext(struct pwd_info *pwd, char *clr);
+void pwd_set_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16]);
+void pwd_get_lm_nt_16(struct pwd_info *pwd, uchar lm_pwd[16], uchar nt_pwd[16]);
+void pwd_make_lm_nt_16(struct pwd_info *pwd, char *clr);
+void pwd_make_lm_nt_owf(struct pwd_info *pwd, uchar cryptkey[8]);
+void pwd_get_lm_nt_owf(struct pwd_info *pwd, uchar lm_owf[24], uchar nt_owf[24]);
 
-void set_first_token(char *ptr);
-BOOL next_token(char **ptr,char *buff,char *sep, size_t bufsize);
-char **toktocliplist(int *ctok, char *sep);
-int StrCaseCmp(const char *s, const char *t);
-int StrnCaseCmp(const char *s, const char *t, size_t n);
-BOOL strequal(const char *s1, const char *s2);
-BOOL strnequal(const char *s1,const char *s2,size_t n);
-BOOL strcsequal(const char *s1,const char *s2);
-int strwicmp(char *psz1, char *psz2);
-void strlower(char *s);
-void strupper(char *s);
-void strnorm(char *s);
-BOOL strisnormal(char *s);
-void string_replace(char *s,char oldc,char newc);
-char *skip_string(char *buf,size_t n);
-size_t str_charnum(const char *s);
-BOOL trim_string(char *s,const char *front,const char *back);
-BOOL strhasupper(const char *s);
-BOOL strhaslower(const char *s);
-size_t count_chars(const char *s,char c);
-BOOL str_is_all(const char *s,char c);
-char *safe_strcpy(char *dest,const char *src, size_t maxlength);
-char *safe_strcat(char *dest, const char *src, size_t maxlength);
-char *alpha_strcpy(char *dest, const char *src, size_t maxlength);
-char *StrnCpy(char *dest,const char *src,size_t n);
-char *strncpyn(char *dest, const char *src,size_t n, char c);
-size_t strhex_to_str(char *p, size_t len, const char *strhex);
-BOOL in_list(char *s,char *list,BOOL casesensitive);
-void string_free(char **s);
-BOOL string_set(char **dest,const char *src);
-void string_sub(char *s,const char *pattern,const char *insert, size_t len);
-void fstring_sub(char *s,const char *pattern,const char *insert);
-void pstring_sub(char *s,const char *pattern,const char *insert);
-void all_string_sub(char *s,const char *pattern,const char *insert, size_t len);
-void split_at_last_component(char *path, char *front, char sep, char *back);
-char *octal_string(int i);
-char *string_truncate(char *s, int length);
-void parse_domain_user(char *domuser, fstring domain, fstring user);
+/*The following definitions come from  libsmb/smbdes.c  */
 
-/*The following definitions come from  lib/util_unistr.c  */
+void E_P16(unsigned char *p14,unsigned char *p16);
+void E_P24(unsigned char *p21, unsigned char *c8, unsigned char *p24);
+void D_P16(unsigned char *p14, unsigned char *in, unsigned char *out);
+void E_old_pw_hash( unsigned char *p14, unsigned char *in, unsigned char *out);
+void cred_hash1(unsigned char *out,unsigned char *in,unsigned char *key);
+void cred_hash2(unsigned char *out,unsigned char *in,unsigned char *key);
+void cred_hash3(unsigned char *out,unsigned char *in,unsigned char *key, int forw);
+void SamOEMhash( unsigned char *data, unsigned char *key, int val);
 
-size_t dos_PutUniCode(char *dst,const char *src, ssize_t len, BOOL null_terminate);
-void unistr_to_dos(char *dest, const char *src, size_t len);
-char *skip_unibuf(char *src, size_t len);
-char *dos_unistrn2(uint16 *src, int len);
-char *dos_unistr2(uint16 *src);
-char *dos_unistr2_to_str(UNISTR2 *str);
-void ascii_to_unistr(uint16 *dest, const char *src, int maxlen);
-void unistr_to_ascii(char *dest, const uint16 *src, int len);
-void unistr2_to_ascii(char *dest, const UNISTR2 *str, size_t maxlen);
-uint32 buffer2_to_uint32(BUFFER2 *str);
-char *dos_buffer2_to_str(BUFFER2 *str);
-char *dos_buffer2_to_multistr(BUFFER2 *str);
-size_t dos_struni2(char *dst, const char *src, size_t max_len);
-char *dos_unistr(char *buf);
-int unistrcpy(char *dst, char *src);
-void default_unicode_map(smb_ucs2_t **pp_cp_to_ucs2, uint16 **pp_ucs2_to_cp);
-BOOL load_unicode_map(const char *codepage, smb_ucs2_t **pp_cp_to_ucs2, uint16 **pp_ucs2_to_cp);
-BOOL load_dos_unicode_map(int codepage);
-BOOL load_unix_unicode_map(const char *unix_char_set);
-smb_ucs2_t *multibyte_to_unicode(smb_ucs2_t *dst, const char *src,
-                                 size_t dst_len, smb_ucs2_t *cp_to_ucs2);
-char *unicode_to_unix(char *dst, const smb_ucs2_t *src, size_t dst_len);
-smb_ucs2_t *unix_to_unicode(smb_ucs2_t *dst, const char *src, size_t dst_len);
-char *unicode_to_dos(char *dst, const smb_ucs2_t *src, size_t dst_len);
-size_t unicode_to_dos_char(char *dst, const smb_ucs2_t src);
-smb_ucs2_t *dos_to_unicode(smb_ucs2_t *dst, const char *src, size_t dst_len);
-size_t strlen_w(const smb_ucs2_t *src);
-smb_ucs2_t *safe_strcpy_w(smb_ucs2_t *dest,const smb_ucs2_t *src, size_t maxlength);
-smb_ucs2_t *safe_strcat_w(smb_ucs2_t *dest, const smb_ucs2_t *src, size_t maxlength);
-int strcmp_w(const smb_ucs2_t *s1, const smb_ucs2_t *s2);
-int strncmp_w(const smb_ucs2_t *s1, const smb_ucs2_t *s2, size_t len);
-smb_ucs2_t *strstr_w(const smb_ucs2_t *s1, const smb_ucs2_t *s2);
-smb_ucs2_t *strchr_w(const smb_ucs2_t *s, smb_ucs2_t c);
-smb_ucs2_t *strrchr_w(const smb_ucs2_t *s, smb_ucs2_t c);
-smb_ucs2_t *strtok_w(smb_ucs2_t *s1, const smb_ucs2_t *s2);
-smb_ucs2_t *strdup_w(const smb_ucs2_t *s);
-int isupper_w( smb_ucs2_t val);
-int islower_w( smb_ucs2_t val);
-int isdigit_w( smb_ucs2_t val);
-int isxdigit_w( smb_ucs2_t val);
-int isspace_w( smb_ucs2_t val);
-smb_ucs2_t toupper_w( smb_ucs2_t val );
-smb_ucs2_t tolower_w( smb_ucs2_t val );
-void set_first_token_w(smb_ucs2_t *ptr);
-BOOL next_token_w(smb_ucs2_t **ptr, smb_ucs2_t *buff, smb_ucs2_t *sep, size_t bufsize);
-smb_ucs2_t **toktocliplist_w(int *ctok, smb_ucs2_t *sep);
-int StrCaseCmp_w(const smb_ucs2_t *s, const smb_ucs2_t *t);
-int StrnCaseCmp_w(const smb_ucs2_t *s, const smb_ucs2_t *t, size_t n);
-BOOL strequal_w(const smb_ucs2_t *s1, const smb_ucs2_t *s2);
-BOOL strnequal_w(const smb_ucs2_t *s1,const smb_ucs2_t *s2,size_t n);
-BOOL strcsequal_w(const smb_ucs2_t *s1,const smb_ucs2_t *s2);
-void strlower_w(smb_ucs2_t *s);
-void strupper_w(smb_ucs2_t *s);
-void strnorm_w(smb_ucs2_t *s);
-BOOL strisnormal_w(smb_ucs2_t *s);
-void string_replace_w(smb_ucs2_t *s, smb_ucs2_t oldc, smb_ucs2_t newc);
-smb_ucs2_t *skip_string_w(smb_ucs2_t *buf,size_t n);
-size_t str_charnum_w(const smb_ucs2_t *s);
-BOOL trim_string_w(smb_ucs2_t *s,const smb_ucs2_t *front,const smb_ucs2_t *back);
-BOOL strhasupper_w(const smb_ucs2_t *s);
-BOOL strhaslower_w(const smb_ucs2_t *s);
-size_t count_chars_w(const smb_ucs2_t *s,smb_ucs2_t c);
-BOOL str_is_all_w(const smb_ucs2_t *s,smb_ucs2_t c);
-smb_ucs2_t *alpha_strcpy_w(smb_ucs2_t *dest, const smb_ucs2_t *src, size_t maxlength);
-smb_ucs2_t *StrnCpy_w(smb_ucs2_t *dest,const smb_ucs2_t *src,size_t n);
-smb_ucs2_t *strncpyn_w(smb_ucs2_t *dest, const smb_ucs2_t *src,size_t n, smb_ucs2_t c);
-size_t strhex_to_str_w(char *p, size_t len, const smb_ucs2_t *strhex);
-BOOL in_list_w(smb_ucs2_t *s,smb_ucs2_t *list,BOOL casesensitive);
-BOOL string_init_w(smb_ucs2_t **dest,const smb_ucs2_t *src);
-void string_free_w(smb_ucs2_t **s);
-BOOL string_set_w(smb_ucs2_t **dest,const smb_ucs2_t *src);
-void string_sub_w(smb_ucs2_t *s,const smb_ucs2_t *pattern,const smb_ucs2_t *insert, size_t len);
-void fstring_sub_w(smb_ucs2_t *s,const smb_ucs2_t *pattern,const smb_ucs2_t *insert);
-void pstring_sub_w(smb_ucs2_t *s,const smb_ucs2_t *pattern,smb_ucs2_t *insert);
-void all_string_sub_w(smb_ucs2_t *s,const smb_ucs2_t *pattern,const smb_ucs2_t *insert, size_t len);
-void split_at_last_component_w(smb_ucs2_t *path, smb_ucs2_t *front, smb_ucs2_t sep, smb_ucs2_t *back);
-smb_ucs2_t *octal_string_w(int i);
-smb_ucs2_t *string_truncate_w(smb_ucs2_t *s, size_t length);
-smb_ucs2_t doscp2ucs2(int w);
-int ucs2doscp(smb_ucs2_t w);
+/*The following definitions come from  libsmb/smbencrypt.c  */
+
+void SMBencrypt(uchar *passwd, uchar *c8, uchar *p24);
+void E_md4hash(uchar *passwd, uchar *p16);
+void nt_lm_owf_gen(char *pwd, uchar nt_p16[16], uchar p16[16]);
+void SMBOWFencrypt(uchar passwd[16], uchar *c8, uchar p24[24]);
+void NTLMSSPOWFencrypt(uchar passwd[8], uchar *ntlmchalresp, uchar p24[24]);
+void SMBNTencrypt(uchar *passwd, uchar *c8, uchar *p24);
+BOOL make_oem_passwd_hash(char data[516], const char *passwd, uchar old_pw_hash[16], BOOL unicode);
+BOOL decode_pw_buffer(char buffer[516], char *new_pwrd,
+                     int new_pwrd_size, uint32 *new_pw_len);
 
-/*The following definitions come from  lib/wins_srv.c  */
+/*The following definitions come from  libsmb/smberr.c  */
 
-BOOL wins_srv_load_list( char *src );
-struct in_addr wins_srv_ip( void );
-void wins_srv_died( struct in_addr boothill_ip );
-unsigned long wins_srv_count( void );
+char *smb_errstr(char *inbuf);
+
+/*The following definitions come from  libsmb/unexpected.c  */
+
+void unexpected_packet(struct packet_struct *p);
+void clear_unexpected(time_t t);
+struct packet_struct *receive_unexpected(enum packet_type packet_type, int id, 
+                                        char *mailslot_name);
 
 /*The following definitions come from  locking/brlock.c  */
 
@@ -1169,6 +1166,9 @@ BOOL queue_dns_query(struct packet_struct *p,struct nmb_name *question,
                     struct name_record **n);
 void kill_async_dns_child(void);
 
+/*The following definitions come from  nmbd/nmbd.c  */
+
+
 /*The following definitions come from  nmbd/nmbd_become_dmb.c  */
 
 void add_domain_names(time_t t);
@@ -1199,9 +1199,6 @@ void announce_and_sync_with_domain_master_browser( struct subnet_record *subrec,
 void collect_all_workgroup_names_from_wins_server(time_t t);
 void sync_all_dmbs(time_t t);
 
-/*The following definitions come from  nmbd/nmbd.c  */
-
-
 /*The following definitions come from  nmbd/nmbd_elections.c  */
 
 void check_master_browser_exists(time_t t);
@@ -1963,7 +1960,6 @@ BOOL parse_lpq_entry(int snum,char *line,
 
 /*The following definitions come from  printing/nt_printing.c  */
 
-#if OLD_NTDOMAIN
 BOOL nt_printing_init(void);
 int get_ntforms(nt_forms_struct **list);
 int write_ntforms(nt_forms_struct **list, int number);
@@ -2002,7 +1998,6 @@ void map_printer_permissions(SEC_DESC *sd);
 BOOL print_access_check(struct current_user *user, int snum, int access_type);
 BOOL print_time_access_check(int snum);
 uint32 printer_write_default_dev(int snum, const PRINTER_DEFAULT *printer_default);
-#endif
 
 /*The following definitions come from  printing/pcap.c  */
 
@@ -2014,16 +2009,18 @@ void pcap_printer_fn(void (*fn)(char *, char *));
 void cups_printer_fn(void (*fn)(char *, char *));
 int cups_printername_ok(char *name);
 
+/*The following definitions come from  printing/print_svid.c  */
+
+void sysv_printer_fn(void (*fn)(char *, char *));
+int sysv_printername_ok(char *name);
+
 /*The following definitions come from  printing/printfsp.c  */
 
-#if OLD_NTDOMAIN
 files_struct *print_fsp_open(connection_struct *conn,char *jobname);
 void print_fsp_end(files_struct *fsp, BOOL normal_close);
-#endif
 
 /*The following definitions come from  printing/printing.c  */
 
-#if OLD_NTDOMAIN
 BOOL print_backend_init(void);
 BOOL print_job_exists(int jobid);
 int print_job_snum(int jobid);
@@ -2044,12 +2041,6 @@ int print_queue_snum(char *qname);
 BOOL print_queue_pause(struct current_user *user, int snum, int *errcode);
 BOOL print_queue_resume(struct current_user *user, int snum, int *errcode);
 BOOL print_queue_purge(struct current_user *user, int snum, int *errcode);
-#endif
-
-/*The following definitions come from  printing/print_svid.c  */
-
-void sysv_printer_fn(void (*fn)(char *, char *));
-int sysv_printername_ok(char *name);
 
 /*The following definitions come from  profile/profile.c  */
 
@@ -2170,7 +2161,6 @@ BOOL do_reg_close(struct cli_state *cli, POLICY_HND *hnd);
 
 /*The following definitions come from  rpc_client/cli_samr.c  */
 
-#if OLD_NTDOMAIN
 BOOL get_samr_query_usergroups(struct cli_state *cli, 
                                POLICY_HND *pol_open_domain, uint32 user_rid,
                                uint32 *num_groups, DOM_GID *gid);
@@ -2209,7 +2199,6 @@ BOOL do_samr_query_usergroups(struct cli_state *cli,
 BOOL do_samr_query_userinfo(struct cli_state *cli, 
                                POLICY_HND *pol, uint16 switch_value, void* usr);
 BOOL do_samr_close(struct cli_state *cli, POLICY_HND *hnd);
-#endif
 
 /*The following definitions come from  rpc_client/cli_spoolss_notify.c  */
 
@@ -2263,17 +2252,6 @@ BOOL do_wks_query_info(struct cli_state *cli,
                        char *server_name, uint32 switch_value,
                        WKS_INFO_100 *wks100);
 
-/*The following definitions come from  rpcclient/cmd_lsarpc.c  */
-
-
-/*The following definitions come from  rpcclient/cmd_samr.c  */
-
-#if NEW_NTDOMAIN
-#endif
-
-/*The following definitions come from  rpcclient/cmd_spoolss.c  */
-
-
 /*The following definitions come from  rpc_client/ncacn_np_use.c  */
 
 BOOL ncacn_np_use_del(const char *srv_name, const char *pipe_name,
@@ -2287,12 +2265,6 @@ struct ncacn_np *ncacn_np_use_add(const char *pipe_name,
                                   const struct ntuser_creds *ntc,
                                   BOOL reuse, BOOL *is_new_connection);
 
-/*The following definitions come from  rpcclient/rpcclient.c  */
-
-void fetch_domain_sid(void);
-void init_rpcclient_creds(struct ntuser_creds *creds);
-void add_command_set(struct cmd_set *cmd_set);
-
 /*The following definitions come from  rpc_parse/parse_creds.c  */
 
 BOOL make_creds_unix(CREDS_UNIX *r_u, const char* user_name,
@@ -2531,13 +2503,12 @@ void init_sam_info(DOM_SAM_INFO *sam,
                                char *logon_srv, char *comp_name, DOM_CRED *clnt_cred,
                                DOM_CRED *rtn_cred, uint16 logon_level,
                                NET_ID_INFO_CTR *ctr);
-void init_net_user_info3(NET_USER_INFO_3 *usr, SAM_ACCOUNT *sampw,
+void init_net_user_info3(TALLOC_CTX *ctx, NET_USER_INFO_3 *usr, SAM_ACCOUNT *sampw,
                         uint16 logon_count, uint16 bad_pw_count,
                         uint32 num_groups, DOM_GID *gids,
                         uint32 user_flgs, char *sess_key,
                         char *logon_srv, char *logon_dom,
                         DOM_SID *dom_sid, char *other_sids);
-void free_user_info3(NET_USER_INFO_3 *usr);
 BOOL net_io_q_sam_logon(char *desc, NET_Q_SAM_LOGON *q_l, prs_struct *ps, int depth);
 BOOL net_io_r_sam_logon(char *desc, NET_R_SAM_LOGON *r_l, prs_struct *ps, int depth);
 BOOL net_io_q_sam_logoff(char *desc,  NET_Q_SAM_LOGOFF *q_l, prs_struct *ps, int depth);
@@ -2716,273 +2687,459 @@ BOOL smb_io_rpc_auth_ntlmssp_chk(char *desc, RPC_AUTH_NTLMSSP_CHK *chk, prs_stru
 
 /*The following definitions come from  rpc_parse/parse_samr.c  */
 
-#if OLD_NTDOMAIN
-void init_samr_q_close_hnd(SAMR_Q_CLOSE_HND *q_c, POLICY_HND *hnd);
-BOOL samr_io_q_close_hnd(char *desc,  SAMR_Q_CLOSE_HND *q_u, prs_struct *ps, int depth);
-BOOL samr_io_r_close_hnd(char *desc,  SAMR_R_CLOSE_HND *r_u, prs_struct *ps, int depth);
-void init_samr_q_open_domain(SAMR_Q_OPEN_DOMAIN *q_u, 
-                            POLICY_HND *connect_pol, 
-                            uint32 access_mask, DOM_SID *sid);
-BOOL samr_io_q_open_domain(char *desc, SAMR_Q_OPEN_DOMAIN *q_u, prs_struct *ps, int depth);
-BOOL samr_io_r_open_domain(char *desc, SAMR_R_OPEN_DOMAIN *r_u, prs_struct *ps, int depth);
-void init_samr_q_unknown_2c(SAMR_Q_UNKNOWN_2C *q_u, POLICY_HND *user_pol);
-BOOL samr_io_q_unknown_2c(char *desc,  SAMR_Q_UNKNOWN_2C *q_u, prs_struct *ps, int depth);
-void init_samr_r_unknown_2c(SAMR_R_UNKNOWN_2C *q_u, uint32 status);
-BOOL samr_io_r_unknown_2c(char *desc,  SAMR_R_UNKNOWN_2C *r_u, prs_struct *ps, int depth);
-void init_samr_q_unknown_3(SAMR_Q_UNKNOWN_3 *q_u,
-                               POLICY_HND *user_pol, uint16 switch_value);
-BOOL samr_io_q_unknown_3(char *desc,  SAMR_Q_UNKNOWN_3 *q_u, prs_struct *ps, int depth);
-void init_samr_q_query_dom_info(SAMR_Q_QUERY_DOMAIN_INFO *q_u,
-                               POLICY_HND *domain_pol, uint16 switch_value);
-BOOL samr_io_q_query_dom_info(char *desc,  SAMR_Q_QUERY_DOMAIN_INFO *q_u, prs_struct *ps, int depth);
-BOOL init_unk_info1(SAM_UNK_INFO_1 *u_1);
-void init_unk_info2(SAM_UNK_INFO_2 *u_2, char *domain, char *server);
-BOOL sam_io_unk_info2(char *desc, SAM_UNK_INFO_2 *u_2, prs_struct *ps, int depth);
-BOOL init_unk_info3(SAM_UNK_INFO_3 * u_3);
-BOOL init_unk_info6(SAM_UNK_INFO_6 * u_6);
-BOOL init_unk_info7(SAM_UNK_INFO_7 *u_7);
-BOOL init_unk_info12(SAM_UNK_INFO_12 * u_12);
-void init_samr_r_query_dom_info(SAMR_R_QUERY_DOMAIN_INFO *r_u, 
-                               uint16 switch_value, SAM_UNK_CTR *ctr,
-                               uint32 status);
-BOOL samr_io_r_query_dom_info(char *desc, SAMR_R_QUERY_DOMAIN_INFO *r_u, prs_struct *ps, int depth);
-void init_dom_sid3(DOM_SID3 *sid3, uint16 unk_0, uint16 unk_1, DOM_SID *sid);
-void init_samr_r_unknown_3(SAMR_R_UNKNOWN_3 *r_u,
-                               uint16 unknown_2, uint16 unknown_3,
-                               uint32 unknown_4, uint16 unknown_6, uint16 unknown_7,
-                               int num_sid3s, DOM_SID3 sid3[MAX_SAM_SIDS],
-                               uint32 status);
-BOOL samr_io_r_unknown_3(char *desc,  SAMR_R_UNKNOWN_3 *r_u, prs_struct *ps, int depth);
-void init_samr_q_enum_dom_users(SAMR_Q_ENUM_DOM_USERS *q_e, POLICY_HND *pol,
-                               uint16 req_num_entries, uint16 unk_0,
-                               uint16 acb_mask, uint16 unk_1, uint32 size);
-BOOL samr_io_q_enum_dom_users(char *desc,  SAMR_Q_ENUM_DOM_USERS *q_e, prs_struct *ps, int depth);
-void init_samr_r_enum_dom_users(SAMR_R_ENUM_DOM_USERS *r_u,
-               uint16 total_num_entries, uint16 unk_0,
-               uint32 num_sam_entries, SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES], uint32 status);
-BOOL samr_io_r_enum_dom_users(char *desc,  SAMR_R_ENUM_DOM_USERS *r_u, prs_struct *ps, int depth);
-void init_samr_q_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES *q_e, POLICY_HND *pol, uint32 size);
-BOOL samr_io_q_enum_dom_aliases(char *desc,  SAMR_Q_ENUM_DOM_ALIASES *q_e, prs_struct *ps, int depth);
-void init_samr_r_enum_dom_aliases(SAMR_R_ENUM_DOM_ALIASES *r_u,
-               uint32 num_sam_entries, SAM_USER_INFO_21 grps[MAX_SAM_ENTRIES],
-               uint32 status);
-BOOL samr_io_r_enum_dom_aliases(char *desc,  SAMR_R_ENUM_DOM_ALIASES *r_u, prs_struct *ps, int depth);
-void init_samr_q_query_dispinfo(SAMR_Q_QUERY_DISPINFO *q_e, POLICY_HND *pol,
-                               uint16 switch_level, uint32 start_idx, uint32 size);
-BOOL samr_io_q_query_dispinfo(char *desc,  SAMR_Q_QUERY_DISPINFO *q_e, prs_struct *ps, int depth);
-void init_sam_info_2(SAM_INFO_2 *sam, uint32 acb_mask,
-               uint32 start_idx, uint32 num_sam_entries,
-               SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES]);
-void init_sam_info_1(SAM_INFO_1 *sam, uint32 acb_mask,
-               uint32 start_idx, uint32 num_sam_entries,
-               SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES]);
-void init_samr_r_query_dispinfo(SAMR_R_QUERY_DISPINFO *r_u,
-               uint16 switch_level, SAM_INFO_CTR *ctr, uint32 status);
-BOOL samr_io_r_query_dispinfo(char *desc,  SAMR_R_QUERY_DISPINFO *r_u, prs_struct *ps, int depth);
-void init_samr_q_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS *q_e, POLICY_HND *pol,
-                               uint16 switch_level, uint32 start_idx, uint32 size);
-BOOL samr_io_q_enum_dom_groups(char *desc,  SAMR_Q_ENUM_DOM_GROUPS *q_e, prs_struct *ps, int depth);
-void init_samr_r_enum_dom_groups(SAMR_R_ENUM_DOM_GROUPS *r_u,
-               uint32 start_idx, uint32 num_sam_entries,
-               SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES],
-               uint32 status);
-BOOL samr_io_r_enum_dom_groups(char *desc,  SAMR_R_ENUM_DOM_GROUPS *r_u, prs_struct *ps, int depth);
-void init_samr_q_query_aliasinfo(SAMR_Q_QUERY_ALIASINFO *q_e,
-                               POLICY_HND *pol,
-                               uint16 switch_level);
-BOOL samr_io_q_query_aliasinfo(char *desc,  SAMR_Q_QUERY_ALIASINFO *q_e, prs_struct *ps, int depth);
-void init_samr_r_query_aliasinfo(SAMR_R_QUERY_ALIASINFO *r_u, uint32 switch_level,
-                                char* alias, char* alias_desc);
-BOOL samr_io_r_query_aliasinfo(char *desc,  SAMR_R_QUERY_ALIASINFO *r_u, prs_struct *ps, int depth);
-BOOL samr_io_q_lookup_ids(char *desc,  SAMR_Q_LOOKUP_IDS *q_u, prs_struct *ps, int depth);
-void init_samr_r_lookup_ids(SAMR_R_LOOKUP_IDS *r_u,
-               uint32 num_rids, uint32 *rid, uint32 status);
-BOOL samr_io_r_lookup_ids(char *desc,  SAMR_R_LOOKUP_IDS *r_u, prs_struct *ps, int depth);
-BOOL samr_io_q_lookup_names(char *desc,  SAMR_Q_LOOKUP_NAMES *q_u, prs_struct *ps, int depth);
-void init_samr_r_lookup_names(SAMR_R_LOOKUP_NAMES *r_u,
-                       uint32 num_rids, uint32 *rid, enum SID_NAME_USE *type, uint32 status);
-BOOL samr_io_r_lookup_names(char *desc,  SAMR_R_LOOKUP_NAMES *r_u, prs_struct *ps, int depth);
-BOOL samr_io_q_lookup_rids(char *desc, SAMR_Q_LOOKUP_RIDS *q_u, prs_struct *ps, int depth);
-void init_samr_r_lookup_rids(SAMR_R_LOOKUP_RIDS *r_u,
-               uint32 num_aliases, fstring *als_name, uint32 *num_als_usrs,
-               uint32 status);
-BOOL samr_io_r_lookup_rids(char *desc, SAMR_R_LOOKUP_RIDS *r_u, prs_struct *ps, int depth);
-void init_samr_q_open_user(SAMR_Q_OPEN_USER *q_u, POLICY_HND *pol,
-                          uint32 access_mask, uint32 rid);
-BOOL samr_io_q_open_user(char *desc, SAMR_Q_OPEN_USER *q_u, 
-                        prs_struct *ps, int depth);
-BOOL samr_io_r_open_user(char *desc,  SAMR_R_OPEN_USER *r_u, prs_struct *ps, int depth);
-void init_samr_q_query_usergroups(SAMR_Q_QUERY_USERGROUPS *q_u,
-                               POLICY_HND *hnd);
-BOOL samr_io_q_query_usergroups(char *desc,  SAMR_Q_QUERY_USERGROUPS *q_u, prs_struct *ps, int depth);
-void init_samr_r_query_usergroups(SAMR_R_QUERY_USERGROUPS *r_u,
-               uint32 num_gids, DOM_GID *gid, uint32 status);
-BOOL samr_io_r_query_usergroups(char *desc,  SAMR_R_QUERY_USERGROUPS *r_u, prs_struct *ps, int depth);
-void init_samr_q_query_userinfo(SAMR_Q_QUERY_USERINFO *q_u,
-                               POLICY_HND *hnd, uint16 switch_value);
-BOOL samr_io_q_query_userinfo(char *desc,  SAMR_Q_QUERY_USERINFO *q_u, prs_struct *ps, int depth);
-void init_sam_user_info10(SAM_USER_INFO_10 *usr,
-                               uint32 acb_info);
-BOOL sam_io_user_info10(char *desc,  SAM_USER_INFO_10 *usr, prs_struct *ps, int depth);
-void init_sam_user_info11(SAM_USER_INFO_11 *usr,
-                               NTTIME *expiry,
-                               char *mach_acct,
-                               uint32 rid_user,
-                               uint32 rid_group,
-                               uint16 acct_ctrl);
-BOOL sam_io_user_info11(char *desc,  SAM_USER_INFO_11 *usr, prs_struct *ps, int depth);
-void init_sam_user_info21(SAM_USER_INFO_21 *usr, SAM_ACCOUNT *pw);
-void init_samr_r_query_userinfo(SAMR_R_QUERY_USERINFO *r_u,
-                               uint16 switch_value, void *info, uint32 status);
-BOOL samr_io_r_query_userinfo(char *desc, SAMR_R_QUERY_USERINFO *r_u, 
-                             prs_struct *ps, int depth);
-BOOL samr_io_q_create_user(char *desc, SAMR_Q_CREATE_USER *q_u, prs_struct *ps, int depth);
-BOOL samr_io_r_create_user(char *desc, SAMR_R_CREATE_USER *r_u, prs_struct *ps, int depth);
-void init_samr_q_connect(SAMR_Q_CONNECT *q_u, char *srv_name, 
-                        uint32 access_mask);
-BOOL samr_io_q_connect(char *desc,  SAMR_Q_CONNECT *q_u, prs_struct *ps, int depth);
-BOOL samr_io_r_connect(char *desc,  SAMR_R_CONNECT *r_u, prs_struct *ps, int depth);
-void init_samr_q_connect_anon(SAMR_Q_CONNECT_ANON *q_u);
-BOOL samr_io_q_connect_anon(char *desc,  SAMR_Q_CONNECT_ANON *q_u, prs_struct *ps, int depth);
-BOOL samr_io_r_connect_anon(char *desc,  SAMR_R_CONNECT_ANON *r_u, prs_struct *ps, int depth);
-void init_samr_q_open_alias(SAMR_Q_OPEN_ALIAS *q_u,
-                               uint32 unknown_0, uint32 rid);
-BOOL samr_io_q_open_alias(char *desc, SAMR_Q_OPEN_ALIAS *q_u, prs_struct *ps, int depth);
-BOOL samr_io_r_open_alias(char *desc,  SAMR_R_OPEN_ALIAS *r_u, prs_struct *ps, int depth);
-void init_samr_q_lookup_rids(SAMR_Q_LOOKUP_RIDS *q_u,
-               POLICY_HND *pol, uint32 rid,
-               uint32 num_gids, uint32 *gid);
-void init_samr_q_unknown_21(SAMR_Q_UNKNOWN_21 *q_c,
-                               POLICY_HND *hnd, uint16 unk_1, uint16 unk_2);
-void init_samr_q_unknown_13(SAMR_Q_UNKNOWN_13 *q_c,
-                               POLICY_HND *hnd, uint16 unk_1, uint16 unk_2);
-void init_samr_q_unknown_38(SAMR_Q_UNKNOWN_38 *q_u, char *srv_name);
-BOOL samr_io_q_unknown_38(char *desc,  SAMR_Q_UNKNOWN_38 *q_u, prs_struct *ps, int depth);
-void init_samr_r_unknown_38(SAMR_R_UNKNOWN_38 *r_u);
-BOOL samr_io_r_unknown_38(char *desc,  SAMR_R_UNKNOWN_38 *r_u, prs_struct *ps, int depth);
-void init_enc_passwd(SAMR_ENC_PASSWD *pwd, char pass[512]);
-BOOL samr_io_enc_passwd(char *desc, SAMR_ENC_PASSWD *pwd, prs_struct *ps, int depth);
-void init_enc_hash(SAMR_ENC_HASH *hsh, uchar hash[16]);
-BOOL samr_io_enc_hash(char *desc, SAMR_ENC_HASH *hsh, prs_struct *ps, int depth);
-void init_samr_q_chgpasswd_user(SAMR_Q_CHGPASSWD_USER *q_u,
-                               char *dest_host, char *user_name,
-                               char nt_newpass[516], uchar nt_oldhash[16],
-                               char lm_newpass[516], uchar lm_oldhash[16]);
-BOOL samr_io_q_chgpasswd_user(char *desc, SAMR_Q_CHGPASSWD_USER *q_u, prs_struct *ps, int depth);
-void init_samr_r_chgpasswd_user(SAMR_R_CHGPASSWD_USER *r_u, uint32 status);
-BOOL samr_io_r_chgpasswd_user(char *desc, SAMR_R_CHGPASSWD_USER *r_u, prs_struct *ps, int depth);
-BOOL samr_io_q_lookup_domain(char* desc, SAMR_Q_LOOKUP_DOMAIN* q_u, prs_struct *ps, int depth);
-BOOL init_samr_r_lookup_domain(SAMR_R_LOOKUP_DOMAIN * r_u,
-                               DOM_SID *dom_sid, uint32 status);
-BOOL samr_io_r_lookup_domain(char *desc, SAMR_R_LOOKUP_DOMAIN * r_u,
-                             prs_struct *ps, int depth);
-BOOL samr_io_q_enum_domains(char *desc, SAMR_Q_ENUM_DOMAINS * q_e,
-                            prs_struct *ps, int depth);
-BOOL init_samr_r_enum_domains(SAMR_R_ENUM_DOMAINS * r_u,
-                              uint32 next_idx, fstring* domains, uint32 num_sam_entries);
-BOOL samr_io_r_enum_domains(char *desc, SAMR_R_ENUM_DOMAINS * r_u,
-                            prs_struct *ps, int depth);
-void free_samr_userinfo_ctr(SAM_USERINFO_CTR * ctr);
-BOOL samr_io_q_set_userinfo(char *desc, SAMR_Q_SET_USERINFO *q_u, prs_struct *ps, int depth);
-void free_samr_q_set_userinfo(SAMR_Q_SET_USERINFO * q_u);
-BOOL samr_io_r_set_userinfo(char *desc, SAMR_R_SET_USERINFO *r_u, prs_struct *ps, int depth);
-BOOL samr_io_q_set_userinfo2(char *desc, SAMR_Q_SET_USERINFO2 *q_u, prs_struct *ps, int depth);
-void free_samr_q_set_userinfo2(SAMR_Q_SET_USERINFO2 *q_u);
-BOOL make_samr_r_set_userinfo2(SAMR_R_SET_USERINFO2 *r_u, uint32 status);
-BOOL samr_io_r_set_userinfo2(char *desc, SAMR_R_SET_USERINFO2 *r_u, prs_struct *ps, int depth);
-#endif
-
-/*The following definitions come from  rpc_parse/parse_samr_new.c  */
-
-#if NEW_NTDOMAIN
-BOOL init_samr_q_connect(SAMR_Q_CONNECT * q_u, char *srv_name, 
-                        uint32 access_mask);
-BOOL samr_io_q_connect(char *desc, SAMR_Q_CONNECT * q_u, prs_struct *ps, 
-                      int depth);
-BOOL samr_io_r_connect(char *desc, SAMR_R_CONNECT * r_u, prs_struct *ps, 
-                      int depth);
-BOOL init_samr_q_close_hnd(SAMR_Q_CLOSE_HND * q_c, POLICY_HND *hnd);
+void init_samr_q_close_hnd(SAMR_Q_CLOSE_HND * q_c, POLICY_HND *hnd);
 BOOL samr_io_q_close_hnd(char *desc, SAMR_Q_CLOSE_HND * q_u,
                         prs_struct *ps, int depth);
 BOOL samr_io_r_close_hnd(char *desc, SAMR_R_CLOSE_HND * r_u,
                         prs_struct *ps, int depth);
-BOOL init_samr_q_open_domain(SAMR_Q_OPEN_DOMAIN * q_u, 
-                            POLICY_HND *connect_pol, uint32 access_mask,
+void init_samr_q_lookup_domain(SAMR_Q_LOOKUP_DOMAIN * q_u,
+                              POLICY_HND *pol, char *dom_name);
+BOOL samr_io_q_lookup_domain(char *desc, SAMR_Q_LOOKUP_DOMAIN * q_u,
+                            prs_struct *ps, int depth);
+void init_samr_r_lookup_domain(SAMR_R_LOOKUP_DOMAIN * r_u,
+                              DOM_SID *dom_sid, uint32 status);
+BOOL samr_io_r_lookup_domain(char *desc, SAMR_R_LOOKUP_DOMAIN * r_u,
+                            prs_struct *ps, int depth);
+void init_samr_q_unknown_2d(SAMR_Q_UNKNOWN_2D * q_u, POLICY_HND *dom_pol, DOM_SID *sid);
+BOOL samr_io_q_unknown_2d(char *desc, SAMR_Q_UNKNOWN_2D * q_u,
+                         prs_struct *ps, int depth);
+BOOL samr_io_r_unknown_2d(char *desc, SAMR_R_UNKNOWN_2D * r_u,
+                         prs_struct *ps, int depth);
+void init_samr_q_open_domain(SAMR_Q_OPEN_DOMAIN * q_u,
+                            POLICY_HND *pol, uint32 flags,
                             DOM_SID *sid);
 BOOL samr_io_q_open_domain(char *desc, SAMR_Q_OPEN_DOMAIN * q_u,
                           prs_struct *ps, int depth);
 BOOL samr_io_r_open_domain(char *desc, SAMR_R_OPEN_DOMAIN * r_u,
                           prs_struct *ps, int depth);
-BOOL init_samr_q_open_user(SAMR_Q_OPEN_USER * q_u, POLICY_HND *pol,
-                          uint32 access_mask, uint32 rid);
-BOOL samr_io_q_open_user(char *desc, SAMR_Q_OPEN_USER * q_u,
-                        prs_struct *ps, int depth);
-BOOL samr_io_r_open_user(char *desc, SAMR_R_OPEN_USER * r_u,
-                        prs_struct *ps, int depth);
-BOOL init_samr_q_query_userinfo(SAMR_Q_QUERY_USERINFO * q_u,
-                               POLICY_HND *hnd, uint16 switch_value);
-BOOL samr_io_q_query_userinfo(char *desc, SAMR_Q_QUERY_USERINFO * q_u,
+void init_samr_q_get_usrdom_pwinfo(SAMR_Q_GET_USRDOM_PWINFO * q_u,
+                                  POLICY_HND *user_pol);
+BOOL samr_io_q_get_usrdom_pwinfo(char *desc, SAMR_Q_GET_USRDOM_PWINFO * q_u,
+                                prs_struct *ps, int depth);
+void init_samr_r_get_usrdom_pwinfo(SAMR_R_GET_USRDOM_PWINFO *r_u, uint32 status);
+BOOL samr_io_r_get_usrdom_pwinfo(char *desc, SAMR_R_GET_USRDOM_PWINFO * r_u,
+                                prs_struct *ps, int depth);
+void init_samr_q_query_sec_obj(SAMR_Q_QUERY_SEC_OBJ * q_u,
+                              POLICY_HND *user_pol, uint32 sec_info);
+BOOL samr_io_q_query_sec_obj(char *desc, SAMR_Q_QUERY_SEC_OBJ * q_u,
+                            prs_struct *ps, int depth);
+void init_samr_q_query_dom_info(SAMR_Q_QUERY_DOMAIN_INFO * q_u,
+                               POLICY_HND *domain_pol, uint16 switch_value);
+BOOL samr_io_q_query_dom_info(char *desc, SAMR_Q_QUERY_DOMAIN_INFO * q_u,
                              prs_struct *ps, int depth);
-BOOL samr_io_r_query_userinfo(char *desc, SAMR_R_QUERY_USERINFO * r_u,
+void init_unk_info3(SAM_UNK_INFO_3 * u_3);
+void init_unk_info6(SAM_UNK_INFO_6 * u_6);
+void init_unk_info7(SAM_UNK_INFO_7 * u_7);
+void init_unk_info12(SAM_UNK_INFO_12 * u_12);
+void init_unk_info2(SAM_UNK_INFO_2 * u_2,
+                       char *domain, char *server,
+                       uint32 seq_num);
+void init_unk_info1(SAM_UNK_INFO_1 * u_1);
+void init_samr_r_query_dom_info(SAMR_R_QUERY_DOMAIN_INFO * r_u,
+                               uint16 switch_value, SAM_UNK_CTR * ctr,
+                               uint32 status);
+BOOL samr_io_r_query_dom_info(char *desc, SAMR_R_QUERY_DOMAIN_INFO * r_u,
                              prs_struct *ps, int depth);
-BOOL samr_io_userinfo_ctr(char *desc, SAM_USERINFO_CTR * ctr,
-                                prs_struct *ps, int depth);
-void free_samr_userinfo_ctr(SAM_USERINFO_CTR * ctr);
-BOOL sam_io_user_info10(char *desc, SAM_USER_INFO_10 * usr,
-                       prs_struct *ps, int depth);
-BOOL init_sam_user_info11(SAM_USER_INFO_11 * usr,
-                         NTTIME * expiry,
-                         char *mach_acct,
-                         uint32 rid_user, uint32 rid_group, uint16 acct_ctrl);
-BOOL sam_io_user_info11(char *desc, SAM_USER_INFO_11 * usr,
-                       prs_struct *ps, int depth);
-BOOL sam_io_user_info12(char *desc, SAM_USER_INFO_12 * u,
-                       prs_struct *ps, int depth);
-BOOL sam_io_user_info21(char *desc, SAM_USER_INFO_21 * usr,
-                       prs_struct *ps, int depth);
-BOOL sam_io_user_info23(char *desc, SAM_USER_INFO_23 * usr,
-                       prs_struct *ps, int depth);
-BOOL init_sam_user_info24(SAM_USER_INFO_24 * usr,
-                         const char newpass[516], uint16 passlen);
-BOOL sam_io_user_info24(char *desc, SAM_USER_INFO_24 * usr,
-                       prs_struct *ps, int depth);
-BOOL sam_io_logon_hrs(char *desc, LOGON_HRS * hrs, prs_struct *ps, 
-                     int depth);
-BOOL init_samr_q_query_groupinfo(SAMR_Q_QUERY_GROUPINFO * q_e,
+BOOL samr_io_r_query_sec_obj(char *desc, SAMR_R_QUERY_SEC_OBJ * r_u,
+                            prs_struct *ps, int depth);
+void init_sam_entry(SAM_ENTRY * sam, uint32 len_sam_name, uint32 rid);
+void init_samr_q_enum_dom_users(SAMR_Q_ENUM_DOM_USERS * q_e, POLICY_HND *pol,
+                               uint32 start_idx,
+                               uint16 acb_mask, uint16 unk_1, uint32 size);
+BOOL samr_io_q_enum_dom_users(char *desc, SAMR_Q_ENUM_DOM_USERS * q_e,
+                             prs_struct *ps, int depth);
+void init_samr_r_enum_dom_users(SAMR_R_ENUM_DOM_USERS * r_u,
+                               uint32 next_idx, uint32 num_sam_entries);
+BOOL samr_io_r_enum_dom_users(char *desc, SAMR_R_ENUM_DOM_USERS * r_u,
+                             prs_struct *ps, int depth);
+void init_samr_q_query_dispinfo(SAMR_Q_QUERY_DISPINFO * q_e, POLICY_HND *pol,
+                               uint16 switch_level, uint32 start_idx,
+                               uint32 max_entries);
+BOOL samr_io_q_query_dispinfo(char *desc, SAMR_Q_QUERY_DISPINFO * q_e,
+                             prs_struct *ps, int depth);
+void init_sam_dispinfo_1(SAM_DISPINFO_1 * sam, uint32 *num_entries,
+                        uint32 *data_size, uint32 start_idx,
+                        SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES]);
+void init_sam_dispinfo_2(SAM_DISPINFO_2 * sam, uint32 *num_entries,
+                        uint32 *data_size, uint32 start_idx,
+                        SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES]);
+void init_sam_dispinfo_3(SAM_DISPINFO_3 * sam, uint32 *num_entries,
+                        uint32 *data_size, uint32 start_idx,
+                        DOMAIN_GRP * grp);
+void init_sam_dispinfo_4(SAM_DISPINFO_4 * sam, uint32 *num_entries,
+                        uint32 *data_size, uint32 start_idx,
+                        SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES]);
+void init_sam_dispinfo_5(SAM_DISPINFO_5 * sam, uint32 *num_entries,
+                        uint32 *data_size, uint32 start_idx,
+                        DOMAIN_GRP * grp);
+void init_samr_r_query_dispinfo(SAMR_R_QUERY_DISPINFO * r_u,
+                               uint32 num_entries, uint32 data_size,
+                               uint16 switch_level, SAM_DISPINFO_CTR * ctr,
+                               uint32 status);
+BOOL samr_io_r_query_dispinfo(char *desc, SAMR_R_QUERY_DISPINFO * r_u,
+                             prs_struct *ps, int depth);
+void init_samr_q_open_group(SAMR_Q_OPEN_GROUP * q_c,
+                           POLICY_HND *hnd,
+                           uint32 access_mask, uint32 rid);
+BOOL samr_io_q_open_group(char *desc, SAMR_Q_OPEN_GROUP * q_u,
+                         prs_struct *ps, int depth);
+BOOL samr_io_r_open_group(char *desc, SAMR_R_OPEN_GROUP * r_u,
+                         prs_struct *ps, int depth);
+void init_samr_group_info1(GROUP_INFO1 * gr1,
+                          char *acct_name, char *acct_desc,
+                          uint32 num_members);
+BOOL samr_io_group_info1(char *desc, GROUP_INFO1 * gr1,
+                        prs_struct *ps, int depth);
+void init_samr_group_info4(GROUP_INFO4 * gr4, char *acct_desc);
+BOOL samr_io_group_info4(char *desc, GROUP_INFO4 * gr4,
+                        prs_struct *ps, int depth);
+void init_samr_q_create_dom_group(SAMR_Q_CREATE_DOM_GROUP * q_e,
+                                 POLICY_HND *pol, char *acct_desc,
+                                 uint32 access_mask);
+BOOL samr_io_q_create_dom_group(char *desc, SAMR_Q_CREATE_DOM_GROUP * q_e,
+                               prs_struct *ps, int depth);
+BOOL samr_io_r_create_dom_group(char *desc, SAMR_R_CREATE_DOM_GROUP * r_u,
+                               prs_struct *ps, int depth);
+void init_samr_q_delete_dom_group(SAMR_Q_DELETE_DOM_GROUP * q_c,
+                                 POLICY_HND *hnd);
+BOOL samr_io_q_delete_dom_group(char *desc, SAMR_Q_DELETE_DOM_GROUP * q_u,
+                               prs_struct *ps, int depth);
+BOOL samr_io_r_delete_dom_group(char *desc, SAMR_R_DELETE_DOM_GROUP * r_u,
+                               prs_struct *ps, int depth);
+void init_samr_q_del_groupmem(SAMR_Q_DEL_GROUPMEM * q_e,
+                             POLICY_HND *pol, uint32 rid);
+BOOL samr_io_q_del_groupmem(char *desc, SAMR_Q_DEL_GROUPMEM * q_e,
+                           prs_struct *ps, int depth);
+void init_samr_r_del_groupmem(SAMR_R_DEL_GROUPMEM * r_u, POLICY_HND *pol,
+                             uint32 status);
+BOOL samr_io_r_del_groupmem(char *desc, SAMR_R_DEL_GROUPMEM * r_u,
+                           prs_struct *ps, int depth);
+void init_samr_q_add_groupmem(SAMR_Q_ADD_GROUPMEM * q_e,
+                             POLICY_HND *pol, uint32 rid);
+BOOL samr_io_q_add_groupmem(char *desc, SAMR_Q_ADD_GROUPMEM * q_e,
+                           prs_struct *ps, int depth);
+void init_samr_r_add_groupmem(SAMR_R_ADD_GROUPMEM * r_u, POLICY_HND *pol,
+                             uint32 status);
+BOOL samr_io_r_add_groupmem(char *desc, SAMR_R_ADD_GROUPMEM * r_u,
+                           prs_struct *ps, int depth);
+void init_samr_q_set_groupinfo(SAMR_Q_SET_GROUPINFO * q_e,
+                              POLICY_HND *pol, GROUP_INFO_CTR * ctr);
+BOOL samr_io_q_set_groupinfo(char *desc, SAMR_Q_SET_GROUPINFO * q_e,
+                            prs_struct *ps, int depth);
+void init_samr_r_set_groupinfo(SAMR_R_SET_GROUPINFO * r_u, uint32 status);
+BOOL samr_io_r_set_groupinfo(char *desc, SAMR_R_SET_GROUPINFO * r_u,
+                            prs_struct *ps, int depth);
+void init_samr_q_query_groupinfo(SAMR_Q_QUERY_GROUPINFO * q_e,
                                 POLICY_HND *pol, uint16 switch_level);
 BOOL samr_io_q_query_groupinfo(char *desc, SAMR_Q_QUERY_GROUPINFO * q_e,
                               prs_struct *ps, int depth);
+void init_samr_r_query_groupinfo(SAMR_R_QUERY_GROUPINFO * r_u,
+                                GROUP_INFO_CTR * ctr, uint32 status);
 BOOL samr_io_r_query_groupinfo(char *desc, SAMR_R_QUERY_GROUPINFO * r_u,
                               prs_struct *ps, int depth);
-BOOL samr_q_query_usergroups(SAMR_Q_QUERY_USERGROUPS * q_u, 
-                                 POLICY_HND *hnd);
-BOOL samr_io_q_query_usergroups(char *desc, SAMR_Q_QUERY_USERGROUPS * q_u,
-                               prs_struct *ps, int depth);
-BOOL samr_io_r_query_usergroups(char *desc, SAMR_R_QUERY_USERGROUPS * r_u,
-                               prs_struct *ps, int depth);
-BOOL init_samr_q_query_groupmem(SAMR_Q_QUERY_GROUPMEM * q_c, POLICY_HND *hnd);
+void init_samr_q_query_groupmem(SAMR_Q_QUERY_GROUPMEM * q_c, POLICY_HND *hnd);
 BOOL samr_io_q_query_groupmem(char *desc, SAMR_Q_QUERY_GROUPMEM * q_u,
                              prs_struct *ps, int depth);
+void init_samr_r_query_groupmem(SAMR_R_QUERY_GROUPMEM * r_u,
+                               uint32 num_entries, uint32 *rid,
+                               uint32 *attr, uint32 status);
 BOOL samr_io_r_query_groupmem(char *desc, SAMR_R_QUERY_GROUPMEM * r_u,
                              prs_struct *ps, int depth);
-void samr_free_r_query_groupmem(SAMR_R_QUERY_GROUPMEM * r_u);
-BOOL samr_group_info_ctr(char *desc, GROUP_INFO_CTR * ctr, prs_struct *ps, 
-                        int depth);
+void init_samr_q_query_usergroups(SAMR_Q_QUERY_USERGROUPS * q_u,
+                                 POLICY_HND *hnd);
+BOOL samr_io_q_query_usergroups(char *desc, SAMR_Q_QUERY_USERGROUPS * q_u,
+                               prs_struct *ps, int depth);
+void init_samr_r_query_usergroups(SAMR_R_QUERY_USERGROUPS * r_u,
+                                 uint32 num_gids, DOM_GID * gid,
+                                 uint32 status);
 BOOL samr_io_gids(char *desc, uint32 *num_gids, DOM_GID ** gid,
                  prs_struct *ps, int depth);
-BOOL samr_io_group_info1(char *desc, GROUP_INFO1 * gr1,
+BOOL samr_io_r_query_usergroups(char *desc, SAMR_R_QUERY_USERGROUPS * r_u,
+                               prs_struct *ps, int depth);
+void init_samr_q_enum_domains(SAMR_Q_ENUM_DOMAINS * q_e,
+                             POLICY_HND *pol,
+                             uint32 start_idx, uint32 size);
+BOOL samr_io_q_enum_domains(char *desc, SAMR_Q_ENUM_DOMAINS * q_e,
+                           prs_struct *ps, int depth);
+void init_samr_r_enum_domains(SAMR_R_ENUM_DOMAINS * r_u,
+                             uint32 next_idx, uint32 num_sam_entries);
+BOOL samr_io_r_enum_domains(char *desc, SAMR_R_ENUM_DOMAINS * r_u,
+                           prs_struct *ps, int depth);
+void init_samr_q_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS * q_e,
+                                POLICY_HND *pol,
+                                uint32 start_idx, uint32 size);
+BOOL samr_io_q_enum_dom_groups(char *desc, SAMR_Q_ENUM_DOM_GROUPS * q_e,
+                              prs_struct *ps, int depth);
+void init_samr_r_enum_dom_groups(SAMR_R_ENUM_DOM_GROUPS * r_u,
+                                uint32 next_idx, uint32 num_sam_entries);
+BOOL samr_io_r_enum_dom_groups(char *desc, SAMR_R_ENUM_DOM_GROUPS * r_u,
+                              prs_struct *ps, int depth);
+void init_samr_q_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES * q_e,
+                                 POLICY_HND *pol, uint32 start_idx,
+                                 uint32 size);
+BOOL samr_io_q_enum_dom_aliases(char *desc, SAMR_Q_ENUM_DOM_ALIASES * q_e,
+                               prs_struct *ps, int depth);
+void init_samr_r_enum_dom_aliases(SAMR_R_ENUM_DOM_ALIASES *r_u, uint32 next_idx, uint32 num_sam_entries);
+BOOL samr_io_r_enum_dom_aliases(char *desc, SAMR_R_ENUM_DOM_ALIASES * r_u,
+                               prs_struct *ps, int depth);
+void init_samr_alias_info3(ALIAS_INFO3 * al3, char *acct_desc);
+BOOL samr_io_alias_info3(char *desc, ALIAS_INFO3 * al3,
                         prs_struct *ps, int depth);
-BOOL samr_io_group_info4(char *desc, GROUP_INFO4 * gr4,
+BOOL samr_alias_info_ctr(char *desc, ALIAS_INFO_CTR * ctr,
                         prs_struct *ps, int depth);
-BOOL init_samr_q_query_usergroups(SAMR_Q_QUERY_USERGROUPS * q_u,
-                                 POLICY_HND *hnd);
-BOOL init_samr_q_open_group(SAMR_Q_OPEN_GROUP * q_c, POLICY_HND *hnd,
-                           uint32 access_mask, uint32 rid);
-BOOL samr_io_q_open_group(char *desc, SAMR_Q_OPEN_GROUP * q_u,
+void init_samr_q_query_aliasinfo(SAMR_Q_QUERY_ALIASINFO * q_e,
+                                POLICY_HND *pol, uint16 switch_level);
+BOOL samr_io_q_query_aliasinfo(char *desc, SAMR_Q_QUERY_ALIASINFO * q_e,
+                              prs_struct *ps, int depth);
+void init_samr_r_query_aliasinfo(SAMR_R_QUERY_ALIASINFO * r_u,
+                                ALIAS_INFO_CTR * ctr, uint32 status);
+BOOL samr_io_r_query_aliasinfo(char *desc, SAMR_R_QUERY_ALIASINFO * r_u,
+                              prs_struct *ps, int depth);
+void init_samr_q_set_aliasinfo(SAMR_Q_SET_ALIASINFO * q_u,
+                              POLICY_HND *hnd, ALIAS_INFO_CTR * ctr);
+BOOL samr_io_q_set_aliasinfo(char *desc, SAMR_Q_SET_ALIASINFO * q_u,
+                            prs_struct *ps, int depth);
+BOOL samr_io_r_set_aliasinfo(char *desc, SAMR_R_SET_ALIASINFO * r_u,
+                            prs_struct *ps, int depth);
+void init_samr_q_query_useraliases(SAMR_Q_QUERY_USERALIASES * q_u,
+                                  POLICY_HND *hnd,
+                                  uint32 num_sids,
+                                  uint32 *ptr_sid, DOM_SID2 * sid);
+BOOL samr_io_q_query_useraliases(char *desc, SAMR_Q_QUERY_USERALIASES * q_u,
+                                prs_struct *ps, int depth);
+void init_samr_r_query_useraliases(SAMR_R_QUERY_USERALIASES * r_u,
+                                  uint32 num_rids, uint32 *rid,
+                                  uint32 status);
+BOOL samr_io_rids(char *desc, uint32 *num_rids, uint32 **rid,
+                 prs_struct *ps, int depth);
+BOOL samr_io_r_query_useraliases(char *desc, SAMR_R_QUERY_USERALIASES * r_u,
+                                prs_struct *ps, int depth);
+void init_samr_q_open_alias(SAMR_Q_OPEN_ALIAS * q_u, POLICY_HND *pol,
+                           uint32 unknown_0, uint32 rid);
+BOOL samr_io_q_open_alias(char *desc, SAMR_Q_OPEN_ALIAS * q_u,
                          prs_struct *ps, int depth);
-BOOL samr_io_r_open_group(char *desc, SAMR_R_OPEN_GROUP * r_u,
+BOOL samr_io_r_open_alias(char *desc, SAMR_R_OPEN_ALIAS * r_u,
                          prs_struct *ps, int depth);
-#endif
+void init_samr_q_lookup_rids(TALLOC_CTX *ctx, SAMR_Q_LOOKUP_RIDS * q_u,
+                            POLICY_HND *pol, uint32 flags,
+                            uint32 num_rids, uint32 *rid);
+BOOL samr_io_q_lookup_rids(char *desc, SAMR_Q_LOOKUP_RIDS * q_u,
+                          prs_struct *ps, int depth);
+void init_samr_r_lookup_rids(SAMR_R_LOOKUP_RIDS * r_u,
+                            uint32 num_names, UNIHDR * hdr_name,
+                            UNISTR2 *uni_name, uint32 *type);
+BOOL samr_io_r_lookup_rids(char *desc, SAMR_R_LOOKUP_RIDS * r_u,
+                          prs_struct *ps, int depth);
+void init_samr_q_delete_alias(SAMR_Q_DELETE_DOM_ALIAS * q_u, POLICY_HND *hnd);
+BOOL samr_io_q_delete_alias(char *desc, SAMR_Q_DELETE_DOM_ALIAS * q_u,
+                           prs_struct *ps, int depth);
+BOOL samr_io_r_delete_alias(char *desc, SAMR_R_DELETE_DOM_ALIAS * r_u,
+                           prs_struct *ps, int depth);
+void init_samr_q_create_dom_alias(SAMR_Q_CREATE_DOM_ALIAS * q_u,
+                                 POLICY_HND *hnd, char *acct_desc);
+BOOL samr_io_q_create_dom_alias(char *desc, SAMR_Q_CREATE_DOM_ALIAS * q_u,
+                               prs_struct *ps, int depth);
+BOOL samr_io_r_create_dom_alias(char *desc, SAMR_R_CREATE_DOM_ALIAS * r_u,
+                               prs_struct *ps, int depth);
+void init_samr_q_add_aliasmem(SAMR_Q_ADD_ALIASMEM * q_u, POLICY_HND *hnd,
+                             DOM_SID *sid);
+BOOL samr_io_q_add_aliasmem(char *desc, SAMR_Q_ADD_ALIASMEM * q_u,
+                           prs_struct *ps, int depth);
+BOOL samr_io_r_add_aliasmem(char *desc, SAMR_R_ADD_ALIASMEM * r_u,
+                           prs_struct *ps, int depth);
+void init_samr_q_del_aliasmem(SAMR_Q_DEL_ALIASMEM * q_u, POLICY_HND *hnd,
+                             DOM_SID *sid);
+BOOL samr_io_q_del_aliasmem(char *desc, SAMR_Q_DEL_ALIASMEM * q_u,
+                           prs_struct *ps, int depth);
+BOOL samr_io_r_del_aliasmem(char *desc, SAMR_R_DEL_ALIASMEM * r_u,
+                           prs_struct *ps, int depth);
+void init_samr_q_delete_dom_alias(SAMR_Q_DELETE_DOM_ALIAS * q_c,
+                                 POLICY_HND *hnd);
+BOOL samr_io_q_delete_dom_alias(char *desc, SAMR_Q_DELETE_DOM_ALIAS * q_u,
+                               prs_struct *ps, int depth);
+void init_samr_r_delete_dom_alias(SAMR_R_DELETE_DOM_ALIAS * r_u,
+                                 uint32 status);
+BOOL samr_io_r_delete_dom_alias(char *desc, SAMR_R_DELETE_DOM_ALIAS * r_u,
+                               prs_struct *ps, int depth);
+void init_samr_q_query_aliasmem(SAMR_Q_QUERY_ALIASMEM * q_c,
+                               POLICY_HND *hnd);
+BOOL samr_io_q_query_aliasmem(char *desc, SAMR_Q_QUERY_ALIASMEM * q_u,
+                             prs_struct *ps, int depth);
+void init_samr_r_query_aliasmem(SAMR_R_QUERY_ALIASMEM * r_u,
+                               uint32 num_sids, DOM_SID2 * sid,
+                               uint32 status);
+BOOL samr_io_r_query_aliasmem(char *desc, SAMR_R_QUERY_ALIASMEM * r_u,
+                             prs_struct *ps, int depth);
+void init_samr_q_lookup_names(SAMR_Q_LOOKUP_NAMES * q_u,
+                             POLICY_HND *pol, uint32 flags,
+                             uint32 num_names, char **name);
+BOOL samr_io_q_lookup_names(char *desc, SAMR_Q_LOOKUP_NAMES * q_u,
+                           prs_struct *ps, int depth);
+void init_samr_r_lookup_names(TALLOC_CTX *ctx, SAMR_R_LOOKUP_NAMES * r_u,
+                             uint32 num_rids,
+                             uint32 *rid, uint32 *type,
+                             uint32 status);
+BOOL samr_io_r_lookup_names(char *desc, SAMR_R_LOOKUP_NAMES * r_u,
+                           prs_struct *ps, int depth);
+void init_samr_q_delete_dom_user(SAMR_Q_DELETE_DOM_USER * q_c,
+                                POLICY_HND *hnd);
+BOOL samr_io_q_delete_dom_user(char *desc, SAMR_Q_DELETE_DOM_USER * q_u,
+                              prs_struct *ps, int depth);
+BOOL samr_io_r_delete_dom_user(char *desc, SAMR_R_DELETE_DOM_USER * r_u,
+                              prs_struct *ps, int depth);
+void init_samr_q_open_user(SAMR_Q_OPEN_USER * q_u,
+                          POLICY_HND *pol,
+                          uint32 access_mask, uint32 rid);
+BOOL samr_io_q_open_user(char *desc, SAMR_Q_OPEN_USER * q_u,
+                        prs_struct *ps, int depth);
+BOOL samr_io_r_open_user(char *desc, SAMR_R_OPEN_USER * r_u,
+                        prs_struct *ps, int depth);
+void init_samr_q_create_user(SAMR_Q_CREATE_USER * q_u,
+                            POLICY_HND *pol,
+                            char *name,
+                            uint32 acb_info, uint32 access_mask);
+BOOL samr_io_q_create_user(char *desc, SAMR_Q_CREATE_USER * q_u,
+                          prs_struct *ps, int depth);
+BOOL samr_io_r_create_user(char *desc, SAMR_R_CREATE_USER * r_u,
+                          prs_struct *ps, int depth);
+void init_samr_q_query_userinfo(SAMR_Q_QUERY_USERINFO * q_u,
+                               POLICY_HND *hnd, uint16 switch_value);
+BOOL samr_io_q_query_userinfo(char *desc, SAMR_Q_QUERY_USERINFO * q_u,
+                             prs_struct *ps, int depth);
+void init_sam_user_info12(SAM_USER_INFO_12 * usr,
+                         uint8 lm_pwd[16], uint8 nt_pwd[16]);
+void init_sam_user_info10(SAM_USER_INFO_10 * usr, uint32 acb_info);
+void init_sam_user_info11(SAM_USER_INFO_11 * usr,
+                         NTTIME * expiry,
+                         char *mach_acct,
+                         uint32 rid_user, uint32 rid_group, uint16 acct_ctrl);
+void init_sam_user_info24(SAM_USER_INFO_24 * usr,
+                         char newpass[516], uint16 passlen);
+void init_sam_user_info23W(SAM_USER_INFO_23 * usr, NTTIME * logon_time,        /* all zeros */
+                       NTTIME * logoff_time,   /* all zeros */
+                       NTTIME * kickoff_time,  /* all zeros */
+                       NTTIME * pass_last_set_time,    /* all zeros */
+                       NTTIME * pass_can_change_time,  /* all zeros */
+                       NTTIME * pass_must_change_time, /* all zeros */
+                       UNISTR2 *user_name,
+                       UNISTR2 *full_name,
+                       UNISTR2 *home_dir,
+                       UNISTR2 *dir_drive,
+                       UNISTR2 *log_scr,
+                       UNISTR2 *prof_path,
+                       UNISTR2 *desc,
+                       UNISTR2 *wkstas,
+                       UNISTR2 *unk_str,
+                       UNISTR2 *mung_dial,
+                       uint32 user_rid,        /* 0x0000 0000 */
+                       uint32 group_rid,
+                       uint32 acb_info,
+                       uint32 unknown_3,
+                       uint16 logon_divs,
+                       LOGON_HRS * hrs,
+                       uint32 unknown_5,
+                       char newpass[516], uint32 unknown_6);
+void init_sam_user_info23A(SAM_USER_INFO_23 * usr, NTTIME * logon_time,        /* all zeros */
+                          NTTIME * logoff_time,        /* all zeros */
+                          NTTIME * kickoff_time,       /* all zeros */
+                          NTTIME * pass_last_set_time, /* all zeros */
+                          NTTIME * pass_can_change_time,       /* all zeros */
+                          NTTIME * pass_must_change_time,      /* all zeros */
+                          char *user_name,     /* NULL */
+                          char *full_name,
+                          char *home_dir, char *dir_drive, char *log_scr,
+                          char *prof_path, char *desc, char *wkstas,
+                          char *unk_str, char *mung_dial, uint32 user_rid,     /* 0x0000 0000 */
+                          uint32 group_rid, uint32 acb_info,
+                          uint32 unknown_3, uint16 logon_divs,
+                          LOGON_HRS * hrs, uint32 unknown_5,
+                          char newpass[516], uint32 unknown_6);
+void init_sam_user_info21W(SAM_USER_INFO_21 * usr,
+                          NTTIME * logon_time,
+                          NTTIME * logoff_time,
+                          NTTIME * kickoff_time,
+                          NTTIME * pass_last_set_time,
+                          NTTIME * pass_can_change_time,
+                          NTTIME * pass_must_change_time,
+                          UNISTR2 *user_name,
+                          UNISTR2 *full_name,
+                          UNISTR2 *home_dir,
+                          UNISTR2 *dir_drive,
+                          UNISTR2 *log_scr,
+                          UNISTR2 *prof_path,
+                          UNISTR2 *desc,
+                          UNISTR2 *wkstas,
+                          UNISTR2 *unk_str,
+                          UNISTR2 *mung_dial,
+                          uchar lm_pwd[16],
+                          uchar nt_pwd[16],
+                          uint32 user_rid,
+                          uint32 group_rid,
+                          uint32 acb_info,
+                          uint32 unknown_3,
+                          uint16 logon_divs,
+                          LOGON_HRS * hrs,
+                          uint32 unknown_5, uint32 unknown_6);
+void init_sam_user_info21A(SAM_USER_INFO_21 *usr, SAM_ACCOUNT *pw);
+uint32 make_samr_userinfo_ctr_usr21(TALLOC_CTX *ctx, SAM_USERINFO_CTR * ctr,
+                                   uint16 switch_value,
+                                   SAM_USER_INFO_21 * usr);
+void init_samr_userinfo_ctr(SAM_USERINFO_CTR * ctr, uchar * sess_key,
+                           uint16 switch_value, void *info);
+void init_samr_r_query_userinfo(SAMR_R_QUERY_USERINFO * r_u,
+                               SAM_USERINFO_CTR * ctr, uint32 status);
+BOOL samr_io_r_query_userinfo(char *desc, SAMR_R_QUERY_USERINFO * r_u,
+                             prs_struct *ps, int depth);
+void init_samr_q_set_userinfo(SAMR_Q_SET_USERINFO * q_u,
+                             POLICY_HND *hnd,  unsigned char sess_key[16],
+                             uint16 switch_value, void *info);
+BOOL samr_io_q_set_userinfo(char *desc, SAMR_Q_SET_USERINFO * q_u,
+                           prs_struct *ps, int depth);
+void init_samr_r_set_userinfo(SAMR_R_SET_USERINFO * r_u, uint32 status);
+BOOL samr_io_r_set_userinfo(char *desc, SAMR_R_SET_USERINFO * r_u,
+                           prs_struct *ps, int depth);
+void init_samr_q_set_userinfo2(SAMR_Q_SET_USERINFO2 * q_u,
+                              POLICY_HND *hnd, unsigned char sess_key[16],
+                              uint16 switch_value, SAM_USERINFO_CTR * ctr);
+BOOL samr_io_q_set_userinfo2(char *desc, SAMR_Q_SET_USERINFO2 * q_u,
+                            prs_struct *ps, int depth);
+void init_samr_r_set_userinfo2(SAMR_R_SET_USERINFO2 * r_u, uint32 status);
+BOOL samr_io_r_set_userinfo2(char *desc, SAMR_R_SET_USERINFO2 * r_u,
+                            prs_struct *ps, int depth);
+void init_samr_q_connect(SAMR_Q_CONNECT * q_u,
+                        char *srv_name, uint32 access_mask);
+BOOL samr_io_q_connect(char *desc, SAMR_Q_CONNECT * q_u,
+                      prs_struct *ps, int depth);
+BOOL samr_io_r_connect(char *desc, SAMR_R_CONNECT * r_u,
+                      prs_struct *ps, int depth);
+void init_samr_q_connect_anon(SAMR_Q_CONNECT_ANON * q_u);
+BOOL samr_io_q_connect_anon(char *desc, SAMR_Q_CONNECT_ANON * q_u,
+                           prs_struct *ps, int depth);
+BOOL samr_io_r_connect_anon(char *desc, SAMR_R_CONNECT_ANON * r_u,
+                           prs_struct *ps, int depth);
+void init_samr_q_get_dom_pwinfo(SAMR_Q_GET_DOM_PWINFO * q_u,
+                               char *srv_name);
+BOOL samr_io_q_get_dom_pwinfo(char *desc, SAMR_Q_GET_DOM_PWINFO * q_u,
+                             prs_struct *ps, int depth);
+BOOL samr_io_r_get_dom_pwinfo(char *desc, SAMR_R_GET_DOM_PWINFO * r_u,
+                             prs_struct *ps, int depth);
+void init_enc_passwd(SAMR_ENC_PASSWD * pwd, char pass[512]);
+BOOL samr_io_enc_passwd(char *desc, SAMR_ENC_PASSWD * pwd,
+                       prs_struct *ps, int depth);
+void init_enc_hash(SAMR_ENC_HASH * hsh, uchar hash[16]);
+BOOL samr_io_enc_hash(char *desc, SAMR_ENC_HASH * hsh,
+                     prs_struct *ps, int depth);
+void init_samr_q_chgpasswd_user(SAMR_Q_CHGPASSWD_USER * q_u,
+                               char *dest_host, char *user_name,
+                               char nt_newpass[516],
+                               uchar nt_oldhash[16],
+                               char lm_newpass[516],
+                               uchar lm_oldhash[16]);
+BOOL samr_io_q_chgpasswd_user(char *desc, SAMR_Q_CHGPASSWD_USER * q_u,
+                             prs_struct *ps, int depth);
+void init_samr_r_chgpasswd_user(SAMR_R_CHGPASSWD_USER * r_u, uint32 status);
+BOOL samr_io_r_chgpasswd_user(char *desc, SAMR_R_CHGPASSWD_USER * r_u,
+                             prs_struct *ps, int depth);
 
 /*The following definitions come from  rpc_parse/parse_sec.c  */
 
@@ -3234,8 +3391,6 @@ void init_srv_q_net_share_enum(SRV_Q_NET_SHARE_ENUM *q_n,
                                uint32 preferred_len, ENUM_HND *hnd);
 BOOL srv_io_q_net_share_enum(char *desc, SRV_Q_NET_SHARE_ENUM *q_n, prs_struct *ps, int depth);
 BOOL srv_io_r_net_share_enum(char *desc, SRV_R_NET_SHARE_ENUM *r_n, prs_struct *ps, int depth);
-void free_srv_q_net_share_get_info(SRV_Q_NET_SHARE_GET_INFO *q_n);
-void free_srv_r_net_share_get_info(SRV_R_NET_SHARE_GET_INFO *r_n);
 BOOL srv_io_q_net_share_get_info(char *desc, SRV_Q_NET_SHARE_GET_INFO *q_n, prs_struct *ps, int depth);
 BOOL srv_io_r_net_share_get_info(char *desc, SRV_R_NET_SHARE_GET_INFO *r_n, prs_struct *ps, int depth);
 void init_srv_sess_info0_str(SESS_INFO_0_STR *ss0, char *name);
@@ -3276,6 +3431,7 @@ void init_srv_q_net_file_enum(SRV_Q_NET_FILE_ENUM *q_n,
                                ENUM_HND *hnd);
 BOOL srv_io_q_net_file_enum(char *desc, SRV_Q_NET_FILE_ENUM *q_n, prs_struct *ps, int depth);
 BOOL srv_io_r_net_file_enum(char *desc, SRV_R_NET_FILE_ENUM *r_n, prs_struct *ps, int depth);
+void init_srv_info_100(SRV_INFO_100 *sv100, uint32 platform_id, char *name);
 void init_srv_info_101(SRV_INFO_101 *sv101, uint32 platform_id, char *name,
                                uint32 ver_major, uint32 ver_minor,
                                uint32 srv_type, char *comment);
@@ -3324,28 +3480,18 @@ uint32 _dfs_get_info(pipes_struct *p, DFS_Q_DFS_GET_INFO *q_u, DFS_R_DFS_GET_INF
 
 /*The following definitions come from  rpc_server/srv_lsa.c  */
 
-#if OLD_NTDOMAIN
 BOOL api_ntlsa_rpc(pipes_struct *p);
-#endif
 
 /*The following definitions come from  rpc_server/srv_lsa_hnd.c  */
 
-#if OLD_NTDOMAIN
-void create_policy_handle(POLICY_HND *hnd, uint32 *hnd_low, uint32 *hnd_high);
-void init_lsa_policy_hnd(void);
-BOOL open_lsa_policy_hnd(POLICY_HND *hnd);
-int find_lsa_policy_by_hnd(POLICY_HND *hnd);
-BOOL set_lsa_policy_samr_pol_status(POLICY_HND *hnd, uint32 pol_status);
-BOOL set_lsa_policy_samr_sid(POLICY_HND *hnd, DOM_SID *sid);
-BOOL get_lsa_policy_samr_sid(POLICY_HND *hnd, DOM_SID *sid);
-uint32 get_lsa_policy_samr_rid(POLICY_HND *hnd);
-BOOL set_lsa_policy_reg_name(POLICY_HND *hnd, fstring name);
-BOOL close_lsa_policy_hnd(POLICY_HND *hnd);
-#endif
+void init_pipe_handles(pipes_struct *p);
+BOOL create_policy_hnd(pipes_struct *p, POLICY_HND *hnd, void (*free_fn)(void *), void *data_ptr);
+BOOL find_policy_by_hnd(pipes_struct *p, POLICY_HND *hnd, void **data_p);
+BOOL close_policy_hnd(pipes_struct *p, POLICY_HND *hnd);
+void close_policy_by_pipe(pipes_struct *p);
 
 /*The following definitions come from  rpc_server/srv_lsa_nt.c  */
 
-#if OLD_NTDOMAIN
 uint32 _lsa_open_policy2(pipes_struct *p, LSA_Q_OPEN_POL2 *q_u, LSA_R_OPEN_POL2 *r_u);
 uint32 _lsa_open_policy(pipes_struct *p, LSA_Q_OPEN_POL *q_u, LSA_R_OPEN_POL *r_u);
 uint32 _lsa_enum_trust_dom(pipes_struct *p, LSA_Q_ENUM_TRUST_DOM *q_u, LSA_R_ENUM_TRUST_DOM *r_u);
@@ -3354,17 +3500,23 @@ uint32 _lsa_lookup_sids(pipes_struct *p, LSA_Q_LOOKUP_SIDS *q_u, LSA_R_LOOKUP_SI
 uint32 _lsa_lookup_names(pipes_struct *p,LSA_Q_LOOKUP_NAMES *q_u, LSA_R_LOOKUP_NAMES *r_u);
 uint32 _lsa_close(pipes_struct *p, LSA_Q_CLOSE *q_u, LSA_R_CLOSE *r_u);
 uint32 _lsa_open_secret(pipes_struct *p, LSA_Q_OPEN_SECRET *q_u, LSA_R_OPEN_SECRET *r_u);
-#endif
 
 /*The following definitions come from  rpc_server/srv_netlog.c  */
 
-#if OLD_NTDOMAIN
 BOOL api_netlog_rpc(pipes_struct *p);
-#endif
+
+/*The following definitions come from  rpc_server/srv_netlog_nt.c  */
+
+uint32 _net_logon_ctrl2(pipes_struct *p, NET_Q_LOGON_CTRL2 *q_u, NET_R_LOGON_CTRL2 *r_u);
+uint32 _net_trust_dom_list(pipes_struct *p, NET_Q_TRUST_DOM_LIST *q_u, NET_R_TRUST_DOM_LIST *r_u);
+uint32 _net_req_chal(pipes_struct *p, NET_Q_REQ_CHAL *q_u, NET_R_REQ_CHAL *r_u);
+uint32 _net_auth_2(pipes_struct *p, NET_Q_AUTH_2 *q_u, NET_R_AUTH_2 *r_u);
+uint32 _net_srv_pwset(pipes_struct *p, NET_Q_SRV_PWSET *q_u, NET_R_SRV_PWSET *r_u);
+uint32 _net_sam_logoff(pipes_struct *p, NET_Q_SAM_LOGOFF *q_u, NET_R_SAM_LOGOFF *r_u);
+uint32 _net_sam_logon(pipes_struct *p, NET_Q_SAM_LOGON *q_u, NET_R_SAM_LOGON *r_u);
 
 /*The following definitions come from  rpc_server/srv_pipe.c  */
 
-#if OLD_NTDOMAIN
 BOOL create_next_pdu(pipes_struct *p);
 BOOL api_pipe_bind_auth_resp(pipes_struct *p, prs_struct *rpc_in_p);
 BOOL setup_fault_pdu(pipes_struct *p);
@@ -3375,16 +3527,17 @@ BOOL api_pipe_auth_process(pipes_struct *p, prs_struct *rpc_in);
 BOOL api_pipe_request(pipes_struct *p);
 BOOL api_rpcTNP(pipes_struct *p, char *rpc_name, 
                struct api_struct *api_rpc_cmds);
-#endif
 
 /*The following definitions come from  rpc_server/srv_pipe_hnd.c  */
 
-#if OLD_NTDOMAIN
+pipes_struct *get_first_pipe(void);
+pipes_struct *get_next_pipe(pipes_struct *p);
 void set_pipe_handle_offset(int max_open_files);
 void reset_chain_p(void);
 void init_rpc_pipe_hnd(void);
 pipes_struct *open_rpc_pipe_p(char *pipe_name, 
                              connection_struct *conn, uint16 vuid);
+void free_pipe_context(pipes_struct *p);
 ssize_t write_to_pipe(pipes_struct *p, char *data, size_t n);
 ssize_t read_from_pipe(pipes_struct *p, char *data, size_t n);
 BOOL wait_rpc_pipe_hnd_state(pipes_struct *p, uint16 priority);
@@ -3392,39 +3545,72 @@ BOOL set_rpc_pipe_hnd_state(pipes_struct *p, uint16 device_state);
 BOOL close_rpc_pipe_hnd(pipes_struct *p, connection_struct *conn);
 pipes_struct *get_rpc_pipe_p(char *buf, int where);
 pipes_struct *get_rpc_pipe(int pnum);
-#endif
 
 /*The following definitions come from  rpc_server/srv_reg.c  */
 
-#if OLD_NTDOMAIN
 BOOL api_reg_rpc(pipes_struct *p);
-#endif
 
 /*The following definitions come from  rpc_server/srv_reg_nt.c  */
 
-#if OLD_NTDOMAIN
 uint32 _reg_close(pipes_struct *p, REG_Q_CLOSE *q_u, REG_R_CLOSE *r_u);
 uint32 _reg_open(pipes_struct *p, REG_Q_OPEN_HKLM *q_u, REG_R_OPEN_HKLM *r_u);
 uint32 _reg_open_entry(pipes_struct *p, REG_Q_OPEN_ENTRY *q_u, REG_R_OPEN_ENTRY *r_u);
 uint32 _reg_info(pipes_struct *p, REG_Q_INFO *q_u, REG_R_INFO *r_u);
-#endif
 
 /*The following definitions come from  rpc_server/srv_samr.c  */
 
-#if OLD_NTDOMAIN
 BOOL api_samr_rpc(pipes_struct *p);
-#endif
+
+/*The following definitions come from  rpc_server/srv_samr_nt.c  */
+
+uint32 _samr_close_hnd(pipes_struct *p, SAMR_Q_CLOSE_HND *q_u, SAMR_R_CLOSE_HND *r_u);
+uint32 _samr_open_domain(pipes_struct *p, SAMR_Q_OPEN_DOMAIN *q_u, SAMR_R_OPEN_DOMAIN *r_u);
+uint32 _samr_get_usrdom_pwinfo(pipes_struct *p, SAMR_Q_GET_USRDOM_PWINFO *q_u, SAMR_R_GET_USRDOM_PWINFO *r_u);
+uint32 _samr_query_sec_obj(pipes_struct *p, SAMR_Q_QUERY_SEC_OBJ *q_u, SAMR_R_QUERY_SEC_OBJ *r_u);
+uint32 _samr_enum_dom_users(pipes_struct *p, SAMR_Q_ENUM_DOM_USERS *q_u, SAMR_R_ENUM_DOM_USERS *r_u);
+uint32 _samr_enum_dom_groups(pipes_struct *p, SAMR_Q_ENUM_DOM_GROUPS *q_u, SAMR_R_ENUM_DOM_GROUPS *r_u);
+uint32 _samr_enum_dom_aliases(pipes_struct *p, SAMR_Q_ENUM_DOM_ALIASES *q_u, SAMR_R_ENUM_DOM_ALIASES *r_u);
+uint32 _samr_query_dispinfo(pipes_struct *p, SAMR_Q_QUERY_DISPINFO *q_u, SAMR_R_QUERY_DISPINFO *r_u);
+uint32 _samr_query_aliasinfo(pipes_struct *p, SAMR_Q_QUERY_ALIASINFO *q_u, SAMR_R_QUERY_ALIASINFO *r_u);
+uint32 _samr_lookup_names(pipes_struct *p, SAMR_Q_LOOKUP_NAMES *q_u, SAMR_R_LOOKUP_NAMES *r_u);
+uint32 _samr_chgpasswd_user(pipes_struct *p, SAMR_Q_CHGPASSWD_USER *q_u, SAMR_R_CHGPASSWD_USER *r_u);
+uint32 _samr_lookup_rids(pipes_struct *p, SAMR_Q_LOOKUP_RIDS *q_u, SAMR_R_LOOKUP_RIDS *r_u);
+uint32 _api_samr_open_user(pipes_struct *p, SAMR_Q_OPEN_USER *q_u, SAMR_R_OPEN_USER *r_u);
+uint32 _samr_query_userinfo(pipes_struct *p, SAMR_Q_QUERY_USERINFO *q_u, SAMR_R_QUERY_USERINFO *r_u);
+uint32 _samr_query_usergroups(pipes_struct *p, SAMR_Q_QUERY_USERGROUPS *q_u, SAMR_R_QUERY_USERGROUPS *r_u);
+uint32 _samr_query_dom_info(pipes_struct *p, SAMR_Q_QUERY_DOMAIN_INFO *q_u, SAMR_R_QUERY_DOMAIN_INFO *r_u);
+uint32 _api_samr_create_user(pipes_struct *p, SAMR_Q_CREATE_USER *q_u, SAMR_R_CREATE_USER *r_u);
+uint32 _samr_connect_anon(pipes_struct *p, SAMR_Q_CONNECT_ANON *q_u, SAMR_R_CONNECT_ANON *r_u);
+uint32 _samr_connect(pipes_struct *p, SAMR_Q_CONNECT *q_u, SAMR_R_CONNECT *r_u);
+uint32 _samr_lookup_domain(pipes_struct *p, SAMR_Q_LOOKUP_DOMAIN *q_u, SAMR_R_LOOKUP_DOMAIN *r_u);
+uint32 _samr_enum_domains(pipes_struct *p, SAMR_Q_ENUM_DOMAINS *q_u, SAMR_R_ENUM_DOMAINS *r_u);
+uint32 _api_samr_open_alias(pipes_struct *p, SAMR_Q_OPEN_ALIAS *q_u, SAMR_R_OPEN_ALIAS *r_u);
+uint32 _samr_set_userinfo(pipes_struct *p, SAMR_Q_SET_USERINFO *q_u, SAMR_R_SET_USERINFO *r_u);
+uint32 _samr_set_userinfo2(pipes_struct *p, SAMR_Q_SET_USERINFO2 *q_u, SAMR_R_SET_USERINFO2 *r_u);
+uint32 _samr_query_useraliases(pipes_struct *p, SAMR_Q_QUERY_USERALIASES *q_u, SAMR_R_QUERY_USERALIASES *r_u);
+uint32 _samr_query_aliasmem(pipes_struct *p, SAMR_Q_QUERY_ALIASMEM *q_u, SAMR_R_QUERY_ALIASMEM *r_u);
+uint32 _samr_query_groupmem(pipes_struct *p, SAMR_Q_QUERY_GROUPMEM *q_u, SAMR_R_QUERY_GROUPMEM *r_u);
+uint32 _samr_add_aliasmem(pipes_struct *p, SAMR_Q_ADD_ALIASMEM *q_u, SAMR_R_ADD_ALIASMEM *r_u);
+uint32 _samr_del_aliasmem(pipes_struct *p, SAMR_Q_DEL_ALIASMEM *q_u, SAMR_R_DEL_ALIASMEM *r_u);
+uint32 _samr_add_groupmem(pipes_struct *p, SAMR_Q_ADD_GROUPMEM *q_u, SAMR_R_ADD_GROUPMEM *r_u);
+uint32 _samr_del_groupmem(pipes_struct *p, SAMR_Q_DEL_GROUPMEM *q_u, SAMR_R_DEL_GROUPMEM *r_u);
+uint32 _samr_delete_dom_user(pipes_struct *p, SAMR_Q_DELETE_DOM_USER *q_u, SAMR_R_DELETE_DOM_USER *r_u );
+uint32 _samr_delete_dom_group(pipes_struct *p, SAMR_Q_DELETE_DOM_GROUP *q_u, SAMR_R_DELETE_DOM_GROUP *r_u);
+uint32 _samr_delete_dom_alias(pipes_struct *p, SAMR_Q_DELETE_DOM_ALIAS *q_u, SAMR_R_DELETE_DOM_ALIAS *r_u);
+uint32 _samr_create_dom_group(pipes_struct *p, SAMR_Q_CREATE_DOM_GROUP *q_u, SAMR_R_CREATE_DOM_GROUP *r_u);
+uint32 _samr_create_dom_alias(pipes_struct *p, SAMR_Q_CREATE_DOM_ALIAS *q_u, SAMR_R_CREATE_DOM_ALIAS *r_u);
+uint32 _samr_query_groupinfo(pipes_struct *p, SAMR_Q_QUERY_GROUPINFO *q_u, SAMR_R_QUERY_GROUPINFO *r_u);
+uint32 _samr_set_groupinfo(pipes_struct *p, SAMR_Q_SET_GROUPINFO *q_u, SAMR_R_SET_GROUPINFO *r_u);
+uint32 _samr_get_dom_pwinfo(pipes_struct *p, SAMR_Q_GET_DOM_PWINFO *q_u, SAMR_R_GET_DOM_PWINFO *r_u);
+uint32 _samr_open_group(pipes_struct *p, SAMR_Q_OPEN_GROUP *q_u, SAMR_R_OPEN_GROUP *r_u);
+uint32 _samr_unknown_2d(pipes_struct *p, SAMR_Q_UNKNOWN_2D *q_u, SAMR_R_UNKNOWN_2D *r_u);
 
 /*The following definitions come from  rpc_server/srv_spoolss.c  */
 
-#if OLD_NTDOMAIN
 BOOL api_spoolss_rpc(pipes_struct *p);
-#endif
 
 /*The following definitions come from  rpc_server/srv_spoolss_nt.c  */
 
-#if OLD_NTDOMAIN
-void init_printer_hnd(void);
 void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size_t len);
 uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u, SPOOL_R_OPEN_PRINTER_EX *r_u);
 BOOL convert_devicemode(char *printername, const DEVICEMODE *devmode,
@@ -3466,17 +3652,13 @@ uint32 _spoolss_enumprintprocessors(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCESSORS
 uint32 _spoolss_enumprintprocdatatypes(pipes_struct *p, SPOOL_Q_ENUMPRINTPROCDATATYPES *q_u, SPOOL_R_ENUMPRINTPROCDATATYPES *r_u);
 uint32 _spoolss_enumprintmonitors(pipes_struct *p, SPOOL_Q_ENUMPRINTMONITORS *q_u, SPOOL_R_ENUMPRINTMONITORS *r_u);
 uint32 _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_u);
-#endif
 
 /*The following definitions come from  rpc_server/srv_srvsvc.c  */
 
-#if OLD_NTDOMAIN
 BOOL api_srvsvc_rpc(pipes_struct *p);
-#endif
 
 /*The following definitions come from  rpc_server/srv_srvsvc_nt.c  */
 
-#if OLD_NTDOMAIN
 uint32 _srv_net_srv_get_info(pipes_struct *p, SRV_Q_NET_SRV_GET_INFO *q_u, SRV_R_NET_SRV_GET_INFO *r_u);
 uint32 _srv_net_file_enum(pipes_struct *p, SRV_Q_NET_FILE_ENUM *q_u, SRV_R_NET_FILE_ENUM *r_u);
 uint32 _srv_net_conn_enum(pipes_struct *p, SRV_Q_NET_CONN_ENUM *q_u, SRV_R_NET_CONN_ENUM *r_u);
@@ -3484,46 +3666,51 @@ uint32 _srv_net_sess_enum(pipes_struct *p, SRV_Q_NET_SESS_ENUM *q_u, SRV_R_NET_S
 uint32 _srv_net_share_enum(pipes_struct *p, SRV_Q_NET_SHARE_ENUM *q_u, SRV_R_NET_SHARE_ENUM *r_u);
 uint32 _srv_net_share_get_info(pipes_struct *p, SRV_Q_NET_SHARE_GET_INFO *q_u, SRV_R_NET_SHARE_GET_INFO *r_u);
 uint32 _srv_net_remote_tod(pipes_struct *p, SRV_Q_NET_REMOTE_TOD *q_u, SRV_R_NET_REMOTE_TOD *r_u);
-#endif
 
 /*The following definitions come from  rpc_server/srv_util.c  */
 
-#if OLD_NTDOMAIN
-int make_dom_gids(char *gids_str, DOM_GID **ppgids);
+int make_dom_gids(TALLOC_CTX *ctx, char *gids_str, DOM_GID **ppgids);
 void get_domain_user_groups(char *domain_groups, char *user);
-uint32 lookup_group_name(uint32 rid, char *group_name, uint32 *type);
-uint32 lookup_alias_name(uint32 rid, char *alias_name, uint32 *type);
-uint32 lookup_user_name(uint32 rid, char *user_name, uint32 *type);
-uint32 lookup_group_rid(char *group_name, uint32 *rid);
-uint32 lookup_alias_rid(char *alias_name, uint32 *rid);
-uint32 lookup_user_rid(char *user_name, uint32 *rid);
-#endif
+uint32 local_lookup_group_name(uint32 rid, char *group_name, uint32 *type);
+uint32 local_lookup_alias_name(uint32 rid, char *alias_name, uint32 *type);
+uint32 local_lookup_user_name(uint32 rid, char *user_name, uint32 *type);
+uint32 local_lookup_group_rid(char *group_name, uint32 *rid);
+uint32 local_lookup_alias_rid(char *alias_name, uint32 *rid);
+uint32 local_lookup_user_rid(char *user_name, uint32 *rid);
 
 /*The following definitions come from  rpc_server/srv_wkssvc.c  */
 
-#if OLD_NTDOMAIN
 BOOL api_wkssvc_rpc(pipes_struct *p);
-#endif
 
 /*The following definitions come from  rpc_server/srv_wkssvc_nt.c  */
 
-#if OLD_NTDOMAIN
 uint32 _wks_query_info(pipes_struct *p, WKS_Q_QUERY_INFO *q_u, WKS_R_QUERY_INFO *r_u);
-#endif
+
+/*The following definitions come from  rpcclient/cmd_lsarpc.c  */
+
+
+/*The following definitions come from  rpcclient/cmd_samr.c  */
+
+
+/*The following definitions come from  rpcclient/cmd_spoolss.c  */
+
+
+/*The following definitions come from  rpcclient/rpcclient.c  */
+
+void fetch_domain_sid(void);
+void init_rpcclient_creds(struct ntuser_creds *creds);
+void add_command_set(struct cmd_set *cmd_set);
 
 /*The following definitions come from  smbd/blocking.c  */
 
-#if OLD_NTDOMAIN
 BOOL push_blocking_lock_request( char *inbuf, int length, int lock_timeout, int lock_num);
 void remove_pending_lock_requests_by_fid(files_struct *fsp);
 void remove_pending_lock_requests_by_mid(int mid);
 BOOL blocking_locks_pending(void);
 void process_blocking_lock_queue(time_t t);
-#endif
 
 /*The following definitions come from  smbd/chgpasswd.c  */
 
-#if OLD_NTDOMAIN
 BOOL chgpasswd(char *name, char *oldpass, char *newpass, BOOL as_root);
 BOOL chgpasswd(char *name, char *oldpass, char *newpass, BOOL as_root);
 BOOL check_lanman_password(char *user, uchar * pass1,
@@ -3542,17 +3729,13 @@ BOOL change_oem_password(SAM_ACCOUNT *hnd, char *new_passwd,
                         BOOL override);
 BOOL check_plaintext_password(char *user, char *old_passwd,
                              int old_passwd_size, SAM_ACCOUNT **hnd);
-#endif
 
 /*The following definitions come from  smbd/close.c  */
 
-#if OLD_NTDOMAIN
 int close_file(files_struct *fsp, BOOL normal_close);
-#endif
 
 /*The following definitions come from  smbd/conn.c  */
 
-#if OLD_NTDOMAIN
 void conn_init(void);
 int conn_num_open(void);
 BOOL conn_snum_used(int snum);
@@ -3561,7 +3744,6 @@ connection_struct *conn_new(void);
 void conn_close_all(void);
 BOOL conn_idle_all(time_t t, int deadtime);
 void conn_free(connection_struct *conn);
-#endif
 
 /*The following definitions come from  smbd/connection.c  */
 
@@ -3576,7 +3758,6 @@ SMB_BIG_UINT sys_disk_free(char *path, BOOL small_query,
 
 /*The following definitions come from  smbd/dir.c  */
 
-#if OLD_NTDOMAIN
 void init_dptrs(void);
 char *dptr_path(int key);
 char *dptr_wcard(int key);
@@ -3602,29 +3783,23 @@ int TellDir(void *p);
 void DirCacheAdd( char *path, char *name, char *dname, int snum );
 char *DirCacheCheck( char *path, char *name, int snum );
 void DirCacheFlush(int snum);
-#endif
 
 /*The following definitions come from  smbd/dosmode.c  */
 
-#if OLD_NTDOMAIN
 mode_t unix_mode(connection_struct *conn,int dosmode,const char *fname);
 int dos_mode(connection_struct *conn,char *path,SMB_STRUCT_STAT *sbuf);
 int file_chmod(connection_struct *conn,char *fname,int dosmode,SMB_STRUCT_STAT *st);
 int file_utime(connection_struct *conn, char *fname, struct utimbuf *times);
 BOOL set_filetime(connection_struct *conn, char *fname, time_t mtime);
-#endif
 
 /*The following definitions come from  smbd/error.c  */
 
-#if OLD_NTDOMAIN
 int cached_error_packet(char *inbuf,char *outbuf,files_struct *fsp,int line);
 int unix_error_packet(char *inbuf,char *outbuf,int def_class,uint32 def_code,int line);
 int error_packet(char *inbuf,char *outbuf,int error_class,uint32 error_code,int line);
-#endif
 
 /*The following definitions come from  smbd/fileio.c  */
 
-#if OLD_NTDOMAIN
 SMB_OFF_T seek_file(files_struct *fsp,SMB_OFF_T pos);
 BOOL read_from_write_cache(files_struct *fsp,char *data,SMB_OFF_T pos,size_t n);
 ssize_t read_file(files_struct *fsp,char *data,SMB_OFF_T pos,size_t n);
@@ -3633,19 +3808,15 @@ void delete_write_cache(files_struct *fsp);
 void set_filelen_write_cache(files_struct *fsp, SMB_OFF_T file_size);
 ssize_t flush_write_cache(files_struct *fsp, enum flush_reason_enum reason);
 void sync_file(connection_struct *conn, files_struct *fsp);
-#endif
 
 /*The following definitions come from  smbd/filename.c  */
 
-#if OLD_NTDOMAIN
 BOOL unix_convert(char *name,connection_struct *conn,char *saved_last_component, 
                   BOOL *bad_path, SMB_STRUCT_STAT *pst);
 BOOL check_name(char *name,connection_struct *conn);
-#endif
 
 /*The following definitions come from  smbd/files.c  */
 
-#if OLD_NTDOMAIN
 files_struct *file_new(void );
 void file_close_conn(connection_struct *conn);
 void file_init(void);
@@ -3661,24 +3832,19 @@ files_struct *file_fsp(char *buf, int where);
 void file_chain_reset(void);
 void file_chain_save(void);
 void file_chain_restore(void);
-#endif
 
 /*The following definitions come from  smbd/ipc.c  */
 
-#if OLD_NTDOMAIN
 void send_trans_reply(char *outbuf,
                                char *rparam, int rparam_len,
                                char *rdata, int rdata_len,
                                BOOL buffer_too_large);
 int reply_trans(connection_struct *conn, char *inbuf,char *outbuf, int size, int bufsize);
-#endif
 
 /*The following definitions come from  smbd/lanman.c  */
 
-#if OLD_NTDOMAIN
 int api_reply(connection_struct *conn,uint16 vuid,char *outbuf,char *data,char *params,
                     int tdscnt,int tpscnt,int mdrcnt,int mprcnt);
-#endif
 
 /*The following definitions come from  smbd/mangle.c  */
 
@@ -3691,7 +3857,6 @@ BOOL name_map_mangle(char *OutName, BOOL need83, BOOL cache83, int snum);
 
 /*The following definitions come from  smbd/message.c  */
 
-#if OLD_NTDOMAIN
 int reply_sends(connection_struct *conn,
                char *inbuf,char *outbuf, int dum_size, int dum_buffsize);
 int reply_sendstrt(connection_struct *conn,
@@ -3700,15 +3865,12 @@ int reply_sendtxt(connection_struct *conn,
                  char *inbuf,char *outbuf, int dum_size, int dum_buffsize);
 int reply_sendend(connection_struct *conn,
                  char *inbuf,char *outbuf, int dum_size, int dum_buffsize);
-#endif
 
 /*The following definitions come from  smbd/negprot.c  */
 
-#if OLD_NTDOMAIN
 int reply_negprot(connection_struct *conn, 
                  char *inbuf,char *outbuf, int dum_size, 
                  int dum_buffsize);
-#endif
 
 /*The following definitions come from  smbd/noquotas.c  */
 
@@ -3716,7 +3878,6 @@ BOOL disk_quotas(char *path,SMB_BIG_UINT *bsize,SMB_BIG_UINT *dfree,SMB_BIG_UINT
 
 /*The following definitions come from  smbd/notify.c  */
 
-#if OLD_NTDOMAIN
 void remove_pending_change_notify_requests_by_fid(files_struct *fsp);
 void remove_pending_change_notify_requests_by_mid(int mid);
 void remove_pending_change_notify_requests_by_filename(files_struct *fsp);
@@ -3724,23 +3885,17 @@ int change_notify_timeout(void);
 BOOL process_pending_change_notify_queue(time_t t);
 BOOL change_notify_set(char *inbuf, files_struct *fsp, connection_struct *conn, uint32 flags);
 BOOL init_change_notify(void);
-#endif
 
 /*The following definitions come from  smbd/notify_hash.c  */
 
-#if OLD_NTDOMAIN
 struct cnotify_fns *hash_notify_init(void) ;
-#endif
 
 /*The following definitions come from  smbd/notify_kernel.c  */
 
-#if OLD_NTDOMAIN
 struct cnotify_fns *kernel_notify_init(void) ;
-#endif
 
 /*The following definitions come from  smbd/nttrans.c  */
 
-#if OLD_NTDOMAIN
 void fail_next_srvsvc_open(void);
 BOOL should_fail_next_srvsvc_open(const char *pipename);
 int reply_ntcreate_and_X(connection_struct *conn,
@@ -3751,11 +3906,9 @@ int reply_nttranss(connection_struct *conn,
                   char *inbuf,char *outbuf,int length,int bufsize);
 int reply_nttrans(connection_struct *conn,
                  char *inbuf,char *outbuf,int length,int bufsize);
-#endif
 
 /*The following definitions come from  smbd/open.c  */
 
-#if OLD_NTDOMAIN
 int fd_close(struct connection_struct *conn, files_struct *fsp);
 files_struct *open_file_shared(connection_struct *conn,char *fname, SMB_STRUCT_STAT *psbuf, 
                                int share_mode,int ofun, mode_t mode,int oplock_request, int *Access,int *action);
@@ -3764,11 +3917,9 @@ files_struct *open_file_stat(connection_struct *conn, char *fname,
 files_struct *open_directory(connection_struct *conn, char *fname,
                                                        SMB_STRUCT_STAT *psbuf, int smb_ofun, mode_t unixmode, int *action);
 BOOL check_file_sharing(connection_struct *conn,char *fname, BOOL rename_op);
-#endif
 
 /*The following definitions come from  smbd/oplock.c  */
 
-#if OLD_NTDOMAIN
 int32 get_number_of_exclusive_open_oplocks(void);
 BOOL receive_local_message(fd_set *fds, char *buffer, int buffer_len, int timeout);
 BOOL set_file_oplock(files_struct *fsp, int oplock_type);
@@ -3782,23 +3933,17 @@ BOOL request_oplock_break(share_mode_entry *share_entry,
 BOOL attempt_close_oplocked_file(files_struct *fsp);
 void release_level_2_oplocks_on_change(files_struct *fsp);
 BOOL init_oplocks(void);
-#endif
 
 /*The following definitions come from  smbd/oplock_irix.c  */
 
-#if OLD_NTDOMAIN
 struct kernel_oplocks *irix_init_kernel_oplocks(void) ;
-#endif
 
 /*The following definitions come from  smbd/oplock_linux.c  */
 
-#if OLD_NTDOMAIN
 struct kernel_oplocks *linux_init_kernel_oplocks(void) ;
-#endif
 
 /*The following definitions come from  smbd/password.c  */
 
-#if OLD_NTDOMAIN
 void generate_next_challenge(char *challenge);
 BOOL set_challenge(unsigned char *challenge);
 user_struct *get_valid_user_struct(uint16 vuid);
@@ -3828,31 +3973,25 @@ BOOL domain_client_validate( char *user, char *domain,
                              char *smb_apasswd, int smb_apasslen, 
                              char *smb_ntpasswd, int smb_ntpasslen,
                              BOOL *user_exists);
-#endif
 
 /*The following definitions come from  smbd/pipes.c  */
 
-#if OLD_NTDOMAIN
 int reply_open_pipe_and_X(connection_struct *conn,
                          char *inbuf,char *outbuf,int length,int bufsize);
 int reply_pipe_write(char *inbuf,char *outbuf,int length,int dum_bufsize);
 int reply_pipe_write_and_X(char *inbuf,char *outbuf,int length,int bufsize);
 int reply_pipe_read_and_X(char *inbuf,char *outbuf,int length,int bufsize);
 int reply_pipe_close(connection_struct *conn, char *inbuf,char *outbuf);
-#endif
 
 /*The following definitions come from  smbd/posix_acls.c  */
 
-#if OLD_NTDOMAIN
 size_t get_nt_acl(files_struct *fsp, SEC_DESC **ppdesc);
 BOOL set_nt_acl(files_struct *fsp, uint32 security_info_sent, SEC_DESC *psd);
 int chmod_acl(char *name, mode_t mode);
 int fchmod_acl(int fd, mode_t mode);
-#endif
 
 /*The following definitions come from  smbd/process.c  */
 
-#if OLD_NTDOMAIN
 BOOL push_oplock_pending_smb_message(char *buf, int msg_len);
 BOOL receive_next_smb(char *inbuf, int bufsize, int timeout);
 void respond_to_all_remaining_local_messages(void);
@@ -3862,11 +4001,9 @@ void construct_reply_common(char *inbuf,char *outbuf);
 int chain_reply(char *inbuf,char *outbuf,int size,int bufsize);
 void check_reload(int t);
 void smbd_process(void);
-#endif
 
 /*The following definitions come from  smbd/reply.c  */
 
-#if OLD_NTDOMAIN
 int reply_special(char *inbuf,char *outbuf);
 int reply_tcon(connection_struct *conn,
               char *inbuf,char *outbuf, int dum_size, int dum_buffsize);
@@ -3938,11 +4075,9 @@ int reply_writebmpx(connection_struct *conn, char *inbuf,char *outbuf, int size,
 int reply_writebs(connection_struct *conn, char *inbuf,char *outbuf, int dum_size, int dum_buffsize);
 int reply_setattrE(connection_struct *conn, char *inbuf,char *outbuf, int size, int dum_buffsize);
 int reply_getattrE(connection_struct *conn, char *inbuf,char *outbuf, int size, int dum_buffsize);
-#endif
 
 /*The following definitions come from  smbd/sec_ctx.c  */
 
-#if OLD_NTDOMAIN
 int get_current_groups(int *p_ngroups, gid_t **p_groups);
 void delete_nt_token(NT_USER_TOKEN **pptoken);
 NT_USER_TOKEN *dup_nt_token(NT_USER_TOKEN *ptoken);
@@ -3952,26 +4087,21 @@ void set_sec_ctx(uid_t uid, gid_t gid, int ngroups, gid_t *groups, NT_USER_TOKEN
 void set_root_sec_ctx(void);
 BOOL pop_sec_ctx(void);
 void init_sec_ctx(void);
-#endif
 
 /*The following definitions come from  smbd/server.c  */
 
-#if OLD_NTDOMAIN
 int smbd_server_fd(void);
 void smbd_set_server_fd(int fd);
 BOOL reload_services(BOOL test);
 void exit_server(char *reason);
-#endif
 
 /*The following definitions come from  smbd/service.c  */
 
-#if OLD_NTDOMAIN
 BOOL become_service(connection_struct *conn,BOOL do_chdir);
 int add_home_service(char *service, char *homedir);
 int find_service(char *service);
 connection_struct *make_connection(char *service,char *user,char *password, int pwlen, char *dev,uint16 vuid, int *ecode);
 void close_cnum(connection_struct *conn, uint16 vuid);
-#endif
 
 /*The following definitions come from  smbd/srvstr.c  */
 
@@ -4000,7 +4130,6 @@ BOOL reset_stat_cache( void );
 
 /*The following definitions come from  smbd/trans2.c  */
 
-#if OLD_NTDOMAIN
 int reply_findclose(connection_struct *conn,
                    char *inbuf,char *outbuf,int length,int bufsize);
 int reply_findnclose(connection_struct *conn, 
@@ -4009,11 +4138,9 @@ int reply_transs2(connection_struct *conn,
                  char *inbuf,char *outbuf,int length,int bufsize);
 int reply_trans2(connection_struct *conn,
                 char *inbuf,char *outbuf,int length,int bufsize);
-#endif
 
 /*The following definitions come from  smbd/uid.c  */
 
-#if OLD_NTDOMAIN
 BOOL become_guest(void);
 BOOL become_user(connection_struct *conn, uint16 vuid);
 BOOL unbecome_user(void );
@@ -4027,32 +4154,9 @@ DOM_SID *uid_to_sid(DOM_SID *psid, uid_t uid);
 DOM_SID *gid_to_sid(DOM_SID *psid, gid_t gid);
 BOOL sid_to_uid(DOM_SID *psid, uid_t *puid, enum SID_NAME_USE *sidtype);
 BOOL sid_to_gid(DOM_SID *psid, gid_t *pgid, enum SID_NAME_USE *sidtype);
-#endif
-
-/*The following definitions come from  smbd/vfs.c  */
-
-#if OLD_NTDOMAIN
-int vfs_init_default(connection_struct *conn);
-BOOL vfs_init_custom(connection_struct *conn);
-BOOL vfs_directory_exist(connection_struct *conn, char *dname, SMB_STRUCT_STAT *st);
-int vfs_mkdir(connection_struct *conn, char *fname, mode_t mode);
-char *vfs_getwd(connection_struct *conn, char *unix_path);
-BOOL vfs_file_exist(connection_struct *conn,char *fname,SMB_STRUCT_STAT *sbuf);
-ssize_t vfs_read_data(files_struct *fsp, char *buf, size_t byte_count);
-ssize_t vfs_write_data(files_struct *fsp,char *buffer,size_t N);
-int vfs_set_filelen(files_struct *fsp, SMB_OFF_T len);
-SMB_OFF_T vfs_transfer_file(int in_fd, files_struct *in_fsp,
-                           int out_fd, files_struct *out_fsp,
-                           SMB_OFF_T n, char *header, int headlen, int align);
-char *vfs_readdirname(connection_struct *conn, void *p);
-int vfs_ChDir(connection_struct *conn, char *path);
-char *vfs_GetWd(connection_struct *conn, char *path);
-BOOL reduce_name(connection_struct *conn, char *s,char *dir,BOOL widelinks);
-#endif
 
 /*The following definitions come from  smbd/vfs-wrap.c  */
 
-#if OLD_NTDOMAIN
 int vfswrap_dummy_connect(connection_struct *conn, char *service, char *user);
 void vfswrap_dummy_disconnect(connection_struct *conn);
 SMB_BIG_UINT vfswrap_disk_free(connection_struct *conn, char *path, BOOL small_query, SMB_BIG_UINT *bsize, 
@@ -4086,7 +4190,25 @@ BOOL vfswrap_fset_nt_acl(files_struct *fsp, int fd, uint32 security_info_sent, S
 BOOL vfswrap_set_nt_acl(files_struct *fsp, char *name, uint32 security_info_sent, SEC_DESC *psd);
 int vfswrap_chmod_acl(connection_struct *conn, char *name, mode_t mode);
 int vfswrap_fchmod_acl(files_struct *fsp, int fd, mode_t mode);
-#endif
+
+/*The following definitions come from  smbd/vfs.c  */
+
+int vfs_init_default(connection_struct *conn);
+BOOL vfs_init_custom(connection_struct *conn);
+BOOL vfs_directory_exist(connection_struct *conn, char *dname, SMB_STRUCT_STAT *st);
+int vfs_mkdir(connection_struct *conn, char *fname, mode_t mode);
+char *vfs_getwd(connection_struct *conn, char *unix_path);
+BOOL vfs_file_exist(connection_struct *conn,char *fname,SMB_STRUCT_STAT *sbuf);
+ssize_t vfs_read_data(files_struct *fsp, char *buf, size_t byte_count);
+ssize_t vfs_write_data(files_struct *fsp,char *buffer,size_t N);
+int vfs_set_filelen(files_struct *fsp, SMB_OFF_T len);
+SMB_OFF_T vfs_transfer_file(int in_fd, files_struct *in_fsp,
+                           int out_fd, files_struct *out_fsp,
+                           SMB_OFF_T n, char *header, int headlen, int align);
+char *vfs_readdirname(connection_struct *conn, void *p);
+int vfs_ChDir(connection_struct *conn, char *path);
+char *vfs_GetWd(connection_struct *conn, char *path);
+BOOL reduce_name(connection_struct *conn, char *s,char *dir,BOOL widelinks);
 
 /*The following definitions come from  smbwrapper/realcalls.c  */
 
index 210a352cf41a4a2ffe721e5e7ef81408916b6ddb..aa22b1996a8e60cf0a4267412d30dda88dd78f79 100644 (file)
@@ -126,7 +126,6 @@ BOOL do_reg_close(struct cli_state *cli, POLICY_HND *hnd);
 
 /*The following definitions come from  rpc_client/cli_samr.c  */
 
-#if OLD_NTDOMAIN
 BOOL get_samr_query_usergroups(struct cli_state *cli, 
                                POLICY_HND *pol_open_domain, uint32 user_rid,
                                uint32 *num_groups, DOM_GID *gid);
@@ -165,7 +164,6 @@ BOOL do_samr_query_usergroups(struct cli_state *cli,
 BOOL do_samr_query_userinfo(struct cli_state *cli, 
                                POLICY_HND *pol, uint16 switch_value, void* usr);
 BOOL do_samr_close(struct cli_state *cli, POLICY_HND *hnd);
-#endif
 
 /*The following definitions come from  rpc_client/cli_spoolss_notify.c  */
 
index 186f8f1115940a9af46f9554f3f217885f1eae84..ad7fa31365e844d2a4cac8b20dd9523fd5b5b944 100644 (file)
@@ -28,6 +28,7 @@
 
 enum SID_NAME_USE
 {
+       SID_NAME_USE_NONE = 0,/* NOTUSED */
        SID_NAME_USER    = 1, /* user */
        SID_NAME_DOM_GRP = 2, /* domain group */
        SID_NAME_DOMAIN  = 3, /* domain: don't know what this is */
index 3438e44abe25ec1820c859b08ec4d6df2d36a97f..15705a1b6cced59f8812c5d3c66af84922e23260 100644 (file)
 #ifndef _RPC_SAMR_H /* _RPC_SAMR_H */
 #define _RPC_SAMR_H 
 
+
 #include "rpc_misc.h"
 
+
 /*******************************************************************
  the following information comes from a QuickView on samsrv.dll,
  and gives an idea of exactly what is needed:
@@ -142,6 +144,8 @@ SamrTestPrivateFunctionsUser
 #define SAMR_CONNECT           0x39
 #define SAMR_SET_USERINFO      0x3A
 
+
+
 typedef struct logon_hours_info
 {
        uint32 len; /* normally 21 bytes */
@@ -213,8 +217,6 @@ typedef struct sam_user_info_23
 typedef struct sam_user_info_24
 {
        uint8 pass[516];
-       uint16 unk_0;
-
 } SAM_USER_INFO_24;
 
 
@@ -395,7 +397,7 @@ typedef struct q_samr_query_sec_obj_info
 typedef struct r_samr_query_sec_obj_info
 {
        uint32 ptr;
-       SEC_DESC_BUF buf;
+       SEC_DESC_BUF *buf;
 
        uint32 status;         /* return status */
 
@@ -537,15 +539,24 @@ typedef struct r_samr_lookup_domain_info
 
 } SAMR_R_LOOKUP_DOMAIN;
 
+
+/****************************************************************************
+SAMR_Q_OPEN_DOMAIN - unknown_0 values seen associated with SIDs:
+
+0x0000 03f1 and a specific   domain sid - S-1-5-21-44c01ca6-797e5c3d-33f83fd0
+0x0000 0200 and a specific   domain sid - S-1-5-21-44c01ca6-797e5c3d-33f83fd0
+*****************************************************************************/
+
 /* SAMR_Q_OPEN_DOMAIN */
 typedef struct q_samr_open_domain_info
 {
-       POLICY_HND connect_pol;   /* Policy handle */
-       uint32 access_mask;       /* Requested permissions */
-       DOM_SID2 dom_sid;         /* Domain SID */
+       POLICY_HND pol;   /* policy handle */
+       uint32 flags;               /* 0x2000 0000; 0x0000 0211; 0x0000 0280; 0x0000 0200 - flags? */
+       DOM_SID2 dom_sid;         /* domain SID */
 
 } SAMR_Q_OPEN_DOMAIN;
 
+
 /* SAMR_R_OPEN_DOMAIN - probably an open */
 typedef struct r_samr_open_domain_info
 {
@@ -1072,7 +1083,7 @@ typedef struct alias_info_ctr
 typedef struct r_samr_query_aliasinfo_info
 {
        uint32 ptr;        
-       ALIAS_INFO_CTR *ctr;
+       ALIAS_INFO_CTR ctr;
 
        uint32 status;
 
@@ -1083,7 +1094,7 @@ typedef struct r_samr_query_aliasinfo_info
 typedef struct q_samr_set_alias_info
 {
        POLICY_HND alias_pol;        /* policy handle */
-       ALIAS_INFO_CTR *ctr;
+       ALIAS_INFO_CTR ctr;
 
 } SAMR_Q_SET_ALIASINFO;
 
@@ -1449,7 +1460,7 @@ typedef struct q_samr_open_group_info
 /* SAMR_R_OPEN_GROUP - probably an open */
 typedef struct r_samr_open_group_info
 {
-       POLICY_HND group_pol;       /* policy handle */
+       POLICY_HND pol;       /* policy handle */
        uint32 status;         /* return status */
 
 } SAMR_R_OPEN_GROUP;
@@ -1585,6 +1596,7 @@ typedef struct r_samr_get_dom_pwinfo
 {
        uint16 unk_0;
        uint16 unk_1;
+       uint16 unk_2;
        uint32 status;
 
 } SAMR_R_GET_DOM_PWINFO;
index 96961cbd2fc463b70b15687d4759a18661d9b692..b18c70bf258a89663b0b72ccda1fe2aac9a0615f 100644 (file)
@@ -470,6 +470,16 @@ typedef struct r_net_file_enum_info
 
 } SRV_R_NET_FILE_ENUM;
 
+/* SRV_INFO_100 */
+typedef struct srv_info_100_info
+{
+       uint32 platform_id;     /* 0x500 */
+       uint32 ptr_name;        /* pointer to server name */
+
+       UNISTR2 uni_name;       /* server name "server" */
+
+} SRV_INFO_100;
+
 /* SRV_INFO_101 */
 typedef struct srv_info_101_info
 {
@@ -518,6 +528,7 @@ typedef struct srv_info_ctr_info
     {
                SRV_INFO_102 sv102; /* server info level 102 */
                SRV_INFO_101 sv101; /* server info level 101 */
+               SRV_INFO_100 sv100; /* server info level 100 */
 
     } srv;
 
index 1813d63ff77892ae6d2f87b570605177a6c1c35f..7625f529095e9ee04549862a230eeb07b0677a70 100644 (file)
@@ -50,6 +50,21 @@ struct bitmap *bitmap_allocate(int n)
        return bm;
 }
 
+/****************************************************************************
+free a bitmap.
+****************************************************************************/
+
+void bitmap_free(struct bitmap *bm)
+{
+       if (!bm)
+               return;
+
+       if(bm->b)
+               free(bm->b);
+
+       free(bm);
+}
+
 /****************************************************************************
 set a bit in a bitmap
 ****************************************************************************/
index 7fedc282ba9fa5c92ef801c2e65238f3d36195d0..4a3d7090e314df7cd44b994c50c5327d97abfbba 100644 (file)
@@ -19,9 +19,7 @@
    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
 */
-
 #include "includes.h"
-
 #define CTRLZ 26
 extern int DEBUGLEVEL;
 
index 2ba35c00dbba87552965a5ff2485973ad112d8e4..27fa80ca3f82a5a3ad34e34a5299238d49e4a06a 100644 (file)
@@ -234,13 +234,13 @@ void debug_message(int msg_type, pid_t src, void *buf, size_t len)
        /* Set the new DEBUGLEVEL_CLASS array from the pased array */
        memcpy(DEBUGLEVEL_CLASS, buf, sizeof(DEBUGLEVEL_CLASS));
        
-       DEBUG(3,("INFO: Debug class %s level = %d   (pid %d from pid %d)\n",
+       DEBUG(1,("INFO: Debug class %s level = %d   (pid %d from pid %d)\n",
                        classname_table[DBGC_ALL],
                        DEBUGLEVEL_CLASS[DBGC_ALL], getpid(), (int)src));
 
        for (i=1; i<DBGC_LAST; i++) {
                if (DEBUGLEVEL_CLASS[i])
-                        DEBUGADD(3,("INFO: Debug class %s level = %d\n", 
+                        DEBUGADD(1,("INFO: Debug class %s level = %d\n", 
                                                classname_table[i], DEBUGLEVEL_CLASS[i]));
        }
 }
@@ -263,6 +263,11 @@ void setup_logging(char *pname, BOOL interactive)
 {
        message_register(MSG_DEBUG, debug_message);
 
+       /* reset to allow multiple setup calls, going from interactive to
+          non-interactive */
+       stdout_logging = False;
+       dbf = NULL;
+
        if (interactive) {
                stdout_logging = True;
                dbf = stdout;
index 19496bd426b121df9b25a29c3cb37fea610ccbda..ab02d1253bf77331b97c0566f0af1dd5d4e5e28a 100644 (file)
@@ -78,10 +78,7 @@ return current debug level
 ****************************************************************************/
 void debuglevel_message(int msg_type, pid_t src, void *buf, size_t len)
 {
-        int level;
-       
        DEBUG(1,("INFO: Received REQ_DEBUGLEVEL message from PID %d\n",src));
-        level = DEBUGLEVEL;
        message_send_pid(src, MSG_DEBUGLEVEL, DEBUGLEVEL_CLASS, sizeof(DEBUGLEVEL_CLASS), True);
 }
 
index 90fac637b3bef5eb286212edd8213d19067eee31..3451b6ec591d32e07a341f17d3b8f8aa7e21ef3d 100644 (file)
@@ -1,5 +1,3 @@
-#define OLD_NTDOMAIN 1
-
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -327,6 +325,3 @@ void msrpc_net_use_enum(uint32 *num_cons, struct use_info ***use)
                add_use_info_to_array(num_cons, use, &item);
        }
 }
-
-
-#undef OLD_NTDOMAIN
index ed7113c8652d28be9a79af91af53dcba08977b2f..be81b4aa120edf6d5a78b00e34fa07b1e70a9c7e 100644 (file)
@@ -78,7 +78,6 @@ va_dcl
        char *format;
 #endif
        va_list ap;  
-       int ret;
        pstring str;
 
 #ifdef HAVE_STDARG_H
@@ -90,7 +89,7 @@ va_dcl
 #endif
        str[0] = 0;
 
-       ret = vslprintf(str,sizeof(str),format,ap);
+       vslprintf(str,sizeof(str),format,ap);
        va_end(ap);
        return write(fd, str, strlen(str));
 }
index 8ad2cfd713f8cda8b5cd3bcf62c79e569aa15f92..3811d81866fd1c4fafbcef07504224e4a5a358e7 100644 (file)
@@ -359,7 +359,7 @@ void set_message_bcc(char *buf,int num_bytes)
 ********************************************************************/
 void set_message_end(void *outbuf,void *end_ptr)
 {
-       set_message_bcc(outbuf,PTR_DIFF(end_ptr,smb_buf(outbuf)));
+       set_message_bcc((char *)outbuf,PTR_DIFF(end_ptr,smb_buf((char *)outbuf)));
 }
 
 /*******************************************************************
index d4540b15c5d0137f58134d47a922d08c5870dc7f..cf11110bd3230bf3435c2b687a9e7b11b03ec039 100644 (file)
@@ -1,4 +1,3 @@
-#define NEW_NTDOMAIN 1
 /* 
    Unix SMB/Netbios implementation.
    Version 2.2
@@ -519,5 +518,3 @@ uint32 cli_samr_query_groupmem(struct cli_state *cli, POLICY_HND *group_pol,
 
        return result;
 }
-
-#undef NEW_NTDOMAIN
index 5c3dae02c02bbda2f696ef7591db27feffc6b7da..175ab5c9b0a62b2ce78207080420db5fc21625df 100644 (file)
@@ -118,13 +118,11 @@ delete a record if it is for a dead process
 static int delete_fn(TDB_CONTEXT *ttdb, TDB_DATA kbuf, TDB_DATA dbuf, void *state)
 {
        struct lock_struct *locks;
-       struct lock_key *key;
        int count, i;
 
        tdb_chainlock(tdb, kbuf);
 
        locks = (struct lock_struct *)dbuf.dptr;
-       key = (struct lock_key *)kbuf.dptr;
 
        count = dbuf.dsize / sizeof(*locks);
        for (i=0; i<count; i++) {
index b3601e8752d0f096e8094be5f5add133b47369bf..118d59cc10c1115b9f5e3bb19326d058b8059c40 100644 (file)
@@ -396,7 +396,6 @@ BOOL set_share_mode(files_struct *fsp, uint16 port, uint16 op_type)
 {
        TDB_DATA dbuf;
        struct locking_data *data;
-       share_mode_entry *shares;
        char *p=NULL;
        int size;
                
@@ -410,12 +409,11 @@ BOOL set_share_mode(files_struct *fsp, uint16 port, uint16 op_type)
                pstrcat(fname, "/");
                pstrcat(fname, fsp->fsp_name);
 
-               size = sizeof(*data) + sizeof(*shares) + strlen(fname) + 1;
+               size = sizeof(*data) + sizeof(share_mode_entry) + strlen(fname) + 1;
                p = (char *)malloc(size);
                data = (struct locking_data *)p;
-               shares = (share_mode_entry *)(p + sizeof(*data));
                data->num_share_mode_entries = 1;
-               pstrcpy(p + sizeof(*data) + sizeof(*shares), fname);
+               pstrcpy(p + sizeof(*data) + sizeof(share_mode_entry), fname);
                fill_share_mode(p + sizeof(*data), fsp, port, op_type);
                dbuf.dptr = p;
                dbuf.dsize = size;
@@ -426,14 +424,13 @@ BOOL set_share_mode(files_struct *fsp, uint16 port, uint16 op_type)
 
        /* we're adding to an existing entry - this is a bit fiddly */
        data = (struct locking_data *)dbuf.dptr;
-       shares = (share_mode_entry *)(dbuf.dptr + sizeof(*data));
 
        data->num_share_mode_entries++;
-       size = dbuf.dsize + sizeof(*shares);
+       size = dbuf.dsize + sizeof(share_mode_entry);
        p = malloc(size);
        memcpy(p, dbuf.dptr, sizeof(*data));
        fill_share_mode(p + sizeof(*data), fsp, port, op_type);
-       memcpy(p + sizeof(*data) + sizeof(*shares), dbuf.dptr + sizeof(*data),
+       memcpy(p + sizeof(*data) + sizeof(share_mode_entry), dbuf.dptr + sizeof(*data),
               dbuf.dsize - sizeof(*data));
        free(dbuf.dptr);
        dbuf.dptr = p;
index 428dd004eee8c5db5ac1a79a0abdd6f6388efa8d..949f4b0498cbfd66111ad34ccca75c0cd1678186 100644 (file)
@@ -1687,8 +1687,3 @@ BOOL pdb_set_lanman_passwd (SAM_ACCOUNT *sampass, BYTE *pwd)
 
        return True;
 }
-
-
-
-
-
index 275ffa21edc66b1786faeb86fc4006b6e4f3c47b..c4fc3377c3f703ca443a66d2731fb316cce97e66 100644 (file)
@@ -48,9 +48,9 @@ static void add_auto_printers(void)
        printers = lp_servicenumber(PRINTERS_NAME);
 
        if (printers < 0) {
-               free(str);
-               return;
-       }
+        free(str);
+        return;
+    }
        
        for (p=strtok(str,LIST_SEP);p;p=strtok(NULL,LIST_SEP)) {
                if (lp_servicenumber(p) >= 0) continue;
@@ -60,7 +60,7 @@ static void add_auto_printers(void)
                }
        }
 
-       free(str);
+    free(str);
 }
 
 /***************************************************************************
index e491d9a6b9933c114f988acc10b162c4c6a8ab08..f5c4a234ee21d3daf18650e87cf8457dfefae634 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /*
  *  Unix SMB/Netbios implementation.
  *  Version 1.9.
@@ -1089,7 +1088,6 @@ BOOL move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract,
        struct passwd *pass;
        int ecode;
        int ver = 0;
-       int outsize = 0;
        int i;
 
        *perr = 0;
@@ -1175,7 +1173,7 @@ BOOL move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract,
                slprintf(new_name, sizeof(new_name), "%s/%s", architecture, driver->driverpath);        
                slprintf(old_name, sizeof(old_name), "%s/%s", new_dir, driver->driverpath);     
                if (ver != -1 && (ver=file_version_is_newer(conn, new_name, old_name)) > 0) {
-                       if ((outsize = rename_internals(conn, inbuf, outbuf, new_name, old_name, True)) != 0) {
+                       if (rename_internals(conn, inbuf, outbuf, new_name, old_name, True) != 0) {
                                DEBUG(0,("move_driver_to_download_area: Unable to rename [%s] to [%s]\n",
                                                new_name, old_name));
                                *perr = (uint32)SVAL(outbuf,smb_err);
@@ -1192,7 +1190,7 @@ BOOL move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract,
                        slprintf(new_name, sizeof(new_name), "%s/%s", architecture, driver->datafile);  
                        slprintf(old_name, sizeof(old_name), "%s/%s", new_dir, driver->datafile);       
                        if (ver != -1 && (ver=file_version_is_newer(conn, new_name, old_name)) > 0) {
-                               if ((outsize = rename_internals(conn, inbuf, outbuf, new_name, old_name, True)) != 0) {
+                               if (rename_internals(conn, inbuf, outbuf, new_name, old_name, True) != 0) {
                                        DEBUG(0,("move_driver_to_download_area: Unable to rename [%s] to [%s]\n",
                                                        new_name, old_name));
                                        *perr = (uint32)SVAL(outbuf,smb_err);
@@ -1211,7 +1209,7 @@ BOOL move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract,
                        slprintf(new_name, sizeof(new_name), "%s/%s", architecture, driver->configfile);        
                        slprintf(old_name, sizeof(old_name), "%s/%s", new_dir, driver->configfile);     
                        if (ver != -1 && (ver=file_version_is_newer(conn, new_name, old_name)) > 0) {
-                               if ((outsize = rename_internals(conn, inbuf, outbuf, new_name, old_name, True)) != 0) {
+                               if (rename_internals(conn, inbuf, outbuf, new_name, old_name, True) != 0) {
                                        DEBUG(0,("move_driver_to_download_area: Unable to rename [%s] to [%s]\n",
                                                        new_name, old_name));
                                        *perr = (uint32)SVAL(outbuf,smb_err);
@@ -1231,7 +1229,7 @@ BOOL move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract,
                        slprintf(new_name, sizeof(new_name), "%s/%s", architecture, driver->helpfile);  
                        slprintf(old_name, sizeof(old_name), "%s/%s", new_dir, driver->helpfile);       
                        if (ver != -1 && (ver=file_version_is_newer(conn, new_name, old_name)) > 0) {
-                               if ((outsize = rename_internals(conn, inbuf, outbuf, new_name, old_name, True)) != 0) {
+                               if (rename_internals(conn, inbuf, outbuf, new_name, old_name, True) != 0) {
                                        DEBUG(0,("move_driver_to_download_area: Unable to rename [%s] to [%s]\n",
                                                        new_name, old_name));
                                        *perr = (uint32)SVAL(outbuf,smb_err);
@@ -1260,7 +1258,7 @@ BOOL move_driver_to_download_area(NT_PRINTER_DRIVER_INFO_LEVEL driver_abstract,
                                slprintf(new_name, sizeof(new_name), "%s/%s", architecture, driver->dependentfiles[i]); 
                                slprintf(old_name, sizeof(old_name), "%s/%s", new_dir, driver->dependentfiles[i]);      
                                if (ver != -1 && (ver=file_version_is_newer(conn, new_name, old_name)) > 0) {
-                                       if ((outsize = rename_internals(conn, inbuf, outbuf, new_name, old_name, True)) != 0) {
+                                       if (rename_internals(conn, inbuf, outbuf, new_name, old_name, True) != 0) {
                                                DEBUG(0,("move_driver_to_download_area: Unable to rename [%s] to [%s]\n",
                                                                new_name, old_name));
                                                *perr = (uint32)SVAL(outbuf,smb_err);
@@ -3195,4 +3193,3 @@ uint32 printer_write_default_dev(int snum, const PRINTER_DEFAULT *printer_defaul
        free_a_printer(&printer, 2);
        return result;
 }
-#undef OLD_NTDOMAIN
index c87fb9754f285580b97f92f475b432b1edcc5581..efb97be91943b7271fa350556e9c17f09685aa57 100644 (file)
@@ -1,5 +1,3 @@
-#define OLD_NTDOMAIN 1
-
 /* 
    Unix SMB/Netbios implementation.
    Version 3.0
@@ -98,5 +96,3 @@ void print_fsp_end(files_struct *fsp, BOOL normal_close)
                string_free(&fsp->fsp_name);
        }
 }
-
-#undef OLD_NTDOMAIN
index e771e936002c5ecfe025ed9af910924f562aba38..241135f744616e7d2ffb6debbf74d9fcd2d8fa6b 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
    Unix SMB/Netbios implementation.
    Version 3.0
@@ -792,14 +791,12 @@ BOOL print_job_resume(struct current_user *user, int jobid, int *errcode)
        char *printer_name;
        int snum, ret;
        fstring jobstr;
-       BOOL owner;
        
        if (!pjob || !user) return False;
 
        if (!pjob->spooled || pjob->sysjob == -1) return False;
 
        snum = print_job_snum(jobid);
-       owner = is_owner(user, jobid);
 
        if (!is_owner(user, jobid) &&
            !print_access_check(user, snum, JOB_ACCESS_ADMINISTER)) {
@@ -1401,4 +1398,3 @@ BOOL print_queue_purge(struct current_user *user, int snum, int *errcode)
 
        return True;
 }
-#undef OLD_NTDOMAIN
index eb9032f7ce7282cde1d049e7682982d4154784a7..a0e9ab6a0037d6d126944893223f924355d712e4 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -63,6 +62,9 @@ BOOL get_samr_query_usergroups(struct cli_state *cli,
        return do_samr_close(cli, &pol_open_user);
 }
 
+#if 0
+/* DOES NOT COMPILE WITH THE NEW SAMR PARSE CODE. JRA. */
+
 /****************************************************************************
 do a SAMR query user info
 ****************************************************************************/
@@ -97,6 +99,7 @@ BOOL get_samr_query_userinfo(struct cli_state *cli,
 
        return do_samr_close(cli, &pol_open_user);
 }
+#endif
 
 /****************************************************************************
 do a SAMR change user password command
@@ -156,6 +159,10 @@ BOOL do_samr_chgpasswd_user(struct cli_state *cli,
        return True;
 }
 
+#if 0 
+
+/* CURRENTLY THIS DOESN'T COMPILE AND IS NOT USED ANYWHERE. JRA. */
+
 /****************************************************************************
 do a SAMR unknown 0x38 command
 ****************************************************************************/
@@ -208,6 +215,7 @@ BOOL do_samr_unknown_38(struct cli_state *cli, char *srv_name)
 
        return True;
 }
+#endif
 
 /****************************************************************************
 do a SAMR unknown 0x8 command
@@ -266,6 +274,10 @@ BOOL do_samr_query_dom_info(struct cli_state *cli,
        return True;
 }
 
+#if 0
+
+/* CURRENTLY DOESN'T COMPILE WITH THE NEW SAMR PARSE CODE. JRA */
+
 /****************************************************************************
 do a SAMR enumerate users
 ****************************************************************************/
@@ -356,6 +368,7 @@ BOOL do_samr_enum_dom_users(struct cli_state *cli,
 
        return True;
 }
+#endif
 
 /****************************************************************************
 do a SAMR Connect
@@ -541,6 +554,10 @@ BOOL do_samr_open_domain(struct cli_state *cli,
        return True;
 }
 
+#if 0
+
+/* CURRENTLY DOES NOT COMPILE AND IS NOT USED ANYWHERE. JRA. */
+
 /****************************************************************************
 do a SAMR Query Unknown 12
 ****************************************************************************/
@@ -621,6 +638,7 @@ BOOL do_samr_query_unknown_12(struct cli_state *cli,
 
        return True;
 }
+#endif
 
 /****************************************************************************
 do a SAMR Query User Groups
@@ -684,6 +702,10 @@ BOOL do_samr_query_usergroups(struct cli_state *cli,
        return True;
 }
 
+#if 0
+
+/* CURRENTLY DOES NOT COMPILE WITH THE NEW SAMR PARSE CODE. JRA */
+
 /****************************************************************************
 do a SAMR Query User Info
 ****************************************************************************/
@@ -756,6 +778,8 @@ BOOL do_samr_query_userinfo(struct cli_state *cli,
        return True;
 }
 
+#endif
+
 /****************************************************************************
 do a SAMR Close
 ****************************************************************************/
@@ -820,5 +844,3 @@ BOOL do_samr_close(struct cli_state *cli, POLICY_HND *hnd)
 
        return True;
 }
-
-#undef OLD_NTDOMAIN
index e1d88ab5093d161a962bc3a578c8aeb2fa3b4e96..6bae2ae4a6b895a9412f6f6cb93a41fdee9f446d 100644 (file)
@@ -411,7 +411,7 @@ BOOL dfs_io_dfs_info_ctr(char* desc, DFS_INFO_CTR* ctr, uint32 num_entries, uint
                                return False;
                        if(!prs_uint32("ptr_comment", ps, depth, &ctr->dfs.info3[i].ptr_comment))
                                return False;
-                       if(!prs_uint32("state", ps, depth, &ctr->dfs.info3[i].state));
+                       if(!prs_uint32("state", ps, depth, &ctr->dfs.info3[i].state))
                                return False;
                        if(!prs_uint32("num_storages", ps, depth, &ctr->dfs.info3[i].num_storages))
                                return False;
index d86df0ee113e96ca2cd7cb8784c0066af9fadce3..98ef3fd0ee3232389b26bbec2e30a1991d51e8e3 100644 (file)
@@ -591,17 +591,16 @@ BOOL lsa_io_r_enum_trust_dom(char *desc, LSA_R_ENUM_TRUST_DOM *r_e,
 
                num_domains = r_e->num_domains2;
 
-               if (!(r_e->hdr_domain_name = (UNIHDR2 *)
-                     malloc(sizeof(UNIHDR2) * num_domains)))
-                       return False;
+               if (UNMARSHALLING(ps)) {
+                       if (!(r_e->hdr_domain_name = (UNIHDR2 *)prs_alloc_mem(ps,sizeof(UNIHDR2) * num_domains)))
+                               return False;
 
-               if (!(r_e->uni_domain_name = (UNISTR2 *)
-                     malloc(sizeof(UNISTR2) * num_domains)))
-                       return False;
+                       if (!(r_e->uni_domain_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2) * num_domains)))
+                               return False;
 
-               if (!(r_e->domain_sid = (DOM_SID2 *)
-                     malloc(sizeof(DOM_SID2) * num_domains)))
-                       return False;
+                       if (!(r_e->domain_sid = (DOM_SID2 *)prs_alloc_mem(ps,sizeof(DOM_SID2) * num_domains)))
+                               return False;
+               }
 
                for (i = 0; i < num_domains; i++) {
                        if(!smb_io_unihdr2 ("", &r_e->hdr_domain_name[i], ps, 
index bde8c01240e3d6a260a929b2893145aa9907e491..f1ff965df24d96a74cd4af6538ae7e89ff56d691 100644 (file)
@@ -627,7 +627,7 @@ BOOL net_io_r_srv_pwset(char *desc, NET_R_SRV_PWSET *r_s, prs_struct *ps, int de
  Init DOM_SID2 array from a string containing multiple sids
  *************************************************************************/
 
-static int init_dom_sid2s(char *sids_str, DOM_SID2 **ppsids)
+static int init_dom_sid2s(TALLOC_CTX *ctx, char *sids_str, DOM_SID2 **ppsids)
 {
        char *ptr;
        pstring s2;
@@ -647,7 +647,7 @@ static int init_dom_sid2s(char *sids_str, DOM_SID2 **ppsids)
                        ;
 
                /* Now allocate space for them. */
-               *ppsids = (DOM_SID2 *)malloc(count * sizeof(DOM_SID2));
+               *ppsids = (DOM_SID2 *)talloc_zero(ctx, count * sizeof(DOM_SID2));
                if (*ppsids == NULL)
                        return 0;
 
@@ -936,14 +936,22 @@ void init_sam_info(DOM_SAM_INFO *sam,
  Reads or writes a DOM_SAM_INFO structure.
 ********************************************************************/
 
-static BOOL net_io_id_info_ctr(char *desc, NET_ID_INFO_CTR *ctr, prs_struct *ps, int depth)
+static BOOL net_io_id_info_ctr(char *desc, NET_ID_INFO_CTR **pp_ctr, prs_struct *ps, int depth)
 {
-       if (ctr == NULL)
-               return False;
+       NET_ID_INFO_CTR *ctr = *pp_ctr;
 
        prs_debug(ps, depth, desc, "smb_io_sam_info");
        depth++;
 
+       if (UNMARSHALLING(ps)) {
+               ctr = *pp_ctr = (NET_ID_INFO_CTR *)prs_alloc_mem(ps, sizeof(NET_ID_INFO_CTR));
+               if (ctr == NULL)
+                       return False;
+       }
+       
+       if (ctr == NULL)
+               return False;
+
        /* don't 4-byte align here! */
 
        if(!prs_uint16("switch_value ", ps, depth, &ctr->switch_value))
@@ -993,8 +1001,8 @@ static BOOL smb_io_sam_info(char *desc, DOM_SAM_INFO *sam, prs_struct *ps, int d
        if(!prs_uint16("logon_level  ", ps, depth, &sam->logon_level))
                return False;
 
-       if (sam->logon_level != 0 && sam->ctr != NULL) {
-               if(!net_io_id_info_ctr("logon_info", sam->ctr, ps, depth))
+       if (sam->logon_level != 0) {
+               if(!net_io_id_info_ctr("logon_info", &sam->ctr, ps, depth))
                        return False;
        }
 
@@ -1005,7 +1013,7 @@ static BOOL smb_io_sam_info(char *desc, DOM_SAM_INFO *sam, prs_struct *ps, int d
  Init
  *************************************************************************/
 
-void init_net_user_info3(NET_USER_INFO_3 *usr, SAM_ACCOUNT *sampw,
+void init_net_user_info3(TALLOC_CTX *ctx, NET_USER_INFO_3 *usr, SAM_ACCOUNT *sampw,
                         uint16 logon_count, uint16 bad_pw_count,
                         uint32 num_groups, DOM_GID *gids,
                         uint32 user_flgs, char *sess_key,
@@ -1090,7 +1098,7 @@ void init_net_user_info3(NET_USER_INFO_3 *usr, SAM_ACCOUNT *sampw,
 
        memset((char *)usr->padding, '\0', sizeof(usr->padding));
 
-       num_other_sids = init_dom_sid2s(other_sids, &usr->other_sids);
+       num_other_sids = init_dom_sid2s(ctx, other_sids, &usr->other_sids);
 
        usr->num_other_sids = num_other_sids;
        usr->buffer_other_sids = (num_other_sids != 0) ? 1 : 0; 
@@ -1105,7 +1113,7 @@ void init_net_user_info3(NET_USER_INFO_3 *usr, SAM_ACCOUNT *sampw,
        usr->num_groups2 = num_groups;
 
        if (num_groups > 0) {
-               usr->gids = (DOM_GID *)malloc(sizeof(DOM_GID) * num_groups);
+               usr->gids = (DOM_GID *)talloc_zero(ctx,sizeof(DOM_GID) * num_groups);
                if (usr->gids == NULL)
                        return;
                for (i = 0; i < num_groups; i++)
@@ -1119,16 +1127,6 @@ void init_net_user_info3(NET_USER_INFO_3 *usr, SAM_ACCOUNT *sampw,
        /* "other" sids are set up above */
 }
 
-/*******************************************************************
- Delete any memory allocated by init_user_info_3...
-********************************************************************/
-
-void free_user_info3(NET_USER_INFO_3 *usr)
-{
-       safe_free(usr->gids);
-       safe_free(usr->other_sids);
-}
-
 /*******************************************************************
  This code has been modified to cope with a NET_USER_INFO_2 - which is
  exactly the same as a NET_USER_INFO_3, minus the other sids parameters.
index 462c9ed19900b9e9693e8d8ce44ceb2905ae0888..5cfa84ff3dc92c3df855a55d9fec605fe13660a2 100644 (file)
@@ -1,11 +1,12 @@
-#define OLD_NTDOMAIN 1
 /* 
  *  Unix SMB/Netbios implementation.
  *  Version 1.9.
  *  RPC Pipe client / server routines
- *  Copyright (C) Andrew Tridgell              1992-1997,
- *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
- *  Copyright (C) Paul Ashton                       1997.
+ *  Copyright (C) Andrew Tridgell              1992-2000,
+ *  Copyright (C) Luke Kenneth Casson Leighton 1996-2000,
+ *  Copyright (C) Paul Ashton                  1997-2000,
+ *  Copyright (C) Elrond                            2000,
+ *  Copyright (C) Jeremy Allison                    2001
  *  
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+
 #include "includes.h"
+#include "rpc_parse.h"
+#include "rpc_client.h"
+#include "nterr.h"
 
 extern int DEBUGLEVEL;
 
 /*******************************************************************
- Inits a SAMR_Q_CLOSE_HND structure.
+inits a SAMR_Q_CLOSE_HND structure.
 ********************************************************************/
 
-void init_samr_q_close_hnd(SAMR_Q_CLOSE_HND *q_c, POLICY_HND *hnd)
+void init_samr_q_close_hnd(SAMR_Q_CLOSE_HND * q_c, POLICY_HND *hnd)
 {
-       DEBUG(5,("init_samr_q_close_hnd\n"));
-
-       memcpy(&q_c->pol, hnd, sizeof(q_c->pol));
+       DEBUG(5, ("init_samr_q_close_hnd\n"));
+       
+       q_c->pol = *hnd;
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_q_close_hnd(char *desc,  SAMR_Q_CLOSE_HND *q_u, prs_struct *ps, int depth)
+BOOL samr_io_q_close_hnd(char *desc, SAMR_Q_CLOSE_HND * q_u,
+                        prs_struct *ps, int depth)
 {
        if (q_u == NULL)
                return False;
@@ -52,19 +58,15 @@ BOOL samr_io_q_close_hnd(char *desc,  SAMR_Q_CLOSE_HND *q_u, prs_struct *ps, int
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
-               return False;
-       if(!prs_align(ps))
-               return False;
-
-       return True;
+       return smb_io_pol_hnd("pol", &q_u->pol, ps, depth);
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_r_close_hnd(char *desc,  SAMR_R_CLOSE_HND *r_u, prs_struct *ps, int depth)
+BOOL samr_io_r_close_hnd(char *desc, SAMR_R_CLOSE_HND * r_u,
+                        prs_struct *ps, int depth)
 {
        if (r_u == NULL)
                return False;
@@ -77,8 +79,6 @@ BOOL samr_io_r_close_hnd(char *desc,  SAMR_R_CLOSE_HND *r_u, prs_struct *ps, int
 
        if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
                return False;
-       if(!prs_align(ps))
-               return False;
 
        if(!prs_uint32("status", ps, depth, &r_u->status))
                return False;
@@ -86,74 +86,93 @@ BOOL samr_io_r_close_hnd(char *desc,  SAMR_R_CLOSE_HND *r_u, prs_struct *ps, int
        return True;
 }
 
-
 /*******************************************************************
- Reads or writes a structure.
+inits a SAMR_Q_LOOKUP_DOMAIN structure.
 ********************************************************************/
 
-void init_samr_q_open_domain(SAMR_Q_OPEN_DOMAIN *q_u, 
-                            POLICY_HND *connect_pol, 
-                            uint32 access_mask, DOM_SID *sid)
+void init_samr_q_lookup_domain(SAMR_Q_LOOKUP_DOMAIN * q_u,
+                              POLICY_HND *pol, char *dom_name)
 {
-       DEBUG(5,("samr_init_q_open_domain\n"));
+       int len_name = strlen(dom_name);
 
-       q_u->pol = *connect_pol;
-       q_u->access_mask = access_mask;
-       init_dom_sid2(&q_u->dom_sid, sid);
+       DEBUG(5, ("init_samr_q_lookup_domain\n"));
+
+       q_u->connect_pol = *pol;
+
+       init_uni_hdr(&q_u->hdr_domain, len_name);
+       init_unistr2(&q_u->uni_domain, dom_name, len_name);
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
-
-BOOL samr_io_q_open_domain(char *desc, SAMR_Q_OPEN_DOMAIN *q_u, prs_struct *ps, int depth)
+BOOL samr_io_q_lookup_domain(char *desc, SAMR_Q_LOOKUP_DOMAIN * q_u,
+                            prs_struct *ps, int depth)
 {
        if (q_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_q_open_domain");
+       prs_debug(ps, depth, desc, "samr_io_q_lookup_domain");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
-               return False;
-       if(!prs_align(ps))
+       if(!smb_io_pol_hnd("connect_pol", &q_u->connect_pol, ps, depth))
                return False;
 
-       if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
+       if(!smb_io_unihdr("hdr_domain", &q_u->hdr_domain, ps, depth))
                return False;
 
-       if(!smb_io_dom_sid2("sid", &q_u->dom_sid, ps, depth))
-               return False;
-       if(!prs_align(ps))
+       if(!smb_io_unistr2("uni_domain", &q_u->uni_domain, q_u->hdr_domain.buffer, ps, depth))
                return False;
 
        return True;
 }
 
+/*******************************************************************
+inits a SAMR_R_LOOKUP_DOMAIN structure.
+********************************************************************/
+
+void init_samr_r_lookup_domain(SAMR_R_LOOKUP_DOMAIN * r_u,
+                              DOM_SID *dom_sid, uint32 status)
+{
+       DEBUG(5, ("init_samr_r_lookup_domain\n"));
+
+       r_u->status = status;
+       r_u->ptr_sid = 0;
+       if (status == 0x0) {
+               r_u->ptr_sid = 1;
+               init_dom_sid2(&r_u->dom_sid, dom_sid);
+       }
+}
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_r_open_domain(char *desc, SAMR_R_OPEN_DOMAIN *r_u, prs_struct *ps, int depth)
+BOOL samr_io_r_lookup_domain(char *desc, SAMR_R_LOOKUP_DOMAIN * r_u,
+                            prs_struct *ps, int depth)
 {
        if (r_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_r_open_domain");
+       prs_debug(ps, depth, desc, "samr_io_r_lookup_domain");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_pol_hnd("domain_pol", &r_u->domain_pol, ps, depth))
-               return False;
-       if(!prs_align(ps))
+       if(!prs_uint32("ptr", ps, depth, &r_u->ptr_sid))
                return False;
 
+       if (r_u->ptr_sid != 0) {
+               if(!smb_io_dom_sid2("sid", &r_u->dom_sid, ps, depth))
+                       return False;
+               if(!prs_align(ps))
+                       return False;
+       }
+
        if(!prs_uint32("status", ps, depth, &r_u->status))
                return False;
 
@@ -161,34 +180,39 @@ BOOL samr_io_r_open_domain(char *desc, SAMR_R_OPEN_DOMAIN *r_u, prs_struct *ps,
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-void init_samr_q_unknown_2c(SAMR_Q_UNKNOWN_2C *q_u, POLICY_HND *user_pol)
+void init_samr_q_unknown_2d(SAMR_Q_UNKNOWN_2D * q_u, POLICY_HND *dom_pol, DOM_SID *sid)
 {
-       DEBUG(5,("samr_init_q_unknown_2c\n"));
+       DEBUG(5, ("samr_init_samr_q_unknown_2d\n"));
 
-       memcpy(&q_u->user_pol, user_pol, sizeof(q_u->user_pol));
+       q_u->dom_pol = *dom_pol;
+       init_dom_sid2(&q_u->sid, sid);
 }
 
-
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_q_unknown_2c(char *desc,  SAMR_Q_UNKNOWN_2C *q_u, prs_struct *ps, int depth)
+BOOL samr_io_q_unknown_2d(char *desc, SAMR_Q_UNKNOWN_2D * q_u,
+                         prs_struct *ps, int depth)
 {
        if (q_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_q_unknown_2c");
+       prs_debug(ps, depth, desc, "samr_io_q_unknown_2d");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_pol_hnd("user_pol", &q_u->user_pol, ps, depth))
+       if(!smb_io_pol_hnd("domain_pol", &q_u->dom_pol, ps, depth))
+               return False;
+
+       if(!smb_io_dom_sid2("sid", &q_u->sid, ps, depth))
                return False;
+
        if(!prs_align(ps))
                return False;
 
@@ -196,282 +220,263 @@ BOOL samr_io_q_unknown_2c(char *desc,  SAMR_Q_UNKNOWN_2C *q_u, prs_struct *ps, i
 }
 
 /*******************************************************************
- Inits a structure.
-********************************************************************/
-
-void init_samr_r_unknown_2c(SAMR_R_UNKNOWN_2C *q_u, uint32 status)
-{
-       DEBUG(5,("samr_init_r_unknown_2c\n"));
-
-       q_u->unknown_0 = 0x00160000;
-       q_u->unknown_1 = 0x00000000;
-       q_u->status    = status;
-}
-
-
-/*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_r_unknown_2c(char *desc,  SAMR_R_UNKNOWN_2C *r_u, prs_struct *ps, int depth)
+BOOL samr_io_r_unknown_2d(char *desc, SAMR_R_UNKNOWN_2D * r_u,
+                         prs_struct *ps, int depth)
 {
        if (r_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_r_unknown_2c");
+       prs_debug(ps, depth, desc, "samr_io_r_unknown_2d");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("unknown_0", ps, depth, &r_u->unknown_0))
-               return False;
-       if(!prs_uint32("unknown_1", ps, depth, &r_u->unknown_1))
-               return False;
-       if(!prs_uint32("status   ", ps, depth, &r_u->status))
+       if(!prs_uint32("status", ps, depth, &r_u->status))
                return False;
 
        return True;
 }
 
 /*******************************************************************
- Inits a SAMR_Q_UNKNOWN_3 structure.
+reads or writes a structure.
 ********************************************************************/
 
-void init_samr_q_unknown_3(SAMR_Q_UNKNOWN_3 *q_u,
-                               POLICY_HND *user_pol, uint16 switch_value)
+void init_samr_q_open_domain(SAMR_Q_OPEN_DOMAIN * q_u,
+                            POLICY_HND *pol, uint32 flags,
+                            DOM_SID *sid)
 {
-       DEBUG(5,("samr_init_q_unknown_3\n"));
+       DEBUG(5, ("samr_init_samr_q_open_domain\n"));
 
-       memcpy(&q_u->user_pol, user_pol, sizeof(q_u->user_pol));
-       q_u->switch_value = switch_value;
+       q_u->pol = *pol;
+       q_u->flags = flags;
+       init_dom_sid2(&q_u->dom_sid, sid);
 }
 
-
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_q_unknown_3(char *desc,  SAMR_Q_UNKNOWN_3 *q_u, prs_struct *ps, int depth)
+BOOL samr_io_q_open_domain(char *desc, SAMR_Q_OPEN_DOMAIN * q_u,
+                          prs_struct *ps, int depth)
 {
        if (q_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_q_unknown_3");
+       prs_debug(ps, depth, desc, "samr_io_q_open_domain");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_pol_hnd("user_pol", &q_u->user_pol, ps, depth))
+       if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
                return False;
 
-       if(!prs_align(ps))
+       if(!prs_uint32("flags", ps, depth, &q_u->flags))
                return False;
 
-       if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
+       if(!smb_io_dom_sid2("sid", &q_u->dom_sid, ps, depth))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_r_open_domain(char *desc, SAMR_R_OPEN_DOMAIN * r_u,
+                          prs_struct *ps, int depth)
+{
+       if (r_u == NULL)
                return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_open_domain");
+       depth++;
+
        if(!prs_align(ps))
                return False;
 
+       if(!smb_io_pol_hnd("domain_pol", &r_u->domain_pol, ps, depth))
+               return False;
+
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
        return True;
 }
 
 /*******************************************************************
- Inits a SAMR_Q_QUERY_DOMAIN_INFO structure.
+reads or writes a structure.
 ********************************************************************/
 
-void init_samr_q_query_dom_info(SAMR_Q_QUERY_DOMAIN_INFO *q_u,
-                               POLICY_HND *domain_pol, uint16 switch_value)
+void init_samr_q_get_usrdom_pwinfo(SAMR_Q_GET_USRDOM_PWINFO * q_u,
+                                  POLICY_HND *user_pol)
 {
-       DEBUG(5,("init_samr_q_query_dom_info\n"));
+       DEBUG(5, ("samr_init_samr_q_get_usrdom_pwinfo\n"));
 
-       memcpy(&q_u->domain_pol, domain_pol, sizeof(q_u->domain_pol));
-       q_u->switch_value = switch_value;
+       q_u->user_pol = *user_pol;
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_q_query_dom_info(char *desc,  SAMR_Q_QUERY_DOMAIN_INFO *q_u, prs_struct *ps, int depth)
+BOOL samr_io_q_get_usrdom_pwinfo(char *desc, SAMR_Q_GET_USRDOM_PWINFO * q_u,
+                                prs_struct *ps, int depth)
 {
        if (q_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_q_query_dom_info");
+       prs_debug(ps, depth, desc, "samr_io_q_get_usrdom_pwinfo");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
-               return False;
-       if(!prs_align(ps))
-               return False;
-
-       if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
-               return False;
-
-       return True;
+       return smb_io_pol_hnd("user_pol", &q_u->user_pol, ps, depth);
 }
 
 /*******************************************************************
-Inits a structure.
+ Init.
 ********************************************************************/
-BOOL init_unk_info1(SAM_UNK_INFO_1 *u_1)
-{
-       if (u_1 == NULL)
-               return False;
 
-       memset(u_1->padding, 0, sizeof(u_1->padding));  /* 12 bytes zeros */
-       u_1->unknown_1 = 0x80000000;
-       u_1->unknown_2 = 0x00000000;
+void init_samr_r_get_usrdom_pwinfo(SAMR_R_GET_USRDOM_PWINFO *r_u, uint32 status)
+{
+       DEBUG(5, ("init_samr_r_get_usrdom_pwinfo\n"));
+       
+       r_u->unknown_0 = 0x0000;
+    r_u->unknown_1 = 0x0015;
+    r_u->unknown_2 = 0x00000000;
 
-       return True;
+       r_u->status = status;
 }
 
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-static BOOL sam_io_unk_info1(char *desc, SAM_UNK_INFO_1 *u_1, prs_struct *ps, int depth)
+
+BOOL samr_io_r_get_usrdom_pwinfo(char *desc, SAMR_R_GET_USRDOM_PWINFO * r_u,
+                                prs_struct *ps, int depth)
 {
-       if (u_1 == NULL)
+       if (r_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "sam_io_unk_info1");
+       prs_debug(ps, depth, desc, "samr_io_r_get_usrdom_pwinfo");
        depth++;
 
-       if(!prs_uint8s(False, "padding", ps, depth, u_1->padding, sizeof(u_1->padding)))
+       if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("unknown_1", ps, depth, &u_1->unknown_1))        /* 0x8000 0000 */
+       if(!prs_uint16("unknown_0", ps, depth, &r_u->unknown_0))
                return False;
-       if(!prs_uint32("unknown_2", ps, depth, &u_1->unknown_2))        /* 0x0000 0000 */
+       if(!prs_uint16("unknown_1", ps, depth, &r_u->unknown_1))
                return False;
-
-       if(!prs_align(ps))
+       if(!prs_uint32("unknown_2", ps, depth, &r_u->unknown_2))
+               return False;
+       if(!prs_uint32("status   ", ps, depth, &r_u->status))
                return False;
 
        return True;
 }
 
 /*******************************************************************
- Inits a structure.
+reads or writes a structure.
 ********************************************************************/
 
-void init_unk_info2(SAM_UNK_INFO_2 *u_2, char *domain, char *server)
+void init_samr_q_query_sec_obj(SAMR_Q_QUERY_SEC_OBJ * q_u,
+                              POLICY_HND *user_pol, uint32 sec_info)
 {
-       int len_domain = strlen(domain)+1;
-       int len_server = strlen(server)+1;
-
-       u_2->unknown_0 = 0x00000000;
-       u_2->unknown_1 = 0x80000000;
-       u_2->unknown_2 = 0x00000000;
-
-       u_2->ptr_0 = 1;
-       init_uni_hdr(&u_2->hdr_domain, len_domain);
-       init_uni_hdr(&u_2->hdr_server, len_server);
-
-       u_2->seq_num = 0x10000000;
-       u_2->unknown_3 = 0x00000000;
-       
-       u_2->unknown_4  = 0x00000001;
-       u_2->unknown_5  = 0x00000003;
-       u_2->unknown_6  = 0x00000001;
-       u_2->num_domain_usrs  = 0x00000008;
-       u_2->num_domain_grps = 0x00000003;
-       u_2->num_local_grps = 0x00000003;
-
-       memset(u_2->padding, 0, sizeof(u_2->padding)); /* 12 bytes zeros */
+       DEBUG(5, ("samr_init_samr_q_query_sec_obj\n"));
 
-       init_unistr2(&u_2->uni_domain, domain, len_domain);
-       init_unistr2(&u_2->uni_server, server, len_server);
+       q_u->user_pol = *user_pol;
+       q_u->sec_info = sec_info;
 }
 
+
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL sam_io_unk_info2(char *desc, SAM_UNK_INFO_2 *u_2, prs_struct *ps, int depth)
+BOOL samr_io_q_query_sec_obj(char *desc, SAMR_Q_QUERY_SEC_OBJ * q_u,
+                            prs_struct *ps, int depth)
 {
-       if (u_2 == NULL)
+       if (q_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "sam_io_unk_info2");
+       prs_debug(ps, depth, desc, "samr_io_q_query_sec_obj");
        depth++;
 
-       if(!prs_uint32("unknown_0", ps, depth, &u_2->unknown_0)) /* 0x0000 0000 */
-               return False;
-       if(!prs_uint32("unknown_1", ps, depth, &u_2->unknown_1)) /* 0x8000 0000 */
-               return False;
-       if(!prs_uint32("unknown_2", ps, depth, &u_2->unknown_2)) /* 0x0000 0000 */
+       if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("ptr_0", ps, depth, &u_2->ptr_0))     /* pointer to unknown structure */
-               return False;
-       if(!smb_io_unihdr("hdr_domain", &u_2->hdr_domain, ps, depth)) /* domain name unicode header */
+       if(!smb_io_pol_hnd("user_pol", &q_u->user_pol, ps, depth))
                return False;
-       if(!smb_io_unihdr("hdr_server", &u_2->hdr_server, ps, depth)) /* server name unicode header */
+
+       if(!prs_uint32("sec_info", ps, depth, &q_u->sec_info))
                return False;
 
-       /* put all the data in here, at the moment, including what the above
-          pointer is referring to
-        */
+       return True;
+}
 
-       if(!prs_uint32("seq_num ", ps, depth, &u_2->seq_num )) /* 0x0000 0099 or 0x1000 0000 */
-               return False;
-       if(!prs_uint32("unknown_3 ", ps, depth, &u_2->unknown_3 )) /* 0x0000 0000 */
-               return False;
-       
-       if(!prs_uint32("unknown_4 ", ps, depth, &u_2->unknown_4 )) /* 0x0000 0001 */
-               return False;
-       if(!prs_uint32("unknown_5 ", ps, depth, &u_2->unknown_5 )) /* 0x0000 0003 */
-               return False;
-       if(!prs_uint32("unknown_6 ", ps, depth, &u_2->unknown_6 )) /* 0x0000 0001 */
-               return False;
-       if(!prs_uint32("num_domain_usrs ", ps, depth, &u_2->num_domain_usrs )) /* 0x0000 0008 */
-               return False;
-       if(!prs_uint32("num_domain_grps", ps, depth, &u_2->num_domain_grps)) /* 0x0000 0003 */
-               return False;
-       if(!prs_uint32("num_local_grps", ps, depth, &u_2->num_local_grps)) /* 0x0000 0003 */
-               return False;
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
 
-       if(!prs_uint8s(False, "padding", ps, depth, u_2->padding, sizeof(u_2->padding))) /* 12 bytes zeros */
-               return False;
+void init_samr_q_query_dom_info(SAMR_Q_QUERY_DOMAIN_INFO * q_u,
+                               POLICY_HND *domain_pol, uint16 switch_value)
+{
+       DEBUG(5, ("samr_init_samr_q_query_dom_info\n"));
+
+       q_u->domain_pol = *domain_pol;
+       q_u->switch_value = switch_value;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
 
-       if(!smb_io_unistr2( "uni_domain", &u_2->uni_domain, u_2->hdr_domain.buffer, ps, depth)) /* domain name unicode string */
+BOOL samr_io_q_query_dom_info(char *desc, SAMR_Q_QUERY_DOMAIN_INFO * q_u,
+                             prs_struct *ps, int depth)
+{
+       if (q_u == NULL)
                return False;
+
+       prs_debug(ps, depth, desc, "samr_io_q_query_dom_info");
+       depth++;
+
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_unistr2( "uni_server", &u_2->uni_server, u_2->hdr_server.buffer, ps, depth)) /* server name unicode string */
+       if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
                return False;
 
-       if(!prs_align(ps))
+       if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
                return False;
 
        return True;
 }
 
+
 /*******************************************************************
-Inits a structure.
+inits a structure.
 ********************************************************************/
-BOOL init_unk_info3(SAM_UNK_INFO_3 * u_3)
-{
-       if (u_3 == NULL)
-               return False;
 
+void init_unk_info3(SAM_UNK_INFO_3 * u_3)
+{
        u_3->unknown_0 = 0x00000000;
        u_3->unknown_1 = 0x80000000;
-
-       return True;
 }
 
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-static BOOL sam_io_unk_info3(char *desc, SAM_UNK_INFO_3 *u_3, prs_struct *ps, int depth)
+
+static BOOL sam_io_unk_info3(char *desc, SAM_UNK_INFO_3 * u_3,
+                            prs_struct *ps, int depth)
 {
        if (u_3 == NULL)
                return False;
@@ -484,31 +489,26 @@ static BOOL sam_io_unk_info3(char *desc, SAM_UNK_INFO_3 *u_3, prs_struct *ps, in
        if(!prs_uint32("unknown_1", ps, depth, &u_3->unknown_1))        /* 0x8000 0000 */
                return False;
 
-       if(!prs_align(ps))
-               return False;
-
        return True;
 }
 
 /*******************************************************************
-Inits a structure.
+inits a structure.
 ********************************************************************/
-BOOL init_unk_info6(SAM_UNK_INFO_6 * u_6)
-{
-       if (u_6 == NULL)
-               return False;
 
+void init_unk_info6(SAM_UNK_INFO_6 * u_6)
+{
        u_6->unknown_0 = 0x00000000;
        u_6->ptr_0 = 1;
        memset(u_6->padding, 0, sizeof(u_6->padding));  /* 12 bytes zeros */
-
-       return True;
 }
 
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-static BOOL sam_io_unk_info6(char *desc, SAM_UNK_INFO_6 *u_6, prs_struct *ps, int depth)
+
+static BOOL sam_io_unk_info6(char *desc, SAM_UNK_INFO_6 * u_6,
+                            prs_struct *ps, int depth)
 {
        if (u_6 == NULL)
                return False;
@@ -516,36 +516,31 @@ static BOOL sam_io_unk_info6(char *desc, SAM_UNK_INFO_6 *u_6, prs_struct *ps, in
        prs_debug(ps, depth, desc, "sam_io_unk_info6");
        depth++;
 
-       if(!prs_uint32("unknown_0", ps, depth, &u_6->unknown_0))        /* 0x0000 0000 */
+       if(!prs_uint32("unknown_0", ps, depth, &u_6->unknown_0)) /* 0x0000 0000 */
                return False;
-       if(!prs_uint32("ptr_0", ps, depth, &u_6->ptr_0))        /* pointer to unknown structure */
+       if(!prs_uint32("ptr_0", ps, depth, &u_6->ptr_0)) /* pointer to unknown structure */
                return False;
        if(!prs_uint8s(False, "padding", ps, depth, u_6->padding, sizeof(u_6->padding)))        /* 12 bytes zeros */
                return False;
 
-       if(!prs_align(ps))
-               return False;
-
        return True;
 }
 
 /*******************************************************************
-Inits a structure.
+inits a structure.
 ********************************************************************/
-BOOL init_unk_info7(SAM_UNK_INFO_7 *u_7)
-{
-       if (u_7 == NULL)
-               return False;
 
+void init_unk_info7(SAM_UNK_INFO_7 * u_7)
+{
        u_7->unknown_0 = 0x0003;
-
-       return True;
 }
 
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-static BOOL sam_io_unk_info7(char *desc, SAM_UNK_INFO_7 *u_7, prs_struct *ps, int depth)
+
+static BOOL sam_io_unk_info7(char *desc, SAM_UNK_INFO_7 * u_7,
+                            prs_struct *ps, int depth)
 {
        if (u_7 == NULL)
                return False;
@@ -553,37 +548,32 @@ static BOOL sam_io_unk_info7(char *desc, SAM_UNK_INFO_7 *u_7, prs_struct *ps, in
        prs_debug(ps, depth, desc, "sam_io_unk_info7");
        depth++;
 
-       if(!prs_uint16("unknown_0", ps, depth, &u_7->unknown_0))        /* 0x0003 */
-               return False;
-       if(!prs_align(ps))
+       if(!prs_uint16("unknown_0", ps, depth, &u_7->unknown_0)) /* 0x0003 */
                return False;
 
        return True;
 }
 
 /*******************************************************************
-Inits a structure.
+inits a structure.
 ********************************************************************/
-BOOL init_unk_info12(SAM_UNK_INFO_12 * u_12)
-{
-       if (u_12 == NULL)
-               return False;
 
+void init_unk_info12(SAM_UNK_INFO_12 * u_12)
+{
        u_12->unknown_0 = 0xcf1dcc00;
        u_12->unknown_1 = 0xfffffffb;
        u_12->unknown_2 = 0xcf1dcc00;
        u_12->unknown_3 = 0xfffffffb;
 
        u_12->unknown_4 = 0x8a880000;
-
-       return True;
 }
 
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
+
 static BOOL sam_io_unk_info12(char *desc, SAM_UNK_INFO_12 * u_12,
-                            prs_struct *ps, int depth)
+                             prs_struct *ps, int depth)
 {
        if (u_12 == NULL)
                return False;
@@ -602,323 +592,247 @@ static BOOL sam_io_unk_info12(char *desc, SAM_UNK_INFO_12 * u_12,
        if(!prs_uint32("unknown_4", ps, depth, &u_12->unknown_4))
                return False;
 
-       if(!prs_align(ps))
-               return False;
-
        return True;
 }
 
 /*******************************************************************
- Inits a SAMR_R_QUERY_DOMAIN_INFO structure.
+inits a structure.
 ********************************************************************/
-
-void init_samr_r_query_dom_info(SAMR_R_QUERY_DOMAIN_INFO *r_u, 
-                               uint16 switch_value, SAM_UNK_CTR *ctr,
-                               uint32 status)
+void init_unk_info2(SAM_UNK_INFO_2 * u_2,
+                       char *domain, char *server,
+                       uint32 seq_num)
 {
-       DEBUG(5,("init_samr_r_query_dom_info\n"));
+       int len_domain = strlen(domain);
+       int len_server = strlen(server);
 
-       r_u->ptr_0 = 0;
-       r_u->switch_value = 0;
-       r_u->status = status; /* return status */
+       u_2->unknown_0 = 0x00000000;
+       u_2->unknown_1 = 0x80000000;
+       u_2->unknown_2 = 0x00000000;
 
-       if (status == 0) {
-               r_u->switch_value = switch_value;
-               r_u->ptr_0 = 1;
-               r_u->ctr = ctr;
-       }
+       u_2->ptr_0 = 1;
+       init_uni_hdr(&u_2->hdr_domain, len_domain);
+       init_uni_hdr(&u_2->hdr_server, len_server);
+
+       u_2->seq_num = seq_num;
+       u_2->unknown_3 = 0x00000000;
+
+       u_2->unknown_4 = 0x00000001;
+       u_2->unknown_5 = 0x00000003;
+       u_2->unknown_6 = 0x00000001;
+       u_2->num_domain_usrs = MAX_SAM_ENTRIES;
+       u_2->num_domain_grps = MAX_SAM_ENTRIES;
+       u_2->num_local_grps = MAX_SAM_ENTRIES;
+
+       memset(u_2->padding, 0, sizeof(u_2->padding));  /* 12 bytes zeros */
+
+       init_unistr2(&u_2->uni_domain, domain, len_domain);
+       init_unistr2(&u_2->uni_server, server, len_server);
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_r_query_dom_info(char *desc, SAMR_R_QUERY_DOMAIN_INFO *r_u, prs_struct *ps, int depth)
+static BOOL sam_io_unk_info2(char *desc, SAM_UNK_INFO_2 * u_2,
+                            prs_struct *ps, int depth)
 {
-       if (r_u == NULL)
+       if (u_2 == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_r_query_dom_info");
+       prs_debug(ps, depth, desc, "sam_io_unk_info2");
        depth++;
 
-       if(!prs_align(ps))
+       if(!prs_uint32("unknown_0", ps, depth, &u_2->unknown_0)) /* 0x0000 0000 */
                return False;
-
-       if(!prs_uint32("ptr_0       ", ps, depth, &r_u->ptr_0))
+       if(!prs_uint32("unknown_1", ps, depth, &u_2->unknown_1)) /* 0x8000 0000 */
                return False;
-
-       if (r_u->ptr_0 != 0 && r_u->ctr != NULL) {
-               if(!prs_uint16("switch_value", ps, depth, &r_u->switch_value))
-                       return False;
-               if(!prs_align(ps))
-                       return False;
-
-               switch (r_u->switch_value) {
-               case 0x01:
-                       if(!sam_io_unk_info1("unk_inf1", &r_u->ctr->info.inf1, ps, depth))
-                               return False;
-                       break;
-               case 0x02:
-                       if(!sam_io_unk_info2("unk_inf2", &r_u->ctr->info.inf2, ps, depth))
-                               return False;
-                       break;
-               case 0x03:
-                       if(!sam_io_unk_info3("unk_inf3", &r_u->ctr->info.inf3, ps, depth))
-                               return False;
-                       break;
-               case 0x06:
-                       if(!sam_io_unk_info6("unk_inf6", &r_u->ctr->info.inf6, ps, depth))
-                               return False;
-                       break;
-               case 0x07:
-                       if(!sam_io_unk_info7("unk_inf7", &r_u->ctr->info.inf7, ps, depth))
-                               return False;
-                       break;
-               case 0x0c:
-                       if(!sam_io_unk_info12("unk_inf12", &r_u->ctr->info.inf12, ps, depth))
-                               return False;
-                       break;
-               default:
-                       DEBUG(3,("samr_io_r_query_dom_info: unknown switch level 0x%x\n",
-                                 r_u->switch_value));
-                       return False;
-               }
-       }
-
-       if(!prs_uint32("status", ps, depth, &r_u->status))
+       if(!prs_uint32("unknown_2", ps, depth, &u_2->unknown_2))        /* 0x0000 0000 */
                return False;
 
-       return True;
-}
-
-
-/*******************************************************************
- Inits a DOM_SID3 structure.
- Calculate length by adding up the size of the components.
- ********************************************************************/
-
-void init_dom_sid3(DOM_SID3 *sid3, uint16 unk_0, uint16 unk_1, DOM_SID *sid)
-{
-       sid3->sid = *sid;
-       sid3->len = 2 + 8 + sid3->sid.num_auths * 4;
-}
-
-/*******************************************************************
- Reads or writes a SAM_SID3 structure.
-
- this one's odd, because the length (in bytes) is specified at the beginning.
- the length _includes_ the length of the length, too :-)
+       if(!prs_uint32("ptr_0", ps, depth, &u_2->ptr_0))
+               return False;
+       if(!smb_io_unihdr("hdr_domain", &u_2->hdr_domain, ps, depth))
+               return False;
+       if(!smb_io_unihdr("hdr_server", &u_2->hdr_server, ps, depth))
+               return False;
 
-********************************************************************/
+       /* put all the data in here, at the moment, including what the above
+          pointer is referring to
+        */
 
-static BOOL sam_io_dom_sid3(char *desc,  DOM_SID3 *sid3, prs_struct *ps, int depth)
-{
-       if (sid3 == NULL)
+       if(!prs_uint32("seq_num ", ps, depth, &u_2->seq_num))   /* 0x0000 0099 or 0x1000 0000 */
+               return False;
+       if(!prs_uint32("unknown_3 ", ps, depth, &u_2->unknown_3))       /* 0x0000 0000 */
                return False;
 
-       prs_debug(ps, depth, desc, "sam_io_dom_sid3");
-       depth++;
+       if(!prs_uint32("unknown_4 ", ps, depth, &u_2->unknown_4)) /* 0x0000 0001 */
+               return False;
+       if(!prs_uint32("unknown_5 ", ps, depth, &u_2->unknown_5)) /* 0x0000 0003 */
+               return False;
+       if(!prs_uint32("unknown_6 ", ps, depth, &u_2->unknown_6)) /* 0x0000 0001 */
+               return False;
+       if(!prs_uint32("num_domain_usrs ", ps, depth, &u_2->num_domain_usrs))
+               return False;
+       if(!prs_uint32("num_domain_grps", ps, depth, &u_2->num_domain_grps))
+               return False;
+       if(!prs_uint32("num_local_grps", ps, depth, &u_2->num_local_grps))
+               return False;
 
-       if(!prs_uint16("len", ps, depth, &sid3->len))
+       if(!prs_uint8s(False, "padding", ps, depth, u_2->padding,sizeof(u_2->padding)))
                return False;
-       if(!prs_align(ps))
+
+       if(!smb_io_unistr2("uni_domain", &u_2->uni_domain, u_2->hdr_domain.buffer, ps, depth))
                return False;
-       if(!smb_io_dom_sid("", &sid3->sid, ps, depth))
+       if(!smb_io_unistr2("uni_server", &u_2->uni_server, u_2->hdr_server.buffer, ps, depth))
                return False;
 
        return True;
 }
 
 /*******************************************************************
- Inits a SAMR_R_UNKNOWN3 structure.
-
-unknown_2   : 0x0001
-unknown_3   : 0x8004
-
-unknown_4,5 : 0x0000 0014
-
-unknown_6   : 0x0002
-unknown_7   : 0x5800 or 0x0070
-
+inits a structure.
 ********************************************************************/
 
-static void init_sam_sid_stuff(SAM_SID_STUFF *stf,
-                               uint16 unknown_2, uint16 unknown_3,
-                               uint32 unknown_4, uint16 unknown_6, uint16 unknown_7,
-                               int num_sid3s, DOM_SID3 sid3[MAX_SAM_SIDS])
+void init_unk_info1(SAM_UNK_INFO_1 * u_1)
 {
-       stf->unknown_2 = unknown_2;
-       stf->unknown_3 = unknown_3;
-
-       memset((char *)stf->padding1, '\0', sizeof(stf->padding1));
-
-       stf->unknown_4 = unknown_4;
-       stf->unknown_5 = unknown_4;
-
-       stf->unknown_6 = unknown_6;
-       stf->unknown_7 = unknown_7;
-
-       stf->num_sids  = num_sid3s;
-
-       stf->padding2  = 0x0000;
-
-       memcpy(stf->sid, sid3, sizeof(DOM_SID3) * num_sid3s);
+       memset(u_1->padding, 0, sizeof(u_1->padding));  /* 12 bytes zeros */
+       u_1->unknown_1 = 0x80000000;
+       u_1->unknown_2 = 0x00000000;
 }
 
 /*******************************************************************
- Reads or writes a SAM_SID_STUFF structure.
+reads or writes a structure.
 ********************************************************************/
 
-static BOOL sam_io_sid_stuff(char *desc,  SAM_SID_STUFF *stf, prs_struct *ps, int depth)
+static BOOL sam_io_unk_info1(char *desc, SAM_UNK_INFO_1 * u_1,
+                            prs_struct *ps, int depth)
 {
-       int i;
-
-       if (stf == NULL)
-               return False;
-
-       DEBUG(5,("init_sam_sid_stuff\n"));
+       if (u_1 == NULL)
+         return False;
 
-       if(!prs_uint16("unknown_2", ps, depth, &stf->unknown_2))
-               return False;
-       if(!prs_uint16("unknown_3", ps, depth, &stf->unknown_3))
-               return False;
+       prs_debug(ps, depth, desc, "sam_io_unk_info1");
+       depth++;
 
-       if(!prs_uint8s(False, "padding1", ps, depth, stf->padding1, sizeof(stf->padding1)))
+       if(!prs_uint8s(False, "padding", ps, depth, u_1->padding, sizeof(u_1->padding)))
                return False;
        
-       if(!prs_uint32("unknown_4", ps, depth, &stf->unknown_4))
-               return False;
-       if(!prs_uint32("unknown_5", ps, depth, &stf->unknown_5))
-               return False;
-       if(!prs_uint16("unknown_6", ps, depth, &stf->unknown_6))
-               return False;
-       if(!prs_uint16("unknown_7", ps, depth, &stf->unknown_7))
-               return False;
-
-       if(!prs_uint32("num_sids ", ps, depth, &stf->num_sids ))
+       if(!prs_uint32("unknown_1", ps, depth, &u_1->unknown_1)) /* 0x8000 0000 */
                return False;
-       if(!prs_uint16("padding2 ", ps, depth, &stf->padding2 ))
+       if(!prs_uint32("unknown_2", ps, depth, &u_1->unknown_2)) /* 0x0000 0000 */
                return False;
 
-       SMB_ASSERT_ARRAY(stf->sid, stf->num_sids);
-
-       for (i = 0; i < stf->num_sids; i++) {
-               if(!sam_io_dom_sid3("", &(stf->sid[i]), ps, depth))
-                       return False;
-       }
-
        return True;
 }
 
 /*******************************************************************
- Inits or writes a SAMR_R_UNKNOWN3 structure.
+inits a SAMR_R_QUERY_DOMAIN_INFO structure.
 ********************************************************************/
 
-void init_samr_r_unknown_3(SAMR_R_UNKNOWN_3 *r_u,
-                               uint16 unknown_2, uint16 unknown_3,
-                               uint32 unknown_4, uint16 unknown_6, uint16 unknown_7,
-                               int num_sid3s, DOM_SID3 sid3[MAX_SAM_SIDS],
+void init_samr_r_query_dom_info(SAMR_R_QUERY_DOMAIN_INFO * r_u,
+                               uint16 switch_value, SAM_UNK_CTR * ctr,
                                uint32 status)
 {
-       DEBUG(5,("samr_init_r_unknown_3\n"));
+       DEBUG(5, ("init_samr_r_query_dom_info\n"));
 
        r_u->ptr_0 = 0;
-       r_u->ptr_1 = 0;
+       r_u->switch_value = 0;
+       r_u->status = status;   /* return status */
 
-       if (status == 0x0) {
+       if (status == 0) {
+               r_u->switch_value = switch_value;
                r_u->ptr_0 = 1;
-               r_u->ptr_1 = 1;
-               init_sam_sid_stuff(&(r_u->sid_stuff), unknown_2, unknown_3,
-                      unknown_4, unknown_6, unknown_7,
-                      num_sid3s, sid3);
+               r_u->ctr = ctr;
        }
-
-       r_u->status = status;
 }
 
 /*******************************************************************
- Reads or writes a SAMR_R_UNKNOWN_3 structure.
-
-this one's odd, because the daft buggers use a different mechanism
-for writing out the array of sids. they put the number of sids in
-only one place: they've calculated the length of each sid and jumped
-by that amount.  then, retrospectively, the length of the whole buffer
-is put at the beginning of the data stream.
-
-wierd.  
-
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_r_unknown_3(char *desc,  SAMR_R_UNKNOWN_3 *r_u, prs_struct *ps, int depth)
+BOOL samr_io_r_query_dom_info(char *desc, SAMR_R_QUERY_DOMAIN_INFO * r_u,
+                             prs_struct *ps, int depth)
 {
-       int ptr_len0=0;
-       int ptr_len1=0;
-       int ptr_sid_stuff = 0;
-
-       if (r_u == NULL)
+        if (r_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_r_unknown_3");
+       prs_debug(ps, depth, desc, "samr_io_r_query_dom_info");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("ptr_0         ", ps, depth, &r_u->ptr_0))
+       if(!prs_uint32("ptr_0 ", ps, depth, &r_u->ptr_0))
                return False;
 
-       if (ps->io) {
-               /* reading.  do the length later */
-               if(!prs_uint32("sid_stuff_len0", ps, depth, &r_u->sid_stuff_len0))
+       if (r_u->ptr_0 != 0 && r_u->ctr != NULL) {
+               if(!prs_uint16("switch_value", ps, depth, &r_u->switch_value))
                        return False;
-       } else {
-               /* storing */
-               ptr_len0 = prs_offset(ps);
-               if(!prs_set_offset(ps, ptr_len0 + 4))
+               if(!prs_align(ps))
                        return False;
-       }
 
-       if (r_u->ptr_0 != 0) {
-               if(!prs_uint32("ptr_1         ", ps, depth, &r_u->ptr_1))
-                       return False;
-               if (ps->io) {
-                       /* reading.  do the length later */
-                       if(!prs_uint32("sid_stuff_len1", ps, depth, &r_u->sid_stuff_len1))
+               switch (r_u->switch_value) {
+               case 0x0c:
+                       if(!sam_io_unk_info12("unk_inf12", &r_u->ctr->info.inf12, ps, depth))
+                               return False;
+                       break;
+               case 0x07:
+                       if(!sam_io_unk_info7("unk_inf7",&r_u->ctr->info.inf7, ps,depth))
                                return False;
-               } else {
-                       /* storing */
-                       ptr_len1 = prs_offset(ps);
-                       if(!prs_set_offset(ps, ptr_len1 + 4))
+                       break;
+               case 0x06:
+                       if(!sam_io_unk_info6("unk_inf6",&r_u->ctr->info.inf6, ps,depth))
                                return False;
-               }
-
-               if (r_u->ptr_1 != 0) {
-                       ptr_sid_stuff = prs_offset(ps);
-                       if(!sam_io_sid_stuff("", &r_u->sid_stuff, ps, depth))
+                       break;
+               case 0x03:
+                       if(!sam_io_unk_info3("unk_inf3",&r_u->ctr->info.inf3, ps,depth))
                                return False;
+                       break;
+               case 0x02:
+                       if(!sam_io_unk_info2("unk_inf2",&r_u->ctr->info.inf2, ps,depth))
+                               return False;
+                       break;
+               case 0x01:
+                       if(!sam_io_unk_info1("unk_inf1",&r_u->ctr->info.inf1, ps,depth))
+                               return False;
+                       break;
+               default:
+                       DEBUG(0, ("samr_io_r_query_dom_info: unknown switch level 0x%x\n",
+                               r_u->switch_value));
+                       r_u->status = NT_STATUS_INVALID_INFO_CLASS;
+                       return False;
                }
        }
+       
+       if(!prs_align(ps))
+               return False;
 
-       if (!(ps->io)) {
-               /* storing not reading.  do the length, now. */
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+       
+       return True;
+}
 
-               if (ptr_sid_stuff != 0) {
-                       int old_len = prs_offset(ps);
-                       uint32 sid_stuff_len = old_len - ptr_sid_stuff;
+/*******************************************************************
+reads or writes a SAMR_R_QUERY_SEC_OBJ structure.
+********************************************************************/
 
-                       if(!prs_set_offset(ps, ptr_len0))
-                               return False;
-                       if(!prs_uint32("sid_stuff_len0", ps, depth, &sid_stuff_len))
-                               return False;
+BOOL samr_io_r_query_sec_obj(char *desc, SAMR_R_QUERY_SEC_OBJ * r_u,
+                            prs_struct *ps, int depth)
+{
+       if (r_u == NULL)
+               return False;
+  
+       prs_debug(ps, depth, desc, "samr_io_r_query_sec_obj");
+       depth++;
 
-                       if(!prs_set_offset(ps, ptr_len1))
-                               return False;
-                       if(!prs_uint32("sid_stuff_len1", ps, depth, &sid_stuff_len))
-                               return False;
+       if(!prs_align(ps))
+               return False;
 
-                       if(!prs_set_offset(ps, old_len))
-                               return False;
-               }
+       if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
+               return False;
+       if (r_u->ptr != 0) {
+               if(!sec_io_desc_buf("sec", &r_u->buf, ps, depth))
+                       return False;
        }
 
        if(!prs_uint32("status", ps, depth, &r_u->status))
@@ -928,11 +842,12 @@ BOOL samr_io_r_unknown_3(char *desc,  SAMR_R_UNKNOWN_3 *r_u, prs_struct *ps, int
 }
 
 /*******************************************************************
- Reads or writes a SAM_STR1 structure.
+reads or writes a SAM_STR1 structure.
 ********************************************************************/
 
-static BOOL sam_io_sam_str1(char *desc, SAM_STR1 *sam, uint32 acct_buf,
-                               uint32 name_buf, uint32 desc_buf, prs_struct *ps, int depth)
+static BOOL sam_io_sam_str1(char *desc, SAM_STR1 * sam, uint32 acct_buf,
+                           uint32 name_buf, uint32 desc_buf,
+                           prs_struct *ps, int depth)
 {
        if (sam == NULL)
                return False;
@@ -942,31 +857,35 @@ static BOOL sam_io_sam_str1(char *desc, SAM_STR1 *sam, uint32 acct_buf,
 
        if(!prs_align(ps))
                return False;
-
-       if(!smb_io_unistr2("unistr2", &sam->uni_acct_name, acct_buf, ps, depth)) /* account name unicode string */
+       if (!smb_io_unistr2("name", &sam->uni_acct_name, acct_buf, ps, depth))
                return False;
-       if(!smb_io_unistr2("unistr2", &sam->uni_full_name, name_buf, ps, depth)) /* full name unicode string */
+
+       if (!smb_io_unistr2("desc", &sam->uni_acct_desc, desc_buf, ps, depth))
                return False;
-       if(!smb_io_unistr2("unistr2", &sam->uni_acct_desc, desc_buf, ps, depth)) /* account description unicode string */
+
+       if (!smb_io_unistr2("full", &sam->uni_full_name, name_buf, ps, depth))
                return False;
 
        return True;
 }
 
 /*******************************************************************
- Inits a SAM_ENTRY1 structure.
+inits a SAM_ENTRY1 structure.
 ********************************************************************/
 
-static void init_sam_entry1(SAM_ENTRY1 *sam, uint32 user_idx, 
-                               uint32 len_sam_name, uint32 len_sam_full, uint32 len_sam_desc,
-                               uint32 rid_user, uint16 acb_info)
+static void init_sam_entry1(SAM_ENTRY1 * sam, uint32 user_idx,
+                           uint32 len_sam_name, uint32 len_sam_full,
+                           uint32 len_sam_desc, uint32 rid_user,
+                           uint16 acb_info)
 {
-       DEBUG(5,("init_sam_entry1\n"));
+       DEBUG(5, ("init_sam_entry1\n"));
+
+       ZERO_STRUCTP(sam);
 
        sam->user_idx = user_idx;
        sam->rid_user = rid_user;
        sam->acb_info = acb_info;
-       sam->pad      = 0;
+       sam->pad = 0;
 
        init_uni_hdr(&sam->hdr_acct_name, len_sam_name);
        init_uni_hdr(&sam->hdr_user_name, len_sam_full);
@@ -974,10 +893,11 @@ static void init_sam_entry1(SAM_ENTRY1 *sam, uint32 user_idx,
 }
 
 /*******************************************************************
- Reads or writes a SAM_ENTRY1 structure.
+reads or writes a SAM_ENTRY1 structure.
 ********************************************************************/
 
-static BOOL sam_io_sam_entry1(char *desc,  SAM_ENTRY1 *sam, prs_struct *ps, int depth)
+static BOOL sam_io_sam_entry1(char *desc, SAM_ENTRY1 * sam,
+                             prs_struct *ps, int depth)
 {
        if (sam == NULL)
                return False;
@@ -998,21 +918,22 @@ static BOOL sam_io_sam_entry1(char *desc,  SAM_ENTRY1 *sam, prs_struct *ps, int
        if(!prs_uint16("pad      ", ps, depth, &sam->pad))
                return False;
 
-       if(!smb_io_unihdr("unihdr", &sam->hdr_acct_name, ps, depth)) /* account name unicode string header */
+       if (!smb_io_unihdr("hdr_acct_name", &sam->hdr_acct_name, ps, depth))
                return False;
-       if(!smb_io_unihdr("unihdr", &sam->hdr_user_name, ps, depth)) /* account name unicode string header */
+       if (!smb_io_unihdr("hdr_user_desc", &sam->hdr_user_desc, ps, depth))
                return False;
-       if(!smb_io_unihdr("unihdr", &sam->hdr_user_desc, ps, depth)) /* account name unicode string header */
+       if (!smb_io_unihdr("hdr_user_name", &sam->hdr_user_name, ps, depth))
                return False;
 
        return True;
 }
 
 /*******************************************************************
- Reads or writes a SAM_STR2 structure.
+reads or writes a SAM_STR2 structure.
 ********************************************************************/
 
-static BOOL sam_io_sam_str2(char *desc,  SAM_STR2 *sam, uint32 acct_buf, uint32 desc_buf, prs_struct *ps, int depth)
+static BOOL sam_io_sam_str2(char *desc, SAM_STR2 * sam, uint32 acct_buf,
+                           uint32 desc_buf, prs_struct *ps, int depth)
 {
        if (sam == NULL)
                return False;
@@ -1023,38 +944,38 @@ static BOOL sam_io_sam_str2(char *desc,  SAM_STR2 *sam, uint32 acct_buf, uint32
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_unistr2("unistr2", &sam->uni_srv_name, acct_buf, ps, depth)) /* account name unicode string */
+       if(!smb_io_unistr2("uni_srv_name", &sam->uni_srv_name, acct_buf, ps, depth)) /* account name unicode string */
                return False;
-       if(!smb_io_unistr2("unistr2", &sam->uni_srv_desc, desc_buf, ps, depth)) /* account description unicode string */
+       if(!smb_io_unistr2("uni_srv_desc", &sam->uni_srv_desc, desc_buf, ps, depth))    /* account desc unicode string */
                return False;
 
        return True;
 }
 
 /*******************************************************************
- Inits a SAM_ENTRY2 structure.
+inits a SAM_ENTRY2 structure.
 ********************************************************************/
-
-static void init_sam_entry2(SAM_ENTRY2 *sam, uint32 user_idx, 
-                               uint32 len_sam_name, uint32 len_sam_desc,
-                               uint32 rid_user, uint16 acb_info)
+static void init_sam_entry2(SAM_ENTRY2 * sam, uint32 user_idx,
+                           uint32 len_sam_name, uint32 len_sam_desc,
+                           uint32 rid_user, uint16 acb_info)
 {
-       DEBUG(5,("init_sam_entry2\n"));
+       DEBUG(5, ("init_sam_entry2\n"));
 
        sam->user_idx = user_idx;
        sam->rid_user = rid_user;
        sam->acb_info = acb_info;
-       sam->pad      = 0;
+       sam->pad = 0;
 
        init_uni_hdr(&sam->hdr_srv_name, len_sam_name);
        init_uni_hdr(&sam->hdr_srv_desc, len_sam_desc);
 }
 
 /*******************************************************************
- Reads or writes a SAM_ENTRY2 structure.
+reads or writes a SAM_ENTRY2 structure.
 ********************************************************************/
 
-static BOOL sam_io_sam_entry2(char *desc,  SAM_ENTRY2 *sam, prs_struct *ps, int depth)
+static BOOL sam_io_sam_entry2(char *desc, SAM_ENTRY2 * sam,
+                             prs_struct *ps, int depth)
 {
        if (sam == NULL)
                return False;
@@ -1075,19 +996,20 @@ static BOOL sam_io_sam_entry2(char *desc,  SAM_ENTRY2 *sam, prs_struct *ps, int
        if(!prs_uint16("pad      ", ps, depth, &sam->pad))
                return False;
 
-       if(!smb_io_unihdr("unihdr", &sam->hdr_srv_name, ps, depth)) /* account name unicode string header */
+       if(!smb_io_unihdr("unihdr", &sam->hdr_srv_name, ps, depth))     /* account name unicode string header */
                return False;
-       if(!smb_io_unihdr("unihdr", &sam->hdr_srv_desc, ps, depth)) /* account name unicode string header */
+       if(!smb_io_unihdr("unihdr", &sam->hdr_srv_desc, ps, depth))     /* account name unicode string header */
                return False;
 
        return True;
 }
 
 /*******************************************************************
- Reads or writes a SAM_STR3 structure.
+reads or writes a SAM_STR3 structure.
 ********************************************************************/
 
-static BOOL sam_io_sam_str3(char *desc,  SAM_STR3 *sam, uint32 acct_buf, uint32 desc_buf, prs_struct *ps, int depth)
+static BOOL sam_io_sam_str3(char *desc, SAM_STR3 * sam, uint32 acct_buf,
+                           uint32 desc_buf, prs_struct *ps, int depth)
 {
        if (sam == NULL)
                return False;
@@ -1098,37 +1020,38 @@ static BOOL sam_io_sam_str3(char *desc,  SAM_STR3 *sam, uint32 acct_buf, uint32
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_unistr2("unistr2", &sam->uni_grp_name, acct_buf, ps, depth)) /* account name unicode string */
+       if(!smb_io_unistr2("uni_grp_name", &sam->uni_grp_name, acct_buf, ps, depth))    /* account name unicode string */
                return False;
-       if(!smb_io_unistr2("unistr2", &sam->uni_grp_desc, desc_buf, ps, depth)) /* account description unicode string */
+       if(!smb_io_unistr2("uni_grp_desc", &sam->uni_grp_desc, desc_buf, ps, depth))    /* account desc unicode string */
                return False;
 
        return True;
 }
 
 /*******************************************************************
- Inits a SAM_ENTRY3 structure.
+inits a SAM_ENTRY3 structure.
 ********************************************************************/
 
-static void init_sam_entry3(SAM_ENTRY3 *sam, uint32 grp_idx, 
-                               uint32 len_grp_name, uint32 len_grp_desc, uint32 rid_grp)
+static void init_sam_entry3(SAM_ENTRY3 * sam, uint32 grp_idx,
+                           uint32 len_grp_name, uint32 len_grp_desc,
+                           uint32 rid_grp)
 {
-       DEBUG(5,("init_sam_entry3\n"));
+       DEBUG(5, ("init_sam_entry3\n"));
 
-       ZERO_STRUCTP(sam);
        sam->grp_idx = grp_idx;
        sam->rid_grp = rid_grp;
-       sam->attr    = 0x07; /* group rid attributes - gets ignored by nt 4.0 */
+       sam->attr = 0x07;       /* group rid attributes - gets ignored by nt 4.0 */
 
        init_uni_hdr(&sam->hdr_grp_name, len_grp_name);
        init_uni_hdr(&sam->hdr_grp_desc, len_grp_desc);
 }
 
 /*******************************************************************
- Reads or writes a SAM_ENTRY3 structure.
+reads or writes a SAM_ENTRY3 structure.
 ********************************************************************/
 
-static BOOL sam_io_sam_entry3(char *desc,  SAM_ENTRY3 *sam, prs_struct *ps, int depth)
+static BOOL sam_io_sam_entry3(char *desc, SAM_ENTRY3 * sam,
+                             prs_struct *ps, int depth)
 {
        if (sam == NULL)
                return False;
@@ -1147,257 +1070,170 @@ static BOOL sam_io_sam_entry3(char *desc,  SAM_ENTRY3 *sam, prs_struct *ps, int
        if(!prs_uint32("attr   ", ps, depth, &sam->attr))
                return False;
 
-       if(!smb_io_unihdr("unihdr", &sam->hdr_grp_name, ps, depth)) /* account name unicode string header */
+       if(!smb_io_unihdr("unihdr", &sam->hdr_grp_name, ps, depth))     /* account name unicode string header */
                return False;
-       if(!smb_io_unihdr("unihdr", &sam->hdr_grp_desc, ps, depth)) /* account name unicode string header */
+       if(!smb_io_unihdr("unihdr", &sam->hdr_grp_desc, ps, depth))     /* account name unicode string header */
                return False;
 
        return True;
 }
 
 /*******************************************************************
- Inits a SAM_ENTRY structure.
+inits a SAM_ENTRY4 structure.
 ********************************************************************/
 
-static void init_sam_entry(SAM_ENTRY *sam, uint32 len_sam_name, uint32 rid)
+static void init_sam_entry4(SAM_ENTRY4 * sam, uint32 user_idx,
+                           uint32 len_acct_name)
 {
-       DEBUG(5,("init_sam_entry\n"));
+       DEBUG(5, ("init_sam_entry4\n"));
 
-       sam->rid = rid;
-       init_uni_hdr(&sam->hdr_name, len_sam_name);
+       sam->user_idx = user_idx;
+       init_str_hdr(&sam->hdr_acct_name, len_acct_name, len_acct_name,
+                    len_acct_name != 0);
 }
 
 /*******************************************************************
- Reads or writes a SAM_ENTRY structure.
+reads or writes a SAM_ENTRY4 structure.
 ********************************************************************/
 
-static BOOL sam_io_sam_entry(char *desc,  SAM_ENTRY *sam, prs_struct *ps, int depth)
+static BOOL sam_io_sam_entry4(char *desc, SAM_ENTRY4 * sam,
+                             prs_struct *ps, int depth)
 {
        if (sam == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "sam_io_sam_entry");
+       prs_debug(ps, depth, desc, "sam_io_sam_entry4");
        depth++;
 
        if(!prs_align(ps))
                return False;
-       if(!prs_uint32("rid", ps, depth, &sam->rid))
+
+       if(!prs_uint32("user_idx", ps, depth, &sam->user_idx))
                return False;
-       if(!smb_io_unihdr("unihdr", &sam->hdr_name, ps, depth)) /* account name unicode string header */
+       if(!smb_io_strhdr("strhdr", &sam->hdr_acct_name, ps, depth))
                return False;
 
        return True;
 }
 
-
 /*******************************************************************
- Inits a SAMR_Q_ENUM_DOM_USERS structure.
+inits a SAM_ENTRY5 structure.
 ********************************************************************/
 
-void init_samr_q_enum_dom_users(SAMR_Q_ENUM_DOM_USERS *q_e, POLICY_HND *pol,
-                               uint16 req_num_entries, uint16 unk_0,
-                               uint16 acb_mask, uint16 unk_1, uint32 size)
+static void init_sam_entry5(SAM_ENTRY5 * sam, uint32 grp_idx,
+                           uint32 len_grp_name)
 {
-       DEBUG(5,("init_q_enum_dom_users\n"));
+       DEBUG(5, ("init_sam_entry5\n"));
 
-       memcpy(&q_e->pol, pol, sizeof(*pol));
-
-       q_e->req_num_entries = req_num_entries; /* zero indicates lots */
-       q_e->unknown_0 = unk_0; /* this gets returned in the response */
-       q_e->acb_mask  = acb_mask;
-       q_e->unknown_1 = unk_1;
-       q_e->max_size = size;
+       sam->grp_idx = grp_idx;
+       init_str_hdr(&sam->hdr_grp_name, len_grp_name, len_grp_name,
+                    len_grp_name != 0);
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a SAM_ENTRY5 structure.
 ********************************************************************/
 
-BOOL samr_io_q_enum_dom_users(char *desc,  SAMR_Q_ENUM_DOM_USERS *q_e, prs_struct *ps, int depth)
+static BOOL sam_io_sam_entry5(char *desc, SAM_ENTRY5 * sam,
+                             prs_struct *ps, int depth)
 {
-       if (q_e == NULL)
+       if (sam == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_q_enum_dom_users");
+       prs_debug(ps, depth, desc, "sam_io_sam_entry5");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
-               return False;
-       if(!prs_align(ps))
-               return False;
-
-       if(!prs_uint16("req_num_entries", ps, depth, &q_e->req_num_entries))
-               return False;
-       if(!prs_uint16("unknown_0      ", ps, depth, &q_e->unknown_0))
-               return False;
-
-       if(!prs_uint16("acb_mask       ", ps, depth, &q_e->acb_mask))
-               return False;
-       if(!prs_uint16("unknown_1      ", ps, depth, &q_e->unknown_1))
-               return False;
-
-       if(!prs_uint32("max_size       ", ps, depth, &q_e->max_size))
+       if(!prs_uint32("grp_idx", ps, depth, &sam->grp_idx))
                return False;
-
-       if(!prs_align(ps))
+       if(!smb_io_strhdr("strhdr", &sam->hdr_grp_name, ps, depth))
                return False;
 
        return True;
 }
 
-
 /*******************************************************************
- Inits a SAMR_R_ENUM_DOM_USERS structure.
+inits a SAM_ENTRY structure.
 ********************************************************************/
 
-void init_samr_r_enum_dom_users(SAMR_R_ENUM_DOM_USERS *r_u,
-               uint16 total_num_entries, uint16 unk_0,
-               uint32 num_sam_entries, SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES], uint32 status)
+void init_sam_entry(SAM_ENTRY * sam, uint32 len_sam_name, uint32 rid)
 {
-       int i;
+       DEBUG(10, ("init_sam_entry: %d %d\n", len_sam_name, rid));
 
-       DEBUG(5,("init_samr_r_enum_dom_users\n"));
+       sam->rid = rid;
+       init_uni_hdr(&sam->hdr_name, len_sam_name);
+}
 
-       if (num_sam_entries >= MAX_SAM_ENTRIES) {
-               num_sam_entries = MAX_SAM_ENTRIES;
-               DEBUG(5,("limiting number of entries to %d\n",
-                        num_sam_entries));
-       }
+/*******************************************************************
+reads or writes a SAM_ENTRY structure.
+********************************************************************/
 
-       r_u->total_num_entries = total_num_entries;
-       r_u->unknown_0         = unk_0;
+static BOOL sam_io_sam_entry(char *desc, SAM_ENTRY * sam,
+                            prs_struct *ps, int depth)
+{
+       if (sam == NULL)
+               return False;
 
-       if (total_num_entries > 0) {
-               r_u->ptr_entries1 = 1;
-               r_u->ptr_entries2 = 1;
-               r_u->num_entries2 = num_sam_entries;
-               r_u->num_entries3 = num_sam_entries;
-
-               SMB_ASSERT_ARRAY(r_u->sam, num_sam_entries);
-               SMB_ASSERT_ARRAY(r_u->uni_acct_name, num_sam_entries);
-
-               for (i = 0; i < num_sam_entries; i++) {
-                       init_sam_entry(&(r_u->sam[i]),
-                                      pass[i].uni_user_name.uni_str_len,
-                                      pass[i].user_rid);
-
-                       copy_unistr2(&r_u->uni_acct_name[i], &(pass[i].uni_user_name));
-               }
-
-               r_u->num_entries4 = num_sam_entries;
-       } else {
-               r_u->ptr_entries1 = 0;
-               r_u->num_entries2 = num_sam_entries;
-               r_u->ptr_entries2 = 1;
-       }
-
-       r_u->status = status;
-}
-
-/*******************************************************************
- Reads or writes a structure.
-********************************************************************/
-
-BOOL samr_io_r_enum_dom_users(char *desc,  SAMR_R_ENUM_DOM_USERS *r_u, prs_struct *ps, int depth)
-{
-       int i;
-
-       if (r_u == NULL)
-               return False;
-
-       prs_debug(ps, depth, desc, "samr_io_r_enum_dom_users");
+       prs_debug(ps, depth, desc, "sam_io_sam_entry");
        depth++;
 
        if(!prs_align(ps))
                return False;
-
-       if(!prs_uint16("total_num_entries", ps, depth, &r_u->total_num_entries))
-               return False;
-       if(!prs_uint16("unknown_0        ", ps, depth, &r_u->unknown_0))
-               return False;
-       if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
+       if(!prs_uint32("rid", ps, depth, &sam->rid))
                return False;
-
-       if (r_u->total_num_entries != 0 && r_u->ptr_entries1 != 0) {
-               if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
-                       return False;
-               if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
-                       return False;
-               if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
-                       return False;
-
-               SMB_ASSERT_ARRAY(r_u->sam, r_u->num_entries2);
-
-               for (i = 0; i < r_u->num_entries2; i++) {
-                       if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth))
-                               return False;
-               }
-
-               SMB_ASSERT_ARRAY(r_u->uni_acct_name, r_u->num_entries2);
-
-               for (i = 0; i < r_u->num_entries2; i++) {
-                       if(!smb_io_unistr2("", &r_u->uni_acct_name[i],
-                                       r_u->sam[i].hdr_name.buffer, ps, depth))
-                               return False;
-               }
-
-               if(!prs_align(ps))
-                       return False;
-
-               if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
-                       return False;
-       }
-
-       if(!prs_uint32("status", ps, depth, &r_u->status))
+       if(!smb_io_unihdr("unihdr", &sam->hdr_name, ps, depth)) /* account name unicode string header */
                return False;
 
        return True;
 }
 
 /*******************************************************************
- Inits a SAMR_Q_ENUM_DOM_ALIASES structure.
+inits a SAMR_Q_ENUM_DOM_USERS structure.
 ********************************************************************/
 
-void init_samr_q_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES *q_e, POLICY_HND *pol, uint32 size)
+void init_samr_q_enum_dom_users(SAMR_Q_ENUM_DOM_USERS * q_e, POLICY_HND *pol,
+                               uint32 start_idx,
+                               uint16 acb_mask, uint16 unk_1, uint32 size)
 {
-       DEBUG(5,("init_q_enum_dom_aliases\n"));
+       DEBUG(5, ("init_samr_q_enum_dom_users\n"));
 
-       memcpy(&q_e->pol, pol, sizeof(*pol));
+       q_e->pol = *pol;
 
-       q_e->unknown_0 = 0;
+       q_e->start_idx = start_idx;     /* zero indicates lots */
+       q_e->acb_mask = acb_mask;
+       q_e->unknown_1 = unk_1;
        q_e->max_size = size;
 }
 
-
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_q_enum_dom_aliases(char *desc,  SAMR_Q_ENUM_DOM_ALIASES *q_e, prs_struct *ps, int depth)
+BOOL samr_io_q_enum_dom_users(char *desc, SAMR_Q_ENUM_DOM_USERS * q_e,
+                             prs_struct *ps, int depth)
 {
        if (q_e == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_q_enum_dom_aliases");
+       prs_debug(ps, depth, desc, "samr_io_q_enum_dom_users");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
-               return False;
-       if(!prs_align(ps))
+       if(!smb_io_pol_hnd("domain_pol", &q_e->pol, ps, depth))
                return False;
 
-       if(!prs_uint32("unknown_0", ps, depth, &q_e->unknown_0))
+       if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
                return False;
-       if(!prs_uint32("max_size ", ps, depth, &q_e->max_size ))
+       if(!prs_uint16("acb_mask ", ps, depth, &q_e->acb_mask))
+               return False;
+       if(!prs_uint16("unknown_1", ps, depth, &q_e->unknown_1))
                return False;
 
-       if(!prs_align(ps))
+       if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
                return False;
 
        return True;
@@ -1405,72 +1241,54 @@ BOOL samr_io_q_enum_dom_aliases(char *desc,  SAMR_Q_ENUM_DOM_ALIASES *q_e, prs_s
 
 
 /*******************************************************************
- Inits a SAMR_R_ENUM_DOM_ALIASES structure.
+inits a SAMR_R_ENUM_DOM_USERS structure.
 ********************************************************************/
 
-void init_samr_r_enum_dom_aliases(SAMR_R_ENUM_DOM_ALIASES *r_u,
-               uint32 num_sam_entries, SAM_USER_INFO_21 grps[MAX_SAM_ENTRIES],
-               uint32 status)
+void init_samr_r_enum_dom_users(SAMR_R_ENUM_DOM_USERS * r_u,
+                               uint32 next_idx, uint32 num_sam_entries)
 {
-       int i;
-
-       DEBUG(5,("init_samr_r_enum_dom_aliases\n"));
-
-       if (num_sam_entries >= MAX_SAM_ENTRIES) {
-               num_sam_entries = MAX_SAM_ENTRIES;
-               DEBUG(5,("limiting number of entries to %d\n", 
-                        num_sam_entries));
-       }
+       DEBUG(5, ("init_samr_r_enum_dom_users\n"));
 
-       r_u->num_entries  = num_sam_entries;
+       r_u->next_idx = next_idx;
 
-       if (num_sam_entries > 0) {
-               r_u->ptr_entries  = 1;
-               r_u->num_entries2 = num_sam_entries;
+       if (num_sam_entries != 0) {
+               r_u->ptr_entries1 = 1;
                r_u->ptr_entries2 = 1;
+               r_u->num_entries2 = num_sam_entries;
                r_u->num_entries3 = num_sam_entries;
 
-               SMB_ASSERT_ARRAY(r_u->sam, num_sam_entries);
-
-               for (i = 0; i < num_sam_entries; i++) {
-                       init_sam_entry(&r_u->sam[i],
-                                      grps[i].uni_user_name.uni_str_len,
-                                      grps[i].user_rid);
-
-                       copy_unistr2(&r_u->uni_grp_name[i], &(grps[i].uni_user_name));
-               }
-
                r_u->num_entries4 = num_sam_entries;
        } else {
-               r_u->ptr_entries = 0;
+               r_u->ptr_entries1 = 0;
+               r_u->num_entries2 = num_sam_entries;
+               r_u->ptr_entries2 = 1;
        }
-
-       r_u->status = status;
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_r_enum_dom_aliases(char *desc,  SAMR_R_ENUM_DOM_ALIASES *r_u, prs_struct *ps, int depth)
+BOOL samr_io_r_enum_dom_users(char *desc, SAMR_R_ENUM_DOM_USERS * r_u,
+                             prs_struct *ps, int depth)
 {
-       int i;
+       uint32 i;
 
        if (r_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_r_enum_dom_aliases");
+       prs_debug(ps, depth, desc, "samr_io_r_enum_dom_users");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("num_entries", ps, depth, &r_u->num_entries))
+       if(!prs_uint32("next_idx    ", ps, depth, &r_u->next_idx))
                return False;
-       if(!prs_uint32("ptr_entries", ps, depth, &r_u->ptr_entries))
+       if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
                return False;
 
-       if (r_u->num_entries != 0 && r_u->ptr_entries != 0) {
+       if (r_u->ptr_entries1 != 0) {
                if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
                        return False;
                if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
@@ -1478,55 +1296,66 @@ BOOL samr_io_r_enum_dom_aliases(char *desc,  SAMR_R_ENUM_DOM_ALIASES *r_u, prs_s
                if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
                        return False;
 
-               SMB_ASSERT_ARRAY(r_u->sam, r_u->num_entries);
+               if (UNMARSHALLING(ps) && (r_u->num_entries2 != 0)) {
+                       r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
+                       r_u->uni_acct_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
+               }
+
+               if ((r_u->sam == NULL || r_u->uni_acct_name == NULL) && r_u->num_entries2 != 0) {
+                       DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOM_USERS\n"));
+                       r_u->num_entries4 = 0;
+                       r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
+                       return False;
+               }
 
-               for (i = 0; i < r_u->num_entries; i++) {
+               for (i = 0; i < r_u->num_entries2; i++) {
                        if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth))
                                return False;
                }
 
-               for (i = 0; i < r_u->num_entries; i++) {
-                       if(!smb_io_unistr2("", &r_u->uni_grp_name[i], r_u->sam[i].hdr_name.buffer, ps, depth))
+               for (i = 0; i < r_u->num_entries2; i++) {
+                       if(!smb_io_unistr2("", &r_u->uni_acct_name[i],r_u->sam[i].hdr_name.buffer, ps,depth))
                                return False;
                }
 
-               if(!prs_align(ps))
-                       return False;
-
-               if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
-                       return False;
        }
 
+       if(!prs_align(ps))
+               return False;
+               
+       if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
+               return False;
        if(!prs_uint32("status", ps, depth, &r_u->status))
                return False;
 
        return True;
 }
 
-
 /*******************************************************************
- Inits a SAMR_Q_QUERY_DISPINFO structure.
+inits a SAMR_Q_QUERY_DISPINFO structure.
 ********************************************************************/
 
-void init_samr_q_query_dispinfo(SAMR_Q_QUERY_DISPINFO *q_e, POLICY_HND *pol,
-                               uint16 switch_level, uint32 start_idx, uint32 size)
+void init_samr_q_query_dispinfo(SAMR_Q_QUERY_DISPINFO * q_e, POLICY_HND *pol,
+                               uint16 switch_level, uint32 start_idx,
+                               uint32 max_entries)
 {
-       DEBUG(5,("init_q_query_dispinfo\n"));
+       DEBUG(5, ("init_samr_q_query_dispinfo\n"));
 
-       memcpy(&q_e->pol, pol, sizeof(*pol));
+       q_e->domain_pol = *pol;
 
        q_e->switch_level = switch_level;
 
        q_e->start_idx = start_idx;
-       q_e->max_entries = 0;
-       q_e->max_size  = size;
+       q_e->max_entries = max_entries;
+       q_e->max_size = 0xffff; /* Not especially useful */
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_q_query_dispinfo(char *desc,  SAMR_Q_QUERY_DISPINFO *q_e, prs_struct *ps, int depth)
+BOOL samr_io_q_query_dispinfo(char *desc, SAMR_Q_QUERY_DISPINFO * q_e,
+                             prs_struct *ps, int depth)
 {
        if (q_e == NULL)
                return False;
@@ -1537,19 +1366,14 @@ BOOL samr_io_q_query_dispinfo(char *desc,  SAMR_Q_QUERY_DISPINFO *q_e, prs_struc
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
-               return False;
-       if(!prs_align(ps))
+       if(!smb_io_pol_hnd("domain_pol", &q_e->domain_pol, ps, depth))
                return False;
 
        if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level))
                return False;
-#if 0
-       if(!prs_uint16("unknown_0   ", ps, depth, &q_e->unknown_0))
+       if(!prs_align(ps))
                return False;
-#else
-       prs_align(ps);
-#endif
+
        if(!prs_uint32("start_idx   ", ps, depth, &q_e->start_idx))
                return False;
        if(!prs_uint32("max_entries ", ps, depth, &q_e->max_entries))
@@ -1557,90 +1381,82 @@ BOOL samr_io_q_query_dispinfo(char *desc,  SAMR_Q_QUERY_DISPINFO *q_e, prs_struc
        if(!prs_uint32("max_size    ", ps, depth, &q_e->max_size))
                return False;
 
-       if(!prs_align(ps))
-               return False;
-
        return True;
 }
 
-
 /*******************************************************************
- Inits a SAM_INFO_2 structure.
+inits a SAM_DISPINFO_1 structure.
 ********************************************************************/
 
-void init_sam_info_2(SAM_INFO_2 *sam, uint32 acb_mask,
-               uint32 start_idx, uint32 num_sam_entries,
-               SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES])
+void init_sam_dispinfo_1(SAM_DISPINFO_1 * sam, uint32 *num_entries,
+                        uint32 *data_size, uint32 start_idx,
+                        SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES])
 {
-       int i;
-       int entries_added;
+       uint32 len_sam_name, len_sam_full, len_sam_desc;
+       uint32 max_entries, max_data_size;
+       uint32 dsize = 0;
+       uint32 i;
 
-       DEBUG(5,("init_sam_info_2\n"));
+       ZERO_STRUCTP(sam);
 
-       if (num_sam_entries >= MAX_SAM_ENTRIES) {
-               num_sam_entries = MAX_SAM_ENTRIES;
-               DEBUG(5,("limiting number of entries to %d\n", 
-                        num_sam_entries));
-       }
+       max_entries = *num_entries;
+       max_data_size = *data_size;
 
-       for (i = start_idx, entries_added = 0; i < num_sam_entries; i++) {
-               if ((pass[i].acb_info & acb_mask) == acb_mask) {
-                       init_sam_entry2(&sam->sam[entries_added],
-                                       start_idx + entries_added + 1,
-                                       pass[i].uni_user_name.uni_str_len,
-                                       pass[i].uni_acct_desc.uni_str_len,
-                                       pass[i].user_rid,
-                                       pass[i].acb_info);
+       DEBUG(5, ("init_sam_dispinfo_1: max_entries: %d max_dsize: 0x%x\n",
+                 max_entries, max_data_size));
 
-                       copy_unistr2(&sam->str[entries_added].uni_srv_name, &pass[i].uni_user_name);
-                       copy_unistr2(&sam->str[entries_added].uni_srv_desc, &pass[i].uni_acct_desc);
+       for (i = 0; (i < max_entries) && (dsize < max_data_size); i++) {
+               len_sam_name = pass[i].uni_user_name.uni_str_len;
+               len_sam_full = pass[i].uni_full_name.uni_str_len;
+               len_sam_desc = pass[i].uni_acct_desc.uni_str_len;
 
-                       entries_added++;
-               }
+               init_sam_entry1(&sam->sam[i], start_idx + i + 1,
+                               len_sam_name, len_sam_full, len_sam_desc,
+                               pass[i].user_rid, pass[i].acb_info);
 
-               sam->num_entries   = entries_added;
-               sam->ptr_entries   = 1;
-               sam->num_entries2  = entries_added;
+               copy_unistr2(&sam->str[i].uni_acct_name, &pass[i].uni_user_name);
+               copy_unistr2(&sam->str[i].uni_full_name, &pass[i].uni_full_name);
+               copy_unistr2(&sam->str[i].uni_acct_desc, &pass[i].uni_acct_desc);
+
+               dsize += sizeof(SAM_ENTRY1);
+               dsize += len_sam_name + len_sam_full + len_sam_desc;
        }
+
+       *num_entries = i;
+       *data_size = dsize;
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-static BOOL sam_io_sam_info_2(char *desc,  SAM_INFO_2 *sam, prs_struct *ps, int depth)
+static BOOL sam_io_sam_dispinfo_1(char *desc, SAM_DISPINFO_1 * sam,
+                                 uint32 num_entries,
+                                 prs_struct *ps, int depth)
 {
-       int i;
+       uint32 i;
 
        if (sam == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "sam_io_sam_info_2");
+       prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_1");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("num_entries  ", ps, depth, &sam->num_entries))
-               return False;
-       if(!prs_uint32("ptr_entries  ", ps, depth, &sam->ptr_entries))
-               return False;
-
-       if(!prs_uint32("num_entries2 ", ps, depth, &sam->num_entries2))
-               return False;
+       SMB_ASSERT_ARRAY(sam->sam, num_entries);
 
-       SMB_ASSERT_ARRAY(sam->sam, sam->num_entries);
-
-       for (i = 0; i < sam->num_entries; i++) {
-               if(!sam_io_sam_entry2("", &sam->sam[i], ps, depth))
+       for (i = 0; i < num_entries; i++) {
+               if(!sam_io_sam_entry1("", &sam->sam[i], ps, depth))
                        return False;
        }
 
-       for (i = 0; i < sam->num_entries; i++) {
-               if(!sam_io_sam_str("", &sam->str[i],
-                                sam->sam[i].hdr_srv_name.buffer,
-                                sam->sam[i].hdr_srv_desc.buffer,
-                                ps, depth))
+       for (i = 0; i < num_entries; i++) {
+               if(!sam_io_sam_str1("", &sam->str[i],
+                             sam->sam[i].hdr_acct_name.buffer,
+                             sam->sam[i].hdr_user_name.buffer,
+                             sam->sam[i].hdr_user_desc.buffer, ps, depth))
                        return False;
        }
 
@@ -1648,896 +1464,824 @@ static BOOL sam_io_sam_info_2(char *desc,  SAM_INFO_2 *sam, prs_struct *ps, int
 }
 
 /*******************************************************************
- Inits a SAM_INFO_1 structure.
+inits a SAM_DISPINFO_2 structure.
 ********************************************************************/
 
-void init_sam_info_1(SAM_INFO_1 *sam, uint32 acb_mask,
-               uint32 start_idx, uint32 num_sam_entries,
-               SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES])
+void init_sam_dispinfo_2(SAM_DISPINFO_2 * sam, uint32 *num_entries,
+                        uint32 *data_size, uint32 start_idx,
+                        SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES])
 {
-       int i;
-       int entries_added;
+       uint32 len_sam_name, len_sam_desc;
+       uint32 max_entries, max_data_size;
+       uint32 dsize = 0;
+       uint32 i;
 
-       DEBUG(5,("init_sam_info_1\n"));
+       DEBUG(5, ("init_sam_dispinfo_2\n"));
 
-       if (num_sam_entries >= MAX_SAM_ENTRIES) {
-               num_sam_entries = MAX_SAM_ENTRIES;
-               DEBUG(5,("limiting number of entries to %d\n", 
-                        num_sam_entries));
-       }
-       DEBUG(5,("num_sam_entries: %u, start_idx: %u\n",num_sam_entries,
-                num_sam_entries));
-
-       for (i = 0, entries_added = 0; 
-            i < num_sam_entries; i++) {
-               if ((pass[i].acb_info & acb_mask) == acb_mask) {
-                       init_sam_entry1(&sam->sam[entries_added],
-                                               start_idx + entries_added + 1,
-                                               pass[i].uni_user_name.uni_str_len,
-                                               pass[i].uni_full_name.uni_str_len, 
-                                               pass[i].uni_acct_desc.uni_str_len,
-                                               pass[i].user_rid,
-                                               pass[i].acb_info);
-
-                       copy_unistr2(&sam->str[entries_added].uni_acct_name, &pass[i].uni_user_name);
-                       copy_unistr2(&sam->str[entries_added].uni_full_name, &pass[i].uni_full_name);
-                       copy_unistr2(&sam->str[entries_added].uni_acct_desc, &pass[i].uni_acct_desc);
-
-                       entries_added++;
-               } 
+       ZERO_STRUCTP(sam);
+
+       max_entries = *num_entries;
+       max_data_size = *data_size;
+
+       for (i = 0; (i < max_entries) && (dsize < max_data_size); i++) {
+               len_sam_name = pass[i].uni_user_name.uni_str_len;
+               len_sam_desc = pass[i].uni_acct_desc.uni_str_len;
+         
+               init_sam_entry2(&sam->sam[i], start_idx + i + 1,
+                         len_sam_name, len_sam_desc,
+                         pass[i].user_rid, pass[i].acb_info);
+         
+               copy_unistr2(&sam->str[i].uni_srv_name,
+                      &pass[i].uni_user_name);
+               copy_unistr2(&sam->str[i].uni_srv_desc,
+                      &pass[i].uni_acct_desc);
+         
+               dsize += sizeof(SAM_ENTRY2);
+               dsize += len_sam_name + len_sam_desc;
        }
 
-       sam->num_entries   = entries_added;
-       sam->ptr_entries   = 1;
-       sam->num_entries2  = entries_added;
+       *num_entries = i;
+       *data_size = dsize;
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-static BOOL sam_io_sam_info_1(char *desc,  SAM_INFO_1 *sam, prs_struct *ps, int depth)
+static BOOL sam_io_sam_dispinfo_2(char *desc, SAM_DISPINFO_2 * sam,
+                                 uint32 num_entries,
+                                 prs_struct *ps, int depth)
 {
-       int i;
+       uint32 i;
 
        if (sam == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "sam_io_sam_info_1");
+       prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_2");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("num_entries  ", ps, depth, &sam->num_entries))
-               return False;
-       if(!prs_uint32("ptr_entries  ", ps, depth, &sam->ptr_entries))
-               return False;
-
-       if(!prs_uint32("num_entries2 ", ps, depth, &sam->num_entries2))
-               return False;
-
-       SMB_ASSERT_ARRAY(sam->sam, sam->num_entries);
+       SMB_ASSERT_ARRAY(sam->sam, num_entries);
 
-       for (i = 0; i < sam->num_entries; i++) {
-               if(!sam_io_sam_entry1("", &sam->sam[i], ps, depth))
+       for (i = 0; i < num_entries; i++) {
+               if(!sam_io_sam_entry2("", &sam->sam[i], ps, depth))
                        return False;
        }
 
-       for (i = 0; i < sam->num_entries; i++) {
-               if(!sam_io_sam_str1 ("", &sam->str[i],
-                                                        sam->sam[i].hdr_acct_name.buffer,
-                                                        sam->sam[i].hdr_user_name.buffer,
-                                                        sam->sam[i].hdr_user_desc.buffer,
-                                                        ps, depth))
-               return False;
+       for (i = 0; i < num_entries; i++) {
+               if(!sam_io_sam_str2("", &sam->str[i],
+                             sam->sam[i].hdr_srv_name.buffer,
+                             sam->sam[i].hdr_srv_desc.buffer, ps, depth))
+                       return False;
        }
 
        return True;
 }
 
 /*******************************************************************
- Inits a SAMR_R_QUERY_DISPINFO structure.
+inits a SAM_DISPINFO_3 structure.
 ********************************************************************/
 
-void init_samr_r_query_dispinfo(SAMR_R_QUERY_DISPINFO *r_u,
-               uint16 switch_level, SAM_INFO_CTR *ctr, uint32 status)
+void init_sam_dispinfo_3(SAM_DISPINFO_3 * sam, uint32 *num_entries,
+                        uint32 *data_size, uint32 start_idx,
+                        DOMAIN_GRP * grp)
 {
-       DEBUG(5,("init_samr_r_query_dispinfo\n"));
+       uint32 len_sam_name, len_sam_desc;
+       uint32 max_entries, max_data_size;
+       uint32 dsize = 0;
+       uint32 i;
 
-       if (status == 0x0 || status == 0x105) {
-               r_u->unknown_0 = 0x0000001;
-               r_u->unknown_1 = 0x0000001;
-       } else {
-               r_u->unknown_0 = 0x0;
-               r_u->unknown_1 = 0x0;
+       DEBUG(5, ("init_sam_dispinfo_3\n"));
+
+       ZERO_STRUCTP(sam);
+
+       max_entries = *num_entries;
+       max_data_size = *data_size;
+
+       for (i = 0; (i < max_entries) && (dsize < max_data_size); i++) {
+               len_sam_name = strlen(grp[i].name);
+               len_sam_desc = strlen(grp[i].comment);
+
+               init_sam_entry3(&sam->sam[i], start_idx + i + 1, len_sam_name, len_sam_desc, grp[i].rid);
+         
+               init_unistr2(&sam->str[i].uni_grp_name, grp[i].name, len_sam_name);
+               init_unistr2(&sam->str[i].uni_grp_desc, grp[i].comment, len_sam_desc);
+         
+               dsize += sizeof(SAM_ENTRY3);
+               dsize += (len_sam_name + len_sam_desc) * 2;
+               dsize += 14;
        }
 
-       r_u->switch_level = switch_level;
-       r_u->ctr = ctr;
-       r_u->status = status;
+       *num_entries = i;
+       *data_size = dsize;
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_r_query_dispinfo(char *desc,  SAMR_R_QUERY_DISPINFO *r_u, prs_struct *ps, int depth)
+static BOOL sam_io_sam_dispinfo_3(char *desc, SAM_DISPINFO_3 * sam,
+                                 uint32 num_entries,
+                                 prs_struct *ps, int depth)
 {
-       if (r_u == NULL)
+       uint32 i;
+
+       if (sam == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_r_query_dispinfo");
+       prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_3");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("unknown_0    ", ps, depth, &r_u->unknown_0))
-               return False;
-       if(!prs_uint32("unknown_1    ", ps, depth, &r_u->unknown_1))
-               return False;
-       if(!prs_uint16("switch_level ", ps, depth, &r_u->switch_level))
-               return False;
-
-       if(!prs_align(ps))
-               return False;
+       SMB_ASSERT_ARRAY(sam->sam, num_entries);
 
-       switch (r_u->switch_level) {
-       case 0x1:
-               if(!sam_io_sam_info_1("users", r_u->ctr->sam.info1, ps, depth))
+       for (i = 0; i < num_entries; i++) {
+               if(!sam_io_sam_entry3("", &sam->sam[i], ps, depth))
                        return False;
-               break;
-       case 0x2:
-               if(!sam_io_sam_info_2("servers", r_u->ctr->sam.info2, ps, depth))
-                       return False;
-               break;
-       default:
-               DEBUG(5,("samr_io_r_query_dispinfo: unknown switch value\n"));
-               break;
        }
 
-       if(!prs_uint32("status", ps, depth, &r_u->status))
-               return False;
+       for (i = 0; i < num_entries; i++) {
+               if(!sam_io_sam_str3("", &sam->str[i],
+                             sam->sam[i].hdr_grp_name.buffer,
+                             sam->sam[i].hdr_grp_desc.buffer, ps, depth))
+                       return False;
+       }
 
        return True;
 }
 
 /*******************************************************************
- Inits a SAMR_Q_ENUM_DOM_GROUPS structure.
+inits a SAM_DISPINFO_4 structure.
 ********************************************************************/
 
-void init_samr_q_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS *q_e, POLICY_HND *pol,
-                               uint16 switch_level, uint32 start_idx, uint32 size)
+void init_sam_dispinfo_4(SAM_DISPINFO_4 * sam, uint32 *num_entries,
+                        uint32 *data_size, uint32 start_idx,
+                        SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES])
 {
-       DEBUG(5,("init_q_enum_dom_groups\n"));
+       fstring sam_name;
+       uint32 len_sam_name;
+       uint32 max_entries, max_data_size;
+       uint32 dsize = 0;
+       uint32 i;
 
-       memcpy(&q_e->pol, pol, sizeof(*pol));
+       DEBUG(5, ("init_sam_dispinfo_4\n"));
 
-       q_e->switch_level = switch_level;
+       ZERO_STRUCTP(sam);
 
-       q_e->unknown_0 = 0;
-       q_e->start_idx = start_idx;
-       q_e->unknown_1 = 0x000007d0;
-       q_e->max_size  = size;
+       max_entries = *num_entries;
+       max_data_size = *data_size;
+
+       for (i = 0; (i < max_entries) && (dsize < max_data_size); i++) {
+               len_sam_name = pass[i].uni_user_name.uni_str_len;
+         
+               init_sam_entry4(&sam->sam[i], start_idx + i + 1,
+                         len_sam_name);
+         
+               unistr2_to_ascii(sam_name, &pass[i].uni_user_name,
+                          sizeof(sam_name));
+               init_string2(&sam->str[i].acct_name, sam_name,
+                      len_sam_name);
+         
+               dsize += sizeof(SAM_ENTRY4);
+               dsize += len_sam_name;
+       }
+       
+       *num_entries = i;
+       *data_size = dsize;
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_q_enum_dom_groups(char *desc,  SAMR_Q_ENUM_DOM_GROUPS *q_e, prs_struct *ps, int depth)
+static BOOL sam_io_sam_dispinfo_4(char *desc, SAM_DISPINFO_4 * sam,
+                                 uint32 num_entries,
+                                 prs_struct *ps, int depth)
 {
-       if (q_e == NULL)
+       uint32 i;
+
+       if (sam == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_q_enum_dom_groups");
+       prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_4");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
-               return False;
-       if(!prs_align(ps))
-               return False;
+       SMB_ASSERT_ARRAY(sam->sam, num_entries);
 
-       if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level))
-               return False;
-       if(!prs_uint16("unknown_0   ", ps, depth, &q_e->unknown_0))
-               return False;
-       if(!prs_uint32("start_idx   ", ps, depth, &q_e->start_idx))
-               return False;
-       if(!prs_uint32("unknown_1   ", ps, depth, &q_e->unknown_1))
-               return False;
-       if(!prs_uint32("max_size    ", ps, depth, &q_e->max_size))
-               return False;
+       for (i = 0; i < num_entries; i++) {
+               if(!sam_io_sam_entry4("", &sam->sam[i], ps, depth))
+                       return False;
+       }
 
-       if(!prs_align(ps))
-               return False;
+       for (i = 0; i < num_entries; i++) {
+               if(!smb_io_string2("acct_name", &sam->str[i].acct_name,
+                            sam->sam[i].hdr_acct_name.buffer, ps, depth))
+                       return False;
+               if(!prs_align(ps))
+                       return False;
+       }
 
        return True;
 }
 
-
 /*******************************************************************
- Inits a SAMR_R_ENUM_DOM_GROUPS structure.
+inits a SAM_DISPINFO_5 structure.
 ********************************************************************/
 
-void init_samr_r_enum_dom_groups(SAMR_R_ENUM_DOM_GROUPS *r_u,
-               uint32 start_idx, uint32 num_sam_entries,
-               SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES],
-               uint32 status)
+void init_sam_dispinfo_5(SAM_DISPINFO_5 * sam, uint32 *num_entries,
+                        uint32 *data_size, uint32 start_idx,
+                        DOMAIN_GRP * grp)
 {
-       int i;
-       int entries_added;
+       uint32 len_sam_name;
+       uint32 max_entries, max_data_size;
+       uint32 dsize = 0;
+       uint32 i;
 
-       DEBUG(5,("init_samr_r_enum_dom_groups\n"));
+       DEBUG(5, ("init_sam_dispinfo_5\n"));
 
-       if (num_sam_entries >= MAX_SAM_ENTRIES) {
-               num_sam_entries = MAX_SAM_ENTRIES;
-               DEBUG(5,("limiting number of entries to %d\n", 
-                        num_sam_entries));
-       }
+       ZERO_STRUCTP(sam);
 
-       if (status == 0x0) {
-               for (i = start_idx, entries_added = 0; i < num_sam_entries; i++) {
-                       init_sam_entry3(&r_u->sam[entries_added],
-                                       start_idx + entries_added + 1,
-                                       pass[i].uni_user_name.uni_str_len,
-                                       pass[i].uni_acct_desc.uni_str_len,
-                                       pass[i].user_rid);
-
-                       copy_unistr2(&r_u->str[entries_added].uni_grp_name, 
-                                               &pass[i].uni_user_name);
-                       copy_unistr2(&r_u->str[entries_added].uni_grp_desc, 
-                                               &pass[i].uni_acct_desc);
-
-                       entries_added++;
-               }
+       max_entries = *num_entries;
+       max_data_size = *data_size;
 
-               if (entries_added > 0) {
-                       r_u->unknown_0 = 0x0000492;
-                       r_u->unknown_1 = 0x000049a;
-               } else {
-                       r_u->unknown_0 = 0x0;
-                       r_u->unknown_1 = 0x0;
-               }
-               r_u->switch_level  = 3;
-               r_u->num_entries   = entries_added;
-               r_u->ptr_entries   = 1;
-               r_u->num_entries2  = entries_added;
-       } else {
-               r_u->switch_level = 0;
+       for (i = 0; (i < max_entries) && (dsize < max_data_size); i++) {
+               len_sam_name = strlen(grp[i].name);
+         
+               init_sam_entry5(&sam->sam[i], start_idx + i + 1,
+                               len_sam_name);
+         
+               init_string2(&sam->str[i].grp_name, grp[i].name,
+                               len_sam_name);
+         
+               dsize += sizeof(SAM_ENTRY5);
+               dsize += len_sam_name;
        }
-
-       r_u->status = status;
+       
+       *num_entries = i;
+       *data_size = dsize;
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_r_enum_dom_groups(char *desc,  SAMR_R_ENUM_DOM_GROUPS *r_u, prs_struct *ps, int depth)
+static BOOL sam_io_sam_dispinfo_5(char *desc, SAM_DISPINFO_5 * sam,
+                                 uint32 num_entries,
+                                 prs_struct *ps, int depth)
 {
-       int i;
+       uint32 i;
 
-       if (r_u == NULL)
+       if (sam == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_r_enum_dom_groups");
+       prs_debug(ps, depth, desc, "sam_io_sam_dispinfo_5");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("unknown_0    ", ps, depth, &r_u->unknown_0))
-               return False;
-       if(!prs_uint32("unknown_1    ", ps, depth, &r_u->unknown_1))
-               return False;
-       if(!prs_uint32("switch_level ", ps, depth, &r_u->switch_level))
-               return False;
+       SMB_ASSERT_ARRAY(sam->sam, num_entries);
 
-       if (r_u->switch_level != 0) {
-               if(!prs_uint32("num_entries  ", ps, depth, &r_u->num_entries))
-                       return False;
-               if(!prs_uint32("ptr_entries  ", ps, depth, &r_u->ptr_entries))
+       for (i = 0; i < num_entries; i++) {
+               if(!sam_io_sam_entry5("", &sam->sam[i], ps, depth))
                        return False;
+       }
 
-               if(!prs_uint32("num_entries2 ", ps, depth, &r_u->num_entries2))
+       for (i = 0; i < num_entries; i++) {
+               if(!smb_io_string2("grp_name", &sam->str[i].grp_name,
+                            sam->sam[i].hdr_grp_name.buffer, ps, depth))
+                       return False;
+               if(!prs_align(ps))
                        return False;
-
-               SMB_ASSERT_ARRAY(r_u->sam, r_u->num_entries);
-
-               for (i = 0; i < r_u->num_entries; i++) {
-                       if(!sam_io_sam_entry3("", &r_u->sam[i], ps, depth))
-                               return False;
-               }
-
-               for (i = 0; i < r_u->num_entries; i++) {
-                       if(!sam_io_sam_str3 ("", &r_u->str[i],
-                                            r_u->sam[i].hdr_grp_name.buffer,
-                                            r_u->sam[i].hdr_grp_desc.buffer,
-                                            ps, depth))
-                               return False;
-               }
        }
 
-       if(!prs_uint32("status", ps, depth, &r_u->status))
-               return False;
-
        return True;
 }
 
 /*******************************************************************
- Inits a SAMR_Q_QUERY_ALIASINFO structure.
+inits a SAMR_R_QUERY_DISPINFO structure.
 ********************************************************************/
 
-void init_samr_q_query_aliasinfo(SAMR_Q_QUERY_ALIASINFO *q_e,
-                               POLICY_HND *pol,
-                               uint16 switch_level)
+void init_samr_r_query_dispinfo(SAMR_R_QUERY_DISPINFO * r_u,
+                               uint32 num_entries, uint32 data_size,
+                               uint16 switch_level, SAM_DISPINFO_CTR * ctr,
+                               uint32 status)
 {
-       DEBUG(5,("init_q_query_aliasinfo\n"));
+       DEBUG(5, ("init_samr_r_query_dispinfo: level %d\n", switch_level));
 
-       memcpy(&q_e->pol, pol, sizeof(*pol));
+       r_u->total_size = data_size;    /* not calculated */
+       r_u->data_size = data_size;
 
-       q_e->switch_level = switch_level;
+       r_u->switch_level = switch_level;
+       r_u->num_entries = num_entries;
+
+       if (num_entries==0)
+               r_u->ptr_entries = 0;
+       else
+               r_u->ptr_entries = 1;
+
+       r_u->num_entries2 = num_entries;
+       r_u->ctr = ctr;
+
+       r_u->status = status;
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_q_query_aliasinfo(char *desc,  SAMR_Q_QUERY_ALIASINFO *q_e, prs_struct *ps, int depth)
+BOOL samr_io_r_query_dispinfo(char *desc, SAMR_R_QUERY_DISPINFO * r_u,
+                             prs_struct *ps, int depth)
 {
-       if (q_e == NULL)
+       if (r_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_q_query_aliasinfo");
+       prs_debug(ps, depth, desc, "samr_io_r_query_dispinfo");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
+       if(!prs_uint32("total_size  ", ps, depth, &r_u->total_size))
+               return False;
+       if(!prs_uint32("data_size   ", ps, depth, &r_u->data_size))
+               return False;
+       if(!prs_uint16("switch_level", ps, depth, &r_u->switch_level))
                return False;
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level))
+       if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
+               return False;
+       if(!prs_uint32("ptr_entries ", ps, depth, &r_u->ptr_entries))
                return False;
 
-       return True;
-}
-
-/*******************************************************************
- Inits a SAMR_R_QUERY_ALIASINFO structure.
-********************************************************************/
-
-void init_samr_r_query_aliasinfo(SAMR_R_QUERY_ALIASINFO *r_u, uint32 switch_level,
-                                char* alias, char* alias_desc)
-                                
-{
-  int alias_desc_len, alias_len;
-
-  if(r_u == NULL)
-    return;
-
-  alias_len = alias?strlen(alias)+1:0;
-  alias_desc_len = alias_desc?strlen(alias_desc)+1:0;
+       if (r_u->ptr_entries==0) {
+               if(!prs_align(ps))
+                       return False;
+               if(!prs_uint32("status", ps, depth, &r_u->status))
+                       return False;
 
-  DEBUG(5,("init_samr_r_query_aliasinfo\n"));
+               return True;
+       }
 
-  r_u->switch_value = switch_level;
+       if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
+               return False;
 
-  if(r_u->status == 0)
-    {
-      switch(switch_level)
-       {
-       case 1: 
-         {
-           r_u->ptr = 1;
-           init_uni_hdr(&r_u->alias.info1.hdr_alias_name, alias_len);
-           init_unistr2(&r_u->alias.info1.uni_alias_name, alias, alias_len);
-           r_u->alias.info1.switch_value_1 = switch_level;
-           init_uni_hdr(&r_u->alias.info1.hdr_alias_desc, alias_desc_len);
-           init_unistr2(&r_u->alias.info1.uni_alias_desc, alias_desc, alias_desc_len);
-           break;
-         }
-       case 3:
-         {
-           r_u->ptr = 1;
-           init_uni_hdr(&r_u->alias.info3.hdr_acct_desc, alias_desc_len);
-           init_unistr2(&r_u->alias.info3.uni_acct_desc, alias_desc, alias_desc_len);
-           break;
-         }
+       switch (r_u->switch_level) {
+       case 0x1:
+               if(!sam_io_sam_dispinfo_1("users", r_u->ctr->sam.info1,
+                               r_u->num_entries, ps, depth))
+                       return False;
+               break;
+       case 0x2:
+               if(!sam_io_sam_dispinfo_2("servers", r_u->ctr->sam.info2,
+                               r_u->num_entries, ps, depth))
+                       return False;
+               break;
+       case 0x3:
+               if(!sam_io_sam_dispinfo_3("groups", r_u->ctr->sam.info3,
+                                   r_u->num_entries, ps, depth))
+                       return False;
+               break;
+       case 0x4:
+               if(!sam_io_sam_dispinfo_4("user list",
+                                   r_u->ctr->sam.info4,
+                                   r_u->num_entries, ps, depth))
+                       return False;
+               break;
+       case 0x5:
+               if(!sam_io_sam_dispinfo_5("group list",
+                                   r_u->ctr->sam.info5,
+                                   r_u->num_entries, ps, depth))
+                       return False;
+               break;
        default:
-         {
-           r_u->status = 0xC0000000 | NT_STATUS_INVALID_INFO_CLASS;
-         }
+               DEBUG(0,("samr_io_r_query_dispinfo: unknown switch value\n"));
+               break;
        }
-    }
-}
+       
+       if(!prs_align(ps))
+               return False;
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
 
-         
+       return True;
+}
 
 /*******************************************************************
- Reads or writes a structure.
+inits a SAMR_Q_OPEN_GROUP structure.
 ********************************************************************/
 
-BOOL samr_io_r_query_aliasinfo(char *desc,  SAMR_R_QUERY_ALIASINFO *r_u, prs_struct *ps, int depth)
+void init_samr_q_open_group(SAMR_Q_OPEN_GROUP * q_c,
+                           POLICY_HND *hnd,
+                           uint32 access_mask, uint32 rid)
 {
-  if (r_u == NULL)
-    return False;
-
-  prs_debug(ps, depth, desc, "samr_io_r_query_aliasinfo");
-  depth++;
-
-  if(!prs_align(ps))
-    return False;
-
-  if(!prs_uint32("ptr         ", ps, depth, &r_u->ptr))
-    return False;
-       
-  if (r_u->ptr != 0) {
-    if(!prs_uint16("switch_value", ps, depth, &r_u->switch_value))
-      return False;
-    if(!prs_align(ps))
-      return False;
-
-    if (r_u->switch_value != 0) {
-      switch (r_u->switch_value) {
-      case 1:
-       smb_io_unihdr("",&r_u->alias.info1.hdr_alias_name, ps, depth);
-       prs_uint32("switch_value_1", ps, depth, &r_u->alias.info1.switch_value_1);
-       smb_io_unihdr("",&r_u->alias.info1.hdr_alias_desc, ps, depth);
-       
-       smb_io_unistr2("", &r_u->alias.info1.uni_alias_name, 
-                      r_u->alias.info1.hdr_alias_name.buffer, ps, depth);
-       smb_io_unistr2("", &r_u->alias.info1.uni_alias_desc,
-                      r_u->alias.info1.hdr_alias_desc.buffer, ps, depth);
-       break;
-      case 3:
-       if(!smb_io_unihdr ("", &r_u->alias.info3.hdr_acct_desc, ps, depth))
-         return False;
-       if(!smb_io_unistr2("", &r_u->alias.info3.uni_acct_desc, 
-                          r_u->alias.info3.hdr_acct_desc.buffer, ps, depth))
-         return False;
-       break;
-      default:
-       DEBUG(4,("samr_io_r_query_aliasinfo: unsupported switch level\n"));
-       break;
-      }
-    }
-  }
+       DEBUG(5, ("init_samr_q_open_group\n"));
 
-  if(!prs_align(ps))
-    return False;
-
-  if(!prs_uint32("status", ps, depth, &r_u->status))
-    return False;
-
-  return True;
+       q_c->domain_pol = *hnd;
+       q_c->access_mask = access_mask;
+       q_c->rid_group = rid;
 }
 
 /*******************************************************************
- Reads or writes a SAMR_Q_LOOKUP_IDS structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_q_lookup_ids(char *desc,  SAMR_Q_LOOKUP_IDS *q_u, prs_struct *ps, int depth)
+BOOL samr_io_q_open_group(char *desc, SAMR_Q_OPEN_GROUP * q_u,
+                         prs_struct *ps, int depth)
 {
-       fstring tmp;
-       int i;
-
        if (q_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_q_lookup_ids");
+       prs_debug(ps, depth, desc, "samr_io_q_open_group");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_pol_hnd("pol", &(q_u->pol), ps, depth))
-               return False;
-       if(!prs_align(ps))
+       if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
                return False;
 
-       if(!prs_uint32("num_sids1", ps, depth, &q_u->num_sids1))
-               return False;
-       if(!prs_uint32("ptr      ", ps, depth, &q_u->ptr))
+       if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
                return False;
-       if(!prs_uint32("num_sids2", ps, depth, &q_u->num_sids2))
+       if(!prs_uint32("rid_group", ps, depth, &q_u->rid_group))
                return False;
 
-       SMB_ASSERT_ARRAY(q_u->ptr_sid, q_u->num_sids2);
+       return True;
+}
 
-       for (i = 0; i < q_u->num_sids2; i++) {
-               slprintf(tmp, sizeof(tmp) - 1, "ptr[%02d]", i);
-               if(!prs_uint32(tmp, ps, depth, &q_u->ptr_sid[i]))
-                       return False;
-       }
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
 
-       for (i = 0; i < q_u->num_sids2; i++) {
-               if (q_u->ptr_sid[i] != 0) {
-                       slprintf(tmp, sizeof(tmp)-1, "sid[%02d]", i);
-                       if(!smb_io_dom_sid2(tmp, &q_u->sid[i], ps, depth))
-                               return False;
-               }
-       }
+BOOL samr_io_r_open_group(char *desc, SAMR_R_OPEN_GROUP * r_u,
+                         prs_struct *ps, int depth)
+{
+       if (r_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_open_group");
+       depth++;
 
        if(!prs_align(ps))
                return False;
 
+       if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
+               return False;
+
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
        return True;
 }
 
 /*******************************************************************
- Inits a SAMR_R_LOOKUP_IDS structure.
+inits a GROUP_INFO1 structure.
 ********************************************************************/
 
-void init_samr_r_lookup_ids(SAMR_R_LOOKUP_IDS *r_u,
-               uint32 num_rids, uint32 *rid, uint32 status)
+void init_samr_group_info1(GROUP_INFO1 * gr1,
+                          char *acct_name, char *acct_desc,
+                          uint32 num_members)
 {
-       int i;
+       int desc_len = acct_desc != NULL ? strlen(acct_desc) : 0;
+       int acct_len = acct_name != NULL ? strlen(acct_name) : 0;
 
-       DEBUG(5,("init_samr_r_lookup_ids\n"));
+       DEBUG(5, ("init_samr_group_info1\n"));
 
-       if (status == 0x0) {
-               r_u->num_entries  = num_rids;
-               r_u->ptr = 1;
-               r_u->num_entries2 = num_rids;
+       init_uni_hdr(&gr1->hdr_acct_name, acct_len);
 
-               SMB_ASSERT_ARRAY(r_u->rid, num_rids);
+       gr1->unknown_1 = 0x3;
+       gr1->num_members = num_members;
 
-               for (i = 0; i < num_rids; i++) {
-                       r_u->rid[i] = rid[i];
-               }
-       } else {
-               r_u->num_entries  = 0;
-               r_u->ptr = 0;
-               r_u->num_entries2 = 0;
-       }
+       init_uni_hdr(&gr1->hdr_acct_desc, desc_len);
 
-       r_u->status = status;
+       init_unistr2(&gr1->uni_acct_name, acct_name, acct_len);
+       init_unistr2(&gr1->uni_acct_desc, acct_desc, desc_len);
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_r_lookup_ids(char *desc,  SAMR_R_LOOKUP_IDS *r_u, prs_struct *ps, int depth)
+BOOL samr_io_group_info1(char *desc, GROUP_INFO1 * gr1,
+                        prs_struct *ps, int depth)
 {
-       fstring tmp;
-       int i;
-
-       if (r_u == NULL)
+       if (gr1 == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_r_lookup_ids");
+       prs_debug(ps, depth, desc, "samr_io_group_info1");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("num_entries", ps, depth, &r_u->num_entries))
+       if(!smb_io_unihdr("hdr_acct_name", &gr1->hdr_acct_name, ps, depth))
                return False;
-       if(!prs_uint32("ptr        ", ps, depth, &r_u->ptr))
+
+       if(!prs_uint32("unknown_1", ps, depth, &gr1->unknown_1))
                return False;
-       if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
+       if(!prs_uint32("num_members", ps, depth, &gr1->num_members))
                return False;
 
-       if (r_u->num_entries != 0) {
-               SMB_ASSERT_ARRAY(r_u->rid, r_u->num_entries2);
+       if(!smb_io_unihdr("hdr_acct_desc", &gr1->hdr_acct_desc, ps, depth))
+               return False;
 
-               for (i = 0; i < r_u->num_entries2; i++) {
-                       slprintf(tmp, sizeof(tmp)-1, "rid[%02d]", i);
-                       if(!prs_uint32(tmp, ps, depth, &r_u->rid[i]))
-                               return False;
-               }
-       }
+       if(!smb_io_unistr2("uni_acct_name", &gr1->uni_acct_name,
+                          gr1->hdr_acct_name.buffer, ps, depth))
+               return False;
 
-       if(!prs_uint32("status", ps, depth, &r_u->status))
+       if(!smb_io_unistr2("uni_acct_desc", &gr1->uni_acct_desc,
+                          gr1->hdr_acct_desc.buffer, ps, depth))
                return False;
 
        return True;
 }
 
 /*******************************************************************
- Reads or writes a structure.
+inits a GROUP_INFO4 structure.
 ********************************************************************/
 
-BOOL samr_io_q_lookup_names(char *desc,  SAMR_Q_LOOKUP_NAMES *q_u, prs_struct *ps, int depth)
+void init_samr_group_info4(GROUP_INFO4 * gr4, char *acct_desc)
 {
-       int i;
+       int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0;
 
-       if (q_u == NULL)
-               return False;
+       DEBUG(5, ("init_samr_group_info4\n"));
 
-       prs_debug(ps, depth, desc, "samr_io_q_lookup_names");
-       depth++;
+       init_uni_hdr(&gr4->hdr_acct_desc, acct_len);
+       init_unistr2(&gr4->uni_acct_desc, acct_desc, acct_len);
+}
 
-       prs_align(ps);
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
 
-       if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
+BOOL samr_io_group_info4(char *desc, GROUP_INFO4 * gr4,
+                        prs_struct *ps, int depth)
+{
+       if (gr4 == NULL)
                return False;
+
+       prs_debug(ps, depth, desc, "samr_io_group_info4");
+       depth++;
+
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("num_names1", ps, depth, &q_u->num_names1))
-               return False;
-       if(!prs_uint32("flags     ", ps, depth, &q_u->flags))
+       if(!smb_io_unihdr("hdr_acct_desc", &gr4->hdr_acct_desc, ps, depth))
                return False;
-       if(!prs_uint32("ptr      ", ps, depth, &q_u->ptr))
+       if(!smb_io_unistr2("uni_acct_desc", &gr4->uni_acct_desc,
+                          gr4->hdr_acct_desc.buffer, ps, depth))
                return False;
-       if(!prs_uint32("num_names2", ps, depth, &q_u->num_names2))
+
+       return True;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+static BOOL samr_group_info_ctr(char *desc, GROUP_INFO_CTR * ctr,
+                               prs_struct *ps, int depth)
+{
+       if (ctr == NULL)
                return False;
 
-       SMB_ASSERT_ARRAY(q_u->hdr_name, q_u->num_names2);
+       prs_debug(ps, depth, desc, "samr_group_info_ctr");
+       depth++;
 
-       for (i = 0; i < q_u->num_names2; i++) {
-               if(!smb_io_unihdr ("", &q_u->hdr_name[i], ps, depth))
+       if(!prs_uint16("switch_value1", ps, depth, &ctr->switch_value1))
+               return False;
+       if(!prs_uint16("switch_value2", ps, depth, &ctr->switch_value2))
+               return False;
+
+       switch (ctr->switch_value1) {
+       case 1:
+               if(!samr_io_group_info1("group_info1",
+                                 &ctr->group.info1, ps, depth))
                        return False;
-       }
-       for (i = 0; i < q_u->num_names2; i++) {
-               if(!smb_io_unistr2("", &q_u->uni_name[i], q_u->hdr_name[i].buffer, ps, depth))
+               break;
+       case 4:
+               if(!samr_io_group_info4("group_info4",
+                                 &ctr->group.info4, ps, depth))
                        return False;
+               break;
+       default:
+               DEBUG(0,("samr_group_info_ctr: unsupported switch level\n"));
+               break;
        }
 
        return True;
 }
 
-
 /*******************************************************************
- Inits a SAMR_R_LOOKUP_NAMES structure.
+inits a SAMR_Q_CREATE_DOM_GROUP structure.
 ********************************************************************/
-void init_samr_r_lookup_names(SAMR_R_LOOKUP_NAMES *r_u,
-                       uint32 num_rids, uint32 *rid, enum SID_NAME_USE *type, uint32 status)
-{
-       int i;
-
-       DEBUG(5,("init_samr_r_lookup_names\n"));
-
-       if (status == 0x0) {
-               r_u->num_types1 = num_rids;
-               r_u->ptr_types  = 1;
-               r_u->num_types2 = num_rids;
 
-               r_u->num_rids1 = num_rids;
-               r_u->ptr_rids  = 1;
-               r_u->num_rids2 = num_rids;
+void init_samr_q_create_dom_group(SAMR_Q_CREATE_DOM_GROUP * q_e,
+                                 POLICY_HND *pol, char *acct_desc,
+                                 uint32 access_mask)
+{
+       int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0;
 
-               SMB_ASSERT_ARRAY(r_u->rid, num_rids);
+       DEBUG(5, ("init_samr_q_create_dom_group\n"));
 
-               for (i = 0; i < num_rids; i++) {
-                       r_u->rid [i] = rid [i];
-                       r_u->type[i] = type[i];
-               }
-       } else {
-               r_u->num_types1 = 0;
-               r_u->ptr_types  = 0;
-               r_u->num_types2 = 0;
+       q_e->pol = *pol;
 
-               r_u->num_rids1 = 0;
-               r_u->ptr_rids  = 0;
-               r_u->num_rids2 = 0;
-       }
+       init_uni_hdr(&q_e->hdr_acct_desc, acct_len);
+       init_unistr2(&q_e->uni_acct_desc, acct_desc, acct_len);
 
-       r_u->status = status;
+       q_e->access_mask = access_mask;
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_r_lookup_names(char *desc,  SAMR_R_LOOKUP_NAMES *r_u, prs_struct *ps, int depth)
+BOOL samr_io_q_create_dom_group(char *desc, SAMR_Q_CREATE_DOM_GROUP * q_e,
+                               prs_struct *ps, int depth)
 {
-       int i;
-       fstring tmp;
-
-       if (r_u == NULL)
+       if (q_e == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_r_lookup_names");
+       prs_debug(ps, depth, desc, "samr_io_q_create_dom_group");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("num_rids1", ps, depth, &r_u->num_rids1))
-               return False;
-       if(!prs_uint32("ptr_rids ", ps, depth, &r_u->ptr_rids ))
+       if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
                return False;
 
-       if (r_u->ptr_rids != 0) {
-               if(!prs_uint32("num_rids2", ps, depth, &r_u->num_rids2))
-                       return False;
-
-               if (r_u->num_rids2 != r_u->num_rids1) {
-                       /* RPC fault */
-                       return False;
-               }
-
-               for (i = 0; i < r_u->num_rids2; i++) {
-                       slprintf(tmp, sizeof(tmp) - 1, "rid[%02d]  ", i);
-                       if(!prs_uint32(tmp, ps, depth, &r_u->rid[i]))
-                               return False;
-               }
-       }
-
-       if(!prs_uint32("num_types1", ps, depth, &r_u->num_types1))
+       if(!smb_io_unihdr("hdr_acct_desc", &q_e->hdr_acct_desc, ps, depth))
                return False;
-       if(!prs_uint32("ptr_types ", ps, depth, &r_u->ptr_types))
+       if(!smb_io_unistr2("uni_acct_desc", &q_e->uni_acct_desc,
+                      q_e->hdr_acct_desc.buffer, ps, depth))
                return False;
 
-       if (r_u->ptr_types != 0) {
-               if(!prs_uint32("num_types2", ps, depth, &r_u->num_types2))
-                       return False;
-
-               if (r_u->num_types2 != r_u->num_types1) {
-                       /* RPC fault */
-                       return False;
-               }
-
-               for (i = 0; i < r_u->num_types2; i++) {
-                       slprintf(tmp, sizeof(tmp) - 1, "type[%02d]  ", i);
-                       if(!prs_uint32(tmp, ps, depth, &r_u->type[i]))
-                               return False;
-               }
-       }
-
-       if(!prs_uint32("status", ps, depth, &r_u->status))
+       if(!prs_align(ps))
+               return False;
+       if(!prs_uint32("access", ps, depth, &q_e->access_mask))
                return False;
 
        return True;
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_q_lookup_rids(char *desc, SAMR_Q_LOOKUP_RIDS *q_u, prs_struct *ps, int depth)
+BOOL samr_io_r_create_dom_group(char *desc, SAMR_R_CREATE_DOM_GROUP * r_u,
+                               prs_struct *ps, int depth)
 {
-       int i;
-       fstring tmp;
-
-       if (q_u == NULL)
+       if (r_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_q_lookup_rids");
+       prs_debug(ps, depth, desc, "samr_io_r_create_dom_group");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
-               return False;
-       if(!prs_align(ps))
+       if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
                return False;
 
-       if(!prs_uint32("num_gids1", ps, depth, &q_u->num_gids1))
-               return False;
-       if(!prs_uint32("rid      ", ps, depth, &q_u->rid))
-               return False;
-       if(!prs_uint32("ptr      ", ps, depth, &q_u->ptr))
+       if(!prs_uint32("rid   ", ps, depth, &r_u->rid))
                return False;
-       if(!prs_uint32("num_gids2", ps, depth, &q_u->num_gids2))
+       if(!prs_uint32("status", ps, depth, &r_u->status))
                return False;
 
-       SMB_ASSERT_ARRAY(q_u->gid, q_u->num_gids2);
-
-       for (i = 0; i < q_u->num_gids2; i++) {
-               slprintf(tmp, sizeof(tmp) - 1, "gid[%02d]  ", i);
-               if(!prs_uint32(tmp, ps, depth, &q_u->gid[i]))
-                       return False;
-       }
-
        return True;
 }
 
 /*******************************************************************
- Inits a SAMR_R_UNKNOWN_12 structure.
+inits a SAMR_Q_DELETE_DOM_GROUP structure.
 ********************************************************************/
 
-void init_samr_r_lookup_rids(SAMR_R_LOOKUP_RIDS *r_u,
-               uint32 num_aliases, fstring *als_name, uint32 *num_als_usrs,
-               uint32 status)
+void init_samr_q_delete_dom_group(SAMR_Q_DELETE_DOM_GROUP * q_c,
+                                 POLICY_HND *hnd)
 {
-       int i;
+       DEBUG(5, ("init_samr_q_delete_dom_group\n"));
 
-       DEBUG(5,("init_samr_r_lookup_rids\n"));
+       q_c->group_pol = *hnd;
+}
 
-       if (status == 0x0) {
-               r_u->num_aliases1 = num_aliases;
-               r_u->ptr_aliases  = 1;
-               r_u->num_aliases2 = num_aliases;
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
 
-               r_u->num_als_usrs1 = num_aliases;
-               r_u->ptr_als_usrs  = 1;
-               r_u->num_als_usrs2 = num_aliases;
+BOOL samr_io_q_delete_dom_group(char *desc, SAMR_Q_DELETE_DOM_GROUP * q_u,
+                               prs_struct *ps, int depth)
+{
+       if (q_u == NULL)
+               return False;
 
-               SMB_ASSERT_ARRAY(r_u->hdr_als_name, num_aliases);
+       prs_debug(ps, depth, desc, "samr_io_q_delete_dom_group");
+       depth++;
 
-               for (i = 0; i < num_aliases; i++) {
-                       int als_len = als_name[i] != NULL ? strlen(als_name[i])+1 : 0;
-                       init_uni_hdr(&r_u->hdr_als_name[i], als_len);
-                       init_unistr2(&r_u->uni_als_name[i], als_name[i], als_len);
-                       r_u->num_als_usrs[i] = num_als_usrs[i];
-               }
-       } else {
-               r_u->num_aliases1 = num_aliases;
-               r_u->ptr_aliases  = 0;
-               r_u->num_aliases2 = num_aliases;
+       if(!prs_align(ps))
+               return False;
 
-               r_u->num_als_usrs1 = num_aliases;
-               r_u->ptr_als_usrs  = 0;
-               r_u->num_als_usrs2 = num_aliases;
-       }
+       if(!smb_io_pol_hnd("group_pol", &q_u->group_pol, ps, depth))
+               return False;
 
-       r_u->status = status;
+       return True;
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_r_lookup_rids(char *desc, SAMR_R_LOOKUP_RIDS *r_u, prs_struct *ps, int depth)
+BOOL samr_io_r_delete_dom_group(char *desc, SAMR_R_DELETE_DOM_GROUP * r_u,
+                               prs_struct *ps, int depth)
 {
-       int i;
-       fstring tmp;
-
        if (r_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_r_lookup_rids");
+       prs_debug(ps, depth, desc, "samr_io_r_delete_dom_group");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("num_aliases1", ps, depth, &r_u->num_aliases1))
-               return False;
-       if(!prs_uint32("ptr_aliases ", ps, depth, &r_u->ptr_aliases ))
-               return False;
-       if(!prs_uint32("num_aliases2", ps, depth, &r_u->num_aliases2))
+       if(!prs_uint32("status", ps, depth, &r_u->status))
                return False;
 
-       if (r_u->ptr_aliases != 0 && r_u->num_aliases1 != 0) {
-               SMB_ASSERT_ARRAY(r_u->hdr_als_name, r_u->num_aliases2);
+       return True;
+}
 
-               for (i = 0; i < r_u->num_aliases2; i++) {
-                       slprintf(tmp, sizeof(tmp) - 1, "als_hdr[%02d]  ", i);
-                       if(!smb_io_unihdr ("", &r_u->hdr_als_name[i], ps, depth))
-                               return False;
-               }
-               for (i = 0; i < r_u->num_aliases2; i++) {
-                       slprintf(tmp, sizeof(tmp) - 1, "als_str[%02d]  ", i);
-                       if(!smb_io_unistr2("", &r_u->uni_als_name[i], r_u->hdr_als_name[i].buffer, ps, depth))
-                               return False;
-                       if(!prs_align(ps))
-                               return False;
-               }
-       }
+/*******************************************************************
+inits a SAMR_Q_DEL_GROUPMEM structure.
+********************************************************************/
+
+void init_samr_q_del_groupmem(SAMR_Q_DEL_GROUPMEM * q_e,
+                             POLICY_HND *pol, uint32 rid)
+{
+       DEBUG(5, ("init_samr_q_del_groupmem\n"));
+
+       q_e->pol = *pol;
+       q_e->rid = rid;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_q_del_groupmem(char *desc, SAMR_Q_DEL_GROUPMEM * q_e,
+                           prs_struct *ps, int depth)
+{
+       if (q_e == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_q_del_groupmem");
+       depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("num_als_usrs1", ps, depth, &r_u->num_als_usrs1))
+       if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
                return False;
-       if(!prs_uint32("ptr_als_usrs ", ps, depth, &r_u->ptr_als_usrs))
+
+       if(!prs_uint32("rid", ps, depth, &q_e->rid))
                return False;
-       if(!prs_uint32("num_als_usrs2", ps, depth, &r_u->num_als_usrs2))
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_R_DEL_GROUPMEM structure.
+********************************************************************/
+
+void init_samr_r_del_groupmem(SAMR_R_DEL_GROUPMEM * r_u, POLICY_HND *pol,
+                             uint32 status)
+{
+       DEBUG(5, ("init_samr_r_del_groupmem\n"));
+
+       r_u->status = status;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_r_del_groupmem(char *desc, SAMR_R_DEL_GROUPMEM * r_u,
+                           prs_struct *ps, int depth)
+{
+       if (r_u == NULL)
                return False;
 
-       if (r_u->ptr_als_usrs != 0 && r_u->num_als_usrs1 != 0) {
-               SMB_ASSERT_ARRAY(r_u->num_als_usrs, r_u->num_als_usrs2);
+       prs_debug(ps, depth, desc, "samr_io_r_del_groupmem");
+       depth++;
 
-               for (i = 0; i < r_u->num_als_usrs2; i++) {
-                       slprintf(tmp, sizeof(tmp) - 1, "als_usrs[%02d]  ", i);
-                       if(!prs_uint32(tmp, ps, depth, &r_u->num_als_usrs[i]))
-                               return False;
-               }
-       }
+       if(!prs_align(ps))
+               return False;
 
        if(!prs_uint32("status", ps, depth, &r_u->status))
                return False;
@@ -2545,73 +2289,75 @@ BOOL samr_io_r_lookup_rids(char *desc, SAMR_R_LOOKUP_RIDS *r_u, prs_struct *ps,
        return True;
 }
 
-
 /*******************************************************************
- Inits a SAMR_Q_OPEN_USER struct.
+inits a SAMR_Q_ADD_GROUPMEM structure.
 ********************************************************************/
 
-void init_samr_q_open_user(SAMR_Q_OPEN_USER *q_u, POLICY_HND *pol,
-                          uint32 access_mask, uint32 rid)
+void init_samr_q_add_groupmem(SAMR_Q_ADD_GROUPMEM * q_e,
+                             POLICY_HND *pol, uint32 rid)
 {
-       DEBUG(5,("init_samr_q_open_user\n"));
+       DEBUG(5, ("init_samr_q_add_groupmem\n"));
 
-       q_u->domain_pol = *pol;
-       q_u->access_mask = access_mask;
-       q_u->user_rid = rid;
+       q_e->pol = *pol;
+       q_e->rid = rid;
+       q_e->unknown = 0x0005;
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_q_open_user(char *desc, SAMR_Q_OPEN_USER *q_u, 
-                        prs_struct *ps, int depth)
+BOOL samr_io_q_add_groupmem(char *desc, SAMR_Q_ADD_GROUPMEM * q_e,
+                           prs_struct *ps, int depth)
 {
-       if (q_u == NULL)
+       if (q_e == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_q_open_user");
+       prs_debug(ps, depth, desc, "samr_io_q_add_groupmem");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
-               return False;
-       if(!prs_align(ps))
+       if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
                return False;
 
-       if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
-               return False;
-       if(!prs_uint32("user_rid ", ps, depth, &q_u->user_rid))
+       if(!prs_uint32("rid    ", ps, depth, &q_e->rid))
                return False;
-
-       if(!prs_align(ps))
+       if(!prs_uint32("unknown", ps, depth, &q_e->unknown))
                return False;
 
        return True;
 }
 
 /*******************************************************************
- Reads or writes a structure.
+inits a SAMR_R_ADD_GROUPMEM structure.
+********************************************************************/
+
+void init_samr_r_add_groupmem(SAMR_R_ADD_GROUPMEM * r_u, POLICY_HND *pol,
+                             uint32 status)
+{
+       DEBUG(5, ("init_samr_r_add_groupmem\n"));
+
+       r_u->status = status;
+}
+
+/*******************************************************************
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_r_open_user(char *desc,  SAMR_R_OPEN_USER *r_u, prs_struct *ps, int depth)
+BOOL samr_io_r_add_groupmem(char *desc, SAMR_R_ADD_GROUPMEM * r_u,
+                           prs_struct *ps, int depth)
 {
        if (r_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_r_open_user");
+       prs_debug(ps, depth, desc, "samr_io_r_add_groupmem");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_pol_hnd("user_pol", &r_u->user_pol, ps, depth))
-               return False;
-       if(!prs_align(ps))
-               return False;
-
        if(!prs_uint32("status", ps, depth, &r_u->status))
                return False;
 
@@ -2619,102 +2365,70 @@ BOOL samr_io_r_open_user(char *desc,  SAMR_R_OPEN_USER *r_u, prs_struct *ps, int
 }
 
 /*******************************************************************
- Inits a SAMR_Q_QUERY_USERGROUPS structure.
+inits a SAMR_Q_SET_GROUPINFO structure.
 ********************************************************************/
 
-void init_samr_q_query_usergroups(SAMR_Q_QUERY_USERGROUPS *q_u,
-                               POLICY_HND *hnd)
+void init_samr_q_set_groupinfo(SAMR_Q_SET_GROUPINFO * q_e,
+                              POLICY_HND *pol, GROUP_INFO_CTR * ctr)
 {
-       DEBUG(5,("init_samr_q_query_usergroups\n"));
+       DEBUG(5, ("init_samr_q_set_groupinfo\n"));
 
-       memcpy(&q_u->pol, hnd, sizeof(q_u->pol));
+       q_e->pol = *pol;
+       q_e->ctr = ctr;
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_q_query_usergroups(char *desc,  SAMR_Q_QUERY_USERGROUPS *q_u, prs_struct *ps, int depth)
+BOOL samr_io_q_set_groupinfo(char *desc, SAMR_Q_SET_GROUPINFO * q_e,
+                            prs_struct *ps, int depth)
 {
-       if (q_u == NULL)
+       if (q_e == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_q_query_usergroups");
+       prs_debug(ps, depth, desc, "samr_io_q_set_groupinfo");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
+       if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
                return False;
-       if(!prs_align(ps))
+       
+       if(!samr_group_info_ctr("ctr", q_e->ctr, ps, depth))
                return False;
 
        return True;
 }
 
 /*******************************************************************
- Inits a SAMR_R_QUERY_USERGROUPS structure.
+inits a SAMR_R_SET_GROUPINFO structure.
 ********************************************************************/
 
-void init_samr_r_query_usergroups(SAMR_R_QUERY_USERGROUPS *r_u,
-               uint32 num_gids, DOM_GID *gid, uint32 status)
+void init_samr_r_set_groupinfo(SAMR_R_SET_GROUPINFO * r_u, uint32 status)
 {
-       DEBUG(5,("init_samr_r_query_usergroups\n"));
-
-       if (status == 0x0) {
-               r_u->ptr_0        = 1;
-               r_u->num_entries  = num_gids;
-               r_u->ptr_1        = 1;
-               r_u->num_entries2 = num_gids;
-
-               r_u->gid = gid;
-       } else {
-               r_u->ptr_0       = 0;
-               r_u->num_entries = 0;
-               r_u->ptr_1       = 0;
-       }
+       DEBUG(5, ("init_samr_r_set_groupinfo\n"));
 
        r_u->status = status;
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_r_query_usergroups(char *desc,  SAMR_R_QUERY_USERGROUPS *r_u, prs_struct *ps, int depth)
+BOOL samr_io_r_set_groupinfo(char *desc, SAMR_R_SET_GROUPINFO * r_u,
+                            prs_struct *ps, int depth)
 {
-       int i;
-
        if (r_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_r_query_usergroups");
+       prs_debug(ps, depth, desc, "samr_io_r_set_groupinfo");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("ptr_0       ", ps, depth, &r_u->ptr_0))
-               return False;
-
-       if (r_u->ptr_0 != 0) {
-               if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
-                       return False;
-               if(!prs_uint32("ptr_1       ", ps, depth, &r_u->ptr_1))
-                       return False;
-
-               if (r_u->num_entries != 0) {
-                       if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
-                               return False;
-
-                       for (i = 0; i < r_u->num_entries2; i++) {
-                               if(!smb_io_gid("", &r_u->gid[i], ps, depth))
-                                       return False;
-                       }
-               }
-       }
-
        if(!prs_uint32("status", ps, depth, &r_u->status))
                return False;
 
@@ -2722,223 +2436,2540 @@ BOOL samr_io_r_query_usergroups(char *desc,  SAMR_R_QUERY_USERGROUPS *r_u, prs_s
 }
 
 /*******************************************************************
- Inits a SAMR_Q_QUERY_USERINFO structure.
+inits a SAMR_Q_QUERY_GROUPINFO structure.
 ********************************************************************/
 
-void init_samr_q_query_userinfo(SAMR_Q_QUERY_USERINFO *q_u,
-                               POLICY_HND *hnd, uint16 switch_value)
+void init_samr_q_query_groupinfo(SAMR_Q_QUERY_GROUPINFO * q_e,
+                                POLICY_HND *pol, uint16 switch_level)
 {
-       DEBUG(5,("init_samr_q_query_userinfo\n"));
+       DEBUG(5, ("init_samr_q_query_groupinfo\n"));
 
-       memcpy(&q_u->pol, hnd, sizeof(q_u->pol));
-       q_u->switch_value = switch_value;
+       q_e->pol = *pol;
+
+       q_e->switch_level = switch_level;
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_q_query_userinfo(char *desc,  SAMR_Q_QUERY_USERINFO *q_u, prs_struct *ps, int depth)
+BOOL samr_io_q_query_groupinfo(char *desc, SAMR_Q_QUERY_GROUPINFO * q_e,
+                              prs_struct *ps, int depth)
 {
-       if (q_u == NULL)
+       if (q_e == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_q_query_userinfo");
+       prs_debug(ps, depth, desc, "samr_io_q_query_groupinfo");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
-               return False;
-       if(!prs_align(ps))
+       if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
                return False;
 
-       if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value)) /* 0x0015 or 0x0011 */
+       if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level))
                return False;
 
        return True;
 }
 
 /*******************************************************************
- Reads or writes a LOGON_HRS structure.
+inits a SAMR_R_QUERY_GROUPINFO structure.
 ********************************************************************/
 
-static BOOL sam_io_logon_hrs(char *desc,  LOGON_HRS *hrs, prs_struct *ps, int depth)
+void init_samr_r_query_groupinfo(SAMR_R_QUERY_GROUPINFO * r_u,
+                                GROUP_INFO_CTR * ctr, uint32 status)
 {
-       if (hrs == NULL)
+       DEBUG(5, ("init_samr_r_query_groupinfo\n"));
+
+       r_u->ptr = (status == 0x0 && ctr != NULL) ? 1 : 0;
+       r_u->ctr = ctr;
+       r_u->status = status;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_r_query_groupinfo(char *desc, SAMR_R_QUERY_GROUPINFO * r_u,
+                              prs_struct *ps, int depth)
+{
+       if (r_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "sam_io_logon_hrs");
+       prs_debug(ps, depth, desc, "samr_io_r_query_groupinfo");
        depth++;
 
        if(!prs_align(ps))
                return False;
-       
-       if(!prs_uint32 ("len  ", ps, depth, &hrs->len))
+
+       if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
                return False;
 
-       if (hrs->len > 64) {
-               DEBUG(5,("sam_io_logon_hrs: truncating length\n"));
-               hrs->len = 64;
+       if (r_u->ptr != 0) {
+               if(!samr_group_info_ctr("ctr", r_u->ctr, ps, depth))
+                       return False;
        }
 
-       if(!prs_uint8s (False, "hours", ps, depth, hrs->hours, hrs->len))
+       if(!prs_align(ps))
+               return False;
+       if(!prs_uint32("status", ps, depth, &r_u->status))
                return False;
 
        return True;
 }
 
 /*******************************************************************
- Inits a SAM_USER_INFO_10 structure.
+inits a SAMR_Q_QUERY_GROUPMEM structure.
 ********************************************************************/
 
-void init_sam_user_info10(SAM_USER_INFO_10 *usr,
-                               uint32 acb_info)
+void init_samr_q_query_groupmem(SAMR_Q_QUERY_GROUPMEM * q_c, POLICY_HND *hnd)
 {
-       DEBUG(5,("init_sam_user_info10\n"));
+       DEBUG(5, ("init_samr_q_query_groupmem\n"));
 
-       usr->acb_info = acb_info;
+       q_c->group_pol = *hnd;
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL sam_io_user_info10(char *desc,  SAM_USER_INFO_10 *usr, prs_struct *ps, int depth)
+BOOL samr_io_q_query_groupmem(char *desc, SAMR_Q_QUERY_GROUPMEM * q_u,
+                             prs_struct *ps, int depth)
 {
-       if (usr == NULL)
+       if (q_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_r_user_info10");
+       prs_debug(ps, depth, desc, "samr_io_q_query_groupmem");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("acb_info", ps, depth, &usr->acb_info))
+       if(!smb_io_pol_hnd("group_pol", &q_u->group_pol, ps, depth))
                return False;
 
        return True;
 }
 
 /*******************************************************************
- Inits a SAM_USER_INFO_11 structure.
+inits a SAMR_R_QUERY_GROUPMEM structure.
 ********************************************************************/
 
-void init_sam_user_info11(SAM_USER_INFO_11 *usr,
-                               NTTIME *expiry,
-                               char *mach_acct,
-                               uint32 rid_user,
-                               uint32 rid_group,
-                               uint16 acct_ctrl)
-                               
+void init_samr_r_query_groupmem(SAMR_R_QUERY_GROUPMEM * r_u,
+                               uint32 num_entries, uint32 *rid,
+                               uint32 *attr, uint32 status)
 {
-       int len_mach_acct;
+       DEBUG(5, ("init_samr_r_query_groupmem\n"));
 
-       DEBUG(5,("init_sam_user_info11\n"));
-
-       len_mach_acct = strlen(mach_acct)+1;
-
-       memcpy(&usr->expiry,expiry, sizeof(usr->expiry)); /* expiry time or something? */
-       memset((char *)usr->padding_1, '\0', sizeof(usr->padding_1)); /* 0 - padding 24 bytes */
-
-       init_uni_hdr(&usr->hdr_mach_acct, len_mach_acct);  /* unicode header for machine account */
-       usr->padding_2 = 0;               /* 0 - padding 4 bytes */
-
-       usr->ptr_1        = 1;            /* pointer */
-       memset((char *)usr->padding_3, '\0', sizeof(usr->padding_3)); /* 0 - padding 32 bytes */
-       usr->padding_4    = 0;            /* 0 - padding 4 bytes */
-
-       usr->ptr_2        = 1;            /* pointer */
-       usr->padding_5    = 0;            /* 0 - padding 4 bytes */
-
-       usr->ptr_3        = 1;          /* pointer */
-       memset((char *)usr->padding_6, '\0', sizeof(usr->padding_6)); /* 0 - padding 32 bytes */
-
-       usr->rid_user     = rid_user; 
-       usr->rid_group    = rid_group;
+       if (status == 0x0) {
+               r_u->ptr = 1;
+               r_u->num_entries = num_entries;
 
-       usr->acct_ctrl    = acct_ctrl;
-       usr->unknown_3    = 0x0000;
+               r_u->ptr_attrs = attr != NULL ? 1 : 0;
+               r_u->ptr_rids = rid != NULL ? 1 : 0;
 
-       usr->unknown_4    = 0x003f;       /* 0x003f      - 16 bit unknown */
-       usr->unknown_5    = 0x003c;       /* 0x003c      - 16 bit unknown */
+               r_u->num_rids = num_entries;
+               r_u->rid = rid;
 
-       memset((char *)usr->padding_7, '\0', sizeof(usr->padding_7)); /* 0 - padding 16 bytes */
-       usr->padding_8    = 0;            /* 0 - padding 4 bytes */
-       
-       init_unistr2(&usr->uni_mach_acct, mach_acct, len_mach_acct);  /* unicode string for machine account */
+               r_u->num_attrs = num_entries;
+               r_u->attr = attr;
+       } else {
+               r_u->ptr = 0;
+               r_u->num_entries = 0;
+       }
 
-       memset((char *)usr->padding_9, '\0', sizeof(usr->padding_9)); /* 0 - padding 48 bytes */
+       r_u->status = status;
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL sam_io_user_info11(char *desc,  SAM_USER_INFO_11 *usr, prs_struct *ps, int depth)
+BOOL samr_io_r_query_groupmem(char *desc, SAMR_R_QUERY_GROUPMEM * r_u,
+                             prs_struct *ps, int depth)
 {
-       if (usr == NULL)
+       uint32 i;
+
+       if (r_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_r_unknown_24");
+       if (UNMARSHALLING(ps))
+               ZERO_STRUCTP(r_u);
+
+       prs_debug(ps, depth, desc, "samr_io_r_query_groupmem");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint8s (False, "padding_0", ps, depth, usr->padding_0, sizeof(usr->padding_0))) 
+       if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
                return False;
-
-       if(!smb_io_time("time", &(usr->expiry), ps, depth))
+       if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
                return False;
 
-       if(!prs_uint8s (False, "padding_1", ps, depth, usr->padding_1, sizeof(usr->padding_1)))
-               return False;
+       if (r_u->ptr != 0) {
+               if(!prs_uint32("ptr_rids ", ps, depth, &r_u->ptr_rids))
+                       return False;
+               if(!prs_uint32("ptr_attrs", ps, depth, &r_u->ptr_attrs))
+                       return False;
 
-       if(!smb_io_unihdr ("unihdr", &usr->hdr_mach_acct, ps, depth))
-               return False;
-       if(!prs_uint32(        "padding_2", ps, depth, &usr->padding_2))
-               return False;
+               if (r_u->ptr_rids != 0) {
+                       if(!prs_uint32("num_rids", ps, depth, &r_u->num_rids))
+                               return False;
+                       if (UNMARSHALLING(ps) && r_u->num_rids != 0) {
+                               r_u->rid = (uint32 *)prs_alloc_mem(ps,sizeof(r_u->rid[0])*r_u->num_rids);
+                               if (r_u->rid == NULL)
+                                       return False;
+                       }
 
-       if(!prs_uint32(        "ptr_1    ", ps, depth, &usr->ptr_1))
-               return False;
-       if(!prs_uint8s (False, "padding_3", ps, depth, usr->padding_3, sizeof(usr->padding_3)))
-               return False;
-       if(!prs_uint32(        "padding_4", ps, depth, &usr->padding_4))
-               return False;
+                       for (i = 0; i < r_u->num_rids; i++) {
+                               if(!prs_uint32("", ps, depth, &r_u->rid[i]))
+                                       return False;
+                       }
+               }
 
-       if(!prs_uint32(        "ptr_2    ", ps, depth, &usr->ptr_2))
-               return False;
-       if(!prs_uint32(        "padding_5", ps, depth, &usr->padding_5))
-               return False;
+               if (r_u->ptr_attrs != 0) {
+                       if(!prs_uint32("num_attrs", ps, depth, &r_u->num_attrs))
+                               return False;
 
-       if(!prs_uint32(        "ptr_3    ", ps, depth, &usr->ptr_3))
-               return False;
-       if(!prs_uint8s(False, "padding_6", ps, depth, usr->padding_6, sizeof(usr->padding_6)))
-               return False;
+                       if (UNMARSHALLING(ps) && r_u->num_attrs != 0) {
+                               r_u->attr = (uint32 *)prs_alloc_mem(ps,sizeof(r_u->attr[0])*r_u->num_attrs);
+                               if (r_u->attr == NULL)
+                                       return False;
+                       }
 
-       if(!prs_uint32(        "rid_user ", ps, depth, &usr->rid_user))
-               return False;
-       if(!prs_uint32(        "rid_group", ps, depth, &usr->rid_group))
-               return False;
-       if(!prs_uint16(        "acct_ctrl", ps, depth, &usr->acct_ctrl))
-               return False;
-       if(!prs_uint16(        "unknown_3", ps, depth, &usr->unknown_3))
-               return False;
-       if(!prs_uint16(        "unknown_4", ps, depth, &usr->unknown_4))
-               return False;
-       if(!prs_uint16(        "unknown_5", ps, depth, &usr->unknown_5))
-               return False;
+                       for (i = 0; i < r_u->num_attrs; i++) {
+                               if(!prs_uint32("", ps, depth, &r_u->attr[i]))
+                                       return False;
+                       }
+               }
+       }
 
-       if(!prs_uint8s (False, "padding_7", ps, depth, usr->padding_7, sizeof(usr->padding_7)))
-               return False;
-       if(!prs_uint32(        "padding_8", ps, depth, &usr->padding_8))
+       if(!prs_uint32("status", ps, depth, &r_u->status))
                return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_Q_QUERY_USERGROUPS structure.
+********************************************************************/
+
+void init_samr_q_query_usergroups(SAMR_Q_QUERY_USERGROUPS * q_u,
+                                 POLICY_HND *hnd)
+{
+       DEBUG(5, ("init_samr_q_query_usergroups\n"));
+
+       q_u->pol = *hnd;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_q_query_usergroups(char *desc, SAMR_Q_QUERY_USERGROUPS * q_u,
+                               prs_struct *ps, int depth)
+{
+       if (q_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_q_query_usergroups");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_R_QUERY_USERGROUPS structure.
+********************************************************************/
+
+void init_samr_r_query_usergroups(SAMR_R_QUERY_USERGROUPS * r_u,
+                                 uint32 num_gids, DOM_GID * gid,
+                                 uint32 status)
+{
+       DEBUG(5, ("init_samr_r_query_usergroups\n"));
+
+       if (status == 0) {
+               r_u->ptr_0 = 1;
+               r_u->num_entries = num_gids;
+               r_u->ptr_1 = (num_gids != 0) ? 1 : 0;
+               r_u->num_entries2 = num_gids;
+
+               r_u->gid = gid;
+       } else {
+               r_u->ptr_0 = 0;
+               r_u->num_entries = 0;
+               r_u->ptr_1 = 0;
+               r_u->gid = NULL;
+       }
+
+       r_u->status = status;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_gids(char *desc, uint32 *num_gids, DOM_GID ** gid,
+                 prs_struct *ps, int depth)
+{
+       uint32 i;
+       if (gid == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_gids");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!prs_uint32("num_gids", ps, depth, num_gids))
+               return False;
+
+       if ((*num_gids) != 0) {
+               if (UNMARSHALLING(ps)) {
+                       (*gid) = (DOM_GID *)prs_alloc_mem(ps,sizeof(DOM_GID)*(*num_gids));
+               }
+
+               if ((*gid) == NULL) {
+                       return False;
+               }
+
+               for (i = 0; i < (*num_gids); i++) {
+                       if(!smb_io_gid("gids", &(*gid)[i], ps, depth))
+                               return False;
+               }
+       }
+
+       return True;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_r_query_usergroups(char *desc, SAMR_R_QUERY_USERGROUPS * r_u,
+                               prs_struct *ps, int depth)
+{
+       if (r_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_query_usergroups");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!prs_uint32("ptr_0       ", ps, depth, &r_u->ptr_0))
+               return False;
+
+       if (r_u->ptr_0 != 0) {
+               if(!prs_uint32("num_entries ", ps, depth, &r_u->num_entries))
+                       return False;
+               if(!prs_uint32("ptr_1       ", ps, depth, &r_u->ptr_1))
+                       return False;
+
+               if (r_u->num_entries != 0 && r_u->ptr_1 != 0) {
+                       if(!samr_io_gids("gids", &r_u->num_entries2, &r_u->gid, ps, depth))
+                               return False;
+               }
+       }
+
+       if(!prs_align(ps))
+               return False;
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+         return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_Q_ENUM_DOMAINS structure.
+********************************************************************/
+
+void init_samr_q_enum_domains(SAMR_Q_ENUM_DOMAINS * q_e,
+                             POLICY_HND *pol,
+                             uint32 start_idx, uint32 size)
+{
+       DEBUG(5, ("init_samr_q_enum_domains\n"));
+
+       q_e->pol = *pol;
+
+       q_e->start_idx = start_idx;
+       q_e->max_size = size;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_q_enum_domains(char *desc, SAMR_Q_ENUM_DOMAINS * q_e,
+                           prs_struct *ps, int depth)
+{
+       if (q_e == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_q_enum_domains");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
+               return False;
+
+       if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
+               return False;
+       if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_R_ENUM_DOMAINS structure.
+********************************************************************/
+
+void init_samr_r_enum_domains(SAMR_R_ENUM_DOMAINS * r_u,
+                             uint32 next_idx, uint32 num_sam_entries)
+{
+       DEBUG(5, ("init_samr_r_enum_domains\n"));
+
+       r_u->next_idx = next_idx;
+
+       if (num_sam_entries != 0) {
+               r_u->ptr_entries1 = 1;
+               r_u->ptr_entries2 = 1;
+               r_u->num_entries2 = num_sam_entries;
+               r_u->num_entries3 = num_sam_entries;
+
+               r_u->num_entries4 = num_sam_entries;
+       } else {
+               r_u->ptr_entries1 = 0;
+               r_u->num_entries2 = num_sam_entries;
+               r_u->ptr_entries2 = 1;
+       }
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_r_enum_domains(char *desc, SAMR_R_ENUM_DOMAINS * r_u,
+                           prs_struct *ps, int depth)
+{
+       uint32 i;
+
+       if (r_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_enum_domains");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!prs_uint32("next_idx    ", ps, depth, &r_u->next_idx))
+               return False;
+       if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
+               return False;
+
+       if (r_u->ptr_entries1 != 0) {
+               if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
+                       return False;
+               if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
+                       return False;
+               if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
+                       return False;
+
+               if (UNMARSHALLING(ps)) {
+                       r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
+                       r_u->uni_dom_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
+               }
+
+               if ((r_u->sam == NULL || r_u->uni_dom_name == NULL) && r_u->num_entries2 != 0) {
+                       DEBUG(0, ("NULL pointers in SAMR_R_ENUM_DOMAINS\n"));
+                       r_u->num_entries4 = 0;
+                       r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
+                       return False;
+               }
+
+               for (i = 0; i < r_u->num_entries2; i++) {
+                       fstring tmp;
+                       slprintf(tmp, sizeof(tmp) - 1, "dom[%d]", i);
+                       if(!sam_io_sam_entry(tmp, &r_u->sam[i], ps, depth))
+                               return False;
+               }
+
+               for (i = 0; i < r_u->num_entries2; i++) {
+                       fstring tmp;
+                       slprintf(tmp, sizeof(tmp) - 1, "dom[%d]", i);
+                       if(!smb_io_unistr2(tmp, &r_u->uni_dom_name[i],
+                                      r_u->sam[i].hdr_name.buffer, ps,
+                                      depth))
+                               return False;
+               }
+
+       }
+
+       if(!prs_align(ps))
+               return False;
+       if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
+               return False;
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_Q_ENUM_DOM_GROUPS structure.
+********************************************************************/
+
+void init_samr_q_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS * q_e,
+                                POLICY_HND *pol,
+                                uint32 start_idx, uint32 size)
+{
+       DEBUG(5, ("init_samr_q_enum_dom_groups\n"));
+
+       q_e->pol = *pol;
+
+       q_e->start_idx = start_idx;
+       q_e->max_size = size;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_q_enum_dom_groups(char *desc, SAMR_Q_ENUM_DOM_GROUPS * q_e,
+                              prs_struct *ps, int depth)
+{
+       if (q_e == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_q_enum_dom_groups");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("pol", &(q_e->pol), ps, depth))
+               return False;
+
+       if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
+               return False;
+       if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_R_ENUM_DOM_GROUPS structure.
+********************************************************************/
+
+void init_samr_r_enum_dom_groups(SAMR_R_ENUM_DOM_GROUPS * r_u,
+                                uint32 next_idx, uint32 num_sam_entries)
+{
+       DEBUG(5, ("init_samr_r_enum_dom_groups\n"));
+
+       r_u->next_idx = next_idx;
+
+       if (num_sam_entries != 0) {
+               r_u->ptr_entries1 = 1;
+               r_u->ptr_entries2 = 1;
+               r_u->num_entries2 = num_sam_entries;
+               r_u->num_entries3 = num_sam_entries;
+
+               r_u->num_entries4 = num_sam_entries;
+       } else {
+               r_u->ptr_entries1 = 0;
+               r_u->num_entries2 = num_sam_entries;
+               r_u->ptr_entries2 = 1;
+       }
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_r_enum_dom_groups(char *desc, SAMR_R_ENUM_DOM_GROUPS * r_u,
+                              prs_struct *ps, int depth)
+{
+       uint32 i;
+
+       if (r_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_enum_dom_groups");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!prs_uint32("next_idx    ", ps, depth, &r_u->next_idx))
+               return False;
+       if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
+               return False;
+
+       if (r_u->ptr_entries1 != 0) {
+               if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
+                       return False;
+               if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
+                       return False;
+               if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
+                       return False;
+
+               if (UNMARSHALLING(ps)) {
+                       r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
+                       r_u->uni_grp_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
+               }
+
+               if ((r_u->sam == NULL || r_u->uni_grp_name == NULL) && r_u->num_entries2 != 0) {
+                       DEBUG(0,
+                             ("NULL pointers in SAMR_R_ENUM_DOM_GROUPS\n"));
+                       r_u->num_entries4 = 0;
+                       r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
+                       return False;
+               }
+
+               for (i = 0; i < r_u->num_entries2; i++) {
+                       if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth))
+                               return False;
+               }
+
+               for (i = 0; i < r_u->num_entries2; i++) {
+                       if(!smb_io_unistr2("", &r_u->uni_grp_name[i],
+                                      r_u->sam[i].hdr_name.buffer, ps, depth))
+                               return False;
+               }
+       }
+
+       if(!prs_align(ps))
+               return False;
+       if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
+               return False;
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_Q_ENUM_DOM_ALIASES structure.
+********************************************************************/
+
+void init_samr_q_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES * q_e,
+                                 POLICY_HND *pol, uint32 start_idx,
+                                 uint32 size)
+{
+       DEBUG(5, ("init_samr_q_enum_dom_aliases\n"));
+
+       q_e->pol = *pol;
+
+       q_e->start_idx = start_idx;
+       q_e->max_size = size;
+}
+
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_q_enum_dom_aliases(char *desc, SAMR_Q_ENUM_DOM_ALIASES * q_e,
+                               prs_struct *ps, int depth)
+{
+       if (q_e == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_q_enum_dom_aliases");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
+               return False;
+
+       if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
+               return False;
+       if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_R_ENUM_DOM_ALIASES structure.
+********************************************************************/
+
+void init_samr_r_enum_dom_aliases(SAMR_R_ENUM_DOM_ALIASES *r_u, uint32 next_idx, uint32 num_sam_entries)
+{
+       DEBUG(5, ("init_samr_r_enum_dom_aliases\n"));
+
+       r_u->next_idx = next_idx;
+
+       if (num_sam_entries != 0) {
+               r_u->ptr_entries1 = 1;
+               r_u->ptr_entries2 = 1;
+               r_u->num_entries2 = num_sam_entries;
+               r_u->num_entries3 = num_sam_entries;
+
+               r_u->num_entries4 = num_sam_entries;
+       } else {
+               r_u->ptr_entries1 = 0;
+               r_u->num_entries2 = num_sam_entries;
+               r_u->ptr_entries2 = 1;
+       }
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_r_enum_dom_aliases(char *desc, SAMR_R_ENUM_DOM_ALIASES * r_u,
+                               prs_struct *ps, int depth)
+{
+       uint32 i;
+
+       if (r_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_enum_dom_aliases");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!prs_uint32("next_idx    ", ps, depth, &r_u->next_idx))
+               return False;
+       if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
+               return False;
+
+       if (r_u->ptr_entries1 != 0) {
+               if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
+                       return False;
+               if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
+                       return False;
+               if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
+                       return False;
+
+               if (UNMARSHALLING(ps) && (r_u->num_entries2 > 0)) {
+                       r_u->sam = (SAM_ENTRY *)prs_alloc_mem(ps,sizeof(SAM_ENTRY)*r_u->num_entries2);
+                       r_u->uni_grp_name = (UNISTR2 *)prs_alloc_mem(ps,sizeof(UNISTR2)*r_u->num_entries2);
+               }
+
+               if (r_u->num_entries2 != 0 && 
+                   (r_u->sam == NULL || r_u->uni_grp_name == NULL)) {
+                       DEBUG(0,("NULL pointers in SAMR_R_ENUM_DOM_ALIASES\n"));
+                       r_u->num_entries4 = 0;
+                       r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
+                       return False;
+               }
+
+               for (i = 0; i < r_u->num_entries2; i++) {
+                       if(!sam_io_sam_entry("", &r_u->sam[i], ps, depth))
+                               return False;
+               }
+
+               for (i = 0; i < r_u->num_entries2; i++) {
+                       if(!smb_io_unistr2("", &r_u->uni_grp_name[i],
+                                      r_u->sam[i].hdr_name.buffer, ps,
+                                      depth))
+                               return False;
+               }
+       }
+
+       if(!prs_align(ps))
+               return False;
+       if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
+               return False;
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a ALIAS_INFO3 structure.
+********************************************************************/
+
+void init_samr_alias_info3(ALIAS_INFO3 * al3, char *acct_desc)
+{
+       int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0;
+
+       DEBUG(5, ("init_samr_alias_info3\n"));
+
+       init_uni_hdr(&al3->hdr_acct_desc, acct_len);
+       init_unistr2(&al3->uni_acct_desc, acct_desc, acct_len);
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_alias_info3(char *desc, ALIAS_INFO3 * al3,
+                        prs_struct *ps, int depth)
+{
+       if (al3 == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_alias_info3");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_unihdr("hdr_acct_desc", &al3->hdr_acct_desc, ps, depth))
+               return False;
+       if(!smb_io_unistr2("uni_acct_desc", &al3->uni_acct_desc,
+                      al3->hdr_acct_desc.buffer, ps, depth))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_alias_info_ctr(char *desc, ALIAS_INFO_CTR * ctr,
+                        prs_struct *ps, int depth)
+{
+       if (ctr == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_alias_info_ctr");
+       depth++;
+
+       if(!prs_uint16("switch_value1", ps, depth, &ctr->switch_value1))
+               return False;
+       if(!prs_uint16("switch_value2", ps, depth, &ctr->switch_value2))
+               return False;
+
+       switch (ctr->switch_value1) {
+       case 3: 
+               if(!samr_io_alias_info3("alias_info3", &ctr->alias.info3, ps, depth))
+                       return False;
+               break;
+       default:
+               DEBUG(0,("samr_alias_info_ctr: unsupported switch level\n"));
+               break;
+       }
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_Q_QUERY_ALIASINFO structure.
+********************************************************************/
+
+void init_samr_q_query_aliasinfo(SAMR_Q_QUERY_ALIASINFO * q_e,
+                                POLICY_HND *pol, uint16 switch_level)
+{
+       DEBUG(5, ("init_samr_q_query_aliasinfo\n"));
+
+       q_e->pol = *pol;
+       q_e->switch_level = switch_level;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_q_query_aliasinfo(char *desc, SAMR_Q_QUERY_ALIASINFO * q_e,
+                              prs_struct *ps, int depth)
+{
+       if (q_e == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_q_query_aliasinfo");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("pol", &(q_e->pol), ps, depth))
+               return False;
+
+       if(!prs_uint16("switch_level", ps, depth, &q_e->switch_level))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_R_QUERY_ALIASINFO structure.
+********************************************************************/
+
+void init_samr_r_query_aliasinfo(SAMR_R_QUERY_ALIASINFO * r_u,
+                                ALIAS_INFO_CTR * ctr, uint32 status)
+{
+       DEBUG(5, ("init_samr_r_query_aliasinfo\n"));
+
+       r_u->ptr = (status == 0x0 && ctr != NULL) ? 1 : 0;
+       r_u->ctr = *ctr;
+       r_u->status = status;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_r_query_aliasinfo(char *desc, SAMR_R_QUERY_ALIASINFO * r_u,
+                              prs_struct *ps, int depth)
+{
+       if (r_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_query_aliasinfo");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
+               return False;
+
+       if (r_u->ptr != 0) {
+               if(!samr_alias_info_ctr("ctr", &r_u->ctr, ps, depth))
+                       return False;
+       }
+
+       if(!prs_align(ps))
+               return False;
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_Q_SET_ALIASINFO structure.
+********************************************************************/
+
+void init_samr_q_set_aliasinfo(SAMR_Q_SET_ALIASINFO * q_u,
+                              POLICY_HND *hnd, ALIAS_INFO_CTR * ctr)
+{
+       DEBUG(5, ("init_samr_q_set_aliasinfo\n"));
+
+       q_u->alias_pol = *hnd;
+       q_u->ctr = *ctr;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_q_set_aliasinfo(char *desc, SAMR_Q_SET_ALIASINFO * q_u,
+                            prs_struct *ps, int depth)
+{
+       if (q_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_q_set_aliasinfo");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
+               return False;
+       if(!samr_alias_info_ctr("ctr", &q_u->ctr, ps, depth))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_r_set_aliasinfo(char *desc, SAMR_R_SET_ALIASINFO * r_u,
+                            prs_struct *ps, int depth)
+{
+       if (r_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_set_aliasinfo");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_Q_QUERY_USERALIASES structure.
+********************************************************************/
+
+void init_samr_q_query_useraliases(SAMR_Q_QUERY_USERALIASES * q_u,
+                                  POLICY_HND *hnd,
+                                  uint32 num_sids,
+                                  uint32 *ptr_sid, DOM_SID2 * sid)
+{
+       DEBUG(5, ("init_samr_q_query_useraliases\n"));
+
+       q_u->pol = *hnd;
+
+       q_u->num_sids1 = num_sids;
+       q_u->ptr = 1;
+       q_u->num_sids2 = num_sids;
+
+       q_u->ptr_sid = ptr_sid;
+       q_u->sid = sid;
+}
+
+/*******************************************************************
+reads or writes a SAMR_Q_QUERY_USERALIASES structure.
+********************************************************************/
+
+BOOL samr_io_q_query_useraliases(char *desc, SAMR_Q_QUERY_USERALIASES * q_u,
+                                prs_struct *ps, int depth)
+{
+       fstring tmp;
+       uint32 i;
+
+       if (q_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_q_query_useraliases");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
+               return False;
+
+       if(!prs_uint32("num_sids1", ps, depth, &q_u->num_sids1))
+               return False;
+       if(!prs_uint32("ptr      ", ps, depth, &q_u->ptr))
+               return False;
+
+       if (q_u->ptr==0)
+               return True;
+
+       if(!prs_uint32("num_sids2", ps, depth, &q_u->num_sids2))
+               return False;
+
+       if (UNMARSHALLING(ps) && (q_u->num_sids2 != 0)) {
+               q_u->ptr_sid = (uint32 *)prs_alloc_mem(ps,sizeof(q_u->ptr_sid[0])*q_u->num_sids2);
+               if (q_u->ptr_sid == NULL)
+                       return False;
+
+               q_u->sid = (DOM_SID2 *)prs_alloc_mem(ps, sizeof(q_u->sid[0]) * q_u->num_sids2);
+               if (q_u->sid == NULL)
+                       return False;
+       }
+
+       for (i = 0; i < q_u->num_sids2; i++) {
+               slprintf(tmp, sizeof(tmp) - 1, "ptr[%02d]", i);
+               if(!prs_uint32(tmp, ps, depth, &q_u->ptr_sid[i]))
+                       return False;
+       }
+
+       for (i = 0; i < q_u->num_sids2; i++) {
+               if (q_u->ptr_sid[i] != 0) {
+                       slprintf(tmp, sizeof(tmp) - 1, "sid[%02d]", i);
+                       if(!smb_io_dom_sid2(tmp, &q_u->sid[i], ps, depth))
+                               return False;
+               }
+       }
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_R_QUERY_USERALIASES structure.
+********************************************************************/
+
+void init_samr_r_query_useraliases(SAMR_R_QUERY_USERALIASES * r_u,
+                                  uint32 num_rids, uint32 *rid,
+                                  uint32 status)
+{
+       DEBUG(5, ("init_samr_r_query_useraliases\n"));
+
+       if (status == 0x0) {
+               r_u->num_entries = num_rids;
+               r_u->ptr = 1;
+               r_u->num_entries2 = num_rids;
+
+               r_u->rid = rid;
+       } else {
+               r_u->num_entries = 0;
+               r_u->ptr = 0;
+               r_u->num_entries2 = 0;
+       }
+
+       r_u->status = status;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_rids(char *desc, uint32 *num_rids, uint32 **rid,
+                 prs_struct *ps, int depth)
+{
+       fstring tmp;
+       uint32 i;
+       if (rid == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_rids");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!prs_uint32("num_rids", ps, depth, num_rids))
+               return False;
+
+       if ((*num_rids) != 0) {
+               if (UNMARSHALLING(ps)) {
+                       /* reading */
+                       (*rid) = (uint32 *)prs_alloc_mem(ps,sizeof(uint32)*(*num_rids));
+               }
+               if ((*rid) == NULL)
+                       return False;
+
+               for (i = 0; i < (*num_rids); i++) {
+                       slprintf(tmp, sizeof(tmp) - 1, "rid[%02d]", i);
+                       if(!prs_uint32(tmp, ps, depth, &((*rid)[i])))
+                               return False;
+               }
+       }
+
+       return True;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_r_query_useraliases(char *desc, SAMR_R_QUERY_USERALIASES * r_u,
+                                prs_struct *ps, int depth)
+{
+       if (r_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_query_useraliases");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!prs_uint32("num_entries", ps, depth, &r_u->num_entries))
+               return False;
+       if(!prs_uint32("ptr        ", ps, depth, &r_u->ptr))
+               return False;
+
+       if (r_u->ptr != 0) {
+               if(!samr_io_rids("rids", &r_u->num_entries2, &r_u->rid, ps, depth))
+                       return False;
+       }
+
+       if(!prs_align(ps))
+               return False;
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_Q_OPEN_ALIAS structure.
+********************************************************************/
+
+void init_samr_q_open_alias(SAMR_Q_OPEN_ALIAS * q_u, POLICY_HND *pol,
+                           uint32 unknown_0, uint32 rid)
+{
+       DEBUG(5, ("init_samr_q_open_alias\n"));
+
+       q_u->dom_pol = *pol;
+
+       /* example values: 0x0000 0008 */
+       q_u->unknown_0 = unknown_0;
+
+       q_u->rid_alias = rid;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_q_open_alias(char *desc, SAMR_Q_OPEN_ALIAS * q_u,
+                         prs_struct *ps, int depth)
+{
+       if (q_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_q_open_alias");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("domain_pol", &q_u->dom_pol, ps, depth))
+               return False;
+
+       if(!prs_uint32("unknown_0", ps, depth, &q_u->unknown_0))
+               return False;
+       if(!prs_uint32("rid_alias", ps, depth, &q_u->rid_alias))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_r_open_alias(char *desc, SAMR_R_OPEN_ALIAS * r_u,
+                         prs_struct *ps, int depth)
+{
+       if (r_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_open_alias");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
+               return False;
+
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_Q_LOOKUP_RIDS structure.
+********************************************************************/
+
+void init_samr_q_lookup_rids(TALLOC_CTX *ctx, SAMR_Q_LOOKUP_RIDS * q_u,
+                            POLICY_HND *pol, uint32 flags,
+                            uint32 num_rids, uint32 *rid)
+{
+       DEBUG(5, ("init_samr_q_lookup_rids\n"));
+
+       q_u->pol = *pol;
+
+       q_u->num_rids1 = num_rids;
+       q_u->flags = flags;
+       q_u->ptr = 0;
+       q_u->num_rids2 = num_rids;
+       q_u->rid = (uint32 *)talloc_zero(ctx, num_rids * sizeof(q_u->rid[0]));
+       if (q_u->rid == NULL) {
+               q_u->num_rids1 = 0;
+               q_u->num_rids2 = 0;
+       }
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_q_lookup_rids(char *desc, SAMR_Q_LOOKUP_RIDS * q_u,
+                          prs_struct *ps, int depth)
+{
+       uint32 i;
+       fstring tmp;
+
+       if (q_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_q_lookup_rids");
+       depth++;
+
+       if (UNMARSHALLING(ps))
+               ZERO_STRUCTP(q_u);
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
+               return False;
+
+       if(!prs_uint32("num_rids1", ps, depth, &q_u->num_rids1))
+               return False;
+       if(!prs_uint32("flags    ", ps, depth, &q_u->flags))
+               return False;
+       if(!prs_uint32("ptr      ", ps, depth, &q_u->ptr))
+               return False;
+       if(!prs_uint32("num_rids2", ps, depth, &q_u->num_rids2))
+               return False;
+
+       if (UNMARSHALLING(ps) && (q_u->num_rids2 != 0)) {
+               q_u->rid = (uint32 *)prs_alloc_mem(ps, sizeof(q_u->rid[0])*q_u->num_rids2);
+               if (q_u->rid == NULL)
+                       return False;
+       }
+
+       for (i = 0; i < q_u->num_rids2; i++) {
+               slprintf(tmp, sizeof(tmp) - 1, "rid[%02d]  ", i);
+               if(!prs_uint32(tmp, ps, depth, &q_u->rid[i]))
+                       return False;
+       }
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_R_LOOKUP_RIDS structure.
+********************************************************************/
+
+void init_samr_r_lookup_rids(SAMR_R_LOOKUP_RIDS * r_u,
+                            uint32 num_names, UNIHDR * hdr_name,
+                            UNISTR2 *uni_name, uint32 *type)
+{
+       DEBUG(5, ("init_samr_r_lookup_rids\n"));
+
+       r_u->hdr_name = NULL;
+       r_u->uni_name = NULL;
+       r_u->type = NULL;
+
+       if (num_names != 0) {
+               r_u->num_names1 = num_names;
+               r_u->ptr_names = 1;
+               r_u->num_names2 = num_names;
+
+               r_u->num_types1 = num_names;
+               r_u->ptr_types = 1;
+               r_u->num_types2 = num_names;
+
+               r_u->hdr_name = hdr_name;
+               r_u->uni_name = uni_name;
+               r_u->type = type;
+       } else {
+               r_u->num_names1 = num_names;
+               r_u->ptr_names = 0;
+               r_u->num_names2 = num_names;
+
+               r_u->num_types1 = num_names;
+               r_u->ptr_types = 0;
+               r_u->num_types2 = num_names;
+       }
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_r_lookup_rids(char *desc, SAMR_R_LOOKUP_RIDS * r_u,
+                          prs_struct *ps, int depth)
+{
+       uint32 i;
+       fstring tmp;
+       if (r_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_lookup_rids");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!prs_uint32("num_names1", ps, depth, &r_u->num_names1))
+               return False;
+       if(!prs_uint32("ptr_names ", ps, depth, &r_u->ptr_names))
+               return False;
+
+       if (r_u->ptr_names != 0) {
+
+               if(!prs_uint32("num_names2", ps, depth, &r_u->num_names2))
+                       return False;
+
+
+               if (UNMARSHALLING(ps) && (r_u->num_names2 != 0)) {
+                       r_u->hdr_name = (UNIHDR *) prs_alloc_mem(ps, r_u->num_names2 * sizeof(r_u->hdr_name[0]));
+                       if (r_u->hdr_name == NULL)
+                               return False;
+
+                       r_u->uni_name = (UNISTR2 *)prs_alloc_mem(ps, r_u->num_names2 * sizeof(r_u->uni_name[0]));
+                       if (r_u->uni_name == NULL)
+                               return False;
+               }
+               
+               for (i = 0; i < r_u->num_names2; i++) {
+                       slprintf(tmp, sizeof(tmp) - 1, "hdr[%02d]  ", i);
+                       if(!smb_io_unihdr("", &r_u->hdr_name[i], ps, depth))
+                               return False;
+               }
+               for (i = 0; i < r_u->num_names2; i++) {
+                       slprintf(tmp, sizeof(tmp) - 1, "str[%02d]  ", i);
+                       if(!smb_io_unistr2("", &r_u->uni_name[i], r_u->hdr_name[i].buffer, ps, depth))
+                               return False;
+               }
+
+       }
        
+       if(!prs_align(ps))
+               return False;
+       if(!prs_uint32("num_types1", ps, depth, &r_u->num_types1))
+               return False;
+       if(!prs_uint32("ptr_types ", ps, depth, &r_u->ptr_types))
+               return False;
+
+       if (r_u->ptr_types != 0) {
+
+               if(!prs_uint32("num_types2", ps, depth, &r_u->num_types2))
+                       return False;
+
+               if (UNMARSHALLING(ps) && (r_u->num_types2 != 0)) {
+                       r_u->type = (uint32 *)prs_alloc_mem(ps, r_u->num_types2 * sizeof(r_u->type[0]));
+                       if (r_u->type == NULL)
+                               return False;
+               }
+
+               for (i = 0; i < r_u->num_types2; i++) {
+                       slprintf(tmp, sizeof(tmp) - 1, "type[%02d]  ", i);
+                       if(!prs_uint32(tmp, ps, depth, &r_u->type[i]))
+                               return False;
+               }
+       }
+
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_Q_OPEN_ALIAS structure.
+********************************************************************/
+
+void init_samr_q_delete_alias(SAMR_Q_DELETE_DOM_ALIAS * q_u, POLICY_HND *hnd)
+{
+       DEBUG(5, ("init_samr_q_delete_alias\n"));
+
+       q_u->alias_pol = *hnd;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_q_delete_alias(char *desc, SAMR_Q_DELETE_DOM_ALIAS * q_u,
+                           prs_struct *ps, int depth)
+{
+       if (q_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_q_delete_alias");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_r_delete_alias(char *desc, SAMR_R_DELETE_DOM_ALIAS * r_u,
+                           prs_struct *ps, int depth)
+{
+       if (r_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_delete_alias");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
+               return False;
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_Q_CREATE_DOM_ALIAS structure.
+********************************************************************/
+
+void init_samr_q_create_dom_alias(SAMR_Q_CREATE_DOM_ALIAS * q_u,
+                                 POLICY_HND *hnd, char *acct_desc)
+{
+       int acct_len = acct_desc != NULL ? strlen(acct_desc) : 0;
+
+       DEBUG(5, ("init_samr_q_create_dom_alias\n"));
+
+       q_u->dom_pol = *hnd;
+
+       init_uni_hdr(&q_u->hdr_acct_desc, acct_len);
+       init_unistr2(&q_u->uni_acct_desc, acct_desc, acct_len);
+
+       q_u->access_mask = 0x001f000f;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_q_create_dom_alias(char *desc, SAMR_Q_CREATE_DOM_ALIAS * q_u,
+                               prs_struct *ps, int depth)
+{
+       if (q_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_q_create_dom_alias");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("dom_pol", &q_u->dom_pol, ps, depth))
+               return False;
+
+       if(!smb_io_unihdr("hdr_acct_desc", &q_u->hdr_acct_desc, ps, depth))
+               return False;
+       if(!smb_io_unistr2("uni_acct_desc", &q_u->uni_acct_desc,
+                      q_u->hdr_acct_desc.buffer, ps, depth))
+               return False;
+
+       if(!prs_align(ps))
+               return False;
+       if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_r_create_dom_alias(char *desc, SAMR_R_CREATE_DOM_ALIAS * r_u,
+                               prs_struct *ps, int depth)
+{
+       if (r_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_create_dom_alias");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("alias_pol", &r_u->alias_pol, ps, depth))
+               return False;
+
+       if(!prs_uint32("rid", ps, depth, &r_u->rid))
+               return False;
+
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_Q_ADD_ALIASMEM structure.
+********************************************************************/
+
+void init_samr_q_add_aliasmem(SAMR_Q_ADD_ALIASMEM * q_u, POLICY_HND *hnd,
+                             DOM_SID *sid)
+{
+       DEBUG(5, ("init_samr_q_add_aliasmem\n"));
+
+       q_u->alias_pol = *hnd;
+       init_dom_sid2(&q_u->sid, sid);
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_q_add_aliasmem(char *desc, SAMR_Q_ADD_ALIASMEM * q_u,
+                           prs_struct *ps, int depth)
+{
+       if (q_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_q_add_aliasmem");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
+               return False;
+       if(!smb_io_dom_sid2("sid      ", &q_u->sid, ps, depth))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_r_add_aliasmem(char *desc, SAMR_R_ADD_ALIASMEM * r_u,
+                           prs_struct *ps, int depth)
+{
+       if (r_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_add_aliasmem");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_Q_DEL_ALIASMEM structure.
+********************************************************************/
+
+void init_samr_q_del_aliasmem(SAMR_Q_DEL_ALIASMEM * q_u, POLICY_HND *hnd,
+                             DOM_SID *sid)
+{
+       DEBUG(5, ("init_samr_q_del_aliasmem\n"));
+
+       q_u->alias_pol = *hnd;
+       init_dom_sid2(&q_u->sid, sid);
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_q_del_aliasmem(char *desc, SAMR_Q_DEL_ALIASMEM * q_u,
+                           prs_struct *ps, int depth)
+{
+       if (q_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_q_del_aliasmem");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
+               return False;
+       if(!smb_io_dom_sid2("sid      ", &q_u->sid, ps, depth))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_r_del_aliasmem(char *desc, SAMR_R_DEL_ALIASMEM * r_u,
+                           prs_struct *ps, int depth)
+{
+       if (r_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_del_aliasmem");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_Q_DELETE_DOM_ALIAS structure.
+********************************************************************/
+
+void init_samr_q_delete_dom_alias(SAMR_Q_DELETE_DOM_ALIAS * q_c,
+                                 POLICY_HND *hnd)
+{
+       DEBUG(5, ("init_samr_q_delete_dom_alias\n"));
+
+       q_c->alias_pol = *hnd;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_q_delete_dom_alias(char *desc, SAMR_Q_DELETE_DOM_ALIAS * q_u,
+                               prs_struct *ps, int depth)
+{
+       if (q_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_q_delete_dom_alias");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_R_DELETE_DOM_ALIAS structure.
+********************************************************************/
+
+void init_samr_r_delete_dom_alias(SAMR_R_DELETE_DOM_ALIAS * r_u,
+                                 uint32 status)
+{
+       DEBUG(5, ("init_samr_r_delete_dom_alias\n"));
+
+       r_u->status = status;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_r_delete_dom_alias(char *desc, SAMR_R_DELETE_DOM_ALIAS * r_u,
+                               prs_struct *ps, int depth)
+{
+       if (r_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_delete_dom_alias");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_Q_QUERY_ALIASMEM structure.
+********************************************************************/
+
+void init_samr_q_query_aliasmem(SAMR_Q_QUERY_ALIASMEM * q_c,
+                               POLICY_HND *hnd)
+{
+       DEBUG(5, ("init_samr_q_query_aliasmem\n"));
+
+       q_c->alias_pol = *hnd;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_q_query_aliasmem(char *desc, SAMR_Q_QUERY_ALIASMEM * q_u,
+                             prs_struct *ps, int depth)
+{
+       if (q_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_q_query_aliasmem");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("alias_pol", &q_u->alias_pol, ps, depth))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_R_QUERY_ALIASMEM structure.
+********************************************************************/
+
+void init_samr_r_query_aliasmem(SAMR_R_QUERY_ALIASMEM * r_u,
+                               uint32 num_sids, DOM_SID2 * sid,
+                               uint32 status)
+{
+       DEBUG(5, ("init_samr_r_query_aliasmem\n"));
+
+       if (status == 0) {
+               r_u->num_sids = num_sids;
+               r_u->ptr = (num_sids != 0) ? 1 : 0;
+               r_u->num_sids1 = num_sids;
+
+               r_u->sid = sid;
+       } else {
+               r_u->ptr = 0;
+               r_u->num_sids = 0;
+       }
+
+       r_u->status = status;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_r_query_aliasmem(char *desc, SAMR_R_QUERY_ALIASMEM * r_u,
+                             prs_struct *ps, int depth)
+{
+       uint32 i;
+       uint32 ptr_sid[MAX_LOOKUP_SIDS];
+
+       if (r_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_query_aliasmem");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!prs_uint32("num_sids ", ps, depth, &r_u->num_sids))
+               return False;
+       if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
+               return False;
+
+       if (r_u->ptr != 0) {
+               SMB_ASSERT_ARRAY(ptr_sid, r_u->num_sids);
+
+               if (r_u->num_sids != 0) {
+                       if(!prs_uint32("num_sids1", ps, depth, &r_u->num_sids1))
+                               return False;
+
+                       for (i = 0; i < r_u->num_sids1; i++) {
+                               ptr_sid[i] = 1;
+                               if(!prs_uint32("", ps, depth, &ptr_sid[i]))
+                                 return False;
+                       }
+
+                       for (i = 0; i < r_u->num_sids1; i++) {
+                               if (ptr_sid[i] != 0) {
+                                       if(!smb_io_dom_sid2("", &r_u->sid[i], ps, depth))
+                                               return False;
+                               }
+                       }
+               }
+       }
+
+       if(!prs_align(ps))
+               return False;
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_Q_LOOKUP_NAMES structure.
+********************************************************************/
+
+void init_samr_q_lookup_names(SAMR_Q_LOOKUP_NAMES * q_u,
+                             POLICY_HND *pol, uint32 flags,
+                             uint32 num_names, char **name)
+{
+       uint32 i;
+
+       DEBUG(5, ("init_samr_q_lookup_names\n"));
+
+       q_u->pol = *pol;
+
+       q_u->num_names1 = num_names;
+       q_u->flags = flags;
+       q_u->ptr = 0;
+       q_u->num_names2 = num_names;
+
+       for (i = 0; i < num_names; i++) {
+               int len_name = name[i] != NULL ? strlen(name[i]) : 0;
+               init_uni_hdr(&q_u->hdr_name[i], len_name);      /* unicode header for user_name */
+               init_unistr2(&q_u->uni_name[i], name[i], len_name);     /* unicode string for machine account */
+       }
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_q_lookup_names(char *desc, SAMR_Q_LOOKUP_NAMES * q_u,
+                           prs_struct *ps, int depth)
+{
+       uint32 i;
+
+       if (q_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_q_lookup_names");
+       depth++;
+
+       if (UNMARSHALLING(ps))
+               ZERO_STRUCTP(q_u);
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
+               return False;
+
+       if(!prs_uint32("num_names1", ps, depth, &q_u->num_names1))
+               return False;
+       if(!prs_uint32("flags     ", ps, depth, &q_u->flags))
+               return False;
+       if(!prs_uint32("ptr       ", ps, depth, &q_u->ptr))
+               return False;
+       if(!prs_uint32("num_names2", ps, depth, &q_u->num_names2))
+               return False;
+
+       SMB_ASSERT_ARRAY(q_u->hdr_name, q_u->num_names2);
+
+       for (i = 0; i < q_u->num_names2; i++) {
+               if(!smb_io_unihdr("", &q_u->hdr_name[i], ps, depth))
+                       return False;
+       }
+
+       for (i = 0; i < q_u->num_names2; i++) {
+               if(!smb_io_unistr2("", &q_u->uni_name[i], q_u->hdr_name[i].buffer, ps, depth))
+                       return False;
+       }
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_R_LOOKUP_NAMES structure.
+********************************************************************/
+
+void init_samr_r_lookup_names(TALLOC_CTX *ctx, SAMR_R_LOOKUP_NAMES * r_u,
+                             uint32 num_rids,
+                             uint32 *rid, uint32 *type,
+                             uint32 status)
+{
+       DEBUG(5, ("init_samr_r_lookup_names\n"));
+
+       if ((status == 0) && (num_rids != 0))   {
+               uint32 i;
+
+               r_u->num_types1 = num_rids;
+               r_u->ptr_types = 1;
+               r_u->num_types2 = num_rids;
+
+               r_u->num_rids1 = num_rids;
+               r_u->ptr_rids = 1;
+               r_u->num_rids2 = num_rids;
+
+               r_u->rids = (uint32 *)talloc_zero(ctx, sizeof(uint32)*num_rids);
+               r_u->types = (uint32 *)talloc_zero(ctx, sizeof(uint32)*num_rids);
+
+               if (!r_u->rids || !r_u->types)
+                       goto empty;
+
+               for (i = 0; i < num_rids; i++) {
+                       r_u->rids[i] = rid[i];
+                       r_u->types[i] = type[i];
+               }
+       } else {
+
+  empty:
+               r_u->num_types1 = 0;
+               r_u->ptr_types = 0;
+               r_u->num_types2 = 0;
+
+               r_u->num_rids1 = 0;
+               r_u->ptr_rids = 0;
+               r_u->num_rids2 = 0;
+
+               r_u->rids = NULL;
+               r_u->types = NULL;
+       }
+
+       r_u->status = status;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_r_lookup_names(char *desc, SAMR_R_LOOKUP_NAMES * r_u,
+                           prs_struct *ps, int depth)
+{
+       uint32 i;
+       fstring tmp;
+
+       if (r_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_lookup_names");
+       depth++;
+
+       if (UNMARSHALLING(ps))
+               ZERO_STRUCTP(r_u);
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!prs_uint32("num_rids1", ps, depth, &r_u->num_rids1))
+               return False;
+       if(!prs_uint32("ptr_rids ", ps, depth, &r_u->ptr_rids))
+               return False;
+
+       if (r_u->ptr_rids != 0) {
+               if(!prs_uint32("num_rids2", ps, depth, &r_u->num_rids2))
+                       return False;
+
+               if (r_u->num_rids2 != r_u->num_rids1) {
+                       /* RPC fault */
+                       return False;
+               }
+
+               if (UNMARSHALLING(ps))
+                       r_u->rids = (uint32 *)prs_alloc_mem(ps, sizeof(uint32)*r_u->num_rids2);
+
+               if (!r_u->rids) {
+                       DEBUG(0, ("NULL rids in samr_io_r_lookup_names\n"));
+                       return False;
+               }
+
+               for (i = 0; i < r_u->num_rids2; i++) {
+                       slprintf(tmp, sizeof(tmp) - 1, "rid[%02d]  ", i);
+                       if(!prs_uint32(tmp, ps, depth, &r_u->rids[i]))
+                               return False;
+               }
+       }
+
+       if(!prs_uint32("num_types1", ps, depth, &r_u->num_types1))
+               return False;
+       if(!prs_uint32("ptr_types ", ps, depth, &r_u->ptr_types))
+               return False;
+
+       if (r_u->ptr_types != 0) {
+               if(!prs_uint32("num_types2", ps, depth, &r_u->num_types2))
+                       return False;
+
+               if (r_u->num_types2 != r_u->num_types1) {
+                       /* RPC fault */
+                       return False;
+               }
+
+               if (UNMARSHALLING(ps))
+                       r_u->types = (uint32 *)prs_alloc_mem(ps, sizeof(uint32)*r_u->num_types2);
+
+               if (!r_u->types) {
+                       DEBUG(0, ("NULL types in samr_io_r_lookup_names\n"));
+                       return False;
+               }
+
+               for (i = 0; i < r_u->num_types2; i++) {
+                       slprintf(tmp, sizeof(tmp) - 1, "type[%02d]  ", i);
+                       if(!prs_uint32(tmp, ps, depth, &r_u->types[i]))
+                               return False;
+               }
+       }
+
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_Q_DELETE_DOM_USER structure.
+********************************************************************/
+
+void init_samr_q_delete_dom_user(SAMR_Q_DELETE_DOM_USER * q_c,
+                                POLICY_HND *hnd)
+{
+       DEBUG(5, ("init_samr_q_delete_dom_user\n"));
+
+       q_c->user_pol = *hnd;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_q_delete_dom_user(char *desc, SAMR_Q_DELETE_DOM_USER * q_u,
+                              prs_struct *ps, int depth)
+{
+       if (q_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_q_delete_dom_user");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("user_pol", &q_u->user_pol, ps, depth))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_r_delete_dom_user(char *desc, SAMR_R_DELETE_DOM_USER * r_u,
+                              prs_struct *ps, int depth)
+{
+       if (r_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_delete_dom_user");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+void init_samr_q_open_user(SAMR_Q_OPEN_USER * q_u,
+                          POLICY_HND *pol,
+                          uint32 access_mask, uint32 rid)
+{
+       DEBUG(5, ("samr_init_samr_q_open_user\n"));
+
+       q_u->domain_pol = *pol;
+       q_u->access_mask = access_mask;
+       q_u->user_rid = rid;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_q_open_user(char *desc, SAMR_Q_OPEN_USER * q_u,
+                        prs_struct *ps, int depth)
+{
+       if (q_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_q_open_user");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
+               return False;
+
+       if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
+               return False;
+       if(!prs_uint32("user_rid ", ps, depth, &q_u->user_rid))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_r_open_user(char *desc, SAMR_R_OPEN_USER * r_u,
+                        prs_struct *ps, int depth)
+{
+       if (r_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_open_user");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("user_pol", &r_u->user_pol, ps, depth))
+               return False;
+
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;
+}
+
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+void init_samr_q_create_user(SAMR_Q_CREATE_USER * q_u,
+                            POLICY_HND *pol,
+                            char *name,
+                            uint32 acb_info, uint32 access_mask)
+{
+       int len_name;
+       len_name = strlen(name);
+
+       DEBUG(5, ("samr_init_samr_q_create_user\n"));
+
+       q_u->domain_pol = *pol;
+
+       init_uni_hdr(&q_u->hdr_name, len_name);
+       init_unistr2(&q_u->uni_name, name, len_name);
+
+       q_u->acb_info = acb_info;
+       q_u->access_mask = access_mask;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_q_create_user(char *desc, SAMR_Q_CREATE_USER * q_u,
+                          prs_struct *ps, int depth)
+{
+       if (q_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_q_create_user");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("domain_pol", &q_u->domain_pol, ps, depth))
+               return False;
+
+       if(!smb_io_unihdr("hdr_name", &q_u->hdr_name, ps, depth))
+               return False;
+       if(!smb_io_unistr2("uni_name", &q_u->uni_name, q_u->hdr_name.buffer, ps, depth))
+               return False;
+
+       if(!prs_align(ps))
+               return False;
+       if(!prs_uint32("acb_info   ", ps, depth, &q_u->acb_info))
+               return False;
+       if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_r_create_user(char *desc, SAMR_R_CREATE_USER * r_u,
+                          prs_struct *ps, int depth)
+{
+       if (r_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_create_user");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("user_pol", &r_u->user_pol, ps, depth))
+               return False;
+
+       if(!prs_uint32("unknown_0", ps, depth, &r_u->unknown_0))
+               return False;
+       if(!prs_uint32("user_rid ", ps, depth, &r_u->user_rid))
+               return False;
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAMR_Q_QUERY_USERINFO structure.
+********************************************************************/
+
+void init_samr_q_query_userinfo(SAMR_Q_QUERY_USERINFO * q_u,
+                               POLICY_HND *hnd, uint16 switch_value)
+{
+       DEBUG(5, ("init_samr_q_query_userinfo\n"));
+
+       q_u->pol = *hnd;
+       q_u->switch_value = switch_value;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_q_query_userinfo(char *desc, SAMR_Q_QUERY_USERINFO * q_u,
+                             prs_struct *ps, int depth)
+{
+       if (q_u == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_q_query_userinfo");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
+               return False;
+
+       if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value)) /* 0x0015 or 0x0011 */
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+reads or writes a LOGON_HRS structure.
+********************************************************************/
+
+static BOOL sam_io_logon_hrs(char *desc, LOGON_HRS * hrs,
+                            prs_struct *ps, int depth)
+{
+       if (hrs == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "sam_io_logon_hrs");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!prs_uint32("len  ", ps, depth, &hrs->len))
+               return False;
+
+       if (hrs->len > sizeof(hrs->hours)) {
+               DEBUG(3, ("sam_io_logon_hrs: truncating length from %d\n", hrs->len));
+               hrs->len = sizeof(hrs->hours);
+       }
+
+       if(!prs_uint8s(False, "hours", ps, depth, hrs->hours, hrs->len))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAM_USER_INFO_12 structure.
+********************************************************************/
+
+void init_sam_user_info12(SAM_USER_INFO_12 * usr,
+                         uint8 lm_pwd[16], uint8 nt_pwd[16])
+{
+       DEBUG(5, ("init_sam_user_info12\n"));
+
+       usr->lm_pwd_active =
+               memcpy(usr->lm_pwd, lm_pwd, sizeof(usr->lm_pwd)) ? 1 : 0;
+       usr->nt_pwd_active =
+               memcpy(usr->nt_pwd, nt_pwd, sizeof(usr->nt_pwd)) ? 1 : 0;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+static BOOL sam_io_user_info12(char *desc, SAM_USER_INFO_12 * u,
+                       prs_struct *ps, int depth)
+{
+       if (u == NULL)
+               return False;
+
+       DEBUG(0, ("possible security breach!\n"));
+
+       prs_debug(ps, depth, desc, "samr_io_r_user_info12");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!prs_uint8s(False, "lm_pwd", ps, depth, u->lm_pwd, sizeof(u->lm_pwd)))
+               return False;
+       if(!prs_uint8s(False, "nt_pwd", ps, depth, u->nt_pwd, sizeof(u->nt_pwd)))
+               return False;
+
+       if(!prs_uint8("lm_pwd_active", ps, depth, &u->lm_pwd_active))
+               return False;
+       if(!prs_uint8("nt_pwd_active", ps, depth, &u->nt_pwd_active))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAM_USER_INFO_10 structure.
+********************************************************************/
+
+void init_sam_user_info10(SAM_USER_INFO_10 * usr, uint32 acb_info)
+{
+       DEBUG(5, ("init_sam_user_info10\n"));
+
+       usr->acb_info = acb_info;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+static BOOL sam_io_user_info10(char *desc, SAM_USER_INFO_10 * usr,
+                       prs_struct *ps, int depth)
+{
+       if (usr == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_user_info10");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!prs_uint32("acb_info", ps, depth, &usr->acb_info))
+               return False;
+
+       return True;
+}
+
+/*******************************************************************
+inits a SAM_USER_INFO_11 structure.
+********************************************************************/
+
+void init_sam_user_info11(SAM_USER_INFO_11 * usr,
+                         NTTIME * expiry,
+                         char *mach_acct,
+                         uint32 rid_user, uint32 rid_group, uint16 acct_ctrl)
+{
+       int len_mach_acct;
+
+       DEBUG(5, ("init_sam_user_info11\n"));
+
+       len_mach_acct = strlen(mach_acct);
+
+       memcpy(&(usr->expiry), expiry, sizeof(usr->expiry));    /* expiry time or something? */
+       ZERO_STRUCT(usr->padding_1);    /* 0 - padding 24 bytes */
+
+       init_uni_hdr(&usr->hdr_mach_acct, len_mach_acct);       /* unicode header for machine account */
+       usr->padding_2 = 0;     /* 0 - padding 4 bytes */
+
+       usr->ptr_1 = 1;         /* pointer */
+       ZERO_STRUCT(usr->padding_3);    /* 0 - padding 32 bytes */
+       usr->padding_4 = 0;     /* 0 - padding 4 bytes */
+
+       usr->ptr_2 = 1;         /* pointer */
+       usr->padding_5 = 0;     /* 0 - padding 4 bytes */
+
+       usr->ptr_3 = 1;         /* pointer */
+       ZERO_STRUCT(usr->padding_6);    /* 0 - padding 32 bytes */
+
+       usr->rid_user = rid_user;
+       usr->rid_group = rid_group;
+
+       usr->acct_ctrl = acct_ctrl;
+       usr->unknown_3 = 0x0000;
+
+       usr->unknown_4 = 0x003f;        /* 0x003f      - 16 bit unknown */
+       usr->unknown_5 = 0x003c;        /* 0x003c      - 16 bit unknown */
+
+       ZERO_STRUCT(usr->padding_7);    /* 0 - padding 16 bytes */
+       usr->padding_8 = 0;     /* 0 - padding 4 bytes */
+
+       init_unistr2(&usr->uni_mach_acct, mach_acct, len_mach_acct);    /* unicode string for machine account */
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+static BOOL sam_io_user_info11(char *desc, SAM_USER_INFO_11 * usr,
+                       prs_struct *ps, int depth)
+{
+       if (usr == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "samr_io_r_unknown_11");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!prs_uint8s(False, "padding_0", ps, depth, usr->padding_0, sizeof(usr->padding_0)))
+               return False;
+
+       if(!smb_io_time("time", &usr->expiry, ps, depth))
+               return False;
+
+       if(!prs_uint8s(False, "padding_1", ps, depth, usr->padding_1, sizeof(usr->padding_1)))
+               return False;
+
+       if(!smb_io_unihdr("unihdr", &usr->hdr_mach_acct, ps, depth))
+               return False;
+
+       if(!prs_uint32("padding_2", ps, depth, &usr->padding_2))
+               return False;
+
+       if(!prs_uint32("ptr_1    ", ps, depth, &usr->ptr_1))
+               return False;
+       if(!prs_uint8s(False, "padding_3", ps, depth, usr->padding_3, sizeof(usr->padding_3)))
+               return False;
+
+       if(!prs_uint32("padding_4", ps, depth, &usr->padding_4))
+               return False;
+
+       if(!prs_uint32("ptr_2    ", ps, depth, &usr->ptr_2))
+               return False;
+       if(!prs_uint32("padding_5", ps, depth, &usr->padding_5))
+               return False;
+
+       if(!prs_uint32("ptr_3    ", ps, depth, &usr->ptr_3))
+               return False;
+       if(!prs_uint8s(False, "padding_6", ps, depth, usr->padding_6,sizeof(usr->padding_6)))
+               return False;
+
+       if(!prs_uint32("rid_user ", ps, depth, &usr->rid_user))
+               return False;
+       if(!prs_uint32("rid_group", ps, depth, &usr->rid_group))
+               return False;
+       if(!prs_uint16("acct_ctrl", ps, depth, &usr->acct_ctrl))
+               return False;
+       if(!prs_uint16("unknown_3", ps, depth, &usr->unknown_3))
+               return False;
+       if(!prs_uint16("unknown_4", ps, depth, &usr->unknown_4))
+               return False;
+       if(!prs_uint16("unknown_5", ps, depth, &usr->unknown_5))
+               return False;
+
+       if(!prs_uint8s(False, "padding_7", ps, depth, usr->padding_7, sizeof(usr->padding_7)))
+               return False;
+
+       if(!prs_uint32("padding_8", ps, depth, &(usr->padding_8)))
+               return False;
+
        if(!smb_io_unistr2("unistr2", &usr->uni_mach_acct, True, ps, depth))
                return False;
+
        if(!prs_align(ps))
                return False;
 
@@ -2948,64 +4979,185 @@ BOOL sam_io_user_info11(char *desc,  SAM_USER_INFO_11 *usr, prs_struct *ps, int
        return True;
 }
 
-/*************************************************************************
- init_sam_user_info21
+/*************************************************************************
+ init_sam_user_infoa
+
+ unknown_3 = 0x09f8 27fa
+ unknown_5 = 0x0001 0000
+ unknown_6 = 0x0000 04ec 
+
+ *************************************************************************/
+
+void init_sam_user_info24(SAM_USER_INFO_24 * usr,
+                         char newpass[516], uint16 passlen)
+{
+       DEBUG(10, ("init_sam_user_info24: passlen: %d\n", passlen));
+       memcpy(usr->pass, newpass, sizeof(usr->pass));
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+static BOOL sam_io_user_info24(char *desc, SAM_USER_INFO_24 * usr,
+                              prs_struct *ps, int depth)
+{
+       if (usr == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "sam_io_user_info24");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!prs_uint8s(False, "password", ps, depth, usr->pass, sizeof(usr->pass)))
+               return False;
+
+       return True;
+}
+
+/*************************************************************************
+ init_sam_user_info23
+
+ unknown_3 = 0x09f8 27fa
+ unknown_5 = 0x0001 0000
+ unknown_6 = 0x0000 04ec 
+
+ *************************************************************************/
+
+void init_sam_user_info23W(SAM_USER_INFO_23 * usr, NTTIME * logon_time,        /* all zeros */
+                       NTTIME * logoff_time,   /* all zeros */
+                       NTTIME * kickoff_time,  /* all zeros */
+                       NTTIME * pass_last_set_time,    /* all zeros */
+                       NTTIME * pass_can_change_time,  /* all zeros */
+                       NTTIME * pass_must_change_time, /* all zeros */
+                       UNISTR2 *user_name,
+                       UNISTR2 *full_name,
+                       UNISTR2 *home_dir,
+                       UNISTR2 *dir_drive,
+                       UNISTR2 *log_scr,
+                       UNISTR2 *prof_path,
+                       UNISTR2 *desc,
+                       UNISTR2 *wkstas,
+                       UNISTR2 *unk_str,
+                       UNISTR2 *mung_dial,
+                       uint32 user_rid,        /* 0x0000 0000 */
+                       uint32 group_rid,
+                       uint32 acb_info,
+                       uint32 unknown_3,
+                       uint16 logon_divs,
+                       LOGON_HRS * hrs,
+                       uint32 unknown_5,
+                       char newpass[516], uint32 unknown_6)
+{
+       int len_user_name = user_name != NULL ? user_name->uni_str_len : 0;
+       int len_full_name = full_name != NULL ? full_name->uni_str_len : 0;
+       int len_home_dir = home_dir != NULL ? home_dir->uni_str_len : 0;
+       int len_dir_drive = dir_drive != NULL ? dir_drive->uni_str_len : 0;
+       int len_logon_script = log_scr != NULL ? log_scr->uni_str_len : 0;
+       int len_profile_path = prof_path != NULL ? prof_path->uni_str_len : 0;
+       int len_description = desc != NULL ? desc->uni_str_len : 0;
+       int len_workstations = wkstas != NULL ? wkstas->uni_str_len : 0;
+       int len_unknown_str = unk_str != NULL ? unk_str->uni_str_len : 0;
+       int len_munged_dial = mung_dial != NULL ? mung_dial->uni_str_len : 0;
+
+       usr->logon_time = *logon_time;  /* all zeros */
+       usr->logoff_time = *logoff_time;        /* all zeros */
+       usr->kickoff_time = *kickoff_time;      /* all zeros */
+       usr->pass_last_set_time = *pass_last_set_time;  /* all zeros */
+       usr->pass_can_change_time = *pass_can_change_time;      /* all zeros */
+       usr->pass_must_change_time = *pass_must_change_time;    /* all zeros */
+
+       init_uni_hdr(&usr->hdr_user_name, len_user_name);       /* NULL */
+       init_uni_hdr(&usr->hdr_full_name, len_full_name);
+       init_uni_hdr(&usr->hdr_home_dir, len_home_dir);
+       init_uni_hdr(&usr->hdr_dir_drive, len_dir_drive);
+       init_uni_hdr(&usr->hdr_logon_script, len_logon_script);
+       init_uni_hdr(&usr->hdr_profile_path, len_profile_path);
+       init_uni_hdr(&usr->hdr_acct_desc, len_description);
+       init_uni_hdr(&usr->hdr_workstations, len_workstations);
+       init_uni_hdr(&usr->hdr_unknown_str, len_unknown_str);
+       init_uni_hdr(&usr->hdr_munged_dial, len_munged_dial);
+
+       ZERO_STRUCT(usr->nt_pwd);
+       ZERO_STRUCT(usr->lm_pwd);
+
+       usr->user_rid = user_rid;       /* 0x0000 0000 */
+       usr->group_rid = group_rid;
+       usr->acb_info = acb_info;
+       usr->unknown_3 = unknown_3;     /* 09f8 27fa */
+
+       usr->logon_divs = logon_divs;   /* should be 168 (hours/week) */
+       usr->ptr_logon_hrs = hrs ? 1 : 0;
+
+       ZERO_STRUCT(usr->padding1);
+
+       usr->unknown_5 = unknown_5;     /* 0x0001 0000 */
+
+       memcpy(usr->pass, newpass, sizeof(usr->pass));
 
- unknown_3 = 0x00ff ffff
- unknown_5 = 0x0002 0000
- unknown_6 = 0x0000 04ec 
- *************************************************************************/
+       copy_unistr2(&usr->uni_user_name, user_name);
+       copy_unistr2(&usr->uni_full_name, full_name);
+       copy_unistr2(&usr->uni_home_dir, home_dir);
+       copy_unistr2(&usr->uni_dir_drive, dir_drive);
+       copy_unistr2(&usr->uni_logon_script, log_scr);
+       copy_unistr2(&usr->uni_profile_path, prof_path);
+       copy_unistr2(&usr->uni_acct_desc, desc);
+       copy_unistr2(&usr->uni_workstations, wkstas);
+       copy_unistr2(&usr->uni_unknown_str, unk_str);
+       copy_unistr2(&usr->uni_munged_dial, mung_dial);
 
-void init_sam_user_info21(SAM_USER_INFO_21 *usr, SAM_ACCOUNT *pw)
-{
-       NTTIME          logon_time, logoff_time, kickoff_time,
-                       pass_last_set_time, pass_can_change_time,
-                       pass_must_change_time;
+       usr->unknown_6 = unknown_6;     /* 0x0000 04ec */
+       usr->padding4 = 0;
 
-       int             len_user_name, len_full_name, len_home_dir,
-                       len_dir_drive, len_logon_script, len_profile_path,
-                       len_description, len_workstations, len_unknown_str,
-                       len_munged_dial;
-                       
-       char*           user_name = pdb_get_username(pw);
-       char*           full_name = pdb_get_fullname(pw);
-       char*           home_dir  = pdb_get_homedir(pw);
-       char*           dir_drive = pdb_get_dirdrive(pw);
-       char*           logon_script = pdb_get_logon_script(pw);
-       char*           profile_path = pdb_get_profile_path(pw);
-       char*           description = pdb_get_acct_desc(pw);
-       char*           workstations = pdb_get_workstations(pw);
-       char*           munged_dial = pdb_get_munged_dial(pw);
+       memcpy(&usr->logon_hrs, hrs, sizeof(usr->logon_hrs));
+}
 
-       len_user_name    = user_name    != NULL ? strlen(user_name   )+1 : 0;
-       len_full_name    = full_name    != NULL ? strlen(full_name   )+1 : 0;
-       len_home_dir     = home_dir     != NULL ? strlen(home_dir    )+1 : 0;
-       len_dir_drive    = dir_drive    != NULL ? strlen(dir_drive   )+1 : 0;
-       len_logon_script = logon_script != NULL ? strlen(logon_script)+1 : 0;
-       len_profile_path = profile_path != NULL ? strlen(profile_path)+1 : 0;
-       len_description  = description  != NULL ? strlen(description )+1 : 0;
-       len_workstations = workstations != NULL ? strlen(workstations)+1 : 0;
-       len_unknown_str  = 0;
-       len_munged_dial  = munged_dial  != NULL ? strlen(munged_dial )+1 : 0;
+/*************************************************************************
+ init_sam_user_info23
 
+ unknown_3 = 0x09f8 27fa
+ unknown_5 = 0x0001 0000
+ unknown_6 = 0x0000 04ec 
 
-       /* Create NTTIME structs */
-       unix_to_nt_time (&logon_time,           pdb_get_logon_time(pw));
-       unix_to_nt_time (&logoff_time,          pdb_get_logoff_time(pw));
-       unix_to_nt_time (&kickoff_time,         pdb_get_kickoff_time(pw));
-       unix_to_nt_time (&pass_last_set_time,   pdb_get_pass_last_set_time(pw));
-       unix_to_nt_time (&pass_can_change_time, pdb_get_pass_can_change_time(pw));
-       unix_to_nt_time (&pass_must_change_time,pdb_get_pass_must_change_time(pw));
-       
-       /* structure assignment */
-       usr->logon_time            = logon_time;
-       usr->logoff_time           = logoff_time;
-       usr->kickoff_time          = kickoff_time;
-       usr->pass_last_set_time    = pass_last_set_time;
-       usr->pass_can_change_time  = pass_can_change_time;
-       usr->pass_must_change_time = pass_must_change_time;
+ *************************************************************************/
 
-       init_uni_hdr(&usr->hdr_user_name, len_user_name);
+void init_sam_user_info23A(SAM_USER_INFO_23 * usr, NTTIME * logon_time,        /* all zeros */
+                          NTTIME * logoff_time,        /* all zeros */
+                          NTTIME * kickoff_time,       /* all zeros */
+                          NTTIME * pass_last_set_time, /* all zeros */
+                          NTTIME * pass_can_change_time,       /* all zeros */
+                          NTTIME * pass_must_change_time,      /* all zeros */
+                          char *user_name,     /* NULL */
+                          char *full_name,
+                          char *home_dir, char *dir_drive, char *log_scr,
+                          char *prof_path, char *desc, char *wkstas,
+                          char *unk_str, char *mung_dial, uint32 user_rid,     /* 0x0000 0000 */
+                          uint32 group_rid, uint32 acb_info,
+                          uint32 unknown_3, uint16 logon_divs,
+                          LOGON_HRS * hrs, uint32 unknown_5,
+                          char newpass[516], uint32 unknown_6)
+{
+       int len_user_name = user_name != NULL ? strlen(user_name) : 0;
+       int len_full_name = full_name != NULL ? strlen(full_name) : 0;
+       int len_home_dir = home_dir != NULL ? strlen(home_dir) : 0;
+       int len_dir_drive = dir_drive != NULL ? strlen(dir_drive) : 0;
+       int len_logon_script = log_scr != NULL ? strlen(log_scr) : 0;
+       int len_profile_path = prof_path != NULL ? strlen(prof_path) : 0;
+       int len_description = desc != NULL ? strlen(desc) : 0;
+       int len_workstations = wkstas != NULL ? strlen(wkstas) : 0;
+       int len_unknown_str = unk_str != NULL ? strlen(unk_str) : 0;
+       int len_munged_dial = mung_dial != NULL ? strlen(mung_dial) : 0;
+
+       usr->logon_time = *logon_time;  /* all zeros */
+       usr->logoff_time = *logoff_time;        /* all zeros */
+       usr->kickoff_time = *kickoff_time;      /* all zeros */
+       usr->pass_last_set_time = *pass_last_set_time;  /* all zeros */
+       usr->pass_can_change_time = *pass_can_change_time;      /* all zeros */
+       usr->pass_must_change_time = *pass_must_change_time;    /* all zeros */
+
+       init_uni_hdr(&usr->hdr_user_name, len_user_name);       /* NULL */
        init_uni_hdr(&usr->hdr_full_name, len_full_name);
        init_uni_hdr(&usr->hdr_home_dir, len_home_dir);
        init_uni_hdr(&usr->hdr_dir_drive, len_dir_drive);
@@ -3016,861 +5168,883 @@ void init_sam_user_info21(SAM_USER_INFO_21 *usr, SAM_ACCOUNT *pw)
        init_uni_hdr(&usr->hdr_unknown_str, len_unknown_str);
        init_uni_hdr(&usr->hdr_munged_dial, len_munged_dial);
 
-       memset((char *)usr->nt_pwd, '\0', sizeof(usr->nt_pwd));
-       memset((char *)usr->lm_pwd, '\0', sizeof(usr->lm_pwd));
+       ZERO_STRUCT(usr->nt_pwd);
+       ZERO_STRUCT(usr->lm_pwd);
 
-       usr->user_rid  = pdb_get_user_rid(pw);
-       usr->group_rid = pdb_get_group_rid(pw);
-       usr->acb_info  = pdb_get_acct_ctrl(pw);
-       usr->unknown_3 = pdb_get_unknown3(pw);
+       usr->user_rid = user_rid;       /* 0x0000 0000 */
+       usr->group_rid = group_rid;
+       usr->acb_info = acb_info;
+       usr->unknown_3 = unknown_3;     /* 09f8 27fa */
 
-       usr->logon_divs = pdb_get_logon_divs(pw); 
-       usr->ptr_logon_hrs = pdb_get_hours(pw) ? 1 : 0;
-       usr->unknown_5 = pdb_get_unknown5(pw); /* 0x0002 0000 */
+       usr->logon_divs = logon_divs;   /* should be 168 (hours/week) */
+       usr->ptr_logon_hrs = hrs ? 1 : 0;
 
-       memset((char *)usr->padding1, '\0', sizeof(usr->padding1));
+       ZERO_STRUCT(usr->padding1);
 
-       init_unistr2(&usr->uni_user_name, user_name, len_user_name);
+       usr->unknown_5 = unknown_5;     /* 0x0001 0000 */
+
+       memcpy(usr->pass, newpass, sizeof(usr->pass));
+
+       init_unistr2(&usr->uni_user_name, user_name, len_user_name);    /* NULL */
        init_unistr2(&usr->uni_full_name, full_name, len_full_name);
        init_unistr2(&usr->uni_home_dir, home_dir, len_home_dir);
        init_unistr2(&usr->uni_dir_drive, dir_drive, len_dir_drive);
-       init_unistr2(&usr->uni_logon_script, logon_script, len_logon_script);
-       init_unistr2(&usr->uni_profile_path, profile_path, len_profile_path);
-       init_unistr2(&usr->uni_acct_desc, description, len_description);
-       init_unistr2(&usr->uni_workstations, workstations, len_workstations);
-       init_unistr2(&usr->uni_unknown_str, NULL, len_unknown_str);
-       init_unistr2(&usr->uni_munged_dial, munged_dial, len_munged_dial);
-
-       usr->unknown_6 = pdb_get_unknown6(pw);
+       init_unistr2(&usr->uni_logon_script, log_scr, len_logon_script);
+       init_unistr2(&usr->uni_profile_path, prof_path, len_profile_path);
+       init_unistr2(&usr->uni_acct_desc, desc, len_description);
+       init_unistr2(&usr->uni_workstations, wkstas, len_workstations);
+       init_unistr2(&usr->uni_unknown_str, unk_str, len_unknown_str);
+       init_unistr2(&usr->uni_munged_dial, mung_dial, len_munged_dial);
+
+       usr->unknown_6 = unknown_6;     /* 0x0000 04ec */
        usr->padding4 = 0;
 
-       if (pdb_get_hours(pw))
-       {
-               usr->logon_hrs.len = pdb_get_hours_len(pw);
-               memcpy(&(usr->logon_hrs.hours), pdb_get_hours(pw), MAX_HOURS_LEN);
-       }
-       else
-               memset(&(usr->logon_hrs), 0xff, sizeof(usr->logon_hrs));
+       memcpy(&usr->logon_hrs, hrs, sizeof(usr->logon_hrs));
 }
 
-
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-static BOOL sam_io_user_info21(char *desc, SAM_USER_INFO_21 *usr, prs_struct *ps, int depth)
+static BOOL sam_io_user_info23(char *desc, SAM_USER_INFO_23 * usr,
+                              prs_struct *ps, int depth)
 {
        if (usr == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "sam_io_user_info21");
+       prs_debug(ps, depth, desc, "sam_io_user_info23");
        depth++;
 
        if(!prs_align(ps))
                return False;
-       
+
        if(!smb_io_time("logon_time           ", &usr->logon_time, ps, depth))
                return False;
-       if(!smb_io_time("logoff_time          ", &usr->logoff_time, ps, depth)) 
+       if(!smb_io_time("logoff_time          ", &usr->logoff_time, ps, depth))
                return False;
-       if(!smb_io_time("kickoff_time         ", &usr->kickoff_time, ps, depth)) 
+       if(!smb_io_time("kickoff_time         ", &usr->kickoff_time, ps, depth))
                return False;
-       if(!smb_io_time("pass_last_set_time   ", &usr->pass_last_set_time, ps, depth)) 
+       if(!smb_io_time("pass_last_set_time   ", &usr->pass_last_set_time, ps, depth))
                return False;
-       if(!smb_io_time("pass_can_change_time ", &usr->pass_can_change_time, ps, depth)) 
+       if(!smb_io_time("pass_can_change_time ", &usr->pass_can_change_time, ps, depth))
                return False;
-       if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time, ps, depth)) 
+       if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time, ps, depth))
                return False;
 
-       if(!smb_io_unihdr("hdr_user_name   ", &usr->hdr_user_name, ps, depth)) /* username unicode string header */
+       if(!smb_io_unihdr("hdr_user_name   ", &usr->hdr_user_name, ps, depth))  /* username unicode string header */
                return False;
-       if(!smb_io_unihdr("hdr_full_name   ", &usr->hdr_full_name, ps, depth)) /* user's full name unicode string header */
+       if(!smb_io_unihdr("hdr_full_name   ", &usr->hdr_full_name, ps, depth))  /* user's full name unicode string header */
                return False;
-       if(!smb_io_unihdr("hdr_home_dir    ", &usr->hdr_home_dir, ps, depth)) /* home directory unicode string header */
+       if(!smb_io_unihdr("hdr_home_dir    ", &usr->hdr_home_dir, ps, depth))   /* home directory unicode string header */
                return False;
-       if(!smb_io_unihdr("hdr_dir_drive   ", &usr->hdr_dir_drive, ps, depth)) /* home directory drive */
+       if(!smb_io_unihdr("hdr_dir_drive   ", &usr->hdr_dir_drive, ps, depth))  /* home directory drive */
                return False;
-       if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth)) /* logon script unicode string header */
+       if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth))       /* logon script unicode string header */
                return False;
-       if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth)) /* profile path unicode string header */
+       if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth))       /* profile path unicode string header */
                return False;
-       if(!smb_io_unihdr("hdr_acct_desc   ", &usr->hdr_acct_desc, ps, depth)) /* account description */
+       if(!smb_io_unihdr("hdr_acct_desc   ", &usr->hdr_acct_desc, ps, depth))  /* account desc */
                return False;
-       if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth)) /* workstations user can log on from */
+       if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth))       /* wkstas user can log on from */
                return False;
-       if(!smb_io_unihdr("hdr_unknown_str ", &usr->hdr_unknown_str, ps, depth)) /* unknown string */
+       if(!smb_io_unihdr("hdr_unknown_str ", &usr->hdr_unknown_str, ps, depth))        /* unknown string */
                return False;
-       if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth)) /* workstations user can log on from */
+       if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth))        /* wkstas user can log on from */
                return False;
 
-       if(!prs_uint8s (False, "lm_pwd        ", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd)))
+       if(!prs_uint8s(False, "lm_pwd        ", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd)))
                return False;
-       if(!prs_uint8s (False, "nt_pwd        ", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd)))
+       if(!prs_uint8s(False, "nt_pwd        ", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd)))
                return False;
 
-       if(!prs_uint32("user_rid      ", ps, depth, &usr->user_rid))       /* User ID */
+       if(!prs_uint32("user_rid      ", ps, depth, &usr->user_rid))    /* User ID */
                return False;
-       if(!prs_uint32("group_rid     ", ps, depth, &usr->group_rid))      /* Group ID */
+       if(!prs_uint32("group_rid     ", ps, depth, &usr->group_rid))   /* Group ID */
                return False;
-       if(!prs_uint32("acb_info      ", ps, depth, &usr->acb_info))      /* Group ID */
+       if(!prs_uint32("acb_info      ", ps, depth, &usr->acb_info))
                return False;
 
        if(!prs_uint32("unknown_3     ", ps, depth, &usr->unknown_3))
                return False;
-       if(!prs_uint16("logon_divs    ", ps, depth, &usr->logon_divs))     /* logon divisions per week */
+       if(!prs_uint16("logon_divs    ", ps, depth, &usr->logon_divs))  /* logon divisions per week */
                return False;
        if(!prs_align(ps))
                return False;
        if(!prs_uint32("ptr_logon_hrs ", ps, depth, &usr->ptr_logon_hrs))
                return False;
+       if(!prs_uint8s(False, "padding1      ", ps, depth, usr->padding1, sizeof(usr->padding1)))
+               return False;
        if(!prs_uint32("unknown_5     ", ps, depth, &usr->unknown_5))
                return False;
 
-       if(!prs_uint8s (False, "padding1      ", ps, depth, usr->padding1, sizeof(usr->padding1)))
+       if(!prs_uint8s(False, "password      ", ps, depth, usr->pass, sizeof(usr->pass)))
                return False;
 
        /* here begins pointed-to data */
 
-       if(!smb_io_unistr2("uni_user_name   ", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth)) /* username unicode string */
-               return False;
-       if(!prs_align_needed(ps, usr->hdr_full_name.buffer))
-               return False;
-       if(!smb_io_unistr2("uni_full_name   ", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth)) /* user's full name unicode string */
-               return False;
-       if(!prs_align_needed(ps, usr->hdr_home_dir.buffer))
-               return False;
-       if(!smb_io_unistr2("uni_home_dir    ", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth)) /* home directory unicode string */
-               return False;
-       if(!prs_align_needed(ps, usr->hdr_dir_drive.buffer))
-               return False;
-       if(!smb_io_unistr2("uni_dir_drive   ", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth)) /* home directory drive unicode string */
-               return False;
-       if(!prs_align_needed(ps, usr->hdr_logon_script.buffer))
-               return False;
-       if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth)) /* logon script unicode string */
+       if(!smb_io_unistr2("uni_user_name   ", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth))      /* username unicode string */
                return False;
-       if(!prs_align_needed(ps, usr->hdr_profile_path.buffer))
-               return False;
-       if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth)) /* profile path unicode string */
+
+       if(!smb_io_unistr2("uni_full_name   ", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth))      /* user's full name unicode string */
                return False;
-       if(!prs_align_needed(ps, usr->hdr_acct_desc.buffer))
+
+       if(!smb_io_unistr2("uni_home_dir    ", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth))        /* home directory unicode string */
                return False;
-       if(!smb_io_unistr2("uni_acct_desc   ", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth)) /* user description unicode string */
+
+       if(!smb_io_unistr2("uni_dir_drive   ", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth))      /* home directory drive unicode string */
                return False;
-       if(!prs_align_needed(ps, usr->hdr_workstations.buffer))
+
+       if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth))        /* logon script unicode string */
                return False;
-       if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth)) /* worksations user can log on from */
+
+       if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth))        /* profile path unicode string */
                return False;
-       if(!prs_align_needed(ps, usr->hdr_unknown_str.buffer))
+
+       if(!smb_io_unistr2("uni_acct_desc   ", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth))      /* user desc unicode string */
                return False;
-       if(!smb_io_unistr2("uni_user_comment", &usr->uni_unknown_str, usr->hdr_unknown_str.buffer, ps, depth)) /* unknown string */
+
+       if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth))        /* worksations user can log on from */
                return False;
-       if(!prs_align_needed(ps, usr->hdr_munged_dial.buffer))
+
+       if(!smb_io_unistr2("uni_unknown_str ", &usr->uni_unknown_str, usr->hdr_unknown_str.buffer, ps, depth))  /* unknown string */
                return False;
-       if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial, usr->hdr_munged_dial.buffer, ps, depth)) /* worksations user can log on from */
+
+       if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial, usr->hdr_munged_dial.buffer, ps, depth))
                return False;
 
+       /* ok, this is only guess-work (as usual) */
        if (usr->ptr_logon_hrs) {
-       
-               if(!prs_align(ps))
-                       return False;
                if(!prs_uint32("unknown_6     ", ps, depth, &usr->unknown_6))
                        return False;
                if(!prs_uint32("padding4      ", ps, depth, &usr->padding4))
                        return False;
-
                if(!sam_io_logon_hrs("logon_hrs", &usr->logon_hrs, ps, depth))
                        return False;
+       } else if (UNMARSHALLING(ps)) {
+               usr->unknown_6 = 0;
+               usr->padding4 = 0;
        }
 
        return True;
 }
 
-/*******************************************************************
- Inits a SAMR_R_QUERY_USERINFO structure.
-********************************************************************/
 
-void init_samr_r_query_userinfo(SAMR_R_QUERY_USERINFO *r_u,
-                               uint16 switch_value, void *info, uint32 status)
-{
-       DEBUG(5,("init_samr_r_query_userinfo\n"));
+/*************************************************************************
+ init_sam_user_info21W
 
-       r_u->ptr = 0;
-       r_u->switch_value = 0;
+ unknown_3 = 0x00ff ffff
+ unknown_5 = 0x0002 0000
+ unknown_6 = 0x0000 04ec 
 
-       if (status == 0) {
-               r_u->switch_value = switch_value;
+ *************************************************************************/
 
-               switch (switch_value) {
-               case 0x10:
-                       r_u->ptr = 1;
-                       r_u->info.id10 = (SAM_USER_INFO_10*)info;
-                       break;
+void init_sam_user_info21W(SAM_USER_INFO_21 * usr,
+                          NTTIME * logon_time,
+                          NTTIME * logoff_time,
+                          NTTIME * kickoff_time,
+                          NTTIME * pass_last_set_time,
+                          NTTIME * pass_can_change_time,
+                          NTTIME * pass_must_change_time,
+                          UNISTR2 *user_name,
+                          UNISTR2 *full_name,
+                          UNISTR2 *home_dir,
+                          UNISTR2 *dir_drive,
+                          UNISTR2 *log_scr,
+                          UNISTR2 *prof_path,
+                          UNISTR2 *desc,
+                          UNISTR2 *wkstas,
+                          UNISTR2 *unk_str,
+                          UNISTR2 *mung_dial,
+                          uchar lm_pwd[16],
+                          uchar nt_pwd[16],
+                          uint32 user_rid,
+                          uint32 group_rid,
+                          uint32 acb_info,
+                          uint32 unknown_3,
+                          uint16 logon_divs,
+                          LOGON_HRS * hrs,
+                          uint32 unknown_5, uint32 unknown_6)
+{
+       int len_user_name = user_name != NULL ? user_name->uni_str_len : 0;
+       int len_full_name = full_name != NULL ? full_name->uni_str_len : 0;
+       int len_home_dir = home_dir != NULL ? home_dir->uni_str_len : 0;
+       int len_dir_drive = dir_drive != NULL ? dir_drive->uni_str_len : 0;
+       int len_logon_script = log_scr != NULL ? log_scr->uni_str_len : 0;
+       int len_profile_path = prof_path != NULL ? prof_path->uni_str_len : 0;
+       int len_description = desc != NULL ? desc->uni_str_len : 0;
+       int len_workstations = wkstas != NULL ? wkstas->uni_str_len : 0;
+       int len_unknown_str = unk_str != NULL ? unk_str->uni_str_len : 0;
+       int len_munged_dial = mung_dial != NULL ? mung_dial->uni_str_len : 0;
+
+       usr->logon_time = *logon_time;
+       usr->logoff_time = *logoff_time;
+       usr->kickoff_time = *kickoff_time;
+       usr->pass_last_set_time = *pass_last_set_time;
+       usr->pass_can_change_time = *pass_can_change_time;
+       usr->pass_must_change_time = *pass_must_change_time;
 
-               case 0x11:
-                       r_u->ptr = 1;
-                       r_u->info.id11 = (SAM_USER_INFO_11*)info;
-                       break;
+       init_uni_hdr(&usr->hdr_user_name, len_user_name);
+       init_uni_hdr(&usr->hdr_full_name, len_full_name);
+       init_uni_hdr(&usr->hdr_home_dir, len_home_dir);
+       init_uni_hdr(&usr->hdr_dir_drive, len_dir_drive);
+       init_uni_hdr(&usr->hdr_logon_script, len_logon_script);
+       init_uni_hdr(&usr->hdr_profile_path, len_profile_path);
+       init_uni_hdr(&usr->hdr_acct_desc, len_description);
+       init_uni_hdr(&usr->hdr_workstations, len_workstations);
+       init_uni_hdr(&usr->hdr_unknown_str, len_unknown_str);
+       init_uni_hdr(&usr->hdr_munged_dial, len_munged_dial);
 
-               case 21:
-                       r_u->ptr = 1;
-                       r_u->info.id21 = (SAM_USER_INFO_21*)info;
-                       break;
+       memcpy(usr->lm_pwd, lm_pwd, sizeof(usr->lm_pwd));
+       memcpy(usr->nt_pwd, nt_pwd, sizeof(usr->nt_pwd));
 
-               default:
-                       DEBUG(4,("init_samr_r_query_aliasinfo: unsupported switch level\n"));
-                       break;
-               }
-       }
+       usr->user_rid = user_rid;
+       usr->group_rid = group_rid;
+       usr->acb_info = acb_info;
+       usr->unknown_3 = unknown_3;     /* 0x00ff ffff */
+
+       usr->logon_divs = logon_divs;   /* should be 168 (hours/week) */
+       usr->ptr_logon_hrs = hrs ? 1 : 0;
+       usr->unknown_5 = unknown_5;     /* 0x0002 0000 */
+
+       ZERO_STRUCT(usr->padding1);
+
+       copy_unistr2(&usr->uni_user_name, user_name);
+       copy_unistr2(&usr->uni_full_name, full_name);
+       copy_unistr2(&usr->uni_home_dir, home_dir);
+       copy_unistr2(&usr->uni_dir_drive, dir_drive);
+       copy_unistr2(&usr->uni_logon_script, log_scr);
+       copy_unistr2(&usr->uni_profile_path, prof_path);
+       copy_unistr2(&usr->uni_acct_desc, desc);
+       copy_unistr2(&usr->uni_workstations, wkstas);
+       copy_unistr2(&usr->uni_unknown_str, unk_str);
+       copy_unistr2(&usr->uni_munged_dial, mung_dial);
+
+       usr->unknown_6 = unknown_6;     /* 0x0000 04ec */
+       usr->padding4 = 0;
 
-       r_u->status = status;         /* return status */
+       memcpy(&usr->logon_hrs, hrs, sizeof(usr->logon_hrs));
 }
 
-/*******************************************************************
- Reads or writes a structure.
-********************************************************************/
-
-BOOL samr_io_r_query_userinfo(char *desc, SAMR_R_QUERY_USERINFO *r_u, 
-                             prs_struct *ps, int depth)
-{
-       if (r_u == NULL)
-               return False;
-
-       prs_debug(ps, depth, desc, "samr_io_r_query_userinfo");
-       depth++;
+/*************************************************************************
+ init_sam_user_info21
 
-       if(!prs_align(ps))
-               return False;
+ unknown_3 = 0x00ff ffff
+ unknown_5 = 0x0002 0000
+ unknown_6 = 0x0000 04ec 
 
-       if(!prs_uint32("ptr         ", ps, depth, &r_u->ptr))
-               return False;
-       if(!prs_uint16("switch_value", ps, depth, &r_u->switch_value))
-               return False;
-       if(!prs_align(ps))
-               return False;
+ *************************************************************************/
 
-       if (r_u->ptr != 0 && r_u->switch_value != 0) {
-               switch (r_u->switch_value) {
-               case 0x10:
-                       if (r_u->info.id10 != NULL) {
-                               if(!sam_io_user_info10("", r_u->info.id10, ps, depth))
-                                       return False;
-                       } else {
-                               DEBUG(2,("samr_io_r_query_userinfo: info pointer not initialised\n"));
-                               return False;
-                       }
-                       break;
-/*
-               case 0x11:
-                       if (r_u->info.id11 != NULL) {
-                               if(!sam_io_user_info11("", r_u->info.id11, ps, depth))
-                                       return False;
-                       } else {
-                               DEBUG(2,("samr_io_r_query_userinfo: info pointer not initialised\n"));
-                               return False;
-                       }
-                       break;
-*/
-               case 21:
-                       if (r_u->info.id21 != NULL) {
-                               if(!sam_io_user_info21("", r_u->info.id21, ps, depth))
-                                       return False;
-                       } else {
-                               DEBUG(2,("samr_io_r_query_userinfo: info pointer not initialised\n"));
-                               return False;
-                       }
-                       break;
-               default:
-                       DEBUG(2,("samr_io_r_query_userinfo: unknown switch level\n"));
-                       break;
-               }
-       }
+void init_sam_user_info21A(SAM_USER_INFO_21 *usr, SAM_ACCOUNT *pw)
+{
+       NTTIME          logon_time, logoff_time, kickoff_time,
+                       pass_last_set_time, pass_can_change_time,
+                       pass_must_change_time;
 
-       if(!prs_align(ps))
-               return False;
+       int             len_user_name, len_full_name, len_home_dir,
+                       len_dir_drive, len_logon_script, len_profile_path,
+                       len_description, len_workstations, len_unknown_str,
+                       len_munged_dial;
+                       
+       char*           user_name = pdb_get_username(pw);
+       char*           full_name = pdb_get_fullname(pw);
+       char*           home_dir  = pdb_get_homedir(pw);
+       char*           dir_drive = pdb_get_dirdrive(pw);
+       char*           logon_script = pdb_get_logon_script(pw);
+       char*           profile_path = pdb_get_profile_path(pw);
+       char*           description = pdb_get_acct_desc(pw);
+       char*           workstations = pdb_get_workstations(pw);
+       char*           munged_dial = pdb_get_munged_dial(pw);
 
-       if(!prs_uint32("status", ps, depth, &r_u->status))
-               return False;
+       len_user_name    = user_name    != NULL ? strlen(user_name   )+1 : 0;
+       len_full_name    = full_name    != NULL ? strlen(full_name   )+1 : 0;
+       len_home_dir     = home_dir     != NULL ? strlen(home_dir    )+1 : 0;
+       len_dir_drive    = dir_drive    != NULL ? strlen(dir_drive   )+1 : 0;
+       len_logon_script = logon_script != NULL ? strlen(logon_script)+1 : 0;
+       len_profile_path = profile_path != NULL ? strlen(profile_path)+1 : 0;
+       len_description  = description  != NULL ? strlen(description )+1 : 0;
+       len_workstations = workstations != NULL ? strlen(workstations)+1 : 0;
+       len_unknown_str  = 0;
+       len_munged_dial  = munged_dial  != NULL ? strlen(munged_dial )+1 : 0;
 
-       return True;
-}
 
-/*******************************************************************
- Reads or writes a structure.
-********************************************************************/
+       /* Create NTTIME structs */
+       unix_to_nt_time (&logon_time,           pdb_get_logon_time(pw));
+       unix_to_nt_time (&logoff_time,          pdb_get_logoff_time(pw));
+       unix_to_nt_time (&kickoff_time,         pdb_get_kickoff_time(pw));
+       unix_to_nt_time (&pass_last_set_time,   pdb_get_pass_last_set_time(pw));
+       unix_to_nt_time (&pass_can_change_time, pdb_get_pass_can_change_time(pw));
+       unix_to_nt_time (&pass_must_change_time,pdb_get_pass_must_change_time(pw));
+       
+       /* structure assignment */
+       usr->logon_time            = logon_time;
+       usr->logoff_time           = logoff_time;
+       usr->kickoff_time          = kickoff_time;
+       usr->pass_last_set_time    = pass_last_set_time;
+       usr->pass_can_change_time  = pass_can_change_time;
+       usr->pass_must_change_time = pass_must_change_time;
 
-BOOL samr_io_q_create_user(char *desc, SAMR_Q_CREATE_USER *q_u, prs_struct *ps, int depth)
-{
-       if (q_u == NULL)
-               return False;
+       init_uni_hdr(&usr->hdr_user_name, len_user_name);
+       init_uni_hdr(&usr->hdr_full_name, len_full_name);
+       init_uni_hdr(&usr->hdr_home_dir, len_home_dir);
+       init_uni_hdr(&usr->hdr_dir_drive, len_dir_drive);
+       init_uni_hdr(&usr->hdr_logon_script, len_logon_script);
+       init_uni_hdr(&usr->hdr_profile_path, len_profile_path);
+       init_uni_hdr(&usr->hdr_acct_desc, len_description);
+       init_uni_hdr(&usr->hdr_workstations, len_workstations);
+       init_uni_hdr(&usr->hdr_unknown_str, len_unknown_str);
+       init_uni_hdr(&usr->hdr_munged_dial, len_munged_dial);
 
-       prs_debug(ps, depth, desc, "samr_io_q_create_user");
-       depth++;
+       ZERO_STRUCT(usr->nt_pwd);
+       ZERO_STRUCT(usr->lm_pwd);
 
-       if(!prs_align(ps))
-               return False;
+       usr->user_rid  = pdb_get_user_rid(pw);
+       usr->group_rid = pdb_get_group_rid(pw);
+       usr->acb_info  = pdb_get_acct_ctrl(pw);
+       usr->unknown_3 = pdb_get_unknown3(pw);
 
-       if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
-               return False;
-       if(!prs_align(ps))
-               return False;
+       usr->logon_divs = pdb_get_logon_divs(pw); 
+       usr->ptr_logon_hrs = pdb_get_hours(pw) ? 1 : 0;
+       usr->unknown_5 = pdb_get_unknown5(pw); /* 0x0002 0000 */
 
-       if(!smb_io_unihdr ("", &q_u->hdr_mach_acct, ps, depth))
-               return False;
-       if(!smb_io_unistr2("", &q_u->uni_mach_acct, q_u->hdr_mach_acct.buffer, ps, depth))
-               return False;
+       ZERO_STRUCT(usr->padding1);
 
-       if(!prs_align(ps))
-               return False;
+       init_unistr2(&usr->uni_user_name, user_name, len_user_name);
+       init_unistr2(&usr->uni_full_name, full_name, len_full_name);
+       init_unistr2(&usr->uni_home_dir, home_dir, len_home_dir);
+       init_unistr2(&usr->uni_dir_drive, dir_drive, len_dir_drive);
+       init_unistr2(&usr->uni_logon_script, logon_script, len_logon_script);
+       init_unistr2(&usr->uni_profile_path, profile_path, len_profile_path);
+       init_unistr2(&usr->uni_acct_desc, description, len_description);
+       init_unistr2(&usr->uni_workstations, workstations, len_workstations);
+       init_unistr2(&usr->uni_unknown_str, NULL, len_unknown_str);
+       init_unistr2(&usr->uni_munged_dial, munged_dial, len_munged_dial);
 
-       if(!prs_uint32("acb_info", ps, depth, &q_u->acb_info))
-               return False;
-       if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
-               return False;
+       usr->unknown_6 = pdb_get_unknown6(pw);
+       usr->padding4 = 0;
 
-       return True;
+       if (pdb_get_hours(pw)) {
+               usr->logon_hrs.len = pdb_get_hours_len(pw);
+               memcpy(&usr->logon_hrs.hours, pdb_get_hours(pw), MAX_HOURS_LEN);
+       } else
+               memset(&usr->logon_hrs, 0xff, sizeof(usr->logon_hrs));
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_r_create_user(char *desc, SAMR_R_CREATE_USER *r_u, prs_struct *ps, int depth)
+static BOOL sam_io_user_info21(char *desc, SAM_USER_INFO_21 * usr,
+                       prs_struct *ps, int depth)
 {
-       if (r_u == NULL)
+       if (usr == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_r_unknown_32");
+       prs_debug(ps, depth, desc, "sam_io_user_info21");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
+       if(!smb_io_time("logon_time           ", &usr->logon_time, ps, depth))
                return False;
-
-       if(!prs_uint32("unknown_0", ps, depth, &r_u->unknown_0))
+       if(!smb_io_time("logoff_time          ", &usr->logoff_time, ps, depth))
                return False;
-       if(!prs_uint32("user_rid", ps, depth, &r_u->user_rid))
+       if(!smb_io_time("pass_last_set_time   ", &usr->pass_last_set_time, ps,depth))
                return False;
-
-       if(!prs_uint32("status", ps, depth, &r_u->status))
+       if(!smb_io_time("kickoff_time         ", &usr->kickoff_time, ps, depth))
                return False;
-
-       return True;
-}
-
-/*******************************************************************
- Inits a SAMR_Q_CONNECT structure.
-********************************************************************/
-
-void init_samr_q_connect(SAMR_Q_CONNECT *q_u, char *srv_name, 
-                        uint32 access_mask)
-{
-       int len_srv_name = strlen(srv_name);
-
-       DEBUG(5,("init_q_connect\n"));
-
-       /* make PDC server name \\server */
-       q_u->ptr_srv_name = len_srv_name > 0; 
-       init_unistr2(&q_u->uni_srv_name, srv_name, len_srv_name + 1);  
-
-       q_u->access_mask = access_mask;
-}
-
-/*******************************************************************
- Reads or writes a structure.
-********************************************************************/
-
-BOOL samr_io_q_connect(char *desc,  SAMR_Q_CONNECT *q_u, prs_struct *ps, int depth)
-{
-       if (q_u == NULL)
+       if(!smb_io_time("pass_can_change_time ", &usr->pass_can_change_time, ps,depth))
                return False;
-
-       prs_debug(ps, depth, desc, "samr_io_q_connect");
-       depth++;
-
-       if(!prs_align(ps))
+       if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time,  ps, depth))
                return False;
 
-       if(!prs_uint32("ptr_srv_name", ps, depth, &q_u->ptr_srv_name))
+       if(!smb_io_unihdr("hdr_user_name   ", &usr->hdr_user_name, ps, depth))  /* username unicode string header */
                return False;
-       if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->ptr_srv_name, ps, depth))
+       if(!smb_io_unihdr("hdr_full_name   ", &usr->hdr_full_name, ps, depth))  /* user's full name unicode string header */
                return False;
-
-       if(!prs_align(ps))
+       if(!smb_io_unihdr("hdr_home_dir    ", &usr->hdr_home_dir, ps, depth))   /* home directory unicode string header */
                return False;
-
-       if(!prs_uint32("access_mask ", ps, depth, &q_u->access_mask))
+       if(!smb_io_unihdr("hdr_dir_drive   ", &usr->hdr_dir_drive, ps, depth))  /* home directory drive */
                return False;
-
-       return True;
-}
-
-/*******************************************************************
- Reads or writes a structure.
-********************************************************************/
-
-BOOL samr_io_r_connect(char *desc,  SAMR_R_CONNECT *r_u, prs_struct *ps, int depth)
-{
-       if (r_u == NULL)
+       if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth))       /* logon script unicode string header */
                return False;
-
-       prs_debug(ps, depth, desc, "samr_io_r_connect");
-       depth++;
-
-       if(!prs_align(ps))
+       if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth))       /* profile path unicode string header */
                return False;
-
-       if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth))
+       if(!smb_io_unihdr("hdr_acct_desc   ", &usr->hdr_acct_desc, ps, depth))  /* account desc */
                return False;
-       if(!prs_align(ps))
+       if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth))       /* wkstas user can log on from */
                return False;
-
-       if(!prs_uint32("status", ps, depth, &r_u->status))
+       if(!smb_io_unihdr("hdr_unknown_str ", &usr->hdr_unknown_str, ps, depth))        /* unknown string */
                return False;
-
-       return True;
-}
-
-/*******************************************************************
- Inits a SAMR_Q_CONNECT_ANON structure.
-********************************************************************/
-
-void init_samr_q_connect_anon(SAMR_Q_CONNECT_ANON *q_u)
-{
-       DEBUG(5,("init_q_connect_anon\n"));
-
-       q_u->ptr       = 1;
-       q_u->unknown_0 = 0x5c; /* server name (?!!) */
-       q_u->unknown_1 = 0x01;
-       q_u->unknown_2 = 0x20;
-}
-
-
-/*******************************************************************
- Reads or writes a structure.
-********************************************************************/
-
-BOOL samr_io_q_connect_anon(char *desc,  SAMR_Q_CONNECT_ANON *q_u, prs_struct *ps, int depth)
-{
-       if (q_u == NULL)
+       if(!smb_io_unihdr("hdr_munged_dial ", &usr->hdr_munged_dial, ps, depth))        /* wkstas user can log on from */
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_q_connect_anon");
-       depth++;
-
-       if(!prs_align(ps))
+       if(!prs_uint8s(False, "lm_pwd        ", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd)))
                return False;
-
-       if(!prs_uint32("ptr      ", ps, depth, &q_u->ptr))
+       if(!prs_uint8s(False, "nt_pwd        ", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd)))
                return False;
-       if(!prs_uint16("unknown_0", ps, depth, &q_u->unknown_0))
+
+       if(!prs_uint32("user_rid      ", ps, depth, &usr->user_rid))    /* User ID */
                return False;
-       if(!prs_uint16("unknown_1", ps, depth, &q_u->unknown_1))
+       if(!prs_uint32("group_rid     ", ps, depth, &usr->group_rid))   /* Group ID */
                return False;
-       if(!prs_uint32("unknown_2", ps, depth, &q_u->unknown_2))
+       if(!prs_uint32("acb_info      ", ps, depth, &usr->acb_info))
                return False;
 
-       return True;
-}
-
-/*******************************************************************
- Reads or writes a structure.
-********************************************************************/
-
-BOOL samr_io_r_connect_anon(char *desc,  SAMR_R_CONNECT_ANON *r_u, prs_struct *ps, int depth)
-{
-       if (r_u == NULL)
+       if(!prs_uint32("unknown_3     ", ps, depth, &usr->unknown_3))
+               return False;
+       if(!prs_uint16("logon_divs    ", ps, depth, &usr->logon_divs))  /* logon divisions per week */
                return False;
-
-       prs_debug(ps, depth, desc, "samr_io_r_connect_anon");
-       depth++;
-
        if(!prs_align(ps))
                return False;
-
-       if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth))
+       if(!prs_uint32("ptr_logon_hrs ", ps, depth, &usr->ptr_logon_hrs))
                return False;
-       if(!prs_align(ps))
+       if(!prs_uint32("unknown_5     ", ps, depth, &usr->unknown_5))
                return False;
 
-       if(!prs_uint32("status", ps, depth, &r_u->status))
+       if(!prs_uint8s(False, "padding1      ", ps, depth, usr->padding1, sizeof(usr->padding1)))
                return False;
 
-       return True;
-}
-
-/*******************************************************************
- Inits a SAMR_Q_OPEN_ALIAS structure.
-********************************************************************/
-void init_samr_q_open_alias(SAMR_Q_OPEN_ALIAS *q_u,
-                               uint32 unknown_0, uint32 rid)
-{
-       DEBUG(5,("init_q_open_alias\n"));
-
-       /* example values: 0x0000 0008 */
-       q_u->unknown_0 = unknown_0; 
-
-       q_u->rid_alias = rid; 
-}
-
-/*******************************************************************
- Reads or writes a structure.
-********************************************************************/
+       /* here begins pointed-to data */
 
-BOOL samr_io_q_open_alias(char *desc, SAMR_Q_OPEN_ALIAS *q_u, prs_struct *ps, int depth)
-{
-       if (q_u == NULL)
+       if(!smb_io_unistr2("uni_user_name   ", &usr->uni_user_name,usr->hdr_user_name.buffer, ps, depth))       /* username unicode string */
                return False;
-
-       prs_debug(ps, depth, desc, "samr_io_q_open_alias");
-       depth++;
-
-       if(!prs_align(ps))
+       if(!smb_io_unistr2("uni_full_name   ", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth))      /* user's full name unicode string */
                return False;
-
-       if(!smb_io_pol_hnd("domain_pol", &(q_u->dom_pol), ps, depth))
+       if(!smb_io_unistr2("uni_home_dir    ", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth))        /* home directory unicode string */
                return False;
-
-       if(!prs_uint32("unknown_0", ps, depth, &q_u->unknown_0))
+       if(!smb_io_unistr2("uni_dir_drive   ", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth))      /* home directory drive unicode string */
                return False;
-       if(!prs_uint32("rid_alias", ps, depth, &q_u->rid_alias))
+       if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth))        /* logon script unicode string */
                return False;
-
-       return True;
-}
-
-/*******************************************************************
- Reads or writes a structure.
-********************************************************************/
-
-BOOL samr_io_r_open_alias(char *desc,  SAMR_R_OPEN_ALIAS *r_u, prs_struct *ps, int depth)
-{
-       if (r_u == NULL)
+       if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth))        /* profile path unicode string */
                return False;
-
-       prs_debug(ps, depth, desc, "samr_io_r_open_alias");
-       depth++;
-
-       if(!prs_align(ps))
+       if(!smb_io_unistr2("uni_acct_desc   ", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth))      /* user desc unicode string */
                return False;
-
-       if(!smb_io_pol_hnd("pol", &r_u->pol, ps, depth))
+       if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth))        /* worksations user can log on from */
                return False;
-       if(!prs_align(ps))
+       if(!smb_io_unistr2("uni_unknown_str ", &usr->uni_unknown_str, usr->hdr_unknown_str.buffer, ps, depth))  /* unknown string */
                return False;
-
-       if(!prs_uint32("status", ps, depth, &r_u->status))
+       if(!smb_io_unistr2("uni_munged_dial ", &usr->uni_munged_dial,usr->hdr_munged_dial.buffer, ps, depth))   /* worksations user can log on from */
                return False;
 
+       /* ok, this is only guess-work (as usual) */
+       if (usr->ptr_logon_hrs) {
+               if(!prs_align(ps))
+                       return False;
+               if(!prs_uint32("unknown_6     ", ps, depth, &usr->unknown_6))
+                       return False;
+               if(!prs_uint32("padding4      ", ps, depth, &usr->padding4))
+                       return False;
+               if(!sam_io_logon_hrs("logon_hrs", &usr->logon_hrs, ps, depth))
+                       return False;
+       } else if (UNMARSHALLING(ps)) {
+               usr->unknown_6 = 0;
+               usr->padding4 = 0;
+       }
+
        return True;
 }
 
 /*******************************************************************
- Inits a SAMR_Q_UNKNOWN_12 structure.
+inits a SAM_USERINFO_CTR structure.
 ********************************************************************/
 
-void init_samr_q_lookup_rids(SAMR_Q_LOOKUP_RIDS *q_u,
-               POLICY_HND *pol, uint32 rid,
-               uint32 num_gids, uint32 *gid)
+uint32 make_samr_userinfo_ctr_usr21(TALLOC_CTX *ctx, SAM_USERINFO_CTR * ctr,
+                                   uint16 switch_value,
+                                   SAM_USER_INFO_21 * usr)
 {
-       int i;
+       DEBUG(5, ("init_samr_userinfo_ctr\n"));
+
+       ctr->switch_value = switch_value;
+       ctr->info.id = NULL;
 
-       DEBUG(5,("init_samr_q_lookup_rids\n"));
+       switch (switch_value) {
+       case 0x10:
+               ctr->info.id10 = (SAM_USER_INFO_10 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_10));
+               if (ctr->info.id10 == NULL)
+                       return NT_STATUS_NO_MEMORY;
 
-       memcpy(&q_u->pol, pol, sizeof(*pol));
+               init_sam_user_info10(ctr->info.id10, usr->acb_info);
+               break;
+#if 0
+/* whoops - got this wrong.  i think.  or don't understand what's happening. */
+       case 0x11:
+               {
+                       NTTIME expire;
+                       info = (void *)&id11;
+
+                       expire.low = 0xffffffff;
+                       expire.high = 0x7fffffff;
+
+                       ctr->info.id = (SAM_USER_INFO_11 *) talloc_zero(ctx,sizeof(*ctr->info.id11));
+                       init_sam_user_info11(ctr->info.id11, &expire,
+                                            "BROOKFIELDS$",    /* name */
+                                            0x03ef,    /* user rid */
+                                            0x201,     /* group rid */
+                                            0x0080);   /* acb info */
 
-       q_u->num_gids1 = num_gids;
-       q_u->rid       = rid;
-       q_u->ptr       = 0;
-       q_u->num_gids2 = num_gids;
+                       break;
+               }
+#endif
+       case 0x12:
+               ctr->info.id12 = (SAM_USER_INFO_12 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_12));
+               if (ctr->info.id12 == NULL)
+                       return NT_STATUS_NO_MEMORY;
 
-       for (i = 0; i < num_gids; i++) {
-               q_u->gid[i] = gid[i];
+               init_sam_user_info12(ctr->info.id12, usr->lm_pwd, usr->nt_pwd);
+               break;
+       case 21:
+               {
+                       SAM_USER_INFO_21 *cusr;
+                       cusr = (SAM_USER_INFO_21 *)talloc_zero(ctx,sizeof(SAM_USER_INFO_21));
+                       ctr->info.id21 = cusr;
+                       if (ctr->info.id21 == NULL)
+                               return NT_STATUS_NO_MEMORY;
+                       memcpy(cusr, usr, sizeof(*usr));
+                       memset(cusr->lm_pwd, 0, sizeof(cusr->lm_pwd));
+                       memset(cusr->nt_pwd, 0, sizeof(cusr->nt_pwd));
+                       break;
+               }
+       default:
+               DEBUG(4,("make_samr_userinfo_ctr: unsupported info\n"));
+               return NT_STATUS_INVALID_INFO_CLASS;
        }
+
+       return NT_STATUS_NOPROBLEMO;
 }
 
 /*******************************************************************
- Inits a SAMR_Q_UNKNOWN_21 structure.
+inits a SAM_USERINFO_CTR structure.
 ********************************************************************/
 
-void init_samr_q_unknown_21(SAMR_Q_UNKNOWN_21 *q_c,
-                               POLICY_HND *hnd, uint16 unk_1, uint16 unk_2)
+void init_samr_userinfo_ctr(SAM_USERINFO_CTR * ctr, uchar * sess_key,
+                           uint16 switch_value, void *info)
 {
-       DEBUG(5,("init_samr_q_unknown_21\n"));
+       DEBUG(5, ("init_samr_userinfo_ctr\n"));
 
-       memcpy(&q_c->group_pol, hnd, sizeof(q_c->group_pol));
-       q_c->unknown_1 = unk_1;
-       q_c->unknown_2 = unk_2;
-}
+       ctr->switch_value = switch_value;
+       ctr->info.id = info;
 
+       switch (switch_value) {
+       case 0x18:
+               SamOEMhash(ctr->info.id24->pass, sess_key, 1);
+               dump_data(100, (char *)sess_key, 16);
+               dump_data(100, (char *)ctr->info.id24->pass, 516);
+               break;
+       case 0x17:
+               SamOEMhash(ctr->info.id23->pass, sess_key, 1);
+               dump_data(100, (char *)sess_key, 16);
+               dump_data(100, (char *)ctr->info.id23->pass, 516);
+               break;
+       default:
+               DEBUG(4,("init_samr_userinfo_ctr: unsupported switch level\n"));
+       }
+}
 
 /*******************************************************************
- Inits a SAMR_Q_UNKNOWN_13 structure.
+reads or writes a structure.
 ********************************************************************/
 
-void init_samr_q_unknown_13(SAMR_Q_UNKNOWN_13 *q_c,
-                               POLICY_HND *hnd, uint16 unk_1, uint16 unk_2)
+static BOOL samr_io_userinfo_ctr(char *desc, SAM_USERINFO_CTR **ppctr,
+                                prs_struct *ps, int depth)
 {
-       DEBUG(5,("init_samr_q_unknown_13\n"));
-
-       memcpy(&q_c->alias_pol, hnd, sizeof(q_c->alias_pol));
-       q_c->unknown_1 = unk_1;
-       q_c->unknown_2 = unk_2;
-}
+       BOOL ret;
+       SAM_USERINFO_CTR *ctr;
 
-/*******************************************************************
- Inits a SAMR_Q_UNKNOWN_38 structure.
-********************************************************************/
-void init_samr_q_unknown_38(SAMR_Q_UNKNOWN_38 *q_u, char *srv_name)
-{
-       int len_srv_name = strlen(srv_name)+1;
+       prs_debug(ps, depth, desc, "samr_io_userinfo_ctr");
+       depth++;
 
-       DEBUG(5,("init_q_unknown_38\n"));
+       if (UNMARSHALLING(ps)) {
+               ctr = (SAM_USERINFO_CTR *)prs_alloc_mem(ps,sizeof(SAM_USERINFO_CTR));
+               if (ctr == NULL)
+                       return False;
+               *ppctr = ctr;
+       } else {
+               ctr = *ppctr;
+       }
 
-       q_u->ptr = 1;
-       init_uni_hdr(&q_u->hdr_srv_name, len_srv_name);
-       init_unistr2(&q_u->uni_srv_name, srv_name, len_srv_name);  
+       /* lkclXXXX DO NOT ALIGN BEFORE READING SWITCH VALUE! */
 
-}
+       if(!prs_uint16("switch_value", ps, depth, &ctr->switch_value))
+               return False;
+       if(!prs_align(ps))
+               return False;
 
-/*******************************************************************
- Reads or writes a structure.
-********************************************************************/
+       ret = False;
 
-BOOL samr_io_q_unknown_38(char *desc,  SAMR_Q_UNKNOWN_38 *q_u, prs_struct *ps, int depth)
-{
-       if (q_u == NULL)
-               return False;
+       switch (ctr->switch_value) {
+       case 0x10:
+               if (UNMARSHALLING(ps))
+                       ctr->info.id10 = (SAM_USER_INFO_10 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_10));
+               if (ctr->info.id10 == NULL) {
+                       DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
+                       return False;
+               }
+               ret = sam_io_user_info10("", ctr->info.id10, ps, depth);
+               break;
+       case 0x11:
+               if (UNMARSHALLING(ps))
+                       ctr->info.id11 = (SAM_USER_INFO_11 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_11));
 
-       prs_debug(ps, depth, desc, "samr_io_q_unknown_38");
-       depth++;
+               if (ctr->info.id11 == NULL) {
+                       DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
+                       return False;
+               }
+               ret = sam_io_user_info11("", ctr->info.id11, ps, depth);
+               break;
+       case 0x12:
+               if (UNMARSHALLING(ps))
+                       ctr->info.id12 = (SAM_USER_INFO_12 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_12));
 
-       if(!prs_align(ps))
-               return False;
+               if (ctr->info.id12 == NULL) {
+                       DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
+                       return False;
+               }
+               ret = sam_io_user_info12("", ctr->info.id12, ps, depth);
+               break;
+       case 21:
+               if (UNMARSHALLING(ps))
+                       ctr->info.id21 = (SAM_USER_INFO_21 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_21));
 
-       if(!prs_uint32("ptr", ps, depth, &q_u->ptr))
-               return False;
+               if (ctr->info.id21 == NULL) {
+                       DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
+                       return False;
+               }
+               ret = sam_io_user_info21("", ctr->info.id21, ps, depth);
+               break;
+       case 23:
+               if (UNMARSHALLING(ps))
+                       ctr->info.id23 = (SAM_USER_INFO_23 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_23));
 
-       if (q_u->ptr != 0) {
-               if(!smb_io_unihdr ("", &q_u->hdr_srv_name, ps, depth))
+               if (ctr->info.id23 == NULL) {
+                       DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
                        return False;
-               if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->hdr_srv_name.buffer, ps, depth))
+               }
+               ret = sam_io_user_info23("", ctr->info.id23, ps, depth);
+               break;
+       case 24:
+               if (UNMARSHALLING(ps))
+                       ctr->info.id24 = (SAM_USER_INFO_24 *)prs_alloc_mem(ps,sizeof(SAM_USER_INFO_24));
+
+               if (ctr->info.id24 == NULL) {
+                       DEBUG(2,("samr_io_userinfo_ctr: info pointer not initialised\n"));
                        return False;
+               }
+               ret = sam_io_user_info24("", ctr->info.id24, ps,  depth);
+               break;
+       default:
+               DEBUG(2, ("samr_io_userinfo_ctr: unknown switch level 0x%x\n", ctr->switch_value));
+               ret = False;
+               break;
        }
 
-       return True;
+       return ret;
 }
 
 /*******************************************************************
- Inits a SAMR_R_UNKNOWN_38 structure.
+inits a SAMR_R_QUERY_USERINFO structure.
 ********************************************************************/
 
-void init_samr_r_unknown_38(SAMR_R_UNKNOWN_38 *r_u)
+void init_samr_r_query_userinfo(SAMR_R_QUERY_USERINFO * r_u,
+                               SAM_USERINFO_CTR * ctr, uint32 status)
 {
-       DEBUG(5,("init_r_unknown_38\n"));
+       DEBUG(5, ("init_samr_r_query_userinfo\n"));
+
+       r_u->ptr = 0;
+       r_u->ctr = NULL;
+
+       if (status == 0) {
+               r_u->ptr = 1;
+               r_u->ctr = ctr;
+       }
 
-       r_u->unk_0 = 0;
-       r_u->unk_1 = 0;
-       r_u->unk_2 = 0;
-       r_u->unk_3 = 0;
+       r_u->status = status;   /* return status */
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_r_unknown_38(char *desc,  SAMR_R_UNKNOWN_38 *r_u, prs_struct *ps, int depth)
+BOOL samr_io_r_query_userinfo(char *desc, SAMR_R_QUERY_USERINFO * r_u,
+                             prs_struct *ps, int depth)
 {
        if (r_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_r_unknown_38");
+       prs_debug(ps, depth, desc, "samr_io_r_query_userinfo");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint16("unk_0", ps, depth, &r_u->unk_0))
-               return False;
-       if(!prs_align(ps))
-               return False;
-       if(!prs_uint16("unk_1", ps, depth, &r_u->unk_1))
-               return False;
-       if(!prs_align(ps))
-               return False;
-       if(!prs_uint16("unk_2", ps, depth, &r_u->unk_2))
+       if(!prs_uint32("ptr", ps, depth, &r_u->ptr))
                return False;
+
+       if (r_u->ptr != 0) {
+               if(!samr_io_userinfo_ctr("ctr", &r_u->ctr, ps, depth))
+                       return False;
+       }
+
        if(!prs_align(ps))
                return False;
-       if(!prs_uint16("unk_3", ps, depth, &r_u->unk_3))
-               return False;
-       if(!prs_align(ps))
+       if(!prs_uint32("status", ps, depth, &r_u->status))
                return False;
 
        return True;
 }
 
 /*******************************************************************
-make a SAMR_ENC_PASSWD structure.
+inits a SAMR_Q_SET_USERINFO structure.
 ********************************************************************/
 
-void init_enc_passwd(SAMR_ENC_PASSWD *pwd, char pass[512])
+void init_samr_q_set_userinfo(SAMR_Q_SET_USERINFO * q_u,
+                             POLICY_HND *hnd,  unsigned char sess_key[16],
+                             uint16 switch_value, void *info)
 {
-       pwd->ptr = 1;
-       memcpy(pwd->pass, pass, sizeof(pwd->pass)); 
+       DEBUG(5, ("init_samr_q_set_userinfo\n"));
+
+       q_u->pol = *hnd;
+       q_u->switch_value = switch_value;
+       init_samr_userinfo_ctr(q_u->ctr, sess_key, switch_value, info);
 }
 
 /*******************************************************************
- Reads or writes a SAMR_ENC_PASSWD structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_enc_passwd(char *desc, SAMR_ENC_PASSWD *pwd, prs_struct *ps, int depth)
+BOOL samr_io_q_set_userinfo(char *desc, SAMR_Q_SET_USERINFO * q_u,
+                           prs_struct *ps, int depth)
 {
-       if (pwd == NULL)
+       if (q_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_enc_passwd");
+       prs_debug(ps, depth, desc, "samr_io_q_set_userinfo");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("ptr", ps, depth, &pwd->ptr))
+       smb_io_pol_hnd("pol", &(q_u->pol), ps, depth);
+
+       if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
                return False;
-       if(!prs_uint8s(False, "pwd", ps, depth, pwd->pass, sizeof(pwd->pass)))
+       if(!samr_io_userinfo_ctr("ctr", &q_u->ctr, ps, depth))
                return False;
 
        return True;
 }
 
 /*******************************************************************
- Inits a SAMR_ENC_HASH structure.
+inits a SAMR_R_SET_USERINFO structure.
 ********************************************************************/
 
-void init_enc_hash(SAMR_ENC_HASH *hsh, uchar hash[16])
+void init_samr_r_set_userinfo(SAMR_R_SET_USERINFO * r_u, uint32 status)
 {
-       hsh->ptr = 1;
-       memcpy(hsh->hash, hash, sizeof(hsh->hash));
+       DEBUG(5, ("init_samr_r_set_userinfo\n"));
+
+       r_u->status = status;   /* return status */
 }
 
 /*******************************************************************
- Reads or writes a SAMR_ENC_HASH structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_enc_hash(char *desc, SAMR_ENC_HASH *hsh, prs_struct *ps, int depth)
+BOOL samr_io_r_set_userinfo(char *desc, SAMR_R_SET_USERINFO * r_u,
+                           prs_struct *ps, int depth)
 {
-       if (hsh == NULL)
+       if (r_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_enc_hash");
+       prs_debug(ps, depth, desc, "samr_io_r_set_userinfo");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("ptr ", ps, depth, &hsh->ptr))
-               return False;
-       if(!prs_uint8s(False, "hash", ps, depth, hsh->hash, sizeof(hsh->hash))) 
+       if(!prs_uint32("status", ps, depth, &r_u->status))
                return False;
 
        return True;
 }
 
 /*******************************************************************
- Inits a SAMR_R_UNKNOWN_38 structure.
+inits a SAMR_Q_SET_USERINFO2 structure.
 ********************************************************************/
 
-void init_samr_q_chgpasswd_user(SAMR_Q_CHGPASSWD_USER *q_u,
-                               char *dest_host, char *user_name,
-                               char nt_newpass[516], uchar nt_oldhash[16],
-                               char lm_newpass[516], uchar lm_oldhash[16])
+void init_samr_q_set_userinfo2(SAMR_Q_SET_USERINFO2 * q_u,
+                              POLICY_HND *hnd, unsigned char sess_key[16],
+                              uint16 switch_value, SAM_USERINFO_CTR * ctr)
 {
-       int len_dest_host = strlen(dest_host)+1;
-       int len_user_name = strlen(user_name)+1;
-
-       DEBUG(5,("init_samr_q_chgpasswd_user\n"));
-
-       q_u->ptr_0 = 1;
-       init_uni_hdr(&q_u->hdr_dest_host, len_dest_host);
-       init_unistr2(&q_u->uni_dest_host, dest_host, len_dest_host);  
-       init_uni_hdr(&q_u->hdr_user_name, len_user_name);
-       init_unistr2(&q_u->uni_user_name, user_name, len_user_name);  
-
-       init_enc_passwd(&q_u->nt_newpass, nt_newpass);
-       init_enc_hash(&q_u->nt_oldhash, nt_oldhash);
-
-       q_u->unknown = 0x01;
+       DEBUG(5, ("init_samr_q_set_userinfo2\n"));
 
-       init_enc_passwd(&q_u->lm_newpass, lm_newpass);
-       init_enc_hash  (&q_u->lm_oldhash, lm_oldhash);
+       q_u->pol = *hnd;
+       q_u->switch_value = switch_value;
+       q_u->ctr = ctr;
+
+       if (q_u->ctr != NULL)
+               q_u->ctr->switch_value = switch_value;
+
+       switch (switch_value) {
+       case 0x12:
+               SamOEMhash(ctr->info.id12->lm_pwd, sess_key, 0);
+               SamOEMhash(ctr->info.id12->nt_pwd, sess_key, 0);
+               dump_data(100, (char *)sess_key, 16);
+               dump_data(100, (char *)ctr->info.id12->lm_pwd, 16);
+               dump_data(100, (char *)ctr->info.id12->nt_pwd, 16);
+               break;
+       }
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_q_chgpasswd_user(char *desc, SAMR_Q_CHGPASSWD_USER *q_u, prs_struct *ps, int depth)
+BOOL samr_io_q_set_userinfo2(char *desc, SAMR_Q_SET_USERINFO2 * q_u,
+                            prs_struct *ps, int depth)
 {
        if (q_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_q_chgpasswd_user");
+       prs_debug(ps, depth, desc, "samr_io_q_set_userinfo2");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("ptr_0", ps, depth, &q_u->ptr_0))
-               return False;
-
-       if(!smb_io_unihdr ("", &q_u->hdr_dest_host, ps, depth))
-               return False;
-       if(!smb_io_unistr2("", &q_u->uni_dest_host, q_u->hdr_dest_host.buffer, ps, depth))
-               return False;
-       if(!smb_io_unihdr ("", &q_u->hdr_user_name, ps, depth))
-               return False;
-       if(!smb_io_unistr2("", &q_u->uni_user_name, q_u->hdr_user_name.buffer, ps, depth))
-               return False;
-
-       if(!samr_io_enc_passwd("nt_newpass", &q_u->nt_newpass, ps, depth))
-               return False;
-       if(!samr_io_enc_hash  ("nt_oldhash", &q_u->nt_oldhash, ps, depth))
-               return False;
-
-       if(!prs_uint32("unknown", ps, depth, &q_u->unknown))
+       if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
                return False;
 
-       if(!samr_io_enc_passwd("lm_newpass", &q_u->lm_newpass, ps, depth))
+       if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
                return False;
-       if(!samr_io_enc_hash("lm_oldhash", &q_u->lm_oldhash, ps, depth))
+       if(!samr_io_userinfo_ctr("ctr", &q_u->ctr, ps, depth))
                return False;
 
        return True;
 }
 
 /*******************************************************************
- Inits a SAMR_R_CHGPASSWD_USER structure.
+inits a SAMR_R_SET_USERINFO2 structure.
 ********************************************************************/
 
-void init_samr_r_chgpasswd_user(SAMR_R_CHGPASSWD_USER *r_u, uint32 status)
+void init_samr_r_set_userinfo2(SAMR_R_SET_USERINFO2 * r_u, uint32 status)
 {
-       DEBUG(5,("init_r_chgpasswd_user\n"));
+       DEBUG(5, ("init_samr_r_set_userinfo2\n"));
 
-       r_u->status = status;
+       r_u->status = status;   /* return status */
 }
 
 /*******************************************************************
- Reads or writes a structure.
+reads or writes a structure.
 ********************************************************************/
 
-BOOL samr_io_r_chgpasswd_user(char *desc, SAMR_R_CHGPASSWD_USER *r_u, prs_struct *ps, int depth)
+BOOL samr_io_r_set_userinfo2(char *desc, SAMR_R_SET_USERINFO2 * r_u,
+                            prs_struct *ps, int depth)
 {
        if (r_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_r_chgpasswd_user");
+       prs_debug(ps, depth, desc, "samr_io_r_set_userinfo2");
        depth++;
 
        if(!prs_align(ps))
@@ -3882,234 +6056,73 @@ BOOL samr_io_r_chgpasswd_user(char *desc, SAMR_R_CHGPASSWD_USER *r_u, prs_struct
        return True;
 }
 
-/**********************************************************************
- Reads or writes a structure
- **********************************************************************/
-BOOL samr_io_q_lookup_domain(char* desc, SAMR_Q_LOOKUP_DOMAIN* q_u, prs_struct *ps, int depth)
-{
-       if (q_u == NULL)
-               return False;
-
-       prs_debug(ps, depth, desc, "samr_io_q_lookup_domain");
-       depth++;
-
-       if(!prs_align(ps))
-               return False;
-
-       if(!smb_io_pol_hnd("connect_pol", &q_u->connect_pol, ps, depth))
-               return False;
-
-       if(!smb_io_unihdr("hdr_domain", &q_u->hdr_domain, ps, depth))
-               return False;
-
-       if(!smb_io_unistr2("uni_domain", &q_u->uni_domain, q_u->hdr_domain.buffer, ps, depth))
-               return False;
-
-       return True;
-} 
-
 /*******************************************************************
-makes a SAMR_R_LOOKUP_DOMAIN structure.
+inits a SAMR_Q_CONNECT structure.
 ********************************************************************/
-BOOL init_samr_r_lookup_domain(SAMR_R_LOOKUP_DOMAIN * r_u,
-                               DOM_SID *dom_sid, uint32 status)
+
+void init_samr_q_connect(SAMR_Q_CONNECT * q_u,
+                        char *srv_name, uint32 access_mask)
 {
-       if (r_u == NULL)
-               return False;
+       int len_srv_name = strlen(srv_name);
 
-       DEBUG(5, ("make_samr_r_lookup_domain\n"));
+       DEBUG(5, ("init_samr_q_connect\n"));
 
-       r_u->status = status;
-       r_u->ptr_sid = 0;
-       if (status == 0x0) {
-               r_u->ptr_sid = 1;
-               init_dom_sid2(&r_u->dom_sid, dom_sid);
-       }
+       /* make PDC server name \\server */
+       q_u->ptr_srv_name = len_srv_name > 0 ? 1 : 0;
+       init_unistr2(&q_u->uni_srv_name, srv_name, len_srv_name + 1);
 
-       return True;
+       /* example values: 0x0000 0002 */
+       q_u->access_mask = access_mask;
 }
 
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-BOOL samr_io_r_lookup_domain(char *desc, SAMR_R_LOOKUP_DOMAIN * r_u,
-                             prs_struct *ps, int depth)
-{
-       if (r_u == NULL)
-               return False;
-
-       prs_debug(ps, depth, desc, "samr_io_r_lookup_domain");
-       depth++;
-
-       if(!prs_align(ps))
-               return False;
-
-       if(!prs_uint32("ptr", ps, depth, &r_u->ptr_sid))
-               return False;
-
-       if (r_u->ptr_sid != 0) {
-                       if(!smb_io_dom_sid2("sid", &r_u->dom_sid, ps, depth))
-                               return False;
-                       if(!prs_align(ps))
-                               return False;
-       }
 
-       if(!prs_uint32("status", ps, depth, &r_u->status))
-               return False;
-
-       return True;
-}  
-
-/*******************************************************************
-reads or writes a structure.
-********************************************************************/
-BOOL samr_io_q_enum_domains(char *desc, SAMR_Q_ENUM_DOMAINS * q_e,
-                            prs_struct *ps, int depth)
+BOOL samr_io_q_connect(char *desc, SAMR_Q_CONNECT * q_u,
+                      prs_struct *ps, int depth)
 {
-       if (q_e == NULL)
+       if (q_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_q_enum_domains");
+       prs_debug(ps, depth, desc, "samr_io_q_connect");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_pol_hnd("pol", &q_e->pol, ps, depth))
-               return False;
-
-       if(!prs_uint32("start_idx", ps, depth, &q_e->start_idx))
+       if(!prs_uint32("ptr_srv_name", ps, depth, &q_u->ptr_srv_name))
                return False;
-       if(!prs_uint32("max_size ", ps, depth, &q_e->max_size))
+       if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->ptr_srv_name, ps, depth))
                return False;
 
        if(!prs_align(ps))
                return False;
+       if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
+               return False;
 
        return True;
-} 
-
-/*******************************************************************
-makes a SAMR_R_ENUM_DOMAINS structure.
-********************************************************************/
-BOOL init_samr_r_enum_domains(SAMR_R_ENUM_DOMAINS * r_u,
-                              uint32 next_idx, fstring* domains, uint32 num_sam_entries)
-{
-  int i=0;
-
-  if (r_u == NULL)
-    return False;
-
-  DEBUG(5, ("init_samr_r_enum_domains\n"));
-
-  r_u->next_idx = next_idx;
-
-  r_u->uni_dom_name = (UNISTR2*) malloc(sizeof(UNISTR2) * num_sam_entries);
-  r_u->sam = (SAM_ENTRY*) malloc(sizeof(SAM_ENTRY) * num_sam_entries);
-  if(r_u->uni_dom_name == NULL || r_u->sam == NULL)
-    {
-      free(r_u->uni_dom_name);
-      free(r_u->sam);
-      r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
-    }
-
-  if(r_u->status == 0)
-    for(i=0;i<num_sam_entries;i++) /* only two domains to send */
-      {
-       init_unistr2(&r_u->uni_dom_name[i],domains[i], strlen(domains[i])+1);
-       init_sam_entry(&(r_u->sam[i]), strlen(domains[i])+1, 0);
-      }
-  else
-    {
-      num_sam_entries = 0;
-    }
-  
-  if (num_sam_entries != 0)
-    {
-      r_u->ptr_entries1 = 1;
-      r_u->ptr_entries2 = 1;
-      r_u->num_entries2 = num_sam_entries;
-      r_u->num_entries3 = num_sam_entries;
-
-      r_u->num_entries4 = num_sam_entries;
-    }
-  else
-    {
-      r_u->ptr_entries1 = 0;
-      r_u->num_entries2 = num_sam_entries;
-      r_u->ptr_entries2 = 1;
-    }
-  
-  return True;
 }
 
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-BOOL samr_io_r_enum_domains(char *desc, SAMR_R_ENUM_DOMAINS * r_u,
-                            prs_struct *ps, int depth)
-{
-       uint32 i;
 
+BOOL samr_io_r_connect(char *desc, SAMR_R_CONNECT * r_u,
+                      prs_struct *ps, int depth)
+{
        if (r_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_r_enum_domains");
+       prs_debug(ps, depth, desc, "samr_io_r_connect");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("next_idx    ", ps, depth, &r_u->next_idx))
-               return False;
-       if(!prs_uint32("ptr_entries1", ps, depth, &r_u->ptr_entries1))
+       if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth))
                return False;
 
-       if (r_u->ptr_entries1 != 0) {
-
-               if(!prs_uint32("num_entries2", ps, depth, &r_u->num_entries2))
-                       return False;
-
-               if(!prs_uint32("ptr_entries2", ps, depth, &r_u->ptr_entries2))
-                       return False;
-               if(!prs_uint32("num_entries3", ps, depth, &r_u->num_entries3))
-                       return False;
-
-               if (UNMARSHALLING(ps)) {
-                       r_u->sam = (SAM_ENTRY*) malloc(sizeof(SAM_ENTRY)* r_u->num_entries2);
-                       r_u->uni_dom_name = (UNISTR2*) malloc(sizeof(UNISTR2)* r_u->num_entries2);
-               }
-
-               if ((r_u->sam == NULL || r_u->uni_dom_name == NULL) && r_u->num_entries2 != 0) {
-                       DEBUG(0, ("NULL pointers in SAMR_R_ENUM_DOMAINS\n"));
-                       r_u->num_entries4 = 0;
-                       r_u->status = NT_STATUS_MEMORY_NOT_ALLOCATED;
-                       return False;
-               }
-
-               for (i = 0; i < r_u->num_entries2; i++) {
-                       fstring tmp;
-                       slprintf(tmp, sizeof(tmp) - 1, "domains[%d]", i);
-                       if (!sam_io_sam_entry(tmp, &r_u->sam[i], ps, depth))
-                               return False;
-               }
-
-               for (i = 0; i < r_u->num_entries2; i++) {
-                       fstring tmp;
-                       slprintf(tmp, sizeof(tmp) - 1, "domains[%d]", i);
-                       if(!smb_io_unistr2(tmp, &r_u->uni_dom_name[i], r_u->sam[i].hdr_name.buffer, ps, depth))
-                               return False;
-                       if(!prs_align(ps))
-                               return False;
-               }
-
-               if(!prs_align(ps))
-                       return False;
-
-       }
-
-       if(!prs_uint32("num_entries4", ps, depth, &r_u->num_entries4))
-               return False;
        if(!prs_uint32("status", ps, depth, &r_u->status))
                return False;
 
@@ -4117,29 +6130,42 @@ BOOL samr_io_r_enum_domains(char *desc, SAMR_R_ENUM_DOMAINS * r_u,
 }
 
 /*******************************************************************
-reads or writes a structure.
+inits a SAMR_Q_CONNECT_ANON structure.
 ********************************************************************/
-static BOOL sam_io_user_info12(char *desc, SAM_USER_INFO_12 *u, prs_struct *ps, int depth)
+
+void init_samr_q_connect_anon(SAMR_Q_CONNECT_ANON * q_u)
 {
-       if (u == NULL)
-               return False;
+       DEBUG(5, ("init_samr_q_connect_anon\n"));
 
-       DEBUG(0, ("possible security breach!\n"));
+       q_u->ptr = 1;
+       q_u->unknown_0 = 0x5c;  /* server name (?!!) */
+       q_u->unknown_1 = 0x01;
+       q_u->access_mask = 0x20;
+}
+
+/*******************************************************************
+reads or writes a structure.
+********************************************************************/
+
+BOOL samr_io_q_connect_anon(char *desc, SAMR_Q_CONNECT_ANON * q_u,
+                           prs_struct *ps, int depth)
+{
+       if (q_u == NULL)
+               return False;
 
-       prs_debug(ps, depth, desc, "samr_io_r_user_info12");
+       prs_debug(ps, depth, desc, "samr_io_q_connect_anon");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint8s(False, "lm_pwd", ps, depth, u->lm_pwd, sizeof(u->lm_pwd)))
+       if(!prs_uint32("ptr      ", ps, depth, &q_u->ptr))
                return False;
-       if(!prs_uint8s(False, "nt_pwd", ps, depth, u->nt_pwd, sizeof(u->nt_pwd)))
+       if(!prs_uint16("unknown_0", ps, depth, &q_u->unknown_0))
                return False;
-
-       if(!prs_uint8("lm_pwd_active", ps, depth, &u->lm_pwd_active))
+       if(!prs_uint16("unknown_1", ps, depth, &q_u->unknown_1))
                return False;
-       if(!prs_uint8("nt_pwd_active", ps, depth, &u->nt_pwd_active))
+       if(!prs_uint32("access_mask", ps, depth, &q_u->access_mask))
                return False;
 
        return True;
@@ -4148,156 +6174,68 @@ static BOOL sam_io_user_info12(char *desc, SAM_USER_INFO_12 *u, prs_struct *ps,
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-static BOOL sam_io_user_info23(char *desc, SAM_USER_INFO_23 *usr, prs_struct *ps, int depth)
+
+BOOL samr_io_r_connect_anon(char *desc, SAMR_R_CONNECT_ANON * r_u,
+                           prs_struct *ps, int depth)
 {
-       if (usr == NULL)
+       if (r_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "sam_io_user_info23");
+       prs_debug(ps, depth, desc, "samr_io_r_connect_anon");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_time("logon_time", &usr->logon_time, ps, depth))
-               return False;
-       if(!smb_io_time("logoff_time", &usr->logoff_time, ps, depth))
-               return False;
-       if(!smb_io_time("kickoff_time", &usr->kickoff_time, ps, depth))
-               return False;
-       if(!smb_io_time("pass_last_set_time", &usr->pass_last_set_time, ps, depth))
-               return False;
-       if(!smb_io_time("pass_can_change_time", &usr->pass_can_change_time, ps, depth))
-               return False;
-       if(!smb_io_time("pass_must_change_time", &usr->pass_must_change_time, ps, depth))
-               return False;
-
-       if(!smb_io_unihdr("hdr_user_name", &usr->hdr_user_name, ps, depth))     /* username unicode string header */
-               return False;
-       if(!smb_io_unihdr("hdr_full_name", &usr->hdr_full_name, ps, depth))     /* user's full name unicode string header */
-               return False;
-       if(!smb_io_unihdr("hdr_home_dir", &usr->hdr_home_dir, ps, depth))       /* home directory unicode string header */
-               return False;
-       if(!smb_io_unihdr("hdr_dir_drive", &usr->hdr_dir_drive, ps, depth))     /* home directory drive */
-               return False;
-       if(!smb_io_unihdr("hdr_logon_script", &usr->hdr_logon_script, ps, depth))       /* logon script unicode string header */
-               return False;
-       if(!smb_io_unihdr("hdr_profile_path", &usr->hdr_profile_path, ps, depth))       /* profile path unicode string header */
-               return False;
-       if(!smb_io_unihdr("hdr_acct_desc", &usr->hdr_acct_desc, ps, depth))     /* account desc */
-               return False;
-       if(!smb_io_unihdr("hdr_workstations", &usr->hdr_workstations, ps, depth))       /* wkstas user can log on from */
-               return False;
-       if(!smb_io_unihdr("hdr_unknown_str", &usr->hdr_unknown_str, ps, depth)) /* unknown string */
-               return False;
-       if(!smb_io_unihdr("hdr_munged_dial", &usr->hdr_munged_dial, ps, depth)) /* wkstas user can log on from */
-               return False;
-
-       if(!prs_uint8s(False, "lm_pwd", ps, depth, usr->lm_pwd, sizeof(usr->lm_pwd)))
-               return False;
-       if(!prs_uint8s(False, "nt_pwd", ps, depth, usr->nt_pwd, sizeof(usr->nt_pwd)))
-               return False;
-
-       if(!prs_uint32("user_rid", ps, depth, &usr->user_rid))  /* User ID */
-               return False;
-       if(!prs_uint32("group_rid", ps, depth, &usr->group_rid))        /* Group ID */
-               return False;
-       if(!prs_uint32("acb_info", ps, depth, &usr->acb_info))
+       if(!smb_io_pol_hnd("connect_pol", &r_u->connect_pol, ps, depth))
                return False;
 
-       if(!prs_uint32("unknown_3", ps, depth, &usr->unknown_3))
-               return False;
-       if(!prs_uint16("logon_divs", ps, depth, &usr->logon_divs))      /* logon divisions per week */
-               return False;
-       if(!prs_align(ps))
-               return False;
-       if(!prs_uint32("ptr_logon_hrs", ps, depth, &usr->ptr_logon_hrs))
-               return False;
-       if(!prs_uint8s(False, "padding1", ps, depth, usr->padding1, sizeof(usr->padding1)))
-               return False;
-       if(!prs_uint32("unknown_5", ps, depth, &usr->unknown_5))
+       if(!prs_uint32("status", ps, depth, &r_u->status))
                return False;
 
-       if(!prs_uint8s(False, "password", ps, depth, usr->pass, sizeof(usr->pass)))
-               return False;
+       return True;
+}
 
-       /* here begins pointed-to data */
+/*******************************************************************
+inits a SAMR_Q_GET_DOM_PWINFO structure.
+********************************************************************/
 
-       if(!prs_align_needed(ps, usr->hdr_user_name.buffer))
-               return False;
-       if(!smb_io_unistr2("uni_user_name", &usr->uni_user_name, usr->hdr_user_name.buffer, ps, depth)) /* username unicode string */
-               return False;
-       if(!prs_align_needed(ps, usr->hdr_full_name.buffer))
-               return False;
-       if(!smb_io_unistr2("uni_full_name", &usr->uni_full_name, usr->hdr_full_name.buffer, ps, depth)) /* user's full name unicode string */
-               return False;
-       if(!prs_align_needed(ps, usr->hdr_home_dir.buffer))
-               return False;
-       if(!smb_io_unistr2("uni_home_dir", &usr->uni_home_dir, usr->hdr_home_dir.buffer, ps, depth))    /* home directory unicode string */
-               return False;
-       if(!prs_align_needed(ps, usr->hdr_dir_drive.buffer))
-               return False;
-       if(!smb_io_unistr2("uni_dir_drive", &usr->uni_dir_drive, usr->hdr_dir_drive.buffer, ps, depth)) /* home directory drive unicode string */
-               return False;
-       if(!prs_align_needed(ps, usr->hdr_logon_script.buffer))
-               return False;
-       if(!smb_io_unistr2("uni_logon_script", &usr->uni_logon_script, usr->hdr_logon_script.buffer, ps, depth))        /* logon script unicode string */
-               return False;
-       if(!prs_align_needed(ps, usr->hdr_profile_path.buffer))
-               return False;
-       if(!smb_io_unistr2("uni_profile_path", &usr->uni_profile_path, usr->hdr_profile_path.buffer, ps, depth))        /* profile path unicode string */
-               return False;
-       if(!prs_align_needed(ps, usr->hdr_acct_desc.buffer))
-               return False;
-       if(!smb_io_unistr2("uni_acct_desc", &usr->uni_acct_desc, usr->hdr_acct_desc.buffer, ps, depth)) /* user desc unicode string */
-               return False;
-       if(!prs_align_needed(ps, usr->hdr_workstations.buffer))
-               return False;
-       if(!smb_io_unistr2("uni_workstations", &usr->uni_workstations, usr->hdr_workstations.buffer, ps, depth))        /* worksations user can log on from */
-               return False;
-       if(!prs_align_needed(ps, usr->hdr_unknown_str.buffer))
-               return False;
-       if(!smb_io_unistr2("uni_unknown_str", &usr->uni_unknown_str, usr->hdr_unknown_str.buffer, ps, depth))   /* unknown string */
-               return False;
-       if(!prs_align_needed(ps, usr->hdr_munged_dial.buffer))
-               return False;
-       if(!smb_io_unistr2("uni_munged_dial", &usr->uni_munged_dial, usr->hdr_munged_dial.buffer, ps, depth))   /* worksations user can log on from */
-               return False;
+void init_samr_q_get_dom_pwinfo(SAMR_Q_GET_DOM_PWINFO * q_u,
+                               char *srv_name)
+{
+       int len_srv_name = strlen(srv_name);
 
-       /* ok, this is only guess-work (as usual) */
-       if (usr->ptr_logon_hrs) {
-               if(!prs_align(ps))
-                       return False;
-               if(!prs_uint32("unknown_6", ps, depth, &usr->unknown_6))
-                       return False;
-               if(!prs_uint32("padding4", ps, depth, &usr->padding4))
-                       return False;
-               if(!sam_io_logon_hrs("logon_hrs", &usr->logon_hrs, ps, depth))
-                       return False;
-       } else if (UNMARSHALLING(ps)) {
-               usr->unknown_6 = 0;
-               usr->padding4 = 0;
-       }
+       DEBUG(5, ("init_samr_q_get_dom_pwinfo\n"));
 
-       return True;
+       q_u->ptr = 1;
+       init_uni_hdr(&q_u->hdr_srv_name, len_srv_name);
+       init_unistr2(&q_u->uni_srv_name, srv_name, len_srv_name);
 }
 
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-static BOOL sam_io_user_info24(char *desc, SAM_USER_INFO_24 *usr, prs_struct *ps, int depth)
+
+BOOL samr_io_q_get_dom_pwinfo(char *desc, SAMR_Q_GET_DOM_PWINFO * q_u,
+                             prs_struct *ps, int depth)
 {
-       if (usr == NULL)
+       if (q_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "sam_io_user_info24");
+       prs_debug(ps, depth, desc, "samr_io_q_get_dom_pwinfo");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint8s(False, "password", ps, depth, usr->pass, sizeof(usr->pass)))
+       if(!prs_uint32("ptr", ps, depth, &q_u->ptr))
                return False;
+       if (q_u->ptr != 0) {
+               if(!smb_io_unihdr("", &q_u->hdr_srv_name, ps, depth))
+                       return False;
+               if(!smb_io_unistr2("", &q_u->uni_srv_name, q_u->hdr_srv_name.buffer, ps, depth))
+                       return False;
+       }
 
        return True;
 }
@@ -4305,214 +6243,223 @@ static BOOL sam_io_user_info24(char *desc, SAM_USER_INFO_24 *usr, prs_struct *ps
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-static BOOL samr_io_userinfo_ctr(char *desc, SAM_USERINFO_CTR *ctr, prs_struct *ps, int depth)
+
+BOOL samr_io_r_get_dom_pwinfo(char *desc, SAMR_R_GET_DOM_PWINFO * r_u,
+                             prs_struct *ps, int depth)
 {
-       if (ctr == NULL)
+       if (r_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_userinfo_ctr");
+       prs_debug(ps, depth, desc, "samr_io_r_get_dom_pwinfo");
        depth++;
 
-       /* lkclXXXX DO NOT ALIGN BEFORE READING SWITCH VALUE! */
+       if(!prs_align(ps))
+               return False;
 
-       if(!prs_uint16("switch_value", ps, depth, &ctr->switch_value))
+       if(!prs_uint16("unk_0", ps, depth, &r_u->unk_0))
+               return False;
+       if(!prs_align(ps))
+               return False;
+       if(!prs_uint16("unk_1", ps, depth, &r_u->unk_1))
+               return False;
+       if(!prs_align(ps))
+               return False;
+       if(!prs_uint16("unk_2", ps, depth, &r_u->unk_2))
                return False;
        if(!prs_align(ps))
                return False;
 
-       switch (ctr->switch_value) {
-               case 0x10:
-                       if (UNMARSHALLING(ps)) /* reading */
-                               ctr->info.id10 = (SAM_USER_INFO_10 *)malloc(sizeof(SAM_USER_INFO_10));
-                       if (ctr->info.id10 == NULL) {
-                               DEBUG(2, ("samr_io_userinfo_ctr: info pointer not initialised\n"));
-                               return False;
-                       }
-                       if(!sam_io_user_info10("", ctr->info.id10, ps, depth))
-                               return False;
-                       break;
-               case 0x11:
-                       if (UNMARSHALLING(ps)) /* reading */
-                               ctr->info.id11 = (SAM_USER_INFO_11 *)malloc(sizeof(SAM_USER_INFO_11));
-                       if (ctr->info.id11 == NULL) {
-                               DEBUG(2, ("samr_io_userinfo_ctr: info pointer not initialised\n"));
-                               return False;
-                       }
-                       if(!sam_io_user_info11("", ctr->info.id11, ps, depth))
-                               return False;
-                       break;
-               case 0x12:
-                       if (UNMARSHALLING(ps)) /* reading */
-                               ctr->info.id12 = (SAM_USER_INFO_12 *)malloc(sizeof(SAM_USER_INFO_12));
-                       if (ctr->info.id12 == NULL) {
-                               DEBUG(2, ("samr_io_userinfo_ctr: info pointer not initialised\n"));
-                               return False;
-                       }
-                       if(!sam_io_user_info12("", ctr->info.id12, ps, depth))
-                               return False;
-                       break;
-               case 21:
-                       if (UNMARSHALLING(ps)) /* reading */
-                               ctr->info.id21 = (SAM_USER_INFO_21 *)malloc(sizeof(SAM_USER_INFO_21));
-                       if (ctr->info.id21 == NULL) {
-                               DEBUG(2, ("samr_io_userinfo_ctr: info pointer not initialised\n"));
-                               return False;
-                       }
-                       if(!sam_io_user_info21("", ctr->info.id21, ps, depth))
-                               return False;
-                       break;
-               case 23:
-                       if (UNMARSHALLING(ps)) /* reading */
-                               ctr->info.id23 = (SAM_USER_INFO_23 *)malloc(sizeof(SAM_USER_INFO_23));
-                       if (ctr->info.id23 == NULL) {
-                               DEBUG(2, ("samr_io_userinfo_ctr: info pointer not initialised\n"));
-                               return False;
-                       }
-                       if(!sam_io_user_info23("", ctr->info.id23, ps, depth))
-                               return False;
-                       break;
-               case 24:
-                       if (UNMARSHALLING(ps)) /* reading */
-                               ctr->info.id24 = (SAM_USER_INFO_24 *)malloc(sizeof(SAM_USER_INFO_24));
-                       if (ctr->info.id24 == NULL) {
-                               DEBUG(2, ("samr_io_userinfo_ctr: info pointer not initialised\n"));
-                               return False;
-                       }
-                       if(!sam_io_user_info24("", ctr->info.id24, ps, depth))
-                               return False;
-                       break;
-               default:
-                       DEBUG(2, ("samr_io_userinfo_ctr: unknown switch level 0x%x\n", ctr->switch_value));
-                       return False;
-
-       }
+       if(!prs_uint32("status", ps, depth, &r_u->status))
+               return False;
 
        return True;
 }
 
 /*******************************************************************
-frees a structure.
+make a SAMR_ENC_PASSWD structure.
 ********************************************************************/
-void free_samr_userinfo_ctr(SAM_USERINFO_CTR * ctr)
+
+void init_enc_passwd(SAMR_ENC_PASSWD * pwd, char pass[512])
 {
-       if (ctr == NULL)
-               return;
-       safe_free(ctr->info.id);
-       ctr->info.id = NULL;
+       ZERO_STRUCTP(pwd);
+
+       if (pass == NULL) {
+               pwd->ptr = 0;
+       } else {
+               pwd->ptr = 1;
+               memcpy(pwd->pass, pass, sizeof(pwd->pass));
+       }
 }
 
 /*******************************************************************
-reads or writes a structure.
+reads or writes a SAMR_ENC_PASSWD structure.
 ********************************************************************/
-BOOL samr_io_q_set_userinfo(char *desc, SAMR_Q_SET_USERINFO *q_u, prs_struct *ps, int depth)
+
+BOOL samr_io_enc_passwd(char *desc, SAMR_ENC_PASSWD * pwd,
+                       prs_struct *ps, int depth)
 {
-       if (q_u == NULL)
+       if (pwd == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_q_set_userinfo");
+       prs_debug(ps, depth, desc, "samr_io_enc_passwd");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
+       if(!prs_uint32("ptr", ps, depth, &pwd->ptr))
                return False;
 
-       if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
-               return False;
-       if(!samr_io_userinfo_ctr("ctr", q_u->ctr, ps, depth))
-               return False;
+       if (pwd->ptr != 0) {
+               if(!prs_uint8s(False, "pwd", ps, depth, pwd->pass, sizeof(pwd->pass)))
+                       return False;
+       }
 
        return True;
 }
 
 /*******************************************************************
-frees a structure.
+inits a SAMR_ENC_HASH structure.
 ********************************************************************/
-void free_samr_q_set_userinfo(SAMR_Q_SET_USERINFO * q_u)
+
+void init_enc_hash(SAMR_ENC_HASH * hsh, uchar hash[16])
 {
-       if (q_u == NULL)
-              return;
-       free_samr_userinfo_ctr(q_u->ctr);
+       ZERO_STRUCTP(hsh);
+
+       if (hash == NULL) {
+               hsh->ptr = 0;
+       } else {
+               hsh->ptr = 1;
+               memcpy(hsh->hash, hash, sizeof(hsh->hash));
+       }
 }
 
 /*******************************************************************
-reads or writes a structure.
+reads or writes a SAMR_ENC_HASH structure.
 ********************************************************************/
-BOOL samr_io_r_set_userinfo(char *desc, SAMR_R_SET_USERINFO *r_u, prs_struct *ps, int depth)
+
+BOOL samr_io_enc_hash(char *desc, SAMR_ENC_HASH * hsh,
+                     prs_struct *ps, int depth)
 {
-       if (r_u == NULL)
+       if (hsh == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_r_set_userinfo");
+       prs_debug(ps, depth, desc, "samr_io_enc_hash");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!prs_uint32("status", ps, depth, &r_u->status))
+       if(!prs_uint32("ptr ", ps, depth, &hsh->ptr))
                return False;
+       if (hsh->ptr != 0) {
+               if(!prs_uint8s(False, "hash", ps, depth, hsh->hash,sizeof(hsh->hash)))
+                       return False;
+       }
 
        return True;
 }
 
+/*******************************************************************
+inits a SAMR_R_GET_DOM_PWINFO structure.
+********************************************************************/
+
+void init_samr_q_chgpasswd_user(SAMR_Q_CHGPASSWD_USER * q_u,
+                               char *dest_host, char *user_name,
+                               char nt_newpass[516],
+                               uchar nt_oldhash[16],
+                               char lm_newpass[516],
+                               uchar lm_oldhash[16])
+{
+       int len_dest_host = strlen(dest_host);
+       int len_user_name = strlen(user_name);
+
+       DEBUG(5, ("init_samr_q_chgpasswd_user\n"));
+
+       q_u->ptr_0 = 1;
+       init_uni_hdr(&q_u->hdr_dest_host, len_dest_host);
+       init_unistr2(&q_u->uni_dest_host, dest_host, len_dest_host);
+       init_uni_hdr(&q_u->hdr_user_name, len_user_name);
+       init_unistr2(&q_u->uni_user_name, user_name, len_user_name);
+
+       init_enc_passwd(&q_u->nt_newpass, nt_newpass);
+       init_enc_hash(&q_u->nt_oldhash, nt_oldhash);
+
+       q_u->unknown = 0x01;
+
+       init_enc_passwd(&q_u->lm_newpass, lm_newpass);
+       init_enc_hash(&q_u->lm_oldhash, lm_oldhash);
+}
+
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-BOOL samr_io_q_set_userinfo2(char *desc, SAMR_Q_SET_USERINFO2 *q_u, prs_struct *ps, int depth)
+
+BOOL samr_io_q_chgpasswd_user(char *desc, SAMR_Q_CHGPASSWD_USER * q_u,
+                             prs_struct *ps, int depth)
 {
        if (q_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_q_set_userinfo2");
+       prs_debug(ps, depth, desc, "samr_io_q_chgpasswd_user");
        depth++;
 
        if(!prs_align(ps))
                return False;
 
-       if(!smb_io_pol_hnd("pol", &q_u->pol, ps, depth))
+       if(!prs_uint32("ptr_0", ps, depth, &q_u->ptr_0))
                return False;
 
-       if(!prs_uint16("switch_value", ps, depth, &q_u->switch_value))
+       if(!smb_io_unihdr("", &q_u->hdr_dest_host, ps, depth))
+               return False;
+       if(!smb_io_unistr2("", &q_u->uni_dest_host, q_u->hdr_dest_host.buffer, ps, depth))
+               return False;
+
+       if(!prs_align(ps))
+               return False;
+       if(!smb_io_unihdr("", &q_u->hdr_user_name, ps, depth))
+               return False;
+       if(!smb_io_unistr2("", &q_u->uni_user_name, q_u->hdr_user_name.buffer,ps, depth))
+               return False;
+
+       if(!samr_io_enc_passwd("nt_newpass", &q_u->nt_newpass, ps, depth))
+               return False;
+       if(!samr_io_enc_hash("nt_oldhash", &q_u->nt_oldhash, ps, depth))
                return False;
-       if(!samr_io_userinfo_ctr("ctr", q_u->ctr, ps, depth))
+
+       if(!prs_uint32("unknown", ps, depth, &q_u->unknown))
+               return False;
+
+       if(!samr_io_enc_passwd("lm_newpass", &q_u->lm_newpass, ps, depth))
+               return False;
+       if(!samr_io_enc_hash("lm_oldhash", &q_u->lm_oldhash, ps, depth))
                return False;
 
        return True;
 }
 
 /*******************************************************************
-frees a structure.
+inits a SAMR_R_CHGPASSWD_USER structure.
 ********************************************************************/
-void free_samr_q_set_userinfo2(SAMR_Q_SET_USERINFO2 *q_u)
-{
-       free_samr_userinfo_ctr(q_u->ctr);
-}
 
-/*******************************************************************
-makes a SAMR_R_SET_USERINFO2 structure.
-********************************************************************/
-BOOL make_samr_r_set_userinfo2(SAMR_R_SET_USERINFO2 *r_u, uint32 status)
+void init_samr_r_chgpasswd_user(SAMR_R_CHGPASSWD_USER * r_u, uint32 status)
 {
-       if (r_u == NULL)
-               return False;
-
-       DEBUG(5, ("make_samr_r_set_userinfo2\n"));
-
-       r_u->status = status;   /* return status */
+       DEBUG(5, ("init_r_chgpasswd_user\n"));
 
-       return True;
+       r_u->status = status;
 }
 
 /*******************************************************************
 reads or writes a structure.
 ********************************************************************/
-BOOL samr_io_r_set_userinfo2(char *desc, SAMR_R_SET_USERINFO2 *r_u, prs_struct *ps, int depth)
+
+BOOL samr_io_r_chgpasswd_user(char *desc, SAMR_R_CHGPASSWD_USER * r_u,
+                             prs_struct *ps, int depth)
 {
        if (r_u == NULL)
                return False;
 
-       prs_debug(ps, depth, desc, "samr_io_r_set_userinfo2");
+       prs_debug(ps, depth, desc, "samr_io_r_chgpasswd_user");
        depth++;
 
        if(!prs_align(ps))
@@ -4523,6 +6470,3 @@ BOOL samr_io_r_set_userinfo2(char *desc, SAMR_R_SET_USERINFO2 *r_u, prs_struct *
 
        return True;
 }
-
-
-#undef OLD_NTDOMAIN 
index 0073f22cab76881a24bb5ad294d57abd4b4ab516..7a4f0b57efa4fae5f63d444bdd3b521ba2290131 100644 (file)
@@ -5387,6 +5387,7 @@ BOOL convert_specific_param(NT_PRINTER_PARAM **param, const UNISTR2 *value,
        }
                
        DEBUGADD(6,("\tvalue:[%s], len:[%d]\n",(*param)->value, (*param)->data_len));
+       dump_data(10, (char *)(*param)->data, (*param)->data_len);
 
        return True;
 }
index 3db3161ed596e2aec2b7f3a69e2a856bb0e33a01..55a0cd95e5aec676b7d2dace9e5213ccd1b27e4f 100644 (file)
@@ -426,28 +426,6 @@ BOOL srv_io_r_net_share_enum(char *desc, SRV_R_NET_SHARE_ENUM *r_n, prs_struct *
        return True;
 }
 
-/*******************************************************************
- Frees a SRV_Q_NET_SHARE_GET_INFO structure.
-********************************************************************/
-
-void free_srv_q_net_share_get_info(SRV_Q_NET_SHARE_GET_INFO *q_n)
-{
-       if(!q_n)
-               return;
-       memset(q_n, '\0', sizeof(SRV_Q_NET_SHARE_GET_INFO));
-}
-
-/*******************************************************************
- Frees a SRV_R_NET_SHARE_GET_INFO structure.
-********************************************************************/
-
-void free_srv_r_net_share_get_info(SRV_R_NET_SHARE_GET_INFO *r_n)
-{
-       if(!r_n)
-               return;
-       memset(r_n, '\0', sizeof(SRV_R_NET_SHARE_GET_INFO));
-}
-
 /*******************************************************************
  Reads or writes a structure.
 ********************************************************************/
@@ -1585,6 +1563,45 @@ BOOL srv_io_r_net_file_enum(char *desc, SRV_R_NET_FILE_ENUM *r_n, prs_struct *ps
        return True;
 }
 
+/*******************************************************************
+ Inits a SRV_INFO_100 structure.
+ ********************************************************************/
+
+void init_srv_info_100(SRV_INFO_100 *sv100, uint32 platform_id, char *name)
+{
+       DEBUG(5,("init_srv_info_100\n"));
+
+       sv100->platform_id  = platform_id;
+       init_buf_unistr2(&sv100->uni_name, &sv100->ptr_name, name);
+}
+
+/*******************************************************************
+ Reads or writes a SRV_INFO_101 structure.
+ ********************************************************************/
+
+static BOOL srv_io_info_100(char *desc, SRV_INFO_100 *sv100, prs_struct *ps, int depth)
+{
+       if (sv100 == NULL)
+               return False;
+
+       prs_debug(ps, depth, desc, "srv_io_info_100");
+       depth++;
+
+       if(!prs_align(ps))
+               return False;
+
+       if(!prs_uint32("platform_id ", ps, depth, &sv100->platform_id))
+               return False;
+       if(!prs_uint32("ptr_name    ", ps, depth, &sv100->ptr_name))
+               return False;
+
+       if(!smb_io_unistr2("uni_name    ", &sv100->uni_name, True, ps, depth))
+               return False;
+
+       return True;
+}
+
+
 /*******************************************************************
  Inits a SRV_INFO_101 structure.
  ********************************************************************/
@@ -1754,6 +1771,10 @@ static BOOL srv_io_info_ctr(char *desc, SRV_INFO_CTR *ctr, prs_struct *ps, int d
 
        if (ctr->ptr_srv_ctr != 0 && ctr->switch_value != 0 && ctr != NULL) {
                switch (ctr->switch_value) {
+               case 100:
+                       if(!srv_io_info_100("sv100", &ctr->srv.sv100, ps, depth))
+                               return False;
+                       break;
                case 101:
                        if(!srv_io_info_101("sv101", &ctr->srv.sv101, ps, depth))
                                return False;
index 3b6725ec3ae395aba06c65d83044ad7e3ed456e9..b6a8c745a45867e06f1fbd3c8714882cc1203777 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
  *  Unix SMB/Netbios implementation.
  *  Version 1.9.
@@ -293,5 +292,3 @@ BOOL api_ntlsa_rpc(pipes_struct *p)
 {
        return api_rpcTNP(p, "api_ntlsa_rpc", api_lsa_cmds);
 }
-
-#undef OLD_NTDOMAIN
index 10b9bef1be1a7ac117d8e059b2c505260dc81536..bcc3878d863d652d3fd422bdfa7f3bc89da1b599 100644 (file)
@@ -1,11 +1,10 @@
-#define OLD_NTDOMAIN 1
-
 /* 
  *  Unix SMB/Netbios implementation.
  *  Version 1.9.
  *  RPC Pipe client / server routines
  *  Copyright (C) Andrew Tridgell              1992-1997,
  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
+ *  Copyright (C) Jeremy Allison                          2001.
  *  
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
 
 extern int DEBUGLEVEL;
 
+/* This is the max handles per pipe. */
 #ifndef MAX_OPEN_POLS
-#define MAX_OPEN_POLS 2048
+#define MAX_OPEN_POLS 256
 #endif
 
-struct reg_info
-{
-       /* for use by \PIPE\winreg */
-       fstring name; /* name of registry key */
-};
-
-struct samr_info
-{
-       /* for use by the \PIPE\samr policy */
-       DOM_SID sid;
-       uint32 status; /* some sort of flag.  best to record it.  comes from opnum 0x39 */
-};
-
-static struct policy
-{
-       struct policy *next, *prev;
-       int pnum;
-       BOOL open;
-       POLICY_HND pol_hnd;
-
-       union {
-               struct samr_info samr;
-               struct reg_info reg;
-       } dev;
-} *Policy;
-
-static struct bitmap *bmap;
-
-static uint32 pol_hnd_low  = 0;
-static uint32 pol_hnd_high = 0;
-
-/*******************************************************************
- Creates a POLICY_HND structure.
-********************************************************************/
-
-void create_policy_handle(POLICY_HND *hnd, uint32 *hnd_low, uint32 *hnd_high)
-{
-       if (hnd == NULL) return;
-
-    (*hnd_low)++;
-    if (*hnd_low == 0) (*hnd_high)++;
-
-    ZERO_STRUCTP(hnd);
-
-    SIVAL(&hnd->data1, 0 , 0);  /* first bit must be null */
-    SIVAL(&hnd->data2, 0 , *hnd_low ); /* second bit is incrementing */
-    SSVAL(&hnd->data3, 0 , *hnd_high); /* second bit is incrementing */
-    SSVAL(&hnd->data4, 0 , (*hnd_high>>16)); /* second bit is incrementing */
-    SIVAL(hnd->data5, 0, time(NULL)); /* something random */
-    SIVAL(hnd->data5, 4, sys_getpid()); /* something more random */
-}
-
 /****************************************************************************
   initialise policy handle states...
 ****************************************************************************/
-void init_lsa_policy_hnd(void)
+
+void init_pipe_handles(pipes_struct *p)
 {
-       bmap = bitmap_allocate(MAX_OPEN_POLS);
-       if (!bmap) {
-               exit_server("out of memory in init_lsa_policy_hnd\n");
-       }
+       p->pipe_handles.Policy = NULL;
+       p->pipe_handles.count = 0;
 }
 
 /****************************************************************************
   find first available policy slot.  creates a policy handle for you.
 ****************************************************************************/
-BOOL open_lsa_policy_hnd(POLICY_HND *hnd)
+
+BOOL create_policy_hnd(pipes_struct *p, POLICY_HND *hnd, void (*free_fn)(void *), void *data_ptr)
 {
-       int i;
-       struct policy *p;
+       static uint32 pol_hnd_low  = 0;
+       static uint32 pol_hnd_high = 0;
 
-       i = bitmap_find(bmap, 1);
+       struct policy *pol;
 
-       if (i == -1) {
-               DEBUG(0,("ERROR: out of Policy Handles!\n"));
+       if (p->pipe_handles.count > MAX_OPEN_POLS) {
+               DEBUG(0,("create_policy_hnd: ERROR: too many handles (%d) on this pipe.\n", (int)p->pipe_handles.count));
                return False;
        }
 
-       p = (struct policy *)malloc(sizeof(*p));
-       if (!p) {
-               DEBUG(0,("ERROR: out of memory!\n"));
+       pol = (struct policy *)malloc(sizeof(*p));
+       if (!pol) {
+               DEBUG(0,("create_policy_hnd: ERROR: out of memory!\n"));
                return False;
        }
 
-       ZERO_STRUCTP(p);
+       ZERO_STRUCTP(pol);
+
+       pol->p = p;
+       pol->data_ptr = data_ptr;
+       pol->free_fn = free_fn;
 
-       p->open = True;                         
-       p->pnum = i;
+    pol_hnd_low++;
+    if (pol_hnd_low == 0) (pol_hnd_high)++;
 
-       create_policy_handle(hnd, &pol_hnd_low, &pol_hnd_high);
-       p->pol_hnd = *hnd;
+    SIVAL(&pol->pol_hnd.data1, 0 , 0);  /* first bit must be null */
+    SIVAL(&pol->pol_hnd.data2, 0 , pol_hnd_low ); /* second bit is incrementing */
+    SSVAL(&pol->pol_hnd.data3, 0 , pol_hnd_high); /* second bit is incrementing */
+    SSVAL(&pol->pol_hnd.data4, 0 , (pol_hnd_high>>16)); /* second bit is incrementing */
+    SIVAL(pol->pol_hnd.data5, 0, time(NULL)); /* something random */
+    SIVAL(pol->pol_hnd.data5, 4, sys_getpid()); /* something more random */
 
-       bitmap_set(bmap, i);
+       DLIST_ADD(p->pipe_handles.Policy, pol);
+       p->pipe_handles.count++;
 
-       DLIST_ADD(Policy, p);
+       *hnd = pol->pol_hnd;
        
-       DEBUG(4,("Opened policy hnd[%x] ", i));
-       dump_data(4, (char *)hnd, sizeof(hnd));
+       DEBUG(4,("Opened policy hnd[%d] ", (int)p->pipe_handles.count));
+       dump_data(4, (char *)hnd, sizeof(*hnd));
 
        return True;
 }
 
 /****************************************************************************
-  find policy by handle
+  find policy by handle - internal version.
 ****************************************************************************/
-static struct policy *find_lsa_policy(POLICY_HND *hnd)
-{
-       struct policy *p;
 
-       for (p=Policy;p;p=p->next) {
-               if (memcmp(&p->pol_hnd, hnd, sizeof(*hnd)) == 0) {
-                       DEBUG(4,("Found policy hnd[%x] ", p->pnum));
-                       dump_data(4, (char *)hnd, sizeof(hnd));
-                       return p;
+static struct policy *find_policy_by_hnd_internal(pipes_struct *p, POLICY_HND *hnd, void **data_p)
+{
+       struct policy *pol;
+       size_t i;
+
+       if (data_p)
+               *data_p = NULL;
+
+       for (i = 0, pol=p->pipe_handles.Policy;pol;pol=pol->next, i++) {
+               if (memcmp(&pol->pol_hnd, hnd, sizeof(*hnd)) == 0) {
+                       DEBUG(4,("Found policy hnd[%d] ", (int)i));
+                       dump_data(4, (char *)hnd, sizeof(*hnd));
+                       if (data_p)
+                               *data_p = pol->data_ptr;
+                       return pol;
                }
        }
 
        DEBUG(4,("Policy not found: "));
-       dump_data(4, (char *)hnd, sizeof(hnd));
+       dump_data(4, (char *)hnd, sizeof(*hnd));
 
        return NULL;
 }
 
 /****************************************************************************
-  find policy index by handle
+  find policy by handle
 ****************************************************************************/
-int find_lsa_policy_by_hnd(POLICY_HND *hnd)
-{
-       struct policy *p = find_lsa_policy(hnd);
 
-       return p?p->pnum:-1;
-}
-
-
-/****************************************************************************
-  set samr pol status.  absolutely no idea what this is.
-****************************************************************************/
-BOOL set_lsa_policy_samr_pol_status(POLICY_HND *hnd, uint32 pol_status)
+BOOL find_policy_by_hnd(pipes_struct *p, POLICY_HND *hnd, void **data_p)
 {
-       struct policy *p = find_lsa_policy(hnd);
-
-       if (p && p->open) {
-               DEBUG(3,("Setting policy status=%x pnum=%x\n",
-                         pol_status, p->pnum));
-
-               p->dev.samr.status = pol_status;
-               return True;
-       } 
-
-       DEBUG(3,("Error setting policy status=%x\n",
-                pol_status));
-       return False;
+       return find_policy_by_hnd_internal(p, hnd, data_p) == NULL ? False : True;
 }
 
 /****************************************************************************
-  set samr sid
+  Close a policy.
 ****************************************************************************/
-BOOL set_lsa_policy_samr_sid(POLICY_HND *hnd, DOM_SID *sid)
-{
-       fstring sidstr;
-       struct policy *p = find_lsa_policy(hnd);
 
-       if (p && p->open) {
-               DEBUG(3,("Setting policy sid=%s pnum=%x\n",
-                        sid_to_string(sidstr, sid), p->pnum));
-
-               memcpy(&p->dev.samr.sid, sid, sizeof(*sid));
-               return True;
-       }
-
-       DEBUG(3,("Error setting policy sid=%s\n",
-                 sid_to_string(sidstr, sid)));
-       return False;
-}
-
-/****************************************************************************
-  get samr sid
-****************************************************************************/
-BOOL get_lsa_policy_samr_sid(POLICY_HND *hnd, DOM_SID *sid)
+BOOL close_policy_hnd(pipes_struct *p, POLICY_HND *hnd)
 {
-       struct policy *p = find_lsa_policy(hnd);
+       struct policy *pol = find_policy_by_hnd_internal(p, hnd, NULL);
 
-       if (p != NULL && p->open) {
-               fstring sidstr;
-               memcpy(sid, &p->dev.samr.sid, sizeof(*sid));
-               DEBUG(3,("Getting policy sid=%s pnum=%x\n",
-                        sid_to_string(sidstr, sid), p->pnum));
-
-               return True;
+       if (!pol) {
+               DEBUG(3,("Error closing policy\n"));
+               return False;
        }
 
-       DEBUG(3,("Error getting policy\n"));
-       return False;
-}
+       DEBUG(3,("Closed policy\n"));
 
-/****************************************************************************
-  get samr rid
-****************************************************************************/
-uint32 get_lsa_policy_samr_rid(POLICY_HND *hnd)
-{
-       struct policy *p = find_lsa_policy(hnd);
+       if (pol->free_fn && pol->data_ptr)
+               (*pol->free_fn)(pol->data_ptr);
 
-       if (p && p->open) {
-               uint32 rid = p->dev.samr.sid.sub_auths[p->dev.samr.sid.num_auths-1];
-               DEBUG(3,("Getting policy device rid=%x pnum=%x\n",
-                         rid, p->pnum));
+       pol->p->pipe_handles.count--;
 
-               return rid;
-       }
+       DLIST_REMOVE(pol->p->pipe_handles.Policy, pol);
 
-       DEBUG(3,("Error getting policy\n"));
-       return 0xffffffff;
-}
+       ZERO_STRUCTP(pol);
 
-/****************************************************************************
-  set reg name 
-****************************************************************************/
-BOOL set_lsa_policy_reg_name(POLICY_HND *hnd, fstring name)
-{
-       struct policy *p = find_lsa_policy(hnd);
-
-       if (p && p->open) {
-               DEBUG(3,("Setting policy pnum=%x name=%s\n",
-                        p->pnum, name));
+       free(pol);
 
-               fstrcpy(p->dev.reg.name, name);
-               return True;
-       }
-
-       DEBUG(3,("Error setting policy name=%s\n", name));
-       return False;
+       return True;
 }
 
 /****************************************************************************
-  close an lsa policy
+ Close all the pipe handles.
 ****************************************************************************/
-BOOL close_lsa_policy_hnd(POLICY_HND *hnd)
-{
-       struct policy *p = find_lsa_policy(hnd);
 
-       if (!p) {
-               DEBUG(3,("Error closing policy\n"));
-               return False;
-       }
-
-       DEBUG(3,("Closed policy name pnum=%x\n",  p->pnum));
-
-       DLIST_REMOVE(Policy, p);
-
-       bitmap_clear(bmap, p->pnum);
-
-       ZERO_STRUCTP(p);
-
-       free(p);
+void close_policy_by_pipe(pipes_struct *p)
+{
+       while (p->pipe_handles.Policy)
+               close_policy_hnd(p, &p->pipe_handles.Policy->pol_hnd);
 
-       return True;
+       p->pipe_handles.Policy = NULL;
+       p->pipe_handles.count = 0;
 }
-
-#undef OLD_NTDOMAIN
index ee2f38b7152e20c9e19426fa5b84c56c5e64cc48..8e1d934309771ce698a8a2868b37002254a51546 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
  *  Unix SMB/Netbios implementation.
  *  Version 1.9.
@@ -275,9 +274,6 @@ static void init_reply_lookup_sids(LSA_R_LOOKUP_SIDS *r_l,
                r_l->status = NT_STATUS_NO_PROBLEMO;
 }
 
-static uint32 lsa_hnd_low  = 0;
-static uint32 lsa_hnd_high = 0;
-
 /***************************************************************************
  _lsa_open_policy2.
  ***************************************************************************/
@@ -287,7 +283,8 @@ uint32 _lsa_open_policy2(pipes_struct *p, LSA_Q_OPEN_POL2 *q_u, LSA_R_OPEN_POL2
        /* lkclXXXX having decoded it, ignore all fields in the open policy! */
 
        /* set up the LSA QUERY INFO response */
-       create_policy_handle(&r_u->pol, &lsa_hnd_low, &lsa_hnd_high);
+       if (!create_policy_hnd(p, &r_u->pol, NULL, NULL))
+               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
 
        return NT_STATUS_NOPROBLEMO;
 }
@@ -301,7 +298,8 @@ uint32 _lsa_open_policy(pipes_struct *p, LSA_Q_OPEN_POL *q_u, LSA_R_OPEN_POL *r_
        /* lkclXXXX having decoded it, ignore all fields in the open policy! */
 
        /* set up the LSA QUERY INFO response */
-       create_policy_handle(&r_u->pol, &lsa_hnd_low, &lsa_hnd_high);
+       if (!create_policy_hnd(p, &r_u->pol, NULL, NULL))
+               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
 
        return NT_STATUS_NOPROBLEMO;
 }
@@ -316,6 +314,9 @@ uint32 _lsa_enum_trust_dom(pipes_struct *p, LSA_Q_ENUM_TRUST_DOM *q_u, LSA_R_ENU
        char *dom_name = NULL;
        DOM_SID *dom_sid = NULL;
 
+       if (!find_policy_by_hnd(p, &q_u->pol, NULL))
+               return NT_STATUS_INVALID_HANDLE;
+
        /* set up the LSA QUERY INFO response */
        init_r_enum_trust_dom(r_u, enum_context, dom_name, dom_sid,
              dom_name != NULL ? NT_STATUS_NO_PROBLEMO : NT_STATUS_UNABLE_TO_FREE_VM);
@@ -336,6 +337,9 @@ uint32 _lsa_query_info(pipes_struct *p, LSA_Q_QUERY_INFO *q_u, LSA_R_QUERY_INFO
 
        r_u->status = NT_STATUS_NO_PROBLEMO;
 
+       if (!find_policy_by_hnd(p, &q_u->pol, NULL))
+               return NT_STATUS_INVALID_HANDLE;
+
        switch (q_u->info_class) {
        case 0x02:
                {
@@ -420,6 +424,9 @@ uint32 _lsa_lookup_sids(pipes_struct *p, LSA_Q_LOOKUP_SIDS *q_u, LSA_R_LOOKUP_SI
        LSA_TRANS_NAME_ENUM *names = NULL;
        uint32 mapped_count = 0;
 
+       if (!find_policy_by_hnd(p, &q_u->pol, NULL))
+               return NT_STATUS_INVALID_HANDLE;
+
        ref = (DOM_R_REF *)talloc_zero(p->mem_ctx, sizeof(DOM_R_REF));
        names = (LSA_TRANS_NAME_ENUM *)talloc_zero(p->mem_ctx, sizeof(LSA_TRANS_NAME_ENUM));
 
@@ -445,6 +452,9 @@ uint32 _lsa_lookup_names(pipes_struct *p,LSA_Q_LOOKUP_NAMES *q_u, LSA_R_LOOKUP_N
        DOM_RID2 *rids;
        uint32 mapped_count = 0;
 
+       if (!find_policy_by_hnd(p, &q_u->pol, NULL))
+               return NT_STATUS_INVALID_HANDLE;
+
        ref = (DOM_R_REF *)talloc_zero(p->mem_ctx, sizeof(DOM_R_REF));
        rids = (DOM_RID2 *)talloc_zero(p->mem_ctx, sizeof(DOM_RID2)*MAX_LOOKUP_SIDS);
 
@@ -464,6 +474,10 @@ uint32 _lsa_lookup_names(pipes_struct *p,LSA_Q_LOOKUP_NAMES *q_u, LSA_R_LOOKUP_N
 
 uint32 _lsa_close(pipes_struct *p, LSA_Q_CLOSE *q_u, LSA_R_CLOSE *r_u)
 {
+       if (!find_policy_by_hnd(p, &q_u->pol, NULL))
+               return NT_STATUS_INVALID_HANDLE;
+
+       close_policy_hnd(p, &q_u->pol);
        return NT_STATUS_NO_PROBLEMO;
 }
 
@@ -475,4 +489,3 @@ uint32 _lsa_open_secret(pipes_struct *p, LSA_Q_OPEN_SECRET *q_u, LSA_R_OPEN_SECR
 {
        return NT_STATUS_OBJECT_NAME_NOT_FOUND;
 }
-#undef OLD_NTDOMAIN
index 8e2b3819cbf578dd06518c333a6427d58626a363..01d646bf576f94f683c7a60b5fc6906485d463ba 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
  *  Unix SMB/Netbios implementation.
  *  Version 1.9.
@@ -6,7 +5,7 @@
  *  Copyright (C) Andrew Tridgell              1992-1997,
  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
  *  Copyright (C) Paul Ashton                       1997.
- *  Copyright (C) Jeremy Allison                    1998.
+ *  Copyright (C) Jeremy Allison               1998-2001.
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+/* This is the interface to the netlogon pipe. */
+
 #include "includes.h"
 
 extern int DEBUGLEVEL;
 
-extern BOOL sam_logon_in_ssb;
-extern pstring samlogon_user;
-extern pstring global_myname;
-extern DOM_SID global_sam_sid;
-
-/*************************************************************************
- init_net_r_req_chal:
- *************************************************************************/
-
-static void init_net_r_req_chal(NET_R_REQ_CHAL *r_c,
-                                DOM_CHAL *srv_chal, int status)
-{
-       DEBUG(6,("init_net_r_req_chal: %d\n", __LINE__));
-       memcpy(r_c->srv_chal.data, srv_chal->data, sizeof(srv_chal->data));
-       r_c->status = status;
-}
-
-/*************************************************************************
- net_reply_req_chal:
- *************************************************************************/
-
-static BOOL net_reply_req_chal(NET_Q_REQ_CHAL *q_c, prs_struct *rdata,
-                                       DOM_CHAL *srv_chal, uint32 srv_time)
-{
-       NET_R_REQ_CHAL r_c;
-
-       DEBUG(6,("net_reply_req_chal: %d\n", __LINE__));
-
-       /* set up the LSA REQUEST CHALLENGE response */
-       init_net_r_req_chal(&r_c, srv_chal, srv_time);
-
-       /* store the response in the SMB stream */
-       if(!net_io_r_req_chal("", &r_c, rdata, 0)) {
-               DEBUG(0,("net_reply_req_chal: Failed to marshall NET_R_REQ_CHAL.\n"));
-               return False;
-       }
-
-       DEBUG(6,("net_reply_req_chal: %d\n", __LINE__));
-
-       return True;
-}
-
-/*************************************************************************
- net_reply_logon_ctrl2:
- *************************************************************************/
-
-static BOOL net_reply_logon_ctrl2(NET_Q_LOGON_CTRL2 *q_l, prs_struct *rdata,
-                       uint32 flags, uint32 pdc_status, uint32 logon_attempts,
-                       uint32 tc_status, char *trust_domain_name)
-{
-       NET_R_LOGON_CTRL2 r_l;
-
-       DEBUG(6,("net_reply_logon_ctrl2: %d\n", __LINE__));
-
-       /* set up the Logon Control2 response */
-       init_r_logon_ctrl2(&r_l, q_l->query_level,
-                          flags, pdc_status, logon_attempts,
-                          tc_status, trust_domain_name);
-
-       /* store the response in the SMB stream */
-       if(!net_io_r_logon_ctrl2("", &r_l, rdata, 0)) {
-               DEBUG(0,("net_reply_logon_ctrl2: Failed to marshall NET_R_LOGON_CTRL2.\n"));
-               return False;
-       }
-
-       DEBUG(6,("net_reply_logon_ctrl2: %d\n", __LINE__));
-
-       return True;
-}
-
-/*************************************************************************
- net_reply_trust_dom_list:
- *************************************************************************/
-
-static BOOL net_reply_trust_dom_list(NET_Q_TRUST_DOM_LIST *q_t, prs_struct *rdata,
-                       uint32 num_trust_domains, char *trust_domain_name)
-{
-       NET_R_TRUST_DOM_LIST r_t;
-
-       DEBUG(6,("net_reply_trust_dom_list: %d\n", __LINE__));
-
-       /* set up the Trusted Domain List response */
-       init_r_trust_dom(&r_t, num_trust_domains, trust_domain_name);
-
-       /* store the response in the SMB stream */
-       if(!net_io_r_trust_dom("", &r_t, rdata, 0)) {
-               DEBUG(0,("net_reply_trust_dom_list: Failed to marshall NET_R_TRUST_DOM_LIST.\n"));
-               return False;
-       }
-
-       DEBUG(6,("net_reply_trust_dom_listlogon_ctrl2: %d\n", __LINE__));
-
-       return True;
-}
-
-/*************************************************************************
- init_net_r_auth_2:
- *************************************************************************/
-
-static void init_net_r_auth_2(NET_R_AUTH_2 *r_a,
-                              DOM_CHAL *resp_cred, NEG_FLAGS *flgs, int status)
-{
-       memcpy(r_a->srv_chal.data, resp_cred->data, sizeof(resp_cred->data));
-       memcpy(&r_a->srv_flgs, flgs, sizeof(r_a->srv_flgs));
-       r_a->status = status;
-}
-
-/************************************************************************
- net_reply_auth_2:
- *************************************************************************/
-
-static BOOL net_reply_auth_2(NET_Q_AUTH_2 *q_a, prs_struct *rdata,
-                               DOM_CHAL *resp_cred, int status)
-{
-       NET_R_AUTH_2 r_a;
-       NEG_FLAGS srv_flgs;
-
-       srv_flgs.neg_flags = 0x000001ff;
-
-       /* set up the LSA AUTH 2 response */
-
-       init_net_r_auth_2(&r_a, resp_cred, &srv_flgs, status);
-
-       /* store the response in the SMB stream */
-       if(!net_io_r_auth_2("", &r_a, rdata, 0)) {
-               DEBUG(0,("net_reply_auth_2: Failed to marshall NET_R_AUTH_2.\n"));
-               return False;
-       }
-
-       return True;
-}
-
-/***********************************************************************************
- init_net_r_srv_pwset:
- ***********************************************************************************/
-
-static void init_net_r_srv_pwset(NET_R_SRV_PWSET *r_s,
-                             DOM_CRED *srv_cred, int status)  
-{
-       DEBUG(5,("init_net_r_srv_pwset: %d\n", __LINE__));
-
-       memcpy(&r_s->srv_cred, srv_cred, sizeof(r_s->srv_cred));
-       r_s->status = status;
-
-       DEBUG(5,("init_net_r_srv_pwset: %d\n", __LINE__));
-}
-
-/*************************************************************************
- net_reply_srv_pwset:
- *************************************************************************/
-
-static BOOL net_reply_srv_pwset(NET_Q_SRV_PWSET *q_s, prs_struct *rdata,
-                               DOM_CRED *srv_cred, int status)
-{
-       NET_R_SRV_PWSET r_s;
-
-       DEBUG(5,("net_srv_pwset: %d\n", __LINE__));
-
-       /* set up the LSA Server Password Set response */
-       init_net_r_srv_pwset(&r_s, srv_cred, status);
-
-       /* store the response in the SMB stream */
-       if(!net_io_r_srv_pwset("", &r_s, rdata, 0)) {
-               DEBUG(0,("net_reply_srv_pwset: Failed to marshall NET_R_SRV_PWSET.\n"));
-               return False;
-       }
-
-       DEBUG(5,("net_srv_pwset: %d\n", __LINE__));
-
-       return True;
-}
-
-/*************************************************************************
- net_reply_sam_logon:
- *************************************************************************/
-
-static BOOL net_reply_sam_logon(NET_Q_SAM_LOGON *q_s, prs_struct *rdata,
-                               DOM_CRED *srv_cred, NET_USER_INFO_3 *user_info,
-                               uint32 status)
-{
-       NET_R_SAM_LOGON r_s;
-
-       /* XXXX maybe we want to say 'no', reject the client's credentials */
-       r_s.buffer_creds = 1; /* yes, we have valid server credentials */
-       memcpy(&r_s.srv_creds, srv_cred, sizeof(r_s.srv_creds));
-
-       /* store the user information, if there is any. */
-       r_s.user = user_info;
-       if (status == 0x0 && user_info != NULL && user_info->ptr_user_info != 0)
-               r_s.switch_value = 3; /* indicates type of validation user info */
-       else
-               r_s.switch_value = 0; /* indicates no info */
-
-       r_s.status = status;
-       r_s.auth_resp = 1; /* authoritative response */
-
-       /* store the response in the SMB stream */
-       if(!net_io_r_sam_logon("", &r_s, rdata, 0)) {
-               DEBUG(0,("net_reply_sam_logon: Failed to marshall NET_R_SAM_LOGON.\n"));
-               return False;
-       }
-
-       return True;
-}
-
-
-/*************************************************************************
- net_reply_sam_logoff:
- *************************************************************************/
-
-static BOOL net_reply_sam_logoff(NET_Q_SAM_LOGOFF *q_s, prs_struct *rdata,
-                               DOM_CRED *srv_cred, 
-                               uint32 status)
-{
-       NET_R_SAM_LOGOFF r_s;
-
-       /* XXXX maybe we want to say 'no', reject the client's credentials */
-       r_s.buffer_creds = 1; /* yes, we have valid server credentials */
-       memcpy(&r_s.srv_creds, srv_cred, sizeof(r_s.srv_creds));
-
-       r_s.status = status;
-
-       /* store the response in the SMB stream */
-       if(!net_io_r_sam_logoff("", &r_s, rdata, 0)) {
-               DEBUG(0,("net_reply_sam_logoff: Failed to marshall NET_R_SAM_LOGOFF.\n"));
-               return False;
-       }
-
-       return True;
-}
-
-/******************************************************************
- gets a machine password entry.  checks access rights of the host.
- ******************************************************************/
-
-static BOOL get_md4pw(char *md4pw, char *mach_name, char *mach_acct)
-{
-       SAM_ACCOUNT     *sampass = NULL;
-       BYTE            *pass = NULL;
-
-#if 0
-    /*
-     * Currently this code is redundent as we already have a filter
-     * by hostname list. What this code really needs to do is to 
-     * get a hosts allowed/hosts denied list from the SAM database
-     * on a per user basis, and make the access decision there.
-     * I will leave this code here for now as a reminder to implement
-     * this at a later date. JRA.
-     */
-
-       if (!allow_access(lp_domain_hostsdeny(), lp_domain_hostsallow(),
-                         client_name(), client_addr()))
-       {
-               DEBUG(0,("get_md4pw: Workstation %s denied access to domain\n", mach_acct));
-               return False;
-       }
-#endif /* 0 */
-
-       become_root();
-       sampass = pdb_getsampwnam(mach_acct);
-       unbecome_root();
-
-       if ((sampass) != NULL && !(pdb_get_acct_ctrl(sampass) & ACB_DISABLED) &&
-        ((pass=pdb_get_nt_passwd(sampass)) != NULL))
-       {
-               memcpy(md4pw, pass, 16);
-               dump_data(5, md4pw, 16);
-
-               return True;
-       }
-       DEBUG(0,("get_md4pw: Workstation %s: no account in domain\n", mach_acct));
-       return False;
-}
-
 /*************************************************************************
  api_net_req_chal:
  *************************************************************************/
 
 static BOOL api_net_req_chal(pipes_struct *p)
 {
-       NET_Q_REQ_CHAL q_r;
-       uint32 status = 0x0;
-        uint16 vuid = p->vuid;
+       NET_Q_REQ_CHAL q_u;
+       NET_R_REQ_CHAL r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
-       fstring mach_acct;
-       fstring mach_name;
-
-       user_struct *vuser;
-
-       DEBUG(5,("api_net_req_chal(%d): vuid %d\n", __LINE__, (int)vuid));
-
-       if ((vuser = get_valid_user_struct(vuid)) == NULL)
-               return False;
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
        /* grab the challenge... */
-       if(!net_io_q_req_chal("", &q_r, data, 0)) {
+       if(!net_io_q_req_chal("", &q_u, data, 0)) {
                DEBUG(0,("api_net_req_chal: Failed to unmarshall NET_Q_REQ_CHAL.\n"));
                return False;
        }
 
-       fstrcpy(mach_acct, dos_unistrn2(q_r.uni_logon_clnt.buffer,
-                                   q_r.uni_logon_clnt.uni_str_len));
-
-       fstrcpy(mach_name, mach_acct);
-       strlower(mach_name);
-
-       fstrcat(mach_acct, "$");
+       r_u.status = _net_req_chal(p, &q_u, &r_u);
 
-       if (get_md4pw((char *)vuser->dc.md4pw, mach_name, mach_acct)) {
-               /* copy the client credentials */
-               memcpy(vuser->dc.clnt_chal.data          , q_r.clnt_chal.data, sizeof(q_r.clnt_chal.data));
-               memcpy(vuser->dc.clnt_cred.challenge.data, q_r.clnt_chal.data, sizeof(q_r.clnt_chal.data));
-
-               /* create a server challenge for the client */
-               /* Set these to random values. */
-                generate_random_buffer(vuser->dc.srv_chal.data, 8, False);
-
-               memcpy(vuser->dc.srv_cred.challenge.data, vuser->dc.srv_chal.data, 8);
-
-               memset((char *)vuser->dc.sess_key, '\0', sizeof(vuser->dc.sess_key));
-
-               /* from client / server challenges and md4 password, generate sess key */
-               cred_session_key(&(vuser->dc.clnt_chal), &(vuser->dc.srv_chal),
-                                (char *)vuser->dc.md4pw, vuser->dc.sess_key);
-       } else {
-               /* lkclXXXX take a guess at a good error message to return :-) */
-               status = NT_STATUS_NOLOGON_WORKSTATION_TRUST_ACCOUNT;
-       }
-
-       /* construct reply. */
-       if(!net_reply_req_chal(&q_r, rdata, &vuser->dc.srv_chal, status))
+       /* store the response in the SMB stream */
+       if(!net_io_r_req_chal("", &r_u, rdata, 0)) {
+               DEBUG(0,("api_net_req_chal: Failed to marshall NET_R_REQ_CHAL.\n"));
                return False;
+       }
 
        return True;
 }
@@ -371,270 +65,90 @@ static BOOL api_net_req_chal(pipes_struct *p)
 
 static BOOL api_net_auth_2(pipes_struct *p)
 {
-       uint16 vuid = p->vuid;
-       NET_Q_AUTH_2 q_a;
-       uint32 status = 0x0;
+       NET_Q_AUTH_2 q_u;
+       NET_R_AUTH_2 r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
-       DOM_CHAL srv_cred;
-       UTIME srv_time;
-
-       user_struct *vuser;
-
-       if ((vuser = get_valid_user_struct(vuid)) == NULL)
-               return False;
-
-       srv_time.time = 0;
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
        /* grab the challenge... */
-       if(!net_io_q_auth_2("", &q_a, data, 0)) {
+       if(!net_io_q_auth_2("", &q_u, data, 0)) {
                DEBUG(0,("api_net_auth_2: Failed to unmarshall NET_Q_AUTH_2.\n"));
                return False;
        }
 
-       /* check that the client credentials are valid */
-       if (cred_assert(&(q_a.clnt_chal), vuser->dc.sess_key,
-                    &(vuser->dc.clnt_cred.challenge), srv_time)) {
-
-               /* create server challenge for inclusion in the reply */
-               cred_create(vuser->dc.sess_key, &(vuser->dc.srv_cred.challenge), srv_time, &srv_cred);
-
-               /* copy the received client credentials for use next time */
-               memcpy(vuser->dc.clnt_cred.challenge.data, q_a.clnt_chal.data, sizeof(q_a.clnt_chal.data));
-               memcpy(vuser->dc.srv_cred .challenge.data, q_a.clnt_chal.data, sizeof(q_a.clnt_chal.data));
-       } else {
-               status = NT_STATUS_ACCESS_DENIED;
-       }
+       r_u.status = _net_auth_2(p, &q_u, &r_u);
 
-       /* construct reply. */
-       if(!net_reply_auth_2(&q_a, rdata, &srv_cred, status))
+       /* store the response in the SMB stream */
+       if(!net_io_r_auth_2("", &r_u, rdata, 0)) {
+               DEBUG(0,("api_net_auth_2: Failed to marshall NET_R_AUTH_2.\n"));
                return False;
+       }
 
        return True;
 }
 
-
 /*************************************************************************
  api_net_srv_pwset:
  *************************************************************************/
 
 static BOOL api_net_srv_pwset(pipes_struct *p)
 {
-       uint16 vuid = p->vuid;
-       NET_Q_SRV_PWSET q_a;
-       uint32 status = NT_STATUS_WRONG_PASSWORD;
-       DOM_CRED srv_cred;
-       pstring mach_acct;
-       SAM_ACCOUNT *sampass;
-       BOOL ret;
-       user_struct *vuser;
+       NET_Q_SRV_PWSET q_u;
+       NET_R_SRV_PWSET r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
-       if ((vuser = get_valid_user_struct(vuid)) == NULL)
-               return False;
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
        /* grab the challenge and encrypted password ... */
-       if(!net_io_q_srv_pwset("", &q_a, data, 0)) {
+       if(!net_io_q_srv_pwset("", &q_u, data, 0)) {
                DEBUG(0,("api_net_srv_pwset: Failed to unmarshall NET_Q_SRV_PWSET.\n"));
                return False;
        }
 
-       /* checks and updates credentials.  creates reply credentials */
-       if (deal_with_creds(vuser->dc.sess_key, &(vuser->dc.clnt_cred), 
-                           &(q_a.clnt_id.cred), &srv_cred))
-       {
-               memcpy(&(vuser->dc.srv_cred), &(vuser->dc.clnt_cred), sizeof(vuser->dc.clnt_cred));
-
-               DEBUG(5,("api_net_srv_pwset: %d\n", __LINE__));
-
-               pstrcpy(mach_acct, dos_unistrn2(q_a.clnt_id.login.uni_acct_name.buffer,
-                                           q_a.clnt_id.login.uni_acct_name.uni_str_len));
-
-               DEBUG(3,("Server Password Set Wksta:[%s]\n", mach_acct));
-
-               become_root();
-               sampass = pdb_getsampwnam(mach_acct);
-               unbecome_root();
-
-               if (sampass != NULL) {
-                       unsigned char pwd[16];
-                       int i;
-
-                       DEBUG(100,("Server password set : new given value was :\n"));
-                       for(i = 0; i < 16; i++)
-                               DEBUG(100,("%02X ", q_a.pwd[i]));
-                       DEBUG(100,("\n"));
-
-                       cred_hash3( pwd, q_a.pwd, vuser->dc.sess_key, 0);
-
-                       /* lies!  nt and lm passwords are _not_ the same: don't care */
-                       pdb_set_lanman_passwd (sampass, pwd);
-                       pdb_set_nt_passwd     (sampass, pwd);
-                       pdb_set_acct_ctrl     (sampass, ACB_WSTRUST);
-
-                       become_root();                  
-                       ret = pdb_update_sam_account (sampass,False);
-                       unbecome_root();
-
-                       if (ret) {
-                               /* hooray! */
-                               status = 0x0;
-                       }
-               }
-
-               DEBUG(5,("api_net_srv_pwset: %d\n", __LINE__));
+       r_u.status = _net_srv_pwset(p, &q_u, &r_u);
 
-       } else {
-               /* lkclXXXX take a guess at a sensible error code to return... */
-               status = NT_STATUS_NETWORK_CREDENTIAL_CONFLICT;
-       }
-
-       /* Construct reply. */
-       if(!net_reply_srv_pwset(&q_a, rdata, &srv_cred, status))
+       /* store the response in the SMB stream */
+       if(!net_io_r_srv_pwset("", &r_u, rdata, 0)) {
+               DEBUG(0,("api_net_srv_pwset: Failed to marshall NET_R_SRV_PWSET.\n"));
                return False;
+       }
 
        return True;
 }
 
-
 /*************************************************************************
  api_net_sam_logoff:
  *************************************************************************/
 
 static BOOL api_net_sam_logoff(pipes_struct *p)
 {
-        uint16 vuid = p->vuid;
-       NET_Q_SAM_LOGOFF q_l;
-       NET_ID_INFO_CTR ctr;    
-       DOM_CRED srv_cred;
+       NET_Q_SAM_LOGOFF q_u;
+       NET_R_SAM_LOGOFF r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
-       user_struct *vuser;
-
-       if ((vuser = get_valid_user_struct(vuid)) == NULL)
-               return False;
-
-       /* the DOM_ID_INFO_1 structure is a bit big.  plus we might want to
-          dynamically allocate it inside net_io_q_sam_logon, at some point */
-       q_l.sam_id.ctr = &ctr;
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       /* grab the challenge... */
-       if(!net_io_q_sam_logoff("", &q_l, data, 0)) {
+       if(!net_io_q_sam_logoff("", &q_u, data, 0)) {
                DEBUG(0,("api_net_sam_logoff: Failed to unmarshall NET_Q_SAM_LOGOFF.\n"));
                return False;
        }
 
-       /* checks and updates credentials.  creates reply credentials */
-       deal_with_creds(vuser->dc.sess_key, &vuser->dc.clnt_cred, 
-                       &q_l.sam_id.client.cred, &srv_cred);
-       memcpy(&vuser->dc.srv_cred, &vuser->dc.clnt_cred, sizeof(vuser->dc.clnt_cred));
+       r_u.status = _net_sam_logoff(p, &q_u, &r_u);
 
-       /* construct reply.  always indicate success */
-       if(!net_reply_sam_logoff(&q_l, rdata, &srv_cred, 0x0))
+       /* store the response in the SMB stream */
+       if(!net_io_r_sam_logoff("", &r_u, rdata, 0)) {
+               DEBUG(0,("api_net_sam_logoff: Failed to marshall NET_R_SAM_LOGOFF.\n"));
                return False;
-
-       return True;
-}
-
-/*************************************************************************
- net_login_interactive:
- *************************************************************************/
-
-static uint32 net_login_interactive(NET_ID_INFO_1 *id1, SAM_ACCOUNT *sampass,
-                                   user_struct *vuser)
-{
-       uint32 status = 0x0;
-
-       char nt_pwd[16];
-       char lm_pwd[16];
-       unsigned char key[16];
-
-       memset(key, 0, 16);
-       memcpy(key, vuser->dc.sess_key, 8);
-
-       memcpy(lm_pwd, id1->lm_owf.data, 16);
-       memcpy(nt_pwd, id1->nt_owf.data, 16);
-
-#ifdef DEBUG_PASSWORD
-       DEBUG(100,("key:"));
-       dump_data(100, (char *)key, 16);
-
-       DEBUG(100,("lm owf password:"));
-       dump_data(100, lm_pwd, 16);
-
-       DEBUG(100,("nt owf password:"));
-       dump_data(100, nt_pwd, 16);
-#endif
-
-       SamOEMhash((uchar *)lm_pwd, key, False);
-       SamOEMhash((uchar *)nt_pwd, key, False);
-
-#ifdef DEBUG_PASSWORD
-       DEBUG(100,("decrypt of lm owf password:"));
-       dump_data(100, lm_pwd, 16);
-
-       DEBUG(100,("decrypt of nt owf password:"));
-       dump_data(100, nt_pwd, 16);
-#endif
-
-       if (memcmp(pdb_get_lanman_passwd(sampass)  ,lm_pwd, 16) != 0 ||
-           memcmp(pdb_get_nt_passwd(sampass)      ,nt_pwd, 16) != 0)
-       {
-               status = NT_STATUS_WRONG_PASSWORD;
        }
 
-       return status;
-}
-
-/*************************************************************************
- net_login_network:
- *************************************************************************/
-
-static uint32 net_login_network(NET_ID_INFO_2 *id2, SAM_ACCOUNT *sampass)
-{
-       BYTE    *nt_pwd, *lanman_pwd;
-       
-       DEBUG(5,("net_login_network: lm_len: %d nt_len: %d\n",
-               id2->hdr_lm_chal_resp.str_str_len, 
-               id2->hdr_nt_chal_resp.str_str_len));
-
-       /* JRA. Check the NT password first if it exists - this is a higher quality 
-           password, if it exists and it doesn't match - fail. */
-
-       nt_pwd     = pdb_get_nt_passwd     (sampass); 
-       lanman_pwd = pdb_get_lanman_passwd (sampass);
-       if (id2->hdr_nt_chal_resp.str_str_len == 24 && 
-               nt_pwd != NULL)
-       {
-               if(smb_password_check((char *)id2->nt_chal_resp.buffer, nt_pwd,
-                           id2->lm_chal)) 
-                       return 0x0;
-               else
-                       return NT_STATUS_WRONG_PASSWORD;
-       }
-
-       /* lkclXXXX this is not a good place to put disabling of LM hashes in.
-          if that is to be done, first move this entire function into a
-          library routine that calls the two smb_password_check() functions.
-          if disabling LM hashes (which nt can do for security reasons) then
-          an attempt should be made to disable them everywhere (which nt does
-          not do, for various security-hole reasons).
-        */
-
-       if (id2->hdr_lm_chal_resp.str_str_len == 24 &&
-               smb_password_check((char *)id2->lm_chal_resp.buffer,
-                                  lanman_pwd, id2->lm_chal))
-       {
-               return 0x0;
-       }
-
-
-       /* oops! neither password check succeeded */
-
-       return NT_STATUS_WRONG_PASSWORD;
+       return True;
 }
 
 /*************************************************************************
@@ -643,284 +157,94 @@ static uint32 net_login_network(NET_ID_INFO_2 *id2, SAM_ACCOUNT *sampass)
 
 static BOOL api_net_sam_logon(pipes_struct *p)
 {
-    uint16 vuid = p->vuid;
-    NET_Q_SAM_LOGON q_l;
-    NET_ID_INFO_CTR ctr;       
-    NET_USER_INFO_3 usr_info;
-    uint32 status = 0x0;
-    DOM_CRED srv_cred;
-    SAM_ACCOUNT *sampass = NULL;
-    uint16 acct_ctrl;
-    UNISTR2 *uni_samlogon_user = NULL;
-    fstring nt_username;
-    prs_struct *data = &p->in_data.data;
-    prs_struct *rdata = &p->out_data.rdata;
-    user_struct *vuser = NULL;
-    
-    if ((vuser = get_valid_user_struct(vuid)) == NULL)
-        return False;
-    
-    ZERO_STRUCT(q_l);
-    ZERO_STRUCT(ctr);
-    ZERO_STRUCT(usr_info);
-    
-    q_l.sam_id.ctr = &ctr;
+       NET_Q_SAM_LOGON q_u;
+       NET_R_SAM_LOGON r_u;
+       prs_struct *data = &p->in_data.data;
+       prs_struct *rdata = &p->out_data.rdata;
     
-    if(!net_io_q_sam_logon("", &q_l, data, 0)) {
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
+
+    if(!net_io_q_sam_logon("", &q_u, data, 0)) {
         DEBUG(0, ("api_net_sam_logon: Failed to unmarshall NET_Q_SAM_LOGON.\n"));
         return False;
     }
-    
-    /* checks and updates credentials.  creates reply credentials */
-    if (!deal_with_creds(vuser->dc.sess_key, &vuser->dc.clnt_cred, &q_l.sam_id.client.cred, &srv_cred))
-        status = NT_STATUS_INVALID_HANDLE;
-    else
-        memcpy(&vuser->dc.srv_cred, &vuser->dc.clnt_cred, sizeof(vuser->dc.clnt_cred));
-    
-    /* find the username */
-    
-    if (status == 0) {
-        switch (q_l.sam_id.logon_level) {
-        case INTERACTIVE_LOGON_TYPE:
-            uni_samlogon_user = &q_l.sam_id.ctr->auth.id1.uni_user_name;
-            
-            DEBUG(3,("SAM Logon (Interactive). Domain:[%s].  ", lp_workgroup()));
-            break;
-        case NET_LOGON_TYPE:
-            uni_samlogon_user = &q_l.sam_id.ctr->auth.id2.uni_user_name;
-            
-            DEBUG(3,("SAM Logon (Network). Domain:[%s].  ", lp_workgroup()));
-            break;
-        default:
-            DEBUG(2,("SAM Logon: unsupported switch value\n"));
-            status = NT_STATUS_INVALID_INFO_CLASS;
-            break;
-        } /* end switch */
-    } /* end if status == 0 */
-
-  /* check username exists */
-
-    if (status == 0) 
-    {
-        pstrcpy(nt_username, dos_unistrn2(uni_samlogon_user->buffer,
-                                          uni_samlogon_user->uni_str_len));
-
-        DEBUG(3,("User:[%s]\n", nt_username));
-        
-        /*
-         * Convert to a UNIX username.
-         */
-        map_username(nt_username);
-        
-       /* get the account information */
-        become_root();
-        sampass = pdb_getsampwnam(nt_username);
-        unbecome_root();
-        
-       acct_ctrl = pdb_get_acct_ctrl(sampass);
-       if (sampass == NULL)
-            status = NT_STATUS_NO_SUCH_USER;
-       else if (acct_ctrl & ACB_PWNOTREQ)
-            status = 0;
-        else if (acct_ctrl & ACB_DISABLED)
-            status =  NT_STATUS_ACCOUNT_DISABLED;
-    }
-    
-    /* Validate password - if required. */
-    
-    if ((status == 0) && !(acct_ctrl & ACB_PWNOTREQ)) {
-        switch (q_l.sam_id.logon_level) {
-        case INTERACTIVE_LOGON_TYPE:
-            /* interactive login. */
-            status = net_login_interactive(&q_l.sam_id.ctr->auth.id1, 
-                                           sampass, vuser);
-            break;
-        case NET_LOGON_TYPE:
-            /* network login.  lm challenge and 24 byte responses */
-            status = net_login_network(&q_l.sam_id.ctr->auth.id2, sampass);
-            break;
-        }
-    }
-
-    /* lkclXXXX this is the point at which, if the login was
-       successful, that the SAM Local Security Authority should
-       record that the user is logged in to the domain.
-    */
-    
-    /* return the profile plus other bits :-) */
-    
-    if (status == 0) {
-        DOM_GID *gids = NULL;
-        int num_gids = 0;
-        pstring my_name;
-        pstring my_workgroup;
-        pstring domain_groups;
-       
-        /* set up pointer indicating user/password failed to be found */
-        usr_info.ptr_user_info = 0;
-                
-        /* XXXX hack to get standard_sub_basic() to use sam logon username */
-        /* possibly a better way would be to do a become_user() call */
-       
-       /*
-        * All this information should be filled in from the 
-        * passdb information
-        */
-        sam_logon_in_ssb = True;
-        pstrcpy(samlogon_user, nt_username);
-
-#if 0
-       gid = pdb_get_gid(sampass);
-       
-        pstrcpy(str, pdb_get_logon_script(sampass));
-        standard_sub_advanced(-1, nt_username, "", gid, str);
-       pdb_set_logon_script(sampass, str);
-       
-        pstrcpy(str, pdb_get_profile_path(sampass));
-        standard_sub_advanced(-1, nt_username, "", gid, str);
-       pdb_set_profile_path(sampass, str);
-               
-        pstrcpy(str, pdb_get_homedir(sampass));
-        standard_sub_advanced(-1, nt_username, "", gid, str);
-       pdb_set_homedir(sampass, str);
-        
-       fstrcpy(full_name, "<Full Name>");
-       if (lp_unix_realname())
-               fstrcpy(full_name, pdb_get_fullname(sampass));
-#endif
-
-        pstrcpy(my_workgroup, lp_workgroup());
-        pstrcpy(my_name, global_myname);
-        strupper(my_name);
-
-        
-        /*
-         * This is the point at which we get the group
-         * database - we should be getting the gid_t list
-         * from /etc/group and then turning the uids into
-         * rids and then into machine sids for this user.
-         * JRA.
-         */
-        
-        get_domain_user_groups(domain_groups, nt_username);
-        
-        /*
-         * make_dom_gids allocates the gids array. JRA.
-         */
-        gids = NULL;
-        num_gids = make_dom_gids(domain_groups, &gids);
-        
-        sam_logon_in_ssb = False;
-        
-       /* 
-        * This next call is where the 'domain admin users' parameter
-        * gets mapped.  I'm leaving it out for now.  The user and group rid
-        * has already been mapped into the SAM_ACCOUNT struct.  I don't
-        * think this should be overridden here.  The correct solution
-        * is proper group memberships and mapping.       --jerry
-        */
-#if 0
-        if (pdb_name_to_rid(nt_username, &r_uid, &r_gid))
-#endif
-        init_net_user_info3(&usr_info, sampass,                                
-                                0, /* logon_count */
-                                0, /* bad_pw_count */
-                                num_gids,    /* uint32 num_groups */
-                                gids    , /* DOM_GID *gids */
-                                0x20    , /* uint32 user_flgs (?) */
-                                NULL, /* char sess_key[16] */
-                                my_name     , /* char *logon_srv */
-                                my_workgroup, /* char *logon_dom */
-                                &global_sam_sid,     /* DOM_SID *dom_sid */
-                                NULL); /* char *other_sids */
-
-#if 0
-        else
-            status = NT_STATUS_NO_SUCH_USER;
-#endif
-        
-        /* Free any allocated groups array. */
-        if(gids)
-            free((char *)gids);
-    }
-    
-    if(!net_reply_sam_logon(&q_l, rdata, &srv_cred, &usr_info, status)) {
-               free_user_info3(&usr_info);
-        return False;
-       }
+   
+       r_u.status = _net_sam_logon(p, &q_u, &r_u);
 
-       free_user_info3(&usr_info); 
+       /* store the response in the SMB stream */
+       if(!net_io_r_sam_logon("", &r_u, rdata, 0)) {
+               DEBUG(0,("api_net_sam_logon: Failed to marshall NET_R_SAM_LOGON.\n"));
+               return False;
+       }
 
     return True;
 }
 
-
 /*************************************************************************
  api_net_trust_dom_list:
  *************************************************************************/
 
 static BOOL api_net_trust_dom_list(pipes_struct *p)
 {
-       NET_Q_TRUST_DOM_LIST q_t;
+       NET_Q_TRUST_DOM_LIST q_u;
+       NET_R_TRUST_DOM_LIST r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
-       char *trusted_domain = "test_domain";
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
        DEBUG(6,("api_net_trust_dom_list: %d\n", __LINE__));
 
        /* grab the lsa trusted domain list query... */
-       if(!net_io_q_trust_dom("", &q_t, data, 0)) {
+       if(!net_io_q_trust_dom("", &q_u, data, 0)) {
                DEBUG(0,("api_net_trust_dom_list: Failed to unmarshall NET_Q_TRUST_DOM_LIST.\n"));
                return False;
        }
 
        /* construct reply. */
-       if(!net_reply_trust_dom_list(&q_t, rdata, 1, trusted_domain))
+       r_u.status = _net_trust_dom_list(p, &q_u, &r_u);
+
+       /* store the response in the SMB stream */
+       if(!net_io_r_trust_dom("", &r_u, rdata, 0)) {
+               DEBUG(0,("net_reply_trust_dom_list: Failed to marshall NET_R_TRUST_DOM_LIST.\n"));
                return False;
+       }
 
        DEBUG(6,("api_net_trust_dom_list: %d\n", __LINE__));
 
        return True;
 }
 
-
-/*************************************************************************
- error messages cropping up when using nltest.exe...
- *************************************************************************/
-#define ERROR_NO_SUCH_DOMAIN   0x54b
-#define ERROR_NO_LOGON_SERVERS 0x51f
-
 /*************************************************************************
  api_net_logon_ctrl2:
  *************************************************************************/
 
 static BOOL api_net_logon_ctrl2(pipes_struct *p)
 {
-       NET_Q_LOGON_CTRL2 q_l;
+       NET_Q_LOGON_CTRL2 q_u;
+       NET_R_LOGON_CTRL2 r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
-       /* lkclXXXX - guess what - absolutely no idea what these are! */
-       uint32 flags = 0x0;
-       uint32 pdc_connection_status = 0x0;
-       uint32 logon_attempts = 0x0;
-       uint32 tc_status = ERROR_NO_LOGON_SERVERS;
-       char *trusted_domain = "test_domain";
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
        DEBUG(6,("api_net_logon_ctrl2: %d\n", __LINE__));
 
        /* grab the lsa netlogon ctrl2 query... */
-       if(!net_io_q_logon_ctrl2("", &q_l, data, 0)) {
+       if(!net_io_q_logon_ctrl2("", &q_u, data, 0)) {
                DEBUG(0,("api_net_logon_ctrl2: Failed to unmarshall NET_Q_LOGON_CTRL2.\n"));
                return False;
        }
 
-       /* construct reply. */
-       if(!net_reply_logon_ctrl2(&q_l, rdata,
-                               flags, pdc_connection_status, logon_attempts,
-                               tc_status, trusted_domain))
+       r_u.status = _net_logon_ctrl2(p, &q_u, &r_u);
+
+       if(!net_io_r_logon_ctrl2("", &r_u, rdata, 0)) {
+               DEBUG(0,("net_reply_logon_ctrl2: Failed to marshall NET_R_LOGON_CTRL2.\n"));
                return False;
+       }
 
        DEBUG(6,("api_net_logon_ctrl2: %d\n", __LINE__));
 
@@ -950,4 +274,3 @@ BOOL api_netlog_rpc(pipes_struct *p)
 {
        return api_rpcTNP(p, "api_netlog_rpc", api_net_cmds);
 }
-#undef OLD_NTDOMAIN
index 151c72499a6868522825be44348fe17b31e5e40b..613f8f54b2cac9c876184fb9a6e2c27b25f2c569 100644 (file)
@@ -129,7 +129,8 @@ static void init_net_r_srv_pwset(NET_R_SRV_PWSET *r_s,
 
 static BOOL get_md4pw(char *md4pw, char *mach_acct)
 {
-       struct smb_passwd *smb_pass;
+       SAM_ACCOUNT *sampass = NULL;
+       BYTE *pass;
 
 #if 0
     /*
@@ -150,17 +151,18 @@ static BOOL get_md4pw(char *md4pw, char *mach_acct)
 #endif /* 0 */
 
        become_root();
-       smb_pass = getsmbpwnam(mach_acct);
+       sampass = pdb_getsampwnam(mach_acct);
        unbecome_root();
-
-       if ((smb_pass) != NULL && !(smb_pass->acct_ctrl & ACB_DISABLED) &&
-        (smb_pass->smb_nt_passwd != NULL))
+       if ((sampass) != NULL && !(pdb_get_acct_ctrl(sampass) & ACB_DISABLED) &&
+               ((pass=pdb_get_nt_passwd(sampass)) != NULL))
        {
-               memcpy(md4pw, smb_pass->smb_nt_passwd, 16);
+               memcpy(md4pw, pass, 16);
                dump_data(5, md4pw, 16);
-
                return True;
        }
+
        DEBUG(0,("get_md4pw: Workstation %s: no account in domain\n", mach_acct));
        return False;
 }
@@ -256,11 +258,11 @@ uint32 _net_auth_2(pipes_struct *p, NET_Q_AUTH_2 *q_u, NET_R_AUTH_2 *r_u)
 uint32 _net_srv_pwset(pipes_struct *p, NET_Q_SRV_PWSET *q_u, NET_R_SRV_PWSET *r_u)
 {
        uint16 vuid = p->vuid;
-       uint32 status = NT_STATUS_NOPROBLEMO;
+       uint32 status = NT_STATUS_WRONG_PASSWORD;
        DOM_CRED srv_cred;
        pstring mach_acct;
-       struct smb_passwd *smb_pass;
-       BOOL ret;
+       SAM_ACCOUNT *sampass;
+       BOOL ret = False;
        user_struct *vuser;
        unsigned char pwd[16];
        int i;
@@ -282,10 +284,10 @@ uint32 _net_srv_pwset(pipes_struct *p, NET_Q_SRV_PWSET *q_u, NET_R_SRV_PWSET *r_
        DEBUG(3,("Server Password Set Wksta:[%s]\n", mach_acct));
 
        become_root();
-       smb_pass = getsmbpwnam(mach_acct);
+       sampass = pdb_getsampwnam(mach_acct);
        unbecome_root();
 
-       if (smb_pass == NULL)
+       if (sampass == NULL)
                return NT_STATUS_NO_SUCH_USER;
 
        DEBUG(100,("Server password set : new given value was :\n"));
@@ -296,16 +298,16 @@ uint32 _net_srv_pwset(pipes_struct *p, NET_Q_SRV_PWSET *q_u, NET_R_SRV_PWSET *r_
        cred_hash3( pwd, q_u->pwd, vuser->dc.sess_key, 0);
 
        /* lies!  nt and lm passwords are _not_ the same: don't care */
-       smb_pass->smb_passwd    = pwd;
-       smb_pass->smb_nt_passwd = pwd;
-       smb_pass->acct_ctrl     = ACB_WSTRUST;
-
+       pdb_set_lanman_passwd (sampass, pwd);
+       pdb_set_nt_passwd     (sampass, pwd);
+       pdb_set_acct_ctrl     (sampass, ACB_WSTRUST);
        become_root();
-       ret = mod_smbpwd_entry(smb_pass,False);
+       ret = pdb_update_sam_account (sampass,False);
        unbecome_root();
-
-       if (!ret)
-               status = NT_STATUS_WRONG_PASSWORD;
+       if (ret)
+               status = NT_STATUS_NOPROBLEMO;
 
        /* set up the LSA Server Password Set response */
        init_net_r_srv_pwset(r_u, &srv_cred, status);
@@ -347,7 +349,7 @@ uint32 _net_sam_logoff(pipes_struct *p, NET_Q_SAM_LOGOFF *q_u, NET_R_SAM_LOGOFF
  net_login_interactive:
  *************************************************************************/
 
-static uint32 net_login_interactive(NET_ID_INFO_1 *id1, struct smb_passwd *smb_pass, user_struct *vuser)
+static uint32 net_login_interactive(NET_ID_INFO_1 *id1, SAM_ACCOUNT *sampass, user_struct *vuser)
 {
        uint32 status = 0x0;
 
@@ -383,9 +385,8 @@ static uint32 net_login_interactive(NET_ID_INFO_1 *id1, struct smb_passwd *smb_p
        dump_data(100, nt_pwd, 16);
 #endif
 
-       if (memcmp(smb_pass->smb_passwd   , lm_pwd, 16) != 0 ||
-           memcmp(smb_pass->smb_nt_passwd, nt_pwd, 16) != 0)
-       {
+       if (memcmp(pdb_get_lanman_passwd(sampass), lm_pwd, 16) != 0 ||
+           memcmp(pdb_get_nt_passwd(sampass), nt_pwd, 16) != 0) {
                status = NT_STATUS_WRONG_PASSWORD;
        }
 
@@ -396,8 +397,10 @@ static uint32 net_login_interactive(NET_ID_INFO_1 *id1, struct smb_passwd *smb_p
  _net_login_network:
  *************************************************************************/
 
-static uint32 net_login_network(NET_ID_INFO_2 *id2, struct smb_passwd *smb_pass)
+static uint32 net_login_network(NET_ID_INFO_2 *id2, SAM_ACCOUNT *sampass)
 {
+       BYTE    *nt_pwd, *lanman_pwd;
+
        DEBUG(5,("net_login_network: lm_len: %d nt_len: %d\n",
                id2->hdr_lm_chal_resp.str_str_len, 
                id2->hdr_nt_chal_resp.str_str_len));
@@ -405,13 +408,13 @@ static uint32 net_login_network(NET_ID_INFO_2 *id2, struct smb_passwd *smb_pass)
        /* JRA. Check the NT password first if it exists - this is a higher quality 
            password, if it exists and it doesn't match - fail. */
 
-       if (id2->hdr_nt_chal_resp.str_str_len == 24 && 
-               smb_pass->smb_nt_passwd != NULL)
-       {
+       nt_pwd = pdb_get_nt_passwd(sampass);
+       lanman_pwd = pdb_get_lanman_passwd(sampass);
+
+       if (id2->hdr_nt_chal_resp.str_str_len == 24 && nt_pwd) {
                if(smb_password_check((char *)id2->nt_chal_resp.buffer,
-                                  smb_pass->smb_nt_passwd,
-                           id2->lm_chal)) 
-                       return 0x0;
+                                  nt_pwd, id2->lm_chal)) 
+                       return NT_STATUS_NOPROBLEMO;
                else
                        return NT_STATUS_WRONG_PASSWORD;
        }
@@ -424,14 +427,10 @@ static uint32 net_login_network(NET_ID_INFO_2 *id2, struct smb_passwd *smb_pass)
           not do, for various security-hole reasons).
         */
 
-       if (id2->hdr_lm_chal_resp.str_str_len == 24 &&
+       if (id2->hdr_lm_chal_resp.str_str_len == 24 && lanman_pwd &&
                smb_password_check((char *)id2->lm_chal_resp.buffer,
-                                  smb_pass->smb_passwd,
-                                  id2->lm_chal))
-       {
-               return 0x0;
-       }
-
+                                  lanman_pwd, id2->lm_chal))
+               return NT_STATUS_NOPROBLEMO;
 
        /* oops! neither password check succeeded */
 
@@ -448,11 +447,10 @@ uint32 _net_sam_logon(pipes_struct *p, NET_Q_SAM_LOGON *q_u, NET_R_SAM_LOGON *r_
     uint16 vuid = p->vuid;
     NET_USER_INFO_3 *usr_info = NULL;
     DOM_CRED srv_cred;
-    struct smb_passwd *smb_pass = NULL;
-    struct sam_passwd *sam_pass = NULL;
+    SAM_ACCOUNT *sampass = NULL;
+       uint16 acct_ctrl;
     UNISTR2 *uni_samlogon_user = NULL;
     fstring nt_username;
-    struct passwd *pw;
     user_struct *vuser = NULL;
    
        usr_info = (NET_USER_INFO_3 *)talloc(p->mem_ctx, sizeof(NET_USER_INFO_3));
@@ -499,33 +497,30 @@ uint32 _net_sam_logon(pipes_struct *p, NET_Q_SAM_LOGON *q_u, NET_R_SAM_LOGON *r_
 
        map_username(nt_username);
 
-       /*
-        * Do any case conversions.
-        */
-
-       pw=Get_Pwnam(nt_username, True);
-        
+       /* get the account information */
        become_root();
-       sam_pass = getsam21pwnam(nt_username);
-       smb_pass = getsmbpwnam(nt_username);
+       sampass = pdb_getsampwnam(nt_username);
        unbecome_root();
-        
-       if (smb_pass == NULL)
+
+       if (sampass == NULL)
                return NT_STATUS_NO_SUCH_USER;
-       else if (smb_pass->acct_ctrl & ACB_DISABLED)
+
+       acct_ctrl = pdb_get_acct_ctrl(sampass);
+
+       if (acct_ctrl & ACB_DISABLED)
                return NT_STATUS_ACCOUNT_DISABLED;
     
        /* Validate password - if required. */
     
-       if (!(smb_pass->acct_ctrl & ACB_PWNOTREQ)) {
+       if (!(acct_ctrl & ACB_PWNOTREQ)) {
                switch (q_u->sam_id.logon_level) {
                case INTERACTIVE_LOGON_TYPE:
                        /* interactive login. */
-                       status = net_login_interactive(&q_u->sam_id.ctr->auth.id1, smb_pass, vuser);
+                       status = net_login_interactive(&q_u->sam_id.ctr->auth.id1, sampass, vuser);
                        break;
                case NET_LOGON_TYPE:
                        /* network login.  lm challenge and 24 byte responses */
-                       status = net_login_network(&q_u->sam_id.ctr->auth.id2, smb_pass);
+                       status = net_login_network(&q_u->sam_id.ctr->auth.id2, sampass);
                        break;
                }
        }
@@ -538,58 +533,25 @@ uint32 _net_sam_logon(pipes_struct *p, NET_Q_SAM_LOGON *q_u, NET_R_SAM_LOGON *r_
                record that the user is logged in to the domain.
        */
     
-       /* return the profile plus other bits :-) */
-    
        {
                DOM_GID *gids = NULL;
                int num_gids = 0;
-               NTTIME dummy_time;
-               pstring logon_script;
-               pstring profile_path;
-               pstring home_dir;
-               pstring home_drive;
                pstring my_name;
                pstring my_workgroup;
                pstring domain_groups;
-               uint32 r_uid;
-               uint32 r_gid;
-               fstring full_name;
        
                /* set up pointer indicating user/password failed to be found */
                usr_info->ptr_user_info = 0;
         
-               dummy_time.low  = 0xffffffff;
-               dummy_time.high = 0x7fffffff;
-        
                /* XXXX hack to get standard_sub_basic() to use sam logon username */
                /* possibly a better way would be to do a become_user() call */
                sam_logon_in_ssb = True;
                pstrcpy(samlogon_user, nt_username);
 
-               pstrcpy(logon_script, sam_pass->logon_script);
-               standard_sub_advanced(-1, nt_username, "", pw->pw_gid, logon_script);
-       
-               pstrcpy(profile_path, sam_pass->profile_path);
-               standard_sub_advanced(-1, nt_username, "", pw->pw_gid, profile_path);
-        
                pstrcpy(my_workgroup, lp_workgroup());
-        
-               pstrcpy(home_drive, sam_pass->dir_drive);
-               standard_sub_advanced(-1, nt_username, "", pw->pw_gid, home_drive);
-
-               pstrcpy(home_dir, sam_pass->home_dir);
-               standard_sub_advanced(-1, nt_username, "", pw->pw_gid, home_dir);
-        
                pstrcpy(my_name, global_myname);
                strupper(my_name);
 
-               pstrcpy(full_name, sam_pass->full_name );
-               if( !*full_name ) {
-                       fstrcpy(full_name, "<Full Name>");
-                       if (lp_unix_realname())
-                               fstrcpy(full_name, strtok(pw->pw_gecos, ","));
-               }
-        
                /*
                 * This is the point at which we get the group
                 * database - we should be getting the gid_t list
@@ -608,41 +570,17 @@ uint32 _net_sam_logon(pipes_struct *p, NET_Q_SAM_LOGON *q_u, NET_R_SAM_LOGON *r_
         
                sam_logon_in_ssb = False;
         
-               if (pdb_name_to_rid(nt_username, &r_uid, &r_gid))
-                       init_net_user_info3(p->mem_ctx, usr_info,
-                                                               &dummy_time, /* logon_time */
-                                                               &dummy_time, /* logoff_time */
-                                                               &dummy_time, /* kickoff_time */
-                                                               &dummy_time, /* pass_last_set_time */
-                                                               &dummy_time, /* pass_can_change_time */
-                                                               &dummy_time, /* pass_must_change_time */
-                                
-                                                               nt_username , /* user_name */
-                                                               full_name,      /* full_name */
-                                                               logon_script    , /* logon_script */
-                                                               profile_path    , /* profile_path */
-                                                               home_dir        , /* home_dir */
-                                                               home_drive      , /* dir_drive */
-                                
-                                                               0, /* logon_count */
-                                                               0, /* bad_pw_count */
-                                
-                                                               r_uid   , /* RID user_id */
-                                                               r_gid   , /* RID group_id */
-                                                               num_gids,    /* uint32 num_groups */
-                                                               gids    , /* DOM_GID *gids */
-                                                               0x20    , /* uint32 user_flgs (?) */
-                                
-                                                               NULL, /* char sess_key[16] */
-                                
-                                                               my_name     , /* char *logon_srv */
-                                                               my_workgroup, /* char *logon_dom */
-                                
-                                                               &global_sam_sid,     /* DOM_SID *dom_sid */
-                                                               NULL); /* char *other_sids */
-        else
-                       return NT_STATUS_NO_SUCH_USER;
-        
+        init_net_user_info3(p->mem_ctx, usr_info, sampass,
+                            0, /* logon_count */
+                            0, /* bad_pw_count */
+                            num_gids,    /* uint32 num_groups */
+                            gids    , /* DOM_GID *gids */
+                            0x20    , /* uint32 user_flgs (?) */
+                            NULL, /* char sess_key[16] */
+                            my_name     , /* char *logon_srv */
+                            my_workgroup, /* char *logon_dom */
+                            &global_sam_sid,     /* DOM_SID *dom_sid */
+                            NULL); /* char *other_sids */
     }
 
        /* XXXX maybe we want to say 'no', reject the client's credentials */
index dcefeed8b9711a8c527a4e59e200bb402b94783b..bc5b2ab473b057d805ea05e48d8073caf8bbf644 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
  *  Unix SMB/Netbios implementation.
  *  Version 1.9.
@@ -270,9 +269,9 @@ static BOOL api_pipe_ntlmssp_verify(pipes_struct *p, RPC_AUTH_NTLMSSP_RESP *ntlm
        fstring domain;
        fstring wks;
        BOOL guest_user = False;
-       SAM_ACCOUNT *sam_pass = NULL;
-       BYTE null_smb_passwd[16];
-       BYTE *smb_passwd_ptr = NULL;
+       SAM_ACCOUNT *sampass = NULL;
+       uchar null_smb_passwd[16];
+       uchar *smb_passwd_ptr = NULL;
        
        DEBUG(5,("api_pipe_ntlmssp_verify: checking user details\n"));
 
@@ -358,18 +357,6 @@ static BOOL api_pipe_ntlmssp_verify(pipes_struct *p, RPC_AUTH_NTLMSSP_RESP *ntlm
                        return False;
 
        }
-/* unnecessary as the passdb validates the user before returning   --jerry */
-#if 0  
-       /*
-        * Find the user in the unix password db.
-        */
-
-       if(!(pass = Get_Pwnam(pipe_user_name,True))) {
-               DEBUG(1,("Couldn't find user '%s' in UNIX password database.\n",pipe_user_name));
-               return(False);
-       }
-
-#endif /* 0 */
 
        if(!guest_user) {
 
@@ -383,8 +370,8 @@ failed authentication on named pipe %s.\n", domain, pipe_user_name, wks, p->name
                        return False;
                }
 
-               if(!(sam_pass = pdb_getsampwnam(pipe_user_name))) {
-                       DEBUG(1,("api_pipe_ntlmssp_verify: Cannot find user %s in passdb.\n",
+               if(!(sampass = pdb_getsampwnam(pipe_user_name))) {
+                       DEBUG(1,("api_pipe_ntlmssp_verify: Cannot find user %s in smb passwd database.\n",
                                pipe_user_name));
                        unbecome_root();
                        return False;
@@ -392,24 +379,18 @@ failed authentication on named pipe %s.\n", domain, pipe_user_name, wks, p->name
 
                unbecome_root();
 
-               if (sam_pass == NULL) {
-                       DEBUG(1,("api_pipe_ntlmssp_verify: Couldn't find user '%s' in passdb.\n", 
-                               pipe_user_name));
-                       return(False);
-               }
-
-               /* Quit if the account was disabled. */
-               if((pdb_get_acct_ctrl(sam_pass) & ACB_DISABLED) || !pdb_get_lanman_passwd(sam_pass)) {
-                       DEBUG(1,("Account for user '%s' was disabled.\n", pipe_user_name));
-                       return(False);
-               }
-
-               if(!pdb_get_nt_passwd(sam_pass)) {
-                       DEBUG(1,("Account for user '%s' has no NT password hash.\n", pipe_user_name));
-                       return(False);
-               }
-
-               smb_passwd_ptr = pdb_get_lanman_passwd(sam_pass);
+        /* Quit if the account was disabled. */
+        if((pdb_get_acct_ctrl(sampass) & ACB_DISABLED) || !pdb_get_lanman_passwd(sampass)) {
+            DEBUG(1,("Account for user '%s' was disabled.\n", pipe_user_name));
+            return(False);
+        }
+        if(!pdb_get_nt_passwd(sampass)) {
+            DEBUG(1,("Account for user '%s' has no NT password hash.\n", pipe_user_name));
+            return(False);
+        }
+        smb_passwd_ptr = pdb_get_lanman_passwd(sampass);
        }
 
        /*
@@ -459,18 +440,18 @@ failed authentication on named pipe %s.\n", domain, pipe_user_name, wks, p->name
        /*
         * Store the UNIX credential data (uid/gid pair) in the pipe structure.
         */
-       p->pipe_user.uid = pdb_get_uid(sam_pass);
-       p->pipe_user.gid = pdb_get_gid(sam_pass);
+
+       p->pipe_user.uid = pdb_get_uid(sampass);
+       p->pipe_user.gid = pdb_get_uid(sampass);
 
        /* Set up pipe user group membership. */
        initialise_groups(pipe_user_name, p->pipe_user.uid, p->pipe_user.gid);
        get_current_groups( &p->pipe_user.ngroups, &p->pipe_user.groups);
 
        /* Create an NT_USER_TOKEN struct for this user. */
-       p->pipe_user.nt_user_token = 
-               create_nt_token(p->pipe_user.uid,p->pipe_user.gid, 
-                               p->pipe_user.ngroups, p->pipe_user.groups, 
-                               guest_user);
+       p->pipe_user.nt_user_token = create_nt_token(p->pipe_user.uid,p->pipe_user.gid,
+                                               p->pipe_user.ngroups, p->pipe_user.groups,
+                                               guest_user);
 
        p->ntlmssp_auth_validated = True;
        return True;
@@ -1148,7 +1129,9 @@ BOOL api_pipe_request(pipes_struct *p)
                if (strequal(api_fd_commands[i].pipe_clnt_name, p->name) &&
                    api_fd_commands[i].fn != NULL) {
                        DEBUG(3,("Doing \\PIPE\\%s\n", api_fd_commands[i].pipe_clnt_name));
+                       set_current_rpc_talloc(p->mem_ctx);
                        ret = api_fd_commands[i].fn(p);
+                       set_current_rpc_talloc(NULL);
                }
        }
 
@@ -1222,7 +1205,7 @@ BOOL api_rpcTNP(pipes_struct *p, char *rpc_name,
 
                DEBUG(10, ("api_rpcTNP: rpc input buffer underflow (parse error?)\n"));
                if (data) {
-                       prs_uint8s(False, "", &p->in_data.data, 0, data,
+                       prs_uint8s(False, "", &p->in_data.data, 0, (unsigned char *)data,
                                   data_len);
                        free(data);
                }
@@ -1231,5 +1214,3 @@ BOOL api_rpcTNP(pipes_struct *p, char *rpc_name,
 
        return True;
 }
-
-#undef OLD_NTDOMAIN
index 554507191361837658c3eb1fba89242fc874803c..cd072122f3fb15320f8a16d4a8cf3a384c31e772 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
  *  Unix SMB/Netbios implementation.
  *  Version 1.9.
@@ -40,6 +39,20 @@ static int pipes_open;
 static pipes_struct *Pipes;
 static struct bitmap *bmap;
 
+/****************************************************************************
+ Pipe iterator functions.
+****************************************************************************/
+
+pipes_struct *get_first_pipe(void)
+{
+       return Pipes;
+}
+
+pipes_struct *get_next_pipe(pipes_struct *p)
+{
+       return p->next;
+}
+
 /* this must be larger than the sum of the open files and directories */
 static int pipe_handle_offset;
 
@@ -135,7 +148,7 @@ pipes_struct *open_rpc_pipe_p(char *pipe_name,
        next_pipe = (i+1) % MAX_OPEN_PIPES;
 
        for (p = Pipes; p; p = p->next)
-               DEBUG(5,("open pipes: name %s pnum=%x\n", p->name, p->pnum));  
+               DEBUG(5,("open_rpc_pipe_p: name %s pnum=%x\n", p->name, p->pnum));  
 
        p = (pipes_struct *)malloc(sizeof(*p));
 
@@ -150,6 +163,8 @@ pipes_struct *open_rpc_pipe_p(char *pipe_name,
                return NULL;
        }
 
+       init_pipe_handles(p);
+
        DLIST_ADD(Pipes, p);
 
        /*
@@ -379,6 +394,23 @@ static ssize_t unmarshall_rpc_header(pipes_struct *p)
        return 0; /* No extra data processed. */
 }
 
+/****************************************************************************
+ Call this to free any talloc'ed memory. Do this before and after processing
+ a complete PDU.
+****************************************************************************/
+
+void free_pipe_context(pipes_struct *p)
+{
+       if (p->mem_ctx) {
+               DEBUG(3,("free_pipe_context: destroying talloc pool of size %u\n", talloc_pool_size(p->mem_ctx) ));
+               talloc_destroy_pool(p->mem_ctx);
+       } else {
+               p->mem_ctx = talloc_init();
+               if (p->mem_ctx == NULL)
+                       p->fault_state = True;
+       }
+}
+
 /****************************************************************************
  Processes a request pdu. This will do auth processing if needed, and
  appends the data into the complete stream if the LAST flag is not set.
@@ -487,9 +519,13 @@ authentication failed. Denying the request.\n", p->name));
                 * Process the complete data stream here.
                 */
 
+               free_pipe_context(p);
+
                if(pipe_init_outgoing_data(p))
                        ret = api_pipe_request(p);
 
+               free_pipe_context(p);
+
                /*
                 * We have consumed the whole data stream. Set back to
                 * marshalling and set the offset back to the start of
@@ -780,23 +816,6 @@ returning %d bytes.\n", p->name, (unsigned int)p->out_data.current_pdu_len,
 
   out:
 
-       if(p->out_data.data_sent_length >= prs_offset(&p->out_data.rdata)) {
-               /*
-                * We have copied all possible data into the current_pdu. This RPC is finished.
-                * Reset the talloc context to free any allocated data from this RPC.
-                */
-
-               if (p->mem_ctx) {
-                       DEBUG(3,("read_from_pipe: destroying talloc pool of size %u\n", talloc_pool_size(p->mem_ctx) ));
-                       talloc_destroy_pool(p->mem_ctx);
-               } else {
-                       p->mem_ctx = talloc_init();
-                       if (p->mem_ctx == NULL)
-                               p->fault_state = True;
-               }
-
-       }
-
        return data_returned;
 }
 
@@ -865,6 +884,9 @@ BOOL close_rpc_pipe_hnd(pipes_struct *p, connection_struct *conn)
        if (p->mem_ctx)
                talloc_destroy(p->mem_ctx);
 
+       /* Free the handles database. */
+       close_policy_by_pipe(p);
+
        bitmap_clear(bmap, p->pnum - pipe_handle_offset);
 
        pipes_open--;
@@ -921,4 +943,3 @@ pipes_struct *get_rpc_pipe(int pnum)
 
        return NULL;
 }
-#undef OLD_NTDOMAIN
index 1ca9963cd4e087056d97f5a07ae4126abb1206aa..65f0e2304c8417f4f5619a5ee1467a1abe525121 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
  *  Unix SMB/Netbios implementation.
  *  Version 1.9.
@@ -156,4 +155,3 @@ BOOL api_reg_rpc(pipes_struct *p)
 {
        return api_rpcTNP(p, "api_reg_rpc", api_reg_cmds);
 }
-#undef OLD_NTDOMAIN
index 4bd97abb6589e0e220ff84ee98b3ddadd3ebff14..4f941e3e1bd32142f461818ca02b9a0c2268ae20 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
  *  Unix SMB/Netbios implementation.
  *  Version 1.9.
 
 extern int DEBUGLEVEL;
 
+struct reg_info
+{
+    /* for use by \PIPE\winreg */
+    fstring name; /* name of registry key */
+};
+
+static void free_reg_info(void *ptr)
+{
+       struct reg_info *info = (struct reg_info *)ptr;
+
+       safe_free(info);
+}
+
 /*******************************************************************
  reg_reply_unknown_1
  ********************************************************************/
@@ -40,7 +52,7 @@ uint32 _reg_close(pipes_struct *p, REG_Q_CLOSE *q_u, REG_R_CLOSE *r_u)
        ZERO_STRUCT(r_u->pol);
 
        /* close the policy handle */
-       if (!close_lsa_policy_hnd(&q_u->pol))
+       if (!close_policy_hnd(p, &q_u->pol))
                return NT_STATUS_OBJECT_NAME_INVALID;
 
        return NT_STATUS_NOPROBLEMO;
@@ -52,7 +64,7 @@ uint32 _reg_close(pipes_struct *p, REG_Q_CLOSE *q_u, REG_R_CLOSE *r_u)
 
 uint32 _reg_open(pipes_struct *p, REG_Q_OPEN_HKLM *q_u, REG_R_OPEN_HKLM *r_u)
 {
-       if (!open_lsa_policy_hnd(&r_u->pol))
+       if (!create_policy_hnd(p, &r_u->pol, free_reg_info, NULL))
                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
 
        return NT_STATUS_NOPROBLEMO;
@@ -66,15 +78,13 @@ uint32 _reg_open_entry(pipes_struct *p, REG_Q_OPEN_ENTRY *q_u, REG_R_OPEN_ENTRY
 {
        POLICY_HND pol;
        fstring name;
+       struct reg_info *info = NULL;
 
        DEBUG(5,("reg_open_entry: %d\n", __LINE__));
 
-       if (find_lsa_policy_by_hnd(&q_u->pol) == -1)
+       if (!find_policy_by_hnd(p, &q_u->pol, NULL))
                return NT_STATUS_INVALID_HANDLE;
 
-       if (!open_lsa_policy_hnd(&pol))
-               return NT_STATUS_TOO_MANY_SECRETS; /* ha ha very droll */
-
        fstrcpy(name, dos_unistrn2(q_u->uni_name.buffer, q_u->uni_name.uni_str_len));
 
        DEBUG(5,("reg_open_entry: %s\n", name));
@@ -84,7 +94,13 @@ uint32 _reg_open_entry(pipes_struct *p, REG_Q_OPEN_ENTRY *q_u, REG_R_OPEN_ENTRY
            !strequal(name, "System\\CurrentControlSet\\services\\Netlogon\\parameters\\"))
                        return NT_STATUS_ACCESS_DENIED;
 
-       if (!set_lsa_policy_reg_name(&pol, name))
+       if ((info = (struct reg_info *)malloc(sizeof(struct reg_info))) == NULL)
+               return NT_STATUS_NO_MEMORY;
+
+       ZERO_STRUCTP(info);
+       fstrcpy(info->name, name);
+
+       if (!create_policy_hnd(p, &pol, free_reg_info, (void *)info))
                return NT_STATUS_TOO_MANY_SECRETS; /* ha ha very droll */
 
        init_reg_r_open_entry(r_u, &pol, NT_STATUS_NOPROBLEMO);
@@ -110,7 +126,7 @@ uint32 _reg_info(pipes_struct *p, REG_Q_INFO *q_u, REG_R_INFO *r_u)
 
        DEBUG(5,("_reg_info: %d\n", __LINE__));
 
-       if (find_lsa_policy_by_hnd(&q_u->pol) == -1)
+       if (find_policy_by_hnd(p, &q_u->pol, NULL) == -1)
                return NT_STATUS_INVALID_HANDLE;
 
        fstrcpy(name, dos_unistrn2(q_u->uni_type.buffer, q_u->uni_type.uni_str_len));
@@ -161,4 +177,3 @@ uint32 _reg_info(pipes_struct *p, REG_Q_INFO *q_u, REG_R_INFO *r_u)
 
        return status;
 }
-#undef OLD_NTDOMAIN
index 2f4143bd6afc8dccf0436bafa6427d7350c538c3..828e2e55959095e8670f13d59c1b5be87be2ce7f 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
  *  Unix SMB/Netbios implementation.
  *  Version 1.9.
@@ -7,6 +6,10 @@
  *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
  *  Copyright (C) Paul Ashton                       1997.
  *  Copyright (C) Hewlett-Packard Company           1999.
+ *     
+ *     Split into interface and implementation modules by, 
+ *
+ *  Copyright (C) Jeremy Allison                    2001.
  *  
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
  *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  */
 
+/*
+ * This is the interface to the SAMR code.
+ */
+
 #include "includes.h"
 
 extern int DEBUGLEVEL;
 
-extern fstring global_myworkgroup;
-extern pstring global_myname;
-extern DOM_SID global_sam_sid;
-
-extern rid_name domain_group_rids[];
-extern rid_name domain_alias_rids[];
-extern rid_name builtin_alias_rids[];
-
 /*******************************************************************
-  This next function should be replaced with something that
-  dynamically returns the correct user info..... JRA.
+ api_samr_close_hnd
  ********************************************************************/
 
-static BOOL get_sampwd_entries(SAM_USER_INFO_21 *pw_buf, int start_idx,
-                                int *total_entries, int *num_entries,
-                                int max_num_entries, uint16 acb_mask)
+static BOOL api_samr_close_hnd(pipes_struct *p)
 {
-       SAM_ACCOUNT *pwd = NULL;
-
-       (*num_entries) = 0;
-       (*total_entries) = 0;
+       SAMR_Q_CLOSE_HND q_u;
+       SAMR_R_CLOSE_HND r_u;
+       prs_struct *data = &p->in_data.data;
+       prs_struct *rdata = &p->out_data.rdata;
 
-       if (pw_buf == NULL) 
-               return False;
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       if (!pdb_setsampwent(False))
-       {
-               DEBUG(0, ("get_sampwd_entries: Unable to open passdb.\n"));
+       if(!samr_io_q_close_hnd("", &q_u, data, 0)) {
+               DEBUG(0,("api_samr_close_hnd: unable to unmarshall SAMR_Q_CLOSE_HND.\n"));
                return False;
        }
 
-       while ( ((pwd=pdb_getsampwent()) != NULL) && ((*num_entries) < max_num_entries) ) 
-       {
-               int user_name_len;
-
-               if (start_idx > 0) {
-                       /* skip the requested number of entries.
-                          not very efficient, but hey...
-                        */
-                       start_idx--;
-                       continue;
-               }
-
-               user_name_len = strlen(pdb_get_username(pwd))+1;
-               init_unistr2(&(pw_buf[(*num_entries)].uni_user_name), pdb_get_username(pwd), user_name_len);
-               init_uni_hdr(&(pw_buf[(*num_entries)].hdr_user_name), user_name_len);
-               pw_buf[(*num_entries)].user_rid = pdb_get_user_rid(pwd);
-               memset((char *)pw_buf[(*num_entries)].nt_pwd, '\0', 16);
-
-               /* Now check if the NT compatible password is available. */
-               if (pdb_get_nt_passwd(pwd) != NULL) 
-               {
-                       memcpy( pw_buf[(*num_entries)].nt_pwd , pdb_get_nt_passwd(pwd), 16);
-               }
-
-               pw_buf[(*num_entries)].acb_info = pdb_get_acct_ctrl(pwd);
-
-               DEBUG(5, ("entry idx: %d user %s, rid 0x%x, acb %x",
-                         (*num_entries), pdb_get_username(pwd),
-                         pdb_get_user_rid(pwd), pdb_get_acct_ctrl(pwd)));
-
-               if (acb_mask == 0 || (pdb_get_acct_ctrl(pwd) & acb_mask)) 
-               {
-                       DEBUG(5,(" acb_mask %x accepts\n", acb_mask));
-                       (*num_entries)++;
-               } 
-               else 
-               {
-                       DEBUG(5,(" acb_mask %x rejects\n", acb_mask));
-               }
-
-               (*total_entries)++;
-       }
-
-       pdb_endsampwent();
-
-       return (*num_entries) > 0;
-}
-
-/*******************************************************************
- This function uses the username map file and tries to map a UNIX
- user name to an DOS name.  (Sort of the reverse of the
- map_username() function.)  Since more than one DOS name can map
- to the UNIX name, to reverse the mapping you have to specify
- which corresponding DOS name you want; that's where the name_idx
- parameter comes in.  Returns the string requested or NULL if it
- fails or can't complete the request for any reason.  This doesn't
- handle group names (starting with '@') or names starting with
- '+' or '&'.  If they are encountered, they are skipped.
-********************************************************************/
-
-static char *unmap_unixname(char *unix_user_name, int name_idx)
-{
-       char *mapfile = lp_username_map();
-       char **lines;
-       static pstring tok;
-       int i;
-
-       if (!*unix_user_name) return NULL;
-       if (!*mapfile) return NULL;
-
-       lines = file_lines_load(mapfile, NULL,False);
-       if (!lines) {
-               DEBUG(0,("unmap_unixname: can't open username map %s\n", mapfile));
-               return NULL;
-       }
-
-       DEBUG(5,("unmap_unixname: scanning username map %s, index: %d\n", mapfile, name_idx));
-
-       for (i=0; lines[i]; i++) {
-               char *unixname = lines[i];
-               char *dosname = strchr(unixname,'=');
-
-               if (!dosname)
-                       continue;
-
-               *dosname++ = 0;
-
-               while (isspace(*unixname))
-                       unixname++;
-               if ('!' == *unixname) {
-                       unixname++;
-                       while (*unixname && isspace(*unixname))
-                               unixname++;
-               }
-    
-               if (!*unixname || strchr("#;",*unixname))
-                       continue;
-
-               if (strncmp(unixname, unix_user_name, strlen(unix_user_name)))
-                       continue;
-
-               /* We have matched the UNIX user name */
-
-               while(next_token(&dosname, tok, LIST_SEP, sizeof(tok))) {
-                       if (!strchr("@&+", *tok)) {
-                               name_idx--;
-                               if (name_idx < 0 ) {
-                                       break;
-                               }
-                       }
-               }
-
-               if (name_idx >= 0) {
-                       DEBUG(0,("unmap_unixname: index too high - not that many DOS names\n"));
-                       file_lines_free(lines);
-                       return NULL;
-               } else {
-                       file_lines_free(lines);
-                       return tok;
-               }
-       }
-
-       DEBUG(0,("unmap_unixname: Couldn't find the UNIX user name\n"));
-       file_lines_free(lines);
-       return NULL;
-}
-
-/*******************************************************************
- This function sets up a list of users taken from the list of
- users that UNIX knows about, as well as all the user names that
- Samba maps to a valid UNIX user name.  (This should work with
- /etc/passwd or NIS.)
-********************************************************************/
-
-static BOOL get_passwd_entries(SAM_USER_INFO_21 *pw_buf,
-                               int start_idx,
-                               int *total_entries, int *num_entries,
-                               int max_num_entries,
-                               uint16 acb_mask)
-{
-       static struct passwd *pwd = NULL;
-       static uint32 pw_rid;
-       static BOOL orig_done = False;
-       static int current_idx = 0;
-       static int mapped_idx = 0;
-       char *sep;
-
-       DEBUG(5, ("get_passwd_entries: retrieving a list of UNIX users\n"));
-
-       (*num_entries) = 0;
-       (*total_entries) = 0;
-
-       /* Skip all this stuff if we're in appliance mode */
-
-       if (lp_hide_local_users()) goto done;
-
-       if (pw_buf == NULL) return False;
-
-       if (current_idx == 0) {
-               sys_setpwent();
-       }
-
-       /* These two cases are inefficient, but should be called very rarely */
-       /* they are the cases where the starting index isn't picking up      */
-       /* where we left off last time.  It is efficient when it starts over */
-       /* at zero though.                                                   */
-       if (start_idx > current_idx) {
-               /* We aren't far enough; advance to start_idx */
-               while (current_idx < start_idx) {
-                       char *unmap_name;
-
-                       if(!orig_done) {
-                               if ((pwd = sys_getpwent()) == NULL) break;
-                               current_idx++;
-                               orig_done = True;
-                       }
-
-                       while (((unmap_name = unmap_unixname(pwd->pw_name, mapped_idx)) != NULL) && 
-                               (current_idx < start_idx)) {
-                               current_idx++;
-                               mapped_idx++;
-                       }
-
-                       if (unmap_name == NULL) {
-                               orig_done = False;
-                               mapped_idx = 0;
-                       }
-               }
-       } else if (start_idx < current_idx) {
-               /* We are already too far; start over and advance to start_idx */
-               sys_endpwent();
-               sys_setpwent();
-               current_idx = 0;
-               mapped_idx = 0;
-               orig_done = False;
-               while (current_idx < start_idx) {
-                       char *unmap_name;
-
-                       if(!orig_done) {
-                               if ((pwd = sys_getpwent()) == NULL) break;
-                               current_idx++;
-                               orig_done = True;
-                       }
-
-                       while (((unmap_name = unmap_unixname(pwd->pw_name, mapped_idx)) != NULL) && 
-                               (current_idx < start_idx)) {
-                               current_idx++;
-                               mapped_idx++;
-                       }
-
-                       if (unmap_name == NULL) {
-                               orig_done = False;
-                               mapped_idx = 0;
-                       }
-               }
-       }
-
-       sep = lp_winbind_separator();
-
-       /* now current_idx == start_idx */
-       while ((*num_entries) < max_num_entries) {
-               int user_name_len;
-               char *unmap_name;
-
-               /* This does the original UNIX user itself */
-               if(!orig_done) {
-                       if ((pwd = sys_getpwent()) == NULL) break;
-
-                       /* Don't enumerate winbind users as they are not local */
-
-                       if (strchr(pwd->pw_name, *sep) != NULL) {
-                               continue;
-                       }
-
-                       user_name_len = strlen(pwd->pw_name);
-                       pw_rid = pdb_uid_to_user_rid(pwd->pw_uid);
-                       ZERO_STRUCTP(&pw_buf[(*num_entries)]);
-                       init_unistr2(&(pw_buf[(*num_entries)].uni_user_name), pwd->pw_name, user_name_len);
-                       init_uni_hdr(&(pw_buf[(*num_entries)].hdr_user_name), user_name_len);
-                       pw_buf[(*num_entries)].user_rid = pw_rid;
-                       memset((char *)pw_buf[(*num_entries)].nt_pwd, '\0', 16);
-
-                       pw_buf[(*num_entries)].acb_info = ACB_NORMAL;
-
-                       DEBUG(5, ("get_passwd_entries: entry idx %d user %s, rid 0x%x\n", (*num_entries), pwd->pw_name, pw_rid));
-
-                       (*num_entries)++;
-                       (*total_entries)++;
-                       current_idx++;
-                       orig_done = True;
-               }
-
-               /* This does all the user names that map to the UNIX user */
-               while (((unmap_name = unmap_unixname(pwd->pw_name, mapped_idx)) != NULL) && 
-                       (*num_entries < max_num_entries)) {
-                       user_name_len = strlen(unmap_name);
-                       ZERO_STRUCTP(&pw_buf[(*num_entries)]);
-                       init_unistr2(&(pw_buf[(*num_entries)].uni_user_name), unmap_name, user_name_len);
-                       init_uni_hdr(&(pw_buf[(*num_entries)].hdr_user_name), user_name_len);
-                       pw_buf[(*num_entries)].user_rid = pw_rid;
-                       memset((char *)pw_buf[(*num_entries)].nt_pwd, '\0', 16);
-
-                       pw_buf[(*num_entries)].acb_info = ACB_NORMAL;
-
-                       DEBUG(5, ("get_passwd_entries: entry idx %d user %s, rid 0x%x\n", (*num_entries), pwd->pw_name, pw_rid));
-
-                       (*num_entries)++;
-                       (*total_entries)++;
-                       current_idx++;
-                       mapped_idx++;
-               }
-
-               if (unmap_name == NULL) {
-                       /* done with 'aliases', go on to next UNIX user */
-                       orig_done = False;
-                       mapped_idx = 0;
-               }
-       }
+       r_u.status = _samr_close_hnd(p, &q_u, &r_u);
 
-       if (pwd == NULL) {
-               /* totally done, reset everything */
-               sys_endpwent();
-               current_idx = 0;
-               mapped_idx = 0;
+       /* store the response in the SMB stream */
+       if(!samr_io_r_close_hnd("", &r_u, rdata, 0)) {
+               DEBUG(0,("api_samr_close_hnd: unable to marshall SAMR_R_CLOSE_HND.\n"));
+               return False;
        }
 
-done:
-       return (*num_entries) > 0;
+       return True;
 }
 
 /*******************************************************************
- samr_reply_unknown_1
+ api_samr_open_domain
  ********************************************************************/
-static BOOL samr_reply_close_hnd(SAMR_Q_CLOSE_HND *q_u,
-                               prs_struct *rdata)
+
+static BOOL api_samr_open_domain(pipes_struct *p)
 {
-       SAMR_R_CLOSE_HND r_u;
+       SAMR_Q_OPEN_DOMAIN q_u;
+       SAMR_R_OPEN_DOMAIN r_u;
 
-       /* set up the SAMR unknown_1 response */
-       ZERO_STRUCT(r_u.pol);
+       prs_struct *data = &p->in_data.data;
+       prs_struct *rdata = &p->out_data.rdata;
 
-       /* close the policy handle */
-       if (close_lsa_policy_hnd(&(q_u->pol)))
-       {
-               r_u.status = 0;
-       }
-       else
-       {
-               r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_INVALID;
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
+
+       if(!samr_io_q_open_domain("", &q_u, data, 0)) {
+               DEBUG(0,("api_samr_open_domain: unable to unmarshall SAMR_Q_OPEN_DOMAIN.\n"));
+               return False;
        }
 
-       DEBUG(5,("samr_reply_close_hnd: %d\n", __LINE__));
+       r_u.status = _samr_open_domain(p, &q_u, &r_u);
 
        /* store the response in the SMB stream */
-       if(!samr_io_r_close_hnd("", &r_u, rdata, 0))
+       if(!samr_io_r_open_domain("", &r_u, rdata, 0)) {
+               DEBUG(0,("api_samr_open_domain: unable to marshall SAMR_R_OPEN_DOMAIN.\n"));
                return False;
-
-       DEBUG(5,("samr_reply_close_hnd: %d\n", __LINE__));
+       }
 
        return True;
 }
 
 /*******************************************************************
- api_samr_close_hnd
+ api_samr_get_usrdom_pwinfo
  ********************************************************************/
-static BOOL api_samr_close_hnd(pipes_struct *p)
+
+static BOOL api_samr_get_usrdom_pwinfo(pipes_struct *p)
 {
-       SAMR_Q_CLOSE_HND q_u;
+       SAMR_Q_GET_USRDOM_PWINFO q_u;
+       SAMR_R_GET_USRDOM_PWINFO r_u;
+
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
-       /* grab the samr unknown 1 */
-       if(!samr_io_q_close_hnd("", &q_u, data, 0))
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
+
+       if(!samr_io_q_get_usrdom_pwinfo("", &q_u, data, 0))
                return False;
 
-       /* construct reply.  always indicate success */
-       if(!samr_reply_close_hnd(&q_u, rdata))
+       r_u.status = _samr_get_usrdom_pwinfo(p, &q_u, &r_u);
+
+       if(!samr_io_r_get_usrdom_pwinfo("", &r_u, rdata, 0))
                return False;
 
        return True;
 }
 
-
 /*******************************************************************
- samr_reply_open_domain
+ api_samr_query_sec_obj
  ********************************************************************/
-static BOOL samr_reply_open_domain(SAMR_Q_OPEN_DOMAIN *q_u,
-                               prs_struct *rdata)
-{
-       SAMR_R_OPEN_DOMAIN r_u;
-       BOOL pol_open = False;
 
-       r_u.status = 0x0;
-
-       /* find the connection policy handle. */
-       if (r_u.status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
-       {
-               r_u.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
-       }
+static BOOL api_samr_query_sec_obj(pipes_struct *p)
+{
+       SAMR_Q_QUERY_SEC_OBJ q_u;
+       SAMR_R_QUERY_SEC_OBJ r_u;
 
-       /* get a (unique) handle.  open a policy on it. */
-       if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.domain_pol))))
-       {
-               r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
-       }
+       prs_struct *data = &p->in_data.data;
+       prs_struct *rdata = &p->out_data.rdata;
 
-       /* associate the domain SID with the (unique) handle. */
-       if (r_u.status == 0x0 && !set_lsa_policy_samr_sid(&(r_u.domain_pol), &(q_u->dom_sid.sid)))
-       {
-               /* oh, whoops.  don't know what error message to return, here */
-               r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
-       }
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       if (r_u.status != 0 && pol_open)
-       {
-               close_lsa_policy_hnd(&(r_u.domain_pol));
-       }
+       if(!samr_io_q_query_sec_obj("", &q_u, data, 0))
+               return False;
 
-       DEBUG(5,("samr_open_domain: %d\n", __LINE__));
+       r_u.status = _samr_query_sec_obj(p, &q_u, &r_u);
 
-       /* store the response in the SMB stream */
-       if(!samr_io_r_open_domain("", &r_u, rdata, 0))
+       if(!samr_io_r_query_sec_obj("", &r_u, rdata, 0))
                return False;
 
-       DEBUG(5,("samr_open_domain: %d\n", __LINE__));
-
        return True;
 }
 
 /*******************************************************************
- api_samr_open_domain
+ api_samr_enum_dom_users
  ********************************************************************/
-static BOOL api_samr_open_domain(pipes_struct *p)
+
+static BOOL api_samr_enum_dom_users(pipes_struct *p)
 {
-       SAMR_Q_OPEN_DOMAIN q_u;
+       SAMR_Q_ENUM_DOM_USERS q_u;
+       SAMR_R_ENUM_DOM_USERS r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
+
        /* grab the samr open */
-       if(!samr_io_q_open_domain("", &q_u, data, 0))
+       if(!samr_io_q_enum_dom_users("", &q_u, data, 0))
                return False;
 
-       /* construct reply.  always indicate success */
-       if(!samr_reply_open_domain(&q_u, rdata))
+       r_u.status = _samr_enum_dom_users(p, &q_u, &r_u);
+
+       /* store the response in the SMB stream */
+       if(!samr_io_r_enum_dom_users("", &r_u, rdata, 0))
                return False;
 
        return True;
 }
 
-
 /*******************************************************************
- samr_reply_unknown_2c
+ api_samr_enum_dom_groups
  ********************************************************************/
-static BOOL samr_reply_unknown_2c(SAMR_Q_UNKNOWN_2C *q_u,
-                               prs_struct *rdata)
-{
-       SAMR_R_UNKNOWN_2C r_u;
-       uint32 status = 0x0;
 
-       /* find the policy handle.  open a policy on it. */
-       if (status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->user_pol)) == -1))
-       {
-               status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
-       }
+static BOOL api_samr_enum_dom_groups(pipes_struct *p)
+{
+       SAMR_Q_ENUM_DOM_GROUPS q_u;
+       SAMR_R_ENUM_DOM_GROUPS r_u;
+       prs_struct *data = &p->in_data.data;
+       prs_struct *rdata = &p->out_data.rdata;
 
-       /* find the user's rid */
-       if ((status == 0x0) && (get_lsa_policy_samr_rid(&(q_u->user_pol)) == 0xffffffff))
-       {
-               status = NT_STATUS_OBJECT_TYPE_MISMATCH;
-       }
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       init_samr_r_unknown_2c(&r_u, status);
+       /* grab the samr open */
+       if(!samr_io_q_enum_dom_groups("", &q_u, data, 0))
+               return False;
 
-       DEBUG(5,("samr_unknown_2c: %d\n", __LINE__));
+       r_u.status = _samr_enum_dom_groups(p, &q_u, &r_u);
 
        /* store the response in the SMB stream */
-       if(!samr_io_r_unknown_2c("", &r_u, rdata, 0))
+       if(!samr_io_r_enum_dom_groups("", &r_u, rdata, 0))
                return False;
 
-       DEBUG(5,("samr_unknown_2c: %d\n", __LINE__));
-
        return True;
 }
 
 /*******************************************************************
- api_samr_unknown_2c
+ api_samr_enum_dom_aliases
  ********************************************************************/
-static BOOL api_samr_unknown_2c(pipes_struct *p)
+
+static BOOL api_samr_enum_dom_aliases(pipes_struct *p)
 {
-       SAMR_Q_UNKNOWN_2C q_u;
+       SAMR_Q_ENUM_DOM_ALIASES q_u;
+       SAMR_R_ENUM_DOM_ALIASES r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
+       
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
        /* grab the samr open */
-       if(!samr_io_q_unknown_2c("", &q_u, data, 0))
+       if(!samr_io_q_enum_dom_aliases("", &q_u, data, 0))
                return False;
 
-       /* construct reply.  always indicate success */
-       if(!samr_reply_unknown_2c(&q_u, rdata))
+       r_u.status = _samr_enum_dom_aliases(p, &q_u, &r_u);
+
+       /* store the response in the SMB stream */
+       if(!samr_io_r_enum_dom_aliases("", &r_u, rdata, 0))
                return False;
 
        return True;
 }
 
-
 /*******************************************************************
- samr_reply_unknown_3
+ api_samr_query_dispinfo
  ********************************************************************/
-static BOOL samr_reply_unknown_3(SAMR_Q_UNKNOWN_3 *q_u,
-                               prs_struct *rdata)
-{
-       SAMR_R_UNKNOWN_3 r_u;
-       DOM_SID3 sid[MAX_SAM_SIDS];
-       uint32 rid;
-       uint32 status;
-
-       status = 0x0;
 
-       /* find the policy handle.  open a policy on it. */
-       if (status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->user_pol)) == -1))
-       {
-               status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
-       }
-
-       /* find the user's rid */
-       if (status == 0x0 && (rid = get_lsa_policy_samr_rid(&(q_u->user_pol))) == 0xffffffff)
-       {
-               status = NT_STATUS_OBJECT_TYPE_MISMATCH;
-       }
-
-       if (status == 0x0)
-       {
-               DOM_SID user_sid;
-               DOM_SID everyone_sid;
-
-               user_sid = global_sam_sid;
-
-               SMB_ASSERT_ARRAY(user_sid.sub_auths, user_sid.num_auths+1);
-
-               /*
-                * Add the user RID.
-                */
-               user_sid.sub_auths[user_sid.num_auths++] = rid;
-               
-                       string_to_sid(&everyone_sid, "S-1-1");
+static BOOL api_samr_query_dispinfo(pipes_struct *p)
+{
+       SAMR_Q_QUERY_DISPINFO q_u;
+       SAMR_R_QUERY_DISPINFO r_u;
+       prs_struct *data = &p->in_data.data;
+       prs_struct *rdata = &p->out_data.rdata;
 
-                       /* maybe need another 1 or 2 (S-1-5-0x20-0x220 and S-1-5-20-0x224) */
-                       /* these two are DOMAIN_ADMIN and DOMAIN_ACCT_OP group RIDs */
-                       init_dom_sid3(&(sid[0]), 0x035b, 0x0002, &everyone_sid);
-                       init_dom_sid3(&(sid[1]), 0x0044, 0x0002, &user_sid);
-       }
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       init_samr_r_unknown_3(&r_u,
-                               0x0001, 0x8004,
-                               0x00000014, 0x0002, 0x0070,
-                               2, sid, status);
+       if(!samr_io_q_query_dispinfo("", &q_u, data, 0))
+               return False;
 
-       DEBUG(5,("samr_unknown_3: %d\n", __LINE__));
+       r_u.status = _samr_query_dispinfo(p, &q_u, &r_u);
 
        /* store the response in the SMB stream */
-       if(!samr_io_r_unknown_3("", &r_u, rdata, 0))
+       if(!samr_io_r_query_dispinfo("", &r_u, rdata, 0))
                return False;
 
-       DEBUG(5,("samr_unknown_3: %d\n", __LINE__));
-
        return True;
 }
 
 /*******************************************************************
- api_samr_unknown_3
+ api_samr_query_aliasinfo
  ********************************************************************/
-static BOOL api_samr_unknown_3(pipes_struct *p)
+
+static BOOL api_samr_query_aliasinfo(pipes_struct *p)
 {
-       SAMR_Q_UNKNOWN_3 q_u;
+       SAMR_Q_QUERY_ALIASINFO q_u;
+       SAMR_R_QUERY_ALIASINFO r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
+
        /* grab the samr open */
-       if(!samr_io_q_unknown_3("", &q_u, data, 0))
+       if(!samr_io_q_query_aliasinfo("", &q_u, data, 0))
                return False;
 
-       /* construct reply.  always indicate success */
-       if(!samr_reply_unknown_3(&q_u, rdata))
-               return False;
+       r_u.status = _samr_query_aliasinfo(p, &q_u, &r_u);
 
+       /* store the response in the SMB stream */
+       if(!samr_io_r_query_aliasinfo("", &r_u, rdata, 0))
+               return False;
+  
        return True;
 }
 
-
 /*******************************************************************
samr_reply_enum_dom_users
api_samr_lookup_names
  ********************************************************************/
-static BOOL samr_reply_enum_dom_users(SAMR_Q_ENUM_DOM_USERS *q_u,
-                               prs_struct *rdata)
-{
-       SAMR_R_ENUM_DOM_USERS r_e;
-       SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES];
-       int num_entries;
-       int total_entries;
-       
-       ZERO_STRUCT(r_e);
 
-       r_e.status = 0x0;
-       r_e.total_num_entries = 0;
-
-       /* find the policy handle.  open a policy on it. */
-       if (r_e.status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
-       {
-               r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
-       }
+static BOOL api_samr_lookup_names(pipes_struct *p)
+{
+       SAMR_Q_LOOKUP_NAMES q_u;
+       SAMR_R_LOOKUP_NAMES r_u;
+       prs_struct *data = &p->in_data.data;
+       prs_struct *rdata = &p->out_data.rdata;
 
-       DEBUG(5,("samr_reply_enum_dom_users: %d\n", __LINE__));
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       become_root();
-       get_sampwd_entries(pass, 0, &total_entries, &num_entries, MAX_SAM_ENTRIES, q_u->acb_mask);
-       unbecome_root();
+       /* grab the samr lookup names */
+       if(!samr_io_q_lookup_names("", &q_u, data, 0))
+               return False;
 
-       init_samr_r_enum_dom_users(&r_e, total_entries,
-                                  q_u->unknown_0, num_entries,
-                                  pass, r_e.status);
+       r_u.status = _samr_lookup_names(p, &q_u, &r_u);
 
        /* store the response in the SMB stream */
-       if(!samr_io_r_enum_dom_users("", &r_e, rdata, 0))
+       if(!samr_io_r_lookup_names("", &r_u, rdata, 0))
                return False;
 
-       DEBUG(5,("samr_enum_dom_users: %d\n", __LINE__));
-
        return True;
 }
 
 /*******************************************************************
- api_samr_enum_dom_users
+ api_samr_chgpasswd_user
  ********************************************************************/
-static BOOL api_samr_enum_dom_users(pipes_struct *p)
+
+static BOOL api_samr_chgpasswd_user(pipes_struct *p)
 {
-       SAMR_Q_ENUM_DOM_USERS q_e;
+       SAMR_Q_CHGPASSWD_USER q_u;
+       SAMR_R_CHGPASSWD_USER r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
-       /* grab the samr open */
-       if(!samr_io_q_enum_dom_users("", &q_e, data, 0))
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
+
+       /* unknown 38 command */
+       if (!samr_io_q_chgpasswd_user("", &q_u, data, 0)) {
+               DEBUG(0,("api_samr_chgpasswd_user: Failed to unmarshall SAMR_Q_CHGPASSWD_USER.\n"));
                return False;
+       }
 
-       /* construct reply. */
-       if(!samr_reply_enum_dom_users(&q_e, rdata))
+       r_u.status = _samr_chgpasswd_user(p, &q_u, &r_u);
+
+       /* store the response in the SMB stream */
+       if(!samr_io_r_chgpasswd_user("", &r_u, rdata, 0)) {
+               DEBUG(0,("api_samr_chgpasswd_user: Failed to marshall SAMR_R_CHGPASSWD_USER.\n" ));
                return False;
+       }
 
        return True;
 }
 
 /*******************************************************************
samr_reply_enum_dom_groups
api_samr_lookup_rids
  ********************************************************************/
-static BOOL samr_reply_enum_dom_groups(SAMR_Q_ENUM_DOM_GROUPS *q_u,
-                               prs_struct *rdata)
-{
-       SAMR_R_ENUM_DOM_GROUPS r_e;
-       SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES];
-       int num_entries;
-       BOOL got_grps;
-       char *dummy_group = "Domain Admins";
-       
-       ZERO_STRUCT(r_e);
-
-       r_e.status = 0x0;
-       r_e.num_entries = 0;
 
-       /* find the policy handle.  open a policy on it. */
-       if (r_e.status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
-       {
-               r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
-       }
+static BOOL api_samr_lookup_rids(pipes_struct *p)
+{
+       SAMR_Q_LOOKUP_RIDS q_u;
+       SAMR_R_LOOKUP_RIDS r_u;
+       prs_struct *data = &p->in_data.data;
+       prs_struct *rdata = &p->out_data.rdata;
 
-       DEBUG(5,("samr_reply_enum_dom_groups: %d\n", __LINE__));
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       got_grps = True;
-       num_entries = 1;
-       ZERO_STRUCTP(&pass[0]);
-       init_unistr2(&(pass[0].uni_user_name), dummy_group, strlen(dummy_group)+1);
-       pass[0].user_rid = DOMAIN_GROUP_RID_ADMINS;
+       /* grab the samr lookup names */
+       if(!samr_io_q_lookup_rids("", &q_u, data, 0))
+               return False;
 
-       if (r_e.status == 0 && got_grps)
-       {
-               init_samr_r_enum_dom_groups(&r_e, q_u->start_idx, num_entries, pass, r_e.status);
-       }
+       r_u.status = _samr_lookup_rids(p, &q_u, &r_u);
 
        /* store the response in the SMB stream */
-       if(!samr_io_r_enum_dom_groups("", &r_e, rdata, 0))
+       if(!samr_io_r_lookup_rids("", &r_u, rdata, 0))
                return False;
 
-       DEBUG(5,("samr_enum_dom_groups: %d\n", __LINE__));
-
        return True;
 }
 
 /*******************************************************************
- api_samr_enum_dom_groups
+ api_samr_open_user
  ********************************************************************/
-static BOOL api_samr_enum_dom_groups(pipes_struct *p)
+
+static BOOL api_samr_open_user(pipes_struct *p)
 {
-       SAMR_Q_ENUM_DOM_GROUPS q_e;
+       SAMR_Q_OPEN_USER q_u;
+       SAMR_R_OPEN_USER r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
-       /* grab the samr open */
-       if(!samr_io_q_enum_dom_groups("", &q_e, data, 0))
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
+
+       /* grab the samr unknown 22 */
+       if(!samr_io_q_open_user("", &q_u, data, 0))
                return False;
 
-       /* construct reply. */
-       if(!samr_reply_enum_dom_groups(&q_e, rdata))
+       r_u.status = _api_samr_open_user(p, &q_u, &r_u);
+
+       /* store the response in the SMB stream */
+       if(!samr_io_r_open_user("", &r_u, rdata, 0))
                return False;
 
+       DEBUG(5,("samr_open_user: %d\n", __LINE__));
+
        return True;
 }
 
 /*******************************************************************
- samr_reply_enum_dom_aliases
+ api_samr_query_userinfo
  ********************************************************************/
-static BOOL samr_reply_enum_dom_aliases(SAMR_Q_ENUM_DOM_ALIASES *q_u,
-                               prs_struct *rdata)
+
+static BOOL api_samr_query_userinfo(pipes_struct *p)
 {
-       SAMR_R_ENUM_DOM_ALIASES r_e;
-       SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES];
-       int num_entries = 0;
-       DOM_SID sid;
-       fstring sid_str;
-       fstring sam_sid_str;
-       struct group *grp;
-       
-       ZERO_STRUCT(r_e);
+       SAMR_Q_QUERY_USERINFO q_u;
+       SAMR_R_QUERY_USERINFO r_u;
+       prs_struct *data = &p->in_data.data;
+       prs_struct *rdata = &p->out_data.rdata;
 
-       /* find the policy handle.  open a policy on it. */
-       if (r_e.status == 0x0 && !get_lsa_policy_samr_sid(&q_u->pol, &sid))
-       {
-               r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
-       }
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       sid_to_string(sid_str, &sid);
-       sid_to_string(sam_sid_str, &global_sam_sid);
-
-       DEBUG(5,("samr_reply_enum_dom_aliases: sid %s\n", sid_str));
-
-       /* well-known aliases */
-       if (strequal(sid_str, "S-1-5-32"))
-       {
-               char *name;
-               while (!lp_hide_local_users() &&
-                      num_entries < MAX_SAM_ENTRIES && 
-                      ((name = builtin_alias_rids[num_entries].name) != NULL))
-               {
-                       init_unistr2(&(pass[num_entries].uni_user_name), name, strlen(name)+1);
-                       pass[num_entries].user_rid = builtin_alias_rids[num_entries].rid;
-                       num_entries++;
-               }
-       }
-       else if (strequal(sid_str, sam_sid_str) && !lp_hide_local_users())
-       {
-               char *name;
-               char *sep;
-
-               sep = lp_winbind_separator();
-
-               /* local aliases */
-               /* we return the UNIX groups here.  This seems to be the right */
-               /* thing to do, since NT member servers return their local     */
-                /* groups in the same situation.                               */
-               setgrent();
-
-               while (num_entries < MAX_SAM_ENTRIES && ((grp = getgrent()) != NULL))
-               {
-                       int i;
-                       uint32 trid;
-                       name = grp->gr_name;
-
-                       /* Don't return winbind groups as they are not local! */
-
-                       if (strchr(name, *sep) != NULL) {
-                               continue;
-                       }
-
-                       trid = pdb_gid_to_group_rid(grp->gr_gid);
-                       for( i = 0; i < num_entries; i++)
-                               if ( pass[i].user_rid == trid ) break;
-                       if ( i < num_entries )
-                               continue; /* rid was there, dup! */
-
-                       init_unistr2(&(pass[num_entries].uni_user_name), name, strlen(name)+1);
-                       pass[num_entries].user_rid = trid;
-                       num_entries++;
-               }
-
-               endgrent();
-       }
-               
-       init_samr_r_enum_dom_aliases(&r_e, num_entries, pass, r_e.status);
+       /* grab the samr unknown 24 */
+       if(!samr_io_q_query_userinfo("", &q_u, data, 0))
+               return False;
+
+       r_u.status = _samr_query_userinfo(p, &q_u, &r_u);
 
        /* store the response in the SMB stream */
-       if(!samr_io_r_enum_dom_aliases("", &r_e, rdata, 0))
+       if(!samr_io_r_query_userinfo("", &r_u, rdata, 0))
                return False;
 
-       DEBUG(5,("samr_enum_dom_aliases: %d\n", __LINE__));
-
        return True;
 }
 
 /*******************************************************************
- api_samr_enum_dom_aliases
+ api_samr_query_usergroups
  ********************************************************************/
-static BOOL api_samr_enum_dom_aliases(pipes_struct *p)
+
+static BOOL api_samr_query_usergroups(pipes_struct *p)
 {
-       SAMR_Q_ENUM_DOM_ALIASES q_e;
+       SAMR_Q_QUERY_USERGROUPS q_u;
+       SAMR_R_QUERY_USERGROUPS r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
-       
-       ZERO_STRUCT(q_e);
 
-       /* grab the samr open */
-       if(!samr_io_q_enum_dom_aliases("", &q_e, data, 0))
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
+
+       /* grab the samr unknown 32 */
+       if(!samr_io_q_query_usergroups("", &q_u, data, 0))
                return False;
 
-       /* construct reply. */
-       if(!samr_reply_enum_dom_aliases(&q_e, rdata))
+       r_u.status = _samr_query_usergroups(p, &q_u, &r_u);
+
+       /* store the response in the SMB stream */
+       if(!samr_io_r_query_usergroups("", &r_u, rdata, 0)) {
                return False;
+       }
 
        return True;
 }
 
-
 /*******************************************************************
samr_reply_query_dispinfo
api_samr_query_dom_info
  ********************************************************************/
-static BOOL samr_reply_query_dispinfo(SAMR_Q_QUERY_DISPINFO *q_u, prs_struct *rdata)
-{
-       SAMR_R_QUERY_DISPINFO r_e;
-       SAM_INFO_CTR ctr;
-       SAM_INFO_1 info1;
-       SAM_INFO_2 info2;
-       SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES];
-       int num_entries = 0;
-       int total_entries = 0;
-       BOOL got_pwds;
-       uint16 switch_level = 0x0;
-
-       ZERO_STRUCT(r_e);
-
-       DEBUG(5,("samr_reply_query_dispinfo: %d\n", __LINE__));
-
-       /* find the policy handle.  open a policy on it. */
-       if (r_e.status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
-       {
-               r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
-               DEBUG(5,("samr_reply_query_dispinfo: invalid handle\n"));
-       }
-
-       if (r_e.status == 0x0)
-       {
-         /* decide how many entries to get depending on the max_entries 
-            and max_size passed by client */
-         uint32 retsize;
-
-         if(q_u->max_entries > MAX_SAM_ENTRIES)
-           q_u->max_entries = MAX_SAM_ENTRIES;
-         
-         retsize = (q_u->max_entries * (sizeof(SAM_ENTRY1)+sizeof(SAM_STR1)))
-           + 3*sizeof(uint32);
-
-         if(retsize > q_u->max_size)
-           {
-             /* determine max_entries based on max_size */
-             q_u->max_entries = (q_u->max_size - 3*sizeof(uint32)) /
-               (sizeof(SAM_ENTRY1)+sizeof(SAM_STR1));
-             q_u->max_entries = (q_u->max_entries>0?q_u->max_entries:1);
-           }
-
-         DEBUG(10,("samr_reply_query_dispinfo: Setting q_u->max_entries to %u\n",q_u->max_entries));
-
-               become_root();
-               got_pwds = get_passwd_entries(pass, q_u->start_idx, &total_entries, &num_entries, q_u->max_entries, 0);
-               unbecome_root();
-
-               /* more left - set resume handle */
-               if(total_entries > num_entries)
-                 {
-                   r_e.status = 0x105;
-                 }
-
-               switch (q_u->switch_level)
-               {
-                       case 0x1:
-                       {
-                       
-                               /* query disp info is for users */
-                               ZERO_STRUCT (info1);
-                               switch_level = 0x1;
-                               init_sam_info_1(&info1, ACB_NORMAL,
-                                       q_u->start_idx, num_entries, pass);
-
-                               ctr.sam.info1 = &info1;
-
-                               break;
-                       }
-                       case 0x2:
-                       {
-                               /* query disp info is for servers */
-                               ZERO_STRUCT (info2);
-                               switch_level = 0x2;
-                               init_sam_info_2(&info2, ACB_WSTRUST,
-                                       q_u->start_idx, num_entries, pass);
-
-                               ctr.sam.info2 = &info2;
-
-                               break;
-                       }
-               }
-       }
-
-       /* more left - set resume handle */
-       if(total_entries > num_entries)
-         {
-           r_e.status = 0x105;
-         }
-
-       if (r_e.status == 0 || r_e.status == 0x105)
-       {
-         init_samr_r_query_dispinfo(&r_e, switch_level, &ctr, r_e.status);
-       }
-
-       /* store the response in the SMB stream */
-       if(!samr_io_r_query_dispinfo("", &r_e, rdata, 0))
-               return False;
-
-       DEBUG(5,("samr_query_dispinfo: %d\n", __LINE__));
-
-       return True;
-}
 
-/*******************************************************************
- api_samr_query_dispinfo
- ********************************************************************/
-static BOOL api_samr_query_dispinfo(pipes_struct *p)
-{
-       SAMR_Q_QUERY_DISPINFO q_e;
-       prs_struct *data = &p->in_data.data;
-       prs_struct *rdata = &p->out_data.rdata;
-
-       /* grab the samr open */
-       if(!samr_io_q_query_dispinfo("", &q_e, data, 0))
-               return False;
-
-       /* construct reply. */
-       if(!samr_reply_query_dispinfo(&q_e, rdata))
-               return False;
-
-       return True;
-}
-
-
-/*******************************************************************
- samr_reply_query_aliasinfo
- ********************************************************************/
-static BOOL samr_reply_query_aliasinfo(SAMR_Q_QUERY_ALIASINFO *q_u,
-                               prs_struct *rdata)
-{
-  SAMR_R_QUERY_ALIASINFO r_e;
-  fstring alias_desc = "Local Unix group";
-  fstring alias="";
-  enum SID_NAME_USE type;
-  uint32 alias_rid;
-
-  ZERO_STRUCT(r_e);
-
-  DEBUG(5,("samr_reply_query_aliasinfo: %d\n", __LINE__));
-
-  /* find the policy handle.  open a policy on it. */
-  if (r_e.status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
-    {
-      r_e.status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
-    }
-
-  alias_rid = get_lsa_policy_samr_rid(&q_u->pol);
-  if(alias_rid == 0xffffffff)
-      r_e.status = 0xC0000000 | NT_STATUS_NO_SUCH_ALIAS;
-
-  if(!local_lookup_rid(alias_rid, alias, &type))
-    {
-      r_e.status = 0xC0000000 | NT_STATUS_NO_SUCH_ALIAS;
-    }
-  
-  init_samr_r_query_aliasinfo(&r_e, q_u->switch_level, alias, alias_desc);
-  
-  /* store the response in the SMB stream */
-  if(!samr_io_r_query_aliasinfo("", &r_e, rdata, 0))
-               return False;
-  
-  DEBUG(5,("samr_query_aliasinfo: %d\n", __LINE__));
-
-       return True;
-}
-
-/*******************************************************************
- api_samr_query_aliasinfo
- ********************************************************************/
-static BOOL api_samr_query_aliasinfo(pipes_struct *p)
+static BOOL api_samr_query_dom_info(pipes_struct *p)
 {
-       SAMR_Q_QUERY_ALIASINFO q_e;
+       SAMR_Q_QUERY_DOMAIN_INFO q_u;
+       SAMR_R_QUERY_DOMAIN_INFO r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
-       /* grab the samr open */
-       if(!samr_io_q_query_aliasinfo("", &q_e, data, 0))
-               return False;
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       /* construct reply. */
-       if(!samr_reply_query_aliasinfo(&q_e, rdata))
+       /* grab the samr unknown 8 command */
+       if(!samr_io_q_query_dom_info("", &q_u, data, 0))
                return False;
 
-       return True;
-}
-
-
-/*******************************************************************
- samr_reply_lookup_ids
- ********************************************************************/
-static BOOL samr_reply_lookup_ids(SAMR_Q_LOOKUP_IDS *q_u,
-                               prs_struct *rdata)
-{
-       uint32 rid[MAX_SAM_ENTRIES];
-       uint32 status     = 0;
-       int num_rids = q_u->num_sids1;
-
-       SAMR_R_LOOKUP_IDS r_u;
-
-       DEBUG(5,("samr_lookup_ids: %d\n", __LINE__));
-
-       if (num_rids > MAX_SAM_ENTRIES)
-       {
-               num_rids = MAX_SAM_ENTRIES;
-               DEBUG(5,("samr_lookup_ids: truncating entries to %d\n", num_rids));
-       }
-
-#if 0
-       int i;
-       SMB_ASSERT_ARRAY(q_u->uni_user_name, num_rids);
-
-       for (i = 0; i < num_rids && status == 0; i++)
-       {
-               SAM_ACCOUNT *sam_pass;
-               fstring user_name;
-
-
-               fstrcpy(user_name, unistrn2(q_u->uni_user_name[i].buffer,
-                                           q_u->uni_user_name[i].uni_str_len));
-
-               /* find the user account */
-               become_root();
-               sam_pass = pdb_getsampwnam(user_name);
-               unbecome_root();
-
-               if (sam_pass == NULL)
-               {
-                       status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
-                       rid[i] = 0;
-               }
-               else
-               {
-                       rid[i] = pdb_get_user_rid(sam_pass);
-               }
-       }
-#endif
-
-       num_rids = 1;
-       rid[0] = BUILTIN_ALIAS_RID_USERS;
-
-       init_samr_r_lookup_ids(&r_u, num_rids, rid, status);
+       r_u.status = _samr_query_dom_info(p, &q_u, &r_u);
 
        /* store the response in the SMB stream */
-       if(!samr_io_r_lookup_ids("", &r_u, rdata, 0))
-               return False;
-
-       DEBUG(5,("samr_lookup_ids: %d\n", __LINE__));
-
-       return True;
-}
-
-/*******************************************************************
- api_samr_lookup_ids
- ********************************************************************/
-static BOOL api_samr_lookup_ids(pipes_struct *p)
-{
-       SAMR_Q_LOOKUP_IDS q_u;
-       prs_struct *data = &p->in_data.data;
-       prs_struct *rdata = &p->out_data.rdata;
-
-       /* grab the samr 0x10 */
-       if(!samr_io_q_lookup_ids("", &q_u, data, 0))
+       if(!samr_io_r_query_dom_info("", &r_u, rdata, 0))
                return False;
 
-       /* construct reply.  always indicate success */
-       if(!samr_reply_lookup_ids(&q_u, rdata))
-               return False;
+       DEBUG(5,("api_samr_query_dom_info: %d\n", __LINE__));
 
        return True;
 }
 
 /*******************************************************************
- samr_reply_lookup_names
- ********************************************************************/
-
-static BOOL samr_reply_lookup_names(SAMR_Q_LOOKUP_NAMES *q_u,
-                                   prs_struct *rdata)
-{
-  uint32 rid[MAX_SAM_ENTRIES];
-  enum SID_NAME_USE type[MAX_SAM_ENTRIES];
-  uint32 status = 0;
-  int i;
-  int num_rids = q_u->num_names1;
-  DOM_SID pol_sid;
-
-  SAMR_R_LOOKUP_NAMES r_u;
-
-  DEBUG(5,("samr_lookup_names: %d\n", __LINE__));
-
-  ZERO_ARRAY(rid);
-  ZERO_ARRAY(type);
-
-  if (!get_lsa_policy_samr_sid(&q_u->pol, &pol_sid)) {
-    status = 0xC0000000 | NT_STATUS_OBJECT_TYPE_MISMATCH;
-    init_samr_r_lookup_names(&r_u, 0, rid, type, status);
-    if(!samr_io_r_lookup_names("", &r_u, rdata, 0)) {
-      DEBUG(0,("samr_reply_lookup_names: failed to marshall SAMR_R_LOOKUP_NAMES.\n"));
-      return False;
-    }
-    return True;
-  }
-
-  if (num_rids > MAX_SAM_ENTRIES) {
-    num_rids = MAX_SAM_ENTRIES;
-    DEBUG(5,("samr_lookup_names: truncating entries to %d\n", num_rids));
-  }
-
-  SMB_ASSERT_ARRAY(q_u->uni_name, num_rids);
-
-  for (i = 0; i < num_rids; i++) {
-    fstring name;
-
-    status = 0xC0000000 | NT_STATUS_NONE_MAPPED;
-
-    rid [i] = 0xffffffff;
-    type[i] = SID_NAME_UNKNOWN;
-
-    fstrcpy(name, dos_unistrn2(q_u->uni_name[i].buffer,
-                              q_u->uni_name[i].uni_str_len));
-
-    if(sid_equal(&pol_sid, &global_sam_sid)) 
-    {
-      DOM_SID sid;
-      if(local_lookup_name(global_myname, name, 
-                          &sid, &type[i]))
-       {
-         sid_split_rid( &sid, &rid[i]);
-         status = 0;
-       }
-    }
-  }
-
-  init_samr_r_lookup_names(&r_u, num_rids, rid, type, status);
-
-  /* store the response in the SMB stream */
-  if(!samr_io_r_lookup_names("", &r_u, rdata, 0)) {
-    DEBUG(0,("samr_reply_lookup_names: failed to marshall SAMR_R_LOOKUP_NAMES.\n"));
-    return False;
-  }
-
-  DEBUG(5,("samr_lookup_names: %d\n", __LINE__));
-
-  return True;
-}
-
-/*******************************************************************
- api_samr_lookup_names
+ api_samr_create_user
  ********************************************************************/
 
-static BOOL api_samr_lookup_names(pipes_struct *p)
+static BOOL api_samr_create_user(pipes_struct *p)
 {
-       SAMR_Q_LOOKUP_NAMES q_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
-       memset(&q_u, '\0', sizeof(q_u));
+       SAMR_Q_CREATE_USER q_u;
+       SAMR_R_CREATE_USER r_u;
 
-       /* grab the samr lookup names */
-       if(!samr_io_q_lookup_names("", &q_u, data, 0)) {
-               DEBUG(0,("api_samr_lookup_names: failed to unmarshall SAMR_Q_LOOKUP_NAMES.\n"));
-               return False;
-       }
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       /* construct reply.  always indicate success */
-       if(!samr_reply_lookup_names(&q_u, rdata))
+       /* grab the samr create user */
+       if (!samr_io_q_create_user("", &q_u, data, 0)) {
+               DEBUG(0,("api_samr_create_user: Unable to unmarshall SAMR_Q_CREATE_USER.\n"));
                return False;
-
-       return True;
-}
-
-/*******************************************************************
- samr_reply_chgpasswd_user
- ********************************************************************/
-
-static BOOL samr_reply_chgpasswd_user(SAMR_Q_CHGPASSWD_USER *q_u,
-                               prs_struct *rdata)
-{
-       SAMR_R_CHGPASSWD_USER r_u;
-       uint32 status = 0x0;
-       fstring user_name;
-       fstring wks;
-
-       fstrcpy(user_name, dos_unistrn2(q_u->uni_user_name.buffer, q_u->uni_user_name.uni_str_len));
-       fstrcpy(wks      , dos_unistrn2(q_u->uni_dest_host.buffer, q_u->uni_dest_host.uni_str_len));
-
-       DEBUG(5,("samr_chgpasswd_user: user: %s wks: %s\n", user_name, wks));
-
-       if (!pass_oem_change(user_name,
-                            q_u->lm_newpass.pass, q_u->lm_oldhash.hash,
-                            q_u->nt_newpass.pass, q_u->nt_oldhash.hash))
-       {
-               status = 0xC0000000 | NT_STATUS_WRONG_PASSWORD;
        }
 
-       init_samr_r_chgpasswd_user(&r_u, status);
+       r_u.status=_api_samr_create_user(p, &q_u, &r_u);
 
        /* store the response in the SMB stream */
-       if(!samr_io_r_chgpasswd_user("", &r_u, rdata, 0)) {
-               DEBUG(0,("samr_reply_chgpasswd_user: Failed to marshall SAMR_R_CHGPASSWD_USER struct.\n" ));
+       if(!samr_io_r_create_user("", &r_u, rdata, 0)) {
+               DEBUG(0,("api_samr_create_user: Unable to marshall SAMR_R_CREATE_USER.\n"));
                return False;
        }
 
-       DEBUG(5,("samr_chgpasswd_user: %d\n", __LINE__));
        return True;
 }
 
 /*******************************************************************
- api_samr_chgpasswd_user
+ api_samr_connect_anon
  ********************************************************************/
 
-static BOOL api_samr_chgpasswd_user(pipes_struct *p)
+static BOOL api_samr_connect_anon(pipes_struct *p)
 {
-       SAMR_Q_CHGPASSWD_USER q_u;
+       SAMR_Q_CONNECT_ANON q_u;
+       SAMR_R_CONNECT_ANON r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
-       /* unknown 38 command */
-       if (!samr_io_q_chgpasswd_user("", &q_u, data, 0)) {
-               DEBUG(0,("api_samr_chgpasswd_user: samr_io_q_chgpasswd_user failed to parse RPC packet.\n"));
-               return False;
-       }
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       /* construct reply. */
-       if(!samr_reply_chgpasswd_user(&q_u, rdata)) {
-               DEBUG(0,("api_samr_chgpasswd_user: samr_reply_chgpasswd_user failed to create reply packet.\n"));
+       /* grab the samr open policy */
+       if(!samr_io_q_connect_anon("", &q_u, data, 0))
                return False;
-       }
-
-       return True;
-}
-
-
-/*******************************************************************
- samr_reply_unknown_38
- ********************************************************************/
-static BOOL samr_reply_unknown_38(SAMR_Q_UNKNOWN_38 *q_u, prs_struct *rdata)
-{
-       SAMR_R_UNKNOWN_38 r_u;
-
-       DEBUG(5,("samr_unknown_38: %d\n", __LINE__));
 
-       init_samr_r_unknown_38(&r_u);
+       r_u.status = _samr_connect_anon(p, &q_u, &r_u);
 
        /* store the response in the SMB stream */
-       if(!samr_io_r_unknown_38("", &r_u, rdata, 0))
+       if(!samr_io_r_connect_anon("", &r_u, rdata, 0))
                return False;
 
-       DEBUG(5,("samr_unknown_38: %d\n", __LINE__));
        return True;
 }
 
 /*******************************************************************
- api_samr_unknown_38
+ api_samr_connect
  ********************************************************************/
-static BOOL api_samr_unknown_38(pipes_struct *p)
+
+static BOOL api_samr_connect(pipes_struct *p)
 {
-       SAMR_Q_UNKNOWN_38 q_u;
+       SAMR_Q_CONNECT q_u;
+       SAMR_R_CONNECT r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
-       /* unknown 38 command */
-       if(!samr_io_q_unknown_38("", &q_u, data, 0))
-               return False;
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       /* construct reply.  always indicate success */
-       if(!samr_reply_unknown_38(&q_u, rdata))
+       /* grab the samr open policy */
+       if(!samr_io_q_connect("", &q_u, data, 0))
                return False;
 
-       return True;
-}
-
-
-/*******************************************************************
- samr_reply_lookup_rids
- ********************************************************************/
-static BOOL samr_reply_lookup_rids(SAMR_Q_LOOKUP_RIDS *q_u,
-                               prs_struct *rdata)
-{
-       fstring group_names[MAX_SAM_ENTRIES];
-       uint32  group_attrs[MAX_SAM_ENTRIES];
-       uint32 status     = 0;
-       int num_gids = q_u->num_gids1;
-
-       SAMR_R_LOOKUP_RIDS r_u;
-
-       DEBUG(5,("samr_reply_lookup_rids: %d\n", __LINE__));
-
-       /* find the policy handle.  open a policy on it. */
-       if (status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
-       {
-               status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
-       }
-
-       if (status == 0x0)
-       {
-               int i;
-               if (num_gids > MAX_SAM_ENTRIES)
-               {
-                       num_gids = MAX_SAM_ENTRIES;
-                       DEBUG(5,("samr_reply_lookup_rids: truncating entries to %d\n", num_gids));
-               }
-
-               for (i = 0; i < num_gids && status == 0; i++)
-               {
-                       fstrcpy(group_names[i], "dummy group");
-                       group_attrs[i] = 0x2;
-               }
-       }
-
-       init_samr_r_lookup_rids(&r_u, num_gids, group_names, group_attrs, status);
+       r_u.status = _samr_connect(p, &q_u, &r_u);
 
        /* store the response in the SMB stream */
-       if(!samr_io_r_lookup_rids("", &r_u, rdata, 0))
-               return False;
-
-       DEBUG(5,("samr_reply_lookup_rids: %d\n", __LINE__));
-
-       return True;
-}
-
-/*******************************************************************
- api_samr_lookup_rids
- ********************************************************************/
-static BOOL api_samr_lookup_rids(pipes_struct *p)
-{
-       SAMR_Q_LOOKUP_RIDS q_u;
-       prs_struct *data = &p->in_data.data;
-       prs_struct *rdata = &p->out_data.rdata;
-
-       /* grab the samr lookup names */
-       if(!samr_io_q_lookup_rids("", &q_u, data, 0))
-               return False;
-
-       /* construct reply.  always indicate success */
-       if(!samr_reply_lookup_rids(&q_u, rdata))
+       if(!samr_io_r_connect("", &r_u, rdata, 0))
                return False;
 
        return True;
 }
 
+/**********************************************************************
+ api_samr_lookup_domain
+ **********************************************************************/
 
-/*******************************************************************
- _api_samr_open_user
- ********************************************************************/
-static uint32 _api_samr_open_user(POLICY_HND domain_pol, uint32 user_rid, POLICY_HND *user_pol)
-{
-       SAM_ACCOUNT *sam_pass;
-       DOM_SID sid;
-
-       /* find the domain policy handle. */
-       if (find_lsa_policy_by_hnd(&domain_pol) == -1)
-               return NT_STATUS_INVALID_HANDLE;
-
-       /* get a (unique) handle.  open a policy on it. */
-       if (!open_lsa_policy_hnd(user_pol))
-               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
-
-       become_root();
-       sam_pass = pdb_getsampwrid(user_rid);
-       unbecome_root();
-
-       /* check that the RID exists in our domain. */
-       if (sam_pass == NULL) {
-               close_lsa_policy_hnd(user_pol);
-               return NT_STATUS_NO_SUCH_USER;
-       }
-       
-       /* Get the domain SID stored in the domain policy */
-       if(!get_lsa_policy_samr_sid(&domain_pol, &sid)) {
-               close_lsa_policy_hnd(user_pol);
-               return NT_STATUS_INVALID_HANDLE;
-       }
-
-       /* append the user's RID to it */
-       if(!sid_append_rid(&sid, user_rid)) {
-               close_lsa_policy_hnd(user_pol);
-               return NT_STATUS_NO_SUCH_USER;
-       }
-
-       /* associate the user's SID with the handle. */
-       if (!set_lsa_policy_samr_sid(user_pol, &sid)) {
-               /* oh, whoops.  don't know what error message to return, here */
-               close_lsa_policy_hnd(user_pol);
-               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
-       }
-
-       return NT_STATUS_NO_PROBLEMO;
-}
-
-/*******************************************************************
- api_samr_open_user
- ********************************************************************/
-static BOOL api_samr_open_user(pipes_struct *p)
+static BOOL api_samr_lookup_domain(pipes_struct *p)
 {
-       SAMR_Q_OPEN_USER q_u;
-       SAMR_R_OPEN_USER r_u;
+       SAMR_Q_LOOKUP_DOMAIN q_u;
+       SAMR_R_LOOKUP_DOMAIN r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
-
+  
        ZERO_STRUCT(q_u);
        ZERO_STRUCT(r_u);
 
-       /* grab the samr unknown 22 */
-       if(!samr_io_q_open_user("", &q_u, data, 0))
-               return False;
-
-       r_u.status = _api_samr_open_user(q_u.domain_pol, q_u.user_rid, &r_u.user_pol);
-
-       /* store the response in the SMB stream */
-       if(!samr_io_r_open_user("", &r_u, rdata, 0))
-               return False;
-
-       DEBUG(5,("samr_open_user: %d\n", __LINE__));
-
-       return True;
-}
-
-/*************************************************************************
- get_user_info_10
- *************************************************************************/
-static BOOL get_user_info_10(SAM_USER_INFO_10 *id10, uint32 user_rid)
-{
-       SAM_ACCOUNT *sampass;
-
-       if (!pdb_rid_is_user(user_rid))
-       {
-               DEBUG(4,("RID 0x%x is not a user RID\n", user_rid));
+       if(!samr_io_q_lookup_domain("", &q_u, data, 0)) {
+               DEBUG(0,("api_samr_lookup_domain: Unable to unmarshall SAMR_Q_LOOKUP_DOMAIN.\n"));
                return False;
        }
 
-       become_root();
-       sampass = pdb_getsampwrid(user_rid);
-       unbecome_root();
-
-       if (sampass == NULL)
-       {
-               DEBUG(4,("User 0x%x not found\n", user_rid));
+       r_u.status = _samr_lookup_domain(p, &q_u, &r_u);
+       
+       if(!samr_io_r_lookup_domain("", &r_u, rdata, 0)){
+               DEBUG(0,("api_samr_lookup_domain: Unable to marshall SAMR_R_LOOKUP_DOMAIN.\n"));
                return False;
        }
-
-       DEBUG(3,("User:[%s]\n", pdb_get_username(sampass)));
-
-       init_sam_user_info10(id10, pdb_get_acct_ctrl(sampass)); 
-
+       
        return True;
 }
 
-/*************************************************************************
- get_user_info_21
- *************************************************************************/
-static BOOL get_user_info_21(SAM_USER_INFO_21 *id21, uint32 user_rid)
+/**********************************************************************
+ api_samr_enum_domains
+ **********************************************************************/
+
+static BOOL api_samr_enum_domains(pipes_struct *p)
 {
-       SAM_ACCOUNT     *sam_pass;
+       SAMR_Q_ENUM_DOMAINS q_u;
+       SAMR_R_ENUM_DOMAINS r_u;
+       prs_struct *data = &p->in_data.data;
+       prs_struct *rdata = &p->out_data.rdata;
+  
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       if (!pdb_rid_is_user(user_rid))
-       {
-               DEBUG(4,("RID 0x%x is not a user RID\n", user_rid));
+       if(!samr_io_q_enum_domains("", &q_u, data, 0)) {
+               DEBUG(0,("api_samr_enum_domains: Unable to unmarshall SAMR_Q_ENUM_DOMAINS.\n"));
                return False;
        }
 
-       become_root();
-       sam_pass = pdb_getsampwrid(user_rid);
-       unbecome_root();
+       r_u.status = _samr_enum_domains(p, &q_u, &r_u);
 
-       if (sam_pass == NULL)
-       {
-               DEBUG(4,("User 0x%x not found\n", user_rid));
+       if(!samr_io_r_enum_domains("", &r_u, rdata, 0)) {
+               DEBUG(0,("api_samr_enum_domains: Unable to marshall SAMR_R_ENUM_DOMAINS.\n"));
                return False;
        }
-
-       DEBUG(3,("User:[%s]\n", pdb_get_username(sam_pass)));
-
-       init_sam_user_info21(id21, sam_pass);
-
+       
        return True;
 }
 
 /*******************************************************************
- samr_reply_query_userinfo
+ api_samr_open_alias
  ********************************************************************/
-static BOOL samr_reply_query_userinfo(SAMR_Q_QUERY_USERINFO *q_u,
-                               prs_struct *rdata)
-{
-       SAMR_R_QUERY_USERINFO r_u;
-#if 0
-       SAM_USER_INFO_11 id11;
-#endif
-       SAM_USER_INFO_10 id10;
-       SAM_USER_INFO_21 id21;
-       void *info = NULL;
-
-       uint32 status = 0x0;
-       uint32 rid = 0x0;
-
-       DEBUG(5,("samr_reply_query_userinfo: %d\n", __LINE__));
-
-       /* search for the handle */
-       if (status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
-       {
-               status = NT_STATUS_INVALID_HANDLE;
-       }
-
-       /* find the user's rid */
-       if (status == 0x0 && (rid = get_lsa_policy_samr_rid(&(q_u->pol))) == 0xffffffff)
-       {
-               status = NT_STATUS_OBJECT_TYPE_MISMATCH;
-       }
-
-       DEBUG(5,("samr_reply_query_userinfo: rid:0x%x\n", rid));
-
-       /* ok!  user info levels (there are lots: see MSDEV help), off we go... */
-       if (status == 0x0)
-       {
-               switch (q_u->switch_value)
-               {
-                       case 0x10:
-                       {
-                               info = (void*)&id10;
-                               status = get_user_info_10(&id10, rid) ? 0 : NT_STATUS_NO_SUCH_USER;
-                               break;
-                       }
-#if 0
-/* whoops - got this wrong.  i think.  or don't understand what's happening. */
-                       case 0x11:
-                       {
-                               NTTIME expire;
-                               info = (void*)&id11;
-                               
-                               expire.low  = 0xffffffff;
-                               expire.high = 0x7fffffff;
-
-                               make_sam_user_info11(&id11, &expire, "BROOKFIELDS$", 0x03ef, 0x201, 0x0080);
-
-                               break;
-                       }
-#endif
-                       case 21:
-                       {
-                               info = (void*)&id21;
-                               status = get_user_info_21(&id21, rid) ? 0 : NT_STATUS_NO_SUCH_USER;
-                               break;
-                       }
-
-                       default:
-                       {
-                               status = NT_STATUS_INVALID_INFO_CLASS;
-
-                               break;
-                       }
-               }
-       }
-
-       init_samr_r_query_userinfo(&r_u, q_u->switch_value, info, status);
 
-       /* store the response in the SMB stream */
-       if(!samr_io_r_query_userinfo("", &r_u, rdata, 0))
-               return False;
-
-       DEBUG(5,("samr_reply_query_userinfo: %d\n", __LINE__));
-
-       return True;
-}
-
-/*******************************************************************
- api_samr_query_userinfo
- ********************************************************************/
-static BOOL api_samr_query_userinfo(pipes_struct *p)
+static BOOL api_samr_open_alias(pipes_struct *p)
 {
-       SAMR_Q_QUERY_USERINFO q_u;
+       SAMR_Q_OPEN_ALIAS q_u;
+       SAMR_R_OPEN_ALIAS r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
-       /* grab the samr unknown 24 */
-       if(!samr_io_q_query_userinfo("", &q_u, data, 0))
-               return False;
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       /* construct reply.  always indicate success */
-       if(!samr_reply_query_userinfo(&q_u, rdata))
+       /* grab the samr open policy */
+       if(!samr_io_q_open_alias("", &q_u, data, 0)) {
+               DEBUG(0,("api_samr_open_alias: Unable to unmarshall SAMR_Q_OPEN_ALIAS.\n"));
                return False;
-
-       return True;
-}
-
-
-/*******************************************************************
- samr_reply_query_usergroups
- ********************************************************************/
-static BOOL samr_reply_query_usergroups(SAMR_Q_QUERY_USERGROUPS *q_u,
-                               prs_struct *rdata)
-{
-       SAMR_R_QUERY_USERGROUPS r_u;
-       uint32 status = 0x0;
-
-       SAM_ACCOUNT *sam_pass;
-       DOM_GID *gids = NULL;
-       int num_groups = 0;
-       uint32 rid;
-
-       DEBUG(5,("samr_query_usergroups: %d\n", __LINE__));
-
-       /* find the policy handle.  open a policy on it. */
-       if (status == 0x0 && (find_lsa_policy_by_hnd(&(q_u->pol)) == -1))
-       {
-               status = 0xC0000000 | NT_STATUS_INVALID_HANDLE;
-       }
-
-       /* find the user's rid */
-       if (status == 0x0 && (rid = get_lsa_policy_samr_rid(&(q_u->pol))) == 0xffffffff)
-       {
-               status = NT_STATUS_OBJECT_TYPE_MISMATCH;
        }
 
-       if (status == 0x0)
-       {
-               become_root();
-               sam_pass = pdb_getsampwrid(rid);
-               unbecome_root();
-
-               if (sam_pass == NULL)
-               {
-                       status = 0xC0000000 | NT_STATUS_NO_SUCH_USER;
-               }
-       }
-
-       if (status == 0x0)
-       {
-               pstring groups;
-               get_domain_user_groups(groups, pdb_get_username(sam_pass));
-                gids = NULL;
-               num_groups = make_dom_gids(groups, &gids);
-       }
-
-       /* construct the response.  lkclXXXX: gids are not copied! */
-       init_samr_r_query_usergroups(&r_u, num_groups, gids, status);
+       r_u.status=_api_samr_open_alias(p, &q_u, &r_u);
 
        /* store the response in the SMB stream */
-       if(!samr_io_r_query_usergroups("", &r_u, rdata, 0)) {
-               if (gids)
-                       free((char *)gids);
+       if(!samr_io_r_open_alias("", &r_u, rdata, 0)) {
+               DEBUG(0,("api_samr_open_alias: Unable to marshall SAMR_R_OPEN_ALIAS.\n"));
                return False;
        }
-
-       if (gids)
-               free((char *)gids);
-
-       DEBUG(5,("samr_query_usergroups: %d\n", __LINE__));
        
        return True;
 }
 
 /*******************************************************************
- api_samr_query_usergroups
+ api_samr_set_userinfo
  ********************************************************************/
-static BOOL api_samr_query_usergroups(pipes_struct *p)
-{
-       SAMR_Q_QUERY_USERGROUPS q_u;
-       prs_struct *data = &p->in_data.data;
-       prs_struct *rdata = &p->out_data.rdata;
-
-       /* grab the samr unknown 32 */
-       if(!samr_io_q_query_usergroups("", &q_u, data, 0))
-               return False;
-
-       /* construct reply. */
-       if(!samr_reply_query_usergroups(&q_u, rdata))
-               return False;
 
-       return True;
-}
-
-
-/*******************************************************************
- api_samr_query_dom_info
- ********************************************************************/
-static BOOL api_samr_query_dom_info(pipes_struct *p)
+static BOOL api_samr_set_userinfo(pipes_struct *p)
 {
-       SAMR_Q_QUERY_DOMAIN_INFO q_u;
-       SAMR_R_QUERY_DOMAIN_INFO r_u;
-       SAM_UNK_CTR ctr;
+       SAMR_Q_SET_USERINFO q_u;
+       SAMR_R_SET_USERINFO r_u;
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
-       uint16 switch_value = 0x0;
-       uint32 status = 0x0;
-
        ZERO_STRUCT(q_u);
        ZERO_STRUCT(r_u);
-       ZERO_STRUCT(ctr);
 
-       DEBUG(5,("api_samr_query_dom_info: %d\n", __LINE__));
-
-       /* grab the samr unknown 8 command */
-       if(!samr_io_q_query_dom_info("", &q_u, data, 0))
+       if (!samr_io_q_set_userinfo("", &q_u, data, 0)) {
+               DEBUG(0,("api_samr_set_userinfo: Unable to unmarshall SAMR_Q_SET_USERINFO.\n"));
                return False;
-
-       /* find the policy handle.  open a policy on it. */
-       if (find_lsa_policy_by_hnd(&q_u.domain_pol) == -1) {
-               status = NT_STATUS_INVALID_HANDLE;
-               DEBUG(5,("api_samr_query_dom_info: invalid handle\n"));
        }
 
-       if (status == 0x0) {
-               switch (q_u.switch_value) {
-                       case 0x01:
-                               switch_value = 0x1;
-                               init_unk_info1(&ctr.info.inf1);
-                               break;
-                       case 0x02:
-                               switch_value = 0x2;
-                               init_unk_info2(&ctr.info.inf2, global_myworkgroup, global_myname);
-                               break;
-                       case 0x03:
-                               switch_value = 0x3;
-                               init_unk_info3(&ctr.info.inf3);
-                               break;
-                       case 0x06:
-                               switch_value = 0x6;
-                               init_unk_info6(&ctr.info.inf6);
-                               break;
-                       case 0x07:
-                               switch_value = 0x7;
-                               init_unk_info7(&ctr.info.inf7);
-                               break;
-                       case 0x0c:
-                               switch_value = 0xc;
-                               init_unk_info12(&ctr.info.inf12);
-                               break;
-                       default:
-                               status = NT_STATUS_INVALID_INFO_CLASS;
-                               break;
-               }
-       }
-
-       init_samr_r_query_dom_info(&r_u, switch_value, &ctr, status);
+       r_u.status = _samr_set_userinfo(p, &q_u, &r_u);
 
-       /* store the response in the SMB stream */
-       if(!samr_io_r_query_dom_info("", &r_u, rdata, 0))
+       if(!samr_io_r_set_userinfo("", &r_u, rdata, 0)) {
+               DEBUG(0,("api_samr_set_userinfo: Unable to marshall SAMR_R_SET_USERINFO.\n"));
                return False;
-
-       DEBUG(5,("api_samr_query_dom_info: %d\n", __LINE__));
+       }
 
        return True;
 }
 
-
 /*******************************************************************
- _api_samr_create_user
+ api_samr_set_userinfo2
  ********************************************************************/
-static BOOL _api_samr_create_user(POLICY_HND dom_pol, UNISTR2 user_account, uint32 acb_info, uint32 access_mask,
-                                 POLICY_HND *user_pol, uint32 *unknown0, uint32 *user_rid)
-{
-       SAM_ACCOUNT *sam_pass;
-       fstring mach_acct;
-       pstring err_str;
-       pstring msg_str;
-       int local_flags=0;
-       DOM_SID sid;
-       
-       /* find the policy handle.  open a policy on it. */
-       if (find_lsa_policy_by_hnd(&dom_pol) == -1)
-               return NT_STATUS_INVALID_HANDLE;
-
-       /* find the machine account: tell the caller if it exists.
-          lkclXXXX i have *no* idea if this is a problem or not
-          or even if you are supposed to construct a different
-          reply if the account already exists...
-        */
-
-       fstrcpy(mach_acct, dos_unistrn2(user_account.buffer, user_account.uni_str_len));
-       strlower(mach_acct);
-
-       become_root();
-       sam_pass = pdb_getsampwnam(mach_acct);
-       unbecome_root();
-       if (sam_pass != NULL) 
-       {
-               /* machine account exists: say so */
-               return NT_STATUS_USER_EXISTS;
-       }
-
-       /* get a (unique) handle.  open a policy on it. */
-       if (!open_lsa_policy_hnd(user_pol))
-               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
-
-       local_flags=LOCAL_ADD_USER|LOCAL_DISABLE_USER|LOCAL_SET_NO_PASSWORD;
-       local_flags|= (acb_info & ACB_WSTRUST) ? LOCAL_TRUST_ACCOUNT:0;
-
-       /*
-        * NB. VERY IMPORTANT ! This call must be done as the current pipe user,
-        * *NOT* surrounded by a become_root()/unbecome_root() call. This ensures
-        * that only people with write access to the smbpasswd file will be able
-        * to create a user. JRA.
-        */
-
-       /* add the user in the /etc/passwd file or the unix authority system */
-       if (lp_adduser_script())
-               smb_create_user(mach_acct,NULL);
-
-       /* add the user in the smbpasswd file or the Samba authority database */
-       if (!local_password_change(mach_acct, local_flags, NULL, err_str, 
-            sizeof(err_str), msg_str, sizeof(msg_str))) 
-       {
-               DEBUG(0, ("%s\n", err_str));
-               close_lsa_policy_hnd(user_pol);
-               return NT_STATUS_ACCESS_DENIED;
-       }
 
-       become_root();
-       sam_pass = pdb_getsampwnam(mach_acct);
-       unbecome_root();
-       if (sam_pass == NULL) {
-               /* account doesn't exist: say so */
-               close_lsa_policy_hnd(user_pol);
-               return NT_STATUS_ACCESS_DENIED;
-       }
-
-       /* Get the domain SID stored in the domain policy */
-       if(!get_lsa_policy_samr_sid(&dom_pol, &sid)) {
-               close_lsa_policy_hnd(user_pol);
-               return NT_STATUS_INVALID_HANDLE;
-       }
-
-       /* append the user's RID to it */
-       if(!sid_append_rid(&sid, sam_pass->user_rid)) {
-               close_lsa_policy_hnd(user_pol);
-               return NT_STATUS_NO_SUCH_USER;
-       }
-
-       /* associate the RID with the (unique) handle. */
-       if (!set_lsa_policy_samr_sid(user_pol, &sid)) {
-               /* oh, whoops.  don't know what error message to return, here */
-               close_lsa_policy_hnd(user_pol);
-               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
-       }
-
-       *unknown0 = 0x000703ff;
-       *user_rid = pdb_get_user_rid(sam_pass);
-
-       return NT_STATUS_NO_PROBLEMO;
-}
-
-/*******************************************************************
- api_samr_create_user
- ********************************************************************/
-static BOOL api_samr_create_user(pipes_struct *p)
+static BOOL api_samr_set_userinfo2(pipes_struct *p)
 {
+       SAMR_Q_SET_USERINFO2 q_u;
+       SAMR_R_SET_USERINFO2 r_u;
+
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
-       SAMR_Q_CREATE_USER q_u;
-       SAMR_R_CREATE_USER r_u;
-
        ZERO_STRUCT(q_u);
        ZERO_STRUCT(r_u);
 
-       /* grab the samr create user */
-       if (!samr_io_q_create_user("", &q_u, data, 0)) {
-               DEBUG(0,("api_samr_create_user: Unable to unmarshall SAMR_Q_CREATE_USER.\n"));
+       if (!samr_io_q_set_userinfo2("", &q_u, data, 0)) {
+               DEBUG(0,("api_samr_set_userinfo2: Unable to unmarshall SAMR_Q_SET_USERINFO2.\n"));
                return False;
        }
 
-       r_u.status=_api_samr_create_user(q_u.pol, q_u.uni_mach_acct, q_u.acb_info, q_u.access_mask,
-                                       &r_u.pol, &r_u.unknown_0, &r_u.user_rid);
+       r_u.status = _samr_set_userinfo2(p, &q_u, &r_u);
 
-       /* store the response in the SMB stream */
-       if(!samr_io_r_create_user("", &r_u, rdata, 0)) {
-               DEBUG(0,("api_samr_create_user: Unable to marshall SAMR_R_CREATE_USER.\n"));
+       if(!samr_io_r_set_userinfo2("", &r_u, rdata, 0)) {
+               DEBUG(0,("api_samr_set_userinfo2: Unable to marshall SAMR_R_SET_USERINFO2.\n"));
                return False;
        }
 
        return True;
 }
 
-
 /*******************************************************************
- samr_reply_connect_anon
+ api_samr_query_useraliases
  ********************************************************************/
-static BOOL samr_reply_connect_anon(SAMR_Q_CONNECT_ANON *q_u, prs_struct *rdata)
-{
-       SAMR_R_CONNECT_ANON r_u;
-       BOOL pol_open = False;
 
-       /* set up the SAMR connect_anon response */
+static BOOL api_samr_query_useraliases(pipes_struct *p)
+{
+       SAMR_Q_QUERY_USERALIASES q_u;
+       SAMR_R_QUERY_USERALIASES r_u;
 
-       r_u.status = 0x0;
-       /* get a (unique) handle.  open a policy on it. */
-       if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.connect_pol))))
-       {
-               r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
-       }
+       prs_struct *data = &p->in_data.data;
+       prs_struct *rdata = &p->out_data.rdata;
 
-       /* associate the domain SID with the (unique) handle. */
-       if (r_u.status == 0x0 && !set_lsa_policy_samr_pol_status(&(r_u.connect_pol), q_u->unknown_0))
-       {
-               /* oh, whoops.  don't know what error message to return, here */
-               r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
-       }
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       if (r_u.status != 0 && pol_open)
-       {
-               close_lsa_policy_hnd(&(r_u.connect_pol));
+       if (!samr_io_q_query_useraliases("", &q_u, data, 0)) {
+               DEBUG(0,("api_samr_query_useraliases:  Unable to unmarshall SAMR_Q_QUERY_USERALIASES.\n"));
+               return False;
        }
 
-       DEBUG(5,("samr_connect_anon: %d\n", __LINE__));
+       r_u.status = _samr_query_useraliases(p, &q_u, &r_u);
 
-       /* store the response in the SMB stream */
-       if(!samr_io_r_connect_anon("", &r_u, rdata, 0))
+       if (! samr_io_r_query_useraliases("", &r_u, rdata, 0)) {
+               DEBUG(0,("api_samr_query_useraliases:  Unable to nmarshall SAMR_R_QUERY_USERALIASES.\n"));
                return False;
-
-       DEBUG(5,("samr_connect_anon: %d\n", __LINE__));
+       }
 
        return True;
 }
 
 /*******************************************************************
- api_samr_connect_anon
+ api_samr_query_aliasmem
  ********************************************************************/
-static BOOL api_samr_connect_anon(pipes_struct *p)
+
+static BOOL api_samr_query_aliasmem(pipes_struct *p)
 {
-       SAMR_Q_CONNECT_ANON q_u;
+       SAMR_Q_QUERY_ALIASMEM q_u;
+       SAMR_R_QUERY_ALIASMEM r_u;
+
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
-       /* grab the samr open policy */
-       if(!samr_io_q_connect_anon("", &q_u, data, 0))
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
+
+       if (!samr_io_q_query_aliasmem("", &q_u, data, 0)) {
                return False;
+       }
+
+       r_u.status = _samr_query_aliasmem(p, &q_u, &r_u);
 
-       /* construct reply.  always indicate success */
-       if(!samr_reply_connect_anon(&q_u, rdata))
+       if (!samr_io_r_query_aliasmem("", &r_u, rdata, 0)) {
                return False;
+       }
 
        return True;
 }
 
 /*******************************************************************
- samr_reply_connect
+ api_samr_query_groupmem
  ********************************************************************/
-static BOOL samr_reply_connect(SAMR_Q_CONNECT *q_u, prs_struct *rdata)
-{
-       SAMR_R_CONNECT r_u;
-       BOOL pol_open = False;
 
-       /* set up the SAMR connect response */
+static BOOL api_samr_query_groupmem(pipes_struct *p)
+{
+       SAMR_Q_QUERY_GROUPMEM q_u;
+       SAMR_R_QUERY_GROUPMEM r_u;
 
-       r_u.status = 0x0;
-       /* get a (unique) handle.  open a policy on it. */
-       if (r_u.status == 0x0 && !(pol_open = open_lsa_policy_hnd(&(r_u.connect_pol))))
-       {
-               r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
-       }
+       prs_struct *data = &p->in_data.data;
+       prs_struct *rdata = &p->out_data.rdata;
 
-       /* associate the domain SID with the (unique) handle. */
-       if (r_u.status == 0x0 && 
-           !set_lsa_policy_samr_pol_status(&(r_u.connect_pol), 
-                                           q_u->access_mask))
-       {
-               /* oh, whoops.  don't know what error message to return, here */
-               r_u.status = 0xC0000000 | NT_STATUS_OBJECT_NAME_NOT_FOUND;
-       }
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       if (r_u.status != 0 && pol_open)
-       {
-               close_lsa_policy_hnd(&(r_u.connect_pol));
+       if (!samr_io_q_query_groupmem("", &q_u, data, 0)) {
+               return False;
        }
 
-       DEBUG(5,("samr_connect: %d\n", __LINE__));
+       r_u.status = _samr_query_groupmem(p, &q_u, &r_u);
 
-       /* store the response in the SMB stream */
-       if(!samr_io_r_connect("", &r_u, rdata, 0))
+       if (!samr_io_r_query_groupmem("", &r_u, rdata, 0)) {
                return False;
-
-       DEBUG(5,("samr_connect: %d\n", __LINE__));
+       }
 
        return True;
 }
 
 /*******************************************************************
- api_samr_connect
+ api_samr_add_aliasmem
  ********************************************************************/
-static BOOL api_samr_connect(pipes_struct *p)
+
+static BOOL api_samr_add_aliasmem(pipes_struct *p)
 {
-       SAMR_Q_CONNECT q_u;
+       SAMR_Q_ADD_ALIASMEM q_u;
+       SAMR_R_ADD_ALIASMEM r_u;
+
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
-       /* grab the samr open policy */
-       if(!samr_io_q_connect("", &q_u, data, 0))
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
+
+       if (!samr_io_q_add_aliasmem("", &q_u, data, 0)) {
                return False;
+       }
 
-       /* construct reply.  always indicate success */
-       if(!samr_reply_connect(&q_u, rdata))
+       r_u.status = _samr_add_aliasmem(p, &q_u, &r_u);
+
+       if (!samr_io_r_add_aliasmem("", &r_u, rdata, 0)) {
                return False;
+       }
 
        return True;
 }
 
-  
-/**********************************************************************
- api_samr_lookup_domain
- **********************************************************************/
-static BOOL api_samr_lookup_domain(pipes_struct *p)
+/*******************************************************************
+ api_samr_del_aliasmem
+ ********************************************************************/
+
+static BOOL api_samr_del_aliasmem(pipes_struct *p)
 {
-       SAMR_Q_LOOKUP_DOMAIN q_u;
-       SAMR_R_LOOKUP_DOMAIN r_u;
+       SAMR_Q_DEL_ALIASMEM q_u;
+       SAMR_R_DEL_ALIASMEM r_u;
+
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
-  
+
        ZERO_STRUCT(q_u);
        ZERO_STRUCT(r_u);
 
-       if(!samr_io_q_lookup_domain("", &q_u, data, 0)) {
-               DEBUG(0,("api_samr_lookup_domain: Unable to unmarshall SAMR_Q_LOOKUP_DOMAIN.\n"));
+       if (!samr_io_q_del_aliasmem("", &q_u, data, 0)) {
                return False;
        }
-       
-       r_u.status = 0x0;
 
-       if (find_lsa_policy_by_hnd(&q_u.connect_pol) == -1){
-               r_u.status = NT_STATUS_INVALID_HANDLE;
-               DEBUG(5,("api_samr_lookup_domain: invalid handle\n"));
-       }
-  
-       /* assume the domain name sent is our global_myname and 
-          send global_sam_sid */
-       init_samr_r_lookup_domain(&r_u, &global_sam_sid, r_u.status);
-  
-       if(!samr_io_r_lookup_domain("", &r_u, rdata, 0)){
-               DEBUG(0,("api_samr_lookup_domain: Unable to marshall SAMR_R_LOOKUP_DOMAIN.\n"));
+       r_u.status = _samr_del_aliasmem(p, &q_u, &r_u);
+
+       if (!samr_io_r_del_aliasmem("", &r_u, rdata, 0)) {
                return False;
        }
-       
+
        return True;
 }
 
-/**********************************************************************
- api_samr_enum_domains
- **********************************************************************/
-static BOOL api_samr_enum_domains(pipes_struct *p)
+/*******************************************************************
+ api_samr_add_groupmem
+ ********************************************************************/
+
+static BOOL api_samr_add_groupmem(pipes_struct *p)
 {
-       SAMR_Q_ENUM_DOMAINS q_u;
-       SAMR_R_ENUM_DOMAINS r_u;
+       SAMR_Q_ADD_GROUPMEM q_u;
+       SAMR_R_ADD_GROUPMEM r_u;
+
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
-  
-       fstring dom[2];
 
        ZERO_STRUCT(q_u);
        ZERO_STRUCT(r_u);
 
-       fstrcpy(dom[0],global_myworkgroup);
-       fstrcpy(dom[1],"Builtin");
-
-       if(!samr_io_q_enum_domains("", &q_u, data, 0)) {
-               DEBUG(0,("api_samr_enum_domains: Unable to unmarshall SAMR_Q_ENUM_DOMAINS.\n"));
+       if (!samr_io_q_add_groupmem("", &q_u, data, 0)) {
                return False;
        }
 
-       r_u.status = NT_STATUS_NO_PROBLEMO;
-   
-       init_samr_r_enum_domains(&r_u, q_u.start_idx, dom, 2); 
+       r_u.status = _samr_add_groupmem(p, &q_u, &r_u);
 
-       if(!samr_io_r_enum_domains("", &r_u, rdata, 0)) {
-               DEBUG(0,("api_samr_enum_domains: Unable to marshall SAMR_R_ENUM_DOMAINS.\n"));
-               free(r_u.sam);
-               free(r_u.uni_dom_name);
+       if (!samr_io_r_add_groupmem("", &r_u, rdata, 0)) {
                return False;
        }
 
-       free(r_u.sam);
-       free(r_u.uni_dom_name);
-       
        return True;
 }
 
-
 /*******************************************************************
- api_samr_open_alias
+ api_samr_del_groupmem
  ********************************************************************/
-static uint32 _api_samr_open_alias(POLICY_HND domain_pol, uint32 alias_rid, POLICY_HND *alias_pol)
+
+static BOOL api_samr_del_groupmem(pipes_struct *p)
 {
-       DOM_SID sid;
-       
-       /* get the domain policy. */
-       if (find_lsa_policy_by_hnd(&domain_pol) == -1)
-               return NT_STATUS_INVALID_HANDLE;
-
-       /* get a (unique) handle.  open a policy on it. */
-       if (!open_lsa_policy_hnd(alias_pol))
-               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
-
-       /* Get the domain SID stored in the domain policy */
-       if(!get_lsa_policy_samr_sid(&domain_pol, &sid)) {
-               close_lsa_policy_hnd(alias_pol);
-               return NT_STATUS_INVALID_HANDLE;
-       }
+       SAMR_Q_DEL_GROUPMEM q_u;
+       SAMR_R_DEL_GROUPMEM r_u;
+
+       prs_struct *data = &p->in_data.data;
+       prs_struct *rdata = &p->out_data.rdata;
+
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       /* append the alias' RID to it */
-       if(!sid_append_rid(&sid, alias_rid)) {
-               close_lsa_policy_hnd(alias_pol);
-               return NT_STATUS_NO_SUCH_USER;
+       if (!samr_io_q_del_groupmem("", &q_u, data, 0)) {
+               return False;
        }
 
-       /* associate a RID with the (unique) handle. */
-       if (!set_lsa_policy_samr_sid(alias_pol, &sid)) {
-               /* oh, whoops.  don't know what error message to return, here */
-               close_lsa_policy_hnd(alias_pol);
-               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+       r_u.status = _samr_del_groupmem(p, &q_u, &r_u);
+
+       if (!samr_io_r_del_groupmem("", &r_u, rdata, 0)) {
+               return False;
        }
 
-       return NT_STATUS_NO_PROBLEMO;
+       return True;
 }
 
 /*******************************************************************
- api_samr_open_alias
+ api_samr_delete_dom_user
  ********************************************************************/
-static BOOL api_samr_open_alias(pipes_struct *p)
+
+static BOOL api_samr_delete_dom_user(pipes_struct *p)
 {
-       SAMR_Q_OPEN_ALIAS q_u;
-       SAMR_R_OPEN_ALIAS r_u;
+       SAMR_Q_DELETE_DOM_USER q_u;
+       SAMR_R_DELETE_DOM_USER r_u;
+
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
        ZERO_STRUCT(q_u);
        ZERO_STRUCT(r_u);
 
-       /* grab the samr open policy */
-       if(!samr_io_q_open_alias("", &q_u, data, 0)) {
-               DEBUG(0,("api_samr_open_alias: Unable to unmarshall SAMR_Q_OPEN_ALIAS.\n"));
+       if (!samr_io_q_delete_dom_user("", &q_u, data, 0)) {
                return False;
        }
 
-       r_u.status=_api_samr_open_alias(q_u.dom_pol, q_u.rid_alias, &r_u.pol);
+       r_u.status = _samr_delete_dom_user(p, &q_u, &r_u);
 
-       /* store the response in the SMB stream */
-       if(!samr_io_r_open_alias("", &r_u, rdata, 0)) {
-               DEBUG(0,("api_samr_open_alias: Unable to marshall SAMR_R_OPEN_ALIAS.\n"));
+       if (!samr_io_r_delete_dom_user("", &r_u, rdata, 0)) {
                return False;
        }
-       
+
        return True;
 }
 
 /*******************************************************************
- set_user_info_10
+ api_samr_delete_dom_group
  ********************************************************************/
-static BOOL set_user_info_10(const SAM_USER_INFO_10 *id10, uint32 rid)
+
+static BOOL api_samr_delete_dom_group(pipes_struct *p)
 {
-       SAM_ACCOUNT *pwd = pdb_getsampwrid(rid);
+       SAMR_Q_DELETE_DOM_GROUP q_u;
+       SAMR_R_DELETE_DOM_GROUP r_u;
 
-       if (id10 == NULL) {
-               DEBUG(5, ("set_user_info_10: NULL id10\n"));
-               return False;
-       }
+       prs_struct *data = &p->in_data.data;
+       prs_struct *rdata = &p->out_data.rdata;
+
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       if (pwd == NULL)
+       if (!samr_io_q_delete_dom_group("", &q_u, data, 0)) {
                return False;
+       }
 
-       pdb_set_acct_ctrl(pwd, id10->acb_info);
+       r_u.status = _samr_delete_dom_group(p, &q_u, &r_u);
 
-       if(!pdb_update_sam_account(pwd, True))
+       if (!samr_io_r_delete_dom_group("", &r_u, rdata, 0)) {
                return False;
+       }
 
        return True;
 }
 
 /*******************************************************************
- set_user_info_12
+ api_samr_delete_dom_alias
  ********************************************************************/
-static BOOL set_user_info_12(SAM_USER_INFO_12 *id12, uint32 rid)
+
+static BOOL api_samr_delete_dom_alias(pipes_struct *p)
 {
-       SAM_ACCOUNT *pwd = pdb_getsampwrid(rid);
+       SAMR_Q_DELETE_DOM_ALIAS q_u;
+       SAMR_R_DELETE_DOM_ALIAS r_u;
 
-       if (pwd == NULL)
-               return False;
+       prs_struct *data = &p->in_data.data;
+       prs_struct *rdata = &p->out_data.rdata;
 
-       if (id12 == NULL) {
-               DEBUG(2, ("set_user_info_12: id12 is NULL\n"));
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
+
+       if (!samr_io_q_delete_dom_alias("", &q_u, data, 0)) {
                return False;
        }
 
-       pdb_set_lanman_passwd (pwd, id12->lm_pwd); 
-       pdb_set_nt_passwd     (pwd, id12->nt_pwd); 
+       r_u.status = _samr_delete_dom_alias(p, &q_u, &r_u);
 
-       if(!pdb_update_sam_account(pwd, True))
+       if (!samr_io_r_delete_dom_alias("", &r_u, rdata, 0)) {
                return False;
+       }
 
        return True;
 }
 
 /*******************************************************************
- set_user_info_21
+ api_samr_create_dom_group
  ********************************************************************/
-static BOOL set_user_info_21 (SAM_USER_INFO_21 *id21, uint32 rid)
+
+static BOOL api_samr_create_dom_group(pipes_struct *p)
 {
-       SAM_ACCOUNT *pwd = pdb_getsampwrid(rid);
-       SAM_ACCOUNT new_pwd;
+       SAMR_Q_CREATE_DOM_GROUP q_u;
+       SAMR_R_CREATE_DOM_GROUP r_u;
 
-       if (id21 == NULL) {
-               DEBUG(5, ("set_user_info_21: NULL id21\n"));
-               return False;
-       }
+       prs_struct *data = &p->in_data.data;
+       prs_struct *rdata = &p->out_data.rdata;
+
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       if (pwd == NULL)
+       if (!samr_io_q_create_dom_group("", &q_u, data, 0)) {
                return False;
+       }
 
-       /* we make a copy so that we can modify stuff */        
-       copy_sam_passwd(&new_pwd, pwd);
-       copy_id21_to_sam_passwd(&new_pwd, id21);
-       
-       /*
-        * The funny part about the previous two calls is 
-        * that pwd still has the password hashes from the 
-        * passdb entry.  These have not been updated from
-        * id21.  I don't know if they need to be set.    --jerry
-        */
+       r_u.status = _samr_create_dom_group(p, &q_u, &r_u);
 
-       /* write the change out */
-       if(!pdb_update_sam_account(&new_pwd, True))
+       if (!samr_io_r_create_dom_group("", &r_u, rdata, 0)) {
                return False;
-       
+       }
+
        return True;
 }
 
 /*******************************************************************
- set_user_info_23
+ api_samr_create_dom_alias
  ********************************************************************/
-static BOOL set_user_info_23(SAM_USER_INFO_23 *id23, uint32 rid)
-{
-       SAM_ACCOUNT *pwd = pdb_getsampwrid(rid);
-       SAM_ACCOUNT new_pwd;
-       BYTE nt_hash[16];
-       BYTE lm_hash[16];
-       pstring buf;
-       uint32 len;
 
-       if (id23 == NULL) {
-               DEBUG(5, ("set_user_info_23: NULL id23\n"));
-               return False;
-       }
+static BOOL api_samr_create_dom_alias(pipes_struct *p)
+{
+       SAMR_Q_CREATE_DOM_ALIAS q_u;
+       SAMR_R_CREATE_DOM_ALIAS r_u;
 
-       if (pwd == NULL)
-               return False;
+       prs_struct *data = &p->in_data.data;
+       prs_struct *rdata = &p->out_data.rdata;
 
-       copy_sam_passwd(&new_pwd, pwd);
-       copy_id23_to_sam_passwd(&new_pwd, id23);
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       if (!decode_pw_buffer((char*)id23->pass, buf, 256, &len))
+       if (!samr_io_q_create_dom_alias("", &q_u, data, 0)) {
                return False;
+       }
 
-       nt_lm_owf_gen(buf, nt_hash, lm_hash);
-
-       pdb_set_lanman_passwd (&new_pwd, lm_hash);
-       pdb_set_nt_passwd     (&new_pwd, nt_hash);
-
-       /* update the UNIX password */
-       if (lp_unix_password_sync())
-               if(!chgpasswd(pdb_get_username(&new_pwd), "", buf, True))
-                       return False;
-
-       memset(buf, 0, sizeof(buf));
+       r_u.status = _samr_create_dom_alias(p, &q_u, &r_u);
 
-       if(!pdb_update_sam_account(&new_pwd, True))
+       if (!samr_io_r_create_dom_alias("", &r_u, rdata, 0)) {
                return False;
-       
+       }
+
        return True;
 }
 
 /*******************************************************************
- set_user_info_24
+ api_samr_query_groupinfo
  ********************************************************************/
-static BOOL set_user_info_24(const SAM_USER_INFO_24 *id24, uint32 rid)
+
+static BOOL api_samr_query_groupinfo(pipes_struct *p)
 {
-       SAM_ACCOUNT *pwd = pdb_getsampwrid(rid);
-       uchar nt_hash[16];
-       uchar lm_hash[16];
-       uint32 len;
-       pstring buf;
+       SAMR_Q_QUERY_GROUPINFO q_u;
+       SAMR_R_QUERY_GROUPINFO r_u;
 
-       if (pwd == NULL)
-               return False;
+       prs_struct *data = &p->in_data.data;
+       prs_struct *rdata = &p->out_data.rdata;
 
-       memset(buf, 0, sizeof(buf));
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       if (!decode_pw_buffer((char*)id24->pass, buf, 256, &len))
+       if (!samr_io_q_query_groupinfo("", &q_u, data, 0)) {
                return False;
+       }
 
-       DEBUG(0,("set_user_info_24:nt_lm_owf_gen\n"));
-
-       nt_lm_owf_gen(buf, nt_hash, lm_hash);
-
-       pdb_set_lanman_passwd (pwd, lm_hash);
-       pdb_set_nt_passwd     (pwd, nt_hash);
-
-       /* update the UNIX password */
-       if (lp_unix_password_sync())
-               if(!chgpasswd(pdb_get_username(pwd), "", buf, True))
-                       return False;
-
-       memset(buf, 0, sizeof(buf));
-       
-       DEBUG(0,("set_user_info_24: pdb_update_sam_account()\n"));
+       r_u.status = _samr_query_groupinfo(p, &q_u, &r_u);
 
-       /* update the SAMBA password */
-       if(!pdb_update_sam_account(pwd, True))
+       if (!samr_io_r_query_groupinfo("", &r_u, rdata, 0)) {
                return False;
+       }
 
        return True;
 }
 
 /*******************************************************************
samr_reply_set_userinfo
api_samr_set_groupinfo
  ********************************************************************/
-static uint32 _samr_set_userinfo(POLICY_HND *pol, uint16 switch_value, 
-                                 SAM_USERINFO_CTR *ctr, pipes_struct *p)
-{
-       uint32 rid = 0x0;
-       DOM_SID sid;
-       struct current_user user;
-       SAM_ACCOUNT *sam_pass;
-       unsigned char sess_key[16];
-
-       DEBUG(5, ("_samr_set_userinfo: %d\n", __LINE__));
-
-       if (p->ntlmssp_auth_validated) 
-       {
-               memcpy(&user, &p->pipe_user, sizeof(user));
-       } 
-       else 
-       {
-               extern struct current_user current_user;
-               memcpy(&user, &current_user, sizeof(user));
-       }
 
-       /* search for the handle */
-       if (find_lsa_policy_by_hnd(pol) == -1)
-               return NT_STATUS_INVALID_HANDLE;
-
-       /* find the policy handle.  open a policy on it. */
-       if (!get_lsa_policy_samr_sid(pol, &sid))
-               return NT_STATUS_INVALID_HANDLE;
+static BOOL api_samr_set_groupinfo(pipes_struct *p)
+{
+       SAMR_Q_SET_GROUPINFO q_u;
+       SAMR_R_SET_GROUPINFO r_u;
 
-       sid_split_rid(&sid, &rid);
+       prs_struct *data = &p->in_data.data;
+       prs_struct *rdata = &p->out_data.rdata;
 
-       DEBUG(5, ("_samr_set_userinfo: rid:0x%x, level:%d\n", rid, switch_value));
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       if (ctr == NULL) {
-               DEBUG(5, ("_samr_set_userinfo: NULL info level\n"));
-               return NT_STATUS_INVALID_INFO_CLASS;
+       if (!samr_io_q_set_groupinfo("", &q_u, data, 0)) {
+               return False;
        }
 
+       r_u.status = _samr_set_groupinfo(p, &q_u, &r_u);
 
-       /* 
-        * We need the NT hash of the user who is changing the user's password.
-        * This NT hash is used to generate a "user session key"
-        * This "user session key" is in turn used to encrypt/decrypt the user's password.
-        */
-
-       become_root();
-       sam_pass = pdb_getsampwuid(user.uid);
-       unbecome_root();
-       if(sam_pass == NULL) {
-               DEBUG(0,("_samr_set_userinfo: Unable to get passdb entry for uid %u\n", 
-                       (unsigned int)pdb_get_uid(sam_pass) ));
-               return NT_STATUS_ACCESS_DENIED;
-       }
-               
-       memset(sess_key, '\0', 16);
-       mdfour(sess_key, pdb_get_nt_passwd(sam_pass), 16);
-
-       /* ok!  user info levels (lots: see MSDEV help), off we go... */
-       switch (switch_value) {
-               case 0x12:
-                       if (!set_user_info_12(ctr->info.id12, rid))
-                               return NT_STATUS_ACCESS_DENIED;
-                       break;
-
-               case 24:
-                       SamOEMhash(ctr->info.id24->pass, sess_key, 1);
-                       if (!set_user_info_24(ctr->info.id24, rid))
-                               return NT_STATUS_ACCESS_DENIED;
-                       break;
-
-               case 23:
-                       SamOEMhash(ctr->info.id23->pass, sess_key, 1);
-                       if (!set_user_info_23(ctr->info.id23, rid))
-                               return NT_STATUS_ACCESS_DENIED;
-                       break;
-
-               default:
-                       return NT_STATUS_INVALID_INFO_CLASS;
+       if (!samr_io_r_set_groupinfo("", &r_u, rdata, 0)) {
+               return False;
        }
 
-       return NT_STATUS_NOPROBLEMO;
+       return True;
 }
 
 /*******************************************************************
- api_samr_set_userinfo
+ api_samr_get_dom_pwinfo
  ********************************************************************/
-static BOOL api_samr_set_userinfo(pipes_struct *p)
+
+static BOOL api_samr_get_dom_pwinfo(pipes_struct *p)
 {
-       SAMR_Q_SET_USERINFO q_u;
-       SAMR_R_SET_USERINFO r_u;
+       SAMR_Q_GET_DOM_PWINFO q_u;
+       SAMR_R_GET_DOM_PWINFO r_u;
 
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
 
-       SAM_USERINFO_CTR ctr;
-
        ZERO_STRUCT(q_u);
        ZERO_STRUCT(r_u);
 
-       q_u.ctr = &ctr;
-
-       if (!samr_io_q_set_userinfo("", &q_u, data, 0)) {
-               DEBUG(0,("api_samr_set_userinfo: Unable to unmarshall SAMR_Q_SET_USERINFO.\n"));
+       if (!samr_io_q_get_dom_pwinfo("", &q_u, data, 0)) {
                return False;
        }
 
-       r_u.status = _samr_set_userinfo(&q_u.pol, q_u.switch_value, &ctr, p);
+       r_u.status = _samr_get_dom_pwinfo(p, &q_u, &r_u);
 
-       free_samr_q_set_userinfo(&q_u);
-       
-       if(!samr_io_r_set_userinfo("", &r_u, rdata, 0)) {
-               DEBUG(0,("api_samr_set_userinfo: Unable to marshall SAMR_R_SET_USERINFO.\n"));
+       if (!samr_io_r_get_dom_pwinfo("", &r_u, rdata, 0)) {
                return False;
        }
 
@@ -2482,59 +1136,41 @@ static BOOL api_samr_set_userinfo(pipes_struct *p)
 }
 
 /*******************************************************************
- samr_reply_set_userinfo2
+ api_samr_open_group
  ********************************************************************/
-static uint32 _samr_set_userinfo2(POLICY_HND *pol, uint16 switch_value, SAM_USERINFO_CTR *ctr)
-{
-       DOM_SID sid;
-       uint32 rid = 0x0;
 
-       DEBUG(5, ("samr_reply_set_userinfo2: %d\n", __LINE__));
-
-       /* search for the handle */
-       if (find_lsa_policy_by_hnd(pol) == -1)
-               return NT_STATUS_INVALID_HANDLE;
-
-       /* find the policy handle.  open a policy on it. */
-       if (!get_lsa_policy_samr_sid(pol, &sid))
-               return NT_STATUS_INVALID_HANDLE;
+static BOOL api_samr_open_group(pipes_struct *p)
+{
+       SAMR_Q_OPEN_GROUP q_u;
+       SAMR_R_OPEN_GROUP r_u;
 
-       sid_split_rid(&sid, &rid);
+       prs_struct *data = &p->in_data.data;
+       prs_struct *rdata = &p->out_data.rdata;
 
-       DEBUG(5, ("samr_reply_set_userinfo2: rid:0x%x\n", rid));
+       ZERO_STRUCT(q_u);
+       ZERO_STRUCT(r_u);
 
-       if (ctr == NULL) {
-               DEBUG(5, ("samr_reply_set_userinfo2: NULL info level\n"));
-               return NT_STATUS_INVALID_INFO_CLASS;
+       if (!samr_io_q_open_group("", &q_u, data, 0)) {
+               return False;
        }
 
-       ctr->switch_value = switch_value;
-
-       /* ok!  user info levels (lots: see MSDEV help), off we go... */
-       switch (switch_value) {
-               case 21:
-                       if (!set_user_info_21(ctr->info.id21, rid))
-                               return NT_STATUS_ACCESS_DENIED;
-                       break;
-               case 16:
-                       if (!set_user_info_10(ctr->info.id10, rid))
-                               return NT_STATUS_ACCESS_DENIED;
-                       break;
-               default:
-                       return NT_STATUS_INVALID_INFO_CLASS;
+       r_u.status = _samr_open_group(p, &q_u, &r_u);
+
+       if (!samr_io_r_open_group("", &r_u, rdata, 0)) {
+               return False;
        }
 
-       return NT_STATUS_NOPROBLEMO;
+       return True;
 }
 
 /*******************************************************************
- api_samr_set_userinfo2
+ api_samr_unknown_2d
  ********************************************************************/
-static BOOL api_samr_set_userinfo2(pipes_struct *p)
+
+static BOOL api_samr_unknown_2d(pipes_struct *p)
 {
-       SAMR_Q_SET_USERINFO2 q_u;
-       SAMR_R_SET_USERINFO2 r_u;
-       SAM_USERINFO_CTR ctr;
+       SAMR_Q_UNKNOWN_2D q_u;
+       SAMR_R_UNKNOWN_2D r_u;
 
        prs_struct *data = &p->in_data.data;
        prs_struct *rdata = &p->out_data.rdata;
@@ -2542,31 +1178,77 @@ static BOOL api_samr_set_userinfo2(pipes_struct *p)
        ZERO_STRUCT(q_u);
        ZERO_STRUCT(r_u);
 
-       q_u.ctr = &ctr;
-
-       if (!samr_io_q_set_userinfo2("", &q_u, data, 0)) {
-               DEBUG(0,("api_samr_set_userinfo2: Unable to unmarshall SAMR_Q_SET_USERINFO2.\n"));
+       if (!samr_io_q_unknown_2d("", &q_u, data, 0)) {
                return False;
        }
 
-       r_u.status = _samr_set_userinfo2(&q_u.pol, q_u.switch_value, &ctr);
-
-       free_samr_q_set_userinfo2(&q_u);
+       r_u.status = _samr_unknown_2d(p, &q_u, &r_u);
 
-       if(!samr_io_r_set_userinfo2("", &r_u, rdata, 0)) {
-               DEBUG(0,("api_samr_set_userinfo2: Unable to marshall SAMR_R_SET_USERINFO2.\n"));
+       if (!samr_io_r_unknown_2d("", &r_u, rdata, 0)) {
                return False;
        }
 
        return True;
 }
 
-
 /*******************************************************************
  array of \PIPE\samr operations
  ********************************************************************/
+
 static struct api_struct api_samr_cmds [] =
 {
+       {"SAMR_CLOSE_HND", SAMR_CLOSE_HND, api_samr_close_hnd},
+       {"SAMR_CONNECT", SAMR_CONNECT, api_samr_connect},
+       {"SAMR_CONNECT_ANON", SAMR_CONNECT_ANON, api_samr_connect_anon},
+       {"SAMR_ENUM_DOMAINS", SAMR_ENUM_DOMAINS, api_samr_enum_domains},
+       {"SAMR_ENUM_DOM_USERS", SAMR_ENUM_DOM_USERS, api_samr_enum_dom_users},
+
+       {"SAMR_ENUM_DOM_GROUPS", SAMR_ENUM_DOM_GROUPS, api_samr_enum_dom_groups},
+       {"SAMR_ENUM_DOM_ALIASES", SAMR_ENUM_DOM_ALIASES, api_samr_enum_dom_aliases},
+       {"SAMR_QUERY_USERALIASES", SAMR_QUERY_USERALIASES, api_samr_query_useraliases},
+       {"SAMR_QUERY_ALIASMEM", SAMR_QUERY_ALIASMEM, api_samr_query_aliasmem},
+       {"SAMR_QUERY_GROUPMEM", SAMR_QUERY_GROUPMEM, api_samr_query_groupmem},
+       {"SAMR_ADD_ALIASMEM", SAMR_ADD_ALIASMEM, api_samr_add_aliasmem},
+       {"SAMR_DEL_ALIASMEM", SAMR_DEL_ALIASMEM, api_samr_del_aliasmem},
+       {"SAMR_ADD_GROUPMEM", SAMR_ADD_GROUPMEM, api_samr_add_groupmem},
+       {"SAMR_DEL_GROUPMEM", SAMR_DEL_GROUPMEM, api_samr_del_groupmem},
+
+       {"SAMR_DELETE_DOM_USER", SAMR_DELETE_DOM_USER, api_samr_delete_dom_user},
+       {"SAMR_DELETE_DOM_GROUP", SAMR_DELETE_DOM_GROUP, api_samr_delete_dom_group},
+       {"SAMR_DELETE_DOM_ALIAS", SAMR_DELETE_DOM_ALIAS, api_samr_delete_dom_alias},
+       {"SAMR_CREATE_DOM_GROUP", SAMR_CREATE_DOM_GROUP, api_samr_create_dom_group},
+       {"SAMR_CREATE_DOM_ALIAS", SAMR_CREATE_DOM_ALIAS, api_samr_create_dom_alias},
+       {"SAMR_LOOKUP_NAMES", SAMR_LOOKUP_NAMES, api_samr_lookup_names},
+       {"SAMR_OPEN_USER", SAMR_OPEN_USER, api_samr_open_user},
+       {"SAMR_QUERY_USERINFO", SAMR_QUERY_USERINFO, api_samr_query_userinfo},
+       {"SAMR_SET_USERINFO", SAMR_SET_USERINFO, api_samr_set_userinfo},
+       {"SAMR_SET_USERINFO2", SAMR_SET_USERINFO2, api_samr_set_userinfo2},
+
+       {"SAMR_QUERY_DOMAIN_INFO", SAMR_QUERY_DOMAIN_INFO, api_samr_query_dom_info},
+       {"SAMR_QUERY_USERGROUPS", SAMR_QUERY_USERGROUPS, api_samr_query_usergroups},
+       {"SAMR_QUERY_DISPINFO", SAMR_QUERY_DISPINFO, api_samr_query_dispinfo},
+       {"SAMR_QUERY_DISPINFO3", SAMR_QUERY_DISPINFO3, api_samr_query_dispinfo},
+       {"SAMR_QUERY_DISPINFO4", SAMR_QUERY_DISPINFO4, api_samr_query_dispinfo},
+
+       {"SAMR_QUERY_ALIASINFO", SAMR_QUERY_ALIASINFO, api_samr_query_aliasinfo},
+       {"SAMR_QUERY_GROUPINFO", SAMR_QUERY_GROUPINFO, api_samr_query_groupinfo},
+       {"SAMR_SET_GROUPINFO", SAMR_SET_GROUPINFO, api_samr_set_groupinfo},
+       {"SAMR_CREATE_USER", SAMR_CREATE_USER, api_samr_create_user},
+       {"SAMR_LOOKUP_RIDS", SAMR_LOOKUP_RIDS, api_samr_lookup_rids},
+       {"SAMR_GET_DOM_PWINFO", SAMR_GET_DOM_PWINFO, api_samr_get_dom_pwinfo},
+       {"SAMR_CHGPASSWD_USER", SAMR_CHGPASSWD_USER, api_samr_chgpasswd_user},
+       {"SAMR_OPEN_ALIAS", SAMR_OPEN_ALIAS, api_samr_open_alias},
+       {"SAMR_OPEN_GROUP", SAMR_OPEN_GROUP, api_samr_open_group},
+       {"SAMR_OPEN_DOMAIN", SAMR_OPEN_DOMAIN, api_samr_open_domain},
+       {"SAMR_UNKNOWN_2D", SAMR_UNKNOWN_2D, api_samr_unknown_2d},
+       {"SAMR_LOOKUP_DOMAIN", SAMR_LOOKUP_DOMAIN, api_samr_lookup_domain},
+
+       {"SAMR_QUERY_SEC_OBJECT", SAMR_QUERY_SEC_OBJECT, api_samr_query_sec_obj},
+       {"SAMR_GET_USRDOM_PWINFO", SAMR_GET_USRDOM_PWINFO, api_samr_get_usrdom_pwinfo},
+       {NULL, 0, NULL}
+
+#if 0
+
        { "SAMR_CLOSE_HND"        , SAMR_CLOSE_HND        , api_samr_close_hnd        },
        { "SAMR_CONNECT"          , SAMR_CONNECT          , api_samr_connect          },
        { "SAMR_CONNECT_ANON"     , SAMR_CONNECT_ANON     , api_samr_connect_anon     },
@@ -2587,13 +1269,14 @@ static struct api_struct api_samr_cmds [] =
        { "SAMR_CHGPASSWD_USER"   , SAMR_CHGPASSWD_USER   , api_samr_chgpasswd_user   },
        { "SAMR_OPEN_ALIAS"       , SAMR_OPEN_ALIAS       , api_samr_open_alias       },
        { "SAMR_OPEN_DOMAIN"      , SAMR_OPEN_DOMAIN      , api_samr_open_domain      },
-       { "SAMR_UNKNOWN_3"        , SAMR_UNKNOWN_3        , api_samr_unknown_3        },
-       { "SAMR_UNKNOWN_2C"       , SAMR_UNKNOWN_2C       , api_samr_unknown_2c       },
+       { "SAMR_QUERY_SEC_OBJECT" , SAMR_QUERY_SEC_OBJECT , api_samr_query_sec_obj    },
+       { "SAMR_GET_USRDOM_PWINFO", SAMR_GET_USRDOM_PWINFO, api_samr_get_usrdom_pwinfo},
        { "SAMR_LOOKUP_DOMAIN"    , SAMR_LOOKUP_DOMAIN    , api_samr_lookup_domain    },
        { "SAMR_ENUM_DOMAINS"     , SAMR_ENUM_DOMAINS     , api_samr_enum_domains     },
        { "SAMR_SET_USERINFO"     , SAMR_SET_USERINFO     , api_samr_set_userinfo     },
        { "SAMR_SET_USERINFO2"    , SAMR_SET_USERINFO2    , api_samr_set_userinfo2    },
        { NULL                    , 0                     , NULL                      }
+#endif
 };
 
 /*******************************************************************
@@ -2603,4 +1286,3 @@ BOOL api_samr_rpc(pipes_struct *p)
 {
        return api_rpcTNP(p, "api_samr_rpc", api_samr_cmds);
 }
-#undef OLD_NTDOMAIN
index bd04b40c4d65a83b062a47ac3680f4af340e5fc4..ff484a8ff1424fe59043c6c3ed08f3caaf47ee51 100644 (file)
@@ -39,6 +39,23 @@ extern rid_name domain_group_rids[];
 extern rid_name domain_alias_rids[];
 extern rid_name builtin_alias_rids[];
 
+struct samr_info {
+    /* for use by the \PIPE\samr policy */
+    DOM_SID sid;
+    uint32 status; /* some sort of flag.  best to record it.  comes from opnum 0x39 */
+};
+
+/*******************************************************************
+ Function to free the per handle data.
+ ********************************************************************/
+
+static void free_samr_info(void *ptr)
+{
+       struct samr_info *samr = (struct samr_info *)ptr;
+
+       safe_free(samr);
+}
+
 /*******************************************************************
   This next function should be replaced with something that
   dynamically returns the correct user info..... JRA.
@@ -48,8 +65,7 @@ static BOOL get_sampwd_entries(SAM_USER_INFO_21 *pw_buf, int start_idx,
                                 int *total_entries, int *num_entries,
                                 int max_num_entries, uint16 acb_mask)
 {
-    void *vp = NULL;
-    struct sam_passwd *pwd = NULL;
+    SAM_ACCOUNT *pwd = NULL;
 
     (*num_entries) = 0;
     (*total_entries) = 0;
@@ -57,13 +73,12 @@ static BOOL get_sampwd_entries(SAM_USER_INFO_21 *pw_buf, int start_idx,
     if (pw_buf == NULL)
         return False;
 
-    vp = startsmbpwent(False);
-    if (!vp) {
-        DEBUG(0, ("get_sampwd_entries: Unable to open SMB password database.\n"));
+       if (!pdb_setsampwent(False)) {
+        DEBUG(0, ("get_sampwd_entries: Unable to open passdb.\n"));
         return False;
     }
 
-    while (((pwd = getsam21pwent(vp)) != NULL) && (*num_entries) < max_num_entries) {
+    while (((pwd = pdb_getsampwent()) != NULL) && (*num_entries) < max_num_entries) {
         int user_name_len;
 
         if (start_idx > 0) {
@@ -74,21 +89,20 @@ static BOOL get_sampwd_entries(SAM_USER_INFO_21 *pw_buf, int start_idx,
             continue;
         }
 
-        user_name_len = strlen(pwd->smb_name)+1;
-        init_unistr2(&pw_buf[(*num_entries)].uni_user_name, pwd->smb_name, user_name_len);
+        user_name_len = strlen(pdb_get_username(pwd))+1;
+        init_unistr2(&pw_buf[(*num_entries)].uni_user_name, pdb_get_username(pwd), user_name_len);
         init_uni_hdr(&pw_buf[(*num_entries)].hdr_user_name, user_name_len);
         pw_buf[(*num_entries)].user_rid = pwd->user_rid;
         memset((char *)pw_buf[(*num_entries)].nt_pwd, '\0', 16);
 
         /* Now check if the NT compatible password is available. */
-        if (pwd->smb_nt_passwd != NULL) {
-            memcpy( pw_buf[(*num_entries)].nt_pwd , pwd->smb_nt_passwd, 16);
-        }
+        if (pdb_get_nt_passwd(pwd))
+            memcpy( pw_buf[(*num_entries)].nt_pwd , pdb_get_nt_passwd(pwd), 16);
 
-        pw_buf[(*num_entries)].acb_info = (uint16)pwd->acct_ctrl;
+        pw_buf[(*num_entries)].acb_info = pdb_get_acct_ctrl(pwd);
 
         DEBUG(5, ("entry idx: %d user %s, rid 0x%x, acb %x",
-                  (*num_entries), pwd->smb_name, pwd->user_rid, pwd->acct_ctrl));
+                  (*num_entries), pdb_get_username(pwd), pdb_get_user_rid(pwd), pdb_get_acct_ctrl(pwd) ));
 
         if (acb_mask == 0 || (pwd->acct_ctrl & acb_mask)) {
             DEBUG(5,(" acb_mask %x accepts\n", acb_mask));
@@ -100,17 +114,16 @@ static BOOL get_sampwd_entries(SAM_USER_INFO_21 *pw_buf, int start_idx,
         (*total_entries)++;
     }
 
-    endsmbpwent(vp);
+    pdb_endsampwent();
 
     return (*num_entries) > 0;
 }
 
 static BOOL jf_get_sampwd_entries(SAM_USER_INFO_21 *pw_buf, int start_idx,
-                                int *total_entries, int *num_entries,
+                                int *total_entries, uint32 *num_entries,
                                 int max_num_entries, uint16 acb_mask)
 {
-       void *vp = NULL;
-       struct sam_passwd *pwd = NULL;
+    SAM_ACCOUNT *pwd = NULL;
 
        *num_entries = 0;
        *total_entries = 0;
@@ -118,17 +131,16 @@ static BOOL jf_get_sampwd_entries(SAM_USER_INFO_21 *pw_buf, int start_idx,
        if (pw_buf == NULL)
                return False;
 
-       vp = startsmbpwent(False);
-       if (!vp) {
-               DEBUG(0, ("get_sampwd_entries: Unable to open SMB password database.\n"));
-               return False;
-       }
+       if (!pdb_setsampwent(False)) {
+        DEBUG(0, ("jf_get_sampwd_entries: Unable to open passdb.\n"));
+        return False;
+    }
 
-       while (((pwd = getsam21pwent(vp)) != NULL) && (*num_entries) < max_num_entries) {
+       while (((pwd = pdb_getsampwent()) != NULL) && (*num_entries) < max_num_entries) {
                int user_name_len;
                int full_name_len;
 
-               if (acb_mask != 0 && !(pwd->acct_ctrl & acb_mask))
+               if (acb_mask != 0 && !(pdb_get_acct_ctrl(pwd) & acb_mask))
                        continue;
 
                if (start_idx > 0) {
@@ -141,29 +153,29 @@ static BOOL jf_get_sampwd_entries(SAM_USER_INFO_21 *pw_buf, int start_idx,
 
                ZERO_STRUCTP(&pw_buf[(*num_entries)]);
 
-               user_name_len = strlen(pwd->smb_name);
-               init_unistr2(&pw_buf[(*num_entries)].uni_user_name, pwd->smb_name, user_name_len);
+               user_name_len = strlen(pdb_get_username(pwd));
+               init_unistr2(&pw_buf[(*num_entries)].uni_user_name, pdb_get_username(pwd), user_name_len);
                init_uni_hdr(&pw_buf[(*num_entries)].hdr_user_name, user_name_len);
 
-               full_name_len = strlen(pwd->full_name);
-               init_unistr2(&pw_buf[(*num_entries)].uni_full_name, pwd->full_name, full_name_len);
+               full_name_len = strlen(pdb_get_fullname(pwd));
+               init_unistr2(&pw_buf[(*num_entries)].uni_full_name, pdb_get_fullname(pwd), full_name_len);
                init_uni_hdr(&pw_buf[(*num_entries)].hdr_full_name, full_name_len);
 
-               pw_buf[(*num_entries)].user_rid = pwd->user_rid;
+               pw_buf[(*num_entries)].user_rid = pdb_get_user_rid(pwd);
                memset((char *)pw_buf[(*num_entries)].nt_pwd, '\0', 16);
 
                /* Now check if the NT compatible password is available. */
-               if (pwd->smb_nt_passwd != NULL) {
-                       memcpy( pw_buf[(*num_entries)].nt_pwd , pwd->smb_nt_passwd, 16);
-               }
+        if (pdb_get_nt_passwd(pwd))
+            memcpy( pw_buf[(*num_entries)].nt_pwd , pdb_get_nt_passwd(pwd), 16);
 
-               pw_buf[(*num_entries)].acb_info = (uint16)pwd->acct_ctrl;
+               pw_buf[(*num_entries)].acb_info = pdb_get_acct_ctrl(pwd);
 
-               DEBUG(5, ("entry idx: %d user %s, rid 0x%x, acb %x\n", (*num_entries), pwd->smb_name, pwd->user_rid, pwd->acct_ctrl));
+               DEBUG(5, ("entry idx: %d user %s, rid 0x%x, acb %x\n", (*num_entries),
+                  pdb_get_username(pwd), pdb_get_user_rid(pwd), pdb_get_acct_ctrl(pwd) ));
                (*num_entries)++;
        }
 
-       endsmbpwent(vp);
+    pdb_endsampwent();
 
        *total_entries = *num_entries;
        return True;
@@ -425,7 +437,7 @@ uint32 _samr_close_hnd(pipes_struct *p, SAMR_Q_CLOSE_HND *q_u, SAMR_R_CLOSE_HND
        r_u->status = NT_STATUS_NOPROBLEMO;
 
        /* close the policy handle */
-       if (!close_lsa_policy_hnd(&q_u->pol))
+       if (!close_policy_hnd(p, &q_u->pol))
                return NT_STATUS_OBJECT_NAME_INVALID;
 
        DEBUG(5,("samr_reply_close_hnd: %d\n", __LINE__));
@@ -439,42 +451,57 @@ uint32 _samr_close_hnd(pipes_struct *p, SAMR_Q_CLOSE_HND *q_u, SAMR_R_CLOSE_HND
 
 uint32 _samr_open_domain(pipes_struct *p, SAMR_Q_OPEN_DOMAIN *q_u, SAMR_R_OPEN_DOMAIN *r_u)
 {
+       struct samr_info *info;
+
        r_u->status = NT_STATUS_NOPROBLEMO;
 
        /* find the connection policy handle. */
-       if (find_lsa_policy_by_hnd(&q_u->pol) == -1)
+       if (!find_policy_by_hnd(p, &q_u->pol, NULL))
                return NT_STATUS_INVALID_HANDLE;
 
-       /* get a (unique) handle.  open a policy on it. */
-       if (!open_lsa_policy_hnd(&r_u->domain_pol))
-               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
-
        /* associate the domain SID with the (unique) handle. */
-       if (!set_lsa_policy_samr_sid(&r_u->domain_pol, &q_u->dom_sid.sid)) {
-               close_lsa_policy_hnd(&r_u->domain_pol);
+       if ((info = (struct samr_info *)malloc(sizeof(struct samr_info))) == NULL)
+               return NT_STATUS_NO_MEMORY;
+
+       ZERO_STRUCTP(info);
+       info->sid = q_u->dom_sid.sid;
+
+       /* get a (unique) handle.  open a policy on it. */
+       if (!create_policy_hnd(p, &r_u->domain_pol, free_samr_info, (void *)info))
                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
-       }
 
        DEBUG(5,("samr_open_domain: %d\n", __LINE__));
 
        return r_u->status;
 }
 
+static uint32 get_lsa_policy_samr_rid(struct samr_info *info)
+{
+       if (!info) {
+       DEBUG(3,("Error getting policy\n"));
+           return 0xffffffff;
+       }
+
+       return info->sid.sub_auths[info->sid.num_auths-1];
+}
+
 /*******************************************************************
  _samr_get_usrdom_pwinfo
  ********************************************************************/
 
 uint32 _samr_get_usrdom_pwinfo(pipes_struct *p, SAMR_Q_GET_USRDOM_PWINFO *q_u, SAMR_R_GET_USRDOM_PWINFO *r_u)
 {
+       struct samr_info *info = NULL;
+
        r_u->status = NT_STATUS_NOPROBLEMO;
 
        /* find the policy handle.  open a policy on it. */
-       if (find_lsa_policy_by_hnd(&q_u->user_pol) == -1) {
+       if (!find_policy_by_hnd(p, &q_u->user_pol, (void **)&info)) {
                return NT_STATUS_INVALID_HANDLE;
        }
 
        /* find the user's rid */
-       if (get_lsa_policy_samr_rid(&q_u->user_pol) == 0xffffffff) {
+       if (get_lsa_policy_samr_rid(info) == 0xffffffff) {
                return NT_STATUS_OBJECT_TYPE_MISMATCH;
        }
 
@@ -531,6 +558,21 @@ static uint32 samr_make_usr_obj_sd(TALLOC_CTX *ctx, SEC_DESC_BUF **buf, DOM_SID
        return NT_STATUS_NOPROBLEMO;
 }
 
+static BOOL get_lsa_policy_samr_sid(pipes_struct *p, POLICY_HND *pol, DOM_SID *sid)
+{
+       struct samr_info *info = NULL;
+
+       /* find the policy handle.  open a policy on it. */
+       if (!find_policy_by_hnd(p, pol, (void **)&info))
+               return False;
+
+       if (!info)
+               return False;
+
+       *sid = info->sid;
+       return True;
+}
+
 /*******************************************************************
  _samr_query_sec_obj
  ********************************************************************/
@@ -541,13 +583,10 @@ uint32 _samr_query_sec_obj(pipes_struct *p, SAMR_Q_QUERY_SEC_OBJ *q_u, SAMR_R_QU
 
        r_u->status = NT_STATUS_NOPROBLEMO;
 
-       /* find the policy handle.  open a policy on it. */
-       if ((find_lsa_policy_by_hnd(&q_u->user_pol)) == -1)
-               return NT_STATUS_INVALID_HANDLE;
-
        /* Get the SID. */
-       if (!get_lsa_policy_samr_sid(&q_u->user_pol, &pol_sid))
-               return NT_STATUS_OBJECT_TYPE_MISMATCH;
+
+       if (!get_lsa_policy_samr_sid(p, &q_u->user_pol, &pol_sid))
+               return NT_STATUS_INVALID_HANDLE;
 
        r_u->status = samr_make_usr_obj_sd(p->mem_ctx, &r_u->buf, &pol_sid);
 
@@ -608,7 +647,7 @@ uint32 _samr_enum_dom_users(pipes_struct *p, SAMR_Q_ENUM_DOM_USERS *q_u, SAMR_R_
        r_u->status = NT_STATUS_NOPROBLEMO;
 
        /* find the policy handle.  open a policy on it. */
-       if (find_lsa_policy_by_hnd(&q_u->pol) == -1)
+       if (!find_policy_by_hnd(p, &q_u->pol, NULL))
                return NT_STATUS_INVALID_HANDLE;
 
        DEBUG(5,("_samr_enum_dom_users: %d\n", __LINE__));
@@ -808,12 +847,12 @@ static BOOL get_group_domain_entries(DOMAIN_GRP *d_grp, DOM_SID *sid, uint32 sta
 uint32 _samr_enum_dom_groups(pipes_struct *p, SAMR_Q_ENUM_DOM_GROUPS *q_u, SAMR_R_ENUM_DOM_GROUPS *r_u)
 {
        DOMAIN_GRP grp[2];
-       int num_entries;
+       uint32 num_entries;
        DOM_SID sid;
 
        r_u->status = NT_STATUS_NOPROBLEMO;
 
-       if (!get_lsa_policy_samr_sid(&q_u->pol, &sid))
+       if (!get_lsa_policy_samr_sid(p, &q_u->pol, &sid))
                return NT_STATUS_INVALID_HANDLE;
 
        DEBUG(5,("samr_reply_enum_dom_groups: %d\n", __LINE__));
@@ -837,14 +876,13 @@ uint32 _samr_enum_dom_groups(pipes_struct *p, SAMR_Q_ENUM_DOM_GROUPS *q_u, SAMR_
 uint32 _samr_enum_dom_aliases(pipes_struct *p, SAMR_Q_ENUM_DOM_ALIASES *q_u, SAMR_R_ENUM_DOM_ALIASES *r_u)
 {
        DOMAIN_GRP grp[MAX_SAM_ENTRIES];
-       int num_entries = 0;
+       uint32 num_entries = 0;
        fstring sid_str;
        DOM_SID sid;
        
        r_u->status = NT_STATUS_NOPROBLEMO;
 
-       /* find the policy handle.  open a policy on it. */
-       if (!get_lsa_policy_samr_sid(&q_u->pol, &sid))
+       if (!get_lsa_policy_samr_sid(p, &q_u->pol, &sid))
                return NT_STATUS_INVALID_HANDLE;
 
        sid_to_string(sid_str, &sid);
@@ -871,7 +909,7 @@ uint32 _samr_query_dispinfo(pipes_struct *p, SAMR_Q_QUERY_DISPINFO *q_u, SAMR_R_
        SAM_USER_INFO_21 pass[MAX_SAM_ENTRIES];
        DOMAIN_GRP grps[MAX_SAM_ENTRIES];
        uint16 acb_mask = ACB_NORMAL;
-    int num_entries = 0;
+    uint32 num_entries = 0;
     int orig_num_entries = 0;
     int total_entries = 0;
     uint32 data_size = 0;
@@ -883,7 +921,7 @@ uint32 _samr_query_dispinfo(pipes_struct *p, SAMR_Q_QUERY_DISPINFO *q_u, SAMR_R_
 
        r_u->status = NT_STATUS_NOPROBLEMO;
 
-       if (!get_lsa_policy_samr_sid(&q_u->domain_pol, &sid))
+       if (!get_lsa_policy_samr_sid(p, &q_u->domain_pol, &sid))
                return NT_STATUS_INVALID_HANDLE;
 
        /* decide how many entries to get depending on the max_entries
@@ -994,21 +1032,22 @@ uint32 _samr_query_aliasinfo(pipes_struct *p, SAMR_Q_QUERY_ALIASINFO *q_u, SAMR_
        fstring alias="";
        enum SID_NAME_USE type;
        uint32 alias_rid;
+       struct samr_info *info = NULL;
 
        r_u->status = NT_STATUS_NOPROBLEMO;
 
        DEBUG(5,("_samr_query_aliasinfo: %d\n", __LINE__));
 
        /* find the policy handle.  open a policy on it. */
-       if (find_lsa_policy_by_hnd(&q_u->pol) == -1)
+       if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info))
                return NT_STATUS_INVALID_HANDLE;
 
-       alias_rid = get_lsa_policy_samr_rid(&q_u->pol);
+       alias_rid = get_lsa_policy_samr_rid(info);
        if(alias_rid == 0xffffffff)
                return NT_STATUS_NO_SUCH_ALIAS;
 
        if(!local_lookup_rid(alias_rid, alias, &type))
-       return NT_STATUS_NO_SUCH_ALIAS;
+               return NT_STATUS_NO_SUCH_ALIAS;
 
        switch (q_u->switch_level) {
        case 3:
@@ -1104,7 +1143,7 @@ uint32 _samr_lookup_names(pipes_struct *p, SAMR_Q_LOOKUP_NAMES *q_u, SAMR_R_LOOK
     ZERO_ARRAY(rid);
     ZERO_ARRAY(type);
 
-    if (!get_lsa_policy_samr_sid(&q_u->pol, &pol_sid)) {
+    if (!get_lsa_policy_samr_sid(p, &q_u->pol, &pol_sid)) {
         init_samr_r_lookup_names(p->mem_ctx, r_u, 0, NULL, NULL, NT_STATUS_OBJECT_TYPE_MISMATCH);
         return r_u->status;
     }
@@ -1135,7 +1174,7 @@ uint32 _samr_lookup_names(pipes_struct *p, SAMR_Q_LOOKUP_NAMES *q_u, SAMR_R_LOOK
         }
     }
 
-    init_samr_r_lookup_names(p->mem_ctx, r_u, num_rids, rid, type, r_u->status);
+    init_samr_r_lookup_names(p->mem_ctx, r_u, num_rids, rid, (uint32 *)type, r_u->status);
 
     DEBUG(5,("_samr_lookup_names: %d\n", __LINE__));
 
@@ -1227,7 +1266,7 @@ uint32 _samr_lookup_rids(pipes_struct *p, SAMR_Q_LOOKUP_RIDS *q_u, SAMR_R_LOOKUP
        DEBUG(5,("_samr_lookup_rids: %d\n", __LINE__));
 
        /* find the policy handle.  open a policy on it. */
-       if (!get_lsa_policy_samr_sid(&q_u->pol, &pol_sid))
+       if (!get_lsa_policy_samr_sid(p, &q_u->pol, &pol_sid))
                return NT_STATUS_INVALID_HANDLE;
 
        if (num_rids > MAX_SAM_ENTRIES) {
@@ -1274,50 +1313,45 @@ uint32 _samr_lookup_rids(pipes_struct *p, SAMR_Q_LOOKUP_RIDS *q_u, SAMR_R_LOOKUP
 
 uint32 _api_samr_open_user(pipes_struct *p, SAMR_Q_OPEN_USER *q_u, SAMR_R_OPEN_USER *r_u)
 {
-    struct sam_passwd *sam_pass;
+    SAM_ACCOUNT *sampass;
     DOM_SID sid;
     POLICY_HND domain_pol = q_u->domain_pol;
     uint32 user_rid = q_u->user_rid;
     POLICY_HND *user_pol = &r_u->user_pol;
+       struct samr_info *info = NULL;
 
     r_u->status = NT_STATUS_NO_PROBLEMO;
 
     /* find the domain policy handle. */
-    if (find_lsa_policy_by_hnd(&domain_pol) == -1)
+    if (!find_policy_by_hnd(p, &domain_pol, NULL))
         return NT_STATUS_INVALID_HANDLE;
 
-    /* get a (unique) handle.  open a policy on it. */
-    if (!open_lsa_policy_hnd(user_pol))
-        return NT_STATUS_OBJECT_NAME_NOT_FOUND;
-
     become_root();
-    sam_pass = getsam21pwrid(user_rid);
+    sampass = pdb_getsampwrid(user_rid);
     unbecome_root();
 
     /* check that the RID exists in our domain. */
-    if (sam_pass == NULL) {
-        close_lsa_policy_hnd(user_pol);
+    if (sampass == NULL)
         return NT_STATUS_NO_SUCH_USER;
-    }
 
     /* Get the domain SID stored in the domain policy */
-    if(!get_lsa_policy_samr_sid(&domain_pol, &sid)) {
-        close_lsa_policy_hnd(user_pol);
+    if(!get_lsa_policy_samr_sid(p, &domain_pol, &sid))
         return NT_STATUS_INVALID_HANDLE;
-    }
 
     /* append the user's RID to it */
-    if(!sid_append_rid(&sid, user_rid)) {
-        close_lsa_policy_hnd(user_pol);
+    if(!sid_append_rid(&sid, user_rid))
         return NT_STATUS_NO_SUCH_USER;
-    }
 
-    /* associate the user's SID with the handle. */
-    if (!set_lsa_policy_samr_sid(user_pol, &sid)) {
-        /* oh, whoops.  don't know what error message to return, here */
-        close_lsa_policy_hnd(user_pol);
+    /* associate the user's SID with the new handle. */
+    if ((info = (struct samr_info *)malloc(sizeof(struct samr_info))) == NULL)
+        return NT_STATUS_NO_MEMORY;
+
+    ZERO_STRUCTP(info);
+    info->sid = sid;
+
+    /* get a (unique) handle.  open a policy on it. */
+    if (!create_policy_hnd(p, user_pol, free_samr_info, (void *)info))
         return NT_STATUS_OBJECT_NAME_NOT_FOUND;
-    }
 
     return r_u->status;
 }
@@ -1328,7 +1362,7 @@ uint32 _api_samr_open_user(pipes_struct *p, SAMR_Q_OPEN_USER *q_u, SAMR_R_OPEN_U
 
 static BOOL get_user_info_10(SAM_USER_INFO_10 *id10, uint32 user_rid)
 {
-    struct smb_passwd *smb_pass;
+    SAM_ACCOUNT *smbpass;
 
     if (!pdb_rid_is_user(user_rid)) {
         DEBUG(4,("RID 0x%x is not a user RID\n", user_rid));
@@ -1336,18 +1370,17 @@ static BOOL get_user_info_10(SAM_USER_INFO_10 *id10, uint32 user_rid)
     }
 
     become_root();
-    smb_pass = getsmbpwrid(user_rid);
+    smbpass = pdb_getsampwrid(user_rid);
     unbecome_root();
 
-    if (smb_pass == NULL)
-    {
+    if (smbpass == NULL) {
         DEBUG(4,("User 0x%x not found\n", user_rid));
         return False;
     }
 
-    DEBUG(3,("User:[%s]\n", smb_pass->smb_name));
+    DEBUG(3,("User:[%s]\n", pdb_get_username(smbpass) ));
 
-    init_sam_user_info10(id10, smb_pass->acct_ctrl);
+    init_sam_user_info10(id10, pdb_get_acct_ctrl(smbpass) );
 
     return True;
 }
@@ -1358,23 +1391,23 @@ static BOOL get_user_info_10(SAM_USER_INFO_10 *id10, uint32 user_rid)
 
 static BOOL get_user_info_12(SAM_USER_INFO_12 * id12, uint32 user_rid)
 {
-    struct smb_passwd *smb_pass;
+    SAM_ACCOUNT *smbpass;
 
        become_root();
-       smb_pass = getsmbpwrid(user_rid);
+    smbpass = pdb_getsampwrid(user_rid);
        unbecome_root();
 
-       if (smb_pass == NULL) {
+       if (smbpass == NULL) {
                DEBUG(4, ("User 0x%x not found\n", user_rid));
                return False;
        }
 
-    DEBUG(3,("User:[%s] 0x%x\n", smb_pass->smb_name, smb_pass->acct_ctrl));
+    DEBUG(3,("User:[%s] 0x%x\n", pdb_get_username(smbpass), pdb_get_acct_ctrl(smbpass) ));
 
-       if (smb_pass->acct_ctrl & ACB_DISABLED)
+       if ( pdb_get_acct_ctrl(smbpass) & ACB_DISABLED)
         return False;
 
-       init_sam_user_info12(id12, smb_pass->smb_passwd, smb_pass->smb_nt_passwd);
+       init_sam_user_info12(id12, pdb_get_lanman_passwd(smbpass), pdb_get_nt_passwd(smbpass));
 
        return True;
 }
@@ -1385,10 +1418,7 @@ static BOOL get_user_info_12(SAM_USER_INFO_12 * id12, uint32 user_rid)
 
 static BOOL get_user_info_21(SAM_USER_INFO_21 *id21, uint32 user_rid)
 {
-    NTTIME dummy_time;
-    struct sam_passwd *sam_pass;
-    LOGON_HRS hrs;
-    int i;
+    SAM_ACCOUNT *sampass;
 
     if (!pdb_rid_is_user(user_rid)) {
         DEBUG(4,("RID 0x%x is not a user RID\n", user_rid));
@@ -1396,56 +1426,17 @@ static BOOL get_user_info_21(SAM_USER_INFO_21 *id21, uint32 user_rid)
     }
 
     become_root();
-    sam_pass = getsam21pwrid(user_rid);
+    sampass = pdb_getsampwrid(user_rid);
     unbecome_root();
 
-    if (sam_pass == NULL) {
+    if (sampass == NULL) {
         DEBUG(4,("User 0x%x not found\n", user_rid));
         return False;
     }
 
-    DEBUG(3,("User:[%s]\n", sam_pass->smb_name));
-
-    dummy_time.low  = 0xffffffff;
-    dummy_time.high = 0x7fffffff;
-
-    DEBUG(5,("get_user_info_21 - TODO: convert unix times to NTTIMEs\n"));
-
-    /* create a LOGON_HRS structure */
-    hrs.len = sam_pass->hours_len;
-    SMB_ASSERT_ARRAY(hrs.hours, hrs.len);
-    for (i = 0; i < hrs.len; i++)
-        hrs.hours[i] = sam_pass->hours[i];
-
-    init_sam_user_info21A(id21,
-
-               &dummy_time, /* logon_time */
-               &dummy_time, /* logoff_time */
-               &dummy_time, /* kickoff_time */
-               &dummy_time, /* pass_last_set_time */
-               &dummy_time, /* pass_can_change_time */
-               &dummy_time, /* pass_must_change_time */
-
-               sam_pass->smb_name, /* user_name */
-               sam_pass->full_name, /* full_name */
-               sam_pass->home_dir, /* home_dir */
-               sam_pass->dir_drive, /* dir_drive */
-               sam_pass->logon_script, /* logon_script */
-               sam_pass->profile_path, /* profile_path */
-               sam_pass->acct_desc, /* description */
-               sam_pass->workstations, /* workstations user can log in from */
-               sam_pass->unknown_str, /* don't know, yet */
-               sam_pass->munged_dial, /* dialin info.  contains dialin path and tel no */
-
-               sam_pass->user_rid, /* RID user_id */
-               sam_pass->group_rid, /* RID group_id */
-               sam_pass->acct_ctrl,
-
-               sam_pass->unknown_3, /* unknown_3 */
-               sam_pass->logon_divs, /* divisions per week */
-               &hrs, /* logon hours */
-               sam_pass->unknown_5,
-               sam_pass->unknown_6);
+    DEBUG(3,("User:[%s]\n",  pdb_get_username(sampass) ));
+
+       init_sam_user_info21A(id21, sampass);
 
     return True;
 }
@@ -1458,15 +1449,16 @@ uint32 _samr_query_userinfo(pipes_struct *p, SAMR_Q_QUERY_USERINFO *q_u, SAMR_R_
 {
        SAM_USERINFO_CTR *ctr;
        uint32 rid = 0;
+       struct samr_info *info = NULL;
 
        r_u->status=NT_STATUS_NO_PROBLEMO;
 
        /* search for the handle */
-       if (find_lsa_policy_by_hnd(&q_u->pol) == -1)
+       if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info))
                return NT_STATUS_INVALID_HANDLE;
 
        /* find the user's rid */
-       if ((rid = get_lsa_policy_samr_rid(&q_u->pol)) == 0xffffffff)
+       if ((rid = get_lsa_policy_samr_rid(info)) == 0xffffffff)
                return NT_STATUS_OBJECT_TYPE_MISMATCH;
 
        DEBUG(5,("_samr_query_userinfo: rid:0x%x\n", rid));
@@ -1554,27 +1546,28 @@ uint32 _samr_query_usergroups(pipes_struct *p, SAMR_Q_QUERY_USERGROUPS *q_u, SAM
     int num_groups = 0;
     pstring groups;
     uint32 rid;
+       struct samr_info *info = NULL;
 
     r_u->status = NT_STATUS_NO_PROBLEMO;
 
     DEBUG(5,("_samr_query_usergroups: %d\n", __LINE__));
 
     /* find the policy handle.  open a policy on it. */
-    if (find_lsa_policy_by_hnd(&q_u->pol) == -1)
+    if (!find_policy_by_hnd(p, &q_u->pol, (void **)&info))
         return NT_STATUS_INVALID_HANDLE;
 
     /* find the user's rid */
-    if ((rid = get_lsa_policy_samr_rid(&q_u->pol)) == 0xffffffff)
+    if ((rid = get_lsa_policy_samr_rid(info)) == 0xffffffff)
         return NT_STATUS_OBJECT_TYPE_MISMATCH;
 
     become_root();
-    sam_pass = getsam21pwrid(rid);
+    sam_pass = pdb_getsampwrid(rid);
     unbecome_root();
 
     if (sam_pass == NULL)
         return NT_STATUS_NO_SUCH_USER;
 
-    get_domain_user_groups(groups, sam_pass->smb_name);
+    get_domain_user_groups(groups, pdb_get_username(sam_pass));
     gids = NULL;
     num_groups = make_dom_gids(p->mem_ctx, groups, &gids);
 
@@ -1593,7 +1586,6 @@ uint32 _samr_query_usergroups(pipes_struct *p, SAMR_Q_QUERY_USERGROUPS *q_u, SAM
 uint32 _samr_query_dom_info(pipes_struct *p, SAMR_Q_QUERY_DOMAIN_INFO *q_u, SAMR_R_QUERY_DOMAIN_INFO *r_u)
 {
     SAM_UNK_CTR *ctr;
-    uint16 switch_value = 0;
 
        if ((ctr = (SAM_UNK_CTR *)talloc(p->mem_ctx, sizeof(SAM_UNK_CTR))) == NULL)
                return NT_STATUS_NO_MEMORY;
@@ -1605,38 +1597,31 @@ uint32 _samr_query_dom_info(pipes_struct *p, SAMR_Q_QUERY_DOMAIN_INFO *q_u, SAMR
     DEBUG(5,("_samr_query_dom_info: %d\n", __LINE__));
 
     /* find the policy handle.  open a policy on it. */
-    if (find_lsa_policy_by_hnd(&q_u->domain_pol) == -1)
+    if (!find_policy_by_hnd(p, &q_u->domain_pol, NULL))
         return NT_STATUS_INVALID_HANDLE;
 
     switch (q_u->switch_value) {
         case 0x01:
-            switch_value = 0x1;
             init_unk_info1(&ctr->info.inf1);
             break;
         case 0x02:
-            switch_value = 0x2;
                        /* The time call below is to get a sequence number for the sam. FIXME !!! JRA. */
             init_unk_info2(&ctr->info.inf2, global_myworkgroup, global_myname, (uint32) time(NULL));
             break;
         case 0x03:
-            switch_value = 0x3;
             init_unk_info3(&ctr->info.inf3);
             break;
         case 0x06:
-            switch_value = 0x6;
             init_unk_info6(&ctr->info.inf6);
             break;
         case 0x07:
-            switch_value = 0x7;
             init_unk_info7(&ctr->info.inf7);
             break;
         case 0x0c:
-            switch_value = 0xc;
             init_unk_info12(&ctr->info.inf12);
             break;
         default:
             return NT_STATUS_INVALID_INFO_CLASS;
-            break;
     }
 
     init_samr_r_query_dom_info(r_u, q_u->switch_value, ctr, NT_STATUS_NOPROBLEMO);
@@ -1652,7 +1637,7 @@ uint32 _samr_query_dom_info(pipes_struct *p, SAMR_Q_QUERY_DOMAIN_INFO *q_u, SAMR
 
 uint32 _api_samr_create_user(pipes_struct *p, SAMR_Q_CREATE_USER *q_u, SAMR_R_CREATE_USER *r_u)
 {
-    struct sam_passwd *sam_pass;
+    SAM_ACCOUNT *sam_pass;
     fstring mach_acct;
     pstring err_str;
     pstring msg_str;
@@ -1663,9 +1648,10 @@ uint32 _api_samr_create_user(pipes_struct *p, SAMR_Q_CREATE_USER *q_u, SAMR_R_CR
     UNISTR2 user_account = q_u->uni_name;
     uint16 acb_info = q_u->acb_info;
     POLICY_HND *user_pol = &r_u->user_pol;
+       struct samr_info *info = NULL;
 
     /* find the policy handle.  open a policy on it. */
-    if (find_lsa_policy_by_hnd(&dom_pol) == -1)
+    if (!find_policy_by_hnd(p, &dom_pol, NULL))
         return NT_STATUS_INVALID_HANDLE;
 
     /* find the machine account: tell the caller if it exists.
@@ -1678,17 +1664,13 @@ uint32 _api_samr_create_user(pipes_struct *p, SAMR_Q_CREATE_USER *q_u, SAMR_R_CR
     strlower(mach_acct);
 
     become_root();
-    sam_pass = getsam21pwnam(mach_acct);
+    sam_pass = pdb_getsampwnam(mach_acct);
     unbecome_root();
     if (sam_pass != NULL) {
         /* machine account exists: say so */
         return NT_STATUS_USER_EXISTS;
     }
 
-    /* get a (unique) handle.  open a policy on it. */
-    if (!open_lsa_policy_hnd(user_pol))
-        return NT_STATUS_OBJECT_NAME_NOT_FOUND;
-
     local_flags=LOCAL_ADD_USER|LOCAL_DISABLE_USER|LOCAL_SET_NO_PASSWORD;
     local_flags|= (acb_info & ACB_WSTRUST) ? LOCAL_TRUST_ACCOUNT:0;
 
@@ -1720,37 +1702,41 @@ uint32 _api_samr_create_user(pipes_struct *p, SAMR_Q_CREATE_USER *q_u, SAMR_R_CR
          sizeof(err_str), msg_str, sizeof(msg_str)))
     {
         DEBUG(0, ("%s\n", err_str));
-        close_lsa_policy_hnd(user_pol);
+        close_policy_hnd(p, user_pol);
         return NT_STATUS_ACCESS_DENIED;
     }
 
     become_root();
-    sam_pass = getsam21pwnam(mach_acct);
+    sam_pass = pdb_getsampwnam(mach_acct);
     unbecome_root();
     if (sam_pass == NULL) {
         /* account doesn't exist: say so */
-        close_lsa_policy_hnd(user_pol);
+        close_policy_hnd(p, user_pol);
         return NT_STATUS_ACCESS_DENIED;
     }
 
     /* Get the domain SID stored in the domain policy */
-    if(!get_lsa_policy_samr_sid(&dom_pol, &sid)) {
-        close_lsa_policy_hnd(user_pol);
+    if(!get_lsa_policy_samr_sid(p, &dom_pol, &sid)) {
+        close_policy_hnd(p, user_pol);
         return NT_STATUS_INVALID_HANDLE;
     }
 
     /* append the user's RID to it */
-    if(!sid_append_rid(&sid, sam_pass->user_rid)) {
-        close_lsa_policy_hnd(user_pol);
+    if(!sid_append_rid(&sid, pdb_get_user_rid(sam_pass) )) {
+        close_policy_hnd(p, user_pol);
         return NT_STATUS_NO_SUCH_USER;
     }
 
-    /* associate the SID with the (unique) handle. */
-    if (!set_lsa_policy_samr_sid(user_pol, &sid)) {
-        /* oh, whoops.  don't know what error message to return, here */
-        close_lsa_policy_hnd(user_pol);
+    /* associate the user's SID with the new handle. */
+    if ((info = (struct samr_info *)malloc(sizeof(struct samr_info))) == NULL)
+        return NT_STATUS_NO_MEMORY;
+
+    ZERO_STRUCTP(info);
+    info->sid = sid;
+
+    /* get a (unique) handle.  open a policy on it. */
+    if (!create_policy_hnd(p, user_pol, free_samr_info, (void *)info))
         return NT_STATUS_OBJECT_NAME_NOT_FOUND;
-    }
 
     r_u->user_rid=sam_pass->user_rid;
     r_u->unknown_0 = 0x000703ff;
@@ -1764,19 +1750,22 @@ uint32 _api_samr_create_user(pipes_struct *p, SAMR_Q_CREATE_USER *q_u, SAMR_R_CR
 
 uint32 _samr_connect_anon(pipes_struct *p, SAMR_Q_CONNECT_ANON *q_u, SAMR_R_CONNECT_ANON *r_u)
 {
+       struct samr_info *info = NULL;
+
     /* set up the SAMR connect_anon response */
 
     r_u->status = NT_STATUS_NO_PROBLEMO;
 
-    /* get a (unique) handle.  open a policy on it. */
-    if (!open_lsa_policy_hnd(&r_u->connect_pol))
-        return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+    /* associate the user's SID with the new handle. */
+    if ((info = (struct samr_info *)malloc(sizeof(struct samr_info))) == NULL)
+        return NT_STATUS_NO_MEMORY;
+
+    ZERO_STRUCTP(info);
+    info->status = q_u->unknown_0;
 
-    /* associate the domain SID with the (unique) handle. */
-    if (!set_lsa_policy_samr_pol_status(&r_u->connect_pol, q_u->unknown_0)) {
-        close_lsa_policy_hnd(&r_u->connect_pol);
+    /* get a (unique) handle.  open a policy on it. */
+    if (!create_policy_hnd(p, &r_u->connect_pol, free_samr_info, (void *)info))
         return NT_STATUS_OBJECT_NAME_NOT_FOUND;
-    }
 
     return r_u->status;
 }
@@ -1787,19 +1776,22 @@ uint32 _samr_connect_anon(pipes_struct *p, SAMR_Q_CONNECT_ANON *q_u, SAMR_R_CONN
 
 uint32 _samr_connect(pipes_struct *p, SAMR_Q_CONNECT *q_u, SAMR_R_CONNECT *r_u)
 {
+       struct samr_info *info = NULL;
+
     DEBUG(5,("_samr_connect: %d\n", __LINE__));
 
     r_u->status = NT_STATUS_NO_PROBLEMO;
 
-    /* get a (unique) handle.  open a policy on it. */
-    if (!open_lsa_policy_hnd(&r_u->connect_pol))
-        return NT_STATUS_OBJECT_NAME_NOT_FOUND;
+    /* associate the user's SID with the new handle. */
+    if ((info = (struct samr_info *)malloc(sizeof(struct samr_info))) == NULL)
+        return NT_STATUS_NO_MEMORY;
+
+    ZERO_STRUCTP(info);
+    info->status = q_u->access_mask;
 
-    /* associate the domain SID with the (unique) handle. */
-    if (!set_lsa_policy_samr_pol_status(&r_u->connect_pol, q_u->access_mask)) {
-        close_lsa_policy_hnd(&r_u->connect_pol);
+    /* get a (unique) handle.  open a policy on it. */
+    if (!create_policy_hnd(p, &r_u->connect_pol, free_samr_info, (void *)info))
         return NT_STATUS_OBJECT_NAME_NOT_FOUND;
-    }
 
     DEBUG(5,("_samr_connect: %d\n", __LINE__));
 
@@ -1814,7 +1806,7 @@ uint32 _samr_lookup_domain(pipes_struct *p, SAMR_Q_LOOKUP_DOMAIN *q_u, SAMR_R_LO
 {
     r_u->status = NT_STATUS_NO_PROBLEMO;
 
-    if (find_lsa_policy_by_hnd(&q_u->connect_pol) == -1)
+    if (!find_policy_by_hnd(p, &q_u->connect_pol, NULL))
         return NT_STATUS_INVALID_HANDLE;
 
     /* assume the domain name sent is our global_myname and
@@ -1894,41 +1886,37 @@ uint32 _api_samr_open_alias(pipes_struct *p, SAMR_Q_OPEN_ALIAS *q_u, SAMR_R_OPEN
        POLICY_HND domain_pol = q_u->dom_pol;
        uint32 alias_rid = q_u->rid_alias;
        POLICY_HND *alias_pol = &r_u->pol;
+       struct samr_info *info = NULL;
 
        r_u->status = NT_STATUS_NO_PROBLEMO;
 
        /* get the domain policy. */
-       if (find_lsa_policy_by_hnd(&domain_pol) == -1)
+       if (!find_policy_by_hnd(p, &domain_pol, NULL))
                return NT_STATUS_INVALID_HANDLE;
 
-       /* get a (unique) handle.  open a policy on it. */
-       if (!open_lsa_policy_hnd(alias_pol))
-               return NT_STATUS_OBJECT_NAME_NOT_FOUND;
-
        /* Get the domain SID stored in the domain policy */
-       if(!get_lsa_policy_samr_sid(&domain_pol, &sid)) {
-               close_lsa_policy_hnd(alias_pol);
+       if(!get_lsa_policy_samr_sid(p, &domain_pol, &sid))
                return NT_STATUS_INVALID_HANDLE;
-       }
+
+       /* append the alias' RID to it */
+       if(!sid_append_rid(&sid, alias_rid))
+               return NT_STATUS_NO_SUCH_USER;
 
        /*
         * we should check if the rid really exist !!!
         * JFM.
         */
 
+    /* associate the user's SID with the new handle. */
+    if ((info = (struct samr_info *)malloc(sizeof(struct samr_info))) == NULL)
+        return NT_STATUS_NO_MEMORY;
 
-       /* append the alias' RID to it */
-       if(!sid_append_rid(&sid, alias_rid)) {
-               close_lsa_policy_hnd(alias_pol);
-               return NT_STATUS_NO_SUCH_USER;
-       }
+    ZERO_STRUCTP(info);
+    info->sid = sid;
 
-       /* associate a SID with the (unique) handle. */
-       if (!set_lsa_policy_samr_sid(alias_pol, &sid)) {
-               /* oh, whoops.  don't know what error message to return, here */
-               close_lsa_policy_hnd(alias_pol);
+       /* get a (unique) handle.  open a policy on it. */
+       if (!create_policy_hnd(p, alias_pol, free_samr_info, (void *)info))
                return NT_STATUS_OBJECT_NAME_NOT_FOUND;
-       }
 
        return r_u->status;
 }
@@ -1939,22 +1927,20 @@ uint32 _api_samr_open_alias(pipes_struct *p, SAMR_Q_OPEN_ALIAS *q_u, SAMR_R_OPEN
 
 static BOOL set_user_info_10(const SAM_USER_INFO_10 *id10, uint32 rid)
 {
-       struct sam_passwd *pwd = getsam21pwrid(rid);
-       struct sam_passwd new_pwd;
+       SAM_ACCOUNT *pwd = pdb_getsampwrid(rid);
 
        if (id10 == NULL) {
                DEBUG(5, ("set_user_info_10: NULL id10\n"));
                return False;
        }
 
-       if (pwd == NULL)
+       pwd = pdb_getsampwrid(rid);
+       if (!pwd)
                return False;
 
-       copy_sam_passwd(&new_pwd, pwd);
-
-       new_pwd.acct_ctrl = id10->acb_info;
+       pdb_set_acct_ctrl(pwd, id10->acb_info);
 
-       if(!mod_sam21pwd_entry(&new_pwd, True))
+       if(!pdb_update_sam_account(pwd, True))
                return False;
 
        return True;
@@ -1966,31 +1952,22 @@ static BOOL set_user_info_10(const SAM_USER_INFO_10 *id10, uint32 rid)
 
 static BOOL set_user_info_12(SAM_USER_INFO_12 *id12, uint32 rid)
 {
-       struct sam_passwd *pwd = getsam21pwrid(rid);
-       struct sam_passwd new_pwd;
-       static uchar nt_hash[16];
-       static uchar lm_hash[16];
-
+       SAM_ACCOUNT *pwd = pdb_getsampwrid(rid);
        if (pwd == NULL)
                return False;
-
        if (id12 == NULL) {
                DEBUG(2, ("set_user_info_12: id12 is NULL\n"));
                return False;
        }
-
-       pdb_init_sam(&new_pwd);
-       copy_sam_passwd(&new_pwd, pwd);
-
-       memcpy(nt_hash, id12->nt_pwd, sizeof(nt_hash));
-       memcpy(lm_hash, id12->lm_pwd, sizeof(lm_hash));
-
-       new_pwd.smb_passwd = lm_hash;
-       new_pwd.smb_nt_passwd = nt_hash;
-
-       if(!mod_sam21pwd_entry(&new_pwd, True))
+       pdb_set_lanman_passwd (pwd, id12->lm_pwd);
+       pdb_set_nt_passwd     (pwd, id12->nt_pwd);
+       if(!pdb_update_sam_account(pwd, True))
                return False;
-
        return True;
 }
 
@@ -1998,41 +1975,34 @@ static BOOL set_user_info_12(SAM_USER_INFO_12 *id12, uint32 rid)
  set_user_info_21
  ********************************************************************/
 
-static BOOL set_user_info_21 (SAM_USER_INFO_21 *id21, uint32 rid)
+static BOOL set_user_info_21(SAM_USER_INFO_21 *id21, uint32 rid)
 {
-       struct sam_passwd *pwd = getsam21pwrid(rid);
-       struct sam_passwd new_pwd;
-       static uchar nt_hash[16];
-       static uchar lm_hash[16];
-
+       SAM_ACCOUNT *pwd = pdb_getsampwrid(rid);
+       SAM_ACCOUNT new_pwd;
        if (id21 == NULL) {
                DEBUG(5, ("set_user_info_21: NULL id21\n"));
                return False;
        }
-
        if (pwd == NULL)
                return False;
-
-       pdb_init_sam(&new_pwd);
-       /* we make a copy so that we can modify stuff */        
+       /* we make a copy so that we can modify stuff */
        copy_sam_passwd(&new_pwd, pwd);
        copy_id21_to_sam_passwd(&new_pwd, id21);
-
-       if (pwd->smb_nt_passwd != NULL) {
-               memcpy(nt_hash, pwd->smb_nt_passwd, 16);
-               new_pwd.smb_nt_passwd = nt_hash;
-       } else
-               new_pwd.smb_nt_passwd = NULL;
-
-       if (pwd->smb_nt_passwd != NULL) {
-               memcpy(lm_hash, pwd->smb_passwd, 16);
-               new_pwd.smb_passwd = lm_hash;
-       } else
-               new_pwd.smb_passwd = NULL;
-
-       if(!mod_sam21pwd_entry(&new_pwd, True))
+       /*
+        * The funny part about the previous two calls is
+        * that pwd still has the password hashes from the
+        * passdb entry.  These have not been updated from
+        * id21.  I don't know if they need to be set.    --jerry
+        */
+       /* write the change out */
+       if(!pdb_update_sam_account(&new_pwd, True))
                return False;
-       
        return True;
 }
 
@@ -2042,52 +2012,54 @@ static BOOL set_user_info_21 (SAM_USER_INFO_21 *id21, uint32 rid)
 
 static BOOL set_user_info_23(SAM_USER_INFO_23 *id23, uint32 rid)
 {
-       struct sam_passwd *pwd = getsam21pwrid(rid);
-       struct sam_passwd new_pwd;
-       static uchar nt_hash[16];
-       static uchar lm_hash[16];
-       pstring buf;
-       uint32 len;
-
-       if (id23 == NULL) {
-               DEBUG(5, ("set_user_info_23: NULL id23\n"));
-               return False;
-       }
-
-       if (pwd == NULL)
-               return False;
-
-       pdb_init_sam(&new_pwd);
-       copy_sam_passwd(&new_pwd, pwd);
-       copy_id23_to_sam_passwd(&new_pwd, id23);
-
-       memset(buf, 0, sizeof(pstring));
-
-       if (!decode_pw_buffer((char*)id23->pass, buf, 256, &len, nt_hash, lm_hash))
-               return False;
-
-       new_pwd.smb_passwd = lm_hash;
-       new_pwd.smb_nt_passwd = nt_hash;
+    SAM_ACCOUNT *pwd = pdb_getsampwrid(rid);
+    SAM_ACCOUNT new_pwd;
+    BYTE nt_hash[16];
+    BYTE lm_hash[16];
+    pstring buf;
+    uint32 len;
+       uint16 acct_ctrl;
+    if (id23 == NULL) {
+        DEBUG(5, ("set_user_info_23: NULL id23\n"));
+        return False;
+    }
+    if (pwd == NULL)
+        return False;
+       acct_ctrl = pdb_get_acct_ctrl(pwd);
 
+    copy_sam_passwd(&new_pwd, pwd);
+    copy_id23_to_sam_passwd(&new_pwd, id23);
+    if (!decode_pw_buffer((char*)id23->pass, buf, 256, &len))
+        return False;
+    nt_lm_owf_gen(buf, nt_hash, lm_hash);
+    pdb_set_lanman_passwd (&new_pwd, lm_hash);
+    pdb_set_nt_passwd     (&new_pwd, nt_hash);
        /* if it's a trust account, don't update /etc/passwd */
-       if ( ( (new_pwd.acct_ctrl &  ACB_DOMTRUST) == ACB_DOMTRUST ) ||
-            ( (new_pwd.acct_ctrl &  ACB_WSTRUST) ==  ACB_WSTRUST) ||
-            ( (new_pwd.acct_ctrl &  ACB_SVRTRUST) ==  ACB_SVRTRUST) ) {
+       if ( ( (acct_ctrl &  ACB_DOMTRUST) == ACB_DOMTRUST ) ||
+            ( (acct_ctrl &  ACB_WSTRUST) ==  ACB_WSTRUST) ||
+            ( (acct_ctrl &  ACB_SVRTRUST) ==  ACB_SVRTRUST) ) {
             DEBUG(5, ("Changing trust account password, not updating /etc/passwd\n"));
-       } else {
-
+       } else  {
+           /* update the UNIX password */
                /* update the UNIX password */
                if (lp_unix_password_sync() )
-                       if(!chgpasswd(new_pwd.smb_name, "", buf, True))
+                       if(!chgpasswd(pdb_get_username(&new_pwd), "", buf, True))
                                return False;
        }
-
-       memset(buf, 0, sizeof(buf));
-
-       if(!mod_sam21pwd_entry(&new_pwd, True))
-               return False;
-       
-       return True;
+    memset(buf, 0, sizeof(buf));
+    if(!pdb_update_sam_account(&new_pwd, True))
+        return False;
+    return True;
 }
 
 /*******************************************************************
@@ -2096,49 +2068,51 @@ static BOOL set_user_info_23(SAM_USER_INFO_23 *id23, uint32 rid)
 
 static BOOL set_user_info_24(SAM_USER_INFO_24 *id24, uint32 rid)
 {
-       struct sam_passwd *pwd = getsam21pwrid(rid);
-       struct sam_passwd new_pwd;
-       static uchar nt_hash[16];
-       static uchar lm_hash[16];
+       SAM_ACCOUNT *pwd = pdb_getsampwrid(rid);
+       uchar nt_hash[16];
+       uchar lm_hash[16];
        uint32 len;
        pstring buf;
-
+       uint16 acct_ctrl;
        if (pwd == NULL)
                return False;
+       acct_ctrl = pdb_get_acct_ctrl(pwd);
 
-       pdb_init_sam(&new_pwd);
-       copy_sam_passwd(&new_pwd, pwd);
-
-       memset(buf, 0, sizeof(pstring));
-
-       if (!decode_pw_buffer((char*)id24->pass, buf, 256, &len, nt_hash, lm_hash))
+       memset(buf, 0, sizeof(buf));
+       if (!decode_pw_buffer((char*)id24->pass, buf, 256, &len))
                return False;
-
-       new_pwd.smb_passwd = lm_hash;
-       new_pwd.smb_nt_passwd = nt_hash;
-       
+       DEBUG(5,("set_user_info_24:nt_lm_owf_gen\n"));
+       nt_lm_owf_gen(buf, nt_hash, lm_hash);
+       pdb_set_lanman_passwd (pwd, lm_hash);
+       pdb_set_nt_passwd     (pwd, nt_hash);
        /* if it's a trust account, don't update /etc/passwd */
-       if ( ( (new_pwd.acct_ctrl &  ACB_DOMTRUST) == ACB_DOMTRUST ) ||
-            ( (new_pwd.acct_ctrl &  ACB_WSTRUST) ==  ACB_WSTRUST) ||
-            ( (new_pwd.acct_ctrl &  ACB_SVRTRUST) ==  ACB_SVRTRUST) ) {
+       if ( ( (acct_ctrl &  ACB_DOMTRUST) == ACB_DOMTRUST ) ||
+            ( (acct_ctrl &  ACB_WSTRUST) ==  ACB_WSTRUST) ||
+            ( (acct_ctrl &  ACB_SVRTRUST) ==  ACB_SVRTRUST) ) {
             DEBUG(5, ("Changing trust account password, not updating /etc/passwd\n"));
        } else {
-
                /* update the UNIX password */
-               if (lp_unix_password_sync() )
-                       if(!chgpasswd(new_pwd.smb_name, "", buf, True))
+               if (lp_unix_password_sync())
+                       if(!chgpasswd(pdb_get_username(pwd), "", buf, True))
                                return False;
        }
-       
-       memset(buf, 0, sizeof(buf));
-       
-       DEBUG(5,("set_user_info_24: pdb_update_sam_account()\n"));
-
-       /* update the SAMBA password */
-       if(!mod_sam21pwd_entry(&new_pwd, True))
-               return False;
-
-       return True;
+    memset(buf, 0, sizeof(buf));
+    DEBUG(0,("set_user_info_24: pdb_update_sam_account()\n"));
+    /* update the SAMBA password */
+    if(!pdb_update_sam_account(pwd, True))
+        return False;
+    return True;
 }
 
 /*******************************************************************
@@ -2150,7 +2124,7 @@ uint32 _samr_set_userinfo(pipes_struct *p, SAMR_Q_SET_USERINFO *q_u, SAMR_R_SET_
        uint32 rid = 0x0;
        DOM_SID sid;
        struct current_user user;
-       struct smb_passwd *smb_pass;
+       SAM_ACCOUNT *sam_pass;
        unsigned char sess_key[16];
        POLICY_HND *pol = &q_u->pol;
        uint16 switch_value = q_u->switch_value;
@@ -2167,12 +2141,8 @@ uint32 _samr_set_userinfo(pipes_struct *p, SAMR_Q_SET_USERINFO *q_u, SAMR_R_SET_
                memcpy(&user, &current_user, sizeof(user));
        }
 
-       /* search for the handle */
-       if (find_lsa_policy_by_hnd(pol) == -1)
-               return NT_STATUS_INVALID_HANDLE;
-
        /* find the policy handle.  open a policy on it. */
-       if (!get_lsa_policy_samr_sid(pol, &sid))
+       if (!get_lsa_policy_samr_sid(p, pol, &sid))
                return NT_STATUS_INVALID_HANDLE;
 
        sid_split_rid(&sid, &rid);
@@ -2192,15 +2162,15 @@ uint32 _samr_set_userinfo(pipes_struct *p, SAMR_Q_SET_USERINFO *q_u, SAMR_R_SET_
         */
 
        become_root();
-       smb_pass = getsmbpwuid(user.uid);
+       sam_pass = pdb_getsampwuid(user.uid);
        unbecome_root();
-       if(smb_pass == NULL) {
+       if(sam_pass == NULL) {
                DEBUG(0,("_samr_set_userinfo: Unable to get smbpasswd entry for uid %u\n", (unsigned int)user.uid ));
                return NT_STATUS_ACCESS_DENIED;
        }
                
        memset(sess_key, '\0', 16);
-       mdfour(sess_key, smb_pass->smb_nt_passwd, 16);
+       mdfour(sess_key, pdb_get_nt_passwd(sam_pass), 16);
 
        /* ok!  user info levels (lots: see MSDEV help), off we go... */
        switch (switch_value) {
@@ -2236,7 +2206,7 @@ uint32 _samr_set_userinfo2(pipes_struct *p, SAMR_Q_SET_USERINFO2 *q_u, SAMR_R_SE
 {
        DOM_SID sid;
        uint32 rid = 0x0;
-       SAM_USERINFO_CTR *ctr = NULL;
+       SAM_USERINFO_CTR *ctr = q_u->ctr;
        POLICY_HND *pol = &q_u->pol;
        uint16 switch_value = q_u->switch_value;
 
@@ -2244,18 +2214,8 @@ uint32 _samr_set_userinfo2(pipes_struct *p, SAMR_Q_SET_USERINFO2 *q_u, SAMR_R_SE
 
        r_u->status = NT_STATUS_NOPROBLEMO;
 
-       ctr = (SAM_USERINFO_CTR *)talloc(p->mem_ctx, sizeof(SAM_USERINFO_CTR));
-       if (!ctr)
-         return NT_STATUS_NO_MEMORY;
-
-       q_u->ctr = ctr;
-
-       /* search for the handle */
-       if (find_lsa_policy_by_hnd(pol) == -1)
-               return NT_STATUS_INVALID_HANDLE;
-
        /* find the policy handle.  open a policy on it. */
-       if (!get_lsa_policy_samr_sid(pol, &sid))
+       if (!get_lsa_policy_samr_sid(p, pol, &sid))
                return NT_STATUS_INVALID_HANDLE;
 
        sid_split_rid(&sid, &rid);
@@ -2267,7 +2227,7 @@ uint32 _samr_set_userinfo2(pipes_struct *p, SAMR_Q_SET_USERINFO2 *q_u, SAMR_R_SE
                return NT_STATUS_INVALID_INFO_CLASS;
        }
 
-       ctr->switch_value = switch_value;
+       switch_value=ctr->switch_value;
 
        /* ok!  user info levels (lots: see MSDEV help), off we go... */
        switch (switch_value) {
index 0cb72232f216ef3093f790179496177cfd1f53e1..126581ba8084563c62646930218a66ccc25b6309 100755 (executable)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
  *  Unix SMB/Netbios implementation.
  *  Version 1.9.
@@ -249,7 +248,11 @@ static BOOL api_spoolss_rffpcnex(pipes_struct *p)
  * api_spoolss_rfnpcnex
  * ReplyFindNextPrinterChangeNotifyEx
  * called from the spoolss dispatcher
- *
+
+ * Note - this is the *ONLY* function that breaks the RPC call
+ * symmetry in all the other calls. We need to do this to fix
+ * the massive memory allocation problem with thousands of jobs...
+ * JRA.
  ********************************************************************/
 
 static BOOL api_spoolss_rfnpcnex(pipes_struct *p)
@@ -1188,5 +1191,3 @@ BOOL api_spoolss_rpc(pipes_struct *p)
 {
        return api_rpcTNP(p, "api_spoolss_rpc", api_spoolss_cmds);
 }
-
-#undef OLD_NTDOMAIN
index 0fb38b84db24a81696ecae9051b407a7d755c621..9fcf9930bf4b68f9c685f31c10d7462c2f799409 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /*
  *  Unix SMB/Netbios implementation.
  *  Version 1.9.
@@ -40,14 +39,9 @@ extern pstring global_myname;
 /* and the notify info asked about */
 /* that's the central struct */
 typedef struct _Printer{
-       ubi_dlNode Next;
-       ubi_dlNode Prev;
-
-       BOOL open;
        BOOL document_started;
        BOOL page_started;
     int jobid; /* jobid in printing backend */
-       POLICY_HND printer_hnd;
        BOOL printer_type;
        union {
                fstring handlename;
@@ -78,14 +72,12 @@ typedef struct _counter_printer_0 {
        uint32 counter;
 } counter_printer_0;
 
-static ubi_dlList Printer_list;
 static ubi_dlList counter_list;
 
 static struct cli_state cli;
 static uint32 smb_connections=0;
 
-#define OPEN_HANDLE(pnum)    ((pnum!=NULL) && (pnum->open!=False) && (IVAL(pnum->printer_hnd.data5,4)==(uint32)sys_getpid()))
-#define OUR_HANDLE(pnum) ((pnum==NULL)?"NULL":(IVAL(pnum->data5,4)==(uint32)sys_getpid()?"OURS":"OTHER"))
+#define OUR_HANDLE(hnd) ((hnd==NULL)?"NULL":(IVAL(hnd->data5,4)==(uint32)sys_getpid()?"OURS":"OTHER"))
 
 /* translate between internal status numbers and NT status numbers */
 static int nt_printj_status(int v)
@@ -151,6 +143,56 @@ static void free_spool_notify_option(SPOOL_NOTIFY_OPTION **pp)
        free(sp);
 }
 
+/***************************************************************************
+ Disconnect from the client
+****************************************************************************/
+
+static void srv_spoolss_replycloseprinter(POLICY_HND *handle)
+{
+       uint32 status;
+
+       /* weird if the test succeds !!! */
+       if (smb_connections==0) {
+               DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n"));
+               return;
+       }
+
+       if(!cli_spoolss_reply_close_printer(&cli, handle, &status))
+               DEBUG(0,("srv_spoolss_replycloseprinter: reply_close_printer failed.\n"));
+
+       /* if it's the last connection, deconnect the IPC$ share */
+       if (smb_connections==1) {
+               if(!spoolss_disconnect_from_client(&cli))
+                       return;
+
+               message_deregister(MSG_PRINTER_NOTIFY);
+       }
+
+       smb_connections--;
+}
+
+/****************************************************************************
+ Functions to free a printer entry datastruct.
+****************************************************************************/
+
+static void free_printer_entry(void *ptr)
+{
+       Printer_entry *Printer = (Printer_entry *)ptr;
+
+       if (Printer->notify.client_connected==True)
+               srv_spoolss_replycloseprinter(&Printer->notify.client_hnd);
+
+       Printer->notify.flags=0;
+       Printer->notify.options=0;
+       Printer->notify.localmachine[0]='\0';
+       Printer->notify.printerlocal=0;
+       free_spool_notify_option(&Printer->notify.option);
+       Printer->notify.option=NULL;
+       Printer->notify.client_connected=False;
+
+       safe_free(Printer);
+}
+
 /****************************************************************************
  Functions to duplicate a SPOOL_NOTIFY_OPTION struct stored in Printer_entry.
 ****************************************************************************/
@@ -180,15 +222,6 @@ SPOOL_NOTIFY_OPTION *dup_spool_notify_option(SPOOL_NOTIFY_OPTION *sp)
        return new_sp;
 }
 
-/****************************************************************************
-  initialise printer handle states...
-****************************************************************************/
-void init_printer_hnd(void)
-{
-       ubi_dlInitList(&Printer_list);
-       ubi_dlInitList(&counter_list);
-}
-
 /****************************************************************************
  Return a user struct for a pipe user.
 ****************************************************************************/
@@ -205,109 +238,36 @@ static struct current_user *get_current_user(struct current_user *user, pipes_st
        return user;
 }
 
-/****************************************************************************
-  create a unique printer handle
-****************************************************************************/
-static void create_printer_hnd(POLICY_HND *hnd)
-{
-       static uint32 prt_hnd_low  = 0;
-       static uint32 prt_hnd_high = 0;
-
-       if (hnd == NULL) return;
-
-       create_policy_handle(hnd, &prt_hnd_low, &prt_hnd_high);
-}
-
 /****************************************************************************
   find printer index by handle
 ****************************************************************************/
-static Printer_entry *find_printer_index_by_hnd(const POLICY_HND *hnd)
-{
-       Printer_entry *find_printer;
 
-       find_printer = (Printer_entry *)ubi_dlFirst(&Printer_list);
-
-       for(; find_printer; find_printer = (Printer_entry *)ubi_dlNext(find_printer)) {
-
-               if (memcmp(&(find_printer->printer_hnd), hnd, sizeof(*hnd)) == 0) {
-                       DEBUG(4,("Found printer handle \n"));
-                       /*dump_data(4, hnd->data, sizeof(hnd->data));*/
-                       return find_printer;
-               }
-       }
-       
-       DEBUG(3,("Whoops, Printer handle not found: "));
-       /*dump_data(4, hnd->data, sizeof(hnd->data));*/
-       return NULL;
-}
-
-/****************************************************************************
-  clear an handle
-****************************************************************************/
-static void clear_handle(POLICY_HND *hnd)
-{
-       ZERO_STRUCTP(hnd);
-}
-
-/***************************************************************************
- Disconnect from the client
-****************************************************************************/
-static BOOL srv_spoolss_replycloseprinter(POLICY_HND *handle)
+static Printer_entry *find_printer_index_by_hnd(pipes_struct *p, POLICY_HND *hnd)
 {
-       uint32 status;
-
-       /* weird if the test succeds !!! */
-       if (smb_connections==0) {
-               DEBUG(0,("srv_spoolss_replycloseprinter:Trying to close non-existant notify backchannel !\n"));
-               return False;
-       }
-
-       if(!cli_spoolss_reply_close_printer(&cli, handle, &status))
-               return False;
-
-       /* if it's the last connection, deconnect the IPC$ share */
-       if (smb_connections==1) {
-               if(!spoolss_disconnect_from_client(&cli))
-                       return False;
+       Printer_entry *find_printer = NULL;
 
-               message_deregister(MSG_PRINTER_NOTIFY);
+       if(!find_policy_by_hnd(p,hnd,(void **)&find_printer)) {
+               DEBUG(3,("find_printer_index_by_hnd: Printer handle not found: "));
+               return NULL;
        }
 
-       smb_connections--;
-
-       return True;
+       return find_printer;
 }
 
 /****************************************************************************
   close printer index by handle
 ****************************************************************************/
-static BOOL close_printer_handle(POLICY_HND *hnd)
+
+static BOOL close_printer_handle(pipes_struct *p, POLICY_HND *hnd)
 {
-       Printer_entry *Printer = find_printer_index_by_hnd(hnd);
+       Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
 
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                DEBUG(0,("close_printer_handle: Invalid handle (%s)\n", OUR_HANDLE(hnd)));
                return False;
        }
 
-       if (Printer->notify.client_connected==True)
-               if(!srv_spoolss_replycloseprinter(&Printer->notify.client_hnd))
-                       return ERROR_INVALID_HANDLE;
-
-       Printer->open=False;
-       Printer->notify.flags=0;
-       Printer->notify.options=0;
-       Printer->notify.localmachine[0]='\0';
-       Printer->notify.printerlocal=0;
-       free_spool_notify_option(&Printer->notify.option);
-       Printer->notify.option=NULL;
-       Printer->notify.client_connected=False;
-
-       clear_handle(hnd);
-
-       ubi_dlRemThis(&Printer_list, Printer);
-
-       safe_free(Printer);
+       close_policy_hnd(p, hnd);
 
        return True;
 }      
@@ -315,11 +275,11 @@ static BOOL close_printer_handle(POLICY_HND *hnd)
 /****************************************************************************
   delete a printer given a handle
 ****************************************************************************/
-static uint32 delete_printer_handle(POLICY_HND *hnd)
+static uint32 delete_printer_handle(pipes_struct *p, POLICY_HND *hnd)
 {
-       Printer_entry *Printer = find_printer_index_by_hnd(hnd);
+       Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
 
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                DEBUG(0,("delete_printer_handle: Invalid handle (%s)\n", OUR_HANDLE(hnd)));
                return ERROR_INVALID_HANDLE;
        }
@@ -387,11 +347,11 @@ static uint32 delete_printer_handle(POLICY_HND *hnd)
 /****************************************************************************
   return the snum of a printer corresponding to an handle
 ****************************************************************************/
-static BOOL get_printer_snum(POLICY_HND *hnd, int *number)
+static BOOL get_printer_snum(pipes_struct *p, POLICY_HND *hnd, int *number)
 {
-       Printer_entry *Printer = find_printer_index_by_hnd(hnd);
+       Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
                
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                DEBUG(0,("get_printer_snum: Invalid handle (%s)\n", OUR_HANDLE(hnd)));
                return False;
        }
@@ -411,11 +371,11 @@ static BOOL get_printer_snum(POLICY_HND *hnd, int *number)
 /****************************************************************************
   set printer handle type.
 ****************************************************************************/
-static BOOL set_printer_hnd_accesstype(POLICY_HND *hnd, uint32 access_required)
+static BOOL set_printer_hnd_accesstype(pipes_struct *p, POLICY_HND *hnd, uint32 access_required)
 {
-       Printer_entry *Printer = find_printer_index_by_hnd(hnd);
+       Printer_entry *Printer = find_printer_index_by_hnd(p, hnd);
 
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                DEBUG(0,("set_printer_hnd_accesstype: Invalid handle (%s)", OUR_HANDLE(hnd)));
                return False;
        }
@@ -581,38 +541,35 @@ static BOOL set_printer_hnd_name(Printer_entry *Printer, char *handlename)
   find first available printer slot. creates a printer handle for you.
  ****************************************************************************/
 
-static BOOL open_printer_hnd(POLICY_HND *hnd, char *name)
+static BOOL open_printer_hnd(pipes_struct *p, POLICY_HND *hnd, char *name)
 {
        Printer_entry *new_printer;
 
        DEBUG(10,("open_printer_hnd: name [%s]\n", name));
-       clear_handle(hnd);
-       create_printer_hnd(hnd);
 
        if((new_printer=(Printer_entry *)malloc(sizeof(Printer_entry))) == NULL)
                return False;
 
        ZERO_STRUCTP(new_printer);
        
-       new_printer->open = True;
        new_printer->notify.option=NULL;
                                
-       memcpy(&new_printer->printer_hnd, hnd, sizeof(*hnd));
-       
-       ubi_dlAddHead( &Printer_list, (ubi_dlNode *)new_printer);
+       if (!create_policy_hnd(p, hnd, free_printer_entry, new_printer)) {
+               safe_free(new_printer);
+               return False;
+       }
 
        if (!set_printer_hnd_printertype(new_printer, name)) {
-               close_printer_handle(hnd);
+               close_printer_handle(p, hnd);
                return False;
        }
        
        if (!set_printer_hnd_name(new_printer, name)) {
-               close_printer_handle(hnd);
+               close_printer_handle(p, hnd);
                return False;
        }
 
-       DEBUG(5, ("%d printer handles active\n", 
-                 (int)ubi_dlCount(&Printer_list)));
+       DEBUG(5, ("%d printer handles active\n", (int)p->pipe_handles.count ));
 
        return True;
 }
@@ -620,11 +577,12 @@ static BOOL open_printer_hnd(POLICY_HND *hnd, char *name)
 /********************************************************************
  Return True is the handle is a print server.
  ********************************************************************/
-static BOOL handle_is_printserver(const POLICY_HND *handle)
+
+static BOOL handle_is_printserver(pipes_struct *p, POLICY_HND *handle)
 {
-       Printer_entry *Printer=find_printer_index_by_hnd(handle);
+       Printer_entry *Printer=find_printer_index_by_hnd(p,handle);
 
-       if (!OPEN_HANDLE(Printer))
+       if (!Printer)
                return False;
                
        if (Printer->printer_type != PRINTER_HANDLE_IS_PRINTSERVER)
@@ -670,11 +628,12 @@ static BOOL alloc_buffer_size(NEW_BUFFER *buffer, uint32 buffer_size)
 /***************************************************************************
  receive the notify message
 ****************************************************************************/
+
 void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size_t len)
 {
        fstring printer;
        uint32 status;
-       Printer_entry *find_printer;
+       struct pipes_struct *p;
 
        *printer = '\0';
        fstrcpy(printer,buf);
@@ -686,36 +645,45 @@ void srv_spoolss_receive_message(int msg_type, pid_t src, void *buf, size_t len)
 
        DEBUG(10,("srv_spoolss_receive_message: Got message about printer %s\n", printer ));
 
-       find_printer = (Printer_entry *)ubi_dlFirst(&Printer_list);
+       /* We need to enumerate all our pipes and all printers on them. */
+       for ( p = get_first_pipe(); p; get_next_pipe(p)) {
+               struct policy *pol;
 
-       /* Iterate the printer list. */
-       for(; find_printer; find_printer = (Printer_entry *)ubi_dlNext(find_printer)) {
+               if (!strequal(p->name, "spoolss"))
+                       continue;
 
-               /*
-                * if the entry is the given printer or if it's a printerserver
-                * we send the message
-                */
+               /* Iterate the printer list on this pipe. */
+               for (pol = p->pipe_handles.Policy; pol; pol = pol->next ) {
+                       Printer_entry *find_printer = (Printer_entry *)pol->data_ptr;
 
-               if (find_printer->printer_type==PRINTER_HANDLE_IS_PRINTER)
-                       if (strcmp(find_printer->dev.handlename, printer))
+                       if (!find_printer)
                                continue;
 
-               if (find_printer->notify.client_connected==True)
-                       cli_spoolss_reply_rrpcn(&cli, &find_printer->notify.client_hnd, PRINTER_CHANGE_ALL, 0x0, &status);
+                       /*
+                        * if the entry is the given printer or if it's a printerserver
+                        * we send the message
+                        */
+
+                       if (find_printer->printer_type==PRINTER_HANDLE_IS_PRINTER)
+                               if (strcmp(find_printer->dev.handlename, printer))
+                                       continue;
 
+                       if (find_printer->notify.client_connected==True)
+                               cli_spoolss_reply_rrpcn(&cli, &find_printer->notify.client_hnd, PRINTER_CHANGE_ALL, 0x0, &status);
+               }
        }
 }
 
 /***************************************************************************
  send a notify event
 ****************************************************************************/
-static BOOL srv_spoolss_sendnotify(POLICY_HND *handle)
+static BOOL srv_spoolss_sendnotify(pipes_struct *p, POLICY_HND *handle)
 {
        fstring printer;
 
-       Printer_entry *Printer=find_printer_index_by_hnd(handle);
+       Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
 
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                DEBUG(0,("srv_spoolss_sendnotify: Invalid handle (%s).\n", OUR_HANDLE(handle)));
                return False;
        }
@@ -767,7 +735,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u,
 
        DEBUGADD(3,("checking name: %s\n",name));
 
-       if (!open_printer_hnd(handle, name))
+       if (!open_printer_hnd(p, handle, name))
                return ERROR_INVALID_PRINTER_NAME;
        
 /*
@@ -780,8 +748,8 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u,
                set_printer_hnd_datatype(handle, "");
 */
        
-       if (!set_printer_hnd_accesstype(handle, printer_default->access_required)) {
-               close_printer_handle(handle);
+       if (!set_printer_hnd_accesstype(p, handle, printer_default->access_required)) {
+               close_printer_handle(p, handle);
                return ERROR_ACCESS_DENIED;
        }
                
@@ -810,7 +778,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u,
 
        get_current_user(&user, p);
 
-       if (handle_is_printserver(handle)) {
+       if (handle_is_printserver(p, handle)) {
                if (printer_default->access_required == 0) {
                        return NT_STATUS_NO_PROBLEMO;
                }
@@ -820,14 +788,14 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u,
                        snum = -1;
 
                        if (!lp_ms_add_printer_wizard()) {
-                               close_printer_handle(handle);
+                               close_printer_handle(p, handle);
                                return ERROR_ACCESS_DENIED;
                        }
                        else if (user.uid == 0 || user_in_list(uidtoname(user.uid), lp_printer_admin(snum))) {
                                return NT_STATUS_NO_PROBLEMO;
                        } 
                        else {
-                               close_printer_handle(handle);
+                               close_printer_handle(p, handle);
                                return ERROR_ACCESS_DENIED;
                        }
                }
@@ -837,7 +805,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u,
                /* NT doesn't let us connect to a printer if the connecting user
                   doesn't have print permission.  */
 
-               if (!get_printer_snum(handle, &snum))
+               if (!get_printer_snum(p, handle, &snum))
                        return ERROR_INVALID_HANDLE;
 
                /* map an empty access mask to the minimum access mask */
@@ -846,7 +814,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u,
 
                if (!print_access_check(&user, snum, printer_default->access_required)) {
                        DEBUG(3, ("access DENIED for printer open\n"));
-                       close_printer_handle(handle);
+                       close_printer_handle(p, handle);
                        return ERROR_ACCESS_DENIED;
                }
 
@@ -919,7 +887,7 @@ uint32 _spoolss_open_printer_ex( pipes_struct *p, SPOOL_Q_OPEN_PRINTER_EX *q_u,
                if (printer_default->devmode_cont.devmode != NULL) {
                        result = printer_write_default_dev( snum, printer_default);
                        if (result != 0) {
-                               close_printer_handle(handle);
+                               close_printer_handle(p, handle);
                                return result;
                        }
                }
@@ -1038,11 +1006,11 @@ BOOL convert_devicemode(char *printername, const DEVICEMODE *devmode,
  * _spoolss_enddocprinter_internal.
  ********************************************************************/
 
-static uint32 _spoolss_enddocprinter_internal(POLICY_HND *handle)
+static uint32 _spoolss_enddocprinter_internal(pipes_struct *p, POLICY_HND *handle)
 {
-       Printer_entry *Printer=find_printer_index_by_hnd(handle);
+       Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
        
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                DEBUG(0,("_spoolss_enddocprinter_internal: Invalid handle (%s)\n", OUR_HANDLE(handle)));
                return ERROR_INVALID_HANDLE;
        }
@@ -1062,14 +1030,14 @@ uint32 _spoolss_closeprinter(pipes_struct *p, SPOOL_Q_CLOSEPRINTER *q_u, SPOOL_R
 {
        POLICY_HND *handle = &q_u->handle;
 
-       Printer_entry *Printer=find_printer_index_by_hnd(handle);
+       Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
 
        if (Printer && Printer->document_started)
-               _spoolss_enddocprinter_internal(handle);          /* print job was not closed */
+               _spoolss_enddocprinter_internal(p, handle);          /* print job was not closed */
 
        memcpy(&r_u->handle, &q_u->handle, sizeof(r_u->handle));
 
-       if (!close_printer_handle(handle))
+       if (!close_printer_handle(p, handle))
                return ERROR_INVALID_HANDLE;    
                
        return NT_STATUS_NO_PROBLEMO;
@@ -1084,18 +1052,18 @@ uint32 _spoolss_deleteprinter(pipes_struct *p, SPOOL_Q_DELETEPRINTER *q_u, SPOOL
 {
        POLICY_HND *handle = &q_u->handle;
 
-       Printer_entry *Printer=find_printer_index_by_hnd(handle);
+       Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
        uint32 result;
 
        if (Printer && Printer->document_started)
-               _spoolss_enddocprinter_internal(handle);  /* print job was not closed */
+               _spoolss_enddocprinter_internal(p, handle);  /* print job was not closed */
 
        memcpy(&r_u->handle, &q_u->handle, sizeof(r_u->handle));
 
-       result = delete_printer_handle(handle);
+       result = delete_printer_handle(p, handle);
 
        if (result == ERROR_SUCCESS) {
-               srv_spoolss_sendnotify(handle);
+               srv_spoolss_sendnotify(p, handle);
        }
                
        return result;
@@ -1182,7 +1150,7 @@ static BOOL getprinterdata_printer_server(TALLOC_CTX *ctx, fstring value, uint32
 /********************************************************************
  GetPrinterData on a printer Handle.
 ********************************************************************/
-static BOOL getprinterdata_printer(TALLOC_CTX *ctx, POLICY_HND *handle,
+static BOOL getprinterdata_printer(pipes_struct *p, TALLOC_CTX *ctx, POLICY_HND *handle,
                                fstring value, uint32 *type,
                                uint8 **data, uint32 *needed, uint32 in_size )
 {
@@ -1190,16 +1158,16 @@ static BOOL getprinterdata_printer(TALLOC_CTX *ctx, POLICY_HND *handle,
        int snum=0;
        uint8 *idata=NULL;
        uint32 len;
-       Printer_entry *Printer = find_printer_index_by_hnd(handle);
+       Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
        
        DEBUG(5,("getprinterdata_printer\n"));
 
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                DEBUG(0,("getprinterdata_printer: Invalid handle (%s).\n", OUR_HANDLE(handle)));
                return False;
        }
 
-       if(!get_printer_snum(handle, &snum))
+       if(!get_printer_snum(p, handle, &snum))
                return False;
 
        if(get_a_printer(&printer, 2, lp_servicename(snum)) != 0)
@@ -1251,7 +1219,7 @@ uint32 _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO
 
        fstring value;
        BOOL found=False;
-       Printer_entry *Printer = find_printer_index_by_hnd(handle);
+       Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
        
        /*
         * Reminder: when it's a string, the length is in BYTES
@@ -1268,7 +1236,7 @@ uint32 _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO
        
        DEBUG(4,("_spoolss_getprinterdata\n"));
        
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                if((*data=(uint8 *)malloc(4*sizeof(uint8))) == NULL)
                        return ERROR_NOT_ENOUGH_MEMORY;
                DEBUG(0,("_spoolss_getprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle)));
@@ -1277,10 +1245,10 @@ uint32 _spoolss_getprinterdata(pipes_struct *p, SPOOL_Q_GETPRINTERDATA *q_u, SPO
        
        unistr2_to_ascii(value, valuename, sizeof(value)-1);
        
-       if (handle_is_printserver(handle))
+       if (Printer->printer_type == PRINTER_HANDLE_IS_PRINTSERVER)
                found=getprinterdata_printer_server(p->mem_ctx, value, type, data, needed, *out_size);
        else
-               found= getprinterdata_printer(p->mem_ctx, handle, value, type, data, needed, *out_size);
+               found= getprinterdata_printer(p, p->mem_ctx, handle, value, type, data, needed, *out_size);
 
        if (found==False) {
                DEBUG(5, ("value not found, allocating %d\n", *out_size));
@@ -1351,9 +1319,9 @@ uint32 _spoolss_rffpcnex(pipes_struct *p, SPOOL_Q_RFFPCNEX *q_u, SPOOL_R_RFFPCNE
 
        /* store the notify value in the printer struct */
 
-       Printer_entry *Printer=find_printer_index_by_hnd(handle);
+       Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
 
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                DEBUG(0,("_spoolss_rffpcnex: Invalid handle (%s).\n", OUR_HANDLE(handle)));
                return ERROR_INVALID_HANDLE;
        }
@@ -1786,13 +1754,11 @@ static void spoolss_notify_status(int snum,
                                  NT_PRINTER_INFO_LEVEL *printer,
                                  TALLOC_CTX *mem_ctx)
 {
-       int count;
-
        print_queue_struct *q=NULL;
        print_status_struct status;
 
        memset(&status, 0, sizeof(status));
-       count = print_queue_status(snum, &q, &status);
+       print_queue_status(snum, &q, &status);
        data->notify_data.value[0]=(uint32) status.status;
        safe_free(q);
 }
@@ -2277,20 +2243,19 @@ static BOOL construct_notify_jobs_info(print_queue_struct *queue,
  * that's the print server case, the printer case is even worse.
  */
 
-
-
 /*******************************************************************
  *
  * enumerate all printers on the printserver
  * fill a notify_info struct with info asked
  *
  ********************************************************************/
-static uint32 printserver_notify_info(const POLICY_HND *hnd, 
+
+static uint32 printserver_notify_info(pipes_struct *p, POLICY_HND *hnd, 
                                      SPOOL_NOTIFY_INFO *info,
                                      TALLOC_CTX *mem_ctx)
 {
        int snum;
-       Printer_entry *Printer=find_printer_index_by_hnd(hnd);
+       Printer_entry *Printer=find_printer_index_by_hnd(p, hnd);
        int n_services=lp_numservices();
        int i;
        uint32 id;
@@ -2341,11 +2306,11 @@ static uint32 printserver_notify_info(const POLICY_HND *hnd,
  * fill a notify_info struct with info asked
  *
  ********************************************************************/
-static uint32 printer_notify_info(POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info,
+static uint32 printer_notify_info(pipes_struct *p, POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info,
                                  TALLOC_CTX *mem_ctx)
 {
        int snum;
-       Printer_entry *Printer=find_printer_index_by_hnd(hnd);
+       Printer_entry *Printer=find_printer_index_by_hnd(p, hnd);
        int i;
        uint32 id;
        SPOOL_NOTIFY_OPTION *option;
@@ -2362,7 +2327,7 @@ static uint32 printer_notify_info(POLICY_HND *hnd, SPOOL_NOTIFY_INFO *info,
        info->data=NULL;
        info->count=0;
 
-       get_printer_snum(hnd, &snum);
+       get_printer_snum(p, hnd, &snum);
 
        for (i=0; i<option->count; i++) {
                option_type=&option->ctr.type[i];
@@ -2430,13 +2395,13 @@ uint32 _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCN
 /*     SPOOL_NOTIFY_OPTION *option = q_u->option; - notused. */
        SPOOL_NOTIFY_INFO *info = &r_u->info;
 
-       Printer_entry *Printer=find_printer_index_by_hnd(handle);
+       Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
        uint32 result = ERROR_INVALID_HANDLE;
 
        /* we always have a NOTIFY_INFO struct */
        r_u->info_ptr=0x1;
 
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                DEBUG(0,("_spoolss_rfnpcnex: Invalid handle (%s).\n",
                         OUR_HANDLE(handle)));
                goto done;
@@ -2459,12 +2424,11 @@ uint32 _spoolss_rfnpcnex( pipes_struct *p, SPOOL_Q_RFNPCNEX *q_u, SPOOL_R_RFNPCN
        
        switch (Printer->printer_type) {
                case PRINTER_HANDLE_IS_PRINTSERVER:
-                       result = printserver_notify_info(handle, info, 
-                                                        p->mem_ctx);
+                       result = printserver_notify_info(p, handle, info, p->mem_ctx);
                        break;
                        
                case PRINTER_HANDLE_IS_PRINTER:
-                       result = printer_notify_info(handle, info, p->mem_ctx);
+                       result = printer_notify_info(p, handle, info, p->mem_ctx);
                        break;
        }
        
@@ -3312,7 +3276,7 @@ uint32 _spoolss_getprinter(pipes_struct *p, SPOOL_Q_GETPRINTER *q_u, SPOOL_R_GET
 
        *needed=0;
 
-       if (!get_printer_snum(handle, &snum))
+       if (!get_printer_snum(p, handle, &snum))
                return ERROR_INVALID_HANDLE;
 
        switch (level) {
@@ -3831,7 +3795,7 @@ uint32 _spoolss_getprinterdriver2(pipes_struct *p, SPOOL_Q_GETPRINTERDRIVER2 *q_
        pstrcpy(servername, global_myname);
        unistr2_to_ascii(architecture, uni_arch, sizeof(architecture)-1);
 
-       if (!get_printer_snum(handle, &snum))
+       if (!get_printer_snum(p, handle, &snum))
                return ERROR_INVALID_HANDLE;
 
        switch (level) {
@@ -3855,9 +3819,9 @@ uint32 _spoolss_startpageprinter(pipes_struct *p, SPOOL_Q_STARTPAGEPRINTER *q_u,
 {
        POLICY_HND *handle = &q_u->handle;
 
-       Printer_entry *Printer = find_printer_index_by_hnd(handle);
+       Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
 
-       if (OPEN_HANDLE(Printer)) {
+       if (Printer) {
                Printer->page_started=True;
                return 0x0;
        }
@@ -3873,9 +3837,9 @@ uint32 _spoolss_endpageprinter(pipes_struct *p, SPOOL_Q_ENDPAGEPRINTER *q_u, SPO
 {
        POLICY_HND *handle = &q_u->handle;
 
-       Printer_entry *Printer = find_printer_index_by_hnd(handle);
+       Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
 
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                DEBUG(0,("_spoolss_endpageprinter: Invalid handle (%s).\n",OUR_HANDLE(handle)));
                return ERROR_INVALID_HANDLE;
        }
@@ -3902,10 +3866,10 @@ uint32 _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S
        int snum;
        pstring jobname;
        fstring datatype;
-       Printer_entry *Printer = find_printer_index_by_hnd(handle);
+       Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
        struct current_user user;
 
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                DEBUG(0,("_spoolss_startdocprinter: Invalid handle (%s)\n", OUR_HANDLE(handle)));
                return ERROR_INVALID_HANDLE;
        }
@@ -3933,7 +3897,7 @@ uint32 _spoolss_startdocprinter(pipes_struct *p, SPOOL_Q_STARTDOCPRINTER *q_u, S
        }               
        
        /* get the share number of the printer */
-       if (!get_printer_snum(handle, &snum)) {
+       if (!get_printer_snum(p, handle, &snum)) {
                return ERROR_INVALID_HANDLE;
        }
 
@@ -3964,7 +3928,7 @@ uint32 _spoolss_enddocprinter(pipes_struct *p, SPOOL_Q_ENDDOCPRINTER *q_u, SPOOL
 {
        POLICY_HND *handle = &q_u->handle;
 
-       return _spoolss_enddocprinter_internal(handle);
+       return _spoolss_enddocprinter_internal(p, handle);
 }
 
 /****************************************************************************
@@ -3977,9 +3941,9 @@ uint32 _spoolss_writeprinter(pipes_struct *p, SPOOL_Q_WRITEPRINTER *q_u, SPOOL_R
        uint8 *buffer = q_u->buffer;
        uint32 *buffer_written = &q_u->buffer_size2;
 
-       Printer_entry *Printer = find_printer_index_by_hnd(handle);
+       Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
        
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                DEBUG(0,("_spoolss_writeprinter: Invalid handle (%s)\n",OUR_HANDLE(handle)));
                r_u->buffer_written = q_u->buffer_size2;
                return ERROR_INVALID_HANDLE;
@@ -4003,16 +3967,16 @@ static uint32 control_printer(POLICY_HND *handle, uint32 command,
 {
        struct current_user user;
        int snum, errcode = ERROR_INVALID_FUNCTION;
-       Printer_entry *Printer = find_printer_index_by_hnd(handle);
+       Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
 
        get_current_user(&user, p);
 
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                DEBUG(0,("control_printer: Invalid handle (%s)\n", OUR_HANDLE(handle)));
                return ERROR_INVALID_HANDLE;
        }
 
-       if (!get_printer_snum(handle, &snum))
+       if (!get_printer_snum(p, handle, &snum))
                return ERROR_INVALID_HANDLE;
 
        switch (command) {
@@ -4063,9 +4027,9 @@ static uint32 update_printer_sec(POLICY_HND *handle, uint32 level,
        uint32 result;
        int snum;
 
-       Printer_entry *Printer = find_printer_index_by_hnd(handle);
+       Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
 
-       if (!OPEN_HANDLE(Printer) || !get_printer_snum(handle, &snum)) {
+       if (!Printer || !get_printer_snum(p, handle, &snum)) {
                DEBUG(0,("update_printer_sec: Invalid handle (%s)\n",
                         OUR_HANDLE(handle)));
 
@@ -4478,13 +4442,13 @@ static BOOL nt_printer_info_level_equal(NT_PRINTER_INFO_LEVEL *p1,
  * when updating a printer description
  ********************************************************************/
 
-static uint32 update_printer(POLICY_HND *handle, uint32 level,
+static uint32 update_printer(pipes_struct *p, POLICY_HND *handle, uint32 level,
                            const SPOOL_PRINTER_INFO_LEVEL *info,
                            DEVICEMODE *devmode)
 {
        int snum;
        NT_PRINTER_INFO_LEVEL *printer = NULL, *old_printer = NULL;
-       Printer_entry *Printer = find_printer_index_by_hnd(handle);
+       Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
        uint32 result;
 
        DEBUG(8,("update_printer\n"));
@@ -4498,12 +4462,12 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level,
                goto done;
        }
 
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                result = ERROR_INVALID_HANDLE;
                goto done;
        }
 
-       if (!get_printer_snum(handle, &snum)) {
+       if (!get_printer_snum(p, handle, &snum)) {
                result = ERROR_INVALID_HANDLE;
                goto done;
        }
@@ -4582,7 +4546,7 @@ static uint32 update_printer(POLICY_HND *handle, uint32 level,
        free_a_printer(&printer, 2);
        free_a_printer(&old_printer, 2);
 
-       srv_spoolss_sendnotify(handle);
+       srv_spoolss_sendnotify(p, handle);
 
        return result;
 }
@@ -4599,9 +4563,9 @@ uint32 _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_SET
        SEC_DESC_BUF *secdesc_ctr = q_u->secdesc_ctr;
        uint32 command = q_u->command;
 
-       Printer_entry *Printer = find_printer_index_by_hnd(handle);
+       Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
        
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                DEBUG(0,("_spoolss_setprinter: Invalid handle (%s)\n", OUR_HANDLE(handle)));
                return ERROR_INVALID_HANDLE;
        }
@@ -4611,7 +4575,7 @@ uint32 _spoolss_setprinter(pipes_struct *p, SPOOL_Q_SETPRINTER *q_u, SPOOL_R_SET
                case 0:
                        return control_printer(handle, command, p);
                case 2:
-                       return update_printer(handle, level, info, devmode_ctr.devmode);
+                       return update_printer(p, handle, level, info, devmode_ctr.devmode);
                case 3:
                        return update_printer_sec(handle, level, info, p,
                                                  secdesc_ctr);
@@ -4627,16 +4591,15 @@ uint32 _spoolss_fcpn(pipes_struct *p, SPOOL_Q_FCPN *q_u, SPOOL_R_FCPN *r_u)
 {
        POLICY_HND *handle = &q_u->handle;
 
-       Printer_entry *Printer= find_printer_index_by_hnd(handle);
+       Printer_entry *Printer= find_printer_index_by_hnd(p, handle);
        
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                DEBUG(0,("_spoolss_fcpn: Invalid handle (%s)\n", OUR_HANDLE(handle)));
                return ERROR_INVALID_HANDLE;
        }
 
        if (Printer->notify.client_connected==True)
-               if(!srv_spoolss_replycloseprinter(&Printer->notify.client_hnd))
-                       return ERROR_INVALID_HANDLE;
+               srv_spoolss_replycloseprinter(&Printer->notify.client_hnd);
 
        Printer->notify.flags=0;
        Printer->notify.options=0;
@@ -4872,7 +4835,7 @@ uint32 _spoolss_enumjobs( pipes_struct *p, SPOOL_Q_ENUMJOBS *q_u, SPOOL_R_ENUMJO
        *needed=0;
        *returned=0;
 
-       if (!get_printer_snum(handle, &snum))
+       if (!get_printer_snum(p, handle, &snum))
                return ERROR_INVALID_HANDLE;
 
        *returned = print_queue_status(snum, &queue, &prt_status);
@@ -4920,7 +4883,7 @@ uint32 _spoolss_setjob(pipes_struct *p, SPOOL_Q_SETJOB *q_u, SPOOL_R_SETJOB *r_u
                
        memset(&prt_status, 0, sizeof(prt_status));
 
-       if (!get_printer_snum(handle, &snum)) {
+       if (!get_printer_snum(p, handle, &snum)) {
                return ERROR_INVALID_HANDLE;
        }
 
@@ -5647,7 +5610,7 @@ uint32 _spoolss_enumports( pipes_struct *p, SPOOL_Q_ENUMPORTS *q_u, SPOOL_R_ENUM
 
 /****************************************************************************
 ****************************************************************************/
-static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name,
+static uint32 spoolss_addprinterex_level_2( pipes_struct *p, const UNISTR2 *uni_srv_name,
                                const SPOOL_PRINTER_INFO_LEVEL *info,
                                uint32 unk0, uint32 unk1, uint32 unk2, uint32 unk3,
                                uint32 user_switch, const SPOOL_USER_CTR *user,
@@ -5702,7 +5665,7 @@ static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name,
                return ERROR_ACCESS_DENIED;
        }
 
-       if (!open_printer_hnd(handle, name)) {
+       if (!open_printer_hnd(p, handle, name)) {
                /* Handle open failed - remove addition. */
                del_a_printer(printer->info_2->sharename);
                free_a_printer(&printer,2);
@@ -5711,7 +5674,7 @@ static uint32 spoolss_addprinterex_level_2( const UNISTR2 *uni_srv_name,
 
        free_a_printer(&printer,2);
 
-       srv_spoolss_sendnotify(handle);
+       srv_spoolss_sendnotify(p, handle);
 
        return NT_STATUS_NO_PROBLEMO;
 }
@@ -5738,7 +5701,7 @@ uint32 _spoolss_addprinterex( pipes_struct *p, SPOOL_Q_ADDPRINTEREX *q_u, SPOOL_
                        /* but I know what to do ... */
                        return ERROR_INVALID_LEVEL;
                case 2:
-                       return spoolss_addprinterex_level_2(uni_srv_name, info,
+                       return spoolss_addprinterex_level_2(p, uni_srv_name, info,
                                                            unk0, unk1, unk2, unk3,
                                                            user_switch, user, handle);
                default:
@@ -5886,7 +5849,7 @@ uint32 _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S
        uint32 biggest_valuesize;
        uint32 biggest_datasize;
        uint32 data_len;
-       Printer_entry *Printer = find_printer_index_by_hnd(handle);
+       Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
        int snum;
        uint8 *data=NULL;
        uint32 type;
@@ -5905,12 +5868,12 @@ uint32 _spoolss_enumprinterdata(pipes_struct *p, SPOOL_Q_ENUMPRINTERDATA *q_u, S
 
        DEBUG(5,("spoolss_enumprinterdata\n"));
 
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                DEBUG(0,("_spoolss_enumprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle)));
                return ERROR_INVALID_HANDLE;
        }
 
-       if (!get_printer_snum(handle, &snum))
+       if (!get_printer_snum(p,handle, &snum))
                return ERROR_INVALID_HANDLE;
        
        if (get_a_printer(&printer, 2, lp_servicename(snum)) != 0)
@@ -6045,16 +6008,16 @@ uint32 _spoolss_setprinterdata( pipes_struct *p, SPOOL_Q_SETPRINTERDATA *q_u, SP
        NT_PRINTER_PARAM *param = NULL, old_param;
        int snum=0;
        uint32 status = 0x0;
-       Printer_entry *Printer=find_printer_index_by_hnd(handle);
+       Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
        
        DEBUG(5,("spoolss_setprinterdata\n"));
 
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                DEBUG(0,("_spoolss_setprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle)));
                return ERROR_INVALID_HANDLE;
        }
 
-       if (!get_printer_snum(handle, &snum))
+       if (!get_printer_snum(p,handle, &snum))
                return ERROR_INVALID_HANDLE;
 
        status = get_a_printer(&printer, 2, lp_servicename(snum));
@@ -6117,16 +6080,16 @@ uint32 _spoolss_deleteprinterdata(pipes_struct *p, SPOOL_Q_DELETEPRINTERDATA *q_
        NT_PRINTER_PARAM param;
        int snum=0;
        uint32 status = 0x0;
-       Printer_entry *Printer=find_printer_index_by_hnd(handle);
+       Printer_entry *Printer=find_printer_index_by_hnd(p, handle);
        
        DEBUG(5,("spoolss_deleteprinterdata\n"));
        
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                DEBUG(0,("_spoolss_deleteprinterdata: Invalid handle (%s).\n", OUR_HANDLE(handle)));
                return ERROR_INVALID_HANDLE;
        }
 
-       if (!get_printer_snum(handle, &snum))
+       if (!get_printer_snum(p, handle, &snum))
                return ERROR_INVALID_HANDLE;
 
        if (!print_access_check(NULL, snum, PRINTER_ACCESS_ADMINISTER)) {
@@ -6162,11 +6125,11 @@ uint32 _spoolss_addform( pipes_struct *p, SPOOL_Q_ADDFORM *q_u, SPOOL_R_ADDFORM
 
        int count=0;
        nt_forms_struct *list=NULL;
-       Printer_entry *Printer = find_printer_index_by_hnd(handle);
+       Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
 
        DEBUG(5,("spoolss_addform\n"));
 
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                DEBUG(0,("_spoolss_addform: Invalid handle (%s).\n", OUR_HANDLE(handle)));
                return ERROR_INVALID_HANDLE;
        }
@@ -6192,11 +6155,11 @@ uint32 _spoolss_deleteform( pipes_struct *p, SPOOL_Q_DELETEFORM *q_u, SPOOL_R_DE
        int count=0;
        uint32 ret = 0;
        nt_forms_struct *list=NULL;
-       Printer_entry *Printer = find_printer_index_by_hnd(handle);
+       Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
 
        DEBUG(5,("spoolss_deleteform\n"));
 
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                DEBUG(0,("_spoolss_deleteform: Invalid handle (%s).\n", OUR_HANDLE(handle)));
                return ERROR_INVALID_HANDLE;
        }
@@ -6222,11 +6185,11 @@ uint32 _spoolss_setform(pipes_struct *p, SPOOL_Q_SETFORM *q_u, SPOOL_R_SETFORM *
 
        int count=0;
        nt_forms_struct *list=NULL;
-       Printer_entry *Printer = find_printer_index_by_hnd(handle);
+       Printer_entry *Printer = find_printer_index_by_hnd(p, handle);
 
        DEBUG(5,("spoolss_setform\n"));
 
-       if (!OPEN_HANDLE(Printer)) {
+       if (!Printer) {
                DEBUG(0,("_spoolss_setform: Invalid handle (%s).\n", OUR_HANDLE(handle)));
                return ERROR_INVALID_HANDLE;
        }
@@ -6605,7 +6568,7 @@ uint32 _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_
 
        *needed=0;
        
-       if (!get_printer_snum(handle, &snum))
+       if (!get_printer_snum(p, handle, &snum))
                return ERROR_INVALID_HANDLE;
        
        count = print_queue_status(snum, &queue, &prt_status);
@@ -6623,4 +6586,3 @@ uint32 _spoolss_getjob( pipes_struct *p, SPOOL_Q_GETJOB *q_u, SPOOL_R_GETJOB *r_
                return ERROR_INVALID_LEVEL;
        }
 }
-#undef OLD_NTDOMAIN
index b530d66092e0bdfa1ef78e19ed958ac47116f785..a3176bfd739c667746ec08abb91f0fb79b86d924 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
  *  Unix SMB/Netbios implementation.
  *  Version 1.9.
@@ -248,5 +247,3 @@ BOOL api_srvsvc_rpc(pipes_struct *p)
 {
        return api_rpcTNP(p, "api_srvsvc_rpc", api_srv_cmds);
 }
-
-#undef OLD_NTDOMAIN
index 80794609eac1d97d706fe990eded18b9856cd722..6e0043b0bb1fdfa27c54f82a7a03676745fa0e13 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
  *  Unix SMB/Netbios implementation.
  *  Version 1.9.
@@ -695,6 +694,9 @@ uint32 _srv_net_srv_get_info(pipes_struct *p, SRV_Q_NET_SRV_GET_INFO *q_u, SRV_R
                                  lp_default_server_announce(),
                                  string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH));
                break;
+       case 100:
+               init_srv_info_100(&ctr->srv.sv100, 500, global_myname);
+               break;
        default:
                status = NT_STATUS_INVALID_INFO_CLASS;
                break;
@@ -863,4 +865,3 @@ uint32 _srv_net_remote_tod(pipes_struct *p, SRV_Q_NET_REMOTE_TOD *q_u, SRV_R_NET
 
        return r_u->status;
 }
-#undef OLD_NTDOMAIN
index 8349b7add69af5d44abee8d7284b32b31c81c0f4..82125a70858ef7b0662e6636a84eb3f68554e35b 100644 (file)
@@ -1,5 +1,3 @@
-#define OLD_NTDOMAIN 1
-
 /* 
  *  Unix SMB/Netbios implementation.
  *  Version 1.9.
@@ -80,7 +78,7 @@ rid_name domain_group_rids[] =
     { 0                             , NULL }
 };
 
-int make_dom_gids(char *gids_str, DOM_GID **ppgids)
+int make_dom_gids(TALLOC_CTX *ctx, char *gids_str, DOM_GID **ppgids)
 {
   char *ptr;
   pstring s2;
@@ -99,10 +97,10 @@ int make_dom_gids(char *gids_str, DOM_GID **ppgids)
        count++)
     ;
 
-  gids = (DOM_GID *)malloc( sizeof(DOM_GID) * count );
+  gids = (DOM_GID *)talloc(ctx, sizeof(DOM_GID) * count );
   if(!gids)
   {
-    DEBUG(0,("make_dom_gids: malloc fail !\n"));
+    DEBUG(0,("make_dom_gids: talloc fail !\n"));
     return 0;
   }
 
@@ -192,11 +190,10 @@ void get_domain_user_groups(char *domain_groups, char *user)
        }
 }
 
-
 /*******************************************************************
- lookup_group_name
+ Look up a local (domain) rid and return a name and type.
  ********************************************************************/
-uint32 lookup_group_name(uint32 rid, char *group_name, uint32 *type)
+uint32 local_lookup_group_name(uint32 rid, char *group_name, uint32 *type)
 {
        int i = 0; 
        (*type) = SID_NAME_DOM_GRP;
@@ -220,9 +217,9 @@ uint32 lookup_group_name(uint32 rid, char *group_name, uint32 *type)
 }
 
 /*******************************************************************
- lookup_alias_name
+ Look up a local alias rid and return a name and type.
  ********************************************************************/
-uint32 lookup_alias_name(uint32 rid, char *alias_name, uint32 *type)
+uint32 local_lookup_alias_name(uint32 rid, char *alias_name, uint32 *type)
 {
        int i = 0; 
        (*type) = SID_NAME_WKN_GRP;
@@ -246,11 +243,11 @@ uint32 lookup_alias_name(uint32 rid, char *alias_name, uint32 *type)
 }
 
 /*******************************************************************
- lookup_user_name
+ Look up a local user rid and return a name and type.
  ********************************************************************/
-uint32 lookup_user_name(uint32 rid, char *user_name, uint32 *type)
+uint32 local_lookup_user_name(uint32 rid, char *user_name, uint32 *type)
 {
-       struct sam_disp_info *disp_info;
+       SAM_ACCOUNT *sampwd;
        int i = 0;
        (*type) = SID_NAME_USER;
 
@@ -271,12 +268,12 @@ uint32 lookup_user_name(uint32 rid, char *user_name, uint32 *type)
 
        /* ok, it's a user.  find the user account */
        become_root();
-       disp_info = pdb_sam_to_dispinfo(pdb_getsampwrid(rid));
+       sampwd = pdb_getsampwrid(rid);
        unbecome_root();
 
-       if (disp_info != NULL)
+       if (sampwd != NULL)
        {
-               fstrcpy(user_name, disp_info->smb_name);
+               fstrcpy(user_name, pdb_get_username(sampwd) );
                DEBUG(5,(" = %s\n", user_name));
                return 0x0;
        }
@@ -286,9 +283,9 @@ uint32 lookup_user_name(uint32 rid, char *user_name, uint32 *type)
 }
 
 /*******************************************************************
lookup_group_rid
Look up a local (domain) group name and return a rid
  ********************************************************************/
-uint32 lookup_group_rid(char *group_name, uint32 *rid)
+uint32 local_lookup_group_rid(char *group_name, uint32 *rid)
 {
        char *grp_name;
        int i = -1; /* start do loop at -1 */
@@ -305,9 +302,9 @@ uint32 lookup_group_rid(char *group_name, uint32 *rid)
 }
 
 /*******************************************************************
lookup_alias_rid
Look up a local (BUILTIN) alias name and return a rid
  ********************************************************************/
-uint32 lookup_alias_rid(char *alias_name, uint32 *rid)
+uint32 local_lookup_alias_rid(char *alias_name, uint32 *rid)
 {
        char *als_name;
        int i = -1; /* start do loop at -1 */
@@ -324,25 +321,23 @@ uint32 lookup_alias_rid(char *alias_name, uint32 *rid)
 }
 
 /*******************************************************************
lookup_user_rid
Look up a local user name and return a rid
  ********************************************************************/
-uint32 lookup_user_rid(char *user_name, uint32 *rid)
+uint32 local_lookup_user_rid(char *user_name, uint32 *rid)
 {
-       SAM_ACCOUNT *sam_pass;
+       SAM_ACCOUNT *sampass;
        (*rid) = 0;
 
        /* find the user account */
        become_root();
-       sam_pass = pdb_getsampwnam(user_name);
+       sampass = pdb_getsampwnam(user_name);
        unbecome_root();
 
-       if (sam_pass != NULL)
+       if (sampass != NULL)
        {
-               *rid = pdb_get_user_rid(sam_pass);
+               (*rid) = pdb_get_user_rid(sampass);
                return 0x0;
        }
 
        return NT_STATUS_NONE_MAPPED;
 }
-
-#undef OLD_NTDOMAIN
index e648c0f122fccb21ad7efe3838dd311a6cbceff6..12e4a8f335910b900aff87761bde60af1cf0aab5 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
  *  Unix SMB/Netbios implementation.
  *  Version 1.9.
@@ -72,5 +71,3 @@ BOOL api_wkssvc_rpc(pipes_struct *p)
 {
        return api_rpcTNP(p, "api_wkssvc_rpc", api_wks_cmds);
 }
-
-#undef OLD_NTDOMAIN
index 688c7f1d0173cee1dc7d3c09d9b596d3d1d67e69..40771d2fb93a354111e62f43676c786df4745778 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
  *  Unix SMB/Netbios implementation.
  *  Version 1.9.
@@ -79,4 +78,3 @@ uint32 _wks_query_info(pipes_struct *p, WKS_Q_QUERY_INFO *q_u, WKS_R_QUERY_INFO
 
        return r_u->status;
 }
-#undef OLD_NTDOMAIN
index 23e2fab0e781e4b5c125ffea375555f153bb2225..59830e77426b1c45a49f8d882e0785105f64eec2 100644 (file)
@@ -1,4 +1,3 @@
-#define NEW_NTDOMAIN 1
 /* 
    Unix SMB/Netbios implementation.
    Version 2.2
@@ -454,5 +453,3 @@ struct cmd_set samr_commands[] = {
        { "querygroupmem", cmd_samr_query_groupmem, "Query group membership" },
        { NULL, NULL, NULL }
 };
-
-#undef NEW_NTDOMAIN
index 16caf8b52e5732d53f621d44cfe3c15c99f3b914..e8dc29f80ac793d9a20950b0ee39a59813ca7a19 100644 (file)
@@ -1,5 +1,3 @@
-#define OLD_NTDOMAIN 1
-
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -633,5 +631,3 @@ void process_blocking_lock_queue(time_t t)
     blr = (blocking_lock_record *)ubi_slNext(blr);
   }
 }
-
-#undef OLD_NTDOMAIN
index ba68557fdf795021dc8fea10984f43efa50b0678..418ad6a6755a3ceb157cb8dc9649977e3ed380af 100644 (file)
@@ -1,5 +1,3 @@
-#define OLD_NTDOMAIN 1
-
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -937,5 +935,3 @@ BOOL check_plaintext_password(char *user, char *old_passwd,
        else
                return (True);
 }
-
-#undef OLD_NTDOMAIN
index 87bd31332768caf48c55868899bd4f71a17bc787..56aad643914d5e7d59d43de3222bb84aec51219a 100644 (file)
@@ -1,5 +1,3 @@
-#define OLD_NTDOMAIN 1
-
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -243,5 +241,3 @@ int close_file(files_struct *fsp, BOOL normal_close)
                return close_statfile(fsp, normal_close);
        return close_normal_file(fsp, normal_close);
 }
-
-#undef OLD_NTDOMAIN
index cd4ca9ded4d0f091ef8f5d7bd3310b13bba4ec53..e9f79fdf32bdf508d2c3f5e3637ea947a89fe381 100644 (file)
@@ -1,5 +1,3 @@
-#define OLD_NTDOMAIN 1
-
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -200,5 +198,3 @@ void conn_free(connection_struct *conn)
        ZERO_STRUCTP(conn);
        free(conn);
 }
-
-#undef OLD_NTDOMAIN
index a7e05c5682654040c6eb8612ebec49266ff1016e..5bf0dec944490ce3b49f088a19a3ab7ef9728c53 100644 (file)
@@ -1,5 +1,3 @@
-#define OLD_NTDOMAIN 1
-
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -893,5 +891,3 @@ void DirCacheFlush(int snum)
                entry = (dir_cache_entry *)next;
        }
 }
-
-#undef OLD_NTDOMAIN
index a4b4f65ad97362dd43f60cbca14531c047ca78ff..8b2c482b0af603deea4cf3156358e1219020b501 100644 (file)
@@ -1,5 +1,3 @@
-#define OLD_NTDOMAIN 1
-
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -334,5 +332,3 @@ BOOL set_filetime(connection_struct *conn, char *fname, time_t mtime)
   
   return(True);
 } 
-
-#undef OLD_NTDOMAIN
index 49da44d68e372c7e1c429abf1f006263f11ae639..d879f9a93c4d06877671162e8bbbd185bc415dea 100644 (file)
@@ -1,5 +1,3 @@
-#define OLD_NTDOMAIN 1
-
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -146,5 +144,3 @@ int error_packet(char *inbuf,char *outbuf,int error_class,uint32 error_code,int
   
   return(outsize);
 }
-
-#undef OLD_NTDOMAIN
index 35e2f1455e95cddffb99ff591777646724715fc9..c79f0aa89e03803fa897964879742ee266f48c66 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -584,4 +583,3 @@ void sync_file(connection_struct *conn, files_struct *fsp)
       conn->vfs_ops.fsync(fsp,fsp->fd);
     }
 }
-#undef OLD_NTDOMAIN
index aedd2e820f419876c5eb3fadb3bf92c86f19ed37..bdbcd81b644538d886fb55dd5ac5de90b444595c 100644 (file)
@@ -1,5 +1,3 @@
-#define OLD_NTDOMAIN 1
-
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -514,6 +512,3 @@ static BOOL scan_directory(char *path, char *name,connection_struct *conn,BOOL d
   CloseDir(cur_dir);
   return(False);
 }
-
-
-#undef OLD_NTDOMAIN
index 2909d49a2a6a82c822040b0bb97b6de51d84cb73..a4837a1a8bc9b0d6704e79b4d4d604d0b9892e68 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -364,4 +363,3 @@ void file_chain_restore(void)
 {
        chain_fsp = oplock_save_chain_fsp;
 }
-#undef OLD_NTDOMAIN
index 5ade6672093f38a95a5c01b102989eb8ad367be6..3b9e34b4d71127ddb0eb9823d1aa6cc2f83d7548 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -517,4 +516,3 @@ int reply_trans(connection_struct *conn, char *inbuf,char *outbuf, int size, int
        END_PROFILE(SMBtrans);
        return(outsize);
 }
-#undef OLD_NTDOMAIN
index c29f0df4341b8948d0c1f69936d52c11895e6e44..f5e1de16087df8736ce4954171020795855b876d 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -3330,6 +3329,3 @@ int api_reply(connection_struct *conn,uint16 vuid,char *outbuf,char *data,char *
   
   return -1;
 }
-
-
-#undef OLD_NTDOMAIN
index ab3c841d9c8aad58f9dad5f2e9358a1f454997a7..3afe7218e0969f2ae6e40d94ec9609cf078aea4c 100644 (file)
@@ -1,5 +1,3 @@
-#define OLD_NTDOMAIN 1
-
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -235,5 +233,3 @@ int reply_sendend(connection_struct *conn,
   END_PROFILE(SMBsendend);
   return(outsize);
 }
-
-#undef OLD_NTDOMAIN
index c2026f46f9f67bdff0e41728c3d2ddb89bb9acac..e15af3f3ae18b486d68e0d529a1d83bb7a45f59b 100644 (file)
@@ -1,5 +1,3 @@
-#define OLD_NTDOMAIN 1
-
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -448,5 +446,3 @@ int reply_negprot(connection_struct *conn,
   END_PROFILE(SMBnegprot);
   return(outsize);
 }
-
-#undef OLD_NTDOMAIN
index 912ab43e9ee390db3204e5cb45dc19d5d0cc37b7..429723c19e74c8b0f02ee3ec08c4f5f9f971f6b4 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /*
    Unix SMB/Netbios implementation.
    Version 3.0
@@ -224,6 +223,3 @@ BOOL init_change_notify(void)
 
        return True;
 }
-
-
-#undef OLD_NTDOMAIN
index 5a2f86531032d1b29fd49f5829584896e0d52f7d..a0a61569a8b396c44d747ead0a8944916d471121 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /*
    Unix SMB/Netbios implementation.
    Version 3.0
@@ -195,5 +194,3 @@ struct cnotify_fns *hash_notify_init(void)
   uint16 vuid = (lp_security() == SEC_SHARE) ? UID_FIELD_INVALID : 
   SVAL(cnbp->request_buf,smb_uid);
 */
-
-#undef OLD_NTDOMAIN
index db823601f1919d2252f4dd94928b61fc3675574e..243a16a7f7a2bb093aad6604bf3fff358af43780 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /*
    Unix SMB/Netbios implementation.
    Version 3.0
@@ -207,5 +206,3 @@ struct cnotify_fns *kernel_notify_init(void)
 #else
  void notify_kernel_dummy(void) {}
 #endif /* HAVE_KERNEL_CHANGE_NOTIFY */
-
-#undef OLD_NTDOMAIN
index d9a93f8d78013b23fb040726d9078de2112ec07b..1ccac83b78acc92def67de13bcc5f6651329b8ad 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /*
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -1974,4 +1973,3 @@ due to being in oplock break state.\n" ));
                     calls have already sent it. If outsize != -1 then it is
                     returning an error packet. */
 }
-#undef OLD_NTDOMAIN
index 3665e7d20f78379876032227d657630b7c159850..afcaeff1ae3ac8578af2e7a408e6d44846d0c322 100644 (file)
@@ -1,5 +1,3 @@
-#define OLD_NTDOMAIN 1
-
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -1158,5 +1156,3 @@ free_and_exit:
     free((char *)old_shares);
   return(ret);
 }
-
-#undef OLD_NTDOMAIN
index 4f26eaf7f241105bebf788fe23673684b293070c..e0b494017a05b6a05b12186cbd8473421a39aa14 100644 (file)
@@ -1,5 +1,3 @@
-#define OLD_NTDOMAIN 1
-
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -978,7 +976,6 @@ should be %d\n", (int)pid, share_entry->op_port, global_oplock_port));
   while(time_left >= 0)
   {
     char op_break_reply[OPBRK_CMD_HEADER_LEN+OPLOCK_BREAK_MSG_LEN];
-    int32 reply_msg_len;
     uint16 reply_from_port;
     char *reply_msg_start;
     fd_set fds;
@@ -1029,7 +1026,6 @@ should be %d\n", (int)pid, share_entry->op_port, global_oplock_port));
       return False;
     }
 
-    reply_msg_len = IVAL(op_break_reply,OPBRK_CMD_LEN_OFFSET);
     reply_from_port = SVAL(op_break_reply,OPBRK_CMD_PORT_OFFSET);
 
     reply_msg_start = &op_break_reply[OPBRK_CMD_HEADER_LEN];
@@ -1234,5 +1230,3 @@ address %lx. Error was %s\n", (long)htonl(INADDR_LOOPBACK), strerror(errno)));
 
        return True;
 }
-
-#undef OLD_NTDOMAIN
index cf1cbbb0fcd2e1dcfe38c4538556030a8813d444..faf7e8e3c87971591e05a544d4c38f7d14b3229e 100644 (file)
@@ -1,6 +1,4 @@
-#define OLD_NTDOMAIN 1
-
-/* 
+/*
    Unix SMB/Netbios implementation.
    Version 2.x
    IRIX kernel oplock processing
@@ -278,5 +276,3 @@ struct kernel_oplocks *irix_init_kernel_oplocks(void)
 #else
  void oplock_irix_dummy(void) {}
 #endif /* HAVE_KERNEL_OPLOCKS_IRIX */
-
-#undef OLD_NTDOMAIN
index d97378ac5df08206a55a40e521b129bffe648cf5..e070761f1088249fe8de046939a4241bc847aead 100644 (file)
@@ -1,5 +1,3 @@
-#define OLD_NTDOMAIN 1
-
 /* 
    Unix SMB/Netbios implementation.
    Version 3.0
@@ -302,6 +300,3 @@ struct kernel_oplocks *linux_init_kernel_oplocks(void)
 #else
  void oplock_linux_dummy(void) {}
 #endif /* HAVE_KERNEL_OPLOCKS_LINUX */
-
-#undef OLD_NTDOMAIN
-
index 311a01950681a106d590265170c72282f7e977de..849aa87a75d63f645a449c39ed32307b1fd99bf7 100644 (file)
@@ -1,5 +1,3 @@
-#define OLD_NTDOMAIN 1
-
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -1610,5 +1608,3 @@ BOOL domain_client_validate( char *user, char *domain,
   cli_shutdown(&cli);
   return True;
 }
-
-#undef OLD_NTDOMAIN
index df7141764ceb72862f17b86d2366ce01733959c6..366707cd5896cb5a410b3bada2bb70d10f60a5d2 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -262,5 +261,3 @@ int reply_pipe_close(connection_struct *conn, char *inbuf,char *outbuf)
 
        return(outsize);
 }
-
-#undef OLD_NTDOMAIN
index 9c5afad9c120b1dd96c701f9599e9995200d638b..fe2974b235d1dbc8cdc29083be71c3c0077d3168 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /*
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -1700,4 +1699,3 @@ int fchmod_acl(int fd, mode_t mode)
        sys_acl_free_acl(posix_acl);
        return ret;
 }
-#undef OLD_NTDOMAIN
index f8fde41b77102797c40608e55fd36341f51081f4..a34555adc17b94212adb56ec4a310109de6a248b 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -1256,5 +1255,3 @@ void smbd_process(void)
                }
        }
 }
-
-#undef OLD_NTDOMAIN
index a505160b7df95467423c5300d31ae9a8761ace63..04e7b4c101d0246446ba07baae920860df04f99f 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -4840,4 +4839,3 @@ int reply_getattrE(connection_struct *conn, char *inbuf,char *outbuf, int size,
   END_PROFILE(SMBgetattrE);
   return(outsize);
 }
-#undef OLD_NTDOMAIN
index f3cc9e04e0bc294ac0c3f959d4fd2fb940c1e5fb..f604f6cce71eabcf2744c2b023d395ad79ffc8c8 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -459,4 +458,3 @@ void init_sec_ctx(void)
        current_user.vuid = UID_FIELD_INVALID;
        current_user.nt_user_token = NULL;
 }
-#undef OLD_NTDOMAIN
index 6457dd6295e0c9fc1fde2ea4ae0138365691bdf8..d2a7ad3be4948e1b8ed4fce122c1486564c16918 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -502,12 +501,6 @@ static void init_structs(void )
        /* for RPC pipes */
        init_rpc_pipe_hnd();
 
-       /* for LSA handles */
-       init_lsa_policy_hnd();
-
-       /* for SPOOLSS handles */
-       init_printer_hnd();
-       
        init_dptrs();
 
        secrets_init();
@@ -804,5 +797,3 @@ static void usage(char *pname)
        exit_server("normal exit");
        return(0);
 }
-
-#undef OLD_NTDOMAIN
index f0ab2ba77127b23ff500b17c9ee06b61eccd4397..02405e8dda598c327a3dec382671898512b45296 100644 (file)
@@ -1,5 +1,3 @@
-#define OLD_NTDOMAIN 1
-
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -681,5 +679,3 @@ void close_cnum(connection_struct *conn, uint16 vuid)
        }
        conn_free(conn);
 }
-
-#undef OLD_NTDOMAIN
index d94a7758462b6f4df1f4c05015f71da347dc073c..6cc65d1b21be0fd082939e4029d43bbe28c905ab 100644 (file)
@@ -1,5 +1,3 @@
-#define OLD_NTDOMAIN 1
-
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -2511,5 +2509,3 @@ int reply_trans2(connection_struct *conn,
                           call_trans2xxx calls have already sent
                           it. If outsize != -1 then it is returning */
 }
-
-#undef OLD_NTDOMAIN
index db43106b77d77fe0007da6e68c3cdca754caa3e0..3d37021fff5fe8590b3fea4b878807c14b2c5eef 100644 (file)
@@ -1,5 +1,3 @@
-#define OLD_NTDOMAIN 1
-
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -521,5 +519,3 @@ BOOL sid_to_gid(DOM_SID *psid, gid_t *pgid, enum SID_NAME_USE *sidtype)
 
        return True;
 }
-
-#undef OLD_NTDOMAIN
index ad4d4ddbef20b8f085cde7230d9d2ea132474fec..8750f7115134cf8694910660ba245a563ea21ee0 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /* 
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -543,5 +542,3 @@ int vfswrap_fchmod_acl(files_struct *fsp, int fd, mode_t mode)
 {
        return fchmod_acl(fd, mode);
 }
-
-#undef OLD_NTDOMAIN
index 2cd83c37f3ab93bb2730a1a444409b853d1280ad..b8aa290cab965fc2b2d32e6d3548d31b92167dcc 100644 (file)
@@ -1,4 +1,3 @@
-#define OLD_NTDOMAIN 1
 /*
    Unix SMB/Netbios implementation.
    Version 1.9.
@@ -895,4 +894,3 @@ BOOL reduce_name(connection_struct *conn, char *s,char *dir,BOOL widelinks)
   return(True);
 #endif
 }
-#undef OLD_NTDOMAIN
index d20760bee12b06c4a067865d21e24e81718fed78..94bfe464e4e9addcd78852aeee35a86260a0bee9 100644 (file)
@@ -221,13 +221,12 @@ static BOOL password_change(const char *remote_machine, char *user_name,
 
        if (remote_machine != NULL) {
                if (local_flags & (LOCAL_ADD_USER|LOCAL_DELETE_USER|LOCAL_DISABLE_USER|LOCAL_ENABLE_USER|
-                                  LOCAL_TRUST_ACCOUNT|LOCAL_SET_NO_PASSWORD)) 
-               {
+                                                       LOCAL_TRUST_ACCOUNT|LOCAL_SET_NO_PASSWORD)) {
                        /* these things can't be done remotely yet */
                        return False;
                }
-               ret = remote_password_change(remote_machine, user_name, old_passwd, 
-                                            new_passwd, err_str, sizeof(err_str));
+               ret = remote_password_change(remote_machine, user_name, 
+                                                                        old_passwd, new_passwd, err_str, sizeof(err_str));
                if(*err_str)
                        fprintf(stderr, err_str);
                return ret;
@@ -409,11 +408,9 @@ static int process_root(int argc, char *argv[])
                 * smbpasswd file) then we need to prompt for a new password.
                 */
 
-               if(local_flags & LOCAL_ENABLE_USER) 
-               {
+               if(local_flags & LOCAL_ENABLE_USER) {
                        SAM_ACCOUNT *sampass = pdb_getsampwnam(user_name);
-                       if((sampass != NULL) && (pdb_get_lanman_passwd(sampass) != NULL)) 
-                       {
+                       if((sampass != NULL) && (pdb_get_lanman_passwd(sampass) != NULL)) {
                                new_passwd = xstrdup("XXXX"); /* Don't care. */
                        }
                }
@@ -427,15 +424,13 @@ static int process_root(int argc, char *argv[])
                }
        }
        
-       if (!password_change(remote_machine, user_name, old_passwd, new_passwd, local_flags)) 
-       {
+       if (!password_change(remote_machine, user_name, old_passwd, new_passwd, local_flags)) {
                fprintf(stderr,"Failed to modify password entry for user %s\n", user_name);
                result = 1;
                goto done;
        } 
 
-       if(!(local_flags & (LOCAL_ADD_USER|LOCAL_DISABLE_USER|LOCAL_ENABLE_USER|LOCAL_DELETE_USER|LOCAL_SET_NO_PASSWORD))) 
-       {
+       if(!(local_flags & (LOCAL_ADD_USER|LOCAL_DISABLE_USER|LOCAL_ENABLE_USER|LOCAL_DELETE_USER|LOCAL_SET_NO_PASSWORD))) {
                SAM_ACCOUNT *sampass = pdb_getsampwnam(user_name);
                printf("Password changed for user %s.", user_name );
                if( (sampass != NULL) && (pdb_get_acct_ctrl(sampass)&ACB_DISABLED) )
index edc861d2672cbac8242edca5b91e9dfb5c2c0552..06abd09d92908a0639bae661a66459fc37b9c1cf 100644 (file)
@@ -58,8 +58,8 @@ static BOOL processes_only=False;
 static int show_brl;
 
 /* we need these because we link to locking*.o */
- void become_root(BOOL save_dir) {}
- void unbecome_root(BOOL restore_dir) {}
+ void become_root(void) {}
+ void unbecome_root(void) {}
 
 
 /* added by OH */
index f85ba7bebdcb79dd4d5dd0b91b5c98ee025222df..e4fda2d99cd0e9a3e2ddfde6436fbac690ad8893 100644 (file)
@@ -332,7 +332,6 @@ static BOOL cgi_handle_authorization(char *line)
 {
        char *p, *user, *user_pass;
        struct passwd *pass = NULL;
-       BOOL ret = False;
        BOOL got_name = False;
        BOOL tested_pass = False;
        fstring default_user_lookup;
@@ -378,7 +377,7 @@ static BOOL cgi_handle_authorization(char *line)
 
        tested_pass = True;
 
-       if((ret = pass_check(user, user_pass, strlen(user_pass), NULL, NULL)) == True) {
+       if(pass_check(user, user_pass, strlen(user_pass), NULL, NULL) == True) {
 
                /*
                 * Password was ok.
index d0a78fb243207e5eda40b2ecbbc6405cf125b146..1e8d23f6e3053c8315da96c32f2ce241662b507f 100644 (file)
@@ -50,8 +50,8 @@ static int iNumNonAutoPrintServices = 0;
 #define RHOST "remote_host"
 
 /* we need these because we link to locking*.o */
- void become_root(BOOL save_dir) {}
- void unbecome_root(BOOL restore_dir) {}
+ void become_root(void) {}
+ void unbecome_root(void) {}
 
 /****************************************************************************
 ****************************************************************************/