r4852: merge simo changes to srv_srvsvc_nt.c from trunk
[ira/wip.git] / source3 / rpc_server / srv_srvsvc_nt.c
index f1dabd64a90ed0408520834e811964e452b8aef8..529b4c198d210078d05d8f7c2f7e1195e5bdc2fe 100644 (file)
@@ -1,11 +1,9 @@
 /* 
- *  Unix SMB/Netbios implementation.
- *  Version 1.9.
+ *  Unix SMB/CIFS implementation.
  *  RPC Pipe client / server routines
  *  Copyright (C) Andrew Tridgell              1992-1997,
- *  Copyright (C) Luke Kenneth Casson Leighton 1996-1997,
- *  Copyright (C) Paul Ashton                       1997.
  *  Copyright (C) Jeremy Allison                                       2001.
+ *  Copyright (C) Nigel Williams                                       2001.
  *  
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
 
 #include "includes.h"
 
-extern pstring global_myname;
+#undef DBGC_CLASS
+#define DBGC_CLASS DBGC_RPC_SRV
 
 /*******************************************************************
Fill in a share info level 1 structure.
Utility function to get the 'type' of a share from an snum.
  ********************************************************************/
-
-static void init_srv_share_info_1(pipes_struct *p, SRV_SHARE_INFO_1 *sh1, int snum)
+static uint32 get_share_type(int snum) 
 {
-       int len_net_name;
-       pstring net_name;
-       pstring remark;
-       uint32 type;
-
-       pstrcpy(net_name, lp_servicename(snum));
-       pstrcpy(remark, lp_comment(snum));
-       standard_sub_conn(p->conn, remark);
-       len_net_name = strlen(net_name);
-
+       char *net_name = lp_servicename(snum);
+       int len_net_name = strlen(net_name);
+       
        /* work out the share type */
-       type = STYPE_DISKTREE;
-               
+       uint32 type = STYPE_DISKTREE;
+
        if (lp_print_ok(snum))
                type = STYPE_PRINTQ;
-       if (strequal("IPC$", net_name) || strequal("ADMIN$", net_name))
+       if (strequal(lp_fstype(snum), "IPC"))
                type = STYPE_IPC;
        if (net_name[len_net_name] == '$')
                type |= STYPE_HIDDEN;
 
-       init_srv_share_info1(&sh1->info_1, net_name, type, remark);
+       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, int snum)
+{
+       pstring net_name;
+
+       pstrcpy(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);
+}
+
+/*******************************************************************
+ Fill in a share info level 1 structure.
+ ********************************************************************/
+
+static void init_srv_share_info_1(pipes_struct *p, SRV_SHARE_INFO_1 *sh1, int snum)
+{
+       pstring remark;
+
+       char *net_name = lp_servicename(snum);
+       pstrcpy(remark, lp_comment(snum));
+       standard_sub_conn(p->conn, remark,sizeof(remark));
+
+       init_srv_share_info1(&sh1->info_1, net_name, get_share_type(snum), remark);
        init_srv_share_info1_str(&sh1->info_1_str, net_name, remark);
 }
 
