s3: Remove an unused variable
[kai/samba-autobuild/.git] / source3 / rpc_server / srv_srvsvc_nt.c
index 274deab88b1102677917809cf7a706d935f7609f..f7f51d1e9a9cd195669b4549663fa8fb482c6105 100644 (file)
@@ -88,12 +88,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 +191,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 +247,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 +263,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 +282,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 +289,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 +305,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 +353,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 +381,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 +397,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 +420,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 +441,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 +450,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 +459,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 +489,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 +519,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 +532,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 +566,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 +583,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 +600,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 +617,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 +634,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 +651,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 +668,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 +685,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 +702,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 +719,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 +778,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 +876,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 +933,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 +987,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++;
@@ -1075,20 +1093,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 +1119,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 +1138,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;
@@ -1225,7 +1245,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 +1265,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 +1281,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();
                        }
@@ -1466,7 +1484,6 @@ 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;
        char *comment = NULL;
@@ -1497,6 +1514,9 @@ WERROR _srvsvc_NetShareSetInfo(pipes_struct *p,
                || ( lp_enable_asu_support() && strequal(share_name,"ADMIN$") )
                || strequal(share_name,"global") )
        {
+               DEBUG(5,("_srvsvc_NetShareSetInfo: share %s cannot be "
+                       "modified by a remote user.\n",
+                       share_name ));
                return WERR_ACCESS_DENIED;
        }
 
@@ -1510,14 +1530,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 +1608,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 +1693,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,7 +1714,6 @@ 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 *comment = NULL;
@@ -1704,11 +1734,9 @@ WERROR _srvsvc_NetShareAdd(pipes_struct *p,
                *r->out.parm_error = 0;
        }
 
-       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_add_share_cmd() || !*lp_add_share_cmd()) {
@@ -1868,7 +1896,6 @@ 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;
        int ret;
@@ -1901,11 +1928,9 @@ WERROR _srvsvc_NetShareDel(pipes_struct *p,
        if (lp_print_ok(snum))
                return WERR_ACCESS_DENIED;
 
-       get_current_user(&user,p);
+       is_disk_op = user_has_privileges( p->server_info->ptok, &se_diskop );
 
-       is_disk_op = user_has_privileges( p->pipe_user.nt_user_token, &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()) {
@@ -1999,19 +2024,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__));
 
@@ -2026,6 +2050,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;
@@ -2059,11 +2084,23 @@ WERROR _srvsvc_NetGetFileSecurity(pipes_struct *p,
                goto error_exit;
        }
 
-       nt_status = create_file(
+       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 = 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*/
@@ -2074,12 +2111,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;
        }
@@ -2091,12 +2127,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) {
@@ -2113,8 +2149,9 @@ WERROR _srvsvc_NetGetFileSecurity(pipes_struct *p,
 
        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:
 
@@ -2127,9 +2164,12 @@ error_exit:
        }
 
        if (conn) {
-               conn_free_internal(conn);
+               conn_free(conn);
        }
 
+ done:
+       TALLOC_FREE(smb_fname);
+
        return werr;
 }
 
@@ -2141,6 +2181,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;
@@ -2173,11 +2214,23 @@ WERROR _srvsvc_NetSetFileSecurity(pipes_struct *p,
                goto error_exit;
        }
 
-       nt_status = create_file(
+       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 = 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*/
@@ -2188,12 +2241,11 @@ 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;
        }
@@ -2231,8 +2283,9 @@ WERROR _srvsvc_NetSetFileSecurity(pipes_struct *p,
 
        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:
 
@@ -2245,9 +2298,12 @@ error_exit:
        }
 
        if (conn) {
-               conn_free_internal(conn);
+               conn_free(conn);
        }
 
+ done:
+       TALLOC_FREE(smb_fname);
+
        return werr;
 }
 
@@ -2320,6 +2376,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++;
@@ -2409,17 +2467,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;
        }