Fix bug #7781 (Samba transforms "ShareName" to lowercase when adding new share via...
[samba.git] / source3 / rpc_server / srv_srvsvc_nt.c
index bb9c3687fbc6d86483e1542306c479950973a408..b51c7e2f2f9be771ba11448195c21760f065213e 100644 (file)
@@ -24,6 +24,7 @@
 /* This is the implementation of the srvsvc pipe. */
 
 #include "includes.h"
+#include "../librpc/gen_ndr/srv_srvsvc.h"
 
 extern const struct generic_mapping file_generic_mapping;
 
@@ -88,12 +89,13 @@ static int pipe_enum_fn( struct db_record *rec, void *p)
        }
        fenum->ctr3->array = f;
 
-       init_srvsvc_NetFileInfo3(&fenum->ctr3->array[i],
-                                (((uint32_t)(procid_to_pid(&prec.pid))<<16) | prec.pnum),
-                                (FILE_READ_DATA|FILE_WRITE_DATA),
-                                0,
-                                fullpath,
-                                username);
+       fenum->ctr3->array[i].fid               =
+               (((uint32_t)(procid_to_pid(&prec.pid))<<16) | prec.pnum);
+       fenum->ctr3->array[i].permissions       =
+               (FILE_READ_DATA|FILE_WRITE_DATA);
+       fenum->ctr3->array[i].num_locks         = 0;
+       fenum->ctr3->array[i].path              = fullpath;
+       fenum->ctr3->array[i].user              = username;
 
        fenum->ctr3->count++;
 
@@ -190,12 +192,14 @@ static void enum_file_fn( const struct share_mode_entry *e,
        permissions = e->access_mask & (FILE_READ_DATA|FILE_WRITE_DATA);
 
        /* now fill in the srvsvc_NetFileInfo3 struct */
-       init_srvsvc_NetFileInfo3(&fenum->ctr3->array[i],
-                                (((uint32_t)(procid_to_pid(&e->pid))<<16) | e->share_file_id),
-                                permissions,
-                                num_locks,
-                                fullpath,
-                                username);
+
+       fenum->ctr3->array[i].fid               =
+               (((uint32_t)(procid_to_pid(&e->pid))<<16) | e->share_file_id);
+       fenum->ctr3->array[i].permissions       = permissions;
+       fenum->ctr3->array[i].num_locks         = num_locks;
+       fenum->ctr3->array[i].path              = fullpath;
+       fenum->ctr3->array[i].user              = username;
+
        fenum->ctr3->count++;
 }
 