@@ -64,16 +84,13 @@ static void init_srv_share_info_1(pipes_struct *p, SRV_SHARE_INFO_1 *sh1, int sn
 
 static void init_srv_share_info_2(pipes_struct *p, SRV_SHARE_INFO_2 *sh2, int snum)
 {
-       int len_net_name;
-       pstring net_name;
        pstring remark;
        pstring path;
        pstring passwd;
-       uint32 type;
 
-       pstrcpy(net_name, lp_servicename(snum));
+       char *net_name = lp_servicename(snum);
        pstrcpy(remark, lp_comment(snum));
-       standard_sub_conn(p->conn, remark);
+       standard_sub_conn(p->conn, remark,sizeof(remark));
        pstrcpy(path, "C:");
        pstrcat(path, lp_pathname(snum));
 
@@ -85,19 +102,8 @@ static void init_srv_share_info_2(pipes_struct *p, SRV_SHARE_INFO_2 *sh2, int sn
        string_replace(path, '/', '\\');
 
        pstrcpy(passwd, "");
-       len_net_name = strlen(net_name);
 
-       /* work out the share type */
-       type = STYPE_DISKTREE;
-               
-       if (lp_print_ok(snum))
-               type = STYPE_PRINTQ;
-       if (strequal("IPC$", net_name) || strequal("ADMIN$", net_name))
-               type = STYPE_IPC;
-       if (net_name[len_net_name] == '$')
-               type |= STYPE_HIDDEN;
-
-       init_srv_share_info2(&sh2->info_2, net_name, type, remark, 0, 0xffffffff, 1, path, passwd);
+       init_srv_share_info2(&sh2->info_2, net_name, get_share_type(snum), remark, 0, 0xffffffff, 1, path, passwd);
        init_srv_share_info2_str(&sh2->info_2_str, net_name, remark, path, passwd);
 }
 
@@ -116,34 +122,46 @@ static void smb_conf_updated(int msg_type, pid_t src, void *buf, size_t len)
  ********************************************************************/
 
 static TDB_CONTEXT *share_tdb; /* used for share security descriptors */
-#define SHARE_DATABASE_VERSION 1
+#define SHARE_DATABASE_VERSION_V1 1
+#define SHARE_DATABASE_VERSION_V2 2 /* version id in little endian. */
 
 BOOL share_info_db_init(void)
 {
-    static pid_t local_pid;
-    char *vstring = "INFO/version";
+       static pid_t local_pid;
+       const char *vstring = "INFO/version";
+       int32 vers_id;
  
-    if (share_tdb && local_pid == sys_getpid()) return True;
-    share_tdb = tdb_open_log(lock_path("share_info.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
-    if (!share_tdb) {
-        DEBUG(0,("Failed to open share info database %s (%s)\n",
-                               lock_path("share_info.tdb"), strerror(errno) ));
-        return False;
-    }
+       if (share_tdb && local_pid == sys_getpid())
+               return True;
+       share_tdb = tdb_open_log(lock_path("share_info.tdb"), 0, TDB_DEFAULT, O_RDWR|O_CREAT, 0600);
+       if (!share_tdb) {
+               DEBUG(0,("Failed to open share info database %s (%s)\n",
+                       lock_path("share_info.tdb"), strerror(errno) ));
+               return False;
+       }
  
-    local_pid = sys_getpid();
+       local_pid = sys_getpid();
  
-    /* handle a Samba upgrade */
-    tdb_lock_bystring(share_tdb, vstring);
-    if (tdb_fetch_int(share_tdb, vstring) != SHARE_DATABASE_VERSION) {
-        tdb_traverse(share_tdb, (tdb_traverse_func)tdb_delete, NULL);
-        tdb_store_int(share_tdb, vstring, SHARE_DATABASE_VERSION);
-    }
-    tdb_unlock_bystring(share_tdb, vstring);
+       /* handle a Samba upgrade */
+       tdb_lock_bystring(share_tdb, vstring, 0);
+
+       /* Cope with byte-reversed older versions of the db. */
+       vers_id = tdb_fetch_int32(share_tdb, vstring);
+       if ((vers_id == SHARE_DATABASE_VERSION_V1) || (IREV(vers_id) == SHARE_DATABASE_VERSION_V1)) {
+               /* Written on a bigendian machine with old fetch_int code. Save as le. */
+               tdb_store_int32(share_tdb, vstring, SHARE_DATABASE_VERSION_V2);
+               vers_id = SHARE_DATABASE_VERSION_V2;
+       }
+
+       if (vers_id != SHARE_DATABASE_VERSION_V2) {
+               tdb_traverse(share_tdb, tdb_traverse_delete_fn, NULL);
+               tdb_store_int32(share_tdb, vstring, SHARE_DATABASE_VERSION_V2);
+       }
+       tdb_unlock_bystring(share_tdb, vstring);
 
        message_register(MSG_SMB_CONF_UPDATED, smb_conf_updated);
  
-    return True;
+       return True;
 }
 
 /*******************************************************************
@@ -162,11 +180,11 @@ static SEC_DESC *get_share_security_default( TALLOC_CTX *ctx, int snum, size_t *
 
        se_map_generic(&def_access, &file_generic_mapping);
 
-    init_sec_access(&sa, GENERIC_ALL_ACCESS | def_access );
-    init_sec_ace(&ace, &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED, sa, 0);
+       init_sec_access(&sa, GENERIC_ALL_ACCESS | def_access );
+       init_sec_ace(&ace, &global_sid_World, SEC_ACE_TYPE_ACCESS_ALLOWED, sa, 0);
 
        if ((psa = make_sec_acl(ctx, NT4_ACL_REVISION, 1, &ace)) != NULL) {
-               psd = make_sec_desc(ctx, SEC_DESC_REVISION, NULL, NULL, NULL, psa, psize);
+               psd = make_sec_desc(ctx, SEC_DESC_REVISION, SEC_DESC_SELF_RELATIVE, NULL, NULL, NULL, psa, psize);
        }
 
        if (!psd) {
@@ -193,13 +211,13 @@ static SEC_DESC *get_share_security( TALLOC_CTX *ctx, int snum, size_t *psize)
  
        slprintf(key, sizeof(key)-1, "SECDESC/%s", lp_servicename(snum));
  
-    if (tdb_prs_fetch(share_tdb, key, &ps, ctx)!=0 ||
-        !sec_io_desc("get_share_security", &psd, &ps, 1)) {
+       if (tdb_prs_fetch(share_tdb, key, &ps, ctx)!=0 ||
+               !sec_io_desc("get_share_security", &psd, &ps, 1)) {
  
-        DEBUG(4,("get_share_security: using default secdesc for %s\n", lp_servicename(snum) ));
+               DEBUG(4,("get_share_security: using default secdesc for %s\n", lp_servicename(snum) ));
  
-        return get_share_security_default(ctx, snum, psize);
-    }
+               return get_share_security_default(ctx, snum, psize);
+       }
 
        if (psd)
                *psize = sec_desc_size(psd);
@@ -219,33 +237,32 @@ static BOOL set_share_security(TALLOC_CTX *ctx, const char *share_name, SEC_DESC
        fstring key;
        BOOL ret = False;
 
-       mem_ctx = talloc_init();
+       mem_ctx = talloc_init("set_share_security");
        if (mem_ctx == NULL)
                return False;
 
        prs_init(&ps, (uint32)sec_desc_size(psd), mem_ctx, MARSHALL);
  
-    if (!sec_io_desc("share_security", &psd, &ps, 1)) {
-        goto out;
-    }
+       if (!sec_io_desc("share_security", &psd, &ps, 1))
+               goto out;
  
        slprintf(key, sizeof(key)-1, "SECDESC/%s", share_name);
  
-    if (tdb_prs_store(share_tdb, key, &ps)==0) {
-        ret = True;
-        DEBUG(5,("set_share_security: stored secdesc for %s\n", share_name ));
-    } else {
-        DEBUG(1,("set_share_security: Failed to store secdesc for %s\n", share_name ));
-    }
-
-    /* Free malloc'ed memory */
+       if (tdb_prs_store(share_tdb, key, &ps)==0) {
+               ret = True;
+               DEBUG(5,("set_share_security: stored secdesc for %s\n", share_name ));
+       } else {
+               DEBUG(1,("set_share_security: Failed to store secdesc for %s\n", share_name ));
+       } 
+
+       /* Free malloc'ed memory */
  
- out:
+out:
  
-    prs_mem_free(&ps);
-    if (mem_ctx)
-        talloc_destroy(mem_ctx);
-    return ret;
+       prs_mem_free(&ps);
+       if (mem_ctx)
+               talloc_destroy(mem_ctx);
+       return ret;
 }
 
 /*******************************************************************
@@ -300,7 +317,7 @@ void map_generic_share_sd_bits(SEC_DESC *psd)
  Can this user access with share with the required permissions ?
 ********************************************************************/
 
-BOOL share_access_check(connection_struct *conn, int snum, uint16 vuid, uint32 desired_access)
+BOOL share_access_check(connection_struct *conn, int snum, user_struct *vuser, uint32 desired_access)
 {
        uint32 granted;
        NTSTATUS status;
@@ -308,11 +325,9 @@ BOOL share_access_check(connection_struct *conn, int snum, uint16 vuid, uint32 d
        SEC_DESC *psd = NULL;
        size_t sd_size;
        NT_USER_TOKEN *token = NULL;
-       user_struct *vuser = get_valid_user_struct(vuid);
        BOOL ret = True;
-       BOOL is_root = False;
 
-       mem_ctx = talloc_init();
+       mem_ctx = talloc_init("share_access_check");
        if (mem_ctx == NULL)
                return False;
 
@@ -321,44 +336,46 @@ BOOL share_access_check(connection_struct *conn, int snum, uint16 vuid, uint32 d
        if (!psd)
                goto out;
 
-       if (vuser) {
-               token = vuser->nt_user_token;
-               if (vuser->uid == (uid_t)0)
-                       is_root = True;
-       } else {
+       if (conn->nt_user_token)
                token = conn->nt_user_token;
-               if (conn->uid == (uid_t)0)
-                       is_root = True;
-       }
-
-       /*
-        * Root gets a free pass.
-        */
+       else 
+               token = vuser->nt_user_token;
 
-       if (is_root)
-               ret = True;
-       else
-               ret = se_access_check(psd, token, desired_access, &granted, &status);
+       ret = se_access_check(psd, token, desired_access, &granted, &status);
 
-  out:
+out:
 
        talloc_destroy(mem_ctx);
 
        return ret;
 }
 
+/*******************************************************************
+ Fill in a share info level 501 structure.
+********************************************************************/
+
+static void init_srv_share_info_501(pipes_struct *p, SRV_SHARE_INFO_501 *sh501, int snum)
+{
+       pstring remark;
+
+       const char *net_name = lp_servicename(snum);
+       pstrcpy(remark, lp_comment(snum));
+       standard_sub_conn(p->conn, remark, sizeof(remark));
+
+       init_srv_share_info501(&sh501->info_501, net_name, get_share_type(snum), remark, (lp_csc_policy(snum) << 4));
+       init_srv_share_info501_str(&sh501->info_501_str, net_name, remark);
+}
+
 /*******************************************************************
  Fill in a share info level 502 structure.
  ********************************************************************/
 
 static void init_srv_share_info_502(pipes_struct *p, SRV_SHARE_INFO_502 *sh502, int snum)
 {
-       int len_net_name;
        pstring net_name;
        pstring remark;
        pstring path;
        pstring passwd;
-       uint32 type;
        SEC_DESC *sd;
        size_t sd_size;
        TALLOC_CTX *ctx = p->mem_ctx;
@@ -368,7 +385,7 @@ static void init_srv_share_info_502(pipes_struct *p, SRV_SHARE_INFO_502 *sh502,
 
        pstrcpy(net_name, lp_servicename(snum));
        pstrcpy(remark, lp_comment(snum));
-       standard_sub_conn(p->conn, remark);
+       standard_sub_conn(p->conn, remark,sizeof(remark));
        pstrcpy(path, "C:");
        pstrcat(path, lp_pathname(snum));
 
@@ -380,46 +397,94 @@ static void init_srv_share_info_502(pipes_struct *p, SRV_SHARE_INFO_502 *sh502,
        string_replace(path, '/', '\\');
 
        pstrcpy(passwd, "");
-       len_net_name = strlen(net_name);
-
-       /* work out the share type */
-       type = STYPE_DISKTREE;
-               
-       if (lp_print_ok(snum))
-               type = STYPE_PRINTQ;
-       if (strequal("IPC$", net_name))
-               type = STYPE_IPC;
-       if (net_name[len_net_name] == '$')
-               type |= STYPE_HIDDEN;
 
        sd = get_share_security(ctx, snum, &sd_size);
 
-       init_srv_share_info502(&sh502->info_502, net_name, type, remark, 0, 0xffffffff, 1, path, passwd, sd, sd_size);
-       init_srv_share_info502_str(&sh502->info_502_str, &sh502->info_502, net_name, remark, path, passwd, sd, sd_size);
+       init_srv_share_info502(&sh502->info_502, net_name, get_share_type(snum), remark, 0, 0xffffffff, 1, path, passwd, sd, sd_size);
+       init_srv_share_info502_str(&sh502->info_502_str, net_name, remark, path, passwd, 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, int snum)
+{
+        pstring remark;
+
+       pstrcpy(remark, lp_comment(snum));
+       standard_sub_conn(p->conn, remark, sizeof(remark));
+
+       ZERO_STRUCTP(sh1004);
+  
+       init_srv_share_info1004(&sh1004->info_1004, remark);
+       init_srv_share_info1004_str(&sh1004->info_1004_str, remark);
 }
 
 /***************************************************************************
  Fill in a share info level 1005 structure.
  ***************************************************************************/
 
-static void init_srv_share_info_1005(SRV_SHARE_INFO_1005* sh1005, int snum)
+static void init_srv_share_info_1005(pipes_struct *p, SRV_SHARE_INFO_1005* sh1005, int snum)
 {
-       sh1005->dfs_root_flag = 0;
+       sh1005->share_info_flags = 0;
 
        if(lp_host_msdfs() && lp_msdfs_root(snum))
-               sh1005->dfs_root_flag = 3;
+               sh1005->share_info_flags |= 
+                       SHARE_1005_IN_DFS | SHARE_1005_DFS_ROOT;
+       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, int snum)
+{
+       sh1006->max_uses = -1;
+}
+
+/***************************************************************************
+ Fill in a share info level 1007 structure.
+ ***************************************************************************/
+
+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);
+}
+
+/*******************************************************************
+ Fill in a share info level 1501 structure.
+ ********************************************************************/
+
+static void init_srv_share_info_1501(pipes_struct *p, SRV_SHARE_INFO_1501 *sh1501, int snum)
+{
+       SEC_DESC *sd;
+       size_t sd_size;
+       TALLOC_CTX *ctx = p->mem_ctx;
+
+       ZERO_STRUCTP(sh1501);
+
+       sd = get_share_security(ctx, snum, &sd_size);
+
+       sh1501->sdb = make_sec_desc_buf(p->mem_ctx, sd_size, sd);
 }
 
 /*******************************************************************
  True if it ends in '$'.
  ********************************************************************/
 
-static BOOL is_admin_share(int snum)
+static BOOL is_hidden_share(int snum)
 {
-       pstring net_name;
+       const char *net_name = lp_servicename(snum);
 
-       pstrcpy(net_name, lp_servicename(snum));
-       return (net_name[strlen(net_name)] == '$') ? True : False;
+       return (net_name[strlen(net_name) - 1] == '$') ? True : False;
 }
 
 /*******************************************************************
@@ -443,7 +508,7 @@ static BOOL init_srv_share_info_ctr(pipes_struct *p, SRV_SHARE_INFO_CTR *ctr,
 
        /* Count the number of entries. */
        for (snum = 0; snum < num_services; snum++) {
-               if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_admin_share(snum)) )
+               if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) )
                        num_entries++;
        }
 
@@ -455,15 +520,37 @@ static BOOL init_srv_share_info_ctr(pipes_struct *p, SRV_SHARE_INFO_CTR *ctr,
                return True;
 
        switch (info_level) {
+       case 0:
+       {
+               SRV_SHARE_INFO_0 *info0 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_0, num_entries);
+               int i = 0;
+
+               if (!info0) {
+                       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_0(p, &info0[i++], snum);
+                       }
+               }
+
+               ctr->share.info0 = info0;
+               break;
+
+       }
+
        case 1:
        {
-               SRV_SHARE_INFO_1 *info1;
+               SRV_SHARE_INFO_1 *info1 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1, num_entries);
                int i = 0;
 
-               info1 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_1));
+               if (!info1) {
+                       return False;
+               }
 
                for (snum = *resume_hnd; snum < num_services; snum++) {
-                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_admin_share(snum)) ) {
+                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
                                init_srv_share_info_1(p, &info1[i++], snum);
                        }
                }
