s3: Remove an unused variable
[kai/samba-autobuild/.git] / source3 / rpc_server / srv_srvsvc_nt.c
index a37e55270e16f8530537311d0d9c1d9476b0fa61..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);
 }
 
 /*******************************************************************
@@ -266,9 +267,9 @@ static void init_srv_share_info_1(pipes_struct *p, struct srvsvc_NetShareInfo1 *
                        "", 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));
@@ -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             = "";
 }
 
 /*******************************************************************
@@ -359,10 +357,10 @@ static void init_srv_share_info_501(pipes_struct *p, struct srvsvc_NetShareInfo5
                        "", 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);
 }
 
 /*******************************************************************
@@ -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;
 }
 
 /***************************************************************************
@@ -426,7 +424,7 @@ static void init_srv_share_info_1004(pipes_struct *p, struct srvsvc_NetShareInfo
                        "", 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     = "";
 }
 
 /*******************************************************************
@@ -543,11 +540,13 @@ static WERROR init_srv_share_info_ctr(pipes_struct *p,
                 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)));
+                        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)));
+                        DEBUG(10, ("NOT counting service %s\n",
+                               lp_servicename(snum) ? lp_servicename(snum) : "(null)"));
                 }
         }
 
@@ -779,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++;
        }
 
@@ -876,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++;
        }
 
@@ -933,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++;
@@ -988,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++;
@@ -1095,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;
        }
@@ -1120,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;
        }
@@ -1138,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;
@@ -1514,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;
        }
 
@@ -1531,8 +1534,14 @@ WERROR _srvsvc_NetShareSetInfo(pipes_struct *p,
 
        /* fail out now if you are not root and not a disk op */
 
-       if ( p->server_info->utok.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:
@@ -1599,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, '"', ' ');
@@ -1677,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 ));
@@ -2008,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__));
 
@@ -2035,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;
@@ -2068,12 +2084,23 @@ WERROR _srvsvc_NetGetFileSecurity(pipes_struct *p,
                goto error_exit;
        }
 
+       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 */
-               CFF_DOS_PATH,                           /* create_file_flags */
+               smb_fname,                              /* fname */
                FILE_READ_ATTRIBUTES,                   /* access_mask */
                FILE_SHARE_READ|FILE_SHARE_WRITE,       /* share_access */
                FILE_OPEN,                              /* create_disposition*/
@@ -2084,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;
        }
@@ -2101,7 +2127,7 @@ 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;
        }
@@ -2123,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:
 
@@ -2137,9 +2164,12 @@ error_exit:
        }
 
        if (conn) {
-               conn_free_internal(conn);
+               conn_free(conn);
        }
 
+ done:
+       TALLOC_FREE(smb_fname);
+
        return werr;
 }
 
@@ -2151,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;
@@ -2183,12 +2214,23 @@ WERROR _srvsvc_NetSetFileSecurity(pipes_struct *p,
                goto error_exit;
        }
 
+       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 */
-               CFF_DOS_PATH,                           /* create_file_flags */
+               smb_fname,                              /* fname */
                FILE_WRITE_ATTRIBUTES,                  /* access_mask */
                FILE_SHARE_READ|FILE_SHARE_WRITE,       /* share_access */
                FILE_OPEN,                              /* create_disposition*/
@@ -2199,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;
        }
@@ -2242,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:
 
@@ -2256,9 +2298,12 @@ error_exit:
        }
 
        if (conn) {
-               conn_free_internal(conn);
+               conn_free(conn);
        }
 
+ done:
+       TALLOC_FREE(smb_fname);
+
        return werr;
 }
 
@@ -2331,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++;