@@ -244,9 +248,7 @@ static uint32 get_share_type(int snum)
 
 static void init_srv_share_info_0(pipes_struct *p, struct srvsvc_NetShareInfo0 *r, int snum)
 {
-       const char *net_name = lp_servicename(snum);
-
-       init_srvsvc_NetShareInfo0(r, net_name);
+       r->name         = lp_servicename(snum);
 }
 
 /*******************************************************************
@@ -262,13 +264,13 @@ static void init_srv_share_info_1(pipes_struct *p, struct srvsvc_NetShareInfo1 *
                remark = talloc_sub_advanced(
                        p->mem_ctx, lp_servicename(snum),
                        get_current_username(), lp_pathname(snum),
-                       p->pipe_user.ut.uid, get_current_username(),
+                       p->server_info->utok.uid, get_current_username(),
                        "", remark);
        }
 
-       init_srvsvc_NetShareInfo1(r, net_name,
-                                 get_share_type(snum),
-                                 remark ? remark : "");
+       r->name         = net_name;
+       r->type         = get_share_type(snum);
+       r->comment      = remark ? remark : "";
 }
 
 /*******************************************************************
@@ -281,7 +283,6 @@ static void init_srv_share_info_2(pipes_struct *p, struct srvsvc_NetShareInfo2 *
        char *path = NULL;
        int max_connections = lp_max_connections(snum);
        uint32_t max_uses = max_connections!=0 ? max_connections : (uint32_t)-1;
-       int count = 0;
        char *net_name = lp_servicename(snum);
 
        remark = talloc_strdup(p->mem_ctx, lp_comment(snum));
@@ -289,7 +290,7 @@ static void init_srv_share_info_2(pipes_struct *p, struct srvsvc_NetShareInfo2 *
                remark = talloc_sub_advanced(
                        p->mem_ctx, lp_servicename(snum),
                        get_current_username(), lp_pathname(snum),
-                       p->pipe_user.ut.uid, get_current_username(),
+                       p->server_info->utok.uid, get_current_username(),
                        "", remark);
        }
        path = talloc_asprintf(p->mem_ctx,
@@ -305,16 +306,14 @@ static void init_srv_share_info_2(pipes_struct *p, struct srvsvc_NetShareInfo2 *
                string_replace(path, '/', '\\');
        }
 
-       count = count_current_connections(net_name, false);
-
-       init_srvsvc_NetShareInfo2(r, net_name,
-                                 get_share_type(snum),
-                                 remark ? remark : "",
-                                 0,
-                                 max_uses,
-                                 count,
-                                 path ? path : "",
-                                 "");
+       r->name                 = net_name;
+       r->type                 = get_share_type(snum);
+       r->comment              = remark ? remark : "";
+       r->permissions          = 0;
+       r->max_users            = max_uses;
+       r->current_users        = count_current_connections(net_name, false);
+       r->path                 = path ? path : "";
+       r->password             = "";
 }
 
 /*******************************************************************
@@ -355,14 +354,14 @@ static void init_srv_share_info_501(pipes_struct *p, struct srvsvc_NetShareInfo5
                remark = talloc_sub_advanced(
                        p->mem_ctx, lp_servicename(snum),
                        get_current_username(), lp_pathname(snum),
-                       p->pipe_user.ut.uid, get_current_username(),
+                       p->server_info->utok.uid, get_current_username(),
                        "", remark);
        }
 
-       init_srvsvc_NetShareInfo501(r, net_name,
-                                   get_share_type(snum),
-                                   remark ? remark : "",
-                                   (lp_csc_policy(snum) << 4));
+       r->name         = net_name;
+       r->type         = get_share_type(snum);
+       r->comment      = remark ? remark : "";
+       r->csc_policy   = (lp_csc_policy(snum) << 4);
 }
 
 /*******************************************************************
@@ -383,7 +382,7 @@ static void init_srv_share_info_502(pipes_struct *p, struct srvsvc_NetShareInfo5
                remark = talloc_sub_advanced(
                        p->mem_ctx, lp_servicename(snum),
                        get_current_username(), lp_pathname(snum),
-                       p->pipe_user.ut.uid, get_current_username(),
+                       p->server_info->utok.uid, get_current_username(),
                        "", remark);
        }
        path = talloc_asprintf(ctx, "C:%s", lp_pathname(snum));
@@ -399,15 +398,15 @@ static void init_srv_share_info_502(pipes_struct *p, struct srvsvc_NetShareInfo5
 
        sd_buf = make_sec_desc_buf(p->mem_ctx, sd_size, sd);
 
-       init_srvsvc_NetShareInfo502(r, net_name,
-                                   get_share_type(snum),
-                                   remark ? remark : "",
-                                   0,
-                                   (uint32_t)-1,
-                                   1,
-                                   path ? path : "",
-                                   "",
-                                   sd_buf);
+       r->name                 = net_name;
+       r->type                 = get_share_type(snum);
+       r->comment              = remark ? remark : "";
+       r->permissions          = 0;
+       r->max_users            = (uint32_t)-1;
+       r->current_users        = 1; /* ??? */
+       r->path                 = path ? path : "";
+       r->password             = "";
+       r->sd_buf               = *sd_buf;
 }
 
 /***************************************************************************
@@ -422,11 +421,11 @@ static void init_srv_share_info_1004(pipes_struct *p, struct srvsvc_NetShareInfo
                remark = talloc_sub_advanced(
                        p->mem_ctx, lp_servicename(snum),
                        get_current_username(), lp_pathname(snum),
-                       p->pipe_user.ut.uid, get_current_username(),
+                       p->server_info->utok.uid, get_current_username(),
                        "", remark);
        }
 
-       init_srvsvc_NetShareInfo1004(r, remark ? remark : "");
+       r->comment      = remark ? remark : "";
 }
 
 /***************************************************************************
@@ -443,7 +442,7 @@ static void init_srv_share_info_1005(pipes_struct *p, struct srvsvc_NetShareInfo
 
        dfs_flags |= lp_csc_policy(snum) << SHARE_1005_CSC_POLICY_SHIFT;
 
-       init_srvsvc_NetShareInfo1005(r, dfs_flags);
+       r->dfs_flags    = dfs_flags;
 }
 
 /***************************************************************************
@@ -452,7 +451,7 @@ static void init_srv_share_info_1005(pipes_struct *p, struct srvsvc_NetShareInfo
 
 static void init_srv_share_info_1006(pipes_struct *p, struct srvsvc_NetShareInfo1006 *r, int snum)
 {
-       init_srvsvc_NetShareInfo1006(r, (uint32_t)-1);
+       r->max_users    = (uint32_t)-1;
 }
 
 /***************************************************************************
@@ -461,9 +460,8 @@ static void init_srv_share_info_1006(pipes_struct *p, struct srvsvc_NetShareInfo
 
 static void init_srv_share_info_1007(pipes_struct *p, struct srvsvc_NetShareInfo1007 *r, int snum)
 {
-       uint32 flags = 0;
-
-       init_srvsvc_NetShareInfo1007(r, flags, "");
+       r->flags                        = 0;
+       r->alternate_directory_name     = "";
 }
 
 /*******************************************************************
@@ -492,6 +490,19 @@ static bool is_hidden_share(int snum)
        return (net_name[strlen(net_name) - 1] == '$') ? True : False;
 }
 
+/*******************************************************************
+ Verify user is allowed to view share, access based enumeration
+********************************************************************/
+static bool is_enumeration_allowed(pipes_struct *p,
+                                   int snum)
+{
+    if (!lp_access_based_share_enum(snum))
+        return true;
+
+    return share_access_check(p->server_info->ptok, lp_servicename(snum),
+                              FILE_READ_DATA);
+}
+
 /*******************************************************************
  Fill in a share info structure.
  ********************************************************************/