@@ -474,13 +561,15 @@ static BOOL init_srv_share_info_ctr(pipes_struct *p, SRV_SHARE_INFO_CTR *ctr,
 
        case 2:
        {
-               SRV_SHARE_INFO_2 *info2;
+               SRV_SHARE_INFO_2 *info2 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_2, num_entries);
                int i = 0;
 
-               info2 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_2));
+               if (!info2) {
+                       return False;
+               }
 
                for (snum = *resume_hnd; snum < num_services; snum++) {
-                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_admin_share(snum)) ) {
+                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
                                init_srv_share_info_2(p, &info2[i++], snum);
                        }
                }
@@ -489,15 +578,36 @@ static BOOL init_srv_share_info_ctr(pipes_struct *p, SRV_SHARE_INFO_CTR *ctr,
                break;
        }
 
+       case 501:
+       {
+               SRV_SHARE_INFO_501 *info501 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_501, num_entries);
+               int i = 0;
+       
+               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);
+                       }
+               }
+       
+               ctr->share.info501 = info501;
+               break;
+       }
+
        case 502:
        {
-               SRV_SHARE_INFO_502 *info502;
+               SRV_SHARE_INFO_502 *info502 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_502, num_entries);
                int i = 0;
 
-               info502 = talloc(ctx, num_entries * sizeof(SRV_SHARE_INFO_502));
+               if (!info502) {
+                       return False;
+               }
 
                for (snum = *resume_hnd; snum < num_services; snum++) {
-                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_admin_share(snum)) ) {
+                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) ) {
                                init_srv_share_info_502(p, &info502[i++], snum);
                        }
                }
@@ -506,6 +616,102 @@ static BOOL init_srv_share_info_ctr(pipes_struct *p, SRV_SHARE_INFO_CTR *ctr,
                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);
+                       }
+               }
+
+               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);
+                       }
+               }
+
+               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);
+                       }
+               }
+
+               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);
+                       }
+               }
+
+               ctr->share.info1007 = info1007;
+               break;
+       }
+
+       case 1501:
+       {
+               SRV_SHARE_INFO_1501 *info1501 = TALLOC_ARRAY(ctx, SRV_SHARE_INFO_1501, num_entries);
+               int i = 0;
+
+               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;
@@ -525,9 +731,9 @@ static void init_srv_r_net_share_enum(pipes_struct *p, SRV_R_NET_SHARE_ENUM *r_n
 
        if (init_srv_share_info_ctr(p, &r_n->ctr, info_level,
                                    &resume_hnd, &r_n->total_entries, all)) {
-               r_n->status = NT_STATUS_OK;
+               r_n->status = WERR_OK;
        } else {
-               r_n->status = NT_STATUS_INVALID_INFO_CLASS;
+               r_n->status = WERR_UNKNOWN_LEVEL;
        }
 
        init_enum_hnd(&r_n->enum_hnd, resume_hnd);
@@ -540,7 +746,7 @@ static void init_srv_r_net_share_enum(pipes_struct *p, SRV_R_NET_SHARE_ENUM *r_n
 static void init_srv_r_net_share_get_info(pipes_struct *p, SRV_R_NET_SHARE_GET_INFO *r_n,
                                  char *share_name, uint32 info_level)
 {
-       NTSTATUS status = NT_STATUS_OK;
+       WERROR status = WERR_OK;
        int snum;
 
        DEBUG(5,("init_srv_r_net_share_get_info: %d\n", __LINE__));
@@ -551,28 +757,50 @@ static void init_srv_r_net_share_get_info(pipes_struct *p, SRV_R_NET_SHARE_GET_I
 
        if (snum >= 0) {
                switch (info_level) {
+               case 0:
+                       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, snum);
                        break;
                case 2:
                        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, snum);
+                       break;
                case 502:
                        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, snum);
+                       break;
                case 1005:
-                       init_srv_share_info_1005(&r_n->info.share.info1005, snum);
+                       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, snum);
+                       break;
+               case 1007:
+                       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, snum);
                        break;
                default:
                        DEBUG(5,("init_srv_net_share_get_info: unsupported switch value %d\n", info_level));
-                       status = NT_STATUS_INVALID_INFO_CLASS;
+                       status = WERR_UNKNOWN_LEVEL;
                        break;
                }
        } else {
-               status = NT_STATUS_BAD_NETWORK_NAME;
+               status = WERR_INVALID_NAME;
        }
 
-       r_n->info.ptr_share_ctr = NT_STATUS_IS_OK(status) ? 1 : 0;
+       r_n->info.ptr_share_ctr = W_ERROR_IS_OK(status) ? 1 : 0;
        r_n->status = status;
 }
 
