Rename the 'hidden' variable to 'administrative share'.
[ira/wip.git] / source / rpc_server / srv_srvsvc_nt.c
index 3e79b420a9956a8ab6203b102ee9c8f6199992d8..8a25b6cfd5134555ec31d3fe1950e2695c0cdddc 100644 (file)
@@ -8,7 +8,7 @@
  *  
  *  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
- *  the Free Software Foundation; either version 2 of the License, or
+ *  the Free Software Foundation; either version 3 of the License, or
  *  (at your option) any later version.
  *  
  *  This program is distributed in the hope that it will be useful,
  *  GNU General Public License for more details.
  *  
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  */
 
 /* This is the implementation of the srvsvc pipe. */
 
 #include "includes.h"
 
-extern struct generic_mapping file_generic_mapping;
-extern userdom_struct current_user_info;
+extern const struct generic_mapping file_generic_mapping;
 
 #undef DBGC_CLASS
 #define DBGC_CLASS DBGC_RPC_SRV
@@ -35,12 +33,13 @@ extern userdom_struct current_user_info;
 
 struct file_enum_count {
        TALLOC_CTX *ctx;
+       const char *username;
        int count;
        FILE_INFO_3 *info;
 };
 
 struct sess_file_count {
-       pid_t pid;
+       struct server_id pid;
        uid_t uid;
        int count;
 };