@@ -509,6 +520,7 @@ static WERROR init_srv_share_info_ctr(pipes_struct *p,
        TALLOC_CTX *ctx = p->mem_ctx;
        int i = 0;
        int valid_share_count = 0;
+       bool *allowed = 0;
        union srvsvc_NetShareCtr ctr;
        uint32_t resume_handle = resume_handle_p ? *resume_handle_p : 0;
 
@@ -521,15 +533,23 @@ static WERROR init_srv_share_info_ctr(pipes_struct *p,
        num_services = lp_numservices();
        unbecome_root();
 
-       /* 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)) ) {
-                       DEBUG(10, ("counting service %s\n", lp_servicename(snum)));
-                       num_entries++;
-               } else {
-                       DEBUG(10, ("NOT counting service %s\n", lp_servicename(snum)));
-               }
-       }
+        allowed = TALLOC_ZERO_ARRAY(ctx, bool, num_services);
+        W_ERROR_HAVE_NO_MEMORY(allowed);
+
+        /* Count the number of entries. */
+        for (snum = 0; snum < num_services; snum++) {
+                if (lp_browseable(snum) && lp_snum_ok(snum) &&
+                    is_enumeration_allowed(p, snum) &&
+                    (all_shares || !is_hidden_share(snum)) ) {
+                        DEBUG(10, ("counting service %s\n",
+                               lp_servicename(snum) ? lp_servicename(snum) : "(null)"));
+                        allowed[snum] = true;
+                        num_entries++;
+                } else {
+                        DEBUG(10, ("NOT counting service %s\n",
+                               lp_servicename(snum) ? lp_servicename(snum) : "(null)"));
+                }
+        }
 
        if (!num_entries || (resume_handle >= num_entries)) {
                return WERR_OK;
@@ -547,7 +567,7 @@ static WERROR init_srv_share_info_ctr(pipes_struct *p,
                W_ERROR_HAVE_NO_MEMORY(ctr.ctr0->array);
 
                for (snum = 0; snum < num_services; snum++) {
-                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) &&
+                       if (allowed[snum] &&
                            (resume_handle <= (i + valid_share_count++)) ) {
                                init_srv_share_info_0(p, &ctr.ctr0->array[i++], snum);
                        }
@@ -564,7 +584,7 @@ static WERROR init_srv_share_info_ctr(pipes_struct *p,
                W_ERROR_HAVE_NO_MEMORY(ctr.ctr1->array);
 
                for (snum = 0; snum < num_services; snum++) {
-                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) &&
+                       if (allowed[snum] &&
                            (resume_handle <= (i + valid_share_count++)) ) {
                                init_srv_share_info_1(p, &ctr.ctr1->array[i++], snum);
                        }
@@ -581,7 +601,7 @@ static WERROR init_srv_share_info_ctr(pipes_struct *p,
                W_ERROR_HAVE_NO_MEMORY(ctr.ctr2->array);
 
                for (snum = 0; snum < num_services; snum++) {
-                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) &&
+                       if (allowed[snum] &&
                            (resume_handle <= (i + valid_share_count++)) ) {
                                init_srv_share_info_2(p, &ctr.ctr2->array[i++], snum);
                        }
@@ -598,7 +618,7 @@ static WERROR init_srv_share_info_ctr(pipes_struct *p,
                W_ERROR_HAVE_NO_MEMORY(ctr.ctr501->array);
 
                for (snum = 0; snum < num_services; snum++) {
-                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) &&
+                       if (allowed[snum] &&
                            (resume_handle <= (i + valid_share_count++)) ) {
                                init_srv_share_info_501(p, &ctr.ctr501->array[i++], snum);
                        }
@@ -615,7 +635,7 @@ static WERROR init_srv_share_info_ctr(pipes_struct *p,
                W_ERROR_HAVE_NO_MEMORY(ctr.ctr502->array);
 
                for (snum = 0; snum < num_services; snum++) {
-                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) &&
+                       if (allowed[snum] &&
                            (resume_handle <= (i + valid_share_count++)) ) {
                                init_srv_share_info_502(p, &ctr.ctr502->array[i++], snum);
                        }
@@ -632,7 +652,7 @@ static WERROR init_srv_share_info_ctr(pipes_struct *p,
                W_ERROR_HAVE_NO_MEMORY(ctr.ctr1004->array);
 
                for (snum = 0; snum < num_services; snum++) {
-                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) &&
+                       if (allowed[snum] &&
                            (resume_handle <= (i + valid_share_count++)) ) {
                                init_srv_share_info_1004(p, &ctr.ctr1004->array[i++], snum);
                        }
@@ -649,7 +669,7 @@ static WERROR init_srv_share_info_ctr(pipes_struct *p,
                W_ERROR_HAVE_NO_MEMORY(ctr.ctr1005->array);
 
                for (snum = 0; snum < num_services; snum++) {
-                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) &&
+                       if (allowed[snum] &&
                            (resume_handle <= (i + valid_share_count++)) ) {
                                init_srv_share_info_1005(p, &ctr.ctr1005->array[i++], snum);
                        }
@@ -666,7 +686,7 @@ static WERROR init_srv_share_info_ctr(pipes_struct *p,
                W_ERROR_HAVE_NO_MEMORY(ctr.ctr1006->array);
 
                for (snum = 0; snum < num_services; snum++) {
-                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) &&
+                       if (allowed[snum] &&
                            (resume_handle <= (i + valid_share_count++)) ) {
                                init_srv_share_info_1006(p, &ctr.ctr1006->array[i++], snum);
                        }
@@ -683,7 +703,7 @@ static WERROR init_srv_share_info_ctr(pipes_struct *p,
                W_ERROR_HAVE_NO_MEMORY(ctr.ctr1007->array);
 
                for (snum = 0; snum < num_services; snum++) {
-                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) &&
+                       if (allowed[snum] &&
                            (resume_handle <= (i + valid_share_count++)) ) {
                                init_srv_share_info_1007(p, &ctr.ctr1007->array[i++], snum);
                        }
@@ -700,7 +720,7 @@ static WERROR init_srv_share_info_ctr(pipes_struct *p,
                W_ERROR_HAVE_NO_MEMORY(ctr.ctr1501->array);
 
                for (snum = 0; snum < num_services; snum++) {
-                       if (lp_browseable(snum) && lp_snum_ok(snum) && (all_shares || !is_hidden_share(snum)) &&
+                       if (allowed[snum] &&
                            (resume_handle <= (i + valid_share_count++)) ) {
                                init_srv_share_info_1501(p, &ctr.ctr1501->array[i++], snum);
                        }
@@ -759,8 +779,9 @@ static WERROR init_srv_sess_info_0(pipes_struct *p,
                                                   num_entries+1);
                W_ERROR_HAVE_NO_MEMORY(ctr0->array);
 
-               init_srvsvc_NetSessInfo0(&ctr0->array[num_entries],
-                                        session_list[resume_handle].remote_machine);
+               ctr0->array[num_entries].client =
+                       session_list[resume_handle].remote_machine;
+
                num_entries++;
        }
 
@@ -856,13 +877,13 @@ static WERROR init_srv_sess_info_1(pipes_struct *p,
                                                   num_entries+1);
                W_ERROR_HAVE_NO_MEMORY(ctr1->array);
 
-               init_srvsvc_NetSessInfo1(&ctr1->array[num_entries],
-                                        session_list[resume_handle].remote_machine,
-                                        session_list[resume_handle].username,
-                                        num_files,
-                                        connect_time,
-                                        0,
-                                        guest);
+               ctr1->array[num_entries].client         = session_list[resume_handle].remote_machine;
+               ctr1->array[num_entries].user           = session_list[resume_handle].username;
+               ctr1->array[num_entries].num_open       = num_files;
+               ctr1->array[num_entries].time           = connect_time;
+               ctr1->array[num_entries].idle_time      = 0;
+               ctr1->array[num_entries].user_flags     = guest;
+
                num_entries++;
        }
 
@@ -913,8 +934,7 @@ static WERROR init_srv_conn_info_0(struct srvsvc_NetConnCtr0 *ctr0,
                        return WERR_NOMEM;
                }
 
-               init_srvsvc_NetConnInfo0(&ctr0->array[num_entries],
-                                        (*total_entries));
+               ctr0->array[num_entries].conn_id = *total_entries;
 
                /* move on to creating next connection */
                num_entries++;
@@ -968,14 +988,13 @@ static WERROR init_srv_conn_info_1(struct srvsvc_NetConnCtr1 *ctr1,
                        return WERR_NOMEM;
                }
 
-               init_srvsvc_NetConnInfo1(&ctr1->array[num_entries],
-                                        (*total_entries),
-                                        0x3,
-                                        1,
-                                        1,
-                                        3,
-                                        "dummy_user",
-                                        "IPC$");
+               ctr1->array[num_entries].conn_id        = *total_entries;
+               ctr1->array[num_entries].conn_type      = 0x3;
+               ctr1->array[num_entries].num_open       = 1;
+               ctr1->array[num_entries].num_users      = 1;
+               ctr1->array[num_entries].conn_time      = 3;
+               ctr1->array[num_entries].user           = "dummy_user";
+               ctr1->array[num_entries].share          = "IPC$";
 
                /* move on to creating next connection */
                num_entries++;
@@ -1014,6 +1033,13 @@ WERROR _srvsvc_NetFileEnum(pipes_struct *p,
                return WERR_UNKNOWN_LEVEL;
        }
 
+       if (!nt_token_check_sid(&global_sid_Builtin_Administrators,
+                               p->server_info->ptok)) {
+               DEBUG(1, ("Enumerating files only allowed for "
+                         "administrators\n"));
+               return WERR_ACCESS_DENIED;
+       }
+
        ctx = talloc_tos();
        ctr3 = r->in.info_ctr->ctr.ctr3;
        if (!ctr3) {
@@ -1075,20 +1101,21 @@ WERROR _srvsvc_NetSrvGetInfo(pipes_struct *p,
                        return WERR_NOMEM;
                }
 
-               init_srvsvc_NetSrvInfo102(info102,
-                                         PLATFORM_ID_NT,
-                                         global_myname(),
-                                         lp_major_announce_version(),
-                                         lp_minor_announce_version(),
-                                         lp_default_server_announce(),
-                                         string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH),
-                                         0xffffffff, /* users */
-                                         0xf, /* disc */
-                                         0, /* hidden */
-                                         240, /* announce */
-                                         3000, /* announce delta */
-                                         100000, /* licenses */
-                                         "c:\\"); /* user path */
+               info102->platform_id    = PLATFORM_ID_NT;
+               info102->server_name    = global_myname();
+               info102->version_major  = lp_major_announce_version();
+               info102->version_minor  = lp_minor_announce_version();
+               info102->server_type    = lp_default_server_announce();
+               info102->comment        = string_truncate(lp_serverstring(),
+                                               MAX_SERVER_STRING_LENGTH);
+               info102->users          = 0xffffffff;
+               info102->disc           = 0xf;
+               info102->hidden         = 0;
+               info102->announce       = 240;
+               info102->anndelta       = 3000;
+               info102->licenses       = 100000;
+               info102->userpath       = "C:\\";
+
                r->out.info->info102 = info102;
                break;
        }
@@ -1100,13 +1127,14 @@ WERROR _srvsvc_NetSrvGetInfo(pipes_struct *p,
                        return WERR_NOMEM;
                }
 
-               init_srvsvc_NetSrvInfo101(info101,
-                                         PLATFORM_ID_NT,
-                                         global_myname(),
-                                         lp_major_announce_version(),
-                                         lp_minor_announce_version(),
-                                         lp_default_server_announce(),
-                                         string_truncate(lp_serverstring(), MAX_SERVER_STRING_LENGTH));
+               info101->platform_id    = PLATFORM_ID_NT;
+               info101->server_name    = global_myname();
+               info101->version_major  = lp_major_announce_version();
+               info101->version_minor  = lp_minor_announce_version();
+               info101->server_type    = lp_default_server_announce();
+               info101->comment        = string_truncate(lp_serverstring(),
+                                               MAX_SERVER_STRING_LENGTH);
+
                r->out.info->info101 = info101;
                break;
        }
@@ -1118,9 +1146,9 @@ WERROR _srvsvc_NetSrvGetInfo(pipes_struct *p,
                        return WERR_NOMEM;
                }
 
-               init_srvsvc_NetSrvInfo100(info100,
-                                         PLATFORM_ID_NT,
-                                         global_myname());
+               info100->platform_id    = PLATFORM_ID_NT;
+               info100->server_name    = global_myname();
+
                r->out.info->info100 = info100;
 
                break;
@@ -1164,6 +1192,13 @@ WERROR _srvsvc_NetConnEnum(pipes_struct *p,
 
        DEBUG(5,("_srvsvc_NetConnEnum: %d\n", __LINE__));
 
+       if (!nt_token_check_sid(&global_sid_Builtin_Administrators,
+                               p->server_info->ptok)) {
+               DEBUG(1, ("Enumerating connections only allowed for "
+                         "administrators\n"));
+               return WERR_ACCESS_DENIED;
+       }
+
        switch (r->in.info_ctr->level) {
                case 0:
                        werr = init_srv_conn_info_0(r->in.info_ctr->ctr.ctr0,
@@ -1195,6 +1230,13 @@ WERROR _srvsvc_NetSessEnum(pipes_struct *p,
 
        DEBUG(5,("_srvsvc_NetSessEnum: %d\n", __LINE__));
 
+       if (!nt_token_check_sid(&global_sid_Builtin_Administrators,
+                               p->server_info->ptok)) {
+               DEBUG(1, ("Enumerating sessions only allowed for "
+                         "administrators\n"));
+               return WERR_ACCESS_DENIED;
+       }
+
        switch (r->in.info_ctr->level) {
                case 0:
                        werr = init_srv_sess_info_0(p,
@@ -1225,7 +1267,6 @@ WERROR _srvsvc_NetSessDel(pipes_struct *p,
                          struct srvsvc_NetSessDel *r)
 {
        struct sessionid *session_list;
-       struct current_user user;
        int num_sessions, snum;
        const char *username;
        const char *machine;
@@ -1246,12 +1287,11 @@ WERROR _srvsvc_NetSessDel(pipes_struct *p,
 
        werr = WERR_ACCESS_DENIED;
 
-       get_current_user(&user, p);
-
        /* fail out now if you are not root or not a domain admin */
 
-       if ((user.ut.uid != sec_initial_uid()) &&
-               ( ! nt_token_check_domain_rid(p->pipe_user.nt_user_token, DOMAIN_GROUP_RID_ADMINS))) {
+       if ((p->server_info->utok.uid != sec_initial_uid()) &&
+               ( ! nt_token_check_domain_rid(p->server_info->ptok,
+                                             DOMAIN_GROUP_RID_ADMINS))) {
 
                goto done;
        }
@@ -1263,7 +1303,7 @@ WERROR _srvsvc_NetSessDel(pipes_struct *p,
 
                        NTSTATUS ntstat;
 
-                       if (user.ut.uid != sec_initial_uid()) {
+                       if (p->server_info->utok.uid != sec_initial_uid()) {
                                not_root = True;
                                become_root();
                        }
@@ -1357,9 +1397,11 @@ WERROR _srvsvc_NetShareGetInfo(pipes_struct *p,
 
        DEBUG(5,("_srvsvc_NetShareGetInfo: %d\n", __LINE__));
 
-       fstrcpy(share_name, r->in.share_name);
+       if (!r->in.share_name) {
+               return WERR_INVALID_NAME;
+       }
 
-       snum = find_service(share_name);
+       snum = find_service(r->in.share_name, share_name);
        if (snum < 0) {
                return WERR_INVALID_NAME;
        }
@@ -1466,9 +1508,8 @@ char *valid_share_pathname(TALLOC_CTX *ctx, const char *dos_pathname)
 WERROR _srvsvc_NetShareSetInfo(pipes_struct *p,
                               struct srvsvc_NetShareSetInfo *r)
 {
-       struct current_user user;
        char *command = NULL;
-       char *share_name = NULL;
+       fstring share_name;
        char *comment = NULL;
        const char *pathname = NULL;
        int type;
@@ -1484,23 +1525,25 @@ WERROR _srvsvc_NetShareSetInfo(pipes_struct *p,
 
        DEBUG(5,("_srvsvc_NetShareSetInfo: %d\n", __LINE__));
 
-       share_name = talloc_strdup(p->mem_ctx, r->in.share_name);
-       if (!share_name) {
-               return WERR_NOMEM;
+       if (!r->in.share_name) {
+               return WERR_INVALID_NAME;
        }
 
        if (r->out.parm_error) {
                *r->out.parm_error = 0;
        }
 
-       if ( strequal(share_name,"IPC$")
-               || ( lp_enable_asu_support() && strequal(share_name,"ADMIN$") )
-               || strequal(share_name,"global") )
+       if ( strequal(r->in.share_name,"IPC$")
+               || ( lp_enable_asu_support() && strequal(r->in.share_name,"ADMIN$") )
+               || strequal(r->in.share_name,"global") )
        {
+               DEBUG(5,("_srvsvc_NetShareSetInfo: share %s cannot be "
+                       "modified by a remote user.\n",
+                       r->in.share_name ));
                return WERR_ACCESS_DENIED;
        }
 
-       snum = find_service(share_name);
+       snum = find_service(r->in.share_name, share_name);
 
        /* Does this share exist ? */
        if (snum < 0)
@@ -1510,14 +1553,18 @@ WERROR _srvsvc_NetShareSetInfo(pipes_struct *p,
        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 );
+       is_disk_op = user_has_privileges( p->server_info->ptok, &se_diskop );
 
        /* fail out now if you are not root and not a disk op */
 
-       if ( user.ut.uid != sec_initial_uid() && !is_disk_op )
+       if ( p->server_info->utok.uid != sec_initial_uid() && !is_disk_op ) {
+               DEBUG(2,("_srvsvc_NetShareSetInfo: uid %u doesn't have the "
+                       "SeDiskOperatorPrivilege privilege needed to modify "
+                       "share %s\n",
+                       (unsigned int)p->server_info->utok.uid,
+                       share_name ));
                return WERR_ACCESS_DENIED;
+       }
 
        switch (r->in.level) {
        case 1:
@@ -1584,16 +1631,23 @@ WERROR _srvsvc_NetShareSetInfo(pipes_struct *p,
        }
 
        /* We can only modify disk shares. */
-       if (type != STYPE_DISKTREE)
+       if (type != STYPE_DISKTREE) {
+               DEBUG(5,("_srvsvc_NetShareSetInfo: share %s is not a "
+                       "disk share\n",
+                       share_name ));
                return WERR_ACCESS_DENIED;
+       }
 
        if (comment == NULL) {
                return WERR_NOMEM;
        }
 
        /* Check if the pathname is valid. */
-       if (!(path = valid_share_pathname(p->mem_ctx, pathname )))
+       if (!(path = valid_share_pathname(p->mem_ctx, pathname ))) {
+               DEBUG(5,("_srvsvc_NetShareSetInfo: invalid pathname %s\n",
+                       pathname ));
                return WERR_OBJECT_PATH_INVALID;
+       }
 
        /* Ensure share name, pathname and comment don't contain '"' characters. */
        string_replace(share_name, '"', ' ');
@@ -1662,7 +1716,7 @@ WERROR _srvsvc_NetShareSetInfo(pipes_struct *p,
 
                old_sd = get_share_security(p->mem_ctx, lp_servicename(snum), &sd_size);
 
-               if (old_sd && !sec_desc_equal(old_sd, psd)) {
+               if (old_sd && !security_descriptor_equal(old_sd, psd)) {
                        if (!set_share_security(share_name, psd))
                                DEBUG(0,("_srvsvc_NetShareSetInfo: Failed to change security info in share %s.\n",
                                        share_name ));
@@ -1683,9 +1737,9 @@ WERROR _srvsvc_NetShareSetInfo(pipes_struct *p,
 WERROR _srvsvc_NetShareAdd(pipes_struct *p,
                           struct srvsvc_NetShareAdd *r)
 {
-       struct current_user user;
        char *command = NULL;
-       char *share_name = NULL;
+       char *share_name_in = NULL;
+       fstring share_name;
        char *comment = NULL;
        char *pathname = NULL;
        int type;
@@ -1700,13 +1754,13 @@ WERROR _srvsvc_NetShareAdd(pipes_struct *p,
 
        DEBUG(5,("_srvsvc_NetShareAdd: %d\n", __LINE__));
 
-       *r->out.parm_error = 0;
-
-       get_current_user(&user,p);
+       if (r->out.parm_error) {
+               *r->out.parm_error = 0;
+       }
 
-       is_disk_op = user_has_privileges( p->pipe_user.nt_user_token, &se_diskop );
+       is_disk_op = user_has_privileges( p->server_info->ptok, &se_diskop );
 
-       if (user.ut.uid != sec_initial_uid()  && !is_disk_op )
+       if (p->server_info->utok.uid != sec_initial_uid()  && !is_disk_op )
                return WERR_ACCESS_DENIED;
 
        if (!lp_add_share_cmd() || !*lp_add_share_cmd()) {
@@ -1722,7 +1776,7 @@ WERROR _srvsvc_NetShareAdd(pipes_struct *p,
                /* Not enough info in a level 1 to do anything. */
                return WERR_ACCESS_DENIED;
        case 2:
-               share_name = talloc_strdup(ctx, r->in.info->info2->name);
+               share_name_in = talloc_strdup(ctx, r->in.info->info2->name);
                comment = talloc_strdup(ctx, r->in.info->info2->comment);
                pathname = talloc_strdup(ctx, r->in.info->info2->path);
                max_connections = (r->in.info->info2->max_users == (uint32_t)-1) ?
@@ -1733,7 +1787,7 @@ WERROR _srvsvc_NetShareAdd(pipes_struct *p,
                /* No path. Not enough info in a level 501 to do anything. */
                return WERR_ACCESS_DENIED;
        case 502:
-               share_name = talloc_strdup(ctx, r->in.info->info502->name);
+               share_name_in = talloc_strdup(ctx, r->in.info->info502->name);
                comment = talloc_strdup(ctx, r->in.info->info502->comment);
                pathname = talloc_strdup(ctx, r->in.info->info502->path);
                max_connections = (r->in.info->info502->max_users == (uint32_t)-1) ?
@@ -1761,25 +1815,25 @@ WERROR _srvsvc_NetShareAdd(pipes_struct *p,
 
        /* check for invalid share names */
 
-       if (!share_name || !validate_net_name(share_name,
+       if (!share_name_in || !validate_net_name(share_name_in,
                                INVALID_SHARENAME_CHARS,
-                               strlen(share_name))) {
+                               strlen(share_name_in))) {
                DEBUG(5,("_srvsvc_NetShareAdd: Bad sharename \"%s\"\n",
-                                       share_name ? share_name : ""));
+                                       share_name_in ? share_name_in : ""));
                return WERR_INVALID_NAME;
        }
 
-       if (strequal(share_name,"IPC$") || strequal(share_name,"global")
+       if (strequal(share_name_in,"IPC$") || strequal(share_name_in,"global")
                        || (lp_enable_asu_support() &&
-                                       strequal(share_name,"ADMIN$"))) {
+                                       strequal(share_name_in,"ADMIN$"))) {
                return WERR_ACCESS_DENIED;
        }
 
-       snum = find_service(share_name);
+       snum = find_service(share_name_in, share_name);
 
        /* Share already exists. */
        if (snum >= 0) {
-               return WERR_ALREADY_EXISTS;
+               return WERR_FILE_EXISTS;
        }
 
        /* We can only add disk shares. */
@@ -1793,7 +1847,7 @@ WERROR _srvsvc_NetShareAdd(pipes_struct *p,
        }
 
        /* Ensure share name, pathname and comment don't contain '"' characters. */
-       string_replace(share_name, '"', ' ');
+       string_replace(share_name_in, '"', ' ');
        string_replace(path, '"', ' ');
        if (comment) {
                string_replace(comment, '"', ' ');
@@ -1803,7 +1857,7 @@ WERROR _srvsvc_NetShareAdd(pipes_struct *p,
                        "%s \"%s\" \"%s\" \"%s\" \"%s\" %d",
                        lp_add_share_cmd(),
                        get_dyn_CONFIGFILE(),
-                       share_name,
+                       share_name_in,
                        path,
                        comment ? comment : "",
                        max_connections);
@@ -1840,6 +1894,8 @@ WERROR _srvsvc_NetShareAdd(pipes_struct *p,
                return WERR_ACCESS_DENIED;
 
        if (psd) {
+               /* Note we use share_name here, not share_name_in as
+                  we need a canonicalized name for setting security. */
                if (!set_share_security(share_name, psd)) {
                        DEBUG(0,("_srvsvc_NetShareAdd: Failed to add security info to share %s.\n",
                                share_name ));
@@ -1866,9 +1922,8 @@ WERROR _srvsvc_NetShareAdd(pipes_struct *p,
 WERROR _srvsvc_NetShareDel(pipes_struct *p,
                           struct srvsvc_NetShareDel *r)
 {
-       struct current_user user;
        char *command = NULL;
-       char *share_name = NULL;
+       fstring share_name;
        int ret;
        int snum;
        SE_PRIV se_diskop = SE_DISK_OPERATOR;
@@ -1878,32 +1933,29 @@ WERROR _srvsvc_NetShareDel(pipes_struct *p,
 
        DEBUG(5,("_srvsvc_NetShareDel: %d\n", __LINE__));
 
-       share_name = talloc_strdup(p->mem_ctx, r->in.share_name);
-       if (!share_name) {
+       if (!r->in.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") )
+       if ( strequal(r->in.share_name,"IPC$")
+               || ( lp_enable_asu_support() && strequal(r->in.share_name,"ADMIN$") )
+               || strequal(r->in.share_name,"global") )
        {
                return WERR_ACCESS_DENIED;
        }
 
-       if (!(params = get_share_params(p->mem_ctx, share_name))) {
+       if (!(params = get_share_params(p->mem_ctx, r->in.share_name))) {
                return WERR_NO_SUCH_SHARE;
        }
 
-       snum = find_service(share_name);
+       snum = find_service(r->in.share_name, 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 );
+       is_disk_op = user_has_privileges( p->server_info->ptok, &se_diskop );
 
-       if (user.ut.uid != sec_initial_uid()  && !is_disk_op )
+       if (p->server_info->utok.uid != sec_initial_uid()  && !is_disk_op )
                return WERR_ACCESS_DENIED;
 
        if (!lp_delete_share_cmd() || !*lp_delete_share_cmd()) {
@@ -1997,19 +2049,18 @@ WERROR _srvsvc_NetRemoteTOD(pipes_struct *p,
        t = gmtime(&unixdate);
 
        /* set up the */
-       init_srvsvc_NetRemoteTODInfo(tod,
-                                    unixdate,
-                                    0,
-                                    t->tm_hour,
-                                    t->tm_min,
-                                    t->tm_sec,
-                                    0,
-                                    zone,
-                                    10000,
-                                    t->tm_mday,
-                                    t->tm_mon + 1,
-                                    1900+t->tm_year,
-                                    t->tm_wday);
+       tod->elapsed    = unixdate;
+       tod->msecs      = 0;
+       tod->hours      = t->tm_hour;
+       tod->mins       = t->tm_min;
+       tod->secs       = t->tm_sec;
+       tod->hunds      = 0;
+       tod->timezone   = zone;
+       tod->tinterval  = 10000;
+       tod->day        = t->tm_mday;
+       tod->month      = t->tm_mon + 1;
+       tod->year       = 1900+t->tm_year;
+       tod->weekday    = t->tm_wday;
 
        DEBUG(5,("_srvsvc_NetRemoteTOD: %d\n", __LINE__));
 
@@ -2024,6 +2075,7 @@ WERROR _srvsvc_NetRemoteTOD(pipes_struct *p,
 WERROR _srvsvc_NetGetFileSecurity(pipes_struct *p,
                                  struct srvsvc_NetGetFileSecurity *r)
 {
+       struct smb_filename *smb_fname = NULL;
        SEC_DESC *psd = NULL;
        size_t sd_size;
        fstring servicename;
@@ -2038,9 +2090,11 @@ WERROR _srvsvc_NetGetFileSecurity(pipes_struct *p,
 
        ZERO_STRUCT(st);
 
-       fstrcpy(servicename, r->in.share);
+       if (!r->in.share) {
+               return WERR_INVALID_NAME;
+       }
 
-       snum = find_service(servicename);
+       snum = find_service(r->in.share, servicename);
        if (snum == -1) {
                DEBUG(10, ("Could not find service %s\n", servicename));
                werr = WERR_NET_NAME_NOT_FOUND;
@@ -2048,7 +2102,8 @@ WERROR _srvsvc_NetGetFileSecurity(pipes_struct *p,
        }
 
        nt_status = create_conn_struct(talloc_tos(), &conn, snum,
-                                      lp_pathname(snum), &oldcwd);
+                                      lp_pathname(snum), p->server_info,
+                                      &oldcwd);
        if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(10, ("create_conn_struct failed: %s\n",
                           nt_errstr(nt_status)));
@@ -2056,13 +2111,23 @@ WERROR _srvsvc_NetGetFileSecurity(pipes_struct *p,
                goto error_exit;
        }
 
-       conn->server_info = p->server_info;
+       nt_status = filename_convert(talloc_tos(),
+                                       conn,
+                                       false,
+                                       r->in.file,
+                                       0,
+                                       NULL,
+                                       &smb_fname);
+       if (!NT_STATUS_IS_OK(nt_status)) {
+               werr = ntstatus_to_werror(nt_status);
+               goto error_exit;
+       }
 
-       nt_status = create_file(
+       nt_status = SMB_VFS_CREATE_FILE(
                conn,                                   /* conn */
                NULL,                                   /* req */
                0,                                      /* root_dir_fid */
-               r->in.file,                             /* fname */
+               smb_fname,                              /* fname */
                FILE_READ_ATTRIBUTES,                   /* access_mask */
                FILE_SHARE_READ|FILE_SHARE_WRITE,       /* share_access */
                FILE_OPEN,                              /* create_disposition*/
@@ -2073,12 +2138,11 @@ WERROR _srvsvc_NetGetFileSecurity(pipes_struct *p,
                NULL,                                   /* sd */
                NULL,                                   /* ea_list */
                &fsp,                                   /* result */
-               NULL,                                   /* pinfo */
-               NULL);                                  /* psbuf */
+               NULL);                                  /* pinfo */
 
        if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(3,("_srvsvc_NetGetFileSecurity: can't open %s\n",
-                        r->in.file));
+                        smb_fname_str_dbg(smb_fname)));
                werr = ntstatus_to_werror(nt_status);
                goto error_exit;
        }
@@ -2090,12 +2154,12 @@ WERROR _srvsvc_NetGetFileSecurity(pipes_struct *p,
 
        if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(3,("_srvsvc_NetGetFileSecurity: Unable to get NT ACL "
-                        "for file %s\n", r->in.file));
+                       "for file %s\n", smb_fname_str_dbg(smb_fname)));
                werr = ntstatus_to_werror(nt_status);
                goto error_exit;
        }
 
-       sd_size = ndr_size_security_descriptor(psd, 0);
+       sd_size = ndr_size_security_descriptor(psd, NULL, 0);
 
        sd_buf = TALLOC_ZERO_P(p->mem_ctx, struct sec_desc_buf);
        if (!sd_buf) {
@@ -2110,15 +2174,16 @@ WERROR _srvsvc_NetGetFileSecurity(pipes_struct *p,
 
        psd->dacl->revision = NT4_ACL_REVISION;
 
-       close_file(fsp, NORMAL_CLOSE);
+       close_file(NULL, fsp, NORMAL_CLOSE);
        vfs_ChDir(conn, oldcwd);
-       conn_free_internal(conn);
-       return WERR_OK;
+       conn_free(conn);
+       werr = WERR_OK;
+       goto done;
 
 error_exit:
 
        if (fsp) {
-               close_file(fsp, NORMAL_CLOSE);
+               close_file(NULL, fsp, NORMAL_CLOSE);
        }
 
        if (oldcwd) {
@@ -2126,9 +2191,12 @@ error_exit:
        }
 
        if (conn) {
-               conn_free_internal(conn);
+               conn_free(conn);
        }
 
+ done:
+       TALLOC_FREE(smb_fname);
+
        return werr;
 }
 
@@ -2140,6 +2208,7 @@ error_exit:
 WERROR _srvsvc_NetSetFileSecurity(pipes_struct *p,
                                  struct srvsvc_NetSetFileSecurity *r)
 {
+       struct smb_filename *smb_fname = NULL;
        fstring servicename;
        files_struct *fsp = NULL;
        SMB_STRUCT_STAT st;
@@ -2148,12 +2217,16 @@ WERROR _srvsvc_NetSetFileSecurity(pipes_struct *p,
        connection_struct *conn = NULL;
        int snum;
        char *oldcwd = NULL;
+       struct security_descriptor *psd = NULL;
+       uint32_t security_info_sent = 0;
 
        ZERO_STRUCT(st);
 
-       fstrcpy(servicename, r->in.share);
+       if (!r->in.share) {
+               return WERR_INVALID_NAME;
+       }
 
-       snum = find_service(servicename);
+       snum = find_service(r->in.share, servicename);
        if (snum == -1) {
                DEBUG(10, ("Could not find service %s\n", servicename));
                werr = WERR_NET_NAME_NOT_FOUND;
@@ -2161,7 +2234,8 @@ WERROR _srvsvc_NetSetFileSecurity(pipes_struct *p,
        }
 
        nt_status = create_conn_struct(talloc_tos(), &conn, snum,
-                                      lp_pathname(snum), &oldcwd);
+                                      lp_pathname(snum), p->server_info,
+                                      &oldcwd);
        if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(10, ("create_conn_struct failed: %s\n",
                           nt_errstr(nt_status)));
@@ -2169,13 +2243,23 @@ WERROR _srvsvc_NetSetFileSecurity(pipes_struct *p,
                goto error_exit;
        }
 
-       conn->server_info = p->server_info;
+       nt_status = filename_convert(talloc_tos(),
+                                       conn,
+                                       false,
+                                       r->in.file,
+                                       0,
+                                       NULL,
+                                       &smb_fname);
+       if (!NT_STATUS_IS_OK(nt_status)) {
+               werr = ntstatus_to_werror(nt_status);
+               goto error_exit;
+       }
 
-       nt_status = create_file(
+       nt_status = SMB_VFS_CREATE_FILE(
                conn,                                   /* conn */
                NULL,                                   /* req */
                0,                                      /* root_dir_fid */
-               r->in.file,                             /* fname */
+               smb_fname,                              /* fname */
                FILE_WRITE_ATTRIBUTES,                  /* access_mask */
                FILE_SHARE_READ|FILE_SHARE_WRITE,       /* share_access */
                FILE_OPEN,                              /* create_disposition*/
@@ -2186,19 +2270,38 @@ WERROR _srvsvc_NetSetFileSecurity(pipes_struct *p,
                NULL,                                   /* sd */
                NULL,                                   /* ea_list */
                &fsp,                                   /* result */
-               NULL,                                   /* pinfo */
-               NULL);                                  /* psbuf */
+               NULL);                                  /* pinfo */
 
        if (!NT_STATUS_IS_OK(nt_status)) {
                DEBUG(3,("_srvsvc_NetSetFileSecurity: can't open %s\n",
-                        r->in.file));
+                        smb_fname_str_dbg(smb_fname)));
                werr = ntstatus_to_werror(nt_status);
                goto error_exit;
        }
 
+       psd = r->in.sd_buf->sd;
+       security_info_sent = r->in.securityinformation;
+
+       if (psd->owner_sid==0) {
+               security_info_sent &= ~OWNER_SECURITY_INFORMATION;
+       }
+       if (psd->group_sid==0) {
+               security_info_sent &= ~GROUP_SECURITY_INFORMATION;
+       }
+       if (psd->sacl==0) {
+               security_info_sent &= ~SACL_SECURITY_INFORMATION;
+       }
+       if (psd->dacl==0) {
+               security_info_sent &= ~DACL_SECURITY_INFORMATION;
+       }
+
+       /* Convert all the generic bits. */
+       security_acl_map_generic(psd->dacl, &file_generic_mapping);
+       security_acl_map_generic(psd->sacl, &file_generic_mapping);
+
        nt_status = SMB_VFS_FSET_NT_ACL(fsp,
-                                      r->in.securityinformation,
-                                      r->in.sd_buf->sd);
+                                       security_info_sent,
+                                       psd);
 
        if (!NT_STATUS_IS_OK(nt_status) ) {
                DEBUG(3,("_srvsvc_NetSetFileSecurity: Unable to set NT ACL "
@@ -2207,15 +2310,16 @@ WERROR _srvsvc_NetSetFileSecurity(pipes_struct *p,
                goto error_exit;
        }
 
-       close_file(fsp, NORMAL_CLOSE);
+       close_file(NULL, fsp, NORMAL_CLOSE);
        vfs_ChDir(conn, oldcwd);
-       conn_free_internal(conn);
-       return WERR_OK;
+       conn_free(conn);
+       werr = WERR_OK;
+       goto done;
 
 error_exit:
 
        if (fsp) {
-               close_file(fsp, NORMAL_CLOSE);
+               close_file(NULL, fsp, NORMAL_CLOSE);
        }
 
        if (oldcwd) {
@@ -2223,9 +2327,12 @@ error_exit:
        }
 
        if (conn) {
-               conn_free_internal(conn);
+               conn_free(conn);
        }
 
+ done:
+       TALLOC_FREE(smb_fname);
+
        return werr;
 }
 
@@ -2298,6 +2405,8 @@ WERROR _srvsvc_NetDiskEnum(pipes_struct *p,
 
        /*allow one struct srvsvc_NetDiskInfo0 for null terminator*/
 
+       r->out.info->count = 0;
+
        for(i = 0; i < MAX_SERVER_DISK_ENTRIES -1 && (disk_name = next_server_disk_enum(&resume)); i++) {
 
                r->out.info->count++;
@@ -2387,17 +2496,14 @@ static void enum_file_close_fn( const struct share_mode_entry *e,
 
 WERROR _srvsvc_NetFileClose(pipes_struct *p, struct srvsvc_NetFileClose *r)
 {
-       struct current_user user;
        SE_PRIV se_diskop = SE_DISK_OPERATOR;
        bool is_disk_op;
 
        DEBUG(5,("_srvsvc_NetFileClose: %d\n", __LINE__));
 
-       get_current_user(&user,p);
-
-       is_disk_op = user_has_privileges( p->pipe_user.nt_user_token, &se_diskop );
+       is_disk_op = user_has_privileges( p->server_info->ptok, &se_diskop );
 
-       if (user.ut.uid != sec_initial_uid() && !is_disk_op) {
+       if (p->server_info->utok.uid != sec_initial_uid() && !is_disk_op) {
                return WERR_ACCESS_DENIED;
        }