@@ -592,11 +820,13 @@ static void init_srv_sess_0_info(SESS_INFO_0 *se0, SESS_INFO_0_STR *str0, char *
 
 static void init_srv_sess_info_0(SRV_SESS_INFO_0 *ss0, uint32 *snum, uint32 *stot)
 {
+       struct sessionid *session_list;
        uint32 num_entries = 0;
-       (*stot) = 1;
+       (*stot) = list_sessions(&session_list);
 
        if (ss0 == NULL) {
                (*snum) = 0;
+               SAFE_FREE(session_list);
                return;
        }
 
@@ -605,7 +835,7 @@ static void init_srv_sess_info_0(SRV_SESS_INFO_0 *ss0, uint32 *snum, uint32 *sto
        if (snum) {
                for (; (*snum) < (*stot) && num_entries < MAX_SESS_ENTRIES; (*snum)++) {
                        init_srv_sess_0_info(&ss0->info_0[num_entries],
-                                                                &ss0->info_0_str[num_entries], "MACHINE");
+                                                                &ss0->info_0_str[num_entries], session_list[(*snum)].remote_machine);
 
                        /* move on to creating next session */
                        /* move on to creating next sess */
@@ -625,6 +855,7 @@ 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);
 }
 
 /*******************************************************************
@@ -647,11 +878,13 @@ static void init_srv_sess_1_info(SESS_INFO_1 *se1, SESS_INFO_1_STR *str1,
 
 static void init_srv_sess_info_1(SRV_SESS_INFO_1 *ss1, uint32 *snum, uint32 *stot)
 {
+       struct sessionid *session_list;
        uint32 num_entries = 0;
-       (*stot) = 1;
+       (*stot) = list_sessions(&session_list);
 
        if (ss1 == NULL) {
                (*snum) = 0;
+               SAFE_FREE(session_list);
                return;
        }
 
@@ -660,8 +893,10 @@ static void init_srv_sess_info_1(SRV_SESS_INFO_1 *ss1, uint32 *snum, uint32 *sto
        if (snum) {
                for (; (*snum) < (*stot) && num_entries < MAX_SESS_ENTRIES; (*snum)++) {
                        init_srv_sess_1_info(&ss1->info_1[num_entries],
-                                                                &ss1->info_1_str[num_entries],
-                                            "MACHINE", "dummy_user", 1, 10, 5, 0);
+                                            &ss1->info_1_str[num_entries],
+                                           session_list[*snum].remote_machine,
+                                            session_list[*snum].username,
+                                            1, 10, 5, 0);
 
                        /* move on to creating next session */
                        /* move on to creating next sess */
@@ -689,10 +924,10 @@ static void init_srv_sess_info_1(SRV_SESS_INFO_1 *ss1, uint32 *snum, uint32 *sto
  makes a SRV_R_NET_SESS_ENUM structure.
 ********************************************************************/
 
-static NTSTATUS init_srv_sess_info_ctr(SRV_SESS_INFO_CTR *ctr,
+static WERROR init_srv_sess_info_ctr(SRV_SESS_INFO_CTR *ctr,
                                int switch_value, uint32 *resume_hnd, uint32 *total_entries)
 {
-       NTSTATUS status = NT_STATUS_OK;
+       WERROR status = WERR_OK;
        DEBUG(5,("init_srv_sess_info_ctr: %d\n", __LINE__));
 
        ctr->switch_value = switch_value;
@@ -711,7 +946,7 @@ static NTSTATUS init_srv_sess_info_ctr(SRV_SESS_INFO_CTR *ctr,
                (*resume_hnd) = 0;
                (*total_entries) = 0;
                ctr->ptr_sess_ctr = 0;
-               status = NT_STATUS_INVALID_INFO_CLASS;
+               status = WERR_UNKNOWN_LEVEL;
                break;
        }
 
@@ -730,11 +965,11 @@ static void init_srv_r_net_sess_enum(SRV_R_NET_SESS_ENUM *r_n,
        r_n->sess_level  = sess_level;
 
        if (sess_level == -1)
-               r_n->status = NT_STATUS_INVALID_INFO_CLASS;
+               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);
 
-       if (NT_STATUS_IS_ERR(r_n->status))
+       if (!W_ERROR_IS_OK(r_n->status))
                resume_hnd = 0;
 
        init_enum_hnd(&r_n->enum_hnd, resume_hnd);
@@ -790,7 +1025,7 @@ static void init_srv_conn_info_0(SRV_CONN_INFO_0 *ss0, uint32 *snum, uint32 *sto
 static void init_srv_conn_1_info(CONN_INFO_1 *se1, CONN_INFO_1_STR *str1,
                                uint32 id, uint32 type,
                                uint32 num_opens, uint32 num_users, uint32 open_time,
-                               char *usr_name, char *net_name)
+                               const char *usr_name, const char *net_name)
 {
        init_srv_conn_info1(se1 , id, type, num_opens, num_users, open_time, usr_name, net_name);
        init_srv_conn_info1_str(str1, usr_name, net_name);
@@ -845,10 +1080,10 @@ static void init_srv_conn_info_1(SRV_CONN_INFO_1 *ss1, uint32 *snum, uint32 *sto
  makes a SRV_R_NET_CONN_ENUM structure.
 ********************************************************************/
 
-static NTSTATUS init_srv_conn_info_ctr(SRV_CONN_INFO_CTR *ctr,
+static WERROR init_srv_conn_info_ctr(SRV_CONN_INFO_CTR *ctr,
                                int switch_value, uint32 *resume_hnd, uint32 *total_entries)
 {
-       NTSTATUS status = NT_STATUS_OK;
+       WERROR status = WERR_OK;
        DEBUG(5,("init_srv_conn_info_ctr: %d\n", __LINE__));
 
        ctr->switch_value = switch_value;
@@ -867,7 +1102,7 @@ static NTSTATUS init_srv_conn_info_ctr(SRV_CONN_INFO_CTR *ctr,
                (*resume_hnd = 0);
                (*total_entries) = 0;
                ctr->ptr_conn_ctr = 0;
-               status = NT_STATUS_INVALID_INFO_CLASS;
+               status = WERR_UNKNOWN_LEVEL;
                break;
        }
 
@@ -885,85 +1120,55 @@ static void init_srv_r_net_conn_enum(SRV_R_NET_CONN_ENUM *r_n,
 
        r_n->conn_level  = conn_level;
        if (conn_level == -1)
-               r_n->status = NT_STATUS_INVALID_INFO_CLASS;
+               r_n->status = WERR_UNKNOWN_LEVEL;
        else
                r_n->status = init_srv_conn_info_ctr(r_n->ctr, switch_value, &resume_hnd, &r_n->total_entries);
 
-       if (NT_STATUS_IS_ERR(r_n->status))
+       if (!W_ERROR_IS_OK(r_n->status))
                resume_hnd = 0;
 
        init_enum_hnd(&r_n->enum_hnd, resume_hnd);
 }
 
-/*******************************************************************
- fill in a file info level 3 structure.
- ********************************************************************/
-
-static void init_srv_file_3_info(FILE_INFO_3 *fl3, FILE_INFO_3_STR *str3,
-                               uint32 fnum, uint32 perms, uint32 num_locks,
-                               char *path_name, char *user_name)
-{
-       init_srv_file_info3(fl3 , fnum, perms, num_locks, path_name, user_name);
-       init_srv_file_info3_str(str3, path_name, user_name);
-}
-
-/*******************************************************************
- fill in a file info level 3 structure.
- ********************************************************************/
-
-static void init_srv_file_info_3(SRV_FILE_INFO_3 *fl3, uint32 *fnum, uint32 *ftot)
-{
-       uint32 num_entries = 0;
-       (*ftot) = 1;
-
-       if (fl3 == NULL) {
-               (*fnum) = 0;
-               return;
-       }
-
-       DEBUG(5,("init_srv_file_3_fl3\n"));
-
-       for (; (*fnum) < (*ftot) && num_entries < MAX_FILE_ENTRIES; (*fnum)++) {
-               init_srv_file_3_info(&fl3->info_3[num_entries],
-                                        &fl3->info_3_str[num_entries],
-                                    (*fnum), 0x35, 0, "\\PIPE\\samr", "dummy user");
-
-               /* move on to creating next file */
-               num_entries++;
-       }
-
-       fl3->num_entries_read  = num_entries;
-       fl3->ptr_file_info     = num_entries > 0 ? 1 : 0;
-       fl3->num_entries_read2 = num_entries;
-       
-       if ((*fnum) >= (*ftot)) {
-               (*fnum) = 0;
-       }
-}
-
 /*******************************************************************
  makes a SRV_R_NET_FILE_ENUM structure.
 ********************************************************************/
 
-static NTSTATUS init_srv_file_info_ctr(SRV_FILE_INFO_CTR *ctr,
-                               int switch_value, uint32 *resume_hnd, uint32 *total_entries)  
+static WERROR init_srv_file_info_ctr(pipes_struct *p, SRV_FILE_INFO_CTR *ctr,
+                                    int switch_value, uint32 *resume_hnd, 
+                                    uint32 *total_entries)  
 {
-       NTSTATUS status = NT_STATUS_OK;
+       WERROR status = WERR_OK;
+       TALLOC_CTX *ctx = p->mem_ctx;
        DEBUG(5,("init_srv_file_info_ctr: %d\n", __LINE__));
+       *total_entries = 1; /* dummy entries only, for */
 
        ctr->switch_value = switch_value;
+       ctr->num_entries = *total_entries - *resume_hnd;
+       ctr->num_entries2 = ctr->num_entries;
 
        switch (switch_value) {
-       case 3:
-               init_srv_file_info_3(&ctr->file.info3, resume_hnd, total_entries);
-               ctr->ptr_file_ctr = 1;
+       case 3: {
+               int i;
+               if (*total_entries > 0) {
+                       ctr->ptr_entries = 1;
+                       ctr->file.info3 = TALLOC_ARRAY(ctx, SRV_FILE_INFO_3, ctr->num_entries);
+               }
+               for (i=0 ;i<ctr->num_entries;i++) {
+                       init_srv_file_info3(&ctr->file.info3[i].info_3, i+*resume_hnd, 0x35, 0, "\\PIPE\\samr", "dummy user");
+                       init_srv_file_info3_str(&ctr->file.info3[i].info_3_str,  "\\PIPE\\samr", "dummy user");
+                       
+               }
+               ctr->ptr_file_info = 1;
+               *resume_hnd = 0;
                break;
+       }
        default:
                DEBUG(5,("init_srv_file_info_ctr: unsupported switch value %d\n", switch_value));
                (*resume_hnd = 0);
                (*total_entries) = 0;
-               ctr->ptr_file_ctr = 0;
-               status = NT_STATUS_INVALID_INFO_CLASS;
+               ctr->ptr_entries = 0;
+               status = WERR_UNKNOWN_LEVEL;
                break;
        }
 
@@ -974,18 +1179,18 @@ static NTSTATUS init_srv_file_info_ctr(SRV_FILE_INFO_CTR *ctr,
  makes a SRV_R_NET_FILE_ENUM structure.
 ********************************************************************/
 
-static void init_srv_r_net_file_enum(SRV_R_NET_FILE_ENUM *r_n,
+static void init_srv_r_net_file_enum(pipes_struct *p, SRV_R_NET_FILE_ENUM *r_n,
                                uint32 resume_hnd, int file_level, int switch_value)  
 {
        DEBUG(5,("init_srv_r_net_file_enum: %d\n", __LINE__));
 
        r_n->file_level  = file_level;
        if (file_level == 0)
-               r_n->status = NT_STATUS_INVALID_INFO_CLASS;
+               r_n->status = WERR_UNKNOWN_LEVEL;
        else
-               r_n->status = init_srv_file_info_ctr(r_n->ctr, switch_value, &resume_hnd, &(r_n->total_entries));
+               r_n->status = init_srv_file_info_ctr(p, &r_n->ctr, switch_value, &resume_hnd, &(r_n->total_entries));
 
-       if (NT_STATUS_IS_ERR(r_n->status))
+       if (!W_ERROR_IS_OK(r_n->status))
                resume_hnd = 0;
 
        init_enum_hnd(&r_n->enum_hnd, resume_hnd);
@@ -995,23 +1200,33 @@ static void init_srv_r_net_file_enum(SRV_R_NET_FILE_ENUM *r_n,
 net server get info
 ********************************************************************/
 
-NTSTATUS _srv_net_srv_get_info(pipes_struct *p, SRV_Q_NET_SRV_GET_INFO *q_u, SRV_R_NET_SRV_GET_INFO *r_u)
+WERROR _srv_net_srv_get_info(pipes_struct *p, SRV_Q_NET_SRV_GET_INFO *q_u, SRV_R_NET_SRV_GET_INFO *r_u)
 {
-       NTSTATUS status = NT_STATUS_OK;
-       SRV_INFO_CTR *ctr = (SRV_INFO_CTR *)talloc(p->mem_ctx, sizeof(SRV_INFO_CTR));
+       WERROR status = WERR_OK;
+       SRV_INFO_CTR *ctr = TALLOC_P(p->mem_ctx, SRV_INFO_CTR);
 
        if (!ctr)
-               return NT_STATUS_NO_MEMORY;
+               return WERR_NOMEM;
 
        ZERO_STRUCTP(ctr);
 
        DEBUG(5,("srv_net_srv_get_info: %d\n", __LINE__));
 
+       if (!pipe_access_check(p)) {
+               DEBUG(3, ("access denied to srv_net_srv_get_info\n"));
+               return WERR_ACCESS_DENIED;
+       }
+
        switch (q_u->switch_value) {
+
+               /* Technically level 102 should only be available to
+                  Administrators but there isn't anything super-secret
+                  here, as most of it is made up. */
+
        case 102:
                init_srv_info_102(&ctr->srv.sv102,
-                                 500, global_myname, 
-                                               string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH),
+                                 500, global_myname()
+                                 string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH),
                                  lp_major_announce_version(), lp_minor_announce_version(),
                                  lp_default_server_announce(),
                                  0xffffffff, /* users */
@@ -1024,16 +1239,16 @@ NTSTATUS _srv_net_srv_get_info(pipes_struct *p, SRV_Q_NET_SRV_GET_INFO *q_u, SRV
                break;
        case 101:
                init_srv_info_101(&ctr->srv.sv101,
-                                 500, global_myname,
+                                 500, global_myname(),
                                  lp_major_announce_version(), lp_minor_announce_version(),
                                  lp_default_server_announce(),
                                  string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH));
                break;
        case 100:
-               init_srv_info_100(&ctr->srv.sv100, 500, global_myname);
+               init_srv_info_100(&ctr->srv.sv100, 500, global_myname());
                break;
        default:
-               status = NT_STATUS_INVALID_INFO_CLASS;
+               status = WERR_UNKNOWN_LEVEL;
                break;
        }
 
@@ -1049,12 +1264,9 @@ NTSTATUS _srv_net_srv_get_info(pipes_struct *p, SRV_Q_NET_SRV_GET_INFO *q_u, SRV
 net server set info
 ********************************************************************/
 
-NTSTATUS _srv_net_srv_set_info(pipes_struct *p, SRV_Q_NET_SRV_SET_INFO *q_u, SRV_R_NET_SRV_SET_INFO *r_u)
+WERROR _srv_net_srv_set_info(pipes_struct *p, SRV_Q_NET_SRV_SET_INFO *q_u, SRV_R_NET_SRV_SET_INFO *r_u)
 {
-       /* NT gives "Windows NT error 0xc00000022" if we return
-          NT_STATUS_ACCESS_DENIED here so just pretend everything is OK. */
-
-       NTSTATUS status = NT_STATUS_OK;
+       WERROR status = WERR_OK;
 
        DEBUG(5,("srv_net_srv_set_info: %d\n", __LINE__));
 
@@ -1071,21 +1283,15 @@ NTSTATUS _srv_net_srv_set_info(pipes_struct *p, SRV_Q_NET_SRV_SET_INFO *q_u, SRV
 net file enum
 ********************************************************************/
 
-NTSTATUS _srv_net_file_enum(pipes_struct *p, SRV_Q_NET_FILE_ENUM *q_u, SRV_R_NET_FILE_ENUM *r_u)
+WERROR _srv_net_file_enum(pipes_struct *p, SRV_Q_NET_FILE_ENUM *q_u, SRV_R_NET_FILE_ENUM *r_u)
 {
-       r_u->ctr = (SRV_FILE_INFO_CTR *)talloc(p->mem_ctx, sizeof(SRV_FILE_INFO_CTR));
-       if (!r_u->ctr)
-               return NT_STATUS_NO_MEMORY;
-
-       ZERO_STRUCTP(r_u->ctr);
-
        DEBUG(5,("srv_net_file_enum: %d\n", __LINE__));
 
        /* set up the */
-       init_srv_r_net_file_enum(r_u,
+       init_srv_r_net_file_enum(p, r_u,
                                get_enum_hnd(&q_u->enum_hnd),
                                q_u->file_level,
-                               q_u->ctr->switch_value);
+                               q_u->ctr.switch_value);
 
        DEBUG(5,("srv_net_file_enum: %d\n", __LINE__));
 
@@ -1096,13 +1302,13 @@ NTSTATUS _srv_net_file_enum(pipes_struct *p, SRV_Q_NET_FILE_ENUM *q_u, SRV_R_NET
 net conn enum
 ********************************************************************/
 
-NTSTATUS _srv_net_conn_enum(pipes_struct *p, SRV_Q_NET_CONN_ENUM *q_u, SRV_R_NET_CONN_ENUM *r_u)
+WERROR _srv_net_conn_enum(pipes_struct *p, SRV_Q_NET_CONN_ENUM *q_u, SRV_R_NET_CONN_ENUM *r_u)
 {
        DEBUG(5,("srv_net_conn_enum: %d\n", __LINE__));
 
-       r_u->ctr = (SRV_CONN_INFO_CTR *)talloc(p->mem_ctx, sizeof(SRV_CONN_INFO_CTR));
+       r_u->ctr = TALLOC_P(p->mem_ctx, SRV_CONN_INFO_CTR);
        if (!r_u->ctr)
-               return NT_STATUS_NO_MEMORY;
+               return WERR_NOMEM;
 
        ZERO_STRUCTP(r_u->ctr);
 
@@ -1121,13 +1327,13 @@ NTSTATUS _srv_net_conn_enum(pipes_struct *p, SRV_Q_NET_CONN_ENUM *q_u, SRV_R_NET
 net sess enum
 ********************************************************************/
 
-NTSTATUS _srv_net_sess_enum(pipes_struct *p, SRV_Q_NET_SESS_ENUM *q_u, SRV_R_NET_SESS_ENUM *r_u)
+WERROR _srv_net_sess_enum(pipes_struct *p, SRV_Q_NET_SESS_ENUM *q_u, SRV_R_NET_SESS_ENUM *r_u)
 {
        DEBUG(5,("_srv_net_sess_enum: %d\n", __LINE__));
 
-       r_u->ctr = (SRV_SESS_INFO_CTR *)talloc(p->mem_ctx, sizeof(SRV_SESS_INFO_CTR));
+       r_u->ctr = TALLOC_P(p->mem_ctx, SRV_SESS_INFO_CTR);
        if (!r_u->ctr)
-               return NT_STATUS_NO_MEMORY;
+               return WERR_NOMEM;
 
        ZERO_STRUCTP(r_u->ctr);
 
@@ -1146,10 +1352,15 @@ NTSTATUS _srv_net_sess_enum(pipes_struct *p, SRV_Q_NET_SESS_ENUM *q_u, SRV_R_NET
  Net share enum all.
 ********************************************************************/
 
-NTSTATUS _srv_net_share_enum_all(pipes_struct *p, SRV_Q_NET_SHARE_ENUM *q_u, SRV_R_NET_SHARE_ENUM *r_u)
+WERROR _srv_net_share_enum_all(pipes_struct *p, SRV_Q_NET_SHARE_ENUM *q_u, SRV_R_NET_SHARE_ENUM *r_u)
 {
        DEBUG(5,("_srv_net_share_enum: %d\n", __LINE__));
 
+       if (!pipe_access_check(p)) {
+               DEBUG(3, ("access denied to srv_net_share_enum_all\n"));
+               return WERR_ACCESS_DENIED;
+       }
+
        /* Create the list of shares for the response. */
        init_srv_r_net_share_enum(p, r_u,
                                q_u->ctr.info_level,
@@ -1164,14 +1375,19 @@ NTSTATUS _srv_net_share_enum_all(pipes_struct *p, SRV_Q_NET_SHARE_ENUM *q_u, SRV
  Net share enum.
 ********************************************************************/
 
-NTSTATUS _srv_net_share_enum(pipes_struct *p, SRV_Q_NET_SHARE_ENUM *q_u, SRV_R_NET_SHARE_ENUM *r_u)
+WERROR _srv_net_share_enum(pipes_struct *p, SRV_Q_NET_SHARE_ENUM *q_u, SRV_R_NET_SHARE_ENUM *r_u)
 {
        DEBUG(5,("_srv_net_share_enum: %d\n", __LINE__));
 
+       if (!pipe_access_check(p)) {
+               DEBUG(3, ("access denied to srv_net_share_enum\n"));
+               return WERR_ACCESS_DENIED;
+       }
+
        /* Create the list of shares for the response. */
        init_srv_r_net_share_enum(p, r_u,
-                               q_u->ctr.info_level,
-                               get_enum_hnd(&q_u->enum_hnd), False);
+                                 q_u->ctr.info_level,
+                                 get_enum_hnd(&q_u->enum_hnd), False);
 
        DEBUG(5,("_srv_net_share_enum: %d\n", __LINE__));
 
@@ -1182,7 +1398,7 @@ NTSTATUS _srv_net_share_enum(pipes_struct *p, SRV_Q_NET_SHARE_ENUM *q_u, SRV_R_N
  Net share get info.
 ********************************************************************/
 
-NTSTATUS _srv_net_share_get_info(pipes_struct *p, SRV_Q_NET_SHARE_GET_INFO *q_u, SRV_R_NET_SHARE_GET_INFO *r_u)
+WERROR _srv_net_share_get_info(pipes_struct *p, SRV_Q_NET_SHARE_GET_INFO *q_u, SRV_R_NET_SHARE_GET_INFO *r_u)
 {
        fstring share_name;
 
@@ -1203,10 +1419,7 @@ NTSTATUS _srv_net_share_get_info(pipes_struct *p, SRV_Q_NET_SHARE_GET_INFO *q_u,
 
 static char *valid_share_pathname(char *dos_pathname)
 {
-       pstring saved_pathname;
-       pstring unix_pathname;
        char *ptr;
-       int ret;
 
        /* Convert any '\' paths to '/' */
        unix_format(dos_pathname);
@@ -1221,28 +1434,14 @@ static char *valid_share_pathname(char *dos_pathname)
        if (*ptr != '/')
                return NULL;
 
-       /* Can we cd to it ? */
-
-       /* First save our current directory. */
-       if (getcwd(saved_pathname, sizeof(saved_pathname)) == NULL)
-               return False;
-
-       pstrcpy(unix_pathname, ptr);
-       
-       ret = chdir(unix_pathname);
-
-       /* We *MUST* be able to chdir back. Abort if we can't. */
-       if (chdir(saved_pathname) == -1)
-               smb_panic("valid_share_pathname: Unable to restore current directory.\n");
-
-       return (ret != -1) ? ptr : NULL;
+       return ptr;
 }
 
 /*******************************************************************
  Net share set info. Modify share details.
 ********************************************************************/
 
-NTSTATUS _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u, SRV_R_NET_SHARE_SET_INFO *r_u)
+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)
 {
        struct current_user user;
        pstring command;
@@ -1252,54 +1451,92 @@ NTSTATUS _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u,
        int type;
        int snum;
        int ret;
-       char *ptr;
+       char *path;
        SEC_DESC *psd = NULL;
+       SE_PRIV se_diskop = SE_DISK_OPERATOR;
+       BOOL is_disk_op;
 
        DEBUG(5,("_srv_net_share_set_info: %d\n", __LINE__));
 
        unistr2_to_ascii(share_name, &q_u->uni_share_name, sizeof(share_name));
 
-       r_u->switch_value = 0;
+       r_u->parm_error = 0;
 
        if (strequal(share_name,"IPC$") || strequal(share_name,"ADMIN$") || strequal(share_name,"global"))
-               return NT_STATUS_ACCESS_DENIED;
+               return WERR_ACCESS_DENIED;
 
        snum = find_service(share_name);
 
        /* Does this share exist ? */
        if (snum < 0)
-               return NT_STATUS_BAD_NETWORK_NAME;
+               return WERR_INVALID_NAME;
 
        /* No change to printer shares. */
        if (lp_print_ok(snum))
-               return NT_STATUS_ACCESS_DENIED;
+               return WERR_ACCESS_DENIED;
 
        get_current_user(&user,p);
 
-       if (user.uid != 0)
-               return NT_STATUS_ACCESS_DENIED;
+       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 ( user.uid != sec_initial_uid() && !is_disk_op )
+               return WERR_ACCESS_DENIED;
 
        switch (q_u->info_level) {
        case 1:
-               /* Not enough info in a level 1 to do anything. */
-               return NT_STATUS_ACCESS_DENIED;
+               pstrcpy(pathname, lp_pathname(snum));
+               unistr2_to_ascii(comment, &q_u->info.share.info2.info_2_str.uni_remark, sizeof(comment));
+               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(share_name));
-               unistr2_to_ascii(pathname, &q_u->info.share.info2.info_2_str.uni_path, sizeof(share_name));
+               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));
                type = q_u->info.share.info2.info_2.type;
                psd = NULL;
                break;
+#if 0
+               /* not supported on set but here for completeness */
+       case 501:
+               unistr2_to_ascii(comment, &q_u->info.share.info501.info_501_str.uni_remark, sizeof(comment));
+               type = q_u->info.share.info501.info_501.type;
+               psd = NULL;
+               break;
+#endif
        case 502:
-               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));
+               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));
                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));
+               type = STYPE_DISKTREE;
+               break;
        case 1005:
-               return NT_STATUS_ACCESS_DENIED;
+                /* XP re-sets the csc policy even if it wasn't changed by the
+                  user, so we must compare it to see if it's what is set in
+                  smb.conf, so that we can contine other ops like setting
+                  ACLs on a share */
+               if (((q_u->info.share.info1005.share_info_flags &
+                     SHARE_1005_CSC_POLICY_MASK) >>
+                    SHARE_1005_CSC_POLICY_SHIFT) == lp_csc_policy(snum))
+                       return WERR_OK;
+               else {
+                       DEBUG(3, ("_srv_net_share_set_info: client is trying to change csc policy from the network; must be done with smb.conf\n"));
+                       return WERR_ACCESS_DENIED;
+               }
+               break;
+       case 1006:
+       case 1007:
+               return WERR_ACCESS_DENIED;
+               break;
        case 1501:
-               fstrcpy(pathname, lp_pathname(snum));
+               pstrcpy(pathname, lp_pathname(snum));
                fstrcpy(comment, lp_comment(snum));
                psd = q_u->info.share.info1501.sdb->sec;
                map_generic_share_sd_bits(psd);
@@ -1307,43 +1544,56 @@ NTSTATUS _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u,
                break;
        default:
                DEBUG(5,("_srv_net_share_set_info: unsupported switch value %d\n", q_u->info_level));
-               return NT_STATUS_INVALID_INFO_CLASS;
+               return WERR_UNKNOWN_LEVEL;
        }
 
        /* We can only modify disk shares. */
        if (type != STYPE_DISKTREE)
-               return NT_STATUS_ACCESS_DENIED;
+               return WERR_ACCESS_DENIED;
                
        /* Check if the pathname is valid. */
-       if (!(ptr = valid_share_pathname( pathname )))
-               return NT_STATUS_OBJECT_PATH_INVALID;
+       if (!(path = valid_share_pathname( pathname )))
+               return WERR_OBJECT_PATH_INVALID;
 
        /* Ensure share name, pathname and comment don't contain '"' characters. */
        string_replace(share_name, '"', ' ');
-       string_replace(ptr, '"', ' ');
+       string_replace(path, '"', ' ');
        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(ptr, lp_pathname(snum)) || strcmp(comment, lp_comment(snum)) ) {
-               if (!lp_change_share_cmd() || !*lp_change_share_cmd())
-                       return NT_STATUS_ACCESS_DENIED;
+       
+       if (strcmp(path, lp_pathname(snum)) || strcmp(comment, lp_comment(snum)) ) 
+       {
+               if (!lp_change_share_cmd() || !*lp_change_share_cmd()) 
+                       return WERR_ACCESS_DENIED;
 
                slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\"",
-                               lp_change_share_cmd(), CONFIGFILE, share_name, ptr, comment);
+                               lp_change_share_cmd(), dyn_CONFIGFILE, share_name, path, comment);
 
                DEBUG(10,("_srv_net_share_set_info: Running [%s]\n", command ));
-               if ((ret = smbrun(command, NULL)) != 0) {
-                       DEBUG(0,("_srv_net_share_set_info: Running [%s] returned (%d)\n", command, ret ));
-                       return NT_STATUS_ACCESS_DENIED;
-               }
+                               
+               /********* BEGIN SeDiskOperatorPrivilege BLOCK *********/
+       
+               if ( is_disk_op )
+                       become_root();
+                       
+               ret = smbrun(command, NULL);
+               
+               if ( is_disk_op )
+                       unbecome_root();
+                       
+               /********* END SeDiskOperatorPrivilege BLOCK *********/
 
-               /* Tell everyone we updated smb.conf. */
-               message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False);
+               DEBUG(3,("_srv_net_share_set_info: Running [%s] returned (%d)\n", command, ret ));              
+       
+               if ( ret != 0 )
+                       return WERR_ACCESS_DENIED;
 
+               /* Tell everyone we updated smb.conf. */
+               message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL);
        } else {
                DEBUG(10,("_srv_net_share_set_info: No change to share name (%s)\n", share_name ));
        }
@@ -1361,17 +1611,17 @@ NTSTATUS _srv_net_share_set_info(pipes_struct *p, SRV_Q_NET_SHARE_SET_INFO *q_u,
                                        share_name ));
                }
        }
-
+                       
        DEBUG(5,("_srv_net_share_set_info: %d\n", __LINE__));
 
-       return NT_STATUS_OK;
+       return WERR_OK;
 }
 
 /*******************************************************************
  Net share add. Call 'add_share_command "sharename" "pathname" "comment" "read only = xxx"'
 ********************************************************************/
 
-NTSTATUS _srv_net_share_add(pipes_struct *p, SRV_Q_NET_SHARE_ADD *q_u, SRV_R_NET_SHARE_ADD *r_u)
+WERROR _srv_net_share_add(pipes_struct *p, SRV_Q_NET_SHARE_ADD *q_u, SRV_R_NET_SHARE_ADD *r_u)
 {
        struct current_user user;
        pstring command;
@@ -1381,35 +1631,43 @@ NTSTATUS _srv_net_share_add(pipes_struct *p, SRV_Q_NET_SHARE_ADD *q_u, SRV_R_NET
        int type;
        int snum;
        int ret;
-       char *ptr;
+       char *path;
        SEC_DESC *psd = NULL;
+       SE_PRIV se_diskop = SE_DISK_OPERATOR;
+       BOOL is_disk_op;
 
        DEBUG(5,("_srv_net_share_add: %d\n", __LINE__));
 
-       r_u->switch_value = 0;
+       r_u->parm_error = 0;
 
        get_current_user(&user,p);
 
-       if (user.uid != 0) {
-               DEBUG(10,("_srv_net_share_add: uid != 0. Access denied.\n"));
-               return NT_STATUS_ACCESS_DENIED;
-       }
+       is_disk_op = user_has_privileges( p->pipe_user.nt_user_token, &se_diskop );
+
+       if (user.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 NT_STATUS_ACCESS_DENIED;
+               return WERR_ACCESS_DENIED;
        }
-
+       
        switch (q_u->info_level) {
+       case 0:
+               /* No path. Not enough info in a level 0 to do anything. */
+               return WERR_ACCESS_DENIED;
        case 1:
                /* Not enough info in a level 1 to do anything. */
-               return NT_STATUS_ACCESS_DENIED;
+               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));
                type = q_u->info.share.info2.info_2.type;
                break;
+       case 501:
+               /* 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));
@@ -1418,53 +1676,75 @@ NTSTATUS _srv_net_share_add(pipes_struct *p, SRV_Q_NET_SHARE_ADD *q_u, SRV_R_NET
                psd = q_u->info.share.info502.info_502_str.sd;
                map_generic_share_sd_bits(psd);
                break;
+
+               /* none of the following contain share names.  NetShareAdd does not have a separate parameter for the share name */ 
+
+       case 1004:
        case 1005:
+       case 1006:
+       case 1007:
+               return WERR_ACCESS_DENIED;
+               break;
+       case 1501:
                /* DFS only level. */
-               return NT_STATUS_ACCESS_DENIED;
+               return WERR_ACCESS_DENIED;
        default:
                DEBUG(5,("_srv_net_share_add: unsupported switch value %d\n", q_u->info_level));
-               return NT_STATUS_INVALID_INFO_CLASS;
+               return WERR_UNKNOWN_LEVEL;
        }
 
        if (strequal(share_name,"IPC$") || strequal(share_name,"ADMIN$") || strequal(share_name,"global"))
-               return NT_STATUS_ACCESS_DENIED;
+               return WERR_ACCESS_DENIED;
 
        snum = find_service(share_name);
 
        /* Share already exists. */
        if (snum >= 0)
-               return NT_STATUS_OBJECT_NAME_COLLISION;
+               return WERR_ALREADY_EXISTS;
 
        /* We can only add disk shares. */
        if (type != STYPE_DISKTREE)
-               return NT_STATUS_ACCESS_DENIED;
+               return WERR_ACCESS_DENIED;
                
        /* Check if the pathname is valid. */
-       if (!(ptr = valid_share_pathname( pathname )))
-               return NT_STATUS_OBJECT_PATH_INVALID;
+       if (!(path = valid_share_pathname( pathname )))
+               return WERR_OBJECT_PATH_INVALID;
 
        /* Ensure share name, pathname and comment don't contain '"' characters. */
        string_replace(share_name, '"', ' ');
-       string_replace(ptr, '"', ' ');
+       string_replace(path, '"', ' ');
        string_replace(comment, '"', ' ');
 
        slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\" \"%s\" \"%s\"",
-                       lp_add_share_cmd(), CONFIGFILE, share_name, ptr, comment);
-
+                       lp_add_share_cmd(), dyn_CONFIGFILE, share_name, path, comment);
+                       
        DEBUG(10,("_srv_net_share_add: Running [%s]\n", command ));
-       if ((ret = smbrun(command, NULL)) != 0) {
-               DEBUG(0,("_srv_net_share_add: Running [%s] returned (%d)\n", command, ret ));
-               return NT_STATUS_ACCESS_DENIED;
-       }
+       
+       /********* BEGIN SeDiskOperatorPrivilege BLOCK *********/
+       
+       if ( is_disk_op )
+               become_root();
 
-       if (psd) {
-               if (!set_share_security(p->mem_ctx, share_name, psd))
-                       DEBUG(0,("_srv_net_share_add: Failed to add security info to share %s.\n",
-                               share_name ));
-       }
+       ret = smbrun(command, NULL);
+
+       if ( is_disk_op )
+               unbecome_root();
+               
+       /********* END SeDiskOperatorPrivilege BLOCK *********/
+
+       DEBUG(3,("_srv_net_share_add: Running [%s] returned (%d)\n", command, ret ));
+
+       if ( ret != 0 )
+               return WERR_ACCESS_DENIED;
 
        /* Tell everyone we updated smb.conf. */
-       message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False);
+       message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL);
+
+       if (psd) {
+               if (!set_share_security(p->mem_ctx, share_name, psd)) {
+                       DEBUG(0,("_srv_net_share_add: Failed to add security info to share %s.\n", share_name ));
+               }
+       }
 
        /*
         * We don't call reload_services() here, the message will
@@ -1474,7 +1754,7 @@ NTSTATUS _srv_net_share_add(pipes_struct *p, SRV_Q_NET_SHARE_ADD *q_u, SRV_R_NET
 
        DEBUG(5,("_srv_net_share_add: %d\n", __LINE__));
 
-       return NT_STATUS_OK;
+       return WERR_OK;
 }
 
 /*******************************************************************
@@ -1482,77 +1762,101 @@ NTSTATUS _srv_net_share_add(pipes_struct *p, SRV_Q_NET_SHARE_ADD *q_u, SRV_R_NET
  a parameter.
 ********************************************************************/
 
-NTSTATUS _srv_net_share_del(pipes_struct *p, SRV_Q_NET_SHARE_DEL *q_u, SRV_R_NET_SHARE_DEL *r_u)
+WERROR _srv_net_share_del(pipes_struct *p, SRV_Q_NET_SHARE_DEL *q_u, SRV_R_NET_SHARE_DEL *r_u)
 {
        struct current_user user;
        pstring command;
        fstring share_name;
        int ret;
        int snum;
+       SE_PRIV se_diskop = SE_DISK_OPERATOR;
+       BOOL is_disk_op;
 
        DEBUG(5,("_srv_net_share_del: %d\n", __LINE__));
 
        unistr2_to_ascii(share_name, &q_u->uni_share_name, sizeof(share_name));
 
        if (strequal(share_name,"IPC$") || strequal(share_name,"ADMIN$") || strequal(share_name,"global"))
-               return NT_STATUS_ACCESS_DENIED;
+               return WERR_ACCESS_DENIED;
 
        snum = find_service(share_name);
 
        if (snum < 0)
-               return NT_STATUS_BAD_NETWORK_NAME;
+               return WERR_NO_SUCH_SHARE;
 
        /* No change to printer shares. */
        if (lp_print_ok(snum))
-               return NT_STATUS_ACCESS_DENIED;
+               return WERR_ACCESS_DENIED;
 
        get_current_user(&user,p);
 
-       if (user.uid != 0)
-               return NT_STATUS_ACCESS_DENIED;
+       is_disk_op = user_has_privileges( p->pipe_user.nt_user_token, &se_diskop );
 
-       if (!lp_delete_share_cmd() || !*lp_delete_share_cmd())
-               return NT_STATUS_ACCESS_DENIED;
+       if (user.uid != sec_initial_uid()  && !is_disk_op ) 
+               return WERR_ACCESS_DENIED;
 
+       if (!lp_delete_share_cmd() || !*lp_delete_share_cmd())
+               return WERR_ACCESS_DENIED;
+               
        slprintf(command, sizeof(command)-1, "%s \"%s\" \"%s\"",
-                       lp_delete_share_cmd(), CONFIGFILE, lp_servicename(snum));
+                       lp_delete_share_cmd(), dyn_CONFIGFILE, lp_servicename(snum));
 
        DEBUG(10,("_srv_net_share_del: Running [%s]\n", command ));
-       if ((ret = smbrun(command, NULL)) != 0) {
-               DEBUG(0,("_srv_net_share_del: Running [%s] returned (%d)\n", command, ret ));
-               return NT_STATUS_ACCESS_DENIED;
-       }
 
-       /* Delete the SD in the database. */
-       delete_share_security(snum);
+       /********* BEGIN SeDiskOperatorPrivilege BLOCK *********/
+       
+       if ( is_disk_op )
+               become_root();
+
+       ret = smbrun(command, NULL);
+
+       if ( is_disk_op )
+               unbecome_root();
+               
+       /********* END SeDiskOperatorPrivilege BLOCK *********/
+
+       DEBUG(3,("_srv_net_share_del: Running [%s] returned (%d)\n", command, ret ));
+
+       if ( ret != 0 )
+               return WERR_ACCESS_DENIED;
 
        /* Tell everyone we updated smb.conf. */
-       message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False);
+       message_send_all(conn_tdb_ctx(), MSG_SMB_CONF_UPDATED, NULL, 0, False, NULL);
+
+       /* Delete the SD in the database. */
+       delete_share_security(snum);
 
        lp_killservice(snum);
 
-       return NT_STATUS_OK;
+       return WERR_OK;
+}
+
+WERROR _srv_net_share_del_sticky(pipes_struct *p, SRV_Q_NET_SHARE_DEL *q_u, SRV_R_NET_SHARE_DEL *r_u)
+{
+       DEBUG(5,("_srv_net_share_del_stick: %d\n", __LINE__));
+
+       return _srv_net_share_del(p, q_u, r_u);
 }
 
 /*******************************************************************
 time of day
 ********************************************************************/
 
-NTSTATUS _srv_net_remote_tod(pipes_struct *p, SRV_Q_NET_REMOTE_TOD *q_u, SRV_R_NET_REMOTE_TOD *r_u)
+WERROR _srv_net_remote_tod(pipes_struct *p, SRV_Q_NET_REMOTE_TOD *q_u, SRV_R_NET_REMOTE_TOD *r_u)
 {
        TIME_OF_DAY_INFO *tod;
        struct tm *t;
        time_t unixdate = time(NULL);
 
-       tod = (TIME_OF_DAY_INFO *)talloc(p->mem_ctx, sizeof(TIME_OF_DAY_INFO));
+       tod = TALLOC_P(p->mem_ctx, TIME_OF_DAY_INFO);
        if (!tod)
-               return NT_STATUS_NO_MEMORY;
+               return WERR_NOMEM;
 
        ZERO_STRUCTP(tod);
  
        r_u->tod = tod;
        r_u->ptr_srv_tod = 0x1;
-       r_u->status = NT_STATUS_OK;
+       r_u->status = WERR_OK;
 
        DEBUG(5,("_srv_net_remote_tod: %d\n", __LINE__));
 
@@ -1582,12 +1886,12 @@ NTSTATUS _srv_net_remote_tod(pipes_struct *p, SRV_Q_NET_REMOTE_TOD *q_u, SRV_R_N
  Win9x NT tools get security descriptor.
 ***********************************************************************************/
 
-NTSTATUS _srv_net_file_query_secdesc(pipes_struct *p, SRV_Q_NET_FILE_QUERY_SECDESC *q_u,
+WERROR _srv_net_file_query_secdesc(pipes_struct *p, SRV_Q_NET_FILE_QUERY_SECDESC *q_u,
                        SRV_R_NET_FILE_QUERY_SECDESC *r_u)
 {
        SEC_DESC *psd = NULL;
        size_t sd_size;
-       fstring null_pw;
+       DATA_BLOB null_pw;
        pstring filename;
        pstring qualname;
        files_struct *fsp = NULL;
@@ -1598,58 +1902,72 @@ NTSTATUS _srv_net_file_query_secdesc(pipes_struct *p, SRV_Q_NET_FILE_QUERY_SECDE
        NTSTATUS nt_status;
        struct current_user user;
        connection_struct *conn = NULL;
-       BOOL became_user = False;
+       BOOL became_user = False; 
 
        ZERO_STRUCT(st);
 
-       r_u->status = NT_STATUS_OK;
+       r_u->status = WERR_OK;
 
        unistr2_to_ascii(qualname, &q_u->uni_qual_name, sizeof(qualname));
 
        /* Null password is ok - we are already an authenticated user... */
-       *null_pw = '\0';
+       null_pw = data_blob(NULL, 0);
 
-       get_current_user(&user, p);     
-       
-       conn = make_connection(qualname, null_pw, 0, "A:", user.vuid, &nt_status);
+       get_current_user(&user, p);
+
+       become_root();
+       conn = make_connection(qualname, null_pw, "A:", user.vuid, &nt_status);
+       unbecome_root();
 
        if (conn == NULL) {
                DEBUG(3,("_srv_net_file_query_secdesc: Unable to connect to %s\n", qualname));
-               r_u->status = nt_status;
+               r_u->status = ntstatus_to_werror(nt_status);
                goto error_exit;
        }
 
        if (!become_user(conn, conn->vuid)) {
                DEBUG(0,("_srv_net_file_query_secdesc: Can't become connected user!\n"));
-               r_u->status = NT_STATUS_ACCESS_DENIED;
+               r_u->status = WERR_ACCESS_DENIED;
                goto error_exit;
        }
        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));
+               r_u->status = WERR_ACCESS_DENIED;
+               goto error_exit;
+       }
 
-       fsp = open_file_shared(conn, filename, &st, SET_OPEN_MODE(DOS_OPEN_RDONLY),
-                              (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN), 0, 0, &access_mode, &action);
+       if (!check_name(filename,conn)) {
+               DEBUG(3,("_srv_net_file_query_secdesc: can't access %s\n", filename));
+               r_u->status = WERR_ACCESS_DENIED;
+               goto error_exit;
+       }
+
+       fsp = open_file_shared(conn, filename, &st, SET_DENY_MODE(DENY_NONE)|SET_OPEN_MODE(DOS_OPEN_RDONLY),
+                               (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN), FILE_ATTRIBUTE_NORMAL, INTERNAL_OPEN_ONLY,
+                               &access_mode, &action);
 
        if (!fsp) {
                /* Perhaps it is a directory */
                if (errno == EISDIR)
-                       fsp = open_directory(conn, filename, &st,
-                                            (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN), 0, &action);
+                       fsp = open_directory(conn, filename, &st,FILE_READ_ATTRIBUTES,0,
+                                       (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN), &action);
 
                if (!fsp) {
                        DEBUG(3,("_srv_net_file_query_secdesc: Unable to open file %s\n", filename));
-                       r_u->status = NT_STATUS_ACCESS_DENIED;
+                       r_u->status = WERR_ACCESS_DENIED;
                        goto error_exit;
                }
        }
 
-       sd_size = conn->vfs_ops.get_nt_acl(fsp, fsp->fsp_name, &psd);
+       sd_size = SMB_VFS_GET_NT_ACL(fsp, fsp->fsp_name, (OWNER_SECURITY_INFORMATION|GROUP_SECURITY_INFORMATION|DACL_SECURITY_INFORMATION), &psd);
 
        if (sd_size == 0) {
                DEBUG(3,("_srv_net_file_query_secdesc: Unable to get NT ACL for file %s\n", filename));
-               r_u->status = NT_STATUS_ACCESS_DENIED;
+               r_u->status = WERR_ACCESS_DENIED;
                goto error_exit;
        }
 
@@ -1662,11 +1980,11 @@ NTSTATUS _srv_net_file_query_secdesc(pipes_struct *p, SRV_Q_NET_FILE_QUERY_SECDE
        psd->dacl->revision = (uint16) NT4_ACL_REVISION;
 
        close_file(fsp, True);
-
+       unbecome_user();
        close_cnum(conn, user.vuid);
        return r_u->status;
 
-  error_exit:
+error_exit:
 
        if(fsp) {
                close_file(fsp, True);
@@ -1685,13 +2003,13 @@ NTSTATUS _srv_net_file_query_secdesc(pipes_struct *p, SRV_Q_NET_FILE_QUERY_SECDE
  Win9x NT tools set security descriptor.
 ***********************************************************************************/
 
-NTSTATUS _srv_net_file_set_secdesc(pipes_struct *p, SRV_Q_NET_FILE_SET_SECDESC *q_u,
+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;
-       fstring null_pw;
        pstring filename;
        pstring qualname;
+       DATA_BLOB null_pw;
        files_struct *fsp = NULL;
        SMB_STRUCT_STAT st;
        BOOL bad_path;
@@ -1704,54 +2022,69 @@ NTSTATUS _srv_net_file_set_secdesc(pipes_struct *p, SRV_Q_NET_FILE_SET_SECDESC *
 
        ZERO_STRUCT(st);
 
-       r_u->status = NT_STATUS_OK;
+       r_u->status = WERR_OK;
 
        unistr2_to_ascii(qualname, &q_u->uni_qual_name, sizeof(qualname));
 
        /* Null password is ok - we are already an authenticated user... */
-       *null_pw = '\0';
+       null_pw = data_blob(NULL, 0);
 
-       get_current_user(&user, p);     
-       
-       conn = make_connection(qualname, null_pw, 0, "A:", user.vuid, &nt_status);
+       get_current_user(&user, p);
+
+       become_root();
+       conn = make_connection(qualname, null_pw, "A:", user.vuid, &nt_status);
+       unbecome_root();
 
        if (conn == NULL) {
                DEBUG(3,("_srv_net_file_set_secdesc: Unable to connect to %s\n", qualname));
-               r_u->status = nt_status;
+               r_u->status = ntstatus_to_werror(nt_status);
                goto error_exit;
        }
 
        if (!become_user(conn, conn->vuid)) {
                DEBUG(0,("_srv_net_file_set_secdesc: Can't become connected user!\n"));
-               r_u->status = NT_STATUS_ACCESS_DENIED;
+               r_u->status = WERR_ACCESS_DENIED;
                goto error_exit;
        }
        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_set_secdesc: bad pathname %s\n", filename));
+               r_u->status = WERR_ACCESS_DENIED;
+               goto error_exit;
+       }
 
-       fsp = open_file_shared(conn, filename, &st, SET_OPEN_MODE(DOS_OPEN_RDWR),
-                              (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN), 0, 0, &access_mode, &action);
+       if (!check_name(filename,conn)) {
+               DEBUG(3,("_srv_net_file_set_secdesc: can't access %s\n", filename));
+               r_u->status = WERR_ACCESS_DENIED;
+               goto error_exit;
+       }
+
+
+       fsp = open_file_shared(conn, filename, &st, SET_DENY_MODE(DENY_NONE)|SET_OPEN_MODE(DOS_OPEN_RDWR),
+                       (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN), FILE_ATTRIBUTE_NORMAL, INTERNAL_OPEN_ONLY,
+                       &access_mode, &action);
 
        if (!fsp) {
                /* Perhaps it is a directory */
                if (errno == EISDIR)
-                       fsp = open_directory(conn, filename, &st,
-                                            (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN), 0, &action);
+                       fsp = open_directory(conn, filename, &st,FILE_READ_ATTRIBUTES,0,
+                                               (FILE_FAIL_IF_NOT_EXIST|FILE_EXISTS_OPEN), &action);
 
                if (!fsp) {
                        DEBUG(3,("_srv_net_file_set_secdesc: Unable to open file %s\n", filename));
-                       r_u->status = NT_STATUS_ACCESS_DENIED;
+                       r_u->status = WERR_ACCESS_DENIED;
                        goto error_exit;
                }
        }
 
-       ret = conn->vfs_ops.set_nt_acl(fsp, fsp->fsp_name, q_u->sec_info, q_u->sec_desc);
+       ret = SMB_VFS_SET_NT_ACL(fsp, fsp->fsp_name, q_u->sec_info, q_u->sec_desc);
 
        if (ret == False) {
                DEBUG(3,("_srv_net_file_set_secdesc: Unable to set NT ACL on file %s\n", filename));
-               r_u->status = NT_STATUS_ACCESS_DENIED;
+               r_u->status = WERR_ACCESS_DENIED;
                goto error_exit;
        }
 
@@ -1760,7 +2093,7 @@ NTSTATUS _srv_net_file_set_secdesc(pipes_struct *p, SRV_Q_NET_FILE_SET_SECDESC *
        close_cnum(conn, user.vuid);
        return r_u->status;
 
-  error_exit:
+error_exit:
 
        if(fsp) {
                close_file(fsp, True);
@@ -1783,7 +2116,7 @@ NTSTATUS _srv_net_file_set_secdesc(pipes_struct *p, SRV_Q_NET_FILE_SET_SECDESC *
  "Nigel Williams" <nigel@veritas.com>.
 ***********************************************************************************/
 
-const char *server_disks[] = {"C:"};
+static const char *server_disks[] = {"C:"};
 
 static uint32 get_server_disk_count(void)
 {
@@ -1821,19 +2154,24 @@ static const char *next_server_disk_enum(uint32 *resume)
        return disk;
 }
 
-NTSTATUS _srv_net_disk_enum(pipes_struct *p, SRV_Q_NET_DISK_ENUM *q_u, SRV_R_NET_DISK_ENUM *r_u)
+WERROR _srv_net_disk_enum(pipes_struct *p, SRV_Q_NET_DISK_ENUM *q_u, SRV_R_NET_DISK_ENUM *r_u)
 {
        uint32 i;
        const char *disk_name;
+       TALLOC_CTX *ctx = p->mem_ctx;
        uint32 resume=get_enum_hnd(&q_u->enum_hnd);
 
-       r_u->status=NT_STATUS_OK;
+       r_u->status=WERR_OK;
 
        r_u->total_entries = init_server_disk_enum(&resume);
 
        r_u->disk_enum_ctr.unknown = 0; 
 
-       r_u->disk_enum_ctr.disk_info_ptr = (uint32) r_u->disk_enum_ctr.disk_info;
+       if(!(r_u->disk_enum_ctr.disk_info =  TALLOC_ARRAY(ctx, DISK_INFO, MAX_SERVER_DISK_ENTRIES))) {
+               return WERR_NOMEM;
+       }
+
+       r_u->disk_enum_ctr.disk_info_ptr = r_u->disk_enum_ctr.disk_info ? 1 : 0;
 
        /*allow one DISK_INFO for null terminator*/
 
@@ -1846,7 +2184,7 @@ NTSTATUS _srv_net_disk_enum(pipes_struct *p, SRV_Q_NET_DISK_ENUM *q_u, SRV_R_NET
                init_unistr3(&r_u->disk_enum_ctr.disk_info[i].disk_name, disk_name);    
        }
 
-       /*add a terminating null string.  Is this there if there is more data to come?*/
+       /* add a terminating null string.  Is this there if there is more data to come? */
 
        r_u->disk_enum_ctr.entries_read++;
 
@@ -1857,12 +2195,12 @@ NTSTATUS _srv_net_disk_enum(pipes_struct *p, SRV_Q_NET_DISK_ENUM *q_u, SRV_R_NET
        return r_u->status;
 }
 
-NTSTATUS _srv_net_name_validate(pipes_struct *p, SRV_Q_NET_NAME_VALIDATE *q_u, SRV_R_NET_NAME_VALIDATE *r_u)
+WERROR _srv_net_name_validate(pipes_struct *p, SRV_Q_NET_NAME_VALIDATE *q_u, SRV_R_NET_NAME_VALIDATE *r_u)
 {
        int snum;
        fstring share_name;
 
-       r_u->status=NT_STATUS_OK;
+       r_u->status=WERR_OK;
 
        switch(q_u->type) {
 
@@ -1876,12 +2214,12 @@ NTSTATUS _srv_net_name_validate(pipes_struct *p, SRV_Q_NET_NAME_VALIDATE *q_u, S
 
                /* Share already exists. */
                if (snum >= 0)
-                       r_u->status = NT_STATUS_OBJECT_NAME_INVALID;
+                       r_u->status = WERR_ALREADY_EXISTS;
                break;
 
        default:
                /*unsupported type*/
-               r_u->status = NT_STATUS_INVALID_LEVEL;
+               r_u->status = WERR_UNKNOWN_LEVEL;
                break;
        }