@@ -49,150 +48,171 @@ struct sess_file_count {
  Count the entries belonging to a service in the connection db.
 ****************************************************************************/
 
-static int pipe_enum_fn( TDB_CONTEXT *the_tdb, TDB_DATA kbuf, TDB_DATA dbuf, void *p)
+static int pipe_enum_fn( struct db_record *rec, void *p)
 {
        struct pipe_open_rec prec;
        struct file_enum_count *fenum = (struct file_enum_count *)p;
-       if (dbuf.dsize != sizeof(struct pipe_open_rec))
+       FILE_INFO_3 *f;
+       int i = fenum->count;
+       char *fullpath = NULL;
+       const char *username;
+
+       if (rec->value.dsize != sizeof(struct pipe_open_rec))
                return 0;
 
-       memcpy(&prec, dbuf.dptr, sizeof(struct pipe_open_rec));
-       if ( process_exists(prec.pid) ) {
-               FILE_INFO_3 *f;
-               int i = fenum->count;
-               pstring fullpath;
-               
-               snprintf( fullpath, sizeof(fullpath), "\\PIPE\\%s", prec.name );
-               
-               f = TALLOC_REALLOC_ARRAY( fenum->ctx, fenum->info, FILE_INFO_3, i+1 );
-               if ( !f ) {
-                       DEBUG(0,("conn_enum_fn: realloc failed for %d items\n", i+1));
-                       return 1;
-               }
-               fenum->info = f;
-               
-               
-               init_srv_file_info3( &fenum->info[i], 
-                       (uint32)((procid_to_pid(&prec.pid)<<16) & prec.pnum),
-                       (FILE_READ_DATA|FILE_WRITE_DATA), 
-                       0,
-                       uidtoname( prec.uid ),
-                       fullpath );
-                       
-               fenum->count++;
+       memcpy(&prec, rec->value.dptr, sizeof(struct pipe_open_rec));
+
+       if ( !process_exists(prec.pid) ) {
+               return 0;
+       }
+
+       username = uidtoname(prec.uid);
+
+       if ((fenum->username != NULL)
+           && !strequal(username, fenum->username)) {
+               return 0;
        }
 
+       fullpath = talloc_asprintf(fenum->ctx, "\\PIPE\\%s", prec.name );
+       if (!fullpath) {
+               return 1;
+       }
+
+       f = TALLOC_REALLOC_ARRAY( fenum->ctx, fenum->info, FILE_INFO_3, i+1 );
+       if ( !f ) {
+               DEBUG(0,("conn_enum_fn: realloc failed for %d items\n", i+1));
+               return 1;
+       }
+       fenum->info = f;
+
+       init_srv_file_info3(
+               &fenum->info[i],
+               (uint32)((procid_to_pid(&prec.pid)<<16) & prec.pnum),
+               (FILE_READ_DATA|FILE_WRITE_DATA),
+               0, username, fullpath);
+
+       TALLOC_FREE(fullpath);
+       fenum->count++;
+
        return 0;
 }
 
 /*******************************************************************
 ********************************************************************/
 
-static WERROR net_enum_pipes( TALLOC_CTX *ctx, FILE_INFO_3 **info, 
+static WERROR net_enum_pipes( TALLOC_CTX *ctx, const char *username,
+                             FILE_INFO_3 **info, 
                               uint32 *count, uint32 resume )
 {
        struct file_enum_count fenum;
-       TDB_CONTEXT *conn_tdb = conn_tdb_ctx();
-
-       if ( !conn_tdb ) {
-               DEBUG(0,("net_enum_pipes: Failed to retrieve the connections tdb handle!\n"));
-               return WERR_ACCESS_DENIED;
-       }
        
        fenum.ctx = ctx;
+       fenum.username = username;
        fenum.count = *count;
        fenum.info = *info;
 
-       if (tdb_traverse(conn_tdb, pipe_enum_fn, &fenum) == -1) {
-               DEBUG(0,("net_enum_pipes: traverse of connections.tdb failed with error %s.\n",
-                       tdb_errorstr(conn_tdb) ));
+       if (connections_traverse(pipe_enum_fn, &fenum) == -1) {
+               DEBUG(0,("net_enum_pipes: traverse of connections.tdb "
+                        "failed\n"));
                return WERR_NOMEM;
        }
-       
+
        *info  = fenum.info;
        *count = fenum.count;
-       
-       return WERR_OK;}
+
+       return WERR_OK;
+}
 
 /*******************************************************************
 ********************************************************************/
 
-/* global needed to make use of the share_mode_forall() callback */
-static struct file_enum_count f_enum_cnt;
-
-static void enum_file_fn( const struct share_mode_entry *e, 
+static void enum_file_fn( const struct share_mode_entry *e,
                           const char *sharepath, const char *fname,
-                         void *dummy )
+                         void *private_data )
 {
-       struct file_enum_count *fenum = &f_enum_cnt;
+       struct file_enum_count *fenum =
+               (struct file_enum_count *)private_data;
+
+       FILE_INFO_3 *f;
+       int i = fenum->count;
+       files_struct fsp;
+       struct byte_range_lock *brl;
+       int num_locks = 0;
+       char *fullpath = NULL;
+       uint32 permissions;
+       const char *username;
+
        /* If the pid was not found delete the entry from connections.tdb */
 
-       if ( process_exists(e->pid) ) {
-               FILE_INFO_3 *f;
-               int i = fenum->count;
-               files_struct fsp;
-               struct byte_range_lock *brl;
-               int num_locks = 0;
-               pstring fullpath;
-               uint32 permissions;
-               
-               f = TALLOC_REALLOC_ARRAY( fenum->ctx, fenum->info, FILE_INFO_3, i+1 );                  
-               if ( !f ) {
-                       DEBUG(0,("conn_enum_fn: realloc failed for %d items\n", i+1));
-                       return;
-               }
-               fenum->info = f;
+       if ( !process_exists(e->pid) ) {
+               return;
+       }
 
-               /* need to count the number of locks on a file */
-               
-               ZERO_STRUCT( fsp );             
-               fsp.dev   = e->dev;
-               fsp.inode = e->inode;
-               
-               if ( (brl = brl_get_locks_readonly(NULL,&fsp)) != NULL ) {
-                       num_locks = brl->num_locks;
-                       TALLOC_FREE( brl );
-               }
-               
-               if ( strcmp( fname, "." ) == 0 ) {
-                       pstr_sprintf( fullpath, "C:%s", sharepath );
-               } else {
-                       pstr_sprintf( fullpath, "C:%s/%s", sharepath, fname );
-               }
-               string_replace( fullpath, '/', '\\' );
-               
-               /* mask out create (what ever that is) */
-               permissions = e->share_access & (FILE_READ_DATA|FILE_WRITE_DATA);
-
-               /* now fill in the FILE_INFO_3 struct */
-               init_srv_file_info3( &fenum->info[i], 
-                       e->share_file_id,
-                       permissions,
-                       num_locks,
-                       uidtoname(e->uid),
-                       fullpath );
-                       
-               fenum->count++;
+       username = uidtoname(e->uid);
+
+       if ((fenum->username != NULL)
+           && !strequal(username, fenum->username)) {
+               return;
        }
 
-       return;
+       f = TALLOC_REALLOC_ARRAY( fenum->ctx, fenum->info, FILE_INFO_3, i+1 );
+       if ( !f ) {
+               DEBUG(0,("conn_enum_fn: realloc failed for %d items\n", i+1));
+               return;
+       }
+       fenum->info = f;
+
+       /* need to count the number of locks on a file */
+
+       ZERO_STRUCT( fsp );
+       fsp.file_id = e->id;
+
+       if ( (brl = brl_get_locks(talloc_tos(), &fsp)) != NULL ) {
+               num_locks = brl->num_locks;
+               TALLOC_FREE(brl);
+       }
+
+       if ( strcmp( fname, "." ) == 0 ) {
+               fullpath = talloc_asprintf(fenum->ctx, "C:%s", sharepath );
+       } else {
+               fullpath = talloc_asprintf(fenum->ctx, "C:%s/%s",
+                               sharepath, fname );
+       }
+       if (!fullpath) {
+               return;
+       }
+       string_replace( fullpath, '/', '\\' );
 
+       /* mask out create (what ever that is) */
+       permissions = e->share_access & (FILE_READ_DATA|FILE_WRITE_DATA);
+
+       /* now fill in the FILE_INFO_3 struct */
+       init_srv_file_info3( &fenum->info[i],
+                            e->share_file_id,
+                            permissions,
+                            num_locks,
+                            username,
+                            fullpath );
+
+       TALLOC_FREE(fullpath);
+       fenum->count++;
 }
 
 /*******************************************************************
 ********************************************************************/
 
-static WERROR net_enum_files( TALLOC_CTX *ctx, FILE_INFO_3 **info, 
+static WERROR net_enum_files( TALLOC_CTX *ctx, const char *username,
+                             FILE_INFO_3 **info, 
                               uint32 *count, uint32 resume )
 {
+       struct file_enum_count f_enum_cnt;
+
        f_enum_cnt.ctx = ctx;
+       f_enum_cnt.username = username;
        f_enum_cnt.count = *count;
        f_enum_cnt.info = *info;
        
-       share_mode_forall( enum_file_fn, NULL );
+       share_mode_forall( enum_file_fn, (void *)&f_enum_cnt );
        
        *info  = f_enum_cnt.info;
        *count = f_enum_cnt.count;
@@ -201,34 +221,31 @@ static WERROR net_enum_files( TALLOC_CTX *ctx, FILE_INFO_3 **info,
 }
 
 /*******************************************************************
- Utility function to get the 'type' of a share from a share definition.
+ Utility function to get the 'type' of a share from an snum.
  ********************************************************************/
-static uint32 get_share_type(const struct share_params *params)
+static uint32 get_share_type(int snum)
 {
-       char *net_name = lp_servicename(params->service);
-       int len_net_name = strlen(net_name);
-       
        /* work out the share type */
        uint32 type = STYPE_DISKTREE;
 
-       if (lp_print_ok(params->service))
+       if (lp_print_ok(snum))
                type = STYPE_PRINTQ;
-       if (strequal(lp_fstype(params->service), "IPC"))
+       if (strequal(lp_fstype(snum), "IPC"))
                type = STYPE_IPC;
-       if (net_name[len_net_name] == '$')
+       if (lp_administrative_share(snum))
                type |= STYPE_HIDDEN;
 
        return type;
 }
-       
+
 /*******************************************************************
  Fill in a share info level 0 structure.
  ********************************************************************/
 
-static void init_srv_share_info_0(pipes_struct *p, SRV_SHARE_INFO_0 *sh0,
-                                 const struct share_params *params)
+static void init_srv_share_info_0(pipes_struct *p, SRV_SHARE_INFO_0 *sh0, int snum)
 {
-       char *net_name = lp_servicename(params->service);
+       const char *net_name = lp_servicename(snum);
+
        init_srv_share_info0(&sh0->info_0, net_name);
        init_srv_share_info0_str(&sh0->info_0_str, net_name);
 }
@@ -237,59 +254,74 @@ static void init_srv_share_info_0(pipes_struct *p, SRV_SHARE_INFO_0 *sh0,
  Fill in a share info level 1 structure.
  ********************************************************************/
 
-static void init_srv_share_info_1(pipes_struct *p, SRV_SHARE_INFO_1 *sh1,
-                                 const struct share_params *params)
+static void init_srv_share_info_1(pipes_struct *p, SRV_SHARE_INFO_1 *sh1, int snum)
 {
-       connection_struct *conn = p->conn;
-       char *net_name = lp_servicename(params->service);
-       char *remark;
+       char *net_name = lp_servicename(snum);
+       char *remark = talloc_strdup(p->mem_ctx, lp_comment(snum));
 
-       remark = talloc_sub_advanced(p->mem_ctx, lp_servicename(SNUM(conn)),
-                                    conn->user, conn->connectpath, conn->gid,
-                                    get_current_username(),
-                                    current_user_info.domain,
-                                    lp_comment(params->service));
+       if (remark) {
+               remark = standard_sub_conn(p->mem_ctx,
+                               p->conn,
+                               remark);
+       }
 
-       init_srv_share_info1(&sh1->info_1, net_name, get_share_type(params),
-                            remark);
-       init_srv_share_info1_str(&sh1->info_1_str, net_name, remark);
+       init_srv_share_info1(&sh1->info_1,
+                       net_name,
+                       get_share_type(snum),
+                       remark ? remark: "");
+       init_srv_share_info1_str(&sh1->info_1_str,
+                       net_name,
+                       remark ? remark: "");
 }
 
 /*******************************************************************
  Fill in a share info level 2 structure.
  ********************************************************************/
 
-static void init_srv_share_info_2(pipes_struct *p, SRV_SHARE_INFO_2 *sh2,
-                                 const struct share_params *params)
+static void init_srv_share_info_2(pipes_struct *p, SRV_SHARE_INFO_2 *sh2, int snum)
 {
-       connection_struct *conn = p->conn;
-       char *remark;
-       char *path;
-       int max_connections = lp_max_connections(params->service);
+       char *remark = NULL;
+       char *path = NULL;
+       int max_connections = lp_max_connections(snum);
        uint32 max_uses = max_connections!=0 ? max_connections : 0xffffffff;
        int count = 0;
-       char *net_name = lp_servicename(params->service);
-       
-       remark = talloc_sub_advanced(p->mem_ctx, lp_servicename(SNUM(conn)),
-                                    conn->user, conn->connectpath, conn->gid,
-                                    get_current_username(),
-                                    current_user_info.domain,
-                                    lp_comment(params->service));
-       path = talloc_asprintf(p->mem_ctx, "C:%s",
-                              lp_pathname(params->service));
+       char *net_name = lp_servicename(snum);
 
-       /*
-        * Change / to \\ so that win2k will see it as a valid path.  This was
-        * added to enable use of browsing in win2k add share dialog.
-        */ 
+       remark = talloc_strdup(p->mem_ctx, lp_comment(snum));
+       if (remark) {
+               remark = standard_sub_conn(p->mem_ctx,
+                               p->conn,
+                               remark);
+       }
+       path = talloc_asprintf(p->mem_ctx,
+                       "C:%s", lp_pathname(snum));
 
-       string_replace(path, '/', '\\');
+       if (path) {
+               /*
+                * Change / to \\ so that win2k will see it as a valid path.
+                * This was added to enable use of browsing in win2k add
+                * share dialog.
+                */
 
-       count = count_current_connections( net_name, False  );
-       init_srv_share_info2(&sh2->info_2, net_name, get_share_type(params), 
-                            remark, 0, max_uses, count, path, "");
+               string_replace(path, '/', '\\');
+       }
 
-       init_srv_share_info2_str(&sh2->info_2_str, net_name, remark, path, "");
+       count = count_current_connections(net_name, false);
+       init_srv_share_info2(&sh2->info_2,
+                               net_name,
+                               get_share_type(snum),
+                               remark ? remark : "",
+                               0,
+                               max_uses,
+                               count,
+                               path ? path : "",
+                               "");
+
+       init_srv_share_info2_str(&sh2->info_2_str,
+                               net_name,
+                               remark ? remark : "",
+                               path ? path : "",
+                               "");
 }
 
 /*******************************************************************
@@ -309,129 +341,120 @@ static void map_generic_share_sd_bits(SEC_DESC *psd)
                return;
 
        for (i = 0; i < ps_dacl->num_aces; i++) {
-               SEC_ACE *psa = &ps_dacl->ace[i];
-               uint32 orig_mask = psa->info.mask;
+               SEC_ACE *psa = &ps_dacl->aces[i];
+               uint32 orig_mask = psa->access_mask;
 
-               se_map_generic(&psa->info.mask, &file_generic_mapping);
-               psa->info.mask |= orig_mask;
-       }       
+               se_map_generic(&psa->access_mask, &file_generic_mapping);
+               psa->access_mask |= orig_mask;
+       }
 }
 
 /*******************************************************************
  Fill in a share info level 501 structure.
 ********************************************************************/
 
-static void init_srv_share_info_501(pipes_struct *p, SRV_SHARE_INFO_501 *sh501,
-                                   const struct share_params *params)
+static void init_srv_share_info_501(pipes_struct *p, SRV_SHARE_INFO_501 *sh501, int snum)
 {
-       connection_struct *conn = p->conn;
-       char *remark;
-       const char *net_name = lp_servicename(params->service);
+       const char *net_name = lp_servicename(snum);
+       char *remark = talloc_strdup(p->mem_ctx, lp_comment(snum));
 
-       remark = talloc_sub_advanced(p->mem_ctx, lp_servicename(SNUM(conn)),
-                                    conn->user, conn->connectpath, conn->gid,
-                                    get_current_username(),
-                                    current_user_info.domain,
-                                    lp_comment(params->service));
+       if (remark) {
+               remark = standard_sub_conn(p->mem_ctx, p->conn, remark);
+       }
 
-       init_srv_share_info501(&sh501->info_501, net_name,
-                              get_share_type(params), remark,
-                              (lp_csc_policy(params->service) << 4));
-       init_srv_share_info501_str(&sh501->info_501_str, net_name, remark);
+       init_srv_share_info501(&sh501->info_501, net_name, get_share_type(snum),
+                       remark ? remark : "", (lp_csc_policy(snum) << 4));
+       init_srv_share_info501_str(&sh501->info_501_str,
+                       net_name, remark ? remark : "");
 }
 
 /*******************************************************************
  Fill in a share info level 502 structure.
  ********************************************************************/
 
-static void init_srv_share_info_502(pipes_struct *p, SRV_SHARE_INFO_502 *sh502,
-                                   const struct share_params *params)
+static void init_srv_share_info_502(pipes_struct *p, SRV_SHARE_INFO_502 *sh502, int snum)
 {
-       connection_struct *conn = p->conn;
-       char *net_name;
-       char *remark;
-       char *path;
-       SEC_DESC *sd;
-       size_t sd_size;
+       const char *net_name = lp_servicename(snum);
+       char *path = NULL;
+       SEC_DESC *sd = NULL;
+       size_t sd_size = 0;
        TALLOC_CTX *ctx = p->mem_ctx;
-
+       char *remark = talloc_strdup(ctx, lp_comment(snum));;
 
        ZERO_STRUCTP(sh502);
 
-       net_name = lp_servicename(params->service);
-       
-       remark = talloc_sub_advanced(p->mem_ctx, lp_servicename(SNUM(conn)),
-                                    conn->user, conn->connectpath, conn->gid,
-                                    get_current_username(),
-                                    current_user_info.domain,
-                                    lp_comment(params->service));
-
-       path = talloc_asprintf(p->mem_ctx, "C:%s",
-                              lp_pathname(params->service));
-
-       /*
-        * Change / to \\ so that win2k will see it as a valid path.  This was
-        * added to enable use of browsing in win2k add share dialog.
-        */ 
-
-       string_replace(path, '/', '\\');
+       if (remark) {
+               remark = standard_sub_conn(ctx, p->conn, remark);
+       }
+       path = talloc_asprintf(ctx, "C:%s", lp_pathname(snum));
+       if (path) {
+               /*
+                * Change / to \\ so that win2k will see it as a valid path.  This was added to
+                * enable use of browsing in win2k add share dialog.
+                */
+               string_replace(path, '/', '\\');
+       }
 
-       sd = get_share_security(ctx, lp_servicename(params->service),
-                               &sd_size);
+       sd = get_share_security(ctx, lp_servicename(snum), &sd_size);
 
-       init_srv_share_info502(&sh502->info_502, net_name,
-                              get_share_type(params), remark, 0, 0xffffffff,
-                              1, path, "", sd, sd_size);
-       init_srv_share_info502_str(&sh502->info_502_str, net_name, remark,
-                                  path, "", sd, sd_size);
+       init_srv_share_info502(&sh502->info_502,
+                       net_name,
+                       get_share_type(snum),
+                       remark ? remark : "",
+                       0,
+                       0xffffffff,
+                       1,
+                       path ? path : "",
+                       "",
+                       sd,
+                       sd_size);
+       init_srv_share_info502_str(&sh502->info_502_str,
+                       net_name,
+                       remark ? remark : "",
+                       path ? path : "",
+                       "",
+                       sd,
+                       sd_size);
 }
 
 /***************************************************************************
  Fill in a share info level 1004 structure.
  ***************************************************************************/
 
-static void init_srv_share_info_1004(pipes_struct *p,
-                                    SRV_SHARE_INFO_1004* sh1004,
-                                    const struct share_params *params)
+static void init_srv_share_info_1004(pipes_struct *p, SRV_SHARE_INFO_1004* sh1004, int snum)
 {
-       connection_struct *conn = p->conn;
-       char *remark;
+       char *remark = talloc_strdup(p->mem_ctx, lp_comment(snum));
 
-       remark = talloc_sub_advanced(p->mem_ctx, lp_servicename(SNUM(conn)),
-                                    conn->user, conn->connectpath, conn->gid,
-                                    get_current_username(),
-                                    current_user_info.domain,
-                                    lp_comment(params->service));
+       if (remark) {
+               remark = standard_sub_conn(p->mem_ctx, p->conn, remark);
+       }
 
        ZERO_STRUCTP(sh1004);
-  
-       init_srv_share_info1004(&sh1004->info_1004, remark);
-       init_srv_share_info1004_str(&sh1004->info_1004_str, remark);
+
+       init_srv_share_info1004(&sh1004->info_1004, remark ? remark : "");
+       init_srv_share_info1004_str(&sh1004->info_1004_str,
+                       remark ? remark : "");
 }
 
 /***************************************************************************
  Fill in a share info level 1005 structure.
  ***************************************************************************/
 
-static void init_srv_share_info_1005(pipes_struct *p,
-                                    SRV_SHARE_INFO_1005* sh1005,
-                                    const struct share_params *params)
+static void init_srv_share_info_1005(pipes_struct *p, SRV_SHARE_INFO_1005* sh1005, int snum)
 {
        sh1005->share_info_flags = 0;
 
-       if(lp_host_msdfs() && lp_msdfs_root(params->service))
-               sh1005->share_info_flags |= 
+       if(lp_host_msdfs() && lp_msdfs_root(snum))
+               sh1005->share_info_flags |=
                        SHARE_1005_IN_DFS | SHARE_1005_DFS_ROOT;
-       sh1005->share_info_flags |= 
-               lp_csc_policy(params->service) << SHARE_1005_CSC_POLICY_SHIFT;
+       sh1005->share_info_flags |=
+               lp_csc_policy(snum) << SHARE_1005_CSC_POLICY_SHIFT;
 }
 /***************************************************************************
  Fill in a share info level 1006 structure.
  ***************************************************************************/
 
-static void init_srv_share_info_1006(pipes_struct *p,
-                                    SRV_SHARE_INFO_1006* sh1006,
-                                    const struct share_params *params)
+static void init_srv_share_info_1006(pipes_struct *p, SRV_SHARE_INFO_1006* sh1006, int snum)
 {
        sh1006->max_uses = -1;
 }
@@ -440,28 +463,21 @@ static void init_srv_share_info_1006(pipes_struct *p,
  Fill in a share info level 1007 structure.
  ***************************************************************************/
 
-static void init_srv_share_info_1007(pipes_struct *p,
-                                    SRV_SHARE_INFO_1007* sh1007,
-                                    const struct share_params *params)
+static void init_srv_share_info_1007(pipes_struct *p, SRV_SHARE_INFO_1007* sh1007, int snum)
 {
-        pstring alternate_directory_name = "";
        uint32 flags = 0;
 
        ZERO_STRUCTP(sh1007);
-  
-       init_srv_share_info1007(&sh1007->info_1007, flags,
-                               alternate_directory_name);
-       init_srv_share_info1007_str(&sh1007->info_1007_str,
-                                   alternate_directory_name);
+
+       init_srv_share_info1007(&sh1007->info_1007, flags, "");
+       init_srv_share_info1007_str(&sh1007->info_1007_str, "");
 }
 
 /*******************************************************************
  Fill in a share info level 1501 structure.
  ********************************************************************/
 
-static void init_srv_share_info_1501(pipes_struct *p,
-                                    SRV_SHARE_INFO_1501 *sh1501,
-                                    const struct share_params *params)
+static void init_srv_share_info_1501(pipes_struct *p, SRV_SHARE_INFO_1501 *sh1501, int snum)
 {
        SEC_DESC *sd;
        size_t sd_size;
@@ -469,8 +485,7 @@ static void init_srv_share_info_1501(pipes_struct *p,
 
        ZERO_STRUCTP(sh1501);
 
-       sd = get_share_security(ctx, lp_servicename(params->service),
-                               &sd_size);
+       sd = get_share_security(ctx, lp_servicename(snum), &sd_size);
 
        sh1501->sdb = make_sec_desc_buf(p->mem_ctx, sd_size, sd);
 }
@@ -479,193 +494,250 @@ static void init_srv_share_info_1501(pipes_struct *p,
  True if it ends in '$'.
  ********************************************************************/
 
-static BOOL is_hidden_share(const struct share_params *params)
+static bool is_hidden_share(int snum)
 {
-       const char *net_name = lp_servicename(params->service);
+       const char *net_name = lp_servicename(snum);
 
-       return (net_name[strlen(net_name) - 1] == '$');
+       return (net_name[strlen(net_name) - 1] == '$') ? True : False;
 }
 
 /*******************************************************************
  Fill in a share info structure.
  ********************************************************************/
 
-static WERROR init_srv_share_info_ctr(pipes_struct *p,
-                                     SRV_SHARE_INFO_CTR *ctr,
-                                     uint32 info_level, uint32 *resume_hnd,
-                                     uint32 *total_entries, BOOL all_shares)
+static bool init_srv_share_info_ctr(pipes_struct *p, SRV_SHARE_INFO_CTR *ctr,
+              uint32 info_level, uint32 *resume_hnd, uint32 *total_entries, bool all_shares)
 {
        int num_entries = 0;
+       int num_services = 0;
+       int snum;
        TALLOC_CTX *ctx = p->mem_ctx;
-       struct share_iterator *shares;
-       struct share_params *share;
 
        DEBUG(5,("init_srv_share_info_ctr\n"));
 
-       ZERO_STRUCT(ctr->share);
+       ZERO_STRUCTPN(ctr);
 
        ctr->info_level = ctr->switch_value = info_level;
        *resume_hnd = 0;
 
        /* Ensure all the usershares are loaded. */
        become_root();
-       load_usershare_shares();
+       num_services = load_usershare_shares();
+       load_registry_shares();
        unbecome_root();
 
-       num_entries = 0;
+       /* Count the number of entries. */
+       for (snum = 0; snum < num_services; snum++) {
+               if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) )
+                       num_entries++;
+       }
+
+       *total_entries = num_entries;
+       ctr->num_entries2 = ctr->num_entries = num_entries;
+       ctr->ptr_share_info = ctr->ptr_entries = 1;
 
-       ZERO_STRUCT(ctr->share);
+       if (!num_entries)
+               return True;
 
-       if (!(shares = share_list_all(ctx))) {
-               DEBUG(5, ("Could not list shares\n"));
-               return WERR_ACCESS_DENIED;
-       }
+       switch (info_level) {
+       case 0:
+       {
+               SRV_SHARE_INFO_0 *info0 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_0, num_entries);
+               int i = 0;
 
-       while ((share = next_share(shares)) != NULL) {
-               if (!lp_browseable(share->service)) {
-                       continue;
-               }
-               if (!all_shares && is_hidden_share(share)) {
-                       continue;
+               if (!info0) {
+                       return False;
                }
 
-               switch (info_level) {
-               case 0:
-               {
-                       SRV_SHARE_INFO_0 i;
-                       init_srv_share_info_0(p, &i, share);
-                       ADD_TO_ARRAY(ctx, SRV_SHARE_INFO_0, i,
-                                    &ctr->share.info0, &num_entries);
-                       if (ctr->share.info0 == NULL) {
-                               return WERR_NOMEM;
+               for (snum = *resume_hnd; snum < num_services; snum++) {
+                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
+                               init_srv_share_info_0(p, &info0[i++], snum);
                        }
-                       break;
                }
 
-               case 1:
-               {
-                       SRV_SHARE_INFO_1 i;
-                       init_srv_share_info_1(p, &i, share);
-                       ADD_TO_ARRAY(ctx, SRV_SHARE_INFO_1, i,
-                                    &ctr->share.info1, &num_entries);
-                       if (ctr->share.info1 == NULL) {
-                               return WERR_NOMEM;
-                       }
-                       break;
+               ctr->share.info0 = info0;
+               break;
+
+       }
+
+       case 1:
+       {
+               SRV_SHARE_INFO_1 *info1 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1, num_entries);
+               int i = 0;
+
+               if (!info1) {
+                       return False;
                }
 
-               case 2:
-               {
-                       SRV_SHARE_INFO_2 i;
-                       init_srv_share_info_2(p, &i, share);
-                       ADD_TO_ARRAY(ctx, SRV_SHARE_INFO_2, i,
-                                    &ctr->share.info2, &num_entries);
-                       if (ctr->share.info2 == NULL) {
-                               return WERR_NOMEM;
+               for (snum = *resume_hnd; snum < num_services; snum++) {
+                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
+                               init_srv_share_info_1(p, &info1[i++], snum);
                        }
-                       break;
                }
 
-               case 501:
-               {
-                       SRV_SHARE_INFO_501 i;
-                       init_srv_share_info_501(p, &i, share);
-                       ADD_TO_ARRAY(ctx, SRV_SHARE_INFO_501, i,
-                                    &ctr->share.info501, &num_entries);
-                       if (ctr->share.info501 == NULL) {
-                               return WERR_NOMEM;
-                       }
-                       break;
+               ctr->share.info1 = info1;
+               break;
+       }
+
+       case 2:
+       {
+               SRV_SHARE_INFO_2 *info2 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_2, num_entries);
+               int i = 0;
+
+               if (!info2) {
+                       return False;
                }
 
-               case 502:
-               {
-                       SRV_SHARE_INFO_502 i;
-                       init_srv_share_info_502(p, &i, share);
-                       ADD_TO_ARRAY(ctx, SRV_SHARE_INFO_502, i,
-                                    &ctr->share.info502, &num_entries);
-                       if (ctr->share.info502 == NULL) {
-                               return WERR_NOMEM;
+               for (snum = *resume_hnd; snum < num_services; snum++) {
+                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
+                               init_srv_share_info_2(p, &info2[i++], snum);
                        }
-                       break;
                }
 
-               /* here for completeness but not currently used with enum
-                * (1004 - 1501)*/
+               ctr->share.info2 = info2;
+               break;
+       }
+
+       case 501:
+       {
+               SRV_SHARE_INFO_501 *info501 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_501, num_entries);
+               int i = 0;
        
-               case 1004:
-               {
-                       SRV_SHARE_INFO_1004 i;
-                       init_srv_share_info_1004(p, &i, share);
-                       ADD_TO_ARRAY(ctx, SRV_SHARE_INFO_1004, i,
-                                    &ctr->share.info1004, &num_entries);
-                       if (ctr->share.info1004 == NULL) {
-                               return WERR_NOMEM;
+               if (!info501) {
+                       return False;
+               }
+
+               for (snum = *resume_hnd; snum < num_services; snum++) {
+                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
+                               init_srv_share_info_501(p, &info501[i++], snum);
                        }
-                       break;
                }
+       
+               ctr->share.info501 = info501;
+               break;
+       }
 
-               case 1005:
-               {
-                       SRV_SHARE_INFO_1005 i;
-                       init_srv_share_info_1005(p, &i, share);
-                       ADD_TO_ARRAY(ctx, SRV_SHARE_INFO_1005, i,
-                                    &ctr->share.info1005, &num_entries);
-                       if (ctr->share.info1005 == NULL) {
-                               return WERR_NOMEM;
+       case 502:
+       {
+               SRV_SHARE_INFO_502 *info502 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_502, num_entries);
+               int i = 0;
+
+               if (!info502) {
+                       return False;
+               }
+
+               for (snum = *resume_hnd; snum < num_services; snum++) {
+                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
+                               init_srv_share_info_502(p, &info502[i++], snum);
                        }
-                       break;
                }
 
-               case 1006:
-               {
-                       SRV_SHARE_INFO_1006 i;
-                       init_srv_share_info_1006(p, &i, share);
-                       ADD_TO_ARRAY(ctx, SRV_SHARE_INFO_1006, i,
-                                    &ctr->share.info1006, &num_entries);
-                       if (ctr->share.info1006 == NULL) {
-                               return WERR_NOMEM;
+               ctr->share.info502 = info502;
+               break;
+       }
+
+       /* here for completeness but not currently used with enum (1004 - 1501)*/
+       
+       case 1004:
+       {
+               SRV_SHARE_INFO_1004 *info1004 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1004, num_entries);
+               int i = 0;
+
+               if (!info1004) {
+                       return False;
+               }
+
+               for (snum = *resume_hnd; snum < num_services; snum++) {
+                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
+                               init_srv_share_info_1004(p, &info1004[i++], snum);
                        }
-                       break;
                }
 
-               case 1007:
-               {
-                       SRV_SHARE_INFO_1007 i;
-                       init_srv_share_info_1007(p, &i, share);
-                       ADD_TO_ARRAY(ctx, SRV_SHARE_INFO_1007, i,
-                                    &ctr->share.info1007, &num_entries);
-                       if (ctr->share.info1007 == NULL) {
-                               return WERR_NOMEM;
+               ctr->share.info1004 = info1004;
+               break;
+       }
+
+       case 1005:
+       {
+               SRV_SHARE_INFO_1005 *info1005 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1005, num_entries);
+               int i = 0;
+
+               if (!info1005) {
+                       return False;
+               }
+
+               for (snum = *resume_hnd; snum < num_services; snum++) {
+                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
+                               init_srv_share_info_1005(p, &info1005[i++], snum);
                        }
-                       break;
                }
 
-               case 1501:
-               {
-                       SRV_SHARE_INFO_1501 i;
-                       init_srv_share_info_1501(p, &i, share);
-                       ADD_TO_ARRAY(ctx, SRV_SHARE_INFO_1501, i,
-                                    &ctr->share.info1501, &num_entries);
-                       if (ctr->share.info1501 == NULL) {
-                               return WERR_NOMEM;
+               ctr->share.info1005 = info1005;
+               break;
+       }
+
+       case 1006:
+       {
+               SRV_SHARE_INFO_1006 *info1006 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1006, num_entries);
+               int i = 0;
+
+               if (!info1006) {
+                       return False;
+               }
+
+               for (snum = *resume_hnd; snum < num_services; snum++) {
+                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
+                               init_srv_share_info_1006(p, &info1006[i++], snum);
                        }
-                       break;
                }
-               default:
-                       DEBUG(5,("init_srv_share_info_ctr: unsupported switch "
-                                "value %d\n", info_level));
-                       return WERR_UNKNOWN_LEVEL;
+
+               ctr->share.info1006 = info1006;
+               break;
+       }
+
+       case 1007:
+       {
+               SRV_SHARE_INFO_1007 *info1007 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1007, num_entries);
+               int i = 0;
+
+               if (!info1007) {
+                       return False;
+               }
+
+               for (snum = *resume_hnd; snum < num_services; snum++) {
+                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
+                               init_srv_share_info_1007(p, &info1007[i++], snum);
+                       }
                }
 
-               TALLOC_FREE(share);
+               ctr->share.info1007 = info1007;
+               break;
        }
 
-       *total_entries = num_entries;
-       ctr->num_entries2 = ctr->num_entries = num_entries;
-       ctr->ptr_share_info = ctr->ptr_entries = 1;
+       case 1501:
+       {
+               SRV_SHARE_INFO_1501 *info1501 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1501, num_entries);
+               int i = 0;
 
-       return WERR_OK;
+               if (!info1501) {
+                       return False;
+               }
+
+               for (snum = *resume_hnd; snum < num_services; snum++) {
+                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
+                               init_srv_share_info_1501(p, &info1501[i++], snum);
+                       }
+               }
+
+               ctr->share.info1501 = info1501;
+               break;
+       }
+       default:
+               DEBUG(5,("init_srv_share_info_ctr: unsupported switch value %d\n", info_level));
+               return False;
+       }
+
+       return True;
 }
 
 /*******************************************************************
@@ -673,13 +745,16 @@ static WERROR init_srv_share_info_ctr(pipes_struct *p,
 ********************************************************************/
 
 static void init_srv_r_net_share_enum(pipes_struct *p, SRV_R_NET_SHARE_ENUM *r_n,
-                                     uint32 info_level, uint32 resume_hnd, BOOL all)  
+                                     uint32 info_level, uint32 resume_hnd, bool all)  
 {
        DEBUG(5,("init_srv_r_net_share_enum: %d\n", __LINE__));
 
-       r_n->status = init_srv_share_info_ctr(p, &r_n->ctr, info_level,
-                                             &resume_hnd,
-                                             &r_n->total_entries, all);
+       if (init_srv_share_info_ctr(p, &r_n->ctr, info_level,
+                                   &resume_hnd, &r_n->total_entries, all)) {
+               r_n->status = WERR_OK;
+       } else {
+               r_n->status = WERR_UNKNOWN_LEVEL;
+       }
 
        init_enum_hnd(&r_n->enum_hnd, resume_hnd);
 }
@@ -692,63 +767,52 @@ static void init_srv_r_net_share_get_info(pipes_struct *p, SRV_R_NET_SHARE_GET_I
                                  char *share_name, uint32 info_level)
 {
        WERROR status = WERR_OK;
-       const struct share_params *params;
+       int snum;
 
        DEBUG(5,("init_srv_r_net_share_get_info: %d\n", __LINE__));
 
        r_n->info.switch_value = info_level;
 
-       params = get_share_params(p->mem_ctx, share_name);
+       snum = find_service(share_name);
 
-       if (params != NULL) {
+       if (snum >= 0) {
                switch (info_level) {
                case 0:
-                       init_srv_share_info_0(p, &r_n->info.share.info0,
-                                             params);
+                       init_srv_share_info_0(p, &r_n->info.share.info0, snum);
                        break;
                case 1:
-                       init_srv_share_info_1(p, &r_n->info.share.info1,
-                                             params);
+                       init_srv_share_info_1(p, &r_n->info.share.info1, snum);
                        break;
                case 2:
-                       init_srv_share_info_2(p, &r_n->info.share.info2,
-                                             params);
+                       init_srv_share_info_2(p, &r_n->info.share.info2, snum);
                        break;
                case 501:
-                       init_srv_share_info_501(p, &r_n->info.share.info501,
-                                               params);
+                       init_srv_share_info_501(p, &r_n->info.share.info501, snum);
                        break;
                case 502:
-                       init_srv_share_info_502(p, &r_n->info.share.info502,
-                                               params);
+                       init_srv_share_info_502(p, &r_n->info.share.info502, snum);
                        break;
 
                        /* here for completeness */
                case 1004:
-                       init_srv_share_info_1004(p, &r_n->info.share.info1004,
-                                                params);
+                       init_srv_share_info_1004(p, &r_n->info.share.info1004, snum);
                        break;
                case 1005:
-                       init_srv_share_info_1005(p, &r_n->info.share.info1005,
-                                                params);
+                       init_srv_share_info_1005(p, &r_n->info.share.info1005, snum);
                        break;
 
                        /* here for completeness 1006 - 1501 */
                case 1006:
-                       init_srv_share_info_1006(p, &r_n->info.share.info1006,
-                                                params);
+                       init_srv_share_info_1006(p, &r_n->info.share.info1006, snum);
                        break;
                case 1007:
-                       init_srv_share_info_1007(p, &r_n->info.share.info1007,
-                                                params);
+                       init_srv_share_info_1007(p, &r_n->info.share.info1007, snum);
                        break;
                case 1501:
-                       init_srv_share_info_1501(p, &r_n->info.share.info1501,
-                                                params);
+                       init_srv_share_info_1501(p, &r_n->info.share.info1501, snum);
                        break;
                default:
-                       DEBUG(5,("init_srv_net_share_get_info: unsupported "
-                                "switch value %d\n", info_level));
+                       DEBUG(5,("init_srv_net_share_get_info: unsupported switch value %d\n", info_level));
                        status = WERR_UNKNOWN_LEVEL;
                        break;
                }
@@ -764,17 +828,16 @@ static void init_srv_r_net_share_get_info(pipes_struct *p, SRV_R_NET_SHARE_GET_I
  fill in a sess info level 0 structure.
  ********************************************************************/
 
-static void init_srv_sess_info_0(SRV_SESS_INFO_0 *ss0, uint32 *snum, uint32 *stot)
+static void init_srv_sess_info_0(pipes_struct *p, SRV_SESS_INFO_0 *ss0, uint32 *snum, uint32 *stot)
 {
        struct sessionid *session_list;
        uint32 num_entries = 0;
-       (*stot) = list_sessions(&session_list);
+       (*stot) = list_sessions(p->mem_ctx, &session_list);
 
        if (ss0 == NULL) {
                if (snum) {
                        (*snum) = 0;
                }
-               SAFE_FREE(session_list);
                return;
        }
 
@@ -799,7 +862,6 @@ static void init_srv_sess_info_0(SRV_SESS_INFO_0 *ss0, uint32 *snum, uint32 *sto
                ss0->ptr_sess_info = 0;
                ss0->num_entries_read2 = 0;
        }
-       SAFE_FREE(session_list);
 }
 
 /*******************************************************************
@@ -807,11 +869,11 @@ static void init_srv_sess_info_0(SRV_SESS_INFO_0 *ss0, uint32 *snum, uint32 *sto
 
 static void sess_file_fn( const struct share_mode_entry *e, 
                           const char *sharepath, const char *fname,
-                         void *private_data )
+                         void *data )
 {
-       struct sess_file_count *sess = (struct sess_file_count *)private_data;
+       struct sess_file_count *sess = (struct sess_file_count *)data;
  
-       if ( (procid_to_pid(&e->pid) == sess->pid) && (sess->uid == e->uid) ) {
+       if ( procid_equal(&e->pid, &sess->pid) && (sess->uid == e->uid) ) {
                sess->count++;
        }
        
@@ -821,7 +883,7 @@ static void sess_file_fn( const struct share_mode_entry *e,
 /*******************************************************************
 ********************************************************************/
 
-static int net_count_files( uid_t uid, pid_t pid )
+static int net_count_files( uid_t uid, struct server_id pid )
 {
        struct sess_file_count s_file_cnt;
 
@@ -829,7 +891,7 @@ static int net_count_files( uid_t uid, pid_t pid )
        s_file_cnt.uid = uid;
        s_file_cnt.pid = pid;
        
-       share_mode_forall( sess_file_fn, (void *)&s_file_cnt );
+       share_mode_forall( sess_file_fn, &s_file_cnt );
        
        return s_file_cnt.count;
 }
@@ -838,7 +900,7 @@ static int net_count_files( uid_t uid, pid_t pid )
  fill in a sess info level 1 structure.
  ********************************************************************/
 
-static void init_srv_sess_info_1(SRV_SESS_INFO_1 *ss1, uint32 *snum, uint32 *stot)
+static void init_srv_sess_info_1(pipes_struct *p, SRV_SESS_INFO_1 *ss1, uint32 *snum, uint32 *stot)
 {
        struct sessionid *session_list;
        uint32 num_entries = 0;
@@ -859,14 +921,14 @@ static void init_srv_sess_info_1(SRV_SESS_INFO_1 *ss1, uint32 *snum, uint32 *sto
                return;
        }
 
-       (*stot) = list_sessions(&session_list);
+       (*stot) = list_sessions(p->mem_ctx, &session_list);
        
 
        for (; (*snum) < (*stot) && num_entries < MAX_SESS_ENTRIES; (*snum)++) {
                uint32 num_files;
                uint32 connect_time;
                struct passwd *pw = sys_getpwnam(session_list[*snum].username);
-               BOOL guest;
+               bool guest;
                        
                if ( !pw ) {
                        DEBUG(10,("init_srv_sess_info_1: failed to find owner: %s\n",
@@ -896,14 +958,13 @@ static void init_srv_sess_info_1(SRV_SESS_INFO_1 *ss1, uint32 *snum, uint32 *sto
                (*snum) = 0;
        }
 
-       SAFE_FREE(session_list);
 }
 
 /*******************************************************************
  makes a SRV_R_NET_SESS_ENUM structure.
 ********************************************************************/
 
-static WERROR init_srv_sess_info_ctr(SRV_SESS_INFO_CTR *ctr,
+static WERROR init_srv_sess_info_ctr(pipes_struct *p, SRV_SESS_INFO_CTR *ctr,
                                int switch_value, uint32 *resume_hnd, uint32 *total_entries)
 {
        WERROR status = WERR_OK;
@@ -913,11 +974,11 @@ static WERROR init_srv_sess_info_ctr(SRV_SESS_INFO_CTR *ctr,
 
        switch (switch_value) {
        case 0:
-               init_srv_sess_info_0(&(ctr->sess.info0), resume_hnd, total_entries);
+               init_srv_sess_info_0(p, &(ctr->sess.info0), resume_hnd, total_entries);
                ctr->ptr_sess_ctr = 1;
                break;
        case 1:
-               init_srv_sess_info_1(&(ctr->sess.info1), resume_hnd, total_entries);
+               init_srv_sess_info_1(p, &(ctr->sess.info1), resume_hnd, total_entries);
                ctr->ptr_sess_ctr = 1;
                break;
        default:
@@ -936,7 +997,7 @@ static WERROR init_srv_sess_info_ctr(SRV_SESS_INFO_CTR *ctr,
  makes a SRV_R_NET_SESS_ENUM structure.
 ********************************************************************/
 
-static void init_srv_r_net_sess_enum(SRV_R_NET_SESS_ENUM *r_n,
+static void init_srv_r_net_sess_enum(pipes_struct *p, SRV_R_NET_SESS_ENUM *r_n,
                                uint32 resume_hnd, int sess_level, int switch_value)  
 {
        DEBUG(5,("init_srv_r_net_sess_enum: %d\n", __LINE__));
@@ -946,7 +1007,7 @@ static void init_srv_r_net_sess_enum(SRV_R_NET_SESS_ENUM *r_n,
        if (sess_level == -1)
                r_n->status = WERR_UNKNOWN_LEVEL;
        else
-               r_n->status = init_srv_sess_info_ctr(r_n->ctr, switch_value, &resume_hnd, &r_n->total_entries);
+               r_n->status = init_srv_sess_info_ctr(p, r_n->ctr, switch_value, &resume_hnd, &r_n->total_entries);
 
        if (!W_ERROR_IS_OK(r_n->status))
                resume_hnd = 0;
@@ -1113,20 +1174,23 @@ static void init_srv_r_net_conn_enum(SRV_R_NET_CONN_ENUM *r_n,
  makes a SRV_R_NET_FILE_ENUM structure.
 ********************************************************************/
 
-static WERROR net_file_enum_3( SRV_R_NET_FILE_ENUM *r, uint32 resume_hnd )
+static WERROR net_file_enum_3( const char *username, SRV_R_NET_FILE_ENUM *r,
+                              uint32 resume_hnd )
 {
-       TALLOC_CTX *ctx = get_talloc_ctx();
+       TALLOC_CTX *ctx = talloc_tos();
        SRV_FILE_INFO_CTR *ctr = &r->ctr;
 
        /* TODO -- Windows enumerates 
           (b) active pipes
           (c) open directories and files */
 
-       r->status = net_enum_files( ctx, &ctr->file.info3, &ctr->num_entries, resume_hnd );
+       r->status = net_enum_files( ctx, username, &ctr->file.info3,
+                                   &ctr->num_entries, resume_hnd );
        if ( !W_ERROR_IS_OK(r->status))
                goto done;
                
-       r->status = net_enum_pipes( ctx, &ctr->file.info3, &ctr->num_entries, resume_hnd );
+       r->status = net_enum_pipes( ctx, username, &ctr->file.info3,
+                                   &ctr->num_entries, resume_hnd );
        if ( !W_ERROR_IS_OK(r->status))
                goto done;
        
@@ -1152,9 +1216,20 @@ done:
 
 WERROR _srv_net_file_enum(pipes_struct *p, SRV_Q_NET_FILE_ENUM *q_u, SRV_R_NET_FILE_ENUM *r_u)
 {
+       const char *username = NULL;
+
        switch ( q_u->level ) {
        case 3:
-               return net_file_enum_3( r_u, get_enum_hnd(&q_u->enum_hnd) );    
+               if (q_u->username) {
+                       username = rpcstr_pull_unistr2_talloc(
+                               p->mem_ctx, q_u->username);
+                       if (!username) {
+                               return WERR_NOMEM;
+                       }
+               }
+
+               return net_file_enum_3(username, r_u,
+                                      get_enum_hnd(&q_u->enum_hnd));
        default:
                return WERR_UNKNOWN_LEVEL;
        }
@@ -1285,7 +1360,7 @@ WERROR _srv_net_sess_enum(pipes_struct *p, SRV_Q_NET_SESS_ENUM *q_u, SRV_R_NET_S
        ZERO_STRUCTP(r_u->ctr);
 
        /* set up the */
-       init_srv_r_net_sess_enum(r_u,
+       init_srv_r_net_sess_enum(p, r_u,
                                get_enum_hnd(&q_u->enum_hnd),
                                q_u->sess_level,
                                q_u->ctr->switch_value);
@@ -1302,9 +1377,11 @@ net sess del
 WERROR _srv_net_sess_del(pipes_struct *p, SRV_Q_NET_SESS_DEL *q_u, SRV_R_NET_SESS_DEL *r_u)
 {
        struct sessionid *session_list;
+       struct current_user user;
        int num_sessions, snum;
        fstring username;
        fstring machine;
+       bool not_root = False;
 
        rpcstr_pull_unistr2_fstring(username, &q_u->uni_user_name);
        rpcstr_pull_unistr2_fstring(machine, &q_u->uni_cli_name);
@@ -1314,15 +1391,17 @@ WERROR _srv_net_sess_del(pipes_struct *p, SRV_Q_NET_SESS_DEL *q_u, SRV_R_NET_SES
                memmove(machine, &machine[1], strlen(machine));
        }
 
-       num_sessions = list_sessions(&session_list);
+       num_sessions = list_sessions(p->mem_ctx, &session_list);
 
        DEBUG(5,("_srv_net_sess_del: %d\n", __LINE__));
 
        r_u->status = WERR_ACCESS_DENIED;
 
+       get_current_user(&user, p);
+
        /* fail out now if you are not root or not a domain admin */
 
-       if ((p->pipe_user.ut.uid != sec_initial_uid()) && 
+       if ((user.ut.uid != sec_initial_uid()) && 
                ( ! nt_token_check_domain_rid(p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS))) {
 
                goto done;
@@ -1332,9 +1411,23 @@ WERROR _srv_net_sess_del(pipes_struct *p, SRV_Q_NET_SESS_DEL *q_u, SRV_R_NET_SES
 
                if ((strequal(session_list[snum].username, username) || username[0] == '\0' ) &&
                    strequal(session_list[snum].remote_machine, machine)) {
+
+                       NTSTATUS ntstat;
                
-                       if (message_send_pid(pid_to_procid(session_list[snum].pid), MSG_SHUTDOWN, NULL, 0, False))
+                       if (user.ut.uid != sec_initial_uid()) {
+                               not_root = True;
+                               become_root();
+                       }
+
+                       ntstat = messaging_send(smbd_messaging_context(),
+                                               session_list[snum].pid,
+                                               MSG_SHUTDOWN, &data_blob_null);
+                       
+                       if (NT_STATUS_IS_OK(ntstat))
                                r_u->status = WERR_OK;
+
+                       if (not_root) 
+                               unbecome_root();
                }
        }
 
@@ -1342,7 +1435,6 @@ WERROR _srv_net_sess_del(pipes_struct *p, SRV_Q_NET_SESS_DEL *q_u, SRV_R_NET_SES
 
 
 done:
-       SAFE_FREE(session_list);
 
        return r_u->status;
 }
@@ -1416,17 +1508,27 @@ WERROR _srv_net_share_get_info(pipes_struct *p, SRV_Q_NET_SHARE_GET_INFO *q_u, S
  Check a given DOS pathname is valid for a share.
 ********************************************************************/
 
-char *valid_share_pathname(char *dos_pathname)
+char *valid_share_pathname(TALLOC_CTX *ctx, const char *dos_pathname)
 {
-       char *ptr;
+       char *ptr = NULL;
 
+       if (!dos_pathname) {
+               return NULL;
+       }
+
+       ptr = talloc_strdup(ctx, dos_pathname);
+       if (!ptr) {
+               return NULL;
+       }
        /* Convert any '\' paths to '/' */
-       unix_format(dos_pathname);
-       unix_clean_name(dos_pathname);
+       unix_format(ptr);
+       ptr = unix_clean_name(ctx, ptr);
+       if (!ptr) {
+               return NULL;
+       }
 
        /* NT is braindead - it wants a C: prefix to a pathname ! So strip it. */
-       ptr = dos_pathname;
-       if (strlen(dos_pathname) > 2 && ptr[1] == ':' && ptr[0] != '/')
+       if (strlen(ptr) > 2 && ptr[1] == ':' && ptr[0] != '/')
                ptr += 2;
 
        /* Only absolute paths allowed. */
@@ -1442,26 +1544,31 @@ char *valid_share_pathname(char *dos_pathname)
 
 WERROR _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u, SRV_R_NET_SHARE_SET_INFO *r_u)
 {
-       pstring command;
-       fstring share_name;
-       fstring comment;
-       pstring pathname;
+       struct current_user user;
+       char *command = NULL;
+       char *share_name = NULL;
+       char *comment = NULL;
+       char *pathname = NULL;
        int type;
        int snum;
        int ret;
-       char *path;
+       char *path = NULL;
        SEC_DESC *psd = NULL;
        SE_PRIV se_diskop = SE_DISK_OPERATOR;
-       BOOL is_disk_op = False;
+       bool is_disk_op = False;
        int max_connections = 0;
+       TALLOC_CTX *ctx = p->mem_ctx;
 
        DEBUG(5,("_srv_net_share_set_info: %d\n", __LINE__));
 
-       unistr2_to_ascii(share_name, &q_u->uni_share_name, sizeof(share_name));
+       share_name = unistr2_to_ascii_talloc(ctx, &q_u->uni_share_name);
+       if (!share_name) {
+               return WERR_NET_NAME_NOT_FOUND;
+       }
 
        r_u->parm_error = 0;
 
-       if ( strequal(share_name,"IPC$") 
+       if ( strequal(share_name,"IPC$")
                || ( lp_enable_asu_support() && strequal(share_name,"ADMIN$") )
                || strequal(share_name,"global") )
        {
@@ -1478,23 +1585,28 @@ WERROR _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u, S
        if (lp_print_ok(snum))
                return WERR_ACCESS_DENIED;
 
+       get_current_user(&user,p);
+
        is_disk_op = user_has_privileges( p->pipe_user.nt_user_token, &se_diskop );
-       
+
        /* fail out now if you are not root and not a disk op */
-       
-       if ( p->pipe_user.ut.uid != sec_initial_uid() && !is_disk_op )
+
+       if ( user.ut.uid != sec_initial_uid() && !is_disk_op )
                return WERR_ACCESS_DENIED;
 
        switch (q_u->info_level) {
        case 1:
-               pstrcpy(pathname, lp_pathname(snum));
-               unistr2_to_ascii(comment, &q_u->info.share.info2.info_2_str.uni_remark, sizeof(comment));
+               pathname = talloc_strdup(ctx, lp_pathname(snum));
+               comment = unistr2_to_ascii_talloc(ctx,
+                               &q_u->info.share.info2.info_2_str.uni_remark);
                type = q_u->info.share.info2.info_2.type;
                psd = NULL;
                break;
        case 2:
-               unistr2_to_ascii(comment, &q_u->info.share.info2.info_2_str.uni_remark, sizeof(comment));
-               unistr2_to_ascii(pathname, &q_u->info.share.info2.info_2_str.uni_path, sizeof(pathname));
+               comment = unistr2_to_ascii_talloc(ctx,
+                               &q_u->info.share.info2.info_2_str.uni_remark);
+               pathname = unistr2_to_ascii_talloc(ctx,
+                               &q_u->info.share.info2.info_2_str.uni_path);
                type = q_u->info.share.info2.info_2.type;
                max_connections = (q_u->info.share.info2.info_2.max_uses == 0xffffffff) ? 0 : q_u->info.share.info2.info_2.max_uses;
                psd = NULL;
@@ -1508,15 +1620,18 @@ WERROR _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u, S
                break;
 #endif
        case 502:
-               unistr2_to_ascii(comment, &q_u->info.share.info502.info_502_str.uni_remark, sizeof(comment));
-               unistr2_to_ascii(pathname, &q_u->info.share.info502.info_502_str.uni_path, sizeof(pathname));
+               comment = unistr2_to_ascii_talloc(ctx,
+                               &q_u->info.share.info502.info_502_str.uni_remark);
+               pathname = unistr2_to_ascii_talloc(ctx,
+                               &q_u->info.share.info502.info_502_str.uni_path);
                type = q_u->info.share.info502.info_502.type;
                psd = q_u->info.share.info502.info_502_str.sd;
                map_generic_share_sd_bits(psd);
                break;
        case 1004:
-               pstrcpy(pathname, lp_pathname(snum));
-               unistr2_to_ascii(comment, &q_u->info.share.info1004.info_1004_str.uni_remark, sizeof(comment));
+               pathname = talloc_strdup(ctx, lp_pathname(snum));
+               comment = unistr2_to_ascii_talloc(ctx,
+                               &q_u->info.share.info1004.info_1004_str.uni_remark);
                type = STYPE_DISKTREE;
                break;
        case 1005:
@@ -1536,9 +1651,9 @@ WERROR _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u, S
        case 1007:
                return WERR_ACCESS_DENIED;
        case 1501:
-               pstrcpy(pathname, lp_pathname(snum));
-               fstrcpy(comment, lp_comment(snum));
-               psd = q_u->info.share.info1501.sdb->sec;
+               pathname = talloc_strdup(ctx, lp_pathname(snum));
+               comment = talloc_strdup(ctx, lp_comment(snum));
+               psd = q_u->info.share.info1501.sdb->sd;
                map_generic_share_sd_bits(psd);
                type = STYPE_DISKTREE;
                break;
@@ -1550,51 +1665,65 @@ WERROR _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u, S
        /* We can only modify disk shares. */
        if (type != STYPE_DISKTREE)
                return WERR_ACCESS_DENIED;
-               
+
        /* Check if the pathname is valid. */
-       if (!(path = valid_share_pathname( pathname )))
+       if (!(path = valid_share_pathname(p->mem_ctx, pathname )))
                return WERR_OBJECT_PATH_INVALID;
 
        /* Ensure share name, pathname and comment don't contain '"' characters. */
        string_replace(share_name, '"', ' ');
        string_replace(path, '"', ' ');
-       string_replace(comment, '"', ' ');
+       if (comment) {
+               string_replace(comment, '"', ' ');
+       }
 
        DEBUG(10,("_srv_net_share_set_info: change share command = %s\n",
                lp_change_share_cmd() ? lp_change_share_cmd() : "NULL" ));
 
        /* Only call modify function if something changed. */
-       
-       if (strcmp(path, lp_pathname(snum)) || strcmp(comment, lp_comment(snum)) 
-               || (lp_max_connections(snum) != max_connections) ) 
-       {
+
+       if (strcmp(path, lp_pathname(snum)) || strcmp(comment, lp_comment(snum))
+                       || (lp_max_connections(snum) != max_connections)) {
                if (!lp_change_share_cmd() || !*lp_change_share_cmd()) {
                        DEBUG(10,("_srv_net_share_set_info: No change share command\n"));
                        return WERR_ACCESS_DENIED;
                }
 
-               slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\" %d",
-                               lp_change_share_cmd(), dyn_CONFIGFILE, share_name, path, comment, max_connections ); 
+               command = talloc_asprintf(p->mem_ctx,
+                               "%s \"%s\" \"%s\" \"%s\" \"%s\" %d",
+                               lp_change_share_cmd(),
+                               get_dyn_CONFIGFILE(),
+                               share_name,
+                               path,
+                               comment ? comment : "",
+                               max_connections);
+               if (!command) {
+                       return WERR_NOMEM;
+               }
 
                DEBUG(10,("_srv_net_share_set_info: Running [%s]\n", command ));
-                               
+
                /********* BEGIN SeDiskOperatorPrivilege BLOCK *********/
-       
-               if ( is_disk_op )
+
+               if (is_disk_op)
                        become_root();
-                       
+
                if ( (ret = smbrun(command, NULL)) == 0 ) {
                        /* Tell everyone we updated smb.conf. */
-                       message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL);
+                       message_send_all(smbd_messaging_context(),
+                                        MSG_SMB_CONF_UPDATED, NULL, 0,
+                                        NULL);
                }
-               
+
                if ( is_disk_op )
                        unbecome_root();
-                       
+
                /********* END SeDiskOperatorPrivilege BLOCK *********/
 
                DEBUG(3,("_srv_net_share_set_info: Running [%s] returned (%d)\n", command, ret ));              
-       
+
+               TALLOC_FREE(command);
+
                if ( ret != 0 )
                        return WERR_ACCESS_DENIED;
        } else {
@@ -1606,55 +1735,58 @@ WERROR _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u, S
                SEC_DESC *old_sd;
                size_t sd_size;
 
-               old_sd = get_share_security(p->mem_ctx, lp_servicename(snum),
-                                           &sd_size);
+               old_sd = get_share_security(p->mem_ctx, lp_servicename(snum), &sd_size);
 
                if (old_sd && !sec_desc_equal(old_sd, psd)) {
-                       if (!set_share_security(p->mem_ctx, share_name, psd))
+                       if (!set_share_security(share_name, psd))
                                DEBUG(0,("_srv_net_share_set_info: Failed to change security info in share %s.\n",
                                        share_name ));
                }
        }
-                       
+
        DEBUG(5,("_srv_net_share_set_info: %d\n", __LINE__));
 
        return WERR_OK;
 }
 
 /*******************************************************************
- Net share add. Call 'add_share_command "sharename" "pathname" 
+ Net share add. Call 'add_share_command "sharename" "pathname"
  "comment" "max connections = "
 ********************************************************************/
 
 WERROR _srv_net_share_add(pipes_struct *p, SRV_Q_NET_SHARE_ADD *q_u, SRV_R_NET_SHARE_ADD *r_u)
 {
-       pstring command;
-       fstring share_name;
-       fstring comment;
-       pstring pathname;
+       struct current_user user;
+       char *command = NULL;
+       char *share_name = NULL;
+       char *comment = NULL;
+       char *pathname = NULL;
        int type;
        int snum;
        int ret;
        char *path;
        SEC_DESC *psd = NULL;
        SE_PRIV se_diskop = SE_DISK_OPERATOR;
-       BOOL is_disk_op;
+       bool is_disk_op;
        int max_connections = 0;
+       TALLOC_CTX *ctx = p->mem_ctx;
 
        DEBUG(5,("_srv_net_share_add: %d\n", __LINE__));
 
        r_u->parm_error = 0;
 
+       get_current_user(&user,p);
+
        is_disk_op = user_has_privileges( p->pipe_user.nt_user_token, &se_diskop );
 
-       if (p->pipe_user.ut.uid != sec_initial_uid()  && !is_disk_op ) 
+       if (user.ut.uid != sec_initial_uid()  && !is_disk_op )
                return WERR_ACCESS_DENIED;
 
        if (!lp_add_share_cmd() || !*lp_add_share_cmd()) {
                DEBUG(10,("_srv_net_share_add: No add share command\n"));
                return WERR_ACCESS_DENIED;
        }
-       
+
        switch (q_u->info_level) {
        case 0:
                /* No path. Not enough info in a level 0 to do anything. */
@@ -1663,9 +1795,12 @@ WERROR _srv_net_share_add(pipes_struct *p, SRV_Q_NET_SHARE_ADD *q_u, SRV_R_NET_S
                /* Not enough info in a level 1 to do anything. */
                return WERR_ACCESS_DENIED;
        case 2:
-               unistr2_to_ascii(share_name, &q_u->info.share.info2.info_2_str.uni_netname, sizeof(share_name));
-               unistr2_to_ascii(comment, &q_u->info.share.info2.info_2_str.uni_remark, sizeof(share_name));
-               unistr2_to_ascii(pathname, &q_u->info.share.info2.info_2_str.uni_path, sizeof(share_name));
+               share_name = unistr2_to_ascii_talloc(ctx,
+                               &q_u->info.share.info2.info_2_str.uni_netname);
+               comment = unistr2_to_ascii_talloc(ctx,
+                               &q_u->info.share.info2.info_2_str.uni_remark);
+               pathname = unistr2_to_ascii_talloc(ctx,
+                               &q_u->info.share.info2.info_2_str.uni_path);
                max_connections = (q_u->info.share.info2.info_2.max_uses == 0xffffffff) ? 0 : q_u->info.share.info2.info_2.max_uses;
                type = q_u->info.share.info2.info_2.type;
                break;
@@ -1673,9 +1808,12 @@ WERROR _srv_net_share_add(pipes_struct *p, SRV_Q_NET_SHARE_ADD *q_u, SRV_R_NET_S
                /* No path. Not enough info in a level 501 to do anything. */
                return WERR_ACCESS_DENIED;
        case 502:
-               unistr2_to_ascii(share_name, &q_u->info.share.info502.info_502_str.uni_netname, sizeof(share_name));
-               unistr2_to_ascii(comment, &q_u->info.share.info502.info_502_str.uni_remark, sizeof(share_name));
-               unistr2_to_ascii(pathname, &q_u->info.share.info502.info_502_str.uni_path, sizeof(share_name));
+               share_name = unistr2_to_ascii_talloc(ctx,
+                               &q_u->info.share.info502.info_502_str.uni_netname);
+               comment = unistr2_to_ascii_talloc(ctx,
+                               &q_u->info.share.info502.info_502_str.uni_remark);
+               pathname = unistr2_to_ascii_talloc(ctx,
+                               &q_u->info.share.info502.info_502_str.uni_path);
                type = q_u->info.share.info502.info_502.type;
                psd = q_u->info.share.info502.info_502_str.sd;
                map_generic_share_sd_bits(psd);
@@ -1698,68 +1836,83 @@ WERROR _srv_net_share_add(pipes_struct *p, SRV_Q_NET_SHARE_ADD *q_u, SRV_R_NET_S
 
        /* check for invalid share names */
 
-       if ( !validate_net_name( share_name, INVALID_SHARENAME_CHARS, sizeof(share_name) ) ) {
-               DEBUG(5,("_srv_net_name_validate: Bad sharename \"%s\"\n", share_name));
+       if (!share_name || !validate_net_name(share_name,
+                               INVALID_SHARENAME_CHARS,
+                               strlen(share_name))) {
+               DEBUG(5,("_srv_net_name_validate: Bad sharename \"%s\"\n",
+                                       share_name ? share_name : ""));
                return WERR_INVALID_NAME;
        }
 
-       if ( strequal(share_name,"IPC$") || strequal(share_name,"global")
-               || ( lp_enable_asu_support() && strequal(share_name,"ADMIN$") ) )
-       {
+       if (strequal(share_name,"IPC$") || strequal(share_name,"global")
+                       || (lp_enable_asu_support() &&
+                                       strequal(share_name,"ADMIN$"))) {
                return WERR_ACCESS_DENIED;
        }
 
        snum = find_service(share_name);
 
        /* Share already exists. */
-       if (snum >= 0)
+       if (snum >= 0) {
                return WERR_ALREADY_EXISTS;
+       }
 
        /* We can only add disk shares. */
-       if (type != STYPE_DISKTREE)
+       if (type != STYPE_DISKTREE) {
                return WERR_ACCESS_DENIED;
-               
+       }
+
        /* Check if the pathname is valid. */
-       if (!(path = valid_share_pathname( pathname )))
+       if (!(path = valid_share_pathname(p->mem_ctx, pathname))) {
                return WERR_OBJECT_PATH_INVALID;
+       }
 
        /* Ensure share name, pathname and comment don't contain '"' characters. */
        string_replace(share_name, '"', ' ');
        string_replace(path, '"', ' ');
-       string_replace(comment, '"', ' ');
-
-       slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\" %d",
-                       lp_add_share_cmd(), 
-                       dyn_CONFIGFILE, 
-                       share_name, 
-                       path, 
-                       comment, 
+       if (comment) {
+               string_replace(comment, '"', ' ');
+       }
+
+       command = talloc_asprintf(ctx,
+                       "%s \"%s\" \"%s\" \"%s\" \"%s\" %d",
+                       lp_add_share_cmd(),
+                       get_dyn_CONFIGFILE(),
+                       share_name,
+                       path,
+                       comment ? comment : "",
                        max_connections);
-                       
+       if (!command) {
+               return WERR_NOMEM;
+       }
+
        DEBUG(10,("_srv_net_share_add: Running [%s]\n", command ));
-       
+
        /********* BEGIN SeDiskOperatorPrivilege BLOCK *********/
-       
+
        if ( is_disk_op )
                become_root();
 
        if ( (ret = smbrun(command, NULL)) == 0 ) {
                /* Tell everyone we updated smb.conf. */
-               message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL);
+               message_send_all(smbd_messaging_context(),
+                                MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
        }
 
        if ( is_disk_op )
                unbecome_root();
-               
+
        /********* END SeDiskOperatorPrivilege BLOCK *********/
 
        DEBUG(3,("_srv_net_share_add: Running [%s] returned (%d)\n", command, ret ));
 
+       TALLOC_FREE(command);
+
        if ( ret != 0 )
                return WERR_ACCESS_DENIED;
 
        if (psd) {
-               if (!set_share_security(p->mem_ctx, share_name, psd)) {
+               if (!set_share_security(share_name, psd)) {
                        DEBUG(0,("_srv_net_share_add: Failed to add security info to share %s.\n", share_name ));
                }
        }
@@ -1782,61 +1935,77 @@ WERROR _srv_net_share_add(pipes_struct *p, SRV_Q_NET_SHARE_ADD *q_u, SRV_R_NET_S
 
 WERROR _srv_net_share_del(pipes_struct *p, SRV_Q_NET_SHARE_DEL *q_u, SRV_R_NET_SHARE_DEL *r_u)
 {
-       pstring command;
-       fstring share_name;
+       struct current_user user;
+       char *command = NULL;
+       char *share_name = NULL;
        int ret;
        int snum;
        SE_PRIV se_diskop = SE_DISK_OPERATOR;
-       BOOL is_disk_op;
+       bool is_disk_op;
+       struct share_params *params;
+       TALLOC_CTX *ctx = p->mem_ctx;
 
        DEBUG(5,("_srv_net_share_del: %d\n", __LINE__));
 
-       unistr2_to_ascii(share_name, &q_u->uni_share_name, sizeof(share_name));
+       share_name = unistr2_to_ascii_talloc(ctx, &q_u->uni_share_name);
 
-       if ( strequal(share_name,"IPC$") 
+       if (!share_name) {
+               return WERR_NET_NAME_NOT_FOUND;
+       }
+       if ( strequal(share_name,"IPC$")
                || ( lp_enable_asu_support() && strequal(share_name,"ADMIN$") )
                || strequal(share_name,"global") )
        {
                return WERR_ACCESS_DENIED;
        }
 
-       snum = find_service(share_name);
-
-       if (snum < 0)
+       if (!(params = get_share_params(p->mem_ctx, share_name))) {
                return WERR_NO_SUCH_SHARE;
+       }
+
+       snum = find_service(share_name);
 
        /* No change to printer shares. */
        if (lp_print_ok(snum))
                return WERR_ACCESS_DENIED;
 
+       get_current_user(&user,p);
+
        is_disk_op = user_has_privileges( p->pipe_user.nt_user_token, &se_diskop );
 
-       if (p->pipe_user.ut.uid != sec_initial_uid()  && !is_disk_op ) 
+       if (user.ut.uid != sec_initial_uid()  && !is_disk_op )
                return WERR_ACCESS_DENIED;
 
        if (!lp_delete_share_cmd() || !*lp_delete_share_cmd()) {
                DEBUG(10,("_srv_net_share_del: No delete share command\n"));
                return WERR_ACCESS_DENIED;
        }
-               
-       slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\"",
-                       lp_delete_share_cmd(), dyn_CONFIGFILE, lp_servicename(snum));
+
+       command = talloc_asprintf(ctx,
+                       "%s \"%s\" \"%s\"",
+                       lp_delete_share_cmd(),
+                       get_dyn_CONFIGFILE(),
+                       lp_servicename(snum));
+       if (!command) {
+               return WERR_NOMEM;
+       }
 
        DEBUG(10,("_srv_net_share_del: Running [%s]\n", command ));
 
        /********* BEGIN SeDiskOperatorPrivilege BLOCK *********/
-       
+
        if ( is_disk_op )
                become_root();
 
        if ( (ret = smbrun(command, NULL)) == 0 ) {
                /* Tell everyone we updated smb.conf. */
-               message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL);
+               message_send_all(smbd_messaging_context(),
+                                MSG_SMB_CONF_UPDATED, NULL, 0, NULL);
        }
 
        if ( is_disk_op )
                unbecome_root();
-               
+
        /********* END SeDiskOperatorPrivilege BLOCK *********/
 
        DEBUG(3,("_srv_net_share_del: Running [%s] returned (%d)\n", command, ret ));
@@ -1845,9 +2014,9 @@ WERROR _srv_net_share_del(pipes_struct *p, SRV_Q_NET_SHARE_DEL *q_u, SRV_R_NET_S
                return WERR_ACCESS_DENIED;
 
        /* Delete the SD in the database. */
-       delete_share_security(snum);
+       delete_share_security(lp_servicename(params->service));
 
-       lp_killservice(snum);
+       lp_killservice(params->service);
 
        return WERR_OK;
 }
@@ -1917,26 +2086,33 @@ WERROR _srv_net_file_query_secdesc(pipes_struct *p, SRV_Q_NET_FILE_QUERY_SECDESC
        SEC_DESC *psd = NULL;
        size_t sd_size;
        DATA_BLOB null_pw;
-       pstring filename;
-       pstring qualname;
-       files_struct *fsp = NULL;
+       char *filename_in = NULL;
+       char *filename = NULL;
+       char *qualname = NULL;
        SMB_STRUCT_STAT st;
-       BOOL bad_path;
        NTSTATUS nt_status;
+       struct current_user user;
        connection_struct *conn = NULL;
-       BOOL became_user = False; 
+       bool became_user = False;
+       TALLOC_CTX *ctx = p->mem_ctx;
 
        ZERO_STRUCT(st);
 
        r_u->status = WERR_OK;
 
-       unistr2_to_ascii(qualname, &q_u->uni_qual_name, sizeof(qualname));
+       qualname = unistr2_to_ascii_talloc(ctx, &q_u->uni_qual_name);
+       if (!qualname) {
+               r_u->status = WERR_ACCESS_DENIED;
+               goto error_exit;
+       }
 
        /* Null password is ok - we are already an authenticated user... */
-       null_pw = data_blob(NULL, 0);
+       null_pw = data_blob_null;
+
+       get_current_user(&user, p);
 
        become_root();
-       conn = make_connection(qualname, null_pw, "A:", p->pipe_user.vuid, &nt_status);
+       conn = make_connection(qualname, null_pw, "A:", user.vuid, &nt_status);
        unbecome_root();
 
        if (conn == NULL) {
@@ -1952,70 +2128,58 @@ WERROR _srv_net_file_query_secdesc(pipes_struct *p, SRV_Q_NET_FILE_QUERY_SECDESC
        }
        became_user = True;
 
-       unistr2_to_ascii(filename, &q_u->uni_file_name, sizeof(filename));
-       unix_convert(filename, conn, NULL, &bad_path, &st);
-       if (bad_path) {
-               DEBUG(3,("_srv_net_file_query_secdesc: bad pathname %s\n", filename));
+       filename_in = unistr2_to_ascii_talloc(ctx, &q_u->uni_file_name);
+       if (!filename_in) {
                r_u->status = WERR_ACCESS_DENIED;
                goto error_exit;
        }
 
-       if (!check_name(filename,conn)) {
-               DEBUG(3,("_srv_net_file_query_secdesc: can't access %s\n", filename));
+       nt_status = unix_convert(ctx, conn, filename_in, False, &filename, NULL, &st);
+       if (!NT_STATUS_IS_OK(nt_status)) {
+               DEBUG(3,("_srv_net_file_query_secdesc: bad pathname %s\n", filename));
                r_u->status = WERR_ACCESS_DENIED;
                goto error_exit;
        }
 
-       nt_status = open_file_stat(conn, filename, &st, &fsp);
+       nt_status = check_name(conn, filename);
        if (!NT_STATUS_IS_OK(nt_status)) {
-               /* Perhaps it is a directory */
-               if (NT_STATUS_EQUAL(nt_status, NT_STATUS_FILE_IS_A_DIRECTORY))
-                       nt_status = open_directory(conn, filename, &st,
-                                       READ_CONTROL_ACCESS,
-                                       FILE_SHARE_READ|FILE_SHARE_WRITE,
-                                       FILE_OPEN,
-                                       0,
-                                       NULL, &fsp);
-
-               if (!NT_STATUS_IS_OK(nt_status)) {
-                       DEBUG(3,("_srv_net_file_query_secdesc: Unable to open file %s\n", filename));
-                       r_u->status = WERR_ACCESS_DENIED;
-                       goto error_exit;
-               }
+               DEBUG(3,("_srv_net_file_query_secdesc: can't access %s\n", filename));
+               r_u->status = WERR_ACCESS_DENIED;
+               goto error_exit;
        }
 
-       sd_size = SMB_VFS_GET_NT_ACL(fsp, fsp->fsp_name, (OWNER_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION|DACL_SECURITY_INFORMATION), &psd);
+       nt_status = SMB_VFS_GET_NT_ACL(conn, filename,
+                                      (OWNER_SECURITY_INFORMATION
+                                       |GROUP_SECURITY_INFORMATION
+                                       |DACL_SECURITY_INFORMATION), &psd);
 
-       if (sd_size == 0) {
+       if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(3,("_srv_net_file_query_secdesc: Unable to get NT ACL for file %s\n", filename));
-               r_u->status = WERR_ACCESS_DENIED;
+               r_u->status = ntstatus_to_werror(nt_status);
                goto error_exit;
        }
 
+       sd_size = ndr_size_security_descriptor(psd, 0);
+
        r_u->ptr_response = 1;
        r_u->size_response = sd_size;
        r_u->ptr_secdesc = 1;
        r_u->size_secdesc = sd_size;
        r_u->sec_desc = psd;
 
-       psd->dacl->revision = (uint16) NT4_ACL_REVISION;
+       psd->dacl->revision = NT4_ACL_REVISION;
 
-       close_file(fsp, NORMAL_CLOSE);
        unbecome_user();
-       close_cnum(conn, p->pipe_user.vuid);
+       close_cnum(conn, user.vuid);
        return r_u->status;
 
 error_exit:
 
-       if(fsp) {
-               close_file(fsp, NORMAL_CLOSE);
-       }
-
        if (became_user)
                unbecome_user();
 
-       if (conn) 
-               close_cnum(conn, p->pipe_user.vuid);
+       if (conn)
+               close_cnum(conn, user.vuid);
 
        return r_u->status;
 }
@@ -2027,28 +2191,35 @@ error_exit:
 WERROR _srv_net_file_set_secdesc(pipes_struct *p, SRV_Q_NET_FILE_SET_SECDESC *q_u,
                                                                        SRV_R_NET_FILE_SET_SECDESC *r_u)
 {
-       BOOL ret;
-       pstring filename;
-       pstring qualname;
+       char *filename_in = NULL;
+       char *filename = NULL;
+       char *qualname = NULL;
        DATA_BLOB null_pw;
        files_struct *fsp = NULL;
        SMB_STRUCT_STAT st;
-       BOOL bad_path;
        NTSTATUS nt_status;
+       struct current_user user;
        connection_struct *conn = NULL;
-       BOOL became_user = False;
+       bool became_user = False;
+       TALLOC_CTX *ctx = p->mem_ctx;
 
        ZERO_STRUCT(st);
 
        r_u->status = WERR_OK;
 
-       unistr2_to_ascii(qualname, &q_u->uni_qual_name, sizeof(qualname));
+       qualname = unistr2_to_ascii_talloc(ctx, &q_u->uni_qual_name);
+       if (!qualname) {
+               r_u->status = WERR_ACCESS_DENIED;
+               goto error_exit;
+       }
 
        /* Null password is ok - we are already an authenticated user... */
-       null_pw = data_blob(NULL, 0);
+       null_pw = data_blob_null;
+
+       get_current_user(&user, p);
 
        become_root();
-       conn = make_connection(qualname, null_pw, "A:", p->pipe_user.vuid, &nt_status);
+       conn = make_connection(qualname, null_pw, "A:", user.vuid, &nt_status);
        unbecome_root();
 
        if (conn == NULL) {
@@ -2064,43 +2235,49 @@ WERROR _srv_net_file_set_secdesc(pipes_struct *p, SRV_Q_NET_FILE_SET_SECDESC *q_
        }
        became_user = True;
 
-       unistr2_to_ascii(filename, &q_u->uni_file_name, sizeof(filename));
-       unix_convert(filename, conn, NULL, &bad_path, &st);
-       if (bad_path) {
+       filename_in= unistr2_to_ascii_talloc(ctx, &q_u->uni_file_name);
+       if (!filename_in) {
+               r_u->status = WERR_ACCESS_DENIED;
+               goto error_exit;
+       }
+
+       nt_status = unix_convert(ctx, conn, filename, False, &filename, NULL, &st);
+       if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(3,("_srv_net_file_set_secdesc: bad pathname %s\n", filename));
                r_u->status = WERR_ACCESS_DENIED;
                goto error_exit;
        }
 
-       if (!check_name(filename,conn)) {
+       nt_status = check_name(conn, filename);
+       if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(3,("_srv_net_file_set_secdesc: can't access %s\n", filename));
                r_u->status = WERR_ACCESS_DENIED;
                goto error_exit;
        }
 
+       nt_status = open_file_stat(conn, NULL, filename, &st, &fsp);
 
-       nt_status = open_file_stat(conn, filename, &st, &fsp);
-
-       if (!NT_STATUS_IS_OK(nt_status)) {
+       if ( !NT_STATUS_IS_OK(nt_status) ) {
                /* Perhaps it is a directory */
                if (NT_STATUS_EQUAL(nt_status, NT_STATUS_FILE_IS_A_DIRECTORY))
-                       nt_status = open_directory(conn, filename, &st,
+                       nt_status = open_directory(conn, NULL, filename, &st,
                                                FILE_READ_ATTRIBUTES,
                                                FILE_SHARE_READ|FILE_SHARE_WRITE,
                                                FILE_OPEN,
                                                0,
+                                               FILE_ATTRIBUTE_DIRECTORY,
                                                NULL, &fsp);
 
-               if (!NT_STATUS_IS_OK(nt_status)) {
+               if ( !NT_STATUS_IS_OK(nt_status) ) {
                        DEBUG(3,("_srv_net_file_set_secdesc: Unable to open file %s\n", filename));
-                       r_u->status = WERR_ACCESS_DENIED;
+                       r_u->status = ntstatus_to_werror(nt_status);
                        goto error_exit;
                }
        }
 
-       ret = SMB_VFS_SET_NT_ACL(fsp, fsp->fsp_name, q_u->sec_info, q_u->sec_desc);
+       nt_status = SMB_VFS_SET_NT_ACL(fsp, fsp->fsp_name, q_u->sec_info, q_u->sec_desc);
 
-       if (ret == False) {
+       if (!NT_STATUS_IS_OK(nt_status) ) {
                DEBUG(3,("_srv_net_file_set_secdesc: Unable to set NT ACL on file %s\n", filename));
                r_u->status = WERR_ACCESS_DENIED;
                goto error_exit;
@@ -2108,7 +2285,7 @@ WERROR _srv_net_file_set_secdesc(pipes_struct *p, SRV_Q_NET_FILE_SET_SECDESC *q_
 
        close_file(fsp, NORMAL_CLOSE);
        unbecome_user();
-       close_cnum(conn, p->pipe_user.vuid);
+       close_cnum(conn, user.vuid);
        return r_u->status;
 
 error_exit:
@@ -2122,7 +2299,7 @@ error_exit:
        }
 
        if (conn) {
-               close_cnum(conn, p->pipe_user.vuid);
+               close_cnum(conn, user.vuid);
        }
 
        return r_u->status;
@@ -2242,8 +2419,330 @@ WERROR _srv_net_name_validate(pipes_struct *p, SRV_Q_NET_NAME_VALIDATE *q_u, SRV
 /********************************************************************
 ********************************************************************/
 
-WERROR _srv_net_file_close(pipes_struct *p, SRV_Q_NET_FILE_CLOSE *q_u, SRV_R_NET_FILE_CLOSE *r_u)
+WERROR _srvsvc_NetFileClose(pipes_struct *p, struct srvsvc_NetFileClose *r)
 {
        return WERR_ACCESS_DENIED;
 }
 
+
+/********************************************************************
+********************************************************************/
+
+WERROR _srvsvc_NetCharDevEnum(pipes_struct *p, struct srvsvc_NetCharDevEnum *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetCharDevGetInfo(pipes_struct *p, struct srvsvc_NetCharDevGetInfo *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetCharDevControl(pipes_struct *p, struct srvsvc_NetCharDevControl *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetCharDevQEnum(pipes_struct *p, struct srvsvc_NetCharDevQEnum *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetCharDevQGetInfo(pipes_struct *p, struct srvsvc_NetCharDevQGetInfo *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetCharDevQSetInfo(pipes_struct *p, struct srvsvc_NetCharDevQSetInfo *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetCharDevQPurge(pipes_struct *p, struct srvsvc_NetCharDevQPurge *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetCharDevQPurgeSelf(pipes_struct *p, struct srvsvc_NetCharDevQPurgeSelf *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetConnEnum(pipes_struct *p, struct srvsvc_NetConnEnum *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetFileEnum(pipes_struct *p, struct srvsvc_NetFileEnum *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetFileGetInfo(pipes_struct *p, struct srvsvc_NetFileGetInfo *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetSessEnum(pipes_struct *p, struct srvsvc_NetSessEnum *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetSessDel(pipes_struct *p, struct srvsvc_NetSessDel *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetShareAdd(pipes_struct *p, struct srvsvc_NetShareAdd *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetShareEnumAll(pipes_struct *p, struct srvsvc_NetShareEnumAll *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetShareGetInfo(pipes_struct *p, struct srvsvc_NetShareGetInfo *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetShareSetInfo(pipes_struct *p, struct srvsvc_NetShareSetInfo *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetShareDel(pipes_struct *p, struct srvsvc_NetShareDel *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetShareDelSticky(pipes_struct *p, struct srvsvc_NetShareDelSticky *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetShareCheck(pipes_struct *p, struct srvsvc_NetShareCheck *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetSrvGetInfo(pipes_struct *p, struct srvsvc_NetSrvGetInfo *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetSrvSetInfo(pipes_struct *p, struct srvsvc_NetSrvSetInfo *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetDiskEnum(pipes_struct *p, struct srvsvc_NetDiskEnum *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetServerStatisticsGet(pipes_struct *p, struct srvsvc_NetServerStatisticsGet *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetTransportAdd(pipes_struct *p, struct srvsvc_NetTransportAdd *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetTransportEnum(pipes_struct *p, struct srvsvc_NetTransportEnum *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetTransportDel(pipes_struct *p, struct srvsvc_NetTransportDel *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetRemoteTOD(pipes_struct *p, struct srvsvc_NetRemoteTOD *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetSetServiceBits(pipes_struct *p, struct srvsvc_NetSetServiceBits *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetPathType(pipes_struct *p, struct srvsvc_NetPathType *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetPathCanonicalize(pipes_struct *p, struct srvsvc_NetPathCanonicalize *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetPathCompare(pipes_struct *p, struct srvsvc_NetPathCompare *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetNameValidate(pipes_struct *p, struct srvsvc_NetNameValidate *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NETRPRNAMECANONICALIZE(pipes_struct *p, struct srvsvc_NETRPRNAMECANONICALIZE *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetPRNameCompare(pipes_struct *p, struct srvsvc_NetPRNameCompare *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetShareEnum(pipes_struct *p, struct srvsvc_NetShareEnum *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetShareDelStart(pipes_struct *p, struct srvsvc_NetShareDelStart *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetShareDelCommit(pipes_struct *p, struct srvsvc_NetShareDelCommit *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetGetFileSecurity(pipes_struct *p, struct srvsvc_NetGetFileSecurity *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetSetFileSecurity(pipes_struct *p, struct srvsvc_NetSetFileSecurity *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetServerTransportAddEx(pipes_struct *p, struct srvsvc_NetServerTransportAddEx *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NetServerSetServiceBitsEx(pipes_struct *p, struct srvsvc_NetServerSetServiceBitsEx *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NETRDFSGETVERSION(pipes_struct *p, struct srvsvc_NETRDFSGETVERSION *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NETRDFSCREATELOCALPARTITION(pipes_struct *p, struct srvsvc_NETRDFSCREATELOCALPARTITION *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NETRDFSDELETELOCALPARTITION(pipes_struct *p, struct srvsvc_NETRDFSDELETELOCALPARTITION *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NETRDFSSETLOCALVOLUMESTATE(pipes_struct *p, struct srvsvc_NETRDFSSETLOCALVOLUMESTATE *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NETRDFSSETSERVERINFO(pipes_struct *p, struct srvsvc_NETRDFSSETSERVERINFO *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NETRDFSCREATEEXITPOINT(pipes_struct *p, struct srvsvc_NETRDFSCREATEEXITPOINT *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NETRDFSDELETEEXITPOINT(pipes_struct *p, struct srvsvc_NETRDFSDELETEEXITPOINT *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NETRDFSMODIFYPREFIX(pipes_struct *p, struct srvsvc_NETRDFSMODIFYPREFIX *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NETRDFSFIXLOCALVOLUME(pipes_struct *p, struct srvsvc_NETRDFSFIXLOCALVOLUME *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NETRDFSMANAGERREPORTSITEINFO(pipes_struct *p, struct srvsvc_NETRDFSMANAGERREPORTSITEINFO *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+
+WERROR _srvsvc_NETRSERVERTRANSPORTDELEX(pipes_struct *p, struct srvsvc_NETRSERVERTRANSPORTDELEX *r)
+{
+       p->rng_fault_state = True;
+       return WERR_NOT_SUPPORTED;
+}
+