root/source3/lib/netapi/file.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. NetFileClose_r
  2. NetFileClose_l
  3. map_srvsvc_FileInfo_to_FILE_INFO_buffer
  4. NetFileGetInfo_r
  5. NetFileGetInfo_l
  6. NetFileEnum_r
  7. NetFileEnum_l

   1 /*
   2  *  Unix SMB/CIFS implementation.
   3  *  NetApi File Support
   4  *  Copyright (C) Guenther Deschner 2008
   5  *
   6  *  This program is free software; you can redistribute it and/or modify
   7  *  it under the terms of the GNU General Public License as published by
   8  *  the Free Software Foundation; either version 3 of the License, or
   9  *  (at your option) any later version.
  10  *
  11  *  This program is distributed in the hope that it will be useful,
  12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
  13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14  *  GNU General Public License for more details.
  15  *
  16  *  You should have received a copy of the GNU General Public License
  17  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
  18  */
  19 
  20 #include "includes.h"
  21 
  22 #include "librpc/gen_ndr/libnetapi.h"
  23 #include "lib/netapi/netapi.h"
  24 #include "lib/netapi/netapi_private.h"
  25 #include "lib/netapi/libnetapi.h"
  26 
  27 /****************************************************************
  28 ****************************************************************/
  29 
  30 WERROR NetFileClose_r(struct libnetapi_ctx *ctx,
     /* [<][>][^][v][top][bottom][index][help] */
  31                       struct NetFileClose *r)
  32 {
  33         WERROR werr;
  34         NTSTATUS status;
  35         struct rpc_pipe_client *pipe_cli = NULL;
  36 
  37         werr = libnetapi_open_pipe(ctx, r->in.server_name,
  38                                    &ndr_table_srvsvc.syntax_id,
  39                                    &pipe_cli);
  40         if (!W_ERROR_IS_OK(werr)) {
  41                 goto done;
  42         }
  43 
  44         status = rpccli_srvsvc_NetFileClose(pipe_cli, ctx,
  45                                             r->in.server_name,
  46                                             r->in.fileid,
  47                                             &werr);
  48         if (!NT_STATUS_IS_OK(status)) {
  49                 werr = ntstatus_to_werror(status);
  50                 goto done;
  51         }
  52 
  53  done:
  54         return werr;
  55 }
  56 
  57 /****************************************************************
  58 ****************************************************************/
  59 
  60 WERROR NetFileClose_l(struct libnetapi_ctx *ctx,
     /* [<][>][^][v][top][bottom][index][help] */
  61                       struct NetFileClose *r)
  62 {
  63         LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetFileClose);
  64 }
  65 
  66 /****************************************************************
  67 ****************************************************************/
  68 
  69 static NTSTATUS map_srvsvc_FileInfo_to_FILE_INFO_buffer(TALLOC_CTX *mem_ctx,
     /* [<][>][^][v][top][bottom][index][help] */
  70                                                         uint32_t level,
  71                                                         union srvsvc_NetFileInfo *info,
  72                                                         uint8_t **buffer,
  73                                                         uint32_t *num_entries)
  74 {
  75         struct FILE_INFO_2 i2;
  76         struct FILE_INFO_3 i3;
  77 
  78         switch (level) {
  79                 case 2:
  80                         i2.fi2_id               = info->info2->fid;
  81 
  82                         ADD_TO_ARRAY(mem_ctx, struct FILE_INFO_2, i2,
  83                                      (struct FILE_INFO_2 **)buffer,
  84                                      num_entries);
  85                         break;
  86                 case 3:
  87                         i3.fi3_id               = info->info3->fid;
  88                         i3.fi3_permissions      = info->info3->permissions;
  89                         i3.fi3_num_locks        = info->info3->num_locks;
  90                         i3.fi3_pathname         = talloc_strdup(mem_ctx, info->info3->path);
  91                         i3.fi3_username         = talloc_strdup(mem_ctx, info->info3->user);
  92 
  93                         NT_STATUS_HAVE_NO_MEMORY(i3.fi3_pathname);
  94                         NT_STATUS_HAVE_NO_MEMORY(i3.fi3_username);
  95 
  96                         ADD_TO_ARRAY(mem_ctx, struct FILE_INFO_3, i3,
  97                                      (struct FILE_INFO_3 **)buffer,
  98                                      num_entries);
  99                         break;
 100                 default:
 101                         return NT_STATUS_INVALID_INFO_CLASS;
 102         }
 103 
 104         return NT_STATUS_OK;
 105 }
 106 
 107 /****************************************************************
 108 ****************************************************************/
 109 
 110 WERROR NetFileGetInfo_r(struct libnetapi_ctx *ctx,
     /* [<][>][^][v][top][bottom][index][help] */
 111                         struct NetFileGetInfo *r)
 112 {
 113         WERROR werr;
 114         NTSTATUS status;
 115         struct rpc_pipe_client *pipe_cli = NULL;
 116         union srvsvc_NetFileInfo info;
 117         uint32_t num_entries = 0;
 118 
 119         if (!r->out.buffer) {
 120                 return WERR_INVALID_PARAM;
 121         }
 122 
 123         switch (r->in.level) {
 124                 case 2:
 125                 case 3:
 126                         break;
 127                 default:
 128                         return WERR_UNKNOWN_LEVEL;
 129         }
 130 
 131         werr = libnetapi_open_pipe(ctx, r->in.server_name,
 132                                    &ndr_table_srvsvc.syntax_id,
 133                                    &pipe_cli);
 134         if (!W_ERROR_IS_OK(werr)) {
 135                 goto done;
 136         }
 137 
 138         status = rpccli_srvsvc_NetFileGetInfo(pipe_cli, ctx,
 139                                               r->in.server_name,
 140                                               r->in.fileid,
 141                                               r->in.level,
 142                                               &info,
 143                                               &werr);
 144         if (!W_ERROR_IS_OK(werr)) {
 145                 goto done;
 146         }
 147 
 148         status = map_srvsvc_FileInfo_to_FILE_INFO_buffer(ctx,
 149                                                          r->in.level,
 150                                                          &info,
 151                                                          r->out.buffer,
 152                                                          &num_entries);
 153         if (!NT_STATUS_IS_OK(status)) {
 154                 werr = ntstatus_to_werror(status);
 155                 goto done;
 156         }
 157  done:
 158         return werr;
 159 }
 160 
 161 /****************************************************************
 162 ****************************************************************/
 163 
 164 WERROR NetFileGetInfo_l(struct libnetapi_ctx *ctx,
     /* [<][>][^][v][top][bottom][index][help] */
 165                         struct NetFileGetInfo *r)
 166 {
 167         LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetFileGetInfo);
 168 }
 169 
 170 /****************************************************************
 171 ****************************************************************/
 172 
 173 WERROR NetFileEnum_r(struct libnetapi_ctx *ctx,
     /* [<][>][^][v][top][bottom][index][help] */
 174                      struct NetFileEnum *r)
 175 {
 176         WERROR werr;
 177         NTSTATUS status;
 178         struct rpc_pipe_client *pipe_cli = NULL;
 179         struct srvsvc_NetFileInfoCtr info_ctr;
 180         struct srvsvc_NetFileCtr2 ctr2;
 181         struct srvsvc_NetFileCtr3 ctr3;
 182         uint32_t num_entries = 0;
 183         uint32_t i;
 184 
 185         if (!r->out.buffer) {
 186                 return WERR_INVALID_PARAM;
 187         }
 188 
 189         switch (r->in.level) {
 190                 case 2:
 191                 case 3:
 192                         break;
 193                 default:
 194                         return WERR_UNKNOWN_LEVEL;
 195         }
 196 
 197         werr = libnetapi_open_pipe(ctx, r->in.server_name,
 198                                    &ndr_table_srvsvc.syntax_id,
 199                                    &pipe_cli);
 200         if (!W_ERROR_IS_OK(werr)) {
 201                 goto done;
 202         }
 203 
 204         ZERO_STRUCT(info_ctr);
 205 
 206         info_ctr.level = r->in.level;
 207         switch (r->in.level) {
 208                 case 2:
 209                         ZERO_STRUCT(ctr2);
 210                         info_ctr.ctr.ctr2 = &ctr2;
 211                         break;
 212                 case 3:
 213                         ZERO_STRUCT(ctr3);
 214                         info_ctr.ctr.ctr3 = &ctr3;
 215                         break;
 216         }
 217 
 218         status = rpccli_srvsvc_NetFileEnum(pipe_cli, ctx,
 219                                            r->in.server_name,
 220                                            r->in.base_path,
 221                                            r->in.user_name,
 222                                            &info_ctr,
 223                                            r->in.prefmaxlen,
 224                                            r->out.total_entries,
 225                                            r->out.resume_handle,
 226                                            &werr);
 227         if (NT_STATUS_IS_ERR(status)) {
 228                 goto done;
 229         }
 230 
 231         for (i=0; i < info_ctr.ctr.ctr2->count; i++) {
 232                 union srvsvc_NetFileInfo _i;
 233                 switch (r->in.level) {
 234                         case 2:
 235                                 _i.info2 = &info_ctr.ctr.ctr2->array[i];
 236                                 break;
 237                         case 3:
 238                                 _i.info3 = &info_ctr.ctr.ctr3->array[i];
 239                                 break;
 240                 }
 241 
 242                 status = map_srvsvc_FileInfo_to_FILE_INFO_buffer(ctx,
 243                                                                  r->in.level,
 244                                                                  &_i,
 245                                                                  r->out.buffer,
 246                                                                  &num_entries);
 247                 if (!NT_STATUS_IS_OK(status)) {
 248                         werr = ntstatus_to_werror(status);
 249                         goto done;
 250                 }
 251         }
 252 
 253         if (r->out.entries_read) {
 254                 *r->out.entries_read = num_entries;
 255         }
 256 
 257         if (r->out.total_entries) {
 258                 *r->out.total_entries = num_entries;
 259         }
 260 
 261  done:
 262         return werr;
 263 }
 264 
 265 /****************************************************************
 266 ****************************************************************/
 267 
 268 WERROR NetFileEnum_l(struct libnetapi_ctx *ctx,
     /* [<][>][^][v][top][bottom][index][help] */
 269                      struct NetFileEnum *r)
 270 {
 271         LIBNETAPI_REDIRECT_TO_LOCALHOST(ctx, r, NetFileEnum);
 272 }

/* [<][>][^][v][top][bottom][index][help] */